@deot/vc-components 1.0.1 → 1.0.2

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { reactive, defineComponent, createVNode, ref, watch, h, getCurrentInstance, inject, computed, onMounted, provide, onBeforeUnmount, toRaw, TransitionGroup, Transition as Transition$1, withDirectives, vShow, onUnmounted, withModifiers, createApp, Fragment as Fragment$1, Teleport, nextTick, mergeProps, shallowRef, onUpdated, isVNode, createTextVNode } from 'vue';
1
+ import { reactive, defineComponent, createVNode, ref, watch, getCurrentInstance, computed, TransitionGroup, Transition as Transition$1, h, inject, onMounted, provide, onBeforeUnmount, toRaw, withDirectives, vShow, onUnmounted, withModifiers, createApp, Fragment as Fragment$1, Teleport, nextTick, mergeProps, shallowRef, onUpdated, isVNode, createTextVNode } from 'vue';
2
2
  import { debounce, cloneDeep, pick, throttle, kebabCase } from 'lodash-es';
3
3
  import * as Utils from '@deot/helper-utils';
4
4
  import { getPropByPath, getUid, raf, throttle as throttle$1 } from '@deot/helper-utils';
@@ -83,58 +83,33 @@ const ActionSheet = /* @__PURE__ */ defineComponent({
83
83
  const MActionSheet = ActionSheet;
84
84
 
85
85
  const props$1f = {
86
- tag: {
86
+ modelValue: {
87
+ type: Boolean,
88
+ default: true
89
+ },
90
+ type: {
87
91
  type: String,
88
- default: "div"
89
- }
90
- };
91
-
92
- /** @jsxImportSource vue */
93
-
94
- const COMPONENT_NAME$1v = 'vc-alert';
95
- const Alert = /* @__PURE__ */ defineComponent({
96
- name: COMPONENT_NAME$1v,
97
- props: props$1f,
98
- setup(props, {
99
- slots
100
- }) {
101
- return () => {
102
- return createVNode("div", {
103
- "class": "vc-alert"
104
- }, [slots?.default?.()]);
105
- };
106
- }
107
- });
108
-
109
- const MAlert = Alert;
110
-
111
- const props$1e = {
112
- tag: {
92
+ default: "info"
93
+ },
94
+ title: {
113
95
  type: String,
114
- default: "div"
96
+ default: ""
97
+ },
98
+ desc: {
99
+ type: String,
100
+ default: ""
101
+ },
102
+ icon: {
103
+ type: [String, Boolean],
104
+ default: true
105
+ },
106
+ closable: {
107
+ type: Boolean,
108
+ default: false
115
109
  }
116
110
  };
117
111
 
118
- /** @jsxImportSource vue */
119
-
120
- const COMPONENT_NAME$1u = 'vc-artboard';
121
- const Artboard = /* @__PURE__ */ defineComponent({
122
- name: COMPONENT_NAME$1u,
123
- props: props$1e,
124
- setup(props, {
125
- slots
126
- }) {
127
- return () => {
128
- return createVNode("div", {
129
- "class": "vc-artboard"
130
- }, [slots?.default?.()]);
131
- };
132
- }
133
- });
134
-
135
- const MArtboard = Artboard;
136
-
137
- const props$1d = {
112
+ const props$1e = {
138
113
  type: String,
139
114
  inherit: {
140
115
  type: Boolean,
@@ -279,10 +254,10 @@ const IconManager = new Manager();
279
254
 
280
255
  /** @jsxImportSource vue */
281
256
 
282
- const COMPONENT_NAME$1t = 'vc-icon';
257
+ const COMPONENT_NAME$1v = 'vc-icon';
283
258
  const Icon = /* @__PURE__ */ defineComponent({
284
- name: COMPONENT_NAME$1t,
285
- props: props$1d,
259
+ name: COMPONENT_NAME$1v,
260
+ props: props$1e,
286
261
  setup(props) {
287
262
  const viewBox = ref('0 0 1024 1024');
288
263
  const path = ref([]);
@@ -315,501 +290,581 @@ const Icon = /* @__PURE__ */ defineComponent({
315
290
  }
316
291
  });
317
292
 
318
- const props$1c = {
319
- size: {
320
- type: Number,
321
- default: 28
322
- },
323
- foreground: {
324
- type: String,
325
- default: "#ccc"
326
- },
327
- background: {
328
- type: String,
329
- default: "var(--vc-color-primary)"
330
- },
293
+ const props$1d = {
331
294
  /**
332
- * 待开发
295
+ * 进入/离开持续时间
296
+ * {enter: 300, leave: 300}
333
297
  */
334
- fixed: {
335
- type: Boolean,
336
- default: false
337
- }
338
- };
339
-
340
- /** @jsxImportSource vue */
341
-
342
- const COMPONENT_NAME$1s = 'vc-spin';
343
- const Spin = /* @__PURE__ */ defineComponent({
344
- name: COMPONENT_NAME$1s,
345
- props: props$1c,
346
- setup(props, {
347
- slots
348
- }) {
349
- return () => {
350
- return createVNode("div", {
351
- "class": "vc-spin"
352
- }, [createVNode("span", {
353
- "style": {
354
- fontSize: `${props.size}px`
355
- }
356
- }, [slots?.loading?.() || createVNode("svg", {
357
- "xmlns": "http://www.w3.org/2000/svg",
358
- "version": "1.1",
359
- "viewBox": "0 0 32 32",
360
- "width": "100%",
361
- "height": "100%"
362
- }, [createVNode("path", {
363
- "stroke": props.foreground,
364
- "d": "M 16 2 A 14 14 0 1 0 30 15",
365
- "fill": "none",
366
- "stroke-width": "2",
367
- "stroke-linecap": "round"
368
- }, null), createVNode("path", {
369
- "stroke": props.background,
370
- "d": "M 16 2 A 14 14 0 0 1 30 15",
371
- "fill": "none",
372
- "stroke-width": "2",
373
- "stroke-linecap": "round"
374
- }, null)])]), slots?.default?.()]);
375
- };
376
- }
377
- });
378
-
379
- const props$1b = {
380
- wait: {
381
- type: Number,
382
- default: 250
383
- },
384
- tag: {
385
- type: [String, Object],
386
- default: "div"
298
+ duration: {
299
+ type: [Number, Object],
300
+ default: 300
387
301
  },
388
- include: {
389
- type: RegExp,
390
- default: () => /^on([A-Z])/
302
+ /**
303
+ * 进入/离开延迟时间
304
+ */
305
+ delay: {
306
+ type: [Number, Object],
307
+ default: 0
391
308
  },
392
- exclude: RegExp
393
- };
394
-
395
- const COMPONENT_NAME$1r = "vc-debounce";
396
- const Debounce = defineComponent({
397
- name: COMPONENT_NAME$1r,
398
- props: props$1b,
399
309
  /**
400
- * 不声明emits使得事件被透传放入attrs中, 这样可以让所有的事件透传
401
- * 如事件onClick
402
- * 当inheritAttrs为true时:因为emits为声明onClick会覆盖到`props.tag`上,使得我们重写的onClick无效
403
- * 当inheritAttrs为false时: 透传的onClick不会被重载,这样我们就可以重写onClick
310
+ * `transition-group` component.
311
+ */
312
+ group: Boolean,
313
+ /**
314
+ * `transition-group` tag, v3版本默认值无
404
315
  */
405
- inheritAttrs: false,
406
- setup(props, { slots, attrs }) {
407
- const listener = ref({});
408
- watch(
409
- [() => props.wait, () => props.exclude, () => props.include],
410
- () => {
411
- const { wait, exclude, include } = props;
412
- const ons = Object.entries(attrs).reduce((pre, [key, callback]) => {
413
- /* istanbul ignore else -- @preserve */
414
- if ((!exclude || !exclude.test(key)) && (!include || include.test(key)) && typeof callback === "function") {
415
- pre[key] = debounce(callback, wait, {
416
- leading: true,
417
- trailing: false
418
- });
419
- }
420
- return pre;
421
- }, {});
422
- if (Object.keys(listener.value).length !== Object.keys(ons).length) {
423
- listener.value = ons;
424
- }
425
- },
426
- {
427
- immediate: true
428
- }
429
- );
430
- return () => {
431
- return h(props.tag, {
432
- ...attrs,
433
- ...listener.value
434
- }, slots.default?.());
435
- };
436
- }
437
- });
438
-
439
- const props$1a = {
440
316
  tag: {
441
317
  type: String,
442
- default: "button"
318
+ default: void 0
443
319
  },
444
- type: {
320
+ /**
321
+ * 变换的初始位置, 可以用style代替, 更短~~
322
+ */
323
+ origin: {
445
324
  type: String,
446
- default: "default"
325
+ default: ""
447
326
  },
448
- size: {
449
- type: String,
450
- default: "medium"
327
+ /**
328
+ * 在转换期间应用的元素样式。这些样式应用于@beforeEnter和@beforeLeave钩子
329
+ * inheritAttrs必须是false
330
+ */
331
+ style: {
332
+ type: Object,
333
+ default: () => {
334
+ return {
335
+ animationFillMode: "both",
336
+ animationTimingFunction: "ease-out"
337
+ };
338
+ }
451
339
  },
452
- wait: {
453
- type: Number,
454
- default: 250
340
+ prefix: {
341
+ type: String,
342
+ default: "vc-transition"
455
343
  },
456
- icon: String,
457
- disabled: Boolean,
458
- circle: Boolean,
459
- round: Boolean,
460
- long: Boolean,
461
- htmlType: {
344
+ mode: {
462
345
  type: String,
463
- default: "button"
346
+ default: "none"
464
347
  }
465
348
  };
466
349
 
467
- /** @jsxImportSource vue */
468
-
469
- const COMPONENT_NAME$1q = 'vc-button';
470
- const Button = /* @__PURE__ */ defineComponent({
471
- name: COMPONENT_NAME$1q,
472
- emits: ['click'],
473
- props: props$1a,
474
- setup(props, {
475
- slots
476
- }) {
477
- const vm = getCurrentInstance();
478
- const hasSlot = ref(true);
479
- const isLoading = ref(false);
480
- const group = inject('button-group', {
481
- size: 'medium',
482
- vertical: false,
483
- circle: false
484
- });
485
- const classes = computed(() => ({
486
- 'is-circle': props.circle || group.circle,
487
- 'is-alone': !hasSlot.value,
488
- 'is-round': props.round,
489
- 'is-long': props.long,
490
- 'is-disabled': props.disabled,
491
- [`is-${props.size}`]: true,
492
- [`is-${props.type}`]: true
493
- }));
494
- const handleClick = (...args) => {
495
- const fn = vm.vnode.props?.['onClick']?.(...args);
496
- if (fn && fn.then) {
497
- isLoading.value = true;
498
- fn.finally(() => {
499
- isLoading.value = false;
500
- });
501
- }
350
+ const trim = (str) => str.trim().replace(/\s+/g, " ");
351
+ const useTransition = () => {
352
+ const instance = getCurrentInstance();
353
+ const attrs = instance.attrs;
354
+ const props = instance.props;
355
+ const Wrapper = computed(() => {
356
+ return props.group ? TransitionGroup : Transition$1;
357
+ });
358
+ const classes = computed(() => {
359
+ const modeClass = props.mode !== "none" ? `is-${props.mode.replace(/-/g, " is-")}` : "";
360
+ return {
361
+ enterActiveClass: trim(`${attrs.enterActiveClass || ""} ${props.prefix} ${modeClass} is-in`),
362
+ leaveActiveClass: trim(`${attrs.leaveActiveClass || ""} ${props.prefix} ${modeClass} is-out`),
363
+ moveClass: props.group ? trim(`${attrs.moveClass || ""} ${props.prefix} ${modeClass} is-move`) : void 0
502
364
  };
503
- onMounted(() => {
504
- hasSlot.value = slots.default !== undefined;
365
+ });
366
+ const clearStyles = (el) => {
367
+ Object.keys(props.style).forEach((key) => {
368
+ const v = props.style[key];
369
+ v && el.style.removeProperty(
370
+ key.replace(/([A-Z])/g, "-$1").toLowerCase()
371
+ );
505
372
  });
506
- return () => {
507
- return createVNode(Debounce, {
508
- "tag": props.tag,
509
- "class": {
510
- 'vc-button': true,
511
- ...classes.value
512
- },
513
- "wait": props.wait,
514
- "disabled": props.disabled,
515
- "type": props.htmlType,
516
- "onClick": handleClick
517
- }, {
518
- default: () => [props.icon && createVNode(Icon, {
519
- "type": props.icon
520
- }, null), isLoading.value && createVNode(Spin, {
521
- "size": 12,
522
- "foreground": props.type === 'default' ? '#ccc' : '#fff',
523
- "class": "vc-button__loading"
524
- }, null), hasSlot.value && createVNode("span", null, [slots?.default?.()])]
525
- });
373
+ el.style.removeProperty("animation-duration");
374
+ el.style.removeProperty("animation-delay");
375
+ };
376
+ const resetAbsolute = (el) => {
377
+ props.group && (el.style.position = "absolute");
378
+ };
379
+ const resetOrigin = (el) => {
380
+ props.origin && (el.style.transformOrigin = props.origin);
381
+ };
382
+ const resetStyles = (el) => {
383
+ resetOrigin(el);
384
+ Object.keys(props.style).forEach((key) => {
385
+ const v = props.style[key];
386
+ v && (el.style[key] = v);
387
+ });
388
+ };
389
+ const handleBeforeEnter = (el) => {
390
+ const duration = props.duration.enter || props.duration;
391
+ el.style.animationDuration = `${duration}ms`;
392
+ const delay = props.delay.enter || props.delay;
393
+ el.style.animationDelay = `${delay}ms`;
394
+ resetStyles(el);
395
+ attrs.onBeforeEnter?.(el);
396
+ };
397
+ const createNext = (callback, duration) => {
398
+ let hasDone = false;
399
+ return (immediate = true) => {
400
+ if (hasDone) return;
401
+ hasDone = true;
402
+ const done = () => callback?.();
403
+ immediate ? done() : setTimeout(done, duration);
526
404
  };
527
- }
528
- });
529
-
530
- const props$19 = {
531
- vertical: {
532
- type: Boolean,
533
- default: false
534
- },
535
- circle: {
536
- type: Boolean,
537
- default: false
538
- },
539
- size: {
540
- type: String,
541
- default: "medium"
542
- },
543
- fragment: {
544
- type: Boolean,
545
- default: false
546
- }
405
+ };
406
+ const handleEnter = async (el, done) => {
407
+ const duration = props.duration.enter || props.duration;
408
+ const next = createNext(done, duration);
409
+ try {
410
+ await attrs.onEnter?.(el, next);
411
+ } finally {
412
+ next(false);
413
+ }
414
+ };
415
+ const handleAfterEnter = (el) => {
416
+ clearStyles(el);
417
+ attrs.onAfterEnter?.(el);
418
+ };
419
+ const handleBeforeLeave = (el) => {
420
+ const duration = props.duration.leave || props.duration;
421
+ el.style.animationDuration = `${duration}ms`;
422
+ const delay = props.delay.leave || props.delay;
423
+ el.style.animationDelay = `${delay}ms`;
424
+ resetStyles(el);
425
+ attrs.onBeforeLeave?.(el);
426
+ };
427
+ const handleLeave = async (el, done) => {
428
+ const duration = props.duration.leave || props.duration;
429
+ const next = createNext(done, duration);
430
+ try {
431
+ resetAbsolute(el);
432
+ await attrs.onLeave?.(el, next);
433
+ } finally {
434
+ next(props.group ? true : false);
435
+ }
436
+ };
437
+ const handleAfterLeave = (el) => {
438
+ clearStyles(el);
439
+ attrs.onAfterLeave?.(el);
440
+ };
441
+ return {
442
+ Wrapper,
443
+ resetStyles,
444
+ resetAbsolute,
445
+ classes,
446
+ createNext,
447
+ listeners: {
448
+ onBeforeEnter: handleBeforeEnter,
449
+ onEnter: handleEnter,
450
+ onAfterEnter: handleAfterEnter,
451
+ onBeforeLeave: handleBeforeLeave,
452
+ onLeave: handleLeave,
453
+ onAfterLeave: handleAfterLeave
454
+ }
455
+ };
547
456
  };
548
457
 
549
- /** @jsxImportSource vue */
550
-
551
- const COMPONENT_NAME$1p = 'vc-button-group';
552
- const ButtonGroup = /* @__PURE__ */ defineComponent({
553
- name: COMPONENT_NAME$1p,
554
- props: props$19,
555
- setup(props, {
556
- slots
557
- }) {
558
- provide('button-group', props);
559
- const classes = computed(() => ({
560
- 'is-vertical': props.vertical,
561
- 'is-circle': props.circle,
562
- [`is-${props.size}`]: !!props.size
563
- }));
458
+ const COMPONENT_NAME$1u = "vc-transition";
459
+ const Transition = defineComponent({
460
+ name: COMPONENT_NAME$1u,
461
+ props: props$1d,
462
+ // 当不声明emits的情况下,事件存在于attrs中
463
+ inheritAttrs: false,
464
+ setup(props, { slots, attrs }) {
465
+ const { Wrapper, listeners, classes } = useTransition();
564
466
  return () => {
565
- return props.fragment ? slots?.default?.() : createVNode("div", {
566
- "class": {
567
- 'vc-button-group': true,
568
- ...classes.value
569
- }
570
- }, [slots?.default?.()]);
467
+ return h(
468
+ Wrapper.value,
469
+ {
470
+ ...attrs,
471
+ ...listeners,
472
+ ...classes.value,
473
+ tag: props.tag
474
+ },
475
+ slots
476
+ );
571
477
  };
572
478
  }
573
479
  });
574
480
 
575
- const MButton = Button;
576
- const MButtonGroup = ButtonGroup;
577
-
578
- const props$18 = {
579
- tag: {
580
- type: String,
581
- default: "div"
582
- }
583
- };
584
-
585
- /** @jsxImportSource vue */
586
-
587
- const COMPONENT_NAME$1o = 'vc-calendar';
588
- const Calendar = /* @__PURE__ */ defineComponent({
589
- name: COMPONENT_NAME$1o,
590
- props: props$18,
591
- setup(props, {
592
- slots
593
- }) {
594
- return () => {
595
- return createVNode("div", {
596
- "class": "vc-calendar"
597
- }, [slots?.default?.()]);
481
+ const COMPONENT_NAME$1t = "vc-transition-collapse";
482
+ const TransitionCollapse = defineComponent({
483
+ name: COMPONENT_NAME$1t,
484
+ props: props$1d,
485
+ // 当不声明emits的情况下,事件存在于attrs中
486
+ inheritAttrs: false,
487
+ setup(props, { slots, attrs: _attrs }) {
488
+ const attrs = _attrs;
489
+ const { Wrapper, resetStyles, resetAbsolute, createNext } = useTransition();
490
+ const getTransitionStyle = (duration) => {
491
+ const style = `
492
+ ${duration}ms height ease-in-out,
493
+ ${duration}ms padding-top ease-in-out,
494
+ ${duration}ms padding-bottom ease-in-out
495
+ `;
496
+ return style;
598
497
  };
599
- }
600
- });
601
-
602
- const MCalendar = Calendar;
603
-
604
- const props$17 = {
605
- tag: {
606
- type: String,
607
- default: "div"
608
- }
609
- };
610
-
611
- /** @jsxImportSource vue */
612
-
613
- const COMPONENT_NAME$1n = 'vc-card';
614
- const Card = /* @__PURE__ */ defineComponent({
615
- name: COMPONENT_NAME$1n,
616
- props: props$17,
617
- setup(props, {
618
- slots
619
- }) {
620
- return () => {
621
- return createVNode("div", {
622
- "class": "vc-card"
623
- }, [slots?.default?.()]);
498
+ const handleBeforeEnter = (el) => {
499
+ const duration = props.duration.enter || props.duration;
500
+ el.style.transition = getTransitionStyle(duration);
501
+ /* istanbul ignore next -- @preserve */
502
+ if (!el.dataset) {
503
+ el.dataset = {};
504
+ }
505
+ el.dataset.oldPaddingTop = el.style.paddingTop;
506
+ el.dataset.oldPaddingBottom = el.style.paddingBottom;
507
+ el.style.height = "0px";
508
+ el.style.paddingTop = "0px";
509
+ el.style.paddingBottom = "0px";
510
+ resetStyles(el);
511
+ attrs.onBeforeEnter?.(el);
624
512
  };
625
- }
626
- });
627
-
628
- const MCard = Card;
629
-
630
- const props$16 = {
631
- tag: {
632
- type: String,
633
- default: "div"
634
- }
635
- };
636
-
637
- /** @jsxImportSource vue */
638
-
639
- const COMPONENT_NAME$1m = 'vc-carousel';
640
- const Carousel = /* @__PURE__ */ defineComponent({
641
- name: COMPONENT_NAME$1m,
642
- props: props$16,
643
- setup(props, {
644
- slots
645
- }) {
646
- return () => {
647
- return createVNode("div", {
648
- "class": "vc-carousel"
649
- }, [slots?.default?.()]);
513
+ const handleEnter = async (el, done) => {
514
+ const duration = props.duration.enter || props.duration;
515
+ const next = createNext(done, duration);
516
+ try {
517
+ el.dataset.oldOverflow = el.style.overflow;
518
+ /* istanbul ignore next -- @preserve */
519
+ if (el.scrollHeight !== 0) {
520
+ el.style.height = el.scrollHeight + "px";
521
+ el.style.paddingTop = el.dataset.oldPaddingTop + "px";
522
+ el.style.paddingBottom = el.dataset.oldPaddingBottom + "px";
523
+ } else {
524
+ el.style.height = "";
525
+ el.style.paddingTop = el.dataset.oldPaddingTop + "px";
526
+ el.style.paddingBottom = el.dataset.oldPaddingBottom + "px";
527
+ }
528
+ el.style.overflow = "hidden";
529
+ attrs.onEnter?.(el);
530
+ } finally {
531
+ next(false);
532
+ }
533
+ };
534
+ const handleAfterEnter = (el) => {
535
+ el.style.transition = "";
536
+ el.style.height = "";
537
+ el.style.overflow = el.dataset.oldOverflow || "";
538
+ attrs.onAfterEnter?.(el);
539
+ };
540
+ const handleBeforeLeave = (el) => {
541
+ /* istanbul ignore next -- @preserve */
542
+ if (!el.dataset) {
543
+ el.dataset = {};
544
+ }
545
+ el.dataset.oldPaddingTop = el.style.paddingTop;
546
+ el.dataset.oldPaddingBottom = el.style.paddingBottom;
547
+ el.dataset.oldOverflow = el.style.overflow;
548
+ el.style.height = el.scrollHeight + "px";
549
+ el.style.overflow = "hidden";
550
+ resetStyles(el);
551
+ attrs.onBeforeLeave?.(el);
552
+ };
553
+ const handleLeave = (el, done) => {
554
+ const duration = props.duration.leave || props.duration;
555
+ const next = createNext(done, duration);
556
+ try {
557
+ const leaveDuration = props.duration.leave || props.duration;
558
+ /* istanbul ignore next -- @preserve */
559
+ if (el.scrollHeight !== 0) {
560
+ el.style.transition = getTransitionStyle(leaveDuration);
561
+ el.style.height = "0px";
562
+ el.style.paddingTop = "0px";
563
+ el.style.paddingBottom = "0px";
564
+ }
565
+ resetAbsolute(el);
566
+ attrs.onLeave?.(el);
567
+ } finally {
568
+ next(props.group ? true : false);
569
+ }
570
+ };
571
+ const handleAfterLeave = (el) => {
572
+ el.style.transition = "";
573
+ el.style.height = "";
574
+ el.style.overflow = el.dataset.oldOverflow || "";
575
+ el.style.paddingTop = el.dataset.oldPaddingTop || "";
576
+ el.style.paddingBottom = el.dataset.oldPaddingBottom || "";
577
+ attrs.onAfterLeave?.(el);
578
+ };
579
+ const listeners = {
580
+ onBeforeEnter: handleBeforeEnter,
581
+ onEnter: handleEnter,
582
+ onAfterEnter: handleAfterEnter,
583
+ onBeforeLeave: handleBeforeLeave,
584
+ onLeave: handleLeave,
585
+ onAfterLeave: handleAfterLeave
650
586
  };
651
- }
652
- });
653
-
654
- const MCarousel = Carousel;
655
-
656
- const props$15 = {
657
- tag: {
658
- type: String,
659
- default: "div"
660
- }
661
- };
662
-
663
- /** @jsxImportSource vue */
664
-
665
- const COMPONENT_NAME$1l = 'vc-cascader';
666
- const Cascader = /* @__PURE__ */ defineComponent({
667
- name: COMPONENT_NAME$1l,
668
- props: props$15,
669
- setup(props, {
670
- slots
671
- }) {
672
587
  return () => {
673
- return createVNode("div", {
674
- "class": "vc-cascader"
675
- }, [slots?.default?.()]);
588
+ return h(
589
+ Wrapper.value,
590
+ {
591
+ ...attrs,
592
+ ...listeners,
593
+ tag: props.tag,
594
+ moveClass: props.group ? `${attrs.moveClass || ""} vc-transition-collapse is-move` : void 0
595
+ },
596
+ slots
597
+ );
676
598
  };
677
599
  }
678
600
  });
679
601
 
680
- const MCascader = Cascader;
681
-
682
- const props$14 = {
683
- tag: {
684
- type: String,
685
- default: "div"
686
- }
687
- };
688
-
689
- /** @jsxImportSource vue */
690
-
691
- const COMPONENT_NAME$1k = 'vc-chart';
692
- const Chart = /* @__PURE__ */ defineComponent({
693
- name: COMPONENT_NAME$1k,
694
- props: props$14,
695
- setup(props, {
696
- slots
697
- }) {
602
+ const COMPONENT_NAME$1s = "vc-transition-fade";
603
+ const TransitionFade = defineComponent({
604
+ name: COMPONENT_NAME$1s,
605
+ props: {
606
+ ...props$1d,
607
+ // inheritAttrs必须是false
608
+ style: {
609
+ type: Object,
610
+ default: () => ({
611
+ animationFillMode: "both",
612
+ animationTimingFunction: void 0
613
+ })
614
+ },
615
+ prefix: {
616
+ type: String,
617
+ default: "vc-transition-fade"
618
+ }
619
+ },
620
+ // 当不声明emits的情况下,事件存在于attrs中
621
+ inheritAttrs: false,
622
+ setup(props, { slots, attrs }) {
623
+ const { Wrapper, listeners, classes } = useTransition();
698
624
  return () => {
699
- return createVNode("div", {
700
- "class": "vc-chart"
701
- }, [slots?.default?.()]);
625
+ return h(
626
+ Wrapper.value,
627
+ {
628
+ ...attrs,
629
+ ...listeners,
630
+ ...classes.value,
631
+ tag: props.tag
632
+ },
633
+ slots
634
+ );
702
635
  };
703
636
  }
704
637
  });
705
638
 
706
- const MChart = Chart;
707
-
708
- const props$13 = {
709
- tag: {
710
- type: String,
711
- default: "div"
712
- }
713
- };
714
-
715
- /** @jsxImportSource vue */
716
-
717
- const COMPONENT_NAME$1j = 'vc-checkbox';
718
- const Checkbox = /* @__PURE__ */ defineComponent({
719
- name: COMPONENT_NAME$1j,
720
- props: props$13,
721
- setup(props, {
722
- slots
723
- }) {
639
+ const COMPONENT_NAME$1r = "vc-transition-scale";
640
+ const TransitionScale = defineComponent({
641
+ name: COMPONENT_NAME$1r,
642
+ props: {
643
+ ...props$1d,
644
+ mode: {
645
+ type: String,
646
+ default: "both",
647
+ validator: (v) => /(part|both|y|x|none)/.test(v)
648
+ },
649
+ // inheritAttrs必须是false
650
+ style: {
651
+ type: Object,
652
+ default: () => ({
653
+ animationFillMode: "both",
654
+ animationTimingFunction: void 0
655
+ })
656
+ },
657
+ prefix: {
658
+ type: String,
659
+ default: "vc-transition-scale"
660
+ }
661
+ },
662
+ // 当不声明emits的情况下,事件存在于attrs中
663
+ inheritAttrs: false,
664
+ setup(props, { slots, attrs }) {
665
+ const { Wrapper, listeners, classes } = useTransition();
724
666
  return () => {
725
- return createVNode("div", {
726
- "class": "vc-checkbox"
727
- }, [slots?.default?.()]);
667
+ return h(
668
+ Wrapper.value,
669
+ {
670
+ ...attrs,
671
+ ...listeners,
672
+ ...classes.value,
673
+ tag: props.tag
674
+ },
675
+ slots
676
+ );
728
677
  };
729
678
  }
730
679
  });
731
680
 
732
- const MCheckbox = Checkbox;
733
-
734
- const props$12 = {
735
- tag: {
736
- type: String,
737
- default: "div"
738
- }
739
- };
740
-
741
- /** @jsxImportSource vue */
742
-
743
- const COMPONENT_NAME$1i = 'vc-clipboard';
744
- const Clipboard = /* @__PURE__ */ defineComponent({
745
- name: COMPONENT_NAME$1i,
746
- props: props$12,
747
- setup(props, {
748
- slots
749
- }) {
681
+ const COMPONENT_NAME$1q = "vc-transition-slide";
682
+ const TransitionSlide = defineComponent({
683
+ name: COMPONENT_NAME$1q,
684
+ props: {
685
+ ...props$1d,
686
+ mode: {
687
+ type: String,
688
+ default: "left",
689
+ validator: (v) => /^(left|right|down|up|none)(|-part)$/.test(v)
690
+ },
691
+ // inheritAttrs必须是false
692
+ style: {
693
+ type: Object,
694
+ default: () => ({
695
+ animationFillMode: "both",
696
+ animationTimingFunction: void 0
697
+ })
698
+ },
699
+ prefix: {
700
+ type: String,
701
+ default: "vc-transition-slide"
702
+ }
703
+ },
704
+ // 当不声明emits的情况下,事件存在于attrs中
705
+ inheritAttrs: false,
706
+ setup(props, { slots, attrs }) {
707
+ const { Wrapper, listeners, classes } = useTransition();
750
708
  return () => {
751
- return createVNode("div", {
752
- "class": "vc-clipboard"
753
- }, [slots?.default?.()]);
709
+ return h(
710
+ Wrapper.value,
711
+ {
712
+ ...attrs,
713
+ ...listeners,
714
+ ...classes.value,
715
+ tag: props.tag
716
+ },
717
+ slots
718
+ );
754
719
  };
755
720
  }
756
721
  });
757
722
 
758
- const MClipboard = Clipboard;
759
-
760
- const props$11 = {
761
- tag: {
762
- type: String,
763
- default: "div"
764
- }
765
- };
766
-
767
- /** @jsxImportSource vue */
768
-
769
- const COMPONENT_NAME$1h = 'vc-collapse';
770
- const Collapse = /* @__PURE__ */ defineComponent({
771
- name: COMPONENT_NAME$1h,
772
- props: props$11,
773
- setup(props, {
774
- slots
775
- }) {
723
+ const COMPONENT_NAME$1p = "vc-transition-zoom";
724
+ const TransitionZoom = defineComponent({
725
+ name: COMPONENT_NAME$1p,
726
+ props: {
727
+ ...props$1d,
728
+ mode: {
729
+ type: String,
730
+ default: "x",
731
+ validator: (v) => /^(x|y|center|none)$/.test(v)
732
+ },
733
+ // inheritAttrs必须是false
734
+ style: {
735
+ type: Object,
736
+ default: () => ({
737
+ animationFillMode: "both",
738
+ animationTimingFunction: void 0
739
+ })
740
+ },
741
+ prefix: {
742
+ type: String,
743
+ default: "vc-transition-zoom"
744
+ }
745
+ },
746
+ // 当不声明emits的情况下,事件存在于attrs中
747
+ inheritAttrs: false,
748
+ setup(props, { slots, attrs }) {
749
+ const { Wrapper, listeners, classes } = useTransition();
776
750
  return () => {
777
- return createVNode("div", {
778
- "class": "vc-collapse"
779
- }, [slots?.default?.()]);
751
+ return h(
752
+ Wrapper.value,
753
+ {
754
+ ...attrs,
755
+ ...listeners,
756
+ ...classes.value,
757
+ tag: props.tag
758
+ },
759
+ slots
760
+ );
780
761
  };
781
762
  }
782
763
  });
783
764
 
784
- const MCollapse = Collapse;
785
-
786
- const props$10 = {
787
- tag: {
788
- type: String,
789
- default: "div"
790
- }
791
- };
792
-
793
765
  /** @jsxImportSource vue */
794
766
 
795
- const COMPONENT_NAME$1g = 'vc-color-picker';
796
- const ColorPicker = /* @__PURE__ */ defineComponent({
797
- name: COMPONENT_NAME$1g,
798
- props: props$10,
767
+ const COMPONENT_NAME$1o = 'vc-alert';
768
+
769
+ // [color, borderColor, backgroundColor], -> CSS
770
+ const THEME_MAP = {
771
+ info: ['#5495f6', '#91d5ff', '#e6f7ff'],
772
+ success: ['#52c41a', '#b7eb8f', '#f6ffed'],
773
+ error: ['#ed4014', '#ffb08f', '#fbe9e9'],
774
+ warning: ['#ffbf00', '#ffe58f', '#fffbe6']
775
+ };
776
+ const Alert = /* @__PURE__ */ defineComponent({
777
+ name: COMPONENT_NAME$1o,
778
+ props: props$1f,
799
779
  setup(props, {
800
- slots
780
+ slots,
781
+ emit
801
782
  }) {
783
+ const isActive = ref(false);
784
+ const showIcon = computed(() => props.icon !== false);
785
+ const containerStyle = computed(() => {
786
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
787
+ const [_, borderColor, backgroundColor] = THEME_MAP[props.type];
788
+ return {
789
+ borderColor,
790
+ backgroundColor
791
+ };
792
+ });
793
+ const iconStyle = computed(() => {
794
+ const [color] = THEME_MAP[props.type];
795
+ return {
796
+ color
797
+ };
798
+ });
799
+ const titleStyle = computed(() => {
800
+ const [color] = THEME_MAP[props.type];
801
+ return props.desc || slots.desc ? {
802
+ marginBottom: '5px',
803
+ fontSize: '14px',
804
+ color
805
+ } : {};
806
+ });
807
+ const descStyle = computed(() => {
808
+ const [color] = THEME_MAP[props.type];
809
+ return {
810
+ color,
811
+ opacity: '.7'
812
+ };
813
+ });
814
+ const iconType = computed(() => {
815
+ return typeof props.icon === 'string' && props.icon ? props.icon : props.type;
816
+ });
817
+ const handleClose = () => {
818
+ isActive.value = false;
819
+ emit('close');
820
+ emit('update:modelValue', false);
821
+ emit('visible-change', false);
822
+ };
823
+ watch(() => props.modelValue, v => {
824
+ isActive.value = v;
825
+ }, {
826
+ immediate: true
827
+ });
802
828
  return () => {
803
- return createVNode("div", {
804
- "class": "vc-color-picker"
805
- }, [slots?.default?.()]);
829
+ return createVNode(TransitionFade, null, {
830
+ default: () => [isActive.value && createVNode("div", {
831
+ "class": [`is-${props.type}`, {
832
+ 'has-icon': showIcon.value,
833
+ 'has-desc': props.desc || slots.desc
834
+ }, 'vc-alert'],
835
+ "style": containerStyle.value
836
+ }, [showIcon.value && createVNode(Icon, {
837
+ "type": iconType.value,
838
+ "style": iconStyle.value,
839
+ "class": "vc-alert__icon"
840
+ }, null), createVNode("div", {
841
+ "class": "vc-alert__content"
842
+ }, [createVNode("div", {
843
+ "class": "vc-alert__message"
844
+ }, [props.title ? createVNode("div", {
845
+ "style": titleStyle.value,
846
+ "innerHTML": props.title
847
+ }, null) : createVNode("div", {
848
+ "style": titleStyle.value
849
+ }, [slots?.default?.()]), props.desc ? createVNode("div", {
850
+ "style": descStyle.value,
851
+ "innerHTML": props.desc
852
+ }, null) : slots.desc && createVNode("div", {
853
+ "style": descStyle.value
854
+ }, [slots.desc?.()])]), props.closable && createVNode("div", {
855
+ "class": "vc-alert__close",
856
+ "onClick": handleClose
857
+ }, [slots.close ? slots.close() : createVNode(Icon, {
858
+ "type": "close"
859
+ }, null)])])])]
860
+ });
806
861
  };
807
862
  }
808
863
  });
809
864
 
810
- const MColorPicker = ColorPicker;
865
+ const MAlert = Alert;
811
866
 
812
- const props$$ = {
867
+ const props$1c = {
813
868
  tag: {
814
869
  type: String,
815
870
  default: "div"
@@ -818,96 +873,284 @@ const props$$ = {
818
873
 
819
874
  /** @jsxImportSource vue */
820
875
 
821
- const COMPONENT_NAME$1f = 'vc-countdown';
822
- const Countdown = /* @__PURE__ */ defineComponent({
823
- name: COMPONENT_NAME$1f,
824
- props: props$$,
876
+ const COMPONENT_NAME$1n = 'vc-artboard';
877
+ const Artboard = /* @__PURE__ */ defineComponent({
878
+ name: COMPONENT_NAME$1n,
879
+ props: props$1c,
825
880
  setup(props, {
826
881
  slots
827
882
  }) {
828
883
  return () => {
829
884
  return createVNode("div", {
830
- "class": "vc-countdown"
885
+ "class": "vc-artboard"
831
886
  }, [slots?.default?.()]);
832
887
  };
833
888
  }
834
889
  });
835
890
 
836
- const MCountdown = Countdown;
837
-
838
- const props$_ = {
839
- render: {
840
- type: Function,
841
- default: () => null
842
- }
843
- };
844
-
845
- const COMPONENT_NAME$1e = "vc-customer";
846
- const Customer = defineComponent({
847
- name: COMPONENT_NAME$1e,
848
- props: props$_,
849
- setup(props, context) {
850
- return () => h(() => {
851
- return props.render(context.attrs, context);
852
- });
853
- }
854
- });
855
-
856
- const MCustomer = Customer;
891
+ const MArtboard = Artboard;
857
892
 
858
- const props$Z = {
859
- tag: {
893
+ const props$1b = {
894
+ size: {
895
+ type: Number,
896
+ default: 28
897
+ },
898
+ foreground: {
860
899
  type: String,
861
- default: "div"
900
+ default: "#ccc"
901
+ },
902
+ background: {
903
+ type: String,
904
+ default: "var(--vc-color-primary)"
905
+ },
906
+ /**
907
+ * 待开发
908
+ */
909
+ fixed: {
910
+ type: Boolean,
911
+ default: false
862
912
  }
863
913
  };
864
914
 
865
915
  /** @jsxImportSource vue */
866
916
 
867
- const COMPONENT_NAME$1d = 'vc-date-picker';
868
- const DatePicker = /* @__PURE__ */ defineComponent({
869
- name: COMPONENT_NAME$1d,
870
- props: props$Z,
917
+ const COMPONENT_NAME$1m = 'vc-spin';
918
+ const Spin = /* @__PURE__ */ defineComponent({
919
+ name: COMPONENT_NAME$1m,
920
+ props: props$1b,
871
921
  setup(props, {
872
922
  slots
873
923
  }) {
874
924
  return () => {
875
925
  return createVNode("div", {
876
- "class": "vc-date-picker"
877
- }, [slots?.default?.()]);
926
+ "class": "vc-spin"
927
+ }, [createVNode("span", {
928
+ "style": {
929
+ fontSize: `${props.size}px`
930
+ }
931
+ }, [slots?.loading?.() || createVNode("svg", {
932
+ "xmlns": "http://www.w3.org/2000/svg",
933
+ "version": "1.1",
934
+ "viewBox": "0 0 32 32",
935
+ "width": "100%",
936
+ "height": "100%"
937
+ }, [createVNode("path", {
938
+ "stroke": props.foreground,
939
+ "d": "M 16 2 A 14 14 0 1 0 30 15",
940
+ "fill": "none",
941
+ "stroke-width": "2",
942
+ "stroke-linecap": "round"
943
+ }, null), createVNode("path", {
944
+ "stroke": props.background,
945
+ "d": "M 16 2 A 14 14 0 0 1 30 15",
946
+ "fill": "none",
947
+ "stroke-width": "2",
948
+ "stroke-linecap": "round"
949
+ }, null)])]), slots?.default?.()]);
878
950
  };
879
951
  }
880
952
  });
881
953
 
882
- const MDatePicker = DatePicker;
883
-
884
- const props$Y = {
954
+ const props$1a = {
955
+ wait: {
956
+ type: Number,
957
+ default: 250
958
+ },
885
959
  tag: {
886
- type: String,
960
+ type: [String, Object],
887
961
  default: "div"
888
- }
962
+ },
963
+ include: {
964
+ type: RegExp,
965
+ default: () => /^on([A-Z])/
966
+ },
967
+ exclude: RegExp
889
968
  };
890
969
 
891
- /** @jsxImportSource vue */
970
+ const COMPONENT_NAME$1l = "vc-debounce";
971
+ const Debounce = defineComponent({
972
+ name: COMPONENT_NAME$1l,
973
+ props: props$1a,
974
+ /**
975
+ * 不声明emits使得事件被透传放入attrs中, 这样可以让所有的事件透传
976
+ * 如事件onClick
977
+ * 当inheritAttrs为true时:因为emits为声明onClick会覆盖到`props.tag`上,使得我们重写的onClick无效
978
+ * 当inheritAttrs为false时: 透传的onClick不会被重载,这样我们就可以重写onClick
979
+ */
980
+ inheritAttrs: false,
981
+ setup(props, { slots, attrs }) {
982
+ const listener = ref({});
983
+ watch(
984
+ [() => props.wait, () => props.exclude, () => props.include],
985
+ () => {
986
+ const { wait, exclude, include } = props;
987
+ const ons = Object.entries(attrs).reduce((pre, [key, callback]) => {
988
+ /* istanbul ignore else -- @preserve */
989
+ if ((!exclude || !exclude.test(key)) && (!include || include.test(key)) && typeof callback === "function") {
990
+ pre[key] = debounce(callback, wait, {
991
+ leading: true,
992
+ trailing: false
993
+ });
994
+ }
995
+ return pre;
996
+ }, {});
997
+ if (Object.keys(listener.value).length !== Object.keys(ons).length) {
998
+ listener.value = ons;
999
+ }
1000
+ },
1001
+ {
1002
+ immediate: true
1003
+ }
1004
+ );
1005
+ return () => {
1006
+ return h(props.tag, {
1007
+ ...attrs,
1008
+ ...listener.value
1009
+ }, slots.default?.());
1010
+ };
1011
+ }
1012
+ });
892
1013
 
893
- const COMPONENT_NAME$1c = 'vc-divider';
894
- const Divider = /* @__PURE__ */ defineComponent({
895
- name: COMPONENT_NAME$1c,
896
- props: props$Y,
1014
+ const props$19 = {
1015
+ tag: {
1016
+ type: String,
1017
+ default: "button"
1018
+ },
1019
+ type: {
1020
+ type: String,
1021
+ default: "default"
1022
+ },
1023
+ size: {
1024
+ type: String,
1025
+ default: "medium"
1026
+ },
1027
+ wait: {
1028
+ type: Number,
1029
+ default: 250
1030
+ },
1031
+ icon: String,
1032
+ disabled: Boolean,
1033
+ circle: Boolean,
1034
+ round: Boolean,
1035
+ long: Boolean,
1036
+ htmlType: {
1037
+ type: String,
1038
+ default: "button"
1039
+ }
1040
+ };
1041
+
1042
+ /** @jsxImportSource vue */
1043
+
1044
+ const COMPONENT_NAME$1k = 'vc-button';
1045
+ const Button = /* @__PURE__ */ defineComponent({
1046
+ name: COMPONENT_NAME$1k,
1047
+ emits: ['click'],
1048
+ props: props$19,
897
1049
  setup(props, {
898
1050
  slots
899
1051
  }) {
1052
+ const vm = getCurrentInstance();
1053
+ const hasSlot = ref(true);
1054
+ const isLoading = ref(false);
1055
+ const group = inject('button-group', {
1056
+ size: 'medium',
1057
+ vertical: false,
1058
+ circle: false
1059
+ });
1060
+ const classes = computed(() => ({
1061
+ 'is-circle': props.circle || group.circle,
1062
+ 'is-alone': !hasSlot.value,
1063
+ 'is-round': props.round,
1064
+ 'is-long': props.long,
1065
+ 'is-disabled': props.disabled,
1066
+ [`is-${props.size}`]: true,
1067
+ [`is-${props.type}`]: true
1068
+ }));
1069
+ const handleClick = (...args) => {
1070
+ const fn = vm.vnode.props?.['onClick']?.(...args);
1071
+ if (fn && fn.then) {
1072
+ isLoading.value = true;
1073
+ fn.finally(() => {
1074
+ isLoading.value = false;
1075
+ });
1076
+ }
1077
+ };
1078
+ onMounted(() => {
1079
+ hasSlot.value = slots.default !== undefined;
1080
+ });
900
1081
  return () => {
901
- return createVNode("div", {
902
- "class": "vc-divider"
1082
+ return createVNode(Debounce, {
1083
+ "tag": props.tag,
1084
+ "class": {
1085
+ 'vc-button': true,
1086
+ ...classes.value
1087
+ },
1088
+ "wait": props.wait,
1089
+ "disabled": props.disabled,
1090
+ "type": props.htmlType,
1091
+ "onClick": handleClick
1092
+ }, {
1093
+ default: () => [props.icon && createVNode(Icon, {
1094
+ "type": props.icon
1095
+ }, null), isLoading.value && createVNode(Spin, {
1096
+ "size": 12,
1097
+ "foreground": props.type === 'default' ? '#ccc' : '#fff',
1098
+ "class": "vc-button__loading"
1099
+ }, null), hasSlot.value && createVNode("span", null, [slots?.default?.()])]
1100
+ });
1101
+ };
1102
+ }
1103
+ });
1104
+
1105
+ const props$18 = {
1106
+ vertical: {
1107
+ type: Boolean,
1108
+ default: false
1109
+ },
1110
+ circle: {
1111
+ type: Boolean,
1112
+ default: false
1113
+ },
1114
+ size: {
1115
+ type: String,
1116
+ default: "medium"
1117
+ },
1118
+ fragment: {
1119
+ type: Boolean,
1120
+ default: false
1121
+ }
1122
+ };
1123
+
1124
+ /** @jsxImportSource vue */
1125
+
1126
+ const COMPONENT_NAME$1j = 'vc-button-group';
1127
+ const ButtonGroup = /* @__PURE__ */ defineComponent({
1128
+ name: COMPONENT_NAME$1j,
1129
+ props: props$18,
1130
+ setup(props, {
1131
+ slots
1132
+ }) {
1133
+ provide('button-group', props);
1134
+ const classes = computed(() => ({
1135
+ 'is-vertical': props.vertical,
1136
+ 'is-circle': props.circle,
1137
+ [`is-${props.size}`]: !!props.size
1138
+ }));
1139
+ return () => {
1140
+ return props.fragment ? slots?.default?.() : createVNode("div", {
1141
+ "class": {
1142
+ 'vc-button-group': true,
1143
+ ...classes.value
1144
+ }
903
1145
  }, [slots?.default?.()]);
904
1146
  };
905
1147
  }
906
1148
  });
907
1149
 
908
- const MDivider = Divider;
1150
+ const MButton = Button;
1151
+ const MButtonGroup = ButtonGroup;
909
1152
 
910
- const props$X = {
1153
+ const props$17 = {
911
1154
  tag: {
912
1155
  type: String,
913
1156
  default: "div"
@@ -916,24 +1159,76 @@ const props$X = {
916
1159
 
917
1160
  /** @jsxImportSource vue */
918
1161
 
919
- const COMPONENT_NAME$1b = 'vc-drawer';
920
- const Drawer = /* @__PURE__ */ defineComponent({
921
- name: COMPONENT_NAME$1b,
922
- props: props$X,
1162
+ const COMPONENT_NAME$1i = 'vc-calendar';
1163
+ const Calendar = /* @__PURE__ */ defineComponent({
1164
+ name: COMPONENT_NAME$1i,
1165
+ props: props$17,
923
1166
  setup(props, {
924
1167
  slots
925
1168
  }) {
926
1169
  return () => {
927
1170
  return createVNode("div", {
928
- "class": "vc-drawer"
1171
+ "class": "vc-calendar"
929
1172
  }, [slots?.default?.()]);
930
1173
  };
931
1174
  }
932
1175
  });
933
1176
 
934
- const MDrawer = Drawer;
1177
+ const MCalendar = Calendar;
935
1178
 
936
- const props$W = {
1179
+ const props$16 = {
1180
+ border: {
1181
+ type: Boolean,
1182
+ default: true
1183
+ },
1184
+ shadow: {
1185
+ type: Boolean,
1186
+ default: false
1187
+ },
1188
+ padding: {
1189
+ type: Number,
1190
+ default: 16
1191
+ },
1192
+ title: {
1193
+ type: String
1194
+ },
1195
+ icon: {
1196
+ type: String
1197
+ }
1198
+ };
1199
+
1200
+ /** @jsxImportSource vue */
1201
+
1202
+ const COMPONENT_NAME$1h = 'vc-card';
1203
+ const Card = /* @__PURE__ */ defineComponent({
1204
+ name: COMPONENT_NAME$1h,
1205
+ props: props$16,
1206
+ setup(props, {
1207
+ slots
1208
+ }) {
1209
+ return () => {
1210
+ return createVNode("div", {
1211
+ "class": [{
1212
+ 'is-border': props.border,
1213
+ 'is-shadow': props.shadow
1214
+ }, 'vc-card']
1215
+ }, [(props.title || slots.title) && createVNode("div", {
1216
+ "class": "vc-card__header"
1217
+ }, [slots.title ? slots.title?.() : props.title && createVNode("p", null, [props.icon && createVNode(Icon, {
1218
+ "type": props.icon
1219
+ }, null), createVNode("span", null, [props.title])])]), slots.extra && createVNode("div", {
1220
+ "class": "vc-card__extra"
1221
+ }, [slots.extra?.()]), createVNode("div", {
1222
+ "style": `padding: ${props.padding}px`,
1223
+ "class": "vc-card__body"
1224
+ }, [slots.default?.()])]);
1225
+ };
1226
+ }
1227
+ });
1228
+
1229
+ const MCard = Card;
1230
+
1231
+ const props$15 = {
937
1232
  tag: {
938
1233
  type: String,
939
1234
  default: "div"
@@ -942,24 +1237,24 @@ const props$W = {
942
1237
 
943
1238
  /** @jsxImportSource vue */
944
1239
 
945
- const COMPONENT_NAME$1a = 'vc-dropdown';
946
- const Dropdown = /* @__PURE__ */ defineComponent({
947
- name: COMPONENT_NAME$1a,
948
- props: props$W,
1240
+ const COMPONENT_NAME$1g = 'vc-carousel';
1241
+ const Carousel = /* @__PURE__ */ defineComponent({
1242
+ name: COMPONENT_NAME$1g,
1243
+ props: props$15,
949
1244
  setup(props, {
950
1245
  slots
951
1246
  }) {
952
1247
  return () => {
953
1248
  return createVNode("div", {
954
- "class": "vc-dropdown"
1249
+ "class": "vc-carousel"
955
1250
  }, [slots?.default?.()]);
956
1251
  };
957
1252
  }
958
1253
  });
959
1254
 
960
- const MDropdown = Dropdown;
1255
+ const MCarousel = Carousel;
961
1256
 
962
- const props$V = {
1257
+ const props$14 = {
963
1258
  tag: {
964
1259
  type: String,
965
1260
  default: "div"
@@ -968,24 +1263,24 @@ const props$V = {
968
1263
 
969
1264
  /** @jsxImportSource vue */
970
1265
 
971
- const COMPONENT_NAME$19 = 'vc-editor';
972
- const Editor = /* @__PURE__ */ defineComponent({
973
- name: COMPONENT_NAME$19,
974
- props: props$V,
1266
+ const COMPONENT_NAME$1f = 'vc-cascader';
1267
+ const Cascader = /* @__PURE__ */ defineComponent({
1268
+ name: COMPONENT_NAME$1f,
1269
+ props: props$14,
975
1270
  setup(props, {
976
1271
  slots
977
1272
  }) {
978
1273
  return () => {
979
1274
  return createVNode("div", {
980
- "class": "vc-editor"
1275
+ "class": "vc-cascader"
981
1276
  }, [slots?.default?.()]);
982
1277
  };
983
1278
  }
984
1279
  });
985
1280
 
986
- const MEditor = Editor;
1281
+ const MCascader = Cascader;
987
1282
 
988
- const props$U = {
1283
+ const props$13 = {
989
1284
  tag: {
990
1285
  type: String,
991
1286
  default: "div"
@@ -994,767 +1289,468 @@ const props$U = {
994
1289
 
995
1290
  /** @jsxImportSource vue */
996
1291
 
997
- const COMPONENT_NAME$18 = 'vc-expand';
998
- const Expand = /* @__PURE__ */ defineComponent({
999
- name: COMPONENT_NAME$18,
1000
- props: props$U,
1292
+ const COMPONENT_NAME$1e = 'vc-chart';
1293
+ const Chart = /* @__PURE__ */ defineComponent({
1294
+ name: COMPONENT_NAME$1e,
1295
+ props: props$13,
1001
1296
  setup(props, {
1002
1297
  slots
1003
1298
  }) {
1004
1299
  return () => {
1005
1300
  return createVNode("div", {
1006
- "class": "vc-expand"
1301
+ "class": "vc-chart"
1007
1302
  }, [slots?.default?.()]);
1008
1303
  };
1009
1304
  }
1010
1305
  });
1011
1306
 
1012
- const MExpand = Expand;
1307
+ const MChart = Chart;
1013
1308
 
1014
- const props$T = {
1309
+ const props$12 = {
1015
1310
  tag: {
1016
1311
  type: String,
1017
- default: "form"
1018
- },
1019
- model: {
1020
- type: Object
1021
- },
1022
- rules: {
1023
- type: Object
1024
- },
1025
- labelWidth: {
1026
- type: Number
1027
- },
1028
- showMessage: {
1029
- type: Boolean,
1030
- default: true
1031
- },
1032
- inline: {
1033
- type: Boolean,
1034
- default: false
1035
- },
1036
- labelPosition: {
1037
- type: String,
1038
- default: "right"
1039
- },
1040
- autocomplete: {
1041
- type: String,
1042
- default: "off"
1043
- },
1044
- styleless: {
1045
- type: Boolean,
1046
- default: false
1312
+ default: "div"
1047
1313
  }
1048
1314
  };
1049
1315
 
1050
- const useForm = (expose, options = {}) => {
1051
- const instance = getCurrentInstance();
1052
- const props = instance.props;
1053
- const fields = [];
1054
- provide("form", {
1055
- props,
1056
- add: (field) => {
1057
- field && fields.push(field);
1058
- },
1059
- remove: (field) => {
1060
- field && fields.splice(fields.indexOf(field), 1);
1061
- }
1062
- });
1063
- const filterFields = (fields$) => {
1064
- return !fields$ ? fields : fields.filter((item) => fields$.includes(item.props.prop));
1065
- };
1066
- const getField = (prop) => {
1067
- const field = fields.find((item) => item.props.prop === prop);
1068
- if (!field) throw new VcError("form", "请选择有用的prop值");
1069
- return field;
1070
- };
1071
- const showToast = (msg) => {
1072
- props.showMessage && options.throwToast?.(msg);
1073
- };
1074
- const sortErrors = async (errors) => {
1075
- const positions = await Promise.all(fields.map((item) => item.exposed.getPosition()));
1076
- try {
1077
- return [...errors].toSorted((a, b) => {
1078
- const aIndex = fields.findIndex((i) => i.props.prop === a.prop);
1079
- const bIndex = fields.findIndex((i) => i.props.prop === b.prop);
1080
- const aPosition = positions[aIndex];
1081
- const bPosition = positions[bIndex];
1082
- if (aPosition.top != bPosition.top) return aPosition.top - bPosition.top;
1083
- return aPosition.left - bPosition.left;
1084
- });
1085
- } catch (e) {
1086
- return errors;
1087
- }
1088
- };
1089
- const scrollIntoView = (prop) => {
1090
- const field = getField(prop);
1091
- field.vnode?.el?.scrollIntoView?.({
1092
- behavior: "smooth",
1093
- block: "center"
1094
- });
1095
- };
1096
- const reset = (options$ = {}) => {
1097
- const { fields: fields$, original = {} } = options$;
1098
- filterFields(fields$).forEach((field) => {
1099
- let v;
1100
- try {
1101
- v = getPropByPath(original, field.props.prop).v;
1102
- } catch (e) {
1103
- }
1104
- field.exposed.reset(v);
1105
- });
1106
- };
1107
- const validate = async (options$ = {}) => {
1108
- const { scroll = true, fields: fields$ } = options$;
1109
- if (!fields.length) {
1110
- return;
1111
- }
1112
- const results = await Promise.allSettled(
1113
- filterFields(fields$).map((item) => item.exposed.validate(""))
1114
- );
1115
- const originErrors = results.filter((i) => i.status === "rejected").map((i) => i.reason);
1116
- if (!originErrors.length) return;
1117
- const errors = await sortErrors(originErrors);
1118
- showToast(errors[0].msg || errors[0].message);
1119
- scroll && scrollIntoView(errors[0].prop);
1120
- throw errors;
1121
- };
1122
- const validateField = async (prop, options$ = {}) => {
1123
- try {
1124
- await validate({
1125
- ...options$,
1126
- fields: [prop]
1127
- });
1128
- } catch (e) {
1129
- throw e[0];
1130
- }
1131
- };
1132
- expose({
1133
- reset,
1134
- validate,
1135
- // 单个操作
1136
- getField,
1137
- validateField
1138
- });
1139
- };
1316
+ /** @jsxImportSource vue */
1140
1317
 
1141
- const COMPONENT_NAME$17 = "vc-form";
1142
- const Form = defineComponent({
1143
- name: COMPONENT_NAME$17,
1144
- props: props$T,
1145
- setup(props, { slots, expose }) {
1146
- useForm(expose);
1318
+ const COMPONENT_NAME$1d = 'vc-checkbox';
1319
+ const Checkbox = /* @__PURE__ */ defineComponent({
1320
+ name: COMPONENT_NAME$1d,
1321
+ props: props$12,
1322
+ setup(props, {
1323
+ slots
1324
+ }) {
1147
1325
  return () => {
1148
- return h(
1149
- props.tag,
1150
- {
1151
- class: "vc-form",
1152
- autocomplete: props.autocomplete
1153
- },
1154
- slots
1155
- );
1326
+ return createVNode("div", {
1327
+ "class": "vc-checkbox"
1328
+ }, [slots?.default?.()]);
1156
1329
  };
1157
1330
  }
1158
1331
  });
1159
1332
 
1160
- const props$S = {
1161
- label: {
1162
- type: String,
1163
- default: ""
1164
- },
1165
- labelWidth: {
1166
- type: Number
1167
- },
1168
- prop: {
1169
- type: String
1170
- },
1171
- required: {
1172
- type: [Boolean, String],
1173
- default: false
1174
- },
1175
- error: {
1176
- type: String
1177
- },
1178
- rules: {
1179
- type: [Array, Object]
1180
- },
1181
- resetByRulesChanged: {
1182
- type: Boolean,
1183
- default: false
1184
- },
1185
- showMessage: {
1186
- type: Boolean,
1187
- default: true
1188
- },
1189
- labelFor: {
1190
- type: String
1191
- },
1192
- styleless: {
1193
- type: Boolean,
1194
- default: false
1195
- },
1196
- labelPosition: {
1333
+ const MCheckbox = Checkbox;
1334
+
1335
+ const props$11 = {
1336
+ tag: {
1197
1337
  type: String,
1198
- default: "right"
1199
- },
1200
- contentStyle: String
1338
+ default: "div"
1339
+ }
1201
1340
  };
1202
1341
 
1203
- const filterEmpty = (val) => {
1204
- if (val instanceof Array) {
1205
- val = val.filter((i) => i !== "");
1342
+ /** @jsxImportSource vue */
1343
+
1344
+ const COMPONENT_NAME$1c = 'vc-clipboard';
1345
+ const Clipboard = /* @__PURE__ */ defineComponent({
1346
+ name: COMPONENT_NAME$1c,
1347
+ props: props$11,
1348
+ setup(props, {
1349
+ slots
1350
+ }) {
1351
+ return () => {
1352
+ return createVNode("div", {
1353
+ "class": "vc-clipboard"
1354
+ }, [slots?.default?.()]);
1355
+ };
1356
+ }
1357
+ });
1358
+
1359
+ const MClipboard = Clipboard;
1360
+
1361
+ const props$10 = {
1362
+ tag: {
1363
+ type: String,
1364
+ default: "div"
1206
1365
  }
1207
- return val;
1208
- };
1209
- const toRules = (rules) => {
1210
- return rules instanceof Array ? rules : rules ? [rules] : [];
1211
1366
  };
1212
- const useFormItem = (expose) => {
1213
- const form = inject("form");
1214
- const instance = getCurrentInstance();
1215
- const props = instance.props;
1216
- const { slots } = instance;
1217
- if (!form?.props) {
1218
- throw new VcError("form-item", "form-item需要在form内使用");
1367
+
1368
+ /** @jsxImportSource vue */
1369
+
1370
+ const COMPONENT_NAME$1b = 'vc-collapse';
1371
+ const Collapse = /* @__PURE__ */ defineComponent({
1372
+ name: COMPONENT_NAME$1b,
1373
+ props: props$10,
1374
+ setup(props, {
1375
+ slots
1376
+ }) {
1377
+ return () => {
1378
+ return createVNode("div", {
1379
+ "class": "vc-collapse"
1380
+ }, [slots?.default?.()]);
1381
+ };
1219
1382
  }
1220
- const formItem = inject("form-item", {});
1221
- const validateState = ref("");
1222
- const validateMessage = ref("");
1223
- let validateDisabled = false;
1224
- let initialValue;
1225
- const currentRules = computed(() => {
1226
- const formRules = form.props.rules;
1227
- const formItemBindRules = toRules(props.rules);
1228
- let formItemRules = formItemBindRules;
1229
- if (!formItemRules.length && formRules && props.prop) {
1230
- try {
1231
- const key = props.prop.replace(/\.[0-9]+\./g, ".");
1232
- const { v } = getPropByPath(formRules, key);
1233
- formItemRules = toRules(v);
1234
- } catch {
1235
- const rules = formRules[props.prop];
1236
- formItemRules = toRules(rules);
1237
- }
1238
- }
1239
- return formItemRules;
1240
- });
1241
- const isRequired = computed(() => {
1242
- if (!currentRules.value.length) {
1243
- return !!props.required;
1244
- }
1245
- let required = false;
1246
- for (let i = 0; i < currentRules.value.length; i++) {
1247
- const rule = currentRules.value[i];
1248
- required = !!rule.required;
1249
- if (required) break;
1250
- }
1251
- return required;
1252
- });
1253
- const labelPosition = computed(() => {
1254
- return props.labelPosition || form.props.labelPosition;
1255
- });
1256
- const classes = computed(() => {
1257
- return {
1258
- "is-require": isRequired.value,
1259
- "is-error": validateState.value === "error",
1260
- "is-validating": validateState.value === "validating",
1261
- "is-inline": form.props.inline,
1262
- "is-nest": isNest.value,
1263
- [`is-${labelPosition.value}`]: true
1383
+ });
1384
+
1385
+ const MCollapse = Collapse;
1386
+
1387
+ const props$$ = {
1388
+ tag: {
1389
+ type: String,
1390
+ default: "div"
1391
+ }
1392
+ };
1393
+
1394
+ /** @jsxImportSource vue */
1395
+
1396
+ const COMPONENT_NAME$1a = 'vc-color-picker';
1397
+ const ColorPicker = /* @__PURE__ */ defineComponent({
1398
+ name: COMPONENT_NAME$1a,
1399
+ props: props$$,
1400
+ setup(props, {
1401
+ slots
1402
+ }) {
1403
+ return () => {
1404
+ return createVNode("div", {
1405
+ "class": "vc-color-picker"
1406
+ }, [slots?.default?.()]);
1264
1407
  };
1265
- });
1266
- const isNest = computed(() => {
1267
- return !!formItem.change;
1268
- });
1269
- const isNestLast = ref(false);
1270
- const hasLabel = computed(() => {
1271
- return !!props.label || slots.label;
1272
- });
1273
- const labelStyle = computed(() => {
1274
- const labelWidth = props.labelWidth === 0 || props.labelWidth ? props.labelWidth : isNest.value ? 0 : form.props.labelWidth;
1275
- return {
1276
- width: labelPosition.value !== "top" && labelWidth && labelWidth > 0 ? `${labelWidth}px` : "auto",
1277
- textAlign: labelPosition.value === "top" ? "left" : labelPosition.value
1408
+ }
1409
+ });
1410
+
1411
+ const MColorPicker = ColorPicker;
1412
+
1413
+ const props$_ = {
1414
+ tag: {
1415
+ type: String,
1416
+ default: "div"
1417
+ }
1418
+ };
1419
+
1420
+ /** @jsxImportSource vue */
1421
+
1422
+ const COMPONENT_NAME$19 = 'vc-countdown';
1423
+ const Countdown = /* @__PURE__ */ defineComponent({
1424
+ name: COMPONENT_NAME$19,
1425
+ props: props$_,
1426
+ setup(props, {
1427
+ slots
1428
+ }) {
1429
+ return () => {
1430
+ return createVNode("div", {
1431
+ "class": "vc-countdown"
1432
+ }, [slots?.default?.()]);
1278
1433
  };
1279
- });
1280
- const contentStyle = computed(() => {
1281
- const labelWidth = props.labelWidth === 0 || props.labelWidth ? props.labelWidth : form.props.labelWidth;
1282
- return [
1283
- {
1284
- marginLeft: !hasLabel.value && isNest.value ? 0 : labelWidth && labelWidth > 0 ? `${labelWidth}px` : "unset",
1285
- marginBottom: isNest.value && !isNestLast.value ? `20px` : 0
1286
- },
1287
- props.contentStyle
1288
- ];
1289
- });
1290
- const isStyleless = computed(() => {
1291
- return props.styleless || form.props.styleless;
1292
- });
1293
- const fieldValue = computed(() => {
1294
- const model = form.props.model;
1295
- if (!model || !props.prop) {
1296
- return;
1297
- }
1298
- let path = props.prop;
1299
- if (path.includes(":")) {
1300
- path = path.replace(/:/, ".");
1301
- }
1302
- return getPropByPath(model, path).v;
1303
- });
1304
- const showError = computed(() => {
1305
- return validateState.value === "error" && props.showMessage && form.props.showMessage;
1306
- });
1307
- watch(
1308
- () => props.error,
1309
- (v) => {
1310
- validateMessage.value = v || "";
1311
- validateState.value = v === "" ? "" : "error";
1312
- }
1313
- );
1314
- const reset = (v) => {
1315
- validateState.value = "";
1316
- validateMessage.value = "";
1317
- const model = form.props.model;
1318
- if (!props.prop) return;
1319
- const { o, k } = getPropByPath(model, props.prop);
1320
- if (!k) return;
1321
- validateDisabled = true;
1322
- o[k] = v !== null && v !== void 0 ? v : Array.isArray(fieldValue.value) ? [].concat(initialValue) : initialValue;
1323
- };
1324
- const validate = async (trigger) => {
1325
- if (!props.prop) return;
1326
- let rules = currentRules.value.filter((rule) => !rule.trigger || rule.trigger.includes(trigger));
1327
- if (!rules.length) {
1328
- if (!props.required) {
1329
- return;
1330
- } else {
1331
- rules = [{
1332
- required: true,
1333
- message: typeof props.required === "string" ? props.required : void 0
1334
- }];
1335
- }
1336
- }
1337
- validateState.value = "validating";
1338
- const descriptor = {};
1339
- descriptor[props.prop] = rules;
1340
- const validator = new Validator(descriptor);
1341
- const model = {};
1342
- model[props.prop] = filterEmpty(fieldValue.value);
1343
- try {
1344
- await validator.validate(model, { first: false });
1345
- validateState.value = "success";
1346
- validateMessage.value = "";
1347
- } catch (errors) {
1348
- validateState.value = "error";
1349
- validateMessage.value = errors[0].message;
1350
- throw {
1351
- prop: props.prop,
1352
- message: validateMessage.value
1353
- };
1354
- }
1355
- validateDisabled = false;
1356
- };
1357
- const handleFieldBlur = () => {
1358
- if (!props.prop) {
1359
- formItem.blur?.();
1360
- return;
1361
- }
1362
- validate("blur");
1363
- };
1364
- const handleFieldChange = () => {
1365
- if (!props.prop) {
1366
- formItem.change?.();
1367
- return;
1368
- }
1369
- if (validateDisabled) {
1370
- validateDisabled = false;
1371
- return;
1372
- }
1373
- validate("change");
1374
- };
1375
- const getPosition = async () => {
1376
- let el = instance.vnode.el;
1377
- try {
1378
- while (el && !el.getBoundingClientRect) {
1379
- el = el.nextSibling;
1380
- }
1381
- ;
1382
- const rect = el.getBoundingClientRect();
1383
- return {
1384
- top: rect.top,
1385
- left: rect.left
1386
- };
1387
- } catch (e) {
1388
- throw new VcError("form-item", "form-item位置计算错误");
1389
- }
1390
- };
1391
- const fields = reactive([]);
1392
- provide("form-item", {
1393
- fields,
1394
- blur: handleFieldBlur,
1395
- change: handleFieldChange,
1396
- message: validateMessage,
1397
- add: (field) => {
1398
- field && fields.push(field);
1399
- },
1400
- remove: (field) => {
1401
- field && fields.splice(fields.indexOf(field), 1);
1402
- }
1403
- });
1404
- onMounted(() => {
1405
- if (props.prop) {
1406
- form.add?.(instance);
1407
- initialValue = cloneDeep(fieldValue.value);
1408
- }
1409
- formItem.add?.(instance);
1410
- });
1411
- onBeforeUnmount(() => {
1412
- form.remove?.(instance);
1413
- formItem.remove?.(instance);
1414
- });
1415
- watch(
1416
- () => props.rules,
1417
- () => {
1418
- props.resetByRulesChanged && reset();
1419
- }
1420
- );
1421
- watch(
1422
- () => formItem.fields?.length,
1423
- async (v) => {
1424
- if (!isNest.value || !v) return isNestLast.value = false;
1425
- const fields$ = [...toRaw(formItem.fields)];
1426
- const positions = await Promise.all(fields$.map((item) => item.exposed.getPosition()));
1427
- const sortFields = fields$.toSorted((a, b) => {
1428
- const aIndex = fields$.findIndex((i) => i === a);
1429
- const bIndex = fields$.findIndex((i) => i === b);
1430
- const aPosition = positions[aIndex];
1431
- const bPosition = positions[bIndex];
1432
- if (aPosition.top != bPosition.top) return aPosition.top - bPosition.top;
1433
- return aPosition.left - bPosition.left;
1434
- });
1435
- isNestLast.value = sortFields[sortFields.length - 1] === instance;
1436
- }
1437
- );
1438
- expose({
1439
- validate,
1440
- reset,
1441
- getPosition
1442
- });
1443
- return {
1444
- isNest,
1445
- isStyleless,
1446
- isNestLast,
1447
- validateMessage,
1448
- classes,
1449
- labelStyle,
1450
- contentStyle,
1451
- showError,
1452
- labelPosition
1453
- };
1434
+ }
1435
+ });
1436
+
1437
+ const MCountdown = Countdown;
1438
+
1439
+ const props$Z = {
1440
+ render: {
1441
+ type: Function,
1442
+ default: () => null
1443
+ }
1454
1444
  };
1455
1445
 
1456
- const props$R = {
1457
- /**
1458
- * 进入/离开持续时间
1459
- * {enter: 300, leave: 300}
1460
- */
1461
- duration: {
1462
- type: [Number, Object],
1463
- default: 300
1464
- },
1465
- /**
1466
- * 进入/离开延迟时间
1467
- */
1468
- delay: {
1469
- type: [Number, Object],
1470
- default: 0
1471
- },
1472
- /**
1473
- * `transition-group` component.
1474
- */
1475
- group: Boolean,
1476
- /**
1477
- * `transition-group` tag, v3版本默认值无
1478
- */
1446
+ const COMPONENT_NAME$18 = "vc-customer";
1447
+ const Customer = defineComponent({
1448
+ name: COMPONENT_NAME$18,
1449
+ props: props$Z,
1450
+ setup(props, context) {
1451
+ return () => h(() => {
1452
+ return props.render(context.attrs, context);
1453
+ });
1454
+ }
1455
+ });
1456
+
1457
+ const MCustomer = Customer;
1458
+
1459
+ const props$Y = {
1479
1460
  tag: {
1480
1461
  type: String,
1481
- default: void 0
1482
- },
1483
- /**
1484
- * 变换的初始位置, 可以用style代替, 更短~~
1485
- */
1486
- origin: {
1462
+ default: "div"
1463
+ }
1464
+ };
1465
+
1466
+ /** @jsxImportSource vue */
1467
+
1468
+ const COMPONENT_NAME$17 = 'vc-date-picker';
1469
+ const DatePicker = /* @__PURE__ */ defineComponent({
1470
+ name: COMPONENT_NAME$17,
1471
+ props: props$Y,
1472
+ setup(props, {
1473
+ slots
1474
+ }) {
1475
+ return () => {
1476
+ return createVNode("div", {
1477
+ "class": "vc-date-picker"
1478
+ }, [slots?.default?.()]);
1479
+ };
1480
+ }
1481
+ });
1482
+
1483
+ const MDatePicker = DatePicker;
1484
+
1485
+ const props$X = {
1486
+ tag: {
1487
1487
  type: String,
1488
- default: ""
1488
+ default: "div"
1489
+ }
1490
+ };
1491
+
1492
+ /** @jsxImportSource vue */
1493
+
1494
+ const COMPONENT_NAME$16 = 'vc-divider';
1495
+ const Divider = /* @__PURE__ */ defineComponent({
1496
+ name: COMPONENT_NAME$16,
1497
+ props: props$X,
1498
+ setup(props, {
1499
+ slots
1500
+ }) {
1501
+ return () => {
1502
+ return createVNode("div", {
1503
+ "class": "vc-divider"
1504
+ }, [slots?.default?.()]);
1505
+ };
1506
+ }
1507
+ });
1508
+
1509
+ const MDivider = Divider;
1510
+
1511
+ const props$W = {
1512
+ tag: {
1513
+ type: String,
1514
+ default: "div"
1515
+ }
1516
+ };
1517
+
1518
+ /** @jsxImportSource vue */
1519
+
1520
+ const COMPONENT_NAME$15 = 'vc-drawer';
1521
+ const Drawer = /* @__PURE__ */ defineComponent({
1522
+ name: COMPONENT_NAME$15,
1523
+ props: props$W,
1524
+ setup(props, {
1525
+ slots
1526
+ }) {
1527
+ return () => {
1528
+ return createVNode("div", {
1529
+ "class": "vc-drawer"
1530
+ }, [slots?.default?.()]);
1531
+ };
1532
+ }
1533
+ });
1534
+
1535
+ const MDrawer = Drawer;
1536
+
1537
+ const props$V = {
1538
+ tag: {
1539
+ type: String,
1540
+ default: "div"
1541
+ }
1542
+ };
1543
+
1544
+ /** @jsxImportSource vue */
1545
+
1546
+ const COMPONENT_NAME$14 = 'vc-dropdown';
1547
+ const Dropdown = /* @__PURE__ */ defineComponent({
1548
+ name: COMPONENT_NAME$14,
1549
+ props: props$V,
1550
+ setup(props, {
1551
+ slots
1552
+ }) {
1553
+ return () => {
1554
+ return createVNode("div", {
1555
+ "class": "vc-dropdown"
1556
+ }, [slots?.default?.()]);
1557
+ };
1558
+ }
1559
+ });
1560
+
1561
+ const MDropdown = Dropdown;
1562
+
1563
+ const props$U = {
1564
+ tag: {
1565
+ type: String,
1566
+ default: "div"
1567
+ }
1568
+ };
1569
+
1570
+ /** @jsxImportSource vue */
1571
+
1572
+ const COMPONENT_NAME$13 = 'vc-editor';
1573
+ const Editor = /* @__PURE__ */ defineComponent({
1574
+ name: COMPONENT_NAME$13,
1575
+ props: props$U,
1576
+ setup(props, {
1577
+ slots
1578
+ }) {
1579
+ return () => {
1580
+ return createVNode("div", {
1581
+ "class": "vc-editor"
1582
+ }, [slots?.default?.()]);
1583
+ };
1584
+ }
1585
+ });
1586
+
1587
+ const MEditor = Editor;
1588
+
1589
+ const props$T = {
1590
+ tag: {
1591
+ type: String,
1592
+ default: "div"
1593
+ }
1594
+ };
1595
+
1596
+ /** @jsxImportSource vue */
1597
+
1598
+ const COMPONENT_NAME$12 = 'vc-expand';
1599
+ const Expand = /* @__PURE__ */ defineComponent({
1600
+ name: COMPONENT_NAME$12,
1601
+ props: props$T,
1602
+ setup(props, {
1603
+ slots
1604
+ }) {
1605
+ return () => {
1606
+ return createVNode("div", {
1607
+ "class": "vc-expand"
1608
+ }, [slots?.default?.()]);
1609
+ };
1610
+ }
1611
+ });
1612
+
1613
+ const MExpand = Expand;
1614
+
1615
+ const props$S = {
1616
+ tag: {
1617
+ type: String,
1618
+ default: "form"
1489
1619
  },
1490
- /**
1491
- * 在转换期间应用的元素样式。这些样式应用于@beforeEnter和@beforeLeave钩子
1492
- * inheritAttrs必须是false
1493
- */
1494
- style: {
1495
- type: Object,
1496
- default: () => {
1497
- return {
1498
- animationFillMode: "both",
1499
- animationTimingFunction: "ease-out"
1500
- };
1501
- }
1620
+ model: {
1621
+ type: Object
1502
1622
  },
1503
- prefix: {
1623
+ rules: {
1624
+ type: Object
1625
+ },
1626
+ labelWidth: {
1627
+ type: Number
1628
+ },
1629
+ showMessage: {
1630
+ type: Boolean,
1631
+ default: true
1632
+ },
1633
+ inline: {
1634
+ type: Boolean,
1635
+ default: false
1636
+ },
1637
+ labelPosition: {
1504
1638
  type: String,
1505
- default: "vc-transition"
1639
+ default: "right"
1506
1640
  },
1507
- mode: {
1641
+ autocomplete: {
1508
1642
  type: String,
1509
- default: "none"
1643
+ default: "off"
1644
+ },
1645
+ styleless: {
1646
+ type: Boolean,
1647
+ default: false
1510
1648
  }
1511
1649
  };
1512
-
1513
- const trim = (str) => str.trim().replace(/\s+/g, " ");
1514
- const useTransition = () => {
1650
+
1651
+ const useForm = (expose, options = {}) => {
1515
1652
  const instance = getCurrentInstance();
1516
- const attrs = instance.attrs;
1517
1653
  const props = instance.props;
1518
- const Wrapper = computed(() => {
1519
- return props.group ? TransitionGroup : Transition$1;
1520
- });
1521
- const classes = computed(() => {
1522
- const modeClass = props.mode !== "none" ? `is-${props.mode.replace(/-/g, " is-")}` : "";
1523
- return {
1524
- enterActiveClass: trim(`${attrs.enterActiveClass || ""} ${props.prefix} ${modeClass} is-in`),
1525
- leaveActiveClass: trim(`${attrs.leaveActiveClass || ""} ${props.prefix} ${modeClass} is-out`),
1526
- moveClass: props.group ? trim(`${attrs.moveClass || ""} ${props.prefix} ${modeClass} is-move`) : void 0
1527
- };
1528
- });
1529
- const clearStyles = (el) => {
1530
- Object.keys(props.style).forEach((key) => {
1531
- const v = props.style[key];
1532
- v && el.style.removeProperty(
1533
- key.replace(/([A-Z])/g, "-$1").toLowerCase()
1534
- );
1535
- });
1536
- el.style.removeProperty("animation-duration");
1537
- el.style.removeProperty("animation-delay");
1538
- };
1539
- const resetAbsolute = (el) => {
1540
- props.group && (el.style.position = "absolute");
1541
- };
1542
- const resetOrigin = (el) => {
1543
- props.origin && (el.style.transformOrigin = props.origin);
1544
- };
1545
- const resetStyles = (el) => {
1546
- resetOrigin(el);
1547
- Object.keys(props.style).forEach((key) => {
1548
- const v = props.style[key];
1549
- v && (el.style[key] = v);
1550
- });
1551
- };
1552
- const handleBeforeEnter = (el) => {
1553
- const duration = props.duration.enter || props.duration;
1554
- el.style.animationDuration = `${duration}ms`;
1555
- const delay = props.delay.enter || props.delay;
1556
- el.style.animationDelay = `${delay}ms`;
1557
- resetStyles(el);
1558
- attrs.onBeforeEnter?.(el);
1559
- };
1560
- const createNext = (callback, duration) => {
1561
- let hasDone = false;
1562
- return (immediate = true) => {
1563
- if (hasDone) return;
1564
- hasDone = true;
1565
- const done = () => callback?.();
1566
- immediate ? done() : setTimeout(done, duration);
1567
- };
1568
- };
1569
- const handleEnter = async (el, done) => {
1570
- const duration = props.duration.enter || props.duration;
1571
- const next = createNext(done, duration);
1572
- try {
1573
- await attrs.onEnter?.(el, next);
1574
- } finally {
1575
- next(false);
1654
+ const fields = [];
1655
+ provide("form", {
1656
+ props,
1657
+ add: (field) => {
1658
+ field && fields.push(field);
1659
+ },
1660
+ remove: (field) => {
1661
+ field && fields.splice(fields.indexOf(field), 1);
1576
1662
  }
1663
+ });
1664
+ const filterFields = (fields$) => {
1665
+ return !fields$ ? fields : fields.filter((item) => fields$.includes(item.props.prop));
1577
1666
  };
1578
- const handleAfterEnter = (el) => {
1579
- clearStyles(el);
1580
- attrs.onAfterEnter?.(el);
1667
+ const getField = (prop) => {
1668
+ const field = fields.find((item) => item.props.prop === prop);
1669
+ if (!field) throw new VcError("form", "请选择有用的prop值");
1670
+ return field;
1581
1671
  };
1582
- const handleBeforeLeave = (el) => {
1583
- const duration = props.duration.leave || props.duration;
1584
- el.style.animationDuration = `${duration}ms`;
1585
- const delay = props.delay.leave || props.delay;
1586
- el.style.animationDelay = `${delay}ms`;
1587
- resetStyles(el);
1588
- attrs.onBeforeLeave?.(el);
1672
+ const showToast = (msg) => {
1673
+ props.showMessage && options.throwToast?.(msg);
1589
1674
  };
1590
- const handleLeave = async (el, done) => {
1591
- const duration = props.duration.leave || props.duration;
1592
- const next = createNext(done, duration);
1675
+ const sortErrors = async (errors) => {
1676
+ const positions = await Promise.all(fields.map((item) => item.exposed.getPosition()));
1593
1677
  try {
1594
- resetAbsolute(el);
1595
- await attrs.onLeave?.(el, next);
1596
- } finally {
1597
- next(props.group ? true : false);
1598
- }
1599
- };
1600
- const handleAfterLeave = (el) => {
1601
- clearStyles(el);
1602
- attrs.onAfterLeave?.(el);
1603
- };
1604
- return {
1605
- Wrapper,
1606
- resetStyles,
1607
- resetAbsolute,
1608
- classes,
1609
- createNext,
1610
- listeners: {
1611
- onBeforeEnter: handleBeforeEnter,
1612
- onEnter: handleEnter,
1613
- onAfterEnter: handleAfterEnter,
1614
- onBeforeLeave: handleBeforeLeave,
1615
- onLeave: handleLeave,
1616
- onAfterLeave: handleAfterLeave
1678
+ return [...errors].toSorted((a, b) => {
1679
+ const aIndex = fields.findIndex((i) => i.props.prop === a.prop);
1680
+ const bIndex = fields.findIndex((i) => i.props.prop === b.prop);
1681
+ const aPosition = positions[aIndex];
1682
+ const bPosition = positions[bIndex];
1683
+ if (aPosition.top != bPosition.top) return aPosition.top - bPosition.top;
1684
+ return aPosition.left - bPosition.left;
1685
+ });
1686
+ } catch (e) {
1687
+ return errors;
1617
1688
  }
1618
1689
  };
1619
- };
1620
-
1621
- const COMPONENT_NAME$16 = "vc-transition";
1622
- const Transition = defineComponent({
1623
- name: COMPONENT_NAME$16,
1624
- props: props$R,
1625
- // 当不声明emits的情况下,事件存在于attrs中
1626
- inheritAttrs: false,
1627
- setup(props, { slots, attrs }) {
1628
- const { Wrapper, listeners, classes } = useTransition();
1629
- return () => {
1630
- return h(
1631
- Wrapper.value,
1632
- {
1633
- ...attrs,
1634
- ...listeners,
1635
- ...classes.value,
1636
- tag: props.tag
1637
- },
1638
- slots
1639
- );
1640
- };
1641
- }
1642
- });
1643
-
1644
- const COMPONENT_NAME$15 = "vc-transition-collapse";
1645
- const TransitionCollapse = defineComponent({
1646
- name: COMPONENT_NAME$15,
1647
- props: props$R,
1648
- // 当不声明emits的情况下,事件存在于attrs中
1649
- inheritAttrs: false,
1650
- setup(props, { slots, attrs: _attrs }) {
1651
- const attrs = _attrs;
1652
- const { Wrapper, resetStyles, resetAbsolute, createNext } = useTransition();
1653
- const getTransitionStyle = (duration) => {
1654
- const style = `
1655
- ${duration}ms height ease-in-out,
1656
- ${duration}ms padding-top ease-in-out,
1657
- ${duration}ms padding-bottom ease-in-out
1658
- `;
1659
- return style;
1660
- };
1661
- const handleBeforeEnter = (el) => {
1662
- const duration = props.duration.enter || props.duration;
1663
- el.style.transition = getTransitionStyle(duration);
1664
- /* istanbul ignore next -- @preserve */
1665
- if (!el.dataset) {
1666
- el.dataset = {};
1667
- }
1668
- el.dataset.oldPaddingTop = el.style.paddingTop;
1669
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
1670
- el.style.height = "0px";
1671
- el.style.paddingTop = "0px";
1672
- el.style.paddingBottom = "0px";
1673
- resetStyles(el);
1674
- attrs.onBeforeEnter?.(el);
1675
- };
1676
- const handleEnter = async (el, done) => {
1677
- const duration = props.duration.enter || props.duration;
1678
- const next = createNext(done, duration);
1679
- try {
1680
- el.dataset.oldOverflow = el.style.overflow;
1681
- /* istanbul ignore next -- @preserve */
1682
- if (el.scrollHeight !== 0) {
1683
- el.style.height = el.scrollHeight + "px";
1684
- el.style.paddingTop = el.dataset.oldPaddingTop + "px";
1685
- el.style.paddingBottom = el.dataset.oldPaddingBottom + "px";
1686
- } else {
1687
- el.style.height = "";
1688
- el.style.paddingTop = el.dataset.oldPaddingTop + "px";
1689
- el.style.paddingBottom = el.dataset.oldPaddingBottom + "px";
1690
- }
1691
- el.style.overflow = "hidden";
1692
- attrs.onEnter?.(el);
1693
- } finally {
1694
- next(false);
1695
- }
1696
- };
1697
- const handleAfterEnter = (el) => {
1698
- el.style.transition = "";
1699
- el.style.height = "";
1700
- el.style.overflow = el.dataset.oldOverflow || "";
1701
- attrs.onAfterEnter?.(el);
1702
- };
1703
- const handleBeforeLeave = (el) => {
1704
- /* istanbul ignore next -- @preserve */
1705
- if (!el.dataset) {
1706
- el.dataset = {};
1707
- }
1708
- el.dataset.oldPaddingTop = el.style.paddingTop;
1709
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
1710
- el.dataset.oldOverflow = el.style.overflow;
1711
- el.style.height = el.scrollHeight + "px";
1712
- el.style.overflow = "hidden";
1713
- resetStyles(el);
1714
- attrs.onBeforeLeave?.(el);
1715
- };
1716
- const handleLeave = (el, done) => {
1717
- const duration = props.duration.leave || props.duration;
1718
- const next = createNext(done, duration);
1719
- try {
1720
- const leaveDuration = props.duration.leave || props.duration;
1721
- /* istanbul ignore next -- @preserve */
1722
- if (el.scrollHeight !== 0) {
1723
- el.style.transition = getTransitionStyle(leaveDuration);
1724
- el.style.height = "0px";
1725
- el.style.paddingTop = "0px";
1726
- el.style.paddingBottom = "0px";
1727
- }
1728
- resetAbsolute(el);
1729
- attrs.onLeave?.(el);
1730
- } finally {
1731
- next(props.group ? true : false);
1732
- }
1733
- };
1734
- const handleAfterLeave = (el) => {
1735
- el.style.transition = "";
1736
- el.style.height = "";
1737
- el.style.overflow = el.dataset.oldOverflow || "";
1738
- el.style.paddingTop = el.dataset.oldPaddingTop || "";
1739
- el.style.paddingBottom = el.dataset.oldPaddingBottom || "";
1740
- attrs.onAfterLeave?.(el);
1741
- };
1742
- const listeners = {
1743
- onBeforeEnter: handleBeforeEnter,
1744
- onEnter: handleEnter,
1745
- onAfterEnter: handleAfterEnter,
1746
- onBeforeLeave: handleBeforeLeave,
1747
- onLeave: handleLeave,
1748
- onAfterLeave: handleAfterLeave
1749
- };
1690
+ const scrollIntoView = (prop) => {
1691
+ const field = getField(prop);
1692
+ field.vnode?.el?.scrollIntoView?.({
1693
+ behavior: "smooth",
1694
+ block: "center"
1695
+ });
1696
+ };
1697
+ const reset = (options$ = {}) => {
1698
+ const { fields: fields$, original = {} } = options$;
1699
+ filterFields(fields$).forEach((field) => {
1700
+ let v;
1701
+ try {
1702
+ v = getPropByPath(original, field.props.prop).v;
1703
+ } catch (e) {
1704
+ }
1705
+ field.exposed.reset(v);
1706
+ });
1707
+ };
1708
+ const validate = async (options$ = {}) => {
1709
+ const { scroll = true, fields: fields$ } = options$;
1710
+ if (!fields.length) {
1711
+ return;
1712
+ }
1713
+ const results = await Promise.allSettled(
1714
+ filterFields(fields$).map((item) => item.exposed.validate(""))
1715
+ );
1716
+ const originErrors = results.filter((i) => i.status === "rejected").map((i) => i.reason);
1717
+ if (!originErrors.length) return;
1718
+ const errors = await sortErrors(originErrors);
1719
+ showToast(errors[0].msg || errors[0].message);
1720
+ scroll && scrollIntoView(errors[0].prop);
1721
+ throw errors;
1722
+ };
1723
+ const validateField = async (prop, options$ = {}) => {
1724
+ try {
1725
+ await validate({
1726
+ ...options$,
1727
+ fields: [prop]
1728
+ });
1729
+ } catch (e) {
1730
+ throw e[0];
1731
+ }
1732
+ };
1733
+ expose({
1734
+ reset,
1735
+ validate,
1736
+ // 单个操作
1737
+ getField,
1738
+ validateField
1739
+ });
1740
+ };
1741
+
1742
+ const COMPONENT_NAME$11 = "vc-form";
1743
+ const Form = defineComponent({
1744
+ name: COMPONENT_NAME$11,
1745
+ props: props$S,
1746
+ setup(props, { slots, expose }) {
1747
+ useForm(expose);
1750
1748
  return () => {
1751
1749
  return h(
1752
- Wrapper.value,
1750
+ props.tag,
1753
1751
  {
1754
- ...attrs,
1755
- ...listeners,
1756
- tag: props.tag,
1757
- moveClass: props.group ? `${attrs.moveClass || ""} vc-transition-collapse is-move` : void 0
1752
+ class: "vc-form",
1753
+ autocomplete: props.autocomplete
1758
1754
  },
1759
1755
  slots
1760
1756
  );
@@ -1762,175 +1758,308 @@ const TransitionCollapse = defineComponent({
1762
1758
  }
1763
1759
  });
1764
1760
 
1765
- const COMPONENT_NAME$14 = "vc-transition-fade";
1766
- const TransitionFade = defineComponent({
1767
- name: COMPONENT_NAME$14,
1768
- props: {
1769
- ...props$R,
1770
- // inheritAttrs必须是false
1771
- style: {
1772
- type: Object,
1773
- default: () => ({
1774
- animationFillMode: "both",
1775
- animationTimingFunction: void 0
1776
- })
1777
- },
1778
- prefix: {
1779
- type: String,
1780
- default: "vc-transition-fade"
1761
+ const props$R = {
1762
+ label: {
1763
+ type: String,
1764
+ default: ""
1765
+ },
1766
+ labelWidth: {
1767
+ type: Number
1768
+ },
1769
+ prop: {
1770
+ type: String
1771
+ },
1772
+ required: {
1773
+ type: [Boolean, String],
1774
+ default: false
1775
+ },
1776
+ error: {
1777
+ type: String
1778
+ },
1779
+ rules: {
1780
+ type: [Array, Object]
1781
+ },
1782
+ resetByRulesChanged: {
1783
+ type: Boolean,
1784
+ default: false
1785
+ },
1786
+ showMessage: {
1787
+ type: Boolean,
1788
+ default: true
1789
+ },
1790
+ labelFor: {
1791
+ type: String
1792
+ },
1793
+ styleless: {
1794
+ type: Boolean,
1795
+ default: false
1796
+ },
1797
+ labelPosition: {
1798
+ type: String,
1799
+ default: "right"
1800
+ },
1801
+ contentStyle: String
1802
+ };
1803
+
1804
+ const filterEmpty = (val) => {
1805
+ if (val instanceof Array) {
1806
+ val = val.filter((i) => i !== "");
1807
+ }
1808
+ return val;
1809
+ };
1810
+ const toRules = (rules) => {
1811
+ return rules instanceof Array ? rules : rules ? [rules] : [];
1812
+ };
1813
+ const useFormItem = (expose) => {
1814
+ const form = inject("form");
1815
+ const instance = getCurrentInstance();
1816
+ const props = instance.props;
1817
+ const { slots } = instance;
1818
+ if (!form?.props) {
1819
+ throw new VcError("form-item", "form-item需要在form内使用");
1820
+ }
1821
+ const formItem = inject("form-item", {});
1822
+ const validateState = ref("");
1823
+ const validateMessage = ref("");
1824
+ let validateDisabled = false;
1825
+ let initialValue;
1826
+ const currentRules = computed(() => {
1827
+ const formRules = form.props.rules;
1828
+ const formItemBindRules = toRules(props.rules);
1829
+ let formItemRules = formItemBindRules;
1830
+ if (!formItemRules.length && formRules && props.prop) {
1831
+ try {
1832
+ const key = props.prop.replace(/\.[0-9]+\./g, ".");
1833
+ const { v } = getPropByPath(formRules, key);
1834
+ formItemRules = toRules(v);
1835
+ } catch {
1836
+ const rules = formRules[props.prop];
1837
+ formItemRules = toRules(rules);
1838
+ }
1839
+ }
1840
+ return formItemRules;
1841
+ });
1842
+ const isRequired = computed(() => {
1843
+ if (!currentRules.value.length) {
1844
+ return !!props.required;
1845
+ }
1846
+ let required = false;
1847
+ for (let i = 0; i < currentRules.value.length; i++) {
1848
+ const rule = currentRules.value[i];
1849
+ required = !!rule.required;
1850
+ if (required) break;
1851
+ }
1852
+ return required;
1853
+ });
1854
+ const labelPosition = computed(() => {
1855
+ return props.labelPosition || form.props.labelPosition;
1856
+ });
1857
+ const classes = computed(() => {
1858
+ return {
1859
+ "is-require": isRequired.value,
1860
+ "is-error": validateState.value === "error",
1861
+ "is-validating": validateState.value === "validating",
1862
+ "is-inline": form.props.inline,
1863
+ "is-nest": isNest.value,
1864
+ [`is-${labelPosition.value}`]: true
1865
+ };
1866
+ });
1867
+ const isNest = computed(() => {
1868
+ return !!formItem.change;
1869
+ });
1870
+ const isNestLast = ref(false);
1871
+ const hasLabel = computed(() => {
1872
+ return !!props.label || slots.label;
1873
+ });
1874
+ const labelStyle = computed(() => {
1875
+ const labelWidth = props.labelWidth === 0 || props.labelWidth ? props.labelWidth : isNest.value ? 0 : form.props.labelWidth;
1876
+ return {
1877
+ width: labelPosition.value !== "top" && labelWidth && labelWidth > 0 ? `${labelWidth}px` : "auto",
1878
+ textAlign: labelPosition.value === "top" ? "left" : labelPosition.value
1879
+ };
1880
+ });
1881
+ const contentStyle = computed(() => {
1882
+ const labelWidth = props.labelWidth === 0 || props.labelWidth ? props.labelWidth : form.props.labelWidth;
1883
+ return [
1884
+ {
1885
+ marginLeft: !hasLabel.value && isNest.value ? 0 : labelWidth && labelWidth > 0 ? `${labelWidth}px` : "unset",
1886
+ marginBottom: isNest.value && !isNestLast.value ? `20px` : 0
1887
+ },
1888
+ props.contentStyle
1889
+ ];
1890
+ });
1891
+ const isStyleless = computed(() => {
1892
+ return props.styleless || form.props.styleless;
1893
+ });
1894
+ const fieldValue = computed(() => {
1895
+ const model = form.props.model;
1896
+ if (!model || !props.prop) {
1897
+ return;
1898
+ }
1899
+ let path = props.prop;
1900
+ if (path.includes(":")) {
1901
+ path = path.replace(/:/, ".");
1902
+ }
1903
+ return getPropByPath(model, path).v;
1904
+ });
1905
+ const showError = computed(() => {
1906
+ return validateState.value === "error" && props.showMessage && form.props.showMessage;
1907
+ });
1908
+ watch(
1909
+ () => props.error,
1910
+ (v) => {
1911
+ validateMessage.value = v || "";
1912
+ validateState.value = v === "" ? "" : "error";
1913
+ }
1914
+ );
1915
+ const reset = (v) => {
1916
+ validateState.value = "";
1917
+ validateMessage.value = "";
1918
+ const model = form.props.model;
1919
+ if (!props.prop) return;
1920
+ const { o, k } = getPropByPath(model, props.prop);
1921
+ if (!k) return;
1922
+ validateDisabled = true;
1923
+ o[k] = v !== null && v !== void 0 ? v : Array.isArray(fieldValue.value) ? [].concat(initialValue) : initialValue;
1924
+ };
1925
+ const validate = async (trigger) => {
1926
+ if (!props.prop) return;
1927
+ let rules = currentRules.value.filter((rule) => !rule.trigger || rule.trigger.includes(trigger));
1928
+ if (!rules.length) {
1929
+ if (!props.required) {
1930
+ return;
1931
+ } else {
1932
+ rules = [{
1933
+ required: true,
1934
+ message: typeof props.required === "string" ? props.required : void 0
1935
+ }];
1936
+ }
1937
+ }
1938
+ validateState.value = "validating";
1939
+ const descriptor = {};
1940
+ descriptor[props.prop] = rules;
1941
+ const validator = new Validator(descriptor);
1942
+ const model = {};
1943
+ model[props.prop] = filterEmpty(fieldValue.value);
1944
+ try {
1945
+ await validator.validate(model, { first: false });
1946
+ validateState.value = "success";
1947
+ validateMessage.value = "";
1948
+ } catch (errors) {
1949
+ validateState.value = "error";
1950
+ validateMessage.value = errors[0].message;
1951
+ throw {
1952
+ prop: props.prop,
1953
+ message: validateMessage.value
1954
+ };
1781
1955
  }
1782
- },
1783
- // 当不声明emits的情况下,事件存在于attrs中
1784
- inheritAttrs: false,
1785
- setup(props, { slots, attrs }) {
1786
- const { Wrapper, listeners, classes } = useTransition();
1787
- return () => {
1788
- return h(
1789
- Wrapper.value,
1790
- {
1791
- ...attrs,
1792
- ...listeners,
1793
- ...classes.value,
1794
- tag: props.tag
1795
- },
1796
- slots
1797
- );
1798
- };
1799
- }
1800
- });
1801
-
1802
- const COMPONENT_NAME$13 = "vc-transition-scale";
1803
- const TransitionScale = defineComponent({
1804
- name: COMPONENT_NAME$13,
1805
- props: {
1806
- ...props$R,
1807
- mode: {
1808
- type: String,
1809
- default: "both",
1810
- validator: (v) => /(part|both|y|x|none)/.test(v)
1811
- },
1812
- // inheritAttrs必须是false
1813
- style: {
1814
- type: Object,
1815
- default: () => ({
1816
- animationFillMode: "both",
1817
- animationTimingFunction: void 0
1818
- })
1819
- },
1820
- prefix: {
1821
- type: String,
1822
- default: "vc-transition-scale"
1956
+ validateDisabled = false;
1957
+ };
1958
+ const handleFieldBlur = () => {
1959
+ if (!props.prop) {
1960
+ formItem.blur?.();
1961
+ return;
1823
1962
  }
1824
- },
1825
- // 当不声明emits的情况下,事件存在于attrs中
1826
- inheritAttrs: false,
1827
- setup(props, { slots, attrs }) {
1828
- const { Wrapper, listeners, classes } = useTransition();
1829
- return () => {
1830
- return h(
1831
- Wrapper.value,
1832
- {
1833
- ...attrs,
1834
- ...listeners,
1835
- ...classes.value,
1836
- tag: props.tag
1837
- },
1838
- slots
1839
- );
1840
- };
1841
- }
1842
- });
1843
-
1844
- const COMPONENT_NAME$12 = "vc-transition-slide";
1845
- const TransitionSlide = defineComponent({
1846
- name: COMPONENT_NAME$12,
1847
- props: {
1848
- ...props$R,
1849
- mode: {
1850
- type: String,
1851
- default: "left",
1852
- validator: (v) => /^(left|right|down|up|none)(|-part)$/.test(v)
1853
- },
1854
- // inheritAttrs必须是false
1855
- style: {
1856
- type: Object,
1857
- default: () => ({
1858
- animationFillMode: "both",
1859
- animationTimingFunction: void 0
1860
- })
1861
- },
1862
- prefix: {
1863
- type: String,
1864
- default: "vc-transition-slide"
1963
+ validate("blur");
1964
+ };
1965
+ const handleFieldChange = () => {
1966
+ if (!props.prop) {
1967
+ formItem.change?.();
1968
+ return;
1865
1969
  }
1866
- },
1867
- // 当不声明emits的情况下,事件存在于attrs中
1868
- inheritAttrs: false,
1869
- setup(props, { slots, attrs }) {
1870
- const { Wrapper, listeners, classes } = useTransition();
1871
- return () => {
1872
- return h(
1873
- Wrapper.value,
1874
- {
1875
- ...attrs,
1876
- ...listeners,
1877
- ...classes.value,
1878
- tag: props.tag
1879
- },
1880
- slots
1881
- );
1882
- };
1883
- }
1884
- });
1885
-
1886
- const COMPONENT_NAME$11 = "vc-transition-zoom";
1887
- const TransitionZoom = defineComponent({
1888
- name: COMPONENT_NAME$11,
1889
- props: {
1890
- ...props$R,
1891
- mode: {
1892
- type: String,
1893
- default: "x",
1894
- validator: (v) => /^(x|y|center|none)$/.test(v)
1895
- },
1896
- // inheritAttrs必须是false
1897
- style: {
1898
- type: Object,
1899
- default: () => ({
1900
- animationFillMode: "both",
1901
- animationTimingFunction: void 0
1902
- })
1970
+ if (validateDisabled) {
1971
+ validateDisabled = false;
1972
+ return;
1973
+ }
1974
+ validate("change");
1975
+ };
1976
+ const getPosition = async () => {
1977
+ let el = instance.vnode.el;
1978
+ try {
1979
+ while (el && !el.getBoundingClientRect) {
1980
+ el = el.nextSibling;
1981
+ }
1982
+ ;
1983
+ const rect = el.getBoundingClientRect();
1984
+ return {
1985
+ top: rect.top,
1986
+ left: rect.left
1987
+ };
1988
+ } catch (e) {
1989
+ throw new VcError("form-item", "form-item位置计算错误");
1990
+ }
1991
+ };
1992
+ const fields = reactive([]);
1993
+ provide("form-item", {
1994
+ fields,
1995
+ blur: handleFieldBlur,
1996
+ change: handleFieldChange,
1997
+ message: validateMessage,
1998
+ add: (field) => {
1999
+ field && fields.push(field);
1903
2000
  },
1904
- prefix: {
1905
- type: String,
1906
- default: "vc-transition-zoom"
2001
+ remove: (field) => {
2002
+ field && fields.splice(fields.indexOf(field), 1);
1907
2003
  }
1908
- },
1909
- // 当不声明emits的情况下,事件存在于attrs中
1910
- inheritAttrs: false,
1911
- setup(props, { slots, attrs }) {
1912
- const { Wrapper, listeners, classes } = useTransition();
1913
- return () => {
1914
- return h(
1915
- Wrapper.value,
1916
- {
1917
- ...attrs,
1918
- ...listeners,
1919
- ...classes.value,
1920
- tag: props.tag
1921
- },
1922
- slots
1923
- );
1924
- };
1925
- }
1926
- });
2004
+ });
2005
+ onMounted(() => {
2006
+ if (props.prop) {
2007
+ form.add?.(instance);
2008
+ initialValue = cloneDeep(fieldValue.value);
2009
+ }
2010
+ formItem.add?.(instance);
2011
+ });
2012
+ onBeforeUnmount(() => {
2013
+ form.remove?.(instance);
2014
+ formItem.remove?.(instance);
2015
+ });
2016
+ watch(
2017
+ () => props.rules,
2018
+ () => {
2019
+ props.resetByRulesChanged && reset();
2020
+ }
2021
+ );
2022
+ watch(
2023
+ () => formItem.fields?.length,
2024
+ async (v) => {
2025
+ if (!isNest.value || !v) return isNestLast.value = false;
2026
+ const fields$ = [...toRaw(formItem.fields)];
2027
+ const positions = await Promise.all(fields$.map((item) => item.exposed.getPosition()));
2028
+ const sortFields = fields$.toSorted((a, b) => {
2029
+ const aIndex = fields$.findIndex((i) => i === a);
2030
+ const bIndex = fields$.findIndex((i) => i === b);
2031
+ const aPosition = positions[aIndex];
2032
+ const bPosition = positions[bIndex];
2033
+ if (aPosition.top != bPosition.top) return aPosition.top - bPosition.top;
2034
+ return aPosition.left - bPosition.left;
2035
+ });
2036
+ isNestLast.value = sortFields[sortFields.length - 1] === instance;
2037
+ }
2038
+ );
2039
+ expose({
2040
+ validate,
2041
+ reset,
2042
+ getPosition
2043
+ });
2044
+ return {
2045
+ isNest,
2046
+ isStyleless,
2047
+ isNestLast,
2048
+ validateMessage,
2049
+ classes,
2050
+ labelStyle,
2051
+ contentStyle,
2052
+ showError,
2053
+ labelPosition
2054
+ };
2055
+ };
1927
2056
 
1928
2057
  /** @jsxImportSource vue */
1929
2058
 
1930
2059
  const COMPONENT_NAME$10 = 'vc-form-item';
1931
2060
  const FormItem = /* @__PURE__ */ defineComponent({
1932
2061
  name: COMPONENT_NAME$10,
1933
- props: props$S,
2062
+ props: props$R,
1934
2063
  setup(props, {
1935
2064
  slots,
1936
2065
  expose
@@ -1983,7 +2112,7 @@ const FormItem = /* @__PURE__ */ defineComponent({
1983
2112
  });
1984
2113
 
1985
2114
  const props$Q = {
1986
- ...props$T,
2115
+ ...props$S,
1987
2116
  showToast: {
1988
2117
  type: Boolean,
1989
2118
  default: false
@@ -2521,7 +2650,7 @@ const MForm = defineComponent({
2521
2650
  });
2522
2651
 
2523
2652
  const props$N = {
2524
- ...props$S,
2653
+ ...props$R,
2525
2654
  indent: {
2526
2655
  type: Number,
2527
2656
  default: 12
@@ -5268,7 +5397,8 @@ const PopoverWrapper = /* @__PURE__ */ defineComponent({
5268
5397
  emits: ['portal-fulfilled', 'close'],
5269
5398
  setup(props, {
5270
5399
  emit,
5271
- slots
5400
+ slots,
5401
+ expose
5272
5402
  }) {
5273
5403
  const {
5274
5404
  getPopupStyle,
@@ -5472,6 +5602,9 @@ const PopoverWrapper = /* @__PURE__ */ defineComponent({
5472
5602
  Resize.off(vnode.el, handleWrapperResize);
5473
5603
  props.alone && props.hover && removeEvents();
5474
5604
  });
5605
+ expose({
5606
+ isActive
5607
+ });
5475
5608
  return () => {
5476
5609
  let _slot;
5477
5610
  return createVNode(TransitionScale, {