@atlaskit/editor-plugin-tasks-and-decisions 8.0.2 → 8.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/pm-plugins/commands.js +14 -16
- package/dist/cjs/pm-plugins/helpers.js +100 -57
- package/dist/cjs/pm-plugins/keymaps.js +58 -38
- package/dist/cjs/pm-plugins/main.js +1 -1
- package/dist/cjs/pm-plugins/utils.js +34 -1
- package/dist/es2019/pm-plugins/commands.js +14 -12
- package/dist/es2019/pm-plugins/helpers.js +108 -53
- package/dist/es2019/pm-plugins/keymaps.js +62 -34
- package/dist/es2019/pm-plugins/main.js +2 -2
- package/dist/es2019/pm-plugins/utils.js +34 -0
- package/dist/esm/pm-plugins/commands.js +12 -14
- package/dist/esm/pm-plugins/helpers.js +100 -57
- package/dist/esm/pm-plugins/keymaps.js +60 -40
- package/dist/esm/pm-plugins/main.js +2 -2
- package/dist/esm/pm-plugins/utils.js +33 -0
- package/dist/types/pm-plugins/utils.d.ts +10 -0
- package/dist/types/ui/TaskListBlockMenuItem/TaskListBlockMenuItem.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +10 -0
- package/dist/types-ts4.5/ui/TaskListBlockMenuItem/TaskListBlockMenuItem.d.ts +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-tasks-and-decisions
|
|
2
2
|
|
|
3
|
+
## 8.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5b8be893d14b5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5b8be893d14b5) -
|
|
8
|
+
[EDITOR-1433] Handle deleting blockTaskItems with backspace and refactor to remove iterative depth
|
|
9
|
+
search for blockTaskItems and instead use position logic to get the relevant nodes
|
|
10
|
+
- [`68424716235d0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/68424716235d0) -
|
|
11
|
+
[ux] EDITOR-1156 Allow checkbox in blockTaskItem node to be selected with keyboard arrows
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 8.0.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 8.0.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -5,13 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.wrapSelectionInTaskList = exports.liftSelection = exports.joinAtCut = void 0;
|
|
7
7
|
var _commands = require("@atlaskit/editor-common/commands");
|
|
8
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
8
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
10
|
-
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
11
9
|
var _helpers = require("./helpers");
|
|
12
|
-
var
|
|
10
|
+
var _utils = require("./utils");
|
|
13
11
|
var liftSelection = exports.liftSelection = function liftSelection(state, dispatch) {
|
|
14
|
-
var normalizedSelection = (0,
|
|
12
|
+
var normalizedSelection = (0, _utils.normalizeTaskItemsSelection)(state.selection);
|
|
15
13
|
var $from = normalizedSelection.$from,
|
|
16
14
|
$to = normalizedSelection.$to;
|
|
17
15
|
var tr = (0, _helpers.liftBlock)(state.tr, $from, $to);
|
|
@@ -39,7 +37,7 @@ var liftSelection = exports.liftSelection = function liftSelection(state, dispat
|
|
|
39
37
|
* ```
|
|
40
38
|
*/
|
|
41
39
|
var wrapSelectionInTaskList = exports.wrapSelectionInTaskList = function wrapSelectionInTaskList(state, dispatch) {
|
|
42
|
-
var _normalizeTaskItemsSe = (0,
|
|
40
|
+
var _normalizeTaskItemsSe = (0, _utils.normalizeTaskItemsSelection)(state.selection),
|
|
43
41
|
$from = _normalizeTaskItemsSe.$from,
|
|
44
42
|
$to = _normalizeTaskItemsSe.$to;
|
|
45
43
|
|
|
@@ -49,17 +47,17 @@ var wrapSelectionInTaskList = exports.wrapSelectionInTaskList = function wrapSel
|
|
|
49
47
|
taskItem = _state$schema$nodes.taskItem,
|
|
50
48
|
blockTaskItem = _state$schema$nodes.blockTaskItem;
|
|
51
49
|
var maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, taskItem]);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
if (blockTaskItem) {
|
|
51
|
+
var resultOfFindBlockTaskItem = (0, _utils.findBlockTaskItem)($from);
|
|
52
|
+
if (resultOfFindBlockTaskItem) {
|
|
53
|
+
var hasParagraph = resultOfFindBlockTaskItem.hasParagraph;
|
|
54
|
+
// If the selection is inside a nested node inside the blockTaskItem
|
|
55
|
+
// Remove the difference in depth between the selection and the blockTaskItemNode
|
|
56
|
+
if (hasParagraph) {
|
|
57
|
+
maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, blockTaskItem]) - 1;
|
|
58
|
+
} else {
|
|
59
|
+
maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, blockTaskItem]);
|
|
60
|
+
}
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
if (maxDepth >= 6) {
|
|
@@ -16,13 +16,16 @@ exports.liftBlock = exports.isTable = exports.isInsideTaskOrDecisionItem = expor
|
|
|
16
16
|
exports.openRequestEditPopupAt = openRequestEditPopupAt;
|
|
17
17
|
exports.removeCheckboxFocus = removeCheckboxFocus;
|
|
18
18
|
exports.walkOut = exports.subtreeHeight = void 0;
|
|
19
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
19
20
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
20
21
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
21
22
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
22
23
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
23
24
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
25
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
24
26
|
var _pluginKey = require("./plugin-key");
|
|
25
27
|
var _types = require("./types");
|
|
28
|
+
var _utils3 = require("./utils");
|
|
26
29
|
var isInsideTaskOrDecisionItem = exports.isInsideTaskOrDecisionItem = function isInsideTaskOrDecisionItem(state) {
|
|
27
30
|
var _state$schema$nodes = state.schema.nodes,
|
|
28
31
|
decisionItem = _state$schema$nodes.decisionItem,
|
|
@@ -80,51 +83,52 @@ var getBlockRange = exports.getBlockRange = function getBlockRange(_ref) {
|
|
|
80
83
|
taskItem = _$from$doc$type$schem.taskItem,
|
|
81
84
|
blockTaskItem = _$from$doc$type$schem.blockTaskItem,
|
|
82
85
|
paragraph = _$from$doc$type$schem.paragraph;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var _$after = $to.doc.resolve(endNode + 1);
|
|
91
|
-
var _after = _$after.nodeAfter;
|
|
92
|
-
var lastNode = $to.node($to.depth);
|
|
93
|
-
var rangeDepth = blockTaskItemNode.depth - 1;
|
|
94
|
-
var endOfBlockRange = $to.start() + lastNode.nodeSize;
|
|
86
|
+
if (blockTaskItem) {
|
|
87
|
+
var result = (0, _utils3.findBlockTaskItem)($from);
|
|
88
|
+
if (result) {
|
|
89
|
+
var _$prevNode$nodeBefore;
|
|
90
|
+
var hasParagraph = result.hasParagraph;
|
|
91
|
+
var blockTaskItemDepth = hasParagraph ? $from.depth - 1 : $from.depth;
|
|
92
|
+
var blockRangeDepth = blockTaskItemDepth - 1;
|
|
95
93
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
_$after = $to.doc.resolve(endNode + 2);
|
|
99
|
-
_after = _$after.nodeAfter;
|
|
100
|
-
}
|
|
101
|
-
// Otherwise assume it's a block node so increase the range depth
|
|
102
|
-
else {
|
|
103
|
-
rangeDepth = rangeDepth - 1;
|
|
104
|
-
endOfBlockRange = endOfBlockRange - 1;
|
|
105
|
-
}
|
|
94
|
+
// Calculate start position of the block range
|
|
95
|
+
var startPos = $from.start(blockTaskItemDepth) - 1;
|
|
106
96
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
// Calculate end position and get node after the current selection
|
|
98
|
+
var endPos = $to.end();
|
|
99
|
+
var _$after = $to.doc.resolve(endPos + 1);
|
|
100
|
+
var afterNode = _$after.nodeAfter;
|
|
101
|
+
var lastNode = $to.node($to.depth);
|
|
102
|
+
var endRangePos = $to.start() + lastNode.nodeSize;
|
|
103
|
+
|
|
104
|
+
// Make adjustments for paragraph nodes
|
|
105
|
+
if (lastNode.type === paragraph) {
|
|
106
|
+
_$after = $to.doc.resolve(endPos + 2);
|
|
107
|
+
afterNode = _$after.nodeAfter;
|
|
108
|
+
} else {
|
|
109
|
+
blockRangeDepth--;
|
|
110
|
+
endRangePos--;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Extend range if there's a sibling taskList
|
|
114
|
+
if (afterNode && afterNode.type === taskList && _$after.depth === blockTaskItemDepth - 1) {
|
|
115
|
+
endRangePos += afterNode.nodeSize;
|
|
116
|
+
}
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
// Check if preceded by another taskItem/blockTaskItem
|
|
119
|
+
var $prevNode = $from.doc.resolve(startPos - 1);
|
|
120
|
+
var prevNodeSize = ((_$prevNode$nodeBefore = $prevNode.nodeBefore) === null || _$prevNode$nodeBefore === void 0 ? void 0 : _$prevNode$nodeBefore.nodeSize) || 0;
|
|
121
|
+
var $prevNodeParent = $from.doc.resolve($prevNode.pos - prevNodeSize - 1);
|
|
122
|
+
var prevNodeParent = $prevNodeParent.nodeAfter;
|
|
123
|
+
if (prevNodeParent && [blockTaskItem, taskItem].includes(prevNodeParent.type)) {
|
|
124
|
+
blockRangeDepth = blockTaskItemDepth - 1;
|
|
125
|
+
endRangePos -= 2;
|
|
126
|
+
startPos += 1;
|
|
127
|
+
}
|
|
117
128
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
rangeDepth = blockTaskItemNode.depth - 1;
|
|
121
|
-
endOfBlockRange = endOfBlockRange - 2;
|
|
122
|
-
startOfBlockRange = startOfBlockRange + 1;
|
|
129
|
+
// Create and return the NodeRange
|
|
130
|
+
return new _model.NodeRange($to.doc.resolve(startPos), $to.doc.resolve(endRangePos), blockRangeDepth);
|
|
123
131
|
}
|
|
124
|
-
var $endOfBlockRange = $to.doc.resolve(endOfBlockRange);
|
|
125
|
-
var $startOfBlockRange = $to.doc.resolve(startOfBlockRange);
|
|
126
|
-
var nodeRange = new _model.NodeRange($startOfBlockRange, $endOfBlockRange, rangeDepth);
|
|
127
|
-
return nodeRange;
|
|
128
132
|
}
|
|
129
133
|
var end = $to.end();
|
|
130
134
|
var $after = $to.doc.resolve(end + 1);
|
|
@@ -300,29 +304,45 @@ function getTaskItemDataAtPos(view) {
|
|
|
300
304
|
var selection = state.selection,
|
|
301
305
|
schema = state.schema;
|
|
302
306
|
var $from = selection.$from;
|
|
303
|
-
|
|
307
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true)) {
|
|
308
|
+
var _schema$nodes = schema.nodes,
|
|
309
|
+
taskItem = _schema$nodes.taskItem,
|
|
310
|
+
blockTaskItem = _schema$nodes.blockTaskItem;
|
|
311
|
+
var maybeTask = (0, _utils2.findParentNodeOfTypeClosestToPos)($from, [taskItem, blockTaskItem]);
|
|
304
312
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
313
|
+
// current selection has to be inside taskitem
|
|
314
|
+
if (maybeTask) {
|
|
315
|
+
return {
|
|
316
|
+
pos: maybeTask === null || maybeTask === void 0 ? void 0 : maybeTask.pos,
|
|
317
|
+
localId: maybeTask === null || maybeTask === void 0 ? void 0 : maybeTask.node.attrs.localId
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
var isInTaskItem = $from.node().type === schema.nodes.taskItem;
|
|
322
|
+
|
|
323
|
+
// current selection has to be inside taskitem
|
|
324
|
+
if (isInTaskItem) {
|
|
325
|
+
var taskItemPos = $from.before();
|
|
326
|
+
return {
|
|
327
|
+
pos: taskItemPos,
|
|
328
|
+
localId: $from.node().attrs.localId
|
|
329
|
+
};
|
|
330
|
+
}
|
|
312
331
|
}
|
|
313
332
|
}
|
|
314
333
|
function getAllTaskItemsDataInRootTaskList(view) {
|
|
315
334
|
var state = view.state;
|
|
316
335
|
var schema = state.schema;
|
|
317
336
|
var $fromPos = state.selection.$from;
|
|
318
|
-
var isInTaskItem = $fromPos.node().type === schema.nodes.taskItem;
|
|
337
|
+
var isInTaskItem = (0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) ? isInsideTask(state) : $fromPos.node().type === schema.nodes.taskItem;
|
|
319
338
|
// if not inside task item then return undefined;
|
|
320
339
|
if (!isInTaskItem) {
|
|
321
340
|
return;
|
|
322
341
|
}
|
|
323
|
-
var _schema$
|
|
324
|
-
taskList = _schema$
|
|
325
|
-
taskItem = _schema$
|
|
342
|
+
var _schema$nodes2 = schema.nodes,
|
|
343
|
+
taskList = _schema$nodes2.taskList,
|
|
344
|
+
taskItem = _schema$nodes2.taskItem,
|
|
345
|
+
blockTaskItem = _schema$nodes2.blockTaskItem;
|
|
326
346
|
var rootTaskListData = (0, _utils.findFarthestParentNode)(function (node) {
|
|
327
347
|
return node.type === taskList;
|
|
328
348
|
})($fromPos);
|
|
@@ -331,7 +351,7 @@ function getAllTaskItemsDataInRootTaskList(view) {
|
|
|
331
351
|
var rootTaskListStartPos = rootTaskListData.start;
|
|
332
352
|
var allTaskItems = [];
|
|
333
353
|
rootTaskList.descendants(function (node, pos, parent, index) {
|
|
334
|
-
if (node.type === taskItem) {
|
|
354
|
+
if (node.type === taskItem || (0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) && blockTaskItem && node.type === blockTaskItem) {
|
|
335
355
|
allTaskItems.push({
|
|
336
356
|
node: node,
|
|
337
357
|
pos: pos + rootTaskListStartPos,
|
|
@@ -343,17 +363,27 @@ function getAllTaskItemsDataInRootTaskList(view) {
|
|
|
343
363
|
}
|
|
344
364
|
}
|
|
345
365
|
function getCurrentTaskItemIndex(view, allTaskItems) {
|
|
366
|
+
var _findParentNodeOfType;
|
|
346
367
|
var state = view.state;
|
|
368
|
+
var schema = state.schema;
|
|
369
|
+
var _schema$nodes3 = schema.nodes,
|
|
370
|
+
taskItem = _schema$nodes3.taskItem,
|
|
371
|
+
blockTaskItem = _schema$nodes3.blockTaskItem;
|
|
347
372
|
var $fromPos = state.selection.$from;
|
|
348
373
|
var allTaskItemNodes = allTaskItems.map(function (nodeData) {
|
|
349
374
|
return nodeData.node;
|
|
350
375
|
});
|
|
351
|
-
var currentTaskItem = $fromPos.node($fromPos.depth);
|
|
352
|
-
|
|
353
|
-
|
|
376
|
+
var currentTaskItem = (0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) ? (_findParentNodeOfType = (0, _utils2.findParentNodeOfTypeClosestToPos)($fromPos, [taskItem, blockTaskItem])) === null || _findParentNodeOfType === void 0 ? void 0 : _findParentNodeOfType.node : $fromPos.node($fromPos.depth);
|
|
377
|
+
if (currentTaskItem) {
|
|
378
|
+
var currentTaskItemIndex = allTaskItemNodes.indexOf(currentTaskItem);
|
|
379
|
+
return currentTaskItemIndex;
|
|
380
|
+
} else {
|
|
381
|
+
return -1;
|
|
382
|
+
}
|
|
354
383
|
}
|
|
355
384
|
function getTaskItemDataToFocus(view, direction) {
|
|
356
385
|
var allTaskItems = getAllTaskItemsDataInRootTaskList(view);
|
|
386
|
+
|
|
357
387
|
// if not inside task item then allTaskItems will be undefined;
|
|
358
388
|
if (!allTaskItems) {
|
|
359
389
|
return;
|
|
@@ -383,13 +413,26 @@ function focusCheckbox(view, taskItemData) {
|
|
|
383
413
|
}
|
|
384
414
|
}
|
|
385
415
|
function focusCheckboxAndUpdateSelection(view, taskItemData) {
|
|
416
|
+
var _doc$resolve$nodeAfte, _doc$resolve$nodeAfte2;
|
|
386
417
|
var pos = taskItemData.pos,
|
|
387
418
|
localId = taskItemData.localId;
|
|
388
419
|
var state = view.state,
|
|
389
420
|
dispatch = view.dispatch;
|
|
390
421
|
var doc = state.doc;
|
|
422
|
+
var schema = state.schema;
|
|
423
|
+
var extension = schema.nodes.extension;
|
|
391
424
|
var tr = state.tr;
|
|
392
|
-
|
|
425
|
+
|
|
426
|
+
// if there's an extension at this position, we're in a blockTaskItem, set a gapCursor
|
|
427
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) && extension && ((_doc$resolve$nodeAfte = doc.resolve(pos + 1).nodeAfter) === null || _doc$resolve$nodeAfte === void 0 ? void 0 : _doc$resolve$nodeAfte.type) === extension) {
|
|
428
|
+
tr.setSelection(new _selection.GapCursorSelection(doc.resolve(pos + 1)));
|
|
429
|
+
// if there's a textblock at this position, we're in a blockTaskItem, add an extra hop into the content
|
|
430
|
+
} else if ((0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) && (_doc$resolve$nodeAfte2 = doc.resolve(pos + 1).nodeAfter) !== null && _doc$resolve$nodeAfte2 !== void 0 && _doc$resolve$nodeAfte2.isTextblock) {
|
|
431
|
+
tr.setSelection(new _state.TextSelection(doc.resolve(pos + 2)));
|
|
432
|
+
// else, this is an ordinary task item with inline content
|
|
433
|
+
} else {
|
|
434
|
+
tr.setSelection(new _state.TextSelection(doc.resolve(pos + 1)));
|
|
435
|
+
}
|
|
393
436
|
tr.setMeta(_pluginKey.stateKey, {
|
|
394
437
|
action: _types.ACTIONS.FOCUS_BY_LOCALID,
|
|
395
438
|
data: localId
|
|
@@ -12,6 +12,7 @@ var _steps = require("@atlaskit/adf-schema/steps");
|
|
|
12
12
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
13
|
var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
|
|
14
14
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
15
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
15
16
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
17
|
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
17
18
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
@@ -151,10 +152,8 @@ var backspaceFrom = function backspaceFrom(editorAnalyticsAPI) {
|
|
|
151
152
|
if ((0, _expValEquals.expValEquals)('editor_refactor_backspace_task_and_decisions', 'isEnabled', true)) {
|
|
152
153
|
var _nodeBefore$firstChil, _nodeBefore$firstChil2;
|
|
153
154
|
// Check if selection is inside a blockTaskItem paragraph
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
})($from);
|
|
157
|
-
var isInBlockTaskItemParagraph = !!blockTaskItemNode && $from.parent.type === paragraph;
|
|
155
|
+
var resultOfFindBlockTaskItem = (0, _utils3.findBlockTaskItem)($from);
|
|
156
|
+
var isInBlockTaskItemParagraph = resultOfFindBlockTaskItem && (resultOfFindBlockTaskItem === null || resultOfFindBlockTaskItem === void 0 ? void 0 : resultOfFindBlockTaskItem.hasParagraph);
|
|
158
157
|
|
|
159
158
|
// Get the node before the current position
|
|
160
159
|
var beforePos = isInBlockTaskItemParagraph ? $from.before() - 1 : $from.before();
|
|
@@ -192,12 +191,25 @@ var backspaceFrom = function backspaceFrom(editorAnalyticsAPI) {
|
|
|
192
191
|
if (actionDecisionFollowsOrNothing($from)) {
|
|
193
192
|
if (dispatch) {
|
|
194
193
|
var taskContent = state.doc.slice($from.start(), $from.end()).content;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
var slice;
|
|
195
|
+
try {
|
|
196
|
+
slice = taskContent.size ? paragraph.createChecked(undefined, taskContent) : paragraph.createChecked();
|
|
197
|
+
// might be end of document after
|
|
198
|
+
var tr = splitListItemWith(state.tr, slice, $from, true);
|
|
199
|
+
dispatch(tr);
|
|
200
|
+
return true;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
// If there's an error creating a paragraph, then just pass the content as is
|
|
203
|
+
// Block task item's can have non-text content that cannot be wrapped in a paragraph
|
|
204
|
+
if (blockTaskItem) {
|
|
205
|
+
// Create an array from the fragment to pass into splitListItemWith, as the `content` property is readonly
|
|
206
|
+
slice = Array.from(taskContent.content);
|
|
207
|
+
var _tr = splitListItemWith(state.tr, slice, $from, true);
|
|
208
|
+
dispatch(_tr);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
199
212
|
}
|
|
200
|
-
return true;
|
|
201
213
|
}
|
|
202
214
|
return false;
|
|
203
215
|
};
|
|
@@ -289,7 +301,6 @@ var splitListItemWith = function splitListItemWith(tr, content, $from, setSelect
|
|
|
289
301
|
var origDoc = tr.doc;
|
|
290
302
|
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
|
|
291
303
|
blockTaskItem = _tr$doc$type$schema$n.blockTaskItem,
|
|
292
|
-
paragraph = _tr$doc$type$schema$n.paragraph,
|
|
293
304
|
taskList = _tr$doc$type$schema$n.taskList;
|
|
294
305
|
var baseDepth = $from.depth;
|
|
295
306
|
var $oldAfter = origDoc.resolve($from.after());
|
|
@@ -297,36 +308,40 @@ var splitListItemWith = function splitListItemWith(tr, content, $from, setSelect
|
|
|
297
308
|
var replaceFromModifier = 0;
|
|
298
309
|
var replaceToModifier = 0;
|
|
299
310
|
var deleteBlockModifier = 0;
|
|
311
|
+
var isGapCursorSelection = false;
|
|
300
312
|
if (blockTaskItem) {
|
|
301
|
-
var
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
313
|
+
var result = (0, _utils3.findBlockTaskItem)($from);
|
|
314
|
+
if (result) {
|
|
315
|
+
var blockTaskItemNode = result.blockTaskItemNode,
|
|
316
|
+
hasParagraph = result.hasParagraph;
|
|
317
|
+
if (blockTaskItemNode) {
|
|
318
|
+
var _$oldAfter$nodeAfter, _$posPreviousSibling$;
|
|
319
|
+
// If the case there is a paragraph in the block task item we need to
|
|
320
|
+
// adjust some calculations
|
|
321
|
+
if (hasParagraph) {
|
|
322
|
+
baseDepth = $from.depth - 1;
|
|
323
|
+
$oldAfter = origDoc.resolve($from.after() + 1);
|
|
324
|
+
|
|
325
|
+
// When we're removing the extra empty task item we need to reduce the range a bit
|
|
326
|
+
deleteBlockModifier = 2;
|
|
327
|
+
} else {
|
|
328
|
+
textSelectionModifier = 1;
|
|
329
|
+
isGapCursorSelection = true;
|
|
330
|
+
}
|
|
312
331
|
textSelectionModifier = 1;
|
|
332
|
+
var hasSiblingTaskList = ((_$oldAfter$nodeAfter = $oldAfter.nodeAfter) === null || _$oldAfter$nodeAfter === void 0 ? void 0 : _$oldAfter$nodeAfter.type) === taskList;
|
|
333
|
+
if (hasSiblingTaskList) {
|
|
334
|
+
// Make sure we're wrapping around the whole list
|
|
335
|
+
replaceToModifier = hasParagraph ? 3 : 1;
|
|
336
|
+
}
|
|
337
|
+
var posPreviousSibling = $from.start(hasParagraph ? $from.depth - 1 : $from.depth) - 1;
|
|
338
|
+
var $posPreviousSibling = tr.doc.resolve(posPreviousSibling);
|
|
339
|
+
var hasPreviousTaskItem = ((_$posPreviousSibling$ = $posPreviousSibling.nodeBefore) === null || _$posPreviousSibling$ === void 0 ? void 0 : _$posPreviousSibling$.type) === blockTaskItem;
|
|
340
|
+
if (!hasPreviousTaskItem && hasParagraph) {
|
|
341
|
+
// Go down one step to get to the doc node
|
|
342
|
+
replaceFromModifier = 1;
|
|
343
|
+
}
|
|
313
344
|
}
|
|
314
|
-
var hasSiblingTaskList = ((_$oldAfter$nodeAfter = $oldAfter.nodeAfter) === null || _$oldAfter$nodeAfter === void 0 ? void 0 : _$oldAfter$nodeAfter.type) === taskList;
|
|
315
|
-
if (hasSiblingTaskList) {
|
|
316
|
-
// Make sure we're wrapping around the whole list
|
|
317
|
-
replaceToModifier = 3;
|
|
318
|
-
}
|
|
319
|
-
var posNodeBefore = origDoc.resolve($oldAfter.pos - blockTaskItemNode.node.nodeSize - 1);
|
|
320
|
-
var hasPreviousTaskItem = !!(0, _utils.findFarthestParentNode)(function (node) {
|
|
321
|
-
return node.type === blockTaskItem;
|
|
322
|
-
})(posNodeBefore);
|
|
323
|
-
if (!hasPreviousTaskItem) {
|
|
324
|
-
// Go down one step to get to the doc node
|
|
325
|
-
replaceFromModifier = 1;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// When we're removing the extra empty task item we need to reduce the range a bit
|
|
329
|
-
deleteBlockModifier = 2;
|
|
330
345
|
}
|
|
331
346
|
}
|
|
332
347
|
|
|
@@ -362,7 +377,12 @@ var splitListItemWith = function splitListItemWith(tr, content, $from, setSelect
|
|
|
362
377
|
var previousListItemPos = isNestedActionInsideLists ? $from.start(baseDepth - 2) : 0;
|
|
363
378
|
tr = tr.replace(tr.mapping.map($from.start() - (2 + replaceFromModifier)), tr.mapping.map($from.end() + (2 + replaceToModifier)), frag.size ? new _model.Slice(frag, 0, 0) : _model.Slice.empty);
|
|
364
379
|
if (setSelection && !isNestedActionInsideLists) {
|
|
365
|
-
|
|
380
|
+
var newPos = $from.pos + 1 - ((shouldSplit ? 0 : 2) + textSelectionModifier);
|
|
381
|
+
if (isGapCursorSelection) {
|
|
382
|
+
tr = tr.setSelection(new _selection.GapCursorSelection(tr.doc.resolve(newPos), _selection.Side.LEFT));
|
|
383
|
+
} else {
|
|
384
|
+
tr = tr.setSelection(new _state.TextSelection(tr.doc.resolve(newPos)));
|
|
385
|
+
}
|
|
366
386
|
}
|
|
367
387
|
|
|
368
388
|
// if different levels then we shouldn't lift
|
|
@@ -93,7 +93,7 @@ function createPlugin(portalProviderAPI, eventDispatcher, dispatch, api, getIntl
|
|
|
93
93
|
var $from = selection.$from,
|
|
94
94
|
$to = selection.$to;
|
|
95
95
|
var parentOffset = $from.parentOffset;
|
|
96
|
-
var isInTaskItem = $from.node().type === schema.nodes.taskItem;
|
|
96
|
+
var isInTaskItem = (0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_patch_1', 'isEnabled', true) ? (0, _helpers.isInsideTask)(state) : $from.node().type === schema.nodes.taskItem;
|
|
97
97
|
var focusedTaskItemLocalId = _pluginKey.stateKey.getState(state).focusedTaskItemLocalId;
|
|
98
98
|
var currentTaskItemData = (0, _helpers.getTaskItemDataAtPos)(view);
|
|
99
99
|
var currentTaskItemFocused = focusedTaskItemLocalId === (currentTaskItemData === null || currentTaskItemData === void 0 ? void 0 : currentTaskItemData.localId);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normalizeTaskItemsSelection = void 0;
|
|
6
|
+
exports.normalizeTaskItemsSelection = exports.findBlockTaskItem = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
8
|
function isTaskListNode(node) {
|
|
9
9
|
return Boolean(node && node.type && 'taskList' === node.type.name);
|
|
@@ -31,4 +31,37 @@ var normalizeTaskItemsSelection = exports.normalizeTaskItemsSelection = function
|
|
|
31
31
|
var head = resolvePositionToStartOfTaskItem($from);
|
|
32
32
|
var anchor = resolvePositionToEndOfTaskItem($to);
|
|
33
33
|
return new _state.TextSelection(anchor, head);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the blockTaskItem node and whether it has a paragraph child if it exists near the given resolved position.
|
|
38
|
+
* @param $from resolved position, typically from the selection when the selection is an empty selection at the start of a task item
|
|
39
|
+
* @returns {{ blockTaskItemNode: PMNode; hasParagraph: boolean } | false} An object with blockTaskItemNode and hasParagraph if found, or false if there is no blockTaskItem node.
|
|
40
|
+
*/
|
|
41
|
+
var findBlockTaskItem = exports.findBlockTaskItem = function findBlockTaskItem($from) {
|
|
42
|
+
var _$from$doc$type$schem = $from.doc.type.schema.nodes,
|
|
43
|
+
blockTaskItem = _$from$doc$type$schem.blockTaskItem,
|
|
44
|
+
paragraph = _$from$doc$type$schem.paragraph;
|
|
45
|
+
var firstParent = $from.parent;
|
|
46
|
+
if (firstParent.type === blockTaskItem) {
|
|
47
|
+
return {
|
|
48
|
+
blockTaskItemNode: firstParent,
|
|
49
|
+
hasParagraph: false
|
|
50
|
+
};
|
|
51
|
+
} else if (firstParent.type === paragraph) {
|
|
52
|
+
if ($from.depth >= 1) {
|
|
53
|
+
var secondParent = $from.node($from.depth - 1);
|
|
54
|
+
if (secondParent.type === blockTaskItem) {
|
|
55
|
+
return {
|
|
56
|
+
blockTaskItemNode: secondParent,
|
|
57
|
+
hasParagraph: true
|
|
58
|
+
};
|
|
59
|
+
} else {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
34
67
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { findCutBefore } from '@atlaskit/editor-common/commands';
|
|
2
|
-
import { findFarthestParentNode } from '@atlaskit/editor-common/utils';
|
|
3
2
|
import { findWrapping, ReplaceAroundStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
-
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
3
|
import { getBlockRange, isActionOrDecisionItem, isActionOrDecisionList, liftBlock, subtreeHeight } from './helpers';
|
|
6
|
-
import { normalizeTaskItemsSelection } from './utils';
|
|
4
|
+
import { findBlockTaskItem, normalizeTaskItemsSelection } from './utils';
|
|
7
5
|
export const liftSelection = (state, dispatch) => {
|
|
8
6
|
const normalizedSelection = normalizeTaskItemsSelection(state.selection);
|
|
9
7
|
const {
|
|
@@ -47,15 +45,19 @@ export const wrapSelectionInTaskList = (state, dispatch) => {
|
|
|
47
45
|
blockTaskItem
|
|
48
46
|
} = state.schema.nodes;
|
|
49
47
|
let maxDepth = subtreeHeight($from, $to, [taskList, taskItem]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
if (blockTaskItem) {
|
|
49
|
+
const resultOfFindBlockTaskItem = findBlockTaskItem($from);
|
|
50
|
+
if (resultOfFindBlockTaskItem) {
|
|
51
|
+
const {
|
|
52
|
+
hasParagraph
|
|
53
|
+
} = resultOfFindBlockTaskItem;
|
|
54
|
+
// If the selection is inside a nested node inside the blockTaskItem
|
|
55
|
+
// Remove the difference in depth between the selection and the blockTaskItemNode
|
|
56
|
+
if (hasParagraph) {
|
|
57
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]) - 1;
|
|
58
|
+
} else {
|
|
59
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]);
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
if (maxDepth >= 6) {
|