vue-codemirror6 0.1.0 → 0.1.2

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.
@@ -1,75 +1,176 @@
1
- import { Vue } from 'vue-property-decorator';
2
- import { type Extension } from '@codemirror/state';
1
+ import type { Ref, PropType, SetupContext } from 'vue-demi';
2
+ import type { Extension } from '@codemirror/state';
3
3
  import type { LanguageSupport } from '@codemirror/language';
4
4
  import type { Diagnostic } from '@codemirror/lint';
5
5
  import type { StyleSpec } from 'style-mod';
6
- /** CodeMirror Component */
7
- export default class CodeMirror extends Vue {
8
- /** Editor */
9
- private editor;
6
+ declare const _default: import("vue-demi").DefineComponent<{
7
+ /** Model value */
8
+ modelValue: {
9
+ type: StringConstructor;
10
+ default: string;
11
+ };
10
12
  /**
11
13
  * Theme
12
14
  *
13
15
  * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
14
16
  */
15
- readonly theme: {
16
- [selector: string]: StyleSpec;
17
+ theme: {
18
+ type: PropType<{
19
+ [selector: string]: StyleSpec;
20
+ }>;
21
+ default: undefined;
17
22
  };
18
23
  /** Dark Mode */
19
- readonly dark: boolean;
24
+ dark: {
25
+ type: BooleanConstructor;
26
+ default: boolean;
27
+ };
20
28
  /**
21
29
  * Readonly
22
30
  *
23
31
  * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
24
32
  */
25
- readonly readonly: boolean;
33
+ readonly: {
34
+ type: BooleanConstructor;
35
+ default: boolean;
36
+ };
26
37
  /**
27
38
  * Editable
28
39
  *
29
40
  * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
30
41
  */
31
- readonly editable: boolean;
42
+ editable: {
43
+ type: BooleanConstructor;
44
+ default: boolean;
45
+ };
46
+ /**
47
+ * Additional Extension
48
+ *
49
+ * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
50
+ */
51
+ extensions: {
52
+ type: PropType<Extension[]>;
53
+ default: undefined;
54
+ };
32
55
  /**
33
56
  * Language Phreses
34
57
  *
35
58
  * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
36
59
  */
37
- readonly phrases: Record<string, string>;
60
+ phrases: {
61
+ type: PropType<Record<string, string>>;
62
+ default: undefined;
63
+ };
64
+ /**
65
+ * CodeMirror Language
66
+ *
67
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
68
+ */
69
+ lang: {
70
+ type: PropType<LanguageSupport>;
71
+ default: undefined;
72
+ };
73
+ /**
74
+ * CodeMirror Linter
75
+ *
76
+ * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
77
+ */
78
+ linter: {
79
+ type: PropType<Diagnostic[]>;
80
+ default: undefined;
81
+ };
82
+ }, {
83
+ context: SetupContext<import("vue-demi").EmitsOptions>;
84
+ editor: Ref<Element | undefined>;
85
+ }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
86
+ /** Model value */
87
+ modelValue: {
88
+ type: StringConstructor;
89
+ default: string;
90
+ };
91
+ /**
92
+ * Theme
93
+ *
94
+ * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
95
+ */
96
+ theme: {
97
+ type: PropType<{
98
+ [selector: string]: StyleSpec;
99
+ }>;
100
+ default: undefined;
101
+ };
102
+ /** Dark Mode */
103
+ dark: {
104
+ type: BooleanConstructor;
105
+ default: boolean;
106
+ };
107
+ /**
108
+ * Readonly
109
+ *
110
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
111
+ */
112
+ readonly: {
113
+ type: BooleanConstructor;
114
+ default: boolean;
115
+ };
116
+ /**
117
+ * Editable
118
+ *
119
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
120
+ */
121
+ editable: {
122
+ type: BooleanConstructor;
123
+ default: boolean;
124
+ };
38
125
  /**
39
126
  * Additional Extension
40
127
  *
41
128
  * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
42
129
  */
43
- readonly extensions: Extension[];
130
+ extensions: {
131
+ type: PropType<Extension[]>;
132
+ default: undefined;
133
+ };
134
+ /**
135
+ * Language Phreses
136
+ *
137
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
138
+ */
139
+ phrases: {
140
+ type: PropType<Record<string, string>>;
141
+ default: undefined;
142
+ };
44
143
  /**
45
144
  * CodeMirror Language
46
145
  *
47
146
  * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
48
147
  */
49
- readonly lang: LanguageSupport;
148
+ lang: {
149
+ type: PropType<LanguageSupport>;
150
+ default: undefined;
151
+ };
50
152
  /**
51
153
  * CodeMirror Linter
52
154
  *
53
155
  * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
54
156
  */
55
- readonly linter: Diagnostic[];
56
- /** Input */
57
- readonly value: string;
58
- /**
59
- * Input value changed
60
- *
61
- * @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
62
- */
63
- onValueChanged(): void;
64
- /** Toggle Dark mode */
65
- onToggleDarkMode(): void;
66
- /** CodeMirror Extension */
67
- get extension(): Extension[];
68
- /** When loaded */
69
- mounted(): void;
70
- /** Destroy */
71
- beforeDestroy(): void;
72
- /** Vue node to plain text */
73
- private getChildrenTextContent;
74
- }
157
+ linter: {
158
+ type: PropType<Diagnostic[]>;
159
+ default: undefined;
160
+ };
161
+ }>>, {
162
+ modelValue: string;
163
+ theme: {
164
+ [selector: string]: StyleSpec;
165
+ };
166
+ dark: boolean;
167
+ readonly: boolean;
168
+ editable: boolean;
169
+ extensions: Extension[];
170
+ phrases: Record<string, string>;
171
+ lang: LanguageSupport;
172
+ linter: Diagnostic[];
173
+ }>;
174
+ /** CodeMirror Component */
175
+ export default _default;
75
176
  //# sourceMappingURL=CodeMirror.vue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,GAAG,EAAS,MAAM,wBAAwB,CAAC;AAGrE,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK3C,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,GAAG;IACzC,aAAa;IACb,OAAO,CAAC,MAAM,CAAc;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,KAAK,EAAG;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAEnD,gBAAgB;IAEhB,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAC;IAExB;;;;OAIG;IAEH,QAAQ,CAAC,QAAQ,EAAG,OAAO,CAAC;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,QAAQ,EAAG,OAAO,CAAC;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C;;;;OAIG;IAEH,QAAQ,CAAC,UAAU,EAAG,SAAS,EAAE,CAAC;IAElC;;;;OAIG;IAEH,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAC;IAEhC;;;;OAIG;IAEH,QAAQ,CAAC,MAAM,EAAG,UAAU,EAAE,CAAC;IAE/B,YAAY;IAEZ,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;IAExB;;;;OAIG;IAEH,cAAc;IAgBd,uBAAuB;IAEvB,gBAAgB;IAShB,2BAA2B;IAC3B,IAAI,SAAS,IAAI,SAAS,EAAE,CAgC3B;IAED,kBAAkB;IAClB,OAAO;IAyBP,cAAc;IACd,aAAa;IAIb,6BAA6B;IAC7B,OAAO,CAAC,sBAAsB;CAS/B"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAe,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIzE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;;IAavC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IApEH,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;;;;;;;;;;AA/EP,2BAA2B;AAC3B,wBA+MG"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,14 @@
1
- import * as namedExports from './index.esm';
2
- declare const _default: typeof import("./components/CodeMirror.vue").default & import("vue").PluginObject<any> & typeof namedExports;
3
- export default _default;
1
+ /**
2
+ * Vue CodeMirror6 Component
3
+ *
4
+ * @license MIT
5
+ * @author Logue {@link logue@hotmail.co.jp}
6
+ * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
+ * @see {@link https://github.com/logue/vue-codemirror6}
8
+ */
9
+ import CodeMirror from './components/CodeMirror.vue';
10
+ import { App } from 'vue-demi';
11
+ declare const installCodeMirror: (app: App) => void;
12
+ export { CodeMirror, installCodeMirror as install };
13
+ export default CodeMirror;
4
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAkB,KAAK,YAAY,MAAM,aAAa,CAAC;;AASvD,wBAC0C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAW,GAAG,EAAE,MAAM,UAAU,CAAC;AAIxC,QAAA,MAAM,iBAAiB,QAAS,GAAG,SAElC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC;AACpD,eAAe,UAAU,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ViewUpdate } from '@codemirror/view';
2
+ /** Emit Interface */
3
+ export default interface CodeMirrorEmitsInterface {
4
+ /** Model Update */
5
+ (e: 'update:modelValue', value: string): void;
6
+ /** CodeMirror ViewUpdate */
7
+ (e: 'update', value: ViewUpdate): void;
8
+ }
9
+ //# sourceMappingURL=CodeMirrorEmitsInterface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeMirrorEmitsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorEmitsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC"}
@@ -1,198 +1,150 @@
1
- import { Prop, Watch, Component, Vue } from "vue-property-decorator";
1
+ import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
2
2
  import { EditorState } from "@codemirror/state";
3
3
  import { EditorView } from "@codemirror/view";
4
- import { compact, merge } from "lodash";
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __decorateClass = (decorators, target, key, kind) => {
8
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
9
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
- if (decorator = decorators[i])
11
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
12
- if (kind && result)
13
- __defProp(target, key, result);
14
- return result;
15
- };
16
- let CodeMirror = class extends Vue {
17
- onValueChanged() {
18
- if (this.editor.composing) {
19
- return;
20
- }
21
- const previous = this.editor.state.selection;
22
- this.editor.setState(EditorState.create({
23
- doc: this.value,
24
- extensions: this.extension,
25
- selection: previous
26
- }));
27
- }
28
- onToggleDarkMode() {
29
- this.editor.setState(EditorState.create({
30
- doc: this.value,
31
- extensions: this.extension
32
- }));
33
- }
34
- get extension() {
35
- const ext = compact([
36
- EditorView.updateListener.of((update) => this.$emit("update", update)),
37
- EditorView.theme(this.theme, { dark: this.dark }),
38
- this.phrases ? EditorState.phrases.of(this.phrases) : void 0,
39
- this.lang ? this.lang : void 0,
40
- EditorState.readOnly.of(this.readonly),
41
- EditorView.editable.of(this.editable)
42
- ]);
43
- if (this.linter.length !== 0) {
44
- merge(ext, this.linter);
45
- }
46
- if (this.extensions.length !== 0) {
47
- merge(ext, this.extensions);
48
- }
49
- console.debug("[CodeMirror.vue] Loaded extensions:", ext);
50
- return ext;
51
- }
52
- mounted() {
53
- let value = this.value;
54
- if (!this.value && this.$slots.default !== void 0) {
55
- value = this.getChildrenTextContent(this.$slots.default);
56
- }
57
- this.editor = new EditorView({
58
- state: EditorState.create({
59
- doc: value,
60
- extensions: this.extension
61
- }),
62
- parent: this.$refs.editor,
63
- dispatch: (tr) => {
64
- this.editor.update([tr]);
65
- if (tr.changes.empty)
66
- return;
67
- this.$emit("input", this.editor.state.doc.toString());
68
- }
69
- });
70
- }
71
- beforeDestroy() {
72
- this.editor.destroy();
73
- }
74
- getChildrenTextContent(children) {
75
- return children.map((node) => node.children ? this.getChildrenTextContent(node.children) : node.text || "\n").join("");
4
+ import { merge, compact } from "lodash";
5
+ import { openBlock, createElementBlock, withDirectives, createElementVNode, renderSlot, vShow } from "vue";
6
+ var _export_sfc = (sfc, props) => {
7
+ const target = sfc.__vccOpts || sfc;
8
+ for (const [key, val] of props) {
9
+ target[key] = val;
76
10
  }
11
+ return target;
77
12
  };
78
- __decorateClass([
79
- Prop({ type: Object, default: () => {
80
- } })
81
- ], CodeMirror.prototype, "theme", 2);
82
- __decorateClass([
83
- Prop({ type: Boolean, default: false })
84
- ], CodeMirror.prototype, "dark", 2);
85
- __decorateClass([
86
- Prop({ type: Boolean, default: false })
87
- ], CodeMirror.prototype, "readonly", 2);
88
- __decorateClass([
89
- Prop({ type: Boolean, default: true })
90
- ], CodeMirror.prototype, "editable", 2);
91
- __decorateClass([
92
- Prop({ type: Object })
93
- ], CodeMirror.prototype, "phrases", 2);
94
- __decorateClass([
95
- Prop({ type: Array, default: () => [] })
96
- ], CodeMirror.prototype, "extensions", 2);
97
- __decorateClass([
98
- Prop({ type: Object })
99
- ], CodeMirror.prototype, "lang", 2);
100
- __decorateClass([
101
- Prop({ type: Array, default: () => [] })
102
- ], CodeMirror.prototype, "linter", 2);
103
- __decorateClass([
104
- Prop({ type: String, default: "" })
105
- ], CodeMirror.prototype, "value", 2);
106
- __decorateClass([
107
- Watch("value")
108
- ], CodeMirror.prototype, "onValueChanged", 1);
109
- __decorateClass([
110
- Watch("dark")
111
- ], CodeMirror.prototype, "onToggleDarkMode", 1);
112
- CodeMirror = __decorateClass([
113
- Component({ name: "CodeMirror" })
114
- ], CodeMirror);
115
- var render = function() {
116
- var _vm = this;
117
- var _h = _vm.$createElement;
118
- var _c = _vm._self._c || _h;
119
- return _c("pre", { ref: "editor" }, [_vm._v(" "), !_vm.$slots.default ? [_vm._t("default")] : _vm._e(), _vm._v("\n")], 2);
120
- };
121
- var staticRenderFns = [];
122
- function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
123
- var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
124
- if (render2) {
125
- options.render = render2;
126
- options.staticRenderFns = staticRenderFns2;
127
- options._compiled = true;
128
- }
129
- if (functionalTemplate) {
130
- options.functional = true;
131
- }
132
- if (scopeId) {
133
- options._scopeId = "data-v-" + scopeId;
134
- }
135
- var hook;
136
- if (moduleIdentifier) {
137
- hook = function(context) {
138
- context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
139
- if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
140
- context = __VUE_SSR_CONTEXT__;
13
+ const _sfc_main = defineComponent({
14
+ name: "CodeMirror",
15
+ model: {
16
+ prop: "modelValue",
17
+ event: "update:modelValue"
18
+ },
19
+ props: {
20
+ modelValue: {
21
+ type: String,
22
+ default: ""
23
+ },
24
+ theme: {
25
+ type: Object,
26
+ default: void 0
27
+ },
28
+ dark: {
29
+ type: Boolean,
30
+ default: false
31
+ },
32
+ readonly: {
33
+ type: Boolean,
34
+ default: false
35
+ },
36
+ editable: {
37
+ type: Boolean,
38
+ default: true
39
+ },
40
+ extensions: {
41
+ type: Array,
42
+ default: void 0
43
+ },
44
+ phrases: {
45
+ type: Object,
46
+ default: void 0
47
+ },
48
+ lang: {
49
+ type: Object,
50
+ default: void 0
51
+ },
52
+ linter: {
53
+ type: Array,
54
+ default: void 0
55
+ }
56
+ },
57
+ emits: ["update:modelValue", "update"],
58
+ setup(props, context) {
59
+ const editor = ref();
60
+ const modelValue = ref(props.modelValue);
61
+ const dark = ref(props.dark);
62
+ const emit = context.emit;
63
+ const extensions = computed(() => {
64
+ const ext = [
65
+ EditorView.updateListener.of((update) => {
66
+ emit("update", update);
67
+ }),
68
+ EditorView.theme(props.theme || {}, { dark: dark.value }),
69
+ props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
70
+ props.lang,
71
+ props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
72
+ props.editable ? EditorView.editable.of(props.editable) : void 0
73
+ ];
74
+ if (props.linter) {
75
+ merge(ext, props.linter);
141
76
  }
142
- if (injectStyles) {
143
- injectStyles.call(this, context);
77
+ if (props.extensions) {
78
+ merge(ext, props.extensions);
144
79
  }
145
- if (context && context._registeredComponents) {
146
- context._registeredComponents.add(moduleIdentifier);
80
+ return compact(ext);
81
+ });
82
+ let view;
83
+ watch(modelValue, (current) => {
84
+ if (view.composing) {
85
+ return;
147
86
  }
87
+ const previous = view.state.selection;
88
+ view.setState(EditorState.create({
89
+ doc: current,
90
+ extensions: extensions.value,
91
+ selection: previous
92
+ }));
93
+ });
94
+ watch(dark, () => {
95
+ view.setState(EditorState.create({
96
+ doc: modelValue.value,
97
+ extensions: extensions.value
98
+ }));
99
+ });
100
+ onMounted(() => {
101
+ const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
102
+ view = new EditorView({
103
+ state: EditorState.create({
104
+ doc: value,
105
+ extensions: extensions.value
106
+ }),
107
+ parent: editor.value,
108
+ dispatch: (tr) => {
109
+ view.update([tr]);
110
+ if (tr.changes.empty)
111
+ return;
112
+ modelValue.value = view.state.doc.toString();
113
+ emit("update:modelValue", modelValue.value);
114
+ }
115
+ });
116
+ });
117
+ onUnmounted(() => view.destroy());
118
+ return {
119
+ context,
120
+ editor
148
121
  };
149
- options._ssrRegister = hook;
150
- } else if (injectStyles) {
151
- hook = shadowMode ? function() {
152
- injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
153
- } : injectStyles;
154
- }
155
- if (hook) {
156
- if (options.functional) {
157
- options._injectStyles = hook;
158
- var originalRender = options.render;
159
- options.render = function renderWithStyleInjection(h, context) {
160
- hook.call(context);
161
- return originalRender(h, context);
162
- };
163
- } else {
164
- var existing = options.beforeCreate;
165
- options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
166
- }
167
- }
168
- return {
169
- exports: scriptExports,
170
- options
171
- };
172
- }
173
- const __cssModules = {};
174
- var __component__ = /* @__PURE__ */ normalizeComponent(CodeMirror, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
175
- function __vue2_injectStyles(context) {
176
- for (let o in __cssModules) {
177
- this[o] = __cssModules[o];
178
122
  }
179
- }
180
- var component$1 = /* @__PURE__ */ function() {
181
- return __component__.exports;
182
- }();
183
- var component = /* @__PURE__ */ (() => {
184
- const installable = component$1;
185
- installable.install = (Vue2) => {
186
- Vue2.component("CodeMirror", installable);
187
- };
188
- return installable;
189
- })();
190
- var namedExports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
191
- __proto__: null,
192
- "default": component
193
- }, Symbol.toStringTag, { value: "Module" }));
194
- Object.entries(namedExports).forEach(([exportName, exported]) => {
195
- if (exportName !== "default")
196
- component[exportName] = exported;
197
123
  });
198
- export { component as default };
124
+ const _hoisted_1 = {
125
+ ref: "editor",
126
+ class: "vue-codemirror"
127
+ };
128
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
129
+ return openBlock(), createElementBlock("div", _hoisted_1, [
130
+ withDirectives(createElementVNode("aside", null, [
131
+ renderSlot(_ctx.$slots, "default")
132
+ ], 512), [
133
+ [vShow, !_ctx.context.slots.default]
134
+ ])
135
+ ], 512);
136
+ }
137
+ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
138
+ /**
139
+ * Vue CodeMirror6 Component
140
+ *
141
+ * @license MIT
142
+ * @author Logue {@link logue@hotmail.co.jp}
143
+ * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
144
+ * @see {@link https://github.com/logue/vue-codemirror6}
145
+ */
146
+ install();
147
+ const installCodeMirror = (app) => {
148
+ app.component("CodeMirror", CodeMirror);
149
+ };
150
+ export { CodeMirror, CodeMirror as default, installCodeMirror as install };
@@ -1,3 +1,8 @@
1
- (function(i,d){typeof exports=="object"&&typeof module<"u"?module.exports=d(require("vue-property-decorator"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["vue-property-decorator","@codemirror/state","@codemirror/view","lodash"],d):(i=typeof globalThis<"u"?globalThis:i||self,i.CodeMirror=d(i.vuePropertyDecorator,i.state,i.view,i.lodash))})(this,function(i,d,c,_){"use strict";var g=Object.defineProperty,b=Object.getOwnPropertyDescriptor,s=(e,t,p,f)=>{for(var r=f>1?void 0:f?b(t,p):t,h=e.length-1,u;h>=0;h--)(u=e[h])&&(r=(f?u(t,p,r):u(r))||r);return f&&r&&g(t,p,r),r};let o=class extends i.Vue{onValueChanged(){if(this.editor.composing)return;const e=this.editor.state.selection;this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension,selection:e}))}onToggleDarkMode(){this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension}))}get extension(){const e=_.compact([c.EditorView.updateListener.of(t=>this.$emit("update",t)),c.EditorView.theme(this.theme,{dark:this.dark}),this.phrases?d.EditorState.phrases.of(this.phrases):void 0,this.lang?this.lang:void 0,d.EditorState.readOnly.of(this.readonly),c.EditorView.editable.of(this.editable)]);return this.linter.length!==0&&_.merge(e,this.linter),this.extensions.length!==0&&_.merge(e,this.extensions),console.debug("[CodeMirror.vue] Loaded extensions:",e),e}mounted(){let e=this.value;!this.value&&this.$slots.default!==void 0&&(e=this.getChildrenTextContent(this.$slots.default)),this.editor=new c.EditorView({state:d.EditorState.create({doc:e,extensions:this.extension}),parent:this.$refs.editor,dispatch:t=>{this.editor.update([t]),!t.changes.empty&&this.$emit("input",this.editor.state.doc.toString())}})}beforeDestroy(){this.editor.destroy()}getChildrenTextContent(e){return e.map(t=>t.children?this.getChildrenTextContent(t.children):t.text||`
2
- `).join("")}};s([i.Prop({type:Object,default:()=>{}})],o.prototype,"theme",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"dark",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"readonly",2),s([i.Prop({type:Boolean,default:!0})],o.prototype,"editable",2),s([i.Prop({type:Object})],o.prototype,"phrases",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"extensions",2),s([i.Prop({type:Object})],o.prototype,"lang",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"linter",2),s([i.Prop({type:String,default:""})],o.prototype,"value",2),s([i.Watch("value")],o.prototype,"onValueChanged",1),s([i.Watch("dark")],o.prototype,"onToggleDarkMode",1),o=s([i.Component({name:"CodeMirror"})],o);var S=function(){var e=this,t=e.$createElement,p=e._self._c||t;return p("pre",{ref:"editor"},[e._v(" "),e.$slots.default?e._e():[e._t("default")],e._v(`
3
- `)],2)},$=[];function E(e,t,p,f,r,h,u,M){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=p,n._compiled=!0),f&&(n.functional=!0),h&&(n._scopeId="data-v-"+h);var l;if(u?(l=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__<"u"&&(a=__VUE_SSR_CONTEXT__),r&&r.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(u)},n._ssrRegister=l):r&&(l=M?function(){r.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(n.functional){n._injectStyles=l;var V=n.render;n.render=function(w,C){return l.call(C),V(w,C)}}else{var y=n.beforeCreate;n.beforeCreate=y?[].concat(y,l):[l]}return{exports:e,options:n}}const v={};var O=E(o,S,$,!1,x,null,null,null);function x(e){for(let t in v)this[t]=v[t]}var T=function(){return O.exports}(),m=(()=>{const e=T;return e.install=t=>{t.component("CodeMirror",e)},e})(),j=Object.freeze(Object.defineProperty({__proto__:null,default:m},Symbol.toStringTag,{value:"Module"}));return Object.entries(j).forEach(([e,t])=>{e!=="default"&&(m[e]=t)}),m});
1
+ (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.lodash,o.Vue))})(this,function(o,t,s,f,m,i){"use strict";var p=(e,u)=>{const d=e.__vccOpts||e;for(const[r,c]of u)d[r]=c;return d};const V=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:void 0},dark:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:void 0},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Array,default:void 0}},emits:["update:modelValue","update"],setup(e,u){const d=t.ref(),r=t.ref(e.modelValue),c=t.ref(e.dark),y=u.emit,h=t.computed(()=>{const a=[f.EditorView.updateListener.of(l=>{y("update",l)}),f.EditorView.theme(e.theme||{},{dark:c.value}),e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?f.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(a,e.linter),e.extensions&&m.merge(a,e.extensions),m.compact(a)});let n;return t.watch(r,a=>{if(n.composing)return;const l=n.state.selection;n.setState(s.EditorState.create({doc:a,extensions:h.value,selection:l}))}),t.watch(c,()=>{n.setState(s.EditorState.create({doc:r.value,extensions:h.value}))}),t.onMounted(()=>{const a=!r.value&&d.value?d.value.childNodes[0].innerText:r.value;n=new f.EditorView({state:s.EditorState.create({doc:a,extensions:h.value}),parent:d.value,dispatch:l=>{n.update([l]),!l.changes.empty&&(r.value=n.state.doc.toString(),y("update:modelValue",r.value))}})}),t.onUnmounted(()=>n.destroy()),{context:u,editor:d}}}),S={ref:"editor",class:"vue-codemirror"};function _(e,u,d,r,c,y){return i.openBlock(),i.createElementBlock("div",S,[i.withDirectives(i.createElementVNode("aside",null,[i.renderSlot(e.$slots,"default")],512),[[i.vShow,!e.context.slots.default]])],512)}var v=p(V,[["render",_]]);/**
2
+ * Vue CodeMirror6 Component
3
+ *
4
+ * @license MIT
5
+ * @author Logue {@link logue@hotmail.co.jp}
6
+ * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
+ * @see {@link https://github.com/logue/vue-codemirror6}
8
+ */t.install();const E=e=>{e.component("CodeMirror",v)};o.CodeMirror=v,o.default=v,o.install=E,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});