@makeswift/runtime 0.7.7 → 0.7.9
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/Box.cjs.js +2 -0
- package/dist/Box.cjs.js.map +1 -1
- package/dist/Box.es.js +2 -0
- package/dist/Box.es.js.map +1 -1
- package/dist/Button.cjs.js +2 -0
- package/dist/Button.cjs.js.map +1 -1
- package/dist/Button.es.js +2 -0
- package/dist/Button.es.js.map +1 -1
- package/dist/Carousel.cjs.js +2 -0
- package/dist/Carousel.cjs.js.map +1 -1
- package/dist/Carousel.es.js +2 -0
- package/dist/Carousel.es.js.map +1 -1
- package/dist/Countdown.cjs.js +2 -0
- package/dist/Countdown.cjs.js.map +1 -1
- package/dist/Countdown.es.js +2 -0
- package/dist/Countdown.es.js.map +1 -1
- package/dist/Divider.cjs.js +2 -0
- package/dist/Divider.cjs.js.map +1 -1
- package/dist/Divider.es.js +2 -0
- package/dist/Divider.es.js.map +1 -1
- package/dist/Embed.cjs.js +2 -0
- package/dist/Embed.cjs.js.map +1 -1
- package/dist/Embed.es.js +2 -0
- package/dist/Embed.es.js.map +1 -1
- package/dist/Form.cjs.js +3 -1
- package/dist/Form.cjs.js.map +1 -1
- package/dist/Form.es.js +3 -1
- package/dist/Form.es.js.map +1 -1
- package/dist/Image.cjs.js +2 -0
- package/dist/Image.cjs.js.map +1 -1
- package/dist/Image.es.js +2 -0
- package/dist/Image.es.js.map +1 -1
- package/dist/LiveProvider.cjs.js +2 -0
- package/dist/LiveProvider.cjs.js.map +1 -1
- package/dist/LiveProvider.es.js +3 -1
- package/dist/LiveProvider.es.js.map +1 -1
- package/dist/Navigation.cjs.js +2 -0
- package/dist/Navigation.cjs.js.map +1 -1
- package/dist/Navigation.es.js +2 -0
- package/dist/Navigation.es.js.map +1 -1
- package/dist/PreviewProvider.cjs.js +29 -23
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +33 -25
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +185 -153
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +182 -153
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/Root.cjs.js +2 -0
- package/dist/Root.cjs.js.map +1 -1
- package/dist/Root.es.js +2 -0
- package/dist/Root.es.js.map +1 -1
- package/dist/SocialLinks.cjs.js +2 -0
- package/dist/SocialLinks.cjs.js.map +1 -1
- package/dist/SocialLinks.es.js +2 -0
- package/dist/SocialLinks.es.js.map +1 -1
- package/dist/Text.cjs.js +3 -1
- package/dist/Text.cjs.js.map +1 -1
- package/dist/Text.es.js +3 -1
- package/dist/Text.es.js.map +1 -1
- package/dist/Video.cjs.js +2 -0
- package/dist/Video.cjs.js.map +1 -1
- package/dist/Video.es.js +2 -0
- package/dist/Video.es.js.map +1 -1
- package/dist/actions.cjs.js +1 -0
- package/dist/actions.cjs.js.map +1 -1
- package/dist/actions.es.js +1 -1
- package/dist/builder.cjs.js +2 -0
- package/dist/builder.cjs.js.map +1 -1
- package/dist/builder.es.js +2 -0
- package/dist/builder.es.js.map +1 -1
- package/dist/compare.cjs.js +126 -0
- package/dist/compare.cjs.js.map +1 -0
- package/dist/compare.es.js +124 -0
- package/dist/compare.es.js.map +1 -0
- package/dist/components.cjs.js +2 -0
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +2 -0
- package/dist/components.es.js.map +1 -1
- package/dist/constants.cjs.js +2 -0
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +2 -0
- package/dist/constants.es.js.map +1 -1
- package/dist/control-serialization.cjs.js +29 -0
- package/dist/control-serialization.cjs.js.map +1 -1
- package/dist/control-serialization.es.js +30 -0
- package/dist/control-serialization.es.js.map +1 -1
- package/dist/controls.cjs.js +13 -0
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +4 -1
- package/dist/controls.es.js.map +1 -1
- package/dist/index.cjs.js +6 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +2 -0
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs5.js +2 -0
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs6.js +663 -96
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.es.js +6 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +2 -0
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es5.js +2 -0
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +657 -95
- package/dist/index.es6.js.map +1 -1
- package/dist/main.cjs.js +2 -0
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.es.js +2 -0
- package/dist/main.es.js.map +1 -1
- package/dist/next.cjs.js +2 -0
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +2 -0
- package/dist/next.es.js.map +1 -1
- package/dist/prop-controllers.cjs.js +2 -0
- package/dist/prop-controllers.cjs.js.map +1 -1
- package/dist/prop-controllers.es.js +2 -0
- package/dist/prop-controllers.es.js.map +1 -1
- package/dist/react.cjs.js +2 -0
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.es.js +2 -0
- package/dist/react.es.js.map +1 -1
- package/dist/rich-text.cjs.js +894 -22
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js +888 -23
- package/dist/rich-text.es.js.map +1 -1
- package/dist/types/src/components/builtin/Button/Button.d.ts +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/ListPlugin/ListPlugin.d.ts +13 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/ListPlugin.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/constants.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/constants.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts +2 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/dedent.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/dedent.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/indent.d.ts +4 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/indent.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts +6 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/toggleList.d.ts +8 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/toggleList.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/unwrapList.d.ts +4 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/unwrapList.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/editor.d.ts +7 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/editor.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/element.d.ts +26 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/element.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/filterForSubtreeRoots.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/filterForSubtreeRoots.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/getSelectedListItems.d.ts +5 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/getSelectedListItems.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/location.d.ts +5 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/location.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/wrapList.d.ts +8 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/wrapList.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts +48 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts +21 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts +2 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts +13 -0
- package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/index.d.ts +4 -0
- package/dist/types/src/components/builtin/Text/EditableText/index.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/EditableText/useSyncWithBuilder.d.ts +8 -0
- package/dist/types/src/components/builtin/Text/EditableText/useSyncWithBuilder.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +16 -0
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/Text.d.ts +1 -1
- package/dist/types/src/components/builtin/Text/Text.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Element/block.d.ts +8 -0
- package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Element/element.d.ts +4 -0
- package/dist/types/src/components/builtin/Text/components/Element/element.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Element/index.d.ts +2 -0
- package/dist/types/src/components/builtin/Text/components/Element/index.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts +8 -0
- package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +4 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts +27 -0
- package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/components/index.d.ts +3 -0
- package/dist/types/src/components/builtin/Text/components/index.d.ts.map +1 -0
- package/dist/types/src/components/utils/types.d.ts +1 -1
- package/dist/types/src/components/utils/types.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text/compare.d.ts +5 -0
- package/dist/types/src/controls/rich-text/compare.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/compare.test.d.ts +2 -0
- package/dist/types/src/controls/rich-text/compare.test.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/dto-types.d.ts +131 -0
- package/dist/types/src/controls/rich-text/dto-types.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/fixtures/blockquote.d.ts +3 -0
- package/dist/types/src/controls/rich-text/fixtures/blockquote.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/fixtures/index.d.ts +4 -0
- package/dist/types/src/controls/rich-text/fixtures/index.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/fixtures/list.d.ts +3 -0
- package/dist/types/src/controls/rich-text/fixtures/list.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/fixtures/typography.d.ts +3 -0
- package/dist/types/src/controls/rich-text/fixtures/typography.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/index.d.ts +6 -0
- package/dist/types/src/controls/rich-text/index.d.ts.map +1 -0
- package/dist/types/src/controls/{rich-text.d.ts → rich-text/rich-text.d.ts} +8 -10
- package/dist/types/src/controls/rich-text/rich-text.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/translation.d.ts +8 -0
- package/dist/types/src/controls/rich-text/translation.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/translation.test.d.ts +2 -0
- package/dist/types/src/controls/rich-text/translation.test.d.ts.map +1 -0
- package/dist/types/src/controls/rich-text/types.d.ts +134 -0
- package/dist/types/src/controls/rich-text/types.d.ts.map +1 -0
- package/dist/types/src/prop-controllers/descriptors.d.ts +2 -3
- package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts +4 -7
- package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/element-imperative-handle.d.ts.map +1 -1
- package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
- package/dist/typography.cjs.js +146 -0
- package/dist/typography.cjs.js.map +1 -0
- package/dist/typography.es.js +143 -0
- package/dist/typography.es.js.map +1 -0
- package/package.json +7 -10
- package/dist/EditableText.cjs.js +0 -380
- package/dist/EditableText.cjs.js.map +0 -1
- package/dist/EditableText.es.js +0 -373
- package/dist/EditableText.es.js.map +0 -1
- package/dist/types/src/components/builtin/Text/EditableText.d.ts +0 -16
- package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Block/index.d.ts +0 -10
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Block/index.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.d.ts +0 -25
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Mark/hooks/useTypographyMark.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Mark/index.d.ts +0 -10
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/components/Mark/index.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/index.d.ts +0 -5
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesBlocks.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/DeviceOverridesMarks.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/Inlines.d.ts.map +0 -1
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/Link.d.ts +0 -3
- package/dist/types/src/components/builtin/Text/components/RichTextEditor/plugins/Link.d.ts.map +0 -1
- package/dist/types/src/controls/rich-text.d.ts.map +0 -1
package/dist/index.es6.js
CHANGED
|
@@ -29,111 +29,673 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
32
|
+
import { useCallback, useState, useEffect, forwardRef, useImperativeHandle, useMemo } from "react";
|
|
33
|
+
import { Element as Element$1, Text, Editor, Transforms, Path, Range, Point, Node, createEditor } from "slate";
|
|
34
|
+
import { withReact, ReactEditor, Slate, Editable } from "slate-react";
|
|
34
35
|
import { cx } from "@emotion/css";
|
|
36
|
+
import { g as getBox } from "./box-models.es.js";
|
|
37
|
+
import { au as TextType, av as BlockType, aw as InlineType, ar as richTextDTOtoDAO, aq as richTextDTOtoSelection, ax as BuilderEditMode } from "./rich-text.es.js";
|
|
38
|
+
import { T as TypographyLeaf } from "./typography.es.js";
|
|
35
39
|
import { jsx } from "react/jsx-runtime";
|
|
36
|
-
import
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
import "use-sync-external-store/shim";
|
|
41
|
+
import { o as useStyle, r as responsiveStyle, V as useBuilderEditMode } from "./index.es.js";
|
|
42
|
+
import "@emotion/serialize";
|
|
43
|
+
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
|
+
import "css-box-model";
|
|
48
|
+
import "./actions.es.js";
|
|
49
|
+
import "./constants.es.js";
|
|
50
|
+
import "redux";
|
|
51
|
+
import "redux-thunk";
|
|
52
|
+
import "use-sync-external-store/shim/with-selector";
|
|
53
|
+
import "next/dynamic";
|
|
54
|
+
import "./text-input.es.js";
|
|
55
|
+
import "./combobox.es.js";
|
|
56
|
+
import "./types.es.js";
|
|
57
|
+
import "color";
|
|
58
|
+
import "scroll-into-view-if-needed";
|
|
59
|
+
import "react-dom";
|
|
60
|
+
import "html-react-parser";
|
|
61
|
+
import "next/head";
|
|
62
|
+
import "@emotion/server/create-instance";
|
|
63
|
+
import "next/document";
|
|
64
|
+
import "cookie";
|
|
65
|
+
import "cors";
|
|
66
|
+
import "http-proxy";
|
|
67
|
+
import "set-cookie-parser";
|
|
68
|
+
import "uuid/v4";
|
|
69
|
+
import "corporate-ipsum";
|
|
70
|
+
import "next/link";
|
|
71
|
+
function Leaf(_a) {
|
|
39
72
|
var _b = _a, {
|
|
40
|
-
|
|
41
|
-
} = _b,
|
|
42
|
-
"
|
|
73
|
+
leaf
|
|
74
|
+
} = _b, props = __objRest(_b, [
|
|
75
|
+
"leaf"
|
|
43
76
|
]);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
switch (leaf.type) {
|
|
78
|
+
case TextType.Typography:
|
|
79
|
+
return /* @__PURE__ */ jsx(TypographyLeaf, __spreadValues({
|
|
80
|
+
leaf
|
|
81
|
+
}, props));
|
|
82
|
+
default:
|
|
83
|
+
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
84
|
+
children: props.children
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function BlockElement({
|
|
89
|
+
element,
|
|
90
|
+
attributes,
|
|
91
|
+
children
|
|
92
|
+
}) {
|
|
93
|
+
const blockStyles = [useStyle({
|
|
94
|
+
margin: 0
|
|
95
|
+
}), useStyle(responsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
|
|
96
|
+
textAlign
|
|
97
|
+
})))];
|
|
98
|
+
switch (element.type) {
|
|
99
|
+
case BlockType.Paragraph:
|
|
100
|
+
return /* @__PURE__ */ jsx("p", __spreadProps(__spreadValues({}, attributes), {
|
|
101
|
+
className: cx(...blockStyles),
|
|
102
|
+
children
|
|
103
|
+
}));
|
|
104
|
+
case BlockType.Heading1:
|
|
105
|
+
return /* @__PURE__ */ jsx("h1", __spreadProps(__spreadValues({}, attributes), {
|
|
106
|
+
className: cx(...blockStyles),
|
|
107
|
+
children
|
|
108
|
+
}));
|
|
109
|
+
case BlockType.Heading2:
|
|
110
|
+
return /* @__PURE__ */ jsx("h2", __spreadProps(__spreadValues({}, attributes), {
|
|
111
|
+
className: cx(...blockStyles),
|
|
112
|
+
children
|
|
113
|
+
}));
|
|
114
|
+
case BlockType.Heading3:
|
|
115
|
+
return /* @__PURE__ */ jsx("h3", __spreadProps(__spreadValues({}, attributes), {
|
|
116
|
+
className: cx(...blockStyles),
|
|
117
|
+
children
|
|
118
|
+
}));
|
|
119
|
+
case BlockType.Heading4:
|
|
120
|
+
return /* @__PURE__ */ jsx("h4", __spreadProps(__spreadValues({}, attributes), {
|
|
121
|
+
className: cx(...blockStyles),
|
|
122
|
+
children
|
|
123
|
+
}));
|
|
124
|
+
case BlockType.Heading5:
|
|
125
|
+
return /* @__PURE__ */ jsx("h5", __spreadProps(__spreadValues({}, attributes), {
|
|
126
|
+
className: cx(...blockStyles),
|
|
127
|
+
children
|
|
128
|
+
}));
|
|
129
|
+
case BlockType.Heading6:
|
|
130
|
+
return /* @__PURE__ */ jsx("h6", __spreadProps(__spreadValues({}, attributes), {
|
|
131
|
+
className: cx(...blockStyles),
|
|
132
|
+
children
|
|
133
|
+
}));
|
|
134
|
+
case BlockType.BlockQuote:
|
|
135
|
+
return /* @__PURE__ */ jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
|
|
136
|
+
className: cx(...blockStyles, useStyle({
|
|
137
|
+
padding: "0.5em 10px",
|
|
138
|
+
fontSize: "1.25em",
|
|
139
|
+
fontWeight: "300",
|
|
140
|
+
borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
|
|
141
|
+
})),
|
|
142
|
+
children
|
|
143
|
+
}));
|
|
144
|
+
case BlockType.OrderedList:
|
|
145
|
+
return /* @__PURE__ */ jsx("ol", __spreadProps(__spreadValues({}, attributes), {
|
|
146
|
+
className: cx(...blockStyles),
|
|
147
|
+
style: {
|
|
148
|
+
listStylePosition: "inside"
|
|
149
|
+
},
|
|
150
|
+
children
|
|
151
|
+
}));
|
|
152
|
+
case BlockType.UnorderedList:
|
|
153
|
+
return /* @__PURE__ */ jsx("ul", __spreadProps(__spreadValues({}, attributes), {
|
|
154
|
+
className: cx(...blockStyles),
|
|
155
|
+
style: {
|
|
156
|
+
listStylePosition: "inside"
|
|
157
|
+
},
|
|
158
|
+
children
|
|
159
|
+
}));
|
|
160
|
+
case BlockType.ListItem:
|
|
161
|
+
return /* @__PURE__ */ jsx("li", __spreadProps(__spreadValues({}, attributes), {
|
|
162
|
+
className: cx(...blockStyles),
|
|
163
|
+
children
|
|
164
|
+
}));
|
|
165
|
+
case BlockType.ListItemChild:
|
|
166
|
+
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, attributes), {
|
|
167
|
+
className: cx(...blockStyles),
|
|
168
|
+
children
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function StyledLink(_c) {
|
|
173
|
+
var _d = _c, {
|
|
73
174
|
className
|
|
74
|
-
} =
|
|
75
|
-
"value",
|
|
175
|
+
} = _d, restOfProps = __objRest(_d, [
|
|
76
176
|
"className"
|
|
77
177
|
]);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fontSize,
|
|
83
|
-
fontWeight,
|
|
84
|
-
lineHeight,
|
|
85
|
-
letterSpacing,
|
|
86
|
-
uppercase,
|
|
87
|
-
underline,
|
|
88
|
-
strikethrough,
|
|
89
|
-
italic
|
|
90
|
-
} = {}]) => __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, color == null ? {} : {
|
|
91
|
-
color: colorToString(color)
|
|
92
|
-
}), fontFamily == null ? {} : {
|
|
93
|
-
fontFamily: `"${fontFamily}"`
|
|
94
|
-
}), fontSize == null || fontSize.value == null || fontSize.unit == null ? {} : {
|
|
95
|
-
fontSize: `${fontSize.value}${fontSize.unit}`
|
|
96
|
-
}), fontWeight == null ? {} : {
|
|
97
|
-
fontWeight
|
|
98
|
-
}), lineHeight == null ? {} : {
|
|
99
|
-
lineHeight
|
|
100
|
-
}), letterSpacing == null ? {} : {
|
|
101
|
-
letterSpacing: `${letterSpacing / 10}em`
|
|
102
|
-
}), uppercase == null ? {} : {
|
|
103
|
-
textTransform: uppercase === true ? "uppercase" : "initial"
|
|
104
|
-
}), underline == null && strikethrough == null ? {} : {
|
|
105
|
-
textDecoration: [Boolean(underline) && "underline", Boolean(strikethrough) && "line-through"].filter(Boolean).join(" ")
|
|
106
|
-
}), italic == null ? {} : {
|
|
107
|
-
fontStyle: italic === true ? "italic" : "initial"
|
|
108
|
-
}), shallowMergeFallbacks));
|
|
109
|
-
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, restOfProps), {
|
|
110
|
-
className: cx(typographyClassName, className)
|
|
178
|
+
return /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({}, restOfProps), {
|
|
179
|
+
className: cx(useStyle({
|
|
180
|
+
textDecoration: "none"
|
|
181
|
+
}), className)
|
|
111
182
|
}));
|
|
112
183
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
184
|
+
function InlineElement({
|
|
185
|
+
element,
|
|
186
|
+
attributes,
|
|
187
|
+
children
|
|
188
|
+
}) {
|
|
189
|
+
switch (element.type) {
|
|
190
|
+
case InlineType.Code:
|
|
191
|
+
return /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({}, attributes), {
|
|
192
|
+
children
|
|
193
|
+
}));
|
|
194
|
+
case InlineType.SuperScript:
|
|
195
|
+
return /* @__PURE__ */ jsx("sup", __spreadProps(__spreadValues({}, attributes), {
|
|
196
|
+
children
|
|
197
|
+
}));
|
|
198
|
+
case InlineType.SubScript:
|
|
199
|
+
return /* @__PURE__ */ jsx("sub", __spreadProps(__spreadValues({}, attributes), {
|
|
200
|
+
children
|
|
201
|
+
}));
|
|
202
|
+
case InlineType.Link:
|
|
203
|
+
return /* @__PURE__ */ jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
|
|
204
|
+
link: element.link,
|
|
205
|
+
children
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function Element(_e) {
|
|
210
|
+
var _f = _e, {
|
|
211
|
+
element
|
|
212
|
+
} = _f, props = __objRest(_f, [
|
|
213
|
+
"element"
|
|
122
214
|
]);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
215
|
+
switch (element.type) {
|
|
216
|
+
case InlineType.Code:
|
|
217
|
+
case InlineType.SuperScript:
|
|
218
|
+
case InlineType.SubScript:
|
|
219
|
+
case InlineType.Link:
|
|
220
|
+
return /* @__PURE__ */ jsx(InlineElement, __spreadValues({
|
|
221
|
+
element
|
|
222
|
+
}, props));
|
|
223
|
+
case BlockType.Paragraph:
|
|
224
|
+
case BlockType.Heading1:
|
|
225
|
+
case BlockType.Heading2:
|
|
226
|
+
case BlockType.Heading3:
|
|
227
|
+
case BlockType.BlockQuote:
|
|
228
|
+
case BlockType.OrderedList:
|
|
229
|
+
case BlockType.UnorderedList:
|
|
230
|
+
case BlockType.ListItem:
|
|
231
|
+
case BlockType.ListItemChild:
|
|
232
|
+
return /* @__PURE__ */ jsx(BlockElement, __spreadValues({
|
|
233
|
+
element
|
|
234
|
+
}, props));
|
|
235
|
+
default:
|
|
236
|
+
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
237
|
+
children: props.children
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const COMMIT_DEBOUNCE_DELAY = 500;
|
|
242
|
+
function useSyncWithBuilder(editor, text) {
|
|
243
|
+
const [shouldCommit, setShouldCommit] = useState(true);
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (shouldCommit && text) {
|
|
246
|
+
const nextValue = richTextDTOtoDAO(text);
|
|
247
|
+
const nextSelection = richTextDTOtoSelection(text);
|
|
248
|
+
if (!compareRichTextDAO(editor.children, nextValue) || !compareRichTextSelection(editor.selection, nextSelection)) {
|
|
249
|
+
editor.children = nextValue;
|
|
250
|
+
editor.selection = nextSelection;
|
|
251
|
+
editor.onChange();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, [editor, shouldCommit, text]);
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (shouldCommit)
|
|
257
|
+
return;
|
|
258
|
+
const timeoutId = window.setTimeout(() => {
|
|
259
|
+
setShouldCommit(true);
|
|
260
|
+
}, COMMIT_DEBOUNCE_DELAY);
|
|
261
|
+
return () => {
|
|
262
|
+
window.clearTimeout(timeoutId);
|
|
263
|
+
};
|
|
264
|
+
}, [shouldCommit]);
|
|
265
|
+
return useCallback(() => setShouldCommit(false), []);
|
|
266
|
+
}
|
|
267
|
+
const ElementUtils = {
|
|
268
|
+
isConvertibleToListTextNode(node) {
|
|
269
|
+
return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node) && !this.isText(node) && !this.isTypography(node);
|
|
270
|
+
},
|
|
271
|
+
isText(node) {
|
|
272
|
+
return Element$1.isElementType(node, TextType.Text) || Text.isText(node);
|
|
273
|
+
},
|
|
274
|
+
isTypography(node) {
|
|
275
|
+
return Element$1.isElementType(node, TextType.Typography);
|
|
276
|
+
},
|
|
277
|
+
isParagraph(node) {
|
|
278
|
+
return Element$1.isElementType(node, BlockType.Paragraph);
|
|
279
|
+
},
|
|
280
|
+
isList(node) {
|
|
281
|
+
return Element$1.isElementType(node, BlockType.OrderedList) || Element$1.isElementType(node, BlockType.UnorderedList);
|
|
282
|
+
},
|
|
283
|
+
isListItem(node) {
|
|
284
|
+
return Element$1.isElementType(node, BlockType.ListItem);
|
|
285
|
+
},
|
|
286
|
+
isListItemChild(node) {
|
|
287
|
+
return Element$1.isElementType(node, BlockType.ListItemChild);
|
|
288
|
+
},
|
|
289
|
+
createText() {
|
|
290
|
+
return { text: "", type: TextType.Text };
|
|
291
|
+
},
|
|
292
|
+
createParagraph() {
|
|
293
|
+
return {
|
|
294
|
+
children: [this.createText()],
|
|
295
|
+
type: BlockType.Paragraph
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
createList(type = BlockType.UnorderedList) {
|
|
299
|
+
return { children: [this.createText()], type };
|
|
300
|
+
},
|
|
301
|
+
createListItem() {
|
|
302
|
+
return {
|
|
303
|
+
children: [this.createListItemChild()],
|
|
304
|
+
type: BlockType.ListItem
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
createListItemChild() {
|
|
308
|
+
return {
|
|
309
|
+
children: [this.createText()],
|
|
310
|
+
type: BlockType.ListItemChild
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
function wrapList(editor, options = { type: BlockType.UnorderedList }) {
|
|
315
|
+
if (!editor.selection)
|
|
316
|
+
return;
|
|
317
|
+
const nonListEntries = Array.from(Editor.nodes(editor, {
|
|
318
|
+
at: editor.selection,
|
|
319
|
+
match: (node) => {
|
|
320
|
+
return Element$1.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
323
|
+
const refs = nonListEntries.map(([_, path]) => Editor.pathRef(editor, path));
|
|
324
|
+
refs.forEach((ref) => {
|
|
325
|
+
const path = ref.current;
|
|
326
|
+
if (path) {
|
|
327
|
+
Editor.withoutNormalizing(editor, () => {
|
|
328
|
+
Transforms.setNodes(editor, { type: BlockType.ListItemChild }, {
|
|
329
|
+
at: path
|
|
330
|
+
});
|
|
331
|
+
Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
332
|
+
at: path
|
|
333
|
+
});
|
|
334
|
+
Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
335
|
+
at: path
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
ref.unref();
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
const LIST_ITEM_CHILD_POSITION = 0;
|
|
343
|
+
const LIST_ITEM_LIST_POSITION = 1;
|
|
344
|
+
const EditorUtils = {
|
|
345
|
+
getFirstAncestorList(editor, path) {
|
|
346
|
+
const parentList = Editor.above(editor, {
|
|
347
|
+
at: path,
|
|
348
|
+
match: (node) => ElementUtils.isList(node)
|
|
349
|
+
});
|
|
350
|
+
return parentList != null ? parentList : null;
|
|
351
|
+
},
|
|
352
|
+
getFirstAncestorListItem(editor, path) {
|
|
353
|
+
const parentListItem = Editor.above(editor, {
|
|
354
|
+
at: path,
|
|
355
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
356
|
+
});
|
|
357
|
+
return parentListItem != null ? parentListItem : null;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
function filterForSubtreeRoots(entries) {
|
|
361
|
+
return entries.filter(([, nodePath]) => !Path.ancestors(nodePath).some((ancestor) => {
|
|
362
|
+
return entries.some(([, path]) => Path.equals(path, ancestor));
|
|
136
363
|
}));
|
|
364
|
+
}
|
|
365
|
+
const LocationUtils = {
|
|
366
|
+
getStartPath(location) {
|
|
367
|
+
if (Range.isRange(location))
|
|
368
|
+
return Range.start(location).path;
|
|
369
|
+
if (Point.isPoint(location))
|
|
370
|
+
return location.path;
|
|
371
|
+
return location;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
function getSelectedListItems(editor) {
|
|
375
|
+
var _a, _b;
|
|
376
|
+
if (!editor.selection)
|
|
377
|
+
return [];
|
|
378
|
+
const start = LocationUtils.getStartPath(editor.selection);
|
|
379
|
+
const listItems = Editor.nodes(editor, {
|
|
380
|
+
at: editor.selection,
|
|
381
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
382
|
+
});
|
|
383
|
+
const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
|
|
384
|
+
return Array.from(listItems).filter((node) => Path.isDescendant(start, node[1]) ? Path.equals(node[1], firstAncestorPath) : !Path.isAfter(start, node[1]));
|
|
385
|
+
}
|
|
386
|
+
function unwrapPath(editor, listItemPath) {
|
|
387
|
+
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
388
|
+
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
389
|
+
if (!parentList || listItemContainingParentList)
|
|
390
|
+
return;
|
|
391
|
+
Editor.withoutNormalizing(editor, () => {
|
|
392
|
+
const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
|
|
393
|
+
const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
|
|
394
|
+
if (Node.has(editor, listItemNestedListPath)) {
|
|
395
|
+
Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
|
|
396
|
+
Transforms.liftNodes(editor, { at: listItemNestedListPath });
|
|
397
|
+
Transforms.liftNodes(editor, { at: Path.next(listItemPath) });
|
|
398
|
+
}
|
|
399
|
+
if (Node.has(editor, listItemTextPath)) {
|
|
400
|
+
Transforms.setNodes(editor, { type: BlockType.Paragraph }, {
|
|
401
|
+
at: listItemTextPath
|
|
402
|
+
});
|
|
403
|
+
Transforms.liftNodes(editor, { at: listItemTextPath });
|
|
404
|
+
Transforms.liftNodes(editor, { at: listItemPath });
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function unwrapList(editor) {
|
|
409
|
+
if (!editor.selection)
|
|
410
|
+
return;
|
|
411
|
+
const listItems = getSelectedListItems(editor);
|
|
412
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
413
|
+
const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
|
|
414
|
+
refs.forEach((ref) => {
|
|
415
|
+
if (ref.current) {
|
|
416
|
+
unwrapPath(editor, ref.current);
|
|
417
|
+
}
|
|
418
|
+
ref.unref();
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function toggleList(editor, options = { type: BlockType.UnorderedList }) {
|
|
422
|
+
if (!editor.selection)
|
|
423
|
+
return;
|
|
424
|
+
const start = LocationUtils.getStartPath(editor.selection);
|
|
425
|
+
const ancestorPath = Path.ancestors(start).at(1);
|
|
426
|
+
if (!ancestorPath || !Node.has(editor, ancestorPath))
|
|
427
|
+
return;
|
|
428
|
+
const ancestor = Node.get(editor, ancestorPath);
|
|
429
|
+
if (!ElementUtils.isList(ancestor)) {
|
|
430
|
+
return wrapList(editor, { type: options.type });
|
|
431
|
+
}
|
|
432
|
+
if (ancestor.type === options.type) {
|
|
433
|
+
unwrapList(editor);
|
|
434
|
+
} else {
|
|
435
|
+
Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function indentPath(editor, path) {
|
|
439
|
+
const parent = Node.parent(editor, path);
|
|
440
|
+
if (!path || !Path.hasPrevious(path) || !ElementUtils.isList(parent))
|
|
441
|
+
return;
|
|
442
|
+
const previosPath = Path.previous(path);
|
|
443
|
+
const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION];
|
|
444
|
+
const previousHasChildList = Node.has(editor, previousChildListPath);
|
|
445
|
+
Editor.withoutNormalizing(editor, () => {
|
|
446
|
+
if (!previousHasChildList) {
|
|
447
|
+
Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {
|
|
448
|
+
at: previousChildListPath
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
const previousChildList = Node.get(editor, previousChildListPath);
|
|
452
|
+
if (ElementUtils.isList(previousChildList)) {
|
|
453
|
+
const index = previousHasChildList ? previousChildList.children.length : 0;
|
|
454
|
+
Transforms.moveNodes(editor, {
|
|
455
|
+
at: path,
|
|
456
|
+
to: [...previousChildListPath, index]
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function indent(editor) {
|
|
462
|
+
if (!editor.selection)
|
|
463
|
+
return;
|
|
464
|
+
const listItems = getSelectedListItems(editor);
|
|
465
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
466
|
+
const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
|
|
467
|
+
refs.forEach((ref) => {
|
|
468
|
+
if (ref.current) {
|
|
469
|
+
indentPath(editor, ref.current);
|
|
470
|
+
}
|
|
471
|
+
ref.unref();
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
function dedentPath(editor, listItemPath) {
|
|
475
|
+
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
476
|
+
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
477
|
+
if (!parentList || !listItemContainingParentList)
|
|
478
|
+
return;
|
|
479
|
+
const [parentListNode, parentListPath] = parentList;
|
|
480
|
+
const [_, listItemContainingParentListPath] = listItemContainingParentList;
|
|
481
|
+
const listItemPosition = listItemPath[listItemPath.length - 1];
|
|
482
|
+
const previousSiblings = parentListNode.children.slice(0, listItemPosition);
|
|
483
|
+
const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
|
|
484
|
+
Editor.withoutNormalizing(editor, () => {
|
|
485
|
+
nextSiblings.forEach(() => {
|
|
486
|
+
const nextSiblingPath = [...parentListPath, listItemPosition + 1];
|
|
487
|
+
indentPath(editor, nextSiblingPath);
|
|
488
|
+
});
|
|
489
|
+
Transforms.moveNodes(editor, {
|
|
490
|
+
at: listItemPath,
|
|
491
|
+
to: Path.next(listItemContainingParentListPath)
|
|
492
|
+
});
|
|
493
|
+
if (previousSiblings.length === 0) {
|
|
494
|
+
Transforms.removeNodes(editor, { at: parentListPath });
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function dedent(editor) {
|
|
499
|
+
if (!editor.selection)
|
|
500
|
+
return;
|
|
501
|
+
const listItems = getSelectedListItems(editor);
|
|
502
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
503
|
+
const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
|
|
504
|
+
refs.forEach((ref) => {
|
|
505
|
+
if (ref.current) {
|
|
506
|
+
dedentPath(editor, ref.current);
|
|
507
|
+
}
|
|
508
|
+
ref.unref();
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
const List = {
|
|
512
|
+
unwrapList,
|
|
513
|
+
wrapList,
|
|
514
|
+
indent,
|
|
515
|
+
dedent,
|
|
516
|
+
toggleList
|
|
517
|
+
};
|
|
518
|
+
function onKeyDown(e, editor) {
|
|
519
|
+
if (!editor.selection || Array.from(Editor.nodes(editor, { match: (node) => ElementUtils.isListItem(node) })).length === 0)
|
|
520
|
+
return;
|
|
521
|
+
if (isHotkey("shift+tab", e)) {
|
|
522
|
+
e.preventDefault();
|
|
523
|
+
List.dedent(editor);
|
|
524
|
+
}
|
|
525
|
+
if (isHotkey("tab", e)) {
|
|
526
|
+
e.preventDefault();
|
|
527
|
+
List.indent(editor);
|
|
528
|
+
}
|
|
529
|
+
if (isHotkey("backspace", e)) {
|
|
530
|
+
if (!editor.selection)
|
|
531
|
+
return;
|
|
532
|
+
if (Range.isExpanded(editor.selection))
|
|
533
|
+
return;
|
|
534
|
+
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
535
|
+
if (editor.selection.anchor.offset === 0 && listItem) {
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
538
|
+
const list = EditorUtils.getFirstAncestorList(editor, listItem[1]);
|
|
539
|
+
if (parentListItem) {
|
|
540
|
+
List.dedent(editor);
|
|
541
|
+
} else if (list) {
|
|
542
|
+
List.unwrapList(editor);
|
|
543
|
+
}
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (isHotkey("enter", e)) {
|
|
548
|
+
e.preventDefault();
|
|
549
|
+
if (!editor.selection)
|
|
550
|
+
return;
|
|
551
|
+
if (Range.isExpanded(editor.selection)) {
|
|
552
|
+
Transforms.delete(editor);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
556
|
+
if (editor.selection.anchor.offset === 0 && listItem && Editor.string(editor, listItem[1]) === "") {
|
|
557
|
+
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
558
|
+
if (parentListItem) {
|
|
559
|
+
List.dedent(editor);
|
|
560
|
+
} else {
|
|
561
|
+
List.unwrapList(editor);
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
Transforms.splitNodes(editor, {
|
|
566
|
+
at: editor.selection,
|
|
567
|
+
always: true,
|
|
568
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if (isHotkey("shift+enter", e)) {
|
|
572
|
+
e.preventDefault();
|
|
573
|
+
editor.insertText("\n");
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function withList(editor) {
|
|
577
|
+
editor.normalizeNode = (entry) => {
|
|
578
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
579
|
+
if (ElementUtils.isListItem(normalizationNode)) {
|
|
580
|
+
const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION];
|
|
581
|
+
if (Node.has(editor, pathToListItemText)) {
|
|
582
|
+
const nodeInListItemTextPosition = Node.get(editor, pathToListItemText);
|
|
583
|
+
if (ElementUtils.isParagraph(nodeInListItemTextPosition)) {
|
|
584
|
+
Transforms.setNodes(editor, { type: BlockType.ListItemChild }, {
|
|
585
|
+
at: pathToListItemText
|
|
586
|
+
});
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
Transforms.insertNodes(editor, ElementUtils.createListItem(), {
|
|
591
|
+
at: pathToListItemText
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (ElementUtils.isList(normalizationNode)) {
|
|
597
|
+
Array.from(Node.children(editor, normalizationPath)).forEach(([node, path]) => {
|
|
598
|
+
if (ElementUtils.isText(node)) {
|
|
599
|
+
Transforms.removeNodes(editor, { at: path });
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
if (!ElementUtils.isText(normalizationNode) && !ElementUtils.isTypography(normalizationNode)) {
|
|
605
|
+
const mergeableChildren = Array.from(Node.children(editor, normalizationPath)).map((child, index, children) => {
|
|
606
|
+
const potentialNodeToBeMerged = children.at(index + 1);
|
|
607
|
+
if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
return [
|
|
611
|
+
Editor.pathRef(editor, child[1]),
|
|
612
|
+
Editor.pathRef(editor, potentialNodeToBeMerged[1])
|
|
613
|
+
];
|
|
614
|
+
}).filter((mergeableNodes) => Boolean(mergeableNodes));
|
|
615
|
+
if (mergeableChildren.length !== 0) {
|
|
616
|
+
mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {
|
|
617
|
+
const nodePath = nodePathRef.current;
|
|
618
|
+
const nodeToBeMergedPath = nodeToBeMergedPathRef.current;
|
|
619
|
+
if (nodePath == null || nodeToBeMergedPath == null)
|
|
620
|
+
return;
|
|
621
|
+
const nodeChildren = Array.from(Node.children(editor, nodePath));
|
|
622
|
+
const childrenToBeMerged = Array.from(Node.children(editor, nodeToBeMergedPath));
|
|
623
|
+
Editor.withoutNormalizing(editor, () => {
|
|
624
|
+
childrenToBeMerged.forEach(([_, childPath], index) => {
|
|
625
|
+
Transforms.moveNodes(editor, {
|
|
626
|
+
at: childPath,
|
|
627
|
+
to: [...nodePath, nodeChildren.length + index]
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
|
|
631
|
+
});
|
|
632
|
+
nodePathRef.unref();
|
|
633
|
+
nodeToBeMergedPathRef.unref();
|
|
634
|
+
});
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
return editor;
|
|
640
|
+
}
|
|
641
|
+
const defaultText = [{
|
|
642
|
+
type: BlockType.Paragraph,
|
|
643
|
+
children: [{
|
|
644
|
+
type: TextType.Text,
|
|
645
|
+
text: ""
|
|
646
|
+
}]
|
|
647
|
+
}];
|
|
648
|
+
const EditableText = forwardRef(function EditableText2({
|
|
649
|
+
id,
|
|
650
|
+
text,
|
|
651
|
+
width,
|
|
652
|
+
margin
|
|
653
|
+
}, ref) {
|
|
654
|
+
const [editor] = useState(() => withList(withReact(createEditor())));
|
|
655
|
+
const delaySync = useSyncWithBuilder(editor, text);
|
|
656
|
+
const editMode = useBuilderEditMode();
|
|
657
|
+
const [propControllers, setPropControllers] = useState(null);
|
|
658
|
+
const controller = propControllers == null ? void 0 : propControllers.text;
|
|
659
|
+
useImperativeHandle(ref, () => ({
|
|
660
|
+
getDomNode() {
|
|
661
|
+
return ReactEditor.toDOMNode(editor, editor);
|
|
662
|
+
},
|
|
663
|
+
getBoxModel() {
|
|
664
|
+
return getBox(ReactEditor.toDOMNode(editor, editor));
|
|
665
|
+
},
|
|
666
|
+
setPropControllers
|
|
667
|
+
}), [editor, setPropControllers]);
|
|
668
|
+
const initialValue = useMemo(() => text ? richTextDTOtoDAO(text) : defaultText, [text]);
|
|
669
|
+
useEffect(() => {
|
|
670
|
+
controller == null ? void 0 : controller.setSlateEditor(editor);
|
|
671
|
+
}, [controller, editor]);
|
|
672
|
+
const handleFocus = useCallback(() => {
|
|
673
|
+
controller == null ? void 0 : controller.focus();
|
|
674
|
+
}, [controller]);
|
|
675
|
+
const handleKeyDown = useCallback((e) => {
|
|
676
|
+
if (isHotkey("mod+shift+z", e))
|
|
677
|
+
return controller == null ? void 0 : controller.redo();
|
|
678
|
+
if (isHotkey("mod+z", e))
|
|
679
|
+
return controller == null ? void 0 : controller.undo();
|
|
680
|
+
if (isHotkey("escape")(e))
|
|
681
|
+
return controller == null ? void 0 : controller.blur();
|
|
682
|
+
onKeyDown(e, editor);
|
|
683
|
+
}, [controller, editor]);
|
|
684
|
+
return /* @__PURE__ */ jsx(Slate, {
|
|
685
|
+
editor,
|
|
686
|
+
value: initialValue,
|
|
687
|
+
onChange: delaySync,
|
|
688
|
+
children: /* @__PURE__ */ jsx(Editable, {
|
|
689
|
+
id,
|
|
690
|
+
renderLeaf: Leaf,
|
|
691
|
+
renderElement: Element,
|
|
692
|
+
onKeyDown: handleKeyDown,
|
|
693
|
+
onFocus: handleFocus,
|
|
694
|
+
className: cx(width, margin),
|
|
695
|
+
readOnly: editMode === BuilderEditMode.INTERACT
|
|
696
|
+
})
|
|
697
|
+
});
|
|
137
698
|
});
|
|
138
|
-
|
|
699
|
+
var EditableText$1 = EditableText;
|
|
700
|
+
export { EditableText, EditableText$1 as default };
|
|
139
701
|
//# sourceMappingURL=index.es6.js.map
|