@pure-ds/core 0.7.23 → 0.7.25
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/types/public/assets/js/pds-ask.d.ts +1 -2
- package/dist/types/public/assets/js/pds-ask.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds-autocomplete.d.ts +36 -25
- package/dist/types/public/assets/js/pds-autocomplete.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds-enhancers.d.ts +4 -4
- package/dist/types/public/assets/js/pds-enhancers.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds-manager.d.ts +159 -444
- package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds-toast.d.ts +6 -7
- package/dist/types/public/assets/js/pds-toast.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds.d.ts +3 -4
- package/dist/types/public/assets/js/pds.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts +3 -0
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -1
- package/package.json +1 -1
- package/packages/pds-cli/bin/templates/bootstrap/pds.config.js +14 -4
- package/public/assets/js/app.js +1 -1
- package/public/assets/js/pds-enhancers.js +1 -1
- package/public/assets/js/pds-manager.js +26 -26
- package/public/assets/pds/components/pds-live-edit.js +3 -8
- package/public/assets/pds/components/pds-omnibox.js +37 -1
- package/public/assets/pds/components/pds-toaster.js +35 -1
- package/public/assets/pds/core/pds-enhancers.js +1 -1
- package/public/assets/pds/core/pds-manager.js +26 -26
- package/src/js/pds-core/pds-enhancers.js +53 -8
- package/src/js/pds-core/pds-generator.js +1 -1
- package/src/js/pds-core/pds-live.js +5 -0
|
@@ -1321,12 +1321,6 @@ function buildFontFamilyOmniboxSettings() {
|
|
|
1321
1321
|
|
|
1322
1322
|
return items;
|
|
1323
1323
|
},
|
|
1324
|
-
action: (options) => {
|
|
1325
|
-
const input = document.querySelector("pds-omnibox");
|
|
1326
|
-
if (input) {
|
|
1327
|
-
input.value = options.text;
|
|
1328
|
-
}
|
|
1329
|
-
},
|
|
1330
1324
|
},
|
|
1331
1325
|
},
|
|
1332
1326
|
};
|
|
@@ -1891,6 +1885,8 @@ async function createConfiguredForm({
|
|
|
1891
1885
|
form.defineRenderer(
|
|
1892
1886
|
"font-family-omnibox",
|
|
1893
1887
|
({ id, path, value, attrs, set }) => {
|
|
1888
|
+
const omnibox = document.createElement("pds-omnibox");
|
|
1889
|
+
|
|
1894
1890
|
const resolveSelectedValue = (options, actionResult, selectionEvent) => {
|
|
1895
1891
|
if (typeof actionResult === "string" && actionResult.trim()) {
|
|
1896
1892
|
return actionResult;
|
|
@@ -1956,6 +1952,7 @@ async function createConfiguredForm({
|
|
|
1956
1952
|
);
|
|
1957
1953
|
if (selected) {
|
|
1958
1954
|
set(selected);
|
|
1955
|
+
omnibox.value = selected;
|
|
1959
1956
|
}
|
|
1960
1957
|
|
|
1961
1958
|
return actionResult;
|
|
@@ -1965,8 +1962,6 @@ async function createConfiguredForm({
|
|
|
1965
1962
|
}
|
|
1966
1963
|
)
|
|
1967
1964
|
);
|
|
1968
|
-
|
|
1969
|
-
const omnibox = document.createElement("pds-omnibox");
|
|
1970
1965
|
omnibox.id = id;
|
|
1971
1966
|
omnibox.setAttribute("name", path);
|
|
1972
1967
|
omnibox.setAttribute("item-grid", "0 1fr 0");
|
|
@@ -564,12 +564,15 @@ export class PdsOmnibox extends HTMLElement {
|
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
if (AutoComplete && typeof AutoComplete.connect === "function") {
|
|
567
|
+
const settingsWithDefaultActions = this.#normalizeSettings(
|
|
568
|
+
this.settings,
|
|
569
|
+
);
|
|
567
570
|
const settings = {
|
|
568
571
|
//debug: true,
|
|
569
572
|
iconHandler: (item) => {
|
|
570
573
|
return item.icon ? `<pds-icon icon="${item.icon}"></pds-icon>` : null;
|
|
571
574
|
},
|
|
572
|
-
...
|
|
575
|
+
...settingsWithDefaultActions,
|
|
573
576
|
};
|
|
574
577
|
|
|
575
578
|
const container = this.#input?.parentElement;
|
|
@@ -607,6 +610,39 @@ export class PdsOmnibox extends HTMLElement {
|
|
|
607
610
|
}
|
|
608
611
|
}
|
|
609
612
|
|
|
613
|
+
#normalizeSettings(settings) {
|
|
614
|
+
if (!settings || typeof settings !== "object") return settings;
|
|
615
|
+
const categories = settings.categories;
|
|
616
|
+
if (!categories || typeof categories !== "object") return settings;
|
|
617
|
+
|
|
618
|
+
const normalizedCategories = Object.fromEntries(
|
|
619
|
+
Object.entries(categories).map(([categoryName, categoryConfig]) => {
|
|
620
|
+
if (!categoryConfig || typeof categoryConfig !== "object") {
|
|
621
|
+
return [categoryName, categoryConfig];
|
|
622
|
+
}
|
|
623
|
+
if (typeof categoryConfig.action === "function") {
|
|
624
|
+
return [categoryName, categoryConfig];
|
|
625
|
+
}
|
|
626
|
+
return [
|
|
627
|
+
categoryName,
|
|
628
|
+
{
|
|
629
|
+
...categoryConfig,
|
|
630
|
+
action: (options = {}) => {
|
|
631
|
+
const nextValue = options?.text ?? options?.value ?? options?.id ?? "";
|
|
632
|
+
this.value = nextValue == null ? "" : String(nextValue);
|
|
633
|
+
return nextValue;
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
];
|
|
637
|
+
}),
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
return {
|
|
641
|
+
...settings,
|
|
642
|
+
categories: normalizedCategories,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
610
646
|
#wrapAutoCompleteResultsHandler(autoComplete) {
|
|
611
647
|
if (!autoComplete || autoComplete.__pdsSuggestionsWrapped) return;
|
|
612
648
|
autoComplete.__pdsSuggestionsWrapped = true;
|
|
@@ -24,6 +24,9 @@ export class AppToaster extends HTMLElement {
|
|
|
24
24
|
constructor() {
|
|
25
25
|
super();
|
|
26
26
|
this.toasts = [];
|
|
27
|
+
this.activeToastKeys = new Set();
|
|
28
|
+
this.activeToastIdsByKey = new Map();
|
|
29
|
+
this.activeToastKeysById = new Map();
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/**
|
|
@@ -197,9 +200,16 @@ export class AppToaster extends HTMLElement {
|
|
|
197
200
|
};
|
|
198
201
|
|
|
199
202
|
const config = { ...defaults, ...options };
|
|
203
|
+
config.type = this.#normalizeToastType(config.type);
|
|
200
204
|
|
|
201
205
|
// Calculate reading time (average 200 words per minute)
|
|
202
206
|
const messageText = String(message || "");
|
|
207
|
+
const dedupeKey = this.#createActiveToastKey(messageText, config.type);
|
|
208
|
+
const activeToastId = this.activeToastIdsByKey.get(dedupeKey);
|
|
209
|
+
if (activeToastId) {
|
|
210
|
+
return activeToastId;
|
|
211
|
+
}
|
|
212
|
+
|
|
203
213
|
const readingText = config.html ? messageText.replace(/<[^>]*>/g, " ") : messageText;
|
|
204
214
|
const wordCount = readingText.split(/\s+/).filter(Boolean).length;
|
|
205
215
|
const baseReadingTime = Math.max(2000, (wordCount / 200) * 60 * 1000); // minimum 2 seconds
|
|
@@ -208,7 +218,11 @@ export class AppToaster extends HTMLElement {
|
|
|
208
218
|
const multiplier = config.type === "error" ? 1.5 : 1;
|
|
209
219
|
const duration = config.duration || baseReadingTime * multiplier;
|
|
210
220
|
|
|
211
|
-
|
|
221
|
+
const toastId = this.#showToast(messageText, config, duration);
|
|
222
|
+
this.activeToastKeys.add(dedupeKey);
|
|
223
|
+
this.activeToastIdsByKey.set(dedupeKey, toastId);
|
|
224
|
+
this.activeToastKeysById.set(toastId, dedupeKey);
|
|
225
|
+
return toastId;
|
|
212
226
|
}
|
|
213
227
|
|
|
214
228
|
/*
|
|
@@ -363,6 +377,13 @@ export class AppToaster extends HTMLElement {
|
|
|
363
377
|
if (toastElement.parentNode === this.shadowRoot) {
|
|
364
378
|
this.shadowRoot.removeChild(toastElement);
|
|
365
379
|
}
|
|
380
|
+
|
|
381
|
+
const toastKey = this.activeToastKeysById.get(toastId);
|
|
382
|
+
if (toastKey) {
|
|
383
|
+
this.activeToastKeysById.delete(toastId);
|
|
384
|
+
this.activeToastIdsByKey.delete(toastKey);
|
|
385
|
+
this.activeToastKeys.delete(toastKey);
|
|
386
|
+
}
|
|
366
387
|
}, 300);
|
|
367
388
|
}
|
|
368
389
|
|
|
@@ -381,9 +402,22 @@ export class AppToaster extends HTMLElement {
|
|
|
381
402
|
while (this.shadowRoot.firstChild) {
|
|
382
403
|
this.shadowRoot.removeChild(this.shadowRoot.firstChild);
|
|
383
404
|
}
|
|
405
|
+
this.activeToastKeys.clear();
|
|
406
|
+
this.activeToastIdsByKey.clear();
|
|
407
|
+
this.activeToastKeysById.clear();
|
|
384
408
|
}, 300);
|
|
385
409
|
}
|
|
386
410
|
|
|
411
|
+
#normalizeToastType(type) {
|
|
412
|
+
if (type === "info") return "information";
|
|
413
|
+
if (type === "danger") return "error";
|
|
414
|
+
return type || "information";
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
#createActiveToastKey(message, type) {
|
|
418
|
+
return `${String(type || "information").trim().toLowerCase()}::${String(message || "").trim()}`;
|
|
419
|
+
}
|
|
420
|
+
|
|
387
421
|
/*
|
|
388
422
|
* Programmatically close the toast associated with a button click.
|
|
389
423
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var F=[{selector:".accordion"},{selector:"nav[data-dropdown]"},{selector:"label[data-toggle]"},{selector:"label[data-color]"},{selector:'input[type="range"]'},{selector:"form[data-required]"},{selector:"fieldset[role=group][data-open]"},{selector:"[data-clip]"},{selector:"button, a[class*='btn-']"}];function W(t){t.dataset.enhancedAccordion||(t.dataset.enhancedAccordion="true",t.addEventListener("toggle",e=>{e.target.open&&e.target.parentElement===t&&t.querySelectorAll(":scope > details[open]").forEach(n=>{n!==e.target&&(n.open=!1)})},!0))}function H(t){if(t.dataset.enhancedDropdown)return;t.dataset.enhancedDropdown="true";let e=t.lastElementChild;if(!e)return;let n=t.querySelector("[data-dropdown-toggle]")||t.querySelector("button");n&&!n.hasAttribute("type")&&n.setAttribute("type","button"),e.id||(e.id=`dropdown-${Math.random().toString(36).slice(2,9)}`);let o=e.tagName?.toLowerCase()==="menu",a=8;o&&!e.hasAttribute("role")&&e.setAttribute("role","menu"),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true"),n&&(n.setAttribute("aria-haspopup","true"),n.setAttribute("aria-controls",e.id),n.setAttribute("aria-expanded","false"));let c=()=>{let s=e.getAttribute("style");e.style.visibility="hidden",e.style.display="inline-block",e.style.pointerEvents="none";let h=e.getBoundingClientRect(),f=Math.max(e.offsetWidth||0,e.scrollWidth||0,h.width||0,1),d=Math.max(e.offsetHeight||0,e.scrollHeight||0,h.height||0,1);return s===null?e.removeAttribute("style"):e.setAttribute("style",s),{width:f,height:d}},i=()=>{let s=(t.getAttribute("data-direction")||t.getAttribute("data-dropdown-direction")||t.getAttribute("data-mode")||"auto").toLowerCase();if(s==="up"||s==="down")return s;let h=(n||t).getBoundingClientRect(),{height:f}=c(),d=Math.max(0,window.innerHeight-h.bottom),b=Math.max(0,h.top),v=d>=f,y=b>=f;return v&&!y?"down":y&&!v?"up":v&&y?"down":b>d?"up":"down"},r=()=>{let s=(t.getAttribute("data-align")||t.getAttribute("data-dropdown-align")||"auto").toLowerCase();if(s==="left"||s==="right"||s==="start"||s==="end")return s==="start"?"left":s==="end"?"right":s;let h=(n||t).getBoundingClientRect(),{width:f}=c(),d=Math.max(0,window.innerWidth-h.left),b=Math.max(0,h.right),v=d>=f,y=b>=f;return v&&!y?"left":y&&!v?"right":v&&y?"left":b>d?"right":"left"},p=(s,h=8)=>{let f=getComputedStyle(t).getPropertyValue(s).trim();if(!f)return h;let d=document.createElement("span");d.style.position="fixed",d.style.visibility="hidden",d.style.pointerEvents="none",d.style.height=f,document.body.appendChild(d);let b=Number.parseFloat(getComputedStyle(d).height);return d.remove(),Number.isFinite(b)?b:h},u=()=>{e.style.removeProperty("position"),e.style.removeProperty("left"),e.style.removeProperty("top"),e.style.removeProperty("right"),e.style.removeProperty("bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("max-width"),e.style.removeProperty("max-inline-size"),e.style.removeProperty("max-height"),e.style.removeProperty("overflow")},l=()=>{e.getAttribute("aria-hidden")==="false"&&(u(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{w()})}))},w=()=>{if(e.getAttribute("aria-hidden")!=="false")return;let s=(n||t).getBoundingClientRect(),h=window.visualViewport,f=h?.width||document.documentElement?.clientWidth||window.innerWidth,d=h?.height||document.documentElement?.clientHeight||window.innerHeight,b=h?.offsetLeft||0,v=h?.offsetTop||0,y=Math.max(1,f-a*2),T=Math.max(1,d-a*2);e.style.maxWidth=`${Math.round(y)}px`,e.style.maxInlineSize=`${Math.round(y)}px`,e.style.maxHeight=`${Math.round(T)}px`,e.style.overflow="auto";let{width:k,height:M}=c(),q=p("--spacing-2",8),P=i(),R=r();t.dataset.dropdownDirection=P,t.dataset.dropdownAlign=R;let C=R==="right"?s.right-k:s.left;k>=y-1?C=b+a:C=Math.max(b+a,Math.min(C,b+f-k-a));let S=P==="up"?s.top-q-M:s.bottom+q;S=Math.max(v+a,Math.min(S,v+d-M-a)),e.style.position="fixed",e.style.left=`${Math.round(C)}px`,e.style.top=`${Math.round(S)}px`,e.style.right="auto",e.style.bottom="auto",e.style.marginTop="0",e.style.marginBottom="0"},g=null,E=()=>{g||(g=()=>w(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0))},L=()=>{g&&(window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0),g=null)},m=null,O=()=>{m||typeof document>"u"||(m=()=>{e.getAttribute("aria-hidden")==="false"&&(t.dataset.dropdownDirection=i(),t.dataset.dropdownAlign=r(),l(),setTimeout(()=>{e.getAttribute("aria-hidden")==="false"&&l()},50),setTimeout(()=>{e.getAttribute("aria-hidden")==="false"&&l()},150))},document.addEventListener("pds:config-changed",m))},D=()=>{!m||typeof document>"u"||(document.removeEventListener("pds:config-changed",m),m=null)},A=null,I=()=>{t.dataset.dropdownDirection=i(),t.dataset.dropdownAlign=r(),e.setAttribute("aria-hidden","false"),n?.setAttribute("aria-expanded","true"),E(),O(),l(),A||(A=s=>{(s.composedPath?s.composedPath():[s.target]).some(d=>d===t)||x()},setTimeout(()=>{document.addEventListener("click",A)},0))},x=()=>{e.setAttribute("aria-hidden","true"),n?.setAttribute("aria-expanded","false"),L(),D(),u(),A&&(document.removeEventListener("click",A),A=null)},B=()=>{e.getAttribute("aria-hidden")==="false"?x():I()};n?.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),B()}),t.addEventListener("keydown",s=>{s.key==="Escape"&&(x(),n?.focus())}),t.addEventListener("focusout",s=>{s.relatedTarget&&((s.composedPath?s.composedPath():[s.relatedTarget]).some(d=>d===t)||x())})}function N(t){if(t.dataset.enhancedToggle)return;t.dataset.enhancedToggle="true";let e=t.querySelector('input[type="checkbox"]');if(!e)return;t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.setAttribute("role","switch"),t.setAttribute("aria-checked",e.checked?"true":"false");let n=document.createElement("span");n.className="toggle-switch",n.setAttribute("role","presentation"),n.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="toggle-knob",n.appendChild(o),t.insertBefore(n,e.nextSibling);let a=()=>{t.setAttribute("aria-checked",e.checked?"true":"false")},c=()=>{e.disabled||(e.checked=!e.checked,a(),e.dispatchEvent(new Event("change",{bubbles:!0})))};t.addEventListener("click",i=>{i.preventDefault(),c()}),t.addEventListener("keydown",i=>{(i.key===" "||i.key==="Enter")&&(i.preventDefault(),c())}),e.addEventListener("change",a)}function $(t){if(t.dataset.enhancedColorInput)return;let e=t.querySelector('input[type="color"]');if(!e)return;t.dataset.enhancedColorInput="true";let n=t.querySelector(":scope > .color-control"),o=t.querySelector(":scope > .color-control > .color-swatch"),a=t.querySelector(":scope > .color-control > output");n||(n=document.createElement("span"),n.className="color-control",e.before(n)),o||(o=document.createElement("span"),o.className="color-swatch",n.appendChild(o)),e.parentElement!==o&&o.appendChild(e),a||(a=document.createElement("output"),n.appendChild(a));let c=()=>{if(e.dataset.colorUnset==="1"){a.value="",a.textContent="not set",n.dataset.value="",n.dataset.unset="1",o.dataset.unset="1";return}a.value=e.value,a.textContent=e.value,n.dataset.value=e.value,delete n.dataset.unset,delete o.dataset.unset};c();let i=()=>{e.dataset.colorUnset==="1"&&(e.dataset.colorUnset="0"),c()};e.addEventListener("input",i,{passive:!0}),e.addEventListener("change",i,{passive:!0})}function U(t){if(t.dataset.enhancedRange)return;let e=i=>{if(t.dataset.enhancedRangeProgrammatic)return;t.dataset.enhancedRangeProgrammatic="1";let r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),"value")||Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");r?.get&&r?.set&&Object.defineProperty(t,"value",{configurable:!0,enumerable:r.enumerable,get(){return r.get.call(this)},set(u){r.set.call(this,u),i()}}),new MutationObserver(u=>{u.some(w=>{let g=w.attributeName;return g==="value"||g==="min"||g==="max"})&&i()}).observe(t,{attributes:!0,attributeFilter:["value","min","max"]})},n=t.closest("label"),o=n?.classList.contains("range-output"),a=t.id||`range-${Math.random().toString(36).substring(2,11)}`,c=`${a}-output`;if(t.id=a,o){let i=n.querySelector("span");if(i&&!i.classList.contains("range-output-wrapper")){let r=document.createElement("span");r.className="range-output-wrapper",r.style.display="flex",r.style.justifyContent="space-between",r.style.alignItems="center";let p=document.createElement("span");p.textContent=i.textContent,r.appendChild(p);let u=document.createElement("output");u.id=c,u.setAttribute("for",a),u.style.color="var(--surface-text-secondary, var(--color-text-secondary))",u.style.fontSize="0.875rem",u.textContent=t.value,r.appendChild(u),i.textContent="",i.appendChild(r);let l=()=>{u.textContent=t.value};t.addEventListener("input",l),t.addEventListener("change",l),e(l),l()}}else{let i=t.closest(".range-container");i||(i=document.createElement("div"),i.className="range-container",t.parentNode?.insertBefore(i,t),i.appendChild(t)),i.style.position="relative";let r=document.createElement("output");r.id=c,r.setAttribute("for",a),r.className="range-bubble",r.setAttribute("aria-live","polite"),i.appendChild(r);let p=()=>{let w=parseFloat(t.min)||0,g=parseFloat(t.max)||100,E=parseFloat(t.value),L=(E-w)/(g-w);r.style.left=`calc(${L*100}% )`,r.textContent=String(E)},u=()=>r.classList.add("visible"),l=()=>r.classList.remove("visible");t.addEventListener("input",p),t.addEventListener("pointerdown",u),t.addEventListener("pointerup",l),t.addEventListener("pointerleave",l),t.addEventListener("focus",u),t.addEventListener("blur",l),t.addEventListener("change",p),e(p),p()}t.dataset.enhancedRange="1"}function z(t){if(t.dataset.enhancedRequired)return;t.dataset.enhancedRequired="true";let e=n=>{let o;if(n.closest("[role$=group]")?o=n.closest("[role$=group]").querySelector("legend"):o=n.closest("label"),!o||o.querySelector(".required-asterisk"))return;let a=document.createElement("span");a.classList.add("required-asterisk"),a.textContent="*",a.style.marginLeft="4px";let c=o.querySelector("span, [data-label]");if(c)c.appendChild(a);else{let r=o.querySelector("input, select, textarea");r?o.insertBefore(a,r):o.appendChild(a)}let i=n.closest("form");if(i&&!i.querySelector(".required-legend")){let r=document.createElement("small");r.classList.add("required-legend"),r.textContent="* Required fields",i.insertBefore(r,i.querySelector(".form-actions")||i.lastElementChild)}};t.querySelectorAll("[required]").forEach(n=>{e(n)})}function j(t){if(t.dataset.enhancedOpenGroup)return;t.dataset.enhancedOpenGroup="true",t.classList.add("flex","flex-wrap","buttons");let e=document.createElement("input");e.type="text",e.placeholder="Add item...",e.classList.add("input-text","input-sm"),e.style.width="auto";let n=()=>t.querySelector('input[type="radio"], input[type="checkbox"]');t.appendChild(e),e.addEventListener("keydown",o=>{if(o.key==="Enter"||o.key==="Tab"){let a=e.value.trim();if(a){o.preventDefault();let c=n(),i=c?.type==="radio"?"radio":"checkbox",r=`open-group-${Math.random().toString(36).substring(2,11)}`,p=document.createElement("label"),u=document.createElement("span");u.setAttribute("data-label",""),u.textContent=a;let l=document.createElement("input");l.type=i,l.name=c?.name||t.getAttribute("data-name")||"open-group",l.value=a,l.id=r,p.appendChild(u),p.appendChild(l),t.insertBefore(p,e),e.value=""}}else if(o.key==="Backspace"&&e.value===""){o.preventDefault();let a=t.querySelectorAll("label");a.length>0&&a[a.length-1].remove()}})}function V(t){if(t.dataset.enhancedClip)return;t.dataset.enhancedClip="true",t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.hasAttribute("role")||t.setAttribute("role","button");let e=()=>{let o=t.getAttribute("data-clip-open")==="true";t.setAttribute("aria-expanded",o?"true":"false")},n=()=>{let o=t.getAttribute("data-clip-open")==="true";t.setAttribute("data-clip-open",o?"false":"true"),e()};t.addEventListener("click",o=>{o.defaultPrevented||n()}),t.addEventListener("keydown",o=>{(o.key===" "||o.key==="Enter")&&(o.preventDefault(),n())}),e()}function G(t){if(t.dataset.enhancedBtnWorking)return;t.dataset.enhancedBtnWorking="true";let e=null,n=!1;new MutationObserver(a=>{a.forEach(c=>{if(c.attributeName==="class"){let i=t.classList.contains("btn-working"),r=t.querySelector("pds-icon");if(i)if(r)e||(e=r.getAttribute("icon")),r.setAttribute("icon","circle-notch");else{let p=document.createElement("pds-icon");p.setAttribute("icon","circle-notch"),p.setAttribute("size","sm"),t.insertBefore(p,t.firstChild),n=!0}else c.oldValue?.includes("btn-working")&&r&&(n?(r.remove(),n=!1):e&&(r.setAttribute("icon",e),e=null))}})}).observe(t,{attributes:!0,attributeFilter:["class"],attributeOldValue:!0})}var _=new Map([[".accordion",W],["nav[data-dropdown]",H],["label[data-toggle]",N],["label[data-color]",$],['input[type="range"]',U],["form[data-required]",z],["fieldset[role=group][data-open]",j],["[data-clip]",V],["button, a[class*='btn-']",G]]),J=F.map(t=>({...t,run:_.get(t.selector)||(()=>{})}));export{J as defaultPDSEnhancers};
|
|
1
|
+
var T=[{selector:".accordion"},{selector:"nav[data-dropdown]"},{selector:"label[data-toggle]"},{selector:"label[data-color]"},{selector:'input[type="range"]'},{selector:"form[data-required]"},{selector:"fieldset[role=group][data-open]"},{selector:"[data-clip]"},{selector:"button, a[class*='btn-']"}];function $(t){t.dataset.enhancedAccordion||(t.dataset.enhancedAccordion="true",t.addEventListener("toggle",e=>{e.target.open&&e.target.parentElement===t&&t.querySelectorAll(":scope > details[open]").forEach(n=>{n!==e.target&&(n.open=!1)})},!0))}function U(t){if(t.dataset.enhancedDropdown)return;t.dataset.enhancedDropdown="true";let e=t.lastElementChild;if(!e)return;let n=t.querySelector("[data-dropdown-toggle]")||t.querySelector("button");n&&!n.hasAttribute("type")&&n.setAttribute("type","button"),e.id||(e.id=`dropdown-${Math.random().toString(36).slice(2,9)}`);let a=e.tagName?.toLowerCase()==="menu",i=8;a&&!e.hasAttribute("role")&&e.setAttribute("role","menu"),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true"),n&&(n.setAttribute("aria-haspopup","true"),n.setAttribute("aria-controls",e.id),n.setAttribute("aria-expanded","false"));let u=()=>{let r=e.getAttribute("style");e.style.visibility="hidden",e.style.display="inline-block",e.style.pointerEvents="none";let c=e.getBoundingClientRect(),p=Math.max(e.offsetWidth||0,e.scrollWidth||0,c.width||0,1),d=Math.max(e.offsetHeight||0,e.scrollHeight||0,c.height||0,1);return r===null?e.removeAttribute("style"):e.setAttribute("style",r),{width:p,height:d}},s=()=>{let r=(t.getAttribute("data-direction")||t.getAttribute("data-dropdown-direction")||t.getAttribute("data-mode")||"auto").toLowerCase();if(r==="up"||r==="down")return r;let c=(n||t).getBoundingClientRect(),{height:p}=u(),d=Math.max(0,window.innerHeight-c.bottom),g=Math.max(0,c.top),v=d>=p,b=g>=p;return v&&!b?"down":b&&!v?"up":v&&b?"down":g>d?"up":"down"},o=()=>{let r=(t.getAttribute("data-align")||t.getAttribute("data-dropdown-align")||"auto").toLowerCase();if(r==="left"||r==="right"||r==="start"||r==="end")return r==="start"?"left":r==="end"?"right":r;let c=(n||t).getBoundingClientRect(),{width:p}=u(),d=Math.max(0,window.innerWidth-c.left),g=Math.max(0,c.right),v=d>=p,b=g>=p;return v&&!b?"left":b&&!v?"right":v&&b?"left":g>d?"right":"left"},f=(r,c=8)=>{let p=getComputedStyle(t).getPropertyValue(r).trim();if(!p)return c;let d=document.createElement("span");d.style.position="fixed",d.style.visibility="hidden",d.style.pointerEvents="none",d.style.height=p,document.body.appendChild(d);let g=Number.parseFloat(getComputedStyle(d).height);return d.remove(),Number.isFinite(g)?g:c},l=()=>{e.style.removeProperty("position"),e.style.removeProperty("left"),e.style.removeProperty("top"),e.style.removeProperty("right"),e.style.removeProperty("bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("max-width"),e.style.removeProperty("max-inline-size"),e.style.removeProperty("max-height"),e.style.removeProperty("overflow")},h=r=>{if(!r)return null;if(r.parentElement)return r.parentElement;let c=r.getRootNode?.();return c instanceof ShadowRoot?c.host:null},A=()=>{let r=h(e);for(;r&&r!==document.documentElement;){let c=getComputedStyle(r),p=c.contain||"",d=c.willChange||"";if(c.transform!=="none"||c.perspective!=="none"||c.filter!=="none"||c.backdropFilter!=="none"||p.includes("paint")||p.includes("layout")||p.includes("strict")||p.includes("content")||d.includes("transform")||d.includes("perspective")||d.includes("filter"))return!0;r=h(r)}return!1},m=()=>{e.getAttribute("aria-hidden")==="false"&&(l(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{E()})}))},E=()=>{if(e.getAttribute("aria-hidden")!=="false")return;if(A()){l();return}let r=(n||t).getBoundingClientRect(),c=window.visualViewport,p=c?.width||document.documentElement?.clientWidth||window.innerWidth,d=c?.height||document.documentElement?.clientHeight||window.innerHeight,g=c?.offsetLeft||0,v=c?.offsetTop||0,b=Math.max(1,p-i*2),H=Math.max(1,d-i*2);e.style.maxWidth=`${Math.round(b)}px`,e.style.maxInlineSize=`${Math.round(b)}px`,e.style.maxHeight=`${Math.round(H)}px`,e.style.overflow="auto";let{width:S,height:M}=u(),P=f("--spacing-2",8),R=s(),O=o();t.dataset.dropdownDirection=R,t.dataset.dropdownAlign=O;let k=O==="right"?r.right-S:r.left;S>=b-1?k=g+i:k=Math.max(g+i,Math.min(k,g+p-S-i));let q=R==="up"?r.top-P-M:r.bottom+P;q=Math.max(v+i,Math.min(q,v+d-M-i)),e.style.position="fixed",e.style.left=`${Math.round(k)}px`,e.style.top=`${Math.round(q)}px`,e.style.right="auto",e.style.bottom="auto",e.style.marginTop="0",e.style.marginBottom="0"},y=null,D=()=>{y||(y=()=>E(),window.addEventListener("resize",y),window.addEventListener("scroll",y,!0))},F=()=>{y&&(window.removeEventListener("resize",y),window.removeEventListener("scroll",y,!0),y=null)},x=null,w=null,B=()=>{x||typeof document>"u"||(x=()=>{e.getAttribute("aria-hidden")==="false"&&(t.dataset.dropdownDirection=s(),t.dataset.dropdownAlign=o(),w!==null&&cancelAnimationFrame(w),w=requestAnimationFrame(()=>{w=null,e.getAttribute("aria-hidden")==="false"&&E()}))},document.addEventListener("pds:config-changed",x))},I=()=>{!x||typeof document>"u"||(document.removeEventListener("pds:config-changed",x),x=null,w!==null&&(cancelAnimationFrame(w),w=null))},C=null,N=()=>{t.dataset.dropdownDirection=s(),t.dataset.dropdownAlign=o(),e.setAttribute("aria-hidden","false"),n?.setAttribute("aria-expanded","true"),D(),B(),m(),C||(C=r=>{(r.composedPath?r.composedPath():[r.target]).some(d=>d===t)||L()},setTimeout(()=>{document.addEventListener("click",C)},0))},L=()=>{e.setAttribute("aria-hidden","true"),n?.setAttribute("aria-expanded","false"),F(),I(),l(),C&&(document.removeEventListener("click",C),C=null)},W=()=>{e.getAttribute("aria-hidden")==="false"?L():N()};n?.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),W()}),t.addEventListener("keydown",r=>{r.key==="Escape"&&(L(),n?.focus())}),t.addEventListener("focusout",r=>{r.relatedTarget&&((r.composedPath?r.composedPath():[r.relatedTarget]).some(d=>d===t)||L())})}function z(t){if(t.dataset.enhancedToggle)return;t.dataset.enhancedToggle="true";let e=t.querySelector('input[type="checkbox"]');if(!e)return;t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.setAttribute("role","switch"),t.setAttribute("aria-checked",e.checked?"true":"false");let n=document.createElement("span");n.className="toggle-switch",n.setAttribute("role","presentation"),n.setAttribute("aria-hidden","true");let a=document.createElement("span");a.className="toggle-knob",n.appendChild(a),t.insertBefore(n,e.nextSibling);let i=()=>{t.setAttribute("aria-checked",e.checked?"true":"false")},u=()=>{e.disabled||(e.checked=!e.checked,i(),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))};t.addEventListener("click",s=>{s.preventDefault(),u()}),t.addEventListener("keydown",s=>{(s.key===" "||s.key==="Enter")&&(s.preventDefault(),u())}),e.addEventListener("change",i)}function V(t){if(t.dataset.enhancedColorInput)return;let e=t.querySelector('input[type="color"]');if(!e)return;t.dataset.enhancedColorInput="true";let n=t.querySelector(":scope > .color-control"),a=t.querySelector(":scope > .color-control > .color-swatch"),i=t.querySelector(":scope > .color-control > output");n||(n=document.createElement("span"),n.className="color-control",e.before(n)),a||(a=document.createElement("span"),a.className="color-swatch",n.appendChild(a)),e.parentElement!==a&&a.appendChild(e),i||(i=document.createElement("output"),n.appendChild(i));let u=()=>{if(e.dataset.colorUnset==="1"){i.value="",i.textContent="not set",n.dataset.value="",n.dataset.unset="1",a.dataset.unset="1";return}i.value=e.value,i.textContent=e.value,n.dataset.value=e.value,delete n.dataset.unset,delete a.dataset.unset};u();let s=()=>{e.dataset.colorUnset==="1"&&(e.dataset.colorUnset="0"),u()};e.addEventListener("input",s,{passive:!0}),e.addEventListener("change",s,{passive:!0})}function j(t){if(t.dataset.enhancedRange)return;let e=s=>{if(t.dataset.enhancedRangeProgrammatic)return;t.dataset.enhancedRangeProgrammatic="1";let o=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),"value")||Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");o?.get&&o?.set&&Object.defineProperty(t,"value",{configurable:!0,enumerable:o.enumerable,get(){return o.get.call(this)},set(l){o.set.call(this,l),s()}}),new MutationObserver(l=>{l.some(A=>{let m=A.attributeName;return m==="value"||m==="min"||m==="max"})&&s()}).observe(t,{attributes:!0,attributeFilter:["value","min","max"]})},n=t.closest("label"),a=n?.classList.contains("range-output"),i=t.id||`range-${Math.random().toString(36).substring(2,11)}`,u=`${i}-output`;if(t.id=i,a){let s=n.querySelector("span");if(s&&!s.classList.contains("range-output-wrapper")){let o=document.createElement("span");o.className="range-output-wrapper",o.style.display="flex",o.style.justifyContent="space-between",o.style.alignItems="center";let f=document.createElement("span");f.textContent=s.textContent,o.appendChild(f);let l=document.createElement("output");l.id=u,l.setAttribute("for",i),l.style.color="var(--surface-text-secondary, var(--color-text-secondary))",l.style.fontSize="0.875rem",l.textContent=t.value,o.appendChild(l),s.textContent="",s.appendChild(o);let h=()=>{l.textContent=t.value};t.addEventListener("input",h),t.addEventListener("change",h),e(h),h()}}else{let s=t.closest(".range-container");s||(s=document.createElement("div"),s.className="range-container",t.parentNode?.insertBefore(s,t),s.appendChild(t)),s.style.position="relative";let o=document.createElement("output");o.id=u,o.setAttribute("for",i),o.className="range-bubble",o.setAttribute("aria-live","polite"),s.appendChild(o);let f=()=>{let A=parseFloat(t.min)||0,m=parseFloat(t.max)||100,E=parseFloat(t.value),y=(E-A)/(m-A);o.style.left=`calc(${y*100}% )`,o.textContent=String(E)},l=()=>o.classList.add("visible"),h=()=>o.classList.remove("visible");t.addEventListener("input",f),t.addEventListener("pointerdown",l),t.addEventListener("pointerup",h),t.addEventListener("pointerleave",h),t.addEventListener("focus",l),t.addEventListener("blur",h),t.addEventListener("change",f),e(f),f()}t.dataset.enhancedRange="1"}function G(t){if(t.dataset.enhancedRequired)return;t.dataset.enhancedRequired="true";let e=n=>{let a;if(n.closest("[role$=group]")?a=n.closest("[role$=group]").querySelector("legend"):a=n.closest("label"),!a||a.querySelector(".required-asterisk"))return;let i=document.createElement("span");i.classList.add("required-asterisk"),i.textContent="*",i.style.marginLeft="4px";let u=a.querySelector("span, [data-label]");if(u)u.appendChild(i);else{let o=a.querySelector("input, select, textarea");o?a.insertBefore(i,o):a.appendChild(i)}let s=n.closest("form");if(s&&!s.querySelector(".required-legend")){let o=document.createElement("small");o.classList.add("required-legend"),o.textContent="* Required fields",s.insertBefore(o,s.querySelector(".form-actions")||s.lastElementChild)}};t.querySelectorAll("[required]").forEach(n=>{e(n)})}function _(t){if(t.dataset.enhancedOpenGroup)return;t.dataset.enhancedOpenGroup="true",t.classList.add("flex","flex-wrap","buttons");let e=document.createElement("input");e.type="text",e.placeholder="Add item...",e.classList.add("input-text","input-sm"),e.style.width="auto";let n=()=>t.querySelector('input[type="radio"], input[type="checkbox"]');t.appendChild(e),e.addEventListener("keydown",a=>{if(a.key==="Enter"||a.key==="Tab"){let i=e.value.trim();if(i){a.preventDefault();let u=n(),s=u?.type==="radio"?"radio":"checkbox",o=`open-group-${Math.random().toString(36).substring(2,11)}`,f=document.createElement("label"),l=document.createElement("span");l.setAttribute("data-label",""),l.textContent=i;let h=document.createElement("input");h.type=s,h.name=u?.name||t.getAttribute("data-name")||"open-group",h.value=i,h.id=o,f.appendChild(l),f.appendChild(h),t.insertBefore(f,e),e.value=""}}else if(a.key==="Backspace"&&e.value===""){a.preventDefault();let i=t.querySelectorAll("label");i.length>0&&i[i.length-1].remove()}})}function J(t){if(t.dataset.enhancedClip)return;t.dataset.enhancedClip="true",t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.hasAttribute("role")||t.setAttribute("role","button");let e=()=>{let a=t.getAttribute("data-clip-open")==="true";t.setAttribute("aria-expanded",a?"true":"false")},n=()=>{let a=t.getAttribute("data-clip-open")==="true";t.setAttribute("data-clip-open",a?"false":"true"),e()};t.addEventListener("click",a=>{a.defaultPrevented||n()}),t.addEventListener("keydown",a=>{(a.key===" "||a.key==="Enter")&&(a.preventDefault(),n())}),e()}function K(t){if(t.dataset.enhancedBtnWorking)return;t.dataset.enhancedBtnWorking="true";let e=null,n=!1;new MutationObserver(i=>{i.forEach(u=>{if(u.attributeName==="class"){let s=t.classList.contains("btn-working"),o=t.querySelector("pds-icon");if(s)if(o)e||(e=o.getAttribute("icon")),o.setAttribute("icon","circle-notch");else{let f=document.createElement("pds-icon");f.setAttribute("icon","circle-notch"),f.setAttribute("size","sm"),t.insertBefore(f,t.firstChild),n=!0}else u.oldValue?.includes("btn-working")&&o&&(n?(o.remove(),n=!1):e&&(o.setAttribute("icon",e),e=null))}})}).observe(t,{attributes:!0,attributeFilter:["class"],attributeOldValue:!0})}var Q=new Map([[".accordion",$],["nav[data-dropdown]",U],["label[data-toggle]",z],["label[data-color]",V],['input[type="range"]',j],["form[data-required]",G],["fieldset[role=group][data-open]",_],["[data-clip]",J],["button, a[class*='btn-']",K]]),X=T.map(t=>({...t,run:Q.get(t.selector)||(()=>{})}));export{X as defaultPDSEnhancers};
|