@hoci/components 0.4.3 → 0.5.1
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 +425 -2
- package/dist/index.d.cts +314 -5
- package/dist/index.d.mts +314 -5
- package/dist/index.d.ts +314 -5
- package/dist/index.mjs +430 -11
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const vue = require('vue');
|
|
4
4
|
const core = require('@hoci/core');
|
|
5
5
|
const tslx = require('tslx');
|
|
6
|
+
const shared = require('@hoci/shared');
|
|
7
|
+
const core$1 = require('@vueuse/core');
|
|
6
8
|
|
|
7
9
|
const HiAffix = vue.defineComponent({
|
|
8
10
|
name: "HiAffix",
|
|
@@ -60,7 +62,7 @@ const HiItem = vue.defineComponent({
|
|
|
60
62
|
props.as,
|
|
61
63
|
{
|
|
62
64
|
class: className.value,
|
|
63
|
-
[`on${
|
|
65
|
+
[`on${tslx.capitalize(activateEvent.value)}`]: activate,
|
|
64
66
|
disabled: isDisabled.value
|
|
65
67
|
},
|
|
66
68
|
render()
|
|
@@ -115,13 +117,430 @@ const HiSwitch = vue.defineComponent({
|
|
|
115
117
|
}
|
|
116
118
|
});
|
|
117
119
|
|
|
120
|
+
const HiConfigProvider = vue.defineComponent({
|
|
121
|
+
props: {
|
|
122
|
+
...core.configProviderProps,
|
|
123
|
+
as: {
|
|
124
|
+
type: String
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
setup(props, context) {
|
|
128
|
+
core.provideSharedConfig(props);
|
|
129
|
+
return () => {
|
|
130
|
+
const content = vue.renderSlot(context.slots, "default", void 0);
|
|
131
|
+
if (props.as) {
|
|
132
|
+
return vue.h(props.as, content);
|
|
133
|
+
}
|
|
134
|
+
return content;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const selectionProps = shared.defineHookProps({
|
|
140
|
+
modelValue: {
|
|
141
|
+
type: shared.valuePropType,
|
|
142
|
+
default: () => null
|
|
143
|
+
},
|
|
144
|
+
/**
|
|
145
|
+
* 选中时的 class
|
|
146
|
+
*/
|
|
147
|
+
activeClass: {
|
|
148
|
+
type: shared.classPropType,
|
|
149
|
+
default: "active"
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* 每个选项的 class
|
|
153
|
+
*/
|
|
154
|
+
itemClass: {
|
|
155
|
+
type: shared.classPropType,
|
|
156
|
+
default: ""
|
|
157
|
+
},
|
|
158
|
+
disabledClass: {
|
|
159
|
+
type: shared.classPropType,
|
|
160
|
+
default: "disabled"
|
|
161
|
+
},
|
|
162
|
+
unactiveClass: {
|
|
163
|
+
type: shared.classPropType,
|
|
164
|
+
default: ""
|
|
165
|
+
},
|
|
166
|
+
label: {
|
|
167
|
+
type: shared.labelPropType
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* 多选模式
|
|
171
|
+
*/
|
|
172
|
+
multiple: {
|
|
173
|
+
type: [Boolean, Number],
|
|
174
|
+
default: () => false
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* 可清除
|
|
178
|
+
*/
|
|
179
|
+
clearable: {
|
|
180
|
+
type: Boolean
|
|
181
|
+
},
|
|
182
|
+
defaultValue: {
|
|
183
|
+
type: shared.valuePropType,
|
|
184
|
+
default: () => null
|
|
185
|
+
},
|
|
186
|
+
activateEvent: {
|
|
187
|
+
type: String
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const selectionEmits = shared.defineHookEmits([
|
|
191
|
+
"update:modelValue",
|
|
192
|
+
"change",
|
|
193
|
+
"load",
|
|
194
|
+
"unload"
|
|
195
|
+
]);
|
|
196
|
+
const HiSelectionContextSymbol = Symbol("[hi-selection]context");
|
|
197
|
+
function useSelectionContext() {
|
|
198
|
+
const sharedConfig = shared.useSharedConfig();
|
|
199
|
+
return vue.inject(HiSelectionContextSymbol, {
|
|
200
|
+
isActive: () => false,
|
|
201
|
+
changeActive: () => {
|
|
202
|
+
},
|
|
203
|
+
activeClass: "active",
|
|
204
|
+
unactiveClass: "unactive",
|
|
205
|
+
disabledClass: "disabled",
|
|
206
|
+
itemClass: "",
|
|
207
|
+
activateEvent: sharedConfig.activateEvent,
|
|
208
|
+
label: null,
|
|
209
|
+
multiple: false
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const useSelectionList = shared.defineHookComponent({
|
|
213
|
+
props: selectionProps,
|
|
214
|
+
emits: selectionEmits,
|
|
215
|
+
setup(props, { emit, slots }) {
|
|
216
|
+
const options = vue.reactive([]);
|
|
217
|
+
function toArray(value) {
|
|
218
|
+
if (!core$1.isDefined(value)) {
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
if (props.multiple && Array.isArray(value)) {
|
|
222
|
+
return value.filter((v) => v != null || v !== void 0);
|
|
223
|
+
}
|
|
224
|
+
return [value];
|
|
225
|
+
}
|
|
226
|
+
const actives = vue.reactive([
|
|
227
|
+
...toArray(props.modelValue ?? props.defaultValue)
|
|
228
|
+
]);
|
|
229
|
+
const currentValue = vue.computed({
|
|
230
|
+
get() {
|
|
231
|
+
return props.multiple ? actives : actives[0];
|
|
232
|
+
},
|
|
233
|
+
set(val) {
|
|
234
|
+
actives.splice(0, actives.length, ...toArray(val));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
const modelValue = vue.computed({
|
|
238
|
+
get() {
|
|
239
|
+
return props.modelValue ?? props.defaultValue;
|
|
240
|
+
},
|
|
241
|
+
set(val) {
|
|
242
|
+
emit("update:modelValue", val);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
core$1.syncRef(currentValue, modelValue, { immediate: true, deep: true });
|
|
246
|
+
const emitChange = () => emit("change", currentValue.value);
|
|
247
|
+
function isActive(value) {
|
|
248
|
+
return actives.includes(value);
|
|
249
|
+
}
|
|
250
|
+
function changeActive(value) {
|
|
251
|
+
if (isActive(value)) {
|
|
252
|
+
if (props.multiple || props.clearable) {
|
|
253
|
+
actives.splice(actives.indexOf(value), 1);
|
|
254
|
+
emitChange();
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
if (props.multiple) {
|
|
258
|
+
const limit = typeof props.multiple === "number" ? props.multiple : Number.POSITIVE_INFINITY;
|
|
259
|
+
if (actives.length < limit) {
|
|
260
|
+
actives.push(value);
|
|
261
|
+
emitChange();
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
actives.splice(0, actives.length, value);
|
|
265
|
+
emitChange();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const init = (option) => {
|
|
270
|
+
function remove() {
|
|
271
|
+
const index = options.findIndex((e) => e.id === option.id);
|
|
272
|
+
if (index > -1) {
|
|
273
|
+
options.splice(index, 1);
|
|
274
|
+
emit("unload", option);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
for (let i = 0; i < options.length; i++) {
|
|
278
|
+
if (options[i].value === option.value) {
|
|
279
|
+
options.splice(i, 1);
|
|
280
|
+
i--;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
options.push(option);
|
|
284
|
+
emit("load", option);
|
|
285
|
+
return remove;
|
|
286
|
+
};
|
|
287
|
+
const sharedConfig = shared.useSharedConfig();
|
|
288
|
+
vue.provide(HiSelectionContextSymbol, core$1.toReactive({
|
|
289
|
+
activeClass: vue.computed(() => tslx.cls(props.activeClass)),
|
|
290
|
+
unactiveClass: vue.computed(() => tslx.cls(props.unactiveClass)),
|
|
291
|
+
disabledClass: vue.computed(() => tslx.cls(props.disabledClass)),
|
|
292
|
+
itemClass: vue.computed(() => tslx.cls(props.itemClass)),
|
|
293
|
+
label: vue.computed(() => props.label),
|
|
294
|
+
multiple: vue.computed(() => props.multiple),
|
|
295
|
+
clearable: vue.computed(() => props.clearable),
|
|
296
|
+
defaultValue: vue.computed(() => props.defaultValue),
|
|
297
|
+
activateEvent: vue.computed(() => props.activateEvent ?? sharedConfig.activateEvent),
|
|
298
|
+
active: currentValue,
|
|
299
|
+
changeActive,
|
|
300
|
+
isActive,
|
|
301
|
+
init
|
|
302
|
+
}));
|
|
303
|
+
const renderItem = () => {
|
|
304
|
+
const children = options.filter((e) => actives.includes(e.value)).map((e) => e.render());
|
|
305
|
+
return props.multiple ? children : shared.getFirstChilld(children);
|
|
306
|
+
};
|
|
307
|
+
const slotData = {
|
|
308
|
+
isActive,
|
|
309
|
+
changeActive,
|
|
310
|
+
renderItem
|
|
311
|
+
};
|
|
312
|
+
const render = () => {
|
|
313
|
+
return vue.renderSlot(slots, "default", slotData);
|
|
314
|
+
};
|
|
315
|
+
return {
|
|
316
|
+
options,
|
|
317
|
+
actives,
|
|
318
|
+
isActive,
|
|
319
|
+
changeActive,
|
|
320
|
+
renderItem,
|
|
321
|
+
render
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const HiTabs = vue.defineComponent({
|
|
327
|
+
props: {
|
|
328
|
+
...selectionProps,
|
|
329
|
+
headerClass: {
|
|
330
|
+
type: shared.classPropType
|
|
331
|
+
},
|
|
332
|
+
as: {
|
|
333
|
+
type: String,
|
|
334
|
+
default: "div"
|
|
335
|
+
},
|
|
336
|
+
headerAs: {
|
|
337
|
+
type: String,
|
|
338
|
+
default: "div"
|
|
339
|
+
},
|
|
340
|
+
contentAs: {
|
|
341
|
+
type: String,
|
|
342
|
+
default: "div"
|
|
343
|
+
},
|
|
344
|
+
contentClass: {
|
|
345
|
+
type: shared.classPropType
|
|
346
|
+
},
|
|
347
|
+
keepAlive: {
|
|
348
|
+
type: [Boolean, Object],
|
|
349
|
+
default: false
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
setup(props, context) {
|
|
353
|
+
const selection = useSelectionList(props, context);
|
|
354
|
+
return () => {
|
|
355
|
+
let component = selection.renderItem();
|
|
356
|
+
if (props.keepAlive) {
|
|
357
|
+
component = vue.h(vue.KeepAlive, {
|
|
358
|
+
...typeof props.keepAlive == "object" ? props.keepAlive : {}
|
|
359
|
+
}, component);
|
|
360
|
+
}
|
|
361
|
+
if (context.slots.content) {
|
|
362
|
+
component = context.slots.content({
|
|
363
|
+
component
|
|
364
|
+
});
|
|
365
|
+
} else {
|
|
366
|
+
component = vue.h(props.contentAs, {
|
|
367
|
+
class: props.contentClass
|
|
368
|
+
}, component);
|
|
369
|
+
}
|
|
370
|
+
return vue.h(props.as, [
|
|
371
|
+
vue.h(props.headerAs, {
|
|
372
|
+
class: props.headerClass
|
|
373
|
+
}, vue.renderSlot(context.slots, "default")),
|
|
374
|
+
component
|
|
375
|
+
]);
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const itemProps = shared.defineHookProps({
|
|
381
|
+
value: {
|
|
382
|
+
type: shared.valuePropType,
|
|
383
|
+
default() {
|
|
384
|
+
return Math.random().toString(16).slice(2);
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
label: {
|
|
388
|
+
type: [Function, String]
|
|
389
|
+
},
|
|
390
|
+
keepAlive: {
|
|
391
|
+
type: Boolean,
|
|
392
|
+
default: () => true
|
|
393
|
+
},
|
|
394
|
+
key: {
|
|
395
|
+
type: [String, Number, Symbol]
|
|
396
|
+
},
|
|
397
|
+
activateEvent: {
|
|
398
|
+
type: String
|
|
399
|
+
},
|
|
400
|
+
disabled: {
|
|
401
|
+
type: Boolean,
|
|
402
|
+
default: false
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
const useSelectionItem = shared.defineHookComponent({
|
|
406
|
+
props: itemProps,
|
|
407
|
+
setup(props, { slots }) {
|
|
408
|
+
const context = useSelectionContext();
|
|
409
|
+
const activate = () => {
|
|
410
|
+
if (props.disabled) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
context.changeActive(props.value);
|
|
414
|
+
};
|
|
415
|
+
const label = vue.computed(() => {
|
|
416
|
+
let label2 = props.label ?? context.label;
|
|
417
|
+
if (label2 && typeof label2 == "function") {
|
|
418
|
+
label2 = label2(props.value);
|
|
419
|
+
}
|
|
420
|
+
return Array.isArray(label2) ? label2 : [label2];
|
|
421
|
+
});
|
|
422
|
+
function render() {
|
|
423
|
+
return slots.default?.({
|
|
424
|
+
active: context.isActive(props.value),
|
|
425
|
+
activate
|
|
426
|
+
}) ?? label.value.filter(Boolean);
|
|
427
|
+
}
|
|
428
|
+
let remove = () => {
|
|
429
|
+
};
|
|
430
|
+
const init = context.init;
|
|
431
|
+
if (init) {
|
|
432
|
+
vue.watch(
|
|
433
|
+
() => props.value,
|
|
434
|
+
(value) => {
|
|
435
|
+
remove();
|
|
436
|
+
remove = init({
|
|
437
|
+
id: Math.random().toString(16).slice(2),
|
|
438
|
+
label: typeof props.label == "string" ? props.label : void 0,
|
|
439
|
+
value,
|
|
440
|
+
render
|
|
441
|
+
});
|
|
442
|
+
},
|
|
443
|
+
{ immediate: true }
|
|
444
|
+
);
|
|
445
|
+
core$1.tryOnScopeDispose(remove);
|
|
446
|
+
}
|
|
447
|
+
const isActive = vue.computed(() => context.isActive(props.value));
|
|
448
|
+
const isDisabled = vue.computed(() => props.disabled);
|
|
449
|
+
const className = vue.computed(() => {
|
|
450
|
+
const array = [context.itemClass];
|
|
451
|
+
if (!isDisabled.value) {
|
|
452
|
+
array.push(context.isActive(props.value) ? context.activeClass : context.unactiveClass);
|
|
453
|
+
} else {
|
|
454
|
+
array.push(context.disabledClass);
|
|
455
|
+
}
|
|
456
|
+
return tslx.cls(array);
|
|
457
|
+
});
|
|
458
|
+
const activateEvent = vue.computed(() => props.activateEvent ?? context.activateEvent);
|
|
459
|
+
return {
|
|
460
|
+
activate,
|
|
461
|
+
render,
|
|
462
|
+
isActive,
|
|
463
|
+
isDisabled,
|
|
464
|
+
className,
|
|
465
|
+
activateEvent,
|
|
466
|
+
label
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const HiTabPane = vue.defineComponent({
|
|
472
|
+
props: {
|
|
473
|
+
...itemProps
|
|
474
|
+
},
|
|
475
|
+
setup(props, context) {
|
|
476
|
+
const { className, activateEvent, activate, isDisabled, label } = useSelectionItem(props, context);
|
|
477
|
+
return () => {
|
|
478
|
+
return vue.h(
|
|
479
|
+
"div",
|
|
480
|
+
{
|
|
481
|
+
class: className.value,
|
|
482
|
+
[`on${tslx.capitalize(activateEvent.value)}`]: activate,
|
|
483
|
+
disabled: isDisabled.value
|
|
484
|
+
},
|
|
485
|
+
label.value
|
|
486
|
+
);
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
const HiPopover = vue.defineComponent({
|
|
492
|
+
name: "HiPopover",
|
|
493
|
+
props: {
|
|
494
|
+
...core.popoverProps,
|
|
495
|
+
as: {
|
|
496
|
+
type: String,
|
|
497
|
+
default: "div"
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
emits: core.popoverEmits,
|
|
501
|
+
setup(props, context) {
|
|
502
|
+
const { triggerRef, popupClass, events, popupRef, popupStyle } = core.usePopover(props, context);
|
|
503
|
+
return () => {
|
|
504
|
+
let content = vue.h(
|
|
505
|
+
"div",
|
|
506
|
+
{
|
|
507
|
+
class: popupClass.value,
|
|
508
|
+
style: popupStyle.value,
|
|
509
|
+
ref: popupRef
|
|
510
|
+
},
|
|
511
|
+
vue.renderSlot(context.slots, "popup")
|
|
512
|
+
);
|
|
513
|
+
if (props.teleport) {
|
|
514
|
+
content = vue.h(
|
|
515
|
+
vue.Teleport,
|
|
516
|
+
{
|
|
517
|
+
to: props.teleport === true ? "body" : props.teleport
|
|
518
|
+
},
|
|
519
|
+
content
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
return vue.h(props.as, {
|
|
523
|
+
ref: triggerRef,
|
|
524
|
+
...events
|
|
525
|
+
}, [
|
|
526
|
+
vue.renderSlot(context.slots, "default"),
|
|
527
|
+
content
|
|
528
|
+
]);
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
|
|
118
533
|
const components = {
|
|
119
534
|
__proto__: null,
|
|
120
535
|
HiAffix: HiAffix,
|
|
536
|
+
HiConfigProvider: HiConfigProvider,
|
|
121
537
|
HiIcon: HiIcon,
|
|
122
538
|
HiItem: HiItem,
|
|
539
|
+
HiPopover: HiPopover,
|
|
123
540
|
HiSelection: HiSelection,
|
|
124
|
-
HiSwitch: HiSwitch
|
|
541
|
+
HiSwitch: HiSwitch,
|
|
542
|
+
HiTabPane: HiTabPane,
|
|
543
|
+
HiTabs: HiTabs
|
|
125
544
|
};
|
|
126
545
|
|
|
127
546
|
const install = (app) => {
|
|
@@ -131,8 +550,12 @@ const install = (app) => {
|
|
|
131
550
|
};
|
|
132
551
|
|
|
133
552
|
exports.HiAffix = HiAffix;
|
|
553
|
+
exports.HiConfigProvider = HiConfigProvider;
|
|
134
554
|
exports.HiIcon = HiIcon;
|
|
135
555
|
exports.HiItem = HiItem;
|
|
556
|
+
exports.HiPopover = HiPopover;
|
|
136
557
|
exports.HiSelection = HiSelection;
|
|
137
558
|
exports.HiSwitch = HiSwitch;
|
|
559
|
+
exports.HiTabPane = HiTabPane;
|
|
560
|
+
exports.HiTabs = HiTabs;
|
|
138
561
|
exports.install = install;
|