Skip to content

Commit 1caaa20

Browse files
committed
Changed implementation to generate *.d.ts with vite-plugin-dts.
Fixed a flaw in the monitoring method of the extensions property.
1 parent 8bbc7bc commit 1caaa20

File tree

8 files changed

+549
-180
lines changed

8 files changed

+549
-180
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ rules:
3535
no-unused-vars: warn
3636
require-jsdoc: warn
3737
valid-jsdoc: off
38+
import/default: off
3839
jsdoc/require-param-type: off
3940
jsdoc/require-param:
4041
- off

package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "vue-codemirror6",
4-
"version": "1.1.11",
4+
"version": "1.1.12",
55
"license": "MIT",
66
"description": "CodeMirror6 Component for vue2 and vue3.",
77
"keywords": [
@@ -36,12 +36,12 @@
3636
},
3737
"main": "dist/index.umd.js",
3838
"module": "dist/index.es.js",
39-
"types": "dist/index.d.ts",
39+
"types": "dist/src/index.d.ts",
4040
"exports": {
4141
".": {
4242
"import": "./dist/index.es.js",
4343
"require": "./dist/index.umd.js",
44-
"types": "./dist/index.d.ts"
44+
"types": "./dist/src/index.d.ts"
4545
}
4646
},
4747
"files": [
@@ -53,21 +53,20 @@
5353
"./sfc": "./src/components/CodeMirror.ts"
5454
},
5555
"engines": {
56-
"node": ">=18.14.1",
57-
"yarn": ">=1.22.10"
56+
"node": ">=18.15.0",
57+
"yarn": ">=1.22.19"
5858
},
5959
"packageManager": "[email protected]",
6060
"sideEffects": false,
6161
"scripts": {
6262
"dev": "vite",
6363
"clean": "rimraf node_modules/.vite",
6464
"type-check": "tsc --noEmit --composite false",
65-
"build": "run-p type-check build-only build-declaration",
65+
"build": "run-p type-check build-only",
6666
"build:analyze": "vite build --mode=analyze",
6767
"build:clean": "rimraf dist docs",
6868
"build:docs": "vite build --mode=docs",
6969
"build-only": "vite build",
70-
"build-declaration": "tsc -p tsconfig.app.json --composite false",
7170
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
7271
"preview": "vite preview --mode=docs",
7372
"prepare": "husky install",
@@ -93,22 +92,22 @@
9392
"@codemirror/lang-markdown": "^6.1.0",
9493
"@codemirror/lang-vue": "^0.1.1",
9594
"@types/lodash": "^4.14.191",
96-
"@types/node": "^18.14.1",
97-
"@typescript-eslint/eslint-plugin": "^5.53.0",
98-
"@typescript-eslint/parser": "^5.53.0",
95+
"@types/node": "^18.15.0",
96+
"@typescript-eslint/eslint-plugin": "^5.54.1",
97+
"@typescript-eslint/parser": "^5.54.1",
9998
"@vitejs/plugin-vue": "^4.0.0",
10099
"@vue/eslint-config-prettier": "^7.1.0",
101100
"@vue/tsconfig": "^0.1.3",
102101
"@vueuse/core": "^9.13.0",
103102
"eslint": "^8.35.0",
104103
"eslint-config-google": "^0.14.0",
105-
"eslint-config-prettier": "^8.6.0",
104+
"eslint-config-prettier": "^8.7.0",
106105
"eslint-import-resolver-alias": "^1.1.2",
107106
"eslint-import-resolver-typescript": "^3.5.3",
108-
"eslint-linter-browserify": "^8.34.0",
107+
"eslint-linter-browserify": "^8.35.0",
109108
"eslint-plugin-html": "^7.1.0",
110109
"eslint-plugin-import": "^2.27.5",
111-
"eslint-plugin-jsdoc": "^40.0.0",
110+
"eslint-plugin-jsdoc": "^40.0.1",
112111
"eslint-plugin-prettier": "^4.2.1",
113112
"eslint-plugin-tsdoc": "^0.2.17",
114113
"eslint-plugin-vue": "^9.9.0",
@@ -118,17 +117,17 @@
118117
"lint-staged": "^13.1.2",
119118
"npm-run-all": "^4.1.5",
120119
"prettier": "^2.8.4",
121-
"rimraf": "^4.1.2",
120+
"rimraf": "^4.4.0",
122121
"rollup-plugin-visualizer": "^5.9.0",
123122
"sass": "^1.58.3",
124-
"sass-loader": "^13.2.0",
125123
"typescript": "^4.9.5",
126124
"vite": "^4.1.4",
127125
"vite-plugin-banner": "^0.7.0",
128126
"vite-plugin-checker": "^0.5.6",
129-
"vue": "3.2.47",
127+
"vite-plugin-dts": "^2.1.0",
128+
"vue": "^3.2.47",
130129
"vue-eslint-parser": "^9.1.0",
131-
"vue-markdown-wasm": "^0.3.2",
130+
"vue-markdown-wasm": "^0.3.6",
132131
"vue-tsc": "^1.2.0"
133132
},
134133
"husky": {

src-docs/components/MarkdownDemo.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ defineProps({ dark: Boolean });
2020
<template>
2121
<div class="row">
2222
<div class="col-6">
23-
<code-mirror
24-
v-model="input"
25-
:dark="dark"
26-
:lang="markdown()"
27-
wrap
28-
basic
29-
@ready="onReady"
30-
/>
23+
<code-mirror v-model="input" :dark="dark" :lang="markdown()" wrap basic />
3124
</div>
3225
<div class="col-6">
3326
<vue-markdown v-model="input" class="markdown-body" />

src/components/CodeMirror.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
6767
(e: 'destroy'): void;
6868
/** State Changed */
6969
(e: 'change', value: EditorState): void;
70+
/** Diagnostic Count */
71+
(e: 'diagnosticCount'): number;
7072
}
7173

7274
/** CodeMirror Component */
@@ -230,7 +232,16 @@ export default defineComponent({
230232
*/
231233
linterConfig: {
232234
type: Object,
233-
default: () => {},
235+
default: () => undefined,
236+
},
237+
/**
238+
* Forces any linters configured to run when the editor is idle to run right away.
239+
*
240+
* @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
241+
*/
242+
forceLinting: {
243+
type: Boolean,
244+
default: false,
234245
},
235246
/**
236247
* Show Linter Gutter
@@ -251,7 +262,7 @@ export default defineComponent({
251262
*/
252263
gutterConfig: {
253264
type: Object,
254-
default: () => {},
265+
default: () => undefined,
255266
},
256267
/**
257268
* Using tag
@@ -269,6 +280,7 @@ export default defineComponent({
269280
* @param props - Props
270281
* @param context - Context
271282
*/
283+
// @ts-ignore
272284
setup(props, context: SetupContext<CodeMirrorEmitsOptions>) {
273285
/** Editor DOM */
274286
const editor: Ref<HTMLElement | undefined> = ref();
@@ -382,6 +394,11 @@ export default defineComponent({
382394
return;
383395
}
384396

397+
// Enable Force Linting
398+
if (props.linter && props.forceLinting) {
399+
forceLinting(view.value);
400+
}
401+
385402
// Update
386403
view.value.dispatch({
387404
changes: { from: 0, to: view.value.state.doc.length, insert: value },
@@ -393,11 +410,13 @@ export default defineComponent({
393410
);
394411

395412
// Extension (mostly props) Changed
396-
watch(extensions, exts =>
397-
// TODO: Reduce unchanched value
398-
view.value.dispatch({
399-
effects: StateEffect.reconfigure.of(exts),
400-
})
413+
watch(
414+
() => extensions.value,
415+
exts => {
416+
view.value.dispatch({
417+
effects: StateEffect.reconfigure.of(exts),
418+
});
419+
}
401420
);
402421

403422
// focus changed
@@ -433,6 +452,7 @@ export default defineComponent({
433452
context.emit('change', view.value.state);
434453
},
435454
});
455+
436456
await nextTick();
437457
context.emit('ready', {
438458
view: view,
@@ -620,16 +640,19 @@ export default defineComponent({
620640
// </div>
621641
// </template>
622642
return h(
643+
// @ts-ignore
623644
this.$props.tag,
624645
{
625646
ref: 'editor',
626647
class: 'vue-codemirror',
627648
},
649+
// @ts-ignore
628650
this.$slots.default
629651
? // Hide original content
630652
h(
631653
'aside',
632654
{ style: 'display: none;', 'aria-hidden': 'true' },
655+
// @ts-ignore
633656
slot(this.$slots.default)
634657
)
635658
: undefined

src/helpers/h-demi.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
* @see {@link https://github.com/vueuse/vue-demi/issues/65}
55
*/
66

7-
import { h as hDemi, isVue2, type VNode, Vue2 } from 'vue-demi';
7+
import {
8+
h as hDemi,
9+
isVue2,
10+
type Slots,
11+
type VNode,
12+
type VNodeProps,
13+
} from 'vue-demi';
814

9-
interface Options {
15+
interface Options extends VNodeProps {
1016
class?: string;
1117
domProps?: Record<any, any>;
1218
on?: Record<any, any>;
1319
props?: Record<any, any>;
14-
ref?: string;
1520
style?: string;
1621
'aria-hidden'?: string;
1722
}
@@ -25,12 +30,15 @@ const adaptOnsV3 = (ons: Object) => {
2530
}, {});
2631
};
2732

28-
const h = (
33+
/**
34+
* hDemi function.
35+
*/
36+
function h(
2937
type: string | Record<any, any>,
3038
options: Options = {},
3139
chidren?: any
32-
): VNode => {
33-
if (isVue2 && parseInt(Vue2.version) < 2.7) {
40+
): VNode {
41+
if (isVue2) {
3442
// Makeshift support :(
3543
// Since Vue2.7 includes the Composition API, the functions in vue-demi are not used.
3644
return hDemi(type, options, chidren);
@@ -43,9 +51,9 @@ const h = (
4351
{ ...extraOptions, ...props, ...domProps, ...ons },
4452
chidren
4553
);
46-
};
54+
}
4755

48-
const slot = (defaultSlots: any) =>
56+
const slot = (defaultSlots: any): Slots =>
4957
typeof defaultSlots == 'function' ? defaultSlots() : defaultSlots;
5058

5159
export { slot, h as default };

tsconfig.app.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"composite": true,
88
"baseUrl": ".",
99
"esModuleInterop": true,
10-
"declaration": true,
11-
"declarationDir": "./dist",
12-
"outDir": "./dist",
1310
"paths": {
1411
"@/*": ["./src/*"]
1512
},

vite.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { checker } from 'vite-plugin-checker';
22
import { defineConfig, type UserConfig } from 'vite';
33
import { visualizer } from 'rollup-plugin-visualizer';
44
import banner from 'vite-plugin-banner';
5+
import dts from 'vite-plugin-dts';
56
import Vue from '@vitejs/plugin-vue';
67

78
import { fileURLToPath, URL } from 'node:url';
@@ -54,6 +55,13 @@ export default defineConfig(async ({ mode, command }): Promise<UserConfig> => {
5455
* @see {@link ${pkg.homepage}}
5556
*/
5657
`),
58+
// vite-plugin-dts
59+
// https://github.com/qmhc/vite-plugin-dts
60+
mode === 'docs'
61+
? undefined
62+
: dts({
63+
tsConfigFilePath: './tsconfig.app.json',
64+
}),
5765
],
5866
optimizeDeps: {
5967
exclude: [

0 commit comments

Comments
 (0)