Skip to content

Commit eda423d

Browse files
committed
chore: cleanup types and module config
1 parent d57157b commit eda423d

File tree

2 files changed

+111
-120
lines changed

2 files changed

+111
-120
lines changed

src/module.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineNuxtModule, addComponent, createResolver, addImports, addTypeTemplate } from '@nuxt/kit'
1+
import { defineNuxtModule, addComponent, createResolver, addImports } from '@nuxt/kit'
22

33
// Module options TypeScript interface definition
44
export interface ModuleOptions {}
@@ -24,11 +24,6 @@ export default defineNuxtModule<ModuleOptions>({
2424
from: resolve('./runtime/composables/useNuxtCodeMirror.ts'),
2525
})
2626

27-
addTypeTemplate({
28-
filename: 'nuxt-codemirror.d.ts',
29-
src: resolve('./runtime/types/nuxt-codemirror.d.ts'),
30-
})
31-
3227
_nuxt.hook('vite:extendConfig', (config) => {
3328
config.resolve = config.resolve || {}
3429
config.resolve.alias = config.resolve.alias || {}

src/runtime/types/nuxt-codemirror.d.ts

Lines changed: 110 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,125 +3,121 @@ import type { EditorView, ViewUpdate } from '@codemirror/view'
33
import type { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup'
44
import type { Ref } from '#imports'
55

6-
declare module 'nuxt-codemirror' {
7-
export interface NuxtCodeMirrorProps
8-
extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
6+
export interface NuxtCodeMirrorProps
7+
extends Omit<EditorStateConfig, 'doc' | 'extensions'> {
98
/** value of the auto created model in the editor. */
10-
modelValue?: string
11-
height?: string
12-
minHeight?: string
13-
maxHeight?: string
14-
width?: string
15-
minWidth?: string
16-
maxWidth?: string
17-
/** focus on the editor. */
18-
autoFocus?: boolean
19-
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
20-
placeholder?: string | HTMLElement
21-
/**
22-
* `light` / `dark` / `Extension` Defaults to `light`.
23-
* @default light
24-
*/
25-
theme?: 'light' | 'dark' | 'none' | Extension
26-
/**
27-
* Whether to optional basicSetup by default
28-
* @default true
29-
*/
30-
basicSetup?: boolean | BasicSetupOptions
31-
/**
32-
* This disables editing of the editor content by the user.
33-
* @default true
34-
*/
35-
editable?: boolean
36-
/**
37-
* This disables editing of the editor content by the user.
38-
* @default false
39-
*/
40-
readOnly?: boolean
41-
/**
42-
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
43-
* or behaves according to the browser's default behavior (`false`).
44-
* @default true
45-
*/
46-
indentWithTab?: boolean
47-
/** Fired whenever a change occurs to the document. */
48-
onChange?(value: string, viewUpdate: ViewUpdate): void
49-
/** Some data on the statistics editor. */
50-
onStatistics?(data: Statistics): void
51-
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
52-
onUpdate?(viewUpdate: ViewUpdate): void
53-
/** The first time the editor executes the event. */
54-
onCreateEditor?(view: EditorView, state: EditorState): void
55-
/** Fired whenever the editor is focused. */
56-
onFocus?(view: ViewUpdate): void
57-
/** Fired whenever the editor is blurred. */
58-
onBlur?(view: ViewUpdate): void
59-
/**
60-
* 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.
61-
* They can either be built-in extension-providing objects,
62-
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
63-
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
64-
*/
65-
extensions?: Extension[]
66-
/**
67-
* 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.
68-
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
69-
*/
70-
root?: ShadowRoot | Document
71-
/**
72-
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
73-
*/
74-
initialState?: {
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?: {
7574
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76-
json: any
77-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
78-
fields?: Record<string, StateField<any>>
79-
}
75+
json: any
76+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77+
fields?: Record<string, StateField<any>>
8078
}
79+
}
8180

82-
export interface UseCodeMirrorProps extends NuxtCodeMirrorProps {
83-
container?: HTMLDivElement | null
84-
viewRef: Ref<EditorView | undefined>
85-
stateRef: Ref<EditorState | undefined>
86-
containerRef: Ref<HTMLDivElement | null>
87-
}
81+
export interface UseCodeMirrorProps extends NuxtCodeMirrorProps {
82+
container?: HTMLDivElement | null
83+
viewRef: Ref<EditorView | undefined>
84+
stateRef: Ref<EditorState | undefined>
85+
containerRef: Ref<HTMLDivElement | null>
86+
}
8887

89-
export interface Statistics {
88+
export interface Statistics {
9089
/** total length of the document */
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
117-
}
118-
119-
export interface CodeMirrorRef {
120-
container: HTMLDivElement | null
121-
view: EditorView | undefined
122-
state: EditorState | undefined
123-
editor: HTMLDivElement | null
124-
}
90+
length: number
91+
/** Get the number of lines in the editor. */
92+
lineCount: number
93+
/** Get the currently line description around the given position. */
94+
line: Line
95+
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
96+
lineBreak: string
97+
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
98+
readOnly: boolean
99+
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
100+
tabSize: number
101+
/** Cursor Position */
102+
selection: EditorSelection
103+
/** Make sure the selection only has one range. */
104+
selectionAsSingle: SelectionRange
105+
/** Retrieves a list of all current selections. */
106+
ranges: readonly SelectionRange[]
107+
/** Get the currently selected code. */
108+
selectionCode: string
109+
/**
110+
* The length of the given array should be the same as the number of active selections.
111+
* Replaces the content of the selections with the strings in the array.
112+
*/
113+
selections: string[]
114+
/** Return true if any text is selected. */
115+
selectedText: boolean
125116
}
126117

127-
export type { Statistics, CodeMirrorRef, UseCodeMirrorProps, NuxtCodeMirrorProps } from 'nuxt-codemirror'
118+
export interface CodeMirrorRef {
119+
container: HTMLDivElement | null
120+
view: EditorView | undefined
121+
state: EditorState | undefined
122+
editor: HTMLDivElement | null
123+
}

0 commit comments

Comments
 (0)