@gravity-ui/markdown-editor 13.20.0 → 13.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/extensions/markdown/CodeBlock/commands.d.ts +4 -0
- package/build/cjs/extensions/markdown/CodeBlock/commands.js +15 -2
- package/build/cjs/extensions/markdown/CodeBlock/const.d.ts +2 -0
- package/build/cjs/extensions/markdown/CodeBlock/const.js +2 -1
- package/build/cjs/extensions/markdown/CodeBlock/index.js +7 -18
- package/build/cjs/markup/codemirror/create.js +4 -0
- package/build/cjs/version.js +1 -1
- package/build/esm/extensions/markdown/CodeBlock/commands.d.ts +4 -0
- package/build/esm/extensions/markdown/CodeBlock/commands.js +14 -2
- package/build/esm/extensions/markdown/CodeBlock/const.d.ts +2 -0
- package/build/esm/extensions/markdown/CodeBlock/const.js +1 -0
- package/build/esm/extensions/markdown/CodeBlock/index.js +8 -19
- package/build/esm/markup/codemirror/create.js +5 -1
- package/build/esm/version.js +1 -1
- package/package.json +2 -2
|
@@ -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.
|
|
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:
|
|
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,
|
|
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.
|
|
34
|
-
builder.addAction(const_1.cbAction, (
|
|
35
|
-
const cb = (0, const_1.
|
|
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:
|
|
48
|
-
run:
|
|
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);
|
|
@@ -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),
|
package/build/cjs/version.js
CHANGED
|
@@ -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.
|
|
5
|
+
exports.VERSION = typeof '13.21.0' !== 'undefined' ? '13.21.0' : '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 {
|
|
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 ===
|
|
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 };
|
|
@@ -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,
|
|
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',
|
|
19
|
+
bindings[codeBlockKey] = withLogAction('code_block', setCodeBlockType(deps));
|
|
22
20
|
}
|
|
23
21
|
return bindings;
|
|
24
22
|
});
|
|
25
|
-
builder.addInputRules(({ schema }) => ({ rules: [codeBlockRule(
|
|
26
|
-
builder.addAction(cbAction, (
|
|
27
|
-
const cb =
|
|
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:
|
|
40
|
-
run:
|
|
28
|
+
isEnable: setCodeBlockType(deps),
|
|
29
|
+
run: setCodeBlockType(deps),
|
|
41
30
|
};
|
|
42
31
|
});
|
|
43
32
|
builder.addPlugin(codeBlockPastePlugin, builder.Priority.High);
|
|
@@ -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),
|
package/build/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** During build process, the current version will be injected here */
|
|
2
|
-
export const VERSION = typeof '13.
|
|
2
|
+
export const VERSION = typeof '13.21.0' !== 'undefined' ? '13.21.0' : 'unknown';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/markdown-editor",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.21.0",
|
|
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.
|
|
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",
|