@codbex/harmonia 0.7.0 → 0.8.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
@@ -606,7 +606,7 @@
606
606
  }
607
607
  };
608
608
  function button_default(Alpine) {
609
- Alpine.directive("h-button", (el, { modifiers }, { cleanup }) => {
609
+ Alpine.directive("h-button", (el, { original, modifiers }, { cleanup }) => {
610
610
  setButtonClasses(el);
611
611
  if (!el.hasAttribute("data-slot")) {
612
612
  el.setAttribute("data-slot", "button");
@@ -623,7 +623,7 @@
623
623
  el.classList.remove(...getButtonSize(lastSize, inGroup));
624
624
  el.classList.add(...getButtonSize(size3, inGroup));
625
625
  if (size3.startsWith("icon") && !el.hasAttribute("aria-labelledby") && !el.hasAttribute("aria-label")) {
626
- console.error('h-button: Icon-only buttons must have an "aria-label" or "aria-labelledby" attribute', el);
626
+ console.error(`${original}: Icon-only buttons must have an "aria-label" or "aria-labelledby" attribute`, el);
627
627
  }
628
628
  lastSize = size3;
629
629
  }
@@ -2167,7 +2167,7 @@
2167
2167
 
2168
2168
  // src/components/calendar.js
2169
2169
  function calendar_default(Alpine) {
2170
- Alpine.directive("h-calendar", (el, { expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
2170
+ Alpine.directive("h-calendar", (el, { original, expression }, { effect, evaluateLater, cleanup, Alpine: Alpine2 }) => {
2171
2171
  const datepicker = Alpine2.findClosest(el.parentElement, (parent) => parent.hasOwnProperty("_h_datepicker"));
2172
2172
  el.classList.add("border", "rounded-control", "gap-2", "p-2");
2173
2173
  el.setAttribute("tabindex", "-1");
@@ -2211,7 +2211,7 @@
2211
2211
  const onInputChange = () => {
2212
2212
  const newValue = new Date(datepicker._h_datepicker.input.value);
2213
2213
  if (isNaN(newValue)) {
2214
- console.error(`h-calendar: input value is not a valid date - ${datepicker._h_datepicker.input.value}`);
2214
+ console.error(`${original}: input value is not a valid date - ${datepicker._h_datepicker.input.value}`);
2215
2215
  datepicker._h_datepicker.input.setCustomValidity("Input value is not a valid date.");
2216
2216
  return;
2217
2217
  } else if (selected.getTime() !== newValue.getTime()) {
@@ -2228,7 +2228,7 @@
2228
2228
  if (el.hasOwnProperty("_x_model") && el._x_model.get()) {
2229
2229
  selected = new Date(el._x_model.get());
2230
2230
  if (isNaN(selected)) {
2231
- console.error(`h-calendar: input value is not a valid date - ${el._x_model.get()}`);
2231
+ console.error(`${original}: input value is not a valid date - ${el._x_model.get()}`);
2232
2232
  if (datepicker) datepicker._h_datepicker.input.setCustomValidity("Input value is not a valid date.");
2233
2233
  else el.setAttribute("data-invalid", "true");
2234
2234
  } else if (datepicker) {
@@ -8509,11 +8509,19 @@
8509
8509
  // src/utils/theme.js
8510
8510
  var colorSchemeKey = "codbex.harmonia.colorMode";
8511
8511
  var savedScheme = localStorage.getItem(colorSchemeKey);
8512
+ var callbacks = [];
8513
+ var onColorSchemeChange = (scheme) => {
8514
+ for (let i = 0; i < callbacks.length; i++) {
8515
+ callbacks[i](scheme);
8516
+ }
8517
+ };
8512
8518
  var colorSchemeChange = (event) => {
8513
8519
  if (event.matches) {
8514
8520
  document.documentElement.classList.add("dark");
8521
+ onColorSchemeChange("dark");
8515
8522
  } else {
8516
8523
  document.documentElement.classList.remove("dark");
8524
+ onColorSchemeChange("light");
8517
8525
  }
8518
8526
  };
8519
8527
  var initColorScheme = () => {
@@ -8533,15 +8541,19 @@
8533
8541
  document.documentElement.classList.add("dark");
8534
8542
  localStorage.setItem(colorSchemeKey, "dark");
8535
8543
  window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", colorSchemeChange);
8544
+ onColorSchemeChange("dark");
8536
8545
  } else if (mode === "light") {
8537
8546
  document.documentElement.classList.remove("dark");
8538
8547
  localStorage.setItem(colorSchemeKey, "light");
8539
8548
  window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", colorSchemeChange);
8549
+ onColorSchemeChange("light");
8540
8550
  } else {
8541
8551
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
8542
8552
  document.documentElement.classList.add("dark");
8553
+ onColorSchemeChange("dark");
8543
8554
  } else {
8544
8555
  document.documentElement.classList.remove("dark");
8556
+ onColorSchemeChange("light");
8545
8557
  }
8546
8558
  localStorage.setItem(colorSchemeKey, "auto");
8547
8559
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", colorSchemeChange);
@@ -8555,6 +8567,17 @@
8555
8567
  }
8556
8568
  return "light";
8557
8569
  };
8570
+ var addColorSchemeListener = (callback) => {
8571
+ callbacks.push(callback);
8572
+ };
8573
+ var removeColorSchemeListener = (callback) => {
8574
+ for (let i = 0; i < callbacks.length; i++) {
8575
+ if (callbacks[i] === callback) {
8576
+ callbacks.splice(i, 1);
8577
+ return;
8578
+ }
8579
+ }
8580
+ };
8558
8581
  initColorScheme();
8559
8582
 
8560
8583
  // src/utils/breakpoint-listener.js
@@ -8574,6 +8597,26 @@
8574
8597
  };
8575
8598
  }
8576
8599
 
8600
+ // src/utils/template.js
8601
+ function template_default(Alpine) {
8602
+ Alpine.directive("h-template", (el, { original, expression }, { evaluate: evaluate2, Alpine: Alpine2, cleanup }) => {
8603
+ if (el.hasAttribute(Alpine2.prefixed("data"))) {
8604
+ const template = evaluate2(expression);
8605
+ const clone = template.content.cloneNode(true).firstElementChild;
8606
+ Alpine2.addScopeToNode(clone, Alpine2.closestDataStack(el)[0], el.parentElement);
8607
+ Alpine2.mutateDom(() => {
8608
+ el.before(clone);
8609
+ Alpine2.initTree(clone);
8610
+ });
8611
+ cleanup(() => {
8612
+ clone.remove();
8613
+ });
8614
+ } else {
8615
+ console.error(`${original}: ${Alpine2.prefixed("data")} directive is missing`);
8616
+ }
8617
+ });
8618
+ }
8619
+
8577
8620
  // src/utils/focus.js
8578
8621
  function focus_default(Alpine) {
8579
8622
  Alpine.directive("h-focus", (el, { expression }, { effect, evaluateLater }) => {
@@ -8587,10 +8630,10 @@
8587
8630
  }
8588
8631
 
8589
8632
  // package.json
8590
- var version = "0.7.0";
8633
+ var version = "0.8.0";
8591
8634
 
8592
8635
  // src/index.js
8593
- window.Harmonia = { getBreakpointListener, getColorScheme, setColorScheme, version };
8636
+ window.Harmonia = { getBreakpointListener, addColorSchemeListener, getColorScheme, removeColorSchemeListener, setColorScheme, version };
8594
8637
  document.addEventListener("alpine:init", () => {
8595
8638
  window.Alpine.plugin(accordion_default);
8596
8639
  window.Alpine.plugin(alert_default);
@@ -8633,6 +8676,7 @@
8633
8676
  window.Alpine.plugin(toolbar_default);
8634
8677
  window.Alpine.plugin(tooltip_default);
8635
8678
  window.Alpine.plugin(focus_default);
8679
+ window.Alpine.plugin(template_default);
8636
8680
  });
8637
8681
  })();
8638
8682
  /*! Bundled license information: