@atlaskit/editor-core 189.3.29 → 189.3.31
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 +13 -0
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/utils/document.js +0 -6
- package/dist/cjs/utils/index.js +0 -6
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/utils/document.js +1 -1
- package/dist/es2019/utils/index.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/utils/document.js +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/insert-block/types.d.ts +2 -2
- package/dist/types/plugins/toolbar-lists-indentation/index.d.ts +2 -2
- package/dist/types/utils/document.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -2
- package/dist/types-ts4.5/plugins/toolbar-lists-indentation/index.d.ts +2 -2
- package/dist/types-ts4.5/utils/document.d.ts +1 -1
- package/dist/types-ts4.5/utils/index.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/plugins/tasks-and-decisions/commands.js +0 -288
- package/dist/cjs/plugins/tasks-and-decisions/index.js +0 -166
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +0 -117
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/hooks/use-show-placeholder.js +0 -40
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +0 -211
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/commands.js +0 -96
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/helpers.js +0 -299
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/input-rules.js +0 -94
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/keymaps.js +0 -376
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/main.js +0 -263
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/plugin-key.js +0 -8
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/types.js +0 -11
- package/dist/cjs/plugins/tasks-and-decisions/types.js +0 -5
- package/dist/cjs/plugins/tasks-and-decisions/ui/Decision/index.js +0 -51
- package/dist/cjs/plugins/tasks-and-decisions/ui/Task/index.js +0 -80
- package/dist/cjs/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.js +0 -137
- package/dist/cjs/plugins/tasks-and-decisions/ui/ToolbarDecision/index.js +0 -76
- package/dist/cjs/plugins/tasks-and-decisions/ui/ToolbarTask/index.js +0 -75
- package/dist/cjs/plugins/tasks-and-decisions/utils.js +0 -41
- package/dist/es2019/plugins/tasks-and-decisions/commands.js +0 -279
- package/dist/es2019/plugins/tasks-and-decisions/index.js +0 -155
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +0 -76
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/hooks/use-show-placeholder.js +0 -36
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +0 -173
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/commands.js +0 -94
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/helpers.js +0 -316
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/input-rules.js +0 -91
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/keymaps.js +0 -370
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/main.js +0 -262
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/plugin-key.js +0 -2
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/types.js +0 -5
- package/dist/es2019/plugins/tasks-and-decisions/types.js +0 -1
- package/dist/es2019/plugins/tasks-and-decisions/ui/Decision/index.js +0 -30
- package/dist/es2019/plugins/tasks-and-decisions/ui/Task/index.js +0 -54
- package/dist/es2019/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.js +0 -71
- package/dist/es2019/plugins/tasks-and-decisions/ui/ToolbarDecision/index.js +0 -52
- package/dist/es2019/plugins/tasks-and-decisions/ui/ToolbarTask/index.js +0 -51
- package/dist/es2019/plugins/tasks-and-decisions/utils.js +0 -32
- package/dist/esm/plugins/tasks-and-decisions/commands.js +0 -281
- package/dist/esm/plugins/tasks-and-decisions/index.js +0 -156
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +0 -110
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/hooks/use-show-placeholder.js +0 -34
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +0 -204
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/commands.js +0 -90
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/helpers.js +0 -285
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/input-rules.js +0 -87
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/keymaps.js +0 -368
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/main.js +0 -256
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/plugin-key.js +0 -2
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/types.js +0 -5
- package/dist/esm/plugins/tasks-and-decisions/types.js +0 -1
- package/dist/esm/plugins/tasks-and-decisions/ui/Decision/index.js +0 -44
- package/dist/esm/plugins/tasks-and-decisions/ui/Task/index.js +0 -70
- package/dist/esm/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.js +0 -128
- package/dist/esm/plugins/tasks-and-decisions/ui/ToolbarDecision/index.js +0 -66
- package/dist/esm/plugins/tasks-and-decisions/ui/ToolbarTask/index.js +0 -65
- package/dist/esm/plugins/tasks-and-decisions/utils.js +0 -30
- package/dist/types/plugins/tasks-and-decisions/commands.d.ts +0 -16
- package/dist/types/plugins/tasks-and-decisions/index.d.ts +0 -3
- package/dist/types/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +0 -10
- package/dist/types/plugins/tasks-and-decisions/nodeviews/hooks/use-show-placeholder.d.ts +0 -11
- package/dist/types/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +0 -14
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/commands.d.ts +0 -15
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/helpers.d.ts +0 -76
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/input-rules.d.ts +0 -6
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/keymaps.d.ts +0 -11
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/main.d.ts +0 -7
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/plugin-key.d.ts +0 -2
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/types.d.ts +0 -8
- package/dist/types/plugins/tasks-and-decisions/types.d.ts +0 -49
- package/dist/types/plugins/tasks-and-decisions/ui/Decision/index.d.ts +0 -14
- package/dist/types/plugins/tasks-and-decisions/ui/Task/index.d.ts +0 -28
- package/dist/types/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.d.ts +0 -29
- package/dist/types/plugins/tasks-and-decisions/ui/ToolbarDecision/index.d.ts +0 -23
- package/dist/types/plugins/tasks-and-decisions/ui/ToolbarTask/index.d.ts +0 -23
- package/dist/types/plugins/tasks-and-decisions/utils.d.ts +0 -4
- package/dist/types-ts4.5/plugins/tasks-and-decisions/commands.d.ts +0 -16
- package/dist/types-ts4.5/plugins/tasks-and-decisions/index.d.ts +0 -3
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +0 -10
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/hooks/use-show-placeholder.d.ts +0 -11
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +0 -14
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/commands.d.ts +0 -15
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/helpers.d.ts +0 -76
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/input-rules.d.ts +0 -6
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/keymaps.d.ts +0 -11
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/main.d.ts +0 -7
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/plugin-key.d.ts +0 -2
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/types.d.ts +0 -8
- package/dist/types-ts4.5/plugins/tasks-and-decisions/types.d.ts +0 -49
- package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/Decision/index.d.ts +0 -14
- package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/Task/index.d.ts +0 -28
- package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.d.ts +0 -29
- package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/ToolbarDecision/index.d.ts +0 -23
- package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/ToolbarTask/index.d.ts +0 -23
- package/dist/types-ts4.5/plugins/tasks-and-decisions/utils.d.ts +0 -4
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
-
import { findParentNodeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { findFarthestParentNode } from '../../../utils';
|
|
5
|
-
import { stateKey } from './plugin-key';
|
|
6
|
-
import { ACTIONS } from './types';
|
|
7
|
-
export var isInsideTaskOrDecisionItem = function isInsideTaskOrDecisionItem(state) {
|
|
8
|
-
var _state$schema$nodes = state.schema.nodes,
|
|
9
|
-
decisionItem = _state$schema$nodes.decisionItem,
|
|
10
|
-
taskItem = _state$schema$nodes.taskItem;
|
|
11
|
-
return hasParentNodeOfType([decisionItem, taskItem])(state.selection);
|
|
12
|
-
};
|
|
13
|
-
export var isActionOrDecisionList = function isActionOrDecisionList(node) {
|
|
14
|
-
var _node$type$schema$nod = node.type.schema.nodes,
|
|
15
|
-
taskList = _node$type$schema$nod.taskList,
|
|
16
|
-
decisionList = _node$type$schema$nod.decisionList;
|
|
17
|
-
return [taskList, decisionList].indexOf(node.type) > -1;
|
|
18
|
-
};
|
|
19
|
-
export var isActionOrDecisionItem = function isActionOrDecisionItem(node) {
|
|
20
|
-
var _node$type$schema$nod2 = node.type.schema.nodes,
|
|
21
|
-
taskItem = _node$type$schema$nod2.taskItem,
|
|
22
|
-
decisionItem = _node$type$schema$nod2.decisionItem;
|
|
23
|
-
return [taskItem, decisionItem].indexOf(node.type) > -1;
|
|
24
|
-
};
|
|
25
|
-
export var isInsideTask = function isInsideTask(state) {
|
|
26
|
-
var taskItem = state.schema.nodes.taskItem;
|
|
27
|
-
return hasParentNodeOfType([taskItem])(state.selection);
|
|
28
|
-
};
|
|
29
|
-
export var isInsideDecision = function isInsideDecision(state) {
|
|
30
|
-
var decisionItem = state.schema.nodes.decisionItem;
|
|
31
|
-
return hasParentNodeOfType([decisionItem])(state.selection);
|
|
32
|
-
};
|
|
33
|
-
export var isTable = function isTable(node) {
|
|
34
|
-
if (!node) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
var _node$type$schema$nod3 = node.type.schema.nodes,
|
|
38
|
-
table = _node$type$schema$nod3.table,
|
|
39
|
-
tableHeader = _node$type$schema$nod3.tableHeader,
|
|
40
|
-
tableCell = _node$type$schema$nod3.tableCell,
|
|
41
|
-
tableRow = _node$type$schema$nod3.tableRow;
|
|
42
|
-
return [table, tableHeader, tableCell, tableRow].includes(node.type);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Creates a NodeRange around the given taskItem and the following
|
|
47
|
-
* ("nested") taskList, if one exists.
|
|
48
|
-
*/
|
|
49
|
-
export var getBlockRange = function getBlockRange($from, $to) {
|
|
50
|
-
var taskList = $from.doc.type.schema.nodes.taskList;
|
|
51
|
-
var end = $to.end();
|
|
52
|
-
var $after = $to.doc.resolve(end + 1);
|
|
53
|
-
var after = $after.nodeAfter;
|
|
54
|
-
|
|
55
|
-
// ensure the node after is actually just a sibling
|
|
56
|
-
// $to will be inside the text, so subtract one to get the taskItem it contains in
|
|
57
|
-
if (after && after.type === taskList && $after.depth === $to.depth - 1) {
|
|
58
|
-
// it was! include it in our blockRange
|
|
59
|
-
end += after.nodeSize;
|
|
60
|
-
}
|
|
61
|
-
return $from.blockRange($to.doc.resolve(end));
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Finds the distance between the current $from and the root of the taskList.
|
|
66
|
-
*/
|
|
67
|
-
export var getCurrentIndentLevel = function getCurrentIndentLevel(selection) {
|
|
68
|
-
var $from = selection.$from;
|
|
69
|
-
var taskList = $from.doc.type.schema.nodes.taskList;
|
|
70
|
-
var furthestParent = findFarthestParentNode(function (node) {
|
|
71
|
-
return node.type === taskList;
|
|
72
|
-
})($from);
|
|
73
|
-
if (!furthestParent) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return $from.depth - furthestParent.depth;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Finds the index of the current task item in relation to the closest taskList
|
|
81
|
-
*/
|
|
82
|
-
export var getTaskItemIndex = function getTaskItemIndex(state) {
|
|
83
|
-
var $pos = state.selection.$from;
|
|
84
|
-
var isTaskList = function isTaskList(node) {
|
|
85
|
-
return (node === null || node === void 0 ? void 0 : node.type.name) === 'taskList';
|
|
86
|
-
};
|
|
87
|
-
var itemAtPos = findParentNodeClosestToPos($pos, isTaskList);
|
|
88
|
-
return $pos.index(itemAtPos ? itemAtPos.depth : undefined);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Walk outwards from a position until we encounter the (inside) start of
|
|
93
|
-
* the next node, or reach the end of the document.
|
|
94
|
-
*
|
|
95
|
-
* @param $startPos Position to start walking from.
|
|
96
|
-
*/
|
|
97
|
-
export var walkOut = function walkOut($startPos) {
|
|
98
|
-
var $pos = $startPos;
|
|
99
|
-
|
|
100
|
-
// invariant 1: don't walk past the end of the document
|
|
101
|
-
// invariant 2: we haven't walked to the start of *any* node
|
|
102
|
-
// parentOffset includes textOffset.
|
|
103
|
-
while ($pos.pos < $pos.doc.nodeSize - 2 && $pos.parentOffset > 0) {
|
|
104
|
-
$pos = $pos.doc.resolve($pos.pos + 1);
|
|
105
|
-
}
|
|
106
|
-
return $pos;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Finds the height of a tree-like structure, given any position inside it.
|
|
111
|
-
*
|
|
112
|
-
* Traverses from the top of the tree to all leaf nodes, and returns the length
|
|
113
|
-
* of the longest path.
|
|
114
|
-
*
|
|
115
|
-
* This means you can use it with things like taskList, which
|
|
116
|
-
* do not nest themselves inside taskItems but rather as adjacent children.
|
|
117
|
-
*
|
|
118
|
-
* @param $pos Any position inside the tree.
|
|
119
|
-
* @param types The node types to consider traversable
|
|
120
|
-
*/
|
|
121
|
-
export var subtreeHeight = function subtreeHeight($from, $to, types) {
|
|
122
|
-
var root = findFarthestParentNode(function (node) {
|
|
123
|
-
return types.indexOf(node.type) > -1;
|
|
124
|
-
})($from);
|
|
125
|
-
if (!root) {
|
|
126
|
-
return -1;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// get the height between the root and the current position
|
|
130
|
-
var distToParent = $from.depth - root.depth;
|
|
131
|
-
|
|
132
|
-
// include any following taskList since nested lists appear
|
|
133
|
-
// as siblings
|
|
134
|
-
//
|
|
135
|
-
// this is unlike regular bullet lists where the orderedList
|
|
136
|
-
// appears as descendent of listItem
|
|
137
|
-
var blockRange = getBlockRange($from, $to);
|
|
138
|
-
if (!blockRange) {
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// and get the max height from the current position to the
|
|
143
|
-
// deepest leaf node
|
|
144
|
-
var maxChildDepth = $from.depth;
|
|
145
|
-
$from.doc.nodesBetween(blockRange.start, blockRange.end, function (descendent, relPos, parent) {
|
|
146
|
-
maxChildDepth = Math.max($from.doc.resolve(relPos).depth, maxChildDepth);
|
|
147
|
-
|
|
148
|
-
// keep descending down the tree if we can
|
|
149
|
-
if (types.indexOf(descendent.type) > -1) {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return distToParent + (maxChildDepth - $from.depth);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Returns `true` if the taskItem or decisionItem has no text.
|
|
158
|
-
*/
|
|
159
|
-
export var isEmptyTaskDecision = function isEmptyTaskDecision(state) {
|
|
160
|
-
var selection = state.selection,
|
|
161
|
-
schema = state.schema;
|
|
162
|
-
var $from = selection.$from;
|
|
163
|
-
var node = $from.node($from.depth);
|
|
164
|
-
return node && (node.type === schema.nodes.taskItem || node.type === schema.nodes.decisionItem) && node.content.size === 0;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Lifts a taskItem and any directly following taskList
|
|
169
|
-
* (taskItem and its "nested children") out one level.
|
|
170
|
-
*
|
|
171
|
-
* @param tr Transaction to base steps on
|
|
172
|
-
* @param $from Start of range you want to lift
|
|
173
|
-
* @param $to End of range you want to lift (can be same as `$from`)
|
|
174
|
-
*/
|
|
175
|
-
export var liftBlock = function liftBlock(tr, $from, $to) {
|
|
176
|
-
var blockRange = getBlockRange($from, $to);
|
|
177
|
-
if (!blockRange) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ensure we can actually lift
|
|
182
|
-
var target = liftTarget(blockRange);
|
|
183
|
-
if (typeof target !== 'number') {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
return tr.lift(blockRange, target).scrollIntoView();
|
|
187
|
-
};
|
|
188
|
-
export function getTaskItemDataAtPos(view) {
|
|
189
|
-
var state = view.state;
|
|
190
|
-
var selection = state.selection,
|
|
191
|
-
schema = state.schema;
|
|
192
|
-
var $from = selection.$from;
|
|
193
|
-
var isInTaskItem = $from.node().type === schema.nodes.taskItem;
|
|
194
|
-
|
|
195
|
-
// current selection has to be inside taskitem
|
|
196
|
-
if (isInTaskItem) {
|
|
197
|
-
var taskItemPos = $from.before();
|
|
198
|
-
return {
|
|
199
|
-
pos: taskItemPos,
|
|
200
|
-
localId: $from.node().attrs.localId
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
export function getAllTaskItemsDataInRootTaskList(view) {
|
|
205
|
-
var state = view.state;
|
|
206
|
-
var schema = state.schema;
|
|
207
|
-
var $fromPos = state.selection.$from;
|
|
208
|
-
var isInTaskItem = $fromPos.node().type === schema.nodes.taskItem;
|
|
209
|
-
// if not inside task item then return undefined;
|
|
210
|
-
if (!isInTaskItem) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
var _schema$nodes = schema.nodes,
|
|
214
|
-
taskList = _schema$nodes.taskList,
|
|
215
|
-
taskItem = _schema$nodes.taskItem;
|
|
216
|
-
var rootTaskListData = findFarthestParentNode(function (node) {
|
|
217
|
-
return node.type === taskList;
|
|
218
|
-
})($fromPos);
|
|
219
|
-
if (rootTaskListData) {
|
|
220
|
-
var rootTaskList = rootTaskListData.node;
|
|
221
|
-
var rootTaskListStartPos = rootTaskListData.start;
|
|
222
|
-
var allTaskItems = [];
|
|
223
|
-
rootTaskList.descendants(function (node, pos, parent, index) {
|
|
224
|
-
if (node.type === taskItem) {
|
|
225
|
-
allTaskItems.push({
|
|
226
|
-
node: node,
|
|
227
|
-
pos: pos + rootTaskListStartPos,
|
|
228
|
-
index: index
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
return allTaskItems;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
export function getCurrentTaskItemIndex(view, allTaskItems) {
|
|
236
|
-
var state = view.state;
|
|
237
|
-
var $fromPos = state.selection.$from;
|
|
238
|
-
var allTaskItemNodes = allTaskItems.map(function (nodeData) {
|
|
239
|
-
return nodeData.node;
|
|
240
|
-
});
|
|
241
|
-
var currentTaskItem = $fromPos.node($fromPos.depth);
|
|
242
|
-
var currentTaskItemIndex = allTaskItemNodes.indexOf(currentTaskItem);
|
|
243
|
-
return currentTaskItemIndex;
|
|
244
|
-
}
|
|
245
|
-
export function getTaskItemDataToFocus(view, direction) {
|
|
246
|
-
var allTaskItems = getAllTaskItemsDataInRootTaskList(view);
|
|
247
|
-
// if not inside task item then allTaskItems will be undefined;
|
|
248
|
-
if (!allTaskItems) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
var currentTaskItemIndex = getCurrentTaskItemIndex(view, allTaskItems);
|
|
252
|
-
if (direction === 'next' ? currentTaskItemIndex === allTaskItems.length - 1 : currentTaskItemIndex === 0) {
|
|
253
|
-
// checkbox of first or last task item is already focused based on direction.
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
var indexOfTaskItemToFocus = direction === 'next' ? currentTaskItemIndex + 1 : currentTaskItemIndex - 1;
|
|
257
|
-
var taskItemToFocus = allTaskItems[indexOfTaskItemToFocus];
|
|
258
|
-
return {
|
|
259
|
-
pos: taskItemToFocus.pos,
|
|
260
|
-
localId: taskItemToFocus.node.attrs.localId
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
export function focusCheckboxAndUpdateSelection(view, taskItemData) {
|
|
264
|
-
var pos = taskItemData.pos,
|
|
265
|
-
localId = taskItemData.localId;
|
|
266
|
-
var state = view.state,
|
|
267
|
-
dispatch = view.dispatch;
|
|
268
|
-
var doc = state.doc,
|
|
269
|
-
tr = state.tr;
|
|
270
|
-
tr.setSelection(new TextSelection(doc.resolve(pos + 1)));
|
|
271
|
-
tr.setMeta(stateKey, {
|
|
272
|
-
action: ACTIONS.FOCUS_BY_LOCALID,
|
|
273
|
-
data: localId
|
|
274
|
-
});
|
|
275
|
-
dispatch(tr);
|
|
276
|
-
}
|
|
277
|
-
export function removeCheckboxFocus(view) {
|
|
278
|
-
var state = view.state,
|
|
279
|
-
dispatch = view.dispatch;
|
|
280
|
-
var tr = state.tr;
|
|
281
|
-
view.focus();
|
|
282
|
-
dispatch(tr.setMeta(stateKey, {
|
|
283
|
-
action: ACTIONS.FOCUS_BY_LOCALID
|
|
284
|
-
}));
|
|
285
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
-
import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
7
|
-
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
8
|
-
import { changeInDepth, insertTaskDecisionAction, getListTypes } from '../commands';
|
|
9
|
-
var createListRule = function createListRule(editorAnalyticsAPI) {
|
|
10
|
-
return function (regex, listType, itemAttrs) {
|
|
11
|
-
return createRule(regex, function (state, _match, start, end) {
|
|
12
|
-
var paragraph = state.schema.nodes.paragraph;
|
|
13
|
-
var _getListTypes = getListTypes(listType, state.schema),
|
|
14
|
-
list = _getListTypes.list;
|
|
15
|
-
var $end = state.doc.resolve(end);
|
|
16
|
-
var $endOfParent = state.doc.resolve($end.after());
|
|
17
|
-
// Only allow creating list in nodes that support them.
|
|
18
|
-
// Parent must be a paragraph as we don't want this applying to headings
|
|
19
|
-
if ($end.parent.type !== paragraph || !canInsert($endOfParent, list.createAndFill())) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
var insertTr = insertTaskDecisionAction(editorAnalyticsAPI)(state, listType, INPUT_METHOD.FORMATTING, addItem(start, end), undefined, undefined, itemAttrs);
|
|
23
|
-
return insertTr;
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
var addItem = function addItem(start, end) {
|
|
28
|
-
return function (_ref) {
|
|
29
|
-
var tr = _ref.tr,
|
|
30
|
-
state = _ref.state,
|
|
31
|
-
list = _ref.list,
|
|
32
|
-
item = _ref.item,
|
|
33
|
-
listLocalId = _ref.listLocalId,
|
|
34
|
-
itemLocalId = _ref.itemLocalId,
|
|
35
|
-
itemAttrs = _ref.itemAttrs;
|
|
36
|
-
var $from = state.selection.$from,
|
|
37
|
-
schema = state.schema;
|
|
38
|
-
var hardBreak = schema.nodes.hardBreak;
|
|
39
|
-
var content = $from.node($from.depth).content;
|
|
40
|
-
var shouldBreakNode = false;
|
|
41
|
-
content.forEach(function (node, offset) {
|
|
42
|
-
if (node.type === hardBreak && offset < start) {
|
|
43
|
-
shouldBreakNode = true;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
if (!shouldBreakNode) {
|
|
47
|
-
tr.replaceRangeWith($from.before(), $from.after(), list.create({
|
|
48
|
-
localId: listLocalId
|
|
49
|
-
}, [item.create(_objectSpread({
|
|
50
|
-
localId: itemLocalId
|
|
51
|
-
}, itemAttrs), content)])).delete(start + 1, end + 1).setSelection(new TextSelection(tr.doc.resolve(start + 1)));
|
|
52
|
-
} else {
|
|
53
|
-
var depthAdjustment = changeInDepth($from, tr.selection.$from);
|
|
54
|
-
tr.split($from.pos).setSelection(new NodeSelection(tr.doc.resolve($from.pos + 1))).replaceSelectionWith(list.create({
|
|
55
|
-
localId: listLocalId
|
|
56
|
-
}, [item.create(_objectSpread({
|
|
57
|
-
localId: itemLocalId
|
|
58
|
-
}, itemAttrs),
|
|
59
|
-
// TODO: [ts30] handle void and null properly
|
|
60
|
-
tr.doc.nodeAt($from.pos + 1).content)])).setSelection(new TextSelection(tr.doc.resolve($from.pos + depthAdjustment))).delete(start, end + 1);
|
|
61
|
-
}
|
|
62
|
-
return tr;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
export var inputRulePlugin = function inputRulePlugin(editorAnalyticsAPI) {
|
|
66
|
-
return function (schema, featureFlags) {
|
|
67
|
-
var rules = [];
|
|
68
|
-
var _schema$nodes = schema.nodes,
|
|
69
|
-
decisionList = _schema$nodes.decisionList,
|
|
70
|
-
decisionItem = _schema$nodes.decisionItem,
|
|
71
|
-
taskList = _schema$nodes.taskList,
|
|
72
|
-
taskItem = _schema$nodes.taskItem;
|
|
73
|
-
if (decisionList && decisionItem) {
|
|
74
|
-
rules.push(createListRule(editorAnalyticsAPI)(new RegExp("(^|".concat(leafNodeReplacementCharacter, ")\\<\\>\\s$")), 'decisionList'));
|
|
75
|
-
}
|
|
76
|
-
if (taskList && taskItem) {
|
|
77
|
-
rules.push(createListRule(editorAnalyticsAPI)(new RegExp("(^|".concat(leafNodeReplacementCharacter, ")\\[\\]\\s$")), 'taskList'));
|
|
78
|
-
rules.push(createListRule(editorAnalyticsAPI)(new RegExp("(^|".concat(leafNodeReplacementCharacter, ")\\[x\\]\\s$")), 'taskList', {
|
|
79
|
-
state: 'DONE'
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
return createPlugin('tasks-and-decisions', rules, {
|
|
83
|
-
isBlockNodeRule: true
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
export default inputRulePlugin;
|