@atlaskit/editor-plugin-local-id 1.0.3 → 1.0.5
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 +16 -0
- package/afm-cc/tsconfig.json +1 -1
- package/dist/cjs/pm-plugins/main.js +10 -23
- package/dist/es2019/pm-plugins/main.js +11 -21
- package/dist/esm/pm-plugins/main.js +11 -23
- package/dist/types/pm-plugins/main.d.ts +1 -5
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -5
- package/package.json +2 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-local-id
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e5f37a1deec51`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e5f37a1deec51) -
|
|
8
|
+
Added check for localId in the node spec to prevent adding id's to nodes that may not allow it.
|
|
9
|
+
|
|
10
|
+
## 1.0.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`84d49ebfb038b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/84d49ebfb038b) -
|
|
15
|
+
EDITOR-1426 Updated addLocalIdToNode to use setNodeAttribute which creates an attr step instead of
|
|
16
|
+
a replace step as localId attribute changes should not result in a document change.
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 1.0.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.localIdPluginKey = exports.createPlugin = exports.addLocalIdToNode = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
8
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
9
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
11
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
12
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
17
13
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
18
14
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -47,10 +43,10 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
47
43
|
// https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
|
|
48
44
|
var ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
|
|
49
45
|
editorView.state.doc.descendants(function (node, pos) {
|
|
50
|
-
|
|
51
|
-
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
|
|
46
|
+
var _node$type$spec$attrs;
|
|
47
|
+
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId && !!((_node$type$spec$attrs = node.type.spec.attrs) !== null && _node$type$spec$attrs !== void 0 && _node$type$spec$attrs.localId)) {
|
|
52
48
|
localIdWasAdded = true;
|
|
53
|
-
addLocalIdToNode(
|
|
49
|
+
addLocalIdToNode(pos, tr);
|
|
54
50
|
}
|
|
55
51
|
return true; // Continue traversing
|
|
56
52
|
});
|
|
@@ -70,7 +66,6 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
70
66
|
* This ensures uniqueness of localIds on nodes being created or edited
|
|
71
67
|
*/
|
|
72
68
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
73
|
-
var _caret$resolve;
|
|
74
69
|
var modified = false;
|
|
75
70
|
var tr = newState.tr;
|
|
76
71
|
var _newState$schema$node = newState.schema.nodes,
|
|
@@ -83,7 +78,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
83
78
|
var addedNodes = new Set();
|
|
84
79
|
var addedNodePos = new Map();
|
|
85
80
|
var localIds = new Set();
|
|
86
|
-
|
|
81
|
+
|
|
87
82
|
// Process only the nodes added in the transactions
|
|
88
83
|
transactions.forEach(function (transaction) {
|
|
89
84
|
if (!transaction.docChanged) {
|
|
@@ -99,7 +94,8 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
99
94
|
step.getMap().forEach(function (oldStart, oldEnd, newStart, newEnd) {
|
|
100
95
|
// Scan the changed range to find all nodes
|
|
101
96
|
tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) {
|
|
102
|
-
|
|
97
|
+
var _node$type$spec$attrs2;
|
|
98
|
+
if (ignoredNodeTypes.includes(node.type.name) || !((_node$type$spec$attrs2 = node.type.spec.attrs) !== null && _node$type$spec$attrs2 !== void 0 && _node$type$spec$attrs2.localId)) {
|
|
103
99
|
return true;
|
|
104
100
|
}
|
|
105
101
|
modified = true;
|
|
@@ -109,7 +105,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
109
105
|
addedNodePos.set(node, pos);
|
|
110
106
|
} else {
|
|
111
107
|
if (!(node !== null && node !== void 0 && node.attrs.localId)) {
|
|
112
|
-
addLocalIdToNode(
|
|
108
|
+
addLocalIdToNode(pos, tr);
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
return true;
|
|
@@ -133,7 +129,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
133
129
|
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
134
130
|
var pos = addedNodePos.get(node);
|
|
135
131
|
if (pos !== undefined) {
|
|
136
|
-
addLocalIdToNode(
|
|
132
|
+
addLocalIdToNode(pos, tr);
|
|
137
133
|
modified = true;
|
|
138
134
|
}
|
|
139
135
|
}
|
|
@@ -144,10 +140,6 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
144
140
|
_iterator.f();
|
|
145
141
|
}
|
|
146
142
|
}
|
|
147
|
-
|
|
148
|
-
// Restore caret to where the user left it.
|
|
149
|
-
var restored = (_caret$resolve = caret.resolve(tr.doc)) !== null && _caret$resolve !== void 0 ? _caret$resolve : _state.Selection.near(tr.doc.resolve(Math.min(newState.selection.from, tr.doc.content.size)), 1);
|
|
150
|
-
tr.setSelection(restored);
|
|
151
143
|
return modified ? tr : undefined;
|
|
152
144
|
}
|
|
153
145
|
});
|
|
@@ -156,15 +148,10 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
156
148
|
* Adds a local ID to a ProseMirror node
|
|
157
149
|
*
|
|
158
150
|
* This utility function updates a node's attributes to include a unique local ID.
|
|
159
|
-
* It preserves all existing attributes and marks while adding the new localId.
|
|
160
151
|
*
|
|
161
|
-
* @param node - The ProseMirror node to add a local ID to
|
|
162
152
|
* @param pos - The position of the node in the document
|
|
163
153
|
* @param tr - The transaction to apply the change to
|
|
164
|
-
* @returns The updated transaction with the node markup change
|
|
165
154
|
*/
|
|
166
|
-
var addLocalIdToNode = exports.addLocalIdToNode = function addLocalIdToNode(
|
|
167
|
-
tr.
|
|
168
|
-
localId: _adfSchema.uuid.generate()
|
|
169
|
-
}), node.marks);
|
|
155
|
+
var addLocalIdToNode = exports.addLocalIdToNode = function addLocalIdToNode(pos, tr) {
|
|
156
|
+
tr.setNodeAttribute(pos, 'localId', _adfSchema.uuid.generate());
|
|
170
157
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { uuid } from '@atlaskit/adf-schema';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
4
|
-
import { PluginKey
|
|
4
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
6
|
export const localIdPluginKey = new PluginKey('localIdPlugin');
|
|
7
7
|
|
|
@@ -35,10 +35,10 @@ export const createPlugin = () => {
|
|
|
35
35
|
// https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
|
|
36
36
|
const ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
|
|
37
37
|
editorView.state.doc.descendants((node, pos) => {
|
|
38
|
-
|
|
39
|
-
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
|
|
38
|
+
var _node$type$spec$attrs;
|
|
39
|
+
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId && !!((_node$type$spec$attrs = node.type.spec.attrs) !== null && _node$type$spec$attrs !== void 0 && _node$type$spec$attrs.localId)) {
|
|
40
40
|
localIdWasAdded = true;
|
|
41
|
-
addLocalIdToNode(
|
|
41
|
+
addLocalIdToNode(pos, tr);
|
|
42
42
|
}
|
|
43
43
|
return true; // Continue traversing
|
|
44
44
|
});
|
|
@@ -58,7 +58,6 @@ export const createPlugin = () => {
|
|
|
58
58
|
* This ensures uniqueness of localIds on nodes being created or edited
|
|
59
59
|
*/
|
|
60
60
|
appendTransaction: (transactions, _oldState, newState) => {
|
|
61
|
-
var _caret$resolve;
|
|
62
61
|
let modified = false;
|
|
63
62
|
const tr = newState.tr;
|
|
64
63
|
const {
|
|
@@ -72,7 +71,7 @@ export const createPlugin = () => {
|
|
|
72
71
|
const addedNodes = new Set();
|
|
73
72
|
const addedNodePos = new Map();
|
|
74
73
|
const localIds = new Set();
|
|
75
|
-
|
|
74
|
+
|
|
76
75
|
// Process only the nodes added in the transactions
|
|
77
76
|
transactions.forEach(transaction => {
|
|
78
77
|
if (!transaction.docChanged) {
|
|
@@ -88,7 +87,8 @@ export const createPlugin = () => {
|
|
|
88
87
|
step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
89
88
|
// Scan the changed range to find all nodes
|
|
90
89
|
tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), (node, pos) => {
|
|
91
|
-
|
|
90
|
+
var _node$type$spec$attrs2;
|
|
91
|
+
if (ignoredNodeTypes.includes(node.type.name) || !((_node$type$spec$attrs2 = node.type.spec.attrs) !== null && _node$type$spec$attrs2 !== void 0 && _node$type$spec$attrs2.localId)) {
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
94
94
|
modified = true;
|
|
@@ -98,7 +98,7 @@ export const createPlugin = () => {
|
|
|
98
98
|
addedNodePos.set(node, pos);
|
|
99
99
|
} else {
|
|
100
100
|
if (!(node !== null && node !== void 0 && node.attrs.localId)) {
|
|
101
|
-
addLocalIdToNode(
|
|
101
|
+
addLocalIdToNode(pos, tr);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
return true;
|
|
@@ -118,16 +118,12 @@ export const createPlugin = () => {
|
|
|
118
118
|
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
119
119
|
const pos = addedNodePos.get(node);
|
|
120
120
|
if (pos !== undefined) {
|
|
121
|
-
addLocalIdToNode(
|
|
121
|
+
addLocalIdToNode(pos, tr);
|
|
122
122
|
modified = true;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
// Restore caret to where the user left it.
|
|
129
|
-
const restored = (_caret$resolve = caret.resolve(tr.doc)) !== null && _caret$resolve !== void 0 ? _caret$resolve : Selection.near(tr.doc.resolve(Math.min(newState.selection.from, tr.doc.content.size)), 1);
|
|
130
|
-
tr.setSelection(restored);
|
|
131
127
|
return modified ? tr : undefined;
|
|
132
128
|
}
|
|
133
129
|
});
|
|
@@ -136,16 +132,10 @@ export const createPlugin = () => {
|
|
|
136
132
|
* Adds a local ID to a ProseMirror node
|
|
137
133
|
*
|
|
138
134
|
* This utility function updates a node's attributes to include a unique local ID.
|
|
139
|
-
* It preserves all existing attributes and marks while adding the new localId.
|
|
140
135
|
*
|
|
141
|
-
* @param node - The ProseMirror node to add a local ID to
|
|
142
136
|
* @param pos - The position of the node in the document
|
|
143
137
|
* @param tr - The transaction to apply the change to
|
|
144
|
-
* @returns The updated transaction with the node markup change
|
|
145
138
|
*/
|
|
146
|
-
export const addLocalIdToNode = (
|
|
147
|
-
tr.
|
|
148
|
-
...node.attrs,
|
|
149
|
-
localId: uuid.generate()
|
|
150
|
-
}, node.marks);
|
|
139
|
+
export const addLocalIdToNode = (pos, tr) => {
|
|
140
|
+
tr.setNodeAttribute(pos, 'localId', uuid.generate());
|
|
151
141
|
};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
5
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
4
|
import { uuid } from '@atlaskit/adf-schema';
|
|
8
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
6
|
import { stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
10
|
-
import { PluginKey
|
|
7
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
11
8
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
9
|
export var localIdPluginKey = new PluginKey('localIdPlugin');
|
|
13
10
|
|
|
@@ -40,10 +37,10 @@ export var createPlugin = function createPlugin() {
|
|
|
40
37
|
// https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
|
|
41
38
|
var ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
|
|
42
39
|
editorView.state.doc.descendants(function (node, pos) {
|
|
43
|
-
|
|
44
|
-
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
|
|
40
|
+
var _node$type$spec$attrs;
|
|
41
|
+
if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId && !!((_node$type$spec$attrs = node.type.spec.attrs) !== null && _node$type$spec$attrs !== void 0 && _node$type$spec$attrs.localId)) {
|
|
45
42
|
localIdWasAdded = true;
|
|
46
|
-
addLocalIdToNode(
|
|
43
|
+
addLocalIdToNode(pos, tr);
|
|
47
44
|
}
|
|
48
45
|
return true; // Continue traversing
|
|
49
46
|
});
|
|
@@ -63,7 +60,6 @@ export var createPlugin = function createPlugin() {
|
|
|
63
60
|
* This ensures uniqueness of localIds on nodes being created or edited
|
|
64
61
|
*/
|
|
65
62
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
66
|
-
var _caret$resolve;
|
|
67
63
|
var modified = false;
|
|
68
64
|
var tr = newState.tr;
|
|
69
65
|
var _newState$schema$node = newState.schema.nodes,
|
|
@@ -76,7 +72,7 @@ export var createPlugin = function createPlugin() {
|
|
|
76
72
|
var addedNodes = new Set();
|
|
77
73
|
var addedNodePos = new Map();
|
|
78
74
|
var localIds = new Set();
|
|
79
|
-
|
|
75
|
+
|
|
80
76
|
// Process only the nodes added in the transactions
|
|
81
77
|
transactions.forEach(function (transaction) {
|
|
82
78
|
if (!transaction.docChanged) {
|
|
@@ -92,7 +88,8 @@ export var createPlugin = function createPlugin() {
|
|
|
92
88
|
step.getMap().forEach(function (oldStart, oldEnd, newStart, newEnd) {
|
|
93
89
|
// Scan the changed range to find all nodes
|
|
94
90
|
tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) {
|
|
95
|
-
|
|
91
|
+
var _node$type$spec$attrs2;
|
|
92
|
+
if (ignoredNodeTypes.includes(node.type.name) || !((_node$type$spec$attrs2 = node.type.spec.attrs) !== null && _node$type$spec$attrs2 !== void 0 && _node$type$spec$attrs2.localId)) {
|
|
96
93
|
return true;
|
|
97
94
|
}
|
|
98
95
|
modified = true;
|
|
@@ -102,7 +99,7 @@ export var createPlugin = function createPlugin() {
|
|
|
102
99
|
addedNodePos.set(node, pos);
|
|
103
100
|
} else {
|
|
104
101
|
if (!(node !== null && node !== void 0 && node.attrs.localId)) {
|
|
105
|
-
addLocalIdToNode(
|
|
102
|
+
addLocalIdToNode(pos, tr);
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
return true;
|
|
@@ -126,7 +123,7 @@ export var createPlugin = function createPlugin() {
|
|
|
126
123
|
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
127
124
|
var pos = addedNodePos.get(node);
|
|
128
125
|
if (pos !== undefined) {
|
|
129
|
-
addLocalIdToNode(
|
|
126
|
+
addLocalIdToNode(pos, tr);
|
|
130
127
|
modified = true;
|
|
131
128
|
}
|
|
132
129
|
}
|
|
@@ -137,10 +134,6 @@ export var createPlugin = function createPlugin() {
|
|
|
137
134
|
_iterator.f();
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
|
-
|
|
141
|
-
// Restore caret to where the user left it.
|
|
142
|
-
var restored = (_caret$resolve = caret.resolve(tr.doc)) !== null && _caret$resolve !== void 0 ? _caret$resolve : Selection.near(tr.doc.resolve(Math.min(newState.selection.from, tr.doc.content.size)), 1);
|
|
143
|
-
tr.setSelection(restored);
|
|
144
137
|
return modified ? tr : undefined;
|
|
145
138
|
}
|
|
146
139
|
});
|
|
@@ -149,15 +142,10 @@ export var createPlugin = function createPlugin() {
|
|
|
149
142
|
* Adds a local ID to a ProseMirror node
|
|
150
143
|
*
|
|
151
144
|
* This utility function updates a node's attributes to include a unique local ID.
|
|
152
|
-
* It preserves all existing attributes and marks while adding the new localId.
|
|
153
145
|
*
|
|
154
|
-
* @param node - The ProseMirror node to add a local ID to
|
|
155
146
|
* @param pos - The position of the node in the document
|
|
156
147
|
* @param tr - The transaction to apply the change to
|
|
157
|
-
* @returns The updated transaction with the node markup change
|
|
158
148
|
*/
|
|
159
|
-
export var addLocalIdToNode = function addLocalIdToNode(
|
|
160
|
-
tr.
|
|
161
|
-
localId: uuid.generate()
|
|
162
|
-
}), node.marks);
|
|
149
|
+
export var addLocalIdToNode = function addLocalIdToNode(pos, tr) {
|
|
150
|
+
tr.setNodeAttribute(pos, 'localId', uuid.generate());
|
|
163
151
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import { PluginKey, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
3
|
export declare const localIdPluginKey: PluginKey<any>;
|
|
5
4
|
export declare const createPlugin: () => SafePlugin<any>;
|
|
@@ -7,11 +6,8 @@ export declare const createPlugin: () => SafePlugin<any>;
|
|
|
7
6
|
* Adds a local ID to a ProseMirror node
|
|
8
7
|
*
|
|
9
8
|
* This utility function updates a node's attributes to include a unique local ID.
|
|
10
|
-
* It preserves all existing attributes and marks while adding the new localId.
|
|
11
9
|
*
|
|
12
|
-
* @param node - The ProseMirror node to add a local ID to
|
|
13
10
|
* @param pos - The position of the node in the document
|
|
14
11
|
* @param tr - The transaction to apply the change to
|
|
15
|
-
* @returns The updated transaction with the node markup change
|
|
16
12
|
*/
|
|
17
|
-
export declare const addLocalIdToNode: (
|
|
13
|
+
export declare const addLocalIdToNode: (pos: number, tr: Transaction) => void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import { PluginKey, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
3
|
export declare const localIdPluginKey: PluginKey<any>;
|
|
5
4
|
export declare const createPlugin: () => SafePlugin<any>;
|
|
@@ -7,11 +6,8 @@ export declare const createPlugin: () => SafePlugin<any>;
|
|
|
7
6
|
* Adds a local ID to a ProseMirror node
|
|
8
7
|
*
|
|
9
8
|
* This utility function updates a node's attributes to include a unique local ID.
|
|
10
|
-
* It preserves all existing attributes and marks while adding the new localId.
|
|
11
9
|
*
|
|
12
|
-
* @param node - The ProseMirror node to add a local ID to
|
|
13
10
|
* @param pos - The position of the node in the document
|
|
14
11
|
* @param tr - The transaction to apply the change to
|
|
15
|
-
* @returns The updated transaction with the node markup change
|
|
16
12
|
*/
|
|
17
|
-
export declare const addLocalIdToNode: (
|
|
13
|
+
export declare const addLocalIdToNode: (pos: number, tr: Transaction) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-local-id",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "LocalId plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -27,9 +27,6 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
|
-
"af:exports": {
|
|
31
|
-
".": "./src/index.ts"
|
|
32
|
-
},
|
|
33
30
|
"dependencies": {
|
|
34
31
|
"@atlaskit/adf-schema": "^50.2.2",
|
|
35
32
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
@@ -38,7 +35,7 @@
|
|
|
38
35
|
"raf-schd": "^4.0.3"
|
|
39
36
|
},
|
|
40
37
|
"peerDependencies": {
|
|
41
|
-
"@atlaskit/editor-common": "^107.
|
|
38
|
+
"@atlaskit/editor-common": "^107.32.0",
|
|
42
39
|
"react": "^18.2.0"
|
|
43
40
|
},
|
|
44
41
|
"devDependencies": {
|