vue-codemirror6 0.6.0 → 0.6.1

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.
@@ -133,6 +133,7 @@ declare const _default: import("vue-demi").DefineComponent<{
133
133
  }, {
134
134
  context: SetupContext<import("vue-demi").EmitsOptions>;
135
135
  editor: Ref<Element | undefined>;
136
+ cursor: Ref<number>;
136
137
  selection: () => EditorSelection;
137
138
  getRange: (from?: number, to?: number) => string;
138
139
  getLine: (number: number) => string;
@@ -144,7 +145,7 @@ declare const _default: import("vue-demi").DefineComponent<{
144
145
  somethingSelected: () => boolean;
145
146
  replaceRange: (replacement: string | Text, from: number, to: number) => void;
146
147
  replaceSelection: (replacement: string | Text) => void;
147
- setCursor: (position: number) => void;
148
+ setCursor: (position: number) => number;
148
149
  setSelection: (anchor: number, head?: number) => void;
149
150
  setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;
150
151
  extendSelectionsBy: (f: Function) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAA4B,MAAM,mBAAmB,CAAC;AAU9E,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,IAAI,EAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,WAAW,wBAAwB;IACvC,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBA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AAM,GAAG,IAAI;0BAOvB,MAAM;2BAOL,MAAM,SAAS,MAAM;4BASzC,SAAS,cAAc,EAAE,YACvB,MAAM;4BAUa,QAAQ;;oBAUlB,OAAO;;IAxW5B,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;AA3HtB,wBA6ZG"}
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isVue2, h as h$1, defineComponent, ref, toRefs, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
2
- import { EditorState, StateEffect, EditorSelection } from "@codemirror/state";
1
+ import { isVue2, h as h$1, defineComponent, ref, toRefs, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
2
+ import { StateEffect, EditorState, EditorSelection } from "@codemirror/state";
3
3
  import { EditorView, keymap } from "@codemirror/view";
4
4
  import { linter, lintGutter } from "@codemirror/lint";
5
5
  import { basicSetup, minimalSetup } from "codemirror";
@@ -95,21 +95,24 @@ var CodeMirror = defineComponent({
95
95
  const editor = ref();
96
96
  const { dark } = toRefs(props);
97
97
  const doc = ref(props.modelValue);
98
+ const cursor = computed({
99
+ get: () => view.state.selection.main.head,
100
+ set: (p) => view.dispatch({ selection: { anchor: p } })
101
+ });
98
102
  const emit = context.emit;
99
103
  let view;
100
104
  watch(doc, (value) => {
101
105
  if (view.composing) {
102
106
  return;
103
107
  }
104
- const previous = view.state.selection;
105
- view.setState(EditorState.create({
106
- doc: value,
107
- extensions: getExtensions(),
108
- selection: previous
109
- }));
108
+ view.dispatch({
109
+ changes: { from: 0, to: value.length, insert: value },
110
+ selection: { anchor: cursor.value }
111
+ });
110
112
  });
111
113
  watch(() => props.modelValue, (text) => view.dispatch({
112
- changes: { from: 0, to: view.state.doc.length, insert: text }
114
+ changes: { from: 0, to: view.state.doc.length, insert: text },
115
+ selection: { anchor: cursor.value }
113
116
  }));
114
117
  watch(dark, () => {
115
118
  view.dispatch({
@@ -161,7 +164,7 @@ var CodeMirror = defineComponent({
161
164
  const getRange = (from, to) => view.state.sliceDoc(from, to);
162
165
  const getLine = (number) => view.state.doc.line(number + 1).text;
163
166
  const lineCount = () => view.state.doc.lines;
164
- const getCursor = () => selection().main.head;
167
+ const getCursor = () => cursor.value;
165
168
  const listSelections = () => selection().ranges;
166
169
  const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
167
170
  const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
@@ -170,7 +173,7 @@ var CodeMirror = defineComponent({
170
173
  changes: { from, to, insert: replacement }
171
174
  });
172
175
  const replaceSelection = (replacement) => view.dispatch(view.state.replaceSelection(replacement));
173
- const setCursor = (position) => view.dispatch({ selection: { anchor: position } });
176
+ const setCursor = (position) => cursor.value = position;
174
177
  const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
175
178
  const setSelections = (ranges, primary) => view.dispatch({
176
179
  selection: EditorSelection.create(ranges, primary)
@@ -183,6 +186,7 @@ var CodeMirror = defineComponent({
183
186
  return {
184
187
  context,
185
188
  editor,
189
+ cursor,
186
190
  selection,
187
191
  getRange,
188
192
  getLine,
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,f,d,p,g,V,S){"use strict";const C=e=>e?Object.entries(e).reduce((c,[a,l])=>(a=a.charAt(0).toUpperCase()+a.slice(1),a=`on${a}`,{...c,[a]:l}),{}):null,y=(e,c={},a)=>{if(n.isVue2)return n.h(e,c,a);const{props:l,domProps:u,on:m,...o}=c,h=m?C(m):{};return n.h(e,{...o,...l,...u,...h},a)},w=e=>typeof e=="function"?e():e;var v=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{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:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,c){const a=n.ref(),{dark:l}=n.toRefs(e),u=n.ref(e.modelValue),m=c.emit;let o;n.watch(u,t=>{if(o.composing)return;const i=o.state.selection;o.setState(f.EditorState.create({doc:t,extensions:h(),selection:i}))}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t}})),n.watch(l,()=>{o.dispatch({effects:f.StateEffect.appendConfig.of(d.EditorView.theme(e.theme,{dark:l.value}))})}),n.onMounted(async()=>{let t=u.value;a.value&&a.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=S.trim(a.value.childNodes[0].innerText)),o=new d.EditorView({doc:t,extensions:h(),parent:a.value,dispatch:i=>{o.update([i]),!i.changes.empty&&(u.value=o.state.doc.toString(),m("update:modelValue",u.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>S.compact([e.basic?g.basicSetup:void 0,e.minimal&&!e.basic?g.minimalSetup:void 0,d.EditorView.updateListener.of(i=>m("update",i)),d.EditorView.theme(e.theme,{dark:l.value}),e.wrap?d.EditorView.lineWrapping:void 0,e.tab?d.keymap.of([V.indentWithTab]):void 0,e.phrases?f.EditorState.phrases.of(e.phrases):void 0,e.readonly?f.EditorState.readOnly.of(e.readonly):void 0,e.editable?d.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]),s=()=>o.state.selection;return{context:c,editor:a,selection:s,getRange:(t,i)=>o.state.sliceDoc(t,i),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>s().main.head,listSelections:()=>s().ranges,getSelection:()=>o.state.sliceDoc(s().main.from,s().main.to),getSelections:()=>s().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>s().ranges.some(t=>!t.empty),replaceRange:(t,i,E)=>o.dispatch({changes:{from:i,to:E,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>o.dispatch({selection:{anchor:t}}),setSelection:(t,i)=>o.dispatch({selection:{anchor:t,head:i}}),setSelections:(t,i)=>o.dispatch({selection:f.EditorSelection.create(t,i)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(s().ranges.map(i=>i.extend(t(i))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return y("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?y("aside",{style:"display: none;"},w(this.$slots.default)):void 0)}});/**
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,m,c,p,g,V,y){"use strict";const C=e=>e?Object.entries(e).reduce((d,[i,l])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:l}),{}):null,S=(e,d={},i)=>{if(n.isVue2)return n.h(e,d,i);const{props:l,domProps:u,on:s,...h}=d,o=s?C(s):{};return n.h(e,{...h,...l,...u,...o},i)},w=e=>typeof e=="function"?e():e;var v=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{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:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,d){const i=n.ref(),{dark:l}=n.toRefs(e),u=n.ref(e.modelValue),s=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),h=d.emit;let o;n.watch(u,t=>{o.composing||o.dispatch({changes:{from:0,to:t.length,insert:t},selection:{anchor:s.value}})}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:s.value}})),n.watch(l,()=>{o.dispatch({effects:m.StateEffect.appendConfig.of(c.EditorView.theme(e.theme,{dark:l.value}))})}),n.onMounted(async()=>{let t=u.value;i.value&&i.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=y.trim(i.value.childNodes[0].innerText)),o=new c.EditorView({doc:t,extensions:E(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(u.value=o.state.doc.toString(),h("update:modelValue",u.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const E=()=>y.compact([e.basic?g.basicSetup:void 0,e.minimal&&!e.basic?g.minimalSetup:void 0,c.EditorView.updateListener.of(a=>h("update",a)),c.EditorView.theme(e.theme,{dark:l.value}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([V.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?n.toRaw(e.lang):void 0,e.linter?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]),f=()=>o.state.selection;return{context:d,editor:i,cursor:s,selection:f,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>s.value,listSelections:()=>f().ranges,getSelection:()=>o.state.sliceDoc(f().main.from,f().main.to),getSelections:()=>f().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>f().ranges.some(t=>!t.empty),replaceRange:(t,a,b)=>o.dispatch({changes:{from:a,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>s.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:m.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:m.EditorSelection.create(f().ranges.map(a=>a.extend(t(a))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;"},w(this.$slots.default)):void 0)}});/**
2
2
  * Vue CodeMirror6 Component
3
3
  *
4
4
  * @license MIT
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.6.0",
4
+ "version": "0.6.1",
5
5
  "description": "CodeMirror6 Component for vue2 and vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -80,9 +80,9 @@
80
80
  "@codemirror/lang-javascript": "^6.0.0",
81
81
  "@codemirror/lang-markdown": "^6.0.0",
82
82
  "@types/lodash": "^4.14.182",
83
- "@types/node": "^17.0.41",
84
- "@typescript-eslint/eslint-plugin": "^5.27.1",
85
- "@typescript-eslint/parser": "^5.27.1",
83
+ "@types/node": "^17.0.43",
84
+ "@typescript-eslint/eslint-plugin": "^5.28.0",
85
+ "@typescript-eslint/parser": "^5.28.0",
86
86
  "@vitejs/plugin-vue": "^2.3.3",
87
87
  "@vue/eslint-config-prettier": "^7.0.0",
88
88
  "eslint": "^8.17.0",
@@ -94,22 +94,22 @@
94
94
  "eslint-plugin-import": "^2.26.0",
95
95
  "eslint-plugin-jsdoc": "^39.3.2",
96
96
  "eslint-plugin-tsdoc": "^0.2.16",
97
- "eslint-plugin-vue": "^9.1.0",
97
+ "eslint-plugin-vue": "^9.1.1",
98
98
  "eslint-plugin-vuejs-accessibility": "^1.2.0",
99
99
  "eslint-plugin-yaml": "^0.5.0",
100
100
  "eslint4b-prebuilt": "^6.7.2",
101
101
  "husky": "^8.0.1",
102
102
  "lint-staged": "^13.0.1",
103
103
  "lodash": "^4.17.21",
104
- "prettier": "^2.6.2",
104
+ "prettier": "^2.7.0",
105
105
  "rimraf": "^3.0.2",
106
106
  "rollup-plugin-visualizer": "^5.6.0",
107
107
  "typescript": "^4.7.3",
108
- "vite": "^2.9.10",
108
+ "vite": "^2.9.12",
109
109
  "vite-plugin-checker": "^0.4.6",
110
110
  "vue": "^3.2.37",
111
111
  "vue-eslint-parser": "^9.0.2",
112
- "vue-tsc": "^0.37.3"
112
+ "vue-tsc": "^0.37.8"
113
113
  },
114
114
  "husky": {
115
115
  "hooks": {