@ecomcx/ecomweb-editor 1.18.0 → 1.19.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/package.json +25 -7
- package/src/index.ts +26 -25
- package/src/{ask.tsx → legacy/ask.tsx} +2 -2
- package/src/{blockMeta.ts → legacy/block-meta.ts} +1 -1
- package/src/{blocks.tsx → legacy/blocks.tsx} +8 -32
- package/src/{content.ts → legacy/content.ts} +1 -1
- package/src/{handle.tsx → legacy/drag-handle.tsx} +3 -3
- package/src/{dynamic.tsx → legacy/dynamic.tsx} +7 -3
- package/src/{Editor.tsx → legacy/editor.tsx} +9 -9
- package/src/{extensions.ts → legacy/extensions.ts} +1 -1
- package/src/legacy/insert-pattern.ts +13 -0
- package/src/{inserter.tsx → legacy/inserter.tsx} +6 -5
- package/src/{inspector.tsx → legacy/inspector.tsx} +7 -7
- package/src/{layoutUi.tsx → legacy/layout-ui.tsx} +6 -5
- package/src/{layout.tsx → legacy/layout.tsx} +2 -2
- package/src/{media.ts → legacy/media.ts} +1 -1
- package/src/{nodes.tsx → legacy/nodes.tsx} +2 -2
- package/src/{outline.tsx → legacy/outline.tsx} +4 -4
- package/src/legacy/panels.ts +22 -0
- package/src/{rank.ts → legacy/rank.ts} +2 -2
- package/src/{registry.ts → legacy/registry.ts} +1 -1
- package/src/{handles.tsx → legacy/resize-handles.tsx} +1 -1
- package/src/{styleattr.ts → legacy/style-attr.ts} +15 -1
- package/src/{synced.tsx → legacy/synced.tsx} +2 -2
- package/src/{toolbar.tsx → legacy/toolbar.tsx} +7 -7
- package/src/{unknown.tsx → legacy/unknown.tsx} +1 -1
- package/src/shared/block-defs.ts +38 -0
- package/src/shared/color-swatch.tsx +19 -0
- package/src/{panels.ts → shared/panel-store.ts} +4 -21
- package/src/{patterns.ts → shared/patterns.ts} +0 -12
- package/src/{stylepanel.tsx → shared/style-panel.tsx} +2 -2
- package/src/{types.ts → shared/types.ts} +2 -0
- package/src/v2/blocks/compat.tsx +51 -0
- package/src/v2/blocks/index.ts +42 -0
- package/src/v2/blocks/layout.tsx +281 -0
- package/src/v2/blocks/media-actions.tsx +76 -0
- package/src/v2/blocks/media.tsx +234 -0
- package/src/v2/blocks/resize.tsx +111 -0
- package/src/v2/blocks/text.tsx +149 -0
- package/src/v2/blocks/theme.tsx +293 -0
- package/src/v2/blocks/tools.tsx +72 -0
- package/src/v2/canvas/block-list.tsx +216 -0
- package/src/v2/canvas/canvas-css.ts +131 -0
- package/src/v2/canvas/canvas.tsx +379 -0
- package/src/v2/canvas/dnd.ts +192 -0
- package/src/v2/context.tsx +146 -0
- package/src/v2/core/bindings.ts +64 -0
- package/src/v2/core/clipboard.ts +238 -0
- package/src/v2/core/host.ts +80 -0
- package/src/v2/core/model.ts +157 -0
- package/src/v2/core/ops.ts +151 -0
- package/src/v2/core/patterns.ts +10 -0
- package/src/v2/core/registry.ts +135 -0
- package/src/v2/core/store.ts +804 -0
- package/src/v2/core/structure.ts +106 -0
- package/src/v2/core/tables.ts +194 -0
- package/src/v2/editor.css +310 -0
- package/src/v2/editor.tsx +288 -0
- package/src/v2/index.ts +28 -0
- package/src/v2/labels.ts +341 -0
- package/src/v2/prefs.ts +69 -0
- package/src/v2/text/paste.ts +75 -0
- package/src/v2/text/rich-schema.ts +96 -0
- package/src/v2/text/rich-text.tsx +512 -0
- package/src/v2/ui/attr-form.tsx +182 -0
- package/src/v2/ui/attr-hints.ts +109 -0
- package/src/v2/ui/bindings.tsx +91 -0
- package/src/v2/ui/block-descriptions.ts +34 -0
- package/src/v2/ui/color-field.tsx +17 -0
- package/src/v2/ui/doc-title.tsx +45 -0
- package/src/v2/ui/inserter.tsx +300 -0
- package/src/v2/ui/inspector.tsx +85 -0
- package/src/v2/ui/layout-panel.tsx +159 -0
- package/src/v2/ui/list-view.tsx +65 -0
- package/src/v2/ui/options.tsx +242 -0
- package/src/v2/ui/style-controls.tsx +57 -0
- package/src/v2/ui/style-tab.tsx +158 -0
- package/src/v2/ui/toolbar.tsx +397 -0
- package/src/v2/ui/unit-controls.tsx +99 -0
- /package/src/{basic.tsx → legacy/basic.tsx} +0 -0
- /package/src/{blockops.ts → legacy/block-ops.ts} +0 -0
- /package/src/{boundary.tsx → legacy/boundary.tsx} +0 -0
- /package/src/{editor.css → legacy/editor.css} +0 -0
- /package/src/{insert.ts → legacy/insert.ts} +0 -0
- /package/src/{labels.ts → shared/labels.ts} +0 -0
- /package/src/{paste.ts → shared/paste.ts} +0 -0
- /package/src/{util.ts → shared/util.ts} +0 -0
package/src/v2/prefs.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tuỳ chọn của trình soạn — cách trình soạn hiển thị cho người đang dùng (không đổi nội dung, không đổi website).
|
|
5
|
+
* Lưu theo người dùng qua `PrefsStorage` của ứng dụng (mặc định localStorage của trình duyệt).
|
|
6
|
+
*/
|
|
7
|
+
export interface EditorPrefs {
|
|
8
|
+
/** Thanh công cụ khối cố định dưới thanh trên cùng thay vì nổi trên khối. */
|
|
9
|
+
fixedToolbar: boolean;
|
|
10
|
+
/** Chỉ còn nội dung: ẩn thư viện khối, cây khối, bảng cài đặt. */
|
|
11
|
+
distractionFree: boolean;
|
|
12
|
+
/** Làm mờ mọi khối trừ khối đang sửa. */
|
|
13
|
+
spotlight: boolean;
|
|
14
|
+
/** Trình soạn che hết giao diện quản trị. */
|
|
15
|
+
fullscreen: boolean;
|
|
16
|
+
/** Mở sẵn cây khối khi vào trình soạn. */
|
|
17
|
+
showListView: boolean;
|
|
18
|
+
/** Đường dẫn khối (cha › con) ở đáy trình soạn. */
|
|
19
|
+
showBreadcrumbs: boolean;
|
|
20
|
+
/** Phím mũi tên không nhảy sang khối khác ở đầu/cuối khối. */
|
|
21
|
+
keepCaretInsideBlock: boolean;
|
|
22
|
+
/** Nút trên thanh công cụ hiện chữ thay vì chỉ biểu tượng. */
|
|
23
|
+
showIconLabels: boolean;
|
|
24
|
+
/** Mục "Dùng nhiều" trong thư viện khối. */
|
|
25
|
+
mostUsedBlocks: boolean;
|
|
26
|
+
/** Loại khối ẩn khỏi trình chèn (vẫn vẽ được nếu nội dung có sẵn). */
|
|
27
|
+
hiddenBlockTypes: string[];
|
|
28
|
+
/** Soạn bằng khối hoặc sửa thẳng mã (JSON nội dung). */
|
|
29
|
+
mode: "visual" | "code";
|
|
30
|
+
/** Số lần chèn theo loại khối (mục "Dùng nhiều"). */
|
|
31
|
+
insertCounts: Record<string, number>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const DEFAULT_PREFS: EditorPrefs = {
|
|
35
|
+
fixedToolbar: false, distractionFree: false, spotlight: false, fullscreen: false, showListView: false, showBreadcrumbs: true,
|
|
36
|
+
keepCaretInsideBlock: false, showIconLabels: false, mostUsedBlocks: true, hiddenBlockTypes: [], mode: "visual", insertCounts: {},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export interface PrefsStorage {
|
|
40
|
+
load(): Partial<EditorPrefs> | null;
|
|
41
|
+
save(prefs: EditorPrefs): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Lưu trong trình duyệt (mỗi máy một bộ); ứng dụng có tài khoản nên lưu lên máy chủ để theo người dùng. */
|
|
45
|
+
export const localPrefsStorage = (key = "ecx-editor-prefs"): PrefsStorage => ({
|
|
46
|
+
load() { try { return JSON.parse(localStorage.getItem(key) ?? "null"); } catch { return null; } },
|
|
47
|
+
save(p) { try { localStorage.setItem(key, JSON.stringify(p)); } catch { /* trình duyệt chặn bộ nhớ */ } },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export class PrefsStore {
|
|
51
|
+
private prefs: EditorPrefs;
|
|
52
|
+
private listeners = new Set<() => void>();
|
|
53
|
+
constructor(private storage: PrefsStorage = localPrefsStorage()) {
|
|
54
|
+
this.prefs = { ...DEFAULT_PREFS, ...(storage.load() ?? {}) };
|
|
55
|
+
}
|
|
56
|
+
get = () => this.prefs;
|
|
57
|
+
subscribe = (l: () => void) => { this.listeners.add(l); return () => { this.listeners.delete(l); }; };
|
|
58
|
+
set(patch: Partial<EditorPrefs>) {
|
|
59
|
+
this.prefs = { ...this.prefs, ...patch };
|
|
60
|
+
this.storage.save(this.prefs);
|
|
61
|
+
this.listeners.forEach((l) => l());
|
|
62
|
+
}
|
|
63
|
+
toggle(key: { [K in keyof EditorPrefs]: EditorPrefs[K] extends boolean ? K : never }[keyof EditorPrefs]) { this.set({ [key]: !this.prefs[key] } as Partial<EditorPrefs>); }
|
|
64
|
+
countInsert(type: string) { this.set({ insertCounts: { ...this.prefs.insertCounts, [type]: (this.prefs.insertCounts[type] ?? 0) + 1 } }); }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function usePrefs(store: PrefsStore): EditorPrefs {
|
|
68
|
+
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
69
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { embedInfo, type RichNode } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import type { EditorView } from "prosemirror-view";
|
|
3
|
+
import type { EditorContextValue } from "../context";
|
|
4
|
+
import { isUrl } from "../../shared/paste";
|
|
5
|
+
import { BLOCKS_MIME, htmlToRich, insertBlocksAtCaret, textToRich } from "../core/clipboard";
|
|
6
|
+
import { fromRich, inlineLength, makeBlock } from "../core/model";
|
|
7
|
+
|
|
8
|
+
/** Dán vào ô gõ: chữ có định dạng ở lại trong khối, nhiều khối thì tách khối tại con trỏ (lõi phân tích ở core/clipboard). */
|
|
9
|
+
export function pasteIntoBlock(ctx: EditorContextValue, blockId: string, view: EditorView, event: ClipboardEvent): boolean {
|
|
10
|
+
const data = event.clipboardData;
|
|
11
|
+
if (!data) return false;
|
|
12
|
+
const { store, registry } = ctx;
|
|
13
|
+
const block = store.block(blockId);
|
|
14
|
+
if (!block) return false;
|
|
15
|
+
const type = registry.get(block.type);
|
|
16
|
+
const { from, to } = view.state.selection;
|
|
17
|
+
|
|
18
|
+
const json = data.getData(BLOCKS_MIME);
|
|
19
|
+
if (json) {
|
|
20
|
+
try {
|
|
21
|
+
const nodes = (JSON.parse(json) as RichNode[]).map(fromRich);
|
|
22
|
+
if (nodes.length) { insertBlocksAtCaret(store, blockId, from, to, nodes); return true; }
|
|
23
|
+
} catch { /* clipboard hỏng: dán như chữ */ }
|
|
24
|
+
}
|
|
25
|
+
const text = data.getData("text/plain");
|
|
26
|
+
// Khối mã: chỉ dán chữ thuần
|
|
27
|
+
if (type?.multiline || type?.plain) {
|
|
28
|
+
if (!text) return false;
|
|
29
|
+
view.dispatch(view.state.tr.insertText(text));
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// Dán đường dẫn lên chữ đang bôi đen → liên kết
|
|
33
|
+
if (text && isUrl(text) && from !== to) {
|
|
34
|
+
view.dispatch(view.state.tr.addMark(from, to, view.state.schema.marks.link.create({ href: text.trim() })));
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
// Đường dẫn trong đoạn trống → khối nhúng / ảnh
|
|
38
|
+
if (text && isUrl(text) && block.type === "paragraph" && !inlineLength(block.inline)) {
|
|
39
|
+
const url = text.trim();
|
|
40
|
+
const node = /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(url) ? makeBlock("image", { src: url }) : embedInfo(url) ? makeBlock("embed", { url }) : null;
|
|
41
|
+
if (node) { store.replace(blockId, [node], { select: { ids: [node.id], editing: null }, caret: null }); return true; }
|
|
42
|
+
}
|
|
43
|
+
const html = data.getData("text/html");
|
|
44
|
+
if (html) {
|
|
45
|
+
const rich = htmlToRich(html);
|
|
46
|
+
// Một đoạn văn: để ProseMirror dán chữ có định dạng tại chỗ
|
|
47
|
+
if (rich.length > 1 || (rich.length === 1 && rich[0].type !== "paragraph")) {
|
|
48
|
+
insertBlocksAtCaret(store, blockId, from, to, rich.map(fromRich));
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (rich.length === 1) {
|
|
52
|
+
const doc = view.state.schema.nodeFromJSON({ type: "doc", content: (rich[0].content ?? []).map((n) => toPm(view, n)) });
|
|
53
|
+
view.dispatch(view.state.tr.replaceWith(from, to, doc.content));
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (text && /\n/.test(text)) {
|
|
58
|
+
const rich = textToRich(text);
|
|
59
|
+
if (rich.length > 1) { insertBlocksAtCaret(store, blockId, from, to, rich.map(fromRich)); return true; }
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** RichNode inline → JSON của inlineSchema (định dạng lạ bỏ qua khi dán). */
|
|
65
|
+
function toPm(view: EditorView, n: RichNode): Record<string, unknown> {
|
|
66
|
+
if (n.type === "text") {
|
|
67
|
+
const marks = (n.marks ?? []).filter((m) => view.state.schema.marks[m.type] && m.type !== "unknownMark");
|
|
68
|
+
return marks.length ? { type: "text", text: n.text, marks } : { type: "text", text: n.text };
|
|
69
|
+
}
|
|
70
|
+
return n.type === "hardBreak" ? { type: "hardBreak" } : { type: "inlineAtom", attrs: { json: n } };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Chép / cắt / dán khối đang chọn
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { RichMark, RichNode } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { Fragment, Schema, type Mark, type MarkSpec, type Node as PMNode } from "prosemirror-model";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema ProseMirror cho MỘT khối chữ: chỉ có chữ + định dạng (không có khối) — mỗi khối chữ là một ProseMirror nhỏ.
|
|
7
|
+
* Bộ gõ tiếng Việt (Telex/VNI, IME) do ProseMirror lo, không tự xử lý contenteditable.
|
|
8
|
+
* Nút inline / định dạng lạ (plugin) được giữ nguyên qua `inlineAtom` / `unknownMark`.
|
|
9
|
+
*/
|
|
10
|
+
const linkSpec: MarkSpec = {
|
|
11
|
+
attrs: { href: { default: "" }, target: { default: null }, rel: { default: null } },
|
|
12
|
+
inclusive: false,
|
|
13
|
+
parseDOM: [{ tag: "a[href]", getAttrs: (d) => ({ href: (d as HTMLElement).getAttribute("href"), target: (d as HTMLElement).getAttribute("target"), rel: (d as HTMLElement).getAttribute("rel") }) }],
|
|
14
|
+
toDOM: (m) => ["a", { href: m.attrs.href, target: m.attrs.target, rel: m.attrs.rel, "data-ecx-link": "" }, 0],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const simple = (tag: string, extra: string[] = []): MarkSpec => ({ parseDOM: [tag, ...extra].map((t) => ({ tag: t })), toDOM: () => [tag, 0] });
|
|
18
|
+
|
|
19
|
+
const marks: Record<string, MarkSpec> = {
|
|
20
|
+
link: linkSpec,
|
|
21
|
+
bold: simple("strong", ["b"]),
|
|
22
|
+
italic: simple("em", ["i"]),
|
|
23
|
+
underline: simple("u"),
|
|
24
|
+
strike: simple("s", ["del", "strike"]),
|
|
25
|
+
code: { ...simple("code"), excludes: "_" },
|
|
26
|
+
subscript: { ...simple("sub"), excludes: "superscript" },
|
|
27
|
+
superscript: { ...simple("sup"), excludes: "subscript" },
|
|
28
|
+
highlight: { attrs: { color: { default: null } }, parseDOM: [{ tag: "mark" }], toDOM: (m) => ["mark", m.attrs.color ? { style: `background:${m.attrs.color}` } : {}, 0] },
|
|
29
|
+
textStyle: { attrs: { color: { default: null } }, parseDOM: [{ tag: "span[style]" }], toDOM: (m) => ["span", m.attrs.color ? { style: `color:${m.attrs.color}` } : {}, 0] },
|
|
30
|
+
unknownMark: { attrs: { json: { default: null } }, excludes: "", toDOM: () => ["span", { "data-ecx-mark": "" }, 0] },
|
|
31
|
+
};
|
|
32
|
+
const inlineNodes = (pre: boolean) => ({
|
|
33
|
+
doc: { content: "inline*", ...(pre ? { whitespace: "pre" as const } : {}) },
|
|
34
|
+
text: { group: "inline" },
|
|
35
|
+
hardBreak: { group: "inline", inline: true, selectable: false, parseDOM: [{ tag: "br" }], toDOM: () => ["br"] as const },
|
|
36
|
+
inlineAtom: {
|
|
37
|
+
group: "inline", inline: true, atom: true, attrs: { json: { default: null } },
|
|
38
|
+
toDOM: (n: PMNode) => ["span", { "data-ecx-inline": (n.attrs.json as RichNode | null)?.type ?? "", contenteditable: "false", class: "ecx-inline-atom" }, `⟨${(n.attrs.json as RichNode | null)?.type ?? "?"}⟩`] as const,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** Chữ thường (đoạn, tiêu đề…): khoảng trắng gộp như HTML. */
|
|
43
|
+
export const inlineSchema = new Schema({ nodes: inlineNodes(false), marks });
|
|
44
|
+
/** Văn bản định dạng sẵn: giữ khoảng trắng, xuống dòng; vẫn có định dạng. */
|
|
45
|
+
export const preSchema = new Schema({ nodes: inlineNodes(true), marks });
|
|
46
|
+
/** Mã nguồn: chỉ chữ thuần, giữ mọi khoảng trắng và xuống dòng ("\n" là ký tự, không phải hardBreak). */
|
|
47
|
+
export const codeSchema = new Schema({ nodes: { doc: { content: "text*", code: true, whitespace: "pre" }, text: {} }, marks: {} });
|
|
48
|
+
|
|
49
|
+
export type SchemaKind = "inline" | "pre" | "code";
|
|
50
|
+
export const schemaOf = (kind: SchemaKind) => (kind === "code" ? codeSchema : kind === "pre" ? preSchema : inlineSchema);
|
|
51
|
+
|
|
52
|
+
const KNOWN_MARKS = new Set(Object.keys(inlineSchema.marks).filter((m) => m !== "unknownMark"));
|
|
53
|
+
|
|
54
|
+
function markFromRich(schema: Schema, m: RichMark): Mark {
|
|
55
|
+
if (KNOWN_MARKS.has(m.type)) return schema.marks[m.type].create(m.attrs ?? {});
|
|
56
|
+
return schema.marks.unknownMark.create({ json: m });
|
|
57
|
+
}
|
|
58
|
+
function markToRich(m: Mark): RichMark {
|
|
59
|
+
if (m.type.name === "unknownMark") return m.attrs.json as RichMark;
|
|
60
|
+
const attrs = Object.fromEntries(Object.entries(m.attrs).filter(([, v]) => v !== null && v !== undefined && v !== ""));
|
|
61
|
+
return Object.keys(attrs).length ? { type: m.type.name, attrs } : { type: m.type.name };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Chữ của khối (RichNode[]) → tài liệu ProseMirror theo loại ô gõ (mã nguồn: bỏ định dạng, hardBreak thành "\n"). */
|
|
65
|
+
export function inlineToDoc(inline: RichNode[] | undefined, kind: SchemaKind = "inline"): PMNode {
|
|
66
|
+
const schema = schemaOf(kind);
|
|
67
|
+
const nodes: PMNode[] = [];
|
|
68
|
+
const pushText = (text: string, ms: Mark[]) => { if (text) nodes.push(schema.text(text, ms)); };
|
|
69
|
+
for (const n of inline ?? []) {
|
|
70
|
+
if (n.type === "text") pushText(n.text ?? "", kind === "code" ? [] : (n.marks ?? []).map((m) => markFromRich(schema, m)));
|
|
71
|
+
else if (n.type === "hardBreak") { if (kind === "code") pushText("\n", []); else nodes.push(schema.nodes.hardBreak.create()); }
|
|
72
|
+
else if (kind !== "code") nodes.push(schema.nodes.inlineAtom.create({ json: n }));
|
|
73
|
+
}
|
|
74
|
+
// Mã nguồn: gộp các đoạn chữ liền nhau (schema "text*" không cho nút khác)
|
|
75
|
+
return schema.nodes.doc.create(null, Fragment.fromArray(nodes));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Tài liệu ProseMirror → chữ của khối, gộp các đoạn text cùng định dạng. */
|
|
79
|
+
export function docToInline(doc: PMNode): RichNode[] {
|
|
80
|
+
const out: RichNode[] = [];
|
|
81
|
+
doc.forEach((n) => {
|
|
82
|
+
if (n.isText) {
|
|
83
|
+
const marks = n.marks.map(markToRich);
|
|
84
|
+
const last = out[out.length - 1];
|
|
85
|
+
if (last && last.type === "text" && JSON.stringify(last.marks ?? []) === JSON.stringify(marks)) last.text += n.text!;
|
|
86
|
+
else out.push(marks.length ? { type: "text", text: n.text!, marks } : { type: "text", text: n.text! });
|
|
87
|
+
} else if (n.type.name === "hardBreak") out.push({ type: "hardBreak" });
|
|
88
|
+
else if (n.type.name === "inlineAtom") out.push(n.attrs.json as RichNode);
|
|
89
|
+
});
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Vị trí ký tự (0…độ dài) ↔ vị trí ProseMirror: tài liệu chỉ có inline nên lệch đúng 0. */
|
|
94
|
+
export const charToPos = (doc: PMNode, offset: number) => (offset < 0 ? doc.content.size : Math.min(offset, doc.content.size));
|
|
95
|
+
|
|
96
|
+
export const sameInline = (a: RichNode[] | undefined, b: RichNode[] | undefined) => JSON.stringify(a ?? []) === JSON.stringify(b ?? []);
|