xladmin 0.1.0 → 0.1.5

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.
Files changed (39) hide show
  1. package/README.md +31 -24
  2. package/dist/client.d.ts +3 -1
  3. package/dist/components/DeletePreviewDialog.d.ts +13 -0
  4. package/dist/components/FieldEditor.d.ts +13 -0
  5. package/dist/components/{AdminFormDialog.d.ts → FormDialog.d.ts} +2 -1
  6. package/dist/components/ModelPage.d.ts +9 -0
  7. package/dist/components/ModelsBlocks.d.ts +10 -0
  8. package/dist/components/NavLink.d.ts +9 -0
  9. package/dist/components/ObjectPage.d.ts +11 -0
  10. package/dist/components/OverviewPage.d.ts +8 -0
  11. package/dist/components/Shell.d.ts +16 -0
  12. package/dist/components/layout/Main.d.ts +11 -0
  13. package/dist/components/layout/MainHeader.d.ts +20 -0
  14. package/dist/components/layout/Sidebar.d.ts +8 -0
  15. package/dist/components/model-page/ListRow.d.ts +15 -0
  16. package/dist/components/model-page/SearchField.d.ts +8 -0
  17. package/dist/components/model-page/Skeletons.d.ts +2 -0
  18. package/dist/components/models-blocks/BlockTitle.d.ts +7 -0
  19. package/dist/components/models-blocks/DashboardModelsBlock.d.ts +7 -0
  20. package/dist/components/models-blocks/SidebarModelsBlock.d.ts +7 -0
  21. package/dist/components/models-blocks/surface.d.ts +8 -0
  22. package/dist/components/models-blocks/types.d.ts +11 -0
  23. package/dist/components/object-page/ObjectField.d.ts +11 -0
  24. package/dist/components/object-page/ObjectPageSkeleton.d.ts +1 -0
  25. package/dist/components/object-page/ReadonlyObjectField.d.ts +7 -0
  26. package/dist/i18n.d.ts +13 -0
  27. package/dist/index.d.mts +12 -6
  28. package/dist/index.d.ts +12 -6
  29. package/dist/index.js +1761 -640
  30. package/dist/types/index.d.ts +30 -0
  31. package/dist/utils/adminFields.d.ts +7 -2
  32. package/package.json +1 -1
  33. package/dist/components/AdminFieldEditor.d.ts +0 -18
  34. package/dist/components/AdminHome.d.ts +0 -7
  35. package/dist/components/AdminModelPage.d.ts +0 -8
  36. package/dist/components/AdminObjectPage.d.ts +0 -8
  37. package/dist/components/AdminShell.d.ts +0 -14
  38. package/dist/components/AdminSidebar.d.ts +0 -7
  39. package/dist/hooks/useAdminRequest.d.ts +0 -6
package/README.md CHANGED
@@ -1,31 +1,38 @@
1
1
  # xladmin
2
2
 
3
- `xladmin` это React/MUI-библиотека для admin UI поверх backend-пакета `xladmin`.
3
+ `xladmin` это React + MUI frontend-пакет для admin UI поверх backend-пакета `xladmin`.
4
4
 
5
5
  Важно:
6
6
 
7
7
  - имя пакета в npm: `xladmin`
8
- - импорты во frontend: `from 'xladmin'`
8
+ - импорт во frontend: `from 'xladmin'`
9
+ - исходники монорепы: [Artasov/xladmin](https://github.com/Artasov/xladmin)
9
10
 
10
11
  ## Что есть в библиотеке
11
12
 
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`
13
+ - transport-agnostic `XLAdminClient`
14
+ - helpers для `axios` и `fetch`
15
+ - `Shell`, `OverviewPage`, `ModelPage`, `ObjectPage`
16
+ - `ModelsBlocks`, `FieldEditor`, `FormDialog`
17
+ - встроенный RU / EN i18n
18
+ - форматирование `date` и `datetime`
19
+ - delete preview dialog перед single delete и bulk delete
20
+ - встроенная MUI theme `defaultAdminTheme`
21
+
22
+ Короткие имена считаются основными. Старые `Admin*` имена оставлены как alias для совместимости.
23
+
24
+ ## Основной API
25
+
26
+ - `createXLAdminClient(...)`
27
+ - `createAxiosXLAdminClient(...)`
28
+ - `createFetchXLAdminClient(...)`
29
+ - `Shell`
30
+ - `OverviewPage`
31
+ - `ModelPage`
32
+ - `ObjectPage`
33
+ - `ModelsBlocks`
34
+ - `DeletePreviewDialog`
35
+ - `defaultAdminTheme`
29
36
 
30
37
  ## Совместимость
31
38
 
@@ -36,7 +43,7 @@
36
43
  - `@mui/icons-material >=7,<8`
37
44
  - `@mui/x-date-pickers >=8,<9`
38
45
  - `dayjs >=1,<2`
39
- - `axios >=1,<2` — опционально, только если проект хочет использовать axios-helper
46
+ - `axios >=1,<2` — опционально, только если проект использует axios-helper
40
47
 
41
48
  ## Как подключать
42
49
 
@@ -44,8 +51,8 @@
44
51
 
45
52
  Можно использовать:
46
53
 
47
- - `createAxiosXLAdminClient(api)` если у проекта уже есть `axios instance`
48
- - `createFetchXLAdminClient({...})` если проект работает через `fetch`
49
- - свой `XLAdminClient`, если проекту нужен полностью свой transport или особая логика
54
+ - `createAxiosXLAdminClient(api)` если проект уже живёт на `axios instance`
55
+ - `createFetchXLAdminClient({...})` если проект работает через `fetch`
56
+ - свой `XLAdminClient` если проекту нужен полностью свой transport
50
57
 
51
- Практическая инструкция вынесена в [docs/HOW_TO_USE.md](docs/HOW_TO_USE.md).
58
+ Практическая интеграция вынесена в [docs/HOW_TO_USE.md](docs/HOW_TO_USE.md).
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AdminChoicesResponse, AdminDetailResponse, AdminListResponse, AdminModelMeta, AdminModelsResponse, AdminObjectActionResponse } from './types';
1
+ import type { AdminChoicesResponse, AdminDeletePreviewResponse, AdminDetailResponse, AdminListResponse, AdminModelMeta, AdminModelsResponse, AdminObjectActionResponse } from './types';
2
2
  export type XLAdminClient = {
3
3
  getModels: () => Promise<AdminModelsResponse>;
4
4
  getModel: (slug: string) => Promise<AdminModelMeta>;
@@ -12,9 +12,11 @@ export type XLAdminClient = {
12
12
  createItem: (slug: string, payload: Record<string, unknown>) => Promise<AdminDetailResponse>;
13
13
  patchItem: (slug: string, id: string | number, payload: Record<string, unknown>) => Promise<AdminDetailResponse>;
14
14
  deleteItem: (slug: string, id: string | number) => Promise<void>;
15
+ getDeletePreview: (slug: string, id: string | number) => Promise<AdminDeletePreviewResponse>;
15
16
  bulkDelete: (slug: string, ids: Array<string | number>) => Promise<{
16
17
  deleted: number;
17
18
  }>;
19
+ getBulkDeletePreview: (slug: string, ids: Array<string | number>) => Promise<AdminDeletePreviewResponse>;
18
20
  runBulkAction: (slug: string, actionSlug: string, ids: Array<string | number>, payload?: Record<string, unknown>) => Promise<{
19
21
  processed: number;
20
22
  } & Record<string, unknown>>;
@@ -0,0 +1,13 @@
1
+ import type { AdminDeletePreviewResponse } from '../types';
2
+ type DeletePreviewDialogProps = {
3
+ open: boolean;
4
+ title: string;
5
+ preview: AdminDeletePreviewResponse | null;
6
+ error: string | null;
7
+ isLoading: boolean;
8
+ isSubmitting: boolean;
9
+ onClose: () => void;
10
+ onConfirm: () => void;
11
+ };
12
+ export declare function DeletePreviewDialog({ open, title, preview, error, isLoading, isSubmitting, onClose, onConfirm, }: DeletePreviewDialogProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
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
+ export type FieldEditorProps = AdminFieldEditorProps;
12
+ export declare const FieldEditor: import("react").NamedExoticComponent<AdminFieldEditorProps>;
13
+ export {};
@@ -12,5 +12,6 @@ type AdminFormDialogProps = {
12
12
  initialValues?: Record<string, unknown>;
13
13
  itemId?: string | number;
14
14
  };
15
- export declare function AdminFormDialog({ open, onClose, onSuccess, title, slug, mode, meta, client, initialValues, itemId, }: AdminFormDialogProps): import("react/jsx-runtime").JSX.Element;
15
+ export type FormDialogProps = AdminFormDialogProps;
16
+ export declare function FormDialog({ open, onClose, onSuccess, title, slug, mode, meta, client, initialValues, itemId, }: FormDialogProps): import("react/jsx-runtime").JSX.Element;
16
17
  export {};
@@ -0,0 +1,9 @@
1
+ import type { XLAdminClient } from '../client';
2
+ type AdminModelPageProps = {
3
+ client: XLAdminClient;
4
+ basePath: string;
5
+ slug: string;
6
+ };
7
+ export type ModelPageProps = AdminModelPageProps;
8
+ export declare function ModelPage({ client, basePath, slug }: ModelPageProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { AdminModelMeta, AdminModelsBlockMeta } from '../types';
2
+ type AdminModelsBlocksProps = {
3
+ basePath: string;
4
+ models: AdminModelMeta[];
5
+ blocks: AdminModelsBlockMeta[];
6
+ variant: 'sidebar' | 'dashboard';
7
+ };
8
+ export type ModelsBlocksProps = AdminModelsBlocksProps;
9
+ export declare const ModelsBlocks: import("react").NamedExoticComponent<AdminModelsBlocksProps>;
10
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ type AdminNavLinkProps = {
3
+ href: string;
4
+ children: ReactNode;
5
+ style?: CSSProperties;
6
+ };
7
+ export type NavLinkProps = AdminNavLinkProps;
8
+ export declare function NavLink({ href, children, style }: NavLinkProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import 'dayjs/locale/en.js';
2
+ import 'dayjs/locale/ru.js';
3
+ import type { XLAdminClient } from '../client';
4
+ type AdminObjectPageProps = {
5
+ client: XLAdminClient;
6
+ slug: string;
7
+ id: string;
8
+ };
9
+ export type ObjectPageProps = AdminObjectPageProps;
10
+ export declare function ObjectPage({ client, slug, id }: ObjectPageProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { XLAdminClient } from '../client';
2
+ type AdminHomeProps = {
3
+ client: XLAdminClient;
4
+ basePath: string;
5
+ };
6
+ export type OverviewPageProps = AdminHomeProps;
7
+ export declare function OverviewPage({ client, basePath }: OverviewPageProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type Theme } from '@mui/material/styles';
3
+ import type { XLAdminClient } from '../client';
4
+ import type { AdminModelMeta, AdminModelsBlockMeta } from '../types';
5
+ type AdminShellProps = {
6
+ client: XLAdminClient;
7
+ models: AdminModelMeta[];
8
+ blocks: AdminModelsBlockMeta[];
9
+ basePath: string;
10
+ locale?: string | null;
11
+ children: ReactNode;
12
+ theme?: Theme;
13
+ };
14
+ export type ShellProps = AdminShellProps;
15
+ export declare function Shell({ client, models, blocks, basePath, locale, children, theme }: ShellProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from 'react';
2
+ type MainProps = {
3
+ children: ReactNode;
4
+ };
5
+ /**
6
+ * Правая часть админки.
7
+ *
8
+ * Здесь живёт только текущий контент маршрута без дополнительной логики переходов.
9
+ */
10
+ export declare function Main({ children }: MainProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react';
2
+ type MainHeaderProps = {
3
+ title: ReactNode;
4
+ subtitle?: ReactNode;
5
+ details?: ReactNode;
6
+ error?: string | null;
7
+ };
8
+ /**
9
+ * Основной заголовок правой панели админки.
10
+ *
11
+ * Это именованный компонент, чтобы в DevTools был виден не анонимный `Paper`,
12
+ * а понятный `MainHeader`.
13
+ */
14
+ export declare function MainHeader({ title, subtitle, details, error }: MainHeaderProps): import("react/jsx-runtime").JSX.Element;
15
+ type MainHeaderSkeletonProps = {
16
+ titleWidth?: number | string;
17
+ subtitleWidth?: number | string;
18
+ };
19
+ export declare function MainHeaderSkeleton({ titleWidth, subtitleWidth, }: MainHeaderSkeletonProps): import("react/jsx-runtime").JSX.Element;
20
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { AdminModelMeta, AdminModelsBlockMeta } from '../../types';
2
+ type SidebarProps = {
3
+ models: AdminModelMeta[];
4
+ blocks: AdminModelsBlockMeta[];
5
+ basePath: string;
6
+ };
7
+ export declare const Sidebar: import("react").NamedExoticComponent<SidebarProps>;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { MouseEvent } from 'react';
2
+ import type { AdminFieldMeta, AdminLocale } from '../../types';
3
+ export type ListRowProps = {
4
+ row: Record<string, unknown>;
5
+ pkField: string;
6
+ listFields: string[];
7
+ basePath: string;
8
+ slug: string;
9
+ locale: AdminLocale;
10
+ fieldMap: Map<string, AdminFieldMeta>;
11
+ isSelected: boolean;
12
+ onToggleSelection: (rowId: string | number, checked: boolean) => void;
13
+ onOpenMenu: (event: MouseEvent<HTMLElement>, rowId: string | number) => void;
14
+ };
15
+ export declare const ListRow: import("react").NamedExoticComponent<ListRowProps>;
@@ -0,0 +1,8 @@
1
+ type SearchFieldProps = {
2
+ value: string;
3
+ onCommit: (value: string) => void;
4
+ debounceMs: number;
5
+ placeholder?: string;
6
+ };
7
+ export declare const SearchField: import("react").NamedExoticComponent<SearchFieldProps>;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function ModelPageSkeleton(): import("react/jsx-runtime").JSX.Element;
2
+ export declare function ModelTableSkeleton(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import type { NormalizedBlock } from './types';
2
+ type BlockTitleProps = {
3
+ block: NormalizedBlock;
4
+ compact?: boolean;
5
+ };
6
+ export declare function BlockTitle({ block, compact }: BlockTitleProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { NormalizedBlock } from './types';
2
+ type DashboardModelsBlockProps = {
3
+ block: NormalizedBlock;
4
+ basePath: string;
5
+ };
6
+ export declare function DashboardModelsBlock({ block, basePath }: DashboardModelsBlockProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { NormalizedBlock } from './types';
2
+ type SidebarModelsBlockProps = {
3
+ block: NormalizedBlock;
4
+ basePath: string;
5
+ };
6
+ export declare function SidebarModelsBlock({ block, basePath }: SidebarModelsBlockProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { NormalizedBlock } from './types';
2
+ export declare function getBlockSurfaceSx(block: NormalizedBlock, variant: 'sidebar' | 'dashboard'): {
3
+ backgroundColor: string;
4
+ backgroundImage?: undefined;
5
+ } | {
6
+ backgroundColor: string;
7
+ backgroundImage: string;
8
+ };
@@ -0,0 +1,11 @@
1
+ import type { AdminModelMeta } from '../../types';
2
+ export type NormalizedBlock = {
3
+ slug: string;
4
+ title: string;
5
+ description?: string | null;
6
+ color?: string | null;
7
+ collapsible: boolean;
8
+ default_expanded: boolean;
9
+ models: AdminModelMeta[];
10
+ isAllModels?: boolean;
11
+ };
@@ -0,0 +1,11 @@
1
+ import type { XLAdminClient } from '../../client';
2
+ import type { AdminFieldMeta } from '../../types';
3
+ type ObjectFieldProps = {
4
+ field: AdminFieldMeta;
5
+ value: unknown;
6
+ slug: string;
7
+ client: XLAdminClient;
8
+ onFieldChange: (fieldName: string, nextValue: unknown) => void;
9
+ };
10
+ export declare const ObjectField: import("react").NamedExoticComponent<ObjectFieldProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export declare function ObjectPageSkeleton(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import type { AdminFieldMeta } from '../../types';
2
+ type ReadonlyObjectFieldProps = {
3
+ field: AdminFieldMeta;
4
+ value: string;
5
+ };
6
+ export declare const ReadonlyObjectField: import("react").NamedExoticComponent<ReadonlyObjectFieldProps>;
7
+ export {};
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { AdminLocale } from './types';
3
+ type AdminTranslationKey = 'loading' | 'overview' | 'overview_title' | 'overview_subtitle' | 'all_models' | 'all_models_description' | 'models_load_error' | 'model_load_error' | 'object_load_error' | 'object_save_error' | 'object_delete_error' | 'object_action_error' | 'search' | 'create' | 'actions' | 'selected_count' | 'delete' | 'save' | 'saving' | 'deleting' | 'executing' | 'cancel' | 'objects_count' | 'yes' | 'no' | 'delete_object_title' | 'delete_bulk_title' | 'delete_preview_hint' | 'delete_preview_roots' | 'delete_preview_related' | 'delete_preview_total' | 'delete_preview_empty' | 'delete_preview_loading' | 'delete_preview_error' | 'delete_preview_no_selection' | 'staff_only';
4
+ type AdminLocaleProviderProps = {
5
+ locale?: string | null;
6
+ children: ReactNode;
7
+ };
8
+ export declare function normalizeAdminLocale(locale?: string | null): AdminLocale;
9
+ export declare function translateAdmin(locale: string | null | undefined, key: AdminTranslationKey, params?: Record<string, string | number>): string;
10
+ export declare function AdminLocaleProvider({ locale, children }: AdminLocaleProviderProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function useAdminLocale(): AdminLocale;
12
+ export declare function useAdminTranslation(): (key: AdminTranslationKey, params?: Record<string, string | number>) => string;
13
+ export {};
package/dist/index.d.mts CHANGED
@@ -1,9 +1,15 @@
1
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';
2
+ export { FormDialog, type FormDialogProps } from './components/FormDialog';
3
+ export { OverviewPage, type OverviewPageProps } from './components/OverviewPage';
4
+ export { ModelPage, type ModelPageProps } from './components/ModelPage';
5
+ export { ObjectPage, type ObjectPageProps } from './components/ObjectPage';
6
+ export { Shell, type ShellProps } from './components/Shell';
7
+ export { FieldEditor, type FieldEditorProps } from './components/FieldEditor';
8
+ export { NavLink, type NavLinkProps } from './components/NavLink';
9
+ export { ModelsBlocks, type ModelsBlocksProps } from './components/ModelsBlocks';
10
+ export * from './components/DeletePreviewDialog';
11
+ export { MainHeader, MainHeaderSkeleton } from './components/layout/MainHeader';
12
+ export * from './components/layout/Sidebar';
8
13
  export * from './theme/defaultAdminTheme';
14
+ export * from './i18n';
9
15
  export * from './types';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
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';
2
+ export { FormDialog, type FormDialogProps } from './components/FormDialog';
3
+ export { OverviewPage, type OverviewPageProps } from './components/OverviewPage';
4
+ export { ModelPage, type ModelPageProps } from './components/ModelPage';
5
+ export { ObjectPage, type ObjectPageProps } from './components/ObjectPage';
6
+ export { Shell, type ShellProps } from './components/Shell';
7
+ export { FieldEditor, type FieldEditorProps } from './components/FieldEditor';
8
+ export { NavLink, type NavLinkProps } from './components/NavLink';
9
+ export { ModelsBlocks, type ModelsBlocksProps } from './components/ModelsBlocks';
10
+ export * from './components/DeletePreviewDialog';
11
+ export { MainHeader, MainHeaderSkeleton } from './components/layout/MainHeader';
12
+ export * from './components/layout/Sidebar';
8
13
  export * from './theme/defaultAdminTheme';
14
+ export * from './i18n';
9
15
  export * from './types';