@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.23 → 0.3.3-wrap-unwrap.25

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.
@@ -63,19 +63,26 @@ export function revertStructureSuggestionsInDoc({ tr, suggestionId, from, to })
63
63
  }
64
64
  function revertStructureSuggestionWithPrerequisites(tr, suggestionId) {
65
65
  const suggestionIds = buildOrderedSuggestionIds(tr.doc, suggestionId, buildMaterializedPaths(tr.doc));
66
- trace("reverting structure suggestions: ", suggestionIds);
66
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67
+ if (TRACE_ENABLED) console.group("reverting structure suggestions", suggestionIds);
67
68
  for (const suggestionId of suggestionIds){
68
69
  revertOneStructureSuggestion(tr, suggestionId);
69
70
  }
71
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
72
+ if (TRACE_ENABLED) console.groupEnd();
70
73
  }
71
74
  function revertOneStructureSuggestion(tr, suggestionId) {
75
+ let count = 0;
72
76
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
73
- if (TRACE_ENABLED) console.group("reverting structure suggestion: ", suggestionId);
77
+ if (TRACE_ENABLED) console.groupCollapsed("reverting structure suggestion", suggestionId);
74
78
  let structureMark = findNextStructureMark(tr.doc, suggestionId);
75
79
  while(structureMark !== null){
80
+ trace("reverting structure suggestion", suggestionId, "structure mark", structureMark.mark, "at pos", structureMark.pos, "at node", structureMark.node.toString());
76
81
  revertStructureMark(tr, structureMark.mark, structureMark.pos);
77
82
  structureMark = findNextStructureMark(tr.doc, suggestionId);
83
+ count++;
78
84
  }
85
+ trace("reverted", count, "structure marks for suggestion", suggestionId);
79
86
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
80
87
  if (TRACE_ENABLED) console.groupEnd();
81
88
  }
@@ -174,6 +181,7 @@ function buildOrderedSuggestionIds(node, suggestionId, materializedPaths) {
174
181
  return sameParentChain(attrs.data.op.to, parentChain.chain);
175
182
  });
176
183
  if (match) {
184
+ trace("suggestion", match.attrs["id"], "is a prerequisite for suggestion", suggestionId);
177
185
  suggestionIds.add(match.attrs["id"]);
178
186
  }
179
187
  return Array.from(suggestionIds).reverse();
@@ -9,12 +9,19 @@ interface NodeParent {
9
9
  childSiblingIds: [string | null, string | null];
10
10
  childIndex: number;
11
11
  }
12
- export interface StructureMarkAttrs {
12
+ interface StructureMoveMarkAttrs {
13
13
  id: SuggestionId;
14
14
  data: {
15
- op: Op;
15
+ op: MoveOp;
16
16
  };
17
17
  }
18
+ interface StructureAddMarkAttrs {
19
+ id: SuggestionId;
20
+ data: {
21
+ op: AddOp;
22
+ };
23
+ }
24
+ export type StructureMarkAttrs = StructureMoveMarkAttrs | StructureAddMarkAttrs;
18
25
  export type StructuralContextPath = readonly [string, ...string[]];
19
26
  export interface DocParent extends Omit<NodeParent, "nodeId"> {
20
27
  nodeId: typeof DOC_NODE_ID;
@@ -37,9 +44,11 @@ export type MaterializedPaths = Map<string, {
37
44
  }>;
38
45
  export declare function guardDocParent(parent: Parent | undefined): parent is DocParent;
39
46
  export declare function guardStructureMarkAttrs(attrs: Attrs): attrs is StructureMarkAttrs;
47
+ export declare function guardStructureMoveMarkAttrs(attrs: Attrs): attrs is StructureMoveMarkAttrs;
48
+ export declare function guardStructureAddMarkAttrs(attrs: Attrs): attrs is StructureAddMarkAttrs;
40
49
  export interface StructureMarkObject {
41
50
  type: "structure";
42
51
  attrs: StructureMarkAttrs;
43
52
  }
44
- export declare function isStructureMarkObject(mark: unknown): mark is StructureMarkObject;
53
+ export declare function guardStructureMarkObject(mark: unknown): mark is StructureMarkObject;
45
54
  export {};
@@ -9,7 +9,13 @@ export function guardStructureMarkAttrs(attrs) {
9
9
  if (!("op" in data)) return false;
10
10
  return true;
11
11
  }
12
- export function isStructureMarkObject(mark) {
12
+ export function guardStructureMoveMarkAttrs(attrs) {
13
+ return guardStructureMarkAttrs(attrs) && attrs.data.op.op === "move";
14
+ }
15
+ export function guardStructureAddMarkAttrs(attrs) {
16
+ return guardStructureMarkAttrs(attrs) && attrs.data.op.op === "add";
17
+ }
18
+ export function guardStructureMarkObject(mark) {
13
19
  if (mark === null || typeof mark !== "object") return false;
14
20
  if (!("type" in mark) || mark.type !== "structure") return false;
15
21
  if (!("attrs" in mark)) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic-marker/prosemirror-suggest-changes",
3
- "version": "0.3.3-wrap-unwrap.23",
3
+ "version": "0.3.3-wrap-unwrap.25",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",