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