vue-codemirror6 1.0.3 → 1.1.0

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/index.es.js CHANGED
@@ -5,15 +5,15 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.0.3
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, toRaw, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
12
+ import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
13
13
  import { compact, trim } from 'lodash';
14
14
  import { EditorState, StateEffect, EditorSelection } from '@codemirror/state';
15
- import { EditorView, keymap } from '@codemirror/view';
16
- import { linter, lintGutter } from '@codemirror/lint';
15
+ import { EditorView, keymap, placeholder } from '@codemirror/view';
16
+ import { linter, lintGutter, diagnosticCount } from '@codemirror/lint';
17
17
  import { basicSetup, minimalSetup } from 'codemirror';
18
18
  import { indentWithTab } from '@codemirror/commands';
19
19
 
@@ -69,6 +69,10 @@ const CodeMirror = defineComponent({
69
69
  type: Boolean,
70
70
  default: false
71
71
  },
72
+ placeholder: {
73
+ type: String,
74
+ default: void 0
75
+ },
72
76
  wrap: {
73
77
  type: Boolean,
74
78
  default: false
@@ -81,9 +85,9 @@ const CodeMirror = defineComponent({
81
85
  type: Boolean,
82
86
  default: false
83
87
  },
84
- editable: {
88
+ disabled: {
85
89
  type: Boolean,
86
- default: true
90
+ default: false
87
91
  },
88
92
  extensions: {
89
93
  type: Array,
@@ -103,16 +107,33 @@ const CodeMirror = defineComponent({
103
107
  type: Function,
104
108
  default: void 0
105
109
  },
106
- lintGutter: {
110
+ linterConfig: {
111
+ type: Object,
112
+ default: () => {
113
+ }
114
+ },
115
+ gutter: {
107
116
  type: Boolean,
108
117
  defalt: false
109
118
  },
119
+ gutterConfig: {
120
+ type: Object,
121
+ default: () => {
122
+ }
123
+ },
110
124
  tag: {
111
125
  type: String,
112
126
  default: "div"
113
127
  }
114
128
  },
115
- emits: ["update:modelValue", "update", "ready", "focus", "changed"],
129
+ emits: [
130
+ "update:modelValue",
131
+ "update",
132
+ "ready",
133
+ "focus",
134
+ "changed",
135
+ "diagnosticCount"
136
+ ],
116
137
  setup(props, context) {
117
138
  const editor = ref();
118
139
  const doc = ref(props.modelValue);
@@ -149,10 +170,11 @@ const CodeMirror = defineComponent({
149
170
  props.tab ? keymap.of([indentWithTab]) : void 0,
150
171
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
151
172
  EditorState.readOnly.of(props.readonly),
152
- EditorView.editable.of(props.editable),
153
- props.lang ? toRaw(props.lang) : void 0,
154
- props.linter ? linter(props.linter) : void 0,
155
- props.linter && props.lintGutter ? lintGutter() : void 0,
173
+ EditorView.editable.of(!props.disabled),
174
+ props.lang ? props.lang : void 0,
175
+ props.linter ? linter(props.linter, props.linterConfig) : void 0,
176
+ props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
177
+ props.placeholder ? placeholder(props.placeholder) : void 0,
156
178
  ...props.extensions
157
179
  ])
158
180
  );
@@ -162,22 +184,25 @@ const CodeMirror = defineComponent({
162
184
  if (!view.value || view.value.composing) {
163
185
  return;
164
186
  }
165
- const previous = view.value.state.selection;
187
+ const current = view.value.state;
188
+ if (props.linter) {
189
+ context.emit("diagnosticCount", diagnosticCount(current));
190
+ }
166
191
  view.value.dispatch({
167
- changes: { from: 0, to: view.value.state.doc.length, insert: value },
168
- selection: previous
192
+ changes: { from: 0, to: current.doc.length, insert: value },
193
+ selection: current.selection,
194
+ scrollIntoView: true
169
195
  });
170
196
  },
171
197
  { immediate: true }
172
198
  );
173
- watch(extensions, (e) => {
174
- view.value.dispatch({
175
- effects: StateEffect.reconfigure.of(e)
176
- });
177
- });
178
- watch(focus, (isFocus) => {
179
- context.emit("focus", isFocus);
180
- });
199
+ watch(
200
+ extensions,
201
+ (exts) => view.value.dispatch({
202
+ effects: StateEffect.reconfigure.of(exts)
203
+ })
204
+ );
205
+ watch(focus, (isFocus) => context.emit("focus", isFocus));
181
206
  onMounted(async () => {
182
207
  let value = doc.value;
183
208
  if (editor.value && editor.value.childNodes[0]) {
@@ -204,7 +229,9 @@ const CodeMirror = defineComponent({
204
229
  container: editor.value
205
230
  });
206
231
  });
207
- onUnmounted(() => view.value.destroy());
232
+ onUnmounted(() => {
233
+ view.value.destroy();
234
+ });
208
235
  const getRange = (from, to) => view.value.state.sliceDoc(from, to);
209
236
  const getLine = (number) => view.value.state.doc.line(number + 1).text;
210
237
  const lineCount = () => view.value.state.doc.lines;
@@ -274,8 +301,8 @@ const CodeMirror = defineComponent({
274
301
  });
275
302
 
276
303
  const meta = {
277
- version: "1.0.3",
278
- date: "2022-10-11T23:57:24.765Z"
304
+ version: "1.1.0",
305
+ date: "2022-10-31T12:33:21.284Z"
279
306
  };
280
307
 
281
308
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.0.3
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
@@ -64,6 +64,10 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
64
64
  type: Boolean,
65
65
  default: false
66
66
  },
67
+ placeholder: {
68
+ type: String,
69
+ default: void 0
70
+ },
67
71
  wrap: {
68
72
  type: Boolean,
69
73
  default: false
@@ -76,9 +80,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
76
80
  type: Boolean,
77
81
  default: false
78
82
  },
79
- editable: {
83
+ disabled: {
80
84
  type: Boolean,
81
- default: true
85
+ default: false
82
86
  },
83
87
  extensions: {
84
88
  type: Array,
@@ -98,16 +102,33 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
98
102
  type: Function,
99
103
  default: void 0
100
104
  },
101
- lintGutter: {
105
+ linterConfig: {
106
+ type: Object,
107
+ default: () => {
108
+ }
109
+ },
110
+ gutter: {
102
111
  type: Boolean,
103
112
  defalt: false
104
113
  },
114
+ gutterConfig: {
115
+ type: Object,
116
+ default: () => {
117
+ }
118
+ },
105
119
  tag: {
106
120
  type: String,
107
121
  default: "div"
108
122
  }
109
123
  },
110
- emits: ["update:modelValue", "update", "ready", "focus", "changed"],
124
+ emits: [
125
+ "update:modelValue",
126
+ "update",
127
+ "ready",
128
+ "focus",
129
+ "changed",
130
+ "diagnosticCount"
131
+ ],
111
132
  setup(props, context) {
112
133
  const editor = vueDemi.ref();
113
134
  const doc = vueDemi.ref(props.modelValue);
@@ -144,10 +165,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
144
165
  props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
145
166
  props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
146
167
  state.EditorState.readOnly.of(props.readonly),
147
- view.EditorView.editable.of(props.editable),
148
- props.lang ? vueDemi.toRaw(props.lang) : void 0,
149
- props.linter ? lint.linter(props.linter) : void 0,
150
- props.linter && props.lintGutter ? lint.lintGutter() : void 0,
168
+ view.EditorView.editable.of(!props.disabled),
169
+ props.lang ? props.lang : void 0,
170
+ props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
171
+ props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
172
+ props.placeholder ? view.placeholder(props.placeholder) : void 0,
151
173
  ...props.extensions
152
174
  ])
153
175
  );
@@ -157,22 +179,25 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
157
179
  if (!view$1.value || view$1.value.composing) {
158
180
  return;
159
181
  }
160
- const previous = view$1.value.state.selection;
182
+ const current = view$1.value.state;
183
+ if (props.linter) {
184
+ context.emit("diagnosticCount", lint.diagnosticCount(current));
185
+ }
161
186
  view$1.value.dispatch({
162
- changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
163
- selection: previous
187
+ changes: { from: 0, to: current.doc.length, insert: value },
188
+ selection: current.selection,
189
+ scrollIntoView: true
164
190
  });
165
191
  },
166
192
  { immediate: true }
167
193
  );
168
- vueDemi.watch(extensions, (e) => {
169
- view$1.value.dispatch({
170
- effects: state.StateEffect.reconfigure.of(e)
171
- });
172
- });
173
- vueDemi.watch(focus, (isFocus) => {
174
- context.emit("focus", isFocus);
175
- });
194
+ vueDemi.watch(
195
+ extensions,
196
+ (exts) => view$1.value.dispatch({
197
+ effects: state.StateEffect.reconfigure.of(exts)
198
+ })
199
+ );
200
+ vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
176
201
  vueDemi.onMounted(async () => {
177
202
  let value = doc.value;
178
203
  if (editor.value && editor.value.childNodes[0]) {
@@ -199,7 +224,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
199
224
  container: editor.value
200
225
  });
201
226
  });
202
- vueDemi.onUnmounted(() => view$1.value.destroy());
227
+ vueDemi.onUnmounted(() => {
228
+ view$1.value.destroy();
229
+ });
203
230
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
204
231
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
205
232
  const lineCount = () => view$1.value.state.doc.lines;
@@ -269,8 +296,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
269
296
  });
270
297
 
271
298
  const meta = {
272
- version: "1.0.3",
273
- date: "2022-10-11T23:57:24.765Z"
299
+ version: "1.1.0",
300
+ date: "2022-10-31T12:33:21.284Z"
274
301
  };
275
302
 
276
303
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
package/dist/index.umd.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.0.3
8
+ * @version 1.1.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
@@ -67,6 +67,10 @@
67
67
  type: Boolean,
68
68
  default: false
69
69
  },
70
+ placeholder: {
71
+ type: String,
72
+ default: void 0
73
+ },
70
74
  wrap: {
71
75
  type: Boolean,
72
76
  default: false
@@ -79,9 +83,9 @@
79
83
  type: Boolean,
80
84
  default: false
81
85
  },
82
- editable: {
86
+ disabled: {
83
87
  type: Boolean,
84
- default: true
88
+ default: false
85
89
  },
86
90
  extensions: {
87
91
  type: Array,
@@ -101,16 +105,33 @@
101
105
  type: Function,
102
106
  default: void 0
103
107
  },
104
- lintGutter: {
108
+ linterConfig: {
109
+ type: Object,
110
+ default: () => {
111
+ }
112
+ },
113
+ gutter: {
105
114
  type: Boolean,
106
115
  defalt: false
107
116
  },
117
+ gutterConfig: {
118
+ type: Object,
119
+ default: () => {
120
+ }
121
+ },
108
122
  tag: {
109
123
  type: String,
110
124
  default: "div"
111
125
  }
112
126
  },
113
- emits: ["update:modelValue", "update", "ready", "focus", "changed"],
127
+ emits: [
128
+ "update:modelValue",
129
+ "update",
130
+ "ready",
131
+ "focus",
132
+ "changed",
133
+ "diagnosticCount"
134
+ ],
114
135
  setup(props, context) {
115
136
  const editor = vueDemi.ref();
116
137
  const doc = vueDemi.ref(props.modelValue);
@@ -147,10 +168,11 @@
147
168
  props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
148
169
  props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
149
170
  state.EditorState.readOnly.of(props.readonly),
150
- view.EditorView.editable.of(props.editable),
151
- props.lang ? vueDemi.toRaw(props.lang) : void 0,
152
- props.linter ? lint.linter(props.linter) : void 0,
153
- props.linter && props.lintGutter ? lint.lintGutter() : void 0,
171
+ view.EditorView.editable.of(!props.disabled),
172
+ props.lang ? props.lang : void 0,
173
+ props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
174
+ props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
175
+ props.placeholder ? view.placeholder(props.placeholder) : void 0,
154
176
  ...props.extensions
155
177
  ])
156
178
  );
@@ -160,22 +182,25 @@
160
182
  if (!view$1.value || view$1.value.composing) {
161
183
  return;
162
184
  }
163
- const previous = view$1.value.state.selection;
185
+ const current = view$1.value.state;
186
+ if (props.linter) {
187
+ context.emit("diagnosticCount", lint.diagnosticCount(current));
188
+ }
164
189
  view$1.value.dispatch({
165
- changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
166
- selection: previous
190
+ changes: { from: 0, to: current.doc.length, insert: value },
191
+ selection: current.selection,
192
+ scrollIntoView: true
167
193
  });
168
194
  },
169
195
  { immediate: true }
170
196
  );
171
- vueDemi.watch(extensions, (e) => {
172
- view$1.value.dispatch({
173
- effects: state.StateEffect.reconfigure.of(e)
174
- });
175
- });
176
- vueDemi.watch(focus, (isFocus) => {
177
- context.emit("focus", isFocus);
178
- });
197
+ vueDemi.watch(
198
+ extensions,
199
+ (exts) => view$1.value.dispatch({
200
+ effects: state.StateEffect.reconfigure.of(exts)
201
+ })
202
+ );
203
+ vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
179
204
  vueDemi.onMounted(async () => {
180
205
  let value = doc.value;
181
206
  if (editor.value && editor.value.childNodes[0]) {
@@ -202,7 +227,9 @@
202
227
  container: editor.value
203
228
  });
204
229
  });
205
- vueDemi.onUnmounted(() => view$1.value.destroy());
230
+ vueDemi.onUnmounted(() => {
231
+ view$1.value.destroy();
232
+ });
206
233
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
207
234
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
208
235
  const lineCount = () => view$1.value.state.doc.lines;
@@ -272,8 +299,8 @@
272
299
  });
273
300
 
274
301
  const meta = {
275
- version: "1.0.3",
276
- date: "2022-10-11T23:57:24.765Z"
302
+ version: "1.1.0",
303
+ date: "2022-10-31T12:33:21.284Z"
277
304
  };
278
305
 
279
306
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
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": "1.0.3",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -44,6 +44,7 @@
44
44
  }
45
45
  },
46
46
  "files": [
47
+ "CHANGELOG.md",
47
48
  "/dist",
48
49
  "./src/components/CodeMirror.ts"
49
50
  ],
@@ -51,7 +52,7 @@
51
52
  "./sfc": "./src/components/CodeMirror.ts"
52
53
  },
53
54
  "engines": {
54
- "node": ">=16.17.1",
55
+ "node": ">=16.18.0",
55
56
  "yarn": ">=1.22.10"
56
57
  },
57
58
  "packageManager": "yarn@3.2.4",
@@ -66,7 +67,8 @@
66
67
  "lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
67
68
  "lint:markup": "vue-tsc --noEmit",
68
69
  "preview": "vite preview --config vite.config.docs.ts",
69
- "prepare": "husky install"
70
+ "prepare": "husky install",
71
+ "version": "auto-changelog -p && git add CHANGELOG.md"
70
72
  },
71
73
  "dependencies": {
72
74
  "vue-demi": "latest"
@@ -82,42 +84,44 @@
82
84
  }
83
85
  },
84
86
  "devDependencies": {
85
- "@codemirror/lang-javascript": "^6.1.0",
86
- "@codemirror/lang-markdown": "^6.0.2",
87
+ "@codemirror/lang-javascript": "^6.1.1",
88
+ "@codemirror/lang-json": "^6.0.1",
89
+ "@codemirror/lang-markdown": "6.0.2",
87
90
  "@types/lodash": "^4.14.186",
88
- "@types/node": "^18.8.4",
89
- "@typescript-eslint/eslint-plugin": "^5.40.0",
90
- "@typescript-eslint/parser": "^5.40.0",
91
- "@vitejs/plugin-vue": "^3.1.2",
91
+ "@types/node": "^18.11.8",
92
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
93
+ "@typescript-eslint/parser": "^5.41.0",
94
+ "@vitejs/plugin-vue": "^3.2.0",
92
95
  "@vue/eslint-config-prettier": "^7.0.0",
93
96
  "@vue/tsconfig": "^0.1.3",
94
97
  "codemirror": "^6.0.1",
95
- "eslint": "^8.25.0",
98
+ "eslint": "^8.26.0",
96
99
  "eslint-config-google": "^0.14.0",
97
100
  "eslint-config-prettier": "^8.5.0",
98
101
  "eslint-import-resolver-alias": "^1.1.2",
99
- "eslint-import-resolver-typescript": "^3.5.1",
100
- "eslint-linter-browserify": "^8.25.0",
102
+ "eslint-import-resolver-typescript": "^3.5.2",
103
+ "eslint-linter-browserify": "^8.26.0",
101
104
  "eslint-plugin-html": "^7.1.0",
102
105
  "eslint-plugin-import": "^2.26.0",
103
- "eslint-plugin-jsdoc": "^39.3.6",
106
+ "eslint-plugin-jsdoc": "^39.4.0",
104
107
  "eslint-plugin-tsdoc": "^0.2.17",
105
- "eslint-plugin-vue": "^9.6.0",
106
- "eslint-plugin-vuejs-accessibility": "^1.2.0",
108
+ "eslint-plugin-vue": "^9.7.0",
109
+ "eslint-plugin-vuejs-accessibility": "^2.0.0",
107
110
  "eslint-plugin-yaml": "^0.5.0",
108
111
  "husky": "^8.0.1",
109
112
  "lint-staged": "^13.0.3",
110
113
  "lodash": "^4.17.21",
114
+ "markdown-wasm": "^1.2.0",
111
115
  "prettier": "^2.7.1",
112
116
  "rimraf": "^3.0.2",
113
- "rollup-plugin-visualizer": "^5.8.2",
117
+ "rollup-plugin-visualizer": "^5.8.3",
114
118
  "typescript": "^4.8.4",
115
- "vite": "^3.1.7",
116
- "vite-plugin-banner": "^0.5.0",
119
+ "vite": "^3.2.2",
120
+ "vite-plugin-banner": "^0.6.1",
117
121
  "vite-plugin-checker": "^0.5.1",
118
- "vue": "^3.2.40",
122
+ "vue": "^3.2.41",
119
123
  "vue-eslint-parser": "^9.1.0",
120
- "vue-tsc": "^1.0.5"
124
+ "vue-tsc": "^1.0.9"
121
125
  },
122
126
  "husky": {
123
127
  "hooks": {