xladmin-next 0.1.9
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/README.md +48 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +82 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="./README.md">
|
|
3
|
+
<img src="https://img.shields.io/badge/English-blue?style=for-the-badge" alt="English">
|
|
4
|
+
</a>
|
|
5
|
+
<a href="./docs/README.ru.md">
|
|
6
|
+
<img src="https://img.shields.io/badge/%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9-red?style=for-the-badge" alt="Russian">
|
|
7
|
+
</a>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
# xladmin-next
|
|
11
|
+
|
|
12
|
+
`xladmin-next` provides the Next.js router adapter for `xladmin`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install xladmin xladmin-next
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
'use client';
|
|
24
|
+
|
|
25
|
+
import {Shell, createFetchXLAdminClient} from 'xladmin';
|
|
26
|
+
import {useNextXLAdminRouter} from 'xladmin-next';
|
|
27
|
+
|
|
28
|
+
export function AdminShell({models, blocks}) {
|
|
29
|
+
const client = createFetchXLAdminClient({baseUrl: '/api/admin'});
|
|
30
|
+
const router = useNextXLAdminRouter();
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Shell client={client} models={models} blocks={blocks} basePath="/admin" locale="en" router={router}>
|
|
34
|
+
{/* your route page */}
|
|
35
|
+
</Shell>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Exports
|
|
41
|
+
|
|
42
|
+
- `useNextXLAdminRouter()`
|
|
43
|
+
- `createNextXLAdminRouter(...)`
|
|
44
|
+
|
|
45
|
+
## Docs
|
|
46
|
+
|
|
47
|
+
- [Russian README](./docs/README.ru.md)
|
|
48
|
+
- [xladmin package](../xladmin-core/README.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { XLAdminRouter } from 'xladmin';
|
|
2
|
+
|
|
3
|
+
type NextXLAdminRouterAdapter = {
|
|
4
|
+
pathname: string;
|
|
5
|
+
search: string;
|
|
6
|
+
push: (href: string) => void;
|
|
7
|
+
replace: (href: string) => void;
|
|
8
|
+
back: () => void;
|
|
9
|
+
};
|
|
10
|
+
declare function createNextXLAdminRouter(adapter: NextXLAdminRouterAdapter): XLAdminRouter;
|
|
11
|
+
declare function useNextXLAdminRouter(): XLAdminRouter;
|
|
12
|
+
|
|
13
|
+
export { type NextXLAdminRouterAdapter, createNextXLAdminRouter, useNextXLAdminRouter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/index.tsx
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { usePathname, useRouter, useSearchParams } from "next/navigation.js";
|
|
6
|
+
function createNextXLAdminRouter(adapter) {
|
|
7
|
+
return {
|
|
8
|
+
getLocation: () => ({
|
|
9
|
+
pathname: adapter.pathname,
|
|
10
|
+
search: adapter.search
|
|
11
|
+
}),
|
|
12
|
+
subscribe: () => () => {
|
|
13
|
+
},
|
|
14
|
+
push: (href) => {
|
|
15
|
+
adapter.push(href);
|
|
16
|
+
},
|
|
17
|
+
replace: (href) => {
|
|
18
|
+
adapter.replace(href);
|
|
19
|
+
},
|
|
20
|
+
back: () => {
|
|
21
|
+
adapter.back();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function useNextXLAdminRouter() {
|
|
26
|
+
const nextRouter = useRouter();
|
|
27
|
+
const pathname = usePathname();
|
|
28
|
+
const searchParams = useSearchParams();
|
|
29
|
+
const listenersRef = useRef(/* @__PURE__ */ new Set());
|
|
30
|
+
const locationRef = useRef({
|
|
31
|
+
pathname,
|
|
32
|
+
search: searchParams.toString() ? `?${searchParams.toString()}` : ""
|
|
33
|
+
});
|
|
34
|
+
const previousLocationRef = useRef(locationRef.current);
|
|
35
|
+
const navigationRef = useRef(nextRouter);
|
|
36
|
+
const routerRef = useRef(null);
|
|
37
|
+
locationRef.current = {
|
|
38
|
+
pathname,
|
|
39
|
+
search: searchParams.toString() ? `?${searchParams.toString()}` : ""
|
|
40
|
+
};
|
|
41
|
+
navigationRef.current = nextRouter;
|
|
42
|
+
if (routerRef.current === null) {
|
|
43
|
+
routerRef.current = createNextXLAdminRouter({
|
|
44
|
+
pathname: locationRef.current.pathname,
|
|
45
|
+
search: locationRef.current.search,
|
|
46
|
+
push: (href) => {
|
|
47
|
+
navigationRef.current.push(href);
|
|
48
|
+
},
|
|
49
|
+
replace: (href) => {
|
|
50
|
+
navigationRef.current.replace(href);
|
|
51
|
+
},
|
|
52
|
+
back: () => {
|
|
53
|
+
navigationRef.current.back();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
routerRef.current.getLocation = () => ({
|
|
57
|
+
pathname: locationRef.current.pathname,
|
|
58
|
+
search: locationRef.current.search
|
|
59
|
+
});
|
|
60
|
+
routerRef.current.subscribe = (listener) => {
|
|
61
|
+
listenersRef.current.add(listener);
|
|
62
|
+
return () => {
|
|
63
|
+
listenersRef.current.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const previousLocation = previousLocationRef.current;
|
|
69
|
+
if (previousLocation.pathname === locationRef.current.pathname && previousLocation.search === locationRef.current.search) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
previousLocationRef.current = locationRef.current;
|
|
73
|
+
for (const listener of listenersRef.current) {
|
|
74
|
+
listener();
|
|
75
|
+
}
|
|
76
|
+
}, [pathname, searchParams]);
|
|
77
|
+
return routerRef.current;
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
createNextXLAdminRouter,
|
|
81
|
+
useNextXLAdminRouter
|
|
82
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xladmin-next",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "Next.js router adapter for xladmin.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Artasov/xladmin.git",
|
|
13
|
+
"directory": "xladmin-frontend/packages/xladmin-next"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/Artasov/xladmin/tree/main/xladmin-frontend/packages/xladmin-next",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Artasov/xladmin/issues"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "node ../../scripts/clean.mjs && tsup src/index.tsx --format esm --dts",
|
|
35
|
+
"check": "tsc --noEmit -p tsconfig.json",
|
|
36
|
+
"test": "vitest run --environment node --pool threads"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"next": ">=15.0.0 <17.0.0",
|
|
40
|
+
"react": ">=19.0.0 <20.0.0",
|
|
41
|
+
"react-dom": ">=19.0.0 <20.0.0",
|
|
42
|
+
"xladmin": "^0.1.9"
|
|
43
|
+
}
|
|
44
|
+
}
|