@webstudio-is/sdk-components-react 0.168.0 → 0.173.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 (40) hide show
  1. package/lib/components.js +68 -45
  2. package/lib/metas.js +223 -64
  3. package/lib/props.js +1273 -6
  4. package/lib/types/__generated__/option.props.d.ts +2 -0
  5. package/lib/types/__generated__/select.props.d.ts +2 -0
  6. package/lib/types/blockquote.d.ts +0 -1
  7. package/lib/types/body.d.ts +0 -1
  8. package/lib/types/bold.d.ts +0 -1
  9. package/lib/types/button.d.ts +0 -1
  10. package/lib/types/checkbox.d.ts +1 -2
  11. package/lib/types/code-text.d.ts +1 -2
  12. package/lib/types/components.d.ts +2 -0
  13. package/lib/types/form.d.ts +0 -1
  14. package/lib/types/hooks.d.ts +2 -0
  15. package/lib/types/html-embed.d.ts +1 -1
  16. package/lib/types/html-embed.test.d.ts +1 -1
  17. package/lib/types/image.d.ts +3 -1
  18. package/lib/types/input.d.ts +1 -2
  19. package/lib/types/italic.d.ts +0 -1
  20. package/lib/types/label.d.ts +0 -1
  21. package/lib/types/list-item.d.ts +0 -1
  22. package/lib/types/metas.d.ts +2 -0
  23. package/lib/types/option.d.ts +2 -0
  24. package/lib/types/option.ws.d.ts +3 -0
  25. package/lib/types/paragraph.d.ts +0 -1
  26. package/lib/types/props.d.ts +2 -0
  27. package/lib/types/radio-button.d.ts +1 -2
  28. package/lib/types/select.d.ts +4 -0
  29. package/lib/types/select.ws.d.ts +3 -0
  30. package/lib/types/separator.d.ts +0 -1
  31. package/lib/types/span.d.ts +0 -1
  32. package/lib/types/subscript.d.ts +0 -1
  33. package/lib/types/superscript.d.ts +0 -1
  34. package/lib/types/textarea.d.ts +0 -1
  35. package/lib/types/vimeo-play-button.d.ts +0 -1
  36. package/lib/types/vimeo-preview-image.d.ts +17 -17
  37. package/lib/types/vimeo-spinner.d.ts +0 -1
  38. package/lib/types/vimeo.d.ts +1 -1
  39. package/lib/types/xml-node.d.ts +2 -2
  40. package/package.json +13 -11
package/lib/components.js CHANGED
@@ -28,7 +28,8 @@ import {
28
28
  useEffect,
29
29
  useRef,
30
30
  useSyncExternalStore,
31
- useState
31
+ useState,
32
+ useMemo
32
33
  } from "react";
33
34
  import { mergeRefs } from "@react-aria/utils";
34
35
  import { ReactSdkContext } from "@webstudio-is/react-sdk";
@@ -48,7 +49,6 @@ var patchDomEvents = () => {
48
49
  return;
49
50
  }
50
51
  domContentLoadedPatched = true;
51
- console.info("Patching DOMContentLoaded event listener");
52
52
  const originalAddEventListener = document.addEventListener;
53
53
  const originalWindowAddEventListener = window.addEventListener;
54
54
  const domContentLoadedEvent = new Event("DOMContentLoaded");
@@ -91,6 +91,7 @@ var insertScript = (sourceScript) => {
91
91
  return new Promise((resolve, reject) => {
92
92
  const script = document.createElement("script");
93
93
  const hasSrc = sourceScript.hasAttribute("src");
94
+ const isTypeModule = sourceScript.type === "module";
94
95
  for (const { name, value } of sourceScript.attributes) {
95
96
  script.setAttribute(name, value);
96
97
  }
@@ -103,6 +104,19 @@ var insertScript = (sourceScript) => {
103
104
  });
104
105
  script.addEventListener("error", reject);
105
106
  } else {
107
+ if (isTypeModule) {
108
+ const blob = new Blob([sourceScript.innerText], {
109
+ type: "text/javascript"
110
+ });
111
+ const url = URL.createObjectURL(blob);
112
+ import(
113
+ /* @vite-ignore */
114
+ url
115
+ ).then(resolve).catch(reject).finally(() => {
116
+ URL.revokeObjectURL(url);
117
+ });
118
+ return;
119
+ }
106
120
  script.textContent = sourceScript.innerText;
107
121
  }
108
122
  sourceScript.replaceWith(script);
@@ -120,7 +134,6 @@ var processSyncTasks = async (syncTasks) => {
120
134
  return;
121
135
  }
122
136
  patchDomEvents();
123
- console.info("Start processing sync tasks");
124
137
  processing = true;
125
138
  while (syncTasksQueue.length > 0) {
126
139
  const task = syncTasksQueue.shift();
@@ -128,7 +141,6 @@ var processSyncTasks = async (syncTasks) => {
128
141
  }
129
142
  executeDomEvents();
130
143
  processing = false;
131
- console.info("Stop processing sync tasks");
132
144
  };
133
145
  var execute = (container) => {
134
146
  const scripts = container.querySelectorAll("script");
@@ -147,7 +159,7 @@ var execute = (container) => {
147
159
  };
148
160
  var Placeholder = (props) => {
149
161
  const { code, innerRef, ...rest } = props;
150
- return /* @__PURE__ */ jsx3("div", { ref: innerRef, ...rest, style: { padding: 20 }, children: 'Open the "Settings" panel to insert HTML code.' });
162
+ return /* @__PURE__ */ jsx3("div", { ref: innerRef, ...rest, style: { display: "block", padding: 20 }, children: 'Open the "Settings" panel to insert HTML code.' });
151
163
  };
152
164
  var useIsServer = () => {
153
165
  const isServer = useSyncExternalStore(
@@ -169,6 +181,12 @@ var ClientEmbed = (props) => {
169
181
  const { code, innerRef, ...rest } = props;
170
182
  const containerRef = useRef(null);
171
183
  const executeScripts = useRef(true);
184
+ const html = useMemo(
185
+ () => ({
186
+ __html: code ?? ""
187
+ }),
188
+ [code]
189
+ );
172
190
  useEffect(() => {
173
191
  const container = containerRef.current;
174
192
  if (container && executeScripts.current) {
@@ -181,8 +199,7 @@ var ClientEmbed = (props) => {
181
199
  {
182
200
  ...rest,
183
201
  ref: mergeRefs(innerRef, containerRef),
184
- style: { display: "contents" },
185
- dangerouslySetInnerHTML: { __html: code ?? "" }
202
+ dangerouslySetInnerHTML: html
186
203
  }
187
204
  );
188
205
  };
@@ -193,7 +210,6 @@ var ServerEmbed = (props) => {
193
210
  {
194
211
  ...rest,
195
212
  ref: innerRef,
196
- style: { display: "contents" },
197
213
  dangerouslySetInnerHTML: { __html: code ?? "" }
198
214
  }
199
215
  );
@@ -360,59 +376,48 @@ import {
360
376
  import { Image as WebstudioImage } from "@webstudio-is/image";
361
377
  import { ReactSdkContext as ReactSdkContext2 } from "@webstudio-is/react-sdk";
362
378
  import { jsx as jsx18 } from "react/jsx-runtime";
363
- var imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
364
- width="140"
365
- height="140"
366
- viewBox="0 0 600 600"
367
- fill="none"
368
- xmlns="http://www.w3.org/2000/svg"
369
- >
370
- <rect width="600" height="600" fill="#CCCCCC" />
371
- <path
372
- fill-rule="evenodd"
373
- clip-rule="evenodd"
374
- d="M450 170H150C141.716 170 135 176.716 135 185V415C135 423.284 141.716 430 150 430H450C458.284 430 465 423.284 465 415V185C465 176.716 458.284 170 450 170ZM150 145C127.909 145 110 162.909 110 185V415C110 437.091 127.909 455 150 455H450C472.091 455 490 437.091 490 415V185C490 162.909 472.091 145 450 145H150Z"
375
- fill="#A2A2A2"
376
- />
377
- <path
378
- d="M237.135 235.012C237.135 255.723 220.345 272.512 199.635 272.512C178.924 272.512 162.135 255.723 162.135 235.012C162.135 214.301 178.924 197.512 199.635 197.512C220.345 197.512 237.135 214.301 237.135 235.012Z"
379
- fill="#A2A2A2"
380
- />
381
- <path
382
- d="M160 405V367.205L221.609 306.364L256.552 338.628L358.161 234L440 316.043V405H160Z"
383
- fill="#A2A2A2"
384
- />
385
- </svg>`)}`;
386
379
  var Image = forwardRef19(
387
- ({ loading = "lazy", ...props }, ref) => {
380
+ ({
381
+ loading = "lazy",
382
+ width,
383
+ height,
384
+ optimize = true,
385
+ decoding: decodingProp,
386
+ $webstudio$canvasOnly$assetId,
387
+ ...props
388
+ }, ref) => {
388
389
  const src = String(props.src ?? "");
389
390
  const { imageLoader, renderer, assetBaseUrl } = useContext2(ReactSdkContext2);
391
+ let decoding = decodingProp;
392
+ let key = src;
390
393
  if (renderer === "canvas") {
391
394
  loading = "eager";
395
+ decoding = "sync";
396
+ key = $webstudio$canvasOnly$assetId ?? src;
397
+ if (width !== void 0 && height !== void 0 && Number.isNaN(width) && Number.isNaN(height)) {
398
+ optimize = false;
399
+ width = void 0;
400
+ height = void 0;
401
+ }
392
402
  }
393
- if (src.startsWith(assetBaseUrl) === false) {
394
- return /* @__PURE__ */ jsx18(
395
- "img",
396
- {
397
- loading,
398
- ...props,
399
- src: src || imagePlaceholderSvg,
400
- ref
401
- },
402
- src
403
- );
403
+ let assetName = src;
404
+ if (src.startsWith(assetBaseUrl)) {
405
+ assetName = src.slice(assetBaseUrl.length);
404
406
  }
405
- const assetName = src.slice(assetBaseUrl.length);
406
407
  return /* @__PURE__ */ jsx18(
407
408
  WebstudioImage,
408
409
  {
409
410
  loading,
411
+ decoding,
412
+ optimize,
413
+ width,
414
+ height,
410
415
  ...props,
411
416
  loader: imageLoader,
412
417
  src: assetName,
413
418
  ref
414
419
  },
415
- assetName
420
+ key
416
421
  );
417
422
  }
418
423
  );
@@ -1227,6 +1232,22 @@ var Time = React.forwardRef(
1227
1232
  return /* @__PURE__ */ jsx31("time", { ref, dateTime: datetimeString, ...props, children: formattedDate });
1228
1233
  }
1229
1234
  );
1235
+
1236
+ // src/select.tsx
1237
+ import {
1238
+ getClosestInstance,
1239
+ getInstanceSelectorById
1240
+ } from "@webstudio-is/react-sdk";
1241
+ import { forwardRef as forwardRef35 } from "react";
1242
+ import { jsx as jsx32 } from "react/jsx-runtime";
1243
+ var Select = forwardRef35((props, ref) => /* @__PURE__ */ jsx32("select", { ...props, ref }));
1244
+ Select.displayName = "Select";
1245
+
1246
+ // src/option.tsx
1247
+ import { forwardRef as forwardRef36 } from "react";
1248
+ import { jsx as jsx33 } from "react/jsx-runtime";
1249
+ var Option = forwardRef36((props, ref) => /* @__PURE__ */ jsx33("option", { ...props, ref }));
1250
+ Option.displayName = "Option";
1230
1251
  export {
1231
1252
  Blockquote,
1232
1253
  Body,
@@ -1246,9 +1267,11 @@ export {
1246
1267
  Link,
1247
1268
  List,
1248
1269
  ListItem,
1270
+ Option,
1249
1271
  Paragraph,
1250
1272
  RadioButton,
1251
1273
  RichTextLink,
1274
+ Select,
1252
1275
  Separator,
1253
1276
  Slot,
1254
1277
  Span,