@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
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormManager = void 0;
|
|
4
|
+
const utils_1 = require("./DataFormProvider/utils");
|
|
5
|
+
class FormManager {
|
|
6
|
+
contextState;
|
|
7
|
+
constructor(contextState) {
|
|
8
|
+
this.contextState = contextState;
|
|
9
|
+
}
|
|
10
|
+
get context() {
|
|
11
|
+
return this.contextState.value.current;
|
|
12
|
+
}
|
|
13
|
+
getAttribute(attributeName) {
|
|
14
|
+
return new FormAttribute(this.contextState, attributeName, this.context.schema.attributes[attributeName]);
|
|
15
|
+
}
|
|
16
|
+
getControl(name) {
|
|
17
|
+
const control = this.context.formInternal.controls.dict[name] ?? null;
|
|
18
|
+
if (!control) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return new Control(this.contextState, control);
|
|
22
|
+
}
|
|
23
|
+
getSection(name) {
|
|
24
|
+
const section = this.context.formInternal.sections.dict[name];
|
|
25
|
+
if (!section) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return new FormSection(this.contextState, section);
|
|
29
|
+
}
|
|
30
|
+
getTab(name) {
|
|
31
|
+
const tab = this.context.formInternal.tabs.dict[name];
|
|
32
|
+
if (!tab) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return new FormTab(this.contextState, tab);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.FormManager = FormManager;
|
|
39
|
+
class FormAttribute {
|
|
40
|
+
contextState;
|
|
41
|
+
attributeName;
|
|
42
|
+
attribute;
|
|
43
|
+
constructor(contextState, attributeName, attribute) {
|
|
44
|
+
this.contextState = contextState;
|
|
45
|
+
this.attributeName = attributeName;
|
|
46
|
+
this.attribute = attribute;
|
|
47
|
+
}
|
|
48
|
+
getInnerAttribute() {
|
|
49
|
+
return this.attribute;
|
|
50
|
+
}
|
|
51
|
+
setRequired(state) {
|
|
52
|
+
const control = this.contextState.value.current.formInternal.controls.dict[this.attributeName];
|
|
53
|
+
if (!control) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (control.type !== 'standard') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.contextState.setValue((prev) => {
|
|
60
|
+
return {
|
|
61
|
+
requiredFields: {
|
|
62
|
+
...prev.requiredFields,
|
|
63
|
+
[this.attributeName]: state,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getRequired() {
|
|
69
|
+
const attribute = this.attribute;
|
|
70
|
+
const control = this.contextState.value.current.formInternal.controls.dict[this.attributeName];
|
|
71
|
+
if (control.type !== 'standard') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return (0, utils_1.getIsFieldRequired)({
|
|
75
|
+
attribute,
|
|
76
|
+
control,
|
|
77
|
+
requiredFields: this.contextState.value.current.requiredFields,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
resetRequired() {
|
|
81
|
+
this.contextState.setValue((prev) => {
|
|
82
|
+
const requiredFields = { ...prev.requiredFields };
|
|
83
|
+
delete requiredFields[this.attributeName];
|
|
84
|
+
return {
|
|
85
|
+
requiredFields,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
getControls() {
|
|
90
|
+
return this.contextState.value.current.formInternal.controls.list
|
|
91
|
+
.filter((control) => control.type === 'standard' &&
|
|
92
|
+
control.attributeName === this.attributeName)
|
|
93
|
+
.map((control) => new Control(this.contextState, control));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class Control {
|
|
97
|
+
contextState;
|
|
98
|
+
control;
|
|
99
|
+
constructor(contextState, control) {
|
|
100
|
+
this.contextState = contextState;
|
|
101
|
+
this.control = control;
|
|
102
|
+
}
|
|
103
|
+
get context() {
|
|
104
|
+
return this.contextState.value.current;
|
|
105
|
+
}
|
|
106
|
+
getKey() {
|
|
107
|
+
let key = this.control.key;
|
|
108
|
+
if (!key && this.control.type === 'standard') {
|
|
109
|
+
key = this.control.attributeName;
|
|
110
|
+
}
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
113
|
+
getDisabled() {
|
|
114
|
+
if (this.control.type !== 'standard') {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const attributeName = this.control.attributeName;
|
|
118
|
+
return (0, utils_1.getIsFieldDisabled)({
|
|
119
|
+
control: this.control,
|
|
120
|
+
attribute: this.context.schema.attributes[attributeName],
|
|
121
|
+
disabledFields: this.context.disabledControls,
|
|
122
|
+
isFormReadonly: this.context.isReadonly,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
setDisabled(state) {
|
|
126
|
+
if (this.control.type !== 'standard') {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const key = this.control.attributeName;
|
|
130
|
+
this.contextState.setValue((prev) => {
|
|
131
|
+
return {
|
|
132
|
+
disabledControls: {
|
|
133
|
+
...prev.disabledControls,
|
|
134
|
+
[key]: state,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
resetDisabled() {
|
|
140
|
+
if (this.control.type !== 'standard') {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const key = this.control.attributeName;
|
|
144
|
+
this.contextState.setValue((prev) => {
|
|
145
|
+
const disabledFields = { ...prev.disabledControls };
|
|
146
|
+
delete disabledFields[key];
|
|
147
|
+
return {
|
|
148
|
+
disabledControls: disabledFields,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getHidden() {
|
|
153
|
+
return (0, utils_1.getIsControlHidden)({
|
|
154
|
+
control: this.control,
|
|
155
|
+
hiddenControls: this.context.hiddenControls,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
setHidden(state) {
|
|
159
|
+
const key = this.getKey();
|
|
160
|
+
if (!key) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.contextState.setValue((prev) => {
|
|
164
|
+
return {
|
|
165
|
+
hiddenControls: {
|
|
166
|
+
...prev.hiddenControls,
|
|
167
|
+
[key]: state,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
resetHidden() {
|
|
173
|
+
const key = this.getKey();
|
|
174
|
+
if (!key) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.contextState.setValue((prev) => {
|
|
178
|
+
const hiddenControls = { ...prev.hiddenControls };
|
|
179
|
+
delete hiddenControls[key];
|
|
180
|
+
return {
|
|
181
|
+
hiddenControls,
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
class FormSection {
|
|
187
|
+
contextState;
|
|
188
|
+
section;
|
|
189
|
+
constructor(contextState, section) {
|
|
190
|
+
this.contextState = contextState;
|
|
191
|
+
this.section = section;
|
|
192
|
+
}
|
|
193
|
+
setHidden(state) {
|
|
194
|
+
this.contextState.setValue((prev) => {
|
|
195
|
+
return {
|
|
196
|
+
hiddenSections: {
|
|
197
|
+
...prev.hiddenSections,
|
|
198
|
+
[this.section.name]: state,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
getHidden() {
|
|
204
|
+
return (this.contextState.value.current.hiddenSections[this.section.name] ??
|
|
205
|
+
this.section.hidden ??
|
|
206
|
+
false);
|
|
207
|
+
}
|
|
208
|
+
resetHidden() {
|
|
209
|
+
this.contextState.setValue((prev) => {
|
|
210
|
+
const hiddenSections = { ...prev.hiddenSections };
|
|
211
|
+
delete hiddenSections[this.section.name];
|
|
212
|
+
return {
|
|
213
|
+
hiddenSections,
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class FormTab {
|
|
219
|
+
contextState;
|
|
220
|
+
tab;
|
|
221
|
+
constructor(contextState, tab) {
|
|
222
|
+
this.contextState = contextState;
|
|
223
|
+
this.tab = tab;
|
|
224
|
+
}
|
|
225
|
+
setHidden(state) {
|
|
226
|
+
this.contextState.setValue((prev) => {
|
|
227
|
+
return {
|
|
228
|
+
hiddenTabs: {
|
|
229
|
+
...prev.hiddenTabs,
|
|
230
|
+
[this.tab.name]: state,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getHidden() {
|
|
236
|
+
return this.contextState.value.current.hiddenTabs[this.tab.name] ?? false;
|
|
237
|
+
}
|
|
238
|
+
resetHidden() {
|
|
239
|
+
this.contextState.setValue((prev) => {
|
|
240
|
+
const hiddenTabs = { ...prev.hiddenTabs };
|
|
241
|
+
delete hiddenTabs[this.tab.name];
|
|
242
|
+
return {
|
|
243
|
+
hiddenTabs,
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EVENT_KEY_ON_FIELD_CHANGE = "onFieldChange";
|
package/dataform/context.d.ts
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
|
-
import { EntityMainFormCommandItemExperience, Form } from '@headless-adminapp/core/experience/form';
|
|
1
|
+
import { EntityMainFormCommandItemExperience, Form, Section } from '@headless-adminapp/core/experience/form';
|
|
2
|
+
import { SectionControl } from '@headless-adminapp/core/experience/form/SectionControl';
|
|
3
|
+
import { Tab } from '@headless-adminapp/core/experience/form/Tab';
|
|
2
4
|
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
|
+
import { IEventManager } from '@headless-adminapp/core/store';
|
|
3
6
|
import { Data } from '@headless-adminapp/core/transport';
|
|
4
7
|
import { Nullable } from '@headless-adminapp/core/types';
|
|
8
|
+
import { SaveRecordFn } from './utils/saveRecord';
|
|
5
9
|
export type DataFormContextState<SA extends SchemaAttributes = SchemaAttributes> = {
|
|
10
|
+
contextKey: number;
|
|
6
11
|
schema: Schema<SA>;
|
|
7
12
|
form: Form<SA>;
|
|
8
13
|
recordId?: string | number;
|
|
9
14
|
cloneId?: string | number;
|
|
10
15
|
commands: EntityMainFormCommandItemExperience[][];
|
|
16
|
+
saveRecordFn: SaveRecordFn;
|
|
11
17
|
activeTab?: string;
|
|
18
|
+
disabledControls: Record<string, boolean>;
|
|
19
|
+
requiredFields: Record<string, boolean>;
|
|
20
|
+
hiddenControls: Record<string, boolean>;
|
|
21
|
+
hiddenSections: Record<string, boolean>;
|
|
22
|
+
hiddenTabs: Record<string, boolean>;
|
|
23
|
+
formInternal: {
|
|
24
|
+
controls: {
|
|
25
|
+
list: SectionControl<SA>[];
|
|
26
|
+
dict: Record<string, SectionControl<SA>>;
|
|
27
|
+
};
|
|
28
|
+
sections: {
|
|
29
|
+
list: Section<SA>[];
|
|
30
|
+
dict: Record<string, Section<SA>>;
|
|
31
|
+
};
|
|
32
|
+
tabs: {
|
|
33
|
+
dict: Record<string, Tab<SA>>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
12
36
|
record?: Data<InferredSchemaType<SA>>;
|
|
13
37
|
cloneRecord?: Data<InferredSchemaType<SA>>;
|
|
14
38
|
isReadonly?: boolean;
|
|
39
|
+
eventManager: IEventManager;
|
|
15
40
|
dataState: {
|
|
16
41
|
isFetching: boolean;
|
|
17
42
|
isError?: boolean;
|
|
@@ -11,3 +11,13 @@ export * from './useRecordTitle';
|
|
|
11
11
|
export * from './useSelectedForm';
|
|
12
12
|
export * from './useLoadFormGridPage';
|
|
13
13
|
export * from './useProcessFlowSteps';
|
|
14
|
+
export * from './useEventManager';
|
|
15
|
+
export * from './useIsControlHiddenByAttributeName';
|
|
16
|
+
export * from './useIsControlHiddenByKey';
|
|
17
|
+
export * from './useHiddenControlsManager';
|
|
18
|
+
export * from './useDisabledControlsManager';
|
|
19
|
+
export * from './useContextKey';
|
|
20
|
+
export * from './useIsControlDisabled';
|
|
21
|
+
export * from './useIsFieldRequired';
|
|
22
|
+
export * from './useRequiredFieldManager';
|
|
23
|
+
export * from './useFormManager';
|
package/dataform/hooks/index.js
CHANGED
|
@@ -27,3 +27,13 @@ __exportStar(require("./useRecordTitle"), exports);
|
|
|
27
27
|
__exportStar(require("./useSelectedForm"), exports);
|
|
28
28
|
__exportStar(require("./useLoadFormGridPage"), exports);
|
|
29
29
|
__exportStar(require("./useProcessFlowSteps"), exports);
|
|
30
|
+
__exportStar(require("./useEventManager"), exports);
|
|
31
|
+
__exportStar(require("./useIsControlHiddenByAttributeName"), exports);
|
|
32
|
+
__exportStar(require("./useIsControlHiddenByKey"), exports);
|
|
33
|
+
__exportStar(require("./useHiddenControlsManager"), exports);
|
|
34
|
+
__exportStar(require("./useDisabledControlsManager"), exports);
|
|
35
|
+
__exportStar(require("./useContextKey"), exports);
|
|
36
|
+
__exportStar(require("./useIsControlDisabled"), exports);
|
|
37
|
+
__exportStar(require("./useIsFieldRequired"), exports);
|
|
38
|
+
__exportStar(require("./useRequiredFieldManager"), exports);
|
|
39
|
+
__exportStar(require("./useFormManager"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useContextKey(): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useContextKey = useContextKey;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useContextKey() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.contextKey);
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDisabledControlsManager = useDisabledControlsManager;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const context_2 = require("../context");
|
|
8
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
9
|
+
/*** @deprecated */
|
|
10
|
+
function useDisabledControlsManager() {
|
|
11
|
+
const setValue = (0, mutable_1.useContextSetValue)(context_2.DataFormContext);
|
|
12
|
+
const dataFormContextValue = (0, context_1.useContextValue)(context_2.DataFormContext);
|
|
13
|
+
const _getIsControlDisabled = (0, react_1.useCallback)((attributeName) => {
|
|
14
|
+
const attribute = dataFormContextValue.current.schema.attributes[attributeName];
|
|
15
|
+
return (0, utils_1.getIsFieldDisabled)({
|
|
16
|
+
attribute,
|
|
17
|
+
control: dataFormContextValue.current.formInternal.controls.dict[attributeName],
|
|
18
|
+
disabledFields: dataFormContextValue.current.disabledControls,
|
|
19
|
+
isFormReadonly: dataFormContextValue.current.isReadonly,
|
|
20
|
+
});
|
|
21
|
+
}, [dataFormContextValue]);
|
|
22
|
+
const _setControlDisabled = (0, react_1.useCallback)((attributeName, state) => {
|
|
23
|
+
setValue((prev) => {
|
|
24
|
+
return {
|
|
25
|
+
disabledControls: {
|
|
26
|
+
...prev.disabledControls,
|
|
27
|
+
[attributeName]: state,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}, [setValue]);
|
|
32
|
+
const _resetControlDisabled = (0, react_1.useCallback)((key) => {
|
|
33
|
+
setValue((prev) => {
|
|
34
|
+
const _disabledControls = { ...prev.disabledControls };
|
|
35
|
+
delete _disabledControls[key];
|
|
36
|
+
return {
|
|
37
|
+
hiddenControls: _disabledControls,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}, [setValue]);
|
|
41
|
+
return {
|
|
42
|
+
getIsControlDisabled: _getIsControlDisabled,
|
|
43
|
+
setControlDisabled: _setControlDisabled,
|
|
44
|
+
resetControlDisabled: _resetControlDisabled,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useEventManager(): import("@headless-adminapp/core/store").IEventManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useEventManager = useEventManager;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useEventManager() {
|
|
7
|
+
return (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.eventManager);
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormManager = useFormManager;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const FormManager_1 = require("../FormManager");
|
|
7
|
+
function useFormManager() {
|
|
8
|
+
const context = (0, react_1.useContext)(context_1.DataFormContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useFormManager must be used within a DataFormProvider');
|
|
11
|
+
}
|
|
12
|
+
return (0, react_1.useMemo)(() => new FormManager_1.FormManager(context), [context]);
|
|
13
|
+
}
|
|
@@ -21,7 +21,6 @@ const useProgressIndicator_1 = require("../../progress-indicator/hooks/useProgre
|
|
|
21
21
|
const useOpenToastNotification_1 = require("../../toast-notification/hooks/useOpenToastNotification");
|
|
22
22
|
const transport_1 = require("../../transport");
|
|
23
23
|
const context_2 = require("../context");
|
|
24
|
-
const utils_1 = require("../utils");
|
|
25
24
|
const useFormRecord_1 = require("./useFormRecord");
|
|
26
25
|
const useFormSchema_1 = require("./useFormSchema");
|
|
27
26
|
const useSelectedForm_1 = require("./useSelectedForm");
|
|
@@ -37,6 +36,7 @@ function useFormSave() {
|
|
|
37
36
|
const { showProgressIndicator, hideProgressIndicator } = (0, useProgressIndicator_1.useProgressIndicator)();
|
|
38
37
|
const openToastNotification = (0, useOpenToastNotification_1.useOpenToastNotification)();
|
|
39
38
|
const routeResolver = (0, route_1.useRouteResolver)();
|
|
39
|
+
const saveRecord = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.saveRecordFn);
|
|
40
40
|
const client = (0, react_query_1.useQueryClient)();
|
|
41
41
|
const router = (0, route_1.useRouter)();
|
|
42
42
|
function showMessageAfterSave({ isCreatedMode }) {
|
|
@@ -66,7 +66,7 @@ function useFormSave() {
|
|
|
66
66
|
showProgressIndicator(undefined, 500);
|
|
67
67
|
}
|
|
68
68
|
try {
|
|
69
|
-
const result = await
|
|
69
|
+
const result = await saveRecord({
|
|
70
70
|
values,
|
|
71
71
|
form: form,
|
|
72
72
|
record: record,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @deprecated */
|
|
2
|
+
export declare function useHiddenControlsManager(): {
|
|
3
|
+
getIsControlHiddenByAttributeName: (attributeName: string) => boolean;
|
|
4
|
+
getIsControlHiddenByKey: (key: string) => boolean;
|
|
5
|
+
setControlHiddenByKey: (key: string, state: boolean) => void;
|
|
6
|
+
resetControlHiddenByKey: (key: string) => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useHiddenControlsManager = useHiddenControlsManager;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("@headless-adminapp/app/mutable/context");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const context_2 = require("../context");
|
|
8
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
9
|
+
/** @deprecated */
|
|
10
|
+
function useHiddenControlsManager() {
|
|
11
|
+
const setValue = (0, mutable_1.useContextSetValue)(context_2.DataFormContext);
|
|
12
|
+
const dataFormContextValue = (0, context_1.useContextValue)(context_2.DataFormContext);
|
|
13
|
+
const _getIsControlHiddenByAttributeName = (0, react_1.useCallback)((attributeName) => {
|
|
14
|
+
return (0, utils_1.getIsControlHidden)({
|
|
15
|
+
control: dataFormContextValue.current.formInternal.controls.dict[attributeName],
|
|
16
|
+
hiddenControls: dataFormContextValue.current.hiddenControls,
|
|
17
|
+
});
|
|
18
|
+
}, [dataFormContextValue]);
|
|
19
|
+
const _getIsControlHiddenByKey = (0, react_1.useCallback)((key) => {
|
|
20
|
+
return (0, utils_1.getIsControlHidden)({
|
|
21
|
+
control: dataFormContextValue.current.formInternal.controls.dict[key],
|
|
22
|
+
hiddenControls: dataFormContextValue.current.hiddenControls,
|
|
23
|
+
});
|
|
24
|
+
}, [dataFormContextValue]);
|
|
25
|
+
const _setControlHiddenByKey = (0, react_1.useCallback)((key, state) => {
|
|
26
|
+
setValue((prev) => {
|
|
27
|
+
return {
|
|
28
|
+
hiddenControls: {
|
|
29
|
+
...prev.hiddenControls,
|
|
30
|
+
[key]: state,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}, [setValue]);
|
|
35
|
+
const _resetControlHiddenByKey = (0, react_1.useCallback)((key) => {
|
|
36
|
+
setValue((prev) => {
|
|
37
|
+
const _hiddenControls = { ...prev.hiddenControls };
|
|
38
|
+
delete _hiddenControls[key];
|
|
39
|
+
return {
|
|
40
|
+
hiddenControls: _hiddenControls,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}, [setValue]);
|
|
44
|
+
return {
|
|
45
|
+
getIsControlHiddenByAttributeName: _getIsControlHiddenByAttributeName,
|
|
46
|
+
getIsControlHiddenByKey: _getIsControlHiddenByKey,
|
|
47
|
+
setControlHiddenByKey: _setControlHiddenByKey,
|
|
48
|
+
resetControlHiddenByKey: _resetControlHiddenByKey,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsControlDisabled(attributeName: string): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsControlDisabled = useIsControlDisabled;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
7
|
+
const useFormIsReadonly_1 = require("./useFormIsReadonly");
|
|
8
|
+
const useFormSchema_1 = require("./useFormSchema");
|
|
9
|
+
function useIsControlDisabled(attributeName) {
|
|
10
|
+
const disabledFields = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.disabledControls);
|
|
11
|
+
const controls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.formInternal.controls.dict);
|
|
12
|
+
const isFormReadonly = (0, useFormIsReadonly_1.useFormIsReadonly)();
|
|
13
|
+
const schema = (0, useFormSchema_1.useDataFormSchema)();
|
|
14
|
+
const attribute = schema.attributes[attributeName];
|
|
15
|
+
if (!attribute) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (!controls[attributeName]) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return (0, utils_1.getIsFieldDisabled)({
|
|
22
|
+
attribute,
|
|
23
|
+
control: controls[attributeName],
|
|
24
|
+
disabledFields: disabledFields,
|
|
25
|
+
isFormReadonly: isFormReadonly,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsControlHiddenByAttributeName(attributeName: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsControlHiddenByAttributeName = useIsControlHiddenByAttributeName;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
7
|
+
function useIsControlHiddenByAttributeName(attributeName) {
|
|
8
|
+
const hiddenControls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.hiddenControls);
|
|
9
|
+
const controls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.formInternal.controls.dict);
|
|
10
|
+
if (!controls[attributeName]) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return (0, utils_1.getIsControlHidden)({
|
|
14
|
+
control: controls[attributeName],
|
|
15
|
+
hiddenControls,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsControlHiddenByKey(key: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsControlHiddenByKey = useIsControlHiddenByKey;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
7
|
+
function useIsControlHiddenByKey(key) {
|
|
8
|
+
const hiddenControls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.hiddenControls);
|
|
9
|
+
const controls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.formInternal.controls.dict);
|
|
10
|
+
if (!controls[key]) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return (0, utils_1.getIsControlHidden)({
|
|
14
|
+
control: controls[key],
|
|
15
|
+
hiddenControls,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsFieldRequired(attributeName: string): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsFieldRequired = useIsFieldRequired;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const utils_1 = require("../DataFormProvider/utils");
|
|
7
|
+
const useFormSchema_1 = require("./useFormSchema");
|
|
8
|
+
function useIsFieldRequired(attributeName) {
|
|
9
|
+
const requiredFields = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.requiredFields);
|
|
10
|
+
const controls = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.formInternal.controls.dict);
|
|
11
|
+
const schema = (0, useFormSchema_1.useDataFormSchema)();
|
|
12
|
+
const attribute = schema.attributes[attributeName];
|
|
13
|
+
const control = controls[attributeName];
|
|
14
|
+
if (!attribute) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (!control || control.type !== 'standard') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return (0, utils_1.getIsFieldRequired)({
|
|
21
|
+
attribute,
|
|
22
|
+
control,
|
|
23
|
+
requiredFields: requiredFields,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOnFieldValueChangeListener(key: string, callback: (value: unknown) => any): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOnFieldValueChangeListener = useOnFieldValueChangeListener;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const useEventManager_1 = require("./useEventManager");
|
|
7
|
+
function useOnFieldValueChangeListener(key, callback) {
|
|
8
|
+
const eventManager = (0, useEventManager_1.useEventManager)();
|
|
9
|
+
const callbackRef = (0, react_1.useRef)(callback);
|
|
10
|
+
callbackRef.current = callback;
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
const listener = (_key, value) => {
|
|
13
|
+
const _path = _key.split('.');
|
|
14
|
+
const path = key.split('.');
|
|
15
|
+
if (_path.length !== path.length) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < path.length; i++) {
|
|
19
|
+
if (path[i] !== _path[i]) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
callbackRef.current(value);
|
|
24
|
+
};
|
|
25
|
+
eventManager.on(constants_1.EVENT_KEY_ON_FIELD_CHANGE, listener);
|
|
26
|
+
return () => {
|
|
27
|
+
eventManager.off(constants_1.EVENT_KEY_ON_FIELD_CHANGE, listener);
|
|
28
|
+
};
|
|
29
|
+
}, [key, callback, eventManager]);
|
|
30
|
+
}
|