@gravity-ui/markdown-editor 13.15.0 → 13.17.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.js +30 -1
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +31 -9
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.js +2 -2
- package/build/cjs/extensions/yfm/YfmHtmlBlock/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmHtmlBlock/utils.js +19 -0
- package/build/cjs/version.js +1 -1
- package/build/cjs/view/hocs/withYfmHtml/index.js +2 -2
- package/build/esm/bundle/Editor.js +30 -1
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +31 -9
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmHtmlBlock/YfmHtmlBlockSpecs/index.js +2 -2
- package/build/esm/extensions/yfm/YfmHtmlBlock/index.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmHtmlBlock/utils.js +19 -0
- package/build/esm/version.js +1 -1
- package/build/esm/view/hocs/withYfmHtml/index.js +3 -3
- package/package.json +3 -3
|
@@ -3,6 +3,7 @@ var _EditorImpl_markup, _EditorImpl_editorMode, _EditorImpl_toolbarVisible, _Edi
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.EditorImpl = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const view_1 = require("@codemirror/view");
|
|
6
7
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
8
|
const core_1 = require("../core");
|
|
8
9
|
const bundle_1 = require("../i18n/bundle");
|
|
@@ -265,11 +266,28 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
265
266
|
let cmLine = line + 1; // lines in codemirror is 1-based
|
|
266
267
|
cmLine = Math.max(cmLine, 1);
|
|
267
268
|
cmLine = Math.min(cmLine, view.state.doc.lines);
|
|
269
|
+
const yMargin = getTopOffset();
|
|
270
|
+
const anchor = view.state.doc.line(cmLine).from;
|
|
268
271
|
view.dispatch({
|
|
269
272
|
scrollIntoView: true,
|
|
270
|
-
selection: { anchor
|
|
273
|
+
selection: { anchor },
|
|
274
|
+
effects: [
|
|
275
|
+
view_1.EditorView.scrollIntoView(anchor, { y: 'start', x: 'start', yMargin }),
|
|
276
|
+
],
|
|
271
277
|
});
|
|
272
278
|
break;
|
|
279
|
+
// eslint-disable-next-line no-inner-declarations
|
|
280
|
+
function getTopOffset() {
|
|
281
|
+
const TOOLBAR_HEIGHT = 36; //px
|
|
282
|
+
const TOOLBAR_BOTTOM_OFFSET = 8; // px
|
|
283
|
+
const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
|
|
284
|
+
const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
|
|
285
|
+
const topOffsetValue = window
|
|
286
|
+
.getComputedStyle(view.dom)
|
|
287
|
+
.getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
|
|
288
|
+
const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
|
|
289
|
+
return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
|
|
290
|
+
}
|
|
273
291
|
}
|
|
274
292
|
case 'wysiwyg': {
|
|
275
293
|
const node = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
|
|
@@ -292,3 +310,14 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
292
310
|
}
|
|
293
311
|
exports.EditorImpl = EditorImpl;
|
|
294
312
|
_EditorImpl_markup = new WeakMap(), _EditorImpl_editorMode = new WeakMap(), _EditorImpl_toolbarVisible = new WeakMap(), _EditorImpl_splitModeEnabled = new WeakMap(), _EditorImpl_splitMode = new WeakMap(), _EditorImpl_renderPreview = new WeakMap(), _EditorImpl_wysiwygEditor = new WeakMap(), _EditorImpl_markupEditor = new WeakMap(), _EditorImpl_markupConfig = new WeakMap(), _EditorImpl_escapeConfig = new WeakMap(), _EditorImpl_preset = new WeakMap(), _EditorImpl_allowHTML = new WeakMap(), _EditorImpl_linkify = new WeakMap(), _EditorImpl_linkifyTlds = new WeakMap(), _EditorImpl_extensions = new WeakMap(), _EditorImpl_renderStorage = new WeakMap(), _EditorImpl_fileUploadHandler = new WeakMap(), _EditorImpl_needToSetDimensionsForUploadedImages = new WeakMap(), _EditorImpl_prepareRawMarkup = new WeakMap(), _EditorImpl_beforeEditorModeChange = new WeakMap();
|
|
313
|
+
function calculateCSSNumberValue(cssValue) {
|
|
314
|
+
const tmp = document.createElement('div');
|
|
315
|
+
tmp.style.position = 'absolute';
|
|
316
|
+
tmp.style.top = '-99999px';
|
|
317
|
+
tmp.style.left = '-99999px';
|
|
318
|
+
tmp.style.width = `calc(${cssValue})`;
|
|
319
|
+
document.body.appendChild(tmp);
|
|
320
|
+
const value = tmp.getBoundingClientRect().width;
|
|
321
|
+
tmp.remove();
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
@@ -22,6 +22,16 @@ function generateID() {
|
|
|
22
22
|
exports.generateID = generateID;
|
|
23
23
|
const DEFAULT_PADDING = 20;
|
|
24
24
|
const DEFAULT_DELAY = 100;
|
|
25
|
+
const createLinkCLickHandler = (value, document) => (event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
const targetId = value.getAttribute('href');
|
|
28
|
+
if (targetId) {
|
|
29
|
+
const targetElement = document.querySelector(targetId);
|
|
30
|
+
if (targetElement) {
|
|
31
|
+
targetElement.scrollIntoView({ behavior: 'smooth' });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
25
35
|
const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
26
36
|
var _a, _b, _c, _d, _e, _f;
|
|
27
37
|
const ref = (0, react_1.useRef)(null);
|
|
@@ -30,11 +40,6 @@ const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
|
30
40
|
const resizeConfig = (0, react_1.useRef)({});
|
|
31
41
|
const [height, setHeight] = (0, react_1.useState)('100%');
|
|
32
42
|
(0, react_1.useEffect)(() => {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
resizeConfig.current = {
|
|
35
|
-
padding: (_a = config === null || config === void 0 ? void 0 : config.resizePadding) !== null && _a !== void 0 ? _a : DEFAULT_PADDING,
|
|
36
|
-
delay: (_b = config === null || config === void 0 ? void 0 : config.resizeDelay) !== null && _b !== void 0 ? _b : DEFAULT_DELAY,
|
|
37
|
-
};
|
|
38
43
|
setStyles(config === null || config === void 0 ? void 0 : config.styles);
|
|
39
44
|
setClassNames(config === null || config === void 0 ? void 0 : config.classNames);
|
|
40
45
|
}, [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]);
|
|
@@ -103,18 +108,35 @@ const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
|
103
108
|
styles.current = newStyles;
|
|
104
109
|
}
|
|
105
110
|
};
|
|
106
|
-
|
|
111
|
+
// finds all relative links (href^="#") and changes their click behavior
|
|
112
|
+
const createAnchorLinkHandlers = (type) => () => {
|
|
107
113
|
var _a;
|
|
114
|
+
const document = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow.document;
|
|
115
|
+
if (document) {
|
|
116
|
+
document.querySelectorAll('a[href^="#"]').forEach((value) => {
|
|
117
|
+
const handler = createLinkCLickHandler(value, document);
|
|
118
|
+
if (type === 'add') {
|
|
119
|
+
value.addEventListener('click', handler);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
value.removeEventListener('click', handler);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
(0, react_1.useEffect)(() => {
|
|
128
|
+
var _a, _b;
|
|
108
129
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('load', handleLoadIFrame);
|
|
130
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.addEventListener('load', createAnchorLinkHandlers('add'));
|
|
109
131
|
return () => {
|
|
110
|
-
var _a;
|
|
132
|
+
var _a, _b;
|
|
111
133
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('load', handleLoadIFrame);
|
|
134
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('load', createAnchorLinkHandlers('remove'));
|
|
112
135
|
};
|
|
113
136
|
}, [html]);
|
|
114
137
|
(0, react_1.useEffect)(() => {
|
|
115
|
-
var _a, _b;
|
|
116
138
|
if (ref.current) {
|
|
117
|
-
const resizeObserver = new window.ResizeObserver((0, debounce_1.default)(handleResizeIFrame,
|
|
139
|
+
const resizeObserver = new window.ResizeObserver((0, debounce_1.default)(handleResizeIFrame, DEFAULT_DELAY));
|
|
118
140
|
resizeObserver.observe(ref.current);
|
|
119
141
|
}
|
|
120
142
|
}, [(_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]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
|
|
2
2
|
import type { ExtensionNodeSpec } from '../../../../core';
|
|
3
3
|
export { yfmHtmlBlockNodeName } from './const';
|
|
4
|
-
export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle'> {
|
|
4
|
+
export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
|
|
5
5
|
nodeView?: ExtensionNodeSpec['view'];
|
|
6
6
|
}
|
|
7
7
|
export declare const YfmHtmlBlockSpecs: import("../../../../core").ExtensionWithOptions<YfmHtmlBlockSpecsOptions> & {
|
|
@@ -10,14 +10,14 @@ Object.defineProperty(exports, "yfmHtmlBlockNodeName", { enumerable: true, get:
|
|
|
10
10
|
const YfmHtmlBlockSpecsExtension = (builder, _a) => {
|
|
11
11
|
var { nodeView } = _a, options = tslib_1.__rest(_a, ["nodeView"]);
|
|
12
12
|
builder
|
|
13
|
-
.configureMd((md) => md.use((0, html_extension_1.transform)(Object.assign({ bundle: false }, options)), {}))
|
|
13
|
+
.configureMd((md) => md.use((0, html_extension_1.transform)(Object.assign({ bundle: false, embeddingMode: 'srcdoc' }, options)), {}))
|
|
14
14
|
.addNode(const_1.YfmHtmlBlockConsts.NodeName, () => ({
|
|
15
15
|
fromMd: {
|
|
16
16
|
tokenSpec: {
|
|
17
17
|
name: const_1.YfmHtmlBlockConsts.NodeName,
|
|
18
18
|
type: 'node',
|
|
19
19
|
noCloseToken: true,
|
|
20
|
-
getAttrs: (
|
|
20
|
+
getAttrs: ({ content }) => ({ srcdoc: content }),
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
spec: {
|
|
@@ -2,7 +2,7 @@ import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
|
|
|
2
2
|
import type { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
|
|
3
3
|
import { Action, ExtensionAuto } from '../../../core';
|
|
4
4
|
import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
|
|
5
|
-
export interface YfmHtmlBlockOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle'> {
|
|
5
|
+
export interface YfmHtmlBlockOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
|
|
6
6
|
useConfig?: () => IHTMLIFrameElementConfig | undefined;
|
|
7
7
|
}
|
|
8
8
|
export declare const YfmHtmlBlock: ExtensionAuto<YfmHtmlBlockOptions>;
|
|
@@ -6,6 +6,7 @@ const sanitize_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/sani
|
|
|
6
6
|
// yfmHtmlBlock additional css properties white list
|
|
7
7
|
const getYfmHtmlBlockWhiteList = () => {
|
|
8
8
|
const whiteList = {};
|
|
9
|
+
// flex, grid, column
|
|
9
10
|
whiteList['align-content'] = true; // default: auto
|
|
10
11
|
whiteList['align-items'] = true; // default: auto
|
|
11
12
|
whiteList['align-self'] = true; // default: auto
|
|
@@ -51,6 +52,24 @@ const getYfmHtmlBlockWhiteList = () => {
|
|
|
51
52
|
whiteList.order = true; // default: 0
|
|
52
53
|
whiteList.orphans = true; // default: 2
|
|
53
54
|
whiteList['row-gap'] = true;
|
|
55
|
+
// position, opacity, overflow
|
|
56
|
+
whiteList['all'] = true; // default: depending on individual properties
|
|
57
|
+
whiteList['bottom'] = true; // default: auto
|
|
58
|
+
whiteList['content'] = true; // default: normal
|
|
59
|
+
whiteList['cursor'] = true; // default: auto
|
|
60
|
+
whiteList['direction'] = true; // default: ltr
|
|
61
|
+
whiteList['left'] = true; // default: auto
|
|
62
|
+
whiteList['line-break'] = true; // default: auto
|
|
63
|
+
whiteList['opacity'] = true; // default: 1
|
|
64
|
+
whiteList['overflow'] = true; // default: depending on individual properties
|
|
65
|
+
whiteList['overflow-wrap'] = true; // default: normal
|
|
66
|
+
whiteList['overflow-x'] = true; // default: visible
|
|
67
|
+
whiteList['overflow-y'] = true; // default: visible
|
|
68
|
+
whiteList['position'] = true; // default: static
|
|
69
|
+
whiteList['right'] = true; // default: auto
|
|
70
|
+
whiteList['top'] = true; // default: auto
|
|
71
|
+
whiteList['white-space'] = true; // default: normal
|
|
72
|
+
whiteList['z-index'] = true; // default: auto
|
|
54
73
|
return whiteList;
|
|
55
74
|
};
|
|
56
75
|
// yfmHtmlBlock additional allowedTags
|
package/build/cjs/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '13.
|
|
5
|
+
exports.VERSION = typeof '13.17.0' !== 'undefined' ? '13.17.0' : 'unknown';
|
|
@@ -9,13 +9,13 @@ function withYfmHtmlBlock(opts) {
|
|
|
9
9
|
return (Component) => (0, react_1.forwardRef)(function WithYfmHtml(props, ref) {
|
|
10
10
|
const { meta, html, yfmHtmlBlockConfig } = props;
|
|
11
11
|
(0, useYfmHtmlBlockRuntime_1.useYfmHtmlBlockRuntime)(meta, opts.runtime);
|
|
12
|
-
const yfmHtmlBlock = (0, react_2.
|
|
12
|
+
const yfmHtmlBlock = (0, react_2.useDiplodocEmbeddedContentController)();
|
|
13
13
|
(0, react_1.useEffect)(() => {
|
|
14
14
|
if (yfmHtmlBlock) {
|
|
15
15
|
if (yfmHtmlBlockConfig) {
|
|
16
16
|
yfmHtmlBlock.setConfig(yfmHtmlBlockConfig);
|
|
17
17
|
}
|
|
18
|
-
yfmHtmlBlock.
|
|
18
|
+
yfmHtmlBlock.initialize();
|
|
19
19
|
}
|
|
20
20
|
}, [yfmHtmlBlock, html, yfmHtmlBlockConfig]);
|
|
21
21
|
return react_1.default.createElement(Component, Object.assign({}, props, { ref: ref }));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var _EditorImpl_markup, _EditorImpl_editorMode, _EditorImpl_toolbarVisible, _EditorImpl_splitModeEnabled, _EditorImpl_splitMode, _EditorImpl_renderPreview, _EditorImpl_wysiwygEditor, _EditorImpl_markupEditor, _EditorImpl_markupConfig, _EditorImpl_escapeConfig, _EditorImpl_preset, _EditorImpl_allowHTML, _EditorImpl_linkify, _EditorImpl_linkifyTlds, _EditorImpl_extensions, _EditorImpl_renderStorage, _EditorImpl_fileUploadHandler, _EditorImpl_needToSetDimensionsForUploadedImages, _EditorImpl_prepareRawMarkup, _EditorImpl_beforeEditorModeChange;
|
|
2
2
|
import { __classPrivateFieldGet, __classPrivateFieldSet, __rest } from "tslib";
|
|
3
|
+
import { EditorView as CMEditorView } from '@codemirror/view';
|
|
3
4
|
import { TextSelection } from 'prosemirror-state';
|
|
4
5
|
import { WysiwygEditor } from '../core';
|
|
5
6
|
import { i18n } from '../i18n/bundle';
|
|
@@ -262,11 +263,28 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
262
263
|
let cmLine = line + 1; // lines in codemirror is 1-based
|
|
263
264
|
cmLine = Math.max(cmLine, 1);
|
|
264
265
|
cmLine = Math.min(cmLine, view.state.doc.lines);
|
|
266
|
+
const yMargin = getTopOffset();
|
|
267
|
+
const anchor = view.state.doc.line(cmLine).from;
|
|
265
268
|
view.dispatch({
|
|
266
269
|
scrollIntoView: true,
|
|
267
|
-
selection: { anchor
|
|
270
|
+
selection: { anchor },
|
|
271
|
+
effects: [
|
|
272
|
+
CMEditorView.scrollIntoView(anchor, { y: 'start', x: 'start', yMargin }),
|
|
273
|
+
],
|
|
268
274
|
});
|
|
269
275
|
break;
|
|
276
|
+
// eslint-disable-next-line no-inner-declarations
|
|
277
|
+
function getTopOffset() {
|
|
278
|
+
const TOOLBAR_HEIGHT = 36; //px
|
|
279
|
+
const TOOLBAR_BOTTOM_OFFSET = 8; // px
|
|
280
|
+
const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
|
|
281
|
+
const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
|
|
282
|
+
const topOffsetValue = window
|
|
283
|
+
.getComputedStyle(view.dom)
|
|
284
|
+
.getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
|
|
285
|
+
const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
|
|
286
|
+
return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
|
|
287
|
+
}
|
|
270
288
|
}
|
|
271
289
|
case 'wysiwyg': {
|
|
272
290
|
const node = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
|
|
@@ -288,3 +306,14 @@ export class EditorImpl extends SafeEventEmitter {
|
|
|
288
306
|
}
|
|
289
307
|
}
|
|
290
308
|
_EditorImpl_markup = new WeakMap(), _EditorImpl_editorMode = new WeakMap(), _EditorImpl_toolbarVisible = new WeakMap(), _EditorImpl_splitModeEnabled = new WeakMap(), _EditorImpl_splitMode = new WeakMap(), _EditorImpl_renderPreview = new WeakMap(), _EditorImpl_wysiwygEditor = new WeakMap(), _EditorImpl_markupEditor = new WeakMap(), _EditorImpl_markupConfig = new WeakMap(), _EditorImpl_escapeConfig = new WeakMap(), _EditorImpl_preset = new WeakMap(), _EditorImpl_allowHTML = new WeakMap(), _EditorImpl_linkify = new WeakMap(), _EditorImpl_linkifyTlds = new WeakMap(), _EditorImpl_extensions = new WeakMap(), _EditorImpl_renderStorage = new WeakMap(), _EditorImpl_fileUploadHandler = new WeakMap(), _EditorImpl_needToSetDimensionsForUploadedImages = new WeakMap(), _EditorImpl_prepareRawMarkup = new WeakMap(), _EditorImpl_beforeEditorModeChange = new WeakMap();
|
|
309
|
+
function calculateCSSNumberValue(cssValue) {
|
|
310
|
+
const tmp = document.createElement('div');
|
|
311
|
+
tmp.style.position = 'absolute';
|
|
312
|
+
tmp.style.top = '-99999px';
|
|
313
|
+
tmp.style.left = '-99999px';
|
|
314
|
+
tmp.style.width = `calc(${cssValue})`;
|
|
315
|
+
document.body.appendChild(tmp);
|
|
316
|
+
const value = tmp.getBoundingClientRect().width;
|
|
317
|
+
tmp.remove();
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
@@ -18,6 +18,16 @@ export function generateID() {
|
|
|
18
18
|
}
|
|
19
19
|
const DEFAULT_PADDING = 20;
|
|
20
20
|
const DEFAULT_DELAY = 100;
|
|
21
|
+
const createLinkCLickHandler = (value, document) => (event) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
const targetId = value.getAttribute('href');
|
|
24
|
+
if (targetId) {
|
|
25
|
+
const targetElement = document.querySelector(targetId);
|
|
26
|
+
if (targetElement) {
|
|
27
|
+
targetElement.scrollIntoView({ behavior: 'smooth' });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
21
31
|
const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
22
32
|
var _a, _b, _c, _d, _e, _f;
|
|
23
33
|
const ref = useRef(null);
|
|
@@ -26,11 +36,6 @@ const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
|
26
36
|
const resizeConfig = useRef({});
|
|
27
37
|
const [height, setHeight] = useState('100%');
|
|
28
38
|
useEffect(() => {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
resizeConfig.current = {
|
|
31
|
-
padding: (_a = config === null || config === void 0 ? void 0 : config.resizePadding) !== null && _a !== void 0 ? _a : DEFAULT_PADDING,
|
|
32
|
-
delay: (_b = config === null || config === void 0 ? void 0 : config.resizeDelay) !== null && _b !== void 0 ? _b : DEFAULT_DELAY,
|
|
33
|
-
};
|
|
34
39
|
setStyles(config === null || config === void 0 ? void 0 : config.styles);
|
|
35
40
|
setClassNames(config === null || config === void 0 ? void 0 : config.classNames);
|
|
36
41
|
}, [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]);
|
|
@@ -99,18 +104,35 @@ const YfmHtmlBlockPreview = ({ html, onСlick, config }) => {
|
|
|
99
104
|
styles.current = newStyles;
|
|
100
105
|
}
|
|
101
106
|
};
|
|
102
|
-
|
|
107
|
+
// finds all relative links (href^="#") and changes their click behavior
|
|
108
|
+
const createAnchorLinkHandlers = (type) => () => {
|
|
103
109
|
var _a;
|
|
110
|
+
const document = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contentWindow.document;
|
|
111
|
+
if (document) {
|
|
112
|
+
document.querySelectorAll('a[href^="#"]').forEach((value) => {
|
|
113
|
+
const handler = createLinkCLickHandler(value, document);
|
|
114
|
+
if (type === 'add') {
|
|
115
|
+
value.addEventListener('click', handler);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
value.removeEventListener('click', handler);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
var _a, _b;
|
|
104
125
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('load', handleLoadIFrame);
|
|
126
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.addEventListener('load', createAnchorLinkHandlers('add'));
|
|
105
127
|
return () => {
|
|
106
|
-
var _a;
|
|
128
|
+
var _a, _b;
|
|
107
129
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('load', handleLoadIFrame);
|
|
130
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('load', createAnchorLinkHandlers('remove'));
|
|
108
131
|
};
|
|
109
132
|
}, [html]);
|
|
110
133
|
useEffect(() => {
|
|
111
|
-
var _a, _b;
|
|
112
134
|
if (ref.current) {
|
|
113
|
-
const resizeObserver = new window.ResizeObserver(debounce(handleResizeIFrame,
|
|
135
|
+
const resizeObserver = new window.ResizeObserver(debounce(handleResizeIFrame, DEFAULT_DELAY));
|
|
114
136
|
resizeObserver.observe(ref.current);
|
|
115
137
|
}
|
|
116
138
|
}, [(_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]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
|
|
2
2
|
import type { ExtensionNodeSpec } from '../../../../core';
|
|
3
3
|
export { yfmHtmlBlockNodeName } from './const';
|
|
4
|
-
export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle'> {
|
|
4
|
+
export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
|
|
5
5
|
nodeView?: ExtensionNodeSpec['view'];
|
|
6
6
|
}
|
|
7
7
|
export declare const YfmHtmlBlockSpecs: import("../../../../core").ExtensionWithOptions<YfmHtmlBlockSpecsOptions> & {
|
|
@@ -6,14 +6,14 @@ export { yfmHtmlBlockNodeName } from './const';
|
|
|
6
6
|
const YfmHtmlBlockSpecsExtension = (builder, _a) => {
|
|
7
7
|
var { nodeView } = _a, options = __rest(_a, ["nodeView"]);
|
|
8
8
|
builder
|
|
9
|
-
.configureMd((md) => md.use(transform(Object.assign({ bundle: false }, options)), {}))
|
|
9
|
+
.configureMd((md) => md.use(transform(Object.assign({ bundle: false, embeddingMode: 'srcdoc' }, options)), {}))
|
|
10
10
|
.addNode(YfmHtmlBlockConsts.NodeName, () => ({
|
|
11
11
|
fromMd: {
|
|
12
12
|
tokenSpec: {
|
|
13
13
|
name: YfmHtmlBlockConsts.NodeName,
|
|
14
14
|
type: 'node',
|
|
15
15
|
noCloseToken: true,
|
|
16
|
-
getAttrs: (
|
|
16
|
+
getAttrs: ({ content }) => ({ srcdoc: content }),
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
spec: {
|
|
@@ -2,7 +2,7 @@ import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
|
|
|
2
2
|
import type { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
|
|
3
3
|
import { Action, ExtensionAuto } from '../../../core';
|
|
4
4
|
import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
|
|
5
|
-
export interface YfmHtmlBlockOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle'> {
|
|
5
|
+
export interface YfmHtmlBlockOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
|
|
6
6
|
useConfig?: () => IHTMLIFrameElementConfig | undefined;
|
|
7
7
|
}
|
|
8
8
|
export declare const YfmHtmlBlock: ExtensionAuto<YfmHtmlBlockOptions>;
|
|
@@ -2,6 +2,7 @@ import diplodocSanitize from '@diplodoc/transform/lib/sanitize';
|
|
|
2
2
|
// yfmHtmlBlock additional css properties white list
|
|
3
3
|
const getYfmHtmlBlockWhiteList = () => {
|
|
4
4
|
const whiteList = {};
|
|
5
|
+
// flex, grid, column
|
|
5
6
|
whiteList['align-content'] = true; // default: auto
|
|
6
7
|
whiteList['align-items'] = true; // default: auto
|
|
7
8
|
whiteList['align-self'] = true; // default: auto
|
|
@@ -47,6 +48,24 @@ const getYfmHtmlBlockWhiteList = () => {
|
|
|
47
48
|
whiteList.order = true; // default: 0
|
|
48
49
|
whiteList.orphans = true; // default: 2
|
|
49
50
|
whiteList['row-gap'] = true;
|
|
51
|
+
// position, opacity, overflow
|
|
52
|
+
whiteList['all'] = true; // default: depending on individual properties
|
|
53
|
+
whiteList['bottom'] = true; // default: auto
|
|
54
|
+
whiteList['content'] = true; // default: normal
|
|
55
|
+
whiteList['cursor'] = true; // default: auto
|
|
56
|
+
whiteList['direction'] = true; // default: ltr
|
|
57
|
+
whiteList['left'] = true; // default: auto
|
|
58
|
+
whiteList['line-break'] = true; // default: auto
|
|
59
|
+
whiteList['opacity'] = true; // default: 1
|
|
60
|
+
whiteList['overflow'] = true; // default: depending on individual properties
|
|
61
|
+
whiteList['overflow-wrap'] = true; // default: normal
|
|
62
|
+
whiteList['overflow-x'] = true; // default: visible
|
|
63
|
+
whiteList['overflow-y'] = true; // default: visible
|
|
64
|
+
whiteList['position'] = true; // default: static
|
|
65
|
+
whiteList['right'] = true; // default: auto
|
|
66
|
+
whiteList['top'] = true; // default: auto
|
|
67
|
+
whiteList['white-space'] = true; // default: normal
|
|
68
|
+
whiteList['z-index'] = true; // default: auto
|
|
50
69
|
return whiteList;
|
|
51
70
|
};
|
|
52
71
|
// yfmHtmlBlock additional allowedTags
|
package/build/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** During build process, the current version will be injected here */
|
|
2
|
-
export const VERSION = typeof '13.
|
|
2
|
+
export const VERSION = typeof '13.17.0' !== 'undefined' ? '13.17.0' : 'unknown';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useDiplodocEmbeddedContentController } from '@diplodoc/html-extension/react';
|
|
3
3
|
import { useYfmHtmlBlockRuntime } from './useYfmHtmlBlockRuntime';
|
|
4
4
|
export function withYfmHtmlBlock(opts) {
|
|
5
5
|
return (Component) => forwardRef(function WithYfmHtml(props, ref) {
|
|
6
6
|
const { meta, html, yfmHtmlBlockConfig } = props;
|
|
7
7
|
useYfmHtmlBlockRuntime(meta, opts.runtime);
|
|
8
|
-
const yfmHtmlBlock =
|
|
8
|
+
const yfmHtmlBlock = useDiplodocEmbeddedContentController();
|
|
9
9
|
useEffect(() => {
|
|
10
10
|
if (yfmHtmlBlock) {
|
|
11
11
|
if (yfmHtmlBlockConfig) {
|
|
12
12
|
yfmHtmlBlock.setConfig(yfmHtmlBlockConfig);
|
|
13
13
|
}
|
|
14
|
-
yfmHtmlBlock.
|
|
14
|
+
yfmHtmlBlock.initialize();
|
|
15
15
|
}
|
|
16
16
|
}, [yfmHtmlBlock, html, yfmHtmlBlockConfig]);
|
|
17
17
|
return React.createElement(Component, Object.assign({}, props, { ref: ref }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/markdown-editor",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.17.0",
|
|
4
4
|
"description": "Markdown wysiwyg and markup editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
},
|
|
201
201
|
"devDependencies": {
|
|
202
202
|
"@diplodoc/folding-headings-extension": "0.1.0",
|
|
203
|
-
"@diplodoc/html-extension": "1.
|
|
203
|
+
"@diplodoc/html-extension": "2.1.0",
|
|
204
204
|
"@diplodoc/latex-extension": "1.0.3",
|
|
205
205
|
"@diplodoc/mermaid-extension": "1.2.1",
|
|
206
206
|
"@diplodoc/transform": "4.22.0",
|
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
},
|
|
276
276
|
"peerDependencies": {
|
|
277
277
|
"@diplodoc/folding-headings-extension": "^0.1.0",
|
|
278
|
-
"@diplodoc/html-extension": "
|
|
278
|
+
"@diplodoc/html-extension": "2.1.0",
|
|
279
279
|
"@diplodoc/latex-extension": "^1.0.3",
|
|
280
280
|
"@diplodoc/mermaid-extension": "^1.0.0",
|
|
281
281
|
"@diplodoc/transform": "^4.5.0",
|