@evergis/react 3.1.38 → 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/react.esm.js CHANGED
@@ -12,6 +12,8 @@ import { enUS } from 'date-fns/locale/en-US';
12
12
  import { uniqueId, isNil, isEmpty, isEqual, unescape } from 'lodash';
13
13
  import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
14
14
  import { changeProps, returnFound } from 'find-and';
15
+ import { jsPDF } from 'jspdf';
16
+ import html2canvas from 'html2canvas';
15
17
  import MapboxDraw from '@mapbox/mapbox-gl-draw';
16
18
  import { geometryCollection, multiPolygon, polygon, multiLineString, multiPoint, point as point$1, bbox } from '@turf/turf';
17
19
  import MapGL, { Source, Layer as Layer$1 } from 'react-map-gl/mapbox';
@@ -3375,6 +3377,7 @@ var ContainerTemplate;
3375
3377
  ContainerTemplate["Camera"] = "Camera";
3376
3378
  ContainerTemplate["AddFeature"] = "AddFeature";
3377
3379
  ContainerTemplate["Slideshow"] = "Slideshow";
3380
+ ContainerTemplate["ExportPdf"] = "ExportPdf";
3378
3381
  ContainerTemplate["Divider"] = "Divider";
3379
3382
  })(ContainerTemplate || (ContainerTemplate = {}));
3380
3383
  var HeaderTemplate;
@@ -5409,6 +5412,8 @@ const getAttributeValue = (element, attributes) => {
5409
5412
  return maxLength && maxLength < value.length ? (jsx(TextTrim, { maxLength: maxLength, expandable: expandable, lineBreak: lineBreak, children: value })) : (value);
5410
5413
  };
5411
5414
 
5415
+ const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
5416
+
5412
5417
  const getChartFilterName = (relatedDataSources) => {
5413
5418
  const relatedAttributes = relatedDataSources || [];
5414
5419
  const axes = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y");
@@ -6002,7 +6007,7 @@ const PagesContainer = memo(({ type = WidgetType.Dashboard, noBorders }) => {
6002
6007
  setSelectedTabId,
6003
6008
  type,
6004
6009
  ]);
6005
- return (jsxs("div", { style: { width }, children: [jsx(ExpandableTitle, { elementConfig: config, type: type, renderElement: renderElement }), jsx(Container, { isColumn: isColumn, isMain: true, noBorders: noBorders, children: jsx(ContainerChildren, { items: filteredChildren, isMain: true, renderElement: renderElement }) })] }));
6010
+ return (jsx(Container, { id: getRootElementId(type), style: { width }, isMain: true, isColumn: isColumn, noBorders: noBorders, children: jsx(ContainerChildren, { items: filteredChildren, isMain: true, renderElement: renderElement }) }));
6006
6011
  });
6007
6012
 
6008
6013
  const TwoColumnsInnerContainer = memo(({ renderElement }) => {
@@ -6570,6 +6575,14 @@ const LayersContainer = memo(({ type, elementConfig, renderElement }) => {
6570
6575
  return (jsxs(Fragment$1, { children: [jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && (jsx(LayersContainerWrapper, { style: style, children: jsx(LayerTree, { layers: layers, onlyMainTools: true }) }))] }));
6571
6576
  });
6572
6577
 
6578
+ const ExportPdfContainer = memo(({ type, elementConfig }) => {
6579
+ const { t } = useGlobalContext();
6580
+ const { loading, onExport } = useExportPdf(getRootElementId(type));
6581
+ const { style, options } = elementConfig || {};
6582
+ const { icon, title } = options || {};
6583
+ return (jsx(Container, { children: jsx(IconButton, { kind: icon || "download", primary: true, disabled: loading, style: style, onClick: onExport, children: title ?? t("downloadPdf", { ns: "dashboard", defaultValue: "Скачать PDF" }) }) }));
6584
+ });
6585
+
6573
6586
  const containerComponents = {
6574
6587
  [ContainerTemplate.DefaultAttributes]: DefaultAttributesContainer,
6575
6588
  [ContainerTemplate.Pages]: PagesContainer,
@@ -6591,6 +6604,7 @@ const containerComponents = {
6591
6604
  [ContainerTemplate.Camera]: CameraContainer,
6592
6605
  [ContainerTemplate.AddFeature]: AddFeatureContainer,
6593
6606
  [ContainerTemplate.Divider]: DividerContainer,
6607
+ [ContainerTemplate.ExportPdf]: ExportPdfContainer,
6594
6608
  default: ContainersGroupContainer,
6595
6609
  };
6596
6610
 
@@ -7418,8 +7432,6 @@ const ElementImage = memo(({ type, elementConfig }) => {
7418
7432
  return firstImage ? jsx("img", { src: firstImage, alt: firstImage, width: width }) : null;
7419
7433
  });
7420
7434
 
7421
- const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
7422
-
7423
7435
  const ElementLegend = memo(({ type, element, elementConfig, expandedContainers }) => {
7424
7436
  const { attributes, dataSources } = useWidgetContext(type);
7425
7437
  const { options } = elementConfig || {};
@@ -8630,6 +8642,8 @@ const getTotalFromRelatedFeatures = (data) => {
8630
8642
  return data?.reduce((result, { value }) => result + Number(value), 0)?.toFixed(0) || "";
8631
8643
  };
8632
8644
 
8645
+ const getRootElementId = (type = WidgetType.Dashboard) => `${type}-root`;
8646
+
8633
8647
  const pieChartTooltipFromAttributes = (t, data, attributes) => {
8634
8648
  const attribute = attributes?.find(({ name }) => name === data[0].name);
8635
8649
  const renderValue = attribute
@@ -9084,6 +9098,102 @@ const useExpandableContainers = () => {
9084
9098
  return [expandedContainers, expandContainer];
9085
9099
  };
9086
9100
 
9101
+ const useExportPdf = (id, margin = 20) => {
9102
+ const [loading, setLoading] = useState(false);
9103
+ const onExport = useCallback(async () => {
9104
+ if (!id) {
9105
+ return;
9106
+ }
9107
+ setLoading(true);
9108
+ const container = document.querySelector(`#${id}`);
9109
+ if (!container) {
9110
+ setLoading(false);
9111
+ return;
9112
+ }
9113
+ // Сохраняем оригинальные стили для восстановления
9114
+ const originalStyles = {
9115
+ overflow: container.style.overflow,
9116
+ position: container.style.position,
9117
+ };
9118
+ // Временные стили для точного измерения
9119
+ container.style.overflow = 'visible';
9120
+ container.style.position = 'relative';
9121
+ const pdf = new jsPDF("p", "px", "a4", false);
9122
+ const pageWidth = pdf.internal.pageSize.getWidth();
9123
+ const pageHeight = pdf.internal.pageSize.getHeight();
9124
+ const availableHeight = pageHeight - (2 * margin);
9125
+ // Получаем все дочерние элементы
9126
+ const children = Array.from(container.children);
9127
+ let currentPageHeight = 0;
9128
+ let currentPageElements = [];
9129
+ const pages = [];
9130
+ // Распределяем элементы по страницам
9131
+ for (const child of children) {
9132
+ const childHeight = child.offsetHeight;
9133
+ // Если элемент не помещается на текущей странице, начинаем новую
9134
+ if (currentPageHeight + childHeight > availableHeight && currentPageElements.length > 0) {
9135
+ pages.push([...currentPageElements]);
9136
+ currentPageElements = [];
9137
+ currentPageHeight = 0;
9138
+ }
9139
+ currentPageElements.push(child);
9140
+ currentPageHeight += childHeight;
9141
+ }
9142
+ // Добавляем последнюю страницу
9143
+ if (currentPageElements.length > 0) {
9144
+ pages.push(currentPageElements);
9145
+ }
9146
+ // Генерируем PDF для каждой страницы
9147
+ for (let pageIndex = 0; pageIndex < pages.length; pageIndex++) {
9148
+ if (pageIndex > 0) {
9149
+ pdf.addPage();
9150
+ }
9151
+ const pageElements = pages[pageIndex];
9152
+ // Создаем временный контейнер для текущей страницы
9153
+ const tempContainer = document.createElement('div');
9154
+ tempContainer.style.position = 'absolute';
9155
+ tempContainer.style.left = '-9999px';
9156
+ tempContainer.style.top = '0';
9157
+ tempContainer.style.width = container.offsetWidth + 'px';
9158
+ tempContainer.style.overflow = 'visible';
9159
+ // Клонируем элементы для текущей страницы
9160
+ pageElements.forEach(element => {
9161
+ const clone = element.cloneNode(true);
9162
+ tempContainer.appendChild(clone);
9163
+ });
9164
+ document.body.appendChild(tempContainer);
9165
+ try {
9166
+ const canvas = await html2canvas(tempContainer, {
9167
+ scale: 2,
9168
+ useCORS: true,
9169
+ logging: false,
9170
+ backgroundColor: '#ffffff',
9171
+ width: container.offsetWidth,
9172
+ height: tempContainer.offsetHeight,
9173
+ });
9174
+ const imgData = canvas.toDataURL('image/png', 1.0);
9175
+ const imgWidth = pageWidth - (2 * margin);
9176
+ const imgHeight = (canvas.height * imgWidth) / canvas.width;
9177
+ // Центрируем по горизонтали и добавляем с верхним отступом
9178
+ pdf.addImage(imgData, 'PNG', margin, margin, imgWidth, imgHeight);
9179
+ }
9180
+ catch (error) {
9181
+ console.error('Error generating page:', error);
9182
+ }
9183
+ finally {
9184
+ // Удаляем временный контейнер
9185
+ document.body.removeChild(tempContainer);
9186
+ }
9187
+ }
9188
+ // Восстанавливаем оригинальные стили
9189
+ container.style.overflow = originalStyles.overflow;
9190
+ container.style.position = originalStyles.position;
9191
+ pdf.save(`${format(new Date(), "yyyy-MM-dd_HH:mm:ss")}.pdf`);
9192
+ setLoading(false);
9193
+ }, [id, margin]);
9194
+ return { loading, onExport };
9195
+ };
9196
+
9087
9197
  const getMinMaxFromStringValue = (items, value, current, type) => {
9088
9198
  const valueIndex = items.findIndex(item => item.value === (type === "min" ? value.min : value.max));
9089
9199
  const currentIndex = items.findIndex(item => item.value === (type === "min" ? value.min : value.max));
@@ -9965,5 +10075,5 @@ const Map$1 = ({ zIndex, lowerSiblings, upperSiblings, onError, children, ...res
9965
10075
  }, children: children }), upperSiblings] }));
9966
10076
  };
9967
10077
 
9968
- export { AddFeatureButton, AddFeatureContainer, AttributeGalleryContainer, AttributeLabel, BaseMapTheme, CONFIG_PAGES_ID, CONFIG_PAGE_ID, CameraContainer, Chart, ChartContainer, ChartLegend, ChartLoading, ContainerChildren, ContainerLoading, ContainerTemplate, ContainerWrapper, ContainersGroupContainer, DEFAULT_ATTRIBUTE_NAME, DEFAULT_BARCHART_RADIUS, DEFAULT_BASE_MAP, DEFAULT_CHART_ANGLE, DEFAULT_CHART_HEIGHT, DEFAULT_CHART_WIDTH, DEFAULT_CIRCLE_PAINT, DEFAULT_DASHBOARD_CONFIG, DEFAULT_DATA_SOURCE_LIMIT, DEFAULT_FILL_EXTRUSION_PAINT, DEFAULT_FILL_PAINT, DEFAULT_ID_ATTRIBUTE_NAME, DEFAULT_LAT, DEFAULT_LINE_PAINT, DEFAULT_LNG, DEFAULT_PAGES_CONFIG, DEFAULT_PIECHART_RADIUS, DEFAULT_ZOOM, Dashboard, DashboardCheckbox, DashboardChip, DashboardContent, DashboardContext, DashboardDefaultHeader, DashboardHeader, DashboardLoading, DashboardPlaceholder, DashboardPlaceholderWrap, DashboardProvider, DashboardWrapper, DataSourceContainer, DataSourceError, DataSourceErrorContainer, DataSourceInnerContainer, DataSourceProgressContainer, DateFormat, DefaultAttributesContainer, DefaultHeaderContainer, DefaultHeaderWrapper, DividerContainer, EditGeometryType, ElementButton, ElementCamera, ElementChart, ElementChips, ElementIcon, ElementImage, ElementLegend, ElementLink, ElementSlideshow, ElementSvg, ElementTooltip, ElementValueWrapper, ExpandableTitle, FEATURE_CARD_DEFAULT_COLORS, FEATURE_CARD_OTHER_COLOR, FILTERED_VALUE_OPACITY, FILTER_PREFIX, FeatureCardButtons, FeatureCardContext, FeatureCardDefaultHeader, FeatureCardGradientHeader, FeatureCardHeader, FeatureCardIconHeader, FeatureCardProvider, FeatureCardSlideshowHeader, FeatureCardTitle, FeatureControls, FeatureTitleContainer, FiltersContainer, GEOMETRY_ATTRIBUTE, GlobalContext, GlobalProvider, Header, HeaderContainer, HeaderFrontView, HeaderTemplate, HeaderTitleContainer, HiddenTitleItems, IconContainer, ImageContainer, LEFT_PANEL_HEADER_HEIGHT, Layer, LayerDescription, LayerGroup, LayerGroupList, LayerIcon, LayerListContainer, LayerTree, LayersContainer, LayersListWrapper, LinearProgressContainer, LogoContainer, MAX_CHART_WIDTH, Map$1 as Map, MapContext, MapProvider, NO_CONTENT_VALUE, NUMERIC_ATTRIBUTE_TYPES, NoLiveSnapshotContainer, OneColumnContainer, PageNavigator, PageTitle, PagesContainer, Pagination, PresentationHeader, PresentationHeaderButtons, PresentationHeaderTools, PresentationPanelContainer, PresentationPanelWrapper, PresentationWrapper, ProgressContainer, RoundedBackgroundContainer, ScalingFactor, ServerNotificationsContext, ServerNotificationsProvider, SlideshowContainer, SmallPreviewContainer$1 as SmallPreviewContainer, SmallPreviewControl, SmallPreviewCounter, SmallPreviewImages, SmallPreviewLeft, SmallPreviewRight, StackBar, SvgImage, TIME_ZONE_FORMAT, TabsContainer, TextTrim, ThemeName, TitleContainer, TmsType, TopContainer, TopContainerButtons, TwoColumnContainer, TwoColumnsInnerContainer, WidgetType, addDataSource, addDataSources, applyFiltersToCondition, applyQueryFilters, applyVarsToCondition, checkEqualOrIncludes, checkIsLoading, convertSpToTurfFeature, createConfigLayer, createConfigPage, createNewPageId, createTreeNode, dateOptions, debounce, decimalOpacityToHex, eqlParametersToPayload, findAttributeInExpression, formatArea, formatAttributeValue, formatChartRelatedValue, formatConditionValue, formatDataSourceCondition, formatDate$1 as formatDate, formatElementValue, formatLength, formatNumber, formatPolygonMeasure, getActualExtrusionHeight, getAttributeByName, getAttributeValue, getAttributesConfiguration, getChartFilterName, getChartMarkers, getConfigFilter, getContainerComponent, getDashboardHeader, getDataFromAttributes, getDataFromRelatedFeatures, getDataSource, getDataSourceFilterValue, getDate, getDefaultConfig, getElementValue, getFeatureAttributes, getFeatureCardHeader, getFilterComponent, getFilterSelectedItems, getFilterValue, getFormattedAttributes, getGradientColors, getLayerDefinition, getLayerInfo, getLayerInfoFromDataSources, getPagesFromConfig, getPagesFromProjectInfo, getProxyService, getRelatedAttribute, getRenderElement, getResourceUrl, getSelectedFilterValue, getSlideshowImages, getSvgUrl, getTotalFromAttributes, getTotalFromRelatedFeatures, hexToRgba, isCompositeLayerConfiguration, isEmptyElementValue, isEmptyValue, isHiddenEmptyValue, isLayerService, isNotValidSelectedTab, isNumeric, isObject, isProxyService, isVisibleContainer, numberOptions, parseClientStyle, pieChartTooltipFromAttributes, pieChartTooltipFromRelatedFeatures, pointOptions, removeDataSource, rgbToHex, roundTotalSum, sliceShownOtherItems, timeOptions, tooltipNameFromAttributes, tooltipValueFromAttributes, tooltipValueFromRelatedFeatures, transparentizeColor, treeNodesToProjectItems, useAppHeight, useChartChange, useChartData, useDashboardHeader, useDataSources, useDebouncedCallback, useDiffPage, useExpandableContainers, useGetConfigLayer, useGlobalContext, useHeaderRender, useLayerParams, useMapContext, useMapDraw, useProjectDashboardInit, useRedrawLayer, useRelatedDataSourceAttributes, useRenderElement, useServerNotificationsContext, useShownOtherItems, useToggle, useUpdateDataSource, useWidgetConfig, useWidgetContext, useWidgetFilters, useWidgetPage, useWindowResize, useZoomToFeatures, useZoomToPoint };
10078
+ export { AddFeatureButton, AddFeatureContainer, AttributeGalleryContainer, AttributeLabel, BaseMapTheme, CONFIG_PAGES_ID, CONFIG_PAGE_ID, CameraContainer, Chart, ChartContainer, ChartLegend, ChartLoading, ContainerChildren, ContainerLoading, ContainerTemplate, ContainerWrapper, ContainersGroupContainer, DEFAULT_ATTRIBUTE_NAME, DEFAULT_BARCHART_RADIUS, DEFAULT_BASE_MAP, DEFAULT_CHART_ANGLE, DEFAULT_CHART_HEIGHT, DEFAULT_CHART_WIDTH, DEFAULT_CIRCLE_PAINT, DEFAULT_DASHBOARD_CONFIG, DEFAULT_DATA_SOURCE_LIMIT, DEFAULT_FILL_EXTRUSION_PAINT, DEFAULT_FILL_PAINT, DEFAULT_ID_ATTRIBUTE_NAME, DEFAULT_LAT, DEFAULT_LINE_PAINT, DEFAULT_LNG, DEFAULT_PAGES_CONFIG, DEFAULT_PIECHART_RADIUS, DEFAULT_ZOOM, Dashboard, DashboardCheckbox, DashboardChip, DashboardContent, DashboardContext, DashboardDefaultHeader, DashboardHeader, DashboardLoading, DashboardPlaceholder, DashboardPlaceholderWrap, DashboardProvider, DashboardWrapper, DataSourceContainer, DataSourceError, DataSourceErrorContainer, DataSourceInnerContainer, DataSourceProgressContainer, DateFormat, DefaultAttributesContainer, DefaultHeaderContainer, DefaultHeaderWrapper, DividerContainer, EditGeometryType, ElementButton, ElementCamera, ElementChart, ElementChips, ElementIcon, ElementImage, ElementLegend, ElementLink, ElementSlideshow, ElementSvg, ElementTooltip, ElementValueWrapper, ExpandableTitle, FEATURE_CARD_DEFAULT_COLORS, FEATURE_CARD_OTHER_COLOR, FILTERED_VALUE_OPACITY, FILTER_PREFIX, FeatureCardButtons, FeatureCardContext, FeatureCardDefaultHeader, FeatureCardGradientHeader, FeatureCardHeader, FeatureCardIconHeader, FeatureCardProvider, FeatureCardSlideshowHeader, FeatureCardTitle, FeatureControls, FeatureTitleContainer, FiltersContainer, GEOMETRY_ATTRIBUTE, GlobalContext, GlobalProvider, Header, HeaderContainer, HeaderFrontView, HeaderTemplate, HeaderTitleContainer, HiddenTitleItems, IconContainer, ImageContainer, LEFT_PANEL_HEADER_HEIGHT, Layer, LayerDescription, LayerGroup, LayerGroupList, LayerIcon, LayerListContainer, LayerTree, LayersContainer, LayersListWrapper, LinearProgressContainer, LogoContainer, MAX_CHART_WIDTH, Map$1 as Map, MapContext, MapProvider, NO_CONTENT_VALUE, NUMERIC_ATTRIBUTE_TYPES, NoLiveSnapshotContainer, OneColumnContainer, PageNavigator, PageTitle, PagesContainer, Pagination, PresentationHeader, PresentationHeaderButtons, PresentationHeaderTools, PresentationPanelContainer, PresentationPanelWrapper, PresentationWrapper, ProgressContainer, RoundedBackgroundContainer, ScalingFactor, ServerNotificationsContext, ServerNotificationsProvider, SlideshowContainer, SmallPreviewContainer$1 as SmallPreviewContainer, SmallPreviewControl, SmallPreviewCounter, SmallPreviewImages, SmallPreviewLeft, SmallPreviewRight, StackBar, SvgImage, TIME_ZONE_FORMAT, TabsContainer, TextTrim, ThemeName, TitleContainer, TmsType, TopContainer, TopContainerButtons, TwoColumnContainer, TwoColumnsInnerContainer, WidgetType, addDataSource, addDataSources, applyFiltersToCondition, applyQueryFilters, applyVarsToCondition, checkEqualOrIncludes, checkIsLoading, convertSpToTurfFeature, createConfigLayer, createConfigPage, createNewPageId, createTreeNode, dateOptions, debounce, decimalOpacityToHex, eqlParametersToPayload, findAttributeInExpression, formatArea, formatAttributeValue, formatChartRelatedValue, formatConditionValue, formatDataSourceCondition, formatDate$1 as formatDate, formatElementValue, formatLength, formatNumber, formatPolygonMeasure, getActualExtrusionHeight, getAttributeByName, getAttributeValue, getAttributesConfiguration, getChartAxes, getChartFilterName, getChartMarkers, getConfigFilter, getContainerComponent, getDashboardHeader, getDataFromAttributes, getDataFromRelatedFeatures, getDataSource, getDataSourceFilterValue, getDate, getDefaultConfig, getElementValue, getFeatureAttributes, getFeatureCardHeader, getFilterComponent, getFilterSelectedItems, getFilterValue, getFormattedAttributes, getGradientColors, getLayerDefinition, getLayerInfo, getLayerInfoFromDataSources, getPagesFromConfig, getPagesFromProjectInfo, getProxyService, getRelatedAttribute, getRenderElement, getResourceUrl, getRootElementId, getSelectedFilterValue, getSlideshowImages, getSvgUrl, getTotalFromAttributes, getTotalFromRelatedFeatures, hexToRgba, isCompositeLayerConfiguration, isEmptyElementValue, isEmptyValue, isHiddenEmptyValue, isLayerService, isNotValidSelectedTab, isNumeric, isObject, isProxyService, isVisibleContainer, numberOptions, parseClientStyle, pieChartTooltipFromAttributes, pieChartTooltipFromRelatedFeatures, pointOptions, removeDataSource, rgbToHex, roundTotalSum, sliceShownOtherItems, timeOptions, tooltipNameFromAttributes, tooltipValueFromAttributes, tooltipValueFromRelatedFeatures, transparentizeColor, treeNodesToProjectItems, useAppHeight, useChartChange, useChartData, useDashboardHeader, useDataSources, useDebouncedCallback, useDiffPage, useExpandableContainers, useExportPdf, useGetConfigLayer, useGlobalContext, useHeaderRender, useLayerParams, useMapContext, useMapDraw, useProjectDashboardInit, useRedrawLayer, useRelatedDataSourceAttributes, useRenderElement, useServerNotificationsContext, useShownOtherItems, useToggle, useUpdateDataSource, useWidgetConfig, useWidgetContext, useWidgetFilters, useWidgetPage, useWindowResize, useZoomToFeatures, useZoomToPoint };
9969
10079
  //# sourceMappingURL=react.esm.js.map