@evergis/react 4.0.154 → 4.0.155

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
@@ -5822,13 +5822,14 @@ const GRID_TILE_SIZE = "4.5rem";
5822
5822
  const LIST_ICON_SIZE = "1.5rem";
5823
5823
  const JPG_MIME_TYPE = "image/jpeg";
5824
5824
  const PNG_MIME_TYPE = "image/png";
5825
+ const SVG_MIME_TYPE = "image/svg+xml";
5825
5826
  const IMAGE_MIME_TYPES = [
5826
5827
  "image/apng",
5827
5828
  "image/avif",
5828
5829
  "image/gif",
5829
5830
  "image/jpeg",
5830
5831
  "image/png",
5831
- "image/svg+xml",
5832
+ SVG_MIME_TYPE,
5832
5833
  "image/webp",
5833
5834
  ];
5834
5835
  const XLSX_MIME_TYPES = [
@@ -9552,7 +9553,10 @@ const ChartContainer = memo(({ elementConfig, isVisible, type, renderElement })
9552
9553
  const chartElement = children.find(child => child.id === "chart");
9553
9554
  const legendElement = children.find(child => child.id === "legend");
9554
9555
  const isLineChart = chartElement?.options?.chartType === "line";
9555
- const xAxisTitle = chartElement?.options?.axis?.x?.title;
9556
+ // Подпись оси X — часть макета осей линейного графика, как и подписи осей Y в `Chart`. У других типов
9557
+ // её нет, даже если она осталась в конфиге после смены типа: редактор показывает настройки осей только
9558
+ // линейному графику, и убрать там такую подпись было бы нечем.
9559
+ const xAxisTitle = useMemo(() => (isLineChart ? chartElement?.options?.axis?.x?.title : undefined), [isLineChart, chartElement?.options?.axis?.x?.title]);
9556
9560
  const footerJustify = useMemo(() => CHART_AXIS_ALIGN_JUSTIFY[chartElement?.options?.axis?.x?.align ?? "center"], [chartElement?.options?.axis?.x?.align]);
9557
9561
  // Легенда встаёт в строку с подписью оси X только когда та есть и легенда не вынесена вбок.
9558
9562
  const isLegendInline = useMemo(() => !!legendInline && !twoColumns && !!xAxisTitle, [legendInline, twoColumns, xAxisTitle]);
@@ -9583,7 +9587,7 @@ const ChartContainer = memo(({ elementConfig, isVisible, type, renderElement })
9583
9587
  if (!loading && !hasItems && hideEmpty)
9584
9588
  return null;
9585
9589
  const chartSlot = (jsx(ContainerChart, { "$fill": !!fill, children: jsx(FillContext.Provider, { value: fillContextValue, children: jsx(ChartPlotContext.Provider, { value: plotContextValue, children: renderElement({ id: "chart" }) }) }) }));
9586
- const footer = xAxisTitle ? (jsxs(ChartFooter, { "$align": footerJustify, "$insets": footerInsets, "$offsetTop": isLineChart ? X_AXIS_TITLE_GAP - LINE_CHART_X_LABELS_BLANK : 0, "$awaitingPlot": isAwaitingPlot, children: [jsx(ChartXAxisTitle, { children: xAxisTitle }), isLegendInline && jsx(ContainerLegend, { children: renderElement({ id: "legend" }) })] })) : null;
9590
+ const footer = xAxisTitle ? (jsxs(ChartFooter, { "$align": footerJustify, "$insets": footerInsets, "$offsetTop": X_AXIS_TITLE_GAP - LINE_CHART_X_LABELS_BLANK, "$awaitingPlot": isAwaitingPlot, children: [jsx(ChartXAxisTitle, { children: xAxisTitle }), isLegendInline && jsx(ContainerLegend, { children: renderElement({ id: "legend" }) })] })) : null;
9587
9591
  // Легенда линейного графика: под подписью оси X — через X_AXIS_TITLE_LEGEND_GAP, без подписи — на её
9588
9592
  // месте, вплотную под подписями делений оси X. У остальных графиков — прежняя раскладка общей легенды.
9589
9593
  const legendRow = isLegendInline ? null : (jsx(ChartLegendRow, { justifyContent: legendJustify, "$insets": isPlotLegend ? footerInsets : null, "$gapTop": isPlotLegend ? (xAxisTitle ? X_AXIS_TITLE_LEGEND_GAP : 0) : undefined, "$offsetTop": isPlotLegend && !xAxisTitle ? X_AXIS_TITLE_GAP - LINE_CHART_X_LABELS_BLANK : undefined, "$justify": isPlotLegend ? legendJustify : undefined, "$awaitingPlot": isPlotLegend && isAwaitingPlot, children: renderElement({ id: "legend" }) }));
@@ -11344,6 +11348,13 @@ const StyledSvg = styled(Flex).withConfig({ displayName: "StyledSvg", componentI
11344
11348
  ${({ $fontColor }) => !!$fontColor && StyledSvgColorMixin};
11345
11349
  `;
11346
11350
 
11351
+ const AttachmentIconImg = styled.img.withConfig({ displayName: "AttachmentIconImg", componentId: "sc-1qtgzdf" }) `
11352
+ flex-shrink: 0;
11353
+ width: ${({ $size }) => $size}px;
11354
+ height: ${({ $size }) => $size}px;
11355
+ object-fit: contain;
11356
+ `;
11357
+
11347
11358
  const ContainerIconValue = styled(Flex).withConfig({ displayName: "ContainerIconValue", componentId: "sc-1adlcb4" }) ``;
11348
11359
  /**
11349
11360
  * Обёртка иконки плитки. Собственный styled нужен, чтобы до иконки можно было дотянуться стилями:
@@ -11448,6 +11459,12 @@ const RoundedBackgroundContainerWrapper = styled(Flex).withConfig({ displayName:
11448
11459
  width: ${BIG_ICON_SIZE} !important;
11449
11460
  height: ${BIG_ICON_SIZE} !important;
11450
11461
  }
11462
+
11463
+ /* Растровая иконка из атрибута-вложения: её размер тоже задаёт контейнер. */
11464
+ ${AttachmentIconImg} {
11465
+ width: ${BIG_ICON_SIZE};
11466
+ height: ${BIG_ICON_SIZE};
11467
+ }
11451
11468
  }
11452
11469
  `};
11453
11470
 
@@ -15545,14 +15562,55 @@ const StyledIcon = styled(Icon).withConfig({ displayName: "StyledIcon", componen
15545
15562
  ${({ fontColor }) => !!fontColor && StyledIconFontColorMixin};
15546
15563
  `;
15547
15564
 
15565
+ /** Размер иконки-вложения, px, когда в конфиге не задан `options.fontSize`. */
15566
+ const ATTACHMENT_ICON_DEFAULT_SIZE = 16;
15567
+
15568
+ /**
15569
+ * Иконка из значения атрибута-вложения: первое изображение списка, остальные файлы пропускаются.
15570
+ * Значение приходит JSON-строкой с сервера или массивом после правки — `parseAttachments` понимает оба.
15571
+ * SVG помечается отдельно: его рисуют инлайном, чтобы перекрасить цветом иконки.
15572
+ */
15573
+ const getAttachmentIcon = (value) => {
15574
+ const image = parseAttachments(value).find(({ mimeType, name }) => IMAGE_FILE_TYPES.includes(getFileType(mimeType, name)));
15575
+ if (!image)
15576
+ return null;
15577
+ return {
15578
+ url: getResourceUrl(image.link),
15579
+ name: image.name,
15580
+ isSvg: image.mimeType === SVG_MIME_TYPE,
15581
+ };
15582
+ };
15583
+
15584
+ /**
15585
+ * Иконка из атрибута-вложения. SVG рисуется инлайном и перекрашивается `fontColor`, как у ElementSvg;
15586
+ * растровый файл — картинкой как есть. Изображений среди вложений нет — не рендерится ничего.
15587
+ */
15588
+ const AttachmentIcon = memo(({ value, fontSize, fontColor, style }) => {
15589
+ const icon = useMemo(() => getAttachmentIcon(value), [value]);
15590
+ const size = useMemo(() => Number(fontSize) || ATTACHMENT_ICON_DEFAULT_SIZE, [fontSize]);
15591
+ const rasterUrl = useMemo(() => (icon && !icon.isSvg ? icon.url : null), [icon]);
15592
+ const imageSrc = useFetchImageWithAuth(rasterUrl);
15593
+ if (!icon)
15594
+ return null;
15595
+ if (icon.isSvg) {
15596
+ return jsx(SvgImage, { url: icon.url, width: size, height: size, fontColor: fontColor });
15597
+ }
15598
+ if (!imageSrc)
15599
+ return null;
15600
+ return jsx(AttachmentIconImg, { src: imageSrc, alt: icon.name, style: style, "$size": size });
15601
+ });
15602
+
15548
15603
  const ElementIcon = memo(({ type, elementConfig, ...rest }) => {
15549
15604
  const ctx = useWidgetContext(type);
15550
15605
  const attributes = rest.attributes || ctx.attributes;
15551
15606
  const { value, attributeName, options, style } = elementConfig || {};
15552
15607
  const { fontSize, fontColor } = options || {};
15553
- const iconValue = useMemo(() => attributeName
15554
- ? attributes?.find(item => item.attributeName === attributeName)?.value
15555
- : value, [attributeName, attributes, value]);
15608
+ const attribute = useMemo(() => (attributeName ? getAttributeByName(attributeName, attributes) : undefined), [attributeName, attributes]);
15609
+ const iconValue = useMemo(() => (attributeName ? attribute?.value : value), [attributeName, attribute, value]);
15610
+ // Во вложениях лежит список файлов, а не имя глифа: иконкой становится первое изображение.
15611
+ if (attribute?.subType === StringSubType.Attachments) {
15612
+ return jsx(AttachmentIcon, { value: attribute.value, fontSize: fontSize, fontColor: fontColor, style: style });
15613
+ }
15556
15614
  return (jsx(StyledIcon, { kind: iconValue, fontSize: fontSize, fontColor: fontColor, style: style }));
15557
15615
  });
15558
15616