@apexcura/core 0.0.14-Beta99 → 0.0.15-Beta0

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/index.d.mts CHANGED
@@ -5,96 +5,148 @@ type styling = {
5
5
  verticalGutter?: number;
6
6
  };
7
7
  type FormExecutorProps = {
8
- table: {
9
- name: string;
10
- label: string;
11
- element: string;
12
- type: string;
13
- thead?: {
14
- id: number;
15
- name: string;
16
- label: string;
17
- }[];
18
- tbody?: {
19
- label: string;
20
- element: string;
21
- type: string;
22
- variable_data?: {
23
- id: {
24
- id: number;
25
- };
26
- Route: {
27
- label: string;
28
- element: string;
29
- type: string;
30
- };
31
- Dose: {
32
- label: string;
33
- element: string;
34
- type: string;
35
- };
36
- Frequency: {
37
- label: string;
38
- element: string;
39
- type: string;
40
- };
41
- When: {
42
- label: string;
43
- element: string;
44
- type: string;
45
- };
46
- Duration: {
47
- label: string;
48
- element: string;
49
- type: string;
50
- };
51
- Instructions: {
52
- label: string;
53
- element: string;
54
- type: string;
55
- };
56
- }[];
57
- }[];
58
- }[];
59
8
  data: {
60
- visible?: boolean;
61
- className?: string;
62
- sectionName?: string;
63
- sectionLabel?: string;
64
- sectionOrder?: number;
65
- colCount: number;
66
- fields: {
9
+ className: string;
10
+ schema?: {
67
11
  name?: string;
68
12
  label?: string;
69
- placeholder?: string;
70
- element?: string;
71
- type?: string;
72
- value?: string | number | boolean | any[] | object[];
73
- fieldNames?: any[];
74
- dropDownOptions?: any[];
13
+ source?: string;
75
14
  visible?: boolean;
15
+ element?: string;
16
+ className?: string;
17
+ action?: string;
18
+ order?: number;
19
+ sie?: string;
20
+ colCount?: number;
76
21
  disabled?: boolean;
77
- required: boolean;
78
- prefix?: React.ReactNode;
79
- suffix?: React.ReactNode;
80
- addonBefore?: React.ReactNode;
81
- defaultValue?: string;
82
- status?: "error" | "warning";
83
- styles?: React.CSSProperties;
84
- fieldClassName?: string;
85
- elementClassName?: string;
86
- variant?: "outlined" | "borderless" | "filled";
22
+ activeClassName?: string;
23
+ listClassName?: string;
24
+ listItemClassName?: string;
25
+ buttonClassName?: string;
26
+ icon?: string;
27
+ placement?: string;
28
+ profileImageClassName?: string;
29
+ value?: string | number | boolean | any[] | object[] | null;
30
+ img?: string;
31
+ primaryText?: string;
32
+ secondaryText?: string;
33
+ count?: number;
34
+ profileImage?: string;
35
+ profileSubClassName?: string;
36
+ subContainerClassName?: string;
37
+ secondTextClassName?: string;
38
+ iconsClassName?: string;
39
+ labelClassName?: string;
40
+ modalContent?: {
41
+ className?: string;
42
+ fields?: {
43
+ _id?: string;
44
+ name?: string;
45
+ label?: string;
46
+ source?: string;
47
+ initial_message?: boolean;
48
+ element: string;
49
+ className?: string;
50
+ position?: string;
51
+ }[];
52
+ };
53
+ items?: {
54
+ icon?: React.JSX.Element;
55
+ label?: string;
56
+ active?: boolean;
57
+ text?: string;
58
+ time?: string;
59
+ }[];
60
+ fields?: {
61
+ name?: string;
62
+ label?: string;
63
+ placeholder?: string;
64
+ element?: string;
65
+ type?: string;
66
+ value?: string | number | boolean | any[] | object[] | null;
67
+ fieldNames?: any[];
68
+ optionType?: string;
69
+ options?: {
70
+ label: string;
71
+ value: string;
72
+ className?: string;
73
+ selectedClassName?: string;
74
+ }[];
75
+ dropDownOptions?: any[];
76
+ visible?: boolean;
77
+ disabled?: boolean;
78
+ required?: boolean;
79
+ prefix?: React.ReactNode;
80
+ suffix?: React.ReactNode;
81
+ addonBefore?: React.ReactNode;
82
+ defaultValue?: string;
83
+ status?: "error" | "warning";
84
+ styles?: React.CSSProperties;
85
+ fieldClassName?: string;
86
+ elementClassName?: string;
87
+ variant?: "outlined" | "borderless" | "filled";
88
+ thead?: {
89
+ id: number;
90
+ name?: string;
91
+ label?: string;
92
+ visible?: boolean;
93
+ required?: boolean;
94
+ key?: string;
95
+ }[];
96
+ tbody?: {
97
+ id?: number;
98
+ name?: string;
99
+ label?: string;
100
+ element?: string;
101
+ type?: string;
102
+ variable_data?: {
103
+ id: {
104
+ id?: number;
105
+ };
106
+ Route?: {
107
+ label: string;
108
+ element: string;
109
+ type: string;
110
+ };
111
+ Dose?: {
112
+ label: string;
113
+ element: string;
114
+ type: string;
115
+ };
116
+ Frequency?: {
117
+ label: string;
118
+ element: string;
119
+ type: string;
120
+ };
121
+ When?: {
122
+ label: string;
123
+ element: string;
124
+ type: string;
125
+ };
126
+ Duration?: {
127
+ label: string;
128
+ element: string;
129
+ type: string;
130
+ };
131
+ Instructions?: {
132
+ label: string;
133
+ element: string;
134
+ type: string;
135
+ };
136
+ SubRows?: {
137
+ label: string;
138
+ };
139
+ }[];
140
+ }[];
141
+ payload_keys?: string[];
142
+ api_endpoint?: string;
143
+ next_id?: string;
144
+ action?: string;
145
+ }[];
87
146
  }[];
88
- }[];
89
- chatbot: {
90
- visible: boolean;
91
- name: string;
92
- label?: string;
93
- element: string;
94
- type: string;
95
- value: string;
96
- required: boolean;
97
- }[];
147
+ };
148
+ setData: Function;
149
+ selectedRecord: Function;
98
150
  };
99
151
  type ElementExecutorProps = FormExecutorProps & styling;
100
152
  declare const ElementExecutor: (props: ElementExecutorProps) => React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -5,96 +5,148 @@ type styling = {
5
5
  verticalGutter?: number;
6
6
  };
7
7
  type FormExecutorProps = {
8
- table: {
9
- name: string;
10
- label: string;
11
- element: string;
12
- type: string;
13
- thead?: {
14
- id: number;
15
- name: string;
16
- label: string;
17
- }[];
18
- tbody?: {
19
- label: string;
20
- element: string;
21
- type: string;
22
- variable_data?: {
23
- id: {
24
- id: number;
25
- };
26
- Route: {
27
- label: string;
28
- element: string;
29
- type: string;
30
- };
31
- Dose: {
32
- label: string;
33
- element: string;
34
- type: string;
35
- };
36
- Frequency: {
37
- label: string;
38
- element: string;
39
- type: string;
40
- };
41
- When: {
42
- label: string;
43
- element: string;
44
- type: string;
45
- };
46
- Duration: {
47
- label: string;
48
- element: string;
49
- type: string;
50
- };
51
- Instructions: {
52
- label: string;
53
- element: string;
54
- type: string;
55
- };
56
- }[];
57
- }[];
58
- }[];
59
8
  data: {
60
- visible?: boolean;
61
- className?: string;
62
- sectionName?: string;
63
- sectionLabel?: string;
64
- sectionOrder?: number;
65
- colCount: number;
66
- fields: {
9
+ className: string;
10
+ schema?: {
67
11
  name?: string;
68
12
  label?: string;
69
- placeholder?: string;
70
- element?: string;
71
- type?: string;
72
- value?: string | number | boolean | any[] | object[];
73
- fieldNames?: any[];
74
- dropDownOptions?: any[];
13
+ source?: string;
75
14
  visible?: boolean;
15
+ element?: string;
16
+ className?: string;
17
+ action?: string;
18
+ order?: number;
19
+ sie?: string;
20
+ colCount?: number;
76
21
  disabled?: boolean;
77
- required: boolean;
78
- prefix?: React.ReactNode;
79
- suffix?: React.ReactNode;
80
- addonBefore?: React.ReactNode;
81
- defaultValue?: string;
82
- status?: "error" | "warning";
83
- styles?: React.CSSProperties;
84
- fieldClassName?: string;
85
- elementClassName?: string;
86
- variant?: "outlined" | "borderless" | "filled";
22
+ activeClassName?: string;
23
+ listClassName?: string;
24
+ listItemClassName?: string;
25
+ buttonClassName?: string;
26
+ icon?: string;
27
+ placement?: string;
28
+ profileImageClassName?: string;
29
+ value?: string | number | boolean | any[] | object[] | null;
30
+ img?: string;
31
+ primaryText?: string;
32
+ secondaryText?: string;
33
+ count?: number;
34
+ profileImage?: string;
35
+ profileSubClassName?: string;
36
+ subContainerClassName?: string;
37
+ secondTextClassName?: string;
38
+ iconsClassName?: string;
39
+ labelClassName?: string;
40
+ modalContent?: {
41
+ className?: string;
42
+ fields?: {
43
+ _id?: string;
44
+ name?: string;
45
+ label?: string;
46
+ source?: string;
47
+ initial_message?: boolean;
48
+ element: string;
49
+ className?: string;
50
+ position?: string;
51
+ }[];
52
+ };
53
+ items?: {
54
+ icon?: React.JSX.Element;
55
+ label?: string;
56
+ active?: boolean;
57
+ text?: string;
58
+ time?: string;
59
+ }[];
60
+ fields?: {
61
+ name?: string;
62
+ label?: string;
63
+ placeholder?: string;
64
+ element?: string;
65
+ type?: string;
66
+ value?: string | number | boolean | any[] | object[] | null;
67
+ fieldNames?: any[];
68
+ optionType?: string;
69
+ options?: {
70
+ label: string;
71
+ value: string;
72
+ className?: string;
73
+ selectedClassName?: string;
74
+ }[];
75
+ dropDownOptions?: any[];
76
+ visible?: boolean;
77
+ disabled?: boolean;
78
+ required?: boolean;
79
+ prefix?: React.ReactNode;
80
+ suffix?: React.ReactNode;
81
+ addonBefore?: React.ReactNode;
82
+ defaultValue?: string;
83
+ status?: "error" | "warning";
84
+ styles?: React.CSSProperties;
85
+ fieldClassName?: string;
86
+ elementClassName?: string;
87
+ variant?: "outlined" | "borderless" | "filled";
88
+ thead?: {
89
+ id: number;
90
+ name?: string;
91
+ label?: string;
92
+ visible?: boolean;
93
+ required?: boolean;
94
+ key?: string;
95
+ }[];
96
+ tbody?: {
97
+ id?: number;
98
+ name?: string;
99
+ label?: string;
100
+ element?: string;
101
+ type?: string;
102
+ variable_data?: {
103
+ id: {
104
+ id?: number;
105
+ };
106
+ Route?: {
107
+ label: string;
108
+ element: string;
109
+ type: string;
110
+ };
111
+ Dose?: {
112
+ label: string;
113
+ element: string;
114
+ type: string;
115
+ };
116
+ Frequency?: {
117
+ label: string;
118
+ element: string;
119
+ type: string;
120
+ };
121
+ When?: {
122
+ label: string;
123
+ element: string;
124
+ type: string;
125
+ };
126
+ Duration?: {
127
+ label: string;
128
+ element: string;
129
+ type: string;
130
+ };
131
+ Instructions?: {
132
+ label: string;
133
+ element: string;
134
+ type: string;
135
+ };
136
+ SubRows?: {
137
+ label: string;
138
+ };
139
+ }[];
140
+ }[];
141
+ payload_keys?: string[];
142
+ api_endpoint?: string;
143
+ next_id?: string;
144
+ action?: string;
145
+ }[];
87
146
  }[];
88
- }[];
89
- chatbot: {
90
- visible: boolean;
91
- name: string;
92
- label?: string;
93
- element: string;
94
- type: string;
95
- value: string;
96
- required: boolean;
97
- }[];
147
+ };
148
+ setData: Function;
149
+ selectedRecord: Function;
98
150
  };
99
151
  type ElementExecutorProps = FormExecutorProps & styling;
100
152
  declare const ElementExecutor: (props: ElementExecutorProps) => React.JSX.Element;
package/dist/index.js CHANGED
@@ -96,77 +96,162 @@ function postService(url, method, data) {
96
96
  }
97
97
 
98
98
  // src/libraries/element-executor.tsx
99
- var import_antd = require("antd");
100
99
  var ElementExecutor = (props) => {
101
- console.log(props.table);
102
- const [formData, setFormData] = (0, import_react.useState)({});
103
100
  const [data, setData] = (0, import_react.useState)([]);
101
+ const [schema, setSchema] = (0, import_react.useState)(props.data.schema);
104
102
  const onHandleChange = (name, value) => {
105
- setFormData((prev) => ({ ...prev, [name]: value }));
103
+ let prev = schema;
104
+ prev?.map((fie) => {
105
+ if (fie.name === name) {
106
+ fie["value"] = value;
107
+ props.selectedRecord(fie);
108
+ }
109
+ if (fie.element === "radio=input") {
110
+ fie.options.map((eachOption) => {
111
+ if (eachOption.name === name) {
112
+ props.selectedRecord(eachOption);
113
+ }
114
+ });
115
+ }
116
+ if (fie.fields && fie.fields.length) {
117
+ fie.fields.map((sub) => {
118
+ if (sub.name === name) {
119
+ sub["value"] = value;
120
+ props.selectedRecord(fie);
121
+ }
122
+ return sub;
123
+ });
124
+ }
125
+ return fie;
126
+ });
127
+ setSchema([...prev]);
128
+ props.setData({ ...props.data, schema: prev });
106
129
  };
107
- (0, import_react.useEffect)(() => {
108
- const fetchData = async () => {
109
- try {
110
- const response = await postService("/products/", "POST", []);
111
- if (response !== false && typeof response === "object") {
112
- setData(response.products);
113
- }
114
- } catch (error) {
115
- console.log(error);
130
+ const handleSelectData = async () => {
131
+ try {
132
+ const response = await postService("/products/", "POST", []);
133
+ if (response !== false && typeof response === "object") {
134
+ setData(response.products);
116
135
  }
117
- };
118
- fetchData();
119
- }, []);
120
- const onHandleSubmit = async () => {
121
- console.log(formData);
136
+ } catch (error) {
137
+ console.log(error);
138
+ }
122
139
  };
123
- return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.data.map((eachSection) => {
124
- if (eachSection.visible) {
125
- return /* @__PURE__ */ import_react.default.createElement(import_antd.Row, { gutter: [props.horizontalGutter, props.verticalGutter] }, /* @__PURE__ */ import_react.default.createElement("h3", null, eachSection.sectionLabel), /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 / eachSection.colCount, className: `${eachSection.className}` }, eachSection.fields.map(
126
- (eachField) => {
127
- if (eachField.visible && eachField.element === "input-text") {
128
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.TextElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
129
- } else if (eachField.visible && eachField.element === "input-number") {
130
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.NumberElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
131
- } else if (eachField.visible && eachField.element === "input-gender") {
132
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.SelectElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
133
- } else if (eachField.visible && eachField.element === "input-mobile") {
134
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.NumberElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
135
- } else if (eachField.visible && eachField.element === "input-textarea") {
136
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.TextareaElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
137
- } else if (eachField.visible && eachField.element === "input-checkbox") {
138
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.CheckboxElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
139
- } else if (eachField.visible && eachField.element === "input-radio") {
140
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.RadioElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
141
- } else if (eachField.visible && eachField.element === "input-description") {
142
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.CkEditor, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
143
- } else if (eachField.visible && eachField.element === "input-single-select") {
144
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(
145
- import_ui_components.SingleSelectElement,
146
- {
147
- ...eachField,
148
- dropDownOptions: data.length > 0 ? data : [],
149
- onChange: (value) => onHandleChange(eachField.name || "", value)
150
- }
151
- ));
152
- } else if (eachField.visible && eachField.element === "input-multiple-select") {
153
- return /* @__PURE__ */ import_react.default.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ import_react.default.createElement(
154
- import_ui_components.MultipleSelectElement,
155
- {
156
- ...eachField,
157
- onChange: (value) => onHandleChange(eachField.name || "", value),
158
- dropDownOptions: data.length > 0 ? data : []
159
- }
160
- ));
161
- } else {
162
- return null;
140
+ const renderElement = (elementProps) => {
141
+ switch (elementProps.element) {
142
+ case "input-text":
143
+ return /* @__PURE__ */ import_react.default.createElement(
144
+ import_ui_components.TextElement,
145
+ {
146
+ ...elementProps,
147
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
163
148
  }
164
- return null;
165
- }
166
- )));
149
+ );
150
+ case "input-number":
151
+ return /* @__PURE__ */ import_react.default.createElement(
152
+ import_ui_components.NumberElement,
153
+ {
154
+ ...elementProps,
155
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
156
+ }
157
+ );
158
+ case "input-textarea":
159
+ return /* @__PURE__ */ import_react.default.createElement(
160
+ import_ui_components.TextareaElement,
161
+ {
162
+ ...elementProps,
163
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
164
+ }
165
+ );
166
+ case "input-gender":
167
+ return /* @__PURE__ */ import_react.default.createElement(
168
+ import_ui_components.SelectElement,
169
+ {
170
+ ...elementProps,
171
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
172
+ }
173
+ );
174
+ case "input-mobile":
175
+ return /* @__PURE__ */ import_react.default.createElement(
176
+ import_ui_components.NumberElement,
177
+ {
178
+ ...elementProps,
179
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
180
+ }
181
+ );
182
+ case "input-checkbox":
183
+ return /* @__PURE__ */ import_react.default.createElement(
184
+ import_ui_components.CheckboxElement,
185
+ {
186
+ ...elementProps,
187
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
188
+ }
189
+ );
190
+ case "input-radio":
191
+ return /* @__PURE__ */ import_react.default.createElement(
192
+ import_ui_components.RadioElement,
193
+ {
194
+ ...elementProps,
195
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
196
+ }
197
+ );
198
+ case "input-description":
199
+ return /* @__PURE__ */ import_react.default.createElement(
200
+ import_ui_components.CkEditor,
201
+ {
202
+ ...elementProps,
203
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
204
+ }
205
+ );
206
+ case "input-single-select":
207
+ return /* @__PURE__ */ import_react.default.createElement(
208
+ import_ui_components.SingleSelectElement,
209
+ {
210
+ ...elementProps,
211
+ dropDownOptions: data.length > 0 ? data : [],
212
+ onChange: (value) => onHandleChange(elementProps.name || "", value),
213
+ onClick: handleSelectData
214
+ }
215
+ );
216
+ case "input-multiple-select":
217
+ return /* @__PURE__ */ import_react.default.createElement(
218
+ import_ui_components.MultipleSelectElement,
219
+ {
220
+ ...elementProps,
221
+ dropDownOptions: data.length > 0 ? data : [],
222
+ onChange: (value) => onHandleChange(elementProps.name || "", value),
223
+ onClick: handleSelectData
224
+ }
225
+ );
226
+ case "add-more":
227
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.AddMoreTable, { ...elementProps });
228
+ case "div":
229
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: elementProps.className }, elementProps.label);
230
+ case "button":
231
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.ButtonElement, { ...elementProps });
232
+ case "sidebar":
233
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.Sidebar, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
234
+ case "navbar":
235
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.Navbar, { ...elementProps });
236
+ case "table":
237
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.TableElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
238
+ case "daterangepicker":
239
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.DateRangePickerElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
240
+ case "datepicker":
241
+ return /* @__PURE__ */ import_react.default.createElement(import_ui_components.DatePickerElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
242
+ default:
243
+ return null;
167
244
  }
168
- return null;
169
- }), /* @__PURE__ */ import_react.default.createElement("div", { onClick: onHandleSubmit }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.ButtonElement, null)));
245
+ };
246
+ const renderFields = (schema2) => {
247
+ return schema2 && schema2.map((eachSection) => {
248
+ if (eachSection.visible !== false) {
249
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, eachSection.fields && eachSection.fields.length > 0 ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderElement(eachSection), /* @__PURE__ */ import_react.default.createElement("div", { className: eachSection.className, key: eachSection.name }, eachSection.label && /* @__PURE__ */ import_react.default.createElement("p", { className: eachSection.labelClassName }, eachSection.label), renderFields(eachSection.fields))) : renderElement(eachSection));
250
+ }
251
+ return null;
252
+ });
253
+ };
254
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: props.data.className }, renderFields(schema)));
170
255
  };
171
256
  // Annotate the CommonJS export names for ESM import in node:
172
257
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,6 +1,23 @@
1
1
  // src/libraries/element-executor.tsx
2
- import React, { useEffect, useState } from "react";
3
- import { TextElement, NumberElement, TextareaElement, SelectElement, ButtonElement, RadioElement, CheckboxElement, CkEditor, SingleSelectElement, MultipleSelectElement } from "@apexcura/ui-components";
2
+ import React, { useState } from "react";
3
+ import {
4
+ TextElement,
5
+ NumberElement,
6
+ TextareaElement,
7
+ SelectElement,
8
+ ButtonElement,
9
+ RadioElement,
10
+ CheckboxElement,
11
+ CkEditor,
12
+ SingleSelectElement,
13
+ MultipleSelectElement,
14
+ AddMoreTable,
15
+ Sidebar,
16
+ Navbar,
17
+ TableElement,
18
+ DateRangePickerElement,
19
+ DatePickerElement
20
+ } from "@apexcura/ui-components";
4
21
 
5
22
  // src/services/http-service.tsx
6
23
  import axios from "axios";
@@ -60,77 +77,162 @@ function postService(url, method, data) {
60
77
  }
61
78
 
62
79
  // src/libraries/element-executor.tsx
63
- import { Col, Row } from "antd";
64
80
  var ElementExecutor = (props) => {
65
- console.log(props.table);
66
- const [formData, setFormData] = useState({});
67
81
  const [data, setData] = useState([]);
82
+ const [schema, setSchema] = useState(props.data.schema);
68
83
  const onHandleChange = (name, value) => {
69
- setFormData((prev) => ({ ...prev, [name]: value }));
84
+ let prev = schema;
85
+ prev?.map((fie) => {
86
+ if (fie.name === name) {
87
+ fie["value"] = value;
88
+ props.selectedRecord(fie);
89
+ }
90
+ if (fie.element === "radio=input") {
91
+ fie.options.map((eachOption) => {
92
+ if (eachOption.name === name) {
93
+ props.selectedRecord(eachOption);
94
+ }
95
+ });
96
+ }
97
+ if (fie.fields && fie.fields.length) {
98
+ fie.fields.map((sub) => {
99
+ if (sub.name === name) {
100
+ sub["value"] = value;
101
+ props.selectedRecord(fie);
102
+ }
103
+ return sub;
104
+ });
105
+ }
106
+ return fie;
107
+ });
108
+ setSchema([...prev]);
109
+ props.setData({ ...props.data, schema: prev });
70
110
  };
71
- useEffect(() => {
72
- const fetchData = async () => {
73
- try {
74
- const response = await postService("/products/", "POST", []);
75
- if (response !== false && typeof response === "object") {
76
- setData(response.products);
77
- }
78
- } catch (error) {
79
- console.log(error);
111
+ const handleSelectData = async () => {
112
+ try {
113
+ const response = await postService("/products/", "POST", []);
114
+ if (response !== false && typeof response === "object") {
115
+ setData(response.products);
80
116
  }
81
- };
82
- fetchData();
83
- }, []);
84
- const onHandleSubmit = async () => {
85
- console.log(formData);
117
+ } catch (error) {
118
+ console.log(error);
119
+ }
86
120
  };
87
- return /* @__PURE__ */ React.createElement(React.Fragment, null, props.data.map((eachSection) => {
88
- if (eachSection.visible) {
89
- return /* @__PURE__ */ React.createElement(Row, { gutter: [props.horizontalGutter, props.verticalGutter] }, /* @__PURE__ */ React.createElement("h3", null, eachSection.sectionLabel), /* @__PURE__ */ React.createElement(Col, { span: 24 / eachSection.colCount, className: `${eachSection.className}` }, eachSection.fields.map(
90
- (eachField) => {
91
- if (eachField.visible && eachField.element === "input-text") {
92
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(TextElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
93
- } else if (eachField.visible && eachField.element === "input-number") {
94
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(NumberElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
95
- } else if (eachField.visible && eachField.element === "input-gender") {
96
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(SelectElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
97
- } else if (eachField.visible && eachField.element === "input-mobile") {
98
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(NumberElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
99
- } else if (eachField.visible && eachField.element === "input-textarea") {
100
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(TextareaElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
101
- } else if (eachField.visible && eachField.element === "input-checkbox") {
102
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(CheckboxElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
103
- } else if (eachField.visible && eachField.element === "input-radio") {
104
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(RadioElement, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
105
- } else if (eachField.visible && eachField.element === "input-description") {
106
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(CkEditor, { ...eachField, onChange: (value) => onHandleChange(eachField.name || "", value) }));
107
- } else if (eachField.visible && eachField.element === "input-single-select") {
108
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(
109
- SingleSelectElement,
110
- {
111
- ...eachField,
112
- dropDownOptions: data.length > 0 ? data : [],
113
- onChange: (value) => onHandleChange(eachField.name || "", value)
114
- }
115
- ));
116
- } else if (eachField.visible && eachField.element === "input-multiple-select") {
117
- return /* @__PURE__ */ React.createElement("div", { className: `${eachField.fieldClassName}` }, /* @__PURE__ */ React.createElement(
118
- MultipleSelectElement,
119
- {
120
- ...eachField,
121
- onChange: (value) => onHandleChange(eachField.name || "", value),
122
- dropDownOptions: data.length > 0 ? data : []
123
- }
124
- ));
125
- } else {
126
- return null;
121
+ const renderElement = (elementProps) => {
122
+ switch (elementProps.element) {
123
+ case "input-text":
124
+ return /* @__PURE__ */ React.createElement(
125
+ TextElement,
126
+ {
127
+ ...elementProps,
128
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
127
129
  }
128
- return null;
129
- }
130
- )));
130
+ );
131
+ case "input-number":
132
+ return /* @__PURE__ */ React.createElement(
133
+ NumberElement,
134
+ {
135
+ ...elementProps,
136
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
137
+ }
138
+ );
139
+ case "input-textarea":
140
+ return /* @__PURE__ */ React.createElement(
141
+ TextareaElement,
142
+ {
143
+ ...elementProps,
144
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
145
+ }
146
+ );
147
+ case "input-gender":
148
+ return /* @__PURE__ */ React.createElement(
149
+ SelectElement,
150
+ {
151
+ ...elementProps,
152
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
153
+ }
154
+ );
155
+ case "input-mobile":
156
+ return /* @__PURE__ */ React.createElement(
157
+ NumberElement,
158
+ {
159
+ ...elementProps,
160
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
161
+ }
162
+ );
163
+ case "input-checkbox":
164
+ return /* @__PURE__ */ React.createElement(
165
+ CheckboxElement,
166
+ {
167
+ ...elementProps,
168
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
169
+ }
170
+ );
171
+ case "input-radio":
172
+ return /* @__PURE__ */ React.createElement(
173
+ RadioElement,
174
+ {
175
+ ...elementProps,
176
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
177
+ }
178
+ );
179
+ case "input-description":
180
+ return /* @__PURE__ */ React.createElement(
181
+ CkEditor,
182
+ {
183
+ ...elementProps,
184
+ onChange: (value) => onHandleChange(elementProps.name || "", value)
185
+ }
186
+ );
187
+ case "input-single-select":
188
+ return /* @__PURE__ */ React.createElement(
189
+ SingleSelectElement,
190
+ {
191
+ ...elementProps,
192
+ dropDownOptions: data.length > 0 ? data : [],
193
+ onChange: (value) => onHandleChange(elementProps.name || "", value),
194
+ onClick: handleSelectData
195
+ }
196
+ );
197
+ case "input-multiple-select":
198
+ return /* @__PURE__ */ React.createElement(
199
+ MultipleSelectElement,
200
+ {
201
+ ...elementProps,
202
+ dropDownOptions: data.length > 0 ? data : [],
203
+ onChange: (value) => onHandleChange(elementProps.name || "", value),
204
+ onClick: handleSelectData
205
+ }
206
+ );
207
+ case "add-more":
208
+ return /* @__PURE__ */ React.createElement(AddMoreTable, { ...elementProps });
209
+ case "div":
210
+ return /* @__PURE__ */ React.createElement("div", { className: elementProps.className }, elementProps.label);
211
+ case "button":
212
+ return /* @__PURE__ */ React.createElement(ButtonElement, { ...elementProps });
213
+ case "sidebar":
214
+ return /* @__PURE__ */ React.createElement(Sidebar, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
215
+ case "navbar":
216
+ return /* @__PURE__ */ React.createElement(Navbar, { ...elementProps });
217
+ case "table":
218
+ return /* @__PURE__ */ React.createElement(TableElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
219
+ case "daterangepicker":
220
+ return /* @__PURE__ */ React.createElement(DateRangePickerElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
221
+ case "datepicker":
222
+ return /* @__PURE__ */ React.createElement(DatePickerElement, { ...elementProps, onChange: (value) => onHandleChange(elementProps.name || "", value) });
223
+ default:
224
+ return null;
131
225
  }
132
- return null;
133
- }), /* @__PURE__ */ React.createElement("div", { onClick: onHandleSubmit }, /* @__PURE__ */ React.createElement(ButtonElement, null)));
226
+ };
227
+ const renderFields = (schema2) => {
228
+ return schema2 && schema2.map((eachSection) => {
229
+ if (eachSection.visible !== false) {
230
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, eachSection.fields && eachSection.fields.length > 0 ? /* @__PURE__ */ React.createElement(React.Fragment, null, renderElement(eachSection), /* @__PURE__ */ React.createElement("div", { className: eachSection.className, key: eachSection.name }, eachSection.label && /* @__PURE__ */ React.createElement("p", { className: eachSection.labelClassName }, eachSection.label), renderFields(eachSection.fields))) : renderElement(eachSection));
231
+ }
232
+ return null;
233
+ });
234
+ };
235
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: props.data.className }, renderFields(schema)));
134
236
  };
135
237
  export {
136
238
  ElementExecutor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/core",
3
- "version": "0.0.14-Beta99",
3
+ "version": "0.0.15-Beta0",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",
@@ -28,7 +28,7 @@
28
28
  "build": "tsup"
29
29
  },
30
30
  "dependencies": {
31
- "@apexcura/ui-components": "^0.0.11-Beta57",
31
+ "@apexcura/ui-components": "^0.0.13-Beta0",
32
32
  "@testing-library/jest-dom": "^6.4.2",
33
33
  "@testing-library/react": "^15.0.6",
34
34
  "@types/react-global-configuration": "^1.3.3",