nuxt-codemirror 0.0.1 → 0.0.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.
package/README.md CHANGED
@@ -22,12 +22,19 @@ Codemirror as a Nuxt module. Demo preview: Coming soon
22
22
  - 🌲 Custom useNuxtCodeMirror composable for creating your own editor
23
23
  - Built for CodeMirror 6 and above
24
24
 
25
+ ## Credits
26
+
27
+ This Nuxt module wouldn't be possible without:
28
+
29
+ - @uiw/react-codemirror: https://github.com/uiwjs/react-codemirror
30
+ - @surmon-china/vue-codemirror: https://github.com/surmon-china/vue-codemirror
31
+
25
32
  ## Quick Setup
26
33
 
27
34
  Install the module to your Nuxt application with one command:
28
35
 
29
36
  ```bash
30
- npx nuxi module add thimodev/nuxt-codemirror
37
+ npx nuxi module add nuxt-codemirror
31
38
  ```
32
39
 
33
40
  That's it! You can now use Nuxt-codemirror in your Nuxt app ✨
@@ -65,14 +72,14 @@ That's it! You can now use Nuxt-codemirror in your Nuxt app ✨
65
72
 
66
73
 
67
74
  <!-- Badges -->
68
- [npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
69
- [npm-version-href]: https://npmjs.com/package/my-module
75
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-codemirror/latest.svg?style=flat&colorA=020420&colorB=00DC82
76
+ [npm-version-href]: https://npmjs.com/package/nuxt-codemirror
70
77
 
71
- [npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
72
- [npm-downloads-href]: https://npmjs.com/package/my-module
78
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-codemirror.svg?style=flat&colorA=020420&colorB=00DC82
79
+ [npm-downloads-href]: https://npmjs.com/package/nuxt-codemirror
73
80
 
74
- [license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
75
- [license-href]: https://npmjs.com/package/my-module
81
+ [license-src]: https://img.shields.io/npm/l/nuxt-codemirror.svg?style=flat&colorA=020420&colorB=00DC82
82
+ [license-href]: https://npmjs.com/package/nuxt-codemirror
76
83
 
77
84
  [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
78
85
  [nuxt-href]: https://nuxt.com
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-codemirror",
3
3
  "configKey": "nuxtCodemirror",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.1",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -19,9 +19,14 @@ const module = defineNuxtModule({
19
19
  from: resolve("./runtime/composables/useNuxtCodeMirror.ts")
20
20
  });
21
21
  addTypeTemplate({
22
- filename: "../runtime/types/nuxt-codemirror.d.ts",
22
+ filename: "nuxt-codemirror.d.ts",
23
23
  src: resolve("./runtime/types/nuxt-codemirror.d.ts")
24
24
  });
25
+ _nuxt.hook("vite:extendConfig", (config) => {
26
+ config.resolve = config.resolve || {};
27
+ config.resolve.alias = config.resolve.alias || {};
28
+ config.resolve.alias["@codemirror/state"] = resolve(_nuxt.options.rootDir, "node_modules/@codemirror/state");
29
+ });
25
30
  }
26
31
  });
27
32
 
@@ -1,8 +1,2 @@
1
- import { EditorState } from '@codemirror/state';
2
- import { EditorView } from '@codemirror/view';
3
1
  import { type UseCodeMirrorProps } from '../types/nuxt-codemirror.js';
4
- export declare function useNuxtCodeMirror(props: UseCodeMirrorProps): {
5
- containerRef: import("#imports").Ref<HTMLDivElement | null>;
6
- viewRef: import("#imports").Ref<EditorView | undefined>;
7
- stateRef: import("#imports").Ref<EditorState | undefined>;
8
- };
2
+ export declare function useNuxtCodeMirror(props: UseCodeMirrorProps): void;
@@ -2,12 +2,12 @@ import { Annotation, EditorState, StateEffect } from "@codemirror/state";
2
2
  import { EditorView } from "@codemirror/view";
3
3
  import { getDefaultExtensions } from "../getDefaultExtensions.js";
4
4
  import { getStatistics } from "../utils/utils.js";
5
- import { onBeforeUnmount, watch, watchEffect } from "#imports";
5
+ import { onUnmounted, watch, watchEffect } from "#imports";
6
6
  const External = Annotation.define();
7
7
  const emptyExtensions = [];
8
8
  export function useNuxtCodeMirror(props) {
9
9
  const {
10
- // modelValue = '',
10
+ modelValue: value = "",
11
11
  selection,
12
12
  onChange,
13
13
  onStatistics,
@@ -51,8 +51,8 @@ export function useNuxtCodeMirror(props) {
51
51
  const updateListener = EditorView.updateListener.of((viewUpdate) => {
52
52
  if (viewUpdate.docChanged && typeof onChange === "function" && !viewUpdate.transactions.some((tr) => tr.annotation(External))) {
53
53
  const doc = viewUpdate.state.doc;
54
- const value = doc.toString();
55
- onChange(value, viewUpdate);
54
+ const value2 = doc.toString();
55
+ onChange(value2, viewUpdate);
56
56
  }
57
57
  if (viewUpdate.focusChanged) {
58
58
  viewUpdate.view.hasFocus ? onFocus && onFocus(viewUpdate) : onBlur && onBlur(viewUpdate);
@@ -75,7 +75,7 @@ export function useNuxtCodeMirror(props) {
75
75
  watchEffect(() => {
76
76
  if (containerRef.value && !stateRef?.value) {
77
77
  const config = {
78
- doc: props.modelValue,
78
+ doc: value,
79
79
  selection,
80
80
  extensions: getExtensions
81
81
  };
@@ -126,13 +126,13 @@ export function useNuxtCodeMirror(props) {
126
126
  { immediate: true }
127
127
  );
128
128
  watchEffect(() => {
129
- if (props.modelValue === void 0) {
129
+ if (value === void 0) {
130
130
  return;
131
131
  }
132
132
  const currentValue = viewRef.value ? viewRef.value.state.doc.toString() : "";
133
- if (viewRef.value && props.modelValue !== currentValue) {
133
+ if (viewRef.value && value !== currentValue) {
134
134
  viewRef.value.dispatch({
135
- changes: { from: 0, to: currentValue.length, insert: props.modelValue || "" },
135
+ changes: { from: 0, to: currentValue.length, insert: value || "" },
136
136
  annotations: [External.of(true)]
137
137
  });
138
138
  }
@@ -146,15 +146,10 @@ export function useNuxtCodeMirror(props) {
146
146
  },
147
147
  { immediate: true }
148
148
  );
149
- onBeforeUnmount(() => {
149
+ onUnmounted(() => {
150
150
  if (viewRef) {
151
151
  viewRef.value?.destroy();
152
152
  viewRef.value = void 0;
153
153
  }
154
154
  });
155
- return {
156
- containerRef,
157
- viewRef,
158
- stateRef
159
- };
160
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-codemirror",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Nuxt codemirror module",
5
5
  "repository": "https://github.com/ThimoDEV/nuxt-codemirror",
6
6
  "license": "MIT",
@@ -30,7 +30,6 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@codemirror/commands": "^6.6.0",
33
- "@codemirror/lang-javascript": "^6.2.2",
34
33
  "@codemirror/state": "6.4.1",
35
34
  "@codemirror/theme-one-dark": "^6.1.1",
36
35
  "@codemirror/view": "6.28.1",
@@ -51,4 +50,4 @@
51
50
  "vitest": "^2.0.3",
52
51
  "vue-tsc": "^2.0.26"
53
52
  }
54
- }
53
+ }
@@ -1,2 +0,0 @@
1
- declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
- export default _default;
@@ -1,4 +0,0 @@
1
- import { defineNuxtPlugin } from "#app";
2
- export default defineNuxtPlugin((_nuxtApp) => {
3
- console.log("Plugin injected by my-module!");
4
- });