@gravity-ui/markdown-editor 13.6.1 → 13.7.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.
@@ -1,4 +1,4 @@
1
- import { Completion, snippet } from '@codemirror/autocomplete';
1
+ import { Completion, CompletionSource, snippet } from '@codemirror/autocomplete';
2
2
  import type { Extension } from '@codemirror/state';
3
3
  import { Tag } from '@lezer/highlight';
4
4
  export declare const customTags: {
@@ -15,4 +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 function yfmLang(): Extension;
18
+ export interface LanguageData {
19
+ autocomplete: CompletionSource;
20
+ [key: string]: any;
21
+ }
22
+ export interface YfmLangOptions {
23
+ languageData?: LanguageData[];
24
+ }
25
+ export declare function yfmLang({ languageData }?: YfmLangOptions): Extension;
@@ -58,7 +58,56 @@ exports.yfmNoteSnippets = {
58
58
  };
59
59
  exports.yfmCutSnippetTemplate = '{% cut "#{title}" %}\n\n#{}\n\n{% endcut %}\n\n';
60
60
  exports.yfmCutSnippet = (0, autocomplete_1.snippet)(exports.yfmCutSnippetTemplate);
61
- function yfmLang() {
61
+ const mdAutocomplete = {
62
+ autocomplete: (context) => {
63
+ // TODO: add more actions and re-enable
64
+ // let word = context.matchBefore(/\/.*/);
65
+ // if (word) {
66
+ // return {
67
+ // from: word.from,
68
+ // options: [
69
+ // ...yfmNoteTypes.map<Completion>((type, index) => ({
70
+ // label: `/yfm note ${type}`,
71
+ // displayLabel: `YFM Note ${capitalize(type)}`,
72
+ // type: 'text',
73
+ // apply: yfmNoteSnippets[type],
74
+ // boost: -index,
75
+ // })),
76
+ // {
77
+ // label: '/yfm cut',
78
+ // displayLabel: 'YFM Cut',
79
+ // type: 'text',
80
+ // apply: yfmCutSnippet,
81
+ // },
82
+ // ],
83
+ // };
84
+ // }
85
+ const word = context.matchBefore(/^.*/);
86
+ if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
87
+ return {
88
+ from: word.from,
89
+ options: [
90
+ ...exports.yfmNoteTypes.map((type, index) => ({
91
+ label: `{% note ${type}`,
92
+ displayLabel: (0, lodash_1.capitalize)(type),
93
+ type: 'text',
94
+ section: 'YFM Note',
95
+ apply: exports.yfmNoteSnippets[type],
96
+ boost: -index,
97
+ })),
98
+ {
99
+ label: '{% cut',
100
+ displayLabel: 'YFM Cut',
101
+ type: 'text',
102
+ apply: exports.yfmCutSnippet,
103
+ },
104
+ ],
105
+ };
106
+ }
107
+ return null;
108
+ },
109
+ };
110
+ function yfmLang({ languageData = [] } = {}) {
62
111
  const mdSupport = (0, lang_markdown_1.markdown)({
63
112
  // defaultCodeLanguage: markdownLanguage,
64
113
  base: lang_markdown_1.markdownLanguage,
@@ -66,55 +115,10 @@ function yfmLang() {
66
115
  completeHTMLTags: false,
67
116
  extensions: [UnderlineExtension, MonospaceExtension, MarkedExtension],
68
117
  });
69
- const mdAutocomplete = {
70
- autocomplete: (context) => {
71
- // TODO: add more actions and re-enable
72
- // let word = context.matchBefore(/\/.*/);
73
- // if (word) {
74
- // return {
75
- // from: word.from,
76
- // options: [
77
- // ...yfmNoteTypes.map<Completion>((type, index) => ({
78
- // label: `/yfm note ${type}`,
79
- // displayLabel: `YFM Note ${capitalize(type)}`,
80
- // type: 'text',
81
- // apply: yfmNoteSnippets[type],
82
- // boost: -index,
83
- // })),
84
- // {
85
- // label: '/yfm cut',
86
- // displayLabel: 'YFM Cut',
87
- // type: 'text',
88
- // apply: yfmCutSnippet,
89
- // },
90
- // ],
91
- // };
92
- // }
93
- const word = context.matchBefore(/^.*/);
94
- if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
95
- return {
96
- from: word.from,
97
- options: [
98
- ...exports.yfmNoteTypes.map((type, index) => ({
99
- label: `{% note ${type}`,
100
- displayLabel: (0, lodash_1.capitalize)(type),
101
- type: 'text',
102
- section: 'YFM Note',
103
- apply: exports.yfmNoteSnippets[type],
104
- boost: -index,
105
- })),
106
- {
107
- label: '{% cut',
108
- displayLabel: 'YFM Cut',
109
- type: 'text',
110
- apply: exports.yfmCutSnippet,
111
- },
112
- ],
113
- };
114
- }
115
- return null;
116
- },
117
- };
118
- return [mdSupport, mdSupport.language.data.of(mdAutocomplete)];
118
+ return [
119
+ mdSupport,
120
+ mdSupport.language.data.of(mdAutocomplete),
121
+ languageData.map((item) => mdSupport.language.data.of(item)),
122
+ ];
119
123
  }
120
124
  exports.yfmLang = yfmLang;
@@ -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.6.1' !== 'undefined' ? '13.6.1' : 'unknown';
5
+ exports.VERSION = typeof '13.7.0' !== 'undefined' ? '13.7.0' : 'unknown';
@@ -1,4 +1,4 @@
1
- import { Completion, snippet } from '@codemirror/autocomplete';
1
+ import { Completion, CompletionSource, snippet } from '@codemirror/autocomplete';
2
2
  import type { Extension } from '@codemirror/state';
3
3
  import { Tag } from '@lezer/highlight';
4
4
  export declare const customTags: {
@@ -15,4 +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 function yfmLang(): Extension;
18
+ export interface LanguageData {
19
+ autocomplete: CompletionSource;
20
+ [key: string]: any;
21
+ }
22
+ export interface YfmLangOptions {
23
+ languageData?: LanguageData[];
24
+ }
25
+ export declare function yfmLang({ languageData }?: YfmLangOptions): Extension;
@@ -54,7 +54,56 @@ export const yfmNoteSnippets = {
54
54
  };
55
55
  export const yfmCutSnippetTemplate = '{% cut "#{title}" %}\n\n#{}\n\n{% endcut %}\n\n';
56
56
  export const yfmCutSnippet = snippet(yfmCutSnippetTemplate);
57
- export function yfmLang() {
57
+ const mdAutocomplete = {
58
+ autocomplete: (context) => {
59
+ // TODO: add more actions and re-enable
60
+ // let word = context.matchBefore(/\/.*/);
61
+ // if (word) {
62
+ // return {
63
+ // from: word.from,
64
+ // options: [
65
+ // ...yfmNoteTypes.map<Completion>((type, index) => ({
66
+ // label: `/yfm note ${type}`,
67
+ // displayLabel: `YFM Note ${capitalize(type)}`,
68
+ // type: 'text',
69
+ // apply: yfmNoteSnippets[type],
70
+ // boost: -index,
71
+ // })),
72
+ // {
73
+ // label: '/yfm cut',
74
+ // displayLabel: 'YFM Cut',
75
+ // type: 'text',
76
+ // apply: yfmCutSnippet,
77
+ // },
78
+ // ],
79
+ // };
80
+ // }
81
+ const word = context.matchBefore(/^.*/);
82
+ if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
83
+ return {
84
+ from: word.from,
85
+ options: [
86
+ ...yfmNoteTypes.map((type, index) => ({
87
+ label: `{% note ${type}`,
88
+ displayLabel: capitalize(type),
89
+ type: 'text',
90
+ section: 'YFM Note',
91
+ apply: yfmNoteSnippets[type],
92
+ boost: -index,
93
+ })),
94
+ {
95
+ label: '{% cut',
96
+ displayLabel: 'YFM Cut',
97
+ type: 'text',
98
+ apply: yfmCutSnippet,
99
+ },
100
+ ],
101
+ };
102
+ }
103
+ return null;
104
+ },
105
+ };
106
+ export function yfmLang({ languageData = [] } = {}) {
58
107
  const mdSupport = markdown({
59
108
  // defaultCodeLanguage: markdownLanguage,
60
109
  base: markdownLanguage,
@@ -62,54 +111,9 @@ export function yfmLang() {
62
111
  completeHTMLTags: false,
63
112
  extensions: [UnderlineExtension, MonospaceExtension, MarkedExtension],
64
113
  });
65
- const mdAutocomplete = {
66
- autocomplete: (context) => {
67
- // TODO: add more actions and re-enable
68
- // let word = context.matchBefore(/\/.*/);
69
- // if (word) {
70
- // return {
71
- // from: word.from,
72
- // options: [
73
- // ...yfmNoteTypes.map<Completion>((type, index) => ({
74
- // label: `/yfm note ${type}`,
75
- // displayLabel: `YFM Note ${capitalize(type)}`,
76
- // type: 'text',
77
- // apply: yfmNoteSnippets[type],
78
- // boost: -index,
79
- // })),
80
- // {
81
- // label: '/yfm cut',
82
- // displayLabel: 'YFM Cut',
83
- // type: 'text',
84
- // apply: yfmCutSnippet,
85
- // },
86
- // ],
87
- // };
88
- // }
89
- const word = context.matchBefore(/^.*/);
90
- if (word === null || word === void 0 ? void 0 : word.text.startsWith('{%')) {
91
- return {
92
- from: word.from,
93
- options: [
94
- ...yfmNoteTypes.map((type, index) => ({
95
- label: `{% note ${type}`,
96
- displayLabel: capitalize(type),
97
- type: 'text',
98
- section: 'YFM Note',
99
- apply: yfmNoteSnippets[type],
100
- boost: -index,
101
- })),
102
- {
103
- label: '{% cut',
104
- displayLabel: 'YFM Cut',
105
- type: 'text',
106
- apply: yfmCutSnippet,
107
- },
108
- ],
109
- };
110
- }
111
- return null;
112
- },
113
- };
114
- return [mdSupport, mdSupport.language.data.of(mdAutocomplete)];
114
+ return [
115
+ mdSupport,
116
+ mdSupport.language.data.of(mdAutocomplete),
117
+ languageData.map((item) => mdSupport.language.data.of(item)),
118
+ ];
115
119
  }
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '13.6.1' !== 'undefined' ? '13.6.1' : 'unknown';
2
+ export const VERSION = typeof '13.7.0' !== 'undefined' ? '13.7.0' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "13.6.1",
3
+ "version": "13.7.0",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {