@headless-adminapp/app 0.0.17-alpha.57 → 0.0.17-alpha.61
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/app/LayoutProvider.js +1 -1
- package/dataform/DataFormProvider/CustomHookExecuter.d.ts +5 -0
- package/dataform/DataFormProvider/CustomHookExecuter.js +14 -0
- package/dataform/DataFormProvider/DataResolver.d.ts +7 -5
- package/dataform/DataFormProvider/DataResolver.js +6 -80
- package/dataform/DataFormProvider/InitialValueResolver.js +1 -1
- package/dataform/DataFormProvider/getRecord.d.ts +3 -0
- package/dataform/DataFormProvider/getRecord.js +56 -0
- package/dataform/DataFormProvider/index.d.ts +4 -0
- package/dataform/DataFormProvider/index.js +33 -2
- package/dataform/DataFormProvider/types.d.ts +13 -0
- package/dataform/DataFormProvider/types.js +2 -0
- package/dataform/DataFormProvider/utils.d.ts +23 -0
- package/dataform/DataFormProvider/utils.js +105 -0
- package/dataform/FormManager.d.ts +57 -0
- package/dataform/FormManager.js +247 -0
- package/dataform/constants.d.ts +1 -0
- package/dataform/constants.js +4 -0
- package/dataform/context.d.ts +26 -1
- package/dataform/hooks/index.d.ts +10 -0
- package/dataform/hooks/index.js +10 -0
- package/dataform/hooks/useContextKey.d.ts +1 -0
- package/dataform/hooks/useContextKey.js +8 -0
- package/dataform/hooks/useDisabledControlsManager.d.ts +6 -0
- package/dataform/hooks/useDisabledControlsManager.js +46 -0
- package/dataform/hooks/useEventManager.d.ts +1 -0
- package/dataform/hooks/useEventManager.js +8 -0
- package/dataform/hooks/useFormManager.d.ts +2 -0
- package/dataform/hooks/useFormManager.js +13 -0
- package/dataform/hooks/useFormSave.js +2 -2
- package/dataform/hooks/useHiddenControlsManager.d.ts +7 -0
- package/dataform/hooks/useHiddenControlsManager.js +50 -0
- package/dataform/hooks/useIsControlDisabled.d.ts +1 -0
- package/dataform/hooks/useIsControlDisabled.js +27 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.js +17 -0
- package/dataform/hooks/useIsControlHiddenByKey.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByKey.js +17 -0
- package/dataform/hooks/useIsFieldRequired.d.ts +1 -0
- package/dataform/hooks/useIsFieldRequired.js +25 -0
- package/dataform/hooks/useOnFieldValueChangeListener.d.ts +1 -0
- package/dataform/hooks/useOnFieldValueChangeListener.js +30 -0
- package/dataform/hooks/useRequiredFieldManager.d.ts +6 -0
- package/dataform/hooks/useRequiredFieldManager.js +49 -0
- package/dataform/test.d.ts +57 -0
- package/dataform/test.js +247 -0
- package/dataform/utils/defaultParameters.d.ts +2 -1
- package/dataform/utils/defaultParameters.js +9 -1
- package/dataform/utils/index.d.ts +4 -2
- package/dataform/utils/index.js +28 -14
- package/dataform/utils/saveRecord.d.ts +4 -2
- package/dataform/utils/saveRecord.js +9 -4
- package/mutable/context.d.ts +3 -0
- package/mutable/context.js +8 -0
- package/package.json +3 -2
- package/providers/PageEntityFormProvider/index.d.ts +5 -1
- package/providers/PageEntityFormProvider/index.js +2 -2
- package/store/EventManager.d.ts +2 -2
- package/store/EventManager.js +2 -2
- package/transport/RestDataService/index.d.ts +2 -2
- package/transport/context.d.ts +1 -2
- package/transport/context.js +7 -7
- package/transport/hooks/useFileService.d.ts +1 -1
- package/transport/hooks/useFileService.js +0 -3
- package/transport/hooks/useRetriveRecords.d.ts +1 -1
- package/utils/getAttributeFormattedValue.d.ts +1 -0
- package/utils/getAttributeFormattedValue.js +9 -0
- package/utils/phone.d.ts +13 -0
- package/utils/phone.js +33 -0
package/app/LayoutProvider.js
CHANGED
|
@@ -40,6 +40,6 @@ const defaultDataService = {
|
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
const LayoutProvider = ({ authPlaceholder, authProps, dataService = defaultDataService, fileService, localeProps, metadataProps, queryClient = defaults_1.queryClient, routeProps, children, containers: { DialogContainer, ProgressIndicatorContainer, ToastNotificationContainer, }, }) => {
|
|
43
|
-
return ((0, jsx_runtime_1.jsx)(route_1.RouteProvider, { ...routeProps, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { ...localeProps, children: (0, jsx_runtime_1.jsx)(metadata_1.MetadataProvider, { ...metadataProps, children: (0, jsx_runtime_1.jsx)(transport_1.DataServiceContext.Provider, { value: dataService, children: (0, jsx_runtime_1.jsx)(context_1.FileServiceContext.Provider, { value: fileService ??
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(route_1.RouteProvider, { ...routeProps, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { ...localeProps, children: (0, jsx_runtime_1.jsx)(metadata_1.MetadataProvider, { ...metadataProps, children: (0, jsx_runtime_1.jsx)(transport_1.DataServiceContext.Provider, { value: dataService, children: (0, jsx_runtime_1.jsx)(context_1.FileServiceContext.Provider, { value: fileService ?? null, children: (0, jsx_runtime_1.jsx)(dialog_1.DialogProvider, { children: (0, jsx_runtime_1.jsx)(progress_indicator_1.ProgressIndicatorProvider, { children: (0, jsx_runtime_1.jsxs)(toast_notification_1.ToastNotificationProvider, { children: [(0, jsx_runtime_1.jsx)(DialogContainer, {}), (0, jsx_runtime_1.jsx)(ProgressIndicatorContainer, {}), (0, jsx_runtime_1.jsx)(ToastNotificationContainer, {}), (0, jsx_runtime_1.jsx)(auth_1.AuthProvider, { ...authProps, children: (0, jsx_runtime_1.jsx)(AuthWrapper_1.AuthWrapper, { Placeholder: authPlaceholder, children: (0, jsx_runtime_1.jsx)(recordset_1.RecordSetProvider, { children: children }) }) })] }) }) }) }) }) }) }) }) }));
|
|
44
44
|
};
|
|
45
45
|
exports.LayoutProvider = LayoutProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomHookExecuter = CustomHookExecuter;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
function CustomHookExecuter({ useHookFn, }) {
|
|
6
|
+
if (!useHookFn) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return (0, jsx_runtime_1.jsx)(CustomHookExecuterInternal, { useHookFn: useHookFn });
|
|
10
|
+
}
|
|
11
|
+
function CustomHookExecuterInternal({ useHookFn, }) {
|
|
12
|
+
useHookFn();
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
2
|
+
import { RetriveRecordFn } from './types';
|
|
3
|
+
interface DataResolverProps<SA extends SchemaAttributes> {
|
|
4
|
+
retriveRecordFn: RetriveRecordFn<SA>;
|
|
5
|
+
}
|
|
6
|
+
export declare function DataResolver<SA extends SchemaAttributes>({ retriveRecordFn, }: DataResolverProps<SA>): null;
|
|
7
|
+
export {};
|
|
@@ -1,96 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getControls = getControls;
|
|
4
|
-
exports.getColumns = getColumns;
|
|
5
3
|
exports.DataResolver = DataResolver;
|
|
6
|
-
const transport_1 = require("@headless-adminapp/core/transport");
|
|
7
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
8
5
|
const react_1 = require("react");
|
|
9
6
|
const hooks_1 = require("../../metadata/hooks");
|
|
10
7
|
const mutable_1 = require("../../mutable");
|
|
11
|
-
const
|
|
8
|
+
const transport_1 = require("../../transport");
|
|
12
9
|
const context_1 = require("../context");
|
|
13
10
|
const hooks_2 = require("../hooks");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.flatMap((tab) => tab.tabColumns)
|
|
17
|
-
.flatMap((tabColumn) => tabColumn.sections)
|
|
18
|
-
.flatMap((section) => section.controls);
|
|
19
|
-
return controls;
|
|
20
|
-
}
|
|
21
|
-
function getColumns(form, schema) {
|
|
22
|
-
const set = new Set([
|
|
23
|
-
...(form.experience.includeAttributes ?? []),
|
|
24
|
-
...(form.experience.headerControls ?? []),
|
|
25
|
-
...getControls(form)
|
|
26
|
-
.filter((control) => control.type === 'standard')
|
|
27
|
-
.map((control) => control.attributeName),
|
|
28
|
-
]);
|
|
29
|
-
if (schema.avatarAttribute) {
|
|
30
|
-
set.add(schema.avatarAttribute);
|
|
31
|
-
}
|
|
32
|
-
const columns = Array.from(set);
|
|
33
|
-
return columns;
|
|
34
|
-
}
|
|
35
|
-
async function getRecord({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
36
|
-
let record = null;
|
|
37
|
-
try {
|
|
38
|
-
record = await dataService.retriveRecord(schema.logicalName, recordId, columns);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
if (error instanceof transport_1.HttpError && error.status === 404) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
if (!record) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const controls = getControls(form);
|
|
50
|
-
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
51
|
-
for (const control of editableGridControls) {
|
|
52
|
-
if (control.type !== 'editablegrid') {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
56
|
-
const records = await dataService.retriveRecords({
|
|
57
|
-
logicalName: controlSchema.logicalName,
|
|
58
|
-
filter: {
|
|
59
|
-
type: 'and',
|
|
60
|
-
conditions: [
|
|
61
|
-
{
|
|
62
|
-
field: control.referenceAttribute,
|
|
63
|
-
operator: 'eq',
|
|
64
|
-
value: recordId,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
sort: [
|
|
69
|
-
{
|
|
70
|
-
field: controlSchema.createdAtAttribute ?? controlSchema.idAttribute,
|
|
71
|
-
order: 'asc',
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
limit: 5000,
|
|
75
|
-
search: '',
|
|
76
|
-
columns: [
|
|
77
|
-
controlSchema.idAttribute,
|
|
78
|
-
control.referenceAttribute,
|
|
79
|
-
...control.attributes,
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
record[control.attributeName] = records.records;
|
|
83
|
-
}
|
|
84
|
-
return record;
|
|
85
|
-
}
|
|
86
|
-
function DataResolver() {
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
function DataResolver({ retriveRecordFn, }) {
|
|
87
13
|
const schema = (0, hooks_2.useDataFormSchema)();
|
|
88
14
|
const form = (0, hooks_2.useSelectedForm)();
|
|
89
|
-
const dataService = (0,
|
|
15
|
+
const dataService = (0, transport_1.useDataService)();
|
|
90
16
|
const recordId = (0, hooks_2.useRecordId)();
|
|
91
17
|
const { schemaStore } = (0, hooks_1.useMetadata)();
|
|
92
18
|
const setState = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
93
|
-
const columns = (0, react_1.useMemo)(() => getColumns(form, schema), [form, schema]);
|
|
19
|
+
const columns = (0, react_1.useMemo)(() => (0, utils_1.getColumns)(form, schema), [form, schema]);
|
|
94
20
|
const queryKey = (0, react_1.useMemo)(() => ['data', 'retriveRecord', schema.logicalName, recordId, columns], [columns, recordId, schema.logicalName]);
|
|
95
21
|
const { data, refetch, isPending } = (0, react_query_1.useQuery)({
|
|
96
22
|
queryKey,
|
|
@@ -98,7 +24,7 @@ function DataResolver() {
|
|
|
98
24
|
if (!recordId) {
|
|
99
25
|
return null;
|
|
100
26
|
}
|
|
101
|
-
const record =
|
|
27
|
+
const record = retriveRecordFn({
|
|
102
28
|
columns,
|
|
103
29
|
dataService,
|
|
104
30
|
form,
|
|
@@ -14,7 +14,7 @@ function InitialValueResolver() {
|
|
|
14
14
|
const record = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.record);
|
|
15
15
|
const formInstance = (0, hooks_1.useFormInstance)();
|
|
16
16
|
const initialValues = (0, react_1.useMemo)(() => {
|
|
17
|
-
const defaultParameters = (0, defaultParameters_1.getFormDefaultParameters)(schema) ?? {};
|
|
17
|
+
const defaultParameters = (0, defaultParameters_1.getFormDefaultParameters)(schema, formConfig.experience) ?? {};
|
|
18
18
|
return (0, utils_1.getInitialValues)({
|
|
19
19
|
cloneRecord: undefined,
|
|
20
20
|
form: formConfig,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
2
|
+
import { RetriveRecordFnOptions } from './types';
|
|
3
|
+
export declare function getRecord<SA extends SchemaAttributes = SchemaAttributes>({ recordId, dataService, form, schema, columns, schemaStore, }: RetriveRecordFnOptions<SA>): Promise<import("@headless-adminapp/core/transport").Data<SA> | null>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRecord = getRecord;
|
|
4
|
+
const transport_1 = require("@headless-adminapp/core/transport");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
async function getRecord({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
7
|
+
let record = null;
|
|
8
|
+
try {
|
|
9
|
+
record = await dataService.retriveRecord(schema.logicalName, recordId, columns);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error instanceof transport_1.HttpError && error.status === 404) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
if (!record) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const controls = (0, utils_1.getControls)(form);
|
|
21
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
22
|
+
for (const control of editableGridControls) {
|
|
23
|
+
if (control.type !== 'editablegrid') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
27
|
+
const records = await dataService.retriveRecords({
|
|
28
|
+
logicalName: controlSchema.logicalName,
|
|
29
|
+
filter: {
|
|
30
|
+
type: 'and',
|
|
31
|
+
conditions: [
|
|
32
|
+
{
|
|
33
|
+
field: control.referenceAttribute,
|
|
34
|
+
operator: 'eq',
|
|
35
|
+
value: recordId,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
sort: [
|
|
40
|
+
{
|
|
41
|
+
field: controlSchema.createdAtAttribute ?? controlSchema.idAttribute,
|
|
42
|
+
order: 'asc',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
limit: 5000,
|
|
46
|
+
search: '',
|
|
47
|
+
columns: [
|
|
48
|
+
controlSchema.idAttribute,
|
|
49
|
+
control.referenceAttribute,
|
|
50
|
+
...control.attributes,
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
record[control.attributeName] = records.records;
|
|
54
|
+
}
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { EntityMainFormCommandItemExperience, Form } from '@headless-adminapp/core/experience/form';
|
|
2
2
|
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
3
|
import { PropsWithChildren } from 'react';
|
|
4
|
+
import { SaveRecordFn } from '../utils/saveRecord';
|
|
5
|
+
import { RetriveRecordFn } from './types';
|
|
4
6
|
export interface DataFormProviderProps<S extends SchemaAttributes = SchemaAttributes> {
|
|
5
7
|
schema: Schema<S>;
|
|
6
8
|
form: Form<S>;
|
|
7
9
|
recordId?: string;
|
|
8
10
|
commands: EntityMainFormCommandItemExperience[][];
|
|
11
|
+
retriveRecordFn?: RetriveRecordFn<S>;
|
|
12
|
+
saveRecordFn?: SaveRecordFn;
|
|
9
13
|
}
|
|
10
14
|
export declare function DataFormProvider<S extends SchemaAttributes = SchemaAttributes>(props: PropsWithChildren<DataFormProviderProps<S>>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataFormProvider = DataFormProvider;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const store_1 = require("@headless-adminapp/app/store");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
const react_hook_form_1 = require("react-hook-form");
|
|
7
8
|
const FormValidationStringContext_1 = require("../../form/FormValidationStringContext");
|
|
@@ -10,13 +11,19 @@ const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
|
10
11
|
const mutable_1 = require("../../mutable");
|
|
11
12
|
const context_1 = require("../context");
|
|
12
13
|
const utils_1 = require("../utils");
|
|
14
|
+
const saveRecord_1 = require("../utils/saveRecord");
|
|
15
|
+
const CustomHookExecuter_1 = require("./CustomHookExecuter");
|
|
13
16
|
const DataResolver_1 = require("./DataResolver");
|
|
17
|
+
const getRecord_1 = require("./getRecord");
|
|
14
18
|
const InitialValueResolver_1 = require("./InitialValueResolver");
|
|
15
19
|
const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
|
|
20
|
+
const utils_2 = require("./utils");
|
|
16
21
|
function DataFormProvider(props) {
|
|
17
22
|
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
18
|
-
const { language } = (0, useLocale_1.useLocale)();
|
|
23
|
+
const { language, region } = (0, useLocale_1.useLocale)();
|
|
19
24
|
const formValidationStrings = (0, FormValidationStringContext_1.useFormValidationStrings)();
|
|
25
|
+
const eventManager = (0, react_1.useMemo)(() => new store_1.EventManager(), []);
|
|
26
|
+
const contextKey = (0, react_1.useRef)(0);
|
|
20
27
|
const [formReadOnly, setFormReadOnly] = (0, react_1.useState)(false); // A trick to provide readOnly info to formInstance
|
|
21
28
|
const formInstance = (0, react_hook_form_1.useForm)({
|
|
22
29
|
mode: 'all',
|
|
@@ -28,10 +35,19 @@ function DataFormProvider(props) {
|
|
|
28
35
|
schema: props.schema,
|
|
29
36
|
strings: formValidationStrings,
|
|
30
37
|
formReadOnly,
|
|
38
|
+
region,
|
|
31
39
|
}),
|
|
32
40
|
shouldUnregister: false,
|
|
33
41
|
});
|
|
42
|
+
const saveRecordFnRef = (0, react_1.useRef)(props.saveRecordFn);
|
|
43
|
+
saveRecordFnRef.current = props.saveRecordFn;
|
|
44
|
+
const saveRecordFnInternal = (0, react_1.useCallback)(async (options) => {
|
|
45
|
+
return saveRecordFnRef.current
|
|
46
|
+
? saveRecordFnRef.current(options)
|
|
47
|
+
: (0, saveRecord_1.saveRecord)(options);
|
|
48
|
+
}, []);
|
|
34
49
|
const contextValue = (0, mutable_1.useCreateContextStore)({
|
|
50
|
+
contextKey: contextKey.current,
|
|
35
51
|
schema: props.schema,
|
|
36
52
|
form: props.form,
|
|
37
53
|
commands: props.commands,
|
|
@@ -42,14 +58,29 @@ function DataFormProvider(props) {
|
|
|
42
58
|
// formInstance,
|
|
43
59
|
// formInstanceRenderCount: 0,
|
|
44
60
|
initialValues: {},
|
|
61
|
+
saveRecordFn: saveRecordFnInternal,
|
|
62
|
+
eventManager,
|
|
63
|
+
disabledControls: {},
|
|
64
|
+
requiredFields: {},
|
|
65
|
+
hiddenControls: {},
|
|
66
|
+
hiddenSections: {},
|
|
67
|
+
hiddenTabs: {},
|
|
68
|
+
formInternal: (0, utils_2.transformFormInternal)(props.form),
|
|
45
69
|
});
|
|
46
70
|
(0, react_1.useEffect)(() => {
|
|
47
71
|
contextValue.setValue({
|
|
72
|
+
contextKey: ++contextKey.current,
|
|
48
73
|
form: props.form,
|
|
49
74
|
schema: props.schema,
|
|
50
75
|
recordId: props.recordId,
|
|
51
76
|
cloneId: undefined,
|
|
52
77
|
commands: props.commands,
|
|
78
|
+
disabledControls: {},
|
|
79
|
+
requiredFields: {},
|
|
80
|
+
hiddenControls: {},
|
|
81
|
+
hiddenSections: {},
|
|
82
|
+
hiddenTabs: {},
|
|
83
|
+
formInternal: (0, utils_2.transformFormInternal)(props.form),
|
|
53
84
|
});
|
|
54
85
|
}, [
|
|
55
86
|
props.form,
|
|
@@ -59,5 +90,5 @@ function DataFormProvider(props) {
|
|
|
59
90
|
schemaStore,
|
|
60
91
|
props.commands,
|
|
61
92
|
]);
|
|
62
|
-
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, { ...formInstance, children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, {}), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), props.children] }) }));
|
|
93
|
+
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, { ...formInstance, children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, { retriveRecordFn: props.retriveRecordFn ?? getRecord_1.getRecord }), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), (0, jsx_runtime_1.jsx)(CustomHookExecuter_1.CustomHookExecuter, { useHookFn: props.form.experience.useHookFn }), props.children] }) }));
|
|
63
94
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Form } from '@headless-adminapp/core/experience/form';
|
|
2
|
+
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
4
|
+
import { Data, IDataService } from '@headless-adminapp/core/transport';
|
|
5
|
+
export type RetriveRecordFnOptions<SA extends SchemaAttributes> = {
|
|
6
|
+
recordId: string;
|
|
7
|
+
dataService: IDataService;
|
|
8
|
+
form: Form<SA>;
|
|
9
|
+
schema: Schema<SA>;
|
|
10
|
+
columns: (keyof SA)[];
|
|
11
|
+
schemaStore: ISchemaStore;
|
|
12
|
+
};
|
|
13
|
+
export type RetriveRecordFn<SA extends SchemaAttributes> = (options: RetriveRecordFnOptions<SA>) => Promise<Data<InferredSchemaType<SA>>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AttributeBase } from '@headless-adminapp/core/attributes/AttributeBase';
|
|
2
|
+
import { Form, Section } from '@headless-adminapp/core/experience/form';
|
|
3
|
+
import { SectionControl, SectionStatndardControl } from '@headless-adminapp/core/experience/form/SectionControl';
|
|
4
|
+
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
|
+
import { DataFormContextState } from '../context';
|
|
6
|
+
export declare function getControls<SA extends SchemaAttributes>(form: Form<SA>): SectionControl<SA>[];
|
|
7
|
+
export declare function getColumns<SA extends SchemaAttributes>(form: Form<SA>, schema: Schema<SA>): (keyof SA)[];
|
|
8
|
+
export declare function transformFormInternal<SA extends SchemaAttributes>(form: Form<SA>): DataFormContextState<SA>['formInternal'];
|
|
9
|
+
export declare function getIsFieldDisabled<S extends SchemaAttributes = SchemaAttributes>({ attribute, isFormReadonly, disabledFields, control, }: {
|
|
10
|
+
attribute: AttributeBase;
|
|
11
|
+
isFormReadonly: boolean | undefined;
|
|
12
|
+
disabledFields: Record<string, boolean>;
|
|
13
|
+
control: Section<S>['controls'][0];
|
|
14
|
+
}): boolean;
|
|
15
|
+
export declare function getIsControlHidden<S extends SchemaAttributes = SchemaAttributes>({ control, hiddenControls, }: {
|
|
16
|
+
hiddenControls: Record<string, boolean>;
|
|
17
|
+
control: Section<S>['controls'][0];
|
|
18
|
+
}): boolean;
|
|
19
|
+
export declare function getIsFieldRequired<S extends SchemaAttributes = SchemaAttributes>({ attribute, control, requiredFields, }: {
|
|
20
|
+
attribute: AttributeBase;
|
|
21
|
+
requiredFields: Record<string, boolean>;
|
|
22
|
+
control: SectionStatndardControl<S>;
|
|
23
|
+
}): boolean;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getControls = getControls;
|
|
4
|
+
exports.getColumns = getColumns;
|
|
5
|
+
exports.transformFormInternal = transformFormInternal;
|
|
6
|
+
exports.getIsFieldDisabled = getIsFieldDisabled;
|
|
7
|
+
exports.getIsControlHidden = getIsControlHidden;
|
|
8
|
+
exports.getIsFieldRequired = getIsFieldRequired;
|
|
9
|
+
function getControls(form) {
|
|
10
|
+
const controls = form.experience.tabs
|
|
11
|
+
.flatMap((tab) => tab.tabColumns)
|
|
12
|
+
.flatMap((tabColumn) => tabColumn.sections)
|
|
13
|
+
.flatMap((section) => section.controls);
|
|
14
|
+
return controls;
|
|
15
|
+
}
|
|
16
|
+
function getColumns(form, schema) {
|
|
17
|
+
const set = new Set([
|
|
18
|
+
...(form.experience.includeAttributes ?? []),
|
|
19
|
+
...(form.experience.headerControls ?? []),
|
|
20
|
+
...getControls(form)
|
|
21
|
+
.filter((control) => control.type === 'standard')
|
|
22
|
+
.map((control) => control.attributeName),
|
|
23
|
+
]);
|
|
24
|
+
if (schema.avatarAttribute) {
|
|
25
|
+
set.add(schema.avatarAttribute);
|
|
26
|
+
}
|
|
27
|
+
const columns = Array.from(set);
|
|
28
|
+
return columns;
|
|
29
|
+
}
|
|
30
|
+
function transformFormInternal(form) {
|
|
31
|
+
const controls = getControls(form);
|
|
32
|
+
const dict = controls.reduce((acc, control) => {
|
|
33
|
+
let key = control.key;
|
|
34
|
+
if (!key && control.type === 'standard') {
|
|
35
|
+
key = control.attributeName;
|
|
36
|
+
}
|
|
37
|
+
if (key) {
|
|
38
|
+
acc[key] = control;
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
const sections = form.experience.tabs
|
|
43
|
+
.flatMap((tab) => tab.tabColumns)
|
|
44
|
+
.flatMap((tabColumn) => tabColumn.sections);
|
|
45
|
+
const dictBySectionKey = sections.reduce((acc, section) => {
|
|
46
|
+
acc[section.name] = section;
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
const tabsDict = form.experience.tabs.reduce((acc, tab) => {
|
|
50
|
+
acc[tab.name] = tab;
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
53
|
+
return {
|
|
54
|
+
controls: {
|
|
55
|
+
list: controls,
|
|
56
|
+
dict,
|
|
57
|
+
},
|
|
58
|
+
sections: {
|
|
59
|
+
list: sections,
|
|
60
|
+
dict: dictBySectionKey,
|
|
61
|
+
},
|
|
62
|
+
tabs: {
|
|
63
|
+
dict: tabsDict,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control, }) {
|
|
68
|
+
let disabled = isFormReadonly ?? false;
|
|
69
|
+
if (!disabled) {
|
|
70
|
+
if (control.type === 'standard' &&
|
|
71
|
+
typeof control.attributeName === 'string' &&
|
|
72
|
+
disabledFields[control.attributeName] !== undefined) {
|
|
73
|
+
disabled = disabledFields[control.attributeName];
|
|
74
|
+
}
|
|
75
|
+
else if (control.disabled !== undefined) {
|
|
76
|
+
disabled = control.disabled;
|
|
77
|
+
}
|
|
78
|
+
else if (attribute.readonly !== undefined) {
|
|
79
|
+
disabled = attribute.readonly;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return disabled;
|
|
83
|
+
}
|
|
84
|
+
function getIsControlHidden({ control, hiddenControls, }) {
|
|
85
|
+
let hidden = control.hidden ?? false;
|
|
86
|
+
let key = control.key;
|
|
87
|
+
if (!key && control.type === 'standard') {
|
|
88
|
+
key = control.attributeName;
|
|
89
|
+
}
|
|
90
|
+
if (key && hiddenControls[key] !== undefined) {
|
|
91
|
+
hidden = hiddenControls[key];
|
|
92
|
+
}
|
|
93
|
+
return hidden;
|
|
94
|
+
}
|
|
95
|
+
function getIsFieldRequired({ attribute, control, requiredFields, }) {
|
|
96
|
+
const attributeName = control.attributeName;
|
|
97
|
+
let required = attribute.required ?? false;
|
|
98
|
+
if (requiredFields[attributeName] !== undefined) {
|
|
99
|
+
required = requiredFields[attributeName];
|
|
100
|
+
}
|
|
101
|
+
else if (control.required !== undefined) {
|
|
102
|
+
required = control.required;
|
|
103
|
+
}
|
|
104
|
+
return required;
|
|
105
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Attribute } from '@headless-adminapp/core';
|
|
2
|
+
import { Section } from '@headless-adminapp/core/experience/form';
|
|
3
|
+
import { SectionControl } from '@headless-adminapp/core/experience/form/SectionControl';
|
|
4
|
+
import { Tab } from '@headless-adminapp/core/experience/form/Tab';
|
|
5
|
+
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
6
|
+
import { ContextValue } from '../mutable';
|
|
7
|
+
import { DataFormContextState } from './context';
|
|
8
|
+
export declare class FormManager<SA extends SchemaAttributes = SchemaAttributes> {
|
|
9
|
+
private readonly contextState;
|
|
10
|
+
constructor(contextState: ContextValue<DataFormContextState<SA>>);
|
|
11
|
+
private get context();
|
|
12
|
+
getAttribute(attributeName: keyof SA): FormAttribute<SA> | null;
|
|
13
|
+
getControl<C extends Control<SA>>(name: string): C | null;
|
|
14
|
+
getSection(name: string): FormSection<SA> | null;
|
|
15
|
+
getTab(name: string): FormTab<SA> | null;
|
|
16
|
+
}
|
|
17
|
+
declare class FormAttribute<SA extends SchemaAttributes = SchemaAttributes> {
|
|
18
|
+
private readonly contextState;
|
|
19
|
+
private readonly attributeName;
|
|
20
|
+
private readonly attribute;
|
|
21
|
+
constructor(contextState: ContextValue<DataFormContextState<SA>>, attributeName: keyof SA, attribute: Attribute);
|
|
22
|
+
getInnerAttribute(): Attribute;
|
|
23
|
+
setRequired(state: boolean): void;
|
|
24
|
+
getRequired(): boolean;
|
|
25
|
+
resetRequired(): void;
|
|
26
|
+
getControls(): Control<SA>[];
|
|
27
|
+
}
|
|
28
|
+
declare class Control<SA extends SchemaAttributes = SchemaAttributes> {
|
|
29
|
+
private readonly contextState;
|
|
30
|
+
private readonly control;
|
|
31
|
+
constructor(contextState: ContextValue<DataFormContextState<SA>>, control: SectionControl<SA>);
|
|
32
|
+
private get context();
|
|
33
|
+
getKey(): string | undefined;
|
|
34
|
+
getDisabled(): boolean;
|
|
35
|
+
setDisabled(state: boolean): void;
|
|
36
|
+
resetDisabled(): void;
|
|
37
|
+
getHidden(): boolean;
|
|
38
|
+
setHidden(state: boolean): void;
|
|
39
|
+
resetHidden(): void;
|
|
40
|
+
}
|
|
41
|
+
declare class FormSection<SA extends SchemaAttributes = SchemaAttributes> {
|
|
42
|
+
private readonly contextState;
|
|
43
|
+
private readonly section;
|
|
44
|
+
constructor(contextState: ContextValue<DataFormContextState<SA>>, section: Section<SA>);
|
|
45
|
+
setHidden(state: boolean): void;
|
|
46
|
+
getHidden(): boolean;
|
|
47
|
+
resetHidden(): void;
|
|
48
|
+
}
|
|
49
|
+
declare class FormTab<SA extends SchemaAttributes = SchemaAttributes> {
|
|
50
|
+
private readonly contextState;
|
|
51
|
+
private readonly tab;
|
|
52
|
+
constructor(contextState: ContextValue<DataFormContextState<SA>>, tab: Tab<SA>);
|
|
53
|
+
setHidden(state: boolean): void;
|
|
54
|
+
getHidden(): boolean;
|
|
55
|
+
resetHidden(): void;
|
|
56
|
+
}
|
|
57
|
+
export {};
|