@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.22 → 0.3.3-wrap-unwrap.23
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/dist/ensureSelectionPlugin.js +1 -1
- package/dist/features/wrapUnwrap/buildMaterializedPaths.js +1 -1
- package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.js +1 -1
- package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.js +1 -1
- package/dist/features/wrapUnwrap/structureChangesPlugin.js +1 -1
- package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.js +16 -8
- package/dist/withSuggestChanges.js +1 -1
- package/package.json +1 -1
|
@@ -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 =
|
|
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 =
|
|
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;
|
|
@@ -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 =
|
|
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 =
|
|
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;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
24
|
+
trace("doc not changed, skipping", [
|
|
19
25
|
...transactions
|
|
20
26
|
]);
|
|
21
27
|
return;
|
|
22
28
|
}
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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;
|