@makeswift/runtime 0.7.13 → 0.7.15
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.
- package/dist/ReadOnlyText.cjs.js +64 -28
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +64 -27
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/controls.cjs.js +1 -4
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +1 -2
- package/dist/controls.es.js.map +1 -1
- package/dist/index.cjs.js +2 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs6.js +143 -132
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.es.js +2 -2
- package/dist/index.es6.js +144 -133
- package/dist/index.es6.js.map +1 -1
- package/dist/introspection.cjs.js +0 -1
- package/dist/introspection.cjs.js.map +1 -1
- package/dist/introspection.es.js +1 -1
- package/dist/{typography.cjs.js → leaf.cjs.js} +49 -12
- package/dist/leaf.cjs.js.map +1 -0
- package/dist/{typography.es.js → leaf.es.js} +49 -12
- package/dist/leaf.es.js.map +1 -0
- package/dist/next.es.js +1 -1
- package/dist/rich-text.cjs.js +29 -43
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js +30 -44
- package/dist/rich-text.es.js.map +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/EditableText/useSyncWithBuilder.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +1 -5
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +21 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text/index.d.ts +0 -1
- package/dist/types/src/controls/rich-text/index.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text/translation.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text/types.d.ts +47 -27
- package/dist/types/src/controls/rich-text/types.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts +5 -0
- package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts.map +1 -0
- package/dist/types/src/slate/BlockPlugin/index.d.ts +9 -0
- package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -0
- package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +5 -0
- package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -0
- package/dist/types/src/slate/BlockPlugin/types.d.ts +4 -0
- package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/constants.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/dedent.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/indent.d.ts.map +1 -0
- package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/ListPlugin.d.ts → slate/ListPlugin/index.d.ts} +6 -2
- package/dist/types/src/slate/ListPlugin/index.d.ts.map +1 -0
- package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/toggleList.d.ts +1 -1
- package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/utils/filterForSubtreeRoots.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/utils/location.d.ts.map +1 -0
- package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/wrapList.d.ts +1 -1
- package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts +3 -0
- package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts +3 -0
- package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +4 -0
- package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/index.d.ts +15 -0
- package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts +3 -0
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +3 -0
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -0
- package/dist/types/src/slate/index.d.ts +4 -0
- package/dist/types/src/slate/index.d.ts.map +1 -0
- package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate}/utils/editor.d.ts +1 -1
- package/dist/types/src/slate/utils/editor.d.ts.map +1 -0
- package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate}/utils/element.d.ts +3 -5
- package/dist/types/src/slate/utils/element.d.ts.map +1 -0
- package/package.json +8 -1
- package/dist/compare.cjs.js +0 -126
- package/dist/compare.cjs.js.map +0 -1
- package/dist/compare.es.js +0 -124
- package/dist/compare.es.js.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/ListPlugin.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/constants.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts +0 -2
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/dedent.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/indent.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts +0 -6
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/toggleList.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/unwrapList.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/editor.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/element.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/filterForSubtreeRoots.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/getSelectedListItems.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/location.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/wrapList.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts +0 -48
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts +0 -21
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts +0 -2
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts +0 -27
- package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts.map +0 -1
- package/dist/types/src/controls/rich-text/compare.d.ts +0 -5
- package/dist/types/src/controls/rich-text/compare.d.ts.map +0 -1
- package/dist/types/src/controls/rich-text/compare.test.d.ts +0 -2
- package/dist/types/src/controls/rich-text/compare.test.d.ts.map +0 -1
- package/dist/typography.cjs.js.map +0 -1
- package/dist/typography.es.js.map +0 -1
- /package/dist/types/src/{components/builtin/Text/EditableText → slate}/ListPlugin/constants.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/dedent.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/indent.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/unwrapList.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/filterForSubtreeRoots.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/getSelectedListItems.d.ts +0 -0
- /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/location.d.ts +0 -0
package/dist/index.es.js
CHANGED
|
@@ -968,7 +968,7 @@ function useCachedSite(siteId) {
|
|
|
968
968
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
969
969
|
return site;
|
|
970
970
|
}
|
|
971
|
-
const version = "0.7.
|
|
971
|
+
const version = "0.7.15";
|
|
972
972
|
class Makeswift {
|
|
973
973
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
974
974
|
__publicField(this, "apiKey");
|
|
@@ -4150,5 +4150,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
4150
4150
|
document: document2
|
|
4151
4151
|
});
|
|
4152
4152
|
}));
|
|
4153
|
-
export {
|
|
4153
|
+
export { getStaticProps as $, Alignments as A, useFile as B, Contrasts as C, DocumentReference as D, Element$1 as E, DEVICES as F, findDeviceOverride as G, forwardNextDynamicRef as H, useIsPreview as I, useFiles as J, useSwatches as K, usePagePathnameSlice as L, useElementId as M, deepEqual as N, ElementImperativeHandle as O, PageProvider as P, storeContextDefaultValue as Q, RuntimeProvider as R, Shapes as S, StoreContext as T, MakeswiftProvider as U, useBuilderEditMode as V, pollBoxModel as W, useTypography as X, shallowMergeFallbacks as Y, MakeswiftClient as Z, getStaticPaths as _, ReactRuntime as a, getServerSideProps as a0, Page as a1, Makeswift as a2, PreviewModeScript as a3, Document$1 as a4, MakeswiftApiHandler as a5, usePageId as b, DEFAULT_BOX_ANIMATE_TYPE as c, DEFAULT_BOX_ANIMATE_DELAY as d, DEFAULT_BOX_ANIMATE_DURATION as e, DEFAULT_ITEM_ANIMATE_TYPE as f, DEFAULT_ITEM_ANIMATE_DELAY as g, DEFAULT_ITEM_ANIMATE_DURATION as h, DEFAULT_ITEM_STAGGER_DURATION as i, useBorder as j, useBoxShadow as k, useResponsiveColor as l, useMediaQuery as m, Page$1 as n, useStyle as o, responsiveWidth as p, responsiveTextStyle as q, responsiveStyle as r, colorToString as s, Sizes as t, useIsInBuilder as u, useFormContext as v, responsiveGridItem as w, useTable as x, useMakeswiftClient as y, Provider as z };
|
|
4154
4154
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es6.js
CHANGED
|
@@ -30,20 +30,19 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
import { useCallback, useState, useEffect, forwardRef, useImperativeHandle, useMemo } from "react";
|
|
33
|
-
import { Element as Element$1,
|
|
33
|
+
import { Element as Element$1, Editor, Path, Range, Point, Node, Transforms, Text, createEditor } from "slate";
|
|
34
34
|
import { withReact, ReactEditor, Slate, Editable } from "slate-react";
|
|
35
35
|
import { cx } from "@emotion/css";
|
|
36
36
|
import { g as getBox } from "./box-models.es.js";
|
|
37
|
-
import { au as
|
|
38
|
-
import {
|
|
37
|
+
import { au as BlockType, av as InlineType, ar as richTextDTOtoDAO, aq as richTextDTOtoSelection, ax as BuilderEditMode } from "./rich-text.es.js";
|
|
38
|
+
import { L as Leaf } from "./leaf.es.js";
|
|
39
|
+
import { o as useStyle, r as responsiveStyle, N as deepEqual, V as useBuilderEditMode, W as pollBoxModel } from "./index.es.js";
|
|
39
40
|
import { jsx } from "react/jsx-runtime";
|
|
41
|
+
import { L as Link } from "./index.es3.js";
|
|
42
|
+
import isHotkey from "is-hotkey";
|
|
40
43
|
import "use-sync-external-store/shim";
|
|
41
|
-
import { o as useStyle, r as responsiveStyle, V as useBuilderEditMode } from "./index.es.js";
|
|
42
44
|
import "@emotion/serialize";
|
|
43
45
|
import "@emotion/utils";
|
|
44
|
-
import { L as Link } from "./index.es3.js";
|
|
45
|
-
import { c as compareRichTextDAO, a as compareRichTextSelection } from "./compare.es.js";
|
|
46
|
-
import isHotkey from "is-hotkey";
|
|
47
46
|
import "css-box-model";
|
|
48
47
|
import "./actions.es.js";
|
|
49
48
|
import "./introspection.es.js";
|
|
@@ -69,23 +68,6 @@ import "set-cookie-parser";
|
|
|
69
68
|
import "uuid";
|
|
70
69
|
import "corporate-ipsum";
|
|
71
70
|
import "next/link";
|
|
72
|
-
function Leaf(_a) {
|
|
73
|
-
var _b = _a, {
|
|
74
|
-
leaf
|
|
75
|
-
} = _b, props = __objRest(_b, [
|
|
76
|
-
"leaf"
|
|
77
|
-
]);
|
|
78
|
-
switch (leaf.type) {
|
|
79
|
-
case TextType.Typography:
|
|
80
|
-
return /* @__PURE__ */ jsx(TypographyLeaf, __spreadValues({
|
|
81
|
-
leaf
|
|
82
|
-
}, props));
|
|
83
|
-
default:
|
|
84
|
-
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
85
|
-
children: props.children
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
71
|
function BlockElement({
|
|
90
72
|
element,
|
|
91
73
|
attributes,
|
|
@@ -170,10 +152,10 @@ function BlockElement({
|
|
|
170
152
|
}));
|
|
171
153
|
}
|
|
172
154
|
}
|
|
173
|
-
function StyledLink(
|
|
174
|
-
var
|
|
155
|
+
function StyledLink(_a) {
|
|
156
|
+
var _b = _a, {
|
|
175
157
|
className
|
|
176
|
-
} =
|
|
158
|
+
} = _b, restOfProps = __objRest(_b, [
|
|
177
159
|
"className"
|
|
178
160
|
]);
|
|
179
161
|
return /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({}, restOfProps), {
|
|
@@ -207,10 +189,10 @@ function InlineElement({
|
|
|
207
189
|
}));
|
|
208
190
|
}
|
|
209
191
|
}
|
|
210
|
-
function Element(
|
|
211
|
-
var
|
|
192
|
+
function Element(_c) {
|
|
193
|
+
var _d = _c, {
|
|
212
194
|
element
|
|
213
|
-
} =
|
|
195
|
+
} = _d, props = __objRest(_d, [
|
|
214
196
|
"element"
|
|
215
197
|
]);
|
|
216
198
|
switch (element.type) {
|
|
@@ -246,7 +228,7 @@ function useSyncWithBuilder(editor, text) {
|
|
|
246
228
|
if (shouldCommit && text) {
|
|
247
229
|
const nextValue = richTextDTOtoDAO(text);
|
|
248
230
|
const nextSelection = richTextDTOtoSelection(text);
|
|
249
|
-
if (!
|
|
231
|
+
if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {
|
|
250
232
|
editor.children = nextValue;
|
|
251
233
|
editor.selection = nextSelection;
|
|
252
234
|
editor.onChange();
|
|
@@ -265,15 +247,17 @@ function useSyncWithBuilder(editor, text) {
|
|
|
265
247
|
}, [shouldCommit]);
|
|
266
248
|
return useCallback(() => setShouldCommit(false), []);
|
|
267
249
|
}
|
|
250
|
+
const LIST_ITEM_CHILD_POSITION = 0;
|
|
251
|
+
const LIST_ITEM_LIST_POSITION = 1;
|
|
268
252
|
const ElementUtils = {
|
|
269
|
-
|
|
270
|
-
return
|
|
253
|
+
isBlock(node) {
|
|
254
|
+
return Element$1.isElement(node) && (Element$1.isElementType(node, BlockType.Paragraph) || Element$1.isElementType(node, BlockType.Heading1) || Element$1.isElementType(node, BlockType.Heading2) || Element$1.isElementType(node, BlockType.Heading3) || Element$1.isElementType(node, BlockType.Heading3) || Element$1.isElementType(node, BlockType.Heading4) || Element$1.isElementType(node, BlockType.Heading5) || Element$1.isElementType(node, BlockType.Heading6) || Element$1.isElementType(node, BlockType.BlockQuote) || Element$1.isElementType(node, BlockType.UnorderedList) || Element$1.isElementType(node, BlockType.OrderedList) || Element$1.isElementType(node, BlockType.ListItem) || Element$1.isElementType(node, BlockType.ListItemChild));
|
|
271
255
|
},
|
|
272
|
-
|
|
273
|
-
return Element$1.isElementType(node,
|
|
256
|
+
isInline(node) {
|
|
257
|
+
return Element$1.isElement(node) && (Element$1.isElementType(node, InlineType.Link) || Element$1.isElementType(node, InlineType.Link) || Element$1.isElementType(node, InlineType.SubScript) || Element$1.isElementType(node, InlineType.SuperScript));
|
|
274
258
|
},
|
|
275
|
-
|
|
276
|
-
return
|
|
259
|
+
isConvertibleToListTextNode(node) {
|
|
260
|
+
return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
|
|
277
261
|
},
|
|
278
262
|
isParagraph(node) {
|
|
279
263
|
return Element$1.isElementType(node, BlockType.Paragraph);
|
|
@@ -288,7 +272,7 @@ const ElementUtils = {
|
|
|
288
272
|
return Element$1.isElementType(node, BlockType.ListItemChild);
|
|
289
273
|
},
|
|
290
274
|
createText() {
|
|
291
|
-
return { text: ""
|
|
275
|
+
return { text: "" };
|
|
292
276
|
},
|
|
293
277
|
createParagraph() {
|
|
294
278
|
return {
|
|
@@ -312,36 +296,6 @@ const ElementUtils = {
|
|
|
312
296
|
};
|
|
313
297
|
}
|
|
314
298
|
};
|
|
315
|
-
function wrapList(editor, options = { type: BlockType.UnorderedList }) {
|
|
316
|
-
if (!editor.selection)
|
|
317
|
-
return;
|
|
318
|
-
const nonListEntries = Array.from(Editor.nodes(editor, {
|
|
319
|
-
at: editor.selection,
|
|
320
|
-
match: (node) => {
|
|
321
|
-
return Element$1.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
322
|
-
}
|
|
323
|
-
}));
|
|
324
|
-
const refs = nonListEntries.map(([_, path]) => Editor.pathRef(editor, path));
|
|
325
|
-
refs.forEach((ref) => {
|
|
326
|
-
const path = ref.current;
|
|
327
|
-
if (path) {
|
|
328
|
-
Editor.withoutNormalizing(editor, () => {
|
|
329
|
-
Transforms.setNodes(editor, { type: BlockType.ListItemChild }, {
|
|
330
|
-
at: path
|
|
331
|
-
});
|
|
332
|
-
Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
333
|
-
at: path
|
|
334
|
-
});
|
|
335
|
-
Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
336
|
-
at: path
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
ref.unref();
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
const LIST_ITEM_CHILD_POSITION = 0;
|
|
344
|
-
const LIST_ITEM_LIST_POSITION = 1;
|
|
345
299
|
const EditorUtils = {
|
|
346
300
|
getFirstAncestorList(editor, path) {
|
|
347
301
|
const parentList = Editor.above(editor, {
|
|
@@ -384,58 +338,6 @@ function getSelectedListItems(editor) {
|
|
|
384
338
|
const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
|
|
385
339
|
return Array.from(listItems).filter((node) => Path.isDescendant(start, node[1]) ? Path.equals(node[1], firstAncestorPath) : !Path.isAfter(start, node[1]));
|
|
386
340
|
}
|
|
387
|
-
function unwrapPath(editor, listItemPath) {
|
|
388
|
-
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
389
|
-
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
390
|
-
if (!parentList || listItemContainingParentList)
|
|
391
|
-
return;
|
|
392
|
-
Editor.withoutNormalizing(editor, () => {
|
|
393
|
-
const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
|
|
394
|
-
const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
|
|
395
|
-
if (Node.has(editor, listItemNestedListPath)) {
|
|
396
|
-
Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
|
|
397
|
-
Transforms.liftNodes(editor, { at: listItemNestedListPath });
|
|
398
|
-
Transforms.liftNodes(editor, { at: Path.next(listItemPath) });
|
|
399
|
-
}
|
|
400
|
-
if (Node.has(editor, listItemTextPath)) {
|
|
401
|
-
Transforms.setNodes(editor, { type: BlockType.Paragraph }, {
|
|
402
|
-
at: listItemTextPath
|
|
403
|
-
});
|
|
404
|
-
Transforms.liftNodes(editor, { at: listItemTextPath });
|
|
405
|
-
Transforms.liftNodes(editor, { at: listItemPath });
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
function unwrapList(editor) {
|
|
410
|
-
if (!editor.selection)
|
|
411
|
-
return;
|
|
412
|
-
const listItems = getSelectedListItems(editor);
|
|
413
|
-
const subRoots = filterForSubtreeRoots(listItems);
|
|
414
|
-
const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
|
|
415
|
-
refs.forEach((ref) => {
|
|
416
|
-
if (ref.current) {
|
|
417
|
-
unwrapPath(editor, ref.current);
|
|
418
|
-
}
|
|
419
|
-
ref.unref();
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
function toggleList(editor, options = { type: BlockType.UnorderedList }) {
|
|
423
|
-
if (!editor.selection)
|
|
424
|
-
return;
|
|
425
|
-
const start = LocationUtils.getStartPath(editor.selection);
|
|
426
|
-
const ancestorPath = Path.ancestors(start).at(1);
|
|
427
|
-
if (!ancestorPath || !Node.has(editor, ancestorPath))
|
|
428
|
-
return;
|
|
429
|
-
const ancestor = Node.get(editor, ancestorPath);
|
|
430
|
-
if (!ElementUtils.isList(ancestor)) {
|
|
431
|
-
return wrapList(editor, { type: options.type });
|
|
432
|
-
}
|
|
433
|
-
if (ancestor.type === options.type) {
|
|
434
|
-
unwrapList(editor);
|
|
435
|
-
} else {
|
|
436
|
-
Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
341
|
function indentPath(editor, path) {
|
|
440
342
|
const parent = Node.parent(editor, path);
|
|
441
343
|
if (!path || !Path.hasPrevious(path) || !ElementUtils.isList(parent))
|
|
@@ -509,6 +411,86 @@ function dedent(editor) {
|
|
|
509
411
|
ref.unref();
|
|
510
412
|
});
|
|
511
413
|
}
|
|
414
|
+
function unwrapPath(editor, listItemPath) {
|
|
415
|
+
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
416
|
+
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
417
|
+
if (!parentList || listItemContainingParentList)
|
|
418
|
+
return;
|
|
419
|
+
Editor.withoutNormalizing(editor, () => {
|
|
420
|
+
const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
|
|
421
|
+
const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
|
|
422
|
+
if (Node.has(editor, listItemNestedListPath)) {
|
|
423
|
+
Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
|
|
424
|
+
Transforms.liftNodes(editor, { at: listItemNestedListPath });
|
|
425
|
+
Transforms.liftNodes(editor, { at: Path.next(listItemPath) });
|
|
426
|
+
}
|
|
427
|
+
if (Node.has(editor, listItemTextPath)) {
|
|
428
|
+
Transforms.setNodes(editor, { type: BlockType.Paragraph }, {
|
|
429
|
+
at: listItemTextPath
|
|
430
|
+
});
|
|
431
|
+
Transforms.liftNodes(editor, { at: listItemTextPath });
|
|
432
|
+
Transforms.liftNodes(editor, { at: listItemPath });
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function unwrapList(editor) {
|
|
437
|
+
if (!editor.selection)
|
|
438
|
+
return;
|
|
439
|
+
const listItems = getSelectedListItems(editor);
|
|
440
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
441
|
+
const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
|
|
442
|
+
refs.forEach((ref) => {
|
|
443
|
+
if (ref.current) {
|
|
444
|
+
unwrapPath(editor, ref.current);
|
|
445
|
+
}
|
|
446
|
+
ref.unref();
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
function wrapList(editor, options = { type: BlockType.UnorderedList }) {
|
|
450
|
+
if (!editor.selection)
|
|
451
|
+
return;
|
|
452
|
+
const nonListEntries = Array.from(Editor.nodes(editor, {
|
|
453
|
+
at: editor.selection,
|
|
454
|
+
match: (node) => {
|
|
455
|
+
return Element$1.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
456
|
+
}
|
|
457
|
+
}));
|
|
458
|
+
const refs = nonListEntries.map(([_, path]) => Editor.pathRef(editor, path));
|
|
459
|
+
refs.forEach((ref) => {
|
|
460
|
+
const path = ref.current;
|
|
461
|
+
if (path) {
|
|
462
|
+
Editor.withoutNormalizing(editor, () => {
|
|
463
|
+
Transforms.setNodes(editor, { type: BlockType.ListItemChild }, {
|
|
464
|
+
at: path
|
|
465
|
+
});
|
|
466
|
+
Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
467
|
+
at: path
|
|
468
|
+
});
|
|
469
|
+
Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
470
|
+
at: path
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
ref.unref();
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function toggleList(editor, options = { type: BlockType.UnorderedList }) {
|
|
478
|
+
if (!editor.selection)
|
|
479
|
+
return;
|
|
480
|
+
const start = LocationUtils.getStartPath(editor.selection);
|
|
481
|
+
const ancestorPath = Path.ancestors(start).at(1);
|
|
482
|
+
if (!ancestorPath || !Node.has(editor, ancestorPath))
|
|
483
|
+
return;
|
|
484
|
+
const ancestor = Node.get(editor, ancestorPath);
|
|
485
|
+
if (!ElementUtils.isList(ancestor)) {
|
|
486
|
+
return wrapList(editor, { type: options.type });
|
|
487
|
+
}
|
|
488
|
+
if (ancestor.type === options.type) {
|
|
489
|
+
unwrapList(editor);
|
|
490
|
+
} else {
|
|
491
|
+
Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
492
|
+
}
|
|
493
|
+
}
|
|
512
494
|
const List = {
|
|
513
495
|
unwrapList,
|
|
514
496
|
wrapList,
|
|
@@ -575,6 +557,7 @@ function onKeyDown(e, editor) {
|
|
|
575
557
|
}
|
|
576
558
|
}
|
|
577
559
|
function withList(editor) {
|
|
560
|
+
const { normalizeNode } = editor;
|
|
578
561
|
editor.normalizeNode = (entry) => {
|
|
579
562
|
const [normalizationNode, normalizationPath] = entry;
|
|
580
563
|
if (ElementUtils.isListItem(normalizationNode)) {
|
|
@@ -594,18 +577,10 @@ function withList(editor) {
|
|
|
594
577
|
return;
|
|
595
578
|
}
|
|
596
579
|
}
|
|
597
|
-
if (
|
|
598
|
-
Array.from(Node.children(editor, normalizationPath)).forEach(([node, path]) => {
|
|
599
|
-
if (ElementUtils.isText(node)) {
|
|
600
|
-
Transforms.removeNodes(editor, { at: path });
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
if (!ElementUtils.isText(normalizationNode) && !ElementUtils.isTypography(normalizationNode)) {
|
|
580
|
+
if (!Text.isText(normalizationNode)) {
|
|
606
581
|
const mergeableChildren = Array.from(Node.children(editor, normalizationPath)).map((child, index, children) => {
|
|
607
582
|
const potentialNodeToBeMerged = children.at(index + 1);
|
|
608
|
-
if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
|
|
583
|
+
if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || !ElementUtils.isList(child[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
|
|
609
584
|
return null;
|
|
610
585
|
}
|
|
611
586
|
return [
|
|
@@ -636,13 +611,39 @@ function withList(editor) {
|
|
|
636
611
|
return;
|
|
637
612
|
}
|
|
638
613
|
}
|
|
614
|
+
normalizeNode(entry);
|
|
615
|
+
};
|
|
616
|
+
return editor;
|
|
617
|
+
}
|
|
618
|
+
function withTypography(editor) {
|
|
619
|
+
const { normalizeNode } = editor;
|
|
620
|
+
editor.normalizeNode = (entry) => {
|
|
621
|
+
var _a, _b;
|
|
622
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
623
|
+
if (Text.isText(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.typography) == null ? void 0 : _a.id) == null && ((_b = normalizationNode == null ? void 0 : normalizationNode.typography) == null ? void 0 : _b.style.length) === 0) {
|
|
624
|
+
Transforms.unsetNodes(editor, "typography", { at: normalizationPath });
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
normalizeNode(entry);
|
|
628
|
+
};
|
|
629
|
+
return editor;
|
|
630
|
+
}
|
|
631
|
+
function withBlock(editor) {
|
|
632
|
+
const { normalizeNode } = editor;
|
|
633
|
+
editor.normalizeNode = (entry) => {
|
|
634
|
+
var _a;
|
|
635
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
636
|
+
if (ElementUtils.isBlock(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.textAlign) == null ? void 0 : _a.length) == 0) {
|
|
637
|
+
Transforms.unsetNodes(editor, "textAlign", { at: normalizationPath });
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
normalizeNode(entry);
|
|
639
641
|
};
|
|
640
642
|
return editor;
|
|
641
643
|
}
|
|
642
644
|
const defaultText = [{
|
|
643
645
|
type: BlockType.Paragraph,
|
|
644
646
|
children: [{
|
|
645
|
-
type: TextType.Text,
|
|
646
647
|
text: ""
|
|
647
648
|
}]
|
|
648
649
|
}];
|
|
@@ -652,11 +653,20 @@ const EditableText = forwardRef(function EditableText2({
|
|
|
652
653
|
width,
|
|
653
654
|
margin
|
|
654
655
|
}, ref) {
|
|
655
|
-
const [editor] = useState(() => withList(withReact(createEditor())));
|
|
656
|
+
const [editor] = useState(() => withBlock(withTypography(withList(withReact(createEditor())))));
|
|
656
657
|
const delaySync = useSyncWithBuilder(editor, text);
|
|
657
658
|
const editMode = useBuilderEditMode();
|
|
658
659
|
const [propControllers, setPropControllers] = useState(null);
|
|
659
660
|
const controller = propControllers == null ? void 0 : propControllers.text;
|
|
661
|
+
useEffect(() => {
|
|
662
|
+
if (controller == null)
|
|
663
|
+
return;
|
|
664
|
+
const element = ReactEditor.toDOMNode(editor, editor);
|
|
665
|
+
return pollBoxModel({
|
|
666
|
+
element,
|
|
667
|
+
onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
|
|
668
|
+
});
|
|
669
|
+
}, [editor, controller]);
|
|
660
670
|
useImperativeHandle(ref, () => ({
|
|
661
671
|
getDomNode() {
|
|
662
672
|
return ReactEditor.toDOMNode(editor, editor);
|
|
@@ -693,7 +703,8 @@ const EditableText = forwardRef(function EditableText2({
|
|
|
693
703
|
onKeyDown: handleKeyDown,
|
|
694
704
|
onFocus: handleFocus,
|
|
695
705
|
className: cx(width, margin),
|
|
696
|
-
readOnly: editMode === BuilderEditMode.INTERACT
|
|
706
|
+
readOnly: editMode === BuilderEditMode.INTERACT,
|
|
707
|
+
placeholder: "Write some text..."
|
|
697
708
|
})
|
|
698
709
|
});
|
|
699
710
|
});
|