elseware-docs-engine 1.1.3 → 1.1.5

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
@@ -1,8 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React from 'react';
2
+ import * as React from 'react';
3
+ import React__default from 'react';
3
4
  import * as elseware_ui from 'elseware-ui';
5
+ import { MenuNode } from 'elseware-ui';
4
6
  import { RouteObject } from 'react-router-dom';
5
7
 
8
+ interface DocsPageRendererProps {
9
+ content: string;
10
+ }
11
+ declare function DocsPageRenderer({ content, }: DocsPageRendererProps): react_jsx_runtime.JSX.Element;
12
+
6
13
  interface DocsPage {
7
14
  title: string;
8
15
  path: string;
@@ -15,35 +22,31 @@ interface DocsCategory {
15
22
  }
16
23
  type DocsNode = DocsCategory | DocsPage;
17
24
 
18
- interface DocsEngineProps {
19
- docs: DocsCategory[];
20
- basePath?: string;
21
- children: React.ReactNode;
22
- }
23
- declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
24
-
25
- interface DocsPageRendererProps {
26
- content: string;
27
- }
28
- declare function DocsPageRenderer({ content, }: DocsPageRendererProps): react_jsx_runtime.JSX.Element;
29
-
30
25
  interface DocsContextType {
31
26
  docs: DocsCategory[];
32
27
  basePath: string;
33
28
  }
29
+ declare const DocsContext: React.Context<DocsContextType | undefined>;
34
30
 
35
- declare function useDocs(): DocsContextType;
31
+ interface DocsEngineProps {
32
+ docs: DocsCategory[];
33
+ basePath?: string;
34
+ children: React__default.ReactNode;
35
+ }
36
+ declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
36
37
 
37
38
  interface UseCurrentPageProps {
38
39
  debug?: boolean;
39
40
  }
40
41
  declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | null;
41
42
 
43
+ declare function useDocs(): DocsContextType;
44
+
42
45
  declare function useSidebar(): elseware_ui.MenuNode[];
43
46
 
44
47
  interface GenerateDocsRoutesProps {
45
48
  basePath?: string;
46
- element: React.ReactNode;
49
+ element: React__default.ReactNode;
47
50
  }
48
51
  declare function generateDocsRoutes({ basePath, element, }: GenerateDocsRoutesProps): RouteObject[];
49
52
 
@@ -56,4 +59,9 @@ declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPat
56
59
  declare function resolveDocs(nodes: DocsNode[], parentPath?: string): ResolvedDocsPage[];
57
60
  declare function findFirstPage(nodes: DocsNode[], parentPath?: string): string | null;
58
61
 
59
- export { type DocsCategory, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, isPage, resolveDocs, useCurrentPage, useDocs, useSidebar };
62
+ declare function normalizePath(path: string): string;
63
+ declare function normalizeRoutePath(path: string): string;
64
+
65
+ declare function generateSidebar(docs: DocsCategory[], basePath: string): MenuNode[];
66
+
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 };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React from 'react';
2
+ import * as React from 'react';
3
+ import React__default from 'react';
3
4
  import * as elseware_ui from 'elseware-ui';
5
+ import { MenuNode } from 'elseware-ui';
4
6
  import { RouteObject } from 'react-router-dom';
5
7
 
8
+ interface DocsPageRendererProps {
9
+ content: string;
10
+ }
11
+ declare function DocsPageRenderer({ content, }: DocsPageRendererProps): react_jsx_runtime.JSX.Element;
12
+
6
13
  interface DocsPage {
7
14
  title: string;
8
15
  path: string;
@@ -15,35 +22,31 @@ interface DocsCategory {
15
22
  }
16
23
  type DocsNode = DocsCategory | DocsPage;
17
24
 
18
- interface DocsEngineProps {
19
- docs: DocsCategory[];
20
- basePath?: string;
21
- children: React.ReactNode;
22
- }
23
- declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
24
-
25
- interface DocsPageRendererProps {
26
- content: string;
27
- }
28
- declare function DocsPageRenderer({ content, }: DocsPageRendererProps): react_jsx_runtime.JSX.Element;
29
-
30
25
  interface DocsContextType {
31
26
  docs: DocsCategory[];
32
27
  basePath: string;
33
28
  }
29
+ declare const DocsContext: React.Context<DocsContextType | undefined>;
34
30
 
35
- declare function useDocs(): DocsContextType;
31
+ interface DocsEngineProps {
32
+ docs: DocsCategory[];
33
+ basePath?: string;
34
+ children: React__default.ReactNode;
35
+ }
36
+ declare function DocsEngine({ docs, basePath, children }: DocsEngineProps): react_jsx_runtime.JSX.Element;
36
37
 
37
38
  interface UseCurrentPageProps {
38
39
  debug?: boolean;
39
40
  }
40
41
  declare function useCurrentPage({ debug }?: UseCurrentPageProps): DocsPage | null;
41
42
 
43
+ declare function useDocs(): DocsContextType;
44
+
42
45
  declare function useSidebar(): elseware_ui.MenuNode[];
43
46
 
44
47
  interface GenerateDocsRoutesProps {
45
48
  basePath?: string;
46
- element: React.ReactNode;
49
+ element: React__default.ReactNode;
47
50
  }
48
51
  declare function generateDocsRoutes({ basePath, element, }: GenerateDocsRoutesProps): RouteObject[];
49
52
 
@@ -56,4 +59,9 @@ declare function findPageByPath(nodes: DocsNode[], targetPath: string, parentPat
56
59
  declare function resolveDocs(nodes: DocsNode[], parentPath?: string): ResolvedDocsPage[];
57
60
  declare function findFirstPage(nodes: DocsNode[], parentPath?: string): string | null;
58
61
 
59
- export { type DocsCategory, DocsEngine, type DocsNode, type DocsPage, DocsPageRenderer, type ResolvedDocsPage, findFirstPage, findPageByPath, generateDocsRoutes, isPage, resolveDocs, useCurrentPage, useDocs, useSidebar };
62
+ declare function normalizePath(path: string): string;
63
+ declare function normalizeRoutePath(path: string): string;
64
+
65
+ declare function generateSidebar(docs: DocsCategory[], basePath: string): MenuNode[];
66
+
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 };
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 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 N(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function Y({debug:e=false}={}){let{docs:t,basePath:r}=s(),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 h(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function f(e,t,r=""){return e.map(o=>{let i=h(`${r}/${o.path}`);return n(o)?{type:"item",name:o.title,to:h(`${t}/${i}`)}:{type:"group",name:o.title,items:f(o.children,t,i)}})}function u(e,t){return f(e,t)}function ie(){let{docs:e,basePath:t}=s();return u(e,t)}function E(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function ae({basePath:e="/docs",element:t}){return [{path:`${E(e)}/*`,element:t}]}
2
- exports.DocsEngine=x;exports.DocsPageRenderer=D;exports.findFirstPage=S;exports.findPageByPath=d;exports.generateDocsRoutes=ae;exports.isPage=n;exports.resolveDocs=R;exports.useCurrentPage=Y;exports.useDocs=s;exports.useSidebar=ie;//# 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 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
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","normalizePath","path","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","useCurrentPage","debug","location","useLocation","pagePath","mapNodes","fullPath","generateSidebar","useSidebar","normalizeRoutePath","generateDocsRoutes","element"],"mappings":"+LAQO,IAAMA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,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,OAAA,CAAQ,MAAA,CAAQ,EAAE,CACpD,CAEO,SAASwB,EAAAA,CAAmB,CACjC,QAAA,CAAAvC,EAAW,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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n /**\n * Remove docs base path\n */\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n\n console.log(\"basePath\", basePath);\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"]}
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,QAAA,CAA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A,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"]}
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 {useLocation}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 N(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function Y({debug:e=false}={}){let{docs:t,basePath:r}=s(),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 h(e){return "/"+e.replace(/\/+/g,"/").replace(/^\/|\/$/g,"")}function f(e,t,r=""){return e.map(o=>{let i=h(`${r}/${o.path}`);return n(o)?{type:"item",name:o.title,to:h(`${t}/${i}`)}:{type:"group",name:o.title,items:f(o.children,t,i)}})}function u(e,t){return f(e,t)}function ie(){let{docs:e,basePath:t}=s();return u(e,t)}function E(e){return e.replace(/^\/+/,"").replace(/\/+$/,"")}function ae({basePath:e="/docs",element:t}){return [{path:`${E(e)}/*`,element:t}]}
2
- export{x as DocsEngine,D as DocsPageRenderer,S as findFirstPage,d as findPageByPath,ae as generateDocsRoutes,n as isPage,R as resolveDocs,Y as useCurrentPage,s as useDocs,ie 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 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
3
3
  //# sourceMappingURL=index.mjs.map
@@ -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","normalizePath","path","isPage","node","findPageByPath","nodes","targetPath","parentPath","normalizedTarget","currentPath","result","resolveDocs","pages","findFirstPage","child","useCurrentPage","debug","location","useLocation","pagePath","mapNodes","fullPath","generateSidebar","useSidebar","normalizeRoutePath","generateDocsRoutes","element"],"mappings":"wMAQO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,MACF,CAAA,CCEA,SAASC,CAAAA,CAAa,CAAE,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,C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A,CAAAvC,EAAW,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.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 { useLocation } from \"react-router-dom\";\n\nimport { useDocs } from \"./useDocs\";\n\nimport { findPageByPath } from \"../utils/page\";\n\ninterface UseCurrentPageProps {\n debug?: boolean;\n}\n\nfunction normalizePath(path: string) {\n return \"/\" + path.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n}\n\nexport function useCurrentPage({ debug = false }: UseCurrentPageProps = {}) {\n const { docs, basePath } = useDocs();\n\n const location = useLocation();\n\n /**\n * Remove docs base path\n */\n const pagePath = normalizePath(\n location.pathname.replace(new RegExp(`^${basePath}`), \"\"),\n );\n\n if (debug) {\n console.log(\"location.pathname\", location.pathname);\n\n console.log(\"basePath\", basePath);\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"]}
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,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,QAAA,CAAAC,CAAAA,CAAW,GAAA,CAAK,QAAA,CAAAC,CAAS,CAAA,CAAoB,CACvE,IAAMG,CAAAA,CAAqBJ,CAAAA,CAAS,UAAA,CAA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AAA,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elseware-docs-engine",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "private": false,
5
5
  "description": "React documentation engine by elseware Technology",
6
6
  "license": "MIT",
@@ -31,11 +31,11 @@
31
31
  ],
32
32
  "peerDependencies": {
33
33
  "react": "^18",
34
- "react-dom": "^18"
34
+ "react-dom": "^18",
35
+ "react-router-dom": "^6"
35
36
  },
36
37
  "dependencies": {
37
- "elseware-ui": "^2.28.0",
38
- "react-router-dom": "^6"
38
+ "elseware-ui": "^2.28.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tailwindcss/postcss": "^4.1.16",