123456 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import{r as t,c as e,h as i,H as n,g as a}from"./p-91755387.js";import{f as o,n as c,l as s,g as r,a as l,t as d,m as h}from"./p-96bf42e5.js";import{C as m}from"./p-af9e6e54.js";import{c as u,d as p}from"./p-a2f5420b.js";import{u as f}from"./p-4d9ab6e1.js";import"./p-d5bfadd8.js";import"./p-8dc9be64.js";var b;function v(t,e){const i="down"===e?"nextElementSibling":"previousElementSibling";let n=t,a=null;for(;null==(o=n)?void 0:o.matches("calcite-tree-item");){if(!n.disabled){a=n;break}n=n[i]}var o;return a}!function(t){t.Single="single",t.Multi="multi",t.None="none",t.Children="children",t.MultiChildren="multi-children",t.Ancestors="ancestors"}(b||(b={}));const k=class{constructor(i){t(this,i),this.calciteTreeSelect=e(this,"calciteTreeSelect",6),this.lines=!1,this.inputEnabled=!1,this.scale="m",this.selectionMode=b.Single}componentWillRender(){var t;const e=null===(t=this.el.parentElement)||void 0===t?void 0:t.closest("calcite-tree");this.lines=e?e.lines:this.lines,this.scale=e?e.scale:this.scale,this.selectionMode=e?e.selectionMode:this.selectionMode,this.child=!!e}render(){return i(n,{"aria-multiselectable":this.child?void 0:(this.selectionMode===b.Multi||this.selectionMode===b.MultiChildren).toString(),role:this.child?void 0:"tree",tabIndex:this.getRootTabIndex()},i("slot",null))}onFocus(){if(!this.child){const t=this.el.querySelector("calcite-tree-item[selected]:not([disabled])")||this.el.querySelector("calcite-tree-item:not([disabled])");o(t)}}onFocusIn(t){(t.relatedTarget===this.el||!this.el.contains(t.relatedTarget))&&this.el.removeAttribute("tabindex")}onFocusOut(t){!this.el.contains(t.relatedTarget)&&(this.el.tabIndex=this.getRootTabIndex())}onClick(t){const e=t.target,i=c(e.querySelectorAll("calcite-tree-item"));if(this.child)return;if(this.child||(t.preventDefault(),t.stopPropagation()),this.selectionMode===b.Ancestors&&!this.child)return void this.updateAncestorTree(t);const n=this.selectionMode===b.None,a=!n&&t.detail.modifyCurrentSelection&&(this.selectionMode===b.Multi||this.selectionMode===b.MultiChildren),o=this.selectionMode===b.MultiChildren||this.selectionMode===b.Children,s=!a&&((this.selectionMode===b.Single||this.selectionMode===b.Multi)&&i.length<=0||this.selectionMode===b.Children||this.selectionMode===b.MultiChildren),r=this.selectionMode===b.Children||this.selectionMode===b.MultiChildren;if(!this.child){const l=[];null!==this.selectionMode&&(!e.hasChildren||e.hasChildren&&(this.selectionMode===b.Children||this.selectionMode===b.MultiChildren))&&l.push(e),o&&i.forEach((t=>{l.push(t)})),s&&c(this.el.querySelectorAll("calcite-tree-item[selected]")).forEach((t=>{l.includes(t)||(t.selected=!1)})),r&&!t.detail.forceToggle&&(e.expanded=!0),a&&window.getSelection().removeAllRanges(),a&&e.selected||o&&t.detail.forceToggle?l.forEach((t=>{t.disabled||(t.selected=!1)})):n||l.forEach((t=>{t.disabled||(t.selected=!0)}))}const l=n?[e]:c(this.el.querySelectorAll("calcite-tree-item")).filter((t=>t.selected));this.calciteTreeSelect.emit({selected:l}),t.stopPropagation()}keyDownHandler(t){var e;const i=this.el.closest("calcite-tree:not([child])"),n=t.target;if(i===this.el&&"CALCITE-TREE-ITEM"===n.tagName&&this.el.contains(n))if("ArrowDown"!==t.key){if("ArrowUp"===t.key){const e=v(n.previousElementSibling,"up");e&&(e.focus(),t.preventDefault())}if("ArrowLeft"===t.key&&!n.disabled){if(n.hasChildren&&n.expanded)return n.expanded=!1,void t.preventDefault();const e=n.parentElement.closest("calcite-tree-item");return!e||n.hasChildren&&!1!==n.expanded?void 0:(e.focus(),void t.preventDefault())}"ArrowRight"!==t.key||n.disabled||n.hasChildren&&(n.expanded&&s(this.el).activeElement===n?(null===(e=v(n.querySelector("calcite-tree-item"),"down"))||void 0===e||e.focus(),t.preventDefault()):(n.expanded=!0,t.preventDefault()))}else{const e=v(n.nextElementSibling,"down");e&&(e.focus(),t.preventDefault())}}updateAncestorTree(t){const e=t.target;if(e.disabled)return;const i=[];let n=e.parentElement.closest("calcite-tree-item");for(;n;)i.push(n),n=n.parentElement.closest("calcite-tree-item");const a=Array.from(e.querySelectorAll("calcite-tree-item:not([disabled])")),o=a.filter((t=>!t.hasChildren)),s=a.filter((t=>t.hasChildren)),r=e.hasChildren?!(e.selected||e.indeterminate):!e.selected;function l(t,e){const i=t.filter((t=>t.selected)),n=t.filter((t=>!t.selected));e.selected=i.length===t.length,e.indeterminate=i.length>0&&n.length>0}o.forEach((t=>{t.selected=r,t.indeterminate=!1})),s.forEach((t=>{l(Array.from(t.querySelectorAll(":scope > calcite-tree > calcite-tree-item")),t)})),e.hasChildren?l(a,e):(e.selected=r,e.indeterminate=!1),i.forEach((t=>{const e=c(t.querySelectorAll("calcite-tree-item")),i=e.filter((t=>t.selected));if(0===i.length)return t.selected=!1,void(t.indeterminate=!1);const n=i.length<e.length;t.indeterminate=n,t.selected=!n})),this.calciteTreeSelect.emit({selected:c(this.el.querySelectorAll("calcite-tree-item")).filter((t=>t.selected))})}getRootTabIndex(){return this.child?-1:0}get el(){return a(this)}};k.style="@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}:host(:focus){outline:2px solid transparent;outline-offset:2px}";const g=class{constructor(i){t(this,i),this.calciteInternalTreeItemSelect=e(this,"calciteInternalTreeItemSelect",6),this.disabled=!1,this.selected=!1,this.expanded=!1,this.parentExpanded=!1,this.depth=-1,this.hasChildren=null,this.iconClickHandler=t=>{t.stopPropagation(),this.expanded=!this.expanded},this.childrenClickHandler=t=>t.stopPropagation(),this.updateParentIsExpanded=(t,e)=>{r(t,"children",{all:!0,selector:"calcite-tree-item"}).forEach((t=>t.parentExpanded=e))},this.updateAncestorTree=()=>{var t;if(this.selected&&this.selectionMode===b.Ancestors){const e=[];let i=this.parentTreeItem;for(;i;)e.push(i),i=null===(t=i.parentElement)||void 0===t?void 0:t.closest("calcite-tree-item");e.forEach((t=>t.indeterminate=!0))}}}expandedHandler(t){this.updateParentIsExpanded(this.el,t)}getselectionMode(){this.isSelectionMultiLike=this.selectionMode===b.Multi||this.selectionMode===b.MultiChildren}connectedCallback(){var t;if(this.parentTreeItem=null===(t=this.el.parentElement)||void 0===t?void 0:t.closest("calcite-tree-item"),this.parentTreeItem){const{expanded:t}=this.parentTreeItem;this.updateParentIsExpanded(this.parentTreeItem,t)}u(this)}disconnectedCallback(){p(this)}componentWillRender(){var t;this.hasChildren=!!this.el.querySelector("calcite-tree"),this.depth=0;let e,i=this.el.closest("calcite-tree");if(i)for(this.selectionMode=i.selectionMode,this.scale=i.scale||"m",this.lines=i.lines;i&&(e=null===(t=i.parentElement)||void 0===t?void 0:t.closest("calcite-tree"),e!==i);)i=e,this.depth=this.depth+1}componentDidLoad(){this.updateAncestorTree()}componentDidRender(){f(this,(()=>this.parentExpanded||1===this.depth))}render(){const t="rtl"===l(this.el),e=this.selectionMode===b.Single||this.selectionMode===b.Children,a=this.selectionMode===b.Multi||this.selectionMode===b.MultiChildren,o=this.selectionMode===b.None&&!this.hasChildren,c=this.hasChildren?i("calcite-icon",{class:{chevron:!0,[m.rtl]:t},"data-test-id":"icon",icon:"chevron-right",onClick:this.iconClickHandler,scale:"s"}):null,s=i("slot",{key:"default-slot"}),r=this.selectionMode===b.Ancestors?i("label",{class:"checkbox-label",key:"checkbox-label"},i("calcite-checkbox",{checked:this.selected,class:"checkbox","data-test-id":"checkbox",indeterminate:this.hasChildren&&this.indeterminate,scale:this.scale,tabIndex:-1}),s):null,h=e?"bullet-point":a?"check":o?"blank":null,u=h?i("calcite-icon",{class:{"bullet-point":"bullet-point"===h,checkmark:"check"===h,[m.rtl]:t},icon:h,scale:"s"}):null,p=!(this.parentExpanded||1===this.depth);return i(n,{"aria-expanded":this.hasChildren?d(this.expanded):void 0,"aria-hidden":d(p),"aria-selected":this.selected?"true":a?"false":void 0,"calcite-hydrated-hidden":p,role:"treeitem"},i("div",{class:{"node-container":!0,[m.rtl]:t},"data-selection-mode":this.selectionMode,ref:t=>this.defaultSlotWrapper=t},c,u,r||s),i("div",{class:{"children-container":!0,[m.rtl]:t},"data-test-id":"calcite-tree-children",onClick:this.childrenClickHandler,ref:t=>this.childrenSlotWrapper=t,role:this.hasChildren?"group":void 0},i("slot",{name:"children"})))}onClick(t){const[e]=h(this.el,"a");e&&"a"!==t.composedPath()[0].tagName.toLowerCase()&&window.open(e.href,""===e.target?"_self":e.target),this.calciteInternalTreeItemSelect.emit({modifyCurrentSelection:this.selectionMode===b.Ancestors||this.isSelectionMultiLike,forceToggle:!1})}keyDownHandler(t){let e;switch(t.key){case" ":this.calciteInternalTreeItemSelect.emit({modifyCurrentSelection:this.isSelectionMultiLike,forceToggle:!1}),t.preventDefault();break;case"Enter":const i=c(this.el.children).find((t=>t.matches("a")));i?(i.click(),this.selected=!0):this.calciteInternalTreeItemSelect.emit({modifyCurrentSelection:this.isSelectionMultiLike,forceToggle:!1}),t.preventDefault();break;case"Home":e=this.el.closest("calcite-tree:not([child])");const n=e.querySelector("calcite-tree-item");null==n||n.focus();break;case"End":e=this.el.closest("calcite-tree:not([child])");let a=e.children[e.children.length-1],o=c(a.children).find((t=>t.matches("calcite-tree")));for(;o;)a=o.children[e.children.length-1],o=c(a.children).find((t=>t.matches("calcite-tree")));null==a||a.focus()}}get el(){return a(this)}static get watchers(){return{expanded:["expandedHandler"],selectionMode:["getselectionMode"]}}};g.style='@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:block;max-inline-size:100%;cursor:pointer;color:var(--calcite-ui-text-3)}:host([calcite-hydrated-hidden]){visibility:hidden !important;pointer-events:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([scale=s]){font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=s]) .node-container{--calcite-tree-padding-y:0.25rem}:host([scale=s]) .node-container .checkbox,:host([scale=s]) .node-container .chevron,:host([scale=s]) .node-container .checkmark,:host([scale=s]) .node-container .bullet-point{margin-inline:0.25rem}:host([scale=m]){font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=m]) .node-container{--calcite-tree-padding-y:0.5rem}:host([scale=m]) .node-container .checkbox,:host([scale=m]) .node-container .chevron,:host([scale=m]) .node-container .checkmark,:host([scale=m]) .node-container .bullet-point{margin-inline:0.5rem}:host([scale=l]){font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=l]) .node-container{--calcite-tree-padding-y:0.75rem}:host([scale=l]) .node-container .checkbox,:host([scale=l]) .node-container .chevron,:host([scale=l]) .node-container .checkmark,:host([scale=l]) .node-container .bullet-point{margin-inline:0.75rem}:host([lines]) .children-container:after{position:absolute;inset-block-start:0px;z-index:1;inline-size:1px;transition-property:color, background-color, border-color, text-decoration-color, fill, stroke;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-duration:150ms;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;block-size:96%;content:"";background-color:var(--calcite-ui-border-2)}:host(:not([lines])) .node-container:after{display:none}::slotted(*){min-inline-size:0px;max-inline-size:100%;overflow-wrap:break-word;color:inherit;text-decoration:none !important}::slotted(*):hover{text-decoration:none !important}::slotted(a){inline-size:100%;text-decoration-line:none}:host{outline-color:transparent}:host(:focus:not([disabled])){outline:2px solid transparent;outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.checkbox{line-height:0}.checkbox-label{pointer-events:none;display:flex;align-items:center}.checkbox:focus{outline:2px solid transparent;outline-offset:2px}.children-container{position:relative;block-size:0px;overflow:hidden;margin-inline-start:1.25rem;transform:scaleY(0);opacity:0;transition:var(--calcite-animation-timing) cubic-bezier(0.215, 0.44, 0.42, 0.88), opacity var(--calcite-animation-timing) cubic-bezier(0.215, 0.44, 0.42, 0.88), all var(--calcite-animation-timing) ease-in-out;transform-origin:top}:host([expanded])>.children-container{transform:scaleY(1);opacity:1;block-size:auto}.node-container{position:relative;display:flex;align-items:center;padding-block:var(--calcite-tree-padding-y);padding-inline:0}.node-container .checkmark,.node-container .bullet-point{opacity:0;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;color:var(--calcite-ui-border-1)}.node-container:hover .checkmark,.node-container:hover .bullet-point,:host([selected]) .node-container:hover .checkmark,:host([selected]) .node-container:hover .bullet-point,:host(:focus:not([disabled])) .node-container .checkmark,:host(:focus:not([disabled])) .node-container .bullet-point{opacity:1}:host([selected])>.node-container,:host([selected])>.node-container:hover{font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}:host([selected])>.node-container .bullet-point,:host([selected])>.node-container .checkmark,:host([selected])>.node-container:hover .bullet-point,:host([selected])>.node-container:hover .checkmark{opacity:1;color:var(--calcite-ui-brand)}:host([selection-mode=none]:not([has-children])):host([scale=s])>.node-container{padding-inline-start:0.5rem}:host([selection-mode=none]:not([has-children])):host([scale=m])>.node-container{padding-inline-start:1rem}:host([selection-mode=none]:not([has-children])):host([scale=l])>.node-container{padding-inline-start:1.5rem}:host(:not([has-children])):host([scale=s])>.node-container[data-selection-mode=ancestors] .checkbox{padding-inline-start:1.25rem}:host(:not([has-children])):host([scale=m])>.node-container[data-selection-mode=ancestors] .checkbox{padding-inline-start:1.5rem}:host(:not([has-children])):host([scale=l])>.node-container[data-selection-mode=ancestors] .checkbox{padding-inline-start:1.75rem}:host([has-children])>.node-container[data-selection-mode=ancestors] .checkbox{margin-inline-start:0}:host([has-children])>.node-container .bullet-point,:host([has-children])>.node-container .checkmark{display:none}:host([has-children][expanded]:not([selected]):not([selection-mode=none]))>.node-container ::slotted(*){font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}:host([has-children][selected])>.node-container[data-selection-mode=children],:host([has-children][selected])>.node-container[data-selection-mode=multi-children]{color:var(--calcite-ui-brand)}.chevron{position:relative;align-self:center;color:var(--calcite-ui-text-3);transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;flex:0 0 auto;transform:rotate(0deg)}.calcite--rtl .chevron{transform:rotate(180deg)}:host([expanded])>.node-container>.chevron{transform:rotate(90deg)}:host([selected]) .checkmark,:host([selected]) .bullet-point{color:var(--calcite-ui-brand)}';export{k as calcite_tree,g as calcite_tree_item}
|