impaktapps-ui-builder 0.0.382-alpha.335 → 0.0.382-alpha.337
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 +75 -54
- package/dist/impaktapps-ui-builder.es.js.map +1 -1
- package/dist/impaktapps-ui-builder.umd.js +9 -9
- package/dist/impaktapps-ui-builder.umd.js.map +1 -1
- package/dist/src/impaktapps-ui-builder/runtime/services/events.d.ts +1 -1
- package/package.json +1 -1
- package/src/impaktapps-ui-builder/runtime/services/events.ts +83 -112
- package/src/impaktapps-ui-builder/runtime/services/service.ts +7 -1
|
@@ -5,4 +5,4 @@ export declare function buildApiPayload(compConfig: any, body: any, headers: any
|
|
|
5
5
|
body: any;
|
|
6
6
|
headers: any;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function getRefreshElements(eventConfig: any,
|
|
8
|
+
export declare function getRefreshElements(eventConfig: any, eventGropus: any): string[];
|
package/package.json
CHANGED
|
@@ -1,103 +1,77 @@
|
|
|
1
1
|
import _, { cloneDeep } from "lodash";
|
|
2
2
|
import { handlersProps } from "./interface";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
export const executeEvents = async (
|
|
6
6
|
params: handlersProps
|
|
7
7
|
) => {
|
|
8
8
|
let nextEvent = [];
|
|
9
9
|
let finalResponse = null;
|
|
10
|
-
let accumulatedData = {}; // Accumulated data variable
|
|
11
|
-
|
|
12
10
|
try {
|
|
13
|
-
const shouldExecute = await shouldEventExecute(params)
|
|
11
|
+
const shouldExecute = await shouldEventExecute(params)
|
|
14
12
|
if (!shouldExecute) {
|
|
15
13
|
return { response: undefined, events: undefined };
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
// Execute the event handler and get the response
|
|
19
|
-
const response = await executeEventsHandler(params);
|
|
15
|
+
const response = await executeEventsHandler(params)
|
|
20
16
|
finalResponse = response;
|
|
21
|
-
|
|
22
|
-
// Check if we need to accumulate data from mergeFormdata handler
|
|
23
|
-
if (params.config.Handler === "mergeFormdata") {
|
|
24
|
-
const data = await mergeFormdata(
|
|
25
|
-
params.parentEventOutput,
|
|
26
|
-
params.componentName,
|
|
27
|
-
params.config,
|
|
28
|
-
params.store,
|
|
29
|
-
params.service
|
|
30
|
-
);
|
|
31
|
-
accumulatedData = { ...accumulatedData, ...data };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Filter events to execute based on success
|
|
35
17
|
const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
|
|
36
18
|
nextEvent = SuccessEvent;
|
|
37
19
|
} catch (err) {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const setEvent = FailEvent?.length > 0 ? FailEvent : [];
|
|
20
|
+
const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail")
|
|
21
|
+
const setEvent = FailEvent?.length > 0 ? FailEvent : []
|
|
41
22
|
nextEvent = setEvent;
|
|
42
23
|
}
|
|
43
|
-
|
|
44
|
-
// Execute the next events
|
|
45
24
|
if (nextEvent?.length > 0) {
|
|
46
25
|
for (const actionConfig of nextEvent) {
|
|
47
|
-
|
|
48
|
-
accumulatedData = { ...accumulatedData, ...result };
|
|
26
|
+
await executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
|
|
49
27
|
}
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
// After all events are processed, update the store with accumulated data
|
|
53
|
-
params.store.setFormdata((pre: any) => ({ ...pre, ...accumulatedData }));
|
|
54
|
-
|
|
55
29
|
return finalResponse;
|
|
56
30
|
}
|
|
57
31
|
|
|
58
|
-
// Handler function execution
|
|
59
32
|
async function executeEventsHandler(params: handlersProps) {
|
|
60
33
|
if (params.config.Handler === "api") {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return await executeInBuiltFunctionHandler(params)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
34
|
+
return await executeApiEventHandler(params)
|
|
35
|
+
}
|
|
36
|
+
else if (params.config.Handler === "inBuiltFunction") {
|
|
37
|
+
return await executeInBuiltFunctionHandler(params)
|
|
38
|
+
}
|
|
39
|
+
else if (params.config.Handler === "custom") {
|
|
40
|
+
return await executeCustomHandler(params)
|
|
41
|
+
}
|
|
42
|
+
else if (params.config.Handler === "refresh") {
|
|
43
|
+
return await executeRefreshHandler(params)
|
|
44
|
+
}
|
|
45
|
+
else if (params.config.Handler === "mergeFormdata") {
|
|
46
|
+
const result = await mergeFormdata(
|
|
47
|
+
params.parentEventOutput, params.componentName, params.config, params.store, params.service)
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
else if (params.config.Handler === "onBackHandler") {
|
|
51
|
+
return params.store.functionParameters?.handleBack()
|
|
52
|
+
}
|
|
53
|
+
else if (params.config.Handler === "onNextHandler") {
|
|
54
|
+
return params.store.functionParameters?.handleNext()
|
|
55
|
+
}
|
|
56
|
+
else if (params.config.Handler === "onResetHandler") {
|
|
57
|
+
return params.store.functionParameters?.handleReset()
|
|
80
58
|
}
|
|
81
59
|
}
|
|
82
|
-
|
|
83
|
-
// Refresh handler function
|
|
84
60
|
export async function executeRefreshHandler(params: handlersProps) {
|
|
85
|
-
const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups)
|
|
61
|
+
const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups)
|
|
86
62
|
for (const componentName of compToRefresh) {
|
|
87
63
|
for (const compEventConfig of params.eventGroups.onLoad[componentName]) {
|
|
88
64
|
await executeEvents({ ...params, config: compEventConfig, componentName });
|
|
89
65
|
}
|
|
90
66
|
}
|
|
91
67
|
}
|
|
92
|
-
|
|
93
|
-
// API event handler function
|
|
94
68
|
async function executeApiEventHandler(params: handlersProps) {
|
|
95
69
|
const initialBody = { ...params.userValue?.payload };
|
|
96
70
|
const initialHeaders = {
|
|
97
71
|
"X-Requested-With": "XMLHttpRequest",
|
|
98
72
|
"Access-Control-Allow-Origin": "*"
|
|
99
73
|
};
|
|
100
|
-
const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
|
|
74
|
+
const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
|
|
101
75
|
|
|
102
76
|
const response = await params.service[params.config.method](
|
|
103
77
|
params.config.path,
|
|
@@ -107,65 +81,62 @@ async function executeApiEventHandler(params: handlersProps) {
|
|
|
107
81
|
return response;
|
|
108
82
|
}
|
|
109
83
|
|
|
110
|
-
// Built-in function event handler
|
|
111
84
|
async function executeInBuiltFunctionHandler(params: handlersProps) {
|
|
112
85
|
let parameter = {};
|
|
113
86
|
if (params.config.funcParametersCode) {
|
|
114
|
-
const makeFunc = eval(params.config.funcParametersCode)
|
|
87
|
+
const makeFunc = eval(params.config.funcParametersCode)
|
|
115
88
|
parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
|
|
116
89
|
}
|
|
117
|
-
params.serviceHolder[params.config.inBuiltFunctionType](parameter)
|
|
90
|
+
params.serviceHolder[params.config.inBuiltFunctionType](parameter)
|
|
118
91
|
}
|
|
119
92
|
|
|
120
|
-
// Custom handler function
|
|
121
93
|
async function executeCustomHandler(params: handlersProps) {
|
|
122
|
-
const makeFunc = eval(params.config.eventCode)
|
|
94
|
+
const makeFunc = eval(params.config.eventCode)
|
|
123
95
|
const response = await makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName);
|
|
124
96
|
return response;
|
|
125
97
|
}
|
|
126
98
|
|
|
127
|
-
|
|
128
|
-
async function mergeFormdata(
|
|
129
|
-
handlerResponse: any,
|
|
130
|
-
componentName: string,
|
|
131
|
-
eventConfig: any,
|
|
132
|
-
store: any,
|
|
133
|
-
service: any
|
|
134
|
-
) {
|
|
135
|
-
let accumulatedData = {};
|
|
136
|
-
|
|
99
|
+
async function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
|
|
137
100
|
if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...
|
|
141
|
-
|
|
101
|
+
store.setSchema((pre) => {
|
|
102
|
+
return {
|
|
103
|
+
...pre, properties: {
|
|
104
|
+
...pre.properties, [componentName]: {
|
|
105
|
+
...pre.properties?.[componentName],
|
|
106
|
+
oneOf: handlerResponse.data
|
|
107
|
+
}
|
|
108
|
+
}
|
|
142
109
|
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
else if (eventConfig.type === "MultipleSelect" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
113
|
+
store.setSchema((pre) => {
|
|
114
|
+
return {
|
|
115
|
+
...pre, properties: {
|
|
116
|
+
...pre.properties, [componentName]: {
|
|
117
|
+
...pre.properties?.[componentName],
|
|
118
|
+
type: "array",
|
|
119
|
+
items: {
|
|
120
|
+
oneOf: handlerResponse?.data
|
|
121
|
+
}
|
|
122
|
+
}
|
|
151
123
|
}
|
|
152
124
|
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
else if (eventConfig.type === "page") {
|
|
155
128
|
if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
156
|
-
|
|
129
|
+
store.setFormdata((pre: any) => { return { ...pre, ...handlerResponse?.data } })
|
|
157
130
|
}
|
|
158
|
-
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
159
133
|
if (handlerResponse) {
|
|
160
|
-
|
|
134
|
+
store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse.data.data : handlerResponse.data } });
|
|
135
|
+
const demoData = await asyncOperation();
|
|
161
136
|
}
|
|
162
137
|
}
|
|
163
|
-
|
|
164
|
-
// Return accumulated data
|
|
165
|
-
return accumulatedData;
|
|
166
138
|
}
|
|
167
139
|
|
|
168
|
-
// Helper functions for building API payloads
|
|
169
140
|
const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
170
141
|
const finalBody = { ...userValue?.payload };
|
|
171
142
|
body.map((elem) => {
|
|
@@ -174,16 +145,16 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
|
174
145
|
} else {
|
|
175
146
|
if (elem?.value?.startsWith("$userValue")) {
|
|
176
147
|
const finalpath = elem.value.substring(11);
|
|
177
|
-
finalBody[elem.key] = _.get(userValue, finalpath)
|
|
148
|
+
finalBody[elem.key] = _.get(userValue, finalpath);;
|
|
178
149
|
}
|
|
179
150
|
else if (elem?.value?.startsWith("$")) {
|
|
180
151
|
const finalpath = elem.value.substring(1);
|
|
181
|
-
finalBody[elem.key] = _.get(formData, finalpath)
|
|
152
|
+
finalBody[elem.key] = _.get(formData, finalpath);;
|
|
182
153
|
} else {
|
|
183
154
|
finalBody[elem.key] = elem.value;
|
|
184
155
|
}
|
|
185
156
|
}
|
|
186
|
-
})
|
|
157
|
+
})
|
|
187
158
|
return finalBody;
|
|
188
159
|
}
|
|
189
160
|
|
|
@@ -191,28 +162,27 @@ const buildHeadersFormat = (headers: any[]) => {
|
|
|
191
162
|
const headerObj = {
|
|
192
163
|
// "Content-Type": "application/json",
|
|
193
164
|
"X-Requested-With": "XMLHttpRequest"
|
|
194
|
-
}
|
|
165
|
+
}
|
|
195
166
|
headers.map((elem) => {
|
|
196
167
|
headerObj[elem.key] = elem.value;
|
|
197
|
-
})
|
|
168
|
+
})
|
|
198
169
|
return headerObj;
|
|
199
170
|
}
|
|
200
171
|
|
|
201
|
-
// Function to determine if an event should execute
|
|
202
172
|
async function shouldEventExecute(params: handlersProps) {
|
|
203
173
|
const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
|
|
204
174
|
if (startEvent?.length > 0) {
|
|
205
175
|
const response = await executeEventsHandler({ ...params, config: startEvent[0] });
|
|
206
176
|
return response;
|
|
207
177
|
} else {
|
|
208
|
-
return true
|
|
178
|
+
return true
|
|
209
179
|
}
|
|
210
180
|
}
|
|
211
181
|
|
|
212
|
-
// Function to build API payload
|
|
213
182
|
export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
|
|
214
183
|
if (compConfig?.headers) {
|
|
215
|
-
headers = buildHeadersFormat(compConfig.headers)
|
|
184
|
+
headers = buildHeadersFormat(compConfig.headers)
|
|
185
|
+
|
|
216
186
|
}
|
|
217
187
|
if (compConfig.body) {
|
|
218
188
|
body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
|
|
@@ -220,19 +190,21 @@ export async function buildApiPayload(compConfig: any, body: any, headers: any,
|
|
|
220
190
|
if (compConfig.apiBody) {
|
|
221
191
|
const makeFunc = eval(compConfig.apiBody);
|
|
222
192
|
const data = await makeFunc(store, dynamicData, userValue, body);
|
|
223
|
-
body = data
|
|
193
|
+
body = data
|
|
224
194
|
}
|
|
225
195
|
return { body, headers };
|
|
226
196
|
}
|
|
227
197
|
|
|
228
|
-
|
|
229
|
-
export function getRefreshElements(eventConfig: any, eventGroups: any) {
|
|
198
|
+
export function getRefreshElements(eventConfig: any, eventGropus: any) {
|
|
230
199
|
let result: string[] = [];
|
|
231
200
|
if (eventConfig?.refreshElements?.length > 0) {
|
|
232
|
-
result = eventConfig.refreshElements.map((e) =>
|
|
201
|
+
result = eventConfig.refreshElements.map((e) => {
|
|
202
|
+
return e.value
|
|
203
|
+
})
|
|
204
|
+
|
|
233
205
|
} else {
|
|
234
|
-
if (
|
|
235
|
-
result = Object.keys(
|
|
206
|
+
if (eventGropus?.onLoad) {
|
|
207
|
+
result = Object.keys(eventGropus?.onLoad)
|
|
236
208
|
result.push(result[0]);
|
|
237
209
|
}
|
|
238
210
|
}
|
|
@@ -240,16 +212,15 @@ export function getRefreshElements(eventConfig: any, eventGroups: any) {
|
|
|
240
212
|
return result;
|
|
241
213
|
}
|
|
242
214
|
|
|
243
|
-
|
|
215
|
+
|
|
244
216
|
function asyncOperation() {
|
|
245
217
|
return new Promise((resolve, reject) => {
|
|
246
218
|
setTimeout(() => {
|
|
247
219
|
const success = true;
|
|
248
220
|
if (success) {
|
|
249
221
|
resolve("Operation completed successfully!");
|
|
250
|
-
} else {
|
|
251
222
|
reject(new Error("Operation failed!"));
|
|
252
223
|
}
|
|
253
224
|
}, 50);
|
|
254
225
|
});
|
|
255
|
-
}
|
|
226
|
+
}
|
|
@@ -130,7 +130,10 @@ export default (funcParams: funcParamsProps) => {
|
|
|
130
130
|
});
|
|
131
131
|
},
|
|
132
132
|
onClick: async function () {
|
|
133
|
+
alert("Loading");
|
|
134
|
+
// funcParams.dynamicData()
|
|
133
135
|
await this.callHandler("onClick");
|
|
136
|
+
alert("end");
|
|
134
137
|
},
|
|
135
138
|
onFileDownload: async function () {
|
|
136
139
|
await this.callHandler("onDownload");
|
|
@@ -160,6 +163,7 @@ export default (funcParams: funcParamsProps) => {
|
|
|
160
163
|
},
|
|
161
164
|
onChange: async function () {
|
|
162
165
|
if (eventGroups.onChange) {
|
|
166
|
+
|
|
163
167
|
const ChangeEventsKeysArray = Object.keys(eventGroups.onChange);
|
|
164
168
|
await Promise.all(
|
|
165
169
|
ChangeEventsKeysArray.map(async (componentName: string) => {
|
|
@@ -173,6 +177,7 @@ export default (funcParams: funcParamsProps) => {
|
|
|
173
177
|
}
|
|
174
178
|
})
|
|
175
179
|
);
|
|
180
|
+
|
|
176
181
|
}
|
|
177
182
|
},
|
|
178
183
|
updateConfigApiBody: async function (paramValue, apiBody) {
|
|
@@ -229,11 +234,12 @@ export default (funcParams: funcParamsProps) => {
|
|
|
229
234
|
if (eventGroups?.[eventType]?.[path] !== undefined) {
|
|
230
235
|
for (const eventConfig of eventGroups?.[eventType]?.[path]) {
|
|
231
236
|
executeEventsParameters.store.functionParameters = functionParameters
|
|
232
|
-
await executeEvents({
|
|
237
|
+
const res = await executeEvents({
|
|
233
238
|
...executeEventsParameters,
|
|
234
239
|
config: eventConfig,
|
|
235
240
|
componentName: path
|
|
236
241
|
})
|
|
242
|
+
// console.log("valll", res);
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
245
|
},
|