sera-components 1.6.3 → 1.6.9
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/dist/data/inputs/foreign-key-input.d.ts +3 -3
- package/dist/data/inputs/phone-number-input.d.ts +1 -0
- package/dist/form/embedded-form-item.d.ts +23 -0
- package/dist/form/embedded-form.d.ts +60 -0
- package/dist/form/form.d.ts +8 -44
- package/dist/form/index.d.ts +2 -0
- package/dist/index.js +1608 -1449
- package/dist/index.umd.cjs +7 -7
- package/dist/misc/index.d.ts +1 -0
- package/dist/misc/row.d.ts +54 -0
- package/dist/table/embedded-table.d.ts +4 -0
- package/dist/table/make-columns.d.ts +20 -0
- package/dist/table/table-action.d.ts +1 -0
- package/dist/table/table-content.d.ts +2 -0
- package/dist/table/table.d.ts +2 -0
- package/dist/utils/test-id.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { InputInterface } from '.';
|
|
2
|
-
import { Record } from 'sera-db';
|
|
2
|
+
import { NestedProperty, ObjectProperty, Record } from 'sera-db';
|
|
3
3
|
export declare const SingleForeignKeyInput: (<T>(_props: InputInterface<T>) => import("react/jsx-runtime").JSX.Element) & {
|
|
4
4
|
displayName: string;
|
|
5
5
|
};
|
|
6
6
|
export declare const MultiForeignKeyInput: (<ID extends string | number>({ db, property, value: recordIds, onChange, freeze, }: InputInterface<ID[]>) => import("react/jsx-runtime").JSX.Element) & {
|
|
7
7
|
displayName: string;
|
|
8
8
|
};
|
|
9
|
-
export declare const SearchInput: <ID extends string | number, R extends Record<ID>>({
|
|
10
|
-
|
|
9
|
+
export declare const SearchInput: <ID extends string | number, R extends Record<ID>>({ property, data, onSelect, renderOption, isIdInteger, query, setQuery, freeze, }: {
|
|
10
|
+
property: ObjectProperty | NestedProperty;
|
|
11
11
|
query: string;
|
|
12
12
|
setQuery: (query: string) => void;
|
|
13
13
|
onSelect: (id: ID) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DataProperty, DB, DraftEmbeddedRecord, ObjectProperty, NestedProperty } from 'sera-db';
|
|
2
|
+
import { InputInterface } from '../data/inputs';
|
|
3
|
+
import { FormItemLayout } from './form-item';
|
|
4
|
+
export interface EmbeddedFormItemProps<DR extends DraftEmbeddedRecord> {
|
|
5
|
+
db: DB;
|
|
6
|
+
record: DR;
|
|
7
|
+
property: DataProperty | ObjectProperty | NestedProperty;
|
|
8
|
+
InputComponent: React.FC<InputInterface<any>> | React.ComponentType<InputInterface<any>>;
|
|
9
|
+
layout?: FormItemLayout;
|
|
10
|
+
freeze?: boolean;
|
|
11
|
+
label?: React.ReactNode;
|
|
12
|
+
onChange?: (value: any) => void;
|
|
13
|
+
visible?: (record: DR) => boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A form item component for embedded records.
|
|
17
|
+
*
|
|
18
|
+
* This is a simplified version of FormItem that doesn't require a store.
|
|
19
|
+
* It directly updates the draft record's properties using the update functions.
|
|
20
|
+
*/
|
|
21
|
+
export declare const EmbeddedFormItem: (<DR extends DraftEmbeddedRecord>({ db, record, property, layout, InputComponent, freeze, label, onChange, visible, }: EmbeddedFormItemProps<DR>) => import("react/jsx-runtime").JSX.Element) & {
|
|
22
|
+
displayName: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DB, DraftEmbeddedRecord, GenericEmbeddedRecord, EmbeddedSchema, PropertyNames, NestedProperty } from 'sera-db';
|
|
2
|
+
import { FormItemLayout } from './form-item';
|
|
3
|
+
import { FieldArgs } from './form';
|
|
4
|
+
export interface EmbeddedFieldGroup<R extends GenericEmbeddedRecord<DR>, DR extends DraftEmbeddedRecord, F extends PropertyNames<DR>> {
|
|
5
|
+
name?: string;
|
|
6
|
+
fields: (F | {
|
|
7
|
+
prop: F;
|
|
8
|
+
args?: FieldArgs<R, DR>;
|
|
9
|
+
} | NestedProperty | {
|
|
10
|
+
prop: NestedProperty;
|
|
11
|
+
args?: FieldArgs<R, DR>;
|
|
12
|
+
} | ((record: DR) => React.ReactNode))[][];
|
|
13
|
+
}
|
|
14
|
+
export interface SeraEmbeddedFormProps<R extends GenericEmbeddedRecord<DR>, DR extends DraftEmbeddedRecord, PF extends PropertyNames<R>, F extends PropertyNames<DR>> {
|
|
15
|
+
schema: EmbeddedSchema<R, DR, PF, F>;
|
|
16
|
+
db: DB;
|
|
17
|
+
fieldGroups: EmbeddedFieldGroup<R, DR, F>[];
|
|
18
|
+
layout?: FormItemLayout;
|
|
19
|
+
actions?: {
|
|
20
|
+
variant: "filled" | "light" | "outline";
|
|
21
|
+
label?: React.ReactNode;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
onClick?: () => void;
|
|
24
|
+
}[];
|
|
25
|
+
record: DR;
|
|
26
|
+
styles?: React.CSSProperties;
|
|
27
|
+
className?: string;
|
|
28
|
+
onSubmit?: (record: DR) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A form component for editing embedded records that don't have their own store.
|
|
32
|
+
*
|
|
33
|
+
* This is a lightweight version of SeraForm designed for embedded schemas.
|
|
34
|
+
* It works directly with draft records and doesn't require a Table store.
|
|
35
|
+
*
|
|
36
|
+
* @template R - The record type that extends GenericEmbeddedRecord
|
|
37
|
+
* @template DR - The draft record type that extends DraftEmbeddedRecord
|
|
38
|
+
* @template PF - The type of public fields in R
|
|
39
|
+
* @template F - The type of fields in DR
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <SeraEmbeddedForm
|
|
44
|
+
* schema={roomTypeSchema}
|
|
45
|
+
* record={draftRoomType}
|
|
46
|
+
* fieldGroups={[
|
|
47
|
+
* {
|
|
48
|
+
* name: "Room Details",
|
|
49
|
+
* fields: [["code", "className"], ["bedConfiguration", "occupancyMax"]]
|
|
50
|
+
* }
|
|
51
|
+
* ]}
|
|
52
|
+
* layout={{ type: "vertical" }}
|
|
53
|
+
* actions={[
|
|
54
|
+
* { variant: "filled", label: "Save", onClick: handleSave },
|
|
55
|
+
* { variant: "outline", label: "Cancel", onClick: handleCancel }
|
|
56
|
+
* ]}
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const SeraEmbeddedForm: <R extends GenericEmbeddedRecord<DR>, DR extends DraftEmbeddedRecord, PF extends PropertyNames<R>, F extends PropertyNames<DR>>(props: SeraEmbeddedFormProps<R, DR, PF, F>) => import("react/jsx-runtime").JSX.Element;
|
package/dist/form/form.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { PropertyNames, DraftRecord, GenericRecord, Schema, SchemaType, Table, NestedProperty } from 'sera-db';
|
|
1
|
+
import { DataProperty, PropertyNames, DraftRecord, GenericRecord, ObjectProperty, Schema, SchemaType, Table, NestedProperty } from 'sera-db';
|
|
2
|
+
import { SeraColProps } from '../misc';
|
|
2
3
|
import { InputInterface } from '../data/inputs';
|
|
3
4
|
import { FormItemLayout } from './form-item';
|
|
4
|
-
|
|
5
|
+
export declare const SPAN_COL = 12;
|
|
6
|
+
export interface FieldArgs<R, DR> {
|
|
5
7
|
label?: React.ReactNode;
|
|
6
8
|
input?: React.ComponentType<InputInterface<any>>;
|
|
7
9
|
freeze?: boolean;
|
|
8
10
|
visible?: (record: R | DR) => boolean;
|
|
9
11
|
onChange?: (value: any) => void;
|
|
12
|
+
colsize?: Pick<SeraColProps, "span" | "grow">;
|
|
10
13
|
}
|
|
11
14
|
export interface FieldGroup<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>> {
|
|
12
15
|
name?: string;
|
|
@@ -68,45 +71,6 @@ export interface SeraFormProps<ID extends string | number, R extends GenericReco
|
|
|
68
71
|
* ```
|
|
69
72
|
*/
|
|
70
73
|
export declare const SeraForm: <ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>>(props: SeraFormProps<ID, R, DR, PF, F, ST>) => import("react/jsx-runtime").JSX.Element;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* This function creates a renderer that displays multiple form fields side-by-side
|
|
75
|
-
* in a flexible row layout with equal column widths.
|
|
76
|
-
*
|
|
77
|
-
* @template ID - The type of the record identifier (string or number)
|
|
78
|
-
* @template R - The generic record type extending GenericRecord
|
|
79
|
-
* @template DR - The draft record type extending DraftRecord
|
|
80
|
-
* @template PF - The type of public fields in R
|
|
81
|
-
* @template F - The type of fields in DR
|
|
82
|
-
* @template ST - The schema type that extends SchemaType
|
|
83
|
-
*
|
|
84
|
-
* @param schema - The schema definition containing property information
|
|
85
|
-
* @param fields - Array of field definitions to display in the group
|
|
86
|
-
* @param args - Optional arguments for visibility, layout, and flex properties
|
|
87
|
-
*
|
|
88
|
-
* @returns A function that takes a store and record, returning a React node with grouped form fields
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```tsx
|
|
92
|
-
* const groupedFields = groupFormFields(
|
|
93
|
-
* userSchema,
|
|
94
|
-
* [{ prop: "firstName" }, { prop: "lastName" }]
|
|
95
|
-
* );
|
|
96
|
-
* // Use in fieldGroups:
|
|
97
|
-
* fieldGroups: [{ fields: [[groupedFields]] }]
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export declare function groupFormFields<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>>(schema: Schema<ID, R, DR, PF, F, ST>, fields: (ST["allProperties"] | {
|
|
101
|
-
prop: ST["allProperties"];
|
|
102
|
-
args?: FieldArgs<R, DR>;
|
|
103
|
-
} | NestedProperty | {
|
|
104
|
-
prop: NestedProperty;
|
|
105
|
-
args?: FieldArgs<R, DR>;
|
|
106
|
-
} | ((store: Table<ID, R, DR>, record: R | DR) => React.ReactNode))[], args?: {
|
|
107
|
-
visible?: (record: R | DR) => boolean;
|
|
108
|
-
layout?: FormItemLayout;
|
|
109
|
-
flexGrow?: boolean;
|
|
110
|
-
flexGap?: import('@mantine/core').MantineSpacing;
|
|
111
|
-
}): (store: Table<ID, R, DR>, record: R | DR) => React.ReactNode;
|
|
112
|
-
export {};
|
|
74
|
+
export declare function getInputComponent(property: DataProperty | ObjectProperty | NestedProperty, input?: React.ComponentType<InputInterface<any>>): ((<ID extends string | number>({ db, property, value: recordIds, onChange, freeze, }: InputInterface<ID[]>) => import("react/jsx-runtime").JSX.Element) & {
|
|
75
|
+
displayName: string;
|
|
76
|
+
}) | import('react').FC<InputInterface<any>> | import('react').ComponentClass<InputInterface<any>, any>;
|