@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.29 → 0.4.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.
Files changed (88) hide show
  1. package/dist/__tests__/playwrightHelpers.d.ts +2 -2
  2. package/dist/__tests__/playwrightPage.d.ts +2 -50
  3. package/dist/commands.js +43 -178
  4. package/dist/ensureSelectionPlugin.js +3 -3
  5. package/dist/features/joinOnDelete/index.d.ts +19 -4
  6. package/dist/features/joinOnDelete/index.js +53 -166
  7. package/dist/generateId.js +4 -31
  8. package/dist/index.d.ts +2 -5
  9. package/dist/index.js +2 -4
  10. package/dist/replaceStep.d.ts +1 -1
  11. package/dist/schema.d.ts +1 -2
  12. package/dist/schema.js +1 -37
  13. package/dist/testing/testBuilders.d.ts +2 -1
  14. package/dist/utils.d.ts +0 -1
  15. package/dist/utils.js +2 -6
  16. package/dist/withSuggestChanges.d.ts +14 -11
  17. package/dist/withSuggestChanges.js +94 -64
  18. package/package.json +1 -1
  19. package/src/features/joinOnDelete/README.md +8 -0
  20. package/dist/features/joinOnDelete/__tests__/joinOnDeleteInLists.playwright.test.d.ts +0 -1
  21. package/dist/features/joinOnDelete/__tests__/joinOnDeleteInListsTipTapStyle.playwright.test.d.ts +0 -1
  22. package/dist/features/joinOnDelete/__tests__/listWithJoinsAndStructureMarks.playwright.test.d.ts +0 -1
  23. package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.d.ts +0 -6
  24. package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.js +0 -24
  25. package/dist/features/joinOnDelete/types.d.ts +0 -34
  26. package/dist/features/joinOnDelete/types.js +0 -20
  27. package/dist/features/transactionShaping/detectSpecialTransactionShape.d.ts +0 -3
  28. package/dist/features/transactionShaping/detectSpecialTransactionShape.js +0 -4
  29. package/dist/features/transactionShaping/index.d.ts +0 -3
  30. package/dist/features/transactionShaping/index.js +0 -11
  31. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.d.ts +0 -3
  32. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.js +0 -48
  33. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.d.ts +0 -1
  34. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.js +0 -188
  35. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.d.ts +0 -3
  36. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.js +0 -64
  37. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.d.ts +0 -2
  38. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.js +0 -2
  39. package/dist/features/transactionShaping/types.d.ts +0 -20
  40. package/dist/features/transactionShaping/types.js +0 -1
  41. package/dist/features/wrapUnwrap/__tests__/blockquoteStructure.playwright.test.d.ts +0 -1
  42. package/dist/features/wrapUnwrap/__tests__/buildMaterializedPaths.test.d.ts +0 -1
  43. package/dist/features/wrapUnwrap/__tests__/listStructure.playwright.test.d.ts +0 -1
  44. package/dist/features/wrapUnwrap/__tests__/listStructureTextEdits.playwright.test.d.ts +0 -1
  45. package/dist/features/wrapUnwrap/__tests__/splitDetection.test.d.ts +0 -1
  46. package/dist/features/wrapUnwrap/addIdAttr.d.ts +0 -2
  47. package/dist/features/wrapUnwrap/addIdAttr.js +0 -60
  48. package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.d.ts +0 -10
  49. package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.js +0 -41
  50. package/dist/features/wrapUnwrap/apply/index.d.ts +0 -5
  51. package/dist/features/wrapUnwrap/apply/index.js +0 -21
  52. package/dist/features/wrapUnwrap/areEquivalentStructureMarks.d.ts +0 -2
  53. package/dist/features/wrapUnwrap/areEquivalentStructureMarks.js +0 -17
  54. package/dist/features/wrapUnwrap/buildMaterializedPaths.d.ts +0 -3
  55. package/dist/features/wrapUnwrap/buildMaterializedPaths.js +0 -82
  56. package/dist/features/wrapUnwrap/constants.d.ts +0 -3
  57. package/dist/features/wrapUnwrap/constants.js +0 -3
  58. package/dist/features/wrapUnwrap/generateUniqueNodeId.d.ts +0 -1
  59. package/dist/features/wrapUnwrap/generateUniqueNodeId.js +0 -6
  60. package/dist/features/wrapUnwrap/getNodeId.d.ts +0 -2
  61. package/dist/features/wrapUnwrap/getNodeId.js +0 -5
  62. package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.d.ts +0 -3
  63. package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.js +0 -37
  64. package/dist/features/wrapUnwrap/revert/index.d.ts +0 -5
  65. package/dist/features/wrapUnwrap/revert/index.js +0 -19
  66. package/dist/features/wrapUnwrap/revert/revertAddOp.d.ts +0 -4
  67. package/dist/features/wrapUnwrap/revert/revertAddOp.js +0 -4
  68. package/dist/features/wrapUnwrap/revert/revertMoveOp.d.ts +0 -16
  69. package/dist/features/wrapUnwrap/revert/revertMoveOp.js +0 -122
  70. package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.d.ts +0 -10
  71. package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.js +0 -236
  72. package/dist/features/wrapUnwrap/sameParentChain.d.ts +0 -2
  73. package/dist/features/wrapUnwrap/sameParentChain.js +0 -4
  74. package/dist/features/wrapUnwrap/structureChangesPlugin.d.ts +0 -17
  75. package/dist/features/wrapUnwrap/structureChangesPlugin.js +0 -299
  76. package/dist/features/wrapUnwrap/types.d.ts +0 -54
  77. package/dist/features/wrapUnwrap/types.js +0 -23
  78. package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.d.ts +0 -17
  79. package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.js +0 -106
  80. package/dist/listInputRules.d.ts +0 -2
  81. package/dist/listInputRules.js +0 -14
  82. package/dist/rebaseStep.d.ts +0 -9
  83. package/dist/rebaseStep.js +0 -11
  84. package/dist/testing/e2eTestSchema.d.ts +0 -2
  85. package/dist/transformToSuggestionTransaction.d.ts +0 -22
  86. package/dist/transformToSuggestionTransaction.js +0 -101
  87. package/dist/wrappingInputRule.d.ts +0 -4
  88. package/dist/wrappingInputRule.js +0 -28
@@ -1,20 +0,0 @@
1
- import { type Node, type Schema } from "prosemirror-model";
2
- import { type EditorState, type Transaction } from "prosemirror-state";
3
- import { type ReplaceStep, type Transform } from "prosemirror-transform";
4
- import { type SuggestionId } from "../../generateId.js";
5
- import { type StructuralContextPath } from "../wrapUnwrap/types.js";
6
- export interface TipTapParagraphIntoListJoinShape {
7
- type: "tipTapParagraphIntoListJoin";
8
- deleteStep: ReplaceStep;
9
- insertStep: ReplaceStep;
10
- joinStep: ReplaceStep;
11
- movedNode: Node;
12
- }
13
- export type SpecialTransactionShape = TipTapParagraphIntoListJoinShape;
14
- export interface HandleSpecialTransactionShapeArgs {
15
- transaction: Transaction;
16
- state: EditorState;
17
- generateId: ((schema: Schema, doc?: Node) => SuggestionId) | undefined;
18
- structuralContextPaths: StructuralContextPath[] | null;
19
- ensureUniqueNodeIds: ((transactions: Transaction[], oldDoc: Node, newDoc: Node) => Transform) | undefined;
20
- }
@@ -1 +0,0 @@
1
- export { };
@@ -1,2 +0,0 @@
1
- import { type NodeSpec } from "prosemirror-model";
2
- export declare const addIdAttr: (nodeSpec: NodeSpec) => NodeSpec;
@@ -1,60 +0,0 @@
1
- export const addIdAttr = (nodeSpec)=>{
2
- const { toDOM, parseDOM } = nodeSpec;
3
- if (!toDOM || !parseDOM) {
4
- return nodeSpec;
5
- }
6
- const newNodeSpec = {
7
- ...nodeSpec,
8
- attrs: {
9
- ...nodeSpec.attrs ?? {},
10
- id: {
11
- default: null
12
- }
13
- },
14
- toDOM (node) {
15
- const domOutputSpec = toDOM(node);
16
- if (!Array.isArray(domOutputSpec)) {
17
- console.warn("addIdAttr", "domOutputSpec is not an array, id is not added", domOutputSpec);
18
- return domOutputSpec;
19
- }
20
- const id = typeof node.attrs["id"] === "string" ? node.attrs["id"] : null;
21
- const attrs = domOutputSpec[1];
22
- if (!Array.isArray(attrs) && typeof attrs === "object" && attrs !== null) {
23
- const theRest = domOutputSpec.slice(2);
24
- const result = [
25
- domOutputSpec[0],
26
- id ? {
27
- ...attrs,
28
- "data-id": id
29
- } : attrs,
30
- ...theRest
31
- ];
32
- return result;
33
- }
34
- const theRest = domOutputSpec.slice(1);
35
- const result = [
36
- domOutputSpec[0],
37
- id ? {
38
- "data-id": id
39
- } : {},
40
- ...theRest
41
- ];
42
- return result;
43
- },
44
- parseDOM: [
45
- ...parseDOM.map((tagParseRule)=>({
46
- ...tagParseRule,
47
- getAttrs (dom) {
48
- const id = dom.getAttribute("data-id");
49
- return tagParseRule.getAttrs ? {
50
- ...tagParseRule.getAttrs(dom),
51
- id
52
- } : {
53
- id
54
- };
55
- }
56
- }))
57
- ]
58
- };
59
- return newNodeSpec;
60
- };
@@ -1,10 +0,0 @@
1
- import { type Node } from "prosemirror-model";
2
- import { type Transform } from "prosemirror-transform";
3
- import { type SuggestionId } from "../../../generateId.js";
4
- export declare function applyStructureSuggestionsInNode({ tr, node, suggestionId, from, to, }: {
5
- tr: Transform;
6
- node: Node;
7
- suggestionId?: SuggestionId;
8
- from?: number | undefined;
9
- to?: number | undefined;
10
- }): void;
@@ -1,41 +0,0 @@
1
- import { getSuggestionMarks } from "../../../utils.js";
2
- export function applyStructureSuggestionsInNode({ tr, node, suggestionId, from, to }) {
3
- const { structure } = getSuggestionMarks(node.type.schema);
4
- const suggestionIds = new Set();
5
- node.descendants((node, pos)=>{
6
- if (from !== undefined && pos < from) {
7
- return true;
8
- }
9
- if (to !== undefined && pos > to) {
10
- return false;
11
- }
12
- if (node.isText) return true;
13
- if (!structure.isInSet(node.marks)) return true;
14
- node.marks.forEach((mark)=>{
15
- if (mark.type !== structure) return;
16
- const markSuggestionId = mark.attrs["id"];
17
- if (suggestionId != null && markSuggestionId !== suggestionId) return;
18
- suggestionIds.add(markSuggestionId);
19
- });
20
- return true;
21
- });
22
- for (const suggestionId of suggestionIds){
23
- applyOneStructureSuggestion(tr, suggestionId);
24
- }
25
- }
26
- function applyOneStructureSuggestion(tr, suggestionId) {
27
- const { structure } = getSuggestionMarks(tr.doc.type.schema);
28
- tr.doc.descendants((node, pos)=>{
29
- if (node.isText) return true;
30
- if (!structure.isInSet(node.marks)) return true;
31
- node.marks.forEach((mark)=>{
32
- if (mark.type !== structure) return;
33
- if (mark.attrs["id"] !== suggestionId) return;
34
- applyStructureMark(tr, mark, pos);
35
- });
36
- return true;
37
- });
38
- }
39
- function applyStructureMark(tr, mark, pos) {
40
- tr.removeNodeMark(pos, mark);
41
- }
@@ -1,5 +0,0 @@
1
- import { Transform } from "prosemirror-transform";
2
- import { type Node } from "prosemirror-model";
3
- import { type SuggestionId } from "../../../generateId.js";
4
- export declare function applyAllStructureSuggestions(node: Node, from?: number, to?: number): Transform;
5
- export declare function applyStructureSuggestion(node: Node, suggestionId: SuggestionId): Transform;
@@ -1,21 +0,0 @@
1
- import { Transform } from "prosemirror-transform";
2
- import { applyStructureSuggestionsInNode } from "./applyStructureSuggestions.js";
3
- export function applyAllStructureSuggestions(node, from, to) {
4
- const tr = new Transform(node);
5
- applyStructureSuggestionsInNode({
6
- tr,
7
- node: tr.doc,
8
- from,
9
- to
10
- });
11
- return tr;
12
- }
13
- export function applyStructureSuggestion(node, suggestionId) {
14
- const tr = new Transform(node);
15
- applyStructureSuggestionsInNode({
16
- tr,
17
- node: tr.doc,
18
- suggestionId
19
- });
20
- return tr;
21
- }
@@ -1,2 +0,0 @@
1
- import { type Mark } from "prosemirror-model";
2
- export declare function areEquivalentStructureMarks(a: Mark, b: Mark): boolean;
@@ -1,17 +0,0 @@
1
- import { sameParentChain } from "./sameParentChain.js";
2
- import { guardStructureMarkAttrs } from "./types.js";
3
- export function areEquivalentStructureMarks(a, b) {
4
- if (a.type !== b.type) return false;
5
- if (!guardStructureMarkAttrs(a.attrs)) return false;
6
- if (!guardStructureMarkAttrs(b.attrs)) return false;
7
- const aOp = a.attrs.data.op;
8
- const bOp = b.attrs.data.op;
9
- if (aOp.op !== bOp.op) return false;
10
- if (aOp.op === "add" && bOp.op === "add") {
11
- return a.attrs.id === b.attrs.id;
12
- }
13
- if (aOp.op === "move" && bOp.op === "move") {
14
- return sameParentChain(aOp.from, bOp.from) && sameParentChain(aOp.to, bOp.to);
15
- }
16
- return false;
17
- }
@@ -1,3 +0,0 @@
1
- import { type MaterializedPaths } from "./types.js";
2
- import { type Node } from "prosemirror-model";
3
- export declare function buildMaterializedPaths(doc: Node): MaterializedPaths;
@@ -1,82 +0,0 @@
1
- import { getNodeId } from "./getNodeId.js";
2
- import { DOC_NODE_ID } from "./constants.js";
3
- const TRACE_ENABLED = false;
4
- function trace(...args) {
5
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
6
- if (!TRACE_ENABLED) return;
7
- console.log("[structureChanges]", ...args);
8
- }
9
- export function buildMaterializedPaths(doc) {
10
- const perfPaths = performance.now();
11
- const paths = new Map();
12
- // add direct doc children first since they have a specific parent signature due to doc not having an ID
13
- doc.children.forEach((node, index, children)=>{
14
- const nodeId = getNodeId(node);
15
- if (nodeId == null) return;
16
- const leftSibling = children[index - 1];
17
- const leftSiblingId = leftSibling ? getNodeId(leftSibling) : null;
18
- const rightSibling = children[index + 1];
19
- const rightSiblingId = rightSibling ? getNodeId(rightSibling) : null;
20
- const parent = {
21
- nodeId: DOC_NODE_ID,
22
- nodeType: DOC_NODE_ID,
23
- nodeAttrs: {},
24
- nodeMarks: [],
25
- childSiblingIds: [
26
- leftSiblingId,
27
- rightSiblingId
28
- ],
29
- childIndex: index
30
- };
31
- paths.set(nodeId, {
32
- nodeType: node.type.name,
33
- node,
34
- chain: [
35
- parent
36
- ]
37
- });
38
- });
39
- // now add the rest of the nodes
40
- doc.descendants((node, _pos, parent, childIndex)=>{
41
- if (node.isInline) return false;
42
- const nodeId = getNodeId(node);
43
- if (nodeId == null) return true;
44
- // this is to avoid processing direct doc children twice
45
- if (paths.has(nodeId)) return true;
46
- if (parent == null) return true;
47
- const parentId = getNodeId(parent);
48
- if (parentId == null) return true;
49
- // by definition, for any node it's parent chain should already exist
50
- // because we go downwards
51
- const parentChain = paths.get(parentId);
52
- if (parentChain == null) return true;
53
- const leftSibling = parent.children[childIndex - 1];
54
- const leftSiblingId = leftSibling ? getNodeId(leftSibling) : null;
55
- const rightSibling = parent.children[childIndex + 1];
56
- const rightSiblingId = rightSibling ? getNodeId(rightSibling) : null;
57
- // (this node parent chain) is (parent chain of the parent node) + (the parent node itself)
58
- const parentDesc = {
59
- nodeId: parentId,
60
- nodeType: parent.type.name,
61
- nodeAttrs: parent.attrs,
62
- nodeMarks: parent.marks.map((mark)=>mark.toJSON()),
63
- childSiblingIds: [
64
- leftSiblingId,
65
- rightSiblingId
66
- ],
67
- childIndex: childIndex
68
- };
69
- const chain = [
70
- parentDesc,
71
- ...parentChain.chain
72
- ];
73
- paths.set(nodeId, {
74
- nodeType: node.type.name,
75
- node,
76
- chain
77
- });
78
- return true;
79
- });
80
- trace("perf", "buildMaterializedPaths", "took", Number((performance.now() - perfPaths).toFixed(2)), "ms");
81
- return paths;
82
- }
@@ -1,3 +0,0 @@
1
- export declare const DOC_NODE_ID = "__doc__";
2
- export declare const STRUCTURE_CHANGES_ADD_MARKS = "structure-changes-add-mark-type";
3
- export declare const STRUCTURE_CHANGES_REVERT_MARKS = "structure-changes-revert-mark-type";
@@ -1,3 +0,0 @@
1
- export const DOC_NODE_ID = "__doc__";
2
- export const STRUCTURE_CHANGES_ADD_MARKS = "structure-changes-add-mark-type";
3
- export const STRUCTURE_CHANGES_REVERT_MARKS = "structure-changes-revert-mark-type";
@@ -1 +0,0 @@
1
- export declare function generateUniqueNodeId(): string;
@@ -1,6 +0,0 @@
1
- export function generateUniqueNodeId() {
2
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
3
- return crypto.randomUUID();
4
- }
5
- return `node-${Math.random().toString(36).slice(2)}`;
6
- }
@@ -1,2 +0,0 @@
1
- import { type Node } from "prosemirror-model";
2
- export declare function getNodeId(node: Node): string | null;
@@ -1,5 +0,0 @@
1
- export function getNodeId(node) {
2
- const nodeId = node.attrs["id"];
3
- if (typeof nodeId !== "string") return null;
4
- return nodeId;
5
- }
@@ -1,3 +0,0 @@
1
- import { type Transform } from "prosemirror-transform";
2
- import { type Node } from "prosemirror-model";
3
- export declare function deleteNodeUpwards(transform: Transform, node: Node, pos: number): void;
@@ -1,37 +0,0 @@
1
- import { getNodeId } from "../getNodeId.js";
2
- const TRACE_ENABLED = false;
3
- function trace(...args) {
4
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
5
- if (!TRACE_ENABLED) return;
6
- console.log("[deleteNodeUpwards]", "\n", ...args);
7
- }
8
- // delete a given node, and traverse upwards deleting parent nodes if they are now empty
9
- export function deleteNodeUpwards(transform, node, pos) {
10
- let $mappedPos = transform.doc.resolve(pos);
11
- trace("attempting to delete node", node.type.name, getNodeId(node), "\n", "node subtree:\n", node.toString(), "\n", "node parent:", $mappedPos.parent.type.name, getNodeId($mappedPos.parent), "\n", {
12
- node,
13
- parent: $mappedPos.parent
14
- });
15
- let deleteFrom = $mappedPos.pos;
16
- let deleteTo = $mappedPos.pos + node.nodeSize;
17
- while($mappedPos.depth > 0){
18
- const $nextMappedPos = transform.doc.resolve($mappedPos.before());
19
- if ($nextMappedPos.nodeAfter?.childCount !== 1) {
20
- trace("stopping deletion at non-empty node:", $nextMappedPos.nodeAfter?.type.name, $nextMappedPos.nodeAfter == null ? null : getNodeId($nextMappedPos.nodeAfter), "\n", "non-empty node parent:", $nextMappedPos.parent.type.name, getNodeId($nextMappedPos.parent), "\n", "non-empty node subtree:\n", $nextMappedPos.nodeAfter?.toString(), "\n", "non-empty node subtree direct children:\n", $nextMappedPos.nodeAfter?.children.map((child)=>`${child.type.name} ${getNodeId(child) ?? "null"}`).join(", "), {
21
- nonEmptyNode: $nextMappedPos.nodeAfter,
22
- nonEmptyNodeParent: $nextMappedPos.parent
23
- });
24
- break;
25
- }
26
- $mappedPos = $nextMappedPos;
27
- deleteFrom = $nextMappedPos.pos;
28
- deleteTo = $nextMappedPos.pos + $nextMappedPos.nodeAfter.nodeSize;
29
- }
30
- trace("deleting subtree:\n", $mappedPos.nodeAfter?.toString(), "\n", "subtree root node:", $mappedPos.nodeAfter?.type.name, $mappedPos.nodeAfter == null ? null : getNodeId($mappedPos.nodeAfter), "\n", "subtree root parent node:", $mappedPos.parent.type.name, getNodeId($mappedPos.parent), "\n", "non-empty node subtree direct children:\n", $mappedPos.nodeAfter?.children.map((child)=>`${child.type.name} (${getNodeId(child) ?? "null"}`).join(", "), "\n", {
31
- node: $mappedPos.nodeAfter,
32
- parent: $mappedPos.parent,
33
- $deleteFrom: $mappedPos.doc.resolve(deleteFrom),
34
- $deleteTo: $mappedPos.doc.resolve(deleteTo)
35
- });
36
- transform.delete(deleteFrom, deleteTo);
37
- }
@@ -1,5 +0,0 @@
1
- import { Transform } from "prosemirror-transform";
2
- import { type Node } from "prosemirror-model";
3
- import { type SuggestionId } from "../../../generateId.js";
4
- export declare function revertAllStructureSuggestions(doc: Node, from?: number, to?: number): Transform;
5
- export declare function revertStructureSuggestion(doc: Node, suggestionId: SuggestionId): Transform;
@@ -1,19 +0,0 @@
1
- import { Transform } from "prosemirror-transform";
2
- import { revertStructureSuggestionsInDoc } from "./revertStructureSuggestions.js";
3
- export function revertAllStructureSuggestions(doc, from, to) {
4
- const tr = new Transform(doc);
5
- revertStructureSuggestionsInDoc({
6
- tr,
7
- from,
8
- to
9
- });
10
- return tr;
11
- }
12
- export function revertStructureSuggestion(doc, suggestionId) {
13
- const tr = new Transform(doc);
14
- revertStructureSuggestionsInDoc({
15
- tr,
16
- suggestionId
17
- });
18
- return tr;
19
- }
@@ -1,4 +0,0 @@
1
- import { type Transform } from "prosemirror-transform";
2
- import { type AddOp } from "../types.js";
3
- import { type Node } from "prosemirror-model";
4
- export declare function revertAddOp(_op: AddOp, tr: Transform, node: Node, pos: number): void;
@@ -1,4 +0,0 @@
1
- import { deleteNodeUpwards } from "./deleteNodeUpwards.js";
2
- export function revertAddOp(_op, tr, node, pos) {
3
- deleteNodeUpwards(tr, node, pos);
4
- }
@@ -1,16 +0,0 @@
1
- import { type Transform } from "prosemirror-transform";
2
- import { type MoveOp } from "../types.js";
3
- import { type Node } from "prosemirror-model";
4
- import { type Parent } from "../types.js";
5
- export declare function revertMoveOp(op: MoveOp, tr: Transform, node: Node, pos: number): void;
6
- export declare function getDeepestSurvivingParent(parentChain: Parent[], doc: Node): {
7
- parent: Parent;
8
- node: Node;
9
- pos: number | null;
10
- remainingChain: Parent[];
11
- };
12
- export declare function wrapNodeInParentChain(parentChain: Parent[], node: Node): Node;
13
- export declare function findInsertionPos(node: Node, pos: number | null, parent: Parent, child: Node): number | {
14
- from: number;
15
- to: number;
16
- };
@@ -1,122 +0,0 @@
1
- import { deleteNodeUpwards } from "./deleteNodeUpwards.js";
2
- import { getNodeId } from "../getNodeId.js";
3
- export function revertMoveOp(op, tr, node, pos) {
4
- const parent = getDeepestSurvivingParent(op.from, tr.doc);
5
- const child = wrapNodeInParentChain(parent.remainingChain, node);
6
- const insertTo = findInsertionPos(parent.node, parent.pos, parent.parent, child);
7
- if (typeof insertTo === "number") {
8
- tr.insert(insertTo, child);
9
- } else {
10
- tr.replaceWith(insertTo.from, insertTo.to, child);
11
- }
12
- const mappedPos = tr.mapping.map(pos);
13
- deleteNodeUpwards(tr, node, mappedPos);
14
- }
15
- // given a chain of parent node descriptors, follow the chain from top to bottom as long as nodes exist
16
- // return the deepest existing parent node descriptor, along with the actual node and the pos in the current document
17
- // also return the remaining part of the chain
18
- export function getDeepestSurvivingParent(parentChain, doc) {
19
- const chain = [
20
- ...parentChain
21
- ].reverse();
22
- const root = chain.shift();
23
- if (root == null) {
24
- throw new Error("Parent chain is empty");
25
- }
26
- let result = {
27
- parent: root,
28
- node: doc,
29
- pos: null
30
- };
31
- let remainingChain = [
32
- ...chain
33
- ];
34
- // follow the chain up-down
35
- // look for the node with the matching id in the children of the previously found node
36
- for (const [index, item] of chain.entries()){
37
- let found = false;
38
- result.node.forEach((child, offset)=>{
39
- if (found) return;
40
- if (child.attrs["id"] !== item.nodeId) return;
41
- found = true;
42
- const pos = result.pos == null ? offset : result.pos + 1 + offset;
43
- result = {
44
- parent: item,
45
- node: child,
46
- pos
47
- };
48
- remainingChain = chain.slice(index + 1);
49
- });
50
- if (!found) break;
51
- }
52
- return {
53
- parent: result.parent,
54
- node: result.node,
55
- pos: result.pos,
56
- remainingChain: remainingChain.reverse()
57
- };
58
- }
59
- // given a chain of parent node descriptors and a node
60
- // wrap the node in the parent chain
61
- export function wrapNodeInParentChain(parentChain, node) {
62
- let child = node.copy(node.content);
63
- for (const parent of parentChain){
64
- const schema = node.type.schema;
65
- const nodeType = schema.nodes[parent.nodeType];
66
- if (!nodeType) {
67
- throw new Error(`node type ${parent.nodeType} not found in schema`);
68
- }
69
- const marks = parent.nodeMarks.map((mark)=>schema.markFromJSON(mark));
70
- const parentNode = nodeType.createAndFill(parent.nodeAttrs, child, marks);
71
- if (parentNode == null) throw new Error(`Unable to create node ${nodeType.name} with child ${child.toString()}`);
72
- child = parentNode;
73
- child.check();
74
- }
75
- return child;
76
- }
77
- // given a node, its position, and a parent descriptor of this node in some parent chain,
78
- // use the info from the descriptor to find the insertion position in the node
79
- // first try to find siblings, fallback to end of node
80
- export function findInsertionPos(node, pos, parent, child) {
81
- let leftSibling = null;
82
- let rightSibling = null;
83
- node.descendants((child, localChildPos)=>{
84
- const childId = getNodeId(child);
85
- if (childId == null) return false;
86
- const globalChildPos = pos != null ? pos + 1 + localChildPos : localChildPos;
87
- if (parent.childSiblingIds[0] === childId) {
88
- leftSibling = {
89
- node: child,
90
- pos: globalChildPos
91
- };
92
- }
93
- if (parent.childSiblingIds[1] === childId) {
94
- rightSibling = {
95
- node: child,
96
- pos: globalChildPos
97
- };
98
- }
99
- // iterate only direct children
100
- return false;
101
- });
102
- if (rightSibling != null) {
103
- // special case: we need to insert as the first child, but the existing first child is an empty node of the same type
104
- // in this case, we need to replace the existing first child with the new node
105
- const firstChild = node.children[0];
106
- if (parent.childSiblingIds[0] == null && firstChild?.type === child.type && firstChild.textContent === "") {
107
- const from = pos != null ? pos + 1 : 0;
108
- return {
109
- from,
110
- to: from + firstChild.nodeSize
111
- };
112
- }
113
- // insert before right sibling
114
- return rightSibling.pos;
115
- }
116
- if (leftSibling != null) {
117
- // insert after left sibling
118
- return leftSibling.pos + leftSibling.node.nodeSize;
119
- }
120
- // insert at end of node
121
- return pos != null ? pos + node.nodeSize - 1 : node.content.size;
122
- }
@@ -1,10 +0,0 @@
1
- import { type Mark } from "prosemirror-model";
2
- import { Transform } from "prosemirror-transform";
3
- import { type SuggestionId } from "../../../generateId.js";
4
- export declare function revertStructureSuggestionsInDoc({ tr, suggestionId, from, to, }: {
5
- tr: Transform;
6
- suggestionId?: SuggestionId;
7
- from?: number | undefined;
8
- to?: number | undefined;
9
- }): void;
10
- export declare function revertStructureMark(tr: Transform, mark: Mark, pos: number): void;