@livenetworks/ashlar 1.3.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/ln-accordion/ln-accordion.js +1 -1
- package/js/ln-api-connector/ln-api-connector.js +1 -1
- package/js/ln-autoresize/ln-autoresize.js +1 -1
- package/js/ln-autosave/ln-autosave.js +1 -1
- package/js/ln-circular-progress/ln-circular-progress.js +1 -1
- package/js/ln-confirm/ln-confirm.js +1 -1
- package/js/ln-core/helpers.js +45 -0
- package/js/ln-core/index.js +1 -1
- package/js/ln-couchdb-connector/ln-couchdb-connector.js +1 -1
- package/js/ln-data-coordinator/ln-data-coordinator.js +1 -1
- package/js/ln-data-store/ln-data-store.js +1 -1
- package/js/ln-data-table/ln-data-table.js +1 -1
- package/js/ln-date/README.md +11 -1
- package/js/ln-date/ln-date.js +1 -1
- package/js/ln-date/src/ln-date.js +104 -1
- package/js/ln-dropdown/ln-dropdown.js +1 -1
- package/js/ln-filter/ln-filter.js +1 -1
- package/js/ln-form/ln-form.js +1 -1
- package/js/ln-modal/ln-modal.js +1 -1
- package/js/ln-number/ln-number.js +1 -1
- package/js/ln-number/src/ln-number.js +50 -2
- package/js/ln-popover/ln-popover.js +1 -1
- package/js/ln-search/ln-search.js +1 -1
- package/js/ln-sortable/ln-sortable.js +1 -1
- package/js/ln-table/ln-table.js +1 -1
- package/js/ln-tabs/ln-tabs.js +1 -1
- package/js/ln-time/ln-time.js +1 -1
- package/js/ln-toggle/ln-toggle.js +1 -1
- package/js/ln-tooltip/ln-tooltip.js +1 -1
- package/js/ln-translations/ln-translations.js +1 -1
- package/js/ln-validate/ln-validate.js +1 -1
- package/package.json +55 -55
- package/scss/components/_date.scss +21 -0
- package/scss/config/mixins/_form.scss +101 -54
- package/scss/config/mixins/_layout.scss +7 -9
- package/scss/ln-ashlar.scss +1 -0
package/js/ln-date/README.md
CHANGED
|
@@ -8,7 +8,17 @@ Locale-aware date formatting with native browser picker.
|
|
|
8
8
|
<input type="date" name="birthday" data-ln-date>
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
On initialization, the component
|
|
11
|
+
On initialization, the component wraps the original input in a `<span data-ln-date-field>` container and injects a visible text input, a hidden native date picker, a hidden form-submit input, and a calendar button. See [`docs/js/date.md`](../../docs/js/date.md) for the full DOM transform.
|
|
12
|
+
|
|
13
|
+
## Styling
|
|
14
|
+
|
|
15
|
+
Apply the `form-field-group` mixin to the wrapper element:
|
|
16
|
+
|
|
17
|
+
```scss
|
|
18
|
+
[data-ln-date-field] {
|
|
19
|
+
@include form-field-group;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
12
22
|
|
|
13
23
|
## Typing Support
|
|
14
24
|
|
package/js/ln-date/ln-date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function b(s,i,p){s.dispatchEvent(new CustomEvent(i,{bubbles:!0,detail:p||{}}))}function C(s,i){if(!document.body){document.addEventListener("DOMContentLoaded",function(){C(s,i)}),console.warn("["+i+'] Script loaded before <body> — add "defer" to your <script> tag');return}s()}function I(s,i,p,u){if(s.nodeType!==1)return;const M=i.indexOf("[")!==-1||i.indexOf(".")!==-1||i.indexOf("#")!==-1?i:"["+i+"]",S=Array.from(s.querySelectorAll(M));s.matches&&s.matches(M)&&S.push(s);for(const g of S)g[p]||(g[p]=new u(g))}function N(s){const i=s.closest("[lang]");return(i?i.lang:null)||navigator.language}function L(s,i,p,u,_={}){const M=_.extraAttributes||[],S=_.onAttributeChange||null,g=_.onInit||null;function w(O){const f=O||document.body;I(f,s,i,p),g&&g(f)}return C(function(){const O=new MutationObserver(function(h){for(let v=0;v<h.length;v++){const y=h[v];if(y.type==="childList")for(let t=0;t<y.addedNodes.length;t++){const e=y.addedNodes[t];e.nodeType===1&&(I(e,s,i,p),g&&g(e))}else y.type==="attributes"&&(S&&y.target[i]?S(y.target,y.attributeName):(I(y.target,s,i,p),g&&g(y.target)))}});let f=[];if(s.indexOf("[")!==-1){const h=/\[([\w-]+)/g;let v;for(;(v=h.exec(s))!==null;)f.push(v[1])}else f.push(s);O.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:f.concat(M)})},u),window[i]=w,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){w(document.body)}):w(document.body),w}const A={};function P(s,i){A[s]=i}function x(s){return A[s]||{ingress:i=>i,egress:i=>i}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=P,window.lnCore.getDataMapper=x),(function(){const s="data-ln-date",i="lnDate";if(window[i]!==void 0)return;const p={},u=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");function _(t,e){const n=t+"|"+JSON.stringify(e);return p[n]||(p[n]=new Intl.DateTimeFormat(t,e)),p[n]}const M=/^(short|medium|long)(\s+datetime)?$/,S={short:{dateStyle:"short"},medium:{dateStyle:"medium"},long:{dateStyle:"long"},"short datetime":{dateStyle:"short",timeStyle:"short"},"medium datetime":{dateStyle:"medium",timeStyle:"short"},"long datetime":{dateStyle:"long",timeStyle:"short"}};function g(t){return!t||t===""?{dateStyle:"medium"}:t.match(M)?S[t]:null}function w(t,e,n){const o=t.getDate(),d=t.getMonth(),a=t.getFullYear(),c=t.getHours(),r=t.getMinutes(),l={yyyy:String(a),yy:String(a).slice(-2),MMMM:_(n,{month:"long"}).format(t),MMM:_(n,{month:"short"}).format(t),MM:String(d+1).padStart(2,"0"),M:String(d+1),dd:String(o).padStart(2,"0"),d:String(o),HH:String(c).padStart(2,"0"),mm:String(r).padStart(2,"0")};return e.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d|HH|mm/g,function(m){return l[m]})}function O(t,e,n){const o=g(e);return o?_(n,o).format(t):w(t,e,n)}function f(t){if(t.tagName!=="INPUT")return console.warn("[ln-date] Can only be applied to <input>, got:",t.tagName),this;this.dom=t;const e=this,n=t.value,o=t.name,d=document.createElement("input");d.type="hidden",d.name=o,t.removeAttribute("name"),t.insertAdjacentElement("afterend",d),this._hidden=d;const a=document.createElement("input");a.type="date",a.tabIndex=-1,a.style.cssText="position:absolute;opacity:0;width:0;height:0;overflow:hidden;pointer-events:none",d.insertAdjacentElement("afterend",a),this._picker=a,t.type="text";const c=document.createElement("button");if(c.type="button",c.setAttribute("aria-label","Open date picker"),c.innerHTML='<svg class="ln-icon" aria-hidden="true"><use href="#ln-calendar"></use></svg>',a.insertAdjacentElement("afterend",c),this._btn=c,this._lastISO="",Object.defineProperty(d,"value",{get:function(){return u.get.call(d)},set:function(r){if(u.set.call(d,r),r&&r!==""){const l=h(r);l&&(e._displayFormatted(l),u.set.call(a,r))}else r===""&&(e.dom.value="",u.set.call(a,""))}}),this._onPickerChange=function(){const r=a.value;if(r){const l=h(r);l&&(e._setHiddenRaw(r),e._displayFormatted(l),e._lastISO=r,b(e.dom,"ln-date:change",{value:r,formatted:e.dom.value,date:l}))}else e._setHiddenRaw(""),e.dom.value="",e._lastISO="",b(e.dom,"ln-date:change",{value:"",formatted:"",date:null})},a.addEventListener("change",this._onPickerChange),this._onBlur=function(){const r=e.dom.value.trim();if(r===""){e._lastISO!==""&&(e._setHiddenRaw(""),u.set.call(e._picker,""),e.dom.value="",e._lastISO="",b(e.dom,"ln-date:change",{value:"",formatted:"",date:null}));return}if(e._lastISO){const m=h(e._lastISO);if(m){const E=e.dom.getAttribute(s)||"",D=N(e.dom),k=O(m,E,D);if(r===k)return}}const l=v(r);if(l){const m=l.getFullYear(),E=String(l.getMonth()+1).padStart(2,"0"),D=String(l.getDate()).padStart(2,"0"),k=m+"-"+E+"-"+D;e._setHiddenRaw(k),u.set.call(e._picker,k),e._displayFormatted(l),e._lastISO=k,b(e.dom,"ln-date:change",{value:k,formatted:e.dom.value,date:l})}else if(e._lastISO){const m=h(e._lastISO);m&&e._displayFormatted(m)}else e.dom.value=""},t.addEventListener("blur",this._onBlur),this._onBtnClick=function(){e._openPicker()},c.addEventListener("click",this._onBtnClick),n&&n!==""){const r=h(n);r&&(this._setHiddenRaw(n),u.set.call(a,n),this._displayFormatted(r),this._lastISO=n)}return this}function h(t){if(!t||typeof t!="string")return null;const e=t.split("T"),n=e[0].split("-");if(n.length<3)return null;const o=parseInt(n[0],10),d=parseInt(n[1],10)-1,a=parseInt(n[2],10);if(isNaN(o)||isNaN(d)||isNaN(a))return null;let c=0,r=0;if(e[1]){const m=e[1].split(":");c=parseInt(m[0],10)||0,r=parseInt(m[1],10)||0}const l=new Date(o,d,a,c,r);return l.getFullYear()!==o||l.getMonth()!==d||l.getDate()!==a?null:l}function v(t){if(!t||typeof t!="string"||(t=t.trim(),t.length<6))return null;let e,n;if(t.indexOf(".")!==-1)e=".",n=t.split(".");else if(t.indexOf("/")!==-1)e="/",n=t.split("/");else if(t.indexOf("-")!==-1)e="-",n=t.split("-");else return null;if(n.length!==3)return null;const o=[];for(let l=0;l<3;l++){const m=parseInt(n[l],10);if(isNaN(m))return null;o.push(m)}let d,a,c;e==="."?(d=o[0],a=o[1],c=o[2]):e==="/"?(a=o[0],d=o[1],c=o[2]):n[0].length===4?(c=o[0],a=o[1],d=o[2]):(d=o[0],a=o[1],c=o[2]),c<100&&(c+=c<50?2e3:1900);const r=new Date(c,a-1,d);return r.getFullYear()!==c||r.getMonth()!==a-1||r.getDate()!==d?null:r}f.prototype._openPicker=function(){if(typeof this._picker.showPicker=="function")try{this._picker.showPicker()}catch{this._picker.click()}else this._picker.click()},f.prototype._setHiddenRaw=function(t){u.set.call(this._hidden,t)},f.prototype._displayFormatted=function(t){const e=this.dom.getAttribute(s)||"",n=N(this.dom);this.dom.value=O(t,e,n)},Object.defineProperty(f.prototype,"value",{get:function(){return u.get.call(this._hidden)},set:function(t){if(!t||t===""){this._setHiddenRaw(""),u.set.call(this._picker,""),this.dom.value="",this._lastISO="";return}const e=h(t);e&&(this._setHiddenRaw(t),u.set.call(this._picker,t),this._displayFormatted(e),this._lastISO=t,b(this.dom,"ln-date:change",{value:t,formatted:this.dom.value,date:e}))}}),Object.defineProperty(f.prototype,"date",{get:function(){const t=this.value;return t?h(t):null},set:function(t){if(!t||!(t instanceof Date)||isNaN(t.getTime())){this.value="";return}const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0");this.value=e+"-"+n+"-"+o}}),Object.defineProperty(f.prototype,"formatted",{get:function(){return this.dom.value}}),f.prototype.destroy=function(){if(!this.dom[i])return;this._picker.removeEventListener("change",this._onPickerChange),this.dom.removeEventListener("blur",this._onBlur),this._btn.removeEventListener("click",this._onBtnClick),this.dom.name=this._hidden.name,this.dom.type="date";const t=this.value;this._hidden.remove(),this._picker.remove(),this._btn.remove(),t&&(this.dom.value=t),b(this.dom,"ln-date:destroyed",{target:this.dom}),delete this.dom[i]};function y(){new MutationObserver(function(){const t=document.querySelectorAll("["+s+"]");for(let e=0;e<t.length;e++){const n=t[e][i];if(n&&n.value){const o=h(n.value);o&&n._displayFormatted(o)}}}).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})}L(s,i,f,"ln-date"),y()})()})();
|
|
1
|
+
(function(){"use strict";function _(r,i,p){r.dispatchEvent(new CustomEvent(i,{bubbles:!0,detail:p||{}}))}function A(r,i){if(!document.body){document.addEventListener("DOMContentLoaded",function(){A(r,i)}),console.warn("["+i+'] Script loaded before <body> — add "defer" to your <script> tag');return}r()}function C(r,i,p,c){if(r.nodeType!==1)return;const S=i.indexOf("[")!==-1||i.indexOf(".")!==-1||i.indexOf("#")!==-1?i:"["+i+"]",M=Array.from(r.querySelectorAll(S));r.matches&&r.matches(S)&&M.push(r);for(const v of M)v[p]||(v[p]=new c(v))}function x(r){const i=r.closest("[lang]");return(i?i.lang:null)||navigator.language}function P(r,i,{get:p,set:c}){Object.defineProperty(r,"value",{get:function(){return p?p.call(this):i.get.call(this)},set:function(b){c?c.call(this,b,S=>i.set.call(this,S)):i.set.call(this,b)},configurable:!0})}function L(r,i,p,c,b={}){const S=b.extraAttributes||[],M=b.onAttributeChange||null,v=b.onInit||null;function I(E){const m=E||document.body;C(m,r,i,p),v&&v(m)}return A(function(){const E=new MutationObserver(function(g){for(let w=0;w<g.length;w++){const y=g[w];if(y.type==="childList"){for(let t=0;t<y.addedNodes.length;t++){const e=y.addedNodes[t];e.nodeType===1&&(C(e,r,i,p),v&&v(e))}for(let t=0;t<y.removedNodes.length;t++){const e=y.removedNodes[t];if(e.nodeType===1){const s=r.indexOf("[")!==-1||r.indexOf(".")!==-1||r.indexOf("#")!==-1?r:"["+r+"]",u=Array.from(e.querySelectorAll(s));e.matches&&e.matches(s)&&u.push(e);for(let d=0;d<u.length;d++){const o=u[d][i];o&&typeof o.destroy=="function"&&o.destroy()}}}}else y.type==="attributes"&&(M&&y.target[i]?M(y.target,y.attributeName):(C(y.target,r,i,p),v&&v(y.target)))}});let m=[];if(r.indexOf("[")!==-1){const g=/\[([\w-]+)/g;let w;for(;(w=g.exec(r))!==null;)m.push(w[1])}else m.push(r);E.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:m.concat(S)})},c),window[i]=I,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){I(document.body)}):I(document.body),I}const F={};function R(r,i){F[r]=i}function T(r){return F[r]||{ingress:i=>i,egress:i=>i}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=R,window.lnCore.getDataMapper=T),(function(){const r="data-ln-date",i="lnDate";if(window[i]!==void 0)return;const p={},c=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");function b(t,e){const a=t+"|"+JSON.stringify(e);return p[a]||(p[a]=new Intl.DateTimeFormat(t,e)),p[a]}const S=/^(short|medium|long)(\s+datetime)?$/,M={short:{dateStyle:"short"},medium:{dateStyle:"medium"},long:{dateStyle:"long"},"short datetime":{dateStyle:"short",timeStyle:"short"},"medium datetime":{dateStyle:"medium",timeStyle:"short"},"long datetime":{dateStyle:"long",timeStyle:"short"}};function v(t){return!t||t===""?{dateStyle:"medium"}:t.match(S)?M[t]:null}function I(t,e,a){const s=t.getDate(),u=t.getMonth(),d=t.getFullYear(),o=t.getHours(),f=t.getMinutes(),n={yyyy:String(d),yy:String(d).slice(-2),MMMM:b(a,{month:"long"}).format(t),MMM:b(a,{month:"short"}).format(t),MM:String(u+1).padStart(2,"0"),M:String(u+1),dd:String(s).padStart(2,"0"),d:String(s),HH:String(o).padStart(2,"0"),mm:String(f).padStart(2,"0")};return e.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d|HH|mm/g,function(l){return n[l]})}function E(t,e,a){const s=v(e);return s?b(a,s).format(t):I(t,e,a)}function m(t){if(t.tagName!=="INPUT")return console.warn("[ln-date] Can only be applied to <input>, got:",t.tagName),this;if(t[i])return t[i];t[i]=this,this.dom=t;const e=this,a=t.value,s=t.name,u=document.createElement("span");u.setAttribute("data-ln-date-field",""),t.parentNode.insertBefore(u,t),u.appendChild(t),this._wrapper=u;const d=document.createElement("input");d.type="hidden",d.name=s,t.removeAttribute("name"),t.insertAdjacentElement("afterend",d),this._hidden=d;const o=document.createElement("input");o.type="date",o.tabIndex=-1,o.style.cssText="position:absolute;opacity:0;width:0;height:0;overflow:hidden;pointer-events:none",d.insertAdjacentElement("afterend",o),this._picker=o,t.type="text";const f=document.createElement("button");if(f.type="button",f.setAttribute("aria-label","Open date picker"),f.innerHTML='<svg class="ln-icon" aria-hidden="true"><use href="#ln-calendar"></use></svg>',o.insertAdjacentElement("afterend",f),this._btn=f,this._lastISO="",Object.defineProperty(d,"value",{get:function(){return c.get.call(d)},set:function(n){if(c.set.call(d,n),n&&n!==""){const l=g(n);l&&(e._displayFormatted(l),c.set.call(o,n),e._lastISO=n,_(e.dom,"ln-date:change",{value:n,formatted:e.dom.value,date:l}),e.dom.dispatchEvent(new Event("change",{bubbles:!0})))}else n===""&&(e.dom.value="",c.set.call(o,""),e._lastISO="",_(e.dom,"ln-date:change",{value:"",formatted:"",date:null}),e.dom.dispatchEvent(new Event("change",{bubbles:!0})))}}),P(t,c,{get:function(){return c.get.call(t)},set:function(n,l){if(e._isFormatting){l(n);return}if(!n||n===""){l(""),e._setHiddenRaw(""),c.set.call(e._picker,""),e._lastISO="",_(t,"ln-date:change",{value:"",formatted:"",date:null}),t.dispatchEvent(new Event("change",{bubbles:!0}));return}let h=g(n);if(h||(h=w(n)),h){const k=h.getFullYear(),D=String(h.getMonth()+1).padStart(2,"0"),O=String(h.getDate()).padStart(2,"0"),N=k+"-"+D+"-"+O;e._setHiddenRaw(N),c.set.call(e._picker,N),e._lastISO=N;const B=t.getAttribute(r)||"",Y=x(t),H=E(h,B,Y);l(H),_(t,"ln-date:change",{value:N,formatted:H,date:h}),t.dispatchEvent(new Event("change",{bubbles:!0}))}else l(String(n)),e._setHiddenRaw(""),c.set.call(e._picker,""),e._lastISO="",_(t,"ln-date:change",{value:"",formatted:String(n),date:null}),t.dispatchEvent(new Event("change",{bubbles:!0}))}}),this._onPickerChange=function(){const n=o.value;if(n){const l=g(n);l&&(e._setHiddenRaw(n),e._displayFormatted(l),e._lastISO=n,_(e.dom,"ln-date:change",{value:n,formatted:e.dom.value,date:l}))}else e._setHiddenRaw(""),e.dom.value="",e._lastISO="",_(e.dom,"ln-date:change",{value:"",formatted:"",date:null})},o.addEventListener("change",this._onPickerChange),this._onBlur=function(){const n=e.dom.value.trim();if(n===""){e._lastISO!==""&&(e._setHiddenRaw(""),c.set.call(e._picker,""),e.dom.value="",e._lastISO="",_(e.dom,"ln-date:change",{value:"",formatted:"",date:null}));return}if(e._lastISO){const h=g(e._lastISO);if(h){const k=e.dom.getAttribute(r)||"",D=x(e.dom),O=E(h,k,D);if(n===O)return}}const l=w(n);if(l){const h=l.getFullYear(),k=String(l.getMonth()+1).padStart(2,"0"),D=String(l.getDate()).padStart(2,"0"),O=h+"-"+k+"-"+D;e._setHiddenRaw(O),c.set.call(e._picker,O),e._displayFormatted(l),e._lastISO=O,_(e.dom,"ln-date:change",{value:O,formatted:e.dom.value,date:l})}else if(e._lastISO){const h=g(e._lastISO);h&&e._displayFormatted(h)}else e.dom.value=""},t.addEventListener("blur",this._onBlur),this._onBtnClick=function(){e._openPicker()},f.addEventListener("click",this._onBtnClick),a&&a!==""){const n=g(a);n&&(this._setHiddenRaw(a),c.set.call(o,a),this._displayFormatted(n),this._lastISO=a,_(t,"ln-date:change",{value:a,formatted:t.value,date:n}),t.dispatchEvent(new Event("change",{bubbles:!0})))}return this}function g(t){if(!t||typeof t!="string")return null;const e=t.split("T"),a=e[0].split("-");if(a.length<3)return null;const s=parseInt(a[0],10),u=parseInt(a[1],10)-1,d=parseInt(a[2],10);if(isNaN(s)||isNaN(u)||isNaN(d))return null;let o=0,f=0;if(e[1]){const l=e[1].split(":");o=parseInt(l[0],10)||0,f=parseInt(l[1],10)||0}const n=new Date(s,u,d,o,f);return n.getFullYear()!==s||n.getMonth()!==u||n.getDate()!==d?null:n}function w(t){if(!t||typeof t!="string"||(t=t.trim(),t.length<6))return null;let e,a;if(t.indexOf(".")!==-1)e=".",a=t.split(".");else if(t.indexOf("/")!==-1)e="/",a=t.split("/");else if(t.indexOf("-")!==-1)e="-",a=t.split("-");else return null;if(a.length!==3)return null;const s=[];for(let n=0;n<3;n++){const l=parseInt(a[n],10);if(isNaN(l))return null;s.push(l)}let u,d,o;e==="."?(u=s[0],d=s[1],o=s[2]):e==="/"?(d=s[0],u=s[1],o=s[2]):a[0].length===4?(o=s[0],d=s[1],u=s[2]):(u=s[0],d=s[1],o=s[2]),o<100&&(o+=o<50?2e3:1900);const f=new Date(o,d-1,u);return f.getFullYear()!==o||f.getMonth()!==d-1||f.getDate()!==u?null:f}m.prototype._openPicker=function(){if(typeof this._picker.showPicker=="function")try{this._picker.showPicker()}catch{this._picker.click()}else this._picker.click()},m.prototype._setHiddenRaw=function(t){c.set.call(this._hidden,t)},m.prototype._displayFormatted=function(t){const e=this.dom.getAttribute(r)||"",a=x(this.dom);this._isFormatting=!0,this.dom.value=E(t,e,a),this._isFormatting=!1},Object.defineProperty(m.prototype,"value",{get:function(){return c.get.call(this._hidden)},set:function(t){if(!t||t===""){this._setHiddenRaw(""),c.set.call(this._picker,""),this.dom.value="",this._lastISO="";return}const e=g(t);e&&(this._setHiddenRaw(t),c.set.call(this._picker,t),this._displayFormatted(e),this._lastISO=t,_(this.dom,"ln-date:change",{value:t,formatted:this.dom.value,date:e}))}}),Object.defineProperty(m.prototype,"date",{get:function(){const t=this.value;return t?g(t):null},set:function(t){if(!t||!(t instanceof Date)||isNaN(t.getTime())){this.value="";return}const e=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0");this.value=e+"-"+a+"-"+s}}),Object.defineProperty(m.prototype,"formatted",{get:function(){return this.dom.value}}),m.prototype.destroy=function(){if(!this.dom[i])return;this._picker.removeEventListener("change",this._onPickerChange),this.dom.removeEventListener("blur",this._onBlur),this._btn.removeEventListener("click",this._onBtnClick),this.dom.name=this._hidden.name,this.dom.type="date";const t=this.value;this._hidden.remove(),this._picker.remove(),this._btn.remove(),this._wrapper&&this._wrapper.parentNode&&(this._wrapper.parentNode.insertBefore(this.dom,this._wrapper),this._wrapper.remove()),t&&(this.dom.value=t),_(this.dom,"ln-date:destroyed",{target:this.dom}),delete this.dom[i]};function y(){new MutationObserver(function(){const t=document.querySelectorAll("["+r+"]");for(let e=0;e<t.length;e++){const a=t[e][i];if(a&&a.value){const s=g(a.value);s&&a._displayFormatted(s)}}}).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})}L(r,i,m,"ln-date"),y()})()})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
1
|
+
import { dispatch, getLocale, registerComponent, interceptValueProperty } from '../../ln-core';
|
|
2
2
|
|
|
3
3
|
(function () {
|
|
4
4
|
const DOM_SELECTOR = 'data-ln-date';
|
|
@@ -84,6 +84,9 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
84
84
|
return this;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
if (dom[DOM_ATTRIBUTE]) return dom[DOM_ATTRIBUTE];
|
|
88
|
+
dom[DOM_ATTRIBUTE] = this;
|
|
89
|
+
|
|
87
90
|
this.dom = dom;
|
|
88
91
|
const self = this;
|
|
89
92
|
|
|
@@ -91,6 +94,13 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
91
94
|
const initialValue = dom.value; // ISO string (YYYY-MM-DD) or empty
|
|
92
95
|
const name = dom.name;
|
|
93
96
|
|
|
97
|
+
// ── Wrap field: replace dom with <span data-ln-date-field> and move dom inside ──
|
|
98
|
+
const wrapper = document.createElement('span');
|
|
99
|
+
wrapper.setAttribute('data-ln-date-field', '');
|
|
100
|
+
dom.parentNode.insertBefore(wrapper, dom);
|
|
101
|
+
wrapper.appendChild(dom);
|
|
102
|
+
this._wrapper = wrapper;
|
|
103
|
+
|
|
94
104
|
// ── Create hidden input for form submission ─────────
|
|
95
105
|
const hidden = document.createElement('input');
|
|
96
106
|
hidden.type = 'hidden';
|
|
@@ -131,10 +141,90 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
131
141
|
if (date) {
|
|
132
142
|
self._displayFormatted(date);
|
|
133
143
|
_inputValueDesc.set.call(picker, val);
|
|
144
|
+
self._lastISO = val;
|
|
145
|
+
dispatch(self.dom, 'ln-date:change', {
|
|
146
|
+
value: val,
|
|
147
|
+
formatted: self.dom.value,
|
|
148
|
+
date: date
|
|
149
|
+
});
|
|
150
|
+
self.dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
134
151
|
}
|
|
135
152
|
} else if (val === '') {
|
|
136
153
|
self.dom.value = '';
|
|
137
154
|
_inputValueDesc.set.call(picker, '');
|
|
155
|
+
self._lastISO = '';
|
|
156
|
+
dispatch(self.dom, 'ln-date:change', {
|
|
157
|
+
value: '',
|
|
158
|
+
formatted: '',
|
|
159
|
+
date: null
|
|
160
|
+
});
|
|
161
|
+
self.dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ── Intercept programmatic value sets on visible input (2-way binding) ──
|
|
167
|
+
interceptValueProperty(dom, _inputValueDesc, {
|
|
168
|
+
get: function () {
|
|
169
|
+
return _inputValueDesc.get.call(dom);
|
|
170
|
+
},
|
|
171
|
+
set: function (val, originalSet) {
|
|
172
|
+
if (self._isFormatting) {
|
|
173
|
+
originalSet(val);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!val || val === '') {
|
|
177
|
+
originalSet('');
|
|
178
|
+
self._setHiddenRaw('');
|
|
179
|
+
_inputValueDesc.set.call(self._picker, '');
|
|
180
|
+
self._lastISO = '';
|
|
181
|
+
dispatch(dom, 'ln-date:change', {
|
|
182
|
+
value: '',
|
|
183
|
+
formatted: '',
|
|
184
|
+
date: null
|
|
185
|
+
});
|
|
186
|
+
dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Programmatic value could be an ISO string (YYYY-MM-DD) or a formatted date string
|
|
191
|
+
let date = _parseISO(val);
|
|
192
|
+
if (!date) {
|
|
193
|
+
date = _parseTyped(val);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (date) {
|
|
197
|
+
const y = date.getFullYear();
|
|
198
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
199
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
200
|
+
const iso = y + '-' + m + '-' + d;
|
|
201
|
+
|
|
202
|
+
self._setHiddenRaw(iso);
|
|
203
|
+
_inputValueDesc.set.call(self._picker, iso);
|
|
204
|
+
self._lastISO = iso;
|
|
205
|
+
|
|
206
|
+
const format = dom.getAttribute(DOM_SELECTOR) || '';
|
|
207
|
+
const locale = getLocale(dom);
|
|
208
|
+
const formatted = _formatDate(date, format, locale);
|
|
209
|
+
originalSet(formatted);
|
|
210
|
+
|
|
211
|
+
dispatch(dom, 'ln-date:change', {
|
|
212
|
+
value: iso,
|
|
213
|
+
formatted: formatted,
|
|
214
|
+
date: date
|
|
215
|
+
});
|
|
216
|
+
dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
217
|
+
} else {
|
|
218
|
+
originalSet(String(val));
|
|
219
|
+
self._setHiddenRaw('');
|
|
220
|
+
_inputValueDesc.set.call(self._picker, '');
|
|
221
|
+
self._lastISO = '';
|
|
222
|
+
dispatch(dom, 'ln-date:change', {
|
|
223
|
+
value: '',
|
|
224
|
+
formatted: String(val),
|
|
225
|
+
date: null
|
|
226
|
+
});
|
|
227
|
+
dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
138
228
|
}
|
|
139
229
|
}
|
|
140
230
|
});
|
|
@@ -238,6 +328,12 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
238
328
|
_inputValueDesc.set.call(picker, initialValue);
|
|
239
329
|
this._displayFormatted(date);
|
|
240
330
|
this._lastISO = initialValue;
|
|
331
|
+
dispatch(dom, 'ln-date:change', {
|
|
332
|
+
value: initialValue,
|
|
333
|
+
formatted: dom.value,
|
|
334
|
+
date: date
|
|
335
|
+
});
|
|
336
|
+
dom.dispatchEvent(new Event('change', { bubbles: true }));
|
|
241
337
|
}
|
|
242
338
|
}
|
|
243
339
|
|
|
@@ -346,7 +442,9 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
346
442
|
_component.prototype._displayFormatted = function (date) {
|
|
347
443
|
const format = this.dom.getAttribute(DOM_SELECTOR) || '';
|
|
348
444
|
const locale = getLocale(this.dom);
|
|
445
|
+
this._isFormatting = true;
|
|
349
446
|
this.dom.value = _formatDate(date, format, locale);
|
|
447
|
+
this._isFormatting = false;
|
|
350
448
|
};
|
|
351
449
|
|
|
352
450
|
// ─── Public API ───────────────────────────────────────────
|
|
@@ -414,6 +512,11 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
414
512
|
this._hidden.remove();
|
|
415
513
|
this._picker.remove();
|
|
416
514
|
this._btn.remove();
|
|
515
|
+
// Unwrap: move dom back out and drop the wrapper
|
|
516
|
+
if (this._wrapper && this._wrapper.parentNode) {
|
|
517
|
+
this._wrapper.parentNode.insertBefore(this.dom, this._wrapper);
|
|
518
|
+
this._wrapper.remove();
|
|
519
|
+
}
|
|
417
520
|
// Restore value
|
|
418
521
|
if (isoVal) this.dom.value = isoVal;
|
|
419
522
|
dispatch(this.dom, 'ln-date:destroyed', { target: this.dom });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function v(t,
|
|
1
|
+
(function(){"use strict";function v(t,e,n){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n||{}}))}function k(t,e){if(!document.body){document.addEventListener("DOMContentLoaded",function(){k(t,e)}),console.warn("["+e+'] Script loaded before <body> — add "defer" to your <script> tag');return}t()}function L(t,e,n,i){if(t.nodeType!==1)return;const s=e.indexOf("[")!==-1||e.indexOf(".")!==-1||e.indexOf("#")!==-1?e:"["+e+"]",d=Array.from(t.querySelectorAll(s));t.matches&&t.matches(s)&&d.push(t);for(const r of d)r[n]||(r[n]=new i(r))}function O(t,e,n,i,o={}){const s=o.extraAttributes||[],d=o.onAttributeChange||null,r=o.onInit||null;function f(y){const _=y||document.body;L(_,t,e,n),r&&r(_)}return k(function(){const y=new MutationObserver(function(h){for(let m=0;m<h.length;m++){const u=h[m];if(u.type==="childList"){for(let c=0;c<u.addedNodes.length;c++){const p=u.addedNodes[c];p.nodeType===1&&(L(p,t,e,n),r&&r(p))}for(let c=0;c<u.removedNodes.length;c++){const p=u.removedNodes[c];if(p.nodeType===1){const b=t.indexOf("[")!==-1||t.indexOf(".")!==-1||t.indexOf("#")!==-1?t:"["+t+"]",a=Array.from(p.querySelectorAll(b));p.matches&&p.matches(b)&&a.push(p);for(let l=0;l<a.length;l++){const g=a[l][e];g&&typeof g.destroy=="function"&&g.destroy()}}}}else u.type==="attributes"&&(d&&u.target[e]?d(u.target,u.attributeName):(L(u.target,t,e,n),r&&r(u.target)))}});let _=[];if(t.indexOf("[")!==-1){const h=/\[([\w-]+)/g;let m;for(;(m=h.exec(t))!==null;)_.push(m[1])}else _.push(t);y.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:_.concat(s)})},i),window[e]=f,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){f(document.body)}):f(document.body),f}const x={};function R(t,e){x[t]=e}function A(t){return x[t]||{ingress:e=>e,egress:e=>e}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=R,window.lnCore.getDataMapper=A);function T(t,e,n,i){const o=typeof i=="number"?i:4,s=window.innerWidth,d=window.innerHeight,r=e.width,f=e.height,y=n.split("-"),_=y[0],h=y[1]==="start"||y[1]==="end"?y[1]:"center",m={top:["top","bottom","right","left"],bottom:["bottom","top","right","left"],left:["left","right","top","bottom"],right:["right","left","top","bottom"]},u=m[_]||m.bottom;function c(l){return l==="top"||l==="bottom"?h==="start"?t.left:h==="end"?t.right-r:t.left+(t.width-r)/2:h==="start"?t.top:h==="end"?t.bottom-f:t.top+(t.height-f)/2}function p(l){let g,C,w=!0;return l==="top"?(g=t.top-o-f,C=c(l),g<0&&(w=!1)):l==="bottom"?(g=t.bottom+o,C=c(l),g+f>d&&(w=!1)):l==="left"?(g=c(l),C=t.left-o-r,C<0&&(w=!1)):(g=c(l),C=t.right+o,C+r>s&&(w=!1)),{top:g,left:C,side:l,fits:w}}let E=null;for(let l=0;l<u.length;l++){const g=p(u[l]);if(g.fits){E=g;break}}E||(E=p(u[0]));let b=E.top,a=E.left;return r>=s?a=0:(a<0&&(a=0),a+r>s&&(a=s-r)),f>=d?b=0:(b<0&&(b=0),b+f>d&&(b=d-f)),{top:b,left:a,placement:E.side}}function S(t){if(!t||t.parentNode===document.body)return function(){};const e=t.parentNode,n=document.createComment("ln-teleport");return e.insertBefore(n,t),document.body.appendChild(t),function(){n.parentNode&&(n.parentNode.insertBefore(t,n),n.parentNode.removeChild(n))}}function D(t){if(!t)return{width:0,height:0};const e=t.style,n=e.visibility,i=e.display,o=e.position;e.visibility="hidden",e.display="block",e.position="fixed";const s=t.offsetWidth,d=t.offsetHeight;return e.visibility=n,e.display=i,e.position=o,{width:s,height:d}}(function(){const t="data-ln-dropdown",e="lnDropdown";if(window[e]!==void 0)return;function n(i){if(this.dom=i,this.toggleEl=i.querySelector("[data-ln-toggle]"),this._teleportRestore=null,this._boundDocClick=null,this._docClickTimeout=null,this._boundScrollReposition=null,this._boundResizeClose=null,this.toggleEl&&(this.toggleEl.setAttribute("data-ln-dropdown-menu",""),this.toggleEl.setAttribute("role","menu")),this.triggerBtn=i.querySelector("[data-ln-toggle-for]"),this.triggerBtn&&(this.triggerBtn.setAttribute("aria-haspopup","menu"),this.triggerBtn.setAttribute("aria-expanded","false")),this.toggleEl)for(const s of this.toggleEl.children)s.setAttribute("role","menuitem");const o=this;return this._onToggleOpen=function(s){s.detail.target===o.toggleEl&&(o.triggerBtn&&o.triggerBtn.setAttribute("aria-expanded","true"),o._teleportRestore=S(o.toggleEl),o.toggleEl.style.position="fixed",o.toggleEl.style.right="auto",o._reposition(),o._addOutsideClickListener(),o._addScrollRepositionListener(),o._addResizeCloseListener(),v(i,"ln-dropdown:open",{target:s.detail.target}))},this._onToggleClose=function(s){s.detail.target===o.toggleEl&&(o.triggerBtn&&o.triggerBtn.setAttribute("aria-expanded","false"),o._removeOutsideClickListener(),o._removeScrollRepositionListener(),o._removeResizeCloseListener(),o.toggleEl.style.position="",o.toggleEl.style.top="",o.toggleEl.style.left="",o.toggleEl.style.right="",o.toggleEl.style.transform="",o.toggleEl.style.margin="",o._teleportRestore&&(o._teleportRestore(),o._teleportRestore=null),v(i,"ln-dropdown:close",{target:s.detail.target}))},this.toggleEl&&(this.toggleEl.addEventListener("ln-toggle:open",this._onToggleOpen),this.toggleEl.addEventListener("ln-toggle:close",this._onToggleClose)),this}n.prototype._reposition=function(){if(!this.triggerBtn||!this.toggleEl)return;const i=this.triggerBtn.getBoundingClientRect(),o=D(this.toggleEl),s=parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--size-xs"))*16||4,d=T(i,o,"bottom-end",s);this.toggleEl.style.top=d.top+"px",this.toggleEl.style.left=d.left+"px"},n.prototype._addOutsideClickListener=function(){if(this._boundDocClick)return;const i=this;this._boundDocClick=function(o){i.dom.contains(o.target)||i.toggleEl&&i.toggleEl.contains(o.target)||i.toggleEl&&i.toggleEl.getAttribute("data-ln-toggle")==="open"&&i.toggleEl.setAttribute("data-ln-toggle","close")},i._docClickTimeout=setTimeout(function(){i._docClickTimeout=null,document.addEventListener("click",i._boundDocClick)},0)},n.prototype._removeOutsideClickListener=function(){this._docClickTimeout&&(clearTimeout(this._docClickTimeout),this._docClickTimeout=null),this._boundDocClick&&(document.removeEventListener("click",this._boundDocClick),this._boundDocClick=null)},n.prototype._addScrollRepositionListener=function(){const i=this;this._boundScrollReposition=function(){i._reposition()},window.addEventListener("scroll",this._boundScrollReposition,{passive:!0,capture:!0})},n.prototype._removeScrollRepositionListener=function(){this._boundScrollReposition&&(window.removeEventListener("scroll",this._boundScrollReposition,{capture:!0}),this._boundScrollReposition=null)},n.prototype._addResizeCloseListener=function(){const i=this;this._boundResizeClose=function(){i.toggleEl&&i.toggleEl.getAttribute("data-ln-toggle")==="open"&&i.toggleEl.setAttribute("data-ln-toggle","close")},window.addEventListener("resize",this._boundResizeClose)},n.prototype._removeResizeCloseListener=function(){this._boundResizeClose&&(window.removeEventListener("resize",this._boundResizeClose),this._boundResizeClose=null)},n.prototype.destroy=function(){this.dom[e]&&(this._removeOutsideClickListener(),this._removeScrollRepositionListener(),this._removeResizeCloseListener(),this._teleportRestore&&(this._teleportRestore(),this._teleportRestore=null),this.toggleEl&&(this.toggleEl.removeEventListener("ln-toggle:open",this._onToggleOpen),this.toggleEl.removeEventListener("ln-toggle:close",this._onToggleClose)),v(this.dom,"ln-dropdown:destroyed",{target:this.dom}),delete this.dom[e])},O(t,e,n,"ln-dropdown")})()})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
1
|
+
(function(){"use strict";function R(r,n,u){r.dispatchEvent(new CustomEvent(n,{bubbles:!0,detail:u||{}}))}function D(r,n){if(!r||!n)return r;const u=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(;u.nextNode();){const c=u.currentNode;c.textContent.indexOf("{{")!==-1&&(c.textContent=c.textContent.replace(/\{\{\s*(\w+)\s*\}\}/g,function(m,h){return n[h]!==void 0?n[h]:""}))}return r}function B(r,n){if(!document.body){document.addEventListener("DOMContentLoaded",function(){B(r,n)}),console.warn("["+n+'] Script loaded before <body> — add "defer" to your <script> tag');return}r()}function S(r,n,u,c){if(r.nodeType!==1)return;const h=n.indexOf("[")!==-1||n.indexOf(".")!==-1||n.indexOf("#")!==-1?n:"["+n+"]",T=Array.from(r.querySelectorAll(h));r.matches&&r.matches(h)&&T.push(r);for(const y of T)y[u]||(y[u]=new c(y))}function F(r,n,u,c,m={}){const h=m.extraAttributes||[],T=m.onAttributeChange||null,y=m.onInit||null;function A(b){const _=b||document.body;S(_,r,n,u),y&&y(_)}return B(function(){const b=new MutationObserver(function(I){for(let w=0;w<I.length;w++){const a=I[w];if(a.type==="childList"){for(let t=0;t<a.addedNodes.length;t++){const e=a.addedNodes[t];e.nodeType===1&&(S(e,r,n,u),y&&y(e))}for(let t=0;t<a.removedNodes.length;t++){const e=a.removedNodes[t];if(e.nodeType===1){const s=r.indexOf("[")!==-1||r.indexOf(".")!==-1||r.indexOf("#")!==-1?r:"["+r+"]",o=Array.from(e.querySelectorAll(s));e.matches&&e.matches(s)&&o.push(e);for(let l=0;l<o.length;l++){const d=o[l][n];d&&typeof d.destroy=="function"&&d.destroy()}}}}else a.type==="attributes"&&(T&&a.target[n]?T(a.target,a.attributeName):(S(a.target,r,n,u),y&&y(a.target)))}});let _=[];if(r.indexOf("[")!==-1){const I=/\[([\w-]+)/g;let w;for(;(w=I.exec(r))!==null;)_.push(w[1])}else _.push(r);b.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:_.concat(h)})},c),window[n]=A,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){A(document.body)}):A(document.body),A}const L={};function K(r,n){L[r]=n}function j(r){return L[r]||{ingress:n=>n,egress:n=>n}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=K,window.lnCore.getDataMapper=j);function H(r,n){let u=!1;return function(){u||(u=!0,queueMicrotask(function(){u=!1,r(),n&&n()}))}}const W="ln:";function J(){return location.pathname.replace(/\/+$/,"").toLowerCase()||"/"}function q(r,n){const u=n.getAttribute("data-ln-persist"),c=u!==null&&u!==""?u:n.id;return c?W+r+":"+J()+":"+c:(console.warn('[ln-persist] Element requires id or data-ln-persist="key"',n),null)}function U(r,n){const u=q(r,n);if(!u)return null;try{const c=localStorage.getItem(u);return c!==null?JSON.parse(c):null}catch{return null}}function N(r,n,u){const c=q(r,n);if(c)try{localStorage.setItem(c,JSON.stringify(u))}catch{}}(function(){const r="data-ln-filter",n="lnFilter",u="data-ln-filter-initialized",c="data-ln-filter-key",m="data-ln-filter-value",h="data-ln-filter-hide",T="data-ln-filter-reset",y="data-ln-filter-col",A=new WeakMap;if(window[n]!==void 0)return;function b(t){return t.hasAttribute(T)||t.getAttribute(m)===""}function _(t){let e=null;const i=[];for(let s=0;s<t.inputs.length;s++){const o=t.inputs[s];if(o.checked&&!b(o)){e===null&&(e=o.getAttribute(c));const l=o.getAttribute(m);l&&i.push(l)}}return{key:e,values:i}}function I(t,e){if(t.length!==e.length)return!0;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!0;return!1}function w(t){const e=t.dom,i=t.colIndex,s=e.querySelector("template");if(!s||i===null)return;const o=document.getElementById(t.targetId);if(!o)return;const l=o.tagName==="TABLE"?o:o.querySelector("table");if(!l||o.hasAttribute("data-ln-table"))return;const d={},f=[],x=l.tBodies;for(let g=0;g<x.length;g++){const p=x[g].rows;for(let v=0;v<p.length;v++){const O=p[v].cells[i],E=O?O.textContent.trim():"";E&&!d[E]&&(d[E]=!0,f.push(E))}}f.sort(function(g,p){return g.localeCompare(p)});const k=e.querySelector("["+c+"]"),C=k?k.getAttribute(c):e.getAttribute("data-ln-filter-key")||"col"+i;for(let g=0;g<f.length;g++){const p=s.content.cloneNode(!0),v=p.querySelector("input");v&&(v.setAttribute(c,C),v.setAttribute(m,f[g]),D(p,{text:f[g]}),e.appendChild(p))}}function a(t){if(t.hasAttribute(u))return this;this.dom=t,this.targetId=t.getAttribute(r);const e=t.getAttribute(y);this.colIndex=e!==null?parseInt(e,10):null,w(this),this.inputs=Array.from(t.querySelectorAll("["+c+"]")),this._filterKey=this.inputs.length>0?this.inputs[0].getAttribute(c):null,this._lastSnapshot=null;const i=this,s=H(function(){i._render()},function(){i._afterRender()});this._queueRender=s,this._attachHandlers();let o=!1;if(t.hasAttribute("data-ln-persist")){const l=U("filter",t);if(l&&l.key&&Array.isArray(l.values)&&l.values.length>0){for(let d=0;d<this.inputs.length;d++){const f=this.inputs[d];b(f)?f.checked=!1:f.getAttribute(c)===l.key&&l.values.indexOf(f.getAttribute(m))!==-1?f.checked=!0:f.checked=!1}s(),o=!0}}if(!o){for(let l=0;l<this.inputs.length;l++)if(this.inputs[l].checked&&!b(this.inputs[l])){s();break}}return t.setAttribute(u,""),this}a.prototype._attachHandlers=function(){const t=this;this.inputs.forEach(function(e){e[n+"Bound"]||(e[n+"Bound"]=!0,e._lnFilterChange=function(){if(b(e)){for(let i=0;i<t.inputs.length;i++)b(t.inputs[i])||(t.inputs[i].checked=!1);e.checked=!0,t._queueRender();return}if(e.checked)for(let i=0;i<t.inputs.length;i++)b(t.inputs[i])&&(t.inputs[i].checked=!1);else{let i=!1;for(let s=0;s<t.inputs.length;s++)if(!b(t.inputs[s])&&t.inputs[s].checked){i=!0;break}if(!i)for(let s=0;s<t.inputs.length;s++)b(t.inputs[s])&&(t.inputs[s].checked=!0)}t._queueRender()},e.addEventListener("change",e._lnFilterChange))})},a.prototype._render=function(){const t=this,e=_(this),i=e.key===null||e.values.length===0,s=[];for(let o=0;o<e.values.length;o++)s.push(e.values[o].toLowerCase());if(t.colIndex!==null)t._filterTableRows(e);else{const o=document.getElementById(t.targetId);if(!o)return;const l=o.children;for(let d=0;d<l.length;d++){const f=l[d];if(i){f.removeAttribute(h);continue}const x=f.getAttribute("data-"+e.key);f.removeAttribute(h),x!==null&&s.indexOf(x.toLowerCase())===-1&&f.setAttribute(h,"true")}}},a.prototype._afterRender=function(){const t=_(this),e=this._lastSnapshot;if(!e||e.key!==t.key||I(e.values,t.values)){this._dispatchOnBoth("ln-filter:changed",{key:t.key,values:t.values.slice()});const s=e&&e.values.length>0,o=t.values.length===0;s&&o&&this._dispatchOnBoth("ln-filter:reset",{}),this._lastSnapshot={key:t.key,values:t.values.slice()}}this.dom.hasAttribute("data-ln-persist")&&(t.key&&t.values.length>0?N("filter",this.dom,{key:t.key,values:t.values.slice()}):N("filter",this.dom,null))},a.prototype._dispatchOnBoth=function(t,e){R(this.dom,t,e);const i=document.getElementById(this.targetId);i&&i!==this.dom&&R(i,t,e)},a.prototype._filterTableRows=function(t){const e=document.getElementById(this.targetId);if(!e)return;const i=e.tagName==="TABLE"?e:e.querySelector("table");if(!i||e.hasAttribute("data-ln-table"))return;const s=t.key||this._filterKey,o=t.values;A.has(i)||A.set(i,{});const l=A.get(i);if(s&&o.length>0){const k=[];for(let C=0;C<o.length;C++)k.push(o[C].toLowerCase());l[s]={col:this.colIndex,values:k}}else s&&delete l[s];const d=Object.keys(l),f=d.length>0,x=i.tBodies;for(let k=0;k<x.length;k++){const C=x[k].rows;for(let g=0;g<C.length;g++){const p=C[g];if(!f){p.removeAttribute(h);continue}let v=!0;for(let O=0;O<d.length;O++){const E=l[d[O]],M=p.cells[E.col],V=M?M.textContent.trim().toLowerCase():"";if(E.values.indexOf(V)===-1){v=!1;break}}v?p.removeAttribute(h):p.setAttribute(h,"true")}}},a.prototype.destroy=function(){if(this.dom[n]){if(this.colIndex!==null){const t=document.getElementById(this.targetId);if(t){const e=t.tagName==="TABLE"?t:t.querySelector("table");if(e&&A.has(e)){const i=A.get(e),s=this._filterKey;s&&i[s]&&delete i[s],Object.keys(i).length===0&&A.delete(e)}}}this.inputs.forEach(function(t){t._lnFilterChange&&(t.removeEventListener("change",t._lnFilterChange),delete t._lnFilterChange),delete t[n+"Bound"]}),this.dom.removeAttribute(u),delete this.dom[n]}},F(r,n,a,"ln-filter")})()})();
|
package/js/ln-form/ln-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
1
|
+
(function(){"use strict";function y(s,t,u){s.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:u||{}}))}function E(s,t){if(!document.body){document.addEventListener("DOMContentLoaded",function(){E(s,t)}),console.warn("["+t+'] Script loaded before <body> — add "defer" to your <script> tag');return}s()}function v(s,t,u,a){if(s.nodeType!==1)return;const o=t.indexOf("[")!==-1||t.indexOf(".")!==-1||t.indexOf("#")!==-1?t:"["+t+"]",r=Array.from(s.querySelectorAll(o));s.matches&&s.matches(o)&&r.push(s);for(const e of r)e[u]||(e[u]=new a(e))}function T(s){const t={},u=s.elements;for(let a=0;a<u.length;a++){const i=u[a];if(!(!i.name||i.disabled||i.type==="file"||i.type==="submit"||i.type==="button"))if(i.type==="checkbox")t[i.name]||(t[i.name]=[]),i.checked&&t[i.name].push(i.value);else if(i.type==="radio")i.checked&&(t[i.name]=i.value);else if(i.type==="select-multiple"){t[i.name]=[];for(let o=0;o<i.options.length;o++)i.options[o].selected&&t[i.name].push(i.options[o].value)}else t[i.name]=i.value}return t}function S(s,t){const u=s.elements,a=[];for(let i=0;i<u.length;i++){const o=u[i];if(!o.name||!(o.name in t)||o.type==="file"||o.type==="submit"||o.type==="button")continue;const r=t[o.name];if(o.type==="checkbox")o.checked=Array.isArray(r)?r.indexOf(o.value)!==-1:!!r,a.push(o);else if(o.type==="radio")o.checked=o.value===String(r),a.push(o);else if(o.type==="select-multiple"){if(Array.isArray(r))for(let e=0;e<o.options.length;e++)o.options[e].selected=r.indexOf(o.options[e].value)!==-1;a.push(o)}else o.value=r,a.push(o)}return a}function w(s,t,u,a,i={}){const o=i.extraAttributes||[],r=i.onAttributeChange||null,e=i.onInit||null;function n(l){const d=l||document.body;v(d,s,t,u),e&&e(d)}return E(function(){const l=new MutationObserver(function(f){for(let h=0;h<f.length;h++){const c=f[h];if(c.type==="childList"){for(let p=0;p<c.addedNodes.length;p++){const m=c.addedNodes[p];m.nodeType===1&&(v(m,s,t,u),e&&e(m))}for(let p=0;p<c.removedNodes.length;p++){const m=c.removedNodes[p];if(m.nodeType===1){const L=s.indexOf("[")!==-1||s.indexOf(".")!==-1||s.indexOf("#")!==-1?s:"["+s+"]",b=Array.from(m.querySelectorAll(L));m.matches&&m.matches(L)&&b.push(m);for(let g=0;g<b.length;g++){const _=b[g][t];_&&typeof _.destroy=="function"&&_.destroy()}}}}else c.type==="attributes"&&(r&&c.target[t]?r(c.target,c.attributeName):(v(c.target,s,t,u),e&&e(c.target)))}});let d=[];if(s.indexOf("[")!==-1){const f=/\[([\w-]+)/g;let h;for(;(h=f.exec(s))!==null;)d.push(h[1])}else d.push(s);l.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:d.concat(o)})},a),window[t]=n,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){n(document.body)}):n(document.body),n}const A={};function x(s,t){A[s]=t}function C(s){return A[s]||{ingress:t=>t,egress:t=>t}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=x,window.lnCore.getDataMapper=C),(function(){const s="data-ln-form",t="lnForm",u="data-ln-form-auto",a="data-ln-form-debounce",i="data-ln-validate",o="lnValidate";if(window[t]!==void 0)return;function r(e){this.dom=e,this._debounceTimer=null;const n=this;if(this._onValid=function(){n._updateSubmitButton()},this._onInvalid=function(){n._updateSubmitButton()},this._onSubmit=function(l){l.preventDefault(),n.submit()},this._onFill=function(l){l.detail&&n.fill(l.detail)},this._onFormReset=function(){n.reset()},this._onNativeReset=function(){setTimeout(function(){n._resetValidation()},0)},e.addEventListener("ln-validate:valid",this._onValid),e.addEventListener("ln-validate:invalid",this._onInvalid),e.addEventListener("submit",this._onSubmit),e.addEventListener("ln-form:fill",this._onFill),e.addEventListener("ln-form:reset",this._onFormReset),e.addEventListener("reset",this._onNativeReset),this._onAutoInput=null,e.hasAttribute(u)){const l=parseInt(e.getAttribute(a))||0;this._onAutoInput=function(){l>0?(clearTimeout(n._debounceTimer),n._debounceTimer=setTimeout(function(){n.submit()},l)):n.submit()},e.addEventListener("input",this._onAutoInput),e.addEventListener("change",this._onAutoInput)}return this._updateSubmitButton(),this}r.prototype._updateSubmitButton=function(){const e=this.dom.querySelectorAll('button[type="submit"], input[type="submit"]');if(!e.length)return;const n=this.dom.querySelectorAll("["+i+"]");let l=!1;if(n.length>0){let d=!1,f=!1;for(let h=0;h<n.length;h++){const c=n[h][o];c&&c._touched&&(d=!0),n[h].checkValidity()||(f=!0)}l=f||!d}for(let d=0;d<e.length;d++)e[d].disabled=l},r.prototype.fill=function(e){const n=S(this.dom,e);for(let l=0;l<n.length;l++){const d=n[l],f=d.tagName==="SELECT"||d.type==="checkbox"||d.type==="radio";d.dispatchEvent(new Event(f?"change":"input",{bubbles:!0}))}},r.prototype.submit=function(){const e=this.dom.querySelectorAll("["+i+"]");let n=!0;for(let d=0;d<e.length;d++){const f=e[d][o];f&&(f.validate()||(n=!1))}if(!n)return;const l=T(this.dom);y(this.dom,"ln-form:submit",{data:l})},r.prototype.reset=function(){this.dom.reset();const e=this.dom.querySelectorAll("input, textarea, select");for(let n=0;n<e.length;n++){const l=e[n],d=l.tagName==="SELECT"||l.type==="checkbox"||l.type==="radio";l.dispatchEvent(new Event(d?"change":"input",{bubbles:!0}))}this._resetValidation(),y(this.dom,"ln-form:reset-complete",{target:this.dom})},r.prototype._resetValidation=function(){const e=this.dom.querySelectorAll("["+i+"]");for(let n=0;n<e.length;n++){const l=e[n][o];l&&l.reset()}this._updateSubmitButton()},Object.defineProperty(r.prototype,"isValid",{get:function(){const e=this.dom.querySelectorAll("["+i+"]");for(let n=0;n<e.length;n++)if(!e[n].checkValidity())return!1;return!0}}),r.prototype.destroy=function(){this.dom[t]&&(this.dom.removeEventListener("ln-validate:valid",this._onValid),this.dom.removeEventListener("ln-validate:invalid",this._onInvalid),this.dom.removeEventListener("submit",this._onSubmit),this.dom.removeEventListener("ln-form:fill",this._onFill),this.dom.removeEventListener("ln-form:reset",this._onFormReset),this.dom.removeEventListener("reset",this._onNativeReset),this._onAutoInput&&(this.dom.removeEventListener("input",this._onAutoInput),this.dom.removeEventListener("change",this._onAutoInput)),clearTimeout(this._debounceTimer),y(this.dom,"ln-form:destroyed",{target:this.dom}),delete this.dom[t])},w(s,t,r,"ln-form")})()})();
|
package/js/ln-modal/ln-modal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function h(
|
|
1
|
+
(function(){"use strict";function h(e,t,c){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:c||{}}))}function _(e,t,c){const m=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:c||{}});return e.dispatchEvent(m),m}function C(e,t){if(!document.body){document.addEventListener("DOMContentLoaded",function(){C(e,t)}),console.warn("["+t+'] Script loaded before <body> — add "defer" to your <script> tag');return}e()}function g(e,t,c,m){if(e.nodeType!==1)return;const b=t.indexOf("[")!==-1||t.indexOf(".")!==-1||t.indexOf("#")!==-1?t:"["+t+"]",n=Array.from(e.querySelectorAll(b));e.matches&&e.matches(b)&&n.push(e);for(const o of n)o[c]||(o[c]=new m(o))}function y(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)}function x(e,t,c,m,p={}){const b=p.extraAttributes||[],n=p.onAttributeChange||null,o=p.onInit||null;function r(u){const i=u||document.body;g(i,e,t,c),o&&o(i)}return C(function(){const u=new MutationObserver(function(a){for(let s=0;s<a.length;s++){const d=a[s];if(d.type==="childList"){for(let f=0;f<d.addedNodes.length;f++){const l=d.addedNodes[f];l.nodeType===1&&(g(l,e,t,c),o&&o(l))}for(let f=0;f<d.removedNodes.length;f++){const l=d.removedNodes[f];if(l.nodeType===1){const O=e.indexOf("[")!==-1||e.indexOf(".")!==-1||e.indexOf("#")!==-1?e:"["+e+"]",A=Array.from(l.querySelectorAll(O));l.matches&&l.matches(O)&&A.push(l);for(let E=0;E<A.length;E++){const w=A[E][t];w&&typeof w.destroy=="function"&&w.destroy()}}}}else d.type==="attributes"&&(n&&d.target[t]?n(d.target,d.attributeName):(g(d.target,e,t,c),o&&o(d.target)))}});let i=[];if(e.indexOf("[")!==-1){const a=/\[([\w-]+)/g;let s;for(;(s=a.exec(e))!==null;)i.push(s[1])}else i.push(e);u.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:i.concat(b)})},m),window[t]=r,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){r(document.body)}):r(document.body),r}const L={};function T(e,t){L[e]=t}function k(e){return L[e]||{ingress:t=>t,egress:t=>t}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=T,window.lnCore.getDataMapper=k),(function(){const e="data-ln-modal",t="lnModal";if(window[t]!==void 0)return;function c(n){const o=Array.from(n.querySelectorAll("[data-ln-modal-for]"));n.hasAttribute&&n.hasAttribute("data-ln-modal-for")&&o.push(n);for(const r of o){if(r[t+"Trigger"])continue;const u=function(i){if(i.ctrlKey||i.metaKey||i.button===1)return;i.preventDefault();const a=r.getAttribute("data-ln-modal-for"),s=document.getElementById(a);if(!s){console.warn('[ln-modal] No modal found for data-ln-modal-for="'+a+'"');return}if(!s[t])return;const d=s.getAttribute(e);s.setAttribute(e,d==="open"?"close":"open")};r.addEventListener("click",u),r[t+"Trigger"]=u}}function m(n){this.dom=n,this.isOpen=n.getAttribute(e)==="open";const o=this;return this._onEscape=function(r){r.key==="Escape"&&o.dom.setAttribute(e,"close")},this._onFocusTrap=function(r){if(r.key!=="Tab")return;const u=Array.prototype.filter.call(o.dom.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'),y);if(u.length===0)return;const i=u[0],a=u[u.length-1];r.shiftKey?document.activeElement===i&&(r.preventDefault(),a.focus()):document.activeElement===a&&(r.preventDefault(),i.focus())},this._onClose=function(r){r.preventDefault(),o.dom.setAttribute(e,"close")},b(this),this.isOpen&&(this.dom.setAttribute("aria-modal","true"),this.dom.setAttribute("role","dialog"),document.body.classList.add("ln-modal-open"),document.addEventListener("keydown",this._onEscape),document.addEventListener("keydown",this._onFocusTrap)),this}m.prototype.destroy=function(){if(!this.dom[t])return;this.isOpen&&(this.dom.removeAttribute("aria-modal"),document.removeEventListener("keydown",this._onEscape),document.removeEventListener("keydown",this._onFocusTrap),this._returnFocusEl=null,document.querySelector("["+e+'="open"]')||document.body.classList.remove("ln-modal-open"));const n=this.dom.querySelectorAll("[data-ln-modal-close]");for(const r of n)r[t+"Close"]&&(r.removeEventListener("click",r[t+"Close"]),delete r[t+"Close"]);const o=document.querySelectorAll('[data-ln-modal-for="'+this.dom.id+'"]');for(const r of o)r[t+"Trigger"]&&(r.removeEventListener("click",r[t+"Trigger"]),delete r[t+"Trigger"]);h(this.dom,"ln-modal:destroyed",{modalId:this.dom.id,target:this.dom}),delete this.dom[t]};function p(n){const o=n[t];if(!o)return;const u=n.getAttribute(e)==="open";if(u!==o.isOpen)if(u){if(_(n,"ln-modal:before-open",{modalId:n.id,target:n}).defaultPrevented){n.setAttribute(e,"close");return}o.isOpen=!0,n.setAttribute("aria-modal","true"),n.setAttribute("role","dialog"),document.body.classList.add("ln-modal-open"),document.addEventListener("keydown",o._onEscape),document.addEventListener("keydown",o._onFocusTrap);const a=document.activeElement;o._returnFocusEl=a&&a!==document.body?a:null;const s=n.querySelector("[autofocus]");if(s&&y(s))s.focus();else{const d=n.querySelectorAll('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled])'),f=Array.prototype.find.call(d,y);if(f)f.focus();else{const l=n.querySelectorAll("a[href], button:not([disabled])"),v=Array.prototype.find.call(l,y);v&&v.focus()}}h(n,"ln-modal:open",{modalId:n.id,target:n})}else{if(_(n,"ln-modal:before-close",{modalId:n.id,target:n}).defaultPrevented){n.setAttribute(e,"open");return}o.isOpen=!1,n.removeAttribute("aria-modal"),document.removeEventListener("keydown",o._onEscape),document.removeEventListener("keydown",o._onFocusTrap),h(n,"ln-modal:close",{modalId:n.id,target:n}),o._returnFocusEl&&document.contains(o._returnFocusEl)&&typeof o._returnFocusEl.focus=="function"&&o._returnFocusEl.focus(),o._returnFocusEl=null,document.querySelector("["+e+'="open"]')||document.body.classList.remove("ln-modal-open")}}function b(n){const o=n.dom.querySelectorAll("[data-ln-modal-close]");for(const r of o)r[t+"Close"]||(r.addEventListener("click",n._onClose),r[t+"Close"]=n._onClose)}x(e,t,m,"ln-modal",{extraAttributes:["data-ln-modal-for"],onAttributeChange:p,onInit:c})})()})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
1
|
+
(function(){"use strict";function v(s,i,u){s.dispatchEvent(new CustomEvent(i,{bubbles:!0,detail:u||{}}))}function S(s,i){if(!document.body){document.addEventListener("DOMContentLoaded",function(){S(s,i)}),console.warn("["+i+'] Script loaded before <body> — add "defer" to your <script> tag');return}s()}function x(s,i,u,p){if(s.nodeType!==1)return;const y=i.indexOf("[")!==-1||i.indexOf(".")!==-1||i.indexOf("#")!==-1?i:"["+i+"]",m=Array.from(s.querySelectorAll(y));s.matches&&s.matches(y)&&m.push(s);for(const h of m)h[u]||(h[u]=new p(h))}function N(s){const i=s.closest("[lang]");return(i?i.lang:null)||navigator.language}function O(s,i,{get:u,set:p}){Object.defineProperty(s,"value",{get:function(){return u?u.call(this):i.get.call(this)},set:function(g){p?p.call(this,g,y=>i.set.call(this,y)):i.set.call(this,g)},configurable:!0})}function I(s,i,u,p,g={}){const y=g.extraAttributes||[],m=g.onAttributeChange||null,h=g.onInit||null;function t(a){const e=a||document.body;x(e,s,i,u),h&&h(e)}return S(function(){const a=new MutationObserver(function(c){for(let r=0;r<c.length;r++){const n=c[r];if(n.type==="childList"){for(let o=0;o<n.addedNodes.length;o++){const l=n.addedNodes[o];l.nodeType===1&&(x(l,s,i,u),h&&h(l))}for(let o=0;o<n.removedNodes.length;o++){const l=n.removedNodes[o];if(l.nodeType===1){const _=s.indexOf("[")!==-1||s.indexOf(".")!==-1||s.indexOf("#")!==-1?s:"["+s+"]",F=Array.from(l.querySelectorAll(_));l.matches&&l.matches(_)&&F.push(l);for(let b=0;b<F.length;b++){const E=F[b][i];E&&typeof E.destroy=="function"&&E.destroy()}}}}else n.type==="attributes"&&(m&&n.target[i]?m(n.target,n.attributeName):(x(n.target,s,i,u),h&&h(n.target)))}});let e=[];if(s.indexOf("[")!==-1){const c=/\[([\w-]+)/g;let r;for(;(r=c.exec(s))!==null;)e.push(r[1])}else e.push(s);a.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:e.concat(y)})},p),window[i]=t,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){t(document.body)}):t(document.body),t}const A={};function C(s,i){A[s]=i}function L(s){return A[s]||{ingress:i=>i,egress:i=>i}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=C,window.lnCore.getDataMapper=L),(function(){const s="data-ln-number",i="lnNumber";if(window[i]!==void 0)return;const u={},p=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");function g(t){if(!u[t]){const a=new Intl.NumberFormat(t,{useGrouping:!0}),e=a.formatToParts(1234.5);let c="",r=".";for(let n=0;n<e.length;n++)e[n].type==="group"&&(c=e[n].value),e[n].type==="decimal"&&(r=e[n].value);u[t]={fmt:a,groupSep:c,decimalSep:r}}return u[t]}function y(t,a,e){if(e!==null){const c=parseInt(e,10),r=t+"|d"+c;return u[r]||(u[r]=new Intl.NumberFormat(t,{useGrouping:!0,minimumFractionDigits:0,maximumFractionDigits:c})),u[r].format(a)}return g(t).fmt.format(a)}function m(t){if(t.tagName!=="INPUT")return console.warn("[ln-number] Can only be applied to <input>, got:",t.tagName),this;if(t[i])return t[i];t[i]=this,this.dom=t;const a=document.createElement("input");a.type="hidden",a.name=t.name,t.removeAttribute("name"),t.type="text",t.setAttribute("inputmode","decimal"),t.insertAdjacentElement("afterend",a),this._hidden=a;const e=this;Object.defineProperty(a,"value",{get:function(){return p.get.call(a)},set:function(r){if(p.set.call(a,r),r!==""&&!isNaN(parseFloat(r))){const n=parseFloat(r);e._displayFormatted(n),v(e.dom,"ln-number:input",{value:n,formatted:e.dom.value}),e.dom.dispatchEvent(new Event("input",{bubbles:!0}))}else r===""&&(e.dom.value="",v(e.dom,"ln-number:input",{value:NaN,formatted:""}),e.dom.dispatchEvent(new Event("input",{bubbles:!0})))}}),O(t,p,{get:function(){return p.get.call(t)},set:function(r,n){if(e._isFormatting){n(r);return}if(r===""){n(""),e._setHiddenRaw(""),v(t,"ln-number:input",{value:NaN,formatted:""}),t.dispatchEvent(new Event("input",{bubbles:!0}));return}let o=typeof r=="number"?r:parseFloat(String(r).replace(/[^\d.-]/g,""));if(isNaN(o))n(String(r)),e._setHiddenRaw(""),v(t,"ln-number:input",{value:NaN,formatted:String(r)}),t.dispatchEvent(new Event("input",{bubbles:!0}));else{e._setHiddenRaw(o);const l=y(N(t),o,t.getAttribute("data-ln-number-decimals"));n(l),v(t,"ln-number:input",{value:o,formatted:l}),t.dispatchEvent(new Event("input",{bubbles:!0}))}}}),this._onInput=function(){e._handleInput()},t.addEventListener("input",this._onInput),this._onPaste=function(r){r.preventDefault();const n=(r.clipboardData||window.clipboardData).getData("text"),o=g(N(t)),l=o.decimalSep.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let f=n.replace(new RegExp("[^0-9\\-"+l+".]","g"),"");o.groupSep&&(f=f.split(o.groupSep).join("")),o.decimalSep!=="."&&(f=f.replace(o.decimalSep,"."));const _=parseFloat(f);isNaN(_)?(t.value="",e._hidden.value=""):e.value=_},t.addEventListener("paste",this._onPaste);const c=t.value;if(c!==""){const r=parseFloat(c);isNaN(r)||(this._displayFormatted(r),p.set.call(a,String(r)),v(t,"ln-number:input",{value:r,formatted:t.value}),t.dispatchEvent(new Event("input",{bubbles:!0})))}return this}m.prototype._handleInput=function(){const t=this.dom,a=g(N(t)),e=t.value;if(e===""){this._hidden.value="",v(t,"ln-number:input",{value:NaN,formatted:""});return}if(e==="-"){this._hidden.value="";return}const c=t.selectionStart;let r=0;for(let d=0;d<c;d++)/[0-9]/.test(e[d])&&r++;let n=e;if(a.groupSep&&(n=n.split(a.groupSep).join("")),n=n.replace(a.decimalSep,"."),e.endsWith(a.decimalSep)||e.endsWith(".")){const d=n.replace(/\.$/,""),w=parseFloat(d);isNaN(w)||this._setHiddenRaw(w);return}const o=n.indexOf(".");if(o!==-1&&n.slice(o+1).endsWith("0")){const w=parseFloat(n);isNaN(w)||this._setHiddenRaw(w);return}const l=t.getAttribute("data-ln-number-decimals");if(l!==null&&o!==-1){const d=parseInt(l,10);n.slice(o+1).length>d&&(n=n.slice(0,o+1+d))}const f=parseFloat(n);if(isNaN(f))return;const _=t.getAttribute("data-ln-number-min"),F=t.getAttribute("data-ln-number-max");if(_!==null&&f<parseFloat(_)||F!==null&&f>parseFloat(F))return;let b;if(l!==null)b=y(N(t),f,l);else{const d=o!==-1?n.slice(o+1).length:0;if(d>0){const w=N(t)+"|u"+d;u[w]||(u[w]=new Intl.NumberFormat(N(t),{useGrouping:!0,minimumFractionDigits:d,maximumFractionDigits:d})),b=u[w].format(f)}else b=a.fmt.format(f)}t.value=b;let E=r,D=0;for(let d=0;d<b.length&&E>0;d++)D=d+1,/[0-9]/.test(b[d])&&E--;E>0&&(D=b.length),t.setSelectionRange(D,D),this._setHiddenRaw(f),v(t,"ln-number:input",{value:f,formatted:b})},m.prototype._setHiddenRaw=function(t){p.set.call(this._hidden,String(t))},m.prototype._displayFormatted=function(t){this._isFormatting=!0,this.dom.value=y(N(this.dom),t,this.dom.getAttribute("data-ln-number-decimals")),this._isFormatting=!1},Object.defineProperty(m.prototype,"value",{get:function(){const t=this._hidden.value;return t===""?NaN:parseFloat(t)},set:function(t){if(typeof t!="number"||isNaN(t)){this.dom.value="",this._setHiddenRaw(""),this.dom.dispatchEvent(new Event("input",{bubbles:!0}));return}this._displayFormatted(t),this._setHiddenRaw(t),v(this.dom,"ln-number:input",{value:t,formatted:this.dom.value}),this.dom.dispatchEvent(new Event("input",{bubbles:!0}))}}),Object.defineProperty(m.prototype,"formatted",{get:function(){return this.dom.value}}),m.prototype.destroy=function(){this.dom[i]&&(this.dom.removeEventListener("input",this._onInput),this.dom.removeEventListener("paste",this._onPaste),this.dom.name=this._hidden.name,this.dom.type="number",this.dom.removeAttribute("inputmode"),this._hidden.remove(),v(this.dom,"ln-number:destroyed",{target:this.dom}),delete this.dom[i])};function h(){new MutationObserver(function(){const t=document.querySelectorAll("["+s+"]");for(let a=0;a<t.length;a++){const e=t[a][i];e&&!isNaN(e.value)&&e._displayFormatted(e.value)}}).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})}I(s,i,m,"ln-number"),h()})()})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
1
|
+
import { dispatch, getLocale, registerComponent, interceptValueProperty } from '../../ln-core';
|
|
2
2
|
|
|
3
3
|
(function () {
|
|
4
4
|
const DOM_SELECTOR = 'data-ln-number';
|
|
@@ -46,6 +46,9 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
46
46
|
return this;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
if (dom[DOM_ATTRIBUTE]) return dom[DOM_ATTRIBUTE];
|
|
50
|
+
dom[DOM_ATTRIBUTE] = this;
|
|
51
|
+
|
|
49
52
|
this.dom = dom;
|
|
50
53
|
|
|
51
54
|
// ── Create hidden input ─────────────────────────────
|
|
@@ -68,9 +71,48 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
68
71
|
_inputValueDesc.set.call(hidden, val);
|
|
69
72
|
// If set programmatically (e.g., populateForm), update display
|
|
70
73
|
if (val !== '' && !isNaN(parseFloat(val))) {
|
|
71
|
-
|
|
74
|
+
const num = parseFloat(val);
|
|
75
|
+
self._displayFormatted(num);
|
|
76
|
+
dispatch(self.dom, 'ln-number:input', { value: num, formatted: self.dom.value });
|
|
77
|
+
self.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
72
78
|
} else if (val === '') {
|
|
73
79
|
self.dom.value = '';
|
|
80
|
+
dispatch(self.dom, 'ln-number:input', { value: NaN, formatted: '' });
|
|
81
|
+
self.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ── Intercept programmatic value sets on visible input (2-way binding) ──
|
|
87
|
+
interceptValueProperty(dom, _inputValueDesc, {
|
|
88
|
+
get: function () {
|
|
89
|
+
return _inputValueDesc.get.call(dom);
|
|
90
|
+
},
|
|
91
|
+
set: function (val, originalSet) {
|
|
92
|
+
if (self._isFormatting) {
|
|
93
|
+
originalSet(val);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (val === '') {
|
|
97
|
+
originalSet('');
|
|
98
|
+
self._setHiddenRaw('');
|
|
99
|
+
dispatch(dom, 'ln-number:input', { value: NaN, formatted: '' });
|
|
100
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Parse and format
|
|
104
|
+
let num = typeof val === 'number' ? val : parseFloat(String(val).replace(/[^\d.-]/g, ''));
|
|
105
|
+
if (isNaN(num)) {
|
|
106
|
+
originalSet(String(val));
|
|
107
|
+
self._setHiddenRaw('');
|
|
108
|
+
dispatch(dom, 'ln-number:input', { value: NaN, formatted: String(val) });
|
|
109
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
110
|
+
} else {
|
|
111
|
+
self._setHiddenRaw(num);
|
|
112
|
+
const formatted = _formatNum(getLocale(dom), num, dom.getAttribute('data-ln-number-decimals'));
|
|
113
|
+
originalSet(formatted);
|
|
114
|
+
dispatch(dom, 'ln-number:input', { value: num, formatted: formatted });
|
|
115
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
74
116
|
}
|
|
75
117
|
}
|
|
76
118
|
});
|
|
@@ -114,6 +156,8 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
114
156
|
if (!isNaN(num)) {
|
|
115
157
|
this._displayFormatted(num);
|
|
116
158
|
_inputValueDesc.set.call(hidden, String(num));
|
|
159
|
+
dispatch(dom, 'ln-number:input', { value: num, formatted: dom.value });
|
|
160
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
117
161
|
}
|
|
118
162
|
}
|
|
119
163
|
|
|
@@ -236,7 +280,9 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
236
280
|
};
|
|
237
281
|
|
|
238
282
|
_component.prototype._displayFormatted = function (num) {
|
|
283
|
+
this._isFormatting = true;
|
|
239
284
|
this.dom.value = _formatNum(getLocale(this.dom), num, this.dom.getAttribute('data-ln-number-decimals'));
|
|
285
|
+
this._isFormatting = false;
|
|
240
286
|
};
|
|
241
287
|
|
|
242
288
|
// ─── Public API ───────────────────────────────────────────
|
|
@@ -250,6 +296,7 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
250
296
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
251
297
|
this.dom.value = '';
|
|
252
298
|
this._setHiddenRaw('');
|
|
299
|
+
this.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
253
300
|
return;
|
|
254
301
|
}
|
|
255
302
|
this._displayFormatted(num);
|
|
@@ -258,6 +305,7 @@ import { dispatch, getLocale, registerComponent } from '../../ln-core';
|
|
|
258
305
|
value: num,
|
|
259
306
|
formatted: this.dom.value
|
|
260
307
|
});
|
|
308
|
+
this.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
261
309
|
}
|
|
262
310
|
});
|
|
263
311
|
|