@gravity-ui/markdown-editor 13.21.3 → 13.22.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/README.md CHANGED
@@ -52,13 +52,13 @@ function Editor({onSubmit}) {
52
52
  }
53
53
  ```
54
54
  Read more:
55
- - [How to connect the editor in the Create React App](docs/how-to-add-editor-with-create-react-app.md)
56
- - [How to add preview for markup mode](docs/how-to-add-preview.md)
57
- - [How to add HTML extension](docs/how-to-connect-html-extension.md)
58
- - [How to add Latex extension](docs/how-to-connect-latex-extension.md)
59
- - [How to add Mermaid extension](docs/how-to-connect-mermaid-extension.md)
60
- - [How to write extension](docs/how-to-create-extension.md)
61
- - [How to add GPT extension](docs/how-to-connect-gpt-extensions.md)
55
+ - [How to connect the editor in the Create React App](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-add-editor-with-create-react-app.md)
56
+ - [How to add preview for markup mode](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-add-preview.md)
57
+ - [How to add HTML extension](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-connect-html-extension.md)
58
+ - [How to add Latex extension](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-connect-latex-extension.md)
59
+ - [How to add Mermaid extension](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-connect-mermaid-extension.md)
60
+ - [How to write extension](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-create-extension.md)
61
+ - [How to add GPT extension](https://github.com/gravity-ui/markdown-editor/blob/main/docs/how-to-connect-gpt-extensions.md)
62
62
 
63
63
 
64
64
  ### i18n
@@ -267,7 +267,7 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
267
267
  let cmLine = line + 1; // lines in codemirror is 1-based
268
268
  cmLine = Math.max(cmLine, 1);
269
269
  cmLine = Math.min(cmLine, view.state.doc.lines);
270
- const yMargin = getTopOffset();
270
+ const yMargin = getTopOffset(view.dom);
271
271
  const anchor = view.state.doc.line(cmLine).from;
272
272
  view.dispatch({
273
273
  scrollIntoView: true,
@@ -278,24 +278,16 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
278
278
  });
279
279
  break;
280
280
  // eslint-disable-next-line no-inner-declarations
281
- function getTopOffset() {
282
- const TOOLBAR_HEIGHT = 36; //px
283
- const TOOLBAR_BOTTOM_OFFSET = 8; // px
284
- const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
285
- const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
286
- const topOffsetValue = window
287
- .getComputedStyle(view.dom)
288
- .getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
289
- const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
290
- return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
291
- }
292
281
  }
293
282
  case 'wysiwyg': {
294
- const node = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
295
- if (node) {
296
- const position = this._wysiwygView.posAtDOM(node, 0);
283
+ const elem = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
284
+ if (elem) {
285
+ const elemTop = elem.getBoundingClientRect().top;
286
+ const topOffset = getTopOffset(this.wysiwygEditor.dom);
287
+ window.scrollTo({ top: elemTop + window.scrollY - topOffset });
288
+ const position = this._wysiwygView.posAtDOM(elem, 0);
297
289
  const { tr } = this._wysiwygView.state;
298
- this._wysiwygView.dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, position)).scrollIntoView());
290
+ this._wysiwygView.dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, position)));
299
291
  }
300
292
  break;
301
293
  }
@@ -311,6 +303,15 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
311
303
  }
312
304
  exports.EditorImpl = EditorImpl;
313
305
  _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();
306
+ function getTopOffset(elem) {
307
+ const TOOLBAR_HEIGHT = 36; //px
308
+ const TOOLBAR_BOTTOM_OFFSET = 8; // px
309
+ const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
310
+ const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
311
+ const topOffsetValue = window.getComputedStyle(elem).getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
312
+ const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
313
+ return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
314
+ }
314
315
  function calculateCSSNumberValue(cssValue) {
315
316
  const tmp = document.createElement('div');
316
317
  tmp.style.position = 'absolute';
@@ -1,4 +1,4 @@
1
- import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  import type { ExtensionNodeSpec } from '../../../../core';
3
3
  export { yfmHtmlBlockNodeName } from './const';
4
4
  export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
@@ -1,4 +1,4 @@
1
- import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  import type { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
3
3
  import { Action, ExtensionAuto } from '../../../core';
4
4
  import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
@@ -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.21.3' !== 'undefined' ? '13.21.3' : 'unknown';
5
+ exports.VERSION = typeof '13.22.0' !== 'undefined' ? '13.22.0' : 'unknown';
@@ -1,3 +1,3 @@
1
- import type { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import type { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  export type { TransformMeta } from '../../types';
3
3
  export declare type PluginRuntime = PluginOptions['runtimeJsPath'];
@@ -264,7 +264,7 @@ export class EditorImpl extends SafeEventEmitter {
264
264
  let cmLine = line + 1; // lines in codemirror is 1-based
265
265
  cmLine = Math.max(cmLine, 1);
266
266
  cmLine = Math.min(cmLine, view.state.doc.lines);
267
- const yMargin = getTopOffset();
267
+ const yMargin = getTopOffset(view.dom);
268
268
  const anchor = view.state.doc.line(cmLine).from;
269
269
  view.dispatch({
270
270
  scrollIntoView: true,
@@ -275,24 +275,16 @@ export class EditorImpl extends SafeEventEmitter {
275
275
  });
276
276
  break;
277
277
  // eslint-disable-next-line no-inner-declarations
278
- function getTopOffset() {
279
- const TOOLBAR_HEIGHT = 36; //px
280
- const TOOLBAR_BOTTOM_OFFSET = 8; // px
281
- const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
282
- const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
283
- const topOffsetValue = window
284
- .getComputedStyle(view.dom)
285
- .getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
286
- const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
287
- return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
288
- }
289
278
  }
290
279
  case 'wysiwyg': {
291
- const node = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
292
- if (node) {
293
- const position = this._wysiwygView.posAtDOM(node, 0);
280
+ const elem = this.wysiwygEditor.dom.querySelector(`[data-line="${line}"]`);
281
+ if (elem) {
282
+ const elemTop = elem.getBoundingClientRect().top;
283
+ const topOffset = getTopOffset(this.wysiwygEditor.dom);
284
+ window.scrollTo({ top: elemTop + window.scrollY - topOffset });
285
+ const position = this._wysiwygView.posAtDOM(elem, 0);
294
286
  const { tr } = this._wysiwygView.state;
295
- this._wysiwygView.dispatch(tr.setSelection(TextSelection.create(tr.doc, position)).scrollIntoView());
287
+ this._wysiwygView.dispatch(tr.setSelection(TextSelection.create(tr.doc, position)));
296
288
  }
297
289
  break;
298
290
  }
@@ -307,6 +299,15 @@ export class EditorImpl extends SafeEventEmitter {
307
299
  }
308
300
  }
309
301
  _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();
302
+ function getTopOffset(elem) {
303
+ const TOOLBAR_HEIGHT = 36; //px
304
+ const TOOLBAR_BOTTOM_OFFSET = 8; // px
305
+ const TOOLBAR_TOP_ADDITIONAL_OFFSET = 8; // px
306
+ const TOOLBAR_TOP_OFFSET_VAR = '--g-md-toolbar-sticky-offset';
307
+ const topOffsetValue = window.getComputedStyle(elem).getPropertyValue(TOOLBAR_TOP_OFFSET_VAR);
308
+ const toolbarTopOffset = calculateCSSNumberValue(topOffsetValue) + TOOLBAR_TOP_ADDITIONAL_OFFSET;
309
+ return toolbarTopOffset + TOOLBAR_HEIGHT + TOOLBAR_BOTTOM_OFFSET;
310
+ }
310
311
  function calculateCSSNumberValue(cssValue) {
311
312
  const tmp = document.createElement('div');
312
313
  tmp.style.position = 'absolute';
@@ -1,4 +1,4 @@
1
- import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  import type { ExtensionNodeSpec } from '../../../../core';
3
3
  export { yfmHtmlBlockNodeName } from './const';
4
4
  export interface YfmHtmlBlockSpecsOptions extends Omit<PluginOptions, 'runtimeJsPath' | 'containerClasses' | 'bundle' | 'embeddingMode'> {
@@ -1,4 +1,4 @@
1
- import { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  import type { IHTMLIFrameElementConfig } from '@diplodoc/html-extension/runtime';
3
3
  import { Action, ExtensionAuto } from '../../../core';
4
4
  import { YfmHtmlBlockAction } from './YfmHtmlBlockSpecs/const';
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.21.3' !== 'undefined' ? '13.21.3' : 'unknown';
2
+ export const VERSION = typeof '13.22.0' !== 'undefined' ? '13.22.0' : 'unknown';
@@ -1,3 +1,3 @@
1
- import type { PluginOptions } from '@diplodoc/html-extension/plugin/transform';
1
+ import type { PluginOptions } from '@diplodoc/html-extension/plugin';
2
2
  export type { TransformMeta } from '../../types';
3
3
  export declare type PluginRuntime = PluginOptions['runtimeJsPath'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.21.3",
3
+ "version": "13.22.0",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -201,7 +201,7 @@
201
201
  },
202
202
  "devDependencies": {
203
203
  "@diplodoc/folding-headings-extension": "0.1.0",
204
- "@diplodoc/html-extension": "2.1.0",
204
+ "@diplodoc/html-extension": "2.3.2",
205
205
  "@diplodoc/latex-extension": "1.0.3",
206
206
  "@diplodoc/mermaid-extension": "1.2.1",
207
207
  "@diplodoc/transform": "4.22.0",
@@ -276,7 +276,7 @@
276
276
  },
277
277
  "peerDependencies": {
278
278
  "@diplodoc/folding-headings-extension": "^0.1.0",
279
- "@diplodoc/html-extension": "2.1.0",
279
+ "@diplodoc/html-extension": "2.3.2",
280
280
  "@diplodoc/latex-extension": "^1.0.3",
281
281
  "@diplodoc/mermaid-extension": "^1.0.0",
282
282
  "@diplodoc/transform": ">=4.5.0 <4.19.0",