xladmin 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +43 -65
- 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,12 +1272,15 @@ 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
|
{
|
|
1293
1279
|
href,
|
|
1294
|
-
style
|
|
1280
|
+
style: {
|
|
1281
|
+
color: "inherit",
|
|
1282
|
+
...style
|
|
1283
|
+
},
|
|
1295
1284
|
title,
|
|
1296
1285
|
onClick: (event) => handleNavLinkClick(event, { href, onClick, router: resolvedRouter }),
|
|
1297
1286
|
children
|
|
@@ -3103,8 +3092,8 @@ function ModelPage({ client, basePath, slug, router, renderBeforePagination }) {
|
|
|
3103
3092
|
const locale = useAdminLocale();
|
|
3104
3093
|
const t = useAdminTranslation();
|
|
3105
3094
|
const selectAllLabel = locale === "ru" ? "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0432\u0441\u0435" : "Select All";
|
|
3106
|
-
const resolvedRouter =
|
|
3107
|
-
const location =
|
|
3095
|
+
const resolvedRouter = useAdminRouter(router);
|
|
3096
|
+
const location = useAdminLocation(resolvedRouter);
|
|
3108
3097
|
const theme = useTheme2();
|
|
3109
3098
|
const isMobile = useMediaQuery2(theme.breakpoints.down("md"));
|
|
3110
3099
|
const controller = useModelPageController({
|
|
@@ -3139,7 +3128,7 @@ function ModelPage({ client, basePath, slug, router, renderBeforePagination }) {
|
|
|
3139
3128
|
appliedFilters: controller.appliedFilters,
|
|
3140
3129
|
refresh: controller.refresh
|
|
3141
3130
|
});
|
|
3142
|
-
return /* @__PURE__ */ jsx19(
|
|
3131
|
+
return /* @__PURE__ */ jsx19(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsxs12(Stack9, { spacing: 1.5, sx: { height: "100%", minHeight: 0 }, children: [
|
|
3143
3132
|
/* @__PURE__ */ jsx19(
|
|
3144
3133
|
MainHeader,
|
|
3145
3134
|
{
|
|
@@ -3541,18 +3530,7 @@ function resolveFieldSortable(field) {
|
|
|
3541
3530
|
// src/components/ObjectPage.tsx
|
|
3542
3531
|
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
|
3543
3532
|
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";
|
|
3533
|
+
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
3534
|
import { LocalizationProvider as LocalizationProvider2 } from "@mui/x-date-pickers";
|
|
3557
3535
|
import { AdapterDayjs as AdapterDayjs2 } from "@mui/x-date-pickers/AdapterDayjs";
|
|
3558
3536
|
import { useTheme as useTheme3 } from "@mui/material/styles";
|
|
@@ -3931,8 +3909,8 @@ function ObjectPage({ client, slug, id, router }) {
|
|
|
3931
3909
|
var _a, _b;
|
|
3932
3910
|
const locale = useAdminLocale();
|
|
3933
3911
|
const t = useAdminTranslation();
|
|
3934
|
-
const resolvedRouter =
|
|
3935
|
-
const location =
|
|
3912
|
+
const resolvedRouter = useAdminRouter(router);
|
|
3913
|
+
const location = useAdminLocation(resolvedRouter);
|
|
3936
3914
|
const pathname = location.pathname;
|
|
3937
3915
|
const theme = useTheme3();
|
|
3938
3916
|
const isPhone = useMediaQuery3(theme.breakpoints.down("sm"));
|
|
@@ -3955,7 +3933,7 @@ function ObjectPage({ client, slug, id, router }) {
|
|
|
3955
3933
|
if (!controller.data || !controller.meta) {
|
|
3956
3934
|
return /* @__PURE__ */ jsx23(ObjectPageSkeleton, {});
|
|
3957
3935
|
}
|
|
3958
|
-
return /* @__PURE__ */ jsx23(
|
|
3936
|
+
return /* @__PURE__ */ jsx23(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsxs15(LocalizationProvider2, { dateAdapter: AdapterDayjs2, adapterLocale: locale, children: [
|
|
3959
3937
|
/* @__PURE__ */ jsxs15(Stack12, { spacing: 1.5, sx: { height: "100%", minHeight: 0 }, children: [
|
|
3960
3938
|
/* @__PURE__ */ jsx23(
|
|
3961
3939
|
MainHeader,
|
|
@@ -4297,7 +4275,7 @@ var defaultAdminTheme = createTheme({
|
|
|
4297
4275
|
import { Box as Box13 } from "@mui/material";
|
|
4298
4276
|
import { jsx as jsx24, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
4299
4277
|
function Main({ children }) {
|
|
4300
|
-
const { pathname } =
|
|
4278
|
+
const { pathname } = useAdminLocation();
|
|
4301
4279
|
const { pendingPath, pendingView } = useShellContext();
|
|
4302
4280
|
const normalizeAdminPath2 = (path) => {
|
|
4303
4281
|
const normalizedPath = path.endsWith("/") && path !== "/" ? path.slice(0, -1) : path;
|
|
@@ -4342,7 +4320,7 @@ import { jsx as jsx25, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
|
4342
4320
|
var Sidebar = memo8(function Sidebar2({ models, blocks, basePath }) {
|
|
4343
4321
|
var _a;
|
|
4344
4322
|
const t = useAdminTranslation();
|
|
4345
|
-
const { pathname } =
|
|
4323
|
+
const { pathname } = useAdminLocation();
|
|
4346
4324
|
const { pendingPath, startPendingNavigation } = useShellContext();
|
|
4347
4325
|
const effectivePathname = pendingPath != null ? pendingPath : pathname;
|
|
4348
4326
|
const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
@@ -4413,8 +4391,8 @@ function normalizeAdminPath(path) {
|
|
|
4413
4391
|
function Shell({ client, models, blocks, basePath, locale, children, theme, router }) {
|
|
4414
4392
|
void client;
|
|
4415
4393
|
const activeTheme = theme != null ? theme : defaultAdminTheme;
|
|
4416
|
-
const resolvedRouter =
|
|
4417
|
-
const location =
|
|
4394
|
+
const resolvedRouter = useAdminRouter(router);
|
|
4395
|
+
const location = useAdminLocation(resolvedRouter);
|
|
4418
4396
|
const pathname = location.pathname;
|
|
4419
4397
|
const isDesktopSidebar = useMediaQuery4(activeTheme.breakpoints.up("lg"));
|
|
4420
4398
|
const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState11(false);
|
|
@@ -4450,7 +4428,7 @@ function Shell({ client, models, blocks, basePath, locale, children, theme, rout
|
|
|
4450
4428
|
setPendingView(view);
|
|
4451
4429
|
}
|
|
4452
4430
|
}), [isDesktopSidebar, pathname, pendingPath, pendingView]);
|
|
4453
|
-
return /* @__PURE__ */ jsx26(
|
|
4431
|
+
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
4432
|
/* @__PURE__ */ jsx26(CssBaseline, {}),
|
|
4455
4433
|
/* @__PURE__ */ jsx26(
|
|
4456
4434
|
GlobalStyles,
|
|
@@ -4572,6 +4550,7 @@ function Shell({ client, models, blocks, basePath, locale, children, theme, rout
|
|
|
4572
4550
|
}
|
|
4573
4551
|
export {
|
|
4574
4552
|
AdminLocaleProvider,
|
|
4553
|
+
AdminRouterProvider,
|
|
4575
4554
|
DeletePreviewDialog,
|
|
4576
4555
|
FieldEditor,
|
|
4577
4556
|
FormDialog,
|
|
@@ -4584,19 +4563,18 @@ export {
|
|
|
4584
4563
|
OverviewPage,
|
|
4585
4564
|
Shell,
|
|
4586
4565
|
Sidebar,
|
|
4587
|
-
XLAdminRouterProvider,
|
|
4588
4566
|
buildUrlWithParams,
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4567
|
+
createAdminClient,
|
|
4568
|
+
createAxiosAdminClient,
|
|
4569
|
+
createBrowserAdminRouter,
|
|
4570
|
+
createFetchAdminClient,
|
|
4571
|
+
createFetchAdminTransport,
|
|
4594
4572
|
defaultAdminTheme,
|
|
4595
4573
|
handleNavLinkClick,
|
|
4596
4574
|
normalizeAdminLocale,
|
|
4597
4575
|
translateAdmin,
|
|
4598
4576
|
useAdminLocale,
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4577
|
+
useAdminLocation,
|
|
4578
|
+
useAdminRouter,
|
|
4579
|
+
useAdminTranslation
|
|
4602
4580
|
};
|
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;
|