@kupola/kupola 2.0.0-beta.2 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kupola-core-datepicker.cjs.js +9 -9
- package/dist/kupola-core-datepicker.esm.js +9 -9
- package/dist/kupola-core-dialog.cjs.js +8 -8
- package/dist/kupola-core-dialog.esm.js +8 -8
- package/dist/kupola-core-drawer.cjs.js +5 -5
- package/dist/kupola-core-drawer.esm.js +5 -5
- package/dist/kupola-core-dropdown.cjs.js +4 -4
- package/dist/kupola-core-dropdown.esm.js +4 -4
- package/dist/kupola-core-i18n.cjs.js +1 -1
- package/dist/kupola-core-i18n.esm.js +1 -1
- package/dist/kupola-core-modal.cjs.js +2 -2
- package/dist/kupola-core-modal.esm.js +2 -2
- package/dist/kupola-core-numberinput.cjs.js +6 -5
- package/dist/kupola-core-numberinput.esm.js +6 -5
- package/dist/kupola-core-select.cjs.js +8 -7
- package/dist/kupola-core-select.esm.js +8 -7
- package/dist/kupola-core-table.cjs.js +1 -1
- package/dist/kupola-core-table.esm.js +1 -1
- package/dist/kupola-core-timepicker.cjs.js +3 -3
- package/dist/kupola-core-timepicker.esm.js +3 -3
- package/dist/kupola-core.cjs.js +1 -1
- package/dist/kupola-core.esm.js +1 -1
- package/package.json +1 -1
- package/packages/core/src/components/datepicker.js +11 -6
- package/packages/core/src/components/dialog.js +14 -7
- package/packages/core/src/components/drawer.js +5 -3
- package/packages/core/src/components/dropdown.js +15 -3
- package/packages/core/src/components/modal.js +20 -1
- package/packages/core/src/components/numberinput.js +12 -3
- package/packages/core/src/components/select.js +22 -5
- package/packages/core/src/components/table.js +3 -1
- package/packages/core/src/components/timepicker.js +2 -1
- package/packages/core/src/errors.js +80 -0
- package/packages/core/src/i18n.js +5 -0
- package/packages/core/src/index.js +3 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";class t{constructor(t,
|
|
1
|
+
"use strict";class t{constructor(t,e){this.strings=t,this.values=e}}function e(e,...n){return new t(e,n)}function n(t){const e={t:t,i:new Set,o:null,l:!1};return e.o=()=>{e.l||i(e)},i(e),()=>function(t){if(t.l)return;t.l=!0,s(t)}(e)}function i(t){s(t);try{t.t()}finally{}}function s(t){for(const e of t.i)e.u.delete(t);t.i.clear()}function o(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function c(t){if(null==t||"object"!=typeof t)return!1;const e=Object.getOwnPropertyDescriptor(t,"value");if(e&&"function"==typeof e.get)return!0;const n=Object.getPrototypeOf(t);if(n){const t=Object.getOwnPropertyDescriptor(n,"value");if(t&&"function"==typeof t.get)return!0}return!1}const r=t=>`${t}`;function l(e){const n=[];for(let i=0;i<e.strings.length;i++)if(n.push(e.strings[i]),i<e.values.length){const s=e.values[i];s instanceof t?n.push(l(s)):Array.isArray(s)&&s.length>0&&s[0]instanceof t?n.push(s.map(l).join("")):c(s)?n.push(o(s.value)):"function"!=typeof s&&n.push(o(s??""))}return n.join("")}function u(t,e){const n=t.indexOf(e);if(-1===n)return{type:"text"};const i=t.substring(0,n).lastIndexOf("<");if(-1===i)return{type:"text"};if(t.substring(i,n).includes(">"))return{type:"text"};const s=t.substring(i+1,n).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!s)return{type:"text"};const o=s[1];return o.startsWith("on")&&o.length>2?{type:"event",attrName:o}:{type:"attr",attrName:o}}class a{constructor(t,e){this.container=t,this.rawValue=e,this.node=null,this.p=null}mount(){const e=document.createTextNode("");if(this.h?this.container.insertBefore(e,this.h):this.container.appendChild(e),this.node=e,c(this.rawValue)){const t=this.rawValue;this.p=n(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof t?this.node.textContent=l(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.p?.(),this.node?.remove()}}class d{constructor(t,e,n){this.element=t,this.attrName=e,this.rawValue=n,this.p=null}mount(){if(c(this.rawValue)){const t=this.rawValue;this.p=n(()=>{const e=t.value;null==e||!1===e?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(e))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.p?.()}}class p{constructor(t,e,n){this.element=t,this.eventName=e.slice(2).toLowerCase(),this.handler=n,this.m=null}mount(){"function"==typeof this.handler&&(this.m=t=>this.handler(t),this.element.addEventListener(this.eventName,this.m))}destroy(){this.m&&(this.element.removeEventListener(this.eventName,this.m),this.m=null)}}class f{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function h(e,n){const i=new f,s=function(e){const n=[];for(let i=0;i<e.strings.length;i++)if(n.push(e.strings[i]),i<e.values.length){const s=e.values[i];s instanceof t?n.push(l(s)):Array.isArray(s)&&s.length>0&&s[0]instanceof t?n.push(s.map(l).join("")):"function"==typeof s||c(s)?n.push(r(i)):n.push(o(s??""))}return n.join("")}(e),u=function(t){const e=document.createElement("template");return e.innerHTML=t,e.content}(s);i.fragment=u,m(u,e.values,s,i);for(const t of i.parts)t.mount();return n.appendChild(u),i}function m(t,e,n,i){const s=[...t.childNodes];for(const o of s)3===o.nodeType?g(o,e,n,i,t):1===o.nodeType&&k(o,e,n,i)}function g(t,e,n,i,s){const o=t.textContent||"";for(let c=0;c<e.length;c++){const l=r(c),d=o.indexOf(l);if(-1===d)continue;if("text"!==u(n,l).type)continue;const p=o.substring(0,d),f=o.substring(d+l.length);p&&s.insertBefore(document.createTextNode(p),t);const h=new a(s,e[c]);i.parts.push(h);let m=t;return f&&(m=document.createTextNode(f),s.insertBefore(m,t)),s.removeChild(t),h.h=m!==t?m:null,void(f&&g(m,e,n,i,s))}}function k(t,e,n,i){const s=[...t.attributes];for(const o of s)for(let s=0;s<e.length;s++){const c=r(s);if(!o.value.includes(c))continue;const l=u(n,c);if("event"===l.type&&l.attrName===o.name){t.removeAttribute(o.name);const n=new p(t,o.name,e[s]);i.parts.push(n)}else if("attr"===l.type&&l.attrName===o.name){const n=o.value.replace(c,"");n?t.setAttribute(o.name,n):t.removeAttribute(o.name);const r=new d(t,o.name,e[s]);i.parts.push(r)}}m(t,e,n,i)}const _={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data","datepicker.months":"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec","datepicker.weekdays":"Mo,Tu,We,Th,Fr,Sa,Su","timepicker.placeholder":"Select time"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","datepicker.months":"1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月","datepicker.weekdays":"一,二,三,四,五,六,日","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};exports.Timepicker=function(t={}){const{value:n="",format:i="24h",step:s=1,disabled:o=!1,onChange:c=null}=t;let r=n,l=!1;function u(){l?a():function(){l=!0,b&&(b.style.display="block");x||(document.addEventListener("click",d),x=!0)}()}function a(){l=!1,b&&(b.style.display="none")}function d(t){v&&v.contains(t.target)||a()}function p(t){r=t.target.value,m(),c&&c(r)}function f(t,e){const n=String(t).padStart(2,"0"),i=String(e).padStart(2,"0");r=`${n}:${i}`,S&&(S.value=r),m(),a(),c&&c(r)}function m(){if(!w)return;if(!r)return void(w.textContent="--:--");const t=r.split(":");let e=parseInt(t[0])||0;const n=parseInt(t[1])||0;if("12h"===i){const t=e>=12?"PM":"AM";e=e%12||12,w.textContent=`${e}:${String(n).padStart(2,"0")} ${t}`}else w.textContent=`${String(e).padStart(2,"0")}:${String(n).padStart(2,"0")}`}const g=e`
|
|
2
2
|
<div class="ds-timepicker">
|
|
3
3
|
<div class="ds-timepicker__input-wrap">
|
|
4
|
-
<input class="ds-timepicker__input" type="text" readonly placeholder="
|
|
4
|
+
<input class="ds-timepicker__input" type="text" readonly placeholder="${function(t,e={}){let n=(_["en-US"]||_["en-US"])[t]||t;for(const[t,i]of Object.entries(e))n=n.replace(`{${t}}`,i);return n}("timepicker.placeholder")}" />
|
|
5
5
|
<span class="ds-timepicker__icon">
|
|
6
6
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
|
7
7
|
</span>
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
|
22
|
-
`,
|
|
22
|
+
`,k=document.createDocumentFragment(),y=h(g,k),v=k.querySelector(".ds-timepicker"),S=k.querySelector(".ds-timepicker__input"),b=k.querySelector(".ds-timepicker__panel"),w=k.querySelector(".ds-timepicker__icon");b&&(b.style.display="none");let x=!1;const $=k.querySelector(".ds-timepicker__grid--hour");for(let t="12h"===i?1:0;t<("12h"===i?13:24);t++){const e=document.createElement("button");e.type="button",e.className="ds-timepicker__item",e.textContent=String(t).padStart(2,"0"),e.addEventListener("click",()=>{const e=r&&parseInt(r.split(":")[1])||0;let n=t;if("12h"===i){const e=r&&parseInt(r.split(":")[0])>=12;e&&t<12?n=t+12:e||12!==t||(n=0)}f(n,e)}),$.appendChild(e)}const M=k.querySelector(".ds-timepicker__grid--minute");for(let t=0;t<60;t+=s){const e=document.createElement("button");e.type="button",e.className="ds-timepicker__item",e.textContent=String(t).padStart(2,"0"),e.addEventListener("click",()=>{f(r&&parseInt(r.split(":")[0])||0,t)}),M.appendChild(e)}return S&&(S.value=r,S.disabled=o,S.addEventListener("click",u)),m(),{get element(){return k},getValue:function(){return r},setValue:function(t){r=t,S&&(S.value=r),m(),c&&c(r)},destroy:function(){a(),S&&S.removeEventListener("click",u),S&&S.removeEventListener("change",p),y.destroy()}}};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
class t{constructor(t,
|
|
1
|
+
class t{constructor(t,e){this.strings=t,this.values=e}}function e(e,...n){return new t(e,n)}function n(t){const e={t:t,i:new Set,o:null,l:!1};return e.o=()=>{e.l||i(e)},i(e),()=>function(t){if(t.l)return;t.l=!0,s(t)}(e)}function i(t){s(t);try{t.t()}finally{}}function s(t){for(const e of t.i)e.u.delete(t);t.i.clear()}function o(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function c(t){if(null==t||"object"!=typeof t)return!1;const e=Object.getOwnPropertyDescriptor(t,"value");if(e&&"function"==typeof e.get)return!0;const n=Object.getPrototypeOf(t);if(n){const t=Object.getOwnPropertyDescriptor(n,"value");if(t&&"function"==typeof t.get)return!0}return!1}const r=t=>`${t}`;function l(e){const n=[];for(let i=0;i<e.strings.length;i++)if(n.push(e.strings[i]),i<e.values.length){const s=e.values[i];s instanceof t?n.push(l(s)):Array.isArray(s)&&s.length>0&&s[0]instanceof t?n.push(s.map(l).join("")):c(s)?n.push(o(s.value)):"function"!=typeof s&&n.push(o(s??""))}return n.join("")}function u(t,e){const n=t.indexOf(e);if(-1===n)return{type:"text"};const i=t.substring(0,n).lastIndexOf("<");if(-1===i)return{type:"text"};if(t.substring(i,n).includes(">"))return{type:"text"};const s=t.substring(i+1,n).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!s)return{type:"text"};const o=s[1];return o.startsWith("on")&&o.length>2?{type:"event",attrName:o}:{type:"attr",attrName:o}}class a{constructor(t,e){this.container=t,this.rawValue=e,this.node=null,this.p=null}mount(){const e=document.createTextNode("");if(this.h?this.container.insertBefore(e,this.h):this.container.appendChild(e),this.node=e,c(this.rawValue)){const t=this.rawValue;this.p=n(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof t?this.node.textContent=l(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.p?.(),this.node?.remove()}}class d{constructor(t,e,n){this.element=t,this.attrName=e,this.rawValue=n,this.p=null}mount(){if(c(this.rawValue)){const t=this.rawValue;this.p=n(()=>{const e=t.value;null==e||!1===e?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(e))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.p?.()}}class p{constructor(t,e,n){this.element=t,this.eventName=e.slice(2).toLowerCase(),this.handler=n,this.m=null}mount(){"function"==typeof this.handler&&(this.m=t=>this.handler(t),this.element.addEventListener(this.eventName,this.m))}destroy(){this.m&&(this.element.removeEventListener(this.eventName,this.m),this.m=null)}}class f{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function h(e,n){const i=new f,s=function(e){const n=[];for(let i=0;i<e.strings.length;i++)if(n.push(e.strings[i]),i<e.values.length){const s=e.values[i];s instanceof t?n.push(l(s)):Array.isArray(s)&&s.length>0&&s[0]instanceof t?n.push(s.map(l).join("")):"function"==typeof s||c(s)?n.push(r(i)):n.push(o(s??""))}return n.join("")}(e),u=function(t){const e=document.createElement("template");return e.innerHTML=t,e.content}(s);i.fragment=u,m(u,e.values,s,i);for(const t of i.parts)t.mount();return n.appendChild(u),i}function m(t,e,n,i){const s=[...t.childNodes];for(const o of s)3===o.nodeType?g(o,e,n,i,t):1===o.nodeType&&k(o,e,n,i)}function g(t,e,n,i,s){const o=t.textContent||"";for(let c=0;c<e.length;c++){const l=r(c),d=o.indexOf(l);if(-1===d)continue;if("text"!==u(n,l).type)continue;const p=o.substring(0,d),f=o.substring(d+l.length);p&&s.insertBefore(document.createTextNode(p),t);const h=new a(s,e[c]);i.parts.push(h);let m=t;return f&&(m=document.createTextNode(f),s.insertBefore(m,t)),s.removeChild(t),h.h=m!==t?m:null,void(f&&g(m,e,n,i,s))}}function k(t,e,n,i){const s=[...t.attributes];for(const o of s)for(let s=0;s<e.length;s++){const c=r(s);if(!o.value.includes(c))continue;const l=u(n,c);if("event"===l.type&&l.attrName===o.name){t.removeAttribute(o.name);const n=new p(t,o.name,e[s]);i.parts.push(n)}else if("attr"===l.type&&l.attrName===o.name){const n=o.value.replace(c,"");n?t.setAttribute(o.name,n):t.removeAttribute(o.name);const r=new d(t,o.name,e[s]);i.parts.push(r)}}m(t,e,n,i)}const _={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data","datepicker.months":"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec","datepicker.weekdays":"Mo,Tu,We,Th,Fr,Sa,Su","timepicker.placeholder":"Select time"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","datepicker.months":"1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月","datepicker.weekdays":"一,二,三,四,五,六,日","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};function y(t={}){const{value:n="",format:i="24h",step:s=1,disabled:o=!1,onChange:c=null}=t;let r=n,l=!1;function u(){l?a():function(){l=!0,b&&(b.style.display="block");x||(document.addEventListener("click",d),x=!0)}()}function a(){l=!1,b&&(b.style.display="none")}function d(t){v&&v.contains(t.target)||a()}function p(t){r=t.target.value,m(),c&&c(r)}function f(t,e){const n=String(t).padStart(2,"0"),i=String(e).padStart(2,"0");r=`${n}:${i}`,S&&(S.value=r),m(),a(),c&&c(r)}function m(){if(!w)return;if(!r)return void(w.textContent="--:--");const t=r.split(":");let e=parseInt(t[0])||0;const n=parseInt(t[1])||0;if("12h"===i){const t=e>=12?"PM":"AM";e=e%12||12,w.textContent=`${e}:${String(n).padStart(2,"0")} ${t}`}else w.textContent=`${String(e).padStart(2,"0")}:${String(n).padStart(2,"0")}`}const g=e`
|
|
2
2
|
<div class="ds-timepicker">
|
|
3
3
|
<div class="ds-timepicker__input-wrap">
|
|
4
|
-
<input class="ds-timepicker__input" type="text" readonly placeholder="
|
|
4
|
+
<input class="ds-timepicker__input" type="text" readonly placeholder="${function(t,e={}){let n=(_["en-US"]||_["en-US"])[t]||t;for(const[t,i]of Object.entries(e))n=n.replace(`{${t}}`,i);return n}("timepicker.placeholder")}" />
|
|
5
5
|
<span class="ds-timepicker__icon">
|
|
6
6
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
|
7
7
|
</span>
|
|
@@ -19,4 +19,4 @@ class t{constructor(t,n){this.strings=t,this.values=n}}function n(n,...i){return
|
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
|
22
|
-
`,
|
|
22
|
+
`,k=document.createDocumentFragment(),y=h(g,k),v=k.querySelector(".ds-timepicker"),S=k.querySelector(".ds-timepicker__input"),b=k.querySelector(".ds-timepicker__panel"),w=k.querySelector(".ds-timepicker__icon");b&&(b.style.display="none");let x=!1;const $=k.querySelector(".ds-timepicker__grid--hour");for(let t="12h"===i?1:0;t<("12h"===i?13:24);t++){const e=document.createElement("button");e.type="button",e.className="ds-timepicker__item",e.textContent=String(t).padStart(2,"0"),e.addEventListener("click",()=>{const e=r&&parseInt(r.split(":")[1])||0;let n=t;if("12h"===i){const e=r&&parseInt(r.split(":")[0])>=12;e&&t<12?n=t+12:e||12!==t||(n=0)}f(n,e)}),$.appendChild(e)}const M=k.querySelector(".ds-timepicker__grid--minute");for(let t=0;t<60;t+=s){const e=document.createElement("button");e.type="button",e.className="ds-timepicker__item",e.textContent=String(t).padStart(2,"0"),e.addEventListener("click",()=>{f(r&&parseInt(r.split(":")[0])||0,t)}),M.appendChild(e)}return S&&(S.value=r,S.disabled=o,S.addEventListener("click",u)),m(),{get element(){return k},getValue:function(){return r},setValue:function(t){r=t,S&&(S.value=r),m(),c&&c(r)},destroy:function(){a(),S&&S.removeEventListener("click",u),S&&S.removeEventListener("change",p),y.destroy()}}}export{y as Timepicker};
|
package/dist/kupola-core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=new Set;let n=!1;function o(o){t.add(o),n||(n=!0,queueMicrotask(e))}function e(){for(n=!1;t.size>0;){const n=[...t];t.clear();for(const t of n)t()}}let s=null;const c=[];function i(t){c.push(s),s=t}function r(){s=c.pop()??null}let f=0;const u=new Set;function l(t){f=t}function a(t){s&&(t.t.add(s),s.o.add(t))}function h(t){for(const n of t.t)n.i?n.u():f>0?u.add(n.u):o(n.u)}class p{constructor(t){this.l=t,this.t=new Set}get value(){return a(this),this.l}set value(t){Object.is(this.l,t)||(this.l=t,h(this))}peek(){return this.l}toString(){return String(this.l)}toJSON(){return JSON.stringify(this.l)}}function d(t){return new p(t)}function y(t){const n={h:t,o:new Set,u:null,p:!1};return n.u=()=>{n.p||g(n)},g(n),()=>function(t){if(t.p)return;t.p=!0,k(t)}(n)}function g(t){k(t),i(t);try{t.h()}finally{r()}}function k(t){for(const n of t.o)n.t.delete(t);t.o.clear()}class x{constructor(t,n){this.strings=t,this.values=n}}function m(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function w(t){if(null==t||"object"!=typeof t)return!1;const n=Object.getOwnPropertyDescriptor(t,"value");if(n&&"function"==typeof n.get)return!0;const o=Object.getPrototypeOf(t);if(o){const t=Object.getOwnPropertyDescriptor(o,"value");if(t&&"function"==typeof t.get)return!0}return!1}const b=t=>`${t}`;function S(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof x?n.push(S(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof x?n.push(e.map(S).join("")):w(e)?n.push(m(e.value)):"function"!=typeof e&&n.push(m(e??""))}return n.join("")}function _(t,n){const o=t.indexOf(n);if(-1===o)return{type:"text"};const e=t.substring(0,o).lastIndexOf("<");if(-1===e)return{type:"text"};if(t.substring(e,o).includes(">"))return{type:"text"};const s=t.substring(e+1,o).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!s)return{type:"text"};const c=s[1];return c.startsWith("on")&&c.length>2?{type:"event",attrName:c}:{type:"attr",attrName:c}}class O{constructor(t,n){this.container=t,this.rawValue=n,this.node=null,this.k=null}mount(){const t=document.createTextNode("");if(this.m?this.container.insertBefore(t,this.m):this.container.appendChild(t),this.node=t,w(this.rawValue)){const t=this.rawValue;this.k=y(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof x?this.node.textContent=S(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.k?.(),this.node?.remove()}}class j{constructor(t,n,o){this.element=t,this.attrName=n,this.rawValue=o,this.k=null}mount(){if(w(this.rawValue)){const t=this.rawValue;this.k=y(()=>{const n=t.value;null==n||!1===n?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(n))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.k?.()}}class v{constructor(t,n,o){this.element=t,this.eventName=n.slice(2).toLowerCase(),this.handler=o,this.S=null}mount(){"function"==typeof this.handler&&(this.S=t=>this.handler(t),this.element.addEventListener(this.eventName,this.S))}destroy(){this.S&&(this.element.removeEventListener(this.eventName,this.S),this.S=null)}}class N{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function $(t,n){const o=new N,e=function(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof x?n.push(S(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof x?n.push(e.map(S).join("")):"function"==typeof e||w(e)?n.push(b(o)):n.push(m(e??""))}return n.join("")}(t),s=function(t){const n=document.createElement("template");return n.innerHTML=t,n.content}(e);o.fragment=s,A(s,t.values,e,o);for(const t of o.parts)t.mount();return n.appendChild(s),o}function A(t,n,o,e){const s=[...t.childNodes];for(const c of s)3===c.nodeType?J(c,n,o,e,t):1===c.nodeType&&C(c,n,o,e)}function J(t,n,o,e,s){const c=t.textContent||"";for(let i=0;i<n.length;i++){const r=b(i),f=c.indexOf(r);if(-1===f)continue;if("text"!==_(o,r).type)continue;const u=c.substring(0,f),l=c.substring(f+r.length);u&&s.insertBefore(document.createTextNode(u),t);const a=new O(s,n[i]);e.parts.push(a);let h=t;return l&&(h=document.createTextNode(l),s.insertBefore(h,t)),s.removeChild(t),a.m=h!==t?h:null,void(l&&J(h,n,o,e,s))}}function C(t,n,o,e){const s=[...t.attributes];for(const c of s)for(let s=0;s<n.length;s++){const i=b(s);if(!c.value.includes(i))continue;const r=_(o,i);if("event"===r.type&&r.attrName===c.name){t.removeAttribute(c.name);const o=new v(t,c.name,n[s]);e.parts.push(o)}else if("attr"===r.type&&r.attrName===c.name){const o=c.value.replace(i,"");o?t.setAttribute(c.name,o):t.removeAttribute(c.name);const r=new j(t,c.name,n[s]);e.parts.push(r)}}A(t,n,o,e)}function M(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof x?n.push(M(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof x?n.push(e.map(t=>M(t)).join("")):w(e)?n.push(m(e.value)):"function"!=typeof e&&n.push(m(e??""))}return n.join("")}function P(t){const n=t.join("");let o=!1,e="",s=-1,c=!1;for(let t=0;t<n.length;t++){const i=n[t];o?i===e&&(o=!1):'"'===i||"'"===i?(o=!0,e=i):"<"===i?(s=t,c=!1):">"===i&&s>=0&&!o&&(c=!0)}return s>=0&&!c}function q(t,n,o,e){const s=[...t.childNodes];for(const c of s)8===c.nodeType?D(c,n,t,o,e):1===c.nodeType&&F(c,n,o,e)}function D(t,n,o,e,s){const c=s.indices[s.nextIdx++]??-1,i=t.previousSibling;let r;if(i&&3===i.nodeType?r=i:(r=document.createTextNode(""),o.insertBefore(r,t)),c>=0&&c<n.length){const t=n[c];if(w(t)){const n=y(()=>{r.textContent=null!=t.value?String(t.value):""});e.parts.push({destroy(){n(),r.remove()}})}else r.textContent=null!=t?String(t):""}o.removeChild(t)}function F(t,n,o,e){const s=t.getAttribute("data-kp");if(s){const e=s.split(",");for(const s of e){const e=s.indexOf(":"),c=s.indexOf(":",e+1),i=parseInt(s.substring(0,e),10),r=s.substring(e+1,c),f=s.substring(c+1);if(i>=0&&i<n.length)if("e"===r){const e=new v(t,f,n[i]);e.mount(),o.parts.push(e)}else if("a"===r){const e=new j(t,f,n[i]);e.mount(),o.parts.push(e)}}t.removeAttribute("data-kp")}q(t,n,o,e)}const I=new Map;function K(t){const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=d(t[o]));const o=Object.keys(n);return new Proxy({},{get(t,o){if("symbol"==typeof o)return;const e=n[o];return e?e.value:void 0},set(t,e,s){const c=n[e];return c?c.value=s:(n[e]=d(s),o.push(e)),!0},has:(t,o)=>o in n,ownKeys:()=>o,getOwnPropertyDescriptor(t,o){if(o in n)return{enumerable:!0,configurable:!0}}})}const U=new Map;function z(t,n){let o=U.get(t);return o||(o=new Function("__s__",`with(__s__){return(${t})}`),U.set(t,o)),o(n)}function B(t){const n=t.split("."),o=n[0],e=n.slice(1),s=o.indexOf(":");return-1===s?{base:o,arg:null,modifiers:e}:{base:o.substring(0,s),arg:o.substring(s+1),modifiers:e}}function E(t,n,o,e){const s=y(()=>{const e=z(n,o);t.style.display=e?"":"none"});e.push(s)}function G(t,n,o,e){const s=y(()=>{t.textContent=String(z(n,o)??"")});e.push(s)}function H(t,n,o,e){const s=y(()=>{t.innerHTML=String(z(n,o)??"")});e.push(s)}function L(t,n,o,e,s){const c=y(()=>{const s=z(n,e);!1===s||null==s?t.removeAttribute(o):!0===s?t.setAttribute(o,""):t.setAttribute(o,String(s))});s.push(c)}function Q(t,n,o,s,c,i){const r=s.includes("stop"),f=s.includes("prevent"),u=s.includes("once"),l=s.includes("self"),a=o=>{l&&o.target!==t||(r&&o.stopPropagation(),f&&o.preventDefault(),function(t,n){const o="$$"+t;let e=U.get(o);e||(e=new Function("__s__",`with(__s__){${t}}`),U.set(o,e)),e(n)}(n,c),e())};t.addEventListener(o,a,{once:u}),i.push(()=>t.removeEventListener(o,a))}function R(t,n,o,s){const c=y(()=>{const e=z(n,o);t.value=null!=e?String(e):""});s.push(c);const i=()=>{const s=n.trim().split(".");if(1===s.length)o[s[0]]=t.value;else{const e=s.slice(0,-1).join("."),c=s[s.length-1];try{const n=z(e,o);n&&"object"==typeof n&&(n[c]=t.value)}catch(e){o[n]=t.value}}e()};t.addEventListener("input",i),s.push(()=>t.removeEventListener("input",i))}function T(t){return t.startsWith("k-")||t.startsWith(":")||t.startsWith("@")}function V(t){return t.startsWith(":")?"k-bind:"+t.substring(1):t.startsWith("@")?"k-on:"+t.substring(1):t}function W(t,n,o){const e=[...t.attributes];for(const s of e){const e=s.name,c=s.value;if(!T(e))continue;const i=V(e),{base:r,arg:f,modifiers:u}=B(i);switch(r){case"k-show":E(t,c,n,o);break;case"k-text":G(t,c,n,o);break;case"k-html":H(t,c,n,o);break;case"k-bind":f&&L(t,c,f,n,o);break;case"k-on":f&&Q(t,c,f,u,n,o);break;case"k-model":R(t,c,n,o)}}}function X(t,n,o){for(const e of t.children)e.hasAttribute("k-data")||(W(e,n,o),X(e,n,o))}function Y(t,n){const o=t.getAttribute("k-data");let e={};try{e=z(o,K({}))||{}}catch(t){}const s=K(e);W(t,s,n),X(t,s,n);for(const o of t.children)o.hasAttribute("k-data")&&Y(o,n)}const Z={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};let tt="en-US";exports.Signal=p,exports.TemplateResult=x,exports.addMessages=function(t,n){Z[t]||(Z[t]={}),Object.assign(Z[t],n)},exports.batch=function(t){l(f+1);try{return t()}finally{if(l(f-1),0===f){const t=u,n=[...t];t.clear();for(const t of n)t();e()}}},exports.clearRegistry=function(){I.clear()},exports.computed=function(t){const n=new p(void 0);let o=!0,e=new Set;const s={h:null,o:e,i:!0,u:null,p:!1};function c(){for(const t of e)t.t.delete(s);e.clear(),s.o=e,i(s);try{const o=t();Object.is(n.l,o)||(n.l=o)}finally{r()}o=!1}return s.u=()=>{o||(o=!0,h(n))},{get value(){return o&&c(),a(n),n.l},peek:()=>(o&&c(),n.l),toString(){return String(this.value)},toJSON(){return JSON.stringify(this.value)}}},exports.defineComponent=function(t){const{props:n=[],setup:o}=t;function e(t={},e=null){const s={};for(const o of n)s[o]=d(t[o]);const c=o(s,e)(),i=document.createDocumentFragment(),r=$(c,i);return{get element(){return i},_:r,destroy(){r.destroy()},update(t){for(const o of n)o in t&&s[o]&&(s[o].value=t[o])}}}return e.O=!0,e.j=n,e},exports.effect=y,exports.flushJobs=e,exports.getComponent=function(t){return I.get(t)},exports.getLocale=function(){return tt},exports.hasComponent=function(t){return I.has(t)},exports.html=function(t,...n){return new x(t,n)},exports.hydrate=function(t,n){const o=new N,e=function(t){const n=[],o=[];let e=!1;for(let s=0;s<t.strings.length;s++)if(o.push(t.strings[s]),e=P(o),s<t.values.length){const c=t.values[s];if(c instanceof x)o.push(M(c));else if(Array.isArray(c)&&c.length>0&&c[0]instanceof x)o.push(c.map(t=>M(t)).join(""));else if("function"==typeof c);else if(w(c))if(e){const t=c.value;o.push(null!=t?m(t):"")}else{n.push(s);const t=c.value;o.push(null!=t?m(t):"")}else o.push(m(c??""))}return{indices:n,nextIdx:0}}(t);return q(n,t.values,o,e),o},exports.register=function(t,n){I.set(t,n)},exports.render=$,exports.resetScheduler=function(){t.clear(),n=!1},exports.setLocale=function(t){tt=t},exports.signal=d,exports.t=function(t,n={}){let o=(Z[tt]||Z["en-US"])[t]||t;for(const[t,e]of Object.entries(n))o=o.replace(`{${t}}`,e);return o},exports.walk=function(t){const n=[];if(t.hasAttribute&&t.hasAttribute("k-data"))Y(t,n);else{const o=t.querySelectorAll?t.querySelectorAll("[k-data]"):[];if(o.length>0)for(const e of o){let o=!1,s=e.parentElement;for(;s&&s!==t;){if(s.hasAttribute("k-data")){o=!0;break}s=s.parentElement}o||Y(e,n)}else{const o=K({});for(const e of t.children)W(e,o,n),X(e,o,n)}}return{destroy(){for(const t of n)t();n.length=0}}};
|
|
1
|
+
"use strict";const t=new Set;let n=!1;function o(o){t.add(o),n||(n=!0,queueMicrotask(e))}function e(){for(n=!1;t.size>0;){const n=[...t];t.clear();for(const t of n)t()}}let s=null;const c=[];function r(t){c.push(s),s=t}function i(){s=c.pop()??null}let u=0;const f=new Set;function l(t){u=t}function a(t){s&&(t.t.add(s),s.o.add(t))}function p(t){for(const n of t.t)n.i?n.u():u>0?f.add(n.u):o(n.u)}class h{constructor(t){this.l=t,this.t=new Set}get value(){return a(this),this.l}set value(t){Object.is(this.l,t)||(this.l=t,p(this))}peek(){return this.l}toString(){return String(this.l)}toJSON(){return JSON.stringify(this.l)}}function d(t){return new h(t)}function y(t){const n={p:t,o:new Set,u:null,h:!1};return n.u=()=>{n.h||g(n)},g(n),()=>function(t){if(t.h)return;t.h=!0,m(t)}(n)}function g(t){m(t),r(t);try{t.p()}finally{i()}}function m(t){for(const n of t.o)n.t.delete(t);t.o.clear()}class k{constructor(t,n){this.strings=t,this.values=n}}function b(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function x(t){if(null==t||"object"!=typeof t)return!1;const n=Object.getOwnPropertyDescriptor(t,"value");if(n&&"function"==typeof n.get)return!0;const o=Object.getPrototypeOf(t);if(o){const t=Object.getOwnPropertyDescriptor(o,"value");if(t&&"function"==typeof t.get)return!0}return!1}const S=t=>`${t}`;function w(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof k?n.push(w(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof k?n.push(e.map(w).join("")):x(e)?n.push(b(e.value)):"function"!=typeof e&&n.push(b(e??""))}return n.join("")}function _(t,n){const o=t.indexOf(n);if(-1===o)return{type:"text"};const e=t.substring(0,o).lastIndexOf("<");if(-1===e)return{type:"text"};if(t.substring(e,o).includes(">"))return{type:"text"};const s=t.substring(e+1,o).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!s)return{type:"text"};const c=s[1];return c.startsWith("on")&&c.length>2?{type:"event",attrName:c}:{type:"attr",attrName:c}}class O{constructor(t,n){this.container=t,this.rawValue=n,this.node=null,this.m=null}mount(){const t=document.createTextNode("");if(this.k?this.container.insertBefore(t,this.k):this.container.appendChild(t),this.node=t,x(this.rawValue)){const t=this.rawValue;this.m=y(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof k?this.node.textContent=w(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.m?.(),this.node?.remove()}}class v{constructor(t,n,o){this.element=t,this.attrName=n,this.rawValue=o,this.m=null}mount(){if(x(this.rawValue)){const t=this.rawValue;this.m=y(()=>{const n=t.value;null==n||!1===n?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(n))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.m?.()}}class j{constructor(t,n,o){this.element=t,this.eventName=n.slice(2).toLowerCase(),this.handler=o,this.S=null}mount(){"function"==typeof this.handler&&(this.S=t=>this.handler(t),this.element.addEventListener(this.eventName,this.S))}destroy(){this.S&&(this.element.removeEventListener(this.eventName,this.S),this.S=null)}}class N{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function $(t,n){const o=new N,e=function(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof k?n.push(w(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof k?n.push(e.map(w).join("")):"function"==typeof e||x(e)?n.push(S(o)):n.push(b(e??""))}return n.join("")}(t),s=function(t){const n=document.createElement("template");return n.innerHTML=t,n.content}(e);o.fragment=s,J(s,t.values,e,o);for(const t of o.parts)t.mount();return n.appendChild(s),o}function J(t,n,o,e){const s=[...t.childNodes];for(const c of s)3===c.nodeType?A(c,n,o,e,t):1===c.nodeType&&M(c,n,o,e)}function A(t,n,o,e,s){const c=t.textContent||"";for(let r=0;r<n.length;r++){const i=S(r),u=c.indexOf(i);if(-1===u)continue;if("text"!==_(o,i).type)continue;const f=c.substring(0,u),l=c.substring(u+i.length);f&&s.insertBefore(document.createTextNode(f),t);const a=new O(s,n[r]);e.parts.push(a);let p=t;return l&&(p=document.createTextNode(l),s.insertBefore(p,t)),s.removeChild(t),a.k=p!==t?p:null,void(l&&A(p,n,o,e,s))}}function M(t,n,o,e){const s=[...t.attributes];for(const c of s)for(let s=0;s<n.length;s++){const r=S(s);if(!c.value.includes(r))continue;const i=_(o,r);if("event"===i.type&&i.attrName===c.name){t.removeAttribute(c.name);const o=new j(t,c.name,n[s]);e.parts.push(o)}else if("attr"===i.type&&i.attrName===c.name){const o=c.value.replace(r,"");o?t.setAttribute(c.name,o):t.removeAttribute(c.name);const i=new v(t,c.name,n[s]);e.parts.push(i)}}J(t,n,o,e)}function C(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof k?n.push(C(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof k?n.push(e.map(t=>C(t)).join("")):x(e)?n.push(b(e.value)):"function"!=typeof e&&n.push(b(e??""))}return n.join("")}function F(t){const n=t.join("");let o=!1,e="",s=-1,c=!1;for(let t=0;t<n.length;t++){const r=n[t];o?r===e&&(o=!1):'"'===r||"'"===r?(o=!0,e=r):"<"===r?(s=t,c=!1):">"===r&&s>=0&&!o&&(c=!0)}return s>=0&&!c}function D(t,n,o,e){const s=[...t.childNodes];for(const c of s)8===c.nodeType?P(c,n,t,o,e):1===c.nodeType&&q(c,n,o,e)}function P(t,n,o,e,s){const c=s.indices[s.nextIdx++]??-1,r=t.previousSibling;let i;if(r&&3===r.nodeType?i=r:(i=document.createTextNode(""),o.insertBefore(i,t)),c>=0&&c<n.length){const t=n[c];if(x(t)){const n=y(()=>{i.textContent=null!=t.value?String(t.value):""});e.parts.push({destroy(){n(),i.remove()}})}else i.textContent=null!=t?String(t):""}o.removeChild(t)}function q(t,n,o,e){const s=t.getAttribute("data-kp");if(s){const e=s.split(",");for(const s of e){const e=s.indexOf(":"),c=s.indexOf(":",e+1),r=parseInt(s.substring(0,e),10),i=s.substring(e+1,c),u=s.substring(c+1);if(r>=0&&r<n.length)if("e"===i){const e=new j(t,u,n[r]);e.mount(),o.parts.push(e)}else if("a"===i){const e=new v(t,u,n[r]);e.mount(),o.parts.push(e)}}t.removeAttribute("data-kp")}D(t,n,o,e)}const I=new Map;function K(t){const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=d(t[o]));const o=Object.keys(n);return new Proxy({},{get(t,o){if("symbol"==typeof o)return;const e=n[o];return e?e.value:void 0},set(t,e,s){const c=n[e];return c?c.value=s:(n[e]=d(s),o.push(e)),!0},has:(t,o)=>o in n,ownKeys:()=>o,getOwnPropertyDescriptor(t,o){if(o in n)return{enumerable:!0,configurable:!0}}})}const T=new Map;function U(t,n){let o=T.get(t);return o||(o=new Function("__s__",`with(__s__){return(${t})}`),T.set(t,o)),o(n)}function z(t){const n=t.split("."),o=n[0],e=n.slice(1),s=o.indexOf(":");return-1===s?{base:o,arg:null,modifiers:e}:{base:o.substring(0,s),arg:o.substring(s+1),modifiers:e}}function B(t,n,o,e){const s=y(()=>{const e=U(n,o);t.style.display=e?"":"none"});e.push(s)}function E(t,n,o,e){const s=y(()=>{t.textContent=String(U(n,o)??"")});e.push(s)}function W(t,n,o,e){const s=y(()=>{t.innerHTML=String(U(n,o)??"")});e.push(s)}function G(t,n,o,e,s){const c=y(()=>{const s=U(n,e);!1===s||null==s?t.removeAttribute(o):!0===s?t.setAttribute(o,""):t.setAttribute(o,String(s))});s.push(c)}function H(t,n,o,s,c,r){const i=s.includes("stop"),u=s.includes("prevent"),f=s.includes("once"),l=s.includes("self"),a=o=>{l&&o.target!==t||(i&&o.stopPropagation(),u&&o.preventDefault(),function(t,n){const o="$$"+t;let e=T.get(o);e||(e=new Function("__s__",`with(__s__){${t}}`),T.set(o,e)),e(n)}(n,c),e())};t.addEventListener(o,a,{once:f}),r.push(()=>t.removeEventListener(o,a))}function L(t,n,o,s){const c=y(()=>{const e=U(n,o);t.value=null!=e?String(e):""});s.push(c);const r=()=>{const s=n.trim().split(".");if(1===s.length)o[s[0]]=t.value;else{const e=s.slice(0,-1).join("."),c=s[s.length-1];try{const n=U(e,o);n&&"object"==typeof n&&(n[c]=t.value)}catch(e){o[n]=t.value}}e()};t.addEventListener("input",r),s.push(()=>t.removeEventListener("input",r))}function Q(t){return t.startsWith("k-")||t.startsWith(":")||t.startsWith("@")}function R(t){return t.startsWith(":")?"k-bind:"+t.substring(1):t.startsWith("@")?"k-on:"+t.substring(1):t}function V(t,n,o){const e=[...t.attributes];for(const s of e){const e=s.name,c=s.value;if(!Q(e))continue;const r=R(e),{base:i,arg:u,modifiers:f}=z(r);switch(i){case"k-show":B(t,c,n,o);break;case"k-text":E(t,c,n,o);break;case"k-html":W(t,c,n,o);break;case"k-bind":u&&G(t,c,u,n,o);break;case"k-on":u&&H(t,c,u,f,n,o);break;case"k-model":L(t,c,n,o)}}}function X(t,n,o){for(const e of t.children)e.hasAttribute("k-data")||(V(e,n,o),X(e,n,o))}function Y(t,n){const o=t.getAttribute("k-data");let e={};try{e=U(o,K({}))||{}}catch(t){}const s=K(e);V(t,s,n),X(t,s,n);for(const o of t.children)o.hasAttribute("k-data")&&Y(o,n)}const Z={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data","datepicker.months":"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec","datepicker.weekdays":"Mo,Tu,We,Th,Fr,Sa,Su","timepicker.placeholder":"Select time"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","datepicker.months":"1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月","datepicker.weekdays":"一,二,三,四,五,六,日","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};let tt="en-US";exports.ErrorBoundary=function(t,n={}){const{fallback:o=null,onError:e=null}=n;try{return t()}catch(t){if(e)try{e(t)}catch(t){}const n=document.createDocumentFragment();if(o)try{const e="function"==typeof o?o(t):o;if("string"==typeof e){const t=document.createElement("div");t.className="ds-error-boundary",t.textContent=e,n.appendChild(t)}else $(e,n)}catch(o){const e=document.createElement("div");e.className="ds-error-boundary",e.textContent=`Component error: ${t.message}`,n.appendChild(e)}else{const o=document.createElement("div");o.className="ds-error-boundary",o.textContent=`Component error: ${t.message}`,n.appendChild(o)}return{element:n,error:t}}},exports.Signal=h,exports.TemplateResult=k,exports.addMessages=function(t,n){Z[t]||(Z[t]={}),Object.assign(Z[t],n)},exports.batch=function(t){l(u+1);try{return t()}finally{if(l(u-1),0===u){const t=f,n=[...t];t.clear();for(const t of n)t();e()}}},exports.clearRegistry=function(){I.clear()},exports.computed=function(t){const n=new h(void 0);let o=!0,e=new Set;const s={p:null,o:e,i:!0,u:null,h:!1};function c(){for(const t of e)t.t.delete(s);e.clear(),s.o=e,r(s);try{const o=t();Object.is(n.l,o)||(n.l=o)}finally{i()}o=!1}return s.u=()=>{o||(o=!0,p(n))},{get value(){return o&&c(),a(n),n.l},peek:()=>(o&&c(),n.l),toString(){return String(this.value)},toJSON(){return JSON.stringify(this.value)}}},exports.defineComponent=function(t){const{props:n=[],setup:o}=t;function e(t={},e=null){const s={};for(const o of n)s[o]=d(t[o]);const c=o(s,e)(),r=document.createDocumentFragment(),i=$(c,r);return{get element(){return r},_:i,destroy(){i.destroy()},update(t){for(const o of n)o in t&&s[o]&&(s[o].value=t[o])}}}return e.O=!0,e.v=n,e},exports.effect=y,exports.flushJobs=e,exports.getComponent=function(t){return I.get(t)},exports.getLocale=function(){return tt},exports.hasComponent=function(t){return I.has(t)},exports.html=function(t,...n){return new k(t,n)},exports.hydrate=function(t,n){const o=new N,e=function(t){const n=[],o=[];let e=!1;for(let s=0;s<t.strings.length;s++)if(o.push(t.strings[s]),e=F(o),s<t.values.length){const c=t.values[s];if(c instanceof k)o.push(C(c));else if(Array.isArray(c)&&c.length>0&&c[0]instanceof k)o.push(c.map(t=>C(t)).join(""));else if("function"==typeof c);else if(x(c))if(e){const t=c.value;o.push(null!=t?b(t):"")}else{n.push(s);const t=c.value;o.push(null!=t?b(t):"")}else o.push(b(c??""))}return{indices:n,nextIdx:0}}(t);return D(n,t.values,o,e),o},exports.register=function(t,n){I.set(t,n)},exports.render=$,exports.resetScheduler=function(){t.clear(),n=!1},exports.setLocale=function(t){tt=t},exports.signal=d,exports.t=function(t,n={}){let o=(Z[tt]||Z["en-US"])[t]||t;for(const[t,e]of Object.entries(n))o=o.replace(`{${t}}`,e);return o},exports.walk=function(t){const n=[];if(t.hasAttribute&&t.hasAttribute("k-data"))Y(t,n);else{const o=t.querySelectorAll?t.querySelectorAll("[k-data]"):[];if(o.length>0)for(const e of o){let o=!1,s=e.parentElement;for(;s&&s!==t;){if(s.hasAttribute("k-data")){o=!0;break}s=s.parentElement}o||Y(e,n)}else{const o=K({});for(const e of t.children)V(e,o,n),X(e,o,n)}}return{destroy(){for(const t of n)t();n.length=0}}};
|
package/dist/kupola-core.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=new Set;let n=!1;function o(o){t.add(o),n||(n=!0,queueMicrotask(e))}function e(){for(n=!1;t.size>0;){const n=[...t];t.clear();for(const t of n)t()}}function s(){t.clear(),n=!1}let c=null;const i=[];function r(t){i.push(c),c=t}function f(){c=i.pop()??null}let u=0;const l=new Set;function a(t){u=t}function h(t){c&&(t.t.add(c),c.o.add(t))}function p(t){for(const n of t.t)n.i?n.u():u>0?l.add(n.u):o(n.u)}class d{constructor(t){this.l=t,this.t=new Set}get value(){return h(this),this.l}set value(t){Object.is(this.l,t)||(this.l=t,p(this))}peek(){return this.l}toString(){return String(this.l)}toJSON(){return JSON.stringify(this.l)}}function y(t){return new d(t)}function g(t){const n=new d(void 0);let o=!0,e=new Set;const s={h:null,o:e,i:!0,u:null,p:!1};function c(){for(const t of e)t.t.delete(s);e.clear(),s.o=e,r(s);try{const o=t();Object.is(n.l,o)||(n.l=o)}finally{f()}o=!1}return s.u=()=>{o||(o=!0,p(n))},{get value(){return o&&c(),h(n),n.l},peek:()=>(o&&c(),n.l),toString(){return String(this.value)},toJSON(){return JSON.stringify(this.value)}}}function k(t){const n={h:t,o:new Set,u:null,p:!1};return n.u=()=>{n.p||m(n)},m(n),()=>function(t){if(t.p)return;t.p=!0,w(t)}(n)}function m(t){w(t),r(t);try{t.h()}finally{f()}}function w(t){for(const n of t.o)n.t.delete(t);t.o.clear()}function b(t){a(u+1);try{return t()}finally{if(a(u-1),0===u){const t=l,n=[...t];t.clear();for(const t of n)t();e()}}}class S{constructor(t,n){this.strings=t,this.values=n}}function _(t,...n){return new S(t,n)}function O(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function x(t){if(null==t||"object"!=typeof t)return!1;const n=Object.getOwnPropertyDescriptor(t,"value");if(n&&"function"==typeof n.get)return!0;const o=Object.getPrototypeOf(t);if(o){const t=Object.getOwnPropertyDescriptor(o,"value");if(t&&"function"==typeof t.get)return!0}return!1}const j=t=>`${t}`;function v(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof S?n.push(v(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof S?n.push(e.map(v).join("")):x(e)?n.push(O(e.value)):"function"!=typeof e&&n.push(O(e??""))}return n.join("")}function N(t,n){const o=t.indexOf(n);if(-1===o)return{type:"text"};const e=t.substring(0,o).lastIndexOf("<");if(-1===e)return{type:"text"};if(t.substring(e,o).includes(">"))return{type:"text"};const s=t.substring(e+1,o).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!s)return{type:"text"};const c=s[1];return c.startsWith("on")&&c.length>2?{type:"event",attrName:c}:{type:"attr",attrName:c}}class ${constructor(t,n){this.container=t,this.rawValue=n,this.node=null,this.k=null}mount(){const t=document.createTextNode("");if(this.m?this.container.insertBefore(t,this.m):this.container.appendChild(t),this.node=t,x(this.rawValue)){const t=this.rawValue;this.k=k(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof S?this.node.textContent=v(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.k?.(),this.node?.remove()}}class A{constructor(t,n,o){this.element=t,this.attrName=n,this.rawValue=o,this.k=null}mount(){if(x(this.rawValue)){const t=this.rawValue;this.k=k(()=>{const n=t.value;null==n||!1===n?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(n))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.k?.()}}class J{constructor(t,n,o){this.element=t,this.eventName=n.slice(2).toLowerCase(),this.handler=o,this.S=null}mount(){"function"==typeof this.handler&&(this.S=t=>this.handler(t),this.element.addEventListener(this.eventName,this.S))}destroy(){this.S&&(this.element.removeEventListener(this.eventName,this.S),this.S=null)}}class C{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function M(t,n){const o=new C,e=function(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof S?n.push(v(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof S?n.push(e.map(v).join("")):"function"==typeof e||x(e)?n.push(j(o)):n.push(O(e??""))}return n.join("")}(t),s=function(t){const n=document.createElement("template");return n.innerHTML=t,n.content}(e);o.fragment=s,P(s,t.values,e,o);for(const t of o.parts)t.mount();return n.appendChild(s),o}function P(t,n,o,e){const s=[...t.childNodes];for(const c of s)3===c.nodeType?q(c,n,o,e,t):1===c.nodeType&&D(c,n,o,e)}function q(t,n,o,e,s){const c=t.textContent||"";for(let i=0;i<n.length;i++){const r=j(i),f=c.indexOf(r);if(-1===f)continue;if("text"!==N(o,r).type)continue;const u=c.substring(0,f),l=c.substring(f+r.length);u&&s.insertBefore(document.createTextNode(u),t);const a=new $(s,n[i]);e.parts.push(a);let h=t;return l&&(h=document.createTextNode(l),s.insertBefore(h,t)),s.removeChild(t),a.m=h!==t?h:null,void(l&&q(h,n,o,e,s))}}function D(t,n,o,e){const s=[...t.attributes];for(const c of s)for(let s=0;s<n.length;s++){const i=j(s);if(!c.value.includes(i))continue;const r=N(o,i);if("event"===r.type&&r.attrName===c.name){t.removeAttribute(c.name);const o=new J(t,c.name,n[s]);e.parts.push(o)}else if("attr"===r.type&&r.attrName===c.name){const o=c.value.replace(i,"");o?t.setAttribute(c.name,o):t.removeAttribute(c.name);const r=new A(t,c.name,n[s]);e.parts.push(r)}}P(t,n,o,e)}function F(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof S?n.push(F(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof S?n.push(e.map(t=>F(t)).join("")):x(e)?n.push(O(e.value)):"function"!=typeof e&&n.push(O(e??""))}return n.join("")}function I(t){const n=t.join("");let o=!1,e="",s=-1,c=!1;for(let t=0;t<n.length;t++){const i=n[t];o?i===e&&(o=!1):'"'===i||"'"===i?(o=!0,e=i):"<"===i?(s=t,c=!1):">"===i&&s>=0&&!o&&(c=!0)}return s>=0&&!c}function K(t,n){const o=new C,e=function(t){const n=[],o=[];let e=!1;for(let s=0;s<t.strings.length;s++)if(o.push(t.strings[s]),e=I(o),s<t.values.length){const c=t.values[s];if(c instanceof S)o.push(F(c));else if(Array.isArray(c)&&c.length>0&&c[0]instanceof S)o.push(c.map(t=>F(t)).join(""));else if("function"==typeof c);else if(x(c))if(e){const t=c.value;o.push(null!=t?O(t):"")}else{n.push(s);const t=c.value;o.push(null!=t?O(t):"")}else o.push(O(c??""))}return{indices:n,nextIdx:0}}(t);return U(n,t.values,o,e),o}function U(t,n,o,e){const s=[...t.childNodes];for(const c of s)8===c.nodeType?z(c,n,t,o,e):1===c.nodeType&&B(c,n,o,e)}function z(t,n,o,e,s){const c=s.indices[s.nextIdx++]??-1,i=t.previousSibling;let r;if(i&&3===i.nodeType?r=i:(r=document.createTextNode(""),o.insertBefore(r,t)),c>=0&&c<n.length){const t=n[c];if(x(t)){const n=k(()=>{r.textContent=null!=t.value?String(t.value):""});e.parts.push({destroy(){n(),r.remove()}})}else r.textContent=null!=t?String(t):""}o.removeChild(t)}function B(t,n,o,e){const s=t.getAttribute("data-kp");if(s){const e=s.split(",");for(const s of e){const e=s.indexOf(":"),c=s.indexOf(":",e+1),i=parseInt(s.substring(0,e),10),r=s.substring(e+1,c),f=s.substring(c+1);if(i>=0&&i<n.length)if("e"===r){const e=new J(t,f,n[i]);e.mount(),o.parts.push(e)}else if("a"===r){const e=new A(t,f,n[i]);e.mount(),o.parts.push(e)}}t.removeAttribute("data-kp")}U(t,n,o,e)}function E(t){const{props:n=[],setup:o}=t;function e(t={},e=null){const s={};for(const o of n)s[o]=y(t[o]);const c=o(s,e)(),i=document.createDocumentFragment(),r=M(c,i);return{get element(){return i},_:r,destroy(){r.destroy()},update(t){for(const o of n)o in t&&s[o]&&(s[o].value=t[o])}}}return e.O=!0,e.j=n,e}const G=new Map;function H(t,n){G.set(t,n)}function L(t){return G.get(t)}function Q(t){return G.has(t)}function R(){G.clear()}function T(t){const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=y(t[o]));const o=Object.keys(n);return new Proxy({},{get(t,o){if("symbol"==typeof o)return;const e=n[o];return e?e.value:void 0},set(t,e,s){const c=n[e];return c?c.value=s:(n[e]=y(s),o.push(e)),!0},has:(t,o)=>o in n,ownKeys:()=>o,getOwnPropertyDescriptor(t,o){if(o in n)return{enumerable:!0,configurable:!0}}})}const V=new Map;function W(t,n){let o=V.get(t);return o||(o=new Function("__s__",`with(__s__){return(${t})}`),V.set(t,o)),o(n)}function X(t){const n=t.split("."),o=n[0],e=n.slice(1),s=o.indexOf(":");return-1===s?{base:o,arg:null,modifiers:e}:{base:o.substring(0,s),arg:o.substring(s+1),modifiers:e}}function Y(t,n,o,e){const s=k(()=>{const e=W(n,o);t.style.display=e?"":"none"});e.push(s)}function Z(t,n,o,e){const s=k(()=>{t.textContent=String(W(n,o)??"")});e.push(s)}function tt(t,n,o,e){const s=k(()=>{t.innerHTML=String(W(n,o)??"")});e.push(s)}function nt(t,n,o,e,s){const c=k(()=>{const s=W(n,e);!1===s||null==s?t.removeAttribute(o):!0===s?t.setAttribute(o,""):t.setAttribute(o,String(s))});s.push(c)}function ot(t,n,o,s,c,i){const r=s.includes("stop"),f=s.includes("prevent"),u=s.includes("once"),l=s.includes("self"),a=o=>{l&&o.target!==t||(r&&o.stopPropagation(),f&&o.preventDefault(),function(t,n){const o="$$"+t;let e=V.get(o);e||(e=new Function("__s__",`with(__s__){${t}}`),V.set(o,e)),e(n)}(n,c),e())};t.addEventListener(o,a,{once:u}),i.push(()=>t.removeEventListener(o,a))}function et(t,n,o,s){const c=k(()=>{const e=W(n,o);t.value=null!=e?String(e):""});s.push(c);const i=()=>{const s=n.trim().split(".");if(1===s.length)o[s[0]]=t.value;else{const e=s.slice(0,-1).join("."),c=s[s.length-1];try{const n=W(e,o);n&&"object"==typeof n&&(n[c]=t.value)}catch(e){o[n]=t.value}}e()};t.addEventListener("input",i),s.push(()=>t.removeEventListener("input",i))}function st(t){return t.startsWith("k-")||t.startsWith(":")||t.startsWith("@")}function ct(t){return t.startsWith(":")?"k-bind:"+t.substring(1):t.startsWith("@")?"k-on:"+t.substring(1):t}function it(t,n,o){const e=[...t.attributes];for(const s of e){const e=s.name,c=s.value;if(!st(e))continue;const i=ct(e),{base:r,arg:f,modifiers:u}=X(i);switch(r){case"k-show":Y(t,c,n,o);break;case"k-text":Z(t,c,n,o);break;case"k-html":tt(t,c,n,o);break;case"k-bind":f&&nt(t,c,f,n,o);break;case"k-on":f&&ot(t,c,f,u,n,o);break;case"k-model":et(t,c,n,o)}}}function rt(t,n,o){for(const e of t.children)e.hasAttribute("k-data")||(it(e,n,o),rt(e,n,o))}function ft(t,n){const o=t.getAttribute("k-data");let e={};try{e=W(o,T({}))||{}}catch(t){}const s=T(e);it(t,s,n),rt(t,s,n);for(const o of t.children)o.hasAttribute("k-data")&&ft(o,n)}function ut(t){const n=[];if(t.hasAttribute&&t.hasAttribute("k-data"))ft(t,n);else{const o=t.querySelectorAll?t.querySelectorAll("[k-data]"):[];if(o.length>0)for(const e of o){let o=!1,s=e.parentElement;for(;s&&s!==t;){if(s.hasAttribute("k-data")){o=!0;break}s=s.parentElement}o||ft(e,n)}else{const o=T({});for(const e of t.children)it(e,o,n),rt(e,o,n)}}return{destroy(){for(const t of n)t();n.length=0}}}const lt={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};let at="en-US";function ht(t){at=t}function pt(){return at}function dt(t,n={}){let o=(lt[at]||lt["en-US"])[t]||t;for(const[t,e]of Object.entries(n))o=o.replace(`{${t}}`,e);return o}function yt(t,n){lt[t]||(lt[t]={}),Object.assign(lt[t],n)}export{d as Signal,S as TemplateResult,yt as addMessages,b as batch,R as clearRegistry,g as computed,E as defineComponent,k as effect,e as flushJobs,L as getComponent,pt as getLocale,Q as hasComponent,_ as html,K as hydrate,H as register,M as render,s as resetScheduler,ht as setLocale,y as signal,dt as t,ut as walk};
|
|
1
|
+
const t=new Set;let n=!1;function o(o){t.add(o),n||(n=!0,queueMicrotask(e))}function e(){for(n=!1;t.size>0;){const n=[...t];t.clear();for(const t of n)t()}}function c(){t.clear(),n=!1}let s=null;const i=[];function r(t){i.push(s),s=t}function f(){s=i.pop()??null}let u=0;const l=new Set;function a(t){u=t}function h(t){s&&(t.t.add(s),s.o.add(t))}function d(t){for(const n of t.t)n.i?n.u():u>0?l.add(n.u):o(n.u)}class p{constructor(t){this.l=t,this.t=new Set}get value(){return h(this),this.l}set value(t){Object.is(this.l,t)||(this.l=t,d(this))}peek(){return this.l}toString(){return String(this.l)}toJSON(){return JSON.stringify(this.l)}}function y(t){return new p(t)}function g(t){const n=new p(void 0);let o=!0,e=new Set;const c={h:null,o:e,i:!0,u:null,p:!1};function s(){for(const t of e)t.t.delete(c);e.clear(),c.o=e,r(c);try{const o=t();Object.is(n.l,o)||(n.l=o)}finally{f()}o=!1}return c.u=()=>{o||(o=!0,d(n))},{get value(){return o&&s(),h(n),n.l},peek:()=>(o&&s(),n.l),toString(){return String(this.value)},toJSON(){return JSON.stringify(this.value)}}}function m(t){const n={h:t,o:new Set,u:null,p:!1};return n.u=()=>{n.p||k(n)},k(n),()=>function(t){if(t.p)return;t.p=!0,b(t)}(n)}function k(t){b(t),r(t);try{t.h()}finally{f()}}function b(t){for(const n of t.o)n.t.delete(t);t.o.clear()}function S(t){a(u+1);try{return t()}finally{if(a(u-1),0===u){const t=l,n=[...t];t.clear();for(const t of n)t();e()}}}class w{constructor(t,n){this.strings=t,this.values=n}}function _(t,...n){return new w(t,n)}function O(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function v(t){if(null==t||"object"!=typeof t)return!1;const n=Object.getOwnPropertyDescriptor(t,"value");if(n&&"function"==typeof n.get)return!0;const o=Object.getPrototypeOf(t);if(o){const t=Object.getOwnPropertyDescriptor(o,"value");if(t&&"function"==typeof t.get)return!0}return!1}const x=t=>`${t}`;function j(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof w?n.push(j(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof w?n.push(e.map(j).join("")):v(e)?n.push(O(e.value)):"function"!=typeof e&&n.push(O(e??""))}return n.join("")}function N(t,n){const o=t.indexOf(n);if(-1===o)return{type:"text"};const e=t.substring(0,o).lastIndexOf("<");if(-1===e)return{type:"text"};if(t.substring(e,o).includes(">"))return{type:"text"};const c=t.substring(e+1,o).match(/([\w\-@:.]+)\s*=\s*(?:"[^"]*|'[^']*|[^\s>]*?)$/);if(!c)return{type:"text"};const s=c[1];return s.startsWith("on")&&s.length>2?{type:"event",attrName:s}:{type:"attr",attrName:s}}class ${constructor(t,n){this.container=t,this.rawValue=n,this.node=null,this.m=null}mount(){const t=document.createTextNode("");if(this.k?this.container.insertBefore(t,this.k):this.container.appendChild(t),this.node=t,v(this.rawValue)){const t=this.rawValue;this.m=m(()=>{this.node.textContent=null!=t.value?String(t.value):""})}else this.rawValue instanceof w?this.node.textContent=j(this.rawValue):this.node.textContent=null!=this.rawValue?String(this.rawValue):""}destroy(){this.m?.(),this.node?.remove()}}class J{constructor(t,n,o){this.element=t,this.attrName=n,this.rawValue=o,this.m=null}mount(){if(v(this.rawValue)){const t=this.rawValue;this.m=m(()=>{const n=t.value;null==n||!1===n?this.element.removeAttribute(this.attrName):this.element.setAttribute(this.attrName,String(n))})}else null!=this.rawValue&&!1!==this.rawValue&&this.element.setAttribute(this.attrName,String(this.rawValue))}destroy(){this.m?.()}}class A{constructor(t,n,o){this.element=t,this.eventName=n.slice(2).toLowerCase(),this.handler=o,this.S=null}mount(){"function"==typeof this.handler&&(this.S=t=>this.handler(t),this.element.addEventListener(this.eventName,this.S))}destroy(){this.S&&(this.element.removeEventListener(this.eventName,this.S),this.S=null)}}class M{constructor(){this.parts=[],this.fragment=null}destroy(){for(const t of this.parts)t.destroy();this.parts.length=0}}function C(t,n){const o=new M,e=function(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof w?n.push(j(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof w?n.push(e.map(j).join("")):"function"==typeof e||v(e)?n.push(x(o)):n.push(O(e??""))}return n.join("")}(t),c=function(t){const n=document.createElement("template");return n.innerHTML=t,n.content}(e);o.fragment=c,F(c,t.values,e,o);for(const t of o.parts)t.mount();return n.appendChild(c),o}function F(t,n,o,e){const c=[...t.childNodes];for(const s of c)3===s.nodeType?D(s,n,o,e,t):1===s.nodeType&&P(s,n,o,e)}function D(t,n,o,e,c){const s=t.textContent||"";for(let i=0;i<n.length;i++){const r=x(i),f=s.indexOf(r);if(-1===f)continue;if("text"!==N(o,r).type)continue;const u=s.substring(0,f),l=s.substring(f+r.length);u&&c.insertBefore(document.createTextNode(u),t);const a=new $(c,n[i]);e.parts.push(a);let h=t;return l&&(h=document.createTextNode(l),c.insertBefore(h,t)),c.removeChild(t),a.k=h!==t?h:null,void(l&&D(h,n,o,e,c))}}function P(t,n,o,e){const c=[...t.attributes];for(const s of c)for(let c=0;c<n.length;c++){const i=x(c);if(!s.value.includes(i))continue;const r=N(o,i);if("event"===r.type&&r.attrName===s.name){t.removeAttribute(s.name);const o=new A(t,s.name,n[c]);e.parts.push(o)}else if("attr"===r.type&&r.attrName===s.name){const o=s.value.replace(i,"");o?t.setAttribute(s.name,o):t.removeAttribute(s.name);const r=new J(t,s.name,n[c]);e.parts.push(r)}}F(t,n,o,e)}function q(t){const n=[];for(let o=0;o<t.strings.length;o++)if(n.push(t.strings[o]),o<t.values.length){const e=t.values[o];e instanceof w?n.push(q(e)):Array.isArray(e)&&e.length>0&&e[0]instanceof w?n.push(e.map(t=>q(t)).join("")):v(e)?n.push(O(e.value)):"function"!=typeof e&&n.push(O(e??""))}return n.join("")}function I(t){const n=t.join("");let o=!1,e="",c=-1,s=!1;for(let t=0;t<n.length;t++){const i=n[t];o?i===e&&(o=!1):'"'===i||"'"===i?(o=!0,e=i):"<"===i?(c=t,s=!1):">"===i&&c>=0&&!o&&(s=!0)}return c>=0&&!s}function K(t,n){const o=new M,e=function(t){const n=[],o=[];let e=!1;for(let c=0;c<t.strings.length;c++)if(o.push(t.strings[c]),e=I(o),c<t.values.length){const s=t.values[c];if(s instanceof w)o.push(q(s));else if(Array.isArray(s)&&s.length>0&&s[0]instanceof w)o.push(s.map(t=>q(t)).join(""));else if("function"==typeof s);else if(v(s))if(e){const t=s.value;o.push(null!=t?O(t):"")}else{n.push(c);const t=s.value;o.push(null!=t?O(t):"")}else o.push(O(s??""))}return{indices:n,nextIdx:0}}(t);return T(n,t.values,o,e),o}function T(t,n,o,e){const c=[...t.childNodes];for(const s of c)8===s.nodeType?U(s,n,t,o,e):1===s.nodeType&&z(s,n,o,e)}function U(t,n,o,e,c){const s=c.indices[c.nextIdx++]??-1,i=t.previousSibling;let r;if(i&&3===i.nodeType?r=i:(r=document.createTextNode(""),o.insertBefore(r,t)),s>=0&&s<n.length){const t=n[s];if(v(t)){const n=m(()=>{r.textContent=null!=t.value?String(t.value):""});e.parts.push({destroy(){n(),r.remove()}})}else r.textContent=null!=t?String(t):""}o.removeChild(t)}function z(t,n,o,e){const c=t.getAttribute("data-kp");if(c){const e=c.split(",");for(const c of e){const e=c.indexOf(":"),s=c.indexOf(":",e+1),i=parseInt(c.substring(0,e),10),r=c.substring(e+1,s),f=c.substring(s+1);if(i>=0&&i<n.length)if("e"===r){const e=new A(t,f,n[i]);e.mount(),o.parts.push(e)}else if("a"===r){const e=new J(t,f,n[i]);e.mount(),o.parts.push(e)}}t.removeAttribute("data-kp")}T(t,n,o,e)}function B(t){const{props:n=[],setup:o}=t;function e(t={},e=null){const c={};for(const o of n)c[o]=y(t[o]);const s=o(c,e)(),i=document.createDocumentFragment(),r=C(s,i);return{get element(){return i},_:r,destroy(){r.destroy()},update(t){for(const o of n)o in t&&c[o]&&(c[o].value=t[o])}}}return e.O=!0,e.v=n,e}const E=new Map;function W(t,n){E.set(t,n)}function G(t){return E.get(t)}function H(t){return E.has(t)}function L(){E.clear()}function Q(t){const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=y(t[o]));const o=Object.keys(n);return new Proxy({},{get(t,o){if("symbol"==typeof o)return;const e=n[o];return e?e.value:void 0},set(t,e,c){const s=n[e];return s?s.value=c:(n[e]=y(c),o.push(e)),!0},has:(t,o)=>o in n,ownKeys:()=>o,getOwnPropertyDescriptor(t,o){if(o in n)return{enumerable:!0,configurable:!0}}})}const R=new Map;function V(t,n){let o=R.get(t);return o||(o=new Function("__s__",`with(__s__){return(${t})}`),R.set(t,o)),o(n)}function X(t){const n=t.split("."),o=n[0],e=n.slice(1),c=o.indexOf(":");return-1===c?{base:o,arg:null,modifiers:e}:{base:o.substring(0,c),arg:o.substring(c+1),modifiers:e}}function Y(t,n,o,e){const c=m(()=>{const e=V(n,o);t.style.display=e?"":"none"});e.push(c)}function Z(t,n,o,e){const c=m(()=>{t.textContent=String(V(n,o)??"")});e.push(c)}function tt(t,n,o,e){const c=m(()=>{t.innerHTML=String(V(n,o)??"")});e.push(c)}function nt(t,n,o,e,c){const s=m(()=>{const c=V(n,e);!1===c||null==c?t.removeAttribute(o):!0===c?t.setAttribute(o,""):t.setAttribute(o,String(c))});c.push(s)}function ot(t,n,o,c,s,i){const r=c.includes("stop"),f=c.includes("prevent"),u=c.includes("once"),l=c.includes("self"),a=o=>{l&&o.target!==t||(r&&o.stopPropagation(),f&&o.preventDefault(),function(t,n){const o="$$"+t;let e=R.get(o);e||(e=new Function("__s__",`with(__s__){${t}}`),R.set(o,e)),e(n)}(n,s),e())};t.addEventListener(o,a,{once:u}),i.push(()=>t.removeEventListener(o,a))}function et(t,n,o,c){const s=m(()=>{const e=V(n,o);t.value=null!=e?String(e):""});c.push(s);const i=()=>{const c=n.trim().split(".");if(1===c.length)o[c[0]]=t.value;else{const e=c.slice(0,-1).join("."),s=c[c.length-1];try{const n=V(e,o);n&&"object"==typeof n&&(n[s]=t.value)}catch(e){o[n]=t.value}}e()};t.addEventListener("input",i),c.push(()=>t.removeEventListener("input",i))}function ct(t){return t.startsWith("k-")||t.startsWith(":")||t.startsWith("@")}function st(t){return t.startsWith(":")?"k-bind:"+t.substring(1):t.startsWith("@")?"k-on:"+t.substring(1):t}function it(t,n,o){const e=[...t.attributes];for(const c of e){const e=c.name,s=c.value;if(!ct(e))continue;const i=st(e),{base:r,arg:f,modifiers:u}=X(i);switch(r){case"k-show":Y(t,s,n,o);break;case"k-text":Z(t,s,n,o);break;case"k-html":tt(t,s,n,o);break;case"k-bind":f&&nt(t,s,f,n,o);break;case"k-on":f&&ot(t,s,f,u,n,o);break;case"k-model":et(t,s,n,o)}}}function rt(t,n,o){for(const e of t.children)e.hasAttribute("k-data")||(it(e,n,o),rt(e,n,o))}function ft(t,n){const o=t.getAttribute("k-data");let e={};try{e=V(o,Q({}))||{}}catch(t){}const c=Q(e);it(t,c,n),rt(t,c,n);for(const o of t.children)o.hasAttribute("k-data")&&ft(o,n)}function ut(t){const n=[];if(t.hasAttribute&&t.hasAttribute("k-data"))ft(t,n);else{const o=t.querySelectorAll?t.querySelectorAll("[k-data]"):[];if(o.length>0)for(const e of o){let o=!1,c=e.parentElement;for(;c&&c!==t;){if(c.hasAttribute("k-data")){o=!0;break}c=c.parentElement}o||ft(e,n)}else{const o=Q({});for(const e of t.children)it(e,o,n),rt(e,o,n)}}return{destroy(){for(const t of n)t();n.length=0}}}const lt={"en-US":{"modal.close":"Close","dialog.ok":"OK","dialog.cancel":"Cancel","table.empty":"No data","pagination.page":"Page","pagination.of":"of","select.placeholder":"Select...","datepicker.placeholder":"Select date","timepicker.placeholder":"Select time","fileupload.drag":"Drag files here or","fileupload.browse":"Browse","empty.text":"No data","datepicker.months":"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec","datepicker.weekdays":"Mo,Tu,We,Th,Fr,Sa,Su","timepicker.placeholder":"Select time"},"zh-CN":{"modal.close":"关闭","dialog.ok":"确定","dialog.cancel":"取消","table.empty":"暂无数据","pagination.page":"页","pagination.of":"/","select.placeholder":"请选择","datepicker.placeholder":"选择日期","datepicker.months":"1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月","datepicker.weekdays":"一,二,三,四,五,六,日","timepicker.placeholder":"选择时间","fileupload.drag":"拖拽文件到此处或","fileupload.browse":"浏览","empty.text":"暂无数据"}};let at="en-US";function ht(t){at=t}function dt(){return at}function pt(t,n={}){let o=(lt[at]||lt["en-US"])[t]||t;for(const[t,e]of Object.entries(n))o=o.replace(`{${t}}`,e);return o}function yt(t,n){lt[t]||(lt[t]={}),Object.assign(lt[t],n)}function gt(t,n={}){const{fallback:o=null,onError:e=null}=n;try{return t()}catch(t){if(e)try{e(t)}catch(t){}const n=document.createDocumentFragment();if(o)try{const e="function"==typeof o?o(t):o;if("string"==typeof e){const t=document.createElement("div");t.className="ds-error-boundary",t.textContent=e,n.appendChild(t)}else C(e,n)}catch(o){const e=document.createElement("div");e.className="ds-error-boundary",e.textContent=`Component error: ${t.message}`,n.appendChild(e)}else{const o=document.createElement("div");o.className="ds-error-boundary",o.textContent=`Component error: ${t.message}`,n.appendChild(o)}return{element:n,error:t}}}export{gt as ErrorBoundary,p as Signal,w as TemplateResult,yt as addMessages,S as batch,L as clearRegistry,g as computed,B as defineComponent,m as effect,e as flushJobs,G as getComponent,dt as getLocale,H as hasComponent,_ as html,K as hydrate,W as register,C as render,c as resetScheduler,ht as setLocale,y as signal,pt as t,ut as walk};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kupola/kupola",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "A modern, modular UI component library for any web project. Zero framework dependencies, tree-shakeable imports. 这是一个现代、模块化的 UI 组件库,适用于任何 Web 项目。零框架依赖,支持按需引入(tree-shakeable)。",
|
|
5
5
|
"main": "dist/kupola-core.esm.js",
|
|
6
6
|
"module": "dist/kupola-core.esm.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { html } from '../template.js';
|
|
22
22
|
import { render } from '../render.js';
|
|
23
|
+
import { t } from '../i18n.js';
|
|
23
24
|
|
|
24
25
|
const MONTHS = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
|
|
25
26
|
const WEEKDAYS = [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ];
|
|
@@ -39,7 +40,7 @@ const WEEKDAYS = [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ];
|
|
|
39
40
|
*/
|
|
40
41
|
export function Datepicker(options = {}) {
|
|
41
42
|
const {
|
|
42
|
-
placeholder =
|
|
43
|
+
placeholder = null,
|
|
43
44
|
format = 'YYYY-MM-DD',
|
|
44
45
|
value: initialValue = '',
|
|
45
46
|
weekStart = 1,
|
|
@@ -48,6 +49,10 @@ export function Datepicker(options = {}) {
|
|
|
48
49
|
onChange = null,
|
|
49
50
|
} = options;
|
|
50
51
|
|
|
52
|
+
const _placeholder = placeholder || t('datepicker.placeholder');
|
|
53
|
+
const _MONTHS = t('datepicker.months').split(',');
|
|
54
|
+
const _WEEKDAYS = t('datepicker.weekdays').split(',');
|
|
55
|
+
|
|
51
56
|
let _isOpen = false;
|
|
52
57
|
let _viewYear = new Date().getFullYear();
|
|
53
58
|
let _viewMonth = new Date().getMonth();
|
|
@@ -247,7 +252,7 @@ export function Datepicker(options = {}) {
|
|
|
247
252
|
// Update title
|
|
248
253
|
const titleEl = calEl.querySelector('.ds-datepicker__title');
|
|
249
254
|
if (titleEl) {
|
|
250
|
-
titleEl.textContent = `${
|
|
255
|
+
titleEl.textContent = `${_MONTHS[_viewMonth]} ${_viewYear}`;
|
|
251
256
|
}
|
|
252
257
|
|
|
253
258
|
// Update days grid
|
|
@@ -305,7 +310,7 @@ export function Datepicker(options = {}) {
|
|
|
305
310
|
// ── Render ─────────────────────────────────────────────────────────────────
|
|
306
311
|
|
|
307
312
|
const displayValue = _selectedDate ? _formatDate(_selectedDate) : '';
|
|
308
|
-
const titleText = `${
|
|
313
|
+
const titleText = `${_MONTHS[_viewMonth]} ${_viewYear}`;
|
|
309
314
|
|
|
310
315
|
// Adjusted weekday labels based on weekStart
|
|
311
316
|
const adjustedWeekdays = [];
|
|
@@ -317,8 +322,8 @@ export function Datepicker(options = {}) {
|
|
|
317
322
|
}
|
|
318
323
|
// Simplify: just use the standard order based on weekStart
|
|
319
324
|
const wdLabels = weekStart === 1
|
|
320
|
-
?
|
|
321
|
-
: [
|
|
325
|
+
? _WEEKDAYS
|
|
326
|
+
: [ _WEEKDAYS[6], ..._WEEKDAYS.slice(0, 6) ];
|
|
322
327
|
|
|
323
328
|
const weekdaySpans = wdLabels.map((d) => html`<span>${d}</span>`);
|
|
324
329
|
|
|
@@ -328,7 +333,7 @@ export function Datepicker(options = {}) {
|
|
|
328
333
|
const tpl = html`
|
|
329
334
|
<div class="ds-datepicker">
|
|
330
335
|
<div class="ds-datepicker__input-wrap" onclick="${onInputClick}">
|
|
331
|
-
<input class="ds-datepicker__input" type="text" readonly placeholder="${
|
|
336
|
+
<input class="ds-datepicker__input" type="text" readonly placeholder="${_placeholder}" value="${displayValue}" />
|
|
332
337
|
<button class="ds-datepicker__icon" onclick="${onIconClick}">
|
|
333
338
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
334
339
|
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/>
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
import { html } from '../template.js';
|
|
24
24
|
import { render } from '../render.js';
|
|
25
|
+
import { t } from '../i18n.js';
|
|
25
26
|
|
|
26
27
|
const ICONS = {
|
|
27
28
|
success: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',
|
|
@@ -48,10 +49,12 @@ function confirm(options = {}) {
|
|
|
48
49
|
title = '',
|
|
49
50
|
content = '',
|
|
50
51
|
type = 'normal',
|
|
51
|
-
confirmText =
|
|
52
|
-
cancelText =
|
|
52
|
+
confirmText = null,
|
|
53
|
+
cancelText = null,
|
|
53
54
|
showCancel = true,
|
|
54
55
|
} = options;
|
|
56
|
+
const _confirmText = confirmText || t('dialog.ok');
|
|
57
|
+
const _cancelText = cancelText || t('dialog.cancel');
|
|
55
58
|
|
|
56
59
|
return new Promise((resolve) => {
|
|
57
60
|
const iconHtml = ICONS[type] || ICONS.normal;
|
|
@@ -79,13 +82,13 @@ function confirm(options = {}) {
|
|
|
79
82
|
|
|
80
83
|
const tpl = html`
|
|
81
84
|
<div class="ds-modal-mask">
|
|
82
|
-
<div class="ds-dialog">
|
|
85
|
+
<div class="ds-dialog" role="alertdialog" aria-modal="true" aria-labelledby="dialog-title" aria-describedby="dialog-content" tabindex="-1">
|
|
83
86
|
<div class="ds-dialog__icon ds-dialog__icon--${type}">${iconHtml}</div>
|
|
84
|
-
<div class="ds-dialog__title">${title}</div>
|
|
85
|
-
<div class="ds-dialog__content">${content}</div>
|
|
87
|
+
<div class="ds-dialog__title" id="dialog-title">${title}</div>
|
|
88
|
+
<div class="ds-dialog__content" id="dialog-content">${content}</div>
|
|
86
89
|
<div class="ds-dialog__actions">
|
|
87
|
-
${showCancel ? html`<button class="ds-btn ds-btn--ghost" data-action="cancel">${
|
|
88
|
-
<button class="ds-btn ds-btn--primary" data-action="confirm">${
|
|
90
|
+
${showCancel ? html`<button class="ds-btn ds-btn--ghost" data-action="cancel" type="button">${_cancelText}</button>` : ''}
|
|
91
|
+
<button class="ds-btn ds-btn--primary" data-action="confirm" type="button">${_confirmText}</button>
|
|
89
92
|
</div>
|
|
90
93
|
</div>
|
|
91
94
|
</div>
|
|
@@ -103,6 +106,10 @@ function confirm(options = {}) {
|
|
|
103
106
|
if (maskEl) {maskEl.classList.add('is-visible');}
|
|
104
107
|
document.body.style.overflow = 'hidden';
|
|
105
108
|
|
|
109
|
+
// Focus the dialog
|
|
110
|
+
const dialogEl = maskEl?.querySelector('.ds-dialog');
|
|
111
|
+
if (dialogEl) {dialogEl.focus();}
|
|
112
|
+
|
|
106
113
|
// Bind button clicks
|
|
107
114
|
const confirmBtn = maskEl.querySelector('[data-action="confirm"]');
|
|
108
115
|
const cancelBtn = maskEl.querySelector('[data-action="cancel"]');
|
|
@@ -52,6 +52,8 @@ export function Drawer(options = {}, children = null) {
|
|
|
52
52
|
if (maskEl) {maskEl.classList.add('is-visible');}
|
|
53
53
|
if (drawerEl) {drawerEl.classList.add('is-visible');}
|
|
54
54
|
document.body.style.overflow = 'hidden';
|
|
55
|
+
// Focus management: focus the drawer panel
|
|
56
|
+
if (drawerEl) {drawerEl.focus();}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
function close() {
|
|
@@ -90,10 +92,10 @@ export function Drawer(options = {}, children = null) {
|
|
|
90
92
|
|
|
91
93
|
const tpl = html`
|
|
92
94
|
<div class="ds-drawer-mask" onclick="${onMaskClick}">
|
|
93
|
-
<div class="${drawerClass}" style="${styleAttr}">
|
|
95
|
+
<div class="${drawerClass}" style="${styleAttr}" role="dialog" aria-modal="true" aria-labelledby="drawer-title" tabindex="-1">
|
|
94
96
|
<div class="ds-drawer__header">
|
|
95
|
-
<span class="ds-drawer__title">${title}</span>
|
|
96
|
-
<button class="ds-drawer__close" onclick="${close}" aria-label="Close">
|
|
97
|
+
<span class="ds-drawer__title" id="drawer-title">${title}</span>
|
|
98
|
+
<button class="ds-drawer__close" onclick="${close}" aria-label="Close" type="button">
|
|
97
99
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
98
100
|
<path d="M18 6L6 18M6 6l12 12"/>
|
|
99
101
|
</svg>
|
|
@@ -49,6 +49,7 @@ export function Dropdown(options = {}) {
|
|
|
49
49
|
if (_isOpen) {return;}
|
|
50
50
|
_isOpen = true;
|
|
51
51
|
if (menuEl) {menuEl.classList.add('is-open');}
|
|
52
|
+
if (triggerEl) {triggerEl.setAttribute('aria-expanded', 'true');}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
function close() {
|
|
@@ -56,6 +57,7 @@ export function Dropdown(options = {}) {
|
|
|
56
57
|
_isOpen = false;
|
|
57
58
|
_focusIndex = -1;
|
|
58
59
|
if (menuEl) {menuEl.classList.remove('is-open');}
|
|
60
|
+
if (triggerEl) {triggerEl.setAttribute('aria-expanded', 'false');}
|
|
59
61
|
_clearFocus();
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -131,11 +133,20 @@ export function Dropdown(options = {}) {
|
|
|
131
133
|
e.preventDefault();
|
|
132
134
|
_setFocus(_focusIndex - 1);
|
|
133
135
|
break;
|
|
136
|
+
case 'Home':
|
|
137
|
+
e.preventDefault();
|
|
138
|
+
_setFocus(0);
|
|
139
|
+
break;
|
|
140
|
+
case 'End':
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
_setFocus(items.length - 1);
|
|
143
|
+
break;
|
|
134
144
|
case 'Enter':
|
|
135
145
|
e.preventDefault();
|
|
136
146
|
if (_focusIndex >= 0) {_selectItem(_focusIndex);}
|
|
137
147
|
break;
|
|
138
148
|
case 'Escape':
|
|
149
|
+
case 'Tab':
|
|
139
150
|
e.preventDefault();
|
|
140
151
|
close();
|
|
141
152
|
break;
|
|
@@ -147,18 +158,18 @@ export function Dropdown(options = {}) {
|
|
|
147
158
|
|
|
148
159
|
const itemTemplates = items.map(
|
|
149
160
|
(item) =>
|
|
150
|
-
html`<button class="ds-dropdown__item" data-value="${item.value}">${item.text}</button>`,
|
|
161
|
+
html`<button class="ds-dropdown__item" data-value="${item.value}" role="option">${item.text}</button>`,
|
|
151
162
|
);
|
|
152
163
|
|
|
153
164
|
const tpl = html`
|
|
154
165
|
<div class="ds-dropdown">
|
|
155
|
-
<button class="ds-dropdown__trigger" onclick="${onTriggerClick}">
|
|
166
|
+
<button class="ds-dropdown__trigger" onclick="${onTriggerClick}" aria-haspopup="listbox" aria-expanded="false">
|
|
156
167
|
<span>${placeholder}</span>
|
|
157
168
|
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
158
169
|
<polyline points="6 9 12 15 18 9"/>
|
|
159
170
|
</svg>
|
|
160
171
|
</button>
|
|
161
|
-
<div class="ds-dropdown__menu">${itemTemplates}</div>
|
|
172
|
+
<div class="ds-dropdown__menu" role="listbox">${itemTemplates}</div>
|
|
162
173
|
</div>
|
|
163
174
|
`;
|
|
164
175
|
|
|
@@ -168,6 +179,7 @@ export function Dropdown(options = {}) {
|
|
|
168
179
|
// Grab references to key elements
|
|
169
180
|
const wrapperEl = container.querySelector('.ds-dropdown');
|
|
170
181
|
const menuEl = container.querySelector('.ds-dropdown__menu');
|
|
182
|
+
const triggerEl = container.querySelector('.ds-dropdown__trigger');
|
|
171
183
|
|
|
172
184
|
// Bind item click handlers (after render, directly on DOM)
|
|
173
185
|
if (menuEl) {
|
|
@@ -68,9 +68,28 @@ export function Modal(options = {}, children = null) {
|
|
|
68
68
|
|
|
69
69
|
// ── Event handlers ─────────────────────────────────────────────────────────
|
|
70
70
|
|
|
71
|
+
/** Focus trap: keep Tab within the dialog when open. */
|
|
72
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
73
|
+
|
|
71
74
|
const onKeydown = (e) => {
|
|
72
|
-
if (
|
|
75
|
+
if (!_isOpen) {return;}
|
|
76
|
+
if (escClose && e.key === 'Escape') {
|
|
73
77
|
close();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Focus trap
|
|
81
|
+
if (e.key === 'Tab' && maskEl) {
|
|
82
|
+
const dialogEl = maskEl.querySelector('.ds-modal');
|
|
83
|
+
if (!dialogEl) {return;}
|
|
84
|
+
const focusable = Array.from(dialogEl.querySelectorAll(FOCUSABLE));
|
|
85
|
+
if (focusable.length === 0) { e.preventDefault(); return; }
|
|
86
|
+
const first = focusable[0];
|
|
87
|
+
const last = focusable[focusable.length - 1];
|
|
88
|
+
if (e.shiftKey) {
|
|
89
|
+
if (document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
90
|
+
} else {
|
|
91
|
+
if (document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
};
|
|
76
95
|
document.addEventListener('keydown', onKeydown);
|
|
@@ -27,6 +27,8 @@ import { render } from '../render.js';
|
|
|
27
27
|
* Create a NumberInput component instance.
|
|
28
28
|
*
|
|
29
29
|
* @param {Object} [options]
|
|
30
|
+
* @param {string} [options.label] Label text (creates <label> linked to input)
|
|
31
|
+
* @param {string} [options.id] Input id (auto-generated if label is set)
|
|
30
32
|
* @param {number} [options.min] Minimum value (default -Infinity)
|
|
31
33
|
* @param {number} [options.max] Maximum value (default Infinity)
|
|
32
34
|
* @param {number} [options.step] Step increment (default 1)
|
|
@@ -37,6 +39,8 @@ import { render } from '../render.js';
|
|
|
37
39
|
*/
|
|
38
40
|
export function NumberInput(options = {}) {
|
|
39
41
|
const {
|
|
42
|
+
label = '',
|
|
43
|
+
id = '',
|
|
40
44
|
min = -Infinity,
|
|
41
45
|
max = Infinity,
|
|
42
46
|
step = 1,
|
|
@@ -45,6 +49,10 @@ export function NumberInput(options = {}) {
|
|
|
45
49
|
onChange = null,
|
|
46
50
|
} = options;
|
|
47
51
|
|
|
52
|
+
// Generate unique id for label association
|
|
53
|
+
const _id = id || (label ? `ds-numinput-${Math.random().toString(36).slice(2, 8)}` : '');
|
|
54
|
+
const _hasLabel = !!label;
|
|
55
|
+
|
|
48
56
|
let _value = _clamp(initialValue);
|
|
49
57
|
|
|
50
58
|
// ── Public API ─────────────────────────────────────────────────────────────
|
|
@@ -99,10 +107,11 @@ export function NumberInput(options = {}) {
|
|
|
99
107
|
// ── Render ─────────────────────────────────────────────────────────────────
|
|
100
108
|
|
|
101
109
|
const tpl = html`
|
|
110
|
+
${_hasLabel ? html`<label class="ds-form-label" for="${_id}">${label}</label>` : ''}
|
|
102
111
|
<div class="ds-number-input">
|
|
103
|
-
<button class="ds-number-input__btn ds-number-input__btn--decrease" type="button">−</button>
|
|
104
|
-
<input class="ds-number-input__input" type="number" />
|
|
105
|
-
<button class="ds-number-input__btn ds-number-input__btn--increase" type="button">+</button>
|
|
112
|
+
<button class="ds-number-input__btn ds-number-input__btn--decrease" type="button" aria-label="Decrease">−</button>
|
|
113
|
+
<input class="ds-number-input__input" type="number" id="${_id}" ${!label ? 'aria-label="Number input"' : ''} />
|
|
114
|
+
<button class="ds-number-input__btn ds-number-input__btn--increase" type="button" aria-label="Increase">+</button>
|
|
106
115
|
</div>
|
|
107
116
|
`;
|
|
108
117
|
|