@xyd-js/framework 0.1.0-xyd.11 → 0.1.0-xyd.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/Sidebar-CdavG0uc.d.ts +23 -0
- package/dist/hydration.d.ts +17 -0
- package/dist/hydration.js +269 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +72 -0
- package/dist/react.js +612 -0
- package/dist/react.js.map +1 -0
- package/package.json +19 -16
- package/packages/hydration/README.md +0 -3
- package/packages/hydration/index.ts +0 -3
- package/packages/hydration/settings-to-props.ts +0 -325
- package/packages/react/README.md +0 -3
- package/packages/react/components/index.tsx +0 -337
- package/packages/react/components/sidebar/index.ts +0 -3
- package/packages/react/components/sidebar/sidebar-group.tsx +0 -240
- package/packages/react/components/sidebar/sidebar.tsx +0 -127
- package/packages/react/contexts/framework.tsx +0 -78
- package/packages/react/contexts/index.ts +0 -2
- package/packages/react/contexts/ui.tsx +0 -6
- package/packages/react/hooks/index.ts +0 -3
- package/packages/react/hooks/useMatchedNav.tsx +0 -29
- package/packages/react/index.ts +0 -12
- package/packages/react/utils/manualHydration.ts +0 -25
- package/packages/theme/context.tsx +0 -19
- package/packages/theme/index.ts +0 -0
- package/postcss.config.cjs +0 -5
- package/src/index.ts +0 -1
- package/src/types.ts +0 -7
- package/tsconfig.json +0 -45
- package/tsup.config.ts +0 -28
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React, {createContext, useContext} from "react";
|
|
2
|
-
|
|
3
|
-
import {Settings} from "@xyd-js/core";
|
|
4
|
-
import type {ITOC, IBreadcrumb, INavLinks} from "@xyd-js/ui";
|
|
5
|
-
|
|
6
|
-
import {FwSidebarGroupProps} from "../components/sidebar";
|
|
7
|
-
|
|
8
|
-
export interface IFramework {
|
|
9
|
-
settings: Settings
|
|
10
|
-
|
|
11
|
-
sidebarGroups: FwSidebarGroupProps[]
|
|
12
|
-
|
|
13
|
-
toc?: ITOC[]
|
|
14
|
-
|
|
15
|
-
breadcrumbs?: IBreadcrumb[]
|
|
16
|
-
|
|
17
|
-
navlinks?: INavLinks
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// TODO: page context + app context?
|
|
21
|
-
const framework: IFramework = {
|
|
22
|
-
settings: {},
|
|
23
|
-
sidebarGroups: []
|
|
24
|
-
}
|
|
25
|
-
const FrameworkContext = createContext<IFramework>(framework)
|
|
26
|
-
|
|
27
|
-
export interface FrameworkProps {
|
|
28
|
-
children: React.ReactNode
|
|
29
|
-
|
|
30
|
-
settings: Settings,
|
|
31
|
-
sidebarGroups: FwSidebarGroupProps[],
|
|
32
|
-
toc?: ITOC[],
|
|
33
|
-
breadcrumbs?: IBreadcrumb[],
|
|
34
|
-
navlinks?: INavLinks
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function Framework(props: FrameworkProps) {
|
|
38
|
-
return <FrameworkContext.Provider value={{
|
|
39
|
-
settings: props.settings,
|
|
40
|
-
sidebarGroups: props.sidebarGroups,
|
|
41
|
-
toc: props.toc,
|
|
42
|
-
breadcrumbs: props.breadcrumbs,
|
|
43
|
-
navlinks: props.navlinks,
|
|
44
|
-
}}>
|
|
45
|
-
{props.children}
|
|
46
|
-
</FrameworkContext.Provider>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export function useSidebarGroups() {
|
|
51
|
-
const ctx = useContext(FrameworkContext)
|
|
52
|
-
|
|
53
|
-
return ctx.sidebarGroups
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function useSettings() {
|
|
57
|
-
const ctx = useContext(FrameworkContext)
|
|
58
|
-
|
|
59
|
-
return ctx.settings
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function useToC() {
|
|
63
|
-
const ctx = useContext(FrameworkContext)
|
|
64
|
-
|
|
65
|
-
return ctx.toc
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function useBreadcrumbs() {
|
|
69
|
-
const ctx = useContext(FrameworkContext)
|
|
70
|
-
|
|
71
|
-
return ctx.breadcrumbs
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function useNavLinks() {
|
|
75
|
-
const ctx = useContext(FrameworkContext)
|
|
76
|
-
|
|
77
|
-
return ctx.navlinks
|
|
78
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {useLocation} from "react-router";
|
|
2
|
-
|
|
3
|
-
import {useSettings} from "../contexts";
|
|
4
|
-
|
|
5
|
-
import {manualHydration} from "../utils/manualHydration";
|
|
6
|
-
|
|
7
|
-
function normalizeHref(href: string) {
|
|
8
|
-
if (href.startsWith("/")) {
|
|
9
|
-
return href
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `/${href}`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// TODO: better data structures
|
|
16
|
-
export function useMatchedSubNav() {
|
|
17
|
-
const settings = useSettings()
|
|
18
|
-
const location = useLocation()
|
|
19
|
-
|
|
20
|
-
const matchedSubnav = settings.structure?.header
|
|
21
|
-
?.filter(item => item.sub)
|
|
22
|
-
?.find(item => normalizeHref(location.pathname).startsWith(normalizeHref(item.sub?.match || "")))
|
|
23
|
-
|
|
24
|
-
if (!matchedSubnav) {
|
|
25
|
-
return null
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return matchedSubnav.sub || null
|
|
29
|
-
}
|
package/packages/react/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React, {ReactElement} from "react";
|
|
2
|
-
|
|
3
|
-
export function manualHydration(obj: any, key = 0): ReactElement<any, string | React.JSXElementConstructor<any>> {
|
|
4
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
5
|
-
return React.createElement(React.Fragment, {key});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const {type, props} = obj || {};
|
|
9
|
-
if (typeof type !== 'string' && typeof type !== 'function') {
|
|
10
|
-
return React.createElement(React.Fragment, {key});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let children: ReactElement<any, string | React.JSXElementConstructor<any>>[] = [];
|
|
14
|
-
if (props?.children) {
|
|
15
|
-
if (Array.isArray(props.children)) {
|
|
16
|
-
children = props.children.map((child: any, i) => manualHydration(child, key + i)) || [];
|
|
17
|
-
} else {
|
|
18
|
-
children = [manualHydration(props.children, key)];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const elementProps = {...props, children, key};
|
|
23
|
-
|
|
24
|
-
return React.createElement(type, elementProps);
|
|
25
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {createContext, useContext} from "react";
|
|
2
|
-
|
|
3
|
-
import type {ITheme} from "@xyd-js/framework";
|
|
4
|
-
|
|
5
|
-
const theme = createContext<ITheme<any> | null>(null)
|
|
6
|
-
|
|
7
|
-
const Provider = theme.Provider
|
|
8
|
-
|
|
9
|
-
// TODO: finish theme context
|
|
10
|
-
|
|
11
|
-
export function withTheme(Component) {
|
|
12
|
-
return <Provider value={null}>
|
|
13
|
-
<Component/>
|
|
14
|
-
</Provider>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function useTheme<T>(): ITheme<any> | null {
|
|
18
|
-
return useContext(theme)
|
|
19
|
-
}
|
package/packages/theme/index.ts
DELETED
|
File without changes
|
package/postcss.config.cjs
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type * from "./types";
|
package/src/types.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "esnext",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"target": "ES6",
|
|
7
|
-
"compilerOptions": {
|
|
8
|
-
"baseUrl": ".",
|
|
9
|
-
"paths": {
|
|
10
|
-
"@/components/*": ["@/components/*"],
|
|
11
|
-
"@/lib/utils/*": ["@/lib/utils/*"],
|
|
12
|
-
"@/components/ui/*": ["@/components/ui/*"],
|
|
13
|
-
"@/components/magicui/*": ["@/components/magicui/*"]
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"lib": [
|
|
17
|
-
"dom",
|
|
18
|
-
"dom.iterable",
|
|
19
|
-
"esnext"
|
|
20
|
-
],
|
|
21
|
-
"allowJs": true,
|
|
22
|
-
"skipLibCheck": true,
|
|
23
|
-
"strict": false,
|
|
24
|
-
"noEmit": true,
|
|
25
|
-
"incremental": false,
|
|
26
|
-
"resolveJsonModule": true,
|
|
27
|
-
"isolatedModules": true,
|
|
28
|
-
"jsx": "preserve",
|
|
29
|
-
"plugins": [
|
|
30
|
-
{
|
|
31
|
-
"name": "next"
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"strictNullChecks": true
|
|
35
|
-
},
|
|
36
|
-
"include": [
|
|
37
|
-
"next-env.d.ts",
|
|
38
|
-
"**/*.ts",
|
|
39
|
-
"**/*.tsx",
|
|
40
|
-
".next/types/**/*.ts"
|
|
41
|
-
],
|
|
42
|
-
"exclude": [
|
|
43
|
-
"node_modules"
|
|
44
|
-
]
|
|
45
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {defineConfig} from 'tsup';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: {
|
|
5
|
-
index: 'src/index.ts',
|
|
6
|
-
react: 'packages/react/index.ts',
|
|
7
|
-
hydration: 'packages/hydration/index.ts',
|
|
8
|
-
},
|
|
9
|
-
format: ['esm', 'cjs'], // Output both ESM and CJS formats
|
|
10
|
-
target: 'node16', // Ensure compatibility with Node.js 16
|
|
11
|
-
dts: {
|
|
12
|
-
entry: {
|
|
13
|
-
index: 'src/index.ts',
|
|
14
|
-
react: 'packages/react/index.ts',
|
|
15
|
-
hydration: 'packages/hydration/index.ts',
|
|
16
|
-
},
|
|
17
|
-
resolve: true, // Resolve external types
|
|
18
|
-
},
|
|
19
|
-
splitting: false, // Disable code splitting
|
|
20
|
-
sourcemap: true, // Generate source maps
|
|
21
|
-
clean: true, // Clean the output directory before each build
|
|
22
|
-
esbuildOptions: (options) => {
|
|
23
|
-
options.platform = 'node'; // Ensure the platform is set to Node.js
|
|
24
|
-
options.external = ['node:fs/promises', 'react-router']; // Mark 'node:fs/promises' as external
|
|
25
|
-
options.loader = {'.js': 'jsx'}; // Ensure proper handling of .js files
|
|
26
|
-
},
|
|
27
|
-
ignoreWatch: ['node_modules', 'dist', '.git', 'build'] // Exclude unnecessary directories
|
|
28
|
-
});
|