hoci 0.0.6 → 0.0.8
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/index.cjs +166 -51
- package/dist/index.d.ts +130 -62
- package/dist/index.esm.js +167 -54
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
const core = require('@vueuse/core');
|
|
4
4
|
const vue = require('vue');
|
|
5
5
|
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
6
25
|
function defineHookProps(props) {
|
|
7
26
|
return props;
|
|
8
27
|
}
|
|
@@ -11,13 +30,73 @@ function defineHookEmits(emits) {
|
|
|
11
30
|
}
|
|
12
31
|
function defineHookComponent(options) {
|
|
13
32
|
return (props, context) => {
|
|
14
|
-
const p =
|
|
15
|
-
|
|
33
|
+
const p = withDefaults(
|
|
34
|
+
isFunction(props) ? core.reactiveComputed(() => props()) : props,
|
|
35
|
+
options.props
|
|
36
|
+
);
|
|
37
|
+
const rs = options.setup(p, context);
|
|
38
|
+
return __spreadProps(__spreadValues({}, rs), { $props: p });
|
|
16
39
|
};
|
|
17
40
|
}
|
|
41
|
+
function isFunction(value) {
|
|
42
|
+
return typeof value === "function";
|
|
43
|
+
}
|
|
44
|
+
function withDefaults(props, propsOptions) {
|
|
45
|
+
if (Array.isArray(propsOptions)) {
|
|
46
|
+
return props;
|
|
47
|
+
}
|
|
48
|
+
const rs = {};
|
|
49
|
+
const options = propsOptions;
|
|
50
|
+
for (const key in options) {
|
|
51
|
+
const k = key;
|
|
52
|
+
const opt = options[k];
|
|
53
|
+
if (opt === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (typeof opt === "function") {
|
|
57
|
+
if (isExtends(opt, Boolean)) {
|
|
58
|
+
rs[key] = false;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(opt)) {
|
|
63
|
+
if (opt.some((e) => isExtends(e, Boolean))) {
|
|
64
|
+
rs[key] = false;
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (isFunction(opt.default)) {
|
|
69
|
+
rs[key] = opt.default(props);
|
|
70
|
+
} else if (opt.default !== void 0) {
|
|
71
|
+
rs[key] = opt.default;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return __spreadValues(__spreadValues({}, rs), props);
|
|
75
|
+
}
|
|
76
|
+
function isExtends(types, value) {
|
|
77
|
+
if (Array.isArray(types)) {
|
|
78
|
+
return types.some((e) => isExtends(e, value));
|
|
79
|
+
}
|
|
80
|
+
return value === types;
|
|
81
|
+
}
|
|
82
|
+
function normalizeClass(value) {
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return value.join(" ");
|
|
85
|
+
}
|
|
86
|
+
if (typeof value === "string") {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return Object.keys(value).filter((e) => !!value[e]).join(" ");
|
|
90
|
+
}
|
|
18
91
|
|
|
19
|
-
const valuePropType = [
|
|
20
|
-
|
|
92
|
+
const valuePropType = [
|
|
93
|
+
String,
|
|
94
|
+
Number,
|
|
95
|
+
Object,
|
|
96
|
+
Boolean,
|
|
97
|
+
null
|
|
98
|
+
];
|
|
99
|
+
const classPropType = [String, Array, Object];
|
|
21
100
|
const labelPropType = [String, Function];
|
|
22
101
|
|
|
23
102
|
const InitSymbol = Symbol("[hi-selection]init");
|
|
@@ -88,17 +167,23 @@ const useSelectionItem = defineHookComponent({
|
|
|
88
167
|
const isActive = vue.inject(IsActiveSymbol, () => false);
|
|
89
168
|
const changeActive = vue.inject(ChangeActiveSymbol, () => {
|
|
90
169
|
});
|
|
91
|
-
const activeClass = vue.computed(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
170
|
+
const activeClass = vue.computed(
|
|
171
|
+
() => {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
return (_b = (_a = vue.inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
const unactiveClass = vue.computed(
|
|
177
|
+
() => {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
return (_b = (_a = vue.inject(UnactiveSymbol)) == null ? void 0 : _a.value) != null ? _b : "unactive";
|
|
180
|
+
}
|
|
181
|
+
);
|
|
99
182
|
const itemClass = vue.computed(() => {
|
|
100
183
|
var _a, _b;
|
|
101
|
-
return [(_b = (_a = vue.inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(
|
|
184
|
+
return [(_b = (_a = vue.inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(
|
|
185
|
+
isActive(props.value) ? activeClass.value : unactiveClass.value
|
|
186
|
+
);
|
|
102
187
|
});
|
|
103
188
|
const activateEvent = core.resolveRef(() => {
|
|
104
189
|
var _a, _b;
|
|
@@ -122,11 +207,18 @@ const HiItem = vue.defineComponent({
|
|
|
122
207
|
name: "HiItem",
|
|
123
208
|
props: selectionItemProps,
|
|
124
209
|
setup(props, context) {
|
|
125
|
-
const { render, activate, itemClass, activateEvent } = useSelectionItem(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
210
|
+
const { render, activate, itemClass, activateEvent } = useSelectionItem(
|
|
211
|
+
props,
|
|
212
|
+
context
|
|
213
|
+
);
|
|
214
|
+
return () => vue.h(
|
|
215
|
+
"div",
|
|
216
|
+
{
|
|
217
|
+
class: itemClass.value,
|
|
218
|
+
[`on${vue.capitalize(activateEvent.value)}`]: activate
|
|
219
|
+
},
|
|
220
|
+
render()
|
|
221
|
+
);
|
|
130
222
|
}
|
|
131
223
|
});
|
|
132
224
|
|
|
@@ -202,7 +294,12 @@ const selectionListProps = defineHookProps({
|
|
|
202
294
|
default: () => "click"
|
|
203
295
|
}
|
|
204
296
|
});
|
|
205
|
-
const selectionListEmits = defineHookEmits([
|
|
297
|
+
const selectionListEmits = defineHookEmits([
|
|
298
|
+
"update:modelValue",
|
|
299
|
+
"change",
|
|
300
|
+
"load",
|
|
301
|
+
"unload"
|
|
302
|
+
]);
|
|
206
303
|
const useSelectionList = defineHookComponent({
|
|
207
304
|
props: selectionListProps,
|
|
208
305
|
emits: selectionListEmits,
|
|
@@ -218,7 +315,9 @@ const useSelectionList = defineHookComponent({
|
|
|
218
315
|
}
|
|
219
316
|
return [value];
|
|
220
317
|
}
|
|
221
|
-
const actives = vue.reactive([
|
|
318
|
+
const actives = vue.reactive([
|
|
319
|
+
...toArray((_a = props.modelValue) != null ? _a : props.defaultValue)
|
|
320
|
+
]);
|
|
222
321
|
const currentValue = vue.computed({
|
|
223
322
|
get() {
|
|
224
323
|
return props.multiple ? actives : actives[0];
|
|
@@ -239,40 +338,47 @@ const useSelectionList = defineHookComponent({
|
|
|
239
338
|
core.syncRef(currentValue, modelValue, { immediate: true, deep: true });
|
|
240
339
|
vue.provide(
|
|
241
340
|
ActiveClassSymbol,
|
|
242
|
-
vue.computed(() => props.activeClass)
|
|
341
|
+
vue.computed(() => normalizeClass(props.activeClass))
|
|
243
342
|
);
|
|
244
343
|
vue.provide(
|
|
245
344
|
UnactiveSymbol,
|
|
246
|
-
vue.computed(() => props.unactiveClass)
|
|
345
|
+
vue.computed(() => normalizeClass(props.unactiveClass))
|
|
247
346
|
);
|
|
248
347
|
vue.provide(
|
|
249
348
|
ItemClassSymbol,
|
|
250
|
-
vue.computed(() => props.itemClass)
|
|
349
|
+
vue.computed(() => normalizeClass(props.itemClass))
|
|
350
|
+
);
|
|
351
|
+
vue.provide(
|
|
352
|
+
ItemLabelSymbol,
|
|
353
|
+
vue.computed(() => props.label)
|
|
354
|
+
);
|
|
355
|
+
vue.provide(
|
|
356
|
+
ActivateEventSymbol,
|
|
357
|
+
vue.computed(() => props.activateEvent)
|
|
251
358
|
);
|
|
252
|
-
|
|
253
|
-
vue.provide(ActivateEventSymbol, vue.computed(() => props.activateEvent));
|
|
359
|
+
const emitChange = () => emit("change", currentValue.value);
|
|
254
360
|
function isActive(value) {
|
|
255
361
|
return actives.includes(value);
|
|
256
362
|
}
|
|
257
363
|
function changeActive(option) {
|
|
258
364
|
return __async(this, null, function* () {
|
|
259
|
-
const stopWatch = vue.watch(currentValue, (val) => emit("change", val), { deep: true });
|
|
260
365
|
if (isActive(option)) {
|
|
261
366
|
if (props.multiple || props.clearable) {
|
|
262
367
|
actives.splice(actives.indexOf(option), 1);
|
|
368
|
+
emitChange();
|
|
263
369
|
}
|
|
264
370
|
} else {
|
|
265
371
|
if (props.multiple) {
|
|
266
372
|
const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
|
|
267
373
|
if (actives.length < limit) {
|
|
268
374
|
actives.push(option);
|
|
375
|
+
emitChange();
|
|
269
376
|
}
|
|
270
377
|
} else {
|
|
271
378
|
actives.splice(0, actives.length, option);
|
|
379
|
+
emitChange();
|
|
272
380
|
}
|
|
273
381
|
}
|
|
274
|
-
yield vue.nextTick();
|
|
275
|
-
stopWatch();
|
|
276
382
|
});
|
|
277
383
|
}
|
|
278
384
|
vue.provide(IsActiveSymbol, isActive);
|
|
@@ -346,39 +452,42 @@ const switchProps = defineHookProps({
|
|
|
346
452
|
tag: {
|
|
347
453
|
type: String,
|
|
348
454
|
default: "div"
|
|
455
|
+
},
|
|
456
|
+
disabled: {
|
|
457
|
+
type: Boolean,
|
|
458
|
+
default: false
|
|
459
|
+
},
|
|
460
|
+
disabledClass: {
|
|
461
|
+
type: classPropType,
|
|
462
|
+
default: ""
|
|
349
463
|
}
|
|
350
464
|
});
|
|
351
465
|
const switchEmits = defineHookEmits(["update:modelValue", "change"]);
|
|
352
466
|
const useSwitch = defineHookComponent({
|
|
353
467
|
props: switchProps,
|
|
354
468
|
emits: switchEmits,
|
|
355
|
-
setup(props,
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
(val) => {
|
|
360
|
-
checked.value = !!val;
|
|
361
|
-
}
|
|
362
|
-
);
|
|
363
|
-
const modelValue = vue.computed({
|
|
364
|
-
get() {
|
|
365
|
-
var _a;
|
|
366
|
-
return !!((_a = props.modelValue) != null ? _a : checked.value);
|
|
367
|
-
},
|
|
368
|
-
set(val) {
|
|
369
|
-
checked.value = val;
|
|
370
|
-
emit("update:modelValue", val);
|
|
371
|
-
}
|
|
469
|
+
setup(props, context) {
|
|
470
|
+
const modelValue = core.useVModel(props, "modelValue", context.emit, {
|
|
471
|
+
passive: true,
|
|
472
|
+
defaultValue: false
|
|
372
473
|
});
|
|
373
474
|
const toggle = function(value) {
|
|
475
|
+
if (props.disabled) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
374
478
|
const oldValue = modelValue.value;
|
|
375
479
|
const newValue = typeof value === "boolean" ? value : !oldValue;
|
|
376
480
|
if (newValue !== oldValue) {
|
|
377
|
-
|
|
481
|
+
modelValue.value = newValue;
|
|
482
|
+
context.emit("change", newValue);
|
|
378
483
|
}
|
|
379
484
|
};
|
|
380
485
|
const switchClass = vue.computed(() => {
|
|
381
|
-
return [
|
|
486
|
+
return [
|
|
487
|
+
props.class,
|
|
488
|
+
modelValue.value ? props.activeClass : props.unactiveClass,
|
|
489
|
+
props.disabled ? props.disabledClass : ""
|
|
490
|
+
];
|
|
382
491
|
});
|
|
383
492
|
return {
|
|
384
493
|
toggle,
|
|
@@ -395,10 +504,14 @@ const HiSwitch = vue.defineComponent({
|
|
|
395
504
|
const { slots } = context;
|
|
396
505
|
const { switchClass, toggle } = useSwitch(props, context);
|
|
397
506
|
return () => {
|
|
398
|
-
return vue.h(
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
507
|
+
return vue.h(
|
|
508
|
+
props.tag,
|
|
509
|
+
{
|
|
510
|
+
class: switchClass.value,
|
|
511
|
+
[`on${vue.capitalize(props.activateEvent)}`]: toggle
|
|
512
|
+
},
|
|
513
|
+
vue.renderSlot(slots, "default")
|
|
514
|
+
);
|
|
402
515
|
};
|
|
403
516
|
}
|
|
404
517
|
});
|
|
@@ -409,6 +522,8 @@ exports.HiSwitch = HiSwitch;
|
|
|
409
522
|
exports.defineHookComponent = defineHookComponent;
|
|
410
523
|
exports.defineHookEmits = defineHookEmits;
|
|
411
524
|
exports.defineHookProps = defineHookProps;
|
|
525
|
+
exports.isExtends = isExtends;
|
|
526
|
+
exports.normalizeClass = normalizeClass;
|
|
412
527
|
exports.selectionItemProps = selectionItemProps;
|
|
413
528
|
exports.selectionListEmits = selectionListEmits;
|
|
414
529
|
exports.selectionListProps = selectionListProps;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import * as vue from 'vue';
|
|
2
|
-
import { EmitsOptions, ComponentPropsOptions, ExtractPropTypes, SetupContext, PropType } from 'vue';
|
|
3
1
|
import { MaybeFunction } from 'maybe-types';
|
|
2
|
+
import * as vue from 'vue';
|
|
3
|
+
import { EmitsOptions, ComponentPropsOptions, ExtractPropTypes, SetupContext, ExtractDefaultPropTypes, ComponentObjectPropsOptions, PropType } from 'vue';
|
|
4
|
+
|
|
5
|
+
type ClassType = string | string[] | Record<string, any>;
|
|
6
|
+
type ActivateEvent = "click" | "mouseenter" | "mousedown" | "mouseup" | "dblclick" | "contextmenu" | "touchstart" | "touchend";
|
|
7
|
+
type ElementLike = JSX.Element | string | ElementLike[];
|
|
4
8
|
|
|
5
|
-
interface HookComponentOptions<R, E = EmitsOptions, EE extends string = string, P = ComponentPropsOptions, D
|
|
9
|
+
interface HookComponentOptions<R, E = EmitsOptions, EE extends string = string, P = ComponentPropsOptions, D = ExtractPropTypes<P>> {
|
|
6
10
|
props?: P;
|
|
7
11
|
emits?: E | EE[];
|
|
8
12
|
setup: (props: D, context: SetupContext<E>) => R;
|
|
9
13
|
}
|
|
10
|
-
type HookComponent<R, E = EmitsOptions, P = ComponentPropsOptions, D
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type HookComponent<R, E = EmitsOptions, P = ComponentPropsOptions, D = ExtractPropTypes<P>, Defaults = ExtractDefaultPropTypes<P>> = (props: MaybeFunction<Partial<Defaults> & Omit<D, keyof Defaults>>, context: SetupContext<E>) => R & {
|
|
15
|
+
$props: D;
|
|
16
|
+
};
|
|
17
|
+
declare function defineHookProps<P extends ComponentObjectPropsOptions = ComponentObjectPropsOptions>(props: P): P;
|
|
18
|
+
declare function defineHookEmits<E extends EmitsOptions = EmitsOptions, EE extends string = string>(emits: E | EE[]): E | EE[];
|
|
19
|
+
declare function defineHookComponent<R, E = EmitsOptions, EE extends string = string, P = ComponentPropsOptions, D = ExtractPropTypes<P>, Defaults = ExtractDefaultPropTypes<P>>(options: HookComponentOptions<R, E, EE, P, D>): HookComponent<R, E, P, D, Defaults>;
|
|
20
|
+
declare function isExtends(types: PropType<any>, value: PropType<any>): boolean;
|
|
21
|
+
declare function normalizeClass(value: ClassType): string;
|
|
18
22
|
|
|
19
23
|
declare const selectionItemProps: {
|
|
20
24
|
value: {
|
|
@@ -32,7 +36,7 @@ declare const selectionItemProps: {
|
|
|
32
36
|
type: PropType<string | number | symbol>;
|
|
33
37
|
};
|
|
34
38
|
activateEvent: {
|
|
35
|
-
type: PropType<
|
|
39
|
+
type: PropType<ActivateEvent>;
|
|
36
40
|
};
|
|
37
41
|
};
|
|
38
42
|
declare const useSelectionItem: HookComponent<{
|
|
@@ -61,7 +65,7 @@ declare const useSelectionItem: HookComponent<{
|
|
|
61
65
|
type: PropType<string | number | symbol>;
|
|
62
66
|
};
|
|
63
67
|
activateEvent: {
|
|
64
|
-
type: PropType<
|
|
68
|
+
type: PropType<ActivateEvent>;
|
|
65
69
|
};
|
|
66
70
|
}, vue.ExtractPropTypes<{
|
|
67
71
|
value: {
|
|
@@ -79,9 +83,12 @@ declare const useSelectionItem: HookComponent<{
|
|
|
79
83
|
type: PropType<string | number | symbol>;
|
|
80
84
|
};
|
|
81
85
|
activateEvent: {
|
|
82
|
-
type: PropType<
|
|
86
|
+
type: PropType<ActivateEvent>;
|
|
83
87
|
};
|
|
84
|
-
}
|
|
88
|
+
}>, {
|
|
89
|
+
value: any;
|
|
90
|
+
keepAlive: boolean;
|
|
91
|
+
}>;
|
|
85
92
|
declare const HiItem: vue.DefineComponent<{
|
|
86
93
|
value: {
|
|
87
94
|
type: PropType<any>;
|
|
@@ -98,7 +105,7 @@ declare const HiItem: vue.DefineComponent<{
|
|
|
98
105
|
type: PropType<string | number | symbol>;
|
|
99
106
|
};
|
|
100
107
|
activateEvent: {
|
|
101
|
-
type: PropType<
|
|
108
|
+
type: PropType<ActivateEvent>;
|
|
102
109
|
};
|
|
103
110
|
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
104
111
|
[key: string]: any;
|
|
@@ -118,11 +125,11 @@ declare const HiItem: vue.DefineComponent<{
|
|
|
118
125
|
type: PropType<string | number | symbol>;
|
|
119
126
|
};
|
|
120
127
|
activateEvent: {
|
|
121
|
-
type: PropType<
|
|
128
|
+
type: PropType<ActivateEvent>;
|
|
122
129
|
};
|
|
123
130
|
}>>, {
|
|
124
|
-
keepAlive: boolean;
|
|
125
131
|
value: any;
|
|
132
|
+
keepAlive: boolean;
|
|
126
133
|
}>;
|
|
127
134
|
|
|
128
135
|
declare const selectionListProps: {
|
|
@@ -138,18 +145,18 @@ declare const selectionListProps: {
|
|
|
138
145
|
* 选中时的 class
|
|
139
146
|
*/
|
|
140
147
|
activeClass: {
|
|
141
|
-
type: PropType<string | string[]
|
|
148
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
142
149
|
default: string;
|
|
143
150
|
};
|
|
144
151
|
/**
|
|
145
152
|
* 每个选项的 class
|
|
146
153
|
*/
|
|
147
154
|
itemClass: {
|
|
148
|
-
type: PropType<string | string[]
|
|
155
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
149
156
|
default: string;
|
|
150
157
|
};
|
|
151
158
|
unactiveClass: {
|
|
152
|
-
type: PropType<string | string[]
|
|
159
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
153
160
|
default: string;
|
|
154
161
|
};
|
|
155
162
|
label: {
|
|
@@ -205,18 +212,18 @@ declare const useSelectionList: HookComponent<{
|
|
|
205
212
|
* 选中时的 class
|
|
206
213
|
*/
|
|
207
214
|
activeClass: {
|
|
208
|
-
type: PropType<string | string[]
|
|
215
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
209
216
|
default: string;
|
|
210
217
|
};
|
|
211
218
|
/**
|
|
212
219
|
* 每个选项的 class
|
|
213
220
|
*/
|
|
214
221
|
itemClass: {
|
|
215
|
-
type: PropType<string | string[]
|
|
222
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
216
223
|
default: string;
|
|
217
224
|
};
|
|
218
225
|
unactiveClass: {
|
|
219
|
-
type: PropType<string | string[]
|
|
226
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
220
227
|
default: string;
|
|
221
228
|
};
|
|
222
229
|
label: {
|
|
@@ -256,18 +263,18 @@ declare const useSelectionList: HookComponent<{
|
|
|
256
263
|
* 选中时的 class
|
|
257
264
|
*/
|
|
258
265
|
activeClass: {
|
|
259
|
-
type: PropType<string | string[]
|
|
266
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
260
267
|
default: string;
|
|
261
268
|
};
|
|
262
269
|
/**
|
|
263
270
|
* 每个选项的 class
|
|
264
271
|
*/
|
|
265
272
|
itemClass: {
|
|
266
|
-
type: PropType<string | string[]
|
|
273
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
267
274
|
default: string;
|
|
268
275
|
};
|
|
269
276
|
unactiveClass: {
|
|
270
|
-
type: PropType<string | string[]
|
|
277
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
271
278
|
default: string;
|
|
272
279
|
};
|
|
273
280
|
label: {
|
|
@@ -294,7 +301,17 @@ declare const useSelectionList: HookComponent<{
|
|
|
294
301
|
type: PropType<ActivateEvent>;
|
|
295
302
|
default: () => "click";
|
|
296
303
|
};
|
|
297
|
-
}
|
|
304
|
+
}>, {
|
|
305
|
+
activateEvent: ActivateEvent;
|
|
306
|
+
itemClass: string | string[] | Record<string, boolean>;
|
|
307
|
+
tag: string;
|
|
308
|
+
modelValue: any;
|
|
309
|
+
activeClass: string | string[] | Record<string, boolean>;
|
|
310
|
+
unactiveClass: string | string[] | Record<string, boolean>;
|
|
311
|
+
multiple: number | boolean;
|
|
312
|
+
clearable: boolean;
|
|
313
|
+
defaultValue: any;
|
|
314
|
+
}>;
|
|
298
315
|
declare const HiSelection: vue.DefineComponent<{
|
|
299
316
|
tag: {
|
|
300
317
|
type: StringConstructor;
|
|
@@ -308,18 +325,18 @@ declare const HiSelection: vue.DefineComponent<{
|
|
|
308
325
|
* 选中时的 class
|
|
309
326
|
*/
|
|
310
327
|
activeClass: {
|
|
311
|
-
type: PropType<string | string[]
|
|
328
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
312
329
|
default: string;
|
|
313
330
|
};
|
|
314
331
|
/**
|
|
315
332
|
* 每个选项的 class
|
|
316
333
|
*/
|
|
317
334
|
itemClass: {
|
|
318
|
-
type: PropType<string | string[]
|
|
335
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
319
336
|
default: string;
|
|
320
337
|
};
|
|
321
338
|
unactiveClass: {
|
|
322
|
-
type: PropType<string | string[]
|
|
339
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
323
340
|
default: string;
|
|
324
341
|
};
|
|
325
342
|
label: {
|
|
@@ -361,18 +378,18 @@ declare const HiSelection: vue.DefineComponent<{
|
|
|
361
378
|
* 选中时的 class
|
|
362
379
|
*/
|
|
363
380
|
activeClass: {
|
|
364
|
-
type: PropType<string | string[]
|
|
381
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
365
382
|
default: string;
|
|
366
383
|
};
|
|
367
384
|
/**
|
|
368
385
|
* 每个选项的 class
|
|
369
386
|
*/
|
|
370
387
|
itemClass: {
|
|
371
|
-
type: PropType<string | string[]
|
|
388
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
372
389
|
default: string;
|
|
373
390
|
};
|
|
374
391
|
unactiveClass: {
|
|
375
|
-
type: PropType<string | string[]
|
|
392
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
376
393
|
default: string;
|
|
377
394
|
};
|
|
378
395
|
label: {
|
|
@@ -406,14 +423,14 @@ declare const HiSelection: vue.DefineComponent<{
|
|
|
406
423
|
onUnload?: ((...args: any[]) => any) | undefined;
|
|
407
424
|
}, {
|
|
408
425
|
activateEvent: ActivateEvent;
|
|
409
|
-
itemClass: string | string[]
|
|
426
|
+
itemClass: string | string[] | Record<string, boolean>;
|
|
427
|
+
tag: string;
|
|
410
428
|
modelValue: any;
|
|
429
|
+
activeClass: string | string[] | Record<string, boolean>;
|
|
430
|
+
unactiveClass: string | string[] | Record<string, boolean>;
|
|
411
431
|
multiple: number | boolean;
|
|
412
|
-
defaultValue: any;
|
|
413
|
-
tag: string;
|
|
414
|
-
activeClass: string | string[];
|
|
415
|
-
unactiveClass: string | string[];
|
|
416
432
|
clearable: boolean;
|
|
433
|
+
defaultValue: any;
|
|
417
434
|
}>;
|
|
418
435
|
|
|
419
436
|
declare const switchProps: {
|
|
@@ -422,15 +439,15 @@ declare const switchProps: {
|
|
|
422
439
|
default: boolean;
|
|
423
440
|
};
|
|
424
441
|
class: {
|
|
425
|
-
type: PropType<string | string[]
|
|
442
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
426
443
|
default: string;
|
|
427
444
|
};
|
|
428
445
|
activeClass: {
|
|
429
|
-
type: PropType<string | string[]
|
|
446
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
430
447
|
default: string;
|
|
431
448
|
};
|
|
432
449
|
unactiveClass: {
|
|
433
|
-
type: PropType<string | string[]
|
|
450
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
434
451
|
default: string;
|
|
435
452
|
};
|
|
436
453
|
activateEvent: {
|
|
@@ -441,27 +458,35 @@ declare const switchProps: {
|
|
|
441
458
|
type: StringConstructor;
|
|
442
459
|
default: string;
|
|
443
460
|
};
|
|
461
|
+
disabled: {
|
|
462
|
+
type: BooleanConstructor;
|
|
463
|
+
default: boolean;
|
|
464
|
+
};
|
|
465
|
+
disabledClass: {
|
|
466
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
467
|
+
default: string;
|
|
468
|
+
};
|
|
444
469
|
};
|
|
445
470
|
declare const switchEmits: ("update:modelValue" | "change")[];
|
|
446
471
|
declare const useSwitch: HookComponent<{
|
|
447
472
|
toggle: (value?: any) => void;
|
|
448
|
-
modelValue: vue.WritableComputedRef<boolean>;
|
|
449
|
-
switchClass: vue.ComputedRef<(string | string[])[]>;
|
|
473
|
+
modelValue: vue.Ref<boolean> | vue.WritableComputedRef<boolean>;
|
|
474
|
+
switchClass: vue.ComputedRef<(string | string[] | Record<string, boolean>)[]>;
|
|
450
475
|
}, ("update:modelValue" | "change")[], {
|
|
451
476
|
modelValue: {
|
|
452
477
|
type: BooleanConstructor;
|
|
453
478
|
default: boolean;
|
|
454
479
|
};
|
|
455
480
|
class: {
|
|
456
|
-
type: PropType<string | string[]
|
|
481
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
457
482
|
default: string;
|
|
458
483
|
};
|
|
459
484
|
activeClass: {
|
|
460
|
-
type: PropType<string | string[]
|
|
485
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
461
486
|
default: string;
|
|
462
487
|
};
|
|
463
488
|
unactiveClass: {
|
|
464
|
-
type: PropType<string | string[]
|
|
489
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
465
490
|
default: string;
|
|
466
491
|
};
|
|
467
492
|
activateEvent: {
|
|
@@ -472,21 +497,29 @@ declare const useSwitch: HookComponent<{
|
|
|
472
497
|
type: StringConstructor;
|
|
473
498
|
default: string;
|
|
474
499
|
};
|
|
500
|
+
disabled: {
|
|
501
|
+
type: BooleanConstructor;
|
|
502
|
+
default: boolean;
|
|
503
|
+
};
|
|
504
|
+
disabledClass: {
|
|
505
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
506
|
+
default: string;
|
|
507
|
+
};
|
|
475
508
|
}, vue.ExtractPropTypes<{
|
|
476
509
|
modelValue: {
|
|
477
510
|
type: BooleanConstructor;
|
|
478
511
|
default: boolean;
|
|
479
512
|
};
|
|
480
513
|
class: {
|
|
481
|
-
type: PropType<string | string[]
|
|
514
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
482
515
|
default: string;
|
|
483
516
|
};
|
|
484
517
|
activeClass: {
|
|
485
|
-
type: PropType<string | string[]
|
|
518
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
486
519
|
default: string;
|
|
487
520
|
};
|
|
488
521
|
unactiveClass: {
|
|
489
|
-
type: PropType<string | string[]
|
|
522
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
490
523
|
default: string;
|
|
491
524
|
};
|
|
492
525
|
activateEvent: {
|
|
@@ -497,22 +530,39 @@ declare const useSwitch: HookComponent<{
|
|
|
497
530
|
type: StringConstructor;
|
|
498
531
|
default: string;
|
|
499
532
|
};
|
|
500
|
-
|
|
533
|
+
disabled: {
|
|
534
|
+
type: BooleanConstructor;
|
|
535
|
+
default: boolean;
|
|
536
|
+
};
|
|
537
|
+
disabledClass: {
|
|
538
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
539
|
+
default: string;
|
|
540
|
+
};
|
|
541
|
+
}>, {
|
|
542
|
+
activateEvent: ActivateEvent;
|
|
543
|
+
class: string | string[] | Record<string, boolean>;
|
|
544
|
+
tag: string;
|
|
545
|
+
modelValue: boolean;
|
|
546
|
+
activeClass: string | string[] | Record<string, boolean>;
|
|
547
|
+
unactiveClass: string | string[] | Record<string, boolean>;
|
|
548
|
+
disabled: boolean;
|
|
549
|
+
disabledClass: string | string[] | Record<string, boolean>;
|
|
550
|
+
}>;
|
|
501
551
|
declare const HiSwitch: vue.DefineComponent<{
|
|
502
552
|
modelValue: {
|
|
503
553
|
type: BooleanConstructor;
|
|
504
554
|
default: boolean;
|
|
505
555
|
};
|
|
506
556
|
class: {
|
|
507
|
-
type: PropType<string | string[]
|
|
557
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
508
558
|
default: string;
|
|
509
559
|
};
|
|
510
560
|
activeClass: {
|
|
511
|
-
type: PropType<string | string[]
|
|
561
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
512
562
|
default: string;
|
|
513
563
|
};
|
|
514
564
|
unactiveClass: {
|
|
515
|
-
type: PropType<string | string[]
|
|
565
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
516
566
|
default: string;
|
|
517
567
|
};
|
|
518
568
|
activateEvent: {
|
|
@@ -523,6 +573,14 @@ declare const HiSwitch: vue.DefineComponent<{
|
|
|
523
573
|
type: StringConstructor;
|
|
524
574
|
default: string;
|
|
525
575
|
};
|
|
576
|
+
disabled: {
|
|
577
|
+
type: BooleanConstructor;
|
|
578
|
+
default: boolean;
|
|
579
|
+
};
|
|
580
|
+
disabledClass: {
|
|
581
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
582
|
+
default: string;
|
|
583
|
+
};
|
|
526
584
|
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
527
585
|
[key: string]: any;
|
|
528
586
|
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("update:modelValue" | "change")[], "update:modelValue" | "change", vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -531,15 +589,15 @@ declare const HiSwitch: vue.DefineComponent<{
|
|
|
531
589
|
default: boolean;
|
|
532
590
|
};
|
|
533
591
|
class: {
|
|
534
|
-
type: PropType<string | string[]
|
|
592
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
535
593
|
default: string;
|
|
536
594
|
};
|
|
537
595
|
activeClass: {
|
|
538
|
-
type: PropType<string | string[]
|
|
596
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
539
597
|
default: string;
|
|
540
598
|
};
|
|
541
599
|
unactiveClass: {
|
|
542
|
-
type: PropType<string | string[]
|
|
600
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
543
601
|
default: string;
|
|
544
602
|
};
|
|
545
603
|
activateEvent: {
|
|
@@ -550,16 +608,26 @@ declare const HiSwitch: vue.DefineComponent<{
|
|
|
550
608
|
type: StringConstructor;
|
|
551
609
|
default: string;
|
|
552
610
|
};
|
|
611
|
+
disabled: {
|
|
612
|
+
type: BooleanConstructor;
|
|
613
|
+
default: boolean;
|
|
614
|
+
};
|
|
615
|
+
disabledClass: {
|
|
616
|
+
type: PropType<string | string[] | Record<string, boolean>>;
|
|
617
|
+
default: string;
|
|
618
|
+
};
|
|
553
619
|
}>> & {
|
|
554
620
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
555
621
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
556
622
|
}, {
|
|
557
623
|
activateEvent: ActivateEvent;
|
|
558
|
-
class: string | string[]
|
|
559
|
-
modelValue: boolean;
|
|
624
|
+
class: string | string[] | Record<string, boolean>;
|
|
560
625
|
tag: string;
|
|
561
|
-
|
|
562
|
-
|
|
626
|
+
modelValue: boolean;
|
|
627
|
+
activeClass: string | string[] | Record<string, boolean>;
|
|
628
|
+
unactiveClass: string | string[] | Record<string, boolean>;
|
|
629
|
+
disabled: boolean;
|
|
630
|
+
disabledClass: string | string[] | Record<string, boolean>;
|
|
563
631
|
}>;
|
|
564
632
|
|
|
565
|
-
export { HiItem, HiSelection, HiSwitch, HookComponent, HookComponentOptions, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
|
|
633
|
+
export { HiItem, HiSelection, HiSwitch, HookComponent, HookComponentOptions, defineHookComponent, defineHookEmits, defineHookProps, isExtends, normalizeClass, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
import { reactiveComputed, resolveRef, syncRef, isDefined } from '@vueuse/core';
|
|
2
|
-
import { defineComponent, h, capitalize, inject, watch, onDeactivated, computed, renderSlot, reactive, provide
|
|
1
|
+
import { reactiveComputed, resolveRef, syncRef, isDefined, useVModel } from '@vueuse/core';
|
|
2
|
+
import { defineComponent, h, capitalize, inject, watch, onDeactivated, computed, renderSlot, reactive, provide } from 'vue';
|
|
3
3
|
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
4
23
|
function defineHookProps(props) {
|
|
5
24
|
return props;
|
|
6
25
|
}
|
|
@@ -9,13 +28,73 @@ function defineHookEmits(emits) {
|
|
|
9
28
|
}
|
|
10
29
|
function defineHookComponent(options) {
|
|
11
30
|
return (props, context) => {
|
|
12
|
-
const p =
|
|
13
|
-
|
|
31
|
+
const p = withDefaults(
|
|
32
|
+
isFunction(props) ? reactiveComputed(() => props()) : props,
|
|
33
|
+
options.props
|
|
34
|
+
);
|
|
35
|
+
const rs = options.setup(p, context);
|
|
36
|
+
return __spreadProps(__spreadValues({}, rs), { $props: p });
|
|
14
37
|
};
|
|
15
38
|
}
|
|
39
|
+
function isFunction(value) {
|
|
40
|
+
return typeof value === "function";
|
|
41
|
+
}
|
|
42
|
+
function withDefaults(props, propsOptions) {
|
|
43
|
+
if (Array.isArray(propsOptions)) {
|
|
44
|
+
return props;
|
|
45
|
+
}
|
|
46
|
+
const rs = {};
|
|
47
|
+
const options = propsOptions;
|
|
48
|
+
for (const key in options) {
|
|
49
|
+
const k = key;
|
|
50
|
+
const opt = options[k];
|
|
51
|
+
if (opt === null) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (typeof opt === "function") {
|
|
55
|
+
if (isExtends(opt, Boolean)) {
|
|
56
|
+
rs[key] = false;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(opt)) {
|
|
61
|
+
if (opt.some((e) => isExtends(e, Boolean))) {
|
|
62
|
+
rs[key] = false;
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (isFunction(opt.default)) {
|
|
67
|
+
rs[key] = opt.default(props);
|
|
68
|
+
} else if (opt.default !== void 0) {
|
|
69
|
+
rs[key] = opt.default;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return __spreadValues(__spreadValues({}, rs), props);
|
|
73
|
+
}
|
|
74
|
+
function isExtends(types, value) {
|
|
75
|
+
if (Array.isArray(types)) {
|
|
76
|
+
return types.some((e) => isExtends(e, value));
|
|
77
|
+
}
|
|
78
|
+
return value === types;
|
|
79
|
+
}
|
|
80
|
+
function normalizeClass(value) {
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
return value.join(" ");
|
|
83
|
+
}
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
return Object.keys(value).filter((e) => !!value[e]).join(" ");
|
|
88
|
+
}
|
|
16
89
|
|
|
17
|
-
const valuePropType = [
|
|
18
|
-
|
|
90
|
+
const valuePropType = [
|
|
91
|
+
String,
|
|
92
|
+
Number,
|
|
93
|
+
Object,
|
|
94
|
+
Boolean,
|
|
95
|
+
null
|
|
96
|
+
];
|
|
97
|
+
const classPropType = [String, Array, Object];
|
|
19
98
|
const labelPropType = [String, Function];
|
|
20
99
|
|
|
21
100
|
const InitSymbol = Symbol("[hi-selection]init");
|
|
@@ -86,17 +165,23 @@ const useSelectionItem = defineHookComponent({
|
|
|
86
165
|
const isActive = inject(IsActiveSymbol, () => false);
|
|
87
166
|
const changeActive = inject(ChangeActiveSymbol, () => {
|
|
88
167
|
});
|
|
89
|
-
const activeClass = computed(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
168
|
+
const activeClass = computed(
|
|
169
|
+
() => {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
return (_b = (_a = inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
const unactiveClass = computed(
|
|
175
|
+
() => {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
return (_b = (_a = inject(UnactiveSymbol)) == null ? void 0 : _a.value) != null ? _b : "unactive";
|
|
178
|
+
}
|
|
179
|
+
);
|
|
97
180
|
const itemClass = computed(() => {
|
|
98
181
|
var _a, _b;
|
|
99
|
-
return [(_b = (_a = inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(
|
|
182
|
+
return [(_b = (_a = inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(
|
|
183
|
+
isActive(props.value) ? activeClass.value : unactiveClass.value
|
|
184
|
+
);
|
|
100
185
|
});
|
|
101
186
|
const activateEvent = resolveRef(() => {
|
|
102
187
|
var _a, _b;
|
|
@@ -120,11 +205,18 @@ const HiItem = defineComponent({
|
|
|
120
205
|
name: "HiItem",
|
|
121
206
|
props: selectionItemProps,
|
|
122
207
|
setup(props, context) {
|
|
123
|
-
const { render, activate, itemClass, activateEvent } = useSelectionItem(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
208
|
+
const { render, activate, itemClass, activateEvent } = useSelectionItem(
|
|
209
|
+
props,
|
|
210
|
+
context
|
|
211
|
+
);
|
|
212
|
+
return () => h(
|
|
213
|
+
"div",
|
|
214
|
+
{
|
|
215
|
+
class: itemClass.value,
|
|
216
|
+
[`on${capitalize(activateEvent.value)}`]: activate
|
|
217
|
+
},
|
|
218
|
+
render()
|
|
219
|
+
);
|
|
128
220
|
}
|
|
129
221
|
});
|
|
130
222
|
|
|
@@ -200,7 +292,12 @@ const selectionListProps = defineHookProps({
|
|
|
200
292
|
default: () => "click"
|
|
201
293
|
}
|
|
202
294
|
});
|
|
203
|
-
const selectionListEmits = defineHookEmits([
|
|
295
|
+
const selectionListEmits = defineHookEmits([
|
|
296
|
+
"update:modelValue",
|
|
297
|
+
"change",
|
|
298
|
+
"load",
|
|
299
|
+
"unload"
|
|
300
|
+
]);
|
|
204
301
|
const useSelectionList = defineHookComponent({
|
|
205
302
|
props: selectionListProps,
|
|
206
303
|
emits: selectionListEmits,
|
|
@@ -216,7 +313,9 @@ const useSelectionList = defineHookComponent({
|
|
|
216
313
|
}
|
|
217
314
|
return [value];
|
|
218
315
|
}
|
|
219
|
-
const actives = reactive([
|
|
316
|
+
const actives = reactive([
|
|
317
|
+
...toArray((_a = props.modelValue) != null ? _a : props.defaultValue)
|
|
318
|
+
]);
|
|
220
319
|
const currentValue = computed({
|
|
221
320
|
get() {
|
|
222
321
|
return props.multiple ? actives : actives[0];
|
|
@@ -237,40 +336,47 @@ const useSelectionList = defineHookComponent({
|
|
|
237
336
|
syncRef(currentValue, modelValue, { immediate: true, deep: true });
|
|
238
337
|
provide(
|
|
239
338
|
ActiveClassSymbol,
|
|
240
|
-
computed(() => props.activeClass)
|
|
339
|
+
computed(() => normalizeClass(props.activeClass))
|
|
241
340
|
);
|
|
242
341
|
provide(
|
|
243
342
|
UnactiveSymbol,
|
|
244
|
-
computed(() => props.unactiveClass)
|
|
343
|
+
computed(() => normalizeClass(props.unactiveClass))
|
|
245
344
|
);
|
|
246
345
|
provide(
|
|
247
346
|
ItemClassSymbol,
|
|
248
|
-
computed(() => props.itemClass)
|
|
347
|
+
computed(() => normalizeClass(props.itemClass))
|
|
348
|
+
);
|
|
349
|
+
provide(
|
|
350
|
+
ItemLabelSymbol,
|
|
351
|
+
computed(() => props.label)
|
|
352
|
+
);
|
|
353
|
+
provide(
|
|
354
|
+
ActivateEventSymbol,
|
|
355
|
+
computed(() => props.activateEvent)
|
|
249
356
|
);
|
|
250
|
-
|
|
251
|
-
provide(ActivateEventSymbol, computed(() => props.activateEvent));
|
|
357
|
+
const emitChange = () => emit("change", currentValue.value);
|
|
252
358
|
function isActive(value) {
|
|
253
359
|
return actives.includes(value);
|
|
254
360
|
}
|
|
255
361
|
function changeActive(option) {
|
|
256
362
|
return __async(this, null, function* () {
|
|
257
|
-
const stopWatch = watch(currentValue, (val) => emit("change", val), { deep: true });
|
|
258
363
|
if (isActive(option)) {
|
|
259
364
|
if (props.multiple || props.clearable) {
|
|
260
365
|
actives.splice(actives.indexOf(option), 1);
|
|
366
|
+
emitChange();
|
|
261
367
|
}
|
|
262
368
|
} else {
|
|
263
369
|
if (props.multiple) {
|
|
264
370
|
const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
|
|
265
371
|
if (actives.length < limit) {
|
|
266
372
|
actives.push(option);
|
|
373
|
+
emitChange();
|
|
267
374
|
}
|
|
268
375
|
} else {
|
|
269
376
|
actives.splice(0, actives.length, option);
|
|
377
|
+
emitChange();
|
|
270
378
|
}
|
|
271
379
|
}
|
|
272
|
-
yield nextTick();
|
|
273
|
-
stopWatch();
|
|
274
380
|
});
|
|
275
381
|
}
|
|
276
382
|
provide(IsActiveSymbol, isActive);
|
|
@@ -344,39 +450,42 @@ const switchProps = defineHookProps({
|
|
|
344
450
|
tag: {
|
|
345
451
|
type: String,
|
|
346
452
|
default: "div"
|
|
453
|
+
},
|
|
454
|
+
disabled: {
|
|
455
|
+
type: Boolean,
|
|
456
|
+
default: false
|
|
457
|
+
},
|
|
458
|
+
disabledClass: {
|
|
459
|
+
type: classPropType,
|
|
460
|
+
default: ""
|
|
347
461
|
}
|
|
348
462
|
});
|
|
349
463
|
const switchEmits = defineHookEmits(["update:modelValue", "change"]);
|
|
350
464
|
const useSwitch = defineHookComponent({
|
|
351
465
|
props: switchProps,
|
|
352
466
|
emits: switchEmits,
|
|
353
|
-
setup(props,
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
(val) => {
|
|
358
|
-
checked.value = !!val;
|
|
359
|
-
}
|
|
360
|
-
);
|
|
361
|
-
const modelValue = computed({
|
|
362
|
-
get() {
|
|
363
|
-
var _a;
|
|
364
|
-
return !!((_a = props.modelValue) != null ? _a : checked.value);
|
|
365
|
-
},
|
|
366
|
-
set(val) {
|
|
367
|
-
checked.value = val;
|
|
368
|
-
emit("update:modelValue", val);
|
|
369
|
-
}
|
|
467
|
+
setup(props, context) {
|
|
468
|
+
const modelValue = useVModel(props, "modelValue", context.emit, {
|
|
469
|
+
passive: true,
|
|
470
|
+
defaultValue: false
|
|
370
471
|
});
|
|
371
472
|
const toggle = function(value) {
|
|
473
|
+
if (props.disabled) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
372
476
|
const oldValue = modelValue.value;
|
|
373
477
|
const newValue = typeof value === "boolean" ? value : !oldValue;
|
|
374
478
|
if (newValue !== oldValue) {
|
|
375
|
-
|
|
479
|
+
modelValue.value = newValue;
|
|
480
|
+
context.emit("change", newValue);
|
|
376
481
|
}
|
|
377
482
|
};
|
|
378
483
|
const switchClass = computed(() => {
|
|
379
|
-
return [
|
|
484
|
+
return [
|
|
485
|
+
props.class,
|
|
486
|
+
modelValue.value ? props.activeClass : props.unactiveClass,
|
|
487
|
+
props.disabled ? props.disabledClass : ""
|
|
488
|
+
];
|
|
380
489
|
});
|
|
381
490
|
return {
|
|
382
491
|
toggle,
|
|
@@ -393,12 +502,16 @@ const HiSwitch = defineComponent({
|
|
|
393
502
|
const { slots } = context;
|
|
394
503
|
const { switchClass, toggle } = useSwitch(props, context);
|
|
395
504
|
return () => {
|
|
396
|
-
return h(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
505
|
+
return h(
|
|
506
|
+
props.tag,
|
|
507
|
+
{
|
|
508
|
+
class: switchClass.value,
|
|
509
|
+
[`on${capitalize(props.activateEvent)}`]: toggle
|
|
510
|
+
},
|
|
511
|
+
renderSlot(slots, "default")
|
|
512
|
+
);
|
|
400
513
|
};
|
|
401
514
|
}
|
|
402
515
|
});
|
|
403
516
|
|
|
404
|
-
export { HiItem, HiSelection, HiSwitch, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
|
|
517
|
+
export { HiItem, HiSelection, HiSwitch, defineHookComponent, defineHookEmits, defineHookProps, isExtends, normalizeClass, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hoci",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@vueuse/core": "^9.12.0",
|
|
15
15
|
"maybe-types": "^0.0.3"
|
|
16
16
|
},
|
|
17
|
-
"
|
|
17
|
+
"peerDependencies": {
|
|
18
18
|
"vue": "^3.2.31"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|