vue-codemirror6 0.1.2 → 0.1.6

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,14 +1,30 @@
1
- import type { Ref, PropType, SetupContext } from 'vue-demi';
2
- import type { Extension } from '@codemirror/state';
1
+ import { type PropType, type Ref, type SetupContext } from 'vue-demi';
2
+ import { EditorSelection } from '@codemirror/state';
3
+ import type { Extension, Text } from '@codemirror/state';
3
4
  import type { LanguageSupport } from '@codemirror/language';
4
5
  import type { Diagnostic } from '@codemirror/lint';
5
6
  import type { StyleSpec } from 'style-mod';
6
- declare const _default: import("vue-demi").DefineComponent<{
7
+ declare const _default: import("vue").ComponentOptions<import("vue").default, import("@vue/composition-api").ShallowUnwrapRef<{
8
+ context: SetupContext<{}>;
9
+ editor: Ref<Element | undefined>;
10
+ }> & import("@vue/composition-api").Data, {}, {}, {
7
11
  /** Model value */
8
12
  modelValue: {
9
- type: StringConstructor;
13
+ type: PropType<string | Text>;
10
14
  default: string;
11
15
  };
16
+ /**
17
+ * Selection
18
+ *
19
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
20
+ */
21
+ selection: {
22
+ type: PropType<EditorSelection | {
23
+ anchor: number;
24
+ head?: number | undefined;
25
+ }>;
26
+ default: undefined;
27
+ };
12
28
  /**
13
29
  * Theme
14
30
  *
@@ -18,7 +34,7 @@ declare const _default: import("vue-demi").DefineComponent<{
18
34
  type: PropType<{
19
35
  [selector: string]: StyleSpec;
20
36
  }>;
21
- default: undefined;
37
+ default: () => {};
22
38
  };
23
39
  /** Dark Mode */
24
40
  dark: {
@@ -26,81 +42,29 @@ declare const _default: import("vue-demi").DefineComponent<{
26
42
  default: boolean;
27
43
  };
28
44
  /**
29
- * Readonly
45
+ * Use Basic Setup
30
46
  *
31
- * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
47
+ * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
32
48
  */
33
- readonly: {
49
+ basic: {
34
50
  type: BooleanConstructor;
35
51
  default: boolean;
36
52
  };
37
53
  /**
38
- * Editable
54
+ * Line wrapping
39
55
  *
40
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
56
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
41
57
  */
42
- editable: {
58
+ wrap: {
43
59
  type: BooleanConstructor;
44
60
  default: boolean;
45
61
  };
46
62
  /**
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
- };
55
- /**
56
- * Language Phreses
57
- *
58
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
59
- */
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
63
+ * Tab handling
93
64
  *
94
- * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
65
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
95
66
  */
96
- theme: {
97
- type: PropType<{
98
- [selector: string]: StyleSpec;
99
- }>;
100
- default: undefined;
101
- };
102
- /** Dark Mode */
103
- dark: {
67
+ tab: {
104
68
  type: BooleanConstructor;
105
69
  default: boolean;
106
70
  };
@@ -158,19 +122,86 @@ declare const _default: import("vue-demi").DefineComponent<{
158
122
  type: PropType<Diagnostic[]>;
159
123
  default: undefined;
160
124
  };
161
- }>>, {
162
- modelValue: string;
125
+ }, {
126
+ modelValue: string | Text;
127
+ selection: EditorSelection | {
128
+ anchor: number;
129
+ head?: number | undefined;
130
+ };
131
+ theme: {
132
+ [selector: string]: StyleSpec;
133
+ };
134
+ dark: boolean;
135
+ basic: boolean;
136
+ wrap: boolean;
137
+ tab: boolean;
138
+ readonly: boolean;
139
+ editable: boolean;
140
+ extensions: Extension[];
141
+ phrases: Record<string, string>;
142
+ lang: LanguageSupport;
143
+ linter: Diagnostic[];
144
+ } & {}> & Omit<import("vue").VueConstructor<import("vue").default>, never> & (new (...args: any[]) => import("@vue/composition-api").ComponentRenderProxy<{
145
+ modelValue: string | Text;
146
+ selection: EditorSelection | {
147
+ anchor: number;
148
+ head?: number | undefined;
149
+ };
150
+ theme: {
151
+ [selector: string]: StyleSpec;
152
+ };
153
+ dark: boolean;
154
+ basic: boolean;
155
+ wrap: boolean;
156
+ tab: boolean;
157
+ readonly: boolean;
158
+ editable: boolean;
159
+ extensions: Extension[];
160
+ phrases: Record<string, string>;
161
+ lang: LanguageSupport;
162
+ linter: Diagnostic[];
163
+ } & {}, import("@vue/composition-api").ShallowUnwrapRef<{
164
+ context: SetupContext<{}>;
165
+ editor: Ref<Element | undefined>;
166
+ }>, import("@vue/composition-api").Data, {}, {}, {}, {}, {}, {
167
+ modelValue: string | Text;
168
+ selection: EditorSelection | {
169
+ anchor: number;
170
+ head?: number | undefined;
171
+ };
172
+ theme: {
173
+ [selector: string]: StyleSpec;
174
+ };
175
+ dark: boolean;
176
+ basic: boolean;
177
+ wrap: boolean;
178
+ tab: boolean;
179
+ readonly: boolean;
180
+ editable: boolean;
181
+ extensions: Extension[];
182
+ phrases: Record<string, string>;
183
+ lang: LanguageSupport;
184
+ linter: Diagnostic[];
185
+ } & {}, {
186
+ modelValue: string | Text;
187
+ selection: EditorSelection | {
188
+ anchor: number;
189
+ head?: number | undefined;
190
+ };
163
191
  theme: {
164
192
  [selector: string]: StyleSpec;
165
193
  };
166
194
  dark: boolean;
195
+ basic: boolean;
196
+ wrap: boolean;
197
+ tab: boolean;
167
198
  readonly: boolean;
168
199
  editable: boolean;
169
200
  extensions: Extension[];
170
201
  phrases: Record<string, string>;
171
202
  lang: LanguageSupport;
172
203
  linter: Diagnostic[];
173
- }>;
204
+ }, true>);
174
205
  /** CodeMirror Component */
175
206
  export default _default;
176
207
  //# 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":"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"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAWL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AASjE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtE,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;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;gBAhG6B,MAAM;;;;;;;;;;;;;;;;;;;gBAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;gBAAN,MAAM;;;;;;;;;;;;;;;;;;;gBAAN,MAAM;;;;;;;;;;;;;;;;;AAvB1C,2BAA2B;AAC3B,wBA6PG"}
package/dist/index.d.ts CHANGED
@@ -8,7 +8,6 @@
8
8
  */
9
9
  import CodeMirror from './components/CodeMirror.vue';
10
10
  import { App } from 'vue-demi';
11
- declare const installCodeMirror: (app: App) => void;
12
- export { CodeMirror, installCodeMirror as install };
13
- export default CodeMirror;
11
+ declare const installCodeMirror: void | ((app: App) => void);
12
+ export { CodeMirror as default, installCodeMirror as install };
14
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAmB,GAAG,EAAE,MAAM,UAAU,CAAC;AAEhD,QAAA,MAAM,iBAAiB,gBACb,GAAG,UAGA,CAAC;AAEd,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
@@ -1,16 +1,10 @@
1
- import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
1
+ import { defineComponent, ref, toRefs, computed, toRaw, watch, onMounted, nextTick, onUnmounted, isVue2, install } from "vue-demi";
2
2
  import { EditorState } from "@codemirror/state";
3
- import { EditorView } from "@codemirror/view";
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;
10
- }
11
- return target;
12
- };
13
- const _sfc_main = defineComponent({
3
+ import { EditorView, keymap } from "@codemirror/view";
4
+ import { basicSetup } from "@codemirror/basic-setup";
5
+ import { indentWithTab } from "@codemirror/commands";
6
+ import { merge, compact, trim } from "lodash";
7
+ var __vue2_script = defineComponent({
14
8
  name: "CodeMirror",
15
9
  model: {
16
10
  prop: "modelValue",
@@ -21,14 +15,32 @@ const _sfc_main = defineComponent({
21
15
  type: String,
22
16
  default: ""
23
17
  },
24
- theme: {
18
+ selection: {
25
19
  type: Object,
26
20
  default: void 0
27
21
  },
22
+ theme: {
23
+ type: Object,
24
+ default: () => {
25
+ return {};
26
+ }
27
+ },
28
28
  dark: {
29
29
  type: Boolean,
30
30
  default: false
31
31
  },
32
+ basic: {
33
+ type: Boolean,
34
+ default: false
35
+ },
36
+ wrap: {
37
+ type: Boolean,
38
+ default: false
39
+ },
40
+ tab: {
41
+ type: Boolean,
42
+ default: false
43
+ },
32
44
  readonly: {
33
45
  type: Boolean,
34
46
  default: false
@@ -57,19 +69,20 @@ const _sfc_main = defineComponent({
57
69
  emits: ["update:modelValue", "update"],
58
70
  setup(props, context) {
59
71
  const editor = ref();
60
- const modelValue = ref(props.modelValue);
61
- const dark = ref(props.dark);
72
+ const doc = ref(props.modelValue);
73
+ const { dark } = toRefs(props);
62
74
  const emit = context.emit;
63
- const extensions = computed(() => {
75
+ const exts = computed(() => {
64
76
  const ext = [
65
- EditorView.updateListener.of((update) => {
66
- emit("update", update);
67
- }),
68
- EditorView.theme(props.theme || {}, { dark: dark.value }),
77
+ props.basic ? basicSetup : void 0,
78
+ EditorView.updateListener.of((update) => emit("update", update)),
79
+ EditorView.theme(props.theme, { dark: dark.value }),
80
+ props.wrap ? EditorView.lineWrapping : void 0,
81
+ props.tab ? keymap.of([indentWithTab]) : void 0,
69
82
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
70
- props.lang,
71
83
  props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
72
- props.editable ? EditorView.editable.of(props.editable) : void 0
84
+ props.editable ? EditorView.editable.of(props.editable) : void 0,
85
+ props.lang ? toRaw(props.lang) : void 0
73
86
  ];
74
87
  if (props.linter) {
75
88
  merge(ext, props.linter);
@@ -80,39 +93,43 @@ const _sfc_main = defineComponent({
80
93
  return compact(ext);
81
94
  });
82
95
  let view;
83
- watch(modelValue, (current) => {
96
+ watch(doc, (current) => {
84
97
  if (view.composing) {
85
98
  return;
86
99
  }
87
100
  const previous = view.state.selection;
88
101
  view.setState(EditorState.create({
89
102
  doc: current,
90
- extensions: extensions.value,
103
+ extensions: exts.value,
91
104
  selection: previous
92
105
  }));
93
106
  });
94
107
  watch(dark, () => {
95
108
  view.setState(EditorState.create({
96
- doc: modelValue.value,
97
- extensions: extensions.value
109
+ doc: doc.value,
110
+ extensions: exts.value
98
111
  }));
99
112
  });
100
- onMounted(() => {
101
- const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
113
+ onMounted(async () => {
114
+ if (doc.value == "" && editor.value) {
115
+ doc.value = trim(editor.value.childNodes[0].innerText);
116
+ }
102
117
  view = new EditorView({
103
118
  state: EditorState.create({
104
- doc: value,
105
- extensions: extensions.value
119
+ doc: doc.value,
120
+ selection: props.selection,
121
+ extensions: exts.value
106
122
  }),
107
123
  parent: editor.value,
108
124
  dispatch: (tr) => {
109
125
  view.update([tr]);
110
126
  if (tr.changes.empty)
111
127
  return;
112
- modelValue.value = view.state.doc.toString();
113
- emit("update:modelValue", modelValue.value);
128
+ doc.value = view.state.doc.toString();
129
+ emit("update:modelValue", doc.value);
114
130
  }
115
131
  });
132
+ await nextTick();
116
133
  });
117
134
  onUnmounted(() => view.destroy());
118
135
  return {
@@ -121,20 +138,84 @@ const _sfc_main = defineComponent({
121
138
  };
122
139
  }
123
140
  });
124
- const _hoisted_1 = {
125
- ref: "editor",
126
- class: "vue-codemirror"
141
+ var render = function() {
142
+ var _vm = this;
143
+ var _h = _vm.$createElement;
144
+ var _c = _vm._self._c || _h;
145
+ return _c("div", {
146
+ ref: "editor",
147
+ staticClass: "vue-codemirror"
148
+ }, [_c("aside", {
149
+ directives: [{
150
+ name: "show",
151
+ rawName: "v-show",
152
+ value: !_vm.context.slots.default,
153
+ expression: "!context.slots.default"
154
+ }]
155
+ }, [_vm._t("default")], 2)]);
127
156
  };
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);
157
+ var staticRenderFns = [];
158
+ function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
159
+ var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
160
+ if (render2) {
161
+ options.render = render2;
162
+ options.staticRenderFns = staticRenderFns2;
163
+ options._compiled = true;
164
+ }
165
+ if (functionalTemplate) {
166
+ options.functional = true;
167
+ }
168
+ if (scopeId) {
169
+ options._scopeId = "data-v-" + scopeId;
170
+ }
171
+ var hook;
172
+ if (moduleIdentifier) {
173
+ hook = function(context) {
174
+ context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
175
+ if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
176
+ context = __VUE_SSR_CONTEXT__;
177
+ }
178
+ if (injectStyles) {
179
+ injectStyles.call(this, context);
180
+ }
181
+ if (context && context._registeredComponents) {
182
+ context._registeredComponents.add(moduleIdentifier);
183
+ }
184
+ };
185
+ options._ssrRegister = hook;
186
+ } else if (injectStyles) {
187
+ hook = shadowMode ? function() {
188
+ injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
189
+ } : injectStyles;
190
+ }
191
+ if (hook) {
192
+ if (options.functional) {
193
+ options._injectStyles = hook;
194
+ var originalRender = options.render;
195
+ options.render = function renderWithStyleInjection(h, context) {
196
+ hook.call(context);
197
+ return originalRender(h, context);
198
+ };
199
+ } else {
200
+ var existing = options.beforeCreate;
201
+ options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
202
+ }
203
+ }
204
+ return {
205
+ exports: scriptExports,
206
+ options
207
+ };
136
208
  }
137
- var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
209
+ const __cssModules = {};
210
+ var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
211
+ function __vue2_injectStyles(context) {
212
+ for (let o in __cssModules) {
213
+ this[o] = __cssModules[o];
214
+ }
215
+ }
216
+ var CodeMirror = /* @__PURE__ */ function() {
217
+ return __component__.exports;
218
+ }();
138
219
  /**
139
220
  * Vue CodeMirror6 Component
140
221
  *
@@ -143,8 +224,7 @@ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]
143
224
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
144
225
  * @see {@link https://github.com/logue/vue-codemirror6}
145
226
  */
146
- install();
147
- const installCodeMirror = (app) => {
227
+ const installCodeMirror = isVue2 ? (app) => {
148
228
  app.component("CodeMirror", CodeMirror);
149
- };
150
- export { CodeMirror, CodeMirror as default, installCodeMirror as install };
229
+ } : install();
230
+ export { CodeMirror as default, installCodeMirror as install };
@@ -1,8 +1,8 @@
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",_]]);/**
1
+ (function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/basic-setup","@codemirror/commands","lodash"],o):(n=typeof globalThis<"u"?globalThis:n||self,o(n.CodeMirror={},n.VueDemi,n.state,n.view,n.basicSetup,n.commands,n.lodash))})(this,function(n,o,m,c,C,S,_){"use strict";var w=o.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},selection:{type:Object,default:void 0},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},wrap:{type:Boolean,default:!1},tab:{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,r){const d=o.ref(),s=o.ref(e.modelValue),{dark:u}=o.toRefs(e),v=r.emit,f=o.computed(()=>{const t=[e.basic?C.basicSetup:void 0,c.EditorView.updateListener.of(a=>v("update",a)),c.EditorView.theme(e.theme,{dark:u.value}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([S.indentWithTab]):void 0,e.phrases?m.EditorState.phrases.of(e.phrases):void 0,e.readonly?m.EditorState.readOnly.of(e.readonly):void 0,e.editable?c.EditorView.editable.of(e.editable):void 0,e.lang?o.toRaw(e.lang):void 0];return e.linter&&_.merge(t,e.linter),e.extensions&&_.merge(t,e.extensions),_.compact(t)});let i;return o.watch(s,t=>{if(i.composing)return;const a=i.state.selection;i.setState(m.EditorState.create({doc:t,extensions:f.value,selection:a}))}),o.watch(u,()=>{i.setState(m.EditorState.create({doc:s.value,extensions:f.value}))}),o.onMounted(async()=>{s.value==""&&d.value&&(s.value=_.trim(d.value.childNodes[0].innerText)),i=new c.EditorView({state:m.EditorState.create({doc:s.value,selection:e.selection,extensions:f.value}),parent:d.value,dispatch:t=>{i.update([t]),!t.changes.empty&&(s.value=i.state.doc.toString(),v("update:modelValue",s.value))}}),await o.nextTick()}),o.onUnmounted(()=>i.destroy()),{context:r,editor:d}}}),V=function(){var e=this,r=e.$createElement,d=e._self._c||r;return d("div",{ref:"editor",staticClass:"vue-codemirror"},[d("aside",{directives:[{name:"show",rawName:"v-show",value:!e.context.slots.default,expression:"!context.slots.default"}]},[e._t("default")],2)])},E=[];function T(e,r,d,s,u,v,f,i){var t=typeof e=="function"?e.options:e;r&&(t.render=r,t.staticRenderFns=d,t._compiled=!0),s&&(t.functional=!0),v&&(t._scopeId="data-v-"+v);var a;if(f?(a=function(l){l=l||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!l&&typeof __VUE_SSR_CONTEXT__<"u"&&(l=__VUE_SSR_CONTEXT__),u&&u.call(this,l),l&&l._registeredComponents&&l._registeredComponents.add(f)},t._ssrRegister=a):u&&(a=i?function(){u.call(this,(t.functional?this.parent:this).$root.$options.shadowRoot)}:u),a)if(t.functional){t._injectStyles=a;var R=t.render;t.render=function($,b){return a.call(b),R($,b)}}else{var y=t.beforeCreate;t.beforeCreate=y?[].concat(y,a):[a]}return{exports:e,options:t}}const h={};var M=T(w,V,E,!1,g,null,null,null);function g(e){for(let r in h)this[r]=h[r]}var p=function(){return M.exports}();/**
2
2
  * Vue CodeMirror6 Component
3
3
  *
4
4
  * @license MIT
5
5
  * @author Logue {@link logue@hotmail.co.jp}
6
6
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
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"}})});
8
+ */const O=o.isVue2?e=>{e.component("CodeMirror",p)}:o.install();n.default=p,n.install=O,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});