@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.22 → 0.3.3-wrap-unwrap.24

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.
@@ -1,7 +1,7 @@
1
1
  import { Plugin, PluginKey, TextSelection } from "prosemirror-state";
2
2
  import { getSuggestionMarks } from "./utils.js";
3
3
  import { ZWSP } from "./constants.js";
4
- const TRACE_ENABLED = true;
4
+ const TRACE_ENABLED = false;
5
5
  function trace(...args) {
6
6
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7
7
  if (!TRACE_ENABLED) return;
@@ -1,6 +1,6 @@
1
1
  import { getNodeId } from "./getNodeId.js";
2
2
  import { DOC_NODE_ID } from "./constants.js";
3
- const TRACE_ENABLED = true;
3
+ const TRACE_ENABLED = false;
4
4
  function trace(...args) {
5
5
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
6
6
  if (!TRACE_ENABLED) return;
@@ -1,5 +1,5 @@
1
1
  import { getNodeId } from "../getNodeId.js";
2
- const TRACE_ENABLED = true;
2
+ const TRACE_ENABLED = false;
3
3
  function trace(...args) {
4
4
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
5
5
  if (!TRACE_ENABLED) return;
@@ -6,7 +6,7 @@ import { sameParentChain } from "../sameParentChain.js";
6
6
  import { buildMaterializedPaths } from "../buildMaterializedPaths.js";
7
7
  import { revertAddOp } from "./revertAddOp.js";
8
8
  import { revertMoveOp } from "./revertMoveOp.js";
9
- const TRACE_ENABLED = true;
9
+ const TRACE_ENABLED = false;
10
10
  function trace(...args) {
11
11
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
12
  if (!TRACE_ENABLED) return;
@@ -8,7 +8,7 @@ import { Transform } from "prosemirror-transform";
8
8
  import { isSuggestChangesEnabled, suggestChangesKey } from "../../plugin.js";
9
9
  import { buildMaterializedPaths } from "./buildMaterializedPaths.js";
10
10
  import { sameParentChain } from "./sameParentChain.js";
11
- const TRACE_ENABLED = true;
11
+ const TRACE_ENABLED = false;
12
12
  function trace(...args) {
13
13
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
14
14
  if (!TRACE_ENABLED) return;
@@ -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;
@@ -6,22 +6,27 @@ import { Transform } from "prosemirror-transform";
6
6
  // (also checks and fix duplicates that inevitably appear)
7
7
  export const uniqueNodeIdsPluginKey = new PluginKey("@handlewithcare/prosemirror-suggest-changes-unique-node-ids");
8
8
  export const UNIQUE_NODE_IDS_PLUGIN_META = "unique-node-ids-plugin";
9
+ const TRACE_ENABLED = false;
10
+ function trace(...args) {
11
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
+ if (!TRACE_ENABLED) return;
13
+ console.log("[uniqueNodeIdsPlugin]", ...args);
14
+ }
9
15
  export function uniqueNodeIdsPlugin({ attributeName, generateID }) {
10
16
  return new Plugin({
11
17
  key: uniqueNodeIdsPluginKey,
12
18
  appendTransaction (transactions, oldState, newState) {
13
- console.log("uniqueNodeIdsPlugin.appendTransaction");
19
+ trace("appendTransaction");
14
20
  const pluginState = uniqueNodeIdsPluginKey.getState(newState);
15
21
  // do nothing if doc hasn't changed (but make sure it runs initially)
16
22
  const docChanged = transactions.some((transaction)=>transaction.docChanged);
17
23
  if (!docChanged && pluginState?.completedInitialRun) {
18
- console.warn("uniqueNodeIdsPlugin", "doc not changed, skipping", [
24
+ trace("doc not changed, skipping", [
19
25
  ...transactions
20
26
  ]);
21
27
  return;
22
28
  }
23
- console.groupCollapsed("uniqueNodeIdsPlugin", "appendTransaction");
24
- console.log("uniqueNodeIdsPlugin", "appendTransaction", [
29
+ trace("appendTransaction", [
25
30
  ...transactions
26
31
  ]);
27
32
  const tr = newState.tr;
@@ -32,8 +37,7 @@ export function uniqueNodeIdsPlugin({ attributeName, generateID }) {
32
37
  transform.steps.forEach((step)=>{
33
38
  tr.step(step);
34
39
  });
35
- console.log("ensureUniqueNodeIdsPlugin", "tr steps", tr.steps);
36
- console.groupEnd();
40
+ trace("tr steps", tr.steps);
37
41
  if (!tr.steps.length) return;
38
42
  tr.setMeta(uniqueNodeIdsPluginKey, UNIQUE_NODE_IDS_PLUGIN_META);
39
43
  return tr;
@@ -59,6 +63,8 @@ export function uniqueNodeIdsPlugin({ attributeName, generateID }) {
59
63
  export function ensureUniqueNodeIds(_transactions, _oldDoc, newDoc, options) {
60
64
  const tr = new Transform(newDoc);
61
65
  const nodeIds = new Set();
66
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67
+ if (TRACE_ENABLED) console.groupCollapsed("ensureUniqueNodeIds");
62
68
  tr.doc.descendants((node, pos)=>{
63
69
  if (node.isText) return false;
64
70
  const nodeId = getNodeId(node);
@@ -75,7 +81,7 @@ export function ensureUniqueNodeIds(_transactions, _oldDoc, newDoc, options) {
75
81
  ...node.attrs,
76
82
  [options.attributeName]: id
77
83
  }, node.marks);
78
- console.log("ensureUniqueNodeIds", "fixed duplicate id", id, "for node", node.type.name, "at pos", pos, {
84
+ trace("fixed duplicate id", id, "for node", node.type.name, "at pos", pos, {
79
85
  was: nodeId,
80
86
  is: id
81
87
  });
@@ -89,10 +95,12 @@ export function ensureUniqueNodeIds(_transactions, _oldDoc, newDoc, options) {
89
95
  ...node.attrs,
90
96
  [options.attributeName]: id
91
97
  }, node.marks);
92
- console.log("ensureUniqueNodeIds", "set unique id", id, "for node", node.type.name, "at pos", pos);
98
+ trace("set unique id", id, "for node", node.type.name, "at pos", pos);
93
99
  return true;
94
100
  }
95
101
  return true;
96
102
  });
103
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
104
+ if (TRACE_ENABLED) console.groupEnd();
97
105
  return tr;
98
106
  }
@@ -4,7 +4,7 @@ import { getRequiredStructuralContextPaths, suggestStructureChanges } from "./fe
4
4
  import { handleSpecialTransactionShape } from "./features/transactionShaping/index.js";
5
5
  import { transformToSuggestionTransaction } from "./transformToSuggestionTransaction.js";
6
6
  export { transformToSuggestionTransaction } from "./transformToSuggestionTransaction.js";
7
- const TRACE_ENABLED = true;
7
+ const TRACE_ENABLED = false;
8
8
  function trace(...args) {
9
9
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10
10
  if (!TRACE_ENABLED) return;
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.22",
3
+ "version": "0.3.3-wrap-unwrap.24",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",