coject 2.4.51 → 2.4.52
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/cjs/Builder/Header/theme.d.ts +1 -1
- package/dist/cjs/Builder/Page/theme.d.ts +1 -1
- package/dist/cjs/Builder/Sidebar/theme.d.ts +1 -1
- package/dist/cjs/Components/Checkbox/theme.d.ts +1 -1
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.d.ts +11 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.js +15 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.js.map +1 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.d.ts +10 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.js +15 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.js.map +1 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.d.ts +10 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.js +15 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.js.map +1 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.d.ts +12 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.js +806 -0
- package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.js.map +1 -0
- package/dist/cjs/Components/CojectReport/PdfContainer.d.ts +9 -0
- package/dist/cjs/Components/CojectReport/PdfContainer.js +206 -0
- package/dist/cjs/Components/CojectReport/PdfContainer.js.map +1 -0
- package/dist/cjs/Components/CojectReport/index.d.ts +14 -0
- package/dist/cjs/Components/CojectReport/index.js +27 -0
- package/dist/cjs/Components/CojectReport/index.js.map +1 -0
- package/dist/cjs/Components/DatePicker/theme.d.ts +1 -1
- package/dist/cjs/Components/Grid/theme.d.ts +1 -1
- package/dist/cjs/Components/Input/theme.d.ts +1 -1
- package/dist/cjs/Components/InputLabel/theme.d.ts +1 -1
- package/dist/cjs/Components/Modal/theme.d.ts +1 -1
- package/dist/cjs/Components/PDFGenerator/theme.d.ts +1 -1
- package/dist/cjs/Components/Scanner/theme.d.ts +1 -1
- package/dist/cjs/Components/Select/theme.d.ts +1 -1
- package/dist/cjs/Components/Switch/theme.d.ts +1 -1
- package/dist/cjs/Components/Upload/theme.d.ts +1 -1
- package/dist/cjs/Components/index.d.ts +1 -0
- package/dist/cjs/Components/index.js +4 -1
- package/dist/cjs/Components/index.js.map +1 -1
- package/dist/esm/Builder/Header/theme.d.ts +1 -1
- package/dist/esm/Builder/Page/theme.d.ts +1 -1
- package/dist/esm/Builder/Sidebar/theme.d.ts +1 -1
- package/dist/esm/Components/Checkbox/theme.d.ts +1 -1
- package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.d.ts +11 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.js +10 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.js.map +1 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.d.ts +10 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.js +10 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.js.map +1 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.d.ts +10 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.js +10 -0
- package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.js.map +1 -0
- package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.d.ts +12 -0
- package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.js +801 -0
- package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.js.map +1 -0
- package/dist/esm/Components/CojectReport/PdfContainer.d.ts +9 -0
- package/dist/esm/Components/CojectReport/PdfContainer.js +201 -0
- package/dist/esm/Components/CojectReport/PdfContainer.js.map +1 -0
- package/dist/esm/Components/CojectReport/index.d.ts +14 -0
- package/dist/esm/Components/CojectReport/index.js +20 -0
- package/dist/esm/Components/CojectReport/index.js.map +1 -0
- package/dist/esm/Components/DatePicker/theme.d.ts +1 -1
- package/dist/esm/Components/Grid/theme.d.ts +1 -1
- package/dist/esm/Components/Input/theme.d.ts +1 -1
- package/dist/esm/Components/InputLabel/theme.d.ts +1 -1
- package/dist/esm/Components/Modal/theme.d.ts +1 -1
- package/dist/esm/Components/PDFGenerator/theme.d.ts +1 -1
- package/dist/esm/Components/Scanner/theme.d.ts +1 -1
- package/dist/esm/Components/Select/theme.d.ts +1 -1
- package/dist/esm/Components/Switch/theme.d.ts +1 -1
- package/dist/esm/Components/Upload/theme.d.ts +1 -1
- package/dist/esm/Components/index.d.ts +1 -0
- package/dist/esm/Components/index.js +2 -0
- package/dist/esm/Components/index.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
// React Pdf
|
|
8
|
+
const renderer_1 = require("@react-pdf/renderer");
|
|
9
|
+
// QR Code
|
|
10
|
+
const qr_code_styling_1 = __importDefault(require("qr-code-styling"));
|
|
11
|
+
// Function to get decimal value
|
|
12
|
+
const getDecimal = (value) => {
|
|
13
|
+
if (value === null || value === undefined)
|
|
14
|
+
return 0;
|
|
15
|
+
if (typeof value === "number")
|
|
16
|
+
return value;
|
|
17
|
+
const parsed = parseFloat(value);
|
|
18
|
+
return isNaN(parsed) ? 0 : parsed;
|
|
19
|
+
};
|
|
20
|
+
// Function to handle text wrapping
|
|
21
|
+
const ensureWrap = (val) => {
|
|
22
|
+
if (val === null || val === undefined)
|
|
23
|
+
return "";
|
|
24
|
+
const str = String(val);
|
|
25
|
+
if (/[\u0600-\u06FF]/.test(str))
|
|
26
|
+
return str;
|
|
27
|
+
return str.split(' ').map(word => {
|
|
28
|
+
if (word.length > 8) {
|
|
29
|
+
return word.split('').join('\u200B');
|
|
30
|
+
}
|
|
31
|
+
return word;
|
|
32
|
+
}).join(' ');
|
|
33
|
+
};
|
|
34
|
+
// Function to get common styles
|
|
35
|
+
const ProcessItemCommonStyles = (item, json) => {
|
|
36
|
+
const x = getDecimal(item?.x);
|
|
37
|
+
const y = getDecimal(item?.y);
|
|
38
|
+
const width = getDecimal(item?.width);
|
|
39
|
+
const height = getDecimal(item?.height);
|
|
40
|
+
const styles = {
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
left: `${x / json.PxPerCmH}cm`,
|
|
43
|
+
top: `${y / json.PxPerCmV}cm`,
|
|
44
|
+
width: `${width / json.PxPerCmH}cm`,
|
|
45
|
+
height: `${height / json.PxPerCmV}cm`,
|
|
46
|
+
zIndex: 1
|
|
47
|
+
};
|
|
48
|
+
if (item?.fontFamily)
|
|
49
|
+
styles.fontFamily = item.fontFamily;
|
|
50
|
+
if (item?.fontSize)
|
|
51
|
+
styles.fontSize = `${item.fontSize}pt`;
|
|
52
|
+
if (item?.fontStyle) {
|
|
53
|
+
const stylesList = item.fontStyle.split(' ');
|
|
54
|
+
if (stylesList.includes('font-bold'))
|
|
55
|
+
styles.fontWeight = 'bold';
|
|
56
|
+
if (stylesList.includes('font-italic'))
|
|
57
|
+
styles.fontStyle = 'italic';
|
|
58
|
+
if (stylesList.includes('font-underline'))
|
|
59
|
+
styles.textDecoration = 'underline';
|
|
60
|
+
}
|
|
61
|
+
if (item?.color)
|
|
62
|
+
styles.color = item.color;
|
|
63
|
+
if (item?.textAlign)
|
|
64
|
+
styles.textAlign = item.textAlign;
|
|
65
|
+
if (item?.characterSpacing) {
|
|
66
|
+
const spacing = getDecimal(item.characterSpacing);
|
|
67
|
+
styles.characterSpacing = spacing.toString();
|
|
68
|
+
styles.letterSpacing = `${spacing / 1000}`;
|
|
69
|
+
styles.wordSpacing = `${spacing / 1000}em`;
|
|
70
|
+
}
|
|
71
|
+
if (item?.lineHeight) {
|
|
72
|
+
const newHeight = getDecimal(item.lineHeight);
|
|
73
|
+
styles.lineHeight = newHeight > 3 ? `${newHeight}pt` : newHeight.toString();
|
|
74
|
+
}
|
|
75
|
+
if (item?.border) {
|
|
76
|
+
switch (item.border) {
|
|
77
|
+
case "single":
|
|
78
|
+
styles.border = "1px solid black";
|
|
79
|
+
break;
|
|
80
|
+
case "double":
|
|
81
|
+
styles.border = "3px double black";
|
|
82
|
+
break;
|
|
83
|
+
case "dashed":
|
|
84
|
+
styles.border = "1px dashed black";
|
|
85
|
+
break;
|
|
86
|
+
case "dotted":
|
|
87
|
+
styles.border = "1px dotted black";
|
|
88
|
+
break;
|
|
89
|
+
case "dropShadow":
|
|
90
|
+
styles.boxShadow = "2px 2px 6px rgba(0, 0, 0, 0.4)";
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (item?.backgroundColor)
|
|
97
|
+
styles.backgroundColor = item.backgroundColor;
|
|
98
|
+
if (item?.textRotation) {
|
|
99
|
+
const rotation = getDecimal(item.textRotation);
|
|
100
|
+
styles.transform = `rotate(${rotation}deg)`;
|
|
101
|
+
styles.transformOrigin = 'left top';
|
|
102
|
+
}
|
|
103
|
+
return styles;
|
|
104
|
+
};
|
|
105
|
+
const ProcessTextObjectItem = (item, json) => {
|
|
106
|
+
const styles = ProcessItemCommonStyles(item, json);
|
|
107
|
+
if (item?.hyperlink && item.hyperlink.trim() !== "") {
|
|
108
|
+
styles.textDecoration = "underline";
|
|
109
|
+
styles.color = "blue";
|
|
110
|
+
styles.hyperlink = item.hyperlink;
|
|
111
|
+
}
|
|
112
|
+
return styles;
|
|
113
|
+
};
|
|
114
|
+
const ProcessDatabaseFieldItem = (item, json) => {
|
|
115
|
+
return ProcessItemCommonStyles(item, json);
|
|
116
|
+
};
|
|
117
|
+
const ProcessPictureItem = (item, json) => {
|
|
118
|
+
const x = getDecimal(item?.x);
|
|
119
|
+
const y = getDecimal(item?.y);
|
|
120
|
+
const width = getDecimal(item?.width);
|
|
121
|
+
const height = getDecimal(item?.height);
|
|
122
|
+
const styles = {
|
|
123
|
+
position: 'absolute',
|
|
124
|
+
left: `${x / json.PxPerCmH}cm`,
|
|
125
|
+
top: `${y / json.PxPerCmV}cm`,
|
|
126
|
+
width: `${width / json.PxPerCmH}cm`,
|
|
127
|
+
height: `${height / json.PxPerCmV}cm`,
|
|
128
|
+
};
|
|
129
|
+
if (item?.rounded) {
|
|
130
|
+
styles.borderRadius = 50;
|
|
131
|
+
}
|
|
132
|
+
if (item?.layerPosition === "back") {
|
|
133
|
+
styles.zIndex = 2;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
styles.zIndex = 0;
|
|
137
|
+
}
|
|
138
|
+
if (item?.border) {
|
|
139
|
+
switch (item.border) {
|
|
140
|
+
case "single":
|
|
141
|
+
styles.border = "1px solid black";
|
|
142
|
+
break;
|
|
143
|
+
case "double":
|
|
144
|
+
styles.border = "3px double black";
|
|
145
|
+
break;
|
|
146
|
+
case "dashed":
|
|
147
|
+
styles.border = "1px dashed black";
|
|
148
|
+
break;
|
|
149
|
+
case "dotted":
|
|
150
|
+
styles.border = "1px dotted black";
|
|
151
|
+
break;
|
|
152
|
+
case "dropShadow":
|
|
153
|
+
styles.boxShadow = "2px 2px 6px rgba(0, 0, 0, 0.4)";
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return styles;
|
|
160
|
+
};
|
|
161
|
+
const ProcessSpecialFieldItem = (item, json) => {
|
|
162
|
+
return ProcessItemCommonStyles(item, json);
|
|
163
|
+
};
|
|
164
|
+
const ProcessTableObjectItem = (item, json) => {
|
|
165
|
+
const x = getDecimal(item?.x);
|
|
166
|
+
const y = getDecimal(item?.y);
|
|
167
|
+
const width = getDecimal(item?.width);
|
|
168
|
+
const styles = {
|
|
169
|
+
position: 'absolute',
|
|
170
|
+
left: `${x / json.PxPerCmH}cm`,
|
|
171
|
+
top: `${y / json.PxPerCmV}cm`,
|
|
172
|
+
width: `${width / json.PxPerCmH}cm`,
|
|
173
|
+
zIndex: 1
|
|
174
|
+
};
|
|
175
|
+
return styles;
|
|
176
|
+
};
|
|
177
|
+
const ProcessQrCodeObjectItem = (item, json) => {
|
|
178
|
+
const x = getDecimal(item?.x);
|
|
179
|
+
const y = getDecimal(item?.y);
|
|
180
|
+
const width = getDecimal(item?.width);
|
|
181
|
+
const height = getDecimal(item?.height);
|
|
182
|
+
const styles = {
|
|
183
|
+
position: 'absolute',
|
|
184
|
+
left: `${x / json.PxPerCmH}cm`,
|
|
185
|
+
top: `${y / json.PxPerCmV}cm`,
|
|
186
|
+
width: `${width / json.PxPerCmH}cm`,
|
|
187
|
+
height: `${height / json.PxPerCmV}cm`,
|
|
188
|
+
zIndex: 1
|
|
189
|
+
};
|
|
190
|
+
return styles;
|
|
191
|
+
};
|
|
192
|
+
const QrCodeGeneratedImage = ({ item, styles }) => {
|
|
193
|
+
const generateQrCode = async () => {
|
|
194
|
+
if (!item?.data)
|
|
195
|
+
return "";
|
|
196
|
+
const size = Math.max(getDecimal(item?.width) || 300, 300);
|
|
197
|
+
const qrContent = unescape(encodeURIComponent(item?.data || ""));
|
|
198
|
+
let base64Image = "";
|
|
199
|
+
if (item?.image && item.image.startsWith("http")) {
|
|
200
|
+
const proxiedUrl = `https://wsrv.nl/?url=${encodeURIComponent(item.image)}&w=150&h=150&fit=contain&output=png`;
|
|
201
|
+
try {
|
|
202
|
+
const res = await fetch(proxiedUrl);
|
|
203
|
+
const blob = await res.blob();
|
|
204
|
+
base64Image = await new Promise(resolve => {
|
|
205
|
+
const reader = new FileReader();
|
|
206
|
+
reader.onloadend = () => resolve(reader.result || "");
|
|
207
|
+
reader.readAsDataURL(blob);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
console.error("Failed to proxy image CORS", e);
|
|
212
|
+
base64Image = proxiedUrl;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
base64Image = item?.image || "";
|
|
217
|
+
}
|
|
218
|
+
const qrCode = new qr_code_styling_1.default({
|
|
219
|
+
width: size,
|
|
220
|
+
height: size,
|
|
221
|
+
data: qrContent,
|
|
222
|
+
image: base64Image,
|
|
223
|
+
margin: getDecimal(item?.margin) || 0,
|
|
224
|
+
qrOptions: {
|
|
225
|
+
errorCorrectionLevel: item?.image ? "H" : (item?.errorCorrectionLevel || "M")
|
|
226
|
+
},
|
|
227
|
+
dotsOptions: {
|
|
228
|
+
type: item?.dotsOptionsType === "rounded" ? "rounded" : (item?.dotsOptionsType || "square"),
|
|
229
|
+
color: item?.dotsOptionsColor || "#000000"
|
|
230
|
+
},
|
|
231
|
+
cornersSquareOptions: {
|
|
232
|
+
type: item?.cornersSquareOptionsType === "rounded" ? "extra-rounded" : (item?.cornersSquareOptionsType || "square"),
|
|
233
|
+
color: item?.cornersSquareOptionsColor || "#000000"
|
|
234
|
+
},
|
|
235
|
+
cornersDotOptions: {
|
|
236
|
+
type: item?.cornersDotOptionsType === "rounded" ? "dot" : (item?.cornersDotOptionsType || "square"),
|
|
237
|
+
color: item?.cornersDotOptionsColor || "#000000"
|
|
238
|
+
},
|
|
239
|
+
backgroundOptions: {
|
|
240
|
+
color: item?.backgroundOptionsColor || "#ffffff"
|
|
241
|
+
},
|
|
242
|
+
imageOptions: {
|
|
243
|
+
crossOrigin: "anonymous",
|
|
244
|
+
margin: 2,
|
|
245
|
+
imageSize: 0.3
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
try {
|
|
249
|
+
const buffer = await qrCode.getRawData("png");
|
|
250
|
+
if (buffer) {
|
|
251
|
+
return new Promise((resolve) => {
|
|
252
|
+
const reader = new FileReader();
|
|
253
|
+
reader.onloadend = () => resolve(reader.result || "");
|
|
254
|
+
reader.readAsDataURL(buffer);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
console.error("Failed to generate QR Code locally:", error);
|
|
260
|
+
return `https://quickchart.io/qr?size=300&text=${encodeURIComponent(item?.data || "")}¢erImageUrl=${encodeURIComponent(item?.image || "")}&dark=${(item?.dotsOptionsColor || "#000000").replace("#", "")}&margin=${getDecimal(item?.margin) || 0}`;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return (react_1.default.createElement(renderer_1.View, { style: { ...styles } }, item?.data ? (react_1.default.createElement(renderer_1.Image, { src: generateQrCode(), style: { width: '100%', height: '100%', objectFit: 'contain' }, cache: false })) : null));
|
|
264
|
+
};
|
|
265
|
+
const processTableColumns = (item, json) => {
|
|
266
|
+
const columns = item?.columns;
|
|
267
|
+
if (!columns || typeof columns !== 'object')
|
|
268
|
+
return {};
|
|
269
|
+
const visibleKeys = Object.keys(columns).filter(key => !columns[key]?.hide);
|
|
270
|
+
visibleKeys.sort((a, b) => (columns[a]?.ordinal ?? 0) - (columns[b]?.ordinal ?? 0));
|
|
271
|
+
const firstColumnName = visibleKeys[0];
|
|
272
|
+
const lastColumnName = visibleKeys[visibleKeys.length - 1];
|
|
273
|
+
const tableTotalPx = getDecimal(item?.width) || 1064;
|
|
274
|
+
const pxPerCmH = json.PxPerCmH || 53.057;
|
|
275
|
+
let totalSizedWidthPx = 0;
|
|
276
|
+
const columnWidthsPx = {};
|
|
277
|
+
visibleKeys.forEach((key) => {
|
|
278
|
+
const col = columns[key];
|
|
279
|
+
if (col?.width) {
|
|
280
|
+
const widthPx = parseFloat(col.width);
|
|
281
|
+
if (!isNaN(widthPx)) {
|
|
282
|
+
columnWidthsPx[key] = widthPx;
|
|
283
|
+
totalSizedWidthPx += widthPx;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const flexColumnCount = visibleKeys.filter(k => !columnWidthsPx[k]).length;
|
|
288
|
+
const remainingPx = Math.max(0, tableTotalPx - totalSizedWidthPx);
|
|
289
|
+
const flexWidthPx = flexColumnCount > 0 ? remainingPx / flexColumnCount : 0;
|
|
290
|
+
const updatedColumns = {};
|
|
291
|
+
visibleKeys.forEach((key) => {
|
|
292
|
+
const col = columns[key];
|
|
293
|
+
const styleDict = {
|
|
294
|
+
fontSize: '12pt',
|
|
295
|
+
padding: '0.1cm 0.2cm',
|
|
296
|
+
minHeight: '1cm',
|
|
297
|
+
display: 'flex',
|
|
298
|
+
flexDirection: 'column',
|
|
299
|
+
justifyContent: 'center',
|
|
300
|
+
borderBottom: '1px solid #000',
|
|
301
|
+
borderRight: '1px solid #000',
|
|
302
|
+
zIndex: 1,
|
|
303
|
+
fontWeight: 'bold'
|
|
304
|
+
};
|
|
305
|
+
if (col?.fontSize)
|
|
306
|
+
styleDict.fontSize = `${col.fontSize}pt`;
|
|
307
|
+
if (col?.color)
|
|
308
|
+
styleDict.color = col.color;
|
|
309
|
+
if (col?.backgroundColor)
|
|
310
|
+
styleDict.backgroundColor = col.backgroundColor;
|
|
311
|
+
if (col?.textAlign)
|
|
312
|
+
styleDict.textAlign = col.textAlign;
|
|
313
|
+
if ((key === lastColumnName && json.Direction === 'rtl') ||
|
|
314
|
+
(key === firstColumnName && json.Direction === 'ltr')) {
|
|
315
|
+
styleDict.borderLeft = '1px solid #000';
|
|
316
|
+
}
|
|
317
|
+
if (columnWidthsPx[key]) {
|
|
318
|
+
styleDict.width = `${columnWidthsPx[key] / pxPerCmH}cm`;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
styleDict.width = `${flexWidthPx / pxPerCmH}cm`;
|
|
322
|
+
}
|
|
323
|
+
updatedColumns[key] = {
|
|
324
|
+
ordinal: col?.ordinal ?? 0,
|
|
325
|
+
text: col?.text ?? key,
|
|
326
|
+
isCustom: col?.isCustom ?? false,
|
|
327
|
+
valueSource: col?.valueSource ?? null,
|
|
328
|
+
staticValue: col?.staticValue ?? null,
|
|
329
|
+
parameter: col?.parameter ?? null,
|
|
330
|
+
Styles: styleDict,
|
|
331
|
+
merge: col?.merge,
|
|
332
|
+
colSpanLabel: col?.colSpanLabel,
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
return updatedColumns;
|
|
336
|
+
};
|
|
337
|
+
// Returns the value of a special field (like page number, date, etc.) based on the given key and context
|
|
338
|
+
const getSpecialFieldValue = (key, context) => {
|
|
339
|
+
switch (key) {
|
|
340
|
+
case 'pageNumber': return context.pageNumber || 1;
|
|
341
|
+
case 'totalPages': return context.totalPages || 1;
|
|
342
|
+
case 'pageXofY':
|
|
343
|
+
if (context?.dir === 'rtl') {
|
|
344
|
+
return `الصفحة ${context.pageNumber || 1} من ${context.totalPages || 1}`;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
return `Page ${context.pageNumber || 1} of ${context.totalPages || 1}`;
|
|
348
|
+
}
|
|
349
|
+
case 'currentDate': return formatDate(new Date(), context.format || "dd/MM/yyyy", context.dir);
|
|
350
|
+
case 'currentTime': return formatDate(new Date(), context.format || "HH:mm", context.dir);
|
|
351
|
+
case 'currentDateTime': return formatDate(new Date(), context.format || "dd/MM/yyyy HH:mm", context.dir);
|
|
352
|
+
case 'printedBy': return context.printedBy || "Unknown";
|
|
353
|
+
case 'printDate': return formatDate(context.printDate || new Date(), context.format || "dd/MM/yyyy HH:mm", context.dir);
|
|
354
|
+
default: return '';
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
// Formats a Date object into a string based on the provided format pattern
|
|
358
|
+
const formatDate = (date, format = "dd/MM/yyyy HH:mm", dir) => {
|
|
359
|
+
if (!(date instanceof Date))
|
|
360
|
+
date = new Date(date);
|
|
361
|
+
const lang = dir === 'rtl' ? 'ar' : 'en';
|
|
362
|
+
const days = {
|
|
363
|
+
ar: ["الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"],
|
|
364
|
+
en: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
|
365
|
+
};
|
|
366
|
+
const months = {
|
|
367
|
+
ar: [
|
|
368
|
+
"يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو",
|
|
369
|
+
"يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"
|
|
370
|
+
],
|
|
371
|
+
en: [
|
|
372
|
+
"January", "February", "March", "April", "May", "June",
|
|
373
|
+
"July", "August", "September", "October", "November", "December"
|
|
374
|
+
]
|
|
375
|
+
};
|
|
376
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
377
|
+
const map = {
|
|
378
|
+
dddd: days[lang][date.getDay()],
|
|
379
|
+
dd: pad(date.getDate()),
|
|
380
|
+
d: date.getDate(),
|
|
381
|
+
MMMM: months[lang][date.getMonth()],
|
|
382
|
+
MMM: months[lang][date.getMonth()].slice(0, 3),
|
|
383
|
+
MM: pad(date.getMonth() + 1),
|
|
384
|
+
M: date.getMonth() + 1,
|
|
385
|
+
yyyy: date.getFullYear(),
|
|
386
|
+
yy: String(date.getFullYear()).slice(-2),
|
|
387
|
+
HH: pad(date.getHours()),
|
|
388
|
+
hh: pad((date.getHours() % 12) || 12),
|
|
389
|
+
mm: pad(date.getMinutes()),
|
|
390
|
+
ss: pad(date.getSeconds()),
|
|
391
|
+
A: lang === "ar" ? (date.getHours() >= 12 ? "م" : "ص") : (date.getHours() >= 12 ? "PM" : "AM")
|
|
392
|
+
};
|
|
393
|
+
return format.replace(/dddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|HH|hh|mm|ss|A/g, m => map[m]);
|
|
394
|
+
};
|
|
395
|
+
// Currency symbol mapping
|
|
396
|
+
const currencySymbolMap = {
|
|
397
|
+
'SAR': 'ر.س',
|
|
398
|
+
'EGP': 'ج.م',
|
|
399
|
+
'$': '$',
|
|
400
|
+
'€': '€',
|
|
401
|
+
'£': '£'
|
|
402
|
+
};
|
|
403
|
+
// Formats a Number based on the provided format pattern
|
|
404
|
+
const formatNumber = (val, format) => {
|
|
405
|
+
if (val === null || val === undefined || val === '' || isNaN(val))
|
|
406
|
+
return '';
|
|
407
|
+
let num = Number(val);
|
|
408
|
+
let prefix = '';
|
|
409
|
+
let suffix = '';
|
|
410
|
+
let hasComma = false;
|
|
411
|
+
let decimalPlaces = 0;
|
|
412
|
+
let f = format || "";
|
|
413
|
+
if (f.includes("%")) {
|
|
414
|
+
suffix += "%";
|
|
415
|
+
f = f.replace("%", "");
|
|
416
|
+
}
|
|
417
|
+
// Replace known currency codes with Arabic symbols before parsing
|
|
418
|
+
for (const [code, symbol] of Object.entries(currencySymbolMap)) {
|
|
419
|
+
if (f.startsWith(code)) {
|
|
420
|
+
prefix = symbol + ' ';
|
|
421
|
+
f = f.slice(code.length);
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const match = f.match(/^([^\d#]*)([\d#,\.]+)([^\d#]*)$/);
|
|
426
|
+
if (match) {
|
|
427
|
+
if (!prefix)
|
|
428
|
+
prefix = match[1] || "";
|
|
429
|
+
let core = match[2];
|
|
430
|
+
suffix = (match[3] || "") + suffix;
|
|
431
|
+
hasComma = core.includes(",");
|
|
432
|
+
const dotIdx = core.indexOf(".");
|
|
433
|
+
if (dotIdx !== -1) {
|
|
434
|
+
decimalPlaces = core.length - dotIdx - 1;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
let str = num.toFixed(decimalPlaces);
|
|
438
|
+
if (hasComma) {
|
|
439
|
+
let parts = str.split(".");
|
|
440
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
441
|
+
str = parts.join(".");
|
|
442
|
+
}
|
|
443
|
+
return prefix + str + suffix;
|
|
444
|
+
};
|
|
445
|
+
const ProcessPanelItem = (item, json) => {
|
|
446
|
+
return ProcessItemCommonStyles(item, json);
|
|
447
|
+
};
|
|
448
|
+
const ProcessItem = ({ apiData, item, pageIndex, tableData, json, parameter, totalPages }) => {
|
|
449
|
+
if (item?.type === "text-object" && ((!item?.fixed && pageIndex == 0) || item?.fixed)) {
|
|
450
|
+
const itemStyles = ProcessTextObjectItem(item, json);
|
|
451
|
+
const { position, left, top, width, height, zIndex, border, boxShadow, backgroundColor, ...textStyles } = itemStyles;
|
|
452
|
+
const containerStyles = { position, left, top, width, height, zIndex, border, boxShadow, backgroundColor };
|
|
453
|
+
return (react_1.default.createElement(renderer_1.View, { style: containerStyles },
|
|
454
|
+
react_1.default.createElement(renderer_1.Text, { style: {
|
|
455
|
+
...textStyles,
|
|
456
|
+
fontSize: textStyles.fontSize || '12pt',
|
|
457
|
+
hyphens: 'none'
|
|
458
|
+
} }, ensureWrap(item?.text))));
|
|
459
|
+
}
|
|
460
|
+
else if (item?.type === "database-field") {
|
|
461
|
+
let fieldValue = '';
|
|
462
|
+
const itemStyles = ProcessDatabaseFieldItem(item, json);
|
|
463
|
+
const sourceData = apiData?.[item?.dataSource];
|
|
464
|
+
if (Array.isArray(sourceData)) {
|
|
465
|
+
fieldValue = sourceData[0]?.[item?.field] ?? '';
|
|
466
|
+
}
|
|
467
|
+
else if (typeof sourceData === 'object') {
|
|
468
|
+
fieldValue = sourceData?.[item?.field] ?? '';
|
|
469
|
+
}
|
|
470
|
+
return (react_1.default.createElement(renderer_1.View, { style: { position: itemStyles.position, left: itemStyles.left, top: itemStyles.top, width: itemStyles.width, height: itemStyles.height, zIndex: itemStyles.zIndex, border: itemStyles.border, boxShadow: itemStyles.boxShadow, backgroundColor: itemStyles.backgroundColor } },
|
|
471
|
+
react_1.default.createElement(renderer_1.Text, { style: {
|
|
472
|
+
fontSize: itemStyles.fontSize || '12pt',
|
|
473
|
+
color: itemStyles.color || 'black',
|
|
474
|
+
fontFamily: itemStyles.fontFamily,
|
|
475
|
+
textAlign: itemStyles.textAlign,
|
|
476
|
+
fontWeight: itemStyles.fontWeight,
|
|
477
|
+
fontStyle: itemStyles.fontStyle,
|
|
478
|
+
textDecoration: itemStyles.textDecoration,
|
|
479
|
+
lineHeight: itemStyles.lineHeight,
|
|
480
|
+
letterSpacing: itemStyles.letterSpacing,
|
|
481
|
+
wordSpacing: itemStyles.wordSpacing,
|
|
482
|
+
transform: itemStyles.transform,
|
|
483
|
+
transformOrigin: itemStyles.transformOrigin,
|
|
484
|
+
hyphens: 'none'
|
|
485
|
+
} }, ensureWrap(fieldValue ?? ''))));
|
|
486
|
+
}
|
|
487
|
+
else if (item?.type === "picture") {
|
|
488
|
+
const itemStyles = ProcessPictureItem(item, json);
|
|
489
|
+
let source = item?.sourceType === "parameter" ? parameter[item?.parameter] : item?.source;
|
|
490
|
+
if (typeof source === 'string' && source.startsWith('http')) {
|
|
491
|
+
source = `https://wsrv.nl/?url=${encodeURIComponent(source)}&fit=contain&output=png&.png`;
|
|
492
|
+
}
|
|
493
|
+
else if (typeof source === 'string' && !source.startsWith('data:') && source.length > 100) {
|
|
494
|
+
source = `data:image/png;base64,${source}`;
|
|
495
|
+
}
|
|
496
|
+
return (react_1.default.createElement(renderer_1.View, { style: { ...itemStyles } }, source ? react_1.default.createElement(renderer_1.Image, { src: source, cache: false }) : null));
|
|
497
|
+
}
|
|
498
|
+
else if (item?.type === "special-field") {
|
|
499
|
+
const itemStyles = ProcessSpecialFieldItem(item, json);
|
|
500
|
+
const context = {
|
|
501
|
+
dir: json?.Direction,
|
|
502
|
+
pageNumber: (pageIndex ?? 0) + 1,
|
|
503
|
+
totalPages: totalPages || 1,
|
|
504
|
+
printedBy: "Coject User",
|
|
505
|
+
printDate: new Date(),
|
|
506
|
+
format: item?.format || (item?.fieldType == "currentTime" ? "HH:mm" : "dd/MM/yyyy HH:mm")
|
|
507
|
+
};
|
|
508
|
+
const value = getSpecialFieldValue(item.fieldType, context);
|
|
509
|
+
return (react_1.default.createElement(renderer_1.View, { style: { position: itemStyles.position, left: itemStyles.left, top: itemStyles.top, width: itemStyles.width, height: itemStyles.height, zIndex: itemStyles.zIndex, border: itemStyles.border, boxShadow: itemStyles.boxShadow, backgroundColor: itemStyles.backgroundColor } },
|
|
510
|
+
react_1.default.createElement(renderer_1.Text, { style: {
|
|
511
|
+
fontSize: itemStyles.fontSize || '12pt',
|
|
512
|
+
color: itemStyles.color || 'black',
|
|
513
|
+
fontFamily: itemStyles.fontFamily,
|
|
514
|
+
textAlign: itemStyles.textAlign,
|
|
515
|
+
fontWeight: itemStyles.fontWeight,
|
|
516
|
+
fontStyle: itemStyles.fontStyle,
|
|
517
|
+
textDecoration: itemStyles.textDecoration,
|
|
518
|
+
lineHeight: itemStyles.lineHeight,
|
|
519
|
+
letterSpacing: itemStyles.letterSpacing,
|
|
520
|
+
wordSpacing: itemStyles.wordSpacing,
|
|
521
|
+
transform: itemStyles.transform,
|
|
522
|
+
transformOrigin: itemStyles.transformOrigin,
|
|
523
|
+
hyphens: 'none'
|
|
524
|
+
} }, String(value))));
|
|
525
|
+
}
|
|
526
|
+
else if (item?.type === "table-object") {
|
|
527
|
+
const itemStyles = ProcessTableObjectItem(item, json);
|
|
528
|
+
const updatedColumns = processTableColumns(item, json);
|
|
529
|
+
const updatedColumnsEntries = Object.entries(updatedColumns);
|
|
530
|
+
const hasMerge = updatedColumnsEntries.some(([_, col]) => col.merge?.colSpan > 1);
|
|
531
|
+
const headerItems = [];
|
|
532
|
+
for (let i = 0; i < updatedColumnsEntries.length; i++) {
|
|
533
|
+
const [key, col] = updatedColumnsEntries[i];
|
|
534
|
+
const colSpan = col.merge?.colSpan || 1;
|
|
535
|
+
if (colSpan > 1) {
|
|
536
|
+
const subCols = updatedColumnsEntries.slice(i, i + colSpan);
|
|
537
|
+
headerItems.push({ type: 'merged', col, subCols });
|
|
538
|
+
i += (colSpan - 1);
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
headerItems.push({ type: 'single', key, col });
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// Grouping Logic
|
|
545
|
+
const tableRows = tableData[item?.id] || [];
|
|
546
|
+
const groupConfigs = item?.groups || [];
|
|
547
|
+
const footerConfigs = item?.footer || [];
|
|
548
|
+
const shouldRepeatHeader = groupConfigs.some((g) => g.showHeader);
|
|
549
|
+
const processedRows = [];
|
|
550
|
+
let lastGroupValues = {};
|
|
551
|
+
tableRows.forEach((row, rowIndex) => {
|
|
552
|
+
if (rowIndex > 0) {
|
|
553
|
+
footerConfigs.forEach((footer, fIdx) => {
|
|
554
|
+
const gc = footer.columns?.groupColumn;
|
|
555
|
+
if (gc && row[gc] !== tableRows[rowIndex - 1][gc]) {
|
|
556
|
+
const groupValue = tableRows[rowIndex - 1][gc];
|
|
557
|
+
const prevGroupRows = [];
|
|
558
|
+
for (let i = rowIndex - 1; i >= 0; i--) {
|
|
559
|
+
if (tableRows[i][gc] === groupValue) {
|
|
560
|
+
prevGroupRows.unshift(tableRows[i]);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
processedRows.push({
|
|
567
|
+
type: 'footer-row',
|
|
568
|
+
dataRows: prevGroupRows,
|
|
569
|
+
footerIndex: fIdx,
|
|
570
|
+
key: `gf-${rowIndex}-${fIdx}`
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
let groupChanged = false;
|
|
576
|
+
groupConfigs.forEach((group, groupIndex) => {
|
|
577
|
+
const val = row[group.field];
|
|
578
|
+
if (groupChanged || rowIndex === 0 || val !== lastGroupValues[group.field]) {
|
|
579
|
+
groupChanged = true;
|
|
580
|
+
lastGroupValues[group.field] = val;
|
|
581
|
+
processedRows.push({
|
|
582
|
+
type: 'group-header',
|
|
583
|
+
text: (group.headerText || "").replace(/\{(\w+)\}/g, (_match, key) => row[key] ?? ""),
|
|
584
|
+
key: `gh-${rowIndex}-${groupIndex}`
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
if (shouldRepeatHeader) {
|
|
589
|
+
processedRows.push({
|
|
590
|
+
type: 'table-header',
|
|
591
|
+
key: `th-${rowIndex}`
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
processedRows.push({
|
|
595
|
+
type: 'data-row',
|
|
596
|
+
data: row,
|
|
597
|
+
index: rowIndex,
|
|
598
|
+
key: `dr-${rowIndex}`
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
footerConfigs.forEach((footer, fIdx) => {
|
|
602
|
+
const gc = footer.columns?.groupColumn;
|
|
603
|
+
if (gc && tableRows.length > 0) {
|
|
604
|
+
const groupValue = tableRows[tableRows.length - 1][gc];
|
|
605
|
+
const lastGroupRows = [];
|
|
606
|
+
for (let i = tableRows.length - 1; i >= 0; i--) {
|
|
607
|
+
if (tableRows[i][gc] === groupValue) {
|
|
608
|
+
lastGroupRows.unshift(tableRows[i]);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
processedRows.push({
|
|
615
|
+
type: 'footer-row',
|
|
616
|
+
dataRows: lastGroupRows,
|
|
617
|
+
footerIndex: fIdx,
|
|
618
|
+
key: `gf-last-${fIdx}`
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
const renderTableHeader = (headerKey) => (react_1.default.createElement(renderer_1.View, { key: headerKey, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' } }, headerItems.map((hItem, idx) => {
|
|
623
|
+
if (hItem.type === 'single') {
|
|
624
|
+
return (react_1.default.createElement(renderer_1.View, { key: idx, style: {
|
|
625
|
+
...hItem.col.Styles,
|
|
626
|
+
minHeight: hasMerge ? '2cm' : '1cm',
|
|
627
|
+
justifyContent: 'center'
|
|
628
|
+
} },
|
|
629
|
+
react_1.default.createElement(renderer_1.Text, { wrap: true, style: { textAlign: hItem.col.Styles.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(hItem.col.text || hItem.key))));
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
let totalWidthCm = 0;
|
|
633
|
+
hItem.subCols.forEach(([_, sc]) => totalWidthCm += parseFloat(sc.Styles.width));
|
|
634
|
+
return (react_1.default.createElement(renderer_1.View, { key: idx, style: { flexDirection: 'column', width: `${totalWidthCm}cm` } },
|
|
635
|
+
react_1.default.createElement(renderer_1.View, { style: {
|
|
636
|
+
...hItem.col.Styles,
|
|
637
|
+
width: `${totalWidthCm}cm`,
|
|
638
|
+
minHeight: '1cm',
|
|
639
|
+
justifyContent: 'center',
|
|
640
|
+
alignItems: 'center'
|
|
641
|
+
} },
|
|
642
|
+
react_1.default.createElement(renderer_1.Text, { wrap: true, style: { textAlign: 'center', hyphens: 'none' } }, ensureWrap(hItem.col.colSpanLabel || ""))),
|
|
643
|
+
react_1.default.createElement(renderer_1.View, { style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' } }, hItem.subCols.map(([sk, sc], sidx) => (react_1.default.createElement(renderer_1.View, { key: sidx, style: { ...sc.Styles, minHeight: '1cm', justifyContent: 'center' } },
|
|
644
|
+
react_1.default.createElement(renderer_1.Text, { wrap: true, style: { textAlign: sc.Styles.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(sc.text || sk))))))));
|
|
645
|
+
}
|
|
646
|
+
})));
|
|
647
|
+
const renderTableFooters = (rows, specificFooterIndex) => {
|
|
648
|
+
if (!item?.footer || !Array.isArray(item.footer))
|
|
649
|
+
return null;
|
|
650
|
+
const footersToRender = specificFooterIndex !== undefined
|
|
651
|
+
? [item.footer[specificFooterIndex]]
|
|
652
|
+
: item.footer;
|
|
653
|
+
return footersToRender.map((footerRow, fIdx) => {
|
|
654
|
+
const actualIdx = specificFooterIndex !== undefined ? specificFooterIndex : fIdx;
|
|
655
|
+
const fCols = footerRow?.columns || {};
|
|
656
|
+
const visibility = fCols.footerVisibility || "ALL";
|
|
657
|
+
const groupCol = fCols.groupColumn;
|
|
658
|
+
if (rows === undefined && groupCol)
|
|
659
|
+
return null;
|
|
660
|
+
if (rows !== undefined && !groupCol)
|
|
661
|
+
return null;
|
|
662
|
+
if (visibility === "LAST" && pageIndex !== (totalPages || 1) - 1) {
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
const colKeys = Object.keys(fCols)
|
|
666
|
+
.filter(k => !isNaN(parseInt(k)))
|
|
667
|
+
.sort((a, b) => parseInt(a) - parseInt(b));
|
|
668
|
+
let currentTableColIndex = 0;
|
|
669
|
+
return (react_1.default.createElement(renderer_1.View, { key: `footer-${actualIdx}`, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' }, wrap: false }, colKeys.map((colKey, cIdx) => {
|
|
670
|
+
const fCol = fCols[colKey];
|
|
671
|
+
const colSpan = parseInt(fCol.colSpan) || 1;
|
|
672
|
+
let widthCm = 0;
|
|
673
|
+
for (let i = 0; i < colSpan; i++) {
|
|
674
|
+
if (currentTableColIndex + i < updatedColumnsEntries.length) {
|
|
675
|
+
const [, tableCol] = updatedColumnsEntries[currentTableColIndex + i];
|
|
676
|
+
widthCm += parseFloat(tableCol.Styles.width);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
currentTableColIndex += colSpan;
|
|
680
|
+
let cellValue = '';
|
|
681
|
+
if (fCol.valueSource === 'staticValue') {
|
|
682
|
+
cellValue = fCol.staticValue || '';
|
|
683
|
+
}
|
|
684
|
+
else if (fCol.valueSource === 'parameter') {
|
|
685
|
+
cellValue = (parameter && fCol.parameter) ? (parameter[fCol.parameter] ?? '') : '';
|
|
686
|
+
}
|
|
687
|
+
else if (fCol.valueSource === 'field' && fCol.field) {
|
|
688
|
+
const fieldName = fCol.field;
|
|
689
|
+
const rowsToUse = rows || tableData[item?.id] || [];
|
|
690
|
+
let values = rowsToUse.map((r) => parseFloat(r[fieldName])).filter((v) => !isNaN(v));
|
|
691
|
+
if (fCol.aggregate === 'sum') {
|
|
692
|
+
cellValue = values.reduce((a, b) => a + b, 0);
|
|
693
|
+
}
|
|
694
|
+
else if (fCol.aggregate === 'count') {
|
|
695
|
+
cellValue = values.length;
|
|
696
|
+
}
|
|
697
|
+
else if (fCol.aggregate === 'avg') {
|
|
698
|
+
cellValue = values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;
|
|
699
|
+
}
|
|
700
|
+
else if (fCol.aggregate === 'min') {
|
|
701
|
+
cellValue = values.length ? Math.min(...values) : 0;
|
|
702
|
+
}
|
|
703
|
+
else if (fCol.aggregate === 'max') {
|
|
704
|
+
cellValue = values.length ? Math.max(...values) : 0;
|
|
705
|
+
}
|
|
706
|
+
if (fCol.format) {
|
|
707
|
+
cellValue = formatNumber(cellValue, fCol.format);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const cellStyle = {
|
|
711
|
+
width: `${widthCm}cm`,
|
|
712
|
+
minHeight: '1cm',
|
|
713
|
+
display: 'flex',
|
|
714
|
+
justifyContent: 'center',
|
|
715
|
+
flexDirection: 'column',
|
|
716
|
+
padding: '0.1cm 0.2cm',
|
|
717
|
+
borderRight: '1px solid #000',
|
|
718
|
+
borderBottom: '1px solid #000',
|
|
719
|
+
zIndex: 1,
|
|
720
|
+
fontWeight: 'bold'
|
|
721
|
+
};
|
|
722
|
+
if ((cIdx === colKeys.length - 1 && json?.Direction === 'rtl') ||
|
|
723
|
+
(cIdx === 0 && json?.Direction === 'ltr')) {
|
|
724
|
+
cellStyle.borderLeft = '1px solid #000';
|
|
725
|
+
}
|
|
726
|
+
if (fCol.fontSize)
|
|
727
|
+
cellStyle.fontSize = `${fCol.fontSize}pt`;
|
|
728
|
+
else
|
|
729
|
+
cellStyle.fontSize = '12pt';
|
|
730
|
+
if (fCol.color)
|
|
731
|
+
cellStyle.color = fCol.color;
|
|
732
|
+
if (fCol.backgroundColor)
|
|
733
|
+
cellStyle.backgroundColor = fCol.backgroundColor;
|
|
734
|
+
if (fCol.textAlign)
|
|
735
|
+
cellStyle.textAlign = fCol.textAlign;
|
|
736
|
+
return (react_1.default.createElement(renderer_1.View, { key: cIdx, style: { ...cellStyle } },
|
|
737
|
+
react_1.default.createElement(renderer_1.Text, { style: { textAlign: cellStyle.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(cellValue))));
|
|
738
|
+
})));
|
|
739
|
+
});
|
|
740
|
+
};
|
|
741
|
+
return ((tableData[item?.id]?.length || pageIndex == 0) ? (react_1.default.createElement(renderer_1.View, { style: { ...itemStyles, borderTop: '1px solid #000' }, wrap: true },
|
|
742
|
+
!shouldRepeatHeader && renderTableHeader('top-header'),
|
|
743
|
+
react_1.default.createElement(renderer_1.View, { style: { flexDirection: 'column' } },
|
|
744
|
+
processedRows.map((pRow) => {
|
|
745
|
+
if (pRow.type === 'group-header') {
|
|
746
|
+
return (react_1.default.createElement(renderer_1.View, { key: pRow.key, style: {
|
|
747
|
+
flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row',
|
|
748
|
+
backgroundColor: '#f0f0f0',
|
|
749
|
+
borderBottom: '1px solid #000',
|
|
750
|
+
borderLeft: '1px solid #000',
|
|
751
|
+
borderRight: '1px solid #000',
|
|
752
|
+
padding: '4pt',
|
|
753
|
+
zIndex: 1
|
|
754
|
+
} },
|
|
755
|
+
react_1.default.createElement(renderer_1.Text, { style: { fontWeight: 'bold', fontSize: '10pt', hyphens: 'none' } }, ensureWrap(pRow.text))));
|
|
756
|
+
}
|
|
757
|
+
if (pRow.type === 'table-header') {
|
|
758
|
+
return renderTableHeader(pRow.key);
|
|
759
|
+
}
|
|
760
|
+
if (pRow.type === 'footer-row') {
|
|
761
|
+
return renderTableFooters(pRow.dataRows, pRow.footerIndex);
|
|
762
|
+
}
|
|
763
|
+
const { data: row, index: idx } = pRow;
|
|
764
|
+
return (react_1.default.createElement(renderer_1.View, { key: pRow.key, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' }, wrap: false }, updatedColumnsEntries.map(([key, col], i) => {
|
|
765
|
+
const { color, backgroundColor, fontWeight, ...filteredStyles } = col?.Styles || {};
|
|
766
|
+
let cellValue;
|
|
767
|
+
if (col?.isCustom && col?.valueSource) {
|
|
768
|
+
switch (col.valueSource) {
|
|
769
|
+
case 'rowNum':
|
|
770
|
+
cellValue = idx + 1;
|
|
771
|
+
break;
|
|
772
|
+
case 'staticValue':
|
|
773
|
+
cellValue = col?.staticValue ?? '';
|
|
774
|
+
break;
|
|
775
|
+
case 'parameter':
|
|
776
|
+
cellValue = parameter?.[col?.parameter] ?? '';
|
|
777
|
+
break;
|
|
778
|
+
default: cellValue = row[key] ?? '';
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
cellValue = row[key] ?? '';
|
|
783
|
+
}
|
|
784
|
+
return (react_1.default.createElement(renderer_1.View, { key: i, style: { ...filteredStyles, backgroundColor: backgroundColor } },
|
|
785
|
+
react_1.default.createElement(renderer_1.Text, { style: {
|
|
786
|
+
width: '100%',
|
|
787
|
+
textAlign: filteredStyles.textAlign || (json?.Direction === 'rtl' ? 'right' : 'left'),
|
|
788
|
+
color: color || 'black',
|
|
789
|
+
hyphens: 'none'
|
|
790
|
+
} }, ensureWrap(cellValue))));
|
|
791
|
+
})));
|
|
792
|
+
}),
|
|
793
|
+
renderTableFooters()))) : null);
|
|
794
|
+
}
|
|
795
|
+
else if (item?.type === "qr-code-object") {
|
|
796
|
+
const itemStyles = ProcessQrCodeObjectItem(item, json);
|
|
797
|
+
return react_1.default.createElement(QrCodeGeneratedImage, { item: item, styles: itemStyles });
|
|
798
|
+
}
|
|
799
|
+
else if (item?.type === "panel") {
|
|
800
|
+
const itemStyles = ProcessPanelItem(item, json);
|
|
801
|
+
return (react_1.default.createElement(renderer_1.View, { style: { ...itemStyles } }, item?.body?.items?.map((childItem, index) => (react_1.default.createElement(ProcessItem, { key: index, apiData: apiData, item: childItem, json: json, pageIndex: pageIndex, tableData: tableData, parameter: parameter, totalPages: totalPages })))));
|
|
802
|
+
}
|
|
803
|
+
return null;
|
|
804
|
+
};
|
|
805
|
+
exports.default = ProcessItem;
|
|
806
|
+
//# sourceMappingURL=ProcessItem.js.map
|