impaktapps-ui-builder 1.0.106 → 1.0.108

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.
@@ -10,5 +10,4 @@ export interface handlersProps {
10
10
  parentEventOutput?: any;
11
11
  functionsProvider?: Record<string, any>;
12
12
  formDataHolder?: Record<string, any>;
13
- pageLoad?: boolean;
14
13
  }
@@ -27,7 +27,7 @@ declare const _default: (funcParams: funcParamsProps) => {
27
27
  onBack: (functionParameters: any) => Promise<void>;
28
28
  onNext: (functionParameters: any) => Promise<void>;
29
29
  onReset: (functionParameters: any) => Promise<void>;
30
- callHandler: (eventType: string, functionParameters?: any) => Promise<void>;
30
+ callHandler: (eventType: string, functionParameters?: any) => void;
31
31
  downloadFile: typeof downloadFile;
32
32
  downloadFileFromUrl: (response: any, service: any) => void;
33
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-ui-builder",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",
@@ -7,9 +7,9 @@ export const buildCard = (config,componentScope,store) =>{
7
7
  if (config.style) {
8
8
  card.config.wrapperStyle = JSON.parse(config.style)
9
9
  }
10
- card.elements[0].elements[0].elements[0].elements[1].scope = `#/properties/${config.name}/properties/value`
11
- card.elements[1].scope = `#/properties/${config.name}/properties/url`
12
- card.elements[0].elements[0].elements[1].scope = `#/properties/${config.name}/properties/description`
10
+ card.elements[0].elements[0].elements[0].elements[1].scope = `#/properties/${config.name}/properties/value`;
11
+ card.elements[1].scope = `#/properties/${config.name}/properties/url`;
12
+ card.elements[0].elements[0].elements[1].scope = `#/properties/${config.name}/properties/description`;
13
13
  if(config.layout){
14
14
  card.config.layout = createLayoutFormat(config.layout)
15
15
  }
@@ -51,91 +51,8 @@ function buildOneOf(values: any[]) {
51
51
  title: e.label
52
52
  }));
53
53
  }
54
- function applyValidations(
55
- schemaNode: any,
56
- validations: any[] = [],
57
- requiredArr?: string[],
58
- fieldName?: string
59
- ) {
60
- validations.forEach((rule) => {
61
- if (rule.validationType === "readOnly") {
62
- schemaNode.disabled = true
63
- }
64
- if (rule.validationType === "required") {
65
- if (requiredArr && fieldName) {
66
- requiredArr.push(fieldName);
67
- }
68
- } else {
69
- schemaNode.type = "string";
70
- schemaNode[rule.validationType] =
71
- isNaN(rule.validationValue)
72
- ? rule.validationValue
73
- : Number(rule.validationValue);
74
- }
75
- });
76
- }
77
-
78
- function buildNode(config: any): any {
79
- if (config.type === "Array") {
80
- const arraySchema: any = {
81
- type: "array",
82
- items: {
83
- type: "object",
84
- properties: {},
85
- required: []
86
- }
87
- };
88
-
89
- config.elements?.forEach((child: any) => {
90
- const childNode = buildNode(child);
91
- if (!childNode) return;
92
-
93
- arraySchema.items.properties[child.name] = childNode.schema;
94
-
95
- if (childNode.required?.length) {
96
- arraySchema.items.required.push(child.name);
97
- }
98
- });
99
-
100
- return { schema: arraySchema };
101
- }
102
-
103
- let fieldSchema: any = {};
104
- if (
105
- (config.type === "Select" || config.type === "MultipleSelect") &&
106
- config.value?.length > 0
107
- ) {
108
- if (config.type === "Select") {
109
- fieldSchema.oneOf = buildOneOf(config.value);
110
- } else {
111
- fieldSchema.type = "array";
112
- fieldSchema.items = {
113
- oneOf: buildOneOf(config.value)
114
- };
115
- }
116
- }
117
-
118
- if (config.validation) {
119
- applyValidations(fieldSchema, config.validation);
120
- }
121
-
122
- const required =
123
- config.validation?.some(
124
- (v: any) => v.validationType === "required"
125
- )
126
- ? [config.name]
127
- : [];
128
-
129
- return {
130
- schema: fieldSchema,
131
- required
132
- };
133
- }
134
-
135
54
  export function buildSchemaFromConfig(config: any, parentSchema: any) {
136
-
137
55
  if (config.elements) {
138
- // 2️⃣ Handle Array component
139
56
  if (config.type === "Array") {
140
57
  parentSchema.properties ??= {};
141
58
  parentSchema.properties[config.name] ??= {
@@ -160,17 +77,16 @@ export function buildSchemaFromConfig(config: any, parentSchema: any) {
160
77
  return;
161
78
  }
162
79
  }
163
- // 3️⃣ Handle normal field components
164
80
  parentSchema.properties ??= {};
165
81
  parentSchema.properties[config.name] ??= {};
166
-
167
82
  const fieldSchema = parentSchema.properties[config.name];
168
-
169
- // Required validation
170
83
  config.validation?.forEach((v: any) => {
171
84
  if (v.validationType === "required") {
172
85
  parentSchema.required ??= [];
173
86
  parentSchema.required.push(config.name);
87
+ } else if (v.validationType === "readOnly") {
88
+ fieldSchema.type = "string";
89
+ fieldSchema.disabled = true;
174
90
  } else {
175
91
  fieldSchema.type = "string";
176
92
  fieldSchema[v.validationType] = isNaN(v.validationValue)
@@ -178,16 +94,12 @@ export function buildSchemaFromConfig(config: any, parentSchema: any) {
178
94
  : Number(v.validationValue);
179
95
  }
180
96
  });
181
-
182
- // Select
183
97
  if (config.type === "Select" && config.value?.length) {
184
98
  fieldSchema.oneOf = config.value.map((v: any) => ({
185
99
  const: v.value,
186
100
  title: v.label,
187
101
  }));
188
102
  }
189
-
190
- // MultipleSelect
191
103
  if (config.type === "MultipleSelect" && config.value?.length) {
192
104
  fieldSchema.type = "array";
193
105
  fieldSchema.items = {
@@ -199,10 +111,9 @@ export function buildSchemaFromConfig(config: any, parentSchema: any) {
199
111
  }
200
112
  }
201
113
 
202
- export const buildSchema = (config) =>{
203
- buildSchemaFromConfig(config,schema)
114
+ export const buildSchema = (config) => {
115
+ buildSchemaFromConfig(config, schema)
204
116
  return schema;
205
-
206
117
  }
207
118
 
208
119
  const buildUiSchema = (config: any, store?: any) => {
@@ -31,18 +31,18 @@ export default (funcParams: funcParamsProps) => {
31
31
  return formData;
32
32
  }
33
33
  saveFormdataInSessionStorage(config)
34
- return config
34
+ return { ...config, type: "page" }
35
35
  },
36
36
  getUiSchema: function () {
37
37
  const UiSchema = _.cloneDeep(PageMasterUiSchema(store.theme.myTheme));
38
- if (sessionStorage.getItem("copiedConfig") ) {
38
+ if (sessionStorage.getItem("copiedConfig")) {
39
39
  Component(store, dynamicData, submitHandler, service).ElementPathSetter(UiSchema)
40
40
  }
41
41
  return UiSchema;
42
42
  },
43
43
  getSchema: () => {
44
44
  const schema = _.cloneDeep(PageMasterSchema);
45
- if (sessionStorage.getItem("copiedConfig") ) {
45
+ if (sessionStorage.getItem("copiedConfig")) {
46
46
  schema.properties.RemoveItemButton.disabled = false;
47
47
  }
48
48
  return schema;
@@ -70,8 +70,8 @@ export default (funcParams: funcParamsProps) => {
70
70
  },
71
71
  saveHandler: async () => await saveHandler(store, service, submitHandler),
72
72
  Edit_Components: Component(store, dynamicData, submitHandler, service).editComponents,
73
-
74
- Delete_Components: async function() {
73
+
74
+ Delete_Components: async function () {
75
75
  await Component(store, dynamicData, submitHandler, service).deleteComponents(false);
76
76
  store.updateDialog("popUpPageMasterComponent");
77
77
  },
@@ -99,25 +99,25 @@ export default (funcParams: funcParamsProps) => {
99
99
  store.updateDialog("popUpPageMasterEvent");
100
100
  sessionStorage.removeItem('rowId');
101
101
  },
102
- deletePopUpComponent: function(){
102
+ deletePopUpComponent: function () {
103
103
  const rowId = dynamicData.path.split(".")[1];
104
- sessionStorage.setItem('rowId',rowId);
104
+ sessionStorage.setItem('rowId', rowId);
105
105
  store.updateDialog("popUpPageMasterComponent");
106
106
  },
107
- deletePopUpEvent: function(){
107
+ deletePopUpEvent: function () {
108
108
  const rowId = dynamicData.path.split(".")[1];
109
- sessionStorage.setItem('rowId',rowId);
109
+ sessionStorage.setItem('rowId', rowId);
110
110
  store.updateDialog("popUpPageMasterEvent");
111
111
  },
112
112
 
113
113
 
114
- copyPasteElement: function(){
115
- Component(store, dynamicData, submitHandler, service).copyPasteElement(store,this.setPage.bind(this));
114
+ copyPasteElement: function () {
115
+ Component(store, dynamicData, submitHandler, service).copyPasteElement(store, this.setPage.bind(this));
116
116
  },
117
-
118
- RemoveItemButton: function(){
117
+
118
+ RemoveItemButton: function () {
119
119
  Component(store, dynamicData, submitHandler, service).RemoveItemButton(store)
120
120
  },
121
-
121
+
122
122
  }
123
123
  };
@@ -1,4 +1,4 @@
1
- import _ from "lodash";
1
+ import _, { isObject, mapKeys } from "lodash";
2
2
  import { handlersProps } from "./interface";
3
3
  export const executeEvents = (params: handlersProps) => {
4
4
  let nextEvent = [];
@@ -68,9 +68,7 @@ function executeEventsHandler(params: handlersProps) {
68
68
  params.componentName,
69
69
  params.config,
70
70
  params.store,
71
- params.service,
72
71
  params.formDataHolder,
73
- params.pageLoad
74
72
  );
75
73
  } else if (params.config.Handler === "onBackHandler") {
76
74
  return params.store.functionParameters?.handleBack();
@@ -145,7 +143,7 @@ function executeCustomHandler(params: handlersProps) {
145
143
  }
146
144
 
147
145
  }
148
- function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any, formDataHolder: any, pageLoad: boolean) {
146
+ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, formDataHolder: any) {
149
147
  if (eventConfig.type === "Select" && handlerResponse?.data) {
150
148
  if (!_.isEmpty(handlerResponse?.data)) {
151
149
  store.setSchema((pre) => {
@@ -178,38 +176,27 @@ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig:
178
176
  }
179
177
  }
180
178
  else if (eventConfig.type === "page") {
181
- if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
179
+ if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data && isObject(handlerResponse.data))) {
182
180
  store.newData = {
183
181
  ...store.newData,
184
182
  ...handlerResponse?.data
185
183
  }
186
- formDataHolder = { ...formDataHolder, ...handlerResponse?.data }
187
- if (!pageLoad) {
188
- store.setFormdata((pre: any) => { return { ...pre, ...handlerResponse?.data } })
189
- }
184
+ const keys = Object.keys(handlerResponse.data)
185
+ keys.map((e) => {
186
+ formDataHolder[e] = { ...formDataHolder, [e]: handlerResponse.data[e] }
187
+ })
188
+
190
189
  }
191
190
  }
192
191
  else if (eventConfig.type === "Table" && eventConfig.lazyLoading) {
193
192
  if (handlerResponse && handlerResponse?.data) {
194
193
  formDataHolder[componentName] = handlerResponse.data?.data
195
194
  formDataHolder[`${componentName}_RowCount`] = handlerResponse.data?.meta?.totalRowCount
196
- if (!pageLoad) {
197
- store.setFormdata((pre: any) => {
198
- return {
199
- ...pre,
200
- [componentName]: handlerResponse.data?.data,
201
- [`${componentName}_RowCount`]: handlerResponse.data?.meta?.totalRowCount
202
- }
203
- })
204
- }
205
195
  }
206
196
  }
207
197
  else {
208
198
  if (handlerResponse) {
209
199
  formDataHolder[componentName] = handlerResponse.data
210
- if (!pageLoad) {
211
- store.setFormdata((pre) => { return { ...pre, [componentName]: handlerResponse.data } });
212
- }
213
200
  }
214
201
  }
215
202
  };
@@ -10,5 +10,4 @@ export interface handlersProps {
10
10
  parentEventOutput?: any,
11
11
  functionsProvider?:Record<string,any>
12
12
  formDataHolder?:Record<string,any>
13
- pageLoad?: boolean
14
13
  }
@@ -62,7 +62,7 @@ export const extractEvents = (eventConfig: any) => {
62
62
  return eventGroups;
63
63
  };
64
64
  export default (funcParams: funcParamsProps) => {
65
- const formDataHolder = {}
65
+ const formDataHolder = {};
66
66
  let executeEventsParameters: handlersProps = {
67
67
  config: {}, componentName: "",
68
68
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
@@ -104,7 +104,7 @@ export default (funcParams: funcParamsProps) => {
104
104
  await executeRefreshHandler({
105
105
  config: {}, componentName: "",
106
106
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
107
- serviceHolder: this, eventGroups, formDataHolder: formDataHolder, pageLoad: true
107
+ serviceHolder: this, eventGroups, formDataHolder: formDataHolder
108
108
  })
109
109
  funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }))
110
110
  uiSchema.elements.push(notifyUiSchema);
@@ -225,35 +225,46 @@ export default (funcParams: funcParamsProps) => {
225
225
  },
226
226
  onBack: async function (functionParameters) {
227
227
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
228
- await this.callHandler("onBack", functionParameters)
228
+ this.callHandler("onBack", functionParameters)
229
229
  if (eventGroups?.["onBack"]?.[path] === undefined) {
230
230
  functionParameters?.handleBack()
231
231
  }
232
232
  },
233
233
  onNext: async function (functionParameters) {
234
234
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
235
- await this.callHandler("onNext", functionParameters)
235
+ this.callHandler("onNext", functionParameters)
236
236
  if (eventGroups?.["onNext"]?.[path] === undefined) {
237
237
  functionParameters?.handleNext()
238
238
  }
239
239
  },
240
240
  onReset: async function (functionParameters) {
241
241
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
242
- await this.callHandler("onReset", functionParameters)
242
+ this.callHandler("onReset", functionParameters)
243
243
  if (eventGroups?.["onReset"]?.[path] === undefined) {
244
244
  functionParameters?.handleReset()
245
245
  }
246
246
  },
247
- callHandler: async function (eventType: string, functionParameters?: any) {
247
+ callHandler: function (eventType: string, functionParameters?: any) {
248
248
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[funcParams.dynamicData.path.split(".").length - 1];
249
249
  if (eventGroups?.[eventType]?.[path] !== undefined) {
250
- Promise.all(eventGroups?.[eventType]?.[path].map((eventConfig) => {
250
+ (eventGroups?.[eventType]?.[path].map((eventConfig) => {
251
251
  executeEventsParameters.store.functionParameters = functionParameters
252
- executeEvents({
253
- ...executeEventsParameters,
254
- config: eventConfig,
255
- componentName: path
256
- })
252
+ if (eventConfig.Handler === "refresh") {
253
+ executeEvents({
254
+ ...executeEventsParameters,
255
+ config: eventConfig,
256
+ componentName: path,
257
+ formDataHolder: formDataHolder
258
+ }).then((res) => {
259
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
260
+ });
261
+ } else {
262
+ executeEvents({
263
+ ...executeEventsParameters,
264
+ config: eventConfig,
265
+ componentName: path
266
+ })
267
+ }
257
268
  }))
258
269
  }
259
270
  },