impaktapps-ui-builder 0.0.409-k → 0.0.409-m
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/impaktapps-ui-builder.es.js +208 -165
- package/dist/impaktapps-ui-builder.es.js.map +1 -1
- package/dist/impaktapps-ui-builder.umd.js +11 -11
- package/dist/impaktapps-ui-builder.umd.js.map +1 -1
- package/dist/src/impaktapps-ui-builder/runtime/services/events.d.ts +7 -5
- package/package.json +1 -1
- package/src/impaktapps-ui-builder/builder/build/buildConfig.ts +0 -7
- package/src/impaktapps-ui-builder/builder/services/component.ts +1 -1
- package/src/impaktapps-ui-builder/runtime/services/events.ts +140 -93
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { handlersProps } from "./interface";
|
|
2
|
-
export declare const executeEvents: (params: handlersProps) =>
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
2
|
+
export declare const executeEvents: (params: handlersProps) => any;
|
|
3
|
+
export declare function getRefreshElements(eventConfig: any, eventGropus: any): string[];
|
|
4
|
+
export declare function executeRefreshHandler(params: handlersProps): Promise<any[][]>;
|
|
5
|
+
export declare function executeApiRequest(params: any): any;
|
|
6
|
+
export declare function shouldEventExecute(params: handlersProps): any;
|
|
7
|
+
export declare function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service: any): {
|
|
5
8
|
body: any;
|
|
6
9
|
headers: any;
|
|
7
|
-
}
|
|
8
|
-
export declare function getRefreshElements(eventConfig: any, eventGropus: any): string[];
|
|
10
|
+
};
|
|
9
11
|
export declare function asyncOperation(): Promise<unknown>;
|
package/package.json
CHANGED
|
@@ -3,13 +3,6 @@ import _ from "lodash";
|
|
|
3
3
|
export default (FormData: any) => {
|
|
4
4
|
const formData = _.cloneDeep(FormData)
|
|
5
5
|
let component: any = {};
|
|
6
|
-
// if (formData?.layout) {
|
|
7
|
-
// component.layout = createData(FormData?.layout, "layout");
|
|
8
|
-
// delete formData.layout
|
|
9
|
-
// }
|
|
10
|
-
// if(!formData.type ){
|
|
11
|
-
// component.type = "page";
|
|
12
|
-
// }
|
|
13
6
|
if (formData.pageName) {
|
|
14
7
|
delete formData.pageName
|
|
15
8
|
}
|
|
@@ -56,7 +56,7 @@ export const refreshPage = (type: string, store: any) => {
|
|
|
56
56
|
|
|
57
57
|
}
|
|
58
58
|
const elements = sectionLabels[type]?.map(e => sectionUiSchema[e]);
|
|
59
|
-
UiSchema.elements[1].config.main.tabLabels = sectionLabels[type] || ["Core", "
|
|
59
|
+
UiSchema.elements[1].config.main.tabLabels = sectionLabels[type] || ["Core", "Style", "Event", "Validation"];
|
|
60
60
|
UiSchema.elements[1].elements = elements || [CoreSection, StyleSection, EventSection, ValidationSection];
|
|
61
61
|
|
|
62
62
|
}
|
|
@@ -1,102 +1,150 @@
|
|
|
1
1
|
import _, { cloneDeep } from "lodash";
|
|
2
2
|
import { handlersProps } from "./interface";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export const executeEvents = async (
|
|
6
|
-
params: handlersProps
|
|
7
|
-
) => {
|
|
4
|
+
export const executeEvents = (params: handlersProps) => {
|
|
8
5
|
let nextEvent = [];
|
|
9
6
|
let finalResponse = null;
|
|
7
|
+
|
|
8
|
+
if (params.config.isSync !== "Yes") {
|
|
9
|
+
|
|
10
|
+
return shouldEventExecute(params)
|
|
11
|
+
.then((shouldExecute) => {
|
|
12
|
+
if (!shouldExecute) {
|
|
13
|
+
return { response: undefined, events: undefined };
|
|
14
|
+
}
|
|
15
|
+
return executeEventsHandler(params);
|
|
16
|
+
})
|
|
17
|
+
.then((response) => {
|
|
18
|
+
finalResponse = response;
|
|
19
|
+
const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
|
|
20
|
+
nextEvent = SuccessEvent;
|
|
21
|
+
})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
|
|
24
|
+
const setEvent = FailEvent?.length > 0 ? FailEvent : [];
|
|
25
|
+
nextEvent = setEvent;
|
|
26
|
+
})
|
|
27
|
+
.then(() => {
|
|
28
|
+
if (nextEvent?.length > 0) {
|
|
29
|
+
return nextEvent.reduce((chain, actionConfig) => {
|
|
30
|
+
return chain.then(() => executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse }));
|
|
31
|
+
}, Promise.resolve());
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
.then(() => finalResponse)
|
|
35
|
+
}
|
|
36
|
+
const shouldExecute = shouldEventExecute(params);
|
|
37
|
+
if (!shouldExecute) {
|
|
38
|
+
return { response: undefined, events: undefined };
|
|
39
|
+
}
|
|
10
40
|
try {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
return { response: undefined, events: undefined };
|
|
14
|
-
}
|
|
15
|
-
const response = await executeEventsHandler(params)
|
|
16
|
-
finalResponse = response;
|
|
41
|
+
const eventsResponse = executeEventsHandler(params);
|
|
42
|
+
finalResponse = eventsResponse;
|
|
17
43
|
const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
|
|
18
44
|
nextEvent = SuccessEvent;
|
|
19
|
-
} catch
|
|
20
|
-
const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail")
|
|
21
|
-
const setEvent = FailEvent?.length > 0 ? FailEvent : []
|
|
45
|
+
} catch {
|
|
46
|
+
const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
|
|
47
|
+
const setEvent = FailEvent?.length > 0 ? FailEvent : [];
|
|
22
48
|
nextEvent = setEvent;
|
|
23
49
|
}
|
|
24
50
|
if (nextEvent?.length > 0) {
|
|
25
51
|
for (const actionConfig of nextEvent) {
|
|
26
|
-
|
|
52
|
+
executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
|
|
27
53
|
}
|
|
28
54
|
}
|
|
29
55
|
return finalResponse;
|
|
30
56
|
}
|
|
31
|
-
|
|
32
|
-
async function executeEventsHandler(params: handlersProps) {
|
|
57
|
+
function executeEventsHandler(params: handlersProps) {
|
|
33
58
|
if (params.config.Handler === "api") {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else if (params.config.Handler === "
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
params.
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else if (params.config.Handler === "
|
|
54
|
-
return params.store.functionParameters?.
|
|
55
|
-
}
|
|
56
|
-
else if (params.config.Handler === "onResetHandler") {
|
|
57
|
-
return params.store.functionParameters?.handleReset()
|
|
59
|
+
return executeApiRequest(params);
|
|
60
|
+
} else if (params.config.Handler === "inBuiltFunction") {
|
|
61
|
+
return executeInBuiltFunctionHandler(params);
|
|
62
|
+
} else if (params.config.Handler === "custom") {
|
|
63
|
+
return executeCustomHandler(params);
|
|
64
|
+
} else if (params.config.Handler === "refresh") {
|
|
65
|
+
return executeRefreshHandler(params);
|
|
66
|
+
} else if (params.config.Handler === "mergeFormdata") {
|
|
67
|
+
return mergeFormdata(
|
|
68
|
+
params.parentEventOutput,
|
|
69
|
+
params.componentName,
|
|
70
|
+
params.config,
|
|
71
|
+
params.store,
|
|
72
|
+
params.service
|
|
73
|
+
);
|
|
74
|
+
} else if (params.config.Handler === "onBackHandler") {
|
|
75
|
+
return params.store.functionParameters?.handleBack();
|
|
76
|
+
} else if (params.config.Handler === "onNextHandler") {
|
|
77
|
+
return params.store.functionParameters?.handleNext();
|
|
78
|
+
} else if (params.config.Handler === "onResetHandler") {
|
|
79
|
+
return params.store.functionParameters?.handleReset();
|
|
58
80
|
}
|
|
59
81
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
|
|
83
|
+
export function getRefreshElements(eventConfig: any, eventGropus: any) {
|
|
84
|
+
let result: string[] = [];
|
|
85
|
+
if (eventConfig?.refreshElements?.length > 0) {
|
|
86
|
+
result = eventConfig.refreshElements.map((e) => {
|
|
87
|
+
return e.value
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
} else {
|
|
91
|
+
if (eventGropus?.onLoad) {
|
|
92
|
+
result = Object.keys(eventGropus?.onLoad)
|
|
93
|
+
result.push(result[0]);
|
|
65
94
|
}
|
|
66
95
|
}
|
|
96
|
+
console.log(result);
|
|
97
|
+
return result;
|
|
67
98
|
}
|
|
68
|
-
|
|
99
|
+
export function executeRefreshHandler(params: handlersProps) {
|
|
100
|
+
const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups);
|
|
101
|
+
|
|
102
|
+
return Promise.all(compToRefresh.map(componentName => {
|
|
103
|
+
return Promise.all(params.eventGroups.onLoad[componentName].map(compEventConfig => {
|
|
104
|
+
return executeEvents({ ...params, config: compEventConfig, componentName });
|
|
105
|
+
}));
|
|
106
|
+
}))
|
|
107
|
+
};
|
|
108
|
+
export function executeApiRequest(params: any) {
|
|
69
109
|
const initialBody = { ...params.userValue?.payload };
|
|
70
110
|
const initialHeaders = {
|
|
71
111
|
"X-Requested-With": "XMLHttpRequest",
|
|
72
112
|
"Access-Control-Allow-Origin": "*"
|
|
73
113
|
};
|
|
74
|
-
const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
|
|
75
114
|
|
|
76
|
-
const
|
|
115
|
+
const payloadApi = buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
|
|
116
|
+
return params.service[params.config.method](
|
|
77
117
|
params.config.path,
|
|
78
|
-
body,
|
|
79
|
-
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
}
|
|
118
|
+
payloadApi.body,
|
|
119
|
+
{ headers: payloadApi.headers }
|
|
120
|
+
).then((response) => {
|
|
121
|
+
return response;
|
|
122
|
+
});
|
|
123
|
+
};
|
|
83
124
|
|
|
84
|
-
|
|
125
|
+
function executeInBuiltFunctionHandler(params: handlersProps) {
|
|
85
126
|
let parameter = {};
|
|
86
127
|
if (params.config.funcParametersCode) {
|
|
87
128
|
const makeFunc = eval(params.config.funcParametersCode)
|
|
88
129
|
parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
|
|
130
|
+
params.serviceHolder[params.config.inBuiltFunctionType](parameter, params.service)
|
|
131
|
+
} else {
|
|
132
|
+
params.serviceHolder[params.config.inBuiltFunctionType](params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service)
|
|
89
133
|
}
|
|
90
|
-
params.serviceHolder[params.config.inBuiltFunctionType](parameter)
|
|
91
134
|
}
|
|
92
135
|
|
|
93
|
-
|
|
136
|
+
function executeCustomHandler(params: handlersProps) {
|
|
94
137
|
const makeFunc = eval(params.config.eventCode)
|
|
95
|
-
|
|
96
|
-
|
|
138
|
+
if (params.config.isSync !== "Yes") {
|
|
139
|
+
return makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName).then((res) => res)
|
|
140
|
+
} else {
|
|
141
|
+
const response = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName)
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
144
|
+
|
|
97
145
|
}
|
|
98
146
|
|
|
99
|
-
|
|
147
|
+
function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
|
|
100
148
|
if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
101
149
|
store.setSchema((pre) => {
|
|
102
150
|
return {
|
|
@@ -131,14 +179,13 @@ async function mergeFormdata(handlerResponse: any, componentName: string, eventC
|
|
|
131
179
|
}
|
|
132
180
|
else {
|
|
133
181
|
if (handlerResponse) {
|
|
134
|
-
store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse
|
|
135
|
-
const demoData = await asyncOperation();
|
|
182
|
+
store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse?.data?.data : handlerResponse.data } });
|
|
136
183
|
}
|
|
137
184
|
}
|
|
138
185
|
}
|
|
139
186
|
|
|
140
187
|
const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
141
|
-
|
|
188
|
+
let finalBody = { ...userValue?.payload };
|
|
142
189
|
body.map((elem) => {
|
|
143
190
|
if (typeof elem?.value !== "string") {
|
|
144
191
|
finalBody[elem.key] = elem.value;
|
|
@@ -150,7 +197,12 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
|
150
197
|
else if (elem?.value?.startsWith("$")) {
|
|
151
198
|
const finalpath = elem.value.substring(1);
|
|
152
199
|
finalBody[elem.key] = _.get(formData, finalpath);;
|
|
153
|
-
} else {
|
|
200
|
+
} else if (elem?.value === "*" && elem?.key === "*") {
|
|
201
|
+
finalBody = { ...finalBody, ...formData };
|
|
202
|
+
} else if (elem?.value === "*") {
|
|
203
|
+
finalBody[elem.key] = formData;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
154
206
|
finalBody[elem.key] = elem.value;
|
|
155
207
|
}
|
|
156
208
|
}
|
|
@@ -169,50 +221,45 @@ const buildHeadersFormat = (headers: any[]) => {
|
|
|
169
221
|
return headerObj;
|
|
170
222
|
}
|
|
171
223
|
|
|
172
|
-
|
|
224
|
+
export function shouldEventExecute(params: handlersProps) {
|
|
173
225
|
const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
|
|
226
|
+
|
|
174
227
|
if (startEvent?.length > 0) {
|
|
175
|
-
|
|
176
|
-
|
|
228
|
+
if (startEvent[0]?.isSync !== "Yes") {
|
|
229
|
+
return executeEventsHandler({ ...params, config: startEvent[0] }).then((response) => {
|
|
230
|
+
return response;
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
return executeEventsHandler({ ...params, config: startEvent[0] })
|
|
234
|
+
}
|
|
177
235
|
} else {
|
|
178
|
-
|
|
236
|
+
if (params.config.isSync !== "Yes") {
|
|
237
|
+
return Promise.resolve(true)
|
|
238
|
+
} else {
|
|
239
|
+
return true
|
|
240
|
+
}
|
|
179
241
|
}
|
|
180
242
|
}
|
|
181
243
|
|
|
182
|
-
export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
|
|
183
|
-
if (compConfig?.headers) {
|
|
184
|
-
headers = buildHeadersFormat(compConfig.headers)
|
|
185
244
|
|
|
245
|
+
export function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
|
|
246
|
+
if (compConfig?.headers) {
|
|
247
|
+
headers = buildHeadersFormat(compConfig.headers);
|
|
186
248
|
}
|
|
249
|
+
|
|
187
250
|
if (compConfig.body) {
|
|
188
251
|
body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
|
|
189
252
|
}
|
|
190
|
-
if (compConfig.apiBody) {
|
|
191
|
-
const makeFunc = eval(compConfig.apiBody);
|
|
192
|
-
const data = await makeFunc(store, dynamicData, userValue, body);
|
|
193
|
-
body = data
|
|
194
|
-
}
|
|
195
|
-
return { body, headers };
|
|
196
|
-
}
|
|
197
253
|
|
|
198
|
-
|
|
199
|
-
let result: string[] = [];
|
|
200
|
-
if (eventConfig?.refreshElements?.length > 0) {
|
|
201
|
-
result = eventConfig.refreshElements.map((e) => {
|
|
202
|
-
return e.value
|
|
203
|
-
})
|
|
254
|
+
const promiseChain = { body, headers };
|
|
204
255
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
256
|
+
|
|
257
|
+
if (compConfig.apiBody) {
|
|
258
|
+
const makeFunc = eval(compConfig.apiBody);
|
|
259
|
+
return { body: makeFunc(store, dynamicData, userValue, promiseChain.body), headers: promiseChain.headers };
|
|
210
260
|
}
|
|
211
|
-
|
|
212
|
-
return result;
|
|
261
|
+
return promiseChain;
|
|
213
262
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
263
|
export function asyncOperation() {
|
|
217
264
|
return new Promise((resolve, reject) => {
|
|
218
265
|
setTimeout(() => {
|
|
@@ -223,4 +270,4 @@ export function asyncOperation() {
|
|
|
223
270
|
}
|
|
224
271
|
}, 50);
|
|
225
272
|
});
|
|
226
|
-
}
|
|
273
|
+
}
|