elseware-docs-engine 1.3.1 → 1.3.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/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var elsewareUi=require('elseware-ui'),jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactRouterDom=require('react-router-dom');function y({content:r}){return jsxRuntime.jsx(elsewareUi.DocumentationPanel,{value:r})}var k=y;var c=react.createContext(void 0);function _({docs:r,basePath:o,children:e}){return jsxRuntime.jsx(c.Provider,{value:{docs:r,basePath:o},children:e})}var m=_;function i(r){return "/"+r.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(r){return r.replace(/^\/+/,"").replace(/\/+$/,"")}function p(r,o){let e=i(r),t=i(o);return t==="/"||e===t||e.startsWith(`${t}/`)}function g(r,o){let e=i(r),t=i(o);return p(e,t)?t==="/"?e:i(e.slice(t.length)):null}function n(r){return "content"in r}function s(r,o,e=""){let t=i(o);for(let a of r){let w=i(`${e}/${a.path}`);if(n(a)){if(w===t)return a}else {let l=s(a.children,o,w);if(l)return l}}return null}function P(r,o=""){let e=[];return r.forEach(t=>{let a=i(`${o}/${t.path}`);if(n(t)){e.push({...t,id:a.replace(/\//g,"-").replace(/^-/,""),fullPath:a});return}e.push(...P(t.children,a));}),e}function B(r,o=""){for(let e of r){let t=i(`${o}/${e.path}`);if(n(e))return t;let a=B(e.children,t);if(a)return a}return null}function x(r,o,e=""){return r.map(t=>{let a=i(`${e}/${t.path}`);return n(t)?{type:"item",name:t.title,to:i(`${o}/${a}`)}:{type:"group",name:t.title,items:x(t.children,o,a)}})}function b(r,o){return x(r,o)}function Y({docs:r,basePath:o="/",children:e}){let t=i(o);return jsxRuntime.jsx(m,{docs:r,basePath:t,children:e})}var j=Y;function d(){let r=react.useContext(c);if(!r)throw new Error("useDocs must be used within DocsProvider");return r}function u(){let{docs:r,basePath:o}=d(),e=reactRouterDom.useLocation(),t=g(e.pathname,o);if(t)return r.find(a=>p(t,a.path))}function xr({debug:r=false}={}){let{docs:o,basePath:e}=d(),t=reactRouterDom.useLocation(),a=g(t.pathname,e);return r&&(console.log("location.pathname",t.pathname),console.log("basePath",e),console.log("pagePath",a)),a?s(o,a):null}function fr(){let{basePath:r}=d(),o=u();return o?b([o],r):[]}function Pr(){let{docs:r,basePath:o}=d();return b(r,o)}function Xr({basePath:r="/docs",element:o}){return [{path:`${h(r)}/*`,element:o}]}
2
- exports.DocsContext=c;exports.DocsEngine=j;exports.DocsPageRenderer=k;exports.findFirstPage=B;exports.findPageByPath=s;exports.generateDocsRoutes=Xr;exports.generateSidebar=b;exports.isPage=n;exports.isPathWithin=p;exports.normalizePath=i;exports.normalizeRoutePath=h;exports.resolveDocs=P;exports.stripBasePath=g;exports.useCurrentDocsSection=u;exports.useCurrentPage=xr;exports.useDocs=d;exports.useScopedSidebar=fr;exports.useSidebar=Pr;//# sourceMappingURL=index.js.map
1
+ 'use strict';var elsewareUi=require('elseware-ui'),jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactRouterDom=require('react-router-dom');function f({content:r,height:t="100vh"}){return jsxRuntime.jsx(elsewareUi.DocumentationPanel,{value:r,height:t})}var z=f;var c=react.createContext(void 0);function P({docs:r,basePath:t,children:o}){return jsxRuntime.jsx(c.Provider,{value:{docs:r,basePath:t},children:o})}var m=P;function i(r){return "/"+r.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(r){return r.replace(/^\/+/,"").replace(/\/+$/,"")}function s(r,t){let o=i(r),e=i(t);return e==="/"||o===e||o.startsWith(`${e}/`)}function g(r,t){let o=i(r),e=i(t);return s(o,e)?e==="/"?o:i(o.slice(e.length)):null}function d(r){return "content"in r}function x(r){for(let t of r){if(d(t)&&t.default)return t;if(!d(t)){let o=x(t.children);if(o)return o}}return null}function u(r){for(let t of r){if(d(t))return t;let o=u(t.children);if(o)return o}return null}function w(r,t,o=""){let e=i(t);for(let a of r){let p=i(`${o}/${a.path}`);if(d(a)){if(p===e)return a}else {if(p===e)return x(a.children)??u(a.children);let l=w(a.children,t,p);if(l)return l}}return null}function D(r,t=""){let o=[];return r.forEach(e=>{let a=i(`${t}/${e.path}`);if(d(e)){o.push({...e,id:a.replace(/\//g,"-").replace(/^-/,""),fullPath:a});return}o.push(...D(e.children,a));}),o}function Y(r,t=""){for(let o of r){let e=i(`${t}/${o.path}`);if(d(o))return e;let a=Y(o.children,e);if(a)return a}return null}function v(r,t,o=""){return r.map(e=>{let a=i(`${o}/${e.path}`);return d(e)?{type:"item",name:e.title,to:i(`${t}/${a}`)}:{type:"group",name:e.title,items:v(e.children,t,a)}})}function b(r,t){return r.flatMap(o=>[{type:"title",name:o.title},...v(o.children,t,o.path)])}function j({docs:r,basePath:t="/",children:o}){let e=i(t);return jsxRuntime.jsx(m,{docs:r,basePath:e,children:o})}var X=j;function n(){let r=react.useContext(c);if(!r)throw new Error("useDocs must be used within DocsProvider");return r}function y(){let{docs:r,basePath:t}=n(),o=reactRouterDom.useLocation(),e=g(o.pathname,t);if(e)return r.find(a=>s(e,a.path))}function vr({debug:r=false}={}){let{docs:t,basePath:o}=n(),e=reactRouterDom.useLocation(),a=g(e.pathname,o);return r&&(console.log("location.pathname",e.pathname),console.log("basePath",o),console.log("pagePath",a)),a?w(t,a):null}function _r(){let{basePath:r}=n(),t=y();return t?b([t],r):[]}function Dr(){let{docs:r,basePath:t}=n();return b(r,t)}function Sr({basePath:r="/docs",element:t}){return [{path:`${h(r)}/*`,element:t}]}
2
+ exports.DocsContext=c;exports.DocsEngine=X;exports.DocsPageRenderer=z;exports.findFirstPage=Y;exports.findPageByPath=w;exports.generateDocsRoutes=Sr;exports.generateSidebar=b;exports.isPage=d;exports.isPathWithin=s;exports.normalizePath=i;exports.normalizeRoutePath=h;exports.resolveDocs=D;exports.stripBasePath=g;exports.useCurrentDocsSection=y;exports.useCurrentPage=vr;exports.useDocs=n;exports.useScopedSidebar=_r;exports.useSidebar=Dr;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/docs-page-renderer/DocsPageRenderer.tsx","../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useScopedSidebar.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","normalizePath","path","normalizeRoutePath","isPathWithin","parentPath","normalizedPath","normalizedParent","stripBasePath","normalizedBase","isPage","node","findPageByPath","nodes","targetPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","pagePath","doc","useCurrentPage","debug","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mappings":"6JAMA,SAASA,CAAAA,CAAiB,CAAE,QAAAC,CAAQ,CAAA,CAA0B,CAC5D,OAAOC,eAACC,6BAAAA,CAAA,CAAmB,KAAA,CAAOF,CAAAA,CAAS,CAC7C,CAEA,IAAOG,CAAAA,CAAQJ,MCDFK,CAAAA,CAAcC,mBAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,EAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACER,cAAAA,CAACG,CAAAA,CAAY,QAAA,CAAZ,CAAqB,MAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOC,CAAAA,CAAQJ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AE,IAAA,CAAA3C,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAI8B,CAAAA,GAE3B,OAAOJ,CAAAA,CAAgB3B,CAAAA,CAAMC,CAAQ,CACvC,CCGO,SAAS2C,GAAmB,CACjC,QAAA,CAAA3C,CAAAA,CAAW,OAAA,CACX,QAAA4C,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJavC,CAAAA,CAAmBL,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAA4C,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({ content }: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;\n","import { createContext } from \"react\";\n\nimport { type DocsCategory } from \"../types\";\n\nexport interface DocsContextType {\n docs: DocsCategory[];\n basePath: string;\n}\n\nexport const DocsContext = createContext<DocsContextType | undefined>(\n undefined,\n);\n","import type { ReactNode } from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { type DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: ReactNode;\n}\n\nfunction DocsProvider({ docs, basePath, children }: DocsProviderProps) {\n return (\n <DocsContext.Provider value={{ docs, basePath }}>\n {children}\n </DocsContext.Provider>\n );\n}\n\nexport default DocsProvider;\n","export function normalizePath(path: string): string {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function normalizeRoutePath(path: string): string {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nexport function isPathWithin(path: string, parentPath: string): boolean {\n const normalizedPath = normalizePath(path);\n const normalizedParent = normalizePath(parentPath);\n\n return (\n normalizedParent === \"/\" ||\n normalizedPath === normalizedParent ||\n normalizedPath.startsWith(`${normalizedParent}/`)\n );\n}\n\nexport function stripBasePath(path: string, basePath: string): string | null {\n const normalizedPath = normalizePath(path);\n const normalizedBase = normalizePath(basePath);\n\n if (!isPathWithin(normalizedPath, normalizedBase)) {\n return null;\n }\n\n if (normalizedBase === \"/\") {\n return normalizedPath;\n }\n\n return normalizePath(normalizedPath.slice(normalizedBase.length));\n}\n","import { type DocsNode, type DocsPage } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nexport interface ResolvedDocsPage extends DocsPage {\n id: string;\n fullPath: string;\n}\n\nexport function isPage(node: DocsNode): node is DocsPage {\n return \"content\" in node;\n}\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n const normalizedTarget = normalizePath(targetPath);\n\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n if (currentPath === normalizedTarget) {\n return node;\n }\n } else {\n const result = findPageByPath(node.children, targetPath, currentPath);\n\n if (result) {\n return result;\n }\n }\n }\n\n return null;\n}\n\nexport function resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n pages.push({\n ...node,\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n fullPath: currentPath,\n });\n\n return;\n }\n\n pages.push(...resolveDocs(node.children, currentPath));\n });\n\n return pages;\n}\n\nexport function findFirstPage(\n nodes: DocsNode[],\n parentPath = \"\",\n): string | null {\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return currentPath;\n }\n\n const child = findFirstPage(node.children, currentPath);\n\n if (child) {\n return child;\n }\n }\n\n return null;\n}\n","import { type MenuNode } from \"elseware-ui\";\n\nimport { type DocsCategory, type DocsNode } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nimport { isPage } from \"./docs\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n name: node.title,\n items: mapNodes(node.children, basePath, fullPath),\n };\n });\n}\n\nexport function generateSidebar(\n docs: DocsCategory[],\n basePath: string,\n): MenuNode[] {\n return mapNodes(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { type DocsCategory } from \"../types\";\nimport { normalizePath } from \"../utils\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = normalizePath(basePath);\n\n return (\n <DocsProvider docs={docs} basePath={normalizedBasePath}>\n {children}\n </DocsProvider>\n );\n}\n\nexport default DocsEngine;\n","import { useContext } from \"react\";\n\nimport { DocsContext } from \"../context\";\n\nexport function useDocs() {\n const context = useContext(DocsContext);\n\n if (!context) {\n throw new Error(\"useDocs must be used within DocsProvider\");\n }\n\n return context;\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { isPathWithin, stripBasePath } from \"../utils\";\n\nexport function useCurrentDocsSection() {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (!pagePath) {\n return undefined;\n }\n\n return docs.find((doc) => isPathWithin(pagePath, doc.path));\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, stripBasePath } from \"../utils\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n if (!pagePath) {\n return null;\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\nimport { useDocs } from \"./useDocs\";\n\nexport function useScopedSidebar() {\n const { basePath } = useDocs();\n\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], basePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useDocs } from \"./useDocs\";\n\nexport function useSidebar() {\n const { docs, basePath } = useDocs();\n\n return generateSidebar(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport { type RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n const normalizedBase = normalizeRoutePath(basePath);\n\n return [\n {\n path: `${normalizedBase}/*`,\n element,\n },\n ];\n}\n"]}
1
+ {"version":3,"sources":["../src/components/docs-page-renderer/DocsPageRenderer.tsx","../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useScopedSidebar.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","height","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","normalizePath","path","normalizeRoutePath","isPathWithin","parentPath","normalizedPath","normalizedParent","stripBasePath","normalizedBase","isPage","node","findMarkedDefaultPage","nodes","child","findFirstPageNode","findPageByPath","targetPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","mapNodes","fullPath","generateSidebar","doc","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","pagePath","useCurrentPage","debug","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mappings":"6JAQA,SAASA,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CAAAA,CACA,OAAAC,CAAAA,CAAS,OACX,EAA0B,CACxB,OAAOC,eAACC,6BAAAA,CAAA,CAAmB,KAAA,CAAOH,CAAAA,CAAS,OAAQC,CAAAA,CAAQ,CAC7D,CAEA,IAAOG,CAAAA,CAAQL,MCNFM,CAAAA,CAAcC,mBAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,KAAAC,CAAAA,CAAM,QAAA,CAAAC,EAAU,QAAA,CAAAC,CAAS,EAAsB,CACrE,OACER,cAAAA,CAACG,CAAAA,CAAY,SAAZ,CAAqB,KAAA,CAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,SAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOC,EAAQJ,CAAAA,CCpBR,SAASK,EAAcC,CAAAA,CAAsB,CAClD,OAAO,GAAA,CAAMA,CAAAA,CAAK,QAAQ,MAAA,CAAQ,GAAG,EAAE,OAAA,CAAQ,UAAA,CAAY,EAAE,CAC/D,CAEO,SAASC,CAAAA,CAAmBD,EAAsB,CACvD,OAAOA,EAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,OAAA,CAAQ,MAAA,CAAQ,EAAE,CACpD,CAEO,SAASE,EAAaF,CAAAA,CAAcG,CAAAA,CAA6B,CACtE,IAAMC,CAAAA,CAAiBL,CAAAA,CAAcC,CAAI,EACnCK,CAAAA,CAAmBN,CAAAA,CAAcI,CAAU,CAAA,CAEjD,OAC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Ef,CAAAA,CAAgB,CAACe,CAAO,CAAA,CAAG3C,CAAQ,EAHjC,EAIX,CCXO,SAAS4C,IAAa,CAC3B,GAAM,CAAE,IAAA,CAAA7C,CAAAA,CAAM,SAAAC,CAAS,CAAA,CAAIiC,CAAAA,EAAQ,CAEnC,OAAOL,CAAAA,CAAgB7B,CAAAA,CAAMC,CAAQ,CACvC,CCGO,SAAS6C,EAAAA,CAAmB,CACjC,SAAA7C,CAAAA,CAAW,OAAA,CACX,QAAA8C,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJazC,EAAmBL,CAAQ,CAIvB,KACvB,OAAA,CAAA8C,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n /** Set to 100% when a layout provides a bounded content area. */\n height?: number | string;\n}\n\nfunction DocsPageRenderer({\n content,\n height = \"100vh\",\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} height={height} />;\n}\n\nexport default DocsPageRenderer;\n","import { createContext } from \"react\";\n\nimport { type DocsCategory } from \"../types\";\n\nexport interface DocsContextType {\n docs: DocsCategory[];\n basePath: string;\n}\n\nexport const DocsContext = createContext<DocsContextType | undefined>(\n undefined,\n);\n","import type { ReactNode } from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { type DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: ReactNode;\n}\n\nfunction DocsProvider({ docs, basePath, children }: DocsProviderProps) {\n return (\n <DocsContext.Provider value={{ docs, basePath }}>\n {children}\n </DocsContext.Provider>\n );\n}\n\nexport default DocsProvider;\n","export function normalizePath(path: string): string {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function normalizeRoutePath(path: string): string {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nexport function isPathWithin(path: string, parentPath: string): boolean {\n const normalizedPath = normalizePath(path);\n const normalizedParent = normalizePath(parentPath);\n\n return (\n normalizedParent === \"/\" ||\n normalizedPath === normalizedParent ||\n normalizedPath.startsWith(`${normalizedParent}/`)\n );\n}\n\nexport function stripBasePath(path: string, basePath: string): string | null {\n const normalizedPath = normalizePath(path);\n const normalizedBase = normalizePath(basePath);\n\n if (!isPathWithin(normalizedPath, normalizedBase)) {\n return null;\n }\n\n if (normalizedBase === \"/\") {\n return normalizedPath;\n }\n\n return normalizePath(normalizedPath.slice(normalizedBase.length));\n}\n","import { type DocsNode, type DocsPage } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nexport interface ResolvedDocsPage extends DocsPage {\n id: string;\n fullPath: string;\n}\n\nexport function isPage(node: DocsNode): node is DocsPage {\n return \"content\" in node;\n}\n\nfunction findMarkedDefaultPage(nodes: DocsNode[]): DocsPage | null {\n for (const node of nodes) {\n if (isPage(node) && node.default) return node;\n if (!isPage(node)) {\n const child = findMarkedDefaultPage(node.children);\n if (child) return child;\n }\n }\n\n return null;\n}\n\nfunction findFirstPageNode(nodes: DocsNode[]): DocsPage | null {\n for (const node of nodes) {\n if (isPage(node)) return node;\n const child = findFirstPageNode(node.children);\n if (child) return child;\n }\n\n return null;\n}\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n const normalizedTarget = normalizePath(targetPath);\n\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n if (currentPath === normalizedTarget) {\n return node;\n }\n } else {\n if (currentPath === normalizedTarget) {\n return (\n findMarkedDefaultPage(node.children) ??\n findFirstPageNode(node.children)\n );\n }\n\n const result = findPageByPath(node.children, targetPath, currentPath);\n\n if (result) {\n return result;\n }\n }\n }\n\n return null;\n}\n\nexport function resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n pages.push({\n ...node,\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n fullPath: currentPath,\n });\n\n return;\n }\n\n pages.push(...resolveDocs(node.children, currentPath));\n });\n\n return pages;\n}\n\nexport function findFirstPage(\n nodes: DocsNode[],\n parentPath = \"\",\n): string | null {\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return currentPath;\n }\n\n const child = findFirstPage(node.children, currentPath);\n\n if (child) {\n return child;\n }\n }\n\n return null;\n}\n","import { type MenuNode } from \"elseware-ui\";\n\nimport { type DocsCategory, type DocsNode } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nimport { isPage } from \"./docs\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n name: node.title,\n items: mapNodes(node.children, basePath, fullPath),\n };\n });\n}\n\nexport function generateSidebar(\n docs: DocsCategory[],\n basePath: string,\n): MenuNode[] {\n return docs.flatMap((doc): MenuNode[] => [\n { type: \"title\", name: doc.title },\n ...mapNodes(doc.children, basePath, doc.path),\n ]);\n}\n","import type { ReactNode } from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { type DocsCategory } from \"../types\";\nimport { normalizePath } from \"../utils\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = normalizePath(basePath);\n\n return (\n <DocsProvider docs={docs} basePath={normalizedBasePath}>\n {children}\n </DocsProvider>\n );\n}\n\nexport default DocsEngine;\n","import { useContext } from \"react\";\n\nimport { DocsContext } from \"../context\";\n\nexport function useDocs() {\n const context = useContext(DocsContext);\n\n if (!context) {\n throw new Error(\"useDocs must be used within DocsProvider\");\n }\n\n return context;\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { isPathWithin, stripBasePath } from \"../utils\";\n\nexport function useCurrentDocsSection() {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (!pagePath) {\n return undefined;\n }\n\n return docs.find((doc) => isPathWithin(pagePath, doc.path));\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, stripBasePath } from \"../utils\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n if (!pagePath) {\n return null;\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\nimport { useDocs } from \"./useDocs\";\n\nexport function useScopedSidebar() {\n const { basePath } = useDocs();\n\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], basePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useDocs } from \"./useDocs\";\n\nexport function useSidebar() {\n const { docs, basePath } = useDocs();\n\n return generateSidebar(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport { type RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n const normalizedBase = normalizeRoutePath(basePath);\n\n return [\n {\n path: `${normalizedBase}/*`,\n element,\n },\n ];\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import {DocumentationPanel}from'elseware-ui';import {jsx}from'react/jsx-runtime';import {createContext,useContext}from'react';import {useLocation}from'react-router-dom';function y({content:r}){return jsx(DocumentationPanel,{value:r})}var k=y;var c=createContext(void 0);function _({docs:r,basePath:o,children:e}){return jsx(c.Provider,{value:{docs:r,basePath:o},children:e})}var m=_;function i(r){return "/"+r.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(r){return r.replace(/^\/+/,"").replace(/\/+$/,"")}function p(r,o){let e=i(r),t=i(o);return t==="/"||e===t||e.startsWith(`${t}/`)}function g(r,o){let e=i(r),t=i(o);return p(e,t)?t==="/"?e:i(e.slice(t.length)):null}function n(r){return "content"in r}function s(r,o,e=""){let t=i(o);for(let a of r){let w=i(`${e}/${a.path}`);if(n(a)){if(w===t)return a}else {let l=s(a.children,o,w);if(l)return l}}return null}function P(r,o=""){let e=[];return r.forEach(t=>{let a=i(`${o}/${t.path}`);if(n(t)){e.push({...t,id:a.replace(/\//g,"-").replace(/^-/,""),fullPath:a});return}e.push(...P(t.children,a));}),e}function B(r,o=""){for(let e of r){let t=i(`${o}/${e.path}`);if(n(e))return t;let a=B(e.children,t);if(a)return a}return null}function x(r,o,e=""){return r.map(t=>{let a=i(`${e}/${t.path}`);return n(t)?{type:"item",name:t.title,to:i(`${o}/${a}`)}:{type:"group",name:t.title,items:x(t.children,o,a)}})}function b(r,o){return x(r,o)}function Y({docs:r,basePath:o="/",children:e}){let t=i(o);return jsx(m,{docs:r,basePath:t,children:e})}var j=Y;function d(){let r=useContext(c);if(!r)throw new Error("useDocs must be used within DocsProvider");return r}function u(){let{docs:r,basePath:o}=d(),e=useLocation(),t=g(e.pathname,o);if(t)return r.find(a=>p(t,a.path))}function xr({debug:r=false}={}){let{docs:o,basePath:e}=d(),t=useLocation(),a=g(t.pathname,e);return r&&(console.log("location.pathname",t.pathname),console.log("basePath",e),console.log("pagePath",a)),a?s(o,a):null}function fr(){let{basePath:r}=d(),o=u();return o?b([o],r):[]}function Pr(){let{docs:r,basePath:o}=d();return b(r,o)}function Xr({basePath:r="/docs",element:o}){return [{path:`${h(r)}/*`,element:o}]}
2
- export{c as DocsContext,j as DocsEngine,k as DocsPageRenderer,B as findFirstPage,s as findPageByPath,Xr as generateDocsRoutes,b as generateSidebar,n as isPage,p as isPathWithin,i as normalizePath,h as normalizeRoutePath,P as resolveDocs,g as stripBasePath,u as useCurrentDocsSection,xr as useCurrentPage,d as useDocs,fr as useScopedSidebar,Pr as useSidebar};//# sourceMappingURL=index.mjs.map
1
+ import {DocumentationPanel}from'elseware-ui';import {jsx}from'react/jsx-runtime';import {createContext,useContext}from'react';import {useLocation}from'react-router-dom';function f({content:r,height:t="100vh"}){return jsx(DocumentationPanel,{value:r,height:t})}var z=f;var c=createContext(void 0);function P({docs:r,basePath:t,children:o}){return jsx(c.Provider,{value:{docs:r,basePath:t},children:o})}var m=P;function i(r){return "/"+r.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(r){return r.replace(/^\/+/,"").replace(/\/+$/,"")}function s(r,t){let o=i(r),e=i(t);return e==="/"||o===e||o.startsWith(`${e}/`)}function g(r,t){let o=i(r),e=i(t);return s(o,e)?e==="/"?o:i(o.slice(e.length)):null}function d(r){return "content"in r}function x(r){for(let t of r){if(d(t)&&t.default)return t;if(!d(t)){let o=x(t.children);if(o)return o}}return null}function u(r){for(let t of r){if(d(t))return t;let o=u(t.children);if(o)return o}return null}function w(r,t,o=""){let e=i(t);for(let a of r){let p=i(`${o}/${a.path}`);if(d(a)){if(p===e)return a}else {if(p===e)return x(a.children)??u(a.children);let l=w(a.children,t,p);if(l)return l}}return null}function D(r,t=""){let o=[];return r.forEach(e=>{let a=i(`${t}/${e.path}`);if(d(e)){o.push({...e,id:a.replace(/\//g,"-").replace(/^-/,""),fullPath:a});return}o.push(...D(e.children,a));}),o}function Y(r,t=""){for(let o of r){let e=i(`${t}/${o.path}`);if(d(o))return e;let a=Y(o.children,e);if(a)return a}return null}function v(r,t,o=""){return r.map(e=>{let a=i(`${o}/${e.path}`);return d(e)?{type:"item",name:e.title,to:i(`${t}/${a}`)}:{type:"group",name:e.title,items:v(e.children,t,a)}})}function b(r,t){return r.flatMap(o=>[{type:"title",name:o.title},...v(o.children,t,o.path)])}function j({docs:r,basePath:t="/",children:o}){let e=i(t);return jsx(m,{docs:r,basePath:e,children:o})}var X=j;function n(){let r=useContext(c);if(!r)throw new Error("useDocs must be used within DocsProvider");return r}function y(){let{docs:r,basePath:t}=n(),o=useLocation(),e=g(o.pathname,t);if(e)return r.find(a=>s(e,a.path))}function vr({debug:r=false}={}){let{docs:t,basePath:o}=n(),e=useLocation(),a=g(e.pathname,o);return r&&(console.log("location.pathname",e.pathname),console.log("basePath",o),console.log("pagePath",a)),a?w(t,a):null}function _r(){let{basePath:r}=n(),t=y();return t?b([t],r):[]}function Dr(){let{docs:r,basePath:t}=n();return b(r,t)}function Sr({basePath:r="/docs",element:t}){return [{path:`${h(r)}/*`,element:t}]}
2
+ export{c as DocsContext,X as DocsEngine,z as DocsPageRenderer,Y as findFirstPage,w as findPageByPath,Sr as generateDocsRoutes,b as generateSidebar,d as isPage,s as isPathWithin,i as normalizePath,h as normalizeRoutePath,D as resolveDocs,g as stripBasePath,y as useCurrentDocsSection,vr as useCurrentPage,n as useDocs,_r as useScopedSidebar,Dr as useSidebar};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/docs-page-renderer/DocsPageRenderer.tsx","../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useScopedSidebar.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","normalizePath","path","normalizeRoutePath","isPathWithin","parentPath","normalizedPath","normalizedParent","stripBasePath","normalizedBase","isPage","node","findPageByPath","nodes","targetPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","pagePath","doc","useCurrentPage","debug","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mappings":"yKAMA,SAASA,CAAAA,CAAiB,CAAE,QAAAC,CAAQ,CAAA,CAA0B,CAC5D,OAAOC,IAACC,kBAAAA,CAAA,CAAmB,KAAA,CAAOF,CAAAA,CAAS,CAC7C,CAEA,IAAOG,CAAAA,CAAQJ,MCDFK,CAAAA,CAAcC,aAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,EAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACER,GAAAA,CAACG,CAAAA,CAAY,QAAA,CAAZ,CAAqB,MAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOC,CAAAA,CAAQJ,CAAAA,CCpBR,SAASK,CAAAA,CAAcC,CAAAA,CAAsB,CAClD,OAAO,IAAMA,CAAAA,CAAK,OAAA,CAAQ,MAAA,CAAQ,GAAG,CAAA,CAAE,OAAA,CAAQ,UAAA,CAAY,EAAE,CAC/D,CAEO,SAASC,CAAAA,CAAmBD,CAAAA,CAAsB,CACvD,OAAOA,CAAAA,CAAK,OAAA,CAAQ,MA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AAM,CAAA,EAJavC,CAAAA,CAAmBL,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAA4C,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({ content }: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;\n","import { createContext } from \"react\";\n\nimport { type DocsCategory } from \"../types\";\n\nexport interface DocsContextType {\n docs: DocsCategory[];\n basePath: string;\n}\n\nexport const DocsContext = createContext<DocsContextType | undefined>(\n undefined,\n);\n","import type { ReactNode } from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { type DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: ReactNode;\n}\n\nfunction DocsProvider({ docs, basePath, children }: DocsProviderProps) {\n return (\n <DocsContext.Provider value={{ docs, basePath }}>\n {children}\n </DocsContext.Provider>\n );\n}\n\nexport default DocsProvider;\n","export function normalizePath(path: string): string {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function normalizeRoutePath(path: string): string {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nexport function isPathWithin(path: string, parentPath: string): boolean {\n const normalizedPath = normalizePath(path);\n const normalizedParent = normalizePath(parentPath);\n\n return (\n normalizedParent === \"/\" ||\n normalizedPath === normalizedParent ||\n normalizedPath.startsWith(`${normalizedParent}/`)\n );\n}\n\nexport function stripBasePath(path: string, basePath: string): string | null {\n const normalizedPath = normalizePath(path);\n const normalizedBase = normalizePath(basePath);\n\n if (!isPathWithin(normalizedPath, normalizedBase)) {\n return null;\n }\n\n if (normalizedBase === \"/\") {\n return normalizedPath;\n }\n\n return normalizePath(normalizedPath.slice(normalizedBase.length));\n}\n","import { type DocsNode, type DocsPage } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nexport interface ResolvedDocsPage extends DocsPage {\n id: string;\n fullPath: string;\n}\n\nexport function isPage(node: DocsNode): node is DocsPage {\n return \"content\" in node;\n}\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n const normalizedTarget = normalizePath(targetPath);\n\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n if (currentPath === normalizedTarget) {\n return node;\n }\n } else {\n const result = findPageByPath(node.children, targetPath, currentPath);\n\n if (result) {\n return result;\n }\n }\n }\n\n return null;\n}\n\nexport function resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n pages.push({\n ...node,\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n fullPath: currentPath,\n });\n\n return;\n }\n\n pages.push(...resolveDocs(node.children, currentPath));\n });\n\n return pages;\n}\n\nexport function findFirstPage(\n nodes: DocsNode[],\n parentPath = \"\",\n): string | null {\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return currentPath;\n }\n\n const child = findFirstPage(node.children, currentPath);\n\n if (child) {\n return child;\n }\n }\n\n return null;\n}\n","import { type MenuNode } from \"elseware-ui\";\n\nimport { type DocsCategory, type DocsNode } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nimport { isPage } from \"./docs\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n name: node.title,\n items: mapNodes(node.children, basePath, fullPath),\n };\n });\n}\n\nexport function generateSidebar(\n docs: DocsCategory[],\n basePath: string,\n): MenuNode[] {\n return mapNodes(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { type DocsCategory } from \"../types\";\nimport { normalizePath } from \"../utils\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = normalizePath(basePath);\n\n return (\n <DocsProvider docs={docs} basePath={normalizedBasePath}>\n {children}\n </DocsProvider>\n );\n}\n\nexport default DocsEngine;\n","import { useContext } from \"react\";\n\nimport { DocsContext } from \"../context\";\n\nexport function useDocs() {\n const context = useContext(DocsContext);\n\n if (!context) {\n throw new Error(\"useDocs must be used within DocsProvider\");\n }\n\n return context;\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { isPathWithin, stripBasePath } from \"../utils\";\n\nexport function useCurrentDocsSection() {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (!pagePath) {\n return undefined;\n }\n\n return docs.find((doc) => isPathWithin(pagePath, doc.path));\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, stripBasePath } from \"../utils\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n if (!pagePath) {\n return null;\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\nimport { useDocs } from \"./useDocs\";\n\nexport function useScopedSidebar() {\n const { basePath } = useDocs();\n\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], basePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useDocs } from \"./useDocs\";\n\nexport function useSidebar() {\n const { docs, basePath } = useDocs();\n\n return generateSidebar(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport { type RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n const normalizedBase = normalizeRoutePath(basePath);\n\n return [\n {\n path: `${normalizedBase}/*`,\n element,\n },\n ];\n}\n"]}
1
+ {"version":3,"sources":["../src/components/docs-page-renderer/DocsPageRenderer.tsx","../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useScopedSidebar.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","height","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","normalizePath","path","normalizeRoutePath","isPathWithin","parentPath","normalizedPath","normalizedParent","stripBasePath","normalizedBase","isPage","node","findMarkedDefaultPage","nodes","child","findFirstPageNode","findPageByPath","targetPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","mapNodes","fullPath","generateSidebar","doc","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","pagePath","useCurrentPage","debug","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mapp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AmB,CACjC,SAAA7C,CAAAA,CAAW,OAAA,CACX,QAAA8C,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJazC,EAAmBL,CAAQ,CAIvB,KACvB,OAAA,CAAA8C,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n /** Set to 100% when a layout provides a bounded content area. */\n height?: number | string;\n}\n\nfunction DocsPageRenderer({\n content,\n height = \"100vh\",\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} height={height} />;\n}\n\nexport default DocsPageRenderer;\n","import { createContext } from \"react\";\n\nimport { type DocsCategory } from \"../types\";\n\nexport interface DocsContextType {\n docs: DocsCategory[];\n basePath: string;\n}\n\nexport const DocsContext = createContext<DocsContextType | undefined>(\n undefined,\n);\n","import type { ReactNode } from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { type DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: ReactNode;\n}\n\nfunction DocsProvider({ docs, basePath, children }: DocsProviderProps) {\n return (\n <DocsContext.Provider value={{ docs, basePath }}>\n {children}\n </DocsContext.Provider>\n );\n}\n\nexport default DocsProvider;\n","export function normalizePath(path: string): string {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function normalizeRoutePath(path: string): string {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nexport function isPathWithin(path: string, parentPath: string): boolean {\n const normalizedPath = normalizePath(path);\n const normalizedParent = normalizePath(parentPath);\n\n return (\n normalizedParent === \"/\" ||\n normalizedPath === normalizedParent ||\n normalizedPath.startsWith(`${normalizedParent}/`)\n );\n}\n\nexport function stripBasePath(path: string, basePath: string): string | null {\n const normalizedPath = normalizePath(path);\n const normalizedBase = normalizePath(basePath);\n\n if (!isPathWithin(normalizedPath, normalizedBase)) {\n return null;\n }\n\n if (normalizedBase === \"/\") {\n return normalizedPath;\n }\n\n return normalizePath(normalizedPath.slice(normalizedBase.length));\n}\n","import { type DocsNode, type DocsPage } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nexport interface ResolvedDocsPage extends DocsPage {\n id: string;\n fullPath: string;\n}\n\nexport function isPage(node: DocsNode): node is DocsPage {\n return \"content\" in node;\n}\n\nfunction findMarkedDefaultPage(nodes: DocsNode[]): DocsPage | null {\n for (const node of nodes) {\n if (isPage(node) && node.default) return node;\n if (!isPage(node)) {\n const child = findMarkedDefaultPage(node.children);\n if (child) return child;\n }\n }\n\n return null;\n}\n\nfunction findFirstPageNode(nodes: DocsNode[]): DocsPage | null {\n for (const node of nodes) {\n if (isPage(node)) return node;\n const child = findFirstPageNode(node.children);\n if (child) return child;\n }\n\n return null;\n}\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n const normalizedTarget = normalizePath(targetPath);\n\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n if (currentPath === normalizedTarget) {\n return node;\n }\n } else {\n if (currentPath === normalizedTarget) {\n return (\n findMarkedDefaultPage(node.children) ??\n findFirstPageNode(node.children)\n );\n }\n\n const result = findPageByPath(node.children, targetPath, currentPath);\n\n if (result) {\n return result;\n }\n }\n }\n\n return null;\n}\n\nexport function resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n pages.push({\n ...node,\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n fullPath: currentPath,\n });\n\n return;\n }\n\n pages.push(...resolveDocs(node.children, currentPath));\n });\n\n return pages;\n}\n\nexport function findFirstPage(\n nodes: DocsNode[],\n parentPath = \"\",\n): string | null {\n for (const node of nodes) {\n const currentPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return currentPath;\n }\n\n const child = findFirstPage(node.children, currentPath);\n\n if (child) {\n return child;\n }\n }\n\n return null;\n}\n","import { type MenuNode } from \"elseware-ui\";\n\nimport { type DocsCategory, type DocsNode } from \"../types\";\n\nimport { normalizePath } from \"./path\";\n\nimport { isPage } from \"./docs\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = normalizePath(`${parentPath}/${node.path}`);\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n name: node.title,\n items: mapNodes(node.children, basePath, fullPath),\n };\n });\n}\n\nexport function generateSidebar(\n docs: DocsCategory[],\n basePath: string,\n): MenuNode[] {\n return docs.flatMap((doc): MenuNode[] => [\n { type: \"title\", name: doc.title },\n ...mapNodes(doc.children, basePath, doc.path),\n ]);\n}\n","import type { ReactNode } from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { type DocsCategory } from \"../types\";\nimport { normalizePath } from \"../utils\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = normalizePath(basePath);\n\n return (\n <DocsProvider docs={docs} basePath={normalizedBasePath}>\n {children}\n </DocsProvider>\n );\n}\n\nexport default DocsEngine;\n","import { useContext } from \"react\";\n\nimport { DocsContext } from \"../context\";\n\nexport function useDocs() {\n const context = useContext(DocsContext);\n\n if (!context) {\n throw new Error(\"useDocs must be used within DocsProvider\");\n }\n\n return context;\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { isPathWithin, stripBasePath } from \"../utils\";\n\nexport function useCurrentDocsSection() {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (!pagePath) {\n return undefined;\n }\n\n return docs.find((doc) => isPathWithin(pagePath, doc.path));\n}\n","import { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, stripBasePath } from \"../utils\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n const pagePath = stripBasePath(location.pathname, basePath);\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n if (!pagePath) {\n return null;\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\nimport { useDocs } from \"./useDocs\";\n\nexport function useScopedSidebar() {\n const { basePath } = useDocs();\n\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], basePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useDocs } from \"./useDocs\";\n\nexport function useSidebar() {\n const { docs, basePath } = useDocs();\n\n return generateSidebar(docs, basePath);\n}\n","import type { ReactNode } from \"react\";\n\nimport { type RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n const normalizedBase = normalizeRoutePath(basePath);\n\n return [\n {\n path: `${normalizedBase}/*`,\n element,\n },\n ];\n}\n"]}
@@ -2,6 +2,8 @@ export interface DocsPage {
2
2
  title: string;
3
3
  path: string;
4
4
  content: string;
5
+ /** Render this page when its parent category path is requested. */
6
+ default?: boolean;
5
7
  }
6
8
  export interface DocsCategory {
7
9
  title: string;
@@ -1 +1 @@
1
- {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/types/docs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/types/docs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/utils/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIxD,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,IAAI,QAAQ,CAEvD;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,SAAK,GACd,QAAQ,GAAG,IAAI,CAoBjB;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,SAAK,GACd,gBAAgB,EAAE,CAoBpB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,SAAK,GACd,MAAM,GAAG,IAAI,CAgBf"}
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/utils/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIxD,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,IAAI,QAAQ,CAEvD;AAwBD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,SAAK,GACd,QAAQ,GAAG,IAAI,CA2BjB;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,SAAK,GACd,gBAAgB,EAAE,CAoBpB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,SAAK,GACd,MAAM,GAAG,IAAI,CAgBf"}
@@ -1 +1 @@
1
- {"version":3,"file":"sidebar.d.ts","sourceRoot":"","sources":["../../src/utils/sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,UAAU,CAAC;AA8B5D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,YAAY,EAAE,EACpB,QAAQ,EAAE,MAAM,GACf,QAAQ,EAAE,CAEZ"}
1
+ {"version":3,"file":"sidebar.d.ts","sourceRoot":"","sources":["../../src/utils/sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,UAAU,CAAC;AA8B5D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,YAAY,EAAE,EACpB,QAAQ,EAAE,MAAM,GACf,QAAQ,EAAE,CAKZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elseware-docs-engine",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "private": false,
5
5
  "description": "React documentation engine by elseware Technology",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "react-router-dom": "^6"
41
41
  },
42
42
  "dependencies": {
43
- "elseware-ui": "^3.2.0"
43
+ "elseware-ui": "^3.13.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^24.0.3",
@@ -65,6 +65,7 @@
65
65
  "scripts": {
66
66
  "dev": "vite",
67
67
  "build": "tsup && tsc --project tsconfig.build.json",
68
+ "check:version": "node scripts/check-version-availability.mjs",
68
69
  "clean": "rimraf dist node_modules/.cache",
69
70
  "typecheck": "tsc --noEmit",
70
71
  "lint": "oxlint --deny-warnings",
@@ -76,7 +77,9 @@
76
77
  "full": "npm run lint:fix && npm run format && npm run validate",
77
78
  "prepare": "husky",
78
79
  "prepublishOnly": "npm run validate",
79
- "release": "npm publish --access public"
80
+ "release": "npm publish --access public",
81
+ "deps:local": "npm install --no-save --package-lock=false ../elseware-ui",
82
+ "deps:registry": "npm ci"
80
83
  },
81
84
  "lint-staged": {
82
85
  "*.{js,jsx,ts,tsx,mjs,cjs}": [