vue-codemirror6 0.0.6 → 0.1.3

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,111 +1,123 @@
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
- const previous = this.editor.state.selection;
19
- this.editor.setState(EditorState.create({
20
- doc: this.value,
21
- extensions: this.extension,
22
- selection: previous
23
- }));
24
- }
25
- onToggleDarkMode() {
26
- this.editor.setState(EditorState.create({
27
- doc: this.value,
28
- extensions: this.extension
29
- }));
30
- }
31
- get extension() {
32
- const ext = compact([
33
- EditorView.updateListener.of((update) => this.$emit("update", update)),
34
- EditorView.theme(this.theme, { dark: this.dark }),
35
- this.phrases ? EditorState.phrases.of(this.phrases) : void 0,
36
- this.lang ? this.lang : void 0
37
- ]);
38
- if (this.linter.length !== 0) {
39
- merge(ext, this.linter);
40
- }
41
- if (this.extensions.length !== 0) {
42
- merge(ext, this.extensions);
43
- }
44
- console.debug("[CodeMirror.vue] Loaded extensions:", ext);
45
- return ext;
46
- }
47
- mounted() {
48
- let value = this.value;
49
- if (!this.value && this.$slots.default !== void 0) {
50
- value = this.getChildrenTextContent(this.$slots.default);
4
+ import { merge, compact } from "lodash";
5
+ var __vue2_script = defineComponent({
6
+ name: "CodeMirror",
7
+ model: {
8
+ prop: "modelValue",
9
+ event: "update:modelValue"
10
+ },
11
+ props: {
12
+ modelValue: {
13
+ type: String,
14
+ default: ""
15
+ },
16
+ theme: {
17
+ type: Object,
18
+ default: void 0
19
+ },
20
+ dark: {
21
+ type: Boolean,
22
+ default: false
23
+ },
24
+ readonly: {
25
+ type: Boolean,
26
+ default: false
27
+ },
28
+ editable: {
29
+ type: Boolean,
30
+ default: true
31
+ },
32
+ extensions: {
33
+ type: Array,
34
+ default: void 0
35
+ },
36
+ phrases: {
37
+ type: Object,
38
+ default: void 0
39
+ },
40
+ lang: {
41
+ type: Object,
42
+ default: void 0
43
+ },
44
+ linter: {
45
+ type: Array,
46
+ default: void 0
51
47
  }
52
- this.editor = new EditorView({
53
- state: EditorState.create({
54
- doc: value,
55
- extensions: this.extension
56
- }),
57
- parent: this.$refs.editor,
58
- dispatch: (tr) => {
59
- this.editor.update([tr]);
60
- if (tr.changes.empty)
61
- return;
62
- this.$emit("input", this.editor.state.doc.toString());
48
+ },
49
+ emits: ["update:modelValue", "update"],
50
+ setup(props, context) {
51
+ const editor = ref();
52
+ const modelValue = ref(props.modelValue);
53
+ const dark = ref(props.dark);
54
+ const emit = context.emit;
55
+ const extensions = computed(() => {
56
+ const ext = [
57
+ EditorView.updateListener.of((update) => {
58
+ emit("update", update);
59
+ }),
60
+ EditorView.theme(props.theme || {}, { dark: dark.value }),
61
+ props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
62
+ props.lang,
63
+ props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
64
+ props.editable ? EditorView.editable.of(props.editable) : void 0
65
+ ];
66
+ if (props.linter) {
67
+ merge(ext, props.linter);
68
+ }
69
+ if (props.extensions) {
70
+ merge(ext, props.extensions);
63
71
  }
72
+ return compact(ext);
64
73
  });
74
+ let view;
75
+ watch(modelValue, (current) => {
76
+ if (view.composing) {
77
+ return;
78
+ }
79
+ const previous = view.state.selection;
80
+ view.setState(EditorState.create({
81
+ doc: current,
82
+ extensions: extensions.value,
83
+ selection: previous
84
+ }));
85
+ });
86
+ watch(dark, () => {
87
+ view.setState(EditorState.create({
88
+ doc: modelValue.value,
89
+ extensions: extensions.value
90
+ }));
91
+ });
92
+ onMounted(() => {
93
+ const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
94
+ view = new EditorView({
95
+ state: EditorState.create({
96
+ doc: value,
97
+ extensions: extensions.value
98
+ }),
99
+ parent: editor.value,
100
+ dispatch: (tr) => {
101
+ view.update([tr]);
102
+ if (tr.changes.empty)
103
+ return;
104
+ modelValue.value = view.state.doc.toString();
105
+ emit("update:modelValue", modelValue.value);
106
+ }
107
+ });
108
+ });
109
+ onUnmounted(() => view.destroy());
110
+ return {
111
+ context,
112
+ editor
113
+ };
65
114
  }
66
- beforeDestroy() {
67
- this.editor.destroy();
68
- }
69
- getChildrenTextContent(children) {
70
- return children.map((node) => node.children ? this.getChildrenTextContent(node.children) : node.text || "\n").join("");
71
- }
72
- };
73
- __decorateClass([
74
- Prop({ type: Object, default: () => {
75
- } })
76
- ], CodeMirror.prototype, "theme", 2);
77
- __decorateClass([
78
- Prop({ type: Boolean, default: false })
79
- ], CodeMirror.prototype, "dark", 2);
80
- __decorateClass([
81
- Prop({ type: Object })
82
- ], CodeMirror.prototype, "phrases", 2);
83
- __decorateClass([
84
- Prop({ type: Array, default: () => [] })
85
- ], CodeMirror.prototype, "extensions", 2);
86
- __decorateClass([
87
- Prop({ type: Object })
88
- ], CodeMirror.prototype, "lang", 2);
89
- __decorateClass([
90
- Prop({ type: Array, default: () => [] })
91
- ], CodeMirror.prototype, "linter", 2);
92
- __decorateClass([
93
- Prop({ type: String, default: "" })
94
- ], CodeMirror.prototype, "value", 2);
95
- __decorateClass([
96
- Watch("value")
97
- ], CodeMirror.prototype, "onValueChanged", 1);
98
- __decorateClass([
99
- Watch("dark")
100
- ], CodeMirror.prototype, "onToggleDarkMode", 1);
101
- CodeMirror = __decorateClass([
102
- Component({ name: "CodeMirror" })
103
- ], CodeMirror);
115
+ });
104
116
  var render = function() {
105
117
  var _vm = this;
106
118
  var _h = _vm.$createElement;
107
119
  var _c = _vm._self._c || _h;
108
- return _c("div", { ref: "editor" }, [!_vm.$slots.default ? [_vm._t("default")] : _vm._e()], 2);
120
+ return _c("div", { ref: "editor", staticClass: "vue-codemirror" }, [_c("aside", { directives: [{ name: "show", rawName: "v-show", value: !_vm.context.slots.default, expression: "!context.slots.default" }] }, [_vm._t("default")], 2)]);
109
121
  };
110
122
  var staticRenderFns = [];
111
123
  function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
@@ -160,28 +172,25 @@ function normalizeComponent(scriptExports, render2, staticRenderFns2, functional
160
172
  };
161
173
  }
162
174
  const __cssModules = {};
163
- var __component__ = /* @__PURE__ */ normalizeComponent(CodeMirror, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
175
+ var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
164
176
  function __vue2_injectStyles(context) {
165
177
  for (let o in __cssModules) {
166
178
  this[o] = __cssModules[o];
167
179
  }
168
180
  }
169
- var component$1 = /* @__PURE__ */ function() {
181
+ var CodeMirror = /* @__PURE__ */ function() {
170
182
  return __component__.exports;
171
183
  }();
172
- var component = /* @__PURE__ */ (() => {
173
- const installable = component$1;
174
- installable.install = (Vue2) => {
175
- Vue2.component("CodeMirror", installable);
176
- };
177
- return installable;
178
- })();
179
- var namedExports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
180
- __proto__: null,
181
- "default": component
182
- }, Symbol.toStringTag, { value: "Module" }));
183
- Object.entries(namedExports).forEach(([exportName, exported]) => {
184
- if (exportName !== "default")
185
- component[exportName] = exported;
186
- });
187
- export { component as default };
184
+ /**
185
+ * Vue CodeMirror6 Component
186
+ *
187
+ * @license MIT
188
+ * @author Logue {@link logue@hotmail.co.jp}
189
+ * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
190
+ * @see {@link https://github.com/logue/vue-codemirror6}
191
+ */
192
+ install();
193
+ const installCodeMirror = (app) => {
194
+ app.component("CodeMirror", CodeMirror);
195
+ };
196
+ export { CodeMirror, CodeMirror as default, installCodeMirror as install };
@@ -1,2 +1,8 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?module.exports=a(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"],a):(i=typeof globalThis<"u"?globalThis:i||self,i.CodeMirror=a(i.vuePropertyDecorator,i.state,i.view,i.lodash))})(this,function(i,a,c,_){"use strict";var y=Object.defineProperty,$=Object.getOwnPropertyDescriptor,s=(e,t,h,f)=>{for(var o=f>1?void 0:f?$(t,h):t,p=e.length-1,u;p>=0;p--)(u=e[p])&&(o=(f?u(t,h,o):u(o))||o);return f&&o&&y(t,h,o),o};let r=class extends i.Vue{onValueChanged(){const e=this.editor.state.selection;this.editor.setState(a.EditorState.create({doc:this.value,extensions:this.extension,selection:e}))}onToggleDarkMode(){this.editor.setState(a.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?a.EditorState.phrases.of(this.phrases):void 0,this.lang?this.lang:void 0]);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:a.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:()=>{}})],r.prototype,"theme",2),s([i.Prop({type:Boolean,default:!1})],r.prototype,"dark",2),s([i.Prop({type:Object})],r.prototype,"phrases",2),s([i.Prop({type:Array,default:()=>[]})],r.prototype,"extensions",2),s([i.Prop({type:Object})],r.prototype,"lang",2),s([i.Prop({type:Array,default:()=>[]})],r.prototype,"linter",2),s([i.Prop({type:String,default:""})],r.prototype,"value",2),s([i.Watch("value")],r.prototype,"onValueChanged",1),s([i.Watch("dark")],r.prototype,"onToggleDarkMode",1),r=s([i.Component({name:"CodeMirror"})],r);var S=function(){var e=this,t=e.$createElement,h=e._self._c||t;return h("div",{ref:"editor"},[e.$slots.default?e._e():[e._t("default")]],2)},x=[];function O(e,t,h,f,o,p,u,M){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=h,n._compiled=!0),f&&(n.functional=!0),p&&(n._scopeId="data-v-"+p);var l;if(u?(l=function(d){d=d||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!d&&typeof __VUE_SSR_CONTEXT__<"u"&&(d=__VUE_SSR_CONTEXT__),o&&o.call(this,d),d&&d._registeredComponents&&d._registeredComponents.add(u)},n._ssrRegister=l):o&&(l=M?function(){o.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:o),l)if(n.functional){n._injectStyles=l;var w=n.render;n.render=function(V,g){return l.call(g),w(V,g)}}else{var C=n.beforeCreate;n.beforeCreate=C?[].concat(C,l):[l]}return{exports:e,options:n}}const m={};var T=O(r,S,x,!1,b,null,null,null);function b(e){for(let t in m)this[t]=m[t]}var E=function(){return T.exports}(),v=(()=>{const e=E;return e.install=t=>{t.component("CodeMirror",e)},e})(),j=Object.freeze(Object.defineProperty({__proto__:null,default:v},Symbol.toStringTag,{value:"Module"}));return Object.entries(j).forEach(([e,t])=>{e!=="default"&&(v[e]=t)}),v});
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lodash))})(this,function(r,n,c,_,m){"use strict";var S=n.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,i){const d=n.ref(),s=n.ref(e.modelValue),u=n.ref(e.dark),v=i.emit,f=n.computed(()=>{const t=[_.EditorView.updateListener.of(o=>{v("update",o)}),_.EditorView.theme(e.theme||{},{dark:u.value}),e.phrases?c.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?c.EditorState.readOnly.of(e.readonly):void 0,e.editable?_.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(t,e.linter),e.extensions&&m.merge(t,e.extensions),m.compact(t)});let a;return n.watch(s,t=>{if(a.composing)return;const o=a.state.selection;a.setState(c.EditorState.create({doc:t,extensions:f.value,selection:o}))}),n.watch(u,()=>{a.setState(c.EditorState.create({doc:s.value,extensions:f.value}))}),n.onMounted(()=>{const t=!s.value&&d.value?d.value.childNodes[0].innerText:s.value;a=new _.EditorView({state:c.EditorState.create({doc:t,extensions:f.value}),parent:d.value,dispatch:o=>{a.update([o]),!o.changes.empty&&(s.value=a.state.doc.toString(),v("update:modelValue",s.value))}})}),n.onUnmounted(()=>a.destroy()),{context:i,editor:d}}}),V=function(){var e=this,i=e.$createElement,d=e._self._c||i;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)])},w=[];function E(e,i,d,s,u,v,f,a){var t=typeof e=="function"?e.options:e;i&&(t.render=i,t.staticRenderFns=d,t._compiled=!0),s&&(t.functional=!0),v&&(t._scopeId="data-v-"+v);var o;if(f?(o=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=o):u&&(o=a?function(){u.call(this,(t.functional?this.parent:this).$root.$options.shadowRoot)}:u),o)if(t.functional){t._injectStyles=o;var T=t.render;t.render=function($,C){return o.call(C),T($,C)}}else{var y=t.beforeCreate;t.beforeCreate=y?[].concat(y,o):[o]}return{exports:e,options:t}}const p={};var M=E(S,V,w,!1,b,null,null,null);function b(e){for(let i in p)this[i]=p[i]}var h=function(){return M.exports}();/**
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
+ */n.install();const g=e=>{e.component("CodeMirror",h)};r.CodeMirror=h,r.default=h,r.install=g,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "vue-codemirror6",
4
- "version": "0.0.6",
4
+ "version": "0.1.3",
5
5
  "description": "CodeMirror6 Component for vue2",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -54,56 +54,67 @@
54
54
  "sideEffects": false,
55
55
  "scripts": {
56
56
  "dev": "vite",
57
+ "clean": "rimraf node_modules/.vite",
57
58
  "build": "vite build & vue-tsc",
58
59
  "build:clean": "rimraf dist",
59
60
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
60
- "lint:markup": "vue-tsc --noEmit",
61
- "prepare": "husky install"
61
+ "switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
62
+ "switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
63
+ "prepare": "husky install",
64
+ "postinstall": "npx vue-demi-fix"
62
65
  },
63
66
  "dependencies": {
64
- "@codemirror/basic-setup": "^0.19.1",
65
- "@codemirror/lang-markdown": "^0.19.6",
66
- "@codemirror/language": "^0.19.8",
67
- "@codemirror/lint": "^0.19.6",
68
- "@codemirror/view": "^0.19.47",
69
- "lodash": "^4.17.21",
70
- "vue": "^2.6.14",
71
- "vue-class-component": "^7.2.6",
72
- "vue-property-decorator": "^9.1.2"
67
+ "vue-demi": "latest"
68
+ },
69
+ "peerDependencies": {
70
+ "@codemirror/state": "^0.19.9",
71
+ "@codemirror/view": "^0.19.48",
72
+ "@vue/composition-api": "^1.4.9",
73
+ "vue": "^2.6.14 || ^3.2.31"
74
+ },
75
+ "peerDependenciesMeta": {
76
+ "@vue/composition-api": {
77
+ "optional": true
78
+ }
73
79
  },
74
80
  "devDependencies": {
75
- "@types/lodash": "^4.14.180",
76
- "@types/node": "^17.0.21",
77
- "@typescript-eslint/eslint-plugin": "^5.15.0",
78
- "@typescript-eslint/parser": "^5.15.0",
79
- "@vue/compiler-sfc": "^3.2.31",
81
+ "@codemirror/basic-setup": "^0.19.3",
82
+ "@codemirror/lang-markdown": "^0.19.6",
83
+ "@codemirror/language": "^0.19.10",
84
+ "@codemirror/lint": "^0.19.6",
85
+ "@modyqyw/vite-plugin-eslint": "^1.2.0",
86
+ "@types/lodash": "^4.14.181",
87
+ "@types/node": "^17.0.23",
88
+ "@typescript-eslint/eslint-plugin": "^5.18.0",
89
+ "@typescript-eslint/parser": "^5.18.0",
90
+ "@vue/composition-api": "^1.4.9",
80
91
  "@vue/eslint-config-typescript": "^10.0.0",
81
- "eslint": "^8.11.0",
92
+ "eslint": "^8.12.0",
82
93
  "eslint-config-google": "^0.14.0",
83
94
  "eslint-config-prettier": "^8.5.0",
84
95
  "eslint-import-resolver-alias": "^1.1.2",
85
- "eslint-import-resolver-typescript": "^2.5.0",
86
- "eslint-plugin-import": "^2.25.4",
96
+ "eslint-import-resolver-typescript": "^2.7.1",
97
+ "eslint-plugin-import": "^2.26.0",
87
98
  "eslint-plugin-prettier": "^4.0.0",
88
99
  "eslint-plugin-prettier-vue": "^3.1.0",
89
100
  "eslint-plugin-tsdoc": "^0.2.14",
90
101
  "eslint-plugin-vue": "^8.5.0",
91
102
  "eslint-plugin-vuejs-accessibility": "^1.1.1",
92
103
  "husky": "^7.0.4",
93
- "lint-staged": "^12.3.6",
94
- "prettier": "^2.6.0",
95
- "prettier-plugin-jsdoc": "^0.3.31",
104
+ "lint-staged": "^12.3.7",
105
+ "lodash": "^4.17.21",
106
+ "prettier": "^2.6.2",
107
+ "prettier-plugin-jsdoc": "^0.3.36",
96
108
  "prettier-plugin-md-nocjsp": "^1.2.0",
97
109
  "prettier-plugin-sort-imports": "^1.6.0",
98
110
  "rimraf": "^3.0.2",
99
- "typescript": ">=3.3.1 <4.6.0",
100
- "vite": "^2.8.6",
101
- "vite-dts": "^1.0.4",
102
- "vite-plugin-eslint": "^1.3.0",
111
+ "typescript": "^4.6.3",
112
+ "vite": "^2.9.1",
103
113
  "vite-plugin-vue2": "^1.9.3",
114
+ "vue": "^2.6.14",
104
115
  "vue-eslint-parser": "^8.3.0",
105
116
  "vue-template-compiler": "^2.6.14",
106
- "vue-tsc": "^0.33.2"
117
+ "vue-tsc": "^0.33.9"
107
118
  },
108
119
  "husky": {
109
120
  "hooks": {