@gravity-ui/markdown-editor 14.12.5 → 14.13.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.
Files changed (24) hide show
  1. package/build/cjs/extensions/additional/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +2 -1
  2. package/build/cjs/extensions/yfm/ImgSize/ImageWidget/index.d.ts +1 -1
  3. package/build/cjs/extensions/yfm/ImgSize/ImageWidget/index.js +1 -0
  4. package/build/cjs/extensions/yfm/ImgSize/ImageWidget/widget.d.ts +1 -0
  5. package/build/cjs/extensions/yfm/ImgSize/ImageWidget/widget.js +5 -1
  6. package/build/cjs/extensions/yfm/ImgSize/index.js +1 -0
  7. package/build/cjs/extensions/yfm/YfmCut/index.css +1 -1
  8. package/build/cjs/version.js +1 -1
  9. package/build/cjs/view/hocs/withYfmHtml/index.d.ts +3 -0
  10. package/build/cjs/view/hocs/withYfmHtml/index.js +2 -2
  11. package/build/cjs/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.js +4 -1
  12. package/build/esm/extensions/additional/YfmHtmlBlock/YfmHtmlBlockNodeView/YfmHtmlBlockView.js +2 -1
  13. package/build/esm/extensions/yfm/ImgSize/ImageWidget/index.d.ts +1 -1
  14. package/build/esm/extensions/yfm/ImgSize/ImageWidget/index.js +1 -0
  15. package/build/esm/extensions/yfm/ImgSize/ImageWidget/widget.d.ts +1 -0
  16. package/build/esm/extensions/yfm/ImgSize/ImageWidget/widget.js +5 -1
  17. package/build/esm/extensions/yfm/ImgSize/index.js +1 -0
  18. package/build/esm/extensions/yfm/YfmCut/index.css +1 -1
  19. package/build/esm/version.js +1 -1
  20. package/build/esm/view/hocs/withYfmHtml/index.d.ts +3 -0
  21. package/build/esm/view/hocs/withYfmHtml/index.js +2 -2
  22. package/build/esm/view/hocs/withYfmHtml/useYfmHtmlBlockRuntime.js +4 -1
  23. package/build/styles.css +1 -1
  24. package/package.json +2 -2
@@ -185,7 +185,8 @@ const YfmHtmlBlockView = ({ onChange, node, getPos, view, options: { useConfig,
185
185
  const head = `<head>${headContent || additional}</head>`;
186
186
  const body = `<body>${(_a = node.attrs[const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc]) !== null && _a !== void 0 ? _a : ''}</body>`;
187
187
  const html = `<!DOCTYPE html><html>${head}${body}</html>`;
188
- const resultHtml = sanitize ? sanitize(html) : html;
188
+ const sanitizeFunction = typeof sanitize === 'function' ? sanitize : sanitize === null || sanitize === void 0 ? void 0 : sanitize.body;
189
+ const resultHtml = sanitizeFunction ? sanitizeFunction(html) : html;
189
190
  return (react_1.default.createElement("div", { className: b(), onDoubleClick: setEditing },
190
191
  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')),
191
192
  react_1.default.createElement(YfmHtmlBlockPreview, { html: resultHtml, "on\u0421lick": handleClick, config: config }),
@@ -2,7 +2,7 @@ import type { Action, ExtensionAuto } from '../../../../core';
2
2
  import { FileUploadHandler } from '../../../../utils/upload';
3
3
  import type { ImageWidgetDescriptorOpts } from './widget';
4
4
  declare const addImageWidgetAction = "addImageWidget";
5
- export declare type ImageWidgetOptions = Pick<ImageWidgetDescriptorOpts, 'needToSetDimensionsForUploadedImages'> & {
5
+ export declare type ImageWidgetOptions = Pick<ImageWidgetDescriptorOpts, 'needToSetDimensionsForUploadedImages' | 'enableNewImageSizeCalculation'> & {
6
6
  imageUploadHandler?: FileUploadHandler;
7
7
  };
8
8
  export declare const ImageWidget: ExtensionAuto<ImageWidgetOptions>;
@@ -7,6 +7,7 @@ const ImageWidget = (builder, opts) => {
7
7
  builder.addAction(addImageWidgetAction, (deps) => (0, actions_1.addImageWidget)(deps, {
8
8
  uploadImages: opts.imageUploadHandler,
9
9
  needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,
10
+ enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation,
10
11
  }));
11
12
  };
12
13
  exports.ImageWidget = ImageWidget;
@@ -6,4 +6,5 @@ export declare const removeWidget: (tr: Transaction, id: string) => Transaction;
6
6
  export declare type ImageWidgetDescriptorOpts = {
7
7
  needToSetDimensionsForUploadedImages: boolean;
8
8
  uploadImages?: FileUploadHandler;
9
+ enableNewImageSizeCalculation?: boolean;
9
10
  };
@@ -22,6 +22,7 @@ class ImageWidgetDescriptor extends WidgetDecoration_1.ReactWidgetDescriptor {
22
22
  this.deps = deps;
23
23
  this.uploadImages = opts.uploadImages;
24
24
  this.needToSetDimensionsForUploadedImages = opts.needToSetDimensionsForUploadedImages;
25
+ this.enableNewImageSizeCalculation = opts.enableNewImageSizeCalculation;
25
26
  }
26
27
  getWidgetHandler(view, getPos) {
27
28
  if (!this.widgetHandler) {
@@ -31,6 +32,7 @@ class ImageWidgetDescriptor extends WidgetDecoration_1.ReactWidgetDescriptor {
31
32
  decoId: this.id,
32
33
  uploadImages: this.uploadImages,
33
34
  needToSetDimensionsForUploadedImages: this.needToSetDimensionsForUploadedImages,
35
+ enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
34
36
  }, this.deps);
35
37
  }
36
38
  return this.widgetHandler;
@@ -49,7 +51,7 @@ class ImageWidgetDescriptor extends WidgetDecoration_1.ReactWidgetDescriptor {
49
51
  }
50
52
  }
51
53
  class ImageWidgetHandler {
52
- constructor({ decoId, view, getPos, uploadImages, needToSetDimensionsForUploadedImages, }, deps) {
54
+ constructor({ decoId, view, getPos, uploadImages, needToSetDimensionsForUploadedImages, enableNewImageSizeCalculation, }, deps) {
53
55
  this.cancelled = false;
54
56
  this.onCancel = () => {
55
57
  this.cancelled = true;
@@ -79,6 +81,7 @@ class ImageWidgetHandler {
79
81
  const { view } = this;
80
82
  new upload_1.ImagesUploadProcess(view, files, this.uploadImages, this.getPos(), {
81
83
  needDimensions: this.needToSetDimensionsForUploadedImages,
84
+ enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
82
85
  }).run();
83
86
  view.dispatch((0, exports.removeWidget)(view.state.tr, this.decoId));
84
87
  view.focus();
@@ -89,6 +92,7 @@ class ImageWidgetHandler {
89
92
  this.uploadImages = uploadImages;
90
93
  this.normalizeUrl = (0, markdown_1.normalizeUrlFactory)(deps);
91
94
  this.needToSetDimensionsForUploadedImages = needToSetDimensionsForUploadedImages;
95
+ this.enableNewImageSizeCalculation = enableNewImageSizeCalculation;
92
96
  }
93
97
  destruct() {
94
98
  this.cancelled = true;
@@ -12,6 +12,7 @@ const ImgSize = (builder, opts) => {
12
12
  builder.use(ImageWidget_1.ImageWidget, {
13
13
  imageUploadHandler: opts.imageUploadHandler,
14
14
  needToSetDimensionsForUploadedImages: Boolean(opts.needToSetDimensionsForUploadedImages),
15
+ enableNewImageSizeCalculation: Boolean(opts.enableNewImageSizeCalculation),
15
16
  });
16
17
  if (opts.imageUploadHandler || opts.parseInsertedUrlAsImage) {
17
18
  builder.use(ImagePaste_1.ImagePaste, {
@@ -11,6 +11,6 @@
11
11
  .ProseMirror.yfm .yfm-cut .yfm-cut-title:focus {
12
12
  outline: 0;
13
13
  }
14
- .ProseMirror.yfm .yfm-cut.open .yfm-cut-title:before {
14
+ .ProseMirror.yfm .yfm-cut.open > .yfm-cut-title:before {
15
15
  transform: translateY(-50%);
16
16
  }
@@ -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 '14.12.5' !== 'undefined' ? '14.12.5' : 'unknown';
5
+ exports.VERSION = typeof '14.13.0' !== 'undefined' ? '14.13.0' : 'unknown';
@@ -1,4 +1,5 @@
1
1
  import React, { ComponentType, RefAttributes } from 'react';
2
+ import type { HTMLRuntimeConfig } from '@diplodoc/html-extension';
2
3
  import { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
3
4
  import type { PluginRuntime, TransformMeta } from '../withMermaid/types';
4
5
  export declare type WithYfmHtmlBlockOptions = {
@@ -7,6 +8,8 @@ export declare type WithYfmHtmlBlockOptions = {
7
8
  export declare type WithYfmHtmlBlockProps = {
8
9
  meta: TransformMeta;
9
10
  yfmHtmlBlockConfig?: IHTMLIFrameElementConfig;
11
+ /** Works only with html-extension dep version 2.7.1 and higher */
12
+ htmlRuntimeConfig?: HTMLRuntimeConfig;
10
13
  };
11
14
  export declare function withYfmHtmlBlock(opts: WithYfmHtmlBlockOptions): <T extends {
12
15
  html: string;
@@ -7,8 +7,8 @@ const react_2 = require("@diplodoc/html-extension/react");
7
7
  const useYfmHtmlBlockRuntime_1 = require("./useYfmHtmlBlockRuntime");
8
8
  function withYfmHtmlBlock(opts) {
9
9
  return (Component) => (0, react_1.forwardRef)(function WithYfmHtml(props, ref) {
10
- const { meta, html, yfmHtmlBlockConfig } = props;
11
- (0, useYfmHtmlBlockRuntime_1.useYfmHtmlBlockRuntime)(meta, opts.runtime);
10
+ const { meta, html, yfmHtmlBlockConfig, htmlRuntimeConfig } = props;
11
+ (0, useYfmHtmlBlockRuntime_1.useYfmHtmlBlockRuntime)(meta, opts.runtime, htmlRuntimeConfig);
12
12
  const yfmHtmlBlock = (0, react_2.useDiplodocEmbeddedContentController)();
13
13
  (0, react_1.useEffect)(() => {
14
14
  if (yfmHtmlBlock) {
@@ -24,10 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.useYfmHtmlBlockRuntime = void 0;
27
+ const utils_1 = require("@diplodoc/html-extension/utils");
27
28
  /** @internal */
28
- function useYfmHtmlBlockRuntime(meta, runtime = '_assets/html-extension.js') {
29
+ function useYfmHtmlBlockRuntime(meta, runtime = '_assets/html-extension.js', htmlRuntimeConfig = {}) {
29
30
  var _a;
30
31
  if ((_a = meta === null || meta === void 0 ? void 0 : meta.script) === null || _a === void 0 ? void 0 : _a.includes(runtime)) {
32
+ // MAJOR: update html-extension peer on ^2.7.1 and remove optional chain
33
+ utils_1.setupRuntimeConfig === null || utils_1.setupRuntimeConfig === void 0 ? void 0 : (0, utils_1.setupRuntimeConfig)(htmlRuntimeConfig);
31
34
  Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "yfm-html-runtime" */ '@diplodoc/html-extension/runtime')));
32
35
  }
33
36
  }
@@ -181,7 +181,8 @@ export const YfmHtmlBlockView = ({ onChange, node, getPos, view, options: { useC
181
181
  const head = `<head>${headContent || additional}</head>`;
182
182
  const body = `<body>${(_a = node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc]) !== null && _a !== void 0 ? _a : ''}</body>`;
183
183
  const html = `<!DOCTYPE html><html>${head}${body}</html>`;
184
- const resultHtml = sanitize ? sanitize(html) : html;
184
+ const sanitizeFunction = typeof sanitize === 'function' ? sanitize : sanitize === null || sanitize === void 0 ? void 0 : sanitize.body;
185
+ const resultHtml = sanitizeFunction ? sanitizeFunction(html) : html;
185
186
  return (React.createElement("div", { className: b(), onDoubleClick: setEditing },
186
187
  React.createElement(Label, { className: b('label'), icon: React.createElement(Icon, { size: 16, data: Eye }) }, i18n('preview')),
187
188
  React.createElement(YfmHtmlBlockPreview, { html: resultHtml, "on\u0421lick": handleClick, config: config }),
@@ -2,7 +2,7 @@ import type { Action, ExtensionAuto } from '../../../../core';
2
2
  import { FileUploadHandler } from '../../../../utils/upload';
3
3
  import type { ImageWidgetDescriptorOpts } from './widget';
4
4
  declare const addImageWidgetAction = "addImageWidget";
5
- export declare type ImageWidgetOptions = Pick<ImageWidgetDescriptorOpts, 'needToSetDimensionsForUploadedImages'> & {
5
+ export declare type ImageWidgetOptions = Pick<ImageWidgetDescriptorOpts, 'needToSetDimensionsForUploadedImages' | 'enableNewImageSizeCalculation'> & {
6
6
  imageUploadHandler?: FileUploadHandler;
7
7
  };
8
8
  export declare const ImageWidget: ExtensionAuto<ImageWidgetOptions>;
@@ -4,5 +4,6 @@ export const ImageWidget = (builder, opts) => {
4
4
  builder.addAction(addImageWidgetAction, (deps) => addImageWidget(deps, {
5
5
  uploadImages: opts.imageUploadHandler,
6
6
  needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,
7
+ enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation,
7
8
  }));
8
9
  };
@@ -6,4 +6,5 @@ export declare const removeWidget: (tr: Transaction, id: string) => Transaction;
6
6
  export declare type ImageWidgetDescriptorOpts = {
7
7
  needToSetDimensionsForUploadedImages: boolean;
8
8
  uploadImages?: FileUploadHandler;
9
+ enableNewImageSizeCalculation?: boolean;
9
10
  };
@@ -17,6 +17,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
17
17
  this.deps = deps;
18
18
  this.uploadImages = opts.uploadImages;
19
19
  this.needToSetDimensionsForUploadedImages = opts.needToSetDimensionsForUploadedImages;
20
+ this.enableNewImageSizeCalculation = opts.enableNewImageSizeCalculation;
20
21
  }
21
22
  getWidgetHandler(view, getPos) {
22
23
  if (!this.widgetHandler) {
@@ -26,6 +27,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
26
27
  decoId: this.id,
27
28
  uploadImages: this.uploadImages,
28
29
  needToSetDimensionsForUploadedImages: this.needToSetDimensionsForUploadedImages,
30
+ enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
29
31
  }, this.deps);
30
32
  }
31
33
  return this.widgetHandler;
@@ -44,7 +46,7 @@ class ImageWidgetDescriptor extends ReactWidgetDescriptor {
44
46
  }
45
47
  }
46
48
  class ImageWidgetHandler {
47
- constructor({ decoId, view, getPos, uploadImages, needToSetDimensionsForUploadedImages, }, deps) {
49
+ constructor({ decoId, view, getPos, uploadImages, needToSetDimensionsForUploadedImages, enableNewImageSizeCalculation, }, deps) {
48
50
  this.cancelled = false;
49
51
  this.onCancel = () => {
50
52
  this.cancelled = true;
@@ -74,6 +76,7 @@ class ImageWidgetHandler {
74
76
  const { view } = this;
75
77
  new ImagesUploadProcess(view, files, this.uploadImages, this.getPos(), {
76
78
  needDimensions: this.needToSetDimensionsForUploadedImages,
79
+ enableNewImageSizeCalculation: this.enableNewImageSizeCalculation,
77
80
  }).run();
78
81
  view.dispatch(removeWidget(view.state.tr, this.decoId));
79
82
  view.focus();
@@ -84,6 +87,7 @@ class ImageWidgetHandler {
84
87
  this.uploadImages = uploadImages;
85
88
  this.normalizeUrl = normalizeUrlFactory(deps);
86
89
  this.needToSetDimensionsForUploadedImages = needToSetDimensionsForUploadedImages;
90
+ this.enableNewImageSizeCalculation = enableNewImageSizeCalculation;
87
91
  }
88
92
  destruct() {
89
93
  this.cancelled = true;
@@ -9,6 +9,7 @@ export const ImgSize = (builder, opts) => {
9
9
  builder.use(ImageWidget, {
10
10
  imageUploadHandler: opts.imageUploadHandler,
11
11
  needToSetDimensionsForUploadedImages: Boolean(opts.needToSetDimensionsForUploadedImages),
12
+ enableNewImageSizeCalculation: Boolean(opts.enableNewImageSizeCalculation),
12
13
  });
13
14
  if (opts.imageUploadHandler || opts.parseInsertedUrlAsImage) {
14
15
  builder.use(ImagePaste, {
@@ -11,6 +11,6 @@
11
11
  .ProseMirror.yfm .yfm-cut .yfm-cut-title:focus {
12
12
  outline: 0;
13
13
  }
14
- .ProseMirror.yfm .yfm-cut.open .yfm-cut-title:before {
14
+ .ProseMirror.yfm .yfm-cut.open > .yfm-cut-title:before {
15
15
  transform: translateY(-50%);
16
16
  }
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '14.12.5' !== 'undefined' ? '14.12.5' : 'unknown';
2
+ export const VERSION = typeof '14.13.0' !== 'undefined' ? '14.13.0' : 'unknown';
@@ -1,4 +1,5 @@
1
1
  import React, { ComponentType, RefAttributes } from 'react';
2
+ import type { HTMLRuntimeConfig } from '@diplodoc/html-extension';
2
3
  import { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
3
4
  import type { PluginRuntime, TransformMeta } from '../withMermaid/types';
4
5
  export declare type WithYfmHtmlBlockOptions = {
@@ -7,6 +8,8 @@ export declare type WithYfmHtmlBlockOptions = {
7
8
  export declare type WithYfmHtmlBlockProps = {
8
9
  meta: TransformMeta;
9
10
  yfmHtmlBlockConfig?: IHTMLIFrameElementConfig;
11
+ /** Works only with html-extension dep version 2.7.1 and higher */
12
+ htmlRuntimeConfig?: HTMLRuntimeConfig;
10
13
  };
11
14
  export declare function withYfmHtmlBlock(opts: WithYfmHtmlBlockOptions): <T extends {
12
15
  html: string;
@@ -3,8 +3,8 @@ import { useDiplodocEmbeddedContentController } from '@diplodoc/html-extension/r
3
3
  import { useYfmHtmlBlockRuntime } from './useYfmHtmlBlockRuntime';
4
4
  export function withYfmHtmlBlock(opts) {
5
5
  return (Component) => forwardRef(function WithYfmHtml(props, ref) {
6
- const { meta, html, yfmHtmlBlockConfig } = props;
7
- useYfmHtmlBlockRuntime(meta, opts.runtime);
6
+ const { meta, html, yfmHtmlBlockConfig, htmlRuntimeConfig } = props;
7
+ useYfmHtmlBlockRuntime(meta, opts.runtime, htmlRuntimeConfig);
8
8
  const yfmHtmlBlock = useDiplodocEmbeddedContentController();
9
9
  useEffect(() => {
10
10
  if (yfmHtmlBlock) {
@@ -1,7 +1,10 @@
1
+ import { setupRuntimeConfig } from '@diplodoc/html-extension/utils';
1
2
  /** @internal */
2
- export function useYfmHtmlBlockRuntime(meta, runtime = '_assets/html-extension.js') {
3
+ export function useYfmHtmlBlockRuntime(meta, runtime = '_assets/html-extension.js', htmlRuntimeConfig = {}) {
3
4
  var _a;
4
5
  if ((_a = meta === null || meta === void 0 ? void 0 : meta.script) === null || _a === void 0 ? void 0 : _a.includes(runtime)) {
6
+ // MAJOR: update html-extension peer on ^2.7.1 and remove optional chain
7
+ setupRuntimeConfig === null || setupRuntimeConfig === void 0 ? void 0 : setupRuntimeConfig(htmlRuntimeConfig);
5
8
  import(/* webpackChunkName: "yfm-html-runtime" */ '@diplodoc/html-extension/runtime');
6
9
  }
7
10
  }
package/build/styles.css CHANGED
@@ -1158,7 +1158,7 @@ body :has(.g-md-resizable_resizing) {
1158
1158
  .ProseMirror.yfm .yfm-cut .yfm-cut-title:focus {
1159
1159
  outline: 0;
1160
1160
  }
1161
- .ProseMirror.yfm .yfm-cut.open .yfm-cut-title:before {
1161
+ .ProseMirror.yfm .yfm-cut.open > .yfm-cut-title:before {
1162
1162
  transform: translateY(-50%);
1163
1163
  }
1164
1164
  .yfm-editor .yfm-file {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "14.12.5",
3
+ "version": "14.13.0",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -206,7 +206,7 @@
206
206
  "devDependencies": {
207
207
  "@diplodoc/cut-extension": "^0.6.1",
208
208
  "@diplodoc/folding-headings-extension": "0.1.0",
209
- "@diplodoc/html-extension": "^2.5.0",
209
+ "@diplodoc/html-extension": "2.7.1",
210
210
  "@diplodoc/latex-extension": "1.0.3",
211
211
  "@diplodoc/mermaid-extension": "1.2.1",
212
212
  "@diplodoc/tabs-extension": "^3.5.1",