@gravity-ui/markdown-editor 14.4.0 → 14.5.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.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 +2 -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/Checkbox/CheckboxSpecs/const.d.ts +7 -0
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/const.js +8 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.js +2 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +1 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +7 -7
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/serializer.d.ts +1 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/serializer.js +2 -2
- package/build/cjs/extensions/yfm/Checkbox/const.d.ts +1 -1
- package/build/cjs/extensions/yfm/Checkbox/const.js +2 -1
- package/build/cjs/extensions/yfm/Checkbox/index.d.ts +2 -2
- package/build/cjs/extensions/yfm/Checkbox/index.js +4 -38
- package/build/cjs/extensions/yfm/Checkbox/nodeviews.d.ts +16 -0
- package/build/cjs/extensions/yfm/Checkbox/nodeviews.js +56 -0
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +21 -2
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
- package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +29 -5
- package/build/cjs/markup/codemirror/create.d.ts +1 -0
- package/build/cjs/markup/codemirror/create.js +41 -4
- 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/commands/inline.js +18 -8
- package/build/cjs/utils/clipboard.d.ts +14 -0
- package/build/cjs/utils/clipboard.js +36 -1
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.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 +2 -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/Checkbox/CheckboxSpecs/const.d.ts +7 -0
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/const.js +7 -0
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -1
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.js +1 -1
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +1 -1
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +7 -7
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/serializer.d.ts +1 -1
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/serializer.js +2 -2
- package/build/esm/extensions/yfm/Checkbox/const.d.ts +1 -1
- package/build/esm/extensions/yfm/Checkbox/const.js +1 -1
- package/build/esm/extensions/yfm/Checkbox/index.d.ts +2 -2
- package/build/esm/extensions/yfm/Checkbox/index.js +3 -38
- package/build/esm/extensions/yfm/Checkbox/nodeviews.d.ts +16 -0
- package/build/esm/extensions/yfm/Checkbox/nodeviews.js +52 -0
- 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 +29 -6
- package/build/esm/markup/codemirror/create.d.ts +1 -0
- package/build/esm/markup/codemirror/create.js +40 -3
- 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/commands/inline.js +18 -8
- package/build/esm/utils/clipboard.d.ts +14 -0
- package/build/esm/utils/clipboard.js +32 -0
- package/build/esm/version.js +1 -1
- package/build/styles.css +1 -1
- package/package.json +9 -7
|
@@ -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
|
}
|
|
@@ -109,6 +109,8 @@ export declare type MarkdownEditorMarkupConfig = {
|
|
|
109
109
|
keymaps?: CreateCodemirrorParams['keymaps'];
|
|
110
110
|
/** Overrides the default placeholder content. */
|
|
111
111
|
placeholder?: CreateCodemirrorParams['placeholder'];
|
|
112
|
+
/** Enable HTML parsing when pasting content. */
|
|
113
|
+
parseHtmlOnPaste?: boolean;
|
|
112
114
|
/**
|
|
113
115
|
* Additional language data for markdown language in codemirror.
|
|
114
116
|
* Can be used to configure additional autocompletions and others.
|
|
@@ -7,6 +7,7 @@ var DataTransferType;
|
|
|
7
7
|
DataTransferType["Text"] = "text/plain";
|
|
8
8
|
DataTransferType["Html"] = "text/html";
|
|
9
9
|
DataTransferType["Yfm"] = "text/yfm";
|
|
10
|
+
DataTransferType["Rtf"] = "text/rtf";
|
|
10
11
|
DataTransferType["UriList"] = "text/uri-list";
|
|
11
12
|
DataTransferType["VSCodeData"] = "vscode-editor-data";
|
|
12
13
|
DataTransferType["Files"] = "Files";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePaste = void 0;
|
|
4
|
-
const
|
|
4
|
+
const clipboard_1 = require("../../../utils/clipboard");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
6
|
const handlePaste = (view, e) => {
|
|
7
7
|
if (!e.clipboardData || view.state.selection.$from.parent.type.spec.code)
|
|
@@ -19,28 +19,16 @@ const handlePaste = (view, e) => {
|
|
|
19
19
|
exports.handlePaste = handlePaste;
|
|
20
20
|
function getCodeData(data) {
|
|
21
21
|
var _a;
|
|
22
|
-
if (data.getData(
|
|
22
|
+
if (data.getData(clipboard_1.DataTransferType.Text)) {
|
|
23
23
|
let editor = 'unknown';
|
|
24
24
|
let mode;
|
|
25
|
-
if (isVSCode(data)) {
|
|
25
|
+
if ((0, clipboard_1.isVSCode)(data)) {
|
|
26
26
|
editor = 'vscode';
|
|
27
|
-
mode = (_a =
|
|
27
|
+
mode = (_a = (0, clipboard_1.tryParseVSCodeData)(data)) === null || _a === void 0 ? void 0 : _a.mode;
|
|
28
28
|
}
|
|
29
29
|
else
|
|
30
30
|
return null;
|
|
31
|
-
return { editor, mode, value: data.getData(
|
|
31
|
+
return { editor, mode, value: data.getData(clipboard_1.DataTransferType.Text) };
|
|
32
32
|
}
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
|
-
function isVSCode(data) {
|
|
36
|
-
return data.types.includes(utils_1.DataTransferType.VSCodeData);
|
|
37
|
-
}
|
|
38
|
-
function tryCatch(fn) {
|
|
39
|
-
try {
|
|
40
|
-
return fn();
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
console.error(e);
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
@@ -3,5 +3,12 @@ export declare enum CheckboxNode {
|
|
|
3
3
|
Input = "checkbox_input",
|
|
4
4
|
Label = "checkbox_label"
|
|
5
5
|
}
|
|
6
|
+
export declare const CheckboxAttr: {
|
|
7
|
+
readonly Class: "class";
|
|
8
|
+
readonly Type: "type";
|
|
9
|
+
readonly Id: "id";
|
|
10
|
+
readonly Checked: "checked";
|
|
11
|
+
readonly For: "for";
|
|
12
|
+
};
|
|
6
13
|
export declare const idPrefix = "yfm-editor-checkbox";
|
|
7
14
|
export declare const b: import("@bem-react/classname").ClassNameFormatter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.b = exports.idPrefix = exports.CheckboxNode = void 0;
|
|
3
|
+
exports.b = exports.idPrefix = exports.CheckboxAttr = exports.CheckboxNode = void 0;
|
|
4
4
|
const classname_1 = require("../../../../classname");
|
|
5
5
|
var CheckboxNode;
|
|
6
6
|
(function (CheckboxNode) {
|
|
@@ -8,5 +8,12 @@ var CheckboxNode;
|
|
|
8
8
|
CheckboxNode["Input"] = "checkbox_input";
|
|
9
9
|
CheckboxNode["Label"] = "checkbox_label";
|
|
10
10
|
})(CheckboxNode = exports.CheckboxNode || (exports.CheckboxNode = {}));
|
|
11
|
+
exports.CheckboxAttr = {
|
|
12
|
+
Class: 'class',
|
|
13
|
+
Type: 'type',
|
|
14
|
+
Id: 'id',
|
|
15
|
+
Checked: 'checked',
|
|
16
|
+
For: 'for',
|
|
17
|
+
};
|
|
11
18
|
exports.idPrefix = 'yfm-editor-checkbox';
|
|
12
19
|
exports.b = (0, classname_1.cn)('checkbox');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
|
|
3
|
-
export { CheckboxNode } from './const';
|
|
3
|
+
export { CheckboxAttr, CheckboxNode } from './const';
|
|
4
4
|
export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
5
5
|
export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
6
6
|
export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckboxSpecs = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = void 0;
|
|
3
|
+
exports.CheckboxSpecs = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = exports.CheckboxAttr = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const checkbox_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/plugins/checkbox"));
|
|
6
6
|
const schema_1 = require("../../../../utils/schema");
|
|
@@ -9,6 +9,7 @@ const parser_1 = require("./parser");
|
|
|
9
9
|
const schema_2 = require("./schema");
|
|
10
10
|
const serializer_1 = require("./serializer");
|
|
11
11
|
var const_2 = require("./const");
|
|
12
|
+
Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return const_2.CheckboxAttr; } });
|
|
12
13
|
Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return const_2.CheckboxNode; } });
|
|
13
14
|
exports.checkboxType = (0, schema_1.nodeTypeFactory)(const_1.CheckboxNode.Checkbox);
|
|
14
15
|
exports.checkboxLabelType = (0, schema_1.nodeTypeFactory)(const_1.CheckboxNode.Label);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
3
|
-
import { CheckboxNode } from '
|
|
3
|
+
import { CheckboxNode } from './const';
|
|
4
4
|
import type { CheckboxSpecsOptions } from './index';
|
|
5
5
|
export declare const getSchemaSpecs: (opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>, placeholder?: PlaceholderOptions) => Record<CheckboxNode, NodeSpec>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSchemaSpecs = void 0;
|
|
4
|
-
const const_1 = require("
|
|
4
|
+
const const_1 = require("./const");
|
|
5
5
|
const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';
|
|
6
6
|
const getSchemaSpecs = (opts, placeholder) => {
|
|
7
7
|
var _a, _b;
|
|
@@ -13,7 +13,7 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
13
13
|
allowSelection: false,
|
|
14
14
|
parseDOM: [],
|
|
15
15
|
attrs: {
|
|
16
|
-
|
|
16
|
+
[const_1.CheckboxAttr.Class]: { default: (0, const_1.b)() },
|
|
17
17
|
},
|
|
18
18
|
toDOM(node) {
|
|
19
19
|
return ['div', node.attrs, 0];
|
|
@@ -24,9 +24,9 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
24
24
|
group: 'block',
|
|
25
25
|
parseDOM: [],
|
|
26
26
|
attrs: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
[const_1.CheckboxAttr.Type]: { default: 'checkbox' },
|
|
28
|
+
[const_1.CheckboxAttr.Id]: { default: null },
|
|
29
|
+
[const_1.CheckboxAttr.Checked]: { default: null },
|
|
30
30
|
},
|
|
31
31
|
toDOM(node) {
|
|
32
32
|
return ['div', node.attrs];
|
|
@@ -42,12 +42,12 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
42
42
|
{
|
|
43
43
|
tag: `span[class="${(0, const_1.b)('label')}"]`,
|
|
44
44
|
getAttrs: (node) => ({
|
|
45
|
-
|
|
45
|
+
[const_1.CheckboxAttr.For]: node.getAttribute(const_1.CheckboxAttr.For) || '',
|
|
46
46
|
}),
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
attrs: {
|
|
50
|
-
|
|
50
|
+
[const_1.CheckboxAttr.For]: { default: null },
|
|
51
51
|
},
|
|
52
52
|
escapeText: false,
|
|
53
53
|
placeholder: {
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializerTokens = void 0;
|
|
4
4
|
const placeholder_1 = require("../../../../utils/placeholder");
|
|
5
|
-
const const_1 = require("
|
|
5
|
+
const const_1 = require("./const");
|
|
6
6
|
exports.serializerTokens = {
|
|
7
7
|
[const_1.CheckboxNode.Checkbox]: (state, node) => {
|
|
8
8
|
state.renderInline(node);
|
|
9
9
|
state.closeBlock(node);
|
|
10
10
|
},
|
|
11
11
|
[const_1.CheckboxNode.Input]: (state, node) => {
|
|
12
|
-
const checked = node.attrs.
|
|
12
|
+
const checked = node.attrs[const_1.CheckboxAttr.Checked] === 'true';
|
|
13
13
|
state.write(`[${checked ? 'X' : ' '}] `);
|
|
14
14
|
},
|
|
15
15
|
[const_1.CheckboxNode.Label]: (state, node, _, idx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CheckboxNode, b } from './CheckboxSpecs/const';
|
|
1
|
+
export { CheckboxAttr, CheckboxNode, b } from './CheckboxSpecs/const';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.b = exports.CheckboxNode = void 0;
|
|
3
|
+
exports.b = exports.CheckboxNode = exports.CheckboxAttr = void 0;
|
|
4
4
|
var const_1 = require("./CheckboxSpecs/const");
|
|
5
|
+
Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return const_1.CheckboxAttr; } });
|
|
5
6
|
Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return const_1.CheckboxNode; } });
|
|
6
7
|
Object.defineProperty(exports, "b", { enumerable: true, get: function () { return const_1.b; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
|
-
import { CheckboxSpecsOptions } from './CheckboxSpecs';
|
|
2
|
+
import { type CheckboxSpecsOptions } from './CheckboxSpecs';
|
|
3
3
|
declare const checkboxAction = "addCheckbox";
|
|
4
|
-
export { CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType } from './CheckboxSpecs';
|
|
4
|
+
export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './CheckboxSpecs';
|
|
5
5
|
export declare type CheckboxOptions = Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'> & {};
|
|
6
6
|
export declare const Checkbox: ExtensionAuto<CheckboxOptions>;
|
|
7
7
|
declare global {
|
|
@@ -1,55 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Checkbox = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = void 0;
|
|
4
|
-
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
3
|
+
exports.Checkbox = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = exports.CheckboxAttr = void 0;
|
|
5
4
|
const inputrules_1 = require("../../../utils/inputrules");
|
|
6
|
-
const BaseSchema_1 = require("../../base/BaseSchema");
|
|
7
5
|
const CheckboxSpecs_1 = require("./CheckboxSpecs");
|
|
8
6
|
const actions_1 = require("./actions");
|
|
9
|
-
const
|
|
7
|
+
const nodeviews_1 = require("./nodeviews");
|
|
10
8
|
const plugin_1 = require("./plugin");
|
|
11
9
|
const utils_1 = require("./utils");
|
|
12
10
|
const checkboxAction = 'addCheckbox';
|
|
13
11
|
var CheckboxSpecs_2 = require("./CheckboxSpecs");
|
|
12
|
+
Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return CheckboxSpecs_2.CheckboxAttr; } });
|
|
14
13
|
Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return CheckboxSpecs_2.CheckboxNode; } });
|
|
15
14
|
Object.defineProperty(exports, "checkboxType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxType; } });
|
|
16
15
|
Object.defineProperty(exports, "checkboxLabelType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxLabelType; } });
|
|
17
16
|
Object.defineProperty(exports, "checkboxInputType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxInputType; } });
|
|
18
17
|
const Checkbox = (builder, opts) => {
|
|
19
|
-
builder.use(CheckboxSpecs_1.CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () =>
|
|
20
|
-
const dom = document.createElement('input');
|
|
21
|
-
for (const attr in node.attrs) {
|
|
22
|
-
if (node.attrs[attr])
|
|
23
|
-
dom.setAttribute(attr, node.attrs[attr]);
|
|
24
|
-
}
|
|
25
|
-
dom.setAttribute('class', (0, const_1.b)('input'));
|
|
26
|
-
dom.addEventListener('click', (e) => {
|
|
27
|
-
const elem = e.target;
|
|
28
|
-
const checkedAttr = elem.getAttribute('checked');
|
|
29
|
-
const checked = checkedAttr ? '' : 'true';
|
|
30
|
-
const pos = getPos();
|
|
31
|
-
if (pos !== undefined) {
|
|
32
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { checked })));
|
|
33
|
-
}
|
|
34
|
-
elem.setAttribute('checked', checked);
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
dom,
|
|
38
|
-
ignoreMutation: () => true,
|
|
39
|
-
update: () => true,
|
|
40
|
-
destroy() {
|
|
41
|
-
const pos = getPos();
|
|
42
|
-
if (pos !== undefined) {
|
|
43
|
-
const resolved = view.state.doc.resolve(pos);
|
|
44
|
-
if (resolved.parent.type.name === const_1.CheckboxNode.Checkbox &&
|
|
45
|
-
resolved.parent.lastChild) {
|
|
46
|
-
view.dispatch((0, prosemirror_utils_1.replaceParentNodeOfType)(resolved.parent.type, (0, BaseSchema_1.pType)(view.state.schema).create(resolved.parent.lastChild.content))(view.state.tr));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
dom.remove();
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
} }));
|
|
18
|
+
builder.use(CheckboxSpecs_1.CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => nodeviews_1.CheckboxInputView.create }));
|
|
53
19
|
builder
|
|
54
20
|
.addPlugin(plugin_1.keymapPlugin, builder.Priority.High)
|
|
55
21
|
.addAction(checkboxAction, () => (0, actions_1.addCheckbox)())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Node } from 'prosemirror-model';
|
|
2
|
+
import type { NodeView, NodeViewConstructor } from 'prosemirror-view';
|
|
3
|
+
export declare class CheckboxInputView implements NodeView {
|
|
4
|
+
static create: NodeViewConstructor;
|
|
5
|
+
dom: HTMLInputElement;
|
|
6
|
+
private _node;
|
|
7
|
+
private _view;
|
|
8
|
+
private _getPos;
|
|
9
|
+
private constructor();
|
|
10
|
+
ignoreMutation(): boolean;
|
|
11
|
+
update(node: Node): boolean;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
private _createDomElem;
|
|
14
|
+
private _applyNodeAttrsToDomElem;
|
|
15
|
+
private _onInputClick;
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CheckboxInputView = void 0;
|
|
5
|
+
const const_1 = require("./const");
|
|
6
|
+
class CheckboxInputView {
|
|
7
|
+
constructor(node, view, getPos) {
|
|
8
|
+
this._onInputClick = (event) => {
|
|
9
|
+
if (event.target instanceof HTMLInputElement) {
|
|
10
|
+
const { checked } = event.target;
|
|
11
|
+
const pos = this._getPos();
|
|
12
|
+
if (pos !== undefined)
|
|
13
|
+
this._view.dispatch(this._view.state.tr.setNodeAttribute(pos, const_1.CheckboxAttr.Checked, checked ? 'true' : null));
|
|
14
|
+
}
|
|
15
|
+
this._view.focus();
|
|
16
|
+
};
|
|
17
|
+
this._node = node;
|
|
18
|
+
this._view = view;
|
|
19
|
+
this._getPos = getPos;
|
|
20
|
+
this.dom = this._createDomElem();
|
|
21
|
+
this._applyNodeAttrsToDomElem();
|
|
22
|
+
}
|
|
23
|
+
ignoreMutation() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
update(node) {
|
|
27
|
+
if (node.type !== this._node.type)
|
|
28
|
+
return false;
|
|
29
|
+
this._node = node;
|
|
30
|
+
this._applyNodeAttrsToDomElem();
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
this.dom.removeEventListener('click', this._onInputClick);
|
|
35
|
+
}
|
|
36
|
+
_createDomElem() {
|
|
37
|
+
const dom = document.createElement('input');
|
|
38
|
+
dom.setAttribute('class', (0, const_1.b)('input'));
|
|
39
|
+
dom.addEventListener('click', this._onInputClick);
|
|
40
|
+
return dom;
|
|
41
|
+
}
|
|
42
|
+
_applyNodeAttrsToDomElem() {
|
|
43
|
+
const { dom, _node: node } = this;
|
|
44
|
+
for (const [key, value] of Object.entries(node.attrs)) {
|
|
45
|
+
if (value)
|
|
46
|
+
dom.setAttribute(key, value);
|
|
47
|
+
else
|
|
48
|
+
dom.removeAttribute(key);
|
|
49
|
+
}
|
|
50
|
+
const checked = node.attrs[const_1.CheckboxAttr.Checked] === 'true';
|
|
51
|
+
this.dom.checked = checked;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CheckboxInputView = CheckboxInputView;
|
|
55
|
+
_a = CheckboxInputView;
|
|
56
|
+
CheckboxInputView.create = (node, view, getPos) => new _a(node, view, getPos);
|
|
@@ -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,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LINK_TO_FILE_ATTRS_MAP = exports.fileNodeAttrsSpec = exports.REQUIRED_ATTRS = exports.KNOWN_ATTRS = exports.yfmFileNodeName = void 0;
|
|
3
|
+
exports.LINK_TO_FILE_ATTRS_MAP = exports.fileNodeAttrsSpec = exports.REQUIRED_ATTRS = exports.KNOWN_ATTRS = exports.YFM_FILE_DIRECTIVE_ATTRS = exports.YfmFileAttr = exports.yfmFileNodeName = void 0;
|
|
4
4
|
const file_extension_1 = require("@diplodoc/file-extension");
|
|
5
5
|
exports.yfmFileNodeName = file_extension_1.FILE_TOKEN;
|
|
6
|
+
exports.YfmFileAttr = {
|
|
7
|
+
Markup: 'data-markup',
|
|
8
|
+
Name: file_extension_1.FileHtmlAttr.Download,
|
|
9
|
+
Link: file_extension_1.FileHtmlAttr.Href,
|
|
10
|
+
ReferrerPolicy: file_extension_1.FileHtmlAttr.ReferrerPolicy,
|
|
11
|
+
Rel: file_extension_1.FileHtmlAttr.Rel,
|
|
12
|
+
Target: file_extension_1.FileHtmlAttr.Target,
|
|
13
|
+
Type: file_extension_1.FileHtmlAttr.Type,
|
|
14
|
+
Lang: file_extension_1.FileHtmlAttr.HrefLang,
|
|
15
|
+
};
|
|
16
|
+
exports.YFM_FILE_DIRECTIVE_ATTRS = [
|
|
17
|
+
exports.YfmFileAttr.ReferrerPolicy,
|
|
18
|
+
exports.YfmFileAttr.Rel,
|
|
19
|
+
exports.YfmFileAttr.Target,
|
|
20
|
+
exports.YfmFileAttr.Type,
|
|
21
|
+
exports.YfmFileAttr.Lang,
|
|
22
|
+
];
|
|
6
23
|
exports.KNOWN_ATTRS = file_extension_1.FILE_KNOWN_ATTRS.map((attrName) => {
|
|
7
24
|
if (attrName in file_extension_1.FILE_TO_LINK_ATTRS_MAP)
|
|
8
25
|
return file_extension_1.FILE_TO_LINK_ATTRS_MAP[attrName];
|
|
@@ -13,7 +30,9 @@ exports.REQUIRED_ATTRS = file_extension_1.FILE_REQUIRED_ATTRS.map((attrName) =>
|
|
|
13
30
|
return file_extension_1.FILE_TO_LINK_ATTRS_MAP[attrName];
|
|
14
31
|
return attrName;
|
|
15
32
|
});
|
|
16
|
-
exports.fileNodeAttrsSpec = {
|
|
33
|
+
exports.fileNodeAttrsSpec = {
|
|
34
|
+
[exports.YfmFileAttr.Markup]: { default: null },
|
|
35
|
+
};
|
|
17
36
|
for (const attrName of exports.KNOWN_ATTRS) {
|
|
18
37
|
const attrSpec = (exports.fileNodeAttrsSpec[attrName] = {});
|
|
19
38
|
if (!exports.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,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YfmFileSpecs = exports.fileType = exports.yfmFileNodeName = void 0;
|
|
3
|
+
exports.YfmFileSpecs = exports.fileType = exports.YfmFileAttr = exports.yfmFileNodeName = void 0;
|
|
4
4
|
const file_extension_1 = require("@diplodoc/file-extension");
|
|
5
5
|
const schema_1 = require("../../../../utils/schema");
|
|
6
6
|
const const_1 = require("./const");
|
|
7
7
|
var const_2 = require("./const");
|
|
8
8
|
Object.defineProperty(exports, "yfmFileNodeName", { enumerable: true, get: function () { return const_2.yfmFileNodeName; } });
|
|
9
|
+
Object.defineProperty(exports, "YfmFileAttr", { enumerable: true, get: function () { return const_2.YfmFileAttr; } });
|
|
9
10
|
exports.fileType = (0, schema_1.nodeTypeFactory)(const_1.yfmFileNodeName);
|
|
10
11
|
const YfmFileSpecs = (builder) => {
|
|
11
|
-
|
|
12
|
+
const directiveContext = builder.context.get('directiveSyntax');
|
|
13
|
+
builder.configureMd((md) => md.use((0, file_extension_1.transform)({
|
|
14
|
+
bundle: false,
|
|
15
|
+
directiveSyntax: directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.mdPluginValueFor('yfmFile'),
|
|
16
|
+
})));
|
|
12
17
|
builder.addNode(const_1.yfmFileNodeName, () => ({
|
|
13
18
|
spec: {
|
|
14
19
|
group: 'inline',
|
|
@@ -52,15 +57,20 @@ const YfmFileSpecs = (builder) => {
|
|
|
52
57
|
name: const_1.yfmFileNodeName,
|
|
53
58
|
type: 'node',
|
|
54
59
|
getAttrs: (tok) => {
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
const attrs = Object.fromEntries(tok.attrs || []);
|
|
61
|
+
attrs[const_1.YfmFileAttr.Markup] = tok.markup;
|
|
62
|
+
return attrs;
|
|
57
63
|
},
|
|
58
64
|
},
|
|
59
65
|
},
|
|
60
66
|
toMd: (state, node) => {
|
|
67
|
+
if (directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.shouldSerializeToDirective('yfmFile', node.attrs[const_1.YfmFileAttr.Markup])) {
|
|
68
|
+
state.write(serializeToDirective(node));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
61
71
|
const attrsStr = Object.entries(node.attrs)
|
|
62
72
|
.reduce((arr, [key, value]) => {
|
|
63
|
-
if (value) {
|
|
73
|
+
if (key !== const_1.YfmFileAttr.Markup && value) {
|
|
64
74
|
if (key in const_1.LINK_TO_FILE_ATTRS_MAP) {
|
|
65
75
|
key = const_1.LINK_TO_FILE_ATTRS_MAP[key];
|
|
66
76
|
}
|
|
@@ -74,3 +84,17 @@ const YfmFileSpecs = (builder) => {
|
|
|
74
84
|
}));
|
|
75
85
|
};
|
|
76
86
|
exports.YfmFileSpecs = YfmFileSpecs;
|
|
87
|
+
function serializeToDirective(node) {
|
|
88
|
+
const filename = node.attrs[const_1.YfmFileAttr.Name] || '';
|
|
89
|
+
const filelink = node.attrs[const_1.YfmFileAttr.Link] || '';
|
|
90
|
+
let fileMarkup = `:file[${filename}](${filelink})`;
|
|
91
|
+
const attrs = const_1.YFM_FILE_DIRECTIVE_ATTRS.reduce((acc, key) => {
|
|
92
|
+
const value = node.attrs[key];
|
|
93
|
+
if (value)
|
|
94
|
+
acc.push(`${key}="${value}"`);
|
|
95
|
+
return acc;
|
|
96
|
+
}, []);
|
|
97
|
+
if (attrs.length)
|
|
98
|
+
fileMarkup += `{${attrs.join(' ')}}`;
|
|
99
|
+
return fileMarkup;
|
|
100
|
+
}
|
|
@@ -20,6 +20,7 @@ export declare type CreateCodemirrorParams = {
|
|
|
20
20
|
onScroll: (event: Event) => void;
|
|
21
21
|
reactRenderer: ReactRenderStorage;
|
|
22
22
|
uploadHandler?: FileUploadHandler;
|
|
23
|
+
parseHtmlOnPaste?: boolean;
|
|
23
24
|
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
|
|
24
25
|
needImageDimensions?: boolean;
|
|
25
26
|
enableNewImageSizeCalculation?: boolean;
|
|
@@ -6,19 +6,20 @@ 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");
|
|
10
9
|
const logger_1 = require("../../logger");
|
|
11
10
|
const shortcuts_1 = require("../../shortcuts");
|
|
11
|
+
const clipboard_1 = require("../../utils/clipboard");
|
|
12
12
|
const commands_2 = require("../commands");
|
|
13
13
|
const directive_facet_1 = require("./directive-facet");
|
|
14
14
|
const files_upload_facet_1 = require("./files-upload-facet");
|
|
15
15
|
const gravity_1 = require("./gravity");
|
|
16
|
+
const converters_1 = require("./html-to-markdown/converters");
|
|
16
17
|
const pairing_chars_1 = require("./pairing-chars");
|
|
17
18
|
const react_facet_1 = require("./react-facet");
|
|
18
19
|
const plugin_1 = require("./search-plugin/plugin");
|
|
19
20
|
const yfm_1 = require("./yfm");
|
|
20
21
|
function createCodemirror(params) {
|
|
21
|
-
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, directiveSyntax, } = params;
|
|
22
|
+
const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseHtmlOnPaste, parseInsertedUrlAsImage, directiveSyntax, } = params;
|
|
22
23
|
const extensions = [gravity_1.gravityTheme, (0, view_1.placeholder)(placeholderContent)];
|
|
23
24
|
if (!disabledExtensions.history) {
|
|
24
25
|
extensions.push((0, commands_1.history)());
|
|
@@ -70,8 +71,44 @@ function createCodemirror(params) {
|
|
|
70
71
|
},
|
|
71
72
|
paste(event, editor) {
|
|
72
73
|
var _a;
|
|
73
|
-
if (event.clipboardData
|
|
74
|
-
|
|
74
|
+
if (!event.clipboardData)
|
|
75
|
+
return;
|
|
76
|
+
// if clipboard contains YFM content - avoid any meddling with pasted content
|
|
77
|
+
// since text/yfm will contain valid markdown
|
|
78
|
+
const yfmContent = event.clipboardData.getData(clipboard_1.DataTransferType.Yfm);
|
|
79
|
+
if (yfmContent) {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
editor.dispatch(editor.state.replaceSelection(yfmContent));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// checking if a copy buffer content is suitable for convertion
|
|
85
|
+
const shouldSkipHtml = (0, clipboard_1.shouldSkipHtmlConversion)(event.clipboardData);
|
|
86
|
+
// if we have text/html inside copy/paste buffer
|
|
87
|
+
const htmlContent = event.clipboardData.getData(clipboard_1.DataTransferType.Html);
|
|
88
|
+
// if we pasting markdown from VsCode we need skip html transformation
|
|
89
|
+
if (htmlContent && parseHtmlOnPaste && !shouldSkipHtml) {
|
|
90
|
+
let parsedMarkdownMarkup;
|
|
91
|
+
try {
|
|
92
|
+
const parser = new DOMParser();
|
|
93
|
+
const htmlDoc = parser.parseFromString(htmlContent, 'text/html');
|
|
94
|
+
const converter = new converters_1.MarkdownConverter();
|
|
95
|
+
parsedMarkdownMarkup = converter.processNode(htmlDoc.body).trim();
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// The code is pretty new and there might be random issues we haven't caught yet,
|
|
99
|
+
// especially with invalid HTML or weird DOM parsing errors.
|
|
100
|
+
// If something goes wrong, I just want to fall back to the "default pasting"
|
|
101
|
+
// rather than break the entire experience for the user.
|
|
102
|
+
logger_1.logger.error(e);
|
|
103
|
+
}
|
|
104
|
+
if (parsedMarkdownMarkup !== undefined) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
editor.dispatch(editor.state.replaceSelection(parsedMarkdownMarkup));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (parseInsertedUrlAsImage) {
|
|
111
|
+
const { imageUrl, title } = parseInsertedUrlAsImage((_a = event.clipboardData.getData(clipboard_1.DataTransferType.Text)) !== null && _a !== void 0 ? _a : '') || {};
|
|
75
112
|
if (!imageUrl) {
|
|
76
113
|
return;
|
|
77
114
|
}
|