@atlaskit/editor-plugin-list 0.2.0 → 1.0.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.
Files changed (181) hide show
  1. package/.eslintrc.js +14 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +1 -1
  4. package/dist/cjs/actions/conversions.js +153 -0
  5. package/dist/cjs/actions/indent-list-items-selected.js +125 -0
  6. package/dist/cjs/actions/indent-list.js +49 -0
  7. package/dist/cjs/actions/join-list-items-forward.js +59 -0
  8. package/dist/cjs/actions/join-list-items-scenarios/index.js +40 -0
  9. package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +88 -0
  10. package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +85 -0
  11. package/dist/cjs/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +79 -0
  12. package/dist/cjs/actions/join-list-items-scenarios/join-paragraph-with-list.js +45 -0
  13. package/dist/cjs/actions/join-list-items-scenarios/join-sibling-list-items.js +56 -0
  14. package/dist/cjs/actions/merge-lists.js +27 -0
  15. package/dist/cjs/actions/outdent-list-items-selected.js +291 -0
  16. package/dist/cjs/actions/wrap-and-join-lists.js +100 -0
  17. package/dist/cjs/commands/indent-list.js +71 -0
  18. package/dist/cjs/commands/index.js +350 -0
  19. package/dist/cjs/commands/isFirstChildOfParent.js +12 -0
  20. package/dist/cjs/commands/join-list-item-forward.js +61 -0
  21. package/dist/cjs/commands/listBackspace.js +284 -0
  22. package/dist/cjs/commands/outdent-list.js +70 -0
  23. package/dist/cjs/index.js +8 -1
  24. package/dist/cjs/messages.js +37 -0
  25. package/dist/cjs/plugin.js +133 -0
  26. package/dist/cjs/pm-plugins/input-rules/create-list-input-rule.js +63 -0
  27. package/dist/cjs/pm-plugins/input-rules/index.js +38 -0
  28. package/dist/cjs/pm-plugins/input-rules/wrapping-join-rule.js +60 -0
  29. package/dist/cjs/pm-plugins/keymap.js +27 -0
  30. package/dist/cjs/pm-plugins/main.js +166 -0
  31. package/dist/cjs/transforms.js +99 -0
  32. package/dist/cjs/types.js +4 -1
  33. package/dist/cjs/utils/analytics.js +22 -0
  34. package/dist/cjs/utils/find.js +68 -0
  35. package/dist/cjs/utils/indentation.js +22 -0
  36. package/dist/cjs/utils/mark.js +40 -0
  37. package/dist/cjs/utils/node.js +16 -0
  38. package/dist/cjs/utils/selection.js +95 -0
  39. package/dist/es2019/actions/conversions.js +160 -0
  40. package/dist/es2019/actions/indent-list-items-selected.js +124 -0
  41. package/dist/es2019/actions/indent-list.js +44 -0
  42. package/dist/es2019/actions/join-list-items-forward.js +54 -0
  43. package/dist/es2019/actions/join-list-items-scenarios/index.js +5 -0
  44. package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +74 -0
  45. package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +77 -0
  46. package/dist/es2019/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +71 -0
  47. package/dist/es2019/actions/join-list-items-scenarios/join-paragraph-with-list.js +37 -0
  48. package/dist/es2019/actions/join-list-items-scenarios/join-sibling-list-items.js +48 -0
  49. package/dist/es2019/actions/merge-lists.js +24 -0
  50. package/dist/es2019/actions/outdent-list-items-selected.js +295 -0
  51. package/dist/es2019/actions/wrap-and-join-lists.js +93 -0
  52. package/dist/es2019/commands/indent-list.js +62 -0
  53. package/dist/es2019/commands/index.js +326 -0
  54. package/dist/es2019/commands/isFirstChildOfParent.js +7 -0
  55. package/dist/es2019/commands/join-list-item-forward.js +53 -0
  56. package/dist/es2019/commands/listBackspace.js +276 -0
  57. package/dist/es2019/commands/outdent-list.js +60 -0
  58. package/dist/es2019/index.js +1 -1
  59. package/dist/es2019/messages.js +29 -0
  60. package/dist/es2019/plugin.js +121 -0
  61. package/dist/es2019/pm-plugins/input-rules/create-list-input-rule.js +56 -0
  62. package/dist/es2019/pm-plugins/input-rules/index.js +35 -0
  63. package/dist/es2019/pm-plugins/input-rules/wrapping-join-rule.js +55 -0
  64. package/dist/es2019/pm-plugins/keymap.js +19 -0
  65. package/dist/es2019/pm-plugins/main.js +156 -0
  66. package/dist/es2019/transforms.js +101 -0
  67. package/dist/es2019/types.js +1 -1
  68. package/dist/es2019/utils/analytics.js +12 -0
  69. package/dist/es2019/utils/find.js +61 -0
  70. package/dist/es2019/utils/indentation.js +15 -0
  71. package/dist/es2019/utils/mark.js +30 -0
  72. package/dist/es2019/utils/node.js +12 -0
  73. package/dist/es2019/utils/selection.js +96 -0
  74. package/dist/esm/actions/conversions.js +147 -0
  75. package/dist/esm/actions/indent-list-items-selected.js +117 -0
  76. package/dist/esm/actions/indent-list.js +43 -0
  77. package/dist/esm/actions/join-list-items-forward.js +52 -0
  78. package/dist/esm/actions/join-list-items-scenarios/index.js +5 -0
  79. package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +81 -0
  80. package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +78 -0
  81. package/dist/esm/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +72 -0
  82. package/dist/esm/actions/join-list-items-scenarios/join-paragraph-with-list.js +38 -0
  83. package/dist/esm/actions/join-list-items-scenarios/join-sibling-list-items.js +49 -0
  84. package/dist/esm/actions/merge-lists.js +21 -0
  85. package/dist/esm/actions/outdent-list-items-selected.js +283 -0
  86. package/dist/esm/actions/wrap-and-join-lists.js +94 -0
  87. package/dist/esm/commands/indent-list.js +63 -0
  88. package/dist/esm/commands/index.js +324 -0
  89. package/dist/esm/commands/isFirstChildOfParent.js +5 -0
  90. package/dist/esm/commands/join-list-item-forward.js +53 -0
  91. package/dist/esm/commands/listBackspace.js +275 -0
  92. package/dist/esm/commands/outdent-list.js +62 -0
  93. package/dist/esm/index.js +1 -1
  94. package/dist/esm/messages.js +29 -0
  95. package/dist/esm/plugin.js +126 -0
  96. package/dist/esm/pm-plugins/input-rules/create-list-input-rule.js +57 -0
  97. package/dist/esm/pm-plugins/input-rules/index.js +32 -0
  98. package/dist/esm/pm-plugins/input-rules/wrapping-join-rule.js +54 -0
  99. package/dist/esm/pm-plugins/keymap.js +19 -0
  100. package/dist/esm/pm-plugins/main.js +156 -0
  101. package/dist/esm/transforms.js +91 -0
  102. package/dist/esm/types.js +1 -1
  103. package/dist/esm/utils/analytics.js +12 -0
  104. package/dist/esm/utils/find.js +59 -0
  105. package/dist/esm/utils/indentation.js +15 -0
  106. package/dist/esm/utils/mark.js +33 -0
  107. package/dist/esm/utils/node.js +10 -0
  108. package/dist/esm/utils/selection.js +81 -0
  109. package/dist/types/actions/conversions.d.ts +6 -0
  110. package/dist/types/actions/indent-list-items-selected.d.ts +2 -0
  111. package/dist/types/actions/indent-list.d.ts +2 -0
  112. package/dist/types/actions/join-list-items-forward.d.ts +13 -0
  113. package/dist/types/actions/join-list-items-scenarios/index.d.ts +5 -0
  114. package/dist/types/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
  115. package/dist/types/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
  116. package/dist/types/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
  117. package/dist/types/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
  118. package/dist/types/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
  119. package/dist/types/actions/merge-lists.d.ts +7 -0
  120. package/dist/types/actions/outdent-list-items-selected.d.ts +3 -0
  121. package/dist/types/actions/wrap-and-join-lists.d.ts +17 -0
  122. package/dist/types/commands/indent-list.d.ts +6 -0
  123. package/dist/types/commands/index.d.ts +16 -0
  124. package/dist/types/commands/isFirstChildOfParent.d.ts +2 -0
  125. package/dist/types/commands/join-list-item-forward.d.ts +3 -0
  126. package/dist/types/commands/listBackspace.d.ts +10 -0
  127. package/dist/types/commands/outdent-list.d.ts +6 -0
  128. package/dist/types/index.d.ts +2 -1
  129. package/dist/types/messages.d.ts +27 -0
  130. package/dist/types/plugin.d.ts +2 -0
  131. package/dist/types/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
  132. package/dist/types/pm-plugins/input-rules/index.d.ts +5 -0
  133. package/dist/types/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
  134. package/dist/types/pm-plugins/keymap.d.ts +5 -0
  135. package/dist/types/pm-plugins/main.d.ts +11 -0
  136. package/dist/types/transforms.d.ts +4 -0
  137. package/dist/types/types.d.ts +4 -6
  138. package/dist/types/utils/analytics.d.ts +5 -0
  139. package/dist/types/utils/find.d.ts +10 -0
  140. package/dist/types/utils/indentation.d.ts +2 -0
  141. package/dist/types/utils/mark.d.ts +8 -0
  142. package/dist/types/utils/node.d.ts +2 -0
  143. package/dist/types/utils/selection.d.ts +14 -0
  144. package/dist/types-ts4.5/actions/conversions.d.ts +6 -0
  145. package/dist/types-ts4.5/actions/indent-list-items-selected.d.ts +2 -0
  146. package/dist/types-ts4.5/actions/indent-list.d.ts +2 -0
  147. package/dist/types-ts4.5/actions/join-list-items-forward.d.ts +16 -0
  148. package/dist/types-ts4.5/actions/join-list-items-scenarios/index.d.ts +5 -0
  149. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
  150. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
  151. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
  152. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
  153. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
  154. package/dist/types-ts4.5/actions/merge-lists.d.ts +7 -0
  155. package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +3 -0
  156. package/dist/types-ts4.5/actions/wrap-and-join-lists.d.ts +17 -0
  157. package/dist/types-ts4.5/commands/indent-list.d.ts +6 -0
  158. package/dist/types-ts4.5/commands/index.d.ts +16 -0
  159. package/dist/types-ts4.5/commands/isFirstChildOfParent.d.ts +2 -0
  160. package/dist/types-ts4.5/commands/join-list-item-forward.d.ts +3 -0
  161. package/dist/types-ts4.5/commands/listBackspace.d.ts +13 -0
  162. package/dist/types-ts4.5/commands/outdent-list.d.ts +6 -0
  163. package/dist/types-ts4.5/index.d.ts +2 -1
  164. package/dist/types-ts4.5/messages.d.ts +27 -0
  165. package/dist/types-ts4.5/plugin.d.ts +2 -0
  166. package/dist/types-ts4.5/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
  167. package/dist/types-ts4.5/pm-plugins/input-rules/index.d.ts +5 -0
  168. package/dist/types-ts4.5/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
  169. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +5 -0
  170. package/dist/types-ts4.5/pm-plugins/main.d.ts +11 -0
  171. package/dist/types-ts4.5/transforms.d.ts +4 -0
  172. package/dist/types-ts4.5/types.d.ts +4 -6
  173. package/dist/types-ts4.5/utils/analytics.d.ts +5 -0
  174. package/dist/types-ts4.5/utils/find.d.ts +10 -0
  175. package/dist/types-ts4.5/utils/indentation.d.ts +2 -0
  176. package/dist/types-ts4.5/utils/mark.d.ts +8 -0
  177. package/dist/types-ts4.5/utils/node.d.ts +2 -0
  178. package/dist/types-ts4.5/utils/selection.d.ts +14 -0
  179. package/package.json +8 -5
  180. package/report.api.md +6 -2
  181. package/tmp/api-report-tmp.d.ts +4 -1
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createWrappingJoinRule = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
9
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
10
+ var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+
13
+ var createWrappingJoinRule = function createWrappingJoinRule(_ref) {
14
+ var match = _ref.match,
15
+ nodeType = _ref.nodeType,
16
+ getAttrs = _ref.getAttrs,
17
+ joinPredicate = _ref.joinPredicate,
18
+ featureFlags = _ref.featureFlags;
19
+ var handler = function handler(state, match, start, end) {
20
+ var attrs = (getAttrs instanceof Function ? getAttrs(match) : getAttrs) || {};
21
+ var tr = state.tr;
22
+ var fixedStart = Math.max(start, 1);
23
+ tr.delete(fixedStart, end);
24
+ var $start = tr.doc.resolve(fixedStart);
25
+ var range = $start.blockRange();
26
+ var wrapping = range && (0, _transform.findWrapping)(range, nodeType, attrs);
27
+ if (!wrapping || !range) {
28
+ return null;
29
+ }
30
+ var parentNodePosMapped = tr.mapping.map(range.start);
31
+ var parentNode = tr.doc.nodeAt(parentNodePosMapped);
32
+ var lastWrap = wrapping[wrapping.length - 1];
33
+ if (parentNode && lastWrap) {
34
+ var allowedMarks = lastWrap.type.allowedMarks(parentNode.marks) || [];
35
+ tr.setNodeMarkup(parentNodePosMapped, parentNode.type, parentNode.attrs, allowedMarks);
36
+ }
37
+ tr.wrap(range, wrapping);
38
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists && nodeType === state.schema.nodes.orderedList) {
39
+ // if an orderedList node would be inserted by the input rule match, and
40
+ // that orderedList node is being added directly before another orderedList
41
+ // node, then join those nodes
42
+ var $end = tr.doc.resolve(tr.mapping.map(end));
43
+ var _node = (0, _utils.findParentNodeOfTypeClosestToPos)($end, nodeType);
44
+ if (_node) {
45
+ var nodeEnd = _node.pos + _node.node.nodeSize;
46
+ var after = tr.doc.resolve(nodeEnd).nodeAfter;
47
+ 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))) {
48
+ tr.join(nodeEnd);
49
+ }
50
+ }
51
+ }
52
+ var before = tr.doc.resolve(fixedStart - 1).nodeBefore;
53
+ 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))) {
54
+ tr.join(fixedStart - 1);
55
+ }
56
+ return tr;
57
+ };
58
+ return (0, _prosemirrorInputRules.createRule)(match, handler);
59
+ };
60
+ exports.createWrappingJoinRule = createWrappingJoinRule;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.keymapPlugin = keymapPlugin;
8
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
10
+ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
11
+ var _commands = require("../commands");
12
+ function keymapPlugin(featureFlags, editorAnalyticsAPI) {
13
+ var list = {};
14
+ (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.toggleOrderedList), (0, _commands.toggleList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, 'orderedList'), list);
15
+ (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.toggleBulletList), (0, _commands.toggleList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, 'bulletList'), list);
16
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.indentList.common, (0, _commands.indentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), list);
17
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.outdentList.common, (0, _commands.outdentList)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD, featureFlags), list);
18
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.enter.common, (0, _commands.enterKeyCommand)(editorAnalyticsAPI)(featureFlags), list);
19
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _commands.backspaceKeyCommand)(editorAnalyticsAPI)(featureFlags), list);
20
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, (0, _commands.deleteKeyCommand)(editorAnalyticsAPI), list);
21
+
22
+ // This shortcut is Mac only
23
+ (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.forwardDelete), (0, _commands.deleteKeyCommand)(editorAnalyticsAPI), list);
24
+ return (0, _keymap.keymap)(list);
25
+ }
26
+ var _default = keymapPlugin;
27
+ exports.default = _default;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.pluginKey = exports.getDecorations = exports.createPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
+ var _selection = require("@atlaskit/editor-common/selection");
11
+ var _styles = require("@atlaskit/editor-common/styles");
12
+ var _utils = require("@atlaskit/editor-common/utils");
13
+ var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
+ var _view = require("@atlaskit/editor-prosemirror/view");
16
+ var _selection2 = require("../utils/selection");
17
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
+ 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) { (0, _defineProperty2.default)(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; }
19
+ var listPluginKey = new _state.PluginKey('listPlugin');
20
+ var pluginKey = listPluginKey;
21
+ exports.pluginKey = pluginKey;
22
+ var initialState = {
23
+ bulletListActive: false,
24
+ bulletListDisabled: false,
25
+ orderedListActive: false,
26
+ orderedListDisabled: false,
27
+ decorationSet: _view.DecorationSet.empty
28
+ };
29
+ var getDecorations = function getDecorations(doc, state, featureFlags) {
30
+ var decorations = [];
31
+
32
+ // this stack keeps track of each (nested) list to calculate the indentation level
33
+ var processedListsStack = [];
34
+ doc.nodesBetween(0, doc.content.size, function (node, currentNodeStartPos) {
35
+ if (processedListsStack.length > 0) {
36
+ var isOutsideLastList = true;
37
+ while (isOutsideLastList && processedListsStack.length > 0) {
38
+ var lastList = processedListsStack[processedListsStack.length - 1];
39
+ var lastListEndPos = lastList.startPos + lastList.node.nodeSize;
40
+ isOutsideLastList = currentNodeStartPos >= lastListEndPos;
41
+ // once we finish iterating over each innermost list, pop the stack to
42
+ // decrease the indent level attribute accordingly
43
+ if (isOutsideLastList) {
44
+ processedListsStack.pop();
45
+ }
46
+ }
47
+ }
48
+ if ((0, _utils.isListNode)(node)) {
49
+ processedListsStack.push({
50
+ node: node,
51
+ startPos: currentNodeStartPos
52
+ });
53
+ var from = currentNodeStartPos;
54
+ var to = currentNodeStartPos + node.nodeSize;
55
+ var depth = processedListsStack.length;
56
+ decorations.push(_view.Decoration.node(from, to, {
57
+ 'data-indent-level': "".concat(depth)
58
+ }));
59
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
60
+ var _node$attrs;
61
+ // If a numbered list has item counters numbering >= 100, we'll need to add special
62
+ // spacing to account for the extra digit chars
63
+ var digitsSize = (0, _utils.getItemCounterDigitsSize)({
64
+ itemsCount: node === null || node === void 0 ? void 0 : node.childCount,
65
+ order: node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.order
66
+ });
67
+ if (digitsSize) {
68
+ decorations.push(_view.Decoration.node(from, to, {
69
+ style: (0, _styles.getOrderedListInlineStyles)(digitsSize, 'string')
70
+ }));
71
+ }
72
+ } else {
73
+ if (node.childCount >= 100) {
74
+ decorations.push(_view.Decoration.node(from, to, {
75
+ 'data-child-count': '100+'
76
+ }));
77
+ }
78
+ }
79
+ }
80
+ });
81
+ return _view.DecorationSet.empty.add(doc, decorations);
82
+ };
83
+ exports.getDecorations = getDecorations;
84
+ var handleDocChanged = function handleDocChanged(featureFlags) {
85
+ return function (tr, pluginState, editorState) {
86
+ var nextPluginState = handleSelectionChanged(tr, pluginState);
87
+ var decorationSet = getDecorations(tr.doc, editorState, featureFlags);
88
+ return _objectSpread(_objectSpread({}, nextPluginState), {}, {
89
+ decorationSet: decorationSet
90
+ });
91
+ };
92
+ };
93
+ var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
94
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
95
+ bulletList = _tr$doc$type$schema$n.bulletList,
96
+ orderedList = _tr$doc$type$schema$n.orderedList;
97
+ var listParent = (0, _utils2.findParentNodeOfType)([bulletList, orderedList])(tr.selection);
98
+ var bulletListActive = !!listParent && listParent.node.type === bulletList;
99
+ var orderedListActive = !!listParent && listParent.node.type === orderedList;
100
+ var bulletListDisabled = !(bulletListActive || orderedListActive || (0, _selection2.isWrappingPossible)(bulletList, tr.selection));
101
+ var orderedListDisabled = !(bulletListActive || orderedListActive || (0, _selection2.isWrappingPossible)(orderedList, tr.selection));
102
+ if (bulletListActive !== pluginState.bulletListActive || orderedListActive !== pluginState.orderedListActive || bulletListDisabled !== pluginState.bulletListDisabled || orderedListDisabled !== pluginState.orderedListDisabled) {
103
+ var nextPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
104
+ bulletListActive: bulletListActive,
105
+ orderedListActive: orderedListActive,
106
+ bulletListDisabled: bulletListDisabled,
107
+ orderedListDisabled: orderedListDisabled
108
+ });
109
+ return nextPluginState;
110
+ }
111
+ return pluginState;
112
+ };
113
+ var reducer = function reducer() {
114
+ return function (state) {
115
+ return state;
116
+ };
117
+ };
118
+ var createInitialState = function createInitialState(featureFlags) {
119
+ return function (state) {
120
+ return _objectSpread(_objectSpread({}, initialState), {}, {
121
+ decorationSet: getDecorations(state.doc, state, featureFlags)
122
+ });
123
+ };
124
+ };
125
+ var createPlugin = function createPlugin(eventDispatch, featureFlags) {
126
+ var _pluginFactory = (0, _utils.pluginFactory)(listPluginKey, reducer(), {
127
+ onDocChanged: handleDocChanged(featureFlags),
128
+ onSelectionChanged: handleSelectionChanged
129
+ }),
130
+ getPluginState = _pluginFactory.getPluginState,
131
+ createPluginState = _pluginFactory.createPluginState;
132
+ return new _safePlugin.SafePlugin({
133
+ state: createPluginState(eventDispatch, createInitialState(featureFlags)),
134
+ key: listPluginKey,
135
+ props: {
136
+ decorations: function decorations(state) {
137
+ var _getPluginState = getPluginState(state),
138
+ decorationSet = _getPluginState.decorationSet;
139
+ return decorationSet;
140
+ },
141
+ handleClick: function handleClick(view, pos, event) {
142
+ var state = view.state;
143
+ if (['LI', 'UL'].includes((event === null || event === void 0 ? void 0 : event.target).tagName)) {
144
+ var _nodeAtPos$firstChild;
145
+ var nodeAtPos = state.tr.doc.nodeAt(pos);
146
+ var _view$state$schema$no = view.state.schema.nodes,
147
+ listItem = _view$state$schema$no.listItem,
148
+ codeBlock = _view$state$schema$no.codeBlock;
149
+ if ((nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type) === listItem && (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : (_nodeAtPos$firstChild = nodeAtPos.firstChild) === null || _nodeAtPos$firstChild === void 0 ? void 0 : _nodeAtPos$firstChild.type) === codeBlock) {
150
+ var _document, _document$elementFrom;
151
+ var bufferPx = 50;
152
+ var isCodeBlockNextToListMarker = Boolean((_document = document) === null || _document === void 0 ? void 0 : (_document$elementFrom = _document.elementFromPoint(event.clientX + (_styles.listItemCounterPadding + bufferPx), event.clientY)) === null || _document$elementFrom === void 0 ? void 0 : _document$elementFrom.closest(".".concat(_styles.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER)));
153
+ if (isCodeBlockNextToListMarker) {
154
+ // +1 needed to put cursor inside li
155
+ // otherwise gap cursor markup will be injected as immediate child of ul resulting in invalid html
156
+ (0, _selection.setGapCursorSelection)(view, pos + 1, _selection.Side.LEFT);
157
+ return true;
158
+ }
159
+ }
160
+ }
161
+ return false;
162
+ }
163
+ }
164
+ });
165
+ };
166
+ exports.createPlugin = createPlugin;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.liftFollowingList = liftFollowingList;
7
+ exports.liftNodeSelectionList = liftNodeSelectionList;
8
+ exports.liftTextSelectionList = liftTextSelectionList;
9
+ var _model = require("@atlaskit/editor-prosemirror/model");
10
+ var _state = require("@atlaskit/editor-prosemirror/state");
11
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
12
+ var _indentation = require("./utils/indentation");
13
+ function liftListItem(selection, tr) {
14
+ var $from = selection.$from,
15
+ $to = selection.$to;
16
+ var nodeType = tr.doc.type.schema.nodes.listItem;
17
+ var range = $from.blockRange($to, function (node) {
18
+ return !!node.childCount && !!node.firstChild && node.firstChild.type === nodeType;
19
+ });
20
+ if (!range || range.depth < 2 || $from.node(range.depth - 1).type !== nodeType) {
21
+ return tr;
22
+ }
23
+ var end = range.end;
24
+ var endOfList = $to.end(range.depth);
25
+ if (end < endOfList) {
26
+ tr.step(new _transform.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new _model.Slice(_model.Fragment.from(nodeType.create(undefined, range.parent.copy())), 1, 0), 1, true));
27
+ range = new _model.NodeRange(tr.doc.resolve($from.pos), tr.doc.resolve(endOfList), range.depth);
28
+ }
29
+ return tr.lift(range, (0, _transform.liftTarget)(range)).scrollIntoView();
30
+ }
31
+
32
+ // Function will lift list item following selection to level-1.
33
+ function liftFollowingList(from, to, rootListDepth, tr) {
34
+ var listItem = tr.doc.type.schema.nodes.listItem;
35
+ var lifted = false;
36
+ tr.doc.nodesBetween(from, to, function (node, pos) {
37
+ if (!lifted && node.type === listItem && pos > from) {
38
+ lifted = true;
39
+ var listDepth = rootListDepth + 3;
40
+ while (listDepth > rootListDepth + 2) {
41
+ var start = tr.doc.resolve(tr.mapping.map(pos));
42
+ listDepth = start.depth;
43
+ var end = tr.doc.resolve(tr.mapping.map(pos + node.textContent.length));
44
+ var sel = new _state.TextSelection(start, end);
45
+ tr = liftListItem(sel, tr);
46
+ }
47
+ }
48
+ });
49
+ return tr;
50
+ }
51
+ function liftNodeSelectionList(selection, tr) {
52
+ var from = selection.from;
53
+ var listItem = tr.doc.type.schema.nodes.listItem;
54
+ var mappedPosition = tr.mapping.map(from);
55
+ var nodeAtPos = tr.doc.nodeAt(mappedPosition);
56
+ var start = tr.doc.resolve(mappedPosition);
57
+ if ((start === null || start === void 0 ? void 0 : start.parent.type) !== listItem) {
58
+ return tr;
59
+ }
60
+ var end = tr.doc.resolve(mappedPosition + ((nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.nodeSize) || 1));
61
+ var range = start.blockRange(end);
62
+ if (range) {
63
+ var _liftTarget = (0, _indentation.getListLiftTarget)(start);
64
+ tr.lift(range, _liftTarget);
65
+ }
66
+ return tr;
67
+ }
68
+ // The function will list paragraphs in selection out to level 1 below root list.
69
+ function liftTextSelectionList(selection, tr) {
70
+ var from = selection.from,
71
+ to = selection.to;
72
+ var paragraph = tr.doc.type.schema.nodes.paragraph;
73
+ var listCol = [];
74
+ tr.doc.nodesBetween(from, to, function (node, pos) {
75
+ if (node.type === paragraph) {
76
+ listCol.push({
77
+ node: node,
78
+ pos: pos
79
+ });
80
+ }
81
+ });
82
+ for (var i = listCol.length - 1; i >= 0; i--) {
83
+ var _paragraph = listCol[i];
84
+ var start = tr.doc.resolve(tr.mapping.map(_paragraph.pos));
85
+ if (start.depth > 0) {
86
+ var end = void 0;
87
+ if (_paragraph.node.textContent && _paragraph.node.textContent.length > 0) {
88
+ end = tr.doc.resolve(tr.mapping.map(_paragraph.pos + _paragraph.node.textContent.length));
89
+ } else {
90
+ end = tr.doc.resolve(tr.mapping.map(_paragraph.pos + 1));
91
+ }
92
+ var range = start.blockRange(end);
93
+ if (range) {
94
+ tr.lift(range, (0, _indentation.getListLiftTarget)(start));
95
+ }
96
+ }
97
+ }
98
+ return tr;
99
+ }
package/dist/cjs/types.js CHANGED
@@ -2,4 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.MAX_NESTED_LIST_INDENTATION = void 0;
7
+ var MAX_NESTED_LIST_INDENTATION = 6;
8
+ exports.MAX_NESTED_LIST_INDENTATION = MAX_NESTED_LIST_INDENTATION;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.storeRestartListsAttributes = exports.getRestartListsAttributes = exports.RESTART_LISTS_ANALYTICS_KEY = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
+ 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) { (0, _defineProperty2.default)(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; }
11
+ var RESTART_LISTS_ANALYTICS_KEY = 'restartListsAnalytics';
12
+ exports.RESTART_LISTS_ANALYTICS_KEY = RESTART_LISTS_ANALYTICS_KEY;
13
+ var getRestartListsAttributes = function getRestartListsAttributes(tr) {
14
+ var _tr$getMeta;
15
+ return (_tr$getMeta = tr.getMeta(RESTART_LISTS_ANALYTICS_KEY)) !== null && _tr$getMeta !== void 0 ? _tr$getMeta : {};
16
+ };
17
+ exports.getRestartListsAttributes = getRestartListsAttributes;
18
+ var storeRestartListsAttributes = function storeRestartListsAttributes(tr, attributes) {
19
+ var meta = getRestartListsAttributes(tr);
20
+ tr.setMeta(RESTART_LISTS_ANALYTICS_KEY, _objectSpread(_objectSpread({}, meta), attributes));
21
+ };
22
+ exports.storeRestartListsAttributes = storeRestartListsAttributes;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findFirstParentListItemNode = findFirstParentListItemNode;
7
+ exports.findFirstParentListNode = findFirstParentListNode;
8
+ exports.findRootParentListNode = void 0;
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
11
+ function findFirstParentListNode($pos) {
12
+ var currentNode = $pos.doc.nodeAt($pos.pos);
13
+ var listNodePosition = null;
14
+ if ((0, _utils.isListNode)(currentNode)) {
15
+ listNodePosition = $pos.pos;
16
+ } else {
17
+ var result = (0, _utils2.findParentNodeClosestToPos)($pos, _utils.isListNode);
18
+ listNodePosition = result && result.pos;
19
+ }
20
+ if (listNodePosition == null) {
21
+ return null;
22
+ }
23
+ var node = $pos.doc.nodeAt(listNodePosition);
24
+ if (!node) {
25
+ return null;
26
+ }
27
+ return {
28
+ node: node,
29
+ pos: listNodePosition
30
+ };
31
+ }
32
+ function findFirstParentListItemNode($pos) {
33
+ var currentNode = $pos.doc.nodeAt($pos.pos);
34
+ var listItemNodePosition = (0, _utils.isListItemNode)(currentNode) ? $pos : (0, _utils2.findParentNodeClosestToPos)($pos, _utils.isListItemNode);
35
+ if (!listItemNodePosition || listItemNodePosition.pos === null) {
36
+ return null;
37
+ }
38
+ var node = $pos.doc.nodeAt(listItemNodePosition.pos);
39
+ if (!node) {
40
+ return null;
41
+ }
42
+ return {
43
+ node: node,
44
+ pos: listItemNodePosition.pos
45
+ };
46
+ }
47
+ var findRootParentListNode = function findRootParentListNode($pos) {
48
+ var doc = $pos.doc;
49
+ if ($pos.pos + 1 > doc.content.size) {
50
+ return null;
51
+ }
52
+ if ($pos.depth === 0) {
53
+ return doc.resolve($pos.pos + 1);
54
+ }
55
+ var currentNode = doc.nodeAt($pos.pos);
56
+ var beforePosition = $pos.before();
57
+ var nodeBefore = doc.nodeAt(beforePosition);
58
+ if ((0, _utils.isListNode)(currentNode) && !(0, _utils.isListItemNode)(nodeBefore)) {
59
+ return doc.resolve($pos.pos + 1);
60
+ }
61
+ var parentList = (0, _utils2.findParentNodeClosestToPos)($pos, _utils.isListNode);
62
+ if (!parentList) {
63
+ return null;
64
+ }
65
+ var listNodePosition = doc.resolve(parentList.pos);
66
+ return findRootParentListNode(listNodePosition);
67
+ };
68
+ exports.findRootParentListNode = findRootParentListNode;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getListLiftTarget = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ // This will return (depth - 1) for root list parent of a list.
9
+ var getListLiftTarget = function getListLiftTarget(resPos) {
10
+ var target = resPos.depth;
11
+ for (var i = resPos.depth; i > 0; i--) {
12
+ var node = resPos.node(i);
13
+ if ((0, _utils.isListNode)(node)) {
14
+ target = i;
15
+ }
16
+ if (!(0, _utils.isListItemNode)(node) && !(0, _utils.isListNode)(node)) {
17
+ break;
18
+ }
19
+ }
20
+ return target - 1;
21
+ };
22
+ exports.getListLiftTarget = getListLiftTarget;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sanitiseMarksInSelection = void 0;
7
+ var sanitiseMarksInSelection = function sanitiseMarksInSelection(tr, newParentType) {
8
+ var _tr$selection = tr.selection,
9
+ from = _tr$selection.from,
10
+ to = _tr$selection.to;
11
+ var nodesSanitized = [];
12
+ tr.doc.nodesBetween(from, to, function (node, pos, parent) {
13
+ if (node.isText) {
14
+ return false;
15
+ }
16
+ // Skip expands and layouts if they are outside selection
17
+ // but continue to iterate over their children.
18
+ if (['expand', 'layoutSection'].includes(node.type.name) && (pos < from || pos > to)) {
19
+ return true;
20
+ }
21
+ node.marks.forEach(function (mark) {
22
+ if (!(parent !== null && parent !== void 0 && parent.type.allowsMarkType(mark.type)) || newParentType && !newParentType.allowsMarkType(mark.type)) {
23
+ var filteredMarks = node.marks.filter(function (m) {
24
+ return m.type !== mark.type;
25
+ });
26
+ var position = pos > 0 ? pos : 0;
27
+ var marksRemoved = node.marks.filter(function (m) {
28
+ return m.type === mark.type;
29
+ });
30
+ nodesSanitized.push({
31
+ node: node,
32
+ marksRemoved: marksRemoved
33
+ });
34
+ tr.setNodeMarkup(position, undefined, node.attrs, filteredMarks);
35
+ }
36
+ });
37
+ });
38
+ return nodesSanitized;
39
+ };
40
+ exports.sanitiseMarksInSelection = sanitiseMarksInSelection;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isListNodeValidContent = isListNodeValidContent;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ var _model = require("@atlaskit/editor-prosemirror/model");
9
+ function isListNodeValidContent(node) {
10
+ var bulletList = node.type.schema.nodes.bulletList;
11
+ if (!bulletList) {
12
+ return false;
13
+ }
14
+ var listFragment = _model.Fragment.from(bulletList.createAndFill());
15
+ return !(0, _utils.isListItemNode)(node) && node.type.validContent(listFragment);
16
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.selectionContainsList = exports.isWrappingPossible = exports.isPosInsideParagraph = exports.isPosInsideList = exports.isInsideTableCell = exports.isInsideListItem = exports.createListNodeRange = exports.canJoinToPreviousListItem = void 0;
7
+ var _selection = require("@atlaskit/editor-common/selection");
8
+ var _utils = require("@atlaskit/editor-common/utils");
9
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
10
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
11
+ var isPosInsideParagraph = function isPosInsideParagraph($pos) {
12
+ return $pos.parent.type.name === 'paragraph';
13
+ };
14
+ exports.isPosInsideParagraph = isPosInsideParagraph;
15
+ var isPosInsideList = function isPosInsideList($pos) {
16
+ var posGrandParent = $pos.node(-1);
17
+ return (0, _utils.isListItemNode)($pos.parent) || (0, _utils.isListNode)($pos.parent) || (0, _utils.isListItemNode)(posGrandParent);
18
+ };
19
+ exports.isPosInsideList = isPosInsideList;
20
+ var isWrappingPossible = function isWrappingPossible(nodeType, selection) {
21
+ var $from = selection.$from,
22
+ $to = selection.$to;
23
+ var range;
24
+ if (selection instanceof _selection.GapCursorSelection && $from.nodeAfter) {
25
+ var nodeSize = $from.nodeAfter.nodeSize || 1;
26
+ range = $from.blockRange($from.doc.resolve($from.pos + nodeSize));
27
+ } else {
28
+ range = $from.blockRange($to);
29
+ }
30
+ if (!range) {
31
+ return false;
32
+ }
33
+ var wrap = (0, _transform.findWrapping)(range, nodeType);
34
+ if (!wrap) {
35
+ return false;
36
+ }
37
+ return true;
38
+ };
39
+
40
+ // canOutdent
41
+ exports.isWrappingPossible = isWrappingPossible;
42
+ var isInsideListItem = function isInsideListItem(state) {
43
+ var parent = state.selection.$from.parent;
44
+ var listItem = state.schema.nodes.listItem;
45
+ if (state.selection instanceof _selection.GapCursorSelection) {
46
+ return (0, _utils.isListItemNode)(parent);
47
+ }
48
+ return (0, _utils2.hasParentNodeOfType)(listItem)(state.selection) && (0, _utils.isParagraphNode)(parent);
49
+ };
50
+ exports.isInsideListItem = isInsideListItem;
51
+ var isInsideTableCell = function isInsideTableCell(state) {
52
+ var _state$schema$nodes = state.schema.nodes,
53
+ tableCell = _state$schema$nodes.tableCell,
54
+ tableHeader = _state$schema$nodes.tableHeader;
55
+ return !!(0, _utils2.findParentNodeOfType)([tableCell, tableHeader])(state.selection);
56
+ };
57
+ exports.isInsideTableCell = isInsideTableCell;
58
+ var canJoinToPreviousListItem = function canJoinToPreviousListItem(state) {
59
+ var $from = state.selection.$from;
60
+ var $before = state.doc.resolve($from.pos - 1);
61
+ var nodeBefore = $before ? $before.nodeBefore : null;
62
+ if (state.selection instanceof _selection.GapCursorSelection) {
63
+ nodeBefore = $from.nodeBefore;
64
+ }
65
+ return (0, _utils.isListNode)(nodeBefore);
66
+ };
67
+ exports.canJoinToPreviousListItem = canJoinToPreviousListItem;
68
+ var selectionContainsList = function selectionContainsList(tr) {
69
+ var _tr$selection = tr.selection,
70
+ from = _tr$selection.from,
71
+ to = _tr$selection.to;
72
+ var foundListNode = null;
73
+ tr.doc.nodesBetween(from, to, function (node) {
74
+ if ((0, _utils.isListNode)(node)) {
75
+ foundListNode = node;
76
+ }
77
+ if (foundListNode) {
78
+ return false;
79
+ }
80
+ return true;
81
+ });
82
+ return foundListNode;
83
+ };
84
+ exports.selectionContainsList = selectionContainsList;
85
+ var createListNodeRange = function createListNodeRange(_ref) {
86
+ var selection = _ref.selection;
87
+ var $from = selection.$from,
88
+ $to = selection.$to;
89
+ var range = $from.blockRange($to, _utils.isListNode);
90
+ if (!range) {
91
+ return null;
92
+ }
93
+ return range;
94
+ };
95
+ exports.createListNodeRange = createListNodeRange;