@codbex/harmonia 1.3.0 → 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
@@ -4637,7 +4637,7 @@
4637
4637
  if (!popover) {
4638
4638
  throw new Error(`${original} must be placed after a popover element`);
4639
4639
  }
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-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");
4641
4641
  el.setAttribute("data-slot", "popover");
4642
4642
  el.setAttribute("role", "dialog");
4643
4643
  el.setAttribute("tabindex", "-1");
@@ -6649,7 +6649,8 @@
6649
6649
  function select_default(Alpine) {
6650
6650
  Alpine.directive("h-select", (el, { modifiers }, { Alpine: Alpine2, cleanup }) => {
6651
6651
  el._h_select = Alpine2.reactive({
6652
- id: void 0,
6652
+ fieldLabelId: void 0,
6653
+ trigger: void 0,
6653
6654
  controls: `hsc${v4_default()}`,
6654
6655
  expanded: false,
6655
6656
  multiple: false,
@@ -6698,9 +6699,16 @@
6698
6699
  });
6699
6700
  Alpine.directive("h-select-input", (el, { original }, { effect, cleanup, Alpine: Alpine2 }) => {
6700
6701
  if (el.tagName !== "INPUT") {
6701
- throw new Error(`${original} must be a readonly input of type "text"`);
6702
+ throw new Error(`${original} must be an input of type "text"`);
6702
6703
  }
6703
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
+ })();
6704
6712
  if (!select) {
6705
6713
  throw new Error(`${original} must be inside a select element`);
6706
6714
  } else if (el.hasOwnProperty("_x_model")) {
@@ -6740,6 +6748,19 @@
6740
6748
  fakeTrigger.setAttribute("data-slot", "select-value");
6741
6749
  fakeTrigger.setAttribute("tabindex", "0");
6742
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
+ }
6743
6764
  function getPlaceholder() {
6744
6765
  if (!el.value) {
6745
6766
  const value = el.getAttribute("placeholder");
@@ -6752,17 +6773,10 @@
6752
6773
  }
6753
6774
  }
6754
6775
  getPlaceholder();
6755
- const observer = new MutationObserver((mutations) => {
6756
- mutations.forEach((mutation) => {
6757
- if (mutation.attributeName === "data-id") {
6758
- select._h_select.id = el.getAttribute("data-id");
6759
- fakeTrigger.setAttribute("id", select._h_select.id);
6760
- } else if (mutation.attributeName === "placeholder" && !select._h_select.label.length) {
6761
- getPlaceholder();
6762
- }
6763
- });
6776
+ const observer = new MutationObserver(() => {
6777
+ getPlaceholder();
6764
6778
  });
6765
- observer.observe(el, { attributes: true, attributeFilter: ["data-id", "placeholder"] });
6779
+ observer.observe(el, { attributes: true, attributeFilter: ["placeholder"] });
6766
6780
  effect(() => {
6767
6781
  if (select._h_select.label.length === 1) {
6768
6782
  displayValue.innerText = select._h_select.label[0];
@@ -6775,8 +6789,6 @@
6775
6789
  }
6776
6790
  });
6777
6791
  fakeTrigger.setAttribute("data-slot", "select-input");
6778
- select._h_select.id = el.hasAttribute("data-id") ? el.getAttribute("data-id") : `hs${v4_default()}`;
6779
- fakeTrigger.setAttribute("id", select._h_select.id);
6780
6792
  fakeTrigger.setAttribute("aria-controls", select._h_select.controls);
6781
6793
  fakeTrigger.setAttribute("aria-haspopup", "listbox");
6782
6794
  fakeTrigger.setAttribute("aria-autocomplete", "none");
@@ -6938,9 +6950,9 @@
6938
6950
  const onInputChange = () => {
6939
6951
  select._h_select.label.length = 0;
6940
6952
  for (let i = 0; i < select._h_select.listeners.length; i++) {
6941
- const label = select._h_select.listeners[i](select._h_model.get());
6942
- if (label) {
6943
- 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);
6944
6956
  }
6945
6957
  }
6946
6958
  };
@@ -6953,6 +6965,9 @@
6953
6965
  top.removeEventListener("click", close);
6954
6966
  el.removeEventListener("change", onInputChange);
6955
6967
  observer.disconnect();
6968
+ if (labelObserver) {
6969
+ labelObserver.disconnect();
6970
+ }
6956
6971
  });
6957
6972
  });
6958
6973
  Alpine.directive("h-select-content", (el, { original }, { effect, Alpine: Alpine2 }) => {
@@ -6963,17 +6978,15 @@
6963
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");
6964
6979
  el.setAttribute("data-slot", "select-content");
6965
6980
  el.setAttribute("role", "listbox");
6966
- el.setAttribute("role", "presentation");
6967
6981
  el.setAttribute("id", select._h_select.controls);
6968
6982
  el.setAttribute("tabindex", "-1");
6969
6983
  el.setAttribute("data-state", select._h_select.expanded ? "open" : "closed");
6970
- const control = select.querySelector(`#${select._h_select.id}`);
6971
- if (!control) {
6984
+ if (!select._h_select.trigger) {
6972
6985
  throw new Error(`${original}: trigger not found`);
6973
6986
  }
6974
6987
  let autoUpdateCleanup;
6975
6988
  function updatePosition() {
6976
- computePosition2(control, el, {
6989
+ computePosition2(select._h_select.trigger, el, {
6977
6990
  placement: el.getAttribute("data-align") || "bottom-start",
6978
6991
  middleware: [
6979
6992
  offset2(4),
@@ -6996,12 +7009,12 @@
6996
7009
  });
6997
7010
  }
6998
7011
  effect(() => {
6999
- el.setAttribute("aria-labelledby", select._h_select.id);
7012
+ el.setAttribute("aria-labelledby", select._h_select.fieldLabelId);
7000
7013
  });
7001
7014
  effect(() => {
7002
7015
  el.setAttribute("data-state", select._h_select.expanded ? "open" : "closed");
7003
7016
  if (select._h_select.expanded) {
7004
- autoUpdateCleanup = autoUpdate(control, el, updatePosition);
7017
+ autoUpdateCleanup = autoUpdate(select._h_select.trigger, el, updatePosition);
7005
7018
  } else {
7006
7019
  if (autoUpdateCleanup) autoUpdateCleanup();
7007
7020
  Object.assign(el.style, {
@@ -9255,7 +9268,7 @@
9255
9268
  timeContainer.addEventListener("click", setTime);
9256
9269
  el.appendChild(timeContainer);
9257
9270
  const hoursList = document.createElement("ul");
9258
- hoursList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9271
+ hoursList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9259
9272
  hoursList.setAttribute("role", "listbox");
9260
9273
  hoursList.setAttribute("tabindex", "-1");
9261
9274
  hoursList.setAttribute("aria-label", el.dataset.labelHours ?? "Select hour");
@@ -9272,7 +9285,7 @@
9272
9285
  hoursList.appendChild(hour);
9273
9286
  }
9274
9287
  const minutesList = document.createElement("ul");
9275
- minutesList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9288
+ minutesList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9276
9289
  minutesList.setAttribute("role", "listbox");
9277
9290
  minutesList.setAttribute("tabindex", "-1");
9278
9291
  minutesList.setAttribute("aria-label", el.dataset.labelMinutes ?? "Select minute");
@@ -9289,7 +9302,7 @@
9289
9302
  minutesList.appendChild(minute);
9290
9303
  }
9291
9304
  const secondsList = document.createElement("ul");
9292
- secondsList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9305
+ secondsList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9293
9306
  if (!timepicker._h_timepicker.seconds) {
9294
9307
  secondsList.classList.add("hidden");
9295
9308
  }
@@ -9309,7 +9322,7 @@
9309
9322
  secondsList.appendChild(second);
9310
9323
  }
9311
9324
  const periodList = document.createElement("ul");
9312
- periodList.classList.add("flex-1", "overflow-y-scroll", "[scrollbar-width:thin]");
9325
+ periodList.classList.add("flex-1", "overflow-y-auto", "[scrollbar-width:thin]");
9313
9326
  if (!timepicker._h_timepicker.is12Hour) {
9314
9327
  periodList.classList.add("hidden");
9315
9328
  }
@@ -9991,7 +10004,7 @@
9991
10004
  }
9992
10005
 
9993
10006
  // package.json
9994
- var version = "1.3.0";
10007
+ var version = "1.4.0";
9995
10008
 
9996
10009
  // src/index.js
9997
10010
  window.Harmonia = { getBreakpointListener, addColorSchemeListener, getColorScheme, removeColorSchemeListener, setColorScheme, version };