@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
|
@@ -2,30 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImagesUploadProcess = void 0;
|
|
4
4
|
const logger_1 = require("../../../../logger");
|
|
5
|
+
const utils_1 = require("../../../../utils");
|
|
5
6
|
const upload_1 = require("../../../behavior/utils/upload");
|
|
6
7
|
const markdown_1 = require("../../../markdown");
|
|
7
8
|
const const_1 = require("../const");
|
|
8
|
-
const
|
|
9
|
+
const utils_2 = require("../utils");
|
|
9
10
|
const skeleton_1 = require("./skeleton");
|
|
10
11
|
class ImagesUploadProcess extends upload_1.FilesBatchUploadProcess {
|
|
11
12
|
constructor(view, files, uploadHandler, position, opts) {
|
|
12
13
|
super(view, files, uploadHandler);
|
|
13
14
|
this.initPosition = position;
|
|
14
|
-
this.createImage = (0,
|
|
15
|
+
this.createImage = (0, utils_2.createImageNode)((0, markdown_1.imageType)(this.view.state.schema), opts);
|
|
16
|
+
this.enableNewImageSizeCalculation = opts.enableNewImageSizeCalculation;
|
|
15
17
|
}
|
|
16
18
|
async createSkeleton() {
|
|
17
|
-
return new skeleton_1.ImageSkeletonDescriptor(this.initPosition, await getSkeletonSize(this.files
|
|
19
|
+
return new skeleton_1.ImageSkeletonDescriptor(this.initPosition, await getSkeletonSize(this.files, {
|
|
20
|
+
enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
|
|
21
|
+
}));
|
|
18
22
|
}
|
|
19
23
|
async createPMNode(res) {
|
|
20
24
|
return this.createImage(res);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
exports.ImagesUploadProcess = ImagesUploadProcess;
|
|
24
|
-
async function getSkeletonSize(files) {
|
|
28
|
+
async function getSkeletonSize(files, opts) {
|
|
25
29
|
const skeletonSize = { width: '300', height: '200' };
|
|
26
30
|
if (files.length === 1) {
|
|
27
31
|
try {
|
|
28
|
-
const size = await (0,
|
|
32
|
+
const size = await (0, utils_2.loadImage)(files[0]).then((opts === null || opts === void 0 ? void 0 : opts.enableNewImageSizeCalculation) ? calcSkeletonSizeNew : calcSkeletonSize);
|
|
29
33
|
skeletonSize.width = String(size.width);
|
|
30
34
|
skeletonSize.height = String(size.height);
|
|
31
35
|
}
|
|
@@ -35,10 +39,16 @@ async function getSkeletonSize(files) {
|
|
|
35
39
|
}
|
|
36
40
|
return skeletonSize;
|
|
37
41
|
}
|
|
38
|
-
function calcSkeletonSize(
|
|
39
|
-
const { width, height } = img;
|
|
42
|
+
function calcSkeletonSize({ width, height }) {
|
|
40
43
|
if (height <= const_1.IMG_MAX_HEIGHT)
|
|
41
44
|
return { width, height };
|
|
42
45
|
const ratio = const_1.IMG_MAX_HEIGHT / height; // ratio<1
|
|
43
46
|
return { height: const_1.IMG_MAX_HEIGHT, width: width * ratio };
|
|
44
47
|
}
|
|
48
|
+
function calcSkeletonSizeNew({ width, height }) {
|
|
49
|
+
return (0, utils_1.getProportionalSize)({
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
imgMaxHeight: const_1.IMG_MAX_HEIGHT,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -78,7 +78,7 @@ class ImageWidgetHandler {
|
|
|
78
78
|
return;
|
|
79
79
|
const { view } = this;
|
|
80
80
|
new upload_1.ImagesUploadProcess(view, files, this.uploadImages, this.getPos(), {
|
|
81
|
-
|
|
81
|
+
needDimensions: this.needToSetDimensionsForUploadedImages,
|
|
82
82
|
}).run();
|
|
83
83
|
view.dispatch((0, exports.removeWidget)(view.state.tr, this.decoId));
|
|
84
84
|
view.focus();
|
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "ImgSizeAttr", { enumerable: true, get: function
|
|
|
11
11
|
const ImgSizeSpecs = (builder, opts) => {
|
|
12
12
|
var _a;
|
|
13
13
|
const placeholderContent = (_a = builder.context.get('placeholder')) === null || _a === void 0 ? void 0 : _a.imgSize;
|
|
14
|
-
builder.configureMd((md) => md.use(imsize_1.default, { log: log_1.default }));
|
|
14
|
+
builder.configureMd((md) => md.use(imsize_1.default, { log: log_1.default, enableInlineStyling: true }));
|
|
15
15
|
builder.addNode(const_1.imageNodeName, () => ({
|
|
16
16
|
spec: {
|
|
17
17
|
inline: true,
|
|
@@ -66,13 +66,20 @@ const ImgSizeSpecs = (builder, opts) => {
|
|
|
66
66
|
},
|
|
67
67
|
toMd: (state, node) => {
|
|
68
68
|
const attrs = node.attrs;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
let result = ' {
|
|
75
|
+
result += state.esc(attrs.src);
|
|
76
|
+
}
|
|
77
|
+
if (attrs.title) {
|
|
78
|
+
result += ` ${state.quote(attrs.title)}`;
|
|
79
|
+
}
|
|
80
|
+
result += getSize(attrs);
|
|
81
|
+
result += ')';
|
|
82
|
+
state.write(result);
|
|
76
83
|
},
|
|
77
84
|
}));
|
|
78
85
|
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
|
-
import
|
|
2
|
+
import { ImagePasteOptions } from './ImagePaste';
|
|
3
3
|
import { ImgSizeSpecsOptions } from './ImgSizeSpecs';
|
|
4
4
|
import { AddImageAttrs } from './actions';
|
|
5
5
|
import { addImageAction } from './const';
|
|
6
6
|
export declare type ImgSizeOptions = ImgSizeSpecsOptions & {
|
|
7
|
-
imageUploadHandler?: FileUploadHandler;
|
|
8
7
|
/**
|
|
9
8
|
* If we need to set dimensions for uploaded images
|
|
10
9
|
*
|
|
11
10
|
* @default false
|
|
12
11
|
*/
|
|
13
12
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
14
|
-
}
|
|
13
|
+
} & Pick<ImagePasteOptions, 'imageUploadHandler' | 'parseInsertedUrlAsImage' | 'enableNewImageSizeCalculation'>;
|
|
15
14
|
export declare const ImgSize: ExtensionAuto<ImgSizeOptions>;
|
|
16
15
|
declare global {
|
|
17
16
|
namespace WysiwygEditor {
|
|
@@ -13,10 +13,12 @@ const ImgSize = (builder, opts) => {
|
|
|
13
13
|
imageUploadHandler: opts.imageUploadHandler,
|
|
14
14
|
needToSetDimensionsForUploadedImages: Boolean(opts.needToSetDimensionsForUploadedImages),
|
|
15
15
|
});
|
|
16
|
-
if (opts.imageUploadHandler) {
|
|
16
|
+
if (opts.imageUploadHandler || opts.parseInsertedUrlAsImage) {
|
|
17
17
|
builder.use(ImagePaste_1.ImagePaste, {
|
|
18
18
|
imageUploadHandler: opts.imageUploadHandler,
|
|
19
|
-
|
|
19
|
+
needDimensions: Boolean(opts.needToSetDimensionsForUploadedImages),
|
|
20
|
+
parseInsertedUrlAsImage: opts.parseInsertedUrlAsImage,
|
|
21
|
+
enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation,
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
builder.addAction(const_1.addImageAction, ({ schema }) => (0, actions_1.addImage)(schema));
|
|
@@ -40,10 +40,18 @@ const ImageNodeView = ({ node, view, getPos, updateAttributes, }) => {
|
|
|
40
40
|
onResize: handleResize,
|
|
41
41
|
});
|
|
42
42
|
const style = {
|
|
43
|
-
width: state.width ? `${state.width}px` : '',
|
|
44
|
-
height: state.height ? `${state.height}px` : '',
|
|
45
43
|
transition: 'width 0.15s ease-out, height 0.15s ease-out',
|
|
46
44
|
};
|
|
45
|
+
if (state.width) {
|
|
46
|
+
style.width = `${state.width}px`;
|
|
47
|
+
if (state.height) {
|
|
48
|
+
style.aspectRatio = state.width / state.height;
|
|
49
|
+
style.height = 'auto;';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (state.height) {
|
|
53
|
+
style.height = `${state.height}px`;
|
|
54
|
+
}
|
|
47
55
|
const handleDelete = (0, react_1.useCallback)(() => {
|
|
48
56
|
const pos = getPos();
|
|
49
57
|
if (pos === undefined)
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Node, NodeType } from 'prosemirror-model';
|
|
2
|
-
import { UploadSuccessItem } from '../../../utils
|
|
2
|
+
import { UploadSuccessItem } from '../../../utils';
|
|
3
3
|
import { ImgSizeAttr } from '../../specs';
|
|
4
4
|
export declare function isImageNode(node: Node): boolean;
|
|
5
5
|
export declare type CreateImageNodeOptions = {
|
|
6
|
-
|
|
6
|
+
needDimensions: boolean;
|
|
7
|
+
enableNewImageSizeCalculation?: boolean;
|
|
7
8
|
};
|
|
8
9
|
export declare const createImageNode: (imgType: NodeType, opts: CreateImageNodeOptions) => ({ result, file }: UploadSuccessItem) => Promise<Node>;
|
|
9
10
|
export declare function loadImage(imgFile: File): Promise<HTMLImageElement>;
|
|
10
11
|
export declare function getImageSize(img: HTMLImageElement): {
|
|
12
|
+
[ImgSizeAttr.Height]?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function getImageSizeNew({ width, height }: HTMLImageElement): {
|
|
11
15
|
[ImgSizeAttr.Width]?: string;
|
|
12
16
|
[ImgSizeAttr.Height]?: string;
|
|
13
17
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImageSize = exports.loadImage = exports.createImageNode = exports.isImageNode = void 0;
|
|
3
|
+
exports.getImageSizeNew = exports.getImageSize = exports.loadImage = exports.createImageNode = exports.isImageNode = void 0;
|
|
4
4
|
const logger_1 = require("../../../logger");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
5
6
|
const markdown_1 = require("../../markdown");
|
|
6
7
|
const specs_1 = require("../../specs");
|
|
7
8
|
const const_1 = require("./const");
|
|
@@ -15,9 +16,9 @@ const createImageNode = (imgType, opts) => async ({ result, file }) => {
|
|
|
15
16
|
[specs_1.ImgSizeAttr.Src]: result.url,
|
|
16
17
|
[specs_1.ImgSizeAttr.Alt]: (_a = result.name) !== null && _a !== void 0 ? _a : file.name,
|
|
17
18
|
};
|
|
18
|
-
if (opts.
|
|
19
|
+
if (opts.needDimensions) {
|
|
19
20
|
try {
|
|
20
|
-
const sizes = await loadImage(file).then(getImageSize);
|
|
21
|
+
const sizes = await loadImage(file).then(opts.enableNewImageSizeCalculation ? getImageSizeNew : getImageSize);
|
|
21
22
|
Object.assign(attrs, sizes);
|
|
22
23
|
}
|
|
23
24
|
catch (err) {
|
|
@@ -43,3 +44,12 @@ function getImageSize(img) {
|
|
|
43
44
|
return { height: String(Math.min(const_1.IMG_MAX_HEIGHT, img.height)) };
|
|
44
45
|
}
|
|
45
46
|
exports.getImageSize = getImageSize;
|
|
47
|
+
function getImageSizeNew({ width, height }) {
|
|
48
|
+
const size = (0, utils_1.getProportionalSize)({
|
|
49
|
+
width,
|
|
50
|
+
height,
|
|
51
|
+
imgMaxHeight: const_1.IMG_MAX_HEIGHT,
|
|
52
|
+
});
|
|
53
|
+
return { width: String(size.width), height: String(size.height) };
|
|
54
|
+
}
|
|
55
|
+
exports.getImageSizeNew = getImageSizeNew;
|
|
@@ -65,7 +65,7 @@ const VideoSpecs = (builder, opts) => {
|
|
|
65
65
|
type: 'text/html',
|
|
66
66
|
width: String(options[service].width),
|
|
67
67
|
height: String(options[service].height),
|
|
68
|
-
src: options.
|
|
68
|
+
src: options.videoUrl(service, videoId, options),
|
|
69
69
|
frameborder: '0',
|
|
70
70
|
webkitallowfullscreen: '',
|
|
71
71
|
mozallowfullscreen: '',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExtensionAuto } from '../../../../core';
|
|
2
|
-
import { FileUploadHandler } from '../../../../utils
|
|
2
|
+
import { FileUploadHandler } from '../../../../utils';
|
|
3
3
|
export declare type YfmFilePasteOptions = {
|
|
4
4
|
fileUploadHandler: FileUploadHandler;
|
|
5
5
|
needToSetDimensionsForUploadedImages: boolean;
|
|
@@ -76,7 +76,7 @@ class YfmFilesPasteUploadProcess extends upload_1.YfmFilesUploadProcessBase {
|
|
|
76
76
|
const { schema } = this.view.state;
|
|
77
77
|
if ((0, markdown_1.imageType)(schema)) {
|
|
78
78
|
this.createImage = (0, utils_1.createImageNode)((0, markdown_1.imageType)(schema), {
|
|
79
|
-
|
|
79
|
+
needDimensions: opts.needToSetDimensionsForUploadedImages,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const i18n: <G extends "bold" | "code" | "
|
|
1
|
+
export declare const i18n: <G extends "bold" | "code" | "colorify" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "list" | "heading" | "note" | "file" | "checkbox" | "emoji" | "undo" | "redo" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "math_inline" | "math_block" | "tabs" | "mermaid" | "gpt" | "codeblock" | "math" | "colorify__color_blue" | "colorify__color_default" | "colorify__color_gray" | "colorify__color_green" | "colorify__color_orange" | "colorify__color_red" | "colorify__color_violet" | "colorify__color_yellow" | "colorify__group_text" | "folding-heading" | "folding-heading_hint" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "more_action" | "olist" | "ulist", S extends string>(key: G | (string extends S ? S : never), params?: {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
} | undefined) => S extends G ? {
|
|
4
4
|
bold: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const i18n: <G extends "block" | "heading" | "
|
|
1
|
+
export declare const i18n: <G extends "block" | "heading" | "checkbox" | "doc_empty" | "codeblock" | "deflist_term" | "deflist_desc" | "cut_title" | "cut_content" | "note_title" | "note_content" | "layout_cell" | "table_cell" | "select_filter", S extends string>(key: G | (string extends S ? S : never), params?: {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
} | undefined) => S extends G ? {
|
|
4
4
|
doc_empty: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const i18n: <G extends "remove" | "info" | "
|
|
1
|
+
export declare const i18n: <G extends "remove" | "info" | "warning" | "tip" | "alert", S extends string>(key: G | (string extends S ? S : never), params?: {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
} | undefined) => S extends G ? {
|
|
4
4
|
info: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { autocompletion } from '@codemirror/autocomplete';
|
|
2
2
|
import type { Extension, StateCommand } from '@codemirror/state';
|
|
3
3
|
import { EditorView, EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
|
|
4
|
+
import type { ParseInsertedUrlAsImage } from '../../bundle';
|
|
4
5
|
import { EventMap } from '../../bundle/Editor';
|
|
5
6
|
import { ReactRenderStorage } from '../../extensions';
|
|
6
7
|
import { Receiver } from '../../utils';
|
|
@@ -18,7 +19,9 @@ export declare type CreateCodemirrorParams = {
|
|
|
18
19
|
onScroll: (event: Event) => void;
|
|
19
20
|
reactRenderer: ReactRenderStorage;
|
|
20
21
|
uploadHandler?: FileUploadHandler;
|
|
21
|
-
|
|
22
|
+
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
23
|
+
needImageDimensions?: boolean;
|
|
24
|
+
enableNewImageSizeCalculation?: boolean;
|
|
22
25
|
extensions?: Extension[];
|
|
23
26
|
disabledExtensions?: {
|
|
24
27
|
history?: boolean;
|
|
@@ -6,6 +6,7 @@ const commands_1 = require("@codemirror/commands");
|
|
|
6
6
|
const language_1 = require("@codemirror/language");
|
|
7
7
|
const view_1 = require("@codemirror/view");
|
|
8
8
|
const action_names_1 = require("../../bundle/config/action-names");
|
|
9
|
+
const utils_1 = require("../../extensions/behavior/Clipboard/utils");
|
|
9
10
|
const logger_1 = require("../../logger");
|
|
10
11
|
const shortcuts_1 = require("../../shortcuts");
|
|
11
12
|
const commands_2 = require("../commands");
|
|
@@ -16,7 +17,7 @@ const react_facet_1 = require("./react-facet");
|
|
|
16
17
|
const plugin_1 = require("./search-plugin/plugin");
|
|
17
18
|
const yfm_1 = require("./yfm");
|
|
18
19
|
function createCodemirror(params) {
|
|
19
|
-
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, } = params;
|
|
20
|
+
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, } = params;
|
|
20
21
|
const extensions = [gravity_1.gravityTheme, (0, view_1.placeholder)(placeholderContent)];
|
|
21
22
|
if (!disabledExtensions.history) {
|
|
22
23
|
extensions.push((0, commands_1.history)());
|
|
@@ -66,6 +67,23 @@ function createCodemirror(params) {
|
|
|
66
67
|
scroll(event) {
|
|
67
68
|
onScroll(event);
|
|
68
69
|
},
|
|
70
|
+
paste(event, editor) {
|
|
71
|
+
var _a;
|
|
72
|
+
if (event.clipboardData && parseInsertedUrlAsImage) {
|
|
73
|
+
const { imageUrl, title } = parseInsertedUrlAsImage((_a = event.clipboardData.getData(utils_1.DataTransferType.Text)) !== null && _a !== void 0 ? _a : '') || {};
|
|
74
|
+
if (!imageUrl) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
(0, commands_2.insertImages)([
|
|
79
|
+
{
|
|
80
|
+
url: imageUrl,
|
|
81
|
+
alt: title,
|
|
82
|
+
title,
|
|
83
|
+
},
|
|
84
|
+
])(editor);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
69
87
|
}), (0, plugin_1.SearchPanelPlugin)({
|
|
70
88
|
anchorSelector: '.g-md-search-anchor',
|
|
71
89
|
receiver,
|
|
@@ -73,7 +91,8 @@ function createCodemirror(params) {
|
|
|
73
91
|
if (params.uploadHandler) {
|
|
74
92
|
extensions.push(files_upload_facet_1.FileUploadHandlerFacet.of({
|
|
75
93
|
fn: params.uploadHandler,
|
|
76
|
-
|
|
94
|
+
imageWithDimensions: params.needImageDimensions,
|
|
95
|
+
enableNewImageSizeCalculation: params.enableNewImageSizeCalculation,
|
|
77
96
|
}));
|
|
78
97
|
}
|
|
79
98
|
if (extraExtensions) {
|
|
@@ -3,8 +3,10 @@ import type { FileUploadHandler } from '../../utils/upload';
|
|
|
3
3
|
export type { FileUploadHandler };
|
|
4
4
|
export declare const FileUploadHandlerFacet: Facet<{
|
|
5
5
|
fn: FileUploadHandler;
|
|
6
|
-
|
|
6
|
+
imageWithDimensions?: boolean | undefined;
|
|
7
|
+
enableNewImageSizeCalculation?: boolean | undefined;
|
|
7
8
|
}, {
|
|
8
9
|
fn: FileUploadHandler;
|
|
9
|
-
|
|
10
|
+
imageWithDimensions?: boolean | undefined;
|
|
11
|
+
enableNewImageSizeCalculation?: boolean | undefined;
|
|
10
12
|
}>;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FilesUploadPlugin = void 0;
|
|
4
4
|
const view_1 = require("@codemirror/view");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
5
6
|
const files_upload_facet_1 = require("../files-upload-facet");
|
|
6
7
|
const react_facet_1 = require("../react-facet");
|
|
7
8
|
const const_1 = require("./const");
|
|
8
9
|
const effects_1 = require("./effects");
|
|
9
|
-
const
|
|
10
|
+
const utils_2 = require("./utils");
|
|
10
11
|
const widget_1 = require("./widget");
|
|
11
12
|
class FileUploadWidget extends view_1.WidgetType {
|
|
12
13
|
constructor(id) {
|
|
@@ -61,7 +62,7 @@ class FileUploadPresenter {
|
|
|
61
62
|
this.widget.render({
|
|
62
63
|
status: 'success',
|
|
63
64
|
fileName: this.file.name,
|
|
64
|
-
fileType: (0,
|
|
65
|
+
fileType: (0, utils_2.isImageFile)(this.file) ? 'image' : 'file',
|
|
65
66
|
});
|
|
66
67
|
setTimeout(async () => {
|
|
67
68
|
const markup = await this.formatFileMarkup(res);
|
|
@@ -82,7 +83,7 @@ class FileUploadPresenter {
|
|
|
82
83
|
this.widget.render({
|
|
83
84
|
status: 'error',
|
|
84
85
|
fileName: this.file.name,
|
|
85
|
-
fileType: (0,
|
|
86
|
+
fileType: (0, utils_2.isImageFile)(this.file) ? 'image' : 'file',
|
|
86
87
|
errorText: String(err),
|
|
87
88
|
onReUploadClick: () => {
|
|
88
89
|
if (this.state === 'error')
|
|
@@ -94,7 +95,8 @@ class FileUploadPresenter {
|
|
|
94
95
|
this.view = params.view;
|
|
95
96
|
this.widget = params.widget;
|
|
96
97
|
this.uploader = params.uploader;
|
|
97
|
-
this.
|
|
98
|
+
this.needDimensionsForImages = params.needDimensionsForImages;
|
|
99
|
+
this.enableNewImageSizeCalculation = params.enableNewImageSizeCalculation;
|
|
98
100
|
this.widget.setPresenter(this);
|
|
99
101
|
this.run();
|
|
100
102
|
}
|
|
@@ -106,28 +108,36 @@ class FileUploadPresenter {
|
|
|
106
108
|
this.widget.render({
|
|
107
109
|
status: 'uploading',
|
|
108
110
|
fileName: this.file.name,
|
|
109
|
-
fileType: (0,
|
|
111
|
+
fileType: (0, utils_2.isImageFile)(this.file) ? 'image' : 'file',
|
|
110
112
|
});
|
|
111
113
|
this.uploader(this.file).then(this.onUploadSuccess, this.onUploadError);
|
|
112
114
|
}
|
|
113
115
|
async formatFileMarkup(res) {
|
|
114
116
|
var _a, _b;
|
|
115
117
|
const fileName = (_b = (_a = res.name) !== null && _a !== void 0 ? _a : this.file.name) !== null && _b !== void 0 ? _b : '';
|
|
116
|
-
let markup
|
|
117
|
-
if ((0,
|
|
118
|
-
if (this.
|
|
118
|
+
let markup = `(this.file)) {
|
|
120
|
+
if (this.needDimensionsForImages) {
|
|
119
121
|
try {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
const fileSize = await (0, utils_2.getImageDimensions)(this.file);
|
|
123
|
+
if (this.enableNewImageSizeCalculation) {
|
|
124
|
+
const { width, height } = (0, utils_1.getProportionalSize)({
|
|
125
|
+
width: fileSize.width,
|
|
126
|
+
height: fileSize.height,
|
|
127
|
+
imgMaxHeight: const_1.IMG_MAX_HEIGHT,
|
|
128
|
+
});
|
|
129
|
+
markup += ` =${width}x${height}`;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const height = Math.min(fileSize.height, const_1.IMG_MAX_HEIGHT);
|
|
133
|
+
markup += ` =x${height}`;
|
|
134
|
+
}
|
|
123
135
|
}
|
|
124
136
|
catch (err) {
|
|
125
|
-
|
|
137
|
+
console.error(err);
|
|
126
138
|
}
|
|
127
139
|
}
|
|
128
|
-
|
|
129
|
-
markup = ``;
|
|
130
|
-
}
|
|
140
|
+
markup += `)`;
|
|
131
141
|
}
|
|
132
142
|
else {
|
|
133
143
|
markup = `{% file src="${res.url}" name="${fileName.replace('"', '')}" %}`;
|
|
@@ -153,8 +163,9 @@ exports.FilesUploadPlugin = view_1.ViewPlugin.fromClass(class {
|
|
|
153
163
|
file,
|
|
154
164
|
view: this.view,
|
|
155
165
|
uploader: uploadFacet.fn,
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
needDimensionsForImages: Boolean(uploadFacet.imageWithDimensions),
|
|
167
|
+
enableNewImageSizeCalculation: Boolean(uploadFacet.enableNewImageSizeCalculation),
|
|
168
|
+
widget: new FileUploadWidget((0, utils_2.uniqueId)('__file_widget_id')),
|
|
158
169
|
});
|
|
159
170
|
return view_1.Decoration.widget({
|
|
160
171
|
widget,
|
|
@@ -190,7 +201,7 @@ exports.FilesUploadPlugin = view_1.ViewPlugin.fromClass(class {
|
|
|
190
201
|
paste(event, view) {
|
|
191
202
|
if (!event.clipboardData)
|
|
192
203
|
return false;
|
|
193
|
-
const files = (0,
|
|
204
|
+
const files = (0, utils_2.getTransferFiles)(event.clipboardData);
|
|
194
205
|
if (!files)
|
|
195
206
|
return false;
|
|
196
207
|
const { from, to } = view.state.selection.main;
|
|
@@ -205,7 +216,7 @@ exports.FilesUploadPlugin = view_1.ViewPlugin.fromClass(class {
|
|
|
205
216
|
drop(event, view) {
|
|
206
217
|
if (!event.dataTransfer)
|
|
207
218
|
return false;
|
|
208
|
-
const files = (0,
|
|
219
|
+
const files = (0, utils_2.getTransferFiles)(event.dataTransfer);
|
|
209
220
|
if (!files)
|
|
210
221
|
return false;
|
|
211
222
|
const pos = this.view.posAtCoords(event, false);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTransferFiles = exports.loadImage = exports.getImageDimensions = exports.isImageFile = exports.uniqueId = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
5
|
var lodash_1 = require("../../../lodash");
|
|
6
6
|
Object.defineProperty(exports, "uniqueId", { enumerable: true, get: function () { return lodash_1.uniqueId; } });
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "isImageFile", { enumerable: true, get: function () { return
|
|
7
|
+
var clipboard_1 = require("../../../utils/clipboard");
|
|
8
|
+
Object.defineProperty(exports, "isImageFile", { enumerable: true, get: function () { return clipboard_1.isImageFile; } });
|
|
9
9
|
async function getImageDimensions(imgFile) {
|
|
10
10
|
const img = await loadImage(imgFile);
|
|
11
11
|
return { width: img.naturalWidth, height: img.naturalHeight };
|
|
@@ -26,7 +26,7 @@ exports.loadImage = loadImage;
|
|
|
26
26
|
function getTransferFiles(data) {
|
|
27
27
|
if (!data)
|
|
28
28
|
return null;
|
|
29
|
-
if (!(0,
|
|
29
|
+
if (!(0, utils_1.isFilesOnly)(data) && !(0, utils_1.isFilesFromHtml)(data))
|
|
30
30
|
return null;
|
|
31
31
|
return Array.from(data.files);
|
|
32
32
|
}
|
|
@@ -8,7 +8,7 @@ export declare const customTags: {
|
|
|
8
8
|
};
|
|
9
9
|
export declare type YfmNoteType = 'info' | 'tip' | 'warning' | 'alert';
|
|
10
10
|
export declare const yfmNoteTypes: readonly YfmNoteType[];
|
|
11
|
-
export declare const yfmNoteSnippetTemplate: (type: YfmNoteType) => "{% note info %}\n\n#{}\n\n{% endnote %}\n\n" | "{% note
|
|
11
|
+
export declare const yfmNoteSnippetTemplate: (type: YfmNoteType) => "{% note info %}\n\n#{}\n\n{% endnote %}\n\n" | "{% note warning %}\n\n#{}\n\n{% endnote %}\n\n" | "{% note tip %}\n\n#{}\n\n{% endnote %}\n\n" | "{% note alert %}\n\n#{}\n\n{% endnote %}\n\n";
|
|
12
12
|
export declare const yfmNoteSnippets: Record<YfmNoteType, ReturnType<typeof snippet>>;
|
|
13
13
|
export declare const yfmCutSnippetTemplate = "{% cut \"#{title}\" %}\n\n#{}\n\n{% endcut %}\n\n";
|
|
14
14
|
export declare const yfmCutSnippet: (editor: {
|
|
@@ -26,9 +26,15 @@ function insertImages(images) {
|
|
|
26
26
|
return ({ state, dispatch }) => {
|
|
27
27
|
const markup = images
|
|
28
28
|
.map(({ title, url, alt, width, height }) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
let result = ` {
|
|
31
|
+
result += ` "${title}`;
|
|
32
|
+
}
|
|
33
|
+
if (width !== undefined || height !== undefined) {
|
|
34
|
+
result += ` =${width !== null && width !== void 0 ? width : ''}x${height !== null && height !== void 0 ? height : ''}`;
|
|
35
|
+
}
|
|
36
|
+
result += ')';
|
|
37
|
+
return result;
|
|
32
38
|
})
|
|
33
39
|
.join(' ');
|
|
34
40
|
const tr = state.changeByRange((range) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Extension, ExtensionAuto } from '../core';
|
|
2
|
-
import { BlockquoteOptions, BoldOptions, BreaksOptions, CodeBlockOptions, CodeOptions, HeadingOptions, ItalicOptions, LinkOptions, ListsOptions } from '../extensions/markdown';
|
|
2
|
+
import { BlockquoteOptions, BoldOptions, BreaksOptions, CodeBlockOptions, CodeOptions, HeadingOptions, ImageOptions, ItalicOptions, LinkOptions, ListsOptions } from '../extensions/markdown';
|
|
3
3
|
import { ZeroPresetOptions } from './zero';
|
|
4
4
|
export declare type CommonMarkPresetOptions = ZeroPresetOptions & {
|
|
5
5
|
bold?: BoldOptions;
|
|
@@ -8,7 +8,7 @@ export declare type CommonMarkPresetOptions = ZeroPresetOptions & {
|
|
|
8
8
|
lists?: ListsOptions;
|
|
9
9
|
italic?: ItalicOptions;
|
|
10
10
|
breaks?: BreaksOptions;
|
|
11
|
-
image?: false | Extension;
|
|
11
|
+
image?: false | Extension | ImageOptions;
|
|
12
12
|
codeBlock?: CodeBlockOptions;
|
|
13
13
|
blockquote?: BlockquoteOptions;
|
|
14
14
|
heading?: false | Extension | HeadingOptions;
|
|
@@ -19,7 +19,7 @@ const CommonMarkPreset = (builder, opts) => {
|
|
|
19
19
|
.use(markdown_1.CodeBlock, (_g = opts.codeBlock) !== null && _g !== void 0 ? _g : {})
|
|
20
20
|
.use(markdown_1.Blockquote, (_h = opts.blockquote) !== null && _h !== void 0 ? _h : {});
|
|
21
21
|
if (opts.image !== false) {
|
|
22
|
-
builder.use((0, lodash_1.isFunction)(opts.image) ? opts.image : markdown_1.Image);
|
|
22
|
+
builder.use((0, lodash_1.isFunction)(opts.image) ? opts.image : markdown_1.Image, (0, lodash_1.isFunction)(opts.image) ? undefined : opts.image);
|
|
23
23
|
}
|
|
24
24
|
if (opts.heading !== false) {
|
|
25
25
|
if ((0, lodash_1.isFunction)(opts.heading))
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type GetProportionalSizeParams = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
imgMaxHeight: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function getProportionalSize({ width: _width, height: _height, imgMaxHeight, }: GetProportionalSizeParams): {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProportionalSize = void 0;
|
|
4
|
+
function getProportionalSize({ width: _width, height: _height, imgMaxHeight, }) {
|
|
5
|
+
let width = _width;
|
|
6
|
+
let height = _height;
|
|
7
|
+
const ratio = width / height;
|
|
8
|
+
if (height > imgMaxHeight) {
|
|
9
|
+
height = imgMaxHeight;
|
|
10
|
+
width = Math.round(height * ratio);
|
|
11
|
+
}
|
|
12
|
+
return { width, height };
|
|
13
|
+
}
|
|
14
|
+
exports.getProportionalSize = getProportionalSize;
|
|
@@ -5,7 +5,7 @@ export * from './clipboard';
|
|
|
5
5
|
export * from './ecapeRegexp';
|
|
6
6
|
export * from './event-emitter';
|
|
7
7
|
export * from './helpers';
|
|
8
|
-
export
|
|
8
|
+
export * from './inputrules';
|
|
9
9
|
export * from './keymap';
|
|
10
10
|
export * from './marks';
|
|
11
11
|
export * from './node-children';
|
|
@@ -18,3 +18,4 @@ export * from './selection';
|
|
|
18
18
|
export * from './serialize-for-clipboard';
|
|
19
19
|
export * from './sync-scroll';
|
|
20
20
|
export * from './upload';
|
|
21
|
+
export * from './get-proportional-size';
|
package/build/cjs/utils/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrappingInputRule = exports.textblockTypeInputRule = exports.inlineNodeInputRule = exports.nodeInputRule = exports.markInputRule = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
tslib_1.__exportStar(require("./actions"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./autocomplete-popup"), exports);
|
|
@@ -9,12 +8,7 @@ tslib_1.__exportStar(require("./clipboard"), exports);
|
|
|
9
8
|
tslib_1.__exportStar(require("./ecapeRegexp"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./event-emitter"), exports);
|
|
11
10
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, "markInputRule", { enumerable: true, get: function () { return inputrules_1.markInputRule; } });
|
|
14
|
-
Object.defineProperty(exports, "nodeInputRule", { enumerable: true, get: function () { return inputrules_1.nodeInputRule; } });
|
|
15
|
-
Object.defineProperty(exports, "inlineNodeInputRule", { enumerable: true, get: function () { return inputrules_1.inlineNodeInputRule; } });
|
|
16
|
-
Object.defineProperty(exports, "textblockTypeInputRule", { enumerable: true, get: function () { return inputrules_1.textblockTypeInputRule; } });
|
|
17
|
-
Object.defineProperty(exports, "wrappingInputRule", { enumerable: true, get: function () { return inputrules_1.wrappingInputRule; } });
|
|
11
|
+
tslib_1.__exportStar(require("./inputrules"), exports);
|
|
18
12
|
tslib_1.__exportStar(require("./keymap"), exports);
|
|
19
13
|
tslib_1.__exportStar(require("./marks"), exports);
|
|
20
14
|
tslib_1.__exportStar(require("./node-children"), exports);
|
|
@@ -27,3 +21,4 @@ tslib_1.__exportStar(require("./selection"), exports);
|
|
|
27
21
|
tslib_1.__exportStar(require("./serialize-for-clipboard"), exports);
|
|
28
22
|
tslib_1.__exportStar(require("./sync-scroll"), exports);
|
|
29
23
|
tslib_1.__exportStar(require("./upload"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./get-proportional-size"), exports);
|