@gravity-ui/markdown-editor 14.8.0 → 14.10.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 +16 -14
- package/build/cjs/bundle/Editor.d.ts +2 -0
- package/build/cjs/bundle/Editor.js +15 -4
- package/build/cjs/bundle/MarkdownEditorView.d.ts +27 -0
- package/build/cjs/bundle/MarkdownEditorView.js +19 -2
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/config/action-names.js +51 -27
- package/build/cjs/bundle/config/index.d.ts +3 -0
- package/build/cjs/bundle/config/index.js +3 -0
- package/build/cjs/bundle/config/markup.js +3 -0
- package/build/cjs/bundle/config/wysiwyg.d.ts +3 -0
- package/build/cjs/bundle/toolbar/utils/flattenPreset.d.ts +2 -0
- package/build/cjs/bundle/toolbar/utils/flattenPreset.js +14 -0
- package/build/cjs/bundle/toolbar/utils/toolbarsConfigs.d.ts +17 -0
- package/build/cjs/bundle/toolbar/utils/toolbarsConfigs.js +60 -0
- package/build/cjs/bundle/types.d.ts +6 -0
- package/build/cjs/bundle/useMarkdownEditor.js +8 -2
- package/build/cjs/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/cjs/bundle/wysiwyg-preset.js +1 -1
- package/build/cjs/core/Editor.d.ts +3 -1
- package/build/cjs/core/Editor.js +2 -1
- package/build/cjs/core/ExtensionsManager.d.ts +2 -0
- package/build/cjs/core/ExtensionsManager.js +8 -4
- package/build/cjs/core/ParserTokensRegistry.d.ts +2 -1
- package/build/cjs/core/ParserTokensRegistry.js +2 -2
- package/build/cjs/core/markdown/MarkdownParser.d.ts +3 -1
- package/build/cjs/core/markdown/MarkdownParser.js +5 -2
- package/build/cjs/core/markdown/MarkdownSerializer.js +1 -1
- package/build/cjs/core/markdown/ProseMirrorTransformer/emptyRowTransformer.d.ts +2 -0
- package/build/cjs/core/markdown/ProseMirrorTransformer/emptyRowTransformer.js +15 -0
- package/build/cjs/core/markdown/ProseMirrorTransformer/getTransformers.d.ts +7 -0
- package/build/cjs/core/markdown/ProseMirrorTransformer/getTransformers.js +13 -0
- package/build/cjs/core/markdown/ProseMirrorTransformer/index.d.ts +15 -0
- package/build/cjs/core/markdown/ProseMirrorTransformer/index.js +25 -0
- package/build/cjs/extensions/additional/Math/MathSpecs/index.js +1 -0
- package/build/cjs/extensions/base/BaseSchema/BaseSchemaSpecs/index.d.ts +1 -0
- package/build/cjs/extensions/base/BaseSchema/BaseSchemaSpecs/index.js +23 -3
- package/build/cjs/extensions/behavior/Selection/selection.js +1 -5
- package/build/cjs/extensions/markdown/Blockquote/BlockquoteSpecs/index.js +1 -0
- package/build/cjs/extensions/markdown/CodeBlock/commands.js +1 -1
- package/build/cjs/extensions/markdown/HorizontalRule/HorizontalRuleSpecs/index.js +1 -0
- package/build/cjs/extensions/markdown/Link/paste-plugin.js +21 -5
- package/build/cjs/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js +1 -0
- package/build/cjs/i18n/empty-row/en.json +3 -0
- package/build/cjs/i18n/empty-row/index.d.ts +5 -0
- package/build/cjs/i18n/empty-row/index.js +9 -0
- package/build/cjs/i18n/empty-row/ru.json +3 -0
- package/build/cjs/i18n/menubar/en.json +1 -0
- package/build/cjs/i18n/menubar/index.d.ts +2 -1
- package/build/cjs/i18n/menubar/ru.json +1 -0
- package/build/cjs/i18n/yfm-note/index.d.ts +1 -1
- package/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/markup/codemirror/autocomplete/emptyRow.d.ts +9 -0
- package/build/cjs/markup/codemirror/autocomplete/emptyRow.js +26 -0
- package/build/cjs/markup/codemirror/autocomplete/index.d.ts +5 -0
- package/build/cjs/markup/codemirror/autocomplete/index.js +14 -0
- package/build/cjs/markup/codemirror/create.d.ts +1 -0
- package/build/cjs/markup/codemirror/create.js +30 -12
- package/build/cjs/markup/codemirror/smart-reindent/index.d.ts +4 -0
- package/build/cjs/markup/codemirror/smart-reindent/index.js +42 -0
- package/build/cjs/markup/codemirror/smart-reindent/utils.d.ts +15 -0
- package/build/cjs/markup/codemirror/smart-reindent/utils.js +59 -0
- package/build/cjs/markup/codemirror/yfm.d.ts +2 -1
- package/build/cjs/markup/codemirror/yfm.js +3 -3
- package/build/cjs/markup/commands/emptyRow.d.ts +2 -0
- package/build/cjs/markup/commands/emptyRow.js +43 -0
- package/build/cjs/markup/commands/index.d.ts +1 -0
- package/build/cjs/markup/commands/index.js +1 -0
- package/build/cjs/modules/toolbars/constants.d.ts +13 -0
- package/build/cjs/modules/toolbars/constants.js +18 -0
- package/build/cjs/modules/toolbars/items.d.ts +127 -0
- package/build/cjs/modules/toolbars/items.js +736 -0
- package/build/cjs/modules/toolbars/presets.d.ts +6 -0
- package/build/cjs/modules/toolbars/presets.js +465 -0
- package/build/cjs/modules/toolbars/types.d.ts +62 -0
- package/build/cjs/modules/toolbars/types.js +2 -0
- package/build/cjs/shortcuts/const.d.ts +1 -0
- package/build/cjs/shortcuts/const.js +1 -0
- package/build/cjs/shortcuts/default.js +1 -0
- package/build/cjs/toolbar/types.d.ts +8 -0
- package/build/cjs/toolbar/types.js +2 -0
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.d.ts +2 -0
- package/build/esm/bundle/Editor.js +15 -4
- package/build/esm/bundle/MarkdownEditorView.d.ts +27 -0
- package/build/esm/bundle/MarkdownEditorView.js +19 -2
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/config/action-names.js +51 -27
- package/build/esm/bundle/config/index.d.ts +3 -0
- package/build/esm/bundle/config/index.js +3 -0
- package/build/esm/bundle/config/markup.js +3 -0
- package/build/esm/bundle/config/wysiwyg.d.ts +3 -0
- package/build/esm/bundle/toolbar/utils/flattenPreset.d.ts +2 -0
- package/build/esm/bundle/toolbar/utils/flattenPreset.js +10 -0
- package/build/esm/bundle/toolbar/utils/toolbarsConfigs.d.ts +17 -0
- package/build/esm/bundle/toolbar/utils/toolbarsConfigs.js +55 -0
- package/build/esm/bundle/types.d.ts +6 -0
- package/build/esm/bundle/useMarkdownEditor.js +8 -2
- package/build/esm/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/esm/bundle/wysiwyg-preset.js +1 -1
- package/build/esm/core/Editor.d.ts +3 -1
- package/build/esm/core/Editor.js +2 -1
- package/build/esm/core/ExtensionsManager.d.ts +2 -0
- package/build/esm/core/ExtensionsManager.js +8 -4
- package/build/esm/core/ParserTokensRegistry.d.ts +2 -1
- package/build/esm/core/ParserTokensRegistry.js +2 -2
- package/build/esm/core/markdown/MarkdownParser.d.ts +3 -1
- package/build/esm/core/markdown/MarkdownParser.js +5 -2
- package/build/esm/core/markdown/MarkdownSerializer.js +1 -1
- package/build/esm/core/markdown/ProseMirrorTransformer/emptyRowTransformer.d.ts +2 -0
- package/build/esm/core/markdown/ProseMirrorTransformer/emptyRowTransformer.js +11 -0
- package/build/esm/core/markdown/ProseMirrorTransformer/getTransformers.d.ts +7 -0
- package/build/esm/core/markdown/ProseMirrorTransformer/getTransformers.js +9 -0
- package/build/esm/core/markdown/ProseMirrorTransformer/index.d.ts +15 -0
- package/build/esm/core/markdown/ProseMirrorTransformer/index.js +21 -0
- package/build/esm/extensions/additional/Math/MathSpecs/index.js +1 -0
- package/build/esm/extensions/base/BaseSchema/BaseSchemaSpecs/index.d.ts +1 -0
- package/build/esm/extensions/base/BaseSchema/BaseSchemaSpecs/index.js +23 -3
- package/build/esm/extensions/behavior/Selection/selection.js +1 -5
- package/build/esm/extensions/markdown/Blockquote/BlockquoteSpecs/index.js +1 -0
- package/build/esm/extensions/markdown/CodeBlock/commands.js +1 -1
- package/build/esm/extensions/markdown/HorizontalRule/HorizontalRuleSpecs/index.js +1 -0
- package/build/esm/extensions/markdown/Link/paste-plugin.js +21 -5
- package/build/esm/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js +1 -0
- package/build/esm/i18n/empty-row/en.json +3 -0
- package/build/esm/i18n/empty-row/index.d.ts +5 -0
- package/build/esm/i18n/empty-row/index.js +5 -0
- package/build/esm/i18n/empty-row/ru.json +3 -0
- package/build/esm/i18n/menubar/en.json +1 -0
- package/build/esm/i18n/menubar/index.d.ts +2 -1
- package/build/esm/i18n/menubar/ru.json +1 -0
- package/build/esm/i18n/yfm-note/index.d.ts +1 -1
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/markup/codemirror/autocomplete/emptyRow.d.ts +9 -0
- package/build/esm/markup/codemirror/autocomplete/emptyRow.js +23 -0
- package/build/esm/markup/codemirror/autocomplete/index.d.ts +5 -0
- package/build/esm/markup/codemirror/autocomplete/index.js +10 -0
- package/build/esm/markup/codemirror/create.d.ts +1 -0
- package/build/esm/markup/codemirror/create.js +31 -13
- package/build/esm/markup/codemirror/smart-reindent/index.d.ts +4 -0
- package/build/esm/markup/codemirror/smart-reindent/index.js +38 -0
- package/build/esm/markup/codemirror/smart-reindent/utils.d.ts +15 -0
- package/build/esm/markup/codemirror/smart-reindent/utils.js +55 -0
- package/build/esm/markup/codemirror/yfm.d.ts +2 -1
- package/build/esm/markup/codemirror/yfm.js +1 -1
- package/build/esm/markup/commands/emptyRow.d.ts +2 -0
- package/build/esm/markup/commands/emptyRow.js +39 -0
- package/build/esm/markup/commands/index.d.ts +1 -0
- package/build/esm/markup/commands/index.js +1 -0
- package/build/esm/modules/toolbars/constants.d.ts +13 -0
- package/build/esm/modules/toolbars/constants.js +15 -0
- package/build/esm/modules/toolbars/items.d.ts +127 -0
- package/build/esm/modules/toolbars/items.js +730 -0
- package/build/esm/modules/toolbars/presets.d.ts +6 -0
- package/build/esm/modules/toolbars/presets.js +462 -0
- package/build/esm/modules/toolbars/types.d.ts +62 -0
- package/build/esm/modules/toolbars/types.js +1 -0
- package/build/esm/shortcuts/const.d.ts +1 -0
- package/build/esm/shortcuts/const.js +1 -0
- package/build/esm/shortcuts/default.js +1 -0
- package/build/esm/toolbar/types.d.ts +8 -0
- package/build/esm/toolbar/types.js +2 -0
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
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;
|
|
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_pmTransformers, _EditorImpl_preserveEmptyRows, _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';
|
|
5
|
+
import { getAutocompleteConfig } from '../../src/markup/codemirror/autocomplete';
|
|
5
6
|
import { WysiwygEditor, } from '../core';
|
|
6
7
|
import { i18n } from '../i18n/bundle';
|
|
7
8
|
import { logger } from '../logger';
|
|
@@ -24,6 +25,8 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
24
25
|
_EditorImpl_markupConfig.set(this, void 0);
|
|
25
26
|
_EditorImpl_escapeConfig.set(this, void 0);
|
|
26
27
|
_EditorImpl_mdOptions.set(this, void 0);
|
|
28
|
+
_EditorImpl_pmTransformers.set(this, []);
|
|
29
|
+
_EditorImpl_preserveEmptyRows.set(this, void 0);
|
|
27
30
|
_EditorImpl_preset.set(this, void 0);
|
|
28
31
|
_EditorImpl_extensions.set(this, void 0);
|
|
29
32
|
_EditorImpl_renderStorage.set(this, void 0);
|
|
@@ -43,6 +46,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
43
46
|
__classPrivateFieldSet(this, _EditorImpl_renderPreview, markupConfig.renderPreview, "f");
|
|
44
47
|
__classPrivateFieldSet(this, _EditorImpl_markup, (_e = initial.markup) !== null && _e !== void 0 ? _e : '', "f");
|
|
45
48
|
__classPrivateFieldSet(this, _EditorImpl_preset, (_f = opts.preset) !== null && _f !== void 0 ? _f : 'full', "f");
|
|
49
|
+
__classPrivateFieldSet(this, _EditorImpl_pmTransformers, opts.pmTransformers, "f");
|
|
46
50
|
__classPrivateFieldSet(this, _EditorImpl_mdOptions, md, "f");
|
|
47
51
|
__classPrivateFieldSet(this, _EditorImpl_extensions, wysiwygConfig.extensions, "f");
|
|
48
52
|
__classPrivateFieldSet(this, _EditorImpl_markupConfig, Object.assign({}, opts.markupConfig), "f");
|
|
@@ -52,6 +56,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
52
56
|
__classPrivateFieldSet(this, _EditorImpl_needToSetDimensionsForUploadedImages, Boolean(experimental.needToSetDimensionsForUploadedImages), "f");
|
|
53
57
|
__classPrivateFieldSet(this, _EditorImpl_directiveSyntax, opts.directiveSyntax, "f");
|
|
54
58
|
__classPrivateFieldSet(this, _EditorImpl_enableNewImageSizeCalculation, Boolean(experimental.enableNewImageSizeCalculation), "f");
|
|
59
|
+
__classPrivateFieldSet(this, _EditorImpl_preserveEmptyRows, experimental.preserveEmptyRows || false, "f");
|
|
55
60
|
__classPrivateFieldSet(this, _EditorImpl_prepareRawMarkup, experimental.prepareRawMarkup, "f");
|
|
56
61
|
__classPrivateFieldSet(this, _EditorImpl_escapeConfig, wysiwygConfig.escapeConfig, "f");
|
|
57
62
|
__classPrivateFieldSet(this, _EditorImpl_beforeEditorModeChange, experimental.beforeEditorModeChange, "f");
|
|
@@ -143,6 +148,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
143
148
|
mdPreset,
|
|
144
149
|
initialContent: __classPrivateFieldGet(this, _EditorImpl_markup, "f"),
|
|
145
150
|
extensions: __classPrivateFieldGet(this, _EditorImpl_extensions, "f"),
|
|
151
|
+
pmTransformers: __classPrivateFieldGet(this, _EditorImpl_pmTransformers, "f"),
|
|
146
152
|
allowHTML: __classPrivateFieldGet(this, _EditorImpl_mdOptions, "f").html,
|
|
147
153
|
linkify: __classPrivateFieldGet(this, _EditorImpl_mdOptions, "f").linkify,
|
|
148
154
|
linkifyTlds: __classPrivateFieldGet(this, _EditorImpl_mdOptions, "f").linkifyTlds,
|
|
@@ -154,7 +160,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
154
160
|
return __classPrivateFieldGet(this, _EditorImpl_wysiwygEditor, "f");
|
|
155
161
|
}
|
|
156
162
|
get markupEditor() {
|
|
157
|
-
var _a;
|
|
163
|
+
var _a, _b;
|
|
158
164
|
if (!__classPrivateFieldGet(this, _EditorImpl_markupEditor, "f")) {
|
|
159
165
|
__classPrivateFieldSet(this, _EditorImpl_markupEditor, new MarkupEditor(createCodemirror({
|
|
160
166
|
doc: __classPrivateFieldGet(this, _EditorImpl_markup, "f"),
|
|
@@ -173,7 +179,12 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
173
179
|
extensions: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").extensions,
|
|
174
180
|
disabledExtensions: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").disabledExtensions,
|
|
175
181
|
keymaps: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").keymaps,
|
|
176
|
-
|
|
182
|
+
preserveEmptyRows: __classPrivateFieldGet(this, _EditorImpl_preserveEmptyRows, "f"),
|
|
183
|
+
yfmLangOptions: {
|
|
184
|
+
languageData: getAutocompleteConfig({
|
|
185
|
+
preserveEmptyRows: __classPrivateFieldGet(this, _EditorImpl_preserveEmptyRows, "f"),
|
|
186
|
+
}).concat(((_b = __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f")) === null || _b === void 0 ? void 0 : _b.languageData) || []),
|
|
187
|
+
},
|
|
177
188
|
autocompletion: __classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").autocompletion,
|
|
178
189
|
directiveSyntax: this.directiveSyntax,
|
|
179
190
|
receiver: this,
|
|
@@ -315,7 +326,7 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
315
326
|
return (serializedEditorMarkup === null || serializedEditorMarkup === void 0 ? void 0 : serializedEditorMarkup.trim()) !== wysiwygValue.trim();
|
|
316
327
|
}
|
|
317
328
|
}
|
|
318
|
-
_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();
|
|
329
|
+
_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_pmTransformers = new WeakMap(), _EditorImpl_preserveEmptyRows = 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();
|
|
319
330
|
function getTopOffset(elem) {
|
|
320
331
|
const TOOLBAR_HEIGHT = 36; //px
|
|
321
332
|
const TOOLBAR_BOTTOM_OFFSET = 8; // px
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ToasterPublicMethods } from '@gravity-ui/uikit';
|
|
3
3
|
import { ClassNameProps } from '../classname';
|
|
4
|
+
import type { ToolbarsPreset } from '../modules/toolbars/types';
|
|
4
5
|
import type { Editor } from './Editor';
|
|
5
6
|
import { MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData } from './config';
|
|
6
7
|
import '../styles/styles.css';
|
|
@@ -9,9 +10,22 @@ export declare const cnEditorComponent: import("@bem-react/classname").ClassName
|
|
|
9
10
|
export declare type MarkdownEditorViewProps = ClassNameProps & {
|
|
10
11
|
editor?: Editor;
|
|
11
12
|
autofocus?: boolean;
|
|
13
|
+
toolbarsPreset?: ToolbarsPreset;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated use `toolbarsPreset` instead
|
|
16
|
+
*/
|
|
12
17
|
markupToolbarConfig?: MToolbarData;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use `toolbarsPreset` instead
|
|
20
|
+
*/
|
|
13
21
|
wysiwygToolbarConfig?: WToolbarData;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use `toolbarsPreset` instead
|
|
24
|
+
*/
|
|
14
25
|
markupHiddenActionsConfig?: MToolbarItemData[];
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use `toolbarsPreset` instead
|
|
28
|
+
*/
|
|
15
29
|
wysiwygHiddenActionsConfig?: WToolbarItemData[];
|
|
16
30
|
/** @default true */
|
|
17
31
|
settingsVisible?: boolean;
|
|
@@ -23,9 +37,22 @@ export declare type MarkdownEditorViewProps = ClassNameProps & {
|
|
|
23
37
|
export declare const MarkdownEditorView: React.ForwardRefExoticComponent<ClassNameProps & {
|
|
24
38
|
editor?: Editor | undefined;
|
|
25
39
|
autofocus?: boolean | undefined;
|
|
40
|
+
toolbarsPreset?: ToolbarsPreset | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated use `toolbarsPreset` instead
|
|
43
|
+
*/
|
|
26
44
|
markupToolbarConfig?: MToolbarData | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use `toolbarsPreset` instead
|
|
47
|
+
*/
|
|
27
48
|
wysiwygToolbarConfig?: WToolbarData | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use `toolbarsPreset` instead
|
|
51
|
+
*/
|
|
28
52
|
markupHiddenActionsConfig?: MToolbarItemData[] | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use `toolbarsPreset` instead
|
|
55
|
+
*/
|
|
29
56
|
wysiwygHiddenActionsConfig?: WToolbarItemData[] | undefined;
|
|
30
57
|
/** @default true */
|
|
31
58
|
settingsVisible?: boolean | undefined;
|
|
@@ -10,10 +10,10 @@ import { HorizontalDrag } from './HorizontalDrag';
|
|
|
10
10
|
import { MarkupEditorView } from './MarkupEditorView';
|
|
11
11
|
import { SplitModeView } from './SplitModeView';
|
|
12
12
|
import { WysiwygEditorView } from './WysiwygEditorView';
|
|
13
|
-
import { mHiddenDataByPreset, mToolbarConfigByPreset, wHiddenDataByPreset, wToolbarConfigByPreset, } from './config';
|
|
14
13
|
import { useMarkdownEditorContext } from './context';
|
|
15
14
|
import { EditorSettings } from './settings';
|
|
16
15
|
import { stickyCn } from './sticky';
|
|
16
|
+
import { getToolbarsConfigs } from './toolbar/utils/toolbarsConfigs';
|
|
17
17
|
import '../styles/styles.css';
|
|
18
18
|
import './MarkdownEditorView.css'; // eslint-disable-line import/order
|
|
19
19
|
export const cnEditorComponent = cn('editor-component');
|
|
@@ -30,7 +30,24 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
30
30
|
const editor = ((_a = props.editor) !== null && _a !== void 0 ? _a : context);
|
|
31
31
|
if (!editor)
|
|
32
32
|
throw new Error('[MarkdownEditorView]: an instance of the editor must be passed through the props or context');
|
|
33
|
-
const { autofocus, className, settingsVisible = true,
|
|
33
|
+
const { autofocus, className, settingsVisible = true, toolbarsPreset, toaster, stickyToolbar, wysiwygToolbarConfig: initialWysiwygToolbarConfig, markupToolbarConfig: initialMarkupToolbarConfig, wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig, markupHiddenActionsConfig: initialMarkupHiddenActionsConfig, enableSubmitInPreview = true, hidePreviewAfterSubmit = false, } = props;
|
|
34
|
+
const { wysiwygToolbarConfig, markupToolbarConfig, wysiwygHiddenActionsConfig, markupHiddenActionsConfig, } = useMemo(() => getToolbarsConfigs({
|
|
35
|
+
toolbarsPreset,
|
|
36
|
+
props: {
|
|
37
|
+
wysiwygToolbarConfig: initialWysiwygToolbarConfig,
|
|
38
|
+
markupToolbarConfig: initialMarkupToolbarConfig,
|
|
39
|
+
wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,
|
|
40
|
+
markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,
|
|
41
|
+
},
|
|
42
|
+
preset: editor.preset,
|
|
43
|
+
}), [
|
|
44
|
+
toolbarsPreset,
|
|
45
|
+
initialWysiwygToolbarConfig,
|
|
46
|
+
initialMarkupToolbarConfig,
|
|
47
|
+
initialWysiwygHiddenActionsConfig,
|
|
48
|
+
initialMarkupHiddenActionsConfig,
|
|
49
|
+
editor.preset,
|
|
50
|
+
]);
|
|
34
51
|
const rerender = useUpdate();
|
|
35
52
|
React.useLayoutEffect(() => {
|
|
36
53
|
editor.on('rerender', rerender);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const namesObj: Record<"bold" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "paragraph" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "file" | "checkbox" | "emoji" | "
|
|
1
|
+
declare const namesObj: Record<"bold" | "colorify" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "block" | "paragraph" | "cut" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "note" | "file" | "codeBlock" | "checkbox" | "emoji" | "bulletList" | "codeInline" | "filePopup" | "gpt" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "emptyRow" | "horizontalrule" | "horizontalRule" | "imagePopup" | "liftListItem" | "math_block" | "mathBlock" | "math_inline" | "mathInline" | "mermaid" | "orderedList" | "redo" | "sinkListItem" | "tabs" | "undo" | "yfm_block" | "yfm_cut" | "yfm_html_block" | "htmlBlock" | "yfm_layout" | "layout" | "yfm_note", string>;
|
|
2
2
|
export declare const ActionName: Readonly<typeof namesObj>;
|
|
3
3
|
export {};
|
|
@@ -1,44 +1,68 @@
|
|
|
1
1
|
const names = [
|
|
2
|
-
'
|
|
3
|
-
'redo',
|
|
2
|
+
'anchor',
|
|
4
3
|
'bold',
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
|
|
4
|
+
'bulletList',
|
|
5
|
+
'checkbox',
|
|
6
|
+
/** @deprecated use codeBlock */
|
|
7
|
+
'code_block',
|
|
8
|
+
'codeBlock',
|
|
9
|
+
/** @deprecated use codeInline */
|
|
10
|
+
'code_inline',
|
|
11
|
+
'codeInline',
|
|
12
|
+
'colorify',
|
|
13
|
+
'emoji',
|
|
14
|
+
'file',
|
|
15
|
+
'filePopup',
|
|
16
|
+
'gpt',
|
|
11
17
|
'heading1',
|
|
12
18
|
'heading2',
|
|
13
19
|
'heading3',
|
|
14
20
|
'heading4',
|
|
15
21
|
'heading5',
|
|
16
22
|
'heading6',
|
|
17
|
-
'
|
|
18
|
-
|
|
23
|
+
'emptyRow',
|
|
24
|
+
/** @deprecated use horizontalRule */
|
|
25
|
+
'horizontalrule',
|
|
26
|
+
'horizontalRule',
|
|
27
|
+
'image',
|
|
28
|
+
'imagePopup',
|
|
29
|
+
'italic',
|
|
19
30
|
'liftListItem',
|
|
20
|
-
'sinkListItem',
|
|
21
|
-
'checkbox',
|
|
22
31
|
'link',
|
|
32
|
+
'mark',
|
|
33
|
+
/** @deprecated use mathBlock */
|
|
34
|
+
'math_block',
|
|
35
|
+
'mathBlock',
|
|
36
|
+
/** @deprecated use mathInline */
|
|
37
|
+
'math_inline',
|
|
38
|
+
'mathInline',
|
|
39
|
+
'mermaid',
|
|
40
|
+
'mono',
|
|
41
|
+
'orderedList',
|
|
42
|
+
'paragraph',
|
|
23
43
|
'quote',
|
|
24
|
-
'
|
|
25
|
-
'
|
|
44
|
+
'redo',
|
|
45
|
+
'sinkListItem',
|
|
46
|
+
'strike',
|
|
47
|
+
'table',
|
|
48
|
+
'tabs',
|
|
49
|
+
'underline',
|
|
50
|
+
'undo',
|
|
51
|
+
/** @deprecated use block */
|
|
26
52
|
'yfm_block',
|
|
53
|
+
'block',
|
|
54
|
+
/** @deprecated use cut */
|
|
55
|
+
'yfm_cut',
|
|
56
|
+
'cut',
|
|
57
|
+
/** @deprecated use htmlBlock */
|
|
27
58
|
'yfm_html_block',
|
|
59
|
+
'htmlBlock',
|
|
60
|
+
/** @deprecated use layout */
|
|
28
61
|
'yfm_layout',
|
|
29
|
-
'
|
|
30
|
-
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'horizontalrule',
|
|
34
|
-
'emoji',
|
|
35
|
-
'file',
|
|
36
|
-
'anchor',
|
|
37
|
-
'math_inline',
|
|
38
|
-
'math_block',
|
|
39
|
-
'tabs',
|
|
40
|
-
'mermaid',
|
|
41
|
-
'gpt',
|
|
62
|
+
'layout',
|
|
63
|
+
/** @deprecated use note */
|
|
64
|
+
'yfm_note',
|
|
65
|
+
'note',
|
|
42
66
|
];
|
|
43
67
|
const namesObj = names.reduce((obj, val) => {
|
|
44
68
|
obj[val] = val;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This file is deprecated. Use ToolbarsPreset instead.
|
|
3
|
+
*/
|
|
1
4
|
import React from 'react';
|
|
2
5
|
import { i18n } from '../../i18n/menubar';
|
|
3
6
|
import { insertHRule, insertLink, insertMermaidDiagram, insertYfmHtmlBlock, insertYfmTable, insertYfmTabs, liftListItem, redo, redoDepth, sinkListItem, toBulletList, toH1, toH2, toH3, toH4, toH5, toH6, toOrderedList, toggleBold, toggleItalic, toggleMarked, toggleMonospace, toggleStrikethrough, toggleUnderline, undo, undoDepth, wrapToBlockquote, wrapToCheckbox, wrapToCodeBlock, wrapToInlineCode, wrapToMathBlock, wrapToMathInline, wrapToYfmCut, wrapToYfmNote, } from '../../markup/commands';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This file is deprecated. Use ToolbarsPreset instead.
|
|
3
|
+
*/
|
|
1
4
|
import { ActionStorage } from 'src/core';
|
|
2
5
|
import type { SelectionContextConfig, SelectionContextItemData } from '../../extensions/behavior/SelectionContext';
|
|
3
6
|
import { ToolbarGroupItemData, ToolbarItemData, ToolbarListButtonItemData, ToolbarListItemData, ToolbarSingleItemData } from '../../toolbar';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToolbarDataType } from '../../../toolbar/types';
|
|
2
|
+
export const flattenPreset = (config) => {
|
|
3
|
+
return config.flat().reduce((acc, item) => {
|
|
4
|
+
if (item.type === ToolbarDataType.ListButton && Array.isArray(item.data)) {
|
|
5
|
+
return acc.concat(item.data);
|
|
6
|
+
}
|
|
7
|
+
acc.push(item);
|
|
8
|
+
return acc;
|
|
9
|
+
}, []);
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ToolbarsPreset } from '../../../modules/toolbars/types';
|
|
2
|
+
import type { MToolbarData, WToolbarData } from '../../../toolbar';
|
|
3
|
+
import type { MarkdownEditorViewProps } from '../../MarkdownEditorView';
|
|
4
|
+
import { MarkdownEditorPreset } from '../../types';
|
|
5
|
+
export declare const createToolbarConfig: <T extends MToolbarData | WToolbarData>(editorType: 'wysiwyg' | 'markup', toolbarPreset: ToolbarsPreset | MarkdownEditorPreset, toolbarName: string) => T;
|
|
6
|
+
interface GetToolbarsConfigsArgs {
|
|
7
|
+
toolbarsPreset?: ToolbarsPreset;
|
|
8
|
+
props: Pick<MarkdownEditorViewProps, 'markupToolbarConfig' | 'wysiwygToolbarConfig' | 'wysiwygHiddenActionsConfig' | 'markupHiddenActionsConfig'>;
|
|
9
|
+
preset: MarkdownEditorPreset;
|
|
10
|
+
}
|
|
11
|
+
export declare const getToolbarsConfigs: ({ toolbarsPreset, props, preset }: GetToolbarsConfigsArgs) => {
|
|
12
|
+
wysiwygToolbarConfig: WToolbarData;
|
|
13
|
+
markupToolbarConfig: MToolbarData;
|
|
14
|
+
wysiwygHiddenActionsConfig: import("../../config/wysiwyg").WToolbarItemData[];
|
|
15
|
+
markupHiddenActionsConfig: import("../../config/markup").MToolbarItemData[];
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ToolbarName } from '../../../modules/toolbars/constants';
|
|
2
|
+
import { commonmark, defaultPreset, full, yfm, zero } from '../../../modules/toolbars/presets';
|
|
3
|
+
import { ToolbarDataType } from '../../../toolbar';
|
|
4
|
+
import { flattenPreset } from './flattenPreset';
|
|
5
|
+
const defaultPresets = {
|
|
6
|
+
zero,
|
|
7
|
+
commonmark,
|
|
8
|
+
default: defaultPreset,
|
|
9
|
+
yfm,
|
|
10
|
+
full,
|
|
11
|
+
};
|
|
12
|
+
const transformItem = (type, item, id = 'unknown') => {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!item) {
|
|
15
|
+
console.warn(`Toolbar item "${id}" not found, it might not have been added to the items dictionary.`);
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const isListButton = item.view.type === ToolbarDataType.ListButton;
|
|
19
|
+
return Object.assign(Object.assign(Object.assign({ type: (_a = item.view.type) !== null && _a !== void 0 ? _a : ToolbarDataType.SingleButton, id, title: item.view.title, hint: item.view.hint, icon: item.view.icon, hotkey: item.view.hotkey }, (isListButton && { withArrow: item.view.withArrow })), (type === 'wysiwyg' && item.wysiwyg && Object.assign({}, item.wysiwyg))), (type === 'markup' && item.markup && Object.assign({}, item.markup)));
|
|
20
|
+
};
|
|
21
|
+
export const createToolbarConfig = (editorType, toolbarPreset, toolbarName) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const preset = typeof toolbarPreset === 'string'
|
|
24
|
+
? defaultPresets[toolbarPreset] || defaultPresets.default
|
|
25
|
+
: toolbarPreset;
|
|
26
|
+
const orders = (_a = preset.orders[toolbarName]) !== null && _a !== void 0 ? _a : [[]];
|
|
27
|
+
const { items } = preset;
|
|
28
|
+
const toolbarData = orders.map((group) => group.map((action) => {
|
|
29
|
+
return typeof action === 'string'
|
|
30
|
+
? transformItem(editorType, items[action], action)
|
|
31
|
+
: Object.assign(Object.assign({}, transformItem(editorType, items[action.id], action.id)), { data: action.items.map((id) => transformItem(editorType, items[id], id)) });
|
|
32
|
+
}));
|
|
33
|
+
return toolbarData;
|
|
34
|
+
};
|
|
35
|
+
export const getToolbarsConfigs = ({ toolbarsPreset, props, preset }) => {
|
|
36
|
+
var _a, _b, _c, _d;
|
|
37
|
+
const wysiwygToolbarConfig = toolbarsPreset
|
|
38
|
+
? createToolbarConfig('wysiwyg', toolbarsPreset, ToolbarName.wysiwygMain)
|
|
39
|
+
: (_a = props.wysiwygToolbarConfig) !== null && _a !== void 0 ? _a : createToolbarConfig('wysiwyg', preset, ToolbarName.wysiwygMain);
|
|
40
|
+
const markupToolbarConfig = toolbarsPreset
|
|
41
|
+
? createToolbarConfig('markup', toolbarsPreset, ToolbarName.markupMain)
|
|
42
|
+
: (_b = props.markupToolbarConfig) !== null && _b !== void 0 ? _b : createToolbarConfig('markup', preset, ToolbarName.markupMain);
|
|
43
|
+
const wysiwygHiddenActionsConfig = toolbarsPreset
|
|
44
|
+
? flattenPreset(createToolbarConfig('wysiwyg', toolbarsPreset, ToolbarName.wysiwygHidden))
|
|
45
|
+
: (_c = props.wysiwygHiddenActionsConfig) !== null && _c !== void 0 ? _c : flattenPreset(createToolbarConfig('wysiwyg', preset, ToolbarName.wysiwygHidden));
|
|
46
|
+
const markupHiddenActionsConfig = toolbarsPreset
|
|
47
|
+
? flattenPreset(createToolbarConfig('markup', toolbarsPreset, ToolbarName.markupHidden))
|
|
48
|
+
: (_d = props.markupHiddenActionsConfig) !== null && _d !== void 0 ? _d : flattenPreset(createToolbarConfig('markup', preset, ToolbarName.markupHidden));
|
|
49
|
+
return {
|
|
50
|
+
wysiwygToolbarConfig,
|
|
51
|
+
markupToolbarConfig,
|
|
52
|
+
wysiwygHiddenActionsConfig,
|
|
53
|
+
markupHiddenActionsConfig,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -93,6 +93,12 @@ export declare type MarkdownEditorExperimentalOptions = {
|
|
|
93
93
|
* Default value is 'disabled'.
|
|
94
94
|
*/
|
|
95
95
|
directiveSyntax?: DirectiveSyntaxOption;
|
|
96
|
+
/**
|
|
97
|
+
* If we need support for empty strings
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
preserveEmptyRows?: boolean;
|
|
96
102
|
};
|
|
97
103
|
export declare type MarkdownEditorMarkupConfig = {
|
|
98
104
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
import { getPMTransformers } from '../core/markdown/ProseMirrorTransformer/getTransformers';
|
|
2
3
|
import { ReactRenderStorage } from '../extensions';
|
|
3
4
|
import { logger } from '../logger';
|
|
4
5
|
import { DirectiveSyntaxContext } from '../utils/directive';
|
|
@@ -10,11 +11,15 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
10
11
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
11
12
|
const { md = {}, initial = {}, handlers = {}, experimental = {}, markupConfig = {}, wysiwygConfig = {}, } = props;
|
|
12
13
|
const breaks = (_a = md.breaks) !== null && _a !== void 0 ? _a : props.breaks;
|
|
14
|
+
const preserveEmptyRows = experimental.preserveEmptyRows;
|
|
13
15
|
const preset = (_b = props.preset) !== null && _b !== void 0 ? _b : 'full';
|
|
14
16
|
const renderStorage = new ReactRenderStorage();
|
|
15
17
|
const uploadFile = (_c = handlers.uploadFile) !== null && _c !== void 0 ? _c : props.fileUploadHandler;
|
|
16
18
|
const needToSetDimensionsForUploadedImages = (_d = experimental.needToSetDimensionsForUploadedImages) !== null && _d !== void 0 ? _d : props.needToSetDimensionsForUploadedImages;
|
|
17
19
|
const enableNewImageSizeCalculation = experimental.enableNewImageSizeCalculation;
|
|
20
|
+
const pmTransformers = getPMTransformers({
|
|
21
|
+
emptyRowTransformer: preserveEmptyRows,
|
|
22
|
+
});
|
|
18
23
|
const directiveSyntax = new DirectiveSyntaxContext(experimental.directiveSyntax);
|
|
19
24
|
const extensions = (builder) => {
|
|
20
25
|
var _a;
|
|
@@ -26,7 +31,7 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
26
31
|
}, onSubmit: () => {
|
|
27
32
|
editor.emit('submit', null);
|
|
28
33
|
return true;
|
|
29
|
-
}, placeholderOptions: wysiwygConfig.placeholderOptions, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
34
|
+
}, preserveEmptyRows: preserveEmptyRows, placeholderOptions: wysiwygConfig.placeholderOptions, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
30
35
|
enableNewImageSizeCalculation }));
|
|
31
36
|
{
|
|
32
37
|
const extraExtensions = wysiwygConfig.extensions || props.extraExtensions;
|
|
@@ -37,7 +42,8 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
37
42
|
};
|
|
38
43
|
return new EditorImpl(Object.assign(Object.assign({}, props), { preset,
|
|
39
44
|
renderStorage,
|
|
40
|
-
directiveSyntax,
|
|
45
|
+
directiveSyntax,
|
|
46
|
+
pmTransformers, 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,
|
|
41
47
|
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 }) }));
|
|
42
48
|
}, deps);
|
|
43
49
|
useLayoutEffect(() => {
|
|
@@ -9,6 +9,7 @@ export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOption
|
|
|
9
9
|
export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
|
|
10
10
|
preset: MarkdownEditorPreset;
|
|
11
11
|
mdBreaks?: boolean;
|
|
12
|
+
preserveEmptyRows?: boolean;
|
|
12
13
|
fileUploadHandler?: FileUploadHandler;
|
|
13
14
|
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
14
15
|
/**
|
|
@@ -31,7 +31,7 @@ export const BundlePreset = (builder, opts) => {
|
|
|
31
31
|
return typeof value === 'function'
|
|
32
32
|
? value()
|
|
33
33
|
: value !== null && value !== void 0 ? value : i18nPlaceholder('doc_empty');
|
|
34
|
-
} }, opts.baseSchema) });
|
|
34
|
+
}, preserveEmptyRows: opts.preserveEmptyRows }, opts.baseSchema) });
|
|
35
35
|
const commonMarkOptions = Object.assign(Object.assign({}, zeroOptions), { selectionContext: Object.assign({ config: wSelectionMenuConfigByPreset.commonmark }, opts.selectionContext), commandMenu: Object.assign({ actions: wCommandMenuConfigByPreset.commonmark }, opts.commandMenu), breaks: Object.assign({ preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') }, opts.breaks), bold: Object.assign({ boldKey: f.toPM(A.Bold) }, opts.bold), italic: Object.assign({ italicKey: f.toPM(A.Italic) }, opts.italic), code: Object.assign({ codeKey: f.toPM(A.Code) }, opts.code), codeBlock: Object.assign({ codeBlockKey: f.toPM(A.CodeBlock) }, opts.codeBlock), blockquote: Object.assign({ qouteKey: f.toPM(A.Quote) }, opts.blockquote), link: Object.assign({ linkKey: f.toPM(A.Link) }, opts.link), lists: Object.assign({ ulKey: f.toPM(A.BulletList), olKey: f.toPM(A.OrderedList), ulInputRules: { plus: false } }, opts.lists), image: {
|
|
36
36
|
parseInsertedUrlAsImage: (_a = opts.imgSize) === null || _a === void 0 ? void 0 : _a.parseInsertedUrlAsImage,
|
|
37
37
|
} });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PresetName } from 'markdown-it';
|
|
2
2
|
import type { CommonEditor, MarkupString } from '../common';
|
|
3
|
+
import { TransformFn } from './markdown/ProseMirrorTransformer';
|
|
3
4
|
import type { ActionStorage } from './types/actions';
|
|
4
5
|
import type { Extension } from './types/extension';
|
|
5
6
|
import type { Parser } from './types/parser';
|
|
@@ -18,6 +19,7 @@ export declare type WysiwygEditorOptions = {
|
|
|
18
19
|
mdPreset?: PresetName;
|
|
19
20
|
allowHTML?: boolean;
|
|
20
21
|
linkify?: boolean;
|
|
22
|
+
pmTransformers?: TransformFn[];
|
|
21
23
|
linkifyTlds?: string | string[];
|
|
22
24
|
escapeConfig?: EscapeConfig;
|
|
23
25
|
/** Call on any state change (move cursor, change selection, etc...) */
|
|
@@ -31,7 +33,7 @@ export declare class WysiwygEditor implements CommonEditor, ActionStorage {
|
|
|
31
33
|
get serializer(): Serializer;
|
|
32
34
|
get parser(): Parser;
|
|
33
35
|
get actions(): WysiwygEditor.Actions;
|
|
34
|
-
constructor({ domElem, initialContent, extensions, allowHTML, mdPreset, linkify, linkifyTlds, escapeConfig, onChange, onDocChange, }: WysiwygEditorOptions);
|
|
36
|
+
constructor({ domElem, initialContent, extensions, allowHTML, mdPreset, linkify, pmTransformers, linkifyTlds, escapeConfig, onChange, onDocChange, }: WysiwygEditorOptions);
|
|
35
37
|
action<T extends keyof WysiwygEditor.Actions>(actionName: T): WysiwygEditor.Actions[T];
|
|
36
38
|
focus(): void;
|
|
37
39
|
hasFocus(): boolean;
|
package/build/esm/core/Editor.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ExtensionsManager } from './ExtensionsManager';
|
|
|
7
7
|
import { bindActions } from './utils/actions';
|
|
8
8
|
import { logTransactionMetrics } from './utils/metrics';
|
|
9
9
|
export class WysiwygEditor {
|
|
10
|
-
constructor({ domElem, initialContent = '', extensions = () => { }, allowHTML, mdPreset, linkify, linkifyTlds, escapeConfig, onChange, onDocChange, }) {
|
|
10
|
+
constructor({ domElem, initialContent = '', extensions = () => { }, allowHTML, mdPreset, linkify, pmTransformers, linkifyTlds, escapeConfig, onChange, onDocChange, }) {
|
|
11
11
|
_WysiwygEditor_view.set(this, void 0);
|
|
12
12
|
_WysiwygEditor_serializer.set(this, void 0);
|
|
13
13
|
_WysiwygEditor_parser.set(this, void 0);
|
|
@@ -18,6 +18,7 @@ export class WysiwygEditor {
|
|
|
18
18
|
// "breaks" option only affects the renderer, but not the parser
|
|
19
19
|
mdOpts: { html: allowHTML, linkify, breaks: true, preset: mdPreset },
|
|
20
20
|
linkifyTlds,
|
|
21
|
+
pmTransformers,
|
|
21
22
|
});
|
|
22
23
|
const state = EditorState.create({
|
|
23
24
|
schema,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import MarkdownIt, { PresetName } from 'markdown-it';
|
|
2
2
|
import type { Plugin } from 'prosemirror-state';
|
|
3
3
|
import { ActionsManager } from './ActionsManager';
|
|
4
|
+
import { TransformFn } from './markdown/ProseMirrorTransformer';
|
|
4
5
|
import type { ActionSpec } from './types/actions';
|
|
5
6
|
import type { Extension, ExtensionDeps } from './types/extension';
|
|
6
7
|
import type { MarkViewConstructor, NodeViewConstructor } from './types/node-views';
|
|
@@ -13,6 +14,7 @@ declare type ExtensionsManagerOptions = {
|
|
|
13
14
|
preset?: PresetName;
|
|
14
15
|
};
|
|
15
16
|
linkifyTlds?: string | string[];
|
|
17
|
+
pmTransformers?: TransformFn[];
|
|
16
18
|
};
|
|
17
19
|
export declare class ExtensionsManager {
|
|
18
20
|
#private;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _ExtensionsManager_schemaRegistry, _ExtensionsManager_parserRegistry, _ExtensionsManager_serializerRegistry, _ExtensionsManager_nodeViewCreators, _ExtensionsManager_markViewCreators, _ExtensionsManager_mdForMarkup, _ExtensionsManager_mdForText, _ExtensionsManager_extensions, _ExtensionsManager_builder, _ExtensionsManager_spec, _ExtensionsManager_deps, _ExtensionsManager_plugins, _ExtensionsManager_actions, _ExtensionsManager_nodeViews, _ExtensionsManager_markViews;
|
|
1
|
+
var _ExtensionsManager_schemaRegistry, _ExtensionsManager_parserRegistry, _ExtensionsManager_serializerRegistry, _ExtensionsManager_nodeViewCreators, _ExtensionsManager_markViewCreators, _ExtensionsManager_pmTransformers, _ExtensionsManager_mdForMarkup, _ExtensionsManager_mdForText, _ExtensionsManager_extensions, _ExtensionsManager_builder, _ExtensionsManager_spec, _ExtensionsManager_deps, _ExtensionsManager_plugins, _ExtensionsManager_actions, _ExtensionsManager_nodeViews, _ExtensionsManager_markViews;
|
|
2
2
|
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
3
|
import MarkdownIt from 'markdown-it';
|
|
4
4
|
import { ActionsManager } from './ActionsManager';
|
|
@@ -14,6 +14,7 @@ export class ExtensionsManager {
|
|
|
14
14
|
_ExtensionsManager_serializerRegistry.set(this, new SerializerTokensRegistry());
|
|
15
15
|
_ExtensionsManager_nodeViewCreators.set(this, new Map());
|
|
16
16
|
_ExtensionsManager_markViewCreators.set(this, new Map());
|
|
17
|
+
_ExtensionsManager_pmTransformers.set(this, []);
|
|
17
18
|
_ExtensionsManager_mdForMarkup.set(this, void 0);
|
|
18
19
|
_ExtensionsManager_mdForText.set(this, void 0);
|
|
19
20
|
_ExtensionsManager_extensions.set(this, void 0);
|
|
@@ -48,6 +49,9 @@ export class ExtensionsManager {
|
|
|
48
49
|
__classPrivateFieldGet(this, _ExtensionsManager_mdForMarkup, "f").linkify.tlds(options.linkifyTlds, true);
|
|
49
50
|
__classPrivateFieldGet(this, _ExtensionsManager_mdForText, "f").linkify.tlds(options.linkifyTlds, true);
|
|
50
51
|
}
|
|
52
|
+
if (options.pmTransformers) {
|
|
53
|
+
__classPrivateFieldSet(this, _ExtensionsManager_pmTransformers, options.pmTransformers, "f");
|
|
54
|
+
}
|
|
51
55
|
// TODO: add prefilled context
|
|
52
56
|
__classPrivateFieldSet(this, _ExtensionsManager_builder, new ExtensionBuilder(), "f");
|
|
53
57
|
}
|
|
@@ -77,8 +81,8 @@ export class ExtensionsManager {
|
|
|
77
81
|
__classPrivateFieldSet(this, _ExtensionsManager_deps, {
|
|
78
82
|
schema,
|
|
79
83
|
actions: new ActionsManager(),
|
|
80
|
-
markupParser: __classPrivateFieldGet(this, _ExtensionsManager_parserRegistry, "f").createParser(schema, __classPrivateFieldGet(this, _ExtensionsManager_mdForMarkup, "f")),
|
|
81
|
-
textParser: __classPrivateFieldGet(this, _ExtensionsManager_parserRegistry, "f").createParser(schema, __classPrivateFieldGet(this, _ExtensionsManager_mdForText, "f")),
|
|
84
|
+
markupParser: __classPrivateFieldGet(this, _ExtensionsManager_parserRegistry, "f").createParser(schema, __classPrivateFieldGet(this, _ExtensionsManager_mdForMarkup, "f"), __classPrivateFieldGet(this, _ExtensionsManager_pmTransformers, "f")),
|
|
85
|
+
textParser: __classPrivateFieldGet(this, _ExtensionsManager_parserRegistry, "f").createParser(schema, __classPrivateFieldGet(this, _ExtensionsManager_mdForText, "f"), __classPrivateFieldGet(this, _ExtensionsManager_pmTransformers, "f")),
|
|
82
86
|
serializer: __classPrivateFieldGet(this, _ExtensionsManager_serializerRegistry, "f").createSerializer(),
|
|
83
87
|
}, "f");
|
|
84
88
|
}
|
|
@@ -93,4 +97,4 @@ export class ExtensionsManager {
|
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
_ExtensionsManager_schemaRegistry = new WeakMap(), _ExtensionsManager_parserRegistry = new WeakMap(), _ExtensionsManager_serializerRegistry = new WeakMap(), _ExtensionsManager_nodeViewCreators = new WeakMap(), _ExtensionsManager_markViewCreators = new WeakMap(), _ExtensionsManager_mdForMarkup = new WeakMap(), _ExtensionsManager_mdForText = new WeakMap(), _ExtensionsManager_extensions = new WeakMap(), _ExtensionsManager_builder = new WeakMap(), _ExtensionsManager_spec = new WeakMap(), _ExtensionsManager_deps = new WeakMap(), _ExtensionsManager_plugins = new WeakMap(), _ExtensionsManager_actions = new WeakMap(), _ExtensionsManager_nodeViews = new WeakMap(), _ExtensionsManager_markViews = new WeakMap();
|
|
100
|
+
_ExtensionsManager_schemaRegistry = new WeakMap(), _ExtensionsManager_parserRegistry = new WeakMap(), _ExtensionsManager_serializerRegistry = new WeakMap(), _ExtensionsManager_nodeViewCreators = new WeakMap(), _ExtensionsManager_markViewCreators = new WeakMap(), _ExtensionsManager_pmTransformers = new WeakMap(), _ExtensionsManager_mdForMarkup = new WeakMap(), _ExtensionsManager_mdForText = new WeakMap(), _ExtensionsManager_extensions = new WeakMap(), _ExtensionsManager_builder = new WeakMap(), _ExtensionsManager_spec = new WeakMap(), _ExtensionsManager_deps = new WeakMap(), _ExtensionsManager_plugins = new WeakMap(), _ExtensionsManager_actions = new WeakMap(), _ExtensionsManager_nodeViews = new WeakMap(), _ExtensionsManager_markViews = new WeakMap();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type MarkdownIt from 'markdown-it';
|
|
2
2
|
import type { Schema } from 'prosemirror-model';
|
|
3
|
+
import { TransformFn } from './markdown/ProseMirrorTransformer';
|
|
3
4
|
import type { Parser, ParserToken } from './types/parser';
|
|
4
5
|
export declare class ParserTokensRegistry {
|
|
5
6
|
#private;
|
|
6
7
|
addToken(name: string, token: ParserToken): this;
|
|
7
|
-
createParser(schema: Schema, tokenizer: MarkdownIt): Parser;
|
|
8
|
+
createParser(schema: Schema, tokenizer: MarkdownIt, pmTransformers: TransformFn[]): Parser;
|
|
8
9
|
}
|
|
@@ -9,8 +9,8 @@ export class ParserTokensRegistry {
|
|
|
9
9
|
__classPrivateFieldGet(this, _ParserTokensRegistry_tokens, "f")[name] = token;
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
|
-
createParser(schema, tokenizer) {
|
|
13
|
-
return new MarkdownParser(schema, tokenizer, __classPrivateFieldGet(this, _ParserTokensRegistry_tokens, "f"));
|
|
12
|
+
createParser(schema, tokenizer, pmTransformers) {
|
|
13
|
+
return new MarkdownParser(schema, tokenizer, __classPrivateFieldGet(this, _ParserTokensRegistry_tokens, "f"), pmTransformers);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
_ParserTokensRegistry_tokens = new WeakMap();
|
|
@@ -2,6 +2,7 @@ import type { Match } from 'linkify-it';
|
|
|
2
2
|
import type MarkdownIt from 'markdown-it';
|
|
3
3
|
import { Mark, Node, NodeType, Schema } from 'prosemirror-model';
|
|
4
4
|
import type { Parser, ParserToken } from '../types/parser';
|
|
5
|
+
import { TransformFn } from './ProseMirrorTransformer';
|
|
5
6
|
declare type TokenAttrs = {
|
|
6
7
|
[name: string]: unknown;
|
|
7
8
|
};
|
|
@@ -15,7 +16,8 @@ export declare class MarkdownParser implements Parser {
|
|
|
15
16
|
marks: readonly Mark[];
|
|
16
17
|
tokens: Record<string, ParserToken>;
|
|
17
18
|
tokenizer: MarkdownIt;
|
|
18
|
-
|
|
19
|
+
pmTransformers: TransformFn[];
|
|
20
|
+
constructor(schema: Schema, tokenizer: MarkdownIt, tokens: Record<string, ParserToken>, pmTransformers: TransformFn[]);
|
|
19
21
|
validateLink(url: string): boolean;
|
|
20
22
|
normalizeLink(url: string): string;
|
|
21
23
|
normalizeLinkText(url: string): string;
|