@vue-interface/btn-dropdown 2.0.0-beta.6 → 3.0.0
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/CHANGELOG.md +12 -0
- package/demo.css +4 -0
- package/docs/btn-dropdown.md +747 -0
- package/index.css +3 -0
- package/index.html +585 -0
- package/{dist/index.d.ts → index.ts} +4 -1
- package/package.json +18 -47
- package/src/BtnDropdown.vue +41 -0
- package/src/BtnDropdownSingle.vue +55 -0
- package/src/BtnDropdownSplit.vue +84 -0
- package/src/useDropdownHandler.ts +213 -0
- package/tsconfig.json +27 -0
- package/vite.config.js +52 -0
- package/dist/btn-dropdown.js +0 -1804
- package/dist/btn-dropdown.umd.cjs +0 -5
- package/dist/src/BtnDropdown.vue.d.ts +0 -9
- package/dist/src/BtnDropdownAction.vue.d.ts +0 -43
- package/dist/src/BtnDropdownSingle.vue.d.ts +0 -280
- package/dist/src/BtnDropdownSplit.vue.d.ts +0 -282
- package/dist/src/DropdownHandler.d.ts +0 -424
- package/dist/style.css +0 -1
package/package.json
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-interface/btn-dropdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A Vue button dropdown component.",
|
|
5
|
-
"files": [
|
|
6
|
-
"dist"
|
|
7
|
-
],
|
|
8
5
|
"type": "module",
|
|
9
6
|
"main": "./dist/btn-dropdown.umd.js",
|
|
10
7
|
"module": "./dist/btn-dropdown.js",
|
|
11
8
|
"types": "./dist/index.d.ts",
|
|
12
9
|
"exports": {
|
|
13
10
|
".": {
|
|
11
|
+
"source": "./index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
14
13
|
"import": "./dist/btn-dropdown.js",
|
|
15
|
-
"require": "./dist/btn-dropdown.umd.js"
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
"./dist/style.css": "./dist/style.css"
|
|
14
|
+
"require": "./dist/btn-dropdown.umd.js"
|
|
15
|
+
}
|
|
19
16
|
},
|
|
20
17
|
"browserslist": "last 2 versions, > 0.5%, ie >= 11",
|
|
21
|
-
"scripts": {
|
|
22
|
-
"dev": "vite",
|
|
23
|
-
"build": "vite build",
|
|
24
|
-
"preview": "vite preview",
|
|
25
|
-
"pre-release": "npm run build; git add . -A; git commit -m 'pre-release commit'",
|
|
26
|
-
"release-patch": "npm run pre-release && npm version patch -m \"%s\" && npm run release;",
|
|
27
|
-
"release-minor": "npm run pre-release && npm version minor -m \"%s\" && npm run release;",
|
|
28
|
-
"release-major": "npm run pre-release && npm version major -m \"%s\" && npm run release;",
|
|
29
|
-
"release": "git add . -A; git commit; git push --tags origin; npm publish;"
|
|
30
|
-
},
|
|
31
18
|
"repository": {
|
|
32
19
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/vue-interface/btn-dropdown
|
|
20
|
+
"url": "git+https://github.com/vue-interface/btn-dropdown"
|
|
34
21
|
},
|
|
35
22
|
"keywords": [
|
|
36
23
|
"Button",
|
|
@@ -44,35 +31,19 @@
|
|
|
44
31
|
"author": "Justin Kimbrell",
|
|
45
32
|
"license": "ISC",
|
|
46
33
|
"bugs": {
|
|
47
|
-
"url": "https://github.com/vue-interface/btn-dropdown
|
|
48
|
-
},
|
|
49
|
-
"homepage": "https://github.com/vue-interface/btn-dropdown/docs#readme",
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@popperjs/core": "^2.11.2",
|
|
52
|
-
"@vue-interface/btn": "^3.0.0-beta.1",
|
|
53
|
-
"@vue-interface/btn-group": "^2.0.0-beta.4",
|
|
54
|
-
"@vue-interface/dropdown-menu": "^2.0.0-beta.8"
|
|
34
|
+
"url": "https://github.com/vue-interface/btn-dropdown"
|
|
55
35
|
},
|
|
36
|
+
"homepage": "https://github.com/vue-interface/vue-interface",
|
|
56
37
|
"peerDependencies": {
|
|
57
|
-
"
|
|
38
|
+
"@floating-ui/dom": "^1.7.1",
|
|
39
|
+
"@floating-ui/vue": "^1.1.6",
|
|
40
|
+
"vue": "^3.3.4",
|
|
41
|
+
"@vue-interface/btn": "4.0.0",
|
|
42
|
+
"@vue-interface/dropdown-menu": "3.0.0"
|
|
58
43
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"autoprefixer": "^10.4.2",
|
|
64
|
-
"babel-eslint": "^10.1.0",
|
|
65
|
-
"babel-preset-vue": "^2.0.2",
|
|
66
|
-
"change-case": "^4.1.2",
|
|
67
|
-
"eslint": "^8.25.0",
|
|
68
|
-
"eslint-plugin-vue": "^9.6.0",
|
|
69
|
-
"pascalcase": "^2.0.0",
|
|
70
|
-
"postcss": "^8.4.6",
|
|
71
|
-
"tailwindcss": "^3.1.0",
|
|
72
|
-
"ts-vue": "^0.1.0",
|
|
73
|
-
"typescript": "^4.9.4",
|
|
74
|
-
"vite": "^4.0.0",
|
|
75
|
-
"vite-plugin-dts": "^1.7.1",
|
|
76
|
-
"vue": "^3.2.41"
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "vite",
|
|
46
|
+
"build": "vite build",
|
|
47
|
+
"preview": "vite preview"
|
|
77
48
|
}
|
|
78
|
-
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import BtnDropdownSingle from './BtnDropdownSingle.vue';
|
|
3
|
+
import BtnDropdownSplit from './BtnDropdownSplit.vue';
|
|
4
|
+
import { BtnDropdownEvents, BtnDropdownProps } from './useDropdownHandler';
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(defineProps<{
|
|
7
|
+
split?: boolean
|
|
8
|
+
} & BtnDropdownProps>(), {
|
|
9
|
+
split: false,
|
|
10
|
+
caret: true
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const emit = defineEmits<BtnDropdownEvents>();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<Component
|
|
18
|
+
:is="!split ? BtnDropdownSingle : BtnDropdownSplit"
|
|
19
|
+
v-bind="props"
|
|
20
|
+
@click="(...args) => emit('click', ...args)"
|
|
21
|
+
@click-toggle="(...args) => emit('clickToggle', ...args)"
|
|
22
|
+
@show="(...args) => emit('show', ...args)"
|
|
23
|
+
@hide="(...args) => emit('hide', ...args)">
|
|
24
|
+
<template #button="slot">
|
|
25
|
+
<slot
|
|
26
|
+
name="button"
|
|
27
|
+
v-bind="slot" />
|
|
28
|
+
</template>
|
|
29
|
+
<template #toggle="slot">
|
|
30
|
+
<slot
|
|
31
|
+
name="toggle"
|
|
32
|
+
v-bind="slot" />
|
|
33
|
+
</template>
|
|
34
|
+
<template #split="slot">
|
|
35
|
+
<slot
|
|
36
|
+
name="split"
|
|
37
|
+
v-bind="slot" />
|
|
38
|
+
</template>
|
|
39
|
+
<slot />
|
|
40
|
+
</Component>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { DropdownMenu } from '@vue-interface/dropdown-menu';
|
|
3
|
+
import { BtnDropdownEvents, BtnDropdownProps, useDropdownHandler } from './useDropdownHandler';
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<BtnDropdownProps>(), {
|
|
6
|
+
caret: true,
|
|
7
|
+
variant: 'btn-primary'
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<BtnDropdownEvents>();
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
target,
|
|
14
|
+
menu,
|
|
15
|
+
buttonClasses,
|
|
16
|
+
classes,
|
|
17
|
+
expanded,
|
|
18
|
+
floatingStyles,
|
|
19
|
+
onBlur,
|
|
20
|
+
onClickToggle,
|
|
21
|
+
onClickItem
|
|
22
|
+
} = useDropdownHandler(props, emit);
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div
|
|
27
|
+
class="btn-group"
|
|
28
|
+
:class="classes">
|
|
29
|
+
<slot
|
|
30
|
+
name="button"
|
|
31
|
+
v-bind="{ target: (el: HTMLElement) => target = el, expanded, onBlur, onClickToggle }">
|
|
32
|
+
<button
|
|
33
|
+
ref="target"
|
|
34
|
+
type="button"
|
|
35
|
+
:class="{...buttonClasses, ['dropdown-toggle']: true}"
|
|
36
|
+
aria-haspopup="true"
|
|
37
|
+
:aria-expanded="expanded"
|
|
38
|
+
@blur="onBlur"
|
|
39
|
+
@click="onClickToggle">
|
|
40
|
+
{{ label }}
|
|
41
|
+
</button>
|
|
42
|
+
</slot>
|
|
43
|
+
<DropdownMenu
|
|
44
|
+
ref="menu"
|
|
45
|
+
:class="{
|
|
46
|
+
'show': expanded
|
|
47
|
+
}"
|
|
48
|
+
:style="floatingStyles"
|
|
49
|
+
@blur="onBlur"
|
|
50
|
+
@click="onClickItem"
|
|
51
|
+
@mousedown.prevent>
|
|
52
|
+
<slot />
|
|
53
|
+
</DropdownMenu>
|
|
54
|
+
</div>
|
|
55
|
+
</template>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { DropdownMenu } from '@vue-interface/dropdown-menu';
|
|
3
|
+
import { BtnDropdownEvents, BtnDropdownProps, useDropdownHandler } from './useDropdownHandler';
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<BtnDropdownProps>(), {
|
|
6
|
+
caret: true,
|
|
7
|
+
variant: 'btn-primary'
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<BtnDropdownEvents>();
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
target,
|
|
14
|
+
menu,
|
|
15
|
+
buttonClasses,
|
|
16
|
+
classes,
|
|
17
|
+
expanded,
|
|
18
|
+
floatingStyles,
|
|
19
|
+
onBlur,
|
|
20
|
+
onClick,
|
|
21
|
+
onClickToggle,
|
|
22
|
+
onClickItem
|
|
23
|
+
} = useDropdownHandler(props, emit);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<div
|
|
28
|
+
class="btn-group btn-dropdown-split"
|
|
29
|
+
:class="classes">
|
|
30
|
+
<slot
|
|
31
|
+
v-if="!dropleft"
|
|
32
|
+
name="button"
|
|
33
|
+
v-bind="{ expanded, onBlur, onClickToggle }">
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
:class="buttonClasses"
|
|
37
|
+
aria-haspopup="true"
|
|
38
|
+
:aria-expanded="expanded"
|
|
39
|
+
@blur="onBlur"
|
|
40
|
+
@click="onClick">
|
|
41
|
+
{{ label }}
|
|
42
|
+
</button>
|
|
43
|
+
</slot>
|
|
44
|
+
<div class="btn-group">
|
|
45
|
+
<slot
|
|
46
|
+
name="toggle"
|
|
47
|
+
v-bind="{ target: (el: HTMLElement) => target = el, expanded, onBlur, onClickToggle }">
|
|
48
|
+
<button
|
|
49
|
+
ref="target"
|
|
50
|
+
type="button"
|
|
51
|
+
aria-haspopup="true"
|
|
52
|
+
:aria-expanded="expanded"
|
|
53
|
+
:class="{...buttonClasses, 'dropdown-toggle': true, 'dropdown-toggle-split': split}"
|
|
54
|
+
@blur="onBlur"
|
|
55
|
+
@click="onClickToggle" />
|
|
56
|
+
</slot>
|
|
57
|
+
<DropdownMenu
|
|
58
|
+
ref="menu"
|
|
59
|
+
:class="{
|
|
60
|
+
'show': expanded
|
|
61
|
+
}"
|
|
62
|
+
:style="floatingStyles"
|
|
63
|
+
@blur="onBlur"
|
|
64
|
+
@click="onClickItem"
|
|
65
|
+
@mousedown.prevent>
|
|
66
|
+
<slot />
|
|
67
|
+
</DropdownMenu>
|
|
68
|
+
</div>
|
|
69
|
+
<slot
|
|
70
|
+
v-if="dropleft"
|
|
71
|
+
name="button"
|
|
72
|
+
v-bind="{ expanded, onBlur, onClickToggle }">
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
:class="buttonClasses"
|
|
76
|
+
aria-haspopup="true"
|
|
77
|
+
:aria-expanded="expanded"
|
|
78
|
+
@blur="onBlur"
|
|
79
|
+
@click="onClick">
|
|
80
|
+
{{ label }}
|
|
81
|
+
</button>
|
|
82
|
+
</slot>
|
|
83
|
+
</div>
|
|
84
|
+
</template>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { flip, offset, Placement, type Alignment, type Middleware, type OffsetOptions, type Side } from '@floating-ui/dom';
|
|
2
|
+
import { useFloating } from '@floating-ui/vue';
|
|
3
|
+
import { DropdownMenu } from '@vue-interface/dropdown-menu';
|
|
4
|
+
import { computed, ref, watchEffect, type EmitFn, type HTMLAttributes } from 'vue';
|
|
5
|
+
|
|
6
|
+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
7
|
+
|
|
8
|
+
export type BtnGroupSizes = 'btn-group-xs'
|
|
9
|
+
| 'btn-group-sm'
|
|
10
|
+
| 'btn-group-md'
|
|
11
|
+
| 'btn-group-lg'
|
|
12
|
+
| 'btn-group-xl'
|
|
13
|
+
| 'btn-group-2xl'
|
|
14
|
+
| 'btn-group-3xl'
|
|
15
|
+
| 'btn-group-4xl';
|
|
16
|
+
|
|
17
|
+
export type BtnDropdownProps = {
|
|
18
|
+
align?: Alignment;
|
|
19
|
+
block?: boolean;
|
|
20
|
+
buttonClass?: HTMLAttributes['class'],
|
|
21
|
+
caret?: boolean;
|
|
22
|
+
dropup?: boolean;
|
|
23
|
+
dropright?: boolean;
|
|
24
|
+
dropleft?: boolean;
|
|
25
|
+
label?: string;
|
|
26
|
+
offset?: OffsetOptions,
|
|
27
|
+
middleware?: Middleware[],
|
|
28
|
+
side?: Side;
|
|
29
|
+
size?: LiteralUnion<BtnGroupSizes>;
|
|
30
|
+
split?: boolean;
|
|
31
|
+
variant?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type BtnDropdownEvents = {
|
|
35
|
+
click: [event: MouseEvent];
|
|
36
|
+
clickToggle: [event: MouseEvent];
|
|
37
|
+
show: [],
|
|
38
|
+
hide: []
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useDropdownHandler(props: BtnDropdownProps, emit: EmitFn<BtnDropdownEvents>) {
|
|
42
|
+
const target = ref<HTMLElement>();
|
|
43
|
+
const menu = ref<InstanceType<typeof DropdownMenu>>();
|
|
44
|
+
const expanded = ref(false);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const alignment = computed<Alignment>(() => props.align ?? 'start');
|
|
48
|
+
|
|
49
|
+
const side = computed<Side>(() => {
|
|
50
|
+
if(props.dropup) {
|
|
51
|
+
return 'top';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if(props.dropleft) {
|
|
55
|
+
return 'left';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if(props.dropright) {
|
|
59
|
+
return 'right';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return 'bottom';
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const placement = computed<Placement>(() => `${side.value}-${alignment.value}`);
|
|
66
|
+
|
|
67
|
+
const classes = computed(() => ({
|
|
68
|
+
'dropdown': props.dropup && props.dropright && props.dropleft,
|
|
69
|
+
'dropup': props.dropup,
|
|
70
|
+
'dropright': props.dropright,
|
|
71
|
+
'dropleft': props.dropleft,
|
|
72
|
+
'expanded': expanded.value,
|
|
73
|
+
[props.size ?? '']: !!props.size,
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
const buttonClasses = computed(() => {
|
|
77
|
+
const classes = {
|
|
78
|
+
btn: true,
|
|
79
|
+
[props.variant ?? '']: !!props.variant,
|
|
80
|
+
'btn-block': !!props.block,
|
|
81
|
+
'no-caret': !props.caret
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if(typeof props.buttonClass === 'string') {
|
|
85
|
+
classes[props.buttonClass] = true;
|
|
86
|
+
}
|
|
87
|
+
else if(Array.isArray(props.buttonClass)) {
|
|
88
|
+
for(const value of props.buttonClass) {
|
|
89
|
+
classes[value] = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if(props.buttonClass) {
|
|
93
|
+
Object.assign(classes, props.buttonClass);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return classes;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { floatingStyles, update } = useFloating(target, menu, {
|
|
100
|
+
placement: placement,
|
|
101
|
+
middleware: props.middleware ?? [
|
|
102
|
+
offset(props.offset ?? 5),
|
|
103
|
+
flip()
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function show() {
|
|
108
|
+
expanded.value = true;
|
|
109
|
+
|
|
110
|
+
if(!target.value || !menu.value) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
update();
|
|
115
|
+
|
|
116
|
+
emit('show');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function hide() {
|
|
120
|
+
expanded.value = false;
|
|
121
|
+
|
|
122
|
+
target.value?.blur();
|
|
123
|
+
|
|
124
|
+
emit('hide');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function toggle() {
|
|
128
|
+
if(!expanded.value) {
|
|
129
|
+
show();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
hide();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isFocusable(element: HTMLElement) {
|
|
137
|
+
const nodes = Array.from(menu.value?.$el.querySelectorAll('label, input, select, textarea') ?? []);
|
|
138
|
+
|
|
139
|
+
for(const i in nodes) {
|
|
140
|
+
if(element === nodes[i]) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function onBlur(e: FocusEvent) {
|
|
149
|
+
if(!(e.relatedTarget instanceof HTMLElement)) {
|
|
150
|
+
hide();
|
|
151
|
+
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if(menu.value && !menu.value?.$el.contains(e.relatedTarget) || !target.value?.contains(e.relatedTarget)) {
|
|
156
|
+
hide();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function onClick(e: MouseEvent) {
|
|
161
|
+
emit('click', e);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function onClickToggle(e: MouseEvent) {
|
|
165
|
+
e.target?.dispatchEvent(new Event('focus', e));
|
|
166
|
+
|
|
167
|
+
emit('clickToggle', e);
|
|
168
|
+
|
|
169
|
+
if(!e.defaultPrevented) {
|
|
170
|
+
toggle();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function onClickItem(e: PointerEvent) {
|
|
175
|
+
if(!(e.target instanceof HTMLElement)) {
|
|
176
|
+
hide();
|
|
177
|
+
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if(!isFocusable(e.target) && !e.defaultPrevented) {
|
|
182
|
+
hide();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
watchEffect(() => {
|
|
187
|
+
if(expanded.value) {
|
|
188
|
+
window.addEventListener('resize', update);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
window.removeEventListener('resize', update);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
target,
|
|
197
|
+
menu,
|
|
198
|
+
alignment,
|
|
199
|
+
expanded,
|
|
200
|
+
floatingStyles,
|
|
201
|
+
placement,
|
|
202
|
+
side,
|
|
203
|
+
classes,
|
|
204
|
+
buttonClasses,
|
|
205
|
+
show,
|
|
206
|
+
hide,
|
|
207
|
+
toggle,
|
|
208
|
+
onBlur,
|
|
209
|
+
onClick,
|
|
210
|
+
onClickToggle,
|
|
211
|
+
onClickItem
|
|
212
|
+
};
|
|
213
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"customConditions": ["source"],
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"jsx": "preserve",
|
|
19
|
+
"jsxImportSource": "vue"
|
|
20
|
+
},
|
|
21
|
+
"include": [
|
|
22
|
+
"**/*.ts",
|
|
23
|
+
"**/*.tsx",
|
|
24
|
+
"**/*.vue",
|
|
25
|
+
],
|
|
26
|
+
"exclude": ["node_modules", "dist"]
|
|
27
|
+
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import { pascalCase } from 'change-case';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { defineConfig } from 'vite';
|
|
6
|
+
import dts from 'vite-plugin-dts';
|
|
7
|
+
import pkg from './package.json';
|
|
8
|
+
|
|
9
|
+
const fileName = pkg.name.split('/')[1];
|
|
10
|
+
|
|
11
|
+
const external = [
|
|
12
|
+
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
|
|
13
|
+
...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default ({ command }) => defineConfig({
|
|
17
|
+
build: {
|
|
18
|
+
sourcemap: command === 'build',
|
|
19
|
+
lib: {
|
|
20
|
+
entry: path.resolve(__dirname, 'index.ts'),
|
|
21
|
+
name: pascalCase(fileName),
|
|
22
|
+
fileName,
|
|
23
|
+
},
|
|
24
|
+
rollupOptions: {
|
|
25
|
+
external,
|
|
26
|
+
output: {
|
|
27
|
+
globals: external.reduce((carry, dep) => {
|
|
28
|
+
return Object.assign(carry, {
|
|
29
|
+
[dep]: pascalCase(dep)
|
|
30
|
+
});
|
|
31
|
+
}, {}),
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
watch: !process.env.NODE_ENV && {
|
|
35
|
+
include: [
|
|
36
|
+
'./tailwindcss/**/*.js'
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
resolve: {
|
|
41
|
+
conditions: process.env.NODE_ENV === 'development'
|
|
42
|
+
? ['source', 'import', 'module', 'browser', 'default']
|
|
43
|
+
: ['import', 'module', 'browser', 'default'],
|
|
44
|
+
},
|
|
45
|
+
plugins: [
|
|
46
|
+
vue(),
|
|
47
|
+
dts({
|
|
48
|
+
entryRoot: path.resolve(__dirname, './'),
|
|
49
|
+
}),
|
|
50
|
+
tailwindcss(),
|
|
51
|
+
],
|
|
52
|
+
});
|