@cas-smartdesign/list 6.3.0 → 6.3.2
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/docs/doc.mjs +2 -3
- package/dist/list-with-externals.js +1 -1
- package/dist/list-with-externals.js.map +2 -2
- package/dist/list.mjs +22 -22
- package/dist/list.mjs.map +1 -1
- package/package.json +6 -6
- package/readme.md +0 -2
package/dist/docs/doc.mjs
CHANGED
|
@@ -323,7 +323,7 @@ container.appendChild(list);
|
|
|
323
323
|
<slot name="items"></slot>
|
|
324
324
|
<slot id="default-slot"></slot>
|
|
325
325
|
</div>
|
|
326
|
-
`;let Dr=0;const J=class J extends ur{constructor(){super(),this._items=[],this._selectedIndexes=[],this._itemGenerator=Pr,this.onDefaultSlotChange=()=>{let e=0;this.defaultSlot.assignedElements().forEach(t=>{this.isSeparator(t)||this.initListItem(t,e++)}),this.updateFocusedElement()},this.handleKeyDown=e=>{let t=!0;switch(e.key){case"ArrowDown":case"Down":this.focusIndex=Math.min(this.getListItems.length-1,this.focusIndex+1);break;case"ArrowUp":case"Up":this.focusIndex=Math.max(0,this.focusIndex-1);break;case"Enter":case"Space":case" ":this.handleSelection(this.focusIndex,e.metaKey||e.ctrlKey);break;case"End":case"PageDown":this.focusIndex=this.items.length-1;break;case"Home":case"PageUp":this.focusIndex=0;break;default:t=!1;break}t&&(e.preventDefault(),e.stopPropagation())},this._fallbackId=J.ID+"_"+Dr++,this.addEventListener("pointerup",e=>{this.focusIndex=this.getListItems.indexOf(e.target),this.updateFocusedElement()}),this.addEventListener("focus",()=>{this.matches(":focus-visible")&&(this.focusIndex==-1?(this.selectedIndexes&&(this.focusIndex=this.selectedIndexes[0]),this.focusIndex==-1&&this.childElementCount>0&&(this.focusIndex=0)):this.updateFocusedElement())}),this.addEventListener("blur",()=>this.removeFocusedItemAttributes())}get items(){return this._items}set items(e){this._items=e,this.render()}get itemGenerator(){return this._itemGenerator}set itemGenerator(e){this._itemGenerator=e,this.render()}get selectionType(){return this.getAttribute("selection-type")}set selectionType(e){e?this.setAttribute("selection-type",e):this.removeAttribute("selection-type")}get focusIndex(){return this.hasAttribute("focus-index")?Number(this.getAttribute("focus-index")):-1}set focusIndex(e){0<=e&&e<this.getListItems.length?this.setAttribute("focus-index",e.toString()):this.removeAttribute("focus-index")}get focusTarget(){return this.hasAttribute("focus-target")}set focusTarget(e){this.toggleAttribute("focus-target",e)}getListItem(e){return this.shadowRoot?this.getListItems[e]:null}get getListItems(){return Array.prototype.slice.call(this.children).filter(e=>!this.isSeparator(e))}get selectedIndexes(){return this._selectedIndexes}set selectedIndexes(e){const t=this._selectedIndexes||[];this._selectedIndexes=e||[],t.filter(i=>!this._selectedIndexes.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!1)}),this._selectedIndexes.filter(i=>!t.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!0)})}static get observedAttributes(){return["focus-index","focus-target"]}is(){return J.ID}template(){const e=document.createElement("template");return e.innerHTML=jr,e}removeFocusedItemAttributes(){if(this.focusIndex!=-1){const e=this.getListItem(this.focusIndex);e&&(e.removeAttribute("focused"),this.removeAttribute("aria-activedescendant"))}}connectedCallback(){super.connectedCallback(),this.defaultSlot.addEventListener("slotchange",this.onDefaultSlotChange),this.hasAttribute("role")||this.setAttribute("role","listbox"),this.id||(this.id=this._fallbackId),this.render(),this.addEventListener("keydown",this.handleKeyDown),this.selectionType||(this.selectionType="trigger-only")}get defaultSlot(){return this.shadowRoot.querySelector("#default-slot")}isSeparator(e){return e.tagName=="HR"||e.getAttribute("role")=="separator"}attributeChangedCallback(e,t,i){if(e==="focus-index"){const s=this.getListItem(t);s&&s.removeAttribute("focused"),this.updateFocusedElement()}else e==="focus-target"&&(this.focusTarget?this.updateFocusedElement():document.activeElement!=this&&this.removeFocusedItemAttributes())}increaseWidthIfNeeded(){window.requestAnimationFrame(()=>{let e=Number.MAX_SAFE_INTEGER;const t=getComputedStyle(this).maxWidth,i=this.offsetWidth;t.endsWith("px")&&(e=Number.parseInt(t)-i);const s=this.style.width;if(e==0||s.endsWith("px")&&i<Number.parseInt(s))this.enableLineClampOnItemsIfNeeded();else{const o=[...this.querySelectorAll("[slot='items']")].map(l=>{if(l instanceof ke){l.enableLineClamp=!1;const a=l.missingWidthForTexts;return a>e&&(l.enableLineClamp=!0),a}}),r=Math.max(...o);if(r>0){const l=i+r;this.style.width=`${l}px`,this.offsetWidth<l&&this.enableLineClampOnItemsIfNeeded()}}})}enableLineClampOnItemsIfNeeded(){this.querySelectorAll("[slot='items']").forEach(e=>{e instanceof ke&&(e.enableLineClamp=e.enableLineClamp||e.missingWidthForTexts>0)})}render(){if(!this.isConnected||!this.items)return;this.querySelectorAll("[slot='items']").forEach(i=>{this.removeChild(i)});const e=document.createDocumentFragment();let t=0;this.items.forEach((i,s)=>{const o=this.itemGenerator(i,s);this.isSeparator(o)||this.initListItem(o,t++),o.slot="items",e.appendChild(o)}),this.appendChild(e),this.updateFocusedElement()}initListItem(e,t){this.setSelectedAttr(e,this.selectedIndexes.includes(t)),e.addEventListener("click",i=>{this.handleItemClick(i,t)}),e.addEventListener("mousedown",i=>{i.button==1&&i.preventDefault()}),e.addEventListener("auxclick",i=>{this.handleItemClick(i,t)}),(!e.id||e.id.startsWith(this.id+"_item_"))&&(e.id=this.id+"_item_"+t)}ensureItemVisible(e){const t=e.getBoundingClientRect(),i=this.getBoundingClientRect();t.bottom>i.bottom?this.scrollTop+=t.bottom-i.bottom:t.top<i.top&&(this.scrollTop-=i.top-t.top)}updateFocusedElement(){const e=this.getListItem(this.focusIndex);e&&(this.focusTarget||document.activeElement==this)?(e.setAttribute("focused",""),this.setAttribute("aria-activedescendant",e.id),this.ensureItemVisible(e)):this.removeAttribute("aria-activedescendant")}handleItemClick(e,t){if(e.button!==null){const i=e.type=="auxclick"&&e.button==1||e.metaKey||e.ctrlKey;(e.button==0||e.button==1)&&this.handleSelection(t,i)}}handleSelection(e,t){const i=this.
|
|
326
|
+
`;let Dr=0;const J=class J extends ur{constructor(){super(),this._items=[],this._selectedIndexes=[],this._itemGenerator=Pr,this.onDefaultSlotChange=()=>{let e=0;this.defaultSlot.assignedElements().forEach(t=>{this.isSeparator(t)||this.initListItem(t,e++)}),this.updateFocusedElement()},this.handleKeyDown=e=>{let t=!0;switch(e.key){case"ArrowDown":case"Down":this.focusIndex=Math.min(this.getListItems.length-1,this.focusIndex+1);break;case"ArrowUp":case"Up":this.focusIndex=Math.max(0,this.focusIndex-1);break;case"Enter":case"Space":case" ":this.handleSelection(this.focusIndex,e.metaKey||e.ctrlKey);break;case"End":case"PageDown":this.focusIndex=this.items.length-1;break;case"Home":case"PageUp":this.focusIndex=0;break;default:t=!1;break}t&&(e.preventDefault(),e.stopPropagation())},this._fallbackId=J.ID+"_"+Dr++,this.addEventListener("pointerup",e=>{this.focusIndex=this.getListItems.indexOf(e.target),this.updateFocusedElement()}),this.addEventListener("focus",()=>{this.matches(":focus-visible")&&(this.focusIndex==-1?(this.selectedIndexes&&(this.focusIndex=this.selectedIndexes[0]),this.focusIndex==-1&&this.childElementCount>0&&(this.focusIndex=0)):this.updateFocusedElement())}),this.addEventListener("blur",()=>this.removeFocusedItemAttributes())}get items(){return this._items}set items(e){this._items=e,this.render()}get itemGenerator(){return this._itemGenerator}set itemGenerator(e){this._itemGenerator=e,this.render()}get selectionType(){return this.getAttribute("selection-type")}set selectionType(e){e?this.setAttribute("selection-type",e):this.removeAttribute("selection-type")}get focusIndex(){return this.hasAttribute("focus-index")?Number(this.getAttribute("focus-index")):-1}set focusIndex(e){0<=e&&e<this.getListItems.length?this.setAttribute("focus-index",e.toString()):this.removeAttribute("focus-index")}get focusTarget(){return this.hasAttribute("focus-target")}set focusTarget(e){this.toggleAttribute("focus-target",e)}getListItem(e){return this.shadowRoot?this.getListItems[e]:null}get getListItems(){return Array.prototype.slice.call(this.children).filter(e=>!this.isSeparator(e))}get selectedIndexes(){return this._selectedIndexes}set selectedIndexes(e){const t=this._selectedIndexes||[];this._selectedIndexes=e||[],t.filter(i=>!this._selectedIndexes.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!1)}),this._selectedIndexes.filter(i=>!t.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!0)})}static get observedAttributes(){return["focus-index","focus-target"]}is(){return J.ID}template(){const e=document.createElement("template");return e.innerHTML=jr,e}removeFocusedItemAttributes(){if(this.focusIndex!=-1){const e=this.getListItem(this.focusIndex);e&&(e.removeAttribute("focused"),this.removeAttribute("aria-activedescendant"))}}connectedCallback(){super.connectedCallback(),this.defaultSlot.addEventListener("slotchange",this.onDefaultSlotChange),this.hasAttribute("role")||this.setAttribute("role","listbox"),this.id||(this.id=this._fallbackId),this.render(),this.addEventListener("keydown",this.handleKeyDown),this.selectionType||(this.selectionType="trigger-only")}get defaultSlot(){return this.shadowRoot.querySelector("#default-slot")}isSeparator(e){return e.tagName=="HR"||e.getAttribute("role")=="separator"}attributeChangedCallback(e,t,i){if(e==="focus-index"){const s=this.getListItem(t);s&&s.removeAttribute("focused"),this.updateFocusedElement()}else e==="focus-target"&&(this.focusTarget?this.updateFocusedElement():document.activeElement!=this&&this.removeFocusedItemAttributes())}increaseWidthIfNeeded(){window.requestAnimationFrame(()=>{let e=Number.MAX_SAFE_INTEGER;const t=getComputedStyle(this).maxWidth,i=this.offsetWidth;t.endsWith("px")&&(e=Number.parseInt(t)-i);const s=this.style.width;if(e==0||s.endsWith("px")&&i<Number.parseInt(s))this.enableLineClampOnItemsIfNeeded();else{const o=[...this.querySelectorAll("[slot='items']")].map(l=>{if(l instanceof ke){l.enableLineClamp=!1;const a=l.missingWidthForTexts;return a>e&&(l.enableLineClamp=!0),a}}),r=Math.max(...o);if(r>0){const l=i+r;this.style.width=`${l}px`,this.offsetWidth<l&&this.enableLineClampOnItemsIfNeeded()}}})}enableLineClampOnItemsIfNeeded(){this.querySelectorAll("[slot='items']").forEach(e=>{e instanceof ke&&(e.enableLineClamp=e.enableLineClamp||e.missingWidthForTexts>0)})}render(){if(!this.isConnected||!this.items)return;this.querySelectorAll("[slot='items']").forEach(i=>{this.removeChild(i)});const e=document.createDocumentFragment();let t=0;this.items.forEach((i,s)=>{const o=this.itemGenerator(i,s);this.isSeparator(o)||this.initListItem(o,t++),o.slot="items",e.appendChild(o)}),this.appendChild(e),this.updateFocusedElement()}initListItem(e,t){this.setSelectedAttr(e,this.selectedIndexes.includes(t)),e.addEventListener("click",i=>{this.handleItemClick(i,t)}),e.addEventListener("mousedown",i=>{i.button==1&&i.preventDefault()}),e.addEventListener("auxclick",i=>{this.handleItemClick(i,t)}),(!e.id||e.id.startsWith(this.id+"_item_"))&&(e.id=this.id+"_item_"+t)}ensureItemVisible(e){const t=e.getBoundingClientRect(),i=this.getBoundingClientRect();t.bottom>i.bottom?this.scrollTop+=t.bottom-i.bottom:t.top<i.top&&(this.scrollTop-=i.top-t.top)}updateFocusedElement(){const e=this.getListItem(this.focusIndex);e&&(this.focusTarget||document.activeElement==this)?(e.setAttribute("focused",""),this.setAttribute("aria-activedescendant",e.id),this.ensureItemVisible(e)):this.removeAttribute("aria-activedescendant")}handleItemClick(e,t){if(e.button!==null){const i=e.type=="auxclick"&&e.button==1||e.metaKey||e.ctrlKey;(e.button==0||e.button==1)&&this.handleSelection(t,i)}}handleSelection(e,t){const i=this.getListItem(e);if(i.getAttribute("aria-disabled")=="true"||i.hasAttribute("disabled"))return;const s=this.isSelected(i);this.selectionType!=="trigger-only"&&(this.selectionType==="single"?this.selectedIndexes=s?[]:[e]:this.toggleSelection(i)?this._selectedIndexes.push(e):this.removeFromSelectedIndexes(e)),this.focusIndex=e,this.dispatchEvent(new CustomEvent("selection",{detail:{index:e,selected:this.selectionType=="trigger-only"||!s,hasModifier:t},bubbles:!0,composed:!0}))}removeFromSelectedIndexes(e){const t=this._selectedIndexes.indexOf(e);t!==-1&&this._selectedIndexes.splice(t,1)}toggleSelection(e){const t=!e.hasAttribute("selected");return this.setSelectedAttr(e,t),t}setSelectedAttr(e,t){e&&(t?e.setAttribute("selected",""):e.removeAttribute("selected"),e.setAttribute("aria-selected",String(t)))}isSelected(e){return e.hasAttribute("selected")}};J.ID="sd-list",J.ensureDefined=()=>{ke.ensureDefined(),customElements.get(J.ID)||customElements.define(J.ID,J)};let Kt=J;Kt.ensureDefined();function $n(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function zr(n){if(n.__esModule)return n;var e=n.default;if(typeof e=="function"){var t=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(i){var s=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return n[i]}})}),t}var hi={exports:{}},$=String,Cn=function(){return{isColorSupported:!1,reset:$,bold:$,dim:$,italic:$,underline:$,inverse:$,hidden:$,strikethrough:$,black:$,red:$,green:$,yellow:$,blue:$,magenta:$,cyan:$,white:$,gray:$,bgBlack:$,bgRed:$,bgGreen:$,bgYellow:$,bgBlue:$,bgMagenta:$,bgCyan:$,bgWhite:$}};hi.exports=Cn();hi.exports.createColors=Cn;var Ur=hi.exports;const Br={},Fr=Object.freeze(Object.defineProperty({__proto__:null,default:Br},Symbol.toStringTag,{value:"Module"})),B=zr(Fr);let Wi=Ur,Gi=B,Zt=class kn extends Error{constructor(e,t,i,s,o,r){super(e),this.name="CssSyntaxError",this.reason=e,o&&(this.file=o),s&&(this.source=s),r&&(this.plugin=r),typeof t<"u"&&typeof i<"u"&&(typeof t=="number"?(this.line=t,this.column=i):(this.line=t.line,this.column=t.column,this.endLine=i.line,this.endColumn=i.column)),this.setMessage(),Error.captureStackTrace&&Error.captureStackTrace(this,kn)}setMessage(){this.message=this.plugin?this.plugin+": ":"",this.message+=this.file?this.file:"<css input>",typeof this.line<"u"&&(this.message+=":"+this.line+":"+this.column),this.message+=": "+this.reason}showSourceCode(e){if(!this.source)return"";let t=this.source;e==null&&(e=Wi.isColorSupported),Gi&&e&&(t=Gi(t));let i=t.split(/\r?\n/),s=Math.max(this.line-3,0),o=Math.min(this.line+2,i.length),r=String(o).length,l,a;if(e){let{bold:c,gray:d,red:f}=Wi.createColors(!0);l=p=>c(f(p)),a=p=>d(p)}else l=a=c=>c;return i.slice(s,o).map((c,d)=>{let f=s+1+d,p=" "+(" "+f).slice(-r)+" | ";if(f===this.line){let x=a(p.replace(/\d/g," "))+c.slice(0,this.column-1).replace(/[^\t]/g," ");return l(">")+a(p)+c+`
|
|
327
327
|
`+x+l("^")}return" "+a(p)+c}).join(`
|
|
328
328
|
`)}toString(){let e=this.showSourceCode();return e&&(e=`
|
|
329
329
|
|
|
@@ -437,8 +437,7 @@ Although normally the page would change by such a selection, so it may not be ne
|
|
|
437
437
|
</ul>
|
|
438
438
|
</li>
|
|
439
439
|
</ul>
|
|
440
|
-
|
|
441
|
-
`;document.querySelector("#markdown-container").innerHTML=Ha;Ua(Object.assign({"./examples/declarative-list-item/index.ts":Hs,"./examples/declarative-option/index.ts":Ks,"./examples/multi-select/index.ts":er,"./examples/single-select/index.ts":rr,"./examples/trigger-only/index.ts":dr}));export{Kt as L};
|
|
440
|
+
`,Wa=document.querySelector("#markdown-container");Wa.innerHTML=Ha;Ua(Object.assign({"./examples/declarative-list-item/index.ts":Hs,"./examples/declarative-option/index.ts":Ks,"./examples/multi-select/index.ts":er,"./examples/single-select/index.ts":rr,"./examples/trigger-only/index.ts":dr}),document.querySelector(".markdown-body"));export{Kt as L};
|
|
442
441
|
function __vite__mapDeps(indexes) {
|
|
443
442
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
444
443
|
__vite__mapDeps.viteFileDeps = ["./multi-select.js","./sample-data.mjs","./single-select.js","./trigger-only.js"]
|
|
@@ -64,7 +64,7 @@ var window;(window||={})["@cas-smartdesign/list"]=(()=>{var X=Object.definePrope
|
|
|
64
64
|
<slot name="items"></slot>
|
|
65
65
|
<slot id="default-slot"></slot>
|
|
66
66
|
</div>
|
|
67
|
-
`,oe=0,k=class mt extends vt{constructor(){super(),this._items=[],this._selectedIndexes=[],this._itemGenerator=Dt,this.onDefaultSlotChange=()=>{let t=0;this.defaultSlot.assignedElements().forEach(e=>{this.isSeparator(e)||this.initListItem(e,t++)}),this.updateFocusedElement()},this.handleKeyDown=t=>{let e=!0;switch(t.key){case"ArrowDown":case"Down":this.focusIndex=Math.min(this.getListItems.length-1,this.focusIndex+1);break;case"ArrowUp":case"Up":this.focusIndex=Math.max(0,this.focusIndex-1);break;case"Enter":case"Space":case" ":this.handleSelection(this.focusIndex,t.metaKey||t.ctrlKey);break;case"End":case"PageDown":this.focusIndex=this.items.length-1;break;case"Home":case"PageUp":this.focusIndex=0;break;default:e=!1;break}e&&(t.preventDefault(),t.stopPropagation())},this._fallbackId=mt.ID+"_"+oe++,this.addEventListener("pointerup",t=>{this.focusIndex=this.getListItems.indexOf(t.target),this.updateFocusedElement()}),this.addEventListener("focus",()=>{this.matches(":focus-visible")&&(this.focusIndex==-1?(this.selectedIndexes&&(this.focusIndex=this.selectedIndexes[0]),this.focusIndex==-1&&this.childElementCount>0&&(this.focusIndex=0)):this.updateFocusedElement())}),this.addEventListener("blur",()=>this.removeFocusedItemAttributes())}get items(){return this._items}set items(t){this._items=t,this.render()}get itemGenerator(){return this._itemGenerator}set itemGenerator(t){this._itemGenerator=t,this.render()}get selectionType(){return this.getAttribute("selection-type")}set selectionType(t){t?this.setAttribute("selection-type",t):this.removeAttribute("selection-type")}get focusIndex(){return this.hasAttribute("focus-index")?Number(this.getAttribute("focus-index")):-1}set focusIndex(t){0<=t&&t<this.getListItems.length?this.setAttribute("focus-index",t.toString()):this.removeAttribute("focus-index")}get focusTarget(){return this.hasAttribute("focus-target")}set focusTarget(t){this.toggleAttribute("focus-target",t)}getListItem(t){return this.shadowRoot?this.getListItems[t]:null}get getListItems(){return Array.prototype.slice.call(this.children).filter(t=>!this.isSeparator(t))}get selectedIndexes(){return this._selectedIndexes}set selectedIndexes(t){let e=this._selectedIndexes||[];this._selectedIndexes=t||[],e.filter(i=>!this._selectedIndexes.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!1)}),this._selectedIndexes.filter(i=>!e.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!0)})}static get observedAttributes(){return["focus-index","focus-target"]}is(){return mt.ID}template(){let t=document.createElement("template");return t.innerHTML=se,t}removeFocusedItemAttributes(){if(this.focusIndex!=-1){let t=this.getListItem(this.focusIndex);t&&(t.removeAttribute("focused"),this.removeAttribute("aria-activedescendant"))}}connectedCallback(){super.connectedCallback(),this.defaultSlot.addEventListener("slotchange",this.onDefaultSlotChange),this.hasAttribute("role")||this.setAttribute("role","listbox"),this.id||(this.id=this._fallbackId),this.render(),this.addEventListener("keydown",this.handleKeyDown),this.selectionType||(this.selectionType="trigger-only")}get defaultSlot(){return this.shadowRoot.querySelector("#default-slot")}isSeparator(t){return t.tagName=="HR"||t.getAttribute("role")=="separator"}attributeChangedCallback(t,e,i){if(t==="focus-index"){let o=this.getListItem(e);o&&o.removeAttribute("focused"),this.updateFocusedElement()}else t==="focus-target"&&(this.focusTarget?this.updateFocusedElement():document.activeElement!=this&&this.removeFocusedItemAttributes())}increaseWidthIfNeeded(){window.requestAnimationFrame(()=>{let t=Number.MAX_SAFE_INTEGER,e=getComputedStyle(this).maxWidth,i=this.offsetWidth;e.endsWith("px")&&(t=Number.parseInt(e)-i);let o=this.style.width;if(t==0||o.endsWith("px")&&i<Number.parseInt(o))this.enableLineClampOnItemsIfNeeded();else{let r=[...this.querySelectorAll("[slot='items']")].map(a=>{if(a instanceof T){a.enableLineClamp=!1;let l=a.missingWidthForTexts;return l>t&&(a.enableLineClamp=!0),l}}),n=Math.max(...r);if(n>0){let a=i+n;this.style.width=`${a}px`,this.offsetWidth<a&&this.enableLineClampOnItemsIfNeeded()}}})}enableLineClampOnItemsIfNeeded(){this.querySelectorAll("[slot='items']").forEach(t=>{t instanceof T&&(t.enableLineClamp=t.enableLineClamp||t.missingWidthForTexts>0)})}render(){if(!this.isConnected||!this.items)return;this.querySelectorAll("[slot='items']").forEach(i=>{this.removeChild(i)});let t=document.createDocumentFragment(),e=0;this.items.forEach((i,o)=>{let r=this.itemGenerator(i,o);this.isSeparator(r)||this.initListItem(r,e++),r.slot="items",t.appendChild(r)}),this.appendChild(t),this.updateFocusedElement()}initListItem(t,e){this.setSelectedAttr(t,this.selectedIndexes.includes(e)),t.addEventListener("click",i=>{this.handleItemClick(i,e)}),t.addEventListener("mousedown",i=>{i.button==1&&i.preventDefault()}),t.addEventListener("auxclick",i=>{this.handleItemClick(i,e)}),(!t.id||t.id.startsWith(this.id+"_item_"))&&(t.id=this.id+"_item_"+e)}ensureItemVisible(t){let e=t.getBoundingClientRect(),i=this.getBoundingClientRect();e.bottom>i.bottom?this.scrollTop+=e.bottom-i.bottom:e.top<i.top&&(this.scrollTop-=i.top-e.top)}updateFocusedElement(){let t=this.getListItem(this.focusIndex);t&&(this.focusTarget||document.activeElement==this)?(t.setAttribute("focused",""),this.setAttribute("aria-activedescendant",t.id),this.ensureItemVisible(t)):this.removeAttribute("aria-activedescendant")}handleItemClick(t,e){if(t.button!==null){let i=t.type=="auxclick"&&t.button==1||t.metaKey||t.ctrlKey;(t.button==0||t.button==1)&&this.handleSelection(e,i)}}handleSelection(t,e){let i=this.
|
|
67
|
+
`,oe=0,k=class mt extends vt{constructor(){super(),this._items=[],this._selectedIndexes=[],this._itemGenerator=Dt,this.onDefaultSlotChange=()=>{let t=0;this.defaultSlot.assignedElements().forEach(e=>{this.isSeparator(e)||this.initListItem(e,t++)}),this.updateFocusedElement()},this.handleKeyDown=t=>{let e=!0;switch(t.key){case"ArrowDown":case"Down":this.focusIndex=Math.min(this.getListItems.length-1,this.focusIndex+1);break;case"ArrowUp":case"Up":this.focusIndex=Math.max(0,this.focusIndex-1);break;case"Enter":case"Space":case" ":this.handleSelection(this.focusIndex,t.metaKey||t.ctrlKey);break;case"End":case"PageDown":this.focusIndex=this.items.length-1;break;case"Home":case"PageUp":this.focusIndex=0;break;default:e=!1;break}e&&(t.preventDefault(),t.stopPropagation())},this._fallbackId=mt.ID+"_"+oe++,this.addEventListener("pointerup",t=>{this.focusIndex=this.getListItems.indexOf(t.target),this.updateFocusedElement()}),this.addEventListener("focus",()=>{this.matches(":focus-visible")&&(this.focusIndex==-1?(this.selectedIndexes&&(this.focusIndex=this.selectedIndexes[0]),this.focusIndex==-1&&this.childElementCount>0&&(this.focusIndex=0)):this.updateFocusedElement())}),this.addEventListener("blur",()=>this.removeFocusedItemAttributes())}get items(){return this._items}set items(t){this._items=t,this.render()}get itemGenerator(){return this._itemGenerator}set itemGenerator(t){this._itemGenerator=t,this.render()}get selectionType(){return this.getAttribute("selection-type")}set selectionType(t){t?this.setAttribute("selection-type",t):this.removeAttribute("selection-type")}get focusIndex(){return this.hasAttribute("focus-index")?Number(this.getAttribute("focus-index")):-1}set focusIndex(t){0<=t&&t<this.getListItems.length?this.setAttribute("focus-index",t.toString()):this.removeAttribute("focus-index")}get focusTarget(){return this.hasAttribute("focus-target")}set focusTarget(t){this.toggleAttribute("focus-target",t)}getListItem(t){return this.shadowRoot?this.getListItems[t]:null}get getListItems(){return Array.prototype.slice.call(this.children).filter(t=>!this.isSeparator(t))}get selectedIndexes(){return this._selectedIndexes}set selectedIndexes(t){let e=this._selectedIndexes||[];this._selectedIndexes=t||[],e.filter(i=>!this._selectedIndexes.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!1)}),this._selectedIndexes.filter(i=>!e.includes(i)).forEach(i=>{this.setSelectedAttr(this.getListItem(i),!0)})}static get observedAttributes(){return["focus-index","focus-target"]}is(){return mt.ID}template(){let t=document.createElement("template");return t.innerHTML=se,t}removeFocusedItemAttributes(){if(this.focusIndex!=-1){let t=this.getListItem(this.focusIndex);t&&(t.removeAttribute("focused"),this.removeAttribute("aria-activedescendant"))}}connectedCallback(){super.connectedCallback(),this.defaultSlot.addEventListener("slotchange",this.onDefaultSlotChange),this.hasAttribute("role")||this.setAttribute("role","listbox"),this.id||(this.id=this._fallbackId),this.render(),this.addEventListener("keydown",this.handleKeyDown),this.selectionType||(this.selectionType="trigger-only")}get defaultSlot(){return this.shadowRoot.querySelector("#default-slot")}isSeparator(t){return t.tagName=="HR"||t.getAttribute("role")=="separator"}attributeChangedCallback(t,e,i){if(t==="focus-index"){let o=this.getListItem(e);o&&o.removeAttribute("focused"),this.updateFocusedElement()}else t==="focus-target"&&(this.focusTarget?this.updateFocusedElement():document.activeElement!=this&&this.removeFocusedItemAttributes())}increaseWidthIfNeeded(){window.requestAnimationFrame(()=>{let t=Number.MAX_SAFE_INTEGER,e=getComputedStyle(this).maxWidth,i=this.offsetWidth;e.endsWith("px")&&(t=Number.parseInt(e)-i);let o=this.style.width;if(t==0||o.endsWith("px")&&i<Number.parseInt(o))this.enableLineClampOnItemsIfNeeded();else{let r=[...this.querySelectorAll("[slot='items']")].map(a=>{if(a instanceof T){a.enableLineClamp=!1;let l=a.missingWidthForTexts;return l>t&&(a.enableLineClamp=!0),l}}),n=Math.max(...r);if(n>0){let a=i+n;this.style.width=`${a}px`,this.offsetWidth<a&&this.enableLineClampOnItemsIfNeeded()}}})}enableLineClampOnItemsIfNeeded(){this.querySelectorAll("[slot='items']").forEach(t=>{t instanceof T&&(t.enableLineClamp=t.enableLineClamp||t.missingWidthForTexts>0)})}render(){if(!this.isConnected||!this.items)return;this.querySelectorAll("[slot='items']").forEach(i=>{this.removeChild(i)});let t=document.createDocumentFragment(),e=0;this.items.forEach((i,o)=>{let r=this.itemGenerator(i,o);this.isSeparator(r)||this.initListItem(r,e++),r.slot="items",t.appendChild(r)}),this.appendChild(t),this.updateFocusedElement()}initListItem(t,e){this.setSelectedAttr(t,this.selectedIndexes.includes(e)),t.addEventListener("click",i=>{this.handleItemClick(i,e)}),t.addEventListener("mousedown",i=>{i.button==1&&i.preventDefault()}),t.addEventListener("auxclick",i=>{this.handleItemClick(i,e)}),(!t.id||t.id.startsWith(this.id+"_item_"))&&(t.id=this.id+"_item_"+e)}ensureItemVisible(t){let e=t.getBoundingClientRect(),i=this.getBoundingClientRect();e.bottom>i.bottom?this.scrollTop+=e.bottom-i.bottom:e.top<i.top&&(this.scrollTop-=i.top-e.top)}updateFocusedElement(){let t=this.getListItem(this.focusIndex);t&&(this.focusTarget||document.activeElement==this)?(t.setAttribute("focused",""),this.setAttribute("aria-activedescendant",t.id),this.ensureItemVisible(t)):this.removeAttribute("aria-activedescendant")}handleItemClick(t,e){if(t.button!==null){let i=t.type=="auxclick"&&t.button==1||t.metaKey||t.ctrlKey;(t.button==0||t.button==1)&&this.handleSelection(e,i)}}handleSelection(t,e){let i=this.getListItem(t);if(i.getAttribute("aria-disabled")=="true"||i.hasAttribute("disabled"))return;let o=this.isSelected(i);this.selectionType!=="trigger-only"&&(this.selectionType==="single"?this.selectedIndexes=o?[]:[t]:this.toggleSelection(i)?this._selectedIndexes.push(t):this.removeFromSelectedIndexes(t)),this.focusIndex=t,this.dispatchEvent(new CustomEvent("selection",{detail:{index:t,selected:this.selectionType=="trigger-only"||!o,hasModifier:e},bubbles:!0,composed:!0}))}removeFromSelectedIndexes(t){let e=this._selectedIndexes.indexOf(t);e!==-1&&this._selectedIndexes.splice(e,1)}toggleSelection(t){let e=!t.hasAttribute("selected");return this.setSelectedAttr(t,e),e}setSelectedAttr(t,e){t&&(e?t.setAttribute("selected",""):t.removeAttribute("selected"),t.setAttribute("aria-selected",String(e)))}isSelected(t){return t.hasAttribute("selected")}};k.ID="sd-list",k.ensureDefined=()=>{T.ensureDefined(),customElements.get(k.ID)||customElements.define(k.ID,k)};var Ot=k;Ot.ensureDefined();return qt(ne);})();
|
|
68
68
|
/*! Bundled license information:
|
|
69
69
|
|
|
70
70
|
@lit/reactive-element/css-tag.js:
|