@headless-adminapp/app 1.4.15 → 1.4.17
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/AuthWrapper.js +2 -2
- package/auth/AuthProvider.js +3 -0
- package/auth/context.d.ts +1 -0
- package/auth/hooks/useLogout.js +1 -0
- package/auth/types.d.ts +1 -0
- package/dataform/DataFormProvider/CalculatedField.d.ts +2 -0
- package/dataform/DataFormProvider/CalculatedField.js +139 -0
- package/dataform/DataFormProvider/index.js +2 -1
- package/dataform/DataFormProvider/utils.d.ts +3 -1
- package/dataform/DataFormProvider/utils.js +6 -1
- package/dataform/FormManager.js +1 -0
- package/dataform/hooks/index.d.ts +0 -2
- package/dataform/hooks/index.js +0 -2
- package/dataform/hooks/useIsControlDisabled.js +1 -0
- package/metadata/MetadataProvider.d.ts +2 -0
- package/metadata/MetadataProvider.js +2 -1
- package/metadata/context.d.ts +2 -0
- package/metadata/hooks/useCalculatedAttributeStore.d.ts +1 -0
- package/metadata/hooks/useCalculatedAttributeStore.js +8 -0
- package/package.json +2 -2
- package/transport/RestDataService/index.d.ts +4 -1
- package/transport/RestDataService/index.js +4 -1
- package/transport/hooks/useDataService.d.ts +2 -1
- package/utils/color.js +28 -3
- package/dataform/hooks/useDisabledControlsManager.d.ts +0 -6
- package/dataform/hooks/useDisabledControlsManager.js +0 -46
- package/dataform/hooks/useHiddenControlsManager.d.ts +0 -7
- package/dataform/hooks/useHiddenControlsManager.js +0 -50
package/app/AuthWrapper.js
CHANGED
|
@@ -17,9 +17,9 @@ const AuthWrapper = ({ children, Placeholder = DefaultPlaceHolder, }) => {
|
|
|
17
17
|
}
|
|
18
18
|
if (!state.authenticated) {
|
|
19
19
|
if (state.sessionExpired) {
|
|
20
|
-
return (0, jsx_runtime_1.jsx)(Placeholder, { sessionExpired: true, retry: state.loadSession });
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)(Placeholder, { sessionExpired: true, retry: state.loadSession, reason: state.reason }));
|
|
21
21
|
}
|
|
22
|
-
return (0, jsx_runtime_1.jsx)(Placeholder, { unauthorized: true, retry: state.loadSession });
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(Placeholder, { unauthorized: true, retry: state.loadSession, reason: state.reason }));
|
|
23
23
|
}
|
|
24
24
|
return children;
|
|
25
25
|
};
|
package/auth/AuthProvider.js
CHANGED
|
@@ -48,6 +48,7 @@ const AuthProvider = ({ sessionResolver, onUnauthenticated, children, }) => {
|
|
|
48
48
|
authenticated: false,
|
|
49
49
|
sessionExpired: false,
|
|
50
50
|
session: null,
|
|
51
|
+
reason: 'load',
|
|
51
52
|
});
|
|
52
53
|
onUnauthenticatedRef.current?.('load');
|
|
53
54
|
}
|
|
@@ -85,6 +86,7 @@ const AuthProvider = ({ sessionResolver, onUnauthenticated, children, }) => {
|
|
|
85
86
|
authenticated: false,
|
|
86
87
|
sessionExpired: true,
|
|
87
88
|
session: null,
|
|
89
|
+
reason: 'sessionExpired',
|
|
88
90
|
});
|
|
89
91
|
onUnauthenticatedRef.current?.('sessionExpired');
|
|
90
92
|
return;
|
|
@@ -99,6 +101,7 @@ const AuthProvider = ({ sessionResolver, onUnauthenticated, children, }) => {
|
|
|
99
101
|
authenticated: false,
|
|
100
102
|
sessionExpired: true,
|
|
101
103
|
session: null,
|
|
104
|
+
reason: 'sessionExpired',
|
|
102
105
|
});
|
|
103
106
|
onUnauthenticatedRef.current?.('sessionExpired');
|
|
104
107
|
}, timeout);
|
package/auth/context.d.ts
CHANGED
package/auth/hooks/useLogout.js
CHANGED
package/auth/types.d.ts
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalculatedField = void 0;
|
|
4
|
+
const useCalculatedAttributeStore_1 = require("@headless-adminapp/app/metadata/hooks/useCalculatedAttributeStore");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const hooks_1 = require("../hooks");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const CalculatedField = () => {
|
|
10
|
+
const formInstance = (0, hooks_1.useFormInstance)();
|
|
11
|
+
const schema = (0, hooks_1.useDataFormSchema)();
|
|
12
|
+
const form = (0, hooks_1.useSelectedForm)();
|
|
13
|
+
const formInstanceRef = (0, react_1.useRef)(formInstance);
|
|
14
|
+
formInstanceRef.current = formInstance;
|
|
15
|
+
const calculatedAttributeStore = (0, useCalculatedAttributeStore_1.useCalculatedAttributeStore)();
|
|
16
|
+
const eventManager = (0, hooks_1.useEventManager)();
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
const editableGridControls = (0, utils_1.getControls)(form).filter((x) => x.type === 'editablegrid');
|
|
19
|
+
const formAttributeNames = (0, utils_1.getColumns)(form, schema);
|
|
20
|
+
const listener = (key) => {
|
|
21
|
+
if (!calculatedAttributeStore)
|
|
22
|
+
return;
|
|
23
|
+
const values = formInstanceRef.current.getValues();
|
|
24
|
+
function recalculateRecordField(item) {
|
|
25
|
+
if (!formAttributeNames.find((x) => x === item.attributeName)) {
|
|
26
|
+
// If the standard control is not found, we can't recalculate
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const record = {};
|
|
30
|
+
for (const dep of item.deps) {
|
|
31
|
+
record[dep] = values[dep];
|
|
32
|
+
}
|
|
33
|
+
const relatedRecords = {};
|
|
34
|
+
for (const relatedDep of Object.entries(item.relatedDeps || {})) {
|
|
35
|
+
const [logicalName, { associatedColumn, columns }] = relatedDep;
|
|
36
|
+
relatedRecords[logicalName] = [];
|
|
37
|
+
const gridControl = editableGridControls.find((x) => x.alias !== false &&
|
|
38
|
+
x.logicalName === logicalName &&
|
|
39
|
+
x.associatedAttribute === associatedColumn);
|
|
40
|
+
if (!gridControl) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const gridItemValues = values[gridControl.alias];
|
|
44
|
+
if (!gridItemValues || !Array.isArray(gridItemValues)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
relatedRecords[logicalName] = gridItemValues.map((item) => {
|
|
48
|
+
const childRecord = {};
|
|
49
|
+
for (const column of columns) {
|
|
50
|
+
childRecord[column] = item[column];
|
|
51
|
+
}
|
|
52
|
+
return childRecord;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const currentValue = formInstanceRef.current.getValues(item.attributeName);
|
|
56
|
+
const newValue = item.handler(record, relatedRecords);
|
|
57
|
+
console.log('Recalculated main record field:', item.attributeName, item, record, relatedRecords, {
|
|
58
|
+
currentValue,
|
|
59
|
+
newValue,
|
|
60
|
+
});
|
|
61
|
+
if (currentValue !== newValue) {
|
|
62
|
+
formInstanceRef.current.setValue(item.attributeName, newValue);
|
|
63
|
+
eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, item.attributeName, newValue, currentValue);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function recalculateSubGridField(item, alias, indexStr) {
|
|
67
|
+
const record = {};
|
|
68
|
+
for (const dep of item.deps) {
|
|
69
|
+
record[dep] = values[alias][indexStr][dep];
|
|
70
|
+
}
|
|
71
|
+
const currentValue = formInstanceRef.current.getValues(`${alias}.${indexStr}.${item.attributeName}`);
|
|
72
|
+
const newValue = item.handler(record, {});
|
|
73
|
+
console.log('Subgrid row level calculation:', item.attributeName, item, record, {
|
|
74
|
+
currentValue,
|
|
75
|
+
newValue,
|
|
76
|
+
});
|
|
77
|
+
if (currentValue !== newValue) {
|
|
78
|
+
formInstanceRef.current.setValue(`${alias}.${indexStr}.${item.attributeName}`, newValue);
|
|
79
|
+
eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, `${alias}.${indexStr}.${item.attributeName}`, newValue, currentValue);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (key.includes('.')) {
|
|
83
|
+
// Handle subgrid changes
|
|
84
|
+
const [alias, indexStr, field] = key.split('.');
|
|
85
|
+
const gridControl = editableGridControls.find((x) => x.alias === alias);
|
|
86
|
+
if (!gridControl) {
|
|
87
|
+
// Invalid state
|
|
88
|
+
// Grid control not found
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!field) {
|
|
92
|
+
// row removed or inserted
|
|
93
|
+
// Find depended controls for all attributes included in subgrid
|
|
94
|
+
let items = calculatedAttributeStore.getCalculatedAttributeInfosByDeps(gridControl.logicalName, ...gridControl.controls.map((x) => typeof x === 'string' ? x : x.attributeName));
|
|
95
|
+
// Filter out row level calculated fields
|
|
96
|
+
items = items.filter((x) => x.logicalName !== gridControl.logicalName);
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
recalculateRecordField(item);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const items = calculatedAttributeStore.getCalculatedAttributeInfosByDeps(gridControl.logicalName, field);
|
|
103
|
+
for (const item of items) {
|
|
104
|
+
if (item.logicalName === gridControl.logicalName) {
|
|
105
|
+
// This is a row level calculated field
|
|
106
|
+
if (Object.keys(item.relatedDeps || {}).length > 0) {
|
|
107
|
+
// Grid row level calculated fields have nested related deps
|
|
108
|
+
// We don't have nested subgrid so no need to handle this case
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
recalculateSubGridField(item, alias, indexStr);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
recalculateRecordField(item);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Handle standard field changes
|
|
121
|
+
const items = calculatedAttributeStore.getCalculatedAttributeInfosByDeps(schema.logicalName, key);
|
|
122
|
+
for (const item of items) {
|
|
123
|
+
if (item.logicalName !== schema.logicalName) {
|
|
124
|
+
// This item is not related to the current schema
|
|
125
|
+
// In main record field we can only calculated top-level fields
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
recalculateRecordField(item);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
eventManager.on(constants_1.EVENT_KEY_ON_FIELD_CHANGE, listener);
|
|
133
|
+
return () => {
|
|
134
|
+
eventManager.off(constants_1.EVENT_KEY_ON_FIELD_CHANGE, listener);
|
|
135
|
+
};
|
|
136
|
+
}, [eventManager, calculatedAttributeStore, form, schema]);
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
exports.CalculatedField = CalculatedField;
|
|
@@ -14,6 +14,7 @@ const mutable_1 = require("../../mutable");
|
|
|
14
14
|
const context_1 = require("../context");
|
|
15
15
|
const utils_1 = require("../utils");
|
|
16
16
|
const saveRecord_1 = require("../utils/saveRecord");
|
|
17
|
+
const CalculatedField_1 = require("./CalculatedField");
|
|
17
18
|
const CustomHookExecuter_1 = require("./CustomHookExecuter");
|
|
18
19
|
const DataResolver_1 = require("./DataResolver");
|
|
19
20
|
const getRecord_1 = require("./getRecord");
|
|
@@ -116,5 +117,5 @@ function DataFormProvider(props) {
|
|
|
116
117
|
schemaStore,
|
|
117
118
|
props.commands,
|
|
118
119
|
]);
|
|
119
|
-
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] }) }));
|
|
120
|
+
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 }), (0, jsx_runtime_1.jsx)(CalculatedField_1.CalculatedField, {}), props.children] }) }));
|
|
120
121
|
}
|
|
@@ -2,15 +2,17 @@ import { AttributeBase } from '@headless-adminapp/core/attributes/AttributeBase'
|
|
|
2
2
|
import { Form, Section } from '@headless-adminapp/core/experience/form';
|
|
3
3
|
import { SectionControl, SectionStatndardControl } from '@headless-adminapp/core/experience/form/SectionControl';
|
|
4
4
|
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
|
+
import { CalculatedAttributeInfo } from '@headless-adminapp/core/schema/CalculatedAttributeInfo';
|
|
5
6
|
import { DataFormContextState } from '../context';
|
|
6
7
|
export declare function getControls<SA extends SchemaAttributes>(form: Form<SA>): SectionControl<SA>[];
|
|
7
8
|
export declare function getColumns<SA extends SchemaAttributes>(form: Form<SA>, schema: Schema<SA>): (keyof SA)[];
|
|
8
9
|
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
|
+
export declare function getIsFieldDisabled<S extends SchemaAttributes = SchemaAttributes>({ attribute, isFormReadonly, disabledFields, control, calculatedAttribute, }: {
|
|
10
11
|
attribute: AttributeBase | null;
|
|
11
12
|
isFormReadonly: boolean | undefined;
|
|
12
13
|
disabledFields: Record<string, boolean>;
|
|
13
14
|
control: Section<S>['controls'][0];
|
|
15
|
+
calculatedAttribute: CalculatedAttributeInfo | undefined;
|
|
14
16
|
}): boolean;
|
|
15
17
|
export declare function getIsControlHidden<S extends SchemaAttributes = SchemaAttributes>({ control, hiddenControls, }: {
|
|
16
18
|
hiddenControls: Record<string, boolean>;
|
|
@@ -65,7 +65,7 @@ function transformFormInternal(form) {
|
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control, }) {
|
|
68
|
+
function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control, calculatedAttribute, }) {
|
|
69
69
|
let disabled = isFormReadonly ?? false;
|
|
70
70
|
if (!disabled) {
|
|
71
71
|
if (control.type === 'standard' &&
|
|
@@ -80,6 +80,11 @@ function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control
|
|
|
80
80
|
disabled = attribute.readonly;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
if (!disabled &&
|
|
84
|
+
calculatedAttribute &&
|
|
85
|
+
!calculatedAttribute.allowUserToEdit) {
|
|
86
|
+
disabled = true;
|
|
87
|
+
}
|
|
83
88
|
return disabled;
|
|
84
89
|
}
|
|
85
90
|
function getIsControlHidden({ control, hiddenControls, }) {
|
package/dataform/FormManager.js
CHANGED
|
@@ -14,8 +14,6 @@ export * from './useProcessFlowSteps';
|
|
|
14
14
|
export * from './useEventManager';
|
|
15
15
|
export * from './useIsControlHiddenByAttributeName';
|
|
16
16
|
export * from './useIsControlHiddenByKey';
|
|
17
|
-
export * from './useHiddenControlsManager';
|
|
18
|
-
export * from './useDisabledControlsManager';
|
|
19
17
|
export * from './useContextKey';
|
|
20
18
|
export * from './useIsControlDisabled';
|
|
21
19
|
export * from './useIsFieldRequired';
|
package/dataform/hooks/index.js
CHANGED
|
@@ -30,8 +30,6 @@ __exportStar(require("./useProcessFlowSteps"), exports);
|
|
|
30
30
|
__exportStar(require("./useEventManager"), exports);
|
|
31
31
|
__exportStar(require("./useIsControlHiddenByAttributeName"), exports);
|
|
32
32
|
__exportStar(require("./useIsControlHiddenByKey"), exports);
|
|
33
|
-
__exportStar(require("./useHiddenControlsManager"), exports);
|
|
34
|
-
__exportStar(require("./useDisabledControlsManager"), exports);
|
|
35
33
|
__exportStar(require("./useContextKey"), exports);
|
|
36
34
|
__exportStar(require("./useIsControlDisabled"), exports);
|
|
37
35
|
__exportStar(require("./useIsFieldRequired"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import { ISchemaExperienceStore, ISchemaStore, SchemaStore } from '@headless-adminapp/core/store';
|
|
3
|
+
import { ICalculatedAttributeStore } from '@headless-adminapp/core/store/ICalculatedAttributeStore';
|
|
3
4
|
import { FC, PropsWithChildren } from 'react';
|
|
4
5
|
import { IRecentItemStore, SchemaExperienceStore } from '../store';
|
|
5
6
|
export interface MetadataProviderProps {
|
|
@@ -7,6 +8,7 @@ export interface MetadataProviderProps {
|
|
|
7
8
|
experienceStore?: ISchemaExperienceStore;
|
|
8
9
|
appExperience?: AppExperience;
|
|
9
10
|
recentItemStore?: IRecentItemStore;
|
|
11
|
+
calculatedAttributeStore?: ICalculatedAttributeStore;
|
|
10
12
|
}
|
|
11
13
|
export declare const defaultSchemaStore: SchemaStore<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
12
14
|
export declare const defaultExperienceStore: SchemaExperienceStore;
|
|
@@ -26,12 +26,13 @@ const defaultApp = {
|
|
|
26
26
|
logo: {},
|
|
27
27
|
};
|
|
28
28
|
const defaultRecentItemStore = new store_2.RecentItemStore();
|
|
29
|
-
const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, recentItemStore = defaultRecentItemStore, }) => {
|
|
29
|
+
const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, recentItemStore = defaultRecentItemStore, calculatedAttributeStore, }) => {
|
|
30
30
|
const contextValue = (0, context_1.useCreateContextStore)({
|
|
31
31
|
experienceStore,
|
|
32
32
|
schemaStore,
|
|
33
33
|
appExperience,
|
|
34
34
|
recentItemStore,
|
|
35
|
+
calculatedAttributeStore,
|
|
35
36
|
});
|
|
36
37
|
(0, react_1.useEffect)(() => {
|
|
37
38
|
contextValue.setValue({
|
package/metadata/context.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import type { ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
|
|
3
|
+
import { ICalculatedAttributeStore } from '@headless-adminapp/core/store/ICalculatedAttributeStore';
|
|
3
4
|
import { IRecentItemStore } from '../store';
|
|
4
5
|
export interface MetadataContextState {
|
|
5
6
|
schemaStore: ISchemaStore;
|
|
6
7
|
experienceStore: ISchemaExperienceStore;
|
|
7
8
|
appExperience: AppExperience;
|
|
8
9
|
recentItemStore: IRecentItemStore;
|
|
10
|
+
calculatedAttributeStore?: ICalculatedAttributeStore;
|
|
9
11
|
}
|
|
10
12
|
export declare const MetadataContext: import("react").Context<import("../mutable/context").ContextValue<MetadataContextState>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useCalculatedAttributeStore(): import("@headless-adminapp/core/store/ICalculatedAttributeStore").ICalculatedAttributeStore | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCalculatedAttributeStore = useCalculatedAttributeStore;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useCalculatedAttributeStore() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.calculatedAttributeStore);
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "a5a471cce4df9e87552b23e3de8c90d53e4adf43"
|
|
42
42
|
}
|
|
@@ -8,9 +8,12 @@ export declare class RestDataService implements IDataService {
|
|
|
8
8
|
protected readonly options: RestDataServiceOptions;
|
|
9
9
|
constructor(options: RestDataServiceOptions);
|
|
10
10
|
protected readonly headers: Record<string, string>;
|
|
11
|
-
|
|
11
|
+
protected getHeaders(): {
|
|
12
|
+
'content-type': string;
|
|
13
|
+
};
|
|
12
14
|
setHeader(name: string, value: string): void;
|
|
13
15
|
removeHeader(name: string): void;
|
|
16
|
+
protected handleResponseError(response: Response): Promise<void>;
|
|
14
17
|
protected execute<T = unknown, D = unknown>(data: D): Promise<T>;
|
|
15
18
|
retriveRecord<T = unknown>(logicalName: string, id: string, columns: (keyof T)[], expand?: {
|
|
16
19
|
[key in keyof T]?: string[];
|
|
@@ -33,13 +33,16 @@ class RestDataService {
|
|
|
33
33
|
removeHeader(name) {
|
|
34
34
|
delete this.headers[name];
|
|
35
35
|
}
|
|
36
|
+
handleResponseError(response) {
|
|
37
|
+
return handleResponseError(response);
|
|
38
|
+
}
|
|
36
39
|
async execute(data) {
|
|
37
40
|
const response = await fetch(this.options.endpoint, {
|
|
38
41
|
headers: this.getHeaders(),
|
|
39
42
|
method: 'POST',
|
|
40
43
|
body: JSON.stringify(data),
|
|
41
44
|
});
|
|
42
|
-
await handleResponseError(response);
|
|
45
|
+
await this.handleResponseError(response);
|
|
43
46
|
return response.json();
|
|
44
47
|
}
|
|
45
48
|
async retriveRecord(logicalName, id, columns, expand) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { IDataService } from '@headless-adminapp/core/transport';
|
|
2
|
+
export declare function useDataService<T extends IDataService = IDataService>(): T;
|
package/utils/color.js
CHANGED
|
@@ -2,13 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isColorDark = isColorDark;
|
|
4
4
|
function isColorDark(color) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let hexColor = getColorHexCode(color);
|
|
6
|
+
if (!hexColor) {
|
|
7
|
+
return false;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
hexColor = hexColor.substring(1);
|
|
10
|
+
const rgb = parseInt(hexColor, 16);
|
|
9
11
|
const r = (rgb >> 16) & 0xff;
|
|
10
12
|
const g = (rgb >> 8) & 0xff;
|
|
11
13
|
const b = (rgb >> 0) & 0xff;
|
|
12
14
|
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
13
15
|
return luma < 128;
|
|
14
16
|
}
|
|
17
|
+
function getColorHexCode(color) {
|
|
18
|
+
if (color.startsWith('#')) {
|
|
19
|
+
return color;
|
|
20
|
+
}
|
|
21
|
+
const tempDiv = document.createElement('div');
|
|
22
|
+
tempDiv.style.color = color; // Accepts color name, rgb(), hsl(), etc.
|
|
23
|
+
document.body.appendChild(tempDiv);
|
|
24
|
+
const computedColor = getComputedStyle(tempDiv).color;
|
|
25
|
+
document.body.removeChild(tempDiv);
|
|
26
|
+
// Convert rgb(a) string to hex
|
|
27
|
+
const rgb = computedColor.match(/\d+/g); // Extract numbers
|
|
28
|
+
if (!rgb)
|
|
29
|
+
return null;
|
|
30
|
+
// rgb might have 3 or 4 values (ignore alpha)
|
|
31
|
+
const hex = rgb
|
|
32
|
+
.slice(0, 3)
|
|
33
|
+
.map((x) => {
|
|
34
|
+
const hexPart = Number(x).toString(16);
|
|
35
|
+
return hexPart.length === 1 ? '0' + hexPart : hexPart;
|
|
36
|
+
})
|
|
37
|
+
.join('');
|
|
38
|
+
return '#' + hex;
|
|
39
|
+
}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|