@krainovsd/markdown-editor 0.0.4 → 0.1.1
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.
- package/lib/cjs/index-Byjf17iv.js +501 -0
- package/lib/cjs/index-Byjf17iv.js.map +1 -0
- package/lib/cjs/index-lPo-3QDL.js +1374 -0
- package/lib/cjs/index-lPo-3QDL.js.map +1 -0
- package/lib/cjs/index.js +14 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/extensions/compartments/index.js +8 -0
- package/lib/esm/extensions/compartments/index.js.map +1 -0
- package/lib/esm/extensions/init-extensions.js +45 -0
- package/lib/esm/extensions/init-extensions.js.map +1 -0
- package/lib/esm/extensions/keymaps/init-key-map.js +91 -0
- package/lib/esm/extensions/keymaps/init-key-map.js.map +1 -0
- package/lib/esm/extensions/listeners/get-change-event.js +14 -0
- package/lib/esm/extensions/listeners/get-change-event.js.map +1 -0
- package/lib/esm/extensions/listeners/get-focus-event.js +16 -0
- package/lib/esm/extensions/listeners/get-focus-event.js.map +1 -0
- package/lib/esm/extensions/listeners/init-listeners.js +9 -0
- package/lib/esm/extensions/listeners/init-listeners.js.map +1 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js +6 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js +99 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-widget.js +25 -0
- package/lib/esm/extensions/markdown/blockquote/blockquote-widget.js.map +1 -0
- package/lib/esm/extensions/markdown/bold/bold-constants.js +5 -0
- package/lib/esm/extensions/markdown/bold/bold-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/bold/bold-decoration.js +41 -0
- package/lib/esm/extensions/markdown/bold/bold-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/code/code-constants.js +6 -0
- package/lib/esm/extensions/markdown/code/code-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/code/code-decoration.js +109 -0
- package/lib/esm/extensions/markdown/code/code-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/code/code-widget.js +83 -0
- package/lib/esm/extensions/markdown/code/code-widget.js.map +1 -0
- package/lib/esm/extensions/markdown/header/header-constants.js +6 -0
- package/lib/esm/extensions/markdown/header/header-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/header/header-decoration.js +64 -0
- package/lib/esm/extensions/markdown/header/header-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/horizontal/horizontal-constants.js +4 -0
- package/lib/esm/extensions/markdown/horizontal/horizontal-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js +31 -0
- package/lib/esm/extensions/markdown/horizontal/horizontal-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/image/image-constants.js +8 -0
- package/lib/esm/extensions/markdown/image/image-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/image/image-decoration.js +75 -0
- package/lib/esm/extensions/markdown/image/image-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/image/image-widget.js +184 -0
- package/lib/esm/extensions/markdown/image/image-widget.js.map +1 -0
- package/lib/esm/extensions/markdown/index.js +2 -0
- package/lib/esm/extensions/markdown/index.js.map +1 -0
- package/lib/esm/extensions/markdown/init-markdown.js +18 -0
- package/lib/esm/extensions/markdown/init-markdown.js.map +1 -0
- package/lib/esm/extensions/markdown/italic/italic-constants.js +5 -0
- package/lib/esm/extensions/markdown/italic/italic-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/italic/italic-decoration.js +77 -0
- package/lib/esm/extensions/markdown/italic/italic-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/link/auto-link-decoration.js +24 -0
- package/lib/esm/extensions/markdown/link/auto-link-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/link/link-constants.js +10 -0
- package/lib/esm/extensions/markdown/link/link-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/link/link-decoration.js +51 -0
- package/lib/esm/extensions/markdown/link/link-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/link/link-label-decoration.js +22 -0
- package/lib/esm/extensions/markdown/link/link-label-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/link/link-widget.js +144 -0
- package/lib/esm/extensions/markdown/link/link-widget.js.map +1 -0
- package/lib/esm/extensions/markdown/list/list-constants.js +7 -0
- package/lib/esm/extensions/markdown/list/list-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/list/list-decoration.js +38 -0
- package/lib/esm/extensions/markdown/list/list-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/list/list-widget.js +33 -0
- package/lib/esm/extensions/markdown/list/list-widget.js.map +1 -0
- package/lib/esm/extensions/markdown/markdown-decoration.js +105 -0
- package/lib/esm/extensions/markdown/markdown-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/markdown-parser.js +6 -0
- package/lib/esm/extensions/markdown/markdown-parser.js.map +1 -0
- package/lib/esm/extensions/markdown/mention/mention-constants.js +6 -0
- package/lib/esm/extensions/markdown/mention/mention-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/mention/mention-decoration.js +37 -0
- package/lib/esm/extensions/markdown/mention/mention-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/mention/mention-parser.js +25 -0
- package/lib/esm/extensions/markdown/mention/mention-parser.js.map +1 -0
- package/lib/esm/extensions/markdown/strike-through/strike-through-constants.js +4 -0
- package/lib/esm/extensions/markdown/strike-through/strike-through-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js +32 -0
- package/lib/esm/extensions/markdown/strike-through/strike-through-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/styles.module.scss.js +8 -0
- package/lib/esm/extensions/markdown/styles.module.scss.js.map +1 -0
- package/lib/esm/extensions/markdown/todo/todo-constants.js +6 -0
- package/lib/esm/extensions/markdown/todo/todo-constants.js.map +1 -0
- package/lib/esm/extensions/markdown/todo/todo-decoration.js +35 -0
- package/lib/esm/extensions/markdown/todo/todo-decoration.js.map +1 -0
- package/lib/esm/extensions/markdown/todo/todo-widget.js +51 -0
- package/lib/esm/extensions/markdown/todo/todo-widget.js.map +1 -0
- package/lib/esm/extensions/settings/init-settings.js +19 -0
- package/lib/esm/extensions/settings/init-settings.js.map +1 -0
- package/lib/esm/extensions/theme/init-theme.js +15 -0
- package/lib/esm/extensions/theme/init-theme.js.map +1 -0
- package/lib/esm/extensions/theme/theme-constants.js +17 -0
- package/lib/esm/extensions/theme/theme-constants.js.map +1 -0
- package/lib/esm/extensions/theme/themes/get-dark-theme.js +40 -0
- package/lib/esm/extensions/theme/themes/get-dark-theme.js.map +1 -0
- package/lib/esm/extensions/theme/themes/get-highlight-template.js +35 -0
- package/lib/esm/extensions/theme/themes/get-highlight-template.js.map +1 -0
- package/lib/esm/extensions/theme/themes/get-light-theme.js +40 -0
- package/lib/esm/extensions/theme/themes/get-light-theme.js.map +1 -0
- package/lib/esm/extensions/theme/themes/get-theme-template.js +69 -0
- package/lib/esm/extensions/theme/themes/get-theme-template.js.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/lib/utils/copy-to-clipboard.js +35 -0
- package/lib/esm/lib/utils/copy-to-clipboard.js.map +1 -0
- package/lib/esm/lib/utils/get-decoration.js +24 -0
- package/lib/esm/lib/utils/get-decoration.js.map +1 -0
- package/lib/esm/lib/utils/is-in-range.js +8 -0
- package/lib/esm/lib/utils/is-in-range.js.map +1 -0
- package/lib/esm/lib/utils/is-range-overlap.js +6 -0
- package/lib/esm/lib/utils/is-range-overlap.js.map +1 -0
- package/lib/esm/lib/utils/tick.js +22 -0
- package/lib/esm/lib/utils/tick.js.map +1 -0
- package/lib/esm/module/Editor/Editor.js +91 -0
- package/lib/esm/module/Editor/Editor.js.map +1 -0
- package/lib/esm/module/Editor/lib/init-editor-provider.js +32 -0
- package/lib/esm/module/Editor/lib/init-editor-provider.js.map +1 -0
- package/lib/esm/module/Editor/lib/init-editor-state.js +18 -0
- package/lib/esm/module/Editor/lib/init-editor-state.js.map +1 -0
- package/lib/esm/module/Editor/lib/init-editor.js +27 -0
- package/lib/esm/module/Editor/lib/init-editor.js.map +1 -0
- package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js +29 -0
- package/lib/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
- package/lib/index.d.ts +137 -0
- package/package.json +37 -30
- package/lib/cjs/editor-qKPDa91b.js +0 -2
- package/lib/cjs/editor-qKPDa91b.js.map +0 -1
- package/lib/cjs/markdown_plugin-IXFRDWyN.js +0 -2
- package/lib/cjs/markdown_plugin-IXFRDWyN.js.map +0 -1
- package/lib/cjs/vendor_vim-BHa51_r7.js +0 -2
- package/lib/cjs/vendor_vim-BHa51_r7.js.map +0 -1
- package/lib/cjs/vendor_y.next-CVyX1ZQB.js +0 -2
- package/lib/cjs/vendor_y.next-CVyX1ZQB.js.map +0 -1
- package/lib/cjs/vendor_y.websocket-Dr9ojjFR.js +0 -2
- package/lib/cjs/vendor_y.websocket-Dr9ojjFR.js.map +0 -1
- package/lib/cjs/vendor_yjs-DXWp84x5.js +0 -2
- package/lib/cjs/vendor_yjs-DXWp84x5.js.map +0 -1
- package/lib/esm/editor-CLyV23xt.js +0 -2
- package/lib/esm/editor-CLyV23xt.js.map +0 -1
- package/lib/esm/markdown_plugin-DdBeaig8.js +0 -2
- package/lib/esm/markdown_plugin-DdBeaig8.js.map +0 -1
- package/lib/esm/vendor_vim-PF2jWG0J.js +0 -2
- package/lib/esm/vendor_vim-PF2jWG0J.js.map +0 -1
- package/lib/esm/vendor_y.next-B9hhKe5T.js +0 -2
- package/lib/esm/vendor_y.next-B9hhKe5T.js.map +0 -1
- package/lib/esm/vendor_y.websocket-gIpX3Cmo.js +0 -2
- package/lib/esm/vendor_y.websocket-gIpX3Cmo.js.map +0 -1
- package/lib/esm/vendor_yjs-otxZW90b.js +0 -2
- package/lib/esm/vendor_yjs-otxZW90b.js.map +0 -1
- package/tmp/app/helpers/common-test.d.ts +0 -1
- package/tmp/app/helpers/full-example.d.ts +0 -1
- package/tmp/app/helpers/index.d.ts +0 -5
- package/tmp/app/helpers/random-color.d.ts +0 -1
- package/tmp/app/helpers/random-string.d.ts +0 -1
- package/tmp/app/helpers/stress-test.d.ts +0 -1
- package/tmp/app/index.d.ts +0 -1
- package/tmp/extensions/compartments/index.d.ts +0 -4
- package/tmp/extensions/index.d.ts +0 -8
- package/tmp/extensions/init-extensions.d.ts +0 -14
- package/tmp/extensions/keymaps/bold-keymap.d.ts +0 -2
- package/tmp/extensions/keymaps/index.d.ts +0 -1
- package/tmp/extensions/keymaps/init-key-map.d.ts +0 -23
- package/tmp/extensions/keymaps/italic-key-map.d.ts +0 -2
- package/tmp/extensions/keymaps/line-through-key-map.d.ts +0 -2
- package/tmp/extensions/keymaps/underline-key-map.d.ts +0 -2
- package/tmp/extensions/listeners/get-change-event.d.ts +0 -6
- package/tmp/extensions/listeners/get-focus-event.d.ts +0 -8
- package/tmp/extensions/listeners/index.d.ts +0 -3
- package/tmp/extensions/listeners/init-listeners.d.ts +0 -4
- package/tmp/extensions/markdown/blockquote/blockquote-constants.d.ts +0 -3
- package/tmp/extensions/markdown/blockquote/blockquote-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/blockquote/blockquote-widget.d.ts +0 -6
- package/tmp/extensions/markdown/blockquote/index.d.ts +0 -1
- package/tmp/extensions/markdown/bold/bold-constants.d.ts +0 -2
- package/tmp/extensions/markdown/bold/bold-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/bold/index.d.ts +0 -1
- package/tmp/extensions/markdown/code/code-constants.d.ts +0 -3
- package/tmp/extensions/markdown/code/code-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/code/code-widget.d.ts +0 -13
- package/tmp/extensions/markdown/code/index.d.ts +0 -1
- package/tmp/extensions/markdown/header/header-constants.d.ts +0 -3
- package/tmp/extensions/markdown/header/header-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/header/index.d.ts +0 -1
- package/tmp/extensions/markdown/horizontal/horizontal-constants.d.ts +0 -1
- package/tmp/extensions/markdown/horizontal/horizontal-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/horizontal/index.d.ts +0 -1
- package/tmp/extensions/markdown/image/image-constants.d.ts +0 -5
- package/tmp/extensions/markdown/image/image-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/image/image-widget.d.ts +0 -14
- package/tmp/extensions/markdown/image/index.d.ts +0 -1
- package/tmp/extensions/markdown/index.d.ts +0 -2
- package/tmp/extensions/markdown/init-markdown.d.ts +0 -3
- package/tmp/extensions/markdown/italic/index.d.ts +0 -1
- package/tmp/extensions/markdown/italic/italic-constants.d.ts +0 -2
- package/tmp/extensions/markdown/italic/italic-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/link/auto-link-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/link/index.d.ts +0 -2
- package/tmp/extensions/markdown/link/link-constants.d.ts +0 -7
- package/tmp/extensions/markdown/link/link-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/link/link-label-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/link/link-widget.d.ts +0 -17
- package/tmp/extensions/markdown/list/index.d.ts +0 -1
- package/tmp/extensions/markdown/list/list-constants.d.ts +0 -4
- package/tmp/extensions/markdown/list/list-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/list/list-widget.d.ts +0 -7
- package/tmp/extensions/markdown/markdown-decoration.d.ts +0 -5
- package/tmp/extensions/markdown/markdown-parser.d.ts +0 -2
- package/tmp/extensions/markdown/markdown-types.d.ts +0 -24
- package/tmp/extensions/markdown/mention/index.d.ts +0 -1
- package/tmp/extensions/markdown/mention/mention-constants.d.ts +0 -3
- package/tmp/extensions/markdown/mention/mention-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/mention/mention-parser.d.ts +0 -2
- package/tmp/extensions/markdown/strike-through/index.d.ts +0 -1
- package/tmp/extensions/markdown/strike-through/strike-through-constants.d.ts +0 -1
- package/tmp/extensions/markdown/strike-through/strike-through-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/todo/index.d.ts +0 -1
- package/tmp/extensions/markdown/todo/todo-constants.d.ts +0 -3
- package/tmp/extensions/markdown/todo/todo-decoration.d.ts +0 -2
- package/tmp/extensions/markdown/todo/todo-widget.d.ts +0 -11
- package/tmp/extensions/settings/index.d.ts +0 -1
- package/tmp/extensions/settings/init-settings.d.ts +0 -6
- package/tmp/extensions/theme/index.d.ts +0 -4
- package/tmp/extensions/theme/init-theme.d.ts +0 -3
- package/tmp/extensions/theme/theme-constants.d.ts +0 -14
- package/tmp/extensions/theme/theme-types.d.ts +0 -39
- package/tmp/extensions/theme/themes/get-dark-theme.d.ts +0 -2
- package/tmp/extensions/theme/themes/get-highlight-template.d.ts +0 -6
- package/tmp/extensions/theme/themes/get-light-theme.d.ts +0 -2
- package/tmp/extensions/theme/themes/get-theme-template.d.ts +0 -2
- package/tmp/extensions/theme/themes/index.d.ts +0 -2
- package/tmp/index.d.ts +0 -3
- package/tmp/lib/index.d.ts +0 -1
- package/tmp/lib/utils/copy-to-clipboard.d.ts +0 -1
- package/tmp/lib/utils/get-decoration.d.ts +0 -26
- package/tmp/lib/utils/index.d.ts +0 -6
- package/tmp/lib/utils/is-in-range.d.ts +0 -2
- package/tmp/lib/utils/is-range-overlap.d.ts +0 -1
- package/tmp/lib/utils/random-string.d.ts +0 -1
- package/tmp/lib/utils/tick.d.ts +0 -10
- package/tmp/module/Editor/Editor.d.ts +0 -18
- package/tmp/module/Editor/Editor.types.d.ts +0 -13
- package/tmp/module/Editor/index.d.ts +0 -3
- package/tmp/module/Editor/lib/index.d.ts +0 -1
- package/tmp/module/Editor/lib/init-editor-provider.d.ts +0 -9
- package/tmp/module/Editor/lib/init-editor-state.d.ts +0 -7
- package/tmp/module/Editor/lib/init-editor.d.ts +0 -7
- package/tmp/module/index.d.ts +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import '@codemirror/view';
|
|
3
|
+
import '../../compartments/index.js';
|
|
4
|
+
import '@codemirror/language';
|
|
5
|
+
import '@lezer/highlight';
|
|
6
|
+
import { CLASSES } from '../../theme/theme-constants.js';
|
|
7
|
+
import { getLineDecoration, getHideDecoration, getReplaceDecoration } from '../../../lib/utils/get-decoration.js';
|
|
8
|
+
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
9
|
+
import styles from '../styles.module.scss.js';
|
|
10
|
+
import { NAME_OF_BLOCKQUOTE_MARK, CODE_OF_SPACE, CODE_OF_BLOCKQUOTE_MARK } from './blockquote-constants.js';
|
|
11
|
+
import { BlockquoteWidget } from './blockquote-widget.js';
|
|
12
|
+
|
|
13
|
+
function getBlockquoteDecorations({ decorations, node, view }) {
|
|
14
|
+
if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const line = view.lineBlockAt(node.from);
|
|
18
|
+
let isInner = false;
|
|
19
|
+
if (line.from !== node.from) {
|
|
20
|
+
const content = view.state.doc.sliceString(line.from, node.to);
|
|
21
|
+
let pos = content.length - 1;
|
|
22
|
+
let isHasMark = false;
|
|
23
|
+
while (pos >= 0) {
|
|
24
|
+
pos--;
|
|
25
|
+
const currentCode = content.charCodeAt(pos);
|
|
26
|
+
if (currentCode === CODE_OF_SPACE)
|
|
27
|
+
continue;
|
|
28
|
+
if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
|
|
29
|
+
if (!isHasMark) {
|
|
30
|
+
isHasMark = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!isInner) {
|
|
34
|
+
isInner = true;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
pos = -1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!isInner) {
|
|
42
|
+
decorations.push(getLineDecoration({
|
|
43
|
+
style: clsx(styles.blockquote, CLASSES.blockquote),
|
|
44
|
+
range: [line.from],
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getBlockquoteSelectionDecorations({ decorations, node, view, isReadonly, }) {
|
|
49
|
+
if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const line = view.lineBlockAt(node.from);
|
|
53
|
+
let isInner = false;
|
|
54
|
+
let isDeepInner = false;
|
|
55
|
+
if (line.from !== node.from) {
|
|
56
|
+
const content = view.state.doc.sliceString(line.from, node.to);
|
|
57
|
+
let pos = content.length;
|
|
58
|
+
let isHasMark = false;
|
|
59
|
+
while (pos >= 0) {
|
|
60
|
+
pos--;
|
|
61
|
+
const currentCode = content.charCodeAt(pos);
|
|
62
|
+
if (currentCode === CODE_OF_SPACE)
|
|
63
|
+
continue;
|
|
64
|
+
if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {
|
|
65
|
+
if (!isHasMark) {
|
|
66
|
+
isHasMark = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!isInner) {
|
|
70
|
+
isInner = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!isDeepInner) {
|
|
74
|
+
isDeepInner = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
pos = -1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (isReadonly ||
|
|
82
|
+
!view.hasFocus ||
|
|
83
|
+
!isInRange(view.state.selection.ranges, [line.from, line.to])) {
|
|
84
|
+
if (!isInner)
|
|
85
|
+
decorations.push(getHideDecoration({ range: [node.from, node.to] }));
|
|
86
|
+
else
|
|
87
|
+
decorations.push(getReplaceDecoration({
|
|
88
|
+
widget: new BlockquoteWidget(isDeepInner),
|
|
89
|
+
range: [node.from, node.to],
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const blockquoteDecorationPlugin = {
|
|
94
|
+
decorations: [getBlockquoteDecorations],
|
|
95
|
+
selectionDecorations: [getBlockquoteSelectionDecorations],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export { blockquoteDecorationPlugin };
|
|
99
|
+
//# sourceMappingURL=blockquote-decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockquote-decoration.js","sources":["../../../../../src/extensions/markdown/blockquote/blockquote-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport {\n CODE_OF_BLOCKQUOTE_MARK,\n CODE_OF_SPACE,\n NAME_OF_BLOCKQUOTE_MARK,\n} from \"./blockquote-constants\";\nimport { BlockquoteWidget } from \"./blockquote-widget\";\n\nfunction getBlockquoteDecorations({ decorations, node, view }: GetDecorationOptions) {\n if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {\n return;\n }\n\n const line = view.lineBlockAt(node.from);\n let isInner = false;\n\n if (line.from !== node.from) {\n const content = view.state.doc.sliceString(line.from, node.to);\n let pos = content.length - 1;\n let isHasMark = false;\n\n while (pos >= 0) {\n pos--;\n const currentCode = content.charCodeAt(pos);\n if (currentCode === CODE_OF_SPACE) continue;\n if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {\n if (!isHasMark) {\n isHasMark = true;\n continue;\n }\n if (!isInner) {\n isInner = true;\n break;\n }\n }\n pos = -1;\n }\n }\n\n if (!isInner) {\n decorations.push(\n utils.getLineDecoration({\n style: clsx(styles.blockquote, CLASSES.blockquote),\n range: [line.from],\n }),\n );\n }\n}\n\nfunction getBlockquoteSelectionDecorations({\n decorations,\n node,\n view,\n isReadonly,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_BLOCKQUOTE_MARK) {\n return;\n }\n\n const line = view.lineBlockAt(node.from);\n let isInner = false;\n let isDeepInner = false;\n\n if (line.from !== node.from) {\n const content = view.state.doc.sliceString(line.from, node.to);\n let pos = content.length;\n let isHasMark = false;\n\n while (pos >= 0) {\n pos--;\n const currentCode = content.charCodeAt(pos);\n\n if (currentCode === CODE_OF_SPACE) continue;\n if (currentCode === CODE_OF_BLOCKQUOTE_MARK) {\n if (!isHasMark) {\n isHasMark = true;\n continue;\n }\n if (!isInner) {\n isInner = true;\n continue;\n }\n if (!isDeepInner) {\n isDeepInner = true;\n break;\n }\n }\n pos = -1;\n }\n }\n\n if (\n isReadonly ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [line.from, line.to])\n ) {\n if (!isInner) decorations.push(utils.getHideDecoration({ range: [node.from, node.to] }));\n else\n decorations.push(\n utils.getReplaceDecoration({\n widget: new BlockquoteWidget(isDeepInner),\n range: [node.from, node.to],\n }),\n );\n }\n}\n\nexport const blockquoteDecorationPlugin: DecorationPlugin = {\n decorations: [getBlockquoteDecorations],\n selectionDecorations: [getBlockquoteSelectionDecorations],\n};\n"],"names":["utils.getLineDecoration","utils.isInRange","utils.getHideDecoration","utils.getReplaceDecoration"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,wBAAwB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAwB,EAAA;AACjF,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,uBAAuB,EAAE;QACzC;;IAGF,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IACxC,IAAI,OAAO,GAAG,KAAK;IAEnB,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AAC3B,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAA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ments/index.js';
|
|
3
|
+
import '@codemirror/language';
|
|
4
|
+
import '@lezer/highlight';
|
|
5
|
+
import { CLASSES } from '../../theme/theme-constants.js';
|
|
6
|
+
import styles from '../styles.module.scss.js';
|
|
7
|
+
|
|
8
|
+
class BlockquoteWidget extends WidgetType {
|
|
9
|
+
deep;
|
|
10
|
+
constructor(deep) {
|
|
11
|
+
super();
|
|
12
|
+
this.deep = deep;
|
|
13
|
+
}
|
|
14
|
+
toDOM() {
|
|
15
|
+
const span = document.createElement("span");
|
|
16
|
+
span.classList.add(styles.blockquote__inner);
|
|
17
|
+
if (this.deep)
|
|
18
|
+
span.classList.add(styles["blockquote__inner-deep"]);
|
|
19
|
+
span.classList.add(CLASSES.blockquoteInner);
|
|
20
|
+
return span;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { BlockquoteWidget };
|
|
25
|
+
//# sourceMappingURL=blockquote-widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockquote-widget.js","sources":["../../../../../src/extensions/markdown/blockquote/blockquote-widget.ts"],"sourcesContent":["import { WidgetType } from \"@codemirror/view\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport styles from \"../styles.module.scss\";\n\nexport class BlockquoteWidget extends WidgetType {\n constructor(private readonly deep: boolean) {\n super();\n }\n\n toDOM(): HTMLElement {\n const span = document.createElement(\"span\");\n span.classList.add(styles.blockquote__inner);\n if (this.deep) span.classList.add(styles[\"blockquote__inner-deep\"]);\n span.classList.add(CLASSES.blockquoteInner);\n\n return span;\n }\n}\n"],"names":[],"mappings":";;;;;;;AAIM,MAAO,gBAAiB,SAAQ,UAAU,CAAA;AACjB,IAAA,IAAA;AAA7B,IAAA,WAAA,CAA6B,IAAa,EAAA;AACxC,QAAA,KAAK,EAAE;QADoB,IAAI,CAAA,IAAA,GAAJ,IAAI;;IAIjC,KAAK,GAAA;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;QAC3C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC;QAC5C,IAAI,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC;AAE3C,QAAA,OAAO,IAAI;;AAEd;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bold-constants.js","sources":["../../../../../src/extensions/markdown/bold/bold-constants.ts"],"sourcesContent":["export const NAME_OF_BOLD = \"StrongEmphasis\";\nexport const LIST_OF_BOLD_MARKS = new Set([95, 42]); // _ *\n"],"names":[],"mappings":"AAAO,MAAM,YAAY,GAAG;AACrB,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { syntaxTree } from '@codemirror/language';
|
|
2
|
+
import { getMarkDecoration, getHideDecoration } from '../../../lib/utils/get-decoration.js';
|
|
3
|
+
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
4
|
+
import styles from '../styles.module.scss.js';
|
|
5
|
+
import { NAME_OF_BOLD, LIST_OF_BOLD_MARKS } from './bold-constants.js';
|
|
6
|
+
|
|
7
|
+
function getBoldDecorations({ decorations, node, view }) {
|
|
8
|
+
if (node.name !== NAME_OF_BOLD) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const step = LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&
|
|
12
|
+
syntaxTree(view.state).resolve(node.from - 1).type.name !== "Emphasis"
|
|
13
|
+
? 1
|
|
14
|
+
: 0;
|
|
15
|
+
decorations.push(getMarkDecoration({
|
|
16
|
+
style: styles.bold,
|
|
17
|
+
range: [node.from - step, node.to + step],
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
function getBoldSelectionDecorations({ decorations, node, view, isReadonly, }) {
|
|
21
|
+
if (node.name !== NAME_OF_BOLD) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&
|
|
25
|
+
syntaxTree(view.state).resolve(node.from - 1).type.name !== "Emphasis") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (isReadonly ||
|
|
29
|
+
!view.hasFocus ||
|
|
30
|
+
!isInRange(view.state.selection.ranges, [node.from, node.to])) {
|
|
31
|
+
decorations.push(getHideDecoration({ range: [node.from, node.from + 2] }));
|
|
32
|
+
decorations.push(getHideDecoration({ range: [node.to - 2, node.to] }));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const boldDecorationPlugin = {
|
|
36
|
+
decorations: [getBoldDecorations],
|
|
37
|
+
selectionDecorations: [getBoldSelectionDecorations],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { boldDecorationPlugin };
|
|
41
|
+
//# sourceMappingURL=bold-decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bold-decoration.js","sources":["../../../../../src/extensions/markdown/bold/bold-decoration.ts"],"sourcesContent":["import { syntaxTree } from \"@codemirror/language\";\nimport { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { LIST_OF_BOLD_MARKS, NAME_OF_BOLD } from \"./bold-constants\";\n\nfunction getBoldDecorations({ decorations, node, view }: GetDecorationOptions) {\n if (node.name !== NAME_OF_BOLD) {\n return;\n }\n\n const step =\n LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&\n syntaxTree(view.state).resolve(node.from - 1).type.name !== \"Emphasis\"\n ? 1\n : 0;\n\n decorations.push(\n utils.getMarkDecoration({\n style: styles.bold,\n range: [node.from - step, node.to + step],\n }),\n );\n}\n\nfunction getBoldSelectionDecorations({\n decorations,\n node,\n view,\n isReadonly,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_BOLD) {\n return;\n }\n\n if (\n LIST_OF_BOLD_MARKS.has(view.state.doc.sliceString(node.from - 1, node.from).charCodeAt(0)) &&\n syntaxTree(view.state).resolve(node.from - 1).type.name !== \"Emphasis\"\n ) {\n return;\n }\n\n if (\n isReadonly ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [node.from, node.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [node.from, node.from + 2] }));\n decorations.push(utils.getHideDecoration({ range: [node.to - 2, node.to] }));\n }\n}\n\nexport const boldDecorationPlugin: DecorationPlugin = {\n decorations: [getBoldDecorations],\n selectionDecorations: [getBoldSelectionDecorations],\n};\n"],"names":["utils.getMarkDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;;AAUA,SAAS,kBAAkB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAwB,EAAA;AAC3E,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE;QAC9B;;AAGF,IAAA,MAAM,IAAI,GACR,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC1F,QAAA,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK;AAC1D,UAAE;UACA,CAAC;AAEP,IAAA,WAAW,CAAC,IAAI,CACdA,iBAAuB,CAAC;QACtB,KAAK,EAAE,MAAM,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@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-constants.js","sources":["../../../../../src/extensions/markdown/code/code-constants.ts"],"sourcesContent":["export const NAME_OF_FENCED_CODE = \"FencedCode\";\nexport const NAME_OF_INLINE_CODE = \"InlineCode\";\nexport const CODE_OF_CODE_MARK = 96; // `\n"],"names":[],"mappings":"AAAO,MAAM,mBAAmB,GAAG;AAC5B,MAAM,mBAAmB,GAAG;AACtB,MAAA,iBAAiB,GAAG,GAAG;;;;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import '@codemirror/view';
|
|
3
|
+
import '../../compartments/index.js';
|
|
4
|
+
import '@codemirror/language';
|
|
5
|
+
import '@lezer/highlight';
|
|
6
|
+
import { CLASSES } from '../../theme/theme-constants.js';
|
|
7
|
+
import { getLineDecoration, getMarkDecoration, getHideDecoration, getWidgetDecorationOptions } from '../../../lib/utils/get-decoration.js';
|
|
8
|
+
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
9
|
+
import { isRangeOverlap } from '../../../lib/utils/is-range-overlap.js';
|
|
10
|
+
import styles from '../styles.module.scss.js';
|
|
11
|
+
import { NAME_OF_FENCED_CODE, NAME_OF_INLINE_CODE, CODE_OF_CODE_MARK } from './code-constants.js';
|
|
12
|
+
import { CodeWidget } from './code-widget.js';
|
|
13
|
+
|
|
14
|
+
function getCodeSelectionDecorations({ decorations, node, view, isReadonly, }) {
|
|
15
|
+
if (node.name !== NAME_OF_FENCED_CODE && node.name !== NAME_OF_INLINE_CODE) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let isOverlapLine = false;
|
|
19
|
+
const startMarkPosition = { from: -1, to: -1 };
|
|
20
|
+
const endMarkPosition = { from: -1, to: -1 };
|
|
21
|
+
const lines = view.viewportLineBlocks.filter((line) => {
|
|
22
|
+
const isOverlap = isRangeOverlap([node.from, node.to], [line.from, line.to]);
|
|
23
|
+
if (isOverlap && isInRange(view.state.selection.ranges, [line.from, line.to]))
|
|
24
|
+
isOverlapLine = true;
|
|
25
|
+
return isOverlap;
|
|
26
|
+
});
|
|
27
|
+
let languagePos;
|
|
28
|
+
let language;
|
|
29
|
+
let codeContent;
|
|
30
|
+
const content = view.state.doc.sliceString(node.from, node.to);
|
|
31
|
+
let pos = -1;
|
|
32
|
+
while ((startMarkPosition.from === -1 || startMarkPosition.to === -1) &&
|
|
33
|
+
pos >= -1 &&
|
|
34
|
+
pos < content.length) {
|
|
35
|
+
pos++;
|
|
36
|
+
const code = content.charCodeAt(pos);
|
|
37
|
+
if (code !== CODE_OF_CODE_MARK && startMarkPosition.from === -1)
|
|
38
|
+
continue;
|
|
39
|
+
else if (code === CODE_OF_CODE_MARK && startMarkPosition.from === -1)
|
|
40
|
+
startMarkPosition.from = node.from + pos;
|
|
41
|
+
else if (code !== CODE_OF_CODE_MARK && startMarkPosition.from !== -1)
|
|
42
|
+
startMarkPosition.to = node.from + pos;
|
|
43
|
+
}
|
|
44
|
+
pos = content.length;
|
|
45
|
+
while ((endMarkPosition.from === -1 || endMarkPosition.to === -1) &&
|
|
46
|
+
pos >= -1 &&
|
|
47
|
+
pos <= content.length) {
|
|
48
|
+
pos--;
|
|
49
|
+
const code = content.charCodeAt(pos);
|
|
50
|
+
if (code !== CODE_OF_CODE_MARK && endMarkPosition.to === -1)
|
|
51
|
+
continue;
|
|
52
|
+
else if (code === CODE_OF_CODE_MARK && endMarkPosition.to === -1)
|
|
53
|
+
endMarkPosition.to = node.from + pos + 1;
|
|
54
|
+
else if (code !== CODE_OF_CODE_MARK && endMarkPosition.to !== -1)
|
|
55
|
+
endMarkPosition.from = node.from + pos + 1;
|
|
56
|
+
}
|
|
57
|
+
if (node.name === NAME_OF_FENCED_CODE) {
|
|
58
|
+
const codeInfo = node.node.getChild("CodeInfo");
|
|
59
|
+
const codeText = node.node.getChild("CodeText");
|
|
60
|
+
if (codeInfo) {
|
|
61
|
+
language = view.state.doc.sliceString(codeInfo.from, codeInfo.to);
|
|
62
|
+
languagePos = [codeInfo.from, codeInfo.to];
|
|
63
|
+
}
|
|
64
|
+
if (codeText)
|
|
65
|
+
codeContent = view.state.doc.sliceString(codeText.from, codeText.to);
|
|
66
|
+
else
|
|
67
|
+
codeContent = "";
|
|
68
|
+
}
|
|
69
|
+
if (node.name === NAME_OF_INLINE_CODE) {
|
|
70
|
+
codeContent = view.state.doc.sliceString(startMarkPosition.to, endMarkPosition.from).trim();
|
|
71
|
+
}
|
|
72
|
+
if (!language)
|
|
73
|
+
language = "copy";
|
|
74
|
+
if (lines.length > 1) {
|
|
75
|
+
lines.forEach((line) => {
|
|
76
|
+
decorations.push(getLineDecoration({
|
|
77
|
+
style: clsx(styles.code__line, CLASSES.code),
|
|
78
|
+
range: [line.from],
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
decorations.push(getMarkDecoration({
|
|
84
|
+
style: clsx(styles.code__single, CLASSES.code),
|
|
85
|
+
range: [node.from, node.to],
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
if (isReadonly ||
|
|
89
|
+
!view.hasFocus ||
|
|
90
|
+
(lines.length > 1 && !isOverlapLine) ||
|
|
91
|
+
(lines.length === 1 && !isInRange(view.state.selection.ranges, [node.from, node.to]))) {
|
|
92
|
+
if (lines.length > 1 && language) {
|
|
93
|
+
if (languagePos)
|
|
94
|
+
decorations.push(getHideDecoration({ range: languagePos }));
|
|
95
|
+
decorations.push(getWidgetDecorationOptions({
|
|
96
|
+
widget: new CodeWidget(language, codeContent),
|
|
97
|
+
range: [node.from],
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
decorations.push(getHideDecoration({ range: [startMarkPosition.from, startMarkPosition.to] }));
|
|
101
|
+
decorations.push(getHideDecoration({ range: [endMarkPosition.from, endMarkPosition.to] }));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const codeDecorationPlugin = {
|
|
105
|
+
selectionDecorations: [getCodeSelectionDecorations],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { codeDecorationPlugin };
|
|
109
|
+
//# sourceMappingURL=code-decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-decoration.js","sources":["../../../../../src/extensions/markdown/code/code-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { CODE_OF_CODE_MARK, NAME_OF_FENCED_CODE, NAME_OF_INLINE_CODE } from \"./code-constants\";\nimport { CodeWidget } from \"./code-widget\";\n\nfunction getCodeSelectionDecorations({\n decorations,\n node,\n view,\n isReadonly,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_FENCED_CODE && node.name !== NAME_OF_INLINE_CODE) {\n return;\n }\n\n let isOverlapLine = false;\n const startMarkPosition = { from: -1, to: -1 };\n const endMarkPosition = { from: -1, to: -1 };\n const lines = view.viewportLineBlocks.filter((line) => {\n const isOverlap = utils.isRangeOverlap([node.from, node.to], [line.from, line.to]);\n if (isOverlap && utils.isInRange(view.state.selection.ranges, [line.from, line.to]))\n isOverlapLine = true;\n\n return isOverlap;\n });\n let languagePos: [number, number] | undefined;\n let language: string | undefined;\n let codeContent: string | undefined;\n\n const content = view.state.doc.sliceString(node.from, node.to);\n let pos = -1;\n while (\n (startMarkPosition.from === -1 || startMarkPosition.to === -1) &&\n pos >= -1 &&\n pos < content.length\n ) {\n pos++;\n const code = content.charCodeAt(pos);\n\n if (code !== CODE_OF_CODE_MARK && startMarkPosition.from === -1) continue;\n else if (code === CODE_OF_CODE_MARK && startMarkPosition.from === -1)\n startMarkPosition.from = node.from + pos;\n else if (code !== CODE_OF_CODE_MARK && startMarkPosition.from !== -1)\n startMarkPosition.to = node.from + pos;\n }\n\n pos = content.length;\n\n while (\n (endMarkPosition.from === -1 || endMarkPosition.to === -1) &&\n pos >= -1 &&\n pos <= content.length\n ) {\n pos--;\n const code = content.charCodeAt(pos);\n\n if (code !== CODE_OF_CODE_MARK && endMarkPosition.to === -1) continue;\n else if (code === CODE_OF_CODE_MARK && endMarkPosition.to === -1)\n endMarkPosition.to = node.from + pos + 1;\n else if (code !== CODE_OF_CODE_MARK && endMarkPosition.to !== -1)\n endMarkPosition.from = node.from + pos + 1;\n }\n\n if (node.name === NAME_OF_FENCED_CODE) {\n const codeInfo = node.node.getChild(\"CodeInfo\");\n const codeText = node.node.getChild(\"CodeText\");\n\n if (codeInfo) {\n language = view.state.doc.sliceString(codeInfo.from, codeInfo.to);\n languagePos = [codeInfo.from, codeInfo.to];\n }\n if (codeText) codeContent = view.state.doc.sliceString(codeText.from, codeText.to);\n else codeContent = \"\";\n }\n if (node.name === NAME_OF_INLINE_CODE) {\n codeContent = view.state.doc.sliceString(startMarkPosition.to, endMarkPosition.from).trim();\n }\n if (!language) language = \"copy\";\n\n if (lines.length > 1) {\n lines.forEach((line) => {\n decorations.push(\n utils.getLineDecoration({\n style: clsx(styles.code__line, CLASSES.code),\n range: [line.from],\n }),\n );\n });\n } else {\n decorations.push(\n utils.getMarkDecoration({\n style: clsx(styles.code__single, CLASSES.code),\n range: [node.from, node.to],\n }),\n );\n }\n\n if (\n isReadonly ||\n !view.hasFocus ||\n (lines.length > 1 && !isOverlapLine) ||\n (lines.length === 1 && !utils.isInRange(view.state.selection.ranges, [node.from, node.to]))\n ) {\n if (lines.length > 1 && language) {\n if (languagePos) decorations.push(utils.getHideDecoration({ range: languagePos }));\n decorations.push(\n utils.getWidgetDecorationOptions({\n widget: new CodeWidget(language, codeContent),\n range: [node.from],\n }),\n );\n }\n decorations.push(\n utils.getHideDecoration({ range: [startMarkPosition.from, startMarkPosition.to] }),\n );\n decorations.push(\n utils.getHideDecoration({ range: [endMarkPosition.from, endMarkPosition.to] }),\n );\n }\n}\n\nexport const codeDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getCodeSelectionDecorations],\n};\n"],"names":["utils.isRangeOverlap","utils.isInRange","utils.getLineDecoration","utils.getMarkDecoration","utils.getHideDecoration","utils.getWidgetDecorationOptions"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,2BAA2B,CAAC,EACnC,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,UAAU,GACoB,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE;QAC1E;;IAGF,IAAI,aAAa,GAAG,KAAK;AACzB,IAAA,MAAM,iBAAiB,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;AAC9C,IAAA,MAAM,eAAe,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,IAAI,KAAI;QACpD,MAAM,SAAS,GAAGA,cAAoB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAClF,IAAI,SAAS,IAAIC,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YACjF,aAAa,GAAG,IAAI;AAEtB,QAAA,OAAO,SAAS;AAClB,KAAC,CAAC;AACF,IAAA,IAAI,WAAyC;AAC7C,IAAA,IAAI,QAA4B;AAChC,IAAA,IAAI,WAA+B;AAEnC,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC9D,IAAA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C,EAAE,CAAC,EAAE,CAAC,CAC/E;;AAEL;AAEa,MAAA,oBAAoB,GAAqB;IACpD,oBAAoB,EAAE,CAAC,2BAA2B,CAAC;;;;;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { WidgetType } from '@codemirror/view';
|
|
2
|
+
import '../../compartments/index.js';
|
|
3
|
+
import '@codemirror/language';
|
|
4
|
+
import '@lezer/highlight';
|
|
5
|
+
import { CLASSES } from '../../theme/theme-constants.js';
|
|
6
|
+
import { copyToClipboard } from '../../../lib/utils/copy-to-clipboard.js';
|
|
7
|
+
import styles from '../styles.module.scss.js';
|
|
8
|
+
|
|
9
|
+
class CodeWidget extends WidgetType {
|
|
10
|
+
language;
|
|
11
|
+
content;
|
|
12
|
+
view;
|
|
13
|
+
timer;
|
|
14
|
+
button;
|
|
15
|
+
span;
|
|
16
|
+
constructor(language, content) {
|
|
17
|
+
super();
|
|
18
|
+
this.language = language;
|
|
19
|
+
this.content = content;
|
|
20
|
+
}
|
|
21
|
+
onClick() {
|
|
22
|
+
if (this.content && this.button && this.span) {
|
|
23
|
+
const span = this.span;
|
|
24
|
+
const button = this.button;
|
|
25
|
+
clearTimeout(this.timer);
|
|
26
|
+
button.classList.remove(styles.pending);
|
|
27
|
+
button.classList.remove(CLASSES.codeButtonPending);
|
|
28
|
+
button.classList.remove(styles.success);
|
|
29
|
+
button.classList.remove(CLASSES.codeButtonSuccess);
|
|
30
|
+
button.classList.remove(styles.fail);
|
|
31
|
+
button.classList.remove(CLASSES.codeButtonFail);
|
|
32
|
+
button.classList.add(styles.pending);
|
|
33
|
+
button.classList.add(CLASSES.codeButtonPending);
|
|
34
|
+
span.classList.add(styles.hide);
|
|
35
|
+
void copyToClipboard(this.content)
|
|
36
|
+
.then(() => {
|
|
37
|
+
button.classList.remove(styles.pending);
|
|
38
|
+
button.classList.remove(CLASSES.codeButtonPending);
|
|
39
|
+
button.classList.add(styles.success);
|
|
40
|
+
button.classList.add(CLASSES.codeButtonSuccess);
|
|
41
|
+
this.timer = setTimeout(() => {
|
|
42
|
+
button.classList.remove(styles.success);
|
|
43
|
+
button.classList.remove(CLASSES.codeButtonSuccess);
|
|
44
|
+
span.classList.remove(styles.hide);
|
|
45
|
+
}, 500);
|
|
46
|
+
})
|
|
47
|
+
.catch(() => {
|
|
48
|
+
button.classList.remove(styles.pending);
|
|
49
|
+
button.classList.remove(CLASSES.codeButtonPending);
|
|
50
|
+
button.classList.add(styles.fail);
|
|
51
|
+
button.classList.add(CLASSES.codeButtonFail);
|
|
52
|
+
this.timer = setTimeout(() => {
|
|
53
|
+
button.classList.remove(styles.fail);
|
|
54
|
+
button.classList.remove(CLASSES.codeButtonFail);
|
|
55
|
+
span.classList.remove(styles.hide);
|
|
56
|
+
}, 500);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
toDOM(view) {
|
|
61
|
+
this.view = view;
|
|
62
|
+
const span = document.createElement("span");
|
|
63
|
+
span.classList.add(styles.code__span);
|
|
64
|
+
span.classList.add(CLASSES.codeButtonSpan);
|
|
65
|
+
span.textContent = this.language;
|
|
66
|
+
const button = document.createElement("button");
|
|
67
|
+
button.classList.add(styles.code__button);
|
|
68
|
+
button.classList.add(CLASSES.codeButton);
|
|
69
|
+
if (this.content)
|
|
70
|
+
button.addEventListener("click", this.onClick.bind(this));
|
|
71
|
+
button.appendChild(span);
|
|
72
|
+
this.button = button;
|
|
73
|
+
this.span = span;
|
|
74
|
+
return button;
|
|
75
|
+
}
|
|
76
|
+
destroy(dom) {
|
|
77
|
+
if (this.content)
|
|
78
|
+
dom.removeEventListener("click", this.onClick.bind(this));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { CodeWidget };
|
|
83
|
+
//# sourceMappingURL=code-widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-widget.js","sources":["../../../../../src/extensions/markdown/code/code-widget.ts"],"sourcesContent":["import { type EditorView, WidgetType } from \"@codemirror/view\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport styles from \"../styles.module.scss\";\n\nexport class CodeWidget extends WidgetType {\n view: EditorView | undefined;\n\n timer: NodeJS.Timeout | undefined;\n\n button: HTMLElement | undefined;\n\n span: HTMLElement | undefined;\n\n constructor(\n private readonly language: string,\n private content: string | undefined,\n ) {\n super();\n }\n\n onClick() {\n if (this.content && this.button && this.span) {\n const span = this.span;\n const button = this.button;\n clearTimeout(this.timer);\n button.classList.remove(styles.pending);\n button.classList.remove(CLASSES.codeButtonPending);\n button.classList.remove(styles.success);\n button.classList.remove(CLASSES.codeButtonSuccess);\n button.classList.remove(styles.fail);\n button.classList.remove(CLASSES.codeButtonFail);\n\n button.classList.add(styles.pending);\n button.classList.add(CLASSES.codeButtonPending);\n\n span.classList.add(styles.hide);\n\n void utils\n .copyToClipboard(this.content)\n .then(() => {\n button.classList.remove(styles.pending);\n button.classList.remove(CLASSES.codeButtonPending);\n\n button.classList.add(styles.success);\n button.classList.add(CLASSES.codeButtonSuccess);\n\n this.timer = setTimeout(() => {\n button.classList.remove(styles.success);\n button.classList.remove(CLASSES.codeButtonSuccess);\n span.classList.remove(styles.hide);\n }, 500);\n })\n .catch(() => {\n button.classList.remove(styles.pending);\n button.classList.remove(CLASSES.codeButtonPending);\n button.classList.add(styles.fail);\n button.classList.add(CLASSES.codeButtonFail);\n\n this.timer = setTimeout(() => {\n button.classList.remove(styles.fail);\n button.classList.remove(CLASSES.codeButtonFail);\n\n span.classList.remove(styles.hide);\n }, 500);\n });\n }\n }\n\n toDOM(view: EditorView): HTMLElement {\n this.view = view;\n\n const span = document.createElement(\"span\");\n span.classList.add(styles.code__span);\n span.classList.add(CLASSES.codeButtonSpan);\n\n span.textContent = this.language;\n\n const button = document.createElement(\"button\");\n button.classList.add(styles.code__button);\n button.classList.add(CLASSES.codeButton);\n\n if (this.content) button.addEventListener(\"click\", this.onClick.bind(this));\n button.appendChild(span);\n\n this.button = button;\n this.span = span;\n\n return button;\n }\n\n destroy(dom: HTMLElement): void {\n if (this.content) dom.removeEventListener(\"click\", this.onClick.bind(this));\n }\n}\n"],"names":["utils\n .copyToClipboard"],"mappings":";;;;;;;;AAKM,MAAO,UAAW,SAAQ,UAAU,CAAA;AAUrB,IAAA,QAAA;AACT,IAAA,OAAA;AAVV,IAAA,IAAI;AAEJ,IAAA,KAAK;AAEL,IAAA,MAAM;AAEN,IAAA,IAAI;IAEJ,WACmB,CAAA,QAAgB,EACzB,OAA2B,EAAA;AAEnC,QAAA,KAAK,EAAE;QAHU,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACjB,IAAO,CAAA,OAAA,GAAP,OAAO;;IAKjB,OAAO,GAAA;AACL,QAAA,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;AAC5C,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI;AACtB,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM;AAC1B,YAAA,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;YACxB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;YACvC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;YAClD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;YACvC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;YAClD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACpC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC;YAE/C,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC;YACpC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC;YAE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AAM,CAAC,MAAM,CAAC,IAAI,CAAC;iBACnC,EAAE,GAAG,CAAC;AACT,aAAC,CAAC;;;AAIR,IAAA,KAAK,CAAC,IAAgB,EAAA;AACpB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;QAEhB,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;QAC3C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC;AAE1C,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ;QAEhC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;QAC/C,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC;QACzC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;QAExC,IAAI,IAAI,CAAC,OAAO;AAAE,YAAA,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3E,QAAA,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;AAExB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAEhB,QAAA,OAAO,MAAM;;AAGf,IAAA,OAAO,CAAC,GAAgB,EAAA;QACtB,IAAI,IAAI,CAAC,OAAO;AAAE,YAAA,GAAG,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;AAE9E;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-constants.js","sources":["../../../../../src/extensions/markdown/header/header-constants.ts"],"sourcesContent":["export const NAME_OF_HEADER = \"ATXHeading\";\nexport const NAME_OF_HEADER_UNDER = \"SetextHeading\";\nexport const NAME_OF_HEADER_MARK = \"HeaderMark\";\n"],"names":[],"mappings":"AAAO,MAAM,cAAc,GAAG;AACvB,MAAM,oBAAoB,GAAG;AAC7B,MAAM,mBAAmB,GAAG;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { getLineDecoration, getHideDecoration } from '../../../lib/utils/get-decoration.js';
|
|
3
|
+
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
4
|
+
import styles from '../styles.module.scss.js';
|
|
5
|
+
import { NAME_OF_HEADER, NAME_OF_HEADER_UNDER, NAME_OF_HEADER_MARK } from './header-constants.js';
|
|
6
|
+
|
|
7
|
+
function getHeaderDecorations({ decorations, node, view }) {
|
|
8
|
+
const isHeader = node.name.startsWith(NAME_OF_HEADER);
|
|
9
|
+
const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);
|
|
10
|
+
if (!isHeader && !isHeaderUnder) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let level;
|
|
14
|
+
if (isHeader) {
|
|
15
|
+
level = node.name.replace(NAME_OF_HEADER, "");
|
|
16
|
+
if (view.state.doc.sliceString(node.from + +level).charCodeAt(0) !== 32)
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
level = node.name.replace(NAME_OF_HEADER_UNDER, "");
|
|
21
|
+
}
|
|
22
|
+
if (!level)
|
|
23
|
+
return;
|
|
24
|
+
decorations.push(getLineDecoration({
|
|
25
|
+
style: clsx(styles.header, styles[`level_${level}`]),
|
|
26
|
+
range: [view.lineBlockAt(node.from).from],
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function getHeaderSelectionDecorations({ decorations, node, view, isReadonly, }) {
|
|
30
|
+
const isHeader = node.name.startsWith(NAME_OF_HEADER);
|
|
31
|
+
const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);
|
|
32
|
+
if (!isHeader && !isHeaderUnder) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const mark = node.node.getChild(NAME_OF_HEADER_MARK);
|
|
36
|
+
if (!mark)
|
|
37
|
+
return;
|
|
38
|
+
if (isHeader) {
|
|
39
|
+
const line = view.lineBlockAt(mark.from);
|
|
40
|
+
if (line.length < mark.to - mark.from + 1)
|
|
41
|
+
return;
|
|
42
|
+
if (isReadonly ||
|
|
43
|
+
!view.hasFocus ||
|
|
44
|
+
!isInRange(view.state.selection.ranges, [line.from, line.to])) {
|
|
45
|
+
decorations.push(getHideDecoration({ range: [mark.from, mark.to + 1] }));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const lineHeader = view.lineBlockAt(node.from);
|
|
50
|
+
const lineMark = view.lineBlockAt(mark.from);
|
|
51
|
+
if (isReadonly ||
|
|
52
|
+
!view.hasFocus ||
|
|
53
|
+
!isInRange(view.state.selection.ranges, [lineHeader.from, lineMark.to])) {
|
|
54
|
+
decorations.push(getHideDecoration({ range: [lineMark.from, lineMark.to] }));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const headerDecorationPlugin = {
|
|
59
|
+
decorations: [getHeaderDecorations],
|
|
60
|
+
selectionDecorations: [getHeaderSelectionDecorations],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { headerDecorationPlugin };
|
|
64
|
+
//# sourceMappingURL=header-decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-decoration.js","sources":["../../../../../src/extensions/markdown/header/header-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { utils } from \"@/lib\";\nimport type {\n DecorationPlugin,\n GetDecorationOptions,\n GetSelectionDecorationOptions,\n} from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_HEADER, NAME_OF_HEADER_MARK, NAME_OF_HEADER_UNDER } from \"./header-constants\";\n\nfunction getHeaderDecorations({ decorations, node, view }: GetDecorationOptions) {\n const isHeader = node.name.startsWith(NAME_OF_HEADER);\n const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);\n\n if (!isHeader && !isHeaderUnder) {\n return;\n }\n\n let level: string | undefined;\n\n if (isHeader) {\n level = node.name.replace(NAME_OF_HEADER, \"\");\n\n if (view.state.doc.sliceString(node.from + +level).charCodeAt(0) !== 32) return;\n } else {\n level = node.name.replace(NAME_OF_HEADER_UNDER, \"\");\n }\n\n if (!level) return;\n\n decorations.push(\n utils.getLineDecoration({\n style: clsx(styles.header, styles[`level_${level}`]),\n range: [view.lineBlockAt(node.from).from],\n }),\n );\n}\n\nfunction getHeaderSelectionDecorations({\n decorations,\n node,\n view,\n isReadonly,\n}: GetSelectionDecorationOptions) {\n const isHeader = node.name.startsWith(NAME_OF_HEADER);\n const isHeaderUnder = node.name.startsWith(NAME_OF_HEADER_UNDER);\n\n if (!isHeader && !isHeaderUnder) {\n return;\n }\n\n const mark = node.node.getChild(NAME_OF_HEADER_MARK);\n if (!mark) return;\n\n if (isHeader) {\n const line = view.lineBlockAt(mark.from);\n if (line.length < mark.to - mark.from + 1) return;\n\n if (\n isReadonly ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [line.from, line.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [mark.from, mark.to + 1] }));\n }\n } else {\n const lineHeader = view.lineBlockAt(node.from);\n const lineMark = view.lineBlockAt(mark.from);\n\n if (\n isReadonly ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [lineHeader.from, lineMark.to])\n ) {\n decorations.push(utils.getHideDecoration({ range: [lineMark.from, lineMark.to] }));\n }\n }\n}\n\nexport const headerDecorationPlugin: DecorationPlugin = {\n decorations: [getHeaderDecorations],\n selectionDecorations: [getHeaderSelectionDecorations],\n};\n"],"names":["utils.getLineDecoration","utils.isInRange","utils.getHideDecoration"],"mappings":";;;;;;AAUA,SAAS,oBAAoB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AAC,oBAAoB,CAAC;IACnC,oBAAoB,EAAE,CAAC,6BAA6B,CAAC;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"horizontal-constants.js","sources":["../../../../../src/extensions/markdown/horizontal/horizontal-constants.ts"],"sourcesContent":["export const NAME_OF_HORIZONTAL = \"HorizontalRule\";\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB,GAAG;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import '@codemirror/view';
|
|
3
|
+
import '../../compartments/index.js';
|
|
4
|
+
import '@codemirror/language';
|
|
5
|
+
import '@lezer/highlight';
|
|
6
|
+
import { CLASSES } from '../../theme/theme-constants.js';
|
|
7
|
+
import { getLineDecoration, getHideDecoration } from '../../../lib/utils/get-decoration.js';
|
|
8
|
+
import { isInRange } from '../../../lib/utils/is-in-range.js';
|
|
9
|
+
import styles from '../styles.module.scss.js';
|
|
10
|
+
import { NAME_OF_HORIZONTAL } from './horizontal-constants.js';
|
|
11
|
+
|
|
12
|
+
function getHorizontalSelectionDecoration({ decorations, isReadonly, node, view, }) {
|
|
13
|
+
if (node.name !== NAME_OF_HORIZONTAL)
|
|
14
|
+
return;
|
|
15
|
+
const line = view.lineBlockAt(node.from);
|
|
16
|
+
if (isReadonly ||
|
|
17
|
+
!view.hasFocus ||
|
|
18
|
+
!isInRange(view.state.selection.ranges, [line.from, line.to])) {
|
|
19
|
+
decorations.push(getLineDecoration({
|
|
20
|
+
style: clsx(styles.horizontal, CLASSES.horizontal),
|
|
21
|
+
range: [line.from],
|
|
22
|
+
}));
|
|
23
|
+
decorations.push(getHideDecoration({ range: [node.from, node.to] }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const horizontalDecorationPlugin = {
|
|
27
|
+
selectionDecorations: [getHorizontalSelectionDecoration],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { horizontalDecorationPlugin };
|
|
31
|
+
//# sourceMappingURL=horizontal-decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"horizontal-decoration.js","sources":["../../../../../src/extensions/markdown/horizontal/horizontal-decoration.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport { CLASSES } from \"@/extensions/theme\";\nimport { utils } from \"@/lib\";\nimport type { DecorationPlugin, GetSelectionDecorationOptions } from \"../markdown-types\";\nimport styles from \"../styles.module.scss\";\nimport { NAME_OF_HORIZONTAL } from \"./horizontal-constants\";\n\nfunction getHorizontalSelectionDecoration({\n decorations,\n isReadonly,\n node,\n view,\n}: GetSelectionDecorationOptions) {\n if (node.name !== NAME_OF_HORIZONTAL) return;\n\n const line = view.lineBlockAt(node.from);\n\n if (\n isReadonly ||\n !view.hasFocus ||\n !utils.isInRange(view.state.selection.ranges, [line.from, line.to])\n ) {\n decorations.push(\n utils.getLineDecoration({\n style: clsx(styles.horizontal, CLASSES.horizontal),\n range: [line.from],\n }),\n );\n decorations.push(utils.getHideDecoration({ range: [node.from, node.to] }));\n }\n}\n\nexport const horizontalDecorationPlugin: DecorationPlugin = {\n selectionDecorations: [getHorizontalSelectionDecoration],\n};\n"],"names":["utils.isInRange","utils.getLineDecoration","utils.getHideDecoration"],"mappings":";;;;;;;;;;;AAOA,SAAS,gCAAgC,CAAC,EACxC,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,GAC0B,EAAA;AAC9B,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB;QAAE;IAEtC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;AAExC,IAAA,IACE,UAAU;QACV,CAAC,IAAI,CAAC,QAAQ;QACd,CAACA,SAAe,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EACnE;AACA,QAAA,WAAW,CAAC,IAAI,CACdC,iBAAuB,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC;AAClD,YAAA,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;AACnB,SAAA,CAAC,CACH;QACD,WAAW,CAAC,IAAI,CAACC,iBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;AAE9E;AAEa,MAAA,0BAA0B,GAAqB;IAC1D,oBAAoB,EAAE,CAAC,gCAAgC,CAAC;;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const NAME_OF_IMAGE = "Image";
|
|
2
|
+
const CODE_OF_START_IMAGE_TEXT = 91; // [
|
|
3
|
+
const CODE_OF_END_IMAGE_TEXT = 93; // ]
|
|
4
|
+
const CODE_OF_START_IMAGE_URL = 40; // (
|
|
5
|
+
const CODE_OF_END_IMAGE_URL = 41; // )
|
|
6
|
+
|
|
7
|
+
export { CODE_OF_END_IMAGE_TEXT, CODE_OF_END_IMAGE_URL, CODE_OF_START_IMAGE_TEXT, CODE_OF_START_IMAGE_URL, NAME_OF_IMAGE };
|
|
8
|
+
//# sourceMappingURL=image-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-constants.js","sources":["../../../../../src/extensions/markdown/image/image-constants.ts"],"sourcesContent":["export const NAME_OF_IMAGE = \"Image\";\nexport const CODE_OF_START_IMAGE_TEXT = 91; // [\nexport const CODE_OF_END_IMAGE_TEXT = 93; // ]\nexport const CODE_OF_START_IMAGE_URL = 40; // (\nexport const CODE_OF_END_IMAGE_URL = 41; // )\n"],"names":[],"mappings":"AAAO,MAAM,aAAa,GAAG;AAChB,MAAA,wBAAwB,GAAG,GAAG;AAC9B,MAAA,sBAAsB,GAAG,GAAG;AAC5B,MAAA,uBAAuB,GAAG,GAAG;AAC7B,MAAA,qBAAqB,GAAG,GAAG;;;;"}
|