@gravity-ui/markdown-editor 13.18.2 → 13.19.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 +1 -1
- package/build/cjs/bundle/Editor.d.ts +2 -0
- package/build/cjs/bundle/Editor.js +2 -1
- package/build/cjs/core/markdown/MarkdownSerializer.js +7 -3
- package/build/cjs/extensions/yfm/YfmTable/YfmTableSpecs/serializer.js +17 -4
- package/build/cjs/markup/codemirror/create.d.ts +2 -2
- package/build/cjs/markup/codemirror/create.js +2 -2
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.d.ts +2 -0
- package/build/esm/bundle/Editor.js +2 -1
- package/build/esm/core/markdown/MarkdownSerializer.js +7 -3
- package/build/esm/extensions/yfm/YfmTable/YfmTableSpecs/serializer.js +17 -4
- package/build/esm/markup/codemirror/create.d.ts +2 -2
- package/build/esm/markup/codemirror/create.js +2 -2
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
# @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/)
|
|
4
4
|
|
|
@@ -57,6 +57,8 @@ export declare type MarkupConfig = {
|
|
|
57
57
|
disabledExtensions?: CreateCodemirrorParams['disabledExtensions'];
|
|
58
58
|
/** Additional keymaps for codemirror instance */
|
|
59
59
|
keymaps?: CreateCodemirrorParams['keymaps'];
|
|
60
|
+
/** Overrides the default placeholder content. */
|
|
61
|
+
placeholder?: CreateCodemirrorParams['placeholder'];
|
|
60
62
|
/**
|
|
61
63
|
* Additional language data for markdown language in codemirror.
|
|
62
64
|
* Can be used to configure additional autocompletions and others.
|
|
@@ -150,10 +150,11 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
150
150
|
return tslib_1.__classPrivateFieldGet(this, _EditorImpl_wysiwygEditor, "f");
|
|
151
151
|
}
|
|
152
152
|
get markupEditor() {
|
|
153
|
+
var _a;
|
|
153
154
|
if (!tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupEditor, "f")) {
|
|
154
155
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_markupEditor, new editor_1.Editor((0, codemirror_1.createCodemirror)({
|
|
155
156
|
doc: tslib_1.__classPrivateFieldGet(this, _EditorImpl_markup, "f"),
|
|
156
|
-
|
|
157
|
+
placeholder: (_a = tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").placeholder) !== null && _a !== void 0 ? _a : (0, bundle_1.i18n)('markup_placeholder'),
|
|
157
158
|
onCancel: () => this.emit('cancel', null),
|
|
158
159
|
onSubmit: () => this.emit('submit', null),
|
|
159
160
|
onChange: () => this.emit('rerender-toolbar', null),
|
|
@@ -195,15 +195,19 @@ class MarkdownSerializerState {
|
|
|
195
195
|
let trailing = '';
|
|
196
196
|
const progress = (node, _, index) => {
|
|
197
197
|
let marks = node ? node.marks : [];
|
|
198
|
-
// Remove marks from breaks (hard_break or soft_break) that are the
|
|
198
|
+
// Remove marks from breaks (hard_break or soft_break) that are the edge node inside
|
|
199
199
|
// that mark to prevent parser edge cases with new lines just
|
|
200
|
-
// before closing marks.
|
|
200
|
+
// before closing or after opening marks.
|
|
201
201
|
if (node && node.type.spec.isBreak) {
|
|
202
202
|
marks = marks.filter(m => {
|
|
203
|
+
if (index === 0)
|
|
204
|
+
return false;
|
|
203
205
|
if (index + 1 == parent.childCount)
|
|
204
206
|
return false;
|
|
207
|
+
const prev = parent.child(index - 1);
|
|
205
208
|
const next = parent.child(index + 1);
|
|
206
|
-
return m.isInSet(
|
|
209
|
+
return ((m.isInSet(prev.marks) && (!prev.isText || /\S/.test(prev.text))) &&
|
|
210
|
+
(m.isInSet(next.marks) && (!next.isText || /\S/.test(next.text))));
|
|
207
211
|
});
|
|
208
212
|
}
|
|
209
213
|
let leading = trailing;
|
|
@@ -67,10 +67,23 @@ exports.serializerTokens = {
|
|
|
67
67
|
state.ensureNewLine();
|
|
68
68
|
});
|
|
69
69
|
},
|
|
70
|
-
[const_1.YfmTableNode.Row]: (
|
|
71
|
-
|
|
70
|
+
[const_1.YfmTableNode.Row]: (state, node) => {
|
|
71
|
+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
|
|
72
|
+
state.write('||');
|
|
73
|
+
state.ensureNewLine();
|
|
74
|
+
state.write('\n');
|
|
75
|
+
state.renderContent(node);
|
|
76
|
+
state.write('||');
|
|
77
|
+
state.ensureNewLine();
|
|
72
78
|
},
|
|
73
|
-
[const_1.YfmTableNode.Cell]: (
|
|
74
|
-
|
|
79
|
+
[const_1.YfmTableNode.Cell]: (state, node, parent) => {
|
|
80
|
+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
|
|
81
|
+
state.renderContent(node);
|
|
82
|
+
const isLastCellInRow = parent.lastChild === node;
|
|
83
|
+
if (!isLastCellInRow) {
|
|
84
|
+
state.write('|');
|
|
85
|
+
state.ensureNewLine();
|
|
86
|
+
state.write('\n');
|
|
87
|
+
}
|
|
75
88
|
},
|
|
76
89
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { autocompletion } from '@codemirror/autocomplete';
|
|
2
2
|
import type { Extension, StateCommand } from '@codemirror/state';
|
|
3
|
-
import { EditorView, EditorViewConfig, KeyBinding } from '@codemirror/view';
|
|
3
|
+
import { EditorView, EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
|
|
4
4
|
import { EventMap } from '../../bundle/Editor';
|
|
5
5
|
import { ReactRenderStorage } from '../../extensions';
|
|
6
6
|
import { Receiver } from '../../utils';
|
|
@@ -10,7 +10,7 @@ export type { YfmLangOptions };
|
|
|
10
10
|
declare type Autocompletion = Parameters<typeof autocompletion>[0];
|
|
11
11
|
export declare type CreateCodemirrorParams = {
|
|
12
12
|
doc: EditorViewConfig['doc'];
|
|
13
|
-
|
|
13
|
+
placeholder: Parameters<typeof placeholder>[0];
|
|
14
14
|
onCancel: () => void;
|
|
15
15
|
onSubmit: () => void;
|
|
16
16
|
onChange: () => void;
|
|
@@ -16,8 +16,8 @@ const react_facet_1 = require("./react-facet");
|
|
|
16
16
|
const plugin_1 = require("./search-plugin/plugin");
|
|
17
17
|
const yfm_1 = require("./yfm");
|
|
18
18
|
function createCodemirror(params) {
|
|
19
|
-
const { doc,
|
|
20
|
-
const extensions = [gravity_1.gravityTheme, (0, view_1.placeholder)(
|
|
19
|
+
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, } = params;
|
|
20
|
+
const extensions = [gravity_1.gravityTheme, (0, view_1.placeholder)(placeholderContent)];
|
|
21
21
|
if (!disabledExtensions.history) {
|
|
22
22
|
extensions.push((0, commands_1.history)());
|
|
23
23
|
}
|
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.19.0' !== 'undefined' ? '13.19.0' : 'unknown';
|
|
@@ -57,6 +57,8 @@ export declare type MarkupConfig = {
|
|
|
57
57
|
disabledExtensions?: CreateCodemirrorParams['disabledExtensions'];
|
|
58
58
|
/** Additional keymaps for codemirror instance */
|
|
59
59
|
keymaps?: CreateCodemirrorParams['keymaps'];
|
|
60
|
+
/** Overrides the default placeholder content. */
|
|
61
|
+
placeholder?: CreateCodemirrorParams['placeholder'];
|
|
60
62
|
/**
|
|
61
63
|
* Additional language data for markdown language in codemirror.
|
|
62
64
|
* Can be used to configure additional autocompletions and others.
|
|
@@ -147,10 +147,11 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
147
147
|
return __classPrivateFieldGet(this, _EditorImpl_wysiwygEditor, "f");
|
|
148
148
|
}
|
|
149
149
|
get markupEditor() {
|
|
150
|
+
var _a;
|
|
150
151
|
if (!__classPrivateFieldGet(this, _EditorImpl_markupEditor, "f")) {
|
|
151
152
|
__classPrivateFieldSet(this, _EditorImpl_markupEditor, new MarkupEditor(createCodemirror({
|
|
152
153
|
doc: __classPrivateFieldGet(this, _EditorImpl_markup, "f"),
|
|
153
|
-
|
|
154
|
+
placeholder: (_a = __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").placeholder) !== null && _a !== void 0 ? _a : i18n('markup_placeholder'),
|
|
154
155
|
onCancel: () => this.emit('cancel', null),
|
|
155
156
|
onSubmit: () => this.emit('submit', null),
|
|
156
157
|
onChange: () => this.emit('rerender-toolbar', null),
|
|
@@ -191,15 +191,19 @@ export class MarkdownSerializerState {
|
|
|
191
191
|
let trailing = '';
|
|
192
192
|
const progress = (node, _, index) => {
|
|
193
193
|
let marks = node ? node.marks : [];
|
|
194
|
-
// Remove marks from breaks (hard_break or soft_break) that are the
|
|
194
|
+
// Remove marks from breaks (hard_break or soft_break) that are the edge node inside
|
|
195
195
|
// that mark to prevent parser edge cases with new lines just
|
|
196
|
-
// before closing marks.
|
|
196
|
+
// before closing or after opening marks.
|
|
197
197
|
if (node && node.type.spec.isBreak) {
|
|
198
198
|
marks = marks.filter(m => {
|
|
199
|
+
if (index === 0)
|
|
200
|
+
return false;
|
|
199
201
|
if (index + 1 == parent.childCount)
|
|
200
202
|
return false;
|
|
203
|
+
const prev = parent.child(index - 1);
|
|
201
204
|
const next = parent.child(index + 1);
|
|
202
|
-
return m.isInSet(
|
|
205
|
+
return ((m.isInSet(prev.marks) && (!prev.isText || /\S/.test(prev.text))) &&
|
|
206
|
+
(m.isInSet(next.marks) && (!next.isText || /\S/.test(next.text))));
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
let leading = trailing;
|
|
@@ -63,10 +63,23 @@ export const serializerTokens = {
|
|
|
63
63
|
state.ensureNewLine();
|
|
64
64
|
});
|
|
65
65
|
},
|
|
66
|
-
[YfmTableNode.Row]: (
|
|
67
|
-
|
|
66
|
+
[YfmTableNode.Row]: (state, node) => {
|
|
67
|
+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
|
|
68
|
+
state.write('||');
|
|
69
|
+
state.ensureNewLine();
|
|
70
|
+
state.write('\n');
|
|
71
|
+
state.renderContent(node);
|
|
72
|
+
state.write('||');
|
|
73
|
+
state.ensureNewLine();
|
|
68
74
|
},
|
|
69
|
-
[YfmTableNode.Cell]: (
|
|
70
|
-
|
|
75
|
+
[YfmTableNode.Cell]: (state, node, parent) => {
|
|
76
|
+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
|
|
77
|
+
state.renderContent(node);
|
|
78
|
+
const isLastCellInRow = parent.lastChild === node;
|
|
79
|
+
if (!isLastCellInRow) {
|
|
80
|
+
state.write('|');
|
|
81
|
+
state.ensureNewLine();
|
|
82
|
+
state.write('\n');
|
|
83
|
+
}
|
|
71
84
|
},
|
|
72
85
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { autocompletion } from '@codemirror/autocomplete';
|
|
2
2
|
import type { Extension, StateCommand } from '@codemirror/state';
|
|
3
|
-
import { EditorView, EditorViewConfig, KeyBinding } from '@codemirror/view';
|
|
3
|
+
import { EditorView, EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
|
|
4
4
|
import { EventMap } from '../../bundle/Editor';
|
|
5
5
|
import { ReactRenderStorage } from '../../extensions';
|
|
6
6
|
import { Receiver } from '../../utils';
|
|
@@ -10,7 +10,7 @@ export type { YfmLangOptions };
|
|
|
10
10
|
declare type Autocompletion = Parameters<typeof autocompletion>[0];
|
|
11
11
|
export declare type CreateCodemirrorParams = {
|
|
12
12
|
doc: EditorViewConfig['doc'];
|
|
13
|
-
|
|
13
|
+
placeholder: Parameters<typeof placeholder>[0];
|
|
14
14
|
onCancel: () => void;
|
|
15
15
|
onSubmit: () => void;
|
|
16
16
|
onChange: () => void;
|
|
@@ -13,8 +13,8 @@ import { ReactRendererFacet } from './react-facet';
|
|
|
13
13
|
import { SearchPanelPlugin } from './search-plugin/plugin';
|
|
14
14
|
import { yfmLang } from './yfm';
|
|
15
15
|
export function createCodemirror(params) {
|
|
16
|
-
const { doc,
|
|
17
|
-
const extensions = [gravityTheme, placeholder(
|
|
16
|
+
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, } = params;
|
|
17
|
+
const extensions = [gravityTheme, placeholder(placeholderContent)];
|
|
18
18
|
if (!disabledExtensions.history) {
|
|
19
19
|
extensions.push(history());
|
|
20
20
|
}
|
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.19.0' !== 'undefined' ? '13.19.0' : 'unknown';
|