@atlaskit/editor-plugin-tasks-and-decisions 6.2.3 → 6.2.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 +7 -0
- package/dist/cjs/pm-plugins/commands.js +47 -4
- package/dist/cjs/pm-plugins/helpers.js +32 -4
- package/dist/es2019/pm-plugins/commands.js +44 -3
- package/dist/es2019/pm-plugins/helpers.js +28 -4
- package/dist/esm/pm-plugins/commands.js +44 -1
- package/dist/esm/pm-plugins/helpers.js +32 -4
- package/dist/types/pm-plugins/commands.d.ts +18 -1
- package/dist/types/pm-plugins/helpers.d.ts +12 -1
- package/dist/types-ts4.5/pm-plugins/commands.d.ts +18 -1
- package/dist/types-ts4.5/pm-plugins/helpers.d.ts +12 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-tasks-and-decisions
|
|
2
2
|
|
|
3
|
+
## 6.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`af3ebe7fda754`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/af3ebe7fda754) -
|
|
8
|
+
[EDITOR-1153] Handle when user presses "Tab" in a blockTaskItem
|
|
9
|
+
|
|
3
10
|
## 6.2.3
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -5,11 +5,14 @@ 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
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
10
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
11
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
9
12
|
var _helpers = require("./helpers");
|
|
10
|
-
var
|
|
13
|
+
var _utils3 = require("./utils");
|
|
11
14
|
var liftSelection = exports.liftSelection = function liftSelection(state, dispatch) {
|
|
12
|
-
var normalizedSelection = (0,
|
|
15
|
+
var normalizedSelection = (0, _utils3.normalizeTaskItemsSelection)(state.selection);
|
|
13
16
|
var $from = normalizedSelection.$from,
|
|
14
17
|
$to = normalizedSelection.$to;
|
|
15
18
|
var tr = (0, _helpers.liftBlock)(state.tr, $from, $to);
|
|
@@ -18,20 +21,60 @@ var liftSelection = exports.liftSelection = function liftSelection(state, dispat
|
|
|
18
21
|
}
|
|
19
22
|
return !!tr;
|
|
20
23
|
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Wraps the current selection in a task list, respecting a maximum indentation depth of 6 levels.
|
|
27
|
+
*
|
|
28
|
+
* - Normalizes the selection to ensure it covers complete task items.
|
|
29
|
+
* - Determines the maximum depth of task list nesting within the selection.
|
|
30
|
+
* - If the selection is already nested at or beyond the maximum depth, the command does nothing.
|
|
31
|
+
* - Calculates the block range to wrap, handling both regular and block task items.
|
|
32
|
+
* - Wraps the block in a task list to increase indentation or create a new task list if necessary.
|
|
33
|
+
*
|
|
34
|
+
* @param state - The current editor state.
|
|
35
|
+
* @param dispatch - The dispatch function to apply the transaction.
|
|
36
|
+
* @returns `true` if the command was handled (even if no changes were made), otherwise `false`.
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* autoJoin(wrapSelectionInTaskList, ['taskList']))(state, dispatch);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
21
42
|
var wrapSelectionInTaskList = exports.wrapSelectionInTaskList = function wrapSelectionInTaskList(state, dispatch) {
|
|
22
|
-
var _normalizeTaskItemsSe = (0,
|
|
43
|
+
var _normalizeTaskItemsSe = (0, _utils3.normalizeTaskItemsSelection)(state.selection),
|
|
23
44
|
$from = _normalizeTaskItemsSe.$from,
|
|
24
45
|
$to = _normalizeTaskItemsSe.$to;
|
|
25
46
|
|
|
26
47
|
// limit ui indentation to 6 levels
|
|
27
48
|
var _state$schema$nodes = state.schema.nodes,
|
|
28
49
|
taskList = _state$schema$nodes.taskList,
|
|
29
|
-
taskItem = _state$schema$nodes.taskItem
|
|
50
|
+
taskItem = _state$schema$nodes.taskItem,
|
|
51
|
+
blockTaskItem = _state$schema$nodes.blockTaskItem;
|
|
30
52
|
var maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, taskItem]);
|
|
53
|
+
var isBlockTaskItem = (0, _utils2.hasParentNodeOfType)([blockTaskItem])(state.selection);
|
|
54
|
+
var blockTaskItemNode = (0, _utils.findFarthestParentNode)(function (node) {
|
|
55
|
+
return node.type === blockTaskItem;
|
|
56
|
+
})($from);
|
|
57
|
+
if (blockTaskItem && isBlockTaskItem && blockTaskItemNode) {
|
|
58
|
+
// If the selection is inside a nested node inside the blockTaskItem
|
|
59
|
+
// Remove the difference in depth between the selection and the blockTaskItemNode
|
|
60
|
+
if ($from.depth > blockTaskItemNode.depth) {
|
|
61
|
+
maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, blockTaskItem]) - ($from.depth - blockTaskItemNode.depth);
|
|
62
|
+
} else {
|
|
63
|
+
maxDepth = (0, _helpers.subtreeHeight)($from, $to, [taskList, blockTaskItem]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
31
66
|
if (maxDepth >= 6) {
|
|
32
67
|
return true;
|
|
33
68
|
}
|
|
34
69
|
var blockRange = (0, _helpers.getBlockRange)($from, $to);
|
|
70
|
+
if (blockTaskItem) {
|
|
71
|
+
if (isBlockTaskItem && blockTaskItemNode) {
|
|
72
|
+
// Get the Resolved $from and $to of the node nested inside the blockTaskItem
|
|
73
|
+
var startOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start);
|
|
74
|
+
var endOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start + blockTaskItemNode.node.nodeSize - 1);
|
|
75
|
+
blockRange = new _model.NodeRange(startOfNodeInBlockTaskItem, endOfNodeInBlockTaskItem, blockTaskItemNode.depth - 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
35
78
|
if (!blockRange) {
|
|
36
79
|
return true;
|
|
37
80
|
}
|
|
@@ -42,8 +42,10 @@ var isActionOrDecisionItem = exports.isActionOrDecisionItem = function isActionO
|
|
|
42
42
|
return [taskItem, decisionItem].indexOf(node.type) > -1;
|
|
43
43
|
};
|
|
44
44
|
var isInsideTask = exports.isInsideTask = function isInsideTask(state) {
|
|
45
|
-
var
|
|
46
|
-
|
|
45
|
+
var _state$schema$nodes2 = state.schema.nodes,
|
|
46
|
+
taskItem = _state$schema$nodes2.taskItem,
|
|
47
|
+
blockTaskItem = _state$schema$nodes2.blockTaskItem;
|
|
48
|
+
return (0, _utils2.hasParentNodeOfType)([taskItem, blockTaskItem])(state.selection);
|
|
47
49
|
};
|
|
48
50
|
var isInsideDecision = exports.isInsideDecision = function isInsideDecision(state) {
|
|
49
51
|
var decisionItem = state.schema.nodes.decisionItem;
|
|
@@ -81,17 +83,43 @@ var getBlockRange = exports.getBlockRange = function getBlockRange($from, $to) {
|
|
|
81
83
|
};
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
|
-
*
|
|
86
|
+
* Calculates the current indent level of the selection within a task list in the ProseMirror document.
|
|
87
|
+
*
|
|
88
|
+
* The indent level is determined by finding the depth difference between the selection and the furthest parent
|
|
89
|
+
* node of type `taskList`. If the selection is inside a `blockTaskItem`, the calculation is adjusted to avoid
|
|
90
|
+
* counting nested block items as additional indent levels.
|
|
91
|
+
*
|
|
92
|
+
* @param selection - The current ProseMirror selection.
|
|
93
|
+
* @returns The indent level as a number, or `null` if the selection is not inside a task list.
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const indentLevel = getCurrentIndentLevel(editorState.selection);
|
|
97
|
+
* ```
|
|
85
98
|
*/
|
|
86
99
|
var getCurrentIndentLevel = exports.getCurrentIndentLevel = function getCurrentIndentLevel(selection) {
|
|
87
100
|
var $from = selection.$from;
|
|
88
|
-
var
|
|
101
|
+
var _$from$doc$type$schem = $from.doc.type.schema.nodes,
|
|
102
|
+
taskList = _$from$doc$type$schem.taskList,
|
|
103
|
+
blockTaskItem = _$from$doc$type$schem.blockTaskItem;
|
|
89
104
|
var furthestParent = (0, _utils.findFarthestParentNode)(function (node) {
|
|
90
105
|
return node.type === taskList;
|
|
91
106
|
})($from);
|
|
92
107
|
if (!furthestParent) {
|
|
93
108
|
return null;
|
|
94
109
|
}
|
|
110
|
+
if ((0, _utils2.hasParentNodeOfType)([blockTaskItem])(selection)) {
|
|
111
|
+
var blockTaskItemNode = (0, _utils.findFarthestParentNode)(function (node) {
|
|
112
|
+
return node.type === blockTaskItem;
|
|
113
|
+
})($from);
|
|
114
|
+
if (blockTaskItemNode) {
|
|
115
|
+
/**
|
|
116
|
+
* If we are inside a blockTaskItem, calculate the indent level from the
|
|
117
|
+
* blockTaskItemNode instead of the selection, in case the selection is
|
|
118
|
+
* nested inside a blockTaskItem.
|
|
119
|
+
*/
|
|
120
|
+
return blockTaskItemNode.depth - furthestParent.depth;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
95
123
|
return $from.depth - furthestParent.depth;
|
|
96
124
|
};
|
|
97
125
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { findCutBefore } from '@atlaskit/editor-common/commands';
|
|
2
|
+
import { findFarthestParentNode } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { NodeRange } from '@atlaskit/editor-prosemirror/model';
|
|
2
4
|
import { findWrapping, ReplaceAroundStep } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
+
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
6
|
import { getBlockRange, isActionOrDecisionItem, isActionOrDecisionList, liftBlock, subtreeHeight } from './helpers';
|
|
4
7
|
import { normalizeTaskItemsSelection } from './utils';
|
|
5
8
|
export const liftSelection = (state, dispatch) => {
|
|
@@ -14,6 +17,24 @@ export const liftSelection = (state, dispatch) => {
|
|
|
14
17
|
}
|
|
15
18
|
return !!tr;
|
|
16
19
|
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Wraps the current selection in a task list, respecting a maximum indentation depth of 6 levels.
|
|
23
|
+
*
|
|
24
|
+
* - Normalizes the selection to ensure it covers complete task items.
|
|
25
|
+
* - Determines the maximum depth of task list nesting within the selection.
|
|
26
|
+
* - If the selection is already nested at or beyond the maximum depth, the command does nothing.
|
|
27
|
+
* - Calculates the block range to wrap, handling both regular and block task items.
|
|
28
|
+
* - Wraps the block in a task list to increase indentation or create a new task list if necessary.
|
|
29
|
+
*
|
|
30
|
+
* @param state - The current editor state.
|
|
31
|
+
* @param dispatch - The dispatch function to apply the transaction.
|
|
32
|
+
* @returns `true` if the command was handled (even if no changes were made), otherwise `false`.
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* autoJoin(wrapSelectionInTaskList, ['taskList']))(state, dispatch);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
17
38
|
export const wrapSelectionInTaskList = (state, dispatch) => {
|
|
18
39
|
const {
|
|
19
40
|
$from,
|
|
@@ -23,13 +44,33 @@ export const wrapSelectionInTaskList = (state, dispatch) => {
|
|
|
23
44
|
// limit ui indentation to 6 levels
|
|
24
45
|
const {
|
|
25
46
|
taskList,
|
|
26
|
-
taskItem
|
|
47
|
+
taskItem,
|
|
48
|
+
blockTaskItem
|
|
27
49
|
} = state.schema.nodes;
|
|
28
|
-
|
|
50
|
+
let maxDepth = subtreeHeight($from, $to, [taskList, taskItem]);
|
|
51
|
+
const isBlockTaskItem = hasParentNodeOfType([blockTaskItem])(state.selection);
|
|
52
|
+
const blockTaskItemNode = findFarthestParentNode(node => node.type === blockTaskItem)($from);
|
|
53
|
+
if (blockTaskItem && isBlockTaskItem && blockTaskItemNode) {
|
|
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 ($from.depth > blockTaskItemNode.depth) {
|
|
57
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]) - ($from.depth - blockTaskItemNode.depth);
|
|
58
|
+
} else {
|
|
59
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
29
62
|
if (maxDepth >= 6) {
|
|
30
63
|
return true;
|
|
31
64
|
}
|
|
32
|
-
|
|
65
|
+
let blockRange = getBlockRange($from, $to);
|
|
66
|
+
if (blockTaskItem) {
|
|
67
|
+
if (isBlockTaskItem && blockTaskItemNode) {
|
|
68
|
+
// Get the Resolved $from and $to of the node nested inside the blockTaskItem
|
|
69
|
+
const startOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start);
|
|
70
|
+
const endOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start + blockTaskItemNode.node.nodeSize - 1);
|
|
71
|
+
blockRange = new NodeRange(startOfNodeInBlockTaskItem, endOfNodeInBlockTaskItem, blockTaskItemNode.depth - 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
33
74
|
if (!blockRange) {
|
|
34
75
|
return true;
|
|
35
76
|
}
|
|
@@ -28,9 +28,10 @@ export const isActionOrDecisionItem = node => {
|
|
|
28
28
|
};
|
|
29
29
|
export const isInsideTask = state => {
|
|
30
30
|
const {
|
|
31
|
-
taskItem
|
|
31
|
+
taskItem,
|
|
32
|
+
blockTaskItem
|
|
32
33
|
} = state.schema.nodes;
|
|
33
|
-
return hasParentNodeOfType([taskItem])(state.selection);
|
|
34
|
+
return hasParentNodeOfType([taskItem, blockTaskItem])(state.selection);
|
|
34
35
|
};
|
|
35
36
|
export const isInsideDecision = state => {
|
|
36
37
|
const {
|
|
@@ -73,19 +74,42 @@ export const getBlockRange = ($from, $to) => {
|
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
|
-
*
|
|
77
|
+
* Calculates the current indent level of the selection within a task list in the ProseMirror document.
|
|
78
|
+
*
|
|
79
|
+
* The indent level is determined by finding the depth difference between the selection and the furthest parent
|
|
80
|
+
* node of type `taskList`. If the selection is inside a `blockTaskItem`, the calculation is adjusted to avoid
|
|
81
|
+
* counting nested block items as additional indent levels.
|
|
82
|
+
*
|
|
83
|
+
* @param selection - The current ProseMirror selection.
|
|
84
|
+
* @returns The indent level as a number, or `null` if the selection is not inside a task list.
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const indentLevel = getCurrentIndentLevel(editorState.selection);
|
|
88
|
+
* ```
|
|
77
89
|
*/
|
|
78
90
|
export const getCurrentIndentLevel = selection => {
|
|
79
91
|
const {
|
|
80
92
|
$from
|
|
81
93
|
} = selection;
|
|
82
94
|
const {
|
|
83
|
-
taskList
|
|
95
|
+
taskList,
|
|
96
|
+
blockTaskItem
|
|
84
97
|
} = $from.doc.type.schema.nodes;
|
|
85
98
|
const furthestParent = findFarthestParentNode(node => node.type === taskList)($from);
|
|
86
99
|
if (!furthestParent) {
|
|
87
100
|
return null;
|
|
88
101
|
}
|
|
102
|
+
if (hasParentNodeOfType([blockTaskItem])(selection)) {
|
|
103
|
+
const blockTaskItemNode = findFarthestParentNode(node => node.type === blockTaskItem)($from);
|
|
104
|
+
if (blockTaskItemNode) {
|
|
105
|
+
/**
|
|
106
|
+
* If we are inside a blockTaskItem, calculate the indent level from the
|
|
107
|
+
* blockTaskItemNode instead of the selection, in case the selection is
|
|
108
|
+
* nested inside a blockTaskItem.
|
|
109
|
+
*/
|
|
110
|
+
return blockTaskItemNode.depth - furthestParent.depth;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
89
113
|
return $from.depth - furthestParent.depth;
|
|
90
114
|
};
|
|
91
115
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { findCutBefore } from '@atlaskit/editor-common/commands';
|
|
2
|
+
import { findFarthestParentNode } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { NodeRange } from '@atlaskit/editor-prosemirror/model';
|
|
2
4
|
import { findWrapping, ReplaceAroundStep } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
+
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
6
|
import { getBlockRange, isActionOrDecisionItem, isActionOrDecisionList, liftBlock, subtreeHeight } from './helpers';
|
|
4
7
|
import { normalizeTaskItemsSelection } from './utils';
|
|
5
8
|
export var liftSelection = function liftSelection(state, dispatch) {
|
|
@@ -12,6 +15,24 @@ export var liftSelection = function liftSelection(state, dispatch) {
|
|
|
12
15
|
}
|
|
13
16
|
return !!tr;
|
|
14
17
|
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wraps the current selection in a task list, respecting a maximum indentation depth of 6 levels.
|
|
21
|
+
*
|
|
22
|
+
* - Normalizes the selection to ensure it covers complete task items.
|
|
23
|
+
* - Determines the maximum depth of task list nesting within the selection.
|
|
24
|
+
* - If the selection is already nested at or beyond the maximum depth, the command does nothing.
|
|
25
|
+
* - Calculates the block range to wrap, handling both regular and block task items.
|
|
26
|
+
* - Wraps the block in a task list to increase indentation or create a new task list if necessary.
|
|
27
|
+
*
|
|
28
|
+
* @param state - The current editor state.
|
|
29
|
+
* @param dispatch - The dispatch function to apply the transaction.
|
|
30
|
+
* @returns `true` if the command was handled (even if no changes were made), otherwise `false`.
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* autoJoin(wrapSelectionInTaskList, ['taskList']))(state, dispatch);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
15
36
|
export var wrapSelectionInTaskList = function wrapSelectionInTaskList(state, dispatch) {
|
|
16
37
|
var _normalizeTaskItemsSe = normalizeTaskItemsSelection(state.selection),
|
|
17
38
|
$from = _normalizeTaskItemsSe.$from,
|
|
@@ -20,12 +41,34 @@ export var wrapSelectionInTaskList = function wrapSelectionInTaskList(state, dis
|
|
|
20
41
|
// limit ui indentation to 6 levels
|
|
21
42
|
var _state$schema$nodes = state.schema.nodes,
|
|
22
43
|
taskList = _state$schema$nodes.taskList,
|
|
23
|
-
taskItem = _state$schema$nodes.taskItem
|
|
44
|
+
taskItem = _state$schema$nodes.taskItem,
|
|
45
|
+
blockTaskItem = _state$schema$nodes.blockTaskItem;
|
|
24
46
|
var maxDepth = subtreeHeight($from, $to, [taskList, taskItem]);
|
|
47
|
+
var isBlockTaskItem = hasParentNodeOfType([blockTaskItem])(state.selection);
|
|
48
|
+
var blockTaskItemNode = findFarthestParentNode(function (node) {
|
|
49
|
+
return node.type === blockTaskItem;
|
|
50
|
+
})($from);
|
|
51
|
+
if (blockTaskItem && isBlockTaskItem && blockTaskItemNode) {
|
|
52
|
+
// If the selection is inside a nested node inside the blockTaskItem
|
|
53
|
+
// Remove the difference in depth between the selection and the blockTaskItemNode
|
|
54
|
+
if ($from.depth > blockTaskItemNode.depth) {
|
|
55
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]) - ($from.depth - blockTaskItemNode.depth);
|
|
56
|
+
} else {
|
|
57
|
+
maxDepth = subtreeHeight($from, $to, [taskList, blockTaskItem]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
25
60
|
if (maxDepth >= 6) {
|
|
26
61
|
return true;
|
|
27
62
|
}
|
|
28
63
|
var blockRange = getBlockRange($from, $to);
|
|
64
|
+
if (blockTaskItem) {
|
|
65
|
+
if (isBlockTaskItem && blockTaskItemNode) {
|
|
66
|
+
// Get the Resolved $from and $to of the node nested inside the blockTaskItem
|
|
67
|
+
var startOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start);
|
|
68
|
+
var endOfNodeInBlockTaskItem = state.doc.resolve(blockTaskItemNode.start + blockTaskItemNode.node.nodeSize - 1);
|
|
69
|
+
blockRange = new NodeRange(startOfNodeInBlockTaskItem, endOfNodeInBlockTaskItem, blockTaskItemNode.depth - 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
29
72
|
if (!blockRange) {
|
|
30
73
|
return true;
|
|
31
74
|
}
|
|
@@ -24,8 +24,10 @@ export var isActionOrDecisionItem = function isActionOrDecisionItem(node) {
|
|
|
24
24
|
return [taskItem, decisionItem].indexOf(node.type) > -1;
|
|
25
25
|
};
|
|
26
26
|
export var isInsideTask = function isInsideTask(state) {
|
|
27
|
-
var
|
|
28
|
-
|
|
27
|
+
var _state$schema$nodes2 = state.schema.nodes,
|
|
28
|
+
taskItem = _state$schema$nodes2.taskItem,
|
|
29
|
+
blockTaskItem = _state$schema$nodes2.blockTaskItem;
|
|
30
|
+
return hasParentNodeOfType([taskItem, blockTaskItem])(state.selection);
|
|
29
31
|
};
|
|
30
32
|
export var isInsideDecision = function isInsideDecision(state) {
|
|
31
33
|
var decisionItem = state.schema.nodes.decisionItem;
|
|
@@ -63,17 +65,43 @@ export var getBlockRange = function getBlockRange($from, $to) {
|
|
|
63
65
|
};
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
|
-
*
|
|
68
|
+
* Calculates the current indent level of the selection within a task list in the ProseMirror document.
|
|
69
|
+
*
|
|
70
|
+
* The indent level is determined by finding the depth difference between the selection and the furthest parent
|
|
71
|
+
* node of type `taskList`. If the selection is inside a `blockTaskItem`, the calculation is adjusted to avoid
|
|
72
|
+
* counting nested block items as additional indent levels.
|
|
73
|
+
*
|
|
74
|
+
* @param selection - The current ProseMirror selection.
|
|
75
|
+
* @returns The indent level as a number, or `null` if the selection is not inside a task list.
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const indentLevel = getCurrentIndentLevel(editorState.selection);
|
|
79
|
+
* ```
|
|
67
80
|
*/
|
|
68
81
|
export var getCurrentIndentLevel = function getCurrentIndentLevel(selection) {
|
|
69
82
|
var $from = selection.$from;
|
|
70
|
-
var
|
|
83
|
+
var _$from$doc$type$schem = $from.doc.type.schema.nodes,
|
|
84
|
+
taskList = _$from$doc$type$schem.taskList,
|
|
85
|
+
blockTaskItem = _$from$doc$type$schem.blockTaskItem;
|
|
71
86
|
var furthestParent = findFarthestParentNode(function (node) {
|
|
72
87
|
return node.type === taskList;
|
|
73
88
|
})($from);
|
|
74
89
|
if (!furthestParent) {
|
|
75
90
|
return null;
|
|
76
91
|
}
|
|
92
|
+
if (hasParentNodeOfType([blockTaskItem])(selection)) {
|
|
93
|
+
var blockTaskItemNode = findFarthestParentNode(function (node) {
|
|
94
|
+
return node.type === blockTaskItem;
|
|
95
|
+
})($from);
|
|
96
|
+
if (blockTaskItemNode) {
|
|
97
|
+
/**
|
|
98
|
+
* If we are inside a blockTaskItem, calculate the indent level from the
|
|
99
|
+
* blockTaskItemNode instead of the selection, in case the selection is
|
|
100
|
+
* nested inside a blockTaskItem.
|
|
101
|
+
*/
|
|
102
|
+
return blockTaskItemNode.depth - furthestParent.depth;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
77
105
|
return $from.depth - furthestParent.depth;
|
|
78
106
|
};
|
|
79
107
|
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const liftSelection: Command;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps the current selection in a task list, respecting a maximum indentation depth of 6 levels.
|
|
6
|
+
*
|
|
7
|
+
* - Normalizes the selection to ensure it covers complete task items.
|
|
8
|
+
* - Determines the maximum depth of task list nesting within the selection.
|
|
9
|
+
* - If the selection is already nested at or beyond the maximum depth, the command does nothing.
|
|
10
|
+
* - Calculates the block range to wrap, handling both regular and block task items.
|
|
11
|
+
* - Wraps the block in a task list to increase indentation or create a new task list if necessary.
|
|
12
|
+
*
|
|
13
|
+
* @param state - The current editor state.
|
|
14
|
+
* @param dispatch - The dispatch function to apply the transaction.
|
|
15
|
+
* @returns `true` if the command was handled (even if no changes were made), otherwise `false`.
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* autoJoin(wrapSelectionInTaskList, ['taskList']))(state, dispatch);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
export declare const wrapSelectionInTaskList: Command;
|
|
5
22
|
/**
|
|
6
23
|
* Tries to move the paragraph content near the given position into the taskItem or decisionItem
|
|
@@ -14,7 +14,18 @@ export declare const isTable: (node?: Node | null) => boolean;
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const getBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => import("prosemirror-model").NodeRange | null;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Calculates the current indent level of the selection within a task list in the ProseMirror document.
|
|
18
|
+
*
|
|
19
|
+
* The indent level is determined by finding the depth difference between the selection and the furthest parent
|
|
20
|
+
* node of type `taskList`. If the selection is inside a `blockTaskItem`, the calculation is adjusted to avoid
|
|
21
|
+
* counting nested block items as additional indent levels.
|
|
22
|
+
*
|
|
23
|
+
* @param selection - The current ProseMirror selection.
|
|
24
|
+
* @returns The indent level as a number, or `null` if the selection is not inside a task list.
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const indentLevel = getCurrentIndentLevel(editorState.selection);
|
|
28
|
+
* ```
|
|
18
29
|
*/
|
|
19
30
|
export declare const getCurrentIndentLevel: (selection: Selection) => number | null;
|
|
20
31
|
/**
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const liftSelection: Command;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps the current selection in a task list, respecting a maximum indentation depth of 6 levels.
|
|
6
|
+
*
|
|
7
|
+
* - Normalizes the selection to ensure it covers complete task items.
|
|
8
|
+
* - Determines the maximum depth of task list nesting within the selection.
|
|
9
|
+
* - If the selection is already nested at or beyond the maximum depth, the command does nothing.
|
|
10
|
+
* - Calculates the block range to wrap, handling both regular and block task items.
|
|
11
|
+
* - Wraps the block in a task list to increase indentation or create a new task list if necessary.
|
|
12
|
+
*
|
|
13
|
+
* @param state - The current editor state.
|
|
14
|
+
* @param dispatch - The dispatch function to apply the transaction.
|
|
15
|
+
* @returns `true` if the command was handled (even if no changes were made), otherwise `false`.
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* autoJoin(wrapSelectionInTaskList, ['taskList']))(state, dispatch);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
export declare const wrapSelectionInTaskList: Command;
|
|
5
22
|
/**
|
|
6
23
|
* Tries to move the paragraph content near the given position into the taskItem or decisionItem
|
|
@@ -14,7 +14,18 @@ export declare const isTable: (node?: Node | null) => boolean;
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const getBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => import("prosemirror-model").NodeRange | null;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Calculates the current indent level of the selection within a task list in the ProseMirror document.
|
|
18
|
+
*
|
|
19
|
+
* The indent level is determined by finding the depth difference between the selection and the furthest parent
|
|
20
|
+
* node of type `taskList`. If the selection is inside a `blockTaskItem`, the calculation is adjusted to avoid
|
|
21
|
+
* counting nested block items as additional indent levels.
|
|
22
|
+
*
|
|
23
|
+
* @param selection - The current ProseMirror selection.
|
|
24
|
+
* @returns The indent level as a number, or `null` if the selection is not inside a task list.
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const indentLevel = getCurrentIndentLevel(editorState.selection);
|
|
28
|
+
* ```
|
|
18
29
|
*/
|
|
19
30
|
export declare const getCurrentIndentLevel: (selection: Selection) => number | null;
|
|
20
31
|
/**
|