@gravity-ui/markdown-editor 14.3.1 → 14.5.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 (112) hide show
  1. package/build/cjs/bundle/Editor.d.ts +2 -0
  2. package/build/cjs/bundle/Editor.js +9 -2
  3. package/build/cjs/bundle/MarkdownEditorView.js +1 -0
  4. package/build/cjs/bundle/SplitModeView.js +1 -0
  5. package/build/cjs/bundle/config/markup.d.ts +41 -17
  6. package/build/cjs/bundle/config/markup.js +413 -308
  7. package/build/cjs/bundle/config/wysiwyg.d.ts +29 -18
  8. package/build/cjs/bundle/config/wysiwyg.js +526 -310
  9. package/build/cjs/bundle/sticky/sticky.css +1 -1
  10. package/build/cjs/bundle/types.d.ts +24 -0
  11. package/build/cjs/bundle/useMarkdownEditor.js +6 -2
  12. package/build/cjs/bundle/wysiwyg-preset.d.ts +11 -2
  13. package/build/cjs/bundle/wysiwyg-preset.js +1 -0
  14. package/build/cjs/extensions/behavior/Clipboard/utils.d.ts +1 -0
  15. package/build/cjs/extensions/behavior/Clipboard/utils.js +1 -0
  16. package/build/cjs/extensions/markdown/CodeBlock/handle-paste.js +5 -17
  17. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
  18. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/const.js +6 -1
  19. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
  20. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/index.js +11 -5
  21. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +5 -1
  22. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
  23. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
  24. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
  25. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +42 -24
  26. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
  27. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/const.js +30 -11
  28. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
  29. package/build/cjs/extensions/yfm/YfmFile/YfmFileSpecs/index.js +46 -24
  30. package/build/cjs/extensions/yfm/YfmFile/index.d.ts +1 -0
  31. package/build/cjs/extensions/yfm/YfmFile/index.js +1 -0
  32. package/build/cjs/index.d.ts +1 -1
  33. package/build/cjs/index.js +2 -1
  34. package/build/cjs/markup/codemirror/create.d.ts +8 -5
  35. package/build/cjs/markup/codemirror/create.js +43 -5
  36. package/build/cjs/markup/codemirror/directive-facet.d.ts +3 -0
  37. package/build/cjs/markup/codemirror/directive-facet.js +8 -0
  38. package/build/cjs/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
  39. package/build/cjs/markup/codemirror/html-to-markdown/converters.js +214 -0
  40. package/build/cjs/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
  41. package/build/cjs/markup/codemirror/html-to-markdown/handlers.js +233 -0
  42. package/build/cjs/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
  43. package/build/cjs/markup/codemirror/html-to-markdown/helpers.js +21 -0
  44. package/build/cjs/markup/codemirror/index.d.ts +1 -0
  45. package/build/cjs/markup/codemirror/index.js +3 -1
  46. package/build/cjs/markup/codemirror/yfm.d.ts +5 -0
  47. package/build/cjs/markup/codemirror/yfm.js +26 -4
  48. package/build/cjs/markup/commands/inline.js +18 -8
  49. package/build/cjs/markup/commands/yfm.js +10 -1
  50. package/build/cjs/utils/clipboard.d.ts +14 -0
  51. package/build/cjs/utils/clipboard.js +36 -1
  52. package/build/cjs/utils/directive.d.ts +28 -0
  53. package/build/cjs/utils/directive.js +55 -0
  54. package/build/cjs/utils/index.d.ts +1 -0
  55. package/build/cjs/version.js +1 -1
  56. package/build/esm/bundle/Editor.d.ts +2 -0
  57. package/build/esm/bundle/Editor.js +9 -2
  58. package/build/esm/bundle/MarkdownEditorView.js +1 -0
  59. package/build/esm/bundle/SplitModeView.js +1 -0
  60. package/build/esm/bundle/config/markup.d.ts +41 -17
  61. package/build/esm/bundle/config/markup.js +411 -307
  62. package/build/esm/bundle/config/wysiwyg.d.ts +29 -18
  63. package/build/esm/bundle/config/wysiwyg.js +499 -284
  64. package/build/esm/bundle/sticky/sticky.css +1 -1
  65. package/build/esm/bundle/types.d.ts +24 -0
  66. package/build/esm/bundle/useMarkdownEditor.js +6 -2
  67. package/build/esm/bundle/wysiwyg-preset.d.ts +11 -2
  68. package/build/esm/bundle/wysiwyg-preset.js +1 -0
  69. package/build/esm/extensions/behavior/Clipboard/utils.d.ts +1 -0
  70. package/build/esm/extensions/behavior/Clipboard/utils.js +1 -0
  71. package/build/esm/extensions/markdown/CodeBlock/handle-paste.js +2 -14
  72. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.d.ts +4 -0
  73. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/const.js +5 -0
  74. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.d.ts +8 -1
  75. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/index.js +8 -3
  76. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/parser.js +6 -2
  77. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.d.ts +1 -1
  78. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +8 -3
  79. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.d.ts +3 -1
  80. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/serializer.js +41 -24
  81. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.d.ts +12 -0
  82. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/const.js +21 -2
  83. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.d.ts +8 -1
  84. package/build/esm/extensions/yfm/YfmFile/YfmFileSpecs/index.js +32 -10
  85. package/build/esm/extensions/yfm/YfmFile/index.d.ts +1 -0
  86. package/build/esm/extensions/yfm/YfmFile/index.js +2 -1
  87. package/build/esm/index.d.ts +1 -1
  88. package/build/esm/index.js +1 -1
  89. package/build/esm/markup/codemirror/create.d.ts +8 -5
  90. package/build/esm/markup/codemirror/create.js +42 -4
  91. package/build/esm/markup/codemirror/directive-facet.d.ts +3 -0
  92. package/build/esm/markup/codemirror/directive-facet.js +5 -0
  93. package/build/esm/markup/codemirror/html-to-markdown/converters.d.ts +111 -0
  94. package/build/esm/markup/codemirror/html-to-markdown/converters.js +210 -0
  95. package/build/esm/markup/codemirror/html-to-markdown/handlers.d.ts +104 -0
  96. package/build/esm/markup/codemirror/html-to-markdown/handlers.js +215 -0
  97. package/build/esm/markup/codemirror/html-to-markdown/helpers.d.ts +1 -0
  98. package/build/esm/markup/codemirror/html-to-markdown/helpers.js +17 -0
  99. package/build/esm/markup/codemirror/index.d.ts +1 -0
  100. package/build/esm/markup/codemirror/index.js +1 -0
  101. package/build/esm/markup/codemirror/yfm.d.ts +5 -0
  102. package/build/esm/markup/codemirror/yfm.js +25 -3
  103. package/build/esm/markup/commands/inline.js +18 -8
  104. package/build/esm/markup/commands/yfm.js +9 -1
  105. package/build/esm/utils/clipboard.d.ts +14 -0
  106. package/build/esm/utils/clipboard.js +32 -0
  107. package/build/esm/utils/directive.d.ts +28 -0
  108. package/build/esm/utils/directive.js +51 -0
  109. package/build/esm/utils/index.d.ts +1 -0
  110. package/build/esm/version.js +1 -1
  111. package/build/styles.css +1 -1
  112. package/package.json +10 -6
@@ -15,7 +15,7 @@
15
15
  position: absolute;
16
16
  inset: var(--g-md-toolbar-sticky-inset, -4px);
17
17
  content: "";
18
- border: 1px solid var(--g-color-line-generic-solid);
18
+ border: var(--g-md-toolbar-sticky-border, 1px solid var(--g-color-line-generic-solid));
19
19
  border-radius: 4px;
20
20
  background-color: var(--g-color-base-background);
21
21
  }
@@ -3,6 +3,7 @@ import type { MarkupString } from '../common';
3
3
  import type { EscapeConfig, Extension } from '../core';
4
4
  import type { CreateCodemirrorParams, YfmLangOptions } from '../markup';
5
5
  import type { FileUploadHandler } from '../utils';
6
+ import type { DirectiveSyntaxContext, DirectiveSyntaxOption } from '../utils/directive';
6
7
  import type { ChangeEditorModeOptions } from './Editor';
7
8
  import type { ExtensionsOptions as WysiwygPresetExtensionsOptions } from './wysiwyg-preset';
8
9
  export type { Editor as MarkdownEditorInstance } from './Editor';
@@ -13,6 +14,7 @@ export declare type RenderPreviewParams = {
13
14
  getValue: () => MarkupString;
14
15
  mode: 'preview' | 'split';
15
16
  md: Readonly<MarkdownEditorMdOptions>;
17
+ directiveSyntax: Pick<DirectiveSyntaxContext, 'option' | 'valueFor' | 'mdPluginValueFor'>;
16
18
  };
17
19
  export declare type RenderPreview = (params: RenderPreviewParams) => ReactNode;
18
20
  export declare type ParseInsertedUrlAsImage = (text: string) => {
@@ -61,6 +63,26 @@ export declare type MarkdownEditorExperimentalOptions = {
61
63
  */
62
64
  prepareRawMarkup?: (value: MarkupString) => MarkupString;
63
65
  beforeEditorModeChange?: (options: Pick<ChangeEditorModeOptions, 'mode' | 'reason'>) => boolean | undefined;
66
+ /**
67
+ * Enables support of directive syntax for diplodoc (YFM) extensions.
68
+ *
69
+ * **Note:** This setting affects parsing of markdown markup and serializing to markdown markup.
70
+ * Be careful with it and use it in consistency with diplodoc/transform and diplodoc-extensions.
71
+ *
72
+ * Before enabling this option, make sure that appropriate versions of diplodoc/transform and diplodoc-extensions are installed.
73
+ *
74
+ * You can pass an object in `key:value` format to provide different behaviour for each extension individually.
75
+ *
76
+ * Values:
77
+ * - 'disabled' – directive syntax is disabled;
78
+ * - 'enabled' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using old syntax;
79
+ * - 'preserve' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using directive syntax;
80
+ * - 'overwrite' – existing blocks will be overwritten using directive syntax through serialization;
81
+ * - 'only' – old syntax is disabled, only directive syntax available. Blocks in old syntax will not be parsed.
82
+ *
83
+ * Default value is 'disabled'.
84
+ */
85
+ directiveSyntax?: DirectiveSyntaxOption;
64
86
  };
65
87
  export declare type MarkdownEditorMarkupConfig = {
66
88
  /**
@@ -87,6 +109,8 @@ export declare type MarkdownEditorMarkupConfig = {
87
109
  keymaps?: CreateCodemirrorParams['keymaps'];
88
110
  /** Overrides the default placeholder content. */
89
111
  placeholder?: CreateCodemirrorParams['placeholder'];
112
+ /** Enable HTML parsing when pasting content. */
113
+ parseHtmlOnPaste?: boolean;
90
114
  /**
91
115
  * Additional language data for markdown language in codemirror.
92
116
  * Can be used to configure additional autocompletions and others.
@@ -4,6 +4,7 @@ exports.useMarkdownEditor = void 0;
4
4
  const react_1 = require("react");
5
5
  const extensions_1 = require("../extensions");
6
6
  const logger_1 = require("../logger");
7
+ const directive_1 = require("../utils/directive");
7
8
  const Editor_1 = require("./Editor");
8
9
  const wysiwyg_preset_1 = require("./wysiwyg-preset");
9
10
  // [major] TODO: remove generic type
@@ -17,10 +18,12 @@ function useMarkdownEditor(props, deps = []) {
17
18
  const uploadFile = (_c = handlers.uploadFile) !== null && _c !== void 0 ? _c : props.fileUploadHandler;
18
19
  const needToSetDimensionsForUploadedImages = (_d = experimental.needToSetDimensionsForUploadedImages) !== null && _d !== void 0 ? _d : props.needToSetDimensionsForUploadedImages;
19
20
  const enableNewImageSizeCalculation = experimental.enableNewImageSizeCalculation;
21
+ const directiveSyntax = new directive_1.DirectiveSyntaxContext(experimental.directiveSyntax);
20
22
  const extensions = (builder) => {
21
23
  var _a;
22
24
  const extensionOptions = (_a = wysiwygConfig.extensionOptions) !== null && _a !== void 0 ? _a : props.extensionOptions;
23
- builder.use(wysiwyg_preset_1.BundlePreset, Object.assign(Object.assign({}, extensionOptions), { preset, reactRenderer: renderStorage, onCancel: () => {
25
+ builder.use(wysiwyg_preset_1.BundlePreset, Object.assign(Object.assign({}, extensionOptions), { directiveSyntax,
26
+ preset, reactRenderer: renderStorage, onCancel: () => {
24
27
  editor.emit('cancel', null);
25
28
  return true;
26
29
  }, onSubmit: () => {
@@ -36,7 +39,8 @@ function useMarkdownEditor(props, deps = []) {
36
39
  }
37
40
  };
38
41
  return new Editor_1.EditorImpl(Object.assign(Object.assign({}, props), { preset,
39
- renderStorage, md: Object.assign(Object.assign({}, md), { breaks, html: (_e = md.html) !== null && _e !== void 0 ? _e : props.allowHTML, linkify: (_f = md.linkify) !== null && _f !== void 0 ? _f : props.linkify, linkifyTlds: (_g = md.linkifyTlds) !== null && _g !== void 0 ? _g : props.linkifyTlds }), initial: Object.assign(Object.assign({}, initial), { markup: (_h = initial.markup) !== null && _h !== void 0 ? _h : props.initialMarkup, mode: (_j = initial.mode) !== null && _j !== void 0 ? _j : props.initialEditorMode, toolbarVisible: (_k = initial.toolbarVisible) !== null && _k !== void 0 ? _k : props.initialToolbarVisible, splitModeEnabled: (_l = initial.splitModeEnabled) !== null && _l !== void 0 ? _l : props.initialSplitModeEnabled }), handlers: Object.assign(Object.assign({}, handlers), { uploadFile }), experimental: Object.assign(Object.assign({}, experimental), { needToSetDimensionsForUploadedImages,
42
+ renderStorage,
43
+ directiveSyntax, md: Object.assign(Object.assign({}, md), { breaks, html: (_e = md.html) !== null && _e !== void 0 ? _e : props.allowHTML, linkify: (_f = md.linkify) !== null && _f !== void 0 ? _f : props.linkify, linkifyTlds: (_g = md.linkifyTlds) !== null && _g !== void 0 ? _g : props.linkifyTlds }), initial: Object.assign(Object.assign({}, initial), { markup: (_h = initial.markup) !== null && _h !== void 0 ? _h : props.initialMarkup, mode: (_j = initial.mode) !== null && _j !== void 0 ? _j : props.initialEditorMode, toolbarVisible: (_k = initial.toolbarVisible) !== null && _k !== void 0 ? _k : props.initialToolbarVisible, splitModeEnabled: (_l = initial.splitModeEnabled) !== null && _l !== void 0 ? _l : props.initialSplitModeEnabled }), handlers: Object.assign(Object.assign({}, handlers), { uploadFile }), experimental: Object.assign(Object.assign({}, experimental), { needToSetDimensionsForUploadedImages,
40
44
  enableNewImageSizeCalculation, prepareRawMarkup: (_m = experimental.prepareRawMarkup) !== null && _m !== void 0 ? _m : props.prepareRawMarkup, beforeEditorModeChange: (_o = experimental.beforeEditorModeChange) !== null && _o !== void 0 ? _o : props.experimental_beforeEditorModeChange }), markupConfig: Object.assign(Object.assign({}, markupConfig), { splitMode: (_p = markupConfig.splitMode) !== null && _p !== void 0 ? _p : props.splitMode, renderPreview: (_q = markupConfig.renderPreview) !== null && _q !== void 0 ? _q : props.renderPreview, extensions: (_r = markupConfig.extensions) !== null && _r !== void 0 ? _r : props.extraMarkupExtensions }), wysiwygConfig: Object.assign(Object.assign({}, wysiwygConfig), { extensions, escapeConfig: (_s = wysiwygConfig.escapeConfig) !== null && _s !== void 0 ? _s : props.escapeConfig }) }));
41
45
  }, deps);
42
46
  (0, react_1.useLayoutEffect)(() => {
@@ -1,9 +1,10 @@
1
- import { ExtensionAuto } from '../core';
1
+ import type { ExtensionAuto } from '../core';
2
2
  import { BehaviorPresetOptions } from '../extensions/behavior';
3
3
  import { EditorModeKeymapOptions } from '../extensions/behavior/EditorModeKeymap';
4
4
  import { FullPresetOptions } from '../presets/full';
5
+ import type { DirectiveSyntaxContext } from '../utils/directive';
5
6
  import type { FileUploadHandler } from '../utils/upload';
6
- import { MarkdownEditorPreset } from './types';
7
+ import type { MarkdownEditorPreset } from './types';
7
8
  export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;
8
9
  export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
9
10
  preset: MarkdownEditorPreset;
@@ -16,5 +17,13 @@ export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOp
16
17
  */
17
18
  needToSetDimensionsForUploadedImages?: boolean;
18
19
  enableNewImageSizeCalculation?: boolean;
20
+ directiveSyntax: DirectiveSyntaxContext;
19
21
  };
22
+ declare global {
23
+ namespace WysiwygEditor {
24
+ interface Context {
25
+ directiveSyntax: DirectiveSyntaxContext;
26
+ }
27
+ }
28
+ }
20
29
  export declare const BundlePreset: ExtensionAuto<BundlePresetOptions>;
@@ -16,6 +16,7 @@ const emoji_1 = require("./emoji");
16
16
  const DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'];
17
17
  const BundlePreset = (builder, opts) => {
18
18
  var _a, _b, _c;
19
+ builder.context.set('directiveSyntax', opts.directiveSyntax);
19
20
  const dropCursor = {
20
21
  color: 'var(--g-color-line-brand)',
21
22
  width: 2,
@@ -3,6 +3,7 @@ export declare enum DataTransferType {
3
3
  Text = "text/plain",
4
4
  Html = "text/html",
5
5
  Yfm = "text/yfm",
6
+ Rtf = "text/rtf",
6
7
  UriList = "text/uri-list",
7
8
  VSCodeData = "vscode-editor-data",
8
9
  Files = "Files"
@@ -7,6 +7,7 @@ var DataTransferType;
7
7
  DataTransferType["Text"] = "text/plain";
8
8
  DataTransferType["Html"] = "text/html";
9
9
  DataTransferType["Yfm"] = "text/yfm";
10
+ DataTransferType["Rtf"] = "text/rtf";
10
11
  DataTransferType["UriList"] = "text/uri-list";
11
12
  DataTransferType["VSCodeData"] = "vscode-editor-data";
12
13
  DataTransferType["Files"] = "Files";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePaste = void 0;
4
- const utils_1 = require("../../behavior/Clipboard/utils");
4
+ const clipboard_1 = require("../../../utils/clipboard");
5
5
  const const_1 = require("./const");
6
6
  const handlePaste = (view, e) => {
7
7
  if (!e.clipboardData || view.state.selection.$from.parent.type.spec.code)
@@ -19,28 +19,16 @@ const handlePaste = (view, e) => {
19
19
  exports.handlePaste = handlePaste;
20
20
  function getCodeData(data) {
21
21
  var _a;
22
- if (data.getData(utils_1.DataTransferType.Text)) {
22
+ if (data.getData(clipboard_1.DataTransferType.Text)) {
23
23
  let editor = 'unknown';
24
24
  let mode;
25
- if (isVSCode(data)) {
25
+ if ((0, clipboard_1.isVSCode)(data)) {
26
26
  editor = 'vscode';
27
- mode = (_a = tryCatch(() => JSON.parse(data.getData(utils_1.DataTransferType.VSCodeData)))) === null || _a === void 0 ? void 0 : _a.mode;
27
+ mode = (_a = (0, clipboard_1.tryParseVSCodeData)(data)) === null || _a === void 0 ? void 0 : _a.mode;
28
28
  }
29
29
  else
30
30
  return null;
31
- return { editor, mode, value: data.getData(utils_1.DataTransferType.Text) };
31
+ return { editor, mode, value: data.getData(clipboard_1.DataTransferType.Text) };
32
32
  }
33
33
  return null;
34
34
  }
35
- function isVSCode(data) {
36
- return data.types.includes(utils_1.DataTransferType.VSCodeData);
37
- }
38
- function tryCatch(fn) {
39
- try {
40
- return fn();
41
- }
42
- catch (e) {
43
- console.error(e);
44
- }
45
- return undefined;
46
- }
@@ -3,6 +3,10 @@ export declare enum CutNode {
3
3
  CutTitle = "yfm_cut_title",
4
4
  CutContent = "yfm_cut_content"
5
5
  }
6
+ export declare enum CutAttr {
7
+ Class = "class",
8
+ Markup = "data-markup"
9
+ }
6
10
  export declare const cutType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
7
11
  export declare const cutTitleType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
8
12
  export declare const cutContentType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cutContentType = exports.cutTitleType = exports.cutType = exports.CutNode = void 0;
3
+ exports.cutContentType = exports.cutTitleType = exports.cutType = exports.CutAttr = exports.CutNode = void 0;
4
4
  const schema_1 = require("../../../../utils/schema");
5
5
  var CutNode;
6
6
  (function (CutNode) {
@@ -8,6 +8,11 @@ var CutNode;
8
8
  CutNode["CutTitle"] = "yfm_cut_title";
9
9
  CutNode["CutContent"] = "yfm_cut_content";
10
10
  })(CutNode = exports.CutNode || (exports.CutNode = {}));
11
+ var CutAttr;
12
+ (function (CutAttr) {
13
+ CutAttr["Class"] = "class";
14
+ CutAttr["Markup"] = "data-markup";
15
+ })(CutAttr = exports.CutAttr || (exports.CutAttr = {}));
11
16
  exports.cutType = (0, schema_1.nodeTypeFactory)(CutNode.Cut);
12
17
  exports.cutTitleType = (0, schema_1.nodeTypeFactory)(CutNode.CutTitle);
13
18
  exports.cutContentType = (0, schema_1.nodeTypeFactory)(CutNode.CutContent);
@@ -1,6 +1,13 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
3
- export { CutNode, cutType, cutTitleType, cutContentType } from './const';
3
+ export { CutAttr, CutNode, cutType, cutTitleType, cutContentType } from './const';
4
+ declare global {
5
+ namespace MarkdownEditor {
6
+ interface DirectiveSyntaxAdditionalSupportedExtensions {
7
+ yfmCut: true;
8
+ }
9
+ }
10
+ }
4
11
  export declare type YfmCutSpecsOptions = {
5
12
  cutView?: ExtensionNodeSpec['view'];
6
13
  cutTitleView?: ExtensionNodeSpec['view'];
@@ -1,23 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YfmCutSpecs = exports.cutContentType = exports.cutTitleType = exports.cutType = exports.CutNode = void 0;
3
+ exports.YfmCutSpecs = exports.cutContentType = exports.cutTitleType = exports.cutType = exports.CutNode = exports.CutAttr = void 0;
4
4
  const cut_extension_1 = require("@diplodoc/cut-extension");
5
5
  const const_1 = require("./const");
6
6
  const parser_1 = require("./parser");
7
7
  const schema_1 = require("./schema");
8
8
  const serializer_1 = require("./serializer");
9
9
  var const_2 = require("./const");
10
+ Object.defineProperty(exports, "CutAttr", { enumerable: true, get: function () { return const_2.CutAttr; } });
10
11
  Object.defineProperty(exports, "CutNode", { enumerable: true, get: function () { return const_2.CutNode; } });
11
12
  Object.defineProperty(exports, "cutType", { enumerable: true, get: function () { return const_2.cutType; } });
12
13
  Object.defineProperty(exports, "cutTitleType", { enumerable: true, get: function () { return const_2.cutTitleType; } });
13
14
  Object.defineProperty(exports, "cutContentType", { enumerable: true, get: function () { return const_2.cutContentType; } });
14
15
  const YfmCutSpecs = (builder, opts) => {
15
16
  const schemaSpecs = (0, schema_1.getSchemaSpecs)(opts, builder.context.get('placeholder'));
17
+ const directiveSyntax = builder.context.get('directiveSyntax');
18
+ const serializerTokens = (0, serializer_1.getSerializerTokens)({ directiveSyntax });
16
19
  builder
17
- .configureMd((md) => md.use((0, cut_extension_1.transform)({ bundle: false })))
20
+ .configureMd((md) => md.use((0, cut_extension_1.transform)({
21
+ bundle: false,
22
+ directiveSyntax: directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.mdPluginValueFor('yfmCut'),
23
+ })))
18
24
  .addNode(const_1.CutNode.Cut, () => ({
19
25
  spec: schemaSpecs[const_1.CutNode.Cut],
20
- toMd: serializer_1.serializerTokens[const_1.CutNode.Cut],
26
+ toMd: serializerTokens[const_1.CutNode.Cut],
21
27
  fromMd: {
22
28
  tokenSpec: parser_1.parserTokens[const_1.CutNode.Cut],
23
29
  },
@@ -25,7 +31,7 @@ const YfmCutSpecs = (builder, opts) => {
25
31
  }))
26
32
  .addNode(const_1.CutNode.CutTitle, () => ({
27
33
  spec: schemaSpecs[const_1.CutNode.CutTitle],
28
- toMd: serializer_1.serializerTokens[const_1.CutNode.CutTitle],
34
+ toMd: serializerTokens[const_1.CutNode.CutTitle],
29
35
  fromMd: {
30
36
  tokenSpec: parser_1.parserTokens[const_1.CutNode.CutTitle],
31
37
  },
@@ -33,7 +39,7 @@ const YfmCutSpecs = (builder, opts) => {
33
39
  }))
34
40
  .addNode(const_1.CutNode.CutContent, () => ({
35
41
  spec: schemaSpecs[const_1.CutNode.CutContent],
36
- toMd: serializer_1.serializerTokens[const_1.CutNode.CutContent],
42
+ toMd: serializerTokens[const_1.CutNode.CutContent],
37
43
  fromMd: {
38
44
  tokenSpec: parser_1.parserTokens[const_1.CutNode.CutContent],
39
45
  },
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parserTokens = void 0;
4
4
  const const_1 = require("./const");
5
- const getAttrs = (tok) => (tok.attrs ? Object.fromEntries(tok.attrs) : {});
5
+ const getAttrs = (tok) => {
6
+ const nodeAttrs = tok.attrs ? Object.fromEntries(tok.attrs) : {};
7
+ nodeAttrs[const_1.CutAttr.Markup] = tok.markup;
8
+ return nodeAttrs;
9
+ };
6
10
  exports.parserTokens = {
7
11
  [const_1.CutNode.Cut]: { name: const_1.CutNode.Cut, type: 'block', getAttrs },
8
12
  [const_1.CutNode.CutTitle]: { name: const_1.CutNode.CutTitle, type: 'block' },
@@ -1,5 +1,5 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import type { PlaceholderOptions } from '../../../../utils/placeholder';
3
- import { CutNode } from '../const';
3
+ import { CutNode } from './const';
4
4
  import type { YfmCutSpecsOptions } from './index';
5
5
  export declare const getSchemaSpecs: (opts?: YfmCutSpecsOptions, placeholder?: PlaceholderOptions) => Record<CutNode, NodeSpec>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSchemaSpecs = void 0;
4
- const const_1 = require("../const");
4
+ const const_1 = require("./const");
5
5
  const DEFAULT_PLACEHOLDERS = {
6
6
  Title: 'Cut title',
7
7
  Content: 'Cut content',
@@ -10,10 +10,15 @@ const getSchemaSpecs = (opts, placeholder) => {
10
10
  var _a, _b, _c, _d;
11
11
  return ({
12
12
  [const_1.CutNode.Cut]: {
13
- attrs: { class: { default: 'yfm-cut' } },
13
+ attrs: { class: { default: 'yfm-cut' }, [const_1.CutAttr.Markup]: { default: null } },
14
14
  content: `${const_1.CutNode.CutTitle} ${const_1.CutNode.CutContent}`,
15
15
  group: 'block yfm-cut',
16
- parseDOM: [{ tag: '.yfm-cut' }],
16
+ parseDOM: [
17
+ {
18
+ tag: '.yfm-cut',
19
+ getAttrs: (node) => ({ [const_1.CutAttr.Markup]: node.getAttribute(const_1.CutAttr.Markup) }),
20
+ },
21
+ ],
17
22
  toDOM(node) {
18
23
  return ['div', node.attrs, 0];
19
24
  },
@@ -1,3 +1,5 @@
1
1
  import type { SerializerNodeToken } from '../../../../core';
2
2
  import { CutNode } from './const';
3
- export declare const serializerTokens: Record<CutNode, SerializerNodeToken>;
3
+ export declare function getSerializerTokens({ directiveSyntax, }: {
4
+ directiveSyntax?: WysiwygEditor.Context['directiveSyntax'];
5
+ }): Record<CutNode, SerializerNodeToken>;
@@ -1,29 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializerTokens = void 0;
3
+ exports.getSerializerTokens = void 0;
4
4
  const nodes_1 = require("../../../../utils/nodes");
5
5
  const placeholder_1 = require("../../../../utils/placeholder");
6
6
  const const_1 = require("./const");
7
- exports.serializerTokens = {
8
- [const_1.CutNode.Cut]: (state, node) => {
9
- state.renderContent(node);
10
- state.write('{% endcut %}');
11
- state.closeBlock(node);
12
- },
13
- [const_1.CutNode.CutTitle]: (state, node) => {
14
- state.write('{% cut "');
15
- if (node.nodeSize > 2)
16
- state.renderInline(node);
17
- else
18
- state.write((0, placeholder_1.getPlaceholderContent)(node));
19
- state.write('" %}\n');
20
- state.write('\n');
21
- state.closeBlock();
22
- },
23
- [const_1.CutNode.CutContent]: (state, node) => {
24
- if (!(0, nodes_1.isNodeEmpty)(node))
25
- state.renderInline(node);
26
- else
27
- state.write((0, placeholder_1.getPlaceholderContent)(node) + '\n\n');
28
- },
29
- };
7
+ function getSerializerTokens({ directiveSyntax, }) {
8
+ const isDirectiveCut = (node) => {
9
+ return directiveSyntax === null || directiveSyntax === void 0 ? void 0 : directiveSyntax.shouldSerializeToDirective('yfmCut', node.attrs[const_1.CutAttr.Markup]);
10
+ };
11
+ return {
12
+ [const_1.CutNode.Cut]: (state, node) => {
13
+ state.renderContent(node);
14
+ state.write(isDirectiveCut(node) ? ':::' : '{% endcut %}');
15
+ state.closeBlock(node);
16
+ },
17
+ [const_1.CutNode.CutTitle]: (state, node, parent) => {
18
+ if (isDirectiveCut(parent)) {
19
+ state.write(':::cut [');
20
+ state.renderInline(node);
21
+ state.write(']');
22
+ state.ensureNewLine();
23
+ state.closeBlock();
24
+ return;
25
+ }
26
+ state.write('{% cut "');
27
+ if (node.nodeSize > 2)
28
+ state.renderInline(node);
29
+ else
30
+ state.write((0, placeholder_1.getPlaceholderContent)(node));
31
+ state.write('" %}\n');
32
+ state.write('\n');
33
+ state.closeBlock();
34
+ },
35
+ [const_1.CutNode.CutContent]: (state, node, parent) => {
36
+ if (isDirectiveCut(parent)) {
37
+ state.renderContent(node);
38
+ return;
39
+ }
40
+ if (!(0, nodes_1.isNodeEmpty)(node))
41
+ state.renderInline(node);
42
+ else
43
+ state.write((0, placeholder_1.getPlaceholderContent)(node) + '\n\n');
44
+ },
45
+ };
46
+ }
47
+ exports.getSerializerTokens = getSerializerTokens;
@@ -1,5 +1,17 @@
1
+ import { FileHtmlAttr } from '@diplodoc/file-extension';
1
2
  import type { AttributeSpec } from 'prosemirror-model';
2
3
  export declare const yfmFileNodeName = "yfm_file";
4
+ export declare const YfmFileAttr: {
5
+ readonly Markup: "data-markup";
6
+ readonly Name: FileHtmlAttr.Download;
7
+ readonly Link: FileHtmlAttr.Href;
8
+ readonly ReferrerPolicy: FileHtmlAttr.ReferrerPolicy;
9
+ readonly Rel: FileHtmlAttr.Rel;
10
+ readonly Target: FileHtmlAttr.Target;
11
+ readonly Type: FileHtmlAttr.Type;
12
+ readonly Lang: FileHtmlAttr.HrefLang;
13
+ };
14
+ export declare const YFM_FILE_DIRECTIVE_ATTRS: readonly string[];
3
15
  export declare const KNOWN_ATTRS: readonly string[];
4
16
  export declare const REQUIRED_ATTRS: string[];
5
17
  export declare const fileNodeAttrsSpec: Record<string, AttributeSpec>;
@@ -1,19 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LINK_TO_FILE_ATTRS_MAP = exports.fileNodeAttrsSpec = exports.REQUIRED_ATTRS = exports.KNOWN_ATTRS = exports.yfmFileNodeName = void 0;
4
- const const_1 = require("@diplodoc/transform/lib/plugins/file/const");
5
- exports.yfmFileNodeName = const_1.FILE_TOKEN;
6
- exports.KNOWN_ATTRS = const_1.KNOWN_ATTRS.map((attrName) => {
7
- if (attrName in const_1.FILE_TO_LINK_ATTRS_MAP)
8
- return const_1.FILE_TO_LINK_ATTRS_MAP[attrName];
3
+ exports.LINK_TO_FILE_ATTRS_MAP = exports.fileNodeAttrsSpec = exports.REQUIRED_ATTRS = exports.KNOWN_ATTRS = exports.YFM_FILE_DIRECTIVE_ATTRS = exports.YfmFileAttr = exports.yfmFileNodeName = void 0;
4
+ const file_extension_1 = require("@diplodoc/file-extension");
5
+ exports.yfmFileNodeName = file_extension_1.FILE_TOKEN;
6
+ exports.YfmFileAttr = {
7
+ Markup: 'data-markup',
8
+ Name: file_extension_1.FileHtmlAttr.Download,
9
+ Link: file_extension_1.FileHtmlAttr.Href,
10
+ ReferrerPolicy: file_extension_1.FileHtmlAttr.ReferrerPolicy,
11
+ Rel: file_extension_1.FileHtmlAttr.Rel,
12
+ Target: file_extension_1.FileHtmlAttr.Target,
13
+ Type: file_extension_1.FileHtmlAttr.Type,
14
+ Lang: file_extension_1.FileHtmlAttr.HrefLang,
15
+ };
16
+ exports.YFM_FILE_DIRECTIVE_ATTRS = [
17
+ exports.YfmFileAttr.ReferrerPolicy,
18
+ exports.YfmFileAttr.Rel,
19
+ exports.YfmFileAttr.Target,
20
+ exports.YfmFileAttr.Type,
21
+ exports.YfmFileAttr.Lang,
22
+ ];
23
+ exports.KNOWN_ATTRS = file_extension_1.FILE_KNOWN_ATTRS.map((attrName) => {
24
+ if (attrName in file_extension_1.FILE_TO_LINK_ATTRS_MAP)
25
+ return file_extension_1.FILE_TO_LINK_ATTRS_MAP[attrName];
9
26
  return attrName;
10
27
  });
11
- exports.REQUIRED_ATTRS = const_1.REQUIRED_ATTRS.map((attrName) => {
12
- if (attrName in const_1.FILE_TO_LINK_ATTRS_MAP)
13
- return const_1.FILE_TO_LINK_ATTRS_MAP[attrName];
28
+ exports.REQUIRED_ATTRS = file_extension_1.FILE_REQUIRED_ATTRS.map((attrName) => {
29
+ if (attrName in file_extension_1.FILE_TO_LINK_ATTRS_MAP)
30
+ return file_extension_1.FILE_TO_LINK_ATTRS_MAP[attrName];
14
31
  return attrName;
15
32
  });
16
- exports.fileNodeAttrsSpec = {};
33
+ exports.fileNodeAttrsSpec = {
34
+ [exports.YfmFileAttr.Markup]: { default: null },
35
+ };
17
36
  for (const attrName of exports.KNOWN_ATTRS) {
18
37
  const attrSpec = (exports.fileNodeAttrsSpec[attrName] = {});
19
38
  if (!exports.REQUIRED_ATTRS.includes(attrName)) {
@@ -21,6 +40,6 @@ for (const attrName of exports.KNOWN_ATTRS) {
21
40
  }
22
41
  }
23
42
  exports.LINK_TO_FILE_ATTRS_MAP = {};
24
- for (const [key, value] of Object.entries(const_1.FILE_TO_LINK_ATTRS_MAP)) {
43
+ for (const [key, value] of Object.entries(file_extension_1.FILE_TO_LINK_ATTRS_MAP)) {
25
44
  exports.LINK_TO_FILE_ATTRS_MAP[value] = key;
26
45
  }
@@ -1,4 +1,11 @@
1
1
  import type { Extension } from '../../../../core';
2
- export { yfmFileNodeName } from './const';
2
+ export { yfmFileNodeName, YfmFileAttr } from './const';
3
3
  export declare const fileType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
4
+ declare global {
5
+ namespace MarkdownEditor {
6
+ interface DirectiveSyntaxAdditionalSupportedExtensions {
7
+ yfmFile: true;
8
+ }
9
+ }
10
+ }
4
11
  export declare const YfmFileSpecs: Extension;
@@ -1,28 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YfmFileSpecs = exports.fileType = exports.yfmFileNodeName = void 0;
4
- const tslib_1 = require("tslib");
5
- const file_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/plugins/file"));
6
- const const_1 = require("@diplodoc/transform/lib/plugins/file/const");
3
+ exports.YfmFileSpecs = exports.fileType = exports.YfmFileAttr = exports.yfmFileNodeName = void 0;
4
+ const file_extension_1 = require("@diplodoc/file-extension");
7
5
  const schema_1 = require("../../../../utils/schema");
8
- const const_2 = require("./const");
9
- var const_3 = require("./const");
10
- Object.defineProperty(exports, "yfmFileNodeName", { enumerable: true, get: function () { return const_3.yfmFileNodeName; } });
11
- exports.fileType = (0, schema_1.nodeTypeFactory)(const_2.yfmFileNodeName);
6
+ const const_1 = require("./const");
7
+ var const_2 = require("./const");
8
+ Object.defineProperty(exports, "yfmFileNodeName", { enumerable: true, get: function () { return const_2.yfmFileNodeName; } });
9
+ Object.defineProperty(exports, "YfmFileAttr", { enumerable: true, get: function () { return const_2.YfmFileAttr; } });
10
+ exports.fileType = (0, schema_1.nodeTypeFactory)(const_1.yfmFileNodeName);
12
11
  const YfmFileSpecs = (builder) => {
13
- builder.configureMd((md) => md.use(file_1.default));
14
- builder.addNode(const_2.yfmFileNodeName, () => ({
12
+ const directiveContext = builder.context.get('directiveSyntax');
13
+ builder.configureMd((md) => md.use((0, file_extension_1.transform)({
14
+ bundle: false,
15
+ directiveSyntax: directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.mdPluginValueFor('yfmFile'),
16
+ })));
17
+ builder.addNode(const_1.yfmFileNodeName, () => ({
15
18
  spec: {
16
19
  group: 'inline',
17
20
  inline: true,
18
- attrs: const_2.fileNodeAttrsSpec,
21
+ attrs: const_1.fileNodeAttrsSpec,
19
22
  parseDOM: [
20
23
  {
21
- tag: `a[class="${const_1.FileClassName.Link}"]`,
24
+ tag: `a[class="${file_extension_1.FileClassName.Link}"]`,
22
25
  getAttrs(p) {
23
26
  const elem = p;
24
27
  const attrs = {};
25
- for (const name of const_2.KNOWN_ATTRS) {
28
+ for (const name of const_1.KNOWN_ATTRS) {
26
29
  const value = elem.getAttribute(name);
27
30
  if (value) {
28
31
  attrs[name] = value;
@@ -36,43 +39,62 @@ const YfmFileSpecs = (builder) => {
36
39
  toDOM(node) {
37
40
  const a = document.createElement('a');
38
41
  a.contentEditable = 'false';
39
- a.classList.add(const_1.FileClassName.Link);
42
+ a.classList.add(file_extension_1.FileClassName.Link);
40
43
  for (const [key, value] of Object.entries(node.attrs)) {
41
44
  if (value)
42
45
  a.setAttribute(key, value);
43
46
  }
44
47
  const span = document.createElement('span');
45
- span.classList.add(const_1.FileClassName.Icon);
48
+ span.classList.add(file_extension_1.FileClassName.Icon);
46
49
  a.appendChild(span);
47
- a.append(node.attrs[const_1.LinkHtmlAttr.Download]);
50
+ a.append(node.attrs[file_extension_1.FileHtmlAttr.Download]);
48
51
  return a;
49
52
  },
50
53
  },
51
54
  fromMd: {
52
- tokenName: const_2.yfmFileNodeName,
55
+ tokenName: const_1.yfmFileNodeName,
53
56
  tokenSpec: {
54
- name: const_2.yfmFileNodeName,
57
+ name: const_1.yfmFileNodeName,
55
58
  type: 'node',
56
59
  getAttrs: (tok) => {
57
- var _a;
58
- return Object.fromEntries((_a = tok.attrs) !== null && _a !== void 0 ? _a : []);
60
+ const attrs = Object.fromEntries(tok.attrs || []);
61
+ attrs[const_1.YfmFileAttr.Markup] = tok.markup;
62
+ return attrs;
59
63
  },
60
64
  },
61
65
  },
62
66
  toMd: (state, node) => {
67
+ if (directiveContext === null || directiveContext === void 0 ? void 0 : directiveContext.shouldSerializeToDirective('yfmFile', node.attrs[const_1.YfmFileAttr.Markup])) {
68
+ state.write(serializeToDirective(node));
69
+ return;
70
+ }
63
71
  const attrsStr = Object.entries(node.attrs)
64
72
  .reduce((arr, [key, value]) => {
65
- if (value) {
66
- if (key in const_2.LINK_TO_FILE_ATTRS_MAP) {
67
- key = const_2.LINK_TO_FILE_ATTRS_MAP[key];
73
+ if (key !== const_1.YfmFileAttr.Markup && value) {
74
+ if (key in const_1.LINK_TO_FILE_ATTRS_MAP) {
75
+ key = const_1.LINK_TO_FILE_ATTRS_MAP[key];
68
76
  }
69
77
  arr.push(`${key}="${value.replace(/"/g, '')}"`);
70
78
  }
71
79
  return arr;
72
80
  }, [])
73
81
  .join(' ');
74
- state.write(`${const_1.PREFIX}${attrsStr} %}`);
82
+ state.write(`${file_extension_1.FILE_MARKUP_PREFIX}${attrsStr} %}`);
75
83
  },
76
84
  }));
77
85
  };
78
86
  exports.YfmFileSpecs = YfmFileSpecs;
87
+ function serializeToDirective(node) {
88
+ const filename = node.attrs[const_1.YfmFileAttr.Name] || '';
89
+ const filelink = node.attrs[const_1.YfmFileAttr.Link] || '';
90
+ let fileMarkup = `:file[${filename}](${filelink})`;
91
+ const attrs = const_1.YFM_FILE_DIRECTIVE_ATTRS.reduce((acc, key) => {
92
+ const value = node.attrs[key];
93
+ if (value)
94
+ acc.push(`${key}="${value}"`);
95
+ return acc;
96
+ }, []);
97
+ if (attrs.length)
98
+ fileMarkup += `{${attrs.join(' ')}}`;
99
+ return fileMarkup;
100
+ }