elseware-docs-engine 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -35,6 +35,8 @@ interface DocsEngineProps {
35
35
  }
36
36
  declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
37
37
 
38
+ declare function useCurrentDocsSection(): DocsCategory | undefined;
39
+
38
40
  interface UseCurrentPageProps {
39
41
  debug?: boolean;
40
42
  }
@@ -42,6 +44,8 @@ declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | nul
42
44
 
43
45
  declare function useDocs(): DocsContextType;
44
46
 
47
+ declare function useScopedSidebar(): elseware_ui.MenuNode[];
48
+
45
49
  declare function useSidebar(): elseware_ui.MenuNode[];
46
50
 
47
51
  interface GenerateDocsRoutesProps {
@@ -64,4 +68,4 @@ declare function normalizeRoutePath(path: string): string;
64
68
 
65
69
  declare function generateSidebar(docs: DocsCategory[], basePath: string): MenuNode[];
66
70
 
67
- export { type DocsCategory, DocsContext, type DocsContextType, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, generateSidebar, isPage, normalizePath, normalizeRoutePath, resolveDocs, useCurrentPage, useDocs, useSidebar };
71
+ export { type DocsCategory, DocsContext, type DocsContextType, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, generateSidebar, isPage, normalizePath, normalizeRoutePath, resolveDocs, useCurrentDocsSection, useCurrentPage, useDocs, useScopedSidebar, useSidebar };
package/dist/index.d.ts CHANGED
@@ -35,6 +35,8 @@ interface DocsEngineProps {
35
35
  }
36
36
  declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
37
37
 
38
+ declare function useCurrentDocsSection(): DocsCategory | undefined;
39
+
38
40
  interface UseCurrentPageProps {
39
41
  debug?: boolean;
40
42
  }
@@ -42,6 +44,8 @@ declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | nul
42
44
 
43
45
  declare function useDocs(): DocsContextType;
44
46
 
47
+ declare function useScopedSidebar(): elseware_ui.MenuNode[];
48
+
45
49
  declare function useSidebar(): elseware_ui.MenuNode[];
46
50
 
47
51
  interface GenerateDocsRoutesProps {
@@ -64,4 +68,4 @@ declare function normalizeRoutePath(path: string): string;
64
68
 
65
69
  declare function generateSidebar(docs: DocsCategory[], basePath: string): MenuNode[];
66
70
 
67
- export { type DocsCategory, DocsContext, type DocsContextType, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, generateSidebar, isPage, normalizePath, normalizeRoutePath, resolveDocs, useCurrentPage, useDocs, useSidebar };
71
+ export { type DocsCategory, DocsContext, type DocsContextType, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, generateSidebar, isPage, normalizePath, normalizeRoutePath, resolveDocs, useCurrentDocsSection, useCurrentPage, useDocs, useScopedSidebar, useSidebar };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';require('elseware-ui/styles.css');var elsewareUi=require('elseware-ui'),jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactRouterDom=require('react-router-dom');function b({content:e}){return jsxRuntime.jsx(elsewareUi.DocumentationPanel,{value:e})}var w=b;var s=react.createContext(void 0);function v({docs:e,basePath:t,children:r}){return jsxRuntime.jsx(s.Provider,{value:{docs:e,basePath:t},children:r})}var g=v;function k({docs:e,basePath:t="/",children:r}){let o=t.startsWith("/")?t:`/${t}`;return jsxRuntime.jsx(g,{docs:e,basePath:o,children:r})}var D=k;function c(){let e=react.useContext(s);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function n(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function a(e){return "content"in e}function d(e,t,r=""){let o=n(t);for(let i of e){let l=n(`${r}/${i.path}`);if(a(i)){if(l===o)return i}else {let p=d(i.children,t,l);if(p)return p}}return null}function R(e,t=""){let r=[];return e.forEach(o=>{let i=n(`${t}/${o.path}`);if(a(o)){r.push({...o,id:i.replace(/\//g,"-").replace(/^-/,""),fullPath:i});return}r.push(...R(o.children,i));}),r}function S(e,t=""){for(let r of e){let o=n(`${t}/${r.path}`);if(a(r))return o;let i=S(r.children,o);if(i)return i}return null}function m(e,t,r=""){return e.map(o=>{let i=n(`${r}/${o.path}`);return a(o)?{type:"item",name:o.title,to:n(`${t}/${i}`)}:{type:"group",name:o.title,items:m(o.children,t,i)}})}function f(e,t){return m(e,t)}function ne({debug:e=false}={}){let{docs:t,basePath:r}=c(),o=reactRouterDom.useLocation(),i=n(o.pathname.replace(new RegExp(`^${r}`),""));return e&&(console.log("location.pathname",o.pathname),console.log("basePath",r),console.log("pagePath",i)),d(t,i)}function de(){let{docs:e,basePath:t}=c();return f(e,t)}function ge({basePath:e="/docs",element:t}){return [{path:`${h(e)}/*`,element:t}]}
2
- exports.DocsContext=s;exports.DocsEngine=D;exports.DocsPageRenderer=w;exports.findFirstPage=S;exports.findPageByPath=d;exports.generateDocsRoutes=ge;exports.generateSidebar=f;exports.isPage=a;exports.normalizePath=n;exports.normalizeRoutePath=h;exports.resolveDocs=R;exports.useCurrentPage=ne;exports.useDocs=c;exports.useSidebar=de;//# sourceMappingURL=index.js.map
1
+ 'use strict';require('elseware-ui/styles.css');var elsewareUi=require('elseware-ui'),jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactRouterDom=require('react-router-dom');function w({content:e}){return jsxRuntime.jsx(elsewareUi.DocumentationPanel,{value:e})}var y=w;var c=react.createContext(void 0);function P({docs:e,basePath:t,children:o}){return jsxRuntime.jsx(c.Provider,{value:{docs:e,basePath:t},children:o})}var g=P;function k({docs:e,basePath:t="/",children:o}){let r=t.startsWith("/")?t:`/${t}`;return jsxRuntime.jsx(g,{docs:e,basePath:r,children:o})}var z=k;function a(){let e=react.useContext(c);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function h(){let{docs:e}=a(),t=reactRouterDom.useLocation();return e.find(o=>t.pathname.startsWith(o.path))}function n(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function f(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function s(e){return "content"in e}function l(e,t,o=""){let r=n(t);for(let i of e){let p=n(`${o}/${i.path}`);if(s(i)){if(p===r)return i}else {let m=l(i.children,t,p);if(m)return m}}return null}function N(e,t=""){let o=[];return e.forEach(r=>{let i=n(`${t}/${r.path}`);if(s(r)){o.push({...r,id:i.replace(/\//g,"-").replace(/^-/,""),fullPath:i});return}o.push(...N(r.children,i));}),o}function $(e,t=""){for(let o of e){let r=n(`${t}/${o.path}`);if(s(o))return r;let i=$(o.children,r);if(i)return i}return null}function u(e,t,o=""){return e.map(r=>{let i=n(`${o}/${r.path}`);return s(r)?{type:"item",name:r.title,to:n(`${t}/${i}`)}:{type:"group",name:r.title,items:u(r.children,t,i)}})}function d(e,t){return u(e,t)}function le({debug:e=false}={}){let{docs:t,basePath:o}=a(),r=reactRouterDom.useLocation(),i=n(r.pathname.replace(new RegExp(`^${o}`),""));return e&&(console.log("location.pathname",r.pathname),console.log("basePath",o),console.log("pagePath",i)),l(t,i)}function he(){let e=h();return e?d([e],"/"):[]}function we(){let{docs:e,basePath:t}=a();return d(e,t)}function ve({basePath:e="/docs",element:t}){return [{path:`${f(e)}/*`,element:t}]}
2
+ exports.DocsContext=c;exports.DocsEngine=z;exports.DocsPageRenderer=y;exports.findFirstPage=$;exports.findPageByPath=l;exports.generateDocsRoutes=ve;exports.generateSidebar=d;exports.isPage=s;exports.normalizePath=n;exports.normalizeRoutePath=f;exports.resolveDocs=N;exports.useCurrentDocsSection=h;exports.useCurrentPage=le;exports.useDocs=a;exports.useScopedSidebar=he;exports.useSidebar=we;//# 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/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","normalizePath","path","normalizeRoutePath","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","useCurrentPage","debug","location","useLocation","pagePath","useSidebar","generateDocsRoutes","element"],"mappings":"+LAQA,SAASA,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAOC,cAAAA,CAACC,6BAAAA,CAAA,CAAmB,KAAA,CAAOF,CAAAA,CAAS,CAC7C,CAEA,IAAOG,CAAAA,CAAQJ,ECLR,IAAMK,CAAAA,CAAcC,mBAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACER,cAAAA,CAACG,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAC3C,SAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOC,CAAAA,CAAQJ,CAAAA,CCRf,SAASK,CAAAA,CAAW,CAAE,IAAA,CAAAJ,CAAAA,CAAM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QAAQ,GAAA,CAAI,mBAAA,CAAqBC,CAAAA,CAAS,QAAQ,CAAA,CAClD,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAY9B,CAAQ,CAAA,CAChC,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAYgC,CAAQ,CAAA,CAAA,CAG3BlB,CAAAA,CAAef,CAAAA,CAAMiC,CAAQ,CACtC,CCvBO,SAASC,EAAAA,EAAa,CAC3B,GAAM,CAAE,IAAA,CAAAlC,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAIM,CAAAA,EAAQ,CAEnC,OAAOqB,CAAAA,CAAgB5B,CAAAA,CAAMC,CAAQ,CACvC,CCGO,SAASkC,EAAAA,CAAmB,CACjC,QAAA,CAAAlC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAmC,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJaxB,CAAAA,CAAmBX,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAAmC,CACF,CACF,CACF","file":"index.js","sourcesContent":["import React from \"react\";\n\nimport { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({\n content,\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;","import { createContext } from \"react\";\n\nimport { 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 React from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: React.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","import React from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = basePath.startsWith(\"/\")\n ? basePath\n : `/${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","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","import { DocsNode, 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 { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, 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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, normalizePath } 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 // Remove docs base path\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\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}","import React from \"react\";\n\nimport { RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.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/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.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","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","doc","normalizePath","path","normalizeRoutePath","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","useCurrentPage","debug","pagePath","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mappings":"+LAQA,SAASA,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAOC,cAAAA,CAACC,6BAAAA,CAAA,CAAmB,KAAA,CAAOF,CAAAA,CAAS,CAC7C,CAEA,IAAOG,CAAAA,CAAQJ,ECLR,IAAMK,CAAAA,CAAcC,mBAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,C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,CAAAuC,CACF,CACF,CACF","file":"index.js","sourcesContent":["import React from \"react\";\n\nimport { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({\n content,\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;","import { createContext } from \"react\";\n\nimport { 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 React from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: React.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","import React from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = basePath.startsWith(\"/\")\n ? basePath\n : `/${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\nexport function useCurrentDocsSection() {\n const { docs } = useDocs();\n\n const location = useLocation();\n\n return docs.find((doc) => location.pathname.startsWith(doc.path));\n}\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","import { DocsNode, 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 { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, 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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, normalizePath } 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 // Remove docs base path\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\n\nexport function useScopedSidebar() {\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], \"/\");\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}","import React from \"react\";\n\nimport { RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.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'elseware-ui/styles.css';import {DocumentationPanel}from'elseware-ui';import {jsx}from'react/jsx-runtime';import {createContext,useContext}from'react';import {useLocation}from'react-router-dom';function b({content:e}){return jsx(DocumentationPanel,{value:e})}var w=b;var s=createContext(void 0);function v({docs:e,basePath:t,children:r}){return jsx(s.Provider,{value:{docs:e,basePath:t},children:r})}var g=v;function k({docs:e,basePath:t="/",children:r}){let o=t.startsWith("/")?t:`/${t}`;return jsx(g,{docs:e,basePath:o,children:r})}var D=k;function c(){let e=useContext(s);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function n(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function a(e){return "content"in e}function d(e,t,r=""){let o=n(t);for(let i of e){let l=n(`${r}/${i.path}`);if(a(i)){if(l===o)return i}else {let p=d(i.children,t,l);if(p)return p}}return null}function R(e,t=""){let r=[];return e.forEach(o=>{let i=n(`${t}/${o.path}`);if(a(o)){r.push({...o,id:i.replace(/\//g,"-").replace(/^-/,""),fullPath:i});return}r.push(...R(o.children,i));}),r}function S(e,t=""){for(let r of e){let o=n(`${t}/${r.path}`);if(a(r))return o;let i=S(r.children,o);if(i)return i}return null}function m(e,t,r=""){return e.map(o=>{let i=n(`${r}/${o.path}`);return a(o)?{type:"item",name:o.title,to:n(`${t}/${i}`)}:{type:"group",name:o.title,items:m(o.children,t,i)}})}function f(e,t){return m(e,t)}function ne({debug:e=false}={}){let{docs:t,basePath:r}=c(),o=useLocation(),i=n(o.pathname.replace(new RegExp(`^${r}`),""));return e&&(console.log("location.pathname",o.pathname),console.log("basePath",r),console.log("pagePath",i)),d(t,i)}function de(){let{docs:e,basePath:t}=c();return f(e,t)}function ge({basePath:e="/docs",element:t}){return [{path:`${h(e)}/*`,element:t}]}
2
- export{s as DocsContext,D as DocsEngine,w as DocsPageRenderer,S as findFirstPage,d as findPageByPath,ge as generateDocsRoutes,f as generateSidebar,a as isPage,n as normalizePath,h as normalizeRoutePath,R as resolveDocs,ne as useCurrentPage,c as useDocs,de as useSidebar};//# sourceMappingURL=index.mjs.map
1
+ import'elseware-ui/styles.css';import {DocumentationPanel}from'elseware-ui';import {jsx}from'react/jsx-runtime';import {createContext,useContext}from'react';import {useLocation}from'react-router-dom';function w({content:e}){return jsx(DocumentationPanel,{value:e})}var y=w;var c=createContext(void 0);function P({docs:e,basePath:t,children:o}){return jsx(c.Provider,{value:{docs:e,basePath:t},children:o})}var g=P;function k({docs:e,basePath:t="/",children:o}){let r=t.startsWith("/")?t:`/${t}`;return jsx(g,{docs:e,basePath:r,children:o})}var z=k;function a(){let e=useContext(c);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function h(){let{docs:e}=a(),t=useLocation();return e.find(o=>t.pathname.startsWith(o.path))}function n(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function f(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function s(e){return "content"in e}function l(e,t,o=""){let r=n(t);for(let i of e){let p=n(`${o}/${i.path}`);if(s(i)){if(p===r)return i}else {let m=l(i.children,t,p);if(m)return m}}return null}function N(e,t=""){let o=[];return e.forEach(r=>{let i=n(`${t}/${r.path}`);if(s(r)){o.push({...r,id:i.replace(/\//g,"-").replace(/^-/,""),fullPath:i});return}o.push(...N(r.children,i));}),o}function $(e,t=""){for(let o of e){let r=n(`${t}/${o.path}`);if(s(o))return r;let i=$(o.children,r);if(i)return i}return null}function u(e,t,o=""){return e.map(r=>{let i=n(`${o}/${r.path}`);return s(r)?{type:"item",name:r.title,to:n(`${t}/${i}`)}:{type:"group",name:r.title,items:u(r.children,t,i)}})}function d(e,t){return u(e,t)}function le({debug:e=false}={}){let{docs:t,basePath:o}=a(),r=useLocation(),i=n(r.pathname.replace(new RegExp(`^${o}`),""));return e&&(console.log("location.pathname",r.pathname),console.log("basePath",o),console.log("pagePath",i)),l(t,i)}function he(){let e=h();return e?d([e],"/"):[]}function we(){let{docs:e,basePath:t}=a();return d(e,t)}function ve({basePath:e="/docs",element:t}){return [{path:`${f(e)}/*`,element:t}]}
2
+ export{c as DocsContext,z as DocsEngine,y as DocsPageRenderer,$ as findFirstPage,l as findPageByPath,ve as generateDocsRoutes,d as generateSidebar,s as isPage,n as normalizePath,f as normalizeRoutePath,N as resolveDocs,h as useCurrentDocsSection,le as useCurrentPage,a as useDocs,he as useScopedSidebar,we 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/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.ts","../src/hooks/useCurrentPage.ts","../src/hooks/useSidebar.ts","../src/router/generateDocsRoutes.tsx"],"names":["DocsPageRenderer","content","jsx","DocumentationPanel","DocsPageRenderer_default","DocsContext","createContext","DocsProvider","docs","basePath","children","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","normalizePath","path","normalizeRoutePath","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","useCurrentPage","debug","location","useLocation","pagePath","useSidebar","generateDocsRoutes","element"],"mappings":"wMAQA,SAASA,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAOC,GAAAA,CAACC,kBAAAA,CAAA,CAAmB,KAAA,CAAOF,CAAAA,CAAS,CAC7C,CAEA,IAAOG,CAAAA,CAAQJ,ECLR,IAAMK,CAAAA,CAAcC,aAAAA,CACzB,MACF,ECCA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACER,GAAAA,CAACG,CAAAA,CAA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AAA,CAAWC,WAAAA,EAAY,CAGvBC,CAAAA,CAAWvB,CAAAA,CACfqB,CAAAA,CAAS,QAAA,CAAS,OAAA,CAAQ,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI9B,CAAQ,CAAA,CAAE,CAAA,CAAG,EAAE,CAC1D,CAAA,CAEA,OAAI6B,CAAAA,GACF,QAAQ,GAAA,CAAI,mBAAA,CAAqBC,CAAAA,CAAS,QAAQ,CAAA,CAClD,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAY9B,CAAQ,CAAA,CAChC,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAYgC,CAAQ,CAAA,CAAA,CAG3BlB,CAAAA,CAAef,CAAAA,CAAMiC,CAAQ,CACtC,CCvBO,SAASC,EAAAA,EAAa,CAC3B,GAAM,CAAE,IAAA,CAAAlC,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAIM,CAAAA,EAAQ,CAEnC,OAAOqB,CAAAA,CAAgB5B,CAAAA,CAAMC,CAAQ,CACvC,CCGO,SAASkC,EAAAA,CAAmB,CACjC,QAAA,CAAAlC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAmC,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJaxB,CAAAA,CAAmBX,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAAmC,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import React from \"react\";\n\nimport { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({\n content,\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;","import { createContext } from \"react\";\n\nimport { 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 React from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: React.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","import React from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = basePath.startsWith(\"/\")\n ? basePath\n : `/${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","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","import { DocsNode, 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 { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, 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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, normalizePath } 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 // Remove docs base path\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\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}","import React from \"react\";\n\nimport { RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.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/engine/DocsEngine.tsx","../src/hooks/useDocs.ts","../src/hooks/useCurrentDocsSection.ts","../src/utils/path.ts","../src/utils/docs.ts","../src/utils/sidebar.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","DocsEngine","normalizedBasePath","DocsEngine_default","useDocs","context","useContext","useCurrentDocsSection","location","useLocation","doc","normalizePath","path","normalizeRoutePath","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","mapNodes","fullPath","generateSidebar","useCurrentPage","debug","pagePath","useScopedSidebar","section","useSidebar","generateDocsRoutes","element"],"mappings":"wMAQA,SAASA,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAOC,GAAAA,CAACC,kBAAAA,C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,CACvC,CCGO,SAASsC,EAAAA,CAAmB,CACjC,SAAAtC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAuC,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJaxB,CAAAA,CAAmBf,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAAuC,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import React from \"react\";\n\nimport { DocumentationPanel } from \"elseware-ui\";\n\ninterface DocsPageRendererProps {\n content: string;\n}\n\nfunction DocsPageRenderer({\n content,\n}: DocsPageRendererProps) {\n return <DocumentationPanel value={content} />;\n}\n\nexport default DocsPageRenderer;","import { createContext } from \"react\";\n\nimport { 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 React from \"react\";\n\nimport { DocsContext } from \"./DocsContext\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsProviderProps {\n docs: DocsCategory[];\n basePath: string;\n children: React.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","import React from \"react\";\n\nimport DocsProvider from \"../context/DocsProvider\";\n\nimport { DocsCategory } from \"../types\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/\", children }: DocsEngineProps) {\n const normalizedBasePath = basePath.startsWith(\"/\")\n ? basePath\n : `/${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\nexport function useCurrentDocsSection() {\n const { docs } = useDocs();\n\n const location = useLocation();\n\n return docs.find((doc) => location.pathname.startsWith(doc.path));\n}\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","import { DocsNode, 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 { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, 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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath, normalizePath } 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 // Remove docs base path\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n console.log(\"basePath\", basePath);\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { generateSidebar } from \"../utils\";\n\nimport { useCurrentDocsSection } from \"./useCurrentDocsSection\";\n\nexport function useScopedSidebar() {\n const section = useCurrentDocsSection();\n\n if (!section) {\n return [];\n }\n\n return generateSidebar([section], \"/\");\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}","import React from \"react\";\n\nimport { RouteObject } from \"react-router-dom\";\n\nimport { normalizeRoutePath } from \"../utils\";\n\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elseware-docs-engine",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "description": "React documentation engine by elseware Technology",
6
6
  "license": "MIT",