@webstudio-is/react-sdk 0.91.0 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app/index.js +1 -0
- package/lib/app/root.js +2 -4
- package/lib/component-renderer.js +3 -5
- package/lib/components/component-meta.js +6 -11
- package/lib/components/components-utils.js +1 -0
- package/lib/context.js +2 -4
- package/lib/css/css.js +4 -9
- package/lib/css/global-rules.js +3 -5
- package/lib/css/index.js +1 -0
- package/lib/css/normalize-type-check.js +1 -0
- package/lib/css/normalize.js +48 -96
- package/lib/css/presets.js +3 -6
- package/lib/css/style-rules.js +3 -6
- package/{src/css/style-rules.test.ts → lib/css/style-rules.test.js} +23 -28
- package/lib/embed-template.js +7 -22
- package/{src/embed-template.test.ts → lib/embed-template.test.js} +165 -176
- package/lib/expression.js +11 -22
- package/{src/expression.test.ts → lib/expression.test.js} +55 -83
- package/lib/generator.js +2 -4
- package/{src/generator.test.ts → lib/generator.test.js} +28 -31
- package/lib/hook.js +2 -4
- package/{src/hook.test.ts → lib/hook.test.js} +4 -4
- package/lib/index.js +9 -31
- package/lib/instance-utils.js +2 -4
- package/{src/instance-utils.test.ts → lib/instance-utils.test.js} +19 -43
- package/lib/prop-meta.js +150 -0
- package/lib/props.js +8 -16
- package/{src/props.test.ts → lib/props.test.js} +39 -68
- package/lib/pubsub/create.js +2 -4
- package/lib/pubsub/index.js +1 -0
- package/lib/pubsub/raf-queue.js +2 -4
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/tree/index.js +1 -0
- package/lib/tree/root.js +2 -5
- package/lib/tree/webstudio-component.js +10 -20
- package/lib/types/component-renderer.d.ts +1 -1
- package/lib/types/components/component-meta.d.ts +526 -526
- package/lib/types/context.d.ts +1 -2
- package/lib/types/css/css.d.ts +22 -23
- package/lib/types/css/global-rules.d.ts +19 -19
- package/lib/types/css/normalize.d.ts +2444 -2444
- package/lib/types/css/style-rules.d.ts +2 -2
- package/lib/types/embed-template.d.ts +648 -648
- package/lib/types/generator.d.ts +1 -1
- package/lib/types/hook.d.ts +3 -3
- package/lib/types/index.d.ts +1 -0
- package/lib/types/instance-utils.d.ts +3 -3
- package/lib/types/prop-meta.d.ts +396 -0
- package/lib/types/props.d.ts +52 -53
- package/lib/types/tree/create-elements-tree.d.ts +3 -4
- package/lib/types/tree/root.d.ts +8 -8
- package/lib/types/tree/webstudio-component.d.ts +1 -1
- package/package.json +14 -22
- package/lib/cjs/app/index.js +0 -18
- package/lib/cjs/app/root.js +0 -40
- package/lib/cjs/component-renderer.js +0 -143
- package/lib/cjs/components/component-meta.js +0 -87
- package/lib/cjs/components/components-utils.js +0 -17
- package/lib/cjs/context.js +0 -43
- package/lib/cjs/css/css.js +0 -84
- package/lib/cjs/css/global-rules.js +0 -37
- package/lib/cjs/css/index.js +0 -20
- package/lib/cjs/css/normalize-type-check.js +0 -26
- package/lib/cjs/css/normalize.js +0 -349
- package/lib/cjs/css/presets.js +0 -48
- package/lib/cjs/css/style-rules.js +0 -86
- package/lib/cjs/embed-template.js +0 -368
- package/lib/cjs/expression.js +0 -371
- package/lib/cjs/generator.js +0 -128
- package/lib/cjs/hook.js +0 -34
- package/lib/cjs/index.js +0 -59
- package/lib/cjs/instance-utils.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/props.js +0 -204
- package/lib/cjs/pubsub/create.js +0 -78
- package/lib/cjs/pubsub/index.js +0 -18
- package/lib/cjs/pubsub/raf-queue.js +0 -42
- package/lib/cjs/tree/create-elements-tree.js +0 -152
- package/lib/cjs/tree/index.js +0 -20
- package/lib/cjs/tree/root.js +0 -100
- package/lib/cjs/tree/webstudio-component.js +0 -91
- package/src/app/index.ts +0 -1
- package/src/app/root.tsx +0 -25
- package/src/component-renderer.tsx +0 -146
- package/src/components/component-meta.ts +0 -86
- package/src/components/components-utils.ts +0 -13
- package/src/context.tsx +0 -73
- package/src/css/css.ts +0 -88
- package/src/css/global-rules.ts +0 -26
- package/src/css/index.ts +0 -3
- package/src/css/normalize-type-check.ts +0 -13
- package/src/css/normalize.ts +0 -507
- package/src/css/presets.ts +0 -27
- package/src/css/style-rules.ts +0 -101
- package/src/embed-template.ts +0 -438
- package/src/expression.ts +0 -401
- package/src/generator.ts +0 -147
- package/src/hook.ts +0 -52
- package/src/index.ts +0 -39
- package/src/instance-utils.ts +0 -65
- package/src/props.ts +0 -231
- package/src/pubsub/create.ts +0 -77
- package/src/pubsub/index.ts +0 -1
- package/src/pubsub/raf-queue.ts +0 -25
- package/src/tree/create-elements-tree.tsx +0 -186
- package/src/tree/index.ts +0 -3
- package/src/tree/root.ts +0 -131
- package/src/tree/webstudio-component.tsx +0 -97
package/lib/app/index.js
CHANGED
package/lib/app/root.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
|
|
3
|
-
const Root = ({
|
|
4
|
+
export const Root = ({
|
|
4
5
|
Outlet = DefaultOutlet
|
|
5
6
|
}) => {
|
|
6
7
|
return /* @__PURE__ */ jsxs("html", { lang: "en", children: [
|
|
@@ -15,6 +16,3 @@ const Root = ({
|
|
|
15
16
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
16
17
|
] });
|
|
17
18
|
};
|
|
18
|
-
export {
|
|
19
|
-
Root
|
|
20
|
-
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { getStyleDeclKey } from "@webstudio-is/
|
|
3
|
+
import { getStyleDeclKey } from "@webstudio-is/sdk";
|
|
3
4
|
import {
|
|
4
5
|
WsEmbedTemplate,
|
|
5
6
|
generateDataFromEmbedTemplate
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
executeEffectfulExpression
|
|
15
16
|
} from "./expression";
|
|
16
17
|
import { getIndexesWithinAncestors } from "./instance-utils";
|
|
17
|
-
const renderComponentTemplate = ({
|
|
18
|
+
export const renderComponentTemplate = ({
|
|
18
19
|
name,
|
|
19
20
|
metas: metasRecord,
|
|
20
21
|
components,
|
|
@@ -127,6 +128,3 @@ const renderComponentTemplate = ({
|
|
|
127
128
|
)
|
|
128
129
|
] });
|
|
129
130
|
};
|
|
130
|
-
export {
|
|
131
|
-
renderComponentTemplate
|
|
132
|
-
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
import { PropMeta } from "
|
|
3
|
+
import { PropMeta } from "../prop-meta";
|
|
3
4
|
import { EmbedTemplateStyleDecl, WsEmbedTemplate } from "../embed-template";
|
|
4
5
|
const WsComponentPropsMeta = z.object({
|
|
5
6
|
props: z.record(PropMeta),
|
|
6
7
|
// Props that will be always visible in properties panel.
|
|
7
8
|
initialProps: z.array(z.string()).optional()
|
|
8
9
|
});
|
|
9
|
-
const componentCategories = [
|
|
10
|
+
export const componentCategories = [
|
|
10
11
|
"general",
|
|
11
12
|
"text",
|
|
12
13
|
"media",
|
|
@@ -14,8 +15,8 @@ const componentCategories = [
|
|
|
14
15
|
"radix",
|
|
15
16
|
"hidden"
|
|
16
17
|
];
|
|
17
|
-
const stateCategories = ["states", "component-states"];
|
|
18
|
-
const ComponentState = z.object({
|
|
18
|
+
export const stateCategories = ["states", "component-states"];
|
|
19
|
+
export const ComponentState = z.object({
|
|
19
20
|
category: z.enum(stateCategories).optional(),
|
|
20
21
|
selector: z.string(),
|
|
21
22
|
label: z.string()
|
|
@@ -24,7 +25,7 @@ const ComponentToken = z.object({
|
|
|
24
25
|
variant: z.optional(z.string()),
|
|
25
26
|
styles: z.array(EmbedTemplateStyleDecl)
|
|
26
27
|
});
|
|
27
|
-
const defaultStates = [
|
|
28
|
+
export const defaultStates = [
|
|
28
29
|
{ selector: ":hover", label: "Hover" },
|
|
29
30
|
{ selector: ":active", label: "Active" },
|
|
30
31
|
{ selector: ":focus", label: "Focus" },
|
|
@@ -59,9 +60,3 @@ const WsComponentMeta = z.object({
|
|
|
59
60
|
template: z.optional(WsEmbedTemplate),
|
|
60
61
|
order: z.number().optional()
|
|
61
62
|
});
|
|
62
|
-
export {
|
|
63
|
-
ComponentState,
|
|
64
|
-
componentCategories,
|
|
65
|
-
defaultStates,
|
|
66
|
-
stateCategories
|
|
67
|
-
};
|
package/lib/context.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { atom } from "nanostores";
|
|
2
3
|
import { createContext } from "react";
|
|
3
|
-
const ReactSdkContext = createContext({
|
|
4
|
+
export const ReactSdkContext = createContext({
|
|
4
5
|
imageBaseUrl: "/",
|
|
5
6
|
assetBaseUrl: "/",
|
|
6
7
|
propsByInstanceIdStore: atom(/* @__PURE__ */ new Map()),
|
|
@@ -18,6 +19,3 @@ const ReactSdkContext = createContext({
|
|
|
18
19
|
},
|
|
19
20
|
indexesWithinAncestors: /* @__PURE__ */ new Map()
|
|
20
21
|
});
|
|
21
|
-
export {
|
|
22
|
-
ReactSdkContext
|
|
23
|
-
};
|
package/lib/css/css.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { createCssEngine } from "@webstudio-is/css-engine";
|
|
2
3
|
import { idAttribute } from "../tree";
|
|
3
4
|
import { addGlobalRules } from "./global-rules";
|
|
4
5
|
import { getPresetStyleRules, getStyleRules } from "./style-rules";
|
|
5
|
-
const createImageValueTransformer = (assets, options) => (styleValue) => {
|
|
6
|
+
export const createImageValueTransformer = (assets, options) => (styleValue) => {
|
|
6
7
|
if (styleValue.type === "image" && styleValue.value.type === "asset") {
|
|
7
8
|
const asset = assets.get(styleValue.value.value);
|
|
8
9
|
if (asset === void 0) {
|
|
@@ -20,10 +21,8 @@ const createImageValueTransformer = (assets, options) => (styleValue) => {
|
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
|
-
const generateCssText = (data, options) => {
|
|
24
|
-
const assets = new Map(
|
|
25
|
-
data.assets.map((asset) => [asset.id, asset])
|
|
26
|
-
);
|
|
24
|
+
export const generateCssText = (data, options) => {
|
|
25
|
+
const assets = new Map(data.assets.map((asset) => [asset.id, asset]));
|
|
27
26
|
const breakpoints = new Map(data.breakpoints);
|
|
28
27
|
const styles = new Map(data.styles);
|
|
29
28
|
const styleSourceSelections = new Map(data.styleSourceSelections);
|
|
@@ -58,7 +57,3 @@ const generateCssText = (data, options) => {
|
|
|
58
57
|
}
|
|
59
58
|
return engine.cssText;
|
|
60
59
|
};
|
|
61
|
-
export {
|
|
62
|
-
createImageValueTransformer,
|
|
63
|
-
generateCssText
|
|
64
|
-
};
|
package/lib/css/global-rules.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { getFontFaces } from "@webstudio-is/fonts";
|
|
2
|
-
const addGlobalRules = (engine, { assets, assetBaseUrl }) => {
|
|
3
|
+
export const addGlobalRules = (engine, { assets, assetBaseUrl }) => {
|
|
3
4
|
engine.addPlaintextRule("html {margin: 0; display: grid; min-height: 100%}");
|
|
4
5
|
const fontAssets = [];
|
|
5
6
|
for (const asset of assets.values()) {
|
|
6
|
-
if (asset
|
|
7
|
+
if (asset.type === "font") {
|
|
7
8
|
fontAssets.push(asset);
|
|
8
9
|
}
|
|
9
10
|
}
|
|
@@ -12,6 +13,3 @@ const addGlobalRules = (engine, { assets, assetBaseUrl }) => {
|
|
|
12
13
|
engine.addFontFaceRule(fontFace);
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
|
-
export {
|
|
16
|
-
addGlobalRules
|
|
17
|
-
};
|
package/lib/css/index.js
CHANGED
package/lib/css/normalize.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { borders, outline } from "./presets";
|
|
2
3
|
const boxSizing = {
|
|
3
4
|
property: "boxSizing",
|
|
4
5
|
value: { type: "keyword", value: "border-box" }
|
|
5
6
|
};
|
|
6
7
|
const baseStyle = [boxSizing, ...borders, ...outline];
|
|
7
|
-
const div = baseStyle;
|
|
8
|
-
const address = baseStyle;
|
|
9
|
-
const article = baseStyle;
|
|
10
|
-
const aside = baseStyle;
|
|
11
|
-
const figure = baseStyle;
|
|
12
|
-
const footer = baseStyle;
|
|
13
|
-
const header = baseStyle;
|
|
14
|
-
const main = baseStyle;
|
|
15
|
-
const nav = baseStyle;
|
|
16
|
-
const section = baseStyle;
|
|
17
|
-
const form = baseStyle;
|
|
18
|
-
const label = baseStyle;
|
|
19
|
-
const h1 = baseStyle;
|
|
20
|
-
const h2 = baseStyle;
|
|
21
|
-
const h3 = baseStyle;
|
|
22
|
-
const h4 = baseStyle;
|
|
23
|
-
const h5 = baseStyle;
|
|
24
|
-
const h6 = baseStyle;
|
|
25
|
-
const i = baseStyle;
|
|
26
|
-
const img = baseStyle;
|
|
27
|
-
const a = baseStyle;
|
|
28
|
-
const li = baseStyle;
|
|
29
|
-
const ul = baseStyle;
|
|
30
|
-
const ol = baseStyle;
|
|
31
|
-
const p = baseStyle;
|
|
32
|
-
const span = baseStyle;
|
|
33
|
-
const html = [
|
|
8
|
+
export const div = baseStyle;
|
|
9
|
+
export const address = baseStyle;
|
|
10
|
+
export const article = baseStyle;
|
|
11
|
+
export const aside = baseStyle;
|
|
12
|
+
export const figure = baseStyle;
|
|
13
|
+
export const footer = baseStyle;
|
|
14
|
+
export const header = baseStyle;
|
|
15
|
+
export const main = baseStyle;
|
|
16
|
+
export const nav = baseStyle;
|
|
17
|
+
export const section = baseStyle;
|
|
18
|
+
export const form = baseStyle;
|
|
19
|
+
export const label = baseStyle;
|
|
20
|
+
export const h1 = baseStyle;
|
|
21
|
+
export const h2 = baseStyle;
|
|
22
|
+
export const h3 = baseStyle;
|
|
23
|
+
export const h4 = baseStyle;
|
|
24
|
+
export const h5 = baseStyle;
|
|
25
|
+
export const h6 = baseStyle;
|
|
26
|
+
export const i = baseStyle;
|
|
27
|
+
export const img = baseStyle;
|
|
28
|
+
export const a = baseStyle;
|
|
29
|
+
export const li = baseStyle;
|
|
30
|
+
export const ul = baseStyle;
|
|
31
|
+
export const ol = baseStyle;
|
|
32
|
+
export const p = baseStyle;
|
|
33
|
+
export const span = baseStyle;
|
|
34
|
+
export const html = [
|
|
34
35
|
/* 1 */
|
|
35
36
|
{
|
|
36
37
|
property: "lineHeight",
|
|
@@ -49,7 +50,7 @@ const html = [
|
|
|
49
50
|
boxSizing,
|
|
50
51
|
...borders
|
|
51
52
|
];
|
|
52
|
-
const body = [
|
|
53
|
+
export const body = [
|
|
53
54
|
/* 1 */
|
|
54
55
|
{
|
|
55
56
|
property: "marginTop",
|
|
@@ -86,7 +87,7 @@ const body = [
|
|
|
86
87
|
boxSizing,
|
|
87
88
|
...borders
|
|
88
89
|
];
|
|
89
|
-
const hr = [
|
|
90
|
+
export const hr = [
|
|
90
91
|
/* 1 */
|
|
91
92
|
{
|
|
92
93
|
property: "height",
|
|
@@ -100,7 +101,7 @@ const hr = [
|
|
|
100
101
|
boxSizing,
|
|
101
102
|
...borders
|
|
102
103
|
];
|
|
103
|
-
const b = [
|
|
104
|
+
export const b = [
|
|
104
105
|
{
|
|
105
106
|
property: "fontWeight",
|
|
106
107
|
value: { type: "keyword", value: "700" }
|
|
@@ -108,8 +109,8 @@ const b = [
|
|
|
108
109
|
boxSizing,
|
|
109
110
|
...borders
|
|
110
111
|
];
|
|
111
|
-
const strong = b;
|
|
112
|
-
const code = [
|
|
112
|
+
export const strong = b;
|
|
113
|
+
export const code = [
|
|
113
114
|
/* 1 */
|
|
114
115
|
{
|
|
115
116
|
property: "fontFamily",
|
|
@@ -126,10 +127,10 @@ const code = [
|
|
|
126
127
|
boxSizing,
|
|
127
128
|
...borders
|
|
128
129
|
];
|
|
129
|
-
const kbd = code;
|
|
130
|
-
const samp = code;
|
|
131
|
-
const pre = code;
|
|
132
|
-
const small = [
|
|
130
|
+
export const kbd = code;
|
|
131
|
+
export const samp = code;
|
|
132
|
+
export const pre = code;
|
|
133
|
+
export const small = [
|
|
133
134
|
{
|
|
134
135
|
property: "fontSize",
|
|
135
136
|
value: { type: "unit", value: 80, unit: "%" }
|
|
@@ -157,21 +158,21 @@ const subSupBase = [
|
|
|
157
158
|
boxSizing,
|
|
158
159
|
...borders
|
|
159
160
|
];
|
|
160
|
-
const sub = [
|
|
161
|
+
export const sub = [
|
|
161
162
|
...subSupBase,
|
|
162
163
|
{
|
|
163
164
|
property: "bottom",
|
|
164
165
|
value: { type: "unit", value: -0.25, unit: "em" }
|
|
165
166
|
}
|
|
166
167
|
];
|
|
167
|
-
const sup = [
|
|
168
|
+
export const sup = [
|
|
168
169
|
...subSupBase,
|
|
169
170
|
{
|
|
170
171
|
property: "top",
|
|
171
172
|
value: { type: "unit", value: -0.5, unit: "em" }
|
|
172
173
|
}
|
|
173
174
|
];
|
|
174
|
-
const table = [
|
|
175
|
+
export const table = [
|
|
175
176
|
/* 1 */
|
|
176
177
|
{
|
|
177
178
|
property: "textIndent",
|
|
@@ -231,18 +232,18 @@ const buttonBase = [
|
|
|
231
232
|
boxSizing,
|
|
232
233
|
...borders
|
|
233
234
|
];
|
|
234
|
-
const input = buttonBase;
|
|
235
|
-
const optgroup = buttonBase;
|
|
236
|
-
const textarea = buttonBase;
|
|
237
|
-
const button = [
|
|
235
|
+
export const input = buttonBase;
|
|
236
|
+
export const optgroup = buttonBase;
|
|
237
|
+
export const textarea = buttonBase;
|
|
238
|
+
export const button = [
|
|
238
239
|
...buttonBase,
|
|
239
240
|
{
|
|
240
241
|
property: "textTransform",
|
|
241
242
|
value: { type: "keyword", value: "none" }
|
|
242
243
|
}
|
|
243
244
|
];
|
|
244
|
-
const select = button;
|
|
245
|
-
const legend = [
|
|
245
|
+
export const select = button;
|
|
246
|
+
export const legend = [
|
|
246
247
|
{
|
|
247
248
|
property: "paddingTop",
|
|
248
249
|
value: { type: "unit", value: 0, unit: "number" }
|
|
@@ -262,7 +263,7 @@ const legend = [
|
|
|
262
263
|
boxSizing,
|
|
263
264
|
...borders
|
|
264
265
|
];
|
|
265
|
-
const progress = [
|
|
266
|
+
export const progress = [
|
|
266
267
|
{
|
|
267
268
|
property: "verticalAlign",
|
|
268
269
|
value: { type: "keyword", value: "baseline" }
|
|
@@ -270,7 +271,7 @@ const progress = [
|
|
|
270
271
|
boxSizing,
|
|
271
272
|
...borders
|
|
272
273
|
];
|
|
273
|
-
const summary = [
|
|
274
|
+
export const summary = [
|
|
274
275
|
{
|
|
275
276
|
property: "display",
|
|
276
277
|
value: { type: "keyword", value: "list-item" }
|
|
@@ -278,52 +279,3 @@ const summary = [
|
|
|
278
279
|
boxSizing,
|
|
279
280
|
...borders
|
|
280
281
|
];
|
|
281
|
-
export {
|
|
282
|
-
a,
|
|
283
|
-
address,
|
|
284
|
-
article,
|
|
285
|
-
aside,
|
|
286
|
-
b,
|
|
287
|
-
body,
|
|
288
|
-
button,
|
|
289
|
-
code,
|
|
290
|
-
div,
|
|
291
|
-
figure,
|
|
292
|
-
footer,
|
|
293
|
-
form,
|
|
294
|
-
h1,
|
|
295
|
-
h2,
|
|
296
|
-
h3,
|
|
297
|
-
h4,
|
|
298
|
-
h5,
|
|
299
|
-
h6,
|
|
300
|
-
header,
|
|
301
|
-
hr,
|
|
302
|
-
html,
|
|
303
|
-
i,
|
|
304
|
-
img,
|
|
305
|
-
input,
|
|
306
|
-
kbd,
|
|
307
|
-
label,
|
|
308
|
-
legend,
|
|
309
|
-
li,
|
|
310
|
-
main,
|
|
311
|
-
nav,
|
|
312
|
-
ol,
|
|
313
|
-
optgroup,
|
|
314
|
-
p,
|
|
315
|
-
pre,
|
|
316
|
-
progress,
|
|
317
|
-
samp,
|
|
318
|
-
section,
|
|
319
|
-
select,
|
|
320
|
-
small,
|
|
321
|
-
span,
|
|
322
|
-
strong,
|
|
323
|
-
sub,
|
|
324
|
-
summary,
|
|
325
|
-
sup,
|
|
326
|
-
table,
|
|
327
|
-
textarea,
|
|
328
|
-
ul
|
|
329
|
-
};
|
package/lib/css/presets.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
export const borders = [
|
|
2
3
|
{
|
|
3
4
|
property: "borderTopWidth",
|
|
4
5
|
value: { type: "unit", value: 1, unit: "px" }
|
|
@@ -16,13 +17,9 @@ const borders = [
|
|
|
16
17
|
value: { type: "unit", value: 1, unit: "px" }
|
|
17
18
|
}
|
|
18
19
|
];
|
|
19
|
-
const outline = [
|
|
20
|
+
export const outline = [
|
|
20
21
|
{
|
|
21
22
|
property: "outlineWidth",
|
|
22
23
|
value: { type: "unit", value: 1, unit: "px" }
|
|
23
24
|
}
|
|
24
25
|
];
|
|
25
|
-
export {
|
|
26
|
-
borders,
|
|
27
|
-
outline
|
|
28
|
-
};
|
package/lib/css/style-rules.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { componentAttribute } from "../tree";
|
|
2
|
-
const getStyleRules = (styles, styleSourceSelections) => {
|
|
3
|
+
export const getStyleRules = (styles, styleSourceSelections) => {
|
|
3
4
|
if (styles === void 0 || styleSourceSelections === void 0) {
|
|
4
5
|
return [];
|
|
5
6
|
}
|
|
@@ -45,7 +46,7 @@ const getStyleRules = (styles, styleSourceSelections) => {
|
|
|
45
46
|
}
|
|
46
47
|
return styleRules;
|
|
47
48
|
};
|
|
48
|
-
const getPresetStyleRules = (component, presetStyle) => {
|
|
49
|
+
export const getPresetStyleRules = (component, presetStyle) => {
|
|
49
50
|
const presetStyleRules = /* @__PURE__ */ new Map();
|
|
50
51
|
for (const [tag, styles] of Object.entries(presetStyle)) {
|
|
51
52
|
for (const styleDecl of styles) {
|
|
@@ -60,7 +61,3 @@ const getPresetStyleRules = (component, presetStyle) => {
|
|
|
60
61
|
}
|
|
61
62
|
return presetStyleRules;
|
|
62
63
|
};
|
|
63
|
-
export {
|
|
64
|
-
getPresetStyleRules,
|
|
65
|
-
getStyleRules
|
|
66
|
-
};
|
|
@@ -1,92 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { test, expect } from "@jest/globals";
|
|
2
3
|
import {
|
|
3
|
-
getStyleDeclKey
|
|
4
|
-
|
|
5
|
-
Styles,
|
|
6
|
-
StyleSourceSelections,
|
|
7
|
-
} from "@webstudio-is/project-build";
|
|
4
|
+
getStyleDeclKey
|
|
5
|
+
} from "@webstudio-is/sdk";
|
|
8
6
|
import { getStyleRules } from "./style-rules";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return [getStyleDeclKey(styleDecl), styleDecl] as const;
|
|
7
|
+
const createStyleDeclPair = (styleDecl) => {
|
|
8
|
+
return [getStyleDeclKey(styleDecl), styleDecl];
|
|
12
9
|
};
|
|
13
|
-
|
|
14
10
|
test("compute styles from different style sources", () => {
|
|
15
|
-
const styles
|
|
11
|
+
const styles = new Map([
|
|
16
12
|
createStyleDeclPair({
|
|
17
13
|
breakpointId: "a",
|
|
18
14
|
styleSourceId: "styleSource1",
|
|
19
15
|
property: "width",
|
|
20
|
-
value: { type: "unit", value: 10, unit: "px" }
|
|
16
|
+
value: { type: "unit", value: 10, unit: "px" }
|
|
21
17
|
}),
|
|
22
18
|
createStyleDeclPair({
|
|
23
19
|
breakpointId: "a",
|
|
24
20
|
styleSourceId: "styleSource2",
|
|
25
21
|
property: "display",
|
|
26
|
-
value: { type: "keyword", value: "block" }
|
|
22
|
+
value: { type: "keyword", value: "block" }
|
|
27
23
|
}),
|
|
28
24
|
createStyleDeclPair({
|
|
29
25
|
breakpointId: "a",
|
|
30
26
|
styleSourceId: "styleSource4",
|
|
31
27
|
property: "color",
|
|
32
|
-
value: { type: "keyword", value: "green" }
|
|
28
|
+
value: { type: "keyword", value: "green" }
|
|
33
29
|
}),
|
|
34
30
|
createStyleDeclPair({
|
|
35
31
|
breakpointId: "a",
|
|
36
32
|
styleSourceId: "styleSource4",
|
|
37
33
|
property: "width",
|
|
38
|
-
value: { type: "keyword", value: "min-content" }
|
|
34
|
+
value: { type: "keyword", value: "min-content" }
|
|
39
35
|
}),
|
|
40
36
|
createStyleDeclPair({
|
|
41
37
|
breakpointId: "a",
|
|
42
38
|
styleSourceId: "styleSource3",
|
|
43
39
|
property: "color",
|
|
44
|
-
value: { type: "keyword", value: "red" }
|
|
40
|
+
value: { type: "keyword", value: "red" }
|
|
45
41
|
}),
|
|
46
42
|
createStyleDeclPair({
|
|
47
43
|
breakpointId: "b",
|
|
48
44
|
styleSourceId: "styleSource5",
|
|
49
45
|
property: "color",
|
|
50
|
-
value: { type: "keyword", value: "orange" }
|
|
46
|
+
value: { type: "keyword", value: "orange" }
|
|
51
47
|
}),
|
|
52
48
|
createStyleDeclPair({
|
|
53
49
|
breakpointId: "a",
|
|
54
50
|
styleSourceId: "styleSource6",
|
|
55
51
|
property: "color",
|
|
56
|
-
value: { type: "keyword", value: "blue" }
|
|
52
|
+
value: { type: "keyword", value: "blue" }
|
|
57
53
|
}),
|
|
58
54
|
createStyleDeclPair({
|
|
59
55
|
breakpointId: "a",
|
|
60
56
|
styleSourceId: "styleSource6",
|
|
61
57
|
state: ":hover",
|
|
62
58
|
property: "color",
|
|
63
|
-
value: { type: "keyword", value: "blue" }
|
|
64
|
-
})
|
|
59
|
+
value: { type: "keyword", value: "blue" }
|
|
60
|
+
})
|
|
65
61
|
]);
|
|
66
|
-
const styleSourceSelections
|
|
62
|
+
const styleSourceSelections = /* @__PURE__ */ new Map([
|
|
67
63
|
[
|
|
68
64
|
"instance1",
|
|
69
65
|
{
|
|
70
66
|
instanceId: "instance1",
|
|
71
|
-
values: ["styleSource1"]
|
|
72
|
-
}
|
|
67
|
+
values: ["styleSource1"]
|
|
68
|
+
}
|
|
73
69
|
],
|
|
74
70
|
[
|
|
75
71
|
"instance2",
|
|
76
72
|
{
|
|
77
73
|
instanceId: "instance2",
|
|
78
|
-
values: ["styleSource4", "styleSource5", "styleSource3"]
|
|
79
|
-
}
|
|
74
|
+
values: ["styleSource4", "styleSource5", "styleSource3"]
|
|
75
|
+
}
|
|
80
76
|
],
|
|
81
77
|
[
|
|
82
78
|
"instance3",
|
|
83
79
|
{
|
|
84
80
|
instanceId: "instance3",
|
|
85
|
-
values: ["styleSource6"]
|
|
86
|
-
}
|
|
87
|
-
]
|
|
81
|
+
values: ["styleSource6"]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
88
84
|
]);
|
|
89
|
-
|
|
90
85
|
expect(getStyleRules(styles, styleSourceSelections)).toMatchInlineSnapshot(`
|
|
91
86
|
[
|
|
92
87
|
{
|
package/lib/embed-template.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { nanoid } from "nanoid";
|
|
3
4
|
import { titleCase } from "title-case";
|
|
4
5
|
import { noCase } from "no-case";
|
|
5
|
-
import {
|
|
6
|
-
Instance,
|
|
7
|
-
PropsList,
|
|
8
|
-
StyleSourceSelectionsList,
|
|
9
|
-
StyleSourcesList,
|
|
10
|
-
StylesList,
|
|
11
|
-
Breakpoint,
|
|
12
|
-
DataSource
|
|
13
|
-
} from "@webstudio-is/project-build";
|
|
14
|
-
import { StyleValue } from "@webstudio-is/css-data";
|
|
6
|
+
import { StyleValue } from "@webstudio-is/css-engine";
|
|
15
7
|
import { encodeDataSourceVariable, validateExpression } from "./expression";
|
|
16
8
|
const EmbedTemplateText = z.object({
|
|
17
9
|
type: z.literal("text"),
|
|
@@ -76,8 +68,8 @@ const EmbedTemplateStyleDeclRaw = z.object({
|
|
|
76
68
|
property: z.string(),
|
|
77
69
|
value: StyleValue
|
|
78
70
|
});
|
|
79
|
-
const EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
|
|
80
|
-
const EmbedTemplateInstance = z.lazy(
|
|
71
|
+
export const EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
|
|
72
|
+
export const EmbedTemplateInstance = z.lazy(
|
|
81
73
|
() => z.object({
|
|
82
74
|
type: z.literal("instance"),
|
|
83
75
|
component: z.string(),
|
|
@@ -89,7 +81,7 @@ const EmbedTemplateInstance = z.lazy(
|
|
|
89
81
|
children: WsEmbedTemplate
|
|
90
82
|
})
|
|
91
83
|
);
|
|
92
|
-
const WsEmbedTemplate = z.lazy(
|
|
84
|
+
export const WsEmbedTemplate = z.lazy(
|
|
93
85
|
() => z.array(z.union([EmbedTemplateInstance, EmbedTemplateText]))
|
|
94
86
|
);
|
|
95
87
|
const getDataSourceValue = (value) => {
|
|
@@ -274,7 +266,7 @@ const createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceB
|
|
|
274
266
|
}
|
|
275
267
|
return parentChildren;
|
|
276
268
|
};
|
|
277
|
-
const generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId) => {
|
|
269
|
+
export const generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId) => {
|
|
278
270
|
const instances = [];
|
|
279
271
|
const props = [];
|
|
280
272
|
const dataSourceByRef = /* @__PURE__ */ new Map();
|
|
@@ -323,7 +315,7 @@ const namespaceEmbedTemplateComponents = (template, namespace, components) => {
|
|
|
323
315
|
throw Error("Impossible case");
|
|
324
316
|
});
|
|
325
317
|
};
|
|
326
|
-
const namespaceMeta = (meta, namespace, components) => {
|
|
318
|
+
export const namespaceMeta = (meta, namespace, components) => {
|
|
327
319
|
const newMeta = { ...meta };
|
|
328
320
|
if (newMeta.requiredAncestors) {
|
|
329
321
|
newMeta.requiredAncestors = newMeta.requiredAncestors.map(
|
|
@@ -347,10 +339,3 @@ const namespaceMeta = (meta, namespace, components) => {
|
|
|
347
339
|
}
|
|
348
340
|
return newMeta;
|
|
349
341
|
};
|
|
350
|
-
export {
|
|
351
|
-
EmbedTemplateInstance,
|
|
352
|
-
EmbedTemplateStyleDecl,
|
|
353
|
-
WsEmbedTemplate,
|
|
354
|
-
generateDataFromEmbedTemplate,
|
|
355
|
-
namespaceMeta
|
|
356
|
-
};
|