@makeswift/runtime 0.9.2 → 0.9.3

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 (153) hide show
  1. package/dist/Box.cjs.js +0 -2
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +0 -2
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +0 -2
  6. package/dist/Button.cjs.js.map +1 -1
  7. package/dist/Button.es.js +0 -2
  8. package/dist/Button.es.js.map +1 -1
  9. package/dist/Carousel.cjs.js +0 -2
  10. package/dist/Carousel.cjs.js.map +1 -1
  11. package/dist/Carousel.es.js +0 -2
  12. package/dist/Carousel.es.js.map +1 -1
  13. package/dist/Countdown.cjs.js +0 -2
  14. package/dist/Countdown.cjs.js.map +1 -1
  15. package/dist/Countdown.es.js +0 -2
  16. package/dist/Countdown.es.js.map +1 -1
  17. package/dist/Divider.cjs.js +0 -2
  18. package/dist/Divider.cjs.js.map +1 -1
  19. package/dist/Divider.es.js +0 -2
  20. package/dist/Divider.es.js.map +1 -1
  21. package/dist/Form.cjs.js +0 -2
  22. package/dist/Form.cjs.js.map +1 -1
  23. package/dist/Form.es.js +0 -2
  24. package/dist/Form.es.js.map +1 -1
  25. package/dist/Image.cjs.js +0 -2
  26. package/dist/Image.cjs.js.map +1 -1
  27. package/dist/Image.es.js +0 -2
  28. package/dist/Image.es.js.map +1 -1
  29. package/dist/LiveProvider.cjs.js +0 -2
  30. package/dist/LiveProvider.cjs.js.map +1 -1
  31. package/dist/LiveProvider.es.js +1 -3
  32. package/dist/LiveProvider.es.js.map +1 -1
  33. package/dist/Navigation.cjs.js +0 -2
  34. package/dist/Navigation.cjs.js.map +1 -1
  35. package/dist/Navigation.es.js +0 -2
  36. package/dist/Navigation.es.js.map +1 -1
  37. package/dist/PreviewProvider.cjs.js +2 -4
  38. package/dist/PreviewProvider.cjs.js.map +1 -1
  39. package/dist/PreviewProvider.es.js +1 -3
  40. package/dist/PreviewProvider.es.js.map +1 -1
  41. package/dist/ReadOnlyText.cjs.js +1 -3
  42. package/dist/ReadOnlyText.cjs.js.map +1 -1
  43. package/dist/ReadOnlyText.es.js +2 -4
  44. package/dist/ReadOnlyText.es.js.map +1 -1
  45. package/dist/ReadOnlyTextV2.cjs.js +1 -3
  46. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  47. package/dist/ReadOnlyTextV2.es.js +2 -4
  48. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  49. package/dist/Root.cjs.js +0 -2
  50. package/dist/Root.cjs.js.map +1 -1
  51. package/dist/Root.es.js +0 -2
  52. package/dist/Root.es.js.map +1 -1
  53. package/dist/SocialLinks.cjs.js +0 -2
  54. package/dist/SocialLinks.cjs.js.map +1 -1
  55. package/dist/SocialLinks.es.js +0 -2
  56. package/dist/SocialLinks.es.js.map +1 -1
  57. package/dist/Text.cjs.js +1 -3
  58. package/dist/Text.cjs.js.map +1 -1
  59. package/dist/Text.es.js +1 -3
  60. package/dist/Text.es.js.map +1 -1
  61. package/dist/components.cjs.js +0 -2
  62. package/dist/components.cjs.js.map +1 -1
  63. package/dist/components.es.js +0 -2
  64. package/dist/components.es.js.map +1 -1
  65. package/dist/controls.cjs.js +5 -6
  66. package/dist/controls.cjs.js.map +1 -1
  67. package/dist/controls.es.js +1 -2
  68. package/dist/controls.es.js.map +1 -1
  69. package/dist/index.cjs.js +49 -13
  70. package/dist/index.cjs.js.map +1 -1
  71. package/dist/index.cjs10.js +248 -171
  72. package/dist/index.cjs10.js.map +1 -1
  73. package/dist/index.cjs6.js +23 -700
  74. package/dist/index.cjs6.js.map +1 -1
  75. package/dist/index.cjs7.js +13 -37
  76. package/dist/index.cjs7.js.map +1 -1
  77. package/dist/index.cjs8.js +39 -17
  78. package/dist/index.cjs8.js.map +1 -1
  79. package/dist/index.cjs9.js +268 -15
  80. package/dist/index.cjs9.js.map +1 -1
  81. package/dist/index.es.js +42 -7
  82. package/dist/index.es.js.map +1 -1
  83. package/dist/index.es10.js +249 -172
  84. package/dist/index.es10.js.map +1 -1
  85. package/dist/index.es6.js +23 -695
  86. package/dist/index.es6.js.map +1 -1
  87. package/dist/index.es7.js +14 -33
  88. package/dist/index.es7.js.map +1 -1
  89. package/dist/index.es8.js +37 -17
  90. package/dist/index.es8.js.map +1 -1
  91. package/dist/index.es9.js +263 -14
  92. package/dist/index.es9.js.map +1 -1
  93. package/dist/leaf.es.js +1 -1
  94. package/dist/next.cjs.js +0 -2
  95. package/dist/next.cjs.js.map +1 -1
  96. package/dist/next.es.js +1 -3
  97. package/dist/next.es.js.map +1 -1
  98. package/dist/react-page.cjs.js +0 -1
  99. package/dist/react-page.cjs.js.map +1 -1
  100. package/dist/react-page.es.js +1 -2
  101. package/dist/react-page.es.js.map +1 -1
  102. package/dist/react.cjs.js +0 -2
  103. package/dist/react.cjs.js.map +1 -1
  104. package/dist/react.es.js +0 -2
  105. package/dist/react.es.js.map +1 -1
  106. package/dist/slate.cjs.js +257 -41
  107. package/dist/slate.cjs.js.map +1 -1
  108. package/dist/slate.es.js +249 -38
  109. package/dist/slate.es.js.map +1 -1
  110. package/dist/text-input.cjs.js +22 -0
  111. package/dist/text-input.cjs.js.map +1 -1
  112. package/dist/text-input.es.js +18 -1
  113. package/dist/text-input.es.js.map +1 -1
  114. package/dist/types/src/controls/icon-radio-group.d.ts +5 -2
  115. package/dist/types/src/controls/icon-radio-group.d.ts.map +1 -1
  116. package/dist/types/src/controls/style-v2.d.ts.map +1 -1
  117. package/dist/types/src/slate/InlinePlugin/getValue.d.ts +5 -0
  118. package/dist/types/src/slate/InlinePlugin/getValue.d.ts.map +1 -0
  119. package/dist/types/src/slate/InlinePlugin/index.d.ts +16 -0
  120. package/dist/types/src/slate/InlinePlugin/index.d.ts.map +1 -0
  121. package/dist/types/src/slate/InlinePlugin/onChange.d.ts +4 -0
  122. package/dist/types/src/slate/InlinePlugin/onChange.d.ts.map +1 -0
  123. package/dist/types/src/slate/InlinePlugin/types.d.ts +9 -0
  124. package/dist/types/src/slate/InlinePlugin/types.d.ts.map +1 -0
  125. package/dist/types/src/slate/LinkPlugin/getValue.d.ts +5 -0
  126. package/dist/types/src/slate/LinkPlugin/getValue.d.ts.map +1 -0
  127. package/dist/types/src/slate/LinkPlugin/index.d.ts +15 -0
  128. package/dist/types/src/slate/LinkPlugin/index.d.ts.map +1 -0
  129. package/dist/types/src/slate/LinkPlugin/onChange.d.ts +4 -0
  130. package/dist/types/src/slate/LinkPlugin/onChange.d.ts.map +1 -0
  131. package/dist/types/src/slate/LinkPlugin/types.d.ts +5 -0
  132. package/dist/types/src/slate/LinkPlugin/types.d.ts.map +1 -0
  133. package/dist/types/src/slate/TextAlignPlugin/index.d.ts +2 -0
  134. package/dist/types/src/slate/TextAlignPlugin/index.d.ts.map +1 -1
  135. package/dist/types/src/slate/index.d.ts +2 -0
  136. package/dist/types/src/slate/index.d.ts.map +1 -1
  137. package/dist/types.cjs2.js +753 -0
  138. package/dist/types.cjs2.js.map +1 -0
  139. package/dist/types.es2.js +736 -0
  140. package/dist/types.es2.js.map +1 -0
  141. package/package.json +1 -1
  142. package/dist/deepEqual.cjs.js +0 -40
  143. package/dist/deepEqual.cjs.js.map +0 -1
  144. package/dist/deepEqual.es.js +0 -39
  145. package/dist/deepEqual.es.js.map +0 -1
  146. package/dist/index.cjs11.js +0 -375
  147. package/dist/index.cjs11.js.map +0 -1
  148. package/dist/index.es11.js +0 -368
  149. package/dist/index.es11.js.map +0 -1
  150. package/dist/select.cjs.js +0 -21
  151. package/dist/select.cjs.js.map +0 -1
  152. package/dist/select.es.js +0 -16
  153. package/dist/select.es.js.map +0 -1
@@ -0,0 +1,753 @@
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 slate = require("slate");
22
+ var state_breakpoints = require("./state/breakpoints.cjs.js");
23
+ var reactPage = require("./react-page.cjs.js");
24
+ var textInput = require("./text-input.cjs.js");
25
+ var isHotkey = require("is-hotkey");
26
+ var css = require("@emotion/css");
27
+ var jsxRuntime = require("react/jsx-runtime");
28
+ require("react");
29
+ require("@emotion/serialize");
30
+ require("@emotion/utils");
31
+ function _interopDefaultLegacy(e) {
32
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
33
+ }
34
+ var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
35
+ const ElementUtils = {
36
+ isRootBlock(node) {
37
+ return slate.Element.isElement(node) && (slate.Element.isElementType(node, reactPage.BlockType.Paragraph) || slate.Element.isElementType(node, reactPage.BlockType.Heading1) || slate.Element.isElementType(node, reactPage.BlockType.Heading2) || slate.Element.isElementType(node, reactPage.BlockType.Heading3) || slate.Element.isElementType(node, reactPage.BlockType.Heading3) || slate.Element.isElementType(node, reactPage.BlockType.Heading4) || slate.Element.isElementType(node, reactPage.BlockType.Heading5) || slate.Element.isElementType(node, reactPage.BlockType.Heading6) || slate.Element.isElementType(node, reactPage.BlockType.BlockQuote) || slate.Element.isElementType(node, reactPage.BlockType.UnorderedList) || slate.Element.isElementType(node, reactPage.BlockType.OrderedList) || slate.Element.isElementType(node, reactPage.BlockType.Text) || slate.Element.isElementType(node, reactPage.BlockType.Default));
38
+ },
39
+ isBlock(node) {
40
+ return slate.Element.isElement(node) && (this.isRootBlock(node) || slate.Element.isElementType(node, reactPage.BlockType.ListItem) || slate.Element.isElementType(node, reactPage.BlockType.ListItemChild));
41
+ },
42
+ isInline(node) {
43
+ return slate.Element.isElementType(node, reactPage.InlineType.Code) || slate.Element.isElementType(node, reactPage.InlineType.Link) || slate.Element.isElementType(node, reactPage.InlineType.SubScript) || slate.Element.isElementType(node, reactPage.InlineType.SuperScript);
44
+ },
45
+ isConvertibleToListTextNode(node) {
46
+ return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
47
+ },
48
+ isList(node) {
49
+ return slate.Element.isElementType(node, reactPage.BlockType.OrderedList) || slate.Element.isElementType(node, reactPage.BlockType.UnorderedList);
50
+ },
51
+ isListItem(node) {
52
+ return slate.Element.isElementType(node, reactPage.BlockType.ListItem);
53
+ },
54
+ isListItemChild(node) {
55
+ return slate.Element.isElementType(node, reactPage.BlockType.ListItemChild);
56
+ },
57
+ createText() {
58
+ return { text: "" };
59
+ },
60
+ createParagraph() {
61
+ return {
62
+ children: [this.createText()],
63
+ type: reactPage.BlockType.Paragraph
64
+ };
65
+ },
66
+ createList(type = reactPage.BlockType.UnorderedList) {
67
+ return { children: [this.createText()], type };
68
+ },
69
+ createListItem() {
70
+ return {
71
+ children: [this.createListItemChild()],
72
+ type: reactPage.BlockType.ListItem
73
+ };
74
+ },
75
+ createListItemChild() {
76
+ return {
77
+ children: [this.createText()],
78
+ type: reactPage.BlockType.ListItemChild
79
+ };
80
+ }
81
+ };
82
+ function unhangRange(editor, range) {
83
+ let [start, end] = slate.Range.edges(range);
84
+ if (start.offset !== 0 || end.offset !== 0 || slate.Range.isCollapsed(range)) {
85
+ return range;
86
+ }
87
+ const endBlock = slate.Editor.above(editor, {
88
+ at: end,
89
+ match: (n) => slate.Element.isElement(n) && slate.Editor.isBlock(editor, n)
90
+ });
91
+ const blockPath = endBlock ? endBlock[1] : [];
92
+ const first = slate.Editor.start(editor, start);
93
+ const before = { anchor: first, focus: end };
94
+ let skip = true;
95
+ for (const [node, path] of slate.Editor.nodes(editor, {
96
+ at: before,
97
+ match: slate.Text.isText,
98
+ reverse: true
99
+ })) {
100
+ if (skip) {
101
+ skip = false;
102
+ continue;
103
+ }
104
+ if (node.text !== "" || slate.Path.isBefore(path, blockPath)) {
105
+ end = { path, offset: node.text.length };
106
+ break;
107
+ }
108
+ }
109
+ return { anchor: start, focus: end };
110
+ }
111
+ function getSelection(editor) {
112
+ if (editor.selection)
113
+ return unhangRange(editor, editor.selection);
114
+ return {
115
+ anchor: slate.Editor.start(editor, []),
116
+ focus: slate.Editor.end(editor, [])
117
+ };
118
+ }
119
+ function getBlocksInSelection(editor) {
120
+ return Array.from(slate.Editor.nodes(editor, {
121
+ at: getSelection(editor),
122
+ match: (node) => ElementUtils.isRootBlock(node)
123
+ })).filter((entry) => ElementUtils.isRootBlock(entry[0]));
124
+ }
125
+ function getActiveBlockType(editor) {
126
+ var _a;
127
+ const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type);
128
+ return rootBlocks.reduce((a, b) => a === b ? b : null, (_a = rootBlocks.at(0)) != null ? _a : null);
129
+ }
130
+ function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
131
+ var _a, _b;
132
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
133
+ if (!at)
134
+ return;
135
+ const rootElements = getBlocksInSelection(editor);
136
+ for (const [node, path] of rootElements) {
137
+ if (ElementUtils.isBlock(node)) {
138
+ const deviceValues = (_b = node[key]) != null ? _b : [];
139
+ const currentDeviceValue = state_breakpoints.findBreakpointOverride(breakpoints, deviceValues, deviceId, (v) => v);
140
+ const nextDeviceValue = __spreadProps(__spreadValues({}, currentDeviceValue), {
141
+ deviceId,
142
+ value
143
+ });
144
+ slate.Transforms.setNodes(editor, {
145
+ [key]: [...deviceValues.filter((v) => v.deviceId !== deviceId), nextDeviceValue]
146
+ }, { at: path });
147
+ }
148
+ }
149
+ }
150
+ function clearBlockKeyForDevice(editor, deviceId, key) {
151
+ var _a;
152
+ const rootElements = getBlocksInSelection(editor);
153
+ for (const [node, path] of rootElements) {
154
+ if (ElementUtils.isBlock(node)) {
155
+ const deviceOverrides = (_a = node[key]) != null ? _a : [];
156
+ slate.Transforms.setNodes(editor, {
157
+ [key]: deviceOverrides.filter((v) => v.deviceId !== deviceId)
158
+ }, { at: path });
159
+ }
160
+ }
161
+ }
162
+ function wrapInline(editor, inline) {
163
+ slate.Transforms.wrapNodes(editor, inline, {
164
+ at: getSelection(editor),
165
+ split: true
166
+ });
167
+ }
168
+ function unwrapInline(editor, type) {
169
+ slate.Transforms.unwrapNodes(editor, {
170
+ match: (node) => ElementUtils.isInline(node) && node.type === type,
171
+ at: getSelection(editor)
172
+ });
173
+ }
174
+ const EditorUtils = {
175
+ getFirstAncestorList(editor, path) {
176
+ try {
177
+ const parentList = slate.Editor.above(editor, {
178
+ at: path,
179
+ match: (node) => ElementUtils.isList(node)
180
+ });
181
+ return parentList != null ? parentList : null;
182
+ } catch (e) {
183
+ return null;
184
+ }
185
+ },
186
+ getFirstAncestorListItem(editor, path) {
187
+ try {
188
+ const parentListItem = slate.Editor.above(editor, {
189
+ at: path,
190
+ match: (node) => ElementUtils.isListItem(node)
191
+ });
192
+ return parentListItem != null ? parentListItem : null;
193
+ } catch (e) {
194
+ return null;
195
+ }
196
+ }
197
+ };
198
+ const LIST_ITEM_CHILD_POSITION = 0;
199
+ const LIST_ITEM_LIST_POSITION = 1;
200
+ function filterForSubtreeRoots(entries) {
201
+ return entries.filter(([, nodePath]) => !slate.Path.ancestors(nodePath).some((ancestor) => {
202
+ return entries.some(([, path]) => slate.Path.equals(path, ancestor));
203
+ }));
204
+ }
205
+ function unwrapPath(editor, listItemPath) {
206
+ const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
207
+ const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
208
+ if (!parentList || listItemContainingParentList)
209
+ return;
210
+ slate.Editor.withoutNormalizing(editor, () => {
211
+ const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
212
+ const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
213
+ if (slate.Node.has(editor, listItemNestedListPath)) {
214
+ slate.Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
215
+ slate.Transforms.liftNodes(editor, { at: listItemNestedListPath });
216
+ slate.Transforms.liftNodes(editor, { at: slate.Path.next(listItemPath) });
217
+ }
218
+ if (slate.Node.has(editor, listItemTextPath)) {
219
+ slate.Transforms.setNodes(editor, { type: reactPage.BlockType.Paragraph }, {
220
+ at: listItemTextPath
221
+ });
222
+ slate.Transforms.liftNodes(editor, { at: listItemTextPath });
223
+ slate.Transforms.liftNodes(editor, { at: listItemPath });
224
+ }
225
+ });
226
+ }
227
+ function unwrapList(editor, options) {
228
+ var _a;
229
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
230
+ if (!at)
231
+ return;
232
+ const listItems = Array.from(slate.Editor.nodes(editor, {
233
+ at,
234
+ match: (node) => {
235
+ return slate.Element.isElement(node) && ElementUtils.isListItem(node);
236
+ }
237
+ }));
238
+ const subRoots = filterForSubtreeRoots(listItems);
239
+ const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
240
+ refs.forEach((ref) => {
241
+ if (ref.current) {
242
+ unwrapPath(editor, ref.current);
243
+ }
244
+ ref.unref();
245
+ });
246
+ }
247
+ function wrapList(editor, options = { type: reactPage.BlockType.UnorderedList }) {
248
+ var _a;
249
+ const at = (_a = options.at) != null ? _a : editor.selection;
250
+ if (!at)
251
+ return;
252
+ const nonListEntries = Array.from(slate.Editor.nodes(editor, {
253
+ at,
254
+ match: (node) => {
255
+ return slate.Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
256
+ }
257
+ }));
258
+ const refs = nonListEntries.map(([_, path]) => slate.Editor.pathRef(editor, path));
259
+ refs.forEach((ref) => {
260
+ const path = ref.current;
261
+ if (path) {
262
+ slate.Editor.withoutNormalizing(editor, () => {
263
+ slate.Transforms.setNodes(editor, { type: reactPage.BlockType.ListItemChild }, {
264
+ at: path
265
+ });
266
+ slate.Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
267
+ match: (node) => ElementUtils.isListItemChild(node),
268
+ at: path
269
+ });
270
+ slate.Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
271
+ at: path
272
+ });
273
+ });
274
+ }
275
+ ref.unref();
276
+ });
277
+ }
278
+ const LocationUtils = {
279
+ getStartPath(location) {
280
+ if (slate.Range.isRange(location))
281
+ return slate.Range.start(location).path;
282
+ if (slate.Point.isPoint(location))
283
+ return location.path;
284
+ return location;
285
+ }
286
+ };
287
+ function getSelectedListItems(editor) {
288
+ var _a, _b;
289
+ if (!editor.selection)
290
+ return [];
291
+ const start = LocationUtils.getStartPath(editor.selection);
292
+ const listItems = slate.Editor.nodes(editor, {
293
+ at: editor.selection,
294
+ match: (node) => ElementUtils.isListItem(node)
295
+ });
296
+ const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
297
+ return Array.from(listItems).filter((node) => slate.Path.isDescendant(start, node[1]) ? slate.Path.equals(node[1], firstAncestorPath) : !slate.Path.isAfter(start, node[1]));
298
+ }
299
+ function indentPath(editor, path) {
300
+ const parent = slate.Node.parent(editor, path);
301
+ if (!path || !slate.Path.hasPrevious(path) || !ElementUtils.isList(parent))
302
+ return;
303
+ const previosPath = slate.Path.previous(path);
304
+ const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION];
305
+ const previousHasChildList = slate.Node.has(editor, previousChildListPath);
306
+ slate.Editor.withoutNormalizing(editor, () => {
307
+ if (!previousHasChildList) {
308
+ slate.Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {
309
+ at: previousChildListPath
310
+ });
311
+ }
312
+ const previousChildList = slate.Node.get(editor, previousChildListPath);
313
+ if (ElementUtils.isList(previousChildList)) {
314
+ const index = previousHasChildList ? previousChildList.children.length : 0;
315
+ slate.Transforms.moveNodes(editor, {
316
+ at: path,
317
+ to: [...previousChildListPath, index]
318
+ });
319
+ }
320
+ });
321
+ }
322
+ function indent(editor) {
323
+ if (!editor.selection)
324
+ return;
325
+ const listItems = getSelectedListItems(editor);
326
+ const subRoots = filterForSubtreeRoots(listItems);
327
+ const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
328
+ refs.forEach((ref) => {
329
+ if (ref.current) {
330
+ indentPath(editor, ref.current);
331
+ }
332
+ ref.unref();
333
+ });
334
+ }
335
+ function dedentPath(editor, listItemPath) {
336
+ const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
337
+ const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
338
+ if (!parentList || !listItemContainingParentList)
339
+ return;
340
+ const [parentListNode, parentListPath] = parentList;
341
+ const [_, listItemContainingParentListPath] = listItemContainingParentList;
342
+ const listItemPosition = listItemPath[listItemPath.length - 1];
343
+ const previousSiblings = parentListNode.children.slice(0, listItemPosition);
344
+ const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
345
+ slate.Editor.withoutNormalizing(editor, () => {
346
+ nextSiblings.forEach(() => {
347
+ const nextSiblingPath = [...parentListPath, listItemPosition + 1];
348
+ indentPath(editor, nextSiblingPath);
349
+ });
350
+ slate.Transforms.moveNodes(editor, {
351
+ at: listItemPath,
352
+ to: slate.Path.next(listItemContainingParentListPath)
353
+ });
354
+ if (previousSiblings.length === 0) {
355
+ slate.Transforms.removeNodes(editor, { at: parentListPath });
356
+ }
357
+ });
358
+ }
359
+ function dedent(editor) {
360
+ if (!editor.selection)
361
+ return;
362
+ const listItems = getSelectedListItems(editor);
363
+ const subRoots = filterForSubtreeRoots(listItems);
364
+ const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
365
+ refs.forEach((ref) => {
366
+ if (ref.current) {
367
+ dedentPath(editor, ref.current);
368
+ }
369
+ ref.unref();
370
+ });
371
+ }
372
+ function toggleList(editor, options = { type: reactPage.BlockType.UnorderedList }) {
373
+ var _a;
374
+ const at = (_a = options.at) != null ? _a : editor.selection;
375
+ if (at == null)
376
+ return;
377
+ const start = LocationUtils.getStartPath(at);
378
+ const ancestorPath = slate.Path.ancestors(start).at(1);
379
+ if (!ancestorPath || !slate.Node.has(editor, ancestorPath))
380
+ return;
381
+ const ancestor = slate.Node.get(editor, ancestorPath);
382
+ if (!ElementUtils.isList(ancestor)) {
383
+ return wrapList(editor, { type: options.type, at });
384
+ }
385
+ if (ancestor.type === options.type) {
386
+ unwrapList(editor, { at });
387
+ } else {
388
+ slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
389
+ }
390
+ }
391
+ const BlockActions = {
392
+ setBlockKeyForDevice,
393
+ clearBlockKeyForDevice,
394
+ wrapInline,
395
+ unwrapInline
396
+ };
397
+ const ListActions = {
398
+ unwrapList,
399
+ wrapList,
400
+ indent,
401
+ dedent,
402
+ toggleList
403
+ };
404
+ function onKeyDown(e, editor) {
405
+ if (!editor.selection || Array.from(slate.Editor.nodes(editor, {
406
+ match: (node) => ElementUtils.isListItem(node)
407
+ })).length === 0)
408
+ return;
409
+ if (isHotkey__default["default"]("shift+tab", e)) {
410
+ e.preventDefault();
411
+ ListActions.dedent(editor);
412
+ }
413
+ if (isHotkey__default["default"]("tab", e)) {
414
+ e.preventDefault();
415
+ ListActions.indent(editor);
416
+ }
417
+ if (isHotkey__default["default"]("backspace", e)) {
418
+ if (!editor.selection)
419
+ return;
420
+ if (slate.Range.isExpanded(editor.selection))
421
+ return;
422
+ const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
423
+ if (editor.selection.anchor.offset === 0 && listItem) {
424
+ e.preventDefault();
425
+ const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
426
+ const list = EditorUtils.getFirstAncestorList(editor, listItem[1]);
427
+ if (parentListItem) {
428
+ ListActions.dedent(editor);
429
+ } else if (list) {
430
+ ListActions.unwrapList(editor);
431
+ }
432
+ return;
433
+ }
434
+ }
435
+ if (isHotkey__default["default"]("enter", e)) {
436
+ e.preventDefault();
437
+ if (!editor.selection)
438
+ return;
439
+ if (slate.Range.isExpanded(editor.selection)) {
440
+ slate.Transforms.delete(editor);
441
+ return;
442
+ }
443
+ const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
444
+ if (editor.selection.anchor.offset === 0 && listItem && slate.Editor.string(editor, listItem[1]) === "") {
445
+ const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
446
+ if (parentListItem) {
447
+ ListActions.dedent(editor);
448
+ } else {
449
+ ListActions.unwrapList(editor);
450
+ }
451
+ return;
452
+ }
453
+ slate.Transforms.splitNodes(editor, {
454
+ at: editor.selection,
455
+ always: true,
456
+ match: (node) => ElementUtils.isListItem(node)
457
+ });
458
+ }
459
+ if (isHotkey__default["default"]("shift+enter", e)) {
460
+ e.preventDefault();
461
+ editor.insertText("\n");
462
+ }
463
+ }
464
+ function withBlock(editor) {
465
+ const {
466
+ normalizeNode
467
+ } = editor;
468
+ editor.isInline = (entry) => {
469
+ return ElementUtils.isInline(entry);
470
+ };
471
+ editor.normalizeNode = (entry) => {
472
+ var _a;
473
+ const [normalizationNode, normalizationPath] = entry;
474
+ if (ElementUtils.isBlock(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.textAlign) == null ? void 0 : _a.length) == 0) {
475
+ slate.Transforms.unsetNodes(editor, "textAlign", {
476
+ at: normalizationPath
477
+ });
478
+ return;
479
+ }
480
+ if (ElementUtils.isListItem(normalizationNode)) {
481
+ const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION];
482
+ if (slate.Node.has(editor, pathToListItemText)) {
483
+ const nodeInListItemTextPosition = slate.Node.get(editor, pathToListItemText);
484
+ if (ElementUtils.isRootBlock(nodeInListItemTextPosition)) {
485
+ slate.Transforms.setNodes(editor, {
486
+ type: reactPage.BlockType.ListItemChild
487
+ }, {
488
+ at: pathToListItemText
489
+ });
490
+ return;
491
+ }
492
+ } else {
493
+ slate.Transforms.insertNodes(editor, ElementUtils.createListItem(), {
494
+ at: pathToListItemText
495
+ });
496
+ return;
497
+ }
498
+ }
499
+ if (!slate.Text.isText(normalizationNode)) {
500
+ const mergeableChildren = Array.from(slate.Node.children(editor, normalizationPath)).map((child, index, children) => {
501
+ const potentialNodeToBeMerged = children.at(index + 1);
502
+ if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || !ElementUtils.isList(child[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
503
+ return null;
504
+ }
505
+ return [slate.Editor.pathRef(editor, child[1]), slate.Editor.pathRef(editor, potentialNodeToBeMerged[1])];
506
+ }).filter((mergeableNodes) => Boolean(mergeableNodes));
507
+ if (mergeableChildren.length !== 0) {
508
+ mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {
509
+ const nodePath = nodePathRef.current;
510
+ const nodeToBeMergedPath = nodeToBeMergedPathRef.current;
511
+ if (nodePath == null || nodeToBeMergedPath == null)
512
+ return;
513
+ const nodeChildren = Array.from(slate.Node.children(editor, nodePath));
514
+ const childrenToBeMerged = Array.from(slate.Node.children(editor, nodeToBeMergedPath));
515
+ slate.Editor.withoutNormalizing(editor, () => {
516
+ childrenToBeMerged.reverse().forEach(([_, childPath]) => {
517
+ slate.Transforms.moveNodes(editor, {
518
+ at: childPath,
519
+ to: [...nodePath, nodeChildren.length]
520
+ });
521
+ });
522
+ slate.Transforms.removeNodes(editor, {
523
+ at: nodeToBeMergedPath
524
+ });
525
+ });
526
+ nodePathRef.unref();
527
+ nodeToBeMergedPathRef.unref();
528
+ });
529
+ return;
530
+ }
531
+ }
532
+ normalizeNode(entry);
533
+ };
534
+ return editor;
535
+ }
536
+ const definition = textInput.Select({
537
+ label: "Block",
538
+ labelOrientation: "horizontal",
539
+ options: [{
540
+ value: reactPage.BlockType.Paragraph,
541
+ label: "Paragraph"
542
+ }, {
543
+ value: reactPage.BlockType.Heading1,
544
+ label: "Heading 1"
545
+ }, {
546
+ value: reactPage.BlockType.Heading2,
547
+ label: "Heading 2"
548
+ }, {
549
+ value: reactPage.BlockType.Heading3,
550
+ label: "Heading 3"
551
+ }, {
552
+ value: reactPage.BlockType.Heading4,
553
+ label: "Heading 4"
554
+ }, {
555
+ value: reactPage.BlockType.Heading5,
556
+ label: "Heading 5"
557
+ }, {
558
+ value: reactPage.BlockType.Heading6,
559
+ label: "Heading 6"
560
+ }, {
561
+ value: reactPage.BlockType.UnorderedList,
562
+ label: "Bulleted list"
563
+ }, {
564
+ value: reactPage.BlockType.OrderedList,
565
+ label: "Numbered list"
566
+ }, {
567
+ value: reactPage.BlockType.BlockQuote,
568
+ label: "Quote"
569
+ }],
570
+ defaultValue: reactPage.BlockType.Paragraph
571
+ });
572
+ function BlockPlugin() {
573
+ return reactPage.createRichTextV2Plugin({
574
+ withPlugin: withBlock,
575
+ onKeyDown,
576
+ control: {
577
+ definition,
578
+ onChange: (editor, value) => {
579
+ const activeBlockType = getActiveBlockType(editor);
580
+ if (value === reactPage.BlockType.UnorderedList || value === reactPage.BlockType.OrderedList) {
581
+ ListActions.toggleList(editor, {
582
+ type: value,
583
+ at: getSelection(editor)
584
+ });
585
+ } else if (activeBlockType === value) {
586
+ slate.Transforms.setNodes(editor, {
587
+ type: reactPage.BlockType.Default
588
+ }, {
589
+ at: getSelection(editor)
590
+ });
591
+ } else {
592
+ ListActions.unwrapList(editor, {
593
+ at: getSelection(editor)
594
+ });
595
+ slate.Transforms.setNodes(editor, {
596
+ type: value != null ? value : reactPage.BlockType.Default
597
+ }, {
598
+ at: getSelection(editor)
599
+ });
600
+ }
601
+ },
602
+ getValue: (editor) => {
603
+ const activeBlock = getActiveBlockType(editor);
604
+ if (activeBlock === reactPage.RootBlockType.Text || activeBlock === reactPage.RootBlockType.Default)
605
+ return void 0;
606
+ return activeBlock;
607
+ }
608
+ },
609
+ renderElement: (renderElement) => (props) => /* @__PURE__ */ jsxRuntime.jsx(BlockPluginComponent, __spreadProps(__spreadValues({}, props), {
610
+ renderElement
611
+ }))
612
+ });
613
+ }
614
+ function BlockPluginComponent({
615
+ element,
616
+ attributes,
617
+ children,
618
+ renderElement
619
+ }) {
620
+ const blockStyles = [reactPage.useStyle({
621
+ margin: 0
622
+ }), element.className];
623
+ const quoteStyles = reactPage.useStyle({
624
+ padding: "0.5em 10px",
625
+ fontSize: "1.25em",
626
+ fontWeight: "300",
627
+ borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
628
+ });
629
+ switch (element.type) {
630
+ case reactPage.BlockType.Text:
631
+ return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
632
+ className: css.cx(...blockStyles),
633
+ children
634
+ }));
635
+ case reactPage.BlockType.Paragraph:
636
+ return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
637
+ className: css.cx(...blockStyles),
638
+ children
639
+ }));
640
+ case reactPage.BlockType.Heading1:
641
+ return /* @__PURE__ */ jsxRuntime.jsx("h1", __spreadProps(__spreadValues({}, attributes), {
642
+ className: css.cx(...blockStyles),
643
+ children
644
+ }));
645
+ case reactPage.BlockType.Heading2:
646
+ return /* @__PURE__ */ jsxRuntime.jsx("h2", __spreadProps(__spreadValues({}, attributes), {
647
+ className: css.cx(...blockStyles),
648
+ children
649
+ }));
650
+ case reactPage.BlockType.Heading3:
651
+ return /* @__PURE__ */ jsxRuntime.jsx("h3", __spreadProps(__spreadValues({}, attributes), {
652
+ className: css.cx(...blockStyles),
653
+ children
654
+ }));
655
+ case reactPage.BlockType.Heading4:
656
+ return /* @__PURE__ */ jsxRuntime.jsx("h4", __spreadProps(__spreadValues({}, attributes), {
657
+ className: css.cx(...blockStyles),
658
+ children
659
+ }));
660
+ case reactPage.BlockType.Heading5:
661
+ return /* @__PURE__ */ jsxRuntime.jsx("h5", __spreadProps(__spreadValues({}, attributes), {
662
+ className: css.cx(...blockStyles),
663
+ children
664
+ }));
665
+ case reactPage.BlockType.Heading6:
666
+ return /* @__PURE__ */ jsxRuntime.jsx("h6", __spreadProps(__spreadValues({}, attributes), {
667
+ className: css.cx(...blockStyles),
668
+ children
669
+ }));
670
+ case reactPage.BlockType.BlockQuote:
671
+ return /* @__PURE__ */ jsxRuntime.jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
672
+ className: css.cx(...blockStyles, quoteStyles),
673
+ children
674
+ }));
675
+ case reactPage.BlockType.OrderedList:
676
+ return /* @__PURE__ */ jsxRuntime.jsx("ol", __spreadProps(__spreadValues({}, attributes), {
677
+ className: css.cx(...blockStyles),
678
+ style: {
679
+ listStylePosition: "inside"
680
+ },
681
+ children
682
+ }));
683
+ case reactPage.BlockType.UnorderedList:
684
+ return /* @__PURE__ */ jsxRuntime.jsx("ul", __spreadProps(__spreadValues({}, attributes), {
685
+ className: css.cx(...blockStyles),
686
+ style: {
687
+ listStylePosition: "inside"
688
+ },
689
+ children
690
+ }));
691
+ case reactPage.BlockType.ListItem:
692
+ return /* @__PURE__ */ jsxRuntime.jsx("li", __spreadProps(__spreadValues({}, attributes), {
693
+ className: css.cx(...blockStyles),
694
+ children
695
+ }));
696
+ case reactPage.BlockType.ListItemChild:
697
+ return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
698
+ className: css.cx(...blockStyles),
699
+ children
700
+ }));
701
+ case reactPage.BlockType.Default:
702
+ return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
703
+ className: css.cx(...blockStyles),
704
+ children
705
+ }));
706
+ default:
707
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
708
+ children: renderElement({
709
+ element,
710
+ attributes,
711
+ children
712
+ })
713
+ });
714
+ }
715
+ }
716
+ const supportedInlineOptions = [
717
+ {
718
+ icon: textInput.unstable_IconRadioGroupIcon.Superscript,
719
+ label: "Superscript",
720
+ value: "superscript"
721
+ },
722
+ {
723
+ icon: textInput.unstable_IconRadioGroupIcon.Subscript,
724
+ label: "Subscript",
725
+ value: "subscript"
726
+ },
727
+ {
728
+ icon: textInput.unstable_IconRadioGroupIcon.Code,
729
+ label: "Code",
730
+ value: "code"
731
+ }
732
+ ];
733
+ function isSupportedInlineType(inline) {
734
+ return supportedInlineOptions.findIndex((option) => option.value === inline) !== -1;
735
+ }
736
+ function isSupportedInlineEntry(entry) {
737
+ const node = entry[0];
738
+ return ElementUtils.isInline(node) && supportedInlineOptions.findIndex((option) => option.value === node.type) !== -1;
739
+ }
740
+ exports.BlockActions = BlockActions;
741
+ exports.BlockPlugin = BlockPlugin;
742
+ exports.ElementUtils = ElementUtils;
743
+ exports.ListActions = ListActions;
744
+ exports.filterForSubtreeRoots = filterForSubtreeRoots;
745
+ exports.getSelection = getSelection;
746
+ exports.isSupportedInlineEntry = isSupportedInlineEntry;
747
+ exports.isSupportedInlineType = isSupportedInlineType;
748
+ exports.onKeyDown = onKeyDown;
749
+ exports.supportedInlineOptions = supportedInlineOptions;
750
+ exports.unwrapInline = unwrapInline;
751
+ exports.withBlock = withBlock;
752
+ exports.wrapInline = wrapInline;
753
+ //# sourceMappingURL=types.cjs2.js.map