impaktapps-ui-builder 1.0.102 → 1.0.103

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.
@@ -3,10 +3,6 @@ export declare let schema: {
3
3
  properties: {};
4
4
  required: any[];
5
5
  };
6
- export declare const buildSchema: (config: any, tableName?: string, isArrayType?: boolean) => {
7
- type: string;
8
- properties: {};
9
- required: any[];
10
- };
6
+ export declare function buildSchema(config: any): any;
11
7
  declare const buildUiSchema: (config: any, store?: any) => any;
12
8
  export default buildUiSchema;
@@ -7,3 +7,4 @@ export { default as buildConfig } from "../builder/build/buildConfig";
7
7
  export { default as buildUiSchema } from "../builder/build/buildUiSchema";
8
8
  export { buildSchema } from "../builder/build/buildUiSchema";
9
9
  export { default as clearFromSessionStorage } from "../builder/services/utils";
10
+ export { downloadFileFromBase64, downloadFileFromUrl } from "../runtime/services/downloadFile";
@@ -1,2 +1,6 @@
1
1
  export declare const downloadFile: (obj: any) => void;
2
- export declare const doDownload: (response: any, service: any) => void;
2
+ export declare function downloadFileFromBase64({ data, name }: {
3
+ data: string;
4
+ name: string;
5
+ }): void;
6
+ export declare const downloadFileFromUrl: (response: any, service: any) => void;
@@ -1,3 +1,4 @@
1
+ import { downloadFileFromBase64 } from "./downloadFile";
1
2
  interface funcParamsProps {
2
3
  store: any;
3
4
  dynamicData: any;
@@ -28,6 +29,7 @@ declare const _default: (funcParams: funcParamsProps) => {
28
29
  onReset: (functionParameters: any) => Promise<void>;
29
30
  callHandler: (eventType: string, functionParameters?: any) => Promise<void>;
30
31
  downloadFile: (obj: any) => void;
31
- download: (response: any, service: any) => void;
32
+ downloadFileFromUrl: (response: any, service: any) => void;
33
+ downloadFileFromBase64: typeof downloadFileFromBase64;
32
34
  };
33
35
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-ui-builder",
3
- "version": "1.0.102",
3
+ "version": "1.0.103",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",
@@ -1,6 +1,4 @@
1
1
  import _ from "lodash";
2
- import emptyBox from "./uischema/emptyBox";
3
- import cardSlider from "./uischema/cardSlider";
4
2
  import { buildLeaderBoard } from "./buildLeaderboard";
5
3
  import { buildProgressBarCard } from "./buildProgressBarCard";
6
4
  import { buildProgressBar } from "./buildProgressBar";
@@ -47,126 +45,117 @@ export let schema = {
47
45
  properties: {},
48
46
  required: []
49
47
  };
50
- //MultipleSelect
51
- function buildRule(configObj: any, tableName?: string, arrayHolderName?: boolean) {
52
- if (arrayHolderName) {
53
- if (schema.properties?.[tableName]?.items?.properties) {
54
- if (!schema.properties?.[tableName]?.items?.properties?.[configObj.name]) {
55
- schema.properties[tableName].items.properties[configObj.name] = {};
56
- if (configObj.type === "Select" && configObj.value?.length > 0) {
57
- schema.properties[tableName].items.properties[configObj.name] = {
58
- oneOf: configObj.value.map((e) => {
59
- return { const: e.value, title: e.label }
60
- })
61
- }
62
- }
63
- else if (configObj.type === "MultipleSelect" && configObj.value?.length > 0) {
64
- schema.properties[tableName].items.properties[configObj.name] = {
65
- items: {
66
- oneOf: configObj.value.map((e) => {
67
- return { const: e.value, title: e.label }
68
- })
69
- }
70
- }
71
- }
72
- }
48
+ function buildOneOf(values: any[]) {
49
+ return values.map((e) => ({
50
+ const: e.value,
51
+ title: e.label
52
+ }));
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
73
63
  }
74
- } else if ((configObj.type === "Select" || configObj.type === "MultipleSelect") && configObj.value?.length > 0) {
75
- if (configObj.type === "Select") {
76
- schema.properties[configObj.name] = {
77
- oneOf: configObj.value.map((e) => {
78
- return { const: e.value, title: e.label }
79
- })
64
+ if (rule.validationType === "required") {
65
+ if (requiredArr && fieldName) {
66
+ requiredArr.push(fieldName);
80
67
  }
68
+ } else {
69
+ schemaNode.type = "string";
70
+ schemaNode[rule.validationType] =
71
+ isNaN(rule.validationValue)
72
+ ? rule.validationValue
73
+ : Number(rule.validationValue);
81
74
  }
82
- else if (configObj.type === "MultipleSelect") {
83
- schema.properties[configObj.name] = {
84
- items: {
85
- oneOf: configObj.value.map((e) => {
86
- return { const: e.value, title: e.label }
87
- })
88
- }
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: []
89
86
  }
90
- }
91
- }
92
- if (configObj.validation) {
93
- configObj.validation.forEach((rule: any) => {
94
- if (tableName) {
95
- if (schema.properties?.[tableName]?.items?.properties) {
96
- if (!schema.properties?.[tableName]?.items?.properties?.[configObj.name]) {
97
- schema.properties[tableName].items.properties[configObj.name] = {};
98
- if (configObj.type === "Select" || configObj.value?.length > 0) {
99
- schema.properties[tableName].items.properties[configObj.name] = {
100
- oneOf: configObj.value.map((e) => {
101
- return { const: e.value, title: e.label }
102
- })
103
- }
104
- }
105
- else if (configObj.type === "MultipleSelect" || configObj.value?.length > 0) {
106
- schema.properties[tableName].items.properties[configObj.name] = {
107
- items: {
108
- oneOf: configObj.value.map((e) => {
109
- return { const: e.value, title: e.label }
110
- })
111
- }
112
- }
113
- }
114
- }
115
- if (rule.validationType === "required") {
116
- schema.properties?.[tableName]?.items?.required.push(configObj.name)
117
- } else {
118
- schema.properties[tableName].items.properties[configObj.name]["type"] = "string"
119
- schema.properties[tableName].items.properties[configObj.name][rule.validationType] =
120
- isNaN(rule.validationValue) ?
121
- rule.validationValue : Number(rule.validationValue)
122
- }
87
+ };
123
88
 
124
- }
125
- } else {
126
- if (!schema.properties[configObj.name]) {
127
- schema.properties[configObj.name] = {};
128
- }
129
- if (rule.validationType === "required") {
130
- schema.required.push(configObj.name)
131
- } else {
132
- schema.properties[configObj.name]["type"] = "string"
133
- schema.properties[configObj.name][rule.validationType] =
134
- isNaN(rule.validationValue) ?
135
- rule.validationValue : Number(rule.validationValue)
136
- }
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);
137
97
  }
138
98
  });
99
+
100
+ return { schema: arraySchema };
139
101
  }
140
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
+ : [];
141
128
 
129
+ return {
130
+ schema: fieldSchema,
131
+ required
132
+ };
142
133
  }
143
- export const buildSchema = (config: any, tableName?: string, isArrayType?: boolean) => {
144
- buildRule(config, tableName, isArrayType);
145
- if (config?.elements) {
146
- if ( config.type == "Array") {
147
- if (!schema.properties[config.name]) {
148
- schema.properties[config.name] = {
149
- type: "array",
150
- items: {
151
- type: "object",
152
- properties: {},
153
- required: []
154
- }
155
- }
156
- }
157
- config.elements.map((e, elemInd) => {
158
- buildSchema(e, config.name, config.type === "Array" ? true : false)
159
- })
160
- }
161
- else {
162
- config.elements.map((e, elemInd) => {
163
- buildSchema(e)
164
- })
134
+
135
+ export function buildSchema(config: any): any {
136
+ const schema: any = {
137
+ type: "object",
138
+ properties: {},
139
+ required: []
140
+ };
141
+
142
+ config.elements?.forEach((element: any) => {
143
+ const node = buildNode(element);
144
+ if (!node) return;
145
+
146
+ schema.properties[element.name] = node.schema;
147
+
148
+ if (node.required?.length) {
149
+ schema.required.push(element.name);
165
150
  }
151
+ });
152
+
153
+ if (schema.required.length === 0) {
154
+ delete schema.required;
166
155
  }
167
- return schema;
168
- }
169
156
 
157
+ return schema;
158
+ };
170
159
 
171
160
  const buildUiSchema = (config: any, store?: any) => {
172
161
  let elements: any = {};
@@ -387,7 +376,7 @@ const buildUiSchema = (config: any, store?: any) => {
387
376
  }
388
377
  if (cellElem.elementType == "tableHeader") {
389
378
  const headerElem = buildUiSchema(cellElem, store);
390
- tableHeaderElements.push({widget:headerElem});
379
+ tableHeaderElements.push({ widget: headerElem });
391
380
  return false;
392
381
  }
393
382
  const tableElem = {
@@ -58,15 +58,15 @@ export const ComponentSchema: any = {
58
58
  { title: "Date Column", const: "date" },
59
59
  { title: "DateTime Column", const: "dateTime" },
60
60
  { title: "Amount Column", const: "amount" },
61
- { title: "Center Column", const: "action"}
61
+ { title: "Center Column", const: "action" }
62
62
  ]
63
63
  },
64
64
  variant: {
65
65
  oneOf: [
66
- { title: "Outlined", const: "outlined" },
67
- { title: "Filled", const: "filled" },
68
- { title: "Standard", const: "standard" },
69
- ]
66
+ { title: "Outlined", const: "outlined" },
67
+ { title: "Filled", const: "filled" },
68
+ { title: "Standard", const: "standard" },
69
+ ]
70
70
  },
71
71
  orientation: {
72
72
  oneOf: [
@@ -83,7 +83,7 @@ export const ComponentSchema: any = {
83
83
  { title: "Put", const: "put" },
84
84
  ]
85
85
  },
86
- maxPageSize:{
86
+ maxPageSize: {
87
87
  type: "number",
88
88
  oneOf: [
89
89
  { title: "10", const: 10 },
@@ -297,6 +297,7 @@ export const ComponentSchema: any = {
297
297
  { const: "minLength", title: "Minimum Length" },
298
298
  { const: "maxLength", title: "Maximum Length" },
299
299
  { const: "pattern", title: "Pattern" },
300
+ { const: "readOnly", title: "Read Only" },
300
301
  ]
301
302
  },
302
303
  validationValue: {
@@ -1,3 +1,5 @@
1
+ import { title } from "process";
2
+
1
3
  export const EventSchema = {
2
4
  type: "object",
3
5
  properties: {
@@ -72,7 +74,8 @@ export const EventSchema = {
72
74
  oneOf: [
73
75
  { title: "RankProvider", const: "RankProvider" },
74
76
  { title: "Download File", const: "downloadFile" },
75
- { title: "Download", const: "download" },
77
+ { title: "downloadFileFromUrl", const: "downloadFileFromUrl" },
78
+ { title: "downloadFileFromBase64", const: "downloadFileFromBase64" }
76
79
  ]
77
80
  },
78
81
  body: {
@@ -30,7 +30,7 @@ const sectionLabels = {
30
30
  Timer: ["Core", "Events", "Style", "Validation"],
31
31
  Rank: ["Core", "Events", "Style", "Validation"],
32
32
  Button: ["Core", "Properties", "Events", "Style", "Validation"],
33
- Array: ["Core", "Components", "Properties","Validation"],
33
+ Array: ["Core", "Components", "Properties","Events","Validation"],
34
34
  Radio: ["Core", "Properties", "Events", "Style", "Validation"],
35
35
  Text: ["Core", "Properties", "Events", "Style", "Validation"],
36
36
  TextArea: ["Core", "Properties", "Events", "Style", "Validation"],
@@ -1,10 +1,11 @@
1
1
 
2
- export {default as pageMaster} from "../builder/services/pageMaster"
3
- export {default as pageMasterEvents} from "../builder/services/event"
4
- export {default as pageMasterComponents} from "../builder/services/component"
5
- export {default as pageService} from "../runtime/services/service"
6
- export { schema} from "../builder/build/buildUiSchema"
7
- export {default as buildConfig} from "../builder/build/buildConfig"
8
- export {default as buildUiSchema} from "../builder/build/buildUiSchema"
9
- export {buildSchema} from "../builder/build/buildUiSchema"
10
- export {default as clearFromSessionStorage} from "../builder/services/utils"
2
+ export { default as pageMaster } from "../builder/services/pageMaster"
3
+ export { default as pageMasterEvents } from "../builder/services/event"
4
+ export { default as pageMasterComponents } from "../builder/services/component"
5
+ export { default as pageService } from "../runtime/services/service"
6
+ export { schema } from "../builder/build/buildUiSchema"
7
+ export { default as buildConfig } from "../builder/build/buildConfig"
8
+ export { default as buildUiSchema } from "../builder/build/buildUiSchema"
9
+ export { buildSchema } from "../builder/build/buildUiSchema"
10
+ export { default as clearFromSessionStorage } from "../builder/services/utils"
11
+ export { downloadFileFromBase64, downloadFileFromUrl } from "../runtime/services/downloadFile"
@@ -15,13 +15,43 @@ export const downloadFile = (obj: any) => {
15
15
  URL.revokeObjectURL(url);
16
16
  document.body.removeChild(link);
17
17
  };
18
+ export function downloadFileFromBase64({ data, name }: { data: string; name: string }) {
19
+ const binary = window.atob(data);
20
+ const bytes = new Uint8Array(binary.length);
18
21
 
19
- export const doDownload = (response: any, service) => {
22
+ for (let i = 0; i < binary.length; i++) {
23
+ bytes[i] = binary.charCodeAt(i);
24
+ }
25
+
26
+ const extension = name.split(".").pop()?.toLowerCase();
27
+ const mimeMap: Record<string, string> = {
28
+ pdf: "application/pdf",
29
+ png: "image/png",
30
+ jpg: "image/jpeg",
31
+ jpeg: "image/jpeg",
32
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
33
+ csv: "text/csv",
34
+ };
35
+
36
+ const blob = new Blob([bytes], {
37
+ type: mimeMap[extension!] || "application/octet-stream",
38
+ });
39
+
40
+ const url = URL.createObjectURL(blob);
41
+ const a = document.createElement("a");
42
+ a.href = url;
43
+ a.download = name;
44
+ a.click();
45
+
46
+ URL.revokeObjectURL(url);
47
+ }
48
+
49
+ export const downloadFileFromUrl = (response: any, service) => {
20
50
  let url = `${service.defaults.baseURL}/${response.path}`;
21
51
  if (response?.params) {
22
52
  const keysArray = Object.keys(response?.params);
23
53
  keysArray.map((e, i) => {
24
- url = url + `${i === 0?"?":"&"}${e}=${response?.params[e]}`
54
+ url = url + `${i === 0 ? "?" : "&"}${e}=${response?.params[e]}`
25
55
  })
26
56
  }
27
57
  const link = document.createElement('a');
@@ -30,3 +60,5 @@ export const doDownload = (response: any, service) => {
30
60
  link.click();
31
61
  link.parentNode.removeChild(link);
32
62
  };
63
+
64
+
@@ -1,5 +1,5 @@
1
1
  import _, { isEmpty } from "lodash";
2
- import { doDownload, downloadFile } from "./downloadFile";
2
+ import { downloadFileFromUrl, downloadFile, downloadFileFromBase64 } from "./downloadFile";
3
3
  import { executeEvents, executeRefreshHandler } from "./events";
4
4
  import { handlersProps } from "./interface";
5
5
  let compType: string;
@@ -66,7 +66,7 @@ export default (funcParams: funcParamsProps) => {
66
66
  let executeEventsParameters: handlersProps = {
67
67
  config: {}, componentName: "",
68
68
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
69
- serviceHolder: { downloadFile, download: doDownload, ...funcParams.functionsProvider }, eventGroups,
69
+ serviceHolder: { downloadFile, download: downloadFileFromUrl,downloadFileFromBase64, ...funcParams.functionsProvider }, eventGroups,
70
70
  functionsProvider: funcParams.functionsProvider, formDataHolder
71
71
  };
72
72
  return {
@@ -106,7 +106,7 @@ export default (funcParams: funcParamsProps) => {
106
106
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
107
107
  serviceHolder: this, eventGroups, formDataHolder: {}
108
108
  })
109
-
109
+
110
110
  uiSchema.elements.push(notifyUiSchema);
111
111
  funcParams.store.setUiSchema(uiSchema);
112
112
  },
@@ -165,7 +165,7 @@ export default (funcParams: funcParamsProps) => {
165
165
  { key: "sorting", value: paginationValues.sorting || [] },
166
166
  { key: "filters", value: paginationValues.tableColumnConfig || [] },
167
167
  { key: "globalFilter", value: paginationValues.globalFilter ?? '' },
168
- { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? []}
168
+ { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? [] }
169
169
  ]
170
170
  const response = await this.callExecuteEvents(paginationValues, apiBody, "onLoad");
171
171
  return response?.data;
@@ -256,7 +256,8 @@ export default (funcParams: funcParamsProps) => {
256
256
  }
257
257
  },
258
258
  downloadFile: downloadFile,
259
- download: doDownload,
259
+ downloadFileFromUrl: downloadFileFromUrl,
260
+ downloadFileFromBase64: downloadFileFromBase64,
260
261
  ...funcParams.functionsProvider
261
262
  };
262
263
  };