@gravity-ui/markdown-editor 13.5.1 → 13.5.3

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 }) })),
@@ -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; } });
@@ -9,10 +9,11 @@ const common_1 = require("../i18n/common");
9
9
  const lodash_1 = require("../lodash");
10
10
  const const_1 = require("./const");
11
11
  const b = (0, classname_1.cn)('toolbar-button');
12
- exports.ToolbarButtonView = react_1.default.forwardRef(function ToolbarButtonView({ icon, title, hotkey, disabledPopoverVisible = true, hintWhenDisabled, active, enabled, onClick, className, }, ref) {
12
+ exports.ToolbarButtonView = react_1.default.forwardRef(function ToolbarButtonView({ icon, title, hint, hotkey, disabledPopoverVisible = true, hintWhenDisabled, active, enabled, onClick, className, }, ref) {
13
13
  var _a;
14
14
  const disabled = !active && !enabled;
15
15
  const titleText = (0, lodash_1.isFunction)(title) ? title() : title;
16
+ const hintText = (0, lodash_1.isFunction)(hint) ? hint() : hint;
16
17
  const hideHintWhenDisabled = hintWhenDisabled === false || !disabledPopoverVisible || !disabled;
17
18
  const hintWhenDisabledText = typeof hintWhenDisabled === 'string'
18
19
  ? hintWhenDisabled
@@ -20,7 +21,7 @@ exports.ToolbarButtonView = react_1.default.forwardRef(function ToolbarButtonVie
20
21
  ? hintWhenDisabled()
21
22
  : (0, common_1.i18n)('toolbar_action_disabled');
22
23
  return (react_1.default.createElement(uikit_1.Popover, { content: hintWhenDisabledText, disabled: hideHintWhenDisabled, tooltipContentClassName: b('action-disabled-tooltip'), placement: ['bottom'] },
23
- react_1.default.createElement(uikit_1.ActionTooltip, { openDelay: const_1.ToolbarTooltipDelay.Open, closeDelay: const_1.ToolbarTooltipDelay.Close, title: titleText, hotkey: hotkey },
24
+ react_1.default.createElement(uikit_1.ActionTooltip, { openDelay: const_1.ToolbarTooltipDelay.Open, closeDelay: const_1.ToolbarTooltipDelay.Close, description: hintText, title: titleText, hotkey: hotkey },
24
25
  react_1.default.createElement(uikit_1.Button, { size: "m", ref: ref, selected: active, disabled: disabled, view: active ? 'normal' : 'flat', onClick: onClick, className: b(null, [className]), extraProps: { 'aria-label': titleText } },
25
26
  react_1.default.createElement(uikit_1.Icon, { data: icon.data, size: (_a = icon.size) !== null && _a !== void 0 ? _a : 16 })))));
26
27
  });
@@ -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.1' !== 'undefined' ? '13.5.1' : 'unknown';
5
+ exports.VERSION = typeof '13.5.3' !== 'undefined' ? '13.5.3' : '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 }) })),
@@ -0,0 +1 @@
1
+ export { enterKeyHandler } from '../utils/handlers';
@@ -0,0 +1 @@
1
+ export { enterKeyHandler } from '../utils/handlers';
@@ -6,10 +6,11 @@ import { isFunction } from '../lodash';
6
6
  import { ToolbarTooltipDelay } from './const';
7
7
  import './ToolbarButton.css';
8
8
  const b = cn('toolbar-button');
9
- export const ToolbarButtonView = React.forwardRef(function ToolbarButtonView({ icon, title, hotkey, disabledPopoverVisible = true, hintWhenDisabled, active, enabled, onClick, className, }, ref) {
9
+ export const ToolbarButtonView = React.forwardRef(function ToolbarButtonView({ icon, title, hint, hotkey, disabledPopoverVisible = true, hintWhenDisabled, active, enabled, onClick, className, }, ref) {
10
10
  var _a;
11
11
  const disabled = !active && !enabled;
12
12
  const titleText = isFunction(title) ? title() : title;
13
+ const hintText = isFunction(hint) ? hint() : hint;
13
14
  const hideHintWhenDisabled = hintWhenDisabled === false || !disabledPopoverVisible || !disabled;
14
15
  const hintWhenDisabledText = typeof hintWhenDisabled === 'string'
15
16
  ? hintWhenDisabled
@@ -17,7 +18,7 @@ export const ToolbarButtonView = React.forwardRef(function ToolbarButtonView({ i
17
18
  ? hintWhenDisabled()
18
19
  : i18n('toolbar_action_disabled');
19
20
  return (React.createElement(Popover, { content: hintWhenDisabledText, disabled: hideHintWhenDisabled, tooltipContentClassName: b('action-disabled-tooltip'), placement: ['bottom'] },
20
- React.createElement(ActionTooltip, { openDelay: ToolbarTooltipDelay.Open, closeDelay: ToolbarTooltipDelay.Close, title: titleText, hotkey: hotkey },
21
+ React.createElement(ActionTooltip, { openDelay: ToolbarTooltipDelay.Open, closeDelay: ToolbarTooltipDelay.Close, description: hintText, title: titleText, hotkey: hotkey },
21
22
  React.createElement(Button, { size: "m", ref: ref, selected: active, disabled: disabled, view: active ? 'normal' : 'flat', onClick: onClick, className: b(null, [className]), extraProps: { 'aria-label': titleText } },
22
23
  React.createElement(Icon, { data: icon.data, size: (_a = icon.size) !== null && _a !== void 0 ? _a : 16 })))));
23
24
  });
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.5.1' !== 'undefined' ? '13.5.1' : 'unknown';
2
+ export const VERSION = typeof '13.5.3' !== 'undefined' ? '13.5.3' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.5.1",
3
+ "version": "13.5.3",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {