@mantine-vue/dates 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.cjs CHANGED
@@ -3313,7 +3313,14 @@ var DateInput_default = /* @__PURE__ */ (0, vue.defineComponent)({
3313
3313
  props: {
3314
3314
  modelValue: {},
3315
3315
  defaultValue: {},
3316
- valueFormat: { default: "MMMM D, YYYY" },
3316
+ valueFormat: {
3317
+ type: [String, Function],
3318
+ default: "MMMM D, YYYY"
3319
+ },
3320
+ withTime: {
3321
+ type: Boolean,
3322
+ default: false
3323
+ },
3317
3324
  dateParser: {},
3318
3325
  locale: {},
3319
3326
  minDate: {},
@@ -3351,14 +3358,22 @@ var DateInput_default = /* @__PURE__ */ (0, vue.defineComponent)({
3351
3358
  emit("change", next);
3352
3359
  }
3353
3360
  });
3354
- const format = (next) => next ? (0, dayjs.default)(next).locale(props.locale || "en").format(props.valueFormat) : "";
3361
+ const format = (next) => next ? typeof props.valueFormat === "function" ? props.valueFormat(toDateString(next)) : (0, dayjs.default)(next).locale(props.locale || "en").format(props.valueFormat) : "";
3355
3362
  const inputValue = (0, vue.ref)(format(value.value));
3356
3363
  const opened = (0, vue.ref)(false);
3357
3364
  (0, vue.watch)(value, (next) => {
3358
3365
  if (!opened.value) inputValue.value = format(next);
3359
3366
  });
3360
3367
  function parse(raw) {
3361
- const parsed = props.dateParser ? props.dateParser(raw) : dateStringParser(raw, props.valueFormat, props.locale);
3368
+ let parsed;
3369
+ if (props.dateParser) parsed = props.dateParser(raw);
3370
+ else if (typeof props.valueFormat === "function") {
3371
+ const value = (0, dayjs.default)(raw);
3372
+ parsed = value.isValid() ? value.format(props.withTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD") : null;
3373
+ } else {
3374
+ const value = (0, dayjs.default)(raw, props.valueFormat, props.locale || "en", true);
3375
+ parsed = value.isValid() ? value.format(props.withTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD") : dateStringParser(raw, props.valueFormat, props.locale);
3376
+ }
3362
3377
  return parsed && isDateValid({
3363
3378
  date: parsed,
3364
3379
  minDate: props.minDate,
@@ -3631,15 +3646,23 @@ var SpinInput_default = /* @__PURE__ */ (0, vue.defineComponent)({
3631
3646
  const props = __props;
3632
3647
  const emit = __emit;
3633
3648
  const attrs = (0, vue.useAttrs)();
3649
+ const inputRef = (0, vue.ref)(null);
3650
+ let emittedValue;
3634
3651
  const [value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
3635
3652
  value: (0, vue.computed)(() => props.modelValue),
3636
3653
  defaultValue: props.defaultValue,
3637
3654
  finalValue: null,
3638
3655
  onChange: (next) => {
3656
+ emittedValue = next;
3639
3657
  emit("update:modelValue", next);
3640
3658
  emit("change", next);
3641
3659
  }
3642
3660
  });
3661
+ (0, vue.watch)(() => props.modelValue, (next) => {
3662
+ const externalChange = next !== emittedValue;
3663
+ emittedValue = void 0;
3664
+ if (externalChange && document.activeElement === inputRef.value) inputRef.value?.select();
3665
+ }, { flush: "post" });
3643
3666
  const finiteMax = () => Number.isFinite(props.max);
3644
3667
  const maxDigit = () => finiteMax() ? Number(props.max.toFixed(0)[0]) : Infinity;
3645
3668
  const arrowsMax = () => props.max + 1 - props.step;
@@ -3708,7 +3731,10 @@ var SpinInput_default = /* @__PURE__ */ (0, vue.defineComponent)({
3708
3731
  event.target.select();
3709
3732
  }
3710
3733
  return (_ctx, _cache) => {
3711
- return (0, vue.openBlock)(), (0, vue.createElementBlock)("input", (0, vue.mergeProps)((0, vue.unref)(attrs), {
3734
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("input", (0, vue.mergeProps)({
3735
+ ref_key: "inputRef",
3736
+ ref: inputRef
3737
+ }, (0, vue.unref)(attrs), {
3712
3738
  type: "text",
3713
3739
  role: "spinbutton",
3714
3740
  "aria-valuemin": props.min,
@@ -4466,7 +4492,10 @@ var MiniCalendar_default = /* @__PURE__ */ (0, vue.defineComponent)({
4466
4492
  maxDate: {},
4467
4493
  minDate: {},
4468
4494
  numberOfDays: { default: 7 },
4469
- monthLabelFormat: { default: "MMM" },
4495
+ monthLabelFormat: {
4496
+ type: [String, Function],
4497
+ default: "MMM"
4498
+ },
4470
4499
  getDayProps: {},
4471
4500
  size: { default: "sm" },
4472
4501
  previousControlProps: {},
@@ -4555,7 +4584,7 @@ var MiniCalendar_default = /* @__PURE__ */ (0, vue.defineComponent)({
4555
4584
  "data-selected": (0, vue.unref)(value) && item.isSame((0, vue.unref)(value), "day") || void 0,
4556
4585
  onClick: ($event) => select(item, $event)
4557
4586
  }), {
4558
- default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("span", { class: (0, vue.normalizeClass)((0, vue.unref)(Dates_module_default).miniCalendarDayMonth) }, (0, vue.toDisplayString)(item.locale(props.locale || (0, vue.unref)(context).locale).format(props.monthLabelFormat)), 3), (0, vue.createElementVNode)("span", { class: (0, vue.normalizeClass)((0, vue.unref)(Dates_module_default).miniCalendarDayNumber) }, (0, vue.toDisplayString)(item.date()), 3)]),
4587
+ default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("span", { class: (0, vue.normalizeClass)((0, vue.unref)(Dates_module_default).miniCalendarDayMonth) }, (0, vue.toDisplayString)(typeof props.monthLabelFormat === "function" ? props.monthLabelFormat(item.format("YYYY-MM-DD")) : item.locale(props.locale || (0, vue.unref)(context).locale).format(props.monthLabelFormat)), 3), (0, vue.createElementVNode)("span", { class: (0, vue.normalizeClass)((0, vue.unref)(Dates_module_default).miniCalendarDayNumber) }, (0, vue.toDisplayString)(item.date()), 3)]),
4559
4588
  _: 2
4560
4589
  }, 1040, [
4561
4590
  "class",