@aceshooting/lyra-ui 31.0.0 → 31.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +149 -0
- package/dist/autoloader-cdn.js +1 -1
- package/dist/components/agent-tools/budget-meter/budget-meter.class.d.ts +12 -1
- package/dist/components/agent-tools/budget-meter/budget-meter.class.js +4 -4
- package/dist/components/charts/chart/lite-chart.class.js +1 -1
- package/dist/components/conversation/chat-composer/chat-composer.class.d.ts +18 -8
- package/dist/components/conversation/chat-composer/chat-composer.class.js +11 -9
- package/dist/components/conversation/chat-composer/chat-composer.styles.js +1 -1
- package/dist/components/conversation/message-feedback/message-feedback.class.d.ts +11 -3
- package/dist/components/conversation/message-feedback/message-feedback.class.js +12 -6
- package/dist/components/conversation/message-feedback/message-feedback.styles.js +1 -1
- package/dist/components/conversation/prompt-input/prompt-input.class.d.ts +6 -3
- package/dist/components/conversation/prompt-input/prompt-input.class.js +3 -2
- package/dist/components/conversation/push-to-talk/push-to-talk.class.js +1 -1
- package/dist/components/conversation/thread-list/thread-list.class.d.ts +1 -1
- package/dist/components/conversation/thread-list/thread-list.class.js +2 -2
- package/dist/components/data/document-library/document-library-cursor.js +1 -0
- package/dist/components/data/document-library/document-library-types.d.ts +20 -0
- package/dist/components/data/document-library/document-library.class.d.ts +37 -26
- package/dist/components/data/document-library/document-library.class.js +20 -11
- package/dist/components/data/document-library/document-library.styles.js +1 -1
- package/dist/components/data/flow-canvas/flow-canvas.class.d.ts +1 -1
- package/dist/components/data/flow-canvas/flow-canvas.class.js +1 -1
- package/dist/components/data/timeline/timeline.class.js +1 -1
- package/dist/components/data/tree/tree-data-expansion.js +1 -0
- package/dist/components/data/tree/tree-item.class.d.ts +10 -4
- package/dist/components/data/tree/tree-item.class.js +5 -2
- package/dist/components/data/tree/tree-item.styles.js +1 -1
- package/dist/components/data/tree/tree-owner-controller.js +1 -1
- package/dist/components/data/tree/tree-pointer-reorder.js +1 -0
- package/dist/components/data/tree/tree-types.d.ts +5 -1
- package/dist/components/data/tree/tree.class.d.ts +27 -9
- package/dist/components/data/tree/tree.class.js +5 -3
- package/dist/components/data/tree/tree.styles.js +1 -1
- package/dist/components/forms/combobox/combobox.class.d.ts +20 -12
- package/dist/components/forms/combobox/combobox.class.js +2 -2
- package/dist/components/forms/select/select.class.js +1 -1
- package/dist/components/layout/dock-panel/dock-panel.class.d.ts +1 -1
- package/dist/components/layout/dock-panel/dock-panel.class.js +1 -1
- package/dist/components/layout/page/page.class.d.ts +3 -3
- package/dist/components/layout/page/page.class.js +1 -1
- package/dist/components/layout/segmented/segmented.class.d.ts +20 -7
- package/dist/components/layout/segmented/segmented.class.js +34 -24
- package/dist/components/layout/segmented/segmented.styles.js +1 -1
- package/dist/components/layout/stepper/stepper.styles.js +1 -1
- package/dist/components/layout/virtual-list/virtual-list.class.js +1 -1
- package/dist/components/media/map/map-anchor-controller.js +1 -1
- package/dist/components/media/map/map-canvas-target.js +1 -0
- package/dist/components/media/map/map.class.d.ts +10 -1
- package/dist/components/media/map/map.class.js +4 -4
- package/dist/components/media/map/map.styles.js +1 -1
- package/dist/components/media/sequence-playback/sequence-playback.class.d.ts +21 -9
- package/dist/components/media/sequence-playback/sequence-playback.class.js +7 -6
- package/dist/components/media/sequence-playback/sequence-playback.styles.js +1 -1
- package/dist/components/overlays/overlay/overlay.styles.js +1 -1
- package/dist/components/retrieval/graph/graph-spatial-controller.js +1 -1
- package/dist/components/retrieval/graph/graph.class.js +1 -1
- package/dist/components/retrieval/ingestion-queue/ingestion-queue-presentation.d.ts +11 -0
- package/dist/components/retrieval/ingestion-queue/ingestion-queue-presentation.js +1 -0
- package/dist/components/retrieval/ingestion-queue/ingestion-queue.class.d.ts +18 -7
- package/dist/components/retrieval/ingestion-queue/ingestion-queue.class.js +13 -26
- package/dist/components/retrieval/ingestion-queue/ingestion-queue.styles.js +1 -1
- package/dist/components/utility/diff-view/diff-view.class.d.ts +5 -5
- package/dist/components/utility/diff-view/diff-view.class.js +1 -1
- package/dist/components/utility/icon/icon.class.js +1 -1
- package/dist/components/viewers/archive-viewer/archive-viewer.class.js +1 -1
- package/dist/components/viewers/calendar-viewer/calendar-viewer.class.js +1 -1
- package/dist/components/viewers/contact-viewer/contact-viewer.class.js +1 -1
- package/dist/components/viewers/document-preview/document-preview.class.js +2 -2
- package/dist/components/viewers/docx-viewer/docx-viewer.class.d.ts +1 -1
- package/dist/components/viewers/docx-viewer/docx-viewer.class.js +1 -1
- package/dist/components/viewers/email-viewer/email-viewer.class.d.ts +1 -1
- package/dist/components/viewers/email-viewer/email-viewer.class.js +2 -2
- package/dist/components/viewers/html-viewer/html-viewer.class.js +1 -1
- package/dist/components/viewers/notebook-viewer/notebook-viewer.class.js +2 -2
- package/dist/components/viewers/pdf-viewer/pdf-viewer.class.d.ts +1 -1
- package/dist/components/viewers/pdf-viewer/pdf-viewer.class.js +1 -1
- package/dist/components/viewers/pptx-viewer/pptx-viewer.class.js +1 -1
- package/dist/components/viewers/svg-viewer/svg-viewer.class.js +1 -1
- package/dist/components/viewers/xml-viewer/xml-viewer.class.js +2 -2
- package/dist/data-sources.d.ts +10 -0
- package/dist/events.d.ts +18 -4
- package/dist/framework-types.d.ts +1 -1
- package/dist/internal/default-strings/conversation.generated.js +1 -1
- package/dist/internal/default-strings/data.generated.js +1 -1
- package/dist/internal/default-strings/retrieval.generated.js +1 -1
- package/dist/internal/localization-types.d.ts +1 -1
- package/dist/internal/localization.js +1 -1
- package/dist/internal/lyra-element.js +2 -2
- package/dist/internal/native-modal-context.js +1 -1
- package/dist/internal/overlay-manager.js +1 -1
- package/dist/internal/overlay-order.js +1 -1
- package/dist/internal/overlay-stack.js +1 -1
- package/dist/internal/package-metadata.js +1 -1
- package/dist/internal/runtime-diagnostics.js +1 -0
- package/dist/internal/sizes.styles.js +1 -1
- package/dist/internal/source-cursor-controller.js +1 -0
- package/dist/internal/source-cursor-projection.js +1 -0
- package/dist/internal/source-page-scope.js +1 -1
- package/dist/lyra.d.ts +1 -1
- package/dist/theme/theme-bootstrap.js +1 -1
- package/dist/theme/theme.js +1 -1
- package/dist/utilities/overlay-manager.d.ts +2 -0
- package/llms/components/lr-budget-meter.md +31 -0
- package/llms/components/lr-chat-composer.md +13 -2
- package/llms/components/lr-combobox.md +27 -1
- package/llms/components/lr-diff-view.md +6 -0
- package/llms/components/lr-document-library.md +90 -6
- package/llms/components/lr-graph.md +5 -0
- package/llms/components/lr-ingestion-queue.md +76 -8
- package/llms/components/lr-json-viewer.md +34 -0
- package/llms/components/lr-lite-chart.md +2 -1
- package/llms/components/lr-map.md +33 -0
- package/llms/components/lr-message-feedback.md +38 -3
- package/llms/components/lr-page.md +4 -2
- package/llms/components/lr-prompt-input.md +5 -2
- package/llms/components/lr-segmented.md +30 -10
- package/llms/components/lr-sequence-playback.md +47 -12
- package/llms/components/lr-tree-item.md +1 -1
- package/llms/components/lr-tree.md +59 -7
- package/llms/components/lr-virtual-list.md +3 -1
- package/llms/peers.md +2 -2
- package/llms/shared/ai-and-peers.md +10 -1
- package/llms/shared/events-and-types.md +61 -2
- package/llms/shared/forms-and-accessibility.md +25 -0
- package/llms/shared/imports-and-registration.md +154 -110
- package/llms/shared/testing-and-utilities.md +5 -1
- package/llms/shared.md +255 -114
- package/locales.json +1 -1
- package/package.json +9 -9
- package/registrations.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import{__decorate}from"tslib";import{HierarchySourceController,hierarchyField,hierarchyKey,hierarchyText}from"../../../internal/hierarchy-source-controller.js";import{hierarchySourceView}from"../../../internal/hierarchy-source-view.js";import{hierarchySourceStyles}from"../../../internal/hierarchy-source-view.styles.js";import{AnnouncementSinkController}from"../../../internal/announcer.js";import{inheritedPreference,preferenceMediaMatches}from"../../../internal/preferences.js";import{finiteCount}from"../../../internal/numbers.js";import{eventCollectionSupport}from"../../../internal/collection-snapshot.js";import{html,nothing}from"lit";import{property,query,state}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{hostAriaLabel}from"../../../internal/a11y.js";import{devWarnOnce}from"../../../internal/dev-mode-attribute-warning.js";import{tag}from"../../../internal/prefix.js";import{resolveListMove}from"../../../internal/list-navigation.js";import{styles}from"./tree.styles.js";import{cascadeUpdateComplete}from"./update-cascade.js";import{configureTreeItemOwner,withTreeItemMotionPreference,fromInteractiveDescendant,setTreeItemSelection,treeItemOwnerContext}from"./tree-owner-controller.js";import"./tree-item.class.js";import{TREE_MAX_RENDER_DEPTH,TREE_MAX_RENDER_NODES}from"./tree-types.js";import{composedParentElement,deepActiveElementIn}from"../../../internal/active-element.js";import{LYRA_DEFAULT_treeLimit}from"../../../internal/default-strings/data.generated.js";import{LYRA_DEFAULT_collapse,LYRA_DEFAULT_expand,LYRA_DEFAULT_loading,LYRA_DEFAULT_noData,LYRA_DEFAULT_retry,LYRA_DEFAULT_treeNodeMoved,LYRA_DEFAULT_treeSourceError,LYRA_DEFAULT_treeSourceSummary}from"../../../internal/default-strings/shared.generated.js";const TREE_SELECTIONS=new Set(["single","multiple","leaf","leaf-multiple"]),TREE_BADGE_LIMIT=100,TREE_MAX_INSPECTED_POSITIONS=1e4,EMPTY_TREE_DATA=Object.freeze([]);function ownValue(record,key){try{const descriptor=Object.getOwnPropertyDescriptor(record,key);return descriptor&&"value"in descriptor?descriptor.value:void 0}catch{return}}function arrayLength(value){if(!Array.isArray(value))return 0;try{return Math.max(0,Math.min(Number.MAX_SAFE_INTEGER,Math.trunc(value.length)))}catch{return 0}}function normalizeBadges(value){if(!Array.isArray(value))return{truncated:value!==void 0};const badges=[],length=arrayLength(value);for(let index=0;index<Math.min(length,TREE_BADGE_LIMIT);index++){const raw=ownValue(value,String(index));if(!raw||typeof raw!="object"||Array.isArray(raw))continue;const text=ownValue(raw,"text");if(typeof text!="string")continue;const rawTone=ownValue(raw,"tone"),tone=rawTone==="brand"||rawTone==="success"||rawTone==="warning"||rawTone==="danger"?rawTone:"neutral",rawLabel=ownValue(raw,"label");badges.push(Object.freeze({text,tone,...typeof rawLabel=="string"?{label:rawLabel}:{}}))}return{badges:Object.freeze(badges),truncated:length>TREE_BADGE_LIMIT}}function sameIcon(left,right){if(Object.is(left,right))return!0;const a=left,b=right;if(!a||!b||typeof a!="object"||typeof b!="object"||a._$litType$===void 0||a._$litType$!==b._$litType$||a.strings!==b.strings)return!1;const leftValues=a.values??[],rightValues=b.values??[];return leftValues.length===rightValues.length&&leftValues.every((value,index)=>Object.is(value,rightValues[index]))}function sameBadges(left,right){return left===right?!0:!left||!right||left.length!==right.length?!1:left.every((badge,index)=>{const other=right[index];return badge.text===other.text&&badge.tone===other.tone&&badge.label===other.label})}function sameTreeNode(next,previous){if(next.id!==previous.id||next.label!==previous.label||next.selected!==previous.selected||next.disabled!==previous.disabled||next.lazy!==previous.lazy||next.description!==previous.description||next.accessibleLabel!==previous.accessibleLabel||!sameIcon(next.icon,previous.icon)||!sameBadges(next.badges,previous.badges))return!1;const children=next.children,previousChildren=previous.children;return!children||!previousChildren?children===void 0&&previousChildren===void 0:children.length===previousChildren.length&&children.every((child,index)=>child===previousChildren[index])}function indexTreeNodes(nodes){const byId=new Map,stack=[...nodes];for(;stack.length>0;){const node=stack.pop();byId.set(node.id,node),node.children&&stack.push(...node.children)}return byId}function normalizeTreeData(input,previous=EMPTY_TREE_DATA,limit=TREE_MAX_RENDER_NODES){if(!Array.isArray(input))return{data:EMPTY_TREE_DATA,declaredChildrenAtPath:new Map,declaredRootCount:0,truncated:input!=null,limitReached:!1};const root=[],declaredChildrenAtPath=new Map,created=[],rootLength=arrayLength(input);let truncated=!1,limitReached=!1,accepted=0,inspected=0;const seenIds=new Set,identityFilteredCollections=new Set,jobs=[{source:input,index:0,length:rootLength,target:root,parentPath:"",depth:0,ancestors:new Set}];for(;jobs.length>0;){const job=jobs[jobs.length-1];if(job.index>=job.length){jobs.pop();continue}if(accepted>=limit||inspected>=TREE_MAX_INSPECTED_POSITIONS){truncated=!0,limitReached=accepted>=limit;break}const raw=ownValue(job.source,String(job.index++));if(inspected++,inspected===TREE_MAX_INSPECTED_POSITIONS&&(truncated=!0),!raw||typeof raw!="object"||Array.isArray(raw)){truncated=!0,identityFilteredCollections.add(job.target);continue}const id=ownValue(raw,"id"),label=ownValue(raw,"label");if(typeof id!="string"||id.trim()===""||seenIds.has(id)||typeof label!="string"){truncated=!0,identityFilteredCollections.add(job.target);continue}seenIds.add(id);const node={id,label},selected=ownValue(raw,"selected"),disabled=ownValue(raw,"disabled"),lazy=ownValue(raw,"lazy");typeof selected=="boolean"&&(node.selected=selected),typeof disabled=="boolean"&&(node.disabled=disabled),typeof lazy=="boolean"&&(node.lazy=lazy);const icon=ownValue(raw,"icon");icon!==void 0&&(node.icon=icon);const description=ownValue(raw,"description");typeof description=="string"&&(node.description=description);const accessibleLabel=ownValue(raw,"accessibleLabel");typeof accessibleLabel=="string"&&(node.accessibleLabel=accessibleLabel);const normalizedBadges=normalizeBadges(ownValue(raw,"badges"));normalizedBadges.badges?.length&&(node.badges=normalizedBadges.badges),truncated||=normalizedBadges.truncated;const ownIndex=job.target.length,path=job.parentPath===""?String(ownIndex):`${job.parentPath}/${ownIndex}`;job.target.push(node),created.push(node),accepted++;const rawChildren=ownValue(raw,"children"),childCount=arrayLength(rawChildren);if(childCount===0)continue;if(declaredChildrenAtPath.set(path,childCount),job.depth>=TREE_MAX_RENDER_DEPTH||job.ancestors.has(raw)){truncated=!0;continue}const children=[];node.children=children;const ancestors=new Set(job.ancestors);ancestors.add(raw),jobs.push({source:rawChildren,index:0,length:childCount,target:children,parentPath:path,depth:job.depth+1,ancestors})}const previousById=previous.length>0?indexTreeNodes(previous):void 0,resolved=new Map,resolve=node=>resolved.get(node)??node;for(let index=created.length-1;index>=0;index--){const node=created[index];if(node.children){for(let child=0;child<node.children.length;child++)node.children[child]=resolve(node.children[child]);Object.freeze(node.children)}Object.freeze(node);const prior=previousById?.get(node.id);prior&&!(node.children&&identityFilteredCollections.has(node.children))&&sameTreeNode(node,prior)&&resolved.set(node,prior)}for(let index=0;index<root.length;index++)root[index]=resolve(root[index]);const normalizedJobs=root.map((node,index)=>({node,path:String(index)}));for(;normalizedJobs.length>0;){const{node,path}=normalizedJobs.pop(),children=node.children??[];identityFilteredCollections.has(children)&&declaredChildrenAtPath.set(path,children.length);for(let index=children.length-1;index>=0;index--)normalizedJobs.push({node:children[index],path:`${path}/${index}`})}return{data:Object.freeze(root),declaredChildrenAtPath,declaredRootCount:identityFilteredCollections.has(root)?root.length:rootLength,truncated,limitReached}}function isInertWithin(node,root){for(let current=node;current&¤t!==root;current=current.parentElement)if(current.hasAttribute("inert"))return!0;return!1}class LyraTree extends LyraElement{constructor(){super(...arguments),this._treeSource=void 0,this.sourceMode=!1,this.sourcePaintVersion=0,this.sourceAnnouncer=new AnnouncementSinkController(this),this.hierarchy=new HierarchySourceController(this,{normalize:(value,key)=>this.normalizeSourceValue(value,key),onChange:()=>{const previous=this.sourcePaintVersion++;this.requestUpdate("sourcePaintVersion",previous)},accepted:(action,_row,state2)=>{action.type==="select"&&this.emit("lr-source-selection-change",Object.freeze({key:action.key,selected:action.selected,scope:action.scope,state:state2}))}}),this._data=EMPTY_TREE_DATA,this.lastDataInput=void 0,this.lastDataLimit=0,this.declaredChildrenAtPath=new Map,this.declaredRootCount=0,this._dataTruncated=!1,this._limitReached=!1,this.label="",this.maxNodes=1e3,this.reorderable=!1,this._selection="single",this._activeId=null,this.readActiveId=()=>this._activeId,this.hasAuthoredItems=!1,this.pendingFocusId=null,this.generatedNodes=new WeakSet,this.dataIdOwnerPaths=new Map,this.dataIdCollisions=new Set,this.selectionSyncPending=!0,this.dataSyncPending=!1,this.inertMutationPending=!1,this.dirtyConfigureRoots=new Set,this.lastFocusedNodeId=null,this.onTreeFocusIn=e=>{const path=e.composedPath(),owner=path.find(target=>target.localName===tag("tree"));if(owner&&owner!==this)return;const item=path.find(target=>target.nodeType===1&&target.localName===tag("tree-item"));item&&this.onItemFocus(item)},this.onItemFocus=element=>{const item=element;this.isNavigable(item)&&(this.lastFocusedNodeId=item.nodeId,this.setActiveNode(item))},this.contextSyncPending=!0,this.bulkExpansions=0,this.syncGeneration=0,this.syncRequested=!1,this.syncRunning=!1,this.requestContextSync=()=>{this.contextSyncPending=!0,this.scheduleTreeSync()},this.onChildrenChanged=()=>{if(this.treeSource!==void 0)return;const wasAuthored=this.hasAuthoredItems;this.refreshAuthoredItems(),wasAuthored&&!this.hasAuthoredItems&&(this.dataSyncPending=!0),this.selectionSyncPending=!0,this.requestUpdate()},this.childObserverGeneration=0,this.onChildMutations=allRecords=>{const records=allRecords.filter(record=>record.type!=="attributes"||record.oldValue!==null!==record.target.hasAttribute(record.attributeName??""));if(records.length!==0){if(records.some(record=>record.attributeName==="inert")&&(this.inertMutationPending=!0),records.every(record=>record.type==="attributes")){const itemTag=tag("tree-item");for(const record of records){const target=record.target;if(!(target instanceof Element)||target.localName!==itemTag)continue;const root=this.rootTreeItemAncestor(target);root&&this.dirtyConfigureRoots.add(root)}}else this.dirtyConfigureRoots.clear();this.onChildrenChanged()}},this.onNodeActivate=e=>{const node=this.eventNode(e);if(!node||node.isDisabled)return;this.selectionSyncPending=!0,this.bulkExpansions>0?this.syncRequested=!0:this.requestUpdate();const expanded=e.detail?.expanded===!0;(this.focusIsWithin(node)||!expanded&&this.activeId!==node.nodeId&&this.subtreeHasId(node,this.activeId))&&this.setActiveNode(node)},this.onNodeSelect=event=>{const node=this.eventNode(event);!node||node.isDisabled||(this.setActiveNode(node),this.updateSelectionFrom(node)&&this.emit("lr-selection-change",Object.freeze({selection:this.selectedItems})))},this.onTreeKeyDown=e=>{const itemTag=tag("tree-item");if(fromInteractiveDescendant(e,target=>target.localName===itemTag))return;const visible=this.visibleNodeElements();if(visible.length===0)return;const currentIndex=visible.findIndex(n=>n.nodeId===this.activeId),current=currentIndex>=0?visible[currentIndex]:visible[0];if(!current)return;if(this.reorderable&&(e.ctrlKey||e.metaKey)&&(e.key==="ArrowUp"||e.key==="ArrowDown")){e.preventDefault(),this.requestReorder(current,e.key==="ArrowDown"?1:-1);return}if(e.altKey)return;const rtl=this.effectiveDirection==="rtl",expandKey=rtl?"ArrowLeft":"ArrowRight",collapseKey=rtl?"ArrowRight":"ArrowLeft",moved=resolveListMove(e.key,{count:visible.length,current:Math.max(currentIndex,0),orientation:"vertical",wrap:!1,clamp:!0});if(moved!==null){e.preventDefault(),this.focusNode(visible[moved]);return}switch(e.key){case expandKey:if(e.preventDefault(),!current.hasChildren)break;if(!current.expanded)current.expand();else{const child=visible[currentIndex+1];child&&treeItemOwnerContext(child).depth>treeItemOwnerContext(current).depth&&this.focusNode(child)}break;case collapseKey:if(e.preventDefault(),current.hasChildren&¤t.expanded)current.collapse();else for(let i=currentIndex-1;i>=0;i--){const sibling=visible[i];if(sibling&&treeItemOwnerContext(sibling).depth<treeItemOwnerContext(current).depth){this.focusNode(sibling);break}}break;case"Enter":case" ":e.preventDefault(),current.select();break;default:return}}}static{this.defaultStrings={...super.defaultStrings,collapse:LYRA_DEFAULT_collapse,expand:LYRA_DEFAULT_expand,loading:LYRA_DEFAULT_loading,noData:LYRA_DEFAULT_noData,retry:LYRA_DEFAULT_retry,treeLimit:LYRA_DEFAULT_treeLimit,treeNodeMoved:LYRA_DEFAULT_treeNodeMoved,treeSourceError:LYRA_DEFAULT_treeSourceError,treeSourceSummary:LYRA_DEFAULT_treeSourceSummary}}static{this.collectionSupport=eventCollectionSupport}static{this.immutableEventDetails=Object.freeze(["lr-selection-change"])}static{this.identityEventDetailProperties=Object.freeze({"lr-selection-change":Object.freeze(["selection"])})}static{this.styles=[LyraElement.styles,styles,hierarchySourceStyles]}get treeSource(){return this._treeSource}set treeSource(value){const previous=this._treeSource;this._treeSource=value,this.hierarchy?.update(value,this.effectiveLocale,!0),this.requestUpdate("treeSource",previous)}revealSourceKey(key){return this.treeSource===void 0?Promise.resolve(!1):this.hierarchy.reveal(key)}normalizeSourceValue(value,key){const id=hierarchyKey(hierarchyField(value,"id"));if(id!==key)throw new TypeError("Hierarchy domain key mismatch");const label=hierarchyText(hierarchyField(value,"label")),description=hierarchyText(hierarchyField(value,"description")),accessibleLabel=hierarchyText(hierarchyField(value,"accessibleLabel")),normalized=normalizeBadges(hierarchyField(value,"badges"));let units=label.length+description.length+accessibleLabel.length;for(const badge of normalized.badges??[])units+=badge.text.length+(badge.label?.length??0);if(normalized.truncated||units>65536)throw new RangeError("Hierarchy display value exceeds its row budget");return Object.freeze({id,label,description,accessibleLabel,icon:hierarchyField(value,"icon"),badges:normalized.badges})}announceSource(){const status=this.hierarchy.error?this.localize("treeSourceError"):this.hierarchy.loading?this.localize("loading"):this.sourceSummary();this.sourceAnnouncement!==void 0&&status!==this.sourceAnnouncement&&this.sourceAnnouncer.announce(status),this.sourceAnnouncement=status,this.hierarchy.rowsObserved&&this.sourceAnnouncer.transition("source-rows",this.hierarchy.rowError?"error":"ready",this.hierarchy.rowError?this.localize("treeSourceError"):"")}sourceSummary(){const projection=this.hierarchy.projection;return projection?this.localize("treeSourceSummary",void 0,{visible:getNumberFormat(this.effectiveLocale).format(projection.rows.count),total:getNumberFormat(this.effectiveLocale).format(projection.total)}):""}get data(){return this._data}set data(value){if((value===this._data||value===this.lastDataInput)&&this.lastDataLimit===this.effectiveMaxNodes)return;this.lastDataInput=value,this.lastDataLimit=this.effectiveMaxNodes,this.hasUpdated&&this.selectionBeforeRefresh===void 0&&(this.selectionBeforeRefresh=this.selectedItems.map(item=>item.nodeId));const previous=this._data,normalized=normalizeTreeData(value,this._data,this.effectiveMaxNodes);this._data=normalized.data,this.declaredChildrenAtPath=normalized.declaredChildrenAtPath,this.declaredRootCount=normalized.declaredRootCount,this._dataTruncated=normalized.truncated,this._limitReached=normalized.limitReached,this.requestUpdate("data",previous)}get dataTruncated(){return this._dataTruncated}get effectiveMaxNodes(){return Math.max(1,Math.min(1e4,finiteCount(this.maxNodes,1e3)))}get selection(){return this._selection}set selection(value){const old=this._selection,normalized=TREE_SELECTIONS.has(value)?value:"single";old!==normalized&&(this._selection=normalized,this.selectionSyncPending=!0,this.requestUpdate("selection",old))}get activeId(){return this._activeId}set activeId(value){value!==this._activeId&&(this.activeNode&&(this.activeNode.tabIndex=-1),this.activeNode=void 0,this._activeId=value)}setActiveNode(node){this.activeId=node?.nodeId??null,this.activeNode!==node&&this.activeNode&&(this.activeNode.tabIndex=-1),this.activeNode=node,node&&(node.tabIndex=this.isNavigable(node)?0:-1)}get nodeWalkLimit(){return this.hasAuthoredItems?Number.POSITIVE_INFINITY:this.effectiveMaxNodes}get nodeElements(){return[...this.querySelectorAll(`:scope > ${tag("tree-item")}`)]}childrenOf(node){return node.childItems()}isNavigable(node){return!node.isDisabled&&!isInertWithin(node,this)}allNodeElements(){const result=[],seen=new Set,stack=this.nodeElements.map(node=>({node,depth:0})).reverse();for(;stack.length>0&&result.length<this.nodeWalkLimit;){const{node,depth}=stack.pop();if(seen.has(node)||(seen.add(node),result.push(node),depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(node);for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}return result}get selectedItems(){return this.treeSource!==void 0?Object.freeze([]):Object.freeze(this.allNodeElements().filter(node=>node.selected))}iconSource(name){return this.querySelector(`:scope > [slot="${name}"]`)}applyTreeContext(){const expandIcon=this.iconSource("expand-icon"),collapseIcon=this.iconSource("collapse-icon"),roots=this.nodeElements,rootCount=this.hasAuthoredItems?roots.length:this.declaredRootCount,stack=[];for(let index=roots.length-1;index>=0;index--)stack.push({node:roots[index],ancestry:[],depth:0,setSize:rootCount,posInSet:index+1,identity:this.hasAuthoredItems?void 0:this.treeIdentityAt(String(index))});const seen=new Set;for(;stack.length>0&&seen.size<this.nodeWalkLimit;){const frame=stack.pop();if(seen.has(frame.node)||(seen.add(frame.node),frame.node.nodeId===this.activeId&&this.setActiveNode(frame.node),configureTreeItemOwner(frame.node,{...treeItemOwnerContext(frame.node),activeId:null,activeNodeId:this.readActiveId,ancestry:frame.ancestry,depth:frame.depth,setSize:frame.setSize,posInSet:frame.posInSet,selection:this.selection,ownsSelection:!0,identity:frame.identity,expandIcon,collapseIcon,syncOwner:this.requestContextSync,focusOwner:this.onItemFocus}),frame.depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(frame.node),declaredCount=frame.identity?.declaredChildrenAtPath.get(frame.identity.path)??frame.node.item?.children?.length??children.length,childAncestry=frame.node.item?[...frame.ancestry,frame.node.item]:frame.ancestry;for(let index=children.length-1;index>=0;index--){const identity=frame.identity?{path:`${frame.identity.path}/${index}`,ownerPaths:frame.identity.ownerPaths,collisionIds:frame.identity.collisionIds,declaredChildrenAtPath:frame.identity.declaredChildrenAtPath}:void 0;stack.push({node:children[index],ancestry:childAncestry,depth:frame.depth+1,setSize:declaredCount,posInSet:index+1,identity})}}}selectableInSingleMode(node){return!node.isDisabled&&(this.selection!=="leaf"||!node.hasChildren)}normalizeSingleSelection(){let kept=!1;for(const node of this.allNodeElements()){const selected=!kept&&node.selected&&this.selectableInSingleMode(node);this.setSelection(node,selected,!1),selected&&(kept=!0)}}setBranchSelection(node,selected,leavesOnly){const stack=[{node,depth:treeItemOwnerContext(node).depth}],seen=new Set;for(;stack.length>0&&seen.size<this.nodeWalkLimit;){const{node:current,depth}=stack.pop();if(seen.has(current)||current.isDisabled)continue;seen.add(current);const children=this.childrenOf(current).filter(child=>!child.isDisabled);if(!leavesOnly||children.length===0?this.setSelection(current,leavesOnly&¤t.hasChildren?!1:selected,!1):this.setSelection(current,!1,!1),depth<TREE_MAX_RENDER_DEPTH)for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}}deriveMultipleSelection(node,leavesOnly){const states=new Map,stack=[{item:node,visited:!1,depth:0}],queued=new Set;for(;stack.length>0;){const entry=stack.pop();if(entry.visited){const current=entry.item;if(current.isDisabled){this.setSelection(current,!1,!1),states.set(current,"ignored");continue}const children2=this.childrenOf(current).filter(child=>!child.isDisabled);if(children2.length===0){leavesOnly&¤t.hasChildren?(this.setSelection(current,!1,!1),states.set(current,"none")):(this.setSelection(current,current.selected,!1),states.set(current,current.selected?"all":"none"));continue}const childStates=children2.map(child=>states.get(child)??"ignored").filter(state2=>state2!=="ignored");if(childStates.length===0){this.setSelection(current,!1,!1),states.set(current,"none");continue}const all=childStates.every(state2=>state2==="all"),none=childStates.every(state2=>state2==="none");this.setSelection(current,all,!all&&!none),states.set(current,all?"all":none?"none":"some");continue}if(queued.size>=this.nodeWalkLimit||queued.has(entry.item)||(queued.add(entry.item),stack.push({...entry,visited:!0}),entry.depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(entry.item);for(let index=children.length-1;index>=0;index--)queued.has(children[index])||stack.push({item:children[index],visited:!1,depth:entry.depth+1})}return states.get(node)??"none"}normalizeMultipleSelection(){const leavesOnly=this.selection==="leaf-multiple";for(const node of this.allNodeElements())node.selected&&this.childrenOf(node).length>0&&this.setBranchSelection(node,!0,leavesOnly);for(const root of this.nodeElements)this.deriveMultipleSelection(root,leavesOnly)}normalizeSelection(){this.selection==="single"||this.selection==="leaf"?this.normalizeSingleSelection():this.normalizeMultipleSelection()}setSelection(node,selected,indeterminate){this.selectionBefore&&!this.selectionBefore.has(node)&&this.selectionBefore.set(node,[node.selected,node.indeterminate]),setTreeItemSelection(node,selected,indeterminate)}updateSelectionFrom(node){if(node.isDisabled||(this.selection==="single"||this.selection==="leaf")&&!this.selectableInSingleMode(node))return!1;const before=new Map;this.selectionBefore=before;try{if(this.selection==="single"||this.selection==="leaf")for(const candidate of this.allNodeElements())this.setSelection(candidate,candidate===node,!1);else{const select=node.indeterminate||!node.selected;this.setBranchSelection(node,select,this.selection==="leaf-multiple");for(const root of this.nodeElements)this.deriveMultipleSelection(root,this.selection==="leaf-multiple")}}finally{this.selectionBefore=void 0}for(const[candidate,[selected,indeterminate]]of before)if(candidate.selected!==selected||candidate.indeterminate!==indeterminate)return!0;return!1}refreshAuthoredItems(){const nodes=this.nodeElements;for(const node of nodes)node.hasAttribute("slot")&&node.removeAttribute("slot");const authored=nodes.some(node=>!this.generatedNodes.has(node));if(authored)for(const node of nodes)this.generatedNodes.has(node)&&node.remove();this.hasAuthoredItems=authored}visibleNodeElements(){const acc=[],seen=new Set,stack=this.nodeElements.map(node=>({node,depth:0})).reverse();for(;stack.length>0&&acc.length<this.nodeWalkLimit;){const{node,depth}=stack.pop();if(seen.has(node)||(seen.add(node),!this.isNavigable(node))||(acc.push(node),!node.expanded||depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(node);for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}return acc}findItem(items,id){const stack=[...items].reverse(),seen=new Set;for(;stack.length>0;){const item=stack.pop();if(!seen.has(item)){if(seen.add(item),item.id===id)return item;if(item.children)for(let i=item.children.length-1;i>=0;i--){const child=item.children[i];child&&stack.push(child)}}}}isDuplicateDataPath(item,path){return this.dataIdCollisions.has(item.id)&&this.dataIdOwnerPaths.get(item.id)!==path}rebuildDataIdentity(){const ownerPaths=new Map,collisionIds=new Set,ancestry=new Set,stack=[{items:this.data,index:0,parentPath:"",depth:0}];for(;stack.length>0;){const frame=stack[stack.length-1];if(frame.index>=frame.items.length){frame.owner&&ancestry.delete(frame.owner),stack.pop();continue}const index=frame.index++,item=frame.items[index];if(!item)continue;const path=frame.parentPath===""?String(index):`${frame.parentPath}/${index}`;ownerPaths.has(item.id)?collisionIds.add(item.id):ownerPaths.set(item.id,path),!(frame.depth>=TREE_MAX_RENDER_DEPTH||ancestry.has(item)||!item.children?.length)&&(ancestry.add(item),stack.push({items:item.children,index:0,parentPath:path,depth:frame.depth+1,owner:item}))}this.dataIdOwnerPaths=ownerPaths,this.dataIdCollisions=collisionIds}treeIdentityAt(path){return{path,ownerPaths:this.dataIdOwnerPaths,collisionIds:this.dataIdCollisions,declaredChildrenAtPath:this.declaredChildrenAtPath}}firstEnabledId(items){for(let index=0;index<items.length;index++){const item=items[index];if(!(!item||item.disabled||this.isDuplicateDataPath(item,String(index))))return item.id}return null}isEnabledReachableId(items,id){const stack=items.map((item,index)=>({item,path:String(index)})).reverse(),seen=new Set;for(;stack.length>0;){const{item,path}=stack.pop();if(!seen.has(item)&&(seen.add(item),!(item.disabled||this.isDuplicateDataPath(item,path)))){if(item.id===id)return!0;if(item.children)for(let i=item.children.length-1;i>=0;i--){const child=item.children[i];child&&stack.push({item:child,path:`${path}/${i}`})}}}return!1}findRenderedSiblings(node){const root=node.getRootNode(),shadowHost="host"in root?root.host:null,shadowParent=shadowHost?.localName===tag("tree-item")?shadowHost:null,lightParent=node.parentElement?.localName===tag("tree-item")?node.parentElement:null,parentItem=shadowParent??lightParent,siblings=parentItem?parentItem.childItems():this.nodeElements,index=siblings.indexOf(node);if(!(index<0))return{parent:parentItem,siblings,index}}deepFocusedNode(){const active=deepActiveElementIn(this.ownerDocument);if(!active||active.localName!==tag("tree-item"))return null;const node=active;return this.visibleNodeElements().some(n=>n.nodeId===node.nodeId)?node:null}resolveActiveFromDom(){const inertMutation=this.inertMutationPending;this.inertMutationPending=!1;const visible=this.visibleNodeElements(),current=visible.find(node=>node.nodeId===this.activeId);if(current){this.setActiveNode(current);return}const displaced=this.activeId;if(this.setActiveNode(visible[0]),!inertMutation||this.activeId==null||displaced==null||displaced!==this.lastFocusedNodeId)return;const ownerDocument=this.ownerDocument,active=deepActiveElementIn(ownerDocument),strandedOnDisplaced=active?.nodeType===1&&active.localName===tag("tree-item")&&active.nodeId===displaced;active!==null&&active!==ownerDocument.body&&!strandedOnDisplaced||(this.pendingFocusId=this.activeId)}requestUpdate(name,oldValue){name===void 0&&this._treeSource!==void 0&&this.hierarchy?.update(this._treeSource,this.effectiveLocale,!0),super.requestUpdate(name,oldValue)}willUpdate(changed){if(super.willUpdate(changed),this.hierarchy.update(this.treeSource,this.effectiveLocale),this.treeSource!==void 0){if(!this.sourceMode){this.sourceMode=!0,this.resetChildObserver(),this.pendingFocusId=null,this.pendingReorder=void 0,this.selectionBeforeRefresh=void 0,this.syncRequested=!1,this.syncGeneration++,this.syncRunning=!1,this.syncTask=void 0;for(const node of this.nodeElements)this.generatedNodes.has(node)&&node.remove()}return}if(this.sourceMode&&(this.sourceMode=!1,this.sourceAnnouncement=void 0,this.dataSyncPending=!0,this.selectionSyncPending=!0,this.armChildObserver()),changed.has("maxNodes")&&this.hasUpdated&&!changed.has("data")&&(this.data=this.data),this.refreshAuthoredItems(),(changed.has("data")||changed.has("selection"))&&(this.selectionSyncPending=!0),this.hasAuthoredItems){this.resolveActiveFromDom();return}if(changed.has("data")||this.dataSyncPending){this.dataSyncPending=!1;const focused=this.deepFocusedNode(),focusedId=focused?.nodeId??null;this.rebuildDataIdentity(),this.syncNodes();const activeItem=this.activeId?this.findItem(this.data,this.activeId):void 0;(!this.activeId||!activeItem||activeItem.disabled||!this.isEnabledReachableId(this.data,this.activeId))&&(this.activeId=this.firstEnabledId(this.data)),this.pendingFocusId=focused==null?null:focusedId!=null&&this.findItem(this.data,focusedId)?focusedId:this.activeId}this.inertMutationPending&&this.resolveActiveFromDom()}firstUpdated(changed){super.firstUpdated(changed),hostAriaLabel(this)==null&&!this.label&&devWarnOnce("lyra-tree-missing-accessible-name","<lr-tree> has no accessible name: set `label` or a host `aria-label`.")}updated(changed){if(super.updated(changed),this.treeSource!==void 0){this.announceSource();return}const targeted=changed.size===0&&this.hasAuthoredItems&&this.dirtyConfigureRoots.size>0;if(targeted){const nodes=this.nodeElements,count=nodes.length,positions=this.dirtyConfigureRoots.size>1?new Map(nodes.map((node,index)=>[node,index])):void 0;for(const node of this.dirtyConfigureRoots){const i=positions?positions.get(node)??-1:nodes.indexOf(node);i<0||configureTreeItemOwner(node,{...treeItemOwnerContext(node),activeId:null,activeNodeId:this.readActiveId,ancestry:[],depth:0,setSize:count,posInSet:i+1,selection:this.selection,ownsSelection:!0,identity:void 0,expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),syncOwner:this.requestContextSync,focusOwner:this.onItemFocus})}}else if(changed.has("activeId")||changed.has("data")||this.hasAuthoredItems){const nodes=this.nodeElements,count=this.hasAuthoredItems?nodes.length:this.declaredRootCount;nodes.forEach((node,i)=>{configureTreeItemOwner(node,{...treeItemOwnerContext(node),activeId:null,activeNodeId:this.readActiveId,ancestry:[],depth:0,setSize:count,posInSet:i+1,selection:this.selection,ownsSelection:!0,identity:this.hasAuthoredItems?void 0:this.treeIdentityAt(String(i)),expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),syncOwner:this.requestContextSync,focusOwner:this.onItemFocus})})}targeted||(this.contextSyncPending=!0),this.dirtyConfigureRoots.clear(),this.scheduleTreeSync()}scheduleTreeSync(){this.treeSource===void 0&&(this.syncRequested=!0,!(this.syncRunning||this.bulkExpansions>0)&&(this.syncRunning=!0,this.syncTask=this.runTreeSync()))}async runTreeSync(){const generation=this.syncGeneration;try{for(;this.syncRequested&&(this.syncRequested=!1,await super.getUpdateComplete(),!(this.treeSource!==void 0||generation!==this.syncGeneration||(await cascadeUpdateComplete(this.nodeElements),this.treeSource!==void 0||generation!==this.syncGeneration)||(this.contextSyncPending&&(this.contextSyncPending=!1,this.applyTreeContext()),this.selectionSyncPending&&(this.selectionSyncPending=!1,this.normalizeSelection()),await cascadeUpdateComplete(this.nodeElements),this.treeSource!==void 0||generation!==this.syncGeneration)));)this.reportRefreshSelectionChange(),this.confirmPendingReorder(),this.restorePendingFocus()}finally{generation===this.syncGeneration&&(this.syncRunning=!1)}}rootTreeItemAncestor(node){const itemTag=tag("tree-item");let current=node;for(;current&¤t.parentElement&¤t.parentElement!==this;)current=current.parentElement;return current&¤t.parentElement===this&¤t.localName===itemTag?current:null}connectedCallback(){super.connectedCallback(),this.armChildObserver()}armChildObserver(){const ownerDocument=this.ownerDocument;if(!this.isConnected||this.treeSource!==void 0||this.childObserver&&this.childObserverDocument===ownerDocument)return;this.resetChildObserver();const MutationObserverCtor=ownerDocument.defaultView?.MutationObserver;if(!MutationObserverCtor)return;const generation=this.childObserverGeneration,observer=new MutationObserverCtor(records=>{this.childObserver!==observer||this.childObserverDocument!==ownerDocument||this.childObserverGeneration!==generation||!this.isConnected||this.ownerDocument!==ownerDocument||this.onChildMutations(records)});this.childObserver=observer,this.childObserverDocument=ownerDocument,observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["selected","disabled","inert","lazy"]})}disconnectedCallback(){super.disconnectedCallback(),this.sourceAnnouncement=void 0,this.pendingReorder=void 0,this.activeNode=void 0,this.resetChildObserver()}adoptedCallback(){super.adoptedCallback(),this.hierarchy.adopted(),this.resetChildObserver()}resetChildObserver(){this.childObserverGeneration+=1,this.childObserver?.disconnect(),this.childObserver=void 0,this.childObserverDocument=void 0}syncNodes(){const existingById=new Map;for(const node of this.nodeElements){if(!node.item)continue;const matches=existingById.get(node.item.id)??[];matches.push(node),existingById.set(node.item.id,matches)}let previousSibling=null;for(let index=0;index<this.data.length;index++){const item=this.data[index];let node=existingById.get(item.id)?.shift();node||(node=this.ownerDocument.createElement(tag("tree-item")),this.generatedNodes.add(node)),node.item=item,configureTreeItemOwner(node,{...treeItemOwnerContext(node),ancestry:[],depth:0,setSize:this.declaredRootCount,posInSet:index+1,selection:this.selection,ownsSelection:!0,identity:this.treeIdentityAt(String(index)),expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),syncOwner:this.requestContextSync,focusOwner:this.onItemFocus});const targetPosition=previousSibling?previousSibling.nextElementSibling:this.firstElementChild;targetPosition!==node&&this.insertBefore(node,targetPosition),previousSibling=node}for(const nodes of existingById.values())for(const node of nodes)node.remove()}focusNode(node){node&&(this.setActiveNode(node),node.focus())}subtreeHasId(root,id){if(id==null)return!1;const stack=this.childrenOf(root).map(item=>({item,depth:treeItemOwnerContext(root).depth+1}));for(let visited=0;stack.length>0&&visited<this.nodeWalkLimit;visited++){const{item,depth}=stack.pop();if(!(depth>TREE_MAX_RENDER_DEPTH)){if(item.nodeId===id)return!0;depth<TREE_MAX_RENDER_DEPTH&&stack.push(...this.childrenOf(item).map(child=>({item:child,depth:depth+1})))}}return!1}focusIsWithin(node){for(let current=deepActiveElementIn(this.ownerDocument);current;current=composedParentElement(current)){if(current===node)return!0;if(current===this)return!1}return!1}eventNode(e){const path=e.composedPath(),origin=path[0];if(origin?.nodeType===1&&origin.localName===tag("tree-item")){const treeTag=tag("tree");for(const target of path){if(target===this)return origin;if(target.localName===treeTag)return}return}const id=e.detail?.nodeId;return this.allNodeElements().find(candidate=>candidate.nodeId===id)}async getUpdateComplete(){let result=await super.getUpdateComplete();if(this.treeSource!==void 0)return result;for(;this.syncRunning||this.isUpdatePending;)this.syncRunning&&await this.syncTask,result=await super.getUpdateComplete();return this.treeSource===void 0&&await cascadeUpdateComplete(this.nodeElements),result}reportRefreshSelectionChange(){const before=this.selectionBeforeRefresh;if(before===void 0||this.isUpdatePending)return;this.selectionBeforeRefresh=void 0;const selection=this.selectedItems;selection.length===before.length&&selection.every((item,index)=>item.nodeId===before[index])||this.emit("lr-selection-change",Object.freeze({selection}))}restorePendingFocus(){if(this.pendingFocusId==null)return;const id=this.pendingFocusId;this.pendingFocusId=null;const visible=this.visibleNodeElements();(visible.find(n=>n.nodeId===id)??visible.find(n=>n.nodeId===this.activeId))?.focus()}requestReorder(node,delta){const id=node.nodeId,found=this.findRenderedSiblings(node);if(!found)return;const{parent,siblings,index}=found,total=siblings.length,toIndex=index+delta;toIndex<0||toIndex>=total||(this.pendingReorder={node,parent,originalSiblings:[...siblings],targetSibling:siblings[toIndex],fromIndex:index,toIndex},this.emit("lr-reorder",{nodeId:id,parentNodeId:parent?.nodeId??null,fromIndex:index,toIndex}))}confirmPendingReorder(){const pending=this.pendingReorder;if(!pending)return;const found=this.findRenderedSiblings(pending.node);if(!found){this.pendingReorder=void 0;return}(found.siblings.length!==pending.originalSiblings.length||found.siblings.some((node,index)=>node!==pending.originalSiblings[index]))&&(this.pendingReorder=void 0,!(found.parent!==pending.parent||found.index!==pending.toIndex||found.siblings[pending.fromIndex]!==pending.targetSibling)&&this.liveRegion?.announce(this.localize("treeNodeMoved",void 0,{label:pending.node.nodeLabel,index:this.formatCount(found.index+1),total:this.formatCount(found.siblings.length)}),{force:!0}))}async expandAll(){if(this.treeSource!==void 0)return;let level=this.nodeElements.map(node=>({node,depth:0}));const seen=new Set,systemReduced=preferenceMediaMatches(this.ownerDocument.defaultView,"(prefers-reduced-motion: reduce)");this.bulkExpansions+=1;try{for(;level.length>0&&seen.size<this.nodeWalkLimit;){const current=[];for(const entry of level){const{node}=entry;if(!(seen.has(node)||seen.size>=this.nodeWalkLimit)){if(seen.add(node),current.push(entry),node.isDisabled)node.expanded=!1;else if(node.hasChildren){const reduced=systemReduced||inheritedPreference(node,"data-lr-motion","reduce")==="reduce";withTreeItemMotionPreference(node,reduced,()=>node.expand())}}}await Promise.all(current.map(({node})=>node.updateComplete)),level=[];for(const{node,depth}of current)depth<TREE_MAX_RENDER_DEPTH&&level.push(...this.childrenOf(node).map(child=>({node:child,depth:depth+1})))}}finally{this.bulkExpansions-=1}this.bulkExpansions===0&&this.syncRequested&&this.scheduleTreeSync(),await this.updateComplete}async collapseAll(){if(this.treeSource!==void 0)return;const focused=this.deepFocusedNode(),topLevel=this.nodeElements,nodes=this.allNodeElements();for(let index=nodes.length-1;index>=0;index--){const node=nodes[index];node.isDisabled?node.expanded=!1:node.collapse()}(this.hasAuthoredItems?topLevel.some(node=>this.isNavigable(node)&&node.nodeId===this.activeId):this.data.some(item=>!item.disabled&&item.id===this.activeId))||(this.activeId=this.hasAuthoredItems?topLevel.find(node=>this.isNavigable(node))?.nodeId??null:this.firstEnabledId(this.data)),focused&&(this.pendingFocusId=this.activeId),await cascadeUpdateComplete(topLevel)}render(){return this.treeSource!==void 0?hierarchySourceView(this.hierarchy,{label:hostAriaLabel(this)??this.label,rtl:this.effectiveDirection==="rtl",multiple:this.selection==="multiple"||this.selection==="leaf-multiple",loading:this.localize("loading"),error:this.localize("treeSourceError"),empty:this.localize("noData"),retry:this.localize("retry"),expand:this.localize("expand"),collapse:this.localize("collapse"),summary:this.sourceSummary(),name:value=>value.accessibleLabel||[value.label,value.description,...(value.badges??[]).map(badge=>badge.label?.trim()?badge.label:badge.text)].filter(text=>text?.trim()).join(" ")||value.id,content:value=>html`${value.icon??nothing}${value.label}${value.description?html` <span>${value.description}</span>`:nothing}${value.badges?.map(badge=>html` <span role=${badge.label?.trim()?"img":nothing} aria-label=${badge.label?.trim()?badge.label:nothing}>${badge.text}</span>`)}`,select:row=>{if((this.selection==="leaf"||this.selection==="leaf-multiple")&&row.childCount>0)return;const multiple=this.selection==="multiple"||this.selection==="leaf-multiple";this.hierarchy.project({type:"select",key:row.key,selected:multiple?!row.selected:!0,scope:multiple&&row.childCount>0?"subtree":"item"},!0,row)}}):html`
|
|
1
|
+
import{__decorate}from"tslib";import{HierarchySourceController,hierarchyField,hierarchyKey,hierarchyText}from"../../../internal/hierarchy-source-controller.js";import{hierarchySourceView}from"../../../internal/hierarchy-source-view.js";import{hierarchySourceStyles}from"../../../internal/hierarchy-source-view.styles.js";import{AnnouncementSinkController}from"../../../internal/announcer.js";import{inheritedPreference,preferenceMediaMatches}from"../../../internal/preferences.js";import{finiteCount}from"../../../internal/numbers.js";import{eventCollectionSupport}from"../../../internal/collection-snapshot.js";import{html,nothing}from"lit";import{property,query,state}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{hostAriaLabel}from"../../../internal/a11y.js";import{devWarnOnce}from"../../../internal/dev-mode-attribute-warning.js";import{normalizeReflectedOptionalSize,optionalSizeConverter}from"../../../internal/variants.js";import{tag}from"../../../internal/prefix.js";import{resolveListMove}from"../../../internal/list-navigation.js";import{TreePointerReorder}from"./tree-pointer-reorder.js";import{styles}from"./tree.styles.js";import{TreeDataExpansion}from"./tree-data-expansion.js";import{cascadeUpdateComplete}from"./update-cascade.js";import{configureTreeItemOwner,withTreeItemMotionPreference,fromInteractiveDescendant,setTreeItemSelection,treeItemOwnerContext}from"./tree-owner-controller.js";import"./tree-item.class.js";import{TREE_MAX_RENDER_DEPTH,TREE_MAX_RENDER_NODES}from"./tree-types.js";import{composedParentElement,deepActiveElementIn}from"../../../internal/active-element.js";import{LYRA_DEFAULT_treeLimit}from"../../../internal/default-strings/data.generated.js";import{LYRA_DEFAULT_collapse,LYRA_DEFAULT_expand,LYRA_DEFAULT_loading,LYRA_DEFAULT_noData,LYRA_DEFAULT_retry,LYRA_DEFAULT_treeNodeMoved,LYRA_DEFAULT_treeSourceError,LYRA_DEFAULT_treeSourceSummary}from"../../../internal/default-strings/shared.generated.js";const TREE_SELECTIONS=new Set(["single","multiple","leaf","leaf-multiple"]),TREE_BADGE_LIMIT=100,TREE_MAX_INSPECTED_POSITIONS=1e4,EMPTY_TREE_DATA=Object.freeze([]);function ownValue(record,key){try{const descriptor=Object.getOwnPropertyDescriptor(record,key);return descriptor&&"value"in descriptor?descriptor.value:void 0}catch{return}}function arrayLength(value){if(!Array.isArray(value))return 0;try{return Math.max(0,Math.min(Number.MAX_SAFE_INTEGER,Math.trunc(value.length)))}catch{return 0}}function normalizeBadges(value){if(!Array.isArray(value))return{truncated:value!==void 0};const badges=[],length=arrayLength(value);for(let index=0;index<Math.min(length,TREE_BADGE_LIMIT);index++){const raw=ownValue(value,String(index));if(!raw||typeof raw!="object"||Array.isArray(raw))continue;const text=ownValue(raw,"text");if(typeof text!="string")continue;const rawTone=ownValue(raw,"tone"),tone=rawTone==="brand"||rawTone==="success"||rawTone==="warning"||rawTone==="danger"?rawTone:"neutral",rawLabel=ownValue(raw,"label");badges.push(Object.freeze({text,tone,...typeof rawLabel=="string"?{label:rawLabel}:{}}))}return{badges:Object.freeze(badges),truncated:length>TREE_BADGE_LIMIT}}function sameIcon(left,right){if(Object.is(left,right))return!0;const a=left,b=right;if(!a||!b||typeof a!="object"||typeof b!="object"||a._$litType$===void 0||a._$litType$!==b._$litType$||a.strings!==b.strings)return!1;const leftValues=a.values??[],rightValues=b.values??[];return leftValues.length===rightValues.length&&leftValues.every((value,index)=>Object.is(value,rightValues[index]))}function sameBadges(left,right){return left===right?!0:!left||!right||left.length!==right.length?!1:left.every((badge,index)=>{const other=right[index];return badge.text===other.text&&badge.tone===other.tone&&badge.label===other.label})}function sameTreeNode(next,previous){if(next.id!==previous.id||next.label!==previous.label||next.selected!==previous.selected||next.expanded!==previous.expanded||next.disabled!==previous.disabled||next.lazy!==previous.lazy||next.description!==previous.description||next.accessibleLabel!==previous.accessibleLabel||!sameIcon(next.icon,previous.icon)||!sameBadges(next.badges,previous.badges))return!1;const children=next.children,previousChildren=previous.children;return!children||!previousChildren?children===void 0&&previousChildren===void 0:children.length===previousChildren.length&&children.every((child,index)=>child===previousChildren[index])}function indexTreeNodes(nodes){const byId=new Map,stack=[...nodes];for(;stack.length>0;){const node=stack.pop();byId.set(node.id,node),node.children&&stack.push(...node.children)}return byId}function normalizeTreeData(input,previous=EMPTY_TREE_DATA,limit=TREE_MAX_RENDER_NODES){if(!Array.isArray(input))return{data:EMPTY_TREE_DATA,declaredChildrenAtPath:new Map,declaredRootCount:0,truncated:input!=null,limitReached:!1};const root=[],declaredChildrenAtPath=new Map,created=[],rootLength=arrayLength(input);let truncated=!1,limitReached=!1,accepted=0,inspected=0;const seenIds=new Set,identityFilteredCollections=new Set,jobs=[{source:input,index:0,length:rootLength,target:root,parentPath:"",depth:0,ancestors:new Set}];for(;jobs.length>0;){const job=jobs[jobs.length-1];if(job.index>=job.length){jobs.pop();continue}if(accepted>=limit||inspected>=TREE_MAX_INSPECTED_POSITIONS){truncated=!0,limitReached=accepted>=limit;break}const raw=ownValue(job.source,String(job.index++));if(inspected++,inspected===TREE_MAX_INSPECTED_POSITIONS&&(truncated=!0),!raw||typeof raw!="object"||Array.isArray(raw)){truncated=!0,identityFilteredCollections.add(job.target);continue}const id=ownValue(raw,"id"),label=ownValue(raw,"label");if(typeof id!="string"||id.trim()===""||seenIds.has(id)||typeof label!="string"){truncated=!0,identityFilteredCollections.add(job.target);continue}seenIds.add(id);const node={id,label},selected=ownValue(raw,"selected"),expanded=ownValue(raw,"expanded"),disabled=ownValue(raw,"disabled"),lazy=ownValue(raw,"lazy");typeof selected=="boolean"&&(node.selected=selected),typeof expanded=="boolean"&&(node.expanded=expanded),typeof disabled=="boolean"&&(node.disabled=disabled),typeof lazy=="boolean"&&(node.lazy=lazy);const icon=ownValue(raw,"icon");icon!==void 0&&(node.icon=icon);const description=ownValue(raw,"description");typeof description=="string"&&(node.description=description);const accessibleLabel=ownValue(raw,"accessibleLabel");typeof accessibleLabel=="string"&&(node.accessibleLabel=accessibleLabel);const normalizedBadges=normalizeBadges(ownValue(raw,"badges"));normalizedBadges.badges?.length&&(node.badges=normalizedBadges.badges),truncated||=normalizedBadges.truncated;const ownIndex=job.target.length,path=job.parentPath===""?String(ownIndex):`${job.parentPath}/${ownIndex}`;job.target.push(node),created.push(node),accepted++;const rawChildren=ownValue(raw,"children"),childCount=arrayLength(rawChildren);if(childCount===0)continue;if(declaredChildrenAtPath.set(path,childCount),job.depth>=TREE_MAX_RENDER_DEPTH||job.ancestors.has(raw)){truncated=!0;continue}const children=[];node.children=children;const ancestors=new Set(job.ancestors);ancestors.add(raw),jobs.push({source:rawChildren,index:0,length:childCount,target:children,parentPath:path,depth:job.depth+1,ancestors})}const previousById=previous.length>0?indexTreeNodes(previous):void 0,resolved=new Map,resolve=node=>resolved.get(node)??node;for(let index=created.length-1;index>=0;index--){const node=created[index];if(node.children){for(let child=0;child<node.children.length;child++)node.children[child]=resolve(node.children[child]);Object.freeze(node.children)}Object.freeze(node);const prior=previousById?.get(node.id);prior&&!(node.children&&identityFilteredCollections.has(node.children))&&sameTreeNode(node,prior)&&resolved.set(node,prior)}for(let index=0;index<root.length;index++)root[index]=resolve(root[index]);const normalizedJobs=root.map((node,index)=>({node,path:String(index)}));for(;normalizedJobs.length>0;){const{node,path}=normalizedJobs.pop(),children=node.children??[];identityFilteredCollections.has(children)&&declaredChildrenAtPath.set(path,children.length);for(let index=children.length-1;index>=0;index--)normalizedJobs.push({node:children[index],path:`${path}/${index}`})}return{data:Object.freeze(root),declaredChildrenAtPath,declaredRootCount:identityFilteredCollections.has(root)?root.length:rootLength,truncated,limitReached}}function isInertWithin(node,root){for(let current=node;current&¤t!==root;current=current.parentElement)if(current.hasAttribute("inert"))return!0;return!1}class LyraTree extends LyraElement{constructor(){super(...arguments),this._treeSource=void 0,this.sourceMode=!1,this.sourcePaintVersion=0,this.sourceAnnouncer=new AnnouncementSinkController(this),this.hierarchy=new HierarchySourceController(this,{normalize:(value,key)=>this.normalizeSourceValue(value,key),onChange:()=>{const previous=this.sourcePaintVersion++;this.requestUpdate("sourcePaintVersion",previous)},accepted:(action,_row,state2)=>{action.type==="select"&&this.emit("lr-source-selection-change",Object.freeze({key:action.key,selected:action.selected,scope:action.scope,state:state2}))}}),this._data=EMPTY_TREE_DATA,this.dataExpansion=new TreeDataExpansion(()=>this.treeSource===void 0),this.lastDataInput=void 0,this.lastDataLimit=0,this.declaredChildrenAtPath=new Map,this.declaredRootCount=0,this._dataTruncated=!1,this._limitReached=!1,this.label="",this.maxNodes=1e3,this.reorderable=!1,this.pointerReorderable=!1,this.allowCrossParentReorder=!1,this._selection="single",this._activeId=null,this.readActiveId=()=>this._activeId,this.hasAuthoredItems=!1,this.pendingFocusId=null,this.generatedNodes=new WeakSet,this.dataIdOwnerPaths=new Map,this.dataIdCollisions=new Set,this.selectionSyncPending=!0,this.dataSyncPending=!1,this.inertMutationPending=!1,this.dirtyConfigureRoots=new Set,this.lastFocusedNodeId=null,this.pointerOrder=new TreePointerReorder(this,node=>this.findRenderedSiblings(node),ids=>{if(!this.hasAuthoredItems)return!0;const seen=new Set;for(const node of this.allNodeElements())if(ids.has(node.nodeId)){if(seen.has(node.nodeId))return!1;seen.add(node.nodeId)}return seen.size===ids.size},detail=>{const nodes=this.visibleNodeElements(),sourceOrder=this.pointerSiblingIds(detail.fromParentNodeId,nodes),targetOrder=detail.fromParentNodeId===detail.toParentNodeId?sourceOrder:this.pointerSiblingIds(detail.toParentNodeId,nodes);this.pendingPointerReorder={detail,sourceOrder,targetOrder},this.emit("lr-pointer-reorder",detail)}),this.onTreeFocusIn=e=>{const path=e.composedPath(),owner=path.find(target=>target.localName===tag("tree"));if(owner&&owner!==this)return;const item=path.find(target=>target.nodeType===1&&target.localName===tag("tree-item"));item&&this.onItemFocus(item)},this.onItemFocus=element=>{const item=element;this.isNavigable(item)&&(this.lastFocusedNodeId=item.nodeId,this.setActiveNode(item))},this.contextSyncPending=!0,this.bulkExpansions=0,this.bulkExpansionGeneration=0,this.syncGeneration=0,this.syncRequested=!1,this.syncRunning=!1,this.requestContextSync=closedBy=>{if(closedBy){const node=closedBy;this.activeId!==node.nodeId&&this.isNavigable(node)&&this.subtreeHasId(node,this.activeId)&&this.setActiveNode(node)}this.contextSyncPending=!0,this.scheduleTreeSync()},this.onChildrenChanged=()=>{if(this.treeSource!==void 0)return;const wasAuthored=this.hasAuthoredItems;this.refreshAuthoredItems(),wasAuthored&&!this.hasAuthoredItems&&(this.dataSyncPending=!0),this.selectionSyncPending=!0,this.requestUpdate()},this.childObserverGeneration=0,this.onChildMutations=allRecords=>{const records=allRecords.filter(record=>record.type!=="attributes"||record.oldValue!==null!==record.target.hasAttribute(record.attributeName??""));if(records.length!==0){if(records.some(record=>record.attributeName==="inert")&&(this.inertMutationPending=!0),records.every(record=>record.type==="attributes")){const itemTag=tag("tree-item");for(const record of records){const target=record.target;if(!(target instanceof Element)||target.localName!==itemTag)continue;const root=this.rootTreeItemAncestor(target);root&&this.dirtyConfigureRoots.add(root)}}else this.dirtyConfigureRoots.clear();this.onChildrenChanged()}},this.onNodeActivate=e=>{const node=this.eventNode(e);if(!node||node.isDisabled)return;this.selectionSyncPending=!0,this.bulkExpansions>0?this.syncRequested=!0:this.requestUpdate();const expanded=e.detail?.expanded===!0;(this.focusIsWithin(node)||!expanded&&this.activeId!==node.nodeId&&this.subtreeHasId(node,this.activeId))&&this.setActiveNode(node)},this.onNodeSelect=event=>{const node=this.eventNode(event);!node||node.isDisabled||(this.setActiveNode(node),this.updateSelectionFrom(node)&&this.emit("lr-selection-change",Object.freeze({selection:this.selectedItems})))},this.onTreeKeyDown=e=>{const itemTag=tag("tree-item");if(fromInteractiveDescendant(e,target=>target.localName===itemTag))return;const visible=this.visibleNodeElements();if(visible.length===0)return;const currentIndex=visible.findIndex(n=>n.nodeId===this.activeId),current=currentIndex>=0?visible[currentIndex]:visible[0];if(!current)return;if(this.reorderable&&(e.ctrlKey||e.metaKey)&&(e.key==="ArrowUp"||e.key==="ArrowDown")){e.preventDefault(),this.requestReorder(current,e.key==="ArrowDown"?1:-1);return}if(e.altKey)return;const rtl=this.effectiveDirection==="rtl",expandKey=rtl?"ArrowLeft":"ArrowRight",collapseKey=rtl?"ArrowRight":"ArrowLeft",moved=resolveListMove(e.key,{count:visible.length,current:Math.max(currentIndex,0),orientation:"vertical",wrap:!1,clamp:!0});if(moved!==null){e.preventDefault(),this.focusNode(visible[moved]);return}switch(e.key){case expandKey:if(e.preventDefault(),!current.hasChildren)break;if(!current.expanded)current.expand();else{const child=visible[currentIndex+1];child&&treeItemOwnerContext(child).depth>treeItemOwnerContext(current).depth&&this.focusNode(child)}break;case collapseKey:if(e.preventDefault(),current.hasChildren&¤t.expanded)current.collapse();else for(let i=currentIndex-1;i>=0;i--){const sibling=visible[i];if(sibling&&treeItemOwnerContext(sibling).depth<treeItemOwnerContext(current).depth){this.focusNode(sibling);break}}break;case"Enter":case" ":e.preventDefault(),current.select();break;default:return}}}static{this.defaultStrings={...super.defaultStrings,collapse:LYRA_DEFAULT_collapse,expand:LYRA_DEFAULT_expand,loading:LYRA_DEFAULT_loading,noData:LYRA_DEFAULT_noData,retry:LYRA_DEFAULT_retry,treeLimit:LYRA_DEFAULT_treeLimit,treeNodeMoved:LYRA_DEFAULT_treeNodeMoved,treeSourceError:LYRA_DEFAULT_treeSourceError,treeSourceSummary:LYRA_DEFAULT_treeSourceSummary}}static{this.collectionSupport=eventCollectionSupport}static{this.immutableEventDetails=Object.freeze(["lr-selection-change"])}static{this.identityEventDetailProperties=Object.freeze({"lr-selection-change":Object.freeze(["selection"])})}static{this.styles=[LyraElement.styles,styles,hierarchySourceStyles]}get size(){return this._size}set size(next){const normalized=normalizeReflectedOptionalSize(this,next),old=this._size;old!==normalized&&(this._size=normalized,this.requestUpdate("size",old))}get treeSource(){return this._treeSource}set treeSource(value){const previous=this._treeSource;this._treeSource=value,value!==void 0&&this.bulkExpansionGeneration++,this.hierarchy?.update(value,this.effectiveLocale,!0),this.requestUpdate("treeSource",previous)}revealSourceKey(key){return this.treeSource===void 0?Promise.resolve(!1):this.hierarchy.reveal(key)}normalizeSourceValue(value,key){const id=hierarchyKey(hierarchyField(value,"id"));if(id!==key)throw new TypeError("Hierarchy domain key mismatch");const label=hierarchyText(hierarchyField(value,"label")),description=hierarchyText(hierarchyField(value,"description")),accessibleLabel=hierarchyText(hierarchyField(value,"accessibleLabel")),normalized=normalizeBadges(hierarchyField(value,"badges"));let units=label.length+description.length+accessibleLabel.length;for(const badge of normalized.badges??[])units+=badge.text.length+(badge.label?.length??0);if(normalized.truncated||units>65536)throw new RangeError("Hierarchy display value exceeds its row budget");return Object.freeze({id,label,description,accessibleLabel,icon:hierarchyField(value,"icon"),badges:normalized.badges})}announceSource(){const status=this.hierarchy.error?this.localize("treeSourceError"):this.hierarchy.loading?this.localize("loading"):this.sourceSummary();this.sourceAnnouncement!==void 0&&status!==this.sourceAnnouncement&&this.sourceAnnouncer.announce(status),this.sourceAnnouncement=status,this.hierarchy.rowsObserved&&this.sourceAnnouncer.transition("source-rows",this.hierarchy.rowError?"error":"ready",this.hierarchy.rowError?this.localize("treeSourceError"):"")}sourceSummary(){const projection=this.hierarchy.projection;return projection?this.localize("treeSourceSummary",void 0,{visible:getNumberFormat(this.effectiveLocale).format(projection.rows.count),total:getNumberFormat(this.effectiveLocale).format(projection.total)}):""}get data(){return this._data}set data(value){if((value===this._data||value===this.lastDataInput)&&this.lastDataLimit===this.effectiveMaxNodes)return;this.lastDataInput=value,this.lastDataLimit=this.effectiveMaxNodes,this.hasUpdated&&this.selectionBeforeRefresh===void 0&&(this.selectionBeforeRefresh=this.selectedItems.map(item=>item.nodeId));const previous=this._data,normalized=normalizeTreeData(value,this._data,this.effectiveMaxNodes);this._data=normalized.data,this.dataExpansion.replace(normalized.data),this.declaredChildrenAtPath=normalized.declaredChildrenAtPath,this.declaredRootCount=normalized.declaredRootCount,this._dataTruncated=normalized.truncated,this._limitReached=normalized.limitReached,this.requestUpdate("data",previous)}get dataTruncated(){return this._dataTruncated}get effectiveMaxNodes(){return Math.max(1,Math.min(1e4,finiteCount(this.maxNodes,1e3)))}get selection(){return this._selection}set selection(value){const old=this._selection,normalized=TREE_SELECTIONS.has(value)?value:"single";old!==normalized&&(this._selection=normalized,this.selectionSyncPending=!0,this.requestUpdate("selection",old))}get activeId(){return this._activeId}set activeId(value){value!==this._activeId&&(this.activeNode&&(this.activeNode.tabIndex=-1),this.activeNode=void 0,this._activeId=value)}setActiveNode(node){this.activeId=node?.nodeId??null,this.activeNode!==node&&this.activeNode&&(this.activeNode.tabIndex=-1),this.activeNode=node,node&&(node.tabIndex=this.isNavigable(node)?0:-1)}get nodeWalkLimit(){return this.hasAuthoredItems?Number.POSITIVE_INFINITY:this.effectiveMaxNodes}get nodeElements(){return[...this.querySelectorAll(`:scope > ${tag("tree-item")}`)]}childrenOf(node){return node.childItems()}isNavigable(node){return!node.isDisabled&&!isInertWithin(node,this)}allNodeElements(){const result=[],seen=new Set,stack=this.nodeElements.map(node=>({node,depth:0})).reverse();for(;stack.length>0&&result.length<this.nodeWalkLimit;){const{node,depth}=stack.pop();if(seen.has(node)||(seen.add(node),result.push(node),depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(node);for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}return result}get selectedItems(){return this.treeSource!==void 0?Object.freeze([]):Object.freeze(this.allNodeElements().filter(node=>node.selected))}iconSource(name){return this.querySelector(`:scope > [slot="${name}"]`)}applyTreeContext(){const expandIcon=this.iconSource("expand-icon"),collapseIcon=this.iconSource("collapse-icon"),roots=this.nodeElements,rootCount=this.hasAuthoredItems?roots.length:this.declaredRootCount,stack=[];for(let index=roots.length-1;index>=0;index--)stack.push({node:roots[index],ancestry:[],depth:0,setSize:rootCount,posInSet:index+1,identity:this.hasAuthoredItems?void 0:this.treeIdentityAt(String(index)),expansionVisible:!0});const seen=new Set;for(;stack.length>0&&seen.size<this.nodeWalkLimit;){const frame=stack.pop();if(seen.has(frame.node)||(seen.add(frame.node),frame.node.nodeId===this.activeId&&this.setActiveNode(frame.node),configureTreeItemOwner(frame.node,{...treeItemOwnerContext(frame.node),activeId:null,activeNodeId:this.readActiveId,ancestry:frame.ancestry,depth:frame.depth,setSize:frame.setSize,posInSet:frame.posInSet,selection:this.selection,ownsSelection:!0,identity:frame.identity,dataExpansion:frame.identity?this.dataExpansion:void 0,expansionVisible:frame.expansionVisible,expandIcon,collapseIcon,pointerReorderable:this.pointerReorderable,syncOwner:this.requestContextSync,focusOwner:this.onItemFocus}),frame.depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(frame.node),declaredCount=frame.identity?.declaredChildrenAtPath.get(frame.identity.path)??frame.node.item?.children?.length??children.length,childAncestry=frame.node.item?[...frame.ancestry,frame.node.item]:frame.ancestry,expansionVisible=frame.expansionVisible&&frame.node.expanded&&!frame.node.isDisabled;for(let index=children.length-1;index>=0;index--){const identity=frame.identity?{path:`${frame.identity.path}/${index}`,ownerPaths:frame.identity.ownerPaths,collisionIds:frame.identity.collisionIds,declaredChildrenAtPath:frame.identity.declaredChildrenAtPath}:void 0;stack.push({node:children[index],ancestry:childAncestry,depth:frame.depth+1,setSize:declaredCount,posInSet:index+1,identity,expansionVisible})}}}selectableInSingleMode(node){return!node.isDisabled&&(this.selection!=="leaf"||!node.hasChildren)}normalizeSingleSelection(){let kept=!1;for(const node of this.allNodeElements()){const selected=!kept&&node.selected&&this.selectableInSingleMode(node);this.setSelection(node,selected,!1),selected&&(kept=!0)}}setBranchSelection(node,selected,leavesOnly){const stack=[{node,depth:treeItemOwnerContext(node).depth}],seen=new Set;for(;stack.length>0&&seen.size<this.nodeWalkLimit;){const{node:current,depth}=stack.pop();if(seen.has(current)||current.isDisabled)continue;seen.add(current);const children=this.childrenOf(current).filter(child=>!child.isDisabled);if(!leavesOnly||children.length===0?this.setSelection(current,leavesOnly&¤t.hasChildren?!1:selected,!1):this.setSelection(current,!1,!1),depth<TREE_MAX_RENDER_DEPTH)for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}}deriveMultipleSelection(node,leavesOnly){const states=new Map,stack=[{item:node,visited:!1,depth:0}],queued=new Set;for(;stack.length>0;){const entry=stack.pop();if(entry.visited){const current=entry.item;if(current.isDisabled){this.setSelection(current,!1,!1),states.set(current,"ignored");continue}const children2=this.childrenOf(current).filter(child=>!child.isDisabled);if(children2.length===0){leavesOnly&¤t.hasChildren?(this.setSelection(current,!1,!1),states.set(current,"none")):(this.setSelection(current,current.selected,!1),states.set(current,current.selected?"all":"none"));continue}const childStates=children2.map(child=>states.get(child)??"ignored").filter(state2=>state2!=="ignored");if(childStates.length===0){this.setSelection(current,!1,!1),states.set(current,"none");continue}const all=childStates.every(state2=>state2==="all"),none=childStates.every(state2=>state2==="none");this.setSelection(current,all,!all&&!none),states.set(current,all?"all":none?"none":"some");continue}if(queued.size>=this.nodeWalkLimit||queued.has(entry.item)||(queued.add(entry.item),stack.push({...entry,visited:!0}),entry.depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(entry.item);for(let index=children.length-1;index>=0;index--)queued.has(children[index])||stack.push({item:children[index],visited:!1,depth:entry.depth+1})}return states.get(node)??"none"}normalizeMultipleSelection(){const leavesOnly=this.selection==="leaf-multiple";for(const node of this.allNodeElements())node.selected&&this.childrenOf(node).length>0&&this.setBranchSelection(node,!0,leavesOnly);for(const root of this.nodeElements)this.deriveMultipleSelection(root,leavesOnly)}normalizeSelection(){this.selection==="single"||this.selection==="leaf"?this.normalizeSingleSelection():this.normalizeMultipleSelection()}setSelection(node,selected,indeterminate){this.selectionBefore&&!this.selectionBefore.has(node)&&this.selectionBefore.set(node,[node.selected,node.indeterminate]),setTreeItemSelection(node,selected,indeterminate)}updateSelectionFrom(node){if(node.isDisabled||(this.selection==="single"||this.selection==="leaf")&&!this.selectableInSingleMode(node))return!1;const before=new Map;this.selectionBefore=before;try{if(this.selection==="single"||this.selection==="leaf")for(const candidate of this.allNodeElements())this.setSelection(candidate,candidate===node,!1);else{const select=node.indeterminate||!node.selected;this.setBranchSelection(node,select,this.selection==="leaf-multiple");for(const root of this.nodeElements)this.deriveMultipleSelection(root,this.selection==="leaf-multiple")}}finally{this.selectionBefore=void 0}for(const[candidate,[selected,indeterminate]]of before)if(candidate.selected!==selected||candidate.indeterminate!==indeterminate)return!0;return!1}refreshAuthoredItems(){const nodes=this.nodeElements;for(const node of nodes)node.hasAttribute("slot")&&node.removeAttribute("slot");const authored=nodes.some(node=>!this.generatedNodes.has(node));if(authored)for(const node of nodes)this.generatedNodes.has(node)&&node.remove();this.hasAuthoredItems=authored}visibleNodeElements(){const acc=[],seen=new Set,stack=this.nodeElements.map(node=>({node,depth:0})).reverse();for(;stack.length>0&&acc.length<this.nodeWalkLimit;){const{node,depth}=stack.pop();if(seen.has(node)||(seen.add(node),!this.isNavigable(node))||(acc.push(node),!node.expanded||depth>=TREE_MAX_RENDER_DEPTH))continue;const children=this.childrenOf(node);for(let index=children.length-1;index>=0;index--)stack.push({node:children[index],depth:depth+1})}return acc}findItem(items,id){const stack=[...items].reverse(),seen=new Set;for(;stack.length>0;){const item=stack.pop();if(!seen.has(item)){if(seen.add(item),item.id===id)return item;if(item.children)for(let i=item.children.length-1;i>=0;i--){const child=item.children[i];child&&stack.push(child)}}}}isDuplicateDataPath(item,path){return this.dataIdCollisions.has(item.id)&&this.dataIdOwnerPaths.get(item.id)!==path}rebuildDataIdentity(){const ownerPaths=new Map,collisionIds=new Set,ancestry=new Set,stack=[{items:this.data,index:0,parentPath:"",depth:0}];for(;stack.length>0;){const frame=stack[stack.length-1];if(frame.index>=frame.items.length){frame.owner&&ancestry.delete(frame.owner),stack.pop();continue}const index=frame.index++,item=frame.items[index];if(!item)continue;const path=frame.parentPath===""?String(index):`${frame.parentPath}/${index}`;ownerPaths.has(item.id)?collisionIds.add(item.id):ownerPaths.set(item.id,path),!(frame.depth>=TREE_MAX_RENDER_DEPTH||ancestry.has(item)||!item.children?.length)&&(ancestry.add(item),stack.push({items:item.children,index:0,parentPath:path,depth:frame.depth+1,owner:item}))}this.dataIdOwnerPaths=ownerPaths,this.dataIdCollisions=collisionIds}treeIdentityAt(path){return{path,ownerPaths:this.dataIdOwnerPaths,collisionIds:this.dataIdCollisions,declaredChildrenAtPath:this.declaredChildrenAtPath}}firstEnabledId(items){for(let index=0;index<items.length;index++){const item=items[index];if(!(!item||item.disabled||this.isDuplicateDataPath(item,String(index))))return item.id}return null}isEnabledReachableId(items,id){const stack=items.map((item,index)=>({item,path:String(index)})).reverse(),seen=new Set;for(;stack.length>0;){const{item,path}=stack.pop();if(!seen.has(item)&&(seen.add(item),!(item.disabled||this.isDuplicateDataPath(item,path)))){if(item.id===id)return!0;if(item.children)for(let i=item.children.length-1;i>=0;i--){const child=item.children[i];child&&stack.push({item:child,path:`${path}/${i}`})}}}return!1}findRenderedSiblings(node){const root=node.getRootNode(),shadowHost="host"in root?root.host:null,shadowParent=shadowHost?.localName===tag("tree-item")?shadowHost:null,lightParent=node.parentElement?.localName===tag("tree-item")?node.parentElement:null,parentItem=shadowParent??lightParent,siblings=parentItem?parentItem.childItems():this.nodeElements,index=siblings.indexOf(node);if(!(index<0))return{parent:parentItem,siblings,index}}deepFocusedNode(){const active=deepActiveElementIn(this.ownerDocument);if(!active||active.localName!==tag("tree-item"))return null;const node=active;return this.visibleNodeElements().some(n=>n.nodeId===node.nodeId)?node:null}resolveActiveFromDom(){const inertMutation=this.inertMutationPending;this.inertMutationPending=!1;const visible=this.visibleNodeElements(),current=visible.find(node=>node.nodeId===this.activeId);if(current){this.setActiveNode(current);return}const displaced=this.activeId;if(this.setActiveNode(visible[0]),!inertMutation||this.activeId==null||displaced==null||displaced!==this.lastFocusedNodeId)return;const ownerDocument=this.ownerDocument,active=deepActiveElementIn(ownerDocument),strandedOnDisplaced=active?.nodeType===1&&active.localName===tag("tree-item")&&active.nodeId===displaced;active!==null&&active!==ownerDocument.body&&!strandedOnDisplaced||(this.pendingFocusId=this.activeId)}requestUpdate(name,oldValue){name===void 0&&this._treeSource!==void 0&&this.hierarchy?.update(this._treeSource,this.effectiveLocale,!0),super.requestUpdate(name,oldValue)}willUpdate(changed){if(super.willUpdate(changed),(!this.pointerReorderable||this.treeSource!==void 0)&&(this.pointerOrder.cancel(),this.pendingPointerReorder=void 0),this.hierarchy.update(this.treeSource,this.effectiveLocale),this.treeSource!==void 0){if(!this.sourceMode){this.sourceMode=!0,this.resetChildObserver(),this.pendingFocusId=null,this.pendingReorder=void 0,this.selectionBeforeRefresh=void 0,this.syncRequested=!1,this.syncGeneration++,this.syncRunning=!1,this.syncTask=void 0;for(const node of this.nodeElements)this.generatedNodes.has(node)&&node.remove()}return}if(this.sourceMode&&(this.sourceMode=!1,this.sourceAnnouncement=void 0,this.dataSyncPending=!0,this.selectionSyncPending=!0,this.armChildObserver()),changed.has("maxNodes")&&this.hasUpdated&&!changed.has("data")&&(this.data=this.data),this.refreshAuthoredItems(),(changed.has("data")||changed.has("selection"))&&(this.selectionSyncPending=!0),this.hasAuthoredItems){this.resolveActiveFromDom();return}if(changed.has("data")||this.dataSyncPending){this.dataSyncPending=!1;const focused=this.deepFocusedNode(),focusedId=focused?.nodeId??null;this.rebuildDataIdentity(),this.syncNodes();const activeItem=this.activeId?this.findItem(this.data,this.activeId):void 0;(!this.activeId||!activeItem||activeItem.disabled||!this.isEnabledReachableId(this.data,this.activeId))&&(this.activeId=this.firstEnabledId(this.data)),this.pendingFocusId=focused==null?null:focusedId!=null&&this.findItem(this.data,focusedId)?focusedId:this.activeId}this.inertMutationPending&&this.resolveActiveFromDom()}firstUpdated(changed){super.firstUpdated(changed),hostAriaLabel(this)==null&&!this.label&&devWarnOnce("lyra-tree-missing-accessible-name","<lr-tree> has no accessible name: set `label` or a host `aria-label`.")}updated(changed){if(super.updated(changed),this.treeSource!==void 0){this.announceSource();return}const targeted=changed.size===0&&this.hasAuthoredItems&&this.dirtyConfigureRoots.size>0;if(targeted){const nodes=this.nodeElements,count=nodes.length,positions=this.dirtyConfigureRoots.size>1?new Map(nodes.map((node,index)=>[node,index])):void 0;for(const node of this.dirtyConfigureRoots){const i=positions?positions.get(node)??-1:nodes.indexOf(node);i<0||configureTreeItemOwner(node,{...treeItemOwnerContext(node),activeId:null,activeNodeId:this.readActiveId,ancestry:[],depth:0,setSize:count,posInSet:i+1,selection:this.selection,ownsSelection:!0,identity:void 0,expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),pointerReorderable:this.pointerReorderable,syncOwner:this.requestContextSync,focusOwner:this.onItemFocus})}}else if(changed.has("activeId")||changed.has("data")||this.hasAuthoredItems){const nodes=this.nodeElements,count=this.hasAuthoredItems?nodes.length:this.declaredRootCount;nodes.forEach((node,i)=>{configureTreeItemOwner(node,{...treeItemOwnerContext(node),activeId:null,activeNodeId:this.readActiveId,ancestry:[],depth:0,setSize:count,posInSet:i+1,selection:this.selection,ownsSelection:!0,identity:this.hasAuthoredItems?void 0:this.treeIdentityAt(String(i)),expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),pointerReorderable:this.pointerReorderable,syncOwner:this.requestContextSync,focusOwner:this.onItemFocus})})}targeted||(this.contextSyncPending=!0),this.dirtyConfigureRoots.clear(),this.scheduleTreeSync()}scheduleTreeSync(){this.treeSource===void 0&&(this.syncRequested=!0,!(this.syncRunning||this.bulkExpansions>0)&&(this.syncRunning=!0,this.syncTask=this.runTreeSync()))}async runTreeSync(){const generation=this.syncGeneration;try{for(;this.syncRequested&&(this.syncRequested=!1,await super.getUpdateComplete(),!(this.treeSource!==void 0||generation!==this.syncGeneration||(await cascadeUpdateComplete(this.nodeElements),this.treeSource!==void 0||generation!==this.syncGeneration)||(this.contextSyncPending&&(this.contextSyncPending=!1,this.applyTreeContext()),this.selectionSyncPending&&(this.selectionSyncPending=!1,this.normalizeSelection()),await cascadeUpdateComplete(this.nodeElements),this.treeSource!==void 0||generation!==this.syncGeneration)));)this.reportRefreshSelectionChange(),this.confirmPendingReorder(),this.confirmPointerReorder(),this.restorePendingFocus()}finally{generation===this.syncGeneration&&(this.syncRunning=!1)}}rootTreeItemAncestor(node){const itemTag=tag("tree-item");let current=node;for(;current&¤t.parentElement&¤t.parentElement!==this;)current=current.parentElement;return current&¤t.parentElement===this&¤t.localName===itemTag?current:null}connectedCallback(){super.connectedCallback(),this.armChildObserver()}armChildObserver(){const ownerDocument=this.ownerDocument;if(!this.isConnected||this.treeSource!==void 0||this.childObserver&&this.childObserverDocument===ownerDocument)return;this.resetChildObserver();const MutationObserverCtor=ownerDocument.defaultView?.MutationObserver;if(!MutationObserverCtor)return;const generation=this.childObserverGeneration,observer=new MutationObserverCtor(records=>{this.childObserver!==observer||this.childObserverDocument!==ownerDocument||this.childObserverGeneration!==generation||!this.isConnected||this.ownerDocument!==ownerDocument||this.onChildMutations(records)});this.childObserver=observer,this.childObserverDocument=ownerDocument,observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["selected","disabled","inert","lazy"]})}disconnectedCallback(){this.pointerOrder.cancel(),this.pointerOrder.clearClick(),this.pendingPointerReorder=void 0,super.disconnectedCallback(),this.sourceAnnouncement=void 0,this.bulkExpansionGeneration++,this.pendingReorder=void 0,this.activeNode=void 0,this.resetChildObserver()}adoptedCallback(){super.adoptedCallback(),this.hierarchy.adopted(),this.resetChildObserver()}resetChildObserver(){this.childObserverGeneration+=1,this.childObserver?.disconnect(),this.childObserver=void 0,this.childObserverDocument=void 0}syncNodes(){const existingById=new Map;for(const node of this.nodeElements){if(!node.item)continue;const matches=existingById.get(node.item.id)??[];matches.push(node),existingById.set(node.item.id,matches)}let previousSibling=null;for(let index=0;index<this.data.length;index++){const item=this.data[index];let node=existingById.get(item.id)?.shift();node||(node=this.ownerDocument.createElement(tag("tree-item")),this.generatedNodes.add(node)),node.item=item,configureTreeItemOwner(node,{...treeItemOwnerContext(node),ancestry:[],depth:0,setSize:this.declaredRootCount,posInSet:index+1,selection:this.selection,ownsSelection:!0,identity:this.treeIdentityAt(String(index)),dataExpansion:this.dataExpansion,expansionVisible:!0,expandIcon:this.iconSource("expand-icon"),collapseIcon:this.iconSource("collapse-icon"),pointerReorderable:this.pointerReorderable,syncOwner:this.requestContextSync,focusOwner:this.onItemFocus});const targetPosition=previousSibling?previousSibling.nextElementSibling:this.firstElementChild;targetPosition!==node&&this.insertBefore(node,targetPosition),previousSibling=node}for(const nodes of existingById.values())for(const node of nodes)node.remove()}focusNode(node){node&&(this.setActiveNode(node),node.focus())}subtreeHasId(root,id){if(id==null)return!1;const stack=this.childrenOf(root).map(item=>({item,depth:treeItemOwnerContext(root).depth+1}));for(let visited=0;stack.length>0&&visited<this.nodeWalkLimit;visited++){const{item,depth}=stack.pop();if(!(depth>TREE_MAX_RENDER_DEPTH)){if(item.nodeId===id)return!0;depth<TREE_MAX_RENDER_DEPTH&&stack.push(...this.childrenOf(item).map(child=>({item:child,depth:depth+1})))}}return!1}focusIsWithin(node){for(let current=deepActiveElementIn(this.ownerDocument);current;current=composedParentElement(current)){if(current===node)return!0;if(current===this)return!1}return!1}eventNode(e){const path=e.composedPath(),origin=path[0];if(origin?.nodeType===1&&origin.localName===tag("tree-item")){const treeTag=tag("tree");for(const target of path){if(target===this)return origin;if(target.localName===treeTag)return}return}const id=e.detail?.nodeId;return this.allNodeElements().find(candidate=>candidate.nodeId===id)}async getUpdateComplete(){let result=await super.getUpdateComplete();if(this.treeSource!==void 0)return result;for(;this.syncRunning||this.isUpdatePending;)this.syncRunning&&await this.syncTask,result=await super.getUpdateComplete();return this.treeSource===void 0&&await cascadeUpdateComplete(this.nodeElements),result}reportRefreshSelectionChange(){const before=this.selectionBeforeRefresh;if(before===void 0||this.isUpdatePending)return;this.selectionBeforeRefresh=void 0;const selection=this.selectedItems;selection.length===before.length&&selection.every((item,index)=>item.nodeId===before[index])||this.emit("lr-selection-change",Object.freeze({selection}))}restorePendingFocus(){if(this.pendingFocusId==null)return;const id=this.pendingFocusId;this.pendingFocusId=null;const visible=this.visibleNodeElements();(visible.find(n=>n.nodeId===id)??visible.find(n=>n.nodeId===this.activeId))?.focus()}requestReorder(node,delta){const id=node.nodeId,found=this.findRenderedSiblings(node);if(!found)return;const{parent,siblings,index}=found,total=siblings.length,toIndex=index+delta;toIndex<0||toIndex>=total||(this.pendingReorder={node,parent,originalSiblings:[...siblings],targetSibling:siblings[toIndex],fromIndex:index,toIndex},this.emit("lr-reorder",{nodeId:id,parentNodeId:parent?.nodeId??null,fromIndex:index,toIndex}))}confirmPendingReorder(){const pending=this.pendingReorder;if(!pending)return;const found=this.findRenderedSiblings(pending.node);if(!found){this.pendingReorder=void 0;return}(found.siblings.length!==pending.originalSiblings.length||found.siblings.some((node,index)=>node!==pending.originalSiblings[index]))&&(this.pendingReorder=void 0,!(found.parent!==pending.parent||found.index!==pending.toIndex||found.siblings[pending.fromIndex]!==pending.targetSibling)&&this.liveRegion?.announce(this.localize("treeNodeMoved",void 0,{label:pending.node.nodeLabel,index:this.formatCount(found.index+1),total:this.formatCount(found.siblings.length)}),{force:!0}))}pointerSiblingIds(parentId,nodes){return parentId===null?this.nodeElements.map(node=>node.nodeId):nodes.find(node=>node.nodeId===parentId)?.childItems().map(node=>node.nodeId)??[]}confirmPointerReorder(){const request=this.pendingPointerReorder;if(!request)return;const pending=request.detail,nodes=this.visibleNodeElements(),node=nodes.find(item=>item.nodeId===pending.nodeId),anchor=nodes.find(item=>item.nodeId===pending.targetNodeId),location=node&&this.findRenderedSiblings(node);if(!node||!anchor||!location){this.pendingPointerReorder=void 0;return}const parentId=location.parent?.nodeId??null,source=this.pointerSiblingIds(pending.fromParentNodeId,nodes),sameParent=pending.fromParentNodeId===pending.toParentNodeId,target=sameParent?source:this.pointerSiblingIds(pending.toParentNodeId,nodes),sameOrder=(left,right)=>left.length===right.length&&left.every((id,index)=>right[index]===id);if(sameOrder(source,request.sourceOrder)&&sameOrder(target,request.targetOrder))return;this.pendingPointerReorder=void 0;const removed=request.sourceOrder.filter(id=>id!==pending.nodeId),expected=[...sameParent?removed:request.targetOrder];if(expected.splice(pending.toIndex,0,pending.nodeId),!sameOrder(target,expected)||!sameParent&&!sameOrder(source,removed))return;const anchorIndex=location.index+(pending.position==="before"?1:-1);parentId!==pending.toParentNodeId||location.index!==pending.toIndex||location.siblings[anchorIndex]!==anchor||this.liveRegion?.announce(this.localize("treeNodeMoved",void 0,{label:node.nodeLabel,index:this.formatCount(location.index+1),total:this.formatCount(location.siblings.length)}),{force:!0})}async expandAll(){if(this.treeSource!==void 0)return;const generation=this.bulkExpansionGeneration,changed=new Set;let level=this.nodeElements.map(node=>({node,depth:0}));const seen=new Set,systemReduced=preferenceMediaMatches(this.ownerDocument.defaultView,"(prefers-reduced-motion: reduce)");this.bulkExpansions+=1;try{for(;level.length>0&&seen.size<this.nodeWalkLimit&&generation===this.bulkExpansionGeneration;){const current=[];for(const entry of level){const{node}=entry;if(generation!==this.bulkExpansionGeneration)break;if(!(!node.isConnected||seen.has(node)||seen.size>=this.nodeWalkLimit)){if(seen.add(node),current.push(entry),node.isDisabled)node.expanded=!1;else if(node.hasChildren){const reduced=systemReduced||inheritedPreference(node,"data-lr-motion","reduce")==="reduce",wasExpanded=node.expanded;withTreeItemMotionPreference(node,reduced,()=>node.expand()),!wasExpanded&&node.expanded&&changed.add(node.nodeId)}}}await Promise.all(current.map(({node})=>node.updateComplete)),level=[];for(const{node,depth}of current)depth<TREE_MAX_RENDER_DEPTH&&level.push(...this.childrenOf(node).map(child=>({node:child,depth:depth+1})))}}finally{this.bulkExpansions-=1}this.bulkExpansions===0&&this.syncRequested&&this.scheduleTreeSync(),await this.updateComplete,generation===this.bulkExpansionGeneration&&this.emitBulkToggle(!0,changed)}async collapseAll(){if(this.treeSource!==void 0)return;this.bulkExpansionGeneration++;const changed=new Set,focused=this.deepFocusedNode(),topLevel=this.nodeElements,nodes=this.allNodeElements();if(!this.hasAuthoredItems){const mounted=new Set;for(const node of nodes)node.item&&mounted.add(node.item);this.dataExpansion.closeAll(changed,mounted)}for(let index=nodes.length-1;index>=0;index--){if(this.treeSource!==void 0)return;const node=nodes[index];if(node.isDisabled)node.expanded=!1;else{const counted=node.expanded&&node.hasChildren;node.collapse(),counted&&!node.expanded&&changed.add(node.nodeId)}}(this.hasAuthoredItems?topLevel.some(node=>this.isNavigable(node)&&node.nodeId===this.activeId):this.data.some(item=>!item.disabled&&item.id===this.activeId))||(this.activeId=this.hasAuthoredItems?topLevel.find(node=>this.isNavigable(node))?.nodeId??null:this.firstEnabledId(this.data)),focused&&(this.pendingFocusId=this.activeId),await cascadeUpdateComplete(topLevel),this.isConnected&&this.treeSource===void 0&&this.emitBulkToggle(!1,changed)}emitBulkToggle(expanded,changed){changed.size>0&&this.emit("lr-bulk-toggle",Object.freeze({expanded,nodeIds:Object.freeze([...changed])}))}render(){return this.treeSource!==void 0?hierarchySourceView(this.hierarchy,{label:hostAriaLabel(this)??this.label,rtl:this.effectiveDirection==="rtl",multiple:this.selection==="multiple"||this.selection==="leaf-multiple",loading:this.localize("loading"),error:this.localize("treeSourceError"),empty:this.localize("noData"),retry:this.localize("retry"),expand:this.localize("expand"),collapse:this.localize("collapse"),summary:this.sourceSummary(),name:value=>value.accessibleLabel||[value.label,value.description,...(value.badges??[]).map(badge=>badge.label?.trim()?badge.label:badge.text)].filter(text=>text?.trim()).join(" ")||value.id,content:value=>html`${value.icon??nothing}${value.label}${value.description?html` <span>${value.description}</span>`:nothing}${value.badges?.map(badge=>html` <span role=${badge.label?.trim()?"img":nothing} aria-label=${badge.label?.trim()?badge.label:nothing}>${badge.text}</span>`)}`,select:row=>{if((this.selection==="leaf"||this.selection==="leaf-multiple")&&row.childCount>0)return;const multiple=this.selection==="multiple"||this.selection==="leaf-multiple";this.hierarchy.project({type:"select",key:row.key,selected:multiple?!row.selected:!0,scope:multiple&&row.childCount>0?"subtree":"item"},!0,row)}}):html`
|
|
2
2
|
<div
|
|
3
3
|
part="base tree"
|
|
4
4
|
role="tree"
|
|
5
5
|
aria-label=${hostAriaLabel(this)??(this.label||nothing)}
|
|
6
6
|
aria-multiselectable=${String(this.selection==="multiple"||this.selection==="leaf-multiple")}
|
|
7
|
+
@pointerdown=${this.pointerOrder.start}
|
|
7
8
|
@focusin=${this.onTreeFocusIn}
|
|
8
9
|
@keydown=${this.onTreeKeyDown}
|
|
9
10
|
@lr-node-toggle=${this.onNodeActivate}
|
|
@@ -11,9 +12,10 @@ import{__decorate}from"tslib";import{HierarchySourceController,hierarchyField,hi
|
|
|
11
12
|
>
|
|
12
13
|
${this.data.length===0&&!this.hasAuthoredItems?html`<lr-empty part="empty" heading=${this.localize("noData")}></lr-empty>`:nothing}
|
|
13
14
|
<slot @slotchange=${this.onChildrenChanged}></slot>
|
|
15
|
+
${this.pointerReorderable?html`<span part="drop-indicator" aria-hidden="true" hidden></span>`:nothing}
|
|
14
16
|
<slot name="expand-icon" hidden @slotchange=${this.onChildrenChanged}></slot>
|
|
15
17
|
<slot name="collapse-icon" hidden @slotchange=${this.onChildrenChanged}></slot>
|
|
16
18
|
</div>
|
|
17
19
|
${this._limitReached?html`<div part="limit">${this.localize("treeLimit",void 0,{count:this.formatCount(this.effectiveMaxNodes)})}</div>`:nothing}
|
|
18
|
-
${this.reorderable?html`<lr-live-region></lr-live-region>`:nothing}
|
|
19
|
-
`}formatCount(value){return getNumberFormat(this.effectiveLocale).format(value)}}__decorate([property({attribute:!1})],LyraTree.prototype,"treeSource",null),__decorate([property({attribute:!1})],LyraTree.prototype,"data",null),__decorate([property()],LyraTree.prototype,"label",void 0),__decorate([property({type:Number,attribute:"max-nodes"})],LyraTree.prototype,"maxNodes",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraTree.prototype,"reorderable",void 0),__decorate([property()],LyraTree.prototype,"selection",null),__decorate([state()],LyraTree.prototype,"hasAuthoredItems",void 0),__decorate([query("lr-live-region")],LyraTree.prototype,"liveRegion",void 0);export{LyraTree};
|
|
20
|
+
${this.reorderable||this.pointerReorderable?html`<lr-live-region></lr-live-region>`:nothing}
|
|
21
|
+
`}formatCount(value){return getNumberFormat(this.effectiveLocale).format(value)}}__decorate([property({reflect:!0,converter:optionalSizeConverter})],LyraTree.prototype,"size",null),__decorate([property({attribute:!1})],LyraTree.prototype,"treeSource",null),__decorate([property({attribute:!1})],LyraTree.prototype,"data",null),__decorate([property()],LyraTree.prototype,"label",void 0),__decorate([property({type:Number,attribute:"max-nodes"})],LyraTree.prototype,"maxNodes",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraTree.prototype,"reorderable",void 0),__decorate([property({type:Boolean,attribute:"pointer-reorderable",reflect:!0})],LyraTree.prototype,"pointerReorderable",void 0),__decorate([property({type:Boolean,attribute:"allow-cross-parent-reorder",reflect:!0})],LyraTree.prototype,"allowCrossParentReorder",void 0),__decorate([property({attribute:!1})],LyraTree.prototype,"canDrop",void 0),__decorate([property()],LyraTree.prototype,"selection",null),__decorate([state()],LyraTree.prototype,"hasAuthoredItems",void 0),__decorate([query("lr-live-region")],LyraTree.prototype,"liveRegion",void 0);export{LyraTree};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{css}from"lit";const styles=css`:host{display:block}[part~=base]{flex-direction:column;display:flex;overflow:auto hidden}[part=limit]{padding:var(--lr-space-s);color:var(--lr-color-text-quiet);font-size:var(--lr-font-size-sm)}`;export{styles};
|
|
1
|
+
import{css}from"lit";const styles=css`:host{--_lr-tree-tier-row-height:initial;--_lr-tree-tier-row-padding:initial;--_lr-tree-tier-toggle-size:calc(var(--_lr-tree-tier-row-height) - var(--lr-space-xs));display:block}:host([size]){--_lr-tree-tier-row-padding:0}:host([size="2xs"]){--_lr-tree-tier-row-height:var(--lr-size-1-25rem)}:host([size=xs]){--_lr-tree-tier-row-height:var(--lr-size-1-5rem)}:host([size=s]),:host([size=small]){--_lr-tree-tier-row-height:var(--lr-size-2rem)}:host([size=m]),:host([size=medium]){--_lr-tree-tier-row-height:var(--lr-size-2-25rem)}:host([size=l]),:host([size=large]){--_lr-tree-tier-row-height:var(--lr-size-2-5rem)}:host([size=xl]){--_lr-tree-tier-row-height:var(--lr-size-3-5rem)}[part=drop-indicator]{z-index:var(--lr-layer-content);pointer-events:none;block-size:var(--lr-border-width-medium);background:var(--lr-tree-drop-indicator-color,var(--lr-color-brand));position:absolute;transform:translateY(-50%)}[part~=base]{flex-direction:column;display:flex;position:relative;overflow:auto hidden}[part=limit]{padding:var(--lr-space-s);color:var(--lr-color-text-quiet);font-size:var(--lr-font-size-sm)}`;export{styles};
|
|
@@ -149,7 +149,8 @@ export type LyraComboboxChangeEvent<Multiple extends boolean=boolean> =LyraCombo
|
|
|
149
149
|
* a host that owns its own retry timing.
|
|
150
150
|
* @method refresh - `refresh(): void` — re-runs the current `source` query without changing the
|
|
151
151
|
* source's identity, its debounce controller, or its delay. Queues for the next open when the
|
|
152
|
-
* listbox is closed; does
|
|
152
|
+
* listbox is closed; does not call a source while the query is below `minQueryLength`, and
|
|
153
|
+
* does nothing without a `source`.
|
|
153
154
|
* @slot source-error - Replaces the built-in failed-`source` state, retry control included. Named
|
|
154
155
|
* apart from the form-control `error` slot deliberately: they are different failures and a
|
|
155
156
|
* control has to be able to show both.
|
|
@@ -158,8 +159,8 @@ export type LyraComboboxChangeEvent<Multiple extends boolean=boolean> =LyraCombo
|
|
|
158
159
|
* @event lr-after-show - The listbox finished opening and its transition settled.
|
|
159
160
|
* @event lr-hide - The listbox is about to close, however `open` became false. Conditionally
|
|
160
161
|
* cancelable: connected transitions can be vetoed on the same terms as `lr-show`; an
|
|
161
|
-
* already-removed element closing on disconnect
|
|
162
|
-
* a veto. Vetoing an ordinary connected dismissal preserves the live filter query, active
|
|
162
|
+
* already-removed element closing on disconnect, a failed positioning runtime, or an enforced
|
|
163
|
+
* minimum-query close cannot honour a veto. Vetoing an ordinary connected dismissal preserves the live filter query, active
|
|
163
164
|
* option, and async rows exactly.
|
|
164
165
|
* @event lr-after-hide - The listbox finished closing and its transition settled.
|
|
165
166
|
* @event lr-clear - The value was cleared.
|
|
@@ -170,7 +171,8 @@ export type LyraComboboxChangeEvent<Multiple extends boolean=boolean> =LyraCombo
|
|
|
170
171
|
* host's `value` (the committed selection). User-input only: typing and the clear button announce
|
|
171
172
|
* it. Programmatic edits, including `setRangeText()`, are silent. `setRangeText()` preserves
|
|
172
173
|
* the replaced filter text and synchronizes its query/options without changing selected value.
|
|
173
|
-
* Picking a row, resetting the form, and
|
|
174
|
+
* Picking a row, resetting the form, and ordinary dismissal also update the filter silently.
|
|
175
|
+
* A minimum-query close instead preserves the typed filter.
|
|
174
176
|
* @event {FocusEvent} blur - Re-dispatched from the internal native input as a bubbling, composed,
|
|
175
177
|
* non-cancelable event.
|
|
176
178
|
* @event {FocusEvent} focus - Re-dispatched from the internal native input as a bubbling, composed,
|
|
@@ -328,7 +330,7 @@ export declare class LyraCombobox<Multiple extends boolean=boolean>extends LyraF
|
|
|
328
330
|
/** `data` carries opaque per-row caller payload -- preserve each item's identity through the
|
|
329
331
|
* frozen event envelope instead of recursively cloning unknown data, the same policy
|
|
330
332
|
* `<lr-prompt-queue>`'s `lr-queue-change` detail uses for its own `items`. */
|
|
331
|
-
protected static readonly identityEventDetailCollectionItems:Readonly<{'lr-input':readonly string[];'lr-change':readonly string[];}>;static formAssociated:boolean;static styles:import("lit").CSSResultGroup[];static properties:{customError:{attribute:string;reflect:boolean;noAccessor:boolean;};multiple:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};disabled:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};required:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};readonly:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};value:{noAccessor:boolean;};name:{reflect:boolean;noAccessor:boolean;converter:import("lit").ComplexAttributeConverter<string,unknown>;};maxOptionsVisible:{type:NumberConstructor;attribute:string;noAccessor:boolean;};maxRender:{type:NumberConstructor;attribute:string;noAccessor:boolean;};sourceDelay:{type:NumberConstructor;attribute:string;noAccessor:boolean;};};placeholder:string;label:string;
|
|
333
|
+
protected static readonly identityEventDetailCollectionItems:Readonly<{'lr-input':readonly string[];'lr-change':readonly string[];}>;static formAssociated:boolean;static styles:import("lit").CSSResultGroup[];static properties:{customError:{attribute:string;reflect:boolean;noAccessor:boolean;};multiple:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};disabled:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};required:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};readonly:{type:BooleanConstructor;reflect:boolean;noAccessor:boolean;};value:{noAccessor:boolean;};name:{reflect:boolean;noAccessor:boolean;converter:import("lit").ComplexAttributeConverter<string,unknown>;};maxOptionsVisible:{type:NumberConstructor;attribute:string;noAccessor:boolean;};maxRender:{type:NumberConstructor;attribute:string;noAccessor:boolean;};sourceDelay:{type:NumberConstructor;attribute:string;noAccessor:boolean;};minQueryLength:{type:NumberConstructor;attribute:string;noAccessor:boolean;};};placeholder:string;label:string;
|
|
332
334
|
/**
|
|
333
335
|
* Whether the `label` renders on screen. `hidden` keeps the label as the accessible name but
|
|
334
336
|
* removes it visually (compact toolbars, table cells); hint, error and required semantics are
|
|
@@ -336,8 +338,8 @@ protected static readonly identityEventDetailCollectionItems:Readonly<{'lr-input
|
|
|
336
338
|
* @attr label-display
|
|
337
339
|
*/
|
|
338
340
|
labelDisplay:LyraLabelDisplay;hint:string;errorText:string;
|
|
339
|
-
/** Whether the listbox is open. Disabled or
|
|
340
|
-
* including a synchronous fieldset cascade. */
|
|
341
|
+
/** Whether the listbox is open. Disabled, readonly, or below-minimum queries reject direct
|
|
342
|
+
* reopen attempts, including a synchronous fieldset cascade. */
|
|
341
343
|
get open():boolean;set open(next:boolean);
|
|
342
344
|
/** Allows a nonmatching query to be created as a new option through the cancelable `lr-create`
|
|
343
345
|
* veto point. The default action appends and selects an `<lr-option>`. */
|
|
@@ -497,9 +499,9 @@ get autocorrect():boolean;set autocorrect(next:boolean);
|
|
|
497
499
|
get inputmode():string;set inputmode(next:string);get enterkeyhint():string;set enterkeyhint(next:string);
|
|
498
500
|
/** Live text in the native filter input. Programmatic writes are event-silent.
|
|
499
501
|
* @default '' */
|
|
500
|
-
get inputValue():string;set inputValue(next:string);private query;private explicitInputValue;private activeIndex;private options;private optionsObserved;private touched;private validityRevision;private validatorAttributeObserver?;private readonly slotPresence;private sourceLoading;private sourceFailed;private sourceEverSettled;private asyncRows;private _sourceTotal;private _sourceTruncated;private readonly sourceErrorAnnouncements;private inputEl?;private optionsSlot?;private readonly sourceDebounce;private sourceToken;private refreshQueued;private sourceAbort?;private _sourceWarmed;private _selectedLabelCache;private _selectedRowCache;private pendingSelectedRowValues?;private _renderedRows;private internals;private _open;private validityController;
|
|
502
|
+
get inputValue():string;set inputValue(next:string);private _query;private get query();private set query(value);private explicitInputValue;private activeIndex;private options;private optionsObserved;private touched;private validityRevision;private validatorAttributeObserver?;private readonly slotPresence;private sourceLoading;private sourceFailed;private sourceEverSettled;private asyncRows;private _sourceTotal;private _sourceTruncated;private readonly sourceErrorAnnouncements;private inputEl?;private optionsSlot?;private readonly sourceDebounce;private sourceToken;private refreshQueued;private sourceAbort?;private _sourceWarmed;private _selectedLabelCache;private _selectedRowCache;private pendingSelectedRowValues?;private _renderedRows;private internals;private _open;private validityController;
|
|
501
503
|
/** Consumer-supplied validation message reflected through `custom-error`.*/
|
|
502
|
-
customError:string|null;private _fieldsetDisabled;private listId;private inputId;private cleanup?;private listboxPositioned;private positioningGeneration;private positioningReady;private resolvePositioningReady?;private overlayHandle?;private restoreFocusOnClose;private restoringOverlayFocus;private readonly popupController;private listboxHidden;private listboxRendered;private _isFirstUpdate;private openVetoed;private closeAfterPositioningFailure;private closeCleanupPending;private _selected;private singleSelectedOption?;private readonly sourceOptionsByRow;private _valueDirty;private _multiple;private _disabled;private _required;private _readonly;private _defaultSelected;private _defaultCaptured;private _restoredStateActive;private _name;private validationTargetOverride?;
|
|
504
|
+
customError:string|null;private _fieldsetDisabled;private listId;private inputId;private cleanup?;private listboxPositioned;private positioningGeneration;private positioningReady;private resolvePositioningReady?;private overlayHandle?;private restoreFocusOnClose;private restoringOverlayFocus;private readonly popupController;private listboxHidden;private listboxRendered;private _isFirstUpdate;private openVetoed;private closeAfterPositioningFailure;private minimumQueryClosePending;private minimumQueryCloseUnpainted;private closeCleanupPending;private _selected;private singleSelectedOption?;private readonly sourceOptionsByRow;private _valueDirty;private _multiple;private _disabled;private _required;private _readonly;private _defaultSelected;private _defaultCaptured;private _restoredStateActive;private _name;private validationTargetOverride?;
|
|
503
505
|
/**
|
|
504
506
|
* Bounds the popup to roughly this many option rows, leaving the rest reachable by scrolling.
|
|
505
507
|
*
|
|
@@ -516,7 +518,7 @@ customError:string|null;private _fieldsetDisabled;private listId;private inputId
|
|
|
516
518
|
* as it was. Zero, negative, and non-finite values normalize to unset rather than collapsing the
|
|
517
519
|
* popup.
|
|
518
520
|
*/
|
|
519
|
-
visibleOptions?:number;private _maxOptionsVisible;private _maxRender;private _sourceDelay;constructor();get form():HTMLFormElement|null;set form(owner:FormOwnerValue);
|
|
521
|
+
visibleOptions?:number;private _maxOptionsVisible;private _maxRender;private _sourceDelay;private _minQueryLength;constructor();get form():HTMLFormElement|null;set form(owner:FormOwnerValue);
|
|
520
522
|
/** Native element used as the constraint-validation focus anchor.*/
|
|
521
523
|
get validationTarget():HTMLElement|undefined;set validationTarget(next:HTMLElement|undefined);
|
|
522
524
|
/** Clears consumer-supplied validity and restores the current intrinsic constraints.*/
|
|
@@ -588,7 +590,12 @@ get maxRender():number;
|
|
|
588
590
|
/** Debounce (ms) between the last keystroke and the `source` call. Sanitized to a finite
|
|
589
591
|
* duration clamped to `[0, browser-timer-ceiling]`; `0` fires on every keystroke, a
|
|
590
592
|
* non-finite value falls back to the `200` default. */
|
|
591
|
-
get sourceDelay():number;set sourceDelay(next:number);
|
|
593
|
+
get sourceDelay():number;set sourceDelay(next:number);
|
|
594
|
+
/** Minimum Unicode code points in the trimmed query before suggestions or source calls are
|
|
595
|
+
* allowed. Counting never changes the displayed or provider query. Zero preserves unrestricted
|
|
596
|
+
* opening and selected-value source warmup; positive values also gate that empty-query warmup.
|
|
597
|
+
* @default 0 */
|
|
598
|
+
get minQueryLength():number;set minQueryLength(next:number);private meetsMinimumQuery;private enforceMinimumQuery;set maxRender(next:number);
|
|
592
599
|
/** Provider-side match count for the latest accepted source response, before component caps.*/
|
|
593
600
|
get sourceTotal():number;
|
|
594
601
|
/** Whether the latest response contained or reported more rows than the bounded retained set.*/
|
|
@@ -626,7 +633,8 @@ formDisabledCallback(disabled:boolean):void;private markInteracted;checkValidity
|
|
|
626
633
|
* The message is caller-supplied content, so it is used verbatim and never localized here.
|
|
627
634
|
*/
|
|
628
635
|
setCustomValidity(message:string):void;disconnectedCallback():void;private collectOptions;private collectOptionsFromSlot;private refreshOptionDefaults;private callbackRefreshEpoch;requestUpdate(...args:Parameters<LyraElement['requestUpdate']>):void;private optionMemo;private memoOption;private get optionIndex();private get asyncIndex();private get searchCorpus();private pendingSelectedWrites;private selectedWritesQueued;private flushSelectedWrites;private optionRefreshPending;private onOptionChange;private reflectSelected;private labelFor;private isUnknownValue;private adornmentClones;private adornmentMarkup;private adornmentsFor;private rowForOption;private get hasSelectionSourceRows();private applySelectedRowValues;private applyPendingSelectedRows;private get unknownRows();private get createRow();private capRows;private lastRenderedRows;private get renderedRows();private computeRenderedRows;private normalizeActiveIndex;private get filtered();private get displayValue();private announceOpenTransition;
|
|
629
|
-
/** Opens the listbox and resolves after `lr-after-show
|
|
636
|
+
/** Opens the listbox and resolves after `lr-after-show`; a below-minimum query resolves
|
|
637
|
+
* immediately without starting an opening. */
|
|
630
638
|
show():Promise<void>;
|
|
631
639
|
/** Closes the listbox and resolves after `lr-after-hide`.*/
|
|
632
640
|
hide():Promise<void>;private finalizeCloseState;private onDocPointer;private activateListboxOverlay;private beginListboxPositioning;private invalidateListboxPositioning;private resolveCurrentPositioning;private startListboxPositioning;private teardownListboxOverlay;private reconnectOpenPopup;private syncVisibleOptionsCap;protected updated(changed:PropertyValues):void;private settleTransition;private emitValueEvents;private assignValue;private createOption;private commitCustomValue;private pickRow;private removeValueAt;private clear;private onInput;
|