@evergis/react 3.1.39 → 3.1.40
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/components/Dashboard/hooks/useExportPdf.d.ts +1 -1
- package/dist/components/Dashboard/utils/getRootElementId.d.ts +2 -0
- package/dist/components/Dashboard/utils/index.d.ts +2 -0
- package/dist/index.js +99 -119
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +98 -120
- package/dist/react.esm.js.map +1 -1
- package/package.json +3 -3
|
@@ -14,6 +14,7 @@ export * from './formatElementValue';
|
|
|
14
14
|
export * from './getAttributeByName';
|
|
15
15
|
export * from './getAttributesConfiguration';
|
|
16
16
|
export * from './getAttributeValue';
|
|
17
|
+
export * from './getChartAxes';
|
|
17
18
|
export * from './getChartFilterName';
|
|
18
19
|
export * from './getChartMarkers';
|
|
19
20
|
export * from './getConfigFilter';
|
|
@@ -44,6 +45,7 @@ export * from './getSlideshowImages';
|
|
|
44
45
|
export * from './getSvgUrl';
|
|
45
46
|
export * from './getTotalFromAttributes';
|
|
46
47
|
export * from './getTotalFromRelatedFeatures';
|
|
48
|
+
export * from './getRootElementId';
|
|
47
49
|
export * from './isEmptyElementValue';
|
|
48
50
|
export * from './isEmptyValue';
|
|
49
51
|
export * from './isHiddenEmptyValue';
|
package/dist/index.js
CHANGED
|
@@ -14,10 +14,10 @@ var enUS = require('date-fns/locale/en-US');
|
|
|
14
14
|
var lodash = require('lodash');
|
|
15
15
|
var signalr = require('@microsoft/signalr');
|
|
16
16
|
var findAnd = require('find-and');
|
|
17
|
-
var MapboxDraw = require('@mapbox/mapbox-gl-draw');
|
|
18
|
-
var turf = require('@turf/turf');
|
|
19
17
|
var jspdf = require('jspdf');
|
|
20
18
|
var html2canvas = require('html2canvas');
|
|
19
|
+
var MapboxDraw = require('@mapbox/mapbox-gl-draw');
|
|
20
|
+
var turf = require('@turf/turf');
|
|
21
21
|
var MapGL = require('react-map-gl/mapbox');
|
|
22
22
|
require('@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css');
|
|
23
23
|
require('mapbox-gl/dist/mapbox-gl.css');
|
|
@@ -5414,6 +5414,8 @@ const getAttributeValue = (element, attributes) => {
|
|
|
5414
5414
|
return maxLength && maxLength < value.length ? (jsxRuntime.jsx(TextTrim, { maxLength: maxLength, expandable: expandable, lineBreak: lineBreak, children: value })) : (value);
|
|
5415
5415
|
};
|
|
5416
5416
|
|
|
5417
|
+
const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
|
|
5418
|
+
|
|
5417
5419
|
const getChartFilterName = (relatedDataSources) => {
|
|
5418
5420
|
const relatedAttributes = relatedDataSources || [];
|
|
5419
5421
|
const axes = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y");
|
|
@@ -6007,7 +6009,7 @@ const PagesContainer = React.memo(({ type = exports.WidgetType.Dashboard, noBord
|
|
|
6007
6009
|
setSelectedTabId,
|
|
6008
6010
|
type,
|
|
6009
6011
|
]);
|
|
6010
|
-
return (jsxRuntime.
|
|
6012
|
+
return (jsxRuntime.jsx(Container, { id: getRootElementId(type), style: { width }, isMain: true, isColumn: isColumn, noBorders: noBorders, children: jsxRuntime.jsx(ContainerChildren, { items: filteredChildren, isMain: true, renderElement: renderElement }) }));
|
|
6011
6013
|
});
|
|
6012
6014
|
|
|
6013
6015
|
const TwoColumnsInnerContainer = React.memo(({ renderElement }) => {
|
|
@@ -6575,10 +6577,12 @@ const LayersContainer = React.memo(({ type, elementConfig, renderElement }) => {
|
|
|
6575
6577
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && (jsxRuntime.jsx(LayersContainerWrapper, { style: style, children: jsxRuntime.jsx(LayerTree, { layers: layers, onlyMainTools: true }) }))] }));
|
|
6576
6578
|
});
|
|
6577
6579
|
|
|
6578
|
-
const ExportPdfContainer = React.memo(({ elementConfig }) => {
|
|
6579
|
-
const {
|
|
6580
|
-
const {
|
|
6581
|
-
|
|
6580
|
+
const ExportPdfContainer = React.memo(({ type, elementConfig }) => {
|
|
6581
|
+
const { t } = useGlobalContext();
|
|
6582
|
+
const { loading, onExport } = useExportPdf(getRootElementId(type));
|
|
6583
|
+
const { style, options } = elementConfig || {};
|
|
6584
|
+
const { icon, title } = options || {};
|
|
6585
|
+
return (jsxRuntime.jsx(Container, { children: jsxRuntime.jsx(uilibGl.IconButton, { kind: icon || "download", primary: true, disabled: loading, style: style, onClick: onExport, children: title ?? t("downloadPdf", { ns: "dashboard", defaultValue: "Скачать PDF" }) }) }));
|
|
6582
6586
|
});
|
|
6583
6587
|
|
|
6584
6588
|
const containerComponents = {
|
|
@@ -7430,8 +7434,6 @@ const ElementImage = React.memo(({ type, elementConfig }) => {
|
|
|
7430
7434
|
return firstImage ? jsxRuntime.jsx("img", { src: firstImage, alt: firstImage, width: width }) : null;
|
|
7431
7435
|
});
|
|
7432
7436
|
|
|
7433
|
-
const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
|
|
7434
|
-
|
|
7435
7437
|
const ElementLegend = React.memo(({ type, element, elementConfig, expandedContainers }) => {
|
|
7436
7438
|
const { attributes, dataSources } = useWidgetContext(type);
|
|
7437
7439
|
const { options } = elementConfig || {};
|
|
@@ -8642,6 +8644,8 @@ const getTotalFromRelatedFeatures = (data) => {
|
|
|
8642
8644
|
return data?.reduce((result, { value }) => result + Number(value), 0)?.toFixed(0) || "";
|
|
8643
8645
|
};
|
|
8644
8646
|
|
|
8647
|
+
const getRootElementId = (type = exports.WidgetType.Dashboard) => `${type}-root`;
|
|
8648
|
+
|
|
8645
8649
|
const pieChartTooltipFromAttributes = (t, data, attributes) => {
|
|
8646
8650
|
const attribute = attributes?.find(({ name }) => name === data[0].name);
|
|
8647
8651
|
const renderValue = attribute
|
|
@@ -9096,125 +9100,99 @@ const useExpandableContainers = () => {
|
|
|
9096
9100
|
return [expandedContainers, expandContainer];
|
|
9097
9101
|
};
|
|
9098
9102
|
|
|
9099
|
-
const useExportPdf = (
|
|
9103
|
+
const useExportPdf = (id, margin = 20) => {
|
|
9100
9104
|
const [loading, setLoading] = React.useState(false);
|
|
9101
9105
|
const onExport = React.useCallback(async () => {
|
|
9102
|
-
if (
|
|
9106
|
+
if (!id) {
|
|
9103
9107
|
return;
|
|
9104
9108
|
}
|
|
9105
9109
|
setLoading(true);
|
|
9106
|
-
const
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
}
|
|
9162
|
-
|
|
9163
|
-
if ((textarea as HTMLTextAreaElement).classList.contains("report-page-front-cover-comment")) {
|
|
9164
|
-
(div as HTMLDivElement).style.fontSize = "16px";
|
|
9165
|
-
(div as HTMLDivElement).style.fontWeight = "400";
|
|
9166
|
-
(div as HTMLDivElement).style.opacity = "0.54";
|
|
9167
|
-
(div as HTMLDivElement).style.lineHeight = "normal";
|
|
9168
|
-
}
|
|
9169
|
-
}
|
|
9170
|
-
|
|
9171
|
-
div.innerText = (textarea as HTMLTextAreaElement).value;
|
|
9172
|
-
|
|
9173
|
-
textarea.replaceWith(div);
|
|
9174
|
-
});
|
|
9175
|
-
|
|
9176
|
-
datePickerWrappers.forEach((inputWrapper) => {
|
|
9177
|
-
const input = inputWrapper.querySelector("input");
|
|
9178
|
-
const div = document.createElement("div");
|
|
9179
|
-
|
|
9180
|
-
if (isCoverPage) {
|
|
9181
|
-
(div as HTMLDivElement).style.fontSize = "12px";
|
|
9182
|
-
(div as HTMLDivElement).style.fontWeight = "400";
|
|
9183
|
-
(div as HTMLDivElement).style.opacity = "0.54";
|
|
9184
|
-
}
|
|
9185
|
-
|
|
9186
|
-
div.innerText = (input as HTMLInputElement).value;
|
|
9187
|
-
|
|
9188
|
-
inputWrapper.replaceWith(div);
|
|
9189
|
-
});
|
|
9190
|
-
|
|
9191
|
-
pageBlockContainers.forEach((element) => {
|
|
9192
|
-
(element as HTMLDivElement).style.background = "#ffffff";
|
|
9193
|
-
});
|
|
9194
|
-
|
|
9195
|
-
pageItemTitles.forEach((item) => {
|
|
9196
|
-
if (isCoverPage) {
|
|
9197
|
-
(item as HTMLDivElement).style.display = "none";
|
|
9198
|
-
} else {
|
|
9199
|
-
(item as HTMLDivElement).style.fontSize = "40px";
|
|
9200
|
-
(item as HTMLDivElement).style.fontWeight = "300";
|
|
9201
|
-
(item as HTMLDivElement).style.marginBottom = "2rem";
|
|
9202
|
-
}
|
|
9203
|
-
});*/
|
|
9204
|
-
},
|
|
9110
|
+
const container = document.querySelector(`#${id}`);
|
|
9111
|
+
if (!container) {
|
|
9112
|
+
setLoading(false);
|
|
9113
|
+
return;
|
|
9114
|
+
}
|
|
9115
|
+
// Сохраняем оригинальные стили для восстановления
|
|
9116
|
+
const originalStyles = {
|
|
9117
|
+
overflow: container.style.overflow,
|
|
9118
|
+
position: container.style.position,
|
|
9119
|
+
};
|
|
9120
|
+
// Временные стили для точного измерения
|
|
9121
|
+
container.style.overflow = 'visible';
|
|
9122
|
+
container.style.position = 'relative';
|
|
9123
|
+
const pdf = new jspdf.jsPDF("p", "px", "a4", false);
|
|
9124
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
|
9125
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
9126
|
+
const availableHeight = pageHeight - (2 * margin);
|
|
9127
|
+
// Получаем все дочерние элементы
|
|
9128
|
+
const children = Array.from(container.children);
|
|
9129
|
+
let currentPageHeight = 0;
|
|
9130
|
+
let currentPageElements = [];
|
|
9131
|
+
const pages = [];
|
|
9132
|
+
// Распределяем элементы по страницам
|
|
9133
|
+
for (const child of children) {
|
|
9134
|
+
const childHeight = child.offsetHeight;
|
|
9135
|
+
// Если элемент не помещается на текущей странице, начинаем новую
|
|
9136
|
+
if (currentPageHeight + childHeight > availableHeight && currentPageElements.length > 0) {
|
|
9137
|
+
pages.push([...currentPageElements]);
|
|
9138
|
+
currentPageElements = [];
|
|
9139
|
+
currentPageHeight = 0;
|
|
9140
|
+
}
|
|
9141
|
+
currentPageElements.push(child);
|
|
9142
|
+
currentPageHeight += childHeight;
|
|
9143
|
+
}
|
|
9144
|
+
// Добавляем последнюю страницу
|
|
9145
|
+
if (currentPageElements.length > 0) {
|
|
9146
|
+
pages.push(currentPageElements);
|
|
9147
|
+
}
|
|
9148
|
+
// Генерируем PDF для каждой страницы
|
|
9149
|
+
for (let pageIndex = 0; pageIndex < pages.length; pageIndex++) {
|
|
9150
|
+
if (pageIndex > 0) {
|
|
9151
|
+
pdf.addPage();
|
|
9152
|
+
}
|
|
9153
|
+
const pageElements = pages[pageIndex];
|
|
9154
|
+
// Создаем временный контейнер для текущей страницы
|
|
9155
|
+
const tempContainer = document.createElement('div');
|
|
9156
|
+
tempContainer.style.position = 'absolute';
|
|
9157
|
+
tempContainer.style.left = '-9999px';
|
|
9158
|
+
tempContainer.style.top = '0';
|
|
9159
|
+
tempContainer.style.width = container.offsetWidth + 'px';
|
|
9160
|
+
tempContainer.style.overflow = 'visible';
|
|
9161
|
+
// Клонируем элементы для текущей страницы
|
|
9162
|
+
pageElements.forEach(element => {
|
|
9163
|
+
const clone = element.cloneNode(true);
|
|
9164
|
+
tempContainer.appendChild(clone);
|
|
9205
9165
|
});
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9166
|
+
document.body.appendChild(tempContainer);
|
|
9167
|
+
try {
|
|
9168
|
+
const canvas = await html2canvas(tempContainer, {
|
|
9169
|
+
scale: 2,
|
|
9170
|
+
useCORS: true,
|
|
9171
|
+
logging: false,
|
|
9172
|
+
backgroundColor: '#ffffff',
|
|
9173
|
+
width: container.offsetWidth,
|
|
9174
|
+
height: tempContainer.offsetHeight,
|
|
9175
|
+
});
|
|
9176
|
+
const imgData = canvas.toDataURL('image/png', 1.0);
|
|
9177
|
+
const imgWidth = pageWidth - (2 * margin);
|
|
9178
|
+
const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
|
9179
|
+
// Центрируем по горизонтали и добавляем с верхним отступом
|
|
9180
|
+
pdf.addImage(imgData, 'PNG', margin, margin, imgWidth, imgHeight);
|
|
9181
|
+
}
|
|
9182
|
+
catch (error) {
|
|
9183
|
+
console.error('Error generating page:', error);
|
|
9184
|
+
}
|
|
9185
|
+
finally {
|
|
9186
|
+
// Удаляем временный контейнер
|
|
9187
|
+
document.body.removeChild(tempContainer);
|
|
9212
9188
|
}
|
|
9213
|
-
pdf.addImage(img, "PNG", 0, 0, pdfWidth, pdfHeight);
|
|
9214
9189
|
}
|
|
9215
|
-
|
|
9190
|
+
// Восстанавливаем оригинальные стили
|
|
9191
|
+
container.style.overflow = originalStyles.overflow;
|
|
9192
|
+
container.style.position = originalStyles.position;
|
|
9193
|
+
pdf.save(`${dateFns.format(new Date(), "yyyy-MM-dd_HH:mm:ss")}.pdf`);
|
|
9216
9194
|
setLoading(false);
|
|
9217
|
-
}, [
|
|
9195
|
+
}, [id, margin]);
|
|
9218
9196
|
return { loading, onExport };
|
|
9219
9197
|
};
|
|
9220
9198
|
|
|
@@ -10274,6 +10252,7 @@ exports.getActualExtrusionHeight = getActualExtrusionHeight;
|
|
|
10274
10252
|
exports.getAttributeByName = getAttributeByName;
|
|
10275
10253
|
exports.getAttributeValue = getAttributeValue;
|
|
10276
10254
|
exports.getAttributesConfiguration = getAttributesConfiguration;
|
|
10255
|
+
exports.getChartAxes = getChartAxes;
|
|
10277
10256
|
exports.getChartFilterName = getChartFilterName;
|
|
10278
10257
|
exports.getChartMarkers = getChartMarkers;
|
|
10279
10258
|
exports.getConfigFilter = getConfigFilter;
|
|
@@ -10302,6 +10281,7 @@ exports.getProxyService = getProxyService;
|
|
|
10302
10281
|
exports.getRelatedAttribute = getRelatedAttribute;
|
|
10303
10282
|
exports.getRenderElement = getRenderElement;
|
|
10304
10283
|
exports.getResourceUrl = getResourceUrl;
|
|
10284
|
+
exports.getRootElementId = getRootElementId;
|
|
10305
10285
|
exports.getSelectedFilterValue = getSelectedFilterValue;
|
|
10306
10286
|
exports.getSlideshowImages = getSlideshowImages;
|
|
10307
10287
|
exports.getSvgUrl = getSvgUrl;
|