@uxf/wysiwyg 11.129.0 → 11.130.1
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/README.md +9 -7
- package/create-all-plugins-with-ui.d.ts +78 -14
- package/create-all-plugins-with-ui.js +3 -5
- package/create-plugins-with-ui.d.ts +2 -2
- package/create-plugins-with-ui.js +25 -30
- package/data-format.test.d.ts +1 -0
- package/data-format.test.js +132 -0
- package/editor-smoke.test.d.ts +1 -0
- package/editor-smoke.test.js +9 -0
- package/hooks.d.ts +1971 -8
- package/hooks.js +18 -11
- package/package.json +15 -47
- package/plugins/blockquote/create-blockquote-plugin.d.ts +9 -3
- package/plugins/blockquote/create-blockquote-plugin.js +31 -3
- package/plugins/blockquote/create-blockquote-plugin.test.d.ts +1 -0
- package/plugins/blockquote/create-blockquote-plugin.test.js +57 -0
- package/plugins/blockquote/types.d.ts +1 -1
- package/plugins/blockquote/types.js +2 -2
- package/plugins/button/create-button-plugin.d.ts +1 -2
- package/plugins/button/create-button-plugin.js +3 -5
- package/plugins/button/transforms/is-button-active.js +1 -2
- package/plugins/button/transforms/update-button.js +1 -2
- package/plugins/constants.test.d.ts +1 -0
- package/plugins/constants.test.js +52 -0
- package/plugins/embedded/types.d.ts +6 -0
- package/plugins/embedded/types.js +2 -0
- package/plugins/embedded/utils.d.ts +2 -1
- package/plugins/embedded/utils.js +4 -4
- package/plugins/embedded/video/create-video-plugin.d.ts +10 -3
- package/plugins/embedded/video/create-video-plugin.js +8 -9
- package/plugins/embedded/video/create-video-plugin.test.d.ts +1 -0
- package/plugins/embedded/video/create-video-plugin.test.js +30 -0
- package/plugins/embedded/video/update-video.js +1 -2
- package/plugins/exit-break/create-exit-break-plugin.d.ts +8 -3
- package/plugins/exit-break/create-exit-break-plugin.js +8 -25
- package/plugins/heading/create-headings-plugin.d.ts +13 -4
- package/plugins/heading/create-headings-plugin.js +22 -36
- package/plugins/heading/create-headings-plugin.test.d.ts +1 -0
- package/plugins/heading/create-headings-plugin.test.js +42 -0
- package/plugins/highlight/createHighlightPlugin.d.ts +4 -2
- package/plugins/highlight/createHighlightPlugin.js +17 -19
- package/plugins/highlight/types.d.ts +1 -2
- package/plugins/image/create-image-plugin.d.ts +3 -3
- package/plugins/image/create-image-plugin.js +58 -91
- package/plugins/image/create-image-plugin.test.d.ts +1 -0
- package/plugins/image/create-image-plugin.test.js +33 -0
- package/plugins/image/transforms/is-image-active.js +1 -2
- package/plugins/image/transforms/update-image.js +1 -2
- package/plugins/image/types.d.ts +6 -3
- package/plugins/image/types.js +2 -2
- package/plugins/image/utils/is-image-url.js +2 -2
- package/plugins/image/with-paste-image-url.d.ts +5 -5
- package/plugins/image/with-paste-image-url.js +29 -25
- package/plugins/image/with-paste-image.d.ts +4 -7
- package/plugins/image/with-paste-image.js +41 -39
- package/plugins/link/constants.d.ts +1 -1
- package/plugins/link/constants.js +2 -2
- package/plugins/link/create-link-plugin.d.ts +38 -3
- package/plugins/link/create-link-plugin.js +9 -7
- package/plugins/link/create-link-plugin.test.d.ts +1 -0
- package/plugins/link/create-link-plugin.test.js +24 -0
- package/plugins/link/floating-link-wrapper.d.ts +14 -7
- package/plugins/link/floating-link-wrapper.js +46 -17
- package/plugins/link/hooks/index.d.ts +1 -1
- package/plugins/link/hooks/index.js +2 -2
- package/plugins/link/hooks/use-floating-link-selectors.d.ts +8 -0
- package/plugins/link/hooks/use-floating-link-selectors.js +21 -0
- package/plugins/link/hooks/use-link-actions.d.ts +991 -8
- package/plugins/link/hooks/use-link-actions.js +22 -19
- package/plugins/link/hooks/use-link-cancel-on-escape.d.ts +1 -1
- package/plugins/link/hooks/use-link-cancel-on-escape.js +2 -2
- package/plugins/link/hooks/use-link-submit-on-enter.js +5 -5
- package/plugins/link/transforms/get-active-link.d.ts +1 -1
- package/plugins/link/transforms/get-active-link.js +3 -5
- package/plugins/link/transforms/insert-link.js +9 -9
- package/plugins/link/transforms/submit-link.d.ts +2 -3
- package/plugins/link/transforms/submit-link.js +13 -13
- package/plugins/link/transforms/trigger-link-insert-or-edit.js +2 -2
- package/plugins/link/transforms/unwrap-link.js +2 -2
- package/plugins/list/constants.d.ts +11 -3
- package/plugins/list/constants.js +14 -10
- package/plugins/list/create-list-plugin.d.ts +26 -4
- package/plugins/list/create-list-plugin.js +13 -12
- package/plugins/list/create-list-plugin.test.d.ts +1 -0
- package/plugins/list/create-list-plugin.test.js +20 -0
- package/plugins/mark-bold/create-bold-plugin.d.ts +3 -3
- package/plugins/mark-bold/create-bold-plugin.js +2 -2
- package/plugins/mark-bold/types.d.ts +2 -2
- package/plugins/mark-bold/types.js +3 -3
- package/plugins/mark-code/create-code-plugin.d.ts +7 -3
- package/plugins/mark-code/create-code-plugin.js +6 -2
- package/plugins/mark-code/types.d.ts +2 -2
- package/plugins/mark-code/types.js +3 -3
- package/plugins/mark-italic/create-italic-plugin.d.ts +3 -3
- package/plugins/mark-italic/create-italic-plugin.js +2 -2
- package/plugins/mark-italic/types.d.ts +2 -2
- package/plugins/mark-italic/types.js +3 -3
- package/plugins/mark-underline/create-underline-plugin.d.ts +3 -3
- package/plugins/mark-underline/create-underline-plugin.js +2 -2
- package/plugins/mark-underline/types.d.ts +2 -2
- package/plugins/mark-underline/types.js +3 -3
- package/plugins/marks.test.d.ts +1 -0
- package/plugins/marks.test.js +42 -0
- package/plugins/node-id/add-ids-to-nodes.d.ts +1 -1
- package/plugins/node-id/create-node-id-plugin.d.ts +22 -3
- package/plugins/node-id/create-node-id-plugin.js +3 -2
- package/plugins/paragraph/create-paragraph-plugin.d.ts +1 -3
- package/plugins/paragraph/create-paragraph-plugin.js +3 -4
- package/plugins/paragraph/types.d.ts +1 -1
- package/plugins/paragraph/types.js +2 -2
- package/plugins/structural.test.d.ts +1 -0
- package/plugins/structural.test.js +29 -0
- package/plugins/trailing-block/create-trailing-block-plugin.d.ts +13 -3
- package/plugins/trailing-block/create-trailing-block-plugin.js +8 -2
- package/serializers/serialize-to-plaintext.js +2 -2
- package/styles/styles.css +1 -0
- package/types.d.ts +23 -14
- package/ui/floating-link.js +28 -28
- package/ui/highlight-mark.d.ts +2 -3
- package/ui/highlight-mark.js +4 -1
- package/ui/link-element.js +6 -3
- package/ui/toolbar/buttons/button-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/element-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/image-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/link-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/link-toolbar-button.js +1 -1
- package/ui/toolbar/buttons/list-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/list-toolbar-button.js +3 -3
- package/ui/toolbar/buttons/mark-toolbar-button.d.ts +1 -1
- package/ui/toolbar/buttons/undo-redo-button-group.d.ts +1 -1
- package/ui/toolbar/buttons/video-toolbar-button.d.ts +1 -1
- package/ui/toolbar/types.d.ts +1 -1
- package/ui/utils.js +1 -1
- package/utils.d.ts +18 -19
- package/utils.js +31 -28
- package/utils.test.d.ts +1 -0
- package/utils.test.js +23 -0
- package/wysiwyg-editor.d.ts +2 -2
- package/wysiwyg-editor.js +29 -23
- package/wysiwyg-editor.test.js +111 -6
- package/plugins/image/with-image.d.ts +0 -7
- package/plugins/image/with-image.js +0 -19
- package/plugins/reset-node/create-reset-node.d.ts +0 -3
- package/plugins/reset-node/create-reset-node.js +0 -28
- package/plugins/select-on-backspace/create-select-on-backspace-plugin.d.ts +0 -3
- package/plugins/select-on-backspace/create-select-on-backspace-plugin.js +0 -14
- package/plugins/soft-break/create-soft-break-plugin.d.ts +0 -3
- package/plugins/soft-break/create-soft-break-plugin.js +0 -22
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @uxf/wysiwyg
|
|
2
2
|
|
|
3
|
-
Rich-text / WYSIWYG editor for React, built on [Plate](https://
|
|
3
|
+
Rich-text / WYSIWYG editor for React, built on [Plate](https://platejs.org) / [Slate](https://docs.slatejs.org). It ships a ready-made `WysiwygEditor` component, a toolbar, and a set of UXF-styled plugins (headings, marks, lists, links, images, videos, buttons, blockquote, highlight).
|
|
4
4
|
|
|
5
5
|
## When to use
|
|
6
6
|
|
|
@@ -17,11 +17,11 @@ yarn add @uxf/wysiwyg
|
|
|
17
17
|
All Plate/Slate packages and the UXF packages are **peer dependencies** with pinned versions — install them at the versions declared in [`package.json`](./package.json):
|
|
18
18
|
|
|
19
19
|
- UXF: `@uxf/core`, `@uxf/core-react`, `@uxf/ui`
|
|
20
|
-
- Plate (`
|
|
21
|
-
- Slate wrappers: `@udecode/slate` (`19.8.0`), `@udecode/slate-react` (`19.7.1`), `@udecode/slate-utils` (`19.7.1`)
|
|
22
|
-
- Slate core: `slate` (`0.90.0`), `slate-history` (`0.86.0`), `slate-hyperscript` (`0.77.0`), `slate-react` (`0.91.11`)
|
|
20
|
+
- Plate: `platejs` (`53.3.9`), `@platejs/basic-nodes` (`53.0.0`), `@platejs/floating` (`53.0.0`), `@platejs/link` (`53.3.5`), `@platejs/list-classic` (`53.0.0`), `@platejs/media` (`53.1.4`)
|
|
23
21
|
- `react` / `react-dom` (`>=18.2.0`)
|
|
24
22
|
|
|
23
|
+
`slate` and `slate-react` are deliberately **not** peer dependencies. Plate owns the whole Slate stack, and declaring them here made npm resolve a second physical copy of `slate-react` — two copies mean two React contexts and a silently broken `useSelected()`.
|
|
24
|
+
|
|
25
25
|
### Required CSS
|
|
26
26
|
|
|
27
27
|
Import the published stylesheet once (e.g. in your global CSS):
|
|
@@ -125,7 +125,7 @@ Everything below is exported from the package root (`@uxf/wysiwyg`) unless a dee
|
|
|
125
125
|
|
|
126
126
|
### Plugin builders
|
|
127
127
|
|
|
128
|
-
`createPluginsWithUi` / `createAllPluginsWithUi` return the `UxfPlatePlugin[]` you pass to `WysiwygEditor`. Both inject the base plugins automatically (paragraph, exit-break,
|
|
128
|
+
`createPluginsWithUi` / `createAllPluginsWithUi` return the `UxfPlatePlugin[]` you pass to `WysiwygEditor`. Both inject the base plugins automatically (paragraph, exit-break, node-id, trailing-block), so pass only the feature builders below — not raw Plate plugins.
|
|
129
129
|
|
|
130
130
|
| Export | Signature | Notes |
|
|
131
131
|
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
|
|
@@ -165,7 +165,9 @@ Everything below is exported from the package root (`@uxf/wysiwyg`) unless a dee
|
|
|
165
165
|
|
|
166
166
|
`import { ... } from "@uxf/wysiwyg";` — thin, typed wrappers over Plate's editor hooks, bound to `WysiwygContent` / `UxfEditor`:
|
|
167
167
|
|
|
168
|
-
`useUxfPlateEditorRef`, `useUxfEditorRef`, `useUxfEditorState`, `useUxfPlateEditorState`,
|
|
168
|
+
`useUxfPlateEditorRef`, `useUxfEditorRef`, `useUxfEditorState`, `useUxfPlateEditorState`, and re-exports of `useSelected` and `usePlateStore`.
|
|
169
|
+
|
|
170
|
+
`useUxfPlateSelectors`, `useUxfPlateActions` and `useUxfPlateStates` still exist but return `unknown`: Plate 53 replaced the split selectors/actions/states store with a single store that these three cannot meaningfully wrap. Use the re-exported `usePlateStore` instead.
|
|
169
171
|
|
|
170
172
|
### Utilities
|
|
171
173
|
|
|
@@ -210,6 +212,6 @@ The full node model and editor types are re-exported, including: `WysiwygContent
|
|
|
210
212
|
|
|
211
213
|
## Links
|
|
212
214
|
|
|
213
|
-
- [Plate documentation](https://
|
|
215
|
+
- [Plate documentation](https://platejs.org) — the underlying editor framework.
|
|
214
216
|
- [Slate documentation](https://docs.slatejs.org) — the underlying document model.
|
|
215
217
|
- Package homepage: [gitlab.com/uxf-npm/wysiwyg](https://gitlab.com/uxf-npm/wysiwyg)
|
|
@@ -3,37 +3,63 @@ import { HeadingsPluginOptions } from "./plugins/heading/create-headings-plugin"
|
|
|
3
3
|
import { UxfImagePluginOptions } from "./plugins/image/types";
|
|
4
4
|
import { ElementUiComponent } from "./types";
|
|
5
5
|
export declare const createHeadingsPluginWithUi: (options?: HeadingsPluginOptions) => {
|
|
6
|
-
plugin: import("
|
|
6
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"heading", {}, {}, {}, {}>>;
|
|
7
7
|
components: {
|
|
8
8
|
[key: string]: ElementUiComponent;
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export declare const createBlockquotePluginWithUi: () => {
|
|
12
|
-
plugin: import("
|
|
12
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"blockquote", {}, {}, {}, {}>>;
|
|
13
13
|
component: ElementUiComponent;
|
|
14
14
|
};
|
|
15
15
|
export declare const createBoldPluginWithUi: () => {
|
|
16
|
-
plugin: import("
|
|
16
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"bold", {}, {}, Record<"bold", {
|
|
17
|
+
toggle: () => void;
|
|
18
|
+
}>, {}>>;
|
|
17
19
|
component: import("./types").LeafUiComponent;
|
|
18
20
|
};
|
|
19
21
|
export declare const createHighlightPluginWithUi: (color?: CSSProperties["color"]) => {
|
|
20
|
-
plugin: import("
|
|
21
|
-
|
|
22
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"highlight", {
|
|
23
|
+
color: import("csstype").Property.Color;
|
|
24
|
+
}, {}, {}, {}>>;
|
|
25
|
+
component: import("./types").LeafUiComponent;
|
|
22
26
|
};
|
|
23
27
|
export declare const createItalicPluginWithUi: () => {
|
|
24
|
-
plugin: import("
|
|
28
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"italic", {}, {}, Record<"italic", {
|
|
29
|
+
toggle: () => void;
|
|
30
|
+
}>, {}>>;
|
|
25
31
|
component: ElementUiComponent;
|
|
26
32
|
};
|
|
27
33
|
export declare const createUnderlinePluginWithUi: () => {
|
|
28
|
-
plugin: import("
|
|
34
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"underline", {}, {}, Record<"underline", {
|
|
35
|
+
toggle: () => void;
|
|
36
|
+
}>, {}>>;
|
|
29
37
|
component: import("./types").LeafUiComponent;
|
|
30
38
|
};
|
|
31
39
|
export declare const createCodePluginWithUi: () => {
|
|
32
|
-
plugin: import("
|
|
40
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"code", {}, {}, Record<"code", {
|
|
41
|
+
toggle: () => void;
|
|
42
|
+
}>, {}>>;
|
|
33
43
|
component: import("./types").LeafUiComponent;
|
|
34
44
|
};
|
|
35
45
|
export declare const createListPluginWithUi: () => {
|
|
36
|
-
plugin: import("
|
|
46
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"listClassic", {
|
|
47
|
+
enableResetOnShiftTab?: boolean;
|
|
48
|
+
inheritCheckStateOnLineEndBreak?: boolean;
|
|
49
|
+
inheritCheckStateOnLineStartBreak?: boolean;
|
|
50
|
+
validLiChildrenTypes?: string[];
|
|
51
|
+
}, {}, {
|
|
52
|
+
toggle: {
|
|
53
|
+
bulletedList: (() => boolean) & (() => boolean);
|
|
54
|
+
list: ((args_0: {
|
|
55
|
+
type: string;
|
|
56
|
+
}) => boolean) & ((args_0: {
|
|
57
|
+
type: string;
|
|
58
|
+
}) => boolean);
|
|
59
|
+
numberedList: (() => boolean) & (() => boolean);
|
|
60
|
+
taskList: ((defaultChecked?: boolean | undefined) => boolean) & ((defaultChecked?: boolean | undefined) => boolean);
|
|
61
|
+
};
|
|
62
|
+
}, {}>>;
|
|
37
63
|
components: {
|
|
38
64
|
ul: ElementUiComponent;
|
|
39
65
|
ol: ElementUiComponent;
|
|
@@ -41,19 +67,57 @@ export declare const createListPluginWithUi: () => {
|
|
|
41
67
|
};
|
|
42
68
|
};
|
|
43
69
|
export declare const createLinkPluginWithUi: () => {
|
|
44
|
-
plugin: import("
|
|
70
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"a", {
|
|
71
|
+
allowedSchemes?: string[];
|
|
72
|
+
dangerouslySkipSanitization?: boolean;
|
|
73
|
+
defaultLinkAttributes?: React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
74
|
+
forceSubmit?: boolean;
|
|
75
|
+
keepSelectedTextOnPaste?: boolean;
|
|
76
|
+
rangeBeforeOptions?: import("platejs").EditorBeforeOptions;
|
|
77
|
+
triggerFloatingLinkHotkeys?: string[] | string;
|
|
78
|
+
getLinkUrl?: (prevUrl: string | null) => Promise<string | null>;
|
|
79
|
+
getUrlHref?: (url: string) => string | undefined;
|
|
80
|
+
isUrl?: (text: string) => boolean;
|
|
81
|
+
transformInput?: (url: string) => string | undefined;
|
|
82
|
+
} & {
|
|
83
|
+
isEditing: boolean;
|
|
84
|
+
mode: import("@platejs/link/react").FloatingLinkMode;
|
|
85
|
+
mouseDown: boolean;
|
|
86
|
+
newTab: boolean;
|
|
87
|
+
openEditorId: string | null;
|
|
88
|
+
text: string;
|
|
89
|
+
updated: boolean;
|
|
90
|
+
url: string;
|
|
91
|
+
triggerFloatingLinkHotkeys?: string;
|
|
92
|
+
}, {
|
|
93
|
+
floatingLink: {
|
|
94
|
+
hide: () => void;
|
|
95
|
+
reset: () => void;
|
|
96
|
+
show: (mode: import("@platejs/link/react").FloatingLinkMode, editorId: string) => void;
|
|
97
|
+
};
|
|
98
|
+
link: {
|
|
99
|
+
getAttributes: import("platejs").OmitFirst<(editor: import("platejs").SlateEditor, link: import("platejs").TLinkElement) => Pick<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "target"> & import("platejs").UnknownObject>;
|
|
100
|
+
};
|
|
101
|
+
}, {}, {
|
|
102
|
+
isOpen?: (editorId: string) => boolean;
|
|
103
|
+
}>>;
|
|
45
104
|
component: ElementUiComponent;
|
|
46
105
|
};
|
|
47
106
|
export declare const createImagePluginWithUi: (options: UxfImagePluginOptions) => {
|
|
48
|
-
plugin: import("
|
|
107
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"img", UxfImagePluginOptions, {}, {}, {}>>;
|
|
49
108
|
component: ElementUiComponent;
|
|
50
109
|
};
|
|
51
110
|
export declare const createVideoPluginWithUi: () => {
|
|
52
|
-
plugin: import("
|
|
111
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"video", {
|
|
112
|
+
rules: {
|
|
113
|
+
parser: (url: string) => import("@platejs/media").EmbedUrlData | undefined;
|
|
114
|
+
}[];
|
|
115
|
+
transformUrl: (url: string) => string;
|
|
116
|
+
}, {}, {}, {}>>;
|
|
53
117
|
component: ElementUiComponent;
|
|
54
118
|
};
|
|
55
119
|
export declare const createButtonPluginWithUi: () => {
|
|
56
|
-
plugin: import("
|
|
120
|
+
plugin: import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"button", {}, {}, {}, {}>>;
|
|
57
121
|
component: ElementUiComponent;
|
|
58
122
|
};
|
|
59
123
|
export interface CreateAllPluginsOptions {
|
|
@@ -61,4 +125,4 @@ export interface CreateAllPluginsOptions {
|
|
|
61
125
|
headings?: HeadingsPluginOptions;
|
|
62
126
|
highlightColor?: CSSProperties["color"];
|
|
63
127
|
}
|
|
64
|
-
export declare const createAllPluginsWithUi: (options: CreateAllPluginsOptions) => import("
|
|
128
|
+
export declare const createAllPluginsWithUi: (options: CreateAllPluginsOptions) => import("platejs/react").AnyPlatePlugin[];
|
|
@@ -94,19 +94,17 @@ const createLinkPluginWithUi = () => ({
|
|
|
94
94
|
});
|
|
95
95
|
exports.createLinkPluginWithUi = createLinkPluginWithUi;
|
|
96
96
|
const createImagePluginWithUi = (options) => ({
|
|
97
|
-
plugin:
|
|
98
|
-
options,
|
|
99
|
-
}),
|
|
97
|
+
plugin: create_image_plugin_1.createImagePlugin.configure({ options }),
|
|
100
98
|
component: image_element_1.ImageElement,
|
|
101
99
|
});
|
|
102
100
|
exports.createImagePluginWithUi = createImagePluginWithUi;
|
|
103
101
|
const createVideoPluginWithUi = () => ({
|
|
104
|
-
plugin:
|
|
102
|
+
plugin: create_video_plugin_1.createVideoPlugin,
|
|
105
103
|
component: video_element_1.VideoElement,
|
|
106
104
|
});
|
|
107
105
|
exports.createVideoPluginWithUi = createVideoPluginWithUi;
|
|
108
106
|
const createButtonPluginWithUi = () => ({
|
|
109
|
-
plugin:
|
|
107
|
+
plugin: button_1.createButtonPlugin,
|
|
110
108
|
component: button_2.ButtonElement,
|
|
111
109
|
});
|
|
112
110
|
exports.createButtonPluginWithUi = createButtonPluginWithUi;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyWysiwygPlatePlugin, MyOverrideByKey, WysiwygPlugin, WysiwygRecursivePlugin } from "./types";
|
|
2
2
|
export declare const createPluginsWithUi: (wysiwygPlugins: Array<WysiwygPlugin | WysiwygRecursivePlugin<string>>, options?: {
|
|
3
3
|
overrideByKey?: MyOverrideByKey;
|
|
4
|
-
}) =>
|
|
4
|
+
}) => AnyWysiwygPlatePlugin[];
|
|
@@ -1,48 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPluginsWithUi = void 0;
|
|
4
|
-
const
|
|
4
|
+
const platejs_1 = require("platejs");
|
|
5
5
|
const create_exit_break_plugin_1 = require("./plugins/exit-break/create-exit-break-plugin");
|
|
6
6
|
const create_node_id_plugin_1 = require("./plugins/node-id/create-node-id-plugin");
|
|
7
7
|
const create_paragraph_plugin_1 = require("./plugins/paragraph/create-paragraph-plugin");
|
|
8
|
-
const types_1 = require("./plugins/paragraph/types");
|
|
9
|
-
const create_reset_node_1 = require("./plugins/reset-node/create-reset-node");
|
|
10
|
-
const create_select_on_backspace_plugin_1 = require("./plugins/select-on-backspace/create-select-on-backspace-plugin");
|
|
11
|
-
const create_soft_break_plugin_1 = require("./plugins/soft-break/create-soft-break-plugin");
|
|
12
8
|
const create_trailing_block_plugin_1 = require("./plugins/trailing-block/create-trailing-block-plugin");
|
|
13
9
|
const paragraph_element_1 = require("./ui/paragraph-element");
|
|
14
10
|
function isRecursivePlugin(plugin) {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
16
12
|
return plugin.components !== undefined;
|
|
17
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The one place that overrides a plugin by key, which is the only way to reach a wrapper plugin's
|
|
16
|
+
* children (headings, lists). Plate declares `overridePluginsByKey` for headless plugins only and
|
|
17
|
+
* ships no React counterpart, so the double cast is the library's typing, not a shortcut: a React
|
|
18
|
+
* plugin is a superset at runtime and Plate's own code overrides them the same way.
|
|
19
|
+
*/
|
|
20
|
+
function overrideByKey(plugin, byKey) {
|
|
21
|
+
const override = platejs_1.overridePluginsByKey;
|
|
22
|
+
return override(plugin, byKey, true);
|
|
23
|
+
}
|
|
24
|
+
/** Flat plugins use `withComponent`; only the wrapper ones need the key-based override. */
|
|
25
|
+
function withNestedComponents(plugin, components) {
|
|
26
|
+
return overrideByKey(plugin, Object.fromEntries(Object.entries(components).map(([key, component]) => [key, { node: { component } }])));
|
|
27
|
+
}
|
|
18
28
|
const createPluginsWithUi = (wysiwygPlugins, options) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
wysiwygPlugins.forEach((p) => {
|
|
24
|
-
if (isRecursivePlugin(p)) {
|
|
25
|
-
Object.keys(p.components).forEach((componentKey) => {
|
|
26
|
-
pluginComponents[componentKey] = p.components[componentKey];
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
pluginComponents[p.plugin.key] = p.component;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return (0, plate_core_1.createPlugins)([
|
|
34
|
-
(0, create_paragraph_plugin_1.createParagraphPlugin)(),
|
|
29
|
+
const withUi = wysiwygPlugins.map((p) => isRecursivePlugin(p) ? withNestedComponents(p.plugin, p.components) : p.plugin.withComponent(p.component));
|
|
30
|
+
const plugins = [
|
|
31
|
+
(0, create_paragraph_plugin_1.createParagraphPlugin)().withComponent(paragraph_element_1.ParagraphElement),
|
|
35
32
|
(0, create_exit_break_plugin_1.createExitBreakPlugin)(),
|
|
36
|
-
(0, create_reset_node_1.createResetNodePlugin)(),
|
|
37
|
-
(0, create_soft_break_plugin_1.createSoftBreakPlugin)(),
|
|
38
33
|
(0, create_node_id_plugin_1.createNodeIdPlugin)(),
|
|
39
|
-
(0, create_select_on_backspace_plugin_1.createSelectOnBackspacePlugin)(),
|
|
40
34
|
(0, create_trailing_block_plugin_1.createTrailingBlockPlugin)(),
|
|
41
|
-
...
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
35
|
+
...withUi,
|
|
36
|
+
];
|
|
37
|
+
const byKey = options === null || options === void 0 ? void 0 : options.overrideByKey;
|
|
38
|
+
if (!byKey) {
|
|
39
|
+
return plugins;
|
|
40
|
+
}
|
|
41
|
+
return plugins.map((plugin) => overrideByKey(plugin, byKey));
|
|
47
42
|
};
|
|
48
43
|
exports.createPluginsWithUi = createPluginsWithUi;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const platejs_1 = require("platejs");
|
|
4
|
+
const create_all_plugins_with_ui_1 = require("./create-all-plugins-with-ui");
|
|
5
|
+
const FILE = { extension: ".png", id: 1, name: "a.png", namespace: "wysiwyg", uuid: "u" };
|
|
6
|
+
/**
|
|
7
|
+
* Every node type and mark the stored format contains. Ids and the trailing empty paragraph are
|
|
8
|
+
* present because the node-id and trailing-block plugins would otherwise add them.
|
|
9
|
+
*/
|
|
10
|
+
const FIXTURE = [
|
|
11
|
+
{ children: [{ text: "Nadpis" }], id: "a1", type: "h1" },
|
|
12
|
+
{ children: [{ text: "H2" }], id: "a2", type: "h2" },
|
|
13
|
+
{ children: [{ text: "H3" }], id: "a3", type: "h3" },
|
|
14
|
+
{ children: [{ text: "H4" }], id: "a4", type: "h4" },
|
|
15
|
+
{ children: [{ text: "H5" }], id: "a5", type: "h5" },
|
|
16
|
+
{ children: [{ text: "H6" }], id: "a6", type: "h6" },
|
|
17
|
+
{
|
|
18
|
+
children: [{ bold: true, text: "tučně" }, { text: " a " }, { italic: true, text: "kurzíva" }],
|
|
19
|
+
id: "a7",
|
|
20
|
+
type: "paragraph",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
children: [
|
|
24
|
+
{ text: "podtržené", underline: true },
|
|
25
|
+
{ code: true, text: "kód" },
|
|
26
|
+
{ highlight: true, text: "zvýrazněné" },
|
|
27
|
+
],
|
|
28
|
+
id: "a8",
|
|
29
|
+
type: "paragraph",
|
|
30
|
+
},
|
|
31
|
+
{ children: [{ text: "citace" }], id: "a9", type: "blockquote" },
|
|
32
|
+
{
|
|
33
|
+
children: [{ children: [{ children: [{ text: "položka" }], id: "a12", type: "lic" }], id: "a11", type: "li" }],
|
|
34
|
+
id: "a10",
|
|
35
|
+
type: "ul",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
children: [{ children: [{ children: [{ text: "první" }], id: "a15", type: "lic" }], id: "a14", type: "li" }],
|
|
39
|
+
id: "a13",
|
|
40
|
+
type: "ol",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
children: [
|
|
44
|
+
{ text: "" },
|
|
45
|
+
{
|
|
46
|
+
children: [{ text: "odkaz" }],
|
|
47
|
+
id: "a17",
|
|
48
|
+
target: "_blank",
|
|
49
|
+
type: "link",
|
|
50
|
+
url: "https://uxf.cz",
|
|
51
|
+
},
|
|
52
|
+
{ text: "" },
|
|
53
|
+
],
|
|
54
|
+
id: "a16",
|
|
55
|
+
type: "paragraph",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
alt: "alt",
|
|
59
|
+
caption: "popisek",
|
|
60
|
+
children: [{ text: "" }],
|
|
61
|
+
file: FILE,
|
|
62
|
+
id: "a18",
|
|
63
|
+
source: "zdroj",
|
|
64
|
+
type: "image",
|
|
65
|
+
url: "https://example.test/a.png",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
children: [{ text: "" }],
|
|
69
|
+
embeddedUrl: "https://www.youtube.com/embed/x",
|
|
70
|
+
id: "a19",
|
|
71
|
+
metaData: null,
|
|
72
|
+
provider: "youtube",
|
|
73
|
+
type: "video",
|
|
74
|
+
url: "https://youtu.be/x",
|
|
75
|
+
videoId: "x",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
buttonText: "klik",
|
|
79
|
+
buttonUrl: "https://uxf.cz",
|
|
80
|
+
children: [{ text: "" }],
|
|
81
|
+
id: "a20",
|
|
82
|
+
type: "button",
|
|
83
|
+
},
|
|
84
|
+
{ children: [{ text: "" }], id: "a21", type: "paragraph" },
|
|
85
|
+
];
|
|
86
|
+
describe("stored data format", () => {
|
|
87
|
+
it("survives a normalising round trip unchanged", () => {
|
|
88
|
+
const editor = (0, platejs_1.createSlateEditor)({
|
|
89
|
+
plugins: (0, create_all_plugins_with_ui_1.createAllPluginsWithUi)({
|
|
90
|
+
image: { getImageUrl: (file) => file.name, uploadImage: async () => FILE },
|
|
91
|
+
}),
|
|
92
|
+
shouldNormalizeEditor: true,
|
|
93
|
+
value: FIXTURE,
|
|
94
|
+
});
|
|
95
|
+
expect(editor.children).toEqual(FIXTURE);
|
|
96
|
+
});
|
|
97
|
+
it("registers every stored node type and no others", () => {
|
|
98
|
+
const editor = (0, platejs_1.createSlateEditor)({
|
|
99
|
+
plugins: (0, create_all_plugins_with_ui_1.createAllPluginsWithUi)({
|
|
100
|
+
image: { getImageUrl: (file) => file.name, uploadImage: async () => FILE },
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
const storedTypes = [
|
|
104
|
+
"paragraph",
|
|
105
|
+
"blockquote",
|
|
106
|
+
"h1",
|
|
107
|
+
"h2",
|
|
108
|
+
"h3",
|
|
109
|
+
"h4",
|
|
110
|
+
"h5",
|
|
111
|
+
"h6",
|
|
112
|
+
"ul",
|
|
113
|
+
"ol",
|
|
114
|
+
"li",
|
|
115
|
+
"lic",
|
|
116
|
+
"link",
|
|
117
|
+
"image",
|
|
118
|
+
"video",
|
|
119
|
+
"button",
|
|
120
|
+
"bold",
|
|
121
|
+
"italic",
|
|
122
|
+
"underline",
|
|
123
|
+
"code",
|
|
124
|
+
"highlight",
|
|
125
|
+
];
|
|
126
|
+
const registeredTypes = Object.values(editor.plugins)
|
|
127
|
+
.map((plugin) => plugin.node.type)
|
|
128
|
+
.filter((type) => Boolean(type));
|
|
129
|
+
expect(storedTypes.filter((type) => !registeredTypes.includes(type))).toEqual([]);
|
|
130
|
+
expect(registeredTypes).not.toContain("taskList");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const platejs_1 = require("platejs");
|
|
4
|
+
describe("platejs runs under this jest config", () => {
|
|
5
|
+
it("creates a working editor", () => {
|
|
6
|
+
const editor = (0, platejs_1.createSlateEditor)({ plugins: [], value: [{ children: [{ text: "ahoj" }], type: "p" }] });
|
|
7
|
+
expect(editor.api.string([])).toBe("ahoj");
|
|
8
|
+
});
|
|
9
|
+
});
|