@zeroman.yang/react-auto-components 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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +260 -0
  3. package/dist/adapters/xlsx.d.ts +7 -0
  4. package/dist/components/AutoChat/VirtualChatMessages.d.ts +16 -0
  5. package/dist/components/AutoChat/index.d.ts +4 -0
  6. package/dist/components/AutoChat/types.d.ts +89 -0
  7. package/dist/components/AutoChat/useChatScroll.d.ts +10 -0
  8. package/dist/components/AutoDialog/index.d.ts +46 -0
  9. package/dist/components/AutoForm/AutoForm.d.ts +2 -0
  10. package/dist/components/AutoForm/ChoiceField.d.ts +16 -0
  11. package/dist/components/AutoForm/FormField.d.ts +8 -0
  12. package/dist/components/AutoForm/index.d.ts +2 -0
  13. package/dist/components/AutoForm/types.d.ts +28 -0
  14. package/dist/components/AutoMenu/index.d.ts +35 -0
  15. package/dist/components/AutoSearchPanel/index.d.ts +21 -0
  16. package/dist/components/AutoTable/AutoTable.d.ts +2 -0
  17. package/dist/components/AutoTable/FilterEditor.d.ts +7 -0
  18. package/dist/components/AutoTable/SettingsPanel.d.ts +7 -0
  19. package/dist/components/AutoTable/TableHeader.d.ts +18 -0
  20. package/dist/components/AutoTable/export.d.ts +11 -0
  21. package/dist/components/AutoTable/features.d.ts +9 -0
  22. package/dist/components/AutoTable/index.d.ts +4 -0
  23. package/dist/components/AutoTable/settings.d.ts +34 -0
  24. package/dist/components/AutoTable/types.d.ts +107 -0
  25. package/dist/components/AutoTable/useTableData.d.ts +9 -0
  26. package/dist/components/AutoTable/useTableSettings.d.ts +7 -0
  27. package/dist/components/AutoTabs/index.d.ts +29 -0
  28. package/dist/core/AutoConfigProvider.d.ts +34 -0
  29. package/dist/core/config.d.ts +10 -0
  30. package/dist/core/i18n.d.ts +2 -0
  31. package/dist/core/query.d.ts +24 -0
  32. package/dist/core/types.d.ts +93 -0
  33. package/dist/index.d.ts +11 -0
  34. package/dist/index.js +3246 -0
  35. package/dist/internal/Popover.d.ts +16 -0
  36. package/dist/style.css +2 -0
  37. package/dist/xlsx.js +9 -0
  38. package/docs/auto-chat.md +89 -0
  39. package/docs/i18n/de/README.md +203 -0
  40. package/docs/i18n/de/auto-chat.md +82 -0
  41. package/docs/i18n/de/migration.md +71 -0
  42. package/docs/i18n/es/README.md +203 -0
  43. package/docs/i18n/es/auto-chat.md +82 -0
  44. package/docs/i18n/es/migration.md +71 -0
  45. package/docs/i18n/fr/README.md +203 -0
  46. package/docs/i18n/fr/auto-chat.md +82 -0
  47. package/docs/i18n/fr/migration.md +71 -0
  48. package/docs/i18n/ja/README.md +203 -0
  49. package/docs/i18n/ja/auto-chat.md +82 -0
  50. package/docs/i18n/ja/migration.md +71 -0
  51. package/docs/i18n/ko/README.md +203 -0
  52. package/docs/i18n/ko/auto-chat.md +82 -0
  53. package/docs/i18n/ko/migration.md +71 -0
  54. package/docs/i18n/pt-BR/README.md +203 -0
  55. package/docs/i18n/pt-BR/auto-chat.md +82 -0
  56. package/docs/i18n/pt-BR/migration.md +71 -0
  57. package/docs/i18n/ru/README.md +203 -0
  58. package/docs/i18n/ru/auto-chat.md +82 -0
  59. package/docs/i18n/ru/migration.md +71 -0
  60. package/docs/i18n/zh-CN/README.md +217 -0
  61. package/docs/i18n/zh-CN/auto-chat.md +82 -0
  62. package/docs/i18n/zh-CN/migration.md +71 -0
  63. package/docs/i18n/zh-TW/README.md +217 -0
  64. package/docs/i18n/zh-TW/auto-chat.md +82 -0
  65. package/docs/i18n/zh-TW/migration.md +71 -0
  66. package/docs/migration.md +71 -0
  67. package/package.json +111 -0
@@ -0,0 +1,4 @@
1
+ export { AutoTable } from "./AutoTable";
2
+ export type * from "./types";
3
+ export * from "./settings";
4
+ export { collectExport, toCsv, toJson } from "./export";
@@ -0,0 +1,34 @@
1
+ import { type QueryNode } from "../../core/query";
2
+ import type { TableSort } from "./types";
3
+ export interface Layout {
4
+ order: string[];
5
+ hidden: string[];
6
+ widths: Record<string, number>;
7
+ pin: Record<string, "left" | "right" | null | undefined>;
8
+ density: "inherit" | "compact" | "normal" | "comfortable";
9
+ }
10
+ export interface ExportSettings {
11
+ columns: string[];
12
+ format: "csv" | "json" | "xlsx";
13
+ scope: "page" | "filtered" | "selected";
14
+ fileName: string;
15
+ }
16
+ export interface Presets<V> {
17
+ activeId: string;
18
+ version: string | number;
19
+ presets: {
20
+ id: string;
21
+ name: string;
22
+ value: V;
23
+ }[];
24
+ }
25
+ export interface TableSettings {
26
+ layout: Presets<Layout>;
27
+ sort: Presets<TableSort[]>;
28
+ filter: Presets<QueryNode>;
29
+ export: Presets<ExportSettings>;
30
+ }
31
+ export declare function initialSettings(keys: string[], base?: Partial<Layout>): TableSettings;
32
+ export declare function active<V>(g: Presets<V>): V;
33
+ export declare function replaceActive<V>(g: Presets<V>, value: V): Presets<V>;
34
+ export declare function reconcileSettings(saved: unknown, keys: string[], versions: Partial<Record<keyof TableSettings, string | number>>, base?: Partial<Layout>): TableSettings;
@@ -0,0 +1,107 @@
1
+ import type { AutoSearchPanelProps } from "../AutoSearchPanel";
2
+ import type { CSSProperties, ReactNode, Ref } from "react";
3
+ import type { Access, ComponentSize, Field, FieldName, Option, TableDensity } from "../../core/types";
4
+ import type { QueryNode } from "../../core/query";
5
+ export interface TableSort {
6
+ id: string;
7
+ desc: boolean;
8
+ }
9
+ export interface TableQuery {
10
+ pageIndex: number;
11
+ pageSize: number;
12
+ sort: TableSort[];
13
+ filter: QueryNode;
14
+ }
15
+ export type DataSource<T> = (query: TableQuery, context: {
16
+ signal: AbortSignal;
17
+ }) => Promise<{
18
+ rows: T[];
19
+ total: number;
20
+ }>;
21
+ export type RowScope = "page" | "filtered" | "selected";
22
+ export interface AutoColumn<T extends object> extends Access {
23
+ key: FieldName<T>;
24
+ label?: string;
25
+ header?: ReactNode;
26
+ type?: "text" | "number" | "date" | "datetime" | "percentage" | "progress";
27
+ width?: number;
28
+ minWidth?: number;
29
+ hidden?: boolean;
30
+ pin?: "left" | "right";
31
+ align?: "left" | "center" | "right";
32
+ sortable?: boolean;
33
+ filterable?: boolean;
34
+ options?: readonly Option[];
35
+ format?: (value: T[FieldName<T>], row: T) => string | number;
36
+ render?: (value: T[FieldName<T>], row: T, index: number) => ReactNode;
37
+ sort?: (a: T, b: T) => number;
38
+ export?: boolean;
39
+ exportFormat?: (row: T) => unknown;
40
+ summary?: boolean | ((rows: readonly T[]) => ReactNode);
41
+ merge?: boolean;
42
+ copyable?: boolean;
43
+ }
44
+ export interface RowAction<T> {
45
+ id: string;
46
+ label: string;
47
+ hidden?: (row: T) => boolean;
48
+ disabled?: (row: T) => boolean;
49
+ onClick: (row: T) => void | Promise<void>;
50
+ }
51
+ export interface AutoTableHandle<T> {
52
+ refresh(): void;
53
+ reset(): void;
54
+ scrollToRow(id: string): void;
55
+ getSelectedRows(): T[];
56
+ export(format: "csv" | "json" | "xlsx", scope?: RowScope): Promise<void>;
57
+ }
58
+ export interface TableBaseProps<T extends object> {
59
+ id: string;
60
+ columns?: readonly AutoColumn<T>[];
61
+ rowKey: FieldName<T> | ((row: T) => string);
62
+ title?: string;
63
+ pageSize?: number;
64
+ pagination?: boolean;
65
+ query?: TableQuery;
66
+ onQueryChange?: (query: TableQuery) => void;
67
+ virtual?: boolean;
68
+ /** Numeric values size the scroll area; "auto" fills a height-constrained parent. */
69
+ height?: number | "auto";
70
+ rowHeight?: number;
71
+ size?: ComponentSize;
72
+ density?: TableDensity;
73
+ searchFields?: readonly Field<T>[];
74
+ searchLayout?: Pick<AutoSearchPanelProps<T>, "columns" | "labelPosition" | "labelAlign" | "labelWidth" | "density" | "size">;
75
+ formFields?: readonly Field<T>[];
76
+ onAdd?: (values: T) => void | Promise<void>;
77
+ onEdit?: (row: T, values: T) => void | Promise<void>;
78
+ onDelete?: (rows: readonly T[]) => void | Promise<void>;
79
+ getChildren?: (row: T) => T[] | undefined;
80
+ renderExpanded?: (row: T) => ReactNode;
81
+ expandAll?: boolean;
82
+ onSelectionChange?: (rows: T[]) => void;
83
+ toolbar?: ReactNode;
84
+ rowActions?: readonly RowAction<T>[];
85
+ rowClassName?: (row: T) => string;
86
+ rowStyle?: (row: T) => CSSProperties;
87
+ rowLoading?: (row: T) => boolean;
88
+ summaryScope?: RowScope;
89
+ /** Server aggregates for the complete filtered result, keyed by column. */
90
+ summaryValues?: Partial<Record<FieldName<T>, ReactNode>>;
91
+ versions?: Partial<Record<"layout" | "sort" | "filter" | "export", string | number>>;
92
+ exportXlsx?: (data: {
93
+ headers: string[];
94
+ rows: unknown[][];
95
+ }, options: {
96
+ fileName: string;
97
+ }) => Promise<ArrayBuffer | Uint8Array>;
98
+ empty?: ReactNode;
99
+ ref?: Ref<AutoTableHandle<T>>;
100
+ }
101
+ export type AutoTableProps<T extends object> = TableBaseProps<T> & ({
102
+ data: readonly T[];
103
+ dataSource?: never;
104
+ } | {
105
+ data?: never;
106
+ dataSource: DataSource<T>;
107
+ });
@@ -0,0 +1,9 @@
1
+ import type { DataSource, TableQuery } from "./types";
2
+ export declare function useTableData<T extends object>(data: readonly T[] | undefined, source: DataSource<T> | undefined, query: TableQuery): {
3
+ resolved: boolean;
4
+ rows: readonly T[];
5
+ total: number;
6
+ loading: boolean;
7
+ error: string;
8
+ refresh: () => void;
9
+ };
@@ -0,0 +1,7 @@
1
+ import { type Layout, type TableSettings } from "./settings";
2
+ export declare function useTableSettings(id: string, keys: string[], versions?: Partial<Record<keyof TableSettings, string | number>>, base?: Partial<Layout>): {
3
+ settings: TableSettings;
4
+ update: (next: TableSettings) => void;
5
+ error: string;
6
+ retry: () => void;
7
+ };
@@ -0,0 +1,29 @@
1
+ import { type ReactNode } from "react";
2
+ import type { Access, ComponentDensity, ComponentSize } from "../../core/types";
3
+ export interface AutoTab extends Access {
4
+ id: string;
5
+ label: string;
6
+ icon?: ReactNode;
7
+ badge?: ReactNode;
8
+ hidden?: boolean | (() => boolean);
9
+ disabled?: boolean;
10
+ content?: ReactNode;
11
+ /** A nested tab group rendered inside this tab's content panel. */
12
+ children?: readonly AutoTab[];
13
+ loading?: boolean;
14
+ onRefresh?: () => void;
15
+ defaultActive?: string;
16
+ }
17
+ export interface AutoTabsProps {
18
+ items: readonly AutoTab[];
19
+ value?: readonly string[];
20
+ defaultValue?: readonly string[];
21
+ onChange?: (path: readonly string[], item: AutoTab) => void;
22
+ /** Tab orientation. Use AutoMenu for hierarchical navigation. */
23
+ mode?: "horizontal" | "vertical";
24
+ keepMounted?: boolean;
25
+ extra?: ReactNode;
26
+ size?: ComponentSize;
27
+ density?: ComponentDensity;
28
+ }
29
+ export declare function AutoTabs({ items, value, defaultValue, onChange, mode, keepMounted, extra, size: ownSize, density: ownDensity, }: AutoTabsProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { type ReactNode } from "react";
2
+ import type { Access, AutoFormLayout, ComponentDensity, ComponentSize, FieldContext, SettingsAdapter, StorageAdapter, TableDensity, Values } from "./types";
3
+ export interface TableGlobalConfig {
4
+ density?: TableDensity;
5
+ size?: ComponentSize;
6
+ }
7
+ export interface TabsGlobalConfig {
8
+ density?: ComponentDensity;
9
+ size?: ComponentSize;
10
+ }
11
+ export interface MenuGlobalConfig {
12
+ density?: ComponentDensity;
13
+ size?: ComponentSize;
14
+ }
15
+ export interface AutoServices {
16
+ namespace: string;
17
+ size?: ComponentSize;
18
+ density?: ComponentDensity;
19
+ table?: TableGlobalConfig;
20
+ tabs?: TabsGlobalConfig;
21
+ menu?: MenuGlobalConfig;
22
+ form: AutoFormLayout;
23
+ t: (key: string, fallback?: string) => string;
24
+ canAccess: (access: Access) => boolean;
25
+ storage: StorageAdapter;
26
+ settings?: SettingsAdapter;
27
+ notify: (message: string, level: "success" | "error") => void;
28
+ fields: Record<string, (context: FieldContext<Values>) => ReactNode>;
29
+ }
30
+ export declare function AutoConfigProvider({ config, children, }: {
31
+ config?: Partial<AutoServices>;
32
+ children: ReactNode;
33
+ }): import("react").JSX.Element;
34
+ export declare function useAutoConfig(): AutoServices;
@@ -0,0 +1,10 @@
1
+ import type { Option, StorageAdapter } from "./types";
2
+ export declare function resolve<V, T>(value: V | ((values: T) => V) | undefined, values: T, fallback: V): V;
3
+ export declare function defaults<T extends object>(fields: readonly {
4
+ name?: string;
5
+ defaultValue?: unknown;
6
+ }[], initial?: Partial<T>): T;
7
+ export declare function normalizeOptions(options: readonly Option[]): readonly Option[];
8
+ export declare const safeStorage: StorageAdapter;
9
+ export declare function errorMessage(error: unknown): string;
10
+ export declare function equal(a: unknown, b: unknown): boolean;
@@ -0,0 +1,2 @@
1
+ /** Translate built-in text without changing the provider's existing t contract. */
2
+ export declare function useAutoText(): (message: string, values?: readonly unknown[]) => string;
@@ -0,0 +1,24 @@
1
+ export type QueryNode = {
2
+ kind: "condition";
3
+ field: string;
4
+ operator: "eq" | "in" | "contains" | "between" | "isNull";
5
+ value: unknown;
6
+ ignoreCase?: boolean;
7
+ } | {
8
+ kind: "group";
9
+ operator: "and" | "or";
10
+ children: readonly QueryNode[];
11
+ };
12
+ export declare const emptyQuery: QueryNode;
13
+ export interface SearchField {
14
+ name?: string;
15
+ match?: "eq" | "in" | "contains" | "between" | "isNull";
16
+ ignoreCase?: boolean;
17
+ includeNull?: boolean;
18
+ searchFields?: readonly string[];
19
+ }
20
+ export declare function buildQuery(values: object, fields: readonly SearchField[]): QueryNode;
21
+ export declare function matchesQuery(row: object, q: QueryNode): boolean;
22
+ export declare function serializeRsql(q: QueryNode): string;
23
+ /** Validate persisted/untrusted query shapes before evaluating them. */
24
+ export declare function isQueryNode(value: unknown, keys?: readonly string[], depth?: number): value is QueryNode;
@@ -0,0 +1,93 @@
1
+ import type { CSSProperties, ReactNode } from "react";
2
+ export type Values = Record<string, unknown>;
3
+ export type ComponentSize = "small" | "medium" | "large";
4
+ export type ComponentDensity = "comfortable" | "compact";
5
+ export type TableDensity = "compact" | "normal" | "comfortable";
6
+ export interface AutoFormLayout {
7
+ labelPosition?: "top" | "left";
8
+ labelAlign?: "left" | "right";
9
+ labelWidth?: CSSProperties["width"];
10
+ density?: ComponentDensity;
11
+ size?: ComponentSize;
12
+ }
13
+ export type FieldName<T> = Extract<keyof T, string>;
14
+ export type Dynamic<V, T> = V | ((values: Readonly<T>) => V);
15
+ export interface Access {
16
+ roles?: readonly string[];
17
+ permissions?: readonly string[];
18
+ }
19
+ export interface Option {
20
+ value: string | number | boolean;
21
+ label: string;
22
+ disabled?: boolean;
23
+ children?: readonly Option[];
24
+ }
25
+ export type FieldType = "input" | "email" | "textarea" | "integer" | "float" | "percentage" | "progress" | "switch" | "select" | "select-v2" | "radio" | "checkbox" | "cascader" | "autocomplete" | "date" | "datetime" | "daterange" | "datetimerange" | "upload" | "text" | "title" | "tip" | "button" | "append" | "custom";
26
+ export interface FieldContext<T extends object> {
27
+ id: string;
28
+ value: unknown;
29
+ values: Readonly<T>;
30
+ onChange: (value: unknown) => void;
31
+ disabled: boolean;
32
+ error?: string;
33
+ }
34
+ export interface FieldBase<T extends object> extends Access {
35
+ label?: string;
36
+ lang?: string;
37
+ type?: FieldType;
38
+ hidden?: Dynamic<boolean, T>;
39
+ disabled?: Dynamic<boolean, T>;
40
+ required?: boolean;
41
+ placeholder?: string;
42
+ options?: Dynamic<readonly Option[], T>;
43
+ multiple?: boolean;
44
+ span?: number;
45
+ lineBreak?: boolean;
46
+ style?: CSSProperties;
47
+ className?: string;
48
+ tip?: ReactNode;
49
+ rules?: readonly ((value: unknown, values: Readonly<T>) => string | undefined | Promise<string | undefined>)[];
50
+ render?: (context: FieldContext<T>) => ReactNode;
51
+ component?: string;
52
+ onChange?: (value: unknown, values: T) => Partial<T> | void;
53
+ min?: number;
54
+ max?: number;
55
+ step?: number;
56
+ rows?: number;
57
+ accept?: string;
58
+ upload?: (files: File[], signal: AbortSignal) => Promise<unknown>;
59
+ dateValue?: "string" | "timestamp";
60
+ shortcuts?: readonly {
61
+ label: string;
62
+ value: () => unknown;
63
+ }[];
64
+ onAction?: (values: Readonly<T>) => void;
65
+ more?: boolean;
66
+ match?: "eq" | "in" | "contains" | "between" | "isNull";
67
+ ignoreCase?: boolean;
68
+ includeNull?: boolean;
69
+ searchFields?: readonly string[];
70
+ }
71
+ export type Field<T extends object> = {
72
+ [K in FieldName<T>]: FieldBase<T> & {
73
+ name: K;
74
+ defaultValue?: T[K];
75
+ };
76
+ }[FieldName<T>] | (FieldBase<T> & {
77
+ name?: never;
78
+ type: "title" | "tip" | "append" | "button";
79
+ defaultValue?: never;
80
+ });
81
+ export type AnyField<T extends object> = FieldBase<T> & {
82
+ name?: FieldName<T>;
83
+ defaultValue?: unknown;
84
+ };
85
+ export interface StorageAdapter {
86
+ get(key: string): unknown;
87
+ set(key: string, value: unknown): void;
88
+ remove(key: string): void;
89
+ }
90
+ export interface SettingsAdapter {
91
+ load(key: string): Promise<unknown>;
92
+ save(key: string, value: unknown): Promise<void>;
93
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./core/types";
2
+ export * from "./core/config";
3
+ export * from "./core/query";
4
+ export * from "./core/AutoConfigProvider";
5
+ export * from "./components/AutoForm";
6
+ export * from "./components/AutoSearchPanel";
7
+ export * from "./components/AutoDialog";
8
+ export * from "./components/AutoTabs";
9
+ export * from "./components/AutoMenu";
10
+ export * from "./components/AutoTable";
11
+ export * from "./components/AutoChat";