@krainovsd/markdown-editor 0.0.3 → 0.1.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 (231) hide show
  1. package/README.md +21 -1
  2. package/lib/cjs/index-Byjf17iv.js +501 -0
  3. package/lib/cjs/index-Byjf17iv.js.map +1 -0
  4. package/lib/cjs/index-lPo-3QDL.js +1374 -0
  5. package/lib/cjs/index-lPo-3QDL.js.map +1 -0
  6. package/lib/cjs/index.js +15 -0
  7. package/lib/cjs/index.js.map +1 -0
  8. package/lib/esm/extensions/compartments/index.js +8 -0
  9. package/lib/esm/extensions/compartments/index.js.map +1 -0
  10. package/lib/esm/extensions/init-extensions.js +45 -0
  11. package/lib/esm/extensions/init-extensions.js.map +1 -0
  12. package/lib/esm/extensions/keymaps/init-key-map.js +91 -0
  13. package/lib/esm/extensions/keymaps/init-key-map.js.map +1 -0
  14. package/lib/esm/extensions/listeners/get-change-event.js +14 -0
  15. package/lib/esm/extensions/listeners/get-change-event.js.map +1 -0
  16. package/lib/esm/extensions/listeners/get-focus-event.js +16 -0
  17. package/lib/esm/extensions/listeners/get-focus-event.js.map +1 -0
  18. package/lib/esm/extensions/listeners/init-listeners.js +9 -0
  19. package/lib/esm/extensions/listeners/init-listeners.js.map +1 -0
  20. package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js +6 -0
  21. package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js.map +1 -0
  22. package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js +99 -0
  23. package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js.map +1 -0
  24. package/lib/esm/extensions/markdown/blockquote/blockquote-widget.js +25 -0
  25. package/lib/esm/extensions/markdown/blockquote/blockquote-widget.js.map +1 -0
  26. package/lib/esm/extensions/markdown/bold/bold-constants.js +5 -0
  27. package/lib/esm/extensions/markdown/bold/bold-constants.js.map +1 -0
  28. package/lib/esm/extensions/markdown/bold/bold-decoration.js +41 -0
  29. package/lib/esm/extensions/markdown/bold/bold-decoration.js.map +1 -0
  30. package/lib/esm/extensions/markdown/code/code-constants.js +6 -0
  31. package/lib/esm/extensions/markdown/code/code-constants.js.map +1 -0
  32. package/lib/esm/extensions/markdown/code/code-decoration.js +109 -0
  33. package/lib/esm/extensions/markdown/code/code-decoration.js.map +1 -0
  34. package/lib/esm/extensions/markdown/code/code-widget.js +83 -0
  35. package/lib/esm/extensions/markdown/code/code-widget.js.map +1 -0
  36. package/lib/esm/extensions/markdown/header/header-constants.js +6 -0
  37. package/lib/esm/extensions/markdown/header/header-constants.js.map +1 -0
  38. package/lib/esm/extensions/markdown/header/header-decoration.js +64 -0
  39. package/lib/esm/extensions/markdown/header/header-decoration.js.map +1 -0
  40. package/lib/esm/extensions/markdown/horizontal/horizontal-constants.js +4 -0
  41. package/lib/esm/extensions/markdown/horizontal/horizontal-constants.js.map +1 -0
  42. package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js +31 -0
  43. package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js.map +1 -0
  44. package/lib/esm/extensions/markdown/image/image-constants.js +8 -0
  45. package/lib/esm/extensions/markdown/image/image-constants.js.map +1 -0
  46. package/lib/esm/extensions/markdown/image/image-decoration.js +75 -0
  47. package/lib/esm/extensions/markdown/image/image-decoration.js.map +1 -0
  48. package/lib/esm/extensions/markdown/image/image-widget.js +184 -0
  49. package/lib/esm/extensions/markdown/image/image-widget.js.map +1 -0
  50. package/lib/esm/extensions/markdown/index.js +2 -0
  51. package/lib/esm/extensions/markdown/index.js.map +1 -0
  52. package/lib/esm/extensions/markdown/init-markdown.js +18 -0
  53. package/lib/esm/extensions/markdown/init-markdown.js.map +1 -0
  54. package/lib/esm/extensions/markdown/italic/italic-constants.js +5 -0
  55. package/lib/esm/extensions/markdown/italic/italic-constants.js.map +1 -0
  56. package/lib/esm/extensions/markdown/italic/italic-decoration.js +77 -0
  57. package/lib/esm/extensions/markdown/italic/italic-decoration.js.map +1 -0
  58. package/lib/esm/extensions/markdown/link/auto-link-decoration.js +24 -0
  59. package/lib/esm/extensions/markdown/link/auto-link-decoration.js.map +1 -0
  60. package/lib/esm/extensions/markdown/link/link-constants.js +10 -0
  61. package/lib/esm/extensions/markdown/link/link-constants.js.map +1 -0
  62. package/lib/esm/extensions/markdown/link/link-decoration.js +51 -0
  63. package/lib/esm/extensions/markdown/link/link-decoration.js.map +1 -0
  64. package/lib/esm/extensions/markdown/link/link-label-decoration.js +22 -0
  65. package/lib/esm/extensions/markdown/link/link-label-decoration.js.map +1 -0
  66. package/lib/esm/extensions/markdown/link/link-widget.js +144 -0
  67. package/lib/esm/extensions/markdown/link/link-widget.js.map +1 -0
  68. package/lib/esm/extensions/markdown/list/list-constants.js +7 -0
  69. package/lib/esm/extensions/markdown/list/list-constants.js.map +1 -0
  70. package/lib/esm/extensions/markdown/list/list-decoration.js +38 -0
  71. package/lib/esm/extensions/markdown/list/list-decoration.js.map +1 -0
  72. package/lib/esm/extensions/markdown/list/list-widget.js +33 -0
  73. package/lib/esm/extensions/markdown/list/list-widget.js.map +1 -0
  74. package/lib/esm/extensions/markdown/markdown-decoration.js +105 -0
  75. package/lib/esm/extensions/markdown/markdown-decoration.js.map +1 -0
  76. package/lib/esm/extensions/markdown/markdown-parser.js +6 -0
  77. package/lib/esm/extensions/markdown/markdown-parser.js.map +1 -0
  78. package/lib/esm/extensions/markdown/mention/mention-constants.js +6 -0
  79. package/lib/esm/extensions/markdown/mention/mention-constants.js.map +1 -0
  80. package/lib/esm/extensions/markdown/mention/mention-decoration.js +37 -0
  81. package/lib/esm/extensions/markdown/mention/mention-decoration.js.map +1 -0
  82. package/lib/esm/extensions/markdown/mention/mention-parser.js +25 -0
  83. package/lib/esm/extensions/markdown/mention/mention-parser.js.map +1 -0
  84. package/lib/esm/extensions/markdown/strike-through/strike-through-constants.js +4 -0
  85. package/lib/esm/extensions/markdown/strike-through/strike-through-constants.js.map +1 -0
  86. package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js +32 -0
  87. package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js.map +1 -0
  88. package/lib/esm/extensions/markdown/styles.module.scss.js +8 -0
  89. package/lib/esm/extensions/markdown/styles.module.scss.js.map +1 -0
  90. package/lib/esm/extensions/markdown/todo/todo-constants.js +6 -0
  91. package/lib/esm/extensions/markdown/todo/todo-constants.js.map +1 -0
  92. package/lib/esm/extensions/markdown/todo/todo-decoration.js +35 -0
  93. package/lib/esm/extensions/markdown/todo/todo-decoration.js.map +1 -0
  94. package/lib/esm/extensions/markdown/todo/todo-widget.js +51 -0
  95. package/lib/esm/extensions/markdown/todo/todo-widget.js.map +1 -0
  96. package/lib/esm/extensions/settings/init-settings.js +19 -0
  97. package/lib/esm/extensions/settings/init-settings.js.map +1 -0
  98. package/lib/esm/extensions/theme/init-theme.js +15 -0
  99. package/lib/esm/extensions/theme/init-theme.js.map +1 -0
  100. package/lib/esm/extensions/theme/theme-constants.js +17 -0
  101. package/lib/esm/extensions/theme/theme-constants.js.map +1 -0
  102. package/lib/esm/extensions/theme/themes/get-dark-theme.js +40 -0
  103. package/lib/esm/extensions/theme/themes/get-dark-theme.js.map +1 -0
  104. package/lib/esm/extensions/theme/themes/get-highlight-template.js +35 -0
  105. package/lib/esm/extensions/theme/themes/get-highlight-template.js.map +1 -0
  106. package/lib/esm/extensions/theme/themes/get-light-theme.js +40 -0
  107. package/lib/esm/extensions/theme/themes/get-light-theme.js.map +1 -0
  108. package/lib/esm/extensions/theme/themes/get-theme-template.js +69 -0
  109. package/lib/esm/extensions/theme/themes/get-theme-template.js.map +1 -0
  110. package/lib/esm/index.js +1 -1
  111. package/lib/esm/index.js.map +1 -1
  112. package/lib/esm/lib/utils/copy-to-clipboard.js +35 -0
  113. package/lib/esm/lib/utils/copy-to-clipboard.js.map +1 -0
  114. package/lib/esm/lib/utils/get-decoration.js +24 -0
  115. package/lib/esm/lib/utils/get-decoration.js.map +1 -0
  116. package/lib/esm/lib/utils/is-in-range.js +8 -0
  117. package/lib/esm/lib/utils/is-in-range.js.map +1 -0
  118. package/lib/esm/lib/utils/is-range-overlap.js +6 -0
  119. package/lib/esm/lib/utils/is-range-overlap.js.map +1 -0
  120. package/lib/esm/lib/utils/tick.js +22 -0
  121. package/lib/esm/lib/utils/tick.js.map +1 -0
  122. package/lib/esm/module/Editor/Editor.js +91 -0
  123. package/lib/esm/module/Editor/Editor.js.map +1 -0
  124. package/lib/esm/module/Editor/lib/init-editor-provider.js +32 -0
  125. package/lib/esm/module/Editor/lib/init-editor-provider.js.map +1 -0
  126. package/lib/esm/module/Editor/lib/init-editor-state.js +18 -0
  127. package/lib/esm/module/Editor/lib/init-editor-state.js.map +1 -0
  128. package/lib/esm/module/Editor/lib/init-editor.js +27 -0
  129. package/lib/esm/module/Editor/lib/init-editor.js.map +1 -0
  130. package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js +29 -0
  131. package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
  132. package/lib/index.d.ts +137 -0
  133. package/package.json +32 -24
  134. package/lib/cjs/bundle.cjs +0 -2
  135. package/lib/cjs/bundle.cjs.map +0 -1
  136. package/tmp/app/helpers/common-test.d.ts +0 -1
  137. package/tmp/app/helpers/full-example.d.ts +0 -1
  138. package/tmp/app/helpers/index.d.ts +0 -5
  139. package/tmp/app/helpers/random-color.d.ts +0 -1
  140. package/tmp/app/helpers/random-string.d.ts +0 -1
  141. package/tmp/app/helpers/stress-test.d.ts +0 -1
  142. package/tmp/app/index.d.ts +0 -1
  143. package/tmp/extensions/compartments/index.d.ts +0 -4
  144. package/tmp/extensions/index.d.ts +0 -8
  145. package/tmp/extensions/init-extensions.d.ts +0 -14
  146. package/tmp/extensions/keymaps/bold-keymap.d.ts +0 -2
  147. package/tmp/extensions/keymaps/index.d.ts +0 -1
  148. package/tmp/extensions/keymaps/init-key-map.d.ts +0 -9
  149. package/tmp/extensions/keymaps/italic-key-map.d.ts +0 -2
  150. package/tmp/extensions/keymaps/line-through-key-map.d.ts +0 -2
  151. package/tmp/extensions/keymaps/underline-key-map.d.ts +0 -2
  152. package/tmp/extensions/listeners/get-change-event.d.ts +0 -6
  153. package/tmp/extensions/listeners/get-focus-event.d.ts +0 -8
  154. package/tmp/extensions/listeners/index.d.ts +0 -3
  155. package/tmp/extensions/listeners/init-listeners.d.ts +0 -4
  156. package/tmp/extensions/markdown/blockquote/blockquote-constants.d.ts +0 -3
  157. package/tmp/extensions/markdown/blockquote/blockquote-decoration.d.ts +0 -2
  158. package/tmp/extensions/markdown/blockquote/blockquote-widget.d.ts +0 -6
  159. package/tmp/extensions/markdown/blockquote/index.d.ts +0 -1
  160. package/tmp/extensions/markdown/bold/bold-constants.d.ts +0 -2
  161. package/tmp/extensions/markdown/bold/bold-decoration.d.ts +0 -2
  162. package/tmp/extensions/markdown/bold/index.d.ts +0 -1
  163. package/tmp/extensions/markdown/code/code-constants.d.ts +0 -3
  164. package/tmp/extensions/markdown/code/code-decoration.d.ts +0 -2
  165. package/tmp/extensions/markdown/code/code-widget.d.ts +0 -13
  166. package/tmp/extensions/markdown/code/index.d.ts +0 -1
  167. package/tmp/extensions/markdown/header/header-constants.d.ts +0 -3
  168. package/tmp/extensions/markdown/header/header-decoration.d.ts +0 -2
  169. package/tmp/extensions/markdown/header/index.d.ts +0 -1
  170. package/tmp/extensions/markdown/horizontal/horizontal-constants.d.ts +0 -1
  171. package/tmp/extensions/markdown/horizontal/horizontal-decoration.d.ts +0 -2
  172. package/tmp/extensions/markdown/horizontal/index.d.ts +0 -1
  173. package/tmp/extensions/markdown/image/image-constants.d.ts +0 -5
  174. package/tmp/extensions/markdown/image/image-decoration.d.ts +0 -2
  175. package/tmp/extensions/markdown/image/image-widget.d.ts +0 -15
  176. package/tmp/extensions/markdown/image/index.d.ts +0 -1
  177. package/tmp/extensions/markdown/index.d.ts +0 -2
  178. package/tmp/extensions/markdown/init-markdown.d.ts +0 -3
  179. package/tmp/extensions/markdown/italic/index.d.ts +0 -1
  180. package/tmp/extensions/markdown/italic/italic-constants.d.ts +0 -2
  181. package/tmp/extensions/markdown/italic/italic-decoration.d.ts +0 -2
  182. package/tmp/extensions/markdown/link/auto-link-decoration.d.ts +0 -2
  183. package/tmp/extensions/markdown/link/index.d.ts +0 -2
  184. package/tmp/extensions/markdown/link/link-constants.d.ts +0 -7
  185. package/tmp/extensions/markdown/link/link-decoration.d.ts +0 -2
  186. package/tmp/extensions/markdown/link/link-label-decoration.d.ts +0 -2
  187. package/tmp/extensions/markdown/link/link-widget.d.ts +0 -17
  188. package/tmp/extensions/markdown/list/index.d.ts +0 -1
  189. package/tmp/extensions/markdown/list/list-constants.d.ts +0 -4
  190. package/tmp/extensions/markdown/list/list-decoration.d.ts +0 -2
  191. package/tmp/extensions/markdown/list/list-widget.d.ts +0 -7
  192. package/tmp/extensions/markdown/markdown-decoration.d.ts +0 -5
  193. package/tmp/extensions/markdown/markdown-types.d.ts +0 -24
  194. package/tmp/extensions/markdown/mention/index.d.ts +0 -1
  195. package/tmp/extensions/markdown/mention/mention-constants.d.ts +0 -3
  196. package/tmp/extensions/markdown/mention/mention-decoration.d.ts +0 -2
  197. package/tmp/extensions/markdown/mention/mention-parser.d.ts +0 -2
  198. package/tmp/extensions/markdown/strike-through/index.d.ts +0 -1
  199. package/tmp/extensions/markdown/strike-through/strike-through-constants.d.ts +0 -1
  200. package/tmp/extensions/markdown/strike-through/strike-through-decoration.d.ts +0 -2
  201. package/tmp/extensions/markdown/todo/index.d.ts +0 -1
  202. package/tmp/extensions/markdown/todo/todo-constants.d.ts +0 -3
  203. package/tmp/extensions/markdown/todo/todo-decoration.d.ts +0 -2
  204. package/tmp/extensions/markdown/todo/todo-widget.d.ts +0 -11
  205. package/tmp/extensions/settings/index.d.ts +0 -1
  206. package/tmp/extensions/settings/init-settings.d.ts +0 -6
  207. package/tmp/extensions/theme/index.d.ts +0 -4
  208. package/tmp/extensions/theme/init-theme.d.ts +0 -3
  209. package/tmp/extensions/theme/theme-constants.d.ts +0 -14
  210. package/tmp/extensions/theme/theme-types.d.ts +0 -36
  211. package/tmp/extensions/theme/themes/get-dark-theme.d.ts +0 -2
  212. package/tmp/extensions/theme/themes/get-highlight-template.d.ts +0 -6
  213. package/tmp/extensions/theme/themes/get-light-theme.d.ts +0 -2
  214. package/tmp/extensions/theme/themes/get-theme-template.d.ts +0 -2
  215. package/tmp/extensions/theme/themes/index.d.ts +0 -2
  216. package/tmp/index.d.ts +0 -3
  217. package/tmp/lib/index.d.ts +0 -1
  218. package/tmp/lib/utils/copy-to-clipboard.d.ts +0 -1
  219. package/tmp/lib/utils/get-decoration.d.ts +0 -26
  220. package/tmp/lib/utils/index.d.ts +0 -5
  221. package/tmp/lib/utils/is-in-range.d.ts +0 -2
  222. package/tmp/lib/utils/is-range-overlap.d.ts +0 -1
  223. package/tmp/lib/utils/tick.d.ts +0 -10
  224. package/tmp/module/Editor/Editor.d.ts +0 -17
  225. package/tmp/module/Editor/Editor.types.d.ts +0 -13
  226. package/tmp/module/Editor/index.d.ts +0 -3
  227. package/tmp/module/Editor/lib/index.d.ts +0 -1
  228. package/tmp/module/Editor/lib/init-editor-provider.d.ts +0 -10
  229. package/tmp/module/Editor/lib/init-editor-state.d.ts +0 -7
  230. package/tmp/module/Editor/lib/init-editor.d.ts +0 -7
  231. package/tmp/module/index.d.ts +0 -1
@@ -0,0 +1,1374 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const langMarkdown = require('@codemirror/lang-markdown');
6
+ const language = require('@codemirror/language');
7
+ const view = require('@codemirror/view');
8
+ const clsx = require('clsx');
9
+ const index = require('./index-Byjf17iv.js');
10
+ require('@lezer/highlight');
11
+ require('@codemirror/state');
12
+ require('@codemirror/commands');
13
+
14
+ function copyToClipboard(content) {
15
+ if (navigator.clipboard && window.isSecureContext) {
16
+ return navigator.clipboard.writeText(content);
17
+ }
18
+ return fallbackCopyTextToClipboard(content);
19
+ }
20
+ function fallbackCopyTextToClipboard(content) {
21
+ const textArea = document.createElement("textarea");
22
+ textArea.value = content;
23
+ textArea.style.top = "0";
24
+ textArea.style.left = "0";
25
+ textArea.style.opacity = "0";
26
+ textArea.style.position = "fixed";
27
+ document.body.appendChild(textArea);
28
+ textArea.focus();
29
+ textArea.select();
30
+ return new Promise((resolve, reject) => {
31
+ try {
32
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
33
+ if (document.execCommand("copy"))
34
+ resolve();
35
+ else
36
+ reject();
37
+ }
38
+ catch {
39
+ reject();
40
+ }
41
+ finally {
42
+ document.body.removeChild(textArea);
43
+ }
44
+ });
45
+ }
46
+
47
+ function tick({ deep = 1, maxDeep = 1, delay = 0, recursiveCondition, delayGetter, type = "macro", }) {
48
+ return new Promise((resolve) => {
49
+ if (type === "micro") {
50
+ if (deep >= maxDeep || !recursiveCondition || recursiveCondition())
51
+ resolve(1);
52
+ else
53
+ void tick({ deep: deep + 1, maxDeep, delay, recursiveCondition, type, delayGetter }).then(() => resolve(1));
54
+ }
55
+ if (type === "macro") {
56
+ const currentDelay = delayGetter ? delayGetter(deep) : delay;
57
+ setTimeout(() => {
58
+ if (deep >= maxDeep || !recursiveCondition || recursiveCondition())
59
+ resolve(1);
60
+ else
61
+ void tick({ deep: deep + 1, maxDeep, delay, recursiveCondition, type, delayGetter }).then(() => resolve(1));
62
+ }, currentDelay);
63
+ }
64
+ });
65
+ }
66
+
67
+ function getLineDecoration({ style, range }) {
68
+ return view.Decoration.line({
69
+ class: style,
70
+ }).range(range[0], range[1]);
71
+ }
72
+ function getMarkDecoration({ range, style }) {
73
+ return view.Decoration.mark({
74
+ class: style,
75
+ }).range(range[0], range[1]);
76
+ }
77
+ function getHideDecoration({ range }) {
78
+ return view.Decoration.replace({}).range(range[0], range[1]);
79
+ }
80
+ function getReplaceDecoration({ range, widget }) {
81
+ return view.Decoration.replace({ widget }).range(range[0], range[1]);
82
+ }
83
+ function getWidgetDecorationOptions({ widget, range }) {
84
+ return view.Decoration.widget({ widget, side: 1 }).range(range[0], range[1]);
85
+ }
86
+
87
+ function isRangeOverlap(range, text) {
88
+ return range[0] <= text[1] && text[0] <= range[1];
89
+ }
90
+
91
+ function isInRange(ranges, text) {
92
+ return ranges.some((range) => isRangeOverlap([range.from, range.to], text));
93
+ }
94
+
95
+ function styleInject(css, ref) {
96
+ if ( ref === void 0 ) ref = {};
97
+ var insertAt = ref.insertAt;
98
+
99
+ if (typeof document === 'undefined') { return; }
100
+
101
+ var head = document.head || document.getElementsByTagName('head')[0];
102
+ var style = document.createElement('style');
103
+ style.type = 'text/css';
104
+
105
+ if (insertAt === 'top') {
106
+ if (head.firstChild) {
107
+ head.insertBefore(style, head.firstChild);
108
+ } else {
109
+ head.appendChild(style);
110
+ }
111
+ } else {
112
+ head.appendChild(style);
113
+ }
114
+
115
+ if (style.styleSheet) {
116
+ style.styleSheet.cssText = css;
117
+ } else {
118
+ style.appendChild(document.createTextNode(css));
119
+ }
120
+ }
121
+
122
+ 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}";
123
+ 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"};
124
+ styleInject(css_248z);
125
+
126
+ const NAME_OF_BLOCKQUOTE_MARK = "QuoteMark";
127
+ const CODE_OF_SPACE$1 = 32;
128
+ const CODE_OF_BLOCKQUOTE_MARK = 62; // >
129
+
130
+ class BlockquoteWidget extends view.WidgetType {
131
+ deep;
132
+ constructor(deep) {
133
+ super();
134
+ this.deep = deep;
135
+ }
136
+ toDOM() {
137
+ const span = document.createElement("span");
138
+ span.classList.add(styles.blockquote__inner);
139
+ if (this.deep)
140
+ span.classList.add(styles["blockquote__inner-deep"]);
141
+ span.classList.add(index.CLASSES.blockquoteInner);
142
+ return span;
143
+ }
144
+ }
145
+
146
+ function getBlockquoteDecorations({ decorations, node, view }) {
147
+ if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {
148
+ return;
149
+ }
150
+ const line = view.lineBlockAt(node.from);
151
+ let isInner = false;
152
+ if (line.from !== node.from) {
153
+ const content = view.state.doc.sliceString(line.from, node.to);
154
+ let pos = content.length - 1;
155
+ let isHasMark = false;
156
+ while (pos >= 0) {
157
+ pos--;
158
+ const currentCode = content.charCodeAt(pos);
159
+ if (currentCode === CODE_OF_SPACE$1)
160
+ continue;
161
+ if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
162
+ if (!isHasMark) {
163
+ isHasMark = true;
164
+ continue;
165
+ }
166
+ if (!isInner) {
167
+ isInner = true;
168
+ break;
169
+ }
170
+ }
171
+ pos = -1;
172
+ }
173
+ }
174
+ if (!isInner) {
175
+ decorations.push(getLineDecoration({
176
+ style: clsx(styles.blockquote, index.CLASSES.blockquote),
177
+ range: [line.from],
178
+ }));
179
+ }
180
+ }
181
+ function getBlockquoteSelectionDecorations({ decorations, node, view, isReadonly, }) {
182
+ if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {
183
+ return;
184
+ }
185
+ const line = view.lineBlockAt(node.from);
186
+ let isInner = false;
187
+ let isDeepInner = false;
188
+ if (line.from !== node.from) {
189
+ const content = view.state.doc.sliceString(line.from, node.to);
190
+ let pos = content.length;
191
+ let isHasMark = false;
192
+ while (pos >= 0) {
193
+ pos--;
194
+ const currentCode = content.charCodeAt(pos);
195
+ if (currentCode === CODE_OF_SPACE$1)
196
+ continue;
197
+ if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
198
+ if (!isHasMark) {
199
+ isHasMark = true;
200
+ continue;
201
+ }
202
+ if (!isInner) {
203
+ isInner = true;
204
+ continue;
205
+ }
206
+ if (!isDeepInner) {
207
+ isDeepInner = true;
208
+ break;
209
+ }
210
+ }
211
+ pos = -1;
212
+ }
213
+ }
214
+ if (isReadonly ||
215
+ !view.hasFocus ||
216
+ !isInRange(view.state.selection.ranges, [line.from, line.to])) {
217
+ if (!isInner)
218
+ decorations.push(getHideDecoration({ range: [node.from, node.to] }));
219
+ else
220
+ decorations.push(getReplaceDecoration({
221
+ widget: new BlockquoteWidget(isDeepInner),
222
+ range: [node.from, node.to],
223
+ }));
224
+ }
225
+ }
226
+ const blockquoteDecorationPlugin = {
227
+ decorations: [getBlockquoteDecorations],
228
+ selectionDecorations: [getBlockquoteSelectionDecorations],
229
+ };
230
+
231
+ const NAME_OF_BOLD = "StrongEmphasis";
232
+ const LIST_OF_BOLD_MARKS = new Set([95, 42]); // _ *
233
+
234
+ function getBoldDecorations({ decorations, node, view }) {
235
+ if (node.name !== NAME_OF_BOLD) {
236
+ return;
237
+ }
238
+ const step = LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&
239
+ language.syntaxTree(view.state).resolve(node.from - 1).type.name !== "Emphasis"
240
+ ? 1
241
+ : 0;
242
+ decorations.push(getMarkDecoration({
243
+ style: styles.bold,
244
+ range: [node.from - step, node.to + step],
245
+ }));
246
+ }
247
+ function getBoldSelectionDecorations({ decorations, node, view, isReadonly, }) {
248
+ if (node.name !== NAME_OF_BOLD) {
249
+ return;
250
+ }
251
+ if (LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&
252
+ language.syntaxTree(view.state).resolve(node.from - 1).type.name !== "Emphasis") {
253
+ return;
254
+ }
255
+ if (isReadonly ||
256
+ !view.hasFocus ||
257
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
258
+ decorations.push(getHideDecoration({ range: [node.from, node.from + 2] }));
259
+ decorations.push(getHideDecoration({ range: [node.to - 2, node.to] }));
260
+ }
261
+ }
262
+ const boldDecorationPlugin = {
263
+ decorations: [getBoldDecorations],
264
+ selectionDecorations: [getBoldSelectionDecorations],
265
+ };
266
+
267
+ const NAME_OF_FENCED_CODE = "FencedCode";
268
+ const NAME_OF_INLINE_CODE = "InlineCode";
269
+ const CODE_OF_CODE_MARK = 96; // `
270
+
271
+ class CodeWidget extends view.WidgetType {
272
+ language;
273
+ content;
274
+ view;
275
+ timer;
276
+ button;
277
+ span;
278
+ constructor(language, content) {
279
+ super();
280
+ this.language = language;
281
+ this.content = content;
282
+ }
283
+ onClick() {
284
+ if (this.content && this.button && this.span) {
285
+ const span = this.span;
286
+ const button = this.button;
287
+ clearTimeout(this.timer);
288
+ button.classList.remove(styles.pending);
289
+ button.classList.remove(index.CLASSES.codeButtonPending);
290
+ button.classList.remove(styles.success);
291
+ button.classList.remove(index.CLASSES.codeButtonSuccess);
292
+ button.classList.remove(styles.fail);
293
+ button.classList.remove(index.CLASSES.codeButtonFail);
294
+ button.classList.add(styles.pending);
295
+ button.classList.add(index.CLASSES.codeButtonPending);
296
+ span.classList.add(styles.hide);
297
+ void copyToClipboard(this.content)
298
+ .then(() => {
299
+ button.classList.remove(styles.pending);
300
+ button.classList.remove(index.CLASSES.codeButtonPending);
301
+ button.classList.add(styles.success);
302
+ button.classList.add(index.CLASSES.codeButtonSuccess);
303
+ this.timer = setTimeout(() => {
304
+ button.classList.remove(styles.success);
305
+ button.classList.remove(index.CLASSES.codeButtonSuccess);
306
+ span.classList.remove(styles.hide);
307
+ }, 500);
308
+ })
309
+ .catch(() => {
310
+ button.classList.remove(styles.pending);
311
+ button.classList.remove(index.CLASSES.codeButtonPending);
312
+ button.classList.add(styles.fail);
313
+ button.classList.add(index.CLASSES.codeButtonFail);
314
+ this.timer = setTimeout(() => {
315
+ button.classList.remove(styles.fail);
316
+ button.classList.remove(index.CLASSES.codeButtonFail);
317
+ span.classList.remove(styles.hide);
318
+ }, 500);
319
+ });
320
+ }
321
+ }
322
+ toDOM(view) {
323
+ this.view = view;
324
+ const span = document.createElement("span");
325
+ span.classList.add(styles.code__span);
326
+ span.classList.add(index.CLASSES.codeButtonSpan);
327
+ span.textContent = this.language;
328
+ const button = document.createElement("button");
329
+ button.classList.add(styles.code__button);
330
+ button.classList.add(index.CLASSES.codeButton);
331
+ if (this.content)
332
+ button.addEventListener("click", this.onClick.bind(this));
333
+ button.appendChild(span);
334
+ this.button = button;
335
+ this.span = span;
336
+ return button;
337
+ }
338
+ destroy(dom) {
339
+ if (this.content)
340
+ dom.removeEventListener("click", this.onClick.bind(this));
341
+ }
342
+ }
343
+
344
+ function getCodeSelectionDecorations({ decorations, node, view, isReadonly, }) {
345
+ if (node.name !== NAME_OF_FENCED_CODE && node.name !== NAME_OF_INLINE_CODE) {
346
+ return;
347
+ }
348
+ let isOverlapLine = false;
349
+ const startMarkPosition = { from: -1, to: -1 };
350
+ const endMarkPosition = { from: -1, to: -1 };
351
+ const lines = view.viewportLineBlocks.filter((line) => {
352
+ const isOverlap = isRangeOverlap([node.from, node.to], [line.from, line.to]);
353
+ if (isOverlap && isInRange(view.state.selection.ranges, [line.from, line.to]))
354
+ isOverlapLine = true;
355
+ return isOverlap;
356
+ });
357
+ let languagePos;
358
+ let language;
359
+ let codeContent;
360
+ const content = view.state.doc.sliceString(node.from, node.to);
361
+ let pos = -1;
362
+ while ((startMarkPosition.from === -1 || startMarkPosition.to === -1) &&
363
+ pos >= -1 &&
364
+ pos < content.length) {
365
+ pos++;
366
+ const code = content.charCodeAt(pos);
367
+ if (code !== CODE_OF_CODE_MARK && startMarkPosition.from === -1)
368
+ continue;
369
+ else if (code === CODE_OF_CODE_MARK && startMarkPosition.from === -1)
370
+ startMarkPosition.from = node.from + pos;
371
+ else if (code !== CODE_OF_CODE_MARK && startMarkPosition.from !== -1)
372
+ startMarkPosition.to = node.from + pos;
373
+ }
374
+ pos = content.length;
375
+ while ((endMarkPosition.from === -1 || endMarkPosition.to === -1) &&
376
+ pos >= -1 &&
377
+ pos <= content.length) {
378
+ pos--;
379
+ const code = content.charCodeAt(pos);
380
+ if (code !== CODE_OF_CODE_MARK && endMarkPosition.to === -1)
381
+ continue;
382
+ else if (code === CODE_OF_CODE_MARK && endMarkPosition.to === -1)
383
+ endMarkPosition.to = node.from + pos + 1;
384
+ else if (code !== CODE_OF_CODE_MARK && endMarkPosition.to !== -1)
385
+ endMarkPosition.from = node.from + pos + 1;
386
+ }
387
+ if (node.name === NAME_OF_FENCED_CODE) {
388
+ const codeInfo = node.node.getChild("CodeInfo");
389
+ const codeText = node.node.getChild("CodeText");
390
+ if (codeInfo) {
391
+ language = view.state.doc.sliceString(codeInfo.from, codeInfo.to);
392
+ languagePos = [codeInfo.from, codeInfo.to];
393
+ }
394
+ if (codeText)
395
+ codeContent = view.state.doc.sliceString(codeText.from, codeText.to);
396
+ else
397
+ codeContent = "";
398
+ }
399
+ if (node.name === NAME_OF_INLINE_CODE) {
400
+ codeContent = view.state.doc.sliceString(startMarkPosition.to, endMarkPosition.from).trim();
401
+ }
402
+ if (!language)
403
+ language = "copy";
404
+ if (lines.length > 1) {
405
+ lines.forEach((line) => {
406
+ decorations.push(getLineDecoration({
407
+ style: clsx(styles.code__line, index.CLASSES.code),
408
+ range: [line.from],
409
+ }));
410
+ });
411
+ }
412
+ else {
413
+ decorations.push(getMarkDecoration({
414
+ style: clsx(styles.code__single, index.CLASSES.code),
415
+ range: [node.from, node.to],
416
+ }));
417
+ }
418
+ if (isReadonly ||
419
+ !view.hasFocus ||
420
+ (lines.length > 1 && !isOverlapLine) ||
421
+ (lines.length === 1 && !isInRange(view.state.selection.ranges, [node.from, node.to]))) {
422
+ if (lines.length > 1 && language) {
423
+ if (languagePos)
424
+ decorations.push(getHideDecoration({ range: languagePos }));
425
+ decorations.push(getWidgetDecorationOptions({
426
+ widget: new CodeWidget(language, codeContent),
427
+ range: [node.from],
428
+ }));
429
+ }
430
+ decorations.push(getHideDecoration({ range: [startMarkPosition.from, startMarkPosition.to] }));
431
+ decorations.push(getHideDecoration({ range: [endMarkPosition.from, endMarkPosition.to] }));
432
+ }
433
+ }
434
+ const codeDecorationPlugin = {
435
+ selectionDecorations: [getCodeSelectionDecorations],
436
+ };
437
+
438
+ const NAME_OF_HEADER = "ATXHeading";
439
+ const NAME_OF_HEADER_UNDER = "SetextHeading";
440
+ const NAME_OF_HEADER_MARK = "HeaderMark";
441
+
442
+ function getHeaderDecorations({ decorations, node, view }) {
443
+ const isHeader = node.name.startsWith(NAME_OF_HEADER);
444
+ const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);
445
+ if (!isHeader && !isHeaderUnder) {
446
+ return;
447
+ }
448
+ let level;
449
+ if (isHeader) {
450
+ level = node.name.replace(NAME_OF_HEADER, "");
451
+ if (view.state.doc.sliceString(node.from + +level).charCodeAt(0) !== 32)
452
+ return;
453
+ }
454
+ else {
455
+ level = node.name.replace(NAME_OF_HEADER_UNDER, "");
456
+ }
457
+ if (!level)
458
+ return;
459
+ decorations.push(getLineDecoration({
460
+ style: clsx(styles.header, styles[`level_${level}`]),
461
+ range: [view.lineBlockAt(node.from).from],
462
+ }));
463
+ }
464
+ function getHeaderSelectionDecorations({ decorations, node, view, isReadonly, }) {
465
+ const isHeader = node.name.startsWith(NAME_OF_HEADER);
466
+ const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);
467
+ if (!isHeader && !isHeaderUnder) {
468
+ return;
469
+ }
470
+ const mark = node.node.getChild(NAME_OF_HEADER_MARK);
471
+ if (!mark)
472
+ return;
473
+ if (isHeader) {
474
+ const line = view.lineBlockAt(mark.from);
475
+ if (line.length < mark.to - mark.from + 1)
476
+ return;
477
+ if (isReadonly ||
478
+ !view.hasFocus ||
479
+ !isInRange(view.state.selection.ranges, [line.from, line.to])) {
480
+ decorations.push(getHideDecoration({ range: [mark.from, mark.to + 1] }));
481
+ }
482
+ }
483
+ else {
484
+ const lineHeader = view.lineBlockAt(node.from);
485
+ const lineMark = view.lineBlockAt(mark.from);
486
+ if (isReadonly ||
487
+ !view.hasFocus ||
488
+ !isInRange(view.state.selection.ranges, [lineHeader.from, lineMark.to])) {
489
+ decorations.push(getHideDecoration({ range: [lineMark.from, lineMark.to] }));
490
+ }
491
+ }
492
+ }
493
+ const headerDecorationPlugin = {
494
+ decorations: [getHeaderDecorations],
495
+ selectionDecorations: [getHeaderSelectionDecorations],
496
+ };
497
+
498
+ const NAME_OF_HORIZONTAL = "HorizontalRule";
499
+
500
+ function getHorizontalSelectionDecoration({ decorations, isReadonly, node, view, }) {
501
+ if (node.name !== NAME_OF_HORIZONTAL)
502
+ return;
503
+ const line = view.lineBlockAt(node.from);
504
+ if (isReadonly ||
505
+ !view.hasFocus ||
506
+ !isInRange(view.state.selection.ranges, [line.from, line.to])) {
507
+ decorations.push(getLineDecoration({
508
+ style: clsx(styles.horizontal, index.CLASSES.horizontal),
509
+ range: [line.from],
510
+ }));
511
+ decorations.push(getHideDecoration({ range: [node.from, node.to] }));
512
+ }
513
+ }
514
+ const horizontalDecorationPlugin = {
515
+ selectionDecorations: [getHorizontalSelectionDecoration],
516
+ };
517
+
518
+ const NAME_OF_IMAGE = "Image";
519
+ const CODE_OF_START_IMAGE_TEXT = 91; // [
520
+ const CODE_OF_END_IMAGE_TEXT = 93; // ]
521
+ const CODE_OF_START_IMAGE_URL = 40; // (
522
+ const CODE_OF_END_IMAGE_URL = 41; // )
523
+
524
+ const INTERVAL_DELAY = 10000;
525
+ const IMAGE_NODES = {};
526
+ const EXISTING_WIDGETS = new Set();
527
+ let interval = null;
528
+ class ImageWidget extends view.WidgetType {
529
+ text;
530
+ link;
531
+ from;
532
+ to;
533
+ view;
534
+ constructor(text, link, from, to) {
535
+ super();
536
+ this.text = text;
537
+ this.link = link;
538
+ this.from = from;
539
+ this.to = to;
540
+ }
541
+ get key() {
542
+ return `${this.link}:${this.text}:${this.from}:${this.to}`;
543
+ }
544
+ eq(widget) {
545
+ const image = IMAGE_NODES[this.key];
546
+ delete IMAGE_NODES[this.key];
547
+ EXISTING_WIDGETS.delete(this.key);
548
+ if (image.src !== widget.link)
549
+ image.src = widget.link;
550
+ if (image.alt !== widget.text)
551
+ image.alt = widget.text;
552
+ this.link = widget.link;
553
+ this.text = widget.text;
554
+ this.from = widget.from;
555
+ this.to = widget.to;
556
+ IMAGE_NODES[this.key] = image;
557
+ EXISTING_WIDGETS.add(this.key);
558
+ return true;
559
+ }
560
+ updateDOM() {
561
+ return true;
562
+ }
563
+ toDOM(view) {
564
+ EXISTING_WIDGETS.add(this.key);
565
+ if (IMAGE_NODES[this.key]) {
566
+ const image = IMAGE_NODES[this.key];
567
+ if (image.src !== this.link) {
568
+ image.src = this.link;
569
+ }
570
+ if (image.alt !== this.text)
571
+ image.alt = this.text;
572
+ return image;
573
+ }
574
+ this.view = view;
575
+ const image = document.createElement("img");
576
+ image.classList.add(styles.image);
577
+ image.alt = this.text;
578
+ image.src = this.link;
579
+ image.addEventListener("mousedown", handleClick);
580
+ image.addEventListener("click", handleClick);
581
+ IMAGE_NODES[this.key] = image;
582
+ if (!interval)
583
+ interval = setInterval(garbageCollectorInterval, INTERVAL_DELAY);
584
+ return image;
585
+ }
586
+ destroy() {
587
+ EXISTING_WIDGETS.delete(this.key);
588
+ }
589
+ }
590
+ function garbageCollectorInterval() {
591
+ for (const [key, node] of Object.entries(IMAGE_NODES)) {
592
+ if (EXISTING_WIDGETS.has(key))
593
+ continue;
594
+ delete IMAGE_NODES[key];
595
+ node.removeEventListener("mousedown", handleClick);
596
+ node.removeEventListener("click", handleClick);
597
+ node.remove();
598
+ }
599
+ if (Object.keys(IMAGE_NODES).length === 0 && interval) {
600
+ clearInterval(interval);
601
+ interval = null;
602
+ }
603
+ }
604
+ /** recursively find the link text node in line */
605
+ function getTextNode(imageNode, line) {
606
+ if (!line)
607
+ return null;
608
+ const link = imageNode.src;
609
+ let textNode = null;
610
+ for (const node of Array.from(line.childNodes)) {
611
+ if (node.nodeType !== 3) {
612
+ const innerNode = getTextNode(imageNode, node);
613
+ if (innerNode) {
614
+ textNode = innerNode;
615
+ break;
616
+ }
617
+ continue;
618
+ }
619
+ const textContent = node.textContent;
620
+ if (textContent && textContent.includes(link)) {
621
+ textNode = node;
622
+ break;
623
+ }
624
+ }
625
+ return textNode;
626
+ }
627
+ function getMinLength(imageNode) {
628
+ const text = imageNode.alt || "";
629
+ const link = imageNode.src;
630
+ const startPosition = 4 + text.length;
631
+ const endPosition = startPosition + link.length + 1;
632
+ return endPosition;
633
+ }
634
+ function isCorrectNode(imageNode, node) {
635
+ if (!node)
636
+ return false;
637
+ const textContent = node?.textContent;
638
+ const minLength = getMinLength(imageNode);
639
+ return Boolean(node && textContent && node.nodeType === 3 && textContent.length >= minLength);
640
+ }
641
+ function selectLink({ imageNode, node, selection, start }) {
642
+ const link = imageNode.src;
643
+ const startPosition = start ?? (node.textContent?.indexOf?.(link) || 0);
644
+ const endPosition = startPosition + link.length;
645
+ const range = document.createRange();
646
+ range.setStart(node, startPosition);
647
+ range.setEnd(node, endPosition);
648
+ selection.removeAllRanges();
649
+ selection.addRange(range);
650
+ }
651
+ function handleClick(event) {
652
+ const selection = window.getSelection();
653
+ if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) {
654
+ return;
655
+ }
656
+ event.stopPropagation();
657
+ event.preventDefault();
658
+ const target = event.target;
659
+ const parent = target.parentNode;
660
+ let line = parent;
661
+ /** recursively find line that contains link */
662
+ while (line && !line.classList.contains("cm-line")) {
663
+ line = line.parentNode;
664
+ }
665
+ const editor = Array.from(document.querySelectorAll(".cm-editor")).find((element) => element.contains(target));
666
+ if (!selection || !editor || !parent)
667
+ return;
668
+ const prevLine = parent.previousSibling;
669
+ let textNode = getTextNode(target, prevLine);
670
+ if (!textNode)
671
+ textNode = getTextNode(target, parent);
672
+ if (textNode) {
673
+ if (isCorrectNode(target, textNode))
674
+ selectLink({ selection, imageNode: target, node: textNode });
675
+ return;
676
+ }
677
+ const range = document.createRange();
678
+ range.selectNode(target);
679
+ range.collapse(true);
680
+ selection.removeAllRanges();
681
+ selection.addRange(range);
682
+ /** wait for the widget to disappear and link will be visible */
683
+ void tick({
684
+ delay: 0,
685
+ maxDeep: 5,
686
+ delayGetter: (deep) => {
687
+ return deep > 1 ? 10 : 0;
688
+ },
689
+ recursiveCondition: () => {
690
+ const textNode = getTextNode(target, line);
691
+ return isCorrectNode(target, textNode);
692
+ },
693
+ })
694
+ .then(() => {
695
+ const textNode = getTextNode(target, line);
696
+ if (isCorrectNode(target, textNode))
697
+ selectLink({ selection, imageNode: target, node: textNode });
698
+ });
699
+ return false;
700
+ }
701
+
702
+ function getImageSelectionDecorations({ decorations, node, view, isReadonly, }) {
703
+ if (node.name !== NAME_OF_IMAGE) {
704
+ return;
705
+ }
706
+ const { text, url } = parseInfo(view, node);
707
+ const line = view.lineBlockAt(node.from);
708
+ if (line.from === node.from && line.to === node.to) {
709
+ if (isReadonly ||
710
+ !view.hasFocus ||
711
+ !isInRange(view.state.selection.ranges, [line.from, line.to])) {
712
+ decorations.push(getReplaceDecoration({
713
+ range: [line.from, line.to],
714
+ widget: new ImageWidget(text, url, node.from, node.to),
715
+ }));
716
+ }
717
+ else {
718
+ decorations.push(getWidgetDecorationOptions({
719
+ range: [node.to + 1],
720
+ widget: new ImageWidget(text, url, node.from, node.to),
721
+ }));
722
+ }
723
+ }
724
+ else if (isReadonly ||
725
+ !view.hasFocus ||
726
+ !isInRange(view.state.selection.ranges, [line.from, line.to])) {
727
+ decorations.push(getReplaceDecoration({
728
+ range: [node.from, node.to],
729
+ widget: new ImageWidget(text, url, node.from, node.to),
730
+ }));
731
+ }
732
+ else {
733
+ decorations.push(getWidgetDecorationOptions({
734
+ range: [node.to],
735
+ widget: new ImageWidget(text, url, node.from, node.to),
736
+ }));
737
+ }
738
+ }
739
+ function parseInfo(view, node) {
740
+ const content = view.state.doc.sliceString(node.from, node.to);
741
+ const textCoordinates = { from: -1, to: -1 };
742
+ const urlCoordinates = { from: -1, to: -1 };
743
+ let pos = -1;
744
+ while (pos < content.length) {
745
+ pos++;
746
+ const code = content.charCodeAt(pos);
747
+ if (textCoordinates.from === -1 && code === CODE_OF_START_IMAGE_TEXT)
748
+ textCoordinates.from = pos + 1;
749
+ else if (urlCoordinates.from === -1 &&
750
+ textCoordinates.to !== -1 &&
751
+ code === CODE_OF_START_IMAGE_URL)
752
+ urlCoordinates.from = pos + 1;
753
+ else if (textCoordinates.from !== -1 &&
754
+ textCoordinates.to === -1 &&
755
+ code === CODE_OF_END_IMAGE_TEXT)
756
+ textCoordinates.to = pos;
757
+ else if (urlCoordinates.from !== -1 &&
758
+ urlCoordinates.to === -1 &&
759
+ code === CODE_OF_END_IMAGE_URL)
760
+ urlCoordinates.to = pos;
761
+ }
762
+ const text = content.substring(textCoordinates.from, textCoordinates.to);
763
+ const url = content.substring(urlCoordinates.from, urlCoordinates.to);
764
+ return { text, url };
765
+ }
766
+ const imageDecorationPlugin = {
767
+ selectionDecorations: [getImageSelectionDecorations],
768
+ };
769
+
770
+ const NAME_OF_ITALIC = "Emphasis";
771
+ const LIST_OF_ITALIC_MARKS = new Set([95, 42]); // _ *
772
+
773
+ function getItalicDecorations({ decorations, node }) {
774
+ if (node.name !== NAME_OF_ITALIC) {
775
+ return;
776
+ }
777
+ decorations.push(getMarkDecoration({
778
+ style: styles.italic,
779
+ range: [node.from, node.to],
780
+ }));
781
+ }
782
+ function getItalicSelectionDecorations({ decorations, node, view, isReadonly, }) {
783
+ if (node.name !== NAME_OF_ITALIC) {
784
+ return;
785
+ }
786
+ if (checkIsSeveralEmphasis({ decorations, node, view, isReadonly })) {
787
+ return void splitEmphasis({ decorations, node, view, isReadonly });
788
+ }
789
+ let step = 1;
790
+ const startText = view.state.doc.sliceString(node.from, node.from + 3);
791
+ if (LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(0)) &&
792
+ LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(1)) &&
793
+ LIST_OF_ITALIC_MARKS.has(startText.charCodeAt(2)))
794
+ step = 3;
795
+ if (isReadonly ||
796
+ !view.hasFocus ||
797
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
798
+ decorations.push(getHideDecoration({ range: [node.from, node.from + step] }));
799
+ decorations.push(getHideDecoration({ range: [node.to - step, node.to] }));
800
+ }
801
+ }
802
+ /** Fixed wide italic + italic */
803
+ function checkIsSeveralEmphasis({ node, view }) {
804
+ let marks = 0;
805
+ let pos = 0;
806
+ const text = view.state.doc.sliceString(node.from, node.to);
807
+ while (pos <= text.length) {
808
+ if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos)))
809
+ marks++;
810
+ pos++;
811
+ }
812
+ if (marks === 8)
813
+ return true;
814
+ return false;
815
+ }
816
+ function splitEmphasis({ decorations, node, view, isReadonly }) {
817
+ const text = view.state.doc.sliceString(node.from, node.to);
818
+ let marks = 0;
819
+ let pos = 0;
820
+ while (pos <= text.length && marks < 6) {
821
+ if (LIST_OF_ITALIC_MARKS.has(text.charCodeAt(pos)))
822
+ marks++;
823
+ pos++;
824
+ }
825
+ getItalicSelectionDecorations({
826
+ decorations,
827
+ view,
828
+ node: { ...node, name: node.name, from: node.from, to: node.from + pos },
829
+ isReadonly,
830
+ });
831
+ getItalicSelectionDecorations({
832
+ decorations,
833
+ view,
834
+ node: { ...node, name: node.name, from: node.from + pos, to: node.to },
835
+ isReadonly,
836
+ });
837
+ }
838
+ const italicDecorationPlugin = {
839
+ decorations: [getItalicDecorations],
840
+ selectionDecorations: [getItalicSelectionDecorations],
841
+ };
842
+
843
+ const NAME_OF_LINK = "Link";
844
+ const CODE_OF_START_LINK_TEXT = 91; // [
845
+ const CODE_OF_END_LINK_TEXT = 93; // ]
846
+ const CODE_OF_START_LINK_URL = 40; // (
847
+ const CODE_OF_END_LINK_URL = 41; // )
848
+ const NAME_OF_AUTO_LINK = "Autolink";
849
+ const CODE_OF_LINK_LABEL_END = 58; // :
850
+
851
+ function getLinkLabelSelectionDecoration({ decorations, node, view, isReadonly, }) {
852
+ if (view.state.doc.sliceString(node.to, node.to + 1).charCodeAt(0) !== CODE_OF_LINK_LABEL_END)
853
+ return;
854
+ if (isReadonly ||
855
+ !view.hasFocus ||
856
+ !isInRange(view.state.selection.ranges, [node.from, node.to + 1])) {
857
+ decorations.push(getMarkDecoration({
858
+ range: [node.from, node.to + 1],
859
+ style: styles.link__label,
860
+ }));
861
+ decorations.push(getHideDecoration({ range: [node.from, node.from + 1] }));
862
+ decorations.push(getHideDecoration({ range: [node.to - 1, node.to + 1] }));
863
+ }
864
+ }
865
+
866
+ class LinkWidget extends view.WidgetType {
867
+ text;
868
+ link;
869
+ type;
870
+ view;
871
+ constructor(text, link, type) {
872
+ super();
873
+ this.text = text;
874
+ this.link = link;
875
+ this.type = type;
876
+ }
877
+ /** recursively find the link text node in line */
878
+ getTextNode(line) {
879
+ if (!line)
880
+ return null;
881
+ let textNode = null;
882
+ for (const node of Array.from(line.childNodes)) {
883
+ if (node.nodeType !== 3) {
884
+ const innerNode = this.getTextNode(node);
885
+ if (innerNode) {
886
+ textNode = innerNode;
887
+ break;
888
+ }
889
+ continue;
890
+ }
891
+ const textContent = node.textContent;
892
+ if (textContent && textContent.includes(this.link)) {
893
+ textNode = node;
894
+ break;
895
+ }
896
+ }
897
+ return textNode;
898
+ }
899
+ getMinLength() {
900
+ let startPosition = 0;
901
+ if (this.type === "link")
902
+ startPosition = 3 + this.text.length;
903
+ if (this.type === "auto")
904
+ startPosition = 1;
905
+ const endPosition = startPosition + this.link.length;
906
+ return endPosition;
907
+ }
908
+ /** check that the text node is correct node */
909
+ isCorrectNode(node) {
910
+ if (!node)
911
+ return false;
912
+ const textContent = node.textContent;
913
+ const minLength = this.getMinLength();
914
+ return Boolean(textContent && node.nodeType === 3 && textContent.length >= minLength);
915
+ }
916
+ selectLink(node, selection) {
917
+ const startPosition = node.textContent?.indexOf?.(this.link) || 0;
918
+ const endPosition = startPosition + this.link.length;
919
+ const range = document.createRange();
920
+ range.setStart(node, startPosition);
921
+ range.setEnd(node, endPosition);
922
+ selection.removeAllRanges();
923
+ selection.addRange(range);
924
+ }
925
+ handleClick(event) {
926
+ if (!this.view)
927
+ return;
928
+ /** open the link if has special key or the view is readonly */
929
+ const contentEditable = this.view.contentDOM.getAttribute("contenteditable");
930
+ const isReadonly = !contentEditable || contentEditable === "false";
931
+ if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey || isReadonly) {
932
+ if (event.type === "mousedown") {
933
+ const target = event.target;
934
+ window.open(target.href, "_blank");
935
+ }
936
+ return;
937
+ }
938
+ event.stopPropagation();
939
+ event.preventDefault();
940
+ const target = event.target;
941
+ const parent = target.parentNode;
942
+ let line = parent;
943
+ /** recursively find line that contains link */
944
+ while (line && !line.classList.contains("cm-line")) {
945
+ line = line.parentNode;
946
+ }
947
+ const editor = this.view.dom.querySelector(".cm-content");
948
+ const selection = window.getSelection();
949
+ if (!selection || !editor || !parent)
950
+ return;
951
+ const range = document.createRange();
952
+ range.selectNode(target);
953
+ range.collapse(true);
954
+ selection.removeAllRanges();
955
+ selection.addRange(range);
956
+ /** trick for correct select the link by click when the view is not focused */
957
+ void tick({ delay: 0 }).then(() => {
958
+ if (selection && selection.anchorNode?.nodeType !== 3) {
959
+ selection.removeAllRanges();
960
+ selection.addRange(range);
961
+ }
962
+ });
963
+ /** wait for the widget to disappear and link will be visible */
964
+ void tick({
965
+ delay: 0,
966
+ maxDeep: 5,
967
+ delayGetter: (deep) => {
968
+ return deep > 1 ? 10 : 5;
969
+ },
970
+ recursiveCondition: () => {
971
+ const textNode = this.getTextNode(line);
972
+ return this.isCorrectNode(textNode);
973
+ },
974
+ })
975
+ .then(() => {
976
+ const textNode = this.getTextNode(line);
977
+ if (this.isCorrectNode(textNode))
978
+ this.selectLink(textNode, selection);
979
+ });
980
+ return false;
981
+ }
982
+ toDOM(view) {
983
+ this.view = view;
984
+ const anchor = document.createElement("a");
985
+ anchor.classList.add(styles.link);
986
+ anchor.classList.add(index.CLASSES.link);
987
+ anchor.target = "_blank";
988
+ anchor.textContent = this.text;
989
+ anchor.href = this.link;
990
+ anchor.addEventListener("mousedown", this.handleClick.bind(this));
991
+ anchor.addEventListener("click", this.handleClick.bind(this));
992
+ return anchor;
993
+ }
994
+ destroy(dom) {
995
+ dom.removeEventListener("mousedown", this.handleClick.bind(this));
996
+ dom.removeEventListener("click", this.handleClick.bind(this));
997
+ }
998
+ }
999
+
1000
+ function getLinkSelectionDecorations({ decorations, node, view, isReadonly, }) {
1001
+ if (node.name !== NAME_OF_LINK) {
1002
+ return;
1003
+ }
1004
+ const content = view.state.doc.sliceString(node.from, node.to);
1005
+ const textCoordinates = { from: -1, to: -1 };
1006
+ const urlCoordinates = { from: -1, to: -1 };
1007
+ let pos = -1;
1008
+ while (pos < content.length) {
1009
+ pos++;
1010
+ const code = content.charCodeAt(pos);
1011
+ if (textCoordinates.from === -1 && code === CODE_OF_START_LINK_TEXT)
1012
+ textCoordinates.from = pos + 1;
1013
+ else if (urlCoordinates.from === -1 &&
1014
+ textCoordinates.to !== -1 &&
1015
+ code === CODE_OF_START_LINK_URL)
1016
+ urlCoordinates.from = pos + 1;
1017
+ else if (textCoordinates.from !== -1 &&
1018
+ textCoordinates.to === -1 &&
1019
+ code === CODE_OF_END_LINK_TEXT)
1020
+ textCoordinates.to = pos;
1021
+ else if (urlCoordinates.from !== -1 &&
1022
+ urlCoordinates.to === -1 &&
1023
+ code === CODE_OF_END_LINK_URL)
1024
+ urlCoordinates.to = pos;
1025
+ }
1026
+ if (urlCoordinates.from === -1 || urlCoordinates.to === -1)
1027
+ return void getLinkLabelSelectionDecoration({ decorations, isReadonly, node, view });
1028
+ const text = content.substring(textCoordinates.from, textCoordinates.to);
1029
+ const url = content.substring(urlCoordinates.from, urlCoordinates.to);
1030
+ if (isReadonly ||
1031
+ !view.hasFocus ||
1032
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
1033
+ decorations.push(getReplaceDecoration({
1034
+ range: [node.from, node.to],
1035
+ widget: new LinkWidget(text, url, "link"),
1036
+ }));
1037
+ }
1038
+ }
1039
+ const linkDecorationPlugin = {
1040
+ selectionDecorations: [getLinkSelectionDecorations],
1041
+ };
1042
+
1043
+ function getAutoLinkSelectionDecorations({ decorations, node, view, isReadonly, }) {
1044
+ if (node.name !== NAME_OF_AUTO_LINK)
1045
+ return;
1046
+ const url = view.state.doc.sliceString(node.from + 1, node.to - 1);
1047
+ if (isReadonly ||
1048
+ !view.hasFocus ||
1049
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
1050
+ decorations.push(getReplaceDecoration({
1051
+ range: [node.from, node.to],
1052
+ widget: new LinkWidget(url, url, "auto"),
1053
+ }));
1054
+ }
1055
+ }
1056
+ const autoLinkDecorationPlugin = {
1057
+ selectionDecorations: [getAutoLinkSelectionDecorations],
1058
+ };
1059
+
1060
+ const NAME_OF_LIST = "ListMark";
1061
+ const NAME_OF_TODO$1 = "Task";
1062
+ const LIST_OF_LIST_MARKS = new Set([42, 43, 45]); // * + -
1063
+ const CODE_OF_ORDERED_LIST_MARK = 46; // .
1064
+
1065
+ class ListPointWidget extends view.WidgetType {
1066
+ mark;
1067
+ lastCodePoint;
1068
+ constructor(mark, lastCodePoint) {
1069
+ super();
1070
+ this.mark = mark;
1071
+ this.lastCodePoint = lastCodePoint;
1072
+ }
1073
+ toDOM() {
1074
+ const span = document.createElement("span");
1075
+ span.classList.add(styles.list);
1076
+ span.textContent = this.mark;
1077
+ if (LIST_OF_LIST_MARKS.has(this.lastCodePoint)) {
1078
+ span.classList.add(styles.common);
1079
+ span.classList.add(index.CLASSES.listCommon);
1080
+ }
1081
+ if (CODE_OF_ORDERED_LIST_MARK === this.lastCodePoint) {
1082
+ span.classList.add(styles.ordered);
1083
+ }
1084
+ return span;
1085
+ }
1086
+ }
1087
+
1088
+ function getListSelectionDecorations({ decorations, node, view, isReadonly, }) {
1089
+ if (node.name !== NAME_OF_LIST) {
1090
+ return;
1091
+ }
1092
+ const content = view.state.doc.sliceString(node.from, node.to);
1093
+ const lastCodePoint = content.codePointAt(content.length - 1) || 0;
1094
+ if (!LIST_OF_LIST_MARKS.has(lastCodePoint) && CODE_OF_ORDERED_LIST_MARK !== lastCodePoint) {
1095
+ return;
1096
+ }
1097
+ const nextSibling = node.node.nextSibling;
1098
+ if (nextSibling && nextSibling.name === NAME_OF_TODO$1) {
1099
+ if (isReadonly ||
1100
+ !view.hasFocus ||
1101
+ !isInRange(view.state.selection.ranges, [node.from, nextSibling.from + 3])) {
1102
+ decorations.push(getHideDecoration({ range: [node.from, nextSibling.from] }));
1103
+ }
1104
+ return;
1105
+ }
1106
+ if (isReadonly ||
1107
+ !view.hasFocus ||
1108
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
1109
+ decorations.push(getReplaceDecoration({
1110
+ range: [node.from, node.to],
1111
+ widget: new ListPointWidget(content, lastCodePoint),
1112
+ }));
1113
+ }
1114
+ }
1115
+ const listDecorationPlugin = {
1116
+ selectionDecorations: [getListSelectionDecorations],
1117
+ };
1118
+
1119
+ const CODE_OF_START_MENTION = 64; // @
1120
+ const CODE_OF_SPACE = 32;
1121
+ const NAME_OF_MENTION = "Mention";
1122
+
1123
+ function getMentionDecorations({ decorations, node }) {
1124
+ if (node.name !== NAME_OF_MENTION) {
1125
+ return;
1126
+ }
1127
+ decorations.push(getMarkDecoration({
1128
+ style: clsx(styles.mention, index.CLASSES.mention),
1129
+ range: [node.from, node.to],
1130
+ }));
1131
+ }
1132
+ function getMentionSelectionDecorations({ decorations, node, view, isReadonly, }) {
1133
+ if (node.name !== NAME_OF_MENTION) {
1134
+ return;
1135
+ }
1136
+ if (isReadonly ||
1137
+ !view.hasFocus ||
1138
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
1139
+ decorations.push(getHideDecoration({ range: [node.from, node.from + 1] }));
1140
+ }
1141
+ }
1142
+ const mentionDecorationPlugin = {
1143
+ decorations: [getMentionDecorations],
1144
+ selectionDecorations: [getMentionSelectionDecorations],
1145
+ };
1146
+
1147
+ const NAME_OF_STRIKE_THROUGH = "Strikethrough";
1148
+
1149
+ function getStrikeThroughDecorations({ decorations, node }) {
1150
+ if (node.name !== NAME_OF_STRIKE_THROUGH) {
1151
+ return;
1152
+ }
1153
+ decorations.push(getMarkDecoration({
1154
+ style: styles["strike-through"],
1155
+ range: [node.from, node.to],
1156
+ }));
1157
+ }
1158
+ function getStrikeThroughSelectionDecorations({ decorations, node, view, isReadonly, }) {
1159
+ if (node.name !== NAME_OF_STRIKE_THROUGH) {
1160
+ return;
1161
+ }
1162
+ if (isReadonly ||
1163
+ !view.hasFocus ||
1164
+ !isInRange(view.state.selection.ranges, [node.from, node.to])) {
1165
+ decorations.push(getHideDecoration({ range: [node.from, node.from + 2] }));
1166
+ decorations.push(getHideDecoration({ range: [node.to - 2, node.to] }));
1167
+ }
1168
+ }
1169
+ const strikeThroughDecorationPlugin = {
1170
+ decorations: [getStrikeThroughDecorations],
1171
+ selectionDecorations: [getStrikeThroughSelectionDecorations],
1172
+ };
1173
+
1174
+ const NAME_OF_TODO = "Task";
1175
+ const NAME_OF_LIST_MARK = "ListMark";
1176
+ const LIST_OF_TODO_MARKS = new Set([120, 1093]); // x
1177
+
1178
+ class TodoWidget extends view.WidgetType {
1179
+ checked;
1180
+ position;
1181
+ view;
1182
+ constructor(checked, position) {
1183
+ super();
1184
+ this.checked = checked;
1185
+ this.position = position;
1186
+ }
1187
+ onClick(event) {
1188
+ if (!this.view)
1189
+ return;
1190
+ event.stopPropagation();
1191
+ event.preventDefault();
1192
+ const target = event.target;
1193
+ const change = {
1194
+ from: this.position,
1195
+ to: this.position + 1,
1196
+ insert: this.checked ? " " : "x",
1197
+ };
1198
+ this.view.dispatch(this.view.state.update({ changes: change }));
1199
+ this.checked = !this.checked;
1200
+ target.checked = this.checked;
1201
+ }
1202
+ onBlock(event) {
1203
+ event.stopPropagation();
1204
+ event.preventDefault();
1205
+ }
1206
+ toDOM(view) {
1207
+ const span = document.createElement("span");
1208
+ span.classList.add(styles.todo);
1209
+ this.view = view;
1210
+ const checkbox = document.createElement("input");
1211
+ checkbox.type = "checkbox";
1212
+ checkbox.checked = this.checked;
1213
+ checkbox.addEventListener("click", this.onBlock.bind(this));
1214
+ checkbox.addEventListener("mousedown", this.onClick.bind(this));
1215
+ span.appendChild(checkbox);
1216
+ return span;
1217
+ }
1218
+ destroy(dom) {
1219
+ dom.removeEventListener("click", this.onBlock.bind(this));
1220
+ dom.removeEventListener("mousedown", this.onClick.bind(this));
1221
+ }
1222
+ }
1223
+
1224
+ function getTodoSelectionDecoration({ decorations, node, view, isReadonly, }) {
1225
+ if (node.name !== NAME_OF_TODO)
1226
+ return;
1227
+ const prevSibling = node.node.prevSibling;
1228
+ if (!prevSibling || prevSibling.name !== NAME_OF_LIST_MARK)
1229
+ return;
1230
+ const isChecked = LIST_OF_TODO_MARKS.has(view.state.doc.sliceString(node.from + 1, node.from + 2).codePointAt(0) || 0);
1231
+ if (isReadonly ||
1232
+ !view.hasFocus ||
1233
+ !isInRange(view.state.selection.ranges, [prevSibling.from, node.from + 3])) {
1234
+ decorations.push(getReplaceDecoration({
1235
+ range: [node.from, node.from + 3],
1236
+ widget: new TodoWidget(isChecked, node.from + 1),
1237
+ }));
1238
+ }
1239
+ if (isChecked) {
1240
+ const line = view.lineBlockAt(node.from);
1241
+ if (isReadonly ||
1242
+ !view.hasFocus ||
1243
+ !isInRange(view.state.selection.ranges, [line.from, line.to]))
1244
+ decorations.push(getMarkDecoration({ style: styles.todo__checked, range: [node.from + 4, node.to] }));
1245
+ }
1246
+ }
1247
+ const todoDecorationPlugin = {
1248
+ selectionDecorations: [getTodoSelectionDecoration],
1249
+ };
1250
+
1251
+ const decorationPlugins = [
1252
+ blockquoteDecorationPlugin,
1253
+ boldDecorationPlugin,
1254
+ codeDecorationPlugin,
1255
+ headerDecorationPlugin,
1256
+ horizontalDecorationPlugin,
1257
+ imageDecorationPlugin,
1258
+ italicDecorationPlugin,
1259
+ linkDecorationPlugin,
1260
+ listDecorationPlugin,
1261
+ autoLinkDecorationPlugin,
1262
+ mentionDecorationPlugin,
1263
+ strikeThroughDecorationPlugin,
1264
+ todoDecorationPlugin,
1265
+ ];
1266
+ let decorationFunctions = [];
1267
+ let selectionDecorationFunctions = [];
1268
+ for (const plugin of decorationPlugins) {
1269
+ if (plugin.decorations)
1270
+ decorationFunctions = decorationFunctions.concat(plugin.decorations);
1271
+ if (plugin.selectionDecorations)
1272
+ selectionDecorationFunctions = selectionDecorationFunctions.concat(plugin.selectionDecorations);
1273
+ }
1274
+ const SKIP_MARKS = new Set([
1275
+ "Document",
1276
+ "Paragraph",
1277
+ "EmphasisMark",
1278
+ "Blockquote",
1279
+ "StrikethroughMark",
1280
+ "BulletList",
1281
+ "OrderedList",
1282
+ "ListItem",
1283
+ "LinkMark",
1284
+ "URL",
1285
+ "CodeMark",
1286
+ "CodeInfo",
1287
+ "CodeText",
1288
+ "HeaderMark",
1289
+ "TaskMarker",
1290
+ ]);
1291
+ let markdownDecorations = [];
1292
+ function getDecorations(view$1, isChanged) {
1293
+ const decorations = isChanged ? [] : markdownDecorations;
1294
+ const selectionDecorations = [];
1295
+ const contentEditable = view$1.contentDOM.getAttribute("contenteditable");
1296
+ const isReadonly = !contentEditable || contentEditable === "false";
1297
+ for (const { from: fromVisible, to: toVisible } of view$1.visibleRanges) {
1298
+ language.syntaxTree(view$1.state).iterate({
1299
+ from: fromVisible,
1300
+ to: toVisible,
1301
+ enter: (node) => {
1302
+ if (SKIP_MARKS.has(node.name))
1303
+ return;
1304
+ /** Decoration by change content */
1305
+ if (isChanged) {
1306
+ decorationFunctions.forEach((f) => f({ decorations, node, view: view$1 }));
1307
+ }
1308
+ /** Decoration by selection content */
1309
+ selectionDecorationFunctions.forEach((f) => f({
1310
+ decorations: selectionDecorations,
1311
+ node,
1312
+ view: view$1,
1313
+ isReadonly,
1314
+ }));
1315
+ },
1316
+ });
1317
+ }
1318
+ if (isChanged) {
1319
+ markdownDecorations = decorations;
1320
+ }
1321
+ return view.Decoration.set([...decorations, ...selectionDecorations], true);
1322
+ }
1323
+ const markdownDecorationPlugin = view.ViewPlugin.fromClass(class DecorationMarkdown {
1324
+ decorations;
1325
+ constructor(view) {
1326
+ this.decorations = getDecorations(view, true);
1327
+ }
1328
+ update(update) {
1329
+ const isDocumentChanged = update.docChanged ||
1330
+ update.viewportChanged ||
1331
+ language.syntaxTree(update.startState) != language.syntaxTree(update.state);
1332
+ this.decorations = getDecorations(update.view, isDocumentChanged);
1333
+ }
1334
+ }, {
1335
+ decorations: (plugin) => plugin.decorations,
1336
+ });
1337
+
1338
+ const mentionParser = {
1339
+ defineNodes: [{ name: NAME_OF_MENTION }],
1340
+ parseInline: [
1341
+ {
1342
+ name: NAME_OF_MENTION,
1343
+ parse(cx, next, pos) {
1344
+ if (next != CODE_OF_START_MENTION)
1345
+ return -1;
1346
+ let end = pos + 1;
1347
+ for (let i = pos + 1; i < cx.end; i++) {
1348
+ const next = cx.char(i);
1349
+ if (next === CODE_OF_SPACE)
1350
+ break;
1351
+ end++;
1352
+ }
1353
+ return cx.addElement(cx.elt(NAME_OF_MENTION, pos, end));
1354
+ },
1355
+ },
1356
+ ],
1357
+ };
1358
+
1359
+ const markdownParserPlugin = [mentionParser];
1360
+
1361
+ const initMarkdown = ({ languages }) => {
1362
+ return [
1363
+ langMarkdown.markdown({
1364
+ base: langMarkdown.markdownLanguage,
1365
+ codeLanguages: languages,
1366
+ addKeymap: true,
1367
+ extensions: [markdownParserPlugin],
1368
+ }),
1369
+ markdownDecorationPlugin,
1370
+ ];
1371
+ };
1372
+
1373
+ exports.initMarkdown = initMarkdown;
1374
+ //# sourceMappingURL=index-lPo-3QDL.js.map