@gravity-ui/markdown-editor 13.20.0 → 13.21.1

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,2 +1,6 @@
1
+ import { newlineInCode } from 'prosemirror-commands';
1
2
  import type { Command } from 'prosemirror-state';
3
+ import type { ExtensionDeps } from '../../../core';
4
+ export { newlineInCode };
2
5
  export declare const resetCodeblock: Command;
6
+ export declare const setCodeBlockType: ({ serializer }: ExtensionDeps) => Command;
@@ -1,15 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetCodeblock = void 0;
3
+ exports.setCodeBlockType = exports.resetCodeblock = exports.newlineInCode = void 0;
4
+ const prosemirror_commands_1 = require("prosemirror-commands");
5
+ Object.defineProperty(exports, "newlineInCode", { enumerable: true, get: function () { return prosemirror_commands_1.newlineInCode; } });
4
6
  const BaseSchema_1 = require("../../base/BaseSchema");
5
7
  const const_1 = require("./const");
6
8
  const resetCodeblock = (state, dispatch, view) => {
7
9
  const { selection } = state;
8
10
  if (selection.empty &&
9
- selection.$from.parent.type === (0, const_1.cbType)(state.schema) &&
11
+ selection.$from.parent.type === (0, const_1.codeBlockType)(state.schema) &&
10
12
  (view === null || view === void 0 ? void 0 : view.endOfTextblock('backward', state))) {
11
13
  return (0, BaseSchema_1.toParagraph)(state, dispatch, view);
12
14
  }
13
15
  return false;
14
16
  };
15
17
  exports.resetCodeblock = resetCodeblock;
18
+ const setCodeBlockType = ({ serializer }) => (state, dispatch) => {
19
+ const nodeType = (0, const_1.codeBlockType)(state.schema);
20
+ if (!(0, prosemirror_commands_1.setBlockType)(nodeType)(state))
21
+ return false;
22
+ if (dispatch) {
23
+ const markup = serializer.serialize(state.selection.content().content);
24
+ dispatch(state.tr.replaceSelectionWith(nodeType.createAndFill({}, markup ? state.schema.text(markup) : null)));
25
+ }
26
+ return true;
27
+ };
28
+ exports.setCodeBlockType = setCodeBlockType;
@@ -1,4 +1,6 @@
1
+ import { codeBlockType } from './CodeBlockSpecs';
1
2
  export { codeBlockNodeName, codeBlockLangAttr, CodeBlockNodeAttr as CodeBlockAttr, } from './CodeBlockSpecs';
2
3
  export declare const cbAction = "toCodeBlock";
3
4
  /** @deprecated Use `codeBlockType` instead */
4
5
  export declare const cbType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
6
+ export { codeBlockType };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cbType = exports.cbAction = exports.CodeBlockAttr = exports.codeBlockLangAttr = exports.codeBlockNodeName = void 0;
3
+ exports.codeBlockType = exports.cbType = exports.cbAction = exports.CodeBlockAttr = exports.codeBlockLangAttr = exports.codeBlockNodeName = void 0;
4
4
  const CodeBlockSpecs_1 = require("./CodeBlockSpecs");
5
+ Object.defineProperty(exports, "codeBlockType", { enumerable: true, get: function () { return CodeBlockSpecs_1.codeBlockType; } });
5
6
  var CodeBlockSpecs_2 = require("./CodeBlockSpecs");
6
7
  Object.defineProperty(exports, "codeBlockNodeName", { enumerable: true, get: function () { return CodeBlockSpecs_2.codeBlockNodeName; } });
7
8
  Object.defineProperty(exports, "codeBlockLangAttr", { enumerable: true, get: function () { return CodeBlockSpecs_2.codeBlockLangAttr; } });
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CodeBlock = exports.codeBlockType = exports.codeBlockLangAttr = exports.CodeBlockNodeAttr = exports.codeBlockNodeName = exports.resetCodeblock = void 0;
4
- const prosemirror_commands_1 = require("prosemirror-commands");
5
- const prosemirror_model_1 = require("prosemirror-model");
6
4
  const prosemirror_utils_1 = require("prosemirror-utils");
7
5
  const lodash_1 = require("../../../lodash");
8
6
  const inputrules_1 = require("../../../utils/inputrules");
@@ -24,28 +22,19 @@ const CodeBlock = (builder, opts) => {
24
22
  builder.use(CodeBlockSpecs_1.CodeBlockSpecs, opts);
25
23
  builder.addKeymap((deps) => {
26
24
  const { codeBlockKey } = opts;
27
- const bindings = { Enter: prosemirror_commands_1.newlineInCode, Backspace: commands_1.resetCodeblock };
25
+ const bindings = { Enter: commands_1.newlineInCode, Backspace: commands_1.resetCodeblock };
28
26
  if (codeBlockKey) {
29
- bindings[codeBlockKey] = (0, keymap_1.withLogAction)('code_block', (0, prosemirror_commands_1.setBlockType)((0, const_1.cbType)(deps.schema)));
27
+ bindings[codeBlockKey] = (0, keymap_1.withLogAction)('code_block', (0, commands_1.setCodeBlockType)(deps));
30
28
  }
31
29
  return bindings;
32
30
  });
33
- builder.addInputRules(({ schema }) => ({ rules: [codeBlockRule((0, const_1.cbType)(schema))] }));
34
- builder.addAction(const_1.cbAction, ({ schema, serializer }) => {
35
- const cb = (0, const_1.cbType)(schema);
36
- const cmd = (state, dispatch) => {
37
- if (!(0, prosemirror_commands_1.setBlockType)(cb)(state))
38
- return false;
39
- if (dispatch) {
40
- const markup = serializer.serialize(prosemirror_model_1.Fragment.from(state.selection.content().content));
41
- dispatch(state.tr.replaceSelectionWith(cb.createAndFill({}, markup ? state.schema.text(markup) : null)));
42
- }
43
- return true;
44
- };
31
+ builder.addInputRules(({ schema }) => ({ rules: [codeBlockRule((0, const_1.codeBlockType)(schema))] }));
32
+ builder.addAction(const_1.cbAction, (deps) => {
33
+ const cb = (0, const_1.codeBlockType)(deps.schema);
45
34
  return {
46
35
  isActive: (state) => (0, prosemirror_utils_1.hasParentNodeOfType)(cb)(state.selection),
47
- isEnable: cmd,
48
- run: cmd,
36
+ isEnable: (0, commands_1.setCodeBlockType)(deps),
37
+ run: (0, commands_1.setCodeBlockType)(deps),
49
38
  };
50
39
  });
51
40
  builder.addPlugin(codeBlockPastePlugin_1.codeBlockPastePlugin, builder.Priority.High);
@@ -9,10 +9,10 @@
9
9
  .g-md-table-view__wrapper {
10
10
  position: relative;
11
11
  display: inline-block;
12
- max-width: calc(100% - 18px);
13
- margin-right: 18px;
12
+ max-width: calc(100% - 16px);
13
+ margin-right: 16px;
14
14
  /* stylelint-disable declaration-no-important */
15
- margin-bottom: 18px !important;
15
+ margin-bottom: 16px !important;
16
16
  }
17
17
  .g-md-table-view__buttons-visible .g-md-table-view__plus-button-controls {
18
18
  pointer-events: initial;
@@ -43,6 +43,7 @@
43
43
  height: 16px;
44
44
  }
45
45
  .g-md-table-view__plus-button {
46
+ --_--padding: 8px;
46
47
  display: flex;
47
48
  justify-content: center;
48
49
  align-items: center;
@@ -70,7 +71,6 @@
70
71
  background: transparent !important;
71
72
  }
72
73
  .g-md-table-view.g-md-table-view tbody {
73
- display: block;
74
74
  border-radius: 8px;
75
75
  background: var(--g-color-base-background);
76
76
  box-shadow: inset 0 0 0 1px var(--g-color-line-generic);
@@ -54,6 +54,10 @@ function createCodemirror(params) {
54
54
  },
55
55
  },
56
56
  { key: 'Tab', preventDefault: true, run: commands_1.insertTab },
57
+ {
58
+ key: 'Enter',
59
+ shift: commands_1.insertNewlineKeepIndent,
60
+ },
57
61
  commands_1.indentWithTab,
58
62
  ...commands_1.defaultKeymap,
59
63
  ...(disabledExtensions.history ? [] : commands_1.historyKeymap),
@@ -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.20.0' !== 'undefined' ? '13.20.0' : 'unknown';
5
+ exports.VERSION = typeof '13.21.1' !== 'undefined' ? '13.21.1' : 'unknown';
@@ -1,2 +1,6 @@
1
+ import { newlineInCode } from 'prosemirror-commands';
1
2
  import type { Command } from 'prosemirror-state';
3
+ import type { ExtensionDeps } from '../../../core';
4
+ export { newlineInCode };
2
5
  export declare const resetCodeblock: Command;
6
+ export declare const setCodeBlockType: ({ serializer }: ExtensionDeps) => Command;
@@ -1,11 +1,23 @@
1
+ import { newlineInCode, setBlockType } from 'prosemirror-commands';
1
2
  import { toParagraph } from '../../base/BaseSchema';
2
- import { cbType } from './const';
3
+ import { codeBlockType } from './const';
4
+ export { newlineInCode };
3
5
  export const resetCodeblock = (state, dispatch, view) => {
4
6
  const { selection } = state;
5
7
  if (selection.empty &&
6
- selection.$from.parent.type === cbType(state.schema) &&
8
+ selection.$from.parent.type === codeBlockType(state.schema) &&
7
9
  (view === null || view === void 0 ? void 0 : view.endOfTextblock('backward', state))) {
8
10
  return toParagraph(state, dispatch, view);
9
11
  }
10
12
  return false;
11
13
  };
14
+ export const setCodeBlockType = ({ serializer }) => (state, dispatch) => {
15
+ const nodeType = codeBlockType(state.schema);
16
+ if (!setBlockType(nodeType)(state))
17
+ return false;
18
+ if (dispatch) {
19
+ const markup = serializer.serialize(state.selection.content().content);
20
+ dispatch(state.tr.replaceSelectionWith(nodeType.createAndFill({}, markup ? state.schema.text(markup) : null)));
21
+ }
22
+ return true;
23
+ };
@@ -1,4 +1,6 @@
1
+ import { codeBlockType } from './CodeBlockSpecs';
1
2
  export { codeBlockNodeName, codeBlockLangAttr, CodeBlockNodeAttr as CodeBlockAttr, } from './CodeBlockSpecs';
2
3
  export declare const cbAction = "toCodeBlock";
3
4
  /** @deprecated Use `codeBlockType` instead */
4
5
  export declare const cbType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
6
+ export { codeBlockType };
@@ -3,3 +3,4 @@ export { codeBlockNodeName, codeBlockLangAttr, CodeBlockNodeAttr as CodeBlockAtt
3
3
  export const cbAction = 'toCodeBlock';
4
4
  /** @deprecated Use `codeBlockType` instead */
5
5
  export const cbType = codeBlockType;
6
+ export { codeBlockType };
@@ -1,13 +1,11 @@
1
- import { newlineInCode, setBlockType } from 'prosemirror-commands';
2
- import { Fragment } from 'prosemirror-model';
3
1
  import { hasParentNodeOfType } from 'prosemirror-utils';
4
2
  import { isFunction } from '../../../lodash';
5
3
  import { textblockTypeInputRule } from '../../../utils/inputrules';
6
4
  import { withLogAction } from '../../../utils/keymap';
7
5
  import { CodeBlockHighlight } from './CodeBlockHighlight/CodeBlockHighlight';
8
6
  import { CodeBlockSpecs } from './CodeBlockSpecs';
9
- import { resetCodeblock } from './commands';
10
- import { cbAction, cbType } from './const';
7
+ import { newlineInCode, resetCodeblock, setCodeBlockType } from './commands';
8
+ import { cbAction, codeBlockType } from './const';
11
9
  import { codeBlockPastePlugin } from './plugins/codeBlockPastePlugin';
12
10
  export { resetCodeblock } from './commands';
13
11
  export { codeBlockNodeName, CodeBlockNodeAttr, codeBlockLangAttr, codeBlockType, } from './CodeBlockSpecs';
@@ -18,26 +16,17 @@ export const CodeBlock = (builder, opts) => {
18
16
  const { codeBlockKey } = opts;
19
17
  const bindings = { Enter: newlineInCode, Backspace: resetCodeblock };
20
18
  if (codeBlockKey) {
21
- bindings[codeBlockKey] = withLogAction('code_block', setBlockType(cbType(deps.schema)));
19
+ bindings[codeBlockKey] = withLogAction('code_block', setCodeBlockType(deps));
22
20
  }
23
21
  return bindings;
24
22
  });
25
- builder.addInputRules(({ schema }) => ({ rules: [codeBlockRule(cbType(schema))] }));
26
- builder.addAction(cbAction, ({ schema, serializer }) => {
27
- const cb = cbType(schema);
28
- const cmd = (state, dispatch) => {
29
- if (!setBlockType(cb)(state))
30
- return false;
31
- if (dispatch) {
32
- const markup = serializer.serialize(Fragment.from(state.selection.content().content));
33
- dispatch(state.tr.replaceSelectionWith(cb.createAndFill({}, markup ? state.schema.text(markup) : null)));
34
- }
35
- return true;
36
- };
23
+ builder.addInputRules(({ schema }) => ({ rules: [codeBlockRule(codeBlockType(schema))] }));
24
+ builder.addAction(cbAction, (deps) => {
25
+ const cb = codeBlockType(deps.schema);
37
26
  return {
38
27
  isActive: (state) => hasParentNodeOfType(cb)(state.selection),
39
- isEnable: cmd,
40
- run: cmd,
28
+ isEnable: setCodeBlockType(deps),
29
+ run: setCodeBlockType(deps),
41
30
  };
42
31
  });
43
32
  builder.addPlugin(codeBlockPastePlugin, builder.Priority.High);
@@ -9,10 +9,10 @@
9
9
  .g-md-table-view__wrapper {
10
10
  position: relative;
11
11
  display: inline-block;
12
- max-width: calc(100% - 18px);
13
- margin-right: 18px;
12
+ max-width: calc(100% - 16px);
13
+ margin-right: 16px;
14
14
  /* stylelint-disable declaration-no-important */
15
- margin-bottom: 18px !important;
15
+ margin-bottom: 16px !important;
16
16
  }
17
17
  .g-md-table-view__buttons-visible .g-md-table-view__plus-button-controls {
18
18
  pointer-events: initial;
@@ -43,6 +43,7 @@
43
43
  height: 16px;
44
44
  }
45
45
  .g-md-table-view__plus-button {
46
+ --_--padding: 8px;
46
47
  display: flex;
47
48
  justify-content: center;
48
49
  align-items: center;
@@ -70,7 +71,6 @@
70
71
  background: transparent !important;
71
72
  }
72
73
  .g-md-table-view.g-md-table-view tbody {
73
- display: block;
74
74
  border-radius: 8px;
75
75
  background: var(--g-color-base-background);
76
76
  box-shadow: inset 0 0 0 1px var(--g-color-line-generic);
@@ -1,5 +1,5 @@
1
1
  import { autocompletion } from '@codemirror/autocomplete';
2
- import { defaultKeymap, history, historyKeymap, indentWithTab, insertTab, } from '@codemirror/commands';
2
+ import { defaultKeymap, history, historyKeymap, indentWithTab, insertNewlineKeepIndent, insertTab, } from '@codemirror/commands';
3
3
  import { syntaxHighlighting } from '@codemirror/language';
4
4
  import { EditorView, keymap, placeholder } from '@codemirror/view';
5
5
  import { ActionName } from '../../bundle/config/action-names';
@@ -51,6 +51,10 @@ export function createCodemirror(params) {
51
51
  },
52
52
  },
53
53
  { key: 'Tab', preventDefault: true, run: insertTab },
54
+ {
55
+ key: 'Enter',
56
+ shift: insertNewlineKeepIndent,
57
+ },
54
58
  indentWithTab,
55
59
  ...defaultKeymap,
56
60
  ...(disabledExtensions.history ? [] : historyKeymap),
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.20.0' !== 'undefined' ? '13.20.0' : 'unknown';
2
+ export const VERSION = typeof '13.21.1' !== 'undefined' ? '13.21.1' : 'unknown';
package/build/styles.css CHANGED
@@ -1658,10 +1658,10 @@ body :has(.g-md-resizable_resizing) {
1658
1658
  .g-md-table-view__wrapper {
1659
1659
  position: relative;
1660
1660
  display: inline-block;
1661
- max-width: calc(100% - 18px);
1662
- margin-right: 18px;
1661
+ max-width: calc(100% - 16px);
1662
+ margin-right: 16px;
1663
1663
  /* stylelint-disable declaration-no-important */
1664
- margin-bottom: 18px !important;
1664
+ margin-bottom: 16px !important;
1665
1665
  }
1666
1666
  .g-md-table-view__buttons-visible .g-md-table-view__plus-button-controls {
1667
1667
  pointer-events: initial;
@@ -1692,6 +1692,7 @@ body :has(.g-md-resizable_resizing) {
1692
1692
  height: 16px;
1693
1693
  }
1694
1694
  .g-md-table-view__plus-button {
1695
+ --_--padding: 8px;
1695
1696
  display: flex;
1696
1697
  justify-content: center;
1697
1698
  align-items: center;
@@ -1719,7 +1720,6 @@ body :has(.g-md-resizable_resizing) {
1719
1720
  background: transparent !important;
1720
1721
  }
1721
1722
  .g-md-table-view.g-md-table-view tbody {
1722
- display: block;
1723
1723
  border-radius: 8px;
1724
1724
  background: var(--g-color-base-background);
1725
1725
  box-shadow: inset 0 0 0 1px var(--g-color-line-generic);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.20.0",
3
+ "version": "13.21.1",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -165,7 +165,7 @@
165
165
  "@codemirror/language": "6.10.1",
166
166
  "@codemirror/search": "6.5.6",
167
167
  "@codemirror/state": "6.4.1",
168
- "@codemirror/view": "6.26.3",
168
+ "@codemirror/view": "6.28.0",
169
169
  "@gravity-ui/i18n": "^1.1.0",
170
170
  "@gravity-ui/icons": "^2.10.0",
171
171
  "@lezer/highlight": "1.2.0",