@codbex/harmonia 1.2.0 → 1.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.
@@ -6507,6 +6507,7 @@ function popover_default(Alpine) {
6507
6507
  const close = () => {
6508
6508
  el._popover.expanded = false;
6509
6509
  el.addEventListener("click", handler);
6510
+ setAttributes();
6510
6511
  };
6511
6512
  const handler = () => {
6512
6513
  el._popover.expanded = !el._popover.expanded;
@@ -7366,13 +7367,35 @@ function sidebar_default(Alpine) {
7366
7367
  el.classList.add("vbox", "min-h-0", "flex-1", "gap-2", "overflow-auto", "group-data-[collapsed=true]/sidebar:overflow-hidden");
7367
7368
  el.setAttribute("data-slot", "sidebar-content");
7368
7369
  });
7369
- Alpine.directive("h-sidebar-group", (el) => {
7370
+ Alpine.directive("h-sidebar-group", (el, { expression, modifiers }, { effect, evaluate: evaluate2, evaluateLater, Alpine: Alpine2 }) => {
7370
7371
  el.classList.add("relative", "vbox", "w-full", "min-w-0", "p-2");
7371
7372
  el.setAttribute("data-slot", "sidebar-group");
7373
+ el._h_sidebar_group = {
7374
+ collapsable: modifiers.includes("collapsed"),
7375
+ controlId: void 0,
7376
+ controls: void 0,
7377
+ state: Alpine2.reactive({
7378
+ collapsed: evaluate2(expression || "false")
7379
+ })
7380
+ };
7381
+ if (expression) {
7382
+ el._h_sidebar_group.state = Alpine2.reactive({
7383
+ collapsed: evaluate2(expression || "false")
7384
+ });
7385
+ const getCollapsed = evaluateLater(expression);
7386
+ effect(() => {
7387
+ getCollapsed((collapsed) => {
7388
+ el._h_sidebar_group.state.collapsed = collapsed;
7389
+ });
7390
+ });
7391
+ }
7372
7392
  });
7373
- Alpine.directive("h-sidebar-group-label", (el, { modifiers }) => {
7393
+ Alpine.directive("h-sidebar-group-label", (el, { original }, { cleanup }) => {
7394
+ const group = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_group"));
7395
+ if (!group) {
7396
+ throw new Error(`${original} must be placed inside a sidebar group`);
7397
+ }
7374
7398
  el.classList.add(
7375
- "text-sidebar-foreground/70",
7376
7399
  "ring-sidebar-ring",
7377
7400
  "flex",
7378
7401
  "h-8",
@@ -7380,7 +7403,6 @@ function sidebar_default(Alpine) {
7380
7403
  "items-center",
7381
7404
  "rounded-md",
7382
7405
  "px-2",
7383
- "text-xs",
7384
7406
  "font-medium",
7385
7407
  "outline-hidden",
7386
7408
  "transition-[margin,opacity]",
@@ -7391,8 +7413,39 @@ function sidebar_default(Alpine) {
7391
7413
  "[&>svg]:shrink-0",
7392
7414
  "group-data-[collapsed=true]/sidebar:!hidden"
7393
7415
  );
7394
- if (modifiers.includes("action")) el.classList.add("hover:bg-secondary-hover", "active:bg-secondary-active");
7395
7416
  el.setAttribute("data-slot", "sidebar-group-label");
7417
+ if (group._h_sidebar_group.collapsable) {
7418
+ el.classList.add("text-sidebar-foreground", "text-sm", "hover:bg-secondary-hover", "active:bg-secondary-active");
7419
+ if (el.hasAttribute("id")) {
7420
+ group._h_sidebar_group.controlId = el.getAttribute("id");
7421
+ } else {
7422
+ group._h_sidebar_group.controlId = `sgl${v4_default()}`;
7423
+ el.setAttribute("id", group._h_sidebar_group.controlId);
7424
+ }
7425
+ group._h_sidebar_group.controls = `sgc${v4_default()}`;
7426
+ el.setAttribute("aria-controls", group._h_sidebar_group.controls);
7427
+ el.setAttribute("aria-expanded", !group._h_sidebar_group.state.collapsed);
7428
+ const handler = () => {
7429
+ group._h_sidebar_group.state.collapsed = !group._h_sidebar_group.state.collapsed;
7430
+ el.setAttribute("aria-expanded", !group._h_sidebar_group.state.collapsed);
7431
+ };
7432
+ el.appendChild(
7433
+ createSvg({
7434
+ icon: ChevronRight,
7435
+ classes: "ml-auto pointer-events-none size-4 shrink-0 transition-transform duration-200 [[aria-expanded=true]>&]:rotate-90",
7436
+ attrs: {
7437
+ "aria-hidden": true,
7438
+ role: "presentation"
7439
+ }
7440
+ })
7441
+ );
7442
+ el.addEventListener("click", handler);
7443
+ cleanup(() => {
7444
+ el.removeEventListener("click", handler);
7445
+ });
7446
+ } else {
7447
+ el.classList.add("text-sidebar-foreground/70", "text-xs");
7448
+ }
7396
7449
  });
7397
7450
  Alpine.directive("h-sidebar-group-action", (el) => {
7398
7451
  el.classList.add(
@@ -7420,36 +7473,92 @@ function sidebar_default(Alpine) {
7420
7473
  "md:after:hidden",
7421
7474
  "group-data-[collapsed=true]/sidebar:hidden"
7422
7475
  );
7476
+ if (el.tagName !== "BUTTON") {
7477
+ el.setAttribute("role", "button");
7478
+ } else {
7479
+ el.setAttribute("type", "button");
7480
+ }
7423
7481
  el.setAttribute("data-slot", "sidebar-group-action");
7424
7482
  });
7425
- Alpine.directive("h-sidebar-group-content", (el) => {
7426
- el.classList.add("w-full", "text-sm");
7483
+ Alpine.directive("h-sidebar-group-content", (el, { original }, { effect }) => {
7484
+ const group = Alpine.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_group"));
7485
+ if (!group) {
7486
+ throw new Error(`${original} must be placed inside a sidebar group`);
7487
+ }
7488
+ el.classList.add("w-full", "text-sm", "data-[collapsed=true]:hidden", "group-data-[collapsed=true]/sidebar:!block");
7427
7489
  el.setAttribute("data-slot", "sidebar-group-content");
7490
+ if (group._h_sidebar_group.collapsable) {
7491
+ el.setAttribute("id", group._h_sidebar_group.controls);
7492
+ el.setAttribute("aria-labelledby", group._h_sidebar_group.controlId);
7493
+ el.setAttribute("data-collapsed", group._h_sidebar_group.state.collapsed);
7494
+ effect(() => {
7495
+ el.setAttribute("data-collapsed", group._h_sidebar_group.state.collapsed);
7496
+ });
7497
+ }
7428
7498
  });
7429
- Alpine.directive("h-sidebar-menu", (el) => {
7499
+ Alpine.directive("h-sidebar-menu", (el, { original }) => {
7500
+ if (el.tagName !== "UL") {
7501
+ throw new Error(`${original} must be an ul element`);
7502
+ }
7430
7503
  el.classList.add("vbox", "w-full", "min-w-0", "gap-1");
7431
7504
  el.setAttribute("data-slot", "sidebar-menu");
7432
7505
  });
7433
- Alpine.directive("h-sidebar-menu-item", (el) => {
7434
- el.classList.add("group/menu-item", "relative");
7506
+ Alpine.directive("h-sidebar-menu-item", (el, { original, expression, modifiers }, { effect, evaluate: evaluate2, evaluateLater, Alpine: Alpine2 }) => {
7507
+ if (el.tagName !== "LI") {
7508
+ throw new Error(`${original} must be a li element`);
7509
+ }
7510
+ el._h_sidebar_menu_item = {
7511
+ isSub: false,
7512
+ collapsable: modifiers.includes("collapsed"),
7513
+ controlId: void 0,
7514
+ controls: void 0,
7515
+ state: Alpine2.reactive({
7516
+ collapsed: evaluate2(expression || "false")
7517
+ })
7518
+ };
7519
+ let parent = el.parentElement;
7520
+ while (parent) {
7521
+ if (parent.getAttribute("data-slot") === "sidebar-menu-sub") {
7522
+ el._h_sidebar_menu_item.isSub = true;
7523
+ break;
7524
+ } else if (parent.getAttribute("data-slot") === "sidebar") {
7525
+ break;
7526
+ }
7527
+ parent = parent.parentElement;
7528
+ }
7529
+ if (!el._h_sidebar_menu_item.isSub) {
7530
+ el.classList.add("group/menu-item", "relative");
7531
+ } else {
7532
+ el.classList.add("relative");
7533
+ }
7435
7534
  el.setAttribute("data-slot", "sidebar-menu-item");
7535
+ if (expression) {
7536
+ const getCollapsed = evaluateLater(expression);
7537
+ effect(() => {
7538
+ getCollapsed((collapsed) => {
7539
+ el._h_sidebar_menu_item.state.collapsed = collapsed;
7540
+ });
7541
+ });
7542
+ }
7436
7543
  });
7437
- Alpine.directive("h-sidebar-menu-button", (el) => {
7544
+ Alpine.directive("h-sidebar-menu-button", (el, { original }, { cleanup, Alpine: Alpine2 }) => {
7545
+ if (el.tagName !== "BUTTON" && el.tagName !== "A") {
7546
+ throw new Error(`${original} must be a button or a link`);
7547
+ } else if (el.tagName === "BUTTON") {
7548
+ el.setAttribute("type", "button");
7549
+ }
7550
+ const menuItem = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_menu_item"));
7438
7551
  el.classList.add(
7439
- "peer/menu-button",
7440
7552
  "flex",
7441
7553
  "w-full",
7442
7554
  "items-center",
7443
7555
  "gap-2",
7444
7556
  "overflow-hidden",
7445
7557
  "rounded-md",
7446
- "p-2",
7447
- "text-left",
7448
- "text-sm",
7449
7558
  "align-middle",
7559
+ "[&>span]:align-middle",
7450
7560
  "outline-hidden",
7451
7561
  "ring-sidebar-ring",
7452
- "transition-[width,height,padding]",
7453
7562
  "hover:bg-sidebar-secondary",
7454
7563
  "hover:text-sidebar-secondary-foreground",
7455
7564
  "focus-visible:ring-2",
@@ -7457,24 +7566,14 @@ function sidebar_default(Alpine) {
7457
7566
  "active:text-sidebar-primary-foreground",
7458
7567
  "disabled:pointer-events-none",
7459
7568
  "disabled:opacity-50",
7460
- "group-has-data-[sidebar=menu-action]/menu-item:pr-8",
7461
7569
  "aria-disabled:pointer-events-none",
7462
7570
  "aria-disabled:opacity-50",
7463
7571
  "data-[active=true]:bg-sidebar-primary",
7464
- "data-[active=true]:font-medium",
7465
7572
  "data-[active=true]:text-sidebar-primary-foreground",
7466
- "data-[state=open]:hover:bg-sidebar-secondary",
7467
- "data-[state=open]:hover:text-sidebar-secondary-foreground",
7468
- "group-data-[collapsed=true]/sidebar:!size-8",
7469
- "group-data-[collapsed=true]/sidebar:!p-2",
7470
- "group-data-[collapsed=true]/sidebar:[&>*:not(svg:first-child):not([data-slot=menu])]:!hidden",
7471
7573
  "[&>span]:truncate",
7472
- "[&>span]:align-middle",
7473
7574
  "[&>svg]:size-4",
7474
- "[&>svg]:shrink-0",
7475
- "[&>svg:not(:first-child):last-child]:ml-auto"
7575
+ "[&>svg]:shrink-0"
7476
7576
  );
7477
- if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-button");
7478
7577
  const sizes = {
7479
7578
  default: ["h-8", "text-sm"],
7480
7579
  sm: ["h-7", "text-xs"],
@@ -7485,22 +7584,77 @@ function sidebar_default(Alpine) {
7485
7584
  el.classList.add(...sizes[size3]);
7486
7585
  }
7487
7586
  }
7488
- if (!el.hasAttribute("data-size")) el.setAttribute("data-size", "default");
7489
- setSize2(el.getAttribute("data-size"));
7587
+ setSize2(el.getAttribute("data-size") || "default");
7588
+ if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-button");
7589
+ if (menuItem && menuItem._h_sidebar_menu_item.isSub) {
7590
+ 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");
7591
+ if (!el.hasAttribute("data-slot")) el.setAttribute("data-slot", "sidebar-menu-sub-button");
7592
+ } else {
7593
+ el.classList.add(
7594
+ "peer/menu-button",
7595
+ "p-2",
7596
+ "text-left",
7597
+ "text-sm",
7598
+ "duration-200",
7599
+ "transition-[width,height,padding]",
7600
+ "group-has-data-[sidebar=menu-action]/menu-item:pr-8",
7601
+ "data-[active=true]:font-medium",
7602
+ "data-[state=open]:hover:bg-sidebar-secondary",
7603
+ "data-[state=open]:hover:text-sidebar-secondary-foreground",
7604
+ "group-data-[collapsed=true]/sidebar:!size-8",
7605
+ "group-data-[collapsed=true]/sidebar:!p-2",
7606
+ "group-data-[collapsed=true]/sidebar:[&>*:not(svg:first-child):not([data-slot=menu])]:!hidden"
7607
+ );
7608
+ }
7609
+ if (menuItem && menuItem._h_sidebar_menu_item.collapsable) {
7610
+ if (el.hasAttribute("id")) {
7611
+ menuItem._h_sidebar_menu_item.controlId = el.getAttribute("id");
7612
+ } else {
7613
+ menuItem._h_sidebar_menu_item.controlId = `sgl${v4_default()}`;
7614
+ el.setAttribute("id", menuItem._h_sidebar_menu_item.controlId);
7615
+ }
7616
+ menuItem._h_sidebar_menu_item.controls = `sgc${v4_default()}`;
7617
+ el.setAttribute("aria-controls", menuItem._h_sidebar_menu_item.controls);
7618
+ el.setAttribute("aria-expanded", !menuItem._h_sidebar_menu_item.state.collapsed);
7619
+ const handler = () => {
7620
+ menuItem._h_sidebar_menu_item.state.collapsed = !menuItem._h_sidebar_menu_item.state.collapsed;
7621
+ el.setAttribute("aria-expanded", !menuItem._h_sidebar_menu_item.state.collapsed);
7622
+ };
7623
+ el.appendChild(
7624
+ createSvg({
7625
+ icon: ChevronRight,
7626
+ classes: "ml-auto pointer-events-none size-4 shrink-0 transition-transform duration-200 [[aria-expanded=true]>&]:rotate-90",
7627
+ attrs: {
7628
+ "aria-hidden": true,
7629
+ role: "presentation"
7630
+ }
7631
+ })
7632
+ );
7633
+ el.addEventListener("click", handler);
7634
+ cleanup(() => {
7635
+ el.removeEventListener("click", handler);
7636
+ });
7637
+ } else {
7638
+ el.classList.add("[&>svg:not(:first-child):last-child]:ml-auto");
7639
+ }
7490
7640
  });
7491
7641
  Alpine.directive("h-sidebar-menu-action", (el, { modifiers }) => {
7492
7642
  el.classList.add(
7493
7643
  "text-sidebar-foreground",
7494
7644
  "ring-sidebar-ring",
7495
7645
  "hover:bg-sidebar-secondary",
7646
+ "active:bg-sidebar-secondary/70",
7496
7647
  "hover:text-sidebar-secondary-foreground",
7497
7648
  "peer-hover/menu-button:text-sidebar-secondary-foreground",
7649
+ "peer-active/menu-button:text-sidebar-primary-foreground",
7650
+ "peer-data-[active=true]/menu-button:text-sidebar-primary-foreground",
7498
7651
  "absolute",
7499
- "top-1.5",
7500
- "right-1.5",
7652
+ "top-0.5",
7653
+ "right-0.5",
7654
+ "bottom-0.5",
7501
7655
  "flex",
7502
7656
  "aspect-square",
7503
- "w-5",
7657
+ "h-auto",
7504
7658
  "items-center",
7505
7659
  "justify-center",
7506
7660
  "rounded-md",
@@ -7513,40 +7667,23 @@ function sidebar_default(Alpine) {
7513
7667
  "after:absolute",
7514
7668
  "after:-inset-2",
7515
7669
  "md:after:hidden",
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
7670
  "group-data-[collapsed=true]/sidebar:hidden"
7520
7671
  );
7521
7672
  if (modifiers.includes("autohide")) {
7522
- 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");
7673
+ el.classList.add("group-focus-within/menu-item:opacity-100", "group-hover/menu-item:opacity-100", "data-[state=open]:opacity-100", "md:opacity-0");
7674
+ }
7675
+ if (el.tagName !== "BUTTON") {
7676
+ el.setAttribute("role", "button");
7677
+ } else {
7678
+ el.setAttribute("type", "button");
7523
7679
  }
7524
7680
  el.setAttribute("data-slot", "sidebar-menu-action");
7525
7681
  });
7526
- Alpine.directive("h-sidebar-menu-badge", (el) => {
7527
- el.classList.add(
7528
- "text-sidebar-foreground",
7529
- "pointer-events-none",
7530
- "absolute",
7531
- "right-1.5",
7532
- "flex",
7533
- "h-5",
7534
- "min-w-5",
7535
- "items-center",
7536
- "justify-center",
7537
- "rounded-md",
7538
- "px-1",
7539
- "text-xs",
7540
- "font-medium",
7541
- "tabular-nums",
7542
- "select-none",
7543
- "peer-hover/menu-button:text-sidebar-secondary-foreground",
7544
- "peer-data-[active=true]/menu-button:text-sidebar-primary-foreground",
7545
- "peer-data-[size=sm]/menu-button:top-1",
7546
- "peer-data-[size=default]/menu-button:top-1.5",
7547
- "peer-data-[size=lg]/menu-button:top-2.5",
7548
- "group-data-[collapsed=true]/sidebar:hidden"
7549
- );
7682
+ Alpine.directive("h-sidebar-menu-badge", (el, { original }) => {
7683
+ if (el.tagName !== "SPAN") {
7684
+ throw new Error(`${original} must be a span element`);
7685
+ }
7686
+ 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");
7550
7687
  el.setAttribute("data-slot", "sidebar-menu-badge");
7551
7688
  });
7552
7689
  Alpine.directive("h-sidebar-menu-skeleton", (el, { modifiers }) => {
@@ -7567,64 +7704,27 @@ function sidebar_default(Alpine) {
7567
7704
  el.setAttribute("data-slot", "sidebar-separator");
7568
7705
  el.setAttribute("role", "none");
7569
7706
  });
7570
- Alpine.directive("h-sidebar-menu-sub", (el, { modifiers }) => {
7571
- el.classList.add("vbox", "min-w-0", "translate-x-px", "gap-1", "py-0.5", "group-data-[collapsed=true]/sidebar:!hidden");
7572
- if (!modifiers.includes("flat")) {
7573
- el.classList.add("border-sidebar-border", "mx-3.5", "border-l", "px-2.5");
7707
+ Alpine.directive("h-sidebar-menu-sub", (el, { original }, { effect, Alpine: Alpine2 }) => {
7708
+ if (el.tagName !== "UL") {
7709
+ throw new Error(`${original} must be an ul element`);
7710
+ }
7711
+ const menuItem = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_sidebar_menu_item"));
7712
+ if (!menuItem) {
7713
+ throw new Error(`${original} must be placed inside a sidebar menu item`);
7714
+ }
7715
+ 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");
7716
+ if (el.getAttribute("data-line") !== "false") {
7717
+ el.classList.add("border-sidebar-border", "border-l");
7574
7718
  }
7575
7719
  el.setAttribute("data-slot", "sidebar-menu-sub");
7576
- });
7577
- Alpine.directive("h-sidebar-menu-sub-item", (el) => {
7578
- el.classList.add("group/menu-sub-item", "relative");
7579
- el.setAttribute("data-slot", "sidebar-menu-sub-item");
7580
- });
7581
- Alpine.directive("h-sidebar-menu-sub-button", (el) => {
7582
- el.classList.add(
7583
- "text-sidebar-foreground",
7584
- "ring-sidebar-ring",
7585
- "hover:bg-sidebar-secondary",
7586
- "hover:text-sidebar-secondary-foreground",
7587
- "active:bg-primary-secondary",
7588
- "active:text-sidebar-primary-foreground",
7589
- "[&>svg]:text-sidebar-secondary-foreground",
7590
- "flex",
7591
- "h-7",
7592
- "w-full",
7593
- "min-w-0",
7594
- "-translate-x-px",
7595
- "items-center",
7596
- "gap-2",
7597
- "overflow-hidden",
7598
- "rounded-md",
7599
- "px-2",
7600
- "align-middle",
7601
- "outline-hidden",
7602
- "focus-visible:ring-2",
7603
- "disabled:pointer-events-none",
7604
- "disabled:opacity-50",
7605
- "aria-disabled:pointer-events-none",
7606
- "aria-disabled:opacity-50",
7607
- "[&>span]:truncate",
7608
- "[&>span]:align-middle",
7609
- "[&>svg]:size-4",
7610
- "[&>svg]:shrink-0",
7611
- "[&>svg:not(:first-child):last-child]:ml-auto",
7612
- "data-[active=true]:bg-sidebar-primary",
7613
- "data-[active=true]:text-sidebar-primary-foreground",
7614
- "group-data-[collapsed=true]/sidebar:hidden"
7615
- );
7616
- el.setAttribute("data-slot", "sidebar-menu-sub-button");
7617
- const sizes = {
7618
- sm: ["text-xs"],
7619
- md: ["text-sm"]
7620
- };
7621
- function setSize2(size3) {
7622
- if (sizes.hasOwnProperty(size3)) {
7623
- el.classList.add(...sizes[size3]);
7624
- }
7720
+ if (menuItem._h_sidebar_menu_item.collapsable) {
7721
+ el.setAttribute("id", menuItem._h_sidebar_menu_item.controls);
7722
+ el.setAttribute("aria-labelledby", menuItem._h_sidebar_menu_item.controlId);
7723
+ el.setAttribute("data-collapsed", menuItem._h_sidebar_menu_item.state.collapsed);
7724
+ effect(() => {
7725
+ el.setAttribute("data-collapsed", menuItem._h_sidebar_menu_item.state.collapsed);
7726
+ });
7625
7727
  }
7626
- if (!el.hasAttribute("data-size")) el.setAttribute("data-size", "md");
7627
- setSize2(el.getAttribute("data-size"));
7628
7728
  });
7629
7729
  Alpine.directive("h-sidebar-footer", (el) => {
7630
7730
  el.classList.add("vbox", "gap-2", "px-2", "h-12", "justify-center", "border-t");
@@ -9814,7 +9914,7 @@ function tree_default(Alpine) {
9814
9914
  }
9815
9915
 
9816
9916
  // package.json
9817
- var version = "1.2.0";
9917
+ var version = "1.3.0";
9818
9918
 
9819
9919
  // src/utils/breakpoint-listener.js
9820
9920
  function getBreakpointListener(handler, breakpoint = 768) {