@atlaskit/editor-plugin-tasks-and-decisions 6.2.2 → 6.2.3

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-tasks-and-decisions
2
2
 
3
+ ## 6.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#201339](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/201339)
8
+ [`b734e816f63ba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b734e816f63ba) -
9
+ [EDITOR-1150] Handle pressing Enter in blockTaskItems
10
+
3
11
  ## 6.2.2
4
12
 
5
13
  ### Patch Changes
@@ -25,8 +25,9 @@ var _types = require("./types");
25
25
  var isInsideTaskOrDecisionItem = exports.isInsideTaskOrDecisionItem = function isInsideTaskOrDecisionItem(state) {
26
26
  var _state$schema$nodes = state.schema.nodes,
27
27
  decisionItem = _state$schema$nodes.decisionItem,
28
- taskItem = _state$schema$nodes.taskItem;
29
- return (0, _utils2.hasParentNodeOfType)([decisionItem, taskItem])(state.selection);
28
+ taskItem = _state$schema$nodes.taskItem,
29
+ blockTaskItem = _state$schema$nodes.blockTaskItem;
30
+ return (0, _utils2.hasParentNodeOfType)([decisionItem, taskItem, blockTaskItem])(state.selection);
30
31
  };
31
32
  var isActionOrDecisionList = exports.isActionOrDecisionList = function isActionOrDecisionList(node) {
32
33
  var _node$type$schema$nod = node.type.schema.nodes,
@@ -348,12 +348,25 @@ var enter = function enter(editorAnalyticsAPI, getContextIdentifier) {
348
348
  return (0, _utils.filterCommand)(_helpers.isInsideTaskOrDecisionItem, (0, _commands.chainCommands)((0, _utils.filterCommand)(_helpers.isEmptyTaskDecision, (0, _commands.chainCommands)(getUnindentCommand(editorAnalyticsAPI)(), splitListItem)), function (state, dispatch) {
349
349
  var selection = state.selection,
350
350
  schema = state.schema;
351
- var taskItem = schema.nodes.taskItem;
351
+ var _schema$nodes = schema.nodes,
352
+ decisionItem = _schema$nodes.decisionItem,
353
+ taskItem = _schema$nodes.taskItem,
354
+ blockTaskItem = _schema$nodes.blockTaskItem;
352
355
  var $from = selection.$from,
353
356
  $to = selection.$to;
354
357
  var node = $from.node($from.depth);
355
358
  var nodeType = node && node.type;
356
- var listType = nodeType === taskItem ? 'taskList' : 'decisionList';
359
+
360
+ // Get the parent node type if the current node type is not one of the task or decision items
361
+ // This is required to handle blockTaskItem
362
+ if (![decisionItem, taskItem, blockTaskItem].includes(nodeType)) {
363
+ var _findParentNodeOfType;
364
+ var possibleNodeType = (_findParentNodeOfType = (0, _utils2.findParentNodeOfType)([decisionItem, taskItem, blockTaskItem])(selection)) === null || _findParentNodeOfType === void 0 || (_findParentNodeOfType = _findParentNodeOfType.node) === null || _findParentNodeOfType === void 0 ? void 0 : _findParentNodeOfType.type;
365
+ if (possibleNodeType) {
366
+ nodeType = possibleNodeType;
367
+ }
368
+ }
369
+ var listType = [taskItem, blockTaskItem].includes(nodeType) ? 'taskList' : 'decisionList';
357
370
  var addItem = function addItem(_ref) {
358
371
  var tr = _ref.tr,
359
372
  itemLocalId = _ref.itemLocalId;
@@ -363,10 +376,55 @@ var enter = function enter(editorAnalyticsAPI, getContextIdentifier) {
363
376
  localId: itemLocalId
364
377
  });
365
378
  if (newTask) {
379
+ if (nodeType === blockTaskItem) {
380
+ var blockTaskItemNode = (0, _utils2.findParentNodeOfType)([blockTaskItem])(selection);
381
+
382
+ // New task items for blockTaskItem should be taskItem
383
+ // We want to prevent creating new blockTaskItems as much as possible
384
+ var newTaskItem = taskItem.createAndFill({
385
+ localId: itemLocalId
386
+ });
387
+ if (!blockTaskItemNode || !newTaskItem) {
388
+ return tr;
389
+ }
390
+ return tr.insert(blockTaskItemNode.pos, newTaskItem);
391
+ }
366
392
  // Current position will point to text node, but we want to insert above the taskItem node
367
393
  return tr.insert($from.pos - 1, newTask);
368
394
  }
369
395
  }
396
+ /**
397
+ * For blockTaskItem, must handle it differently because it can have a different depth
398
+ */
399
+ if (nodeType === blockTaskItem) {
400
+ var _blockTaskItemNode = (0, _utils2.findParentNodeOfType)([blockTaskItem])(selection);
401
+ if (!_blockTaskItemNode) {
402
+ return tr;
403
+ }
404
+
405
+ // If the selection is a gap cursor at the end of the blockTaskItem,
406
+ // we should insert a new taskItem.
407
+ if ($from.parentOffset === $from.parent.nodeSize - 2) {
408
+ var _newTaskItem = taskItem.createAndFill({
409
+ localId: itemLocalId
410
+ });
411
+ if (_newTaskItem) {
412
+ tr.insert(_blockTaskItemNode.pos + _blockTaskItemNode.node.nodeSize, _newTaskItem);
413
+
414
+ // Move the cursor to the end of the newly inserted blockTaskItem
415
+ tr.setSelection(_state.TextSelection.create(tr.doc, _blockTaskItemNode.pos + _blockTaskItemNode.node.nodeSize + 1));
416
+ return tr;
417
+ }
418
+ }
419
+
420
+ // Split near the depth of the current selection
421
+ return tr.split($from.pos, $from.depth - 1, [{
422
+ type: blockTaskItem,
423
+ attrs: {
424
+ localId: itemLocalId
425
+ }
426
+ }]);
427
+ }
370
428
  return tr.split($from.pos, 1, [{
371
429
  type: nodeType,
372
430
  attrs: {
@@ -7,9 +7,10 @@ import { ACTIONS } from './types';
7
7
  export const isInsideTaskOrDecisionItem = state => {
8
8
  const {
9
9
  decisionItem,
10
- taskItem
10
+ taskItem,
11
+ blockTaskItem
11
12
  } = state.schema.nodes;
12
- return hasParentNodeOfType([decisionItem, taskItem])(state.selection);
13
+ return hasParentNodeOfType([decisionItem, taskItem, blockTaskItem])(state.selection);
13
14
  };
14
15
  export const isActionOrDecisionList = node => {
15
16
  const {
@@ -337,15 +337,27 @@ const enter = (editorAnalyticsAPI, getContextIdentifier) => filter(isInsideTaskO
337
337
  schema
338
338
  } = state;
339
339
  const {
340
- taskItem
340
+ decisionItem,
341
+ taskItem,
342
+ blockTaskItem
341
343
  } = schema.nodes;
342
344
  const {
343
345
  $from,
344
346
  $to
345
347
  } = selection;
346
348
  const node = $from.node($from.depth);
347
- const nodeType = node && node.type;
348
- const listType = nodeType === taskItem ? 'taskList' : 'decisionList';
349
+ let nodeType = node && node.type;
350
+
351
+ // Get the parent node type if the current node type is not one of the task or decision items
352
+ // This is required to handle blockTaskItem
353
+ if (![decisionItem, taskItem, blockTaskItem].includes(nodeType)) {
354
+ var _findParentNodeOfType, _findParentNodeOfType2;
355
+ const possibleNodeType = (_findParentNodeOfType = findParentNodeOfType([decisionItem, taskItem, blockTaskItem])(selection)) === null || _findParentNodeOfType === void 0 ? void 0 : (_findParentNodeOfType2 = _findParentNodeOfType.node) === null || _findParentNodeOfType2 === void 0 ? void 0 : _findParentNodeOfType2.type;
356
+ if (possibleNodeType) {
357
+ nodeType = possibleNodeType;
358
+ }
359
+ }
360
+ const listType = [taskItem, blockTaskItem].includes(nodeType) ? 'taskList' : 'decisionList';
349
361
  const addItem = ({
350
362
  tr,
351
363
  itemLocalId
@@ -356,10 +368,55 @@ const enter = (editorAnalyticsAPI, getContextIdentifier) => filter(isInsideTaskO
356
368
  localId: itemLocalId
357
369
  });
358
370
  if (newTask) {
371
+ if (nodeType === blockTaskItem) {
372
+ const blockTaskItemNode = findParentNodeOfType([blockTaskItem])(selection);
373
+
374
+ // New task items for blockTaskItem should be taskItem
375
+ // We want to prevent creating new blockTaskItems as much as possible
376
+ const newTaskItem = taskItem.createAndFill({
377
+ localId: itemLocalId
378
+ });
379
+ if (!blockTaskItemNode || !newTaskItem) {
380
+ return tr;
381
+ }
382
+ return tr.insert(blockTaskItemNode.pos, newTaskItem);
383
+ }
359
384
  // Current position will point to text node, but we want to insert above the taskItem node
360
385
  return tr.insert($from.pos - 1, newTask);
361
386
  }
362
387
  }
388
+ /**
389
+ * For blockTaskItem, must handle it differently because it can have a different depth
390
+ */
391
+ if (nodeType === blockTaskItem) {
392
+ const blockTaskItemNode = findParentNodeOfType([blockTaskItem])(selection);
393
+ if (!blockTaskItemNode) {
394
+ return tr;
395
+ }
396
+
397
+ // If the selection is a gap cursor at the end of the blockTaskItem,
398
+ // we should insert a new taskItem.
399
+ if ($from.parentOffset === $from.parent.nodeSize - 2) {
400
+ const newTaskItem = taskItem.createAndFill({
401
+ localId: itemLocalId
402
+ });
403
+ if (newTaskItem) {
404
+ tr.insert(blockTaskItemNode.pos + blockTaskItemNode.node.nodeSize, newTaskItem);
405
+
406
+ // Move the cursor to the end of the newly inserted blockTaskItem
407
+ tr.setSelection(TextSelection.create(tr.doc, blockTaskItemNode.pos + blockTaskItemNode.node.nodeSize + 1));
408
+ return tr;
409
+ }
410
+ }
411
+
412
+ // Split near the depth of the current selection
413
+ return tr.split($from.pos, $from.depth - 1, [{
414
+ type: blockTaskItem,
415
+ attrs: {
416
+ localId: itemLocalId
417
+ }
418
+ }]);
419
+ }
363
420
  return tr.split($from.pos, 1, [{
364
421
  type: nodeType,
365
422
  attrs: {
@@ -7,8 +7,9 @@ import { ACTIONS } from './types';
7
7
  export var isInsideTaskOrDecisionItem = function isInsideTaskOrDecisionItem(state) {
8
8
  var _state$schema$nodes = state.schema.nodes,
9
9
  decisionItem = _state$schema$nodes.decisionItem,
10
- taskItem = _state$schema$nodes.taskItem;
11
- return hasParentNodeOfType([decisionItem, taskItem])(state.selection);
10
+ taskItem = _state$schema$nodes.taskItem,
11
+ blockTaskItem = _state$schema$nodes.blockTaskItem;
12
+ return hasParentNodeOfType([decisionItem, taskItem, blockTaskItem])(state.selection);
12
13
  };
13
14
  export var isActionOrDecisionList = function isActionOrDecisionList(node) {
14
15
  var _node$type$schema$nod = node.type.schema.nodes,
@@ -340,12 +340,25 @@ var enter = function enter(editorAnalyticsAPI, getContextIdentifier) {
340
340
  return filter(isInsideTaskOrDecisionItem, chainCommands(filter(isEmptyTaskDecision, chainCommands(getUnindentCommand(editorAnalyticsAPI)(), splitListItem)), function (state, dispatch) {
341
341
  var selection = state.selection,
342
342
  schema = state.schema;
343
- var taskItem = schema.nodes.taskItem;
343
+ var _schema$nodes = schema.nodes,
344
+ decisionItem = _schema$nodes.decisionItem,
345
+ taskItem = _schema$nodes.taskItem,
346
+ blockTaskItem = _schema$nodes.blockTaskItem;
344
347
  var $from = selection.$from,
345
348
  $to = selection.$to;
346
349
  var node = $from.node($from.depth);
347
350
  var nodeType = node && node.type;
348
- var listType = nodeType === taskItem ? 'taskList' : 'decisionList';
351
+
352
+ // Get the parent node type if the current node type is not one of the task or decision items
353
+ // This is required to handle blockTaskItem
354
+ if (![decisionItem, taskItem, blockTaskItem].includes(nodeType)) {
355
+ var _findParentNodeOfType;
356
+ var possibleNodeType = (_findParentNodeOfType = findParentNodeOfType([decisionItem, taskItem, blockTaskItem])(selection)) === null || _findParentNodeOfType === void 0 || (_findParentNodeOfType = _findParentNodeOfType.node) === null || _findParentNodeOfType === void 0 ? void 0 : _findParentNodeOfType.type;
357
+ if (possibleNodeType) {
358
+ nodeType = possibleNodeType;
359
+ }
360
+ }
361
+ var listType = [taskItem, blockTaskItem].includes(nodeType) ? 'taskList' : 'decisionList';
349
362
  var addItem = function addItem(_ref) {
350
363
  var tr = _ref.tr,
351
364
  itemLocalId = _ref.itemLocalId;
@@ -355,10 +368,55 @@ var enter = function enter(editorAnalyticsAPI, getContextIdentifier) {
355
368
  localId: itemLocalId
356
369
  });
357
370
  if (newTask) {
371
+ if (nodeType === blockTaskItem) {
372
+ var blockTaskItemNode = findParentNodeOfType([blockTaskItem])(selection);
373
+
374
+ // New task items for blockTaskItem should be taskItem
375
+ // We want to prevent creating new blockTaskItems as much as possible
376
+ var newTaskItem = taskItem.createAndFill({
377
+ localId: itemLocalId
378
+ });
379
+ if (!blockTaskItemNode || !newTaskItem) {
380
+ return tr;
381
+ }
382
+ return tr.insert(blockTaskItemNode.pos, newTaskItem);
383
+ }
358
384
  // Current position will point to text node, but we want to insert above the taskItem node
359
385
  return tr.insert($from.pos - 1, newTask);
360
386
  }
361
387
  }
388
+ /**
389
+ * For blockTaskItem, must handle it differently because it can have a different depth
390
+ */
391
+ if (nodeType === blockTaskItem) {
392
+ var _blockTaskItemNode = findParentNodeOfType([blockTaskItem])(selection);
393
+ if (!_blockTaskItemNode) {
394
+ return tr;
395
+ }
396
+
397
+ // If the selection is a gap cursor at the end of the blockTaskItem,
398
+ // we should insert a new taskItem.
399
+ if ($from.parentOffset === $from.parent.nodeSize - 2) {
400
+ var _newTaskItem = taskItem.createAndFill({
401
+ localId: itemLocalId
402
+ });
403
+ if (_newTaskItem) {
404
+ tr.insert(_blockTaskItemNode.pos + _blockTaskItemNode.node.nodeSize, _newTaskItem);
405
+
406
+ // Move the cursor to the end of the newly inserted blockTaskItem
407
+ tr.setSelection(TextSelection.create(tr.doc, _blockTaskItemNode.pos + _blockTaskItemNode.node.nodeSize + 1));
408
+ return tr;
409
+ }
410
+ }
411
+
412
+ // Split near the depth of the current selection
413
+ return tr.split($from.pos, $from.depth - 1, [{
414
+ type: blockTaskItem,
415
+ attrs: {
416
+ localId: itemLocalId
417
+ }
418
+ }]);
419
+ }
362
420
  return tr.split($from.pos, 1, [{
363
421
  type: nodeType,
364
422
  attrs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-tasks-and-decisions",
3
- "version": "6.2.2",
3
+ "version": "6.2.3",
4
4
  "description": "Tasks and decisions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -49,7 +49,7 @@
49
49
  "@atlaskit/primitives": "^14.11.0",
50
50
  "@atlaskit/prosemirror-input-rules": "^3.4.0",
51
51
  "@atlaskit/task-decision": "^19.2.0",
52
- "@atlaskit/tmp-editor-statsig": "^9.27.0",
52
+ "@atlaskit/tmp-editor-statsig": "^9.28.0",
53
53
  "@atlaskit/tokens": "^6.0.0",
54
54
  "@babel/runtime": "^7.0.0",
55
55
  "@compiled/react": "^0.18.3",