@webstudio-is/sdk-components-react 0.95.0 → 0.97.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 (128) hide show
  1. package/lib/components.js +747 -33
  2. package/lib/metas.js +3635 -33
  3. package/lib/props.js +16274 -33
  4. package/lib/types/vimeo-preview-image.d.ts +2 -2
  5. package/package.json +8 -8
  6. package/lib/__generated__/blockquote.props.js +0 -514
  7. package/lib/__generated__/body.props.js +0 -508
  8. package/lib/__generated__/bold.props.js +0 -508
  9. package/lib/__generated__/box.props.js +0 -527
  10. package/lib/__generated__/button.props.js +0 -564
  11. package/lib/__generated__/checkbox.props.js +0 -666
  12. package/lib/__generated__/code-text.props.js +0 -508
  13. package/lib/__generated__/form.props.js +0 -556
  14. package/lib/__generated__/fragment.props.js +0 -2
  15. package/lib/__generated__/heading.props.js +0 -516
  16. package/lib/__generated__/html-embed.props.js +0 -9
  17. package/lib/__generated__/image.props.js +0 -581
  18. package/lib/__generated__/input.props.js +0 -673
  19. package/lib/__generated__/italic.props.js +0 -508
  20. package/lib/__generated__/label.props.js +0 -520
  21. package/lib/__generated__/link.props.js +0 -562
  22. package/lib/__generated__/list-item.props.js +0 -508
  23. package/lib/__generated__/list.props.js +0 -534
  24. package/lib/__generated__/paragraph.props.js +0 -508
  25. package/lib/__generated__/radio-button.props.js +0 -666
  26. package/lib/__generated__/rich-text-link.props.js +0 -562
  27. package/lib/__generated__/separator.props.js +0 -508
  28. package/lib/__generated__/slot.props.js +0 -2
  29. package/lib/__generated__/span.props.js +0 -508
  30. package/lib/__generated__/subscript.props.js +0 -508
  31. package/lib/__generated__/superscript.props.js +0 -508
  32. package/lib/__generated__/text.props.js +0 -516
  33. package/lib/__generated__/textarea.props.js +0 -575
  34. package/lib/__generated__/vimeo-play-button.props.js +0 -563
  35. package/lib/__generated__/vimeo-preview-image.props.js +0 -580
  36. package/lib/__generated__/vimeo-spinner.props.js +0 -508
  37. package/lib/__generated__/vimeo.props.js +0 -665
  38. package/lib/blockquote.js +0 -12
  39. package/lib/blockquote.stories.js +0 -11
  40. package/lib/blockquote.ws.js +0 -75
  41. package/lib/body.js +0 -6
  42. package/lib/body.stories.js +0 -11
  43. package/lib/body.ws.js +0 -31
  44. package/lib/bold.js +0 -6
  45. package/lib/bold.stories.js +0 -11
  46. package/lib/bold.ws.js +0 -21
  47. package/lib/box.js +0 -12
  48. package/lib/box.stories.js +0 -11
  49. package/lib/box.ws.js +0 -44
  50. package/lib/button.js +0 -8
  51. package/lib/button.stories.js +0 -11
  52. package/lib/button.ws.js +0 -36
  53. package/lib/checkbox.js +0 -6
  54. package/lib/checkbox.ws.js +0 -57
  55. package/lib/code-text.js +0 -10
  56. package/lib/code-text.stories.js +0 -11
  57. package/lib/code-text.ws.js +0 -54
  58. package/lib/form.js +0 -6
  59. package/lib/form.stories.js +0 -11
  60. package/lib/form.ws.js +0 -63
  61. package/lib/fragment.js +0 -7
  62. package/lib/fragment.ws.js +0 -10
  63. package/lib/heading.js +0 -12
  64. package/lib/heading.stories.js +0 -11
  65. package/lib/heading.ws.js +0 -37
  66. package/lib/html-embed.js +0 -63
  67. package/lib/html-embed.stories.js +0 -11
  68. package/lib/html-embed.ws.js +0 -28
  69. package/lib/image.js +0 -74
  70. package/lib/image.stories.js +0 -7
  71. package/lib/image.ws.js +0 -48
  72. package/lib/input.js +0 -6
  73. package/lib/input.stories.js +0 -9
  74. package/lib/input.ws.js +0 -43
  75. package/lib/italic.js +0 -6
  76. package/lib/italic.stories.js +0 -11
  77. package/lib/italic.ws.js +0 -27
  78. package/lib/label.js +0 -6
  79. package/lib/label.ws.js +0 -40
  80. package/lib/link.js +0 -33
  81. package/lib/link.stories.js +0 -11
  82. package/lib/link.ws.js +0 -60
  83. package/lib/list-item.js +0 -12
  84. package/lib/list-item.stories.js +0 -11
  85. package/lib/list-item.ws.js +0 -32
  86. package/lib/list.js +0 -12
  87. package/lib/list.stories.js +0 -13
  88. package/lib/list.ws.js +0 -53
  89. package/lib/paragraph.js +0 -6
  90. package/lib/paragraph.stories.js +0 -11
  91. package/lib/paragraph.ws.js +0 -32
  92. package/lib/radio-button.js +0 -6
  93. package/lib/radio-button.ws.js +0 -58
  94. package/lib/rich-text-link.js +0 -6
  95. package/lib/rich-text-link.stories.js +0 -11
  96. package/lib/rich-text-link.ws.js +0 -9
  97. package/lib/separator.js +0 -12
  98. package/lib/separator.stories.js +0 -7
  99. package/lib/separator.ws.js +0 -50
  100. package/lib/slot.js +0 -14
  101. package/lib/slot.stories.js +0 -11
  102. package/lib/slot.ws.js +0 -14
  103. package/lib/span.js +0 -6
  104. package/lib/span.stories.js +0 -11
  105. package/lib/span.ws.js +0 -21
  106. package/lib/subscript.js +0 -6
  107. package/lib/subscript.stories.js +0 -11
  108. package/lib/subscript.ws.js +0 -21
  109. package/lib/superscript.js +0 -6
  110. package/lib/superscript.stories.js +0 -11
  111. package/lib/superscript.ws.js +0 -21
  112. package/lib/text.js +0 -12
  113. package/lib/text.stories.js +0 -11
  114. package/lib/text.ws.js +0 -37
  115. package/lib/textarea.js +0 -6
  116. package/lib/textarea.ws.js +0 -44
  117. package/lib/vimeo-play-button.js +0 -19
  118. package/lib/vimeo-play-button.stories.js +0 -11
  119. package/lib/vimeo-play-button.ws.js +0 -25
  120. package/lib/vimeo-preview-image.js +0 -21
  121. package/lib/vimeo-preview-image.stories.js +0 -11
  122. package/lib/vimeo-preview-image.ws.js +0 -19
  123. package/lib/vimeo-spinner.js +0 -18
  124. package/lib/vimeo-spinner.stories.js +0 -11
  125. package/lib/vimeo-spinner.ws.js +0 -23
  126. package/lib/vimeo.js +0 -279
  127. package/lib/vimeo.stories.js +0 -11
  128. package/lib/vimeo.ws.js +0 -327
package/lib/vimeo.js DELETED
@@ -1,279 +0,0 @@
1
- "use strict";
2
- import { jsx } from "react/jsx-runtime";
3
- import { colord } from "colord";
4
- import {
5
- forwardRef,
6
- useState,
7
- useRef,
8
- useEffect,
9
- useContext,
10
- createContext,
11
- useMemo
12
- } from "react";
13
- import { ReactSdkContext } from "@webstudio-is/react-sdk";
14
- import { shallowEqual } from "shallow-equal";
15
- const defaultTag = "div";
16
- const getUrl = (options) => {
17
- if (options.url === void 0) {
18
- return;
19
- }
20
- let url;
21
- try {
22
- const userUrl = new URL(options.url);
23
- url = new URL(IFRAME_CDN);
24
- url.pathname = `/video${userUrl.pathname}`;
25
- } catch {
26
- }
27
- if (url === void 0) {
28
- return;
29
- }
30
- let option;
31
- for (option in options) {
32
- const value = options[option];
33
- if (option === "url" || value === void 0) {
34
- continue;
35
- }
36
- url.searchParams.append(option, value.toString());
37
- }
38
- url.searchParams.set("autoplay", "true");
39
- if (typeof options.color === "string") {
40
- const color = colord(options.color).toHex().replace("#", "");
41
- url.searchParams.set("color", color);
42
- }
43
- if (options.portrait) {
44
- url.searchParams.set("title", "true");
45
- }
46
- if (options.byline) {
47
- url.searchParams.set("portrait", "true");
48
- url.searchParams.set("title", "true");
49
- }
50
- return url.toString();
51
- };
52
- const preconnect = (url) => {
53
- const link = document.createElement("link");
54
- link.rel = "preconnect";
55
- link.href = url;
56
- link.crossOrigin = "true";
57
- document.head.append(link);
58
- };
59
- let warmed = false;
60
- const PLAYER_CDN = "https://f.vimeocdn.com";
61
- const IFRAME_CDN = "https://player.vimeo.com";
62
- const IMAGE_CDN = "https://i.vimeocdn.com";
63
- const warmConnections = () => {
64
- if (warmed) {
65
- return;
66
- }
67
- preconnect(PLAYER_CDN);
68
- preconnect(IFRAME_CDN);
69
- preconnect(IMAGE_CDN);
70
- warmed = true;
71
- };
72
- const createPlayer = (parent, options, callback) => {
73
- const url = getUrl(options);
74
- if (url === void 0) {
75
- return;
76
- }
77
- const iframe = document.createElement("iframe");
78
- iframe.setAttribute(
79
- "allow",
80
- "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture;"
81
- );
82
- iframe.setAttribute("frameborder", "0");
83
- iframe.setAttribute("allowfullscreen", "true");
84
- iframe.setAttribute("src", url);
85
- iframe.setAttribute(
86
- "style",
87
- "position: absolute; width: 100%; height: 100%; opacity: 0; transition: opacity 1s;"
88
- );
89
- iframe.addEventListener(
90
- "load",
91
- () => {
92
- iframe.style.opacity = "1";
93
- callback();
94
- },
95
- { once: true }
96
- );
97
- parent.appendChild(iframe);
98
- return () => {
99
- iframe.parentElement?.removeChild(iframe);
100
- };
101
- };
102
- const getVideoId = (url) => {
103
- try {
104
- const parsedUrl = new URL(url);
105
- const id = parsedUrl.pathname.split("/")[1];
106
- if (id === "" || id == null) {
107
- return;
108
- }
109
- return id;
110
- } catch {
111
- }
112
- };
113
- const loadPreviewImage = async (element, videoUrl) => {
114
- const videoId = getVideoId(videoUrl);
115
- const apiUrl = `https://vimeo.com/api/v2/video/${videoId}.json`;
116
- const response = (await (await fetch(apiUrl)).json())[0];
117
- const thumbnail = response.thumbnail_large;
118
- const imgId = thumbnail.substr(thumbnail.lastIndexOf("/") + 1).split("_")[0];
119
- const imageUrl = new URL(IMAGE_CDN);
120
- imageUrl.pathname = `/video/${imgId}.webp`;
121
- imageUrl.searchParams.append("mw", "1100");
122
- imageUrl.searchParams.append("mh", "619");
123
- imageUrl.searchParams.append("q", "70");
124
- return imageUrl;
125
- };
126
- const useVimeo = ({
127
- options,
128
- renderer,
129
- showPreview
130
- }) => {
131
- const [playerStatus, setPlayerStatus] = useState("initial");
132
- const elementRef = useRef(null);
133
- const [previewImageUrl, setPreviewImageUrl] = useState();
134
- useEffect(() => {
135
- setPlayerStatus(
136
- options.autoplay && renderer !== "canvas" ? "initialized" : "initial"
137
- );
138
- }, [options.autoplay, renderer]);
139
- useEffect(() => {
140
- if (elementRef.current === null || playerStatus === "ready" || options.url === void 0) {
141
- return;
142
- }
143
- if (showPreview) {
144
- loadPreviewImage(elementRef.current, options.url).then(
145
- setPreviewImageUrl
146
- );
147
- return;
148
- }
149
- setPreviewImageUrl(void 0);
150
- }, [renderer, showPreview, options.url, playerStatus]);
151
- const optionsRef = useRef(options);
152
- const stableOptions = useMemo(() => {
153
- if (shallowEqual(options, optionsRef.current) === false) {
154
- optionsRef.current = options;
155
- }
156
- return optionsRef.current;
157
- }, [options]);
158
- useEffect(() => {
159
- if (elementRef.current === null || playerStatus === "initial") {
160
- return;
161
- }
162
- return createPlayer(elementRef.current, stableOptions, () => {
163
- setPlayerStatus("ready");
164
- });
165
- }, [stableOptions, playerStatus]);
166
- return { previewImageUrl, playerStatus, setPlayerStatus, elementRef };
167
- };
168
- export const Vimeo = forwardRef(
169
- ({
170
- url,
171
- autoplay = false,
172
- autopause = true,
173
- backgroundMode = false,
174
- showByline = false,
175
- showControls = true,
176
- doNotTrack = false,
177
- keyboard = true,
178
- loop = false,
179
- muted = false,
180
- pip = false,
181
- playsinline = true,
182
- showPortrait = true,
183
- quality = "auto",
184
- responsive = true,
185
- speed = false,
186
- showTitle = false,
187
- transparent = true,
188
- showPreview = false,
189
- autopip,
190
- controlsColor,
191
- interactiveParams,
192
- texttrack,
193
- children,
194
- ...rest
195
- }, ref) => {
196
- const { renderer } = useContext(ReactSdkContext);
197
- const { previewImageUrl, playerStatus, setPlayerStatus, elementRef } = useVimeo({
198
- renderer,
199
- showPreview,
200
- options: {
201
- url,
202
- autoplay,
203
- autopause,
204
- keyboard,
205
- loop,
206
- muted,
207
- pip,
208
- playsinline,
209
- quality,
210
- responsive,
211
- speed,
212
- transparent,
213
- portrait: showPortrait,
214
- byline: showByline,
215
- title: showTitle,
216
- color: controlsColor,
217
- controls: showControls,
218
- interactive_params: interactiveParams,
219
- background: backgroundMode,
220
- dnt: doNotTrack
221
- }
222
- });
223
- return /* @__PURE__ */ jsx(
224
- VimeoContext.Provider,
225
- {
226
- value: {
227
- status: playerStatus,
228
- previewImageUrl,
229
- onInitPlayer() {
230
- if (renderer !== "canvas") {
231
- setPlayerStatus("initialized");
232
- }
233
- }
234
- },
235
- children: /* @__PURE__ */ jsx(
236
- "div",
237
- {
238
- ...rest,
239
- ref: (value) => {
240
- elementRef.current = value;
241
- if (ref !== null) {
242
- typeof ref === "function" ? ref(value) : ref.current = value;
243
- }
244
- },
245
- onPointerOver: () => {
246
- if (renderer !== "canvas") {
247
- warmConnections();
248
- }
249
- },
250
- children: url === void 0 ? /* @__PURE__ */ jsx(EmptyState, {}) : children
251
- }
252
- )
253
- }
254
- );
255
- }
256
- );
257
- Vimeo.displayName = "Vimeo";
258
- const EmptyState = () => {
259
- return /* @__PURE__ */ jsx(
260
- "div",
261
- {
262
- style: {
263
- display: "flex",
264
- width: "100%",
265
- height: "100%",
266
- alignItems: "center",
267
- justifyContent: "center",
268
- fontSize: "1.2em"
269
- },
270
- children: 'Open the "Settings" panel and paste a video URL, e.g. https://vimeo.com/831343124.'
271
- }
272
- );
273
- };
274
- export const VimeoContext = createContext({
275
- // eslint-disable-next-line @typescript-eslint/no-empty-function
276
- onInitPlayer: () => {
277
- },
278
- status: "initial"
279
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- import { Vimeo as VimeoPrimitive } from "./vimeo";
3
- export default {
4
- title: "Components/Vimeo",
5
- component: VimeoPrimitive
6
- };
7
- export const Vimeo = {
8
- args: {
9
- style: { minHeight: 20, outline: "1px solid black" }
10
- }
11
- };
package/lib/vimeo.ws.js DELETED
@@ -1,327 +0,0 @@
1
- "use strict";
2
- import { PlayIcon, SpinnerIcon, VimeoIcon } from "@webstudio-is/icons/svg";
3
- import {
4
- defaultStates
5
- } from "@webstudio-is/react-sdk";
6
- import { div } from "@webstudio-is/react-sdk/css-normalize";
7
- import { props } from "./__generated__/vimeo.props";
8
- import { Vimeo } from "./vimeo";
9
- const presetStyle = {
10
- div
11
- };
12
- export const meta = {
13
- category: "media",
14
- type: "container",
15
- label: "Vimeo",
16
- description: "Add a video to your page that is hosted on Vimeo. Paste a Vimeo URL and configure the video in the Settings tab.",
17
- order: 1,
18
- icon: VimeoIcon,
19
- states: defaultStates,
20
- presetStyle,
21
- template: [
22
- {
23
- type: "instance",
24
- component: "Vimeo",
25
- styles: [
26
- {
27
- property: "position",
28
- value: { type: "keyword", value: "relative" }
29
- },
30
- {
31
- property: "aspectRatio",
32
- value: { type: "keyword", value: "640/360" }
33
- },
34
- {
35
- property: "width",
36
- value: { type: "unit", value: 100, unit: "%" }
37
- }
38
- ],
39
- children: [
40
- {
41
- type: "instance",
42
- component: "VimeoPreviewImage",
43
- styles: [
44
- {
45
- property: "position",
46
- value: { type: "keyword", value: "absolute" }
47
- },
48
- {
49
- property: "objectFit",
50
- value: { type: "keyword", value: "cover" }
51
- },
52
- {
53
- property: "width",
54
- value: { type: "unit", value: 100, unit: "%" }
55
- },
56
- {
57
- property: "height",
58
- value: { type: "unit", value: 100, unit: "%" }
59
- },
60
- {
61
- property: "borderTopLeftRadius",
62
- value: { type: "unit", value: 20, unit: "px" }
63
- },
64
- {
65
- property: "borderTopRightRadius",
66
- value: { type: "unit", value: 20, unit: "px" }
67
- },
68
- {
69
- property: "borderBottomLeftRadius",
70
- value: { type: "unit", value: 20, unit: "px" }
71
- },
72
- {
73
- property: "borderBottomRightRadius",
74
- value: { type: "unit", value: 20, unit: "px" }
75
- },
76
- {
77
- property: "objectPosition",
78
- value: { type: "keyword", value: "cover" }
79
- }
80
- ],
81
- children: [],
82
- props: [
83
- {
84
- type: "string",
85
- name: "alt",
86
- value: "Vimeo video preview image"
87
- },
88
- {
89
- type: "string",
90
- name: "sizes",
91
- value: "100vw"
92
- }
93
- ]
94
- },
95
- {
96
- type: "instance",
97
- component: "Box",
98
- label: "Spinner",
99
- styles: [
100
- {
101
- property: "position",
102
- value: { type: "keyword", value: "absolute" }
103
- },
104
- {
105
- property: "top",
106
- value: { type: "unit", value: 50, unit: "%" }
107
- },
108
- {
109
- property: "left",
110
- value: { type: "unit", value: 50, unit: "%" }
111
- },
112
- {
113
- property: "width",
114
- value: { type: "unit", value: 70, unit: "px" }
115
- },
116
- {
117
- property: "height",
118
- value: { type: "unit", value: 70, unit: "px" }
119
- },
120
- {
121
- property: "marginTop",
122
- value: { type: "unit", value: -35, unit: "px" }
123
- },
124
- {
125
- property: "marginLeft",
126
- value: { type: "unit", value: -35, unit: "px" }
127
- }
128
- ],
129
- children: [
130
- {
131
- type: "instance",
132
- component: "HtmlEmbed",
133
- label: "Spinner SVG",
134
- props: [
135
- {
136
- type: "string",
137
- name: "code",
138
- value: SpinnerIcon
139
- }
140
- ],
141
- children: []
142
- }
143
- ]
144
- },
145
- {
146
- type: "instance",
147
- component: "VimeoPlayButton",
148
- props: [
149
- {
150
- type: "string",
151
- name: "aria-label",
152
- value: "Play button"
153
- }
154
- ],
155
- styles: [
156
- {
157
- property: "position",
158
- value: { type: "keyword", value: "absolute" }
159
- },
160
- {
161
- property: "width",
162
- value: { type: "unit", value: 140, unit: "px" }
163
- },
164
- {
165
- property: "height",
166
- value: { type: "unit", value: 80, unit: "px" }
167
- },
168
- {
169
- property: "top",
170
- value: { type: "unit", value: 50, unit: "%" }
171
- },
172
- {
173
- property: "left",
174
- value: { type: "unit", value: 50, unit: "%" }
175
- },
176
- {
177
- property: "marginTop",
178
- value: { type: "unit", value: -40, unit: "px" }
179
- },
180
- {
181
- property: "marginLeft",
182
- value: { type: "unit", value: -70, unit: "px" }
183
- },
184
- {
185
- property: "display",
186
- value: { type: "keyword", value: "flex" }
187
- },
188
- {
189
- property: "alignItems",
190
- value: { type: "keyword", value: "center" }
191
- },
192
- {
193
- property: "justifyContent",
194
- value: { type: "keyword", value: "center" }
195
- },
196
- {
197
- property: "borderTopStyle",
198
- value: { type: "keyword", value: "none" }
199
- },
200
- {
201
- property: "borderRightStyle",
202
- value: { type: "keyword", value: "none" }
203
- },
204
- {
205
- property: "borderBottomStyle",
206
- value: { type: "keyword", value: "none" }
207
- },
208
- {
209
- property: "borderLeftStyle",
210
- value: { type: "keyword", value: "none" }
211
- },
212
- {
213
- property: "borderTopLeftRadius",
214
- value: { type: "unit", value: 5, unit: "px" }
215
- },
216
- {
217
- property: "borderTopRightRadius",
218
- value: { type: "unit", value: 5, unit: "px" }
219
- },
220
- {
221
- property: "borderBottomLeftRadius",
222
- value: { type: "unit", value: 5, unit: "px" }
223
- },
224
- {
225
- property: "borderBottomRightRadius",
226
- value: { type: "unit", value: 5, unit: "px" }
227
- },
228
- {
229
- property: "cursor",
230
- value: { type: "keyword", value: "pointer" }
231
- },
232
- {
233
- property: "backgroundColor",
234
- value: {
235
- type: "rgb",
236
- r: 18,
237
- g: 18,
238
- b: 18,
239
- alpha: 1
240
- }
241
- },
242
- {
243
- property: "color",
244
- value: {
245
- type: "rgb",
246
- r: 255,
247
- g: 255,
248
- b: 255,
249
- alpha: 1
250
- }
251
- },
252
- {
253
- state: ":hover",
254
- property: "backgroundColor",
255
- value: {
256
- type: "rgb",
257
- r: 0,
258
- g: 173,
259
- b: 239,
260
- alpha: 1
261
- }
262
- }
263
- ],
264
- children: [
265
- {
266
- type: "instance",
267
- component: "Box",
268
- label: "Play Icon",
269
- styles: [
270
- {
271
- property: "width",
272
- value: { type: "unit", value: 60, unit: "px" }
273
- },
274
- {
275
- property: "height",
276
- value: { type: "unit", value: 60, unit: "px" }
277
- }
278
- ],
279
- props: [
280
- {
281
- type: "string",
282
- name: "aria-hidden",
283
- value: "true"
284
- }
285
- ],
286
- children: [
287
- {
288
- type: "instance",
289
- component: "HtmlEmbed",
290
- label: "Play SVG",
291
- props: [
292
- {
293
- type: "string",
294
- name: "code",
295
- value: PlayIcon
296
- }
297
- ],
298
- children: []
299
- }
300
- ]
301
- }
302
- ]
303
- }
304
- ]
305
- }
306
- ]
307
- };
308
- const initialProps = [
309
- "id",
310
- "url",
311
- "quality",
312
- "showPreview",
313
- "autoplay",
314
- "backgroundMode",
315
- "doNotTrack",
316
- "loop",
317
- "muted",
318
- "showPortrait",
319
- "showByline",
320
- "showTitle",
321
- "showControls",
322
- "controlsColor"
323
- ];
324
- export const propsMeta = {
325
- props,
326
- initialProps
327
- };