@type32/codemirror-rich-obsidian-editor 0.0.8 → 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/editorInternalLinkAutocompletePlugin.js +1 -1
- 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 +83 -80
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;
|
|
@@ -27,7 +27,7 @@ function internalLinkSource(context) {
|
|
|
27
27
|
const linkMap = context.state.facet(internalLinkMapFacet);
|
|
28
28
|
const options = linkMap.filter((link) => link.internalLinkName.toLowerCase().includes(textBefore.toLowerCase())).map((link) => ({
|
|
29
29
|
label: link.internalLinkName,
|
|
30
|
-
detail: link.
|
|
30
|
+
detail: link.filePath,
|
|
31
31
|
apply: `${link.internalLinkName}`
|
|
32
32
|
}));
|
|
33
33
|
if (options.length === 0) return null;
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,82 +1,85 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
2
|
+
"name": "@type32/codemirror-rich-obsidian-editor",
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"description": "OFM Editor Component for Nuxt.",
|
|
5
|
+
"repository": "Type-32/codemirror-rich-obsidian",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"private": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types.d.mts",
|
|
12
|
+
"import": "./dist/module.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/module.mjs",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
".": [
|
|
19
|
+
"./dist/types.d.mts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepack": "bunx nuxt-module-build build",
|
|
28
|
+
"dev": "bun run dev:prepare && bunx nuxi dev playground",
|
|
29
|
+
"dev:build": "bunx nuxi build playground",
|
|
30
|
+
"dev:prepare": "bunx nuxt-module-build build --stub && bunx nuxt-module-build prepare && bunx nuxi prepare playground",
|
|
31
|
+
"release": "bun run prepack && bunx changelogen --release && bun publish && git push --follow-tags",
|
|
32
|
+
"lint": "bunx eslint .",
|
|
33
|
+
"test": "bunx vitest run",
|
|
34
|
+
"test:watch": "bunx vitest watch",
|
|
35
|
+
"test:types": "bunx vue-tsc --noEmit && cd playground && bunx vue-tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@codemirror/autocomplete": "^6.18.7",
|
|
39
|
+
"@codemirror/lang-json": "^6.0.2",
|
|
40
|
+
"@codemirror/lang-markdown": "^6.3.4",
|
|
41
|
+
"@codemirror/lang-yaml": "^6.1.2",
|
|
42
|
+
"@codemirror/language": "^6.11.3",
|
|
43
|
+
"@codemirror/language-data": "^6.5.1",
|
|
44
|
+
"@hsorby/vue3-katex": "0.6.0-rc.7",
|
|
45
|
+
"@lezer/markdown": "^1.4.3",
|
|
46
|
+
"@nuxt/image": "1.10.0",
|
|
47
|
+
"@nuxt/kit": "^4.1.2",
|
|
48
|
+
"@nuxt/ui": "^4.0.0-alpha.1",
|
|
49
|
+
"codemirror": "^6.0.2",
|
|
50
|
+
"js-yaml": "^4.1.0",
|
|
51
|
+
"katex": "^0.16.22",
|
|
52
|
+
"lezer-markdown-obsidian": "^0.0.3",
|
|
53
|
+
"markdown-it": "^14.1.0",
|
|
54
|
+
"markdown-it-obsidian-callouts": "^0.3.2",
|
|
55
|
+
"vue-codemirror6": "^1.3.22"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@iconify-json/lucide": "^1.2.67",
|
|
59
|
+
"@iconify-json/simple-icons": "^1.2.51",
|
|
60
|
+
"@nuxt/devtools": "^2.6.3",
|
|
61
|
+
"@nuxt/eslint-config": "^1.9.0",
|
|
62
|
+
"@nuxt/fonts": "0.11.4",
|
|
63
|
+
"@nuxt/icon": "1.15.0",
|
|
64
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
65
|
+
"@nuxt/schema": "^4.1.2",
|
|
66
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
67
|
+
"@types/js-yaml": "^4.0.9",
|
|
68
|
+
"@types/node": "latest",
|
|
69
|
+
"changelogen": "^0.6.2",
|
|
70
|
+
"eslint": "^9.35.0",
|
|
71
|
+
"nuxt": "^4.1.2",
|
|
72
|
+
"typescript": "~5.9.2",
|
|
73
|
+
"vitest": "^3.2.4",
|
|
74
|
+
"vue-tsc": "^3.0.7"
|
|
75
|
+
},
|
|
76
|
+
"trustedDependencies": [
|
|
77
|
+
"@parcel/watcher",
|
|
78
|
+
"@tailwindcss/oxide",
|
|
79
|
+
"core-js",
|
|
80
|
+
"esbuild",
|
|
81
|
+
"sharp",
|
|
82
|
+
"unrs-resolver",
|
|
83
|
+
"vue-demi"
|
|
84
|
+
]
|
|
82
85
|
}
|