xladmin 0.3.0 → 0.3.1
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 +5 -5
- package/dist/cache.d.ts +6 -6
- package/dist/client.d.ts +23 -23
- package/dist/components/FieldEditor.d.ts +2 -2
- package/dist/components/FormDialog.d.ts +2 -2
- package/dist/components/ModelPage.d.ts +5 -5
- package/dist/components/NavLink.d.ts +2 -2
- package/dist/components/ObjectPage.d.ts +4 -4
- package/dist/components/OverviewPage.d.ts +2 -2
- package/dist/components/Shell.d.ts +4 -4
- package/dist/components/model-page/ListFiltersBar.d.ts +2 -2
- package/dist/components/model-page/useModelPageController.d.ts +4 -4
- package/dist/components/object-page/ObjectField.d.ts +2 -2
- package/dist/components/object-page/useObjectPageController.d.ts +4 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -64
- package/dist/router.d.ts +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,22 +31,22 @@ You also need one router adapter:
|
|
|
31
31
|
- `FormDialog`
|
|
32
32
|
- `FieldEditor`
|
|
33
33
|
- `NavLink`
|
|
34
|
-
- `
|
|
35
|
-
- `
|
|
36
|
-
- `
|
|
34
|
+
- `createAxiosAdminClient(...)`
|
|
35
|
+
- `createFetchAdminClient(...)`
|
|
36
|
+
- `createBrowserAdminRouter(...)`
|
|
37
37
|
- admin types, i18n helpers, and default theme
|
|
38
38
|
|
|
39
39
|
## Minimal Example
|
|
40
40
|
|
|
41
41
|
```tsx
|
|
42
42
|
import {useEffect, useMemo, useState} from 'react';
|
|
43
|
-
import {Shell, OverviewPage,
|
|
43
|
+
import {Shell, OverviewPage, createAxiosAdminClient, type AdminModelMeta, type AdminModelsBlockMeta} from 'xladmin';
|
|
44
44
|
import axios from 'axios';
|
|
45
45
|
|
|
46
46
|
const api = axios.create({baseURL: '/api/admin'});
|
|
47
47
|
|
|
48
48
|
export function AdminApp() {
|
|
49
|
-
const client = useMemo(() =>
|
|
49
|
+
const client = useMemo(() => createAxiosAdminClient(api), []);
|
|
50
50
|
const [models, setModels] = useState<AdminModelMeta[]>([]);
|
|
51
51
|
const [blocks, setBlocks] = useState<AdminModelsBlockMeta[]>([]);
|
|
52
52
|
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from './client';
|
|
2
2
|
import type { AdminDetailResponse, AdminListResponse } from './types';
|
|
3
3
|
type ClientCacheBucket = {
|
|
4
4
|
detailResponseCache: Map<string, AdminDetailResponse>;
|
|
@@ -14,9 +14,9 @@ export declare function buildListCacheKey(slug: string, params: {
|
|
|
14
14
|
limit?: number;
|
|
15
15
|
offset?: number;
|
|
16
16
|
} & Record<string, unknown>): string;
|
|
17
|
-
export declare function getClientCacheBucket(client:
|
|
18
|
-
export declare function getModelCacheVersion(client:
|
|
19
|
-
export declare function setCachedListResponse(client:
|
|
20
|
-
export declare function setCachedDetailResponse(client:
|
|
21
|
-
export declare function invalidateModelCache(client:
|
|
17
|
+
export declare function getClientCacheBucket(client: AdminClient): ClientCacheBucket;
|
|
18
|
+
export declare function getModelCacheVersion(client: AdminClient, slug: string): number;
|
|
19
|
+
export declare function setCachedListResponse(client: AdminClient, key: string, response: AdminListResponse): void;
|
|
20
|
+
export declare function setCachedDetailResponse(client: AdminClient, key: string, response: AdminDetailResponse): void;
|
|
21
|
+
export declare function invalidateModelCache(client: AdminClient, slug: string): void;
|
|
22
22
|
export {};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { AdminChoicesResponse, AdminDeletePreviewResponse, AdminDetailResponse, AdminListResponse, AdminModelMeta, AdminModelsResponse, AdminObjectActionResponse } from './types';
|
|
2
|
-
export type
|
|
2
|
+
export type AdminRequestOptions = {
|
|
3
3
|
signal?: AbortSignal;
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type AdminSelectionScope = {
|
|
6
6
|
q?: string;
|
|
7
7
|
filters?: Record<string, string>;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
9
|
+
export type AdminSelectionOptions = {
|
|
10
10
|
selectAll?: boolean;
|
|
11
|
-
selectionScope?:
|
|
11
|
+
selectionScope?: AdminSelectionScope;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
13
|
+
export type AdminClient = {
|
|
14
14
|
getModels: () => Promise<AdminModelsResponse>;
|
|
15
15
|
getModel: (slug: string) => Promise<AdminModelMeta>;
|
|
16
16
|
getItems: (slug: string, params?: {
|
|
@@ -24,37 +24,37 @@ export type XLAdminClient = {
|
|
|
24
24
|
patchItem: (slug: string, id: string | number, payload: Record<string, unknown>) => Promise<AdminDetailResponse>;
|
|
25
25
|
deleteItem: (slug: string, id: string | number) => Promise<void>;
|
|
26
26
|
getDeletePreview: (slug: string, id: string | number) => Promise<AdminDeletePreviewResponse>;
|
|
27
|
-
bulkDelete: (slug: string, ids: Array<string | number>, options?:
|
|
27
|
+
bulkDelete: (slug: string, ids: Array<string | number>, options?: AdminSelectionOptions) => Promise<{
|
|
28
28
|
deleted: number;
|
|
29
29
|
}>;
|
|
30
|
-
getBulkDeletePreview: (slug: string, ids: Array<string | number>, options?:
|
|
31
|
-
runBulkAction: (slug: string, actionSlug: string, ids: Array<string | number>, payload?: Record<string, unknown>, options?:
|
|
30
|
+
getBulkDeletePreview: (slug: string, ids: Array<string | number>, options?: AdminSelectionOptions) => Promise<AdminDeletePreviewResponse>;
|
|
31
|
+
runBulkAction: (slug: string, actionSlug: string, ids: Array<string | number>, payload?: Record<string, unknown>, options?: AdminSelectionOptions) => Promise<{
|
|
32
32
|
processed: number;
|
|
33
33
|
} & Record<string, unknown>>;
|
|
34
34
|
runObjectAction: (slug: string, id: string | number, actionSlug: string, payload?: Record<string, unknown>) => Promise<AdminObjectActionResponse>;
|
|
35
|
-
getChoices: (slug: string, fieldName: string, q?: string, ids?: Array<string | number>, options?:
|
|
36
|
-
getFilterChoices: (slug: string, filterSlug: string, q?: string, ids?: Array<string | number>, options?:
|
|
35
|
+
getChoices: (slug: string, fieldName: string, q?: string, ids?: Array<string | number>, options?: AdminRequestOptions) => Promise<AdminChoicesResponse>;
|
|
36
|
+
getFilterChoices: (slug: string, filterSlug: string, q?: string, ids?: Array<string | number>, options?: AdminRequestOptions) => Promise<AdminChoicesResponse>;
|
|
37
37
|
};
|
|
38
|
-
type
|
|
38
|
+
type AdminTransportResponse<T> = T | {
|
|
39
39
|
data: T;
|
|
40
40
|
};
|
|
41
|
-
export type
|
|
42
|
-
get: <T>(url: string, options?:
|
|
41
|
+
export type AdminTransport = {
|
|
42
|
+
get: <T>(url: string, options?: AdminRequestOptions & {
|
|
43
43
|
params?: Record<string, unknown>;
|
|
44
|
-
}) => Promise<
|
|
45
|
-
post: <T>(url: string, body?: Record<string, unknown>, options?:
|
|
46
|
-
patch: <T>(url: string, body: Record<string, unknown>, options?:
|
|
47
|
-
delete: (url: string, options?:
|
|
44
|
+
}) => Promise<AdminTransportResponse<T>>;
|
|
45
|
+
post: <T>(url: string, body?: Record<string, unknown>, options?: AdminRequestOptions) => Promise<AdminTransportResponse<T>>;
|
|
46
|
+
patch: <T>(url: string, body: Record<string, unknown>, options?: AdminRequestOptions) => Promise<AdminTransportResponse<T>>;
|
|
47
|
+
delete: (url: string, options?: AdminRequestOptions) => Promise<unknown>;
|
|
48
48
|
};
|
|
49
|
-
export type
|
|
50
|
-
export type
|
|
49
|
+
export type AdminAxiosLike = AdminTransport;
|
|
50
|
+
export type AdminFetchClientConfig = {
|
|
51
51
|
baseUrl: string;
|
|
52
52
|
fetch?: typeof globalThis.fetch;
|
|
53
53
|
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
54
54
|
credentials?: RequestCredentials;
|
|
55
55
|
};
|
|
56
|
-
export declare function
|
|
57
|
-
export declare function
|
|
58
|
-
export declare function
|
|
59
|
-
export declare function
|
|
56
|
+
export declare function createAdminClient(transport: AdminTransport): AdminClient;
|
|
57
|
+
export declare function createAxiosAdminClient(api: AdminAxiosLike): AdminClient;
|
|
58
|
+
export declare function createFetchAdminClient(config: AdminFetchClientConfig): AdminClient;
|
|
59
|
+
export declare function createFetchAdminTransport(config: AdminFetchClientConfig): AdminTransport;
|
|
60
60
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '@xladmin-core/client';
|
|
2
2
|
import type { AdminFieldMeta } from '@xladmin-core/types';
|
|
3
3
|
type AdminFieldEditorProps = {
|
|
4
4
|
field: AdminFieldMeta;
|
|
5
5
|
value: unknown;
|
|
6
6
|
onChange: (value: unknown) => void;
|
|
7
7
|
slug: string;
|
|
8
|
-
client:
|
|
8
|
+
client: AdminClient;
|
|
9
9
|
readOnly?: boolean;
|
|
10
10
|
};
|
|
11
11
|
export type FieldEditorProps = AdminFieldEditorProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '../client';
|
|
2
2
|
import type { AdminModelMeta } from '../types';
|
|
3
3
|
type AdminFormDialogProps = {
|
|
4
4
|
open: boolean;
|
|
@@ -8,7 +8,7 @@ type AdminFormDialogProps = {
|
|
|
8
8
|
slug: string;
|
|
9
9
|
mode: 'create' | 'patch';
|
|
10
10
|
meta: AdminModelMeta;
|
|
11
|
-
client:
|
|
11
|
+
client: AdminClient;
|
|
12
12
|
initialValues?: Record<string, unknown>;
|
|
13
13
|
itemId?: string | number;
|
|
14
14
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { AdminClient } from '../client';
|
|
3
|
+
import type { AdminRouter } from '../router';
|
|
4
4
|
type AdminModelPageProps = {
|
|
5
|
-
client:
|
|
5
|
+
client: AdminClient;
|
|
6
6
|
basePath: string;
|
|
7
7
|
slug: string;
|
|
8
|
-
router?:
|
|
8
|
+
router?: AdminRouter;
|
|
9
9
|
renderBeforePagination?: (context: ModelPageToolbarContext) => ReactNode;
|
|
10
10
|
};
|
|
11
11
|
export type ModelPageProps = AdminModelPageProps;
|
|
12
12
|
export type ModelPageToolbarContext = {
|
|
13
|
-
client:
|
|
13
|
+
client: AdminClient;
|
|
14
14
|
slug: string;
|
|
15
15
|
meta: {
|
|
16
16
|
slug: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AdminRouter } from '../router';
|
|
3
3
|
type AdminNavLinkProps = {
|
|
4
4
|
href: string;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
style?: CSSProperties;
|
|
7
7
|
title?: string;
|
|
8
8
|
onClick?: () => void;
|
|
9
|
-
router?:
|
|
9
|
+
router?: AdminRouter;
|
|
10
10
|
};
|
|
11
11
|
export type NavLinkProps = AdminNavLinkProps;
|
|
12
12
|
export declare function NavLink({ href, children, style, title, onClick, router }: NavLinkProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import 'dayjs/locale/en.js';
|
|
2
2
|
import 'dayjs/locale/ru.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { AdminClient } from '../client';
|
|
4
|
+
import type { AdminRouter } from '../router';
|
|
5
5
|
type AdminObjectPageProps = {
|
|
6
|
-
client:
|
|
6
|
+
client: AdminClient;
|
|
7
7
|
slug: string;
|
|
8
8
|
id: string;
|
|
9
|
-
router?:
|
|
9
|
+
router?: AdminRouter;
|
|
10
10
|
};
|
|
11
11
|
export type ObjectPageProps = AdminObjectPageProps;
|
|
12
12
|
export declare function ObjectPage({ client, slug, id, router }: ObjectPageProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import { type Theme } from '@mui/material/styles';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { AdminClient } from '../client';
|
|
4
|
+
import type { AdminRouter } from '../router';
|
|
5
5
|
import type { AdminModelMeta, AdminModelsBlockMeta } from '../types';
|
|
6
6
|
type AdminShellProps = {
|
|
7
|
-
client:
|
|
7
|
+
client: AdminClient;
|
|
8
8
|
models: AdminModelMeta[];
|
|
9
9
|
blocks: AdminModelsBlockMeta[];
|
|
10
10
|
basePath: string;
|
|
11
11
|
locale?: string | null;
|
|
12
12
|
children: ReactNode;
|
|
13
13
|
theme?: Theme;
|
|
14
|
-
router?:
|
|
14
|
+
router?: AdminRouter;
|
|
15
15
|
};
|
|
16
16
|
export type ShellProps = AdminShellProps;
|
|
17
17
|
export declare function Shell({ client, models, blocks, basePath, locale, children, theme, router }: ShellProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '@xladmin-core/client';
|
|
2
2
|
import type { AdminListFilterMeta } from '@xladmin-core/types';
|
|
3
3
|
type ListFiltersSidebarProps = {
|
|
4
|
-
client:
|
|
4
|
+
client: AdminClient;
|
|
5
5
|
slug: string;
|
|
6
6
|
filters: AdminListFilterMeta[];
|
|
7
7
|
values: Record<string, string>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '@xladmin-core/client';
|
|
2
2
|
import type { AdminTranslationKey } from '@xladmin-core/i18n';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AdminRouter } from '@xladmin-core/router';
|
|
4
4
|
import type { AdminDeletePreviewResponse, AdminListResponse } from '@xladmin-core/types';
|
|
5
5
|
type UseModelPageControllerOptions = {
|
|
6
|
-
client:
|
|
6
|
+
client: AdminClient;
|
|
7
7
|
slug: string;
|
|
8
8
|
pathname: string;
|
|
9
9
|
locationSearch: string;
|
|
10
|
-
router:
|
|
10
|
+
router: AdminRouter;
|
|
11
11
|
t: (key: AdminTranslationKey, params?: Record<string, string | number>) => string;
|
|
12
12
|
};
|
|
13
13
|
export declare function useModelPageController({ client, slug, pathname, locationSearch, router, t, }: UseModelPageControllerOptions): {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '@xladmin-core/client';
|
|
2
2
|
import type { AdminFieldMeta } from '@xladmin-core/types';
|
|
3
3
|
type ObjectFieldProps = {
|
|
4
4
|
field: AdminFieldMeta;
|
|
5
5
|
value: unknown;
|
|
6
6
|
slug: string;
|
|
7
|
-
client:
|
|
7
|
+
client: AdminClient;
|
|
8
8
|
onFieldChange: (fieldName: string, nextValue: unknown) => void;
|
|
9
9
|
};
|
|
10
10
|
export declare const ObjectField: import("react").NamedExoticComponent<ObjectFieldProps>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AdminClient } from '@xladmin-core/client';
|
|
2
2
|
import type { AdminTranslationKey } from '@xladmin-core/i18n';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AdminRouter } from '@xladmin-core/router';
|
|
4
4
|
import type { AdminDeletePreviewResponse, AdminDetailResponse } from '@xladmin-core/types';
|
|
5
5
|
type UseObjectPageControllerOptions = {
|
|
6
|
-
client:
|
|
6
|
+
client: AdminClient;
|
|
7
7
|
slug: string;
|
|
8
8
|
id: string;
|
|
9
9
|
listPath: string;
|
|
10
|
-
router:
|
|
10
|
+
router: AdminRouter;
|
|
11
11
|
t: (key: AdminTranslationKey, params?: Record<string, string | number>) => string;
|
|
12
12
|
};
|
|
13
13
|
export declare function useObjectPageController({ client, slug, id, listPath, router, t, }: UseObjectPageControllerOptions): {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createAxiosAdminClient, createFetchAdminClient, createFetchAdminTransport, createAdminClient, type AdminAxiosLike, type AdminClient, type AdminFetchClientConfig, type AdminRequestOptions, type AdminTransport, } from './client';
|
|
2
|
+
export { AdminRouterProvider, buildUrlWithParams, createBrowserAdminRouter, handleNavLinkClick, type AdminAnchorProps, type AdminLocation, type AdminRouter, useAdminLocation, useAdminRouter, } from './router';
|
|
3
3
|
export { FormDialog, type FormDialogProps } from './components/FormDialog';
|
|
4
4
|
export { OverviewPage, type OverviewPageProps } from './components/OverviewPage';
|
|
5
5
|
export { ModelPage, type ModelPageProps, type ModelPageToolbarContext } from './components/ModelPage';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createAxiosAdminClient, createFetchAdminClient, createFetchAdminTransport, createAdminClient, type AdminAxiosLike, type AdminClient, type AdminFetchClientConfig, type AdminRequestOptions, type AdminTransport, } from './client';
|
|
2
|
+
export { AdminRouterProvider, buildUrlWithParams, createBrowserAdminRouter, handleNavLinkClick, type AdminAnchorProps, type AdminLocation, type AdminRouter, useAdminLocation, useAdminRouter, } from './router';
|
|
3
3
|
export { FormDialog, type FormDialogProps } from './components/FormDialog';
|
|
4
4
|
export { OverviewPage, type OverviewPageProps } from './components/OverviewPage';
|
|
5
5
|
export { ModelPage, type ModelPageProps, type ModelPageToolbarContext } from './components/ModelPage';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
function
|
|
2
|
+
function createAdminClient(transport) {
|
|
3
3
|
return {
|
|
4
4
|
async getModels() {
|
|
5
5
|
return await transportGet(transport, "/xladmin/models/");
|
|
@@ -81,13 +81,13 @@ function createXLAdminClient(transport) {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
84
|
+
function createAxiosAdminClient(api) {
|
|
85
|
+
return createAdminClient(api);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
87
|
+
function createFetchAdminClient(config) {
|
|
88
|
+
return createAdminClient(createFetchAdminTransport(config));
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function createFetchAdminTransport(config) {
|
|
91
91
|
var _a;
|
|
92
92
|
const fetchImpl = (_a = config.fetch) != null ? _a : globalThis.fetch;
|
|
93
93
|
if (!fetchImpl) {
|
|
@@ -210,12 +210,12 @@ function buildSelectionPayload(ids, payload, options) {
|
|
|
210
210
|
// src/router.tsx
|
|
211
211
|
import { createContext, useContext, useMemo, useRef, useSyncExternalStore } from "react";
|
|
212
212
|
import { jsx } from "react/jsx-runtime";
|
|
213
|
-
var
|
|
213
|
+
var AdminRouterContext = createContext(null);
|
|
214
214
|
var browserRouterInstance = null;
|
|
215
|
-
function
|
|
216
|
-
return /* @__PURE__ */ jsx(
|
|
215
|
+
function AdminRouterProvider({ router, children }) {
|
|
216
|
+
return /* @__PURE__ */ jsx(AdminRouterContext.Provider, { value: router, children });
|
|
217
217
|
}
|
|
218
|
-
function
|
|
218
|
+
function createBrowserAdminRouter(browserWindow = window) {
|
|
219
219
|
return {
|
|
220
220
|
getLocation: () => ({
|
|
221
221
|
pathname: browserWindow.location.pathname,
|
|
@@ -241,8 +241,8 @@ function createBrowserXLAdminRouter(browserWindow = window) {
|
|
|
241
241
|
}
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
-
function
|
|
245
|
-
const contextRouter = useContext(
|
|
244
|
+
function useAdminRouter(router) {
|
|
245
|
+
const contextRouter = useContext(AdminRouterContext);
|
|
246
246
|
return useMemo(() => {
|
|
247
247
|
if (router) {
|
|
248
248
|
return router;
|
|
@@ -251,13 +251,13 @@ function useXLAdminRouter(router) {
|
|
|
251
251
|
return contextRouter;
|
|
252
252
|
}
|
|
253
253
|
if (browserRouterInstance === null) {
|
|
254
|
-
browserRouterInstance =
|
|
254
|
+
browserRouterInstance = createBrowserAdminRouter();
|
|
255
255
|
}
|
|
256
256
|
return browserRouterInstance;
|
|
257
257
|
}, [contextRouter, router]);
|
|
258
258
|
}
|
|
259
|
-
function
|
|
260
|
-
const resolvedRouter =
|
|
259
|
+
function useAdminLocation(router) {
|
|
260
|
+
const resolvedRouter = useAdminRouter(router);
|
|
261
261
|
const snapshotRef = useRef(null);
|
|
262
262
|
const getSnapshot = useMemo(() => () => {
|
|
263
263
|
const nextLocation = resolvedRouter.getLocation();
|
|
@@ -303,15 +303,7 @@ function handleNavLinkClick(event, { href, onClick, router }) {
|
|
|
303
303
|
|
|
304
304
|
// src/components/FormDialog.tsx
|
|
305
305
|
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
306
|
-
import {
|
|
307
|
-
Alert,
|
|
308
|
-
Box,
|
|
309
|
-
Button,
|
|
310
|
-
Dialog,
|
|
311
|
-
DialogActions,
|
|
312
|
-
DialogContent,
|
|
313
|
-
DialogTitle
|
|
314
|
-
} from "@mui/material";
|
|
306
|
+
import { Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
|
315
307
|
import { LocalizationProvider } from "@mui/x-date-pickers";
|
|
316
308
|
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
317
309
|
|
|
@@ -603,13 +595,7 @@ function trimAdminValue(value, maxLength) {
|
|
|
603
595
|
|
|
604
596
|
// src/components/FieldEditor.tsx
|
|
605
597
|
import { memo, useCallback, useEffect as useEffect2, useMemo as useMemo3, useState as useState2 } from "react";
|
|
606
|
-
import {
|
|
607
|
-
Autocomplete,
|
|
608
|
-
CircularProgress,
|
|
609
|
-
FormControlLabel,
|
|
610
|
-
Switch,
|
|
611
|
-
TextField
|
|
612
|
-
} from "@mui/material";
|
|
598
|
+
import { Autocomplete, CircularProgress, FormControlLabel, Switch, TextField } from "@mui/material";
|
|
613
599
|
import { DatePicker, DateTimePicker } from "@mui/x-date-pickers";
|
|
614
600
|
import dayjs from "dayjs";
|
|
615
601
|
|
|
@@ -1286,7 +1272,7 @@ function getStorageKey(blockSlug) {
|
|
|
1286
1272
|
// src/components/NavLink.tsx
|
|
1287
1273
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1288
1274
|
function NavLink({ href, children, style, title, onClick, router }) {
|
|
1289
|
-
const resolvedRouter =
|
|
1275
|
+
const resolvedRouter = useAdminRouter(router);
|
|
1290
1276
|
return /* @__PURE__ */ jsx7(
|
|
1291
1277
|
"a",
|
|
1292
1278
|
{
|
|
@@ -3103,8 +3089,8 @@ function ModelPage({ client, basePath, slug, router, renderBeforePagination }) {
|
|
|
3103
3089
|
const locale = useAdminLocale();
|
|
3104
3090
|
const t = useAdminTranslation();
|
|
3105
3091
|
const selectAllLabel = locale === "ru" ? "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0432\u0441\u0435" : "Select All";
|
|
3106
|
-
const resolvedRouter =
|
|
3107
|
-
const location =
|
|
3092
|
+
const resolvedRouter = useAdminRouter(router);
|
|
3093
|
+
const location = useAdminLocation(resolvedRouter);
|
|
3108
3094
|
const theme = useTheme2();
|
|
3109
3095
|
const isMobile = useMediaQuery2(theme.breakpoints.down("md"));
|
|
3110
3096
|
const controller = useModelPageController({
|
|
@@ -3139,7 +3125,7 @@ function ModelPage({ client, basePath, slug, router, renderBeforePagination }) {
|
|
|
3139
3125
|
appliedFilters: controller.appliedFilters,
|
|
3140
3126
|
refresh: controller.refresh
|
|
3141
3127
|
});
|
|
3142
|
-
return /* @__PURE__ */ jsx19(
|
|
3128
|
+
return /* @__PURE__ */ jsx19(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsxs12(Stack9, { spacing: 1.5, sx: { height: "100%", minHeight: 0 }, children: [
|
|
3143
3129
|
/* @__PURE__ */ jsx19(
|
|
3144
3130
|
MainHeader,
|
|
3145
3131
|
{
|
|
@@ -3541,18 +3527,7 @@ function resolveFieldSortable(field) {
|
|
|
3541
3527
|
// src/components/ObjectPage.tsx
|
|
3542
3528
|
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
|
3543
3529
|
import MoreVertIcon2 from "@mui/icons-material/MoreVert";
|
|
3544
|
-
import {
|
|
3545
|
-
Alert as Alert6,
|
|
3546
|
-
Box as Box12,
|
|
3547
|
-
Button as Button5,
|
|
3548
|
-
IconButton as IconButton4,
|
|
3549
|
-
Menu as Menu2,
|
|
3550
|
-
MenuItem as MenuItem3,
|
|
3551
|
-
Paper as Paper8,
|
|
3552
|
-
Stack as Stack12,
|
|
3553
|
-
Typography as Typography6,
|
|
3554
|
-
useMediaQuery as useMediaQuery3
|
|
3555
|
-
} from "@mui/material";
|
|
3530
|
+
import { Alert as Alert6, Box as Box12, Button as Button5, IconButton as IconButton4, Menu as Menu2, MenuItem as MenuItem3, Paper as Paper8, Stack as Stack12, Typography as Typography6, useMediaQuery as useMediaQuery3 } from "@mui/material";
|
|
3556
3531
|
import { LocalizationProvider as LocalizationProvider2 } from "@mui/x-date-pickers";
|
|
3557
3532
|
import { AdapterDayjs as AdapterDayjs2 } from "@mui/x-date-pickers/AdapterDayjs";
|
|
3558
3533
|
import { useTheme as useTheme3 } from "@mui/material/styles";
|
|
@@ -3931,8 +3906,8 @@ function ObjectPage({ client, slug, id, router }) {
|
|
|
3931
3906
|
var _a, _b;
|
|
3932
3907
|
const locale = useAdminLocale();
|
|
3933
3908
|
const t = useAdminTranslation();
|
|
3934
|
-
const resolvedRouter =
|
|
3935
|
-
const location =
|
|
3909
|
+
const resolvedRouter = useAdminRouter(router);
|
|
3910
|
+
const location = useAdminLocation(resolvedRouter);
|
|
3936
3911
|
const pathname = location.pathname;
|
|
3937
3912
|
const theme = useTheme3();
|
|
3938
3913
|
const isPhone = useMediaQuery3(theme.breakpoints.down("sm"));
|
|
@@ -3955,7 +3930,7 @@ function ObjectPage({ client, slug, id, router }) {
|
|
|
3955
3930
|
if (!controller.data || !controller.meta) {
|
|
3956
3931
|
return /* @__PURE__ */ jsx23(ObjectPageSkeleton, {});
|
|
3957
3932
|
}
|
|
3958
|
-
return /* @__PURE__ */ jsx23(
|
|
3933
|
+
return /* @__PURE__ */ jsx23(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsxs15(LocalizationProvider2, { dateAdapter: AdapterDayjs2, adapterLocale: locale, children: [
|
|
3959
3934
|
/* @__PURE__ */ jsxs15(Stack12, { spacing: 1.5, sx: { height: "100%", minHeight: 0 }, children: [
|
|
3960
3935
|
/* @__PURE__ */ jsx23(
|
|
3961
3936
|
MainHeader,
|
|
@@ -4297,7 +4272,7 @@ var defaultAdminTheme = createTheme({
|
|
|
4297
4272
|
import { Box as Box13 } from "@mui/material";
|
|
4298
4273
|
import { jsx as jsx24, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
4299
4274
|
function Main({ children }) {
|
|
4300
|
-
const { pathname } =
|
|
4275
|
+
const { pathname } = useAdminLocation();
|
|
4301
4276
|
const { pendingPath, pendingView } = useShellContext();
|
|
4302
4277
|
const normalizeAdminPath2 = (path) => {
|
|
4303
4278
|
const normalizedPath = path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
|
|
@@ -4342,7 +4317,7 @@ import { jsx as jsx25, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
|
4342
4317
|
var Sidebar = memo8(function Sidebar2({ models, blocks, basePath }) {
|
|
4343
4318
|
var _a;
|
|
4344
4319
|
const t = useAdminTranslation();
|
|
4345
|
-
const { pathname } =
|
|
4320
|
+
const { pathname } = useAdminLocation();
|
|
4346
4321
|
const { pendingPath, startPendingNavigation } = useShellContext();
|
|
4347
4322
|
const effectivePathname = pendingPath != null ? pendingPath : pathname;
|
|
4348
4323
|
const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
@@ -4413,8 +4388,8 @@ function normalizeAdminPath(path) {
|
|
|
4413
4388
|
function Shell({ client, models, blocks, basePath, locale, children, theme, router }) {
|
|
4414
4389
|
void client;
|
|
4415
4390
|
const activeTheme = theme != null ? theme : defaultAdminTheme;
|
|
4416
|
-
const resolvedRouter =
|
|
4417
|
-
const location =
|
|
4391
|
+
const resolvedRouter = useAdminRouter(router);
|
|
4392
|
+
const location = useAdminLocation(resolvedRouter);
|
|
4418
4393
|
const pathname = location.pathname;
|
|
4419
4394
|
const isDesktopSidebar = useMediaQuery4(activeTheme.breakpoints.up("lg"));
|
|
4420
4395
|
const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState11(false);
|
|
@@ -4450,7 +4425,7 @@ function Shell({ client, models, blocks, basePath, locale, children, theme, rout
|
|
|
4450
4425
|
setPendingView(view);
|
|
4451
4426
|
}
|
|
4452
4427
|
}), [isDesktopSidebar, pathname, pendingPath, pendingView]);
|
|
4453
|
-
return /* @__PURE__ */ jsx26(
|
|
4428
|
+
return /* @__PURE__ */ jsx26(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsx26(ThemeProvider, { theme: activeTheme, children: /* @__PURE__ */ jsx26(AdminLocaleProvider, { locale, children: /* @__PURE__ */ jsx26(AdminDataProvider, { value: { locale: locale === "en" ? "en" : "ru", models, blocks }, children: /* @__PURE__ */ jsxs18(ShellContextProvider, { value: shellContextValue, children: [
|
|
4454
4429
|
/* @__PURE__ */ jsx26(CssBaseline, {}),
|
|
4455
4430
|
/* @__PURE__ */ jsx26(
|
|
4456
4431
|
GlobalStyles,
|
|
@@ -4572,6 +4547,7 @@ function Shell({ client, models, blocks, basePath, locale, children, theme, rout
|
|
|
4572
4547
|
}
|
|
4573
4548
|
export {
|
|
4574
4549
|
AdminLocaleProvider,
|
|
4550
|
+
AdminRouterProvider,
|
|
4575
4551
|
DeletePreviewDialog,
|
|
4576
4552
|
FieldEditor,
|
|
4577
4553
|
FormDialog,
|
|
@@ -4584,19 +4560,18 @@ export {
|
|
|
4584
4560
|
OverviewPage,
|
|
4585
4561
|
Shell,
|
|
4586
4562
|
Sidebar,
|
|
4587
|
-
XLAdminRouterProvider,
|
|
4588
4563
|
buildUrlWithParams,
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4564
|
+
createAdminClient,
|
|
4565
|
+
createAxiosAdminClient,
|
|
4566
|
+
createBrowserAdminRouter,
|
|
4567
|
+
createFetchAdminClient,
|
|
4568
|
+
createFetchAdminTransport,
|
|
4594
4569
|
defaultAdminTheme,
|
|
4595
4570
|
handleNavLinkClick,
|
|
4596
4571
|
normalizeAdminLocale,
|
|
4597
4572
|
translateAdmin,
|
|
4598
4573
|
useAdminLocale,
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4574
|
+
useAdminLocation,
|
|
4575
|
+
useAdminRouter,
|
|
4576
|
+
useAdminTranslation
|
|
4602
4577
|
};
|
package/dist/router.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactNode } from 'react';
|
|
2
|
-
export type
|
|
2
|
+
export type AdminLocation = {
|
|
3
3
|
pathname: string;
|
|
4
4
|
search: string;
|
|
5
5
|
};
|
|
6
|
-
export type
|
|
7
|
-
getLocation: () =>
|
|
6
|
+
export type AdminRouter = {
|
|
7
|
+
getLocation: () => AdminLocation;
|
|
8
8
|
subscribe: (listener: () => void) => () => void;
|
|
9
9
|
push: (href: string) => void;
|
|
10
10
|
replace: (href: string) => void;
|
|
11
11
|
back: () => void;
|
|
12
12
|
};
|
|
13
|
-
type
|
|
14
|
-
router:
|
|
13
|
+
type AdminRouterProviderProps = {
|
|
14
|
+
router: AdminRouter;
|
|
15
15
|
children: ReactNode;
|
|
16
16
|
};
|
|
17
17
|
type NavigateLinkOptions = {
|
|
18
18
|
href: string;
|
|
19
19
|
onClick?: () => void;
|
|
20
|
-
router:
|
|
20
|
+
router: AdminRouter;
|
|
21
21
|
};
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
22
|
+
export declare function AdminRouterProvider({ router, children }: AdminRouterProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function createBrowserAdminRouter(browserWindow?: Window): AdminRouter;
|
|
24
|
+
export declare function useAdminRouter(router?: AdminRouter): AdminRouter;
|
|
25
|
+
export declare function useAdminLocation(router?: AdminRouter): AdminLocation;
|
|
26
26
|
export declare function buildUrlWithParams(pathname: string, query: string, sort: string, page: number, filters: Record<string, string>): string;
|
|
27
27
|
export declare function handleNavLinkClick(event: ReactMouseEvent<HTMLAnchorElement>, { href, onClick, router }: NavigateLinkOptions): void;
|
|
28
|
-
export type
|
|
28
|
+
export type AdminAnchorProps = {
|
|
29
29
|
href: string;
|
|
30
30
|
children: ReactNode;
|
|
31
31
|
style?: CSSProperties;
|