@atlaskit/editor-plugin-metrics 3.3.0 → 3.4.0
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 +19 -0
- package/dist/cjs/metricsPlugin.js +20 -11
- package/dist/cjs/pm-plugins/main.js +22 -99
- package/dist/cjs/pm-plugins/utils/analytics.js +21 -27
- package/dist/cjs/pm-plugins/utils/check-tr-actions/check-tr-action-type.js +90 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-content-moved.js +26 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-deleting-content.js +20 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-empty-line-added-or-deleted.js +29 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-list-type-node-changed.js +37 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-mark-changed.js +16 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-node-attribute-changed.js +103 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-status-changed.js +22 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-table-column-resized.js +60 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/tr-checks/check-text-input.js +23 -0
- package/dist/cjs/pm-plugins/utils/check-tr-actions/types.js +23 -0
- package/dist/cjs/pm-plugins/utils/get-new-plugin-state.js +103 -0
- package/dist/cjs/pm-plugins/utils/is-safe-insert.js +37 -0
- package/dist/cjs/pm-plugins/utils/should-skip-tr.js +52 -0
- package/dist/es2019/metricsPlugin.js +9 -1
- package/dist/es2019/pm-plugins/main.js +22 -109
- package/dist/es2019/pm-plugins/utils/analytics.js +10 -18
- package/dist/es2019/pm-plugins/utils/check-tr-actions/check-tr-action-type.js +81 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-content-moved.js +20 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-deleting-content.js +17 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-empty-line-added-or-deleted.js +26 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-list-type-node-changed.js +23 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-mark-changed.js +10 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-node-attribute-changed.js +71 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-status-changed.js +18 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-table-column-resized.js +53 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/tr-checks/check-text-input.js +20 -0
- package/dist/es2019/pm-plugins/utils/check-tr-actions/types.js +17 -0
- package/dist/es2019/pm-plugins/utils/get-new-plugin-state.js +101 -0
- package/dist/es2019/pm-plugins/utils/is-safe-insert.js +28 -0
- package/dist/es2019/pm-plugins/utils/should-skip-tr.js +38 -0
- package/dist/esm/metricsPlugin.js +20 -11
- package/dist/esm/pm-plugins/main.js +21 -98
- package/dist/esm/pm-plugins/utils/analytics.js +20 -26
- package/dist/esm/pm-plugins/utils/check-tr-actions/check-tr-action-type.js +83 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-content-moved.js +20 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-deleting-content.js +14 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-empty-line-added-or-deleted.js +23 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-list-type-node-changed.js +31 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-mark-changed.js +10 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-node-attribute-changed.js +96 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-status-changed.js +16 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-table-column-resized.js +54 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/tr-checks/check-text-input.js +17 -0
- package/dist/esm/pm-plugins/utils/check-tr-actions/types.js +17 -0
- package/dist/esm/pm-plugins/utils/get-new-plugin-state.js +96 -0
- package/dist/esm/pm-plugins/utils/is-safe-insert.js +30 -0
- package/dist/esm/pm-plugins/utils/should-skip-tr.js +46 -0
- package/dist/types/metricsPluginType.d.ts +2 -2
- package/dist/types/pm-plugins/main.d.ts +4 -1
- package/dist/types/pm-plugins/utils/analytics.d.ts +1 -7
- package/dist/types/pm-plugins/utils/check-tr-actions/check-tr-action-type.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-content-moved.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-deleting-content.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-empty-line-added-or-deleted.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-list-type-node-changed.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-mark-changed.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-node-attribute-changed.d.ts +4 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-status-changed.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-table-column-resized.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/tr-checks/check-text-input.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-actions/types.d.ts +44 -0
- package/dist/types/pm-plugins/utils/get-new-plugin-state.d.ts +56 -0
- package/dist/types/pm-plugins/utils/is-safe-insert.d.ts +3 -0
- package/dist/types/pm-plugins/utils/should-skip-tr.d.ts +2 -0
- package/dist/types-ts4.5/metricsPluginType.d.ts +2 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -1
- package/dist/types-ts4.5/pm-plugins/utils/analytics.d.ts +1 -7
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/check-tr-action-type.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-content-moved.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-deleting-content.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-empty-line-added-or-deleted.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-list-type-node-changed.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-mark-changed.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-node-attribute-changed.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-status-changed.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-table-column-resized.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/tr-checks/check-text-input.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-actions/types.d.ts +44 -0
- package/dist/types-ts4.5/pm-plugins/utils/get-new-plugin-state.d.ts +56 -0
- package/dist/types-ts4.5/pm-plugins/utils/is-safe-insert.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/should-skip-tr.d.ts +2 -0
- package/package.json +12 -6
- package/dist/cjs/pm-plugins/utils/check-tr-action-type.js +0 -312
- package/dist/es2019/pm-plugins/utils/check-tr-action-type.js +0 -271
- package/dist/esm/pm-plugins/utils/check-tr-action-type.js +0 -305
- package/dist/types/pm-plugins/utils/check-tr-action-type.d.ts +0 -38
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-action-type.d.ts +0 -38
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-metrics",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Metrics plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"module": "dist/esm/index.js",
|
|
19
19
|
"module:es2019": "dist/es2019/index.js",
|
|
20
20
|
"types": "dist/types/index.d.ts",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
">=4.5 <4.9": {
|
|
23
|
+
"*": [
|
|
24
|
+
"dist/types-ts4.5/*",
|
|
25
|
+
"dist/types-ts4.5/index.d.ts"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
21
29
|
"sideEffects": false,
|
|
22
30
|
"atlaskit:src": "src/index.ts",
|
|
23
31
|
"af:exports": {
|
|
@@ -25,20 +33,18 @@
|
|
|
25
33
|
},
|
|
26
34
|
"dependencies": {
|
|
27
35
|
"@atlaskit/adf-schema": "^47.6.0",
|
|
28
|
-
"@atlaskit/editor-common": "^
|
|
36
|
+
"@atlaskit/editor-common": "^101.1.0",
|
|
29
37
|
"@atlaskit/editor-plugin-analytics": "^2.1.0",
|
|
30
|
-
"@atlaskit/editor-plugin-block-controls": "^3.2.0",
|
|
31
38
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
32
39
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
33
40
|
"@babel/runtime": "^7.0.0",
|
|
34
41
|
"bind-event-listener": "^3.0.0"
|
|
35
42
|
},
|
|
36
43
|
"peerDependencies": {
|
|
37
|
-
"react": "^18.2.0"
|
|
44
|
+
"react": "^18.2.0",
|
|
45
|
+
"react-dom": "^18.2.0"
|
|
38
46
|
},
|
|
39
47
|
"devDependencies": {
|
|
40
|
-
"@testing-library/react": "^13.4.0",
|
|
41
|
-
"react-dom": "^18.2.0",
|
|
42
48
|
"typescript": "~5.4.2"
|
|
43
49
|
},
|
|
44
50
|
"techstack": {
|
|
@@ -1,312 +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.shouldSkipTr = exports.checkTrActionType = exports.ActionType = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _steps = require("@atlaskit/adf-schema/steps");
|
|
11
|
-
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
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; } } }; }
|
|
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; } }
|
|
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; }
|
|
15
|
-
var ActionType = exports.ActionType = /*#__PURE__*/function (ActionType) {
|
|
16
|
-
ActionType["TEXT_INPUT"] = "textInput";
|
|
17
|
-
ActionType["EMPTY_LINE_ADDED_OR_DELETED"] = "emptyLineAddedOrDeleted";
|
|
18
|
-
ActionType["INSERTED_FROM_TYPE_AHEAD"] = "insertedFromTypeAhead";
|
|
19
|
-
ActionType["INSERTING_NEW_LIST_TYPE_NODE"] = "insertingNewListTypeNode";
|
|
20
|
-
ActionType["UPDATING_NEW_LIST_TYPE_ITEM"] = "updatingNewListItem";
|
|
21
|
-
ActionType["ADDING_LINK"] = "addingLink";
|
|
22
|
-
ActionType["UPDATING_STATUS"] = "updatingStatus";
|
|
23
|
-
ActionType["CHANGING_MARK"] = "changingMark";
|
|
24
|
-
ActionType["CHANGING_ATTRS"] = "changingAttrs";
|
|
25
|
-
return ActionType;
|
|
26
|
-
}({});
|
|
27
|
-
var isTextInput = function isTextInput(step) {
|
|
28
|
-
var _ref = step,
|
|
29
|
-
content = _ref.slice.content,
|
|
30
|
-
from = _ref.from,
|
|
31
|
-
to = _ref.to;
|
|
32
|
-
var node = content.firstChild;
|
|
33
|
-
var isAddingCharacter = from === to && content.childCount === 1 && !!node && !!node.text && node.text.length === 1;
|
|
34
|
-
var isDeletingCharacter = to - from === 1 && content.childCount === 0;
|
|
35
|
-
return isAddingCharacter || isDeletingCharacter;
|
|
36
|
-
};
|
|
37
|
-
var isEmptyLineAddedOrDeleted = function isEmptyLineAddedOrDeleted(step) {
|
|
38
|
-
var _ref2 = step,
|
|
39
|
-
content = _ref2.slice.content,
|
|
40
|
-
from = _ref2.from,
|
|
41
|
-
to = _ref2.to;
|
|
42
|
-
var isEmptyLineDeleted = to - from === 2 && content.size === 0;
|
|
43
|
-
if (isEmptyLineDeleted) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
var isEmptyLineAdded = false;
|
|
47
|
-
content.forEach(function (node) {
|
|
48
|
-
isEmptyLineAdded = node.type.name === 'paragraph' && node.content.size === 0;
|
|
49
|
-
});
|
|
50
|
-
return isEmptyLineAdded;
|
|
51
|
-
};
|
|
52
|
-
var compareAttributes = function compareAttributes(prevAttr, newAttr) {
|
|
53
|
-
var allKeys = new Set([].concat((0, _toConsumableArray2.default)(Object.keys(prevAttr)), (0, _toConsumableArray2.default)(Object.keys(newAttr))));
|
|
54
|
-
var _iterator = _createForOfIteratorHelper(allKeys),
|
|
55
|
-
_step;
|
|
56
|
-
try {
|
|
57
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
58
|
-
var key = _step.value;
|
|
59
|
-
var prevValue = prevAttr[key];
|
|
60
|
-
var newValue = newAttr[key];
|
|
61
|
-
if (prevValue !== newValue) {
|
|
62
|
-
return key;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} catch (err) {
|
|
66
|
-
_iterator.e(err);
|
|
67
|
-
} finally {
|
|
68
|
-
_iterator.f();
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
};
|
|
72
|
-
var compareMarks = function compareMarks(prevMarks, newMarks) {
|
|
73
|
-
if (!prevMarks && !newMarks) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
var previousMarksArr = new Map(prevMarks.map(function (mark) {
|
|
77
|
-
return [mark.type.name, mark.attrs];
|
|
78
|
-
}));
|
|
79
|
-
var newMarksArr = new Map(newMarks.map(function (mark) {
|
|
80
|
-
return [mark.type.name, mark.attrs];
|
|
81
|
-
}));
|
|
82
|
-
var allMarks = new Set([].concat((0, _toConsumableArray2.default)(previousMarksArr.keys()), (0, _toConsumableArray2.default)(newMarksArr.keys())));
|
|
83
|
-
var _iterator2 = _createForOfIteratorHelper(allMarks),
|
|
84
|
-
_step2;
|
|
85
|
-
try {
|
|
86
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
87
|
-
var key = _step2.value;
|
|
88
|
-
var previousValue = previousMarksArr.get(key);
|
|
89
|
-
var newValue = newMarksArr.get(key);
|
|
90
|
-
if (JSON.stringify(previousValue) !== JSON.stringify(newValue)) {
|
|
91
|
-
return key;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} catch (err) {
|
|
95
|
-
_iterator2.e(err);
|
|
96
|
-
} finally {
|
|
97
|
-
_iterator2.f();
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
100
|
-
};
|
|
101
|
-
var detectNodeAttributeChange = function detectNodeAttributeChange(tr, step) {
|
|
102
|
-
var from = step.from,
|
|
103
|
-
slice = step.slice,
|
|
104
|
-
to = step.to;
|
|
105
|
-
var oldNode = tr.docs[0].nodeAt(from);
|
|
106
|
-
var newNode = slice.content.firstChild;
|
|
107
|
-
if (!oldNode || !newNode) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
var changedAttr = compareAttributes(oldNode.attrs, newNode.attrs);
|
|
111
|
-
if (changedAttr) {
|
|
112
|
-
return {
|
|
113
|
-
attr: changedAttr,
|
|
114
|
-
from: from,
|
|
115
|
-
to: to
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
var changedMarks = compareMarks(oldNode.marks, newNode.marks);
|
|
119
|
-
if (changedMarks) {
|
|
120
|
-
return {
|
|
121
|
-
attr: changedMarks,
|
|
122
|
-
from: from,
|
|
123
|
-
to: to
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return undefined;
|
|
127
|
-
};
|
|
128
|
-
var isUpdatingListTypeNode = function isUpdatingListTypeNode(step) {
|
|
129
|
-
var slice = step.slice;
|
|
130
|
-
var childCount = slice.content.childCount;
|
|
131
|
-
if (childCount < 1) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
var _iterator3 = _createForOfIteratorHelper(slice.content.content),
|
|
135
|
-
_step3;
|
|
136
|
-
try {
|
|
137
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
138
|
-
var node = _step3.value;
|
|
139
|
-
var isListTypeNode = ['decisionList', 'decisionItem', 'bulletList', 'listItem', 'orderedList', 'taskList', 'taskItem'].includes(node.type.name);
|
|
140
|
-
if (isListTypeNode) {
|
|
141
|
-
return childCount === 1 ? ActionType.INSERTING_NEW_LIST_TYPE_NODE : ActionType.UPDATING_NEW_LIST_TYPE_ITEM;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
} catch (err) {
|
|
145
|
-
_iterator3.e(err);
|
|
146
|
-
} finally {
|
|
147
|
-
_iterator3.f();
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
};
|
|
151
|
-
var isUpdatingStatus = function isUpdatingStatus(step) {
|
|
152
|
-
var slice = step.slice;
|
|
153
|
-
var firstChild = slice.content.firstChild;
|
|
154
|
-
if (!firstChild) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
return firstChild.type.name === 'status' && firstChild.attrs.localId;
|
|
158
|
-
};
|
|
159
|
-
var isAddingLink = function isAddingLink(tr) {
|
|
160
|
-
var hasLinkStep = tr.steps.some(function (step) {
|
|
161
|
-
return step instanceof _steps.LinkMetaStep;
|
|
162
|
-
});
|
|
163
|
-
var hasReplaceStep = tr.steps.some(function (step) {
|
|
164
|
-
return step instanceof _transform.ReplaceStep;
|
|
165
|
-
});
|
|
166
|
-
return hasLinkStep && !hasReplaceStep;
|
|
167
|
-
};
|
|
168
|
-
var isTypeAheadRelatedTr = function isTypeAheadRelatedTr(tr) {
|
|
169
|
-
var _tr$getMeta;
|
|
170
|
-
if (((_tr$getMeta = tr.getMeta('typeAheadPlugin$')) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.action) === 'INSERT_RAW_QUERY') {
|
|
171
|
-
return 'INSERT_RAW_QUERY';
|
|
172
|
-
}
|
|
173
|
-
if (!tr.getMeta('appendedTransaction')) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
var insertTypeAheadStep = tr.steps.find(function (step) {
|
|
177
|
-
return step instanceof _steps.InsertTypeAheadStep;
|
|
178
|
-
});
|
|
179
|
-
var replaceStep = tr.steps.find(function (step) {
|
|
180
|
-
return step instanceof _transform.ReplaceStep;
|
|
181
|
-
});
|
|
182
|
-
if (!insertTypeAheadStep || !replaceStep) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
return insertTypeAheadStep instanceof _steps.InsertTypeAheadStep && insertTypeAheadStep.stage;
|
|
186
|
-
};
|
|
187
|
-
var shouldSkipTr = exports.shouldSkipTr = function shouldSkipTr(tr) {
|
|
188
|
-
var resolvingLink = isAddingLink(tr);
|
|
189
|
-
if (resolvingLink) {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
var typeAheadRelatedTr = isTypeAheadRelatedTr(tr);
|
|
193
|
-
if (typeAheadRelatedTr) {
|
|
194
|
-
return typeAheadRelatedTr !== 'INSERTING_ITEM';
|
|
195
|
-
} else {
|
|
196
|
-
return tr.getMeta('appendedTransaction');
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
var isResizingColumns = function isResizingColumns(tr) {
|
|
200
|
-
var COL_WIDTH_ATTR = 'colwidth';
|
|
201
|
-
var steps = tr.steps;
|
|
202
|
-
var resizingColumnStep = steps.find(function (step) {
|
|
203
|
-
return step instanceof _transform.AttrStep || step instanceof _steps.BatchAttrsStep;
|
|
204
|
-
});
|
|
205
|
-
if (!resizingColumnStep) {
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
var pos;
|
|
209
|
-
|
|
210
|
-
// BatchAttrsStep is used for resizing columns in tables
|
|
211
|
-
if (resizingColumnStep instanceof _steps.BatchAttrsStep) {
|
|
212
|
-
var _resizingColumnStep$d = resizingColumnStep.data[0],
|
|
213
|
-
attrs = _resizingColumnStep$d.attrs,
|
|
214
|
-
nodeType = _resizingColumnStep$d.nodeType,
|
|
215
|
-
position = _resizingColumnStep$d.position;
|
|
216
|
-
if (['tableHeader', 'tableCell'].includes(nodeType) && attrs !== null && attrs !== void 0 && attrs[COL_WIDTH_ATTR]) {
|
|
217
|
-
pos = position;
|
|
218
|
-
}
|
|
219
|
-
} else if (resizingColumnStep instanceof _transform.AttrStep && resizingColumnStep.attr === COL_WIDTH_ATTR) {
|
|
220
|
-
pos = resizingColumnStep.pos;
|
|
221
|
-
}
|
|
222
|
-
if (!pos) {
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
var $pos = tr.doc.resolve(pos);
|
|
226
|
-
var blockRange = $pos.blockRange();
|
|
227
|
-
if (!blockRange) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
var from = blockRange.start;
|
|
231
|
-
var to = from + blockRange.parent.content.size;
|
|
232
|
-
return {
|
|
233
|
-
attr: COL_WIDTH_ATTR,
|
|
234
|
-
from: from,
|
|
235
|
-
to: to
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
var checkTrActionType = exports.checkTrActionType = function checkTrActionType(tr) {
|
|
239
|
-
if (tr.getMeta('input_rule_plugin_transaction')) {
|
|
240
|
-
return {
|
|
241
|
-
type: ActionType.INSERTING_NEW_LIST_TYPE_NODE
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
var stepsLength = tr.steps.length;
|
|
245
|
-
if (stepsLength <= 0) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
if (isAddingLink(tr)) {
|
|
249
|
-
return {
|
|
250
|
-
type: ActionType.ADDING_LINK
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
var isResizingCol = isResizingColumns(tr);
|
|
254
|
-
if (isResizingCol) {
|
|
255
|
-
return {
|
|
256
|
-
type: ActionType.CHANGING_ATTRS,
|
|
257
|
-
extraData: isResizingCol
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
var _tr$steps = (0, _slicedToArray2.default)(tr.steps, 1),
|
|
261
|
-
firstStep = _tr$steps[0];
|
|
262
|
-
var isReplaceStep = firstStep instanceof _transform.ReplaceStep;
|
|
263
|
-
var isReplaceAroundStep = firstStep instanceof _transform.ReplaceAroundStep;
|
|
264
|
-
if (firstStep instanceof _transform.AddMarkStep || firstStep instanceof _transform.RemoveMarkStep) {
|
|
265
|
-
return {
|
|
266
|
-
type: ActionType.CHANGING_MARK,
|
|
267
|
-
extraData: {
|
|
268
|
-
markType: firstStep.mark.type.name,
|
|
269
|
-
from: firstStep.from,
|
|
270
|
-
to: firstStep.to
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
if (!isReplaceStep && !isReplaceAroundStep) {
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
|
-
if (isReplaceStep) {
|
|
278
|
-
if (isTextInput(firstStep)) {
|
|
279
|
-
return {
|
|
280
|
-
type: ActionType.TEXT_INPUT
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
if (isEmptyLineAddedOrDeleted(firstStep)) {
|
|
284
|
-
return {
|
|
285
|
-
type: ActionType.EMPTY_LINE_ADDED_OR_DELETED
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
var statusId = isUpdatingStatus(firstStep);
|
|
289
|
-
if (statusId) {
|
|
290
|
-
return {
|
|
291
|
-
type: ActionType.UPDATING_STATUS,
|
|
292
|
-
extraData: {
|
|
293
|
-
statusId: statusId
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
var updatingListTypeNode = isUpdatingListTypeNode(firstStep);
|
|
299
|
-
if (updatingListTypeNode) {
|
|
300
|
-
return {
|
|
301
|
-
type: updatingListTypeNode
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
var nodeAttributeChange = detectNodeAttributeChange(tr, firstStep);
|
|
305
|
-
if (nodeAttributeChange) {
|
|
306
|
-
return {
|
|
307
|
-
type: ActionType.CHANGING_ATTRS,
|
|
308
|
-
extraData: nodeAttributeChange
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
return undefined;
|
|
312
|
-
};
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { BatchAttrsStep, InsertTypeAheadStep, LinkMetaStep } from '@atlaskit/adf-schema/steps';
|
|
2
|
-
import { AddMarkStep, AttrStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
-
export let ActionType = /*#__PURE__*/function (ActionType) {
|
|
4
|
-
ActionType["TEXT_INPUT"] = "textInput";
|
|
5
|
-
ActionType["EMPTY_LINE_ADDED_OR_DELETED"] = "emptyLineAddedOrDeleted";
|
|
6
|
-
ActionType["INSERTED_FROM_TYPE_AHEAD"] = "insertedFromTypeAhead";
|
|
7
|
-
ActionType["INSERTING_NEW_LIST_TYPE_NODE"] = "insertingNewListTypeNode";
|
|
8
|
-
ActionType["UPDATING_NEW_LIST_TYPE_ITEM"] = "updatingNewListItem";
|
|
9
|
-
ActionType["ADDING_LINK"] = "addingLink";
|
|
10
|
-
ActionType["UPDATING_STATUS"] = "updatingStatus";
|
|
11
|
-
ActionType["CHANGING_MARK"] = "changingMark";
|
|
12
|
-
ActionType["CHANGING_ATTRS"] = "changingAttrs";
|
|
13
|
-
return ActionType;
|
|
14
|
-
}({});
|
|
15
|
-
const isTextInput = step => {
|
|
16
|
-
const {
|
|
17
|
-
slice: {
|
|
18
|
-
content
|
|
19
|
-
},
|
|
20
|
-
from,
|
|
21
|
-
to
|
|
22
|
-
} = step;
|
|
23
|
-
const node = content.firstChild;
|
|
24
|
-
const isAddingCharacter = from === to && content.childCount === 1 && !!node && !!node.text && node.text.length === 1;
|
|
25
|
-
const isDeletingCharacter = to - from === 1 && content.childCount === 0;
|
|
26
|
-
return isAddingCharacter || isDeletingCharacter;
|
|
27
|
-
};
|
|
28
|
-
const isEmptyLineAddedOrDeleted = step => {
|
|
29
|
-
const {
|
|
30
|
-
slice: {
|
|
31
|
-
content
|
|
32
|
-
},
|
|
33
|
-
from,
|
|
34
|
-
to
|
|
35
|
-
} = step;
|
|
36
|
-
const isEmptyLineDeleted = to - from === 2 && content.size === 0;
|
|
37
|
-
if (isEmptyLineDeleted) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
let isEmptyLineAdded = false;
|
|
41
|
-
content.forEach(node => {
|
|
42
|
-
isEmptyLineAdded = node.type.name === 'paragraph' && node.content.size === 0;
|
|
43
|
-
});
|
|
44
|
-
return isEmptyLineAdded;
|
|
45
|
-
};
|
|
46
|
-
const compareAttributes = (prevAttr, newAttr) => {
|
|
47
|
-
const allKeys = new Set([...Object.keys(prevAttr), ...Object.keys(newAttr)]);
|
|
48
|
-
for (const key of allKeys) {
|
|
49
|
-
const prevValue = prevAttr[key];
|
|
50
|
-
const newValue = newAttr[key];
|
|
51
|
-
if (prevValue !== newValue) {
|
|
52
|
-
return key;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
};
|
|
57
|
-
const compareMarks = (prevMarks, newMarks) => {
|
|
58
|
-
if (!prevMarks && !newMarks) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
const previousMarksArr = new Map(prevMarks.map(mark => [mark.type.name, mark.attrs]));
|
|
62
|
-
const newMarksArr = new Map(newMarks.map(mark => [mark.type.name, mark.attrs]));
|
|
63
|
-
const allMarks = new Set([...previousMarksArr.keys(), ...newMarksArr.keys()]);
|
|
64
|
-
for (const key of allMarks) {
|
|
65
|
-
const previousValue = previousMarksArr.get(key);
|
|
66
|
-
const newValue = newMarksArr.get(key);
|
|
67
|
-
if (JSON.stringify(previousValue) !== JSON.stringify(newValue)) {
|
|
68
|
-
return key;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return undefined;
|
|
72
|
-
};
|
|
73
|
-
const detectNodeAttributeChange = (tr, step) => {
|
|
74
|
-
const {
|
|
75
|
-
from,
|
|
76
|
-
slice,
|
|
77
|
-
to
|
|
78
|
-
} = step;
|
|
79
|
-
const oldNode = tr.docs[0].nodeAt(from);
|
|
80
|
-
const newNode = slice.content.firstChild;
|
|
81
|
-
if (!oldNode || !newNode) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const changedAttr = compareAttributes(oldNode.attrs, newNode.attrs);
|
|
85
|
-
if (changedAttr) {
|
|
86
|
-
return {
|
|
87
|
-
attr: changedAttr,
|
|
88
|
-
from,
|
|
89
|
-
to
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const changedMarks = compareMarks(oldNode.marks, newNode.marks);
|
|
93
|
-
if (changedMarks) {
|
|
94
|
-
return {
|
|
95
|
-
attr: changedMarks,
|
|
96
|
-
from,
|
|
97
|
-
to
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return undefined;
|
|
101
|
-
};
|
|
102
|
-
const isUpdatingListTypeNode = step => {
|
|
103
|
-
const {
|
|
104
|
-
slice
|
|
105
|
-
} = step;
|
|
106
|
-
const childCount = slice.content.childCount;
|
|
107
|
-
if (childCount < 1) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
for (const node of slice.content.content) {
|
|
111
|
-
const isListTypeNode = ['decisionList', 'decisionItem', 'bulletList', 'listItem', 'orderedList', 'taskList', 'taskItem'].includes(node.type.name);
|
|
112
|
-
if (isListTypeNode) {
|
|
113
|
-
return childCount === 1 ? ActionType.INSERTING_NEW_LIST_TYPE_NODE : ActionType.UPDATING_NEW_LIST_TYPE_ITEM;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
};
|
|
118
|
-
const isUpdatingStatus = step => {
|
|
119
|
-
const {
|
|
120
|
-
slice
|
|
121
|
-
} = step;
|
|
122
|
-
const firstChild = slice.content.firstChild;
|
|
123
|
-
if (!firstChild) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return firstChild.type.name === 'status' && firstChild.attrs.localId;
|
|
127
|
-
};
|
|
128
|
-
const isAddingLink = tr => {
|
|
129
|
-
const hasLinkStep = tr.steps.some(step => step instanceof LinkMetaStep);
|
|
130
|
-
const hasReplaceStep = tr.steps.some(step => step instanceof ReplaceStep);
|
|
131
|
-
return hasLinkStep && !hasReplaceStep;
|
|
132
|
-
};
|
|
133
|
-
const isTypeAheadRelatedTr = tr => {
|
|
134
|
-
var _tr$getMeta;
|
|
135
|
-
if (((_tr$getMeta = tr.getMeta('typeAheadPlugin$')) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.action) === 'INSERT_RAW_QUERY') {
|
|
136
|
-
return 'INSERT_RAW_QUERY';
|
|
137
|
-
}
|
|
138
|
-
if (!tr.getMeta('appendedTransaction')) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
const insertTypeAheadStep = tr.steps.find(step => step instanceof InsertTypeAheadStep);
|
|
142
|
-
const replaceStep = tr.steps.find(step => step instanceof ReplaceStep);
|
|
143
|
-
if (!insertTypeAheadStep || !replaceStep) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
return insertTypeAheadStep instanceof InsertTypeAheadStep && insertTypeAheadStep.stage;
|
|
147
|
-
};
|
|
148
|
-
export const shouldSkipTr = tr => {
|
|
149
|
-
const resolvingLink = isAddingLink(tr);
|
|
150
|
-
if (resolvingLink) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
const typeAheadRelatedTr = isTypeAheadRelatedTr(tr);
|
|
154
|
-
if (typeAheadRelatedTr) {
|
|
155
|
-
return typeAheadRelatedTr !== 'INSERTING_ITEM';
|
|
156
|
-
} else {
|
|
157
|
-
return tr.getMeta('appendedTransaction');
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const isResizingColumns = tr => {
|
|
161
|
-
const COL_WIDTH_ATTR = 'colwidth';
|
|
162
|
-
const steps = tr.steps;
|
|
163
|
-
const resizingColumnStep = steps.find(step => step instanceof AttrStep || step instanceof BatchAttrsStep);
|
|
164
|
-
if (!resizingColumnStep) {
|
|
165
|
-
return undefined;
|
|
166
|
-
}
|
|
167
|
-
let pos;
|
|
168
|
-
|
|
169
|
-
// BatchAttrsStep is used for resizing columns in tables
|
|
170
|
-
if (resizingColumnStep instanceof BatchAttrsStep) {
|
|
171
|
-
const {
|
|
172
|
-
attrs,
|
|
173
|
-
nodeType,
|
|
174
|
-
position
|
|
175
|
-
} = resizingColumnStep.data[0];
|
|
176
|
-
if (['tableHeader', 'tableCell'].includes(nodeType) && attrs !== null && attrs !== void 0 && attrs[COL_WIDTH_ATTR]) {
|
|
177
|
-
pos = position;
|
|
178
|
-
}
|
|
179
|
-
} else if (resizingColumnStep instanceof AttrStep && resizingColumnStep.attr === COL_WIDTH_ATTR) {
|
|
180
|
-
pos = resizingColumnStep.pos;
|
|
181
|
-
}
|
|
182
|
-
if (!pos) {
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
|
-
const $pos = tr.doc.resolve(pos);
|
|
186
|
-
const blockRange = $pos.blockRange();
|
|
187
|
-
if (!blockRange) {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
const from = blockRange.start;
|
|
191
|
-
const to = from + blockRange.parent.content.size;
|
|
192
|
-
return {
|
|
193
|
-
attr: COL_WIDTH_ATTR,
|
|
194
|
-
from,
|
|
195
|
-
to
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
export const checkTrActionType = tr => {
|
|
199
|
-
if (tr.getMeta('input_rule_plugin_transaction')) {
|
|
200
|
-
return {
|
|
201
|
-
type: ActionType.INSERTING_NEW_LIST_TYPE_NODE
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
const stepsLength = tr.steps.length;
|
|
205
|
-
if (stepsLength <= 0) {
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
if (isAddingLink(tr)) {
|
|
209
|
-
return {
|
|
210
|
-
type: ActionType.ADDING_LINK
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const isResizingCol = isResizingColumns(tr);
|
|
214
|
-
if (isResizingCol) {
|
|
215
|
-
return {
|
|
216
|
-
type: ActionType.CHANGING_ATTRS,
|
|
217
|
-
extraData: isResizingCol
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
const [firstStep] = tr.steps;
|
|
221
|
-
const isReplaceStep = firstStep instanceof ReplaceStep;
|
|
222
|
-
const isReplaceAroundStep = firstStep instanceof ReplaceAroundStep;
|
|
223
|
-
if (firstStep instanceof AddMarkStep || firstStep instanceof RemoveMarkStep) {
|
|
224
|
-
return {
|
|
225
|
-
type: ActionType.CHANGING_MARK,
|
|
226
|
-
extraData: {
|
|
227
|
-
markType: firstStep.mark.type.name,
|
|
228
|
-
from: firstStep.from,
|
|
229
|
-
to: firstStep.to
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (!isReplaceStep && !isReplaceAroundStep) {
|
|
234
|
-
return undefined;
|
|
235
|
-
}
|
|
236
|
-
if (isReplaceStep) {
|
|
237
|
-
if (isTextInput(firstStep)) {
|
|
238
|
-
return {
|
|
239
|
-
type: ActionType.TEXT_INPUT
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (isEmptyLineAddedOrDeleted(firstStep)) {
|
|
243
|
-
return {
|
|
244
|
-
type: ActionType.EMPTY_LINE_ADDED_OR_DELETED
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
const statusId = isUpdatingStatus(firstStep);
|
|
248
|
-
if (statusId) {
|
|
249
|
-
return {
|
|
250
|
-
type: ActionType.UPDATING_STATUS,
|
|
251
|
-
extraData: {
|
|
252
|
-
statusId
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const updatingListTypeNode = isUpdatingListTypeNode(firstStep);
|
|
258
|
-
if (updatingListTypeNode) {
|
|
259
|
-
return {
|
|
260
|
-
type: updatingListTypeNode
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
const nodeAttributeChange = detectNodeAttributeChange(tr, firstStep);
|
|
264
|
-
if (nodeAttributeChange) {
|
|
265
|
-
return {
|
|
266
|
-
type: ActionType.CHANGING_ATTRS,
|
|
267
|
-
extraData: nodeAttributeChange
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
return undefined;
|
|
271
|
-
};
|