@gravity-ui/markdown-editor 14.0.3 → 14.2.1
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 +1 -1
- package/build/cjs/bundle/Editor.js +19 -7
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/toolbar/markup/MToolbarImagePopup.d.ts +1 -1
- package/build/cjs/bundle/toolbar/markup/MToolbarImagePopup.js +4 -5
- package/build/cjs/bundle/types.d.ts +16 -2
- package/build/cjs/bundle/useMarkdownEditor.js +5 -2
- package/build/cjs/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/cjs/bundle/wysiwyg-preset.js +6 -4
- package/build/cjs/extensions/additional/Mermaid/MermaidNodeView/MermaidView.js +2 -2
- package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js +1 -4
- package/build/cjs/extensions/markdown/Image/ImageSpecs/index.js +13 -6
- package/build/cjs/extensions/markdown/Image/imageUrlPaste/index.d.ts +9 -0
- package/build/cjs/extensions/markdown/Image/imageUrlPaste/index.js +34 -0
- package/build/cjs/extensions/markdown/Image/index.d.ts +3 -1
- package/build/cjs/extensions/markdown/Image/index.js +8 -1
- package/build/cjs/extensions/markdown/Lists/inputrules.d.ts +1 -1
- package/build/cjs/extensions/markdown/Lists/inputrules.js +5 -2
- package/build/cjs/extensions/yfm/Emoji/EmojiSuggest/EmojiSuggestComponent.js +2 -3
- package/build/cjs/extensions/yfm/ImgSize/ImagePaste/index.d.ts +8 -3
- package/build/cjs/extensions/yfm/ImgSize/ImagePaste/index.js +31 -8
- package/build/cjs/extensions/yfm/ImgSize/ImagePaste/upload.d.ts +2 -1
- package/build/cjs/extensions/yfm/ImgSize/ImagePaste/upload.js +17 -7
- package/build/cjs/extensions/yfm/ImgSize/ImageWidget/widget.js +1 -1
- package/build/cjs/extensions/yfm/ImgSize/ImgSizeSpecs/index.js +15 -8
- package/build/cjs/extensions/yfm/ImgSize/index.d.ts +2 -3
- package/build/cjs/extensions/yfm/ImgSize/index.js +4 -2
- package/build/cjs/extensions/yfm/ImgSize/plugins/ImgSizeNodeView/NodeView.js +10 -2
- package/build/cjs/extensions/yfm/ImgSize/utils.d.ts +6 -2
- package/build/cjs/extensions/yfm/ImgSize/utils.js +13 -3
- package/build/cjs/extensions/yfm/Video/VideoSpecs/index.js +1 -1
- package/build/cjs/extensions/yfm/YfmFile/YfmFilePaste/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmFile/YfmFilePaste/index.js +1 -1
- package/build/cjs/i18n/menubar/index.d.ts +1 -1
- package/build/cjs/i18n/placeholder/index.d.ts +1 -1
- package/build/cjs/i18n/yfm-note/index.d.ts +1 -1
- package/build/cjs/markup/codemirror/create.d.ts +4 -1
- package/build/cjs/markup/codemirror/create.js +21 -2
- package/build/cjs/markup/codemirror/files-upload-facet.d.ts +4 -2
- package/build/cjs/markup/codemirror/files-upload-plugin/plugin.js +30 -19
- package/build/cjs/markup/codemirror/files-upload-plugin/utils.js +4 -4
- package/build/cjs/markup/codemirror/yfm.d.ts +1 -1
- package/build/cjs/markup/commands/inline.js +9 -3
- package/build/cjs/presets/commonmark.d.ts +2 -2
- package/build/cjs/presets/commonmark.js +1 -1
- package/build/cjs/utils/get-proportional-size.d.ts +10 -0
- package/build/cjs/utils/get-proportional-size.js +14 -0
- package/build/cjs/utils/index.d.ts +2 -1
- package/build/cjs/utils/index.js +2 -7
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.d.ts +1 -1
- package/build/esm/bundle/Editor.js +17 -5
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/toolbar/markup/MToolbarImagePopup.d.ts +1 -1
- package/build/esm/bundle/toolbar/markup/MToolbarImagePopup.js +3 -4
- package/build/esm/bundle/types.d.ts +16 -2
- package/build/esm/bundle/useMarkdownEditor.js +5 -2
- package/build/esm/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/esm/bundle/wysiwyg-preset.js +6 -4
- package/build/esm/extensions/additional/Mermaid/MermaidNodeView/MermaidView.js +2 -2
- package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js +1 -4
- package/build/esm/extensions/markdown/Image/ImageSpecs/index.js +13 -6
- package/build/esm/extensions/markdown/Image/imageUrlPaste/index.d.ts +9 -0
- package/build/esm/extensions/markdown/Image/imageUrlPaste/index.js +30 -0
- package/build/esm/extensions/markdown/Image/index.d.ts +3 -1
- package/build/esm/extensions/markdown/Image/index.js +8 -1
- package/build/esm/extensions/markdown/Lists/inputrules.d.ts +1 -1
- package/build/esm/extensions/markdown/Lists/inputrules.js +5 -2
- package/build/esm/extensions/yfm/Emoji/EmojiSuggest/EmojiSuggestComponent.js +2 -3
- package/build/esm/extensions/yfm/ImgSize/ImagePaste/index.d.ts +8 -3
- package/build/esm/extensions/yfm/ImgSize/ImagePaste/index.js +29 -6
- package/build/esm/extensions/yfm/ImgSize/ImagePaste/upload.d.ts +2 -1
- package/build/esm/extensions/yfm/ImgSize/ImagePaste/upload.js +15 -5
- package/build/esm/extensions/yfm/ImgSize/ImageWidget/widget.js +1 -1
- package/build/esm/extensions/yfm/ImgSize/ImgSizeSpecs/index.js +15 -8
- package/build/esm/extensions/yfm/ImgSize/index.d.ts +2 -3
- package/build/esm/extensions/yfm/ImgSize/index.js +4 -2
- package/build/esm/extensions/yfm/ImgSize/plugins/ImgSizeNodeView/NodeView.js +10 -2
- package/build/esm/extensions/yfm/ImgSize/utils.d.ts +6 -2
- package/build/esm/extensions/yfm/ImgSize/utils.js +11 -2
- package/build/esm/extensions/yfm/Video/VideoSpecs/index.js +1 -1
- package/build/esm/extensions/yfm/YfmFile/YfmFilePaste/index.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmFile/YfmFilePaste/index.js +1 -1
- package/build/esm/i18n/menubar/index.d.ts +1 -1
- package/build/esm/i18n/placeholder/index.d.ts +1 -1
- package/build/esm/i18n/yfm-note/index.d.ts +1 -1
- package/build/esm/markup/codemirror/create.d.ts +4 -1
- package/build/esm/markup/codemirror/create.js +22 -3
- package/build/esm/markup/codemirror/files-upload-facet.d.ts +4 -2
- package/build/esm/markup/codemirror/files-upload-plugin/plugin.js +22 -11
- package/build/esm/markup/codemirror/files-upload-plugin/utils.js +1 -1
- package/build/esm/markup/codemirror/yfm.d.ts +1 -1
- package/build/esm/markup/commands/inline.js +9 -3
- package/build/esm/presets/commonmark.d.ts +2 -2
- package/build/esm/presets/commonmark.js +1 -1
- package/build/esm/utils/get-proportional-size.d.ts +10 -0
- package/build/esm/utils/get-proportional-size.js +10 -0
- package/build/esm/utils/index.d.ts +2 -1
- package/build/esm/utils/index.js +2 -1
- package/build/esm/version.js +1 -1
- package/package.json +10 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommonEditor } from '../common';
|
|
2
2
|
import { ReactRenderStorage } from '../extensions';
|
|
3
|
-
import { type Receiver } from '../utils
|
|
3
|
+
import { type Receiver } from '../utils';
|
|
4
4
|
import type { MarkdownEditorMode as EditorMode, MarkdownEditorPreset as EditorPreset, MarkdownEditorOptions } from './types';
|
|
5
5
|
export declare type ToolbarActionData = {
|
|
6
6
|
editorMode: EditorMode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
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_needToSetDimensionsForUploadedImages, _EditorImpl_prepareRawMarkup, _EditorImpl_beforeEditorModeChange;
|
|
2
|
+
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;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.EditorImpl = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
@@ -8,11 +8,11 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
8
8
|
const core_1 = require("../core");
|
|
9
9
|
const bundle_1 = require("../i18n/bundle");
|
|
10
10
|
const logger_1 = require("../logger");
|
|
11
|
-
const
|
|
11
|
+
const markup_1 = require("../markup");
|
|
12
12
|
const editor_1 = require("../markup/editor");
|
|
13
|
-
const
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
14
|
/** @internal */
|
|
15
|
-
class EditorImpl extends
|
|
15
|
+
class EditorImpl extends utils_1.SafeEventEmitter {
|
|
16
16
|
constructor(opts) {
|
|
17
17
|
var _a, _b, _c, _d, _e, _f;
|
|
18
18
|
super({ onError: logger_1.logger.error.bind(logger_1.logger) });
|
|
@@ -31,7 +31,9 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
31
31
|
_EditorImpl_extensions.set(this, void 0);
|
|
32
32
|
_EditorImpl_renderStorage.set(this, void 0);
|
|
33
33
|
_EditorImpl_fileUploadHandler.set(this, void 0);
|
|
34
|
+
_EditorImpl_parseInsertedUrlAsImage.set(this, void 0);
|
|
34
35
|
_EditorImpl_needToSetDimensionsForUploadedImages.set(this, void 0);
|
|
36
|
+
_EditorImpl_enableNewImageSizeCalculation.set(this, void 0);
|
|
35
37
|
_EditorImpl_prepareRawMarkup.set(this, void 0);
|
|
36
38
|
_EditorImpl_beforeEditorModeChange.set(this, void 0);
|
|
37
39
|
this.getValue = () => this.currentEditor.getValue();
|
|
@@ -48,7 +50,9 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
48
50
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_markupConfig, Object.assign({}, opts.markupConfig), "f");
|
|
49
51
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_renderStorage, opts.renderStorage, "f");
|
|
50
52
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_fileUploadHandler, handlers.uploadFile, "f");
|
|
53
|
+
tslib_1.__classPrivateFieldSet(this, _EditorImpl_parseInsertedUrlAsImage, markupConfig.parseInsertedUrlAsImage, "f");
|
|
51
54
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_needToSetDimensionsForUploadedImages, Boolean(experimental.needToSetDimensionsForUploadedImages), "f");
|
|
55
|
+
tslib_1.__classPrivateFieldSet(this, _EditorImpl_enableNewImageSizeCalculation, Boolean(experimental.enableNewImageSizeCalculation), "f");
|
|
52
56
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_prepareRawMarkup, experimental.prepareRawMarkup, "f");
|
|
53
57
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_escapeConfig, wysiwygConfig.escapeConfig, "f");
|
|
54
58
|
tslib_1.__classPrivateFieldSet(this, _EditorImpl_beforeEditorModeChange, experimental.beforeEditorModeChange, "f");
|
|
@@ -150,7 +154,7 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
150
154
|
get markupEditor() {
|
|
151
155
|
var _a;
|
|
152
156
|
if (!tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupEditor, "f")) {
|
|
153
|
-
tslib_1.__classPrivateFieldSet(this, _EditorImpl_markupEditor, new editor_1.Editor((0,
|
|
157
|
+
tslib_1.__classPrivateFieldSet(this, _EditorImpl_markupEditor, new editor_1.Editor((0, markup_1.createCodemirror)({
|
|
154
158
|
doc: tslib_1.__classPrivateFieldGet(this, _EditorImpl_markup, "f"),
|
|
155
159
|
placeholder: (_a = tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").placeholder) !== null && _a !== void 0 ? _a : (0, bundle_1.i18n)('markup_placeholder'),
|
|
156
160
|
onCancel: () => this.emit('cancel', null),
|
|
@@ -160,7 +164,9 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
160
164
|
onScroll: (event) => this.emit('cm-scroll', { event }),
|
|
161
165
|
reactRenderer: tslib_1.__classPrivateFieldGet(this, _EditorImpl_renderStorage, "f"),
|
|
162
166
|
uploadHandler: this.fileUploadHandler,
|
|
163
|
-
|
|
167
|
+
parseInsertedUrlAsImage: this.parseInsertedUrlAsImage,
|
|
168
|
+
needImageDimensions: this.needToSetDimensionsForUploadedImages,
|
|
169
|
+
enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
|
|
164
170
|
extensions: tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").extensions,
|
|
165
171
|
disabledExtensions: tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").disabledExtensions,
|
|
166
172
|
keymaps: tslib_1.__classPrivateFieldGet(this, _EditorImpl_markupConfig, "f").keymaps,
|
|
@@ -177,9 +183,15 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
177
183
|
get fileUploadHandler() {
|
|
178
184
|
return tslib_1.__classPrivateFieldGet(this, _EditorImpl_fileUploadHandler, "f");
|
|
179
185
|
}
|
|
186
|
+
get parseInsertedUrlAsImage() {
|
|
187
|
+
return tslib_1.__classPrivateFieldGet(this, _EditorImpl_parseInsertedUrlAsImage, "f");
|
|
188
|
+
}
|
|
180
189
|
get needToSetDimensionsForUploadedImages() {
|
|
181
190
|
return tslib_1.__classPrivateFieldGet(this, _EditorImpl_needToSetDimensionsForUploadedImages, "f");
|
|
182
191
|
}
|
|
192
|
+
get enableNewImageSizeCalculation() {
|
|
193
|
+
return tslib_1.__classPrivateFieldGet(this, _EditorImpl_enableNewImageSizeCalculation, "f");
|
|
194
|
+
}
|
|
183
195
|
// ---> implements CodeEditor
|
|
184
196
|
get cm() {
|
|
185
197
|
return this.markupEditor.cm;
|
|
@@ -300,7 +312,7 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
300
312
|
}
|
|
301
313
|
}
|
|
302
314
|
exports.EditorImpl = EditorImpl;
|
|
303
|
-
_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_needToSetDimensionsForUploadedImages = new WeakMap(), _EditorImpl_prepareRawMarkup = new WeakMap(), _EditorImpl_beforeEditorModeChange = new WeakMap();
|
|
315
|
+
_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();
|
|
304
316
|
function getTopOffset(elem) {
|
|
305
317
|
const TOOLBAR_HEIGHT = 36; //px
|
|
306
318
|
const TOOLBAR_BOTTOM_OFFSET = 8; // px
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const namesObj: Record<"bold" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "
|
|
1
|
+
declare const namesObj: Record<"bold" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "paragraph" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "file" | "checkbox" | "emoji" | "undo" | "redo" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "bulletList" | "orderedList" | "liftListItem" | "sinkListItem" | "yfm_cut" | "yfm_note" | "yfm_block" | "yfm_html_block" | "yfm_layout" | "horizontalrule" | "math_inline" | "math_block" | "tabs" | "mermaid" | "gpt", string>;
|
|
2
2
|
export declare const ActionName: Readonly<typeof namesObj>;
|
|
3
3
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import type { CodeEditor } from '../../../markup
|
|
2
|
+
import type { CodeEditor } from '../../../markup';
|
|
3
3
|
import type { ToolbarBaseProps } from '../../../toolbar';
|
|
4
4
|
export declare type MToolbarImagePopupProps = ToolbarBaseProps<CodeEditor> & {
|
|
5
5
|
hide: () => void;
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const is_number_1 = tslib_1.__importDefault(require("is-number"));
|
|
7
7
|
const markup_1 = require("../../../markup");
|
|
8
|
-
const commands_1 = require("../../../markup/commands");
|
|
9
8
|
const ToolbarImagePopup_1 = require("../custom/ToolbarImagePopup");
|
|
10
9
|
const context_1 = require("./context");
|
|
11
10
|
const noop = (err) => {
|
|
@@ -14,7 +13,7 @@ const noop = (err) => {
|
|
|
14
13
|
const MToolbarImagePopup = ({ focus, onClick, hide, anchorRef, editor, className, }) => {
|
|
15
14
|
const { uploadHandler, needToSetDimensionsForUploadedImages } = (0, context_1.useMarkupToolbarContext)();
|
|
16
15
|
return (react_1.default.createElement(ToolbarImagePopup_1.ToolbarImagePopup, { hide: hide, anchorRef: anchorRef, focus: focus, onClick: onClick, className: className, onSubmit: ({ url, name, alt, width, height }) => {
|
|
17
|
-
(0,
|
|
16
|
+
(0, markup_1.insertImages)([
|
|
18
17
|
{
|
|
19
18
|
url,
|
|
20
19
|
alt,
|
|
@@ -25,17 +24,17 @@ const MToolbarImagePopup = ({ focus, onClick, hide, anchorRef, editor, className
|
|
|
25
24
|
])(editor.cm);
|
|
26
25
|
}, uploadImages: uploadHandler, onSuccessUpload: async (res) => {
|
|
27
26
|
const images = await toImageItems(res.success, Boolean(needToSetDimensionsForUploadedImages));
|
|
28
|
-
(0,
|
|
27
|
+
(0, markup_1.insertImages)(images)(editor.cm);
|
|
29
28
|
} }));
|
|
30
29
|
};
|
|
31
30
|
exports.MToolbarImagePopup = MToolbarImagePopup;
|
|
32
|
-
async function toImageItems(items,
|
|
31
|
+
async function toImageItems(items, withDimensions) {
|
|
33
32
|
const imgItems = [];
|
|
34
33
|
await Promise.all(items.map(({ result, file }) => {
|
|
35
34
|
var _a;
|
|
36
35
|
const imgItem = { url: result.url, alt: (_a = result.name) !== null && _a !== void 0 ? _a : file.name };
|
|
37
36
|
imgItems.push(imgItem);
|
|
38
|
-
if (
|
|
37
|
+
if (withDimensions) {
|
|
39
38
|
return (0, markup_1.getImageDimensions)(file).then(({ height }) => {
|
|
40
39
|
imgItem.height = String(Math.min(height, markup_1.IMG_MAX_HEIGHT));
|
|
41
40
|
}, noop);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { MarkupString } from '../common';
|
|
3
3
|
import type { EscapeConfig, Extension } from '../core';
|
|
4
|
-
import type { CreateCodemirrorParams, YfmLangOptions } from '../markup
|
|
5
|
-
import type { FileUploadHandler } from '../utils
|
|
4
|
+
import type { CreateCodemirrorParams, YfmLangOptions } from '../markup';
|
|
5
|
+
import type { FileUploadHandler } from '../utils';
|
|
6
6
|
import type { ChangeEditorModeOptions } from './Editor';
|
|
7
7
|
import type { ExtensionsOptions as WysiwygPresetExtensionsOptions } from './wysiwyg-preset';
|
|
8
8
|
export type { Editor as MarkdownEditorInstance } from './Editor';
|
|
@@ -15,6 +15,10 @@ export declare type RenderPreviewParams = {
|
|
|
15
15
|
md: Readonly<MarkdownEditorMdOptions>;
|
|
16
16
|
};
|
|
17
17
|
export declare type RenderPreview = (params: RenderPreviewParams) => ReactNode;
|
|
18
|
+
export declare type ParseInsertedUrlAsImage = (text: string) => {
|
|
19
|
+
imageUrl: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
} | null;
|
|
18
22
|
export declare type MarkdownEditorMdOptions = {
|
|
19
23
|
html?: boolean;
|
|
20
24
|
breaks?: boolean;
|
|
@@ -45,6 +49,12 @@ export declare type MarkdownEditorExperimentalOptions = {
|
|
|
45
49
|
* @default false
|
|
46
50
|
*/
|
|
47
51
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* If we need to enable new image size calculations
|
|
54
|
+
*
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
enableNewImageSizeCalculation?: boolean;
|
|
48
58
|
/**
|
|
49
59
|
* Called before switching from the markup editor to the wysiwyg editor.
|
|
50
60
|
* You can use it to pre-process the value from the markup editor before it gets into the wysiwyg editor.
|
|
@@ -85,6 +95,10 @@ export declare type MarkdownEditorMarkupConfig = {
|
|
|
85
95
|
languageData?: YfmLangOptions['languageData'];
|
|
86
96
|
/** Config for @codemirror/autocomplete https://codemirror.net/docs/ref/#autocomplete.autocompletion%5Econfig */
|
|
87
97
|
autocompletion?: CreateCodemirrorParams['autocompletion'];
|
|
98
|
+
/**
|
|
99
|
+
* The function, used to determine if the pasted text is the image url and should be inserted as an image
|
|
100
|
+
*/
|
|
101
|
+
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
88
102
|
};
|
|
89
103
|
declare type ExtensionsOptions<T extends object = {}> = Omit<WysiwygPresetExtensionsOptions, 'reactRenderer'> & T;
|
|
90
104
|
export declare type MarkdownEditorWysiwygConfig = {
|
|
@@ -16,6 +16,7 @@ function useMarkdownEditor(props, deps = []) {
|
|
|
16
16
|
const renderStorage = new extensions_1.ReactRenderStorage();
|
|
17
17
|
const uploadFile = (_c = handlers.uploadFile) !== null && _c !== void 0 ? _c : props.fileUploadHandler;
|
|
18
18
|
const needToSetDimensionsForUploadedImages = (_d = experimental.needToSetDimensionsForUploadedImages) !== null && _d !== void 0 ? _d : props.needToSetDimensionsForUploadedImages;
|
|
19
|
+
const enableNewImageSizeCalculation = experimental.enableNewImageSizeCalculation;
|
|
19
20
|
const extensions = (builder) => {
|
|
20
21
|
var _a;
|
|
21
22
|
const extensionOptions = (_a = wysiwygConfig.extensionOptions) !== null && _a !== void 0 ? _a : props.extensionOptions;
|
|
@@ -25,7 +26,8 @@ function useMarkdownEditor(props, deps = []) {
|
|
|
25
26
|
}, onSubmit: () => {
|
|
26
27
|
editor.emit('submit', null);
|
|
27
28
|
return true;
|
|
28
|
-
}, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages
|
|
29
|
+
}, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
30
|
+
enableNewImageSizeCalculation }));
|
|
29
31
|
{
|
|
30
32
|
const extraExtensions = wysiwygConfig.extensions || props.extraExtensions;
|
|
31
33
|
if (extraExtensions) {
|
|
@@ -34,7 +36,8 @@ function useMarkdownEditor(props, deps = []) {
|
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
return new Editor_1.EditorImpl(Object.assign(Object.assign({}, props), { preset,
|
|
37
|
-
renderStorage, 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,
|
|
39
|
+
renderStorage, 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,
|
|
40
|
+
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
41
|
}, deps);
|
|
39
42
|
(0, react_1.useLayoutEffect)(() => {
|
|
40
43
|
function onToolbarAction({ editorMode, id }) {
|
|
@@ -15,5 +15,6 @@ export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOp
|
|
|
15
15
|
* @default false
|
|
16
16
|
*/
|
|
17
17
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
18
|
+
enableNewImageSizeCalculation?: boolean;
|
|
18
19
|
};
|
|
19
20
|
export declare const BundlePreset: ExtensionAuto<BundlePresetOptions>;
|
|
@@ -15,7 +15,7 @@ const wysiwyg_1 = require("./config/wysiwyg");
|
|
|
15
15
|
const emoji_1 = require("./emoji");
|
|
16
16
|
const DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'];
|
|
17
17
|
const BundlePreset = (builder, opts) => {
|
|
18
|
-
var _a, _b;
|
|
18
|
+
var _a, _b, _c;
|
|
19
19
|
const dropCursor = {
|
|
20
20
|
color: 'var(--g-color-line-brand)',
|
|
21
21
|
width: 2,
|
|
@@ -24,9 +24,11 @@ const BundlePreset = (builder, opts) => {
|
|
|
24
24
|
const isDocEmpty = !node.text && (parent === null || parent === void 0 ? void 0 : parent.type.name) === specs_1.BaseNode.Doc && parent.childCount === 1;
|
|
25
25
|
return isDocEmpty ? (0, placeholder_1.i18n)('doc_empty') : null;
|
|
26
26
|
} }, opts.baseSchema) });
|
|
27
|
-
const commonMarkOptions = Object.assign(Object.assign({}, zeroOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.commonmark }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.commonmark }, opts.commandMenu), breaks: Object.assign({ preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') }, opts.breaks), bold: Object.assign({ boldKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Bold) }, opts.bold), italic: Object.assign({ italicKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Italic) }, opts.italic), code: Object.assign({ codeKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Code) }, opts.code), codeBlock: Object.assign({ codeBlockKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.CodeBlock) }, opts.codeBlock), blockquote: Object.assign({ qouteKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Quote) }, opts.blockquote), link: Object.assign({ linkKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Link) }, opts.link), lists: Object.assign({ ulKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.BulletList), olKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.OrderedList), ulInputRules: { plus: false } }, opts.lists)
|
|
27
|
+
const commonMarkOptions = Object.assign(Object.assign({}, zeroOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.commonmark }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.commonmark }, opts.commandMenu), breaks: Object.assign({ preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') }, opts.breaks), bold: Object.assign({ boldKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Bold) }, opts.bold), italic: Object.assign({ italicKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Italic) }, opts.italic), code: Object.assign({ codeKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Code) }, opts.code), codeBlock: Object.assign({ codeBlockKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.CodeBlock) }, opts.codeBlock), blockquote: Object.assign({ qouteKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Quote) }, opts.blockquote), link: Object.assign({ linkKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Link) }, opts.link), lists: Object.assign({ ulKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.BulletList), olKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.OrderedList), ulInputRules: { plus: false } }, opts.lists), image: {
|
|
28
|
+
parseInsertedUrlAsImage: (_a = opts.imgSize) === null || _a === void 0 ? void 0 : _a.parseInsertedUrlAsImage,
|
|
29
|
+
} });
|
|
28
30
|
const defaultOptions = Object.assign(Object.assign({}, commonMarkOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.default }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.default }, opts.commandMenu), strike: Object.assign({ strikeKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Strike) }, opts.strike) });
|
|
29
|
-
const yfmOptions = Object.assign(Object.assign({}, defaultOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.yfm }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.yfm }, opts.commandMenu), underline: Object.assign({ underlineKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Underline) }, opts.underline), imgSize: Object.assign({ imageUploadHandler: opts.fileUploadHandler, needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages }, opts.imgSize), checkbox: Object.assign({ checkboxLabelPlaceholder: () => (0, placeholder_1.i18n)('checkbox') }, opts.checkbox), deflist: {
|
|
31
|
+
const yfmOptions = Object.assign(Object.assign({}, defaultOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.yfm }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.yfm }, opts.commandMenu), underline: Object.assign({ underlineKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Underline) }, opts.underline), imgSize: Object.assign({ imageUploadHandler: opts.fileUploadHandler, needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages, enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation }, opts.imgSize), checkbox: Object.assign({ checkboxLabelPlaceholder: () => (0, placeholder_1.i18n)('checkbox') }, opts.checkbox), deflist: {
|
|
30
32
|
deflistTermPlaceholder: () => (0, placeholder_1.i18n)('deflist_term'),
|
|
31
33
|
deflistDescPlaceholder: () => (0, placeholder_1.i18n)('deflist_desc'),
|
|
32
34
|
}, yfmCut: Object.assign({ yfmCutKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Cut), yfmCutTitlePlaceholder: () => (0, placeholder_1.i18n)('cut_title'), yfmCutContentPlaceholder: () => (0, placeholder_1.i18n)('cut_content') }, opts.yfmCut), yfmNote: Object.assign({ yfmNoteKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Note), yfmNoteTitlePlaceholder: () => (0, placeholder_1.i18n)('note_title') }, opts.yfmNote), yfmTable: Object.assign({ yfmTableCellPlaceholder: () => (0, placeholder_1.i18n)('table_cell') }, opts.yfmTable), yfmFile: Object.assign({ fileUploadHandler: opts.fileUploadHandler, needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages }, opts.yfmFile), yfmHeading: Object.assign({ h1Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading1), h2Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading2), h3Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading3), h4Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading4), h5Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading5), h6Key: shortcuts_1.formatter.toPM(shortcuts_1.Action.Heading6), headingPlaceholder: (node) => `${(0, placeholder_1.i18n)('heading')} ${node.attrs[specs_1.YfmHeadingAttr.Level]}` }, opts.yfmHeading), placeholder: {
|
|
@@ -66,7 +68,7 @@ const BundlePreset = (builder, opts) => {
|
|
|
66
68
|
break;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
|
-
const ignoreKeysList = (
|
|
71
|
+
const ignoreKeysList = (_c = (_b = opts.ignoreKeysList) === null || _b === void 0 ? void 0 : _b.slice()) !== null && _c !== void 0 ? _c : [];
|
|
70
72
|
ignoreKeysList.push(...DEFAULT_IGNORED_KEYS);
|
|
71
73
|
for (const action of ignoreActions) {
|
|
72
74
|
const key = shortcuts_1.formatter.toPM(action);
|
|
@@ -53,9 +53,9 @@ const DiagramEditMode = ({ initialText, onSave, onCancel, mermaidInstance }) =>
|
|
|
53
53
|
react_1.default.createElement("div", { className: b('Controls') },
|
|
54
54
|
react_1.default.createElement("div", null,
|
|
55
55
|
react_1.default.createElement(uikit_1.Button, { onClick: onCancel, view: 'flat' },
|
|
56
|
-
react_1.default.createElement("span", { className: (0, exports.cnDiagramHelper)({ 'prosemirror-stop-event': true }) },
|
|
56
|
+
react_1.default.createElement("span", { className: (0, exports.cnDiagramHelper)({ 'prosemirror-stop-event': true }) }, (0, common_1.i18n)('cancel'))),
|
|
57
57
|
react_1.default.createElement(uikit_1.Button, { onClick: () => onSave(text), view: 'action' },
|
|
58
|
-
react_1.default.createElement("span", { className: (0, exports.cnDiagramHelper)({ 'prosemirror-stop-event': true }) },
|
|
58
|
+
react_1.default.createElement("span", { className: (0, exports.cnDiagramHelper)({ 'prosemirror-stop-event': true }) }, (0, common_1.i18n)('save'))))))));
|
|
59
59
|
};
|
|
60
60
|
const MermaidView = ({ onChange, node, getPos, view, getMermaidInstance }) => {
|
|
61
61
|
const [mermaidInstance, setMermaidInstance] = (0, react_1.useState)(null);
|
|
@@ -125,10 +125,7 @@ const CodeBlockHighlight = (builder, opts) => {
|
|
|
125
125
|
let from = pos + 1;
|
|
126
126
|
let nodes;
|
|
127
127
|
const lang = node.attrs[CodeBlockSpecs_1.codeBlockLangAttr];
|
|
128
|
-
if (
|
|
129
|
-
nodes = lowlight.highlightAuto(node.textContent).children;
|
|
130
|
-
}
|
|
131
|
-
else if (lowlight.registered(lang)) {
|
|
128
|
+
if (lang && lowlight.registered(lang)) {
|
|
132
129
|
nodes = lowlight.highlight(lang, node.textContent).children;
|
|
133
130
|
}
|
|
134
131
|
else {
|
|
@@ -55,12 +55,19 @@ const ImageSpecs = (builder) => {
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
toMd: (state, { attrs }) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
let result = ' {
|
|
64
|
+
result += state.esc(attrs.src);
|
|
65
|
+
}
|
|
66
|
+
if (attrs.title) {
|
|
67
|
+
result += ` ${state.quote(attrs.title)}`;
|
|
68
|
+
}
|
|
69
|
+
result += ')';
|
|
70
|
+
state.write(result);
|
|
64
71
|
},
|
|
65
72
|
}));
|
|
66
73
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ParseInsertedUrlAsImage } from '../../../../bundle';
|
|
2
|
+
import { ExtensionAuto } from '../../../../core';
|
|
3
|
+
export declare type ImageUrlPasteOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The function, used to determine if the pasted text is the image url and should be inserted as an image
|
|
6
|
+
*/
|
|
7
|
+
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
8
|
+
};
|
|
9
|
+
export declare const imageUrlPaste: ExtensionAuto<ImageUrlPasteOptions>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageUrlPaste = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
const utils_1 = require("../../../behavior/Clipboard/utils");
|
|
6
|
+
const ImageSpecs_1 = require("../ImageSpecs");
|
|
7
|
+
const imageUrlPaste = (builder, opts) => {
|
|
8
|
+
builder.addPlugin(() => new prosemirror_state_1.Plugin({
|
|
9
|
+
props: {
|
|
10
|
+
handleDOMEvents: {
|
|
11
|
+
paste(view, e) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (!opts.parseInsertedUrlAsImage ||
|
|
14
|
+
!e.clipboardData ||
|
|
15
|
+
view.state.selection.$from.parent.type.spec.code)
|
|
16
|
+
return false;
|
|
17
|
+
const { imageUrl, title } = opts.parseInsertedUrlAsImage((_a = e.clipboardData.getData(utils_1.DataTransferType.Text)) !== null && _a !== void 0 ? _a : '') || {};
|
|
18
|
+
if (!imageUrl) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
const imageNode = (0, ImageSpecs_1.imageType)(view.state.schema).create({
|
|
23
|
+
src: imageUrl,
|
|
24
|
+
alt: title,
|
|
25
|
+
});
|
|
26
|
+
const tr = view.state.tr.replaceSelectionWith(imageNode);
|
|
27
|
+
view.dispatch(tr.scrollIntoView());
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}), builder.Priority.High);
|
|
33
|
+
};
|
|
34
|
+
exports.imageUrlPaste = imageUrlPaste;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
2
|
import { AddImageAttrs } from './actions';
|
|
3
3
|
import { addImageAction } from './const';
|
|
4
|
+
import { ImageUrlPasteOptions } from './imageUrlPaste';
|
|
4
5
|
export { imageNodeName, imageType, ImageAttr } from './ImageSpecs';
|
|
5
6
|
/** @deprecated Use `imageType` instead */
|
|
6
7
|
export declare const imgType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
7
8
|
export type { AddImageAttrs } from './actions';
|
|
8
|
-
export declare
|
|
9
|
+
export declare type ImageOptions = ImageUrlPasteOptions;
|
|
10
|
+
export declare const Image: ExtensionAuto<ImageOptions | undefined>;
|
|
9
11
|
declare global {
|
|
10
12
|
namespace WysiwygEditor {
|
|
11
13
|
interface Actions {
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Image = exports.imgType = exports.ImageAttr = exports.imageType = exports.imageNodeName = void 0;
|
|
4
|
+
const lodash_1 = require("../../../lodash");
|
|
4
5
|
const ImageSpecs_1 = require("./ImageSpecs");
|
|
5
6
|
const actions_1 = require("./actions");
|
|
6
7
|
const const_1 = require("./const");
|
|
8
|
+
const imageUrlPaste_1 = require("./imageUrlPaste");
|
|
7
9
|
var ImageSpecs_2 = require("./ImageSpecs");
|
|
8
10
|
Object.defineProperty(exports, "imageNodeName", { enumerable: true, get: function () { return ImageSpecs_2.imageNodeName; } });
|
|
9
11
|
Object.defineProperty(exports, "imageType", { enumerable: true, get: function () { return ImageSpecs_2.imageType; } });
|
|
10
12
|
Object.defineProperty(exports, "ImageAttr", { enumerable: true, get: function () { return ImageSpecs_2.ImageAttr; } });
|
|
11
13
|
/** @deprecated Use `imageType` instead */
|
|
12
14
|
exports.imgType = ImageSpecs_1.imageType;
|
|
13
|
-
const Image = (builder) => {
|
|
15
|
+
const Image = (builder, opts) => {
|
|
14
16
|
builder.use(ImageSpecs_1.ImageSpecs);
|
|
15
17
|
builder.addAction(const_1.addImageAction, ({ schema }) => (0, actions_1.addImage)(schema));
|
|
18
|
+
if ((0, lodash_1.isFunction)(opts === null || opts === void 0 ? void 0 : opts.parseInsertedUrlAsImage)) {
|
|
19
|
+
builder.use(imageUrlPaste_1.imageUrlPaste, {
|
|
20
|
+
parseInsertedUrlAsImage: opts.parseInsertedUrlAsImage,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
16
23
|
};
|
|
17
24
|
exports.Image = Image;
|
|
@@ -6,7 +6,7 @@ export declare type ListsInputRulesOptions = {
|
|
|
6
6
|
export declare const ListsInputRulesExtension: ExtensionWithOptions<ListsInputRulesOptions>;
|
|
7
7
|
/**
|
|
8
8
|
* Given a list node type, returns an input rule that turns a number
|
|
9
|
-
* followed by a dot at the start of a textblock into an ordered list.
|
|
9
|
+
* followed by a dot or parenthesis at the start of a textblock into an ordered list.
|
|
10
10
|
*/
|
|
11
11
|
export declare function orderedListRule(nodeType: NodeType): import("prosemirror-inputrules").InputRule;
|
|
12
12
|
declare type BulletListInputRuleConfig = {
|
|
@@ -18,10 +18,13 @@ const ListsInputRulesExtension = (builder, options) => {
|
|
|
18
18
|
exports.ListsInputRulesExtension = ListsInputRulesExtension;
|
|
19
19
|
/**
|
|
20
20
|
* Given a list node type, returns an input rule that turns a number
|
|
21
|
-
* followed by a dot at the start of a textblock into an ordered list.
|
|
21
|
+
* followed by a dot or parenthesis at the start of a textblock into an ordered list.
|
|
22
22
|
*/
|
|
23
23
|
function orderedListRule(nodeType) {
|
|
24
|
-
return (0, inputrules_1.wrappingInputRule)(/^(\d+)
|
|
24
|
+
return (0, inputrules_1.wrappingInputRule)(/^(\d+)([.)])\s$/, nodeType, (match) => ({
|
|
25
|
+
[ListsSpecs_1.ListsAttr.Order]: Number(match[1]),
|
|
26
|
+
[ListsSpecs_1.ListsAttr.Markup]: match[2],
|
|
27
|
+
}), (match, node) => node.childCount + node.attrs[ListsSpecs_1.ListsAttr.Order] === Number(match[1]));
|
|
25
28
|
}
|
|
26
29
|
exports.orderedListRule = orderedListRule;
|
|
27
30
|
/**
|
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
7
7
|
const classname_1 = require("../../../../classname");
|
|
8
|
-
const suggest_1 = require("../../../../i18n/suggest");
|
|
9
8
|
const ErrorBoundary_1 = require("../../../../react-utils/ErrorBoundary");
|
|
10
9
|
const b = (0, classname_1.cn)('emoji-suggest');
|
|
11
10
|
const placement = ['bottom-start', 'top-start', 'bottom-end', 'top-end'];
|
|
@@ -20,9 +19,9 @@ function calcListHeight(itemsCount) {
|
|
|
20
19
|
const EmojiSuggestComponent = ({ anchor, currentIndex, items, onClick, onEnterKeyDown, onEscapeKeyDown, onOutsideClick, }) => {
|
|
21
20
|
if (!anchor)
|
|
22
21
|
return null;
|
|
23
|
-
return (react_1.default.createElement(uikit_1.Popup, { open:
|
|
22
|
+
return (react_1.default.createElement(uikit_1.Popup, { open: Boolean(items.length), anchorRef: { current: anchor }, placement: placement, onEnterKeyDown: onEnterKeyDown, onEscapeKeyDown: onEscapeKeyDown, onOutsideClick: onOutsideClick },
|
|
24
23
|
react_1.default.createElement("div", { className: b() },
|
|
25
|
-
react_1.default.createElement(uikit_1.List, { virtualized: true, items: items, sortable: false, filterable: false,
|
|
24
|
+
react_1.default.createElement(uikit_1.List, { virtualized: true, items: items, sortable: false, filterable: false, itemHeight: ITEM_HEIGHT, itemsHeight: calcListHeight(items.length), renderItem: renderItem, deactivateOnLeave: false, activeItemIndex: currentIndex, onItemClick: (_item, index) => onClick(index), className: b('list'), itemClassName: b('list-item') }))));
|
|
26
25
|
};
|
|
27
26
|
exports.EmojiSuggestComponent = EmojiSuggestComponent;
|
|
28
27
|
function renderItem({ origName, symbol, origShortcuts }) {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { ParseInsertedUrlAsImage } from '../../../../bundle';
|
|
1
2
|
import { ExtensionAuto } from '../../../../core';
|
|
2
|
-
import { FileUploadHandler } from '../../../../utils
|
|
3
|
+
import { FileUploadHandler } from '../../../../utils';
|
|
3
4
|
import { CreateImageNodeOptions } from '../utils';
|
|
4
|
-
export declare type ImagePasteOptions = Pick<CreateImageNodeOptions, '
|
|
5
|
-
imageUploadHandler
|
|
5
|
+
export declare type ImagePasteOptions = Pick<CreateImageNodeOptions, 'needDimensions' | 'enableNewImageSizeCalculation'> & {
|
|
6
|
+
imageUploadHandler?: FileUploadHandler;
|
|
7
|
+
/**
|
|
8
|
+
* The function, used to determine if the pasted text is the image url and should be inserted as an image
|
|
9
|
+
*/
|
|
10
|
+
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
6
11
|
};
|
|
7
12
|
export declare const ImagePaste: ExtensionAuto<ImagePasteOptions>;
|
|
@@ -7,27 +7,47 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
7
7
|
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
8
8
|
const lodash_1 = require("../../../../lodash");
|
|
9
9
|
const Clipboard_1 = require("../../../behavior/Clipboard");
|
|
10
|
+
const utils_1 = require("../../../behavior/Clipboard/utils");
|
|
10
11
|
const specs_1 = require("../../../specs");
|
|
11
|
-
const
|
|
12
|
+
const utils_2 = require("../utils");
|
|
12
13
|
const upload_1 = require("./upload");
|
|
13
14
|
const { isFilesFromHtml, isFilesOnly, isImageFile } = Clipboard_1.clipboardUtils;
|
|
14
15
|
const ImagePaste = (builder, opts) => {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const { parseInsertedUrlAsImage, imageUploadHandler } = opts !== null && opts !== void 0 ? opts : {};
|
|
17
|
+
if (!(0, lodash_1.isFunction)(imageUploadHandler !== null && imageUploadHandler !== void 0 ? imageUploadHandler : parseInsertedUrlAsImage))
|
|
18
|
+
throw new Error(`ImagePaste extension: ${opts.imageUploadHandler ? 'imageUploadHandler' : 'parseInsertedUrlAsImage'} is not a function`);
|
|
17
19
|
builder.addPlugin(() => new prosemirror_state_1.Plugin({
|
|
18
20
|
props: {
|
|
19
21
|
handleDOMEvents: {
|
|
20
22
|
paste(view, e) {
|
|
23
|
+
var _a, _b;
|
|
21
24
|
const files = getPastedImages(e.clipboardData);
|
|
22
|
-
if (files) {
|
|
25
|
+
if (imageUploadHandler && files) {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
new upload_1.ImagesUploadProcess(view, files, imageUploadHandler, view.state.tr.selection.from, opts).run();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
else if (parseInsertedUrlAsImage) {
|
|
31
|
+
const { imageUrl, title } = parseInsertedUrlAsImage((_b = (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.getData(utils_1.DataTransferType.Text)) !== null && _b !== void 0 ? _b : '') || {};
|
|
32
|
+
if (!imageUrl) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
23
35
|
e.preventDefault();
|
|
24
|
-
|
|
36
|
+
const imageNode = (0, specs_1.imageType)(view.state.schema).create({
|
|
37
|
+
src: imageUrl,
|
|
38
|
+
alt: title,
|
|
39
|
+
});
|
|
40
|
+
const tr = view.state.tr.replaceSelectionWith(imageNode);
|
|
41
|
+
view.dispatch(tr.scrollIntoView());
|
|
25
42
|
return true;
|
|
26
43
|
}
|
|
27
44
|
return false;
|
|
28
45
|
},
|
|
29
46
|
drop(view, e) {
|
|
30
47
|
var _a, _b;
|
|
48
|
+
if (!imageUploadHandler) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
31
51
|
// handle drop images from device
|
|
32
52
|
if (view.dragging)
|
|
33
53
|
return false;
|
|
@@ -39,19 +59,22 @@ const ImagePaste = (builder, opts) => {
|
|
|
39
59
|
return false;
|
|
40
60
|
const posToInsert = (0, prosemirror_transform_1.dropPoint)(view.state.doc, dropPos, createFakeImageSlice(view.state.schema));
|
|
41
61
|
if (posToInsert !== null) {
|
|
42
|
-
new upload_1.ImagesUploadProcess(view, files,
|
|
62
|
+
new upload_1.ImagesUploadProcess(view, files, imageUploadHandler, posToInsert, opts).run();
|
|
43
63
|
}
|
|
44
64
|
e.preventDefault();
|
|
45
65
|
return true;
|
|
46
66
|
},
|
|
47
67
|
},
|
|
48
68
|
handlePaste(view, _event, slice) {
|
|
69
|
+
if (!imageUploadHandler) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
49
72
|
const node = sliceSingleNode(slice);
|
|
50
|
-
if (node && (0,
|
|
73
|
+
if (node && (0, utils_2.isImageNode)(node)) {
|
|
51
74
|
const imgUrl = node.attrs[specs_1.ImgSizeAttr.Src];
|
|
52
75
|
const imgFile = dataUrlToFile(imgUrl, 'image');
|
|
53
76
|
if (imgFile) {
|
|
54
|
-
new upload_1.ImagesUploadProcess(view, [imgFile],
|
|
77
|
+
new upload_1.ImagesUploadProcess(view, [imgFile], imageUploadHandler, view.state.tr.selection.from, opts).run();
|
|
55
78
|
return true;
|
|
56
79
|
}
|
|
57
80
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Node } from 'prosemirror-model';
|
|
2
2
|
import { EditorView } from 'prosemirror-view';
|
|
3
|
-
import { FileUploadHandler, UploadSuccessItem } from '../../../../utils
|
|
3
|
+
import { FileUploadHandler, UploadSuccessItem } from '../../../../utils';
|
|
4
4
|
import { FilesBatchUploadProcess } from '../../../behavior/utils/upload';
|
|
5
5
|
import { CreateImageNodeOptions } from '../utils';
|
|
6
6
|
import { ImageSkeletonDescriptor } from './skeleton';
|
|
7
7
|
export declare class ImagesUploadProcess extends FilesBatchUploadProcess {
|
|
8
8
|
protected readonly createImage: ({ result, file }: UploadSuccessItem) => Promise<Node>;
|
|
9
9
|
protected readonly initPosition: number;
|
|
10
|
+
private readonly enableNewImageSizeCalculation?;
|
|
10
11
|
constructor(view: EditorView, files: readonly File[], uploadHandler: FileUploadHandler, position: number, opts: CreateImageNodeOptions);
|
|
11
12
|
protected createSkeleton(): Promise<ImageSkeletonDescriptor>;
|
|
12
13
|
protected createPMNode(res: UploadSuccessItem): Promise<Node>;
|