@atlaskit/editor-core 189.1.0 → 189.1.1
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 +8 -0
- package/dist/cjs/extensibility.js +4 -4
- package/dist/cjs/plugins/annotation/commands/index.js +51 -43
- package/dist/cjs/plugins/annotation/commands/transform.js +43 -33
- package/dist/cjs/plugins/annotation/index.js +12 -5
- package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +17 -13
- package/dist/cjs/plugins/annotation/pm-plugins/keymap.js +2 -2
- package/dist/cjs/plugins/annotation/toolbar.js +41 -39
- package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +4 -3
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/utils/document.js +0 -26
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/extensibility.js +1 -1
- package/dist/es2019/plugins/annotation/commands/index.js +8 -8
- package/dist/es2019/plugins/annotation/commands/transform.js +13 -11
- package/dist/es2019/plugins/annotation/index.js +12 -5
- package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +10 -10
- package/dist/es2019/plugins/annotation/pm-plugins/keymap.js +2 -2
- package/dist/es2019/plugins/annotation/toolbar.js +2 -2
- package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +4 -3
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/presets/universal.js +3 -2
- package/dist/es2019/utils/document.js +0 -25
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/extensibility.js +1 -1
- package/dist/esm/plugins/annotation/commands/index.js +51 -43
- package/dist/esm/plugins/annotation/commands/transform.js +40 -30
- package/dist/esm/plugins/annotation/index.js +12 -5
- package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +17 -13
- package/dist/esm/plugins/annotation/pm-plugins/keymap.js +2 -2
- package/dist/esm/plugins/annotation/toolbar.js +41 -39
- package/dist/esm/plugins/annotation/ui/InlineCommentView.js +4 -3
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/presets/universal.js +3 -2
- package/dist/esm/utils/document.js +0 -24
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/extensibility.d.ts +1 -1
- package/dist/types/plugins/annotation/commands/index.d.ts +5 -4
- package/dist/types/plugins/annotation/commands/transform.d.ts +5 -4
- package/dist/types/plugins/annotation/index.d.ts +5 -2
- package/dist/types/plugins/annotation/pm-plugins/keymap.d.ts +2 -1
- package/dist/types/plugins/annotation/pm-plugins/types.d.ts +2 -0
- package/dist/types/plugins/annotation/toolbar.d.ts +2 -1
- package/dist/types/plugins/annotation/ui/InlineCommentView.d.ts +3 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/utils/document.d.ts +0 -11
- package/dist/types-ts4.5/extensibility.d.ts +1 -1
- package/dist/types-ts4.5/plugins/annotation/commands/index.d.ts +5 -4
- package/dist/types-ts4.5/plugins/annotation/commands/transform.d.ts +5 -4
- package/dist/types-ts4.5/plugins/annotation/index.d.ts +7 -2
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/keymap.d.ts +2 -1
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +2 -1
- package/dist/types-ts4.5/plugins/annotation/ui/InlineCommentView.d.ts +3 -1
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/utils/document.d.ts +0 -11
- package/package.json +4 -3
- package/dist/cjs/plugins/fragment/index.js +0 -29
- package/dist/cjs/plugins/fragment/plugin-key.js +0 -8
- package/dist/cjs/plugins/fragment/pm-plugins/fragment-consistency.js +0 -143
- package/dist/es2019/plugins/fragment/index.js +0 -20
- package/dist/es2019/plugins/fragment/plugin-key.js +0 -2
- package/dist/es2019/plugins/fragment/pm-plugins/fragment-consistency.js +0 -113
- package/dist/esm/plugins/fragment/index.js +0 -23
- package/dist/esm/plugins/fragment/plugin-key.js +0 -2
- package/dist/esm/plugins/fragment/pm-plugins/fragment-consistency.js +0 -137
- package/dist/types/plugins/fragment/index.d.ts +0 -3
- package/dist/types/plugins/fragment/plugin-key.d.ts +0 -2
- package/dist/types/plugins/fragment/pm-plugins/fragment-consistency.d.ts +0 -15
- package/dist/types-ts4.5/plugins/fragment/index.d.ts +0 -3
- package/dist/types-ts4.5/plugins/fragment/plugin-key.d.ts +0 -2
- package/dist/types-ts4.5/plugins/fragment/pm-plugins/fragment-consistency.d.ts +0 -15
|
@@ -8,17 +8,6 @@ import type { BreakoutMarkAttrs } from '@atlaskit/adf-schema';
|
|
|
8
8
|
export { findFarthestParentNode, isInEmptyLine, } from '@atlaskit/editor-common/utils';
|
|
9
9
|
export declare function processRawFragmentValue(schema: Schema, value?: ReplaceRawValue[], providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Fragment | undefined;
|
|
10
10
|
export type ChangedFn = (node: Node, pos: number, parent: Node | null, index: number) => boolean | void;
|
|
11
|
-
export declare function getChangedNodesIn({ tr, doc, }: {
|
|
12
|
-
tr: ReadonlyTransaction | Transaction;
|
|
13
|
-
doc: Node;
|
|
14
|
-
}): {
|
|
15
|
-
node: Node;
|
|
16
|
-
pos: number;
|
|
17
|
-
}[];
|
|
18
|
-
export declare function getChangedNodes(tr: ReadonlyTransaction | Transaction): {
|
|
19
|
-
node: Node;
|
|
20
|
-
pos: number;
|
|
21
|
-
}[];
|
|
22
11
|
export declare function nodesBetweenChanged(tr: Transaction | ReadonlyTransaction, f: ChangedFn, startPos?: number): void;
|
|
23
12
|
export declare function getNodesCount(node: Node): Record<string, number>;
|
|
24
13
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-core",
|
|
3
|
-
"version": "189.1.
|
|
3
|
+
"version": "189.1.1",
|
|
4
4
|
"description": "A package contains Atlassian editor core functionality",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@atlaskit/code": "^14.6.0",
|
|
54
54
|
"@atlaskit/date": "^0.10.0",
|
|
55
55
|
"@atlaskit/datetime-picker": "^12.10.0",
|
|
56
|
-
"@atlaskit/editor-common": "^76.
|
|
56
|
+
"@atlaskit/editor-common": "^76.17.0",
|
|
57
57
|
"@atlaskit/editor-json-transformer": "^8.10.0",
|
|
58
58
|
"@atlaskit/editor-markdown-transformer": "^5.2.5",
|
|
59
59
|
"@atlaskit/editor-palette": "1.5.1",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|
|
78
78
|
"@atlaskit/editor-plugin-floating-toolbar": "^0.7.0",
|
|
79
79
|
"@atlaskit/editor-plugin-focus": "^0.2.0",
|
|
80
|
+
"@atlaskit/editor-plugin-fragment": "^0.1.0",
|
|
80
81
|
"@atlaskit/editor-plugin-grid": "^0.3.0",
|
|
81
82
|
"@atlaskit/editor-plugin-guideline": "^0.5.0",
|
|
82
83
|
"@atlaskit/editor-plugin-help-dialog": "^0.2.0",
|
|
@@ -121,7 +122,7 @@
|
|
|
121
122
|
"@atlaskit/radio": "^5.6.0",
|
|
122
123
|
"@atlaskit/section-message": "^6.4.0",
|
|
123
124
|
"@atlaskit/select": "^16.7.0",
|
|
124
|
-
"@atlaskit/smart-card": "^26.
|
|
125
|
+
"@atlaskit/smart-card": "^26.40.0",
|
|
125
126
|
"@atlaskit/smart-user-picker": "^6.3.0",
|
|
126
127
|
"@atlaskit/spinner": "^15.6.0",
|
|
127
128
|
"@atlaskit/tabs": "^13.4.0",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _adfSchema = require("@atlaskit/adf-schema");
|
|
8
|
-
var _fragmentConsistency = require("./pm-plugins/fragment-consistency");
|
|
9
|
-
var fragmentMarkPlugin = function fragmentMarkPlugin() {
|
|
10
|
-
return {
|
|
11
|
-
name: 'fragmentPlugin',
|
|
12
|
-
marks: function marks() {
|
|
13
|
-
return [{
|
|
14
|
-
name: 'fragment',
|
|
15
|
-
mark: _adfSchema.fragment
|
|
16
|
-
}];
|
|
17
|
-
},
|
|
18
|
-
pmPlugins: function pmPlugins() {
|
|
19
|
-
return [{
|
|
20
|
-
name: 'fragmentMarkConsistency',
|
|
21
|
-
plugin: function plugin(_ref) {
|
|
22
|
-
var dispatch = _ref.dispatch;
|
|
23
|
-
return (0, _fragmentConsistency.createPlugin)(dispatch);
|
|
24
|
-
}
|
|
25
|
-
}];
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
var _default = exports.default = fragmentMarkPlugin;
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createPlugin = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
-
var _adfSchema = require("@atlaskit/adf-schema");
|
|
12
|
-
var _document = require("../../../utils/document");
|
|
13
|
-
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; }
|
|
14
|
-
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; }
|
|
15
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**
|
|
18
|
-
* This plugin ensures that certain nodes (such as tables, and various extension ones)
|
|
19
|
-
* have a unique `localId` attribute value for `fragment` marks.
|
|
20
|
-
* It also ensures the preservation of these IDs when nodes are being cut-and-pasted
|
|
21
|
-
* around the document.
|
|
22
|
-
*
|
|
23
|
-
* The implementation has been _heavily_ borrowed from
|
|
24
|
-
* - packages/editor/editor-core/src/plugins/table/pm-plugins/table-local-id.ts
|
|
25
|
-
*/
|
|
26
|
-
var pluginKey = new _state.PluginKey('fragmentMarkConsistencyPlugin');
|
|
27
|
-
var getNodesSupportingFragmentMark = function getNodesSupportingFragmentMark(schema) {
|
|
28
|
-
var _schema$nodes = schema.nodes,
|
|
29
|
-
table = _schema$nodes.table,
|
|
30
|
-
extension = _schema$nodes.extension,
|
|
31
|
-
bodiedExtension = _schema$nodes.bodiedExtension,
|
|
32
|
-
inlineExtension = _schema$nodes.inlineExtension;
|
|
33
|
-
return [table, extension, bodiedExtension, inlineExtension];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Ensures presence of `fragment` mark on certain node types and the uniqueness of their `localId` attributes
|
|
38
|
-
*/
|
|
39
|
-
var createPlugin = exports.createPlugin = function createPlugin(dispatch) {
|
|
40
|
-
return new _safePlugin.SafePlugin({
|
|
41
|
-
key: pluginKey,
|
|
42
|
-
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
43
|
-
var modified = false;
|
|
44
|
-
var tr = newState.tr;
|
|
45
|
-
var fragment = newState.schema.marks.fragment;
|
|
46
|
-
var supportedNodeTypes = getNodesSupportingFragmentMark(newState.schema);
|
|
47
|
-
var addedSupportedNodes = new Set();
|
|
48
|
-
var addedSupportedNodesPos = new Map();
|
|
49
|
-
var localIds = new Set();
|
|
50
|
-
transactions.forEach(function (transaction) {
|
|
51
|
-
if (!transaction.docChanged) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Don't interfere with cut as it clashes with fixTables & we don't need
|
|
56
|
-
// to handle any extra cut cases in this plugin
|
|
57
|
-
var uiEvent = transaction.getMeta('uiEvent');
|
|
58
|
-
if (uiEvent === 'cut') {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
var changedNodes = (0, _document.getChangedNodes)(transaction);
|
|
62
|
-
var _iterator = _createForOfIteratorHelper(changedNodes),
|
|
63
|
-
_step;
|
|
64
|
-
try {
|
|
65
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
66
|
-
var node = _step.value.node;
|
|
67
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
addedSupportedNodes.add(node);
|
|
71
|
-
}
|
|
72
|
-
} catch (err) {
|
|
73
|
-
_iterator.e(err);
|
|
74
|
-
} finally {
|
|
75
|
-
_iterator.f();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
if (!addedSupportedNodes.size) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Get existing fragment marks localIds on the page
|
|
83
|
-
newState.doc.descendants(function (node, pos) {
|
|
84
|
-
if (addedSupportedNodes.has(node)) {
|
|
85
|
-
addedSupportedNodesPos.set(node, pos);
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
var existingFragmentMark = node.marks.find(function (mark) {
|
|
92
|
-
return mark.type === fragment;
|
|
93
|
-
});
|
|
94
|
-
if (!existingFragmentMark) {
|
|
95
|
-
// continue traversing
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
localIds.add(existingFragmentMark.attrs.localId);
|
|
99
|
-
return true;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// If an added node has localId that collides with existing node, generate new localId
|
|
103
|
-
var _iterator2 = _createForOfIteratorHelper(addedSupportedNodes),
|
|
104
|
-
_step2;
|
|
105
|
-
try {
|
|
106
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
107
|
-
var node = _step2.value;
|
|
108
|
-
var pos = addedSupportedNodesPos.get(node);
|
|
109
|
-
if (pos === undefined) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
var existingFragmentMark = node.marks.find(function (mark) {
|
|
113
|
-
return mark.type === fragment;
|
|
114
|
-
});
|
|
115
|
-
if (!existingFragmentMark) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (localIds.has(existingFragmentMark.attrs.localId)) {
|
|
119
|
-
tr.setNodeMarkup(pos, undefined, node.attrs, node.marks.map(function (mark) {
|
|
120
|
-
if (mark.type !== fragment) {
|
|
121
|
-
return mark;
|
|
122
|
-
}
|
|
123
|
-
var fragmentMark = fragment.create(_objectSpread(_objectSpread({}, mark.attrs), {}, {
|
|
124
|
-
localId: _adfSchema.uuid.generate(),
|
|
125
|
-
name: null
|
|
126
|
-
}));
|
|
127
|
-
return fragmentMark;
|
|
128
|
-
}));
|
|
129
|
-
modified = true;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
} catch (err) {
|
|
133
|
-
_iterator2.e(err);
|
|
134
|
-
} finally {
|
|
135
|
-
_iterator2.f();
|
|
136
|
-
}
|
|
137
|
-
if (modified) {
|
|
138
|
-
return tr;
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { fragment } from '@atlaskit/adf-schema';
|
|
2
|
-
import { createPlugin as createFragmentMarkConsistencyPlugin } from './pm-plugins/fragment-consistency';
|
|
3
|
-
const fragmentMarkPlugin = () => ({
|
|
4
|
-
name: 'fragmentPlugin',
|
|
5
|
-
marks() {
|
|
6
|
-
return [{
|
|
7
|
-
name: 'fragment',
|
|
8
|
-
mark: fragment
|
|
9
|
-
}];
|
|
10
|
-
},
|
|
11
|
-
pmPlugins() {
|
|
12
|
-
return [{
|
|
13
|
-
name: 'fragmentMarkConsistency',
|
|
14
|
-
plugin: ({
|
|
15
|
-
dispatch
|
|
16
|
-
}) => createFragmentMarkConsistencyPlugin(dispatch)
|
|
17
|
-
}];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
export default fragmentMarkPlugin;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This plugin ensures that certain nodes (such as tables, and various extension ones)
|
|
3
|
-
* have a unique `localId` attribute value for `fragment` marks.
|
|
4
|
-
* It also ensures the preservation of these IDs when nodes are being cut-and-pasted
|
|
5
|
-
* around the document.
|
|
6
|
-
*
|
|
7
|
-
* The implementation has been _heavily_ borrowed from
|
|
8
|
-
* - packages/editor/editor-core/src/plugins/table/pm-plugins/table-local-id.ts
|
|
9
|
-
*/
|
|
10
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
11
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
12
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
13
|
-
import { getChangedNodes } from '../../../utils/document';
|
|
14
|
-
const pluginKey = new PluginKey('fragmentMarkConsistencyPlugin');
|
|
15
|
-
const getNodesSupportingFragmentMark = schema => {
|
|
16
|
-
const {
|
|
17
|
-
table,
|
|
18
|
-
extension,
|
|
19
|
-
bodiedExtension,
|
|
20
|
-
inlineExtension
|
|
21
|
-
} = schema.nodes;
|
|
22
|
-
return [table, extension, bodiedExtension, inlineExtension];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Ensures presence of `fragment` mark on certain node types and the uniqueness of their `localId` attributes
|
|
27
|
-
*/
|
|
28
|
-
export const createPlugin = dispatch => new SafePlugin({
|
|
29
|
-
key: pluginKey,
|
|
30
|
-
appendTransaction: (transactions, _oldState, newState) => {
|
|
31
|
-
let modified = false;
|
|
32
|
-
const tr = newState.tr;
|
|
33
|
-
const {
|
|
34
|
-
fragment
|
|
35
|
-
} = newState.schema.marks;
|
|
36
|
-
const supportedNodeTypes = getNodesSupportingFragmentMark(newState.schema);
|
|
37
|
-
const addedSupportedNodes = new Set();
|
|
38
|
-
const addedSupportedNodesPos = new Map();
|
|
39
|
-
const localIds = new Set();
|
|
40
|
-
transactions.forEach(transaction => {
|
|
41
|
-
if (!transaction.docChanged) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Don't interfere with cut as it clashes with fixTables & we don't need
|
|
46
|
-
// to handle any extra cut cases in this plugin
|
|
47
|
-
const uiEvent = transaction.getMeta('uiEvent');
|
|
48
|
-
if (uiEvent === 'cut') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const changedNodes = getChangedNodes(transaction);
|
|
52
|
-
for (const {
|
|
53
|
-
node
|
|
54
|
-
} of changedNodes) {
|
|
55
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
addedSupportedNodes.add(node);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
if (!addedSupportedNodes.size) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Get existing fragment marks localIds on the page
|
|
66
|
-
newState.doc.descendants((node, pos) => {
|
|
67
|
-
if (addedSupportedNodes.has(node)) {
|
|
68
|
-
addedSupportedNodesPos.set(node, pos);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
const existingFragmentMark = node.marks.find(mark => mark.type === fragment);
|
|
75
|
-
if (!existingFragmentMark) {
|
|
76
|
-
// continue traversing
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
localIds.add(existingFragmentMark.attrs.localId);
|
|
80
|
-
return true;
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// If an added node has localId that collides with existing node, generate new localId
|
|
84
|
-
for (const node of addedSupportedNodes) {
|
|
85
|
-
const pos = addedSupportedNodesPos.get(node);
|
|
86
|
-
if (pos === undefined) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const existingFragmentMark = node.marks.find(mark => mark.type === fragment);
|
|
90
|
-
if (!existingFragmentMark) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (localIds.has(existingFragmentMark.attrs.localId)) {
|
|
94
|
-
tr.setNodeMarkup(pos, undefined, node.attrs, node.marks.map(mark => {
|
|
95
|
-
if (mark.type !== fragment) {
|
|
96
|
-
return mark;
|
|
97
|
-
}
|
|
98
|
-
const fragmentMark = fragment.create({
|
|
99
|
-
...mark.attrs,
|
|
100
|
-
localId: uuid.generate(),
|
|
101
|
-
name: null
|
|
102
|
-
});
|
|
103
|
-
return fragmentMark;
|
|
104
|
-
}));
|
|
105
|
-
modified = true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (modified) {
|
|
109
|
-
return tr;
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { fragment } from '@atlaskit/adf-schema';
|
|
2
|
-
import { createPlugin as createFragmentMarkConsistencyPlugin } from './pm-plugins/fragment-consistency';
|
|
3
|
-
var fragmentMarkPlugin = function fragmentMarkPlugin() {
|
|
4
|
-
return {
|
|
5
|
-
name: 'fragmentPlugin',
|
|
6
|
-
marks: function marks() {
|
|
7
|
-
return [{
|
|
8
|
-
name: 'fragment',
|
|
9
|
-
mark: fragment
|
|
10
|
-
}];
|
|
11
|
-
},
|
|
12
|
-
pmPlugins: function pmPlugins() {
|
|
13
|
-
return [{
|
|
14
|
-
name: 'fragmentMarkConsistency',
|
|
15
|
-
plugin: function plugin(_ref) {
|
|
16
|
-
var dispatch = _ref.dispatch;
|
|
17
|
-
return createFragmentMarkConsistencyPlugin(dispatch);
|
|
18
|
-
}
|
|
19
|
-
}];
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export default fragmentMarkPlugin;
|
|
@@ -1,137 +0,0 @@
|
|
|
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
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
-
/**
|
|
8
|
-
* This plugin ensures that certain nodes (such as tables, and various extension ones)
|
|
9
|
-
* have a unique `localId` attribute value for `fragment` marks.
|
|
10
|
-
* It also ensures the preservation of these IDs when nodes are being cut-and-pasted
|
|
11
|
-
* around the document.
|
|
12
|
-
*
|
|
13
|
-
* The implementation has been _heavily_ borrowed from
|
|
14
|
-
* - packages/editor/editor-core/src/plugins/table/pm-plugins/table-local-id.ts
|
|
15
|
-
*/
|
|
16
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
17
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
18
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
19
|
-
import { getChangedNodes } from '../../../utils/document';
|
|
20
|
-
var pluginKey = new PluginKey('fragmentMarkConsistencyPlugin');
|
|
21
|
-
var getNodesSupportingFragmentMark = function getNodesSupportingFragmentMark(schema) {
|
|
22
|
-
var _schema$nodes = schema.nodes,
|
|
23
|
-
table = _schema$nodes.table,
|
|
24
|
-
extension = _schema$nodes.extension,
|
|
25
|
-
bodiedExtension = _schema$nodes.bodiedExtension,
|
|
26
|
-
inlineExtension = _schema$nodes.inlineExtension;
|
|
27
|
-
return [table, extension, bodiedExtension, inlineExtension];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Ensures presence of `fragment` mark on certain node types and the uniqueness of their `localId` attributes
|
|
32
|
-
*/
|
|
33
|
-
export var createPlugin = function createPlugin(dispatch) {
|
|
34
|
-
return new SafePlugin({
|
|
35
|
-
key: pluginKey,
|
|
36
|
-
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
37
|
-
var modified = false;
|
|
38
|
-
var tr = newState.tr;
|
|
39
|
-
var fragment = newState.schema.marks.fragment;
|
|
40
|
-
var supportedNodeTypes = getNodesSupportingFragmentMark(newState.schema);
|
|
41
|
-
var addedSupportedNodes = new Set();
|
|
42
|
-
var addedSupportedNodesPos = new Map();
|
|
43
|
-
var localIds = new Set();
|
|
44
|
-
transactions.forEach(function (transaction) {
|
|
45
|
-
if (!transaction.docChanged) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Don't interfere with cut as it clashes with fixTables & we don't need
|
|
50
|
-
// to handle any extra cut cases in this plugin
|
|
51
|
-
var uiEvent = transaction.getMeta('uiEvent');
|
|
52
|
-
if (uiEvent === 'cut') {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
var changedNodes = getChangedNodes(transaction);
|
|
56
|
-
var _iterator = _createForOfIteratorHelper(changedNodes),
|
|
57
|
-
_step;
|
|
58
|
-
try {
|
|
59
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
60
|
-
var node = _step.value.node;
|
|
61
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
addedSupportedNodes.add(node);
|
|
65
|
-
}
|
|
66
|
-
} catch (err) {
|
|
67
|
-
_iterator.e(err);
|
|
68
|
-
} finally {
|
|
69
|
-
_iterator.f();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (!addedSupportedNodes.size) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Get existing fragment marks localIds on the page
|
|
77
|
-
newState.doc.descendants(function (node, pos) {
|
|
78
|
-
if (addedSupportedNodes.has(node)) {
|
|
79
|
-
addedSupportedNodesPos.set(node, pos);
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
if (!supportedNodeTypes.includes(node.type)) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
var existingFragmentMark = node.marks.find(function (mark) {
|
|
86
|
-
return mark.type === fragment;
|
|
87
|
-
});
|
|
88
|
-
if (!existingFragmentMark) {
|
|
89
|
-
// continue traversing
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
localIds.add(existingFragmentMark.attrs.localId);
|
|
93
|
-
return true;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// If an added node has localId that collides with existing node, generate new localId
|
|
97
|
-
var _iterator2 = _createForOfIteratorHelper(addedSupportedNodes),
|
|
98
|
-
_step2;
|
|
99
|
-
try {
|
|
100
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
101
|
-
var node = _step2.value;
|
|
102
|
-
var pos = addedSupportedNodesPos.get(node);
|
|
103
|
-
if (pos === undefined) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
var existingFragmentMark = node.marks.find(function (mark) {
|
|
107
|
-
return mark.type === fragment;
|
|
108
|
-
});
|
|
109
|
-
if (!existingFragmentMark) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
if (localIds.has(existingFragmentMark.attrs.localId)) {
|
|
113
|
-
tr.setNodeMarkup(pos, undefined, node.attrs, node.marks.map(function (mark) {
|
|
114
|
-
if (mark.type !== fragment) {
|
|
115
|
-
return mark;
|
|
116
|
-
}
|
|
117
|
-
var fragmentMark = fragment.create(_objectSpread(_objectSpread({}, mark.attrs), {}, {
|
|
118
|
-
localId: uuid.generate(),
|
|
119
|
-
name: null
|
|
120
|
-
}));
|
|
121
|
-
return fragmentMark;
|
|
122
|
-
}));
|
|
123
|
-
modified = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} catch (err) {
|
|
127
|
-
_iterator2.e(err);
|
|
128
|
-
} finally {
|
|
129
|
-
_iterator2.f();
|
|
130
|
-
}
|
|
131
|
-
if (modified) {
|
|
132
|
-
return tr;
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This plugin ensures that certain nodes (such as tables, and various extension ones)
|
|
3
|
-
* have a unique `localId` attribute value for `fragment` marks.
|
|
4
|
-
* It also ensures the preservation of these IDs when nodes are being cut-and-pasted
|
|
5
|
-
* around the document.
|
|
6
|
-
*
|
|
7
|
-
* The implementation has been _heavily_ borrowed from
|
|
8
|
-
* - packages/editor/editor-core/src/plugins/table/pm-plugins/table-local-id.ts
|
|
9
|
-
*/
|
|
10
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
11
|
-
import type { Dispatch } from '../../../event-dispatcher';
|
|
12
|
-
/**
|
|
13
|
-
* Ensures presence of `fragment` mark on certain node types and the uniqueness of their `localId` attributes
|
|
14
|
-
*/
|
|
15
|
-
export declare const createPlugin: (dispatch: Dispatch) => SafePlugin<any>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This plugin ensures that certain nodes (such as tables, and various extension ones)
|
|
3
|
-
* have a unique `localId` attribute value for `fragment` marks.
|
|
4
|
-
* It also ensures the preservation of these IDs when nodes are being cut-and-pasted
|
|
5
|
-
* around the document.
|
|
6
|
-
*
|
|
7
|
-
* The implementation has been _heavily_ borrowed from
|
|
8
|
-
* - packages/editor/editor-core/src/plugins/table/pm-plugins/table-local-id.ts
|
|
9
|
-
*/
|
|
10
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
11
|
-
import type { Dispatch } from '../../../event-dispatcher';
|
|
12
|
-
/**
|
|
13
|
-
* Ensures presence of `fragment` mark on certain node types and the uniqueness of their `localId` attributes
|
|
14
|
-
*/
|
|
15
|
-
export declare const createPlugin: (dispatch: Dispatch) => SafePlugin<any>;
|