@gravity-ui/markdown-editor 14.3.1 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/bundle/Editor.d.ts +2 -0
- package/build/cjs/bundle/Editor.js +9 -2
- package/build/cjs/bundle/MarkdownEditorView.js +1 -0
- package/build/cjs/bundle/SplitModeView.js +1 -0
- package/build/cjs/bundle/config/markup.d.ts +41 -17
- package/build/cjs/bundle/config/markup.js +413 -308
- package/build/cjs/bundle/config/wysiwyg.d.ts +29 -18
- package/build/cjs/bundle/config/wysiwyg.js +526 -310
- package/build/cjs/bundle/sticky/sticky.css +1 -1
- package/build/cjs/bundle/types.d.ts +24 -0
- package/build/cjs/bundle/useMarkdownEditor.js +6 -2
- package/build/cjs/bundle/wysiwyg-preset.d.ts +11 -2
- package/build/cjs/bundle/wysiwyg-preset.js +1 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.d.ts +1 -0
- package/build/cjs/extensions/behavior/Clipboard/utils.js +1 -0
- package/build/cjs/extensions/markdown/CodeBlock/handle-paste.js +5 -17
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.js +6 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.js +11 -5
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +5 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +42 -24
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +30 -11
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +46 -24
- package/build/cjs/extensions/yfm/YfmFile/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/YfmFile/index.js +1 -0
- package/build/cjs/index.d.ts +1 -1
- package/build/cjs/index.js +2 -1
- package/build/cjs/markup/codemirror/create.d.ts +8 -5
- package/build/cjs/markup/codemirror/create.js +43 -5
- package/build/cjs/markup/codemirror/directive-facet.d.ts +3 -0
- package/build/cjs/markup/codemirror/directive-facet.js +8 -0
- package/build/cjs/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
- package/build/cjs/markup/codemirror/html-to-markdown/converters.js +214 -0
- package/build/cjs/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
- package/build/cjs/markup/codemirror/html-to-markdown/handlers.js +233 -0
- package/build/cjs/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
- package/build/cjs/markup/codemirror/html-to-markdown/helpers.js +21 -0
- package/build/cjs/markup/codemirror/index.d.ts +1 -0
- package/build/cjs/markup/codemirror/index.js +3 -1
- package/build/cjs/markup/codemirror/yfm.d.ts +5 -0
- package/build/cjs/markup/codemirror/yfm.js +26 -4
- package/build/cjs/markup/commands/inline.js +18 -8
- package/build/cjs/markup/commands/yfm.js +10 -1
- package/build/cjs/utils/clipboard.d.ts +14 -0
- package/build/cjs/utils/clipboard.js +36 -1
- package/build/cjs/utils/directive.d.ts +28 -0
- package/build/cjs/utils/directive.js +55 -0
- package/build/cjs/utils/index.d.ts +1 -0
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.d.ts +2 -0
- package/build/esm/bundle/Editor.js +9 -2
- package/build/esm/bundle/MarkdownEditorView.js +1 -0
- package/build/esm/bundle/SplitModeView.js +1 -0
- package/build/esm/bundle/config/markup.d.ts +41 -17
- package/build/esm/bundle/config/markup.js +411 -307
- package/build/esm/bundle/config/wysiwyg.d.ts +29 -18
- package/build/esm/bundle/config/wysiwyg.js +499 -284
- package/build/esm/bundle/sticky/sticky.css +1 -1
- package/build/esm/bundle/types.d.ts +24 -0
- package/build/esm/bundle/useMarkdownEditor.js +6 -2
- package/build/esm/bundle/wysiwyg-preset.d.ts +11 -2
- package/build/esm/bundle/wysiwyg-preset.js +1 -0
- package/build/esm/extensions/behavior/Clipboard/utils.d.ts +1 -0
- package/build/esm/extensions/behavior/Clipboard/utils.js +1 -0
- package/build/esm/extensions/markdown/CodeBlock/handle-paste.js +2 -14
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.js +5 -0
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.js +8 -3
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +6 -2
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +41 -24
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.js +21 -2
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
- package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.js +32 -10
- package/build/esm/extensions/yfm/YfmFile/index.d.ts +1 -0
- package/build/esm/extensions/yfm/YfmFile/index.js +2 -1
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/markup/codemirror/create.d.ts +8 -5
- package/build/esm/markup/codemirror/create.js +42 -4
- package/build/esm/markup/codemirror/directive-facet.d.ts +3 -0
- package/build/esm/markup/codemirror/directive-facet.js +5 -0
- package/build/esm/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
- package/build/esm/markup/codemirror/html-to-markdown/converters.js +210 -0
- package/build/esm/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
- package/build/esm/markup/codemirror/html-to-markdown/handlers.js +215 -0
- package/build/esm/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
- package/build/esm/markup/codemirror/html-to-markdown/helpers.js +17 -0
- package/build/esm/markup/codemirror/index.d.ts +1 -0
- package/build/esm/markup/codemirror/index.js +1 -0
- package/build/esm/markup/codemirror/yfm.d.ts +5 -0
- package/build/esm/markup/codemirror/yfm.js +25 -3
- package/build/esm/markup/commands/inline.js +18 -8
- package/build/esm/markup/commands/yfm.js +9 -1
- package/build/esm/utils/clipboard.d.ts +14 -0
- package/build/esm/utils/clipboard.js +32 -0
- package/build/esm/utils/directive.d.ts +28 -0
- package/build/esm/utils/directive.js +51 -0
- package/build/esm/utils/index.d.ts +1 -0
- package/build/esm/version.js +1 -1
- package/build/styles.css +1 -1
- package/package.json +10 -6
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
position: absolute;
|
|
16
16
|
inset: var(--g-md-toolbar-sticky-inset, -4px);
|
|
17
17
|
content: "";
|
|
18
|
-
border: 1px solid var(--g-color-line-generic-solid);
|
|
18
|
+
border: var(--g-md-toolbar-sticky-border, 1px solid var(--g-color-line-generic-solid));
|
|
19
19
|
border-radius: 4px;
|
|
20
20
|
background-color: var(--g-color-base-background);
|
|
21
21
|
}
|
|
@@ -3,6 +3,7 @@ import type { MarkupString } from '../common';
|
|
|
3
3
|
import type { EscapeConfig, Extension } from '../core';
|
|
4
4
|
import type { CreateCodemirrorParams, YfmLangOptions } from '../markup';
|
|
5
5
|
import type { FileUploadHandler } from '../utils';
|
|
6
|
+
import type { DirectiveSyntaxContext, DirectiveSyntaxOption } from '../utils/directive';
|
|
6
7
|
import type { ChangeEditorModeOptions } from './Editor';
|
|
7
8
|
import type { ExtensionsOptions as WysiwygPresetExtensionsOptions } from './wysiwyg-preset';
|
|
8
9
|
export type { Editor as MarkdownEditorInstance } from './Editor';
|
|
@@ -13,6 +14,7 @@ export declare type RenderPreviewParams = {
|
|
|
13
14
|
getValue: () => MarkupString;
|
|
14
15
|
mode: 'preview' | 'split';
|
|
15
16
|
md: Readonly<MarkdownEditorMdOptions>;
|
|
17
|
+
directiveSyntax: Pick<DirectiveSyntaxContext, 'option' | 'valueFor' | 'mdPluginValueFor'>;
|
|
16
18
|
};
|
|
17
19
|
export declare type RenderPreview = (params: RenderPreviewParams) => ReactNode;
|
|
18
20
|
export declare type ParseInsertedUrlAsImage = (text: string) => {
|
|
@@ -61,6 +63,26 @@ export declare type MarkdownEditorExperimentalOptions = {
|
|
|
61
63
|
*/
|
|
62
64
|
prepareRawMarkup?: (value: MarkupString) => MarkupString;
|
|
63
65
|
beforeEditorModeChange?: (options: Pick<ChangeEditorModeOptions, 'mode' | 'reason'>) => boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Enables support of directive syntax for diplodoc (YFM) extensions.
|
|
68
|
+
*
|
|
69
|
+
* **Note:** This setting affects parsing of markdown markup and serializing to markdown markup.
|
|
70
|
+
* Be careful with it and use it in consistency with diplodoc/transform and diplodoc-extensions.
|
|
71
|
+
*
|
|
72
|
+
* Before enabling this option, make sure that appropriate versions of diplodoc/transform and diplodoc-extensions are installed.
|
|
73
|
+
*
|
|
74
|
+
* You can pass an object in `key:value` format to provide different behaviour for each extension individually.
|
|
75
|
+
*
|
|
76
|
+
* Values:
|
|
77
|
+
* - 'disabled' – directive syntax is disabled;
|
|
78
|
+
* - 'enabled' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using old syntax;
|
|
79
|
+
* - 'preserve' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using directive syntax;
|
|
80
|
+
* - 'overwrite' – existing blocks will be overwritten using directive syntax through serialization;
|
|
81
|
+
* - 'only' – old syntax is disabled, only directive syntax available. Blocks in old syntax will not be parsed.
|
|
82
|
+
*
|
|
83
|
+
* Default value is 'disabled'.
|
|
84
|
+
*/
|
|
85
|
+
directiveSyntax?: DirectiveSyntaxOption;
|
|
64
86
|
};
|
|
65
87
|
export declare type MarkdownEditorMarkupConfig = {
|
|
66
88
|
/**
|
|
@@ -87,6 +109,8 @@ export declare type MarkdownEditorMarkupConfig = {
|
|
|
87
109
|
keymaps?: CreateCodemirrorParams['keymaps'];
|
|
88
110
|
/** Overrides the default placeholder content. */
|
|
89
111
|
placeholder?: CreateCodemirrorParams['placeholder'];
|
|
112
|
+
/** Enable HTML parsing when pasting content. */
|
|
113
|
+
parseHtmlOnPaste?: boolean;
|
|
90
114
|
/**
|
|
91
115
|
* Additional language data for markdown language in codemirror.
|
|
92
116
|
* Can be used to configure additional autocompletions and others.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useLayoutEffect, useMemo } from 'react';
|
|
2
2
|
import { ReactRenderStorage } from '../extensions';
|
|
3
3
|
import { logger } from '../logger';
|
|
4
|
+
import { DirectiveSyntaxContext } from '../utils/directive';
|
|
4
5
|
import { EditorImpl } from './Editor';
|
|
5
6
|
import { BundlePreset } from './wysiwyg-preset';
|
|
6
7
|
// [major] TODO: remove generic type
|
|
@@ -14,10 +15,12 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
14
15
|
const uploadFile = (_c = handlers.uploadFile) !== null && _c !== void 0 ? _c : props.fileUploadHandler;
|
|
15
16
|
const needToSetDimensionsForUploadedImages = (_d = experimental.needToSetDimensionsForUploadedImages) !== null && _d !== void 0 ? _d : props.needToSetDimensionsForUploadedImages;
|
|
16
17
|
const enableNewImageSizeCalculation = experimental.enableNewImageSizeCalculation;
|
|
18
|
+
const directiveSyntax = new DirectiveSyntaxContext(experimental.directiveSyntax);
|
|
17
19
|
const extensions = (builder) => {
|
|
18
20
|
var _a;
|
|
19
21
|
const extensionOptions = (_a = wysiwygConfig.extensionOptions) !== null && _a !== void 0 ? _a : props.extensionOptions;
|
|
20
|
-
builder.use(BundlePreset, Object.assign(Object.assign({}, extensionOptions), {
|
|
22
|
+
builder.use(BundlePreset, Object.assign(Object.assign({}, extensionOptions), { directiveSyntax,
|
|
23
|
+
preset, reactRenderer: renderStorage, onCancel: () => {
|
|
21
24
|
editor.emit('cancel', null);
|
|
22
25
|
return true;
|
|
23
26
|
}, onSubmit: () => {
|
|
@@ -33,7 +36,8 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
return new EditorImpl(Object.assign(Object.assign({}, props), { preset,
|
|
36
|
-
renderStorage,
|
|
39
|
+
renderStorage,
|
|
40
|
+
directiveSyntax, md: Object.assign(Object.assign({}, md), { breaks, html: (_e = md.html) !== null && _e !== void 0 ? _e : props.allowHTML, linkify: (_f = md.linkify) !== null && _f !== void 0 ? _f : props.linkify, linkifyTlds: (_g = md.linkifyTlds) !== null && _g !== void 0 ? _g : props.linkifyTlds }), initial: Object.assign(Object.assign({}, initial), { markup: (_h = initial.markup) !== null && _h !== void 0 ? _h : props.initialMarkup, mode: (_j = initial.mode) !== null && _j !== void 0 ? _j : props.initialEditorMode, toolbarVisible: (_k = initial.toolbarVisible) !== null && _k !== void 0 ? _k : props.initialToolbarVisible, splitModeEnabled: (_l = initial.splitModeEnabled) !== null && _l !== void 0 ? _l : props.initialSplitModeEnabled }), handlers: Object.assign(Object.assign({}, handlers), { uploadFile }), experimental: Object.assign(Object.assign({}, experimental), { needToSetDimensionsForUploadedImages,
|
|
37
41
|
enableNewImageSizeCalculation, prepareRawMarkup: (_m = experimental.prepareRawMarkup) !== null && _m !== void 0 ? _m : props.prepareRawMarkup, beforeEditorModeChange: (_o = experimental.beforeEditorModeChange) !== null && _o !== void 0 ? _o : props.experimental_beforeEditorModeChange }), markupConfig: Object.assign(Object.assign({}, markupConfig), { splitMode: (_p = markupConfig.splitMode) !== null && _p !== void 0 ? _p : props.splitMode, renderPreview: (_q = markupConfig.renderPreview) !== null && _q !== void 0 ? _q : props.renderPreview, extensions: (_r = markupConfig.extensions) !== null && _r !== void 0 ? _r : props.extraMarkupExtensions }), wysiwygConfig: Object.assign(Object.assign({}, wysiwygConfig), { extensions, escapeConfig: (_s = wysiwygConfig.escapeConfig) !== null && _s !== void 0 ? _s : props.escapeConfig }) }));
|
|
38
42
|
}, deps);
|
|
39
43
|
useLayoutEffect(() => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ExtensionAuto } from '../core';
|
|
1
|
+
import type { ExtensionAuto } from '../core';
|
|
2
2
|
import { BehaviorPresetOptions } from '../extensions/behavior';
|
|
3
3
|
import { EditorModeKeymapOptions } from '../extensions/behavior/EditorModeKeymap';
|
|
4
4
|
import { FullPresetOptions } from '../presets/full';
|
|
5
|
+
import type { DirectiveSyntaxContext } from '../utils/directive';
|
|
5
6
|
import type { FileUploadHandler } from '../utils/upload';
|
|
6
|
-
import { MarkdownEditorPreset } from './types';
|
|
7
|
+
import type { MarkdownEditorPreset } from './types';
|
|
7
8
|
export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;
|
|
8
9
|
export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
|
|
9
10
|
preset: MarkdownEditorPreset;
|
|
@@ -16,5 +17,13 @@ export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOp
|
|
|
16
17
|
*/
|
|
17
18
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
18
19
|
enableNewImageSizeCalculation?: boolean;
|
|
20
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
19
21
|
};
|
|
22
|
+
declare global {
|
|
23
|
+
namespace WysiwygEditor {
|
|
24
|
+
interface Context {
|
|
25
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
20
29
|
export declare const BundlePreset: ExtensionAuto<BundlePresetOptions>;
|
|
@@ -13,6 +13,7 @@ import { emojiDefs } from './emoji';
|
|
|
13
13
|
const DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'];
|
|
14
14
|
export const BundlePreset = (builder, opts) => {
|
|
15
15
|
var _a, _b, _c;
|
|
16
|
+
builder.context.set('directiveSyntax', opts.directiveSyntax);
|
|
16
17
|
const dropCursor = {
|
|
17
18
|
color: 'var(--g-color-line-brand)',
|
|
18
19
|
width: 2,
|
|
@@ -4,6 +4,7 @@ export var DataTransferType;
|
|
|
4
4
|
DataTransferType["Text"] = "text/plain";
|
|
5
5
|
DataTransferType["Html"] = "text/html";
|
|
6
6
|
DataTransferType["Yfm"] = "text/yfm";
|
|
7
|
+
DataTransferType["Rtf"] = "text/rtf";
|
|
7
8
|
DataTransferType["UriList"] = "text/uri-list";
|
|
8
9
|
DataTransferType["VSCodeData"] = "vscode-editor-data";
|
|
9
10
|
DataTransferType["Files"] = "Files";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTransferType } from '
|
|
1
|
+
import { DataTransferType, isVSCode, tryParseVSCodeData } from '../../../utils/clipboard';
|
|
2
2
|
import { cbType, codeBlockLangAttr } from './const';
|
|
3
3
|
export const handlePaste = (view, e) => {
|
|
4
4
|
if (!e.clipboardData || view.state.selection.$from.parent.type.spec.code)
|
|
@@ -20,7 +20,7 @@ function getCodeData(data) {
|
|
|
20
20
|
let mode;
|
|
21
21
|
if (isVSCode(data)) {
|
|
22
22
|
editor = 'vscode';
|
|
23
|
-
mode = (_a =
|
|
23
|
+
mode = (_a = tryParseVSCodeData(data)) === null || _a === void 0 ? void 0 : _a.mode;
|
|
24
24
|
}
|
|
25
25
|
else
|
|
26
26
|
return null;
|
|
@@ -28,15 +28,3 @@ function getCodeData(data) {
|
|
|
28
28
|
}
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
function isVSCode(data) {
|
|
32
|
-
return data.types.includes(DataTransferType.VSCodeData);
|
|
33
|
-
}
|
|
34
|
-
function tryCatch(fn) {
|
|
35
|
-
try {
|
|
36
|
-
return fn();
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
console.error(e);
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
@@ -3,6 +3,10 @@ export declare enum CutNode {
|
|
|
3
3
|
CutTitle = "yfm_cut_title",
|
|
4
4
|
CutContent = "yfm_cut_content"
|
|
5
5
|
}
|
|
6
|
+
export declare enum CutAttr {
|
|
7
|
+
Class = "class",
|
|
8
|
+
Markup = "data-markup"
|
|
9
|
+
}
|
|
6
10
|
export declare const cutType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
7
11
|
export declare const cutTitleType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
8
12
|
export declare const cutContentType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -5,6 +5,11 @@ export var CutNode;
|
|
|
5
5
|
CutNode["CutTitle"] = "yfm_cut_title";
|
|
6
6
|
CutNode["CutContent"] = "yfm_cut_content";
|
|
7
7
|
})(CutNode || (CutNode = {}));
|
|
8
|
+
export var CutAttr;
|
|
9
|
+
(function (CutAttr) {
|
|
10
|
+
CutAttr["Class"] = "class";
|
|
11
|
+
CutAttr["Markup"] = "data-markup";
|
|
12
|
+
})(CutAttr || (CutAttr = {}));
|
|
8
13
|
export const cutType = nodeTypeFactory(CutNode.Cut);
|
|
9
14
|
export const cutTitleType = nodeTypeFactory(CutNode.CutTitle);
|
|
10
15
|
export const cutContentType = nodeTypeFactory(CutNode.CutContent);
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
|
|
3
|
-
export { CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
3
|
+
export { CutAttr, CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
4
|
+
declare global {
|
|
5
|
+
namespace MarkdownEditor {
|
|
6
|
+
interface DirectiveSyntaxAdditionalSupportedExtensions {
|
|
7
|
+
yfmCut: true;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
export declare type YfmCutSpecsOptions = {
|
|
5
12
|
cutView?: ExtensionNodeSpec['view'];
|
|
6
13
|
cutTitleView?: ExtensionNodeSpec['view'];
|
|
@@ -2,12 +2,17 @@ import { transform as yfmCut } from '@diplodoc/cut-extension';
|
|
|
2
2
|
import { CutNode } from './const';
|
|
3
3
|
import { parserTokens } from './parser';
|
|
4
4
|
import { getSchemaSpecs } from './schema';
|
|
5
|
-
import {
|
|
6
|
-
export { CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
5
|
+
import { getSerializerTokens } from './serializer';
|
|
6
|
+
export { CutAttr, CutNode, cutType, cutTitleType, cutContentType } from './const';
|
|
7
7
|
export const YfmCutSpecs = (builder, opts) => {
|
|
8
8
|
const schemaSpecs = getSchemaSpecs(opts, builder.context.get('placeholder'));
|
|
9
|
+
const directiveSyntax = builder.context.get('directiveSyntax');
|
|
10
|
+
const serializerTokens = getSerializerTokens({ directiveSyntax });
|
|
9
11
|
builder
|
|
10
|
-
.configureMd((md) => md.use(yfmCut({
|
|
12
|
+
.configureMd((md) => md.use(yfmCut({
|
|
13
|
+
bundle: false,
|
|
14
|
+
directiveSyntax: directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.mdPluginValueFor('yfmCut'),
|
|
15
|
+
})))
|
|
11
16
|
.addNode(CutNode.Cut, () => ({
|
|
12
17
|
spec: schemaSpecs[CutNode.Cut],
|
|
13
18
|
toMd: serializerTokens[CutNode.Cut],
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { CutNode } from './const';
|
|
2
|
-
const getAttrs = (tok) =>
|
|
1
|
+
import { CutAttr, CutNode } from './const';
|
|
2
|
+
const getAttrs = (tok) => {
|
|
3
|
+
const nodeAttrs = tok.attrs ? Object.fromEntries(tok.attrs) : {};
|
|
4
|
+
nodeAttrs[CutAttr.Markup] = tok.markup;
|
|
5
|
+
return nodeAttrs;
|
|
6
|
+
};
|
|
3
7
|
export const parserTokens = {
|
|
4
8
|
[CutNode.Cut]: { name: CutNode.Cut, type: 'block', getAttrs },
|
|
5
9
|
[CutNode.CutTitle]: { name: CutNode.CutTitle, type: 'block' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
3
|
-
import { CutNode } from '
|
|
3
|
+
import { CutNode } from './const';
|
|
4
4
|
import type { YfmCutSpecsOptions } from './index';
|
|
5
5
|
export declare const getSchemaSpecs: (opts?: YfmCutSpecsOptions, placeholder?: PlaceholderOptions) => Record<CutNode, NodeSpec>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CutNode } from '
|
|
1
|
+
import { CutAttr, CutNode } from './const';
|
|
2
2
|
const DEFAULT_PLACEHOLDERS = {
|
|
3
3
|
Title: 'Cut title',
|
|
4
4
|
Content: 'Cut content',
|
|
@@ -7,10 +7,15 @@ export const getSchemaSpecs = (opts, placeholder) => {
|
|
|
7
7
|
var _a, _b, _c, _d;
|
|
8
8
|
return ({
|
|
9
9
|
[CutNode.Cut]: {
|
|
10
|
-
attrs: { class: { default: 'yfm-cut' } },
|
|
10
|
+
attrs: { class: { default: 'yfm-cut' }, [CutAttr.Markup]: { default: null } },
|
|
11
11
|
content: `${CutNode.CutTitle} ${CutNode.CutContent}`,
|
|
12
12
|
group: 'block yfm-cut',
|
|
13
|
-
parseDOM: [
|
|
13
|
+
parseDOM: [
|
|
14
|
+
{
|
|
15
|
+
tag: '.yfm-cut',
|
|
16
|
+
getAttrs: (node) => ({ [CutAttr.Markup]: node.getAttribute(CutAttr.Markup) }),
|
|
17
|
+
},
|
|
18
|
+
],
|
|
14
19
|
toDOM(node) {
|
|
15
20
|
return ['div', node.attrs, 0];
|
|
16
21
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { SerializerNodeToken } from '../../../../core';
|
|
2
2
|
import { CutNode } from './const';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function getSerializerTokens({ directiveSyntax, }: {
|
|
4
|
+
directiveSyntax?: WysiwygEditor.Context['directiveSyntax'];
|
|
5
|
+
}): Record<CutNode, SerializerNodeToken>;
|
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
import { isNodeEmpty } from '../../../../utils/nodes';
|
|
2
2
|
import { getPlaceholderContent } from '../../../../utils/placeholder';
|
|
3
|
-
import { CutNode } from './const';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
import { CutAttr, CutNode } from './const';
|
|
4
|
+
export function getSerializerTokens({ directiveSyntax, }) {
|
|
5
|
+
const isDirectiveCut = (node) => {
|
|
6
|
+
return directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.shouldSerializeToDirective('yfmCut', node.attrs[CutAttr.Markup]);
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
[CutNode.Cut]: (state, node) => {
|
|
10
|
+
state.renderContent(node);
|
|
11
|
+
state.write(isDirectiveCut(node) ? ':::' : '{% endcut %}');
|
|
12
|
+
state.closeBlock(node);
|
|
13
|
+
},
|
|
14
|
+
[CutNode.CutTitle]: (state, node, parent) => {
|
|
15
|
+
if (isDirectiveCut(parent)) {
|
|
16
|
+
state.write(':::cut [');
|
|
17
|
+
state.renderInline(node);
|
|
18
|
+
state.write(']');
|
|
19
|
+
state.ensureNewLine();
|
|
20
|
+
state.closeBlock();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
state.write('{% cut "');
|
|
24
|
+
if (node.nodeSize > 2)
|
|
25
|
+
state.renderInline(node);
|
|
26
|
+
else
|
|
27
|
+
state.write(getPlaceholderContent(node));
|
|
28
|
+
state.write('" %}\n');
|
|
29
|
+
state.write('\n');
|
|
30
|
+
state.closeBlock();
|
|
31
|
+
},
|
|
32
|
+
[CutNode.CutContent]: (state, node, parent) => {
|
|
33
|
+
if (isDirectiveCut(parent)) {
|
|
34
|
+
state.renderContent(node);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!isNodeEmpty(node))
|
|
38
|
+
state.renderInline(node);
|
|
39
|
+
else
|
|
40
|
+
state.write(getPlaceholderContent(node) + '\n\n');
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
import { FileHtmlAttr } from '@diplodoc/file-extension';
|
|
1
2
|
import type { AttributeSpec } from 'prosemirror-model';
|
|
2
3
|
export declare const yfmFileNodeName = "yfm_file";
|
|
4
|
+
export declare const YfmFileAttr: {
|
|
5
|
+
readonly Markup: "data-markup";
|
|
6
|
+
readonly Name: FileHtmlAttr.Download;
|
|
7
|
+
readonly Link: FileHtmlAttr.Href;
|
|
8
|
+
readonly ReferrerPolicy: FileHtmlAttr.ReferrerPolicy;
|
|
9
|
+
readonly Rel: FileHtmlAttr.Rel;
|
|
10
|
+
readonly Target: FileHtmlAttr.Target;
|
|
11
|
+
readonly Type: FileHtmlAttr.Type;
|
|
12
|
+
readonly Lang: FileHtmlAttr.HrefLang;
|
|
13
|
+
};
|
|
14
|
+
export declare const YFM_FILE_DIRECTIVE_ATTRS: readonly string[];
|
|
3
15
|
export declare const KNOWN_ATTRS: readonly string[];
|
|
4
16
|
export declare const REQUIRED_ATTRS: string[];
|
|
5
17
|
export declare const fileNodeAttrsSpec: Record<string, AttributeSpec>;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FILE_KNOWN_ATTRS, FILE_REQUIRED_ATTRS, FILE_TOKEN, FILE_TO_LINK_ATTRS_MAP, FileHtmlAttr, } from '@diplodoc/file-extension';
|
|
2
2
|
export const yfmFileNodeName = FILE_TOKEN;
|
|
3
|
+
export const YfmFileAttr = {
|
|
4
|
+
Markup: 'data-markup',
|
|
5
|
+
Name: FileHtmlAttr.Download,
|
|
6
|
+
Link: FileHtmlAttr.Href,
|
|
7
|
+
ReferrerPolicy: FileHtmlAttr.ReferrerPolicy,
|
|
8
|
+
Rel: FileHtmlAttr.Rel,
|
|
9
|
+
Target: FileHtmlAttr.Target,
|
|
10
|
+
Type: FileHtmlAttr.Type,
|
|
11
|
+
Lang: FileHtmlAttr.HrefLang,
|
|
12
|
+
};
|
|
13
|
+
export const YFM_FILE_DIRECTIVE_ATTRS = [
|
|
14
|
+
YfmFileAttr.ReferrerPolicy,
|
|
15
|
+
YfmFileAttr.Rel,
|
|
16
|
+
YfmFileAttr.Target,
|
|
17
|
+
YfmFileAttr.Type,
|
|
18
|
+
YfmFileAttr.Lang,
|
|
19
|
+
];
|
|
3
20
|
export const KNOWN_ATTRS = FILE_KNOWN_ATTRS.map((attrName) => {
|
|
4
21
|
if (attrName in FILE_TO_LINK_ATTRS_MAP)
|
|
5
22
|
return FILE_TO_LINK_ATTRS_MAP[attrName];
|
|
@@ -10,7 +27,9 @@ export const REQUIRED_ATTRS = FILE_REQUIRED_ATTRS.map((attrName) => {
|
|
|
10
27
|
return FILE_TO_LINK_ATTRS_MAP[attrName];
|
|
11
28
|
return attrName;
|
|
12
29
|
});
|
|
13
|
-
export const fileNodeAttrsSpec = {
|
|
30
|
+
export const fileNodeAttrsSpec = {
|
|
31
|
+
[YfmFileAttr.Markup]: { default: null },
|
|
32
|
+
};
|
|
14
33
|
for (const attrName of KNOWN_ATTRS) {
|
|
15
34
|
const attrSpec = (fileNodeAttrsSpec[attrName] = {});
|
|
16
35
|
if (!REQUIRED_ATTRS.includes(attrName)) {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { Extension } from '../../../../core';
|
|
2
|
-
export { yfmFileNodeName } from './const';
|
|
2
|
+
export { yfmFileNodeName, YfmFileAttr } from './const';
|
|
3
3
|
export declare const fileType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
4
|
+
declare global {
|
|
5
|
+
namespace MarkdownEditor {
|
|
6
|
+
interface DirectiveSyntaxAdditionalSupportedExtensions {
|
|
7
|
+
yfmFile: true;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
export declare const YfmFileSpecs: Extension;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FileClassName, LinkHtmlAttr, PREFIX } from '@diplodoc/transform/lib/plugins/file/const';
|
|
1
|
+
import { FILE_MARKUP_PREFIX, FileClassName, FileHtmlAttr, transform as fileTransform, } from '@diplodoc/file-extension';
|
|
3
2
|
import { nodeTypeFactory } from '../../../../utils/schema';
|
|
4
|
-
import { KNOWN_ATTRS, LINK_TO_FILE_ATTRS_MAP, fileNodeAttrsSpec, yfmFileNodeName } from './const';
|
|
5
|
-
export { yfmFileNodeName } from './const';
|
|
3
|
+
import { KNOWN_ATTRS, LINK_TO_FILE_ATTRS_MAP, YFM_FILE_DIRECTIVE_ATTRS, YfmFileAttr, fileNodeAttrsSpec, yfmFileNodeName, } from './const';
|
|
4
|
+
export { yfmFileNodeName, YfmFileAttr } from './const';
|
|
6
5
|
export const fileType = nodeTypeFactory(yfmFileNodeName);
|
|
7
6
|
export const YfmFileSpecs = (builder) => {
|
|
8
|
-
|
|
7
|
+
const directiveContext = builder.context.get('directiveSyntax');
|
|
8
|
+
builder.configureMd((md) => md.use(fileTransform({
|
|
9
|
+
bundle: false,
|
|
10
|
+
directiveSyntax: directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.mdPluginValueFor('yfmFile'),
|
|
11
|
+
})));
|
|
9
12
|
builder.addNode(yfmFileNodeName, () => ({
|
|
10
13
|
spec: {
|
|
11
14
|
group: 'inline',
|
|
@@ -39,7 +42,7 @@ export const YfmFileSpecs = (builder) => {
|
|
|
39
42
|
const span = document.createElement('span');
|
|
40
43
|
span.classList.add(FileClassName.Icon);
|
|
41
44
|
a.appendChild(span);
|
|
42
|
-
a.append(node.attrs[
|
|
45
|
+
a.append(node.attrs[FileHtmlAttr.Download]);
|
|
43
46
|
return a;
|
|
44
47
|
},
|
|
45
48
|
},
|
|
@@ -49,15 +52,20 @@ export const YfmFileSpecs = (builder) => {
|
|
|
49
52
|
name: yfmFileNodeName,
|
|
50
53
|
type: 'node',
|
|
51
54
|
getAttrs: (tok) => {
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const attrs = Object.fromEntries(tok.attrs || []);
|
|
56
|
+
attrs[YfmFileAttr.Markup] = tok.markup;
|
|
57
|
+
return attrs;
|
|
54
58
|
},
|
|
55
59
|
},
|
|
56
60
|
},
|
|
57
61
|
toMd: (state, node) => {
|
|
62
|
+
if (directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.shouldSerializeToDirective('yfmFile', node.attrs[YfmFileAttr.Markup])) {
|
|
63
|
+
state.write(serializeToDirective(node));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
58
66
|
const attrsStr = Object.entries(node.attrs)
|
|
59
67
|
.reduce((arr, [key, value]) => {
|
|
60
|
-
if (value) {
|
|
68
|
+
if (key !== YfmFileAttr.Markup && value) {
|
|
61
69
|
if (key in LINK_TO_FILE_ATTRS_MAP) {
|
|
62
70
|
key = LINK_TO_FILE_ATTRS_MAP[key];
|
|
63
71
|
}
|
|
@@ -66,7 +74,21 @@ export const YfmFileSpecs = (builder) => {
|
|
|
66
74
|
return arr;
|
|
67
75
|
}, [])
|
|
68
76
|
.join(' ');
|
|
69
|
-
state.write(`${
|
|
77
|
+
state.write(`${FILE_MARKUP_PREFIX}${attrsStr} %}`);
|
|
70
78
|
},
|
|
71
79
|
}));
|
|
72
80
|
};
|
|
81
|
+
function serializeToDirective(node) {
|
|
82
|
+
const filename = node.attrs[YfmFileAttr.Name] || '';
|
|
83
|
+
const filelink = node.attrs[YfmFileAttr.Link] || '';
|
|
84
|
+
let fileMarkup = `:file[${filename}](${filelink})`;
|
|
85
|
+
const attrs = YFM_FILE_DIRECTIVE_ATTRS.reduce((acc, key) => {
|
|
86
|
+
const value = node.attrs[key];
|
|
87
|
+
if (value)
|
|
88
|
+
acc.push(`${key}="${value}"`);
|
|
89
|
+
return acc;
|
|
90
|
+
}, []);
|
|
91
|
+
if (attrs.length)
|
|
92
|
+
fileMarkup += `{${attrs.join(' ')}}`;
|
|
93
|
+
return fileMarkup;
|
|
94
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { YfmFilePaste } from './YfmFilePaste';
|
|
2
2
|
import { YfmFileSpecs } from './YfmFileSpecs';
|
|
3
3
|
import { YfmFileWidget } from './YfmFileWidget';
|
|
4
|
-
import '
|
|
4
|
+
import '@diplodoc/file-extension/runtime/styles.css';
|
|
5
|
+
import './index.css'; // eslint-disable-line import/order
|
|
5
6
|
export const YfmFile = (builder, opts = {}) => {
|
|
6
7
|
builder.use(YfmFileSpecs, opts);
|
|
7
8
|
builder.use(YfmFileWidget, opts);
|
package/build/esm/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export * from './forms';
|
|
|
11
11
|
export * from './view';
|
|
12
12
|
export * from './utils';
|
|
13
13
|
export * from './bundle';
|
|
14
|
-
export { ReactRendererFacet, getImageDimensions } from './markup';
|
|
14
|
+
export { DirectiveSyntaxFacet, ReactRendererFacet, getImageDimensions } from './markup';
|
|
15
15
|
export * as MarkupCommands from './markup/commands';
|
|
16
16
|
export * as MarkupHelpers from './markup/commands/helpers';
|
|
17
17
|
export { Lang, configure } from './configure';
|
package/build/esm/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export * from './forms';
|
|
|
11
11
|
export * from './view';
|
|
12
12
|
export * from './utils';
|
|
13
13
|
export * from './bundle';
|
|
14
|
-
export { ReactRendererFacet, getImageDimensions } from './markup';
|
|
14
|
+
export { DirectiveSyntaxFacet, ReactRendererFacet, getImageDimensions } from './markup';
|
|
15
15
|
export * as MarkupCommands from './markup/commands';
|
|
16
16
|
export * as MarkupHelpers from './markup/commands/helpers';
|
|
17
17
|
export { Lang, configure } from './configure';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { autocompletion } from '@codemirror/autocomplete';
|
|
2
2
|
import type { Extension, StateCommand } from '@codemirror/state';
|
|
3
|
-
import { EditorView, EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
|
|
3
|
+
import { EditorView, type EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
|
|
4
4
|
import type { ParseInsertedUrlAsImage } from '../../bundle';
|
|
5
|
-
import { EventMap } from '../../bundle/Editor';
|
|
6
|
-
import { ReactRenderStorage } from '../../extensions';
|
|
7
|
-
import { Receiver } from '../../utils';
|
|
8
|
-
import {
|
|
5
|
+
import type { EventMap } from '../../bundle/Editor';
|
|
6
|
+
import type { ReactRenderStorage } from '../../extensions';
|
|
7
|
+
import type { Receiver } from '../../utils';
|
|
8
|
+
import type { DirectiveSyntaxContext } from '../../utils/directive';
|
|
9
|
+
import { type FileUploadHandler } from './files-upload-facet';
|
|
9
10
|
import { type YfmLangOptions } from './yfm';
|
|
10
11
|
export type { YfmLangOptions };
|
|
11
12
|
declare type Autocompletion = Parameters<typeof autocompletion>[0];
|
|
@@ -19,6 +20,7 @@ export declare type CreateCodemirrorParams = {
|
|
|
19
20
|
onScroll: (event: Event) => void;
|
|
20
21
|
reactRenderer: ReactRenderStorage;
|
|
21
22
|
uploadHandler?: FileUploadHandler;
|
|
23
|
+
parseHtmlOnPaste?: boolean;
|
|
22
24
|
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
23
25
|
needImageDimensions?: boolean;
|
|
24
26
|
enableNewImageSizeCalculation?: boolean;
|
|
@@ -30,6 +32,7 @@ export declare type CreateCodemirrorParams = {
|
|
|
30
32
|
receiver?: Receiver<EventMap>;
|
|
31
33
|
yfmLangOptions?: YfmLangOptions;
|
|
32
34
|
autocompletion?: Autocompletion;
|
|
35
|
+
directiveSyntax: DirectiveSyntaxContext;
|
|
33
36
|
};
|
|
34
37
|
export declare function createCodemirror(params: CreateCodemirrorParams): EditorView;
|
|
35
38
|
export declare function withLogger(action: string, command: StateCommand): StateCommand;
|