@gravity-ui/markdown-editor 13.2.0 → 13.4.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 +5 -2
- package/build/cjs/bundle/HorizontalDrag.d.ts +1 -0
- package/build/cjs/bundle/HorizontalDrag.js +2 -1
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/config/action-names.js +1 -0
- package/build/cjs/bundle/config/icons.d.ts +1 -1
- package/build/cjs/bundle/config/icons.js +1 -0
- package/build/cjs/bundle/config/markup.d.ts +1 -0
- package/build/cjs/bundle/config/markup.js +10 -1
- package/build/cjs/bundle/config/wysiwyg.d.ts +1 -0
- package/build/cjs/bundle/config/wysiwyg.js +12 -1
- package/build/cjs/bundle/wysiwyg-preset.js +2 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/NodeView.d.ts +23 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/NodeView.js +57 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlock.css +66 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.d.ts +17 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +178 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/index.js +4 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/const.d.ts +15 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/const.js +20 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.d.ts +10 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.js +43 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/actions.d.ts +2 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/actions.js +15 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/const.d.ts +2 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/const.js +6 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/index.d.ts +14 -0
- package/build/cjs/extensions/yfm/YfmHtmlBlock/index.js +17 -0
- package/build/cjs/extensions/yfm/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/index.js +1 -1
- package/build/cjs/i18n/common/en.json +6 -2
- package/build/cjs/i18n/common/index.d.ts +7 -3
- package/build/cjs/i18n/common/ru.json +6 -2
- package/build/cjs/i18n/menubar/en.json +37 -36
- package/build/cjs/i18n/menubar/index.d.ts +38 -37
- package/build/cjs/i18n/menubar/ru.json +37 -36
- package/build/cjs/icons/index.d.ts +1 -1
- package/build/cjs/icons/index.js +2 -1
- package/build/cjs/markup/codemirror/create.d.ts +2 -1
- package/build/cjs/markup/codemirror/create.js +5 -1
- package/build/cjs/markup/commands/blocks.d.ts +1 -0
- package/build/cjs/markup/commands/blocks.js +12 -1
- package/build/cjs/version.js +1 -1
- package/build/cjs/view/components/YfmHtml/{YfmHtml.d.ts → YfmStaticView.d.ts} +2 -2
- package/build/cjs/view/components/YfmHtml/{YfmHtml.js → YfmStaticView.js} +2 -2
- package/build/cjs/view/components/YfmHtml/index.d.ts +12 -1
- package/build/cjs/view/components/YfmHtml/index.js +4 -2
- package/build/cjs/view/hocs/withYfmHtml/index.d.ts +13 -0
- package/build/cjs/view/hocs/withYfmHtml/index.js +24 -0
- package/build/cjs/view/hocs/withYfmHtml/types.d.ts +3 -0
- package/build/cjs/view/hocs/withYfmHtml/types.js +2 -0
- package/build/cjs/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.d.ts +1 -0
- package/build/cjs/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.js +34 -0
- package/build/cjs/view/hocs/withYfmHtml/utils.d.ts +16 -0
- package/build/cjs/view/hocs/withYfmHtml/utils.js +26 -0
- package/build/esm/bundle/Editor.d.ts +2 -0
- package/build/esm/bundle/Editor.js +5 -2
- package/build/esm/bundle/HorizontalDrag.d.ts +1 -0
- package/build/esm/bundle/HorizontalDrag.js +2 -1
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/config/action-names.js +1 -0
- package/build/esm/bundle/config/icons.d.ts +1 -1
- package/build/esm/bundle/config/icons.js +2 -1
- package/build/esm/bundle/config/markup.d.ts +1 -0
- package/build/esm/bundle/config/markup.js +10 -1
- package/build/esm/bundle/config/wysiwyg.d.ts +1 -0
- package/build/esm/bundle/config/wysiwyg.js +11 -0
- package/build/esm/bundle/wysiwyg-preset.js +2 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/NodeView.d.ts +23 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/NodeView.js +52 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlock.css +66 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.d.ts +18 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +173 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/index.d.ts +1 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/index.js +1 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/const.d.ts +15 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/const.js +17 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.d.ts +10 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.js +39 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/actions.d.ts +2 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/actions.js +12 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/const.d.ts +2 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/const.js +2 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/index.d.ts +14 -0
- package/build/esm/extensions/yfm/YfmHtmlBlock/index.js +13 -0
- package/build/esm/extensions/yfm/index.d.ts +1 -1
- package/build/esm/extensions/yfm/index.js +1 -1
- package/build/esm/i18n/common/en.json +6 -2
- package/build/esm/i18n/common/index.d.ts +7 -3
- package/build/esm/i18n/common/ru.json +6 -2
- package/build/esm/i18n/menubar/en.json +37 -36
- package/build/esm/i18n/menubar/index.d.ts +38 -37
- package/build/esm/i18n/menubar/ru.json +37 -36
- package/build/esm/icons/index.d.ts +1 -1
- package/build/esm/icons/index.js +1 -1
- package/build/esm/markup/codemirror/create.d.ts +2 -1
- package/build/esm/markup/codemirror/create.js +6 -2
- package/build/esm/markup/commands/blocks.d.ts +1 -0
- package/build/esm/markup/commands/blocks.js +10 -0
- package/build/esm/version.js +1 -1
- package/build/esm/view/components/YfmHtml/{YfmHtml.d.ts → YfmStaticView.d.ts} +2 -2
- package/build/esm/view/components/YfmHtml/{YfmHtml.js → YfmStaticView.js} +1 -1
- package/build/esm/view/components/YfmHtml/index.d.ts +12 -1
- package/build/esm/view/components/YfmHtml/index.js +6 -1
- package/build/esm/view/hocs/withYfmHtml/index.d.ts +13 -0
- package/build/esm/view/hocs/withYfmHtml/index.js +19 -0
- package/build/esm/view/hocs/withYfmHtml/types.d.ts +3 -0
- package/build/esm/view/hocs/withYfmHtml/types.js +1 -0
- package/build/esm/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.d.ts +1 -0
- package/build/esm/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.js +7 -0
- package/build/esm/view/hocs/withYfmHtml/utils.d.ts +16 -0
- package/build/esm/view/hocs/withYfmHtml/utils.js +22 -0
- package/build/styles.css +66 -0
- package/package.json +6 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Ellipsis as DotsIcon, Eye } from '@gravity-ui/icons';
|
|
3
|
+
import { Button, Icon, Label, Menu, Popup } from '@gravity-ui/uikit';
|
|
4
|
+
import debounce from 'lodash/debounce';
|
|
5
|
+
import { cn } from '../../../../classname';
|
|
6
|
+
import { TextAreaFixed as TextArea } from '../../../../forms/TextInput';
|
|
7
|
+
import { i18n } from '../../../../i18n/common';
|
|
8
|
+
import { useBooleanState } from '../../../../react-utils/hooks';
|
|
9
|
+
import { removeNode } from '../../../../utils/remove-node';
|
|
10
|
+
import { YfmHtmlBlockConsts } from '../YfmHtmlBlockSpecs/const';
|
|
11
|
+
export const cnYfmHtmlBlock = cn('yfm-html-block');
|
|
12
|
+
export const cnHelper = cn('yfm-html-block-helper');
|
|
13
|
+
import './YfmHtmlBlock.css';
|
|
14
|
+
const b = cnYfmHtmlBlock;
|
|
15
|
+
export function generateID() {
|
|
16
|
+
return Math.random().toString(36).substr(2, 8);
|
|
17
|
+
}
|
|
18
|
+
const DEFAULT_PADDING = 20;
|
|
19
|
+
const DEFAULT_DELAY = 100;
|
|
20
|
+
const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f;
|
|
22
|
+
const ref = useRef(null);
|
|
23
|
+
const styles = useRef({});
|
|
24
|
+
const classNames = useRef([]);
|
|
25
|
+
const resizeConfig = useRef({});
|
|
26
|
+
const [height, setHeight] = useState('100%');
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
resizeConfig.current = {
|
|
30
|
+
padding: (_a = config === null || config === void 0 ? void 0 : config.resizePadding) !== null && _a !== void 0 ? _a : DEFAULT_PADDING,
|
|
31
|
+
delay: (_b = config === null || config === void 0 ? void 0 : config.resizeDelay) !== null && _b !== void 0 ? _b : DEFAULT_DELAY,
|
|
32
|
+
};
|
|
33
|
+
setStyles(config === null || config === void 0 ? void 0 : config.styles);
|
|
34
|
+
setClassNames(config === null || config === void 0 ? void 0 : config.classNames);
|
|
35
|
+
}, [config, (_c = (_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document) === null || _c === void 0 ? void 0 : _c.body]);
|
|
36
|
+
const handleLoadIFrame = () => {
|
|
37
|
+
var _a;
|
|
38
|
+
const contentWindow = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
|
|
39
|
+
handleResizeIFrame();
|
|
40
|
+
if (contentWindow) {
|
|
41
|
+
const frameDocument = contentWindow.document;
|
|
42
|
+
frameDocument.addEventListener('dblclick', () => {
|
|
43
|
+
onСlick();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const handleResizeIFrame = () => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (ref.current) {
|
|
50
|
+
const contentWindow = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow;
|
|
51
|
+
if (contentWindow) {
|
|
52
|
+
const body = contentWindow.document.body;
|
|
53
|
+
if (body) {
|
|
54
|
+
const height = body.scrollHeight +
|
|
55
|
+
(((_b = resizeConfig.current) === null || _b === void 0 ? void 0 : _b.padding) || DEFAULT_PADDING) +
|
|
56
|
+
'px';
|
|
57
|
+
setHeight(height);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const setClassNames = (newClassNames) => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const body = (_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document.body;
|
|
65
|
+
if (body && newClassNames) {
|
|
66
|
+
const previousClassNames = classNames.current;
|
|
67
|
+
// remove all classes that were in previousClassNames but are not in classNames
|
|
68
|
+
previousClassNames.forEach((className) => {
|
|
69
|
+
if (!newClassNames.includes(className)) {
|
|
70
|
+
body.classList.remove(className);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// add classes that are in classNames
|
|
74
|
+
newClassNames.forEach((className) => {
|
|
75
|
+
if (!body.classList.contains(className)) {
|
|
76
|
+
body.classList.add(className);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
classNames.current = newClassNames;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const setStyles = (newStyles) => {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const body = (_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document.body;
|
|
85
|
+
if (body && newStyles) {
|
|
86
|
+
const previousStyles = styles.current;
|
|
87
|
+
// remove all styles that are in previousStyles but not in styles
|
|
88
|
+
Object.keys(previousStyles).forEach((property) => {
|
|
89
|
+
if (!Object.prototype.hasOwnProperty.call(newStyles, property)) {
|
|
90
|
+
body.style.removeProperty(property);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// sdd or update styles that are in styles
|
|
94
|
+
Object.keys(newStyles).forEach((property) => {
|
|
95
|
+
body.style.setProperty(property, newStyles[property]);
|
|
96
|
+
});
|
|
97
|
+
// update current styles to the new styles
|
|
98
|
+
styles.current = newStyles;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
var _a;
|
|
103
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('load', handleLoadIFrame);
|
|
104
|
+
return () => {
|
|
105
|
+
var _a;
|
|
106
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('load', handleLoadIFrame);
|
|
107
|
+
};
|
|
108
|
+
}, [html]);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
if (ref.current) {
|
|
112
|
+
const resizeObserver = new window.ResizeObserver(debounce(handleResizeIFrame, (_b = (_a = resizeConfig.current) === null || _a === void 0 ? void 0 : _a.delay) !== null && _b !== void 0 ? _b : DEFAULT_DELAY));
|
|
113
|
+
resizeObserver.observe(ref.current);
|
|
114
|
+
}
|
|
115
|
+
}, [(_f = (_e = (_d = ref.current) === null || _d === void 0 ? void 0 : _d.contentWindow) === null || _e === void 0 ? void 0 : _e.document) === null || _f === void 0 ? void 0 : _f.body]);
|
|
116
|
+
return (React.createElement("iframe", { style: {
|
|
117
|
+
height,
|
|
118
|
+
}, ref: ref, title: generateID(), frameBorder: 0, className: b('content'), srcDoc: html }));
|
|
119
|
+
};
|
|
120
|
+
const CodeEditMode = ({ initialText, onSave, onCancel }) => {
|
|
121
|
+
const [text, setText] = useState(initialText || '\n');
|
|
122
|
+
return (React.createElement("div", { className: b({ editing: true }) },
|
|
123
|
+
React.createElement("div", { className: b('editor') },
|
|
124
|
+
React.createElement(TextArea, { controlProps: {
|
|
125
|
+
className: cnHelper({ 'prosemirror-stop-event': true }),
|
|
126
|
+
}, value: text, onUpdate: (v) => {
|
|
127
|
+
setText(v);
|
|
128
|
+
}, autoFocus: true }),
|
|
129
|
+
React.createElement("div", { className: b('controls') },
|
|
130
|
+
React.createElement("div", null,
|
|
131
|
+
React.createElement(Button, { onClick: onCancel, view: 'flat' },
|
|
132
|
+
React.createElement("span", { className: cnHelper({ 'prosemirror-stop-event': true }) }, i18n('cancel'))),
|
|
133
|
+
React.createElement(Button, { onClick: () => onSave(text), view: 'action' },
|
|
134
|
+
React.createElement("span", { className: cnHelper({ 'prosemirror-stop-event': true }) }, i18n('save'))))))));
|
|
135
|
+
};
|
|
136
|
+
export const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig }) => {
|
|
137
|
+
const [editing, setEditing, unsetEditing, toggleEditing] = useBooleanState(Boolean(node.attrs[YfmHtmlBlockConsts.NodeAttrs.newCreated]));
|
|
138
|
+
const config = useConfig === null || useConfig === void 0 ? void 0 : useConfig();
|
|
139
|
+
const [menuOpen, , , toggleMenuOpen] = useBooleanState(false);
|
|
140
|
+
const buttonRef = useRef(null);
|
|
141
|
+
const handleClick = () => {
|
|
142
|
+
setEditing();
|
|
143
|
+
};
|
|
144
|
+
if (editing) {
|
|
145
|
+
return (React.createElement(CodeEditMode, { initialText: node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc], onCancel: unsetEditing, onSave: (v) => {
|
|
146
|
+
onChange({ [YfmHtmlBlockConsts.NodeAttrs.srcdoc]: v });
|
|
147
|
+
unsetEditing();
|
|
148
|
+
} }));
|
|
149
|
+
}
|
|
150
|
+
return (React.createElement("div", { className: b(), onDoubleClick: setEditing },
|
|
151
|
+
React.createElement(Label, { className: b('label'), icon: React.createElement(Icon, { size: 16, data: Eye }) }, i18n('preview')),
|
|
152
|
+
React.createElement(YfmHtmlBlockPreview, { html: node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc], "on\u0421lick": handleClick, config: config }),
|
|
153
|
+
React.createElement("div", { className: b('menu') },
|
|
154
|
+
React.createElement(Button, { onClick: toggleMenuOpen, ref: buttonRef, size: 's', className: cnHelper({ 'prosemirror-stop-event': true }) },
|
|
155
|
+
React.createElement(Icon, { data: DotsIcon, className: cnHelper({ 'prosemirror-stop-event': true }) })),
|
|
156
|
+
React.createElement(Popup, { anchorRef: buttonRef, open: menuOpen, onClose: toggleMenuOpen, placement: ['bottom-end'] },
|
|
157
|
+
React.createElement(Menu, null,
|
|
158
|
+
React.createElement(Menu.Item, { onClick: () => {
|
|
159
|
+
toggleEditing();
|
|
160
|
+
toggleMenuOpen();
|
|
161
|
+
} }, i18n('edit')),
|
|
162
|
+
React.createElement(Menu.Item, { onClick: () => {
|
|
163
|
+
const pos = getPos();
|
|
164
|
+
if (pos === undefined)
|
|
165
|
+
return;
|
|
166
|
+
removeNode({
|
|
167
|
+
node,
|
|
168
|
+
pos,
|
|
169
|
+
tr: view.state.tr,
|
|
170
|
+
dispatch: view.dispatch,
|
|
171
|
+
});
|
|
172
|
+
} }, i18n('remove')))))));
|
|
173
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NodeView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NodeView';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum YfmHtmlBlockAttrs {
|
|
2
|
+
class = "class",
|
|
3
|
+
frameborder = "frameborder",
|
|
4
|
+
newCreated = "newCreated",
|
|
5
|
+
srcdoc = "srcdoc",
|
|
6
|
+
style = "style"
|
|
7
|
+
}
|
|
8
|
+
export declare const yfmHtmlBlockNodeName = "yfm_html_block";
|
|
9
|
+
export declare const yfmHtmlBlockNodeType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
10
|
+
export declare const YfmHtmlBlockAction = "createYfmHtmlBlock";
|
|
11
|
+
export declare const YfmHtmlBlockConsts: {
|
|
12
|
+
readonly NodeName: "yfm_html_block";
|
|
13
|
+
readonly NodeAttrs: typeof YfmHtmlBlockAttrs;
|
|
14
|
+
readonly nodeType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { nodeTypeFactory } from '../../../../utils/schema';
|
|
2
|
+
export var YfmHtmlBlockAttrs;
|
|
3
|
+
(function (YfmHtmlBlockAttrs) {
|
|
4
|
+
YfmHtmlBlockAttrs["class"] = "class";
|
|
5
|
+
YfmHtmlBlockAttrs["frameborder"] = "frameborder";
|
|
6
|
+
YfmHtmlBlockAttrs["newCreated"] = "newCreated";
|
|
7
|
+
YfmHtmlBlockAttrs["srcdoc"] = "srcdoc";
|
|
8
|
+
YfmHtmlBlockAttrs["style"] = "style";
|
|
9
|
+
})(YfmHtmlBlockAttrs || (YfmHtmlBlockAttrs = {}));
|
|
10
|
+
export const yfmHtmlBlockNodeName = 'yfm_html_block';
|
|
11
|
+
export const yfmHtmlBlockNodeType = nodeTypeFactory(yfmHtmlBlockNodeName);
|
|
12
|
+
export const YfmHtmlBlockAction = 'createYfmHtmlBlock';
|
|
13
|
+
export const YfmHtmlBlockConsts = {
|
|
14
|
+
NodeName: yfmHtmlBlockNodeName,
|
|
15
|
+
NodeAttrs: YfmHtmlBlockAttrs,
|
|
16
|
+
nodeType: yfmHtmlBlockNodeType,
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtensionNodeSpec } from '../../../../core';
|
|
2
|
+
export { yfmHtmlBlockNodeName } from './const';
|
|
3
|
+
export declare type YfmHtmlBlockSpecsOptions = {
|
|
4
|
+
nodeView?: ExtensionNodeSpec['view'];
|
|
5
|
+
};
|
|
6
|
+
export declare const YfmHtmlBlockSpecs: import("../../../../core").ExtensionWithOptions<YfmHtmlBlockSpecsOptions> & {
|
|
7
|
+
readonly NodeName: "yfm_html_block";
|
|
8
|
+
readonly NodeAttrs: typeof import("./const").YfmHtmlBlockAttrs;
|
|
9
|
+
readonly nodeType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
10
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { transform } from '@diplodoc/html-extension';
|
|
3
|
+
import { YfmHtmlBlockConsts } from './const';
|
|
4
|
+
export { yfmHtmlBlockNodeName } from './const';
|
|
5
|
+
const YfmHtmlBlockSpecsExtension = (builder, { nodeView }) => {
|
|
6
|
+
builder
|
|
7
|
+
.configureMd((md) => md.use(transform({ bundle: false }), {}))
|
|
8
|
+
.addNode(YfmHtmlBlockConsts.NodeName, () => ({
|
|
9
|
+
fromMd: {
|
|
10
|
+
tokenSpec: {
|
|
11
|
+
name: YfmHtmlBlockConsts.NodeName,
|
|
12
|
+
type: 'node',
|
|
13
|
+
noCloseToken: true,
|
|
14
|
+
getAttrs: (token) => { var _a; return Object.fromEntries((_a = token.attrs) !== null && _a !== void 0 ? _a : []); },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
spec: {
|
|
18
|
+
group: 'block',
|
|
19
|
+
attrs: {
|
|
20
|
+
[YfmHtmlBlockConsts.NodeAttrs.class]: { default: 'yfm-html' },
|
|
21
|
+
[YfmHtmlBlockConsts.NodeAttrs.frameborder]: { default: '' },
|
|
22
|
+
[YfmHtmlBlockConsts.NodeAttrs.srcdoc]: { default: '' },
|
|
23
|
+
[YfmHtmlBlockConsts.NodeAttrs.style]: { default: null },
|
|
24
|
+
[YfmHtmlBlockConsts.NodeAttrs.newCreated]: { default: null },
|
|
25
|
+
},
|
|
26
|
+
toDOM: (node) => ['iframe', node.attrs],
|
|
27
|
+
},
|
|
28
|
+
toMd: (state, node) => {
|
|
29
|
+
state.write('::: html');
|
|
30
|
+
state.write('\n');
|
|
31
|
+
state.write(node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc]);
|
|
32
|
+
state.ensureNewLine();
|
|
33
|
+
state.write(':::');
|
|
34
|
+
state.closeBlock(node);
|
|
35
|
+
},
|
|
36
|
+
view: nodeView,
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
export const YfmHtmlBlockSpecs = Object.assign(YfmHtmlBlockSpecsExtension, YfmHtmlBlockConsts);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { YfmHtmlBlockConsts, yfmHtmlBlockNodeType } from './YfmHtmlBlockSpecs/const';
|
|
2
|
+
export const addYfmHtmlBlock = {
|
|
3
|
+
isEnable(state) {
|
|
4
|
+
return state.selection.empty;
|
|
5
|
+
},
|
|
6
|
+
run(state, dispatch, _view) {
|
|
7
|
+
dispatch(state.tr.insert(state.selection.from, yfmHtmlBlockNodeType(state.schema).create({
|
|
8
|
+
[YfmHtmlBlockConsts.NodeAttrs.srcdoc]: '\n',
|
|
9
|
+
[YfmHtmlBlockConsts.NodeAttrs.newCreated]: true,
|
|
10
|
+
})));
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
|
|
2
|
+
import { Action, ExtensionAuto } from '../../../core';
|
|
3
|
+
import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
|
|
4
|
+
export declare type YfmHtmlBlockOptions = {
|
|
5
|
+
useConfig?: () => IHTMLIFrameElementConfig | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const YfmHtmlBlock: ExtensionAuto<YfmHtmlBlockOptions>;
|
|
8
|
+
declare global {
|
|
9
|
+
namespace WysiwygEditor {
|
|
10
|
+
interface Actions {
|
|
11
|
+
[YfmHtmlBlockAction]: Action;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WYfmHtmlBlockNodeView } from './YfmHtmlBlockNodeView';
|
|
2
|
+
import { YfmHtmlBlockSpecs } from './YfmHtmlBlockSpecs';
|
|
3
|
+
import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
|
|
4
|
+
import { addYfmHtmlBlock } from './actions';
|
|
5
|
+
export const YfmHtmlBlock = (builder, options) => {
|
|
6
|
+
builder.use(YfmHtmlBlockSpecs, {
|
|
7
|
+
nodeView: YfmHtmlBlockNodeViewFactory(options),
|
|
8
|
+
});
|
|
9
|
+
builder.addAction(YfmHtmlBlockAction, () => addYfmHtmlBlock);
|
|
10
|
+
};
|
|
11
|
+
const YfmHtmlBlockNodeViewFactory = (options) => () => (node, view, getPos) => {
|
|
12
|
+
return new WYfmHtmlBlockNodeView({ node, view, getPos, options });
|
|
13
|
+
};
|
|
@@ -4,8 +4,8 @@ export * from './Emoji';
|
|
|
4
4
|
export * from './ImgSize';
|
|
5
5
|
export * from './Monospace';
|
|
6
6
|
export * from './Video';
|
|
7
|
-
export * from './YfmCut';
|
|
8
7
|
export * from './YfmConfigs';
|
|
8
|
+
export * from './YfmCut';
|
|
9
9
|
export * from './YfmFile';
|
|
10
10
|
export * from './YfmHeading';
|
|
11
11
|
export * from './YfmNote';
|
|
@@ -4,8 +4,8 @@ export * from './Emoji';
|
|
|
4
4
|
export * from './ImgSize';
|
|
5
5
|
export * from './Monospace';
|
|
6
6
|
export * from './Video';
|
|
7
|
-
export * from './YfmCut';
|
|
8
7
|
export * from './YfmConfigs';
|
|
8
|
+
export * from './YfmCut';
|
|
9
9
|
export * from './YfmFile';
|
|
10
10
|
export * from './YfmHeading';
|
|
11
11
|
export * from './YfmNote';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"cancel": "Cancel",
|
|
3
|
+
"delete": "Delete",
|
|
3
4
|
"edit": "Edit",
|
|
4
|
-
"
|
|
5
|
+
"preview": "Preview",
|
|
6
|
+
"remove": "Remove",
|
|
7
|
+
"save": "Save",
|
|
8
|
+
"toolbar_action_disabled": "Incompatible markup element"
|
|
5
9
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export declare const i18n: <G extends "
|
|
1
|
+
export declare const i18n: <G extends "remove" | "cancel" | "delete" | "edit" | "preview" | "save" | "toolbar_action_disabled", S extends string>(key: G | (string extends S ? S : never), params?: {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
} | undefined) => S extends G ? {
|
|
4
|
-
|
|
5
|
-
edit: string;
|
|
4
|
+
cancel: string;
|
|
6
5
|
delete: string;
|
|
6
|
+
edit: string;
|
|
7
|
+
preview: string;
|
|
8
|
+
remove: string;
|
|
9
|
+
save: string;
|
|
10
|
+
toolbar_action_disabled: string;
|
|
7
11
|
}[G] : string;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"cancel": "Отмена",
|
|
3
|
+
"delete": "Удалить",
|
|
3
4
|
"edit": "Редактировать",
|
|
4
|
-
"
|
|
5
|
+
"preview": "Предпросмотр",
|
|
6
|
+
"remove": "Удалить",
|
|
7
|
+
"save": "Сохранить",
|
|
8
|
+
"toolbar_action_disabled": "Несовместимый элемент разметки"
|
|
5
9
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
"undo": "Undo",
|
|
3
|
-
"redo": "Redo",
|
|
4
2
|
"bold": "Bold",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
3
|
+
"checkbox": "Checkbox",
|
|
4
|
+
"code": "Code",
|
|
5
|
+
"code_inline": "Inline code",
|
|
6
|
+
"codeblock": "Code block",
|
|
7
|
+
"colorify": "Text color",
|
|
8
|
+
"colorify__color_blue": "Blue",
|
|
9
|
+
"colorify__color_default": "Default",
|
|
10
|
+
"colorify__color_gray": "Gray",
|
|
11
|
+
"colorify__color_green": "Green",
|
|
12
|
+
"colorify__color_orange": "Orange",
|
|
13
|
+
"colorify__color_red": "Red",
|
|
14
|
+
"colorify__color_violet": "Violet",
|
|
15
|
+
"colorify__color_yellow": "Yellow",
|
|
16
|
+
"colorify__group_text": "Text",
|
|
17
|
+
"cut": "Cut",
|
|
18
|
+
"emoji": "Emoji",
|
|
19
|
+
"file": "File",
|
|
11
20
|
"heading": "Heading",
|
|
12
21
|
"heading1": "Heading 1",
|
|
13
22
|
"heading2": "Heading 2",
|
|
@@ -15,39 +24,31 @@
|
|
|
15
24
|
"heading4": "Heading 4",
|
|
16
25
|
"heading5": "Heading 5",
|
|
17
26
|
"heading6": "Heading 6",
|
|
27
|
+
"hrule": "Separator",
|
|
28
|
+
"html": "HTML",
|
|
29
|
+
"image": "Image",
|
|
30
|
+
"italic": "Italic",
|
|
31
|
+
"link": "Link",
|
|
18
32
|
"list": "List",
|
|
19
|
-
"ulist": "Bullet list",
|
|
20
|
-
"olist": "Ordered list",
|
|
21
|
-
"list__action_sink": "Sink item",
|
|
22
33
|
"list__action_lift": "Lift item",
|
|
34
|
+
"list__action_sink": "Sink item",
|
|
23
35
|
"list_action_disabled": "Contradicts the logic of the list",
|
|
24
|
-
"
|
|
25
|
-
"quote": "Quote",
|
|
26
|
-
"cut": "Cut",
|
|
27
|
-
"note": "Note",
|
|
28
|
-
"table": "Table",
|
|
29
|
-
"link": "Link",
|
|
30
|
-
"code": "Code",
|
|
31
|
-
"code_inline": "Inline code",
|
|
32
|
-
"codeblock": "Code block",
|
|
33
|
-
"image": "Image",
|
|
34
|
-
"hrule": "Separator",
|
|
35
|
-
"emoji": "Emoji",
|
|
36
|
-
"file": "File",
|
|
36
|
+
"mark": "Marked",
|
|
37
37
|
"math": "Math",
|
|
38
|
-
"math_inline": "Inline math",
|
|
39
38
|
"math_block": "Math block",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"colorify__color_gray": "Gray",
|
|
44
|
-
"colorify__color_yellow": "Yellow",
|
|
45
|
-
"colorify__color_orange": "Orange",
|
|
46
|
-
"colorify__color_red": "Red",
|
|
47
|
-
"colorify__color_green": "Green",
|
|
48
|
-
"colorify__color_blue": "Blue",
|
|
49
|
-
"colorify__color_violet": "Violet",
|
|
39
|
+
"math_inline": "Inline math",
|
|
40
|
+
"mermaid": "Mermaid",
|
|
41
|
+
"mono": "Monospace",
|
|
50
42
|
"more_action": "More action",
|
|
43
|
+
"note": "Note",
|
|
44
|
+
"olist": "Ordered list",
|
|
45
|
+
"quote": "Quote",
|
|
46
|
+
"redo": "Redo",
|
|
47
|
+
"strike": "Strikethrough",
|
|
48
|
+
"table": "Table",
|
|
51
49
|
"tabs": "Tabs",
|
|
52
|
-
"
|
|
50
|
+
"text": "Text",
|
|
51
|
+
"ulist": "Bullet list",
|
|
52
|
+
"underline": "Underline",
|
|
53
|
+
"undo": "Undo"
|
|
53
54
|
}
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
export declare const i18n: <G extends "bold" | "code" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "colorify" | "mono" | "text" | "cut" | "table" | "image" | "code_inline" | "heading" | "note" | "file" | "codeblock" | "checkbox" | "emoji" | "list" | "tabs" | "math" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "undo" | "redo" | "math_inline" | "math_block" | "
|
|
1
|
+
export declare const i18n: <G extends "bold" | "code" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "colorify" | "mono" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "heading" | "note" | "file" | "codeblock" | "checkbox" | "emoji" | "list" | "tabs" | "math" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "undo" | "redo" | "math_inline" | "math_block" | "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" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "mermaid" | "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
|
-
undo: string;
|
|
5
|
-
redo: string;
|
|
6
4
|
bold: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
checkbox: string;
|
|
6
|
+
code: string;
|
|
7
|
+
code_inline: string;
|
|
8
|
+
codeblock: string;
|
|
9
|
+
colorify: string;
|
|
10
|
+
colorify__color_blue: string;
|
|
11
|
+
colorify__color_default: string;
|
|
12
|
+
colorify__color_gray: string;
|
|
13
|
+
colorify__color_green: string;
|
|
14
|
+
colorify__color_orange: string;
|
|
15
|
+
colorify__color_red: string;
|
|
16
|
+
colorify__color_violet: string;
|
|
17
|
+
colorify__color_yellow: string;
|
|
18
|
+
colorify__group_text: string;
|
|
19
|
+
cut: string;
|
|
20
|
+
emoji: string;
|
|
21
|
+
file: string;
|
|
13
22
|
heading: string;
|
|
14
23
|
heading1: string;
|
|
15
24
|
heading2: string;
|
|
@@ -17,39 +26,31 @@ export declare const i18n: <G extends "bold" | "code" | "link" | "italic" | "str
|
|
|
17
26
|
heading4: string;
|
|
18
27
|
heading5: string;
|
|
19
28
|
heading6: string;
|
|
29
|
+
hrule: string;
|
|
30
|
+
html: string;
|
|
31
|
+
image: string;
|
|
32
|
+
italic: string;
|
|
33
|
+
link: string;
|
|
20
34
|
list: string;
|
|
21
|
-
ulist: string;
|
|
22
|
-
olist: string;
|
|
23
|
-
list__action_sink: string;
|
|
24
35
|
list__action_lift: string;
|
|
36
|
+
list__action_sink: string;
|
|
25
37
|
list_action_disabled: string;
|
|
26
|
-
|
|
27
|
-
quote: string;
|
|
28
|
-
cut: string;
|
|
29
|
-
note: string;
|
|
30
|
-
table: string;
|
|
31
|
-
link: string;
|
|
32
|
-
code: string;
|
|
33
|
-
code_inline: string;
|
|
34
|
-
codeblock: string;
|
|
35
|
-
image: string;
|
|
36
|
-
hrule: string;
|
|
37
|
-
emoji: string;
|
|
38
|
-
file: string;
|
|
38
|
+
mark: string;
|
|
39
39
|
math: string;
|
|
40
|
-
math_inline: string;
|
|
41
40
|
math_block: string;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
colorify__color_gray: string;
|
|
46
|
-
colorify__color_yellow: string;
|
|
47
|
-
colorify__color_orange: string;
|
|
48
|
-
colorify__color_red: string;
|
|
49
|
-
colorify__color_green: string;
|
|
50
|
-
colorify__color_blue: string;
|
|
51
|
-
colorify__color_violet: string;
|
|
41
|
+
math_inline: string;
|
|
42
|
+
mermaid: string;
|
|
43
|
+
mono: string;
|
|
52
44
|
more_action: string;
|
|
45
|
+
note: string;
|
|
46
|
+
olist: string;
|
|
47
|
+
quote: string;
|
|
48
|
+
redo: string;
|
|
49
|
+
strike: string;
|
|
50
|
+
table: string;
|
|
53
51
|
tabs: string;
|
|
54
|
-
|
|
52
|
+
text: string;
|
|
53
|
+
ulist: string;
|
|
54
|
+
underline: string;
|
|
55
|
+
undo: string;
|
|
55
56
|
}[G] : string;
|