@nexub/elements 0.0.0 → 11.6.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/LICENSE +21 -0
- package/dist/chunk-DSA3RZXV.js +119 -0
- package/dist/define.d.ts +17 -0
- package/dist/define.js +1 -0
- package/dist/index.d.ts +202 -0
- package/dist/index.js +1 -0
- package/package.json +67 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexub Pte. Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var Z="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)",De="outline: 0.1875rem solid var(--color-ring-default, var(--color-primary)); outline-offset: 0.125rem;",Y=`
|
|
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
|
+
input {
|
|
31
|
+
flex: 1; min-inline-size: 0; block-size: 100%; margin: 0; padding: 0; border: 0; outline: none;
|
|
32
|
+
background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums;
|
|
33
|
+
}
|
|
34
|
+
input::placeholder { color: var(--color-on-surface-muted); opacity: 1; }
|
|
35
|
+
input:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
|
|
36
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
37
|
+
.field { transition: border-color ${Z}, box-shadow ${Z}; }
|
|
38
|
+
}
|
|
39
|
+
@media (forced-colors: active) {
|
|
40
|
+
.field { border-color: FieldText; }
|
|
41
|
+
.field:focus-within { outline: 0.125rem solid Highlight; outline-offset: 0; }
|
|
42
|
+
.field[data-invalid] { border-style: dashed; }
|
|
43
|
+
.field[data-disabled] { border-color: GrayText; color: GrayText; }
|
|
44
|
+
}
|
|
45
|
+
`,he=`
|
|
46
|
+
:host([size='sm']) .field { padding-inline-end: 0.125rem; }
|
|
47
|
+
.field { padding-inline-end: 0.25rem; }
|
|
48
|
+
:host([size='lg']) .field { padding-inline-end: 0.375rem; }
|
|
49
|
+
button {
|
|
50
|
+
position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center;
|
|
51
|
+
margin: 0; padding: 0; border: 1px solid transparent; border-radius: var(--shape-control, 999rem);
|
|
52
|
+
background: transparent; color: inherit; font: inherit; cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
/* The state layer (themes' .nx-state-layer): the text colour at the --state-* opacity. */
|
|
55
|
+
button::before {
|
|
56
|
+
content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
|
|
57
|
+
background: currentColor; opacity: 0; pointer-events: none;
|
|
58
|
+
}
|
|
59
|
+
button:hover::before { opacity: var(--state-hover, 0.08); }
|
|
60
|
+
button:focus-visible::before { opacity: var(--state-focus, 0.1); }
|
|
61
|
+
button:active::before { opacity: var(--state-pressed, 0.1); }
|
|
62
|
+
button:disabled { cursor: default; pointer-events: none; color: var(--color-text-disabled); }
|
|
63
|
+
button:disabled::before { opacity: 0; }
|
|
64
|
+
button:focus-visible { ${De} }
|
|
65
|
+
svg { inline-size: 1rem; block-size: 1rem; flex: none; }
|
|
66
|
+
.open { flex: none; inline-size: 2rem; block-size: 2rem; border-radius: 999rem; }
|
|
67
|
+
:host([size='sm']) .open { inline-size: 1.75rem; block-size: 1.75rem; }
|
|
68
|
+
dialog {
|
|
69
|
+
position: fixed; margin: 0; inset: auto;
|
|
70
|
+
inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
|
|
71
|
+
inline-size: max-content; max-inline-size: calc(100vw - 1rem); max-block-size: calc(100dvh - 1rem); overflow: auto;
|
|
72
|
+
padding: 0.75rem; border: 0; border-radius: var(--shape-container, 1rem);
|
|
73
|
+
background: var(--color-surface-elevated, var(--color-surface)); color: var(--color-on-surface);
|
|
74
|
+
box-shadow: var(--elevation-2); font-size: var(--type-body-sm-size, 0.875rem);
|
|
75
|
+
}
|
|
76
|
+
dialog::backdrop { background: transparent; }
|
|
77
|
+
.head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-block-end: 0.5rem; }
|
|
78
|
+
.title { font-size: var(--type-label-lg-size, 0.875rem); font-weight: var(--type-label-lg-weight, 600); }
|
|
79
|
+
.nav { inline-size: 1.75rem; block-size: 1.75rem; border-radius: 999rem; }
|
|
80
|
+
:host(:dir(rtl)) .nav svg { transform: scaleX(-1); }
|
|
81
|
+
table { border-collapse: collapse; margin-inline: auto; }
|
|
82
|
+
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); }
|
|
83
|
+
td { padding: 0; padding-block-start: 0.25rem; text-align: center; }
|
|
84
|
+
.day, .cell { font-variant-numeric: tabular-nums; border-radius: 999rem; }
|
|
85
|
+
.day { inline-size: var(--day-cell, 2rem); block-size: var(--day-cell, 2rem); }
|
|
86
|
+
.day[data-outside]:not([aria-pressed='true']):not(:disabled) { color: var(--color-on-surface-muted); }
|
|
87
|
+
.cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.25rem; inline-size: 16.5rem; max-inline-size: 100%; }
|
|
88
|
+
/* Long month names in some locales wrap to two lines rather than overflow. */
|
|
89
|
+
.cell { block-size: 2.5rem; padding-inline: 0.25rem; line-height: 1.125; overflow-wrap: anywhere; }
|
|
90
|
+
[aria-current='date'] { border-color: var(--color-primary); }
|
|
91
|
+
[aria-pressed='true'], [aria-selected='true'] > button { background: var(--color-primary); color: var(--color-on-primary); }
|
|
92
|
+
@media (max-width: 47.99rem) {
|
|
93
|
+
dialog {
|
|
94
|
+
inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 85dvh;
|
|
95
|
+
border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
|
|
96
|
+
border-end-start-radius: 0; border-end-end-radius: 0;
|
|
97
|
+
padding-block-end: max(0.75rem, env(safe-area-inset-bottom));
|
|
98
|
+
}
|
|
99
|
+
dialog::before {
|
|
100
|
+
content: ''; display: block; inline-size: 2rem; block-size: 0.25rem; margin: 0 auto 0.5rem;
|
|
101
|
+
border-radius: var(--shape-overlay, 1.5rem); background: var(--color-outline-variant);
|
|
102
|
+
}
|
|
103
|
+
dialog::backdrop { background: color-mix(in srgb, var(--color-scrim, CanvasText) 40%, transparent); }
|
|
104
|
+
.cells { inline-size: 100%; }
|
|
105
|
+
.day { inline-size: 2.75rem; block-size: 2.75rem; }
|
|
106
|
+
}
|
|
107
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
108
|
+
button::before { transition: opacity ${Z}; }
|
|
109
|
+
dialog[open] { animation: nx-pop var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
|
|
110
|
+
@keyframes nx-pop { from { opacity: 0; scale: 0.96; } }
|
|
111
|
+
}
|
|
112
|
+
@media (forced-colors: active) {
|
|
113
|
+
dialog { outline: 1px solid CanvasText; }
|
|
114
|
+
button:focus-visible { outline-color: Highlight; }
|
|
115
|
+
[aria-current='date'] { border-color: CanvasText; }
|
|
116
|
+
[aria-pressed='true'], [aria-selected='true'] > button { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
117
|
+
button:disabled { color: GrayText; }
|
|
118
|
+
}
|
|
119
|
+
`,ce=new Map;function O(n){let e=ce.get(n);return e||(e=new CSSStyleSheet,e.replaceSync(n),ce.set(n,e)),e}var ke=typeof HTMLElement>"u"?class{}:HTMLElement,N=class extends ke{static formAssociated=!0;internals;root;box;#e="";#t=!1;#n=!1;#r=!1;static get observedAttributes(){return["value","required","disabled","readonly","size","aria-label"]}constructor(){super(),this.internals=this.attachInternals(),this.root=this.attachShadow({mode:"open",delegatesFocus:!0}),this.root.adoptedStyleSheets=[O(Y)],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.#t||(this.#e=this.sanitize(this.getAttribute("value")??"")),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(e,r,t){r!==t&&(e==="value"&&!this.#t&&(this.#e=this.sanitize(t??"")),e==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#e}set value(e){this.#t=!0,this.#e=this.sanitize(String(e??"")),this.render()}get defaultValue(){return this.getAttribute("value")??""}set defaultValue(e){this.setAttribute("value",e)}get name(){return this.getAttribute("name")??""}set name(e){this.setAttribute("name",e)}get required(){return this.hasAttribute("required")}set required(e){this.toggleAttribute("required",!!e)}get disabled(){return this.hasAttribute("disabled")}set disabled(e){this.toggleAttribute("disabled",!!e)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(e){this.toggleAttribute("readonly",!!e)}get size(){let e=this.getAttribute("size");return e==="sm"||e==="lg"?e:"md"}set size(e){this.setAttribute("size",e)}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(e){this.control.focus(e)}blur(){this.control.blur()}formResetCallback(){this.#t=!1,this.#r=!1,this.reset(),this.#e=this.sanitize(this.getAttribute("value")??""),this.render()}formDisabledCallback(e){this.#n=e,this.render()}formStateRestoreCallback(e){typeof e=="string"&&(this.value=e)}reset(){}resanitize(){this.#e=this.sanitize(this.#t?this.#e:this.getAttribute("value")??"")}get isDisabled(){return this.disabled||this.#n}setValue(e){let r=this.sanitize(e),t=r!==this.#e;return this.#t=!0,this.#e=r,t}touch(){this.#r=!0}emit(e){this.dispatchEvent(new Event(e,{bubbles:!0,composed:e==="input"}))}render(){let e=this.check();this.internals.setFormValue(this.#e),e&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[e.kind]:!0},e.message,this.control):this.internals.setValidity({});let r=!!e&&this.#r&&!this.readOnly;this.box.toggleAttribute("data-invalid",r),this.box.toggleAttribute("data-disabled",this.isDisabled),this.box.toggleAttribute("data-readonly",this.readOnly),this.control.disabled=this.isDisabled,this.control.readOnly=this.readOnly,this.control.setAttribute("aria-required",String(this.required)),this.control.setAttribute("aria-invalid",String(r)),this.update()}nameControl(){let e=this.getAttribute("aria-label"),r=Array.from(this.internals.labels??[]);if(!r.length){let i=this.getRootNode(),a=this.id?Array.from(i.querySelectorAll("label[for]")).filter(s=>s.htmlFor===this.id):[],o=this.closest("label");r=o&&!a.includes(o)?[...a,o]:a}let t=e??r.map(i=>i.textContent?.trim()).filter(Boolean).join(" ");t?this.control.setAttribute("aria-label",t):this.control.removeAttribute("aria-label")}};var we=/^[-+]?\d*(?:[.,]\d*)?$/;function Q(n){return we.test(n)}function U(n){let e=Number(n.trim().replace(",","."));return n.trim()!==""&&Number.isFinite(e)&&/\d/.test(n)?e:void 0}function z(n,e,r){let t=n;return e!==void 0&&t<e&&(t=e),r!==void 0&&t>r&&(t=r),t}function me(n=1){return n==="any"?1:n}function R(n,e,r,t){return z(n===null?z(0,r,t):n+e,r,t)}function X(n,e,{min:r,max:t,step:i}={}){let a=me(i);switch(n){case"ArrowUp":return R(e,a,r,t);case"ArrowDown":return R(e,-a,r,t);case"PageUp":return R(e,a*10,r,t);case"PageDown":return R(e,-a*10,r,t);case"Home":return r===void 0?void 0:z(r,r,t);case"End":return t===void 0?void 0:z(t,r,t);default:return}}var fe=/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/,Ae={year:0,month:1,day:2},W=(n,e=2)=>String(n).padStart(e,"0");function M(n,e){let r=new Date(0);return r.setUTCFullYear(n,e+1,0),r.getUTCDate()}function A(n){let e=n?fe.exec(n):null;if(!e)return;let r=e[3]?"day":e[2]?"month":"year";return c(n,r)?r:void 0}function c(n,e){let r=n?fe.exec(n):null;if(!r)return;let t=r[3]?"day":r[2]?"month":"year";if(e&&t!==e)return;let i=Number(r[1]),a=r[2]?Number(r[2])-1:0,o=r[3]?Number(r[3]):1;if(!(a<0||a>11||o<1||o>M(i,a)))return{year:i,month:a,day:o}}function v(n,e="day"){let r=W(n.year,4);return e==="year"?r:e==="month"?`${r}-${W(n.month+1)}`:`${r}-${W(n.month+1)}-${W(n.day)}`}function y(n,e,r="day"){let t=Ae[r];return n.year!==e.year?n.year-e.year:t>=1&&n.month!==e.month?n.month-e.month:t>=2&&n.day!==e.day?n.day-e.day:0}function H(n,e,r,t="day"){let i=c(e),a=c(r),o=(s,d)=>d==="year"?{year:s.year,month:11,day:31}:d==="month"?{...s,day:M(s.year,s.month)}:s;if(i&&y(n,i,t)<0)return"under";if(a&&y(n,o(a,A(r)),t)>0)return"over"}function $({year:n,month:e,day:r}){let t=new Date(0);return t.setUTCFullYear(n,e,r),t.getUTCDay()}function C({year:n,month:e,day:r},t){let i=new Date(0);return i.setUTCFullYear(n,e,r+t),{year:i.getUTCFullYear(),month:i.getUTCMonth(),day:i.getUTCDate()}}function x({year:n,month:e,day:r},t){let i=n*12+e+t,a=Math.floor(i/12),o=i-a*12;return{year:a,month:o,day:Math.min(r,M(a,o))}}function K(n=new Date){return{year:n.getFullYear(),month:n.getMonth(),day:n.getDate()}}var Se=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(" ")),Ee=new Set("AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));function B(n){let e;try{e=new Intl.Locale(n??new Intl.DateTimeFormat().resolvedOptions().locale)}catch{return 1}try{let t=typeof e.getWeekInfo=="function"?e.getWeekInfo():e.weekInfo;if(t&&typeof t.firstDay=="number")return t.firstDay%7}catch{}let r=e.maximize().region??"";return Se.has(r)?0:Ee.has(r)?6:1}var h={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`};function D(n,e,r,t){if(n!=="badInput"&&typeof document<"u"){let i=document.createElement("input");if(n==="valueMissing"?i.required=!0:(i.type=e,i[n==="rangeUnderflow"?"min":"max"]=r,i.value=e==="number"?String(Number(r)+(n==="rangeUnderflow"?-1:1)):n==="rangeUnderflow"?"0001-01-01".slice(0,r.length):"9999-12-31".slice(0,r.length)),i.validationMessage)return i.validationMessage}return t}var J=n=>{if(n===null||n.trim()==="")return;let e=Number(n);return Number.isFinite(e)?e:void 0},ee=class extends N{static get observedAttributes(){return[...super.observedAttributes,"min","max","step","placeholder"]}control=document.createElement("input");#e=null;#t="";constructor(){super();let e=this.control;e.type="text",e.inputMode="decimal",e.autocomplete="off",e.setAttribute("role","spinbutton"),e.setAttribute("part","input"),this.box.append(e),e.addEventListener("focus",()=>{this.#e=this.value,this.#t=this.value}),e.addEventListener("input",this.#r),e.addEventListener("blur",this.#o),e.addEventListener("keydown",this.#i)}get min(){return this.getAttribute("min")??""}set min(e){this.setAttribute("min",e)}get max(){return this.getAttribute("max")??""}set max(e){this.setAttribute("max",e)}get step(){return this.getAttribute("step")??""}set step(e){this.setAttribute("step",e)}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(e){this.setAttribute("placeholder",e)}get valueAsNumber(){return this.value===""?NaN:Number(this.value)}set valueAsNumber(e){this.value=Number.isFinite(e)?String(e):""}get#n(){let e=this.getAttribute("step"),r=J(e),t=e?.trim().toLowerCase()==="any"?"any":r!==void 0&&r>0?r:1;return{min:J(this.getAttribute("min")),max:J(this.getAttribute("max")),step:t}}sanitize(e){let r=U(e);return r===void 0?"":String(r)}reset(){this.#e=null,this.#t=this.sanitize(this.getAttribute("value")??"")}check(){let{min:e,max:r}=this.#n,t=this.#e;if(t!==null&&t.trim()!==""&&U(t)===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 i=Number(this.value);if(e!==void 0&&i<e)return{kind:"rangeUnderflow",message:D("rangeUnderflow","number",String(e),`Value must be ${e} or more.`)};if(r!==void 0&&i>r)return{kind:"rangeOverflow",message:D("rangeOverflow","number",String(r),`Value must be ${r} or less.`)}}update(){let e=this.control,{min:r,max:t}=this.#n,i=this.#e??this.value;e.value!==i&&(e.value=i),e.placeholder=this.placeholder;let a=(o,s)=>s===void 0?e.removeAttribute(o):e.setAttribute(o,String(s));a("aria-valuenow",this.value===""?void 0:Number(this.value)),a("aria-valuemin",r),a("aria-valuemax",t)}#r=e=>{e.stopPropagation();let r=this.control,t=r.value;if(!Q(t)){let o=this.#e??this.value,s=Math.max(0,(r.selectionStart??o.length)-(t.length-o.length));r.value=o,r.setSelectionRange?.(s,s);return}this.#e=t;let i=U(t),a=i!==void 0?this.setValue(String(i)):t.trim()===""?this.setValue(""):!1;this.render(),a&&this.emit("input")};#a(){this.#e=null;let{min:e,max:r}=this.#n,t=!1;this.value!==""&&!this.readOnly&&(t=this.setValue(String(z(Number(this.value),e,r)))),this.value!==this.#t&&this.touch(),this.render(),t&&this.emit("input"),this.value!==this.#t&&(this.#t=this.value,this.emit("change"))}#o=()=>this.#a();#i=e=>{if(e.key==="Enter"&&!e.isComposing){this.#a(),this.#e=this.value,this.form?.requestSubmit();return}if(this.readOnly){(e.key==="ArrowUp"||e.key==="ArrowDown")&&e.preventDefault();return}if(this.isDisabled)return;let r=this.value===""?null:Number(this.value),t=X(e.key,r,this.#n);if(t===void 0)return;e.preventDefault();let i=this.setValue(String(t));this.#e!==null&&(this.#e=this.value),this.touch(),this.render(),i&&(this.emit("input"),this.#t=this.value,this.emit("change"))}};var pe={year:0,month:1,day:2};function k({year:n,month:e,day:r}){let t=new Date(0);return t.setUTCFullYear(n,e,r),t}var F=(n,e)=>new Intl.DateTimeFormat(n,{timeZone:"UTC",...e}),te={year:"numeric",month:"2-digit",day:"2-digit"};function j(n,e,r){return e==="year"?String(n.year):F(r,e==="month"?{year:"numeric",month:"long"}:te).format(k(n))}function Ne(n){return F(n,te).formatToParts(k({year:2026,month:0,day:31})).map(e=>e.type).filter(e=>e==="year"||e==="month"||e==="day")}function re(n,e){if(n==="year")return"yyyy";let r={year:"yyyy",month:"mm",day:"dd"};return F(e,n==="month"?{year:"numeric",month:"2-digit"}:te).formatToParts(k({year:2026,month:0,day:31})).map(i=>i.type==="year"||i.type==="month"||i.type==="day"?r[i.type]:i.type==="literal"?i.value:"").join("").trim()}function ze(n,e){let r=new Intl.NumberFormat(e,{useGrouping:!1}),t=n;for(let i=0;i<=9;i++){let a=r.format(i);a!==String(i)&&(t=t.split(a).join(String(i)))}return t}function Me(n,e){let r=t=>t.toLowerCase().replace(/\.$/,"");for(let t=0;t<12;t++){let i=k({year:2026,month:t,day:1});if([F(e,{month:"long"}).format(i),F(e,{month:"short"}).format(i),F(e,{day:"numeric",month:"long"}).formatToParts(i).find(o=>o.type==="month")?.value??""].map(r).some(o=>o===n||n.length>=3&&o.startsWith(n)))return t}}function be(n,e,r){let t=ze(n.trim(),r);if(!t)return;let i=c(t);if(i)return pe[A(t)]>=pe[e]?i:void 0;let a,o=[];for(let m of t.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean))if(/^\d+$/.test(m))o.push(m);else{let S=Me(m,r);if(S===void 0||a!==void 0)return;a=S}let s=Ne(r).filter(m=>m==="year"||m==="month"&&e!=="year"&&a===void 0||m==="day"&&e==="day");if(o.length!==s.length)return;let d=m=>o[s.indexOf(m)]??"",g=d("year"),L={year:g.length<=2?2e3+Number(g):Number(g),month:a??(e==="year"?0:Number(d("month"))-1),day:e==="day"?Number(d("day")):1};return c(v(L,e),e)}var q={year:0,month:1,day:2},T=12,ye="http://www.w3.org/2000/svg",ne=n=>{let e=document.createElementNS(ye,"svg"),r={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[t,i]of Object.entries(r))e.setAttribute(t,i);for(let[t,i]of n){let a=document.createElementNS(ye,t);for(let[o,s]of Object.entries(i))a.setAttribute(o,s);e.append(a)}return e},Te=[["rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}],["path",{d:"M16 2v4M8 2v4M3 10h18"}]],Pe=[["path",{d:"m15 18-6-6 6-6"}]],Ce=[["path",{d:"m9 18 6-6-6-6"}]],Fe="(max-width: 47.99rem)",l=(n,e={})=>{let r=document.createElement(n);for(let[t,i]of Object.entries(e))i!==void 0&&r.setAttribute(t,i);return r},ie=n=>n-(n%T+T)%T,ae=class extends N{static get observedAttributes(){return[...super.observedAttributes,"min","max","granularity","locale"]}control=l("input",{type:"text",part:"input",autocomplete:"off",spellcheck:"false"});#e=l("button",{type:"button",part:"button",class:"open","aria-haspopup":"dialog","aria-expanded":"false"});#t=l("dialog",{part:"calendar"});#n=l("span",{class:"title","aria-live":"polite"});#r=l("button",{type:"button",class:"nav"});#a=l("button",{type:"button",class:"nav"});#o=l("div");#i=null;#s;#d=K();constructor(){super(),this.root.adoptedStyleSheets=[O(Y),O(he)],this.#e.replaceChildren(ne(Te)),this.#r.replaceChildren(ne(Pe)),this.#a.replaceChildren(ne(Ce));let e=l("div",{class:"head"});e.append(this.#r,this.#n,this.#a),this.#t.append(e,this.#o),this.box.append(this.control,this.#e),this.root.append(this.#t);let r=this.control;r.addEventListener("input",t=>{t.stopPropagation(),this.#i=r.value}),r.addEventListener("blur",()=>this.#b()),r.addEventListener("keydown",t=>{t.key!=="Enter"||t.isComposing||(this.#b(),this.form?.requestSubmit())}),this.#e.addEventListener("click",()=>this.show()),this.#r.addEventListener("click",()=>this.#y(-1)),this.#a.addEventListener("click",()=>this.#y(1)),this.#o.addEventListener("click",t=>{let i=t.target.closest("button[data-value]");i&&!i.disabled&&this.#g(i.dataset.value)}),this.#o.addEventListener("keydown",this.#v),this.#t.addEventListener("close",()=>{this.#e.setAttribute("aria-expanded","false"),window.removeEventListener("resize",this.#u),window.removeEventListener("scroll",this.#u,!0),this.control.focus()}),this.#t.addEventListener("click",t=>{if(t.target!==this.#t)return;let i=this.#t.getBoundingClientRect();(t.clientX<i.left||t.clientX>i.right||t.clientY<i.top||t.clientY>i.bottom)&&this.close()})}get min(){return this.getAttribute("min")??""}set min(e){this.setAttribute("min",e)}get max(){return this.getAttribute("max")??""}set max(e){this.setAttribute("max",e)}get granularity(){let e=this.getAttribute("granularity");return e==="month"||e==="year"?e:"day"}set granularity(e){this.setAttribute("granularity",e)}get locale(){return this.getAttribute("locale")??""}set locale(e){this.setAttribute("locale",e)}get value(){return super.value}set value(e){this.#i=null,this.#s=void 0,super.value=e}get open(){return this.#t.open}show(){this.open||this.isDisabled||this.readOnly||(this.#d=this.#h(c(this.value)??K()),this.#c(),this.#t.showModal(),this.#e.setAttribute("aria-expanded","true"),this.#u(),window.addEventListener("resize",this.#u),window.addEventListener("scroll",this.#u,{capture:!0,passive:!0}),this.#m())}close(){this.open&&this.#t.close()}attributeChangedCallback(e,r,t){e==="granularity"&&r!==t&&this.resanitize(),super.attributeChangedCallback(e,r,t),this.open&&this.#c()}get#l(){let e=this.getAttribute("locale")||this.closest("[lang]")?.getAttribute("lang")||void 0;try{return e?Intl.getCanonicalLocales(e)[0]:void 0}catch{return}}get#f(){try{return this.matches(":dir(rtl)")}catch{return this.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}}sanitize(e){let r=c(e.trim()),t=A(e.trim());return r&&t&&q[t]>=q[this.granularity]?v(r,this.granularity):""}reset(){this.#i=null,this.#s=void 0,this.close()}#p(e){let r=H(e,this.min,this.max,this.granularity);if(!r)return;let t=r==="under",i=c(t?this.min:this.max),a=this.granularity,o=j(i,a,this.#l),s=t?"rangeUnderflow":"rangeOverflow";return{kind:s,message:D(s,a==="day"?"date":a==="month"?"month":"number",v(i,a),`Value must be ${o} or ${t?"later":"earlier"}.`)}}check(){if(this.#s)return this.#s;let e=c(this.value);return e?this.#p(e):this.required?{kind:"valueMissing",message:D("valueMissing","date","","Fill out this field.")}:void 0}update(){let e=this.granularity,r=c(this.value),t=this.#i??(r?j(r,e,this.#l):"");this.control.value!==t&&(this.control.value=t),this.control.placeholder=re(e,this.#l),this.#e.disabled=this.isDisabled||this.readOnly,this.#e.setAttribute("aria-label",e==="day"?h.pickDate:e==="month"?h.pickMonth:h.pickYear)}#b(){let e=this.#i;if(e===null)return;let r=!1,t=e.trim()?be(e,this.granularity,this.#l):void 0;this.#s=!e.trim()||!t?e.trim()?{kind:"badInput",message:D("badInput","date","",`Enter a date as ${re(this.granularity,this.#l)}.`)}:void 0:this.#p(t),this.#s||(this.#i=null,r=this.setValue(t?v(t,this.granularity):"")),this.touch(),this.render(),r&&this.emit("change")}#g(e){this.#i=null,this.#s=void 0;let r=this.setValue(e);this.touch(),this.render(),this.close(),r&&this.emit("change")}#h(e){let r=this.granularity,t=H(e,this.min,this.max,r);if(!t)return e;let i=c(t==="under"?this.min:this.max);if(t==="under"||q[A(this.max)]>=q[r])return i;let a=A(this.max)==="year"?11:i.month;return{year:i.year,month:a,day:M(i.year,a)}}#y(e,r=!1){let t=this.granularity,i=this.#d;this.#d=this.#h(t==="day"?x(i,e):x(i,e*12*(t==="year"?T:1))),this.#c(),r&&this.#m()}#v=e=>{let r=this.granularity,t=this.#d,i=this.#f?-1:1,a=d=>r==="day"?C(t,d):x(t,d*(r==="year"?12:1)),o=()=>r==="day"?C(t,-(($(t)-B(this.#l)+7)%7)):r==="month"?{...t,month:0,day:1}:{year:ie(t.year),month:0,day:1},s;switch(e.key){case"ArrowLeft":s=a(-i);break;case"ArrowRight":s=a(i);break;case"ArrowUp":s=a(r==="day"?-7:-3);break;case"ArrowDown":s=a(r==="day"?7:3);break;case"PageUp":case"PageDown":{let d=e.key==="PageUp"?-1:1;s=r==="day"?x(t,d*(e.shiftKey?12:1)):x(t,d*12*(r==="year"?T:1));break}case"Home":s=o();break;case"End":s=r==="day"?C(o(),6):r==="month"?{...t,month:11,day:1}:{year:ie(t.year)+11,month:0,day:1};break;default:return}e.preventDefault(),this.#d=this.#h(s),this.#c(),this.#m()};#m(){this.#o.querySelector('[tabindex="0"]')?.focus()}#u=()=>{if(!this.open||window.matchMedia?.(Fe).matches)return;let e=this.box.getBoundingClientRect(),{offsetWidth:r,offsetHeight:t}=this.#t,i=document.documentElement.clientWidth||innerWidth,a=document.documentElement.clientHeight||innerHeight,o=4,s=e.bottom+o;s+t>a-o&&e.top-o-t>=o&&(s=e.top-o-t);let d=Math.max(o,Math.min(this.#f?i-e.right:e.left,i-r-o));this.#t.style.setProperty("--nx-top",`${Math.max(o,s)}px`),this.#t.style.setProperty("--nx-start",`${d}px`)};#c(){let e=this.granularity,r=this.#l,t=this.#d,i=c(this.value),a=K(),o=(u,b)=>H(u,this.min,this.max,b),s=u=>new Intl.DateTimeFormat(r,{timeZone:"UTC",...u}),d=new Intl.NumberFormat(r,{useGrouping:!1}),g,L,m,S,G;if(e==="day"){let u={year:t.year,month:t.month,day:1};g=s({month:"long",year:"numeric"}).format(k(u)),[L,m,S]=[x(u,-1),x(u,1),"month"];let b=B(r),E=($(u)-b+7)%7,f=Math.ceil((E+M(t.year,t.month))/7)*7;G=l("table",{role:"grid","aria-label":g});let P=l("tr");for(let w=0;w<7;w++){let p=k({year:1970,month:0,day:4+(b+w)%7}),V=l("th",{scope:"col",abbr:s({weekday:"long"}).format(p)});V.textContent=s({weekday:"short"}).format(p),P.append(V)}let oe=l("thead");oe.append(P);let se=l("tbody");G.append(oe,se);let xe=s({dateStyle:"full"}),le;for(let w=0;w<f;w++){w%7===0&&se.append(le=l("tr"));let p=C(u,w-E),V=i!==void 0&&y(p,i)===0,de=y(p,a)===0,I=xe.format(k(p));de&&(I=h.todayDate(I)),V&&(I=h.selectedDate(I));let ue=l("td",{role:"gridcell","aria-selected":V?"true":void 0}),_=l("button",{type:"button",class:"day","data-value":v(p),tabindex:y(p,t)===0?"0":"-1","aria-label":I,"aria-current":de?"date":void 0,"data-outside":p.month!==t.month?"":void 0});_.disabled=o(p,"day")!==void 0,_.textContent=d.format(p.day),ue.append(_),le.append(ue)}}else{let u=e==="month",b=u?t.year:ie(t.year);g=u?String(t.year):`${b} \u2013 ${b+T-1}`,S="year",L={year:u?t.year-1:b-1,month:0,day:1},m={year:u?t.year+1:b+T,month:0,day:1},G=l("div",{role:"group",class:"cells","aria-label":g});for(let E=0;E<12;E++){let f=u?{year:t.year,month:E,day:1}:{year:b+E,month:0,day:1},P=l("button",{type:"button",class:"cell","data-value":v(f,e),tabindex:y(f,t,e)===0?"0":"-1","aria-pressed":String(i!==void 0&&y(f,i,e)===0),"aria-current":y(f,a,e)===0?"date":void 0,"aria-label":u?j(f,"month",r):String(f.year)});P.disabled=o(f,e)!==void 0,P.textContent=u?s({month:"long"}).format(k(f)):String(f.year),G.append(P)}}this.#r.disabled=o(L,S)==="under",this.#a.disabled=o(m,S)==="over";let[ge,ve]=e==="day"?[h.previousMonth,h.nextMonth]:e==="month"?[h.previousYear,h.nextYear]:[h.previousYears,h.nextYears];this.#r.setAttribute("aria-label",ge),this.#a.setAttribute("aria-label",ve),this.#n.textContent=g,this.#t.setAttribute("aria-label",e==="day"?h.pickDate:e==="month"?h.pickMonth:h.pickYear),this.#o.replaceChildren(G)}};export{N as a,ee as b,ae as c};
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NxNumberInput, NxDatePicker } from './index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registers `<nx-number-input>` and `<nx-date-picker>` (skipped for a tag that is already
|
|
5
|
+
* defined, so loading this twice is safe).
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
'nx-number-input': NxNumberInput;
|
|
13
|
+
'nx-date-picker': NxDatePicker;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { NxDatePicker, NxNumberInput };
|
package/dist/define.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as t,c as n}from"./chunk-DSA3RZXV.js";var m=[["nx-number-input",t],["nx-date-picker",n]];if(typeof customElements<"u")for(let[e,r]of m)customElements.get(e)||customElements.define(e,r);export{n as NxDatePicker,t as NxNumberInput};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
type ValidityKind = 'valueMissing' | 'rangeUnderflow' | 'rangeOverflow' | 'badInput';
|
|
2
|
+
|
|
3
|
+
/** `HTMLElement`, or a stand-in where there is none (a server importing the classes), so the import doesn't throw. */
|
|
4
|
+
declare const Base: typeof HTMLElement;
|
|
5
|
+
/** Control sizes, as `@nexub/react`'s `size`. */
|
|
6
|
+
type NxFieldSize = 'sm' | 'md' | 'lg';
|
|
7
|
+
/** What a field's current value fails, with the message; `undefined` when valid. */
|
|
8
|
+
type FieldError = {
|
|
9
|
+
kind: ValidityKind;
|
|
10
|
+
message: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The form plumbing both elements share: form association through `ElementInternals`
|
|
14
|
+
* (form value, validity, reset, disabled from a fieldset, state restore), the attributes every
|
|
15
|
+
* field has, and naming the inner control from the host's `<label>`.
|
|
16
|
+
*
|
|
17
|
+
* `value` behaves as on a native input: the `value` attribute is the default (`defaultValue`),
|
|
18
|
+
* the `value` property is the current value; `form.reset()` goes back to the attribute.
|
|
19
|
+
*
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
declare abstract class NxFieldElement extends Base {
|
|
23
|
+
#private;
|
|
24
|
+
static formAssociated: boolean;
|
|
25
|
+
/** @internal */
|
|
26
|
+
protected readonly internals: ElementInternals;
|
|
27
|
+
/** @internal */
|
|
28
|
+
protected readonly root: ShadowRoot;
|
|
29
|
+
/** @internal The focusable control: the validation anchor, named from the label. */
|
|
30
|
+
protected abstract readonly control: HTMLInputElement;
|
|
31
|
+
/** @internal The bordered box around the control. */
|
|
32
|
+
protected readonly box: HTMLDivElement;
|
|
33
|
+
static get observedAttributes(): string[];
|
|
34
|
+
constructor();
|
|
35
|
+
/** @internal Turns any string into a valid value for this field (or `''`). */
|
|
36
|
+
protected abstract sanitize(value: string): string;
|
|
37
|
+
/** @internal What the current value fails, if anything. */
|
|
38
|
+
protected abstract check(): FieldError;
|
|
39
|
+
/** @internal Updates the shadow DOM from the state. */
|
|
40
|
+
protected abstract update(): void;
|
|
41
|
+
connectedCallback(): void;
|
|
42
|
+
attributeChangedCallback(name: string, old: string | null, next: string | null): void;
|
|
43
|
+
/** The current value: a string, `''` for none. Setting it doesn't fire events. */
|
|
44
|
+
get value(): string;
|
|
45
|
+
set value(v: string);
|
|
46
|
+
/** The `value` attribute: the value the field starts with and goes back to on `form.reset()`. */
|
|
47
|
+
get defaultValue(): string;
|
|
48
|
+
set defaultValue(v: string);
|
|
49
|
+
get name(): string;
|
|
50
|
+
set name(v: string);
|
|
51
|
+
get required(): boolean;
|
|
52
|
+
set required(v: boolean);
|
|
53
|
+
get disabled(): boolean;
|
|
54
|
+
set disabled(v: boolean);
|
|
55
|
+
get readOnly(): boolean;
|
|
56
|
+
set readOnly(v: boolean);
|
|
57
|
+
/** `sm`, `md` (default) or `lg`. */
|
|
58
|
+
get size(): NxFieldSize;
|
|
59
|
+
set size(v: NxFieldSize);
|
|
60
|
+
get form(): HTMLFormElement | null;
|
|
61
|
+
get labels(): NodeList;
|
|
62
|
+
get validity(): ValidityState;
|
|
63
|
+
get validationMessage(): string;
|
|
64
|
+
get willValidate(): boolean;
|
|
65
|
+
checkValidity(): boolean;
|
|
66
|
+
reportValidity(): boolean;
|
|
67
|
+
/** Focuses the inner field (a `<label for>` click does the same through `delegatesFocus`). */
|
|
68
|
+
focus(options?: FocusOptions): void;
|
|
69
|
+
blur(): void;
|
|
70
|
+
formResetCallback(): void;
|
|
71
|
+
formDisabledCallback(disabled: boolean): void;
|
|
72
|
+
formStateRestoreCallback(state: File | string | FormData | null): void;
|
|
73
|
+
/** @internal Clears typing state on reset. */
|
|
74
|
+
protected reset(): void;
|
|
75
|
+
/** @internal Runs `sanitize` again after an attribute it reads changed (the default when untouched). */
|
|
76
|
+
protected resanitize(): void;
|
|
77
|
+
/** @internal Disabled by its own attribute or by a disabled fieldset. */
|
|
78
|
+
protected get isDisabled(): boolean;
|
|
79
|
+
/** @internal Sets the value from the user; `true` when it changed. Doesn't render. */
|
|
80
|
+
protected setValue(v: string): boolean;
|
|
81
|
+
/** @internal Marks the field as edited, so an invalid value shows. */
|
|
82
|
+
protected touch(): void;
|
|
83
|
+
/** @internal Fires `input` / `change` as a native field does (`input` crosses shadow roots). */
|
|
84
|
+
protected emit(type: 'input' | 'change'): void;
|
|
85
|
+
/** @internal Form value, validity and the shadow DOM, from the state. */
|
|
86
|
+
protected render(): void;
|
|
87
|
+
/**
|
|
88
|
+
* @internal The label can't reach into the shadow root, so its text becomes the control's
|
|
89
|
+
* accessible name: the host's `aria-label`, else its `<label>`s.
|
|
90
|
+
*/
|
|
91
|
+
protected nameControl(): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* `<nx-number-input>`: a form-associated number field with the `@nexub/react` `NumberInput`
|
|
96
|
+
* rules (from `@nexub/core`). It can be empty (`value` is `''`), a half-typed `2.` or `-` stays
|
|
97
|
+
* as typed while focused, and `min` / `max` apply when it loses focus or on a step, never while
|
|
98
|
+
* typing. Arrow Up/Down step, Page Up/Down step ten times, Home/End go to `min`/`max`.
|
|
99
|
+
*
|
|
100
|
+
* Attributes (reflected as properties): `name`, `value` (the default), `min`, `max`, `step`
|
|
101
|
+
* (a number or `any`), `required`, `disabled`, `readonly`, `placeholder`, `size`.
|
|
102
|
+
*
|
|
103
|
+
* Events: `input` on every edit and step, `change` when the value was committed (blur, a step,
|
|
104
|
+
* Enter); `value` is a string, `''` when cleared.
|
|
105
|
+
*
|
|
106
|
+
* @alpha
|
|
107
|
+
*/
|
|
108
|
+
declare class NxNumberInput extends NxFieldElement {
|
|
109
|
+
#private;
|
|
110
|
+
static get observedAttributes(): string[];
|
|
111
|
+
/** @internal */
|
|
112
|
+
protected readonly control: HTMLInputElement;
|
|
113
|
+
constructor();
|
|
114
|
+
/** Smallest value, applied on blur and steps (a number as a string, `''` for none). */
|
|
115
|
+
get min(): string;
|
|
116
|
+
set min(v: string);
|
|
117
|
+
/** Largest value, applied on blur and steps. */
|
|
118
|
+
get max(): string;
|
|
119
|
+
set max(v: string);
|
|
120
|
+
/** The step for keys: a positive number, or `any` (any decimal; keys move by 1). Default 1. */
|
|
121
|
+
get step(): string;
|
|
122
|
+
set step(v: string);
|
|
123
|
+
get placeholder(): string;
|
|
124
|
+
set placeholder(v: string);
|
|
125
|
+
/** The value as a number, `NaN` when empty. */
|
|
126
|
+
get valueAsNumber(): number;
|
|
127
|
+
set valueAsNumber(n: number);
|
|
128
|
+
/** @internal */
|
|
129
|
+
protected sanitize(v: string): string;
|
|
130
|
+
/** @internal */
|
|
131
|
+
protected reset(): void;
|
|
132
|
+
/** @internal */
|
|
133
|
+
protected check(): FieldError;
|
|
134
|
+
/** @internal */
|
|
135
|
+
protected update(): void;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Date values as strings, shared by `@nexub/react`'s DatePicker (`granularity="month" | "year"`)
|
|
140
|
+
* and `@nexub/elements`' `<nx-date-picker>`. A value is `YYYY-MM-DD` (day), `YYYY-MM` (month) or
|
|
141
|
+
* `YYYY` (year): no time and no time zone, so a date never shifts by a day across zones. These
|
|
142
|
+
* are calendar-independent helpers (Gregorian calendar, plain arithmetic); the calendar grid
|
|
143
|
+
* itself is not shared (the React day picker uses react-day-picker).
|
|
144
|
+
*/
|
|
145
|
+
/** How fine a date value is. */
|
|
146
|
+
type DateGranularity = 'day' | 'month' | 'year';
|
|
147
|
+
|
|
148
|
+
/** `day`, `month` or `year`: what `<nx-date-picker>` picks. */
|
|
149
|
+
type NxDateGranularity = DateGranularity;
|
|
150
|
+
/**
|
|
151
|
+
* `<nx-date-picker>`: a form-associated date field. A text field that accepts a typed date
|
|
152
|
+
* (normalised on blur or Enter) and a button that opens a dialog with a grid: days, months
|
|
153
|
+
* (`granularity="month"`) or years (`granularity="year"`); a bottom sheet below 48rem. The
|
|
154
|
+
* value is `YYYY-MM-DD`, `YYYY-MM` or `YYYY`, so it never shifts across time zones.
|
|
155
|
+
*
|
|
156
|
+
* Keyboard in the grid (as `@nexub/react`'s DatePicker): arrows move, Page Up/Down change the
|
|
157
|
+
* month (Shift: the year; in the month and year grids, the page), Home/End go to the start or
|
|
158
|
+
* end of the week (row), Enter or Space picks, Escape closes; focus returns to the field.
|
|
159
|
+
*
|
|
160
|
+
* Attributes (reflected as properties): `name`, `value` (the default), `min`, `max`,
|
|
161
|
+
* `granularity`, `required`, `disabled`, `readonly`, `locale` (defaults to the nearest `lang`),
|
|
162
|
+
* `size`. Event: `change` when the value changes.
|
|
163
|
+
*
|
|
164
|
+
* @alpha
|
|
165
|
+
*/
|
|
166
|
+
declare class NxDatePicker extends NxFieldElement {
|
|
167
|
+
#private;
|
|
168
|
+
static get observedAttributes(): string[];
|
|
169
|
+
/** @internal */
|
|
170
|
+
protected readonly control: HTMLInputElement;
|
|
171
|
+
constructor();
|
|
172
|
+
get min(): string;
|
|
173
|
+
set min(v: string);
|
|
174
|
+
get max(): string;
|
|
175
|
+
set max(v: string);
|
|
176
|
+
/** `day` (default), `month` or `year`. */
|
|
177
|
+
get granularity(): NxDateGranularity;
|
|
178
|
+
set granularity(v: NxDateGranularity);
|
|
179
|
+
/** BCP 47 locale for month and weekday names and the typed format; `''` follows the nearest `lang`. */
|
|
180
|
+
get locale(): string;
|
|
181
|
+
set locale(v: string);
|
|
182
|
+
get value(): string;
|
|
183
|
+
set value(v: string);
|
|
184
|
+
/** `true` while the calendar is open. */
|
|
185
|
+
get open(): boolean;
|
|
186
|
+
/** Opens the calendar on the selected date (or today), focused. */
|
|
187
|
+
show(): void;
|
|
188
|
+
/** Closes the calendar; focus goes back to the field. */
|
|
189
|
+
close(): void;
|
|
190
|
+
attributeChangedCallback(name: string, old: string | null, next: string | null): void;
|
|
191
|
+
/** @internal Any of the three forms, cut to the granularity; a coarser one (`2026` for a day) is no value. */
|
|
192
|
+
protected sanitize(v: string): string;
|
|
193
|
+
/** @internal */
|
|
194
|
+
protected reset(): void;
|
|
195
|
+
/** @internal */
|
|
196
|
+
protected check(): FieldError;
|
|
197
|
+
/** @internal */
|
|
198
|
+
protected update(): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { NxDatePicker, NxFieldElement, NxNumberInput };
|
|
202
|
+
export type { NxDateGranularity, NxFieldSize };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./chunk-DSA3RZXV.js";export{c as NxDatePicker,a as NxFieldElement,b as NxNumberInput};
|
package/package.json
CHANGED
|
@@ -1 +1,67 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexub/elements",
|
|
3
|
+
"version": "11.6.0",
|
|
4
|
+
"description": "Web components for Nexub Design System: form-associated <nx-number-input> and <nx-date-picker> for server-rendered pages, with no framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/Nexub-AI/nexub-ds#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/Nexub-AI/nexub-ds.git",
|
|
11
|
+
"directory": "packages/elements"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"web-components",
|
|
15
|
+
"custom-elements",
|
|
16
|
+
"forms",
|
|
17
|
+
"design-system",
|
|
18
|
+
"nexub"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"./dist/define.js",
|
|
28
|
+
"./src/define.ts"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./define": {
|
|
36
|
+
"types": "./dist/define.d.ts",
|
|
37
|
+
"default": "./dist/define.js"
|
|
38
|
+
},
|
|
39
|
+
"./define.js": {
|
|
40
|
+
"types": "./dist/define.d.ts",
|
|
41
|
+
"default": "./dist/define.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"main": "./dist/index.js",
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@nexub/core": "11.6.0",
|
|
49
|
+
"@nexub/tokens": "11.6.0",
|
|
50
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
51
|
+
"@testing-library/user-event": "^14.6.8",
|
|
52
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
53
|
+
"jsdom": "^31.0.0",
|
|
54
|
+
"tsup": "^9.0.0",
|
|
55
|
+
"typescript": "~6.0.3",
|
|
56
|
+
"vite": "^8.3.6",
|
|
57
|
+
"vitest": "^5.1.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"clean": "rm -rf dist",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"test": "vitest run --coverage",
|
|
65
|
+
"lint": "eslint src"
|
|
66
|
+
}
|
|
67
|
+
}
|