mktcms 0.1.46 → 0.1.47

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mktcms",
3
3
  "configKey": "mktcms",
4
- "version": "0.1.46",
4
+ "version": "0.1.47",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -5,6 +5,7 @@ import Saved from "../saved.vue";
5
5
  import usePathParam from "../../../composables/usePathParam";
6
6
  import { useFetch } from "#imports";
7
7
  import FrontmatterForm from "./frontmatter/form.vue";
8
+ import MonacoEditor from "./monacoEditor.vue";
8
9
  const { path } = usePathParam();
9
10
  const { data: content } = await useFetch(`/api/admin/md?path=${path}`);
10
11
  const frontmatter = ref(content.value?.frontmatter ?? {});
@@ -52,11 +53,14 @@ const mode = ref("preview");
52
53
  </div>
53
54
 
54
55
  <div class="lg:grid lg:grid-cols-2 lg:gap-3">
55
- <textarea
56
- v-model="markdown"
57
- class="w-full min-h-72 lg:block"
58
- :class="mode === 'edit' ? 'block' : 'hidden'"
59
- />
56
+ <ClientOnly>
57
+ <MonacoEditor
58
+ v-model="markdown"
59
+ language="markdown"
60
+ class="w-full min-h-72 border border-gray-200 rounded-sm lg:block"
61
+ :class="mode === 'edit' ? 'block' : 'hidden'"
62
+ />
63
+ </ClientOnly>
60
64
 
61
65
  <MDC
62
66
  class="prose max-w-full min-h-72 border border-gray-200 rounded-sm p-4 lg:block"
@@ -0,0 +1,16 @@
1
+ import 'monaco-editor/min/vs/editor/editor.main.css';
2
+ type __VLS_Props = {
3
+ modelValue: string;
4
+ language?: string;
5
+ readOnly?: boolean;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
8
+ "update:modelValue": (value: string) => any;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
11
+ }>, {
12
+ language: string;
13
+ readOnly: boolean;
14
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
@@ -0,0 +1,84 @@
1
+ <script setup>
2
+ import { onBeforeUnmount, onMounted, ref, watch } from "vue";
3
+ import "monaco-editor/min/vs/editor/editor.main.css";
4
+ import * as monaco from "monaco-editor";
5
+ import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
6
+ import JsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
7
+ import CssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker";
8
+ import HtmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker";
9
+ import TsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker";
10
+ const props = defineProps({
11
+ modelValue: { type: String, required: true },
12
+ language: { type: String, required: false, default: "markdown" },
13
+ readOnly: { type: Boolean, required: false, default: false }
14
+ });
15
+ const emit = defineEmits(["update:modelValue"]);
16
+ const rootEl = ref(null);
17
+ let editor;
18
+ let resizeObserver;
19
+ let suppressModelEmit = false;
20
+ function ensureMonacoWorkers() {
21
+ const globalAny = globalThis;
22
+ if (globalAny.MonacoEnvironment?.getWorker)
23
+ return;
24
+ globalAny.MonacoEnvironment = {
25
+ getWorker(_, label) {
26
+ if (label === "json")
27
+ return new JsonWorker();
28
+ if (label === "css" || label === "scss" || label === "less")
29
+ return new CssWorker();
30
+ if (label === "html" || label === "handlebars" || label === "razor")
31
+ return new HtmlWorker();
32
+ if (label === "typescript" || label === "javascript")
33
+ return new TsWorker();
34
+ return new EditorWorker();
35
+ }
36
+ };
37
+ }
38
+ onMounted(() => {
39
+ ensureMonacoWorkers();
40
+ if (!rootEl.value)
41
+ return;
42
+ editor = monaco.editor.create(rootEl.value, {
43
+ value: props.modelValue ?? "",
44
+ language: props.language,
45
+ readOnly: props.readOnly,
46
+ minimap: { enabled: false },
47
+ scrollBeyondLastLine: false,
48
+ wordWrap: "on",
49
+ automaticLayout: true
50
+ });
51
+ editor.onDidChangeModelContent(() => {
52
+ if (!editor || suppressModelEmit)
53
+ return;
54
+ emit("update:modelValue", editor.getValue());
55
+ });
56
+ resizeObserver = new ResizeObserver(() => {
57
+ editor?.layout();
58
+ });
59
+ resizeObserver.observe(rootEl.value);
60
+ queueMicrotask(() => {
61
+ editor?.layout();
62
+ });
63
+ });
64
+ watch(() => props.modelValue, (nextValue) => {
65
+ if (!editor)
66
+ return;
67
+ const current = editor.getValue();
68
+ if (nextValue === current)
69
+ return;
70
+ suppressModelEmit = true;
71
+ editor.setValue(nextValue ?? "");
72
+ suppressModelEmit = false;
73
+ });
74
+ onBeforeUnmount(() => {
75
+ resizeObserver?.disconnect();
76
+ resizeObserver = void 0;
77
+ editor?.dispose();
78
+ editor = void 0;
79
+ });
80
+ </script>
81
+
82
+ <template>
83
+ <div ref="rootEl" class="w-full" />
84
+ </template>
@@ -0,0 +1,16 @@
1
+ import 'monaco-editor/min/vs/editor/editor.main.css';
2
+ type __VLS_Props = {
3
+ modelValue: string;
4
+ language?: string;
5
+ readOnly?: boolean;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
8
+ "update:modelValue": (value: string) => any;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
11
+ }>, {
12
+ language: string;
13
+ readOnly: boolean;
14
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mktcms",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "Simple CMS module for Nuxt",
5
5
  "repository": "mktcode/mktcms",
6
6
  "license": "MIT",
@@ -45,6 +45,7 @@
45
45
  "csv-stringify": "^6.6.0",
46
46
  "defu": "^6.1.4",
47
47
  "ejs": "^4.0.1",
48
+ "monaco-editor": "^0.55.1",
48
49
  "marked": "^17.0.1",
49
50
  "nodemailer": "^7.0.12",
50
51
  "sharp": "^0.34.5",