nuxt-codemirror 0.0.9 → 0.0.11

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/README.md CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  # Nuxt CodeMirror
4
2
 
5
3
  [![npm version][npm-version-src]][npm-version-href]
@@ -7,7 +5,7 @@
7
5
  [![License][license-src]][license-href]
8
6
  [![Nuxt][nuxt-src]][nuxt-href]
9
7
 
10
- Codemirror as a Nuxt module. Demo preview: Coming soon
8
+ Codemirror as a Nuxt module. Demo can be found in below playground
11
9
 
12
10
 
13
11
  - [✨  Release Notes](/CHANGELOG.md)
@@ -24,18 +22,19 @@ Codemirror as a Nuxt module. Demo preview: Coming soon
24
22
 
25
23
  ## Documentation
26
24
 
27
- This module consists of one Component, one Composable and a few types for you to use.
25
+ This module consists of one Component, one Composable and a few types for you to use.
28
26
  Read the CodeMirror Reference guide for more in depth information: [CodeMirror docs](https://codemirror.net/docs/ref/)
29
27
 
30
28
  ### NuxtCodeMirror.vue
31
29
  This component is auto imported and is the CodeMirror wrapper.
32
30
 
33
31
  Component props:
34
- ```
32
+
33
+ ```ts
35
34
  interface NuxtCodeMirrorProps
36
35
  extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
37
36
  /** value of the auto created model in the editor. Works as underlying logic of a V-Model */
38
- modelValue?: string This is linked to a Vue V-Model
37
+ modelValue?: string
39
38
  /** The height value of the editor. */
40
39
  height?: string
41
40
  /** The minimum height value of the editor. */
@@ -116,7 +115,7 @@ interface NuxtCodeMirrorProps
116
115
 
117
116
  The NuxtCodeMirror component accepts a Template ref and exposes The CodeMirror div element, the Editor view and the Editor State
118
117
 
119
- ```
118
+ ```ts
120
119
  interface CodeMirrorRef {
121
120
  /** Container element of the CodeMirror instance */
122
121
  container: HTMLDivElement | null
@@ -129,33 +128,27 @@ interface CodeMirrorRef {
129
128
  }
130
129
  ```
131
130
 
132
- If you need access to the underlying CodeMirror instance You can do so by adding a ref with the same name as your Template ref.
131
+ If you need access to the underlying CodeMirror instance You can do so by adding a ref with the same name as your Template ref.
133
132
  An example on how to do this can be found here: [🏀 Online playground](https://stackblitz.com/edit/nuxt-starter-ev2hgm?file=app.vue)
134
133
 
135
134
 
136
135
  If for some reason you want to write your own CodeMirror component then you can do that too :)
137
136
 
138
137
  ### UseNuxtCodeMirror.ts
138
+
139
139
  This composable is the underlying magic of the NuxtCodeMirror component and is also auto imported.
140
140
 
141
141
  It requires minimum 3 Refs, one for the div element CodeMirror will connect to, one for the CodeMirror view, and one for the CodeMirror state
142
142
 
143
- Make sure you execute the composable in onMounted otherwise you will get an eror because codemirror can't be linked to the DOM.
144
-
145
- ```
146
- /** The EditorView of the CodeMirror instance */
147
- viewRef: Ref<EditorView | undefined>
148
- /** The EditorState of the CodeMirror instance */
149
- stateRef: Ref<EditorState | undefined>
150
- /** Editor element of the CodeMirror instance */
151
- containerRef: Ref<HTMLDivElement | null>
143
+ Make sure you execute the composable in `onMounted` otherwise you will get an eror because codemirror can't be linked to the DOM.
152
144
 
145
+ ```ts
153
146
  const editor = ref<HTMLDivElement | null>(null)
154
147
  const container = ref<HTMLDivElement | null>(null)
155
148
  const view = ref<EditorView>()
156
149
  const state = ref<EditorState>()
157
150
 
158
- onMounted(() => {
151
+ onMounted(() => {
159
152
  useNuxtCodeMirror({
160
153
  ...props,
161
154
  container: editor.value,
package/dist/module.d.mts CHANGED
@@ -1,7 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
- interface ModuleOptions {
4
- }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
3
+ declare const _default: _nuxt_schema.NuxtModule<_nuxt_schema.ModuleOptions>;
6
4
 
7
- export { type ModuleOptions, _default as default };
5
+ export { _default as default };
package/dist/module.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
- interface ModuleOptions {
4
- }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
3
+ declare const _default: _nuxt_schema.NuxtModule<_nuxt_schema.ModuleOptions>;
6
4
 
7
- export { type ModuleOptions, _default as default };
5
+ export { _default as default };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-codemirror",
3
3
  "configKey": "nuxtCodemirror",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.1",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -6,7 +6,7 @@ const module = defineNuxtModule({
6
6
  configKey: "nuxtCodemirror"
7
7
  },
8
8
  // Default configuration options of the Nuxt module
9
- defaults: {},
9
+ // defaults: {},
10
10
  setup(_options, _nuxt) {
11
11
  const { resolve } = createResolver(import.meta.url);
12
12
  addComponent({
@@ -34,7 +34,7 @@ const emit = defineEmits<{
34
34
  onMounted(() => {
35
35
  useNuxtCodeMirror({
36
36
  ...props,
37
- modelValue: modelValue.value,
37
+ modelValue: modelValue,
38
38
  onChange: (value, viewUpdate) => {
39
39
  modelValue.value = value
40
40
  emit('onChange', value, viewUpdate)
@@ -1,2 +1,2 @@
1
- import { type UseCodeMirrorProps } from '../types/nuxt-codemirror.js';
1
+ import type { UseCodeMirrorProps } from '../types/nuxt-codemirror.js';
2
2
  export declare function useNuxtCodeMirror(props: UseCodeMirrorProps): void;
@@ -7,7 +7,7 @@ const External = Annotation.define();
7
7
  const emptyExtensions = [];
8
8
  export function useNuxtCodeMirror(props) {
9
9
  const {
10
- modelValue: value = "",
10
+ modelValue: value,
11
11
  selection,
12
12
  onChange,
13
13
  onStatistics,
@@ -54,10 +54,13 @@ export function useNuxtCodeMirror(props) {
54
54
  const value2 = doc.toString();
55
55
  onChange(value2, viewUpdate);
56
56
  }
57
- if (viewUpdate.focusChanged) {
58
- viewUpdate.view.hasFocus ? onFocus && onFocus(viewUpdate) : onBlur && onBlur(viewUpdate);
57
+ onStatistics?.(getStatistics(viewUpdate));
58
+ if (!viewUpdate.focusChanged) return;
59
+ if (viewUpdate.view.hasFocus) {
60
+ onFocus?.(viewUpdate);
61
+ } else {
62
+ onBlur?.(viewUpdate);
59
63
  }
60
- onStatistics && onStatistics(getStatistics(viewUpdate));
61
64
  });
62
65
  const defaultExtensions = getDefaultExtensions({
63
66
  theme,
@@ -75,7 +78,7 @@ export function useNuxtCodeMirror(props) {
75
78
  watchEffect(() => {
76
79
  if (containerRef.value && !stateRef?.value) {
77
80
  const config = {
78
- doc: value,
81
+ doc: value?.value,
79
82
  selection,
80
83
  extensions: getExtensions
81
84
  };
@@ -88,7 +91,7 @@ export function useNuxtCodeMirror(props) {
88
91
  root
89
92
  });
90
93
  viewRef.value = viewCurrent;
91
- onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
94
+ onCreateEditor?.(viewCurrent, stateCurrent);
92
95
  }
93
96
  }
94
97
  });
@@ -130,9 +133,9 @@ export function useNuxtCodeMirror(props) {
130
133
  return;
131
134
  }
132
135
  const currentValue = viewRef.value ? viewRef.value.state.doc.toString() : "";
133
- if (viewRef.value && value !== currentValue) {
136
+ if (viewRef.value && value.value !== currentValue) {
134
137
  viewRef.value.dispatch({
135
- changes: { from: 0, to: currentValue.length, insert: value || "" },
138
+ changes: { from: 0, to: currentValue.length, insert: value.value || "" },
136
139
  annotations: [External.of(true)]
137
140
  });
138
141
  }
@@ -1,4 +1,4 @@
1
- import { type Extension } from '@codemirror/state';
1
+ import type { Extension } from '@codemirror/state';
2
2
  import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
3
3
  export * from '@codemirror/theme-one-dark';
4
4
  export * from './theme/light.js';
@@ -1,12 +1,13 @@
1
1
  import type { EditorState, EditorStateConfig, Extension, StateField, EditorSelection, SelectionRange, Line } from '@codemirror/state'
2
2
  import type { EditorView, ViewUpdate } from '@codemirror/view'
3
3
  import type { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup'
4
+ import type { ModelRef } from 'vue'
4
5
  import type { Ref } from '#imports'
5
6
 
6
7
  export interface NuxtCodeMirrorProps
7
8
  extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
8
9
  /** value of the auto created model in the editor. Works as underlying logic of a V-Model */
9
- modelValue?: string
10
+ modelValue?: ModelRef<string | undefined, string>
10
11
  /** The height value of the editor. */
11
12
  height?: string
12
13
  /** The minimum height value of the editor. */
package/dist/types.d.mts CHANGED
@@ -1 +1,7 @@
1
- export { type ModuleOptions, default } from './module.js'
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.js'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1 +1,7 @@
1
- export { type ModuleOptions, default } from './module'
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-codemirror",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Nuxt codemirror module",
5
5
  "repository": "https://github.com/ThimoDEV/nuxt-codemirror",
6
6
  "license": "MIT",
@@ -37,13 +37,13 @@
37
37
  "@codemirror/commands": "^6.6.0",
38
38
  "@codemirror/state": "6.4.1",
39
39
  "@codemirror/theme-one-dark": "^6.1.1",
40
- "@codemirror/view": "6.29.1",
40
+ "@codemirror/view": "6.30.0",
41
41
  "@nuxt/kit": "^3.12.4",
42
42
  "@uiw/codemirror-extensions-basic-setup": "^4.23.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@nuxt/devtools": "^1.3.9",
46
- "@nuxt/eslint-config": "^0.3.13",
46
+ "@nuxt/eslint-config": "^0.5.0",
47
47
  "@nuxt/module-builder": "^0.8.1",
48
48
  "@nuxt/schema": "^3.12.4",
49
49
  "@nuxt/test-utils": "^3.13.1",
@@ -60,5 +60,5 @@
60
60
  "codemirror",
61
61
  "vue"
62
62
  ],
63
- "packageManager": "pnpm@9.6.0"
64
- }
63
+ "packageManager": "pnpm@9.7.0"
64
+ }