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