Skip to content

Commit 8aaa48e

Browse files
authored
experimental: Advanced style panel mode (#4840)
#4816 ## Description - [x] added switch - [x] full-size advaned panel ## Steps for reproduction 1. click button 3. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent a8bfa4d commit 8aaa48e

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

apps/builder/app/builder/features/inspector/inspector.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { getInstanceLabel } from "~/shared/instance-utils";
3333
import { BindingPopoverProvider } from "~/builder/shared/binding-popover";
3434
import { $activeInspectorPanel } from "~/builder/shared/nano-states";
3535
import { $selectedInstance, $selectedPage } from "~/shared/awareness";
36-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
3736

3837
const InstanceInfo = ({ instance }: { instance: Instance }) => {
3938
const metas = useStore($registeredComponentMetas);
@@ -177,7 +176,7 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {
177176
}}
178177
>
179178
<InstanceInfo instance={selectedInstance} />
180-
{isFeatureEnabled("stylePanelModes") && <ModeMenu />}
179+
<ModeMenu />
181180
</Flex>
182181
<StylePanel />
183182
</PanelTabsContent>

apps/builder/app/builder/features/navigator/css-preview.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const preStyle = css(textVariants.mono, {
2828
// - Compiles a CSS string from the style engine
2929
// - Groups by category and separates categories with comments
3030
const getCssText = (
31-
computedStyles: ComputedStyleDecl[],
31+
definedComputedStyles: ComputedStyleDecl[],
3232
instanceId: string
3333
) => {
3434
const sourceStyles: StyleMap = new Map();
3535
const cascadedStyles: StyleMap = new Map();
3636
const presetStyles: StyleMap = new Map();
3737

3838
// Aggregate styles by category so we can group them when rendering.
39-
for (const styleDecl of computedStyles) {
39+
for (const styleDecl of definedComputedStyles) {
4040
const property = hyphenateProperty(styleDecl.property) as StyleProperty;
4141
let group;
4242
if (
@@ -77,15 +77,19 @@ const getCssText = (
7777

7878
const $highlightedCss = computed(
7979
[$selectedInstance, $definedComputedStyles],
80-
(instance, computedStyles) => {
80+
(instance, definedComputedStyles) => {
8181
if (instance === undefined) {
8282
return;
8383
}
84-
const cssText = getCssText(computedStyles, instance.id);
84+
const cssText = getCssText(definedComputedStyles, instance.id);
8585
return highlightCss(cssText);
8686
}
8787
);
8888

89+
/**
90+
* Will be deleted soon in favor of advanced panel as soon as it has ability to select.
91+
* @deprecated
92+
*/
8993
export const CssPreview = () => {
9094
const code = useStore($highlightedCss);
9195
if (code === undefined) {

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
} from "~/shared/nano-states";
7373
import { useClientSupports } from "~/shared/client-supports";
7474
import { $selectedInstancePath } from "~/shared/awareness";
75+
import { $settings } from "~/builder/shared/client-settings";
7576

7677
// Only here to keep the same section module interface
7778
export const properties = [];
@@ -381,8 +382,16 @@ const $advancedProperties = computed(
381382
$styleSourceSelections,
382383
$matchingBreakpoints,
383384
$styles,
385+
$settings,
384386
],
385-
(instancePath, metas, styleSourceSelections, matchingBreakpoints, styles) => {
387+
(
388+
instancePath,
389+
metas,
390+
styleSourceSelections,
391+
matchingBreakpoints,
392+
styles,
393+
settings
394+
) => {
386395
if (instancePath === undefined) {
387396
return [];
388397
}
@@ -402,6 +411,11 @@ const $advancedProperties = computed(
402411
}
403412
const advancedProperties = new Set<StyleProperty>(initialProperties);
404413
for (const { property, listed } of definedStyles) {
414+
// In advanced mode we show all defined properties
415+
if (settings.stylePanelMode === "advanced") {
416+
advancedProperties.add(property);
417+
continue;
418+
}
405419
// exclude properties from style panel UI unless edited in advanced section
406420
if (baseProperties.has(property) === false || listed) {
407421
advancedProperties.add(property);

apps/builder/app/builder/features/style-panel/shared/model.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ const $model = computed(
240240
}
241241
);
242242

243+
/**
244+
* Will be deleted along with CSS Preview.
245+
* @deprecated
246+
*/
243247
export const $definedComputedStyles = computed(
244248
[
245249
$definedStyles,

apps/builder/app/builder/features/style-panel/style-panel.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
type Settings,
3636
} from "~/builder/shared/client-settings";
3737
import { useState } from "react";
38+
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
3839

3940
const $selectedInstanceTag = computed(
4041
[$selectedInstance, $instanceTags],
@@ -83,10 +84,15 @@ export const ModeMenu = () => {
8384
<Text>Focus mode</Text> <Kbd value={["alt", "shift", "s"]} />
8485
</Flex>
8586
</DropdownMenuRadioItem>
86-
{/*
87-
<DropdownMenuRadioItem value="advanced" icon={<MenuCheckedIcon />}>
88-
Advanced mode
89-
</DropdownMenuRadioItem> */}
87+
{isFeatureEnabled("stylePanelAdvancedMode") && (
88+
<DropdownMenuRadioItem
89+
value="advanced"
90+
icon={<MenuCheckedIcon />}
91+
onFocus={() => setFocusedValue("advanced")}
92+
>
93+
Advanced mode
94+
</DropdownMenuRadioItem>
95+
)}
9096
</DropdownMenuRadioGroup>
9197
<DropdownMenuSeparator />
9298

@@ -100,6 +106,9 @@ export const ModeMenu = () => {
100106
Only one section is open at a time.
101107
</DropdownMenuItem>
102108
)}
109+
{focusedValue === "advanced" && (
110+
<DropdownMenuItem hint>Advanced section only.</DropdownMenuItem>
111+
)}
103112
</DropdownMenuContent>
104113
</DropdownMenu>
105114
);
@@ -128,6 +137,10 @@ export const StylePanel = () => {
128137
const all = [];
129138

130139
for (const [category, { Section }] of sections.entries()) {
140+
// In advanced mode we only need to show advanced panel
141+
if (stylePanelMode === "advanced" && category !== "advanced") {
142+
continue;
143+
}
131144
// show flex child UI only when parent is flex or inline-flex
132145
if (category === "flexChild" && displayValue.includes("flex") === false) {
133146
continue;

packages/feature-flags/src/flags.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const staticExport = false;
99
export const contentEditableMode = false;
1010
export const command = false;
1111
export const headSlotComponent = false;
12-
export const stylePanelModes = false;
12+
export const stylePanelAdvancedMode = false;

0 commit comments

Comments
 (0)