@coreui/vue-pro 4.10.4 → 4.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1041,9 +1041,7 @@ const CCalendar = vue.defineComponent({
1041
1041
  /**
1042
1042
  * Default date of the component
1043
1043
  */
1044
- calendarDate: {
1045
- type: [Date, String],
1046
- },
1044
+ calendarDate: [Date, String],
1047
1045
  /**
1048
1046
  * The number of calendars that render on desktop devices.
1049
1047
  */
@@ -1083,9 +1081,7 @@ const CCalendar = vue.defineComponent({
1083
1081
  /**
1084
1082
  * Initial selected to date (range).
1085
1083
  */
1086
- endDate: {
1087
- type: [Date, String],
1088
- },
1084
+ endDate: [Date, String],
1089
1085
  /**
1090
1086
  * Sets the day of start week.
1091
1087
  * - 0 - Sunday,
@@ -1110,15 +1106,11 @@ const CCalendar = vue.defineComponent({
1110
1106
  /**
1111
1107
  * Max selectable date.
1112
1108
  */
1113
- maxDate: {
1114
- type: [Date, String],
1115
- },
1109
+ maxDate: [Date, String],
1116
1110
  /**
1117
1111
  * Min selectable date.
1118
1112
  */
1119
- minDate: {
1120
- type: [Date, String],
1121
- },
1113
+ minDate: [Date, String],
1122
1114
  /**
1123
1115
  * Show arrows navigation.
1124
1116
  */
@@ -1158,9 +1150,7 @@ const CCalendar = vue.defineComponent({
1158
1150
  /**
1159
1151
  * Initial selected date.
1160
1152
  */
1161
- startDate: {
1162
- type: [Date, String],
1163
- },
1153
+ startDate: [Date, String],
1164
1154
  /**
1165
1155
  * Set length or format of day name.
1166
1156
  *
@@ -1240,13 +1230,15 @@ const CCalendar = vue.defineComponent({
1240
1230
  }
1241
1231
  });
1242
1232
  vue.watch(() => props.maxDate, () => {
1243
- if (props.maxDate) {
1244
- maxDate.value = new Date(props.maxDate);
1233
+ const date = props.maxDate ? new Date(props.maxDate) : null;
1234
+ if (!isSameDateAs(date, maxDate.value)) {
1235
+ maxDate.value = date;
1245
1236
  }
1246
1237
  });
1247
1238
  vue.watch(() => props.minDate, () => {
1248
- if (props.minDate) {
1249
- minDate.value = new Date(props.minDate);
1239
+ const date = props.minDate ? new Date(props.minDate) : null;
1240
+ if (!isSameDateAs(date, minDate.value)) {
1241
+ minDate.value = date;
1250
1242
  }
1251
1243
  });
1252
1244
  vue.watch(() => props.selectEndDate, () => {
@@ -6554,6 +6546,52 @@ const CPickerPlugin = {
6554
6546
  },
6555
6547
  };
6556
6548
 
6549
+ const useDebouncedCallback = (callback, delay) => {
6550
+ const timeout = vue.ref();
6551
+ const debouncedFn = (...args) => {
6552
+ const handler = () => {
6553
+ clearTimeout(timeout.value);
6554
+ callback(...args);
6555
+ };
6556
+ clearTimeout(timeout.value);
6557
+ timeout.value = setTimeout(handler, delay);
6558
+ };
6559
+ return debouncedFn();
6560
+ };
6561
+
6562
+ const useIsVisible = (el) => {
6563
+ const isIntersecting = vue.ref(false);
6564
+ const observer = vue.ref();
6565
+ vue.onMounted(() => {
6566
+ observer.value = new IntersectionObserver(([entry]) => {
6567
+ isIntersecting.value = entry.isIntersecting;
6568
+ });
6569
+ el.value && observer.value.observe(el.value);
6570
+ });
6571
+ vue.onUnmounted(() => {
6572
+ observer.value.disconnect();
6573
+ });
6574
+ return isIntersecting;
6575
+ };
6576
+
6577
+ const usePopper = () => {
6578
+ const _popper = vue.ref();
6579
+ const initPopper = (reference, popper, options) => {
6580
+ _popper.value = createPopper(reference, popper, options);
6581
+ };
6582
+ const destroyPopper = () => {
6583
+ if (_popper.value) {
6584
+ _popper.value.destroy();
6585
+ }
6586
+ _popper.value = undefined;
6587
+ };
6588
+ return {
6589
+ popper: _popper.value,
6590
+ initPopper,
6591
+ destroyPopper,
6592
+ };
6593
+ };
6594
+
6557
6595
  const CTimePickerRollCol = vue.defineComponent({
6558
6596
  name: 'CTimePickerRollCol',
6559
6597
  props: {
@@ -6569,15 +6607,24 @@ const CTimePickerRollCol = vue.defineComponent({
6569
6607
  setup(props, { emit }) {
6570
6608
  const init = vue.ref(true);
6571
6609
  const colRef = vue.ref();
6572
- vue.onUpdated(() => {
6610
+ const isVisible = useIsVisible(colRef);
6611
+ const scrollToSelectedElement = () => {
6573
6612
  const nodeEl = colRef.value?.querySelector('.selected');
6574
- if (nodeEl && nodeEl instanceof HTMLElement) {
6613
+ if (isVisible.value && nodeEl && nodeEl instanceof HTMLElement) {
6575
6614
  colRef.value?.scrollTo({
6576
6615
  top: nodeEl.offsetTop,
6577
6616
  behavior: init.value ? 'auto' : 'smooth',
6578
6617
  });
6579
6618
  }
6580
- init.value = false;
6619
+ };
6620
+ vue.watch(isVisible, () => {
6621
+ scrollToSelectedElement();
6622
+ if (isVisible.value) {
6623
+ init.value = false;
6624
+ }
6625
+ });
6626
+ vue.onUpdated(() => {
6627
+ scrollToSelectedElement();
6581
6628
  });
6582
6629
  const handleKeyDown = (event, value) => {
6583
6630
  if (event.code === 'Space' || event.key === 'Enter') {
@@ -7478,6 +7525,27 @@ const CDateRangePicker = vue.defineComponent({
7478
7525
  type: Boolean,
7479
7526
  default: true,
7480
7527
  },
7528
+ /**
7529
+ * Custom function to format the selected date into a string according to a custom format.
7530
+ *
7531
+ * @since v4.11.0
7532
+ */
7533
+ inputDateFormat: Function,
7534
+ /**
7535
+ * Custom function to parse the input value into a valid Date object.
7536
+ *
7537
+ * @since v4.11.0
7538
+ */
7539
+ inputDateParse: Function,
7540
+ /**
7541
+ * Defines the delay (in milliseconds) for the input field's onChange event.
7542
+ *
7543
+ * @since v4.11.0
7544
+ */
7545
+ inputOnChangeDelay: {
7546
+ type: Number,
7547
+ default: 750,
7548
+ },
7481
7549
  /**
7482
7550
  * Toggle the readonly state for the component.
7483
7551
  */
@@ -7737,8 +7805,8 @@ const CDateRangePicker = vue.defineComponent({
7737
7805
  const endDate = vue.ref(props.endDate ? new Date(props.endDate) : null);
7738
7806
  const initialStartDate = vue.ref(startDate.value ? new Date(startDate.value) : null);
7739
7807
  const initialEndDate = vue.ref(endDate.value ? new Date(endDate.value) : null);
7740
- const maxDate = vue.ref(props.maxDate && new Date(props.maxDate));
7741
- const minDate = vue.ref(props.minDate && new Date(props.minDate));
7808
+ const maxDate = vue.ref(props.maxDate ? new Date(props.maxDate) : null);
7809
+ const minDate = vue.ref(props.minDate ? new Date(props.minDate) : null);
7742
7810
  const selectEndDate = vue.ref(false);
7743
7811
  const isValid = vue.ref(props.valid ?? (props.invalid === true ? false : undefined));
7744
7812
  const isMobile = vue.ref(false);
@@ -7749,28 +7817,18 @@ const CDateRangePicker = vue.defineComponent({
7749
7817
  isValid.value = props.valid ?? (props.invalid === true ? false : undefined);
7750
7818
  });
7751
7819
  vue.watch(() => props.startDate, () => {
7752
- if (props.startDate) {
7753
- const date = new Date(props.startDate);
7754
- calendarDate.value = date;
7755
- startDate.value = date;
7756
- }
7820
+ calendarDate.value = props.startDate ? new Date(props.startDate) : new Date();
7821
+ startDate.value = props.startDate ? new Date(props.startDate) : null;
7757
7822
  });
7758
7823
  vue.watch(() => props.endDate, () => {
7759
- if (props.endDate) {
7760
- const date = new Date(props.endDate);
7761
- calendarDate.value = date;
7762
- endDate.value = date;
7763
- }
7824
+ calendarDate.value = props.endDate ? new Date(props.endDate) : new Date();
7825
+ endDate.value = props.endDate ? new Date(props.endDate) : null;
7764
7826
  });
7765
7827
  vue.watch(() => props.maxDate, () => {
7766
- if (props.maxDate) {
7767
- maxDate.value = new Date(props.maxDate);
7768
- }
7828
+ maxDate.value = props.maxDate ? new Date(props.maxDate) : null;
7769
7829
  });
7770
7830
  vue.watch(() => props.minDate, () => {
7771
- if (props.minDate) {
7772
- minDate.value = new Date(props.minDate);
7773
- }
7831
+ minDate.value = props.minDate ? new Date(props.minDate) : null;
7774
7832
  });
7775
7833
  vue.watch(inputStartRef, () => {
7776
7834
  if (inputStartRef.value && inputStartRef.value.form) {
@@ -7786,11 +7844,13 @@ const CDateRangePicker = vue.defineComponent({
7786
7844
  }
7787
7845
  });
7788
7846
  const formatDate = (date) => {
7789
- return props.format
7790
- ? format(date, props.format)
7791
- : props.timepicker
7792
- ? date.toLocaleString(props.locale)
7793
- : date.toLocaleDateString(props.locale);
7847
+ return props.inputDateFormat
7848
+ ? props.inputDateFormat(date)
7849
+ : props.format
7850
+ ? format(date, props.format)
7851
+ : props.timepicker
7852
+ ? date.toLocaleString(props.locale)
7853
+ : date.toLocaleDateString(props.locale);
7794
7854
  };
7795
7855
  const setInputValue = (date) => {
7796
7856
  if (date) {
@@ -7863,6 +7923,20 @@ const CDateRangePicker = vue.defineComponent({
7863
7923
  emit('update:start-date', null);
7864
7924
  emit('update:end-date', null);
7865
7925
  };
7926
+ const handleOnChange = (value, input) => {
7927
+ const date = props.inputDateParse
7928
+ ? props.inputDateParse(value)
7929
+ : getLocalDateFromString(value, props.locale, props.timepicker);
7930
+ if (date instanceof Date && date.getTime()) {
7931
+ calendarDate.value = date;
7932
+ if (input === 'start') {
7933
+ startDate.value = date;
7934
+ }
7935
+ else {
7936
+ endDate.value = date;
7937
+ }
7938
+ }
7939
+ };
7866
7940
  const InputGroup = () => vue.h('div', {
7867
7941
  class: [
7868
7942
  'input-group',
@@ -7885,13 +7959,8 @@ const CDateRangePicker = vue.defineComponent({
7885
7959
  onClick: () => {
7886
7960
  selectEndDate.value = false;
7887
7961
  },
7888
- onInput: (event) => {
7889
- const date = getLocalDateFromString(event.target.value, props.locale, props.timepicker);
7890
- if (date instanceof Date && date.getTime()) {
7891
- calendarDate.value = date;
7892
- startDate.value = date;
7893
- }
7894
- },
7962
+ onChange: (event) => handleOnChange(event.target.value, 'start'),
7963
+ onInput: (event) => useDebouncedCallback(() => handleOnChange(event.target.value, 'start'), props.inputOnChangeDelay),
7895
7964
  placeholder: Array.isArray(props.placeholder)
7896
7965
  ? props.placeholder[0]
7897
7966
  : props.placeholder,
@@ -7921,13 +7990,8 @@ const CDateRangePicker = vue.defineComponent({
7921
7990
  onClick: () => {
7922
7991
  selectEndDate.value = true;
7923
7992
  },
7924
- onInput: (event) => {
7925
- const date = getLocalDateFromString(event.target.value, props.locale, props.timepicker);
7926
- if (date instanceof Date && date.getTime()) {
7927
- calendarDate.value = date;
7928
- endDate.value = date;
7929
- }
7930
- },
7993
+ onChange: (event) => handleOnChange(event.target.value, 'end'),
7994
+ onInput: (event) => useDebouncedCallback(() => handleOnChange(event.target.value, 'end'), props.inputOnChangeDelay),
7931
7995
  placeholder: props.placeholder[1],
7932
7996
  readonly: props.inputReadOnly || typeof props.format === 'string',
7933
7997
  required: props.required,
@@ -8053,8 +8117,8 @@ const CDateRangePicker = vue.defineComponent({
8053
8117
  ...(endDate.value && { endDate: endDate.value }),
8054
8118
  firstDayOfWeek: props.firstDayOfWeek,
8055
8119
  locale: props.locale,
8056
- maxDate: maxDate.value,
8057
- minDate: minDate.value,
8120
+ ...(maxDate.value && { maxDate: maxDate.value }),
8121
+ ...(minDate.value && { minDate: minDate.value }),
8058
8122
  navYearFirst: props.navYearFirst,
8059
8123
  navigation: props.navigation,
8060
8124
  range: props.range,
@@ -8444,24 +8508,6 @@ const CDatePickerPlugin = {
8444
8508
  },
8445
8509
  };
8446
8510
 
8447
- const usePopper = () => {
8448
- const _popper = vue.ref();
8449
- const initPopper = (reference, popper, options) => {
8450
- _popper.value = createPopper(reference, popper, options);
8451
- };
8452
- const destroyPopper = () => {
8453
- if (_popper.value) {
8454
- _popper.value.destroy();
8455
- }
8456
- _popper.value = undefined;
8457
- };
8458
- return {
8459
- popper: _popper.value,
8460
- initPopper,
8461
- destroyPopper,
8462
- };
8463
- };
8464
-
8465
8511
  const getPlacement = (placement, direction, alignment, isRTL) => {
8466
8512
  let _placement = placement;
8467
8513
  if (direction === 'dropup') {
@@ -11095,7 +11141,7 @@ const CVirtualScroller = vue.defineComponent({
11095
11141
  }),
11096
11142
  },
11097
11143
  ref: (node) => {
11098
- if (node && node.offsetHeight) {
11144
+ if (itemHeight.value === 0 && node && node.offsetHeight) {
11099
11145
  itemHeight.value =
11100
11146
  node.offsetHeight +
11101
11147
  Number.parseFloat(getComputedStyle(node).marginTop) +
@@ -16798,6 +16844,8 @@ exports.CWidgetStatsE = CWidgetStatsE;
16798
16844
  exports.CWidgetStatsF = CWidgetStatsF;
16799
16845
  exports.CWidgetsStatsPlugin = CWidgetsStatsPlugin;
16800
16846
  exports.default = CoreuiVue;
16847
+ exports.useDebouncedCallback = useDebouncedCallback;
16848
+ exports.useIsVisible = useIsVisible;
16801
16849
  exports.usePopper = usePopper;
16802
16850
  exports.vcplaceholder = vCPlaceholder;
16803
16851
  exports.vcpopover = vCPopover;