@makeswift/runtime 0.8.9 → 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 (249) hide show
  1. package/dist/Box.cjs.js +2 -4
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +2 -4
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +1 -4
  6. package/dist/Button.cjs.js.map +1 -1
  7. package/dist/Button.es.js +1 -4
  8. package/dist/Button.es.js.map +1 -1
  9. package/dist/Carousel.cjs.js +1 -4
  10. package/dist/Carousel.cjs.js.map +1 -1
  11. package/dist/Carousel.es.js +1 -4
  12. package/dist/Carousel.es.js.map +1 -1
  13. package/dist/Countdown.cjs.js +1 -4
  14. package/dist/Countdown.cjs.js.map +1 -1
  15. package/dist/Countdown.es.js +1 -4
  16. package/dist/Countdown.es.js.map +1 -1
  17. package/dist/Divider.cjs.js +1 -4
  18. package/dist/Divider.cjs.js.map +1 -1
  19. package/dist/Divider.es.js +1 -4
  20. package/dist/Divider.es.js.map +1 -1
  21. package/dist/Embed.cjs.js +3 -5
  22. package/dist/Embed.cjs.js.map +1 -1
  23. package/dist/Embed.es.js +3 -5
  24. package/dist/Embed.es.js.map +1 -1
  25. package/dist/Form.cjs.js +1 -4
  26. package/dist/Form.cjs.js.map +1 -1
  27. package/dist/Form.es.js +2 -5
  28. package/dist/Form.es.js.map +1 -1
  29. package/dist/Image.cjs.js +1 -4
  30. package/dist/Image.cjs.js.map +1 -1
  31. package/dist/Image.es.js +2 -5
  32. package/dist/Image.es.js.map +1 -1
  33. package/dist/LiveProvider.cjs.js +1 -4
  34. package/dist/LiveProvider.cjs.js.map +1 -1
  35. package/dist/LiveProvider.es.js +2 -5
  36. package/dist/LiveProvider.es.js.map +1 -1
  37. package/dist/Navigation.cjs.js +3 -5
  38. package/dist/Navigation.cjs.js.map +1 -1
  39. package/dist/Navigation.es.js +3 -5
  40. package/dist/Navigation.es.js.map +1 -1
  41. package/dist/PreviewProvider.cjs.js +1 -4
  42. package/dist/PreviewProvider.cjs.js.map +1 -1
  43. package/dist/PreviewProvider.es.js +3 -6
  44. package/dist/PreviewProvider.es.js.map +1 -1
  45. package/dist/ReadOnlyText.cjs.js +62 -60
  46. package/dist/ReadOnlyText.cjs.js.map +1 -1
  47. package/dist/ReadOnlyText.es.js +9 -7
  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 +2 -4
  54. package/dist/Root.cjs.js.map +1 -1
  55. package/dist/Root.es.js +2 -4
  56. package/dist/Root.es.js.map +1 -1
  57. package/dist/SocialLinks.cjs.js +1 -4
  58. package/dist/SocialLinks.cjs.js.map +1 -1
  59. package/dist/SocialLinks.es.js +1 -4
  60. package/dist/SocialLinks.es.js.map +1 -1
  61. package/dist/Text.cjs.js +2 -5
  62. package/dist/Text.cjs.js.map +1 -1
  63. package/dist/Text.es.js +3 -6
  64. package/dist/Text.es.js.map +1 -1
  65. package/dist/Video.cjs.js +1 -4
  66. package/dist/Video.cjs.js.map +1 -1
  67. package/dist/Video.es.js +1 -4
  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 +2 -4
  76. package/dist/components.cjs.js.map +1 -1
  77. package/dist/components.es.js +2 -4
  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 +2 -6
  86. package/dist/controls.cjs.js.map +1 -1
  87. package/dist/controls.es.js +2 -3
  88. package/dist/controls.es.js.map +1 -1
  89. package/dist/descriptors.cjs.js +53 -88
  90. package/dist/descriptors.cjs.js.map +1 -1
  91. package/dist/descriptors.es.js +32 -64
  92. package/dist/descriptors.es.js.map +1 -1
  93. package/dist/element.cjs.js +55 -0
  94. package/dist/element.cjs.js.map +1 -0
  95. package/dist/element.es.js +54 -0
  96. package/dist/element.es.js.map +1 -0
  97. package/dist/index.cjs.js +33 -116
  98. package/dist/index.cjs.js.map +1 -1
  99. package/dist/index.cjs2.js +3 -4
  100. package/dist/index.cjs2.js.map +1 -1
  101. package/dist/index.cjs5.js +48 -82
  102. package/dist/index.cjs5.js.map +1 -1
  103. package/dist/index.cjs6.js +41 -42
  104. package/dist/index.cjs6.js.map +1 -1
  105. package/dist/index.cjs7.js +14 -341
  106. package/dist/index.cjs7.js.map +1 -1
  107. package/dist/index.cjs8.js +209 -0
  108. package/dist/index.cjs8.js.map +1 -0
  109. package/dist/index.cjs9.js +370 -0
  110. package/dist/index.cjs9.js.map +1 -0
  111. package/dist/index.es.js +32 -117
  112. package/dist/index.es.js.map +1 -1
  113. package/dist/index.es2.js +2 -3
  114. package/dist/index.es2.js.map +1 -1
  115. package/dist/index.es3.js +1 -1
  116. package/dist/index.es5.js +19 -54
  117. package/dist/index.es5.js.map +1 -1
  118. package/dist/index.es6.js +36 -40
  119. package/dist/index.es6.js.map +1 -1
  120. package/dist/index.es7.js +13 -336
  121. package/dist/index.es7.js.map +1 -1
  122. package/dist/index.es8.js +202 -0
  123. package/dist/index.es8.js.map +1 -0
  124. package/dist/index.es9.js +363 -0
  125. package/dist/index.es9.js.map +1 -0
  126. package/dist/introspection.cjs.js +0 -2
  127. package/dist/introspection.cjs.js.map +1 -1
  128. package/dist/introspection.es.js +0 -2
  129. package/dist/introspection.es.js.map +1 -1
  130. package/dist/leaf.cjs.js.map +1 -1
  131. package/dist/leaf.es.js +1 -1
  132. package/dist/leaf.es.js.map +1 -1
  133. package/dist/main.cjs.js +1 -2
  134. package/dist/main.cjs.js.map +1 -1
  135. package/dist/main.es.js +1 -2
  136. package/dist/main.es.js.map +1 -1
  137. package/dist/next.cjs.js +1 -4
  138. package/dist/next.cjs.js.map +1 -1
  139. package/dist/next.es.js +2 -5
  140. package/dist/next.es.js.map +1 -1
  141. package/dist/prop-controllers.cjs.js +1 -2
  142. package/dist/prop-controllers.cjs.js.map +1 -1
  143. package/dist/prop-controllers.es.js +1 -2
  144. package/dist/prop-controllers.es.js.map +1 -1
  145. package/dist/react.cjs.js +1 -4
  146. package/dist/react.cjs.js.map +1 -1
  147. package/dist/react.es.js +1 -4
  148. package/dist/react.es.js.map +1 -1
  149. package/dist/slate.cjs.js +8 -3
  150. package/dist/slate.cjs.js.map +1 -1
  151. package/dist/slate.cjs2.js +46 -0
  152. package/dist/slate.cjs2.js.map +1 -0
  153. package/dist/slate.es.js +6 -4
  154. package/dist/slate.es.js.map +1 -1
  155. package/dist/slate.es2.js +44 -0
  156. package/dist/slate.es2.js.map +1 -0
  157. package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
  158. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  159. package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -1
  160. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +2 -1
  161. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  162. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts +1 -1
  163. package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -1
  164. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts +1 -1
  165. package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts.map +1 -1
  166. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +1 -1
  167. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  168. package/dist/types/src/controls/list.d.ts +2 -1
  169. package/dist/types/src/controls/list.d.ts.map +1 -1
  170. package/dist/types/src/controls/rich-text/dto-types.d.ts +1 -1
  171. package/dist/types/src/controls/rich-text/dto-types.d.ts.map +1 -1
  172. package/dist/types/src/controls/rich-text/index.d.ts +0 -1
  173. package/dist/types/src/controls/rich-text/index.d.ts.map +1 -1
  174. package/dist/types/src/controls/rich-text/rich-text.d.ts +1 -1
  175. package/dist/types/src/controls/rich-text/rich-text.d.ts.map +1 -1
  176. package/dist/types/src/controls/rich-text/translation.d.ts +1 -1
  177. package/dist/types/src/controls/rich-text/translation.d.ts.map +1 -1
  178. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +25 -4
  179. package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  180. package/dist/types/src/controls/shape.d.ts +2 -1
  181. package/dist/types/src/controls/shape.d.ts.map +1 -1
  182. package/dist/types/src/controls/slot.d.ts +1 -1
  183. package/dist/types/src/controls/slot.d.ts.map +1 -1
  184. package/dist/types/src/controls/style.d.ts +2 -1
  185. package/dist/types/src/controls/style.d.ts.map +1 -1
  186. package/dist/types/src/prop-controllers/base.d.ts +7 -0
  187. package/dist/types/src/prop-controllers/base.d.ts.map +1 -0
  188. package/dist/types/src/prop-controllers/instances.d.ts +1 -5
  189. package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
  190. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts +13 -0
  191. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -0
  192. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts +4 -0
  193. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts.map +1 -0
  194. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.d.ts +9 -0
  195. package/dist/types/src/runtimes/react/controls/rich-text-v2/EditableTextV2/useSyncDOMSelection.d.ts.map +1 -0
  196. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +21 -0
  197. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -0
  198. package/dist/types/src/runtimes/react/controls/rich-text-v2/index.d.ts +2 -0
  199. package/dist/types/src/runtimes/react/controls/rich-text-v2/index.d.ts.map +1 -0
  200. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +8 -0
  201. package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -0
  202. package/dist/types/src/slate/BlockPlugin/index.d.ts +1 -1
  203. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
  204. package/dist/types/src/slate/BlockPlugin/types.d.ts +1 -1
  205. package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -1
  206. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts +1 -1
  207. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts.map +1 -1
  208. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts +1 -1
  209. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts.map +1 -1
  210. package/dist/types/src/slate/BuilderPlugin/index.d.ts +7 -0
  211. package/dist/types/src/slate/BuilderPlugin/index.d.ts.map +1 -0
  212. package/dist/types/src/slate/InlineModePlugin/index.d.ts +5 -0
  213. package/dist/types/src/slate/InlineModePlugin/index.d.ts.map +1 -0
  214. package/dist/types/src/slate/ListPlugin/index.d.ts +1 -1
  215. package/dist/types/src/slate/ListPlugin/index.d.ts.map +1 -1
  216. package/dist/types/src/slate/ListPlugin/toggleList.d.ts +1 -1
  217. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -1
  218. package/dist/types/src/slate/ListPlugin/wrapList.d.ts +1 -1
  219. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -1
  220. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +1 -1
  221. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -1
  222. package/dist/types/src/slate/TypographyPlugin/index.d.ts +1 -1
  223. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  224. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  225. package/dist/types/src/slate/index.d.ts +2 -0
  226. package/dist/types/src/slate/index.d.ts.map +1 -1
  227. package/dist/types/src/slate/selectors.d.ts +1 -1
  228. package/dist/types/src/slate/selectors.d.ts.map +1 -1
  229. package/dist/types/src/slate/utils/editor.d.ts +1 -1
  230. package/dist/types/src/slate/utils/editor.d.ts.map +1 -1
  231. package/dist/types/src/slate/utils/element.d.ts +1 -1
  232. package/dist/types/src/slate/utils/element.d.ts.map +1 -1
  233. package/dist/types/src/state/actions.d.ts +2 -1
  234. package/dist/types/src/state/actions.d.ts.map +1 -1
  235. package/dist/types/src/state/modules/prop-controller-handles.d.ts +2 -1
  236. package/dist/types/src/state/modules/prop-controller-handles.d.ts.map +1 -1
  237. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  238. package/dist/types/src/state/react-page.d.ts +1 -1
  239. package/dist/types/src/state/react-page.d.ts.map +1 -1
  240. package/dist/types/{src/controls/rich-text/types.d.ts → types/slate.d.ts} +20 -17
  241. package/dist/types/types/slate.d.ts.map +1 -0
  242. package/dist/useIsomorphicLayoutEffect.cjs.js +6 -0
  243. package/dist/useIsomorphicLayoutEffect.cjs.js.map +1 -0
  244. package/dist/useIsomorphicLayoutEffect.es.js +5 -0
  245. package/dist/useIsomorphicLayoutEffect.es.js.map +1 -0
  246. package/package.json +1 -1
  247. package/dist/types/src/controls/rich-text/types.d.ts.map +0 -1
  248. package/dist/types/src/runtimes/react/controls/rich-text-v2.d.ts +0 -15
  249. package/dist/types/src/runtimes/react/controls/rich-text-v2.d.ts.map +0 -1
@@ -1,66 +1,30 @@
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
- require("css-box-model");
47
- require("./actions.cjs.js");
48
- require("./introspection.cjs.js");
49
- require("./state/breakpoints.cjs.js");
50
- require("use-sync-external-store/shim/with-selector");
3
+ var Text = require("./Text.cjs.js");
51
4
  require("next/dynamic");
5
+ require("react");
6
+ require("./index.cjs.js");
7
+ require("use-sync-external-store/shim/with-selector");
52
8
  require("./constants.cjs.js");
53
9
  require("redux");
54
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");
55
17
  require("@emotion/serialize");
56
18
  require("@emotion/utils");
19
+ require("react/jsx-runtime");
57
20
  require("./text-input.cjs.js");
58
21
  require("./combobox.cjs.js");
59
22
  require("use-sync-external-store/shim");
60
23
  require("./types.cjs.js");
24
+ require("./box-models.cjs.js");
25
+ require("css-box-model");
61
26
  require("color");
62
27
  require("scroll-into-view-if-needed");
63
- require("slate-history");
64
28
  require("react-dom");
65
29
  require("html-react-parser");
66
30
  require("next/head");
@@ -73,296 +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.Text:
93
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
94
- className: css.cx(...blockStyles),
95
- children
96
- }));
97
- case descriptors.BlockType.Paragraph:
98
- return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
99
- className: css.cx(...blockStyles),
100
- children
101
- }));
102
- case descriptors.BlockType.Heading1:
103
- return /* @__PURE__ */ jsxRuntime.jsx("h1", __spreadProps(__spreadValues({}, attributes), {
104
- className: css.cx(...blockStyles),
105
- children
106
- }));
107
- case descriptors.BlockType.Heading2:
108
- return /* @__PURE__ */ jsxRuntime.jsx("h2", __spreadProps(__spreadValues({}, attributes), {
109
- className: css.cx(...blockStyles),
110
- children
111
- }));
112
- case descriptors.BlockType.Heading3:
113
- return /* @__PURE__ */ jsxRuntime.jsx("h3", __spreadProps(__spreadValues({}, attributes), {
114
- className: css.cx(...blockStyles),
115
- children
116
- }));
117
- case descriptors.BlockType.Heading4:
118
- return /* @__PURE__ */ jsxRuntime.jsx("h4", __spreadProps(__spreadValues({}, attributes), {
119
- className: css.cx(...blockStyles),
120
- children
121
- }));
122
- case descriptors.BlockType.Heading5:
123
- return /* @__PURE__ */ jsxRuntime.jsx("h5", __spreadProps(__spreadValues({}, attributes), {
124
- className: css.cx(...blockStyles),
125
- children
126
- }));
127
- case descriptors.BlockType.Heading6:
128
- return /* @__PURE__ */ jsxRuntime.jsx("h6", __spreadProps(__spreadValues({}, attributes), {
129
- className: css.cx(...blockStyles),
130
- children
131
- }));
132
- case descriptors.BlockType.BlockQuote:
133
- return /* @__PURE__ */ jsxRuntime.jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
134
- className: css.cx(...blockStyles, next.useStyle({
135
- padding: "0.5em 10px",
136
- fontSize: "1.25em",
137
- fontWeight: "300",
138
- borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
139
- })),
140
- children
141
- }));
142
- case descriptors.BlockType.OrderedList:
143
- return /* @__PURE__ */ jsxRuntime.jsx("ol", __spreadProps(__spreadValues({}, attributes), {
144
- className: css.cx(...blockStyles),
145
- style: {
146
- listStylePosition: "inside"
147
- },
148
- children
149
- }));
150
- case descriptors.BlockType.UnorderedList:
151
- return /* @__PURE__ */ jsxRuntime.jsx("ul", __spreadProps(__spreadValues({}, attributes), {
152
- className: css.cx(...blockStyles),
153
- style: {
154
- listStylePosition: "inside"
155
- },
156
- children
157
- }));
158
- case descriptors.BlockType.ListItem:
159
- return /* @__PURE__ */ jsxRuntime.jsx("li", __spreadProps(__spreadValues({}, attributes), {
160
- className: css.cx(...blockStyles),
161
- children
162
- }));
163
- case descriptors.BlockType.ListItemChild:
164
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
165
- className: css.cx(...blockStyles),
166
- children
167
- }));
168
- }
169
- }
170
- function StyledLink(_a) {
171
- var _b = _a, {
172
- className
173
- } = _b, restOfProps = __objRest(_b, [
174
- "className"
175
- ]);
176
- return /* @__PURE__ */ jsxRuntime.jsx(index.Link, __spreadProps(__spreadValues({}, restOfProps), {
177
- className: css.cx(next.useStyle({
178
- textDecoration: "none"
179
- }), className)
180
- }));
181
- }
182
- function InlineElement({
183
- element,
184
- attributes,
185
- children
186
- }) {
187
- switch (element.type) {
188
- case descriptors.InlineType.Code:
189
- return /* @__PURE__ */ jsxRuntime.jsx("code", __spreadProps(__spreadValues({}, attributes), {
190
- children
191
- }));
192
- case descriptors.InlineType.SuperScript:
193
- return /* @__PURE__ */ jsxRuntime.jsx("sup", __spreadProps(__spreadValues({}, attributes), {
194
- children
195
- }));
196
- case descriptors.InlineType.SubScript:
197
- return /* @__PURE__ */ jsxRuntime.jsx("sub", __spreadProps(__spreadValues({}, attributes), {
198
- children
199
- }));
200
- case descriptors.InlineType.Link:
201
- return /* @__PURE__ */ jsxRuntime.jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
202
- link: element.link,
203
- children
204
- }));
205
- }
206
- }
207
- function Element(_c) {
208
- var _d = _c, {
209
- element
210
- } = _d, props = __objRest(_d, [
211
- "element"
212
- ]);
213
- switch (element.type) {
214
- case descriptors.InlineType.Code:
215
- case descriptors.InlineType.SuperScript:
216
- case descriptors.InlineType.SubScript:
217
- case descriptors.InlineType.Link:
218
- return /* @__PURE__ */ jsxRuntime.jsx(InlineElement, __spreadValues({
219
- element
220
- }, props));
221
- case descriptors.BlockType.Paragraph:
222
- case descriptors.BlockType.Heading1:
223
- case descriptors.BlockType.Heading2:
224
- case descriptors.BlockType.Heading3:
225
- case descriptors.BlockType.BlockQuote:
226
- case descriptors.BlockType.OrderedList:
227
- case descriptors.BlockType.UnorderedList:
228
- case descriptors.BlockType.ListItem:
229
- case descriptors.BlockType.ListItemChild:
230
- return /* @__PURE__ */ jsxRuntime.jsx(BlockElement, __spreadValues({
231
- element
232
- }, props));
233
- default:
234
- return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
235
- children: props.children
236
- }));
237
- }
238
- }
239
- const COMMIT_DEBOUNCE_DELAY = 500;
240
- function useSyncWithBuilder(editor, text) {
241
- const [shouldCommit, setShouldCommit] = React.useState(true);
242
- const isInBuilder = next.useIsInBuilder();
243
- React.useEffect(() => {
244
- if (shouldCommit && text && isInBuilder) {
245
- const nextValue = descriptors.richTextDTOtoDAO(text);
246
- const nextSelection = descriptors.richTextDTOtoSelection(text);
247
- if (!next.deepEqual(editor.children, nextValue) || !next.deepEqual(editor.selection, nextSelection)) {
248
- editor.children = nextValue;
249
- editor.selection = nextSelection;
250
- editor.onChange();
251
- }
252
- }
253
- }, [editor, shouldCommit, text]);
254
- React.useEffect(() => {
255
- if (shouldCommit)
256
- return;
257
- const timeoutId = window.setTimeout(() => {
258
- setShouldCommit(true);
259
- }, COMMIT_DEBOUNCE_DELAY);
260
- return () => {
261
- window.clearTimeout(timeoutId);
262
- };
263
- }, [shouldCommit]);
264
- return React.useCallback(() => setShouldCommit(false), []);
265
- }
266
- function useSyncDOMSelection(editor, isEnabled) {
267
- next.useIsomorphicLayoutEffect(() => {
268
- if (!isEnabled || editor.selection == null || slateReact.ReactEditor.isFocused(editor))
269
- return;
270
- try {
271
- const root = slateReact.ReactEditor.findDocumentOrShadowRoot(editor);
272
- const domSelection = root.getSelection();
273
- const newDomRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
274
- if (newDomRange) {
275
- if (slate.Range.isBackward(editor.selection)) {
276
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
277
- } else {
278
- domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
279
- }
280
- } else {
281
- domSelection == null ? void 0 : domSelection.removeAllRanges();
282
- }
283
- } catch (e) {
284
- console.error(e);
285
- }
286
- });
287
- }
288
- const defaultText = [{
289
- type: descriptors.BlockType.Paragraph,
290
- children: [{
291
- text: ""
292
- }]
293
- }];
294
- const EditableText = React.forwardRef(function EditableText2({
295
- id,
296
- text,
297
- width,
298
- margin
299
- }, ref) {
300
- const [editor] = React.useState(() => index$1.withBlock(index$1.withTypography(index$1.withList(slateReact.withReact(slate.createEditor())))));
301
- const [isPreservingDOMSElection, setIsPreservingDOMSelection] = React.useState(false);
302
- useSyncDOMSelection(editor, isPreservingDOMSElection);
303
- const delaySync = useSyncWithBuilder(editor, text);
304
- const editMode = next.useBuilderEditMode();
305
- const [propControllers, setPropControllers] = React.useState(null);
306
- const controller = propControllers == null ? void 0 : propControllers.text;
307
- React.useEffect(() => {
308
- if (controller == null)
309
- return;
310
- const element = slateReact.ReactEditor.toDOMNode(editor, editor);
311
- return next.pollBoxModel({
312
- element,
313
- onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
314
- });
315
- }, [editor, controller]);
316
- React.useImperativeHandle(ref, () => ({
317
- getDomNode() {
318
- return slateReact.ReactEditor.toDOMNode(editor, editor);
319
- },
320
- getBoxModel() {
321
- return boxModels.getBox(slateReact.ReactEditor.toDOMNode(editor, editor));
322
- },
323
- setPropControllers
324
- }), [editor, setPropControllers]);
325
- const initialValue = React.useMemo(() => text ? descriptors.richTextDTOtoDAO(text) : defaultText, [text]);
326
- React.useEffect(() => {
327
- controller == null ? void 0 : controller.setSlateEditor(editor);
328
- }, [controller, editor]);
329
- const handleFocus = React.useCallback(() => {
330
- controller == null ? void 0 : controller.focus();
331
- setIsPreservingDOMSelection(true);
332
- }, [controller]);
333
- const handleKeyDown = React.useCallback((e) => {
334
- if (isHotkey__default["default"]("mod+shift+z", e))
335
- return controller == null ? void 0 : controller.redo();
336
- if (isHotkey__default["default"]("mod+z", e))
337
- return controller == null ? void 0 : controller.undo();
338
- if (isHotkey__default["default"]("escape")(e))
339
- return controller == null ? void 0 : controller.blur();
340
- index$1.onKeyDown(e, editor);
341
- }, [controller, editor]);
342
- const handleBlur = React.useCallback((e) => {
343
- if (e.relatedTarget == null)
344
- return;
345
- setIsPreservingDOMSelection(false);
346
- slateReact.ReactEditor.deselect(editor);
347
- }, []);
348
- return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
349
- editor,
350
- value: initialValue,
351
- onChange: delaySync,
352
- children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
353
- id,
354
- renderLeaf: leaf.Leaf,
355
- renderElement: Element,
356
- onFocus: handleFocus,
357
- onKeyDown: handleKeyDown,
358
- onBlur: handleBlur,
359
- className: css.cx(width, margin),
360
- readOnly: editMode !== descriptors.BuilderEditMode.CONTENT,
361
- placeholder: "Write some text..."
362
- })
363
- });
364
- });
365
- var EditableText$1 = EditableText;
366
- exports.EditableText = EditableText;
367
- exports["default"] = EditableText$1;
40
+ exports["default"] = Text["default"];
368
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.Text:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\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","Text","cx","Paragraph","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,qFACYT;QAAY,WAAWU,IAAAA,GAAG,GAAGR,WAAJ;AAAA,QAChCD;AAAAA,MAAAA,EAFL;AAA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B;AAChBuC,QAAAA,kBAAAA,WAAS,eAAevC,CAAhB;AAAoB,aAAOuB,yCAAYiB;AAC/CD,QAAAA,kBAAAA,WAAS,SAASvC,CAAV;AAAc,aAAOuB,yCAAYkB;AACzCF,QAAAA,kBAAAA,WAAS,QAAD,EAAWvC,CAAnB;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,WAAW/G,IAAAA,GAAG0E,OAAOhF,MAAR;AAAA,MACb,UAAU4F,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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