@payloadcms/richtext-lexical 3.55.0-internal.ce8fe55 → 3.55.0-internal.df60e35
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/exports/client/Field-SOED2PIU.js +2 -0
- package/dist/exports/client/{Field-Q3PTZQ75.js.map → Field-SOED2PIU.js.map} +3 -3
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-FSKAVN4P.js +2 -0
- package/dist/exports/client/{chunk-CYLMY5ZJ.js.map → chunk-FSKAVN4P.js.map} +2 -2
- package/dist/exports/client/chunk-KZKGNMS3.js +12 -0
- package/dist/exports/client/{chunk-YCH4JNUH.js.map → chunk-KZKGNMS3.js.map} +2 -2
- package/dist/exports/client/{component-3PENNOM3.js → component-M3U253XK.js} +2 -2
- package/dist/exports/client/index.d.ts +0 -2
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blocks/client/component/BlockContent.js +10 -8
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +39 -124
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +8 -6
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +3 -3
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js +37 -20
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js +53 -28
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js +37 -35
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +30 -20
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.js +35 -22
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +15 -7
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +15 -7
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +141 -75
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +3 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +11 -2
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.js +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.js.map +1 -0
- package/dist/nodeTypes.d.ts +1 -13
- package/dist/nodeTypes.d.ts.map +1 -1
- package/dist/nodeTypes.js +1 -4
- package/dist/nodeTypes.js.map +1 -1
- package/package.json +26 -21
- package/dist/exports/client/Field-Q3PTZQ75.js +0 -2
- package/dist/exports/client/chunk-CYLMY5ZJ.js +0 -2
- package/dist/exports/client/chunk-YCH4JNUH.js +0 -12
- package/dist/field/RenderLexical/index.d.ts +0 -19
- package/dist/field/RenderLexical/index.d.ts.map +0 -1
- package/dist/field/RenderLexical/index.js +0 -123
- package/dist/field/RenderLexical/index.js.map +0 -1
- package/dist/utilities/buildEditorState.d.ts +0 -11
- package/dist/utilities/buildEditorState.d.ts.map +0 -1
- package/dist/utilities/buildEditorState.js +0 -76
- package/dist/utilities/buildEditorState.js.map +0 -1
- /package/dist/exports/client/{component-3PENNOM3.js.map → component-M3U253XK.js.map} +0 -0
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
import { FieldContext, FieldPathContext, ServerFunctionsContext, ShimmerEffect, useServerFunctions } from '@payloadcms/ui';
|
|
6
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
7
|
-
/**
|
|
8
|
-
* Utility to render a lexical editor on the client.
|
|
9
|
-
*
|
|
10
|
-
* @experimental - may break in minor releases
|
|
11
|
-
* @todo - replace this with a general utility that works for all fields. Maybe merge with packages/ui/src/forms/RenderFields/RenderField.tsx
|
|
12
|
-
*/
|
|
13
|
-
export const RenderLexical = args => {
|
|
14
|
-
const $ = _c(9);
|
|
15
|
-
const {
|
|
16
|
-
field,
|
|
17
|
-
initialValue,
|
|
18
|
-
path,
|
|
19
|
-
schemaPath,
|
|
20
|
-
setValue,
|
|
21
|
-
value
|
|
22
|
-
} = args;
|
|
23
|
-
const [Component, setComponent] = React.useState(null);
|
|
24
|
-
const serverFunctionContext = useServerFunctions();
|
|
25
|
-
const {
|
|
26
|
-
_internal_renderField
|
|
27
|
-
} = serverFunctionContext;
|
|
28
|
-
const [entityType, entitySlug] = schemaPath.split(".");
|
|
29
|
-
const fieldPath = path ?? (field && "name" in field ? field?.name : "") ?? "";
|
|
30
|
-
let t0;
|
|
31
|
-
if ($[0] !== _internal_renderField || $[1] !== field || $[2] !== initialValue || $[3] !== path || $[4] !== schemaPath) {
|
|
32
|
-
t0 = () => {
|
|
33
|
-
const render = async function render() {
|
|
34
|
-
const {
|
|
35
|
-
Field
|
|
36
|
-
} = await _internal_renderField({
|
|
37
|
-
field,
|
|
38
|
-
initialValue: initialValue ?? undefined,
|
|
39
|
-
path,
|
|
40
|
-
schemaPath
|
|
41
|
-
});
|
|
42
|
-
setComponent(Field);
|
|
43
|
-
};
|
|
44
|
-
render();
|
|
45
|
-
};
|
|
46
|
-
$[0] = _internal_renderField;
|
|
47
|
-
$[1] = field;
|
|
48
|
-
$[2] = initialValue;
|
|
49
|
-
$[3] = path;
|
|
50
|
-
$[4] = schemaPath;
|
|
51
|
-
$[5] = t0;
|
|
52
|
-
} else {
|
|
53
|
-
t0 = $[5];
|
|
54
|
-
}
|
|
55
|
-
const renderLexical = t0;
|
|
56
|
-
const mounted = useRef(false);
|
|
57
|
-
let t1;
|
|
58
|
-
let t2;
|
|
59
|
-
if ($[6] !== renderLexical) {
|
|
60
|
-
t1 = () => {
|
|
61
|
-
if (mounted.current) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
mounted.current = true;
|
|
65
|
-
renderLexical();
|
|
66
|
-
};
|
|
67
|
-
t2 = [renderLexical];
|
|
68
|
-
$[6] = renderLexical;
|
|
69
|
-
$[7] = t1;
|
|
70
|
-
$[8] = t2;
|
|
71
|
-
} else {
|
|
72
|
-
t1 = $[7];
|
|
73
|
-
t2 = $[8];
|
|
74
|
-
}
|
|
75
|
-
useEffect(t1, t2);
|
|
76
|
-
if (!Component) {
|
|
77
|
-
return _jsx(ShimmerEffect, {});
|
|
78
|
-
}
|
|
79
|
-
const adjustedServerFunctionContext = {
|
|
80
|
-
...serverFunctionContext,
|
|
81
|
-
getFormState: async getFormStateArgs => serverFunctionContext.getFormState({
|
|
82
|
-
...getFormStateArgs,
|
|
83
|
-
collectionSlug: entityType === "collection" ? entitySlug : undefined,
|
|
84
|
-
globalSlug: entityType === "global" ? entitySlug : undefined
|
|
85
|
-
})
|
|
86
|
-
};
|
|
87
|
-
if (typeof value === "undefined" && !setValue) {
|
|
88
|
-
return _jsx(ServerFunctionsContext, {
|
|
89
|
-
value: {
|
|
90
|
-
...adjustedServerFunctionContext
|
|
91
|
-
},
|
|
92
|
-
children: _jsx(FieldPathContext, {
|
|
93
|
-
value: fieldPath,
|
|
94
|
-
children: Component
|
|
95
|
-
}, fieldPath)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
const fieldValue = {
|
|
99
|
-
disabled: false,
|
|
100
|
-
formInitializing: false,
|
|
101
|
-
formProcessing: false,
|
|
102
|
-
formSubmitted: false,
|
|
103
|
-
initialValue: value,
|
|
104
|
-
path: fieldPath,
|
|
105
|
-
setValue: setValue ?? _temp,
|
|
106
|
-
showError: false,
|
|
107
|
-
value
|
|
108
|
-
};
|
|
109
|
-
return _jsx(ServerFunctionsContext, {
|
|
110
|
-
value: {
|
|
111
|
-
...adjustedServerFunctionContext
|
|
112
|
-
},
|
|
113
|
-
children: _jsx(FieldPathContext, {
|
|
114
|
-
value: fieldPath,
|
|
115
|
-
children: _jsx(FieldContext, {
|
|
116
|
-
value: fieldValue,
|
|
117
|
-
children: Component
|
|
118
|
-
})
|
|
119
|
-
}, fieldPath)
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
function _temp() {}
|
|
123
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","FieldContext","FieldPathContext","ServerFunctionsContext","ShimmerEffect","useServerFunctions","React","useCallback","useEffect","useRef","RenderLexical","args","$","field","initialValue","path","schemaPath","setValue","value","Component","setComponent","useState","serverFunctionContext","_internal_renderField","entityType","entitySlug","split","fieldPath","name","t0","render","Field","undefined","renderLexical","mounted","t1","t2","current","_jsx","adjustedServerFunctionContext","getFormState","getFormStateArgs","collectionSlug","globalSlug","children","fieldValue","disabled","formInitializing","formProcessing","formSubmitted","_temp","showError"],"sources":["../../../src/field/RenderLexical/index.tsx"],"sourcesContent":["'use client'\nimport {\n FieldContext,\n FieldPathContext,\n type FieldType,\n type RenderFieldServerFnArgs,\n ServerFunctionsContext,\n type ServerFunctionsContextType,\n ShimmerEffect,\n useServerFunctions,\n} from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useRef } from 'react'\n\nimport type { DefaultTypedEditorState } from '../../nodeTypes.js'\n\n/**\n * Utility to render a lexical editor on the client.\n *\n * @experimental - may break in minor releases\n * @todo - replace this with a general utility that works for all fields. Maybe merge with packages/ui/src/forms/RenderFields/RenderField.tsx\n */\nexport const RenderLexical: React.FC<\n /**\n * If value or setValue, or both, is provided, this component will manage its own value.\n * If neither is passed, it will rely on the parent form to manage the value.\n */\n {\n setValue?: FieldType<DefaultTypedEditorState | undefined>['setValue']\n\n value?: FieldType<DefaultTypedEditorState | undefined>['value']\n } & RenderFieldServerFnArgs\n> = (args) => {\n const { field, initialValue, path, schemaPath, setValue, value } = args\n const [Component, setComponent] = React.useState<null | React.ReactNode>(null)\n const serverFunctionContext = useServerFunctions()\n const { _internal_renderField } = serverFunctionContext\n\n const [entityType, entitySlug] = schemaPath.split('.')\n\n const fieldPath = path ?? (field && 'name' in field ? field?.name : '') ?? ''\n\n const renderLexical = useCallback(() => {\n async function render() {\n const { Field } = await _internal_renderField({\n field,\n initialValue: initialValue ?? undefined,\n path,\n schemaPath,\n })\n\n setComponent(Field)\n }\n void render()\n }, [_internal_renderField, schemaPath, path, field, initialValue])\n\n const mounted = useRef(false)\n\n useEffect(() => {\n if (mounted.current) {\n return\n }\n mounted.current = true\n void renderLexical()\n }, [renderLexical])\n\n if (!Component) {\n return <ShimmerEffect />\n }\n\n /**\n * By default, the lexical will make form state requests (e.g. to get drawer fields), passing in the arguments\n * of the current field. However, we need to override those arguments to get it to make requests based on the\n * *target* field. The server only knows the schema map of the target field.\n */\n const adjustedServerFunctionContext: ServerFunctionsContextType = {\n ...serverFunctionContext,\n getFormState: async (getFormStateArgs) => {\n return serverFunctionContext.getFormState({\n ...getFormStateArgs,\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n })\n },\n }\n\n if (typeof value === 'undefined' && !setValue) {\n return (\n <ServerFunctionsContext value={{ ...adjustedServerFunctionContext }}>\n <FieldPathContext key={fieldPath} value={fieldPath}>\n {Component}\n </FieldPathContext>\n </ServerFunctionsContext>\n )\n }\n\n const fieldValue: FieldType<DefaultTypedEditorState | undefined> = {\n disabled: false,\n formInitializing: false,\n formProcessing: false,\n formSubmitted: false,\n initialValue: value,\n path: fieldPath,\n setValue: setValue ?? (() => undefined),\n showError: false,\n value,\n }\n\n return (\n <ServerFunctionsContext value={{ ...adjustedServerFunctionContext }}>\n <FieldPathContext key={fieldPath} value={fieldPath}>\n <FieldContext value={fieldValue}>{Component}</FieldContext>\n </FieldPathContext>\n </ServerFunctionsContext>\n )\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { SerializedLexicalNode } from 'lexical';
|
|
2
|
-
import type { DefaultTypedEditorState, TypedEditorState } from '../nodeTypes.js';
|
|
3
|
-
export declare function buildEditorState(args: {
|
|
4
|
-
nodes?: DefaultTypedEditorState['root']['children'];
|
|
5
|
-
text?: string;
|
|
6
|
-
}): DefaultTypedEditorState;
|
|
7
|
-
export declare function buildEditorState<T extends SerializedLexicalNode>(args: {
|
|
8
|
-
nodes?: TypedEditorState<T>['root']['children'];
|
|
9
|
-
text?: string;
|
|
10
|
-
}): TypedEditorState<T>;
|
|
11
|
-
//# sourceMappingURL=buildEditorState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildEditorState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildEditorState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEhF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,KAAK,CAAC,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,uBAAuB,CAAA;AAE3B,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE;IAEtE,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper to build lexical editor state JSON from text and/or nodes.
|
|
3
|
-
*
|
|
4
|
-
* @param nodes - The nodes to include in the editor state. If you pass the `text` argument, this will append your nodes after the first paragraph node.
|
|
5
|
-
* @param text - The text content to include in the editor state. This will create a paragraph node with a text node for you and set that as the first node.
|
|
6
|
-
* @returns The constructed editor state JSON.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* just passing text:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const editorState = buildEditorState({ text: 'Hello world' }) // result typed as DefaultTypedEditorState
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* passing nodes:
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* const editorState = // result typed as TypedEditorState<DefaultNodeTypes | SerializedBlockNode> (or TypedEditorState<SerializedBlockNode>)
|
|
22
|
-
* buildEditorState<DefaultNodeTypes | SerializedBlockNode>({ // or just buildEditorState<SerializedBlockNode> if you *only* want to allow block nodes
|
|
23
|
-
* nodes: [
|
|
24
|
-
* {
|
|
25
|
-
* type: 'block',
|
|
26
|
-
* fields: {
|
|
27
|
-
* id: 'id',
|
|
28
|
-
* blockName: 'Cool block',
|
|
29
|
-
* blockType: 'myBlock',
|
|
30
|
-
* },
|
|
31
|
-
* format: 'left',
|
|
32
|
-
* version: 1,
|
|
33
|
-
* }
|
|
34
|
-
* ],
|
|
35
|
-
* })
|
|
36
|
-
* ```
|
|
37
|
-
*/export function buildEditorState({
|
|
38
|
-
nodes,
|
|
39
|
-
text
|
|
40
|
-
}) {
|
|
41
|
-
const editorJSON = {
|
|
42
|
-
root: {
|
|
43
|
-
type: 'root',
|
|
44
|
-
children: [],
|
|
45
|
-
direction: 'ltr',
|
|
46
|
-
format: '',
|
|
47
|
-
indent: 0,
|
|
48
|
-
version: 1
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
if (text) {
|
|
52
|
-
editorJSON.root.children.push({
|
|
53
|
-
type: 'paragraph',
|
|
54
|
-
children: [{
|
|
55
|
-
type: 'text',
|
|
56
|
-
detail: 0,
|
|
57
|
-
format: 0,
|
|
58
|
-
mode: 'normal',
|
|
59
|
-
style: '',
|
|
60
|
-
text,
|
|
61
|
-
version: 1
|
|
62
|
-
}],
|
|
63
|
-
direction: 'ltr',
|
|
64
|
-
format: '',
|
|
65
|
-
indent: 0,
|
|
66
|
-
textFormat: 0,
|
|
67
|
-
textStyle: '',
|
|
68
|
-
version: 1
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (nodes?.length) {
|
|
72
|
-
editorJSON.root.children.push(...nodes);
|
|
73
|
-
}
|
|
74
|
-
return editorJSON;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=buildEditorState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildEditorState.js","names":["buildEditorState","nodes","text","editorJSON","root","type","children","direction","format","indent","version","push","detail","mode","style","textFormat","textStyle","length"],"sources":["../../src/utilities/buildEditorState.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type { DefaultTypedEditorState, TypedEditorState } from '../nodeTypes.js'\n\nexport function buildEditorState(args: {\n nodes?: DefaultTypedEditorState['root']['children']\n text?: string\n}): DefaultTypedEditorState\n\nexport function buildEditorState<T extends SerializedLexicalNode>(args: {\n // If you pass children typed for a specific schema T, the return is TypedEditorState<T>\n nodes?: TypedEditorState<T>['root']['children']\n text?: string\n}): TypedEditorState<T>\n\n/**\n * Helper to build lexical editor state JSON from text and/or nodes.\n *\n * @param nodes - The nodes to include in the editor state. If you pass the `text` argument, this will append your nodes after the first paragraph node.\n * @param text - The text content to include in the editor state. This will create a paragraph node with a text node for you and set that as the first node.\n * @returns The constructed editor state JSON.\n *\n * @example\n *\n * just passing text:\n *\n * ```ts\n * const editorState = buildEditorState({ text: 'Hello world' }) // result typed as DefaultTypedEditorState\n * ```\n *\n * @example\n *\n * passing nodes:\n *\n * ```ts\n * const editorState = // result typed as TypedEditorState<DefaultNodeTypes | SerializedBlockNode> (or TypedEditorState<SerializedBlockNode>)\n * buildEditorState<DefaultNodeTypes | SerializedBlockNode>({ // or just buildEditorState<SerializedBlockNode> if you *only* want to allow block nodes\n * nodes: [\n * {\n * type: 'block',\n * fields: {\n * id: 'id',\n * blockName: 'Cool block',\n * blockType: 'myBlock',\n * },\n * format: 'left',\n * version: 1,\n * }\n * ],\n * })\n * ```\n */\nexport function buildEditorState<T extends SerializedLexicalNode>({\n nodes,\n text,\n}: {\n nodes?: DefaultTypedEditorState['root']['children'] | TypedEditorState<T>['root']['children']\n text?: string\n}): DefaultTypedEditorState | TypedEditorState<T> {\n const editorJSON: DefaultTypedEditorState = {\n root: {\n type: 'root',\n children: [],\n direction: 'ltr',\n format: '',\n indent: 0,\n version: 1,\n },\n }\n\n if (text) {\n editorJSON.root.children.push({\n type: 'paragraph',\n children: [\n {\n type: 'text',\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n text,\n version: 1,\n },\n ],\n direction: 'ltr',\n format: '',\n indent: 0,\n textFormat: 0,\n textStyle: '',\n version: 1,\n })\n }\n\n if (nodes?.length) {\n editorJSON.root.children.push(...(nodes as any))\n }\n\n return editorJSON\n}\n"],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCA,OAAO,SAASA,iBAAkD;EAChEC,KAAK;EACLC;AAAI,CAIL;EACC,MAAMC,UAAA,GAAsC;IAC1CC,IAAA,EAAM;MACJC,IAAA,EAAM;MACNC,QAAA,EAAU,EAAE;MACZC,SAAA,EAAW;MACXC,MAAA,EAAQ;MACRC,MAAA,EAAQ;MACRC,OAAA,EAAS;IACX;EACF;EAEA,IAAIR,IAAA,EAAM;IACRC,UAAA,CAAWC,IAAI,CAACE,QAAQ,CAACK,IAAI,CAAC;MAC5BN,IAAA,EAAM;MACNC,QAAA,EAAU,CACR;QACED,IAAA,EAAM;QACNO,MAAA,EAAQ;QACRJ,MAAA,EAAQ;QACRK,IAAA,EAAM;QACNC,KAAA,EAAO;QACPZ,IAAA;QACAQ,OAAA,EAAS;MACX,EACD;MACDH,SAAA,EAAW;MACXC,MAAA,EAAQ;MACRC,MAAA,EAAQ;MACRM,UAAA,EAAY;MACZC,SAAA,EAAW;MACXN,OAAA,EAAS;IACX;EACF;EAEA,IAAIT,KAAA,EAAOgB,MAAA,EAAQ;IACjBd,UAAA,CAAWC,IAAI,CAACE,QAAQ,CAACK,IAAI,IAAKV,KAAA;EACpC;EAEA,OAAOE,UAAA;AACT","ignoreList":[]}
|
|
File without changes
|