nuxt-codemirror 0.0.5 → 0.0.7
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/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addComponent, addImports, addTypeTemplate } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, addImports, addTypeTemplate, extendViteConfig } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
@@ -22,10 +22,11 @@ const module = defineNuxtModule({
|
|
|
22
22
|
filename: "nuxt-codemirror.d.ts",
|
|
23
23
|
src: resolve("./runtime/types/nuxt-codemirror.d.ts")
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
extendViteConfig((config) => {
|
|
26
26
|
config.resolve = config.resolve || {};
|
|
27
27
|
config.resolve.alias = config.resolve.alias || {};
|
|
28
28
|
config.resolve.alias["@codemirror/state"] = resolve(_nuxt.options.rootDir, "node_modules/@codemirror/state");
|
|
29
|
+
config.resolve.alias["@codemirror/view"] = resolve(_nuxt.options.rootDir, "node_modules/@codemirror/view");
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
});
|
|
@@ -3,7 +3,7 @@ import type { ViewUpdate, EditorView } from '@codemirror/view'
|
|
|
3
3
|
import type { EditorState } from '@codemirror/state'
|
|
4
4
|
import { useNuxtCodeMirror } from '../composables/useNuxtCodeMirror'
|
|
5
5
|
import type { NuxtCodeMirrorProps, Statistics } from '../types/nuxt-codemirror'
|
|
6
|
-
import { onMounted, ref, watch,
|
|
6
|
+
import { onMounted, ref, watch, computed, onBeforeUnmount } from '#imports'
|
|
7
7
|
|
|
8
8
|
const editor = ref<HTMLDivElement | null>(null)
|
|
9
9
|
const container = ref<HTMLDivElement | null>(null)
|
|
@@ -31,9 +31,7 @@ const emit = defineEmits<{
|
|
|
31
31
|
(event: 'onUpdate' | 'onFocus' | 'onBlur', update: ViewUpdate): void
|
|
32
32
|
}>()
|
|
33
33
|
|
|
34
|
-
onMounted(
|
|
35
|
-
await nextTick()
|
|
36
|
-
|
|
34
|
+
onMounted(() => {
|
|
37
35
|
useNuxtCodeMirror({
|
|
38
36
|
...props,
|
|
39
37
|
modelValue: modelValue.value,
|
|
@@ -57,6 +55,13 @@ onMounted(async () => {
|
|
|
57
55
|
// console.log('test: ', view.value)
|
|
58
56
|
})
|
|
59
57
|
|
|
58
|
+
onBeforeUnmount(() => {
|
|
59
|
+
if (view.value) {
|
|
60
|
+
view.value?.destroy()
|
|
61
|
+
view.value = undefined
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
60
65
|
watch(() => modelValue, (newValue) => {
|
|
61
66
|
if (typeof newValue !== 'string') {
|
|
62
67
|
console.error(`value must be typeof string but got ${typeof newValue}`)
|
|
@@ -2,7 +2,7 @@ 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 {
|
|
5
|
+
import { watch, watchEffect } from "#imports";
|
|
6
6
|
const External = Annotation.define();
|
|
7
7
|
const emptyExtensions = [];
|
|
8
8
|
export function useNuxtCodeMirror(props) {
|
|
@@ -146,10 +146,4 @@ export function useNuxtCodeMirror(props) {
|
|
|
146
146
|
},
|
|
147
147
|
{ immediate: true }
|
|
148
148
|
);
|
|
149
|
-
onUnmounted(() => {
|
|
150
|
-
if (viewRef) {
|
|
151
|
-
viewRef.value?.destroy();
|
|
152
|
-
viewRef.value = void 0;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
149
|
}
|
|
@@ -3,125 +3,126 @@ import type { EditorView, ViewUpdate } from '@codemirror/view'
|
|
|
3
3
|
import type { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup'
|
|
4
4
|
import type { Ref } from '#imports'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
|
|
6
|
+
export interface NuxtCodeMirrorProps
|
|
7
|
+
extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
|
|
9
8
|
/** value of the auto created model in the editor. */
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
9
|
+
modelValue?: string
|
|
10
|
+
height?: string
|
|
11
|
+
minHeight?: string
|
|
12
|
+
maxHeight?: string
|
|
13
|
+
width?: string
|
|
14
|
+
minWidth?: string
|
|
15
|
+
maxWidth?: string
|
|
16
|
+
/** focus on the editor. */
|
|
17
|
+
autoFocus?: boolean
|
|
18
|
+
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
|
|
19
|
+
placeholder?: string | HTMLElement
|
|
20
|
+
/**
|
|
21
|
+
* `light` / `dark` / `Extension` Defaults to `light`.
|
|
22
|
+
* @default light
|
|
23
|
+
*/
|
|
24
|
+
theme?: 'light' | 'dark' | 'none' | Extension
|
|
25
|
+
/**
|
|
26
|
+
* Whether to optional basicSetup by default
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
basicSetup?: boolean | BasicSetupOptions
|
|
30
|
+
/**
|
|
31
|
+
* This disables editing of the editor content by the user.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
editable?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* This disables editing of the editor content by the user.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
readOnly?: boolean
|
|
40
|
+
/**
|
|
41
|
+
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
|
|
42
|
+
* or behaves according to the browser's default behavior (`false`).
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
indentWithTab?: boolean
|
|
46
|
+
/** Fired whenever a change occurs to the document. */
|
|
47
|
+
onChange?(value: string, viewUpdate: ViewUpdate): void
|
|
48
|
+
/** Some data on the statistics editor. */
|
|
49
|
+
onStatistics?(data: Statistics): void
|
|
50
|
+
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
|
|
51
|
+
onUpdate?(viewUpdate: ViewUpdate): void
|
|
52
|
+
/** The first time the editor executes the event. */
|
|
53
|
+
onCreateEditor?(view: EditorView, state: EditorState): void
|
|
54
|
+
/** Fired whenever the editor is focused. */
|
|
55
|
+
onFocus?(view: ViewUpdate): void
|
|
56
|
+
/** Fired whenever the editor is blurred. */
|
|
57
|
+
onBlur?(view: ViewUpdate): void
|
|
58
|
+
/**
|
|
59
|
+
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
|
|
60
|
+
* They can either be built-in extension-providing objects,
|
|
61
|
+
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
|
|
62
|
+
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
|
|
63
|
+
*/
|
|
64
|
+
extensions?: Extension[]
|
|
65
|
+
/**
|
|
66
|
+
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
|
|
67
|
+
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
|
|
68
|
+
*/
|
|
69
|
+
root?: ShadowRoot | Document
|
|
70
|
+
/**
|
|
71
|
+
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
|
|
72
|
+
*/
|
|
73
|
+
initialState?: {
|
|
75
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
75
|
+
json: any
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
fields?: Record<string, StateField<any>>
|
|
80
78
|
}
|
|
79
|
+
}
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
export interface UseCodeMirrorProps extends NuxtCodeMirrorProps {
|
|
82
|
+
/** Container element of the CodeMirror instance */
|
|
83
|
+
container?: HTMLDivElement | null
|
|
84
|
+
viewRef: Ref<EditorView | undefined>
|
|
85
|
+
stateRef: Ref<EditorState | undefined>
|
|
86
|
+
containerRef: Ref<HTMLDivElement | null>
|
|
87
|
+
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
export interface Statistics {
|
|
90
90
|
/** total length of the document */
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface CodeMirrorRef {
|
|
120
|
-
container: HTMLDivElement | null
|
|
121
|
-
view: EditorView | undefined
|
|
122
|
-
state: EditorState | undefined
|
|
123
|
-
editor: HTMLDivElement | null
|
|
124
|
-
}
|
|
91
|
+
length: number
|
|
92
|
+
/** Get the number of lines in the editor. */
|
|
93
|
+
lineCount: number
|
|
94
|
+
/** Get the currently line description around the given position. */
|
|
95
|
+
line: Line
|
|
96
|
+
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
|
|
97
|
+
lineBreak: string
|
|
98
|
+
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
|
|
99
|
+
readOnly: boolean
|
|
100
|
+
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
|
|
101
|
+
tabSize: number
|
|
102
|
+
/** Cursor Position */
|
|
103
|
+
selection: EditorSelection
|
|
104
|
+
/** Make sure the selection only has one range. */
|
|
105
|
+
selectionAsSingle: SelectionRange
|
|
106
|
+
/** Retrieves a list of all current selections. */
|
|
107
|
+
ranges: readonly SelectionRange[]
|
|
108
|
+
/** Get the currently selected code. */
|
|
109
|
+
selectionCode: string
|
|
110
|
+
/**
|
|
111
|
+
* The length of the given array should be the same as the number of active selections.
|
|
112
|
+
* Replaces the content of the selections with the strings in the array.
|
|
113
|
+
*/
|
|
114
|
+
selections: string[]
|
|
115
|
+
/** Return true if any text is selected. */
|
|
116
|
+
selectedText: boolean
|
|
125
117
|
}
|
|
126
118
|
|
|
127
|
-
export
|
|
119
|
+
export interface CodeMirrorRef {
|
|
120
|
+
/** Container element of the CodeMirror instance */
|
|
121
|
+
container: HTMLDivElement | null
|
|
122
|
+
/** The EditorView of the CodeMirror instance */
|
|
123
|
+
view: EditorView | undefined
|
|
124
|
+
/** The EditorState of the CodeMirror instance */
|
|
125
|
+
state: EditorState | undefined
|
|
126
|
+
/** Editor element of the CodeMirror instance */
|
|
127
|
+
editor: HTMLDivElement | null
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-codemirror",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Nuxt codemirror module",
|
|
5
5
|
"repository": "https://github.com/ThimoDEV/nuxt-codemirror",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@codemirror/commands": "^6.6.0",
|
|
33
33
|
"@codemirror/state": "6.4.1",
|
|
34
34
|
"@codemirror/theme-one-dark": "^6.1.1",
|
|
35
|
-
"@codemirror/view": "6.
|
|
35
|
+
"@codemirror/view": "6.29.1",
|
|
36
36
|
"@nuxt/kit": "^3.12.4",
|
|
37
37
|
"@uiw/codemirror-extensions-basic-setup": "^4.23.0"
|
|
38
38
|
},
|