@powerduck/tree 0.7.4 → 0.7.7

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.
@@ -1,5 +1,6 @@
1
+ import * as react from 'react';
1
2
  import { ReactNode } from 'react';
2
- import { T as TreeNode } from '../types-DVz8c2Yd.js';
3
+ import { T as TreeNode } from '../types-CH939NGV.js';
3
4
  import { ReorderResult } from '../core/index.js';
4
5
 
5
6
  /**
@@ -90,6 +91,8 @@ interface TreeProps<TMetadata = unknown> {
90
91
  className?: string;
91
92
  /** Inline styles. */
92
93
  style?: React.CSSProperties;
94
+ /** Optional standalone theme. Omit to inherit host theme tokens. */
95
+ theme?: "light" | "dark";
93
96
  /** Size variant. Default "sm". */
94
97
  size?: "xs" | "sm" | "md";
95
98
  /** Visual variant for different use cases. Default "default".
@@ -100,6 +103,8 @@ interface TreeProps<TMetadata = unknown> {
100
103
  variant?: "default" | "api" | "schema" | "doc";
101
104
  /** Whether to show indent guides. Default true. */
102
105
  showIndentGuides?: boolean;
106
+ /** Window fixed-height rows above 500 visible nodes by default. Disabled for doc variants and custom row renderers. */
107
+ virtualized?: boolean | "auto";
103
108
  /** Maximum height before scrolling. Default undefined (no limit). */
104
109
  maxHeight?: number | string;
105
110
  /** Callback ref for the root DOM element. */
@@ -177,7 +182,7 @@ declare function useTreeSearch<TMetadata>(nodes: TreeNode<TMetadata>[]): {
177
182
  /**
178
183
  * Manages tree expansion state.
179
184
  *
180
- * Supports controlled (via onExpandedChange) and uncontrolled usage.
185
+ * Keeps local state and notifies consumers through onExpandedChange.
181
186
  * Provides expandAll, collapseAll, and expandToDepth helpers.
182
187
  */
183
188
  declare function useTreeExpansion<TMetadata>(nodes: TreeNode<TMetadata>[], options?: {
@@ -195,6 +200,7 @@ declare function useTreeExpansion<TMetadata>(nodes: TreeNode<TMetadata>[], optio
195
200
  allBranchIds: string[];
196
201
  setNodeElementRef: (id: string, element: HTMLElement | null) => void;
197
202
  scrollToNode: (id: string) => void;
203
+ nodeElementRefs: react.RefObject<Map<string, HTMLElement>>;
198
204
  };
199
205
 
200
206
  /**
@@ -1 +1 @@
1
- import{filterTree as e,findPath as n,getBranchIds as t,getExpandableIds as r,moveNode as d,reorderNode as o}from"../chunk-5KF7QUTD.js";import{forwardRef as a,memo as i,useCallback as l,useEffect as s,useImperativeHandle as c,useMemo as u,useRef as p,useState as h}from"react";import{useCallback as g,useMemo as f,useRef as m,useState as x}from"react";function I(e,n={}){const{defaultExpandedIds:d,defaultExpandDepth:o=1,onExpandedChange:a}=n,i=f(()=>d&&d.length>0?[...d]:o<=1?[]:r(e,{maxDepth:o-1,onlyWithChildren:!0}),[]),[l,s]=x(i),c=m(new Map),u=f(()=>t(e),[e]),p=f(()=>u.length>0&&u.every(e=>l.includes(e)),[u,l]),h=g(e=>{s(e),a?.(e)},[a]),I=g(e=>{s(n=>{const t=n.includes(e)?n.filter(n=>n!==e):[...n,e];return a?.(t),t})},[a]),v=g(()=>{h([...u])},[u,h]),D=g(()=>{h([])},[h]),N=g(n=>{const t=r(e,{maxDepth:n,onlyWithChildren:!0});h(t)},[e,h]),b=g((e,n)=>{n?c.current.set(e,n):c.current.delete(e)},[]),S=g(e=>{const n=c.current.get(e);n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},[]);return{expandedIds:l,setExpandedIds:h,toggleNode:I,expandAll:v,collapseAll:D,expandToDepth:N,isAllExpanded:p,allBranchIds:u,setNodeElementRef:b,scrollToNode:S}}import{useCallback as v,useDeferredValue as D,useMemo as N,useState as b}from"react";function S(n){const[t,r]=b(""),d=D(t),[o,a]=b(null),i=d.trim().length>0,l=N(()=>i?e(n,{query:d,keepAncestors:!0}):n,[n,d,i]),s=v((e,n)=>{const d=t.trim(),o=e.trim();!d&&o&&a(n),d&&!o&&a(null),r(e)},[t]),c=v(()=>{r(""),a(null)},[]);return{query:t,deferredQuery:d,isSearching:i,filteredNodes:l,expandedBeforeSearch:o,handleQueryChange:s,clearSearch:c}}function C(e,n,t=[]){for(const r of e){if(r.id===n)return[...t,r];if(r.children?.length){const e=C(r.children,n,[...t,r]);if(e)return e}}return null}function y(e,n){const t=C(e,n);return t?t.slice(0,-1).map(e=>e.id):[]}var M={get:"GET",post:"POST",put:"PUT",delete:"DEL",patch:"PATCH",head:"HEAD",options:"OPT",trace:"TRA",connect:"CONN"};function E(e){const n=e.toLowerCase().trim();return M[n]??n.slice(0,4).toUpperCase()}import{LuBraces as w,LuChevronDown as B,LuChevronRight as O,LuEllipsisVertical as A,LuFolder as L,LuFolderOpen as P,LuGripVertical as R,LuList as k,LuRefreshCw as T,LuSearch as z,LuZap as G}from"react-icons/lu";import{MdOutlineUnfoldMore as $,MdUnfoldLess as q}from"react-icons/md";import{Fragment as H,jsx as Q,jsxs as j}from"react/jsx-runtime";var F={branchControl:"pde-tree-branchControl",contextMenu:"pde-tree-contextMenu",contextMenuItem:"pde-tree-contextMenuItem",contextMenuItemDanger:"pde-tree-contextMenuItemDanger",contextMenuItemConfirming:"pde-tree-contextMenuItemConfirming",contextMenuIcon:"pde-tree-contextMenuIcon",contextMenuSeparator:"pde-tree-contextMenuSeparator",deprecatedLabel:"pde-tree-deprecatedLabel",dragHandle:"pde-tree-dragHandle",dragHandleDisabled:"pde-tree-dragHandleDisabled",dropIndicatorAfter:"pde-tree-dropIndicatorAfter",dropIndicatorBefore:"pde-tree-dropIndicatorBefore",dropIndicatorChild:"pde-tree-dropIndicatorChild",emptyState:"pde-tree-emptyState",expandIcon:"pde-tree-expandIcon",expandIconExpanded:"pde-tree-expandIconExpanded",expandIconPlaceholder:"pde-tree-expandIconPlaceholder",highlight:"pde-tree-highlight",iconButton:"pde-tree-iconButton",indentGuide:"pde-tree-indentGuide",leafItem:"pde-tree-leafItem",methodBadge:"pde-tree-methodBadge",methodDelete:"pde-tree-methodDelete",methodGet:"pde-tree-methodGet",methodOther:"pde-tree-methodOther",methodPatch:"pde-tree-methodPatch",methodPost:"pde-tree-methodPost",methodPut:"pde-tree-methodPut",moreButton:"pde-tree-moreButton",moreButtonActive:"pde-tree-moreButtonActive",nodeDragging:"pde-tree-nodeDragging",nodeIcon:"pde-tree-nodeIcon",primitiveDot:"pde-tree-primitiveDot",nodeLabel:"pde-tree-nodeLabel",nodeLabelBranch:"pde-tree-nodeLabelBranch",nodeRow:"pde-tree-nodeRow",nodeRowSelected:"pde-tree-nodeRowSelected",nodeSuffix:"pde-tree-nodeSuffix",requiredDot:"pde-tree-requiredDot",root:"pde-tree-root",searchIcon:"pde-tree-searchIcon",searchInput:"pde-tree-searchInput",searchInputWrap:"pde-tree-searchInputWrap",searchRow:"pde-tree-searchRow",toolbar:"pde-tree-toolbar",treeContainer:"pde-tree-treeContainer"};function W({expanded:e}){return Q("span",{className:F.expandIcon,children:Q(e?B:O,{size:14})})}function K(){return Q(z,{size:14,"aria-hidden":"true"})}function U(){return Q(R,{size:14,"aria-hidden":"true"})}function Y(){return Q(A,{size:14,"aria-hidden":"true"})}function V({state:e,onClose:n}){const{x:t,y:r,items:d}=e,[o,a]=h(null);return Q("div",{className:F.contextMenu,style:{left:t,top:r},role:"menu",onMouseDown:e=>e.stopPropagation(),children:d.map((t,r)=>t.separator?Q("div",{className:F.contextMenuSeparator},`sep-${r}`):j("button",{type:"button",role:"menuitem",className:[F.contextMenuItem,t.danger?F.contextMenuItemDanger:"",o===r?F.contextMenuItemConfirming:""].filter(Boolean).join(" "),disabled:t.disabled,onClick:()=>((t,r)=>{t.confirm&&o!==r?a(r):(t.onClick(e.node),a(null),n())})(t,r),children:[t.icon&&Q("span",{className:F.contextMenuIcon,children:t.icon}),Q("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:t.confirm&&o===r?t.confirmLabel??"Confirm?":t.label})]},`${t.label}-${r}`))})}function X(e,n,t){const r=function(e){const n=e.metadata,t=n?.jsonPath;if(Array.isArray(t)&&t.length>0)return t}(e);if(!r||0===r.length)return[];const d=r.slice(0,-1);return[{op:"move",from:[...d,n],path:[...d,t]}]}function J({text:e,query:n}){if(!n)return Q(H,{children:e});const t=e.toLowerCase(),r=n.toLowerCase(),d=t.indexOf(r);return-1===d?Q(H,{children:e}):j(H,{children:[e.slice(0,d),Q("span",{className:F.highlight,children:e.slice(d,d+n.length)}),e.slice(d+n.length)]})}var Z={get:F.methodGet,post:F.methodPost,put:F.methodPut,patch:F.methodPatch,delete:F.methodDelete};function _({method:e}){const n=e.toLowerCase(),t=Z[n]??F.methodOther,r=E(e);return Q("span",{className:`${F.methodBadge} ${t}`,children:r})}var ee={draggedId:null,dragOverId:null,dragOverPosition:null};var ne=i(function(e){const{node:n,depth:t,expandedIds:r,selectedId:d,onToggle:o,onSelect:a,onNodeRef:i,searchQuery:s,showIndentGuides:c,renderIcon:u,renderLabel:p,renderSuffix:h,renderNode:g,draggable:f,dragState:m,canDragNode:x,canDragNodeFn:I,onDragStart:v,onDragOver:D,onDragLeave:N,onDrop:b,onDragEnd:S,showContextMenuButton:C,activeMenuNodeId:y,onContextMenu:M,onMoreClick:E}=e,B=r.includes(n.id),O=d===n.id,A=(n.children?.length??0)>0,R=A,T=!A,z=m.draggedId===n.id,$=m.dragOverId===n.id,q=$?m.dragOverPosition:null,H=n.metadata,K="string"==typeof H?.method?H.method:void 0,V=!0===H?.deprecated,X=!0===H?.required,Z="string"==typeof H?.kind?H.kind:void 0,ee={node:n,depth:t,isExpanded:B,isSelected:O,isBranch:R,isLeaf:T,isDragging:z,isDragOver:$,dragOverPosition:q},te=l(()=>{R?o(n.id):a(n)},[R,n,a,o]),re=l(e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),te()):("ArrowRight"===e.key&&R&&!B||"ArrowLeft"===e.key&&R&&B)&&(e.preventDefault(),o(n.id))},[te,R,B,n.id,o]),de=u?u(ee):K?null:Q("span",{className:F.nodeIcon,children:"section"===Z&&"components"===H?.section?Q(w,{size:14}):"section"===Z&&"webhooks"===H?.section?Q(G,{size:14}):"schema"===Z||"component"===Z||"object"===Z?Q(w,{size:14}):"array"===Z||"items"===Z?Q(k,{size:14}):R?Q(B?P:L,{size:14}):Q("span",{className:F.primitiveDot})}),oe=p?p(ee):Q("span",{className:`${F.nodeLabel} ${R?F.nodeLabelBranch:""} ${V?F.deprecatedLabel:""}`,children:Q(J,{text:n.name,query:s})}),ae=h?h(ee):null,ie=[F.nodeRow,R?F.branchControl:F.leafItem,O?F.nodeRowSelected:"",z?F.nodeDragging:"",$&&"before"===q?F.dropIndicatorBefore:"",$&&"after"===q?F.dropIndicatorAfter:"",$&&"child"===q?F.dropIndicatorChild:"",Z?`pde-tree-kind-${Z}`:""].filter(Boolean).join(" "),le=j("div",{ref:e=>i(n.id,e),className:ie,style:{paddingLeft:14*t+8+"px"},role:"treeitem","aria-expanded":R?B:void 0,"aria-selected":O,"aria-level":t,"aria-grabbed":f&&x?z:void 0,tabIndex:0,onClick:te,onKeyDown:re,onContextMenu:C?e=>M(n,e):void 0,onDragOver:f?e=>D(n,e):void 0,onDragLeave:f?()=>N(n):void 0,onDrop:f?e=>b(n,e):void 0,children:[c&&t>1&&Array.from({length:t-1},(e,n)=>Q("span",{className:F.indentGuide,style:{left:14*(n+1)+33+"px"}},`guide-${n}`)),f&&x&&Q("span",{className:F.dragHandle,draggable:!0,onDragStart:e=>v(n,e),onDragEnd:S,title:"Drag to reorder","aria-label":"Drag to reorder",children:Q(U,{})}),R?Q(W,{expanded:B}):Q("span",{className:F.expandIconPlaceholder}),de,K&&Q(_,{method:K}),oe,X&&Q("span",{className:F.requiredDot,title:"Required"}),Q("span",{className:F.nodeSuffix,children:ae}),C&&Q("button",{type:"button",className:[F.moreButton,y===n.id?F.moreButtonActive:""].filter(Boolean).join(" "),onClick:e=>E(n,e),title:"More actions","aria-label":"More actions",children:Q(Y,{})})]}),se=g?g(ee,le):le;return j("div",{role:"presentation",children:[se,R&&B&&n.children?.map(n=>Q(ne,{...e,node:n,depth:t+1,isExpanded:r.includes(n.id),isSelected:d===n.id,canDragNode:I(n)},n.id))]})},function(e,n){if(e.node!==n.node)return!1;if(e.depth!==n.depth)return!1;if(e.isExpanded!==n.isExpanded)return!1;if(e.isSelected!==n.isSelected)return!1;if(e.searchQuery!==n.searchQuery)return!1;if(e.showIndentGuides!==n.showIndentGuides)return!1;if(e.canDragNode!==n.canDragNode)return!1;if(e.draggable!==n.draggable)return!1;if(e.showContextMenuButton!==n.showContextMenuButton)return!1;if(e.activeMenuNodeId!==n.activeMenuNodeId)return!1;if((e.node.children?.length??0)>0){if(e.expandedIds!==n.expandedIds)return!1;if(e.selectedId!==n.selectedId)return!1;if(e.dragState!==n.dragState)return!1}if(e.dragState.draggedId===e.node.id!==(n.dragState.draggedId===n.node.id))return!1;const t=e.dragState.dragOverId===e.node.id,r=n.dragState.dragOverId===n.node.id;return t===r&&((!t||!r||e.dragState.dragOverPosition===n.dragState.dragOverPosition)&&(e.renderIcon===n.renderIcon&&(e.renderLabel===n.renderLabel&&(e.renderSuffix===n.renderSuffix&&(e.renderNode===n.renderNode&&(e.onToggle===n.onToggle&&(e.onSelect===n.onSelect&&(e.onNodeRef===n.onNodeRef&&(e.canDragNodeFn===n.canDragNodeFn&&(e.onDragStart===n.onDragStart&&(e.onDragOver===n.onDragOver&&(e.onDragLeave===n.onDragLeave&&(e.onDrop===n.onDrop&&(e.onDragEnd===n.onDragEnd&&(e.onContextMenu===n.onContextMenu&&e.onMoreClick===n.onMoreClick)))))))))))))))}),te=a(function(e,t){const{nodes:r,onSelect:a,onExpandedChange:i,defaultExpandedIds:g,defaultExpandDepth:f=1,searchable:m=!1,searchPlaceholder:x="Search...",showExpandAll:v=!1,showRefresh:D=!1,onRefresh:N,toolbar:b,searchRowExtra:C,renderNode:M,renderIcon:E,renderLabel:w,renderSuffix:B,className:O,style:A,size:L="sm",variant:P="default",showIndentGuides:R=!0,maxHeight:k,rootRef:z,draggable:G=!1,dragGroupKey:H,onReorder:W,onMove:U,canDrag:Y,canDrop:J,contextMenuItems:Z,onPatch:_}=e,[te,re]=h(null),[de,oe]=h(ee),[ae,ie]=h(null),le=p(null),se=I(r,{defaultExpandedIds:g,defaultExpandDepth:f,onExpandedChange:i}),ce=S(r),ue=ce.isSearching?se.allBranchIds:ce.expandedBeforeSearch??se.expandedIds,pe=l(e=>{re(e.id),a?.(e)},[a]),he=l(e=>{ce.handleQueryChange(e,se.expandedIds)},[se.expandedIds,ce]),ge=l(e=>{if(!G)return!1;const n=e.metadata;return"section"!==n?.kind&&(!Y||Y(e))},[Y,G]),fe=l((e,n)=>{ge(e)?(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",e.id),oe({draggedId:e.id,dragOverId:null,dragOverPosition:null})):n.preventDefault()},[ge]),me=l((e,t)=>{if(!de.draggedId||de.draggedId===e.id)return;t.preventDefault(),t.dataTransfer.dropEffect="move";const d=t.currentTarget.getBoundingClientRect(),o=(t.clientY-d.top)/d.height,a=(e.children?.length??0)>0;let i;i=a?o<.25?"before":o>.75?"after":"child":o<.5?"before":"after";const l=de.draggedId?n(r,de.draggedId):null;if("child"!==i||!l||!l.ancestorIds.includes(e.id)){if(H&&l){const t=n(r,e.id);if(t){const e=e=>{for(let n=e.nodes.length-1;n>=0;n--){const t=e.nodes[n]?.metadata;if(t&&H in t)return t[H]}},n=e(l),r=e(t);if(void 0!==n&&void 0!==r&&n!==r)return}}if(J){const n=l?.target;if(!n||!J(n,e,i))return}oe(n=>n.dragOverId===e.id&&n.dragOverPosition===i?n:{...n,dragOverId:e.id,dragOverPosition:i})}},[J,de.draggedId,r]),xe=l(e=>{oe(n=>n.dragOverId!==e.id?n:{...n,dragOverId:null,dragOverPosition:null})},[]),Ie=l((e,t)=>{t.preventDefault();const a=de.draggedId,i=de.dragOverPosition;if(!a||!i||a===e.id)return void oe(ee);if("child"===i){const t=n(r,a),o=t?.target;if(!o)return void oe(ee);const i=d(r,a,e.id);return i&&U?.(i,o,e.id),void oe(ee)}const l=n(r,e.id);if(!l)return void oe(ee);const s=l.parent?.children??r,c=s.findIndex(n=>n.id===e.id);if(-1===c)return void oe(ee);let u="before"===i?c:c+1;const p=n(r,a),h=l.parent?.id??null;if((p?.parent?.id??null)!==h){const e=p?.target,n=d(r,a,h,u);return n&&e&&U?.(n,e,h),void oe(ee)}if(p&&p.parent===l.parent){const e=s.findIndex(e=>e.id===a);-1!==e&&e<u&&(u-=1)}const g=o(r,a,u);if(g&&g.fromIndex!==g.toIndex&&(W?.(g),_)){const e=X(g.moved,g.fromIndex,g.toIndex);e.length>0&&_(e,{node:g.moved,type:"reorder"})}oe(ee)},[de,r,U,_,W]),ve=l(()=>{oe(ee)},[]),De=l((e,n,t)=>{if(!Z)return;const r=Z(e);if(0===r.length)return;const d=28*r.length+8,o=Math.min(n,window.innerWidth-200-8),a=Math.min(t,window.innerHeight-d-8);ie({x:Math.max(8,o),y:Math.max(8,a),node:e,items:r})},[Z]),Ne=l(()=>{ie(null)},[]),be=l((e,n)=>{n.preventDefault(),De(e,n.clientX,n.clientY)},[De]),Se=l((e,n)=>{n.stopPropagation();const t=n.currentTarget.getBoundingClientRect();De(e,t.left,t.bottom+4)},[De]);s(()=>{if(!ae)return;const e=e=>{const n=e.target;n.closest(`.${F.contextMenu}`)||n.closest(`.${F.moreButton}`)||Ne()},n=e=>{"Escape"===e.key&&Ne()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[ae,Ne]);const Ce=l(e=>{const n=y(r,e);se.setExpandedIds([...new Set([...se.expandedIds,...n])]),requestAnimationFrame(()=>{se.scrollToNode(e)})},[se,r]);c(t,()=>({expandAll:se.expandAll,collapseAll:se.collapseAll,expandToDepth:se.expandToDepth,getExpandedIds:()=>se.expandedIds,getSelectedNode:()=>{if(!te)return;const e=n(r,te);return e?.target},scrollToNode:Ce,locateNode:e=>{const t=[...r];for(;t.length>0;){const d=t.shift();if(d){if(e(d)){const e=n(r,d.id);return e&&se.setExpandedIds([...new Set([...se.expandedIds,...e.ancestorIds])]),re(d.id),requestAnimationFrame(()=>{se.scrollToNode(d.id)}),d}d.children?.length&&t.push(...d.children)}}}}),[se,Ce,te,r]);const ye=u(()=>({...A,...void 0!==k?{maxHeight:k}:{}}),[A,k]),Me=[F.root,"default"!==P?`pde-tree-variant-${P}`:"",O].filter(Boolean).join(" ");return j("div",{ref:z,className:Me,style:ye,"data-size":L,children:[b&&Q("div",{className:F.toolbar,children:b}),m&&j("div",{className:F.searchRow,children:[j("div",{className:F.searchInputWrap,children:[Q("span",{className:F.searchIcon,children:Q(K,{})}),Q("input",{className:F.searchInput,type:"search",placeholder:x,value:ce.query,onChange:e=>he(e.target.value),"aria-label":"Search tree"})]}),C,v&&Q("button",{type:"button",className:F.iconButton,onClick:se.isAllExpanded?se.collapseAll:se.expandAll,title:se.isAllExpanded?"Collapse all":"Expand all","aria-label":se.isAllExpanded?"Collapse all":"Expand all",children:se.isAllExpanded?Q(q,{size:16,"aria-hidden":"true"}):Q($,{size:16,"aria-hidden":"true"})}),D&&Q("button",{type:"button",className:F.iconButton,onClick:N,title:"Refresh","aria-label":"Refresh",children:Q(T,{size:14,"aria-hidden":"true"})})]}),Q("div",{ref:le,className:F.treeContainer,role:"tree","aria-label":"Tree navigation",children:0===ce.filteredNodes.length?Q("div",{className:F.emptyState,children:ce.isSearching?"No matching results":"No items"}):ce.filteredNodes.map(e=>Q(ne,{node:e,depth:0,expandedIds:ue,selectedId:te,isExpanded:ue.includes(e.id),isSelected:te===e.id,onToggle:se.toggleNode,onSelect:pe,onNodeRef:se.setNodeElementRef,searchQuery:ce.deferredQuery,showIndentGuides:R,renderIcon:E,renderLabel:w,renderSuffix:B,renderNode:M,draggable:G,dragState:de,canDragNode:ge(e),canDragNodeFn:ge,onDragStart:fe,onDragOver:me,onDragLeave:xe,onDrop:Ie,onDragEnd:ve,showContextMenuButton:Boolean(Z),activeMenuNodeId:ae?.node.id??null,onContextMenu:be,onMoreClick:Se},e.id))}),ae&&Q(V,{state:ae,onClose:Ne})]})});export{M as METHOD_LABEL_MAP,te as Tree,E as getMethodLabel,I as useTreeExpansion,S as useTreeSearch};
1
+ import{i as _e,j as Oe,k as Je,p as Ue,q as Ae}from"../chunk-AHHDXXHL.js";import{forwardRef as Nt,memo as Dt,useCallback as R,useEffect as $e,useImperativeHandle as Ct,useId as Rt,useMemo as Ie,useRef as ot,useState as ue}from"react";import{useLayoutEffect as yt,useRef as It,useState as He}from"react";import{createPortal as Tt}from"react-dom";import{jsx as Ce,jsxs as Ye}from"react/jsx-runtime";function Xe({state:r,onClose:t}){let u=It(null),[n,c]=He(null),[b,m]=He({left:r.x,top:r.y}),[P,w]=He({}),T=r.anchor.closest("dialog")??r.anchor.ownerDocument.body;return yt(()=>{let l=r.anchor.closest(".pde-tree-root")??r.anchor,v=getComputedStyle(l),y={};for(let M=0;M<v.length;M++){let O=v.item(M);(O.startsWith("--tree-")||O.startsWith("--color-")||O.startsWith("--radius-")||O.startsWith("--font-")||O.startsWith("--shadow-"))&&(y[O]=v.getPropertyValue(O))}w(y);let h=u.current;if(!h)return;let E=()=>{let M=h.getBoundingClientRect();m({left:Math.max(8,Math.min(r.x,document.documentElement.clientWidth-M.width-8)),top:Math.max(8,Math.min(r.y,document.documentElement.clientHeight-M.height-8))})};E();let Q=typeof ResizeObserver>"u"?void 0:new ResizeObserver(E);Q?.observe(h),h.querySelector("button:not(:disabled)")?.focus();let V=M=>{M.target instanceof Node&&!h.contains(M.target)&&t()},_=M=>{M.target instanceof Node&&!h.contains(M.target)&&t()};return document.addEventListener("pointerdown",V),document.addEventListener("scroll",_,!0),window.addEventListener("resize",t),()=>{Q?.disconnect(),document.removeEventListener("pointerdown",V),document.removeEventListener("scroll",_,!0),window.removeEventListener("resize",t),h.contains(document.activeElement)&&r.anchor.isConnected&&r.anchor.focus({preventScroll:!0})}},[r,t]),Tt(Ce("div",{ref:u,className:"pde-tree-contextMenu",style:{...P,...b},role:"menu","aria-label":`Actions for ${r.node.name}`,tabIndex:-1,onKeyDown:l=>{let v=u.current;if(!v)return;let y=Array.from(v.querySelectorAll("button:not(:disabled)")),h=y.indexOf(document.activeElement);if(l.key==="Escape"||l.key==="Tab"){l.key==="Escape"&&l.preventDefault(),l.stopPropagation(),t();return}let E;if(l.key==="ArrowDown")E=(h+1)%y.length;else if(l.key==="ArrowUp")E=(h-1+y.length)%y.length;else if(l.key==="Home")E=0;else if(l.key==="End")E=y.length-1;else return;l.preventDefault(),y[E]?.focus()},children:r.items.map((l,v)=>Ye("div",{role:"presentation",children:[l.separator&&Ce("div",{className:"pde-tree-contextMenuSeparator",role:"separator"}),Ye("button",{type:"button",role:"menuitem",tabIndex:-1,disabled:l.disabled,className:`pde-tree-contextMenuItem${l.danger?" pde-tree-contextMenuItemDanger":""}${n===v?" pde-tree-contextMenuItemConfirming":""}`,onClick:()=>{if(l.confirm&&n!==v){c(v);return}t(),l.onClick(r.node)},children:[l.icon&&Ce("span",{className:"pde-tree-contextMenuIcon","aria-hidden":"true",children:l.icon}),Ce("span",{children:l.confirm&&n===v?l.confirmLabel??"Confirm?":l.label})]})]},`${l.label}-${v}`))}),T)}import{useCallback as ie,useMemo as Re,useRef as Ze,useState as Mt}from"react";function Ge(r,t={}){let{defaultExpandedIds:u,defaultExpandDepth:n=1,onExpandedChange:c}=t,b=Re(()=>u!==void 0?[...u]:n<=1?[]:Oe(r,{maxDepth:n-1,onlyWithChildren:!0}),[]),[m,P]=Mt(b),w=Ze(new Map),T=Re(()=>Je(r),[r]),l=Re(()=>new Set(m),[m]),v=Ze(m);v.current=m;let y=Re(()=>T.length>0&&T.every(I=>l.has(I)),[T,l]),h=ie(I=>{v.current=I,P(I),c?.(I)},[c]),E=ie(I=>{let S=v.current,te=S.includes(I)?S.filter(he=>he!==I):[...S,I];h(te)},[h]),Q=ie(()=>{h([...T])},[T,h]),V=ie(()=>{h([])},[h]),_=ie(I=>{let S=Oe(r,{maxDepth:I,onlyWithChildren:!0});h(S)},[r,h]),M=ie((I,S)=>{S?w.current.set(I,S):w.current.delete(I)},[]),O=ie(I=>{let S=w.current.get(I);S&&S.scrollIntoView?.({behavior:"auto",block:"nearest"})},[]);return{expandedIds:m,setExpandedIds:h,toggleNode:E,expandAll:Q,collapseAll:V,expandToDepth:_,isAllExpanded:y,allBranchIds:T,setNodeElementRef:M,scrollToNode:O,nodeElementRefs:w}}import{useCallback as et,useDeferredValue as St,useMemo as kt,useState as tt}from"react";function qe(r){let[t,u]=tt(""),n=St(t),[c,b]=tt(null),m=n.trim().length>0,P=kt(()=>m?_e(r,{query:n,keepAncestors:!0}):r,[r,n,m]),w=et((l,v)=>{let y=t.trim(),h=l.trim();!y&&h&&b(v),y&&!h&&b(null),u(l)},[t]),T=et(()=>{u(""),b(null)},[]);return{query:t,deferredQuery:n,isSearching:m,filteredNodes:P,expandedBeforeSearch:c,handleQueryChange:w,clearSearch:T}}function rt(r){let t=new Map,u=new Set,n=r.map(c=>({node:c,parentId:null})).reverse();for(;n.length;){let c=n.pop();if(u.has(c.node)||t.has(c.node.id))continue;u.add(c.node),t.set(c.node.id,c);let b=c.node.children??[];for(let m=b.length-1;m>=0;m--)n.push({node:b[m],parentId:c.node.id})}return{byId:t,path(c){let b=t.get(c);if(!b)return null;let m=[b.node],P=b.parentId;for(;P!==null;){let w=t.get(P);if(!w)break;m.push(w.node),P=w.parentId}return m.reverse(),{nodes:m,target:b.node,parent:m[m.length-2],ancestorIds:m.slice(0,-1).map(w=>w.id)}}}}var je={get:"GET",post:"POST",put:"PUT",delete:"DEL",patch:"PATCH",head:"HEAD",options:"OPT",trace:"TRA",connect:"CONN"};function Ee(r){let t=r.toLowerCase().trim();return Object.prototype.hasOwnProperty.call(je,t)?je[t]:t.slice(0,4).toUpperCase()}import{LuBraces as nt,LuChevronDown as Et,LuChevronRight as Lt,LuEllipsisVertical as Pt,LuFolder as Bt,LuFolderOpen as zt,LuGripVertical as Ot,LuList as At,LuRefreshCw as Ht,LuSearch as Gt,LuZap as qt}from"react-icons/lu";import{MdOutlineUnfoldMore as jt,MdUnfoldLess as $t}from"react-icons/md";import{Fragment as Te,jsx as a,jsxs as fe}from"react/jsx-runtime";var s={branchControl:"pde-tree-branchControl",deprecatedLabel:"pde-tree-deprecatedLabel",dragHandle:"pde-tree-dragHandle",dropIndicatorAfter:"pde-tree-dropIndicatorAfter",dropIndicatorBefore:"pde-tree-dropIndicatorBefore",dropIndicatorChild:"pde-tree-dropIndicatorChild",emptyState:"pde-tree-emptyState",expandIcon:"pde-tree-expandIcon",expandIconPlaceholder:"pde-tree-expandIconPlaceholder",highlight:"pde-tree-highlight",iconButton:"pde-tree-iconButton",indentGuide:"pde-tree-indentGuide",leafItem:"pde-tree-leafItem",methodBadge:"pde-tree-methodBadge",methodDelete:"pde-tree-methodDelete",methodGet:"pde-tree-methodGet",methodOther:"pde-tree-methodOther",methodPatch:"pde-tree-methodPatch",methodPost:"pde-tree-methodPost",methodPut:"pde-tree-methodPut",moreButton:"pde-tree-moreButton",moreButtonActive:"pde-tree-moreButtonActive",nodeDragging:"pde-tree-nodeDragging",nodeIcon:"pde-tree-nodeIcon",primitiveDot:"pde-tree-primitiveDot",nodeLabel:"pde-tree-nodeLabel",nodeLabelBranch:"pde-tree-nodeLabelBranch",nodeRow:"pde-tree-nodeRow",nodeRowSelected:"pde-tree-nodeRowSelected",nodeSuffix:"pde-tree-nodeSuffix",requiredDot:"pde-tree-requiredDot",root:"pde-tree-root",searchIcon:"pde-tree-searchIcon",searchInput:"pde-tree-searchInput",searchInputWrap:"pde-tree-searchInputWrap",searchRow:"pde-tree-searchRow",toolbar:"pde-tree-toolbar",treeContainer:"pde-tree-treeContainer"};function Ft({expanded:r}){return a("span",{className:s.expandIcon,children:r?a(Et,{size:14}):a(Lt,{size:14})})}function Qt(){return a(Gt,{size:14,"aria-hidden":"true"})}function Wt(){return a(Ot,{size:14,"aria-hidden":"true"})}function Kt(){return a(Pt,{size:14,"aria-hidden":"true"})}function at(r){let u=r.metadata?.jsonPath;if(Array.isArray(u)&&u.length>0&&u.every(n=>typeof n=="string"||typeof n=="number"&&Number.isInteger(n)&&n>=0))return u}function Vt(r,t,u,n){let c=at(r);if(!c||c.length===0)return[];let b=JSON.stringify(c.slice(0,-1));if(!n.every((P,w)=>{let T=at(P);return T&&T[T.length-1]===w&&JSON.stringify(T.slice(0,-1))===b}))return[];let m=c.slice(0,-1);return[{op:"move",from:[...m,t],path:[...m,u]}]}function _t({text:r,query:t}){if(!t)return a(Te,{children:r});let u=r.toLowerCase(),n=t.toLowerCase(),c=u.indexOf(n);return c===-1?a(Te,{children:r}):fe(Te,{children:[r.slice(0,c),a("span",{className:s.highlight,children:r.slice(c,c+t.length)}),r.slice(c+t.length)]})}var dt={get:s.methodGet,post:s.methodPost,put:s.methodPut,patch:s.methodPatch,delete:s.methodDelete};function Jt({method:r}){let t=r.toLowerCase(),u=Object.prototype.hasOwnProperty.call(dt,t)?dt[t]:s.methodOther,n=Ee(r);return a("span",{className:`${s.methodBadge} ${u}`,children:n})}var F={draggedId:null,dragOverId:null,dragOverPosition:null};function Ut(r,t){if(r.isFocused!==t.isFocused||r.positionInSet!==t.positionInSet||r.setSize!==t.setSize||r.node!==t.node||r.depth!==t.depth||r.isExpanded!==t.isExpanded||r.isSelected!==t.isSelected||r.searchQuery!==t.searchQuery||r.showIndentGuides!==t.showIndentGuides||r.canDragNode!==t.canDragNode||r.draggable!==t.draggable||r.showContextMenuButton!==t.showContextMenuButton||r.activeMenuNodeId===r.node.id!=(t.activeMenuNodeId===t.node.id))return!1;let u=r.dragState.draggedId===r.node.id,n=t.dragState.draggedId===t.node.id;if(u!==n)return!1;let c=r.dragState.dragOverId===r.node.id,b=t.dragState.dragOverId===t.node.id;return!(c!==b||c&&b&&r.dragState.dragOverPosition!==t.dragState.dragOverPosition||r.renderIcon!==t.renderIcon||r.renderLabel!==t.renderLabel||r.renderSuffix!==t.renderSuffix||r.renderNode!==t.renderNode||r.onToggle!==t.onToggle||r.onSelect!==t.onSelect||r.onNodeRef!==t.onNodeRef||r.onDragStart!==t.onDragStart||r.onDragOver!==t.onDragOver||r.onDragLeave!==t.onDragLeave||r.onDrop!==t.onDrop||r.onDragEnd!==t.onDragEnd||r.onContextMenu!==t.onContextMenu||r.onMoreClick!==t.onMoreClick)}function Yt(r){let{node:t,depth:u,onToggle:n,onSelect:c,onNodeRef:b,searchQuery:m,showIndentGuides:P,renderIcon:w,renderLabel:T,renderSuffix:l,renderNode:v,draggable:y,dragState:h,canDragNode:E,onDragStart:Q,onDragOver:V,onDragLeave:_,onDrop:M,onDragEnd:O,showContextMenuButton:I,activeMenuNodeId:S,onContextMenu:te,onMoreClick:he}=r,{isExpanded:q,isSelected:ge}=r,se=(t.children?.length??0)>0,L=se,Me=!se,re=h.draggedId===t.id,W=h.dragOverId===t.id,J=W?h.dragOverPosition:null,A=t.metadata,K=typeof A?.method=="string"?A.method:void 0,Le=A?.deprecated===!0,Se=A?.required===!0,z=typeof A?.kind=="string"?A.kind:void 0,oe={node:t,depth:u,isExpanded:q,isSelected:ge,isBranch:L,isLeaf:Me,isDragging:re,isDragOver:W,dragOverPosition:J},H=R(()=>{L?n(t.id):c(t)},[L,t,c,n]),B=R(g=>{g.target===g.currentTarget&&(g.key==="Enter"||g.key===" "?(g.preventDefault(),H()):(g.key==="ArrowRight"&&L&&!q||g.key==="ArrowLeft"&&L&&q)&&(g.preventDefault(),g.stopPropagation(),n(t.id)))},[H,L,q,t.id,n]),ce=w?w(oe):K?null:a("span",{className:s.nodeIcon,children:z==="section"&&A?.section==="components"?a(nt,{size:14}):z==="section"&&A?.section==="webhooks"?a(qt,{size:14}):z==="schema"||z==="component"||z==="object"?a(nt,{size:14}):z==="array"||z==="items"?a(At,{size:14}):L?q?a(zt,{size:14}):a(Bt,{size:14}):a("span",{className:s.primitiveDot})}),ke=T?T(oe):a("span",{className:`${s.nodeLabel} ${L?s.nodeLabelBranch:""} ${Le?s.deprecatedLabel:""}`,children:a(_t,{text:t.name,query:m})}),ne=l?l(oe):null,Ne=[s.nodeRow,L?s.branchControl:s.leafItem,ge?s.nodeRowSelected:"",re?s.nodeDragging:"",W&&J==="before"?s.dropIndicatorBefore:"",W&&J==="after"?s.dropIndicatorAfter:"",W&&J==="child"?s.dropIndicatorChild:"",z?`pde-tree-kind-${z}`:""].filter(Boolean).join(" "),D=R(g=>b(t.id,g),[t.id,b]),me=fe("div",{ref:D,className:Ne,style:{paddingLeft:`${Math.min(u,20)*12+4}px`},"data-node-id":t.id,role:"treeitem","aria-expanded":L?q:void 0,"aria-label":K?`${Ee(K)} ${t.name}`:t.name,"aria-selected":ge,"aria-level":u+1,"aria-posinset":r.positionInSet,"aria-setsize":r.setSize,"aria-grabbed":y&&E?re:void 0,tabIndex:r.isFocused?0:-1,onFocus:()=>r.onFocusNode(t.id),onClick:H,onKeyDown:B,onContextMenu:I?g=>te(t,g):void 0,onDragOver:y?g=>V(t,g):void 0,onDragLeave:y?()=>_(t):void 0,onDrop:y?g=>M(t,g):void 0,children:[P&&u>1&&Array.from({length:Math.min(u-1,20)},(g,U)=>a("span",{className:s.indentGuide,style:{left:`${(U+1)*12+29}px`}},`guide-${U}`)),y&&E&&a("span",{className:s.dragHandle,draggable:!0,onDragStart:g=>Q(t,g),onDragEnd:O,title:"Drag to reorder","aria-label":"Drag to reorder",children:a(Wt,{})}),L?a(Ft,{expanded:q}):a("span",{className:s.expandIconPlaceholder}),ce,K&&a(Jt,{method:K}),ke,Se&&a("span",{className:s.requiredDot,title:"Required"}),a("span",{className:s.nodeSuffix,children:ne}),I&&a("button",{type:"button",className:[s.moreButton,S===t.id?s.moreButtonActive:""].filter(Boolean).join(" "),onClick:g=>he(t,g),title:"More actions","aria-label":`More actions for ${t.name}`,"aria-haspopup":"menu","aria-expanded":S===t.id,tabIndex:-1,children:a(Kt,{})})]}),le=v?v(oe,me):me;return a(Te,{children:le})}var Xt=Dt(Yt,Ut),Zt=Nt(function(t,u){let{nodes:n,onSelect:c,onExpandedChange:b,defaultExpandedIds:m,defaultExpandDepth:P=1,searchable:w=!1,searchPlaceholder:T="Search...",showExpandAll:l=!1,showRefresh:v=!1,onRefresh:y,toolbar:h,searchRowExtra:E,renderNode:Q,renderIcon:V,renderLabel:_,renderSuffix:M,className:O,style:I,size:S="sm",variant:te="default",showIndentGuides:he=!0,maxHeight:q,rootRef:ge,draggable:se=!1,dragGroupKey:L,onReorder:Me,onMove:re,canDrag:W,canDrop:J,contextMenuItems:A,onPatch:K,theme:Le,virtualized:Se="auto"}=t,[z,oe]=ue(null),[H,B]=ue(F),[ce,ke]=ue(null),ne=ot(null),Ne=Rt(),D=Ie(()=>rt(n),[n]),[me,le]=ue({top:0,height:400}),[g,U]=ue(null),[Pe,Fe]=ue(null),x=Ge(n,{defaultExpandedIds:m,defaultExpandDepth:P,onExpandedChange:b}),C=qe(n),Qe=C.isSearching?x.allBranchIds:C.expandedBeforeSearch??x.expandedIds,xe=Ie(()=>new Set(Qe),[Qe]),k=Ie(()=>{let e=[],o=new Set,d=C.filteredNodes.map((i,f,p)=>({node:i,depth:0,parentId:null,positionInSet:f+1,setSize:p.length})).reverse();for(;d.length;){let i=d.pop();if(!o.has(i.node.id)&&(o.add(i.node.id),e.push(i),xe.has(i.node.id))){let f=i.node.children??[];for(let p=f.length-1;p>=0;p--)d.push({node:f[p],depth:i.depth+1,parentId:i.node.id,positionInSet:p+1,setSize:f.length})}}return e},[C.filteredNodes,xe]),be=Ie(()=>new Map(k.map((e,o)=>[e.node.id,o])),[k]),ae=S==="xs"?24:S==="md"?32:28,Y=Se!==!1&&te!=="doc"&&!Q&&(Se===!0||k.length>500),pe=Y?Math.max(0,Math.min(Math.floor(me.top/ae)-8,k.length-1)):0,ve=Y?Math.min(k.length,pe+Math.ceil(me.height/ae)+16):k.length,We=k.slice(pe,ve);$e(()=>{let e=ne.current;if(!e)return;let o=()=>le({top:e.scrollTop,height:e.clientHeight||400});o();let d=typeof ResizeObserver>"u"?void 0:new ResizeObserver(o);return d?.observe(e),()=>d?.disconnect()},[]),$e(()=>{if(!g)return;let e=be.get(g.id);if(e===void 0){U(null);return}let o=ne.current;if(Y&&o&&(e<pe||e>=ve)){let i=o.clientHeight||400,f=Math.min(e*ae,Math.max(0,k.length*ae-i));o.scrollTop=f,le(p=>({...p,top:o.scrollTop}));return}let d=x.nodeElementRefs.current.get(g.id);g.focus&&d?.focus({preventScroll:!0}),d?.scrollIntoView?.({block:"nearest"}),U(null)},[g,be,Y,ae,pe,ve,k.length,x.nodeElementRefs]);let Be=Pe===null?void 0:be.get(Pe),it=Be!==void 0&&Be>=pe&&Be<ve?Pe:We[0]?.node.id,ze=ot({query:"",time:0}),st=e=>{if(!(e.target instanceof HTMLElement)||e.target.getAttribute("role")!=="treeitem")return;let o=be.get(e.target.dataset.nodeId??"");if(o===void 0)return;let d=k[o],i=o;if(e.key==="ArrowDown")i=Math.min(o+1,k.length-1);else if(e.key==="ArrowUp")i=Math.max(0,o-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=k.length-1;else if(e.key==="ArrowRight"&&d.node.children?.length&&xe.has(d.node.id))i=Math.min(o+1,k.length-1);else if(e.key==="ArrowLeft"&&(!d.node.children?.length||!xe.has(d.node.id)))i=be.get(d.parentId??"")??o;else if(e.key==="ContextMenu"||e.shiftKey&&e.key==="F10"){let p=e.target.getBoundingClientRect();e.preventDefault(),ye(d.node,p.left+24,p.bottom);return}else if(e.key.length===1&&e.key!==" "&&!e.ctrlKey&&!e.metaKey&&!e.altKey){let p=Date.now(),G=p-ze.current.time<600?ze.current.query+e.key.toLowerCase():e.key.toLowerCase();ze.current={query:G,time:p};for(let N=1;N<=k.length;N++){let $=(o+N)%k.length;if(k[$].node.name.toLowerCase().startsWith(G)){i=$;break}}}else return;e.preventDefault();let f=k[i].node.id;Fe(f),U({id:f,focus:!0})};$e(()=>{ne.current&&(ne.current.scrollTop=0),le(e=>({...e,top:0}))},[C.deferredQuery]);let ct=R(e=>{oe(e.id),c?.(e)},[c]),lt=R(e=>{!e.trim()&&C.expandedBeforeSearch&&x.setExpandedIds(C.expandedBeforeSearch),C.handleQueryChange(e,x.expandedIds)},[x.expandedIds,C]),we=R(e=>!se||e.metadata?.kind==="section"?!1:W?W(e):!0,[W,se]),De=R((e,o,d)=>{if(e.id===o.id||!we(e)||D.path(o.id)?.ancestorIds.includes(e.id))return!1;if(L){let f=N=>{let $=D.path(N)?.nodes??[];for(let X=$.length-1;X>=0;X--){let Z=$[X]?.metadata;if(Z&&typeof Z=="object"&&Object.prototype.hasOwnProperty.call(Z,L))return Z[L]}},p=f(e.id),G=f(o.id);if(p!==void 0&&G!==void 0&&p!==G)return!1}return!J||J(e,o,d)},[we,J,L,D]),pt=R((e,o)=>{if(!we(e)){o.preventDefault();return}o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",e.id),B({draggedId:e.id,dragOverId:null,dragOverPosition:null})},[we]),ut=R((e,o)=>{if(!H.draggedId||H.draggedId===e.id)return;o.dataTransfer.dropEffect="none";let d=o.currentTarget.getBoundingClientRect(),i=(o.clientY-d.top)/d.height,f=(e.children?.length??0)>0,p;f?i<.25?p="before":i>.75?p="after":p="child":p=i<.5?"before":"after";let G=D.byId.get(H.draggedId)?.node;if(!G||!De(G,e,p)){B(N=>N.dragOverId===null?N:{...N,dragOverId:null,dragOverPosition:null});return}o.preventDefault(),o.dataTransfer.dropEffect="move",B(N=>N.dragOverId===e.id&&N.dragOverPosition===p?N:{...N,dragOverId:e.id,dragOverPosition:p})},[De,H.draggedId,D]),ft=R(e=>{B(o=>o.dragOverId!==e.id?o:{...o,dragOverId:null,dragOverPosition:null})},[]),ht=R((e,o)=>{o.preventDefault();let d=H.draggedId,i=H.dragOverPosition;if(!d||!i||d===e.id||H.dragOverId!==e.id){B(F);return}let f=D.byId.get(d)?.node;if(!f||!De(f,e,i)){B(F);return}if(i==="child"){let de=D.path(d)?.target;if(!de){B(F);return}let Ve=Ae(n,d,e.id);Ve&&re?.(Ve,de,e.id),B(F);return}let p=D.path(e.id);if(!p){B(F);return}let G=p.parent?.children??n,N=G.findIndex(j=>j.id===e.id);if(N===-1){B(F);return}let $=i==="before"?N:N+1,X=D.path(d),Z=p.parent?.id??null;if((X?.parent?.id??null)!==Z){let j=X?.target,de=Ae(n,d,Z,$);de&&j&&re?.(de,j,Z),B(F);return}if(X&&X.parent===p.parent){let j=G.findIndex(de=>de.id===d);j!==-1&&j<$&&($-=1)}let ee=Ue(n,d,$);if(ee&&ee.fromIndex!==ee.toIndex&&(Me?.(ee),K)){let j=Vt(ee.moved,ee.fromIndex,ee.toIndex,G);j.length>0&&K(j,{node:ee.moved,type:"reorder"})}B(F)},[H,n,D,De,re,K,Me]),gt=R(()=>{B(F)},[]),ye=R((e,o,d)=>{if(!A)return;let i=A(e);if(i.length===0)return;let f=x.nodeElementRefs.current.get(e.id);f&&ke({x:o,y:d,node:e,items:i,anchor:f})},[A,x.nodeElementRefs]),mt=R(()=>{ke(null)},[]),xt=R((e,o)=>{o.preventDefault(),ye(e,o.clientX,o.clientY)},[ye]),bt=R((e,o)=>{o.stopPropagation();let d=o.currentTarget.getBoundingClientRect();ye(e,d.left,d.bottom+4)},[ye]),Ke=R(e=>{let o=D.path(e);if(!o)return;let d=o.ancestorIds;x.setExpandedIds([...new Set([...x.expandedIds,...d])]),C.clearSearch(),U({id:e,focus:!1})},[x,D,C.clearSearch]);Ct(u,()=>({expandAll:x.expandAll,collapseAll:x.collapseAll,expandToDepth:x.expandToDepth,getExpandedIds:()=>x.expandedIds,getSelectedNode:()=>z?D.path(z)?.target:void 0,scrollToNode:Ke,locateNode:e=>{let o=[...n],d=new Set;for(let i=0;i<o.length;i++){let f=o[i];if(!(!f||d.has(f))){if(d.add(f),e(f)){let p=D.path(f.id);return p&&x.setExpandedIds([...new Set([...x.expandedIds,...p.ancestorIds])]),C.clearSearch(),oe(f.id),U({id:f.id,focus:!1}),f}if(f.children?.length)for(let p of f.children)o.push(p)}}}}),[x,Ke,z,n,D,C.clearSearch]);let vt=Ie(()=>({...I,...q!==void 0?{maxHeight:q}:{}}),[I,q]),wt=[s.root,te!=="default"?`pde-tree-variant-${te}`:"",O].filter(Boolean).join(" ");return fe("div",{ref:ge,className:wt,style:vt,"data-size":S,"data-theme":Le,children:[h&&a("div",{className:s.toolbar,children:h}),(w||l||v||E)&&fe("div",{className:s.searchRow,children:[w&&fe("div",{className:s.searchInputWrap,children:[a("span",{className:s.searchIcon,children:a(Qt,{})}),a("input",{className:s.searchInput,type:"search","aria-controls":Ne,placeholder:T,value:C.query,onChange:e=>lt(e.target.value),"aria-label":"Search tree"})]}),E,l&&a("button",{type:"button",className:s.iconButton,onClick:x.isAllExpanded?x.collapseAll:x.expandAll,title:x.isAllExpanded?"Collapse all":"Expand all","aria-label":x.isAllExpanded?"Collapse all":"Expand all",children:x.isAllExpanded?a($t,{size:16,"aria-hidden":"true"}):a(jt,{size:16,"aria-hidden":"true"})}),v&&a("button",{type:"button",className:s.iconButton,onClick:y,title:"Refresh","aria-label":"Refresh",children:a(Ht,{size:14,"aria-hidden":"true"})})]}),a("div",{ref:ne,className:s.treeContainer,"data-virtualized":Y||void 0,onScroll:e=>{Y&&le({top:e.currentTarget.scrollTop,height:e.currentTarget.clientHeight||400})},id:Ne,role:"tree",onKeyDown:st,"aria-label":"Tree navigation",children:C.filteredNodes.length===0?a("div",{className:s.emptyState,children:C.isSearching?"No matching results":"No items"}):fe(Te,{children:[Y&&a("div",{role:"presentation",style:{height:pe*ae}}),We.map(({node:e,depth:o,positionInSet:d,setSize:i})=>a(Xt,{node:e,depth:o,positionInSet:d,setSize:i,isFocused:e.id===it,onFocusNode:Fe,isExpanded:xe.has(e.id),isSelected:z===e.id,onToggle:x.toggleNode,onSelect:ct,onNodeRef:x.setNodeElementRef,searchQuery:C.deferredQuery,showIndentGuides:he,renderIcon:V,renderLabel:_,renderSuffix:M,renderNode:Q,draggable:se,dragState:H,canDragNode:we(e),onDragStart:pt,onDragOver:ut,onDragLeave:ft,onDrop:ht,onDragEnd:gt,showContextMenuButton:!!A,activeMenuNodeId:ce?.node.id??null,onContextMenu:xt,onMoreClick:bt},e.id)),Y&&a("div",{role:"presentation",style:{height:(k.length-ve)*ae}})]})}),ce&&a(Xe,{state:ce,onClose:mt},ce.node.id)]})});export{je as METHOD_LABEL_MAP,Zt as Tree,Ee as getMethodLabel,Ge as useTreeExpansion,qe as useTreeSearch};
@@ -42,7 +42,7 @@ interface FilterTreeOptions {
42
42
  * Options for building expansion paths.
43
43
  */
44
44
  interface ExpandOptions {
45
- /** Maximum depth to expand. 0 means only the root. Defaults to Infinity. */
45
+ /** Maximum depth to expand. Root nodes have depth 1; 0 expands nothing. Defaults to Infinity. */
46
46
  maxDepth?: number;
47
47
  /** When true, only expand nodes that have children. Defaults to true. */
48
48
  onlyWithChildren?: boolean;
@@ -42,7 +42,7 @@ interface FilterTreeOptions {
42
42
  * Options for building expansion paths.
43
43
  */
44
44
  interface ExpandOptions {
45
- /** Maximum depth to expand. 0 means only the root. Defaults to Infinity. */
45
+ /** Maximum depth to expand. Root nodes have depth 1; 0 expands nothing. Defaults to Infinity. */
46
46
  maxDepth?: number;
47
47
  /** When true, only expand nodes that have children. Defaults to true. */
48
48
  onlyWithChildren?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerduck/tree",
3
- "version": "0.7.4",
3
+ "version": "0.7.7",
4
4
  "description": "Extensible tree component for API navigation, schema exploration, and documentation. Supports OpenAPI 3.2 nested tags, x-tagGroups, and custom data sources.",
5
5
  "license": "MIT",
6
6
  "author": "powerduck",
@@ -40,15 +40,21 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "build": "tsup",
43
+ "postbuild": "ln -sf /Users/electron/powerduck-react/node_modules/react node_modules/react && ln -sf /Users/electron/powerduck-react/node_modules/react-dom node_modules/react-dom",
43
44
  "test": "vitest run",
44
45
  "test:watch": "vitest",
45
46
  "typecheck": "tsc --noEmit",
46
- "prepublishOnly": "npm run build && npm run test"
47
+ "prepublishOnly": "npm run check",
48
+ "check:english": "node scripts/check-english.mjs",
49
+ "check": "npm run check:english && npm run typecheck && npm run typecheck:examples && npm test && npm run build",
50
+ "preview": "vite --config examples/vite.config.ts",
51
+ "benchmark": "npm run build && node scripts/benchmark.mjs",
52
+ "typecheck:examples": "tsc --noEmit -p tsconfig.examples.json"
47
53
  },
48
54
  "peerDependencies": {
49
- "@chakra-ui/react": ">=2.4.0",
50
- "react": ">=17.0.0",
51
- "react-dom": ">=17.0.0"
55
+ "@chakra-ui/react": ">=3.0.0",
56
+ "react": "^19.3.0",
57
+ "react-dom": "^19.3.0"
52
58
  },
53
59
  "peerDependenciesMeta": {
54
60
  "@chakra-ui/react": {
@@ -62,18 +68,24 @@
62
68
  }
63
69
  },
64
70
  "dependencies": {
65
- "@powerduck/openapi-parser": "^0.3.3",
71
+ "@powerduck/openapi-parser": "^0.3.5",
66
72
  "react-icons": "^5.7.0"
67
73
  },
68
74
  "devDependencies": {
69
- "@types/react": "^18.2.0",
70
- "@types/react-dom": "^18.2.0",
71
- "react": "^18.2.0",
72
- "react-dom": "^18.2.0",
75
+ "@testing-library/dom": "^10.4.2",
76
+ "@testing-library/jest-dom": "^6.9.1",
77
+ "@testing-library/react": "^16.3.3",
78
+ "@types/node": "^22.20.3",
79
+ "@types/react": "^19.3.0",
80
+ "@types/react-dom": "^19.3.0",
81
+ "jsdom": "^24.1.3",
82
+ "react": "^19.3.0",
83
+ "react-dom": "^19.3.0",
73
84
  "terser": "^5.51.2",
74
85
  "tsup": "^8.0.0",
75
86
  "typescript": "^5.3.0",
76
- "vitest": "^1.2.0"
87
+ "vite": "^6.4.3",
88
+ "vitest": "^3.2.7"
77
89
  },
78
90
  "keywords": [
79
91
  "tree",
@@ -1 +0,0 @@
1
- function n(n){return null!=n}function e(n,r){for(const t of n){if(t.id===r)return t;if(t.children?.length){const n=e(t.children,r);if(n)return n}}}function r(n,e,t=[]){for(const i of n){const n=[...t,i];if(i.id===e)return{nodes:n,target:i,parent:t[t.length-1],ancestorIds:t.map(n=>n.id)};if(i.children?.length){const t=r(i.children,e,n);if(t)return t}}return null}function t(n){const e=[],r=n=>{if(n.children?.length)for(const e of n.children)r(e);else e.push(n)};for(const e of n)r(e);return e}function i(n){let e=0;const r=n=>{e+=1;for(const e of n.children??[])r(e)};for(const e of n)r(e);return e}function o(n){let e=0;const r=(n,t)=>{e=Math.max(e,t);for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function c(n){return[...n].sort((n,e)=>{const r=n.order??Number.MAX_SAFE_INTEGER,t=e.order??Number.MAX_SAFE_INTEGER;if(r!==t)return r-t;return n.name.localeCompare(e.name,"en-US",{numeric:!0,sensitivity:"base"})||n.id.localeCompare(e.id)})}function l(n){return c(n).map(n=>n.children?.length?{...n,children:l(n.children)}:n)}function d(e,r){const t=r.query.trim().toLowerCase();if(!t)return e;const i=r.keepAncestors??!0,o=e=>{const r=(e.children??[]).map(o).filter(n),c=(n=>n.name.toLowerCase().includes(t)||n.id.toLowerCase().includes(t))(e);return(c||r.length)&&(i||c)?r.length===(e.children?.length??0)?e:{...e,children:r}:null};return e.map(o).filter(n)}function f(n,e={}){const r=e.maxDepth??1/0,t=e.onlyWithChildren??!0,i=[],o=(n,e)=>{if(e>r)return;const c=(n.children?.length??0)>0;t&&!c||i.push(n.id);for(const r of n.children??[])o(r,e+1)};for(const e of n)o(e,1);return i}function u(n){const e=[],r=n=>{const t=n.children;if(t&&0!==t.length){e.push(n.id);for(const n of t)r(n)}};for(const e of n)r(e);return e}function h(n){const e=[],r=(n,t)=>{e.push({node:n,depth:t});for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function s(n,e,r){let t=!1;const i=n.map(n=>{if(n.id===e)return t=!0,r(n);if(n.children?.length){const i=s(n.children,e,r);if(i!==n.children)return t=!0,{...n,children:i}}return n});return t?i:n}function a(n,e){const r=[];let t=!1;for(const i of n)if(i.id!==e){if(i.children?.length){const n=a(i.children,e);if(n!==i.children){t=!0,r.push({...i,children:n});continue}}r.push(i)}else t=!0;return t?r:n}function p(n,e,r){let t=!1;const i=n.map(n=>{if(n.id===e)return t=!0,{...n,children:[...n.children??[],r]};if(n.children?.length){const i=p(n.children,e,r);if(i!==n.children)return t=!0,{...n,children:i}}return n});return t?i:n}function m(n,e,r){const t=(n,r)=>{const i=n.findIndex(n=>n.id===e);if(-1!==i)return{array:n,index:i,parentId:r};for(const e of n)if(e.children?.length){const n=t(e.children,e.id);if(n)return n}return null},i=t(n,null);if(!i)return null;const{array:o,index:c,parentId:l}=i,d=Math.max(0,Math.min(r,o.length-1));if(d===c)return{nodes:n,moved:o[c],parentId:l,fromIndex:c,toIndex:c};const f=[...o],[u]=f.splice(c,1);f.splice(d,0,u);const h=n=>null===l?f:n.map(n=>n.id===l?{...n,children:f}:n.children?.length?{...n,children:h(n.children)}:n);return{nodes:h(n),moved:u,parentId:l,fromIndex:c,toIndex:d}}function g(n,e,t,i){let o=null;if(null!==t){const i=r(n,e);if(i&&i.ancestorIds.includes(t))return null}const c=n=>{const r=[];let t=!1;for(const i of n)if(i.id!==e){if(i.children?.length){const n=c(i.children);if(n!==i.children){t=!0,r.push({...i,children:n});continue}}r.push(i)}else o=i,t=!0;return t?r:n},l=c(n);if(!o)return null;if(null===t){const n=i??l.length,e=[...l];return e.splice(Math.max(0,Math.min(n,e.length)),0,o),e}let d=!1;const f=n=>n.map(n=>{if(n.id===t){d=!0;const e=[...n.children??[]],r=i??e.length;return e.splice(Math.max(0,Math.min(r,e.length)),0,o),{...n,children:e}}return n.children?.length?{...n,children:f(n.children)}:n}),u=f(l);return d?u:null}export{n as isTreeNode,e as findNode,r as findPath,t as getLeaves,i as countNodes,o as getMaxDepth,c as sortNodes,l as sortTree,d as filterTree,f as getExpandableIds,u as getBranchIds,h as flattenTree,s as updateNode,a as removeNode,p as insertChild,m as reorderNode,g as moveNode};
@@ -1 +0,0 @@
1
- import{sortNodes as e}from"./chunk-5KF7QUTD.js";var t=["get","put","post","delete","options","head","patch","trace"],n={showInternal:!1,showComponents:!0,showWebhooks:!0,defaultExpandDepth:2};function o(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function r(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function a(e){return"boolean"==typeof e?e:void 0}function s(e){return Array.isArray(e)?e:void 0}function i(e,t){return!t&&(!0===a(e["x-scalar-ignore"])||!0===a(e["x-internal"]))}function c(e){return"number"==typeof(t=e["x-order"])&&Number.isFinite(t)?t:void 0;var t}function d(e){return r(e["x-displayName"])}function p(t,n,o,r){const a=new Map;for(const e of t)a.set(e.name,e);const s=new Map;for(const e of t){if(!e.parent){s.set(e.name,null);continue}if(!a.has(e.parent)){r.push(`Tag "${e.name}" references unknown parent "${e.parent}", treating as root.`),s.set(e.name,null);continue}const t=[e.name];let n=e.parent,o=!1;for(;n;){if(t.includes(n)){o=!0,r.push(`Circular tag reference detected: ${t.join(" -> ")} -> ${n}. Breaking cycle.`);break}t.push(n),n=a.get(n)?.parent}s.set(e.name,o?null:e.parent)}const d=new Map;for(const e of n){if(i(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=d.get(n)??[];t.push(e),d.set(n,t)}}const p=new Map;for(const e of t){const t=s.get(e.name)??null??"__root__",n=p.get(t)??[];n.push(e),p.set(t,n)}const u=t=>{const n=p.get(t)??[];return e(n.map(t=>{const n=(t=>{const n=(d.get(t.name)??[]).map(e=>({id:`op:${t.name}:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"oas32-parent",kind:"operation"}}));return{id:`tag:${t.name}`,name:t.displayName,order:t.order,children:e(n),metadata:{source:"oas32-parent",kind:"tag"}}})(t),o=u(t.name);return o.length>0&&(n.children=e([...n.children??[],...o])),n}))},m=u("__root__"),f=d.get("Other")??[];if(f.length>0){const t=f.map(e=>({id:`op:Other:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"fallback",kind:"operation"}}));m.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(m)}function u(u,m={}){const f={...n,...m},h=[],l=o(u);if(!l)return{root:{id:"root",name:"OpenAPI",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const g=function(e){const n=o(e.paths);if(!n)return[];const i=[];for(const[e,c]of Object.entries(n)){const n=o(c);if(n)for(const c of t){const t=n[c];if(null==t)continue;const d=o(t);if(!d)continue;const p=r(d.operationId),u=r(d.summary),m=s(d.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],f=u??p??`${c.toUpperCase()} ${e}`,h=p??`${c}:${e}`,l=`/paths/${encodeURIComponent(e)}/${c}`;i.push({id:h,path:e,method:c,name:f,summary:u,operationId:p,deprecated:!0===a(d.deprecated),tags:m,pointer:l,raw:d})}}return i}(l),y=function(e){const t=s(e.tags);if(!t)return[];const n=[];for(const e of t){const t=o(e),a=r(t?.name);a&&t&&n.push({name:a,displayName:d(t)??a,description:r(t.description),parent:r(t.parent),order:c(t),raw:t})}return n}(l);let $;if(function(e){return e.some(e=>void 0!==e.parent)}(y))$=p(y,g,f,h);else{const t=function(e){const t=s(e["x-tagGroups"]);if(!t)return[];const n=(e,t)=>{const a=o(e),i=r(a?.name),d=s(a?.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[];if(!i)return null;const p=s(a?.groups)?.map((e,t)=>n(e,t)).filter(e=>null!==e)??[];return{name:i,tags:d,groups:p.length>0?p:void 0,order:c(a??{})??t}};return t.map((e,t)=>n(e,t)).filter(e=>null!==e)}(l);$=t.length>0?function(t,n,o,r){const a=new Map;for(const e of n)a.set(e.name,e.displayName);const s=new Map;for(const e of o)if(!i(e.raw,r.showInternal))for(const t of e.tags){const n=s.get(t)??[];n.push(e),s.set(t,n)}const d=e=>(s.get(e)??[]).map(t=>({id:`op:${e}:${t.id}`,name:t.name,order:c(t.raw),metadata:{method:t.method,path:t.path,operationId:t.operationId,deprecated:t.deprecated,summary:t.summary,pointer:t.pointer,source:"tag-group",kind:"operation"}})),p=t=>({id:`tag:${t}`,name:a.get(t)??t,children:e(d(t)),metadata:{source:"tag-group",kind:"tag"}}),u=t=>{const n=[];for(const e of t.tags){const t=s.get(e);t?.length&&n.push(p(e))}for(const e of t.groups??[])n.push(u(e));return{id:`tag-group:${t.name}`,name:t.name,order:t.order,children:e(n),metadata:{source:"tag-group",kind:"tag-group"}}};return e(t.map(u))}(t,y,g,f):function(t,n,o){const r=new Map,a=new Map;for(let e=0;e<t.length;e+=1){const n=t[e];a.set(n.name,n.order??e)}for(const e of n){if(i(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=r.get(n)??[];t.push(e),r.set(n,t)}}const s=new Map;for(const e of t)s.set(e.name,e.displayName);const d=[];for(const[t,n]of r){const o=n.map(e=>({id:`op:${t}:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"tag",kind:"operation"}}));d.push({id:`tag:${t}`,name:s.get(t)??t,order:"Other"===t?Number.MAX_SAFE_INTEGER:a.get(t),children:e(o),metadata:{source:"tag",kind:"tag"}})}return e(d)}(y,g,f)}const k=function(n,s){if(!s.showWebhooks)return;const d=o(n.webhooks);if(!d)return;const p=[];for(const[e,n]of Object.entries(d)){const d=o(n);if(d)for(const n of t){const t=o(d[n]);if(!t||i(t,s.showInternal))continue;const u=r(t.operationId),m=r(t.summary),f=m??u??`${n.toUpperCase()} ${e}`;p.push({id:`webhook:${e}:${n}`,name:f,order:c(t),metadata:{method:n,path:e,operationId:u,deprecated:!0===a(t.deprecated),summary:m,pointer:`/webhooks/${encodeURIComponent(e)}/${n}`,source:"tag",kind:"webhook"}})}}return 0!==p.length?{id:"section:webhooks",name:"Webhooks",order:Number.MAX_SAFE_INTEGER-2,children:e(p),metadata:{source:"section",kind:"section",section:"webhooks"}}:void 0}(l,f),w=function(t,n){if(!n.showComponents)return;const r=o(t.components),a=o(r?.schemas);if(!a)return;const s=[];for(const[e,t]of Object.entries(a)){const r=o(t);r&&!i(r,n.showInternal)&&s.push({id:`schema:${e}`,name:e,order:c(r),metadata:{pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==s.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:e(s),metadata:{source:"section",kind:"section",section:"components"}}:void 0}(l,f),b=[{id:"section:apis",name:"APIs",children:$,metadata:{kind:"section",source:"section",section:"apis"},order:0},...k?[k]:[],...w?[w]:[]];return{root:{id:"root",name:"OpenAPI",children:e(b),metadata:{kind:"root"}},warnings:h}}var m={openapi:0,info:1,servers:2,paths:3,webhooks:4,components:5,security:6,tags:7,externalDocs:8,jsonSchemaDialect:9},f={maxDepth:8,showDeprecated:!0,expandCombinators:!0,showArrayItems:!0},h=new Set(["string","number","integer","boolean","null"]);function l(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function g(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function y(e){return"boolean"==typeof e?e:void 0}function $(e){return Array.isArray(e)?e:void 0}function k(e){return e?Array.isArray(e)?e.join(" | "):e:"any"}function w(t,n,o,r,a,s){const i=function(e){const t=e.type;return"string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)?t:void 0}(n),c=g(n.format),d=g(n.description),p=!0===y(n.deprecated),u=function(e){if(!e)return"unknown";switch(Array.isArray(e)?e[0]:e){case"object":return"object";case"array":return"array";case"string":return"string";case"number":return"number";case"integer":return"integer";case"boolean":return"boolean";case"null":return"null";default:return"unknown"}}(i),f={jsonPath:o,type:i,format:c,required:s,deprecated:p,description:d,kind:u},k=g(n.$ref);if(k){if(a.refStack.has(k))return a.warnings.push(`Circular $ref detected at ${o.join(".")}: ${k}. Breaking recursion.`),{id:o.join(".")||"root",name:t,metadata:{...f,kind:"ref",isLeaf:!0}};a.refStack.add(k)}let b,I=function(e){return!!e&&(Array.isArray(e)?e.every(e=>h.has(e)):h.has(e))}(i);if(r>=a.options.maxDepth)return k&&a.refStack.delete(k),{id:o.join(".")||"root",name:t,metadata:{...f,isLeaf:!0}};const A=l(n.properties);if(A){const t=$(n.required)??[],s=new Set(t.filter(e=>"string"==typeof e)),i=[];for(const[e,t]of Object.entries(A)){const n=l(t);n&&((a.options.showDeprecated||!0!==y(n.deprecated))&&i.push(w(e,n,[...o,"properties",e],r+1,a,s.has(e))))}b=[...b??[],...e(i)],I=!1}if(a.options.showArrayItems&&"array"===i){const e=l(n.items);if(e){b=[...b??[],w("items",e,[...o,"items"],r+1,a,!1)],I=!1}else f.hasItems=!1}if(a.options.expandCombinators){const t=[{key:"allOf",kind:"allOf"},{key:"anyOf",kind:"anyOf"},{key:"oneOf",kind:"oneOf"}];for(const{key:s,kind:i}of t){const t=$(n[s]);if(!t?.length)continue;const c=t.map((e,t)=>{const n=l(e);return n?w(`[${t}]`,n,[...o,s,String(t)],r+1,a,!1):{id:`${o.join(".")}.${s}[${t}]`,name:`[${t}]`,metadata:{jsonPath:[...o,s,String(t)],kind:"unknown",isLeaf:!0}}});b=[...b??[],{id:`${o.join(".")}.${s}`,name:s,children:e(c),metadata:{jsonPath:[...o,s],kind:i}}],I=!1}}const O=$(n.enum);return O?.length&&!b?.length&&(f.kind="enum",I=!0),k&&a.refStack.delete(k),{id:o.join(".")||"root",name:t,order:m[t],metadata:{...f,isLeaf:I},children:b}}function b(e,t={}){const n={...f,...t},o=[],r=l(e);if(!r)return{root:{id:"root",name:"Schema",metadata:{jsonPath:[],kind:"root",isLeaf:!0}},warnings:["Schema is null or not an object."]};return{root:w("root",r,[],0,{options:n,warnings:o,refStack:new Set},!0),warnings:o}}function I(e,t){if(0===t.length)return e;const n=t.join("."),o=[e];for(;o.length>0;){const e=o.shift();if(!e)continue;const t=e.metadata?.jsonPath?.join(".");if(t===n)return e;for(const t of e.children??[])o.push(t)}}function A(e){return"enum"===e.kind?"enum":"ref"===e.kind?"$ref":e.format?`${k(e.type)} (${e.format})`:k(e.type)}var O=["get","put","post","delete","options","head","patch","trace"],j={showInternal:!1,showComponents:!1,showWebhooks:!0,expandOperationDetails:!1};function _(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function C(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function v(e){return"boolean"==typeof e?e:void 0}function N(e){return Array.isArray(e)?e:void 0}function M(e,t){return!t&&(!0===v(e["x-scalar-ignore"])||!0===v(e["x-internal"]))}function E(e){const t=e["x-order"];return"number"==typeof t&&Number.isFinite(t)?t:void 0}function R(e){return C(e["x-displayName"])}function x(t,n){const o=[],r=N(t.parameters);if(r?.length){const t=function(t,n){const o=[];for(const e of t){const t=_(e);if(!t)continue;const r=C(t.name),a=C(t.in);if(!r||!a)continue;const s=`${a}:${r}`;o.push({id:`${n}/parameters/${encodeURIComponent(s)}`,name:r,metadata:{paramIn:a,required:!0===v(t.required),description:C(t.description),pointer:`${n}/parameters`,kind:"parameter"}})}return e(o)}(r,n);t.length>0&&o.push({id:`${n}/parameters`,name:"Parameters",children:t,metadata:{pointer:`${n}/parameters`,kind:"parameters"}})}const a=_(t.requestBody);if(a){const e=_(a.content),t=[];if(e)for(const[o]of Object.entries(e))t.push({id:`${n}/requestBody/content/${encodeURIComponent(o)}`,name:o,metadata:{contentType:o,pointer:`${n}/requestBody/content/${encodeURIComponent(o)}`,kind:"content"}});o.push({id:`${n}/requestBody`,name:"Request Body",metadata:{description:C(a.description),required:!0===v(a.required),pointer:`${n}/requestBody`,kind:"request-body"},children:t.length>0?t:void 0})}const s=_(t.responses);if(s){const t=function(t,n){const o=[];for(const[e,r]of Object.entries(t)){const t=_(r);if(!t)continue;const a=C(t.description),s=_(t.content),i=[];if(s)for(const[t]of Object.entries(s))i.push({id:`${n}/responses/${encodeURIComponent(e)}/content/${encodeURIComponent(t)}`,name:t,metadata:{contentType:t,pointer:`${n}/responses/${encodeURIComponent(e)}/content/${encodeURIComponent(t)}`,kind:"content"}});o.push({id:`${n}/responses/${encodeURIComponent(e)}`,name:e,metadata:{statusCode:e,description:a,pointer:`${n}/responses/${encodeURIComponent(e)}`,kind:"response"},children:i.length>0?i:void 0})}return e(o)}(s,n);t.length>0&&o.push({id:`${n}/responses`,name:"Responses",children:t,metadata:{pointer:`${n}/responses`,kind:"responses"}})}return o}function S(e,t,n,o){const r=t.expandOperationDetails?x(e.raw,e.pointer):void 0;return{id:`op:${o}:${e.id}`,name:e.name,order:E(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,description:e.description,pointer:e.pointer,source:n,kind:"operation"},children:r&&r.length>0?r:void 0}}function U(t,n,o,r){const a=new Map;for(const e of t)a.set(e.name,e);const s=new Map;for(const e of t){if(!e.parent){s.set(e.name,null);continue}if(!a.has(e.parent)){r.push(`Tag "${e.name}" references unknown parent "${e.parent}", treating as root.`),s.set(e.name,null);continue}const t=[e.name];let n=e.parent,o=!1;for(;n;){if(t.includes(n)){o=!0,r.push(`Circular tag reference detected: ${t.join(" -> ")} -> ${n}. Breaking cycle.`);break}t.push(n),n=a.get(n)?.parent}s.set(e.name,o?null:e.parent)}const i=new Map;for(const e of n){if(M(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=i.get(n)??[];t.push(e),i.set(n,t)}}const c=new Map;for(const e of t){const t=s.get(e.name)??null??"__root__",n=c.get(t)??[];n.push(e),c.set(t,n)}const d=t=>{const n=c.get(t)??[];return e(n.map(t=>{const n=(t=>{const n=(i.get(t.name)??[]).map(e=>S(e,o,"oas32-parent",t.name));return{id:`tag:${t.name}`,name:t.displayName,order:t.order,children:e(n),metadata:{description:t.description,source:"oas32-parent",kind:"tag"}}})(t),r=d(t.name);return r.length>0&&(n.children=e([...n.children??[],...r])),n}))},p=d("__root__"),u=i.get("Other")??[];if(u.length>0){const t=u.map(e=>S(e,o,"fallback","Other"));p.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(p)}function D(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=_(n);if(!e||"string"!=typeof e.name)continue;const o={name:e.name};Array.isArray(e.tags)&&(o.tags=e.tags.filter(e=>"string"==typeof e)),Array.isArray(e.groups)&&(o.groups=D(e.groups)),t.push(o)}return t}function q(t,n,o,r,a,s=0){const i=[];if(t.tags)for(const s of t.tags){const t=n.get(s);if(!t||0===t.length)continue;const c=t.map(e=>S(e,a,"tag-group",s));i.push({id:`tag:${s}`,name:o.get(s)??s,order:r.get(s),children:e(c),metadata:{source:"tag-group",kind:"tag"}})}if(t.groups)for(const e of t.groups)i.push(q(e,n,o,r,a,s+1));return{id:`tag-group:${t.name}`,name:t.name,order:1e3*s,children:e(i),metadata:{source:"tag-group",kind:"tag-group"}}}function T(t,n,o,r){const a=new Map,s=new Map,i=new Map;for(let e=0;e<n.length;e+=1)s.set(n[e].name,e),i.set(n[e].name,n[e].displayName);for(const e of o){if(M(e.raw,r.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=a.get(n)??[];t.push(e),a.set(n,t)}}const c=D(t["x-tagGroups"]).map(e=>q(e,a,i,s,r)),d=a.get("Other");if(d&&d.length>0){const t=d.map(e=>S(e,r,"fallback","Other"));c.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(c)}function G(e){return e.map(e=>{const t=e.children?G(e.children):void 0,n="operation"===e.metadata?.kind?1:0,o=t?.reduce((e,t)=>e+(t.metadata?.operationCount??0),0)??0;return{...e,children:t,metadata:{...e.metadata,operationCount:n+o}}})}function F(t,n={}){const o={...j,...n},r=[],a=_(t);if(!a)return{root:{id:"root",name:"API Documentation",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const s=function(e){const t=_(e.paths);if(!t)return[];const n=[];for(const[e,o]of Object.entries(t)){const t=_(o);if(t)for(const o of O){const r=_(t[o]);if(!r)continue;const a=C(r.operationId),s=C(r.summary),i=C(r.description),c=N(r.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],d=s??a??`${o.toUpperCase()} ${e}`,p=a??`${o}:${e}`,u=`/paths/${encodeURIComponent(e)}/${o}`;n.push({id:p,path:e,method:o,name:d,summary:s,description:i,operationId:a,deprecated:!0===v(r.deprecated),tags:c,pointer:u,raw:r})}}return n}(a),i=function(e){const t=N(e.tags);if(!t)return[];const n=[];for(const e of t){const t=_(e),o=C(t?.name);o&&t&&n.push({name:o,displayName:R(t)??o,description:C(t.description),parent:C(t.parent),order:E(t)})}return n}(a);let c;c=function(e){return e.some(e=>void 0!==e.parent)}(i)?U(i,s,o,r):function(e){return Array.isArray(e["x-tagGroups"])&&e["x-tagGroups"].length>0}(a)?T(a,i,s,o):function(t,n,o){const r=new Map,a=new Map;for(let e=0;e<t.length;e+=1)a.set(t[e].name,e);for(const e of n){if(M(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=r.get(n)??[];t.push(e),r.set(n,t)}}const s=new Map;for(const e of t)s.set(e.name,e.displayName);const i=[];for(const[t,n]of r){const r=n.map(e=>S(e,o,"tag",t));i.push({id:`tag:${t}`,name:s.get(t)??t,order:"Other"===t?Number.MAX_SAFE_INTEGER:a.get(t),children:e(r),metadata:{source:"tag",kind:"tag"}})}return e(i)}(i,s,o);const d=function(t,n){if(!n.showComponents)return;const o=_(t.components),r=_(o?.schemas);if(!r)return;const a=[];for(const[e,t]of Object.entries(r)){const o=_(t);o&&!M(o,n.showInternal)&&a.push({id:`schema:${e}`,name:e,order:E(o),metadata:{description:C(o.description),pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==a.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:e(a),metadata:{source:"tag",kind:"component"}}:void 0}(a,o),p=G([...c,...d?[d]:[]]);return{root:{id:"root",name:"API Documentation",children:e(p),metadata:{kind:"root"}},warnings:r}}export{u as buildOpenApiTree,b as buildSchemaTree,I as findSchemaNodeByPath,A as formatSchemaType,F as buildDocTree};