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

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,12 @@
1
1
  # @atlaskit/editor-plugin-local-id
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`655a927604c69`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/655a927604c69) -
8
+ Ignore media group node for local id as it is not in the schema for now
9
+
3
10
  ## 1.0.2
4
11
 
5
12
  ### Patch Changes
@@ -2,9 +2,9 @@
2
2
  "extends": "../../../../tsconfig.entry-points.confluence.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
- "composite": true,
6
5
  "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-local-id",
7
- "rootDir": "../"
6
+ "rootDir": "../",
7
+ "composite": true
8
8
  },
9
9
  "include": [
10
10
  "../src/**/*.ts",
@@ -41,8 +41,11 @@ var createPlugin = exports.createPlugin = function createPlugin() {
41
41
  var localIdWasAdded = false;
42
42
  var _editorView$state$sch = editorView.state.schema.nodes,
43
43
  text = _editorView$state$sch.text,
44
- hardBreak = _editorView$state$sch.hardBreak;
45
- var ignoredNodeTypes = [text.name, hardBreak.name];
44
+ hardBreak = _editorView$state$sch.hardBreak,
45
+ mediaGroup = _editorView$state$sch.mediaGroup;
46
+ // Media group is ignored for now
47
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
48
+ var ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
46
49
  editorView.state.doc.descendants(function (node, pos) {
47
50
  // Skip text nodes, hard breaks and nodes that already have local IDs
48
51
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
@@ -67,15 +70,20 @@ var createPlugin = exports.createPlugin = function createPlugin() {
67
70
  * This ensures uniqueness of localIds on nodes being created or edited
68
71
  */
69
72
  appendTransaction: function appendTransaction(transactions, _oldState, newState) {
73
+ var _caret$resolve;
70
74
  var modified = false;
71
75
  var tr = newState.tr;
72
76
  var _newState$schema$node = newState.schema.nodes,
73
77
  text = _newState$schema$node.text,
74
- hardBreak = _newState$schema$node.hardBreak;
75
- var ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name];
78
+ hardBreak = _newState$schema$node.hardBreak,
79
+ mediaGroup = _newState$schema$node.mediaGroup;
80
+ // Media group is ignored for now
81
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
82
+ var ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name, mediaGroup === null || mediaGroup === void 0 ? void 0 : mediaGroup.name];
76
83
  var addedNodes = new Set();
77
84
  var addedNodePos = new Map();
78
85
  var localIds = new Set();
86
+ var caret = newState.selection.getBookmark();
79
87
  // Process only the nodes added in the transactions
80
88
  transactions.forEach(function (transaction) {
81
89
  if (!transaction.docChanged) {
@@ -136,6 +144,10 @@ var createPlugin = exports.createPlugin = function createPlugin() {
136
144
  _iterator.f();
137
145
  }
138
146
  }
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);
139
151
  return modified ? tr : undefined;
140
152
  }
141
153
  });
@@ -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 } from '@atlaskit/editor-prosemirror/state';
4
+ import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
6
  export const localIdPluginKey = new PluginKey('localIdPlugin');
7
7
 
@@ -28,9 +28,12 @@ export const createPlugin = () => {
28
28
  let localIdWasAdded = false;
29
29
  const {
30
30
  text,
31
- hardBreak
31
+ hardBreak,
32
+ mediaGroup
32
33
  } = editorView.state.schema.nodes;
33
- const ignoredNodeTypes = [text.name, hardBreak.name];
34
+ // Media group is ignored for now
35
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
36
+ const ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
34
37
  editorView.state.doc.descendants((node, pos) => {
35
38
  // Skip text nodes, hard breaks and nodes that already have local IDs
36
39
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
@@ -55,16 +58,21 @@ export const createPlugin = () => {
55
58
  * This ensures uniqueness of localIds on nodes being created or edited
56
59
  */
57
60
  appendTransaction: (transactions, _oldState, newState) => {
61
+ var _caret$resolve;
58
62
  let modified = false;
59
63
  const tr = newState.tr;
60
64
  const {
61
65
  text,
62
- hardBreak
66
+ hardBreak,
67
+ mediaGroup
63
68
  } = newState.schema.nodes;
64
- const ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name];
69
+ // Media group is ignored for now
70
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
71
+ const ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name, mediaGroup === null || mediaGroup === void 0 ? void 0 : mediaGroup.name];
65
72
  const addedNodes = new Set();
66
73
  const addedNodePos = new Map();
67
74
  const localIds = new Set();
75
+ const caret = newState.selection.getBookmark();
68
76
  // Process only the nodes added in the transactions
69
77
  transactions.forEach(transaction => {
70
78
  if (!transaction.docChanged) {
@@ -116,6 +124,10 @@ export const createPlugin = () => {
116
124
  }
117
125
  }
118
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);
119
131
  return modified ? tr : undefined;
120
132
  }
121
133
  });
@@ -7,7 +7,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
7
7
  import { uuid } from '@atlaskit/adf-schema';
8
8
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
9
  import { stepHasSlice } from '@atlaskit/editor-common/utils';
10
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
+ import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
12
  export var localIdPluginKey = new PluginKey('localIdPlugin');
13
13
 
@@ -34,8 +34,11 @@ export var createPlugin = function createPlugin() {
34
34
  var localIdWasAdded = false;
35
35
  var _editorView$state$sch = editorView.state.schema.nodes,
36
36
  text = _editorView$state$sch.text,
37
- hardBreak = _editorView$state$sch.hardBreak;
38
- var ignoredNodeTypes = [text.name, hardBreak.name];
37
+ hardBreak = _editorView$state$sch.hardBreak,
38
+ mediaGroup = _editorView$state$sch.mediaGroup;
39
+ // Media group is ignored for now
40
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
41
+ var ignoredNodeTypes = mediaGroup ? [text.name, hardBreak.name, mediaGroup.name] : [text.name, hardBreak.name];
39
42
  editorView.state.doc.descendants(function (node, pos) {
40
43
  // Skip text nodes, hard breaks and nodes that already have local IDs
41
44
  if (!ignoredNodeTypes.includes(node.type.name) && !node.attrs.localId) {
@@ -60,15 +63,20 @@ export var createPlugin = function createPlugin() {
60
63
  * This ensures uniqueness of localIds on nodes being created or edited
61
64
  */
62
65
  appendTransaction: function appendTransaction(transactions, _oldState, newState) {
66
+ var _caret$resolve;
63
67
  var modified = false;
64
68
  var tr = newState.tr;
65
69
  var _newState$schema$node = newState.schema.nodes,
66
70
  text = _newState$schema$node.text,
67
- hardBreak = _newState$schema$node.hardBreak;
68
- var ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name];
71
+ hardBreak = _newState$schema$node.hardBreak,
72
+ mediaGroup = _newState$schema$node.mediaGroup;
73
+ // Media group is ignored for now
74
+ // https://bitbucket.org/atlassian/adf-schema/src/fb2236147a0c2bc9c8efbdb75fd8f8c411df44ba/packages/adf-schema/src/next-schema/nodes/mediaGroup.ts#lines-12
75
+ var ignoredNodeTypes = [text === null || text === void 0 ? void 0 : text.name, hardBreak === null || hardBreak === void 0 ? void 0 : hardBreak.name, mediaGroup === null || mediaGroup === void 0 ? void 0 : mediaGroup.name];
69
76
  var addedNodes = new Set();
70
77
  var addedNodePos = new Map();
71
78
  var localIds = new Set();
79
+ var caret = newState.selection.getBookmark();
72
80
  // Process only the nodes added in the transactions
73
81
  transactions.forEach(function (transaction) {
74
82
  if (!transaction.docChanged) {
@@ -129,6 +137,10 @@ export var createPlugin = function createPlugin() {
129
137
  _iterator.f();
130
138
  }
131
139
  }
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);
132
144
  return modified ? tr : undefined;
133
145
  }
134
146
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-local-id",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "LocalId plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,14 +31,14 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/adf-schema": "^50.2.1",
34
+ "@atlaskit/adf-schema": "^50.2.2",
35
35
  "@atlaskit/editor-prosemirror": "7.0.0",
36
36
  "@atlaskit/platform-feature-flags": "^1.1.0",
37
37
  "@babel/runtime": "^7.0.0",
38
38
  "raf-schd": "^4.0.3"
39
39
  },
40
40
  "peerDependencies": {
41
- "@atlaskit/editor-common": "^107.26.0",
41
+ "@atlaskit/editor-common": "^107.31.0",
42
42
  "react": "^18.2.0"
43
43
  },
44
44
  "devDependencies": {