@makeswift/runtime 0.8.8 → 0.8.10

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 (251) hide show
  1. package/dist/Box.cjs.js +1 -2
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +1 -2
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +1 -2
  6. package/dist/Button.cjs.js.map +1 -1
  7. package/dist/Button.es.js +1 -2
  8. package/dist/Button.es.js.map +1 -1
  9. package/dist/Carousel.cjs.js +1 -2
  10. package/dist/Carousel.cjs.js.map +1 -1
  11. package/dist/Carousel.es.js +1 -2
  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 +1 -2
  18. package/dist/Divider.cjs.js.map +1 -1
  19. package/dist/Divider.es.js +1 -2
  20. package/dist/Divider.es.js.map +1 -1
  21. package/dist/Embed.cjs.js +1 -2
  22. package/dist/Embed.cjs.js.map +1 -1
  23. package/dist/Embed.es.js +1 -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 +1 -2
  34. package/dist/LiveProvider.cjs.js.map +1 -1
  35. package/dist/LiveProvider.es.js +1 -2
  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 +68 -56
  46. package/dist/ReadOnlyText.cjs.js.map +1 -1
  47. package/dist/ReadOnlyText.es.js +17 -5
  48. package/dist/ReadOnlyText.es.js.map +1 -1
  49. package/dist/ReadOnlyTextV2.cjs.js +318 -0
  50. package/dist/ReadOnlyTextV2.cjs.js.map +1 -0
  51. package/dist/ReadOnlyTextV2.es.js +314 -0
  52. package/dist/ReadOnlyTextV2.es.js.map +1 -0
  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 +1 -2
  58. package/dist/SocialLinks.cjs.js.map +1 -1
  59. package/dist/SocialLinks.es.js +1 -2
  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 +1 -2
  66. package/dist/Video.cjs.js.map +1 -1
  67. package/dist/Video.es.js +1 -2
  68. package/dist/Video.es.js.map +1 -1
  69. package/dist/actions.cjs.js.map +1 -1
  70. package/dist/actions.es.js.map +1 -1
  71. package/dist/builder.cjs.js +1 -2
  72. package/dist/builder.cjs.js.map +1 -1
  73. package/dist/builder.es.js +1 -2
  74. package/dist/builder.es.js.map +1 -1
  75. package/dist/components.cjs.js +1 -2
  76. package/dist/components.cjs.js.map +1 -1
  77. package/dist/components.es.js +1 -2
  78. package/dist/components.es.js.map +1 -1
  79. package/dist/constants.cjs.js.map +1 -1
  80. package/dist/constants.es.js.map +1 -1
  81. package/dist/control-serialization.cjs.js +0 -2
  82. package/dist/control-serialization.cjs.js.map +1 -1
  83. package/dist/control-serialization.es.js +0 -2
  84. package/dist/control-serialization.es.js.map +1 -1
  85. package/dist/controls.cjs.js +6 -6
  86. package/dist/controls.es.js +2 -3
  87. package/dist/controls.es.js.map +1 -1
  88. package/dist/descriptors.cjs.js +112 -87
  89. package/dist/descriptors.cjs.js.map +1 -1
  90. package/dist/descriptors.es.js +87 -63
  91. package/dist/descriptors.es.js.map +1 -1
  92. package/dist/element.cjs.js +55 -0
  93. package/dist/element.cjs.js.map +1 -0
  94. package/dist/element.es.js +54 -0
  95. package/dist/element.es.js.map +1 -0
  96. package/dist/index.cjs.js +35 -6
  97. package/dist/index.cjs.js.map +1 -1
  98. package/dist/index.cjs2.js +0 -2
  99. package/dist/index.cjs2.js.map +1 -1
  100. package/dist/index.cjs5.js +48 -82
  101. package/dist/index.cjs5.js.map +1 -1
  102. package/dist/index.cjs6.js +41 -40
  103. package/dist/index.cjs6.js.map +1 -1
  104. package/dist/index.cjs7.js +14 -336
  105. package/dist/index.cjs7.js.map +1 -1
  106. package/dist/index.cjs8.js +209 -0
  107. package/dist/index.cjs8.js.map +1 -0
  108. package/dist/index.cjs9.js +370 -0
  109. package/dist/index.cjs9.js.map +1 -0
  110. package/dist/index.es.js +32 -7
  111. package/dist/index.es.js.map +1 -1
  112. package/dist/index.es2.js +0 -2
  113. package/dist/index.es2.js.map +1 -1
  114. package/dist/index.es5.js +19 -54
  115. package/dist/index.es5.js.map +1 -1
  116. package/dist/index.es6.js +36 -38
  117. package/dist/index.es6.js.map +1 -1
  118. package/dist/index.es7.js +13 -331
  119. package/dist/index.es7.js.map +1 -1
  120. package/dist/index.es8.js +202 -0
  121. package/dist/index.es8.js.map +1 -0
  122. package/dist/index.es9.js +363 -0
  123. package/dist/index.es9.js.map +1 -0
  124. package/dist/introspection.cjs.js +0 -2
  125. package/dist/introspection.cjs.js.map +1 -1
  126. package/dist/introspection.es.js +0 -2
  127. package/dist/introspection.es.js.map +1 -1
  128. package/dist/leaf.cjs.js.map +1 -1
  129. package/dist/leaf.es.js.map +1 -1
  130. package/dist/main.cjs.js +1 -2
  131. package/dist/main.cjs.js.map +1 -1
  132. package/dist/main.es.js +1 -2
  133. package/dist/main.es.js.map +1 -1
  134. package/dist/next.cjs.js +1 -2
  135. package/dist/next.cjs.js.map +1 -1
  136. package/dist/next.es.js +1 -2
  137. package/dist/next.es.js.map +1 -1
  138. package/dist/prop-controllers.cjs.js +1 -2
  139. package/dist/prop-controllers.cjs.js.map +1 -1
  140. package/dist/prop-controllers.es.js +1 -2
  141. package/dist/prop-controllers.es.js.map +1 -1
  142. package/dist/react.cjs.js +1 -2
  143. package/dist/react.cjs.js.map +1 -1
  144. package/dist/react.es.js +1 -2
  145. package/dist/react.es.js.map +1 -1
  146. package/dist/slate.cjs.js +8 -3
  147. package/dist/slate.cjs.js.map +1 -1
  148. package/dist/slate.cjs2.js +46 -0
  149. package/dist/slate.cjs2.js.map +1 -0
  150. package/dist/slate.es.js +6 -4
  151. package/dist/slate.es.js.map +1 -1
  152. package/dist/slate.es2.js +44 -0
  153. package/dist/slate.es2.js.map +1 -0
  154. package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
  155. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  156. package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -1
  157. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +2 -1
  158. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  159. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts +1 -1
  160. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -1
  161. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts +1 -1
  162. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts.map +1 -1
  163. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +1 -1
  164. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  165. package/dist/types/src/controls/control.d.ts +2 -1
  166. package/dist/types/src/controls/control.d.ts.map +1 -1
  167. package/dist/types/src/controls/index.d.ts +1 -0
  168. package/dist/types/src/controls/index.d.ts.map +1 -1
  169. package/dist/types/src/controls/list.d.ts +2 -1
  170. package/dist/types/src/controls/list.d.ts.map +1 -1
  171. package/dist/types/src/controls/rich-text/dto-types.d.ts +1 -1
  172. package/dist/types/src/controls/rich-text/dto-types.d.ts.map +1 -1
  173. package/dist/types/src/controls/rich-text/index.d.ts +0 -1
  174. package/dist/types/src/controls/rich-text/index.d.ts.map +1 -1
  175. package/dist/types/src/controls/rich-text/rich-text.d.ts +1 -1
  176. package/dist/types/src/controls/rich-text/rich-text.d.ts.map +1 -1
  177. package/dist/types/src/controls/rich-text/translation.d.ts +1 -1
  178. package/dist/types/src/controls/rich-text/translation.d.ts.map +1 -1
  179. package/dist/types/src/controls/rich-text-v2/index.d.ts +2 -0
  180. package/dist/types/src/controls/rich-text-v2/index.d.ts.map +1 -0
  181. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +79 -0
  182. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -0
  183. package/dist/types/src/controls/shape.d.ts +2 -1
  184. package/dist/types/src/controls/shape.d.ts.map +1 -1
  185. package/dist/types/src/controls/slot.d.ts +1 -1
  186. package/dist/types/src/controls/slot.d.ts.map +1 -1
  187. package/dist/types/src/controls/style.d.ts +2 -1
  188. package/dist/types/src/controls/style.d.ts.map +1 -1
  189. package/dist/types/src/prop-controllers/base.d.ts +7 -0
  190. package/dist/types/src/prop-controllers/base.d.ts.map +1 -0
  191. package/dist/types/src/prop-controllers/descriptors.d.ts +4 -3
  192. package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
  193. package/dist/types/src/prop-controllers/instances.d.ts +6 -8
  194. package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
  195. package/dist/types/src/runtimes/react/controls/control.d.ts +3 -2
  196. package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
  197. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts +13 -0
  198. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -0
  199. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts +4 -0
  200. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts.map +1 -0
  201. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.d.ts +9 -0
  202. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.d.ts.map +1 -0
  203. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +21 -0
  204. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -0
  205. package/dist/types/src/runtimes/react/controls/rich-text-v2/index.d.ts +2 -0
  206. package/dist/types/src/runtimes/react/controls/rich-text-v2/index.d.ts.map +1 -0
  207. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +8 -0
  208. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -0
  209. package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
  210. package/dist/types/src/slate/BlockPlugin/index.d.ts +1 -1
  211. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
  212. package/dist/types/src/slate/BlockPlugin/types.d.ts +1 -1
  213. package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -1
  214. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts +1 -1
  215. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts.map +1 -1
  216. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts +1 -1
  217. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts.map +1 -1
  218. package/dist/types/src/slate/BuilderPlugin/index.d.ts +7 -0
  219. package/dist/types/src/slate/BuilderPlugin/index.d.ts.map +1 -0
  220. package/dist/types/src/slate/InlineModePlugin/index.d.ts +5 -0
  221. package/dist/types/src/slate/InlineModePlugin/index.d.ts.map +1 -0
  222. package/dist/types/src/slate/ListPlugin/index.d.ts +1 -1
  223. package/dist/types/src/slate/ListPlugin/index.d.ts.map +1 -1
  224. package/dist/types/src/slate/ListPlugin/toggleList.d.ts +1 -1
  225. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -1
  226. package/dist/types/src/slate/ListPlugin/wrapList.d.ts +1 -1
  227. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -1
  228. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +1 -1
  229. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -1
  230. package/dist/types/src/slate/TypographyPlugin/index.d.ts +1 -1
  231. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  232. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  233. package/dist/types/src/slate/index.d.ts +2 -0
  234. package/dist/types/src/slate/index.d.ts.map +1 -1
  235. package/dist/types/src/slate/selectors.d.ts +1 -1
  236. package/dist/types/src/slate/selectors.d.ts.map +1 -1
  237. package/dist/types/src/slate/utils/editor.d.ts +1 -1
  238. package/dist/types/src/slate/utils/editor.d.ts.map +1 -1
  239. package/dist/types/src/slate/utils/element.d.ts +1 -1
  240. package/dist/types/src/slate/utils/element.d.ts.map +1 -1
  241. package/dist/types/src/state/actions.d.ts +2 -1
  242. package/dist/types/src/state/actions.d.ts.map +1 -1
  243. package/dist/types/src/state/modules/prop-controller-handles.d.ts +2 -1
  244. package/dist/types/src/state/modules/prop-controller-handles.d.ts.map +1 -1
  245. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  246. package/dist/types/src/state/react-page.d.ts +1 -1
  247. package/dist/types/src/state/react-page.d.ts.map +1 -1
  248. package/dist/types/{src/controls/rich-text/types.d.ts → types/slate.d.ts} +28 -18
  249. package/dist/types/types/slate.d.ts.map +1 -0
  250. package/package.json +2 -1
  251. package/dist/types/src/controls/rich-text/types.d.ts.map +0 -1
@@ -1,64 +1,28 @@
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));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source)
24
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
- target[prop] = source[prop];
26
- if (source != null && __getOwnPropSymbols)
27
- for (var prop of __getOwnPropSymbols(source)) {
28
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
- target[prop] = source[prop];
30
- }
31
- return target;
32
- };
33
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
34
- var React = require("react");
35
- var slate = require("slate");
36
- var slateReact = require("slate-react");
37
- var css = require("@emotion/css");
38
- var boxModels = require("./box-models.cjs.js");
39
- var descriptors = require("./descriptors.cjs.js");
40
- var leaf = require("./leaf.cjs.js");
41
- var next = require("./index.cjs.js");
42
- var jsxRuntime = require("react/jsx-runtime");
43
- var index = require("./index.cjs3.js");
44
- var isHotkey = require("is-hotkey");
45
- var index$1 = require("./index.cjs5.js");
46
- var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
47
- require("css-box-model");
48
- require("./actions.cjs.js");
49
- require("./introspection.cjs.js");
50
- require("./state/breakpoints.cjs.js");
51
- require("use-sync-external-store/shim/with-selector");
3
+ var Text = require("./Text.cjs.js");
52
4
  require("next/dynamic");
5
+ require("react");
6
+ require("./index.cjs.js");
7
+ require("use-sync-external-store/shim/with-selector");
53
8
  require("./constants.cjs.js");
54
9
  require("redux");
55
10
  require("redux-thunk");
11
+ require("./actions.cjs.js");
12
+ require("./descriptors.cjs.js");
13
+ require("./slate.cjs2.js");
14
+ require("./state/breakpoints.cjs.js");
15
+ require("./introspection.cjs.js");
16
+ require("@emotion/css");
56
17
  require("@emotion/serialize");
57
18
  require("@emotion/utils");
19
+ require("react/jsx-runtime");
58
20
  require("./text-input.cjs.js");
59
21
  require("./combobox.cjs.js");
60
22
  require("use-sync-external-store/shim");
61
23
  require("./types.cjs.js");
24
+ require("./box-models.cjs.js");
25
+ require("css-box-model");
62
26
  require("color");
63
27
  require("scroll-into-view-if-needed");
64
28
  require("react-dom");
@@ -73,291 +37,5 @@ require("http-proxy");
73
37
  require("set-cookie-parser");
74
38
  require("uuid");
75
39
  require("corporate-ipsum");
76
- require("next/link");
77
- function _interopDefaultLegacy(e) {
78
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
79
- }
80
- var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
81
- function BlockElement({
82
- element,
83
- attributes,
84
- children
85
- }) {
86
- const blockStyles = [next.useStyle({
87
- margin: 0
88
- }), next.useStyle(next.useResponsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
89
- textAlign
90
- })))];
91
- switch (element.type) {
92
- case descriptors.BlockType.Paragraph:
93
- return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
94
- className: css.cx(...blockStyles),
95
- children
96
- }));
97
- case descriptors.BlockType.Heading1:
98
- return /* @__PURE__ */ jsxRuntime.jsx("h1", __spreadProps(__spreadValues({}, attributes), {
99
- className: css.cx(...blockStyles),
100
- children
101
- }));
102
- case descriptors.BlockType.Heading2:
103
- return /* @__PURE__ */ jsxRuntime.jsx("h2", __spreadProps(__spreadValues({}, attributes), {
104
- className: css.cx(...blockStyles),
105
- children
106
- }));
107
- case descriptors.BlockType.Heading3:
108
- return /* @__PURE__ */ jsxRuntime.jsx("h3", __spreadProps(__spreadValues({}, attributes), {
109
- className: css.cx(...blockStyles),
110
- children
111
- }));
112
- case descriptors.BlockType.Heading4:
113
- return /* @__PURE__ */ jsxRuntime.jsx("h4", __spreadProps(__spreadValues({}, attributes), {
114
- className: css.cx(...blockStyles),
115
- children
116
- }));
117
- case descriptors.BlockType.Heading5:
118
- return /* @__PURE__ */ jsxRuntime.jsx("h5", __spreadProps(__spreadValues({}, attributes), {
119
- className: css.cx(...blockStyles),
120
- children
121
- }));
122
- case descriptors.BlockType.Heading6:
123
- return /* @__PURE__ */ jsxRuntime.jsx("h6", __spreadProps(__spreadValues({}, attributes), {
124
- className: css.cx(...blockStyles),
125
- children
126
- }));
127
- case descriptors.BlockType.BlockQuote:
128
- return /* @__PURE__ */ jsxRuntime.jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
129
- className: css.cx(...blockStyles, next.useStyle({
130
- padding: "0.5em 10px",
131
- fontSize: "1.25em",
132
- fontWeight: "300",
133
- borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
134
- })),
135
- children
136
- }));
137
- case descriptors.BlockType.OrderedList:
138
- return /* @__PURE__ */ jsxRuntime.jsx("ol", __spreadProps(__spreadValues({}, attributes), {
139
- className: css.cx(...blockStyles),
140
- style: {
141
- listStylePosition: "inside"
142
- },
143
- children
144
- }));
145
- case descriptors.BlockType.UnorderedList:
146
- return /* @__PURE__ */ jsxRuntime.jsx("ul", __spreadProps(__spreadValues({}, attributes), {
147
- className: css.cx(...blockStyles),
148
- style: {
149
- listStylePosition: "inside"
150
- },
151
- children
152
- }));
153
- case descriptors.BlockType.ListItem:
154
- return /* @__PURE__ */ jsxRuntime.jsx("li", __spreadProps(__spreadValues({}, attributes), {
155
- className: css.cx(...blockStyles),
156
- children
157
- }));
158
- case descriptors.BlockType.ListItemChild:
159
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
160
- className: css.cx(...blockStyles),
161
- children
162
- }));
163
- }
164
- }
165
- function StyledLink(_a) {
166
- var _b = _a, {
167
- className
168
- } = _b, restOfProps = __objRest(_b, [
169
- "className"
170
- ]);
171
- return /* @__PURE__ */ jsxRuntime.jsx(index.Link, __spreadProps(__spreadValues({}, restOfProps), {
172
- className: css.cx(next.useStyle({
173
- textDecoration: "none"
174
- }), className)
175
- }));
176
- }
177
- function InlineElement({
178
- element,
179
- attributes,
180
- children
181
- }) {
182
- switch (element.type) {
183
- case descriptors.InlineType.Code:
184
- return /* @__PURE__ */ jsxRuntime.jsx("code", __spreadProps(__spreadValues({}, attributes), {
185
- children
186
- }));
187
- case descriptors.InlineType.SuperScript:
188
- return /* @__PURE__ */ jsxRuntime.jsx("sup", __spreadProps(__spreadValues({}, attributes), {
189
- children
190
- }));
191
- case descriptors.InlineType.SubScript:
192
- return /* @__PURE__ */ jsxRuntime.jsx("sub", __spreadProps(__spreadValues({}, attributes), {
193
- children
194
- }));
195
- case descriptors.InlineType.Link:
196
- return /* @__PURE__ */ jsxRuntime.jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
197
- link: element.link,
198
- children
199
- }));
200
- }
201
- }
202
- function Element(_c) {
203
- var _d = _c, {
204
- element
205
- } = _d, props = __objRest(_d, [
206
- "element"
207
- ]);
208
- switch (element.type) {
209
- case descriptors.InlineType.Code:
210
- case descriptors.InlineType.SuperScript:
211
- case descriptors.InlineType.SubScript:
212
- case descriptors.InlineType.Link:
213
- return /* @__PURE__ */ jsxRuntime.jsx(InlineElement, __spreadValues({
214
- element
215
- }, props));
216
- case descriptors.BlockType.Paragraph:
217
- case descriptors.BlockType.Heading1:
218
- case descriptors.BlockType.Heading2:
219
- case descriptors.BlockType.Heading3:
220
- case descriptors.BlockType.BlockQuote:
221
- case descriptors.BlockType.OrderedList:
222
- case descriptors.BlockType.UnorderedList:
223
- case descriptors.BlockType.ListItem:
224
- case descriptors.BlockType.ListItemChild:
225
- return /* @__PURE__ */ jsxRuntime.jsx(BlockElement, __spreadValues({
226
- element
227
- }, props));
228
- default:
229
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
230
- children: props.children
231
- }));
232
- }
233
- }
234
- const COMMIT_DEBOUNCE_DELAY = 500;
235
- function useSyncWithBuilder(editor, text) {
236
- const [shouldCommit, setShouldCommit] = React.useState(true);
237
- const isInBuilder = next.useIsInBuilder();
238
- React.useEffect(() => {
239
- if (shouldCommit && text && isInBuilder) {
240
- const nextValue = descriptors.richTextDTOtoDAO(text);
241
- const nextSelection = descriptors.richTextDTOtoSelection(text);
242
- if (!next.deepEqual(editor.children, nextValue) || !next.deepEqual(editor.selection, nextSelection)) {
243
- editor.children = nextValue;
244
- editor.selection = nextSelection;
245
- editor.onChange();
246
- }
247
- }
248
- }, [editor, shouldCommit, text]);
249
- React.useEffect(() => {
250
- if (shouldCommit)
251
- return;
252
- const timeoutId = window.setTimeout(() => {
253
- setShouldCommit(true);
254
- }, COMMIT_DEBOUNCE_DELAY);
255
- return () => {
256
- window.clearTimeout(timeoutId);
257
- };
258
- }, [shouldCommit]);
259
- return React.useCallback(() => setShouldCommit(false), []);
260
- }
261
- function useSyncDOMSelection(editor, isEnabled) {
262
- useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
263
- if (!isEnabled || editor.selection == null || slateReact.ReactEditor.isFocused(editor))
264
- return;
265
- try {
266
- const root = slateReact.ReactEditor.findDocumentOrShadowRoot(editor);
267
- const domSelection = root.getSelection();
268
- const newDomRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
269
- if (newDomRange) {
270
- if (slate.Range.isBackward(editor.selection)) {
271
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
272
- } else {
273
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
274
- }
275
- } else {
276
- domSelection == null ? void 0 : domSelection.removeAllRanges();
277
- }
278
- } catch (e) {
279
- console.error(e);
280
- }
281
- });
282
- }
283
- const defaultText = [{
284
- type: descriptors.BlockType.Paragraph,
285
- children: [{
286
- text: ""
287
- }]
288
- }];
289
- const EditableText = React.forwardRef(function EditableText2({
290
- id,
291
- text,
292
- width,
293
- margin
294
- }, ref) {
295
- const [editor] = React.useState(() => index$1.withBlock(index$1.withTypography(index$1.withList(slateReact.withReact(slate.createEditor())))));
296
- const [isPreservingDOMSElection, setIsPreservingDOMSelection] = React.useState(false);
297
- useSyncDOMSelection(editor, isPreservingDOMSElection);
298
- const delaySync = useSyncWithBuilder(editor, text);
299
- const editMode = next.useBuilderEditMode();
300
- const [propControllers, setPropControllers] = React.useState(null);
301
- const controller = propControllers == null ? void 0 : propControllers.text;
302
- React.useEffect(() => {
303
- if (controller == null)
304
- return;
305
- const element = slateReact.ReactEditor.toDOMNode(editor, editor);
306
- return next.pollBoxModel({
307
- element,
308
- onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
309
- });
310
- }, [editor, controller]);
311
- React.useImperativeHandle(ref, () => ({
312
- getDomNode() {
313
- return slateReact.ReactEditor.toDOMNode(editor, editor);
314
- },
315
- getBoxModel() {
316
- return boxModels.getBox(slateReact.ReactEditor.toDOMNode(editor, editor));
317
- },
318
- setPropControllers
319
- }), [editor, setPropControllers]);
320
- const initialValue = React.useMemo(() => text ? descriptors.richTextDTOtoDAO(text) : defaultText, [text]);
321
- React.useEffect(() => {
322
- controller == null ? void 0 : controller.setSlateEditor(editor);
323
- }, [controller, editor]);
324
- const handleFocus = React.useCallback(() => {
325
- controller == null ? void 0 : controller.focus();
326
- setIsPreservingDOMSelection(true);
327
- }, [controller]);
328
- const handleKeyDown = React.useCallback((e) => {
329
- if (isHotkey__default["default"]("mod+shift+z", e))
330
- return controller == null ? void 0 : controller.redo();
331
- if (isHotkey__default["default"]("mod+z", e))
332
- return controller == null ? void 0 : controller.undo();
333
- if (isHotkey__default["default"]("escape")(e))
334
- return controller == null ? void 0 : controller.blur();
335
- index$1.onKeyDown(e, editor);
336
- }, [controller, editor]);
337
- const handleBlur = React.useCallback((e) => {
338
- if (e.relatedTarget == null)
339
- return;
340
- setIsPreservingDOMSelection(false);
341
- slateReact.ReactEditor.deselect(editor);
342
- }, []);
343
- return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
344
- editor,
345
- value: initialValue,
346
- onChange: delaySync,
347
- children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
348
- id,
349
- renderLeaf: leaf.Leaf,
350
- renderElement: Element,
351
- onFocus: handleFocus,
352
- onKeyDown: handleKeyDown,
353
- onBlur: handleBlur,
354
- className: css.cx(width, margin),
355
- readOnly: editMode !== descriptors.BuilderEditMode.CONTENT,
356
- placeholder: "Write some text..."
357
- })
358
- });
359
- });
360
- var EditableText$1 = EditableText;
361
- exports.EditableText = EditableText;
362
- exports["default"] = EditableText$1;
40
+ exports["default"] = Text["default"];
363
41
  //# sourceMappingURL=index.cjs7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs7.js","sources":["../src/components/builtin/Text/components/Element/block.tsx","../src/components/builtin/Text/components/Element/inline.tsx","../src/components/builtin/Text/components/Element/element.tsx","../src/components/builtin/Text/EditableText/useSyncWithBuilder.tsx","../src/components/builtin/Text/EditableText/useSyncDOMSelection.tsx","../src/components/builtin/Text/EditableText/editable-text.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { Block, BlockType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n switch (element.type) {\n case BlockType.Paragraph:\n return (\n <p {...attributes} className={cx(...blockStyles)}>\n {children}\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote\n {...attributes}\n className={cx(\n ...blockStyles,\n useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n }),\n )}\n >\n {children}\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li {...attributes} className={cx(...blockStyles)}>\n {children}\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { Inline, InlineType } from '../../../../../controls'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Inline\n}\n\nexport function InlineElement({ element, attributes, children }: InlineRenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n case InlineType.Link:\n return (\n <StyledLink {...attributes} link={element.link}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockType, InlineType } from '../../../../../controls'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../runtimes/react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { BlockType, RichTextDAO, richTextDTOtoDAO } from '../../../../controls'\nimport { Leaf } from '../components/Leaf'\nimport { Element } from '../components/Element'\nimport { useSyncWithBuilder } from './useSyncWithBuilder'\nimport isHotkey from 'is-hotkey'\nimport { useBuilderEditMode } from '../../../../runtimes/react'\nimport { BuilderEditMode } from '../../../../state/modules/builder-edit-mode'\nimport { onKeyDown, withBlock, withList, withTypography } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: RichTextDAO = [{ type: BlockType.Paragraph, children: [{ text: '' }] }]\n\nexport const EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<PropControllersHandle<Descriptors>>,\n) {\n const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","type","BlockType","Paragraph","cx","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","padding","fontSize","fontWeight","borderLeft","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","Link","textDecoration","InlineType","Code","SuperScript","SubScript","link","props","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withList","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Slate","Editable","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,cAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,KAAAA,SAASE,KAAmB,mBAAA,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAnB,CAFU;AAKZP,UAAAA,QAAQQ;AAAAA,SACTC,YAAUC,UAAAA;AACb,kFACST;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAC7BD;AAAAA,MAAAA,EAFL;AAAA,SAKGO,YAAUG,UAAAA;AACb,mFACUX;QAAY,WAAWU,IAAAA,GAAG,GAAGR,W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AAAuB,aAAOuB,yCAAYmB;AAC9CC,sBAAU3C,GAAGtC,MAAJ;AAAA,EAAA,GAEX,CAAC6D,YAAY7D,MAAb,CAP+B;AAU3BkF,QAAAA,aAAa/D,kBAAY,CAACmB,MAAkB;AAEhD,QAAIA,EAAE6C,iBAAiB;AAAM;AAE7B9B,gCAA4B,KAAD;AAC3B/B,2BAAY8D,SAASpF,MAArB;AAAA,EAL4B,GAM3B,CAN2B,CAAA;AAQ9B,wCACGqF,WAAAA,OAAD;AAAA,IAAO;AAAA,IAAgB,OAAOd;AAAAA,IAAc,UAAUhB;AAAAA,IAAtD,yCACG+B,qBAAD;AAAA,MACE;AAAA,MACA,YAAYC,KAAAA;AAAAA,MACZ,eAAeC;AAAAA,MACf,SAASd;AAAAA,MACT,WAAWE;AAAAA,MACX,QAAQM;AAAAA,MACR,WAAW9G,IAAAA,GAAGyE,OAAO/E,MAAR;AAAA,MACb,UAAU2F,aAAagC,YAAAA,gBAAgBC;AAAAA,MACvC,aAAY;AAAA,IAAA,CATd;AAAA,EAAA,CAFJ;AAeD,CAnFqC;AAqFtC,IAAA,iBAAehD;;;"}
1
+ {"version":3,"file":"index.cjs7.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
22
+ var React = require("react");
23
+ var slate = require("slate");
24
+ var isHotkey = require("is-hotkey");
25
+ var slateHistory = require("slate-history");
26
+ var slateReact = require("slate-react");
27
+ var descriptors = require("./descriptors.cjs.js");
28
+ var slate$1 = require("./slate.cjs2.js");
29
+ var next = require("./index.cjs.js");
30
+ require("./state/breakpoints.cjs.js");
31
+ var index = require("./index.cjs6.js");
32
+ var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
33
+ var jsxRuntime = require("react/jsx-runtime");
34
+ require("./actions.cjs.js");
35
+ require("use-sync-external-store/shim/with-selector");
36
+ require("next/dynamic");
37
+ require("./constants.cjs.js");
38
+ require("redux");
39
+ require("redux-thunk");
40
+ require("./introspection.cjs.js");
41
+ require("@emotion/css");
42
+ require("@emotion/serialize");
43
+ require("@emotion/utils");
44
+ require("./text-input.cjs.js");
45
+ require("./combobox.cjs.js");
46
+ require("use-sync-external-store/shim");
47
+ require("./types.cjs.js");
48
+ require("./box-models.cjs.js");
49
+ require("css-box-model");
50
+ require("color");
51
+ require("scroll-into-view-if-needed");
52
+ require("react-dom");
53
+ require("html-react-parser");
54
+ require("next/head");
55
+ require("@emotion/server/create-instance");
56
+ require("next/document");
57
+ require("cors");
58
+ require("path-to-regexp");
59
+ require("cookie");
60
+ require("http-proxy");
61
+ require("set-cookie-parser");
62
+ require("uuid");
63
+ require("corporate-ipsum");
64
+ require("./element.cjs.js");
65
+ function _interopDefaultLegacy(e) {
66
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
67
+ }
68
+ var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
69
+ function useSyncDOMSelection(editor, isEnabled) {
70
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
71
+ if (!isEnabled.current || editor.selection == null || slateReact.ReactEditor.isFocused(editor))
72
+ return;
73
+ try {
74
+ const root = slateReact.ReactEditor.findDocumentOrShadowRoot(editor);
75
+ const domSelection = root.getSelection();
76
+ const newDomRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
77
+ if (newDomRange) {
78
+ if (slate.Range.isBackward(editor.selection)) {
79
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
80
+ } else {
81
+ domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
82
+ }
83
+ } else {
84
+ domSelection == null ? void 0 : domSelection.removeAllRanges();
85
+ }
86
+ } catch (e) {
87
+ console.error(e);
88
+ }
89
+ });
90
+ }
91
+ const defaultText = [{
92
+ type: slate$1.BlockType.Text,
93
+ children: [{
94
+ text: ""
95
+ }]
96
+ }];
97
+ function EditableTextV2({
98
+ text,
99
+ control
100
+ }) {
101
+ const plugins = React.useMemo(() => {
102
+ var _a, _b, _c, _d, _e;
103
+ const plugins2 = [...(_c = (_b = (_a = control == null ? void 0 : control.descriptor) == null ? void 0 : _a.config) == null ? void 0 : _b.plugins) != null ? _c : [], ...((_e = (_d = control == null ? void 0 : control.descriptor) == null ? void 0 : _d.config) == null ? void 0 : _e.mode) === descriptors.RichTextV2Mode.Inline ? [index.InlineMode] : []];
104
+ return plugins2;
105
+ }, [control == null ? void 0 : control.descriptor.config]);
106
+ const [editor] = React.useState(() => plugins.reduceRight((editor2, plugin) => {
107
+ var _a, _b;
108
+ return (_b = (_a = plugin == null ? void 0 : plugin.withPlugin) == null ? void 0 : _a.call(plugin, editor2)) != null ? _b : editor2;
109
+ }, slateHistory.withHistory(slateReact.withReact(slate.createEditor()))));
110
+ const isPreservingFocus = React.useRef(false);
111
+ useSyncDOMSelection(editor, isPreservingFocus);
112
+ const editMode = next.useBuilderEditMode();
113
+ React.useEffect(() => {
114
+ if (control == null)
115
+ return;
116
+ const element = slateReact.ReactEditor.toDOMNode(editor, editor);
117
+ return next.pollBoxModel({
118
+ element,
119
+ onBoxModelChange: (boxModel) => control.changeBoxModel(boxModel)
120
+ });
121
+ }, [editor, control]);
122
+ const renderElement = React.useCallback(({
123
+ attributes,
124
+ children,
125
+ element
126
+ }) => {
127
+ switch (element.type) {
128
+ default:
129
+ return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
130
+ children
131
+ }));
132
+ }
133
+ }, []);
134
+ const renderLeaf = React.useCallback(({
135
+ attributes,
136
+ children
137
+ }) => {
138
+ return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
139
+ children
140
+ }));
141
+ }, []);
142
+ const initialValue = React.useMemo(() => text != null ? text : defaultText, [text]);
143
+ React.useEffect(() => {
144
+ if (editMode !== descriptors.BuilderEditMode.CONTENT) {
145
+ isPreservingFocus.current = false;
146
+ slateReact.ReactEditor.deselect(editor);
147
+ }
148
+ }, [editMode]);
149
+ React.useEffect(() => {
150
+ control == null ? void 0 : control.setEditor(editor);
151
+ control == null ? void 0 : control.setDefaultValue(defaultText);
152
+ }, [control, editor, defaultText]);
153
+ const handleFocus = React.useCallback(() => {
154
+ isPreservingFocus.current = true;
155
+ control == null ? void 0 : control.select();
156
+ }, [control]);
157
+ const handleKeyDown = React.useCallback((e) => {
158
+ if (isHotkey__default["default"]("mod+shift+z", e))
159
+ return slateHistory.HistoryEditor.redo(editor);
160
+ if (isHotkey__default["default"]("mod+z", e))
161
+ return slateHistory.HistoryEditor.undo(editor);
162
+ if (isHotkey__default["default"]("escape")(e)) {
163
+ isPreservingFocus.current = false;
164
+ slateReact.ReactEditor.blur(editor);
165
+ control == null ? void 0 : control.switchToBuildMode();
166
+ }
167
+ plugins.forEach((plugin) => {
168
+ var _a;
169
+ return (_a = plugin == null ? void 0 : plugin.onKeyDown) == null ? void 0 : _a.call(plugin, e);
170
+ });
171
+ }, [control, plugins, editor]);
172
+ const handleKeyUp = React.useCallback((e) => {
173
+ if (editMode === descriptors.BuilderEditMode.CONTENT)
174
+ e.preventDefault();
175
+ }, [control, editor, editMode]);
176
+ const handleClick = React.useCallback((e) => {
177
+ if (editMode === descriptors.BuilderEditMode.CONTENT)
178
+ e.stopPropagation();
179
+ }, [editMode]);
180
+ const handleBlur = React.useCallback((e) => {
181
+ var _a;
182
+ if (e.relatedTarget == null)
183
+ return;
184
+ if (((_a = e.relatedTarget) == null ? void 0 : _a.getAttribute("contenteditable")) === "true")
185
+ isPreservingFocus.current = false;
186
+ }, []);
187
+ const handleOnChange = React.useCallback((value) => {
188
+ control == null ? void 0 : control.onChange(value);
189
+ }, [control]);
190
+ return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
191
+ editor,
192
+ onChange: handleOnChange,
193
+ value: initialValue,
194
+ children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
195
+ renderLeaf,
196
+ renderElement,
197
+ onFocus: handleFocus,
198
+ onKeyDown: handleKeyDown,
199
+ onKeyUp: handleKeyUp,
200
+ onClick: handleClick,
201
+ onBlur: handleBlur,
202
+ readOnly: editMode !== descriptors.BuilderEditMode.CONTENT,
203
+ placeholder: "Write some text..."
204
+ })
205
+ });
206
+ }
207
+ exports.EditableTextV2 = EditableTextV2;
208
+ exports["default"] = EditableTextV2;
209
+ //# sourceMappingURL=index.cjs8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs8.js","sources":["../src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.tsx","../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["import { Editor, Range as SlateRange } from 'slate'\nimport { useIsomorphicLayoutEffect } from '../../../../../components/hooks/useIsomorphicLayoutEffect'\nimport { MutableRefObject } from 'react'\nimport { ReactEditor } from 'slate-react'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: MutableRefObject<boolean>) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled.current || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { Descendant, createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport { withHistory, HistoryEditor } from 'slate-history'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport {\n RichTextV2Control,\n RichTextV2ControlData,\n RichTextV2ControlDefinition,\n RichTextV2Mode,\n} from '../../../../../controls'\nimport { useBuilderEditMode } from '../../..'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { InlineMode } from '../../../../../slate'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { BlockType } from '../../../../../../types/slate'\n\nexport type RichTextV2ControlValue = ReactNode\n\nexport type Descriptors = { text?: RichTextV2ControlDefinition }\n\nconst defaultText: Descendant[] = [{ type: BlockType.Text, children: [{ text: '' }] }]\n\ntype Props = {\n text: RichTextV2ControlData\n control: RichTextV2Control | null\n}\n\nexport function EditableTextV2({ text, control }: Props) {\n const plugins = useMemo(() => {\n const plugins = [\n ...(control?.descriptor?.config?.plugins ?? []),\n ...(control?.descriptor?.config?.mode === RichTextV2Mode.Inline ? [InlineMode] : []),\n ]\n return plugins\n }, [control?.descriptor.config])\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withHistory(withReact(createEditor())),\n ),\n )\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n const renderElement = useCallback(({ attributes, children, element }: RenderElementProps) => {\n switch (element.type) {\n default:\n return <p {...attributes}>{children}</p>\n }\n }, [])\n\n const renderLeaf = useCallback(({ attributes, children }: RenderLeafProps) => {\n return <span {...attributes}>{children}</span>\n }, [])\n\n const initialValue = useMemo(() => text ?? defaultText, [text])\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode])\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultText)\n }, [control, editor, defaultText])\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return HistoryEditor.redo(editor)\n if (isHotkey('mod+z', e)) return HistoryEditor.undo(editor)\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e))\n },\n [control, plugins, editor],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) e.preventDefault()\n },\n [control, editor, editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) e.stopPropagation()\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n const handleOnChange = useCallback(\n (value: Descendant[]) => {\n control?.onChange(value)\n },\n [control],\n )\n\n return (\n <Slate editor={editor} onChange={handleOnChange} value={initialValue}>\n <Editable\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n\nexport default EditableTextV2\n"],"names":["editor","isEnabled","useIsomorphicLayoutEffect","current","selection","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","type","BlockType","Text","children","text","control","plugins","useMemo","descriptor","config","mode","RichTextV2Mode","Inline","InlineMode","useState","reduceRight","plugin","withPlugin","withHistory","withReact","createEditor","isPreservingFocus","useRef","useSyncDOMSelection","editMode","useBuilderEditMode","useEffect","element","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","renderElement","useCallback","attributes","renderLeaf","initialValue","BuilderEditMode","CONTENT","deselect","setEditor","setDefaultValue","handleFocus","select","handleKeyDown","isHotkey","HistoryEditor","redo","undo","blur","switchToBuildMode","forEach","onKeyDown","handleKeyUp","preventDefault","handleClick","stopPropagation","handleBlur","relatedTarget","getAttribute","handleOnChange","value","onChange","Slate","Editable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,6BAA6BA,QAAgBC,WAAsC;AACxFC,4BAAAA,0BAA0B,MAAM;AAC1B,QAAA,CAACD,UAAUE,WAAWH,OAAOI,aAAa,QAAQC,WAAAA,YAAYC,UAAUN,MAAtB;AAA+B;AACjF,QAAA;AACIO,YAAAA,OAAOF,WAAAA,YAAYG,yBAAyBR,MAArC;AACPS,YAAAA,eAAeF,KAAKG;AAC1B,YAAMC,cAA4BN,WAAAA,YAAYO,WAAWZ,QAAQA,OAAOI,SAAtC;AAElC,UAAIO,aAAa;AACXE,YAAAA,YAAWC,WAAWd,OAAOI,SAA7B,GAA0C;AAC9BW,uDAAAA,iBACZJ,YAAYK,cACZL,YAAYM,WACZN,YAAYO,gBACZP,YAAYQ;AAAAA,QAJd,OAMK;AACSJ,uDAAAA,iBACZJ,YAAYO,gBACZP,YAAYQ,aACZR,YAAYK,cACZL,YAAYM;AAAAA,QAEf;AAAA,MAAA,OACI;AACLR,qDAAcW;AAAAA,MACf;AAAA,aACMC;AACPC,cAAQC,MAAMF,CAAd;AAAA,IACD;AAAA,EAAA,CA5BsB;AA8B1B;ACDD,MAAMG,cAA4B,CAAC;AAAA,EAAEC,MAAMC,QAAUC,UAAAA;AAAAA,EAAMC,UAAU,CAAC;AAAA,IAAEC,MAAM;AAAA,EAAA,CAAT;AAAlC,CAAD;AAOH,wBAAA;AAAA,EAAEA;AAAAA,EAAMC;AAAAA,GAAkB;AACjDC,QAAAA,UAAUC,MAAAA,QAAQ,MAAM;;AACtBD,UAAAA,WAAU,CACd,GA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