Skip to content

Commit 32120c3

Browse files
authored
refactor: hyphenate builder (#5007)
Switched all left overs to hyphenated css properties including animation section. StyleProperty is only stored in data.
1 parent abb3572 commit 32120c3

File tree

17 files changed

+89
-142
lines changed

17 files changed

+89
-142
lines changed

apps/builder/app/builder/features/settings-panel/props-section/animation/set-css-property.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test("Add Css Property styles", () => {
5656
data.styleSources,
5757
data.styleSourceSelections,
5858
data.styles
59-
)("boxChildId", "viewTimelineName", {
59+
)("boxChildId", "view-timeline-name", {
6060
type: "unparsed",
6161
value: "--view-timeline-name-child",
6262
});
@@ -66,7 +66,7 @@ test("Add Css Property styles", () => {
6666
data.styleSources,
6767
data.styleSourceSelections,
6868
data.styles
69-
)("boxId", "viewTimelineName", {
69+
)("boxId", "view-timeline-name", {
7070
type: "unparsed",
7171
value: "--view-timeline-name",
7272
});

apps/builder/app/builder/features/settings-panel/props-section/animation/set-css-property.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import type { StyleProperty, StyleValue } from "@webstudio-is/css-engine";
1+
import { nanoid } from "nanoid";
2+
import type { CssProperty, StyleValue } from "@webstudio-is/css-engine";
23
import {
34
getStyleDeclKey,
5+
StyleDecl,
46
type Breakpoints,
57
type Instance,
68
type Styles,
79
type StyleSources,
810
type StyleSourceSelections,
911
} from "@webstudio-is/sdk";
10-
import { nanoid } from "nanoid";
1112

1213
import { isBaseBreakpoint } from "~/shared/nano-states";
14+
import { camelCaseProperty } from "@webstudio-is/css-data";
1315

1416
export const setListedCssProperty =
1517
(
@@ -19,7 +21,7 @@ export const setListedCssProperty =
1921
styleSourceSelections: StyleSourceSelections,
2022
styles: Styles
2123
) =>
22-
(instanceId: Instance["id"], property: StyleProperty, value: StyleValue) => {
24+
(instanceId: Instance["id"], property: CssProperty, value: StyleValue) => {
2325
if (!styleSourceSelections.has(instanceId)) {
2426
const styleSourceId = nanoid();
2527
styleSources.set(styleSourceId, { type: "local", id: styleSourceId });
@@ -48,17 +50,12 @@ export const setListedCssProperty =
4850
throw new Error("Base breakpoint not found");
4951
}
5052

51-
const styleKey = getStyleDeclKey({
52-
breakpointId: baseBreakpoint.id,
53-
property,
54-
styleSourceId: localStyleSorceId,
55-
});
56-
57-
styles.set(styleKey, {
53+
const styleDecl: StyleDecl = {
5854
breakpointId: baseBreakpoint.id,
59-
property,
55+
property: camelCaseProperty(property),
6056
styleSourceId: localStyleSorceId,
6157
value,
6258
listed: true,
63-
});
59+
};
60+
styles.set(getStyleDeclKey(styleDecl), styleDecl);
6461
};

apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const initSubjects = () => {
4949
selector.length !== 0;
5050
selector = selector.slice(1)
5151
) {
52-
const styleDecl = getInstanceStyleDecl("viewTimelineName", selector);
52+
const styleDecl = getInstanceStyleDecl("view-timeline-name", selector);
5353
const instanceId = selector.at(0)!;
5454

5555
const instance = instances.get(selector[0]);
@@ -139,7 +139,7 @@ export const SubjectSelect = ({
139139
styleSources,
140140
styleSourceSelections,
141141
styles
142-
)(subjectItem.instanceId, "viewTimelineName", {
142+
)(subjectItem.instanceId, "view-timeline-name", {
143143
type: "unparsed",
144144
value: newValue.subject,
145145
});

apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { matchSorter } from "match-sorter";
2+
import { forwardRef, useMemo, useState, type ComponentProps } from "react";
13
import {
24
Combobox,
35
EnhancedTooltip,
46
Flex,
57
NestedInputButton,
68
FloatingPanel,
79
} from "@webstudio-is/design-system";
8-
import { forwardRef, useMemo, useState, type ComponentProps } from "react";
910
import { toValue } from "@webstudio-is/css-engine";
10-
import { matchSorter } from "match-sorter";
1111
import { UploadIcon } from "@webstudio-is/icons";
1212
import { keywordValues, parseCssValue } from "@webstudio-is/css-data";
1313
import { FontsManager } from "~/builder/shared/fonts-manager";
@@ -41,9 +41,9 @@ const matchOrSuggestToCreate = (
4141
};
4242

4343
export const FontFamilyControl = () => {
44-
const fontFamily = useComputedStyleDecl("fontFamily");
44+
const fontFamily = useComputedStyleDecl("font-family");
4545
const value = fontFamily.cascadedValue;
46-
const setValue = setProperty("fontFamily");
46+
const setValue = setProperty("font-family");
4747
const [intermediateValue, setIntermediateValue] = useState<
4848
string | undefined
4949
>();

apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { useEffect } from "react";
2+
import { useStore } from "@nanostores/react";
13
import { Select, Text } from "@webstudio-is/design-system";
24
import {
35
type FontWeight,
46
fontWeightNames,
57
fontWeights,
68
} from "@webstudio-is/fonts";
79
import { toValue } from "@webstudio-is/css-engine";
8-
import { useEffect } from "react";
9-
import { useComputedStyles } from "../../shared/model";
10-
import { setProperty } from "../../shared/use-style-data";
1110
import { canvasApi } from "~/shared/canvas-api";
12-
import { useStore } from "@nanostores/react";
1311
import { $detectedFontsWeights } from "~/shared/nano-states";
12+
import { useComputedStyles } from "../../shared/model";
13+
import { setProperty } from "../../shared/use-style-data";
1414

1515
const allFontWeights = Object.keys(fontWeights) as Array<FontWeight>;
1616

@@ -24,8 +24,8 @@ const labels = new Map(
2424
export const FontWeightControl = () => {
2525
// We need the font family to determine which font weights are available
2626
const [fontWeight, fontFamily] = useComputedStyles([
27-
"fontWeight",
28-
"fontFamily",
27+
"font-weight",
28+
"font-family",
2929
]);
3030
const detectedFontsWeights = useStore($detectedFontsWeights);
3131
const fontFamilyCss = toValue(fontFamily.usedValue);
@@ -39,7 +39,7 @@ export const FontWeightControl = () => {
3939
const selectedWeight =
4040
fontWeightNames.get(fontWeightCss) ?? (fontWeightCss as FontWeight);
4141

42-
const setValue = setProperty("fontWeight");
42+
const setValue = setProperty("font-weight");
4343

4444
const setFontWeight = (
4545
nextWeight: FontWeight,

apps/builder/app/builder/features/style-panel/controls/image/image-control.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
import { useEffect, useState } from "react";
12
import { useStore } from "@nanostores/react";
23
import {
34
Button,
45
InputField,
56
Flex,
67
FloatingPanel,
78
} from "@webstudio-is/design-system";
9+
import type { CssProperty, InvalidValue } from "@webstudio-is/css-engine";
810
import { $assets } from "~/shared/nano-states";
911
import { ImageManager } from "~/builder/shared/image-manager";
10-
import { useEffect, useState } from "react";
11-
import type {
12-
CssProperty,
13-
InvalidValue,
14-
StyleProperty,
15-
} from "@webstudio-is/css-engine";
1612
import { useComputedStyleDecl } from "../../shared/model";
1713
import {
1814
getRepeatedStyleItem,
@@ -36,7 +32,7 @@ export const ImageControl = ({
3632
property,
3733
index,
3834
}: {
39-
property: StyleProperty | CssProperty;
35+
property: CssProperty;
4036
index: number;
4137
}) => {
4238
const assets = useStore($assets);

apps/builder/app/builder/features/style-panel/controls/select/select-control.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import {
66
parseCssValue,
77
} from "@webstudio-is/css-data";
88
import {
9-
hyphenateProperty,
10-
StyleValue,
119
toValue,
10+
type StyleValue,
1211
type CssProperty,
13-
type StyleProperty,
1412
} from "@webstudio-is/css-engine";
1513
import { Box, Select, theme } from "@webstudio-is/design-system";
1614
import { toKebabCase } from "../../shared/keyword-utils";
@@ -30,7 +28,7 @@ export const SelectControl = ({
3028
index,
3129
items,
3230
}: {
33-
property: StyleProperty | CssProperty;
31+
property: CssProperty;
3432
index?: number;
3533
items?: Array<{ label: string; name: string }>;
3634
}) => {
@@ -47,9 +45,7 @@ export const SelectControl = ({
4745
}
4846
};
4947
const options =
50-
items?.map(({ name }) => name) ??
51-
keywordValues[hyphenateProperty(property)] ??
52-
[];
48+
items?.map(({ name }) => name) ?? keywordValues[property] ?? [];
5349

5450
// We can't render an empty string as a value when display was added but without a value.
5551
// One case is when advanced property is being added, but no value is set.
@@ -86,7 +82,7 @@ export const SelectControl = ({
8682
return;
8783
}
8884
// Preview on mouse enter or focus.
89-
const nextValue = parseCssValue(camelCaseProperty(property), name);
85+
const nextValue = parseCssValue(property, name);
9086
setValue(nextValue, { isEphemeral: true });
9187
}}
9288
onOpenChange={(isOpen) => {

apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import {
1111
ToggleGroupButton,
1212
Tooltip,
1313
} from "@webstudio-is/design-system";
14-
import {
15-
hyphenateProperty,
16-
toValue,
17-
type CssProperty,
18-
type StyleProperty,
19-
} from "@webstudio-is/css-engine";
14+
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
2015
import { humanizeString } from "~/shared/string-utils";
2116
import { useComputedStyles } from "../../shared/model";
2217
import { createBatchUpdate } from "../../shared/use-style-data";
@@ -42,7 +37,7 @@ export const ToggleGroupTooltip = ({
4237
label?: string;
4338
code?: string;
4439
description: string | undefined;
45-
properties: (StyleProperty | CssProperty)[];
40+
properties: CssProperty[];
4641
isAdvanced?: boolean;
4742
children: ReactNode;
4843
}) => {
@@ -103,7 +98,7 @@ export const ToggleGroupControl = ({
10398
items,
10499
}: {
105100
label?: string;
106-
properties: [CssProperty | StyleProperty, ...(CssProperty | StyleProperty)[]];
101+
properties: [CssProperty, ...CssProperty[]];
107102
items: Array<{
108103
child: JSX.Element;
109104
value: string;
@@ -151,12 +146,12 @@ export const ToggleGroupControl = ({
151146
isAdvanced={isAdvanced}
152147
label={label}
153148
code={properties
154-
.map((property) => `${hyphenateProperty(property)}: ${item.value};`)
149+
.map((property) => `${property}: ${item.value};`)
155150
.join("\n")}
156151
description={
157152
item.description ??
158153
declarationDescriptions[
159-
`${camelCaseProperty(properties[0])}:${item.value}` as keyof typeof declarationDescriptions
154+
`${camelCaseProperty(properties[0])}:${item.value}`
160155
]
161156
}
162157
properties={properties}

apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export const ToggleControl = ({
3434
const isAdvanced =
3535
computedStyleDecl.source.name !== "default" && currentItem === undefined;
3636
const description =
37-
declarationDescriptions[
38-
`${camelCaseProperty(property)}:${currentValue}` as keyof typeof declarationDescriptions
39-
];
37+
declarationDescriptions[`${camelCaseProperty(property)}:${currentValue}`];
4038

4139
return (
4240
<PropertyValueTooltip

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { atom } from "nanostores";
22
import { useStore } from "@nanostores/react";
33
import { useState, type ReactNode } from "react";
44
import { AlertIcon, ResetIcon } from "@webstudio-is/icons";
5-
import {
6-
hyphenateProperty,
7-
toValue,
8-
type CssProperty,
9-
type StyleProperty,
10-
} from "@webstudio-is/css-engine";
5+
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
116
import { propertiesData } from "@webstudio-is/css-data";
127
import {
138
Button,
@@ -238,7 +233,7 @@ export const PropertyLabel = ({
238233
}: {
239234
label: string;
240235
description?: string;
241-
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
236+
properties: [CssProperty, ...CssProperty[]];
242237
}) => {
243238
const styles = useComputedStyles(properties);
244239
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -279,7 +274,7 @@ export const PropertyLabel = ({
279274
resetProperty();
280275
setIsOpen(false);
281276
}}
282-
link={propertiesData[hyphenateProperty(properties[0])]?.mdnUrl}
277+
link={propertiesData[properties[0]]?.mdnUrl}
283278
/>
284279
}
285280
>
@@ -300,7 +295,7 @@ export const PropertySectionLabel = ({
300295
}: {
301296
label: string;
302297
description: string | undefined;
303-
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
298+
properties: [CssProperty, ...CssProperty[]];
304299
}) => {
305300
const styles = useComputedStyles(properties);
306301
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -339,7 +334,7 @@ export const PropertySectionLabel = ({
339334
resetProperty();
340335
setIsOpen(false);
341336
}}
342-
link={propertiesData[hyphenateProperty(properties[0])]?.mdnUrl}
337+
link={propertiesData[properties[0]]?.mdnUrl}
343338
/>
344339
}
345340
>
@@ -369,10 +364,7 @@ export const PropertyInlineLabel = ({
369364
label: string;
370365
title?: string;
371366
description?: string;
372-
properties?: [
373-
StyleProperty | CssProperty,
374-
...(StyleProperty | CssProperty)[],
375-
];
367+
properties?: [CssProperty, ...CssProperty[]];
376368
disabled?: boolean;
377369
}) => {
378370
const [isOpen, setIsOpen] = useState(false);
@@ -401,7 +393,7 @@ export const PropertyInlineLabel = ({
401393
userSelect="text"
402394
css={{ whiteSpace: "break-spaces", cursor: "text" }}
403395
>
404-
{properties.map(hyphenateProperty).join("\n")}
396+
{properties.join("\n")}
405397
</Text>
406398
)}
407399
<Text>{description}</Text>
@@ -428,7 +420,7 @@ export const PropertyValueTooltip = ({
428420
}: {
429421
label: string;
430422
description: string | undefined;
431-
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
423+
properties: [CssProperty, ...CssProperty[]];
432424
isAdvanced?: boolean;
433425
children: ReactNode;
434426
}) => {
@@ -476,7 +468,7 @@ export const PropertyValueTooltip = ({
476468
resetProperty();
477469
setIsOpen(false);
478470
}}
479-
link={propertiesData[hyphenateProperty(properties[0])]?.mdnUrl}
471+
link={propertiesData[properties[0]]?.mdnUrl}
480472
/>
481473
}
482474
>

0 commit comments

Comments
 (0)