@powerduck/tree 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +556 -0
- package/dist/adapters/index.cjs +1 -0
- package/dist/adapters/index.d.cts +161 -0
- package/dist/adapters/index.d.ts +161 -0
- package/dist/adapters/index.js +1 -0
- package/dist/chunk-5KF7QUTD.js +1 -0
- package/dist/chunk-NHPRTISE.js +0 -0
- package/dist/chunk-YSSQNJPQ.js +1 -0
- package/dist/core/index.cjs +1 -0
- package/dist/core/index.d.cts +107 -0
- package/dist/core/index.d.ts +107 -0
- package/dist/core/index.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.css +592 -0
- package/dist/react/index.d.cts +213 -0
- package/dist/react/index.d.ts +213 -0
- package/dist/react/index.js +1 -0
- package/dist/types-DVz8c2Yd.d.cts +51 -0
- package/dist/types-DVz8c2Yd.d.ts +51 -0
- package/package.json +90 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,a={};function i(e){return null!=e}function s(e,n){for(const t of e){if(t.id===n)return t;if(t.children?.length){const e=s(t.children,n);if(e)return e}}}function c(e,n,t=[]){for(const o of e){const e=[...t,o];if(o.id===n)return{nodes:e,target:o,parent:t[t.length-1],ancestorIds:t.map(e=>e.id)};if(o.children?.length){const t=c(o.children,n,e);if(t)return t}}return null}function d(e){const n=[],t=e=>{if(e.children?.length)for(const n of e.children)t(n);else n.push(e)};for(const n of e)t(n);return n}function u(e){let n=0;const t=e=>{n+=1;for(const n of e.children??[])t(n)};for(const n of e)t(n);return n}function p(e){let n=0;const t=(e,o)=>{n=Math.max(n,o);for(const n of e.children??[])t(n,o+1)};for(const n of e)t(n,1);return n}function f(e){return[...e].sort((e,n)=>{const t=e.order??Number.MAX_SAFE_INTEGER,o=n.order??Number.MAX_SAFE_INTEGER;if(t!==o)return t-o;return e.name.localeCompare(n.name,"en-US",{numeric:!0,sensitivity:"base"})||e.id.localeCompare(n.id)})}function m(e){return f(e).map(e=>e.children?.length?{...e,children:m(e.children)}:e)}function l(e,n){const t=n.query.trim().toLowerCase();if(!t)return e;const o=n.keepAncestors??!0,r=e=>{const n=(e.children??[]).map(r).filter(i),a=(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t))(e);return(a||n.length)&&(o||a)?n.length===(e.children?.length??0)?e:{...e,children:n}:null};return e.map(r).filter(i)}function h(e,n={}){const t=n.maxDepth??1/0,o=n.onlyWithChildren??!0,r=[],a=(e,n)=>{if(n>t)return;const i=(e.children?.length??0)>0;o&&!i||r.push(e.id);for(const t of e.children??[])a(t,n+1)};for(const n of e)a(n,1);return r}function g(e){const n=[],t=e=>{const o=e.children;if(o&&0!==o.length){n.push(e.id);for(const e of o)t(e)}};for(const n of e)t(n);return n}function y(e){const n=[],t=(e,o)=>{n.push({node:e,depth:o});for(const n of e.children??[])t(n,o+1)};for(const n of e)t(n,1);return n}function w(e,n,t){let o=!1;const r=e.map(e=>{if(e.id===n)return o=!0,t(e);if(e.children?.length){const r=w(e.children,n,t);if(r!==e.children)return o=!0,{...e,children:r}}return e});return o?r:e}function $(e,n){const t=[];let o=!1;for(const r of e)if(r.id!==n){if(r.children?.length){const e=$(r.children,n);if(e!==r.children){o=!0,t.push({...r,children:e});continue}}t.push(r)}else o=!0;return o?t:e}function k(e,n,t){let o=!1;const r=e.map(e=>{if(e.id===n)return o=!0,{...e,children:[...e.children??[],t]};if(e.children?.length){const r=k(e.children,n,t);if(r!==e.children)return o=!0,{...e,children:r}}return e});return o?r:e}function b(e,n,t){const o=(e,t)=>{const r=e.findIndex(e=>e.id===n);if(-1!==r)return{array:e,index:r,parentId:t};for(const n of e)if(n.children?.length){const e=o(n.children,n.id);if(e)return e}return null},r=o(e,null);if(!r)return null;const{array:a,index:i,parentId:s}=r,c=Math.max(0,Math.min(t,a.length-1));if(c===i)return{nodes:e,moved:a[i],parentId:s,fromIndex:i,toIndex:i};const d=[...a],[u]=d.splice(i,1);d.splice(c,0,u);const p=e=>null===s?d:e.map(e=>e.id===s?{...e,children:d}:e.children?.length?{...e,children:p(e.children)}:e);return{nodes:p(e),moved:u,parentId:s,fromIndex:i,toIndex:c}}function I(e,n,t,o){let r=null;if(null!==t){const o=c(e,n);if(o&&o.ancestorIds.includes(t))return null}const a=e=>{const t=[];let o=!1;for(const i of e)if(i.id!==n){if(i.children?.length){const e=a(i.children);if(e!==i.children){o=!0,t.push({...i,children:e});continue}}t.push(i)}else r=i,o=!0;return o?t:e},i=a(e);if(!r)return null;if(null===t){const e=o??i.length,n=[...i];return n.splice(Math.max(0,Math.min(e,n.length)),0,r),n}let s=!1;const d=e=>e.map(e=>{if(e.id===t){s=!0;const n=[...e.children??[]],t=o??n.length;return n.splice(Math.max(0,Math.min(t,n.length)),0,r),{...e,children:n}}return e.children?.length?{...e,children:d(e.children)}:e}),u=d(i);return s?u:null}((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(a,{buildDocTree:()=>ce,buildOpenApiTree:()=>S,buildSchemaTree:()=>X,countNodes:()=>u,filterTree:()=>l,findNode:()=>s,findPath:()=>c,findSchemaNodeByPath:()=>L,flattenTree:()=>y,formatSchemaType:()=>W,getBranchIds:()=>g,getExpandableIds:()=>h,getLeaves:()=>d,getMaxDepth:()=>p,insertChild:()=>k,isTreeNode:()=>i,moveNode:()=>I,removeNode:()=>$,reorderNode:()=>b,sortNodes:()=>f,sortTree:()=>m,updateNode:()=>w}),module.exports=(e=a,((e,a,i,s)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let c of o(a))r.call(e,c)||c===i||n(e,c,{get:()=>a[c],enumerable:!(s=t(a,c))||s.enumerable});return e})(n({},"__esModule",{value:!0}),e));var A=["get","put","post","delete","options","head","patch","trace"],O={showInternal:!1,showComponents:!0,showWebhooks:!0,defaultExpandDepth:2};function N(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function j(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function v(e){return"boolean"==typeof e?e:void 0}function C(e){return Array.isArray(e)?e:void 0}function M(e,n){return!n&&(!0===v(e["x-scalar-ignore"])||!0===v(e["x-internal"]))}function _(e){return"number"==typeof(n=e["x-order"])&&Number.isFinite(n)?n:void 0;var n}function x(e){return j(e["x-displayName"])}function E(e,n,t,o){const r=new Map;for(const n of e)r.set(n.name,n);const a=new Map;for(const n of e){if(!n.parent){a.set(n.name,null);continue}if(!r.has(n.parent)){o.push(`Tag "${n.name}" references unknown parent "${n.parent}", treating as root.`),a.set(n.name,null);continue}const e=[n.name];let t=n.parent,i=!1;for(;t;){if(e.includes(t)){i=!0,o.push(`Circular tag reference detected: ${e.join(" -> ")} -> ${t}. Breaking cycle.`);break}e.push(t),t=r.get(t)?.parent}a.set(n.name,i?null:n.parent)}const i=new Map;for(const e of n){if(M(e.raw,t.showInternal))continue;const n=e.tags.length>0?e.tags:["Other"];for(const t of n){const n=i.get(t)??[];n.push(e),i.set(t,n)}}const s=new Map;for(const n of e){const e=a.get(n.name)??null??"__root__",t=s.get(e)??[];t.push(n),s.set(e,t)}const c=e=>f((s.get(e)??[]).map(e=>{const n=(e=>{const n=(i.get(e.name)??[]).map(n=>({id:`op:${e.name}:${n.id}`,name:n.name,order:_(n.raw),metadata:{method:n.method,path:n.path,operationId:n.operationId,deprecated:n.deprecated,summary:n.summary,pointer:n.pointer,source:"oas32-parent",kind:"operation"}}));return{id:`tag:${e.name}`,name:e.displayName,order:e.order,children:f(n),metadata:{source:"oas32-parent",kind:"tag"}}})(e),t=c(e.name);return t.length>0&&(n.children=f([...n.children??[],...t])),n})),d=c("__root__"),u=i.get("Other")??[];if(u.length>0){const e=u.map(e=>({id:`op:Other:${e.id}`,name:e.name,order:_(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"}}));d.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:f(e),metadata:{source:"fallback",kind:"tag"}})}return f(d)}function S(e,n={}){const t={...O,...n},o=[],r=N(e);if(!r)return{root:{id:"root",name:"OpenAPI",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const a=function(e){const n=N(e.paths);if(!n)return[];const t=[];for(const[e,o]of Object.entries(n)){const n=N(o);if(n)for(const o of A){const r=n[o];if(null==r)continue;const a=N(r);if(!a)continue;const i=j(a.operationId),s=j(a.summary),c=C(a.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],d=s??i??`${o.toUpperCase()} ${e}`,u=i??`${o}:${e}`,p=`/paths/${encodeURIComponent(e)}/${o}`;t.push({id:u,path:e,method:o,name:d,summary:s,operationId:i,deprecated:!0===v(a.deprecated),tags:c,pointer:p,raw:a})}}return t}(r),i=function(e){const n=C(e.tags);if(!n)return[];const t=[];for(const e of n){const n=N(e),o=j(n?.name);o&&n&&t.push({name:o,displayName:x(n)??o,description:j(n.description),parent:j(n.parent),order:_(n),raw:n})}return t}(r);let s;if(function(e){return e.some(e=>void 0!==e.parent)}(i))s=E(i,a,t,o);else{const e=function(e){const n=C(e["x-tagGroups"]);if(!n)return[];const t=(e,n)=>{const o=N(e),r=j(o?.name),a=C(o?.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[];if(!r)return null;const i=C(o?.groups)?.map((e,n)=>t(e,n)).filter(e=>null!==e)??[];return{name:r,tags:a,groups:i.length>0?i:void 0,order:_(o??{})??n}};return n.map((e,n)=>t(e,n)).filter(e=>null!==e)}(r);s=e.length>0?function(e,n,t,o){const r=new Map;for(const e of n)r.set(e.name,e.displayName);const a=new Map;for(const e of t)if(!M(e.raw,o.showInternal))for(const n of e.tags){const t=a.get(n)??[];t.push(e),a.set(n,t)}const i=e=>(a.get(e)??[]).map(n=>({id:`op:${e}:${n.id}`,name:n.name,order:_(n.raw),metadata:{method:n.method,path:n.path,operationId:n.operationId,deprecated:n.deprecated,summary:n.summary,pointer:n.pointer,source:"tag-group",kind:"operation"}})),s=e=>({id:`tag:${e}`,name:r.get(e)??e,children:f(i(e)),metadata:{source:"tag-group",kind:"tag"}}),c=e=>{const n=[];for(const t of e.tags){const e=a.get(t);e?.length&&n.push(s(t))}for(const t of e.groups??[])n.push(c(t));return{id:`tag-group:${e.name}`,name:e.name,order:e.order,children:f(n),metadata:{source:"tag-group",kind:"tag-group"}}};return f(e.map(c))}(e,i,a,t):function(e,n,t){const o=new Map,r=new Map;for(let n=0;n<e.length;n+=1){const t=e[n];r.set(t.name,t.order??n)}for(const e of n){if(M(e.raw,t.showInternal))continue;const n=e.tags.length>0?e.tags:["Other"];for(const t of n){const n=o.get(t)??[];n.push(e),o.set(t,n)}}const a=new Map;for(const n of e)a.set(n.name,n.displayName);const i=[];for(const[e,n]of o){const t=n.map(n=>({id:`op:${e}:${n.id}`,name:n.name,order:_(n.raw),metadata:{method:n.method,path:n.path,operationId:n.operationId,deprecated:n.deprecated,summary:n.summary,pointer:n.pointer,source:"tag",kind:"operation"}}));i.push({id:`tag:${e}`,name:a.get(e)??e,order:"Other"===e?Number.MAX_SAFE_INTEGER:r.get(e),children:f(t),metadata:{source:"tag",kind:"tag"}})}return f(i)}(i,a,t)}const c=function(e,n){if(!n.showWebhooks)return;const t=N(e.webhooks);if(!t)return;const o=[];for(const[e,r]of Object.entries(t)){const t=N(r);if(t)for(const r of A){const a=N(t[r]);if(!a||M(a,n.showInternal))continue;const i=j(a.operationId),s=j(a.summary),c=s??i??`${r.toUpperCase()} ${e}`;o.push({id:`webhook:${e}:${r}`,name:c,order:_(a),metadata:{method:r,path:e,operationId:i,deprecated:!0===v(a.deprecated),summary:s,pointer:`/webhooks/${encodeURIComponent(e)}/${r}`,source:"tag",kind:"webhook"}})}}return 0!==o.length?{id:"section:webhooks",name:"Webhooks",order:Number.MAX_SAFE_INTEGER-2,children:f(o),metadata:{source:"section",kind:"section",section:"webhooks"}}:void 0}(r,t),d=function(e,n){if(!n.showComponents)return;const t=N(e.components),o=N(t?.schemas);if(!o)return;const r=[];for(const[e,t]of Object.entries(o)){const o=N(t);o&&!M(o,n.showInternal)&&r.push({id:`schema:${e}`,name:e,order:_(o),metadata:{pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==r.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:f(r),metadata:{source:"section",kind:"section",section:"components"}}:void 0}(r,t);return{root:{id:"root",name:"OpenAPI",children:f([{id:"section:apis",name:"APIs",children:s,metadata:{kind:"section",source:"section",section:"apis"},order:0},...c?[c]:[],...d?[d]:[]]),metadata:{kind:"root"}},warnings:o}}var R={openapi:0,info:1,servers:2,paths:3,webhooks:4,components:5,security:6,tags:7,externalDocs:8,jsonSchemaDialect:9},T={maxDepth:8,showDeprecated:!0,expandCombinators:!0,showArrayItems:!0},U=new Set(["string","number","integer","boolean","null"]);function D(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function P(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function q(e){return"boolean"==typeof e?e:void 0}function G(e){return Array.isArray(e)?e:void 0}function F(e){return e?Array.isArray(e)?e.join(" | "):e:"any"}function B(e,n,t,o,r,a){const i=function(e){const n=e.type;return"string"==typeof n||Array.isArray(n)&&n.every(e=>"string"==typeof e)?n:void 0}(n),s=P(n.format),c=P(n.description),d=!0===q(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),p={jsonPath:t,type:i,format:s,required:a,deprecated:d,description:c,kind:u},m=P(n.$ref);if(m){if(r.refStack.has(m))return r.warnings.push(`Circular $ref detected at ${t.join(".")}: ${m}. Breaking recursion.`),{id:t.join(".")||"root",name:e,metadata:{...p,kind:"ref",isLeaf:!0}};r.refStack.add(m)}let l,h=function(e){return!!e&&(Array.isArray(e)?e.every(e=>U.has(e)):U.has(e))}(i);if(o>=r.options.maxDepth)return m&&r.refStack.delete(m),{id:t.join(".")||"root",name:e,metadata:{...p,isLeaf:!0}};const g=D(n.properties);if(g){const e=G(n.required)??[],a=new Set(e.filter(e=>"string"==typeof e)),i=[];for(const[e,n]of Object.entries(g)){const s=D(n);s&&((r.options.showDeprecated||!0!==q(s.deprecated))&&i.push(B(e,s,[...t,"properties",e],o+1,r,a.has(e))))}l=[...l??[],...f(i)],h=!1}if(r.options.showArrayItems&&"array"===i){const e=D(n.items);if(e){l=[...l??[],B("items",e,[...t,"items"],o+1,r,!1)],h=!1}else p.hasItems=!1}if(r.options.expandCombinators){const e=[{key:"allOf",kind:"allOf"},{key:"anyOf",kind:"anyOf"},{key:"oneOf",kind:"oneOf"}];for(const{key:a,kind:i}of e){const e=G(n[a]);if(!e?.length)continue;const s=e.map((e,n)=>{const i=D(e);return i?B(`[${n}]`,i,[...t,a,String(n)],o+1,r,!1):{id:`${t.join(".")}.${a}[${n}]`,name:`[${n}]`,metadata:{jsonPath:[...t,a,String(n)],kind:"unknown",isLeaf:!0}}});l=[...l??[],{id:`${t.join(".")}.${a}`,name:a,children:f(s),metadata:{jsonPath:[...t,a],kind:i}}],h=!1}}const y=G(n.enum);return y?.length&&!l?.length&&(p.kind="enum",h=!0),m&&r.refStack.delete(m),{id:t.join(".")||"root",name:e,order:R[e],metadata:{...p,isLeaf:h},children:l}}function X(e,n={}){const t={...T,...n},o=[],r=D(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:B("root",r,[],0,{options:t,warnings:o,refStack:new Set},!0),warnings:o}}function L(e,n){if(0===n.length)return e;const t=n.join("."),o=[e];for(;o.length>0;){const e=o.shift();if(!e)continue;const n=e.metadata?.jsonPath?.join(".");if(n===t)return e;for(const n of e.children??[])o.push(n)}}function W(e){return"enum"===e.kind?"enum":"ref"===e.kind?"$ref":e.format?`${F(e.type)} (${e.format})`:F(e.type)}var z=["get","put","post","delete","options","head","patch","trace"],H={showInternal:!1,showComponents:!1,showWebhooks:!0,expandOperationDetails:!0};function J(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function K(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function Q(e){return"boolean"==typeof e?e:void 0}function V(e){return Array.isArray(e)?e:void 0}function Y(e,n){return!n&&(!0===Q(e["x-scalar-ignore"])||!0===Q(e["x-internal"]))}function Z(e){const n=e["x-order"];return"number"==typeof n&&Number.isFinite(n)?n:void 0}function ee(e){return K(e["x-displayName"])}function ne(e,n){const t=[],o=V(e.parameters);if(o?.length){const e=function(e,n){const t=[];for(const o of e){const e=J(o);if(!e)continue;const r=K(e.name),a=K(e.in);if(!r||!a)continue;const i=`${a}:${r}`;t.push({id:`${n}/parameters/${encodeURIComponent(i)}`,name:r,metadata:{paramIn:a,required:!0===Q(e.required),description:K(e.description),pointer:`${n}/parameters`,kind:"parameter"}})}return f(t)}(o,n);e.length>0&&t.push({id:`${n}/parameters`,name:"Parameters",children:e,metadata:{pointer:`${n}/parameters`,kind:"parameters"}})}const r=J(e.requestBody);if(r){const e=J(r.content),o=[];if(e)for(const[t]of Object.entries(e))o.push({id:`${n}/requestBody/content/${encodeURIComponent(t)}`,name:t,metadata:{contentType:t,pointer:`${n}/requestBody/content/${encodeURIComponent(t)}`,kind:"content"}});t.push({id:`${n}/requestBody`,name:"Request Body",metadata:{description:K(r.description),required:!0===Q(r.required),pointer:`${n}/requestBody`,kind:"request-body"},children:o.length>0?o:void 0})}const a=J(e.responses);if(a){const e=function(e,n){const t=[];for(const[o,r]of Object.entries(e)){const e=J(r);if(!e)continue;const a=K(e.description),i=J(e.content),s=[];if(i)for(const[e]of Object.entries(i))s.push({id:`${n}/responses/${encodeURIComponent(o)}/content/${encodeURIComponent(e)}`,name:e,metadata:{contentType:e,pointer:`${n}/responses/${encodeURIComponent(o)}/content/${encodeURIComponent(e)}`,kind:"content"}});t.push({id:`${n}/responses/${encodeURIComponent(o)}`,name:o,metadata:{statusCode:o,description:a,pointer:`${n}/responses/${encodeURIComponent(o)}`,kind:"response"},children:s.length>0?s:void 0})}return f(t)}(a,n);e.length>0&&t.push({id:`${n}/responses`,name:"Responses",children:e,metadata:{pointer:`${n}/responses`,kind:"responses"}})}return t}function te(e,n,t,o){const r=n.expandOperationDetails?ne(e.raw,e.pointer):void 0;return{id:`op:${o}:${e.id}`,name:e.name,order:Z(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:t,kind:"operation"},children:r&&r.length>0?r:void 0}}function oe(e,n,t,o){const r=new Map;for(const n of e)r.set(n.name,n);const a=new Map;for(const n of e){if(!n.parent){a.set(n.name,null);continue}if(!r.has(n.parent)){o.push(`Tag "${n.name}" references unknown parent "${n.parent}", treating as root.`),a.set(n.name,null);continue}const e=[n.name];let t=n.parent,i=!1;for(;t;){if(e.includes(t)){i=!0,o.push(`Circular tag reference detected: ${e.join(" -> ")} -> ${t}. Breaking cycle.`);break}e.push(t),t=r.get(t)?.parent}a.set(n.name,i?null:n.parent)}const i=new Map;for(const e of n){if(Y(e.raw,t.showInternal))continue;const n=e.tags.length>0?e.tags:["Other"];for(const t of n){const n=i.get(t)??[];n.push(e),i.set(t,n)}}const s=new Map;for(const n of e){const e=a.get(n.name)??null??"__root__",t=s.get(e)??[];t.push(n),s.set(e,t)}const c=e=>f((s.get(e)??[]).map(e=>{const n=(e=>{const n=(i.get(e.name)??[]).map(n=>te(n,t,"oas32-parent",e.name));return{id:`tag:${e.name}`,name:e.displayName,order:e.order,children:f(n),metadata:{description:e.description,source:"oas32-parent",kind:"tag"}}})(e),o=c(e.name);return o.length>0&&(n.children=f([...n.children??[],...o])),n})),d=c("__root__"),u=i.get("Other")??[];if(u.length>0){const e=u.map(e=>te(e,t,"fallback","Other"));d.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:f(e),metadata:{source:"fallback",kind:"tag"}})}return f(d)}function re(e){if(!Array.isArray(e))return[];const n=[];for(const t of e){const e=J(t);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=re(e.groups)),n.push(o)}return n}function ae(e,n,t,o,r,a=0){const i=[];if(e.tags)for(const a of e.tags){const e=n.get(a);if(!e||0===e.length)continue;const s=e.map(e=>te(e,r,"tag-group",a));i.push({id:`tag:${a}`,name:t.get(a)??a,order:o.get(a),children:f(s),metadata:{source:"tag-group",kind:"tag"}})}if(e.groups)for(const s of e.groups)i.push(ae(s,n,t,o,r,a+1));return{id:`tag-group:${e.name}`,name:e.name,order:1e3*a,children:f(i),metadata:{source:"tag-group",kind:"tag-group"}}}function ie(e,n,t,o){const r=new Map,a=new Map,i=new Map;for(let e=0;e<n.length;e+=1)a.set(n[e].name,e),i.set(n[e].name,n[e].displayName);for(const e of t){if(Y(e.raw,o.showInternal))continue;const n=e.tags.length>0?e.tags:["Other"];for(const t of n){const n=r.get(t)??[];n.push(e),r.set(t,n)}}const s=re(e["x-tagGroups"]).map(e=>ae(e,r,i,a,o)),c=r.get("Other");if(c&&c.length>0){const e=c.map(e=>te(e,o,"fallback","Other"));s.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:f(e),metadata:{source:"fallback",kind:"tag"}})}return f(s)}function se(e){return e.map(e=>{const n=e.children?se(e.children):void 0,t="operation"===e.metadata?.kind?1:0,o=n?.reduce((e,n)=>e+(n.metadata?.operationCount??0),0)??0;return{...e,children:n,metadata:{...e.metadata,operationCount:t+o}}})}function ce(e,n={}){const t={...H,...n},o=[],r=J(e);if(!r)return{root:{id:"root",name:"API Documentation",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const a=function(e){const n=J(e.paths);if(!n)return[];const t=[];for(const[e,o]of Object.entries(n)){const n=J(o);if(n)for(const o of z){const r=J(n[o]);if(!r)continue;const a=K(r.operationId),i=K(r.summary),s=K(r.description),c=V(r.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],d=i??a??`${o.toUpperCase()} ${e}`,u=a??`${o}:${e}`,p=`/paths/${encodeURIComponent(e)}/${o}`;t.push({id:u,path:e,method:o,name:d,summary:i,description:s,operationId:a,deprecated:!0===Q(r.deprecated),tags:c,pointer:p,raw:r})}}return t}(r),i=function(e){const n=V(e.tags);if(!n)return[];const t=[];for(const e of n){const n=J(e),o=K(n?.name);o&&n&&t.push({name:o,displayName:ee(n)??o,description:K(n.description),parent:K(n.parent),order:Z(n)})}return t}(r);let s;s=function(e){return e.some(e=>void 0!==e.parent)}(i)?oe(i,a,t,o):function(e){return Array.isArray(e["x-tagGroups"])&&e["x-tagGroups"].length>0}(r)?ie(r,i,a,t):function(e,n,t){const o=new Map,r=new Map;for(let n=0;n<e.length;n+=1)r.set(e[n].name,n);for(const e of n){if(Y(e.raw,t.showInternal))continue;const n=e.tags.length>0?e.tags:["Other"];for(const t of n){const n=o.get(t)??[];n.push(e),o.set(t,n)}}const a=new Map;for(const n of e)a.set(n.name,n.displayName);const i=[];for(const[e,n]of o){const o=n.map(n=>te(n,t,"tag",e));i.push({id:`tag:${e}`,name:a.get(e)??e,order:"Other"===e?Number.MAX_SAFE_INTEGER:r.get(e),children:f(o),metadata:{source:"tag",kind:"tag"}})}return f(i)}(i,a,t);const c=function(e,n){if(!n.showComponents)return;const t=J(e.components),o=J(t?.schemas);if(!o)return;const r=[];for(const[e,t]of Object.entries(o)){const o=J(t);o&&!Y(o,n.showInternal)&&r.push({id:`schema:${e}`,name:e,order:Z(o),metadata:{description:K(o.description),pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==r.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:f(r),metadata:{source:"tag",kind:"component"}}:void 0}(r,t);return{root:{id:"root",name:"API Documentation",children:f(se([...s,...c?[c]:[]])),metadata:{kind:"root"}},warnings:o}}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { E as ExpandOptions, F as FilterTreeOptions, T as TreeNode, a as TreePath } from './types-DVz8c2Yd.cjs';
|
|
2
|
+
export { ReorderResult, countNodes, filterTree, findNode, findPath, flattenTree, getBranchIds, getExpandableIds, getLeaves, getMaxDepth, insertChild, isTreeNode, moveNode, removeNode, reorderNode, sortNodes, sortTree, updateNode } from './core/index.cjs';
|
|
3
|
+
export { DocNodeKind, DocNodeMetadata, DocTreeBuildResult, DocTreeNode, DocTreeOptions, OpenApiNodeKind, OpenApiNodeMetadata, OpenApiTreeBuildResult, OpenApiTreeNode, OpenApiTreeOptions, SchemaNodeKind, SchemaNodeMetadata, SchemaTreeBuildResult, SchemaTreeNode, SchemaTreeOptions, buildDocTree, buildOpenApiTree, buildSchemaTree, findSchemaNodeByPath, formatSchemaType } from './adapters/index.cjs';
|
|
4
|
+
import '@powerduck/openapi-parser';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { E as ExpandOptions, F as FilterTreeOptions, T as TreeNode, a as TreePath } from './types-DVz8c2Yd.js';
|
|
2
|
+
export { ReorderResult, countNodes, filterTree, findNode, findPath, flattenTree, getBranchIds, getExpandableIds, getLeaves, getMaxDepth, insertChild, isTreeNode, moveNode, removeNode, reorderNode, sortNodes, sortTree, updateNode } from './core/index.js';
|
|
3
|
+
export { DocNodeKind, DocNodeMetadata, DocTreeBuildResult, DocTreeNode, DocTreeOptions, OpenApiNodeKind, OpenApiNodeMetadata, OpenApiTreeBuildResult, OpenApiTreeNode, OpenApiTreeOptions, SchemaNodeKind, SchemaNodeMetadata, SchemaTreeBuildResult, SchemaTreeNode, SchemaTreeOptions, buildDocTree, buildOpenApiTree, buildSchemaTree, findSchemaNodeByPath, formatSchemaType } from './adapters/index.js';
|
|
4
|
+
import '@powerduck/openapi-parser';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{buildDocTree as o,buildOpenApiTree as r,buildSchemaTree as m,findSchemaNodeByPath as p,formatSchemaType as t}from"./chunk-YSSQNJPQ.js";import"./chunk-NHPRTISE.js";import{countNodes as c,filterTree as h,findNode as i,findPath as j,flattenTree as k,getBranchIds as n,getExpandableIds as s,getLeaves as u,getMaxDepth as Q,insertChild as S,isTreeNode as f,moveNode as N,removeNode as P,reorderNode as T,sortNodes as e,sortTree as x,updateNode as D}from"./chunk-5KF7QUTD.js";export{o as buildDocTree,r as buildOpenApiTree,m as buildSchemaTree,c as countNodes,h as filterTree,i as findNode,j as findPath,p as findSchemaNodeByPath,k as flattenTree,t as formatSchemaType,n as getBranchIds,s as getExpandableIds,u as getLeaves,Q as getMaxDepth,S as insertChild,f as isTreeNode,N as moveNode,P as removeNode,T as reorderNode,e as sortNodes,x as sortTree,D as updateNode};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,d=Object.prototype.hasOwnProperty,o={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(o,{METHOD_LABEL_MAP:()=>I,Tree:()=>A,getMethodLabel:()=>v,useTreeExpansion:()=>p,useTreeSearch:()=>g}),module.exports=(e=o,((e,o,a,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let l of r(o))d.call(e,l)||l===a||n(e,l,{get:()=>o[l],enumerable:!(i=t(o,l))||i.enumerable});return e})(n({},"__esModule",{value:!0}),e));var a=require("react");function i(e){return null!=e}function l(e,n,t=[]){for(const r of e){const e=[...t,r];if(r.id===n)return{nodes:e,target:r,parent:t[t.length-1],ancestorIds:t.map(e=>e.id)};if(r.children?.length){const t=l(r.children,n,e);if(t)return t}}return null}function s(e,n){const t=n.query.trim().toLowerCase();if(!t)return e;const r=n.keepAncestors??!0,d=e=>{const n=(e.children??[]).map(d).filter(i),o=(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t))(e);return(o||n.length)&&(r||o)?n.length===(e.children?.length??0)?e:{...e,children:n}:null};return e.map(d).filter(i)}function c(e,n={}){const t=n.maxDepth??1/0,r=n.onlyWithChildren??!0,d=[],o=(e,n)=>{if(n>t)return;const a=(e.children?.length??0)>0;r&&!a||d.push(e.id);for(const t of e.children??[])o(t,n+1)};for(const n of e)o(n,1);return d}function u(e,n,t,r){let d=null;if(null!==t){const r=l(e,n);if(r&&r.ancestorIds.includes(t))return null}const o=e=>{const t=[];let r=!1;for(const a of e)if(a.id!==n){if(a.children?.length){const e=o(a.children);if(e!==a.children){r=!0,t.push({...a,children:e});continue}}t.push(a)}else d=a,r=!0;return r?t:e},a=o(e);if(!d)return null;if(null===t){const e=r??a.length,n=[...a];return n.splice(Math.max(0,Math.min(e,n.length)),0,d),n}let i=!1;const s=e=>e.map(e=>{if(e.id===t){i=!0;const n=[...e.children??[]],t=r??n.length;return n.splice(Math.max(0,Math.min(t,n.length)),0,d),{...e,children:n}}return e.children?.length?{...e,children:s(e.children)}:e}),c=s(a);return i?c:null}var h=require("react");function p(e,n={}){const{defaultExpandedIds:t,defaultExpandDepth:r=1,onExpandedChange:d}=n,o=(0,h.useMemo)(()=>t&&t.length>0?[...t]:r<=1?[]:c(e,{maxDepth:r-1,onlyWithChildren:!0}),[]),[a,i]=(0,h.useState)(o),l=(0,h.useRef)(new Map),s=(0,h.useMemo)(()=>function(e){const n=[],t=e=>{const r=e.children;if(r&&0!==r.length){n.push(e.id);for(const e of r)t(e)}};for(const n of e)t(n);return n}(e),[e]),u=(0,h.useMemo)(()=>s.length>0&&s.every(e=>a.includes(e)),[s,a]),p=(0,h.useCallback)(e=>{i(e),d?.(e)},[d]),f=(0,h.useCallback)(e=>{i(n=>{const t=n.includes(e)?n.filter(n=>n!==e):[...n,e];return d?.(t),t})},[d]),g=(0,h.useCallback)(()=>{p([...s])},[s,p]),x=(0,h.useCallback)(()=>{p([])},[p]),m=(0,h.useCallback)(n=>{const t=c(e,{maxDepth:n,onlyWithChildren:!0});p(t)},[e,p]),I=(0,h.useCallback)((e,n)=>{n?l.current.set(e,n):l.current.delete(e)},[]),v=(0,h.useCallback)(e=>{const n=l.current.get(e);n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},[]);return{expandedIds:a,setExpandedIds:p,toggleNode:f,expandAll:g,collapseAll:x,expandToDepth:m,isAllExpanded:u,allBranchIds:s,setNodeElementRef:I,scrollToNode:v}}var f=require("react");function g(e){const[n,t]=(0,f.useState)(""),r=(0,f.useDeferredValue)(n),[d,o]=(0,f.useState)(null),a=r.trim().length>0,i=(0,f.useMemo)(()=>a?s(e,{query:r,keepAncestors:!0}):e,[e,r,a]),l=(0,f.useCallback)((e,r)=>{const d=n.trim(),a=e.trim();!d&&a&&o(r),d&&!a&&o(null),t(e)},[n]),c=(0,f.useCallback)(()=>{t(""),o(null)},[]);return{query:n,deferredQuery:r,isSearching:a,filteredNodes:i,expandedBeforeSearch:d,handleQueryChange:l,clearSearch:c}}function x(e,n,t=[]){for(const r of e){if(r.id===n)return[...t,r];if(r.children?.length){const e=x(r.children,n,[...t,r]);if(e)return e}}return null}function m(e,n){const t=x(e,n);return t?t.slice(0,-1).map(e=>e.id):[]}var I={get:"GET",post:"POST",put:"PUT",delete:"DEL",patch:"PATCH",head:"HEAD",options:"OPT",trace:"TRA",connect:"CONN"};function v(e){const n=e.toLowerCase().trim();return I[n]??n.slice(0,4).toUpperCase()}var b=require("react-icons/lu"),C=require("react-icons/md"),D=require("react/jsx-runtime"),N={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 j({expanded:e}){return(0,D.jsx)("span",{className:N.expandIcon,children:e?(0,D.jsx)(b.LuChevronDown,{size:14}):(0,D.jsx)(b.LuChevronRight,{size:14})})}function M(){return(0,D.jsx)(b.LuSearch,{size:14,"aria-hidden":"true"})}function S(){return(0,D.jsx)(b.LuGripVertical,{size:14,"aria-hidden":"true"})}function y(){return(0,D.jsx)(b.LuEllipsisVertical,{size:14,"aria-hidden":"true"})}function w({state:e,onClose:n}){const{x:t,y:r,items:d}=e,[o,i]=(0,a.useState)(null);return(0,D.jsx)("div",{className:N.contextMenu,style:{left:t,top:r},role:"menu",onMouseDown:e=>e.stopPropagation(),children:d.map((t,r)=>t.separator?(0,D.jsx)("div",{className:N.contextMenuSeparator},`sep-${r}`):(0,D.jsxs)("button",{type:"button",role:"menuitem",className:[N.contextMenuItem,t.danger?N.contextMenuItemDanger:"",o===r?N.contextMenuItemConfirming:""].filter(Boolean).join(" "),disabled:t.disabled,onClick:()=>((t,r)=>{t.confirm&&o!==r?i(r):(t.onClick(e.node),i(null),n())})(t,r),children:[t.icon&&(0,D.jsx)("span",{className:N.contextMenuIcon,children:t.icon}),(0,D.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:t.confirm&&o===r?t.confirmLabel??"Confirm?":t.label})]},`${t.label}-${r}`))})}function L(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 E({text:e,query:n}){if(!n)return(0,D.jsx)(D.Fragment,{children:e});const t=e.toLowerCase(),r=n.toLowerCase(),d=t.indexOf(r);return-1===d?(0,D.jsx)(D.Fragment,{children:e}):(0,D.jsxs)(D.Fragment,{children:[e.slice(0,d),(0,D.jsx)("span",{className:N.highlight,children:e.slice(d,d+n.length)}),e.slice(d+n.length)]})}var k={get:N.methodGet,post:N.methodPost,put:N.methodPut,patch:N.methodPatch,delete:N.methodDelete};function O({method:e}){const n=e.toLowerCase(),t=k[n]??N.methodOther,r=v(e);return(0,D.jsx)("span",{className:`${N.methodBadge} ${t}`,children:r})}var B={draggedId:null,dragOverId:null,dragOverPosition:null};var P=(0,a.memo)(function(e){const{node:n,depth:t,expandedIds:r,selectedId:d,onToggle:o,onSelect:i,onNodeRef:l,searchQuery:s,showIndentGuides:c,renderIcon:u,renderLabel:h,renderSuffix:p,renderNode:f,draggable:g,dragState:x,canDragNode:m,canDragNodeFn:I,onDragStart:v,onDragOver:C,onDragLeave:M,onDrop:w,onDragEnd:L,showContextMenuButton:k,activeMenuNodeId:B,onContextMenu:A,onMoreClick:R}=e,T=r.includes(n.id),q=d===n.id,z=(n.children?.length??0)>0,G=z,$=!z,H=x.draggedId===n.id,F=x.dragOverId===n.id,Q=F?x.dragOverPosition:null,W=n.metadata,U="string"==typeof W?.method?W.method:void 0,V=!0===W?.deprecated,_=!0===W?.required,K="string"==typeof W?.kind?W.kind:void 0,Y={node:n,depth:t,isExpanded:T,isSelected:q,isBranch:G,isLeaf:$,isDragging:H,isDragOver:F,dragOverPosition:Q},X=(0,a.useCallback)(()=>{G?o(n.id):i(n)},[G,n,i,o]),Z=(0,a.useCallback)(e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),X()):("ArrowRight"===e.key&&G&&!T||"ArrowLeft"===e.key&&G&&T)&&(e.preventDefault(),o(n.id))},[X,G,T,n.id,o]),J=u?u(Y):U?null:(0,D.jsx)("span",{className:N.nodeIcon,children:"section"===K&&"components"===W?.section?(0,D.jsx)(b.LuBraces,{size:14}):"section"===K&&"webhooks"===W?.section?(0,D.jsx)(b.LuZap,{size:14}):"schema"===K||"component"===K||"object"===K?(0,D.jsx)(b.LuBraces,{size:14}):"array"===K||"items"===K?(0,D.jsx)(b.LuList,{size:14}):G?T?(0,D.jsx)(b.LuFolderOpen,{size:14}):(0,D.jsx)(b.LuFolder,{size:14}):(0,D.jsx)("span",{className:N.primitiveDot})}),ee=h?h(Y):(0,D.jsx)("span",{className:`${N.nodeLabel} ${G?N.nodeLabelBranch:""} ${V?N.deprecatedLabel:""}`,children:(0,D.jsx)(E,{text:n.name,query:s})}),ne=p?p(Y):null,te=[N.nodeRow,G?N.branchControl:N.leafItem,q?N.nodeRowSelected:"",H?N.nodeDragging:"",F&&"before"===Q?N.dropIndicatorBefore:"",F&&"after"===Q?N.dropIndicatorAfter:"",F&&"child"===Q?N.dropIndicatorChild:"",K?`pde-tree-kind-${K}`:""].filter(Boolean).join(" "),re=(0,D.jsxs)("div",{ref:e=>l(n.id,e),className:te,style:{paddingLeft:14*t+8+"px"},role:"treeitem","aria-expanded":G?T:void 0,"aria-selected":q,"aria-level":t,"aria-grabbed":g&&m?H:void 0,tabIndex:0,onClick:X,onKeyDown:Z,onContextMenu:k?e=>A(n,e):void 0,onDragOver:g?e=>C(n,e):void 0,onDragLeave:g?()=>M(n):void 0,onDrop:g?e=>w(n,e):void 0,children:[c&&t>1&&Array.from({length:t-1},(e,n)=>(0,D.jsx)("span",{className:N.indentGuide,style:{left:14*(n+1)+33+"px"}},`guide-${n}`)),g&&m&&(0,D.jsx)("span",{className:N.dragHandle,draggable:!0,onDragStart:e=>v(n,e),onDragEnd:L,title:"Drag to reorder","aria-label":"Drag to reorder",children:(0,D.jsx)(S,{})}),G?(0,D.jsx)(j,{expanded:T}):(0,D.jsx)("span",{className:N.expandIconPlaceholder}),J,U&&(0,D.jsx)(O,{method:U}),ee,_&&(0,D.jsx)("span",{className:N.requiredDot,title:"Required"}),(0,D.jsx)("span",{className:N.nodeSuffix,children:ne}),k&&(0,D.jsx)("button",{type:"button",className:[N.moreButton,B===n.id?N.moreButtonActive:""].filter(Boolean).join(" "),onClick:e=>R(n,e),title:"More actions","aria-label":"More actions",children:(0,D.jsx)(y,{})})]}),de=f?f(Y,re):re;return(0,D.jsxs)("div",{role:"presentation",children:[de,G&&T&&n.children?.map(n=>(0,D.jsx)(P,{...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)))))))))))))))}),A=(0,a.forwardRef)(function(e,n){const{nodes:t,onSelect:r,onExpandedChange:d,defaultExpandedIds:o,defaultExpandDepth:i=1,searchable:s=!1,searchPlaceholder:c="Search...",showExpandAll:h=!1,showRefresh:f=!1,onRefresh:x,toolbar:I,searchRowExtra:v,renderNode:j,renderIcon:S,renderLabel:y,renderSuffix:E,className:k,style:O,size:A="sm",variant:R="default",showIndentGuides:T=!0,maxHeight:q,rootRef:z,draggable:G=!1,dragGroupKey:$,onReorder:H,onMove:F,canDrag:Q,canDrop:W,contextMenuItems:U,onPatch:V}=e,[_,K]=(0,a.useState)(null),[Y,X]=(0,a.useState)(B),[Z,J]=(0,a.useState)(null),ee=(0,a.useRef)(null),ne=p(t,{defaultExpandedIds:o,defaultExpandDepth:i,onExpandedChange:d}),te=g(t),re=te.isSearching?ne.allBranchIds:te.expandedBeforeSearch??ne.expandedIds,de=(0,a.useCallback)(e=>{K(e.id),r?.(e)},[r]),oe=(0,a.useCallback)(e=>{te.handleQueryChange(e,ne.expandedIds)},[ne.expandedIds,te]),ae=(0,a.useCallback)(e=>{if(!G)return!1;const n=e.metadata;return"section"!==n?.kind&&(!Q||Q(e))},[Q,G]),ie=(0,a.useCallback)((e,n)=>{ae(e)?(n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",e.id),X({draggedId:e.id,dragOverId:null,dragOverPosition:null})):n.preventDefault()},[ae]),le=(0,a.useCallback)((e,n)=>{if(!Y.draggedId||Y.draggedId===e.id)return;n.preventDefault(),n.dataTransfer.dropEffect="move";const r=n.currentTarget.getBoundingClientRect(),d=(n.clientY-r.top)/r.height,o=(e.children?.length??0)>0;let a;a=o?d<.25?"before":d>.75?"after":"child":d<.5?"before":"after";const i=Y.draggedId?l(t,Y.draggedId):null;if("child"!==a||!i||!i.ancestorIds.includes(e.id)){if($&&i){const n=l(t,e.id);if(n){const e=e=>{for(let n=e.nodes.length-1;n>=0;n--){const t=e.nodes[n]?.metadata;if(t&&$ in t)return t[$]}},t=e(i),r=e(n);if(void 0!==t&&void 0!==r&&t!==r)return}}if(W){const n=i?.target;if(!n||!W(n,e,a))return}X(n=>n.dragOverId===e.id&&n.dragOverPosition===a?n:{...n,dragOverId:e.id,dragOverPosition:a})}},[W,Y.draggedId,t]),se=(0,a.useCallback)(e=>{X(n=>n.dragOverId!==e.id?n:{...n,dragOverId:null,dragOverPosition:null})},[]),ce=(0,a.useCallback)((e,n)=>{n.preventDefault();const r=Y.draggedId,d=Y.dragOverPosition;if(!r||!d||r===e.id)return void X(B);if("child"===d){const n=l(t,r),d=n?.target;if(!d)return void X(B);const o=u(t,r,e.id);return o&&F?.(o,d,e.id),void X(B)}const o=l(t,e.id);if(!o)return void X(B);const a=o.parent?.children??t,i=a.findIndex(n=>n.id===e.id);if(-1===i)return void X(B);let s="before"===d?i:i+1;const c=l(t,r),h=o.parent?.id??null;if((c?.parent?.id??null)!==h){const e=c?.target,n=u(t,r,h,s);return n&&e&&F?.(n,e,h),void X(B)}if(c&&c.parent===o.parent){const e=a.findIndex(e=>e.id===r);-1!==e&&e<s&&(s-=1)}const p=function(e,n,t){const r=(e,t)=>{const d=e.findIndex(e=>e.id===n);if(-1!==d)return{array:e,index:d,parentId:t};for(const n of e)if(n.children?.length){const e=r(n.children,n.id);if(e)return e}return null},d=r(e,null);if(!d)return null;const{array:o,index:a,parentId:i}=d,l=Math.max(0,Math.min(t,o.length-1));if(l===a)return{nodes:e,moved:o[a],parentId:i,fromIndex:a,toIndex:a};const s=[...o],[c]=s.splice(a,1);s.splice(l,0,c);const u=e=>null===i?s:e.map(e=>e.id===i?{...e,children:s}:e.children?.length?{...e,children:u(e.children)}:e);return{nodes:u(e),moved:c,parentId:i,fromIndex:a,toIndex:l}}(t,r,s);if(p&&p.fromIndex!==p.toIndex&&(H?.(p),V)){const e=L(p.moved,p.fromIndex,p.toIndex);e.length>0&&V(e,{node:p.moved,type:"reorder"})}X(B)},[Y,t,F,V,H]),ue=(0,a.useCallback)(()=>{X(B)},[]),he=(0,a.useCallback)((e,n,t)=>{if(!U)return;const r=U(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);J({x:Math.max(8,o),y:Math.max(8,a),node:e,items:r})},[U]),pe=(0,a.useCallback)(()=>{J(null)},[]),fe=(0,a.useCallback)((e,n)=>{n.preventDefault(),he(e,n.clientX,n.clientY)},[he]),ge=(0,a.useCallback)((e,n)=>{n.stopPropagation();const t=n.currentTarget.getBoundingClientRect();he(e,t.left,t.bottom+4)},[he]);(0,a.useEffect)(()=>{if(!Z)return;const e=e=>{const n=e.target;n.closest(`.${N.contextMenu}`)||n.closest(`.${N.moreButton}`)||pe()},n=e=>{"Escape"===e.key&&pe()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[Z,pe]);const xe=(0,a.useCallback)(e=>{const n=m(t,e);ne.setExpandedIds([...new Set([...ne.expandedIds,...n])]),requestAnimationFrame(()=>{ne.scrollToNode(e)})},[ne,t]);(0,a.useImperativeHandle)(n,()=>({expandAll:ne.expandAll,collapseAll:ne.collapseAll,expandToDepth:ne.expandToDepth,getExpandedIds:()=>ne.expandedIds,getSelectedNode:()=>{if(!_)return;const e=l(t,_);return e?.target},scrollToNode:xe,locateNode:e=>{const n=[...t];for(;n.length>0;){const r=n.shift();if(r){if(e(r)){const e=l(t,r.id);return e&&ne.setExpandedIds([...new Set([...ne.expandedIds,...e.ancestorIds])]),K(r.id),requestAnimationFrame(()=>{ne.scrollToNode(r.id)}),r}r.children?.length&&n.push(...r.children)}}}}),[ne,xe,_,t]);const me=(0,a.useMemo)(()=>({...O,...void 0!==q?{maxHeight:q}:{}}),[O,q]),Ie=[N.root,"default"!==R?`pde-tree-variant-${R}`:"",k].filter(Boolean).join(" ");return(0,D.jsxs)("div",{ref:z,className:Ie,style:me,"data-size":A,children:[I&&(0,D.jsx)("div",{className:N.toolbar,children:I}),s&&(0,D.jsxs)("div",{className:N.searchRow,children:[(0,D.jsxs)("div",{className:N.searchInputWrap,children:[(0,D.jsx)("span",{className:N.searchIcon,children:(0,D.jsx)(M,{})}),(0,D.jsx)("input",{className:N.searchInput,type:"search",placeholder:c,value:te.query,onChange:e=>oe(e.target.value),"aria-label":"Search tree"})]}),v,h&&(0,D.jsx)("button",{type:"button",className:N.iconButton,onClick:ne.isAllExpanded?ne.collapseAll:ne.expandAll,title:ne.isAllExpanded?"Collapse all":"Expand all","aria-label":ne.isAllExpanded?"Collapse all":"Expand all",children:ne.isAllExpanded?(0,D.jsx)(C.MdUnfoldLess,{size:16,"aria-hidden":"true"}):(0,D.jsx)(C.MdOutlineUnfoldMore,{size:16,"aria-hidden":"true"})}),f&&(0,D.jsx)("button",{type:"button",className:N.iconButton,onClick:x,title:"Refresh","aria-label":"Refresh",children:(0,D.jsx)(b.LuRefreshCw,{size:14,"aria-hidden":"true"})})]}),(0,D.jsx)("div",{ref:ee,className:N.treeContainer,role:"tree","aria-label":"Tree navigation",children:0===te.filteredNodes.length?(0,D.jsx)("div",{className:N.emptyState,children:te.isSearching?"No matching results":"No items"}):te.filteredNodes.map(e=>(0,D.jsx)(P,{node:e,depth:0,expandedIds:re,selectedId:_,isExpanded:re.includes(e.id),isSelected:_===e.id,onToggle:ne.toggleNode,onSelect:de,onNodeRef:ne.setNodeElementRef,searchQuery:te.deferredQuery,showIndentGuides:T,renderIcon:S,renderLabel:y,renderSuffix:E,renderNode:j,draggable:G,dragState:Y,canDragNode:ae(e),canDragNodeFn:ae,onDragStart:ie,onDragOver:le,onDragLeave:se,onDrop:ce,onDragEnd:ue,showContextMenuButton:Boolean(U),activeMenuNodeId:Z?.node.id??null,onContextMenu:fe,onMoreClick:ge},e.id))}),Z&&(0,D.jsx)(w,{state:Z,onClose:pe})]})});
|