@makeswift/runtime 0.9.10 → 0.9.12

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 (209) hide show
  1. package/dist/Box.cjs.js +1 -1
  2. package/dist/Box.es.js +1 -1
  3. package/dist/Button.cjs.js +1 -1
  4. package/dist/Button.es.js +1 -1
  5. package/dist/Carousel.cjs.js +1 -1
  6. package/dist/Carousel.es.js +1 -1
  7. package/dist/Countdown.cjs.js +1 -1
  8. package/dist/Countdown.es.js +1 -1
  9. package/dist/Divider.cjs.js +1 -1
  10. package/dist/Divider.es.js +1 -1
  11. package/dist/Form.cjs.js +1 -1
  12. package/dist/Form.es.js +1 -1
  13. package/dist/Image.cjs.js +1 -1
  14. package/dist/Image.es.js +1 -1
  15. package/dist/LiveProvider.cjs.js +1 -1
  16. package/dist/LiveProvider.es.js +3 -3
  17. package/dist/Navigation.cjs.js +1 -1
  18. package/dist/Navigation.es.js +1 -1
  19. package/dist/PreviewProvider.cjs.js +1 -1
  20. package/dist/PreviewProvider.es.js +3 -3
  21. package/dist/ReadOnlyText.cjs.js +18 -3
  22. package/dist/ReadOnlyText.cjs.js.map +1 -1
  23. package/dist/ReadOnlyText.es.js +20 -5
  24. package/dist/ReadOnlyText.es.js.map +1 -1
  25. package/dist/ReadOnlyTextV2.cjs.js +116 -240
  26. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  27. package/dist/ReadOnlyTextV2.es.js +115 -238
  28. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  29. package/dist/Root.cjs.js +1 -1
  30. package/dist/Root.es.js +1 -1
  31. package/dist/SocialLinks.cjs.js +1 -1
  32. package/dist/SocialLinks.es.js +1 -1
  33. package/dist/Text.cjs.js +1 -1
  34. package/dist/Text.es.js +1 -1
  35. package/dist/components.cjs.js +1 -1
  36. package/dist/components.es.js +1 -1
  37. package/dist/control-serialization.es.js +1 -1
  38. package/dist/controls.cjs.js +28 -18
  39. package/dist/controls.cjs.js.map +1 -1
  40. package/dist/controls.es.js +2 -2
  41. package/dist/index.cjs.js +47 -42
  42. package/dist/index.cjs.js.map +1 -1
  43. package/dist/index.cjs10.js +2 -2
  44. package/dist/index.cjs2.js +3 -3
  45. package/dist/index.cjs2.js.map +1 -1
  46. package/dist/index.cjs5.js +5 -6
  47. package/dist/index.cjs5.js.map +1 -1
  48. package/dist/index.cjs6.js +20 -0
  49. package/dist/index.cjs6.js.map +1 -1
  50. package/dist/index.cjs8.js +1 -1
  51. package/dist/index.cjs9.js +27 -31
  52. package/dist/index.cjs9.js.map +1 -1
  53. package/dist/index.es.js +22 -18
  54. package/dist/index.es.js.map +1 -1
  55. package/dist/index.es10.js +4 -4
  56. package/dist/index.es2.js +2 -2
  57. package/dist/index.es3.js +1 -1
  58. package/dist/index.es5.js +1 -2
  59. package/dist/index.es5.js.map +1 -1
  60. package/dist/index.es6.js +21 -2
  61. package/dist/index.es6.js.map +1 -1
  62. package/dist/index.es8.js +1 -1
  63. package/dist/index.es9.js +31 -35
  64. package/dist/index.es9.js.map +1 -1
  65. package/dist/next.cjs.js +1 -1
  66. package/dist/next.es.js +2 -2
  67. package/dist/react-page.cjs.js +310 -147
  68. package/dist/react-page.cjs.js.map +1 -1
  69. package/dist/react-page.es.js +297 -146
  70. package/dist/react-page.es.js.map +1 -1
  71. package/dist/react.cjs.js +1 -1
  72. package/dist/react.es.js +1 -1
  73. package/dist/slate.cjs.js +40 -27
  74. package/dist/slate.cjs.js.map +1 -1
  75. package/dist/slate.es.js +49 -37
  76. package/dist/slate.es.js.map +1 -1
  77. package/dist/{typography.cjs.js → text-input.cjs.js} +1 -9
  78. package/dist/text-input.cjs.js.map +1 -0
  79. package/dist/{typography.es.js → text-input.es.js} +2 -8
  80. package/dist/text-input.es.js.map +1 -0
  81. package/dist/types/src/api/react.d.ts +1 -1
  82. package/dist/types/src/api/react.d.ts.map +1 -1
  83. package/dist/types/src/components/builtin/Button/Button.d.ts +3 -39
  84. package/dist/types/src/components/builtin/Button/Button.d.ts.map +1 -1
  85. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +2 -2
  86. package/dist/types/src/components/builtin/Form/components/Field/components/Input/index.d.ts +1 -1
  87. package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts +0 -1
  88. package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts.map +1 -1
  89. package/dist/types/src/components/builtin/Form/components/Field/components/RadioButton/index.d.ts +2 -2
  90. package/dist/types/src/components/builtin/Form/components/Field/components/TextArea/index.d.ts +1 -1
  91. package/dist/types/src/components/builtin/Form/components/Field/index.d.ts +0 -1
  92. package/dist/types/src/components/builtin/Form/components/Field/index.d.ts.map +1 -1
  93. package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts +0 -1
  94. package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts.map +1 -1
  95. package/dist/types/src/components/builtin/Navigation/components/DropDownButton/index.d.ts +1 -1
  96. package/dist/types/src/components/builtin/Navigation/components/DropDownButton/index.d.ts.map +1 -1
  97. package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts +0 -1
  98. package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts.map +1 -1
  99. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/components/MobileDropDownButton/index.d.ts +1 -1
  100. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/components/MobileDropDownButton/index.d.ts.map +1 -1
  101. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts +0 -1
  102. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts.map +1 -1
  103. package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts +0 -1
  104. package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts.map +1 -1
  105. package/dist/types/src/components/builtin/SocialLinks/options.d.ts +23 -24
  106. package/dist/types/src/components/builtin/SocialLinks/options.d.ts.map +1 -1
  107. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +2 -2
  108. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  109. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts +1 -2
  110. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -1
  111. package/dist/types/src/components/builtin/Text/components/Element/element.d.ts +1 -2
  112. package/dist/types/src/components/builtin/Text/components/Element/element.d.ts.map +1 -1
  113. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts +1 -2
  114. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts.map +1 -1
  115. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +1 -2
  116. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  117. package/dist/types/src/components/page/Page.d.ts +0 -1
  118. package/dist/types/src/components/page/Page.d.ts.map +1 -1
  119. package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts +0 -1
  120. package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
  121. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts +0 -1
  122. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
  123. package/dist/types/src/components/shared/BackgroundsContainer/index.d.ts +1 -1
  124. package/dist/types/src/components/shared/GutterContainer/index.d.ts +1 -1
  125. package/dist/types/src/components/shared/GutterContainer/index.d.ts.map +1 -1
  126. package/dist/types/src/components/shared/Link/index.d.ts +1 -1
  127. package/dist/types/src/components/shared/Link/index.d.ts.map +1 -1
  128. package/dist/types/src/components/shared/grid-item.d.ts +1 -1
  129. package/dist/types/src/components/shared/grid-item.d.ts.map +1 -1
  130. package/dist/types/src/controls/list.d.ts +5 -2
  131. package/dist/types/src/controls/list.d.ts.map +1 -1
  132. package/dist/types/src/controls/rich-text/introspection.d.ts +5 -0
  133. package/dist/types/src/controls/rich-text/introspection.d.ts.map +1 -0
  134. package/dist/types/src/controls/rich-text/introspection.test.d.ts +2 -0
  135. package/dist/types/src/controls/rich-text/introspection.test.d.ts.map +1 -0
  136. package/dist/types/src/controls/rich-text-v2/introspection.d.ts +5 -0
  137. package/dist/types/src/controls/rich-text-v2/introspection.d.ts.map +1 -0
  138. package/dist/types/src/controls/rich-text-v2/introspection.test.d.ts +2 -0
  139. package/dist/types/src/controls/rich-text-v2/introspection.test.d.ts.map +1 -0
  140. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +15 -3
  141. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  142. package/dist/types/src/controls/rich-text-v2/translation.d.ts +1 -1
  143. package/dist/types/src/controls/rich-text-v2/translation.d.ts.map +1 -1
  144. package/dist/types/src/controls/shape.d.ts +5 -2
  145. package/dist/types/src/controls/shape.d.ts.map +1 -1
  146. package/dist/types/src/controls/typography.d.ts +2 -0
  147. package/dist/types/src/controls/typography.d.ts.map +1 -1
  148. package/dist/types/src/next/client.d.ts.map +1 -1
  149. package/dist/types/src/next/document.d.ts +1 -2
  150. package/dist/types/src/next/document.d.ts.map +1 -1
  151. package/dist/types/src/next/index.d.ts +1 -1
  152. package/dist/types/src/next/index.d.ts.map +1 -1
  153. package/dist/types/src/next/preview-mode.d.ts +1 -2
  154. package/dist/types/src/next/preview-mode.d.ts.map +1 -1
  155. package/dist/types/src/prop-controllers/descriptors.d.ts +10 -0
  156. package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
  157. package/dist/types/src/prop-controllers/introspection.d.ts +0 -2
  158. package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
  159. package/dist/types/src/runtimes/react/components/render-hook.d.ts +0 -1
  160. package/dist/types/src/runtimes/react/components/render-hook.d.ts.map +1 -1
  161. package/dist/types/src/runtimes/react/controls/control.d.ts +0 -1
  162. package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
  163. package/dist/types/src/runtimes/react/controls/list.d.ts +0 -1
  164. package/dist/types/src/runtimes/react/controls/list.d.ts.map +1 -1
  165. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts +1 -1
  166. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  167. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.d.ts +1 -2
  168. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.d.ts.map +1 -1
  169. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.d.ts +1 -2
  170. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.d.ts.map +1 -1
  171. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useRemoteChanges.d.ts +4 -0
  172. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useRemoteChanges.d.ts.map +1 -0
  173. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +7 -16
  174. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  175. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +1 -1
  176. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  177. package/dist/types/src/runtimes/react/controls/rich-text.d.ts +1 -1
  178. package/dist/types/src/runtimes/react/controls/rich-text.d.ts.map +1 -1
  179. package/dist/types/src/runtimes/react/controls/shape.d.ts +0 -1
  180. package/dist/types/src/runtimes/react/controls/shape.d.ts.map +1 -1
  181. package/dist/types/src/runtimes/react/controls/slot.d.ts +2 -2
  182. package/dist/types/src/runtimes/react/controls/slot.d.ts.map +1 -1
  183. package/dist/types/src/runtimes/react/controls/style-v2.d.ts +0 -1
  184. package/dist/types/src/runtimes/react/controls/style-v2.d.ts.map +1 -1
  185. package/dist/types/src/runtimes/react/controls.d.ts +0 -1
  186. package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
  187. package/dist/types/src/runtimes/react/find-dom-node.d.ts.map +1 -1
  188. package/dist/types/src/runtimes/react/index.d.ts +1 -1
  189. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  190. package/dist/types/src/slate/LinkPlugin/index.d.ts.map +1 -1
  191. package/dist/types/src/slate/LocalChangesPlugin/index.d.ts +16 -0
  192. package/dist/types/src/slate/LocalChangesPlugin/index.d.ts.map +1 -0
  193. package/dist/types/src/slate/TextAlignPlugin/index.d.ts +3 -3
  194. package/dist/types/src/slate/TextAlignPlugin/index.d.ts.map +1 -1
  195. package/dist/types/src/slate/index.d.ts +1 -0
  196. package/dist/types/src/slate/index.d.ts.map +1 -1
  197. package/dist/types/src/slate/types.d.ts +2 -2
  198. package/dist/types/src/slate/types.d.ts.map +1 -1
  199. package/dist/types/src/slate/utils/responsive.d.ts +1 -1
  200. package/dist/types/src/slate/utils/responsive.d.ts.map +1 -1
  201. package/dist/types/src/state/modules/react-components.d.ts +2 -2
  202. package/dist/types/src/state/modules/react-components.d.ts.map +1 -1
  203. package/dist/types.cjs2.js +67 -48
  204. package/dist/types.cjs2.js.map +1 -1
  205. package/dist/types.es2.js +64 -45
  206. package/dist/types.es2.js.map +1 -1
  207. package/package.json +4 -5
  208. package/dist/typography.cjs.js.map +0 -1
  209. package/dist/typography.es.js.map +0 -1
@@ -34,7 +34,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
34
34
  var React = require("react");
35
35
  var slate = require("slate");
36
36
  var isHotkey = require("is-hotkey");
37
- var slateHistory = require("slate-history");
38
37
  var slateReact = require("slate-react");
39
38
  var reactPage = require("./react-page.cjs.js");
40
39
  var next = require("./index.cjs.js");
@@ -44,7 +43,7 @@ var index = require("./index.cjs6.js");
44
43
  var index$1 = require("./index.cjs7.js");
45
44
  var jsxRuntime = require("react/jsx-runtime");
46
45
  require("./index.cjs3.js");
47
- var css = require("@emotion/css");
46
+ require("@emotion/css");
48
47
  var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
49
48
  require("./actions.cjs.js");
50
49
  require("redux");
@@ -53,7 +52,7 @@ require("@emotion/serialize");
53
52
  require("@emotion/utils");
54
53
  require("use-sync-external-store/shim/with-selector");
55
54
  require("next/dynamic");
56
- require("./typography.cjs.js");
55
+ require("./text-input.cjs.js");
57
56
  require("./combobox.cjs.js");
58
57
  require("use-sync-external-store/shim");
59
58
  require("./types.cjs.js");
@@ -110,24 +109,8 @@ function RichTextV2Element(_a) {
110
109
  "definition",
111
110
  "plugins"
112
111
  ]);
113
- const blockStyles = [reactPage.useStyle({
114
- margin: 0
115
- })];
116
112
  function initialRenderElement(props2) {
117
- switch (props2.element.type) {
118
- case reactPage.BlockType.Default:
119
- default:
120
- if (definition.config.mode === reactPage.RichTextV2Mode.Inline) {
121
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props2.attributes), {
122
- className: css.cx(...blockStyles),
123
- children: props2.children
124
- }));
125
- }
126
- return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, props2.attributes), {
127
- className: css.cx(...blockStyles),
128
- children: props2.children
129
- }));
130
- }
113
+ return props2.children;
131
114
  }
132
115
  const renderElement = plugins.reduce((renderFn, plugin) => (props2) => {
133
116
  const {
@@ -182,6 +165,21 @@ function RichTextV2Leaf(_c) {
182
165
  }, initialRenderLeaf);
183
166
  return renderLeaf(props);
184
167
  }
168
+ function isChangeWithinPreviousSec(change) {
169
+ var _a;
170
+ return performance.now() - ((_a = change == null ? void 0 : change.time) != null ? _a : 0) < 1e3;
171
+ }
172
+ function useSyncRemoteChanges(editor, data) {
173
+ const isInBuilder = next.useIsInBuilder();
174
+ React.useEffect(() => {
175
+ var _a, _b, _c;
176
+ if (!isChangeWithinPreviousSec(editor.localChanges.get((_a = data == null ? void 0 : data.key) != null ? _a : "")) && data && isInBuilder) {
177
+ editor.children = reactPage.richTextV2DataToDescendents(data);
178
+ editor.selection = (_c = (_b = editor == null ? void 0 : editor.localChanges.get(data.key)) == null ? void 0 : _b.selection) != null ? _c : null;
179
+ editor.onChange();
180
+ }
181
+ }, [editor, data]);
182
+ }
185
183
  const defaultText = [{
186
184
  type: reactPage.BlockType.Default,
187
185
  children: [{
@@ -201,10 +199,11 @@ function EditableTextV2({
201
199
  const [editor] = React.useState(() => plugins.reduceRight((editor2, plugin) => {
202
200
  var _a, _b;
203
201
  return (_b = (_a = plugin == null ? void 0 : plugin.withPlugin) == null ? void 0 : _a.call(plugin, editor2)) != null ? _b : editor2;
204
- }, index$1.withBuilder(slateHistory.withHistory(slateReact.withReact(slate.createEditor())))));
202
+ }, index.withLocalChanges(index$1.withBuilder(slateReact.withReact(slate.createEditor())))));
205
203
  const isPreservingFocus = React.useRef(false);
206
204
  useSyncDOMSelection(editor, isPreservingFocus);
207
205
  const editMode = next.useBuilderEditMode();
206
+ useSyncRemoteChanges(editor, text);
208
207
  React.useEffect(() => {
209
208
  if (control == null)
210
209
  return;
@@ -245,23 +244,24 @@ function EditableTextV2({
245
244
  control == null ? void 0 : control.select();
246
245
  }, [control]);
247
246
  const handleKeyDown = React.useCallback((e) => {
248
- if (isHotkey__default["default"]("mod+shift+z", e))
249
- return slateHistory.HistoryEditor.redo(editor);
250
- if (isHotkey__default["default"]("mod+z", e))
251
- return slateHistory.HistoryEditor.undo(editor);
252
247
  if (isHotkey__default["default"]("escape")(e)) {
253
248
  isPreservingFocus.current = false;
254
249
  slateReact.ReactEditor.blur(editor);
255
250
  control == null ? void 0 : control.switchToBuildMode();
256
251
  }
252
+ if (editMode === reactPage.BuilderEditMode.CONTENT) {
253
+ e.stopPropagation();
254
+ }
257
255
  plugins.forEach((plugin) => {
258
256
  var _a;
259
257
  return (_a = plugin == null ? void 0 : plugin.onKeyDown) == null ? void 0 : _a.call(plugin, e, editor);
260
258
  });
261
- }, [control, plugins, editor]);
259
+ }, [control, plugins, editor, editMode]);
262
260
  const handleKeyUp = React.useCallback((e) => {
263
- if (editMode === reactPage.BuilderEditMode.CONTENT)
261
+ if (editMode === reactPage.BuilderEditMode.CONTENT) {
262
+ e.stopPropagation();
264
263
  e.preventDefault();
264
+ }
265
265
  }, [control, editor, editMode]);
266
266
  const handleClick = React.useCallback((e) => {
267
267
  if (editMode === reactPage.BuilderEditMode.CONTENT)
@@ -274,12 +274,8 @@ function EditableTextV2({
274
274
  if (((_a = e.relatedTarget) == null ? void 0 : _a.getAttribute("contenteditable")) === "true")
275
275
  isPreservingFocus.current = false;
276
276
  }, []);
277
- const handleOnChange = React.useCallback((value) => {
278
- control == null ? void 0 : control.onChange(value);
279
- }, [control]);
280
277
  return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
281
278
  editor,
282
- onChange: handleOnChange,
283
279
  value: initialValue,
284
280
  children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
285
281
  renderLeaf,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs9.js","sources":["../src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["import { Editor, Range as SlateRange } from 'slate'\nimport { useIsomorphicLayoutEffect } from '../../../../../components/hooks/useIsomorphicLayoutEffect'\nimport { MutableRefObject } from 'react'\nimport { ReactEditor } from 'slate-react'\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: MutableRefObject<boolean>) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled.current || 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 { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport {\n RichTextV2ControlDefinition,\n RichTextV2Plugin,\n RichTextV2Mode,\n} from '../../../../../controls'\nimport { BlockType } from '../../../../../slate'\nimport { useStyle } from '../../../use-style'\nimport { ControlValue } from '../../control'\n\ntype RichTextV2ElementProps = RenderElementProps & {\n definition: RichTextV2ControlDefinition\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Element({ definition, plugins, ...props }: RichTextV2ElementProps) {\n const blockStyles = [useStyle({ margin: 0 })]\n\n function initialRenderElement(props: RenderElementProps) {\n switch (props.element.type) {\n case BlockType.Default:\n default:\n if (definition.config.mode === RichTextV2Mode.Inline) {\n return (\n <span {...props.attributes} className={cx(...blockStyles)}>\n {props.children}\n </span>\n )\n }\n\n return (\n <p {...props.attributes} className={cx(...blockStyles)}>\n {props.children}\n </p>\n )\n }\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) => (props: RenderElementProps) => {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getElementValue(props.element)}>\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement(props)\n}\n","import { RenderLeafProps } from 'slate-react'\nimport { RichTextV2ControlDefinition, RichTextV2Plugin } from '../../../../../controls'\nimport { ControlValue } from '../../control'\n\ntype RichTextV2LeafProps = RenderLeafProps & {\n definition: RichTextV2ControlDefinition\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Leaf({ definition, plugins, ...props }: RichTextV2LeafProps) {\n function initialRenderLeaf({ attributes, children, leaf }: RenderLeafProps) {\n return (\n <span className={leaf.className} {...attributes}>\n {children}\n </span>\n )\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) => (props: RenderLeafProps) => {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf(props)\n}\n","import {\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { Descendant, createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport { withHistory, HistoryEditor } from 'slate-history'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport {\n RichTextV2Control,\n RichTextV2ControlData,\n RichTextV2ControlDefinition,\n RichTextV2Mode,\n} from '../../../../../controls'\nimport { useBuilderEditMode } from '../../..'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { InlineModePlugin, withBuilder } from '../../../../../slate'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { BlockType } from '../../../../../slate'\nimport { RichTextV2Element } from './render-element'\nimport { RichTextV2Leaf } from './render-leaf'\nimport { richTextV2DataToDescendents } from '../../../../../controls/rich-text-v2/translation'\n\nexport type RichTextV2ControlValue = ReactNode\n\nexport type Descriptors = { text?: RichTextV2ControlDefinition }\n\nconst defaultText: Descendant[] = [{ type: BlockType.Default, children: [{ text: '' }] }]\n\ntype Props = {\n text?: RichTextV2ControlData\n definition: RichTextV2ControlDefinition\n control: RichTextV2Control | null\n}\n\nexport function EditableTextV2({ text, definition, control }: Props) {\n const plugins = useMemo(() => {\n const plugins = [\n ...(definition?.config?.plugins ?? []),\n ...(definition?.config?.mode === RichTextV2Mode.Inline ? [InlineModePlugin] : []),\n ]\n return plugins\n }, [definition])\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withBuilder(withHistory(withReact(createEditor()))),\n ),\n )\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return <RichTextV2Element {...props} definition={definition} plugins={plugins} />\n },\n [plugins, definition],\n )\n\n const renderLeaf = useCallback(\n (props: RenderLeafProps) => {\n return <RichTextV2Leaf {...props} definition={definition} plugins={plugins} />\n },\n [plugins, definition],\n )\n\n const initialValue = useMemo(\n () => (text && richTextV2DataToDescendents(text)) ?? defaultText,\n [text],\n )\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode])\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultText)\n }, [control, editor, defaultText])\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return HistoryEditor.redo(editor)\n if (isHotkey('mod+z', e)) return HistoryEditor.undo(editor)\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e, editor))\n },\n [control, plugins, editor],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) e.preventDefault()\n },\n [control, editor, editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) e.stopPropagation()\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n const handleOnChange = useCallback(\n (value: Descendant[]) => {\n control?.onChange(value)\n },\n [control],\n )\n\n return (\n <Slate editor={editor} onChange={handleOnChange} value={initialValue}>\n <Editable\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n\nexport default EditableTextV2\n"],"names":["editor","isEnabled","useIsomorphicLayoutEffect","current","selection","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","definition","plugins","props","blockStyles","useStyle","margin","element","type","BlockType","Default","config","mode","RichTextV2Mode","Inline","attributes","cx","children","renderElement","reduce","renderFn","plugin","control","getElementValue","undefined","ControlValue","value","initialRenderElement","leaf","className","renderLeaf","getLeafValue","initialRenderLeaf","defaultText","text","useMemo","InlineModePlugin","useState","reduceRight","withPlugin","withBuilder","withHistory","withReact","createEditor","isPreservingFocus","useRef","useSyncDOMSelection","editMode","useBuilderEditMode","useEffect","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useCallback","initialValue","richTextV2DataToDescendents","BuilderEditMode","CONTENT","deselect","setEditor","setDefaultValue","handleFocus","select","handleKeyDown","isHotkey","HistoryEditor","redo","undo","blur","switchToBuildMode","forEach","onKeyDown","handleKeyUp","preventDefault","handleClick","stopPropagation","handleBlur","relatedTarget","getAttribute","handleOnChange","onChange","Slate","Editable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,6BAA6BA,QAAgBC,WAAsC;AACxFC,4BAAAA,0BAA0B,MAAM;AAC1B,QAAA,CAACD,UAAUE,WAAWH,OAAOI,aAAa,QAAQC,WAAAA,YAAYC,UAAUN,MAAtB;AAA+B;AACjF,QAAA;AACIO,YAAAA,OAAOF,WAAAA,YAAYG,yBAAyBR,MAArC;AACPS,YAAAA,eAAeF,KAAKG;AAC1B,YAAMC,cAA4BN,WAAAA,YAAYO,WAAWZ,QAAQA,OAAOI,SAAtC;AAElC,UAAIO,aAAa;AACXE,YAAAA,YAAWC,WAAWd,OAAOI,SAA7B,GAA0C;AAC9BW,uDAAAA,iBACZJ,YAAYK,cACZL,YAAYM,WACZN,YAAYO,gBACZP,YAAYQ;AAAAA,QAJd,OAMK;AACSJ,uDAAAA,iBACZJ,YAAYO,gBACZP,YAAYQ,aACZR,YAAYK,cACZL,YAAYM;AAAAA,QAEf;AAAA,MAAA,OACI;AACLR,qDAAcW;AAAAA,MACf;AAAA,aACMC;AACPC,cAAQC,MAAMF,CAAd;AAAA,IACD;AAAA,EAAA,CA5BsB;AA8B1B;ACzBiC,2BAAA,IAA2D;AAA3D,eAAEG;AAAAA;AAAAA,IAAYC;AAAAA,MA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AAAM;AAE7B,QAAIjF,SAAEiF,kBAAFjF,mBAAiBkF,aAAa,wBAAuB;AACvDpC,wBAAkBhE,UAAU;AAAA,EALF,GAM3B,CAN2B,CAAA;AAQxBqG,QAAAA,iBAAiB1B,kBACrB,CAAC7B,UAAwB;AACvBJ,uCAAS4D,SAASxD;AAAAA,EAAlB,GAEF,CAACJ,OAAD,CAJgC;AAOlC,wCACG6D,WAAAA,OAAD;AAAA,IAAO;AAAA,IAAgB,UAAUF;AAAAA,IAAgB,OAAOzB;AAAAA,IAAxD,yCACG4B,qBAAD;AAAA,MACE;AAAA,MACA;AAAA,MACA,SAASrB;AAAAA,MACT,WAAWE;AAAAA,MACX,SAASS;AAAAA,MACT,SAASE;AAAAA,MACT,QAAQE;AAAAA,MACR,UAAU/B,aAAaW,UAAAA,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD;;;"}
1
+ {"version":3,"file":"index.cjs9.js","sources":["../src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/useRemoteChanges.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["import { Editor, Range as SlateRange } from 'slate'\nimport { useIsomorphicLayoutEffect } from '../../../../../components/hooks/useIsomorphicLayoutEffect'\nimport { MutableRefObject } from 'react'\nimport { ReactEditor } from 'slate-react'\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: MutableRefObject<boolean>) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled.current || 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 { RenderElementProps } from 'slate-react'\nimport { RichTextV2ControlDefinition, RichTextV2Plugin } from '../../../../../controls'\nimport { ControlValue } from '../../control'\n\ntype RichTextV2ElementProps = RenderElementProps & {\n definition: RichTextV2ControlDefinition\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Element({ definition, plugins, ...props }: RichTextV2ElementProps) {\n function initialRenderElement(props: RenderElementProps) {\n return props.children\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) => (props: RenderElementProps) => {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getElementValue(props.element)}>\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement(props)\n}\n","import { RenderLeafProps } from 'slate-react'\nimport { RichTextV2ControlDefinition, RichTextV2Plugin } from '../../../../../controls'\nimport { ControlValue } from '../../control'\n\ntype RichTextV2LeafProps = RenderLeafProps & {\n definition: RichTextV2ControlDefinition\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Leaf({ definition, plugins, ...props }: RichTextV2LeafProps) {\n function initialRenderLeaf({ attributes, children, leaf }: RenderLeafProps) {\n return (\n <span className={leaf.className} {...attributes}>\n {children}\n </span>\n )\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) => (props: RenderLeafProps) => {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf(props)\n}\n","import { useEffect } from 'react'\nimport { Editor } from 'slate'\nimport { useIsInBuilder } from '../../../../../react'\nimport { RichTextV2ControlData, richTextV2DataToDescendents } from '../../../../../controls'\nimport { LocalChange } from '../../../../../slate'\n\n// From the component point of view we can't know if the change came from an action or a undo/redo\n// So we diff the time and force updates on actions that occured over a second ago.\nfunction isChangeWithinPreviousSec(change?: LocalChange) {\n return performance.now() - (change?.time ?? 0) < 1000\n}\n\nexport function useSyncRemoteChanges(editor: Editor, data?: RichTextV2ControlData) {\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (\n !isChangeWithinPreviousSec(editor.localChanges.get(data?.key ?? '')) &&\n data &&\n isInBuilder\n ) {\n editor.children = richTextV2DataToDescendents(data)\n editor.selection = editor?.localChanges.get(data.key)?.selection ?? null\n editor.onChange()\n }\n }, [editor, data])\n}\n","import {\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { Descendant, createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport {\n RichTextV2Control,\n RichTextV2ControlData,\n RichTextV2ControlDefinition,\n RichTextV2Mode,\n} from '../../../../../controls'\nimport { useBuilderEditMode } from '../../..'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { InlineModePlugin, withBuilder, withLocalChanges } from '../../../../../slate'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { BlockType } from '../../../../../slate'\nimport { RichTextV2Element } from './render-element'\nimport { RichTextV2Leaf } from './render-leaf'\nimport { richTextV2DataToDescendents } from '../../../../../controls/rich-text-v2/translation'\nimport { useSyncRemoteChanges } from './useRemoteChanges'\n\nexport type RichTextV2ControlValue = ReactNode\n\nexport type Descriptors = { text?: RichTextV2ControlDefinition }\n\nconst defaultText: Descendant[] = [{ type: BlockType.Default, children: [{ text: '' }] }]\n\ntype Props = {\n text?: RichTextV2ControlData\n definition: RichTextV2ControlDefinition\n control: RichTextV2Control | null\n}\n\nexport function EditableTextV2({ text, definition, control }: Props) {\n const plugins = useMemo(() => {\n const plugins = [\n ...(definition?.config?.plugins ?? []),\n ...(definition?.config?.mode === RichTextV2Mode.Inline ? [InlineModePlugin] : []),\n ]\n return plugins\n }, [definition])\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withLocalChanges(withBuilder(withReact(createEditor()))),\n ),\n )\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n\n const editMode = useBuilderEditMode()\n\n useSyncRemoteChanges(editor, text)\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return <RichTextV2Element {...props} definition={definition} plugins={plugins} />\n },\n [plugins, definition],\n )\n\n const renderLeaf = useCallback(\n (props: RenderLeafProps) => {\n return <RichTextV2Leaf {...props} definition={definition} plugins={plugins} />\n },\n [plugins, definition],\n )\n\n const initialValue = useMemo(\n () => (text && richTextV2DataToDescendents(text)) ?? defaultText,\n [text],\n )\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode])\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultText)\n }, [control, editor, defaultText])\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e, editor))\n },\n [control, plugins, editor, editMode],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [control, editor, editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) e.stopPropagation()\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue}>\n <Editable\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n\nexport default EditableTextV2\n"],"names":["editor","isEnabled","useIsomorphicLayoutEffect","current","selection","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","definition","plugins","props","children","renderElement","reduce","renderFn","plugin","control","getElementValue","undefined","ControlValue","element","value","initialRenderElement","attributes","leaf","className","renderLeaf","getLeafValue","initialRenderLeaf","change","performance","now","time","data","isInBuilder","useIsInBuilder","useEffect","isChangeWithinPreviousSec","localChanges","get","key","richTextV2DataToDescendents","onChange","defaultText","type","BlockType","Default","text","useMemo","config","mode","RichTextV2Mode","Inline","InlineModePlugin","useState","reduceRight","withPlugin","withLocalChanges","withBuilder","withReact","createEditor","isPreservingFocus","useRef","useSyncDOMSelection","editMode","useBuilderEditMode","useSyncRemoteChanges","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useCallback","initialValue","BuilderEditMode","CONTENT","deselect","setEditor","setDefaultValue","handleFocus","select","handleKeyDown","isHotkey","blur","switchToBuildMode","stopPropagation","forEach","onKeyDown","handleKeyUp","preventDefault","handleClick","handleBlur","relatedTarget","getAttribute","Slate","Editable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,6BAA6BA,QAAgBC,WAAsC;AACxFC,4BAAAA,0BAA0B,MAAM;AAC1B,QAAA,CAACD,UAAUE,WAAWH,OAAOI,aAAa,QAAQC,WAAAA,YAAYC,UAAUN,MAAtB;AAA+B;AACjF,QAAA;AACIO,YAAAA,OAAOF,WAAAA,YAAYG,yBAAyBR,MAArC;AACPS,YAAAA,eAAeF,KAAKG;AAC1B,YAAMC,cAA4BN,WAAAA,YAAYO,WAAWZ,QAAQA,OAAOI,SAAtC;AAElC,UAAIO,aAAa;AACXE,YAAAA,YAAWC,WAAWd,OAAOI,SAA7B,GAA0C;AAC9BW,uDAAAA,iBACZJ,YAAYK,cACZL,YAAYM,WACZN,YAAYO,gBACZP,YAAYQ;AAAAA,QAJd,OAMK;AACSJ,uDAAAA,iBACZJ,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UzB0B,QAAAA,cAAclB,kBAClB,CAACnE,MAAkB;AACb2D,QAAAA,aAAaU,UAAAA,gBAAgBC;AAAStE,QAAEgF,gBAAF;AAAA,EAAA,GAE5C,CAACrB,QAAD,CAJ6B;AAOzB2B,QAAAA,aAAanB,kBAAY,CAACnE,MAAkB;;AAEhD,QAAIA,EAAEuF,iBAAiB;AAAM;AAE7B,QAAIvF,SAAEuF,kBAAFvF,mBAAiBwF,aAAa,wBAAuB;AACvDhC,wBAAkB1E,UAAU;AAAA,EALF,GAM3B,CAN2B,CAAA;AAQ9B,wCACG2G,WAAAA,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOrB;AAAAA,IAA9B,yCACGsB,qBAAD;AAAA,MACE;AAAA,MACA;AAAA,MACA,SAAShB;AAAAA,MACT,WAAWE;AAAAA,MACX,SAASO;AAAAA,MACT,SAASE;AAAAA,MACT,QAAQC;AAAAA,MACR,UAAU3B,aAAaU,UAAAA,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD;;;"}
package/dist/index.es.js CHANGED
@@ -38,10 +38,10 @@ import * as React from "react";
38
38
  import { useEffect, createContext, useContext, useState, useMemo, useRef, Children, createElement, forwardRef, memo, useId, useCallback, useImperativeHandle, Component, Suspense } from "react";
39
39
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
40
40
  import dynamic from "next/dynamic";
41
- import { a as createDocumentReference, g as getPropControllerDescriptors, b as isElementReference, e as getSwatchIds, f as getFileIds, h as getTypographyIds, j as getTableIds, k as getPageIds, l as getElementChildren, E as ElementID, B as Backgrounds, W as Width, m as ResponsiveIconRadioGroup, M as Margin, P as Padding, n as Border, o as BorderRadius, S as Shadows, G as GapY, p as GapX, q as ResponsiveSelect, r as ResponsiveNumber, s as Checkbox, t as Grid, u as TextInput, L as Link, v as ResponsiveColor, w as TextStyle, C as ComponentIcon, I as Images, N as Number$1, D as Date$1, F as Font, x as ResponsiveLength, y as TextArea, z as Table, A as TableFormFields, H as Image, J as ResponsiveOpacity, K as NavigationLinks, O as SocialLinks, Q as RichText, V as Video, U as useStyle, X as getBorderSwatchIds, Y as isNonNullable$1, Z as getBoxShadowsSwatchIds, _ as getResponsiveColorSwatchIds, $ as StyleControlProperty, a0 as ImageControlValueFormat, a1 as isPropControllersHandle, a2 as isRichTextV1Data, a3 as StyleControlType, a4 as RichTextV2ControlType, a5 as RichTextControlType, a6 as SlotControlType, a7 as StyleV2ControlType, a8 as ListControlType, a9 as ShapeControlType, aa as LinkControlType, ab as ImageControlType, ac as ColorControlType, ad as getComponentPropControllerDescriptors, ae as getPropControllers, af as Types, ag as BorderPropControllerFormat, ah as ShadowsPropControllerFormat, ai as BorderRadiusPropControllerFormat, aj as MarginPropControllerFormat, ak as PaddingPropControllerFormat, al as WidthPropControllerFormat, am as configureStore$1, an as copyElementTree, ao as getBreakpoints, ap as parseLocalesInput, aq as getDocument, ar as getElementId, as as getIsPreview, at as getIsInBuilder, au as getReactComponent, av as getBuilderEditMode } from "./react-page.es.js";
41
+ import { a as createDocumentReference, g as getPropControllerDescriptors, b as isElementReference, e as getSwatchIds, f as getFileIds, h as getTypographyIds, j as getTableIds, k as getPageIds, l as getElementChildren, E as ElementID, B as Backgrounds, W as Width, m as ResponsiveIconRadioGroup, M as Margin, P as Padding, n as Border, o as BorderRadius, S as Shadows, G as GapY, p as GapX, q as ResponsiveSelect, r as ResponsiveNumber, s as Checkbox, t as Grid, u as TextInput, L as Link, v as ResponsiveColor, w as TextStyle, C as ComponentIcon, I as Images, N as Number$1, D as Date$1, F as Font, x as ResponsiveLength, y as TextArea, z as Table, A as TableFormFields, H as Image, J as ResponsiveOpacity, K as NavigationLinks, O as SocialLinks, Q as RichText, V as Video, U as useStyle, X as getBorderSwatchIds, Y as getBoxShadowsSwatchIds, Z as getResponsiveColorSwatchIds, _ as StyleControlProperty, $ as ImageControlValueFormat, a0 as isPropControllersHandle, a1 as isRichTextV1Data, a2 as isNonNullable$1, a3 as TypographyControlType, a4 as StyleControlType, a5 as RichTextV2ControlType, a6 as RichTextControlType, a7 as SlotControlType, a8 as StyleV2ControlType, a9 as ListControlType, aa as ShapeControlType, ab as LinkControlType, ac as ImageControlType, ad as ColorControlType, ae as getComponentPropControllerDescriptors, af as getPropControllers, ag as Types, ah as BorderPropControllerFormat, ai as ShadowsPropControllerFormat, aj as BorderRadiusPropControllerFormat, ak as MarginPropControllerFormat, al as PaddingPropControllerFormat, am as WidthPropControllerFormat, an as configureStore$1, ao as copyElementTree, ap as getBreakpoints, aq as parseLocalesInput, ar as getDocument, as as getElementId, at as getIsPreview, au as getIsInBuilder, av as getReactComponent, aw as getBuilderEditMode } from "./react-page.es.js";
42
42
  import { A as ActionTypes, o as apiResourceFulfilled, p as registerComponentEffect, q as registerReactComponentEffect, t as registerComponentHandleEffect, v as mountComponentEffect } from "./actions.es.js";
43
43
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
44
- import { T as TypographyControlType, I as IconRadioGroupControlType, S as SelectControlType, a as TextAreaControlType, b as TextInputControlType, N as NumberControlType, C as CheckboxControlType } from "./typography.es.js";
44
+ import { I as IconRadioGroupControlType, S as SelectControlType, T as TextAreaControlType, a as TextInputControlType, N as NumberControlType, C as CheckboxControlType } from "./text-input.es.js";
45
45
  import { C as ComboboxControlType } from "./combobox.es.js";
46
46
  import "slate";
47
47
  import { useSyncExternalStore } from "use-sync-external-store/shim";
@@ -916,7 +916,8 @@ Received "${apiKey}" instead.`);
916
916
  return response;
917
917
  }
918
918
  async getPages() {
919
- const response = await this.fetch(`/v2/pages`, {
919
+ const isUsingVersioning = this.siteVersion != null;
920
+ const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages`, {
920
921
  headers: {
921
922
  "Makeswift-Site-Version": MakeswiftSiteVersion.Live
922
923
  }
@@ -934,7 +935,8 @@ Received "${apiKey}" instead.`);
934
935
  }
935
936
  async getSwatches(ids, preview) {
936
937
  var _a;
937
- const url = new URL(`v1/swatches/bulk`, this.apiOrigin);
938
+ const isUsingVersioning = this.siteVersion != null;
939
+ const url = new URL(`${isUsingVersioning ? "v2" : "v1"}/swatches/bulk`, this.apiOrigin);
938
940
  ids.forEach((id) => {
939
941
  url.searchParams.append("ids", id);
940
942
  });
@@ -1086,11 +1088,12 @@ Received "${apiKey}" instead.`);
1086
1088
  unstable_locale
1087
1089
  } = {}) {
1088
1090
  var _a;
1091
+ const isUsingVersioning = this.siteVersion != null;
1089
1092
  const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
1090
1093
  const searchParams = new URLSearchParams();
1091
1094
  if (unstable_locale)
1092
1095
  searchParams.set("locale", unstable_locale);
1093
- const response = await this.fetch(`/v2/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1096
+ const response = await this.fetch(`/${isUsingVersioning ? "v3" : "v2"}/pages/${encodeURIComponent(pathname)}/document?${searchParams.toString()}`, {
1094
1097
  headers: { "Makeswift-Site-Version": siteVersion }
1095
1098
  });
1096
1099
  if (!response.ok) {
@@ -1113,7 +1116,8 @@ Received "${apiKey}" instead.`);
1113
1116
  };
1114
1117
  }
1115
1118
  async getSwatch(swatchId) {
1116
- const response = await this.fetch(`v1/swatches/${swatchId}`);
1119
+ const isUsingVersioning = this.siteVersion != null;
1120
+ const response = await this.fetch(`${isUsingVersioning ? "v2" : "v1"}/swatches/${swatchId}`);
1117
1121
  if (!response.ok) {
1118
1122
  if (response.status !== 404)
1119
1123
  console.error("Failed to get swatch", await response.json());
@@ -1202,7 +1206,7 @@ async function fonts(_req, res, { getFonts } = {}) {
1202
1206
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1203
1207
  return res.json(fonts2);
1204
1208
  }
1205
- const version = "0.9.10";
1209
+ const version = "0.9.12";
1206
1210
  async function handler(req, res, { apiKey, unstable_siteVersions }) {
1207
1211
  if (req.query.secret !== apiKey) {
1208
1212
  return res.status(401).json({ message: "Unauthorized" });
@@ -2533,6 +2537,9 @@ const FallbackComponent = forwardRef(function FallbackComponent2({
2533
2537
  })]
2534
2538
  });
2535
2539
  });
2540
+ function isNonNullable(value) {
2541
+ return value != null;
2542
+ }
2536
2543
  function useSwatch(swatchId) {
2537
2544
  const client = useMakeswiftClient();
2538
2545
  const readSwatch = () => swatchId == null ? null : client.readSwatch(swatchId);
@@ -2641,7 +2648,7 @@ function mapSideColor(swatches, _e) {
2641
2648
  return __spreadProps(__spreadValues({}, restOfSide), {
2642
2649
  color: color && {
2643
2650
  alpha: color.alpha,
2644
- swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId)
2651
+ swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId)
2645
2652
  }
2646
2653
  });
2647
2654
  }
@@ -2687,7 +2694,7 @@ function useBoxShadow(value) {
2687
2694
  return __spreadProps(__spreadValues({}, restOfShadow), {
2688
2695
  payload: {
2689
2696
  color: color != null ? {
2690
- swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId),
2697
+ swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId),
2691
2698
  alpha: color.alpha
2692
2699
  } : null,
2693
2700
  inset: inset != null ? inset : ShadowDefaultValue.inset,
@@ -2711,7 +2718,7 @@ function useResponsiveColor(color) {
2711
2718
  const { swatchId, alpha } = v;
2712
2719
  const swatch = swatches.find((s) => s && s.id === swatchId);
2713
2720
  return swatch == null ? null : __spreadProps(__spreadValues({}, rest), { value: { swatch, alpha } });
2714
- }).filter(isNonNullable$1);
2721
+ }).filter(isNonNullable);
2715
2722
  }
2716
2723
  const getIndexes = (spans, index) => {
2717
2724
  const flattened = spans.reduce((a, s) => a.concat(s), []);
@@ -3199,7 +3206,7 @@ function useRichTextV2(data, definition, control) {
3199
3206
  control
3200
3207
  }) : /* @__PURE__ */ jsx(ReadOnlyText, {
3201
3208
  text: data,
3202
- control
3209
+ definition
3203
3210
  });
3204
3211
  }
3205
3212
  function useSelectControlValue(data, definition) {
@@ -3425,9 +3432,6 @@ function useTextAreaValue(data, definition) {
3425
3432
  function useTextInputValue(data, definition) {
3426
3433
  return data != null ? data : definition.config.defaultValue;
3427
3434
  }
3428
- function isNonNullable(value) {
3429
- return value != null;
3430
- }
3431
3435
  function typographyFragementToTypographyControlData(typography) {
3432
3436
  if (typography == null)
3433
3437
  return void 0;
@@ -3459,7 +3463,7 @@ function getTypographyStyleSwatchIds(style) {
3459
3463
  return (_a = style == null ? void 0 : style.map((override) => override.value).flatMap((typographyStyle) => {
3460
3464
  var _a2;
3461
3465
  return (_a2 = typographyStyle.color) == null ? void 0 : _a2.swatchId;
3462
- }).filter(isNonNullable)) != null ? _a : [];
3466
+ }).filter(isNonNullable$1)) != null ? _a : [];
3463
3467
  }
3464
3468
  const withColor = (swatches) => (deviceRawTypographyValue) => {
3465
3469
  var _b, _c;
@@ -3495,7 +3499,7 @@ function useEnhancedTypography(value) {
3495
3499
  ...getTypographyStyleSwatchIds(value == null ? void 0 : value.style),
3496
3500
  ...getTypographyStyleSwatchIds(typography == null ? void 0 : typography.style)
3497
3501
  ];
3498
- const swatches = useSwatches(swatchIds).filter(isNonNullable);
3502
+ const swatches = useSwatches(swatchIds).filter(isNonNullable$1);
3499
3503
  const enhancedSource = source.map(withColor(swatches));
3500
3504
  const enhancedOverride = override.map(withColor(swatches));
3501
3505
  const devices = [
@@ -3522,7 +3526,7 @@ function useEnhancedTypography(value) {
3522
3526
  };
3523
3527
  }
3524
3528
  return null;
3525
- }).filter(isNonNullable);
3529
+ }).filter(isNonNullable$1);
3526
3530
  }
3527
3531
  function useTypographyClassName(value) {
3528
3532
  return useStyle(useResponsiveStyle([value], ([value2]) => {
@@ -4223,5 +4227,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
4223
4227
  document: document2
4224
4228
  });
4225
4229
  }));
4226
- export { Makeswift as $, Alignments as A, forwardNextDynamicRef as B, Contrasts as C, DocumentReference as D, Element$1 as E, useIsPreview as F, useFiles as G, useSwatches as H, usePagePathnameSlice as I, useElementId as J, shallowEqual as K, deepEqual as L, ElementImperativeHandle as M, StoreContext as N, MakeswiftProvider as O, PageProvider as P, ControlValue as Q, RuntimeProvider as R, Shapes as S, useBuilderEditMode as T, pollBoxModel as U, useEnhancedTypography as V, useTypographyClassName as W, getStaticPaths as X, getStaticProps as Y, getServerSideProps as Z, Page as _, ReactRuntime as a, PreviewModeScript as a0, Document$1 as a1, MakeswiftApiHandler as a2, usePageId as b, DEFAULT_BOX_ANIMATE_TYPE as c, DEFAULT_BOX_ANIMATE_DELAY as d, DEFAULT_BOX_ANIMATE_DURATION as e, DEFAULT_ITEM_ANIMATE_TYPE as f, DEFAULT_ITEM_ANIMATE_DELAY as g, DEFAULT_ITEM_ANIMATE_DURATION as h, DEFAULT_ITEM_STAGGER_DURATION as i, useBorder as j, useBoxShadow as k, useResponsiveColor as l, Page$1 as m, useResponsiveStyle as n, useResponsiveWidth as o, useResponsiveTextStyle as p, colorToString as q, useBreakpoints as r, Sizes as s, useFormContext as t, useIsInBuilder as u, useResponsiveGridItem as v, useTable as w, useMakeswiftClient as x, Provider as y, useFile as z };
4230
+ export { Page as $, Alignments as A, forwardNextDynamicRef as B, Contrasts as C, DocumentReference as D, Element$1 as E, useIsPreview as F, isNonNullable as G, useFiles as H, useSwatches as I, usePagePathnameSlice as J, useElementId as K, shallowEqual as L, deepEqual as M, ElementImperativeHandle as N, StoreContext as O, PageProvider as P, MakeswiftProvider as Q, RuntimeProvider as R, Shapes as S, ControlValue as T, useBuilderEditMode as U, pollBoxModel as V, useEnhancedTypography as W, useTypographyClassName as X, getStaticPaths as Y, getStaticProps as Z, getServerSideProps as _, ReactRuntime as a, Makeswift as a0, PreviewModeScript as a1, Document$1 as a2, MakeswiftApiHandler as a3, usePageId as b, DEFAULT_BOX_ANIMATE_TYPE as c, DEFAULT_BOX_ANIMATE_DELAY as d, DEFAULT_BOX_ANIMATE_DURATION as e, DEFAULT_ITEM_ANIMATE_TYPE as f, DEFAULT_ITEM_ANIMATE_DELAY as g, DEFAULT_ITEM_ANIMATE_DURATION as h, DEFAULT_ITEM_STAGGER_DURATION as i, useBorder as j, useBoxShadow as k, useResponsiveColor as l, Page$1 as m, useResponsiveStyle as n, useResponsiveWidth as o, useResponsiveTextStyle as p, colorToString as q, useBreakpoints as r, Sizes as s, useFormContext as t, useIsInBuilder as u, useResponsiveGridItem as v, useTable as w, useMakeswiftClient as x, Provider as y, useFile as z };
4227
4231
  //# sourceMappingURL=index.es.js.map