@gravity-ui/markdown-editor 13.5.0 → 13.5.2

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.
@@ -51,7 +51,7 @@ class WYfmHtmlBlockNodeView {
51
51
  this.view.dispatch(tr);
52
52
  }
53
53
  renderYfmHtmlBlock() {
54
- return (0, react_dom_1.createPortal)(react_1.default.createElement(YfmHtmlBlockView_1.YfmHtmlBlockView, { useConfig: this.options.useConfig, view: this.view, onChange: this.onChange.bind(this), node: this.node, getPos: this.getPos }), this.dom);
54
+ return (0, react_dom_1.createPortal)(react_1.default.createElement(YfmHtmlBlockView_1.YfmHtmlBlockView, { getPos: this.getPos, node: this.node, onChange: this.onChange.bind(this), sanitize: this.options.sanitize, useConfig: this.options.useConfig, view: this.view }), this.dom);
55
55
  }
56
56
  }
57
57
  exports.WYfmHtmlBlockNodeView = WYfmHtmlBlockNodeView;
@@ -7,11 +7,12 @@ export declare const cnYfmHtmlBlock: import("@bem-react/classname").ClassNameFor
7
7
  export declare const cnHelper: import("@bem-react/classname").ClassNameFormatter;
8
8
  export declare function generateID(): string;
9
9
  export declare const YfmHtmlBlockView: React.FC<{
10
- view: EditorView;
10
+ getPos: () => number | undefined;
11
+ node: Node;
11
12
  onChange: (attrs: {
12
13
  [YfmHtmlBlockConsts.NodeAttrs.srcdoc]: string;
13
14
  }) => void;
14
- node: Node;
15
- getPos: () => number | undefined;
15
+ sanitize?: (dirtyHtml: string) => string;
16
16
  useConfig?: () => IHTMLIFrameElementConfig | undefined;
17
+ view: EditorView;
17
18
  }>;
@@ -137,7 +137,7 @@ const CodeEditMode = ({ initialText, onSave, onCancel }) => {
137
137
  react_1.default.createElement(uikit_1.Button, { onClick: () => onSave(text), view: 'action' },
138
138
  react_1.default.createElement("span", { className: (0, exports.cnHelper)({ 'prosemirror-stop-event': true }) }, (0, common_1.i18n)('save'))))))));
139
139
  };
140
- const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig }) => {
140
+ const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig, sanitize }) => {
141
141
  const [editing, setEditing, unsetEditing, toggleEditing] = (0, hooks_1.useBooleanState)(Boolean(node.attrs[const_1.YfmHtmlBlockConsts.NodeAttrs.newCreated]));
142
142
  const config = useConfig === null || useConfig === void 0 ? void 0 : useConfig();
143
143
  const [menuOpen, , , toggleMenuOpen] = (0, hooks_1.useBooleanState)(false);
@@ -151,9 +151,11 @@ const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig }) => {
151
151
  unsetEditing();
152
152
  } }));
153
153
  }
154
+ const dirtyHtml = node.attrs[const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc];
155
+ const html = sanitize ? sanitize(dirtyHtml) : dirtyHtml;
154
156
  return (react_1.default.createElement("div", { className: b(), onDoubleClick: setEditing },
155
157
  react_1.default.createElement(uikit_1.Label, { className: b('label'), icon: react_1.default.createElement(uikit_1.Icon, { size: 16, data: icons_1.Eye }) }, (0, common_1.i18n)('preview')),
156
- react_1.default.createElement(YfmHtmlBlockPreview, { html: node.attrs[const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc], "on\u0421lick": handleClick, config: config }),
158
+ react_1.default.createElement(YfmHtmlBlockPreview, { html: html, "on\u0421lick": handleClick, config: config }),
157
159
  react_1.default.createElement("div", { className: b('menu') },
158
160
  react_1.default.createElement(uikit_1.Button, { onClick: toggleMenuOpen, ref: buttonRef, size: 's', className: (0, exports.cnHelper)({ 'prosemirror-stop-event': true }) },
159
161
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Ellipsis, className: (0, exports.cnHelper)({ 'prosemirror-stop-event': true }) })),
@@ -2,6 +2,7 @@ import type { ExtensionNodeSpec } from '../../../../core';
2
2
  export { yfmHtmlBlockNodeName } from './const';
3
3
  export declare type YfmHtmlBlockSpecsOptions = {
4
4
  nodeView?: ExtensionNodeSpec['view'];
5
+ sanitize?: (dirtyHtml: string) => string;
5
6
  };
6
7
  export declare const YfmHtmlBlockSpecs: import("../../../../core").ExtensionWithOptions<YfmHtmlBlockSpecsOptions> & {
7
8
  readonly NodeName: "yfm_html_block";
@@ -6,9 +6,9 @@ const html_extension_1 = require("@diplodoc/html-extension");
6
6
  const const_1 = require("./const");
7
7
  var const_2 = require("./const");
8
8
  Object.defineProperty(exports, "yfmHtmlBlockNodeName", { enumerable: true, get: function () { return const_2.yfmHtmlBlockNodeName; } });
9
- const YfmHtmlBlockSpecsExtension = (builder, { nodeView }) => {
9
+ const YfmHtmlBlockSpecsExtension = (builder, { nodeView, sanitize }) => {
10
10
  builder
11
- .configureMd((md) => md.use((0, html_extension_1.transform)({ bundle: false }), {}))
11
+ .configureMd((md) => md.use((0, html_extension_1.transform)({ bundle: false, sanitize }), {}))
12
12
  .addNode(const_1.YfmHtmlBlockConsts.NodeName, () => ({
13
13
  fromMd: {
14
14
  tokenSpec: {
@@ -3,6 +3,7 @@ import { Action, ExtensionAuto } from '../../../core';
3
3
  import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
4
4
  export declare type YfmHtmlBlockOptions = {
5
5
  useConfig?: () => IHTMLIFrameElementConfig | undefined;
6
+ sanitize?: (dirtyHtml: string) => string;
6
7
  };
7
8
  export declare const YfmHtmlBlock: ExtensionAuto<YfmHtmlBlockOptions>;
8
9
  declare global {
@@ -8,6 +8,7 @@ const actions_1 = require("./actions");
8
8
  const YfmHtmlBlock = (builder, options) => {
9
9
  builder.use(YfmHtmlBlockSpecs_1.YfmHtmlBlockSpecs, {
10
10
  nodeView: YfmHtmlBlockNodeViewFactory(options),
11
+ sanitize: options.sanitize,
11
12
  });
12
13
  builder.addAction(const_1.YfmHtmlBlockAction, () => actions_1.addYfmHtmlBlock);
13
14
  };
@@ -0,0 +1 @@
1
+ export { enterKeyHandler } from '../utils/handlers';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enterKeyHandler = void 0;
4
+ var handlers_1 = require("../utils/handlers");
5
+ Object.defineProperty(exports, "enterKeyHandler", { enumerable: true, get: function () { return handlers_1.enterKeyHandler; } });
@@ -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.0' !== 'undefined' ? '13.5.0' : 'unknown';
5
+ exports.VERSION = typeof '13.5.2' !== 'undefined' ? '13.5.2' : 'unknown';
@@ -47,6 +47,6 @@ export class WYfmHtmlBlockNodeView {
47
47
  this.view.dispatch(tr);
48
48
  }
49
49
  renderYfmHtmlBlock() {
50
- return createPortal(React.createElement(YfmHtmlBlockView, { useConfig: this.options.useConfig, view: this.view, onChange: this.onChange.bind(this), node: this.node, getPos: this.getPos }), this.dom);
50
+ return createPortal(React.createElement(YfmHtmlBlockView, { getPos: this.getPos, node: this.node, onChange: this.onChange.bind(this), sanitize: this.options.sanitize, useConfig: this.options.useConfig, view: this.view }), this.dom);
51
51
  }
52
52
  }
@@ -8,11 +8,12 @@ export declare const cnHelper: import("@bem-react/classname").ClassNameFormatter
8
8
  import './YfmHtmlBlock.css';
9
9
  export declare function generateID(): string;
10
10
  export declare const YfmHtmlBlockView: React.FC<{
11
- view: EditorView;
11
+ getPos: () => number | undefined;
12
+ node: Node;
12
13
  onChange: (attrs: {
13
14
  [YfmHtmlBlockConsts.NodeAttrs.srcdoc]: string;
14
15
  }) => void;
15
- node: Node;
16
- getPos: () => number | undefined;
16
+ sanitize?: (dirtyHtml: string) => string;
17
17
  useConfig?: () => IHTMLIFrameElementConfig | undefined;
18
+ view: EditorView;
18
19
  }>;
@@ -133,7 +133,7 @@ const CodeEditMode = ({ initialText, onSave, onCancel }) => {
133
133
  React.createElement(Button, { onClick: () => onSave(text), view: 'action' },
134
134
  React.createElement("span", { className: cnHelper({ 'prosemirror-stop-event': true }) }, i18n('save'))))))));
135
135
  };
136
- export const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig }) => {
136
+ export const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig, sanitize }) => {
137
137
  const [editing, setEditing, unsetEditing, toggleEditing] = useBooleanState(Boolean(node.attrs[YfmHtmlBlockConsts.NodeAttrs.newCreated]));
138
138
  const config = useConfig === null || useConfig === void 0 ? void 0 : useConfig();
139
139
  const [menuOpen, , , toggleMenuOpen] = useBooleanState(false);
@@ -147,9 +147,11 @@ export const YfmHtmlBlockView = ({ onChange, node, getPos, view, useConfig }) =>
147
147
  unsetEditing();
148
148
  } }));
149
149
  }
150
+ const dirtyHtml = node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc];
151
+ const html = sanitize ? sanitize(dirtyHtml) : dirtyHtml;
150
152
  return (React.createElement("div", { className: b(), onDoubleClick: setEditing },
151
153
  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 }),
154
+ React.createElement(YfmHtmlBlockPreview, { html: html, "on\u0421lick": handleClick, config: config }),
153
155
  React.createElement("div", { className: b('menu') },
154
156
  React.createElement(Button, { onClick: toggleMenuOpen, ref: buttonRef, size: 's', className: cnHelper({ 'prosemirror-stop-event': true }) },
155
157
  React.createElement(Icon, { data: DotsIcon, className: cnHelper({ 'prosemirror-stop-event': true }) })),
@@ -2,6 +2,7 @@ import type { ExtensionNodeSpec } from '../../../../core';
2
2
  export { yfmHtmlBlockNodeName } from './const';
3
3
  export declare type YfmHtmlBlockSpecsOptions = {
4
4
  nodeView?: ExtensionNodeSpec['view'];
5
+ sanitize?: (dirtyHtml: string) => string;
5
6
  };
6
7
  export declare const YfmHtmlBlockSpecs: import("../../../../core").ExtensionWithOptions<YfmHtmlBlockSpecsOptions> & {
7
8
  readonly NodeName: "yfm_html_block";
@@ -2,9 +2,9 @@
2
2
  import { transform } from '@diplodoc/html-extension';
3
3
  import { YfmHtmlBlockConsts } from './const';
4
4
  export { yfmHtmlBlockNodeName } from './const';
5
- const YfmHtmlBlockSpecsExtension = (builder, { nodeView }) => {
5
+ const YfmHtmlBlockSpecsExtension = (builder, { nodeView, sanitize }) => {
6
6
  builder
7
- .configureMd((md) => md.use(transform({ bundle: false }), {}))
7
+ .configureMd((md) => md.use(transform({ bundle: false, sanitize }), {}))
8
8
  .addNode(YfmHtmlBlockConsts.NodeName, () => ({
9
9
  fromMd: {
10
10
  tokenSpec: {
@@ -3,6 +3,7 @@ import { Action, ExtensionAuto } from '../../../core';
3
3
  import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
4
4
  export declare type YfmHtmlBlockOptions = {
5
5
  useConfig?: () => IHTMLIFrameElementConfig | undefined;
6
+ sanitize?: (dirtyHtml: string) => string;
6
7
  };
7
8
  export declare const YfmHtmlBlock: ExtensionAuto<YfmHtmlBlockOptions>;
8
9
  declare global {
@@ -5,6 +5,7 @@ import { addYfmHtmlBlock } from './actions';
5
5
  export const YfmHtmlBlock = (builder, options) => {
6
6
  builder.use(YfmHtmlBlockSpecs, {
7
7
  nodeView: YfmHtmlBlockNodeViewFactory(options),
8
+ sanitize: options.sanitize,
8
9
  });
9
10
  builder.addAction(YfmHtmlBlockAction, () => addYfmHtmlBlock);
10
11
  };
@@ -0,0 +1 @@
1
+ export { enterKeyHandler } from '../utils/handlers';
@@ -0,0 +1 @@
1
+ export { enterKeyHandler } from '../utils/handlers';
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.5.0' !== 'undefined' ? '13.5.0' : 'unknown';
2
+ export const VERSION = typeof '13.5.2' !== 'undefined' ? '13.5.2' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.5.0",
3
+ "version": "13.5.2",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {