@makeswift/runtime 0.5.5 → 0.6.1

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 (130) hide show
  1. package/dist/Box.cjs.js +11 -6
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +12 -7
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +2 -1
  6. package/dist/Button.cjs.js.map +1 -1
  7. package/dist/Button.es.js +2 -1
  8. package/dist/Button.es.js.map +1 -1
  9. package/dist/Carousel.cjs.js +2 -1
  10. package/dist/Carousel.cjs.js.map +1 -1
  11. package/dist/Carousel.es.js +2 -1
  12. package/dist/Carousel.es.js.map +1 -1
  13. package/dist/Countdown.cjs.js +2 -1
  14. package/dist/Countdown.cjs.js.map +1 -1
  15. package/dist/Countdown.es.js +2 -1
  16. package/dist/Countdown.es.js.map +1 -1
  17. package/dist/Divider.cjs.js +2 -1
  18. package/dist/Divider.cjs.js.map +1 -1
  19. package/dist/Divider.es.js +2 -1
  20. package/dist/Divider.es.js.map +1 -1
  21. package/dist/EditableText.cjs.js +359 -0
  22. package/dist/EditableText.cjs.js.map +1 -0
  23. package/dist/EditableText.es.js +352 -0
  24. package/dist/EditableText.es.js.map +1 -0
  25. package/dist/Embed.cjs.js +2 -1
  26. package/dist/Embed.cjs.js.map +1 -1
  27. package/dist/Embed.es.js +2 -1
  28. package/dist/Embed.es.js.map +1 -1
  29. package/dist/Form.cjs.js +73 -67
  30. package/dist/Form.cjs.js.map +1 -1
  31. package/dist/Form.es.js +73 -67
  32. package/dist/Form.es.js.map +1 -1
  33. package/dist/Image.cjs.js +2 -1
  34. package/dist/Image.cjs.js.map +1 -1
  35. package/dist/Image.es.js +2 -1
  36. package/dist/Image.es.js.map +1 -1
  37. package/dist/LiveProvider.cjs.js +3 -11
  38. package/dist/LiveProvider.cjs.js.map +1 -1
  39. package/dist/LiveProvider.es.js +6 -14
  40. package/dist/LiveProvider.es.js.map +1 -1
  41. package/dist/Navigation.cjs.js +2 -1
  42. package/dist/Navigation.cjs.js.map +1 -1
  43. package/dist/Navigation.es.js +2 -1
  44. package/dist/Navigation.es.js.map +1 -1
  45. package/dist/PreviewProvider.cjs.js +6 -3
  46. package/dist/PreviewProvider.cjs.js.map +1 -1
  47. package/dist/PreviewProvider.es.js +8 -5
  48. package/dist/PreviewProvider.es.js.map +1 -1
  49. package/dist/ReadOnlyText.cjs.js +206 -0
  50. package/dist/ReadOnlyText.cjs.js.map +1 -0
  51. package/dist/ReadOnlyText.es.js +204 -0
  52. package/dist/ReadOnlyText.es.js.map +1 -0
  53. package/dist/Root.cjs.js +4 -3
  54. package/dist/Root.cjs.js.map +1 -1
  55. package/dist/Root.es.js +3 -2
  56. package/dist/Root.es.js.map +1 -1
  57. package/dist/SocialLinks.cjs.js +2 -1
  58. package/dist/SocialLinks.cjs.js.map +1 -1
  59. package/dist/SocialLinks.es.js +2 -1
  60. package/dist/SocialLinks.es.js.map +1 -1
  61. package/dist/Text.cjs.js +26 -405
  62. package/dist/Text.cjs.js.map +1 -1
  63. package/dist/Text.es.js +23 -405
  64. package/dist/Text.es.js.map +1 -1
  65. package/dist/Video.cjs.js +2 -1
  66. package/dist/Video.cjs.js.map +1 -1
  67. package/dist/Video.es.js +2 -1
  68. package/dist/Video.es.js.map +1 -1
  69. package/dist/actions.cjs.js.map +1 -1
  70. package/dist/actions.es.js.map +1 -1
  71. package/dist/components.cjs.js +2 -5
  72. package/dist/components.cjs.js.map +1 -1
  73. package/dist/components.es.js +2 -5
  74. package/dist/components.es.js.map +1 -1
  75. package/dist/constants.cjs.js +45 -26
  76. package/dist/constants.cjs.js.map +1 -1
  77. package/dist/constants.es.js +36 -20
  78. package/dist/constants.es.js.map +1 -1
  79. package/dist/index.cjs.js +78 -310
  80. package/dist/index.cjs.js.map +1 -1
  81. package/dist/index.cjs2.js +20 -21
  82. package/dist/index.cjs2.js.map +1 -1
  83. package/dist/index.cjs5.js +141 -0
  84. package/dist/index.cjs5.js.map +1 -0
  85. package/dist/index.es.js +77 -308
  86. package/dist/index.es.js.map +1 -1
  87. package/dist/index.es2.js +23 -24
  88. package/dist/index.es2.js.map +1 -1
  89. package/dist/index.es3.js +1 -1
  90. package/dist/index.es5.js +139 -0
  91. package/dist/index.es5.js.map +1 -0
  92. package/dist/next.cjs.js +2 -1
  93. package/dist/next.cjs.js.map +1 -1
  94. package/dist/next.es.js +3 -2
  95. package/dist/next.es.js.map +1 -1
  96. package/dist/react.cjs.js +2 -1
  97. package/dist/react.cjs.js.map +1 -1
  98. package/dist/react.es.js +2 -1
  99. package/dist/react.es.js.map +1 -1
  100. package/dist/types/src/api/react.d.ts.map +1 -1
  101. package/dist/types/src/components/builtin/Box/Box.d.ts.map +1 -1
  102. package/dist/types/src/components/builtin/Box/animations.d.ts +1 -1
  103. package/dist/types/src/components/builtin/Box/animations.d.ts.map +1 -1
  104. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  105. package/dist/types/src/components/builtin/Form/components/Field/components/RadioButton/index.d.ts.map +1 -1
  106. package/dist/types/src/components/builtin/Text/EditableText.d.ts +16 -0
  107. package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +1 -0
  108. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +11 -0
  109. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -0
  110. package/dist/types/src/components/builtin/Text/Text.d.ts +3 -7
  111. package/dist/types/src/components/builtin/Text/Text.d.ts.map +1 -1
  112. package/dist/types/src/components/builtin/register.d.ts.map +1 -1
  113. package/dist/types/src/components/shared/BackgroundsContainer/index.d.ts.map +1 -1
  114. package/dist/types/src/next/document.d.ts.map +1 -1
  115. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -1
  116. package/dist/types/src/runtimes/react/element-imperative-handle.d.ts +12 -0
  117. package/dist/types/src/runtimes/react/element-imperative-handle.d.ts.map +1 -0
  118. package/dist/types/src/runtimes/react/find-dom-node.d.ts +1 -1
  119. package/dist/types/src/runtimes/react/find-dom-node.d.ts.map +1 -1
  120. package/dist/types/src/runtimes/react/index.d.ts +4 -2
  121. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  122. package/dist/types/src/state/actions.d.ts +4 -3
  123. package/dist/types/src/state/actions.d.ts.map +1 -1
  124. package/dist/types/src/state/modules/is-preview.d.ts +6 -0
  125. package/dist/types/src/state/modules/is-preview.d.ts.map +1 -0
  126. package/dist/types/src/state/react-builder-preview.d.ts +1 -0
  127. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  128. package/dist/types/src/state/react-page.d.ts +2 -0
  129. package/dist/types/src/state/react-page.d.ts.map +1 -1
  130. package/package.json +4 -1
@@ -0,0 +1,352 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { forwardRef, useMemo, useState, useImperativeHandle, useEffect, useRef, useCallback } from "react";
33
+ import { Value } from "slate";
34
+ import Hotkeys from "slate-hotkeys";
35
+ import { isHotkey } from "is-hotkey";
36
+ import { g as getBox } from "./box-models.es.js";
37
+ import { Editor } from "slate-react";
38
+ import Lists from "@convertkit/slate-lists";
39
+ import { M as Mark, D as DeviceOverrideBlock } from "./index.es5.js";
40
+ import { jsx } from "react/jsx-runtime";
41
+ import { cx } from "@emotion/css";
42
+ import { o as useStyle, u as useIsInBuilder } from "./index.es.js";
43
+ import { L as Link } from "./index.es3.js";
44
+ import "use-sync-external-store/shim";
45
+ import "./slot.es.js";
46
+ import "css-box-model";
47
+ import "./actions.es.js";
48
+ import "./constants.es.js";
49
+ import "redux";
50
+ import "redux-thunk";
51
+ import "./control.es.js";
52
+ import "use-sync-external-store/shim/with-selector";
53
+ import "next/dynamic";
54
+ import "@emotion/serialize";
55
+ import "@emotion/utils";
56
+ import "./text-input.es.js";
57
+ import "./combobox.es.js";
58
+ import "./types.es.js";
59
+ import "color";
60
+ import "scroll-into-view-if-needed";
61
+ import "react-dom";
62
+ import "html-react-parser";
63
+ import "next/head";
64
+ import "@emotion/server/create-instance";
65
+ import "next/document";
66
+ import "cookie";
67
+ import "cors";
68
+ import "http-proxy";
69
+ import "set-cookie-parser";
70
+ import "uuid/v4";
71
+ import "corporate-ipsum";
72
+ import "next/link";
73
+ const TYPOGRAPHY_TYPE = "typography";
74
+ function DeviceOverridesMarksPlugin() {
75
+ return {
76
+ renderMark({
77
+ mark,
78
+ children
79
+ }, _editor, next) {
80
+ if (mark.type === TYPOGRAPHY_TYPE) {
81
+ return /* @__PURE__ */ jsx(Mark, {
82
+ value: mark.data.get("value"),
83
+ children
84
+ });
85
+ }
86
+ return next();
87
+ }
88
+ };
89
+ }
90
+ function DeviceOverridesBlockPlugin() {
91
+ return {
92
+ renderBlock(props, _editor, next) {
93
+ const {
94
+ node,
95
+ attributes,
96
+ children
97
+ } = props;
98
+ const blockProps = {
99
+ textAlign: node.data.get("textAlign")
100
+ };
101
+ switch (node.type) {
102
+ case "paragraph":
103
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
104
+ as: "p",
105
+ children
106
+ }));
107
+ case "heading-one":
108
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
109
+ as: "h1",
110
+ children
111
+ }));
112
+ case "heading-two":
113
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
114
+ as: "h2",
115
+ children
116
+ }));
117
+ case "heading-three":
118
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
119
+ as: "h3",
120
+ children
121
+ }));
122
+ case "heading-four":
123
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
124
+ as: "h4",
125
+ children
126
+ }));
127
+ case "heading-five":
128
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
129
+ as: "h5",
130
+ children
131
+ }));
132
+ case "heading-six":
133
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
134
+ as: "h6",
135
+ children
136
+ }));
137
+ case "blockquote":
138
+ return /* @__PURE__ */ jsx(DeviceOverrideBlock, __spreadProps(__spreadValues(__spreadValues({}, attributes), blockProps), {
139
+ as: "blockquote",
140
+ children
141
+ }));
142
+ default:
143
+ return next();
144
+ }
145
+ }
146
+ };
147
+ }
148
+ function StyledLink(_a) {
149
+ var _b = _a, {
150
+ className
151
+ } = _b, restOfProps = __objRest(_b, [
152
+ "className"
153
+ ]);
154
+ return /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({}, restOfProps), {
155
+ className: cx(useStyle({
156
+ textDecoration: "none"
157
+ }), className)
158
+ }));
159
+ }
160
+ function LinkPlugin() {
161
+ return {
162
+ renderInline(props, _editor, next) {
163
+ const {
164
+ attributes,
165
+ children,
166
+ node
167
+ } = props;
168
+ switch (node.type) {
169
+ case "link": {
170
+ const {
171
+ data
172
+ } = node;
173
+ return /* @__PURE__ */ jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
174
+ link: data.toJS(),
175
+ children
176
+ }));
177
+ }
178
+ default: {
179
+ return next();
180
+ }
181
+ }
182
+ }
183
+ };
184
+ }
185
+ function Inlines() {
186
+ return {
187
+ renderInline(props, _editor, next) {
188
+ const {
189
+ attributes,
190
+ children,
191
+ node
192
+ } = props;
193
+ switch (node.type) {
194
+ case "code": {
195
+ return /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({}, attributes), {
196
+ children
197
+ }));
198
+ }
199
+ case "superscript": {
200
+ return /* @__PURE__ */ jsx("sup", __spreadProps(__spreadValues({}, attributes), {
201
+ children
202
+ }));
203
+ }
204
+ case "subscript": {
205
+ return /* @__PURE__ */ jsx("sub", __spreadProps(__spreadValues({}, attributes), {
206
+ children
207
+ }));
208
+ }
209
+ default: {
210
+ return next();
211
+ }
212
+ }
213
+ }
214
+ };
215
+ }
216
+ const RichTextEditor = forwardRef(function RichTextEditor2(_c, ref) {
217
+ var _d = _c, {
218
+ placeholder = "Write some text...",
219
+ className
220
+ } = _d, restOfProps = __objRest(_d, [
221
+ "placeholder",
222
+ "className"
223
+ ]);
224
+ const plugins = useMemo(() => [Lists(), LinkPlugin(), Inlines(), DeviceOverridesBlockPlugin(), DeviceOverridesMarksPlugin()], []);
225
+ return /* @__PURE__ */ jsx(Editor, __spreadProps(__spreadValues({}, restOfProps), {
226
+ style: {
227
+ WebkitUserModify: void 0
228
+ },
229
+ className: cx(useStyle({
230
+ "ul, ol": {
231
+ margin: 0
232
+ }
233
+ }), className),
234
+ ref,
235
+ autoFocus: false,
236
+ plugins,
237
+ placeholder
238
+ }));
239
+ });
240
+ const defaultText = {
241
+ document: {
242
+ nodes: [{
243
+ object: "block",
244
+ type: "paragraph",
245
+ nodes: []
246
+ }]
247
+ },
248
+ data: {}
249
+ };
250
+ const COMMIT_DEBOUNCE_DELAY = 500;
251
+ const EditableText = forwardRef(function EditableText2({
252
+ id,
253
+ text,
254
+ width,
255
+ margin
256
+ }, ref) {
257
+ const [editor, setEditor] = useState(null);
258
+ const [propControllers, setPropControllers] = useState(null);
259
+ const controller = propControllers == null ? void 0 : propControllers.text;
260
+ useImperativeHandle(ref, () => ({
261
+ getBoxModel() {
262
+ const el = editor == null ? void 0 : editor.findDOMNode([]);
263
+ return el instanceof Element ? getBox(el) : null;
264
+ },
265
+ setPropControllers
266
+ }), [editor, setPropControllers]);
267
+ useEffect(() => {
268
+ if (editor)
269
+ controller == null ? void 0 : controller.setSlateEditor(editor);
270
+ }, [controller, editor]);
271
+ const [value, setValue] = useState(() => {
272
+ const _a = text != null ? text : defaultText, {
273
+ selection
274
+ } = _a, textWithoutSelection = __objRest(_a, [
275
+ "selection"
276
+ ]);
277
+ return Value.fromJSON(textWithoutSelection);
278
+ });
279
+ const [shouldCommit, setShouldCommit] = useState(true);
280
+ useEffect(() => {
281
+ if (shouldCommit) {
282
+ const nextValue = Value.fromJSON(text != null ? text : defaultText);
283
+ setValue((currentValue) => currentValue.selection.isBlurred ? Value.fromJSON(nextValue.toJSON({
284
+ preserveSelection: false
285
+ })) : nextValue);
286
+ }
287
+ }, [shouldCommit, text]);
288
+ useEffect(() => {
289
+ if (shouldCommit)
290
+ return;
291
+ const timeoutId = window.setTimeout(() => {
292
+ setShouldCommit(true);
293
+ }, COMMIT_DEBOUNCE_DELAY);
294
+ return () => {
295
+ window.clearTimeout(timeoutId);
296
+ };
297
+ }, [shouldCommit]);
298
+ function handleChange(change) {
299
+ setValue(change.value);
300
+ if (change.value !== value) {
301
+ setShouldCommit(false);
302
+ controller == null ? void 0 : controller.onChange(change);
303
+ }
304
+ }
305
+ const lastController = useRef(controller);
306
+ if (lastController.current !== controller)
307
+ lastController.current = controller;
308
+ const handleFocus = useCallback(() => {
309
+ var _a;
310
+ (_a = lastController.current) == null ? void 0 : _a.focus();
311
+ }, []);
312
+ const handleKeyDown = useCallback((event, _editor, next) => {
313
+ var _a, _b, _c;
314
+ if (Hotkeys.isUndo(event)) {
315
+ (_a = lastController.current) == null ? void 0 : _a.undo();
316
+ return true;
317
+ }
318
+ if (Hotkeys.isRedo(event)) {
319
+ (_b = lastController.current) == null ? void 0 : _b.redo();
320
+ return true;
321
+ }
322
+ if (isHotkey("escape")(event)) {
323
+ (_c = lastController.current) == null ? void 0 : _c.blur();
324
+ return true;
325
+ }
326
+ return next();
327
+ }, []);
328
+ const handleBlur = useCallback((event, editor2, next) => {
329
+ const selection = editor2.value.selection;
330
+ next();
331
+ if (event.relatedTarget == null)
332
+ editor2.select(selection);
333
+ }, []);
334
+ const isInBuilder = useIsInBuilder();
335
+ return /* @__PURE__ */ jsx(RichTextEditor, {
336
+ id,
337
+ ref: setEditor,
338
+ className: cx(useStyle({
339
+ "ul, ol": {
340
+ margin: 0
341
+ }
342
+ }), width, margin),
343
+ value,
344
+ onChange: handleChange,
345
+ onFocus: handleFocus,
346
+ onKeyDown: handleKeyDown,
347
+ onBlur: handleBlur,
348
+ readOnly: !isInBuilder || controller == null
349
+ });
350
+ });
351
+ export { EditableText as default };
352
+ //# sourceMappingURL=EditableText.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditableText.es.js","sources":["../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Link.tsx","../src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.tsx","../src/components/builtin/Text/components/RichTextEditor/index.tsx","../src/components/builtin/Text/EditableText.tsx"],"sourcesContent":["import type { Plugin } from 'slate-react'\n\nimport Mark from '../components/Mark'\n\nconst TYPOGRAPHY_TYPE = 'typography'\n\nexport default function DeviceOverridesMarksPlugin(): Plugin {\n return {\n renderMark({ mark, children }, _editor, next) {\n if (mark.type === TYPOGRAPHY_TYPE) {\n return <Mark value={mark.data.get('value')}>{children}</Mark>\n }\n\n return next()\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nimport Block from '../components/Block'\n\nexport default function DeviceOverridesBlockPlugin(): Plugin {\n return {\n renderBlock(props, _editor, next): JSX.Element {\n const { node, attributes, children } = props\n const blockProps = { textAlign: node.data.get('textAlign') }\n\n switch (node.type) {\n case 'paragraph':\n return (\n <Block {...attributes} {...blockProps} as=\"p\">\n {children}\n </Block>\n )\n\n case 'heading-one':\n return (\n <Block {...attributes} {...blockProps} as=\"h1\">\n {children}\n </Block>\n )\n\n case 'heading-two':\n return (\n <Block {...attributes} {...blockProps} as=\"h2\">\n {children}\n </Block>\n )\n\n case 'heading-three':\n return (\n <Block {...attributes} {...blockProps} as=\"h3\">\n {children}\n </Block>\n )\n\n case 'heading-four':\n return (\n <Block {...attributes} {...blockProps} as=\"h4\">\n {children}\n </Block>\n )\n\n case 'heading-five':\n return (\n <Block {...attributes} {...blockProps} as=\"h5\">\n {children}\n </Block>\n )\n\n case 'heading-six':\n return (\n <Block {...attributes} {...blockProps} as=\"h6\">\n {children}\n </Block>\n )\n\n case 'blockquote':\n return (\n <Block {...attributes} {...blockProps} as=\"blockquote\">\n {children}\n </Block>\n )\n\n default:\n return next()\n }\n },\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { Plugin } from 'slate-react'\nimport { useStyle } from '../../../../../../runtimes/react/use-style'\n\nimport { Link } from '../../../../../shared/Link'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport default function LinkPlugin(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'link': {\n const { data } = node\n\n return (\n <StyledLink {...attributes} link={data.toJS()}>\n {children}\n </StyledLink>\n )\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { Plugin } from 'slate-react'\n\nexport default function Inlines(): Plugin {\n return {\n renderInline(props, _editor, next) {\n const { attributes, children, node } = props\n\n switch (node.type) {\n case 'code': {\n return <code {...attributes}>{children}</code>\n }\n\n case 'superscript': {\n return <sup {...attributes}>{children}</sup>\n }\n\n case 'subscript': {\n return <sub {...attributes}>{children}</sub>\n }\n\n default: {\n return next()\n }\n }\n },\n }\n}\n","import { ComponentPropsWithoutRef, forwardRef, useMemo } from 'react'\n\nimport { Editor as SlateEditor } from 'slate-react'\n\n// @ts-expect-error: no types for '@convertkit/slate-lists'\nimport Lists from '@convertkit/slate-lists'\n\nimport DeviceOverridesMarks from './plugins/DeviceOverridesMarks'\nimport DeviceOverridesBlocks from './plugins/DeviceOverridesBlocks'\nimport Link from './plugins/Link'\nimport Inlines from './plugins/Inlines'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\nexport { overrideTypographyStyle } from './components/Mark'\n\ntype Props = ComponentPropsWithoutRef<typeof SlateEditor>\n\nexport const RichTextEditor = forwardRef<SlateEditor, Props>(function RichTextEditor(\n { placeholder = 'Write some text...', className, ...restOfProps }: Props,\n ref,\n) {\n const plugins = useMemo(\n () => [Lists(), Link(), Inlines(), DeviceOverridesBlocks(), DeviceOverridesMarks()],\n [],\n )\n\n return (\n <SlateEditor\n {...restOfProps}\n // Workaround because our Slate editor is broken on Chrome 105\n // Problem: https://linear.app/makeswift/issue/PRD-434/our-rich-text-component-breaks-in-the-latest-version-of-chrome\n // Workaround: https://github.com/ianstormtaylor/slate/issues/5110#issuecomment-1234951122\n style={{ WebkitUserModify: undefined }}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), className)}\n ref={ref}\n autoFocus={false}\n plugins={plugins}\n placeholder={placeholder}\n />\n )\n})\n","import {\n useState,\n Ref,\n useImperativeHandle,\n forwardRef,\n useEffect,\n useCallback,\n useRef,\n KeyboardEvent as ReactKeyboardEvent,\n FocusEvent as ReactFocusEvent,\n} from 'react'\nimport { Editor, OnChangeParam } from 'slate-react'\nimport { Value, ValueJSON } from 'slate'\n// @ts-expect-error: no types for 'slate-hotkeys'\nimport Hotkeys from 'slate-hotkeys'\nimport { isHotkey } from 'is-hotkey'\n\nimport {\n ElementIDValue,\n RichTextDescriptor,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { BoxModelHandle, getBox } from '../../../box-model'\nimport { PropControllersHandle } from '../../../state/modules/prop-controller-handles'\nimport { RichTextEditor } from './components/RichTextEditor'\nimport { DescriptorsPropControllers } from '../../../prop-controllers/instances'\nimport { cx } from '@emotion/css'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { useIsInBuilder } from '../../../runtimes/react'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: ValueJSON = {\n document: { nodes: [{ object: 'block' as const, type: 'paragraph' as const, nodes: [] }] },\n data: {},\n}\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\ntype Descriptors = { text?: RichTextDescriptor }\n\nconst EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<BoxModelHandle & PropControllersHandle<Descriptors>>,\n) {\n const [editor, setEditor] = useState<Editor | null>(null)\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useImperativeHandle(\n ref,\n () => ({\n getBoxModel() {\n const el = editor?.findDOMNode([])\n\n return el instanceof Element ? getBox(el) : null\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n useEffect(() => {\n if (editor) controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n /**\n * We must keep local state so that we can reflect the user's typed changes immediately. At the\n * same time, though, the source of truth for the data is the prop data. This presents a\n * challenge: how do we keep local state in sync with the prop data without mangling user input as\n * data comes in?\n *\n * Consider, for example, that the user types \"Hello\". If at a later time, when the user is trying\n * to type \", world\" the component re-renders with prop data \"H\", \"He\", \"Hel\", \"Hell\", \"Hello\", it\n * will disrupt the user's typing. This could also happen as a result of the prop data changing\n * for other reasons, like collaborators changing the prop data concurrently. We want to avoid to\n * disrupt the user's typing, while at the same time display the \"true\" value as quickly as\n * possible.\n *\n * The approach we take here is to commit the prop data at an opportune time: as the user is\n * typing we avoid to commit prop data. But once they've stopped typing, we commit it as soon as\n * possible. This is known as a debounce.\n */\n const [value, setValue] = useState(() => {\n const { selection, ...textWithoutSelection } = text ?? defaultText\n\n return Value.fromJSON(textWithoutSelection)\n })\n const [shouldCommit, setShouldCommit] = useState(true)\n\n useEffect(() => {\n if (shouldCommit) {\n const nextValue = Value.fromJSON(text ?? defaultText)\n\n setValue(currentValue =>\n currentValue.selection.isBlurred\n ? Value.fromJSON(nextValue.toJSON({ preserveSelection: false }))\n : nextValue,\n )\n }\n }, [shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n function handleChange(change: OnChangeParam) {\n setValue(change.value as Value)\n\n if (change.value !== value) {\n setShouldCommit(false)\n\n controller?.onChange(change)\n }\n }\n\n // HACK: Slate holds on to the very first DOM event handlers passed in and doesn't update them\n // even if they change. Since `controller` is first `undefined` then we must use a ref.\n const lastController = useRef(controller)\n if (lastController.current !== controller) lastController.current = controller\n const handleFocus = useCallback(() => {\n lastController.current?.focus()\n }, [])\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent, _editor: Editor, next: () => any) => {\n if (Hotkeys.isUndo(event)) {\n lastController.current?.undo()\n\n return true\n }\n\n if (Hotkeys.isRedo(event)) {\n lastController.current?.redo()\n\n return true\n }\n\n if (isHotkey('escape')(event)) {\n lastController.current?.blur()\n\n return true\n }\n\n return next()\n },\n [],\n )\n const handleBlur = useCallback((event: ReactFocusEvent, editor: Editor, next: () => any) => {\n const selection = editor.value.selection\n\n next()\n\n // Normally, after a user highlight a text, clicking on the panel will remove the text selection.\n // This line is a workaround for that. Because the panel is not in the iframe, relatedTarget\n // would be null, and we select the previous text selection to maintain the text highlight.\n // Inspiration: https://github.com/ianstormtaylor/slate/issues/3412#issuecomment-663906003\n if (event.relatedTarget == null) editor.select(selection)\n }, [])\n\n const isInBuilder = useIsInBuilder()\n\n return (\n <RichTextEditor\n // @ts-expect-error: types don't allow for 'id' prop even though it's used.\n id={id}\n ref={setEditor}\n className={cx(useStyle({ 'ul, ol': { margin: 0 } }), width, margin)}\n value={value}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n readOnly={!isInBuilder || controller == null}\n />\n )\n})\n\nexport default EditableText\n"],"names":["TYPOGRAPHY_TYPE","renderMark","mark","children","_editor","next","type","data","get","renderBlock","props","node","attributes","blockProps","textAlign","Block","className","restOfProps","cx","useStyle","textDecoration","renderInline","toJS","RichTextEditor","forwardRef","ref","placeholder","plugins","useMemo","Lists","Link","Inlines","DeviceOverridesBlocks","DeviceOverridesMarks","SlateEditor","WebkitUserModify","undefined","margin","defaultText","document","nodes","object","COMMIT_DEBOUNCE_DELAY","EditableText","id","text","width","editor","setEditor","useState","propControllers","setPropControllers","controller","useImperativeHandle","getBoxModel","el","findDOMNode","Element","getBox","useEffect","setSlateEditor","value","setValue","selection","textWithoutSelection","Value","fromJSON","shouldCommit","setShouldCommit","nextValue","currentValue","isBlurred","toJSON","preserveSelection","timeoutId","window","setTimeout","clearTimeout","change","onChange","lastController","useRef","current","handleFocus","useCallback","focus","handleKeyDown","event","Hotkeys","isUndo","undo","isRedo","redo","isHotkey","blur","handleBlur","relatedTarget","select","isInBuilder","useIsInBuilder","handleChange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,kBAAkB;AAEqC,sCAAA;AACpD,SAAA;AAAA,IACLC,WAAW;AAAA,MAAEC;AAAAA,MAAMC;AAAAA,OAAYC,SAASC,MAAM;AACxCH,UAAAA,KAAKI,SAASN,iBAAiB;AACjC,mCAAQ,MAAD;AAAA,UAAM,OAAOE,KAAKK,KAAKC,IAAI,OAAd;AAAA,UAAyBL;AAAAA,QAAAA,CAA7C;AAAA,MACD;AAED,aAAOE,KAAP;AAAA,IACD;AAAA,EAAA;AAEJ;ACZ4D,sCAAA;AACpD,SAAA;AAAA,IACLI,YAAYC,OAAON,SAASC,MAAmB;AACvC,YAAA;AAAA,QAAEM;AAAAA,QAAMC;AAAAA,QAAYT;AAAAA,UAAaO;AACvC,YAAMG,aAAa;AAAA,QAAEC,WAAWH,KAAKJ,KAAKC,IAAI,WAAd;AAAA,MAAA;AAExBG,cAAAA,KAAKL;AAAAA,aACN;AAED,qCAACS,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCV;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,qCAACY,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCV;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,qCAACY,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCV;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,qCAACY,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,YACvCV;AAAAA,UAAAA,EAFL;AAAA,aAMG;AAED,qCAACY,qBAAD,gDAAWH,aAAgBC,aAA3B;AAAA,YAAuC,IAAG;AAAA,Y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,QAAQS;AAAAA,IACR,UAAU,CAACG,eAAe9C,cAAc;AAAA,EAAA,CAX5C;AAcD,CA/I8B;;"}
package/dist/Embed.cjs.js CHANGED
@@ -13,10 +13,11 @@ require("redux-thunk");
13
13
  require("./actions.cjs.js");
14
14
  require("./slot.cjs.js");
15
15
  require("./control.cjs.js");
16
+ require("@emotion/serialize");
17
+ require("@emotion/utils");
16
18
  require("./text-input.cjs.js");
17
19
  require("./combobox.cjs.js");
18
20
  require("use-sync-external-store/shim");
19
- require("slate");
20
21
  require("./types.cjs.js");
21
22
  require("color");
22
23
  require("scroll-into-view-if-needed");
@@ -1 +1 @@
1
- {"version":3,"file":"Embed.cjs.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { ElementIDValue, TextAreaValue } from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","className","useStyle","minHeight","cx","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEbC,MAAAA,QAAQC,MAAAA,WAAW,gBACvB;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAOC;AAAAA,EAAQC,OAAOP;AAAAA,GAC5BQ,KACA;AACA,QAAM,CAACC,WAAWC,gBAAgBC,MAAAA,SAAgC,IAAxB;AACpC,QAAA,CAACC,cAAcC,mBAAmBF,MAAAA,SAAS,KAAD;AAEhDG,4BAAAA,0BAA0B,MAAM;AAC9BD,oBAAgB,IAAD;AAAA,EADQ,GAEtB,CAFsB,CAAA;AAIzBE,QAAAA,oBAAoBP,KAAK,MAAMC,WAAW,CAACA,SAAD,CAAvB;AAEnBO,QAAAA,UAAU,MAAM;AAGV,QAAA,CAACP;AAAW;AAEhB,UAAMQ,SAASR,UAAUS,cAAcC,iBAAiBV,WAAWW,WAAWC,cAAc;AAAA,MAC1FC,WAAWC,MAAe;AACxB,eAAOA,KAAKC,QAAQC,kBAAkBxB,aAClCmB,WAAWM,gBACXN,WAAWO;AAAAA,MAChB;AAAA,IAAA,CALY;AAQf,UAAMC,QAAmB,CAAA;AAEzB,WAAOX,OAAOY,SAAP;AAAyBC,YAAAA,KAAKb,OAAOc;AAOL,2CAAA;AACrC,eAASC,IAAI,GAAGA,IAAIJ,MAAMK,QAAQD,KAAK;AAC/B,cAAA,IAAIE,QAAcC,CAAW,YAAA;;AACjC,gBAAMZ,OAAOK,MAAMI;AACbI,gBAAAA,SAASb,KAAKL,cAAcmB,cAAcpC,UAAjC;AAEfmC,iBAAOE,cAAcf,KAAKe;AAC1BC,gBAAMC,KAAKjB,KAAKkB,UAAhB,EAA4BC,QAAQ,CAAC;AAAA,YAAEC;AAAAA,YAAMC;AAAAA,gBAAY;AAChDC,mBAAAA,aAAaF,MAAMC,KAA1B;AAAA,UAAA,CADF;AAIOE,iBAAAA,SAAS,MAAMX;AACfY,iBAAAA,UAAU,MAAMZ;AAElBa,qBAAAA,eAAAA,mBAAYC,aAAab,QAAQb;AACjCyB,qBAAAA,eAAAA,mBAAYE,YAAY3B;AAEzB,cAAA,CAACa,OAAOe,aAAa,KAApB;AAAmC;QAAA,CAfpC;AAAA,MAiBP;AAAA,IACF;AAEoB,0BAAA,EAAGC,MAAMC,CAAS,UAAA;AAErCC,cAAQD,MAAMA,KAAd;AAAA,IAAA,CAFF;AAAA,EAAA,GAIC,CAAC5C,WAAWF,IAAZ,CAhDM;AAkDHgD,QAAAA,YAAYC,KAAAA,SAAS;AAAA,IAAEC,WAAW;AAAA,EAAA,CAAd;AAE1B,MAAI7C,iBAAiB;AAAc,WAAA;AAGjC,wCAAA,OAAA;AAAA,IACE,KAAKF;AAAAA,IACL;AAAA,IACA,WAAWgD,IAAAA,GAAGH,WAAWlD,OAAOC,MAAnB;AAAA,IACb,yBAAyB;AAAA,MAAEqD,QAAQpD;AAAAA,IAAV;AAAA,EAAA,CAL7B;AAQD,CA3EuB;;"}
1
+ {"version":3,"file":"Embed.cjs.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { ElementIDValue, TextAreaValue } from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","className","useStyle","minHeight","cx","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEb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B;AAEzB,cAAA,CAACa,OAAOe,aAAa,KAApB;AAAmC;QAAA,CAfpC;AAAA,MAiBP;AAAA,IACF;AAEoB,0BAAA,EAAGC,MAAMC,CAAS,UAAA;AAErCC,cAAQD,MAAMA,KAAd;AAAA,IAAA,CAFF;AAAA,EAAA,GAIC,CAAC5C,WAAWF,IAAZ,CAhDM;AAkDHgD,QAAAA,YAAYC,KAAAA,SAAS;AAAA,IAAEC,WAAW;AAAA,EAAA,CAAd;AAE1B,MAAI7C,iBAAiB;AAAc,WAAA;AAGjC,wCAAA,OAAA;AAAA,IACE,KAAKF;AAAAA,IACL;AAAA,IACA,WAAWgD,IAAAA,GAAGH,WAAWlD,OAAOC,MAAnB;AAAA,IACb,yBAAyB;AAAA,MAAEqD,QAAQpD;AAAAA,IAAV;AAAA,EAAA,CAL7B;AAQD,CA3EuB;;"}
package/dist/Embed.es.js CHANGED
@@ -11,10 +11,11 @@ import "redux-thunk";
11
11
  import "./actions.es.js";
12
12
  import "./slot.es.js";
13
13
  import "./control.es.js";
14
+ import "@emotion/serialize";
15
+ import "@emotion/utils";
14
16
  import "./text-input.es.js";
15
17
  import "./combobox.es.js";
16
18
  import "use-sync-external-store/shim";
17
- import "slate";
18
19
  import "./types.es.js";
19
20
  import "color";
20
21
  import "scroll-into-view-if-needed";
@@ -1 +1 @@
1
- {"version":3,"file":"Embed.es.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { ElementIDValue, TextAreaValue } from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","className","useStyle","minHeight","cx","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEbC,MAAAA,QAAQC,WAAW,gBACvB;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAOC;AAAAA,EAAQC,OAAOP;AAAAA,GAC5BQ,KACA;AACA,QAAM,CAACC,WAAWC,gBAAgBC,SAAgC,IAAxB;AACpC,QAAA,CAACC,cAAcC,mBAAmBF,SAAS,KAAD;AAEhDG,4BAA0B,MAAM;AAC9BD,oBAAgB,IAAD;AAAA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AAiB;AAAc,WAAA;AAGjC,6BAAA,OAAA;AAAA,IACE,KAAKF;AAAAA,IACL;AAAA,IACA,WAAWgD,GAAGH,WAAWlD,OAAOC,MAAnB;AAAA,IACb,yBAAyB;AAAA,MAAEqD,QAAQpD;AAAAA,IAAV;AAAA,EAAA,CAL7B;AAQD,CA3EuB;;"}
1
+ {"version":3,"file":"Embed.es.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { ElementIDValue, TextAreaValue } from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","className","useStyle","minHeight","cx","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEbC,MAAAA,QAAQC,WAAW,gBACvB;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAOC;AAAAA,EAAQC,OAAOP;AAAAA,GAC5BQ,KACA;AACA,QAAM,CAACC,WAAWC,gBAAgBC,SAAgC,IAAxB;AACpC,QAAA,CAACC,cAAcC,mBAAmBF,SAAS,KAAD;AAEhDG,4BAA0B,MAAM;AAC9BD,oBAAgB,IAAD;AAAA,EADQ,GAEtB,CAFsB,CAAA;AAIzBE,sBAAoBP,KAAK,MAAMC,WAAW,CAACA,SAAD,CAAvB;AAEnBO,YAAU,MAAM;AAGV,QAAA,CAACP;AAAW;AAEhB,UAAMQ,SAASR,UAAUS,cAAcC,iBAAiBV,WAAWW,WAAWC,cAAc;AAAA,MAC1FC,WAAWC,MAAe;AACxB,eAAOA,KAAKC,QAAQC,kBAAkBxB,aAClCmB,WAAWM,gBACXN,WAAWO;AAAAA,MAChB;AAAA,IAAA,CALY;AAQf,UAAMC,QAAmB,CAAA;AAEzB,WAAOX,OAAOY,SAAP;AAAyBC,YAAAA,KAAKb,OAAOc;AAOL,2CAAA;AACrC,eAASC,IAAI,GAAGA,IAAIJ,MAAMK,QAAQD,KAAK;AAC/B,cAAA,IAAIE,QAAcC,CAAW,YAAA;;AACjC,gBAAMZ,OAAOK,MAAMI;AACbI,gBAAAA,SAASb,KAAKL,cAAcmB,cAAcpC,UAAjC;AAEfmC,iBAAO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