smartrte-core 0.2.1 → 1.0.0-beta.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/CHANGELOG.md +12 -0
- package/README.md +23 -0
- package/dist/command.d.ts +8 -8
- package/dist/editor.d.ts +32 -0
- package/dist/editor.js +121 -0
- package/dist/foundation/annotations/index.d.ts +2 -0
- package/dist/foundation/annotations/index.js +2 -0
- package/dist/foundation/annotations/range.d.ts +54 -0
- package/dist/foundation/annotations/range.js +158 -0
- package/dist/foundation/annotations/types.d.ts +33 -0
- package/dist/foundation/annotations/types.js +1 -0
- package/dist/foundation/atom/commands.d.ts +11 -0
- package/dist/foundation/atom/commands.js +118 -0
- package/dist/foundation/atom/composition.d.ts +8 -0
- package/dist/foundation/atom/composition.js +22 -0
- package/dist/foundation/atom/declarations.d.ts +2 -0
- package/dist/foundation/atom/declarations.js +17 -0
- package/dist/foundation/atom/formats.d.ts +21 -0
- package/dist/foundation/atom/formats.js +77 -0
- package/dist/foundation/atom/index.d.ts +10 -0
- package/dist/foundation/atom/index.js +10 -0
- package/dist/foundation/atom/lifecycle.d.ts +12 -0
- package/dist/foundation/atom/lifecycle.js +41 -0
- package/dist/foundation/atom/persistence.d.ts +3 -0
- package/dist/foundation/atom/persistence.js +20 -0
- package/dist/foundation/atom/plugin.d.ts +20 -0
- package/dist/foundation/atom/plugin.js +55 -0
- package/dist/foundation/atom/schema.d.ts +3 -0
- package/dist/foundation/atom/schema.js +29 -0
- package/dist/foundation/atom/security.d.ts +10 -0
- package/dist/foundation/atom/security.js +20 -0
- package/dist/foundation/atom/selection.d.ts +3 -0
- package/dist/foundation/atom/selection.js +4 -0
- package/dist/foundation/atom/types.d.ts +47 -0
- package/dist/foundation/atom/types.js +1 -0
- package/dist/foundation/block/commands.d.ts +17 -0
- package/dist/foundation/block/commands.js +197 -0
- package/dist/foundation/block/formats.d.ts +33 -0
- package/dist/foundation/block/formats.js +57 -0
- package/dist/foundation/block/index.d.ts +5 -0
- package/dist/foundation/block/index.js +5 -0
- package/dist/foundation/block/input.d.ts +19 -0
- package/dist/foundation/block/input.js +67 -0
- package/dist/foundation/block/plugin.d.ts +26 -0
- package/dist/foundation/block/plugin.js +79 -0
- package/dist/foundation/block/schema.d.ts +49 -0
- package/dist/foundation/block/schema.js +27 -0
- package/dist/foundation/block/types.d.ts +40 -0
- package/dist/foundation/block/types.js +1 -0
- package/dist/foundation/boundaries.d.ts +11 -0
- package/dist/foundation/boundaries.js +117 -0
- package/dist/foundation/clipboard/detection.d.ts +3 -0
- package/dist/foundation/clipboard/detection.js +29 -0
- package/dist/foundation/clipboard/diagnostics.d.ts +24 -0
- package/dist/foundation/clipboard/diagnostics.js +59 -0
- package/dist/foundation/clipboard/index.d.ts +8 -0
- package/dist/foundation/clipboard/index.js +8 -0
- package/dist/foundation/clipboard/insertion.d.ts +22 -0
- package/dist/foundation/clipboard/insertion.js +210 -0
- package/dist/foundation/clipboard/normalizers.d.ts +8 -0
- package/dist/foundation/clipboard/normalizers.js +229 -0
- package/dist/foundation/clipboard/pipeline.d.ts +13 -0
- package/dist/foundation/clipboard/pipeline.js +58 -0
- package/dist/foundation/clipboard/sanitizer.d.ts +3 -0
- package/dist/foundation/clipboard/sanitizer.js +58 -0
- package/dist/foundation/clipboard/serialization.d.ts +5 -0
- package/dist/foundation/clipboard/serialization.js +33 -0
- package/dist/foundation/clipboard/transfer.d.ts +11 -0
- package/dist/foundation/clipboard/transfer.js +108 -0
- package/dist/foundation/clipboard/types.d.ts +65 -0
- package/dist/foundation/clipboard/types.js +1 -0
- package/dist/foundation/collab/index.d.ts +3 -0
- package/dist/foundation/collab/index.js +3 -0
- package/dist/foundation/collab/rebase.d.ts +28 -0
- package/dist/foundation/collab/rebase.js +82 -0
- package/dist/foundation/collab/transform.d.ts +73 -0
- package/dist/foundation/collab/transform.js +251 -0
- package/dist/foundation/collab/types.d.ts +52 -0
- package/dist/foundation/collab/types.js +1 -0
- package/dist/foundation/comments/fromSelection.d.ts +16 -0
- package/dist/foundation/comments/fromSelection.js +24 -0
- package/dist/foundation/comments/index.d.ts +3 -0
- package/dist/foundation/comments/index.js +3 -0
- package/dist/foundation/comments/rebase.d.ts +31 -0
- package/dist/foundation/comments/rebase.js +43 -0
- package/dist/foundation/comments/types.d.ts +37 -0
- package/dist/foundation/comments/types.js +1 -0
- package/dist/foundation/diff/documentDiff.d.ts +12 -0
- package/dist/foundation/diff/documentDiff.js +148 -0
- package/dist/foundation/diff/index.d.ts +3 -0
- package/dist/foundation/diff/index.js +3 -0
- package/dist/foundation/diff/textDiff.d.ts +12 -0
- package/dist/foundation/diff/textDiff.js +114 -0
- package/dist/foundation/diff/types.d.ts +74 -0
- package/dist/foundation/diff/types.js +1 -0
- package/dist/foundation/editor.d.ts +138 -0
- package/dist/foundation/editor.js +398 -0
- package/dist/foundation/formats/codec.d.ts +45 -0
- package/dist/foundation/formats/codec.js +1 -0
- package/dist/foundation/formats/docx/export.d.ts +4 -0
- package/dist/foundation/formats/docx/export.js +285 -0
- package/dist/foundation/formats/docx/import.d.ts +9 -0
- package/dist/foundation/formats/docx/import.js +37 -0
- package/dist/foundation/formats/docx/nestingGuard.d.ts +40 -0
- package/dist/foundation/formats/docx/nestingGuard.js +66 -0
- package/dist/foundation/formats/docx/portableAtoms.d.ts +4 -0
- package/dist/foundation/formats/docx/portableAtoms.js +66 -0
- package/dist/foundation/formats/docx/styledImport.d.ts +10 -0
- package/dist/foundation/formats/docx/styledImport.js +205 -0
- package/dist/foundation/formats/featureCodecs.d.ts +37 -0
- package/dist/foundation/formats/featureCodecs.js +69 -0
- package/dist/foundation/formats/fidelity.d.ts +31 -0
- package/dist/foundation/formats/fidelity.js +123 -0
- package/dist/foundation/formats/index.d.ts +7 -0
- package/dist/foundation/formats/index.js +7 -0
- package/dist/foundation/formats/pdf/format.d.ts +29 -0
- package/dist/foundation/formats/pdf/format.js +190 -0
- package/dist/foundation/history.d.ts +20 -0
- package/dist/foundation/history.js +121 -0
- package/dist/foundation/identity.d.ts +8 -0
- package/dist/foundation/identity.js +30 -0
- package/dist/foundation/index.d.ts +30 -0
- package/dist/foundation/index.js +30 -0
- package/dist/foundation/list/commands.d.ts +28 -0
- package/dist/foundation/list/commands.js +422 -0
- package/dist/foundation/list/formats.d.ts +20 -0
- package/dist/foundation/list/formats.js +795 -0
- package/dist/foundation/list/index.d.ts +8 -0
- package/dist/foundation/list/index.js +8 -0
- package/dist/foundation/list/input.d.ts +35 -0
- package/dist/foundation/list/input.js +320 -0
- package/dist/foundation/list/plugin.d.ts +21 -0
- package/dist/foundation/list/plugin.js +71 -0
- package/dist/foundation/list/presets.d.ts +16 -0
- package/dist/foundation/list/presets.js +21 -0
- package/dist/foundation/list/schema.d.ts +35 -0
- package/dist/foundation/list/schema.js +29 -0
- package/dist/foundation/list/shadow.d.ts +54 -0
- package/dist/foundation/list/shadow.js +75 -0
- package/dist/foundation/list/shadowCorpus.d.ts +10 -0
- package/dist/foundation/list/shadowCorpus.js +41 -0
- package/dist/foundation/list/types.d.ts +50 -0
- package/dist/foundation/list/types.js +1 -0
- package/dist/foundation/mapping.d.ts +11 -0
- package/dist/foundation/mapping.js +40 -0
- package/dist/foundation/marks/canonical.d.ts +9 -0
- package/dist/foundation/marks/canonical.js +72 -0
- package/dist/foundation/marks/commands.d.ts +21 -0
- package/dist/foundation/marks/commands.js +136 -0
- package/dist/foundation/marks/dom.d.ts +2 -0
- package/dist/foundation/marks/dom.js +46 -0
- package/dist/foundation/marks/editor.d.ts +8 -0
- package/dist/foundation/marks/editor.js +50 -0
- package/dist/foundation/marks/formats.d.ts +37 -0
- package/dist/foundation/marks/formats.js +49 -0
- package/dist/foundation/marks/hardBreak.d.ts +8 -0
- package/dist/foundation/marks/hardBreak.js +80 -0
- package/dist/foundation/marks/index.d.ts +11 -0
- package/dist/foundation/marks/index.js +11 -0
- package/dist/foundation/marks/normalization.d.ts +2 -0
- package/dist/foundation/marks/normalization.js +49 -0
- package/dist/foundation/marks/plugin.d.ts +14 -0
- package/dist/foundation/marks/plugin.js +63 -0
- package/dist/foundation/marks/resolveMarkRun.d.ts +8 -0
- package/dist/foundation/marks/resolveMarkRun.js +47 -0
- package/dist/foundation/marks/schema.d.ts +167 -0
- package/dist/foundation/marks/schema.js +50 -0
- package/dist/foundation/marks/stored.d.ts +2 -0
- package/dist/foundation/marks/stored.js +31 -0
- package/dist/foundation/marks/types.d.ts +40 -0
- package/dist/foundation/marks/types.js +1 -0
- package/dist/foundation/modelDom.d.ts +38 -0
- package/dist/foundation/modelDom.js +327 -0
- package/dist/foundation/normalization.d.ts +22 -0
- package/dist/foundation/normalization.js +132 -0
- package/dist/foundation/operations.d.ts +28 -0
- package/dist/foundation/operations.js +568 -0
- package/dist/foundation/plugin/builtins.d.ts +10 -0
- package/dist/foundation/plugin/builtins.js +27 -0
- package/dist/foundation/plugin/dispatch.d.ts +33 -0
- package/dist/foundation/plugin/dispatch.js +34 -0
- package/dist/foundation/plugin/index.d.ts +4 -0
- package/dist/foundation/plugin/index.js +4 -0
- package/dist/foundation/plugin/registry.d.ts +36 -0
- package/dist/foundation/plugin/registry.js +115 -0
- package/dist/foundation/plugin/types.d.ts +141 -0
- package/dist/foundation/plugin/types.js +13 -0
- package/dist/foundation/positions.d.ts +20 -0
- package/dist/foundation/positions.js +121 -0
- package/dist/foundation/schema.d.ts +57 -0
- package/dist/foundation/schema.js +371 -0
- package/dist/foundation/schemaBuilder.d.ts +41 -0
- package/dist/foundation/schemaBuilder.js +96 -0
- package/dist/foundation/scope/index.d.ts +2 -0
- package/dist/foundation/scope/index.js +2 -0
- package/dist/foundation/scope/resolveScope.d.ts +13 -0
- package/dist/foundation/scope/resolveScope.js +860 -0
- package/dist/foundation/scope/types.d.ts +122 -0
- package/dist/foundation/scope/types.js +1 -0
- package/dist/foundation/security/urlPolicy.d.ts +21 -0
- package/dist/foundation/security/urlPolicy.js +75 -0
- package/dist/foundation/structural/contentTarget.d.ts +21 -0
- package/dist/foundation/structural/contentTarget.js +51 -0
- package/dist/foundation/structural/index.d.ts +2 -0
- package/dist/foundation/structural/index.js +2 -0
- package/dist/foundation/structural/move.d.ts +7 -0
- package/dist/foundation/structural/move.js +35 -0
- package/dist/foundation/suggestions/index.d.ts +3 -0
- package/dist/foundation/suggestions/index.js +3 -0
- package/dist/foundation/suggestions/inline.d.ts +64 -0
- package/dist/foundation/suggestions/inline.js +116 -0
- package/dist/foundation/suggestions/structural.d.ts +40 -0
- package/dist/foundation/suggestions/structural.js +47 -0
- package/dist/foundation/suggestions/types.d.ts +19 -0
- package/dist/foundation/suggestions/types.js +1 -0
- package/dist/foundation/surface/index.d.ts +3 -0
- package/dist/foundation/surface/index.js +3 -0
- package/dist/foundation/surface/input.d.ts +127 -0
- package/dist/foundation/surface/input.js +1761 -0
- package/dist/foundation/surface/renderer.d.ts +84 -0
- package/dist/foundation/surface/renderer.js +974 -0
- package/dist/foundation/surface/types.d.ts +48 -0
- package/dist/foundation/surface/types.js +1 -0
- package/dist/foundation/table/commands.d.ts +31 -0
- package/dist/foundation/table/commands.js +470 -0
- package/dist/foundation/table/formats.d.ts +26 -0
- package/dist/foundation/table/formats.js +40 -0
- package/dist/foundation/table/grid.d.ts +8 -0
- package/dist/foundation/table/grid.js +178 -0
- package/dist/foundation/table/index.d.ts +6 -0
- package/dist/foundation/table/index.js +6 -0
- package/dist/foundation/table/plugin.d.ts +23 -0
- package/dist/foundation/table/plugin.js +119 -0
- package/dist/foundation/table/schema.d.ts +2 -0
- package/dist/foundation/table/schema.js +38 -0
- package/dist/foundation/table/selection.d.ts +7 -0
- package/dist/foundation/table/selection.js +35 -0
- package/dist/foundation/table/types.d.ts +109 -0
- package/dist/foundation/table/types.js +1 -0
- package/dist/foundation/transactions.d.ts +41 -0
- package/dist/foundation/transactions.js +90 -0
- package/dist/foundation/types.d.ts +261 -0
- package/dist/foundation/types.js +1 -0
- package/dist/foundation/versioning/diffVersions.d.ts +5 -0
- package/dist/foundation/versioning/diffVersions.js +3 -0
- package/dist/foundation/versioning/index.d.ts +2 -0
- package/dist/foundation/versioning/index.js +2 -0
- package/dist/foundation/versioning/types.d.ts +17 -0
- package/dist/foundation/versioning/types.js +1 -0
- package/dist/history.d.ts +20 -0
- package/dist/history.js +165 -0
- package/dist/html/compatibility.js +7 -1
- package/dist/index.d.ts +1 -14
- package/dist/index.js +9 -14
- package/dist/legacy/index.d.ts +45 -0
- package/dist/legacy/index.js +45 -0
- package/dist/legacyCommands/alignment.d.ts +20 -0
- package/dist/{commands → legacyCommands}/alignment.js +17 -0
- package/dist/legacyCommands/blocks.d.ts +14 -0
- package/dist/legacyCommands/blocks.js +105 -0
- package/dist/legacyCommands/checklist.d.ts +11 -0
- package/dist/legacyCommands/checklist.js +45 -0
- package/dist/legacyCommands/code.d.ts +15 -0
- package/dist/{commands → legacyCommands}/code.js +25 -1
- package/dist/legacyCommands/formula.d.ts +7 -0
- package/dist/legacyCommands/formula.js +67 -0
- package/dist/legacyCommands/inlineAtoms.d.ts +7 -0
- package/dist/legacyCommands/inlineAtoms.js +58 -0
- package/dist/legacyCommands/list.d.ts +38 -0
- package/dist/legacyCommands/list.js +477 -0
- package/dist/{commands → legacyCommands}/marks.d.ts +3 -0
- package/dist/{commands → legacyCommands}/marks.js +28 -11
- package/dist/legacyCommands/media.d.ts +31 -0
- package/dist/legacyCommands/media.js +205 -0
- package/dist/legacyCommands/move.d.ts +14 -0
- package/dist/legacyCommands/move.js +91 -0
- package/dist/legacyCommands/table.d.ts +91 -0
- package/dist/legacyCommands/table.js +547 -0
- package/dist/listPresets.d.ts +12 -0
- package/dist/listPresets.js +6 -0
- package/dist/listScope.d.ts +27 -0
- package/dist/listScope.js +104 -0
- package/dist/markdown/compatibility.d.ts +2 -0
- package/dist/markdown/compatibility.js +94 -2
- package/dist/marks.d.ts +5 -5
- package/dist/model.d.ts +65 -9
- package/dist/plugin.d.ts +15 -0
- package/dist/plugin.js +31 -0
- package/dist/plugins/alignment.d.ts +3 -0
- package/dist/plugins/alignment.js +6 -0
- package/dist/plugins/basicFormatting.d.ts +9 -0
- package/dist/plugins/basicFormatting.js +24 -0
- package/dist/plugins/blockType.d.ts +3 -0
- package/dist/plugins/blockType.js +6 -0
- package/dist/plugins/blockquote.d.ts +3 -0
- package/dist/plugins/blockquote.js +6 -0
- package/dist/plugins/checklist.d.ts +3 -0
- package/dist/plugins/checklist.js +10 -0
- package/dist/plugins/codeBlock.d.ts +3 -0
- package/dist/plugins/codeBlock.js +6 -0
- package/dist/plugins/formula.d.ts +3 -0
- package/dist/plugins/formula.js +9 -0
- package/dist/plugins/list.d.ts +3 -0
- package/dist/plugins/list.js +10 -0
- package/dist/plugins/media.d.ts +3 -0
- package/dist/plugins/media.js +12 -0
- package/dist/plugins/move.d.ts +3 -0
- package/dist/plugins/move.js +9 -0
- package/dist/plugins/table.d.ts +3 -0
- package/dist/plugins/table.js +22 -0
- package/dist/preset.d.ts +12 -0
- package/dist/preset.js +40 -0
- package/dist/schema.d.ts +22 -0
- package/dist/schema.js +333 -0
- package/dist/security/urlPolicy.d.ts +1 -17
- package/dist/security/urlPolicy.js +3 -69
- package/dist/selection.d.ts +1 -1
- package/dist/selectionMapping.d.ts +4 -0
- package/dist/selectionMapping.js +222 -0
- package/dist/table.d.ts +3 -3
- package/dist/transaction.d.ts +35 -12
- package/dist/transaction.js +174 -28
- package/dist/tree.d.ts +8 -2
- package/dist/tree.js +44 -0
- package/package.json +27 -8
- package/dist/commands/alignment.d.ts +0 -18
- package/dist/commands/code.d.ts +0 -13
- package/dist/commands/list.d.ts +0 -20
- package/dist/commands/list.js +0 -52
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getNodeAtPath } from "./model.js";
|
|
2
|
+
const samePath = (left, right) => left.length === right.length && left.every((part, index) => part === right[index]);
|
|
3
|
+
const isBlock = (node) => Boolean(node) && typeof node === "object" &&
|
|
4
|
+
["paragraph", "heading", "list", "blockquote", "codeBlock", "table"].includes(node.type || "");
|
|
5
|
+
const structuralUnit = (document, path) => {
|
|
6
|
+
let firstBlockPath = null;
|
|
7
|
+
let deepestList = null;
|
|
8
|
+
for (let depth = 1; depth <= path.length; depth += 1) {
|
|
9
|
+
const candidatePath = path.slice(0, depth);
|
|
10
|
+
const node = getNodeAtPath(document, candidatePath);
|
|
11
|
+
if (!isBlock(node))
|
|
12
|
+
continue;
|
|
13
|
+
if (!firstBlockPath)
|
|
14
|
+
firstBlockPath = candidatePath;
|
|
15
|
+
if (node.type === "list") {
|
|
16
|
+
const itemIndex = path[depth];
|
|
17
|
+
deepestList = {
|
|
18
|
+
path: candidatePath,
|
|
19
|
+
listItemIndex: Number.isInteger(itemIndex) ? itemIndex : undefined,
|
|
20
|
+
};
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (node.type === "table")
|
|
24
|
+
firstBlockPath = null;
|
|
25
|
+
}
|
|
26
|
+
return deepestList || (firstBlockPath ? { path: firstBlockPath, listItemIndex: undefined } : null);
|
|
27
|
+
};
|
|
28
|
+
/** Resolves the semantic list scope without inspecting DOM details. */
|
|
29
|
+
export const resolveListSelectionScope = (document, selection) => {
|
|
30
|
+
if (selection.type === "all")
|
|
31
|
+
return { kind: "all", containerPath: [] };
|
|
32
|
+
if (selection.type !== "text" && selection.type !== "node")
|
|
33
|
+
return { kind: "none" };
|
|
34
|
+
const paths = selection.type === "text"
|
|
35
|
+
? [selection.anchor.path, selection.focus.path]
|
|
36
|
+
: [selection.path, selection.path];
|
|
37
|
+
const anchor = structuralUnit(document, paths[0]);
|
|
38
|
+
const focus = structuralUnit(document, paths[1]);
|
|
39
|
+
if (!anchor || !focus)
|
|
40
|
+
return { kind: "none" };
|
|
41
|
+
if (samePath(anchor.path, focus.path) && anchor.listItemIndex !== undefined && focus.listItemIndex !== undefined) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "list",
|
|
44
|
+
listPath: anchor.path,
|
|
45
|
+
start: Math.min(anchor.listItemIndex, focus.listItemIndex),
|
|
46
|
+
end: Math.max(anchor.listItemIndex, focus.listItemIndex),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// A range whose endpoints are list content at different depths belongs to
|
|
50
|
+
// the nearest common containing list. For example, selecting a parent item
|
|
51
|
+
// through one of its nested items changes the parent list while preserving
|
|
52
|
+
// the nested descendants. A nested-only range is handled by the same-path
|
|
53
|
+
// branch above and therefore remains scoped to the nested list.
|
|
54
|
+
if (anchor.listItemIndex !== undefined && focus.listItemIndex !== undefined) {
|
|
55
|
+
const listPaths = [anchor.path, focus.path];
|
|
56
|
+
const ancestor = listPaths.find((candidate) => listPaths.every((path) => path.length >= candidate.length && candidate.every((part, index) => path[index] === part)));
|
|
57
|
+
if (ancestor) {
|
|
58
|
+
const indices = [
|
|
59
|
+
samePath(anchor.path, ancestor) ? anchor.listItemIndex : anchor.path[ancestor.length],
|
|
60
|
+
samePath(focus.path, ancestor) ? focus.listItemIndex : focus.path[ancestor.length],
|
|
61
|
+
]
|
|
62
|
+
.filter((index) => Number.isInteger(index));
|
|
63
|
+
if (indices.length === 2) {
|
|
64
|
+
return {
|
|
65
|
+
kind: "list",
|
|
66
|
+
listPath: ancestor,
|
|
67
|
+
start: Math.min(...indices),
|
|
68
|
+
end: Math.max(...indices),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const mixed = [anchor, focus].find((unit) => unit.listItemIndex !== undefined);
|
|
74
|
+
const plain = [anchor, focus].find((unit) => unit.listItemIndex === undefined);
|
|
75
|
+
if (mixed && plain) {
|
|
76
|
+
let outerListPath = null;
|
|
77
|
+
for (let depth = 1; depth <= mixed.path.length; depth += 1) {
|
|
78
|
+
if (getNodeAtPath(document, mixed.path.slice(0, depth))?.type === "list") {
|
|
79
|
+
outerListPath = mixed.path.slice(0, depth);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!outerListPath || !samePath(outerListPath.slice(0, -1), plain.path.slice(0, -1)))
|
|
84
|
+
return { kind: "none" };
|
|
85
|
+
return {
|
|
86
|
+
kind: "mixed",
|
|
87
|
+
containerPath: plain.path.slice(0, -1),
|
|
88
|
+
blockIndex: plain.path[plain.path.length - 1],
|
|
89
|
+
listPath: outerListPath,
|
|
90
|
+
itemStart: mixed.path[outerListPath.length],
|
|
91
|
+
itemEnd: mixed.path[outerListPath.length],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const anchorParent = anchor.path.slice(0, -1);
|
|
95
|
+
const focusParent = focus.path.slice(0, -1);
|
|
96
|
+
if (!samePath(anchorParent, focusParent))
|
|
97
|
+
return { kind: "none" };
|
|
98
|
+
return {
|
|
99
|
+
kind: "blocks",
|
|
100
|
+
containerPath: anchorParent,
|
|
101
|
+
start: Math.min(anchor.path[anchor.path.length - 1], focus.path[focus.path.length - 1]),
|
|
102
|
+
end: Math.max(anchor.path[anchor.path.length - 1], focus.path[focus.path.length - 1]),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -5,3 +5,5 @@
|
|
|
5
5
|
* indentation and table syntax that no HTML repair pass can recover once lost.
|
|
6
6
|
*/
|
|
7
7
|
export declare const markdownToCompatibilityHtml: (markdown: string) => string;
|
|
8
|
+
/** Converts canonical HTML to portable GFM with Smart RTE formula syntax. */
|
|
9
|
+
export declare const compatibilityHtmlToMarkdown: (html: string) => string;
|
|
@@ -4,6 +4,19 @@ import remarkParse from "remark-parse";
|
|
|
4
4
|
import remarkRehype from "remark-rehype";
|
|
5
5
|
import { unified } from "unified";
|
|
6
6
|
import { normalizeCompatibilityHtml } from "../html/compatibility.js";
|
|
7
|
+
import { parseCompatibilityHtml } from "../html/compatibility.js";
|
|
8
|
+
const escapeAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
9
|
+
const extractFormulaPlaceholders = (markdown) => {
|
|
10
|
+
const formulas = [];
|
|
11
|
+
const source = markdown.replace(/\$\$([\s\S]+?)\$\$|\$([^$\n]+?)\$/g, (_match, block, inline) => {
|
|
12
|
+
const value = String(block ?? inline ?? "").trim();
|
|
13
|
+
if (!value)
|
|
14
|
+
return _match;
|
|
15
|
+
const index = formulas.push(value) - 1;
|
|
16
|
+
return `SMART_RTE_FORMULA_${index}_TOKEN`;
|
|
17
|
+
});
|
|
18
|
+
return { source, formulas };
|
|
19
|
+
};
|
|
7
20
|
/**
|
|
8
21
|
* Converts CommonMark/GFM input to canonical Smart RTE HTML.
|
|
9
22
|
*
|
|
@@ -11,11 +24,90 @@ import { normalizeCompatibilityHtml } from "../html/compatibility.js";
|
|
|
11
24
|
* indentation and table syntax that no HTML repair pass can recover once lost.
|
|
12
25
|
*/
|
|
13
26
|
export const markdownToCompatibilityHtml = (markdown) => {
|
|
27
|
+
const { source, formulas } = extractFormulaPlaceholders(markdown);
|
|
14
28
|
const html = String(unified()
|
|
15
29
|
.use(remarkParse)
|
|
16
30
|
.use(remarkGfm)
|
|
17
31
|
.use(remarkRehype)
|
|
18
32
|
.use(rehypeStringify)
|
|
19
|
-
.processSync(
|
|
20
|
-
|
|
33
|
+
.processSync(source));
|
|
34
|
+
const withFormulas = formulas.reduce((current, formula, index) => current.replace(new RegExp(`SMART_RTE_FORMULA_${index}_TOKEN`, "g"), `<span data-formula="${escapeAttribute(formula)}">$${escapeAttribute(formula)}$</span>`), html);
|
|
35
|
+
const withChecklists = withFormulas
|
|
36
|
+
.replace(/<ul class="contains-task-list">/g, '<ul data-srte-checklist="true">')
|
|
37
|
+
.replace(/<li class="task-list-item"><input type="checkbox"([^>]*)>\s*/g, (_match, attributes) => `<li data-srte-checked="${/\bchecked(?:\s|=|$)/.test(attributes) ? "true" : "false"}">`);
|
|
38
|
+
return normalizeCompatibilityHtml(withChecklists);
|
|
39
|
+
};
|
|
40
|
+
const attr = (node, name) => node.attrs?.find((candidate) => candidate.name === name)?.value || "";
|
|
41
|
+
const markdownEscapeText = (value) => value.replace(/\\/g, "\\\\").replace(/([*_`[\]])/g, "\\$1");
|
|
42
|
+
const descendantsByTag = (node, tagName) => (node.childNodes || []).flatMap((child) => [
|
|
43
|
+
...(child.tagName === tagName ? [child] : []),
|
|
44
|
+
...descendantsByTag(child, tagName),
|
|
45
|
+
]);
|
|
46
|
+
/** Converts canonical HTML to portable GFM with Smart RTE formula syntax. */
|
|
47
|
+
export const compatibilityHtmlToMarkdown = (html) => {
|
|
48
|
+
const { fragment } = parseCompatibilityHtml(html);
|
|
49
|
+
const walk = (node, listDepth = 0) => {
|
|
50
|
+
if (node.nodeName === "#text")
|
|
51
|
+
return markdownEscapeText(node.value || "");
|
|
52
|
+
const tag = node.tagName || "";
|
|
53
|
+
if (tag === "span" && attr(node, "data-formula"))
|
|
54
|
+
return `$${attr(node, "data-formula")}$`;
|
|
55
|
+
if (tag === "img")
|
|
56
|
+
return `})`;
|
|
57
|
+
const content = (node.childNodes || []).map((child) => walk(child, listDepth)).join("");
|
|
58
|
+
if (tag === "strong" || tag === "b")
|
|
59
|
+
return `**${content}**`;
|
|
60
|
+
if (tag === "em" || tag === "i")
|
|
61
|
+
return `*${content}*`;
|
|
62
|
+
if (tag === "s" || tag === "del" || tag === "strike")
|
|
63
|
+
return `~~${content}~~`;
|
|
64
|
+
if (tag === "code")
|
|
65
|
+
return `\`${content}\``;
|
|
66
|
+
if (tag === "a")
|
|
67
|
+
return `[${content}](${attr(node, "href")})`;
|
|
68
|
+
if (tag === "br")
|
|
69
|
+
return " \n";
|
|
70
|
+
if (/^h[1-6]$/.test(tag))
|
|
71
|
+
return `${"#".repeat(Number(tag.slice(1)))} ${content.trim()}\n\n`;
|
|
72
|
+
if (tag === "p")
|
|
73
|
+
return `${content.trim()}\n\n`;
|
|
74
|
+
if (tag === "blockquote") {
|
|
75
|
+
return `${content.trim().split("\n").map((line) => `> ${line}`).join("\n")}\n\n`;
|
|
76
|
+
}
|
|
77
|
+
if (tag === "li") {
|
|
78
|
+
return `${" ".repeat(listDepth)}- ${content.trim()}\n`;
|
|
79
|
+
}
|
|
80
|
+
if (tag === "ul" || tag === "ol") {
|
|
81
|
+
const ordered = tag === "ol";
|
|
82
|
+
const checklist = attr(node, "data-srte-checklist") === "true";
|
|
83
|
+
return (node.childNodes || []).map((child, index) => {
|
|
84
|
+
if (child.tagName !== "li")
|
|
85
|
+
return walk(child, listDepth + 1);
|
|
86
|
+
const item = (child.childNodes || []).map((nested) => walk(nested, listDepth + 1)).join("").trim();
|
|
87
|
+
const marker = checklist
|
|
88
|
+
? `- [${attr(child, "data-srte-checked") === "true" ? "x" : " "}]`
|
|
89
|
+
: ordered ? `${index + 1}.` : "-";
|
|
90
|
+
return `${" ".repeat(listDepth)}${marker} ${item}\n`;
|
|
91
|
+
}).join("") + (listDepth === 0 ? "\n" : "");
|
|
92
|
+
}
|
|
93
|
+
if (tag === "table") {
|
|
94
|
+
const rows = descendantsByTag(node, "tr").map((row) => (row.childNodes || [])
|
|
95
|
+
.filter((cell) => cell.tagName === "td" || cell.tagName === "th")
|
|
96
|
+
.map((cell) => (cell.childNodes || []).map((child) => walk(child, listDepth)).join("")
|
|
97
|
+
.replace(/\n+/g, " ").trim().replace(/\|/g, "\\|")));
|
|
98
|
+
if (!rows.length)
|
|
99
|
+
return "";
|
|
100
|
+
const columns = Math.max(...rows.map((row) => row.length));
|
|
101
|
+
const normalized = rows.map((row) => [...row, ...Array(Math.max(0, columns - row.length)).fill("")]);
|
|
102
|
+
return [
|
|
103
|
+
`| ${normalized[0].join(" | ")} |`,
|
|
104
|
+
`| ${Array(columns).fill("---").join(" | ")} |`,
|
|
105
|
+
...normalized.slice(1).map((row) => `| ${row.join(" | ")} |`),
|
|
106
|
+
"",
|
|
107
|
+
"",
|
|
108
|
+
].join("\n");
|
|
109
|
+
}
|
|
110
|
+
return content;
|
|
111
|
+
};
|
|
112
|
+
return walk(fragment).replace(/\n{3,}/g, "\n\n").trim();
|
|
21
113
|
};
|
package/dist/marks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type InlineMarkType = Extract<
|
|
1
|
+
import type { LegacySmartMark } from "./model.js";
|
|
2
|
+
export type InlineMarkType = Extract<LegacySmartMark, {
|
|
3
3
|
type: string;
|
|
4
4
|
}>['type'];
|
|
5
|
-
export declare const hasMark: (marks: readonly
|
|
6
|
-
export declare const addMark: (marks: readonly
|
|
7
|
-
export declare const removeMark: (marks: readonly
|
|
5
|
+
export declare const hasMark: (marks: readonly LegacySmartMark[] | undefined, type: InlineMarkType) => boolean;
|
|
6
|
+
export declare const addMark: (marks: readonly LegacySmartMark[] | undefined, mark: LegacySmartMark) => LegacySmartMark[];
|
|
7
|
+
export declare const removeMark: (marks: readonly LegacySmartMark[] | undefined, type: InlineMarkType) => LegacySmartMark[] | undefined;
|
package/dist/model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type Path = readonly number[];
|
|
2
2
|
export type TextAlignment = "left" | "center" | "right" | "justify";
|
|
3
|
-
export type
|
|
3
|
+
export type LegacySmartMark = {
|
|
4
4
|
type: "bold";
|
|
5
5
|
} | {
|
|
6
6
|
type: "italic";
|
|
@@ -23,45 +23,95 @@ export type SmartMark = {
|
|
|
23
23
|
} | {
|
|
24
24
|
type: "fontSize";
|
|
25
25
|
valuePx: number;
|
|
26
|
+
} | {
|
|
27
|
+
type: "fontFamily";
|
|
28
|
+
value: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "formula";
|
|
31
|
+
value: string;
|
|
26
32
|
} | {
|
|
27
33
|
type: "link";
|
|
28
34
|
href: string;
|
|
29
35
|
target?: string;
|
|
30
36
|
};
|
|
31
|
-
export interface
|
|
37
|
+
export interface LegacySmartTextNode {
|
|
32
38
|
type: "text";
|
|
33
39
|
text: string;
|
|
34
|
-
marks?:
|
|
40
|
+
marks?: LegacySmartMark[];
|
|
35
41
|
}
|
|
42
|
+
/** An indivisible inline node. Text commands must treat these as length-one atoms. */
|
|
43
|
+
export interface SmartFormulaNode {
|
|
44
|
+
type: "formula";
|
|
45
|
+
value: string;
|
|
46
|
+
displayText?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SmartInlineImageNode {
|
|
49
|
+
type: "inlineImage";
|
|
50
|
+
src: string;
|
|
51
|
+
alt?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
}
|
|
56
|
+
export type SmartInlineNode = LegacySmartTextNode | SmartFormulaNode | SmartInlineImageNode;
|
|
36
57
|
export interface SmartParagraphNode {
|
|
37
58
|
type: "paragraph";
|
|
38
59
|
alignment?: TextAlignment;
|
|
39
|
-
|
|
60
|
+
indent?: number;
|
|
61
|
+
children: SmartInlineNode[];
|
|
40
62
|
}
|
|
41
63
|
export interface SmartHeadingNode {
|
|
42
64
|
type: "heading";
|
|
43
65
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
44
66
|
alignment?: TextAlignment;
|
|
45
|
-
|
|
67
|
+
indent?: number;
|
|
68
|
+
children: SmartInlineNode[];
|
|
46
69
|
}
|
|
47
70
|
export interface SmartListItemNode {
|
|
48
71
|
type: "listItem";
|
|
49
72
|
alignment?: TextAlignment;
|
|
73
|
+
checked?: boolean;
|
|
50
74
|
children: SmartBlockNode[];
|
|
51
75
|
}
|
|
76
|
+
export type SmartListStyle = "disc" | "circle" | "square" | "decimal" | "decimal-leading-zero" | "lower-alpha" | "upper-alpha" | "lower-roman" | "upper-roman";
|
|
77
|
+
export type SmartListPreset = "bullet-disc" | "bullet-diamond" | "bullet-square" | "bullet-arrow" | "bullet-star" | "bullet-arrow-circle" | "ordered-decimal" | "ordered-decimal-paren" | "ordered-outline" | "ordered-upper-alpha" | "ordered-upper-roman" | "ordered-leading-zero";
|
|
52
78
|
export interface SmartListNode {
|
|
53
79
|
type: "list";
|
|
54
|
-
|
|
80
|
+
indent?: number;
|
|
81
|
+
style: SmartListStyle;
|
|
82
|
+
/** Marker family applied to this list hierarchy. `style` remains the portable fallback. */
|
|
83
|
+
preset?: SmartListPreset;
|
|
84
|
+
checklist?: boolean;
|
|
85
|
+
strikeCompleted?: boolean;
|
|
55
86
|
children: SmartListItemNode[];
|
|
56
87
|
}
|
|
88
|
+
export interface SmartImageNode {
|
|
89
|
+
type: "image";
|
|
90
|
+
indent?: number;
|
|
91
|
+
src: string;
|
|
92
|
+
alt?: string;
|
|
93
|
+
title?: string;
|
|
94
|
+
width?: number;
|
|
95
|
+
height?: number;
|
|
96
|
+
}
|
|
97
|
+
export interface SmartMediaNode {
|
|
98
|
+
type: "media";
|
|
99
|
+
indent?: number;
|
|
100
|
+
src: string;
|
|
101
|
+
mediaType: "audio" | "video" | "file";
|
|
102
|
+
title?: string;
|
|
103
|
+
mimeType?: string;
|
|
104
|
+
}
|
|
57
105
|
export interface SmartBlockquoteNode {
|
|
58
106
|
type: "blockquote";
|
|
59
107
|
alignment?: TextAlignment;
|
|
108
|
+
indent?: number;
|
|
60
109
|
children: SmartBlockNode[];
|
|
61
110
|
}
|
|
62
111
|
export interface SmartCodeBlockNode {
|
|
63
112
|
type: "codeBlock";
|
|
64
113
|
alignment?: TextAlignment;
|
|
114
|
+
indent?: number;
|
|
65
115
|
text: string;
|
|
66
116
|
language?: string;
|
|
67
117
|
}
|
|
@@ -69,20 +119,26 @@ export interface SmartTableCellNode {
|
|
|
69
119
|
type: "tableCell" | "tableHeaderCell";
|
|
70
120
|
colspan?: number;
|
|
71
121
|
rowspan?: number;
|
|
122
|
+
backgroundColor?: string;
|
|
123
|
+
textColor?: string;
|
|
124
|
+
border?: string;
|
|
72
125
|
children: SmartBlockNode[];
|
|
73
126
|
}
|
|
74
127
|
export interface SmartTableRowNode {
|
|
75
128
|
type: "tableRow";
|
|
129
|
+
heightPx?: number;
|
|
76
130
|
children: SmartTableCellNode[];
|
|
77
131
|
}
|
|
78
132
|
export interface SmartTableNode {
|
|
79
133
|
type: "table";
|
|
134
|
+
indent?: number;
|
|
135
|
+
columnWidths?: number[];
|
|
80
136
|
children: SmartTableRowNode[];
|
|
81
137
|
}
|
|
82
|
-
export type SmartBlockNode = SmartParagraphNode | SmartHeadingNode | SmartListNode | SmartBlockquoteNode | SmartCodeBlockNode | SmartTableNode;
|
|
83
|
-
export interface
|
|
138
|
+
export type SmartBlockNode = SmartParagraphNode | SmartHeadingNode | SmartListNode | SmartBlockquoteNode | SmartCodeBlockNode | SmartImageNode | SmartMediaNode | SmartTableNode;
|
|
139
|
+
export interface LegacySmartDocument {
|
|
84
140
|
type: "doc";
|
|
85
141
|
children: SmartBlockNode[];
|
|
86
142
|
}
|
|
87
143
|
export declare const paragraph: (text?: string) => SmartParagraphNode;
|
|
88
|
-
export declare const getNodeAtPath: (document:
|
|
144
|
+
export declare const getNodeAtPath: (document: LegacySmartDocument, path: Path) => unknown;
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SmartCommand } from "./command.js";
|
|
2
|
+
import type { LegacySmartDocument } from "./model.js";
|
|
3
|
+
import type { SmartSchemaExtension } from "./schema.js";
|
|
4
|
+
import type { LegacySmartTransaction } from "./transaction.js";
|
|
5
|
+
export type SmartPluginCommand = SmartCommand<any>;
|
|
6
|
+
export type SmartNormalizer = (document: LegacySmartDocument) => LegacySmartDocument;
|
|
7
|
+
export interface SmartRtePlugin {
|
|
8
|
+
id: string;
|
|
9
|
+
dependencies?: string[];
|
|
10
|
+
commands?: Record<string, SmartPluginCommand>;
|
|
11
|
+
schema?: Omit<SmartSchemaExtension, "id">;
|
|
12
|
+
normalizers?: SmartNormalizer[];
|
|
13
|
+
onTransaction?: (transaction: LegacySmartTransaction) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const orderPlugins: (plugins: readonly SmartRtePlugin[]) => SmartRtePlugin[];
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const orderPlugins = (plugins) => {
|
|
2
|
+
const byId = new Map();
|
|
3
|
+
plugins.forEach((plugin) => {
|
|
4
|
+
if (!plugin.id.trim())
|
|
5
|
+
throw new Error("Plugin id cannot be empty.");
|
|
6
|
+
if (byId.has(plugin.id))
|
|
7
|
+
throw new Error(`Duplicate plugin id "${plugin.id}".`);
|
|
8
|
+
byId.set(plugin.id, plugin);
|
|
9
|
+
});
|
|
10
|
+
const ordered = [];
|
|
11
|
+
const visiting = new Set();
|
|
12
|
+
const visited = new Set();
|
|
13
|
+
const visit = (plugin) => {
|
|
14
|
+
if (visited.has(plugin.id))
|
|
15
|
+
return;
|
|
16
|
+
if (visiting.has(plugin.id))
|
|
17
|
+
throw new Error(`Circular plugin dependency involving "${plugin.id}".`);
|
|
18
|
+
visiting.add(plugin.id);
|
|
19
|
+
(plugin.dependencies || []).forEach((dependency) => {
|
|
20
|
+
const required = byId.get(dependency);
|
|
21
|
+
if (!required)
|
|
22
|
+
throw new Error(`Plugin "${plugin.id}" requires missing plugin "${dependency}".`);
|
|
23
|
+
visit(required);
|
|
24
|
+
});
|
|
25
|
+
visiting.delete(plugin.id);
|
|
26
|
+
visited.add(plugin.id);
|
|
27
|
+
ordered.push(plugin);
|
|
28
|
+
};
|
|
29
|
+
plugins.forEach(visit);
|
|
30
|
+
return ordered;
|
|
31
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SmartRtePlugin } from "../plugin.js";
|
|
2
|
+
/**
|
|
3
|
+
* Inline formatting as an independently selectable feature bundle.
|
|
4
|
+
*
|
|
5
|
+
* Applications may use the singleton or create a fresh plugin descriptor when
|
|
6
|
+
* composing an editor preset. Commands remain model-only and UI-framework-free.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createBasicFormattingPlugin: () => SmartRtePlugin;
|
|
9
|
+
export declare const basicFormattingPlugin: SmartRtePlugin;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { applyBackgroundColor, applyFontSize, applyFontFamily, applyTextColor, toggleBold, toggleInlineCode, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, } from "../legacyCommands/marks.js";
|
|
2
|
+
/**
|
|
3
|
+
* Inline formatting as an independently selectable feature bundle.
|
|
4
|
+
*
|
|
5
|
+
* Applications may use the singleton or create a fresh plugin descriptor when
|
|
6
|
+
* composing an editor preset. Commands remain model-only and UI-framework-free.
|
|
7
|
+
*/
|
|
8
|
+
export const createBasicFormattingPlugin = () => ({
|
|
9
|
+
id: "basic-formatting",
|
|
10
|
+
commands: {
|
|
11
|
+
[toggleBold.id]: toggleBold,
|
|
12
|
+
[toggleItalic.id]: toggleItalic,
|
|
13
|
+
[toggleUnderline.id]: toggleUnderline,
|
|
14
|
+
[toggleStrike.id]: toggleStrike,
|
|
15
|
+
[toggleInlineCode.id]: toggleInlineCode,
|
|
16
|
+
[toggleSuperscript.id]: toggleSuperscript,
|
|
17
|
+
[toggleSubscript.id]: toggleSubscript,
|
|
18
|
+
[applyTextColor.id]: applyTextColor,
|
|
19
|
+
[applyBackgroundColor.id]: applyBackgroundColor,
|
|
20
|
+
[applyFontSize.id]: applyFontSize,
|
|
21
|
+
[applyFontFamily.id]: applyFontFamily,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
export const basicFormattingPlugin = createBasicFormattingPlugin();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { setChecklistItemChecked, toggleChecklist } from "../legacyCommands/checklist.js";
|
|
2
|
+
export const createChecklistPlugin = () => ({
|
|
3
|
+
id: "checklist",
|
|
4
|
+
dependencies: ["list"],
|
|
5
|
+
commands: {
|
|
6
|
+
[toggleChecklist.id]: toggleChecklist,
|
|
7
|
+
[setChecklistItemChecked.id]: setChecklistItemChecked,
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const checklistPlugin = createChecklistPlugin();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { deleteFormula, insertFormula } from "../legacyCommands/formula.js";
|
|
2
|
+
export const createFormulaPlugin = () => ({
|
|
3
|
+
id: "formula",
|
|
4
|
+
commands: {
|
|
5
|
+
[insertFormula.id]: insertFormula,
|
|
6
|
+
[deleteFormula.id]: deleteFormula,
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
export const formulaPlugin = createFormulaPlugin();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { indentListItems, outdentListItems, toggleList } from "../legacyCommands/list.js";
|
|
2
|
+
export const createListPlugin = () => ({
|
|
3
|
+
id: "list",
|
|
4
|
+
commands: {
|
|
5
|
+
[toggleList.id]: toggleList,
|
|
6
|
+
[indentListItems.id]: indentListItems,
|
|
7
|
+
[outdentListItems.id]: outdentListItems,
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const listPlugin = createListPlugin();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { deleteInlineImage, insertImage, insertInlineImage, insertMedia, updateInlineImage, } from "../legacyCommands/media.js";
|
|
2
|
+
export const createMediaPlugin = () => ({
|
|
3
|
+
id: "media",
|
|
4
|
+
commands: {
|
|
5
|
+
[insertImage.id]: insertImage,
|
|
6
|
+
[insertInlineImage.id]: insertInlineImage,
|
|
7
|
+
[deleteInlineImage.id]: deleteInlineImage,
|
|
8
|
+
[updateInlineImage.id]: updateInlineImage,
|
|
9
|
+
[insertMedia.id]: insertMedia,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
export const mediaPlugin = createMediaPlugin();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { indentBlocks, moveBlocks } from "../legacyCommands/move.js";
|
|
2
|
+
export const createMovePlugin = () => ({
|
|
3
|
+
id: "move",
|
|
4
|
+
commands: {
|
|
5
|
+
[moveBlocks.id]: moveBlocks,
|
|
6
|
+
[indentBlocks.id]: indentBlocks,
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
export const movePlugin = createMovePlugin();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { addTableColumn, addTableRow, insertTable, mergeTableCells, removeTable, removeTableColumn, removeTableRow, setTableCellStyle, setTableColumnWidth, setTableRowHeight, splitTableCell, toggleTableHeaderCell, toggleTableHeaderColumn, toggleTableHeaderRow, toggleTableCellBorder, } from "../legacyCommands/table.js";
|
|
2
|
+
export const createTablePlugin = () => ({
|
|
3
|
+
id: "table",
|
|
4
|
+
commands: {
|
|
5
|
+
[insertTable.id]: insertTable,
|
|
6
|
+
[removeTable.id]: removeTable,
|
|
7
|
+
[addTableRow.id]: addTableRow,
|
|
8
|
+
[removeTableRow.id]: removeTableRow,
|
|
9
|
+
[addTableColumn.id]: addTableColumn,
|
|
10
|
+
[removeTableColumn.id]: removeTableColumn,
|
|
11
|
+
[setTableCellStyle.id]: setTableCellStyle,
|
|
12
|
+
[setTableColumnWidth.id]: setTableColumnWidth,
|
|
13
|
+
[setTableRowHeight.id]: setTableRowHeight,
|
|
14
|
+
[mergeTableCells.id]: mergeTableCells,
|
|
15
|
+
[splitTableCell.id]: splitTableCell,
|
|
16
|
+
[toggleTableHeaderCell.id]: toggleTableHeaderCell,
|
|
17
|
+
[toggleTableHeaderRow.id]: toggleTableHeaderRow,
|
|
18
|
+
[toggleTableHeaderColumn.id]: toggleTableHeaderColumn,
|
|
19
|
+
[toggleTableCellBorder.id]: toggleTableCellBorder,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const tablePlugin = createTablePlugin();
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SmartRtePlugin } from "./plugin.js";
|
|
2
|
+
export type CoreFeatureId = "basicFormatting" | "blockType" | "alignment" | "list" | "checklist" | "blockquote" | "codeBlock" | "table" | "media" | "formula" | "move";
|
|
3
|
+
export type CoreFeatureConfig = Partial<Record<CoreFeatureId, boolean>>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates the standard model plugin set.
|
|
6
|
+
*
|
|
7
|
+
* Features default to enabled. Disabling `list` also disables `checklist`,
|
|
8
|
+
* because checklist commands depend on list structure. Applications can append
|
|
9
|
+
* custom plugins to the returned array before constructing an editor.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createCorePlugins: (config?: CoreFeatureConfig) => SmartRtePlugin[];
|
|
12
|
+
export declare const corePlugins: SmartRtePlugin[];
|