@atlaskit/editor-plugin-list 1.0.0 → 1.1.2

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/actions/outdent-list-items-selected.js +1 -3
  3. package/dist/cjs/commands/indent-list.js +12 -14
  4. package/dist/cjs/commands/index.js +26 -27
  5. package/dist/cjs/commands/outdent-list.js +13 -14
  6. package/dist/cjs/plugin.js +8 -4
  7. package/dist/cjs/pm-plugins/keymap.js +4 -4
  8. package/dist/cjs/utils/selection.js +14 -14
  9. package/dist/es2019/actions/outdent-list-items-selected.js +1 -3
  10. package/dist/es2019/commands/indent-list.js +13 -14
  11. package/dist/es2019/commands/index.js +19 -23
  12. package/dist/es2019/commands/outdent-list.js +14 -14
  13. package/dist/es2019/plugin.js +6 -4
  14. package/dist/es2019/pm-plugins/keymap.js +5 -5
  15. package/dist/es2019/utils/selection.js +12 -12
  16. package/dist/esm/actions/outdent-list-items-selected.js +1 -3
  17. package/dist/esm/commands/indent-list.js +12 -14
  18. package/dist/esm/commands/index.js +26 -27
  19. package/dist/esm/commands/outdent-list.js +13 -14
  20. package/dist/esm/plugin.js +9 -5
  21. package/dist/esm/pm-plugins/keymap.js +5 -5
  22. package/dist/esm/utils/selection.js +14 -14
  23. package/dist/types/actions/outdent-list-items-selected.d.ts +2 -2
  24. package/dist/types/commands/indent-list.d.ts +2 -2
  25. package/dist/types/commands/index.d.ts +4 -5
  26. package/dist/types/commands/outdent-list.d.ts +2 -2
  27. package/dist/types/types.d.ts +15 -16
  28. package/dist/types/utils/selection.d.ts +4 -4
  29. package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +2 -2
  30. package/dist/types-ts4.5/commands/indent-list.d.ts +2 -2
  31. package/dist/types-ts4.5/commands/index.d.ts +4 -5
  32. package/dist/types-ts4.5/commands/outdent-list.d.ts +2 -2
  33. package/dist/types-ts4.5/types.d.ts +16 -14
  34. package/dist/types-ts4.5/utils/selection.d.ts +4 -4
  35. package/package.json +3 -4
  36. package/report.api.md +14 -22
  37. package/tmp/api-report-tmp.d.ts +0 -80
@@ -1,5 +1,6 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, OUTDENT_SCENARIOS } from '@atlaskit/editor-common/analytics';
2
2
  import { getCommonListAnalyticsAttributes } from '@atlaskit/editor-common/lists';
3
+ import { PassiveTransaction } from '@atlaskit/editor-common/preset';
3
4
  import { isBulletList } from '@atlaskit/editor-common/utils';
4
5
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
5
6
  import { outdentListItemsSelected as outdentListAction } from '../actions/outdent-list-items-selected';
@@ -7,28 +8,30 @@ import { getRestartListsAttributes } from '../utils/analytics';
7
8
  import { findFirstParentListNode } from '../utils/find';
8
9
  import { isInsideListItem, isInsideTableCell } from '../utils/selection';
9
10
  export const outdentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYBOARD, featureFlags) => {
10
- return function (state, dispatch) {
11
- if (!isInsideListItem(state)) {
12
- return false;
11
+ return function ({
12
+ tr
13
+ }) {
14
+ if (!isInsideListItem(tr)) {
15
+ return null;
13
16
  }
14
17
  const {
15
18
  $from
16
- } = state.selection;
19
+ } = tr.selection;
17
20
  const parentListNode = findFirstParentListNode($from);
18
21
  if (!parentListNode) {
19
22
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
20
- return true;
23
+ return new PassiveTransaction();
21
24
  }
22
25
 
23
26
  // Save the history, so it could undo/revert to the same state before the outdent, see https://product-fabric.atlassian.net/browse/ED-14753
24
- closeHistory(state.tr);
27
+ closeHistory(tr);
25
28
  const actionSubjectId = isBulletList(parentListNode.node) ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
26
- let customTr = state.tr;
27
- outdentListAction(customTr, state, featureFlags);
29
+ let customTr = tr;
30
+ outdentListAction(customTr, featureFlags);
28
31
  if (!customTr || !customTr.docChanged) {
29
32
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
30
33
  // If inside table cell and can't outdent list, then let it handle by table keymap
31
- return !isInsideTableCell(state);
34
+ return !isInsideTableCell(customTr) ? new PassiveTransaction() : null;
32
35
  }
33
36
  const restartListsAttributes = {};
34
37
  if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
@@ -47,14 +50,11 @@ export const outdentList = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEY
47
50
  actionSubjectId,
48
51
  eventType: EVENT_TYPE.TRACK,
49
52
  attributes: {
50
- ...getCommonListAnalyticsAttributes(state),
53
+ ...getCommonListAnalyticsAttributes(customTr),
51
54
  ...restartListsAttributes,
52
55
  inputMethod
53
56
  }
54
57
  })(customTr);
55
- if (dispatch) {
56
- dispatch(customTr);
57
- }
58
- return true;
58
+ return customTr;
59
59
  };
60
60
  };
@@ -22,13 +22,15 @@ export const listPlugin = (options, api) => {
22
22
  return {
23
23
  name: 'list',
24
24
  actions: {
25
- indentList: indentList(editorAnalyticsAPI),
26
- outdentList: outdentList(editorAnalyticsAPI),
27
- toggleOrderedList: toggleOrderedListCommand(editorAnalyticsAPI),
28
- toggleBulletList: toggleBulletListCommand(editorAnalyticsAPI),
29
25
  isInsideListItem,
30
26
  findRootParentListNode
31
27
  },
28
+ commands: {
29
+ indentList: indentList(editorAnalyticsAPI),
30
+ outdentList: inputMethod => outdentList(editorAnalyticsAPI)(inputMethod, featureFlags),
31
+ toggleOrderedList: toggleOrderedListCommand(editorAnalyticsAPI),
32
+ toggleBulletList: toggleBulletListCommand(editorAnalyticsAPI)
33
+ },
32
34
  getSharedState: editorState => {
33
35
  if (!editorState) {
34
36
  return undefined;
@@ -1,13 +1,13 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { backspace, bindKeymapWithCommand, deleteKey, enter, findKeyMapForBrowser, findShortcutByKeymap, forwardDelete, indentList, outdentList, toggleBulletList, toggleOrderedList } from '@atlaskit/editor-common/keymaps';
2
+ import { backspace, bindKeymapWithCommand, bindKeymapWithEditorCommand, deleteKey, enter, findKeyMapForBrowser, findShortcutByKeymap, forwardDelete, indentList, outdentList, toggleBulletList, toggleOrderedList } from '@atlaskit/editor-common/keymaps';
3
3
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { backspaceKeyCommand, deleteKeyCommand, enterKeyCommand, indentList as indentListCommand, outdentList as outdentListCommand, toggleList } from '../commands';
5
5
  export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
6
6
  const list = {};
7
- bindKeymapWithCommand(findShortcutByKeymap(toggleOrderedList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'orderedList'), list);
8
- bindKeymapWithCommand(findShortcutByKeymap(toggleBulletList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'bulletList'), list);
9
- bindKeymapWithCommand(indentList.common, indentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
10
- bindKeymapWithCommand(outdentList.common, outdentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags), list);
7
+ bindKeymapWithEditorCommand(findShortcutByKeymap(toggleOrderedList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'orderedList'), list);
8
+ bindKeymapWithEditorCommand(findShortcutByKeymap(toggleBulletList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'bulletList'), list);
9
+ bindKeymapWithEditorCommand(indentList.common, indentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
10
+ bindKeymapWithEditorCommand(outdentList.common, outdentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags), list);
11
11
  bindKeymapWithCommand(enter.common, enterKeyCommand(editorAnalyticsAPI)(featureFlags), list);
12
12
  bindKeymapWithCommand(backspace.common, backspaceKeyCommand(editorAnalyticsAPI)(featureFlags), list);
13
13
  bindKeymapWithCommand(deleteKey.common, deleteKeyCommand(editorAnalyticsAPI), list);
@@ -32,32 +32,32 @@ export const isWrappingPossible = (nodeType, selection) => {
32
32
  };
33
33
 
34
34
  // canOutdent
35
- export const isInsideListItem = state => {
35
+ export const isInsideListItem = tr => {
36
36
  const {
37
37
  parent
38
- } = state.selection.$from;
38
+ } = tr.selection.$from;
39
39
  const {
40
40
  listItem
41
- } = state.schema.nodes;
42
- if (state.selection instanceof GapCursorSelection) {
41
+ } = tr.doc.type.schema.nodes;
42
+ if (tr.selection instanceof GapCursorSelection) {
43
43
  return isListItemNode(parent);
44
44
  }
45
- return hasParentNodeOfType(listItem)(state.selection) && isParagraphNode(parent);
45
+ return hasParentNodeOfType(listItem)(tr.selection) && isParagraphNode(parent);
46
46
  };
47
- export const isInsideTableCell = state => {
47
+ export const isInsideTableCell = tr => {
48
48
  const {
49
49
  tableCell,
50
50
  tableHeader
51
- } = state.schema.nodes;
52
- return !!findParentNodeOfType([tableCell, tableHeader])(state.selection);
51
+ } = tr.doc.type.schema.nodes;
52
+ return !!findParentNodeOfType([tableCell, tableHeader])(tr.selection);
53
53
  };
54
- export const canJoinToPreviousListItem = state => {
54
+ export const canJoinToPreviousListItem = tr => {
55
55
  const {
56
56
  $from
57
- } = state.selection;
58
- const $before = state.doc.resolve($from.pos - 1);
57
+ } = tr.selection;
58
+ const $before = tr.doc.resolve($from.pos - 1);
59
59
  let nodeBefore = $before ? $before.nodeBefore : null;
60
- if (state.selection instanceof GapCursorSelection) {
60
+ if (tr.selection instanceof GapCursorSelection) {
61
61
  nodeBefore = $from.nodeBefore;
62
62
  }
63
63
  return isListNode(nodeBefore);
@@ -11,7 +11,7 @@ import { liftTarget, ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-pro
11
11
  import { getRestartListsAttributes, storeRestartListsAttributes } from '../utils/analytics';
12
12
  import { findFirstParentListItemNode, findRootParentListNode } from '../utils/find';
13
13
  import { createListNodeRange } from '../utils/selection';
14
- export var outdentListItemsSelected = function outdentListItemsSelected(tr, state, featureFlags) {
14
+ export var outdentListItemsSelected = function outdentListItemsSelected(tr, featureFlags) {
15
15
  var originalSelection = tr.selection;
16
16
  var normalizedSelection = normalizeListItemsSelection({
17
17
  selection: tr.selection,
@@ -46,7 +46,6 @@ export var outdentListItemsSelected = function outdentListItemsSelected(tr, stat
46
46
  extractListItemsRangeFromList({
47
47
  tr: tr,
48
48
  range: mappedRange,
49
- state: state,
50
49
  featureFlags: featureFlags
51
50
  });
52
51
  hasNormalizedToPositionLiftedOut = hasNormalizedToPositionLiftedOut || oldTo >= range.from && oldTo < range.to;
@@ -168,7 +167,6 @@ var outdentRangeToParentList = function outdentRangeToParentList(_ref2) {
168
167
  var extractListItemsRangeFromList = function extractListItemsRangeFromList(_ref3) {
169
168
  var tr = _ref3.tr,
170
169
  range = _ref3.range,
171
- state = _ref3.state,
172
170
  featureFlags = _ref3.featureFlags;
173
171
  var list = range.parent;
174
172
  var $start = tr.doc.resolve(range.start);
@@ -3,6 +3,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
5
  import { getCommonListAnalyticsAttributes, getListItemAttributes, hasValidListIndentationLevel } from '@atlaskit/editor-common/lists';
6
+ import { PassiveTransaction } from '@atlaskit/editor-common/preset';
6
7
  import { isBulletList } from '@atlaskit/editor-common/utils';
7
8
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
8
9
  import { indentListItemsSelected as indentListAction } from '../actions/indent-list-items-selected';
@@ -12,13 +13,13 @@ import { isInsideListItem, isInsideTableCell } from '../utils/selection';
12
13
  export var indentList = function indentList(editorAnalyticsAPI) {
13
14
  return function () {
14
15
  var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.KEYBOARD;
15
- return function (state, dispatch) {
16
- var tr = state.tr,
17
- $from = state.selection.$from;
16
+ return function (_ref) {
17
+ var tr = _ref.tr;
18
+ var $from = tr.selection.$from;
18
19
 
19
20
  // don't indent if selection is not inside a list
20
- if (!isInsideListItem(state)) {
21
- return false;
21
+ if (!isInsideListItem(tr)) {
22
+ return null;
22
23
  }
23
24
 
24
25
  // Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
@@ -26,12 +27,12 @@ export var indentList = function indentList(editorAnalyticsAPI) {
26
27
  var firstListItemSelectedAttributes = getListItemAttributes($from);
27
28
  var parentListNode = findFirstParentListNode($from);
28
29
  if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
29
- if (isInsideTableCell(state)) {
30
+ if (isInsideTableCell(tr)) {
30
31
  // dont consume tab, as table-keymap should move cursor to next cell
31
- return false;
32
+ return null;
32
33
  } else {
33
34
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
34
- return true;
35
+ return new PassiveTransaction();
35
36
  }
36
37
  }
37
38
  var currentListNode = parentListNode.node;
@@ -43,21 +44,18 @@ export var indentList = function indentList(editorAnalyticsAPI) {
43
44
  });
44
45
  if (maximimunNestedLevelReached || !tr.docChanged) {
45
46
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
46
- return true;
47
+ return new PassiveTransaction();
47
48
  }
48
49
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
49
50
  action: ACTION.INDENTED,
50
51
  actionSubject: ACTION_SUBJECT.LIST,
51
52
  actionSubjectId: actionSubjectId,
52
53
  eventType: EVENT_TYPE.TRACK,
53
- attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(state)), {}, {
54
+ attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(tr)), {}, {
54
55
  inputMethod: inputMethod
55
56
  })
56
57
  })(tr);
57
- if (dispatch) {
58
- dispatch(tr);
59
- }
60
- return true;
58
+ return tr;
61
59
  };
62
60
  };
63
61
  };
@@ -4,6 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
5
  import { findCutBefore } from '@atlaskit/editor-common/commands';
6
6
  import { getCommonListAnalyticsAttributes, moveTargetIntoList } from '@atlaskit/editor-common/lists';
7
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
7
8
  import { GapCursorSelection } from '@atlaskit/editor-common/selection';
8
9
  import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart } from '@atlaskit/editor-common/utils';
9
10
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
@@ -35,7 +36,7 @@ export var enterKeyCommand = function enterKeyCommand(editorAnalyticsAPI) {
35
36
  /** Check if the wrapper has any visible content */
36
37
  var wrapperHasContent = hasVisibleContent(wrapper);
37
38
  if (!wrapperHasContent) {
38
- return outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags)(state, dispatch);
39
+ return editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags))(state, dispatch);
39
40
  } else if (!hasParentNodeOfType(codeBlock)(selection)) {
40
41
  return splitListItem(listItem)(state, dispatch);
41
42
  }
@@ -53,10 +54,14 @@ export var backspaceKeyCommand = function backspaceKeyCommand(editorAnalyticsAPI
53
54
  // directly to an empty list item above, or outdent this node
54
55
  filter([isEmptySelectionAtStart,
55
56
  // list items might have multiple paragraphs; only do this at the first one
56
- isFirstChildOfParent, isInsideListItem], chainCommands(deletePreviousEmptyListItem, outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags))),
57
+ isFirstChildOfParent, function (state) {
58
+ return isInsideListItem(state.tr);
59
+ }], chainCommands(deletePreviousEmptyListItem, editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags)))),
57
60
  // if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
58
61
  // the text to the previous list item, if one exists
59
- filter([isEmptySelectionAtStart, canJoinToPreviousListItem], joinToPreviousListItem))(state, dispatch);
62
+ filter([isEmptySelectionAtStart, function (state) {
63
+ return canJoinToPreviousListItem(state.tr);
64
+ }], joinToPreviousListItem))(state, dispatch);
60
65
  };
61
66
  };
62
67
  };
@@ -93,13 +98,13 @@ function untoggleSelectedList(tr) {
93
98
  }
94
99
  export var toggleList = function toggleList(editorAnalyticsAPI) {
95
100
  return function (inputMethod, listType) {
96
- return function (state, dispatch) {
97
- var tr = state.tr;
101
+ return function (_ref) {
102
+ var tr = _ref.tr;
98
103
  var listInsideSelection = selectionContainsList(tr);
99
- var listNodeType = state.schema.nodes[listType];
104
+ var listNodeType = tr.doc.type.schema.nodes[listType];
100
105
  var actionSubjectId = listType === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
101
106
  if (listInsideSelection) {
102
- var selection = state.selection;
107
+ var selection = tr.selection;
103
108
 
104
109
  // for gap cursor or node selection - list is expected 1 level up (listItem -> list)
105
110
  // for text selection - list is expected 2 levels up (paragraph -> listItem -> list)
@@ -108,22 +113,19 @@ export var toggleList = function toggleList(editorAnalyticsAPI) {
108
113
  var toNode = selection.$to.node(selection.$to.depth - positionDiff);
109
114
  var transformedFrom = listInsideSelection.type.name === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
110
115
  if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
111
- var _tr2 = state.tr;
112
- untoggleSelectedList(_tr2);
116
+ var commonAttributes = getCommonListAnalyticsAttributes(tr);
117
+ untoggleSelectedList(tr);
113
118
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
114
119
  action: ACTION.CONVERTED,
115
120
  actionSubject: ACTION_SUBJECT.LIST,
116
121
  actionSubjectId: ACTION_SUBJECT_ID.TEXT,
117
122
  eventType: EVENT_TYPE.TRACK,
118
- attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(state)), {}, {
123
+ attributes: _objectSpread(_objectSpread({}, commonAttributes), {}, {
119
124
  transformedFrom: transformedFrom,
120
125
  inputMethod: inputMethod
121
126
  })
122
- })(_tr2);
123
- if (dispatch) {
124
- dispatch(_tr2);
125
- }
126
- return true;
127
+ })(tr);
128
+ return tr;
127
129
  }
128
130
  convertListType({
129
131
  tr: tr,
@@ -134,7 +136,7 @@ export var toggleList = function toggleList(editorAnalyticsAPI) {
134
136
  actionSubject: ACTION_SUBJECT.LIST,
135
137
  actionSubjectId: actionSubjectId,
136
138
  eventType: EVENT_TYPE.TRACK,
137
- attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(state)), {}, {
139
+ attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(tr)), {}, {
138
140
  transformedFrom: transformedFrom,
139
141
  inputMethod: inputMethod
140
142
  })
@@ -158,25 +160,22 @@ export var toggleList = function toggleList(editorAnalyticsAPI) {
158
160
  // If document wasn't changed, return false from the command to indicate that the
159
161
  // editing action failed
160
162
  if (!tr.docChanged) {
161
- return false;
163
+ return null;
162
164
  }
163
- if (dispatch) {
164
- dispatch(tr);
165
- }
166
- return true;
165
+ return tr;
167
166
  };
168
167
  };
169
168
  };
170
169
  export var toggleBulletList = function toggleBulletList(editorAnalyticsAPI) {
171
- return function (view) {
172
- var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
173
- return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList')(view.state, view.dispatch);
170
+ return function () {
171
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
172
+ return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList');
174
173
  };
175
174
  };
176
175
  export var toggleOrderedList = function toggleOrderedList(editorAnalyticsAPI) {
177
- return function (view) {
178
- var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
179
- return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList')(view.state, view.dispatch);
176
+ return function () {
177
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
178
+ return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList');
180
179
  };
181
180
  };
182
181
 
@@ -3,6 +3,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, OUTDENT_SCENARIOS } from '@atlaskit/editor-common/analytics';
5
5
  import { getCommonListAnalyticsAttributes } from '@atlaskit/editor-common/lists';
6
+ import { PassiveTransaction } from '@atlaskit/editor-common/preset';
6
7
  import { isBulletList } from '@atlaskit/editor-common/utils';
7
8
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
8
9
  import { outdentListItemsSelected as outdentListAction } from '../actions/outdent-list-items-selected';
@@ -13,26 +14,27 @@ export var outdentList = function outdentList(editorAnalyticsAPI) {
13
14
  return function () {
14
15
  var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.KEYBOARD;
15
16
  var featureFlags = arguments.length > 1 ? arguments[1] : undefined;
16
- return function (state, dispatch) {
17
- if (!isInsideListItem(state)) {
18
- return false;
17
+ return function (_ref) {
18
+ var tr = _ref.tr;
19
+ if (!isInsideListItem(tr)) {
20
+ return null;
19
21
  }
20
- var $from = state.selection.$from;
22
+ var $from = tr.selection.$from;
21
23
  var parentListNode = findFirstParentListNode($from);
22
24
  if (!parentListNode) {
23
25
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
24
- return true;
26
+ return new PassiveTransaction();
25
27
  }
26
28
 
27
29
  // Save the history, so it could undo/revert to the same state before the outdent, see https://product-fabric.atlassian.net/browse/ED-14753
28
- closeHistory(state.tr);
30
+ closeHistory(tr);
29
31
  var actionSubjectId = isBulletList(parentListNode.node) ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
30
- var customTr = state.tr;
31
- outdentListAction(customTr, state, featureFlags);
32
+ var customTr = tr;
33
+ outdentListAction(customTr, featureFlags);
32
34
  if (!customTr || !customTr.docChanged) {
33
35
  // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
34
36
  // If inside table cell and can't outdent list, then let it handle by table keymap
35
- return !isInsideTableCell(state);
37
+ return !isInsideTableCell(customTr) ? new PassiveTransaction() : null;
36
38
  }
37
39
  var restartListsAttributes = {};
38
40
  if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
@@ -49,14 +51,11 @@ export var outdentList = function outdentList(editorAnalyticsAPI) {
49
51
  actionSubject: ACTION_SUBJECT.LIST,
50
52
  actionSubjectId: actionSubjectId,
51
53
  eventType: EVENT_TYPE.TRACK,
52
- attributes: _objectSpread(_objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(state)), restartListsAttributes), {}, {
54
+ attributes: _objectSpread(_objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(customTr)), restartListsAttributes), {}, {
53
55
  inputMethod: inputMethod
54
56
  })
55
57
  })(customTr);
56
- if (dispatch) {
57
- dispatch(customTr);
58
- }
59
- return true;
58
+ return customTr;
60
59
  };
61
60
  };
62
61
  };
@@ -4,7 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { toggleBulletList, toggleOrderedList, tooltip } from '@atlaskit/editor-common/keymaps';
5
5
  import { listMessages as messages } from '@atlaskit/editor-common/messages';
6
6
  import { IconList, IconListNumber } from '@atlaskit/editor-common/quick-insert';
7
- import { indentList, outdentList, toggleBulletList as toggleBulletListCommand, toggleOrderedList as toggleOrderedListCommand } from './commands';
7
+ import { indentList, outdentList as _outdentList, toggleBulletList as toggleBulletListCommand, toggleOrderedList as toggleOrderedListCommand } from './commands';
8
8
  import inputRulePlugin from './pm-plugins/input-rules';
9
9
  import keymapPlugin from './pm-plugins/keymap';
10
10
  import { createPlugin, pluginKey as listPluginKey } from './pm-plugins/main';
@@ -22,13 +22,17 @@ export var listPlugin = function listPlugin(options, api) {
22
22
  return {
23
23
  name: 'list',
24
24
  actions: {
25
- indentList: indentList(editorAnalyticsAPI),
26
- outdentList: outdentList(editorAnalyticsAPI),
27
- toggleOrderedList: toggleOrderedListCommand(editorAnalyticsAPI),
28
- toggleBulletList: toggleBulletListCommand(editorAnalyticsAPI),
29
25
  isInsideListItem: isInsideListItem,
30
26
  findRootParentListNode: findRootParentListNode
31
27
  },
28
+ commands: {
29
+ indentList: indentList(editorAnalyticsAPI),
30
+ outdentList: function outdentList(inputMethod) {
31
+ return _outdentList(editorAnalyticsAPI)(inputMethod, featureFlags);
32
+ },
33
+ toggleOrderedList: toggleOrderedListCommand(editorAnalyticsAPI),
34
+ toggleBulletList: toggleBulletListCommand(editorAnalyticsAPI)
35
+ },
32
36
  getSharedState: function getSharedState(editorState) {
33
37
  if (!editorState) {
34
38
  return undefined;
@@ -1,13 +1,13 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { backspace, bindKeymapWithCommand, deleteKey, enter, findKeyMapForBrowser, findShortcutByKeymap, forwardDelete, indentList, outdentList, toggleBulletList, toggleOrderedList } from '@atlaskit/editor-common/keymaps';
2
+ import { backspace, bindKeymapWithCommand, bindKeymapWithEditorCommand, deleteKey, enter, findKeyMapForBrowser, findShortcutByKeymap, forwardDelete, indentList, outdentList, toggleBulletList, toggleOrderedList } from '@atlaskit/editor-common/keymaps';
3
3
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { backspaceKeyCommand, deleteKeyCommand, enterKeyCommand, indentList as indentListCommand, outdentList as outdentListCommand, toggleList } from '../commands';
5
5
  export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
6
6
  var list = {};
7
- bindKeymapWithCommand(findShortcutByKeymap(toggleOrderedList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'orderedList'), list);
8
- bindKeymapWithCommand(findShortcutByKeymap(toggleBulletList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'bulletList'), list);
9
- bindKeymapWithCommand(indentList.common, indentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
10
- bindKeymapWithCommand(outdentList.common, outdentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags), list);
7
+ bindKeymapWithEditorCommand(findShortcutByKeymap(toggleOrderedList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'orderedList'), list);
8
+ bindKeymapWithEditorCommand(findShortcutByKeymap(toggleBulletList), toggleList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, 'bulletList'), list);
9
+ bindKeymapWithEditorCommand(indentList.common, indentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
10
+ bindKeymapWithEditorCommand(outdentList.common, outdentListCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags), list);
11
11
  bindKeymapWithCommand(enter.common, enterKeyCommand(editorAnalyticsAPI)(featureFlags), list);
12
12
  bindKeymapWithCommand(backspace.common, backspaceKeyCommand(editorAnalyticsAPI)(featureFlags), list);
13
13
  bindKeymapWithCommand(deleteKey.common, deleteKeyCommand(editorAnalyticsAPI), list);
@@ -30,25 +30,25 @@ export var isWrappingPossible = function isWrappingPossible(nodeType, selection)
30
30
  };
31
31
 
32
32
  // canOutdent
33
- export var isInsideListItem = function isInsideListItem(state) {
34
- var parent = state.selection.$from.parent;
35
- var listItem = state.schema.nodes.listItem;
36
- if (state.selection instanceof GapCursorSelection) {
33
+ export var isInsideListItem = function isInsideListItem(tr) {
34
+ var parent = tr.selection.$from.parent;
35
+ var listItem = tr.doc.type.schema.nodes.listItem;
36
+ if (tr.selection instanceof GapCursorSelection) {
37
37
  return isListItemNode(parent);
38
38
  }
39
- return hasParentNodeOfType(listItem)(state.selection) && isParagraphNode(parent);
39
+ return hasParentNodeOfType(listItem)(tr.selection) && isParagraphNode(parent);
40
40
  };
41
- export var isInsideTableCell = function isInsideTableCell(state) {
42
- var _state$schema$nodes = state.schema.nodes,
43
- tableCell = _state$schema$nodes.tableCell,
44
- tableHeader = _state$schema$nodes.tableHeader;
45
- return !!findParentNodeOfType([tableCell, tableHeader])(state.selection);
41
+ export var isInsideTableCell = function isInsideTableCell(tr) {
42
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
43
+ tableCell = _tr$doc$type$schema$n.tableCell,
44
+ tableHeader = _tr$doc$type$schema$n.tableHeader;
45
+ return !!findParentNodeOfType([tableCell, tableHeader])(tr.selection);
46
46
  };
47
- export var canJoinToPreviousListItem = function canJoinToPreviousListItem(state) {
48
- var $from = state.selection.$from;
49
- var $before = state.doc.resolve($from.pos - 1);
47
+ export var canJoinToPreviousListItem = function canJoinToPreviousListItem(tr) {
48
+ var $from = tr.selection.$from;
49
+ var $before = tr.doc.resolve($from.pos - 1);
50
50
  var nodeBefore = $before ? $before.nodeBefore : null;
51
- if (state.selection instanceof GapCursorSelection) {
51
+ if (tr.selection instanceof GapCursorSelection) {
52
52
  nodeBefore = $from.nodeBefore;
53
53
  }
54
54
  return isListNode(nodeBefore);
@@ -1,3 +1,3 @@
1
1
  import type { FeatureFlags } from '@atlaskit/editor-common/types';
2
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
- export declare const outdentListItemsSelected: (tr: Transaction, state: EditorState, featureFlags: FeatureFlags) => void;
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const outdentListItemsSelected: (tr: Transaction, featureFlags: FeatureFlags) => void;
@@ -1,6 +1,6 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
4
4
  type InputMethod = INPUT_METHOD.KEYBOARD | INPUT_METHOD.TOOLBAR;
5
- export declare const indentList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod?: InputMethod) => Command;
5
+ export declare const indentList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod?: InputMethod) => EditorCommand;
6
6
  export {};
@@ -1,8 +1,7 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { Command, FeatureFlags } from '@atlaskit/editor-common/types';
3
+ import type { Command, EditorCommand, FeatureFlags } from '@atlaskit/editor-common/types';
4
4
  import type { NodeType, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
5
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
5
  import { indentList } from './indent-list';
7
6
  import { outdentList } from './outdent-list';
8
7
  export { outdentList, indentList };
@@ -11,6 +10,6 @@ export declare const enterKeyCommand: (editorAnalyticsAPI: EditorAnalyticsAPI |
11
10
  export declare const backspaceKeyCommand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (featureFlags: FeatureFlags) => Command;
12
11
  export declare const deleteKeyCommand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
13
12
  export declare const rootListDepth: (pos: ResolvedPos, nodes: Record<string, NodeType>) => number | undefined;
14
- export declare const toggleList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InputMethod, listType: 'bulletList' | 'orderedList') => Command;
15
- export declare const toggleBulletList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, inputMethod?: InputMethod) => boolean;
16
- export declare const toggleOrderedList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (view: EditorView, inputMethod?: InputMethod) => boolean;
13
+ export declare const toggleList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InputMethod, listType: 'bulletList' | 'orderedList') => EditorCommand;
14
+ export declare const toggleBulletList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod?: InputMethod) => EditorCommand;
15
+ export declare const toggleOrderedList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod?: InputMethod) => EditorCommand;
@@ -1,6 +1,6 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { Command, FeatureFlags } from '@atlaskit/editor-common/types';
3
+ import type { EditorCommand, FeatureFlags } from '@atlaskit/editor-common/types';
4
4
  type InputMethod = INPUT_METHOD.KEYBOARD | INPUT_METHOD.TOOLBAR;
5
- export declare const outdentList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InputMethod | undefined, featureFlags: FeatureFlags) => Command;
5
+ export declare const outdentList: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InputMethod | undefined, featureFlags: FeatureFlags) => EditorCommand;
6
6
  export {};
@@ -1,18 +1,18 @@
1
1
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { Command, FeatureFlags, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
- import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
- import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
2
+ import type { EditorCommand, FeatureFlags, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
5
5
  import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
6
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
7
- import type { DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
7
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  export type InputMethod = INPUT_METHOD.KEYBOARD | INPUT_METHOD.TOOLBAR;
9
9
  export declare const MAX_NESTED_LIST_INDENTATION = 6;
10
10
  export type ListPluginOptions = Pick<FeatureFlags, 'restartNumberedLists'>;
11
- export type IndentList = (inputMethod: InputMethod) => Command;
12
- export type OutdentList = (inputMethod: InputMethod, featureFlags: FeatureFlags) => Command;
13
- export type ToggleOrderedList = (view: EditorView, inputMethod: InputMethod) => boolean;
14
- export type ToggleBulletList = (view: EditorView, inputMethod: InputMethod) => boolean;
15
- export type IsInsideListItem = (state: EditorState) => boolean;
11
+ export type IndentList = (inputMethod: InputMethod) => EditorCommand;
12
+ export type OutdentList = (inputMethod: InputMethod) => EditorCommand;
13
+ export type ToggleOrderedList = (inputMethod: InputMethod) => EditorCommand;
14
+ export type ToggleBulletList = (inputMethod: InputMethod) => EditorCommand;
15
+ export type IsInsideListItem = (tr: Transaction) => boolean;
16
16
  export type FindRootParentListNode = ($pos: ResolvedPos) => ResolvedPos | null;
17
17
  export interface ListState {
18
18
  bulletListActive: boolean;
@@ -23,17 +23,16 @@ export interface ListState {
23
23
  }
24
24
  export type ListPlugin = NextEditorPlugin<'list', {
25
25
  pluginConfiguration: ListPluginOptions | undefined;
26
- dependencies: [
27
- typeof featureFlagsPlugin,
28
- OptionalPlugin<typeof analyticsPlugin>
29
- ];
26
+ dependencies: [FeatureFlagsPlugin, OptionalPlugin<AnalyticsPlugin>];
30
27
  actions: {
28
+ isInsideListItem: IsInsideListItem;
29
+ findRootParentListNode: FindRootParentListNode;
30
+ };
31
+ commands: {
31
32
  indentList: IndentList;
32
33
  outdentList: OutdentList;
33
34
  toggleOrderedList: ToggleOrderedList;
34
35
  toggleBulletList: ToggleBulletList;
35
- isInsideListItem: IsInsideListItem;
36
- findRootParentListNode: FindRootParentListNode;
37
36
  };
38
37
  sharedState: ListState | undefined;
39
38
  }>;