@type32/codemirror-rich-obsidian-editor 0.0.9 → 0.0.10
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/dist/module.json +1 -1
- package/dist/runtime/components/Editor.client.vue +9 -1
- package/dist/runtime/components/Editor.client.vue.d.ts +6 -6
- package/dist/runtime/editor/plugins/codemirror-editor-plugins/editorLinkClickPlugin.js +23 -7
- package/dist/runtime/editor/types/editor-types.d.ts +18 -1
- package/dist/runtime/editor/wysiwyg.js +3 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { standardKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
15
15
|
import { defaultHighlightStyle, syntaxHighlighting, indentOnInput, foldGutter, syntaxTree } from "@codemirror/language";
|
|
16
16
|
import { Compartment, RangeSetBuilder } from "@codemirror/state";
|
|
17
|
+
import { LanguageSupport, LRLanguage } from "@codemirror/language";
|
|
17
18
|
import { languages } from "@codemirror/language-data";
|
|
18
19
|
import wysiwyg from "../editor/wysiwyg";
|
|
19
20
|
import { internalLinkMapFacet } from "../editor/plugins/linkMappingConfig";
|
|
@@ -43,10 +44,17 @@ const editorElement = ref();
|
|
|
43
44
|
const keymaps = computed(() => {
|
|
44
45
|
return props.disabled ? keymap.of([]) : keymap.of([...standardKeymap, ...historyKeymap, indentWithTab]);
|
|
45
46
|
});
|
|
47
|
+
async function loadLanguage(info) {
|
|
48
|
+
const lang = languages.find((l) => l.name.toLowerCase() === info.toLowerCase() || l.alias.map((a) => a.toLowerCase()).includes(info.toLowerCase()));
|
|
49
|
+
if (lang) {
|
|
50
|
+
return await lang.load();
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Language ${info} not found`);
|
|
53
|
+
}
|
|
46
54
|
onMounted(() => {
|
|
47
55
|
const wysiwygPlugin = wysiwyg({
|
|
48
56
|
lezer: {
|
|
49
|
-
codeLanguages:
|
|
57
|
+
codeLanguages: loadLanguage
|
|
50
58
|
}
|
|
51
59
|
});
|
|
52
60
|
extensions.value = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
|
-
import type { InternalLink, SpecialCodeBlockMapping } from '#codemirror-rich-obsidian-editor/editor-types';
|
|
2
|
+
import type { InternalLink, SpecialCodeBlockMapping, InternalLinkClickDetail, ExternalLinkClickDetail } from '#codemirror-rich-obsidian-editor/editor-types';
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
class?: string;
|
|
5
5
|
internalLinkMap?: InternalLink[];
|
|
@@ -15,12 +15,12 @@ type __VLS_PublicProps = __VLS_Props & {
|
|
|
15
15
|
declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
16
16
|
view: import("vue").ShallowRef<EditorView | undefined, EditorView | undefined>;
|
|
17
17
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
18
|
-
"internal-link-click": (
|
|
19
|
-
"external-link-click": (
|
|
20
|
-
"update:modelValue": (value: string | undefined) =>
|
|
18
|
+
"internal-link-click": (detail: InternalLinkClickDetail) => any;
|
|
19
|
+
"external-link-click": (detail: ExternalLinkClickDetail) => any;
|
|
20
|
+
"update:modelValue": (value: string | undefined) => any;
|
|
21
21
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
22
|
-
"onInternal-link-click"?: ((
|
|
23
|
-
"onExternal-link-click"?: ((
|
|
22
|
+
"onInternal-link-click"?: ((detail: InternalLinkClickDetail) => any) | undefined;
|
|
23
|
+
"onExternal-link-click"?: ((detail: ExternalLinkClickDetail) => any) | undefined;
|
|
24
24
|
"onUpdate:modelValue"?: ((value: string | undefined) => any) | undefined;
|
|
25
25
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
26
26
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EditorView } from "@codemirror/view";
|
|
2
2
|
import { syntaxTree } from "@codemirror/language";
|
|
3
|
+
import { internalLinkMapFacet } from "../linkMappingConfig.js";
|
|
3
4
|
export const editorLinkClickPlugin = EditorView.domEventHandlers({
|
|
4
5
|
mousedown(event, view) {
|
|
5
6
|
let target = event.target;
|
|
@@ -21,21 +22,36 @@ export const editorLinkClickPlugin = EditorView.domEventHandlers({
|
|
|
21
22
|
}
|
|
22
23
|
if (anchor.dataset.internalLink === "true") {
|
|
23
24
|
event.preventDefault();
|
|
25
|
+
const path = anchor.dataset.path;
|
|
26
|
+
if (!path) return true;
|
|
27
|
+
const linkMap = view.state.facet(internalLinkMapFacet);
|
|
28
|
+
const linkInfo = linkMap.find((l) => l.internalLinkName === path);
|
|
29
|
+
const type = anchor.dataset.type;
|
|
30
|
+
const detail = {
|
|
31
|
+
path,
|
|
32
|
+
subpath: anchor.dataset.subpath,
|
|
33
|
+
display: anchor.dataset.display,
|
|
34
|
+
type: type || "internal-link",
|
|
35
|
+
redirectToPath: linkInfo?.redirectToPath
|
|
36
|
+
};
|
|
24
37
|
view.dom.dispatchEvent(new CustomEvent("internal-link-click", {
|
|
25
38
|
bubbles: true,
|
|
26
39
|
composed: true,
|
|
27
|
-
detail
|
|
28
|
-
path: anchor.dataset.path,
|
|
29
|
-
subpath: anchor.dataset.subpath,
|
|
30
|
-
display: anchor.dataset.display,
|
|
31
|
-
type: anchor.dataset.type
|
|
32
|
-
}
|
|
40
|
+
detail
|
|
33
41
|
}));
|
|
34
42
|
} else if (anchor.dataset.externalLink === "true") {
|
|
35
43
|
event.preventDefault();
|
|
36
44
|
const url = anchor.dataset.url;
|
|
37
45
|
if (url) {
|
|
38
|
-
|
|
46
|
+
const detail = {
|
|
47
|
+
url,
|
|
48
|
+
text: anchor.textContent
|
|
49
|
+
};
|
|
50
|
+
view.dom.dispatchEvent(new CustomEvent("external-link-click", {
|
|
51
|
+
bubbles: true,
|
|
52
|
+
composed: true,
|
|
53
|
+
detail
|
|
54
|
+
}));
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
return true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Component } from 'vue'
|
|
2
|
+
import type { LanguageSupport } from '@codemirror/language'
|
|
2
3
|
|
|
3
4
|
export interface InternalLink {
|
|
4
5
|
internalLinkName: string;
|
|
@@ -7,11 +8,27 @@ export interface InternalLink {
|
|
|
7
8
|
embedComponent?: Component;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
export interface InternalLinkClickDetail {
|
|
12
|
+
path: string;
|
|
13
|
+
subpath?: string;
|
|
14
|
+
display?: string;
|
|
15
|
+
type: 'embed' | 'internal-link';
|
|
16
|
+
redirectToPath?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ExternalLinkClickDetail {
|
|
20
|
+
url: string;
|
|
21
|
+
text: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
export interface SpecialCodeBlockMapping {
|
|
11
25
|
codeInfo: string
|
|
12
26
|
component: Component
|
|
13
27
|
}
|
|
14
28
|
|
|
15
29
|
export type WysiwygPlugin = {
|
|
16
|
-
lezer?:
|
|
30
|
+
lezer?: {
|
|
31
|
+
codeLanguages?: (info: string) => LanguageSupport | Promise<LanguageSupport> | null
|
|
32
|
+
[key: string]: any
|
|
33
|
+
}
|
|
17
34
|
}
|
|
@@ -33,9 +33,10 @@ import { editorLivePreviewField, proseTaskListPlugin } from "./plugins/codemirro
|
|
|
33
33
|
import { proseCalloutPlugin } from "./plugins/codemirror-plugin-proses/proseCalloutPlugin.js";
|
|
34
34
|
import { indentationListPlugin } from "./plugins/codemirror-editor-plugins/indentationListPlugin.js";
|
|
35
35
|
export default function(config) {
|
|
36
|
+
const { codeLanguages, ...lezerRest } = config?.lezer ?? {};
|
|
36
37
|
const mergedConfig = {
|
|
37
|
-
...
|
|
38
|
-
|
|
38
|
+
...lezerRest ?? [],
|
|
39
|
+
codeLanguages,
|
|
39
40
|
extensions: [
|
|
40
41
|
GFM,
|
|
41
42
|
CustomOFM,
|