@payload-onpage/lexical 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/InlineRichText.d.ts +13 -0
- package/dist/InlineRichText.d.ts.map +1 -0
- package/dist/InlineRichText.js +311 -0
- package/dist/InlineRichText.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +1 -0
- package/dist/convert.d.ts +15 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +65 -0
- package/dist/convert.js.map +1 -0
- package/dist/editor.d.ts +4 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +4 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/nodeList.d.ts +6 -0
- package/dist/nodeList.d.ts.map +1 -0
- package/dist/nodeList.js +13 -0
- package/dist/nodeList.js.map +1 -0
- package/dist/nodes.d.ts +76 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +136 -0
- package/dist/nodes.js.map +1 -0
- package/package.json +69 -4
- package/src/InlineRichText.tsx +542 -0
- package/src/constants.ts +2 -0
- package/src/convert.ts +73 -0
- package/src/editor.ts +10 -0
- package/src/index.ts +33 -0
- package/src/nodeList.ts +13 -0
- package/src/nodes.tsx +213 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jellologic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @payload-onpage/lexical
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Inline rich-text editing for Payload's Lexical `richText` fields. Reads and writes Payload's Lexical JSON, keeps Payload's link shape, and preserves nodes it doesn't edit (uploads, blocks…). The editor loads lazily, only when a rich-text field opens.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { lexicalEditors } from '@payload-onpage/lexical' // included by @payload-onpage/next by default
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Peers: `lexical` and `@lexical/*` `~0.50.0`, the versions Payload 3.90's `@payloadcms/richtext-lexical` uses. Entries: `.` (registry, converters), `./editor` (component and nodes).
|
|
10
|
+
|
|
11
|
+
Part of [**payload-onpage**](https://github.com/jellologic/payload-onpage): on-page editing and draft previews for Payload CMS + Next.js. Start with the [getting started guide](https://github.com/jellologic/payload-onpage/blob/main/docs/getting-started.md).
|
|
12
|
+
|
|
13
|
+
MIT licensed.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-place rich-text editing with Lexical. The editable surface is laid over
|
|
3
|
+
* the rendered element, takes its classes (so the site's prose styles apply)
|
|
4
|
+
* and hides the original. Clicking outside, or "Done", commits; Escape cancels.
|
|
5
|
+
* Only a real change is written: the value is compared with what the same
|
|
6
|
+
* editor produced for the untouched content.
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { type FieldEditorProps } from '@payload-onpage/react/editor-kit';
|
|
10
|
+
import { RICH_TEXT_NODES } from './nodeList.ts';
|
|
11
|
+
export { RICH_TEXT_NODES };
|
|
12
|
+
export declare function InlineRichText({ field, value, element, commit, close, ghost, live, point, t, }: FieldEditorProps): React.JSX.Element;
|
|
13
|
+
//# sourceMappingURL=InlineRichText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InlineRichText.d.ts","sourceRoot":"","sources":["../src/InlineRichText.tsx"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,OAAO,KAA6E,MAAM,OAAO,CAAA;AAsCjG,OAAO,EAML,KAAK,gBAAgB,EAEtB,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAG/C,OAAO,EAAE,eAAe,EAAE,CAAA;AA8V1B,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,EACL,CAAC,GACF,EAAE,gBAAgB,qBAyGlB"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* In-place rich-text editing with Lexical. The editable surface is laid over
|
|
5
|
+
* the rendered element, takes its classes (so the site's prose styles apply)
|
|
6
|
+
* and hides the original. Clicking outside, or "Done", commits; Escape cancels.
|
|
7
|
+
* Only a real change is written: the value is compared with what the same
|
|
8
|
+
* editor produced for the untouched content.
|
|
9
|
+
*/
|
|
10
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
12
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
13
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
14
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
15
|
+
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
16
|
+
import { ListPlugin } from '@lexical/react/LexicalListPlugin';
|
|
17
|
+
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
18
|
+
import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, } from '@lexical/rich-text';
|
|
19
|
+
import { $isListNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, } from '@lexical/list';
|
|
20
|
+
import { $setBlocksType } from '@lexical/selection';
|
|
21
|
+
import { $findMatchingParent } from '@lexical/utils';
|
|
22
|
+
import { $createParagraphNode, $createRangeSelectionFromDom, $getNearestNodeFromDOMNode, $getRoot, $getSelection, $isRangeSelection, $isTextNode, $setSelection, FORMAT_TEXT_COMMAND, REDO_COMMAND, UNDO_COMMAND, } from 'lexical';
|
|
23
|
+
import { eachLexicalNode, newRowId, safeLinkUrl } from '@payload-onpage/core';
|
|
24
|
+
import { HIDDEN, caretAt, placeOver, useEvent, useTrackElement, } from '@payload-onpage/react/editor-kit';
|
|
25
|
+
import { $createPayloadLinkNode, $isPayloadLinkNode } from "./nodes.js";
|
|
26
|
+
import { RICH_TEXT_NODES } from "./nodeList.js";
|
|
27
|
+
import { fromEditorState, plainText, toEditorState } from "./convert.js";
|
|
28
|
+
export { RICH_TEXT_NODES };
|
|
29
|
+
function readToolbarState() {
|
|
30
|
+
const sel = $getSelection();
|
|
31
|
+
if (!$isRangeSelection(sel))
|
|
32
|
+
return { bold: false, italic: false, underline: false, block: 'paragraph', link: false };
|
|
33
|
+
const anchor = sel.anchor.getNode();
|
|
34
|
+
const top = anchor.getKey() === 'root' ? anchor : anchor.getTopLevelElementOrThrow();
|
|
35
|
+
const list = $findMatchingParent(anchor, $isListNode);
|
|
36
|
+
const block = list
|
|
37
|
+
? `list-${list.getListType()}`
|
|
38
|
+
: $isHeadingNode(top)
|
|
39
|
+
? top.getTag()
|
|
40
|
+
: $isQuoteNode(top)
|
|
41
|
+
? 'quote'
|
|
42
|
+
: 'paragraph';
|
|
43
|
+
return {
|
|
44
|
+
bold: sel.hasFormat('bold'),
|
|
45
|
+
italic: sel.hasFormat('italic'),
|
|
46
|
+
underline: sel.hasFormat('underline'),
|
|
47
|
+
block,
|
|
48
|
+
link: !!$findMatchingParent(anchor, $isPayloadLinkNode),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Pull the browser's current selection into Lexical. Keyboard-extended
|
|
53
|
+
* selections (⌥⇧→ and friends) don't always reach Lexical's model before a
|
|
54
|
+
* toolbar click, so every toolbar action syncs first and acts on what the user
|
|
55
|
+
* actually sees selected.
|
|
56
|
+
*/
|
|
57
|
+
function syncSelection(editor) {
|
|
58
|
+
const dom = window.getSelection();
|
|
59
|
+
const root = editor.getRootElement();
|
|
60
|
+
if (!dom || !root || !dom.anchorNode || !root.contains(dom.anchorNode))
|
|
61
|
+
return;
|
|
62
|
+
editor.update(() => {
|
|
63
|
+
const sel = $createRangeSelectionFromDom(dom, editor);
|
|
64
|
+
if (sel)
|
|
65
|
+
$setSelection(sel);
|
|
66
|
+
}, { discrete: true });
|
|
67
|
+
}
|
|
68
|
+
/** The URL of the link around the selection, if any. */
|
|
69
|
+
function currentLinkUrl(editor) {
|
|
70
|
+
let url;
|
|
71
|
+
editor.getEditorState().read(() => {
|
|
72
|
+
const sel = $getSelection();
|
|
73
|
+
if ($isRangeSelection(sel))
|
|
74
|
+
url = $findMatchingParent(sel.anchor.getNode(), $isPayloadLinkNode)?.getFields().url;
|
|
75
|
+
});
|
|
76
|
+
return url;
|
|
77
|
+
}
|
|
78
|
+
/** Link the selection to `url`; an empty url removes the link around it. */
|
|
79
|
+
/** Link the selection; returns false (and changes nothing) for an unsafe URL such as `javascript:`. */
|
|
80
|
+
function applyLink(editor, rawUrl, saved) {
|
|
81
|
+
const url = rawUrl.trim();
|
|
82
|
+
if (url && !safeLinkUrl(url))
|
|
83
|
+
return false;
|
|
84
|
+
editor.update(() => {
|
|
85
|
+
// Focus moved to the URL field; put back the selection it was opened for.
|
|
86
|
+
if (saved)
|
|
87
|
+
$setSelection(saved.clone());
|
|
88
|
+
const sel = $getSelection();
|
|
89
|
+
if (!$isRangeSelection(sel))
|
|
90
|
+
return;
|
|
91
|
+
const nodes = sel.extract();
|
|
92
|
+
const existing = nodes.map((n) => $findMatchingParent(n, $isPayloadLinkNode)).find(Boolean);
|
|
93
|
+
if (existing) {
|
|
94
|
+
if (!url) {
|
|
95
|
+
for (const child of existing.getChildren())
|
|
96
|
+
existing.insertBefore(child);
|
|
97
|
+
existing.remove();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
existing.setFields({ ...existing.getFields(), url });
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!url)
|
|
105
|
+
return;
|
|
106
|
+
let link = null;
|
|
107
|
+
for (const node of nodes) {
|
|
108
|
+
if (!$isTextNode(node) || $findMatchingParent(node, $isPayloadLinkNode))
|
|
109
|
+
continue;
|
|
110
|
+
if (!link || node.getPreviousSibling() !== link) {
|
|
111
|
+
// Payload's own link node carries an id; so do ours.
|
|
112
|
+
link = $createPayloadLinkNode({ url, newTab: /^https?:/.test(url), linkType: 'custom' }, newRowId());
|
|
113
|
+
node.insertBefore(link);
|
|
114
|
+
}
|
|
115
|
+
link.append(node);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
/** A toolbar button that keeps the editor's selection (and syncs a keyboard selection first). */
|
|
121
|
+
function ToolButton({ label, title, pressed = false, onAction, id, }) {
|
|
122
|
+
const [editor] = useLexicalComposerContext();
|
|
123
|
+
return (_jsx("button", { type: "button", className: "po-btn", title: title, "aria-label": title, "aria-pressed": pressed, "data-testid": `onpage-rt-${id}`, onMouseDown: (e) => e.preventDefault() /* keep the editor's selection */, onClick: () => {
|
|
124
|
+
syncSelection(editor);
|
|
125
|
+
onAction();
|
|
126
|
+
}, children: label }));
|
|
127
|
+
}
|
|
128
|
+
function Toolbar({ onDone, t }) {
|
|
129
|
+
const [editor] = useLexicalComposerContext();
|
|
130
|
+
const [state, setState] = useState({
|
|
131
|
+
bold: false,
|
|
132
|
+
italic: false,
|
|
133
|
+
underline: false,
|
|
134
|
+
block: 'paragraph',
|
|
135
|
+
link: false,
|
|
136
|
+
});
|
|
137
|
+
const [linkDraft, setLinkDraft] = useState(null);
|
|
138
|
+
const savedSelection = useRef(null);
|
|
139
|
+
const [linkError, setLinkError] = useState(false);
|
|
140
|
+
const openLink = () => {
|
|
141
|
+
editor.getEditorState().read(() => {
|
|
142
|
+
savedSelection.current = $getSelection()?.clone() ?? null;
|
|
143
|
+
});
|
|
144
|
+
setLinkDraft(currentLinkUrl(editor) ?? 'https://');
|
|
145
|
+
};
|
|
146
|
+
const saveLink = () => {
|
|
147
|
+
if (linkDraft === null)
|
|
148
|
+
return;
|
|
149
|
+
if (!applyLink(editor, linkDraft === 'https://' ? '' : linkDraft, savedSelection.current)) {
|
|
150
|
+
setLinkError(true);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
setLinkError(false);
|
|
154
|
+
setLinkDraft(null);
|
|
155
|
+
editor.focus();
|
|
156
|
+
};
|
|
157
|
+
useEffect(() => editor.registerUpdateListener(({ editorState }) => editorState.read(() => setState(readToolbarState()))), [editor]);
|
|
158
|
+
const setBlock = (kind) => editor.update(() => {
|
|
159
|
+
const sel = $getSelection();
|
|
160
|
+
if (!$isRangeSelection(sel))
|
|
161
|
+
return;
|
|
162
|
+
const target = state.block === kind ? 'paragraph' : kind;
|
|
163
|
+
$setBlocksType(sel, () => target === 'paragraph'
|
|
164
|
+
? $createParagraphNode()
|
|
165
|
+
: target === 'quote'
|
|
166
|
+
? $createQuoteNode()
|
|
167
|
+
: $createHeadingNode(target));
|
|
168
|
+
});
|
|
169
|
+
const list = (type) => {
|
|
170
|
+
if (state.block === `list-${type}`)
|
|
171
|
+
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
|
|
172
|
+
else
|
|
173
|
+
editor.dispatchCommand(type === 'bullet' ? INSERT_UNORDERED_LIST_COMMAND : INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
174
|
+
};
|
|
175
|
+
return (_jsxs("div", { className: "po-rt-toolbar", role: "toolbar", "aria-label": t('rt.toolbar'), children: [_jsx(ToolButton, { label: _jsx("b", { children: "B" }), title: t('rt.bold'), pressed: state.bold, onAction: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold'), id: "bold" }), _jsx(ToolButton, { label: _jsx("i", { children: "I" }), title: t('rt.italic'), pressed: state.italic, onAction: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic'), id: "italic" }), _jsx(ToolButton, { label: _jsx("u", { children: "U" }), title: t('rt.underline'), pressed: state.underline, onAction: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline'), id: "underline" }), _jsx(ToolButton, { label: "\uD83D\uDD17", title: t('rt.link'), pressed: state.link, onAction: openLink, id: "link" }), _jsx(ToolButton, { label: "H2", title: t('rt.h2'), pressed: state.block === 'h2', onAction: () => setBlock('h2'), id: "h2" }), _jsx(ToolButton, { label: "H3", title: t('rt.h3'), pressed: state.block === 'h3', onAction: () => setBlock('h3'), id: "h3" }), _jsx(ToolButton, { label: "\u2022", title: t('rt.ul'), pressed: state.block === 'list-bullet', onAction: () => list('bullet'), id: "ul" }), _jsx(ToolButton, { label: "1.", title: t('rt.ol'), pressed: state.block === 'list-number', onAction: () => list('number'), id: "ol" }), _jsx(ToolButton, { label: "\u275D", title: t('rt.quote'), pressed: state.block === 'quote', onAction: () => setBlock('quote'), id: "quote" }), _jsx(ToolButton, { label: "\u21B6", title: t('dock.undo'), onAction: () => editor.dispatchCommand(UNDO_COMMAND, undefined), id: "undo" }), _jsx(ToolButton, { label: "\u21B7", title: t('dock.redo'), onAction: () => editor.dispatchCommand(REDO_COMMAND, undefined), id: "redo" }), _jsx(ToolButton, { label: t('rt.done'), title: t('rt.done'), onAction: onDone, id: "done" }), linkDraft !== null && (_jsxs("span", { style: { display: 'inline-flex', gap: 4, marginLeft: 6 }, children: [_jsx("input", { className: "po-input", style: { width: 260, height: 28 }, value: linkDraft, "aria-invalid": linkError || undefined, title: linkError ? t('rt.linkInvalid') : undefined, ref: (el) => el?.focus(), placeholder: t('rt.linkPlaceholder'), onChange: (e) => setLinkDraft(e.target.value), onKeyDown: (e) => {
|
|
176
|
+
if (e.key === 'Enter') {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
saveLink();
|
|
179
|
+
}
|
|
180
|
+
else if (e.key === 'Escape') {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
e.stopPropagation();
|
|
183
|
+
setLinkDraft(null);
|
|
184
|
+
}
|
|
185
|
+
}, "data-testid": "onpage-rt-link-input" }), _jsx("button", { type: "button", className: "po-btn", onMouseDown: (e) => e.preventDefault(), onClick: saveLink, "data-testid": "onpage-rt-link-apply", children: "Apply" })] }))] }));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Grabs the editor instance and puts the caret where the user clicked —
|
|
189
|
+
* through Lexical's own selection (setting only the DOM selection leaves
|
|
190
|
+
* Lexical's model at the end of the text, so keys and toolbar act there).
|
|
191
|
+
*/
|
|
192
|
+
function Bridge({ onReady, point, }) {
|
|
193
|
+
const [editor] = useLexicalComposerContext();
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
onReady(editor);
|
|
196
|
+
const root = editor.getRootElement();
|
|
197
|
+
if (!root)
|
|
198
|
+
return;
|
|
199
|
+
// Wait two frames so the surface sits exactly over the original text.
|
|
200
|
+
let raf = requestAnimationFrame(() => (raf = requestAnimationFrame(() => {
|
|
201
|
+
const hit = point ? caretAt(point, root) : null;
|
|
202
|
+
// Focus first: Lexical may restore its own selection on focus, which would
|
|
203
|
+
// undo the caret placement if it came before.
|
|
204
|
+
root.focus({ preventScroll: true });
|
|
205
|
+
editor.update(() => {
|
|
206
|
+
const node = hit ? $getNearestNodeFromDOMNode(hit.node) : null;
|
|
207
|
+
if (node && $isTextNode(node))
|
|
208
|
+
node.select(hit.offset, hit.offset);
|
|
209
|
+
else
|
|
210
|
+
$getRoot().selectEnd();
|
|
211
|
+
}, { discrete: true });
|
|
212
|
+
})));
|
|
213
|
+
return () => cancelAnimationFrame(raf);
|
|
214
|
+
}, [editor, onReady, point]);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
export function InlineRichText({ field, value, element, commit, close, ghost, live, point, t, }) {
|
|
218
|
+
const box = useRef(null);
|
|
219
|
+
const editorRef = useRef(null);
|
|
220
|
+
const baseline = useRef(null);
|
|
221
|
+
const done = useRef(false);
|
|
222
|
+
// The surface takes the element's classes, so the site's prose styles apply.
|
|
223
|
+
const [className] = useState(() => {
|
|
224
|
+
const cls = element()?.className;
|
|
225
|
+
return typeof cls === 'string' ? cls : '';
|
|
226
|
+
});
|
|
227
|
+
const onReady = useCallback((editor) => {
|
|
228
|
+
editorRef.current = editor;
|
|
229
|
+
baseline.current = JSON.stringify(editor.getEditorState().toJSON());
|
|
230
|
+
}, []);
|
|
231
|
+
const initialState = useMemo(() => JSON.stringify(toEditorState(value)), []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
232
|
+
useLayoutEffect(() => {
|
|
233
|
+
const el = element();
|
|
234
|
+
if (el) {
|
|
235
|
+
// Position before first paint, so the caret hit-test finds the surface.
|
|
236
|
+
if (box.current)
|
|
237
|
+
placeOver(box.current, el);
|
|
238
|
+
el.setAttribute(HIDDEN, 'true');
|
|
239
|
+
}
|
|
240
|
+
return () => element()?.removeAttribute(HIDDEN);
|
|
241
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
242
|
+
}, []);
|
|
243
|
+
// Follow the original element's box as the page scrolls and reflows.
|
|
244
|
+
useTrackElement(element, (el) => {
|
|
245
|
+
if (!box.current)
|
|
246
|
+
return;
|
|
247
|
+
if (!el.hasAttribute(HIDDEN))
|
|
248
|
+
el.setAttribute(HIDDEN, 'true');
|
|
249
|
+
placeOver(box.current, el);
|
|
250
|
+
});
|
|
251
|
+
const finish = (save) => {
|
|
252
|
+
if (done.current)
|
|
253
|
+
return;
|
|
254
|
+
done.current = true;
|
|
255
|
+
const editor = editorRef.current;
|
|
256
|
+
if (save && editor) {
|
|
257
|
+
const json = editor.getEditorState().toJSON();
|
|
258
|
+
if (JSON.stringify(json) !== baseline.current) {
|
|
259
|
+
const next = fromEditorState(json);
|
|
260
|
+
commit(plainText(next) || hasOpaque(next) ? next : null);
|
|
261
|
+
const surface = editor.getRootElement();
|
|
262
|
+
if (!live && surface)
|
|
263
|
+
ghost({ html: surface.innerHTML, className });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
close();
|
|
267
|
+
};
|
|
268
|
+
// Commit when the user clicks anywhere outside the editor.
|
|
269
|
+
// Escape (inside the editor) cancels.
|
|
270
|
+
const onOutside = useEvent((e) => {
|
|
271
|
+
if (box.current && !box.current.contains(e.target))
|
|
272
|
+
finish(true);
|
|
273
|
+
});
|
|
274
|
+
const onEscape = useEvent((e) => {
|
|
275
|
+
if (e.key === 'Escape' && box.current?.contains(document.activeElement)) {
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
finish(false);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
const onDown = (e) => onOutside(e);
|
|
282
|
+
const onKey = (e) => onEscape(e);
|
|
283
|
+
document.addEventListener('pointerdown', onDown, true);
|
|
284
|
+
document.addEventListener('keydown', onKey);
|
|
285
|
+
return () => {
|
|
286
|
+
document.removeEventListener('pointerdown', onDown, true);
|
|
287
|
+
document.removeEventListener('keydown', onKey);
|
|
288
|
+
};
|
|
289
|
+
}, [onEscape, onOutside]);
|
|
290
|
+
return (_jsx("div", { ref: box, className: "po-rt", role: "group", "aria-label": t('inline.label', { field: field.label }), "data-testid": "onpage-inline-richtext", children: _jsxs(LexicalComposer, { initialConfig: {
|
|
291
|
+
namespace: 'payload-onpage',
|
|
292
|
+
nodes: RICH_TEXT_NODES,
|
|
293
|
+
editorState: initialState,
|
|
294
|
+
onError: (error) => console.error('[payload-onpage] rich text', error),
|
|
295
|
+
theme: { text: { bold: 'po-b', italic: 'po-i', underline: 'po-u' } },
|
|
296
|
+
}, children: [_jsx(Toolbar, { onDone: () => finish(true), t: t }), _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: `${className} po-rt-surface`, "aria-label": t('inline.label', { field: field.label }) }), ErrorBoundary: LexicalErrorBoundary }), _jsx(HistoryPlugin, {}), _jsx(ListPlugin, {}), _jsx(Bridge, { onReady: onReady, point: point })] }) }));
|
|
297
|
+
}
|
|
298
|
+
/** Does the value hold nodes the editor shows as placeholders (uploads, blocks…)? Then it isn't empty. */
|
|
299
|
+
function hasOpaque(state) {
|
|
300
|
+
let found = false;
|
|
301
|
+
eachLexicalNode(state, (n) => {
|
|
302
|
+
if (n.type !== 'root' &&
|
|
303
|
+
n.type !== 'paragraph' &&
|
|
304
|
+
n.type !== 'text' &&
|
|
305
|
+
n.type !== 'linebreak' &&
|
|
306
|
+
!n.children)
|
|
307
|
+
found = true;
|
|
308
|
+
});
|
|
309
|
+
return found;
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=InlineRichText.js.map
|
|
@@ -0,0 +1 @@
|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AED,KAAC,OAAO,IAAC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,GAAI,EAC7C,KAAC,cAAc,IACb,eAAe,EACb,KAAC,eAAe,IACd,SAAS,EAAE,GAAG,SAAS,gBAAgB,gBAC3B,CAAC,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,GACrD,EAEJ,aAAa,EAAE,oBAAoB,GACnC,EACF,KAAC,aAAa,KAAG,EACjB,KAAC,UAAU,KAAG,EACd,KAAC,MAAM,IAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAI,IAC1B,GACd,CACP,CAAA;AACH,CAAC;AAED,0GAA0G;AAC1G,SAAS,SAAS,CAAC,KAAoB;IACrC,IAAI,KAAK,GAAG,KAAK,CAAA;IACjB,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;QAC3B,IACE,CAAC,CAAC,IAAI,KAAK,MAAM;YACjB,CAAC,CAAC,IAAI,KAAK,WAAW;YACtB,CAAC,CAAC,IAAI,KAAK,MAAM;YACjB,CAAC,CAAC,IAAI,KAAK,WAAW;YACtB,CAAC,CAAC,CAAC,QAAQ;YAEX,KAAK,GAAG,IAAI,CAAA;IAChB,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,eAAO,MAAM,WAAW,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload rich text ⇄ the inline editor's Lexical state. Node types we edit go
|
|
3
|
+
* through as-is; everything else is wrapped in an OpaqueNode on the way in and
|
|
4
|
+
* unwrapped on the way out, byte-for-byte.
|
|
5
|
+
*/
|
|
6
|
+
import { type LexicalState } from '@payload-onpage/core';
|
|
7
|
+
export declare const EDITABLE_NODE_TYPES: Set<string>;
|
|
8
|
+
export type RichTextState = LexicalState;
|
|
9
|
+
export declare const EMPTY_STATE: RichTextState;
|
|
10
|
+
export declare function isRichTextState(value: unknown): value is RichTextState;
|
|
11
|
+
export declare function toEditorState(value: unknown): RichTextState;
|
|
12
|
+
export declare function fromEditorState(state: RichTextState): RichTextState;
|
|
13
|
+
/** Plain text of a state (used to treat a blank editor as "no value"). */
|
|
14
|
+
export declare function plainText(state: RichTextState): string;
|
|
15
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAqC,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAG3F,eAAO,MAAM,mBAAmB,aAW9B,CAAA;AAGF,MAAM,MAAM,aAAa,GAAG,YAAY,CAAA;AAExC,eAAO,MAAM,WAAW,EAAE,aAWzB,CAAA;AAYD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAItE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAM3D;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAEnE;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAMtD"}
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload rich text ⇄ the inline editor's Lexical state. Node types we edit go
|
|
3
|
+
* through as-is; everything else is wrapped in an OpaqueNode on the way in and
|
|
4
|
+
* unwrapped on the way out, byte-for-byte.
|
|
5
|
+
*/
|
|
6
|
+
import { eachLexicalNode } from '@payload-onpage/core';
|
|
7
|
+
import { OPAQUE_TYPE } from "./constants.js";
|
|
8
|
+
export const EDITABLE_NODE_TYPES = new Set([
|
|
9
|
+
'root',
|
|
10
|
+
'paragraph',
|
|
11
|
+
'heading',
|
|
12
|
+
'quote',
|
|
13
|
+
'list',
|
|
14
|
+
'listitem',
|
|
15
|
+
'text',
|
|
16
|
+
'linebreak',
|
|
17
|
+
'tab',
|
|
18
|
+
'link',
|
|
19
|
+
]);
|
|
20
|
+
export const EMPTY_STATE = {
|
|
21
|
+
root: {
|
|
22
|
+
type: 'root',
|
|
23
|
+
version: 1,
|
|
24
|
+
format: '',
|
|
25
|
+
indent: 0,
|
|
26
|
+
direction: null,
|
|
27
|
+
children: [
|
|
28
|
+
{ type: 'paragraph', version: 1, format: '', indent: 0, direction: null, children: [] },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
function wrap(node) {
|
|
33
|
+
if (!EDITABLE_NODE_TYPES.has(node.type))
|
|
34
|
+
return { type: OPAQUE_TYPE, version: 1, data: node };
|
|
35
|
+
return Array.isArray(node.children) ? { ...node, children: node.children.map(wrap) } : node;
|
|
36
|
+
}
|
|
37
|
+
function unwrap(node) {
|
|
38
|
+
if (node.type === OPAQUE_TYPE)
|
|
39
|
+
return node.data;
|
|
40
|
+
return Array.isArray(node.children) ? { ...node, children: node.children.map(unwrap) } : node;
|
|
41
|
+
}
|
|
42
|
+
export function isRichTextState(value) {
|
|
43
|
+
return (!!value && typeof value === 'object' && value.root?.type === 'root');
|
|
44
|
+
}
|
|
45
|
+
export function toEditorState(value) {
|
|
46
|
+
const state = isRichTextState(value) ? value : EMPTY_STATE;
|
|
47
|
+
const root = wrap(state.root);
|
|
48
|
+
// Lexical needs at least one block child to place a caret.
|
|
49
|
+
if (!root.children?.length)
|
|
50
|
+
root.children = EMPTY_STATE.root.children;
|
|
51
|
+
return { root };
|
|
52
|
+
}
|
|
53
|
+
export function fromEditorState(state) {
|
|
54
|
+
return { root: unwrap(state.root) };
|
|
55
|
+
}
|
|
56
|
+
/** Plain text of a state (used to treat a blank editor as "no value"). */
|
|
57
|
+
export function plainText(state) {
|
|
58
|
+
const parts = [];
|
|
59
|
+
eachLexicalNode(state, (n) => {
|
|
60
|
+
if (typeof n.text === 'string')
|
|
61
|
+
parts.push(n.text);
|
|
62
|
+
});
|
|
63
|
+
return parts.join('').trim();
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAuC,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IACzC,MAAM;IACN,WAAW;IACX,SAAS;IACT,OAAO;IACP,MAAM;IACN,UAAU;IACV,MAAM;IACN,WAAW;IACX,KAAK;IACL,MAAM;CACP,CAAC,CAAA;AAKF,MAAM,CAAC,MAAM,WAAW,GAAkB;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;SACxF;KACF;CACF,CAAA;AAED,SAAS,IAAI,CAAC,IAAU;IACtB,IAAI,CAAC,mBAA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AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;AACrC,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,KAAoB;IAC5C,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;QAC3B,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;AAC9B,CAAC"}
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The rich-text editor component and its Lexical nodes (statically imported; prefer `lexicalEditors` for lazy loading). */
|
|
2
|
+
export { InlineRichText, RICH_TEXT_NODES } from './InlineRichText.tsx';
|
|
3
|
+
export { PayloadLinkNode, OpaqueNode, $createPayloadLinkNode, $isPayloadLinkNode, describeNode, type OpaqueData, } from './nodes.tsx';
|
|
4
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EACL,eAAe,EACf,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,KAAK,UAAU,GAChB,MAAM,aAAa,CAAA"}
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The rich-text editor component and its Lexical nodes (statically imported; prefer `lexicalEditors` for lazy loading). */
|
|
2
|
+
export { InlineRichText, RICH_TEXT_NODES } from "./InlineRichText.js";
|
|
3
|
+
export { PayloadLinkNode, OpaqueNode, $createPayloadLinkNode, $isPayloadLinkNode, describeNode, } from "./nodes.js";
|
|
4
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAsB,CAAA;AACtE,OAAO,EACL,eAAe,EACf,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,GAEb,MAAM,YAAa,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @payload-onpage/lexical — inline rich-text editing for Payload's Lexical
|
|
3
|
+
* richText fields.
|
|
4
|
+
*
|
|
5
|
+
* <OnPageEditor editors={lexicalEditors} … /> // the Next adapter includes it by default
|
|
6
|
+
*
|
|
7
|
+
* Light by design: the Lexical editor itself (~75 KB gz with Lexical) loads
|
|
8
|
+
* only when someone opens a rich-text field. It reads and writes Payload's
|
|
9
|
+
* Lexical JSON; links keep Payload's shape, and nodes it doesn't edit
|
|
10
|
+
* (uploads, blocks, relationships…) are kept as-is and shown as placeholders.
|
|
11
|
+
* The editor component and its nodes are in `@payload-onpage/lexical/editor`.
|
|
12
|
+
*/
|
|
13
|
+
import type { EditorRegistry } from '@payload-onpage/react/editor-kit';
|
|
14
|
+
export declare const lexicalEditors: EditorRegistry;
|
|
15
|
+
export { toEditorState, fromEditorState, plainText, isRichTextState, type RichTextState, } from './convert.ts';
|
|
16
|
+
export { OPAQUE_TYPE } from './constants.ts';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAOtE,eAAO,MAAM,cAAc,EAAE,cAE5B,CAAA;AAED,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACT,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { lazy } from 'react';
|
|
3
|
+
const InlineRichText = lazy(() => import("./InlineRichText.js").then((m) => ({ default: m.InlineRichText })));
|
|
4
|
+
export const lexicalEditors = {
|
|
5
|
+
richText: { mode: 'inline', component: InlineRichText },
|
|
6
|
+
};
|
|
7
|
+
export { toEditorState, fromEditorState, plainText, isRichTextState, } from "./convert.js";
|
|
8
|
+
export { OPAQUE_TYPE } from "./constants.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAeZ,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAE5B,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAC/B,MAAM,CAAC,qBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAC5E,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE;CACxD,CAAA;AAED,OAAO,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACT,eAAe,GAEhB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The node classes the inline editor registers (no React UI imported here). */
|
|
2
|
+
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
3
|
+
import { ListItemNode, ListNode } from '@lexical/list';
|
|
4
|
+
import { OpaqueNode, PayloadLinkNode } from './nodes.tsx';
|
|
5
|
+
export declare const RICH_TEXT_NODES: (typeof PayloadLinkNode | typeof OpaqueNode | typeof HeadingNode | typeof QuoteNode | typeof ListNode | typeof ListItemNode)[];
|
|
6
|
+
//# sourceMappingURL=nodeList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeList.d.ts","sourceRoot":"","sources":["../src/nodeList.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,eAAe,gIAO3B,CAAA"}
|
package/dist/nodeList.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The node classes the inline editor registers (no React UI imported here). */
|
|
2
|
+
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
3
|
+
import { ListItemNode, ListNode } from '@lexical/list';
|
|
4
|
+
import { OpaqueNode, PayloadLinkNode } from "./nodes.js";
|
|
5
|
+
export const RICH_TEXT_NODES = [
|
|
6
|
+
HeadingNode,
|
|
7
|
+
QuoteNode,
|
|
8
|
+
ListNode,
|
|
9
|
+
ListItemNode,
|
|
10
|
+
PayloadLinkNode,
|
|
11
|
+
OpaqueNode,
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=nodeList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeList.js","sourceRoot":"","sources":["../src/nodeList.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAa,CAAA;AAEzD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW;IACX,SAAS;IACT,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,UAAU;CACX,CAAA"}
|