xladmin 0.1.0

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 ADDED
@@ -0,0 +1,51 @@
1
+ # xladmin
2
+
3
+ `xladmin` это React/MUI-библиотека для admin UI поверх backend-пакета `xladmin`.
4
+
5
+ Важно:
6
+
7
+ - имя пакета в npm: `xladmin`
8
+ - импорты во frontend: `from 'xladmin'`
9
+
10
+ ## Что есть в библиотеке
11
+
12
+ - `createXLAdminClient(...)` — сборка клиента из любого совместимого transport-объекта
13
+ - `createAxiosXLAdminClient(...)` — готовый helper для `axios`
14
+ - `createFetchXLAdminClient(...)` — готовый helper для `fetch`
15
+ - `AdminShell` — общий layout админки
16
+ - `AdminHome` — главная страница со списком моделей
17
+ - `AdminModelPage` — список объектов модели
18
+ - `AdminObjectPage` — детальная страница объекта
19
+ - `defaultAdminTheme` — встроенная тема библиотеки
20
+
21
+ Основные файлы:
22
+
23
+ - `src/client.ts`
24
+ - `src/components/AdminShell.tsx`
25
+ - `src/components/AdminModelPage.tsx`
26
+ - `src/components/AdminObjectPage.tsx`
27
+ - `src/components/AdminFieldEditor.tsx`
28
+ - `src/theme/defaultAdminTheme.ts`
29
+
30
+ ## Совместимость
31
+
32
+ - `React >=19,<20`
33
+ - `React DOM >=19,<20`
34
+ - `Next >=15,<17`
35
+ - `@mui/material >=7,<8`
36
+ - `@mui/icons-material >=7,<8`
37
+ - `@mui/x-date-pickers >=8,<9`
38
+ - `dayjs >=1,<2`
39
+ - `axios >=1,<2` — опционально, только если проект хочет использовать axios-helper
40
+
41
+ ## Как подключать
42
+
43
+ Библиотека не требует именно `axios`.
44
+
45
+ Можно использовать:
46
+
47
+ - `createAxiosXLAdminClient(api)` если у проекта уже есть `axios instance`
48
+ - `createFetchXLAdminClient({...})` если проект работает через `fetch`
49
+ - свой `XLAdminClient`, если проекту нужен полностью свой transport или особая логика
50
+
51
+ Практическая инструкция вынесена в [docs/HOW_TO_USE.md](docs/HOW_TO_USE.md).
@@ -0,0 +1,46 @@
1
+ import type { AdminChoicesResponse, AdminDetailResponse, AdminListResponse, AdminModelMeta, AdminModelsResponse, AdminObjectActionResponse } from './types';
2
+ export type XLAdminClient = {
3
+ getModels: () => Promise<AdminModelsResponse>;
4
+ getModel: (slug: string) => Promise<AdminModelMeta>;
5
+ getItems: (slug: string, params?: {
6
+ limit?: number;
7
+ offset?: number;
8
+ q?: string;
9
+ sort?: string;
10
+ }) => Promise<AdminListResponse>;
11
+ getItem: (slug: string, id: string | number) => Promise<AdminDetailResponse>;
12
+ createItem: (slug: string, payload: Record<string, unknown>) => Promise<AdminDetailResponse>;
13
+ patchItem: (slug: string, id: string | number, payload: Record<string, unknown>) => Promise<AdminDetailResponse>;
14
+ deleteItem: (slug: string, id: string | number) => Promise<void>;
15
+ bulkDelete: (slug: string, ids: Array<string | number>) => Promise<{
16
+ deleted: number;
17
+ }>;
18
+ runBulkAction: (slug: string, actionSlug: string, ids: Array<string | number>, payload?: Record<string, unknown>) => Promise<{
19
+ processed: number;
20
+ } & Record<string, unknown>>;
21
+ runObjectAction: (slug: string, id: string | number, actionSlug: string, payload?: Record<string, unknown>) => Promise<AdminObjectActionResponse>;
22
+ getChoices: (slug: string, fieldName: string, q?: string, ids?: Array<string | number>) => Promise<AdminChoicesResponse>;
23
+ };
24
+ type XLAdminTransportResponse<T> = T | {
25
+ data: T;
26
+ };
27
+ export type XLAdminTransport = {
28
+ get: <T>(url: string, options?: {
29
+ params?: Record<string, unknown>;
30
+ }) => Promise<XLAdminTransportResponse<T>>;
31
+ post: <T>(url: string, body?: Record<string, unknown>) => Promise<XLAdminTransportResponse<T>>;
32
+ patch: <T>(url: string, body: Record<string, unknown>) => Promise<XLAdminTransportResponse<T>>;
33
+ delete: (url: string) => Promise<unknown>;
34
+ };
35
+ export type XLAdminAxiosLike = XLAdminTransport;
36
+ export type XLAdminFetchClientConfig = {
37
+ baseUrl: string;
38
+ fetch?: typeof globalThis.fetch;
39
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
40
+ credentials?: RequestCredentials;
41
+ };
42
+ export declare function createXLAdminClient(transport: XLAdminTransport): XLAdminClient;
43
+ export declare function createAxiosXLAdminClient(api: XLAdminAxiosLike): XLAdminClient;
44
+ export declare function createFetchXLAdminClient(config: XLAdminFetchClientConfig): XLAdminClient;
45
+ export declare function createFetchXLAdminTransport(config: XLAdminFetchClientConfig): XLAdminTransport;
46
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { XLAdminClient } from '../client';
2
+ import type { AdminFieldMeta } from '../types';
3
+ type AdminFieldEditorProps = {
4
+ field: AdminFieldMeta;
5
+ value: unknown;
6
+ onChange: (value: unknown) => void;
7
+ slug: string;
8
+ client: XLAdminClient;
9
+ readOnly?: boolean;
10
+ };
11
+ /**
12
+ * Универсальный редактор поля админки.
13
+ *
14
+ * Здесь библиотека сама подбирает виджет под тип поля, а проект при необходимости
15
+ * может переопределить это через `input_kind` на backend.
16
+ */
17
+ export declare function AdminFieldEditor({ field, value, onChange, slug, client, readOnly, }: AdminFieldEditorProps): import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { XLAdminClient } from '../client';
2
+ import type { AdminModelMeta } from '../types';
3
+ type AdminFormDialogProps = {
4
+ open: boolean;
5
+ onClose: () => void;
6
+ onSuccess: () => void;
7
+ title: string;
8
+ slug: string;
9
+ mode: 'create' | 'patch';
10
+ meta: AdminModelMeta;
11
+ client: XLAdminClient;
12
+ initialValues?: Record<string, unknown>;
13
+ itemId?: string | number;
14
+ };
15
+ export declare function AdminFormDialog({ open, onClose, onSuccess, title, slug, mode, meta, client, initialValues, itemId, }: AdminFormDialogProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { XLAdminClient } from '../client';
2
+ type AdminHomeProps = {
3
+ client: XLAdminClient;
4
+ basePath: string;
5
+ };
6
+ export declare function AdminHome({ client, basePath }: AdminHomeProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { XLAdminClient } from '../client';
2
+ type AdminModelPageProps = {
3
+ client: XLAdminClient;
4
+ basePath: string;
5
+ slug: string;
6
+ };
7
+ export declare function AdminModelPage({ client, basePath, slug }: AdminModelPageProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { XLAdminClient } from '../client';
2
+ type AdminObjectPageProps = {
3
+ client: XLAdminClient;
4
+ slug: string;
5
+ id: string;
6
+ };
7
+ export declare function AdminObjectPage({ client, slug, id }: AdminObjectPageProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type Theme } from '@mui/material/styles';
3
+ import type { XLAdminClient } from '../client';
4
+ import type { AdminModelMeta } from '../types';
5
+ type AdminShellProps = {
6
+ client: XLAdminClient;
7
+ models: AdminModelMeta[];
8
+ basePath: string;
9
+ children: ReactNode;
10
+ /** Передайте свою MUI theme сюда, если хотите переопределить дефолтную тему библиотеки. */
11
+ theme?: Theme;
12
+ };
13
+ export declare function AdminShell({ client, models, basePath, children, theme }: AdminShellProps): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { AdminModelMeta } from '../types';
2
+ type AdminSidebarProps = {
3
+ models: AdminModelMeta[];
4
+ basePath: string;
5
+ };
6
+ export declare function AdminSidebar({ models, basePath }: AdminSidebarProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare function useAdminRequest<T>(loader: () => Promise<T>, deps: unknown[]): {
2
+ data: T | null;
3
+ isLoading: boolean;
4
+ error: string | null;
5
+ setData: import("react").Dispatch<import("react").SetStateAction<T | null>>;
6
+ };
@@ -0,0 +1,9 @@
1
+ export { createAxiosXLAdminClient, createFetchXLAdminClient, createFetchXLAdminTransport, createXLAdminClient, type XLAdminAxiosLike, type XLAdminClient, type XLAdminFetchClientConfig, type XLAdminTransport, } from './client';
2
+ export * from './components/AdminFormDialog';
3
+ export * from './components/AdminHome';
4
+ export * from './components/AdminModelPage';
5
+ export * from './components/AdminObjectPage';
6
+ export * from './components/AdminShell';
7
+ export * from './components/AdminSidebar';
8
+ export * from './theme/defaultAdminTheme';
9
+ export * from './types';
@@ -0,0 +1,9 @@
1
+ export { createAxiosXLAdminClient, createFetchXLAdminClient, createFetchXLAdminTransport, createXLAdminClient, type XLAdminAxiosLike, type XLAdminClient, type XLAdminFetchClientConfig, type XLAdminTransport, } from './client';
2
+ export * from './components/AdminFormDialog';
3
+ export * from './components/AdminHome';
4
+ export * from './components/AdminModelPage';
5
+ export * from './components/AdminObjectPage';
6
+ export * from './components/AdminShell';
7
+ export * from './components/AdminSidebar';
8
+ export * from './theme/defaultAdminTheme';
9
+ export * from './types';