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