Skip to content

Commit e0635ea

Browse files
committed
fix: added type definitions
1 parent 083c7a5 commit e0635ea

8 files changed

+164
-43
lines changed

dist/types/SearchInput.types.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export declare const fieldType: readonly ["search", "text"];
2+
export declare type FieldType = typeof fieldType[number];

dist/types/SearchInput.vue.d.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { PropType } from 'vue';
2+
import { FieldType } from './SearchInput.types';
3+
declare const _default: import("vue").DefineComponent<{
4+
type: {
5+
type: PropType<"search" | "text">;
6+
default: string;
7+
validator: (prop: FieldType) => boolean;
8+
};
9+
modelValue: {
10+
type: StringConstructor;
11+
default: string;
12+
};
13+
}, {
14+
inputRef: import("vue").Ref<HTMLInputElement | null>;
15+
hasFocus: import("vue").Ref<boolean>;
16+
clear: () => void;
17+
onInput: (e: Event) => void;
18+
onKeydown: (e: KeyboardEvent) => void;
19+
attrsStyles: import("vue").ComputedRef<{
20+
[key: string]: unknown;
21+
}>;
22+
attrsWithoutStyles: import("vue").ComputedRef<{
23+
[key: string]: unknown;
24+
}>;
25+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
26+
type?: unknown;
27+
modelValue?: unknown;
28+
} & {
29+
type: "search" | "text";
30+
modelValue: string;
31+
} & {}> & {
32+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
33+
}, {
34+
type: "search" | "text";
35+
modelValue: string;
36+
}>;
37+
export default _default;

dist/vue-search-input.es.js

+12-30
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
var __defProp = Object.defineProperty;
2-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3-
var __hasOwnProp = Object.prototype.hasOwnProperty;
4-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
5-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6-
var __spreadValues = (a, b) => {
7-
for (var prop in b || (b = {}))
8-
if (__hasOwnProp.call(b, prop))
9-
__defNormalProp(a, prop, b[prop]);
10-
if (__getOwnPropSymbols)
11-
for (var prop of __getOwnPropSymbols(b)) {
12-
if (__propIsEnum.call(b, prop))
13-
__defNormalProp(a, prop, b[prop]);
14-
}
15-
return a;
16-
};
171
import { defineComponent, ref, computed, onBeforeUnmount, openBlock, createElementBlock, normalizeProps, guardReactiveProps, renderSlot, createElementVNode, mergeProps, createCommentVNode } from "vue";
182
const fieldType = ["search", "text"];
193
var _export_sfc = (sfc, props) => {
@@ -23,6 +7,16 @@ var _export_sfc = (sfc, props) => {
237
}
248
return target;
259
};
10+
const filterObject = (obj, properties, remove = true) => {
11+
const res = {};
12+
Object.keys(obj).forEach((objAttr) => {
13+
const condition = remove ? properties.indexOf(objAttr) === -1 : properties.indexOf(objAttr) >= 0;
14+
if (condition) {
15+
res[objAttr] = obj[objAttr];
16+
}
17+
});
18+
return res;
19+
};
2620
const _sfc_main = defineComponent({
2721
inheritAttrs: false,
2822
props: {
@@ -40,20 +34,8 @@ const _sfc_main = defineComponent({
4034
setup(props, { emit, attrs }) {
4135
const hasFocus = ref(false);
4236
const inputRef = ref(null);
43-
const attrsWithoutStyles = computed(() => {
44-
const toOmit = ["class", "style"];
45-
const res = {};
46-
Object.keys(attrs).forEach((attr) => {
47-
if (toOmit.indexOf(attr) === -1) {
48-
res[attr] = attrs[attr];
49-
}
50-
});
51-
return res;
52-
});
53-
const attrsStyles = computed(() => {
54-
const style = attrs.style;
55-
return __spreadValues(__spreadValues({}, attrs.class ? { class: attrs.class } : {}), style ? { style } : {});
56-
});
37+
const attrsWithoutStyles = computed(() => filterObject(attrs, ["class", "style"]));
38+
const attrsStyles = computed(() => filterObject(attrs, ["class", "style"], false));
5739
const clear = () => {
5840
emit("update:modelValue", "");
5941
};

dist/vue-search-input.umd.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
],
1616
"main": "./dist/vue-search-input.umd.js",
1717
"module": "./dist/vue-search-input.es.js",
18+
"types": "./dist/types/SearchInput.vue.d.ts",
1819
"exports": {
1920
".": {
2021
"import": "./dist/vue-search-input.es.js",
@@ -73,6 +74,7 @@
7374
"ts-jest": "^27.1.2",
7475
"typescript": "^4.4.4",
7576
"vite": "^2.7.2",
77+
"vite-plugin-dts": "^0.9.9",
7678
"vue": "^3.2.25",
7779
"vue-tsc": "^0.29.8"
7880
}

tsconfig.json

+33-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"skipLibCheck": true,
44
"baseUrl": ".",
5-
"target": "es5",
5+
"target": "es2016",
66
"useDefineForClassFields": true,
77
"module": "esnext",
88
"moduleResolution": "node",
@@ -11,18 +11,40 @@
1111
"sourceMap": true,
1212
"resolveJsonModule": true,
1313
"esModuleInterop": true,
14-
"lib": ["esnext", "dom"],
14+
"lib": [
15+
"esnext",
16+
"dom"
17+
],
1518
"paths": {
16-
"@/*": ["./src/*"],
17-
"@playground/*": ["./playground/*"],
18-
"@root/*": ["./*"]
19+
"@/*": [
20+
"./src/*"
21+
],
22+
"@playground/*": [
23+
"./playground/*"
24+
],
25+
"@root/*": [
26+
"./*"
27+
]
1928
},
20-
"types": ["@types/jest"],
29+
"types": [
30+
"@types/jest"
31+
],
2132
},
2233
"include": [
23-
"src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue",
24-
"playground/**/*.ts", "playground/**/*.d.ts", "playground/**/*.tsx", "playground/**/*.vue",
25-
"tests/**/*.ts", "tests/**/*.d.ts", "tests/**/*.tsx", "tests/**/*.vue"
34+
"src/**/*.ts",
35+
"src/**/*.d.ts",
36+
"src/**/*.tsx",
37+
"src/**/*.vue",
38+
"playground/**/*.ts",
39+
"playground/**/*.d.ts",
40+
"playground/**/*.tsx",
41+
"playground/**/*.vue",
42+
"tests/**/*.ts",
43+
"tests/**/*.d.ts",
44+
"tests/**/*.tsx",
45+
"tests/**/*.vue"
2646
],
27-
"exclude": ["node_modules"]
28-
}
47+
"exclude": [
48+
"node_modules"
49+
]
50+
}

vite.config.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
33
import del from 'rollup-plugin-delete'
44
import { resolve } from 'path'
5+
import dts from 'vite-plugin-dts'
56

67
// https://vitejs.dev/config/
78
export default defineConfig({
8-
plugins: [del({ targets: 'dist/favicon.ico', hook: 'writeBundle' }), vue()],
9+
plugins: [
10+
del({ targets: 'dist/favicon.ico', hook: 'writeBundle' }),
11+
vue(),
12+
// https://github.com/qmhc/vite-plugin-dts#options
13+
dts({
14+
exclude: ['playground/**'],
15+
beforeWriteFile: function (filePath, content) {
16+
// Write definition files in /dist/types/ instead of /dist/src/
17+
const finalFilePath = filePath.replace('/dist/src/', '/dist/types/')
18+
19+
return { filePath: finalFilePath, content }
20+
}
21+
})
22+
],
923
resolve: {
1024
alias: {
1125
'@': resolve(__dirname, './src'),

0 commit comments

Comments
 (0)