@gravity-ui/markdown-editor 13.18.1 → 13.18.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.
@@ -1,5 +1,4 @@
1
1
  import type { NodeType } from 'prosemirror-model';
2
2
  import type { Command } from 'prosemirror-state';
3
3
  export declare function toList(listType: NodeType): Command;
4
- export declare const liftIfCursorIsAtBeginningOfItem: Command;
5
4
  export declare const joinPrevList: Command;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joinPrevList = exports.liftIfCursorIsAtBeginningOfItem = exports.toList = void 0;
3
+ exports.joinPrevList = exports.toList = void 0;
4
4
  const prosemirror_schema_list_1 = require("prosemirror-schema-list");
5
5
  const join_1 = require("../../../commands/join");
6
- const selection_1 = require("../../../utils/selection");
7
6
  const utils_1 = require("./utils");
8
7
  function toList(listType) {
9
8
  return (state, dispatch) => {
@@ -18,18 +17,6 @@ function toList(listType) {
18
17
  };
19
18
  }
20
19
  exports.toList = toList;
21
- const liftIfCursorIsAtBeginningOfItem = (state, dispatch) => {
22
- const $cursor = (0, selection_1.get$CursorAtBlockStart)(state.selection);
23
- if (!$cursor)
24
- return false;
25
- const { schema } = state;
26
- const parentBlock = $cursor.node($cursor.depth - 1);
27
- if (parentBlock.firstChild === $cursor.parent && (0, utils_1.isListItemNode)(parentBlock)) {
28
- return (0, prosemirror_schema_list_1.liftListItem)((0, utils_1.liType)(schema))(state, dispatch);
29
- }
30
- return false;
31
- };
32
- exports.liftIfCursorIsAtBeginningOfItem = liftIfCursorIsAtBeginningOfItem;
33
20
  exports.joinPrevList = (0, join_1.joinPreviousBlock)({
34
21
  checkPrevNode: utils_1.isListNode,
35
22
  skipNode: utils_1.isListOrItemNode,
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Lists = exports.olType = exports.liType = exports.blType = exports.ListsAttr = exports.ListNode = void 0;
4
- const prosemirror_commands_1 = require("prosemirror-commands");
5
4
  const prosemirror_schema_list_1 = require("prosemirror-schema-list");
6
5
  const keymap_1 = require("../../../utils/keymap");
7
6
  const ListsSpecs_1 = require("./ListsSpecs");
@@ -29,7 +28,7 @@ const Lists = (builder, opts) => {
29
28
  }, builder.Priority.High);
30
29
  builder.addKeymap(({ schema }) => ({
31
30
  Enter: (0, prosemirror_schema_list_1.splitListItem)((0, ListsSpecs_1.liType)(schema)),
32
- Backspace: (0, prosemirror_commands_1.chainCommands)(commands_1.liftIfCursorIsAtBeginningOfItem, commands_1.joinPrevList),
31
+ Backspace: commands_1.joinPrevList,
33
32
  }), builder.Priority.Low);
34
33
  builder.use(inputrules_1.ListsInputRulesExtension, { bulletListInputRule: opts === null || opts === void 0 ? void 0 : opts.ulInputRules });
35
34
  builder.addPlugin(MergeListsPlugin_1.mergeListsPlugin);
@@ -21,11 +21,15 @@ const mergeListsPlugin = () => new prosemirror_state_1.Plugin({
21
21
  });
22
22
  exports.mergeListsPlugin = mergeListsPlugin;
23
23
  function mergeAdjacentNodesWithSameType(tr, nodes) {
24
- for (let i = nodes.length - 1; i > 0; i--) {
25
- const prev = nodes[i - 1];
26
- const next = nodes[i];
27
- if (prev.node.type === next.node.type && prev.pos + prev.node.nodeSize === next.pos) {
28
- tr.join(next.pos);
24
+ const posAfterMap = {};
25
+ for (const item of nodes) {
26
+ const posBefore = item.pos;
27
+ const posAfter = posBefore + item.node.nodeSize;
28
+ posAfterMap[posAfter] = item.node;
29
+ const nodeBefore = posAfterMap[posBefore];
30
+ if ((nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type) === item.node.type) {
31
+ tr.join(tr.mapping.map(posBefore));
32
+ posAfterMap[posBefore] = undefined;
29
33
  }
30
34
  }
31
35
  }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  /** During build process, the current version will be injected here */
5
- exports.VERSION = typeof '13.18.1' !== 'undefined' ? '13.18.1' : 'unknown';
5
+ exports.VERSION = typeof '13.18.2' !== 'undefined' ? '13.18.2' : 'unknown';
@@ -1,5 +1,4 @@
1
1
  import type { NodeType } from 'prosemirror-model';
2
2
  import type { Command } from 'prosemirror-state';
3
3
  export declare function toList(listType: NodeType): Command;
4
- export declare const liftIfCursorIsAtBeginningOfItem: Command;
5
4
  export declare const joinPrevList: Command;
@@ -1,7 +1,6 @@
1
- import { liftListItem, wrapInList } from 'prosemirror-schema-list';
1
+ import { wrapInList } from 'prosemirror-schema-list';
2
2
  import { joinPreviousBlock } from '../../../commands/join';
3
- import { get$CursorAtBlockStart } from '../../../utils/selection';
4
- import { findAnyParentList, isListItemNode, isListNode, isListOrItemNode, liType } from './utils';
3
+ import { findAnyParentList, isListNode, isListOrItemNode } from './utils';
5
4
  export function toList(listType) {
6
5
  return (state, dispatch) => {
7
6
  const parentList = findAnyParentList(state.schema)(state.selection);
@@ -14,17 +13,6 @@ export function toList(listType) {
14
13
  return wrapInList(listType)(state, dispatch);
15
14
  };
16
15
  }
17
- export const liftIfCursorIsAtBeginningOfItem = (state, dispatch) => {
18
- const $cursor = get$CursorAtBlockStart(state.selection);
19
- if (!$cursor)
20
- return false;
21
- const { schema } = state;
22
- const parentBlock = $cursor.node($cursor.depth - 1);
23
- if (parentBlock.firstChild === $cursor.parent && isListItemNode(parentBlock)) {
24
- return liftListItem(liType(schema))(state, dispatch);
25
- }
26
- return false;
27
- };
28
16
  export const joinPrevList = joinPreviousBlock({
29
17
  checkPrevNode: isListNode,
30
18
  skipNode: isListOrItemNode,
@@ -1,9 +1,8 @@
1
- import { chainCommands } from 'prosemirror-commands';
2
1
  import { liftListItem, sinkListItem, splitListItem } from 'prosemirror-schema-list';
3
2
  import { withLogAction } from '../../../utils/keymap';
4
3
  import { ListsSpecs, blType, liType, olType } from './ListsSpecs';
5
4
  import { actions } from './actions';
6
- import { joinPrevList, liftIfCursorIsAtBeginningOfItem, toList } from './commands';
5
+ import { joinPrevList, toList } from './commands';
7
6
  import { ListAction } from './const';
8
7
  import { ListsInputRulesExtension } from './inputrules';
9
8
  import { mergeListsPlugin } from './plugins/MergeListsPlugin';
@@ -21,7 +20,7 @@ export const Lists = (builder, opts) => {
21
20
  }, builder.Priority.High);
22
21
  builder.addKeymap(({ schema }) => ({
23
22
  Enter: splitListItem(liType(schema)),
24
- Backspace: chainCommands(liftIfCursorIsAtBeginningOfItem, joinPrevList),
23
+ Backspace: joinPrevList,
25
24
  }), builder.Priority.Low);
26
25
  builder.use(ListsInputRulesExtension, { bulletListInputRule: opts === null || opts === void 0 ? void 0 : opts.ulInputRules });
27
26
  builder.addPlugin(mergeListsPlugin);
@@ -17,11 +17,15 @@ export const mergeListsPlugin = () => new Plugin({
17
17
  },
18
18
  });
19
19
  function mergeAdjacentNodesWithSameType(tr, nodes) {
20
- for (let i = nodes.length - 1; i > 0; i--) {
21
- const prev = nodes[i - 1];
22
- const next = nodes[i];
23
- if (prev.node.type === next.node.type && prev.pos + prev.node.nodeSize === next.pos) {
24
- tr.join(next.pos);
20
+ const posAfterMap = {};
21
+ for (const item of nodes) {
22
+ const posBefore = item.pos;
23
+ const posAfter = posBefore + item.node.nodeSize;
24
+ posAfterMap[posAfter] = item.node;
25
+ const nodeBefore = posAfterMap[posBefore];
26
+ if ((nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type) === item.node.type) {
27
+ tr.join(tr.mapping.map(posBefore));
28
+ posAfterMap[posBefore] = undefined;
25
29
  }
26
30
  }
27
31
  }
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.18.1' !== 'undefined' ? '13.18.1' : 'unknown';
2
+ export const VERSION = typeof '13.18.2' !== 'undefined' ? '13.18.2' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.18.1",
3
+ "version": "13.18.2",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {