vue-codemirror6 1.1.10 → 1.1.12

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.
@@ -5,7 +5,7 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.10
8
+ * @version 1.1.12
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
@@ -21,8 +21,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
21
21
  return { ...ret, [key]: handler };
22
22
  }, {});
23
23
  };
24
- const h = (type, options = {}, chidren) => {
25
- if (vueDemi.isVue2 && parseInt(vueDemi.Vue2.version) < 2.7) {
24
+ function h(type, options = {}, chidren) {
25
+ if (vueDemi.isVue2) {
26
26
  return vueDemi.h(type, options, chidren);
27
27
  }
28
28
  const { props, domProps, on, ...extraOptions } = options;
@@ -32,103 +32,219 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
32
32
  { ...extraOptions, ...props, ...domProps, ...ons },
33
33
  chidren
34
34
  );
35
- };
35
+ }
36
36
  const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
37
37
 
38
38
  var CodeMirror = vueDemi.defineComponent({
39
+ /** Component Name */
39
40
  name: "CodeMirror",
41
+ /** Model Definition */
40
42
  model: {
41
43
  prop: "modelValue",
42
44
  event: "update:modelValue"
43
45
  },
46
+ /** Props Definition */
44
47
  props: {
48
+ /** Model value */
45
49
  modelValue: {
46
50
  type: String,
47
51
  default: ""
48
52
  },
53
+ /**
54
+ * Theme
55
+ *
56
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
57
+ */
49
58
  theme: {
50
59
  type: Object,
51
60
  default: () => {
52
61
  }
53
62
  },
63
+ /** Dark Mode */
54
64
  dark: {
55
65
  type: Boolean,
56
66
  default: false
57
67
  },
68
+ /**
69
+ * Use Basic Setup
70
+ *
71
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
72
+ */
58
73
  basic: {
59
74
  type: Boolean,
60
75
  default: false
61
76
  },
77
+ /**
78
+ * Use Minimal Setup (The basic setting has priority.)
79
+ *
80
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
81
+ */
62
82
  minimal: {
63
83
  type: Boolean,
64
84
  default: false
65
85
  },
86
+ /**
87
+ * Placeholder
88
+ *
89
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
90
+ */
66
91
  placeholder: {
67
92
  type: String,
68
93
  default: void 0
69
94
  },
95
+ /**
96
+ * Line wrapping
97
+ *
98
+ * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
99
+ *
100
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
101
+ */
70
102
  wrap: {
71
103
  type: Boolean,
72
104
  default: false
73
105
  },
106
+ /**
107
+ * Allow tab key indent.
108
+ *
109
+ * @see {@link https://codemirror.net/examples/tab/}
110
+ */
74
111
  tab: {
75
112
  type: Boolean,
76
113
  default: false
77
114
  },
115
+ /**
116
+ * Tab size
117
+ *
118
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
119
+ */
78
120
  tabSize: {
79
121
  type: Number,
80
122
  default: void 0
81
123
  },
124
+ /**
125
+ * Set line break (separetor) char.
126
+ *
127
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
128
+ */
82
129
  lineSeparator: {
83
130
  type: String,
84
131
  default: void 0
85
132
  },
133
+ /**
134
+ * Readonly
135
+ *
136
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
137
+ */
86
138
  readonly: {
87
139
  type: Boolean,
88
140
  default: false
89
141
  },
142
+ /**
143
+ * Disable input.
144
+ *
145
+ * This is the reversed value of the CodeMirror editable.
146
+ * Similar to `readonly`, but setting this value to true disables dragging.
147
+ *
148
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
149
+ */
90
150
  disabled: {
91
151
  type: Boolean,
92
152
  default: false
93
153
  },
154
+ /**
155
+ * Additional Extension
156
+ *
157
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
158
+ */
94
159
  extensions: {
95
160
  type: Array,
96
161
  default: () => {
97
162
  return [];
98
163
  }
99
164
  },
165
+ /**
166
+ * Language Phreses
167
+ *
168
+ * @see {@link https://codemirror.net/examples/translate/}
169
+ */
100
170
  phrases: {
101
171
  type: Object,
102
172
  default: () => void 0
103
173
  },
174
+ /**
175
+ * CodeMirror Language
176
+ *
177
+ * @see {@link https://codemirror.net/docs/ref/#language}
178
+ */
104
179
  lang: {
105
180
  type: Object,
106
181
  default: () => void 0
107
182
  },
183
+ /**
184
+ * CodeMirror Linter
185
+ *
186
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
187
+ */
108
188
  linter: {
109
189
  type: Function,
110
190
  default: void 0
111
191
  },
192
+ /**
193
+ * Linter Config
194
+ *
195
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
196
+ */
112
197
  linterConfig: {
113
198
  type: Object,
114
- default: () => {
115
- }
199
+ default: () => void 0
200
+ },
201
+ /**
202
+ * Forces any linters configured to run when the editor is idle to run right away.
203
+ *
204
+ * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
205
+ */
206
+ forceLinting: {
207
+ type: Boolean,
208
+ default: false
116
209
  },
210
+ /**
211
+ * Show Linter Gutter
212
+ *
213
+ * An area to 🔴 the lines with errors will be displayed.
214
+ * This feature is not enabled if `linter` is not specified.
215
+ *
216
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
217
+ */
117
218
  gutter: {
118
219
  type: Boolean,
119
220
  defalt: false
120
221
  },
222
+ /**
223
+ * Gutter Config
224
+ *
225
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
226
+ */
121
227
  gutterConfig: {
122
228
  type: Object,
123
- default: () => {
124
- }
229
+ default: () => void 0
125
230
  },
231
+ /**
232
+ * Using tag
233
+ */
126
234
  tag: {
127
235
  type: String,
128
236
  default: "div"
129
237
  }
130
238
  },
239
+ /** Emits */
131
240
  emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
241
+ /**
242
+ * Setup
243
+ *
244
+ * @param props - Props
245
+ * @param context - Context
246
+ */
247
+ // @ts-ignore
132
248
  setup(props, context) {
133
249
  const editor = vueDemi.ref();
134
250
  const doc = vueDemi.ref(props.modelValue);
@@ -157,26 +273,45 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
157
273
  () => view$1.value.state.doc.length
158
274
  );
159
275
  const extensions = vueDemi.computed(
160
- () => lodash.compact([
161
- props.basic ? codemirror.basicSetup : void 0,
162
- props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
163
- view.EditorView.updateListener.of(
164
- (update) => context.emit("update", update)
165
- ),
166
- view.EditorView.theme(props.theme, { dark: props.dark }),
167
- props.wrap ? view.EditorView.lineWrapping : void 0,
168
- props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
169
- props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
170
- props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
171
- state.EditorState.readOnly.of(props.readonly),
172
- view.EditorView.editable.of(!props.disabled),
173
- props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
174
- props.lang ? props.lang : void 0,
175
- props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
176
- props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
177
- props.placeholder ? view.placeholder(props.placeholder) : void 0,
178
- ...props.extensions
179
- ])
276
+ () => (
277
+ // TODO: Ignore previous prop was not changed.
278
+ lodash.compact([
279
+ // Toggle basic setup
280
+ props.basic ? codemirror.basicSetup : void 0,
281
+ // Toggle minimal setup
282
+ props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
283
+ // ViewUpdate event listener
284
+ view.EditorView.updateListener.of(
285
+ (update) => context.emit("update", update)
286
+ ),
287
+ // Toggle light/dark mode.
288
+ view.EditorView.theme(props.theme, { dark: props.dark }),
289
+ // Toggle line wrapping
290
+ props.wrap ? view.EditorView.lineWrapping : void 0,
291
+ // Indent with tab
292
+ props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
293
+ // Indent tab size
294
+ props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
295
+ // locale settings
296
+ props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
297
+ // Readonly option
298
+ state.EditorState.readOnly.of(props.readonly),
299
+ // Editable option
300
+ view.EditorView.editable.of(!props.disabled),
301
+ // Set Line break char
302
+ props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
303
+ // Lang
304
+ props.lang ? props.lang : void 0,
305
+ // Append Linter settings
306
+ props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
307
+ // Show 🔴 to error line when linter enabled.
308
+ props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
309
+ // Placeholder
310
+ props.placeholder ? view.placeholder(props.placeholder) : void 0,
311
+ // Append Extensions (such as basic-setup)
312
+ ...props.extensions
313
+ ])
314
+ )
180
315
  );
181
316
  vueDemi.watch(
182
317
  () => props.modelValue,
@@ -184,6 +319,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
184
319
  if (view$1.value.composing) {
185
320
  return;
186
321
  }
322
+ if (props.linter && props.forceLinting) {
323
+ lint.forceLinting(view$1.value);
324
+ }
187
325
  view$1.value.dispatch({
188
326
  changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
189
327
  selection: view$1.value.state.selection,
@@ -193,10 +331,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
193
331
  { immediate: true }
194
332
  );
195
333
  vueDemi.watch(
196
- extensions,
197
- (exts) => view$1.value.dispatch({
198
- effects: state.StateEffect.reconfigure.of(exts)
199
- })
334
+ () => extensions.value,
335
+ (exts) => {
336
+ view$1.value.dispatch({
337
+ effects: state.StateEffect.reconfigure.of(exts)
338
+ });
339
+ }
200
340
  );
201
341
  vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
202
342
  vueDemi.onMounted(async () => {
@@ -286,6 +426,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
286
426
  length,
287
427
  lint: lint$1,
288
428
  forceReconfigure,
429
+ // Bellow is CodeMirror5's function
289
430
  getRange,
290
431
  getLine,
291
432
  lineCount,
@@ -307,23 +448,29 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
307
448
  },
308
449
  render() {
309
450
  return h(
451
+ // @ts-ignore
310
452
  this.$props.tag,
311
453
  {
312
454
  ref: "editor",
313
455
  class: "vue-codemirror"
314
456
  },
315
- this.$slots.default ? h(
316
- "aside",
317
- { style: "display: none;", "aria-hidden": "true" },
318
- slot(this.$slots.default)
457
+ // @ts-ignore
458
+ this.$slots.default ? (
459
+ // Hide original content
460
+ h(
461
+ "aside",
462
+ { style: "display: none;", "aria-hidden": "true" },
463
+ // @ts-ignore
464
+ slot(this.$slots.default)
465
+ )
319
466
  ) : void 0
320
467
  );
321
468
  }
322
469
  });
323
470
 
324
471
  const meta = {
325
- version: "1.1.10",
326
- date: "2023-01-29T01:57:06.994Z"
472
+ version: "1.1.12",
473
+ date: "2023-03-10T04:51:22.645Z"
327
474
  };
328
475
 
329
476
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);