elseware-docs-engine 1.1.0 → 1.1.2
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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -34,7 +34,10 @@ interface DocsContextType {
|
|
|
34
34
|
|
|
35
35
|
declare function useDocs(): DocsContextType;
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
interface UseCurrentPageProps {
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | null;
|
|
38
41
|
|
|
39
42
|
declare function useSidebar(): elseware_ui.MenuNode[];
|
|
40
43
|
|
|
@@ -44,12 +47,12 @@ interface GenerateDocsRoutesProps {
|
|
|
44
47
|
}
|
|
45
48
|
declare function generateDocsRoutes({ basePath, element, }: GenerateDocsRoutesProps): RouteObject[];
|
|
46
49
|
|
|
47
|
-
declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPath?: string): DocsPage | null;
|
|
48
50
|
interface ResolvedDocsPage extends DocsPage {
|
|
49
51
|
id: string;
|
|
50
52
|
fullPath: string;
|
|
51
53
|
}
|
|
52
54
|
declare function isPage(node: DocsNode): node is DocsPage;
|
|
55
|
+
declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPath?: string): DocsPage | null;
|
|
53
56
|
declare function resolveDocs(nodes: DocsNode[], parentPath?: string): ResolvedDocsPage[];
|
|
54
57
|
declare function findFirstPage(nodes: DocsNode[], parentPath?: string): string | null;
|
|
55
58
|
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,10 @@ interface DocsContextType {
|
|
|
34
34
|
|
|
35
35
|
declare function useDocs(): DocsContextType;
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
interface UseCurrentPageProps {
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | null;
|
|
38
41
|
|
|
39
42
|
declare function useSidebar(): elseware_ui.MenuNode[];
|
|
40
43
|
|
|
@@ -44,12 +47,12 @@ interface GenerateDocsRoutesProps {
|
|
|
44
47
|
}
|
|
45
48
|
declare function generateDocsRoutes({ basePath, element, }: GenerateDocsRoutesProps): RouteObject[];
|
|
46
49
|
|
|
47
|
-
declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPath?: string): DocsPage | null;
|
|
48
50
|
interface ResolvedDocsPage extends DocsPage {
|
|
49
51
|
id: string;
|
|
50
52
|
fullPath: string;
|
|
51
53
|
}
|
|
52
54
|
declare function isPage(node: DocsNode): node is DocsPage;
|
|
55
|
+
declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPath?: string): DocsPage | null;
|
|
53
56
|
declare function resolveDocs(nodes: DocsNode[], parentPath?: string): ResolvedDocsPage[];
|
|
54
57
|
declare function findFirstPage(nodes: DocsNode[], parentPath?: string): string | null;
|
|
55
58
|
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';require('elseware-ui/styles.css');var react=require('react'),jsxRuntime=require('react/jsx-runtime'),elsewareUi=require('elseware-ui'),reactRouterDom=require('react-router-dom');var a=react.createContext(void 0);function
|
|
2
|
-
exports.DocsEngine=
|
|
1
|
+
'use strict';require('elseware-ui/styles.css');var react=require('react'),jsxRuntime=require('react/jsx-runtime'),elsewareUi=require('elseware-ui'),reactRouterDom=require('react-router-dom');var a=react.createContext(void 0);function b({docs:e,basePath:t,children:r}){return jsxRuntime.jsx(a.Provider,{value:{docs:e,basePath:t},children:r})}var g=b;function y({docs:e,basePath:t="/docs",children:r}){let o=t.startsWith("/")?t:`/${t}`;return jsxRuntime.jsx(g,{docs:e,basePath:o,children:r})}var x=y;function k({content:e}){return jsxRuntime.jsx(elsewareUi.DocumentationPanel,{value:e})}var D=k;function s(){let e=react.useContext(a);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function c(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function n(e){return "content"in e}function d(e,t,r=""){let o=c(t);for(let i of e){let l=c(`${r}/${i.path}`);if(n(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=c(`${t}/${o.path}`);if(n(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=c(`${t}/${r.path}`);if(n(r))return o;let i=S(r.children,o);if(i)return i}return null}function X({debug:e=false}={}){let{docs:t}=s(),r=reactRouterDom.useParams(),o=r["*"]??"";return e&&(console.log("params",r),console.log("pagePath",o)),d(t,o)}function f(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(e,t,r=""){return e.map(o=>{let i=f(`${r}/${o.path}`);return n(o)?{type:"item",name:o.title,to:f(`${t}/${i}`)}:{type:"group",name:o.title,items:h(o.children,t,i)}})}function u(e,t){return h(e,t)}function re(){let{docs:e,basePath:t}=s();return u(e,t)}function $(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function ne({basePath:e="/docs",element:t}){return [{path:`${$(e)}/*`,element:t}]}
|
|
2
|
+
exports.DocsEngine=x;exports.DocsPageRenderer=D;exports.findFirstPage=S;exports.findPageByPath=d;exports.generateDocsRoutes=ne;exports.isPage=n;exports.resolveDocs=R;exports.useCurrentPage=X;exports.useDocs=s;exports.useSidebar=re;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/engine/DocsEngine.tsx","../src/components/DocsPageRenderer.tsx","../src/hooks/useDocs.ts","../src/utils/page.ts","../src/hooks/useCurrentPage.ts","../src/utils/generateSidebar.ts","../src/hooks/useSidebar.ts","../src/utils/generateRoutes.tsx"],"names":["DocsContext","createContext","DocsProvider","docs","basePath","children","jsx","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","DocsPageRenderer","content","DocumentationPanel","DocsPageRenderer_default","useDocs","context","useContext","findPageByPath","nodes","targetPath","parentPath","node","fullPath","isPage","found","resolveDocs","pages","currentPath","findFirstPage","nested","useCurrentPage","pagePath","useParams","mapNodes","generateSidebar","useSidebar","generateDocsRoutes","element"],"mappings":"+LAQO,IAAMA,CAAAA,CAAcC,mBAAAA,CACzB,MACF,CAAA,CCEA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,EAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACEC,cAAAA,CAACN,EAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,SAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOE,CAAAA,CAAQL,CAAAA,CCRf,SAASM,EAAW,CAAE,IAAA,CAAAL,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAW,OAAA,CAAS,SAAAC,CAAS,CAAA,CAAoB,CAC3E,IAAMI,CAAAA,CAAqBL,CAAAA,CAAS,WAAW,GAAG,CAAA,CAC9CA,CAAAA,CACA,CAAA,CAAA,EAAIA,CAAQ,CAAA,CAAA,CAEhB,OACEE,cAAAA,CAACC,CAAAA,CAAA,CAAa,IAAA,CAAMJ,CAAAA,CAAM,QAAA,CAAUM,EACjC,QAAA,CAAAJ,CAAAA,CACH,CAEJ,CAEA,IAAOK,CAAAA,CAAQF,EChBf,SAASG,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAON,cAAAA,CAACO,6BAAAA,CAAA,CAA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AAIE,CAAAA,CAAOF,CAAI,EACN,CACL,IAAA,CAAM,MAAA,CACN,IAAA,CAAMA,CAAAA,CAAK,KAAA,CACX,GAAI,CAAA,CAAA,EAAIlB,CAAQ,CAAA,EAAGmB,CAAQ,CAAA,CAAA,CAAG,OAAA,CAAQ,OAAQ,GAAG,CACnD,CAAA,CAGK,CACL,IAAA,CAAM,OAAA,CACN,IAAA,CAAMD,CAAAA,CAAK,KAAA,CACX,KAAA,CAAOY,CAAAA,CAASZ,CAAAA,CAAK,QAAA,CAAUlB,CAAAA,CAAUmB,CAAQ,CACnD,CACF,CAAC,CACH,CAEO,SAASY,EACdhC,CAAAA,CAEAC,CAAAA,CACY,CACZ,OAAO8B,CAAAA,CAAS/B,CAAAA,CAAMC,CAAQ,CAChC,CChCO,SAASgC,CAAAA,EAAa,CAC3B,GAAM,CAAE,IAAA,CAAAjC,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAIW,CAAAA,GAE3B,OAAOoB,CAAAA,CAAgBhC,CAAAA,CAAMC,CAAQ,CACvC,CCCO,SAASiC,EAAAA,CAAmB,CACjC,QAAA,CAAAjC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAkC,CACF,CAAA,CAA2C,CACzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAAGlC,CAAQ,CAAA,EAAA,CAAA,CACjB,OAAA,CAAAkC,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { createContext } from \"react\";\nimport { DocsCategory } from \"../types/docs\";\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/docs\";\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/docs\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/docs\", 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 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 { useContext } from \"react\";\n\nimport { DocsContext } from \"../context/DocsContext\";\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 { DocsNode, DocsPage } from \"../types/docs\";\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n for (const node of nodes) {\n const fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n if (fullPath.replace(/^\\//, \"\") === targetPath.replace(/^\\//, \"\")) {\n return {\n ...node,\n path: fullPath,\n };\n }\n\n continue;\n }\n\n const found = findPageByPath(node.children, targetPath, fullPath);\n\n if (found) {\n return found;\n }\n }\n\n return null;\n}\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 resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\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 fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n return fullPath;\n }\n\n const nested = findFirstPage(node.children, fullPath);\n\n if (nested) {\n return nested;\n }\n }\n\n return null;\n}\n","import { useParams } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\nexport function useCurrentPage() {\n const { docs } = useDocs();\n\n const params = useParams();\n\n const pagePath = params[\"*\"] ?? \"\";\n\n return findPageByPath(docs, pagePath);\n}","import { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, DocsNode } from \"../types/docs\";\n\nimport { isPage } from \"./page\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: `/${basePath}${fullPath}`.replace(/\\/+/g, \"/\"),\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\n basePath: string,\n): MenuNode[] {\n return mapNodes(docs, basePath);\n}\n","import { generateSidebar } from \"../utils/generateSidebar\";\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\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n return [\n {\n path: `${basePath}/*`,\n element,\n },\n ];\n}"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/engine/DocsEngine.tsx","../src/components/DocsPageRenderer.tsx","../src/hooks/useDocs.ts","../src/utils/page.ts","../src/hooks/useCurrentPage.ts","../src/utils/generateSidebar.ts","../src/hooks/useSidebar.ts","../src/utils/generateRoutes.tsx"],"names":["DocsContext","createContext","DocsProvider","docs","basePath","children","jsx","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","DocsPageRenderer","content","DocumentationPanel","DocsPageRenderer_default","useDocs","context","useContext","normalizePath","path","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","useCurrentPage","debug","params","useParams","pagePath","mapNodes","fullPath","generateSidebar","useSidebar","normalizeRoutePath","generateDocsRoutes","element"],"mappings":"+LAQO,IAAMA,CAAAA,CAAcC,mBAAAA,CACzB,MACF,CAAA,CCEA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACEC,cAAAA,CAACN,CAAAA,CAAY,QAAA,CAAZ,CAAqB,MAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOE,CAAAA,CAAQL,CAAAA,CCRf,SAASM,CAAAA,CAAW,CAAE,IAAA,CAAAL,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAW,OAAA,CAAS,QAAA,CAAAC,CAAS,CAAA,CAAoB,CAC3E,IAAMI,CAAAA,CAAqBL,EAAS,UAAA,CAAW,GAAG,CAAA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ACdrC,CAAAA,CACAC,CAAAA,CACY,CACZ,OAAOkC,CAAAA,CAASnC,CAAAA,CAAMC,CAAQ,CAChC,CCvCO,SAASqC,EAAAA,EAAa,CAC3B,GAAM,CAAE,IAAA,CAAAtC,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAIW,CAAAA,EAAQ,CAEnC,OAAOyB,CAAAA,CAAgBrC,CAAAA,CAAMC,CAAQ,CACvC,CCCA,SAASsC,CAAAA,CAAmBvB,CAAAA,CAAc,CACxC,OAAOA,CAAAA,CAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,OAAA,CAAQ,MAAA,CAAQ,EAAE,CACpD,CAEO,SAASwB,EAAAA,CAAmB,CACjC,QAAA,CAAAvC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAwC,CACF,CAAA,CAA2C,CAGzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAJaF,CAAAA,CAAmBtC,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAAwC,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { createContext } from \"react\";\nimport { DocsCategory } from \"../types/docs\";\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/docs\";\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/docs\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/docs\", 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 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 { useContext } from \"react\";\n\nimport { DocsContext } from \"../context/DocsContext\";\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 { DocsNode, DocsPage } from \"../types/docs\";\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\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\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n\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 { useParams } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs } = useDocs();\n\n const params = useParams();\n\n const pagePath = params[\"*\"] ?? \"\";\n\n if (debug) {\n console.log(\"params\", params);\n\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, DocsNode } from \"../types/docs\";\n\nimport { isPage } from \"./page\";\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\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\n name: node.title,\n\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n\n name: node.title,\n\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 { generateSidebar } from \"../utils/generateSidebar\";\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\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.ReactNode;\n}\n\nfunction normalizeRoutePath(path: string) {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\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 {createContext,useContext}from'react';import {jsx}from'react/jsx-runtime';import {DocumentationPanel}from'elseware-ui';import {useParams}from'react-router-dom';var a=createContext(void 0);function
|
|
2
|
-
export{
|
|
1
|
+
import'elseware-ui/styles.css';import {createContext,useContext}from'react';import {jsx}from'react/jsx-runtime';import {DocumentationPanel}from'elseware-ui';import {useParams}from'react-router-dom';var a=createContext(void 0);function b({docs:e,basePath:t,children:r}){return jsx(a.Provider,{value:{docs:e,basePath:t},children:r})}var g=b;function y({docs:e,basePath:t="/docs",children:r}){let o=t.startsWith("/")?t:`/${t}`;return jsx(g,{docs:e,basePath:o,children:r})}var x=y;function k({content:e}){return jsx(DocumentationPanel,{value:e})}var D=k;function s(){let e=useContext(a);if(!e)throw new Error("useDocs must be used within DocsProvider");return e}function c(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function n(e){return "content"in e}function d(e,t,r=""){let o=c(t);for(let i of e){let l=c(`${r}/${i.path}`);if(n(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=c(`${t}/${o.path}`);if(n(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=c(`${t}/${r.path}`);if(n(r))return o;let i=S(r.children,o);if(i)return i}return null}function X({debug:e=false}={}){let{docs:t}=s(),r=useParams(),o=r["*"]??"";return e&&(console.log("params",r),console.log("pagePath",o)),d(t,o)}function f(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function h(e,t,r=""){return e.map(o=>{let i=f(`${r}/${o.path}`);return n(o)?{type:"item",name:o.title,to:f(`${t}/${i}`)}:{type:"group",name:o.title,items:h(o.children,t,i)}})}function u(e,t){return h(e,t)}function re(){let{docs:e,basePath:t}=s();return u(e,t)}function $(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function ne({basePath:e="/docs",element:t}){return [{path:`${$(e)}/*`,element:t}]}
|
|
2
|
+
export{x as DocsEngine,D as DocsPageRenderer,S as findFirstPage,d as findPageByPath,ne as generateDocsRoutes,n as isPage,R as resolveDocs,X as useCurrentPage,s as useDocs,re as useSidebar};//# sourceMappingURL=index.mjs.map
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/engine/DocsEngine.tsx","../src/components/DocsPageRenderer.tsx","../src/hooks/useDocs.ts","../src/utils/page.ts","../src/hooks/useCurrentPage.ts","../src/utils/generateSidebar.ts","../src/hooks/useSidebar.ts","../src/utils/generateRoutes.tsx"],"names":["DocsContext","createContext","DocsProvider","docs","basePath","children","jsx","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","DocsPageRenderer","content","DocumentationPanel","DocsPageRenderer_default","useDocs","context","useContext","findPageByPath","nodes","targetPath","parentPath","node","fullPath","isPage","found","resolveDocs","pages","currentPath","findFirstPage","nested","useCurrentPage","pagePath","useParams","mapNodes","generateSidebar","useSidebar","generateDocsRoutes","element"],"mappings":"sMAQO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,MACF,CAAA,CCEA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,EAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB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AA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAAIW,CAAAA,GAE3B,OAAOoB,CAAAA,CAAgBhC,CAAAA,CAAMC,CAAQ,CACvC,CCCO,SAASiC,EAAAA,CAAmB,CACjC,QAAA,CAAAjC,CAAAA,CAAW,OAAA,CACX,OAAA,CAAAkC,CACF,CAAA,CAA2C,CACzC,OAAO,CACL,CACE,IAAA,CAAM,CAAA,EAAGlC,CAAQ,CAAA,EAAA,CAAA,CACjB,OAAA,CAAAkC,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import { createContext } from \"react\";\nimport { DocsCategory } from \"../types/docs\";\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/docs\";\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/docs\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/docs\", 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 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 { useContext } from \"react\";\n\nimport { DocsContext } from \"../context/DocsContext\";\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 { DocsNode, DocsPage } from \"../types/docs\";\n\nexport function findPageByPath(\n nodes: DocsNode[],\n targetPath: string,\n parentPath = \"\",\n): DocsPage | null {\n for (const node of nodes) {\n const fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n if (fullPath.replace(/^\\//, \"\") === targetPath.replace(/^\\//, \"\")) {\n return {\n ...node,\n path: fullPath,\n };\n }\n\n continue;\n }\n\n const found = findPageByPath(node.children, targetPath, fullPath);\n\n if (found) {\n return found;\n }\n }\n\n return null;\n}\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 resolveDocs(\n nodes: DocsNode[],\n parentPath = \"\",\n): ResolvedDocsPage[] {\n const pages: ResolvedDocsPage[] = [];\n\n nodes.forEach((node) => {\n const currentPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\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 fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n return fullPath;\n }\n\n const nested = findFirstPage(node.children, fullPath);\n\n if (nested) {\n return nested;\n }\n }\n\n return null;\n}\n","import { useParams } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\nexport function useCurrentPage() {\n const { docs } = useDocs();\n\n const params = useParams();\n\n const pagePath = params[\"*\"] ?? \"\";\n\n return findPageByPath(docs, pagePath);\n}","import { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, DocsNode } from \"../types/docs\";\n\nimport { isPage } from \"./page\";\n\nfunction mapNodes(\n nodes: DocsNode[],\n basePath: string,\n parentPath = \"\",\n): MenuNode[] {\n return nodes.map((node) => {\n const fullPath = `${parentPath}${node.path}`.replace(/\\/+/g, \"/\");\n\n if (isPage(node)) {\n return {\n type: \"item\",\n name: node.title,\n to: `/${basePath}${fullPath}`.replace(/\\/+/g, \"/\"),\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\n basePath: string,\n): MenuNode[] {\n return mapNodes(docs, basePath);\n}\n","import { generateSidebar } from \"../utils/generateSidebar\";\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\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.ReactNode;\n}\n\nexport function generateDocsRoutes({\n basePath = \"/docs\",\n element,\n}: GenerateDocsRoutesProps): RouteObject[] {\n return [\n {\n path: `${basePath}/*`,\n element,\n },\n ];\n}"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/DocsContext.ts","../src/context/DocsProvider.tsx","../src/engine/DocsEngine.tsx","../src/components/DocsPageRenderer.tsx","../src/hooks/useDocs.ts","../src/utils/page.ts","../src/hooks/useCurrentPage.ts","../src/utils/generateSidebar.ts","../src/hooks/useSidebar.ts","../src/utils/generateRoutes.tsx"],"names":["DocsContext","createContext","DocsProvider","docs","basePath","children","jsx","DocsProvider_default","DocsEngine","normalizedBasePath","DocsEngine_default","DocsPageRenderer","content","DocumentationPanel","DocsPageRenderer_default","useDocs","context","useContext","normalizePath","path","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","useCurrentPage","debug","params","useParams","pagePath","mapNodes","fullPath","generateSidebar","useSidebar","normalizeRoutePath","generateDocsRoutes","element"],"mappings":"sMAQO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,MACF,CAAA,CCEA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,CAAS,CAAA,CAAsB,CACrE,OACEC,GAAAA,CAACN,CAAAA,CAAY,QAAA,CAAZ,CAAqB,MAAO,CAAE,IAAA,CAAAG,CAAAA,CAAM,QAAA,CAAAC,CAAS,CAAA,CAC3C,QAAA,CAAAC,CAAAA,CACH,CAEJ,CAEA,IAAOE,CAAAA,CAAQL,CAAAA,CCRf,SAASM,CAAAA,CAAW,CAAE,IAAA,CAAAL,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAW,OAAA,CAAS,QAAA,CAAAC,CAAS,CAAA,CAAoB,CAC3E,IAAMI,CAAAA,CAAqBL,EAAS,UAAA,CAAW,GAAG,CAAA,CAC9CA,CAAAA,CACA,CAAA,CAAA,EAAIA,CAAQ,CAAA,CAAA,CAEhB,OACEE,GAAAA,CAACC,CAAAA,CAAA,CAAa,IAAA,CAAMJ,CAAAA,CAAM,QAAA,CAAUM,CAAAA,CACjC,QAAA,CAAAJ,CAAAA,CACH,CAEJ,CAEA,IAAOK,CAAAA,CAAQF,EChBf,SAASG,CAAAA,CAAiB,CACxB,OAAA,CAAAC,CACF,CAAA,CAA0B,CACxB,OAAON,GAAAA,CAACO,kBAAAA,CAAA,CAAmB,KAAA,CAAOD,CAAAA,CAAS,CAC7C,CAEA,IAAOE,CAAAA,CAAQH,ECVR,SAASI,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,UAAAA,CAAWjB,CAAW,CAAA,CAEtC,GAAI,CAACgB,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,0CAA0C,CAAA,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E,IAAA,CAAM,CAAA,EAJaF,CAAAA,CAAmBtC,CAAQ,CAIvB,CAAA,EAAA,CAAA,CACvB,OAAA,CAAAwC,CACF,CACF,CACF","file":"index.mjs","sourcesContent":["import { createContext } from \"react\";\nimport { DocsCategory } from \"../types/docs\";\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/docs\";\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/docs\";\n\ninterface DocsEngineProps {\n docs: DocsCategory[];\n basePath?: string;\n children: React.ReactNode;\n}\n\nfunction DocsEngine({ docs, basePath = \"/docs\", 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 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 { useContext } from \"react\";\n\nimport { DocsContext } from \"../context/DocsContext\";\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 { DocsNode, DocsPage } from \"../types/docs\";\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\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\n id: currentPath.replace(/\\//g, \"-\").replace(/^-/, \"\"),\n\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 { useParams } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs } = useDocs();\n\n const params = useParams();\n\n const pagePath = params[\"*\"] ?? \"\";\n\n if (debug) {\n console.log(\"params\", params);\n\n console.log(\"pagePath\", pagePath);\n }\n\n return findPageByPath(docs, pagePath);\n}\n","import { MenuNode } from \"elseware-ui\";\n\nimport { DocsCategory, DocsNode } from \"../types/docs\";\n\nimport { isPage } from \"./page\";\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\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\n name: node.title,\n\n to: normalizePath(`${basePath}/${fullPath}`),\n };\n }\n\n return {\n type: \"group\",\n\n name: node.title,\n\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 { generateSidebar } from \"../utils/generateSidebar\";\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\ninterface GenerateDocsRoutesProps {\n basePath?: string;\n element: React.ReactNode;\n}\n\nfunction normalizeRoutePath(path: string) {\n return path.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\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"]}
|