@sima-land/moleculas 15.5.0 → 15.6.0

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.
@@ -1,7 +1,10 @@
1
- import React from 'react';
1
+ import React, { AnchorHTMLAttributes } from 'react';
2
2
  import { InteractiveImageProps, InteractiveImageImageProps, InteractiveImagePointProps } from './types';
3
3
  export declare const InteractiveImage: React.ForwardRefExoticComponent<InteractiveImageProps & React.RefAttributes<HTMLDivElement>>;
4
+ declare function ImageAnchor({ children, className, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement>): JSX.Element;
4
5
  export declare const Parts: {
6
+ readonly ImageAnchor: typeof ImageAnchor;
5
7
  readonly Image: React.ForwardRefExoticComponent<InteractiveImageImageProps & React.RefAttributes<HTMLImageElement>>;
6
8
  readonly Point: React.ForwardRefExoticComponent<InteractiveImagePointProps & React.RefAttributes<HTMLAnchorElement>>;
7
9
  };
10
+ export {};
@@ -43,8 +43,25 @@ exports.InteractiveImage = (0, react_1.forwardRef)((_a, ref) => {
43
43
  const rootClassName = cx('root', {
44
44
  'dot-size-unset': dotSize === 'unset',
45
45
  }, className);
46
- return (react_1.default.createElement("div", Object.assign({ ref: ref, className: rootClassName }, rest, { "data-testid": testId }), react_1.Children.toArray(children).filter(child => (0, react_1.isValidElement)(child) && (child.type === Image || child.type === Point))));
46
+ validateChildren(children);
47
+ return (react_1.default.createElement("div", Object.assign({ ref: ref, className: rootClassName }, rest, { "data-testid": testId }), react_1.Children.toArray(children).filter(child => (0, react_1.isValidElement)(child) &&
48
+ (child.type === ImageAnchor || child.type === Image || child.type === Point))));
47
49
  });
50
+ function validateChildren(children) {
51
+ let counter = 0;
52
+ for (const child of react_1.Children.toArray(children)) {
53
+ if ((0, react_1.isValidElement)(child) && (child.type === ImageAnchor || child.type === Image)) {
54
+ counter++;
55
+ }
56
+ if (counter > 1) {
57
+ throw new Error('[InteractiveImage] Either Image or ImageAnchor allowed. Not both.');
58
+ }
59
+ }
60
+ }
61
+ function ImageAnchor(_a) {
62
+ var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
63
+ return (react_1.default.createElement("a", Object.assign({}, rest, { className: cx('image-anchor', className), "data-testid": 'interactive-image:image-anchor' }), react_1.Children.toArray(children).filter(child => (0, react_1.isValidElement)(child) && child.type === Image)));
64
+ }
48
65
  const Image = (0, react_1.forwardRef)((_a, ref) => {
49
66
  var { className, 'data-testid': testId = 'interactive-image:image' } = _a, rest = __rest(_a, ["className", 'data-testid']);
50
67
  return (react_1.default.createElement("img", Object.assign({ ref: ref, className: cx('image', className), "data-testid": testId }, rest)));
@@ -53,4 +70,4 @@ const Point = (0, react_1.forwardRef)((_a, ref) => {
53
70
  var { x, y, className, style, 'data-testid': testId = 'interactive-image:point' } = _a, rest = __rest(_a, ["x", "y", "className", "style", 'data-testid']);
54
71
  return (react_1.default.createElement("a", Object.assign({ ref: ref, "aria-label": '\u0422\u043E\u0447\u043A\u0430 \u043D\u0430 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0438', "data-testid": testId, className: cx('point', className), style: Object.assign(Object.assign({}, style), { top: `${y}%`, left: `${x}%` }) }, rest)));
55
72
  });
56
- exports.Parts = { Image, Point };
73
+ exports.Parts = { ImageAnchor, Image, Point };
@@ -13,6 +13,7 @@
13
13
  }
14
14
  }
15
15
 
16
+ .image-anchor,
16
17
  .image {
17
18
  display: block;
18
19
  max-width: 100%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sima-land/moleculas",
3
- "version": "15.5.0",
3
+ "version": "15.6.0",
4
4
  "repository": "ssh://git@github.com:sima-land/moleculas.git",
5
5
  "author": "www.sima-land.ru team",
6
6
  "license": "Apache-2.0",
@@ -9,7 +9,6 @@
9
9
  "node": ">=14.16.0"
10
10
  },
11
11
  "scripts": {
12
- "prepare": "",
13
12
  "build:before": "rimraf build",
14
13
  "build:main": "tsc --project tsconfig.build.json",
15
14
  "build:after": "node .build/dist.js",