@makeswift/runtime 0.10.3 → 0.10.4

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 (146) hide show
  1. package/dist/Box.cjs.js +1 -3
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +2 -4
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +4 -4
  6. package/dist/Button.es.js +5 -5
  7. package/dist/Carousel.cjs.js +3 -3
  8. package/dist/Carousel.es.js +4 -4
  9. package/dist/Countdown.cjs.js +1 -3
  10. package/dist/Countdown.cjs.js.map +1 -1
  11. package/dist/Countdown.es.js +2 -4
  12. package/dist/Countdown.es.js.map +1 -1
  13. package/dist/Divider.cjs.js +1 -3
  14. package/dist/Divider.cjs.js.map +1 -1
  15. package/dist/Divider.es.js +2 -4
  16. package/dist/Divider.es.js.map +1 -1
  17. package/dist/Embed.cjs.js +1 -0
  18. package/dist/Embed.cjs.js.map +1 -1
  19. package/dist/Embed.es.js +2 -1
  20. package/dist/Embed.es.js.map +1 -1
  21. package/dist/Form.cjs.js +13 -13
  22. package/dist/Form.cjs.js.map +1 -1
  23. package/dist/Form.es.js +5 -5
  24. package/dist/Image.cjs.js +13 -13
  25. package/dist/Image.cjs.js.map +1 -1
  26. package/dist/Image.es.js +13 -13
  27. package/dist/LiveProvider.cjs.js +1 -3
  28. package/dist/LiveProvider.cjs.js.map +1 -1
  29. package/dist/LiveProvider.es.js +3 -5
  30. package/dist/LiveProvider.es.js.map +1 -1
  31. package/dist/Navigation.cjs.js +12 -12
  32. package/dist/Navigation.cjs.js.map +1 -1
  33. package/dist/Navigation.es.js +12 -12
  34. package/dist/PreviewProvider.cjs.js +1 -3
  35. package/dist/PreviewProvider.cjs.js.map +1 -1
  36. package/dist/PreviewProvider.es.js +3 -5
  37. package/dist/PreviewProvider.es.js.map +1 -1
  38. package/dist/ReadOnlyText.cjs.js +7 -6
  39. package/dist/ReadOnlyText.cjs.js.map +1 -1
  40. package/dist/ReadOnlyText.es.js +4 -3
  41. package/dist/ReadOnlyText.es.js.map +1 -1
  42. package/dist/ReadOnlyTextV2.cjs.js +7 -60
  43. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  44. package/dist/ReadOnlyTextV2.es.js +9 -62
  45. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  46. package/dist/Root.cjs.js +1 -3
  47. package/dist/Root.cjs.js.map +1 -1
  48. package/dist/Root.es.js +2 -4
  49. package/dist/Root.es.js.map +1 -1
  50. package/dist/SocialLinks.cjs.js +6 -6
  51. package/dist/SocialLinks.cjs.js.map +1 -1
  52. package/dist/SocialLinks.es.js +7 -7
  53. package/dist/Video.cjs.js +1 -0
  54. package/dist/Video.cjs.js.map +1 -1
  55. package/dist/Video.es.js +2 -1
  56. package/dist/Video.es.js.map +1 -1
  57. package/dist/builder.cjs.js +1 -0
  58. package/dist/builder.cjs.js.map +1 -1
  59. package/dist/builder.es.js +1 -0
  60. package/dist/builder.es.js.map +1 -1
  61. package/dist/components.cjs.js +3 -3
  62. package/dist/components.es.js +3 -3
  63. package/dist/control-serialization.es.js +1 -1
  64. package/dist/controls.cjs.js +1 -0
  65. package/dist/controls.cjs.js.map +1 -1
  66. package/dist/controls.es.js +2 -1
  67. package/dist/controls.es.js.map +1 -1
  68. package/dist/index.cjs.js +120 -256
  69. package/dist/index.cjs.js.map +1 -1
  70. package/dist/index.cjs3.js +107 -21
  71. package/dist/index.cjs3.js.map +1 -1
  72. package/dist/index.cjs4.js +57 -16
  73. package/dist/index.cjs4.js.map +1 -1
  74. package/dist/index.cjs5.js +42 -81
  75. package/dist/index.cjs5.js.map +1 -1
  76. package/dist/index.cjs6.js +82 -17
  77. package/dist/index.cjs6.js.map +1 -1
  78. package/dist/index.cjs7.js +18 -377
  79. package/dist/index.cjs7.js.map +1 -1
  80. package/dist/index.cjs8.js +258 -181
  81. package/dist/index.cjs8.js.map +1 -1
  82. package/dist/index.cjs9.js +343 -0
  83. package/dist/index.cjs9.js.map +1 -0
  84. package/dist/index.es.js +125 -260
  85. package/dist/index.es.js.map +1 -1
  86. package/dist/index.es2.js +1 -1
  87. package/dist/index.es3.js +103 -22
  88. package/dist/index.es3.js.map +1 -1
  89. package/dist/index.es4.js +57 -16
  90. package/dist/index.es4.js.map +1 -1
  91. package/dist/index.es5.js +42 -80
  92. package/dist/index.es5.js.map +1 -1
  93. package/dist/index.es6.js +81 -17
  94. package/dist/index.es6.js.map +1 -1
  95. package/dist/index.es7.js +18 -371
  96. package/dist/index.es7.js.map +1 -1
  97. package/dist/index.es8.js +259 -182
  98. package/dist/index.es8.js.map +1 -1
  99. package/dist/index.es9.js +336 -0
  100. package/dist/index.es9.js.map +1 -0
  101. package/dist/main.cjs.js +1 -0
  102. package/dist/main.cjs.js.map +1 -1
  103. package/dist/main.es.js +1 -0
  104. package/dist/main.es.js.map +1 -1
  105. package/dist/next.cjs.js +1 -3
  106. package/dist/next.cjs.js.map +1 -1
  107. package/dist/next.es.js +2 -4
  108. package/dist/next.es.js.map +1 -1
  109. package/dist/prop-controllers.cjs.js +1 -0
  110. package/dist/prop-controllers.cjs.js.map +1 -1
  111. package/dist/prop-controllers.es.js +1 -0
  112. package/dist/prop-controllers.es.js.map +1 -1
  113. package/dist/react-page.cjs.js +26 -6
  114. package/dist/react-page.cjs.js.map +1 -1
  115. package/dist/react-page.es.js +26 -7
  116. package/dist/react-page.es.js.map +1 -1
  117. package/dist/react.cjs.js +1 -3
  118. package/dist/react.cjs.js.map +1 -1
  119. package/dist/react.es.js +1 -3
  120. package/dist/react.es.js.map +1 -1
  121. package/dist/slate.cjs.js +9 -6
  122. package/dist/slate.cjs.js.map +1 -1
  123. package/dist/slate.es.js +9 -7
  124. package/dist/slate.es.js.map +1 -1
  125. package/dist/toText.cjs.js +67 -0
  126. package/dist/toText.cjs.js.map +1 -0
  127. package/dist/toText.es.js +66 -0
  128. package/dist/toText.es.js.map +1 -0
  129. package/dist/types/src/components/builtin/Text/register.d.ts.map +1 -1
  130. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +2 -4
  131. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  132. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  133. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.d.ts.map +1 -1
  134. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.d.ts +10 -0
  135. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.d.ts.map +1 -0
  136. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  137. package/dist/types/src/slate/BuilderPlugin/index.d.ts +2 -1
  138. package/dist/types/src/slate/BuilderPlugin/index.d.ts.map +1 -1
  139. package/dist/types/src/slate/InlineModePlugin/index.d.ts.map +1 -1
  140. package/dist/types/src/slate/index.d.ts +1 -0
  141. package/dist/types/src/slate/index.d.ts.map +1 -1
  142. package/dist/types/src/slate/utils/index.d.ts +2 -0
  143. package/dist/types/src/slate/utils/index.d.ts.map +1 -0
  144. package/dist/types/src/slate/utils/toText.d.ts +4 -0
  145. package/dist/types/src/slate/utils/toText.d.ts.map +1 -0
  146. package/package.json +1 -1
@@ -1,381 +1,22 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source)
24
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
- target[prop] = source[prop];
26
- if (source != null && __getOwnPropSymbols)
27
- for (var prop of __getOwnPropSymbols(source)) {
28
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
- target[prop] = source[prop];
30
- }
31
- return target;
32
- };
33
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
34
- var css = require("@emotion/css");
35
- var cssBoxModel = require("css-box-model");
36
- var isHotkey = require("is-hotkey");
37
- var React = require("react");
38
- var slate = require("slate");
39
- var slateReact = require("slate-react");
40
- var next = require("./index.cjs.js");
41
- var reactPage = require("./react-page.cjs.js");
42
- require("uuid");
43
- var jsxRuntime = require("react/jsx-runtime");
44
- var index = require("./index.cjs4.js");
45
- require("./state/breakpoints.cjs.js");
46
- require("./actions.cjs.js");
47
- var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
48
- require("use-sync-external-store/shim/with-selector");
49
- require("next/dynamic");
50
- require("./text-input.cjs.js");
51
- require("./combobox.cjs.js");
52
- require("use-sync-external-store/shim");
53
- require("redux");
54
- require("redux-thunk");
55
- require("./types.cjs.js");
56
- require("./box-models.cjs.js");
57
- require("color");
58
- require("scroll-into-view-if-needed");
59
- require("react-dom");
60
- require("html-react-parser");
61
- require("next/head");
62
- require("zod");
63
- require("@emotion/server/create-instance");
64
- require("next/document");
65
- require("cors");
66
- require("path-to-regexp");
67
- require("cookie");
68
- require("http-proxy");
69
- require("set-cookie-parser");
70
- require("./constants.cjs.js");
71
- require("corporate-ipsum");
72
- require("next/link");
73
- require("@emotion/serialize");
74
- require("@emotion/utils");
75
- function _interopDefaultLegacy(e) {
76
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
77
- }
78
- var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
79
- function BlockElement({
80
- element,
81
- attributes,
82
- children
83
- }) {
84
- const blockStyles = [reactPage.useStyle({
85
- margin: 0
86
- }), reactPage.useStyle(next.useResponsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
87
- textAlign
88
- })))];
89
- const quoteStyles = reactPage.useStyle({
90
- padding: "0.5em 10px",
91
- fontSize: "1.25em",
92
- fontWeight: "300",
93
- borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
94
- });
95
- switch (element.type) {
96
- case reactPage.BlockType.Default:
97
- case reactPage.BlockType.Paragraph:
98
- return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
99
- className: css.cx(...blockStyles),
100
- children
101
- }));
102
- case reactPage.BlockType.Heading1:
103
- return /* @__PURE__ */ jsxRuntime.jsx("h1", __spreadProps(__spreadValues({}, attributes), {
104
- className: css.cx(...blockStyles),
105
- children
106
- }));
107
- case reactPage.BlockType.Heading2:
108
- return /* @__PURE__ */ jsxRuntime.jsx("h2", __spreadProps(__spreadValues({}, attributes), {
109
- className: css.cx(...blockStyles),
110
- children
111
- }));
112
- case reactPage.BlockType.Heading3:
113
- return /* @__PURE__ */ jsxRuntime.jsx("h3", __spreadProps(__spreadValues({}, attributes), {
114
- className: css.cx(...blockStyles),
115
- children
116
- }));
117
- case reactPage.BlockType.Heading4:
118
- return /* @__PURE__ */ jsxRuntime.jsx("h4", __spreadProps(__spreadValues({}, attributes), {
119
- className: css.cx(...blockStyles),
120
- children
121
- }));
122
- case reactPage.BlockType.Heading5:
123
- return /* @__PURE__ */ jsxRuntime.jsx("h5", __spreadProps(__spreadValues({}, attributes), {
124
- className: css.cx(...blockStyles),
125
- children
126
- }));
127
- case reactPage.BlockType.Heading6:
128
- return /* @__PURE__ */ jsxRuntime.jsx("h6", __spreadProps(__spreadValues({}, attributes), {
129
- className: css.cx(...blockStyles),
130
- children
131
- }));
132
- case reactPage.BlockType.BlockQuote:
133
- return /* @__PURE__ */ jsxRuntime.jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
134
- className: css.cx(...blockStyles, quoteStyles),
135
- children
136
- }));
137
- case reactPage.BlockType.OrderedList:
138
- return /* @__PURE__ */ jsxRuntime.jsx("ol", __spreadProps(__spreadValues({}, attributes), {
139
- className: css.cx(...blockStyles),
140
- style: {
141
- listStylePosition: "inside"
142
- },
143
- children
144
- }));
145
- case reactPage.BlockType.UnorderedList:
146
- return /* @__PURE__ */ jsxRuntime.jsx("ul", __spreadProps(__spreadValues({}, attributes), {
147
- className: css.cx(...blockStyles),
148
- style: {
149
- listStylePosition: "inside"
150
- },
151
- children
152
- }));
153
- case reactPage.BlockType.ListItem:
154
- return /* @__PURE__ */ jsxRuntime.jsx("li", __spreadProps(__spreadValues({}, attributes), {
155
- className: css.cx(...blockStyles),
156
- children
157
- }));
158
- case reactPage.BlockType.ListItemChild:
159
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
160
- className: css.cx(...blockStyles),
161
- children
162
- }));
163
- }
164
- }
165
- function StyledLink(_a) {
166
- var _b = _a, {
167
- className
168
- } = _b, restOfProps = __objRest(_b, [
169
- "className"
170
- ]);
171
- return /* @__PURE__ */ jsxRuntime.jsx(next.Link, __spreadProps(__spreadValues({}, restOfProps), {
172
- className: css.cx(reactPage.useStyle({
173
- textDecoration: "none"
174
- }), className)
175
- }));
176
- }
177
- function InlineElement({
178
- element,
179
- attributes,
180
- children
181
- }) {
182
- var _a;
183
- switch (element.type) {
184
- case reactPage.InlineType.Code:
185
- return /* @__PURE__ */ jsxRuntime.jsx("code", __spreadProps(__spreadValues({}, attributes), {
186
- children
187
- }));
188
- case reactPage.InlineType.SuperScript:
189
- return /* @__PURE__ */ jsxRuntime.jsx("sup", __spreadProps(__spreadValues({}, attributes), {
190
- children
191
- }));
192
- case reactPage.InlineType.SubScript:
193
- return /* @__PURE__ */ jsxRuntime.jsx("sub", __spreadProps(__spreadValues({}, attributes), {
194
- children
195
- }));
196
- case reactPage.InlineType.Link:
197
- return /* @__PURE__ */ jsxRuntime.jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
198
- link: (_a = element.link) != null ? _a : void 0,
199
- children
200
- }));
201
- }
202
- }
203
- function Element(_c) {
204
- var _d = _c, {
205
- element
206
- } = _d, props = __objRest(_d, [
207
- "element"
208
- ]);
209
- switch (element.type) {
210
- case reactPage.InlineType.Code:
211
- case reactPage.InlineType.SuperScript:
212
- case reactPage.InlineType.SubScript:
213
- case reactPage.InlineType.Link:
214
- return /* @__PURE__ */ jsxRuntime.jsx(InlineElement, __spreadValues({
215
- element
216
- }, props));
217
- case reactPage.BlockType.Default:
218
- case reactPage.BlockType.Paragraph:
219
- case reactPage.BlockType.Heading1:
220
- case reactPage.BlockType.Heading2:
221
- case reactPage.BlockType.Heading3:
222
- case reactPage.BlockType.Heading4:
223
- case reactPage.BlockType.Heading5:
224
- case reactPage.BlockType.Heading6:
225
- case reactPage.BlockType.BlockQuote:
226
- case reactPage.BlockType.OrderedList:
227
- case reactPage.BlockType.UnorderedList:
228
- case reactPage.BlockType.ListItem:
229
- case reactPage.BlockType.ListItemChild:
230
- return /* @__PURE__ */ jsxRuntime.jsx(BlockElement, __spreadValues({
231
- element
232
- }, props));
233
- default:
234
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
235
- children: props.children
236
- }));
237
- }
238
- }
239
- function Leaf(_e) {
240
- var _f = _e, {
241
- leaf
242
- } = _f, props = __objRest(_f, [
243
- "leaf"
244
- ]);
245
- const enhancedTypography = next.useEnhancedTypography(leaf.typography);
246
- const typographyClassName = next.useTypographyClassName(enhancedTypography);
247
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
248
- className: typographyClassName,
249
- children: props.children
250
- }));
251
- }
252
- function useSyncDOMSelection(editor, isEnabled) {
253
- useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
254
- if (!isEnabled || editor.selection == null || slateReact.ReactEditor.isFocused(editor))
2
+ var uuid = require("uuid");
3
+ function withLocalChanges(editor) {
4
+ editor.localChanges = /* @__PURE__ */ new Map();
5
+ editor.recentLocalChanges = [];
6
+ editor.currentKey = "";
7
+ const _onChange = editor.onChange;
8
+ editor.onChange = (options) => {
9
+ _onChange(options);
10
+ if (editor == null || (options == null ? void 0 : options.operation) == null)
255
11
  return;
256
- try {
257
- const root = slateReact.ReactEditor.findDocumentOrShadowRoot(editor);
258
- const domSelection = root.getSelection();
259
- const newDomRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
260
- if (newDomRange) {
261
- if (slate.Range.isBackward(editor.selection)) {
262
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
263
- } else {
264
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
265
- }
266
- } else {
267
- domSelection == null ? void 0 : domSelection.removeAllRanges();
268
- }
269
- } catch (e) {
270
- console.error(e);
271
- }
272
- });
273
- }
274
- const COMMIT_DEBOUNCE_DELAY = 500;
275
- function useSyncWithBuilder(editor, text) {
276
- const [shouldCommit, setShouldCommit] = React.useState(true);
277
- const isInBuilder = next.useIsInBuilder();
278
- React.useEffect(() => {
279
- if (shouldCommit && text && isInBuilder) {
280
- const nextValue = reactPage.richTextDTOtoDAO(text);
281
- const nextSelection = reactPage.richTextDTOtoSelection(text);
282
- if (!reactPage.deepEqual(editor.children, nextValue) || !reactPage.deepEqual(editor.selection, nextSelection)) {
283
- editor.children = nextValue;
284
- editor.selection = nextSelection;
285
- editor.onChange();
286
- }
287
- }
288
- }, [editor, shouldCommit, text]);
289
- React.useEffect(() => {
290
- if (shouldCommit)
291
- return;
292
- const timeoutId = window.setTimeout(() => {
293
- setShouldCommit(true);
294
- }, COMMIT_DEBOUNCE_DELAY);
295
- return () => {
296
- window.clearTimeout(timeoutId);
297
- };
298
- }, [shouldCommit]);
299
- return React.useCallback(() => setShouldCommit(false), []);
300
- }
301
- const defaultText = [{
302
- type: reactPage.BlockType.Paragraph,
303
- children: [{
304
- text: ""
305
- }]
306
- }];
307
- const EditableText = React.forwardRef(function EditableText2({
308
- id,
309
- text,
310
- width,
311
- margin
312
- }, ref) {
313
- const [editor] = React.useState(() => reactPage.withBlock(reactPage.withTypography(index.withBuilder(slateReact.withReact(slate.createEditor())))));
314
- const [isPreservingDOMSElection, setIsPreservingDOMSelection] = React.useState(false);
315
- useSyncDOMSelection(editor, isPreservingDOMSElection);
316
- const delaySync = useSyncWithBuilder(editor, text);
317
- const editMode = next.useBuilderEditMode();
318
- const [propControllers, setPropControllers] = React.useState(null);
319
- const controller = propControllers == null ? void 0 : propControllers.text;
320
- React.useEffect(() => {
321
- if (controller == null)
322
- return;
323
- const element = slateReact.ReactEditor.toDOMNode(editor, editor);
324
- return next.pollBoxModel({
325
- element,
326
- onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
12
+ const key = uuid.v4();
13
+ editor.localChanges.set(key, {
14
+ selection: editor.selection,
15
+ time: performance.now()
327
16
  });
328
- }, [editor, controller]);
329
- React.useImperativeHandle(ref, () => ({
330
- getDomNode() {
331
- return slateReact.ReactEditor.toDOMNode(editor, editor);
332
- },
333
- getBoxModel() {
334
- return cssBoxModel.getBox(slateReact.ReactEditor.toDOMNode(editor, editor));
335
- },
336
- setPropControllers
337
- }), [editor, setPropControllers]);
338
- const initialValue = React.useMemo(() => text ? reactPage.richTextDTOtoDAO(text) : defaultText, [text]);
339
- React.useEffect(() => {
340
- controller == null ? void 0 : controller.setSlateEditor(editor);
341
- }, [controller, editor]);
342
- const handleFocus = React.useCallback(() => {
343
- controller == null ? void 0 : controller.focus();
344
- setIsPreservingDOMSelection(true);
345
- }, [controller]);
346
- const handleKeyDown = React.useCallback((e) => {
347
- if (isHotkey__default["default"]("mod+shift+z", e))
348
- return controller == null ? void 0 : controller.redo();
349
- if (isHotkey__default["default"]("mod+z", e))
350
- return controller == null ? void 0 : controller.undo();
351
- if (isHotkey__default["default"]("escape")(e))
352
- return controller == null ? void 0 : controller.blur();
353
- reactPage.onKeyDown(e, editor);
354
- }, [controller, editor]);
355
- const handleBlur = React.useCallback((e) => {
356
- if (e.relatedTarget == null)
357
- return;
358
- setIsPreservingDOMSelection(false);
359
- slateReact.ReactEditor.deselect(editor);
360
- }, []);
361
- return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
362
- editor,
363
- value: initialValue,
364
- onChange: delaySync,
365
- children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
366
- id,
367
- renderLeaf: Leaf,
368
- renderElement: Element,
369
- onFocus: handleFocus,
370
- onKeyDown: handleKeyDown,
371
- onBlur: handleBlur,
372
- className: css.cx(width, margin),
373
- readOnly: editMode !== reactPage.BuilderEditMode.CONTENT,
374
- placeholder: "Write some text..."
375
- })
376
- });
377
- });
378
- var EditableText$1 = EditableText;
379
- exports.EditableText = EditableText;
380
- exports["default"] = EditableText$1;
17
+ editor.currentKey = key;
18
+ };
19
+ return editor;
20
+ }
21
+ exports.withLocalChanges = withLocalChanges;
381
22
  //# sourceMappingURL=index.cjs7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs7.js","sources":["../src/runtimes/react/controls/rich-text/components/Element/block.tsx","../src/runtimes/react/controls/rich-text/components/Element/inline.tsx","../src/runtimes/react/controls/rich-text/components/Element/element.tsx","../src/runtimes/react/controls/rich-text/components/Leaf/leaf.tsx","../src/runtimes/react/controls/rich-text/EditableText/useSyncDOMSelection.tsx","../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx","../src/runtimes/react/controls/rich-text/EditableText/editable-text.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { useResponsiveStyle } from '../../../../../../components/utils/responsive-style'\nimport { Block, BlockType } from '../../../../../../slate'\nimport { useStyle } from '../../../../use-style'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n const quoteStyles = useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n })\n\n switch (element.type) {\n case BlockType.Default:\n case BlockType.Paragraph:\n return (\n <p {...attributes} className={cx(...blockStyles)}>\n {children}\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote {...attributes} className={cx(...blockStyles, quoteStyles)}>\n {children}\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li {...attributes} className={cx(...blockStyles)}>\n {children}\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { Inline, InlineType } from '../../../../../../slate/types'\nimport { useStyle } from '../../../../use-style'\nimport { Link } from '../../../../../../components/shared/Link'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Inline\n}\n\nexport function InlineElement({ element, attributes, children }: InlineRenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n case InlineType.Link:\n return (\n <StyledLink {...attributes} link={element.link ?? undefined}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\nimport { BlockType, InlineType } from '../../../../../../slate/types'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Default:\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { RenderLeafProps } from 'slate-react'\nimport useEnhancedTypography, { useTypographyClassName } from '../../../typography'\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n // for each breakpoint fetch related resources and merge its value with its override\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n\n // for each breakpoint shallow merge back up through the breakpoints and create a className\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n","import { ReactEditor } from 'slate-react'\nimport { Editor, Range as SlateRange } from 'slate'\nimport { useIsomorphicLayoutEffect } from '../../../../../components/hooks/useIsomorphicLayoutEffect'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { useIsInBuilder } from '../../../../../react'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../../controls'\nimport { RichTextValue } from '../../../../../prop-controllers'\nimport deepEqual from '../../../../../utils/deepEqual'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, 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 return useCallback(() => setShouldCommit(false), [])\n}\n","import { cx } from '@emotion/css'\nimport { getBox } from 'css-box-model'\nimport isHotkey from 'is-hotkey'\nimport {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\nimport { useBuilderEditMode } from '../../..'\nimport { richTextDTOtoDAO } from '../../../../../controls'\nimport { RichTextValue } from '../../../../../prop-controllers'\nimport { ElementIDValue } from '../../../../../prop-controllers/descriptors'\nimport { DescriptorsPropControllers } from '../../../../../prop-controllers/instances'\nimport {\n RichTextDAO,\n BlockType,\n withBlock,\n withTypography,\n withBuilder,\n onKeyDown,\n} from '../../../../../slate'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { PropControllersHandle } from '../../../../../state/modules/prop-controller-handles'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { Element, Leaf } from '../components'\nimport { Descriptors } from '../rich-text'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { useSyncWithBuilder } from './useSyncWithBuilder'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: RichTextDAO = [{ type: BlockType.Paragraph, children: [{ text: '' }] }]\n\nexport const EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<PropControllersHandle<Descriptors>>,\n) {\n const [editor] = useState(() => withBlock(withTypography(withBuilder(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","quoteStyles","padding","fontSize","fontWeight","borderLeft","type","BlockType","Default","Paragraph","cx","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","Link","textDecoration","InlineType","Code","SuperScript","SubScript","link","undefined","props","leaf","enhancedTypography","useEnhancedTypography","typography","typographyClassName","useTypographyClassName","editor","isEnabled","useIsomorphicLayoutEffect","selection","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","COMMIT_DEBOUNCE_DELAY","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withBuilder","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Slate","Editable","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,gCAA4B,KAAD;AAC3BlD,2BAAYiF,SAASrF,MAArB;AAAA,EAL4B,GAM3B,CAN2B,CAAA;AAQ9B,wCACGsF,WAAAA,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOd;AAAAA,IAAc,UAAUhB;AAAAA,IAAtD,yCACG+B,qBAAD;AAAA,MACE;AAAA,MACA,YAAYC;AAAAA,MACZ,eAAeC;AAAAA,MACf,SAASd;AAAAA,MACT,WAAWE;AAAAA,MACX,QAAQM;AAAAA,MACR,WAAWjH,IAAAA,GAAG4E,OAAOxF,MAAR;AAAA,MACb,UAAUoG,aAAagC,UAAAA,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD,CAnFqC;AAqFtC,IAAA,iBAAehD;;;"}
1
+ {"version":3,"file":"index.cjs7.js","sources":["../src/slate/LocalChangesPlugin/index.tsx"],"sourcesContent":["import { BaseEditor, Editor, Selection } from 'slate'\nimport { v4 as uuid } from 'uuid'\n\nexport type LocalChange = { selection: Selection; time: number }\n\nexport interface LocalChangesEditor extends BaseEditor {\n localChanges: Map<string, LocalChange>\n recentKeys: Map<string, number>\n recentLocalChanges: { time: number; key: string }[]\n currentKey: string\n}\n\nexport function withLocalChanges(editor: Editor): Editor {\n editor.localChanges = new Map<string, LocalChange>()\n editor.recentLocalChanges = []\n editor.currentKey = ''\n\n const _onChange = editor.onChange\n editor.onChange = options => {\n _onChange(options)\n if (editor == null || options?.operation == null) return\n\n const key = uuid()\n editor.localChanges.set(key, { selection: editor.selection, time: performance.now() })\n editor.currentKey = key\n }\n\n return editor\n}\n"],"names":["editor","localChanges","Map","recentLocalChanges","currentKey","_onChange","onChange","options","operation","key","uuid","set","selection","time","performance","now"],"mappings":";;AAYO,0BAA0BA,QAAwB;AAChDC,SAAAA,mCAAmBC;AAC1BF,SAAOG,qBAAqB;AAC5BH,SAAOI,aAAa;AAEpB,QAAMC,YAAYL,OAAOM;AACzBN,SAAOM,WAAWC,CAAW,YAAA;AAC3BF,cAAUE,OAAD;AACLP,QAAAA,UAAU,QAAQO,oCAASC,cAAa;AAAM;AAE5CC,UAAAA,MAAMC,KAAAA;AACLT,WAAAA,aAAaU,IAAIF,KAAK;AAAA,MAAEG,WAAWZ,OAAOY;AAAAA,MAAWC,MAAMC,YAAYC,IAAZ;AAAA,IAAA,CAAlE;AACAf,WAAOI,aAAaK;AAAAA,EAAAA;AAGfT,SAAAA;AACR;;"}