@makeswift/runtime 0.9.0 → 0.9.2

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