@webstudio-is/react-sdk 0.68.0 → 0.69.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.
Files changed (184) hide show
  1. package/lib/cjs/components/__generated__/image.props.js +6 -3
  2. package/lib/cjs/components/__generated__/text-block.props.js +7 -0
  3. package/lib/cjs/components/blockquote.ws.js +9 -2
  4. package/lib/cjs/components/box.ws.js +2 -1
  5. package/lib/cjs/components/button.ws.js +3 -1
  6. package/lib/cjs/components/checkbox-field.ws.js +12 -6
  7. package/lib/cjs/components/checkbox.ws.js +1 -0
  8. package/lib/cjs/components/code-text.ws.js +8 -1
  9. package/lib/cjs/components/component-meta.js +6 -3
  10. package/lib/cjs/components/components-utils.js +0 -28
  11. package/lib/cjs/components/form.ws.js +32 -25
  12. package/lib/cjs/components/fragment.ws.js +2 -1
  13. package/lib/cjs/components/heading.ws.js +10 -3
  14. package/lib/cjs/components/html-embed.ws.js +3 -1
  15. package/lib/cjs/components/image.js +27 -19
  16. package/lib/cjs/components/image.ws.js +4 -2
  17. package/lib/cjs/components/index.js +1 -29
  18. package/lib/cjs/components/input.ws.js +1 -0
  19. package/lib/cjs/components/label.ws.js +8 -1
  20. package/lib/cjs/components/link-block.ws.js +2 -1
  21. package/lib/cjs/components/link.ws.js +8 -1
  22. package/lib/cjs/components/list-item.ws.js +11 -4
  23. package/lib/cjs/components/list.ws.js +2 -2
  24. package/lib/cjs/components/paragraph.ws.js +10 -3
  25. package/lib/cjs/components/radio-button-field.ws.js +12 -6
  26. package/lib/cjs/components/radio-button.ws.js +1 -0
  27. package/lib/cjs/components/rich-text-link.ws.js +1 -1
  28. package/lib/cjs/components/separator.ws.js +1 -1
  29. package/lib/cjs/components/slot.ws.js +3 -1
  30. package/lib/cjs/components/text-block.js +5 -2
  31. package/lib/cjs/components/text-block.ws.js +11 -3
  32. package/lib/cjs/components/textarea.ws.js +1 -0
  33. package/lib/cjs/embed-template.js +2 -1
  34. package/lib/cjs/index.js +4 -5
  35. package/lib/cjs/tree/create-elements-tree.js +8 -8
  36. package/lib/cjs/tree/root.js +2 -6
  37. package/lib/cjs/tree/webstudio-component.js +2 -2
  38. package/lib/components/__generated__/image.props.js +6 -3
  39. package/lib/components/__generated__/text-block.props.js +7 -0
  40. package/lib/components/blockquote.ws.js +9 -2
  41. package/lib/components/box.ws.js +2 -1
  42. package/lib/components/button.ws.js +3 -1
  43. package/lib/components/checkbox-field.ws.js +12 -6
  44. package/lib/components/checkbox.ws.js +1 -0
  45. package/lib/components/code-text.ws.js +8 -1
  46. package/lib/components/component-meta.js +6 -3
  47. package/lib/components/components-utils.js +0 -14
  48. package/lib/components/form.ws.js +32 -25
  49. package/lib/components/fragment.ws.js +2 -1
  50. package/lib/components/heading.ws.js +10 -3
  51. package/lib/components/html-embed.ws.js +3 -1
  52. package/lib/components/image.js +34 -20
  53. package/lib/components/image.ws.js +4 -2
  54. package/lib/components/index.js +1 -29
  55. package/lib/components/input.ws.js +1 -0
  56. package/lib/components/label.ws.js +8 -1
  57. package/lib/components/link-block.ws.js +2 -1
  58. package/lib/components/link.ws.js +8 -1
  59. package/lib/components/list-item.ws.js +11 -4
  60. package/lib/components/list.ws.js +2 -2
  61. package/lib/components/paragraph.ws.js +10 -3
  62. package/lib/components/radio-button-field.ws.js +12 -6
  63. package/lib/components/radio-button.ws.js +1 -0
  64. package/lib/components/rich-text-link.ws.js +1 -1
  65. package/lib/components/separator.ws.js +1 -1
  66. package/lib/components/slot.ws.js +3 -1
  67. package/lib/components/text-block.js +9 -3
  68. package/lib/components/text-block.ws.js +11 -3
  69. package/lib/components/textarea.ws.js +1 -0
  70. package/lib/embed-template.js +2 -1
  71. package/lib/index.js +4 -9
  72. package/lib/tree/create-elements-tree.js +8 -8
  73. package/lib/tree/root.js +2 -6
  74. package/lib/tree/webstudio-component.js +2 -2
  75. package/lib/types/components/component-meta.d.ts +363 -1356
  76. package/lib/types/components/components-utils.d.ts +2 -17
  77. package/lib/types/components/image.d.ts +5 -1
  78. package/lib/types/components/image.stories.d.ts +10 -2
  79. package/lib/types/components/index.d.ts +0 -15
  80. package/lib/types/components/text-block.d.ts +6 -2
  81. package/lib/types/components/text-block.stories.d.ts +6 -2
  82. package/lib/types/css/css.d.ts +14 -4
  83. package/lib/types/css/global-rules.d.ts +14 -4
  84. package/lib/types/css/normalize.d.ts +611 -611
  85. package/lib/types/css/style-rules.d.ts +2 -187
  86. package/lib/types/embed-template.d.ts +543 -167
  87. package/lib/types/index.d.ts +2 -2
  88. package/lib/types/props.d.ts +44 -18
  89. package/lib/types/tree/create-elements-tree.d.ts +4 -4
  90. package/lib/types/tree/root.d.ts +3 -5
  91. package/lib/types/tree/webstudio-component.d.ts +3 -3
  92. package/package.json +24 -13
  93. package/src/components/__generated__/image.props.ts +5 -2
  94. package/src/components/__generated__/text-block.props.ts +7 -0
  95. package/src/components/blockquote.ws.tsx +9 -2
  96. package/src/components/box.tsx +1 -1
  97. package/src/components/box.ws.ts +1 -0
  98. package/src/components/button.ws.tsx +2 -0
  99. package/src/components/checkbox-field.ws.tsx +12 -6
  100. package/src/components/checkbox.ws.tsx +1 -0
  101. package/src/components/code-text.ws.tsx +8 -1
  102. package/src/components/component-meta.ts +6 -3
  103. package/src/components/components-utils.ts +2 -31
  104. package/src/components/form.ws.tsx +32 -25
  105. package/src/components/fragment.ws.ts +1 -0
  106. package/src/components/heading.tsx +1 -1
  107. package/src/components/heading.ws.tsx +9 -2
  108. package/src/components/html-embed.ws.ts +2 -0
  109. package/src/components/image.tsx +54 -26
  110. package/src/components/image.ws.tsx +5 -1
  111. package/src/components/index.ts +0 -48
  112. package/src/components/input.ws.tsx +1 -0
  113. package/src/components/label.ws.tsx +8 -1
  114. package/src/components/link-block.ws.tsx +1 -0
  115. package/src/components/link.ws.tsx +8 -1
  116. package/src/components/list-item.ws.tsx +10 -3
  117. package/src/components/list.ws.tsx +2 -2
  118. package/src/components/paragraph.ws.tsx +9 -2
  119. package/src/components/radio-button-field.ws.tsx +12 -6
  120. package/src/components/radio-button.ws.tsx +1 -0
  121. package/src/components/rich-text-link.ws.tsx +1 -1
  122. package/src/components/separator.ws.tsx +1 -1
  123. package/src/components/slot.ws.ts +2 -0
  124. package/src/components/text-block.tsx +16 -5
  125. package/src/components/text-block.ws.tsx +10 -2
  126. package/src/components/textarea.ws.tsx +1 -0
  127. package/src/embed-template.ts +11 -3
  128. package/src/index.ts +2 -5
  129. package/src/props.test.ts +0 -1
  130. package/src/tree/create-elements-tree.tsx +12 -12
  131. package/src/tree/root.ts +4 -9
  132. package/src/tree/webstudio-component.tsx +4 -4
  133. package/lib/app/custom-components/__generated__/form.props.js +0 -411
  134. package/lib/app/custom-components/__generated__/image.props.js +0 -442
  135. package/lib/app/custom-components/__generated__/link-block.props.js +0 -432
  136. package/lib/app/custom-components/__generated__/link.props.js +0 -432
  137. package/lib/app/custom-components/__generated__/rich-text-link.props.js +0 -432
  138. package/lib/app/custom-components/form.js +0 -65
  139. package/lib/app/custom-components/form.ws.js +0 -81
  140. package/lib/app/custom-components/image.js +0 -40
  141. package/lib/app/custom-components/index.js +0 -29
  142. package/lib/app/custom-components/link-block.js +0 -6
  143. package/lib/app/custom-components/link.js +0 -6
  144. package/lib/app/custom-components/rich-text-link.js +0 -6
  145. package/lib/app/custom-components/shared/remix-link.js +0 -22
  146. package/lib/cjs/app/custom-components/__generated__/form.props.js +0 -431
  147. package/lib/cjs/app/custom-components/__generated__/image.props.js +0 -462
  148. package/lib/cjs/app/custom-components/__generated__/link-block.props.js +0 -452
  149. package/lib/cjs/app/custom-components/__generated__/link.props.js +0 -452
  150. package/lib/cjs/app/custom-components/__generated__/rich-text-link.props.js +0 -452
  151. package/lib/cjs/app/custom-components/form.js +0 -81
  152. package/lib/cjs/app/custom-components/form.ws.js +0 -101
  153. package/lib/cjs/app/custom-components/image.js +0 -54
  154. package/lib/cjs/app/custom-components/index.js +0 -49
  155. package/lib/cjs/app/custom-components/link-block.js +0 -26
  156. package/lib/cjs/app/custom-components/link.js +0 -26
  157. package/lib/cjs/app/custom-components/rich-text-link.js +0 -26
  158. package/lib/cjs/app/custom-components/shared/remix-link.js +0 -42
  159. package/lib/types/app/custom-components/__generated__/form.props.d.ts +0 -2
  160. package/lib/types/app/custom-components/__generated__/image.props.d.ts +0 -2
  161. package/lib/types/app/custom-components/__generated__/link-block.props.d.ts +0 -2
  162. package/lib/types/app/custom-components/__generated__/link.props.d.ts +0 -2
  163. package/lib/types/app/custom-components/__generated__/rich-text-link.props.d.ts +0 -2
  164. package/lib/types/app/custom-components/form.d.ts +0 -5
  165. package/lib/types/app/custom-components/form.ws.d.ts +0 -3
  166. package/lib/types/app/custom-components/image.d.ts +0 -6
  167. package/lib/types/app/custom-components/index.d.ts +0 -31
  168. package/lib/types/app/custom-components/link-block.d.ts +0 -6
  169. package/lib/types/app/custom-components/link.d.ts +0 -6
  170. package/lib/types/app/custom-components/rich-text-link.d.ts +0 -6
  171. package/lib/types/app/custom-components/shared/remix-link.d.ts +0 -10
  172. package/src/app/custom-components/__generated__/form.props.ts +0 -456
  173. package/src/app/custom-components/__generated__/image.props.ts +0 -487
  174. package/src/app/custom-components/__generated__/link-block.props.ts +0 -477
  175. package/src/app/custom-components/__generated__/link.props.ts +0 -477
  176. package/src/app/custom-components/__generated__/rich-text-link.props.ts +0 -477
  177. package/src/app/custom-components/form.tsx +0 -111
  178. package/src/app/custom-components/form.ws.tsx +0 -86
  179. package/src/app/custom-components/image.tsx +0 -55
  180. package/src/app/custom-components/index.ts +0 -28
  181. package/src/app/custom-components/link-block.tsx +0 -4
  182. package/src/app/custom-components/link.tsx +0 -4
  183. package/src/app/custom-components/rich-text-link.tsx +0 -4
  184. package/src/app/custom-components/shared/remix-link.tsx +0 -28
@@ -17,7 +17,8 @@ const meta = {
17
17
  label: "Link Block",
18
18
  icon: LinkBlockIcon,
19
19
  states: linkMeta.states,
20
- presetStyle
20
+ presetStyle,
21
+ order: 2
21
22
  };
22
23
  const propsMeta = {
23
24
  props: {
@@ -23,6 +23,7 @@ const meta = {
23
23
  label: "Link Text",
24
24
  icon: LinkIcon,
25
25
  presetStyle,
26
+ order: 1,
26
27
  states: [
27
28
  ...defaultStates,
28
29
  {
@@ -35,7 +36,13 @@ const meta = {
35
36
  label: "Current page"
36
37
  }
37
38
  ],
38
- children: [{ type: "text", value: "Link text you can edit" }]
39
+ template: [
40
+ {
41
+ type: "instance",
42
+ component: "Link",
43
+ children: [{ type: "text", value: "Link text you can edit" }]
44
+ }
45
+ ]
39
46
  };
40
47
  const propsMeta = {
41
48
  props: {
@@ -8,14 +8,21 @@ const presetStyle = {
8
8
  li
9
9
  };
10
10
  const meta = {
11
- category: "typography",
11
+ category: "general",
12
12
  type: "rich-text",
13
- acceptedParents: ["List"],
13
+ requiredAncestors: ["List"],
14
14
  label: "List Item",
15
15
  icon: ListItemIcon,
16
- children: [{ type: "text", value: "List Item you can edit" }],
17
16
  states: defaultStates,
18
- presetStyle
17
+ presetStyle,
18
+ template: [
19
+ {
20
+ type: "instance",
21
+ component: "ListItem",
22
+ children: [{ type: "text", value: "List Item you can edit" }]
23
+ }
24
+ ],
25
+ order: 4
19
26
  };
20
27
  const propsMeta = {
21
28
  props
@@ -37,13 +37,13 @@ const presetStyle = {
37
37
  ]
38
38
  };
39
39
  const meta = {
40
- category: "typography",
40
+ category: "general",
41
41
  type: "container",
42
42
  label: "List",
43
43
  icon: ListIcon,
44
44
  states: defaultStates,
45
45
  presetStyle,
46
- children: []
46
+ order: 3
47
47
  };
48
48
  const propsMeta = {
49
49
  props,
@@ -8,13 +8,20 @@ const presetStyle = {
8
8
  p
9
9
  };
10
10
  const meta = {
11
- category: "typography",
11
+ category: "text",
12
12
  type: "rich-text",
13
13
  label: "Paragraph",
14
14
  icon: TextAlignLeftIcon,
15
- children: [{ type: "text", value: "Pragraph you can edit" }],
16
15
  states: defaultStates,
17
- presetStyle
16
+ presetStyle,
17
+ template: [
18
+ {
19
+ type: "instance",
20
+ component: "Paragraph",
21
+ children: [{ type: "text", value: "Pragraph you can edit" }]
22
+ }
23
+ ],
24
+ order: 2
18
25
  };
19
26
  const propsMeta = {
20
27
  props
@@ -17,14 +17,20 @@ const meta = {
17
17
  icon: RadioCheckedIcon,
18
18
  states: defaultStates,
19
19
  presetStyle,
20
- children: [
21
- { type: "instance", component: "RadioButton", props: [], children: [] },
20
+ template: [
22
21
  {
23
22
  type: "instance",
24
- component: "TextBlock",
25
- label: "Radio Label",
26
- props: [],
27
- children: [{ type: "text", value: "Radio" }]
23
+ component: "RadioButtonField",
24
+ children: [
25
+ { type: "instance", component: "RadioButton", props: [], children: [] },
26
+ {
27
+ type: "instance",
28
+ component: "TextBlock",
29
+ label: "Radio Label",
30
+ props: [],
31
+ children: [{ type: "text", value: "Radio" }]
32
+ }
33
+ ]
28
34
  }
29
35
  ]
30
36
  };
@@ -18,6 +18,7 @@ const meta = {
18
18
  label: "Radio Input",
19
19
  icon: RadioCheckedIcon,
20
20
  presetStyle,
21
+ order: 5,
21
22
  states: [
22
23
  ...defaultStates,
23
24
  { selector: ":checked", label: "Checked" },
@@ -4,7 +4,7 @@ const { category, ...linkMetaRest } = linkMeta;
4
4
  const meta = {
5
5
  ...linkMetaRest,
6
6
  type: "rich-text-child",
7
- children: []
7
+ template: []
8
8
  };
9
9
  const propsMeta = {
10
10
  initialProps: linkPropsMeta.initialProps,
@@ -40,7 +40,7 @@ const meta = {
40
40
  icon: DashIcon,
41
41
  states: defaultStates,
42
42
  presetStyle,
43
- children: []
43
+ order: 5
44
44
  };
45
45
  const propsMeta = {
46
46
  props,
@@ -3,7 +3,9 @@ const meta = {
3
3
  category: "general",
4
4
  type: "container",
5
5
  label: "Slot",
6
- icon: SlotComponentIcon
6
+ icon: SlotComponentIcon,
7
+ stylable: false,
8
+ order: 6
7
9
  };
8
10
  const propsMeta = {
9
11
  props: {}
@@ -1,7 +1,13 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
1
+ import {
2
+ createElement,
3
+ forwardRef
4
+ } from "react";
3
5
  const defaultTag = "div";
4
- const TextBlock = forwardRef((props, ref) => /* @__PURE__ */ jsx("div", { ...props, ref }));
6
+ const TextBlock = forwardRef(
7
+ ({ tag = defaultTag, ...props }, ref) => {
8
+ return createElement(tag, { ...props, ref });
9
+ }
10
+ );
5
11
  TextBlock.displayName = "TextBlock";
6
12
  export {
7
13
  TextBlock,
@@ -14,16 +14,24 @@ const presetStyle = {
14
14
  ]
15
15
  };
16
16
  const meta = {
17
- category: "typography",
17
+ category: "text",
18
18
  type: "rich-text",
19
19
  label: "Text Block",
20
20
  icon: TextBlockIcon,
21
21
  states: defaultStates,
22
22
  presetStyle,
23
- children: [{ type: "text", value: "Block of text you can edit" }]
23
+ template: [
24
+ {
25
+ type: "instance",
26
+ component: "TextBlock",
27
+ children: [{ type: "text", value: "Block of text you can edit" }]
28
+ }
29
+ ],
30
+ order: 0
24
31
  };
25
32
  const propsMeta = {
26
- props
33
+ props,
34
+ initialProps: ["tag"]
27
35
  };
28
36
  export {
29
37
  meta,
@@ -17,6 +17,7 @@ const meta = {
17
17
  label: "Text Area",
18
18
  icon: FormTextAreaIcon,
19
19
  presetStyle,
20
+ order: 4,
20
21
  states: [
21
22
  ...defaultStates,
22
23
  { selector: "::placeholder", label: "Placeholder" },
@@ -27,11 +27,12 @@ const EmbedTemplateProp = z.union([
27
27
  value: z.array(z.string())
28
28
  })
29
29
  ]);
30
- const EmbedTemplateStyleDecl = z.object({
30
+ const EmbedTemplateStyleDeclRaw = z.object({
31
31
  state: z.optional(z.string()),
32
32
  property: z.string(),
33
33
  value: StyleValue
34
34
  });
35
+ const EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
35
36
  const EmbedTemplateInstance = z.lazy(
36
37
  () => z.object({
37
38
  type: z.literal("instance"),
package/lib/index.js CHANGED
@@ -5,20 +5,15 @@ export * from "./pubsub";
5
5
  export * from "./app";
6
6
  export * from "./components/components";
7
7
  export * from "./components/components-utils";
8
- import {
9
- customComponents,
10
- customComponentMetas,
11
- customComponentPropsMetas
12
- } from "./app/custom-components";
13
8
  import {
14
9
  componentCategories,
15
10
  stateCategories
16
11
  } from "./components/component-meta";
17
12
  export * from "./embed-template";
13
+ import { usePropUrl, getInstanceIdFromComponentProps } from "./props";
18
14
  export {
19
15
  componentCategories,
20
- customComponentMetas,
21
- customComponentPropsMetas,
22
- customComponents,
23
- stateCategories
16
+ getInstanceIdFromComponentProps,
17
+ stateCategories,
18
+ usePropUrl
24
19
  };
@@ -10,7 +10,7 @@ const createElementsTree = ({
10
10
  assetsStore,
11
11
  pagesStore,
12
12
  Component,
13
- getComponent
13
+ components
14
14
  }) => {
15
15
  const rootInstance = instances.get(rootInstanceId);
16
16
  if (rootInstance === void 0) {
@@ -22,7 +22,7 @@ const createElementsTree = ({
22
22
  instanceSelector: rootInstanceSelector,
23
23
  Component,
24
24
  children: rootInstance.children,
25
- getComponent
25
+ components
26
26
  });
27
27
  const root = createInstanceElement({
28
28
  Component,
@@ -35,7 +35,7 @@ const createElementsTree = ({
35
35
  /* @__PURE__ */ jsx(Scripts, {})
36
36
  ] }, "children")
37
37
  ],
38
- getComponent
38
+ components
39
39
  });
40
40
  return /* @__PURE__ */ jsx(
41
41
  ReactSdkContext.Provider,
@@ -50,7 +50,7 @@ const createInstanceChildrenElements = ({
50
50
  instanceSelector,
51
51
  children,
52
52
  Component,
53
- getComponent
53
+ components
54
54
  }) => {
55
55
  const elements = [];
56
56
  for (const child of children) {
@@ -68,14 +68,14 @@ const createInstanceChildrenElements = ({
68
68
  instanceSelector: childInstanceSelector,
69
69
  children: childInstance.children,
70
70
  Component,
71
- getComponent
71
+ components
72
72
  });
73
73
  const element = createInstanceElement({
74
74
  instance: childInstance,
75
75
  instanceSelector: childInstanceSelector,
76
76
  Component,
77
77
  children: children2,
78
- getComponent
78
+ components
79
79
  });
80
80
  elements.push(element);
81
81
  }
@@ -86,14 +86,14 @@ const createInstanceElement = ({
86
86
  instance,
87
87
  instanceSelector,
88
88
  children = [],
89
- getComponent
89
+ components
90
90
  }) => {
91
91
  return /* @__PURE__ */ jsx(
92
92
  Component,
93
93
  {
94
94
  instance,
95
95
  instanceSelector,
96
- getComponent,
96
+ components,
97
97
  children
98
98
  },
99
99
  instance.id
package/lib/tree/root.js CHANGED
@@ -1,18 +1,14 @@
1
1
  import { atom } from "nanostores";
2
2
  import { createElementsTree } from "./create-elements-tree";
3
3
  import { WebstudioComponent } from "./webstudio-component";
4
- import { registerComponents } from "../components";
5
- import { customComponents as defaultCustomComponents } from "../app/custom-components";
6
4
  import { setParams } from "../app/params";
7
5
  import { getPropsByInstanceId } from "../props";
8
6
  const InstanceRoot = ({
9
7
  data,
10
8
  Component,
11
- customComponents = defaultCustomComponents,
12
- getComponent
9
+ components
13
10
  }) => {
14
11
  setParams(data.params);
15
- registerComponents(customComponents);
16
12
  return createElementsTree({
17
13
  instances: new Map(data.build.instances),
18
14
  rootInstanceId: data.page.rootInstanceId,
@@ -22,7 +18,7 @@ const InstanceRoot = ({
22
18
  assetsStore: atom(new Map(data.assets.map((asset) => [asset.id, asset]))),
23
19
  pagesStore: atom(new Map(data.pages.map((page) => [page.id, page]))),
24
20
  Component: Component ?? WebstudioComponent,
25
- getComponent
21
+ components
26
22
  });
27
23
  };
28
24
  export {
@@ -20,7 +20,7 @@ const WebstudioComponent = ({
20
20
  instance,
21
21
  instanceSelector,
22
22
  children,
23
- getComponent,
23
+ components,
24
24
  ...rest
25
25
  }) => {
26
26
  const instanceProps = useInstanceProps(instance.id);
@@ -30,7 +30,7 @@ const WebstudioComponent = ({
30
30
  [idAttribute]: instance.id,
31
31
  [componentAttribute]: instance.component
32
32
  };
33
- const Component = getComponent(instance.component);
33
+ const Component = components.get(instance.component);
34
34
  if (Component === void 0) {
35
35
  return /* @__PURE__ */ jsx(Fragment, {});
36
36
  }