@gravity-ui/markdown-editor 14.3.0 → 14.4.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 (75) hide show
  1. package/build/cjs/bundle/Editor.d.ts +2 -0
  2. package/build/cjs/bundle/Editor.js +8 -2
  3. package/build/cjs/bundle/MarkdownEditorView.js +1 -0
  4. package/build/cjs/bundle/SplitModeView.js +1 -0
  5. package/build/cjs/bundle/types.d.ts +22 -0
  6. package/build/cjs/bundle/useMarkdownEditor.js +6 -2
  7. package/build/cjs/bundle/wysiwyg-preset.d.ts +11 -2
  8. package/build/cjs/bundle/wysiwyg-preset.js +1 -0
  9. package/build/cjs/extensions/base/BaseInputRules/index.js +1 -1
  10. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
  11. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.js +6 -1
  12. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
  13. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.js +11 -5
  14. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +5 -1
  15. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
  16. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
  17. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
  18. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +42 -24
  19. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +9 -9
  20. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +18 -20
  21. package/build/cjs/extensions/yfm/YfmFile/index.d.ts +1 -0
  22. package/build/cjs/extensions/yfm/YfmFile/index.js +1 -0
  23. package/build/cjs/index.d.ts +1 -1
  24. package/build/cjs/index.js +2 -1
  25. package/build/cjs/markup/codemirror/create.d.ts +7 -5
  26. package/build/cjs/markup/codemirror/create.js +3 -2
  27. package/build/cjs/markup/codemirror/directive-facet.d.ts +3 -0
  28. package/build/cjs/markup/codemirror/directive-facet.js +8 -0
  29. package/build/cjs/markup/codemirror/index.d.ts +1 -0
  30. package/build/cjs/markup/codemirror/index.js +3 -1
  31. package/build/cjs/markup/codemirror/yfm.d.ts +5 -0
  32. package/build/cjs/markup/codemirror/yfm.js +26 -4
  33. package/build/cjs/markup/commands/yfm.js +10 -1
  34. package/build/cjs/utils/directive.d.ts +28 -0
  35. package/build/cjs/utils/directive.js +55 -0
  36. package/build/cjs/utils/index.d.ts +1 -0
  37. package/build/cjs/version.js +1 -1
  38. package/build/esm/bundle/Editor.d.ts +2 -0
  39. package/build/esm/bundle/Editor.js +8 -2
  40. package/build/esm/bundle/MarkdownEditorView.js +1 -0
  41. package/build/esm/bundle/SplitModeView.js +1 -0
  42. package/build/esm/bundle/types.d.ts +22 -0
  43. package/build/esm/bundle/useMarkdownEditor.js +6 -2
  44. package/build/esm/bundle/wysiwyg-preset.d.ts +11 -2
  45. package/build/esm/bundle/wysiwyg-preset.js +1 -0
  46. package/build/esm/extensions/base/BaseInputRules/index.js +2 -2
  47. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
  48. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.js +5 -0
  49. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
  50. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.js +8 -3
  51. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +6 -2
  52. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
  53. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
  54. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
  55. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +41 -24
  56. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.js +1 -1
  57. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.js +4 -5
  58. package/build/esm/extensions/yfm/YfmFile/index.d.ts +1 -0
  59. package/build/esm/extensions/yfm/YfmFile/index.js +2 -1
  60. package/build/esm/index.d.ts +1 -1
  61. package/build/esm/index.js +1 -1
  62. package/build/esm/markup/codemirror/create.d.ts +7 -5
  63. package/build/esm/markup/codemirror/create.js +3 -2
  64. package/build/esm/markup/codemirror/directive-facet.d.ts +3 -0
  65. package/build/esm/markup/codemirror/directive-facet.js +5 -0
  66. package/build/esm/markup/codemirror/index.d.ts +1 -0
  67. package/build/esm/markup/codemirror/index.js +1 -0
  68. package/build/esm/markup/codemirror/yfm.d.ts +5 -0
  69. package/build/esm/markup/codemirror/yfm.js +25 -3
  70. package/build/esm/markup/commands/yfm.js +9 -1
  71. package/build/esm/utils/directive.d.ts +28 -0
  72. package/build/esm/utils/directive.js +51 -0
  73. package/build/esm/utils/index.d.ts +1 -0
  74. package/build/esm/version.js +1 -1
  75. package/package.json +7 -3
@@ -1,26 +1,43 @@
1
1
  import { isNodeEmpty } from '../../../../utils/nodes';
2
2
  import { getPlaceholderContent } from '../../../../utils/placeholder';
3
- import { CutNode } from './const';
4
- export const serializerTokens = {
5
- [CutNode.Cut]: (state, node) => {
6
- state.renderContent(node);
7
- state.write('{% endcut %}');
8
- state.closeBlock(node);
9
- },
10
- [CutNode.CutTitle]: (state, node) => {
11
- state.write('{% cut "');
12
- if (node.nodeSize > 2)
13
- state.renderInline(node);
14
- else
15
- state.write(getPlaceholderContent(node));
16
- state.write('" %}\n');
17
- state.write('\n');
18
- state.closeBlock();
19
- },
20
- [CutNode.CutContent]: (state, node) => {
21
- if (!isNodeEmpty(node))
22
- state.renderInline(node);
23
- else
24
- state.write(getPlaceholderContent(node) + '\n\n');
25
- },
26
- };
3
+ import { CutAttr, CutNode } from './const';
4
+ export function getSerializerTokens({ directiveSyntax, }) {
5
+ const isDirectiveCut = (node) => {
6
+ return directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.shouldSerializeToDirective('yfmCut', node.attrs[CutAttr.Markup]);
7
+ };
8
+ return {
9
+ [CutNode.Cut]: (state, node) => {
10
+ state.renderContent(node);
11
+ state.write(isDirectiveCut(node) ? ':::' : '{% endcut %}');
12
+ state.closeBlock(node);
13
+ },
14
+ [CutNode.CutTitle]: (state, node, parent) => {
15
+ if (isDirectiveCut(parent)) {
16
+ state.write(':::cut [');
17
+ state.renderInline(node);
18
+ state.write(']');
19
+ state.ensureNewLine();
20
+ state.closeBlock();
21
+ return;
22
+ }
23
+ state.write('{% cut "');
24
+ if (node.nodeSize > 2)
25
+ state.renderInline(node);
26
+ else
27
+ state.write(getPlaceholderContent(node));
28
+ state.write('" %}\n');
29
+ state.write('\n');
30
+ state.closeBlock();
31
+ },
32
+ [CutNode.CutContent]: (state, node, parent) => {
33
+ if (isDirectiveCut(parent)) {
34
+ state.renderContent(node);
35
+ return;
36
+ }
37
+ if (!isNodeEmpty(node))
38
+ state.renderInline(node);
39
+ else
40
+ state.write(getPlaceholderContent(node) + '\n\n');
41
+ },
42
+ };
43
+ }
@@ -1,4 +1,4 @@
1
- import { KNOWN_ATTRS as FILE_KNOWN_ATTRS, REQUIRED_ATTRS as FILE_REQUIRED_ATTRS, FILE_TOKEN, FILE_TO_LINK_ATTRS_MAP, } from '@diplodoc/transform/lib/plugins/file/const';
1
+ import { FILE_KNOWN_ATTRS, FILE_REQUIRED_ATTRS, FILE_TOKEN, FILE_TO_LINK_ATTRS_MAP, } from '@diplodoc/file-extension';
2
2
  export const yfmFileNodeName = FILE_TOKEN;
3
3
  export const KNOWN_ATTRS = FILE_KNOWN_ATTRS.map((attrName) => {
4
4
  if (attrName in FILE_TO_LINK_ATTRS_MAP)
@@ -1,11 +1,10 @@
1
- import yfmPlugin from '@diplodoc/transform/lib/plugins/file';
2
- import { FileClassName, LinkHtmlAttr, PREFIX } from '@diplodoc/transform/lib/plugins/file/const';
1
+ import { FILE_MARKUP_PREFIX, FileClassName, FileHtmlAttr, transform as fileTransform, } from '@diplodoc/file-extension';
3
2
  import { nodeTypeFactory } from '../../../../utils/schema';
4
3
  import { KNOWN_ATTRS, LINK_TO_FILE_ATTRS_MAP, fileNodeAttrsSpec, yfmFileNodeName } from './const';
5
4
  export { yfmFileNodeName } from './const';
6
5
  export const fileType = nodeTypeFactory(yfmFileNodeName);
7
6
  export const YfmFileSpecs = (builder) => {
8
- builder.configureMd((md) => md.use(yfmPlugin));
7
+ builder.configureMd((md) => md.use(fileTransform({ bundle: false })));
9
8
  builder.addNode(yfmFileNodeName, () => ({
10
9
  spec: {
11
10
  group: 'inline',
@@ -39,7 +38,7 @@ export const YfmFileSpecs = (builder) => {
39
38
  const span = document.createElement('span');
40
39
  span.classList.add(FileClassName.Icon);
41
40
  a.appendChild(span);
42
- a.append(node.attrs[LinkHtmlAttr.Download]);
41
+ a.append(node.attrs[FileHtmlAttr.Download]);
43
42
  return a;
44
43
  },
45
44
  },
@@ -66,7 +65,7 @@ export const YfmFileSpecs = (builder) => {
66
65
  return arr;
67
66
  }, [])
68
67
  .join(' ');
69
- state.write(`${PREFIX}${attrsStr} %}`);
68
+ state.write(`${FILE_MARKUP_PREFIX}${attrsStr} %}`);
70
69
  },
71
70
  }));
72
71
  };
@@ -1,5 +1,6 @@
1
1
  import { ExtensionAuto } from '../../../core';
2
2
  import { FileUploadHandler } from '../../../utils/upload';
3
+ import '@diplodoc/file-extension/runtime/styles.css';
3
4
  import './index.css';
4
5
  export declare type YfmFileOptions = {
5
6
  fileUploadHandler?: FileUploadHandler;
@@ -1,7 +1,8 @@
1
1
  import { YfmFilePaste } from './YfmFilePaste';
2
2
  import { YfmFileSpecs } from './YfmFileSpecs';
3
3
  import { YfmFileWidget } from './YfmFileWidget';
4
- import './index.css';
4
+ import '@diplodoc/file-extension/runtime/styles.css';
5
+ import './index.css'; // eslint-disable-line import/order
5
6
  export const YfmFile = (builder, opts = {}) => {
6
7
  builder.use(YfmFileSpecs, opts);
7
8
  builder.use(YfmFileWidget, opts);
@@ -11,7 +11,7 @@ export * from './forms';
11
11
  export * from './view';
12
12
  export * from './utils';
13
13
  export * from './bundle';
14
- export { ReactRendererFacet, getImageDimensions } from './markup';
14
+ export { DirectiveSyntaxFacet, ReactRendererFacet, getImageDimensions } from './markup';
15
15
  export * as MarkupCommands from './markup/commands';
16
16
  export * as MarkupHelpers from './markup/commands/helpers';
17
17
  export { Lang, configure } from './configure';
@@ -11,7 +11,7 @@ export * from './forms';
11
11
  export * from './view';
12
12
  export * from './utils';
13
13
  export * from './bundle';
14
- export { ReactRendererFacet, getImageDimensions } from './markup';
14
+ export { DirectiveSyntaxFacet, ReactRendererFacet, getImageDimensions } from './markup';
15
15
  export * as MarkupCommands from './markup/commands';
16
16
  export * as MarkupHelpers from './markup/commands/helpers';
17
17
  export { Lang, configure } from './configure';
@@ -1,11 +1,12 @@
1
1
  import { autocompletion } from '@codemirror/autocomplete';
2
2
  import type { Extension, StateCommand } from '@codemirror/state';
3
- import { EditorView, EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
3
+ import { EditorView, type EditorViewConfig, KeyBinding, placeholder } from '@codemirror/view';
4
4
  import type { ParseInsertedUrlAsImage } from '../../bundle';
5
- import { EventMap } from '../../bundle/Editor';
6
- import { ReactRenderStorage } from '../../extensions';
7
- import { Receiver } from '../../utils';
8
- import { FileUploadHandler } from './files-upload-facet';
5
+ import type { EventMap } from '../../bundle/Editor';
6
+ import type { ReactRenderStorage } from '../../extensions';
7
+ import type { Receiver } from '../../utils';
8
+ import type { DirectiveSyntaxContext } from '../../utils/directive';
9
+ import { type FileUploadHandler } from './files-upload-facet';
9
10
  import { type YfmLangOptions } from './yfm';
10
11
  export type { YfmLangOptions };
11
12
  declare type Autocompletion = Parameters<typeof autocompletion>[0];
@@ -30,6 +31,7 @@ export declare type CreateCodemirrorParams = {
30
31
  receiver?: Receiver<EventMap>;
31
32
  yfmLangOptions?: YfmLangOptions;
32
33
  autocompletion?: Autocompletion;
34
+ directiveSyntax: DirectiveSyntaxContext;
33
35
  };
34
36
  export declare function createCodemirror(params: CreateCodemirrorParams): EditorView;
35
37
  export declare function withLogger(action: string, command: StateCommand): StateCommand;
@@ -7,6 +7,7 @@ import { DataTransferType } from '../../extensions/behavior/Clipboard/utils';
7
7
  import { logger } from '../../logger';
8
8
  import { Action as A, formatter as f } from '../../shortcuts';
9
9
  import { insertImages, insertLink, toH1, toH2, toH3, toH4, toH5, toH6, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, wrapToCodeBlock, wrapToInlineCode, wrapToYfmCut, wrapToYfmNote, } from '../commands';
10
+ import { DirectiveSyntaxFacet } from './directive-facet';
10
11
  import { FileUploadHandlerFacet } from './files-upload-facet';
11
12
  import { gravityHighlightStyle, gravityTheme } from './gravity';
12
13
  import { PairingCharactersExtension } from './pairing-chars';
@@ -14,7 +15,7 @@ import { ReactRendererFacet } from './react-facet';
14
15
  import { SearchPanelPlugin } from './search-plugin/plugin';
15
16
  import { yfmLang } from './yfm';
16
17
  export function createCodemirror(params) {
17
- const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, } = params;
18
+ const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseInsertedUrlAsImage, directiveSyntax, } = params;
18
19
  const extensions = [gravityTheme, placeholder(placeholderContent)];
19
20
  if (!disabledExtensions.history) {
20
21
  extensions.push(history());
@@ -60,7 +61,7 @@ export function createCodemirror(params) {
60
61
  ...defaultKeymap,
61
62
  ...(disabledExtensions.history ? [] : historyKeymap),
62
63
  ...keymaps,
63
- ]), autocompletion(autocompletionConfig), yfmLang(yfmLangOptions), ReactRendererFacet.of(reactRenderer), PairingCharactersExtension, EditorView.lineWrapping, EditorView.contentAttributes.of({ spellcheck: 'true' }), EditorView.domEventHandlers({
64
+ ]), autocompletion(autocompletionConfig), yfmLang(yfmLangOptions), ReactRendererFacet.of(reactRenderer), DirectiveSyntaxFacet.of(directiveSyntax), PairingCharactersExtension, EditorView.lineWrapping, EditorView.contentAttributes.of({ spellcheck: 'true' }), EditorView.domEventHandlers({
64
65
  scroll(event) {
65
66
  onScroll(event);
66
67
  },
@@ -0,0 +1,3 @@
1
+ import { Facet } from '@codemirror/state';
2
+ import type { DirectiveSyntaxContext } from '../../utils/directive';
3
+ export declare const DirectiveSyntaxFacet: Facet<DirectiveSyntaxContext, Omit<DirectiveSyntaxContext, "shouldSerializeToDirective">>;
@@ -0,0 +1,5 @@
1
+ import { Facet } from '@codemirror/state';
2
+ export const DirectiveSyntaxFacet = Facet.define({
3
+ combine: ([context]) => context,
4
+ static: true,
5
+ });
@@ -1,5 +1,6 @@
1
1
  export type { CreateCodemirrorParams } from './create';
2
2
  export { createCodemirror } from './create';
3
3
  export { ReactRendererFacet } from './react-facet';
4
+ export { DirectiveSyntaxFacet } from './directive-facet';
4
5
  export { getImageDimensions, IMG_MAX_HEIGHT } from './files-upload-plugin';
5
6
  export type { YfmLangOptions } from './yfm';
@@ -1,3 +1,4 @@
1
1
  export { createCodemirror } from './create';
2
2
  export { ReactRendererFacet } from './react-facet';
3
+ export { DirectiveSyntaxFacet } from './directive-facet';
3
4
  export { getImageDimensions, IMG_MAX_HEIGHT } from './files-upload-plugin';
@@ -15,6 +15,11 @@ export declare const yfmCutSnippet: (editor: {
15
15
  state: import("@codemirror/state").EditorState;
16
16
  dispatch: (tr: import("@codemirror/state").Transaction) => void;
17
17
  }, completion: Completion | null, from: number, to: number) => void;
18
+ export declare const yfmCutDirectiveSnippetTemplate = ":::cut [#{title}]\n#{}\n:::\n\n";
19
+ export declare const yfmCutDirectiveSnippet: (editor: {
20
+ state: import("@codemirror/state").EditorState;
21
+ dispatch: (tr: import("@codemirror/state").Transaction) => void;
22
+ }, completion: Completion | null, from: number, to: number) => void;
18
23
  export interface LanguageData {
19
24
  autocomplete: CompletionSource;
20
25
  [key: string]: any;
@@ -2,6 +2,7 @@ import { snippet } from '@codemirror/autocomplete';
2
2
  import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
3
3
  import { Tag, tags } from '@lezer/highlight';
4
4
  import { capitalize } from '../../lodash';
5
+ import { DirectiveSyntaxFacet } from './directive-facet';
5
6
  export const customTags = {
6
7
  underline: Tag.define(),
7
8
  monospace: Tag.define(),
@@ -54,8 +55,11 @@ export const yfmNoteSnippets = {
54
55
  };
55
56
  export const yfmCutSnippetTemplate = '{% cut "#{title}" %}\n\n#{}\n\n{% endcut %}\n\n';
56
57
  export const yfmCutSnippet = snippet(yfmCutSnippetTemplate);
58
+ export const yfmCutDirectiveSnippetTemplate = ':::cut [#{title}]\n#{}\n:::\n\n';
59
+ export const yfmCutDirectiveSnippet = snippet(yfmCutDirectiveSnippetTemplate);
57
60
  const mdAutocomplete = {
58
61
  autocomplete: (context) => {
62
+ const directiveContext = context.state.facet(DirectiveSyntaxFacet);
59
63
  // TODO: add more actions and re-enable
60
64
  // let word = context.matchBefore(/\/.*/);
61
65
  // if (word) {
@@ -73,13 +77,15 @@ const mdAutocomplete = {
73
77
  // label: '/yfm cut',
74
78
  // displayLabel: 'YFM Cut',
75
79
  // type: 'text',
76
- // apply: yfmCutSnippet,
80
+ // apply: directiveFacet.shouldInsertDirectiveMarkup('yfmCut')
81
+ // ? yfmCutDirectiveSnippet
82
+ // : yfmCutSnippet,
77
83
  // },
78
84
  // ],
79
85
  // };
80
86
  // }
81
87
  const word = context.matchBefore(/^.*/);
82
- if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
88
+ if (directiveContext.option !== 'only' && (word === null || word === void 0 ? void 0 : word.text.startsWith('{%'))) {
83
89
  return {
84
90
  from: word.from,
85
91
  options: [
@@ -95,11 +101,27 @@ const mdAutocomplete = {
95
101
  label: '{% cut',
96
102
  displayLabel: 'YFM Cut',
97
103
  type: 'text',
98
- apply: yfmCutSnippet,
104
+ apply: directiveContext.shouldInsertDirectiveMarkup('yfmCut')
105
+ ? yfmCutDirectiveSnippet
106
+ : yfmCutSnippet,
99
107
  },
100
108
  ],
101
109
  };
102
110
  }
111
+ if (directiveContext.option !== 'disabled' && (word === null || word === void 0 ? void 0 : word.text.startsWith(':'))) {
112
+ const options = [];
113
+ if (directiveContext.valueFor('yfmCut') !== 'disabled') {
114
+ options.push({
115
+ label: ':::cut',
116
+ displayLabel: 'YFM Cut',
117
+ type: 'text',
118
+ apply: yfmCutDirectiveSnippet,
119
+ });
120
+ }
121
+ if (options.length) {
122
+ return { from: word.from, options };
123
+ }
124
+ }
103
125
  return null;
104
126
  },
105
127
  };
@@ -1,5 +1,13 @@
1
+ import { DirectiveSyntaxFacet } from '../codemirror/directive-facet';
1
2
  import { wrapToBlock } from './helpers';
2
- export const wrapToYfmCut = wrapToBlock(({ lineBreak }) => '{% cut "title" %}' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endcut %}');
3
+ const wrapToYfmCutCurly = wrapToBlock(({ lineBreak }) => '{% cut "title" %}' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endcut %}');
4
+ const wrapToYfmCutDirective = wrapToBlock(({ lineBreak }) => ':::cut [title]' + lineBreak, ({ lineBreak }) => lineBreak + ':::');
5
+ export const wrapToYfmCut = (target) => {
6
+ const cmd = target.state.facet(DirectiveSyntaxFacet).shouldInsertDirectiveMarkup('yfmCut')
7
+ ? wrapToYfmCutDirective
8
+ : wrapToYfmCutCurly;
9
+ return cmd(target);
10
+ };
3
11
  export const wrapToYfmNote = wrapToBlock(({ lineBreak }) => '{% note info %}' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endnote %}');
4
12
  export const insertYfmTabs = wrapToBlock(({ lineBreak }) => '{% list tabs %}' + lineBreak.repeat(2) + '- Tab name' + lineBreak.repeat(2), ({ lineBreak }) => lineBreak.repeat(2) + '{% endlist %}', { before: ' ', after: '' });
5
13
  export const insertYfmTable = wrapToBlock(({ lineBreak }) => ['#|', '||'].join(lineBreak) + lineBreak, ({ lineBreak }) => lineBreak + ['|', '', '||', '||', '', '|', '', '||', '|#', ''].join(lineBreak));
@@ -0,0 +1,28 @@
1
+ export declare type DirectiveSyntaxValue = 'disabled' | 'enabled' | 'preserve' | 'overwrite' | 'only';
2
+ declare type DirectiveSyntaxMdPluginValue = 'disabled' | 'enabled' | 'only';
3
+ export declare type DirectiveSyntaxOption = DirectiveSyntaxValue | DirectiveSyntaxOptionObj;
4
+ declare type DirectiveSyntaxOptionObj = {
5
+ [K in keyof MarkdownEditor.DirectiveSyntaxAdditionalSupportedExtensions]?: DirectiveSyntaxValue;
6
+ };
7
+ declare global {
8
+ namespace MarkdownEditor {
9
+ /**
10
+ * Add more keys for you additional supported extensions
11
+ */
12
+ interface DirectiveSyntaxAdditionalSupportedExtensions {
13
+ }
14
+ }
15
+ }
16
+ export declare class DirectiveSyntaxContext {
17
+ #private;
18
+ protected set option(value: DirectiveSyntaxOption | undefined);
19
+ get option(): DirectiveSyntaxOption;
20
+ constructor(option: DirectiveSyntaxOption | undefined);
21
+ valueFor(key: keyof DirectiveSyntaxOptionObj): DirectiveSyntaxValue;
22
+ mdPluginValueFor(key: keyof DirectiveSyntaxOptionObj): DirectiveSyntaxMdPluginValue;
23
+ /** helper for wisywig serializer */
24
+ shouldSerializeToDirective(key: keyof DirectiveSyntaxOptionObj, tokenMarkup: unknown): boolean;
25
+ /** helper for markup-mode commands and actions */
26
+ shouldInsertDirectiveMarkup(key: keyof DirectiveSyntaxOptionObj): boolean;
27
+ }
28
+ export {};
@@ -0,0 +1,51 @@
1
+ var _DirectiveSyntaxContext_option;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ const DIRECTIVE_SYNTAX_DEFAULT = 'disabled';
4
+ export class DirectiveSyntaxContext {
5
+ constructor(option) {
6
+ _DirectiveSyntaxContext_option.set(this, void 0);
7
+ this.option = option;
8
+ __classPrivateFieldSet(this, _DirectiveSyntaxContext_option, this.option, "f");
9
+ }
10
+ set option(value) {
11
+ __classPrivateFieldSet(this, _DirectiveSyntaxContext_option, value !== null && value !== void 0 ? value : DIRECTIVE_SYNTAX_DEFAULT, "f");
12
+ }
13
+ get option() {
14
+ return __classPrivateFieldGet(this, _DirectiveSyntaxContext_option, "f");
15
+ }
16
+ valueFor(key) {
17
+ let value;
18
+ if (typeof this.option === 'object')
19
+ value = this.option[key];
20
+ if (typeof this.option === 'string')
21
+ value = this.option;
22
+ return value !== null && value !== void 0 ? value : DIRECTIVE_SYNTAX_DEFAULT;
23
+ }
24
+ mdPluginValueFor(key) {
25
+ const value = this.valueFor(key);
26
+ return value === 'preserve' || value === 'overwrite' ? 'enabled' : value;
27
+ }
28
+ /** helper for wisywig serializer */
29
+ shouldSerializeToDirective(key, tokenMarkup) {
30
+ const option = this.valueFor(key);
31
+ if (option === 'overwrite' || option === 'only')
32
+ return true;
33
+ if (typeof tokenMarkup === 'string') {
34
+ if (tokenMarkup.startsWith(':'))
35
+ return true;
36
+ if (tokenMarkup.startsWith('{'))
37
+ return false;
38
+ }
39
+ if (option === 'preserve')
40
+ return true;
41
+ return false;
42
+ }
43
+ /** helper for markup-mode commands and actions */
44
+ shouldInsertDirectiveMarkup(key) {
45
+ const value = this.valueFor(key);
46
+ if (value === 'disabled' || value === 'enabled')
47
+ return false;
48
+ return true;
49
+ }
50
+ }
51
+ _DirectiveSyntaxContext_option = new WeakMap();
@@ -19,3 +19,4 @@ export * from './serialize-for-clipboard';
19
19
  export * from './sync-scroll';
20
20
  export * from './upload';
21
21
  export * from './get-proportional-size';
22
+ export type { DirectiveSyntaxValue, DirectiveSyntaxOption } from './directive';
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '14.3.0' !== 'undefined' ? '14.3.0' : 'unknown';
2
+ export const VERSION = typeof '14.4.0' !== 'undefined' ? '14.4.0' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "14.3.0",
3
+ "version": "14.4.0",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -166,6 +166,7 @@
166
166
  "@codemirror/search": "~6.5.6",
167
167
  "@codemirror/state": "~6.4.1",
168
168
  "@codemirror/view": "~6.34.1",
169
+ "@diplodoc/file-extension": "^0.1.0",
169
170
  "@gravity-ui/i18n": "^1.1.0",
170
171
  "@gravity-ui/icons": "^2.10.0",
171
172
  "@lezer/highlight": "~1.2.1",
@@ -200,7 +201,7 @@
200
201
  "tslib": "^2.3.1"
201
202
  },
202
203
  "devDependencies": {
203
- "@diplodoc/cut-extension": "^0.3.1",
204
+ "@diplodoc/cut-extension": "^0.4.0",
204
205
  "@diplodoc/folding-headings-extension": "0.1.0",
205
206
  "@diplodoc/html-extension": "2.3.2",
206
207
  "@diplodoc/latex-extension": "1.0.3",
@@ -213,8 +214,10 @@
213
214
  "@gravity-ui/stylelint-config": "4.0.1",
214
215
  "@gravity-ui/tsconfig": "1.0.0",
215
216
  "@gravity-ui/uikit": "6.11.0",
217
+ "@storybook/addon-docs": "8.4.1",
216
218
  "@storybook/addon-essentials": "^8.4.1",
217
219
  "@storybook/addon-webpack5-compiler-babel": "3.0.3",
220
+ "@storybook/blocks": "8.4.1",
218
221
  "@storybook/cli": "^8.4.1",
219
222
  "@storybook/preset-scss": "1.0.3",
220
223
  "@storybook/react": "8.4.1",
@@ -256,6 +259,7 @@
256
259
  "sass": "^1.64.1",
257
260
  "sass-loader": "^13.3.2",
258
261
  "stylelint": "15.11.0",
262
+ "ts-dedent": "2.2.0",
259
263
  "ts-jest": "^27.0.7",
260
264
  "typescript": "^4.5.2"
261
265
  },
@@ -280,7 +284,7 @@
280
284
  }
281
285
  },
282
286
  "peerDependencies": {
283
- "@diplodoc/cut-extension": "^0.3.1",
287
+ "@diplodoc/cut-extension": "^0.3.1 || ^0.4.0",
284
288
  "@diplodoc/folding-headings-extension": "^0.1.0",
285
289
  "@diplodoc/html-extension": "2.3.2",
286
290
  "@diplodoc/latex-extension": "^1.0.3",