@krainovsd/markdown-editor 0.3.2 → 0.4.2

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 (85) hide show
  1. package/lib/cjs/{index-BgxbH3r2.js → index-Df0WnJ4c.js} +470 -54
  2. package/lib/cjs/index-Df0WnJ4c.js.map +1 -0
  3. package/lib/cjs/{index-DU8JMAfc.js → index-Ne5xJkxS.js} +10 -6
  4. package/lib/cjs/index-Ne5xJkxS.js.map +1 -0
  5. package/lib/cjs/index.js +2 -1
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/esm/extensions/auto-completes/custom/tag-auto-complete.js +33 -0
  8. package/lib/esm/extensions/auto-completes/custom/tag-auto-complete.js.map +1 -0
  9. package/lib/esm/extensions/auto-completes/init-auto-complete.js +27 -0
  10. package/lib/esm/extensions/auto-completes/init-auto-complete.js.map +1 -0
  11. package/lib/esm/extensions/init-extensions.js +5 -3
  12. package/lib/esm/extensions/init-extensions.js.map +1 -1
  13. package/lib/esm/extensions/keymaps/custom/bold-key-map.js +56 -0
  14. package/lib/esm/extensions/keymaps/custom/bold-key-map.js.map +1 -0
  15. package/lib/esm/extensions/keymaps/custom/italic-key-map.js +57 -0
  16. package/lib/esm/extensions/keymaps/custom/italic-key-map.js.map +1 -0
  17. package/lib/esm/extensions/keymaps/custom/link-key-map.js +28 -0
  18. package/lib/esm/extensions/keymaps/custom/link-key-map.js.map +1 -0
  19. package/lib/esm/extensions/keymaps/init-key-map.js +7 -10
  20. package/lib/esm/extensions/keymaps/init-key-map.js.map +1 -1
  21. package/lib/esm/extensions/listeners/get-change-event.js +3 -3
  22. package/lib/esm/extensions/listeners/get-change-event.js.map +1 -1
  23. package/lib/esm/extensions/listeners/get-focus-event.js +3 -3
  24. package/lib/esm/extensions/listeners/get-focus-event.js.map +1 -1
  25. package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js +1 -1
  26. package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js.map +1 -1
  27. package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js +1 -1
  28. package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js.map +1 -1
  29. package/lib/esm/extensions/markdown/bold/bold-constants.js +1 -1
  30. package/lib/esm/extensions/markdown/bold/bold-constants.js.map +1 -1
  31. package/lib/esm/extensions/markdown/bold/bold-decoration.js +1 -1
  32. package/lib/esm/extensions/markdown/code/code-constants.js +3 -1
  33. package/lib/esm/extensions/markdown/code/code-constants.js.map +1 -1
  34. package/lib/esm/extensions/markdown/code/code-decoration.js +34 -3
  35. package/lib/esm/extensions/markdown/code/code-decoration.js.map +1 -1
  36. package/lib/esm/extensions/markdown/header/header-decoration.js +1 -1
  37. package/lib/esm/extensions/markdown/image/image-decoration.js.map +1 -1
  38. package/lib/esm/extensions/markdown/image/image-widget.js +26 -2
  39. package/lib/esm/extensions/markdown/image/image-widget.js.map +1 -1
  40. package/lib/esm/extensions/markdown/italic/italic-decoration.js +2 -2
  41. package/lib/esm/extensions/markdown/italic/italic-decoration.js.map +1 -1
  42. package/lib/esm/extensions/markdown/link/link-decoration.js +1 -1
  43. package/lib/esm/extensions/markdown/link/link-decoration.js.map +1 -1
  44. package/lib/esm/extensions/markdown/link/link-widget.js +28 -2
  45. package/lib/esm/extensions/markdown/link/link-widget.js.map +1 -1
  46. package/lib/esm/extensions/markdown/list/list-decoration.js +1 -1
  47. package/lib/esm/extensions/markdown/list/list-decoration.js.map +1 -1
  48. package/lib/esm/extensions/markdown/markdown-decoration.js +2 -2
  49. package/lib/esm/extensions/markdown/markdown-decoration.js.map +1 -1
  50. package/lib/esm/extensions/markdown/mention/mention-constants.js +4 -3
  51. package/lib/esm/extensions/markdown/mention/mention-constants.js.map +1 -1
  52. package/lib/esm/extensions/markdown/mention/mention-decoration.js +1 -1
  53. package/lib/esm/extensions/markdown/mention/mention-parser.js +8 -5
  54. package/lib/esm/extensions/markdown/mention/mention-parser.js.map +1 -1
  55. package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js +1 -1
  56. package/lib/esm/extensions/markdown/styles.module.scss.js +2 -2
  57. package/lib/esm/extensions/markdown/todo/todo-decoration.js +1 -1
  58. package/lib/esm/extensions/markdown/todo/todo-decoration.js.map +1 -1
  59. package/lib/esm/extensions/settings/init-settings.js +2 -2
  60. package/lib/esm/extensions/settings/init-settings.js.map +1 -1
  61. package/lib/esm/extensions/theme/theme-constants.js +2 -0
  62. package/lib/esm/extensions/theme/theme-constants.js.map +1 -1
  63. package/lib/esm/extensions/theme/themes/get-dark-theme.js +5 -2
  64. package/lib/esm/extensions/theme/themes/get-dark-theme.js.map +1 -1
  65. package/lib/esm/extensions/theme/themes/get-highlight-template.js +4 -1
  66. package/lib/esm/extensions/theme/themes/get-highlight-template.js.map +1 -1
  67. package/lib/esm/extensions/theme/themes/get-light-theme.js +5 -2
  68. package/lib/esm/extensions/theme/themes/get-light-theme.js.map +1 -1
  69. package/lib/esm/extensions/theme/themes/get-theme-template.js +7 -0
  70. package/lib/esm/extensions/theme/themes/get-theme-template.js.map +1 -1
  71. package/lib/esm/index.js +1 -0
  72. package/lib/esm/index.js.map +1 -1
  73. package/lib/esm/lib/utils/overlap-mark.js +151 -0
  74. package/lib/esm/lib/utils/overlap-mark.js.map +1 -0
  75. package/lib/esm/module/Editor/Editor.js +3 -6
  76. package/lib/esm/module/Editor/Editor.js.map +1 -1
  77. package/lib/esm/module/Editor/lib/init-editor-provider.js +2 -3
  78. package/lib/esm/module/Editor/lib/init-editor-provider.js.map +1 -1
  79. package/lib/esm/module/Editor/lib/init-editor.js +1 -1
  80. package/lib/esm/module/Editor/lib/init-editor.js.map +1 -1
  81. package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +1 -1
  82. package/lib/index.d.ts +11 -2
  83. package/package.json +19 -29
  84. package/lib/cjs/index-BgxbH3r2.js.map +0 -1
  85. package/lib/cjs/index-DU8JMAfc.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
 
3
3
  const view = require('@codemirror/view');
4
4
  const state = require('@codemirror/state');
5
+ const autocomplete = require('@codemirror/autocomplete');
5
6
  const commands = require('@codemirror/commands');
6
7
  const language = require('@codemirror/language');
7
8
  const highlight = require('@lezer/highlight');
@@ -13,6 +14,59 @@ const ReadonlyCompartment = new state.Compartment();
13
14
  const VimModeCompartment = new state.Compartment();
14
15
  const ThemeCompartment = new state.Compartment();
15
16
 
17
+ const CODE_OF_START_MENTION$1 = "@".codePointAt(0); // @
18
+ const CODE_OF_SPACE$3 = " ".codePointAt(0);
19
+ const CODE_OF_LINE_BREAK$1 = "\n".codePointAt(0);
20
+ const tagAutoComplete = (tagOptions) => {
21
+ const options = tagOptions.map((user) => ({
22
+ label: `@${user}`,
23
+ type: "text",
24
+ }));
25
+ return (context) => {
26
+ const line = context.view?.lineBlockAt?.(context.pos);
27
+ if (!line)
28
+ return null;
29
+ const content = context.state.sliceDoc(line.from, context.pos);
30
+ let pos = content.length - 1;
31
+ while (pos > -1) {
32
+ const code = content.codePointAt(pos);
33
+ if (!code || code === CODE_OF_SPACE$3 || code === CODE_OF_LINE_BREAK$1)
34
+ return null;
35
+ if (code == CODE_OF_START_MENTION$1)
36
+ break;
37
+ pos--;
38
+ }
39
+ if (pos === -1)
40
+ return null;
41
+ return {
42
+ from: line.from + pos,
43
+ options,
44
+ };
45
+ };
46
+ };
47
+
48
+ const initAutoComplete = ({ autoCompleteTagOptions, autoCompleteConfig = {}, }) => {
49
+ if (!autoCompleteTagOptions)
50
+ return [];
51
+ return [
52
+ autocomplete.autocompletion({
53
+ activateOnTyping: true,
54
+ activateOnTypingDelay: 100,
55
+ selectOnOpen: true,
56
+ closeOnBlur: true,
57
+ maxRenderedOptions: 20,
58
+ aboveCursor: false,
59
+ defaultKeymap: true,
60
+ icons: false,
61
+ filterStrict: false,
62
+ interactionDelay: 75,
63
+ updateSyncTime: 100,
64
+ ...autoCompleteConfig,
65
+ override: [tagAutoComplete(autoCompleteTagOptions)],
66
+ }),
67
+ ];
68
+ };
69
+
16
70
  function copyToClipboard(content) {
17
71
  if (navigator.clipboard && window.isSecureContext) {
18
72
  return navigator.clipboard.writeText(content);
@@ -92,6 +146,155 @@ function saveDispatch(dispatch) {
92
146
  });
93
147
  }
94
148
 
149
+ function overlapMark({ marks, shift, state, requireMatched }) {
150
+ const { from, to, shiftAfterInner, shiftAfterOuter, shiftBeforeInner, shiftBeforeOuter, text } = processShiftContent(state, shift, marks);
151
+ const startIndex = findMarkIndex(text.substring(0, shiftBeforeInner + shiftBeforeOuter), marks, requireMatched, "right");
152
+ const endIndex = findMarkIndex(text.substring(text.length - shiftAfterInner - shiftAfterOuter), marks, requireMatched, "left");
153
+ const start = ~startIndex ? from - shiftBeforeOuter + startIndex : -1;
154
+ const end = ~endIndex ? to - shiftAfterInner + endIndex : -1;
155
+ // console.log({
156
+ // from,
157
+ // to,
158
+ // shiftAfterInner,
159
+ // shiftAfterOuter,
160
+ // shiftBeforeInner,
161
+ // shiftBeforeOuter,
162
+ // text,
163
+ // textStart: text.substring(0, shiftBeforeInner + shiftBeforeOuter),
164
+ // textEnd: text.substring(text.length - shiftAfterInner - shiftAfterOuter),
165
+ // startIndex,
166
+ // endIndex,
167
+ // end,
168
+ // start,
169
+ // });
170
+ return {
171
+ start,
172
+ end,
173
+ marked: Boolean(~start || ~end),
174
+ originalText: text.substring(shiftBeforeOuter, text.length - shiftAfterOuter),
175
+ };
176
+ }
177
+ // eslint-disable-next-line max-params
178
+ function findMarkIndex(text, marks, requireMatched, direction = "right") {
179
+ if (text.length === 0)
180
+ return -1;
181
+ const maxRequired = Math.max(...requireMatched);
182
+ const minRequired = Math.min(...requireMatched);
183
+ let pos = 0;
184
+ let matched = 0;
185
+ let start = -1;
186
+ for (const mark of marks) {
187
+ if (!mark)
188
+ continue;
189
+ while (pos < text.length) {
190
+ if (text.codePointAt(pos) === mark)
191
+ matched++;
192
+ else {
193
+ if (
194
+ // eslint-disable-next-line no-loop-func -- https://eslint.org/docs/latest/rules/no-loop-func#known-limitations
195
+ requireMatched.some((rm) => rm === matched) &&
196
+ ((direction === "right" && pos - matched > start) ||
197
+ (direction === "left" && (pos - matched < start || start === -1)))) {
198
+ start = direction === "right" ? pos - minRequired : pos - matched;
199
+ // console.log({ pos, matched, start, minRequired, maxRequired, direction });
200
+ }
201
+ else if (maxRequired < matched) {
202
+ const posMin = pos - minRequired;
203
+ const posMax = pos - matched;
204
+ // console.log({ posMin, posMax, pos, minRequired, maxRequired, direction, matched });
205
+ // eslint-disable-next-line max-depth
206
+ if (direction === "right" && posMin > start)
207
+ start = posMin;
208
+ // eslint-disable-next-line max-depth
209
+ if (direction === "left" && (posMax < start || start === -1))
210
+ start = posMax;
211
+ }
212
+ matched = 0;
213
+ }
214
+ pos++;
215
+ }
216
+ if (
217
+ // eslint-disable-next-line no-loop-func -- https://eslint.org/docs/latest/rules/no-loop-func#known-limitations
218
+ requireMatched.some((rm) => rm === matched) &&
219
+ ((direction === "right" && pos - matched > start) ||
220
+ (direction === "left" && (pos - matched < start || start === -1)))) {
221
+ start = direction === "right" ? pos - minRequired : pos - matched;
222
+ // console.log({ pos, matched, start, minRequired, maxRequired, direction });
223
+ }
224
+ else if (maxRequired < matched) {
225
+ const posMin = pos - minRequired;
226
+ const posMax = pos - matched;
227
+ // console.log({ posMin, posMax, pos, minRequired, maxRequired, direction, matched });
228
+ if (direction === "right" && posMin > start)
229
+ start = posMin;
230
+ if (direction === "left" && (posMax < start || start === -1))
231
+ start = posMax;
232
+ }
233
+ pos = 0;
234
+ matched = 0;
235
+ }
236
+ return start;
237
+ }
238
+ function processShiftContent(state, shift, marks) {
239
+ const { from, to } = state.selection.ranges[0];
240
+ const linePoint = state.lineBreak.codePointAt(0);
241
+ let pos = 0;
242
+ /** processing outer shifts */
243
+ const initialTextBefore = state.sliceDoc(from - shift, from);
244
+ let shiftBeforeOuter = 0;
245
+ pos = initialTextBefore.length - 1;
246
+ while (pos > -1) {
247
+ if (initialTextBefore.codePointAt(pos) === linePoint)
248
+ break;
249
+ shiftBeforeOuter++;
250
+ pos--;
251
+ }
252
+ const initialTextAfter = state.sliceDoc(to, to + shift);
253
+ let shiftAfterOuter = 0;
254
+ pos = 0;
255
+ while (pos < initialTextAfter.length) {
256
+ if (initialTextAfter.codePointAt(pos) === linePoint)
257
+ break;
258
+ shiftAfterOuter++;
259
+ pos++;
260
+ }
261
+ /** processing inner shifts */
262
+ const initialText = state.sliceDoc(from, to);
263
+ let shiftBeforeInner = 0;
264
+ pos = 0;
265
+ if (initialText.length > 1)
266
+ while (pos < initialText.length) {
267
+ // eslint-disable-next-line no-loop-func -- https://eslint.org/docs/latest/rules/no-loop-func#known-limitations
268
+ if (marks.some((mark) => mark === initialText.codePointAt(pos)))
269
+ shiftBeforeInner++;
270
+ else
271
+ break;
272
+ pos++;
273
+ }
274
+ const initialTextWithoutBeforeShift = initialText.substring(shiftBeforeInner + 1);
275
+ let shiftAfterInner = 0;
276
+ pos = initialTextWithoutBeforeShift.length - 1;
277
+ if (initialText.length > 1 || shiftBeforeInner > 0)
278
+ while (pos > -1) {
279
+ // eslint-disable-next-line no-loop-func -- https://eslint.org/docs/latest/rules/no-loop-func#known-limitations
280
+ if (marks.some((mark) => mark === initialTextWithoutBeforeShift.codePointAt(pos)))
281
+ shiftAfterInner++;
282
+ else
283
+ break;
284
+ pos--;
285
+ }
286
+ const text = state.sliceDoc(from - shiftBeforeOuter, to + shiftAfterOuter);
287
+ return {
288
+ from,
289
+ to,
290
+ shiftBeforeOuter,
291
+ shiftBeforeInner,
292
+ shiftAfterOuter,
293
+ shiftAfterInner,
294
+ text,
295
+ };
296
+ }
297
+
95
298
  /**
96
299
  * t.processingInstruction, t.meta - # () []
97
300
  * t.url, t.link - links
@@ -106,7 +309,10 @@ function getHighlightTemplate(config) {
106
309
  color: config.string,
107
310
  },
108
311
  { tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: config.function },
109
- { tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: config.constant },
312
+ {
313
+ tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)],
314
+ color: config.constant,
315
+ },
110
316
  { tag: [highlight.tags.definition(highlight.tags.name), highlight.tags.separator], color: config.variable },
111
317
  { tag: [highlight.tags.className], color: config.class },
112
318
  {
@@ -125,6 +331,8 @@ function getHighlightTemplate(config) {
125
331
  const CLASSES = {
126
332
  listCommon: "cm-list-common",
127
333
  code: "cm-code",
334
+ codeBlockLine: "cm-code-block-line",
335
+ codeBlock: "cm-code-block",
128
336
  codeButton: "cm-code-button",
129
337
  codeButtonSuccess: "cm-code-button-success",
130
338
  codeButtonFail: "cm-code-button-fail",
@@ -163,6 +371,7 @@ function getThemeTemplate(dark, config) {
163
371
  [`.${CLASSES.code}`]: {
164
372
  background: config.codeBackground,
165
373
  color: config.codeColor,
374
+ fontFamily: `${config.codeFontFamily} !important`,
166
375
  },
167
376
  [`.${CLASSES.horizontal}`]: {
168
377
  borderBottomColor: config.horizontalColor,
@@ -198,6 +407,12 @@ function getThemeTemplate(dark, config) {
198
407
  [`.${CLASSES.mention}`]: {
199
408
  color: config.mentionColor,
200
409
  },
410
+ [`.${CLASSES.codeBlockLine}`]: {
411
+ borderColor: config.codeBlockBorderColor,
412
+ },
413
+ [`.${CLASSES.codeBlock}`]: {
414
+ background: config.codeBlockBackground,
415
+ },
201
416
  }, { dark });
202
417
  }
203
418
 
@@ -224,15 +439,18 @@ const THEME_CONFIG$1 = {
224
439
  codeColor: "#DDDDDD",
225
440
  color: "#DDDDDD",
226
441
  fontFamily: "Montserrat",
442
+ codeFontFamily: "Consolas",
227
443
  horizontalColor: "#DDDDDD",
228
444
  linkColor: "#8A5CF5",
229
445
  mentionColor: "#8A5CF5",
230
446
  vimSelection: "#1A1919FF",
231
447
  vimSelectionFocused: "#2E4B4BFF",
448
+ codeBlockBorderColor: "#7b7e81",
449
+ codeBlockBackground: "#24292e",
232
450
  };
233
451
  function getDarkTheme({ dark }) {
234
- const highlightConfig = { ...HIGHLIGHT_CONFIG$1, ...(dark?.highlightConfig || {}) };
235
- const themeConfig = { ...THEME_CONFIG$1, ...(dark?.themeConfig || {}) };
452
+ const highlightConfig = { ...HIGHLIGHT_CONFIG$1, ...(dark?.highlightConfig ?? {}) };
453
+ const themeConfig = { ...THEME_CONFIG$1, ...(dark?.themeConfig ?? {}) };
236
454
  return [getThemeTemplate(true, themeConfig), getHighlightTemplate(highlightConfig)];
237
455
  }
238
456
 
@@ -259,15 +477,18 @@ const THEME_CONFIG = {
259
477
  codeColor: "#000000",
260
478
  color: "#000000",
261
479
  fontFamily: "Montserrat",
480
+ codeFontFamily: "Consolas",
262
481
  horizontalColor: "#000000",
263
482
  linkColor: "#8A5CF5",
264
483
  mentionColor: "#8A5CF5",
265
484
  vimSelection: "#d9d9d9",
266
485
  vimSelectionFocused: "#d7d4f0",
486
+ codeBlockBackground: "#e1e2e7",
487
+ codeBlockBorderColor: "##CCCCCDFF",
267
488
  };
268
489
  function getLightTheme({ light }) {
269
- const highlightConfig = { ...HIGHLIGHT_CONFIG, ...(light?.highlightConfig || {}) };
270
- const themeConfig = { ...THEME_CONFIG, ...(light?.themeConfig || {}) };
490
+ const highlightConfig = { ...HIGHLIGHT_CONFIG, ...(light?.highlightConfig ?? {}) };
491
+ const themeConfig = { ...THEME_CONFIG, ...(light?.themeConfig ?? {}) };
271
492
  return [getThemeTemplate(false, themeConfig), getHighlightTemplate(highlightConfig)];
272
493
  }
273
494
 
@@ -279,13 +500,135 @@ const initTheme = (options) => {
279
500
  return extensions;
280
501
  };
281
502
 
503
+ const BOLD_MARK_STAR = "*".codePointAt(0);
504
+ const BOLD_MARK_DASH = "_".codePointAt(0);
505
+ const SHIFT = 2;
506
+ const insertBoldMarker = ({ state, dispatch }) => {
507
+ const changes = [];
508
+ const { from, to } = state.selection.ranges[0];
509
+ if (from === to)
510
+ return true;
511
+ const { end, start, marked, originalText } = overlapMark({
512
+ marks: [BOLD_MARK_DASH, BOLD_MARK_STAR],
513
+ requireMatched: [SHIFT],
514
+ shift: SHIFT,
515
+ state,
516
+ });
517
+ if (marked) {
518
+ if (~start) {
519
+ changes.push({ from: start, to: start + SHIFT, insert: "" });
520
+ }
521
+ if (~end) {
522
+ changes.push({ from: end, to: end + SHIFT, insert: "" });
523
+ }
524
+ }
525
+ else {
526
+ const markedText = `**${originalText}**`;
527
+ changes.push({ from, to, insert: markedText });
528
+ }
529
+ saveDispatch(() => {
530
+ const startSelection = ~start ? start : from;
531
+ const endSelection = ~end ? end - (~start ? SHIFT : 0) : to - (~start ? SHIFT : 0);
532
+ dispatch(state.update({
533
+ changes,
534
+ selection: !marked
535
+ ? {
536
+ anchor: from + SHIFT,
537
+ head: to + SHIFT,
538
+ }
539
+ : {
540
+ anchor: startSelection,
541
+ head: endSelection,
542
+ },
543
+ }));
544
+ });
545
+ return true;
546
+ };
547
+ const boldKeymap = {
548
+ key: "Mod-b",
549
+ run: insertBoldMarker,
550
+ };
551
+
552
+ const ITALIC_MARK_STAR = "*".codePointAt(0);
553
+ const ITALIC_MARK_DASH = "_".codePointAt(0);
554
+ const SHIFT_COUPLE = 3;
555
+ const SHIFT_ALONE = 1;
556
+ const insertItalicMarker = ({ state, dispatch }) => {
557
+ const changes = [];
558
+ const { from, to } = state.selection.ranges[0];
559
+ if (from === to)
560
+ return true;
561
+ const { end, start, marked, originalText } = overlapMark({
562
+ marks: [ITALIC_MARK_STAR, ITALIC_MARK_DASH],
563
+ requireMatched: [SHIFT_ALONE, SHIFT_COUPLE],
564
+ shift: SHIFT_COUPLE,
565
+ state,
566
+ });
567
+ if (marked) {
568
+ if (~start) {
569
+ changes.push({ from: start, to: start + SHIFT_ALONE, insert: "" });
570
+ }
571
+ if (~end) {
572
+ changes.push({ from: end, to: end + SHIFT_ALONE, insert: "" });
573
+ }
574
+ }
575
+ else {
576
+ const markedText = `*${originalText}*`;
577
+ changes.push({ from, to, insert: markedText });
578
+ }
579
+ saveDispatch(() => {
580
+ const startSelection = ~start ? start : from;
581
+ const endSelection = ~end ? end - (~start ? SHIFT_ALONE : 0) : to - (~start ? SHIFT_ALONE : 0);
582
+ dispatch(state.update({
583
+ changes,
584
+ selection: !marked
585
+ ? {
586
+ anchor: from + SHIFT_ALONE,
587
+ head: to + SHIFT_ALONE,
588
+ }
589
+ : {
590
+ anchor: startSelection,
591
+ head: endSelection,
592
+ },
593
+ }));
594
+ });
595
+ return true;
596
+ };
597
+ const italicKeymap = {
598
+ key: "Mod-i",
599
+ run: insertItalicMarker,
600
+ };
601
+
602
+ const insertLinkWrapper = ({ state, dispatch }) => {
603
+ const changes = [];
604
+ const { from, to } = state.selection.ranges[0];
605
+ if (from === to)
606
+ return true;
607
+ const content = state.sliceDoc(from, to);
608
+ const wrapper = `[${content}]()`;
609
+ changes.push({ from, to, insert: wrapper });
610
+ saveDispatch(() => {
611
+ dispatch(state.update({
612
+ changes,
613
+ selection: {
614
+ anchor: to + 3,
615
+ },
616
+ }));
617
+ });
618
+ return true;
619
+ };
620
+ const linkKeymap = {
621
+ key: "Mod-k",
622
+ run: insertLinkWrapper,
623
+ };
624
+
282
625
  let vimMode = false;
283
626
  let theme = "light";
284
627
  const initKeyMaps = async ({ onEnter, onEscape, multiCursorMode, keyMaps, defaultKeyMaps, theme: initialTheme, vimMode: initialVimMode, dark, light, }) => {
285
628
  vimMode = initialVimMode;
286
629
  theme = initialTheme;
287
630
  /** tab */
288
- const keyBindings = [commands.indentWithTab];
631
+ const keyBindings = [commands.indentWithTab, boldKeymap, italicKeymap, linkKeymap];
289
632
  /** standard */
290
633
  keyBindings.push(...commands.standardKeymap.map((keyMap) => {
291
634
  if (keyMap.key === "Enter" && onEnter) {
@@ -328,15 +671,9 @@ const initKeyMaps = async ({ onEnter, onEscape, multiCursorMode, keyMaps, defaul
328
671
  view.dispatch({
329
672
  effects: ThemeCompartment.reconfigure(theme === "dark"
330
673
  ? getDarkTheme({
331
- dark,
332
- light,
333
- theme,
334
- })
674
+ dark})
335
675
  : getLightTheme({
336
- dark,
337
- light,
338
- theme,
339
- })),
676
+ light})),
340
677
  });
341
678
  });
342
679
  return true;
@@ -368,9 +705,9 @@ const initKeyMaps = async ({ onEnter, onEscape, multiCursorMode, keyMaps, defaul
368
705
 
369
706
  function getChangeEvent({ onChange }) {
370
707
  return onChange
371
- ? view.EditorView.updateListener.of((e) => {
372
- if (e.docChanged) {
373
- onChange(e);
708
+ ? view.EditorView.updateListener.of((event) => {
709
+ if (event.docChanged) {
710
+ onChange(event);
374
711
  }
375
712
  })
376
713
  : [];
@@ -378,11 +715,11 @@ function getChangeEvent({ onChange }) {
378
715
 
379
716
  function getFocusEvent({ onBlur, onFocus }) {
380
717
  return onFocus || onBlur
381
- ? view.EditorView.focusChangeEffect.of((e, focus) => {
718
+ ? view.EditorView.focusChangeEffect.of((event, focus) => {
382
719
  if (focus && onFocus)
383
- onFocus(e);
720
+ onFocus(event);
384
721
  else if (!focus && onBlur)
385
- onBlur(e);
722
+ onBlur(event);
386
723
  return null;
387
724
  })
388
725
  : [];
@@ -419,12 +756,12 @@ function styleInject(css, ref) {
419
756
  }
420
757
  }
421
758
 
422
- var css_248z = "._header_XFwV5{font-weight:700}._header_XFwV5._level_1_-KPph{font-size:2rem}._header_XFwV5._level_2_ecHlB{font-size:1.8rem}._header_XFwV5._level_3_SYcVr{font-size:1.6rem}._header_XFwV5._level_4_V3o5m{font-size:1.4rem}._header_XFwV5._level_5_I7eVk{font-size:1.3rem}._header_XFwV5._level_6_A3lbK{font-size:1.2rem}._bold_I8DT-{font-weight:700}._italic_72qBe{font-style:italic}._blockquote_Xq6O4{border-left:3px solid;margin-left:5px}._blockquote__inner_mjT0h{margin-left:1px;padding-left:5px;position:relative}._blockquote__inner_mjT0h:before{border-left:3px solid;content:\"\";height:140%;left:0;position:absolute;top:-3px}._blockquote__inner-deep_s6tNj{margin-left:5px}._strike-through_U64jP{text-decoration:line-through}._list_MHIjT._common_0GdDi{position:relative;visibility:hidden}._list_MHIjT._common_0GdDi:after{border-radius:100%;content:\"\";height:5px;left:0;position:absolute;top:50%;transform:translateY(-50%);visibility:visible;width:5px}._link_7U9wl{text-decoration:none;text-decoration:underline}._link__label_dHGGf{font-size:12px;position:relative;top:-4px}._image_KmBM8{display:inline-flex}._code__line_m3IiO{padding:5px;position:relative}._code__line_m3IiO,._code__single_hbMte{font-family:monospace}._code__button_WwYE-{background-color:transparent;border:none;border-radius:4px;box-shadow:none;cursor:pointer;min-width:30px;outline:none;padding:4px 10px;position:absolute;right:5px;top:5px;transition:all .3s ease;z-index:1}._code__button_WwYE-._pending_fgHgD:before{animation:_loading-btn--fade-in_8z5an .33s ease,_loading-btn--rotation_QaopN .66s linear 0s infinite;border:2px solid hsla(0,0%,100%,.33);border-radius:50%;border-top-color:#000;content:\"\";display:inline-block;height:10.5px;left:50%;position:absolute;top:50%;width:10.5px}._code__button_WwYE-._success_kUPnO:after{animation:_loading-btn--fade-in_8z5an .6s ease;border-color:currentcolor;border-style:solid;border-width:0 0 1px 1px;content:\"\";display:inline-block;height:7px;left:50%;position:absolute;top:50%;transform:translate(-50%,-75%) rotate(-45deg);width:11px}._code__button_WwYE-._fail_cOpap:after,._code__button_WwYE-._fail_cOpap:before{content:\" \";height:13px;left:50%;position:absolute;top:50%;width:1px}._code__button_WwYE-._fail_cOpap:before{transform:translate(-50%,-50%) rotate(45deg)}._code__button_WwYE-._fail_cOpap:after{transform:translate(-50%,-50%) rotate(-45deg)}@keyframes _loading-btn--fade-in_8z5an{0%{opacity:0}to{opacity:1}}@keyframes _loading-btn--rotation_QaopN{0%{transform:translate(-50%,-50%) rotate(0deg)}to{transform:translate(-50%,-50%) rotate(1turn)}}._code__span_iSCmj{opacity:1;transition:opacity .3s ease}._code__span_iSCmj._hide_uqpax{opacity:0}._horizontal_J1jU-{border-bottom:1px solid;margin:0 5px;position:relative;width:calc(100% - 10px)}._todo_m6MIP{align-items:flex-end;display:inline-flex;height:100%;padding-left:3px;padding-right:3px}._todo_m6MIP>input{margin:0}._todo__checked_kemjy{text-decoration:line-through}._mention_cpzik{font-weight:700}";
423
- const styles = {"header":"_header_XFwV5","level_1":"_level_1_-KPph","level_2":"_level_2_ecHlB","level_3":"_level_3_SYcVr","level_4":"_level_4_V3o5m","level_5":"_level_5_I7eVk","level_6":"_level_6_A3lbK","bold":"_bold_I8DT-","italic":"_italic_72qBe","blockquote":"_blockquote_Xq6O4","blockquote__inner":"_blockquote__inner_mjT0h","blockquote__inner-deep":"_blockquote__inner-deep_s6tNj","strike-through":"_strike-through_U64jP","list":"_list_MHIjT","common":"_common_0GdDi","link":"_link_7U9wl","link__label":"_link__label_dHGGf","image":"_image_KmBM8","code__line":"_code__line_m3IiO","code__single":"_code__single_hbMte","code__button":"_code__button_WwYE-","pending":"_pending_fgHgD","loading-btn--fade-in":"_loading-btn--fade-in_8z5an","loading-btn--rotation":"_loading-btn--rotation_QaopN","success":"_success_kUPnO","fail":"_fail_cOpap","code__span":"_code__span_iSCmj","hide":"_hide_uqpax","horizontal":"_horizontal_J1jU-","todo":"_todo_m6MIP","todo__checked":"_todo__checked_kemjy","mention":"_mention_cpzik"};
759
+ var css_248z = "._header_XFwV5{font-weight:700}._header_XFwV5._level_1_-KPph{font-size:2em}._header_XFwV5._level_2_ecHlB{font-size:1.8em}._header_XFwV5._level_3_SYcVr{font-size:1.6em}._header_XFwV5._level_4_V3o5m{font-size:1.4em}._header_XFwV5._level_5_I7eVk{font-size:1.3em}._header_XFwV5._level_6_A3lbK{font-size:1.2em}._bold_I8DT-{font-weight:700}._italic_72qBe{font-style:italic}._blockquote_Xq6O4{border-left:3px solid;margin-left:5px}._blockquote__inner_mjT0h{margin-left:1px;padding-left:5px;position:relative}._blockquote__inner_mjT0h:before{border-left:3px solid;content:\"\";height:140%;left:0;position:absolute;top:-3px}._blockquote__inner-deep_s6tNj{margin-left:5px}._strike-through_U64jP{text-decoration:line-through}._list_MHIjT._common_0GdDi{position:relative;visibility:hidden}._list_MHIjT._common_0GdDi:after{border-radius:100%;content:\"\";height:5px;left:0;position:absolute;top:50%;transform:translateY(-50%);visibility:visible;width:5px}._link_7U9wl{text-decoration:none;text-decoration:underline}._link__label_dHGGf{font-size:12px;position:relative;top:-4px}._image_KmBM8{display:inline-flex}._code__line_m3IiO{padding:5px;position:relative}._code__button_WwYE-{background-color:transparent;border:none;border-radius:4px;box-shadow:none;cursor:pointer;min-width:30px;outline:none;padding:4px 10px;position:absolute;right:5px;top:5px;transition:all .3s ease;z-index:1}._code__button_WwYE-._pending_fgHgD:before{animation:_loading-btn--fade-in_8z5an .33s ease,_loading-btn--rotation_QaopN .66s linear 0s infinite;border:2px solid hsla(0,0%,100%,.33);border-radius:50%;border-top-color:#000;content:\"\";display:inline-block;height:10.5px;left:50%;position:absolute;top:50%;width:10.5px}._code__button_WwYE-._success_kUPnO:after{animation:_loading-btn--fade-in_8z5an .6s ease;border-color:currentcolor;border-style:solid;border-width:0 0 1px 1px;content:\"\";display:inline-block;height:7px;left:50%;position:absolute;top:50%;transform:translate(-50%,-75%) rotate(-45deg);width:11px}._code__button_WwYE-._fail_cOpap:after,._code__button_WwYE-._fail_cOpap:before{content:\" \";height:13px;left:50%;position:absolute;top:50%;width:1px}._code__button_WwYE-._fail_cOpap:before{transform:translate(-50%,-50%) rotate(45deg)}._code__button_WwYE-._fail_cOpap:after{transform:translate(-50%,-50%) rotate(-45deg)}@keyframes _loading-btn--fade-in_8z5an{0%{opacity:0}to{opacity:1}}@keyframes _loading-btn--rotation_QaopN{0%{transform:translate(-50%,-50%) rotate(0deg)}to{transform:translate(-50%,-50%) rotate(1turn)}}._code__span_iSCmj{opacity:1;transition:opacity .3s ease}._code__span_iSCmj._hide_uqpax{opacity:0}._code__block_JehA4{padding:1px 5px}._code__block_line_U7lcQ{border-left:1px solid;margin-left:5px}._horizontal_J1jU-{border-bottom:1px solid;margin:0 5px;position:relative;width:calc(100% - 10px)}._todo_m6MIP{align-items:flex-end;display:inline-flex;height:100%;padding-left:3px;padding-right:3px}._todo_m6MIP>input{margin:0}._todo__checked_kemjy{text-decoration:line-through}._mention_cpzik{font-weight:700}";
760
+ const styles = {"header":"_header_XFwV5","level_1":"_level_1_-KPph","level_2":"_level_2_ecHlB","level_3":"_level_3_SYcVr","level_4":"_level_4_V3o5m","level_5":"_level_5_I7eVk","level_6":"_level_6_A3lbK","bold":"_bold_I8DT-","italic":"_italic_72qBe","blockquote":"_blockquote_Xq6O4","blockquote__inner":"_blockquote__inner_mjT0h","blockquote__inner-deep":"_blockquote__inner-deep_s6tNj","strike-through":"_strike-through_U64jP","list":"_list_MHIjT","common":"_common_0GdDi","link":"_link_7U9wl","link__label":"_link__label_dHGGf","image":"_image_KmBM8","code__line":"_code__line_m3IiO","code__button":"_code__button_WwYE-","pending":"_pending_fgHgD","loading-btn--fade-in":"_loading-btn--fade-in_8z5an","loading-btn--rotation":"_loading-btn--rotation_QaopN","success":"_success_kUPnO","fail":"_fail_cOpap","code__span":"_code__span_iSCmj","hide":"_hide_uqpax","code__block":"_code__block_JehA4","code__block_line":"_code__block_line_U7lcQ","horizontal":"_horizontal_J1jU-","todo":"_todo_m6MIP","todo__checked":"_todo__checked_kemjy","mention":"_mention_cpzik"};
424
761
  styleInject(css_248z);
425
762
 
426
763
  const NAME_OF_BLOCKQUOTE_MARK = "QuoteMark";
427
- const CODE_OF_SPACE$1 = 32;
764
+ const CODE_OF_SPACE$2 = " ".codePointAt(0);
428
765
  const CODE_OF_BLOCKQUOTE_MARK = 62; // >
429
766
 
430
767
  class BlockquoteWidget extends view.WidgetType {
@@ -456,7 +793,7 @@ function getBlockquoteDecorations({ decorations, node, view }) {
456
793
  while (pos >= 0) {
457
794
  pos--;
458
795
  const currentCode = content.charCodeAt(pos);
459
- if (currentCode === CODE_OF_SPACE$1)
796
+ if (currentCode === CODE_OF_SPACE$2)
460
797
  continue;
461
798
  if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
462
799
  if (!isHasMark) {
@@ -492,7 +829,7 @@ function getBlockquoteSelectionDecorations({ decorations, node, view, forceActiv
492
829
  while (pos >= 0) {
493
830
  pos--;
494
831
  const currentCode = content.charCodeAt(pos);
495
- if (currentCode === CODE_OF_SPACE$1)
832
+ if (currentCode === CODE_OF_SPACE$2)
496
833
  continue;
497
834
  if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
498
835
  if (!isHasMark) {
@@ -529,7 +866,7 @@ const blockquoteDecorationPlugin = {
529
866
  };
530
867
 
531
868
  const NAME_OF_BOLD = "StrongEmphasis";
532
- const LIST_OF_BOLD_MARKS = new Set([95, 42]); // _ *
869
+ const LIST_OF_BOLD_MARKS = new Set(["_".codePointAt(0), "*".codePointAt(0)]);
533
870
 
534
871
  function getBoldDecorations({ decorations, node, view }) {
535
872
  if (node.name !== NAME_OF_BOLD) {
@@ -566,6 +903,8 @@ const boldDecorationPlugin = {
566
903
 
567
904
  const NAME_OF_FENCED_CODE = "FencedCode";
568
905
  const NAME_OF_INLINE_CODE = "InlineCode";
906
+ const NAME_OF_BLOCK_CODE = "CodeBlock";
907
+ const CODE_OF_SPACE$1 = " ".codePointAt(0);
569
908
  const CODE_OF_CODE_MARK = 96; // `
570
909
 
571
910
  class CodeWidget extends view.WidgetType {
@@ -711,7 +1050,7 @@ function getCodeSelectionDecorations({ decorations, node, view, forceActive, })
711
1050
  }
712
1051
  else {
713
1052
  decorations.push(getMarkDecoration({
714
- style: clsx(styles.code__single, CLASSES.code),
1053
+ style: clsx(CLASSES.code),
715
1054
  range: [node.from, node.to],
716
1055
  }));
717
1056
  }
@@ -731,8 +1070,39 @@ function getCodeSelectionDecorations({ decorations, node, view, forceActive, })
731
1070
  decorations.push(getHideDecoration({ range: [endMarkPosition.from, endMarkPosition.to] }));
732
1071
  }
733
1072
  }
1073
+ function getCodeBlockDecorations({ decorations, node, view }) {
1074
+ if (node.name !== NAME_OF_BLOCK_CODE)
1075
+ return;
1076
+ const lines = view.viewportLineBlocks.filter((line) => {
1077
+ const isOverlap = isRangeOverlap([node.from, node.to], [line.from, line.to]);
1078
+ return isOverlap;
1079
+ });
1080
+ lines.forEach((line) => {
1081
+ const content = view.state.sliceDoc(line.from, line.to);
1082
+ let startContent = 0;
1083
+ let pos = 0;
1084
+ while (pos < content.length) {
1085
+ if (content.codePointAt(pos) === CODE_OF_SPACE$1) {
1086
+ pos++;
1087
+ }
1088
+ else {
1089
+ startContent = pos;
1090
+ break;
1091
+ }
1092
+ }
1093
+ decorations.push(getMarkDecoration({
1094
+ range: [line.from + startContent, line.to],
1095
+ style: clsx(styles.code__block, CLASSES.codeBlock),
1096
+ }));
1097
+ decorations.push(getLineDecoration({
1098
+ range: [line.from],
1099
+ style: clsx(styles.code__block_line, CLASSES.codeBlockLine),
1100
+ }));
1101
+ });
1102
+ }
734
1103
  const codeDecorationPlugin = {
735
1104
  selectionDecorations: [getCodeSelectionDecorations],
1105
+ decorations: [getCodeBlockDecorations],
736
1106
  };
737
1107
 
738
1108
  const NAME_OF_HEADER = "ATXHeading";
@@ -843,6 +1213,7 @@ const CODE_OF_END_IMAGE_TEXT = 93; // ]
843
1213
  const CODE_OF_START_IMAGE_URL = 40; // (
844
1214
  const CODE_OF_END_IMAGE_URL = 41; // )
845
1215
 
1216
+ /* eslint-disable max-params */
846
1217
  const IMAGE_NODES = {};
847
1218
  const INTERVAL_DELAY = 10000;
848
1219
  const EXISTING_WIDGETS = new Set();
@@ -889,7 +1260,7 @@ class ImageWidget extends view.WidgetType {
889
1260
  this.from = widget.from;
890
1261
  this.to = widget.to;
891
1262
  this.registerListeners(image);
892
- IMAGE_NODES[this.key] = image;
1263
+ IMAGE_NODES[this.key] = container;
893
1264
  EXISTING_WIDGETS.add(this.key);
894
1265
  return true;
895
1266
  }
@@ -995,8 +1366,30 @@ function isCorrectNode$1(text, link, node) {
995
1366
  textContent.includes(text));
996
1367
  }
997
1368
  function selectLink$1({ link, node, selection, start }) {
998
- const startPosition = start ?? (node.textContent?.indexOf?.(link) || 0);
1369
+ const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;
999
1370
  const endPosition = startPosition + link.length;
1371
+ if (startPosition === 0 && endPosition === 0) {
1372
+ const content = node.textContent;
1373
+ if (!content)
1374
+ return;
1375
+ let startPosition = 0;
1376
+ let pos = 0;
1377
+ while (pos < content.length) {
1378
+ if (content.codePointAt(pos) !== CODE_OF_START_IMAGE_URL) {
1379
+ pos++;
1380
+ }
1381
+ else {
1382
+ startPosition = pos + 1;
1383
+ break;
1384
+ }
1385
+ }
1386
+ const range = document.createRange();
1387
+ range.setStart(node, startPosition);
1388
+ range.collapse(true);
1389
+ selection.removeAllRanges();
1390
+ selection.addRange(range);
1391
+ return;
1392
+ }
1000
1393
  const range = document.createRange();
1001
1394
  range.setStart(node, startPosition);
1002
1395
  range.setEnd(node, endPosition);
@@ -1134,7 +1527,7 @@ function getItalicSelectionDecorations({ decorations, node, view, forceActive, s
1134
1527
  if (node.name !== NAME_OF_ITALIC) {
1135
1528
  return;
1136
1529
  }
1137
- if (checkIsSeveralEmphasis({ decorations, node, view, forceActive, settings })) {
1530
+ if (checkIsSeveralEmphasis({ node, view})) {
1138
1531
  return void splitEmphasis({ decorations, node, view, forceActive, settings });
1139
1532
  }
1140
1533
  let step = 1;
@@ -1217,6 +1610,7 @@ function getLinkLabelSelectionDecoration({ decorations, node, view, forceActive,
1217
1610
  }
1218
1611
  }
1219
1612
 
1613
+ /* eslint-disable max-params */
1220
1614
  const LINK_NODES = {};
1221
1615
  class LinkWidget extends view.WidgetType {
1222
1616
  text;
@@ -1273,7 +1667,9 @@ class LinkWidget extends view.WidgetType {
1273
1667
  anchor.clearListeners?.();
1274
1668
  const abortController = new AbortController();
1275
1669
  anchor.addEventListener("mousedown", (event) => handleClick(this.view, this.text, this.link, this.key, event), { signal: abortController.signal });
1276
- anchor.addEventListener("click", (e) => e.preventDefault(), { signal: abortController.signal });
1670
+ anchor.addEventListener("click", (event) => event.preventDefault(), {
1671
+ signal: abortController.signal,
1672
+ });
1277
1673
  anchor.clearListeners = () => {
1278
1674
  abortController.abort();
1279
1675
  };
@@ -1323,8 +1719,30 @@ function isCorrectNode(text, link, node) {
1323
1719
  textContent.includes(text));
1324
1720
  }
1325
1721
  function selectLink({ link, node, selection, start }) {
1326
- const startPosition = start ?? (node.textContent?.indexOf?.(link) || 0);
1722
+ const startPosition = start ?? node.textContent?.indexOf?.(link) ?? 0;
1327
1723
  const endPosition = startPosition + link.length;
1724
+ if (startPosition === 0 && endPosition === 0) {
1725
+ const content = node.textContent;
1726
+ if (!content)
1727
+ return;
1728
+ let startPosition = 0;
1729
+ let pos = 0;
1730
+ while (pos < content.length) {
1731
+ if (content.codePointAt(pos) !== CODE_OF_START_LINK_URL) {
1732
+ pos++;
1733
+ }
1734
+ else {
1735
+ startPosition = pos + 1;
1736
+ break;
1737
+ }
1738
+ }
1739
+ const range = document.createRange();
1740
+ range.setStart(node, startPosition);
1741
+ range.collapse(true);
1742
+ selection.removeAllRanges();
1743
+ selection.addRange(range);
1744
+ return;
1745
+ }
1328
1746
  const range = document.createRange();
1329
1747
  range.setStart(node, startPosition);
1330
1748
  range.setEnd(node, endPosition);
@@ -1404,7 +1822,7 @@ function getLinkSelectionDecorations({ decorations, node, view, forceActive, set
1404
1822
  urlCoordinates.to = pos;
1405
1823
  }
1406
1824
  if (urlCoordinates.from === -1 || urlCoordinates.to === -1)
1407
- return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view, settings });
1825
+ return void getLinkLabelSelectionDecoration({ decorations, forceActive, node, view});
1408
1826
  const text = content.substring(textCoordinates.from, textCoordinates.to);
1409
1827
  const url = content.substring(urlCoordinates.from, urlCoordinates.to);
1410
1828
  const openedLink = view.state.field(markdownState).openedLink;
@@ -1510,7 +1928,7 @@ function getListSelectionDecorations({ decorations, node, view, forceActive, })
1510
1928
  return;
1511
1929
  }
1512
1930
  const content = view.state.doc.sliceString(node.from, node.to);
1513
- const lastCodePoint = content.codePointAt(content.length - 1) || 0;
1931
+ const lastCodePoint = content.codePointAt(content.length - 1) ?? 0;
1514
1932
  if (!LIST_OF_LIST_MARKS.has(lastCodePoint) && CODE_OF_ORDERED_LIST_MARK !== lastCodePoint) {
1515
1933
  return;
1516
1934
  }
@@ -1536,8 +1954,9 @@ const listDecorationPlugin = {
1536
1954
  selectionDecorations: [getListSelectionDecorations],
1537
1955
  };
1538
1956
 
1539
- const CODE_OF_START_MENTION = 64; // @
1540
- const CODE_OF_SPACE = 32;
1957
+ const CODE_OF_START_MENTION = "@".codePointAt(0); // @
1958
+ const CODE_OF_SPACE = " ".codePointAt(0);
1959
+ const CODE_OF_LINE_BREAK = "\n".codePointAt(0);
1541
1960
  const NAME_OF_MENTION = "Mention";
1542
1961
 
1543
1962
  function getMentionDecorations({ decorations, node }) {
@@ -1649,7 +2068,7 @@ function getTodoSelectionDecoration({ decorations, node, view, forceActive, }) {
1649
2068
  const prevSibling = node.node.prevSibling;
1650
2069
  if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK)
1651
2070
  return;
1652
- const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) || 0);
2071
+ const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) ?? 0);
1653
2072
  if (forceActive ||
1654
2073
  !view.hasFocus ||
1655
2074
  !isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])) {
@@ -1731,10 +2150,10 @@ function createDecorationsGetter(settings) {
1731
2150
  return;
1732
2151
  /** Decoration by change content */
1733
2152
  if (processDecorations)
1734
- decorationFunctions.forEach((f) => f({ decorations, node, view: view$1, settings }));
2153
+ decorationFunctions.forEach((funk) => funk({ decorations, node, view: view$1, settings }));
1735
2154
  /** Decoration by selection content */
1736
2155
  if (processSelectionDecorations)
1737
- selectionDecorationFunctions.forEach((f) => f({
2156
+ selectionDecorationFunctions.forEach((funk) => funk({
1738
2157
  decorations: selectionDecorations,
1739
2158
  node,
1740
2159
  view: view$1,
@@ -1795,7 +2214,7 @@ const markdownDecorationPlugin = (settings) => {
1795
2214
  });
1796
2215
  };
1797
2216
 
1798
- async function InitSettings({ readonly, vimMode, }) {
2217
+ async function initSettings({ readonly, vimMode, }) {
1799
2218
  let vimExtension = [];
1800
2219
  if (vimMode) {
1801
2220
  const { vim } = await import('@replit/codemirror-vim');
@@ -1808,10 +2227,10 @@ async function InitSettings({ readonly, vimMode, }) {
1808
2227
  ];
1809
2228
  }
1810
2229
 
1811
- const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, readonly = true, vimMode = false, multiCursorText, provider, theme = "light", dark, light, languages, keyMaps, defaultKeyMaps, imageSrcGetter, }) => {
2230
+ const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, readonly = true, vimMode = false, multiCursorText, provider, theme = "light", dark, light, languages, keyMaps, defaultKeyMaps, imageSrcGetter, autoCompleteTagOptions, autoCompleteConfig, }) => {
1812
2231
  const multiCursorMode = Boolean(multiCursorText && provider);
1813
2232
  const asyncPlugins = await Promise.all([
1814
- InitSettings({ readonly, vimMode }),
2233
+ initSettings({ readonly, vimMode }),
1815
2234
  initKeyMaps({
1816
2235
  onEnter,
1817
2236
  onEscape,
@@ -1824,10 +2243,11 @@ const initExtensions = async ({ onBlur, onChange, onFocus, onEnter, onEscape, re
1824
2243
  light,
1825
2244
  }),
1826
2245
  new Promise((resolve) => {
1827
- void Promise.resolve().then(() => require('./index-DU8JMAfc.js')).then(({ initMarkdown }) => {
2246
+ void Promise.resolve().then(() => require('./index-Ne5xJkxS.js')).then(({ initMarkdown }) => {
1828
2247
  resolve(initMarkdown({ languages, imageSrcGetter }));
1829
2248
  });
1830
2249
  }),
2250
+ initAutoComplete({ autoCompleteConfig, autoCompleteTagOptions }),
1831
2251
  ]);
1832
2252
  const extensions = [
1833
2253
  ...asyncPlugins,
@@ -1848,8 +2268,7 @@ async function initEditorProvider({ roomId, url, userName = "Anonymous", userCol
1848
2268
  const { WebsocketProvider } = await import('y-websocket');
1849
2269
  const multiCursorDocument = new Doc();
1850
2270
  const multiCursorText = multiCursorDocument.getText(roomId);
1851
- if (!userColor || !userColor.startsWith("#")) {
1852
- // eslint-disable-next-line no-console
2271
+ if (!userColor?.startsWith?.("#")) {
1853
2272
  console.warn("user color must be hex!");
1854
2273
  userColor = "#30bced";
1855
2274
  }
@@ -1864,7 +2283,7 @@ async function initEditorProvider({ roomId, url, userName = "Anonymous", userCol
1864
2283
  provider.on("status", (event) => {
1865
2284
  onStartProvider(event?.status);
1866
2285
  });
1867
- if (provider && multiCursorText)
2286
+ if (provider)
1868
2287
  provider.on("sync", (isSynced) => {
1869
2288
  if (isSynced && !multiCursorText.length && initialText) {
1870
2289
  multiCursorText.insert(0, initialText);
@@ -1892,7 +2311,7 @@ async function initEditor({ multiCursor, root, initialText, ...rest }) {
1892
2311
  }
1893
2312
  const state = await initEditorState({
1894
2313
  ...rest,
1895
- text: initialText || "",
2314
+ text: initialText ?? "",
1896
2315
  provider,
1897
2316
  multiCursorText,
1898
2317
  });
@@ -1978,14 +2397,10 @@ class Editor {
1978
2397
  effects: ThemeCompartment.reconfigure(theme === "dark"
1979
2398
  ? getDarkTheme({
1980
2399
  dark: this.arguments.dark,
1981
- light: this.arguments.light,
1982
- theme,
1983
- })
2400
+ light: this.arguments.light})
1984
2401
  : getLightTheme({
1985
2402
  dark: this.arguments.dark,
1986
- light: this.arguments.light,
1987
- theme,
1988
- })),
2403
+ light: this.arguments.light})),
1989
2404
  });
1990
2405
  });
1991
2406
  };
@@ -2019,10 +2434,11 @@ class Editor {
2019
2434
  };
2020
2435
  }
2021
2436
 
2437
+ exports.CODE_OF_LINE_BREAK = CODE_OF_LINE_BREAK;
2022
2438
  exports.CODE_OF_SPACE = CODE_OF_SPACE;
2023
2439
  exports.CODE_OF_START_MENTION = CODE_OF_START_MENTION;
2024
2440
  exports.Editor = Editor;
2025
2441
  exports.NAME_OF_MENTION = NAME_OF_MENTION;
2026
2442
  exports.markdownDecorationPlugin = markdownDecorationPlugin;
2027
2443
  exports.markdownState = markdownState;
2028
- //# sourceMappingURL=index-BgxbH3r2.js.map
2444
+ //# sourceMappingURL=index-Df0WnJ4c.js.map