@codbex/harmonia 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/harmonia.js CHANGED
@@ -304,10 +304,10 @@
304
304
  }) : { single: false };
305
305
  el.setAttribute("data-slot", "accordion");
306
306
  });
307
- Alpine.directive("h-accordion-item", (el, { original: original2, expression, modifiers }, { effect, Alpine: Alpine2 }) => {
307
+ Alpine.directive("h-accordion-item", (el, { original, expression, modifiers }, { effect, Alpine: Alpine2 }) => {
308
308
  const accordion = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_accordion"));
309
309
  if (!accordion) {
310
- throw new Error(`${original2} must be inside an accordion`);
310
+ throw new Error(`${original} must be inside an accordion`);
311
311
  }
312
312
  el.classList.add("border-b", "last:border-b-0", "[[data-variant=header]_&]:data-[state=closed]:border-b-0");
313
313
  el.setAttribute("data-slot", "accordion-item");
@@ -335,14 +335,14 @@
335
335
  setAttributes();
336
336
  effect(setAttributes);
337
337
  });
338
- Alpine.directive("h-accordion-trigger", (el, { original: original2, expression }, { effect, evaluateLater, Alpine: Alpine2, cleanup }) => {
338
+ Alpine.directive("h-accordion-trigger", (el, { original, expression }, { effect, evaluateLater, Alpine: Alpine2, cleanup }) => {
339
339
  if (el.tagName.length !== 2 && !el.tagName.startsWith("H")) {
340
- throw new Error(`${original2} must be a header element`);
340
+ throw new Error(`${original} must be a header element`);
341
341
  }
342
342
  const accordion = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_accordion"));
343
343
  const accordionItem = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_accordionItem"));
344
344
  if (!accordionItem || !accordion) {
345
- throw new Error(`${original2} must have an accordion and accordion item parent elements`);
345
+ throw new Error(`${original} must have an accordion and accordion item parent elements`);
346
346
  }
347
347
  el.classList.add(
348
348
  "flex",
@@ -527,10 +527,10 @@
527
527
  el.classList.add("cursor-pointer", "hover:bg-secondary-hover", "active:bg-secondary-active");
528
528
  }
529
529
  });
530
- Alpine.directive("h-avatar-image", (el, { original: original2 }, { cleanup }) => {
530
+ Alpine.directive("h-avatar-image", (el, { original }, { cleanup }) => {
531
531
  const avatar = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_avatar"));
532
532
  if (!avatar) {
533
- throw new Error(`${original2} must be inside an avatar element`);
533
+ throw new Error(`${original} must be inside an avatar element`);
534
534
  }
535
535
  el.classList.add("aspect-square", "size-full");
536
536
  el.setAttribute("data-slot", "avatar-image");
@@ -561,10 +561,10 @@
561
561
  observer.disconnect();
562
562
  });
563
563
  });
564
- Alpine.directive("h-avatar-fallback", (el, { original: original2 }, { effect }) => {
564
+ Alpine.directive("h-avatar-fallback", (el, { original }, { effect }) => {
565
565
  const avatar = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_avatar"));
566
566
  if (!avatar) {
567
- throw new Error(`${original2} must be inside an avatar element`);
567
+ throw new Error(`${original} must be inside an avatar element`);
568
568
  }
569
569
  el.classList.add("hidden", "bg-muted", "flex", "size-full", "items-center", "justify-center");
570
570
  el.setAttribute("data-slot", "avatar-fallback");
@@ -773,7 +773,7 @@
773
773
  }
774
774
  };
775
775
  function button_default(Alpine) {
776
- Alpine.directive("h-button", (el, { original: original2, modifiers }, { cleanup }) => {
776
+ Alpine.directive("h-button", (el, { original, modifiers }, { cleanup }) => {
777
777
  setButtonClasses(el);
778
778
  if (!el.hasAttribute("data-slot")) {
779
779
  el.setAttribute("data-slot", "button");
@@ -790,7 +790,7 @@
790
790
  el.classList.remove(...getButtonSize(lastSize, isAddon));
791
791
  el.classList.add(...getButtonSize(size3, isAddon));
792
792
  if (size3.startsWith("icon") && !el.hasAttribute("aria-labelledby") && !el.hasAttribute("aria-label")) {
793
- console.error(`${original2}: Icon-only buttons must have an "aria-label" or "aria-labelledby" attribute`, el);
793
+ console.error(`${original}: Icon-only buttons must have an "aria-label" or "aria-labelledby" attribute`, el);
794
794
  }
795
795
  lastSize = size3;
796
796
  }
@@ -2339,7 +2339,7 @@
2339
2339
 
2340
2340
  // src/components/calendar.js
2341
2341
  function calendar_default(Alpine) {
2342
- Alpine.directive("h-calendar", (el, { original: original2, expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
2342
+ Alpine.directive("h-calendar", (el, { original, expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
2343
2343
  const datepicker = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_datepicker"));
2344
2344
  el.classList.add("border", "rounded-control", "gap-2", "p-2");
2345
2345
  el.setAttribute("tabindex", "-1");
@@ -2383,7 +2383,7 @@
2383
2383
  const onInputChange = () => {
2384
2384
  const newValue = new Date(datepicker._h_datepicker.input.value);
2385
2385
  if (isNaN(newValue)) {
2386
- console.error(`${original2}: input value is not a valid date - ${datepicker._h_datepicker.input.value}`);
2386
+ console.error(`${original}: input value is not a valid date - ${datepicker._h_datepicker.input.value}`);
2387
2387
  datepicker._h_datepicker.input.setCustomValidity("Input value is not a valid date.");
2388
2388
  return;
2389
2389
  } else if (selected.getTime() !== newValue.getTime()) {
@@ -2400,7 +2400,7 @@
2400
2400
  if (el.hasOwnProperty("_x_model") && el._x_model.get()) {
2401
2401
  selected = new Date(el._x_model.get());
2402
2402
  if (isNaN(selected)) {
2403
- console.error(`${original2}: input value is not a valid date - ${el._x_model.get()}`);
2403
+ console.error(`${original}: input value is not a valid date - ${el._x_model.get()}`);
2404
2404
  if (datepicker) datepicker._h_datepicker.input.setCustomValidity("Input value is not a valid date.");
2405
2405
  else el.setAttribute("data-invalid", "true");
2406
2406
  } else if (datepicker) {
@@ -2909,10 +2909,10 @@
2909
2909
  });
2910
2910
  }
2911
2911
  });
2912
- Alpine.directive("h-collapsible-trigger", (el, { original: original2, modifiers }, { effect, Alpine: Alpine2, cleanup }) => {
2912
+ Alpine.directive("h-collapsible-trigger", (el, { original, modifiers }, { effect, Alpine: Alpine2, cleanup }) => {
2913
2913
  const collapsible = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_collapsible"));
2914
2914
  if (!collapsible) {
2915
- throw new Error(`${original2} must be inside a collapsible element`);
2915
+ throw new Error(`${original} must be inside a collapsible element`);
2916
2916
  }
2917
2917
  if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "collapsible-trigger");
2918
2918
  if (modifiers.includes("chevron")) {
@@ -2931,10 +2931,10 @@
2931
2931
  el.removeEventListener("click", handler);
2932
2932
  });
2933
2933
  });
2934
- Alpine.directive("h-collapsible-content", (el, { original: original2 }, { effect, Alpine: Alpine2 }) => {
2934
+ Alpine.directive("h-collapsible-content", (el, { original }, { effect, Alpine: Alpine2 }) => {
2935
2935
  const collapsible = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_collapsible"));
2936
2936
  if (!collapsible) {
2937
- throw new Error(`${original2} must be inside an h-collapsible element`);
2937
+ throw new Error(`${original} must be inside an h-collapsible element`);
2938
2938
  }
2939
2939
  if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "collapsible-content");
2940
2940
  el.classList.add("data-[state=closed]:!hidden");
@@ -2965,7 +2965,7 @@
2965
2965
 
2966
2966
  // src/components/datepicker.js
2967
2967
  function datepicker_default(Alpine) {
2968
- Alpine.directive("h-date-picker", (el, { original: original2, modifiers }, { Alpine: Alpine2, cleanup }) => {
2968
+ Alpine.directive("h-date-picker", (el, { original, modifiers }, { Alpine: Alpine2, cleanup }) => {
2969
2969
  const state = Alpine2.reactive({
2970
2970
  expanded: false
2971
2971
  });
@@ -2978,7 +2978,7 @@
2978
2978
  };
2979
2979
  el._h_datepicker.input = el.querySelector("input");
2980
2980
  if (!el._h_datepicker.input || el._h_datepicker.input.tagName !== "INPUT") {
2981
- throw new Error(`${original2} must contain an input`);
2981
+ throw new Error(`${original} must contain an input`);
2982
2982
  } else if (el._h_datepicker.input.hasAttribute("id")) {
2983
2983
  el._h_datepicker.id = el._h_datepicker.input.getAttribute("id");
2984
2984
  } else {
@@ -3055,16 +3055,16 @@
3055
3055
  observer.disconnect();
3056
3056
  });
3057
3057
  });
3058
- Alpine.directive("h-date-picker-trigger", (el, { original: original2 }, { effect, cleanup, Alpine: Alpine2 }) => {
3058
+ Alpine.directive("h-date-picker-trigger", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
3059
3059
  if (el.tagName !== "BUTTON") {
3060
- throw new Error(`${original2} must be a button`);
3060
+ throw new Error(`${original} must be a button`);
3061
3061
  }
3062
3062
  if (!el.hasAttribute("aria-labelledby") && !el.hasAttribute("aria-label")) {
3063
- throw new Error(`${original2}: must have an "aria-label" or "aria-labelledby" attribute`);
3063
+ throw new Error(`${original}: must have an "aria-label" or "aria-labelledby" attribute`);
3064
3064
  }
3065
3065
  const datepicker = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_datepicker"));
3066
3066
  if (!datepicker) {
3067
- throw new Error(`${original2} must be inside an date-picker element`);
3067
+ throw new Error(`${original} must be inside an date-picker element`);
3068
3068
  }
3069
3069
  el.classList.add("cursor-pointer", "inline-flex", "items-center", "justify-center", "h-full", "aspect-square", "bg-transparent", "hover:bg-secondary", "active:bg-secondary-active", "outline-none");
3070
3070
  if (datepicker._h_datepicker.inTable) {
@@ -3344,13 +3344,13 @@
3344
3344
 
3345
3345
  // src/components/icon.js
3346
3346
  function icon_default(Alpine) {
3347
- Alpine.directive("h-icon", (el, { original: original2, modifiers }) => {
3347
+ Alpine.directive("h-icon", (el, { original, modifiers }) => {
3348
3348
  if (el.tagName.toLowerCase() !== "svg") {
3349
- throw new Error(`${original2} works only on svg elements`);
3349
+ throw new Error(`${original} works only on svg elements`);
3350
3350
  } else if (!el.hasAttribute("role")) {
3351
- throw new Error(`${original2} must have a role`);
3351
+ throw new Error(`${original} must have a role`);
3352
3352
  } else if (el.getAttribute("role") === "img" && !el.hasAttribute("aria-labelledby") && !el.hasAttribute("aria-label")) {
3353
- throw new Error(`${original2}: svg images with the role of img must have an "aria-label" or "aria-labelledby" attribute`);
3353
+ throw new Error(`${original}: svg images with the role of img must have an "aria-label" or "aria-labelledby" attribute`);
3354
3354
  }
3355
3355
  el.classList.add("fill-current");
3356
3356
  el.setAttribute("data-slot", "icon");
@@ -3567,7 +3567,7 @@
3567
3567
  el.classList.add("text-muted-foreground", "flex", "items-center", "gap-2", "text-sm", "[&_svg]:pointer-events-none", "[&_svg:not([class*='size-'])]:size-4");
3568
3568
  el.setAttribute("data-slot", "label");
3569
3569
  });
3570
- Alpine.directive("h-input-number", (el, { original: original2 }, { cleanup }) => {
3570
+ Alpine.directive("h-input-number", (el, { original }, { cleanup }) => {
3571
3571
  el.classList.add(
3572
3572
  "overflow-hidden",
3573
3573
  "group/input-number",
@@ -3600,7 +3600,7 @@
3600
3600
  el.setAttribute("data-slot", "input-number");
3601
3601
  const input = el.querySelector("input");
3602
3602
  if (!input || input.getAttribute("type") !== "number") {
3603
- throw new Error(`${original2} must contain an input of type 'number'`);
3603
+ throw new Error(`${original} must contain an input of type 'number'`);
3604
3604
  }
3605
3605
  if (!input.hasAttribute("type")) input.setAttribute("type", "number");
3606
3606
  if (!input.hasAttribute("inputmode")) input.setAttribute("inputmode", "numeric");
@@ -3846,13 +3846,13 @@
3846
3846
  el.setAttribute("data-slot", "list");
3847
3847
  el.setAttribute("role", "group");
3848
3848
  });
3849
- Alpine.directive("h-list-header", (el, { original: original2 }, { Alpine: Alpine2 }) => {
3849
+ Alpine.directive("h-list-header", (el, { original }, { Alpine: Alpine2 }) => {
3850
3850
  el.classList.add("font-medium", "flex", "items-center", "p-2", "gap-2", "align-middle", "bg-table-header", "text-table-header-foreground");
3851
3851
  el.setAttribute("role", "presentation");
3852
3852
  el.setAttribute("data-slot", "list-header");
3853
3853
  const list = Alpine2.findClosest(el.parentElement, (parent) => parent.getAttribute("data-slot") === "list");
3854
3854
  if (!list) {
3855
- throw new Error(`${original2} must be placed inside a list element`);
3855
+ throw new Error(`${original} must be placed inside a list element`);
3856
3856
  }
3857
3857
  if (!el.hasAttribute("id")) {
3858
3858
  const id = `lbh${v4_default()}`;
@@ -3904,9 +3904,9 @@
3904
3904
  };
3905
3905
  el.setAttribute("data-state", "closed");
3906
3906
  });
3907
- Alpine.directive("h-menu", (el, { original: original2, modifiers }, { cleanup, Alpine: Alpine2 }) => {
3907
+ Alpine.directive("h-menu", (el, { original, modifiers }, { cleanup, Alpine: Alpine2 }) => {
3908
3908
  if (el.tagName !== "UL") {
3909
- throw new Error(`${original2} must be an ul element`);
3909
+ throw new Error(`${original} must be an ul element`);
3910
3910
  }
3911
3911
  el.classList.add("hidden", "fixed", "bg-popover", "text-popover-foreground", "font-normal", "z-50", "min-w-[8rem]", "overflow-x-hidden", "overflow-y-auto", "rounded-md", "p-1", "shadow-md", "border", "outline-none");
3912
3912
  el.setAttribute("role", "menu");
@@ -3914,7 +3914,7 @@
3914
3914
  el.setAttribute("tabindex", "-1");
3915
3915
  el.setAttribute("data-slot", "menu");
3916
3916
  if (!el.hasAttribute("aria-labelledby") && !el.hasAttribute("aria-label")) {
3917
- throw new Error(`${original2} must have an "aria-label" or "aria-labelledby" attribute`);
3917
+ throw new Error(`${original} must have an "aria-label" or "aria-labelledby" attribute`);
3918
3918
  }
3919
3919
  const isSubmenu = modifiers.includes("sub");
3920
3920
  const menuTrigger = (() => {
@@ -3926,7 +3926,7 @@
3926
3926
  return sibling;
3927
3927
  })();
3928
3928
  if (!isSubmenu && !menuTrigger) {
3929
- throw new Error(`${original2} menu must be placed after a menu trigger element`);
3929
+ throw new Error(`${original} menu must be placed after a menu trigger element`);
3930
3930
  }
3931
3931
  let menuSubItem;
3932
3932
  if (isSubmenu) menuSubItem = Alpine2.findClosest(el.parentElement, (parent) => parent.getAttribute("data-slot") === "menu-sub");
@@ -4145,9 +4145,9 @@
4145
4145
  el.removeEventListener("keydown", onKeyDown);
4146
4146
  });
4147
4147
  });
4148
- Alpine.directive("h-menu-item", (el, { original: original2 }, { cleanup, Alpine: Alpine2 }) => {
4148
+ Alpine.directive("h-menu-item", (el, { original }, { cleanup, Alpine: Alpine2 }) => {
4149
4149
  if (el.tagName !== "LI") {
4150
- throw new Error(`${original2} must be a li element`);
4150
+ throw new Error(`${original} must be a li element`);
4151
4151
  }
4152
4152
  el.classList.add(
4153
4153
  "focus:bg-secondary-hover",
@@ -4201,7 +4201,7 @@
4201
4201
  el.removeEventListener("mouseleave", focusOut);
4202
4202
  });
4203
4203
  });
4204
- Alpine.directive("h-menu-sub", (el, { original: original2 }, { cleanup, Alpine: Alpine2 }) => {
4204
+ Alpine.directive("h-menu-sub", (el, { original }, { cleanup, Alpine: Alpine2 }) => {
4205
4205
  el.classList.add(
4206
4206
  "focus:bg-secondary-hover",
4207
4207
  "hover:bg-secondary-hover",
@@ -4233,7 +4233,7 @@
4233
4233
  const chevronRight = createSvg({ icon: ChevronRight, classes: "size-4 ml-auto", attrs: { "aria-hidden": true, role: "presentation" } });
4234
4234
  el.appendChild(chevronRight);
4235
4235
  const parentMenu = Alpine2.findClosest(el.parentElement, (parent) => parent.getAttribute("role") === "menu");
4236
- if (!parentMenu) throw new Error(`${original2} must have a parent`);
4236
+ if (!parentMenu) throw new Error(`${original} must have a parent`);
4237
4237
  el._menu_sub = {
4238
4238
  open: void 0,
4239
4239
  close: void 0,
@@ -4327,9 +4327,9 @@
4327
4327
  el.classList.add("text-foreground", "px-2", "py-1.5", "text-sm", "font-semibold", "text-left", "data-[inset=true]:pl-8");
4328
4328
  el.setAttribute("data-slot", "menu-label");
4329
4329
  });
4330
- Alpine.directive("h-menu-checkbox-item", (el, { original: original2 }, { cleanup, Alpine: Alpine2 }) => {
4330
+ Alpine.directive("h-menu-checkbox-item", (el, { original }, { cleanup, Alpine: Alpine2 }) => {
4331
4331
  if (el.tagName !== "LI" && el.tagName !== "DIV") {
4332
- throw new Error(`${original2} must be a li or div element`);
4332
+ throw new Error(`${original} must be a li or div element`);
4333
4333
  }
4334
4334
  el.classList.add(
4335
4335
  "focus:bg-secondary-hover",
@@ -4395,9 +4395,9 @@
4395
4395
  el.removeEventListener("mouseleave", focusOut);
4396
4396
  });
4397
4397
  });
4398
- Alpine.directive("h-menu-radio-item", (el, { original: original2, expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
4398
+ Alpine.directive("h-menu-radio-item", (el, { original, expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
4399
4399
  if (el.tagName !== "LI" && el.tagName !== "DIV") {
4400
- throw new Error(`${original2} must be a li or div element`);
4400
+ throw new Error(`${original} must be a li or div element`);
4401
4401
  }
4402
4402
  el.classList.add(
4403
4403
  "focus:bg-secondary-hover",
@@ -4601,6 +4601,7 @@
4601
4601
  const close = () => {
4602
4602
  el._popover.expanded = false;
4603
4603
  el.addEventListener("click", handler);
4604
+ setAttributes();
4604
4605
  };
4605
4606
  const handler = () => {
4606
4607
  el._popover.expanded = !el._popover.expanded;
@@ -4625,7 +4626,7 @@
4625
4626
  });
4626
4627
  }
4627
4628
  });
4628
- Alpine.directive("h-popover", (el, { original: original2, modifiers }, { effect }) => {
4629
+ Alpine.directive("h-popover", (el, { original, modifiers }, { effect }) => {
4629
4630
  const popover = (() => {
4630
4631
  let sibling = el.previousElementSibling;
4631
4632
  while (sibling && !sibling.hasOwnProperty("_popover")) {
@@ -4634,9 +4635,9 @@
4634
4635
  return sibling;
4635
4636
  })();
4636
4637
  if (!popover) {
4637
- throw new Error(`${original2} must be placed after a popover element`);
4638
+ throw new Error(`${original} must be placed after a popover element`);
4638
4639
  }
4639
- el.classList.add("absolute", "bg-popover", "text-popover-foreground", "data-[state=closed]:hidden", "top-0", "left-0", "z-50", "min-w-[1rem]", "rounded-md", "border", "shadow-md", "outline-hidden", "overflow-scroll");
4640
+ el.classList.add("absolute", "bg-popover", "text-popover-foreground", "data-[state=closed]:hidden", "top-0", "left-0", "z-50", "min-w-[1rem]", "rounded-md", "border", "shadow-md", "outline-hidden", "overflow-auto");
4640
4641
  el.setAttribute("data-slot", "popover");
4641
4642
  el.setAttribute("role", "dialog");
4642
4643
  el.setAttribute("tabindex", "-1");
@@ -6648,7 +6649,8 @@
6648
6649
  function select_default(Alpine) {
6649
6650
  Alpine.directive("h-select", (el, { modifiers }, { Alpine: Alpine2, cleanup }) => {
6650
6651
  el._h_select = Alpine2.reactive({
6651
- id: void 0,
6652
+ fieldLabelId: void 0,
6653
+ trigger: void 0,
6652
6654
  controls: `hsc${v4_default()}`,
6653
6655
  expanded: false,
6654
6656
  multiple: false,
@@ -6695,13 +6697,20 @@
6695
6697
  });
6696
6698
  }
6697
6699
  });
6698
- Alpine.directive("h-select-input", (el, { original: original2 }, { effect, cleanup, Alpine: Alpine2 }) => {
6700
+ Alpine.directive("h-select-input", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
6699
6701
  if (el.tagName !== "INPUT") {
6700
- throw new Error(`${original2} must be a readonly input of type "text"`);
6702
+ throw new Error(`${original} must be an input of type "text"`);
6701
6703
  }
6702
6704
  const select = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_select"));
6705
+ const label = (() => {
6706
+ const field = Alpine2.findClosest(el.parentElement, (parent) => parent.getAttribute("data-slot") === "field");
6707
+ if (field) {
6708
+ return field.querySelector("[data-slot=field-label]");
6709
+ }
6710
+ return;
6711
+ })();
6703
6712
  if (!select) {
6704
- throw new Error(`${original2} must be inside a select element`);
6713
+ throw new Error(`${original} must be inside a select element`);
6705
6714
  } else if (el.hasOwnProperty("_x_model")) {
6706
6715
  select._h_select.multiple = Array.isArray(el._x_model.get());
6707
6716
  select._h_model.set = (value) => {
@@ -6739,6 +6748,19 @@
6739
6748
  fakeTrigger.setAttribute("data-slot", "select-value");
6740
6749
  fakeTrigger.setAttribute("tabindex", "0");
6741
6750
  fakeTrigger.classList.add("flex", "items-center", "justify-between", "gap-2", "outline-none", "pl-3", "pr-2", "size-full", "[&[data-state=open]>svg]:rotate-180");
6751
+ select._h_select.trigger = fakeTrigger;
6752
+ let labelObserver;
6753
+ if (label) {
6754
+ if (!label.hasAttribute("id")) {
6755
+ label.setAttribute("id", `hsil${v4_default()}`);
6756
+ }
6757
+ select._h_select.fieldLabelId = label.getAttribute("id");
6758
+ fakeTrigger.setAttribute("aria-labelledby", label.getAttribute("id"));
6759
+ labelObserver = new MutationObserver(() => {
6760
+ select._h_select.fieldLabelId = label.getAttribute("id");
6761
+ });
6762
+ labelObserver.observe(label, { attributes: true, attributeFilter: ["id"] });
6763
+ }
6742
6764
  function getPlaceholder() {
6743
6765
  if (!el.value) {
6744
6766
  const value = el.getAttribute("placeholder");
@@ -6751,17 +6773,10 @@
6751
6773
  }
6752
6774
  }
6753
6775
  getPlaceholder();
6754
- const observer = new MutationObserver((mutations) => {
6755
- mutations.forEach((mutation) => {
6756
- if (mutation.attributeName === "data-id") {
6757
- select._h_select.id = el.getAttribute("data-id");
6758
- fakeTrigger.setAttribute("id", select._h_select.id);
6759
- } else if (mutation.attributeName === "placeholder" && !select._h_select.label.length) {
6760
- getPlaceholder();
6761
- }
6762
- });
6776
+ const observer = new MutationObserver(() => {
6777
+ getPlaceholder();
6763
6778
  });
6764
- observer.observe(el, { attributes: true, attributeFilter: ["data-id", "placeholder"] });
6779
+ observer.observe(el, { attributes: true, attributeFilter: ["placeholder"] });
6765
6780
  effect(() => {
6766
6781
  if (select._h_select.label.length === 1) {
6767
6782
  displayValue.innerText = select._h_select.label[0];
@@ -6774,8 +6789,6 @@
6774
6789
  }
6775
6790
  });
6776
6791
  fakeTrigger.setAttribute("data-slot", "select-input");
6777
- select._h_select.id = el.hasAttribute("data-id") ? el.getAttribute("data-id") : `hs${v4_default()}`;
6778
- fakeTrigger.setAttribute("id", select._h_select.id);
6779
6792
  fakeTrigger.setAttribute("aria-controls", select._h_select.controls);
6780
6793
  fakeTrigger.setAttribute("aria-haspopup", "listbox");
6781
6794
  fakeTrigger.setAttribute("aria-autocomplete", "none");
@@ -6937,9 +6950,9 @@
6937
6950
  const onInputChange = () => {
6938
6951
  select._h_select.label.length = 0;
6939
6952
  for (let i = 0; i < select._h_select.listeners.length; i++) {
6940
- const label = select._h_select.listeners[i](select._h_model.get());
6941
- if (label) {
6942
- select._h_select.label.push(label);
6953
+ const label2 = select._h_select.listeners[i](select._h_model.get());
6954
+ if (label2) {
6955
+ select._h_select.label.push(label2);
6943
6956
  }
6944
6957
  }
6945
6958
  };
@@ -6952,27 +6965,28 @@
6952
6965
  top.removeEventListener("click", close);
6953
6966
  el.removeEventListener("change", onInputChange);
6954
6967
  observer.disconnect();
6968
+ if (labelObserver) {
6969
+ labelObserver.disconnect();
6970
+ }
6955
6971
  });
6956
6972
  });
6957
- Alpine.directive("h-select-content", (el, { original: original2 }, { effect, Alpine: Alpine2 }) => {
6973
+ Alpine.directive("h-select-content", (el, { original }, { effect, Alpine: Alpine2 }) => {
6958
6974
  const select = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_select"));
6959
6975
  if (!select) {
6960
- throw new Error(`${original2} must be inside a select element`);
6976
+ throw new Error(`${original} must be inside a select element`);
6961
6977
  }
6962
6978
  el.classList.add("absolute", "bg-popover", "text-popover-foreground", "data-[state=closed]:hidden", "p-1", "top-0", "left-0", "z-50", "min-w-[1rem]", "overflow-x-hidden", "overflow-y-auto", "rounded-md", "border", "shadow-md");
6963
6979
  el.setAttribute("data-slot", "select-content");
6964
6980
  el.setAttribute("role", "listbox");
6965
- el.setAttribute("role", "presentation");
6966
6981
  el.setAttribute("id", select._h_select.controls);
6967
6982
  el.setAttribute("tabindex", "-1");
6968
6983
  el.setAttribute("data-state", select._h_select.expanded ? "open" : "closed");
6969
- const control = select.querySelector(`#${select._h_select.id}`);
6970
- if (!control) {
6971
- throw new Error(`${original2}: trigger not found`);
6984
+ if (!select._h_select.trigger) {
6985
+ throw new Error(`${original}: trigger not found`);
6972
6986
  }
6973
6987
  let autoUpdateCleanup;
6974
6988
  function updatePosition() {
6975
- computePosition2(control, el, {
6989
+ computePosition2(select._h_select.trigger, el, {
6976
6990
  placement: el.getAttribute("data-align") || "bottom-start",
6977
6991
  middleware: [
6978
6992
  offset2(4),
@@ -6995,12 +7009,12 @@
6995
7009
  });
6996
7010
  }
6997
7011
  effect(() => {
6998
- el.setAttribute("aria-labelledby", select._h_select.id);
7012
+ el.setAttribute("aria-labelledby", select._h_select.fieldLabelId);
6999
7013
  });
7000
7014
  effect(() => {
7001
7015
  el.setAttribute("data-state", select._h_select.expanded ? "open" : "closed");
7002
7016
  if (select._h_select.expanded) {
7003
- autoUpdateCleanup = autoUpdate(control, el, updatePosition);
7017
+ autoUpdateCleanup = autoUpdate(select._h_select.trigger, el, updatePosition);
7004
7018
  } else {
7005
7019
  if (autoUpdateCleanup) autoUpdateCleanup();
7006
7020
  Object.assign(el.style, {
@@ -7010,10 +7024,10 @@
7010
7024
  }
7011
7025
  });
7012
7026
  });
7013
- Alpine.directive("h-select-search", (el, { original: original2 }, { effect, cleanup, Alpine: Alpine2 }) => {
7027
+ Alpine.directive("h-select-search", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
7014
7028
  const select = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_select"));
7015
7029
  if (!select) {
7016
- throw new Error(`${original2} must be inside an h-select element`);
7030
+ throw new Error(`${original} must be inside an h-select element`);
7017
7031
  } else {
7018
7032
  select._h_select.filterType = FilterType[el.getAttribute("data-filter")] ?? FilterType["starts-with"];
7019
7033
  }
@@ -7085,10 +7099,10 @@
7085
7099
  selectGroup._h_selectGroup.labelledby = id;
7086
7100
  }
7087
7101
  });
7088
- Alpine.directive("h-select-option", (el, { original: original2, expression }, { effect, evaluateLater, cleanup }) => {
7102
+ Alpine.directive("h-select-option", (el, { original, expression }, { effect, evaluateLater, cleanup }) => {
7089
7103
  const select = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_select"));
7090
7104
  if (!select) {
7091
- throw new Error(`${original2} must be inside an h-select element`);
7105
+ throw new Error(`${original} must be inside an h-select element`);
7092
7106
  }
7093
7107
  el.classList.add(
7094
7108
  "focus:bg-primary",
@@ -7319,13 +7333,35 @@
7319
7333
  el.classList.add("vbox", "min-h-0", "flex-1", "gap-2", "overflow-auto", "group-data-[collapsed=true]/sidebar:overflow-hidden");
7320
7334
  el.setAttribute("data-slot", "sidebar-content");
7321
7335
  });
7322
- Alpine.directive("h-sidebar-group", (el) => {
7336
+ Alpine.directive("h-sidebar-group", (el, { expression, modifiers }, { effect, evaluate: evaluate2, evaluateLater, Alpine: Alpine2 }) => {
7323
7337
  el.classList.add("relative", "vbox", "w-full", "min-w-0", "p-2");
7324
7338
  el.setAttribute("data-slot", "sidebar-group");
7339
+ el._h_sidebar_group = {
7340
+ collapsable: modifiers.includes("collapsed"),
7341
+ controlId: void 0,
7342
+ controls: void 0,
7343
+ state: Alpine2.reactive({
7344
+ collapsed: evaluate2(expression || "false")
7345
+ })
7346
+ };
7347
+ if (expression) {
7348
+ el._h_sidebar_group.state = Alpine2.reactive({
7349
+ collapsed: evaluate2(expression || "false")
7350
+ });
7351
+ const getCollapsed = evaluateLater(expression);
7352
+ effect(() => {
7353
+ getCollapsed((collapsed) => {
7354
+ el._h_sidebar_group.state.collapsed = collapsed;
7355
+ });
7356
+ });
7357
+ }
7325
7358
  });
7326
- Alpine.directive("h-sidebar-group-label", (el, { modifiers }) => {
7359
+ Alpine.directive("h-sidebar-group-label", (el, { original }, { cleanup }) => {
7360
+ const group = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_group"));
7361
+ if (!group) {
7362
+ throw new Error(`${original} must be placed inside a sidebar group`);
7363
+ }
7327
7364
  el.classList.add(
7328
- "text-sidebar-foreground/70",
7329
7365
  "ring-sidebar-ring",
7330
7366
  "flex",
7331
7367
  "h-8",
@@ -7333,7 +7369,6 @@
7333
7369
  "items-center",
7334
7370
  "rounded-md",
7335
7371
  "px-2",
7336
- "text-xs",
7337
7372
  "font-medium",
7338
7373
  "outline-hidden",
7339
7374
  "transition-[margin,opacity]",
@@ -7344,8 +7379,39 @@
7344
7379
  "[&>svg]:shrink-0",
7345
7380
  "group-data-[collapsed=true]/sidebar:!hidden"
7346
7381
  );
7347
- if (modifiers.includes("action")) el.classList.add("hover:bg-secondary-hover", "active:bg-secondary-active");
7348
7382
  el.setAttribute("data-slot", "sidebar-group-label");
7383
+ if (group._h_sidebar_group.collapsable) {
7384
+ el.classList.add("text-sidebar-foreground", "text-sm", "hover:bg-secondary-hover", "active:bg-secondary-active");
7385
+ if (el.hasAttribute("id")) {
7386
+ group._h_sidebar_group.controlId = el.getAttribute("id");
7387
+ } else {
7388
+ group._h_sidebar_group.controlId = `sgl${v4_default()}`;
7389
+ el.setAttribute("id", group._h_sidebar_group.controlId);
7390
+ }
7391
+ group._h_sidebar_group.controls = `sgc${v4_default()}`;
7392
+ el.setAttribute("aria-controls", group._h_sidebar_group.controls);
7393
+ el.setAttribute("aria-expanded", !group._h_sidebar_group.state.collapsed);
7394
+ const handler = () => {
7395
+ group._h_sidebar_group.state.collapsed = !group._h_sidebar_group.state.collapsed;
7396
+ el.setAttribute("aria-expanded", !group._h_sidebar_group.state.collapsed);
7397
+ };
7398
+ el.appendChild(
7399
+ createSvg({
7400
+ icon: ChevronRight,
7401
+ classes: "ml-auto pointer-events-none size-4 shrink-0 transition-transform duration-200 [[aria-expanded=true]>&]:rotate-90",
7402
+ attrs: {
7403
+ "aria-hidden": true,
7404
+ role: "presentation"
7405
+ }
7406
+ })
7407
+ );
7408
+ el.addEventListener("click", handler);
7409
+ cleanup(() => {
7410
+ el.removeEventListener("click", handler);
7411
+ });
7412
+ } else {
7413
+ el.classList.add("text-sidebar-foreground/70", "text-xs");
7414
+ }
7349
7415
  });
7350
7416
  Alpine.directive("h-sidebar-group-action", (el) => {
7351
7417
  el.classList.add(
@@ -7380,41 +7446,85 @@
7380
7446
  }
7381
7447
  el.setAttribute("data-slot", "sidebar-group-action");
7382
7448
  });
7383
- Alpine.directive("h-sidebar-group-content", (el) => {
7384
- el.classList.add("w-full", "text-sm");
7449
+ Alpine.directive("h-sidebar-group-content", (el, { original }, { effect }) => {
7450
+ const group = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_group"));
7451
+ if (!group) {
7452
+ throw new Error(`${original} must be placed inside a sidebar group`);
7453
+ }
7454
+ el.classList.add("w-full", "text-sm", "data-[collapsed=true]:hidden", "group-data-[collapsed=true]/sidebar:!block");
7385
7455
  el.setAttribute("data-slot", "sidebar-group-content");
7456
+ if (group._h_sidebar_group.collapsable) {
7457
+ el.setAttribute("id", group._h_sidebar_group.controls);
7458
+ el.setAttribute("aria-labelledby", group._h_sidebar_group.controlId);
7459
+ el.setAttribute("data-collapsed", group._h_sidebar_group.state.collapsed);
7460
+ effect(() => {
7461
+ el.setAttribute("data-collapsed", group._h_sidebar_group.state.collapsed);
7462
+ });
7463
+ }
7386
7464
  });
7387
- Alpine.directive("h-sidebar-menu", (el) => {
7465
+ Alpine.directive("h-sidebar-menu", (el, { original }) => {
7466
+ if (el.tagName !== "UL") {
7467
+ throw new Error(`${original} must be an ul element`);
7468
+ }
7388
7469
  el.classList.add("vbox", "w-full", "min-w-0", "gap-1");
7389
7470
  el.setAttribute("data-slot", "sidebar-menu");
7390
7471
  });
7391
- Alpine.directive("h-sidebar-menu-item", (el, { original: original2 }) => {
7392
- if (el.tagName !== "BUTTON") {
7393
- throw new Error(`${original2} must be a button`);
7472
+ Alpine.directive("h-sidebar-menu-item", (el, { original, expression, modifiers }, { effect, evaluate: evaluate2, evaluateLater, Alpine: Alpine2 }) => {
7473
+ if (el.tagName !== "LI") {
7474
+ throw new Error(`${original} must be a li element`);
7475
+ }
7476
+ el._h_sidebar_menu_item = {
7477
+ isSub: false,
7478
+ collapsable: modifiers.includes("collapsed"),
7479
+ controlId: void 0,
7480
+ controls: void 0,
7481
+ state: Alpine2.reactive({
7482
+ collapsed: evaluate2(expression || "false")
7483
+ })
7484
+ };
7485
+ let parent = el.parentElement;
7486
+ while (parent) {
7487
+ if (parent.getAttribute("data-slot") === "sidebar-menu-sub") {
7488
+ el._h_sidebar_menu_item.isSub = true;
7489
+ break;
7490
+ } else if (parent.getAttribute("data-slot") === "sidebar") {
7491
+ break;
7492
+ }
7493
+ parent = parent.parentElement;
7494
+ }
7495
+ if (!el._h_sidebar_menu_item.isSub) {
7496
+ el.classList.add("group/menu-item", "relative");
7497
+ } else {
7498
+ el.classList.add("relative");
7394
7499
  }
7395
- el.classList.add("group/menu-item", "relative");
7396
- el.setAttribute("type", "button");
7397
7500
  el.setAttribute("data-slot", "sidebar-menu-item");
7501
+ if (expression) {
7502
+ const getCollapsed = evaluateLater(expression);
7503
+ effect(() => {
7504
+ getCollapsed((collapsed) => {
7505
+ el._h_sidebar_menu_item.state.collapsed = collapsed;
7506
+ });
7507
+ });
7508
+ }
7398
7509
  });
7399
- Alpine.directive("h-sidebar-menu-button", (el) => {
7400
- if (el.tagName !== "BUTTON") {
7401
- throw new Error(`${original} must be a button`);
7510
+ Alpine.directive("h-sidebar-menu-button", (el, { original }, { cleanup, Alpine: Alpine2 }) => {
7511
+ if (el.tagName !== "BUTTON" && el.tagName !== "A") {
7512
+ throw new Error(`${original} must be a button or a link`);
7513
+ } else if (el.tagName === "BUTTON") {
7514
+ el.setAttribute("type", "button");
7402
7515
  }
7516
+ const menuItem = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_menu_item"));
7403
7517
  el.classList.add(
7404
- "peer/menu-button",
7405
7518
  "flex",
7406
7519
  "w-full",
7407
7520
  "items-center",
7408
7521
  "gap-2",
7409
7522
  "overflow-hidden",
7410
7523
  "rounded-md",
7411
- "p-2",
7412
- "text-left",
7413
- "text-sm",
7414
7524
  "align-middle",
7525
+ "[&>span]:align-middle",
7415
7526
  "outline-hidden",
7416
7527
  "ring-sidebar-ring",
7417
- "transition-[width,height,padding]",
7418
7528
  "hover:bg-sidebar-secondary",
7419
7529
  "hover:text-sidebar-secondary-foreground",
7420
7530
  "focus-visible:ring-2",
@@ -7422,25 +7532,14 @@
7422
7532
  "active:text-sidebar-primary-foreground",
7423
7533
  "disabled:pointer-events-none",
7424
7534
  "disabled:opacity-50",
7425
- "group-has-data-[sidebar=menu-action]/menu-item:pr-8",
7426
7535
  "aria-disabled:pointer-events-none",
7427
7536
  "aria-disabled:opacity-50",
7428
7537
  "data-[active=true]:bg-sidebar-primary",
7429
- "data-[active=true]:font-medium",
7430
7538
  "data-[active=true]:text-sidebar-primary-foreground",
7431
- "data-[state=open]:hover:bg-sidebar-secondary",
7432
- "data-[state=open]:hover:text-sidebar-secondary-foreground",
7433
- "group-data-[collapsed=true]/sidebar:!size-8",
7434
- "group-data-[collapsed=true]/sidebar:!p-2",
7435
- "group-data-[collapsed=true]/sidebar:[&>*:not(svg:first-child):not([data-slot=menu])]:!hidden",
7436
7539
  "[&>span]:truncate",
7437
- "[&>span]:align-middle",
7438
7540
  "[&>svg]:size-4",
7439
- "[&>svg]:shrink-0",
7440
- "[&>svg:not(:first-child):last-child]:ml-auto"
7541
+ "[&>svg]:shrink-0"
7441
7542
  );
7442
- el.setAttribute("type", "button");
7443
- if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-button");
7444
7543
  const sizes = {
7445
7544
  default: ["h-8", "text-sm"],
7446
7545
  sm: ["h-7", "text-xs"],
@@ -7451,22 +7550,77 @@
7451
7550
  el.classList.add(...sizes[size3]);
7452
7551
  }
7453
7552
  }
7454
- if (!el.hasAttribute("data-size")) el.setAttribute("data-size", "default");
7455
- setSize2(el.getAttribute("data-size"));
7553
+ setSize2(el.getAttribute("data-size") || "default");
7554
+ if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-button");
7555
+ if (menuItem && menuItem._h_sidebar_menu_item.isSub) {
7556
+ el.classList.add("text-sidebar-foreground", "h-7", "min-w-0", "-translate-x-px", "px-2", "[&>svg:not(:first-child):last-child]:ml-auto", "group-data-[collapsed=true]/sidebar:hidden");
7557
+ if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-sub-button");
7558
+ } else {
7559
+ el.classList.add(
7560
+ "peer/menu-button",
7561
+ "p-2",
7562
+ "text-left",
7563
+ "text-sm",
7564
+ "duration-200",
7565
+ "transition-[width,height,padding]",
7566
+ "group-has-data-[sidebar=menu-action]/menu-item:pr-8",
7567
+ "data-[active=true]:font-medium",
7568
+ "data-[state=open]:hover:bg-sidebar-secondary",
7569
+ "data-[state=open]:hover:text-sidebar-secondary-foreground",
7570
+ "group-data-[collapsed=true]/sidebar:!size-8",
7571
+ "group-data-[collapsed=true]/sidebar:!p-2",
7572
+ "group-data-[collapsed=true]/sidebar:[&>*:not(svg:first-child):not([data-slot=menu])]:!hidden"
7573
+ );
7574
+ }
7575
+ if (menuItem && menuItem._h_sidebar_menu_item.collapsable) {
7576
+ if (el.hasAttribute("id")) {
7577
+ menuItem._h_sidebar_menu_item.controlId = el.getAttribute("id");
7578
+ } else {
7579
+ menuItem._h_sidebar_menu_item.controlId = `sgl${v4_default()}`;
7580
+ el.setAttribute("id", menuItem._h_sidebar_menu_item.controlId);
7581
+ }
7582
+ menuItem._h_sidebar_menu_item.controls = `sgc${v4_default()}`;
7583
+ el.setAttribute("aria-controls", menuItem._h_sidebar_menu_item.controls);
7584
+ el.setAttribute("aria-expanded", !menuItem._h_sidebar_menu_item.state.collapsed);
7585
+ const handler = () => {
7586
+ menuItem._h_sidebar_menu_item.state.collapsed = !menuItem._h_sidebar_menu_item.state.collapsed;
7587
+ el.setAttribute("aria-expanded", !menuItem._h_sidebar_menu_item.state.collapsed);
7588
+ };
7589
+ el.appendChild(
7590
+ createSvg({
7591
+ icon: ChevronRight,
7592
+ classes: "ml-auto pointer-events-none size-4 shrink-0 transition-transform duration-200 [[aria-expanded=true]>&]:rotate-90",
7593
+ attrs: {
7594
+ "aria-hidden": true,
7595
+ role: "presentation"
7596
+ }
7597
+ })
7598
+ );
7599
+ el.addEventListener("click", handler);
7600
+ cleanup(() => {
7601
+ el.removeEventListener("click", handler);
7602
+ });
7603
+ } else {
7604
+ el.classList.add("[&>svg:not(:first-child):last-child]:ml-auto");
7605
+ }
7456
7606
  });
7457
7607
  Alpine.directive("h-sidebar-menu-action", (el, { modifiers }) => {
7458
7608
  el.classList.add(
7459
7609
  "text-sidebar-foreground",
7460
7610
  "ring-sidebar-ring",
7461
7611
  "hover:bg-sidebar-secondary",
7612
+ "active:bg-sidebar-secondary/70",
7462
7613
  "hover:text-sidebar-secondary-foreground",
7463
7614
  "peer-hover/menu-button:text-sidebar-secondary-foreground",
7615
+ "peer-active/menu-button:text-sidebar-primary-foreground",
7616
+ "peer-data-[active=true]/menu-button:text-sidebar-primary-foreground",
7464
7617
  "absolute",
7465
- "top-1.5",
7466
- "right-1.5",
7618
+ "top-0.5",
7619
+ "right-0.5",
7620
+ "bottom-0.5",
7467
7621
  "flex",
7468
7622
  "aspect-square",
7469
- "w-5",
7623
+ "h-auto",
7470
7624
  "items-center",
7471
7625
  "justify-center",
7472
7626
  "rounded-md",
@@ -7479,13 +7633,10 @@
7479
7633
  "after:absolute",
7480
7634
  "after:-inset-2",
7481
7635
  "md:after:hidden",
7482
- "peer-data-[size=sm]/menu-button:top-1",
7483
- "peer-data-[size=default]/menu-button:top-1.5",
7484
- "peer-data-[size=lg]/menu-button:top-2.5",
7485
7636
  "group-data-[collapsed=true]/sidebar:hidden"
7486
7637
  );
7487
7638
  if (modifiers.includes("autohide")) {
7488
- el.classList.add("peer-data-[active=true]/menu-button:text-sidebar-secondary-foreground", "group-focus-within/menu-item:opacity-100", "group-hover/menu-item:opacity-100", "data-[state=open]:opacity-100", "md:opacity-0");
7639
+ el.classList.add("group-focus-within/menu-item:opacity-100", "group-hover/menu-item:opacity-100", "data-[state=open]:opacity-100", "md:opacity-0");
7489
7640
  }
7490
7641
  if (el.tagName !== "BUTTON") {
7491
7642
  el.setAttribute("role", "button");
@@ -7494,30 +7645,11 @@
7494
7645
  }
7495
7646
  el.setAttribute("data-slot", "sidebar-menu-action");
7496
7647
  });
7497
- Alpine.directive("h-sidebar-menu-badge", (el) => {
7498
- el.classList.add(
7499
- "text-sidebar-foreground",
7500
- "pointer-events-none",
7501
- "absolute",
7502
- "right-1.5",
7503
- "flex",
7504
- "h-5",
7505
- "min-w-5",
7506
- "items-center",
7507
- "justify-center",
7508
- "rounded-md",
7509
- "px-1",
7510
- "text-xs",
7511
- "font-medium",
7512
- "tabular-nums",
7513
- "select-none",
7514
- "peer-hover/menu-button:text-sidebar-secondary-foreground",
7515
- "peer-data-[active=true]/menu-button:text-sidebar-primary-foreground",
7516
- "peer-data-[size=sm]/menu-button:top-1",
7517
- "peer-data-[size=default]/menu-button:top-1.5",
7518
- "peer-data-[size=lg]/menu-button:top-2.5",
7519
- "group-data-[collapsed=true]/sidebar:hidden"
7520
- );
7648
+ Alpine.directive("h-sidebar-menu-badge", (el, { original }) => {
7649
+ if (el.tagName !== "SPAN") {
7650
+ throw new Error(`${original} must be a span element`);
7651
+ }
7652
+ el.classList.add("flex-1", "pointer-events-none", "flex", "h-full", "min-w-min", "items-center", "justify-end", "text-xs", "font-medium", "tabular-nums", "select-none", "group-data-[collapsed=true]/sidebar:hidden");
7521
7653
  el.setAttribute("data-slot", "sidebar-menu-badge");
7522
7654
  });
7523
7655
  Alpine.directive("h-sidebar-menu-skeleton", (el, { modifiers }) => {
@@ -7538,68 +7670,27 @@
7538
7670
  el.setAttribute("data-slot", "sidebar-separator");
7539
7671
  el.setAttribute("role", "none");
7540
7672
  });
7541
- Alpine.directive("h-sidebar-menu-sub", (el, { modifiers }) => {
7542
- el.classList.add("vbox", "min-w-0", "translate-x-px", "gap-1", "py-0.5", "group-data-[collapsed=true]/sidebar:!hidden");
7543
- if (!modifiers.includes("flat")) {
7544
- el.classList.add("border-sidebar-border", "mx-3.5", "border-l", "px-2.5");
7673
+ Alpine.directive("h-sidebar-menu-sub", (el, { original }, { effect, Alpine: Alpine2 }) => {
7674
+ if (el.tagName !== "UL") {
7675
+ throw new Error(`${original} must be an ul element`);
7545
7676
  }
7546
- el.setAttribute("data-slot", "sidebar-menu-sub");
7547
- });
7548
- Alpine.directive("h-sidebar-menu-sub-item", (el) => {
7549
- el.classList.add("group/menu-sub-item", "relative");
7550
- el.setAttribute("data-slot", "sidebar-menu-sub-item");
7551
- });
7552
- Alpine.directive("h-sidebar-menu-sub-button", (el) => {
7553
- if (el.tagName !== "BUTTON") {
7554
- throw new Error(`${original} must be a button`);
7677
+ const menuItem = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_menu_item"));
7678
+ if (!menuItem) {
7679
+ throw new Error(`${original} must be placed inside a sidebar menu item`);
7555
7680
  }
7556
- el.classList.add(
7557
- "text-sidebar-foreground",
7558
- "ring-sidebar-ring",
7559
- "hover:bg-sidebar-secondary",
7560
- "hover:text-sidebar-secondary-foreground",
7561
- "active:bg-primary-secondary",
7562
- "active:text-sidebar-primary-foreground",
7563
- "[&>svg]:text-sidebar-secondary-foreground",
7564
- "flex",
7565
- "h-7",
7566
- "w-full",
7567
- "min-w-0",
7568
- "-translate-x-px",
7569
- "items-center",
7570
- "gap-2",
7571
- "overflow-hidden",
7572
- "rounded-md",
7573
- "px-2",
7574
- "align-middle",
7575
- "outline-hidden",
7576
- "focus-visible:ring-2",
7577
- "disabled:pointer-events-none",
7578
- "disabled:opacity-50",
7579
- "aria-disabled:pointer-events-none",
7580
- "aria-disabled:opacity-50",
7581
- "[&>span]:truncate",
7582
- "[&>span]:align-middle",
7583
- "[&>svg]:size-4",
7584
- "[&>svg]:shrink-0",
7585
- "[&>svg:not(:first-child):last-child]:ml-auto",
7586
- "data-[active=true]:bg-sidebar-primary",
7587
- "data-[active=true]:text-sidebar-primary-foreground",
7588
- "group-data-[collapsed=true]/sidebar:hidden"
7589
- );
7590
- el.setAttribute("type", "button");
7591
- el.setAttribute("data-slot", "sidebar-menu-sub-button");
7592
- const sizes = {
7593
- sm: ["text-xs"],
7594
- md: ["text-sm"]
7595
- };
7596
- function setSize2(size3) {
7597
- if (sizes.hasOwnProperty(size3)) {
7598
- el.classList.add(...sizes[size3]);
7599
- }
7681
+ el.classList.add("vbox", "min-w-0", "translate-x-px", "gap-1", "pl-2.5", "py-0.5", "ml-3.5", "data-[collapsed=true]:!hidden", "group-data-[collapsed=true]/sidebar:!hidden");
7682
+ if (el.getAttribute("data-line") !== "false") {
7683
+ el.classList.add("border-sidebar-border", "border-l");
7684
+ }
7685
+ el.setAttribute("data-slot", "sidebar-menu-sub");
7686
+ if (menuItem._h_sidebar_menu_item.collapsable) {
7687
+ el.setAttribute("id", menuItem._h_sidebar_menu_item.controls);
7688
+ el.setAttribute("aria-labelledby", menuItem._h_sidebar_menu_item.controlId);
7689
+ el.setAttribute("data-collapsed", menuItem._h_sidebar_menu_item.state.collapsed);
7690
+ effect(() => {
7691
+ el.setAttribute("data-collapsed", menuItem._h_sidebar_menu_item.state.collapsed);
7692
+ });
7600
7693
  }
7601
- if (!el.hasAttribute("data-size")) el.setAttribute("data-size", "md");
7602
- setSize2(el.getAttribute("data-size"));
7603
7694
  });
7604
7695
  Alpine.directive("h-sidebar-footer", (el) => {
7605
7696
  el.classList.add("vbox", "gap-2", "px-2", "h-12", "justify-center", "border-t");
@@ -7850,10 +7941,10 @@
7850
7941
  observer.disconnect();
7851
7942
  });
7852
7943
  });
7853
- Alpine.directive("h-split-panel", (el, { original: original2 }, { effect, cleanup, Alpine: Alpine2 }) => {
7944
+ Alpine.directive("h-split-panel", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
7854
7945
  const split = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_split"));
7855
7946
  if (!split) {
7856
- throw new Error(`${original2} must be inside an split element`);
7947
+ throw new Error(`${original} must be inside an split element`);
7857
7948
  }
7858
7949
  el.classList.add("flex", "shrink", "grow-0", "box-border", "min-w-0", "min-h-0", "overflow-visible");
7859
7950
  el.setAttribute("tabindex", "-1");
@@ -8373,7 +8464,7 @@
8373
8464
  el.setAttribute("role", "tablist");
8374
8465
  el.setAttribute("data-slot", "tab-list");
8375
8466
  });
8376
- Alpine.directive("h-tab", (el, { original: original2 }) => {
8467
+ Alpine.directive("h-tab", (el, { original }) => {
8377
8468
  el.classList.add(
8378
8469
  "cursor-pointer",
8379
8470
  "focus-visible:border-ring",
@@ -8420,8 +8511,8 @@
8420
8511
  );
8421
8512
  el.setAttribute("role", "tab");
8422
8513
  el.setAttribute("data-slot", "tab");
8423
- if (!el.hasAttribute("id")) throw new Error(`${original2}: Tabs must have an id`);
8424
- if (!el.hasAttribute("aria-controls")) throw new Error(`${original2}: aria-controls must be set to the tab-content id.`);
8514
+ if (!el.hasAttribute("id")) throw new Error(`${original}: Tabs must have an id`);
8515
+ if (!el.hasAttribute("aria-controls")) throw new Error(`${original}: aria-controls must be set to the tab-content id.`);
8425
8516
  });
8426
8517
  Alpine.directive("h-tab-action", (el) => {
8427
8518
  el.classList.add("cursor-pointer", "ml-auto", "rounded-md", "text-foreground", "hover:bg-secondary", "hover:text-secondary-foreground", "active:bg-secondary-active");
@@ -8455,13 +8546,13 @@
8455
8546
  el.setAttribute("role", "button");
8456
8547
  el.setAttribute("data-slot", "tab-list-action");
8457
8548
  });
8458
- Alpine.directive("h-tabs-content", (el, { original: original2 }) => {
8549
+ Alpine.directive("h-tabs-content", (el, { original }) => {
8459
8550
  el.classList.add("flex-1", "outline-none");
8460
8551
  el.setAttribute("role", "tabpanel");
8461
8552
  el.setAttribute("tabindex", "0");
8462
8553
  el.setAttribute("data-slot", "tabs-content");
8463
- if (!el.hasAttribute("id")) throw new Error(`${original2}: Tab content must have an id`);
8464
- if (!el.hasAttribute("aria-labelledby")) throw new Error(`${original2}: aria-labelledby must be set to the tab id.`);
8554
+ if (!el.hasAttribute("id")) throw new Error(`${original}: Tab content must have an id`);
8555
+ if (!el.hasAttribute("aria-labelledby")) throw new Error(`${original}: aria-labelledby must be set to the tab id.`);
8465
8556
  });
8466
8557
  }
8467
8558
 
@@ -8854,13 +8945,13 @@
8854
8945
  top.removeEventListener("click", el._h_timepicker.close);
8855
8946
  });
8856
8947
  });
8857
- Alpine.directive("h-time-picker-input", (el, { original: original2 }, { effect, cleanup, Alpine: Alpine2 }) => {
8948
+ Alpine.directive("h-time-picker-input", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
8858
8949
  if (el.tagName !== "INPUT") {
8859
- throw new Error(`${original2} must be a readonly input of type "text"`);
8950
+ throw new Error(`${original} must be a readonly input of type "text"`);
8860
8951
  }
8861
8952
  const timepicker = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_timepicker"));
8862
8953
  if (!timepicker) {
8863
- throw new Error(`${original2} must be inside a time-picker element`);
8954
+ throw new Error(`${original} must be inside a time-picker element`);
8864
8955
  }
8865
8956
  timepicker._h_timepicker.focusInput = () => {
8866
8957
  el.focus();
@@ -9177,7 +9268,7 @@
9177
9268
  timeContainer.addEventListener("click", setTime);
9178
9269
  el.appendChild(timeContainer);
9179
9270
  const hoursList = document.createElement("ul");
9180
- hoursList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9271
+ hoursList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9181
9272
  hoursList.setAttribute("role", "listbox");
9182
9273
  hoursList.setAttribute("tabindex", "-1");
9183
9274
  hoursList.setAttribute("aria-label", el.dataset.labelHours ?? "Select hour");
@@ -9194,7 +9285,7 @@
9194
9285
  hoursList.appendChild(hour);
9195
9286
  }
9196
9287
  const minutesList = document.createElement("ul");
9197
- minutesList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9288
+ minutesList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9198
9289
  minutesList.setAttribute("role", "listbox");
9199
9290
  minutesList.setAttribute("tabindex", "-1");
9200
9291
  minutesList.setAttribute("aria-label", el.dataset.labelMinutes ?? "Select minute");
@@ -9211,7 +9302,7 @@
9211
9302
  minutesList.appendChild(minute);
9212
9303
  }
9213
9304
  const secondsList = document.createElement("ul");
9214
- secondsList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9305
+ secondsList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9215
9306
  if (!timepicker._h_timepicker.seconds) {
9216
9307
  secondsList.classList.add("hidden");
9217
9308
  }
@@ -9231,7 +9322,7 @@
9231
9322
  secondsList.appendChild(second);
9232
9323
  }
9233
9324
  const periodList = document.createElement("ul");
9234
- periodList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9325
+ periodList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9235
9326
  if (!timepicker._h_timepicker.is12Hour) {
9236
9327
  periodList.classList.add("hidden");
9237
9328
  }
@@ -9509,7 +9600,7 @@
9509
9600
  el.removeEventListener("pointerleave", handler);
9510
9601
  });
9511
9602
  });
9512
- Alpine.directive("h-tooltip", (el, { original: original2 }, { effect }) => {
9603
+ Alpine.directive("h-tooltip", (el, { original }, { effect }) => {
9513
9604
  const tooltip = (() => {
9514
9605
  let sibling = el.previousElementSibling;
9515
9606
  while (sibling && !sibling.hasOwnProperty("_tooltip")) {
@@ -9518,7 +9609,7 @@
9518
9609
  return sibling;
9519
9610
  })();
9520
9611
  if (!tooltip) {
9521
- throw new Error(`${original2} must be placed after a tooltip trigger element`);
9612
+ throw new Error(`${original} must be placed after a tooltip trigger element`);
9522
9613
  }
9523
9614
  el.classList.add("absolute", "bg-foreground", "text-background", "z-50", "w-fit", "rounded-md", "px-3", "py-1.5", "text-xs", "text-balance");
9524
9615
  el.setAttribute("data-slot", "tooltip");
@@ -9724,9 +9815,9 @@
9724
9815
  });
9725
9816
  }
9726
9817
  });
9727
- Alpine.directive("h-tree-button", (el, { original: original2 }, { effect }) => {
9818
+ Alpine.directive("h-tree-button", (el, { original }, { effect }) => {
9728
9819
  const treeItem = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_tree_item"));
9729
- if (!treeItem) throw new Error(`${original2} must be inside a tree item`);
9820
+ if (!treeItem) throw new Error(`${original} must be inside a tree item`);
9730
9821
  el.classList.add(
9731
9822
  "flex",
9732
9823
  "w-full",
@@ -9881,7 +9972,7 @@
9881
9972
 
9882
9973
  // src/utils/template.js
9883
9974
  function template_default(Alpine) {
9884
- Alpine.directive("h-template", (el, { original: original2, expression }, { evaluate: evaluate2, Alpine: Alpine2, cleanup }) => {
9975
+ Alpine.directive("h-template", (el, { original, expression }, { evaluate: evaluate2, Alpine: Alpine2, cleanup }) => {
9885
9976
  if (el.hasAttribute(Alpine2.prefixed("data"))) {
9886
9977
  const template = evaluate2(expression);
9887
9978
  const clone = template.content.cloneNode(true).firstElementChild;
@@ -9895,7 +9986,7 @@
9895
9986
  clone.remove();
9896
9987
  });
9897
9988
  } else {
9898
- console.error(`${original2}: ${Alpine2.prefixed("data")} directive is missing`);
9989
+ console.error(`${original}: ${Alpine2.prefixed("data")} directive is missing`);
9899
9990
  }
9900
9991
  });
9901
9992
  }
@@ -9913,7 +10004,7 @@
9913
10004
  }
9914
10005
 
9915
10006
  // package.json
9916
- var version = "1.2.1";
10007
+ var version = "1.4.0";
9917
10008
 
9918
10009
  // src/index.js
9919
10010
  window.Harmonia = { getBreakpointListener, addColorSchemeListener, getColorScheme, removeColorSchemeListener, setColorScheme, version };