@atlaskit/editor-plugin-list 0.2.0 → 1.0.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/.eslintrc.js +14 -0
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/cjs/actions/conversions.js +153 -0
- package/dist/cjs/actions/indent-list-items-selected.js +125 -0
- package/dist/cjs/actions/indent-list.js +49 -0
- package/dist/cjs/actions/join-list-items-forward.js +59 -0
- package/dist/cjs/actions/join-list-items-scenarios/index.js +40 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +88 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +85 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +79 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-paragraph-with-list.js +45 -0
- package/dist/cjs/actions/join-list-items-scenarios/join-sibling-list-items.js +56 -0
- package/dist/cjs/actions/merge-lists.js +27 -0
- package/dist/cjs/actions/outdent-list-items-selected.js +291 -0
- package/dist/cjs/actions/wrap-and-join-lists.js +100 -0
- package/dist/cjs/commands/indent-list.js +71 -0
- package/dist/cjs/commands/index.js +350 -0
- package/dist/cjs/commands/isFirstChildOfParent.js +12 -0
- package/dist/cjs/commands/join-list-item-forward.js +61 -0
- package/dist/cjs/commands/listBackspace.js +284 -0
- package/dist/cjs/commands/outdent-list.js +70 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/messages.js +37 -0
- package/dist/cjs/plugin.js +133 -0
- package/dist/cjs/pm-plugins/input-rules/create-list-input-rule.js +63 -0
- package/dist/cjs/pm-plugins/input-rules/index.js +38 -0
- package/dist/cjs/pm-plugins/input-rules/wrapping-join-rule.js +60 -0
- package/dist/cjs/pm-plugins/keymap.js +27 -0
- package/dist/cjs/pm-plugins/main.js +166 -0
- package/dist/cjs/transforms.js +99 -0
- package/dist/cjs/types.js +4 -1
- package/dist/cjs/utils/analytics.js +22 -0
- package/dist/cjs/utils/find.js +68 -0
- package/dist/cjs/utils/indentation.js +22 -0
- package/dist/cjs/utils/mark.js +40 -0
- package/dist/cjs/utils/node.js +16 -0
- package/dist/cjs/utils/selection.js +95 -0
- package/dist/es2019/actions/conversions.js +160 -0
- package/dist/es2019/actions/indent-list-items-selected.js +124 -0
- package/dist/es2019/actions/indent-list.js +44 -0
- package/dist/es2019/actions/join-list-items-forward.js +54 -0
- package/dist/es2019/actions/join-list-items-scenarios/index.js +5 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +74 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +77 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +71 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-paragraph-with-list.js +37 -0
- package/dist/es2019/actions/join-list-items-scenarios/join-sibling-list-items.js +48 -0
- package/dist/es2019/actions/merge-lists.js +24 -0
- package/dist/es2019/actions/outdent-list-items-selected.js +295 -0
- package/dist/es2019/actions/wrap-and-join-lists.js +93 -0
- package/dist/es2019/commands/indent-list.js +62 -0
- package/dist/es2019/commands/index.js +326 -0
- package/dist/es2019/commands/isFirstChildOfParent.js +7 -0
- package/dist/es2019/commands/join-list-item-forward.js +53 -0
- package/dist/es2019/commands/listBackspace.js +276 -0
- package/dist/es2019/commands/outdent-list.js +60 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/messages.js +29 -0
- package/dist/es2019/plugin.js +121 -0
- package/dist/es2019/pm-plugins/input-rules/create-list-input-rule.js +56 -0
- package/dist/es2019/pm-plugins/input-rules/index.js +35 -0
- package/dist/es2019/pm-plugins/input-rules/wrapping-join-rule.js +55 -0
- package/dist/es2019/pm-plugins/keymap.js +19 -0
- package/dist/es2019/pm-plugins/main.js +156 -0
- package/dist/es2019/transforms.js +101 -0
- package/dist/es2019/types.js +1 -1
- package/dist/es2019/utils/analytics.js +12 -0
- package/dist/es2019/utils/find.js +61 -0
- package/dist/es2019/utils/indentation.js +15 -0
- package/dist/es2019/utils/mark.js +30 -0
- package/dist/es2019/utils/node.js +12 -0
- package/dist/es2019/utils/selection.js +96 -0
- package/dist/esm/actions/conversions.js +147 -0
- package/dist/esm/actions/indent-list-items-selected.js +117 -0
- package/dist/esm/actions/indent-list.js +43 -0
- package/dist/esm/actions/join-list-items-forward.js +52 -0
- package/dist/esm/actions/join-list-items-scenarios/index.js +5 -0
- package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +81 -0
- package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +78 -0
- package/dist/esm/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +72 -0
- package/dist/esm/actions/join-list-items-scenarios/join-paragraph-with-list.js +38 -0
- package/dist/esm/actions/join-list-items-scenarios/join-sibling-list-items.js +49 -0
- package/dist/esm/actions/merge-lists.js +21 -0
- package/dist/esm/actions/outdent-list-items-selected.js +283 -0
- package/dist/esm/actions/wrap-and-join-lists.js +94 -0
- package/dist/esm/commands/indent-list.js +63 -0
- package/dist/esm/commands/index.js +324 -0
- package/dist/esm/commands/isFirstChildOfParent.js +5 -0
- package/dist/esm/commands/join-list-item-forward.js +53 -0
- package/dist/esm/commands/listBackspace.js +275 -0
- package/dist/esm/commands/outdent-list.js +62 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/messages.js +29 -0
- package/dist/esm/plugin.js +126 -0
- package/dist/esm/pm-plugins/input-rules/create-list-input-rule.js +57 -0
- package/dist/esm/pm-plugins/input-rules/index.js +32 -0
- package/dist/esm/pm-plugins/input-rules/wrapping-join-rule.js +54 -0
- package/dist/esm/pm-plugins/keymap.js +19 -0
- package/dist/esm/pm-plugins/main.js +156 -0
- package/dist/esm/transforms.js +91 -0
- package/dist/esm/types.js +1 -1
- package/dist/esm/utils/analytics.js +12 -0
- package/dist/esm/utils/find.js +59 -0
- package/dist/esm/utils/indentation.js +15 -0
- package/dist/esm/utils/mark.js +33 -0
- package/dist/esm/utils/node.js +10 -0
- package/dist/esm/utils/selection.js +81 -0
- package/dist/types/actions/conversions.d.ts +6 -0
- package/dist/types/actions/indent-list-items-selected.d.ts +2 -0
- package/dist/types/actions/indent-list.d.ts +2 -0
- package/dist/types/actions/join-list-items-forward.d.ts +13 -0
- package/dist/types/actions/join-list-items-scenarios/index.d.ts +5 -0
- package/dist/types/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
- package/dist/types/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
- package/dist/types/actions/merge-lists.d.ts +7 -0
- package/dist/types/actions/outdent-list-items-selected.d.ts +3 -0
- package/dist/types/actions/wrap-and-join-lists.d.ts +17 -0
- package/dist/types/commands/indent-list.d.ts +6 -0
- package/dist/types/commands/index.d.ts +16 -0
- package/dist/types/commands/isFirstChildOfParent.d.ts +2 -0
- package/dist/types/commands/join-list-item-forward.d.ts +3 -0
- package/dist/types/commands/listBackspace.d.ts +10 -0
- package/dist/types/commands/outdent-list.d.ts +6 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/messages.d.ts +27 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
- package/dist/types/pm-plugins/input-rules/index.d.ts +5 -0
- package/dist/types/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
- package/dist/types/pm-plugins/keymap.d.ts +5 -0
- package/dist/types/pm-plugins/main.d.ts +11 -0
- package/dist/types/transforms.d.ts +4 -0
- package/dist/types/types.d.ts +4 -6
- package/dist/types/utils/analytics.d.ts +5 -0
- package/dist/types/utils/find.d.ts +10 -0
- package/dist/types/utils/indentation.d.ts +2 -0
- package/dist/types/utils/mark.d.ts +8 -0
- package/dist/types/utils/node.d.ts +2 -0
- package/dist/types/utils/selection.d.ts +14 -0
- package/dist/types-ts4.5/actions/conversions.d.ts +6 -0
- package/dist/types-ts4.5/actions/indent-list-items-selected.d.ts +2 -0
- package/dist/types-ts4.5/actions/indent-list.d.ts +2 -0
- package/dist/types-ts4.5/actions/join-list-items-forward.d.ts +16 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/index.d.ts +5 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
- package/dist/types-ts4.5/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
- package/dist/types-ts4.5/actions/merge-lists.d.ts +7 -0
- package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +3 -0
- package/dist/types-ts4.5/actions/wrap-and-join-lists.d.ts +17 -0
- package/dist/types-ts4.5/commands/indent-list.d.ts +6 -0
- package/dist/types-ts4.5/commands/index.d.ts +16 -0
- package/dist/types-ts4.5/commands/isFirstChildOfParent.d.ts +2 -0
- package/dist/types-ts4.5/commands/join-list-item-forward.d.ts +3 -0
- package/dist/types-ts4.5/commands/listBackspace.d.ts +13 -0
- package/dist/types-ts4.5/commands/outdent-list.d.ts +6 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/messages.d.ts +27 -0
- package/dist/types-ts4.5/plugin.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/index.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +11 -0
- package/dist/types-ts4.5/transforms.d.ts +4 -0
- package/dist/types-ts4.5/types.d.ts +4 -6
- package/dist/types-ts4.5/utils/analytics.d.ts +5 -0
- package/dist/types-ts4.5/utils/find.d.ts +10 -0
- package/dist/types-ts4.5/utils/indentation.d.ts +2 -0
- package/dist/types-ts4.5/utils/mark.d.ts +8 -0
- package/dist/types-ts4.5/utils/node.d.ts +2 -0
- package/dist/types-ts4.5/utils/selection.d.ts +14 -0
- package/package.json +8 -5
- package/report.api.md +6 -2
- package/tmp/api-report-tmp.d.ts +4 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.enterKeyCommand = exports.deleteKeyCommand = exports.backspaceKeyCommand = void 0;
|
|
8
|
+
Object.defineProperty(exports, "indentList", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _indentList.indentList;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "outdentList", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _outdentList.outdentList;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.toggleOrderedList = exports.toggleList = exports.toggleBulletList = exports.rootListDepth = void 0;
|
|
21
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
22
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
23
|
+
var _commands = require("@atlaskit/editor-common/commands");
|
|
24
|
+
var _lists = require("@atlaskit/editor-common/lists");
|
|
25
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
26
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
27
|
+
var _commands2 = require("@atlaskit/editor-prosemirror/commands");
|
|
28
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
29
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
30
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
31
|
+
var _conversions = require("../actions/conversions");
|
|
32
|
+
var _wrapAndJoinLists = require("../actions/wrap-and-join-lists");
|
|
33
|
+
var _transforms = require("../transforms");
|
|
34
|
+
var _mark = require("../utils/mark");
|
|
35
|
+
var _selection2 = require("../utils/selection");
|
|
36
|
+
var _indentList = require("./indent-list");
|
|
37
|
+
var _isFirstChildOfParent = require("./isFirstChildOfParent");
|
|
38
|
+
var _joinListItemForward = require("./join-list-item-forward");
|
|
39
|
+
var _listBackspace = require("./listBackspace");
|
|
40
|
+
var _outdentList = require("./outdent-list");
|
|
41
|
+
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; }
|
|
42
|
+
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; }
|
|
43
|
+
var enterKeyCommand = function enterKeyCommand(editorAnalyticsAPI) {
|
|
44
|
+
return function (featureFlags) {
|
|
45
|
+
return function (state, dispatch) {
|
|
46
|
+
var selection = state.selection;
|
|
47
|
+
if (selection.empty) {
|
|
48
|
+
var $from = selection.$from;
|
|
49
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
50
|
+
listItem = _state$schema$nodes.listItem,
|
|
51
|
+
codeBlock = _state$schema$nodes.codeBlock;
|
|
52
|
+
var wrapper = $from.node($from.depth - 1);
|
|
53
|
+
if (wrapper && wrapper.type === listItem) {
|
|
54
|
+
/** Check if the wrapper has any visible content */
|
|
55
|
+
var wrapperHasContent = (0, _utils.hasVisibleContent)(wrapper);
|
|
56
|
+
if (!wrapperHasContent) {
|
|
57
|
+
return (0, _outdentList.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags)(state, dispatch);
|
|
58
|
+
} else if (!(0, _utils2.hasParentNodeOfType)(codeBlock)(selection)) {
|
|
59
|
+
return splitListItem(listItem)(state, dispatch);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.enterKeyCommand = enterKeyCommand;
|
|
68
|
+
var backspaceKeyCommand = function backspaceKeyCommand(editorAnalyticsAPI) {
|
|
69
|
+
return function (featureFlags) {
|
|
70
|
+
return function (state, dispatch) {
|
|
71
|
+
return (0, _commands2.chainCommands)((0, _listBackspace.listBackspace)(editorAnalyticsAPI),
|
|
72
|
+
// if we're at the start of a list item, we need to either backspace
|
|
73
|
+
// directly to an empty list item above, or outdent this node
|
|
74
|
+
(0, _utils.filterCommand)([_utils.isEmptySelectionAtStart,
|
|
75
|
+
// list items might have multiple paragraphs; only do this at the first one
|
|
76
|
+
_isFirstChildOfParent.isFirstChildOfParent, _selection2.isInsideListItem], (0, _commands2.chainCommands)(deletePreviousEmptyListItem, (0, _outdentList.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags))),
|
|
77
|
+
// if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
|
|
78
|
+
// the text to the previous list item, if one exists
|
|
79
|
+
(0, _utils.filterCommand)([_utils.isEmptySelectionAtStart, _selection2.canJoinToPreviousListItem], joinToPreviousListItem))(state, dispatch);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.backspaceKeyCommand = backspaceKeyCommand;
|
|
84
|
+
var deleteKeyCommand = function deleteKeyCommand(editorAnalyticsAPI) {
|
|
85
|
+
return (0, _joinListItemForward.joinListItemForward)(editorAnalyticsAPI);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Get the depth of the nearest ancestor list
|
|
89
|
+
exports.deleteKeyCommand = deleteKeyCommand;
|
|
90
|
+
var rootListDepth = function rootListDepth(pos, nodes) {
|
|
91
|
+
var bulletList = nodes.bulletList,
|
|
92
|
+
orderedList = nodes.orderedList,
|
|
93
|
+
listItem = nodes.listItem;
|
|
94
|
+
var depth;
|
|
95
|
+
for (var i = pos.depth - 1; i > 0; i--) {
|
|
96
|
+
var node = pos.node(i);
|
|
97
|
+
if (node.type === bulletList || node.type === orderedList) {
|
|
98
|
+
depth = i;
|
|
99
|
+
}
|
|
100
|
+
if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return depth;
|
|
105
|
+
};
|
|
106
|
+
exports.rootListDepth = rootListDepth;
|
|
107
|
+
function untoggleSelectedList(tr) {
|
|
108
|
+
var _tr = tr,
|
|
109
|
+
selection = _tr.selection;
|
|
110
|
+
var depth = rootListDepth(selection.$to, tr.doc.type.schema.nodes);
|
|
111
|
+
tr = (0, _transforms.liftFollowingList)(selection.$to.pos, selection.$to.end(depth), depth || 0, tr);
|
|
112
|
+
if (selection instanceof _state.NodeSelection || selection instanceof _selection.GapCursorSelection) {
|
|
113
|
+
return (0, _transforms.liftNodeSelectionList)(selection, tr);
|
|
114
|
+
}
|
|
115
|
+
return (0, _transforms.liftTextSelectionList)(selection, tr);
|
|
116
|
+
}
|
|
117
|
+
var toggleList = function toggleList(editorAnalyticsAPI) {
|
|
118
|
+
return function (inputMethod, listType) {
|
|
119
|
+
return function (state, dispatch) {
|
|
120
|
+
var tr = state.tr;
|
|
121
|
+
var listInsideSelection = (0, _selection2.selectionContainsList)(tr);
|
|
122
|
+
var listNodeType = state.schema.nodes[listType];
|
|
123
|
+
var actionSubjectId = listType === 'bulletList' ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
124
|
+
if (listInsideSelection) {
|
|
125
|
+
var selection = state.selection;
|
|
126
|
+
|
|
127
|
+
// for gap cursor or node selection - list is expected 1 level up (listItem -> list)
|
|
128
|
+
// for text selection - list is expected 2 levels up (paragraph -> listItem -> list)
|
|
129
|
+
var positionDiff = selection instanceof _selection.GapCursorSelection || selection instanceof _state.NodeSelection ? 1 : 2;
|
|
130
|
+
var fromNode = selection.$from.node(selection.$from.depth - positionDiff);
|
|
131
|
+
var toNode = selection.$to.node(selection.$to.depth - positionDiff);
|
|
132
|
+
var transformedFrom = listInsideSelection.type.name === 'bulletList' ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
133
|
+
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 _tr2 = state.tr;
|
|
135
|
+
untoggleSelectedList(_tr2);
|
|
136
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
137
|
+
action: _analytics.ACTION.CONVERTED,
|
|
138
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
139
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.TEXT,
|
|
140
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
141
|
+
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(state)), {}, {
|
|
142
|
+
transformedFrom: transformedFrom,
|
|
143
|
+
inputMethod: inputMethod
|
|
144
|
+
})
|
|
145
|
+
})(_tr2);
|
|
146
|
+
if (dispatch) {
|
|
147
|
+
dispatch(_tr2);
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
(0, _conversions.convertListType)({
|
|
152
|
+
tr: tr,
|
|
153
|
+
nextListNodeType: listNodeType
|
|
154
|
+
});
|
|
155
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
156
|
+
action: _analytics.ACTION.CONVERTED,
|
|
157
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
158
|
+
actionSubjectId: actionSubjectId,
|
|
159
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
160
|
+
attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(state)), {}, {
|
|
161
|
+
transformedFrom: transformedFrom,
|
|
162
|
+
inputMethod: inputMethod
|
|
163
|
+
})
|
|
164
|
+
})(tr);
|
|
165
|
+
} else {
|
|
166
|
+
// Need to have this before wrapInList so the wrapping is done with valid content
|
|
167
|
+
// For example, if trying to convert centre or right aligned paragraphs to lists
|
|
168
|
+
(0, _mark.sanitiseMarksInSelection)(tr, listNodeType);
|
|
169
|
+
(0, _wrapAndJoinLists.wrapInListAndJoin)(listNodeType, tr);
|
|
170
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
171
|
+
action: _analytics.ACTION.INSERTED,
|
|
172
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
173
|
+
actionSubjectId: actionSubjectId,
|
|
174
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
175
|
+
attributes: {
|
|
176
|
+
inputMethod: inputMethod
|
|
177
|
+
}
|
|
178
|
+
})(tr);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// If document wasn't changed, return false from the command to indicate that the
|
|
182
|
+
// editing action failed
|
|
183
|
+
if (!tr.docChanged) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (dispatch) {
|
|
187
|
+
dispatch(tr);
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
exports.toggleList = toggleList;
|
|
194
|
+
var toggleBulletList = function toggleBulletList(editorAnalyticsAPI) {
|
|
195
|
+
return function (view) {
|
|
196
|
+
var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
197
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList')(view.state, view.dispatch);
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
exports.toggleBulletList = toggleBulletList;
|
|
201
|
+
var toggleOrderedList = function toggleOrderedList(editorAnalyticsAPI) {
|
|
202
|
+
return function (view) {
|
|
203
|
+
var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
204
|
+
return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList')(view.state, view.dispatch);
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Implementation taken and modified for our needs from PM
|
|
210
|
+
* @param itemType Node
|
|
211
|
+
* Splits the list items, specific implementation take from PM
|
|
212
|
+
*/
|
|
213
|
+
exports.toggleOrderedList = toggleOrderedList;
|
|
214
|
+
function splitListItem(itemType) {
|
|
215
|
+
return function (state, dispatch) {
|
|
216
|
+
var ref = state.selection;
|
|
217
|
+
var $from = ref.$from;
|
|
218
|
+
var $to = ref.$to;
|
|
219
|
+
var node = ref.node;
|
|
220
|
+
if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
var grandParent = $from.node(-1);
|
|
224
|
+
if (grandParent.type !== itemType) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
/** --> The following line changed from the original PM implementation to allow list additions with multiple paragraphs */
|
|
228
|
+
if (
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
+
grandParent.content.content.length <= 1 && $from.parent.content.size === 0 && !(grandParent.content.size === 0)) {
|
|
231
|
+
// In an empty block. If this is a nested list, the wrapping
|
|
232
|
+
// list item should be split. Otherwise, bail out and let next
|
|
233
|
+
// command handle lifting.
|
|
234
|
+
if ($from.depth === 2 || $from.node(-3).type !== itemType || $from.index(-2) !== $from.node(-2).childCount - 1) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
if (dispatch) {
|
|
238
|
+
var wrap = _model.Fragment.empty;
|
|
239
|
+
var keepItem = $from.index(-1) > 0;
|
|
240
|
+
// Build a fragment containing empty versions of the structure
|
|
241
|
+
// from the outer list item to the parent node of the cursor
|
|
242
|
+
for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) {
|
|
243
|
+
wrap = _model.Fragment.from($from.node(d).copy(wrap));
|
|
244
|
+
}
|
|
245
|
+
// Add a second list item with an empty default start node
|
|
246
|
+
wrap = wrap.append(_model.Fragment.from(itemType.createAndFill()));
|
|
247
|
+
var tr$1 = state.tr.replace($from.before(keepItem ? undefined : -1), $from.after(-3), new _model.Slice(wrap, keepItem ? 3 : 2, 2));
|
|
248
|
+
tr$1.setSelection(
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
|
+
state.selection.constructor.near(tr$1.doc.resolve($from.pos + (keepItem ? 3 : 2))));
|
|
251
|
+
dispatch(tr$1.scrollIntoView());
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
var nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
|
|
256
|
+
var tr = state.tr.delete($from.pos, $to.pos);
|
|
257
|
+
var types = nextType && [null, {
|
|
258
|
+
type: nextType
|
|
259
|
+
}];
|
|
260
|
+
if (dispatch) {
|
|
261
|
+
dispatch(tr.split($from.pos, 2, types !== null && types !== void 0 ? types : undefined).scrollIntoView());
|
|
262
|
+
}
|
|
263
|
+
return true;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
var deletePreviousEmptyListItem = function deletePreviousEmptyListItem(state, dispatch) {
|
|
267
|
+
var $from = state.selection.$from;
|
|
268
|
+
var listItem = state.schema.nodes.listItem;
|
|
269
|
+
var $cut = (0, _commands.findCutBefore)($from);
|
|
270
|
+
if (!$cut || !$cut.nodeBefore || !($cut.nodeBefore.type === listItem)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
var previousListItemEmpty = $cut.nodeBefore.childCount === 1 && $cut.nodeBefore.firstChild.nodeSize <= 2;
|
|
274
|
+
if (previousListItemEmpty) {
|
|
275
|
+
var tr = state.tr;
|
|
276
|
+
if (dispatch) {
|
|
277
|
+
dispatch(tr.delete($cut.pos - $cut.nodeBefore.nodeSize, $from.pos).scrollIntoView());
|
|
278
|
+
}
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
};
|
|
283
|
+
var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
|
|
284
|
+
var $from = state.selection.$from;
|
|
285
|
+
var _state$schema$nodes2 = state.schema.nodes,
|
|
286
|
+
paragraph = _state$schema$nodes2.paragraph,
|
|
287
|
+
listItem = _state$schema$nodes2.listItem,
|
|
288
|
+
codeBlock = _state$schema$nodes2.codeBlock,
|
|
289
|
+
bulletList = _state$schema$nodes2.bulletList,
|
|
290
|
+
orderedList = _state$schema$nodes2.orderedList;
|
|
291
|
+
var isGapCursorShown = state.selection instanceof _selection.GapCursorSelection;
|
|
292
|
+
var $cutPos = isGapCursorShown ? state.doc.resolve($from.pos + 1) : $from;
|
|
293
|
+
var $cut = (0, _commands.findCutBefore)($cutPos);
|
|
294
|
+
if (!$cut) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// see if the containing node is a list
|
|
299
|
+
if ($cut.nodeBefore && [bulletList, orderedList].indexOf($cut.nodeBefore.type) > -1) {
|
|
300
|
+
// and the node after this is a paragraph or a codeBlock
|
|
301
|
+
if ($cut.nodeAfter && ($cut.nodeAfter.type === paragraph || $cut.nodeAfter.type === codeBlock)) {
|
|
302
|
+
// find the nearest paragraph that precedes this node
|
|
303
|
+
var $lastNode = $cut.doc.resolve($cut.pos - 1);
|
|
304
|
+
while ($lastNode.parent.type !== paragraph) {
|
|
305
|
+
$lastNode = state.doc.resolve($lastNode.pos - 1);
|
|
306
|
+
}
|
|
307
|
+
var tr = state.tr;
|
|
308
|
+
if (isGapCursorShown) {
|
|
309
|
+
var nodeBeforePos = (0, _utils2.findPositionOfNodeBefore)(tr.selection);
|
|
310
|
+
if (typeof nodeBeforePos !== 'number') {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
// append the codeblock to the list node
|
|
314
|
+
var list = $cut.nodeBefore.copy($cut.nodeBefore.content.append(_model.Fragment.from(listItem.createChecked({}, $cut.nodeAfter))));
|
|
315
|
+
tr.replaceWith(nodeBeforePos, $from.pos + $cut.nodeAfter.nodeSize, list);
|
|
316
|
+
} else {
|
|
317
|
+
var step = (0, _lists.moveTargetIntoList)({
|
|
318
|
+
insertPosition: $lastNode.pos,
|
|
319
|
+
$target: $cut
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ED-13966: check if the step will cause an ProseMirror error
|
|
323
|
+
// if there's an error don't apply the step as it will might lead into a data loss.
|
|
324
|
+
// It doesn't play well with media being a leaf node.
|
|
325
|
+
var stepResult = state.tr.maybeStep(step);
|
|
326
|
+
if (stepResult.failed) {
|
|
327
|
+
return false;
|
|
328
|
+
} else {
|
|
329
|
+
tr = state.tr.step(step);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// find out if there's now another list following and join them
|
|
334
|
+
// as in, [list, p, list] => [list with p, list], and we want [joined list]
|
|
335
|
+
var $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
|
|
336
|
+
if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
|
|
337
|
+
tr = tr.join($postCut.pos);
|
|
338
|
+
}
|
|
339
|
+
if (dispatch) {
|
|
340
|
+
var _tr$doc$resolve$nodeB;
|
|
341
|
+
if (!((_tr$doc$resolve$nodeB = tr.doc.resolve($lastNode.pos).nodeBefore) !== null && _tr$doc$resolve$nodeB !== void 0 && _tr$doc$resolve$nodeB.isBlock) || tr.doc.resolve($lastNode.pos).nodeBefore === null) {
|
|
342
|
+
tr = tr.setSelection(_state.TextSelection.near(tr.doc.resolve(tr.mapping.map($cut.pos)), -1));
|
|
343
|
+
}
|
|
344
|
+
dispatch(tr.scrollIntoView());
|
|
345
|
+
}
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isFirstChildOfParent = void 0;
|
|
7
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
|
+
var isFirstChildOfParent = function isFirstChildOfParent(state) {
|
|
9
|
+
var $from = state.selection.$from;
|
|
10
|
+
return $from.depth > 1 ? state.selection instanceof _selection.GapCursorSelection && $from.parentOffset === 0 || $from.index($from.depth - 1) === 0 : true;
|
|
11
|
+
};
|
|
12
|
+
exports.isFirstChildOfParent = isFirstChildOfParent;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.joinListItemForward = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
+
var _joinListItemsForward = require("../actions/join-list-items-forward");
|
|
13
|
+
var joinListItemForward = function joinListItemForward(editorAnalyticsAPI) {
|
|
14
|
+
return function (state, dispatch) {
|
|
15
|
+
var tr = state.tr,
|
|
16
|
+
$head = state.selection.$head;
|
|
17
|
+
var walkNode = (0, _utils.walkNextNode)($head);
|
|
18
|
+
if (!(0, _utils.isEmptySelectionAtEnd)(state)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var scenarios = (0, _joinListItemsForward.calcJoinListScenario)(walkNode, $head);
|
|
22
|
+
if (!scenarios) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
var _scenarios = (0, _slicedToArray2.default)(scenarios, 2),
|
|
26
|
+
scenario = _scenarios[0],
|
|
27
|
+
action = _scenarios[1];
|
|
28
|
+
var result = action({
|
|
29
|
+
tr: tr,
|
|
30
|
+
$next: walkNode.$pos,
|
|
31
|
+
$head: $head
|
|
32
|
+
});
|
|
33
|
+
if (!result) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
37
|
+
bulletList = _state$schema$nodes.bulletList,
|
|
38
|
+
orderedList = _state$schema$nodes.orderedList;
|
|
39
|
+
var listParent = (0, _utils2.findParentNodeOfType)([bulletList, orderedList])(tr.selection);
|
|
40
|
+
var actionSubjectId = _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET;
|
|
41
|
+
if (listParent && listParent.node.type === orderedList) {
|
|
42
|
+
actionSubjectId = _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
|
|
43
|
+
}
|
|
44
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
45
|
+
action: _analytics.ACTION.LIST_ITEM_JOINED,
|
|
46
|
+
actionSubject: _analytics.ACTION_SUBJECT.LIST,
|
|
47
|
+
actionSubjectId: actionSubjectId,
|
|
48
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
49
|
+
attributes: {
|
|
50
|
+
inputMethod: _analytics.INPUT_METHOD.KEYBOARD,
|
|
51
|
+
direction: _analytics.DELETE_DIRECTION.FORWARD,
|
|
52
|
+
scenario: scenario
|
|
53
|
+
}
|
|
54
|
+
})(tr);
|
|
55
|
+
if (dispatch) {
|
|
56
|
+
dispatch(tr);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.joinListItemForward = joinListItemForward;
|