@atlaskit/editor-plugin-local-id 1.0.3 → 1.0.4

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-local-id
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`84d49ebfb038b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/84d49ebfb038b) -
8
+ EDITOR-1426 Updated addLocalIdToNode to use setNodeAttribute which creates an attr step instead of
9
+ a replace step as localId attribute changes should not result in a document change.
10
+ - Updated dependencies
11
+
3
12
  ## 1.0.3
4
13
 
5
14
  ### Patch Changes
@@ -24,4 +24,4 @@
24
24
  "path": "../../editor-common/afm-cc/tsconfig.json"
25
25
  }
26
26
  ]
27
- }
27
+ }
@@ -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; }
@@ -50,7 +46,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
50
46
  // Skip text nodes, hard breaks and nodes that already have local IDs
51
47
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
52
48
  localIdWasAdded = true;
53
- addLocalIdToNode(node, pos, tr);
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
- var caret = newState.selection.getBookmark();
81
+
87
82
  // Process only the nodes added in the transactions
88
83
  transactions.forEach(function (transaction) {
89
84
  if (!transaction.docChanged) {
@@ -109,7 +104,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
109
104
  addedNodePos.set(node, pos);
110
105
  } else {
111
106
  if (!(node !== null && node !== void 0 && node.attrs.localId)) {
112
- addLocalIdToNode(node, pos, tr);
107
+ addLocalIdToNode(pos, tr);
113
108
  }
114
109
  }
115
110
  return true;
@@ -133,7 +128,7 @@ var createPlugin = exports.createPlugin = function createPlugin() {
133
128
  if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
134
129
  var pos = addedNodePos.get(node);
135
130
  if (pos !== undefined) {
136
- addLocalIdToNode(node, pos, tr);
131
+ addLocalIdToNode(pos, tr);
137
132
  modified = true;
138
133
  }
139
134
  }
@@ -144,10 +139,6 @@ var createPlugin = exports.createPlugin = function createPlugin() {
144
139
  _iterator.f();
145
140
  }
146
141
  }
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
142
  return modified ? tr : undefined;
152
143
  }
153
144
  });
@@ -156,15 +147,10 @@ var createPlugin = exports.createPlugin = function createPlugin() {
156
147
  * Adds a local ID to a ProseMirror node
157
148
  *
158
149
  * 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
150
  *
161
- * @param node - The ProseMirror node to add a local ID to
162
151
  * @param pos - The position of the node in the document
163
152
  * @param tr - The transaction to apply the change to
164
- * @returns The updated transaction with the node markup change
165
153
  */
166
- var addLocalIdToNode = exports.addLocalIdToNode = function addLocalIdToNode(node, pos, tr) {
167
- tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
168
- localId: _adfSchema.uuid.generate()
169
- }), node.marks);
154
+ var addLocalIdToNode = exports.addLocalIdToNode = function addLocalIdToNode(pos, tr) {
155
+ tr.setNodeAttribute(pos, 'localId', _adfSchema.uuid.generate());
170
156
  };
@@ -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, Selection } from '@atlaskit/editor-prosemirror/state';
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
 
@@ -38,7 +38,7 @@ export const createPlugin = () => {
38
38
  // Skip text nodes, hard breaks and nodes that already have local IDs
39
39
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
40
40
  localIdWasAdded = true;
41
- addLocalIdToNode(node, pos, tr);
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
- const caret = newState.selection.getBookmark();
74
+
76
75
  // Process only the nodes added in the transactions
77
76
  transactions.forEach(transaction => {
78
77
  if (!transaction.docChanged) {
@@ -98,7 +97,7 @@ export const createPlugin = () => {
98
97
  addedNodePos.set(node, pos);
99
98
  } else {
100
99
  if (!(node !== null && node !== void 0 && node.attrs.localId)) {
101
- addLocalIdToNode(node, pos, tr);
100
+ addLocalIdToNode(pos, tr);
102
101
  }
103
102
  }
104
103
  return true;
@@ -118,16 +117,12 @@ export const createPlugin = () => {
118
117
  if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
119
118
  const pos = addedNodePos.get(node);
120
119
  if (pos !== undefined) {
121
- addLocalIdToNode(node, pos, tr);
120
+ addLocalIdToNode(pos, tr);
122
121
  modified = true;
123
122
  }
124
123
  }
125
124
  }
126
125
  }
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
126
  return modified ? tr : undefined;
132
127
  }
133
128
  });
@@ -136,16 +131,10 @@ export const createPlugin = () => {
136
131
  * Adds a local ID to a ProseMirror node
137
132
  *
138
133
  * 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
134
  *
141
- * @param node - The ProseMirror node to add a local ID to
142
135
  * @param pos - The position of the node in the document
143
136
  * @param tr - The transaction to apply the change to
144
- * @returns The updated transaction with the node markup change
145
137
  */
146
- export const addLocalIdToNode = (node, pos, tr) => {
147
- tr.setNodeMarkup(pos, node.type, {
148
- ...node.attrs,
149
- localId: uuid.generate()
150
- }, node.marks);
138
+ export const addLocalIdToNode = (pos, tr) => {
139
+ tr.setNodeAttribute(pos, 'localId', uuid.generate());
151
140
  };
@@ -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, Selection } from '@atlaskit/editor-prosemirror/state';
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
 
@@ -43,7 +40,7 @@ export var createPlugin = function createPlugin() {
43
40
  // Skip text nodes, hard breaks and nodes that already have local IDs
44
41
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
45
42
  localIdWasAdded = true;
46
- addLocalIdToNode(node, pos, tr);
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
- var caret = newState.selection.getBookmark();
75
+
80
76
  // Process only the nodes added in the transactions
81
77
  transactions.forEach(function (transaction) {
82
78
  if (!transaction.docChanged) {
@@ -102,7 +98,7 @@ export var createPlugin = function createPlugin() {
102
98
  addedNodePos.set(node, pos);
103
99
  } else {
104
100
  if (!(node !== null && node !== void 0 && node.attrs.localId)) {
105
- addLocalIdToNode(node, pos, tr);
101
+ addLocalIdToNode(pos, tr);
106
102
  }
107
103
  }
108
104
  return true;
@@ -126,7 +122,7 @@ export var createPlugin = function createPlugin() {
126
122
  if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
127
123
  var pos = addedNodePos.get(node);
128
124
  if (pos !== undefined) {
129
- addLocalIdToNode(node, pos, tr);
125
+ addLocalIdToNode(pos, tr);
130
126
  modified = true;
131
127
  }
132
128
  }
@@ -137,10 +133,6 @@ export var createPlugin = function createPlugin() {
137
133
  _iterator.f();
138
134
  }
139
135
  }
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
136
  return modified ? tr : undefined;
145
137
  }
146
138
  });
@@ -149,15 +141,10 @@ export var createPlugin = function createPlugin() {
149
141
  * Adds a local ID to a ProseMirror node
150
142
  *
151
143
  * 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
144
  *
154
- * @param node - The ProseMirror node to add a local ID to
155
145
  * @param pos - The position of the node in the document
156
146
  * @param tr - The transaction to apply the change to
157
- * @returns The updated transaction with the node markup change
158
147
  */
159
- export var addLocalIdToNode = function addLocalIdToNode(node, pos, tr) {
160
- tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
161
- localId: uuid.generate()
162
- }), node.marks);
148
+ export var addLocalIdToNode = function addLocalIdToNode(pos, tr) {
149
+ tr.setNodeAttribute(pos, 'localId', uuid.generate());
163
150
  };
@@ -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: (node: PMNode, pos: number, tr: Transaction) => void;
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: (node: PMNode, pos: number, tr: Transaction) => void;
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",
3
+ "version": "1.0.4",
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.31.0",
38
+ "@atlaskit/editor-common": "^107.32.0",
42
39
  "react": "^18.2.0"
43
40
  },
44
41
  "devDependencies": {