@makeswift/runtime 0.8.11 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) 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 +2 -2
  6. package/dist/Carousel.es.js +2 -2
  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/Embed.cjs.js +1 -1
  12. package/dist/Embed.es.js +1 -1
  13. package/dist/Form.cjs.js +1 -1
  14. package/dist/Form.es.js +1 -1
  15. package/dist/Image.cjs.js +1 -1
  16. package/dist/Image.es.js +1 -1
  17. package/dist/LiveProvider.cjs.js +2 -2
  18. package/dist/LiveProvider.es.js +3 -3
  19. package/dist/Navigation.cjs.js +2 -2
  20. package/dist/Navigation.es.js +2 -2
  21. package/dist/PreviewProvider.cjs.js +17 -2
  22. package/dist/PreviewProvider.cjs.js.map +1 -1
  23. package/dist/PreviewProvider.es.js +19 -4
  24. package/dist/PreviewProvider.es.js.map +1 -1
  25. package/dist/ReadOnlyText.cjs.js +10 -9
  26. package/dist/ReadOnlyText.cjs.js.map +1 -1
  27. package/dist/ReadOnlyText.es.js +10 -9
  28. package/dist/ReadOnlyText.es.js.map +1 -1
  29. package/dist/ReadOnlyTextV2.cjs.js +10 -9
  30. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  31. package/dist/ReadOnlyTextV2.es.js +10 -9
  32. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  33. package/dist/Root.cjs.js +1 -1
  34. package/dist/Root.es.js +1 -1
  35. package/dist/SocialLinks.cjs.js +1 -1
  36. package/dist/SocialLinks.es.js +1 -1
  37. package/dist/Text.cjs.js +1 -1
  38. package/dist/Text.es.js +1 -1
  39. package/dist/Video.cjs.js +1 -1
  40. package/dist/Video.es.js +1 -1
  41. package/dist/actions.cjs.js +16 -1
  42. package/dist/actions.cjs.js.map +1 -1
  43. package/dist/actions.es.js +14 -2
  44. package/dist/actions.es.js.map +1 -1
  45. package/dist/components.cjs.js +1 -1
  46. package/dist/components.es.js +1 -1
  47. package/dist/control-serialization.cjs.js +1 -1
  48. package/dist/control-serialization.es.js +2 -2
  49. package/dist/controls.cjs.js +2 -3
  50. package/dist/controls.cjs.js.map +1 -1
  51. package/dist/controls.es.js +1 -2
  52. package/dist/controls.es.js.map +1 -1
  53. package/dist/index.cjs.js +253 -218
  54. package/dist/index.cjs.js.map +1 -1
  55. package/dist/index.cjs10.js +11 -10
  56. package/dist/index.cjs10.js.map +1 -1
  57. package/dist/index.cjs2.js +1 -1
  58. package/dist/index.cjs5.js +0 -522
  59. package/dist/index.cjs5.js.map +1 -1
  60. package/dist/index.cjs6.js +1 -2
  61. package/dist/index.cjs6.js.map +1 -1
  62. package/dist/index.cjs7.js +0 -52
  63. package/dist/index.cjs7.js.map +1 -1
  64. package/dist/index.cjs8.js +1 -1
  65. package/dist/index.cjs9.js +42 -3
  66. package/dist/index.cjs9.js.map +1 -1
  67. package/dist/index.es.js +253 -218
  68. package/dist/index.es.js.map +1 -1
  69. package/dist/index.es10.js +12 -11
  70. package/dist/index.es10.js.map +1 -1
  71. package/dist/index.es2.js +2 -2
  72. package/dist/index.es5.js +2 -514
  73. package/dist/index.es5.js.map +1 -1
  74. package/dist/index.es6.js +1 -2
  75. package/dist/index.es6.js.map +1 -1
  76. package/dist/index.es7.js +2 -53
  77. package/dist/index.es7.js.map +1 -1
  78. package/dist/index.es8.js +1 -1
  79. package/dist/index.es9.js +43 -4
  80. package/dist/index.es9.js.map +1 -1
  81. package/dist/leaf.es.js +1 -1
  82. package/dist/main.cjs.js +3 -0
  83. package/dist/main.cjs.js.map +1 -1
  84. package/dist/main.es.js +2 -2
  85. package/dist/next.cjs.js +1 -1
  86. package/dist/next.es.js +1 -1
  87. package/dist/react-page.cjs.js +711 -61
  88. package/dist/react-page.cjs.js.map +1 -1
  89. package/dist/react-page.es.js +694 -56
  90. package/dist/react-page.es.js.map +1 -1
  91. package/dist/react.cjs.js +1 -1
  92. package/dist/react.es.js +1 -1
  93. package/dist/slate.cjs.js +11 -13
  94. package/dist/slate.cjs.js.map +1 -1
  95. package/dist/slate.es.js +4 -5
  96. package/dist/slate.es.js.map +1 -1
  97. package/dist/types/src/api/graphql/documents/queries.d.ts.map +1 -1
  98. package/dist/types/src/api/graphql/generated/types.d.ts +0 -8
  99. package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
  100. package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
  101. package/dist/types/src/components/builtin/Carousel/register.d.ts.map +1 -1
  102. package/dist/types/src/components/builtin/Countdown/register.d.ts.map +1 -1
  103. package/dist/types/src/components/builtin/Divider/register.d.ts.map +1 -1
  104. package/dist/types/src/components/builtin/Embed/register.d.ts.map +1 -1
  105. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  106. package/dist/types/src/components/builtin/Form/register.d.ts.map +1 -1
  107. package/dist/types/src/components/builtin/Navigation/register.d.ts.map +1 -1
  108. package/dist/types/src/components/builtin/SocialLinks/register.d.ts.map +1 -1
  109. package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -1
  110. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  111. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -1
  112. package/dist/types/src/components/builtin/Video/register.d.ts.map +1 -1
  113. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +3 -3
  114. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  115. package/dist/types/src/index.d.ts +2 -1
  116. package/dist/types/src/index.d.ts.map +1 -1
  117. package/dist/types/src/next/api-handler/handlers/manifest.d.ts +3 -1
  118. package/dist/types/src/next/api-handler/handlers/manifest.d.ts.map +1 -1
  119. package/dist/types/src/next/api-handler/handlers/proxy-preview-mode.d.ts.map +1 -1
  120. package/dist/types/src/next/api-handler/index.d.ts +2 -1
  121. package/dist/types/src/next/api-handler/index.d.ts.map +1 -1
  122. package/dist/types/src/next/client.d.ts +7 -7
  123. package/dist/types/src/next/client.d.ts.map +1 -1
  124. package/dist/types/src/next/index.d.ts +8 -5
  125. package/dist/types/src/next/index.d.ts.map +1 -1
  126. package/dist/types/src/next/preview-mode.d.ts +17 -3
  127. package/dist/types/src/next/preview-mode.d.ts.map +1 -1
  128. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  129. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  130. package/dist/types/src/runtimes/react/index.d.ts +3 -1
  131. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  132. package/dist/types/src/slate/BlockPlugin/constants.d.ts.map +1 -0
  133. package/dist/types/src/slate/BlockPlugin/dedent.d.ts.map +1 -0
  134. package/dist/types/src/slate/BlockPlugin/indent.d.ts.map +1 -0
  135. package/dist/types/src/slate/BlockPlugin/index.d.ts +26 -3
  136. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
  137. package/dist/types/src/slate/BlockPlugin/toggleList.d.ts.map +1 -0
  138. package/dist/types/src/slate/BlockPlugin/unwrapList.d.ts.map +1 -0
  139. package/dist/types/src/slate/BlockPlugin/utils/filterForSubtreeRoots.d.ts.map +1 -0
  140. package/dist/types/src/slate/BlockPlugin/utils/getSelectedListItems.d.ts.map +1 -0
  141. package/dist/types/src/slate/BlockPlugin/utils/location.d.ts.map +1 -0
  142. package/dist/types/src/slate/BlockPlugin/wrapList.d.ts.map +1 -0
  143. package/dist/types/src/slate/InlineModePlugin/index.d.ts +1 -1
  144. package/dist/types/src/slate/index.d.ts +0 -1
  145. package/dist/types/src/slate/index.d.ts.map +1 -1
  146. package/dist/types/src/slate/utils/element.d.ts +1 -2
  147. package/dist/types/src/slate/utils/element.d.ts.map +1 -1
  148. package/dist/types/src/state/actions.d.ts +26 -1
  149. package/dist/types/src/state/actions.d.ts.map +1 -1
  150. package/dist/types/src/state/modules/components-meta.d.ts +25 -1
  151. package/dist/types/src/state/modules/components-meta.d.ts.map +1 -1
  152. package/dist/types/src/state/modules/locales.d.ts +16 -0
  153. package/dist/types/src/state/modules/locales.d.ts.map +1 -0
  154. package/dist/types/src/state/react-builder-preview.d.ts +2 -0
  155. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  156. package/dist/types/src/state/react-page.d.ts +5 -1
  157. package/dist/types/src/state/react-page.d.ts.map +1 -1
  158. package/package.json +6 -3
  159. package/dist/select.cjs.js +0 -8
  160. package/dist/select.cjs.js.map +0 -1
  161. package/dist/select.es.js +0 -6
  162. package/dist/select.es.js.map +0 -1
  163. package/dist/types/src/slate/ListPlugin/constants.d.ts.map +0 -1
  164. package/dist/types/src/slate/ListPlugin/dedent.d.ts.map +0 -1
  165. package/dist/types/src/slate/ListPlugin/indent.d.ts.map +0 -1
  166. package/dist/types/src/slate/ListPlugin/index.d.ts +0 -17
  167. package/dist/types/src/slate/ListPlugin/index.d.ts.map +0 -1
  168. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +0 -1
  169. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +0 -1
  170. package/dist/types/src/slate/ListPlugin/utils/filterForSubtreeRoots.d.ts.map +0 -1
  171. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +0 -1
  172. package/dist/types/src/slate/ListPlugin/utils/location.d.ts.map +0 -1
  173. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +0 -1
  174. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/constants.d.ts +0 -0
  175. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/dedent.d.ts +0 -0
  176. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/indent.d.ts +0 -0
  177. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/toggleList.d.ts +0 -0
  178. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/unwrapList.d.ts +0 -0
  179. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/utils/filterForSubtreeRoots.d.ts +0 -0
  180. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/utils/getSelectedListItems.d.ts +0 -0
  181. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/utils/location.d.ts +0 -0
  182. /package/dist/types/src/slate/{ListPlugin → BlockPlugin}/wrapList.d.ts +0 -0
@@ -19,357 +19,7 @@ var __spreadValues = (a, b) => {
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  var slate = require("slate");
22
- var isHotkey = require("is-hotkey");
23
- var index = require("./index.cjs7.js");
24
- var reactPage = require("./react-page.cjs.js");
25
22
  var state_breakpoints = require("./state/breakpoints.cjs.js");
26
- var select = require("./select.cjs.js");
27
- require("slate-react");
28
- function _interopDefaultLegacy(e) {
29
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
30
- }
31
- var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
32
- const LIST_ITEM_CHILD_POSITION = 0;
33
- const LIST_ITEM_LIST_POSITION = 1;
34
- const EditorUtils = {
35
- getFirstAncestorList(editor, path) {
36
- try {
37
- const parentList = slate.Editor.above(editor, {
38
- at: path,
39
- match: (node) => index.ElementUtils.isList(node)
40
- });
41
- return parentList != null ? parentList : null;
42
- } catch (e) {
43
- return null;
44
- }
45
- },
46
- getFirstAncestorListItem(editor, path) {
47
- try {
48
- const parentListItem = slate.Editor.above(editor, {
49
- at: path,
50
- match: (node) => index.ElementUtils.isListItem(node)
51
- });
52
- return parentListItem != null ? parentListItem : null;
53
- } catch (e) {
54
- return null;
55
- }
56
- }
57
- };
58
- function filterForSubtreeRoots(entries) {
59
- return entries.filter(([, nodePath]) => !slate.Path.ancestors(nodePath).some((ancestor) => {
60
- return entries.some(([, path]) => slate.Path.equals(path, ancestor));
61
- }));
62
- }
63
- const LocationUtils = {
64
- getStartPath(location) {
65
- if (slate.Range.isRange(location))
66
- return slate.Range.start(location).path;
67
- if (slate.Point.isPoint(location))
68
- return location.path;
69
- return location;
70
- }
71
- };
72
- function getSelectedListItems(editor) {
73
- var _a, _b;
74
- if (!editor.selection)
75
- return [];
76
- const start = LocationUtils.getStartPath(editor.selection);
77
- const listItems = slate.Editor.nodes(editor, {
78
- at: editor.selection,
79
- match: (node) => index.ElementUtils.isListItem(node)
80
- });
81
- const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
82
- return Array.from(listItems).filter((node) => slate.Path.isDescendant(start, node[1]) ? slate.Path.equals(node[1], firstAncestorPath) : !slate.Path.isAfter(start, node[1]));
83
- }
84
- function indentPath(editor, path) {
85
- const parent = slate.Node.parent(editor, path);
86
- if (!path || !slate.Path.hasPrevious(path) || !index.ElementUtils.isList(parent))
87
- return;
88
- const previosPath = slate.Path.previous(path);
89
- const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION];
90
- const previousHasChildList = slate.Node.has(editor, previousChildListPath);
91
- slate.Editor.withoutNormalizing(editor, () => {
92
- if (!previousHasChildList) {
93
- slate.Transforms.insertNodes(editor, index.ElementUtils.createList(parent.type), {
94
- at: previousChildListPath
95
- });
96
- }
97
- const previousChildList = slate.Node.get(editor, previousChildListPath);
98
- if (index.ElementUtils.isList(previousChildList)) {
99
- const index2 = previousHasChildList ? previousChildList.children.length : 0;
100
- slate.Transforms.moveNodes(editor, {
101
- at: path,
102
- to: [...previousChildListPath, index2]
103
- });
104
- }
105
- });
106
- }
107
- function indent(editor) {
108
- if (!editor.selection)
109
- return;
110
- const listItems = getSelectedListItems(editor);
111
- const subRoots = filterForSubtreeRoots(listItems);
112
- const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
113
- refs.forEach((ref) => {
114
- if (ref.current) {
115
- indentPath(editor, ref.current);
116
- }
117
- ref.unref();
118
- });
119
- }
120
- function dedentPath(editor, listItemPath) {
121
- const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
122
- const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
123
- if (!parentList || !listItemContainingParentList)
124
- return;
125
- const [parentListNode, parentListPath] = parentList;
126
- const [_, listItemContainingParentListPath] = listItemContainingParentList;
127
- const listItemPosition = listItemPath[listItemPath.length - 1];
128
- const previousSiblings = parentListNode.children.slice(0, listItemPosition);
129
- const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
130
- slate.Editor.withoutNormalizing(editor, () => {
131
- nextSiblings.forEach(() => {
132
- const nextSiblingPath = [...parentListPath, listItemPosition + 1];
133
- indentPath(editor, nextSiblingPath);
134
- });
135
- slate.Transforms.moveNodes(editor, {
136
- at: listItemPath,
137
- to: slate.Path.next(listItemContainingParentListPath)
138
- });
139
- if (previousSiblings.length === 0) {
140
- slate.Transforms.removeNodes(editor, { at: parentListPath });
141
- }
142
- });
143
- }
144
- function dedent(editor) {
145
- if (!editor.selection)
146
- return;
147
- const listItems = getSelectedListItems(editor);
148
- const subRoots = filterForSubtreeRoots(listItems);
149
- const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
150
- refs.forEach((ref) => {
151
- if (ref.current) {
152
- dedentPath(editor, ref.current);
153
- }
154
- ref.unref();
155
- });
156
- }
157
- function unwrapPath(editor, listItemPath) {
158
- const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
159
- const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
160
- if (!parentList || listItemContainingParentList)
161
- return;
162
- slate.Editor.withoutNormalizing(editor, () => {
163
- const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
164
- const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
165
- if (slate.Node.has(editor, listItemNestedListPath)) {
166
- slate.Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
167
- slate.Transforms.liftNodes(editor, { at: listItemNestedListPath });
168
- slate.Transforms.liftNodes(editor, { at: slate.Path.next(listItemPath) });
169
- }
170
- if (slate.Node.has(editor, listItemTextPath)) {
171
- slate.Transforms.setNodes(editor, { type: reactPage.BlockType.Paragraph }, {
172
- at: listItemTextPath
173
- });
174
- slate.Transforms.liftNodes(editor, { at: listItemTextPath });
175
- slate.Transforms.liftNodes(editor, { at: listItemPath });
176
- }
177
- });
178
- }
179
- function unwrapList(editor, options) {
180
- var _a;
181
- const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
182
- if (!at)
183
- return;
184
- const listItems = Array.from(slate.Editor.nodes(editor, {
185
- at,
186
- match: (node) => {
187
- return slate.Element.isElement(node) && index.ElementUtils.isListItem(node);
188
- }
189
- }));
190
- const subRoots = filterForSubtreeRoots(listItems);
191
- const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
192
- refs.forEach((ref) => {
193
- if (ref.current) {
194
- unwrapPath(editor, ref.current);
195
- }
196
- ref.unref();
197
- });
198
- }
199
- function wrapList(editor, options = { type: reactPage.BlockType.UnorderedList }) {
200
- var _a;
201
- const at = (_a = options.at) != null ? _a : editor.selection;
202
- if (!at)
203
- return;
204
- const nonListEntries = Array.from(slate.Editor.nodes(editor, {
205
- at,
206
- match: (node) => {
207
- return slate.Element.isElement(node) && index.ElementUtils.isConvertibleToListTextNode(node);
208
- }
209
- }));
210
- const refs = nonListEntries.map(([_, path]) => slate.Editor.pathRef(editor, path));
211
- refs.forEach((ref) => {
212
- const path = ref.current;
213
- if (path) {
214
- slate.Editor.withoutNormalizing(editor, () => {
215
- slate.Transforms.setNodes(editor, { type: reactPage.BlockType.ListItemChild }, {
216
- at: path
217
- });
218
- slate.Transforms.wrapNodes(editor, index.ElementUtils.createListItem(), {
219
- match: (node) => index.ElementUtils.isListItemChild(node),
220
- at: path
221
- });
222
- slate.Transforms.wrapNodes(editor, index.ElementUtils.createList(options.type), {
223
- at: path
224
- });
225
- });
226
- }
227
- ref.unref();
228
- });
229
- }
230
- function toggleList(editor, options = { type: reactPage.BlockType.UnorderedList }) {
231
- var _a;
232
- const at = (_a = options.at) != null ? _a : editor.selection;
233
- if (at == null)
234
- return;
235
- const start = LocationUtils.getStartPath(at);
236
- const ancestorPath = slate.Path.ancestors(start).at(1);
237
- if (!ancestorPath || !slate.Node.has(editor, ancestorPath))
238
- return;
239
- const ancestor = slate.Node.get(editor, ancestorPath);
240
- if (!index.ElementUtils.isList(ancestor)) {
241
- return wrapList(editor, { type: options.type, at });
242
- }
243
- if (ancestor.type === options.type) {
244
- unwrapList(editor, { at });
245
- } else {
246
- slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
247
- }
248
- }
249
- const ListActions = {
250
- unwrapList,
251
- wrapList,
252
- indent,
253
- dedent,
254
- toggleList
255
- };
256
- function onKeyDown(e, editor) {
257
- if (!editor.selection || Array.from(slate.Editor.nodes(editor, { match: (node) => index.ElementUtils.isListItem(node) })).length === 0)
258
- return;
259
- if (isHotkey__default["default"]("shift+tab", e)) {
260
- e.preventDefault();
261
- ListActions.dedent(editor);
262
- }
263
- if (isHotkey__default["default"]("tab", e)) {
264
- e.preventDefault();
265
- ListActions.indent(editor);
266
- }
267
- if (isHotkey__default["default"]("backspace", e)) {
268
- if (!editor.selection)
269
- return;
270
- if (slate.Range.isExpanded(editor.selection))
271
- return;
272
- const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
273
- if (editor.selection.anchor.offset === 0 && listItem) {
274
- e.preventDefault();
275
- const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
276
- const list = EditorUtils.getFirstAncestorList(editor, listItem[1]);
277
- if (parentListItem) {
278
- ListActions.dedent(editor);
279
- } else if (list) {
280
- ListActions.unwrapList(editor);
281
- }
282
- return;
283
- }
284
- }
285
- if (isHotkey__default["default"]("enter", e)) {
286
- e.preventDefault();
287
- if (!editor.selection)
288
- return;
289
- if (slate.Range.isExpanded(editor.selection)) {
290
- slate.Transforms.delete(editor);
291
- return;
292
- }
293
- const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
294
- if (editor.selection.anchor.offset === 0 && listItem && slate.Editor.string(editor, listItem[1]) === "") {
295
- const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
296
- if (parentListItem) {
297
- ListActions.dedent(editor);
298
- } else {
299
- ListActions.unwrapList(editor);
300
- }
301
- return;
302
- }
303
- slate.Transforms.splitNodes(editor, {
304
- at: editor.selection,
305
- always: true,
306
- match: (node) => index.ElementUtils.isListItem(node)
307
- });
308
- }
309
- if (isHotkey__default["default"]("shift+enter", e)) {
310
- e.preventDefault();
311
- editor.insertText("\n");
312
- }
313
- }
314
- function withList(editor) {
315
- const { normalizeNode } = editor;
316
- editor.normalizeNode = (entry) => {
317
- const [normalizationNode, normalizationPath] = entry;
318
- if (index.ElementUtils.isListItem(normalizationNode)) {
319
- const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION];
320
- if (slate.Node.has(editor, pathToListItemText)) {
321
- const nodeInListItemTextPosition = slate.Node.get(editor, pathToListItemText);
322
- if (index.ElementUtils.isParagraph(nodeInListItemTextPosition)) {
323
- slate.Transforms.setNodes(editor, { type: reactPage.BlockType.ListItemChild }, {
324
- at: pathToListItemText
325
- });
326
- return;
327
- }
328
- } else {
329
- slate.Transforms.insertNodes(editor, index.ElementUtils.createListItem(), {
330
- at: pathToListItemText
331
- });
332
- return;
333
- }
334
- }
335
- if (!slate.Text.isText(normalizationNode)) {
336
- const mergeableChildren = Array.from(slate.Node.children(editor, normalizationPath)).map((child, index$1, children) => {
337
- const potentialNodeToBeMerged = children.at(index$1 + 1);
338
- if (!potentialNodeToBeMerged || !index.ElementUtils.isList(potentialNodeToBeMerged[0]) || !index.ElementUtils.isList(child[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
339
- return null;
340
- }
341
- return [
342
- slate.Editor.pathRef(editor, child[1]),
343
- slate.Editor.pathRef(editor, potentialNodeToBeMerged[1])
344
- ];
345
- }).filter((mergeableNodes) => Boolean(mergeableNodes));
346
- if (mergeableChildren.length !== 0) {
347
- mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {
348
- const nodePath = nodePathRef.current;
349
- const nodeToBeMergedPath = nodeToBeMergedPathRef.current;
350
- if (nodePath == null || nodeToBeMergedPath == null)
351
- return;
352
- const nodeChildren = Array.from(slate.Node.children(editor, nodePath));
353
- const childrenToBeMerged = Array.from(slate.Node.children(editor, nodeToBeMergedPath));
354
- slate.Editor.withoutNormalizing(editor, () => {
355
- childrenToBeMerged.reverse().forEach(([_, childPath]) => {
356
- slate.Transforms.moveNodes(editor, {
357
- at: childPath,
358
- to: [...nodePath, nodeChildren.length]
359
- });
360
- });
361
- slate.Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
362
- });
363
- nodePathRef.unref();
364
- nodeToBeMergedPathRef.unref();
365
- });
366
- return;
367
- }
368
- }
369
- normalizeNode(entry);
370
- };
371
- return editor;
372
- }
373
23
  function clearActiveTypographyStyle(editor, options) {
374
24
  slate.Editor.withoutNormalizing(editor, () => {
375
25
  var _a;
@@ -557,178 +207,6 @@ function withTypography(editor) {
557
207
  };
558
208
  return editor;
559
209
  }
560
- function unhangRange(editor, range) {
561
- let [start, end] = slate.Range.edges(range);
562
- if (start.offset !== 0 || end.offset !== 0 || slate.Range.isCollapsed(range)) {
563
- return range;
564
- }
565
- const endBlock = slate.Editor.above(editor, {
566
- at: end,
567
- match: (n) => slate.Element.isElement(n) && slate.Editor.isBlock(editor, n)
568
- });
569
- const blockPath = endBlock ? endBlock[1] : [];
570
- const first = slate.Editor.start(editor, start);
571
- const before = { anchor: first, focus: end };
572
- let skip = true;
573
- for (const [node, path] of slate.Editor.nodes(editor, {
574
- at: before,
575
- match: slate.Text.isText,
576
- reverse: true
577
- })) {
578
- if (skip) {
579
- skip = false;
580
- continue;
581
- }
582
- if (node.text !== "" || slate.Path.isBefore(path, blockPath)) {
583
- end = { path, offset: node.text.length };
584
- break;
585
- }
586
- }
587
- return { anchor: start, focus: end };
588
- }
589
- function getSelection(editor) {
590
- if (editor.selection)
591
- return unhangRange(editor, editor.selection);
592
- return {
593
- anchor: slate.Editor.start(editor, []),
594
- focus: slate.Editor.end(editor, [])
595
- };
596
- }
597
- function getBlocksInSelection(editor) {
598
- return Array.from(slate.Editor.nodes(editor, {
599
- at: getSelection(editor),
600
- match: (node) => index.ElementUtils.isRootBlock(node)
601
- })).filter((entry) => index.ElementUtils.isRootBlock(entry[0]));
602
- }
603
- function getActiveBlockType(editor) {
604
- var _a;
605
- const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type);
606
- return rootBlocks.reduce((a, b) => a === b ? b : null, (_a = rootBlocks.at(0)) != null ? _a : null);
607
- }
608
- function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
609
- var _a, _b;
610
- const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
611
- if (!at)
612
- return;
613
- const rootElements = getBlocksInSelection(editor);
614
- for (const [node, path] of rootElements) {
615
- if (index.ElementUtils.isBlock(node)) {
616
- const deviceValues = (_b = node[key]) != null ? _b : [];
617
- const currentDeviceValue = state_breakpoints.findBreakpointOverride(breakpoints, deviceValues, deviceId, (v) => v);
618
- const nextDeviceValue = __spreadProps(__spreadValues({}, currentDeviceValue), {
619
- deviceId,
620
- value
621
- });
622
- slate.Transforms.setNodes(editor, {
623
- [key]: [...deviceValues.filter((v) => v.deviceId !== deviceId), nextDeviceValue]
624
- }, { at: path });
625
- }
626
- }
627
- }
628
- function clearBlockKeyForDevice(editor, deviceId, key) {
629
- var _a;
630
- const rootElements = getBlocksInSelection(editor);
631
- for (const [node, path] of rootElements) {
632
- if (index.ElementUtils.isBlock(node)) {
633
- const deviceOverrides = (_a = node[key]) != null ? _a : [];
634
- slate.Transforms.setNodes(editor, {
635
- [key]: deviceOverrides.filter((v) => v.deviceId !== deviceId)
636
- }, { at: path });
637
- }
638
- }
639
- }
640
- function wrapInline(editor, inline) {
641
- slate.Transforms.wrapNodes(editor, inline, {
642
- at: getSelection(editor),
643
- split: true
644
- });
645
- }
646
- function unwrapInline(editor, type) {
647
- slate.Transforms.unwrapNodes(editor, {
648
- match: (node) => index.ElementUtils.isInline(node) && node.type === type,
649
- at: getSelection(editor)
650
- });
651
- }
652
- const BlockActions = {
653
- setBlockKeyForDevice,
654
- clearBlockKeyForDevice,
655
- wrapInline,
656
- unwrapInline
657
- };
658
- function withBlock(editor) {
659
- const { normalizeNode } = editor;
660
- editor.isInline = (entry) => {
661
- return index.ElementUtils.isInline(entry);
662
- };
663
- editor.normalizeNode = (entry) => {
664
- var _a;
665
- const [normalizationNode, normalizationPath] = entry;
666
- if (index.ElementUtils.isBlock(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.textAlign) == null ? void 0 : _a.length) == 0) {
667
- slate.Transforms.unsetNodes(editor, "textAlign", { at: normalizationPath });
668
- return;
669
- }
670
- normalizeNode(entry);
671
- };
672
- return editor;
673
- }
674
- function BlockPlugin() {
675
- return reactPage.createRichTextV2Plugin({
676
- withPlugin: withBlock,
677
- control: {
678
- definition: select.Select({
679
- label: "Block",
680
- options: [
681
- {
682
- value: reactPage.BlockType.Heading1,
683
- label: "Heading1"
684
- },
685
- {
686
- value: reactPage.BlockType.Heading2,
687
- label: "Heading2"
688
- },
689
- {
690
- value: reactPage.BlockType.Heading3,
691
- label: "Heading3"
692
- },
693
- {
694
- value: reactPage.BlockType.Heading4,
695
- label: "Heading4"
696
- },
697
- {
698
- value: reactPage.BlockType.Heading5,
699
- label: "Heading5"
700
- },
701
- {
702
- value: reactPage.BlockType.Heading6,
703
- label: "Heading6"
704
- },
705
- {
706
- value: reactPage.BlockType.Paragraph,
707
- label: "Paragraph"
708
- }
709
- ],
710
- defaultValue: reactPage.BlockType.Paragraph
711
- }),
712
- onChange: (editor, value) => {
713
- slate.Transforms.setNodes(editor, {
714
- type: value != null ? value : reactPage.BlockType.Default
715
- }, { at: getSelection(editor) });
716
- },
717
- getValue: (editor) => {
718
- const activeBlock = getActiveBlockType(editor);
719
- if (activeBlock === reactPage.RootBlockType.BlockQuote || activeBlock === reactPage.RootBlockType.OrderedList || activeBlock === reactPage.RootBlockType.UnorderedList || activeBlock === reactPage.RootBlockType.Text || activeBlock === reactPage.RootBlockType.Default)
720
- return void 0;
721
- return activeBlock;
722
- }
723
- }
724
- });
725
- }
726
- exports.BlockActions = BlockActions;
727
- exports.BlockPlugin = BlockPlugin;
728
- exports.ListActions = ListActions;
729
210
  exports.TypographyActions = TypographyActions;
730
- exports.onKeyDown = onKeyDown;
731
- exports.withBlock = withBlock;
732
- exports.withList = withList;
733
211
  exports.withTypography = withTypography;
734
212
  //# sourceMappingURL=index.cjs5.js.map