@makeswift/runtime 0.9.12 → 0.10.0

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