@nexub/elements 11.8.0 → 11.9.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/chunk-NG5UPH5U.js +181 -0
- package/dist/define/choice-jYQxGH_T.d.ts +104 -0
- package/dist/define/combobox.d.ts +74 -0
- package/dist/define/combobox.js +107 -0
- package/dist/define/date-picker.d.ts +72 -0
- package/dist/define/date-picker.js +121 -0
- package/dist/define/field-PQ7-S6JJ.d.ts +102 -0
- package/dist/define/index.d-B-hFBS-X.d.ts +14 -0
- package/dist/define/number-input.d.ts +60 -0
- package/dist/define/number-input.js +47 -0
- package/dist/define/phone-input.d.ts +71 -0
- package/dist/define/phone-input.js +107 -0
- package/dist/define/select.d.ts +56 -0
- package/dist/define/select.js +107 -0
- package/dist/define.d.ts +55 -4
- package/dist/define.js +1 -1
- package/dist/index.d.ts +263 -4
- package/dist/index.js +1 -1
- package/package.json +12 -6
- package/dist/chunk-N4ME7GWE.js +0 -119
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
var R="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)",Mt="outline: 0.1875rem solid var(--color-ring-default, var(--color-primary)); outline-offset: 0.125rem;",k=`
|
|
2
|
+
:host { display: block; font-family: var(--font-family-sans, inherit); color: var(--color-on-surface); }
|
|
3
|
+
:host([hidden]) { display: none; }
|
|
4
|
+
/* The field draws focus itself; no second ring on the host. */
|
|
5
|
+
:host(:focus-within) { outline: none !important; }
|
|
6
|
+
* { box-sizing: border-box; }
|
|
7
|
+
.field {
|
|
8
|
+
display: flex; align-items: center; gap: 0.5rem; inline-size: 100%;
|
|
9
|
+
block-size: var(--size-control-md, 2.5rem); padding-inline: 0.875rem;
|
|
10
|
+
border: 1px solid var(--field-border, var(--color-outline));
|
|
11
|
+
border-radius: var(--field-radius, var(--shape-field));
|
|
12
|
+
background: var(--field-bg, var(--color-surface-container-lowest));
|
|
13
|
+
color: var(--field-fg, var(--color-on-surface));
|
|
14
|
+
font-size: var(--type-body-md-size, 1rem); line-height: var(--type-body-md-lineHeight, 1.5rem);
|
|
15
|
+
}
|
|
16
|
+
:host([size='sm']) .field {
|
|
17
|
+
block-size: var(--size-control-sm, 2rem); padding-inline: 0.75rem; gap: 0.375rem;
|
|
18
|
+
font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
|
|
19
|
+
}
|
|
20
|
+
:host([size='lg']) .field { block-size: var(--size-control-lg, 3rem); padding-inline: 1rem; }
|
|
21
|
+
.field:hover { border-color: var(--color-on-surface-variant); }
|
|
22
|
+
.field:focus-within, .field:focus-within:hover { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
|
|
23
|
+
.field[data-invalid], .field[data-invalid]:hover { border-color: var(--color-error); }
|
|
24
|
+
.field[data-invalid]:focus-within { border-color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }
|
|
25
|
+
.field[data-readonly], .field[data-readonly]:hover { border-color: var(--color-outline-variant); background: var(--color-surface-container-low); }
|
|
26
|
+
.field[data-disabled], .field[data-disabled]:hover {
|
|
27
|
+
cursor: not-allowed; border-color: var(--color-outline-variant);
|
|
28
|
+
background: var(--color-surface-container-low); color: var(--color-text-disabled);
|
|
29
|
+
}
|
|
30
|
+
/* 11.9: inline-size 100% (not the input's own ~20ch width) so the field's narrowest size is its
|
|
31
|
+
padding and button: at a 20rem viewport (WCAG 1.4.10 reflow) a grid or flex parent no longer overflows. */
|
|
32
|
+
input {
|
|
33
|
+
flex: 1; min-inline-size: 0; inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; outline: none;
|
|
34
|
+
background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums;
|
|
35
|
+
}
|
|
36
|
+
input::placeholder { color: var(--color-on-surface-muted); opacity: 1; }
|
|
37
|
+
input:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
|
|
38
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
39
|
+
.field { transition: border-color ${R}, box-shadow ${R}; }
|
|
40
|
+
}
|
|
41
|
+
@media (forced-colors: active) {
|
|
42
|
+
.field { border-color: FieldText; }
|
|
43
|
+
.field:focus-within { outline: 0.125rem solid Highlight; outline-offset: 0; }
|
|
44
|
+
.field[data-invalid] { border-style: dashed; }
|
|
45
|
+
.field[data-disabled] { border-color: GrayText; color: GrayText; }
|
|
46
|
+
}
|
|
47
|
+
`,St=new Map;function b(n){let t=St.get(n);return t||(t=new CSSStyleSheet,t.replaceSync(n),St.set(n,t)),t}var jt=typeof HTMLElement>"u"?class{}:HTMLElement,E=class extends jt{static formAssociated=!0;internals;root;box;#t="";#e=!1;#r=!1;#i=!1;static get observedAttributes(){return["value","required","disabled","readonly","size","aria-label","invalid"]}constructor(){super(),this.internals=this.attachInternals(),this.root=this.attachShadow({mode:"open",delegatesFocus:!0}),this.root.adoptedStyleSheets=[b(k)],this.box=document.createElement("div"),this.box.className="field",this.box.setAttribute("part","field"),this.root.append(this.box),this.addEventListener("invalid",()=>{this.#i=!0,this.render()})}connectedCallback(){this.#e||(this.#t=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(t,e,i){e!==i&&(t==="value"&&!this.#e&&(this.#t=this.sanitize(i??this.initial())),t==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#t}set value(t){this.#e=!0,this.#t=this.sanitize(String(t??"")),this.render()}get defaultValue(){return this.getAttribute("value")??""}set defaultValue(t){this.setAttribute("value",t)}get name(){return this.getAttribute("name")??""}set name(t){this.setAttribute("name",t)}get required(){return this.hasAttribute("required")}set required(t){this.toggleAttribute("required",!!t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",!!t)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(t){this.toggleAttribute("readonly",!!t)}get invalid(){return this.hasAttribute("invalid")}set invalid(t){this.toggleAttribute("invalid",!!t)}get size(){let t=this.getAttribute("size");return t==="sm"||t==="lg"?t:"md"}set size(t){this.setAttribute("size",t)}get form(){return this.internals.form}get labels(){return this.internals.labels}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}focus(t){this.control.focus(t)}blur(){this.control.blur()}formResetCallback(){this.#e=!1,this.#i=!1,this.reset(),this.#t=this.sanitize(this.initial()),this.render()}formDisabledCallback(t){this.#r=t,this.render()}formStateRestoreCallback(t){typeof t=="string"&&(this.value=t)}initial(){return this.getAttribute("value")??""}upgrade(...t){let e=this;for(let i of t){if(!Object.prototype.hasOwnProperty.call(this,i))continue;let r=e[i];delete e[i],e[i]=r}}reset(){}resanitize(){this.#t=this.sanitize(this.#e?this.#t:this.initial())}get isDisabled(){return this.disabled||this.#r}setValue(t){let e=this.sanitize(t),i=e!==this.#t;return this.#e=!0,this.#t=e,i}touch(){this.#i=!0}emit(t){this.dispatchEvent(new Event(t,{bubbles:!0,composed:t==="input"}))}render(){let t=this.check();this.internals.setFormValue(this.#t),t&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[t.kind]:!0},t.message,this.control):this.internals.setValidity({});let e=!!t&&this.#i&&!this.readOnly||this.invalid;this.box.toggleAttribute("data-invalid",e),this.box.toggleAttribute("data-disabled",this.isDisabled),this.box.toggleAttribute("data-readonly",this.readOnly),this.control.disabled=this.isDisabled,"readOnly"in this.control?this.control.readOnly=this.readOnly:this.control.setAttribute("aria-readonly",String(this.readOnly)),this.control.setAttribute("aria-required",String(this.required)),this.control.setAttribute("aria-invalid",String(e)),this.update()}nameControl(){let t=this.getAttribute("aria-label"),e=Array.from(this.internals.labels??[]);if(!e.length){let r=this.getRootNode(),s=this.id?Array.from(r.querySelectorAll("label[for]")).filter(a=>a.htmlFor===this.id):[],o=this.closest("label");e=o&&!s.includes(o)?[...s,o]:s}let i=t??e.map(r=>r.textContent?.trim()).filter(Boolean).join(" ");i?this.control.setAttribute("aria-label",i):this.control.removeAttribute("aria-label")}};var ct={pickDate:"Pick a date",pickMonth:"Pick a month",pickYear:"Pick a year",previousMonth:"Go to previous month",nextMonth:"Go to next month",previousYear:"Go to previous year",nextYear:"Go to next year",previousYears:"Go to previous years",nextYears:"Go to next years",todayDate:n=>`Today, ${n}`,selectedDate:n=>`${n}, selected`};var ht={selectPlaceholder:"Select\u2026",noResults:"No results found.",searching:"Searching\u2026",searchFailed:"Search failed. Try again.",countryCode:(n,t)=>`Country code, ${n} +${t}`,invalidPhone:"Enter a valid phone number."};var Zt="US1GB44RU7AU61IT39NO47FI358MA212RE262GP590CW599AF93AL355DZ213AS1AD376AO244AI1AG1AR54AM374AW297AT43AZ994BS1BH973BD880BB1BY375BE32BZ501BJ229BM1BT975BO591BA387BW267BR55IO246VG1BN673BG359BF226BI257KH855CM237CA1CV238BQ599KY1CF236TD235CL56CN86CX61CC61CO57KM269CG242CD243CK682CR506CI225HR385CU53CY357CZ420DK45DJ253DM1DO1EC593EG20SV503GQ240ER291EE372SZ268ET251FK500FO298FJ679FR33GF594PF689GA241GM220GE995DE49GH233GI350GR30GL299GD1GU1GT502GG44GN224GW245GY592HT509HN504HK852HU36IS354IN91ID62IR98IQ964IE353IM44IL972JM1JP81JE44JO962KZ7KE254KI686XK383KW965KG996LA856LV371LB961LS266LR231LY218LI423LT370LU352MO853MG261MW265MY60MV960ML223MT356MH692MQ596MR222MU230YT262MX52FM691MD373MC377MN976ME382MS1MZ258MM95NA264NR674NP977NL31NC687NZ64NI505NE227NG234NU683NF672KP850MK389MP1OM968PK92PW680PS970PA507PG675PY595PE51PH63PL48PT351PR1QA974RO40RW250BL590SH290KN1LC1MF590PM508VC1WS685SM378ST239SA966SN221RS381SC248SL232SG65SX1SK421SI386SB677SO252ZA27KR82SS211ES34LK94SD249SR597SJ47SE46CH41SY963TW886TJ992TZ255TH66TL670TG228TK690TO676TT1TN216TR90TM993TC1TV688UG256UA380AE971UY598UZ998VU678VA39VE58VN84VI1WF681EH212YE967ZM260ZW263AX358",w=Object.fromEntries(Array.from(Zt.matchAll(/([A-Z]{2})(\d+)/g),n=>[n[1],n[2]])),Nt={IN:[10,10,"5 5"],AE:[8,9,"2 3 4"],SA:[9,9,"2 3 4"],QA:[8,8,"4 4"],KW:[8,8,"4 4"],BH:[8,8,"4 4"],OM:[8,8,"4 4"],US:[10,10,"3 3 4"],CA:[10,10,"3 3 4"],GB:[9,10,"4 6"],SG:[8,8,"4 4"],MY:[8,10,"2 4 4"],AU:[9,9,"3 3 3"],DE:[6,11,"3 4 4"],FR:[9,9,"1 2 2 2 2"],ID:[8,12,"3 4 4"],PH:[10,10,"3 3 4"],LK:[9,9,"2 3 4"],BD:[10,10,"4 6"],NP:[8,10,"3 3 4"],PK:[10,10,"3 7"]},pt=n=>n.replace(/\D/g,"");function M(n){return w[n.toUpperCase()]??""}function mt(n,t){let e=pt(n),i=Nt[t.toUpperCase()]?.[2].split(" ").map(Number),r=[];if(i)for(let s=0;s<i.length&&e;s++){let o=s===i.length-1?e.length:i[s];r.push(e.slice(0,o)),e=e.slice(o)}else{for(;e.length>4;e=e.slice(3))r.push(e.slice(0,3));e&&r.push(e)}return r.join(" ")}function rt(n,t){let e=M(t),i=pt(n);return e&&i?`+${e}${i}`:""}var Jt=(n,t)=>{let e=M(t),[i,r]=Nt[t]??[4,14];return!!e&&n.length>=i&&n.length<=r&&e.length+n.length<=15};function z(n,t="US"){let e=t.toUpperCase(),i=n.trim(),r=pt(i);if(/^(\+|00)/.test(i)){i[0]!=="+"&&(r=r.slice(2));let o=M(e);if(o&&r.startsWith(o))r=r.slice(o.length);else for(let a=3;a>0;a--){let d=Object.keys(w).find(u=>w[u]===r.slice(0,a));if(d){e=d,r=r.slice(a);break}}}e!=="IT"&&e!=="VA"&&(r=r.replace(/^0/,"")),r=r.slice(0,15-(M(e).length||1));let s=M(e);return{country:e,national:r,e164:rt(r,e),valid:Jt(r,e),dialCode:s?`+${s}`:""}}function ft(n,t="US"){try{let e=n?new Intl.Locale(n).maximize().region:void 0;if(e&&w[e])return e}catch{}return t}var Qt=/^[-+]?\d*(?:[.,]\d*)?$/;function gt(n){return Qt.test(n)}function tt(n){let t=Number(n.trim().replace(",","."));return n.trim()!==""&&Number.isFinite(t)&&/\d/.test(n)?t:void 0}function H(n,t,e){let i=n;return t!==void 0&&i<t&&(i=t),e!==void 0&&i>e&&(i=e),i}function Lt(n=1){return n==="any"?1:n}function X(n,t,e,i){return H(n===null?H(0,e,i):n+t,e,i)}function bt(n,t,{min:e,max:i,step:r}={}){let s=Lt(r);switch(n){case"ArrowUp":return X(t,s,e,i);case"ArrowDown":return X(t,-s,e,i);case"PageUp":return X(t,s*10,e,i);case"PageDown":return X(t,-s*10,e,i);case"Home":return e===void 0?void 0:H(e,e,i);case"End":return i===void 0?void 0:H(i,e,i);default:return}}var Ot=/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/,_t={year:0,month:1,day:2},nt=(n,t=2)=>String(n).padStart(t,"0");function V(n,t){let e=new Date(0);return e.setUTCFullYear(n,t+1,0),e.getUTCDate()}function F(n){let t=n?Ot.exec(n):null;if(!t)return;let e=t[3]?"day":t[2]?"month":"year";return m(n,e)?e:void 0}function m(n,t){let e=n?Ot.exec(n):null;if(!e)return;let i=e[3]?"day":e[2]?"month":"year";if(t&&i!==t)return;let r=Number(e[1]),s=e[2]?Number(e[2])-1:0,o=e[3]?Number(e[3]):1;if(!(s<0||s>11||o<1||o>V(r,s)))return{year:r,month:s,day:o}}function N(n,t="day"){let e=nt(n.year,4);return t==="year"?e:t==="month"?`${e}-${nt(n.month+1)}`:`${e}-${nt(n.month+1)}-${nt(n.day)}`}function A(n,t,e="day"){let i=_t[e];return n.year!==t.year?n.year-t.year:i>=1&&n.month!==t.month?n.month-t.month:i>=2&&n.day!==t.day?n.day-t.day:0}function et(n,t,e,i="day"){let r=m(t),s=m(e),o=(a,d)=>d==="year"?{year:a.year,month:11,day:31}:d==="month"?{...a,day:V(a.year,a.month)}:a;if(r&&A(n,r,i)<0)return"under";if(s&&A(n,o(s,F(e)),i)>0)return"over"}function st({year:n,month:t,day:e}){let i=new Date(0);return i.setUTCFullYear(n,t,e),i.getUTCDay()}function W({year:n,month:t,day:e},i){let r=new Date(0);return r.setUTCFullYear(n,t,e+i),{year:r.getUTCFullYear(),month:r.getUTCMonth(),day:r.getUTCDate()}}function L({year:n,month:t,day:e},i){let r=n*12+t+i,s=Math.floor(r/12),o=r-s*12;return{year:s,month:o,day:Math.min(e,V(s,o))}}function it(n=new Date){return{year:n.getFullYear(),month:n.getMonth(),day:n.getDate()}}var Xt=new Set("AG AS BD BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW".split(" ")),te=new Set("AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));function ot(n){let t;try{t=new Intl.Locale(n??new Intl.DateTimeFormat().resolvedOptions().locale)}catch{return 1}try{let i=typeof t.getWeekInfo=="function"?t.getWeekInfo():t.weekInfo;if(i&&typeof i.firstDay=="number")return i.firstDay%7}catch{}let e=t.maximize().region??"";return Xt.has(e)?0:te.has(e)?6:1}function D(n,t,e,i){if(n!=="badInput"&&n!=="typeMismatch"&&typeof document<"u"){let r=document.createElement("input");if(n==="valueMissing"?r.required=!0:(r.type=t,r[n==="rangeUnderflow"?"min":"max"]=e,r.value=t==="number"?String(Number(e)+(n==="rangeUnderflow"?-1:1)):n==="rangeUnderflow"?"0001-01-01".slice(0,e.length):"9999-12-31".slice(0,e.length)),r.validationMessage)return r.validationMessage}return i}var Y=()=>D("valueMissing","number","","Fill out this field.");var yt=n=>{if(n===null||n.trim()==="")return;let t=Number(n);return Number.isFinite(t)?t:void 0},Pt=class extends E{static get observedAttributes(){return[...super.observedAttributes,"min","max","step","placeholder"]}control=document.createElement("input");#t=null;#e="";constructor(){super();let t=this.control;t.type="text",t.inputMode="decimal",t.autocomplete="off",t.setAttribute("role","spinbutton"),t.setAttribute("part","input"),this.box.append(t),t.addEventListener("focus",()=>{this.#t=this.value,this.#e=this.value}),t.addEventListener("input",this.#i),t.addEventListener("blur",this.#a),t.addEventListener("keydown",this.#n)}get min(){return this.getAttribute("min")??""}set min(t){this.setAttribute("min",t)}get max(){return this.getAttribute("max")??""}set max(t){this.setAttribute("max",t)}get step(){return this.getAttribute("step")??""}set step(t){this.setAttribute("step",t)}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get valueAsNumber(){return this.value===""?NaN:Number(this.value)}set valueAsNumber(t){this.value=Number.isFinite(t)?String(t):""}get#r(){let t=this.getAttribute("step"),e=yt(t),i=t?.trim().toLowerCase()==="any"?"any":e!==void 0&&e>0?e:1;return{min:yt(this.getAttribute("min")),max:yt(this.getAttribute("max")),step:i}}sanitize(t){let e=tt(t);return e===void 0?"":String(e)}reset(){this.#t=null,this.#e=this.sanitize(this.getAttribute("value")??"")}check(){let{min:t,max:e}=this.#r,i=this.#t;if(i!==null&&i.trim()!==""&&tt(i)===void 0)return{kind:"badInput",message:D("badInput","number","","Enter a number.")};if(this.value==="")return this.required?{kind:"valueMissing",message:D("valueMissing","number","","Fill out this field.")}:void 0;let r=Number(this.value);if(t!==void 0&&r<t)return{kind:"rangeUnderflow",message:D("rangeUnderflow","number",String(t),`Value must be ${t} or more.`)};if(e!==void 0&&r>e)return{kind:"rangeOverflow",message:D("rangeOverflow","number",String(e),`Value must be ${e} or less.`)}}update(){let t=this.control,{min:e,max:i}=this.#r,r=this.#t??this.value;t.value!==r&&(t.value=r),t.placeholder=this.placeholder;let s=(o,a)=>a===void 0?t.removeAttribute(o):t.setAttribute(o,String(a));s("aria-valuenow",this.value===""?void 0:Number(this.value)),s("aria-valuemin",e),s("aria-valuemax",i)}#i=t=>{t.stopPropagation();let e=this.control,i=e.value;if(!gt(i)){let o=this.#t??this.value,a=Math.max(0,(e.selectionStart??o.length)-(i.length-o.length));e.value=o,e.setSelectionRange?.(a,a);return}this.#t=i;let r=tt(i),s=r!==void 0?this.setValue(String(r)):i.trim()===""?this.setValue(""):!1;this.render(),s&&this.emit("input")};#o(){this.#t=null;let{min:t,max:e}=this.#r,i=!1;this.value!==""&&!this.readOnly&&(i=this.setValue(String(H(Number(this.value),t,e)))),this.value!==this.#e&&this.touch(),this.render(),i&&this.emit("input"),this.value!==this.#e&&(this.#e=this.value,this.emit("change"))}#a=()=>this.#o();#n=t=>{if(t.key==="Enter"&&!t.isComposing){this.#o(),this.#t=this.value,this.form?.requestSubmit();return}if(this.readOnly){(t.key==="ArrowUp"||t.key==="ArrowDown")&&t.preventDefault();return}if(this.isDisabled)return;let e=this.value===""?null:Number(this.value),i=bt(t.key,e,this.#r);if(i===void 0)return;t.preventDefault();let r=this.setValue(String(i));this.#t!==null&&(this.#t=this.value),this.touch(),this.render(),r&&(this.emit("input"),this.#e=this.value,this.emit("change"))}};var Tt=`
|
|
48
|
+
:host([size='sm']) .field { padding-inline-end: 0.125rem; }
|
|
49
|
+
.field { padding-inline-end: 0.25rem; }
|
|
50
|
+
:host([size='lg']) .field { padding-inline-end: 0.375rem; }
|
|
51
|
+
button {
|
|
52
|
+
position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center;
|
|
53
|
+
margin: 0; padding: 0; border: 1px solid transparent; border-radius: var(--shape-control, 999rem);
|
|
54
|
+
background: transparent; color: inherit; font: inherit; cursor: pointer;
|
|
55
|
+
}
|
|
56
|
+
/* The state layer (themes' .nx-state-layer): the text colour at the --state-* opacity. */
|
|
57
|
+
button::before {
|
|
58
|
+
content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
|
|
59
|
+
background: currentColor; opacity: 0; pointer-events: none;
|
|
60
|
+
}
|
|
61
|
+
button:hover::before { opacity: var(--state-hover, 0.08); }
|
|
62
|
+
button:focus-visible::before { opacity: var(--state-focus, 0.1); }
|
|
63
|
+
button:active::before { opacity: var(--state-pressed, 0.1); }
|
|
64
|
+
button:disabled { cursor: default; pointer-events: none; color: var(--color-text-disabled); }
|
|
65
|
+
button:disabled::before { opacity: 0; }
|
|
66
|
+
button:focus-visible { ${Mt} }
|
|
67
|
+
svg { inline-size: 1rem; block-size: 1rem; flex: none; }
|
|
68
|
+
.open { flex: none; inline-size: 2rem; block-size: 2rem; border-radius: 999rem; }
|
|
69
|
+
:host([size='sm']) .open { inline-size: 1.75rem; block-size: 1.75rem; }
|
|
70
|
+
dialog {
|
|
71
|
+
position: fixed; margin: 0; inset: auto;
|
|
72
|
+
inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
|
|
73
|
+
inline-size: max-content; max-inline-size: calc(100vw - 1rem); max-block-size: calc(100dvh - 1rem); overflow: auto;
|
|
74
|
+
padding: 0.75rem; border: 0; border-radius: var(--shape-container, 1rem);
|
|
75
|
+
background: var(--color-surface-elevated, var(--color-surface)); color: var(--color-on-surface);
|
|
76
|
+
box-shadow: var(--elevation-2); font-size: var(--type-body-sm-size, 0.875rem);
|
|
77
|
+
}
|
|
78
|
+
dialog::backdrop { background: transparent; }
|
|
79
|
+
.head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-block-end: 0.5rem; }
|
|
80
|
+
.title { font-size: var(--type-label-lg-size, 0.875rem); font-weight: var(--type-label-lg-weight, 600); }
|
|
81
|
+
.nav { inline-size: 1.75rem; block-size: 1.75rem; border-radius: 999rem; }
|
|
82
|
+
:host(:dir(rtl)) .nav svg { transform: scaleX(-1); }
|
|
83
|
+
table { border-collapse: collapse; margin-inline: auto; }
|
|
84
|
+
th { block-size: var(--day-cell, 2rem); padding: 0; font-weight: inherit; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
|
|
85
|
+
td { padding: 0; padding-block-start: 0.25rem; text-align: center; }
|
|
86
|
+
.day, .cell { font-variant-numeric: tabular-nums; border-radius: 999rem; }
|
|
87
|
+
.day { inline-size: var(--day-cell, 2rem); block-size: var(--day-cell, 2rem); }
|
|
88
|
+
.day[data-outside]:not([aria-pressed='true']):not(:disabled) { color: var(--color-on-surface-muted); }
|
|
89
|
+
.cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.25rem; inline-size: 16.5rem; max-inline-size: 100%; }
|
|
90
|
+
/* Long month names in some locales wrap to two lines rather than overflow. */
|
|
91
|
+
.cell { block-size: 2.5rem; padding-inline: 0.25rem; line-height: 1.125; overflow-wrap: anywhere; }
|
|
92
|
+
[aria-current='date'] { border-color: var(--color-primary); }
|
|
93
|
+
[aria-pressed='true'], [aria-selected='true'] > button { background: var(--color-primary); color: var(--color-on-primary); }
|
|
94
|
+
@media (max-width: 47.99rem) {
|
|
95
|
+
dialog {
|
|
96
|
+
inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 85dvh;
|
|
97
|
+
border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
|
|
98
|
+
border-end-start-radius: 0; border-end-end-radius: 0;
|
|
99
|
+
padding-block-end: max(0.75rem, env(safe-area-inset-bottom));
|
|
100
|
+
}
|
|
101
|
+
dialog::before {
|
|
102
|
+
content: ''; display: block; inline-size: 2rem; block-size: 0.25rem; margin: 0 auto 0.5rem;
|
|
103
|
+
border-radius: var(--shape-overlay, 1.5rem); background: var(--color-outline-variant);
|
|
104
|
+
}
|
|
105
|
+
dialog::backdrop { background: color-mix(in srgb, var(--color-scrim, CanvasText) 40%, transparent); }
|
|
106
|
+
.cells { inline-size: 100%; }
|
|
107
|
+
.day { inline-size: 2.75rem; block-size: 2.75rem; }
|
|
108
|
+
}
|
|
109
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
110
|
+
button::before { transition: opacity ${R}; }
|
|
111
|
+
dialog[open] { animation: nx-pop var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
|
|
112
|
+
@keyframes nx-pop { from { opacity: 0; scale: 0.96; } }
|
|
113
|
+
}
|
|
114
|
+
@media (forced-colors: active) {
|
|
115
|
+
dialog { outline: 1px solid CanvasText; }
|
|
116
|
+
button:focus-visible { outline-color: Highlight; }
|
|
117
|
+
[aria-current='date'] { border-color: CanvasText; }
|
|
118
|
+
[aria-pressed='true'], [aria-selected='true'] > button { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
119
|
+
button:disabled { color: GrayText; }
|
|
120
|
+
}
|
|
121
|
+
`;var f=ct,zt={year:0,month:1,day:2};function O({year:n,month:t,day:e}){let i=new Date(0);return i.setUTCFullYear(n,t,e),i}var q=(n,t)=>new Intl.DateTimeFormat(n,{timeZone:"UTC",...t}),vt={year:"numeric",month:"2-digit",day:"2-digit"};function at(n,t,e){return t==="year"?String(n.year):q(e,t==="month"?{year:"numeric",month:"long"}:vt).format(O(n))}function ee(n){return q(n,vt).formatToParts(O({year:2026,month:0,day:31})).map(t=>t.type).filter(t=>t==="year"||t==="month"||t==="day")}function xt(n,t){if(n==="year")return"yyyy";let e={year:"yyyy",month:"mm",day:"dd"};return q(t,n==="month"?{year:"numeric",month:"2-digit"}:vt).formatToParts(O({year:2026,month:0,day:31})).map(r=>r.type==="year"||r.type==="month"||r.type==="day"?e[r.type]:r.type==="literal"?r.value:"").join("").trim()}function ie(n,t){let e=new Intl.NumberFormat(t,{useGrouping:!1}),i=n;for(let r=0;r<=9;r++){let s=e.format(r);s!==String(r)&&(i=i.split(s).join(String(r)))}return i}function re(n,t){let e=i=>i.toLowerCase().replace(/\.$/,"");for(let i=0;i<12;i++){let r=O({year:2026,month:i,day:1});if([q(t,{month:"long"}).format(r),q(t,{month:"short"}).format(r),q(t,{day:"numeric",month:"long"}).formatToParts(r).find(o=>o.type==="month")?.value??""].map(e).some(o=>o===n||n.length>=3&&o.startsWith(n)))return i}}function Ft(n,t,e){let i=ie(n.trim(),e);if(!i)return;let r=m(i);if(r)return zt[F(i)]>=zt[t]?r:void 0;let s,o=[];for(let c of i.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean))if(/^\d+$/.test(c))o.push(c);else{let h=re(c,e);if(h===void 0||s!==void 0)return;s=h}let a=ee(e).filter(c=>c==="year"||c==="month"&&t!=="year"&&s===void 0||c==="day"&&t==="day");if(o.length!==a.length)return;let d=c=>o[a.indexOf(c)]??"",u=d("year"),g={year:u.length<=2?2e3+Number(u):Number(u),month:s??(t==="year"?0:Number(d("month"))-1),day:t==="day"?Number(d("day")):1};return m(N(g,t),t)}var Gt="http://www.w3.org/2000/svg",y=n=>{let t=document.createElementNS(Gt,"svg"),e={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[i,r]of Object.entries(e))t.setAttribute(i,r);for(let[i,r]of n){let s=document.createElementNS(Gt,i);for(let[o,a]of Object.entries(r))s.setAttribute(o,a);t.append(s)}return t},l=(n,t={})=>{let e=document.createElement(n);for(let[i,r]of Object.entries(t))r!==void 0&&e.setAttribute(i,r);return e},j=[["path",{d:"m6 9 6 6 6-6"}]],It=[["path",{d:"M20 6 9 17l-5-5"}]],U=n=>{let t=n.getAttribute("locale")||n.closest("[lang]")?.getAttribute("lang")||void 0;try{return t?Intl.getCanonicalLocales(t)[0]:void 0}catch{return}},lt=n=>{try{return n.matches(":dir(rtl)")}catch{return n.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}};var dt={year:0,month:1,day:2},K=12,ne=[["rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}],["path",{d:"M16 2v4M8 2v4M3 10h18"}]],se=[["path",{d:"m15 18-6-6 6-6"}]],oe=[["path",{d:"m9 18 6-6-6-6"}]],ae="(max-width: 47.99rem)",wt=n=>n-(n%K+K)%K,Rt=class extends E{static get observedAttributes(){return[...super.observedAttributes,"min","max","granularity","locale"]}control=l("input",{type:"text",part:"input",autocomplete:"off",spellcheck:"false"});#t=l("button",{type:"button",part:"button",class:"open","aria-haspopup":"dialog","aria-expanded":"false"});#e=l("dialog",{part:"calendar",tabindex:"-1"});#r=l("span",{class:"title","aria-live":"polite"});#i=l("button",{type:"button",class:"nav"});#o=l("button",{type:"button",class:"nav"});#a=l("div");#n=null;#s;#d=it();constructor(){super(),this.root.adoptedStyleSheets=[b(k),b(Tt)],this.#t.replaceChildren(y(ne)),this.#i.replaceChildren(y(se)),this.#o.replaceChildren(y(oe));let t=l("div",{class:"head"});t.append(this.#i,this.#r,this.#o),this.#e.append(t,this.#a),this.box.append(this.control,this.#t),this.root.append(this.#e);let e=this.control;e.addEventListener("input",i=>{i.stopPropagation(),this.#n=e.value}),e.addEventListener("blur",()=>this.#f()),e.addEventListener("keydown",i=>{i.key!=="Enter"||i.isComposing||(this.#f(),this.form?.requestSubmit())}),this.#t.addEventListener("click",()=>this.show()),this.#i.addEventListener("click",()=>this.#b(-1)),this.#o.addEventListener("click",()=>this.#b(1)),this.#a.addEventListener("click",i=>{let r=i.target.closest("button[data-value]");r&&!r.disabled&&this.#g(r.dataset.value)}),this.#a.addEventListener("keydown",this.#w),this.#e.addEventListener("close",()=>this.#u()),this.#e.addEventListener("keydown",i=>{i.key!=="Escape"||i.isComposing||(i.preventDefault(),this.close())}),this.#e.addEventListener("click",i=>{if(i.target!==this.#e)return;let r=this.#e.getBoundingClientRect();(i.clientX<r.left||i.clientX>r.right||i.clientY<r.top||i.clientY>r.bottom)&&this.close()})}get min(){return this.getAttribute("min")??""}set min(t){this.setAttribute("min",t)}get max(){return this.getAttribute("max")??""}set max(t){this.setAttribute("max",t)}get granularity(){let t=this.getAttribute("granularity");return t==="month"||t==="year"?t:"day"}set granularity(t){this.setAttribute("granularity",t)}get locale(){return this.getAttribute("locale")??""}set locale(t){this.setAttribute("locale",t)}get value(){return super.value}set value(t){this.#n=null,this.#s=void 0,super.value=t}get open(){return this.#e.open}show(){this.open||this.isDisabled||this.readOnly||(this.#d=this.#p(m(this.value)??it()),this.#v(),this.#e.showModal(),this.#t.setAttribute("aria-expanded","true"),this.#y(),window.addEventListener("resize",this.#y),window.addEventListener("scroll",this.#y,{capture:!0,passive:!0}),this.#x())}close(){this.open&&(this.#e.close(),this.#u())}#u(){this.open||this.#t.getAttribute("aria-expanded")==="false"||(this.#t.setAttribute("aria-expanded","false"),window.removeEventListener("resize",this.#y),window.removeEventListener("scroll",this.#y,!0),this.control.focus())}attributeChangedCallback(t,e,i){t==="granularity"&&e!==i&&this.resanitize(),super.attributeChangedCallback(t,e,i),this.open&&this.#v()}get#l(){return U(this)}get#c(){return lt(this)}sanitize(t){let e=m(t.trim()),i=F(t.trim());return e&&i&&dt[i]>=dt[this.granularity]?N(e,this.granularity):""}reset(){this.#n=null,this.#s=void 0,this.close()}#h(t){let e=et(t,this.min,this.max,this.granularity);if(!e)return;let i=e==="under",r=m(i?this.min:this.max),s=this.granularity,o=at(r,s,this.#l),a=i?"rangeUnderflow":"rangeOverflow";return{kind:a,message:D(a,s==="day"?"date":s==="month"?"month":"number",N(r,s),`Value must be ${o} or ${i?"later":"earlier"}.`)}}check(){if(this.#s)return this.#s;let t=m(this.value);return t?this.#h(t):this.required?{kind:"valueMissing",message:D("valueMissing","date","","Fill out this field.")}:void 0}update(){let t=this.granularity,e=m(this.value),i=this.#n??(e?at(e,t,this.#l):"");this.control.value!==i&&(this.control.value=i),this.control.placeholder=xt(t,this.#l),this.#t.disabled=this.isDisabled||this.readOnly,this.#m()}#m(){let t=this.granularity,e=t==="day"?f.pickDate:t==="month"?f.pickMonth:f.pickYear,i=this.control.getAttribute("aria-label");this.#t.setAttribute("aria-label",i?`${e}, ${i}`:e)}nameControl(){super.nameControl(),this.#m()}#f(){let t=this.#n;if(t===null)return;let e=!1,i=t.trim()?Ft(t,this.granularity,this.#l):void 0;this.#s=!t.trim()||!i?t.trim()?{kind:"badInput",message:D("badInput","date","",`Enter a date as ${xt(this.granularity,this.#l)}.`)}:void 0:this.#h(i),this.#s||(this.#n=null,e=this.setValue(i?N(i,this.granularity):"")),this.touch(),this.render(),e&&this.emit("change")}#g(t){this.#n=null,this.#s=void 0;let e=this.setValue(t);this.touch(),this.render(),this.close(),e&&this.emit("change")}#p(t){let e=this.granularity,i=et(t,this.min,this.max,e);if(!i)return t;let r=m(i==="under"?this.min:this.max);if(i==="under"||dt[F(this.max)]>=dt[e])return r;let s=F(this.max)==="year"?11:r.month;return{year:r.year,month:s,day:V(r.year,s)}}#b(t,e=!1){let i=this.granularity,r=this.#d;this.#d=this.#p(i==="day"?L(r,t):L(r,t*12*(i==="year"?K:1))),this.#v(),e&&this.#x()}#w=t=>{let e=this.granularity,i=this.#d,r=this.#c?-1:1,s=d=>e==="day"?W(i,d):L(i,d*(e==="year"?12:1)),o=()=>e==="day"?W(i,-((st(i)-ot(this.#l)+7)%7)):e==="month"?{...i,month:0,day:1}:{year:wt(i.year),month:0,day:1},a;switch(t.key){case"ArrowLeft":a=s(-r);break;case"ArrowRight":a=s(r);break;case"ArrowUp":a=s(e==="day"?-7:-3);break;case"ArrowDown":a=s(e==="day"?7:3);break;case"PageUp":case"PageDown":{let d=t.key==="PageUp"?-1:1;a=e==="day"?L(i,d*(t.shiftKey?12:1)):L(i,d*12*(e==="year"?K:1));break}case"Home":a=o();break;case"End":a=e==="day"?W(o(),6):e==="month"?{...i,month:11,day:1}:{year:wt(i.year)+11,month:0,day:1};break;default:return}t.preventDefault(),this.#d=this.#p(a),this.#v(),this.#x()};#x(){this.#a.querySelector('[tabindex="0"]')?.focus()}#y=()=>{if(!this.open||window.matchMedia?.(ae).matches)return;let t=this.box.getBoundingClientRect(),{offsetWidth:e,offsetHeight:i}=this.#e,r=document.documentElement.clientWidth||innerWidth,s=document.documentElement.clientHeight||innerHeight,o=4,a=t.bottom+o;a+i>s-o&&t.top-o-i>=o&&(a=t.top-o-i);let d=Math.max(o,Math.min(this.#c?r-t.right:t.left,r-e-o));this.#e.style.setProperty("--nx-top",`${Math.max(o,a)}px`),this.#e.style.setProperty("--nx-start",`${d}px`)};#v(){let t=this.granularity,e=this.#l,i=this.#d,r=m(this.value),s=it(),o=(p,C)=>et(p,this.min,this.max,C),a=p=>new Intl.DateTimeFormat(e,{timeZone:"UTC",...p}),d=new Intl.NumberFormat(e,{useGrouping:!1}),u,g,c,h,P;if(t==="day"){let p={year:i.year,month:i.month,day:1};u=a({month:"long",year:"numeric"}).format(O(p)),[g,c,h]=[L(p,-1),L(p,1),"month"];let C=ot(e),I=(st(p)-C+7)%7,v=Math.ceil((I+V(i.year,i.month))/7)*7;P=l("table",{role:"grid","aria-label":u});let $=l("tr");for(let T=0;T<7;T++){let x=O({year:1970,month:0,day:4+(C+T)%7}),Q=l("th",{scope:"col",abbr:a({weekday:"long"}).format(x)});Q.textContent=a({weekday:"short"}).format(x),$.append(Q)}let Ct=l("thead");Ct.append($);let kt=l("tbody");P.append(Ct,kt);let qt=a({dateStyle:"full"}),Et;for(let T=0;T<v;T++){T%7===0&&kt.append(Et=l("tr"));let x=W(p,T-I),Q=r!==void 0&&A(x,r)===0,At=A(x,s)===0,_=qt.format(O(x));At&&(_=f.todayDate(_)),Q&&(_=f.selectedDate(_));let Dt=l("td",{role:"gridcell","aria-selected":Q?"true":void 0}),ut=l("button",{type:"button",class:"day","data-value":N(x),tabindex:A(x,i)===0?"0":"-1","aria-label":_,"aria-current":At?"date":void 0,"data-outside":x.month!==i.month?"":void 0});ut.disabled=o(x,"day")!==void 0,ut.textContent=d.format(x.day),Dt.append(ut),Et.append(Dt)}}else{let p=t==="month",C=p?i.year:wt(i.year);u=p?String(i.year):`${C} \u2013 ${C+K-1}`,h="year",g={year:p?i.year-1:C-1,month:0,day:1},c={year:p?i.year+1:C+K,month:0,day:1},P=l("div",{role:"group",class:"cells","aria-label":u});for(let I=0;I<12;I++){let v=p?{year:i.year,month:I,day:1}:{year:C+I,month:0,day:1},$=l("button",{type:"button",class:"cell","data-value":N(v,t),tabindex:A(v,i,t)===0?"0":"-1","aria-pressed":String(r!==void 0&&A(v,r,t)===0),"aria-current":A(v,s,t)===0?"date":void 0,"aria-label":p?at(v,"month",e):String(v.year)});$.disabled=o(v,t)!==void 0,$.textContent=p?a({month:"long"}).format(O(v)):String(v.year),P.append($)}}this.#i.disabled=o(g,h)==="under",this.#o.disabled=o(c,h)==="over";let[Wt,Yt]=t==="day"?[f.previousMonth,f.nextMonth]:t==="month"?[f.previousYear,f.nextYear]:[f.previousYears,f.nextYears];this.#i.setAttribute("aria-label",Wt),this.#o.setAttribute("aria-label",Yt),this.#r.textContent!==u&&(this.#r.textContent=u),this.#e.setAttribute("aria-label",t==="day"?f.pickDate:t==="month"?f.pickMonth:f.pickYear),this.#a.replaceChildren(P)}};var S=ht,le="(max-width: 47.99rem)",Ht=500,B=n=>n.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function Vt(n){return Array.from(n.querySelectorAll("option"),t=>{let e=t.parentElement?.localName==="optgroup"?t.parentElement:void 0;return{value:t.value,label:t.label,disabled:t.disabled||!!e?.disabled,group:e?.label||void 0}})}function Ut(n,t){let e=B(t.trim());return e?n.filter(i=>[i.label,i.description,...i.keywords??[]].some(r=>r&&B(r).includes(e))):n}var de=0,G=class{constructor(t,e,i,r,s){this.host=t;this.anchor=e;this.control=i;this.pick=r;this.refresh=s;this.list=l("div",{role:"listbox",id:this.#e,part:"listbox"}),this.popup.append(this.status,this.list),"popover"in this.popup&&(this.popup.popover="manual"),i.setAttribute("aria-controls",this.#e),i.setAttribute("aria-expanded","false"),this.popup.addEventListener("mousedown",o=>o.preventDefault()),this.list.addEventListener("click",o=>{let a=this.options[this.#o(o)];a&&!a.disabled&&this.pick(a)}),this.list.addEventListener("mousemove",o=>{let a=this.#o(o);a>=0&&a!==this.active&&!this.options[a].disabled&&this.setActive(a,!1)})}host;anchor;control;pick;refresh;popup=l("div",{class:"popup",part:"popup",hidden:""});status=l("div",{role:"status",class:"status"});list;options=[];active=-1;#t="";#e=`nx-list-${++de}`;#r="";#i=0;#o(t){let e=t.target.closest('[role="option"]');return e?Number(e.dataset.index):-1}get open(){return!this.popup.hidden}render(t,e,i){this.options=t,this.#t=e,i?this.list.setAttribute("aria-label",i):this.list.removeAttribute("aria-label");let r=[],s,o;t.forEach((a,d)=>{if(a.group!==o&&(o=a.group,s=void 0,o)){let h=`${this.#e}-g${d}`;s=l("div",{role:"group","aria-labelledby":h});let P=l("div",{role:"presentation",id:h,class:"heading"});P.textContent=o,s.append(P),r.push(s)}let u=`${this.#e}-${d}`,g=l("div",{role:"option",id:u,class:"option",part:"option","data-index":String(d),"aria-selected":String(a.value===e),"aria-disabled":a.disabled?"true":void 0,"aria-describedby":a.description?`${u}-d`:void 0}),c=l("span",{class:"label"});if(c.textContent=a.label,g.append(y(It),c),a.description){let h=l("span",{id:`${u}-d`,class:"description"});h.textContent=a.description,c.append(h)}s?s.append(g):r.push(g)}),this.list.replaceChildren(...r),this.active>=t.length&&(this.active=-1),this.setActive(this.active,!1)}setActive(t,e=!0){this.active=t;let i;for(let r of this.list.querySelectorAll('[role="option"]')){let s=Number(r.dataset.index)===t;r.toggleAttribute("data-active",s),s&&(i=r)}i&&this.open?(this.control.setAttribute("aria-activedescendant",i.id),e&&i.scrollIntoView?.({block:"nearest"})):this.control.removeAttribute("aria-activedescendant")}step(t,e,i=1){let r=t;for(let s=t+e;s>=0&&s<this.options.length&&i>0;s+=e)this.options[s].disabled||(r=s,i--);return r}first(){return this.step(-1,1)}last(){return this.step(this.options.length,-1)}indexOf(t){return this.options.findIndex(e=>e.value===t)}show(){if(!this.open){this.refresh(),this.popup.hidden=!1;try{this.popup.showPopover?.()}catch{}this.control.setAttribute("aria-expanded","true"),this.place(),window.addEventListener("resize",this.place),window.addEventListener("scroll",this.place,{capture:!0,passive:!0}),document.addEventListener("mousedown",this.#a,!0)}}hide(){if(this.open){try{this.popup.hidePopover?.()}catch{}this.popup.hidden=!0,this.active=-1,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant"),window.removeEventListener("resize",this.place),window.removeEventListener("scroll",this.place,!0),document.removeEventListener("mousedown",this.#a,!0)}}#a=t=>{t.composedPath().includes(this.host)||this.hide()};place=()=>{if(!this.open||window.matchMedia?.(le).matches)return;let t=this.anchor.getBoundingClientRect(),e=this.popup.offsetHeight,i=document.documentElement.clientWidth||innerWidth,r=document.documentElement.clientHeight||innerHeight,s=4,o=t.bottom+s;o+e>r-s&&t.top-s-e>=s&&(o=t.top-s-e);let a=this.popup.style;a.setProperty("--nx-top",`${Math.max(s,o)}px`),a.setProperty("--nx-start",`${Math.max(0,lt(this.host)?i-t.right:t.left)}px`),a.setProperty("--nx-width",`${t.right-t.left}px`)};get typing(){return this.#r!==""&&Date.now()-this.#i<=Ht}typeahead(t){let e=Date.now();this.#r=e-this.#i>Ht?t:this.#r+t,this.#i=e;let i=B(this.#r),r=[...i].every(u=>u===i[0]),s=r?i[0]:i,o=this.active>=0?this.active:this.indexOf(this.#t),a=o<0?0:o+(r?1:0),d=this.options.length;for(let u=0;u<d;u++){let g=(a+u)%d,c=this.options[g];if(!c.disabled&&[c.label,...c.keywords??[]].some(h=>B(h).startsWith(s)))return g}return-1}selectKey(t){let{key:e}=t,i=e.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey,r=i&&(e!==" "||this.typing);if(!this.open){if(r){t.preventDefault(),this.refresh();let o=this.options[this.typeahead(e)];o&&this.pick(o)}else if(["ArrowDown","ArrowUp","Enter"," ","Home","End"].includes(e)){t.preventDefault(),this.show();let o=this.indexOf(this.#t);this.setActive(e==="Home"?this.first():e==="End"?this.last():o>=0&&!this.options[o].disabled?o:this.first())}return}let s;switch(e){case"ArrowDown":s=this.step(this.active,1);break;case"ArrowUp":if(t.altKey)return this.#n(t);s=this.active<0?this.last():this.step(this.active,-1);break;case"Home":s=this.first();break;case"End":s=this.last();break;case"PageDown":s=this.step(this.active,1,10);break;case"PageUp":s=this.step(this.active,-1,10);break;case"Enter":return this.#n(t);case"Tab":return this.#n();case"Escape":return t.preventDefault(),t.stopPropagation(),this.hide();default:if(!i)return;if(!r)return this.#n(t);if(s=this.typeahead(e),s<0)return t.preventDefault()}t.preventDefault(),this.setActive(s)}#n(t){t?.preventDefault();let e=this.options[this.active];e?this.pick(e):this.hide()}},Z=class extends E{static get observedAttributes(){return[...super.observedAttributes,"placeholder"]}#t=null;#e=[];#r;get options(){return this.#t??this.#e}set options(t){this.#t=t?t.map(e=>({...e,value:String(e.value),label:String(e.label??e.value)})):null,this.optionsChanged()}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get open(){return this.list.open}close(){this.list.hide()}connectedCallback(){this.#e=Vt(this),this.#r??=new MutationObserver(()=>{this.#e=Vt(this),this.#t||this.optionsChanged()}),this.#r.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","label","disabled","selected"]}),super.connectedCallback()}disconnectedCallback(){this.#r?.disconnect(),this.list.hide()}initial(){return this.getAttribute("value")??this.querySelector("option[selected]")?.value??""}optionsChanged(){this.resanitize(),this.render()}get locked(){return this.isDisabled||this.readOnly}get listLabel(){return this.control.getAttribute("aria-label")??""}};var J=`
|
|
122
|
+
button { margin: 0; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
123
|
+
button:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
|
|
124
|
+
button svg, .option svg { inline-size: 1rem; block-size: 1rem; flex: none; }
|
|
125
|
+
.trigger { flex: 1; align-self: stretch; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; outline: none; text-align: start; }
|
|
126
|
+
/* One line, as the React trigger's line-clamp-1. */
|
|
127
|
+
.text { flex: 1; min-inline-size: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow-wrap: anywhere; }
|
|
128
|
+
.trigger[data-placeholder] .text { color: var(--color-on-surface-muted); }
|
|
129
|
+
.trigger svg, .toggle svg, .country svg { color: var(--color-on-surface-variant); }
|
|
130
|
+
.toggle { flex: none; display: inline-flex; align-items: center; justify-content: center; inline-size: 1.75rem; block-size: 1.75rem; margin-inline-end: -0.5rem; border-radius: 999rem; }
|
|
131
|
+
.country {
|
|
132
|
+
flex: none; display: inline-flex; align-items: center; gap: 0.25rem; align-self: stretch;
|
|
133
|
+
margin-block: 0.25rem; margin-inline-start: -0.5rem; padding-inline: 0.5rem;
|
|
134
|
+
border-radius: var(--shape-control, 999rem); font-variant-numeric: tabular-nums; outline: none;
|
|
135
|
+
}
|
|
136
|
+
span.country { color: var(--color-on-surface-variant); }
|
|
137
|
+
.country[hidden] { display: none; }
|
|
138
|
+
button.country:hover { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
|
|
139
|
+
button.country:focus-visible { background: color-mix(in srgb, var(--color-on-surface) 12%, transparent); }
|
|
140
|
+
button.country:disabled { background: transparent; }
|
|
141
|
+
.popup {
|
|
142
|
+
position: fixed; z-index: var(--z-popover); margin: 0; inset: auto;
|
|
143
|
+
inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
|
|
144
|
+
inline-size: max(var(--nx-width, 12rem), 12rem); max-inline-size: calc(100vw - 1rem); max-block-size: min(24rem, calc(100dvh - 1rem));
|
|
145
|
+
display: flex; flex-direction: column; overflow: auto; padding: 0.375rem; border: 0;
|
|
146
|
+
border-radius: var(--shape-container, 1rem); background: var(--color-surface-elevated, var(--color-surface));
|
|
147
|
+
color: var(--color-on-surface); box-shadow: var(--elevation-2);
|
|
148
|
+
font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
|
|
149
|
+
}
|
|
150
|
+
.popup[hidden] { display: none; }
|
|
151
|
+
.status { padding: 0.5rem 0.75rem; color: var(--color-on-surface-muted); }
|
|
152
|
+
.status:empty { display: none; }
|
|
153
|
+
.heading { padding: 0.5rem 0.5rem 0.25rem; font-size: var(--type-label-sm-size, 0.75rem); font-weight: var(--type-label-lg-weight, 600); color: var(--color-on-surface-muted); }
|
|
154
|
+
.option { display: flex; align-items: center; gap: 0.5rem; min-block-size: 2.25rem; padding: 0.375rem 0.5rem; border-radius: 0.625rem; cursor: default; }
|
|
155
|
+
.option svg { visibility: hidden; }
|
|
156
|
+
.option[aria-selected='true'] svg { visibility: visible; }
|
|
157
|
+
.option[data-active] { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
|
|
158
|
+
.option[aria-disabled='true'] { color: var(--color-text-disabled); }
|
|
159
|
+
.description { display: block; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
|
|
160
|
+
@media (max-width: 47.99rem) {
|
|
161
|
+
.popup {
|
|
162
|
+
inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 50dvh;
|
|
163
|
+
border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
|
|
164
|
+
border-end-start-radius: 0; border-end-end-radius: 0;
|
|
165
|
+
padding-block-end: max(0.375rem, env(safe-area-inset-bottom));
|
|
166
|
+
}
|
|
167
|
+
.option { min-block-size: 2.75rem; }
|
|
168
|
+
}
|
|
169
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
170
|
+
.popup:not([hidden]) { animation: nx-fade var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
|
|
171
|
+
@keyframes nx-fade { from { opacity: 0; } }
|
|
172
|
+
.trigger svg, button.country { transition: rotate ${R}, background-color ${R}; }
|
|
173
|
+
}
|
|
174
|
+
[aria-expanded='true'] > svg { rotate: 180deg; }
|
|
175
|
+
@media (forced-colors: active) {
|
|
176
|
+
.popup { outline: 1px solid CanvasText; }
|
|
177
|
+
.option[data-active] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
178
|
+
.option[aria-disabled='true'], button:disabled { color: GrayText; }
|
|
179
|
+
button.country:focus-visible { outline: 0.125rem solid Highlight; }
|
|
180
|
+
}
|
|
181
|
+
`;var Kt=class extends Z{control=l("button",{type:"button",role:"combobox",class:"trigger",part:"trigger","aria-haspopup":"listbox"});#t=l("span",{class:"text",part:"value"});list;constructor(){super(),this.root.adoptedStyleSheets=[b(k),b(J)],this.control.append(this.#t,y(j)),this.box.append(this.control),this.list=new G(this,this.box,this.control,t=>this.#e(t),()=>this.list.render(this.options,this.value,this.listLabel)),this.root.append(this.list.popup),this.control.addEventListener("click",()=>this.open?this.close():this.show()),this.control.addEventListener("keydown",t=>{if(this.locked){t.key!=="Tab"&&t.preventDefault();return}this.list.selectKey(t)}),this.control.addEventListener("keyup",t=>t.key===" "&&t.preventDefault()),this.control.addEventListener("blur",()=>this.close()),this.upgrade("options","value")}get selectedOption(){return this.options.find(t=>t.value===this.value)}show(){if(this.locked||this.open)return;this.list.show();let t=this.list.indexOf(this.value);this.list.setActive(t>=0&&!this.options[t].disabled?t:this.list.first())}sanitize(t){return!this.options.length||this.options.some(e=>e.value===t)?t:""}check(){return this.required&&!this.value?{kind:"valueMissing",message:Y()}:void 0}reset(){this.close()}update(){let t=this.selectedOption;this.#t.textContent=t?t.label:this.placeholder||S.selectPlaceholder,this.control.toggleAttribute("data-placeholder",!t),this.open&&this.list.refresh()}#e(t){this.close();let e=this.setValue(t.value);this.touch(),this.render(),e&&(this.emit("input"),this.emit("change"))}};var Bt=class extends Z{static get observedAttributes(){return[...super.observedAttributes,"allow-custom"]}control=l("input",{type:"text",role:"combobox",part:"input",autocomplete:"off",spellcheck:"false","aria-autocomplete":"list"});#t=l("button",{type:"button",class:"toggle",part:"button",tabindex:"-1","aria-hidden":"true"});list;#e=null;#r=null;#i="idle";#o=0;#a;#n;#s=null;#d="";constructor(){super(),this.root.adoptedStyleSheets=[b(k),b(J)],this.#t.append(y(j)),this.box.append(this.control,this.#t),this.list=new G(this,this.box,this.control,e=>this.#f(e),()=>this.#l()),this.root.append(this.list.popup);let t=this.control;t.addEventListener("focus",()=>this.#d=this.value),t.addEventListener("input",this.#h),t.addEventListener("keydown",this.#m),t.addEventListener("blur",()=>this.#g()),this.#t.addEventListener("mousedown",e=>e.preventDefault()),this.#t.addEventListener("click",()=>{if(this.open)return this.close();this.control.focus(),this.show()}),this.upgrade("options","onsearch","value")}get allowCustom(){return this.hasAttribute("allow-custom")}set allowCustom(t){this.toggleAttribute("allow-custom",!!t)}get onsearch(){return this.#e}set onsearch(t){this.#e=typeof t=="function"?t:null,this.#r=null,this.optionsChanged()}get selectedOption(){return this.#u().find(t=>t.value===this.value)}show(){this.locked||this.open||(this.#e&&!this.#r&&this.#i!=="loading"&&this.#c(this.#s??""),this.list.show())}attributeChangedCallback(t,e,i){t==="allow-custom"&&e!==i&&this.resanitize(),super.attributeChangedCallback(t,e,i)}#u(){return[...this.options,...this.#r??[],...this.#n?[this.#n]:[]]}sanitize(t){return this.allowCustom||this.#e||!this.options.length||this.options.some(e=>e.value===t)?t:""}check(){return this.required&&!this.value?{kind:"valueMissing",message:Y()}:void 0}reset(){this.#s=null,this.close()}update(){let t=this.#s??(this.value?this.selectedOption?.label??this.value:"");this.control.value!==t&&(this.control.value=t),this.control.placeholder=this.placeholder,this.#t.disabled=this.locked,this.open&&this.#l()}#l(){let t=this.#e?this.#r??[]:Ut(this.options,this.#s??""),e=this.#i==="loading";this.list.render(t,this.value,this.listLabel),this.list.list.setAttribute("aria-busy",String(e));let i=e?S.searching:this.#i==="failed"?S.searchFailed:t.length||this.#e&&!this.#r?"":S.noResults;this.list.status.textContent!==i&&(this.list.status.textContent=i)}async#c(t){let e=++this.#o;this.#a?.abort();let i=this.#a=new AbortController;this.#i="loading",this.#l();let r=[],s="idle";try{r=await this.#e(t,i.signal)??[]}catch{s="failed"}e===this.#o&&(this.#r=r,this.#i=s,this.list.active=-1,this.#l())}#h=t=>{t.stopPropagation(),this.#s=this.control.value,this.list.active=-1,this.allowCustom&&this.setValue(this.#s)&&(this.render(),this.emit("input")),this.#e&&this.#c(this.#s),this.open?this.#l():this.show()};#m=t=>{if(t.isComposing)return;let e=this.list;switch(t.key){case"ArrowDown":case"ArrowUp":{t.preventDefault();let i=t.key==="ArrowDown";this.open?t.altKey?i||this.close():e.setActive(e.active<0?i?e.first():e.last():e.step(e.active,i?1:-1)):(this.show(),this.open&&!t.altKey&&e.setActive(i?e.first():e.last()));return}case"Enter":{let i=this.open?e.options[e.active]:void 0;if(i)return t.preventDefault(),this.#f(i);let r=this.open;this.#g(),r||this.form?.requestSubmit();return}case"Escape":if(this.open)return t.preventDefault(),this.close();this.control.value&&!this.locked&&(t.preventDefault(),this.#s="",this.#g())}};#f(t){this.#n=t,this.#s=null,this.close();let e=this.setValue(t.value);this.touch(),this.render(),e&&this.emit("input"),this.#p()}#g(){this.close();let t=this.#s;if(t===null)return;this.#s=null;let e=B(t.trim()),i=e?this.#u().find(o=>!o.disabled&&B(o.label)===e):void 0;i&&(this.#n=i);let r=e?i?i.value:this.allowCustom?t:void 0:"",s=r!==void 0&&this.setValue(r);this.touch(),this.render(),s&&this.emit("input"),this.#p()}#p(){this.value!==this.#d&&(this.#d=this.value,this.emit("change"))}};var ue=(n,t)=>{let e=0;for(let i=0;i<t&&e<n.length;e++)/\d/.test(n[e])&&i++;return e},$t=class extends E{static get observedAttributes(){return[...super.observedAttributes,"country","default-country","countries","locale","placeholder"]}control=l("input",{type:"tel",inputmode:"tel",autocomplete:"tel-national",part:"input"});#t=l("button",{type:"button",role:"combobox",class:"country",part:"country","aria-haspopup":"listbox"});#e=l("span");#r=l("span",{class:"country",role:"img",hidden:""});#i;#o=null;#a=null;#n="";#s;#d;constructor(){super(),this.root.adoptedStyleSheets=[b(k),b(J)],this.#t.append(this.#e,y(j)),this.box.append(this.#t,this.#r,this.control),this.#i=new G(this,this.box,this.#t,e=>this.#g(e.value),()=>this.#m()),this.root.append(this.#i.popup),this.#t.addEventListener("click",()=>this.#i.open?this.#i.hide():this.#f()),this.#t.addEventListener("keydown",e=>this.#i.selectKey(e)),this.#t.addEventListener("keyup",e=>e.key===" "&&e.preventDefault()),this.#t.addEventListener("blur",()=>this.#i.hide());let t=this.control;t.addEventListener("focus",()=>this.#n=this.value),t.addEventListener("input",this.#p),t.addEventListener("blur",()=>this.#b()),t.addEventListener("keydown",e=>{e.key!=="Enter"||e.isComposing||(this.#b(),this.form?.requestSubmit())}),this.upgrade("value","country")}get country(){return this.#o??this.#l(this.getAttribute("country"))??this.#l(this.getAttribute("default-country"))??this.#l(ft(U(this)))??this.#u?.[0]??"US"}set country(t){this.setAttribute("country",t)}get defaultCountry(){return this.getAttribute("default-country")??""}set defaultCountry(t){this.setAttribute("default-country",t)}get countries(){return this.getAttribute("countries")??""}set countries(t){this.setAttribute("countries",t)}get locale(){return this.getAttribute("locale")??""}set locale(t){this.setAttribute("locale",t)}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get open(){return this.#i.open}close(){this.#i.hide()}disconnectedCallback(){this.close()}get#u(){let t=this.countries.split(/[\s,]+/).map(e=>e.toUpperCase()).filter(e=>w[e]);return t.length?t:void 0}#l(t){let e=t?.trim().toUpperCase(),i=this.#u;return e&&w[e]&&(!i||i.includes(e))?e:void 0}#c(t){let e=U(this);if(!this.#s||this.#s[0]!==e){let i;try{i=new Intl.DisplayNames(e?[e]:void 0,{type:"region"})}catch{i=void 0}this.#s=[e,i]}return this.#s[1]?.of(t)??t}attributeChangedCallback(t,e,i){if(e!==i)if(t==="country"){let r=this.#l(i);r&&this.#h(r)}else t==="countries"&&this.#o&&!this.#l(this.#o)&&this.#h(null);super.attributeChangedCallback(t,e,i)}#h(t){let{national:e}=z(this.value,this.country);this.#o=t,this.#a=null,e?this.setValue(rt(e,this.country)):this.resanitize()}sanitize(t){if(!t.trim())return"";let e=z(t,this.country);return this.#l(e.country)?(this.#o=e.country,e.e164):""}reset(){this.#o=null,this.#a=null,this.#i.hide()}check(){return this.#a?{kind:"badInput",message:S.invalidPhone}:this.value?z(this.value,this.country).valid?void 0:{kind:"typeMismatch",message:S.invalidPhone}:this.required?{kind:"valueMissing",message:Y()}:void 0}update(){let t=this.country,e=this.#a??mt(z(this.value,t).national,t);this.control.value!==e&&(this.control.value=e),this.control.placeholder=this.placeholder;let i=M(t),r=S.countryCode(this.#c(t),i),s=this.#u?.length===1;this.#e.textContent=`+${i}`,this.#r.textContent=`+${i}`,this.#t.setAttribute("aria-label",r),this.#r.setAttribute("aria-label",r),this.#t.hidden=s,this.#r.hidden=!s,this.#t.disabled=this.isDisabled||this.readOnly,this.#i.open&&this.#m()}#m(){let t=this.#u,e=`${U(this)}|${this.countries}`;if(this.#d?.[0]!==e){let i=(t??Object.keys(w)).map(r=>({value:r,label:`${this.#c(r)} +${w[r]}`,keywords:[`+${w[r]}`]}));t||i.sort((r,s)=>r.label.localeCompare(s.label,U(this))),this.#d=[e,i]}this.#i.render(this.#d[1],this.country,this.#t.getAttribute("aria-label")??"")}#f(){this.#i.show(),this.#i.setActive(this.#i.indexOf(this.country))}#g(t){this.#i.hide();let e=this.country,i=this.value;this.#h(t),this.touch(),this.render(),this.country!==e&&this.dispatchEvent(new Event("countrychange",{bubbles:!0})),this.value!==i&&(this.emit("input"),this.#n=this.value,this.emit("change"))}#p=t=>{t.stopPropagation();let e=this.control,i=e.value,r=this.country,s=/^\s*(\+|00)/.test(i),o=z(i,r);this.#l(o.country)||(o=z(i.replace(/^[\s+0]+/,""),r),s=!1);let a=i.replace(/\D/g,"").slice(/^\s*0/.test(i)?2:0),d=M(o.country);this.#a=s&&!(a.startsWith(d)&&a.length>d.length)?i.replace(/[^\d+\s]/g,""):null;let u=i.slice(0,e.selectionStart??i.length).replace(/\D/g,""),g=u.startsWith("0")&&!o.national.startsWith("0")?1:0;this.#a||(this.#o=o.country);let c=this.setValue(this.#a?"":o.e164);if(this.render(),!this.#a){let h=ue(e.value,s?o.national.length:Math.max(0,u.length-g));e.setSelectionRange(h,h)}this.country!==r&&this.dispatchEvent(new Event("countrychange",{bubbles:!0})),c&&this.emit("input")};#b(){this.touch(),this.render(),this.value!==this.#n&&(this.#n=this.value,this.emit("change"))}};export{E as a,Pt as b,Rt as c,Z as d,Kt as e,Bt as f,$t as g};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { N as NxFieldElement } from './field-PQ7-S6JJ.js';
|
|
2
|
+
|
|
3
|
+
/** One choice in `<nx-select>` or `<nx-combobox>`: the shape of `@nexub/react`'s `ComboboxOption`. */
|
|
4
|
+
interface NxOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** A second line under the label (an email, a code). Also searched. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** More text the option is found by (type-ahead and filtering). */
|
|
10
|
+
keywords?: string[];
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** A heading the option is listed under; consecutive options with the same group share it. */
|
|
13
|
+
group?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The popup listbox of the three list fields. Focus never moves into it: the field keeps focus
|
|
17
|
+
* and points at the active option with `aria-activedescendant` (WAI-ARIA combobox pattern).
|
|
18
|
+
* The popup is a `popover="manual"` (the top layer) where the browser has it, placed under the
|
|
19
|
+
* field (above it without room), and a bottom sheet below 48rem.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
declare class ListPopup {
|
|
24
|
+
#private;
|
|
25
|
+
readonly host: HTMLElement;
|
|
26
|
+
readonly anchor: HTMLElement;
|
|
27
|
+
readonly control: HTMLElement;
|
|
28
|
+
readonly pick: (option: NxOption) => void;
|
|
29
|
+
/** Draws the options; runs before the popup opens. */
|
|
30
|
+
readonly refresh: () => void;
|
|
31
|
+
readonly popup: HTMLDivElement;
|
|
32
|
+
readonly status: HTMLDivElement;
|
|
33
|
+
readonly list: HTMLDivElement;
|
|
34
|
+
options: NxOption[];
|
|
35
|
+
/** The highlighted option's index, `-1` for none. */
|
|
36
|
+
active: number;
|
|
37
|
+
constructor(host: HTMLElement, anchor: HTMLElement, control: HTMLElement, pick: (option: NxOption) => void,
|
|
38
|
+
/** Draws the options; runs before the popup opens. */
|
|
39
|
+
refresh: () => void);
|
|
40
|
+
get open(): boolean;
|
|
41
|
+
/** Draws `options`; `selected` (the field's value) is `aria-selected` with a check. */
|
|
42
|
+
render(options: NxOption[], selected: string, label: string): void;
|
|
43
|
+
/** Highlights option `i` (`-1`: none) and scrolls it into view. */
|
|
44
|
+
setActive(i: number, scroll?: boolean): void;
|
|
45
|
+
/** The enabled option `count` steps from `from` in `dir`, stopping at the ends. */
|
|
46
|
+
step(from: number, dir: 1 | -1, count?: number): number;
|
|
47
|
+
first(): number;
|
|
48
|
+
last(): number;
|
|
49
|
+
indexOf(value: string): number;
|
|
50
|
+
show(): void;
|
|
51
|
+
hide(): void;
|
|
52
|
+
/** Under the field, the field's width (above it without room below); the sheet layout ignores this. */
|
|
53
|
+
place: () => void;
|
|
54
|
+
/** `true` while a type-ahead search is running (a space then adds to it). */
|
|
55
|
+
get typing(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Type-ahead: the next enabled option whose label (or a keyword) starts with the keys typed in
|
|
58
|
+
* the last half second; one key pressed again cycles through the options starting with it.
|
|
59
|
+
* `-1` when none matches.
|
|
60
|
+
*/
|
|
61
|
+
typeahead(key: string): number;
|
|
62
|
+
/**
|
|
63
|
+
* The select-only combobox keys (WAI-ARIA APG), for a button that opens this list. Closed:
|
|
64
|
+
* Arrow Down / Up, Enter, Space, Home, End open it; a printable key picks by type-ahead (as a
|
|
65
|
+
* native select). Open: arrows, Home / End, Page Up / Down (ten) and type-ahead move; Enter,
|
|
66
|
+
* Space and Alt+Arrow Up pick; Tab picks and moves on; Escape closes.
|
|
67
|
+
*/
|
|
68
|
+
selectKey(e: KeyboardEvent): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* What `<nx-select>` and `<nx-combobox>` share: options from child `<option>` / `<optgroup>`
|
|
72
|
+
* elements (watched for changes) or the `options` property, the placeholder, and the popup.
|
|
73
|
+
*
|
|
74
|
+
* @alpha
|
|
75
|
+
*/
|
|
76
|
+
declare abstract class NxChoiceElement extends NxFieldElement {
|
|
77
|
+
#private;
|
|
78
|
+
static get observedAttributes(): string[];
|
|
79
|
+
/** @internal */
|
|
80
|
+
protected abstract readonly list: ListPopup;
|
|
81
|
+
/** The options: the `options` property when set, else the child `<option>` elements. */
|
|
82
|
+
get options(): NxOption[];
|
|
83
|
+
/** Replaces the child `<option>`s as the source; `null` goes back to them. */
|
|
84
|
+
set options(v: NxOption[] | null);
|
|
85
|
+
get placeholder(): string;
|
|
86
|
+
set placeholder(v: string);
|
|
87
|
+
/** `true` while the list is open. */
|
|
88
|
+
get open(): boolean;
|
|
89
|
+
/** Closes the list. */
|
|
90
|
+
close(): void;
|
|
91
|
+
connectedCallback(): void;
|
|
92
|
+
disconnectedCallback(): void;
|
|
93
|
+
/** @internal The `value` attribute, else the child `<option selected>`. */
|
|
94
|
+
protected initial(): string;
|
|
95
|
+
/** @internal The options changed: the value is checked against them again. */
|
|
96
|
+
protected optionsChanged(): void;
|
|
97
|
+
/** @internal Read-only or disabled: the list can't open and the value can't change. */
|
|
98
|
+
protected get locked(): boolean;
|
|
99
|
+
/** @internal The text the list is named by: the field's own name. */
|
|
100
|
+
protected get listLabel(): string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { ListPopup as L, NxChoiceElement as N };
|
|
104
|
+
export type { NxOption as a };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { F as FieldError } from './field-PQ7-S6JJ.js';
|
|
2
|
+
export { N as NxFieldElement } from './field-PQ7-S6JJ.js';
|
|
3
|
+
import { N as NxChoiceElement, L as ListPopup, a as NxOption } from './choice-jYQxGH_T.js';
|
|
4
|
+
|
|
5
|
+
/** `<nx-combobox>`'s async search: the options for `query`; `signal` aborts when a newer search starts. */
|
|
6
|
+
type NxSearch = (query: string, signal: AbortSignal) => Promise<NxOption[]>;
|
|
7
|
+
/**
|
|
8
|
+
* `<nx-combobox>`: a form-associated editable combobox, the `@nexub/react` `ComboboxField`: a
|
|
9
|
+
* text field that filters a listbox as you type (WAI-ARIA combobox pattern, list autocomplete,
|
|
10
|
+
* `aria-activedescendant`). Options come from child `<option>` / `<optgroup>` elements or the
|
|
11
|
+
* `options` property, or from the server through `onsearch`.
|
|
12
|
+
*
|
|
13
|
+
* Without `allow-custom` the value is an option's value: text that names no option goes back
|
|
14
|
+
* to the picked option's label on blur (typing an option's label exactly picks it). With
|
|
15
|
+
* `allow-custom` the typed text is the value.
|
|
16
|
+
*
|
|
17
|
+
* Async search: set `onsearch` to `(query, signal) => Promise<options>`. It runs on every edit
|
|
18
|
+
* (debounce on your side) and when the list opens; only the latest search's answer is shown
|
|
19
|
+
* (older ones are dropped and their `signal` aborted). "Searching…", "No results found." and a
|
|
20
|
+
* failed search are announced in a live region.
|
|
21
|
+
*
|
|
22
|
+
* Keyboard: Arrow Down / Up open the list and move (Alt+Arrow Down opens without moving,
|
|
23
|
+
* Alt+Arrow Up closes), Enter picks (or, closed, submits the form), Escape closes, then clears.
|
|
24
|
+
*
|
|
25
|
+
* Attributes (reflected as properties): `name`, `value` (the default), `placeholder`,
|
|
26
|
+
* `allow-custom`, `required`, `disabled`, `readonly`, `invalid`, `size`. Events: `input` when
|
|
27
|
+
* the value changes, `change` when it was committed (a pick, blur, Enter).
|
|
28
|
+
*
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
declare class NxCombobox extends NxChoiceElement {
|
|
32
|
+
#private;
|
|
33
|
+
static get observedAttributes(): string[];
|
|
34
|
+
/** @internal */
|
|
35
|
+
protected readonly control: HTMLInputElement;
|
|
36
|
+
/** @internal */
|
|
37
|
+
protected readonly list: ListPopup;
|
|
38
|
+
constructor();
|
|
39
|
+
/** Free text: the typed text is the value when it names no option. */
|
|
40
|
+
get allowCustom(): boolean;
|
|
41
|
+
set allowCustom(v: boolean);
|
|
42
|
+
/** The async search (see the class docs); `null` filters the options here. */
|
|
43
|
+
get onsearch(): NxSearch | null;
|
|
44
|
+
set onsearch(fn: NxSearch | null);
|
|
45
|
+
/** The picked option, if it is known (an option, a search result or the last pick). */
|
|
46
|
+
get selectedOption(): NxOption | undefined;
|
|
47
|
+
/** Opens the list (and runs the search when there is none yet). */
|
|
48
|
+
show(): void;
|
|
49
|
+
attributeChangedCallback(name: string, old: string | null, next: string | null): void;
|
|
50
|
+
/** @internal Without free text or a search, a value that is none of the options is no value. */
|
|
51
|
+
protected sanitize(v: string): string;
|
|
52
|
+
/** @internal */
|
|
53
|
+
protected check(): FieldError;
|
|
54
|
+
/** @internal */
|
|
55
|
+
protected reset(): void;
|
|
56
|
+
/** @internal */
|
|
57
|
+
protected update(): void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Registers `<nx-combobox>` only (11.9): a page that uses one element loads just its code.
|
|
62
|
+
* `@nexub/elements/define` registers every element.
|
|
63
|
+
*
|
|
64
|
+
* @alpha
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
declare global {
|
|
68
|
+
interface HTMLElementTagNameMap {
|
|
69
|
+
'nx-combobox': NxCombobox;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { FieldError, ListPopup, NxChoiceElement, NxCombobox, NxOption };
|
|
74
|
+
export type { NxSearch };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var A={selectPlaceholder:"Select\u2026",noResults:"No results found.",searching:"Searching\u2026",searchFailed:"Search failed. Try again.",countryCode:(s,t)=>`Country code, ${s} +${t}`,invalidPhone:"Enter a valid phone number."};var m="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)";var g=`
|
|
2
|
+
:host { display: block; font-family: var(--font-family-sans, inherit); color: var(--color-on-surface); }
|
|
3
|
+
:host([hidden]) { display: none; }
|
|
4
|
+
/* The field draws focus itself; no second ring on the host. */
|
|
5
|
+
:host(:focus-within) { outline: none !important; }
|
|
6
|
+
* { box-sizing: border-box; }
|
|
7
|
+
.field {
|
|
8
|
+
display: flex; align-items: center; gap: 0.5rem; inline-size: 100%;
|
|
9
|
+
block-size: var(--size-control-md, 2.5rem); padding-inline: 0.875rem;
|
|
10
|
+
border: 1px solid var(--field-border, var(--color-outline));
|
|
11
|
+
border-radius: var(--field-radius, var(--shape-field));
|
|
12
|
+
background: var(--field-bg, var(--color-surface-container-lowest));
|
|
13
|
+
color: var(--field-fg, var(--color-on-surface));
|
|
14
|
+
font-size: var(--type-body-md-size, 1rem); line-height: var(--type-body-md-lineHeight, 1.5rem);
|
|
15
|
+
}
|
|
16
|
+
:host([size='sm']) .field {
|
|
17
|
+
block-size: var(--size-control-sm, 2rem); padding-inline: 0.75rem; gap: 0.375rem;
|
|
18
|
+
font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
|
|
19
|
+
}
|
|
20
|
+
:host([size='lg']) .field { block-size: var(--size-control-lg, 3rem); padding-inline: 1rem; }
|
|
21
|
+
.field:hover { border-color: var(--color-on-surface-variant); }
|
|
22
|
+
.field:focus-within, .field:focus-within:hover { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
|
|
23
|
+
.field[data-invalid], .field[data-invalid]:hover { border-color: var(--color-error); }
|
|
24
|
+
.field[data-invalid]:focus-within { border-color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }
|
|
25
|
+
.field[data-readonly], .field[data-readonly]:hover { border-color: var(--color-outline-variant); background: var(--color-surface-container-low); }
|
|
26
|
+
.field[data-disabled], .field[data-disabled]:hover {
|
|
27
|
+
cursor: not-allowed; border-color: var(--color-outline-variant);
|
|
28
|
+
background: var(--color-surface-container-low); color: var(--color-text-disabled);
|
|
29
|
+
}
|
|
30
|
+
/* 11.9: inline-size 100% (not the input's own ~20ch width) so the field's narrowest size is its
|
|
31
|
+
padding and button: at a 20rem viewport (WCAG 1.4.10 reflow) a grid or flex parent no longer overflows. */
|
|
32
|
+
input {
|
|
33
|
+
flex: 1; min-inline-size: 0; inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; outline: none;
|
|
34
|
+
background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums;
|
|
35
|
+
}
|
|
36
|
+
input::placeholder { color: var(--color-on-surface-muted); opacity: 1; }
|
|
37
|
+
input:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
|
|
38
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
39
|
+
.field { transition: border-color ${m}, box-shadow ${m}; }
|
|
40
|
+
}
|
|
41
|
+
@media (forced-colors: active) {
|
|
42
|
+
.field { border-color: FieldText; }
|
|
43
|
+
.field:focus-within { outline: 0.125rem solid Highlight; outline-offset: 0; }
|
|
44
|
+
.field[data-invalid] { border-style: dashed; }
|
|
45
|
+
.field[data-disabled] { border-color: GrayText; color: GrayText; }
|
|
46
|
+
}
|
|
47
|
+
`,S=new Map;function b(s){let t=S.get(s);return t||(t=new CSSStyleSheet,t.replaceSync(s),S.set(s,t)),t}var P=typeof HTMLElement>"u"?class{}:HTMLElement,v=class extends P{static formAssociated=!0;internals;root;box;#t="";#e=!1;#i=!1;#r=!1;static get observedAttributes(){return["value","required","disabled","readonly","size","aria-label","invalid"]}constructor(){super(),this.internals=this.attachInternals(),this.root=this.attachShadow({mode:"open",delegatesFocus:!0}),this.root.adoptedStyleSheets=[b(g)],this.box=document.createElement("div"),this.box.className="field",this.box.setAttribute("part","field"),this.root.append(this.box),this.addEventListener("invalid",()=>{this.#r=!0,this.render()})}connectedCallback(){this.#e||(this.#t=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(t,e,i){e!==i&&(t==="value"&&!this.#e&&(this.#t=this.sanitize(i??this.initial())),t==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#t}set value(t){this.#e=!0,this.#t=this.sanitize(String(t??"")),this.render()}get defaultValue(){return this.getAttribute("value")??""}set defaultValue(t){this.setAttribute("value",t)}get name(){return this.getAttribute("name")??""}set name(t){this.setAttribute("name",t)}get required(){return this.hasAttribute("required")}set required(t){this.toggleAttribute("required",!!t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",!!t)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(t){this.toggleAttribute("readonly",!!t)}get invalid(){return this.hasAttribute("invalid")}set invalid(t){this.toggleAttribute("invalid",!!t)}get size(){let t=this.getAttribute("size");return t==="sm"||t==="lg"?t:"md"}set size(t){this.setAttribute("size",t)}get form(){return this.internals.form}get labels(){return this.internals.labels}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}focus(t){this.control.focus(t)}blur(){this.control.blur()}formResetCallback(){this.#e=!1,this.#r=!1,this.reset(),this.#t=this.sanitize(this.initial()),this.render()}formDisabledCallback(t){this.#i=t,this.render()}formStateRestoreCallback(t){typeof t=="string"&&(this.value=t)}initial(){return this.getAttribute("value")??""}upgrade(...t){let e=this;for(let i of t){if(!Object.prototype.hasOwnProperty.call(this,i))continue;let r=e[i];delete e[i],e[i]=r}}reset(){}resanitize(){this.#t=this.sanitize(this.#e?this.#t:this.initial())}get isDisabled(){return this.disabled||this.#i}setValue(t){let e=this.sanitize(t),i=e!==this.#t;return this.#e=!0,this.#t=e,i}touch(){this.#r=!0}emit(t){this.dispatchEvent(new Event(t,{bubbles:!0,composed:t==="input"}))}render(){let t=this.check();this.internals.setFormValue(this.#t),t&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[t.kind]:!0},t.message,this.control):this.internals.setValidity({});let e=!!t&&this.#r&&!this.readOnly||this.invalid;this.box.toggleAttribute("data-invalid",e),this.box.toggleAttribute("data-disabled",this.isDisabled),this.box.toggleAttribute("data-readonly",this.readOnly),this.control.disabled=this.isDisabled,"readOnly"in this.control?this.control.readOnly=this.readOnly:this.control.setAttribute("aria-readonly",String(this.readOnly)),this.control.setAttribute("aria-required",String(this.required)),this.control.setAttribute("aria-invalid",String(e)),this.update()}nameControl(){let t=this.getAttribute("aria-label"),e=Array.from(this.internals.labels??[]);if(!e.length){let r=this.getRootNode(),o=this.id?Array.from(r.querySelectorAll("label[for]")).filter(a=>a.htmlFor===this.id):[],n=this.closest("label");e=n&&!o.includes(n)?[...o,n]:o}let i=t??e.map(r=>r.textContent?.trim()).filter(Boolean).join(" ");i?this.control.setAttribute("aria-label",i):this.control.removeAttribute("aria-label")}};var O="http://www.w3.org/2000/svg",y=s=>{let t=document.createElementNS(O,"svg"),e={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[i,r]of Object.entries(e))t.setAttribute(i,r);for(let[i,r]of s){let o=document.createElementNS(O,i);for(let[n,a]of Object.entries(r))o.setAttribute(n,a);t.append(o)}return t},l=(s,t={})=>{let e=document.createElement(s);for(let[i,r]of Object.entries(t))r!==void 0&&e.setAttribute(i,r);return e},z=[["path",{d:"m6 9 6 6 6-6"}]],N=[["path",{d:"M20 6 9 17l-5-5"}]];var M=s=>{try{return s.matches(":dir(rtl)")}catch{return s.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}};var E=A,R="(max-width: 47.99rem)",L=500,u=s=>s.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function D(s){return Array.from(s.querySelectorAll("option"),t=>{let e=t.parentElement?.localName==="optgroup"?t.parentElement:void 0;return{value:t.value,label:t.label,disabled:t.disabled||!!e?.disabled,group:e?.label||void 0}})}function F(s,t){let e=u(t.trim());return e?s.filter(i=>[i.label,i.description,...i.keywords??[]].some(r=>r&&u(r).includes(e))):s}var K=0,x=class{constructor(t,e,i,r,o){this.host=t;this.anchor=e;this.control=i;this.pick=r;this.refresh=o;this.list=l("div",{role:"listbox",id:this.#e,part:"listbox"}),this.popup.append(this.status,this.list),"popover"in this.popup&&(this.popup.popover="manual"),i.setAttribute("aria-controls",this.#e),i.setAttribute("aria-expanded","false"),this.popup.addEventListener("mousedown",n=>n.preventDefault()),this.list.addEventListener("click",n=>{let a=this.options[this.#n(n)];a&&!a.disabled&&this.pick(a)}),this.list.addEventListener("mousemove",n=>{let a=this.#n(n);a>=0&&a!==this.active&&!this.options[a].disabled&&this.setActive(a,!1)})}host;anchor;control;pick;refresh;popup=l("div",{class:"popup",part:"popup",hidden:""});status=l("div",{role:"status",class:"status"});list;options=[];active=-1;#t="";#e=`nx-list-${++K}`;#i="";#r=0;#n(t){let e=t.target.closest('[role="option"]');return e?Number(e.dataset.index):-1}get open(){return!this.popup.hidden}render(t,e,i){this.options=t,this.#t=e,i?this.list.setAttribute("aria-label",i):this.list.removeAttribute("aria-label");let r=[],o,n;t.forEach((a,p)=>{if(a.group!==n&&(n=a.group,o=void 0,n)){let h=`${this.#e}-g${p}`;o=l("div",{role:"group","aria-labelledby":h});let C=l("div",{role:"presentation",id:h,class:"heading"});C.textContent=n,o.append(C),r.push(o)}let d=`${this.#e}-${p}`,f=l("div",{role:"option",id:d,class:"option",part:"option","data-index":String(p),"aria-selected":String(a.value===e),"aria-disabled":a.disabled?"true":void 0,"aria-describedby":a.description?`${d}-d`:void 0}),c=l("span",{class:"label"});if(c.textContent=a.label,f.append(y(N),c),a.description){let h=l("span",{id:`${d}-d`,class:"description"});h.textContent=a.description,c.append(h)}o?o.append(f):r.push(f)}),this.list.replaceChildren(...r),this.active>=t.length&&(this.active=-1),this.setActive(this.active,!1)}setActive(t,e=!0){this.active=t;let i;for(let r of this.list.querySelectorAll('[role="option"]')){let o=Number(r.dataset.index)===t;r.toggleAttribute("data-active",o),o&&(i=r)}i&&this.open?(this.control.setAttribute("aria-activedescendant",i.id),e&&i.scrollIntoView?.({block:"nearest"})):this.control.removeAttribute("aria-activedescendant")}step(t,e,i=1){let r=t;for(let o=t+e;o>=0&&o<this.options.length&&i>0;o+=e)this.options[o].disabled||(r=o,i--);return r}first(){return this.step(-1,1)}last(){return this.step(this.options.length,-1)}indexOf(t){return this.options.findIndex(e=>e.value===t)}show(){if(!this.open){this.refresh(),this.popup.hidden=!1;try{this.popup.showPopover?.()}catch{}this.control.setAttribute("aria-expanded","true"),this.place(),window.addEventListener("resize",this.place),window.addEventListener("scroll",this.place,{capture:!0,passive:!0}),document.addEventListener("mousedown",this.#a,!0)}}hide(){if(this.open){try{this.popup.hidePopover?.()}catch{}this.popup.hidden=!0,this.active=-1,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant"),window.removeEventListener("resize",this.place),window.removeEventListener("scroll",this.place,!0),document.removeEventListener("mousedown",this.#a,!0)}}#a=t=>{t.composedPath().includes(this.host)||this.hide()};place=()=>{if(!this.open||window.matchMedia?.(R).matches)return;let t=this.anchor.getBoundingClientRect(),e=this.popup.offsetHeight,i=document.documentElement.clientWidth||innerWidth,r=document.documentElement.clientHeight||innerHeight,o=4,n=t.bottom+o;n+e>r-o&&t.top-o-e>=o&&(n=t.top-o-e);let a=this.popup.style;a.setProperty("--nx-top",`${Math.max(o,n)}px`),a.setProperty("--nx-start",`${Math.max(0,M(this.host)?i-t.right:t.left)}px`),a.setProperty("--nx-width",`${t.right-t.left}px`)};get typing(){return this.#i!==""&&Date.now()-this.#r<=L}typeahead(t){let e=Date.now();this.#i=e-this.#r>L?t:this.#i+t,this.#r=e;let i=u(this.#i),r=[...i].every(d=>d===i[0]),o=r?i[0]:i,n=this.active>=0?this.active:this.indexOf(this.#t),a=n<0?0:n+(r?1:0),p=this.options.length;for(let d=0;d<p;d++){let f=(a+d)%p,c=this.options[f];if(!c.disabled&&[c.label,...c.keywords??[]].some(h=>u(h).startsWith(o)))return f}return-1}selectKey(t){let{key:e}=t,i=e.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey,r=i&&(e!==" "||this.typing);if(!this.open){if(r){t.preventDefault(),this.refresh();let n=this.options[this.typeahead(e)];n&&this.pick(n)}else if(["ArrowDown","ArrowUp","Enter"," ","Home","End"].includes(e)){t.preventDefault(),this.show();let n=this.indexOf(this.#t);this.setActive(e==="Home"?this.first():e==="End"?this.last():n>=0&&!this.options[n].disabled?n:this.first())}return}let o;switch(e){case"ArrowDown":o=this.step(this.active,1);break;case"ArrowUp":if(t.altKey)return this.#s(t);o=this.active<0?this.last():this.step(this.active,-1);break;case"Home":o=this.first();break;case"End":o=this.last();break;case"PageDown":o=this.step(this.active,1,10);break;case"PageUp":o=this.step(this.active,-1,10);break;case"Enter":return this.#s(t);case"Tab":return this.#s();case"Escape":return t.preventDefault(),t.stopPropagation(),this.hide();default:if(!i)return;if(!r)return this.#s(t);if(o=this.typeahead(e),o<0)return t.preventDefault()}t.preventDefault(),this.setActive(o)}#s(t){t?.preventDefault();let e=this.options[this.active];e?this.pick(e):this.hide()}},w=class extends v{static get observedAttributes(){return[...super.observedAttributes,"placeholder"]}#t=null;#e=[];#i;get options(){return this.#t??this.#e}set options(t){this.#t=t?t.map(e=>({...e,value:String(e.value),label:String(e.label??e.value)})):null,this.optionsChanged()}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get open(){return this.list.open}close(){this.list.hide()}connectedCallback(){this.#e=D(this),this.#i??=new MutationObserver(()=>{this.#e=D(this),this.#t||this.optionsChanged()}),this.#i.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","label","disabled","selected"]}),super.connectedCallback()}disconnectedCallback(){this.#i?.disconnect(),this.list.hide()}initial(){return this.getAttribute("value")??this.querySelector("option[selected]")?.value??""}optionsChanged(){this.resanitize(),this.render()}get locked(){return this.isDisabled||this.readOnly}get listLabel(){return this.control.getAttribute("aria-label")??""}};function q(s,t,e,i){if(s!=="badInput"&&s!=="typeMismatch"&&typeof document<"u"){let r=document.createElement("input");if(s==="valueMissing"?r.required=!0:(r.type=t,r[s==="rangeUnderflow"?"min":"max"]=e,r.value=t==="number"?String(Number(e)+(s==="rangeUnderflow"?-1:1)):s==="rangeUnderflow"?"0001-01-01".slice(0,e.length):"9999-12-31".slice(0,e.length)),r.validationMessage)return r.validationMessage}return i}var T=()=>q("valueMissing","number","","Fill out this field.");var H=`
|
|
48
|
+
button { margin: 0; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
49
|
+
button:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
|
|
50
|
+
button svg, .option svg { inline-size: 1rem; block-size: 1rem; flex: none; }
|
|
51
|
+
.trigger { flex: 1; align-self: stretch; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; outline: none; text-align: start; }
|
|
52
|
+
/* One line, as the React trigger's line-clamp-1. */
|
|
53
|
+
.text { flex: 1; min-inline-size: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow-wrap: anywhere; }
|
|
54
|
+
.trigger[data-placeholder] .text { color: var(--color-on-surface-muted); }
|
|
55
|
+
.trigger svg, .toggle svg, .country svg { color: var(--color-on-surface-variant); }
|
|
56
|
+
.toggle { flex: none; display: inline-flex; align-items: center; justify-content: center; inline-size: 1.75rem; block-size: 1.75rem; margin-inline-end: -0.5rem; border-radius: 999rem; }
|
|
57
|
+
.country {
|
|
58
|
+
flex: none; display: inline-flex; align-items: center; gap: 0.25rem; align-self: stretch;
|
|
59
|
+
margin-block: 0.25rem; margin-inline-start: -0.5rem; padding-inline: 0.5rem;
|
|
60
|
+
border-radius: var(--shape-control, 999rem); font-variant-numeric: tabular-nums; outline: none;
|
|
61
|
+
}
|
|
62
|
+
span.country { color: var(--color-on-surface-variant); }
|
|
63
|
+
.country[hidden] { display: none; }
|
|
64
|
+
button.country:hover { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
|
|
65
|
+
button.country:focus-visible { background: color-mix(in srgb, var(--color-on-surface) 12%, transparent); }
|
|
66
|
+
button.country:disabled { background: transparent; }
|
|
67
|
+
.popup {
|
|
68
|
+
position: fixed; z-index: var(--z-popover); margin: 0; inset: auto;
|
|
69
|
+
inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
|
|
70
|
+
inline-size: max(var(--nx-width, 12rem), 12rem); max-inline-size: calc(100vw - 1rem); max-block-size: min(24rem, calc(100dvh - 1rem));
|
|
71
|
+
display: flex; flex-direction: column; overflow: auto; padding: 0.375rem; border: 0;
|
|
72
|
+
border-radius: var(--shape-container, 1rem); background: var(--color-surface-elevated, var(--color-surface));
|
|
73
|
+
color: var(--color-on-surface); box-shadow: var(--elevation-2);
|
|
74
|
+
font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
|
|
75
|
+
}
|
|
76
|
+
.popup[hidden] { display: none; }
|
|
77
|
+
.status { padding: 0.5rem 0.75rem; color: var(--color-on-surface-muted); }
|
|
78
|
+
.status:empty { display: none; }
|
|
79
|
+
.heading { padding: 0.5rem 0.5rem 0.25rem; font-size: var(--type-label-sm-size, 0.75rem); font-weight: var(--type-label-lg-weight, 600); color: var(--color-on-surface-muted); }
|
|
80
|
+
.option { display: flex; align-items: center; gap: 0.5rem; min-block-size: 2.25rem; padding: 0.375rem 0.5rem; border-radius: 0.625rem; cursor: default; }
|
|
81
|
+
.option svg { visibility: hidden; }
|
|
82
|
+
.option[aria-selected='true'] svg { visibility: visible; }
|
|
83
|
+
.option[data-active] { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
|
|
84
|
+
.option[aria-disabled='true'] { color: var(--color-text-disabled); }
|
|
85
|
+
.description { display: block; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
|
|
86
|
+
@media (max-width: 47.99rem) {
|
|
87
|
+
.popup {
|
|
88
|
+
inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 50dvh;
|
|
89
|
+
border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
|
|
90
|
+
border-end-start-radius: 0; border-end-end-radius: 0;
|
|
91
|
+
padding-block-end: max(0.375rem, env(safe-area-inset-bottom));
|
|
92
|
+
}
|
|
93
|
+
.option { min-block-size: 2.75rem; }
|
|
94
|
+
}
|
|
95
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
96
|
+
.popup:not([hidden]) { animation: nx-fade var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
|
|
97
|
+
@keyframes nx-fade { from { opacity: 0; } }
|
|
98
|
+
.trigger svg, button.country { transition: rotate ${m}, background-color ${m}; }
|
|
99
|
+
}
|
|
100
|
+
[aria-expanded='true'] > svg { rotate: 180deg; }
|
|
101
|
+
@media (forced-colors: active) {
|
|
102
|
+
.popup { outline: 1px solid CanvasText; }
|
|
103
|
+
.option[data-active] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
104
|
+
.option[aria-disabled='true'], button:disabled { color: GrayText; }
|
|
105
|
+
button.country:focus-visible { outline: 0.125rem solid Highlight; }
|
|
106
|
+
}
|
|
107
|
+
`;var k=class extends w{static get observedAttributes(){return[...super.observedAttributes,"allow-custom"]}control=l("input",{type:"text",role:"combobox",part:"input",autocomplete:"off",spellcheck:"false","aria-autocomplete":"list"});#t=l("button",{type:"button",class:"toggle",part:"button",tabindex:"-1","aria-hidden":"true"});list;#e=null;#i=null;#r="idle";#n=0;#a;#s;#o=null;#d="";constructor(){super(),this.root.adoptedStyleSheets=[b(g),b(H)],this.#t.append(y(z)),this.box.append(this.control,this.#t),this.list=new x(this,this.box,this.control,e=>this.#p(e),()=>this.#l()),this.root.append(this.list.popup);let t=this.control;t.addEventListener("focus",()=>this.#d=this.value),t.addEventListener("input",this.#m),t.addEventListener("keydown",this.#b),t.addEventListener("blur",()=>this.#c()),this.#t.addEventListener("mousedown",e=>e.preventDefault()),this.#t.addEventListener("click",()=>{if(this.open)return this.close();this.control.focus(),this.show()}),this.upgrade("options","onsearch","value")}get allowCustom(){return this.hasAttribute("allow-custom")}set allowCustom(t){this.toggleAttribute("allow-custom",!!t)}get onsearch(){return this.#e}set onsearch(t){this.#e=typeof t=="function"?t:null,this.#i=null,this.optionsChanged()}get selectedOption(){return this.#h().find(t=>t.value===this.value)}show(){this.locked||this.open||(this.#e&&!this.#i&&this.#r!=="loading"&&this.#u(this.#o??""),this.list.show())}attributeChangedCallback(t,e,i){t==="allow-custom"&&e!==i&&this.resanitize(),super.attributeChangedCallback(t,e,i)}#h(){return[...this.options,...this.#i??[],...this.#s?[this.#s]:[]]}sanitize(t){return this.allowCustom||this.#e||!this.options.length||this.options.some(e=>e.value===t)?t:""}check(){return this.required&&!this.value?{kind:"valueMissing",message:T()}:void 0}reset(){this.#o=null,this.close()}update(){let t=this.#o??(this.value?this.selectedOption?.label??this.value:"");this.control.value!==t&&(this.control.value=t),this.control.placeholder=this.placeholder,this.#t.disabled=this.locked,this.open&&this.#l()}#l(){let t=this.#e?this.#i??[]:F(this.options,this.#o??""),e=this.#r==="loading";this.list.render(t,this.value,this.listLabel),this.list.list.setAttribute("aria-busy",String(e));let i=e?E.searching:this.#r==="failed"?E.searchFailed:t.length||this.#e&&!this.#i?"":E.noResults;this.list.status.textContent!==i&&(this.list.status.textContent=i)}async#u(t){let e=++this.#n;this.#a?.abort();let i=this.#a=new AbortController;this.#r="loading",this.#l();let r=[],o="idle";try{r=await this.#e(t,i.signal)??[]}catch{o="failed"}e===this.#n&&(this.#i=r,this.#r=o,this.list.active=-1,this.#l())}#m=t=>{t.stopPropagation(),this.#o=this.control.value,this.list.active=-1,this.allowCustom&&this.setValue(this.#o)&&(this.render(),this.emit("input")),this.#e&&this.#u(this.#o),this.open?this.#l():this.show()};#b=t=>{if(t.isComposing)return;let e=this.list;switch(t.key){case"ArrowDown":case"ArrowUp":{t.preventDefault();let i=t.key==="ArrowDown";this.open?t.altKey?i||this.close():e.setActive(e.active<0?i?e.first():e.last():e.step(e.active,i?1:-1)):(this.show(),this.open&&!t.altKey&&e.setActive(i?e.first():e.last()));return}case"Enter":{let i=this.open?e.options[e.active]:void 0;if(i)return t.preventDefault(),this.#p(i);let r=this.open;this.#c(),r||this.form?.requestSubmit();return}case"Escape":if(this.open)return t.preventDefault(),this.close();this.control.value&&!this.locked&&(t.preventDefault(),this.#o="",this.#c())}};#p(t){this.#s=t,this.#o=null,this.close();let e=this.setValue(t.value);this.touch(),this.render(),e&&this.emit("input"),this.#f()}#c(){this.close();let t=this.#o;if(t===null)return;this.#o=null;let e=u(t.trim()),i=e?this.#h().find(n=>!n.disabled&&u(n.label)===e):void 0;i&&(this.#s=i);let r=e?i?i.value:this.allowCustom?t:void 0:"",o=r!==void 0&&this.setValue(r);this.touch(),this.render(),o&&this.emit("input"),this.#f()}#f(){this.value!==this.#d&&(this.#d=this.value,this.emit("change"))}};function V(s,t){typeof customElements<"u"&&!customElements.get(s)&&customElements.define(s,t)}V("nx-combobox",k);export{k as NxCombobox};
|