@mantine-vue/core 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.mjs CHANGED
@@ -8724,21 +8724,21 @@ var AccordionChevron = /* @__PURE__ */ defineComponent({
8724
8724
  //#region src/components/Accordion/Accordion.context.ts
8725
8725
  var [provideAccordionContext, useAccordionContext] = createSafeContext("Accordion component was not found in the tree");
8726
8726
  var Accordion_module_default = {
8727
- root: "_root_ltqd9_1",
8728
- panel: "_panel_ltqd9_5",
8729
- content: "_content_ltqd9_9",
8730
- itemTitle: "_itemTitle_ltqd9_14",
8731
- control: "_control_ltqd9_20",
8732
- "control--default": "_control--default_ltqd9_42",
8733
- "control--contained": "_control--contained_ltqd9_43",
8734
- label: "_label_ltqd9_57",
8735
- chevron: "_chevron_ltqd9_67",
8736
- icon: "_icon_ltqd9_86",
8737
- item: "_item_ltqd9_14",
8738
- "item--default": "_item--default_ltqd9_110",
8739
- "item--contained": "_item--contained_ltqd9_114",
8740
- "item--filled": "_item--filled_ltqd9_147",
8741
- "item--separated": "_item--separated_ltqd9_155"
8727
+ root: "_root_1ysxv_1",
8728
+ panel: "_panel_1ysxv_5",
8729
+ content: "_content_1ysxv_9",
8730
+ itemTitle: "_itemTitle_1ysxv_14",
8731
+ control: "_control_1ysxv_20",
8732
+ "control--default": "_control--default_1ysxv_42",
8733
+ "control--contained": "_control--contained_1ysxv_43",
8734
+ label: "_label_1ysxv_57",
8735
+ chevron: "_chevron_1ysxv_67",
8736
+ icon: "_icon_1ysxv_86",
8737
+ item: "_item_1ysxv_14",
8738
+ "item--default": "_item--default_1ysxv_110",
8739
+ "item--contained": "_item--contained_1ysxv_114",
8740
+ "item--filled": "_item--filled_1ysxv_149",
8741
+ "item--separated": "_item--separated_1ysxv_157"
8742
8742
  };
8743
8743
  //#endregion
8744
8744
  //#region src/components/Accordion/Accordion.vue?vue&type=script&setup=true&lang.ts
@@ -13914,16 +13914,58 @@ function sanitizeNumberInputString(rawValue, allowDecimal, allowNegative, decima
13914
13914
  }
13915
13915
  return normalized;
13916
13916
  }
13917
- function clampAndSanitizeInput(sanitizedValue, max, min) {
13918
- const stringValue = sanitizedValue.toString();
13919
- const hasTrailingDecimalSeparator = trailingDecimalSeparatorPattern.test(stringValue);
13920
- const replaced = stringValue.replace(/^0+(?=\d)/, "");
13921
- const parsedValue = parseFloat(replaced);
13922
- if (Number.isNaN(parsedValue)) return replaced;
13923
- if (parsedValue > Number.MAX_SAFE_INTEGER) return max !== void 0 ? max : replaced;
13924
- const clamped = clamp$3(parsedValue, min, max);
13925
- if (hasTrailingDecimalSeparator) return `${clamped.toString().replace(/^0+(?=\d)/, "")}.`;
13926
- return clamped;
13917
+ function withTrailingSeparator(value, hasTrailingDecimalSeparator) {
13918
+ return hasTrailingDecimalSeparator ? `${value}.` : value;
13919
+ }
13920
+ function sanitizeInputOnBlur(value, options) {
13921
+ const hasTrailingDecimalSeparator = trailingDecimalSeparatorPattern.test(value);
13922
+ const trimmed = options.trim ? value.replace(/^0+(?=\d)/, "") : value;
13923
+ const parsedValue = parseFloat(trimmed);
13924
+ if (Number.isNaN(parsedValue)) return trimmed;
13925
+ if (!options.clamp) return options.trim ? withTrailingSeparator(parsedValue, hasTrailingDecimalSeparator) : value;
13926
+ const clamped = parsedValue > Number.MAX_SAFE_INTEGER && options.max !== void 0 ? options.max : clamp$3(parsedValue, options.min, options.max);
13927
+ if (!options.trim && clamped === parsedValue) return value;
13928
+ return withTrailingSeparator(clamped, hasTrailingDecimalSeparator);
13929
+ }
13930
+ function countTrailingDigits(value, from) {
13931
+ let count = 0;
13932
+ while (from + count < value.length && /\d/.test(value[from + count])) count += 1;
13933
+ return count;
13934
+ }
13935
+ function normalizePastedValue(value, options) {
13936
+ const candidates = new Set([...options.allowedDecimalSeparators, options.decimalSeparator].filter((separator) => separator.length === 1));
13937
+ const chars = value.split("");
13938
+ const occurrences = chars.reduce((result, char, index) => {
13939
+ if (candidates.has(char)) result.push(index);
13940
+ return result;
13941
+ }, []);
13942
+ if (occurrences.length === 0) return value;
13943
+ const lastIndex = occurrences[occurrences.length - 1];
13944
+ const lastChar = chars[lastIndex];
13945
+ const lastCharCount = occurrences.filter((index) => chars[index] === lastChar).length;
13946
+ const lastGroupSize = options.thousandsGroupStyle === "wan" ? 4 : 3;
13947
+ let decimalIndex = -1;
13948
+ if (lastCharCount === 1) if (lastChar === options.decimalSeparator) decimalIndex = lastIndex;
13949
+ else if (lastChar === options.thousandSeparator) decimalIndex = countTrailingDigits(value, lastIndex + 1) === lastGroupSize ? -1 : lastIndex;
13950
+ else decimalIndex = lastIndex;
13951
+ return chars.map((char, index) => {
13952
+ if (index === decimalIndex) return options.decimalSeparator;
13953
+ if (candidates.has(char) && char !== options.thousandSeparator) return "";
13954
+ return char;
13955
+ }).join("");
13956
+ }
13957
+ function isSignificant(char, decimalSeparator) {
13958
+ return /\d/.test(char) || char === decimalSeparator;
13959
+ }
13960
+ function getCaretPositionAfterPaste(rawValue, rawCaret, formattedValue, decimalSeparator) {
13961
+ let remaining = 0;
13962
+ for (let index = 0; index < rawCaret && index < rawValue.length; index += 1) if (isSignificant(rawValue[index], decimalSeparator)) remaining += 1;
13963
+ if (remaining === 0) return Math.min(rawCaret, formattedValue.length);
13964
+ for (let index = 0; index < formattedValue.length; index += 1) if (isSignificant(formattedValue[index], decimalSeparator)) {
13965
+ remaining -= 1;
13966
+ if (remaining === 0) return index + 1;
13967
+ }
13968
+ return formattedValue.length;
13927
13969
  }
13928
13970
  function isInRange(value, min, max) {
13929
13971
  if (value === void 0) return true;
@@ -14376,12 +14418,41 @@ var NumberInput = factory(/* @__PURE__ */ defineComponent({
14376
14418
  if (props.selectAllOnFocus) window.setTimeout(() => inputRef.value?.select(), 0);
14377
14419
  else scheduleCaretClamp(event.currentTarget);
14378
14420
  }
14421
+ function onPaste(event) {
14422
+ const pastedText = event.clipboardData?.getData("text") ?? "";
14423
+ const decimalSeparator = props.decimalSeparator || ".";
14424
+ const modifiedText = normalizePastedValue(pastedText, {
14425
+ decimalSeparator,
14426
+ thousandSeparator: props.thousandSeparator === true ? "," : props.thousandSeparator === false ? void 0 : props.thousandSeparator,
14427
+ allowedDecimalSeparators: props.allowedDecimalSeparators,
14428
+ thousandsGroupStyle: props.thousandsGroupStyle
14429
+ });
14430
+ if (modifiedText !== pastedText && inputRef.value) {
14431
+ event.preventDefault();
14432
+ const input = inputRef.value;
14433
+ const start = input.selectionStart ?? 0;
14434
+ const end = input.selectionEnd ?? 0;
14435
+ const newValue = input.value.slice(0, start) + modifiedText + input.value.slice(end);
14436
+ input.value = newValue;
14437
+ input.dispatchEvent(new Event("input", { bubbles: true }));
14438
+ const rawCaret = start + modifiedText.length;
14439
+ setTimeout(() => {
14440
+ const caret = getCaretPositionAfterPaste(newValue, rawCaret, input.value, decimalSeparator);
14441
+ input.setSelectionRange(caret, caret);
14442
+ }, 0);
14443
+ }
14444
+ }
14379
14445
  function onBlur() {
14380
14446
  let sanitizedValue = value.value;
14381
14447
  const min = typeof props.min === "number" ? props.min : void 0;
14382
14448
  const max = typeof props.max === "number" ? props.max : void 0;
14383
14449
  if (props.clampBehavior === "blur" && typeof sanitizedValue === "number") sanitizedValue = clamp$3(sanitizedValue, min, max);
14384
- if (props.trimLeadingZeroesOnBlur && typeof sanitizedValue === "string" && getDecimalPlaces(sanitizedValue) < 15) sanitizedValue = clampAndSanitizeInput(sanitizedValue, max, min);
14450
+ if (!isBigIntMode.value && typeof sanitizedValue === "string") sanitizedValue = sanitizeInputOnBlur(sanitizedValue, {
14451
+ min,
14452
+ max,
14453
+ trim: props.trimLeadingZeroesOnBlur && getDecimalPlaces(sanitizedValue) < 15,
14454
+ clamp: props.clampBehavior === "blur"
14455
+ });
14385
14456
  if (sanitizedValue !== value.value) commitValue(sanitizedValue, "blur");
14386
14457
  }
14387
14458
  return (_ctx, _cache) => {
@@ -14415,6 +14486,7 @@ var NumberInput = factory(/* @__PURE__ */ defineComponent({
14415
14486
  onKeyup,
14416
14487
  onClick,
14417
14488
  onFocus,
14489
+ onPaste,
14418
14490
  onBlur
14419
14491
  }), createSlots({ _: 2 }, [
14420
14492
  unref(slots).label ? {
@@ -16531,8 +16603,16 @@ var SegmentedControl = Object.assign(/* @__PURE__ */ defineComponent({
16531
16603
  parent.value = node?.$el ?? node ?? null;
16532
16604
  };
16533
16605
  const setItemRef = (key, node) => {
16534
- itemRefs[key] = node?.$el ?? node ?? null;
16606
+ const element = node?.$el ?? node ?? null;
16607
+ if (element === null) delete itemRefs[key];
16608
+ else itemRefs[key] = element;
16535
16609
  };
16610
+ watch(normalizedData, (items) => {
16611
+ const values = new Set(items.map((item) => String(item.value)));
16612
+ Object.keys(itemRefs).forEach((key) => {
16613
+ if (!values.has(key)) delete itemRefs[key];
16614
+ });
16615
+ });
16536
16616
  const ItemLabel = (item) => h("span", getStyles("innerLabel"), resolveNode(item.label));
16537
16617
  const handleClick = (event) => {
16538
16618
  if (props.readOnly) event.preventDefault();
@@ -18273,6 +18353,7 @@ var Autosize_default = /* @__PURE__ */ defineComponent({
18273
18353
  }
18274
18354
  }
18275
18355
  const cleanupFns = [];
18356
+ let resizeFrame = 0;
18276
18357
  onMounted(() => {
18277
18358
  resizeTextarea();
18278
18359
  const onResize = () => resizeTextarea();
@@ -18284,11 +18365,15 @@ var Autosize_default = /* @__PURE__ */ defineComponent({
18284
18365
  const observer = new ResizeObserver(() => {
18285
18366
  if (textareaRef.value && textareaRef.value.offsetWidth !== widthRef.value) {
18286
18367
  widthRef.value = textareaRef.value.offsetWidth;
18287
- resizeTextarea();
18368
+ cancelAnimationFrame(resizeFrame);
18369
+ resizeFrame = requestAnimationFrame(resizeTextarea);
18288
18370
  }
18289
18371
  });
18290
18372
  observer.observe(node);
18291
- cleanupFns.push(() => observer.disconnect());
18373
+ cleanupFns.push(() => {
18374
+ cancelAnimationFrame(resizeFrame);
18375
+ observer.disconnect();
18376
+ });
18292
18377
  }
18293
18378
  const onFontsLoaded = () => resizeTextarea();
18294
18379
  document.fonts.addEventListener("loadingdone", onFontsLoaded);
@@ -18305,6 +18390,7 @@ var Autosize_default = /* @__PURE__ */ defineComponent({
18305
18390
  cleanupFns.push(() => document.body.removeEventListener("reset", onReset));
18306
18391
  });
18307
18392
  onUnmounted(() => {
18393
+ cancelAnimationFrame(resizeFrame);
18308
18394
  cleanupFns.forEach((fn) => fn());
18309
18395
  cleanupFns.length = 0;
18310
18396
  });
@@ -22818,20 +22904,30 @@ function getEl$1(value) {
22818
22904
  function useDimensions(element) {
22819
22905
  const dimensions = ref(null);
22820
22906
  let observer = null;
22907
+ let frame = 0;
22821
22908
  onMounted(() => {
22822
22909
  const el = getEl$1(element.value);
22823
22910
  if (!el || typeof ResizeObserver === "undefined") return;
22824
22911
  observer = new ResizeObserver(([entry]) => {
22825
- if (entry) dimensions.value = {
22826
- width: entry.borderBoxSize?.[0]?.inlineSize ?? entry.target.clientWidth,
22827
- height: entry.borderBoxSize?.[0]?.blockSize ?? entry.target.clientHeight,
22828
- contentWidth: entry.contentRect.width,
22829
- contentHeight: entry.contentRect.height
22830
- };
22912
+ if (entry) {
22913
+ const nextDimensions = {
22914
+ width: entry.borderBoxSize?.[0]?.inlineSize ?? entry.target.clientWidth,
22915
+ height: entry.borderBoxSize?.[0]?.blockSize ?? entry.target.clientHeight,
22916
+ contentWidth: entry.contentRect.width,
22917
+ contentHeight: entry.contentRect.height
22918
+ };
22919
+ cancelAnimationFrame(frame);
22920
+ frame = requestAnimationFrame(() => {
22921
+ dimensions.value = nextDimensions;
22922
+ });
22923
+ }
22831
22924
  });
22832
22925
  observer.observe(el);
22833
22926
  });
22834
- onBeforeUnmount(() => observer?.disconnect());
22927
+ onBeforeUnmount(() => {
22928
+ cancelAnimationFrame(frame);
22929
+ observer?.disconnect();
22930
+ });
22835
22931
  return dimensions;
22836
22932
  }
22837
22933
  var OverflowList_module_default = { root: "_root_uggjd_1" };
@@ -28260,7 +28356,10 @@ function useModal(input) {
28260
28356
  const bodyMounted = ref(false);
28261
28357
  useWindowEvent("keydown", (event) => {
28262
28358
  const stopped = event.target?.getAttribute?.("data-mantine-stop-propagation") === "true";
28263
- if (event.key === "Escape" && !event.isComposing && input.opened() && input.closeOnEscape() && !stopped) input.onClose();
28359
+ if (event.key === "Escape" && !event.isComposing && input.opened() && input.closeOnEscape() && !input.handledEscapeEvents?.has(event) && !stopped) {
28360
+ input.handledEscapeEvents?.add(event);
28361
+ input.onClose();
28362
+ }
28264
28363
  }, { capture: true });
28265
28364
  useFocusReturn({
28266
28365
  opened: input.opened,
@@ -28279,6 +28378,7 @@ var ModalBase = factory(/* @__PURE__ */ defineComponent({
28279
28378
  inheritAttrs: false,
28280
28379
  __name: "ModalBase",
28281
28380
  props: {
28381
+ __handledEscapeEvents: {},
28282
28382
  rootRef: {},
28283
28383
  opened: { type: Boolean },
28284
28384
  id: { default: void 0 },
@@ -28340,7 +28440,8 @@ var ModalBase = factory(/* @__PURE__ */ defineComponent({
28340
28440
  onClose: () => emit("close"),
28341
28441
  trapFocus: () => props.trapFocus,
28342
28442
  closeOnEscape: () => props.closeOnEscape,
28343
- returnFocus: () => props.returnFocus
28443
+ returnFocus: () => props.returnFocus,
28444
+ handledEscapeEvents: props.__handledEscapeEvents
28344
28445
  });
28345
28446
  useLockScroll(computed(() => props.opened && props.lockScroll));
28346
28447
  provideModalBaseContext({
@@ -28771,6 +28872,7 @@ var ModalRoot_default = /* @__PURE__ */ defineComponent({
28771
28872
  classNames: {},
28772
28873
  styles: {},
28773
28874
  vars: {},
28875
+ __handledEscapeEvents: {},
28774
28876
  rootRef: {},
28775
28877
  opened: { type: Boolean },
28776
28878
  id: {},
@@ -28934,6 +29036,7 @@ var Modal_default = /* @__PURE__ */ defineComponent({
28934
29036
  classNames: {},
28935
29037
  styles: {},
28936
29038
  vars: {},
29039
+ __handledEscapeEvents: {},
28937
29040
  rootRef: {},
28938
29041
  opened: { type: Boolean },
28939
29042
  id: {},
@@ -29156,6 +29259,7 @@ var DrawerRoot_default = /* @__PURE__ */ defineComponent({
29156
29259
  offset: { default: 0 },
29157
29260
  size: { default: "md" },
29158
29261
  scrollAreaComponent: {},
29262
+ __handledEscapeEvents: {},
29159
29263
  rootRef: {},
29160
29264
  opened: { type: Boolean },
29161
29265
  id: {},
@@ -29319,6 +29423,7 @@ var Drawer_default = /* @__PURE__ */ defineComponent({
29319
29423
  offset: {},
29320
29424
  size: {},
29321
29425
  scrollAreaComponent: {},
29426
+ __handledEscapeEvents: {},
29322
29427
  rootRef: {},
29323
29428
  opened: { type: Boolean },
29324
29429
  id: {},
@@ -29390,7 +29495,8 @@ var Drawer_default = /* @__PURE__ */ defineComponent({
29390
29495
  const isCurrent = stackCtx.currentId === props.stackId;
29391
29496
  return {
29392
29497
  closeOnEscape: isCurrent,
29393
- trapFocus: isCurrent
29498
+ trapFocus: isCurrent,
29499
+ __handledEscapeEvents: stackCtx.handledEscapeEvents
29394
29500
  };
29395
29501
  });
29396
29502
  /** One overlay for the whole stack: only the topmost drawer renders it. */
@@ -29495,7 +29601,8 @@ var DrawerStack_default = /* @__PURE__ */ defineComponent({
29495
29601
  },
29496
29602
  get maxZIndex() {
29497
29603
  return maxZIndex.value;
29498
- }
29604
+ },
29605
+ handledEscapeEvents: /* @__PURE__ */ new WeakSet()
29499
29606
  }));
29500
29607
  return (_ctx, _cache) => {
29501
29608
  return renderSlot(_ctx.$slots, "default");
@@ -32241,6 +32348,8 @@ var MenuSub_default = /* @__PURE__ */ defineComponent({
32241
32348
  inheritAttrs: false,
32242
32349
  __name: "MenuSub",
32243
32350
  props: {
32351
+ withinPortal: {},
32352
+ portalProps: {},
32244
32353
  opened: {
32245
32354
  type: Boolean,
32246
32355
  default: void 0
@@ -32274,7 +32383,7 @@ var MenuSub_default = /* @__PURE__ */ defineComponent({
32274
32383
  transitionProps: props.transitionProps,
32275
32384
  middlewares: props.middlewares,
32276
32385
  closeOnItemClick: false,
32277
- withinPortal: attrs.withinPortal ?? false
32386
+ withinPortal: false
32278
32387
  }));
32279
32388
  return (_ctx, _cache) => {
32280
32389
  return openBlock(), createBlock(Menu_default, normalizeProps(guardReactiveProps(menuBindings.value)), {
@@ -33260,7 +33369,6 @@ function useCombobox(options = {}) {
33260
33369
  const items = () => Array.from(list()?.querySelectorAll("[data-combobox-option]") ?? []);
33261
33370
  const clearSelected = () => items().forEach((item) => {
33262
33371
  item.removeAttribute("data-combobox-selected");
33263
- item.removeAttribute("aria-selected");
33264
33372
  });
33265
33373
  const selectOption = (index) => {
33266
33374
  const optionsList = items();
@@ -33275,7 +33383,6 @@ function useCombobox(options = {}) {
33275
33383
  selectedIndex.value = next;
33276
33384
  clearSelected();
33277
33385
  optionsList[next].setAttribute("data-combobox-selected", "true");
33278
- optionsList[next].setAttribute("aria-selected", "true");
33279
33386
  optionsList[next].scrollIntoView?.({
33280
33387
  block: "nearest",
33281
33388
  behavior: options.scrollBehavior ?? "instant"
@@ -34727,7 +34834,6 @@ var ComboboxPopover_default = /* @__PURE__ */ defineComponent({
34727
34834
  onDropdownClose: () => {
34728
34835
  emit("dropdown-close");
34729
34836
  combobox.resetSelectedOption();
34730
- if (props.searchable) combobox.focusTarget();
34731
34837
  }
34732
34838
  });
34733
34839
  function handleSearchChange(val) {
@@ -34763,6 +34869,7 @@ var ComboboxPopover_default = /* @__PURE__ */ defineComponent({
34763
34869
  styles: props.styles,
34764
34870
  unstyled: props.unstyled,
34765
34871
  onOptionSubmit: handleOptionSubmit,
34872
+ returnFocus: true,
34766
34873
  ...props.comboboxProps,
34767
34874
  ...attrs
34768
34875
  }));