@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
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
+
},
|
|
6
|
+
overrides: [
|
|
7
|
+
{
|
|
8
|
+
files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
|
|
9
|
+
rules: {
|
|
10
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-list
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`8e9c21af71d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8e9c21af71d) - Extracting list plugin code from editor-core to @atlaskit/editor-plugin-list.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 0.2.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -4,6 +4,6 @@ List plugin for @atlaskit/editor-core
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
`import
|
|
7
|
+
`import { listPlugin } from '@atlaskit/editor-plugin-list';`
|
|
8
8
|
|
|
9
9
|
Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-list).
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertListType = convertListType;
|
|
7
|
+
var _lists = require("@atlaskit/editor-common/lists");
|
|
8
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
9
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
13
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
14
|
+
var _find = require("../utils/find");
|
|
15
|
+
function convertListType(_ref) {
|
|
16
|
+
var tr = _ref.tr,
|
|
17
|
+
nextListNodeType = _ref.nextListNodeType;
|
|
18
|
+
var doc = tr.doc,
|
|
19
|
+
_tr$selection = tr.selection,
|
|
20
|
+
$from = _tr$selection.$from,
|
|
21
|
+
$to = _tr$selection.$to;
|
|
22
|
+
var listRange;
|
|
23
|
+
if (tr.selection instanceof _selection.GapCursorSelection) {
|
|
24
|
+
var _$from$nodeAfter;
|
|
25
|
+
var nodeSize = ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.nodeSize) || 1;
|
|
26
|
+
listRange = $from.blockRange($from.doc.resolve($from.pos + nodeSize));
|
|
27
|
+
} else {
|
|
28
|
+
listRange = $from.blockRange($to, _utils.isListNode);
|
|
29
|
+
}
|
|
30
|
+
if (listRange) {
|
|
31
|
+
return convertSelectedList({
|
|
32
|
+
tr: tr,
|
|
33
|
+
nextListNodeType: nextListNodeType
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
var nodeRangeAroundList = $from.blockRange($to);
|
|
37
|
+
if (!nodeRangeAroundList) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var parentNode = nodeRangeAroundList.parent;
|
|
41
|
+
var startIndex = nodeRangeAroundList.startIndex,
|
|
42
|
+
endIndex = nodeRangeAroundList.endIndex,
|
|
43
|
+
depth = nodeRangeAroundList.depth;
|
|
44
|
+
|
|
45
|
+
// Checking for invalid nodes to prevent conversion
|
|
46
|
+
// eg. a panel cannot be wrapped in a list so return
|
|
47
|
+
// It will skip this check if the selection begins within a list
|
|
48
|
+
// This is to match the behaviour of the toolbar buttons being disabled
|
|
49
|
+
if (!(0, _find.findFirstParentListNode)($from)) {
|
|
50
|
+
for (var i = startIndex; i < endIndex; i++) {
|
|
51
|
+
var position = nodeRangeAroundList.$from.posAtIndex(i, depth);
|
|
52
|
+
var resolvedPosition = doc.resolve(position);
|
|
53
|
+
var currentChild = parentNode.child(i);
|
|
54
|
+
var currentNodeRange = resolvedPosition.blockRange(tr.doc.resolve(position + currentChild.nodeSize));
|
|
55
|
+
if (currentNodeRange && !(0, _utils.isListNode)(currentChild) && !(0, _transform.findWrapping)(currentNodeRange, nextListNodeType)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Checking for any non list nodes and wrapping them in a list
|
|
62
|
+
// so they can be converted
|
|
63
|
+
tr.doc.nodesBetween(nodeRangeAroundList.start, nodeRangeAroundList.end, function (node, pos) {
|
|
64
|
+
// Skip over any nodes that are part of a list
|
|
65
|
+
if ((0, _find.findFirstParentListNode)(tr.doc.resolve(tr.mapping.map(pos)))) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The following applies to suitable nodes that are not within a list
|
|
70
|
+
var currentNodeNotWrappedInList = node;
|
|
71
|
+
var isNotAnEmptyParagraphAndIsParagraphOrLeafNode = !(0, _utils.isEmptyParagraph)(currentNodeNotWrappedInList) && (!node.type.isBlock || node.type.name === 'paragraph');
|
|
72
|
+
if (isNotAnEmptyParagraphAndIsParagraphOrLeafNode && nodeRangeAroundList) {
|
|
73
|
+
var remainingNodeRange = new _model.NodeRange(tr.doc.resolve(tr.mapping.map(pos)), tr.doc.resolve(tr.mapping.map(pos) + currentNodeNotWrappedInList.nodeSize), nodeRangeAroundList.depth);
|
|
74
|
+
convertAroundList({
|
|
75
|
+
tr: tr,
|
|
76
|
+
nextListNodeType: nextListNodeType,
|
|
77
|
+
nodeRange: remainingNodeRange
|
|
78
|
+
});
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
convertSelectedList({
|
|
83
|
+
tr: tr,
|
|
84
|
+
nextListNodeType: nextListNodeType
|
|
85
|
+
});
|
|
86
|
+
if (tr.docChanged) {
|
|
87
|
+
(0, _lists.joinSiblingLists)({
|
|
88
|
+
tr: tr,
|
|
89
|
+
forceListType: nextListNodeType
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var convertSelectedList = function convertSelectedList(_ref2) {
|
|
94
|
+
var tr = _ref2.tr,
|
|
95
|
+
nextListNodeType = _ref2.nextListNodeType;
|
|
96
|
+
var selection = tr.selection,
|
|
97
|
+
_tr$selection2 = tr.selection,
|
|
98
|
+
from = _tr$selection2.from,
|
|
99
|
+
to = _tr$selection2.to;
|
|
100
|
+
var codeBlock = tr.doc.type.schema.nodes.codeBlock;
|
|
101
|
+
// get the positions of all the leaf nodes within the selection
|
|
102
|
+
var nodePositions = [];
|
|
103
|
+
if (selection instanceof _state.TextSelection && selection.$cursor || selection instanceof _selection.GapCursorSelection) {
|
|
104
|
+
nodePositions.push(from);
|
|
105
|
+
} else {
|
|
106
|
+
// nodesBetween doesn't return leaf nodes that are outside of from and to
|
|
107
|
+
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
108
|
+
// isLeaf is false for empty codeBlock so adding additional check for childCount
|
|
109
|
+
if (!node.isLeaf && !(node.type === codeBlock && node.childCount === 0)) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
nodePositions.push(pos);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// use those positions to get the closest parent list nodes
|
|
117
|
+
nodePositions.reduce(function (acc, pos) {
|
|
118
|
+
var closestParentListNode = (0, _utils2.findParentNodeClosestToPos)(tr.doc.resolve(pos), _utils.isListNode);
|
|
119
|
+
if (!closestParentListNode) {
|
|
120
|
+
return acc;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// don't add duplicates if the parent has already been added into the array
|
|
124
|
+
var existingParent = acc.find(function (node) {
|
|
125
|
+
return node.pos === closestParentListNode.pos && node.start === closestParentListNode.start && node.depth === closestParentListNode.depth;
|
|
126
|
+
});
|
|
127
|
+
if (!existingParent) {
|
|
128
|
+
acc.push(closestParentListNode);
|
|
129
|
+
}
|
|
130
|
+
return acc;
|
|
131
|
+
}, []).forEach(function (item) {
|
|
132
|
+
tr.setNodeMarkup(item.pos, nextListNodeType);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
var convertAroundList = function convertAroundList(_ref3) {
|
|
136
|
+
var tr = _ref3.tr,
|
|
137
|
+
nextListNodeType = _ref3.nextListNodeType,
|
|
138
|
+
nodeRange = _ref3.nodeRange;
|
|
139
|
+
for (var i = nodeRange.endIndex - 1; i >= nodeRange.startIndex; i--) {
|
|
140
|
+
// @ts-ignore posAtIndex is a public API but has no type yet
|
|
141
|
+
var position = nodeRange.$from.posAtIndex(i, nodeRange.depth);
|
|
142
|
+
var resolvedPos = tr.doc.resolve(position + 1);
|
|
143
|
+
var range = resolvedPos.blockRange(resolvedPos);
|
|
144
|
+
if (!range) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var wrappings = (0, _transform.findWrapping)(range, nextListNodeType);
|
|
148
|
+
if (!range || !wrappings) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
tr.wrap(range, wrappings);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.indentListItemsSelected = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _lists = require("@atlaskit/editor-common/lists");
|
|
10
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
11
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
13
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
|
+
var _find = require("../utils/find");
|
|
15
|
+
var indentListItemsSelected = function indentListItemsSelected(tr) {
|
|
16
|
+
var originalSelection = tr.selection;
|
|
17
|
+
var normalizedSelection = (0, _lists.normalizeListItemsSelection)({
|
|
18
|
+
selection: originalSelection,
|
|
19
|
+
doc: tr.doc
|
|
20
|
+
});
|
|
21
|
+
var $from = normalizedSelection.$from,
|
|
22
|
+
$to = normalizedSelection.$to;
|
|
23
|
+
var range = calculateRange({
|
|
24
|
+
selection: normalizedSelection
|
|
25
|
+
});
|
|
26
|
+
if (!range) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var listItemsSelected = {
|
|
30
|
+
from: (0, _find.findFirstParentListItemNode)($from),
|
|
31
|
+
to: (0, _find.findFirstParentListItemNode)($to)
|
|
32
|
+
};
|
|
33
|
+
if (listItemsSelected.from === null || listItemsSelected.to === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
var resolvedPos = tr.doc.resolve(listItemsSelected.from.pos);
|
|
37
|
+
var listItemIndex = resolvedPos.index();
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
var positionListItemPosition = resolvedPos.posAtIndex(listItemIndex - 1);
|
|
40
|
+
var previousListItem = tr.doc.nodeAt(positionListItemPosition);
|
|
41
|
+
if (!previousListItem || !(0, _utils.isListItemNode)(previousListItem)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if ((0, _utils.isListItemNode)(previousListItem) && listItemIndex === 0) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var listItemSelectedCommonParent = range.parent;
|
|
48
|
+
var previousNestedList = (0, _utils.isListNode)(previousListItem.lastChild) ? previousListItem.lastChild : null;
|
|
49
|
+
var listNodeType = previousNestedList ? previousNestedList.type : listItemSelectedCommonParent.type;
|
|
50
|
+
var nestedList = listItemsSelected.to.node.lastChild;
|
|
51
|
+
var nestedItemsOffset = nestedList && (0, _utils.isListNode)(nestedList) ? nestedList.nodeSize : 0;
|
|
52
|
+
var from = listItemsSelected.from.pos;
|
|
53
|
+
var to = listItemsSelected.to.pos + listItemsSelected.to.node.nodeSize - nestedItemsOffset;
|
|
54
|
+
var _createIndentedListIt = createIndentedListItemsSlice({
|
|
55
|
+
tr: tr,
|
|
56
|
+
listNodeType: listNodeType,
|
|
57
|
+
range: range,
|
|
58
|
+
from: from,
|
|
59
|
+
to: to
|
|
60
|
+
}),
|
|
61
|
+
_createIndentedListIt2 = (0, _slicedToArray2.default)(_createIndentedListIt, 2),
|
|
62
|
+
sliceSelected = _createIndentedListIt2[0],
|
|
63
|
+
nestedListItemsLeftover = _createIndentedListIt2[1];
|
|
64
|
+
var hasPreviousNestedList = Boolean(previousNestedList);
|
|
65
|
+
var start = from - 1;
|
|
66
|
+
tr.replaceRange(hasPreviousNestedList ? start - 1 : start, range.end, sliceSelected);
|
|
67
|
+
var leftoverContentPosition = tr.mapping.map(to) - 2;
|
|
68
|
+
if (nestedListItemsLeftover.openStart === 0) {
|
|
69
|
+
tr.insert(leftoverContentPosition, nestedListItemsLeftover.content);
|
|
70
|
+
} else {
|
|
71
|
+
tr.replace(leftoverContentPosition - nestedListItemsLeftover.openStart, leftoverContentPosition - nestedListItemsLeftover.openStart, nestedListItemsLeftover);
|
|
72
|
+
}
|
|
73
|
+
var nextSelection = calculateNewSelection({
|
|
74
|
+
originalSelection: originalSelection,
|
|
75
|
+
normalizedSelection: normalizedSelection,
|
|
76
|
+
tr: tr,
|
|
77
|
+
hasPreviousNestedList: hasPreviousNestedList
|
|
78
|
+
});
|
|
79
|
+
tr.setSelection(nextSelection);
|
|
80
|
+
};
|
|
81
|
+
exports.indentListItemsSelected = indentListItemsSelected;
|
|
82
|
+
var calculateRange = function calculateRange(_ref) {
|
|
83
|
+
var selection = _ref.selection;
|
|
84
|
+
var $from = selection.$from,
|
|
85
|
+
$to = selection.$to;
|
|
86
|
+
var range = $from.blockRange($to, _utils.isListNode);
|
|
87
|
+
if (!range) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return range;
|
|
91
|
+
};
|
|
92
|
+
var calculateNewSelection = function calculateNewSelection(_ref2) {
|
|
93
|
+
var tr = _ref2.tr,
|
|
94
|
+
normalizedSelection = _ref2.normalizedSelection,
|
|
95
|
+
originalSelection = _ref2.originalSelection,
|
|
96
|
+
hasPreviousNestedList = _ref2.hasPreviousNestedList;
|
|
97
|
+
var offset = hasPreviousNestedList ? 2 : 0;
|
|
98
|
+
var $from = normalizedSelection.$from,
|
|
99
|
+
$to = normalizedSelection.$to;
|
|
100
|
+
if (normalizedSelection instanceof _selection.GapCursorSelection) {
|
|
101
|
+
var _nextSelectionFrom = tr.doc.resolve($from.pos - offset);
|
|
102
|
+
return new _selection.GapCursorSelection(_nextSelectionFrom, normalizedSelection.side);
|
|
103
|
+
}
|
|
104
|
+
if (originalSelection instanceof _state.NodeSelection) {
|
|
105
|
+
return _state.NodeSelection.create(tr.doc, $from.pos - offset);
|
|
106
|
+
}
|
|
107
|
+
var _Selection$near = _state.Selection.near(tr.doc.resolve($from.pos - offset)),
|
|
108
|
+
nextSelectionFrom = _Selection$near.$from;
|
|
109
|
+
var _Selection$near2 = _state.Selection.near(tr.doc.resolve($to.pos - offset), -1),
|
|
110
|
+
nextSelectionTo = _Selection$near2.$to;
|
|
111
|
+
return new _state.TextSelection(nextSelectionFrom, nextSelectionTo);
|
|
112
|
+
};
|
|
113
|
+
var createIndentedListItemsSlice = function createIndentedListItemsSlice(_ref3) {
|
|
114
|
+
var tr = _ref3.tr,
|
|
115
|
+
from = _ref3.from,
|
|
116
|
+
to = _ref3.to,
|
|
117
|
+
listNodeType = _ref3.listNodeType,
|
|
118
|
+
range = _ref3.range;
|
|
119
|
+
var listItemsSlice = tr.doc.slice(from, to - 2);
|
|
120
|
+
var listFragment = _model.Fragment.from(listNodeType.create(null, listItemsSlice.content));
|
|
121
|
+
var nonSelectedListItemsSlice = tr.doc.slice(to, range.end - 2);
|
|
122
|
+
var openStart = tr.doc.slice(from - 1, range.end).openStart;
|
|
123
|
+
var slice = new _model.Slice(listFragment, openStart, 0);
|
|
124
|
+
return [slice, nonSelectedListItemsSlice];
|
|
125
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.indentList = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
9
|
+
// adapted from https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js#L206:L231
|
|
10
|
+
var indentList = function indentList(tr) {
|
|
11
|
+
var _tr$selection = tr.selection,
|
|
12
|
+
$from = _tr$selection.$from,
|
|
13
|
+
$to = _tr$selection.$to;
|
|
14
|
+
var listItem = tr.doc.type.schema.nodes.listItem;
|
|
15
|
+
var range = $from.blockRange($to, function (node) {
|
|
16
|
+
return !!node.childCount && !!node.firstChild && node.firstChild.type === listItem;
|
|
17
|
+
});
|
|
18
|
+
if (!range) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// get the index of the selected list item in the list it is part of
|
|
23
|
+
var startIndex = range.startIndex;
|
|
24
|
+
if (startIndex === 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// get the parent list of the list item(s) in the selected range
|
|
29
|
+
var parent = range.parent;
|
|
30
|
+
|
|
31
|
+
// get the list immediately before the selection start
|
|
32
|
+
var previousListItem = parent.child(startIndex - 1);
|
|
33
|
+
if (previousListItem.type !== listItem) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// if that list was nested, join the selected list items into the same
|
|
38
|
+
// nested list; if not, create a new child list of the same type and
|
|
39
|
+
// nest it under the current level
|
|
40
|
+
var isPreviousListNested = previousListItem.lastChild && ['bulletList', 'orderedList'].includes(previousListItem.lastChild.type.name);
|
|
41
|
+
var inner = _model.Fragment.from(isPreviousListNested ? listItem.create() : undefined);
|
|
42
|
+
var nextListNodeType = isPreviousListNested ? previousListItem.lastChild.type : parent.type;
|
|
43
|
+
var nextListNodeContent = _model.Fragment.from(nextListNodeType.create(null, inner));
|
|
44
|
+
var slice = new _model.Slice(_model.Fragment.from(listItem.create(null, nextListNodeContent)), isPreviousListNested ? 3 : 1, 0);
|
|
45
|
+
var before = range.start;
|
|
46
|
+
var after = range.end;
|
|
47
|
+
tr.step(new _transform.ReplaceAroundStep(before - (isPreviousListNested ? 3 : 1), after, before, after, slice, 1, true));
|
|
48
|
+
};
|
|
49
|
+
exports.indentList = indentList;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calcJoinListScenario = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
+
var _selection = require("../utils/selection");
|
|
10
|
+
var _joinListItemsScenarios = require("./join-list-items-scenarios");
|
|
11
|
+
var calcJoinListScenario = function calcJoinListScenario(walkNode, $head) {
|
|
12
|
+
var $next = walkNode.$pos,
|
|
13
|
+
nextFoundNode = walkNode.foundNode;
|
|
14
|
+
var headParent = $head.parent;
|
|
15
|
+
var headGrandParent = $head.node(-1);
|
|
16
|
+
var headInList = (0, _selection.isPosInsideList)($head);
|
|
17
|
+
var headInParagraph = (0, _selection.isPosInsideParagraph)($head);
|
|
18
|
+
var headInLastNonListChild = headGrandParent && headGrandParent.lastChild && (headGrandParent.lastChild === headParent || headGrandParent.childCount > 1 && headGrandParent.child(headGrandParent.childCount - 2) === headParent &&
|
|
19
|
+
//find the second last child if a list item may be the last child
|
|
20
|
+
(0, _utils.isListNode)(headGrandParent.lastChild));
|
|
21
|
+
var nextInList = (0, _selection.isPosInsideList)($next);
|
|
22
|
+
var nextInParagraph = (0, _selection.isPosInsideParagraph)($next);
|
|
23
|
+
if (!headInList && headInParagraph && nextInList) {
|
|
24
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_LIST_ITEM_WITH_PARAGRAPH, _joinListItemsScenarios.joinListItemWithParagraph];
|
|
25
|
+
}
|
|
26
|
+
if (!nextFoundNode || !headInList || !headInParagraph || !headInLastNonListChild) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!nextInList && nextInParagraph) {
|
|
30
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_PARAGRAPH_WITH_LIST, _joinListItemsScenarios.joinParagrapWithList];
|
|
31
|
+
}
|
|
32
|
+
if (!nextInList) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var nextNodeAfter = $next.nodeAfter;
|
|
36
|
+
var nextGrandParent = $next.node(-1);
|
|
37
|
+
var headGreatGrandParent = $head.node(-2);
|
|
38
|
+
var nextInListItem = (0, _utils.isListItemNode)($next.parent);
|
|
39
|
+
var nextNodeAfterListItem = (0, _utils.isListItemNode)(nextNodeAfter);
|
|
40
|
+
var nextListItemHasFirstChildParagraph = nextNodeAfter &&
|
|
41
|
+
//Redundant check but the linter complains otherwise
|
|
42
|
+
nextNodeAfterListItem && (0, _utils.isParagraphNode)(nextNodeAfter.firstChild);
|
|
43
|
+
if (!nextInListItem && nextListItemHasFirstChildParagraph) {
|
|
44
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_DESCENDANT_TO_PARENT, _joinListItemsScenarios.joinNestedListWithParentListItem];
|
|
45
|
+
}
|
|
46
|
+
if (!nextInListItem) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
var nextParentSiblingOfHeadParent = nextGrandParent && nextGrandParent === headGreatGrandParent;
|
|
50
|
+
var nextNodeAfterIsParagraph = (0, _utils.isParagraphNode)(nextNodeAfter);
|
|
51
|
+
if (!nextNodeAfterIsParagraph) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (nextParentSiblingOfHeadParent) {
|
|
55
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_SIBLINGS, _joinListItemsScenarios.joinSiblingListItems];
|
|
56
|
+
}
|
|
57
|
+
return [_analytics.LIST_TEXT_SCENARIOS.JOIN_PARENT_SIBLING_TO_PARENT_CHILD, _joinListItemsScenarios.joinListItemWithParentNestedList];
|
|
58
|
+
};
|
|
59
|
+
exports.calcJoinListScenario = calcJoinListScenario;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "joinListItemWithParagraph", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _joinListItemWithParagraph.joinListItemWithParagraph;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "joinListItemWithParentNestedList", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _joinListItemWithParentNestedList.joinListItemWithParentNestedList;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "joinNestedListWithParentListItem", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _joinNestedListWithParentListItem.joinNestedListWithParentListItem;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "joinParagrapWithList", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _joinParagraphWithList.joinParagrapWithList;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "joinSiblingListItems", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _joinSiblingListItems.joinSiblingListItems;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _joinParagraphWithList = require("./join-paragraph-with-list");
|
|
37
|
+
var _joinSiblingListItems = require("./join-sibling-list-items");
|
|
38
|
+
var _joinNestedListWithParentListItem = require("./join-nested-list-with-parent-list-item");
|
|
39
|
+
var _joinListItemWithParentNestedList = require("./join-list-item-with-parent-nested-list");
|
|
40
|
+
var _joinListItemWithParagraph = require("./join-list-item-with-paragraph");
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.joinListItemWithParagraph = void 0;
|
|
7
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
9
|
+
// Case for when a users selection is at the end of a paragraph, the paragraph
|
|
10
|
+
// is followed by a list, and they delete forward
|
|
11
|
+
var joinListItemWithParagraph = function joinListItemWithParagraph(_ref) {
|
|
12
|
+
var tr = _ref.tr,
|
|
13
|
+
$next = _ref.$next,
|
|
14
|
+
$head = _ref.$head;
|
|
15
|
+
// For empty paragraphs before a list
|
|
16
|
+
if ($head.parent.content.size < 1) {
|
|
17
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
18
|
+
return tr.doc.resolve($head.pos);
|
|
19
|
+
}, [], [[$head.pos - 1, $head.pos]]);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
var paragraphPosition = $head.pos;
|
|
23
|
+
var list = tr.doc.nodeAt($next.pos - 1);
|
|
24
|
+
var firstListItem = tr.doc.nodeAt($next.pos);
|
|
25
|
+
if (!list || !firstListItem) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
var firstChildNodeOfFirstListItem = firstListItem.firstChild;
|
|
29
|
+
if (!firstChildNodeOfFirstListItem) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
var lastChildOfFirstListItem = firstListItem.lastChild;
|
|
33
|
+
var firstGrandchildOfFirstListItem = firstChildNodeOfFirstListItem.firstChild;
|
|
34
|
+
var firstListItemHasOneChildWithNoNestedLists = hasSingleChild(firstListItem) && firstChildNodeOfFirstListItem.childCount < 2 && $next.nodeAfter;
|
|
35
|
+
var firstListItemContainsParagraphAndNestedList = !hasSingleChild(firstListItem) && lastChildOfFirstListItem && (0, _utils.isListNode)(lastChildOfFirstListItem);
|
|
36
|
+
var insertions = [];
|
|
37
|
+
var deletions = [];
|
|
38
|
+
|
|
39
|
+
// For lists that only have one list item with no children - need to remove remaining list
|
|
40
|
+
if (hasSingleChild(list) && hasSingleChild(firstListItem) && $next.nodeAfter) {
|
|
41
|
+
deletions.push([tr.mapping.map($next.pos - 1), tr.mapping.map($next.pos + $next.nodeAfter.nodeSize + 1)]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// For first list items that have a paragraph and a list
|
|
45
|
+
if (firstListItemContainsParagraphAndNestedList) {
|
|
46
|
+
var firstListItemNestedList = _model.Fragment.from(lastChildOfFirstListItem.content);
|
|
47
|
+
insertions.push([firstListItemNestedList, tr.mapping.map($next.pos)]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// For first list item has one child & no nested lists OR first list items that have a paragraph and a list
|
|
51
|
+
if (firstListItemHasOneChildWithNoNestedLists || firstListItemContainsParagraphAndNestedList) {
|
|
52
|
+
deletions.push([tr.mapping.map($next.pos), tr.mapping.map($next.pos + firstListItem.nodeSize - 1)]);
|
|
53
|
+
var firstListItemText = _model.Fragment.from(firstChildNodeOfFirstListItem.content);
|
|
54
|
+
insertions.push([firstListItemText, paragraphPosition]);
|
|
55
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
56
|
+
return tr.doc.resolve($head.pos);
|
|
57
|
+
}, insertions, deletions);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// For any first list items that have multiple children (eg. multiple paragraphs)
|
|
62
|
+
if (firstListItem.childCount > 1) {
|
|
63
|
+
insertions.push([_model.Fragment.from(firstChildNodeOfFirstListItem.content), paragraphPosition]);
|
|
64
|
+
deletions.push([tr.mapping.map($next.pos + 1), tr.mapping.map($next.pos + firstChildNodeOfFirstListItem.nodeSize + 1)]);
|
|
65
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
66
|
+
return tr.doc.resolve($head.pos);
|
|
67
|
+
}, insertions, deletions);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// For any remaining first list items that have a single child (eg. single paragraph, multiple lines of text)
|
|
72
|
+
if (firstGrandchildOfFirstListItem && firstGrandchildOfFirstListItem.type.name === 'hardBreak') {
|
|
73
|
+
var nodeSizeOfGrandchild = firstGrandchildOfFirstListItem ? firstGrandchildOfFirstListItem.nodeSize : 0;
|
|
74
|
+
deletions.push([tr.mapping.map($next.pos + 2), tr.mapping.map($next.pos + 2 + nodeSizeOfGrandchild)]);
|
|
75
|
+
} else {
|
|
76
|
+
insertions.push([_model.Fragment.from(firstChildNodeOfFirstListItem.content), paragraphPosition]);
|
|
77
|
+
var nodeSizeOfFirstChild = firstChildNodeOfFirstListItem.nodeSize;
|
|
78
|
+
deletions.push([tr.mapping.map($next.pos), tr.mapping.map($next.pos + 2 + nodeSizeOfFirstChild)]);
|
|
79
|
+
}
|
|
80
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
81
|
+
return tr.doc.resolve($head.pos);
|
|
82
|
+
}, insertions, deletions);
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
exports.joinListItemWithParagraph = joinListItemWithParagraph;
|
|
86
|
+
var hasSingleChild = function hasSingleChild(node) {
|
|
87
|
+
return node.childCount === 1;
|
|
88
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.joinListItemWithParentNestedList = void 0;
|
|
7
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
|
+
//Case for two adjacent list items with the first being of greater indentation
|
|
9
|
+
var joinListItemWithParentNestedList = function joinListItemWithParentNestedList(_ref) {
|
|
10
|
+
var tr = _ref.tr,
|
|
11
|
+
$next = _ref.$next,
|
|
12
|
+
$head = _ref.$head;
|
|
13
|
+
/* CASE 4
|
|
14
|
+
* Initial Structure:
|
|
15
|
+
*
|
|
16
|
+
* List A {
|
|
17
|
+
* ListItem B {
|
|
18
|
+
* Paragraph C { text1 }
|
|
19
|
+
* ...Children D
|
|
20
|
+
* List E {
|
|
21
|
+
* ...
|
|
22
|
+
* List F { //May be multiple levels of lists
|
|
23
|
+
* ...Children G
|
|
24
|
+
* ListItem H { //Last node of the block
|
|
25
|
+
* ...Children I
|
|
26
|
+
* Paragraph J { text2 |$head||textInsertPos| } |childrenMInsertPos| //Cant have children since this ListItem is the last of the block
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ...
|
|
30
|
+
* |childrenOInsertPos| }
|
|
31
|
+
* }
|
|
32
|
+
* ListItem K { |$next|
|
|
33
|
+
* Paragraph L { text3 }
|
|
34
|
+
* ...Children M
|
|
35
|
+
* List? N {
|
|
36
|
+
* ...Children O
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* Converts to:
|
|
42
|
+
*
|
|
43
|
+
* List A {
|
|
44
|
+
* ListItem B {
|
|
45
|
+
* Paragraph C { text1 }
|
|
46
|
+
* ...Children D
|
|
47
|
+
* List E {
|
|
48
|
+
* ...
|
|
49
|
+
* List F {
|
|
50
|
+
* ...Children G
|
|
51
|
+
* ListItem H {
|
|
52
|
+
* ...Children I
|
|
53
|
+
* Paragraph J { text2text3 }
|
|
54
|
+
* ...Children M
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ...
|
|
58
|
+
* ...Children O
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
var listItemK = $next.parent; //List must have at least one child
|
|
66
|
+
if (!listItemK.firstChild || !listItemK.lastChild) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
var beforeListItemK = $next.before();
|
|
70
|
+
var afterListItemB = $next.before();
|
|
71
|
+
var afterListItemK = $next.after();
|
|
72
|
+
var containsChildrenO = (0, _utils.isListNode)(listItemK.lastChild);
|
|
73
|
+
var textInsertPos = $head.pos;
|
|
74
|
+
var childrenMInsertPos = $head.pos + 1;
|
|
75
|
+
var childrenOInsertPos = afterListItemB - 2;
|
|
76
|
+
var textContent = listItemK.firstChild.content;
|
|
77
|
+
var childrenMContent = containsChildrenO ? listItemK.content.cut(listItemK.firstChild.nodeSize, listItemK.nodeSize - listItemK.lastChild.nodeSize - 2 //Get the position before
|
|
78
|
+
) : listItemK.content.cut(listItemK.firstChild.nodeSize);
|
|
79
|
+
var childrenOContent = listItemK.lastChild.content;
|
|
80
|
+
(0, _utils.insertContentDeleteRange)(tr, function (tr) {
|
|
81
|
+
return tr.doc.resolve(textInsertPos);
|
|
82
|
+
}, containsChildrenO ? [[textContent, textInsertPos], [childrenMContent, childrenMInsertPos], [childrenOContent, childrenOInsertPos]] : [[textContent, textInsertPos], [childrenMContent, childrenMInsertPos]], [[beforeListItemK, afterListItemK]]);
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
exports.joinListItemWithParentNestedList = joinListItemWithParentNestedList;
|