@webstudio-is/react-sdk 0.29.0 → 0.30.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/custom-components/index.js +12 -6
- package/lib/app/root.js +0 -2
- package/lib/cjs/app/custom-components/index.cjs +12 -6
- package/lib/cjs/app/root.cjs +0 -2
- package/lib/cjs/components/__generated__/body.props.json +557 -305
- package/lib/cjs/components/__generated__/bold.props.json +557 -305
- package/lib/cjs/components/__generated__/box.props.json +577 -320
- package/lib/cjs/components/__generated__/button.props.json +616 -339
- package/lib/cjs/components/__generated__/form.props.json +597 -329
- package/lib/cjs/components/__generated__/heading.props.json +566 -309
- package/lib/cjs/components/__generated__/image.props.json +638 -352
- package/lib/cjs/components/__generated__/input.props.json +725 -405
- package/lib/cjs/components/__generated__/italic.props.json +557 -305
- package/lib/cjs/components/__generated__/link.props.json +616 -343
- package/lib/cjs/components/__generated__/paragraph.props.json +557 -305
- package/lib/cjs/components/__generated__/rich-text-link.props.json +616 -343
- package/lib/cjs/components/__generated__/span.props.json +557 -305
- package/lib/cjs/components/__generated__/subscript.props.json +557 -305
- package/lib/cjs/components/__generated__/superscript.props.json +557 -305
- package/lib/cjs/components/__generated__/text-block.props.json +557 -305
- package/lib/cjs/components/body.ws.cjs +6 -3
- package/lib/cjs/components/bold.ws.cjs +7 -4
- package/lib/cjs/components/box.ws.cjs +8 -4
- package/lib/cjs/components/button.ws.cjs +8 -4
- package/lib/cjs/components/component-type.cjs +21 -56
- package/lib/cjs/components/form.ws.cjs +7 -4
- package/lib/cjs/components/heading.ws.cjs +8 -4
- package/lib/cjs/components/image.ws.cjs +11 -5
- package/lib/cjs/components/index.cjs +165 -111
- package/lib/cjs/components/input.ws.cjs +7 -4
- package/lib/cjs/components/italic.ws.cjs +7 -4
- package/lib/cjs/components/link.ws.cjs +8 -4
- package/lib/cjs/components/paragraph.ws.cjs +7 -4
- package/lib/cjs/components/rich-text-link.ws.cjs +7 -4
- package/lib/cjs/components/span.ws.cjs +7 -4
- package/lib/cjs/components/subscript.ws.cjs +7 -4
- package/lib/cjs/components/superscript.ws.cjs +7 -4
- package/lib/cjs/components/text-block.ws.cjs +7 -4
- package/lib/cjs/index.cjs +3 -2
- package/lib/cjs/tree/session-storage-polyfill.cjs +1 -1
- package/lib/components/__generated__/body.props.json +557 -305
- package/lib/components/__generated__/bold.props.json +557 -305
- package/lib/components/__generated__/box.props.json +577 -320
- package/lib/components/__generated__/button.props.json +616 -339
- package/lib/components/__generated__/form.props.json +597 -329
- package/lib/components/__generated__/heading.props.json +566 -309
- package/lib/components/__generated__/image.props.json +638 -352
- package/lib/components/__generated__/input.props.json +725 -405
- package/lib/components/__generated__/italic.props.json +557 -305
- package/lib/components/__generated__/link.props.json +616 -343
- package/lib/components/__generated__/paragraph.props.json +557 -305
- package/lib/components/__generated__/rich-text-link.props.json +616 -343
- package/lib/components/__generated__/span.props.json +557 -305
- package/lib/components/__generated__/subscript.props.json +557 -305
- package/lib/components/__generated__/superscript.props.json +557 -305
- package/lib/components/__generated__/text-block.props.json +557 -305
- package/lib/components/body.ws.js +6 -3
- package/lib/components/bold.ws.js +7 -4
- package/lib/components/box.ws.js +8 -4
- package/lib/components/button.ws.js +8 -4
- package/lib/components/component-type.js +21 -56
- package/lib/components/form.ws.js +7 -4
- package/lib/components/heading.ws.js +8 -4
- package/lib/components/image.ws.js +11 -5
- package/lib/components/index.js +117 -57
- package/lib/components/input.ws.js +7 -4
- package/lib/components/italic.ws.js +7 -4
- package/lib/components/link.ws.js +8 -4
- package/lib/components/paragraph.ws.js +7 -4
- package/lib/components/rich-text-link.ws.js +7 -4
- package/lib/components/span.ws.js +7 -4
- package/lib/components/subscript.ws.js +7 -4
- package/lib/components/superscript.ws.js +7 -4
- package/lib/components/text-block.ws.js +7 -4
- package/lib/index.js +5 -3
- package/lib/tree/session-storage-polyfill.js +1 -1
- package/package.json +8 -8
- package/src/app/custom-components/image.tsx +2 -2
- package/src/app/custom-components/index.ts +11 -5
- package/src/app/root.tsx +0 -2
- package/src/components/__generated__/body.props.json +557 -305
- package/src/components/__generated__/bold.props.json +557 -305
- package/src/components/__generated__/box.props.json +577 -320
- package/src/components/__generated__/button.props.json +616 -339
- package/src/components/__generated__/form.props.json +597 -329
- package/src/components/__generated__/heading.props.json +566 -309
- package/src/components/__generated__/image.props.json +638 -352
- package/src/components/__generated__/input.props.json +725 -405
- package/src/components/__generated__/italic.props.json +557 -305
- package/src/components/__generated__/link.props.json +616 -343
- package/src/components/__generated__/paragraph.props.json +557 -305
- package/src/components/__generated__/rich-text-link.props.json +616 -343
- package/src/components/__generated__/span.props.json +557 -305
- package/src/components/__generated__/subscript.props.json +557 -305
- package/src/components/__generated__/superscript.props.json +557 -305
- package/src/components/__generated__/text-block.props.json +557 -305
- package/src/components/body.ws.tsx +5 -4
- package/src/components/bold.ws.tsx +5 -4
- package/src/components/box.ws.ts +6 -4
- package/src/components/button.ws.tsx +6 -4
- package/src/components/component-type.ts +23 -63
- package/src/components/form.ws.tsx +5 -4
- package/src/components/heading.ws.tsx +6 -4
- package/src/components/image.ws.tsx +9 -5
- package/src/components/index.test.ts +2 -24
- package/src/components/index.ts +155 -81
- package/src/components/input.ws.tsx +5 -4
- package/src/components/italic.ws.tsx +5 -4
- package/src/components/link.ws.tsx +6 -4
- package/src/components/paragraph.ws.tsx +5 -4
- package/src/components/rich-text-link.ws.tsx +5 -4
- package/src/components/span.ws.tsx +5 -4
- package/src/components/subscript.ws.tsx +5 -4
- package/src/components/superscript.ws.tsx +5 -4
- package/src/components/text-block.ws.tsx +5 -4
- package/src/css/breakpoints.ts +1 -1
- package/src/index.ts +6 -2
- package/src/props.ts +1 -1
- package/src/tree/create-elements-tree.tsx +3 -3
- package/src/tree/session-storage-polyfill.tsx +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BodyIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/body.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
marginTop: {
|
|
@@ -53,10 +54,12 @@ const meta = {
|
|
|
53
54
|
type: "body",
|
|
54
55
|
label: "Body",
|
|
55
56
|
Icon: BodyIcon,
|
|
56
|
-
props,
|
|
57
57
|
presetStyle
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
60
|
+
props
|
|
61
|
+
});
|
|
60
62
|
export {
|
|
61
|
-
|
|
63
|
+
meta,
|
|
64
|
+
propsMeta
|
|
62
65
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { FontBoldIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/bold.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text-child",
|
|
5
6
|
label: "Bold Text",
|
|
6
|
-
Icon: FontBoldIcon
|
|
7
|
-
props
|
|
7
|
+
Icon: FontBoldIcon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
package/lib/components/box.ws.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SquareIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/box.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
boxSizing: {
|
|
@@ -10,10 +11,13 @@ const meta = {
|
|
|
10
11
|
type: "container",
|
|
11
12
|
label: "Box",
|
|
12
13
|
Icon: SquareIcon,
|
|
13
|
-
presetStyle
|
|
14
|
-
props
|
|
14
|
+
presetStyle
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
17
|
+
props,
|
|
18
|
+
initialProps: ["tag"]
|
|
19
|
+
});
|
|
17
20
|
export {
|
|
18
|
-
|
|
21
|
+
meta,
|
|
22
|
+
propsMeta
|
|
19
23
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { ButtonIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/button.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text",
|
|
5
6
|
label: "Button",
|
|
6
7
|
Icon: ButtonIcon,
|
|
7
|
-
children: ["Button text you can edit"]
|
|
8
|
-
props
|
|
8
|
+
children: ["Button text you can edit"]
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
11
|
+
props,
|
|
12
|
+
initialProps: ["type"]
|
|
13
|
+
});
|
|
11
14
|
export {
|
|
12
|
-
|
|
15
|
+
meta,
|
|
16
|
+
propsMeta
|
|
13
17
|
};
|
|
@@ -1,59 +1,24 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
required: z.boolean(),
|
|
22
|
-
defaultValue: z.boolean().nullable()
|
|
23
|
-
}),
|
|
24
|
-
z.object({
|
|
25
|
-
type: z.enum([
|
|
26
|
-
"radio",
|
|
27
|
-
"inline-radio",
|
|
28
|
-
"check",
|
|
29
|
-
"inline-check",
|
|
30
|
-
"multi-select",
|
|
31
|
-
"select"
|
|
32
|
-
]),
|
|
33
|
-
required: z.boolean(),
|
|
34
|
-
options: z.array(z.string()),
|
|
35
|
-
defaultValue: z.string().nullable()
|
|
36
|
-
})
|
|
37
|
-
])
|
|
38
|
-
);
|
|
39
|
-
const WsComponentMeta = z.lazy(
|
|
40
|
-
() => z.object({
|
|
41
|
-
type: z.enum([
|
|
42
|
-
"body",
|
|
43
|
-
"container",
|
|
44
|
-
"control",
|
|
45
|
-
"embed",
|
|
46
|
-
"rich-text",
|
|
47
|
-
"rich-text-child"
|
|
48
|
-
]),
|
|
49
|
-
label: z.string(),
|
|
50
|
-
Icon: z.any(),
|
|
51
|
-
presetStyle: z.optional(z.any()),
|
|
52
|
-
children: z.optional(z.array(z.string())),
|
|
53
|
-
props: Props,
|
|
54
|
-
initialProps: z.optional(z.array(z.string()))
|
|
55
|
-
})
|
|
56
|
-
);
|
|
2
|
+
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
3
|
+
const WsComponentPropsMeta = z.object({
|
|
4
|
+
props: z.record(PropMeta),
|
|
5
|
+
initialProps: z.array(z.string()).optional()
|
|
6
|
+
});
|
|
7
|
+
const WsComponentMeta = z.object({
|
|
8
|
+
type: z.enum([
|
|
9
|
+
"body",
|
|
10
|
+
"container",
|
|
11
|
+
"control",
|
|
12
|
+
"embed",
|
|
13
|
+
"rich-text",
|
|
14
|
+
"rich-text-child"
|
|
15
|
+
]),
|
|
16
|
+
label: z.string(),
|
|
17
|
+
Icon: z.any(),
|
|
18
|
+
presetStyle: z.optional(z.any()),
|
|
19
|
+
children: z.optional(z.array(z.string()))
|
|
20
|
+
});
|
|
57
21
|
export {
|
|
58
|
-
WsComponentMeta
|
|
22
|
+
WsComponentMeta,
|
|
23
|
+
WsComponentPropsMeta
|
|
59
24
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/form.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
minHeight: {
|
|
@@ -15,10 +16,12 @@ const meta = {
|
|
|
15
16
|
type: "container",
|
|
16
17
|
label: "Form",
|
|
17
18
|
Icon: FormIcon,
|
|
18
|
-
presetStyle
|
|
19
|
-
props
|
|
19
|
+
presetStyle
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
22
|
+
props
|
|
23
|
+
});
|
|
22
24
|
export {
|
|
23
|
-
|
|
25
|
+
meta,
|
|
26
|
+
propsMeta
|
|
24
27
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { HeadingIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/heading.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text",
|
|
5
6
|
label: "Heading",
|
|
6
7
|
Icon: HeadingIcon,
|
|
7
|
-
children: ["Heading you can edit"]
|
|
8
|
-
props
|
|
8
|
+
children: ["Heading you can edit"]
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
11
|
+
props,
|
|
12
|
+
initialProps: ["tag"]
|
|
13
|
+
});
|
|
11
14
|
export {
|
|
12
|
-
|
|
15
|
+
meta,
|
|
16
|
+
propsMeta
|
|
13
17
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ImageIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/image.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
maxWidth: {
|
|
@@ -15,11 +16,16 @@ const meta = {
|
|
|
15
16
|
type: "embed",
|
|
16
17
|
label: "Image",
|
|
17
18
|
Icon: ImageIcon,
|
|
18
|
-
presetStyle
|
|
19
|
-
props,
|
|
20
|
-
initialProps: ["src", "width", "height", "alt", "loading"]
|
|
19
|
+
presetStyle
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
22
|
+
props: {
|
|
23
|
+
...props,
|
|
24
|
+
src: { ...props.src, control: "file-image", name: "Source" }
|
|
25
|
+
},
|
|
26
|
+
initialProps: ["src", "width", "height", "alt", "loading"]
|
|
27
|
+
});
|
|
23
28
|
export {
|
|
24
|
-
|
|
29
|
+
meta,
|
|
30
|
+
propsMeta
|
|
25
31
|
};
|
package/lib/components/index.js
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
1
|
+
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
2
|
+
import { meta as BodyMeta } from "./body.ws";
|
|
3
|
+
import { meta as BoxMeta } from "./box.ws";
|
|
4
|
+
import { meta as TextBlockMeta } from "./text-block.ws";
|
|
5
|
+
import { meta as HeadingMeta } from "./heading.ws";
|
|
6
|
+
import { meta as ParagraphMeta } from "./paragraph.ws";
|
|
7
|
+
import { meta as LinkMeta } from "./link.ws";
|
|
8
|
+
import { meta as RichTextLinkMeta } from "./rich-text-link.ws";
|
|
9
|
+
import { meta as SpanMeta } from "./span.ws";
|
|
10
|
+
import { meta as BoldMeta } from "./bold.ws";
|
|
11
|
+
import { meta as ItalicMeta } from "./italic.ws";
|
|
12
|
+
import { meta as SuperscriptMeta } from "./superscript.ws";
|
|
13
|
+
import { meta as SubscriptMeta } from "./subscript.ws";
|
|
14
|
+
import { meta as ButtonMeta } from "./button.ws";
|
|
15
|
+
import { meta as InputMeta } from "./input.ws";
|
|
16
|
+
import { meta as FormMeta } from "./form.ws";
|
|
17
|
+
import { meta as ImageMeta } from "./image.ws";
|
|
18
|
+
import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
|
|
19
|
+
import { propsMeta as BoxMetaPropsMeta } from "./box.ws";
|
|
20
|
+
import { propsMeta as TextBlockMetaPropsMeta } from "./text-block.ws";
|
|
21
|
+
import { propsMeta as HeadingMetaPropsMeta } from "./heading.ws";
|
|
22
|
+
import { propsMeta as ParagraphMetaPropsMeta } from "./paragraph.ws";
|
|
23
|
+
import { propsMeta as LinkMetaPropsMeta } from "./link.ws";
|
|
24
|
+
import { propsMeta as RichTextLinkMetaPropsMeta } from "./rich-text-link.ws";
|
|
25
|
+
import { propsMeta as SpanMetaPropsMeta } from "./span.ws";
|
|
26
|
+
import { propsMeta as BoldMetaPropsMeta } from "./bold.ws";
|
|
27
|
+
import { propsMeta as ItalicMetaPropsMeta } from "./italic.ws";
|
|
28
|
+
import { propsMeta as SuperscriptMetaPropsMeta } from "./superscript.ws";
|
|
29
|
+
import { propsMeta as SubscriptMetaPropsMeta } from "./subscript.ws";
|
|
30
|
+
import { propsMeta as ButtonMetaPropsMeta } from "./button.ws";
|
|
31
|
+
import { propsMeta as InputMetaPropsMeta } from "./input.ws";
|
|
32
|
+
import { propsMeta as FormMetaPropsMeta } from "./form.ws";
|
|
33
|
+
import { propsMeta as ImageMetaPropsMeta } from "./image.ws";
|
|
17
34
|
import { Body } from "./body";
|
|
18
35
|
import { Box } from "./box";
|
|
19
36
|
import { TextBlock } from "./text-block";
|
|
@@ -30,7 +47,7 @@ import { Button } from "./button";
|
|
|
30
47
|
import { Input } from "./input";
|
|
31
48
|
import { Form } from "./form";
|
|
32
49
|
import { Image } from "./image";
|
|
33
|
-
const
|
|
50
|
+
const defaultMetas = {
|
|
34
51
|
Box: BoxMeta,
|
|
35
52
|
Body: BodyMeta,
|
|
36
53
|
TextBlock: TextBlockMeta,
|
|
@@ -48,7 +65,60 @@ const meta = {
|
|
|
48
65
|
Form: FormMeta,
|
|
49
66
|
Image: ImageMeta
|
|
50
67
|
};
|
|
51
|
-
|
|
68
|
+
let currentMetas = defaultMetas;
|
|
69
|
+
const getComponentMeta = (name) => {
|
|
70
|
+
return currentMetas[name];
|
|
71
|
+
};
|
|
72
|
+
const registerComponentMetas = (overrides) => {
|
|
73
|
+
const result = {};
|
|
74
|
+
for (const name of Object.keys(defaultMetas)) {
|
|
75
|
+
result[name] = { ...defaultMetas[name], ...overrides[name] };
|
|
76
|
+
}
|
|
77
|
+
currentMetas = result;
|
|
78
|
+
};
|
|
79
|
+
const defaultPropsMetas = {
|
|
80
|
+
Box: BoxMetaPropsMeta,
|
|
81
|
+
Body: BodyMetaPropsMeta,
|
|
82
|
+
TextBlock: TextBlockMetaPropsMeta,
|
|
83
|
+
Heading: HeadingMetaPropsMeta,
|
|
84
|
+
Paragraph: ParagraphMetaPropsMeta,
|
|
85
|
+
Link: LinkMetaPropsMeta,
|
|
86
|
+
RichTextLink: RichTextLinkMetaPropsMeta,
|
|
87
|
+
Span: SpanMetaPropsMeta,
|
|
88
|
+
Bold: BoldMetaPropsMeta,
|
|
89
|
+
Italic: ItalicMetaPropsMeta,
|
|
90
|
+
Superscript: SuperscriptMetaPropsMeta,
|
|
91
|
+
Subscript: SubscriptMetaPropsMeta,
|
|
92
|
+
Button: ButtonMetaPropsMeta,
|
|
93
|
+
Input: InputMetaPropsMeta,
|
|
94
|
+
Form: FormMetaPropsMeta,
|
|
95
|
+
Image: ImageMetaPropsMeta
|
|
96
|
+
};
|
|
97
|
+
let registeredPropsMetas = {};
|
|
98
|
+
let currentPropsMetas = void 0;
|
|
99
|
+
const getComponentPropsMeta = (name) => {
|
|
100
|
+
if (currentPropsMetas === void 0) {
|
|
101
|
+
currentPropsMetas = {};
|
|
102
|
+
for (const name2 of Object.keys(defaultPropsMetas)) {
|
|
103
|
+
const props = computeProps(
|
|
104
|
+
defaultPropsMetas[name2],
|
|
105
|
+
registeredPropsMetas[name2] ?? {}
|
|
106
|
+
);
|
|
107
|
+
const initialProps = computeInitialProps(
|
|
108
|
+
props,
|
|
109
|
+
defaultPropsMetas[name2],
|
|
110
|
+
registeredPropsMetas[name2] ?? {}
|
|
111
|
+
);
|
|
112
|
+
currentPropsMetas[name2] = { props, initialProps };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return currentPropsMetas[name];
|
|
116
|
+
};
|
|
117
|
+
const registerComponentPropsMetas = (metas) => {
|
|
118
|
+
registeredPropsMetas = metas;
|
|
119
|
+
currentPropsMetas = void 0;
|
|
120
|
+
};
|
|
121
|
+
const defaultComponents = {
|
|
52
122
|
Box,
|
|
53
123
|
Body,
|
|
54
124
|
TextBlock,
|
|
@@ -67,8 +137,7 @@ const components = {
|
|
|
67
137
|
Image
|
|
68
138
|
};
|
|
69
139
|
let registeredComponents = null;
|
|
70
|
-
|
|
71
|
-
const componentNames = Object.keys(components);
|
|
140
|
+
const componentNames = Object.keys(defaultComponents);
|
|
72
141
|
const getComponentNames = () => {
|
|
73
142
|
const uniqueNames = /* @__PURE__ */ new Set([
|
|
74
143
|
...componentNames,
|
|
@@ -76,51 +145,42 @@ const getComponentNames = () => {
|
|
|
76
145
|
]);
|
|
77
146
|
return [...uniqueNames.values()];
|
|
78
147
|
};
|
|
79
|
-
const getComponentMeta = (name) => {
|
|
80
|
-
const componentMeta = meta[name];
|
|
81
|
-
if (registeredComponentsMeta != null && name in registeredComponentsMeta) {
|
|
82
|
-
return {
|
|
83
|
-
...componentMeta,
|
|
84
|
-
...registeredComponentsMeta[name]
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return componentMeta;
|
|
88
|
-
};
|
|
89
148
|
const getComponent = (name) => {
|
|
90
|
-
return registeredComponents != null && name in registeredComponents ? registeredComponents[name] :
|
|
149
|
+
return registeredComponents != null && name in registeredComponents ? registeredComponents[name] : defaultComponents[name];
|
|
150
|
+
};
|
|
151
|
+
const registerComponents = (components) => {
|
|
152
|
+
registeredComponents = components;
|
|
91
153
|
};
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
...registeredComponentMeta?.props?.[key],
|
|
105
|
-
defaultValue: registeredComponentMeta?.props?.[key]?.defaultValue ?? componentMeta?.props[key]?.defaultValue ?? null,
|
|
106
|
-
required: registeredComponentMeta?.props?.[key]?.required || componentMeta?.props[key]?.required
|
|
107
|
-
};
|
|
154
|
+
const computeProps = (defaults, overrides) => {
|
|
155
|
+
if (overrides) {
|
|
156
|
+
const allNames = (/* @__PURE__ */ new Set([
|
|
157
|
+
...Object.keys(defaults.props ?? {}),
|
|
158
|
+
...Object.keys(overrides?.props ?? {})
|
|
159
|
+
])).values();
|
|
160
|
+
const result = {};
|
|
161
|
+
for (const name of allNames) {
|
|
162
|
+
result[name] = PropMeta.parse({
|
|
163
|
+
...defaults.props[name],
|
|
164
|
+
...overrides?.props?.[name]
|
|
165
|
+
});
|
|
108
166
|
}
|
|
109
|
-
return
|
|
167
|
+
return result;
|
|
110
168
|
}
|
|
111
|
-
return
|
|
112
|
-
};
|
|
113
|
-
const registerComponents = (components2) => {
|
|
114
|
-
registeredComponents = components2;
|
|
169
|
+
return defaults.props;
|
|
115
170
|
};
|
|
116
|
-
const
|
|
117
|
-
|
|
171
|
+
const computeInitialProps = (props, defaults, overrides) => {
|
|
172
|
+
const initialProps = overrides?.initialProps ?? defaults?.initialProps ?? [];
|
|
173
|
+
const requiredProps = props ? Object.entries(props).filter(
|
|
174
|
+
([name, value]) => value?.type.required && initialProps.includes(name) === false
|
|
175
|
+
).map(([name]) => name) : [];
|
|
176
|
+
return [...initialProps, ...requiredProps];
|
|
118
177
|
};
|
|
119
178
|
export {
|
|
120
179
|
getComponent,
|
|
121
180
|
getComponentMeta,
|
|
122
|
-
getComponentMetaProps,
|
|
123
181
|
getComponentNames,
|
|
124
|
-
|
|
125
|
-
|
|
182
|
+
getComponentPropsMeta,
|
|
183
|
+
registerComponentMetas,
|
|
184
|
+
registerComponentPropsMetas,
|
|
185
|
+
registerComponents
|
|
126
186
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { InputIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/input.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "control",
|
|
5
6
|
label: "Input",
|
|
6
|
-
Icon: InputIcon
|
|
7
|
-
props
|
|
7
|
+
Icon: InputIcon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FontItalicIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/italic.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
fontStyle: {
|
|
@@ -10,10 +11,12 @@ const meta = {
|
|
|
10
11
|
type: "rich-text-child",
|
|
11
12
|
label: "Italic Text",
|
|
12
13
|
Icon: FontItalicIcon,
|
|
13
|
-
presetStyle
|
|
14
|
-
props
|
|
14
|
+
presetStyle
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
17
|
+
props
|
|
18
|
+
});
|
|
17
19
|
export {
|
|
18
|
-
|
|
20
|
+
meta,
|
|
21
|
+
propsMeta
|
|
19
22
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Link2Icon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/link.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
minHeight: {
|
|
@@ -16,10 +17,13 @@ const meta = {
|
|
|
16
17
|
label: "Link",
|
|
17
18
|
Icon: Link2Icon,
|
|
18
19
|
presetStyle,
|
|
19
|
-
children: ["Link text you can edit"]
|
|
20
|
-
props
|
|
20
|
+
children: ["Link text you can edit"]
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
23
|
+
props,
|
|
24
|
+
initialProps: ["href"]
|
|
25
|
+
});
|
|
23
26
|
export {
|
|
24
|
-
|
|
27
|
+
meta,
|
|
28
|
+
propsMeta
|
|
25
29
|
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { TextAlignLeftIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/paragraph.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text",
|
|
5
6
|
label: "Paragraph",
|
|
6
7
|
Icon: TextAlignLeftIcon,
|
|
7
|
-
children: ["Pragraph you can edit"]
|
|
8
|
-
props
|
|
8
|
+
children: ["Pragraph you can edit"]
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
11
|
+
props
|
|
12
|
+
});
|
|
11
13
|
export {
|
|
12
|
-
|
|
14
|
+
meta,
|
|
15
|
+
propsMeta
|
|
13
16
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Link2Icon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/rich-text-link.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text-child",
|
|
5
6
|
label: "Link",
|
|
6
|
-
Icon: Link2Icon
|
|
7
|
-
props
|
|
7
|
+
Icon: Link2Icon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { BrushIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/span.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text-child",
|
|
5
6
|
label: "Styled Text",
|
|
6
|
-
Icon: BrushIcon
|
|
7
|
-
props
|
|
7
|
+
Icon: BrushIcon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { SubscriptIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/subscript.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text-child",
|
|
5
6
|
label: "Subscript Text",
|
|
6
|
-
Icon: SubscriptIcon
|
|
7
|
-
props
|
|
7
|
+
Icon: SubscriptIcon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { SuperscriptIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/superscript.props.json";
|
|
3
4
|
const meta = {
|
|
4
5
|
type: "rich-text-child",
|
|
5
6
|
label: "Superscript Text",
|
|
6
|
-
Icon: SuperscriptIcon
|
|
7
|
-
props
|
|
7
|
+
Icon: SuperscriptIcon
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
10
|
+
props
|
|
11
|
+
});
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
meta,
|
|
14
|
+
propsMeta
|
|
12
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TextIcon } from "@webstudio-is/icons";
|
|
2
|
+
import { WsComponentPropsMeta } from "./component-type";
|
|
2
3
|
import props from "./__generated__/text-block.props.json";
|
|
3
4
|
const presetStyle = {
|
|
4
5
|
minHeight: {
|
|
@@ -12,10 +13,12 @@ const meta = {
|
|
|
12
13
|
label: "Text Block",
|
|
13
14
|
Icon: TextIcon,
|
|
14
15
|
presetStyle,
|
|
15
|
-
children: ["Block of text you can edit"]
|
|
16
|
-
props
|
|
16
|
+
children: ["Block of text you can edit"]
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const propsMeta = WsComponentPropsMeta.parse({
|
|
19
|
+
props
|
|
20
|
+
});
|
|
19
21
|
export {
|
|
20
|
-
|
|
22
|
+
meta,
|
|
23
|
+
propsMeta
|
|
21
24
|
};
|
package/lib/index.js
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./pubsub";
|
|
|
5
5
|
export * from "./app";
|
|
6
6
|
import {
|
|
7
7
|
customComponents,
|
|
8
|
-
|
|
8
|
+
customComponentMetas,
|
|
9
|
+
customComponentPropsMetas
|
|
9
10
|
} from "./app/custom-components";
|
|
10
11
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
customComponentMetas,
|
|
13
|
+
customComponentPropsMetas,
|
|
14
|
+
customComponents
|
|
13
15
|
};
|