@gravity-ui/markdown-editor 14.3.1 → 14.4.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/bundle/Editor.d.ts +2 -0
- package/build/cjs/bundle/Editor.js +8 -2
- package/build/cjs/bundle/MarkdownEditorView.js +1 -0
- package/build/cjs/bundle/SplitModeView.js +1 -0
- package/build/cjs/bundle/types.d.ts +22 -0
- package/build/cjs/bundle/useMarkdownEditor.js +6 -2
- package/build/cjs/bundle/wysiwyg-preset.d.ts +11 -2
- package/build/cjs/bundle/wysiwyg-preset.js +1 -0
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.js +6 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.js +11 -5
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +5 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +42 -24
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +9 -9
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +18 -20
- package/build/cjs/extensions/yfm/YfmFile/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/YfmFile/index.js +1 -0
- package/build/cjs/index.d.ts +1 -1
- package/build/cjs/index.js +2 -1
- package/build/cjs/markup/codemirror/create.d.ts +7 -5
- package/build/cjs/markup/codemirror/create.js +3 -2
- package/build/cjs/markup/codemirror/directive-facet.d.ts +3 -0
- package/build/cjs/markup/codemirror/directive-facet.js +8 -0
- package/build/cjs/markup/codemirror/index.d.ts +1 -0
- package/build/cjs/markup/codemirror/index.js +3 -1
- package/build/cjs/markup/codemirror/yfm.d.ts +5 -0
- package/build/cjs/markup/codemirror/yfm.js +26 -4
- package/build/cjs/markup/commands/yfm.js +10 -1
- package/build/cjs/utils/directive.d.ts +28 -0
- package/build/cjs/utils/directive.js +55 -0
- package/build/cjs/utils/index.d.ts +1 -0
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.d.ts +2 -0
- package/build/esm/bundle/Editor.js +8 -2
- package/build/esm/bundle/MarkdownEditorView.js +1 -0
- package/build/esm/bundle/SplitModeView.js +1 -0
- package/build/esm/bundle/types.d.ts +22 -0
- package/build/esm/bundle/useMarkdownEditor.js +6 -2
- package/build/esm/bundle/wysiwyg-preset.d.ts +11 -2
- package/build/esm/bundle/wysiwyg-preset.js +1 -0
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.js +5 -0
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.js +8 -3
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +6 -2
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +41 -24
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.js +1 -1
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.js +4 -5
- package/build/esm/extensions/yfm/YfmFile/index.d.ts +1 -0
- package/build/esm/extensions/yfm/YfmFile/index.js +2 -1
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/markup/codemirror/create.d.ts +7 -5
- package/build/esm/markup/codemirror/create.js +3 -2
- package/build/esm/markup/codemirror/directive-facet.d.ts +3 -0
- package/build/esm/markup/codemirror/directive-facet.js +5 -0
- package/build/esm/markup/codemirror/index.d.ts +1 -0
- package/build/esm/markup/codemirror/index.js +1 -0
- package/build/esm/markup/codemirror/yfm.d.ts +5 -0
- package/build/esm/markup/codemirror/yfm.js +25 -3
- package/build/esm/markup/commands/yfm.js +9 -1
- package/build/esm/utils/directive.d.ts +28 -0
- package/build/esm/utils/directive.js +51 -0
- package/build/esm/utils/index.d.ts +1 -0
- package/build/esm/version.js +1 -1
- package/package.json +5 -3
|
@@ -10,6 +10,7 @@ const utils_1 = require("../../extensions/behavior/Clipboard/utils");
|
|
|
10
10
|
const logger_1 = require("../../logger");
|
|
11
11
|
const shortcuts_1 = require("../../shortcuts");
|
|
12
12
|
const commands_2 = require("../commands");
|
|
13
|
+
const directive_facet_1 = require("./directive-facet");
|
|
13
14
|
const files_upload_facet_1 = require("./files-upload-facet");
|
|
14
15
|
const gravity_1 = require("./gravity");
|
|
15
16
|
const pairing_chars_1 = require("./pairing-chars");
|
|
@@ -17,7 +18,7 @@ const react_facet_1 = require("./react-facet");
|
|
|
17
18
|
const plugin_1 = require("./search-plugin/plugin");
|
|
18
19
|
const yfm_1 = require("./yfm");
|
|
19
20
|
function createCodemirror(params) {
|
|
20
|
-
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, } = params;
|
|
21
|
+
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, directiveSyntax, } = params;
|
|
21
22
|
const extensions = [gravity_1.gravityTheme, (0, view_1.placeholder)(placeholderContent)];
|
|
22
23
|
if (!disabledExtensions.history) {
|
|
23
24
|
extensions.push((0, commands_1.history)());
|
|
@@ -63,7 +64,7 @@ function createCodemirror(params) {
|
|
|
63
64
|
...commands_1.defaultKeymap,
|
|
64
65
|
...(disabledExtensions.history ? [] : commands_1.historyKeymap),
|
|
65
66
|
...keymaps,
|
|
66
|
-
]), (0, autocomplete_1.autocompletion)(autocompletionConfig), (0, yfm_1.yfmLang)(yfmLangOptions), react_facet_1.ReactRendererFacet.of(reactRenderer), pairing_chars_1.PairingCharactersExtension, view_1.EditorView.lineWrapping, view_1.EditorView.contentAttributes.of({ spellcheck: 'true' }), view_1.EditorView.domEventHandlers({
|
|
67
|
+
]), (0, autocomplete_1.autocompletion)(autocompletionConfig), (0, yfm_1.yfmLang)(yfmLangOptions), react_facet_1.ReactRendererFacet.of(reactRenderer), directive_facet_1.DirectiveSyntaxFacet.of(directiveSyntax), pairing_chars_1.PairingCharactersExtension, view_1.EditorView.lineWrapping, view_1.EditorView.contentAttributes.of({ spellcheck: 'true' }), view_1.EditorView.domEventHandlers({
|
|
67
68
|
scroll(event) {
|
|
68
69
|
onScroll(event);
|
|
69
70
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DirectiveSyntaxFacet = void 0;
|
|
4
|
+
const state_1 = require("@codemirror/state");
|
|
5
|
+
exports.DirectiveSyntaxFacet = state_1.Facet.define({
|
|
6
|
+
combine: ([context]) => context,
|
|
7
|
+
static: true,
|
|
8
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { CreateCodemirrorParams } from './create';
|
|
2
2
|
export { createCodemirror } from './create';
|
|
3
3
|
export { ReactRendererFacet } from './react-facet';
|
|
4
|
+
export { DirectiveSyntaxFacet } from './directive-facet';
|
|
4
5
|
export { getImageDimensions, IMG_MAX_HEIGHT } from './files-upload-plugin';
|
|
5
6
|
export type { YfmLangOptions } from './yfm';
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IMG_MAX_HEIGHT = exports.getImageDimensions = exports.ReactRendererFacet = exports.createCodemirror = void 0;
|
|
3
|
+
exports.IMG_MAX_HEIGHT = exports.getImageDimensions = exports.DirectiveSyntaxFacet = exports.ReactRendererFacet = exports.createCodemirror = void 0;
|
|
4
4
|
var create_1 = require("./create");
|
|
5
5
|
Object.defineProperty(exports, "createCodemirror", { enumerable: true, get: function () { return create_1.createCodemirror; } });
|
|
6
6
|
var react_facet_1 = require("./react-facet");
|
|
7
7
|
Object.defineProperty(exports, "ReactRendererFacet", { enumerable: true, get: function () { return react_facet_1.ReactRendererFacet; } });
|
|
8
|
+
var directive_facet_1 = require("./directive-facet");
|
|
9
|
+
Object.defineProperty(exports, "DirectiveSyntaxFacet", { enumerable: true, get: function () { return directive_facet_1.DirectiveSyntaxFacet; } });
|
|
8
10
|
var files_upload_plugin_1 = require("./files-upload-plugin");
|
|
9
11
|
Object.defineProperty(exports, "getImageDimensions", { enumerable: true, get: function () { return files_upload_plugin_1.getImageDimensions; } });
|
|
10
12
|
Object.defineProperty(exports, "IMG_MAX_HEIGHT", { enumerable: true, get: function () { return files_upload_plugin_1.IMG_MAX_HEIGHT; } });
|
|
@@ -15,6 +15,11 @@ export declare const yfmCutSnippet: (editor: {
|
|
|
15
15
|
state: import("@codemirror/state").EditorState;
|
|
16
16
|
dispatch: (tr: import("@codemirror/state").Transaction) => void;
|
|
17
17
|
}, completion: Completion | null, from: number, to: number) => void;
|
|
18
|
+
export declare const yfmCutDirectiveSnippetTemplate = ":::cut [#{title}]\n#{}\n:::\n\n";
|
|
19
|
+
export declare const yfmCutDirectiveSnippet: (editor: {
|
|
20
|
+
state: import("@codemirror/state").EditorState;
|
|
21
|
+
dispatch: (tr: import("@codemirror/state").Transaction) => void;
|
|
22
|
+
}, completion: Completion | null, from: number, to: number) => void;
|
|
18
23
|
export interface LanguageData {
|
|
19
24
|
autocomplete: CompletionSource;
|
|
20
25
|
[key: string]: any;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.yfmLang = exports.yfmCutSnippet = exports.yfmCutSnippetTemplate = exports.yfmNoteSnippets = exports.yfmNoteSnippetTemplate = exports.yfmNoteTypes = exports.customTags = void 0;
|
|
3
|
+
exports.yfmLang = exports.yfmCutDirectiveSnippet = exports.yfmCutDirectiveSnippetTemplate = exports.yfmCutSnippet = exports.yfmCutSnippetTemplate = exports.yfmNoteSnippets = exports.yfmNoteSnippetTemplate = exports.yfmNoteTypes = exports.customTags = void 0;
|
|
4
4
|
const autocomplete_1 = require("@codemirror/autocomplete");
|
|
5
5
|
const lang_markdown_1 = require("@codemirror/lang-markdown");
|
|
6
6
|
const highlight_1 = require("@lezer/highlight");
|
|
7
7
|
const lodash_1 = require("../../lodash");
|
|
8
|
+
const directive_facet_1 = require("./directive-facet");
|
|
8
9
|
exports.customTags = {
|
|
9
10
|
underline: highlight_1.Tag.define(),
|
|
10
11
|
monospace: highlight_1.Tag.define(),
|
|
@@ -58,8 +59,11 @@ exports.yfmNoteSnippets = {
|
|
|
58
59
|
};
|
|
59
60
|
exports.yfmCutSnippetTemplate = '{% cut "#{title}" %}\n\n#{}\n\n{% endcut %}\n\n';
|
|
60
61
|
exports.yfmCutSnippet = (0, autocomplete_1.snippet)(exports.yfmCutSnippetTemplate);
|
|
62
|
+
exports.yfmCutDirectiveSnippetTemplate = ':::cut [#{title}]\n#{}\n:::\n\n';
|
|
63
|
+
exports.yfmCutDirectiveSnippet = (0, autocomplete_1.snippet)(exports.yfmCutDirectiveSnippetTemplate);
|
|
61
64
|
const mdAutocomplete = {
|
|
62
65
|
autocomplete: (context) => {
|
|
66
|
+
const directiveContext = context.state.facet(directive_facet_1.DirectiveSyntaxFacet);
|
|
63
67
|
// TODO: add more actions and re-enable
|
|
64
68
|
// let word = context.matchBefore(/\/.*/);
|
|
65
69
|
// if (word) {
|
|
@@ -77,13 +81,15 @@ const mdAutocomplete = {
|
|
|
77
81
|
// label: '/yfm cut',
|
|
78
82
|
// displayLabel: 'YFM Cut',
|
|
79
83
|
// type: 'text',
|
|
80
|
-
// apply:
|
|
84
|
+
// apply: directiveFacet.shouldInsertDirectiveMarkup('yfmCut')
|
|
85
|
+
// ? yfmCutDirectiveSnippet
|
|
86
|
+
// : yfmCutSnippet,
|
|
81
87
|
// },
|
|
82
88
|
// ],
|
|
83
89
|
// };
|
|
84
90
|
// }
|
|
85
91
|
const word = context.matchBefore(/^.*/);
|
|
86
|
-
if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
|
|
92
|
+
if (directiveContext.option !== 'only' && (word === null || word === void 0 ? void 0 : word.text.startsWith('{%'))) {
|
|
87
93
|
return {
|
|
88
94
|
from: word.from,
|
|
89
95
|
options: [
|
|
@@ -99,11 +105,27 @@ const mdAutocomplete = {
|
|
|
99
105
|
label: '{% cut',
|
|
100
106
|
displayLabel: 'YFM Cut',
|
|
101
107
|
type: 'text',
|
|
102
|
-
apply:
|
|
108
|
+
apply: directiveContext.shouldInsertDirectiveMarkup('yfmCut')
|
|
109
|
+
? exports.yfmCutDirectiveSnippet
|
|
110
|
+
: exports.yfmCutSnippet,
|
|
103
111
|
},
|
|
104
112
|
],
|
|
105
113
|
};
|
|
106
114
|
}
|
|
115
|
+
if (directiveContext.option !== 'disabled' && (word === null || word === void 0 ? void 0 : word.text.startsWith(':'))) {
|
|
116
|
+
const options = [];
|
|
117
|
+
if (directiveContext.valueFor('yfmCut') !== 'disabled') {
|
|
118
|
+
options.push({
|
|
119
|
+
label: ':::cut',
|
|
120
|
+
displayLabel: 'YFM Cut',
|
|
121
|
+
type: 'text',
|
|
122
|
+
apply: exports.yfmCutDirectiveSnippet,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (options.length) {
|
|
126
|
+
return { from: word.from, options };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
107
129
|
return null;
|
|
108
130
|
},
|
|
109
131
|
};
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.insertYfmTable = exports.insertYfmTabs = exports.wrapToYfmNote = exports.wrapToYfmCut = void 0;
|
|
4
|
+
const directive_facet_1 = require("../codemirror/directive-facet");
|
|
4
5
|
const helpers_1 = require("./helpers");
|
|
5
|
-
|
|
6
|
+
const wrapToYfmCutCurly = (0, helpers_1.wrapToBlock)(({ lineBreak }) => '{% cut "title" %}' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endcut %}');
|
|
7
|
+
const wrapToYfmCutDirective = (0, helpers_1.wrapToBlock)(({ lineBreak }) => ':::cut [title]' + lineBreak, ({ lineBreak }) => lineBreak + ':::');
|
|
8
|
+
const wrapToYfmCut = (target) => {
|
|
9
|
+
const cmd = target.state.facet(directive_facet_1.DirectiveSyntaxFacet).shouldInsertDirectiveMarkup('yfmCut')
|
|
10
|
+
? wrapToYfmCutDirective
|
|
11
|
+
: wrapToYfmCutCurly;
|
|
12
|
+
return cmd(target);
|
|
13
|
+
};
|
|
14
|
+
exports.wrapToYfmCut = wrapToYfmCut;
|
|
6
15
|
exports.wrapToYfmNote = (0, helpers_1.wrapToBlock)(({ lineBreak }) => '{% note info %}' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endnote %}');
|
|
7
16
|
exports.insertYfmTabs = (0, helpers_1.wrapToBlock)(({ lineBreak }) => '{% list tabs %}' + lineBreak.repeat(2) + '- Tab name' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endlist %}', { before: ' ', after: '' });
|
|
8
17
|
exports.insertYfmTable = (0, helpers_1.wrapToBlock)(({ lineBreak }) => ['#|', '||'].join(lineBreak) + lineBreak, ({ lineBreak }) => lineBreak + ['|', '', '||', '||', '', '|', '', '||', '|#', ''].join(lineBreak));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare type DirectiveSyntaxValue = 'disabled' | 'enabled' | 'preserve' | 'overwrite' | 'only';
|
|
2
|
+
declare type DirectiveSyntaxMdPluginValue = 'disabled' | 'enabled' | 'only';
|
|
3
|
+
export declare type DirectiveSyntaxOption = DirectiveSyntaxValue | DirectiveSyntaxOptionObj;
|
|
4
|
+
declare type DirectiveSyntaxOptionObj = {
|
|
5
|
+
[K in keyof MarkdownEditor.DirectiveSyntaxAdditionalSupportedExtensions]?: DirectiveSyntaxValue;
|
|
6
|
+
};
|
|
7
|
+
declare global {
|
|
8
|
+
namespace MarkdownEditor {
|
|
9
|
+
/**
|
|
10
|
+
* Add more keys for you additional supported extensions
|
|
11
|
+
*/
|
|
12
|
+
interface DirectiveSyntaxAdditionalSupportedExtensions {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare class DirectiveSyntaxContext {
|
|
17
|
+
#private;
|
|
18
|
+
protected set option(value: DirectiveSyntaxOption | undefined);
|
|
19
|
+
get option(): DirectiveSyntaxOption;
|
|
20
|
+
constructor(option: DirectiveSyntaxOption | undefined);
|
|
21
|
+
valueFor(key: keyof DirectiveSyntaxOptionObj): DirectiveSyntaxValue;
|
|
22
|
+
mdPluginValueFor(key: keyof DirectiveSyntaxOptionObj): DirectiveSyntaxMdPluginValue;
|
|
23
|
+
/** helper for wisywig serializer */
|
|
24
|
+
shouldSerializeToDirective(key: keyof DirectiveSyntaxOptionObj, tokenMarkup: unknown): boolean;
|
|
25
|
+
/** helper for markup-mode commands and actions */
|
|
26
|
+
shouldInsertDirectiveMarkup(key: keyof DirectiveSyntaxOptionObj): boolean;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _DirectiveSyntaxContext_option;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DirectiveSyntaxContext = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const DIRECTIVE_SYNTAX_DEFAULT = 'disabled';
|
|
7
|
+
class DirectiveSyntaxContext {
|
|
8
|
+
constructor(option) {
|
|
9
|
+
_DirectiveSyntaxContext_option.set(this, void 0);
|
|
10
|
+
this.option = option;
|
|
11
|
+
tslib_1.__classPrivateFieldSet(this, _DirectiveSyntaxContext_option, this.option, "f");
|
|
12
|
+
}
|
|
13
|
+
set option(value) {
|
|
14
|
+
tslib_1.__classPrivateFieldSet(this, _DirectiveSyntaxContext_option, value !== null && value !== void 0 ? value : DIRECTIVE_SYNTAX_DEFAULT, "f");
|
|
15
|
+
}
|
|
16
|
+
get option() {
|
|
17
|
+
return tslib_1.__classPrivateFieldGet(this, _DirectiveSyntaxContext_option, "f");
|
|
18
|
+
}
|
|
19
|
+
valueFor(key) {
|
|
20
|
+
let value;
|
|
21
|
+
if (typeof this.option === 'object')
|
|
22
|
+
value = this.option[key];
|
|
23
|
+
if (typeof this.option === 'string')
|
|
24
|
+
value = this.option;
|
|
25
|
+
return value !== null && value !== void 0 ? value : DIRECTIVE_SYNTAX_DEFAULT;
|
|
26
|
+
}
|
|
27
|
+
mdPluginValueFor(key) {
|
|
28
|
+
const value = this.valueFor(key);
|
|
29
|
+
return value === 'preserve' || value === 'overwrite' ? 'enabled' : value;
|
|
30
|
+
}
|
|
31
|
+
/** helper for wisywig serializer */
|
|
32
|
+
shouldSerializeToDirective(key, tokenMarkup) {
|
|
33
|
+
const option = this.valueFor(key);
|
|
34
|
+
if (option === 'overwrite' || option === 'only')
|
|
35
|
+
return true;
|
|
36
|
+
if (typeof tokenMarkup === 'string') {
|
|
37
|
+
if (tokenMarkup.startsWith(':'))
|
|
38
|
+
return true;
|
|
39
|
+
if (tokenMarkup.startsWith('{'))
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (option === 'preserve')
|
|
43
|
+
return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/** helper for markup-mode commands and actions */
|
|
47
|
+
shouldInsertDirectiveMarkup(key) {
|
|
48
|
+
const value = this.valueFor(key);
|
|
49
|
+
if (value === 'disabled' || value === 'enabled')
|
|
50
|
+
return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.DirectiveSyntaxContext = DirectiveSyntaxContext;
|
|
55
|
+
_DirectiveSyntaxContext_option = new WeakMap();
|
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 '14.
|
|
5
|
+
exports.VERSION = typeof '14.4.0' !== 'undefined' ? '14.4.0' : 'unknown';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CommonEditor } from '../common';
|
|
2
2
|
import { ReactRenderStorage } from '../extensions';
|
|
3
3
|
import { type Receiver } from '../utils';
|
|
4
|
+
import type { DirectiveSyntaxContext } from '../utils/directive';
|
|
4
5
|
import type { MarkdownEditorMode as EditorMode, MarkdownEditorPreset as EditorPreset, MarkdownEditorOptions } from './types';
|
|
5
6
|
export declare type ToolbarActionData = {
|
|
6
7
|
editorMode: EditorMode;
|
|
@@ -41,5 +42,6 @@ export declare type ChangeEditorModeOptions = {
|
|
|
41
42
|
export declare type EditorOptions = Pick<MarkdownEditorOptions, 'md' | 'initial' | 'handlers' | 'experimental' | 'markupConfig' | 'wysiwygConfig'> & {
|
|
42
43
|
renderStorage: ReactRenderStorage;
|
|
43
44
|
preset: EditorPreset;
|
|
45
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
44
46
|
};
|
|
45
47
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _EditorImpl_markup, _EditorImpl_editorMode, _EditorImpl_toolbarVisible, _EditorImpl_splitModeEnabled, _EditorImpl_splitMode, _EditorImpl_renderPreview, _EditorImpl_wysiwygEditor, _EditorImpl_markupEditor, _EditorImpl_markupConfig, _EditorImpl_escapeConfig, _EditorImpl_mdOptions, _EditorImpl_preset, _EditorImpl_extensions, _EditorImpl_renderStorage, _EditorImpl_fileUploadHandler, _EditorImpl_parseInsertedUrlAsImage, _EditorImpl_needToSetDimensionsForUploadedImages, _EditorImpl_enableNewImageSizeCalculation, _EditorImpl_prepareRawMarkup, _EditorImpl_beforeEditorModeChange;
|
|
1
|
+
var _EditorImpl_markup, _EditorImpl_editorMode, _EditorImpl_toolbarVisible, _EditorImpl_splitModeEnabled, _EditorImpl_splitMode, _EditorImpl_renderPreview, _EditorImpl_wysiwygEditor, _EditorImpl_markupEditor, _EditorImpl_markupConfig, _EditorImpl_escapeConfig, _EditorImpl_mdOptions, _EditorImpl_preset, _EditorImpl_extensions, _EditorImpl_renderStorage, _EditorImpl_fileUploadHandler, _EditorImpl_parseInsertedUrlAsImage, _EditorImpl_needToSetDimensionsForUploadedImages, _EditorImpl_enableNewImageSizeCalculation, _EditorImpl_directiveSyntax, _EditorImpl_prepareRawMarkup, _EditorImpl_beforeEditorModeChange;
|
|
2
2
|
import { __classPrivateFieldGet, __classPrivateFieldSet, __rest } from "tslib";
|
|
3
3
|
import { EditorView as CMEditorView } from '@codemirror/view';
|
|
4
4
|
import { TextSelection } from 'prosemirror-state';
|
|
@@ -31,6 +31,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
31
31
|
_EditorImpl_parseInsertedUrlAsImage.set(this, void 0);
|
|
32
32
|
_EditorImpl_needToSetDimensionsForUploadedImages.set(this, void 0);
|
|
33
33
|
_EditorImpl_enableNewImageSizeCalculation.set(this, void 0);
|
|
34
|
+
_EditorImpl_directiveSyntax.set(this, void 0);
|
|
34
35
|
_EditorImpl_prepareRawMarkup.set(this, void 0);
|
|
35
36
|
_EditorImpl_beforeEditorModeChange.set(this, void 0);
|
|
36
37
|
this.getValue = () => this.currentEditor.getValue();
|
|
@@ -49,6 +50,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
49
50
|
__classPrivateFieldSet(this, _EditorImpl_fileUploadHandler, handlers.uploadFile, "f");
|
|
50
51
|
__classPrivateFieldSet(this, _EditorImpl_parseInsertedUrlAsImage, markupConfig.parseInsertedUrlAsImage, "f");
|
|
51
52
|
__classPrivateFieldSet(this, _EditorImpl_needToSetDimensionsForUploadedImages, Boolean(experimental.needToSetDimensionsForUploadedImages), "f");
|
|
53
|
+
__classPrivateFieldSet(this, _EditorImpl_directiveSyntax, opts.directiveSyntax, "f");
|
|
52
54
|
__classPrivateFieldSet(this, _EditorImpl_enableNewImageSizeCalculation, Boolean(experimental.enableNewImageSizeCalculation), "f");
|
|
53
55
|
__classPrivateFieldSet(this, _EditorImpl_prepareRawMarkup, experimental.prepareRawMarkup, "f");
|
|
54
56
|
__classPrivateFieldSet(this, _EditorImpl_escapeConfig, wysiwygConfig.escapeConfig, "f");
|
|
@@ -117,6 +119,9 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
117
119
|
get mdOptions() {
|
|
118
120
|
return __classPrivateFieldGet(this, _EditorImpl_mdOptions, "f");
|
|
119
121
|
}
|
|
122
|
+
get directiveSyntax() {
|
|
123
|
+
return __classPrivateFieldGet(this, _EditorImpl_directiveSyntax, "f");
|
|
124
|
+
}
|
|
120
125
|
get renderPreview() {
|
|
121
126
|
return __classPrivateFieldGet(this, _EditorImpl_renderPreview, "f");
|
|
122
127
|
}
|
|
@@ -169,6 +174,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
169
174
|
keymaps: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").keymaps,
|
|
170
175
|
yfmLangOptions: { languageData: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").languageData },
|
|
171
176
|
autocompletion: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").autocompletion,
|
|
177
|
+
directiveSyntax: this.directiveSyntax,
|
|
172
178
|
receiver: this,
|
|
173
179
|
})), "f");
|
|
174
180
|
}
|
|
@@ -308,7 +314,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
308
314
|
return (serializedEditorMarkup === null || serializedEditorMarkup === void 0 ? void 0 : serializedEditorMarkup.trim()) !== wysiwygValue.trim();
|
|
309
315
|
}
|
|
310
316
|
}
|
|
311
|
-
_EditorImpl_markup = new WeakMap(), _EditorImpl_editorMode = new WeakMap(), _EditorImpl_toolbarVisible = new WeakMap(), _EditorImpl_splitModeEnabled = new WeakMap(), _EditorImpl_splitMode = new WeakMap(), _EditorImpl_renderPreview = new WeakMap(), _EditorImpl_wysiwygEditor = new WeakMap(), _EditorImpl_markupEditor = new WeakMap(), _EditorImpl_markupConfig = new WeakMap(), _EditorImpl_escapeConfig = new WeakMap(), _EditorImpl_mdOptions = new WeakMap(), _EditorImpl_preset = new WeakMap(), _EditorImpl_extensions = new WeakMap(), _EditorImpl_renderStorage = new WeakMap(), _EditorImpl_fileUploadHandler = new WeakMap(), _EditorImpl_parseInsertedUrlAsImage = new WeakMap(), _EditorImpl_needToSetDimensionsForUploadedImages = new WeakMap(), _EditorImpl_enableNewImageSizeCalculation = new WeakMap(), _EditorImpl_prepareRawMarkup = new WeakMap(), _EditorImpl_beforeEditorModeChange = new WeakMap();
|
|
317
|
+
_EditorImpl_markup = new WeakMap(), _EditorImpl_editorMode = new WeakMap(), _EditorImpl_toolbarVisible = new WeakMap(), _EditorImpl_splitModeEnabled = new WeakMap(), _EditorImpl_splitMode = new WeakMap(), _EditorImpl_renderPreview = new WeakMap(), _EditorImpl_wysiwygEditor = new WeakMap(), _EditorImpl_markupEditor = new WeakMap(), _EditorImpl_markupConfig = new WeakMap(), _EditorImpl_escapeConfig = new WeakMap(), _EditorImpl_mdOptions = new WeakMap(), _EditorImpl_preset = new WeakMap(), _EditorImpl_extensions = new WeakMap(), _EditorImpl_renderStorage = new WeakMap(), _EditorImpl_fileUploadHandler = new WeakMap(), _EditorImpl_parseInsertedUrlAsImage = new WeakMap(), _EditorImpl_needToSetDimensionsForUploadedImages = new WeakMap(), _EditorImpl_enableNewImageSizeCalculation = new WeakMap(), _EditorImpl_directiveSyntax = new WeakMap(), _EditorImpl_prepareRawMarkup = new WeakMap(), _EditorImpl_beforeEditorModeChange = new WeakMap();
|
|
312
318
|
function getTopOffset(elem) {
|
|
313
319
|
const TOOLBAR_HEIGHT = 36; //px
|
|
314
320
|
const TOOLBAR_BOTTOM_OFFSET = 8; // px
|
|
@@ -120,6 +120,7 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
120
120
|
getValue: editor.getValue,
|
|
121
121
|
mode: 'preview',
|
|
122
122
|
md: editor.mdOptions,
|
|
123
|
+
directiveSyntax: editor.directiveSyntax,
|
|
123
124
|
})),
|
|
124
125
|
settings)) : (React.createElement(React.Fragment, null,
|
|
125
126
|
editorMode === 'wysiwyg' && (React.createElement(WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: settingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar }, editor.toolbarVisible && settingsVisible && settings)),
|
|
@@ -3,6 +3,7 @@ import type { MarkupString } from '../common';
|
|
|
3
3
|
import type { EscapeConfig, Extension } from '../core';
|
|
4
4
|
import type { CreateCodemirrorParams, YfmLangOptions } from '../markup';
|
|
5
5
|
import type { FileUploadHandler } from '../utils';
|
|
6
|
+
import type { DirectiveSyntaxContext, DirectiveSyntaxOption } from '../utils/directive';
|
|
6
7
|
import type { ChangeEditorModeOptions } from './Editor';
|
|
7
8
|
import type { ExtensionsOptions as WysiwygPresetExtensionsOptions } from './wysiwyg-preset';
|
|
8
9
|
export type { Editor as MarkdownEditorInstance } from './Editor';
|
|
@@ -13,6 +14,7 @@ export declare type RenderPreviewParams = {
|
|
|
13
14
|
getValue: () => MarkupString;
|
|
14
15
|
mode: 'preview' | 'split';
|
|
15
16
|
md: Readonly<MarkdownEditorMdOptions>;
|
|
17
|
+
directiveSyntax: Pick<DirectiveSyntaxContext, 'option' | 'valueFor' | 'mdPluginValueFor'>;
|
|
16
18
|
};
|
|
17
19
|
export declare type RenderPreview = (params: RenderPreviewParams) => ReactNode;
|
|
18
20
|
export declare type ParseInsertedUrlAsImage = (text: string) => {
|
|
@@ -61,6 +63,26 @@ export declare type MarkdownEditorExperimentalOptions = {
|
|
|
61
63
|
*/
|
|
62
64
|
prepareRawMarkup?: (value: MarkupString) => MarkupString;
|
|
63
65
|
beforeEditorModeChange?: (options: Pick<ChangeEditorModeOptions, 'mode' | 'reason'>) => boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Enables support of directive syntax for diplodoc (YFM) extensions.
|
|
68
|
+
*
|
|
69
|
+
* **Note:** This setting affects parsing of markdown markup and serializing to markdown markup.
|
|
70
|
+
* Be careful with it and use it in consistency with diplodoc/transform and diplodoc-extensions.
|
|
71
|
+
*
|
|
72
|
+
* Before enabling this option, make sure that appropriate versions of diplodoc/transform and diplodoc-extensions are installed.
|
|
73
|
+
*
|
|
74
|
+
* You can pass an object in `key:value` format to provide different behaviour for each extension individually.
|
|
75
|
+
*
|
|
76
|
+
* Values:
|
|
77
|
+
* - 'disabled' – directive syntax is disabled;
|
|
78
|
+
* - 'enabled' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using old syntax;
|
|
79
|
+
* - 'preserve' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using directive syntax;
|
|
80
|
+
* - 'overwrite' – existing blocks will be overwritten using directive syntax through serialization;
|
|
81
|
+
* - 'only' – old syntax is disabled, only directive syntax available. Blocks in old syntax will not be parsed.
|
|
82
|
+
*
|
|
83
|
+
* Default value is 'disabled'.
|
|
84
|
+
*/
|
|
85
|
+
directiveSyntax?: DirectiveSyntaxOption;
|
|
64
86
|
};
|
|
65
87
|
export declare type MarkdownEditorMarkupConfig = {
|
|
66
88
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useLayoutEffect, useMemo } from 'react';
|
|
2
2
|
import { ReactRenderStorage } from '../extensions';
|
|
3
3
|
import { logger } from '../logger';
|
|
4
|
+
import { DirectiveSyntaxContext } from '../utils/directive';
|
|
4
5
|
import { EditorImpl } from './Editor';
|
|
5
6
|
import { BundlePreset } from './wysiwyg-preset';
|
|
6
7
|
// [major] TODO: remove generic type
|
|
@@ -14,10 +15,12 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
14
15
|
const uploadFile = (_c = handlers.uploadFile) !== null && _c !== void 0 ? _c : props.fileUploadHandler;
|
|
15
16
|
const needToSetDimensionsForUploadedImages = (_d = experimental.needToSetDimensionsForUploadedImages) !== null && _d !== void 0 ? _d : props.needToSetDimensionsForUploadedImages;
|
|
16
17
|
const enableNewImageSizeCalculation = experimental.enableNewImageSizeCalculation;
|
|
18
|
+
const directiveSyntax = new DirectiveSyntaxContext(experimental.directiveSyntax);
|
|
17
19
|
const extensions = (builder) => {
|
|
18
20
|
var _a;
|
|
19
21
|
const extensionOptions = (_a = wysiwygConfig.extensionOptions) !== null && _a !== void 0 ? _a : props.extensionOptions;
|
|
20
|
-
builder.use(BundlePreset, Object.assign(Object.assign({}, extensionOptions), {
|
|
22
|
+
builder.use(BundlePreset, Object.assign(Object.assign({}, extensionOptions), { directiveSyntax,
|
|
23
|
+
preset, reactRenderer: renderStorage, onCancel: () => {
|
|
21
24
|
editor.emit('cancel', null);
|
|
22
25
|
return true;
|
|
23
26
|
}, onSubmit: () => {
|
|
@@ -33,7 +36,8 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
return new EditorImpl(Object.assign(Object.assign({}, props), { preset,
|
|
36
|
-
renderStorage,
|
|
39
|
+
renderStorage,
|
|
40
|
+
directiveSyntax, md: Object.assign(Object.assign({}, md), { breaks, html: (_e = md.html) !== null && _e !== void 0 ? _e : props.allowHTML, linkify: (_f = md.linkify) !== null && _f !== void 0 ? _f : props.linkify, linkifyTlds: (_g = md.linkifyTlds) !== null && _g !== void 0 ? _g : props.linkifyTlds }), initial: Object.assign(Object.assign({}, initial), { markup: (_h = initial.markup) !== null && _h !== void 0 ? _h : props.initialMarkup, mode: (_j = initial.mode) !== null && _j !== void 0 ? _j : props.initialEditorMode, toolbarVisible: (_k = initial.toolbarVisible) !== null && _k !== void 0 ? _k : props.initialToolbarVisible, splitModeEnabled: (_l = initial.splitModeEnabled) !== null && _l !== void 0 ? _l : props.initialSplitModeEnabled }), handlers: Object.assign(Object.assign({}, handlers), { uploadFile }), experimental: Object.assign(Object.assign({}, experimental), { needToSetDimensionsForUploadedImages,
|
|
37
41
|
enableNewImageSizeCalculation, prepareRawMarkup: (_m = experimental.prepareRawMarkup) !== null && _m !== void 0 ? _m : props.prepareRawMarkup, beforeEditorModeChange: (_o = experimental.beforeEditorModeChange) !== null && _o !== void 0 ? _o : props.experimental_beforeEditorModeChange }), markupConfig: Object.assign(Object.assign({}, markupConfig), { splitMode: (_p = markupConfig.splitMode) !== null && _p !== void 0 ? _p : props.splitMode, renderPreview: (_q = markupConfig.renderPreview) !== null && _q !== void 0 ? _q : props.renderPreview, extensions: (_r = markupConfig.extensions) !== null && _r !== void 0 ? _r : props.extraMarkupExtensions }), wysiwygConfig: Object.assign(Object.assign({}, wysiwygConfig), { extensions, escapeConfig: (_s = wysiwygConfig.escapeConfig) !== null && _s !== void 0 ? _s : props.escapeConfig }) }));
|
|
38
42
|
}, deps);
|
|
39
43
|
useLayoutEffect(() => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ExtensionAuto } from '../core';
|
|
1
|
+
import type { ExtensionAuto } from '../core';
|
|
2
2
|
import { BehaviorPresetOptions } from '../extensions/behavior';
|
|
3
3
|
import { EditorModeKeymapOptions } from '../extensions/behavior/EditorModeKeymap';
|
|
4
4
|
import { FullPresetOptions } from '../presets/full';
|
|
5
|
+
import type { DirectiveSyntaxContext } from '../utils/directive';
|
|
5
6
|
import type { FileUploadHandler } from '../utils/upload';
|
|
6
|
-
import { MarkdownEditorPreset } from './types';
|
|
7
|
+
import type { MarkdownEditorPreset } from './types';
|
|
7
8
|
export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;
|
|
8
9
|
export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
|
|
9
10
|
preset: MarkdownEditorPreset;
|
|
@@ -16,5 +17,13 @@ export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOp
|
|
|
16
17
|
*/
|
|
17
18
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
18
19
|
enableNewImageSizeCalculation?: boolean;
|
|
20
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
19
21
|
};
|
|
22
|
+
declare global {
|
|
23
|
+
namespace WysiwygEditor {
|
|
24
|
+
interface Context {
|
|
25
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
20
29
|
export declare const BundlePreset: ExtensionAuto<BundlePresetOptions>;
|
|
@@ -13,6 +13,7 @@ import { emojiDefs } from './emoji';
|
|
|
13
13
|
const DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'];
|
|
14
14
|
export const BundlePreset = (builder, opts) => {
|
|
15
15
|
var _a, _b, _c;
|
|
16
|
+
builder.context.set('directiveSyntax', opts.directiveSyntax);
|
|
16
17
|
const dropCursor = {
|
|
17
18
|
color: 'var(--g-color-line-brand)',
|
|
18
19
|
width: 2,
|
|
@@ -3,6 +3,10 @@ export declare enum CutNode {
|
|
|
3
3
|
CutTitle = "yfm_cut_title",
|
|
4
4
|
CutContent = "yfm_cut_content"
|
|
5
5
|
}
|
|
6
|
+
export declare enum CutAttr {
|
|
7
|
+
Class = "class",
|
|
8
|
+
Markup = "data-markup"
|
|
9
|
+
}
|
|
6
10
|
export declare const cutType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
7
11
|
export declare const cutTitleType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
8
12
|
export declare const cutContentType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -5,6 +5,11 @@ export var CutNode;
|
|
|
5
5
|
CutNode["CutTitle"] = "yfm_cut_title";
|
|
6
6
|
CutNode["CutContent"] = "yfm_cut_content";
|
|
7
7
|
})(CutNode || (CutNode = {}));
|
|
8
|
+
export var CutAttr;
|
|
9
|
+
(function (CutAttr) {
|
|
10
|
+
CutAttr["Class"] = "class";
|
|
11
|
+
CutAttr["Markup"] = "data-markup";
|
|
12
|
+
})(CutAttr || (CutAttr = {}));
|
|
8
13
|
export const cutType = nodeTypeFactory(CutNode.Cut);
|
|
9
14
|
export const cutTitleType = nodeTypeFactory(CutNode.CutTitle);
|
|
10
15
|
export const cutContentType = nodeTypeFactory(CutNode.CutContent);
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
|
|
3
|
-
export { CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
3
|
+
export { CutAttr, CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
4
|
+
declare global {
|
|
5
|
+
namespace MarkdownEditor {
|
|
6
|
+
interface DirectiveSyntaxAdditionalSupportedExtensions {
|
|
7
|
+
yfmCut: true;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
export declare type YfmCutSpecsOptions = {
|
|
5
12
|
cutView?: ExtensionNodeSpec['view'];
|
|
6
13
|
cutTitleView?: ExtensionNodeSpec['view'];
|
|
@@ -2,12 +2,17 @@ import { transform as yfmCut } from '@diplodoc/cut-extension';
|
|
|
2
2
|
import { CutNode } from './const';
|
|
3
3
|
import { parserTokens } from './parser';
|
|
4
4
|
import { getSchemaSpecs } from './schema';
|
|
5
|
-
import {
|
|
6
|
-
export { CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
5
|
+
import { getSerializerTokens } from './serializer';
|
|
6
|
+
export { CutAttr, CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
7
7
|
export const YfmCutSpecs = (builder, opts) => {
|
|
8
8
|
const schemaSpecs = getSchemaSpecs(opts, builder.context.get('placeholder'));
|
|
9
|
+
const directiveSyntax = builder.context.get('directiveSyntax');
|
|
10
|
+
const serializerTokens = getSerializerTokens({ directiveSyntax });
|
|
9
11
|
builder
|
|
10
|
-
.configureMd((md) => md.use(yfmCut({
|
|
12
|
+
.configureMd((md) => md.use(yfmCut({
|
|
13
|
+
bundle: false,
|
|
14
|
+
directiveSyntax: directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.mdPluginValueFor('yfmCut'),
|
|
15
|
+
})))
|
|
11
16
|
.addNode(CutNode.Cut, () => ({
|
|
12
17
|
spec: schemaSpecs[CutNode.Cut],
|
|
13
18
|
toMd: serializerTokens[CutNode.Cut],
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { CutNode } from './const';
|
|
2
|
-
const getAttrs = (tok) =>
|
|
1
|
+
import { CutAttr, CutNode } from './const';
|
|
2
|
+
const getAttrs = (tok) => {
|
|
3
|
+
const nodeAttrs = tok.attrs ? Object.fromEntries(tok.attrs) : {};
|
|
4
|
+
nodeAttrs[CutAttr.Markup] = tok.markup;
|
|
5
|
+
return nodeAttrs;
|
|
6
|
+
};
|
|
3
7
|
export const parserTokens = {
|
|
4
8
|
[CutNode.Cut]: { name: CutNode.Cut, type: 'block', getAttrs },
|
|
5
9
|
[CutNode.CutTitle]: { name: CutNode.CutTitle, type: 'block' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
3
|
-
import { CutNode } from '
|
|
3
|
+
import { CutNode } from './const';
|
|
4
4
|
import type { YfmCutSpecsOptions } from './index';
|
|
5
5
|
export declare const getSchemaSpecs: (opts?: YfmCutSpecsOptions, placeholder?: PlaceholderOptions) => Record<CutNode, NodeSpec>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CutNode } from '
|
|
1
|
+
import { CutAttr, CutNode } from './const';
|
|
2
2
|
const DEFAULT_PLACEHOLDERS = {
|
|
3
3
|
Title: 'Cut title',
|
|
4
4
|
Content: 'Cut content',
|
|
@@ -7,10 +7,15 @@ export const getSchemaSpecs = (opts, placeholder) => {
|
|
|
7
7
|
var _a, _b, _c, _d;
|
|
8
8
|
return ({
|
|
9
9
|
[CutNode.Cut]: {
|
|
10
|
-
attrs: { class: { default: 'yfm-cut' } },
|
|
10
|
+
attrs: { class: { default: 'yfm-cut' }, [CutAttr.Markup]: { default: null } },
|
|
11
11
|
content: `${CutNode.CutTitle} ${CutNode.CutContent}`,
|
|
12
12
|
group: 'block yfm-cut',
|
|
13
|
-
parseDOM: [
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: '.yfm-cut',
|
|
16
|
+
getAttrs: (node) => ({ [CutAttr.Markup]: node.getAttribute(CutAttr.Markup) }),
|
|
17
|
+
},
|
|
18
|
+
],
|
|
14
19
|
toDOM(node) {
|
|
15
20
|
return ['div', node.attrs, 0];
|
|
16
21
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { SerializerNodeToken } from '../../../../core';
|
|
2
2
|
import { CutNode } from './const';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function getSerializerTokens({ directiveSyntax, }: {
|
|
4
|
+
directiveSyntax?: WysiwygEditor.Context['directiveSyntax'];
|
|
5
|
+
}): Record<CutNode, SerializerNodeToken>;
|