@gravity-ui/markdown-editor 13.1.1 → 13.2.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/README.md +2 -2
- package/build/cjs/core/markdown/MarkdownSerializer.js +1 -1
- package/build/cjs/extensions/behavior/SelectionContext/tooltip.d.ts +5 -3
- package/build/cjs/extensions/behavior/SelectionContext/tooltip.js +10 -1
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/const.d.ts +9 -0
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/const.js +11 -1
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/index.d.ts +1 -1
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/index.js +2 -1
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/parser.js +12 -5
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/schema.js +11 -9
- package/build/cjs/extensions/markdown/Lists/ListsSpecs/serializer.js +2 -2
- package/build/cjs/extensions/markdown/Lists/index.d.ts +1 -1
- package/build/cjs/extensions/markdown/Lists/index.js +2 -1
- package/build/cjs/extensions/markdown/Lists/inputrules.js +3 -2
- package/build/cjs/extensions/markdown/Lists/plugins/MergeListsPlugin.js +4 -5
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +1 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +8 -2
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +1 -0
- package/build/cjs/extensions/yfm/YfmHeading/commands.js +8 -6
- package/build/cjs/markup/codemirror/gravity.js +24 -0
- package/build/cjs/version.js +1 -1
- package/build/esm/core/markdown/MarkdownSerializer.js +1 -1
- package/build/esm/extensions/behavior/SelectionContext/tooltip.d.ts +5 -3
- package/build/esm/extensions/behavior/SelectionContext/tooltip.js +11 -2
- package/build/esm/extensions/markdown/Lists/ListsSpecs/const.d.ts +9 -0
- package/build/esm/extensions/markdown/Lists/ListsSpecs/const.js +10 -0
- package/build/esm/extensions/markdown/Lists/ListsSpecs/index.d.ts +1 -1
- package/build/esm/extensions/markdown/Lists/ListsSpecs/index.js +1 -1
- package/build/esm/extensions/markdown/Lists/ListsSpecs/parser.js +13 -6
- package/build/esm/extensions/markdown/Lists/ListsSpecs/schema.js +12 -10
- package/build/esm/extensions/markdown/Lists/ListsSpecs/serializer.js +3 -3
- package/build/esm/extensions/markdown/Lists/index.d.ts +1 -1
- package/build/esm/extensions/markdown/Lists/index.js +1 -1
- package/build/esm/extensions/markdown/Lists/inputrules.js +3 -2
- package/build/esm/extensions/markdown/Lists/plugins/MergeListsPlugin.js +4 -5
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +1 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +8 -2
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +1 -0
- package/build/esm/extensions/yfm/YfmHeading/commands.js +8 -6
- package/build/esm/markup/codemirror/gravity.js +24 -0
- package/build/esm/version.js +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @gravity-ui/markdown-editor · [](https://www.npmjs.com/package/@gravity-ui/markdown-editor) [](https://github.com/gravity-ui/markdown-editor/actions/workflows/ci.yml?query=branch:main) [](https://github.com/gravity-ui/markdown-editor/actions/workflows/release.yml?query=branch:main) [](https://preview.gravity-ui.com/md-editor/)
|
|
2
2
|
|
|
3
|
-
## Markdown wysiwyg and markup editor
|
|
3
|
+
## Markdown wysiwyg and markup editor
|
|
4
4
|
|
|
5
5
|
MarkdownEditor is a powerful tool for working with Markdown, which combines WYSIWYG and Markup modes. This means that you can create and edit content in a convenient visual mode, as well as have full control over the markup.
|
|
6
6
|
|
|
@@ -69,5 +69,5 @@ Don't forget to call `configure()` from [UIKit](https://github.com/gravity-ui/ui
|
|
|
69
69
|
To start the dev storybook
|
|
70
70
|
|
|
71
71
|
```shell
|
|
72
|
-
npm
|
|
72
|
+
npm start
|
|
73
73
|
```
|
|
@@ -299,7 +299,7 @@ class MarkdownSerializerState {
|
|
|
299
299
|
node.forEach((child, _, i) => {
|
|
300
300
|
if (i && isTight)
|
|
301
301
|
this.flushClose(1);
|
|
302
|
-
this.wrapBlock(delim, firstDelim(i), node, () => this.render(child, node, i));
|
|
302
|
+
this.wrapBlock(delim, firstDelim(i, child), node, () => this.render(child, node, i));
|
|
303
303
|
});
|
|
304
304
|
this.inTightList = prevTight;
|
|
305
305
|
}
|
|
@@ -2,10 +2,12 @@ import { PopupProps } from '@gravity-ui/uikit';
|
|
|
2
2
|
import { EditorState } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
4
|
import { ActionStorage } from '../../../core';
|
|
5
|
-
import { ToolbarGroupItemData } from '../../../toolbar';
|
|
6
|
-
export declare type ContextGroupItemData = ToolbarGroupItemData<ActionStorage> & {
|
|
5
|
+
import { ToolbarButtonPopupData, ToolbarGroupItemData, ToolbarSingleItemData } from '../../../toolbar';
|
|
6
|
+
export declare type ContextGroupItemData = (ToolbarGroupItemData<ActionStorage> & {
|
|
7
7
|
condition?: (state: EditorState) => void;
|
|
8
|
-
}
|
|
8
|
+
}) | ((ToolbarSingleItemData<ActionStorage> | ToolbarButtonPopupData<ActionStorage>) & {
|
|
9
|
+
condition?: 'enabled';
|
|
10
|
+
});
|
|
9
11
|
export declare type ContextGroupData = ContextGroupItemData[];
|
|
10
12
|
export declare type ContextConfig = ContextGroupData[];
|
|
11
13
|
export declare class TooltipView {
|
|
@@ -54,7 +54,16 @@ class TooltipView {
|
|
|
54
54
|
getFilteredConfig() {
|
|
55
55
|
return this.baseProps.show
|
|
56
56
|
? this.menuConfig
|
|
57
|
-
.map((groupData) => groupData.filter((
|
|
57
|
+
.map((groupData) => groupData.filter((item) => {
|
|
58
|
+
const { condition } = item;
|
|
59
|
+
if (condition === 'enabled') {
|
|
60
|
+
return item.isEnable(this.actions);
|
|
61
|
+
}
|
|
62
|
+
if ((0, lodash_1.isFunction)(condition)) {
|
|
63
|
+
return condition(this.view.state);
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}))
|
|
58
67
|
.filter((groupData) => Boolean(groupData.length))
|
|
59
68
|
: [];
|
|
60
69
|
}
|
|
@@ -3,3 +3,12 @@ export declare enum ListNode {
|
|
|
3
3
|
BulletList = "bullet_list",
|
|
4
4
|
OrderedList = "ordered_list"
|
|
5
5
|
}
|
|
6
|
+
export declare enum ListsAttr {
|
|
7
|
+
Tight = "tight",
|
|
8
|
+
/** used in bullet list only */
|
|
9
|
+
Bullet = "bullet",
|
|
10
|
+
/** used in ordered list only */
|
|
11
|
+
Order = "order",
|
|
12
|
+
/** used in list item only */
|
|
13
|
+
Markup = "markup"
|
|
14
|
+
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ListNode = void 0;
|
|
3
|
+
exports.ListsAttr = exports.ListNode = void 0;
|
|
4
4
|
var ListNode;
|
|
5
5
|
(function (ListNode) {
|
|
6
6
|
ListNode["ListItem"] = "list_item";
|
|
7
7
|
ListNode["BulletList"] = "bullet_list";
|
|
8
8
|
ListNode["OrderedList"] = "ordered_list";
|
|
9
9
|
})(ListNode = exports.ListNode || (exports.ListNode = {}));
|
|
10
|
+
var ListsAttr;
|
|
11
|
+
(function (ListsAttr) {
|
|
12
|
+
ListsAttr["Tight"] = "tight";
|
|
13
|
+
/** used in bullet list only */
|
|
14
|
+
ListsAttr["Bullet"] = "bullet";
|
|
15
|
+
/** used in ordered list only */
|
|
16
|
+
ListsAttr["Order"] = "order";
|
|
17
|
+
/** used in list item only */
|
|
18
|
+
ListsAttr["Markup"] = "markup";
|
|
19
|
+
})(ListsAttr = exports.ListsAttr || (exports.ListsAttr = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAuto } from '../../../../core';
|
|
2
|
-
export { ListNode } from './const';
|
|
2
|
+
export { ListsAttr, ListNode } from './const';
|
|
3
3
|
export declare const liType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
4
4
|
export declare const blType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
5
5
|
export declare const olType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ListsSpecs = exports.olType = exports.blType = exports.liType = exports.ListNode = void 0;
|
|
3
|
+
exports.ListsSpecs = exports.olType = exports.blType = exports.liType = exports.ListNode = exports.ListsAttr = void 0;
|
|
4
4
|
const schema_1 = require("../../../../utils/schema");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
6
|
const parser_1 = require("./parser");
|
|
7
7
|
const schema_2 = require("./schema");
|
|
8
8
|
const serializer_1 = require("./serializer");
|
|
9
9
|
var const_2 = require("./const");
|
|
10
|
+
Object.defineProperty(exports, "ListsAttr", { enumerable: true, get: function () { return const_2.ListsAttr; } });
|
|
10
11
|
Object.defineProperty(exports, "ListNode", { enumerable: true, get: function () { return const_2.ListNode; } });
|
|
11
12
|
exports.liType = (0, schema_1.nodeTypeFactory)(const_1.ListNode.ListItem);
|
|
12
13
|
exports.blType = (0, schema_1.nodeTypeFactory)(const_1.ListNode.BulletList);
|
|
@@ -3,18 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parserTokens = void 0;
|
|
4
4
|
const const_1 = require("./const");
|
|
5
5
|
exports.parserTokens = {
|
|
6
|
-
[const_1.ListNode.ListItem]: {
|
|
6
|
+
[const_1.ListNode.ListItem]: {
|
|
7
|
+
name: const_1.ListNode.ListItem,
|
|
8
|
+
type: 'block',
|
|
9
|
+
getAttrs: (token) => ({ [const_1.ListsAttr.Markup]: token.markup }),
|
|
10
|
+
},
|
|
7
11
|
[const_1.ListNode.BulletList]: {
|
|
8
12
|
name: const_1.ListNode.BulletList,
|
|
9
13
|
type: 'block',
|
|
10
|
-
getAttrs: (
|
|
14
|
+
getAttrs: (token, tokens, i) => ({
|
|
15
|
+
[const_1.ListsAttr.Tight]: listIsTight(tokens, i),
|
|
16
|
+
[const_1.ListsAttr.Bullet]: token.markup,
|
|
17
|
+
}),
|
|
11
18
|
},
|
|
12
19
|
[const_1.ListNode.OrderedList]: {
|
|
13
20
|
name: const_1.ListNode.OrderedList,
|
|
14
21
|
type: 'block',
|
|
15
|
-
getAttrs: (
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
getAttrs: (token, tokens, i) => ({
|
|
23
|
+
[const_1.ListsAttr.Order]: Number(token.attrGet('start')) || 1,
|
|
24
|
+
[const_1.ListsAttr.Tight]: listIsTight(tokens, i),
|
|
18
25
|
}),
|
|
19
26
|
},
|
|
20
27
|
};
|
|
@@ -4,7 +4,7 @@ exports.schemaSpecs = void 0;
|
|
|
4
4
|
const const_1 = require("./const");
|
|
5
5
|
exports.schemaSpecs = {
|
|
6
6
|
[const_1.ListNode.ListItem]: {
|
|
7
|
-
attrs: {
|
|
7
|
+
attrs: { [const_1.ListsAttr.Tight]: { default: false }, [const_1.ListsAttr.Markup]: { default: null } },
|
|
8
8
|
content: '(paragraph|block)+',
|
|
9
9
|
defining: true,
|
|
10
10
|
parseDOM: [{ tag: 'li' }],
|
|
@@ -19,22 +19,24 @@ exports.schemaSpecs = {
|
|
|
19
19
|
[const_1.ListNode.BulletList]: {
|
|
20
20
|
content: `${const_1.ListNode.ListItem}+`,
|
|
21
21
|
group: 'block',
|
|
22
|
-
attrs: {
|
|
22
|
+
attrs: { [const_1.ListsAttr.Tight]: { default: false }, [const_1.ListsAttr.Bullet]: { default: '*' } },
|
|
23
23
|
parseDOM: [
|
|
24
24
|
{
|
|
25
25
|
tag: 'ul',
|
|
26
|
-
getAttrs: (dom) => ({
|
|
26
|
+
getAttrs: (dom) => ({
|
|
27
|
+
[const_1.ListsAttr.Tight]: dom.hasAttribute('data-tight'),
|
|
28
|
+
}),
|
|
27
29
|
},
|
|
28
30
|
],
|
|
29
31
|
toDOM(node) {
|
|
30
|
-
return ['ul', { 'data-tight': node.attrs.
|
|
32
|
+
return ['ul', { 'data-tight': node.attrs[const_1.ListsAttr.Tight] ? 'true' : null }, 0];
|
|
31
33
|
},
|
|
32
34
|
selectable: false,
|
|
33
35
|
allowSelection: false,
|
|
34
36
|
complex: 'root',
|
|
35
37
|
},
|
|
36
38
|
[const_1.ListNode.OrderedList]: {
|
|
37
|
-
attrs: {
|
|
39
|
+
attrs: { [const_1.ListsAttr.Order]: { default: 1 }, [const_1.ListsAttr.Tight]: { default: false } },
|
|
38
40
|
content: `${const_1.ListNode.ListItem}+`,
|
|
39
41
|
group: 'block',
|
|
40
42
|
parseDOM: [
|
|
@@ -42,10 +44,10 @@ exports.schemaSpecs = {
|
|
|
42
44
|
tag: 'ol',
|
|
43
45
|
getAttrs(dom) {
|
|
44
46
|
return {
|
|
45
|
-
|
|
47
|
+
[const_1.ListsAttr.Order]: dom.hasAttribute('start')
|
|
46
48
|
? Number(dom.getAttribute('start'))
|
|
47
49
|
: 1,
|
|
48
|
-
|
|
50
|
+
[const_1.ListsAttr.Tight]: dom.hasAttribute('data-tight'),
|
|
49
51
|
};
|
|
50
52
|
},
|
|
51
53
|
},
|
|
@@ -54,8 +56,8 @@ exports.schemaSpecs = {
|
|
|
54
56
|
return [
|
|
55
57
|
'ol',
|
|
56
58
|
{
|
|
57
|
-
start: node.attrs.
|
|
58
|
-
'data-tight': node.attrs.
|
|
59
|
+
start: node.attrs[const_1.ListsAttr.Order] === 1 ? null : node.attrs[const_1.ListsAttr.Order],
|
|
60
|
+
'data-tight': node.attrs[const_1.ListsAttr.Tight] ? 'true' : null,
|
|
59
61
|
},
|
|
60
62
|
0,
|
|
61
63
|
];
|
|
@@ -7,10 +7,10 @@ exports.serializerTokens = {
|
|
|
7
7
|
state.renderContent(node);
|
|
8
8
|
},
|
|
9
9
|
[const_1.ListNode.BulletList]: (state, node) => {
|
|
10
|
-
state.renderList(node, ' ', () => (node.attrs.
|
|
10
|
+
state.renderList(node, ' ', (_i, li) => (li.attrs[const_1.ListsAttr.Markup] || node.attrs[const_1.ListsAttr.Bullet] || '*') + ' ');
|
|
11
11
|
},
|
|
12
12
|
[const_1.ListNode.OrderedList]: (state, node) => {
|
|
13
|
-
const start = node.attrs.
|
|
13
|
+
const start = node.attrs[const_1.ListsAttr.Order] || 1;
|
|
14
14
|
const maxW = String(start + node.childCount - 1).length;
|
|
15
15
|
const space = state.repeat(' ', maxW + 2);
|
|
16
16
|
state.renderList(node, space, (i) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
2
|
import { ListAction } from './const';
|
|
3
3
|
import { ListsInputRulesOptions } from './inputrules';
|
|
4
|
-
export { ListNode, blType, liType, olType } from './ListsSpecs';
|
|
4
|
+
export { ListNode, ListsAttr, blType, liType, olType } from './ListsSpecs';
|
|
5
5
|
export declare type ListsOptions = {
|
|
6
6
|
ulKey?: string | null;
|
|
7
7
|
olKey?: string | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Lists = exports.olType = exports.liType = exports.blType = exports.ListNode = void 0;
|
|
3
|
+
exports.Lists = exports.olType = exports.liType = exports.blType = exports.ListsAttr = exports.ListNode = void 0;
|
|
4
4
|
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
5
5
|
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
6
6
|
const keymap_1 = require("../../../utils/keymap");
|
|
@@ -12,6 +12,7 @@ const inputrules_1 = require("./inputrules");
|
|
|
12
12
|
const MergeListsPlugin_1 = require("./plugins/MergeListsPlugin");
|
|
13
13
|
var ListsSpecs_2 = require("./ListsSpecs");
|
|
14
14
|
Object.defineProperty(exports, "ListNode", { enumerable: true, get: function () { return ListsSpecs_2.ListNode; } });
|
|
15
|
+
Object.defineProperty(exports, "ListsAttr", { enumerable: true, get: function () { return ListsSpecs_2.ListsAttr; } });
|
|
15
16
|
Object.defineProperty(exports, "blType", { enumerable: true, get: function () { return ListsSpecs_2.blType; } });
|
|
16
17
|
Object.defineProperty(exports, "liType", { enumerable: true, get: function () { return ListsSpecs_2.liType; } });
|
|
17
18
|
Object.defineProperty(exports, "olType", { enumerable: true, get: function () { return ListsSpecs_2.olType; } });
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bulletListRule = exports.orderedListRule = exports.ListsInputRulesExtension = void 0;
|
|
4
4
|
const inputrules_1 = require("../../../utils/inputrules");
|
|
5
|
+
const ListsSpecs_1 = require("./ListsSpecs");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
7
|
const ListsInputRulesExtension = (builder, options) => {
|
|
7
8
|
builder.addInputRules(({ schema }) => {
|
|
@@ -20,7 +21,7 @@ exports.ListsInputRulesExtension = ListsInputRulesExtension;
|
|
|
20
21
|
* followed by a dot at the start of a textblock into an ordered list.
|
|
21
22
|
*/
|
|
22
23
|
function orderedListRule(nodeType) {
|
|
23
|
-
return (0, inputrules_1.wrappingInputRule)(/^(\d+)\.\s$/, nodeType, (match) => ({
|
|
24
|
+
return (0, inputrules_1.wrappingInputRule)(/^(\d+)\.\s$/, nodeType, (match) => ({ [ListsSpecs_1.ListsAttr.Order]: Number(match[1]) }), (match, node) => node.childCount + node.attrs[ListsSpecs_1.ListsAttr.Order] === Number(match[1]));
|
|
24
25
|
}
|
|
25
26
|
exports.orderedListRule = orderedListRule;
|
|
26
27
|
/**
|
|
@@ -39,6 +40,6 @@ function bulletListRule(nodeType, config) {
|
|
|
39
40
|
if (bullets.length === 0)
|
|
40
41
|
return null;
|
|
41
42
|
const regexp = new RegExp(`^\\s*([${bullets.join('')}])\\s$`); // same as /^\s*([-+*])\s$/
|
|
42
|
-
return (0, inputrules_1.wrappingInputRule)(regexp, nodeType);
|
|
43
|
+
return (0, inputrules_1.wrappingInputRule)(regexp, nodeType, (match) => ({ [ListsSpecs_1.ListsAttr.Bullet]: match[1] }));
|
|
43
44
|
}
|
|
44
45
|
exports.bulletListRule = bulletListRule;
|
|
@@ -21,11 +21,10 @@ const mergeListsPlugin = () => new prosemirror_state_1.Plugin({
|
|
|
21
21
|
});
|
|
22
22
|
exports.mergeListsPlugin = mergeListsPlugin;
|
|
23
23
|
function mergeAdjacentNodesWithSameType(tr, nodes) {
|
|
24
|
-
for (let i =
|
|
25
|
-
const
|
|
26
|
-
const next = nodes[i
|
|
27
|
-
if (
|
|
28
|
-
current.pos + current.node.nodeSize === next.pos) {
|
|
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) {
|
|
29
28
|
tr.join(next.pos);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -16,6 +16,7 @@ const YfmHeadingSpecs = (builder, opts) => {
|
|
|
16
16
|
[const_1.YfmHeadingAttr.Id]: { default: '' },
|
|
17
17
|
[const_1.YfmHeadingAttr.Level]: { default: 1 },
|
|
18
18
|
[const_1.YfmHeadingAttr.DataLine]: { default: null },
|
|
19
|
+
[const_1.YfmHeadingAttr.Folding]: { default: false },
|
|
19
20
|
},
|
|
20
21
|
content: '(text | inline)*',
|
|
21
22
|
group: 'block',
|
|
@@ -32,11 +33,13 @@ const YfmHeadingSpecs = (builder, opts) => {
|
|
|
32
33
|
toDOM(node) {
|
|
33
34
|
const id = node.attrs[const_1.YfmHeadingAttr.Id];
|
|
34
35
|
const lineNumber = node.attrs[const_1.YfmHeadingAttr.DataLine];
|
|
36
|
+
const folding = node.attrs[const_1.YfmHeadingAttr.Folding];
|
|
35
37
|
return [
|
|
36
38
|
'h' + node.attrs[const_1.YfmHeadingAttr.Level],
|
|
37
39
|
{
|
|
38
40
|
id: id || null,
|
|
39
41
|
[const_1.YfmHeadingAttr.DataLine]: lineNumber,
|
|
42
|
+
[`data-${const_1.YfmHeadingAttr.Folding}`]: folding ? '' : null,
|
|
40
43
|
},
|
|
41
44
|
0,
|
|
42
45
|
// [
|
|
@@ -61,6 +64,7 @@ const YfmHeadingSpecs = (builder, opts) => {
|
|
|
61
64
|
name: const_1.headingNodeName,
|
|
62
65
|
type: 'block',
|
|
63
66
|
getAttrs: (token) => {
|
|
67
|
+
var _a;
|
|
64
68
|
if (token.type.endsWith('_close'))
|
|
65
69
|
return {};
|
|
66
70
|
const attrs = Object.fromEntries(token.attrs || []);
|
|
@@ -70,12 +74,14 @@ const YfmHeadingSpecs = (builder, opts) => {
|
|
|
70
74
|
// attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
|
|
71
75
|
// }
|
|
72
76
|
// attrs have id only if it explicitly specified manually
|
|
73
|
-
return Object.assign({ [const_1.YfmHeadingAttr.Level]: Number(token.tag.slice(1)) }, attrs);
|
|
77
|
+
return Object.assign({ [const_1.YfmHeadingAttr.Level]: Number(token.tag.slice(1)), [const_1.YfmHeadingAttr.Folding]: (_a = token.meta) === null || _a === void 0 ? void 0 : _a.folding }, attrs);
|
|
74
78
|
},
|
|
75
79
|
},
|
|
76
80
|
},
|
|
77
81
|
toMd: (state, node) => {
|
|
78
|
-
|
|
82
|
+
const folding = node.attrs[const_1.YfmHeadingAttr.Folding];
|
|
83
|
+
const level = node.attrs[const_1.YfmHeadingAttr.Level];
|
|
84
|
+
state.write(state.repeat('#', level) + (folding ? '+' : '') + ' ');
|
|
79
85
|
state.renderInline(node);
|
|
80
86
|
const anchor = node.attrs[const_1.YfmHeadingAttr.Id];
|
|
81
87
|
if (anchor /*&& anchor !== node.firstChild?.textContent*/) {
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "headingRule", { enumerable: true, get: function
|
|
|
10
10
|
const getNodeAttrs = (level) => (node) => ({
|
|
11
11
|
[const_1.YfmHeadingAttr.Level]: level,
|
|
12
12
|
[const_1.YfmHeadingAttr.Id]: node.getAttribute('id') || '',
|
|
13
|
+
[const_1.YfmHeadingAttr.Folding]: node.hasAttribute(`data-${const_1.YfmHeadingAttr.Folding}`),
|
|
13
14
|
});
|
|
14
15
|
exports.getNodeAttrs = getNodeAttrs;
|
|
15
16
|
// export const slugify = (str: string) =>
|
|
@@ -9,15 +9,17 @@ const const_1 = require("./const");
|
|
|
9
9
|
var commands_1 = require("../../markdown/Heading/commands");
|
|
10
10
|
Object.defineProperty(exports, "resetHeading", { enumerable: true, get: function () { return commands_1.resetHeading; } });
|
|
11
11
|
const toHeading = (level) => (state, dispatch, view) => {
|
|
12
|
+
const attrs = {};
|
|
12
13
|
const parentHeading = (0, prosemirror_utils_1.findParentNodeOfType)((0, utils_1.hType)(state.schema))(state.selection);
|
|
13
|
-
if (parentHeading
|
|
14
|
-
|
|
14
|
+
if (parentHeading) {
|
|
15
|
+
if (parentHeading.node.attrs[const_1.headingLevelAttr] === level) {
|
|
16
|
+
return (0, base_1.toParagraph)(state, dispatch, view);
|
|
17
|
+
}
|
|
18
|
+
Object.assign(attrs, parentHeading.node.attrs);
|
|
15
19
|
}
|
|
16
20
|
// const text = state.selection.$head.parent.textContent;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[const_1.YfmHeadingAttr.Level]: level,
|
|
20
|
-
};
|
|
21
|
+
// attrs[YfmHeadingAttr.Id] = slugify(text);
|
|
22
|
+
attrs[const_1.YfmHeadingAttr.Level] = level;
|
|
21
23
|
return (0, prosemirror_commands_1.setBlockType)((0, utils_1.hType)(state.schema), attrs)(state, dispatch);
|
|
22
24
|
};
|
|
23
25
|
exports.toHeading = toHeading;
|
|
@@ -33,4 +33,28 @@ exports.gravityTheme = view_1.EditorView.baseTheme({
|
|
|
33
33
|
'&.cm-focused .cm-selectionBackground, &.cm-focused ::selection': {
|
|
34
34
|
background: 'var(--g-color-base-misc-medium)',
|
|
35
35
|
},
|
|
36
|
+
'.cm-tooltip.cm-tooltip-autocomplete': {
|
|
37
|
+
padding: '4px 0',
|
|
38
|
+
lineHeight: '24px',
|
|
39
|
+
color: 'var(--g-color-text-primary)',
|
|
40
|
+
fontFamily: 'var(--g-font-family-monospace)',
|
|
41
|
+
fontSize: 'var(--g-text-body-1-font-size)',
|
|
42
|
+
backgroundColor: 'var(--g-color-base-float)',
|
|
43
|
+
border: '1px solid var(--g-color-line-generic-solid)',
|
|
44
|
+
borderRadius: '4px',
|
|
45
|
+
'& > ul': {
|
|
46
|
+
'& > completion-section': {
|
|
47
|
+
color: 'var(--g-color-text-hint)',
|
|
48
|
+
fontWeight: 'var(--g-text-accent-font-weight)',
|
|
49
|
+
borderBottom: '1px solid var(--g-color-line-generic)',
|
|
50
|
+
},
|
|
51
|
+
'& > li:hover': {
|
|
52
|
+
backgroundColor: 'var(--g-color-base-simple-hover)',
|
|
53
|
+
},
|
|
54
|
+
'& > li[aria-selected]': {
|
|
55
|
+
backgroundColor: 'var(--g-color-base-selection)',
|
|
56
|
+
color: 'revert',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
36
60
|
});
|
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.2.0' !== 'undefined' ? '13.2.0' : 'unknown';
|
|
@@ -295,7 +295,7 @@ export class MarkdownSerializerState {
|
|
|
295
295
|
node.forEach((child, _, i) => {
|
|
296
296
|
if (i && isTight)
|
|
297
297
|
this.flushClose(1);
|
|
298
|
-
this.wrapBlock(delim, firstDelim(i), node, () => this.render(child, node, i));
|
|
298
|
+
this.wrapBlock(delim, firstDelim(i, child), node, () => this.render(child, node, i));
|
|
299
299
|
});
|
|
300
300
|
this.inTightList = prevTight;
|
|
301
301
|
}
|
|
@@ -2,10 +2,12 @@ import { PopupProps } from '@gravity-ui/uikit';
|
|
|
2
2
|
import { EditorState } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
4
|
import { ActionStorage } from '../../../core';
|
|
5
|
-
import { ToolbarGroupItemData } from '../../../toolbar';
|
|
6
|
-
export declare type ContextGroupItemData = ToolbarGroupItemData<ActionStorage> & {
|
|
5
|
+
import { ToolbarButtonPopupData, ToolbarGroupItemData, ToolbarSingleItemData } from '../../../toolbar';
|
|
6
|
+
export declare type ContextGroupItemData = (ToolbarGroupItemData<ActionStorage> & {
|
|
7
7
|
condition?: (state: EditorState) => void;
|
|
8
|
-
}
|
|
8
|
+
}) | ((ToolbarSingleItemData<ActionStorage> | ToolbarButtonPopupData<ActionStorage>) & {
|
|
9
|
+
condition?: 'enabled';
|
|
10
|
+
});
|
|
9
11
|
export declare type ContextGroupData = ContextGroupItemData[];
|
|
10
12
|
export declare type ContextConfig = ContextGroupData[];
|
|
11
13
|
export declare class TooltipView {
|
|
@@ -5,7 +5,7 @@ import { Popup } from '@gravity-ui/uikit';
|
|
|
5
5
|
import { isFunction } from '../../../lodash';
|
|
6
6
|
import { logger } from '../../../logger';
|
|
7
7
|
import { ErrorLoggerBoundary } from '../../../react-utils/ErrorBoundary';
|
|
8
|
-
import { Toolbar } from '../../../toolbar';
|
|
8
|
+
import { Toolbar, } from '../../../toolbar';
|
|
9
9
|
import { getReactRendererFromState } from '../ReactRenderer';
|
|
10
10
|
const SelectionTooltip = (_a) => {
|
|
11
11
|
var { show, poppupProps } = _a, toolbarProps = __rest(_a, ["show", "poppupProps"]);
|
|
@@ -51,7 +51,16 @@ export class TooltipView {
|
|
|
51
51
|
getFilteredConfig() {
|
|
52
52
|
return this.baseProps.show
|
|
53
53
|
? this.menuConfig
|
|
54
|
-
.map((groupData) => groupData.filter((
|
|
54
|
+
.map((groupData) => groupData.filter((item) => {
|
|
55
|
+
const { condition } = item;
|
|
56
|
+
if (condition === 'enabled') {
|
|
57
|
+
return item.isEnable(this.actions);
|
|
58
|
+
}
|
|
59
|
+
if (isFunction(condition)) {
|
|
60
|
+
return condition(this.view.state);
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}))
|
|
55
64
|
.filter((groupData) => Boolean(groupData.length))
|
|
56
65
|
: [];
|
|
57
66
|
}
|
|
@@ -3,3 +3,12 @@ export declare enum ListNode {
|
|
|
3
3
|
BulletList = "bullet_list",
|
|
4
4
|
OrderedList = "ordered_list"
|
|
5
5
|
}
|
|
6
|
+
export declare enum ListsAttr {
|
|
7
|
+
Tight = "tight",
|
|
8
|
+
/** used in bullet list only */
|
|
9
|
+
Bullet = "bullet",
|
|
10
|
+
/** used in ordered list only */
|
|
11
|
+
Order = "order",
|
|
12
|
+
/** used in list item only */
|
|
13
|
+
Markup = "markup"
|
|
14
|
+
}
|
|
@@ -4,3 +4,13 @@ export var ListNode;
|
|
|
4
4
|
ListNode["BulletList"] = "bullet_list";
|
|
5
5
|
ListNode["OrderedList"] = "ordered_list";
|
|
6
6
|
})(ListNode || (ListNode = {}));
|
|
7
|
+
export var ListsAttr;
|
|
8
|
+
(function (ListsAttr) {
|
|
9
|
+
ListsAttr["Tight"] = "tight";
|
|
10
|
+
/** used in bullet list only */
|
|
11
|
+
ListsAttr["Bullet"] = "bullet";
|
|
12
|
+
/** used in ordered list only */
|
|
13
|
+
ListsAttr["Order"] = "order";
|
|
14
|
+
/** used in list item only */
|
|
15
|
+
ListsAttr["Markup"] = "markup";
|
|
16
|
+
})(ListsAttr || (ListsAttr = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAuto } from '../../../../core';
|
|
2
|
-
export { ListNode } from './const';
|
|
2
|
+
export { ListsAttr, ListNode } from './const';
|
|
3
3
|
export declare const liType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
4
4
|
export declare const blType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
5
5
|
export declare const olType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -3,7 +3,7 @@ import { ListNode } from './const';
|
|
|
3
3
|
import { parserTokens } from './parser';
|
|
4
4
|
import { schemaSpecs } from './schema';
|
|
5
5
|
import { serializerTokens } from './serializer';
|
|
6
|
-
export { ListNode } from './const';
|
|
6
|
+
export { ListsAttr, ListNode } from './const';
|
|
7
7
|
export const liType = nodeTypeFactory(ListNode.ListItem);
|
|
8
8
|
export const blType = nodeTypeFactory(ListNode.BulletList);
|
|
9
9
|
export const olType = nodeTypeFactory(ListNode.OrderedList);
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import { ListNode } from './const';
|
|
1
|
+
import { ListNode, ListsAttr } from './const';
|
|
2
2
|
export const parserTokens = {
|
|
3
|
-
[ListNode.ListItem]: {
|
|
3
|
+
[ListNode.ListItem]: {
|
|
4
|
+
name: ListNode.ListItem,
|
|
5
|
+
type: 'block',
|
|
6
|
+
getAttrs: (token) => ({ [ListsAttr.Markup]: token.markup }),
|
|
7
|
+
},
|
|
4
8
|
[ListNode.BulletList]: {
|
|
5
9
|
name: ListNode.BulletList,
|
|
6
10
|
type: 'block',
|
|
7
|
-
getAttrs: (
|
|
11
|
+
getAttrs: (token, tokens, i) => ({
|
|
12
|
+
[ListsAttr.Tight]: listIsTight(tokens, i),
|
|
13
|
+
[ListsAttr.Bullet]: token.markup,
|
|
14
|
+
}),
|
|
8
15
|
},
|
|
9
16
|
[ListNode.OrderedList]: {
|
|
10
17
|
name: ListNode.OrderedList,
|
|
11
18
|
type: 'block',
|
|
12
|
-
getAttrs: (
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
getAttrs: (token, tokens, i) => ({
|
|
20
|
+
[ListsAttr.Order]: Number(token.attrGet('start')) || 1,
|
|
21
|
+
[ListsAttr.Tight]: listIsTight(tokens, i),
|
|
15
22
|
}),
|
|
16
23
|
},
|
|
17
24
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ListNode } from './const';
|
|
1
|
+
import { ListNode, ListsAttr } from './const';
|
|
2
2
|
export const schemaSpecs = {
|
|
3
3
|
[ListNode.ListItem]: {
|
|
4
|
-
attrs: {
|
|
4
|
+
attrs: { [ListsAttr.Tight]: { default: false }, [ListsAttr.Markup]: { default: null } },
|
|
5
5
|
content: '(paragraph|block)+',
|
|
6
6
|
defining: true,
|
|
7
7
|
parseDOM: [{ tag: 'li' }],
|
|
@@ -16,22 +16,24 @@ export const schemaSpecs = {
|
|
|
16
16
|
[ListNode.BulletList]: {
|
|
17
17
|
content: `${ListNode.ListItem}+`,
|
|
18
18
|
group: 'block',
|
|
19
|
-
attrs: {
|
|
19
|
+
attrs: { [ListsAttr.Tight]: { default: false }, [ListsAttr.Bullet]: { default: '*' } },
|
|
20
20
|
parseDOM: [
|
|
21
21
|
{
|
|
22
22
|
tag: 'ul',
|
|
23
|
-
getAttrs: (dom) => ({
|
|
23
|
+
getAttrs: (dom) => ({
|
|
24
|
+
[ListsAttr.Tight]: dom.hasAttribute('data-tight'),
|
|
25
|
+
}),
|
|
24
26
|
},
|
|
25
27
|
],
|
|
26
28
|
toDOM(node) {
|
|
27
|
-
return ['ul', { 'data-tight': node.attrs.
|
|
29
|
+
return ['ul', { 'data-tight': node.attrs[ListsAttr.Tight] ? 'true' : null }, 0];
|
|
28
30
|
},
|
|
29
31
|
selectable: false,
|
|
30
32
|
allowSelection: false,
|
|
31
33
|
complex: 'root',
|
|
32
34
|
},
|
|
33
35
|
[ListNode.OrderedList]: {
|
|
34
|
-
attrs: {
|
|
36
|
+
attrs: { [ListsAttr.Order]: { default: 1 }, [ListsAttr.Tight]: { default: false } },
|
|
35
37
|
content: `${ListNode.ListItem}+`,
|
|
36
38
|
group: 'block',
|
|
37
39
|
parseDOM: [
|
|
@@ -39,10 +41,10 @@ export const schemaSpecs = {
|
|
|
39
41
|
tag: 'ol',
|
|
40
42
|
getAttrs(dom) {
|
|
41
43
|
return {
|
|
42
|
-
|
|
44
|
+
[ListsAttr.Order]: dom.hasAttribute('start')
|
|
43
45
|
? Number(dom.getAttribute('start'))
|
|
44
46
|
: 1,
|
|
45
|
-
|
|
47
|
+
[ListsAttr.Tight]: dom.hasAttribute('data-tight'),
|
|
46
48
|
};
|
|
47
49
|
},
|
|
48
50
|
},
|
|
@@ -51,8 +53,8 @@ export const schemaSpecs = {
|
|
|
51
53
|
return [
|
|
52
54
|
'ol',
|
|
53
55
|
{
|
|
54
|
-
start: node.attrs.
|
|
55
|
-
'data-tight': node.attrs.
|
|
56
|
+
start: node.attrs[ListsAttr.Order] === 1 ? null : node.attrs[ListsAttr.Order],
|
|
57
|
+
'data-tight': node.attrs[ListsAttr.Tight] ? 'true' : null,
|
|
56
58
|
},
|
|
57
59
|
0,
|
|
58
60
|
];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ListNode } from './const';
|
|
1
|
+
import { ListNode, ListsAttr } from './const';
|
|
2
2
|
export const serializerTokens = {
|
|
3
3
|
[ListNode.ListItem]: (state, node) => {
|
|
4
4
|
state.renderContent(node);
|
|
5
5
|
},
|
|
6
6
|
[ListNode.BulletList]: (state, node) => {
|
|
7
|
-
state.renderList(node, ' ', () => (node.attrs.
|
|
7
|
+
state.renderList(node, ' ', (_i, li) => (li.attrs[ListsAttr.Markup] || node.attrs[ListsAttr.Bullet] || '*') + ' ');
|
|
8
8
|
},
|
|
9
9
|
[ListNode.OrderedList]: (state, node) => {
|
|
10
|
-
const start = node.attrs.
|
|
10
|
+
const start = node.attrs[ListsAttr.Order] || 1;
|
|
11
11
|
const maxW = String(start + node.childCount - 1).length;
|
|
12
12
|
const space = state.repeat(' ', maxW + 2);
|
|
13
13
|
state.renderList(node, space, (i) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
2
|
import { ListAction } from './const';
|
|
3
3
|
import { ListsInputRulesOptions } from './inputrules';
|
|
4
|
-
export { ListNode, blType, liType, olType } from './ListsSpecs';
|
|
4
|
+
export { ListNode, ListsAttr, blType, liType, olType } from './ListsSpecs';
|
|
5
5
|
export declare type ListsOptions = {
|
|
6
6
|
ulKey?: string | null;
|
|
7
7
|
olKey?: string | null;
|
|
@@ -7,7 +7,7 @@ import { joinPrevList, liftIfCursorIsAtBeginningOfItem, toList } from './command
|
|
|
7
7
|
import { ListAction } from './const';
|
|
8
8
|
import { ListsInputRulesExtension } from './inputrules';
|
|
9
9
|
import { mergeListsPlugin } from './plugins/MergeListsPlugin';
|
|
10
|
-
export { ListNode, blType, liType, olType } from './ListsSpecs';
|
|
10
|
+
export { ListNode, ListsAttr, blType, liType, olType } from './ListsSpecs';
|
|
11
11
|
export const Lists = (builder, opts) => {
|
|
12
12
|
builder.use(ListsSpecs);
|
|
13
13
|
builder.addKeymap(({ schema }) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { wrappingInputRule } from '../../../utils/inputrules';
|
|
2
|
+
import { ListsAttr } from './ListsSpecs';
|
|
2
3
|
import { blType, olType } from './utils';
|
|
3
4
|
export const ListsInputRulesExtension = (builder, options) => {
|
|
4
5
|
builder.addInputRules(({ schema }) => {
|
|
@@ -16,7 +17,7 @@ export const ListsInputRulesExtension = (builder, options) => {
|
|
|
16
17
|
* followed by a dot at the start of a textblock into an ordered list.
|
|
17
18
|
*/
|
|
18
19
|
export function orderedListRule(nodeType) {
|
|
19
|
-
return wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({
|
|
20
|
+
return wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ [ListsAttr.Order]: Number(match[1]) }), (match, node) => node.childCount + node.attrs[ListsAttr.Order] === Number(match[1]));
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Given a list node type, returns an input rule that turns a bullet
|
|
@@ -34,5 +35,5 @@ export function bulletListRule(nodeType, config) {
|
|
|
34
35
|
if (bullets.length === 0)
|
|
35
36
|
return null;
|
|
36
37
|
const regexp = new RegExp(`^\\s*([${bullets.join('')}])\\s$`); // same as /^\s*([-+*])\s$/
|
|
37
|
-
return wrappingInputRule(regexp, nodeType);
|
|
38
|
+
return wrappingInputRule(regexp, nodeType, (match) => ({ [ListsAttr.Bullet]: match[1] }));
|
|
38
39
|
}
|
|
@@ -17,11 +17,10 @@ export const mergeListsPlugin = () => new Plugin({
|
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
function mergeAdjacentNodesWithSameType(tr, nodes) {
|
|
20
|
-
for (let i =
|
|
21
|
-
const
|
|
22
|
-
const next = nodes[i
|
|
23
|
-
if (
|
|
24
|
-
current.pos + current.node.nodeSize === next.pos) {
|
|
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) {
|
|
25
24
|
tr.join(next.pos);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -12,6 +12,7 @@ export const YfmHeadingSpecs = (builder, opts) => {
|
|
|
12
12
|
[YfmHeadingAttr.Id]: { default: '' },
|
|
13
13
|
[YfmHeadingAttr.Level]: { default: 1 },
|
|
14
14
|
[YfmHeadingAttr.DataLine]: { default: null },
|
|
15
|
+
[YfmHeadingAttr.Folding]: { default: false },
|
|
15
16
|
},
|
|
16
17
|
content: '(text | inline)*',
|
|
17
18
|
group: 'block',
|
|
@@ -28,11 +29,13 @@ export const YfmHeadingSpecs = (builder, opts) => {
|
|
|
28
29
|
toDOM(node) {
|
|
29
30
|
const id = node.attrs[YfmHeadingAttr.Id];
|
|
30
31
|
const lineNumber = node.attrs[YfmHeadingAttr.DataLine];
|
|
32
|
+
const folding = node.attrs[YfmHeadingAttr.Folding];
|
|
31
33
|
return [
|
|
32
34
|
'h' + node.attrs[YfmHeadingAttr.Level],
|
|
33
35
|
{
|
|
34
36
|
id: id || null,
|
|
35
37
|
[YfmHeadingAttr.DataLine]: lineNumber,
|
|
38
|
+
[`data-${YfmHeadingAttr.Folding}`]: folding ? '' : null,
|
|
36
39
|
},
|
|
37
40
|
0,
|
|
38
41
|
// [
|
|
@@ -57,6 +60,7 @@ export const YfmHeadingSpecs = (builder, opts) => {
|
|
|
57
60
|
name: headingNodeName,
|
|
58
61
|
type: 'block',
|
|
59
62
|
getAttrs: (token) => {
|
|
63
|
+
var _a;
|
|
60
64
|
if (token.type.endsWith('_close'))
|
|
61
65
|
return {};
|
|
62
66
|
const attrs = Object.fromEntries(token.attrs || []);
|
|
@@ -66,12 +70,14 @@ export const YfmHeadingSpecs = (builder, opts) => {
|
|
|
66
70
|
// attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
|
|
67
71
|
// }
|
|
68
72
|
// attrs have id only if it explicitly specified manually
|
|
69
|
-
return Object.assign({ [YfmHeadingAttr.Level]: Number(token.tag.slice(1)) }, attrs);
|
|
73
|
+
return Object.assign({ [YfmHeadingAttr.Level]: Number(token.tag.slice(1)), [YfmHeadingAttr.Folding]: (_a = token.meta) === null || _a === void 0 ? void 0 : _a.folding }, attrs);
|
|
70
74
|
},
|
|
71
75
|
},
|
|
72
76
|
},
|
|
73
77
|
toMd: (state, node) => {
|
|
74
|
-
|
|
78
|
+
const folding = node.attrs[YfmHeadingAttr.Folding];
|
|
79
|
+
const level = node.attrs[YfmHeadingAttr.Level];
|
|
80
|
+
state.write(state.repeat('#', level) + (folding ? '+' : '') + ' ');
|
|
75
81
|
state.renderInline(node);
|
|
76
82
|
const anchor = node.attrs[YfmHeadingAttr.Id];
|
|
77
83
|
if (anchor /*&& anchor !== node.firstChild?.textContent*/) {
|
|
@@ -4,6 +4,7 @@ export { hType, hasParentHeading, headingRule } from '../../../markdown/Heading/
|
|
|
4
4
|
export const getNodeAttrs = (level) => (node) => ({
|
|
5
5
|
[YfmHeadingAttr.Level]: level,
|
|
6
6
|
[YfmHeadingAttr.Id]: node.getAttribute('id') || '',
|
|
7
|
+
[YfmHeadingAttr.Folding]: node.hasAttribute(`data-${YfmHeadingAttr.Folding}`),
|
|
7
8
|
});
|
|
8
9
|
// export const slugify = (str: string) =>
|
|
9
10
|
// // same config as in yfm-transform
|
|
@@ -5,14 +5,16 @@ import { hType } from './YfmHeadingSpecs/utils';
|
|
|
5
5
|
import { YfmHeadingAttr, headingLevelAttr } from './const';
|
|
6
6
|
export { resetHeading } from '../../markdown/Heading/commands';
|
|
7
7
|
export const toHeading = (level) => (state, dispatch, view) => {
|
|
8
|
+
const attrs = {};
|
|
8
9
|
const parentHeading = findParentNodeOfType(hType(state.schema))(state.selection);
|
|
9
|
-
if (parentHeading
|
|
10
|
-
|
|
10
|
+
if (parentHeading) {
|
|
11
|
+
if (parentHeading.node.attrs[headingLevelAttr] === level) {
|
|
12
|
+
return toParagraph(state, dispatch, view);
|
|
13
|
+
}
|
|
14
|
+
Object.assign(attrs, parentHeading.node.attrs);
|
|
11
15
|
}
|
|
12
16
|
// const text = state.selection.$head.parent.textContent;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[YfmHeadingAttr.Level]: level,
|
|
16
|
-
};
|
|
17
|
+
// attrs[YfmHeadingAttr.Id] = slugify(text);
|
|
18
|
+
attrs[YfmHeadingAttr.Level] = level;
|
|
17
19
|
return setBlockType(hType(state.schema), attrs)(state, dispatch);
|
|
18
20
|
};
|
|
@@ -30,4 +30,28 @@ export const gravityTheme = EditorView.baseTheme({
|
|
|
30
30
|
'&.cm-focused .cm-selectionBackground, &.cm-focused ::selection': {
|
|
31
31
|
background: 'var(--g-color-base-misc-medium)',
|
|
32
32
|
},
|
|
33
|
+
'.cm-tooltip.cm-tooltip-autocomplete': {
|
|
34
|
+
padding: '4px 0',
|
|
35
|
+
lineHeight: '24px',
|
|
36
|
+
color: 'var(--g-color-text-primary)',
|
|
37
|
+
fontFamily: 'var(--g-font-family-monospace)',
|
|
38
|
+
fontSize: 'var(--g-text-body-1-font-size)',
|
|
39
|
+
backgroundColor: 'var(--g-color-base-float)',
|
|
40
|
+
border: '1px solid var(--g-color-line-generic-solid)',
|
|
41
|
+
borderRadius: '4px',
|
|
42
|
+
'& > ul': {
|
|
43
|
+
'& > completion-section': {
|
|
44
|
+
color: 'var(--g-color-text-hint)',
|
|
45
|
+
fontWeight: 'var(--g-text-accent-font-weight)',
|
|
46
|
+
borderBottom: '1px solid var(--g-color-line-generic)',
|
|
47
|
+
},
|
|
48
|
+
'& > li:hover': {
|
|
49
|
+
backgroundColor: 'var(--g-color-base-simple-hover)',
|
|
50
|
+
},
|
|
51
|
+
'& > li[aria-selected]': {
|
|
52
|
+
backgroundColor: 'var(--g-color-base-selection)',
|
|
53
|
+
color: 'revert',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
33
57
|
});
|
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.2.0' !== 'undefined' ? '13.2.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.2.0",
|
|
4
4
|
"description": "Markdown wysiwyg and markup editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "npm run storybook:start",
|
|
19
|
-
"dev": "npm run storybook:start",
|
|
20
19
|
"clean": "gulp clean",
|
|
21
20
|
"build": "gulp",
|
|
22
21
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|