@webstudio-is/react-sdk 0.65.0 → 0.66.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 (155) hide show
  1. package/lib/app/custom-components/form.ws.js +2 -2
  2. package/lib/app/custom-components/image.js +7 -13
  3. package/lib/app/params.js +1 -0
  4. package/lib/cjs/app/custom-components/form.ws.js +2 -2
  5. package/lib/cjs/app/custom-components/image.js +3 -12
  6. package/lib/cjs/app/params.js +1 -0
  7. package/lib/cjs/components/__generated__/html.props.js +31 -0
  8. package/lib/cjs/components/blockquote.ws.js +2 -2
  9. package/lib/cjs/components/body.ws.js +2 -2
  10. package/lib/cjs/components/bold.ws.js +2 -2
  11. package/lib/cjs/components/box.ws.js +2 -2
  12. package/lib/cjs/components/button.ws.js +2 -2
  13. package/lib/cjs/components/checkbox-field.ws.js +2 -2
  14. package/lib/cjs/components/checkbox.ws.js +2 -2
  15. package/lib/cjs/components/code.ws.js +2 -2
  16. package/lib/cjs/components/component-meta.js +2 -2
  17. package/lib/cjs/components/components-utils.js +1 -43
  18. package/lib/cjs/components/components.js +2 -0
  19. package/lib/cjs/components/error-message.ws.js +2 -2
  20. package/lib/cjs/components/form.ws.js +2 -2
  21. package/lib/cjs/components/fragment.ws.js +1 -1
  22. package/lib/cjs/components/heading.ws.js +2 -2
  23. package/lib/cjs/components/html.js +80 -0
  24. package/lib/cjs/components/html.ws.js +43 -0
  25. package/lib/cjs/components/image.ws.js +2 -2
  26. package/lib/cjs/components/index.js +7 -53
  27. package/lib/cjs/components/input.ws.js +2 -2
  28. package/lib/cjs/components/italic.ws.js +2 -2
  29. package/lib/cjs/components/label.ws.js +2 -2
  30. package/lib/cjs/components/link-block.ws.js +2 -2
  31. package/lib/cjs/components/link.ws.js +2 -2
  32. package/lib/cjs/components/list-item.ws.js +2 -2
  33. package/lib/cjs/components/list.ws.js +2 -2
  34. package/lib/cjs/components/paragraph.ws.js +2 -2
  35. package/lib/cjs/components/radio-button-field.ws.js +2 -2
  36. package/lib/cjs/components/radio-button.ws.js +2 -2
  37. package/lib/cjs/components/separator.ws.js +2 -2
  38. package/lib/cjs/components/slot.ws.js +2 -2
  39. package/lib/cjs/components/span.ws.js +2 -2
  40. package/lib/cjs/components/subscript.ws.js +2 -2
  41. package/lib/cjs/components/success-message.ws.js +2 -2
  42. package/lib/cjs/components/superscript.ws.js +2 -2
  43. package/lib/cjs/components/text-block.ws.js +2 -2
  44. package/lib/cjs/components/textarea.ws.js +2 -2
  45. package/lib/cjs/css/css.js +2 -5
  46. package/lib/cjs/css/normalize.js +1 -1
  47. package/lib/cjs/css/presets.js +8 -1
  48. package/lib/cjs/tree/create-elements-tree.js +2 -4
  49. package/lib/components/__generated__/html.props.js +11 -0
  50. package/lib/components/blockquote.ws.js +2 -2
  51. package/lib/components/body.ws.js +2 -2
  52. package/lib/components/bold.ws.js +2 -2
  53. package/lib/components/box.ws.js +2 -2
  54. package/lib/components/button.ws.js +2 -2
  55. package/lib/components/checkbox-field.ws.js +2 -2
  56. package/lib/components/checkbox.ws.js +2 -2
  57. package/lib/components/code.ws.js +2 -2
  58. package/lib/components/component-meta.js +3 -3
  59. package/lib/components/components-utils.js +1 -43
  60. package/lib/components/components.js +2 -0
  61. package/lib/components/error-message.ws.js +2 -2
  62. package/lib/components/form.ws.js +2 -2
  63. package/lib/components/fragment.ws.js +1 -1
  64. package/lib/components/heading.ws.js +2 -2
  65. package/lib/components/html.js +65 -0
  66. package/lib/components/html.ws.js +23 -0
  67. package/lib/components/image.ws.js +2 -2
  68. package/lib/components/index.js +7 -53
  69. package/lib/components/input.ws.js +2 -2
  70. package/lib/components/italic.ws.js +2 -2
  71. package/lib/components/label.ws.js +2 -2
  72. package/lib/components/link-block.ws.js +2 -2
  73. package/lib/components/link.ws.js +2 -2
  74. package/lib/components/list-item.ws.js +2 -2
  75. package/lib/components/list.ws.js +2 -2
  76. package/lib/components/paragraph.ws.js +2 -2
  77. package/lib/components/radio-button-field.ws.js +2 -2
  78. package/lib/components/radio-button.ws.js +2 -2
  79. package/lib/components/separator.ws.js +2 -2
  80. package/lib/components/slot.ws.js +2 -2
  81. package/lib/components/span.ws.js +2 -2
  82. package/lib/components/subscript.ws.js +2 -2
  83. package/lib/components/success-message.ws.js +2 -2
  84. package/lib/components/superscript.ws.js +2 -2
  85. package/lib/components/text-block.ws.js +2 -2
  86. package/lib/components/textarea.ws.js +2 -2
  87. package/lib/css/css.js +2 -5
  88. package/lib/css/normalize.js +2 -2
  89. package/lib/css/presets.js +8 -1
  90. package/lib/tree/create-elements-tree.js +2 -4
  91. package/lib/types/app/params.d.ts +22 -1
  92. package/lib/types/components/__generated__/html.props.d.ts +2 -0
  93. package/lib/types/components/component-meta.d.ts +1785 -10
  94. package/lib/types/components/components-utils.d.ts +6 -3
  95. package/lib/types/components/components.d.ts +1 -0
  96. package/lib/types/components/html.d.ts +7 -0
  97. package/lib/types/components/html.stories.d.ts +11 -0
  98. package/lib/types/components/html.ws.d.ts +3 -0
  99. package/lib/types/components/index.d.ts +2 -2
  100. package/lib/types/context.d.ts +1 -0
  101. package/lib/types/css/css.d.ts +2 -0
  102. package/lib/types/css/presets.d.ts +1 -0
  103. package/lib/types/tree/create-elements-tree.d.ts +2 -2
  104. package/package.json +13 -12
  105. package/src/app/custom-components/form.ws.tsx +2 -2
  106. package/src/app/custom-components/image.tsx +7 -13
  107. package/src/app/params.ts +23 -1
  108. package/src/components/__generated__/html.props.ts +10 -0
  109. package/src/components/blockquote.ws.tsx +2 -2
  110. package/src/components/body.ws.tsx +2 -2
  111. package/src/components/bold.ws.tsx +2 -2
  112. package/src/components/box.ws.ts +2 -2
  113. package/src/components/button.ws.tsx +2 -2
  114. package/src/components/checkbox-field.ws.tsx +2 -2
  115. package/src/components/checkbox.ws.tsx +2 -2
  116. package/src/components/code.ws.tsx +2 -2
  117. package/src/components/component-meta.ts +3 -6
  118. package/src/components/components-utils.ts +14 -58
  119. package/src/components/components.ts +1 -0
  120. package/src/components/error-message.ws.tsx +2 -2
  121. package/src/components/form.ws.tsx +2 -2
  122. package/src/components/fragment.ws.ts +1 -1
  123. package/src/components/heading.ws.tsx +2 -2
  124. package/src/components/html.stories.tsx +16 -0
  125. package/src/components/html.tsx +96 -0
  126. package/src/components/html.ws.ts +22 -0
  127. package/src/components/image.ws.tsx +2 -2
  128. package/src/components/index.ts +6 -83
  129. package/src/components/input.ws.tsx +2 -2
  130. package/src/components/italic.ws.tsx +2 -2
  131. package/src/components/label.ws.tsx +2 -2
  132. package/src/components/link-block.ws.tsx +2 -2
  133. package/src/components/link.ws.tsx +2 -2
  134. package/src/components/list-item.ws.tsx +2 -2
  135. package/src/components/list.ws.tsx +2 -2
  136. package/src/components/paragraph.ws.tsx +2 -2
  137. package/src/components/radio-button-field.ws.tsx +2 -2
  138. package/src/components/radio-button.ws.tsx +2 -2
  139. package/src/components/separator.ws.tsx +2 -2
  140. package/src/components/slot.ws.ts +2 -2
  141. package/src/components/span.ws.tsx +2 -2
  142. package/src/components/subscript.ws.tsx +2 -2
  143. package/src/components/success-message.ws.tsx +2 -2
  144. package/src/components/superscript.ws.tsx +2 -2
  145. package/src/components/text-block.ws.tsx +2 -2
  146. package/src/components/textarea.ws.tsx +2 -2
  147. package/src/context.tsx +1 -0
  148. package/src/css/css.ts +4 -5
  149. package/src/css/normalize.ts +2 -2
  150. package/src/css/presets.ts +7 -0
  151. package/src/tree/create-elements-tree.tsx +3 -5
  152. package/lib/cjs/tree/session-storage-polyfill.js +0 -65
  153. package/lib/tree/session-storage-polyfill.js +0 -45
  154. package/lib/types/tree/session-storage-polyfill.d.ts +0 -2
  155. package/src/tree/session-storage-polyfill.tsx +0 -50
@@ -0,0 +1,96 @@
1
+ import {
2
+ forwardRef,
3
+ useContext,
4
+ useEffect,
5
+ useRef,
6
+ type ForwardedRef,
7
+ } from "react";
8
+ import { mergeRefs } from "@react-aria/utils";
9
+ import { ReactSdkContext } from "../context";
10
+
11
+ type Props = {
12
+ code: string;
13
+ executeScriptInCanvas: boolean;
14
+ };
15
+
16
+ type ChildProps = {
17
+ innerRef: ForwardedRef<HTMLDivElement>;
18
+ // code can be actually undefined when prop is not provided
19
+ code?: string;
20
+ };
21
+
22
+ /**
23
+ * Scripts are executed when rendered client side.
24
+ * Necessary on canvas which does not have server rendering.
25
+ */
26
+ const ExecutableHtml = (props: ChildProps) => {
27
+ const { code, innerRef, ...rest } = props;
28
+ const containerRef = useRef<HTMLDivElement>(null);
29
+
30
+ useEffect(() => {
31
+ const container = containerRef.current;
32
+ if (container === null || code === undefined) {
33
+ return;
34
+ }
35
+ // the trick to execute inserted scripts
36
+ // https://ghinda.net/article/script-tags
37
+ const range = document.createRange();
38
+ range.setStart(container, 0);
39
+ const fragment = range.createContextualFragment(code);
40
+ while (container.firstChild) {
41
+ container.removeChild(container.firstChild);
42
+ }
43
+ container.append(fragment);
44
+ }, [code]);
45
+
46
+ return (
47
+ <div
48
+ {...rest}
49
+ ref={mergeRefs(innerRef, containerRef)}
50
+ style={{ display: "contents" }}
51
+ />
52
+ );
53
+ };
54
+
55
+ /**
56
+ * Scripts are executed when rendered server side
57
+ */
58
+ const InnerHtml = (props: ChildProps) => {
59
+ const { code, innerRef, ...rest } = props;
60
+
61
+ return (
62
+ <div
63
+ {...rest}
64
+ ref={innerRef}
65
+ style={{ display: "contents" }}
66
+ dangerouslySetInnerHTML={{ __html: props.code ?? "" }}
67
+ />
68
+ );
69
+ };
70
+
71
+ const Placeholder = (props: ChildProps) => {
72
+ const { code, innerRef, ...rest } = props;
73
+ return (
74
+ <div ref={innerRef} {...rest} style={{ padding: "20px" }}>
75
+ {'Paste html into "Code" prop'}
76
+ </div>
77
+ );
78
+ };
79
+
80
+ export const Html = forwardRef<HTMLDivElement, Props>((props, ref) => {
81
+ const { renderer } = useContext(ReactSdkContext);
82
+ const { code, executeScriptInCanvas, ...rest } = props;
83
+
84
+ // code can be actually undefined when prop is not provided
85
+ if (code === undefined || code.trim().length === 0) {
86
+ return <Placeholder innerRef={ref} {...rest} />;
87
+ }
88
+
89
+ if (renderer === "canvas" && executeScriptInCanvas === true) {
90
+ return <ExecutableHtml innerRef={ref} code={code} {...rest} />;
91
+ }
92
+
93
+ return <InnerHtml innerRef={ref} code={code} {...rest} />;
94
+ });
95
+
96
+ Html.displayName = "Html";
@@ -0,0 +1,22 @@
1
+ import { CodeIcon } from "@webstudio-is/icons/svg";
2
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import { props } from "./__generated__/html.props";
4
+
5
+ export const meta: WsComponentMeta = {
6
+ category: "general",
7
+ type: "embed",
8
+ label: "Html",
9
+ icon: CodeIcon,
10
+ };
11
+
12
+ export const propsMeta: WsComponentPropsMeta = {
13
+ props: {
14
+ ...props,
15
+ code: {
16
+ required: true,
17
+ control: "code",
18
+ type: "string",
19
+ rows: 10,
20
+ },
21
+ },
22
+ };
@@ -1,4 +1,4 @@
1
- import { ImageIcon } from "@webstudio-is/icons";
1
+ import { ImageIcon } from "@webstudio-is/icons/svg";
2
2
  import { img } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -31,7 +31,7 @@ export const meta: WsComponentMeta = {
31
31
  category: "media",
32
32
  type: "embed",
33
33
  label: "Image",
34
- Icon: ImageIcon,
34
+ icon: ImageIcon,
35
35
  states: defaultStates,
36
36
  presetStyle,
37
37
  };
@@ -1,8 +1,8 @@
1
- import { PropMeta } from "@webstudio-is/generate-arg-types";
2
1
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
2
  import type { ComponentName } from "./components-utils";
4
3
  import { meta as SlotMeta } from "./slot.ws";
5
4
  import { meta as FragmentMeta } from "./fragment.ws";
5
+ import { meta as HtmlMeta } from "./html.ws";
6
6
  import { meta as BodyMeta } from "./body.ws";
7
7
  import { meta as BoxMeta } from "./box.ws";
8
8
  import { meta as TextBlockMeta } from "./text-block.ws";
@@ -37,6 +37,7 @@ import { meta as CheckboxMeta } from "./checkbox.ws";
37
37
  // these are huge JSON objects that we want to be tree-shaken when not used!
38
38
  import { propsMeta as SlotMetaPropsMeta } from "./slot.ws";
39
39
  import { propsMeta as FragmentMetaPropsMeta } from "./fragment.ws";
40
+ import { propsMeta as HtmlMetaPropsMeta } from "./html.ws";
40
41
  import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
41
42
  import { propsMeta as BoxMetaPropsMeta } from "./box.ws";
42
43
  import { propsMeta as TextBlockMetaPropsMeta } from "./text-block.ws";
@@ -69,9 +70,10 @@ import { propsMeta as CheckboxFieldPropsMeta } from "./checkbox-field.ws";
69
70
  import { propsMeta as CheckboxPropsMeta } from "./checkbox.ws";
70
71
 
71
72
  // @todo this list should not be hardcoded!
72
- const defaultMetas: Record<string, WsComponentMeta> = {
73
+ export const defaultMetas: Record<string, WsComponentMeta> = {
73
74
  Slot: SlotMeta,
74
75
  Fragment: FragmentMeta,
76
+ Html: HtmlMeta,
75
77
  Box: BoxMeta,
76
78
  Body: BodyMeta,
77
79
  TextBlock: TextBlockMeta,
@@ -121,9 +123,10 @@ export const registerComponentMetas = (
121
123
  };
122
124
 
123
125
  // @todo this list should not be hardcoded!
124
- const defaultPropsMetasRaw = {
126
+ export const defaultPropsMetas: Record<string, WsComponentPropsMeta> = {
125
127
  Slot: SlotMetaPropsMeta,
126
128
  Fragment: FragmentMetaPropsMeta,
129
+ Html: HtmlMetaPropsMeta,
127
130
  Box: BoxMetaPropsMeta,
128
131
  Body: BodyMetaPropsMeta,
129
132
  TextBlock: TextBlockMetaPropsMeta,
@@ -154,44 +157,6 @@ const defaultPropsMetasRaw = {
154
157
  RadioButton: RadioButtonPropsMeta,
155
158
  CheckboxField: CheckboxFieldPropsMeta,
156
159
  Checkbox: CheckboxPropsMeta,
157
- } as const;
158
-
159
- const defaultPropsMetas: Record<string, WsComponentPropsMeta> =
160
- defaultPropsMetasRaw;
161
-
162
- let registeredPropsMetas: Record<string, Partial<WsComponentPropsMeta>> = {};
163
-
164
- // we start as `undefined` because pre-computing will likely kill tree-shaking
165
- let currentPropsMetas: Record<string, WsComponentPropsMeta> | undefined =
166
- undefined;
167
-
168
- export const getComponentPropsMeta = (
169
- name: string
170
- ): WsComponentPropsMeta | undefined => {
171
- if (currentPropsMetas === undefined) {
172
- currentPropsMetas = {};
173
- for (const name of Object.keys(defaultPropsMetas)) {
174
- const props = computeProps(
175
- defaultPropsMetas[name],
176
- registeredPropsMetas[name] ?? {}
177
- );
178
- const initialProps = computeInitialProps(
179
- props,
180
- defaultPropsMetas[name],
181
- registeredPropsMetas[name] ?? {}
182
- );
183
- currentPropsMetas[name] = { props, initialProps };
184
- }
185
- }
186
-
187
- return currentPropsMetas[name];
188
- };
189
-
190
- export const registerComponentPropsMetas = (
191
- metas: Record<string, WsComponentPropsMeta>
192
- ) => {
193
- registeredPropsMetas = metas;
194
- currentPropsMetas = undefined;
195
160
  };
196
161
 
197
162
  type RegisteredComponents = Partial<{
@@ -210,48 +175,6 @@ export const registerComponents = (components: RegisteredComponents) => {
210
175
  registeredComponents = components;
211
176
  };
212
177
 
213
- const computeProps = (
214
- defaults: WsComponentPropsMeta,
215
- overrides: Partial<WsComponentPropsMeta>
216
- ) => {
217
- if (overrides) {
218
- const allNames = new Set([
219
- ...Object.keys(defaults.props ?? {}),
220
- ...Object.keys(overrides?.props ?? {}),
221
- ]).values();
222
-
223
- const result: WsComponentPropsMeta["props"] = {};
224
- for (const name of allNames) {
225
- result[name] = PropMeta.parse({
226
- ...defaults.props[name],
227
- ...overrides?.props?.[name],
228
- });
229
- }
230
- return result;
231
- }
232
-
233
- return defaults.props;
234
- };
235
-
236
- const computeInitialProps = (
237
- props: WsComponentPropsMeta["props"],
238
- defaults: WsComponentPropsMeta,
239
- overrides: Partial<WsComponentPropsMeta>
240
- ): Array<string> => {
241
- const initialProps = overrides?.initialProps ?? defaults?.initialProps ?? [];
242
- const requiredProps = props
243
- ? Object.entries(props)
244
- .filter(
245
- ([name, value]) =>
246
- value?.required && initialProps.includes(name) === false
247
- )
248
- .map(([name]) => name)
249
- : [];
250
-
251
- // order of initialProps must be preserved
252
- return [...initialProps, ...requiredProps];
253
- };
254
-
255
178
  export const canAcceptComponent = (
256
179
  parentComponent: string,
257
180
  childComponent: string
@@ -1,4 +1,4 @@
1
- import { FormTextFieldIcon } from "@webstudio-is/icons";
1
+ import { FormTextFieldIcon } from "@webstudio-is/icons/svg";
2
2
  import { input } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -17,7 +17,7 @@ export const meta: WsComponentMeta = {
17
17
  category: "forms",
18
18
  type: "control",
19
19
  label: "Text Input",
20
- Icon: FormTextFieldIcon,
20
+ icon: FormTextFieldIcon,
21
21
  presetStyle,
22
22
  states: [
23
23
  ...defaultStates,
@@ -1,4 +1,4 @@
1
- import { TextItalicIcon } from "@webstudio-is/icons";
1
+ import { TextItalicIcon } from "@webstudio-is/icons/svg";
2
2
  import type { defaultTag } from "./italic";
3
3
  import {
4
4
  defaultStates,
@@ -22,7 +22,7 @@ const presetStyle = {
22
22
  export const meta: WsComponentMeta = {
23
23
  type: "rich-text-child",
24
24
  label: "Italic Text",
25
- Icon: TextItalicIcon,
25
+ icon: TextItalicIcon,
26
26
  states: defaultStates,
27
27
  presetStyle,
28
28
  };
@@ -1,4 +1,4 @@
1
- import { TextBlockIcon } from "@webstudio-is/icons";
1
+ import { TextBlockIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  type WsComponentMeta,
4
4
  type WsComponentPropsMeta,
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
20
20
  category: "forms",
21
21
  type: "rich-text",
22
22
  label: "Input Label",
23
- Icon: TextBlockIcon,
23
+ icon: TextBlockIcon,
24
24
  states: defaultStates,
25
25
  presetStyle,
26
26
  children: [{ type: "text", value: "Form Label" }],
@@ -1,4 +1,4 @@
1
- import { LinkBlockIcon } from "@webstudio-is/icons";
1
+ import { LinkBlockIcon } from "@webstudio-is/icons/svg";
2
2
  import type {
3
3
  PresetStyle,
4
4
  WsComponentMeta,
@@ -23,7 +23,7 @@ export const meta: WsComponentMeta = {
23
23
  category: "general",
24
24
  type: "container",
25
25
  label: "Link Block",
26
- Icon: LinkBlockIcon,
26
+ icon: LinkBlockIcon,
27
27
  states: linkMeta.states,
28
28
  presetStyle,
29
29
  };
@@ -1,4 +1,4 @@
1
- import { LinkIcon } from "@webstudio-is/icons";
1
+ import { LinkIcon } from "@webstudio-is/icons/svg";
2
2
  import { a } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -27,7 +27,7 @@ export const meta: WsComponentMeta = {
27
27
  category: "general",
28
28
  type: "rich-text",
29
29
  label: "Link Text",
30
- Icon: LinkIcon,
30
+ icon: LinkIcon,
31
31
  presetStyle,
32
32
  states: [
33
33
  ...defaultStates,
@@ -1,4 +1,4 @@
1
- import { ListItemIcon } from "@webstudio-is/icons";
1
+ import { ListItemIcon } from "@webstudio-is/icons/svg";
2
2
  import { li } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -18,7 +18,7 @@ export const meta: WsComponentMeta = {
18
18
  type: "rich-text",
19
19
  acceptedParents: ["List"],
20
20
  label: "List Item",
21
- Icon: ListItemIcon,
21
+ icon: ListItemIcon,
22
22
  children: [{ type: "text", value: "List Item you can edit" }],
23
23
  states: defaultStates,
24
24
  presetStyle,
@@ -1,4 +1,4 @@
1
- import { ListIcon } from "@webstudio-is/icons";
1
+ import { ListIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  defaultStates,
4
4
  type PresetStyle,
@@ -46,7 +46,7 @@ export const meta: WsComponentMeta = {
46
46
  category: "typography",
47
47
  type: "container",
48
48
  label: "List",
49
- Icon: ListIcon,
49
+ icon: ListIcon,
50
50
  states: defaultStates,
51
51
  presetStyle,
52
52
  children: [],
@@ -1,4 +1,4 @@
1
- import { TextAlignLeftIcon } from "@webstudio-is/icons";
1
+ import { TextAlignLeftIcon } from "@webstudio-is/icons/svg";
2
2
  import { p } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -17,7 +17,7 @@ export const meta: WsComponentMeta = {
17
17
  category: "typography",
18
18
  type: "rich-text",
19
19
  label: "Paragraph",
20
- Icon: TextAlignLeftIcon,
20
+ icon: TextAlignLeftIcon,
21
21
  children: [{ type: "text", value: "Pragraph you can edit" }],
22
22
  states: defaultStates,
23
23
  presetStyle,
@@ -1,4 +1,4 @@
1
- import { RadioCheckedIcon } from "@webstudio-is/icons";
1
+ import { RadioCheckedIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  type WsComponentMeta,
4
4
  type WsComponentPropsMeta,
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
20
20
  category: "forms",
21
21
  type: "container",
22
22
  label: "Radio",
23
- Icon: RadioCheckedIcon,
23
+ icon: RadioCheckedIcon,
24
24
  states: defaultStates,
25
25
  presetStyle,
26
26
  children: [
@@ -1,4 +1,4 @@
1
- import { RadioCheckedIcon } from "@webstudio-is/icons";
1
+ import { RadioCheckedIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  type WsComponentMeta,
4
4
  type WsComponentPropsMeta,
@@ -22,7 +22,7 @@ const presetStyle = {
22
22
  export const meta: WsComponentMeta = {
23
23
  type: "control",
24
24
  label: "Radio Input",
25
- Icon: RadioCheckedIcon,
25
+ icon: RadioCheckedIcon,
26
26
  presetStyle,
27
27
  states: [
28
28
  ...defaultStates,
@@ -1,4 +1,4 @@
1
- import { DashIcon } from "@webstudio-is/icons";
1
+ import { DashIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  defaultStates,
4
4
  type PresetStyle,
@@ -44,7 +44,7 @@ export const meta: WsComponentMeta = {
44
44
  category: "general",
45
45
  type: "embed",
46
46
  label: "Separator",
47
- Icon: DashIcon,
47
+ icon: DashIcon,
48
48
  states: defaultStates,
49
49
  presetStyle,
50
50
  children: [],
@@ -1,11 +1,11 @@
1
- import { SlotComponentIcon } from "@webstudio-is/icons";
1
+ import { SlotComponentIcon } from "@webstudio-is/icons/svg";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
3
 
4
4
  export const meta: WsComponentMeta = {
5
5
  category: "general",
6
6
  type: "container",
7
7
  label: "Slot",
8
- Icon: SlotComponentIcon,
8
+ icon: SlotComponentIcon,
9
9
  };
10
10
 
11
11
  export const propsMeta: WsComponentPropsMeta = {
@@ -1,4 +1,4 @@
1
- import { PaintBrushIcon } from "@webstudio-is/icons";
1
+ import { PaintBrushIcon } from "@webstudio-is/icons/svg";
2
2
  import { span } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -16,7 +16,7 @@ const presetStyle = {
16
16
  export const meta: WsComponentMeta = {
17
17
  type: "rich-text-child",
18
18
  label: "Styled Text",
19
- Icon: PaintBrushIcon,
19
+ icon: PaintBrushIcon,
20
20
  states: defaultStates,
21
21
  presetStyle,
22
22
  };
@@ -1,4 +1,4 @@
1
- import { SubscriptIcon } from "@webstudio-is/icons";
1
+ import { SubscriptIcon } from "@webstudio-is/icons/svg";
2
2
  import { sub } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -16,7 +16,7 @@ const presetStyle = {
16
16
  export const meta: WsComponentMeta = {
17
17
  type: "rich-text-child",
18
18
  label: "Subscript Text",
19
- Icon: SubscriptIcon,
19
+ icon: SubscriptIcon,
20
20
  states: defaultStates,
21
21
  presetStyle,
22
22
  };
@@ -1,4 +1,4 @@
1
- import { BoxIcon } from "@webstudio-is/icons";
1
+ import { BoxIcon } from "@webstudio-is/icons/svg";
2
2
  import type {
3
3
  WsComponentMeta,
4
4
  WsComponentPropsMeta,
@@ -14,7 +14,7 @@ const presetStyle = {
14
14
  export const meta: WsComponentMeta = {
15
15
  type: "container",
16
16
  label: "Success Message",
17
- Icon: BoxIcon,
17
+ icon: BoxIcon,
18
18
  presetStyle,
19
19
  };
20
20
 
@@ -1,4 +1,4 @@
1
- import { SuperscriptIcon } from "@webstudio-is/icons";
1
+ import { SuperscriptIcon } from "@webstudio-is/icons/svg";
2
2
  import { sup } from "../css/normalize";
3
3
  import {
4
4
  defaultStates,
@@ -16,7 +16,7 @@ const presetStyle = {
16
16
  export const meta: WsComponentMeta = {
17
17
  type: "rich-text-child",
18
18
  label: "Superscript Text",
19
- Icon: SuperscriptIcon,
19
+ icon: SuperscriptIcon,
20
20
  states: defaultStates,
21
21
  presetStyle,
22
22
  };
@@ -1,4 +1,4 @@
1
- import { TextBlockIcon } from "@webstudio-is/icons";
1
+ import { TextBlockIcon } from "@webstudio-is/icons/svg";
2
2
  import {
3
3
  defaultStates,
4
4
  type PresetStyle,
@@ -23,7 +23,7 @@ export const meta: WsComponentMeta = {
23
23
  category: "typography",
24
24
  type: "rich-text",
25
25
  label: "Text Block",
26
- Icon: TextBlockIcon,
26
+ icon: TextBlockIcon,
27
27
  states: defaultStates,
28
28
  presetStyle,
29
29
  children: [{ type: "text", value: "Block of text you can edit" }],
@@ -1,4 +1,4 @@
1
- import { FormTextAreaIcon } from "@webstudio-is/icons";
1
+ import { FormTextAreaIcon } from "@webstudio-is/icons/svg";
2
2
  import { textarea } from "../css/normalize";
3
3
  import {
4
4
  type WsComponentMeta,
@@ -21,7 +21,7 @@ export const meta: WsComponentMeta = {
21
21
  category: "forms",
22
22
  type: "control",
23
23
  label: "Text Area",
24
- Icon: FormTextAreaIcon,
24
+ icon: FormTextAreaIcon,
25
25
  presetStyle,
26
26
  states: [
27
27
  ...defaultStates,
package/src/context.tsx CHANGED
@@ -4,6 +4,7 @@ import type { Assets } from "@webstudio-is/asset-uploader";
4
4
  import type { Pages, PropsByInstanceId } from "./props";
5
5
 
6
6
  export const ReactSdkContext = createContext<{
7
+ renderer?: "canvas";
7
8
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
8
9
  assetsStore: ReadableAtom<Assets>;
9
10
  pagesStore: ReadableAtom<Pages>;
package/src/css/css.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { createCssEngine, type TransformValue } from "@webstudio-is/css-engine";
2
2
  import type { Asset, Assets } from "@webstudio-is/asset-uploader";
3
3
  import type { Build } from "@webstudio-is/project-build";
4
- import { getComponentNames } from "../components/components-utils";
5
- import { getComponentMeta } from "../components";
4
+ import type { WsComponentMeta } from "../components/component-meta";
6
5
  import { idAttribute } from "../tree";
7
6
  import { addGlobalRules } from "./global-rules";
8
7
  import { getPresetStyleRules, getStyleRules } from "./style-rules";
@@ -12,6 +11,7 @@ type Data = {
12
11
  breakpoints?: Build["breakpoints"];
13
12
  styles?: Build["styles"];
14
13
  styleSourceSelections?: Build["styleSourceSelections"];
14
+ componentMetas: Map<string, WsComponentMeta>;
15
15
  };
16
16
 
17
17
  type CssOptions = {
@@ -61,9 +61,8 @@ export const generateCssText = (data: Data, options: CssOptions) => {
61
61
  engine.addMediaRule(breakpoint.id, breakpoint);
62
62
  }
63
63
 
64
- for (const component of getComponentNames()) {
65
- const meta = getComponentMeta(component);
66
- const presetStyle = meta?.presetStyle;
64
+ for (const [component, meta] of data.componentMetas) {
65
+ const presetStyle = meta.presetStyle;
67
66
  if (presetStyle === undefined) {
68
67
  continue;
69
68
  }
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  // webstudio custom opinionated presets
19
- import { borders } from "./presets";
19
+ import { borders, outline } from "./presets";
20
20
  import type { EmbedTemplateStyleDecl } from "../embed-template";
21
21
 
22
22
  export type Styles = EmbedTemplateStyleDecl[];
@@ -37,7 +37,7 @@ const boxSizing = {
37
37
  * box-sizing: border-box;
38
38
  }
39
39
  */
40
- const baseStyle = [boxSizing, ...borders] satisfies Styles;
40
+ const baseStyle = [boxSizing, ...borders, ...outline] satisfies Styles;
41
41
 
42
42
  export const div = baseStyle;
43
43
  export const address = baseStyle;
@@ -18,3 +18,10 @@ export const borders: Styles = [
18
18
  value: { type: "unit", value: 1, unit: "px" },
19
19
  },
20
20
  ];
21
+
22
+ export const outline: Styles = [
23
+ {
24
+ property: "outlineWidth",
25
+ value: { type: "unit", value: 1, unit: "px" },
26
+ },
27
+ ];
@@ -7,23 +7,22 @@ import type { GetComponent } from "../components/components-utils";
7
7
  import { ReactSdkContext } from "../context";
8
8
  import type { Pages, PropsByInstanceId } from "../props";
9
9
  import type { WebstudioComponent } from "./webstudio-component";
10
- import { SessionStoragePolyfill } from "./session-storage-polyfill";
11
10
 
12
11
  type InstanceSelector = Instance["id"][];
13
12
 
14
13
  export const createElementsTree = ({
14
+ renderer,
15
15
  instances,
16
16
  rootInstanceId,
17
- sandbox,
18
17
  propsByInstanceIdStore,
19
18
  assetsStore,
20
19
  pagesStore,
21
20
  Component,
22
21
  getComponent,
23
22
  }: {
23
+ renderer?: "canvas";
24
24
  instances: Instances;
25
25
  rootInstanceId: Instance["id"];
26
- sandbox?: boolean;
27
26
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
28
27
  assetsStore: ReadableAtom<Assets>;
29
28
  pagesStore: ReadableAtom<Pages>;
@@ -50,7 +49,6 @@ export const createElementsTree = ({
50
49
  children: [
51
50
  <Fragment key="children">
52
51
  {children}
53
- {sandbox && <SessionStoragePolyfill />}
54
52
  <ScrollRestoration />
55
53
  <Scripts />
56
54
  </Fragment>,
@@ -59,7 +57,7 @@ export const createElementsTree = ({
59
57
  });
60
58
  return (
61
59
  <ReactSdkContext.Provider
62
- value={{ propsByInstanceIdStore, assetsStore, pagesStore }}
60
+ value={{ propsByInstanceIdStore, assetsStore, pagesStore, renderer }}
63
61
  >
64
62
  {root}
65
63
  </ReactSdkContext.Provider>