@atlaskit/editor-plugin-list 1.0.0 → 1.1.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 +6 -0
- package/dist/cjs/actions/outdent-list-items-selected.js +1 -3
- package/dist/cjs/commands/indent-list.js +12 -14
- package/dist/cjs/commands/index.js +26 -27
- package/dist/cjs/commands/outdent-list.js +13 -14
- package/dist/cjs/plugin.js +8 -4
- package/dist/cjs/pm-plugins/keymap.js +4 -4
- package/dist/cjs/utils/selection.js +14 -14
- package/dist/es2019/actions/outdent-list-items-selected.js +1 -3
- package/dist/es2019/commands/indent-list.js +13 -14
- package/dist/es2019/commands/index.js +19 -23
- package/dist/es2019/commands/outdent-list.js +14 -14
- package/dist/es2019/plugin.js +6 -4
- package/dist/es2019/pm-plugins/keymap.js +5 -5
- package/dist/es2019/utils/selection.js +12 -12
- package/dist/esm/actions/outdent-list-items-selected.js +1 -3
- package/dist/esm/commands/indent-list.js +12 -14
- package/dist/esm/commands/index.js +26 -27
- package/dist/esm/commands/outdent-list.js +13 -14
- package/dist/esm/plugin.js +9 -5
- package/dist/esm/pm-plugins/keymap.js +5 -5
- package/dist/esm/utils/selection.js +14 -14
- package/dist/types/actions/outdent-list-items-selected.d.ts +2 -2
- package/dist/types/commands/indent-list.d.ts +2 -2
- package/dist/types/commands/index.d.ts +4 -5
- package/dist/types/commands/outdent-list.d.ts +2 -2
- package/dist/types/types.d.ts +12 -10
- package/dist/types/utils/selection.d.ts +4 -4
- package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +2 -2
- package/dist/types-ts4.5/commands/indent-list.d.ts +2 -2
- package/dist/types-ts4.5/commands/index.d.ts +4 -5
- package/dist/types-ts4.5/commands/outdent-list.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +12 -10
- package/dist/types-ts4.5/utils/selection.d.ts +4 -4
- package/package.json +2 -2
- package/report.api.md +11 -16
- package/tmp/api-report-tmp.d.ts +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-list
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`4795a87a349`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4795a87a349) - Migrating some actions of `editor-plugin-list` to commands. Adding sharedState for `editor-plugin-text-formatting`.
|
|
8
|
+
|
|
3
9
|
## 1.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
|
@@ -18,7 +18,7 @@ var _find = require("../utils/find");
|
|
|
18
18
|
var _selection2 = require("../utils/selection");
|
|
19
19
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
var outdentListItemsSelected = function outdentListItemsSelected(tr,
|
|
21
|
+
var outdentListItemsSelected = function outdentListItemsSelected(tr, featureFlags) {
|
|
22
22
|
var originalSelection = tr.selection;
|
|
23
23
|
var normalizedSelection = (0, _lists.normalizeListItemsSelection)({
|
|
24
24
|
selection: tr.selection,
|
|
@@ -53,7 +53,6 @@ var outdentListItemsSelected = function outdentListItemsSelected(tr, state, feat
|
|
|
53
53
|
extractListItemsRangeFromList({
|
|
54
54
|
tr: tr,
|
|
55
55
|
range: mappedRange,
|
|
56
|
-
state: state,
|
|
57
56
|
featureFlags: featureFlags
|
|
58
57
|
});
|
|
59
58
|
hasNormalizedToPositionLiftedOut = hasNormalizedToPositionLiftedOut || oldTo >= range.from && oldTo < range.to;
|
|
@@ -176,7 +175,6 @@ var outdentRangeToParentList = function outdentRangeToParentList(_ref2) {
|
|
|
176
175
|
var extractListItemsRangeFromList = function extractListItemsRangeFromList(_ref3) {
|
|
177
176
|
var tr = _ref3.tr,
|
|
178
177
|
range = _ref3.range,
|
|
179
|
-
state = _ref3.state,
|
|
180
178
|
featureFlags = _ref3.featureFlags;
|
|
181
179
|
var list = range.parent;
|
|
182
180
|
var $start = tr.doc.resolve(range.start);
|
|
@@ -8,6 +8,7 @@ exports.indentList = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _lists = require("@atlaskit/editor-common/lists");
|
|
11
|
+
var _preset = require("@atlaskit/editor-common/preset");
|
|
11
12
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
13
|
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
13
14
|
var _indentListItemsSelected = require("../actions/indent-list-items-selected");
|
|
@@ -19,13 +20,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
19
20
|
var indentList = function indentList(editorAnalyticsAPI) {
|
|
20
21
|
return function () {
|
|
21
22
|
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.KEYBOARD;
|
|
22
|
-
return function (
|
|
23
|
-
var tr =
|
|
24
|
-
|
|
23
|
+
return function (_ref) {
|
|
24
|
+
var tr = _ref.tr;
|
|
25
|
+
var $from = tr.selection.$from;
|
|
25
26
|
|
|
26
27
|
// don't indent if selection is not inside a list
|
|
27
|
-
if (!(0, _selection.isInsideListItem)(
|
|
28
|
-
return
|
|
28
|
+
if (!(0, _selection.isInsideListItem)(tr)) {
|
|
29
|
+
return null;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
|
|
@@ -33,12 +34,12 @@ var indentList = function indentList(editorAnalyticsAPI) {
|
|
|
33
34
|
var firstListItemSelectedAttributes = (0, _lists.getListItemAttributes)($from);
|
|
34
35
|
var parentListNode = (0, _find.findFirstParentListNode)($from);
|
|
35
36
|
if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
|
|
36
|
-
if ((0, _selection.isInsideTableCell)(
|
|
37
|
+
if ((0, _selection.isInsideTableCell)(tr)) {
|
|
37
38
|
// dont consume tab, as table-keymap should move cursor to next cell
|
|
38
|
-
return
|
|
39
|
+
return null;
|
|
39
40
|
} else {
|
|
40
41
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
41
|
-
return
|
|
42
|
+
return new _preset.PassiveTransaction();
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
var currentListNode = parentListNode.node;
|
|
@@ -50,21 +51,18 @@ var indentList = function indentList(editorAnalyticsAPI) {
|
|
|
50
51
|
});
|
|
51
52
|
if (maximimunNestedLevelReached || !tr.docChanged) {
|
|
52
53
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
53
|
-
return
|
|
54
|
+
return new _preset.PassiveTransaction();
|
|
54
55
|
}
|
|
55
56
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
56
57
|
action: _analytics.ACTION.INDENTED,
|
|
57
58
|
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
58
59
|
actionSubjectId: actionSubjectId,
|
|
59
60
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
60
|
-
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(
|
|
61
|
+
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(tr)), {}, {
|
|
61
62
|
inputMethod: inputMethod
|
|
62
63
|
})
|
|
63
64
|
})(tr);
|
|
64
|
-
|
|
65
|
-
dispatch(tr);
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
65
|
+
return tr;
|
|
68
66
|
};
|
|
69
67
|
};
|
|
70
68
|
};
|
|
@@ -22,6 +22,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
22
22
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
23
23
|
var _commands = require("@atlaskit/editor-common/commands");
|
|
24
24
|
var _lists = require("@atlaskit/editor-common/lists");
|
|
25
|
+
var _preset = require("@atlaskit/editor-common/preset");
|
|
25
26
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
26
27
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
27
28
|
var _commands2 = require("@atlaskit/editor-prosemirror/commands");
|
|
@@ -54,7 +55,7 @@ var enterKeyCommand = function enterKeyCommand(editorAnalyticsAPI) {
|
|
|
54
55
|
/** Check if the wrapper has any visible content */
|
|
55
56
|
var wrapperHasContent = (0, _utils.hasVisibleContent)(wrapper);
|
|
56
57
|
if (!wrapperHasContent) {
|
|
57
|
-
return (0, _outdentList.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags)(state, dispatch);
|
|
58
|
+
return (0, _preset.editorCommandToPMCommand)((0, _outdentList.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags))(state, dispatch);
|
|
58
59
|
} else if (!(0, _utils2.hasParentNodeOfType)(codeBlock)(selection)) {
|
|
59
60
|
return splitListItem(listItem)(state, dispatch);
|
|
60
61
|
}
|
|
@@ -73,10 +74,14 @@ var backspaceKeyCommand = function backspaceKeyCommand(editorAnalyticsAPI) {
|
|
|
73
74
|
// directly to an empty list item above, or outdent this node
|
|
74
75
|
(0, _utils.filterCommand)([_utils.isEmptySelectionAtStart,
|
|
75
76
|
// list items might have multiple paragraphs; only do this at the first one
|
|
76
|
-
_isFirstChildOfParent.isFirstChildOfParent,
|
|
77
|
+
_isFirstChildOfParent.isFirstChildOfParent, function (state) {
|
|
78
|
+
return (0, _selection2.isInsideListItem)(state.tr);
|
|
79
|
+
}], (0, _commands2.chainCommands)(deletePreviousEmptyListItem, (0, _preset.editorCommandToPMCommand)((0, _outdentList.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags)))),
|
|
77
80
|
// if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
|
|
78
81
|
// the text to the previous list item, if one exists
|
|
79
|
-
(0, _utils.filterCommand)([_utils.isEmptySelectionAtStart,
|
|
82
|
+
(0, _utils.filterCommand)([_utils.isEmptySelectionAtStart, function (state) {
|
|
83
|
+
return (0, _selection2.canJoinToPreviousListItem)(state.tr);
|
|
84
|
+
}], joinToPreviousListItem))(state, dispatch);
|
|
80
85
|
};
|
|
81
86
|
};
|
|
82
87
|
};
|
|
@@ -116,13 +121,13 @@ function untoggleSelectedList(tr) {
|
|
|
116
121
|
}
|
|
117
122
|
var toggleList = function toggleList(editorAnalyticsAPI) {
|
|
118
123
|
return function (inputMethod, listType) {
|
|
119
|
-
return function (
|
|
120
|
-
var tr =
|
|
124
|
+
return function (_ref) {
|
|
125
|
+
var tr = _ref.tr;
|
|
121
126
|
var listInsideSelection = (0, _selection2.selectionContainsList)(tr);
|
|
122
|
-
var listNodeType =
|
|
127
|
+
var listNodeType = tr.doc.type.schema.nodes[listType];
|
|
123
128
|
var actionSubjectId = listType === 'bulletList' ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
124
129
|
if (listInsideSelection) {
|
|
125
|
-
var selection =
|
|
130
|
+
var selection = tr.selection;
|
|
126
131
|
|
|
127
132
|
// for gap cursor or node selection - list is expected 1 level up (listItem -> list)
|
|
128
133
|
// for text selection - list is expected 2 levels up (paragraph -> listItem -> list)
|
|
@@ -131,22 +136,19 @@ var toggleList = function toggleList(editorAnalyticsAPI) {
|
|
|
131
136
|
var toNode = selection.$to.node(selection.$to.depth - positionDiff);
|
|
132
137
|
var transformedFrom = listInsideSelection.type.name === 'bulletList' ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
133
138
|
if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
|
|
134
|
-
var
|
|
135
|
-
untoggleSelectedList(
|
|
139
|
+
var commonAttributes = (0, _lists.getCommonListAnalyticsAttributes)(tr);
|
|
140
|
+
untoggleSelectedList(tr);
|
|
136
141
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
137
142
|
action: _analytics.ACTION.CONVERTED,
|
|
138
143
|
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
139
144
|
actionSubjectId: _analytics.ACTION_SUBJECT_ID.TEXT,
|
|
140
145
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
141
|
-
attributes: _objectSpread(_objectSpread({},
|
|
146
|
+
attributes: _objectSpread(_objectSpread({}, commonAttributes), {}, {
|
|
142
147
|
transformedFrom: transformedFrom,
|
|
143
148
|
inputMethod: inputMethod
|
|
144
149
|
})
|
|
145
|
-
})(
|
|
146
|
-
|
|
147
|
-
dispatch(_tr2);
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
+
})(tr);
|
|
151
|
+
return tr;
|
|
150
152
|
}
|
|
151
153
|
(0, _conversions.convertListType)({
|
|
152
154
|
tr: tr,
|
|
@@ -157,7 +159,7 @@ var toggleList = function toggleList(editorAnalyticsAPI) {
|
|
|
157
159
|
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
158
160
|
actionSubjectId: actionSubjectId,
|
|
159
161
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
160
|
-
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(
|
|
162
|
+
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(tr)), {}, {
|
|
161
163
|
transformedFrom: transformedFrom,
|
|
162
164
|
inputMethod: inputMethod
|
|
163
165
|
})
|
|
@@ -181,27 +183,24 @@ var toggleList = function toggleList(editorAnalyticsAPI) {
|
|
|
181
183
|
// If document wasn't changed, return false from the command to indicate that the
|
|
182
184
|
// editing action failed
|
|
183
185
|
if (!tr.docChanged) {
|
|
184
|
-
return
|
|
186
|
+
return null;
|
|
185
187
|
}
|
|
186
|
-
|
|
187
|
-
dispatch(tr);
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
188
|
+
return tr;
|
|
190
189
|
};
|
|
191
190
|
};
|
|
192
191
|
};
|
|
193
192
|
exports.toggleList = toggleList;
|
|
194
193
|
var toggleBulletList = function toggleBulletList(editorAnalyticsAPI) {
|
|
195
|
-
return function (
|
|
196
|
-
var inputMethod = arguments.length >
|
|
197
|
-
return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList')
|
|
194
|
+
return function () {
|
|
195
|
+
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
196
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList');
|
|
198
197
|
};
|
|
199
198
|
};
|
|
200
199
|
exports.toggleBulletList = toggleBulletList;
|
|
201
200
|
var toggleOrderedList = function toggleOrderedList(editorAnalyticsAPI) {
|
|
202
|
-
return function (
|
|
203
|
-
var inputMethod = arguments.length >
|
|
204
|
-
return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList')
|
|
201
|
+
return function () {
|
|
202
|
+
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
203
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList');
|
|
205
204
|
};
|
|
206
205
|
};
|
|
207
206
|
|
|
@@ -8,6 +8,7 @@ exports.outdentList = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _lists = require("@atlaskit/editor-common/lists");
|
|
11
|
+
var _preset = require("@atlaskit/editor-common/preset");
|
|
11
12
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
13
|
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
13
14
|
var _outdentListItemsSelected = require("../actions/outdent-list-items-selected");
|
|
@@ -20,26 +21,27 @@ var outdentList = function outdentList(editorAnalyticsAPI) {
|
|
|
20
21
|
return function () {
|
|
21
22
|
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.KEYBOARD;
|
|
22
23
|
var featureFlags = arguments.length > 1 ? arguments[1] : undefined;
|
|
23
|
-
return function (
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
return function (_ref) {
|
|
25
|
+
var tr = _ref.tr;
|
|
26
|
+
if (!(0, _selection.isInsideListItem)(tr)) {
|
|
27
|
+
return null;
|
|
26
28
|
}
|
|
27
|
-
var $from =
|
|
29
|
+
var $from = tr.selection.$from;
|
|
28
30
|
var parentListNode = (0, _find.findFirstParentListNode)($from);
|
|
29
31
|
if (!parentListNode) {
|
|
30
32
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
31
|
-
return
|
|
33
|
+
return new _preset.PassiveTransaction();
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
// Save the history, so it could undo/revert to the same state before the outdent, see https://product-fabric.atlassian.net/browse/ED-14753
|
|
35
|
-
(0, _history.closeHistory)(
|
|
37
|
+
(0, _history.closeHistory)(tr);
|
|
36
38
|
var actionSubjectId = (0, _utils.isBulletList)(parentListNode.node) ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
37
|
-
var customTr =
|
|
38
|
-
(0, _outdentListItemsSelected.outdentListItemsSelected)(customTr,
|
|
39
|
+
var customTr = tr;
|
|
40
|
+
(0, _outdentListItemsSelected.outdentListItemsSelected)(customTr, featureFlags);
|
|
39
41
|
if (!customTr || !customTr.docChanged) {
|
|
40
42
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
41
43
|
// If inside table cell and can't outdent list, then let it handle by table keymap
|
|
42
|
-
return !(0, _selection.isInsideTableCell)(
|
|
44
|
+
return !(0, _selection.isInsideTableCell)(customTr) ? new _preset.PassiveTransaction() : null;
|
|
43
45
|
}
|
|
44
46
|
var restartListsAttributes = {};
|
|
45
47
|
if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
|
|
@@ -56,14 +58,11 @@ var outdentList = function outdentList(editorAnalyticsAPI) {
|
|
|
56
58
|
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
57
59
|
actionSubjectId: actionSubjectId,
|
|
58
60
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
59
|
-
attributes: _objectSpread(_objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(
|
|
61
|
+
attributes: _objectSpread(_objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(customTr)), restartListsAttributes), {}, {
|
|
60
62
|
inputMethod: inputMethod
|
|
61
63
|
})
|
|
62
64
|
})(customTr);
|
|
63
|
-
|
|
64
|
-
dispatch(customTr);
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
65
|
+
return customTr;
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
68
|
};
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -28,13 +28,17 @@ var listPlugin = function listPlugin(options, api) {
|
|
|
28
28
|
return {
|
|
29
29
|
name: 'list',
|
|
30
30
|
actions: {
|
|
31
|
-
indentList: (0, _commands.indentList)(editorAnalyticsAPI),
|
|
32
|
-
outdentList: (0, _commands.outdentList)(editorAnalyticsAPI),
|
|
33
|
-
toggleOrderedList: (0, _commands.toggleOrderedList)(editorAnalyticsAPI),
|
|
34
|
-
toggleBulletList: (0, _commands.toggleBulletList)(editorAnalyticsAPI),
|
|
35
31
|
isInsideListItem: _selection.isInsideListItem,
|
|
36
32
|
findRootParentListNode: _find.findRootParentListNode
|
|
37
33
|
},
|
|
34
|
+
commands: {
|
|
35
|
+
indentList: (0, _commands.indentList)(editorAnalyticsAPI),
|
|
36
|
+
outdentList: function outdentList(inputMethod) {
|
|
37
|
+
return (0, _commands.outdentList)(editorAnalyticsAPI)(inputMethod, featureFlags);
|
|
38
|
+
},
|
|
39
|
+
toggleOrderedList: (0, _commands.toggleOrderedList)(editorAnalyticsAPI),
|
|
40
|
+
toggleBulletList: (0, _commands.toggleBulletList)(editorAnalyticsAPI)
|
|
41
|
+
},
|
|
38
42
|
getSharedState: function getSharedState(editorState) {
|
|
39
43
|
if (!editorState) {
|
|
40
44
|
return undefined;
|
|
@@ -11,10 +11,10 @@ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
|
11
11
|
var _commands = require("../commands");
|
|
12
12
|
function keymapPlugin(featureFlags, editorAnalyticsAPI) {
|
|
13
13
|
var list = {};
|
|
14
|
-
(0, _keymaps.
|
|
15
|
-
(0, _keymaps.
|
|
16
|
-
(0, _keymaps.
|
|
17
|
-
(0, _keymaps.
|
|
14
|
+
(0, _keymaps.bindKeymapWithEditorCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.toggleOrderedList), (0, _commands.toggleList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, 'orderedList'), list);
|
|
15
|
+
(0, _keymaps.bindKeymapWithEditorCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.toggleBulletList), (0, _commands.toggleList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, 'bulletList'), list);
|
|
16
|
+
(0, _keymaps.bindKeymapWithEditorCommand)(_keymaps.indentList.common, (0, _commands.indentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), list);
|
|
17
|
+
(0, _keymaps.bindKeymapWithEditorCommand)(_keymaps.outdentList.common, (0, _commands.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags), list);
|
|
18
18
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.enter.common, (0, _commands.enterKeyCommand)(editorAnalyticsAPI)(featureFlags), list);
|
|
19
19
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _commands.backspaceKeyCommand)(editorAnalyticsAPI)(featureFlags), list);
|
|
20
20
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, (0, _commands.deleteKeyCommand)(editorAnalyticsAPI), list);
|
|
@@ -39,27 +39,27 @@ var isWrappingPossible = function isWrappingPossible(nodeType, selection) {
|
|
|
39
39
|
|
|
40
40
|
// canOutdent
|
|
41
41
|
exports.isWrappingPossible = isWrappingPossible;
|
|
42
|
-
var isInsideListItem = function isInsideListItem(
|
|
43
|
-
var parent =
|
|
44
|
-
var listItem =
|
|
45
|
-
if (
|
|
42
|
+
var isInsideListItem = function isInsideListItem(tr) {
|
|
43
|
+
var parent = tr.selection.$from.parent;
|
|
44
|
+
var listItem = tr.doc.type.schema.nodes.listItem;
|
|
45
|
+
if (tr.selection instanceof _selection.GapCursorSelection) {
|
|
46
46
|
return (0, _utils.isListItemNode)(parent);
|
|
47
47
|
}
|
|
48
|
-
return (0, _utils2.hasParentNodeOfType)(listItem)(
|
|
48
|
+
return (0, _utils2.hasParentNodeOfType)(listItem)(tr.selection) && (0, _utils.isParagraphNode)(parent);
|
|
49
49
|
};
|
|
50
50
|
exports.isInsideListItem = isInsideListItem;
|
|
51
|
-
var isInsideTableCell = function isInsideTableCell(
|
|
52
|
-
var
|
|
53
|
-
tableCell =
|
|
54
|
-
tableHeader =
|
|
55
|
-
return !!(0, _utils2.findParentNodeOfType)([tableCell, tableHeader])(
|
|
51
|
+
var isInsideTableCell = function isInsideTableCell(tr) {
|
|
52
|
+
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
|
|
53
|
+
tableCell = _tr$doc$type$schema$n.tableCell,
|
|
54
|
+
tableHeader = _tr$doc$type$schema$n.tableHeader;
|
|
55
|
+
return !!(0, _utils2.findParentNodeOfType)([tableCell, tableHeader])(tr.selection);
|
|
56
56
|
};
|
|
57
57
|
exports.isInsideTableCell = isInsideTableCell;
|
|
58
|
-
var canJoinToPreviousListItem = function canJoinToPreviousListItem(
|
|
59
|
-
var $from =
|
|
60
|
-
var $before =
|
|
58
|
+
var canJoinToPreviousListItem = function canJoinToPreviousListItem(tr) {
|
|
59
|
+
var $from = tr.selection.$from;
|
|
60
|
+
var $before = tr.doc.resolve($from.pos - 1);
|
|
61
61
|
var nodeBefore = $before ? $before.nodeBefore : null;
|
|
62
|
-
if (
|
|
62
|
+
if (tr.selection instanceof _selection.GapCursorSelection) {
|
|
63
63
|
nodeBefore = $from.nodeBefore;
|
|
64
64
|
}
|
|
65
65
|
return (0, _utils.isListNode)(nodeBefore);
|
|
@@ -8,7 +8,7 @@ import { liftTarget, ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-pro
|
|
|
8
8
|
import { getRestartListsAttributes, storeRestartListsAttributes } from '../utils/analytics';
|
|
9
9
|
import { findFirstParentListItemNode, findRootParentListNode } from '../utils/find';
|
|
10
10
|
import { createListNodeRange } from '../utils/selection';
|
|
11
|
-
export const outdentListItemsSelected = (tr,
|
|
11
|
+
export const outdentListItemsSelected = (tr, featureFlags) => {
|
|
12
12
|
const originalSelection = tr.selection;
|
|
13
13
|
const normalizedSelection = normalizeListItemsSelection({
|
|
14
14
|
selection: tr.selection,
|
|
@@ -45,7 +45,6 @@ export const outdentListItemsSelected = (tr, state, featureFlags) => {
|
|
|
45
45
|
extractListItemsRangeFromList({
|
|
46
46
|
tr,
|
|
47
47
|
range: mappedRange,
|
|
48
|
-
state,
|
|
49
48
|
featureFlags
|
|
50
49
|
});
|
|
51
50
|
hasNormalizedToPositionLiftedOut = hasNormalizedToPositionLiftedOut || oldTo >= range.from && oldTo < range.to;
|
|
@@ -177,7 +176,6 @@ const outdentRangeToParentList = ({
|
|
|
177
176
|
const extractListItemsRangeFromList = ({
|
|
178
177
|
tr,
|
|
179
178
|
range,
|
|
180
|
-
state,
|
|
181
179
|
featureFlags
|
|
182
180
|
}) => {
|
|
183
181
|
const list = range.parent;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { getCommonListAnalyticsAttributes, getListItemAttributes, hasValidListIndentationLevel } from '@atlaskit/editor-common/lists';
|
|
3
|
+
import { PassiveTransaction } from '@atlaskit/editor-common/preset';
|
|
3
4
|
import { isBulletList } from '@atlaskit/editor-common/utils';
|
|
4
5
|
import { closeHistory } from '@atlaskit/editor-prosemirror/history';
|
|
5
6
|
import { indentListItemsSelected as indentListAction } from '../actions/indent-list-items-selected';
|
|
@@ -7,17 +8,18 @@ import { MAX_NESTED_LIST_INDENTATION } from '../types';
|
|
|
7
8
|
import { findFirstParentListNode } from '../utils/find';
|
|
8
9
|
import { isInsideListItem, isInsideTableCell } from '../utils/selection';
|
|
9
10
|
export const indentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYBOARD) => {
|
|
10
|
-
return function (
|
|
11
|
+
return function ({
|
|
12
|
+
tr
|
|
13
|
+
}) {
|
|
11
14
|
const {
|
|
12
|
-
tr,
|
|
13
15
|
selection: {
|
|
14
16
|
$from
|
|
15
17
|
}
|
|
16
|
-
} =
|
|
18
|
+
} = tr;
|
|
17
19
|
|
|
18
20
|
// don't indent if selection is not inside a list
|
|
19
|
-
if (!isInsideListItem(
|
|
20
|
-
return
|
|
21
|
+
if (!isInsideListItem(tr)) {
|
|
22
|
+
return null;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
|
|
@@ -25,12 +27,12 @@ export const indentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYB
|
|
|
25
27
|
const firstListItemSelectedAttributes = getListItemAttributes($from);
|
|
26
28
|
const parentListNode = findFirstParentListNode($from);
|
|
27
29
|
if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
|
|
28
|
-
if (isInsideTableCell(
|
|
30
|
+
if (isInsideTableCell(tr)) {
|
|
29
31
|
// dont consume tab, as table-keymap should move cursor to next cell
|
|
30
|
-
return
|
|
32
|
+
return null;
|
|
31
33
|
} else {
|
|
32
34
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
33
|
-
return
|
|
35
|
+
return new PassiveTransaction();
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
const currentListNode = parentListNode.node;
|
|
@@ -42,7 +44,7 @@ export const indentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYB
|
|
|
42
44
|
});
|
|
43
45
|
if (maximimunNestedLevelReached || !tr.docChanged) {
|
|
44
46
|
// Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
|
|
45
|
-
return
|
|
47
|
+
return new PassiveTransaction();
|
|
46
48
|
}
|
|
47
49
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
48
50
|
action: ACTION.INDENTED,
|
|
@@ -50,13 +52,10 @@ export const indentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYB
|
|
|
50
52
|
actionSubjectId,
|
|
51
53
|
eventType: EVENT_TYPE.TRACK,
|
|
52
54
|
attributes: {
|
|
53
|
-
...getCommonListAnalyticsAttributes(
|
|
55
|
+
...getCommonListAnalyticsAttributes(tr),
|
|
54
56
|
inputMethod
|
|
55
57
|
}
|
|
56
58
|
})(tr);
|
|
57
|
-
|
|
58
|
-
dispatch(tr);
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
59
|
+
return tr;
|
|
61
60
|
};
|
|
62
61
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { findCutBefore } from '@atlaskit/editor-common/commands';
|
|
3
3
|
import { getCommonListAnalyticsAttributes, moveTargetIntoList } from '@atlaskit/editor-common/lists';
|
|
4
|
+
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
4
5
|
import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
5
6
|
import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart } from '@atlaskit/editor-common/utils';
|
|
6
7
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
@@ -35,7 +36,7 @@ export const enterKeyCommand = editorAnalyticsAPI => featureFlags => (state, dis
|
|
|
35
36
|
/** Check if the wrapper has any visible content */
|
|
36
37
|
const wrapperHasContent = hasVisibleContent(wrapper);
|
|
37
38
|
if (!wrapperHasContent) {
|
|
38
|
-
return outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags)(state, dispatch);
|
|
39
|
+
return editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags))(state, dispatch);
|
|
39
40
|
} else if (!hasParentNodeOfType(codeBlock)(selection)) {
|
|
40
41
|
return splitListItem(listItem)(state, dispatch);
|
|
41
42
|
}
|
|
@@ -49,10 +50,10 @@ export const backspaceKeyCommand = editorAnalyticsAPI => featureFlags => (state,
|
|
|
49
50
|
// directly to an empty list item above, or outdent this node
|
|
50
51
|
filter([isEmptySelectionAtStart,
|
|
51
52
|
// list items might have multiple paragraphs; only do this at the first one
|
|
52
|
-
isFirstChildOfParent, isInsideListItem], chainCommands(deletePreviousEmptyListItem, outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags))),
|
|
53
|
+
isFirstChildOfParent, state => isInsideListItem(state.tr)], chainCommands(deletePreviousEmptyListItem, editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags)))),
|
|
53
54
|
// if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
|
|
54
55
|
// the text to the previous list item, if one exists
|
|
55
|
-
filter([isEmptySelectionAtStart, canJoinToPreviousListItem], joinToPreviousListItem))(state, dispatch);
|
|
56
|
+
filter([isEmptySelectionAtStart, state => canJoinToPreviousListItem(state.tr)], joinToPreviousListItem))(state, dispatch);
|
|
56
57
|
};
|
|
57
58
|
export const deleteKeyCommand = editorAnalyticsAPI => joinListItemForward(editorAnalyticsAPI);
|
|
58
59
|
|
|
@@ -87,15 +88,16 @@ function untoggleSelectedList(tr) {
|
|
|
87
88
|
return liftTextSelectionList(selection, tr);
|
|
88
89
|
}
|
|
89
90
|
export const toggleList = editorAnalyticsAPI => (inputMethod, listType) => {
|
|
90
|
-
return function (
|
|
91
|
-
|
|
91
|
+
return function ({
|
|
92
|
+
tr
|
|
93
|
+
}) {
|
|
92
94
|
const listInsideSelection = selectionContainsList(tr);
|
|
93
|
-
const listNodeType =
|
|
95
|
+
const listNodeType = tr.doc.type.schema.nodes[listType];
|
|
94
96
|
const actionSubjectId = listType === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
95
97
|
if (listInsideSelection) {
|
|
96
98
|
const {
|
|
97
99
|
selection
|
|
98
|
-
} =
|
|
100
|
+
} = tr;
|
|
99
101
|
|
|
100
102
|
// for gap cursor or node selection - list is expected 1 level up (listItem -> list)
|
|
101
103
|
// for text selection - list is expected 2 levels up (paragraph -> listItem -> list)
|
|
@@ -104,7 +106,7 @@ export const toggleList = editorAnalyticsAPI => (inputMethod, listType) => {
|
|
|
104
106
|
const toNode = selection.$to.node(selection.$to.depth - positionDiff);
|
|
105
107
|
const transformedFrom = listInsideSelection.type.name === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
106
108
|
if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
|
|
107
|
-
|
|
109
|
+
const commonAttributes = getCommonListAnalyticsAttributes(tr);
|
|
108
110
|
untoggleSelectedList(tr);
|
|
109
111
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
110
112
|
action: ACTION.CONVERTED,
|
|
@@ -112,15 +114,12 @@ export const toggleList = editorAnalyticsAPI => (inputMethod, listType) => {
|
|
|
112
114
|
actionSubjectId: ACTION_SUBJECT_ID.TEXT,
|
|
113
115
|
eventType: EVENT_TYPE.TRACK,
|
|
114
116
|
attributes: {
|
|
115
|
-
...
|
|
117
|
+
...commonAttributes,
|
|
116
118
|
transformedFrom,
|
|
117
119
|
inputMethod
|
|
118
120
|
}
|
|
119
121
|
})(tr);
|
|
120
|
-
|
|
121
|
-
dispatch(tr);
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
122
|
+
return tr;
|
|
124
123
|
}
|
|
125
124
|
convertListType({
|
|
126
125
|
tr,
|
|
@@ -132,7 +131,7 @@ export const toggleList = editorAnalyticsAPI => (inputMethod, listType) => {
|
|
|
132
131
|
actionSubjectId,
|
|
133
132
|
eventType: EVENT_TYPE.TRACK,
|
|
134
133
|
attributes: {
|
|
135
|
-
...getCommonListAnalyticsAttributes(
|
|
134
|
+
...getCommonListAnalyticsAttributes(tr),
|
|
136
135
|
transformedFrom,
|
|
137
136
|
inputMethod
|
|
138
137
|
}
|
|
@@ -156,19 +155,16 @@ export const toggleList = editorAnalyticsAPI => (inputMethod, listType) => {
|
|
|
156
155
|
// If document wasn't changed, return false from the command to indicate that the
|
|
157
156
|
// editing action failed
|
|
158
157
|
if (!tr.docChanged) {
|
|
159
|
-
return
|
|
158
|
+
return null;
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
dispatch(tr);
|
|
163
|
-
}
|
|
164
|
-
return true;
|
|
160
|
+
return tr;
|
|
165
161
|
};
|
|
166
162
|
};
|
|
167
|
-
export const toggleBulletList = editorAnalyticsAPI => (
|
|
168
|
-
return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList')
|
|
163
|
+
export const toggleBulletList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.TOOLBAR) => {
|
|
164
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList');
|
|
169
165
|
};
|
|
170
|
-
export const toggleOrderedList = editorAnalyticsAPI => (
|
|
171
|
-
return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList')
|
|
166
|
+
export const toggleOrderedList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.TOOLBAR) => {
|
|
167
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList');
|
|
172
168
|
};
|
|
173
169
|
|
|
174
170
|
/**
|