@atlaskit/editor-plugin-list 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-plugin-list
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#63553](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63553) [`e022e5359b7a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e022e5359b7a) - [ux] ED-21352: Support more edge cases for ordered list auto-join improvements. These improvements are guarded behind platform.editor.ordered-list-auto-join-improvements_mrlv5.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 3.0.1
4
14
 
5
15
  ### Patch Changes
@@ -29,6 +29,7 @@ var _commands2 = require("@atlaskit/editor-prosemirror/commands");
29
29
  var _model = require("@atlaskit/editor-prosemirror/model");
30
30
  var _state = require("@atlaskit/editor-prosemirror/state");
31
31
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
32
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
32
33
  var _conversions = require("../actions/conversions");
33
34
  var _wrapAndJoinLists = require("../actions/wrap-and-join-lists");
34
35
  var _transforms = require("../transforms");
@@ -326,7 +327,18 @@ var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
326
327
  // as in, [list, p, list] => [list with p, list], and we want [joined list]
327
328
  var $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
328
329
  if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
329
- tr = tr.join($postCut.pos);
330
+ var firstList = $postCut.nodeBefore;
331
+ var secondList = $postCut.nodeAfter;
332
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
333
+ // If lists are ordered, only join if second list continues from the first
334
+ if (!(0, _utils.isOrderedList)(firstList) ||
335
+ // both lists have the same type so one check is sufficient
336
+ (0, _utils.isOrderedListContinuous)(firstList, secondList)) {
337
+ tr = tr.join($postCut.pos);
338
+ }
339
+ } else {
340
+ tr = tr.join($postCut.pos);
341
+ }
330
342
  }
331
343
  if (dispatch) {
332
344
  var _tr$doc$resolve$nodeB;
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createWrappingJoinRule = void 0;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _utils = require("@atlaskit/editor-common/utils");
8
9
  var _transform = require("@atlaskit/editor-prosemirror/transform");
9
- var _utils = require("@atlaskit/editor-prosemirror/utils");
10
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
10
11
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
12
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -38,23 +39,12 @@ var createWrappingJoinRule = exports.createWrappingJoinRule = function createWra
38
39
 
39
40
  // if an orderedList node would be inserted by the input rule match, and
40
41
  // that orderedList node is being added directly after another orderedList
42
+ var $end = tr.doc.resolve(tr.mapping.map(end));
43
+ var nodeWithPos = (0, _utils2.findParentNodeOfTypeClosestToPos)($end, nodeType);
41
44
  if (nodeType === state.schema.nodes.orderedList) {
42
- var $end = tr.doc.resolve(tr.mapping.map(end));
43
- var _node = (0, _utils.findParentNodeOfTypeClosestToPos)($end, nodeType);
44
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
45
- // if there's a list before & the new list has an order property that does
46
- // not match to follow the last number on the first list then do NOT merge the lists
47
- var nodeBeforeSelection = tr.doc.resolve(parentNodePosMapped).nodeBefore;
48
- var nextExpectedNumberAfterListBefore = (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.type.name) === 'orderedList' ? (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.attrs.order) + (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.childCount) : undefined;
49
- var listBeforeDoesNotMatchWithNewList = nodeBeforeSelection && typeof attrs.order === 'number' && nextExpectedNumberAfterListBefore && attrs.order !== nextExpectedNumberAfterListBefore;
50
- if (nodeBeforeSelection && listBeforeDoesNotMatchWithNewList) {
51
- return tr;
52
- }
53
- }
54
-
55
45
  // otherwise join the lists
56
- if (_node) {
57
- var nodeEnd = _node.pos + _node.node.nodeSize;
46
+ if (nodeWithPos) {
47
+ var nodeEnd = nodeWithPos.pos + nodeWithPos.node.nodeSize;
58
48
  var after = tr.doc.resolve(nodeEnd).nodeAfter;
59
49
  if (after && after.type === nodeType && (0, _transform.canJoin)(tr.doc, nodeEnd) && (!joinPredicate || joinPredicate(match, after, _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_BELOW))) {
60
50
  tr.join(nodeEnd);
@@ -63,7 +53,9 @@ var createWrappingJoinRule = exports.createWrappingJoinRule = function createWra
63
53
  }
64
54
  var before = tr.doc.resolve(fixedStart - 1).nodeBefore;
65
55
  if (before && before.type === nodeType && (0, _transform.canJoin)(tr.doc, fixedStart - 1) && (!joinPredicate || joinPredicate(match, before, _analytics.JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_ABOVE))) {
66
- tr.join(fixedStart - 1);
56
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.ordered-list-auto-join-improvements_mrlv5') || !(0, _utils.isOrderedList)(before) || nodeWithPos !== null && nodeWithPos !== void 0 && nodeWithPos.node && (0, _utils.isOrderedListContinuous)(before, nodeWithPos.node)) {
57
+ tr.join(fixedStart - 1);
58
+ }
67
59
  }
68
60
  return tr;
69
61
  };
@@ -3,11 +3,12 @@ import { findCutBefore } from '@atlaskit/editor-common/commands';
3
3
  import { getCommonListAnalyticsAttributes, moveTargetIntoList } from '@atlaskit/editor-common/lists';
4
4
  import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
5
5
  import { GapCursorSelection } from '@atlaskit/editor-common/selection';
6
- import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart } from '@atlaskit/editor-common/utils';
6
+ import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart, isOrderedList, isOrderedListContinuous } from '@atlaskit/editor-common/utils';
7
7
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
8
8
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
9
9
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
10
  import { findPositionOfNodeBefore, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
12
  import { convertListType } from '../actions/conversions';
12
13
  import { wrapInListAndJoin } from '../actions/wrap-and-join-lists';
13
14
  import { liftFollowingList, liftNodeSelectionList, liftTextSelectionList } from '../transforms';
@@ -306,7 +307,18 @@ const joinToPreviousListItem = (state, dispatch) => {
306
307
  // as in, [list, p, list] => [list with p, list], and we want [joined list]
307
308
  let $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
308
309
  if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
309
- tr = tr.join($postCut.pos);
310
+ const firstList = $postCut.nodeBefore;
311
+ const secondList = $postCut.nodeAfter;
312
+ if (getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
313
+ // If lists are ordered, only join if second list continues from the first
314
+ if (!isOrderedList(firstList) ||
315
+ // both lists have the same type so one check is sufficient
316
+ isOrderedListContinuous(firstList, secondList)) {
317
+ tr = tr.join($postCut.pos);
318
+ }
319
+ } else {
320
+ tr = tr.join($postCut.pos);
321
+ }
310
322
  }
311
323
  if (dispatch) {
312
324
  var _tr$doc$resolve$nodeB;
@@ -1,4 +1,5 @@
1
1
  import { JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST } from '@atlaskit/editor-common/analytics';
2
+ import { isOrderedList, isOrderedListContinuous } from '@atlaskit/editor-common/utils';
2
3
  import { canJoin, findWrapping } from '@atlaskit/editor-prosemirror/transform';
3
4
  import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
4
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -34,23 +35,12 @@ export const createWrappingJoinRule = ({
34
35
 
35
36
  // if an orderedList node would be inserted by the input rule match, and
36
37
  // that orderedList node is being added directly after another orderedList
38
+ const $end = tr.doc.resolve(tr.mapping.map(end));
39
+ const nodeWithPos = findParentNodeOfTypeClosestToPos($end, nodeType);
37
40
  if (nodeType === state.schema.nodes.orderedList) {
38
- const $end = tr.doc.resolve(tr.mapping.map(end));
39
- const node = findParentNodeOfTypeClosestToPos($end, nodeType);
40
- if (getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
41
- // if there's a list before & the new list has an order property that does
42
- // not match to follow the last number on the first list then do NOT merge the lists
43
- const nodeBeforeSelection = tr.doc.resolve(parentNodePosMapped).nodeBefore;
44
- const nextExpectedNumberAfterListBefore = (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.type.name) === 'orderedList' ? (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.attrs.order) + (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.childCount) : undefined;
45
- const listBeforeDoesNotMatchWithNewList = nodeBeforeSelection && typeof attrs.order === 'number' && nextExpectedNumberAfterListBefore && attrs.order !== nextExpectedNumberAfterListBefore;
46
- if (nodeBeforeSelection && listBeforeDoesNotMatchWithNewList) {
47
- return tr;
48
- }
49
- }
50
-
51
41
  // otherwise join the lists
52
- if (node) {
53
- const nodeEnd = node.pos + node.node.nodeSize;
42
+ if (nodeWithPos) {
43
+ const nodeEnd = nodeWithPos.pos + nodeWithPos.node.nodeSize;
54
44
  const after = tr.doc.resolve(nodeEnd).nodeAfter;
55
45
  if (after && after.type === nodeType && canJoin(tr.doc, nodeEnd) && (!joinPredicate || joinPredicate(match, after, JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_BELOW))) {
56
46
  tr.join(nodeEnd);
@@ -59,7 +49,9 @@ export const createWrappingJoinRule = ({
59
49
  }
60
50
  const before = tr.doc.resolve(fixedStart - 1).nodeBefore;
61
51
  if (before && before.type === nodeType && canJoin(tr.doc, fixedStart - 1) && (!joinPredicate || joinPredicate(match, before, JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_ABOVE))) {
62
- tr.join(fixedStart - 1);
52
+ if (!getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5') || !isOrderedList(before) || nodeWithPos !== null && nodeWithPos !== void 0 && nodeWithPos.node && isOrderedListContinuous(before, nodeWithPos.node)) {
53
+ tr.join(fixedStart - 1);
54
+ }
63
55
  }
64
56
  return tr;
65
57
  };
@@ -6,11 +6,12 @@ import { findCutBefore } from '@atlaskit/editor-common/commands';
6
6
  import { getCommonListAnalyticsAttributes, moveTargetIntoList } from '@atlaskit/editor-common/lists';
7
7
  import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
8
8
  import { GapCursorSelection } from '@atlaskit/editor-common/selection';
9
- import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart } from '@atlaskit/editor-common/utils';
9
+ import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart, isOrderedList, isOrderedListContinuous } from '@atlaskit/editor-common/utils';
10
10
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
11
11
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
12
12
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
13
13
  import { findPositionOfNodeBefore, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
14
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
15
  import { convertListType } from '../actions/conversions';
15
16
  import { wrapInListAndJoin } from '../actions/wrap-and-join-lists';
16
17
  import { liftFollowingList, liftNodeSelectionList, liftTextSelectionList } from '../transforms';
@@ -307,7 +308,18 @@ var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
307
308
  // as in, [list, p, list] => [list with p, list], and we want [joined list]
308
309
  var $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
309
310
  if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
310
- tr = tr.join($postCut.pos);
311
+ var firstList = $postCut.nodeBefore;
312
+ var secondList = $postCut.nodeAfter;
313
+ if (getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
314
+ // If lists are ordered, only join if second list continues from the first
315
+ if (!isOrderedList(firstList) ||
316
+ // both lists have the same type so one check is sufficient
317
+ isOrderedListContinuous(firstList, secondList)) {
318
+ tr = tr.join($postCut.pos);
319
+ }
320
+ } else {
321
+ tr = tr.join($postCut.pos);
322
+ }
311
323
  }
312
324
  if (dispatch) {
313
325
  var _tr$doc$resolve$nodeB;
@@ -1,4 +1,5 @@
1
1
  import { JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST } from '@atlaskit/editor-common/analytics';
2
+ import { isOrderedList, isOrderedListContinuous } from '@atlaskit/editor-common/utils';
2
3
  import { canJoin, findWrapping } from '@atlaskit/editor-prosemirror/transform';
3
4
  import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
4
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -33,23 +34,12 @@ export var createWrappingJoinRule = function createWrappingJoinRule(_ref) {
33
34
 
34
35
  // if an orderedList node would be inserted by the input rule match, and
35
36
  // that orderedList node is being added directly after another orderedList
37
+ var $end = tr.doc.resolve(tr.mapping.map(end));
38
+ var nodeWithPos = findParentNodeOfTypeClosestToPos($end, nodeType);
36
39
  if (nodeType === state.schema.nodes.orderedList) {
37
- var $end = tr.doc.resolve(tr.mapping.map(end));
38
- var _node = findParentNodeOfTypeClosestToPos($end, nodeType);
39
- if (getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5')) {
40
- // if there's a list before & the new list has an order property that does
41
- // not match to follow the last number on the first list then do NOT merge the lists
42
- var nodeBeforeSelection = tr.doc.resolve(parentNodePosMapped).nodeBefore;
43
- var nextExpectedNumberAfterListBefore = (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.type.name) === 'orderedList' ? (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.attrs.order) + (nodeBeforeSelection === null || nodeBeforeSelection === void 0 ? void 0 : nodeBeforeSelection.childCount) : undefined;
44
- var listBeforeDoesNotMatchWithNewList = nodeBeforeSelection && typeof attrs.order === 'number' && nextExpectedNumberAfterListBefore && attrs.order !== nextExpectedNumberAfterListBefore;
45
- if (nodeBeforeSelection && listBeforeDoesNotMatchWithNewList) {
46
- return tr;
47
- }
48
- }
49
-
50
40
  // otherwise join the lists
51
- if (_node) {
52
- var nodeEnd = _node.pos + _node.node.nodeSize;
41
+ if (nodeWithPos) {
42
+ var nodeEnd = nodeWithPos.pos + nodeWithPos.node.nodeSize;
53
43
  var after = tr.doc.resolve(nodeEnd).nodeAfter;
54
44
  if (after && after.type === nodeType && canJoin(tr.doc, nodeEnd) && (!joinPredicate || joinPredicate(match, after, JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_BELOW))) {
55
45
  tr.join(nodeEnd);
@@ -58,7 +48,9 @@ export var createWrappingJoinRule = function createWrappingJoinRule(_ref) {
58
48
  }
59
49
  var before = tr.doc.resolve(fixedStart - 1).nodeBefore;
60
50
  if (before && before.type === nodeType && canJoin(tr.doc, fixedStart - 1) && (!joinPredicate || joinPredicate(match, before, JOIN_SCENARIOS_WHEN_TYPING_TO_INSERT_LIST.JOINED_TO_LIST_ABOVE))) {
61
- tr.join(fixedStart - 1);
51
+ if (!getBooleanFF('platform.editor.ordered-list-auto-join-improvements_mrlv5') || !isOrderedList(before) || nodeWithPos !== null && nodeWithPos !== void 0 && nodeWithPos.node && isOrderedListContinuous(before, nodeWithPos.node)) {
52
+ tr.join(fixedStart - 1);
53
+ }
62
54
  }
63
55
  return tr;
64
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-list",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "List plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -10,7 +10,8 @@
10
10
  "atlassian": {
11
11
  "team": "Editor: AI",
12
12
  "releaseModel": "continuous",
13
- "singleton": true
13
+ "singleton": true,
14
+ "runReact18": false
14
15
  },
15
16
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend",
16
17
  "main": "dist/cjs/index.js",
@@ -32,7 +33,7 @@
32
33
  },
33
34
  "dependencies": {
34
35
  "@atlaskit/adf-schema": "^35.2.0",
35
- "@atlaskit/editor-common": "^76.27.0",
36
+ "@atlaskit/editor-common": "^76.31.0",
36
37
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
37
38
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
38
39
  "@atlaskit/editor-prosemirror": "1.1.0",