@headless-adminapp/app 0.0.17-alpha.59 → 0.0.17-alpha.62

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 (63) hide show
  1. package/app/LayoutProvider.js +1 -1
  2. package/dataform/DataFormProvider/CustomHookExecuter.d.ts +5 -0
  3. package/dataform/DataFormProvider/CustomHookExecuter.js +14 -0
  4. package/dataform/DataFormProvider/DataResolver.d.ts +7 -5
  5. package/dataform/DataFormProvider/DataResolver.js +6 -80
  6. package/dataform/DataFormProvider/InitialValueResolver.js +1 -1
  7. package/dataform/DataFormProvider/getRecord.d.ts +3 -0
  8. package/dataform/DataFormProvider/getRecord.js +56 -0
  9. package/dataform/DataFormProvider/index.d.ts +4 -0
  10. package/dataform/DataFormProvider/index.js +31 -1
  11. package/dataform/DataFormProvider/types.d.ts +13 -0
  12. package/dataform/DataFormProvider/types.js +2 -0
  13. package/dataform/DataFormProvider/utils.d.ts +23 -0
  14. package/dataform/DataFormProvider/utils.js +105 -0
  15. package/dataform/FormManager.d.ts +57 -0
  16. package/dataform/FormManager.js +247 -0
  17. package/dataform/constants.d.ts +1 -0
  18. package/dataform/constants.js +4 -0
  19. package/dataform/context.d.ts +26 -1
  20. package/dataform/hooks/index.d.ts +10 -0
  21. package/dataform/hooks/index.js +10 -0
  22. package/dataform/hooks/useContextKey.d.ts +1 -0
  23. package/dataform/hooks/useContextKey.js +8 -0
  24. package/dataform/hooks/useDisabledControlsManager.d.ts +6 -0
  25. package/dataform/hooks/useDisabledControlsManager.js +46 -0
  26. package/dataform/hooks/useEventManager.d.ts +1 -0
  27. package/dataform/hooks/useEventManager.js +8 -0
  28. package/dataform/hooks/useFormManager.d.ts +2 -0
  29. package/dataform/hooks/useFormManager.js +13 -0
  30. package/dataform/hooks/useFormSave.js +2 -2
  31. package/dataform/hooks/useHiddenControlsManager.d.ts +7 -0
  32. package/dataform/hooks/useHiddenControlsManager.js +50 -0
  33. package/dataform/hooks/useIsControlDisabled.d.ts +1 -0
  34. package/dataform/hooks/useIsControlDisabled.js +27 -0
  35. package/dataform/hooks/useIsControlHiddenByAttributeName.d.ts +1 -0
  36. package/dataform/hooks/useIsControlHiddenByAttributeName.js +17 -0
  37. package/dataform/hooks/useIsControlHiddenByKey.d.ts +1 -0
  38. package/dataform/hooks/useIsControlHiddenByKey.js +17 -0
  39. package/dataform/hooks/useIsFieldRequired.d.ts +1 -0
  40. package/dataform/hooks/useIsFieldRequired.js +25 -0
  41. package/dataform/hooks/useOnFieldValueChangeListener.d.ts +1 -0
  42. package/dataform/hooks/useOnFieldValueChangeListener.js +30 -0
  43. package/dataform/hooks/useRequiredFieldManager.d.ts +6 -0
  44. package/dataform/hooks/useRequiredFieldManager.js +49 -0
  45. package/dataform/test.d.ts +57 -0
  46. package/dataform/test.js +247 -0
  47. package/dataform/utils/defaultParameters.d.ts +4 -1
  48. package/dataform/utils/defaultParameters.js +15 -4
  49. package/dataform/utils/index.js +5 -5
  50. package/dataform/utils/saveRecord.d.ts +4 -2
  51. package/dataform/utils/saveRecord.js +9 -4
  52. package/mutable/context.d.ts +3 -0
  53. package/mutable/context.js +8 -0
  54. package/package.json +2 -2
  55. package/providers/PageEntityFormProvider/index.d.ts +5 -1
  56. package/providers/PageEntityFormProvider/index.js +2 -2
  57. package/store/EventManager.d.ts +2 -2
  58. package/store/EventManager.js +2 -2
  59. package/transport/RestDataService/index.d.ts +2 -2
  60. package/transport/context.d.ts +1 -2
  61. package/transport/context.js +7 -7
  62. package/transport/hooks/useFileService.d.ts +1 -1
  63. package/transport/hooks/useFileService.js +0 -3
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRequiredFieldManager = useRequiredFieldManager;
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 useRequiredFieldManager() {
11
+ const setValue = (0, mutable_1.useContextSetValue)(context_2.DataFormContext);
12
+ const dataFormContextValue = (0, context_1.useContextValue)(context_2.DataFormContext);
13
+ const _getIsFieldRequired = (0, react_1.useCallback)((attributeName) => {
14
+ const attribute = dataFormContextValue.current.schema.attributes[attributeName];
15
+ const control = dataFormContextValue.current.formInternal.controls.dict[attributeName];
16
+ if (control.type !== 'standard') {
17
+ return false;
18
+ }
19
+ return (0, utils_1.getIsFieldRequired)({
20
+ attribute,
21
+ control,
22
+ requiredFields: dataFormContextValue.current.requiredFields,
23
+ });
24
+ }, [dataFormContextValue]);
25
+ const _setFieldRequired = (0, react_1.useCallback)((attributeName, state) => {
26
+ setValue((prev) => {
27
+ return {
28
+ requiredFields: {
29
+ ...prev.requiredFields,
30
+ [attributeName]: state,
31
+ },
32
+ };
33
+ });
34
+ }, [setValue]);
35
+ const _resetFieldRequired = (0, react_1.useCallback)((key) => {
36
+ setValue((prev) => {
37
+ const _requiredFields = { ...prev.requiredFields };
38
+ delete _requiredFields[key];
39
+ return {
40
+ requiredFields: _requiredFields,
41
+ };
42
+ });
43
+ }, [setValue]);
44
+ return {
45
+ getIsFieldRequired: _getIsFieldRequired,
46
+ setFieldRequired: _setFieldRequired,
47
+ resetFieldRequired: _resetFieldRequired,
48
+ };
49
+ }
@@ -0,0 +1,57 @@
1
+ import { Attribute } from '@headless-adminapp/core';
2
+ import { SectionControl } from '@headless-adminapp/core/experience/form/SectionControl';
3
+ import { SchemaAttributes } from '@headless-adminapp/core/schema';
4
+ import { ContextValue } from '../mutable';
5
+ import { DataFormContextState } from './context';
6
+ import { Section } from '@headless-adminapp/core/experience/form';
7
+ import { Tab } from '@headless-adminapp/core/experience/form/Tab';
8
+ export declare class FormUiManager<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 {};
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormUiManager = void 0;
4
+ const utils_1 = require("./DataFormProvider/utils");
5
+ class FormUiManager {
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.FormUiManager = FormUiManager;
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
+ }
@@ -1,3 +1,6 @@
1
+ import { FormExperience } from '@headless-adminapp/core/experience/form';
1
2
  import { Schema } from '@headless-adminapp/core/schema';
2
- export declare function getFormDefaultParameters(schema: Schema): Record<string, any>;
3
+ export declare function getFormDefaultParameters(schema: Schema, formExperience: FormExperience): {
4
+ [x: string]: any;
5
+ };
3
6
  export declare function setFormDefaultParameters(logicalName: string, values: Record<string, any>): void;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFormDefaultParameters = getFormDefaultParameters;
4
4
  exports.setFormDefaultParameters = setFormDefaultParameters;
5
5
  let formDefaultParameters = null;
6
- function getFormDefaultParameters(schema) {
6
+ function getFormDefaultParameters(schema, formExperience) {
7
7
  const _values = formDefaultParameters?.values;
8
8
  const _logicalName = formDefaultParameters?.logicalName;
9
9
  const schemaDefaultValues = Object.keys(schema.attributes).reduce((acc, key) => {
@@ -20,13 +20,24 @@ function getFormDefaultParameters(schema) {
20
20
  [key]: defaultValue,
21
21
  };
22
22
  }, {});
23
+ let formDefaultValues = {};
24
+ if (typeof formExperience.defaultValues === 'function') {
25
+ formDefaultValues = formExperience.defaultValues();
26
+ }
27
+ else if (typeof formExperience.defaultValues === 'object') {
28
+ formDefaultValues = formExperience.defaultValues;
29
+ }
30
+ let defaultValues = {
31
+ ...schemaDefaultValues,
32
+ ...formDefaultValues,
33
+ };
23
34
  if (_logicalName === schema.logicalName) {
24
- return {
25
- ...schemaDefaultValues,
35
+ defaultValues = {
36
+ ...defaultValues,
26
37
  ..._values,
27
38
  };
28
39
  }
29
- return schemaDefaultValues;
40
+ return defaultValues;
30
41
  }
31
42
  let defaultParamsTimeout = null;
32
43
  function setFormDefaultParameters(logicalName, values) {
@@ -29,13 +29,13 @@ const phone_1 = require("@headless-adminapp/app/utils/phone");
29
29
  const yup_1 = require("@hookform/resolvers/yup");
30
30
  const lodash_1 = require("lodash");
31
31
  const yup = __importStar(require("yup"));
32
- const DataResolver_1 = require("../../dataform/DataFormProvider/DataResolver");
33
- const utils_1 = require("../../locale/utils");
32
+ const utils_1 = require("../../dataform/DataFormProvider/utils");
33
+ const utils_2 = require("../../locale/utils");
34
34
  var saveRecord_1 = require("./saveRecord");
35
35
  Object.defineProperty(exports, "saveRecord", { enumerable: true, get: function () { return saveRecord_1.saveRecord; } });
36
36
  function getInitialValues({ cloneRecord, form, record, recordId, schema, defaultParameters, }) {
37
- const formColumns = (0, DataResolver_1.getColumns)(form, schema);
38
- const editableGridControls = (0, DataResolver_1.getControls)(form).filter((control) => control.type === 'editablegrid');
37
+ const formColumns = (0, utils_1.getColumns)(form, schema);
38
+ const editableGridControls = (0, utils_1.getControls)(form).filter((control) => control.type === 'editablegrid');
39
39
  const allColumns = [
40
40
  ...formColumns,
41
41
  ...editableGridControls.map((x) => x.attributeName),
@@ -301,7 +301,7 @@ function extendAttributeAttachmentsValidationSchema({ attribute, validationSchem
301
301
  }
302
302
  exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function generateAttributeValidationSchema(attribute, language, strings, region) {
303
303
  let validationSchema = createAttributeValidationSchema(attribute);
304
- const label = (0, utils_1.localizedLabel)(language, attribute);
304
+ const label = (0, utils_2.localizedLabel)(language, attribute);
305
305
  validationSchema = extendAttributeRequiredValidationSchema({
306
306
  attribute,
307
307
  validationSchema,
@@ -13,7 +13,7 @@ type SaveRecordResult = {
13
13
  message: string;
14
14
  isError: boolean;
15
15
  };
16
- export declare function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }: {
16
+ export interface SaveRecordFnOptions {
17
17
  values: any;
18
18
  form: Form<SchemaAttributes>;
19
19
  record: InferredSchemaType<SchemaAttributes> | undefined;
@@ -21,5 +21,7 @@ export declare function saveRecord({ values, form, schema, dataService, initialV
21
21
  schema: Schema<SchemaAttributes>;
22
22
  dataService: IDataService;
23
23
  schemaStore: ISchemaStore;
24
- }): Promise<SaveRecordResult>;
24
+ }
25
+ export type SaveRecordFn = (options: SaveRecordFnOptions) => Promise<SaveRecordResult>;
26
+ export declare function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }: SaveRecordFnOptions): Promise<SaveRecordResult>;
25
27
  export {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getModifiedValues = getModifiedValues;
4
4
  exports.saveRecord = saveRecord;
5
- const DataResolver_1 = require("../../dataform/DataFormProvider/DataResolver");
5
+ const utils_1 = require("../../dataform/DataFormProvider/utils");
6
6
  function getModifiedValues(initialValues, values, exclude) {
7
7
  const keys = Object.keys(values);
8
8
  return keys.reduce((p, c) => {
@@ -78,7 +78,7 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
78
78
  return operations;
79
79
  }
80
80
  async function createRecord({ values, form, schema, dataService, }) {
81
- const controls = (0, DataResolver_1.getControls)(form);
81
+ const controls = (0, utils_1.getControls)(form);
82
82
  const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
83
83
  const result = await dataService.createRecord(schema.logicalName, values);
84
84
  const recordId = result[schema.idAttribute];
@@ -96,7 +96,7 @@ async function createRecord({ values, form, schema, dataService, }) {
96
96
  return recordId;
97
97
  }
98
98
  async function updateRecord({ recordId, values, form, schema, dataService, initialValues, schemaStore, }) {
99
- const controls = (0, DataResolver_1.getControls)(form);
99
+ const controls = (0, utils_1.getControls)(form);
100
100
  const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
101
101
  const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.attributeName));
102
102
  const operations = [];
@@ -128,12 +128,16 @@ async function updateRecord({ recordId, values, form, schema, dataService, initi
128
128
  for (const operation of operations) {
129
129
  await executeOperation(operation, dataService);
130
130
  }
131
+ return {
132
+ success: true,
133
+ recordId,
134
+ };
131
135
  }
132
136
  async function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
133
137
  let recordId;
134
138
  if (record) {
135
139
  recordId = record[schema.idAttribute];
136
- await updateRecord({
140
+ const updateResult = await updateRecord({
137
141
  recordId,
138
142
  values,
139
143
  form,
@@ -142,6 +146,7 @@ async function saveRecord({ values, form, schema, dataService, initialValues, re
142
146
  initialValues,
143
147
  schemaStore,
144
148
  });
149
+ return updateResult;
145
150
  }
146
151
  else {
147
152
  recordId = await createRecord({
@@ -4,6 +4,9 @@ export type ContextValue<T> = MutableValue<T>;
4
4
  export declare const useContextSelectorInternal: typeof useMutableValueSelector;
5
5
  export declare function createContext<T>(): import("react").Context<ContextValue<T>>;
6
6
  export declare function useCreateContextStore<T>(initialValue: T): MutableValue<T>;
7
+ export declare function useContextValue<T>(context: React.Context<ContextValue<T>>): {
8
+ current: T;
9
+ };
7
10
  export declare function useContextSelector<T, R>(context: React.Context<ContextValue<T>>, selector: (state: T) => R): R;
8
11
  export declare function useContextSetValue<T>(context: React.Context<ContextValue<T>>): (value: Partial<T> | ((state: T) => Partial<T>)) => void;
9
12
  type Setter<T, U extends unknown[]> = (setValue: ContextValue<T>['setValue']) => (...args: U) => void;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useContextSelectorInternal = void 0;
4
4
  exports.createContext = createContext;
5
5
  exports.useCreateContextStore = useCreateContextStore;
6
+ exports.useContextValue = useContextValue;
6
7
  exports.useContextSelector = useContextSelector;
7
8
  exports.useContextSetValue = useContextSetValue;
8
9
  exports.useContextValueSetter = useContextValueSetter;
@@ -18,6 +19,13 @@ function useCreateContextStore(initialValue) {
18
19
  const [state] = (0, react_1.useState)(() => createContextValue(initialValue));
19
20
  return state;
20
21
  }
22
+ function useContextValue(context) {
23
+ const contextValue = (0, react_1.useContext)(context);
24
+ if (!contextValue) {
25
+ throw new Error('useContextValue must be used within a Provider');
26
+ }
27
+ return contextValue.value;
28
+ }
21
29
  function useContextSelector(context, selector) {
22
30
  const contextValue = (0, react_1.useContext)(context);
23
31
  if (!contextValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "0.0.17-alpha.59",
3
+ "version": "0.0.17-alpha.62",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -34,5 +34,5 @@
34
34
  "uuid": "11.0.3",
35
35
  "yup": "^1.4.0"
36
36
  },
37
- "gitHead": "813d07729a10a5613b46f012ba4b24bcaab384dc"
37
+ "gitHead": "7b4ba8b46dc270e88055b7352d74fae7a2363cd0"
38
38
  }
@@ -1,11 +1,15 @@
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 { RetriveRecordFn } from '../../dataform/DataFormProvider/types';
5
+ import { SaveRecordFn } from '../../dataform/utils/saveRecord';
4
6
  interface PageEntityFormProviderProps<S extends 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
- export declare function PageEntityFormProvider<S extends SchemaAttributes>({ schema, form, recordId, children, commands, }: PropsWithChildren<PageEntityFormProviderProps<S>>): import("react/jsx-runtime").JSX.Element;
14
+ export declare function PageEntityFormProvider<S extends SchemaAttributes>({ schema, form, recordId, children, commands, retriveRecordFn, saveRecordFn, }: PropsWithChildren<PageEntityFormProviderProps<S>>): import("react/jsx-runtime").JSX.Element;
11
15
  export {};
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PageEntityFormProvider = PageEntityFormProvider;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const DataFormProvider_1 = require("../../dataform/DataFormProvider");
6
- function PageEntityFormProvider({ schema, form, recordId, children, commands, }) {
7
- return ((0, jsx_runtime_1.jsx)(DataFormProvider_1.DataFormProvider, { schema: schema, form: form, recordId: recordId, commands: commands, children: children }));
6
+ function PageEntityFormProvider({ schema, form, recordId, children, commands, retriveRecordFn, saveRecordFn, }) {
7
+ return ((0, jsx_runtime_1.jsx)(DataFormProvider_1.DataFormProvider, { schema: schema, form: form, recordId: recordId, commands: commands, retriveRecordFn: retriveRecordFn, saveRecordFn: saveRecordFn, children: children }));
8
8
  }
@@ -1,7 +1,7 @@
1
1
  import { IEventManager } from '@headless-adminapp/core/store';
2
2
  export declare class EventManager implements IEventManager {
3
3
  private handlers;
4
- on<T>(key: string, handler: T): Promise<void>;
5
- off<T>(key: string, handler: T): Promise<void>;
4
+ on<T>(key: string, handler: T): void;
5
+ off<T>(key: string, handler: T): void;
6
6
  emit(key: string, ...args: any[]): any[];
7
7
  }
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventManager = void 0;
4
4
  class EventManager {
5
5
  handlers = {};
6
- async on(key, handler) {
6
+ on(key, handler) {
7
7
  if (!this.handlers[key]) {
8
8
  this.handlers[key] = [];
9
9
  }
10
10
  this.handlers[key].push(handler);
11
11
  }
12
- async off(key, handler) {
12
+ off(key, handler) {
13
13
  if (!this.handlers[key]) {
14
14
  return;
15
15
  }
@@ -16,8 +16,8 @@ export declare class RestDataService implements IDataService {
16
16
  [key in keyof T]?: string[];
17
17
  }): Promise<Data<T>>;
18
18
  retriveRecords<T = unknown>(params: RetriveRecordsFnOptions<T>): Promise<RetriveRecordsResult<T>>;
19
- createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core/attributes").Id>>;
20
- updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core/attributes").Id>>;
19
+ createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
20
+ updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
21
21
  deleteRecord(logicalName: string, id: string): Promise<void>;
22
22
  retriveAggregate<Q extends Record<string, AggregateAttribute> = Record<string, AggregateAttribute>>(query: AggregateQuery<Q>): Promise<InferredAggregateQueryResult<Q>[]>;
23
23
  customAction<T = unknown>(_actionName: string, _payload: unknown): Promise<T>;
@@ -1,4 +1,3 @@
1
1
  import { IDataService, IFileService } from '@headless-adminapp/core/transport';
2
2
  export declare const DataServiceContext: import("react").Context<IDataService | undefined>;
3
- export declare const noopFileService: IFileService;
4
- export declare const FileServiceContext: import("react").Context<IFileService>;
3
+ export declare const FileServiceContext: import("react").Context<IFileService | null>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileServiceContext = exports.noopFileService = exports.DataServiceContext = void 0;
3
+ exports.FileServiceContext = exports.DataServiceContext = void 0;
4
4
  const react_1 = require("react");
5
5
  exports.DataServiceContext = (0, react_1.createContext)(undefined);
6
- exports.noopFileService = {
7
- uploadFile: async () => {
8
- throw new Error('File service not implemented');
9
- },
10
- };
11
- exports.FileServiceContext = (0, react_1.createContext)(exports.noopFileService);
6
+ // export const noopFileService = {
7
+ // uploadFile: async () => {
8
+ // throw new Error('File service not implemented');
9
+ // },
10
+ // } as IFileService;
11
+ exports.FileServiceContext = (0, react_1.createContext)(null);
@@ -1 +1 @@
1
- export declare function useFileService(): import("@headless-adminapp/core/transport").IFileService;
1
+ export declare function useFileService(): import("@headless-adminapp/core/transport").IFileService | null;
@@ -5,8 +5,5 @@ const react_1 = require("react");
5
5
  const context_1 = require("../context");
6
6
  function useFileService() {
7
7
  const context = (0, react_1.useContext)(context_1.FileServiceContext);
8
- if (!context) {
9
- throw new Error('FileServiceContext must be used within a FileServiceProvider');
10
- }
11
8
  return context;
12
9
  }