hart-estate-widget 0.0.37 → 0.0.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.
@@ -47,15 +47,18 @@ const {
47
47
  } = PANOLENS.CONTROLS;
48
48
  const imgExtentions = ['.png', '.PNG', '.jpg', '.JPG'];
49
49
  const pathName = 'Panorama_0_0_';
50
+ const cameraIdBeginning = 'CameraId';
51
+
52
+ const removeExtention = str => imgExtentions.reduce((acc, extention) => {
53
+ return acc.replace(extention, '');
54
+ }, str);
50
55
 
51
56
  const getCameraFromSrc = (json, src) => {
52
57
  var _json$Floors$0$Camera;
53
58
 
54
- const cameraIdIndex = src.indexOf('CameraId');
59
+ const cameraIdIndex = src.indexOf(cameraIdBeginning);
55
60
  if (cameraIdIndex === -1) return null;
56
- const cameraId = imgExtentions.reduce((acc, extention) => {
57
- return acc.replace(extention, '');
58
- }, src.substring(cameraIdIndex));
61
+ const cameraId = removeExtention(src.substring(cameraIdIndex));
59
62
  return ((_json$Floors$0$Camera = json.Floors[0].CameraPoints) === null || _json$Floors$0$Camera === void 0 ? void 0 : _json$Floors$0$Camera.find(_ref => {
60
63
  let {
61
64
  ID
@@ -82,12 +85,15 @@ const getPanoramas = (json, images, setLoadingState) => {
82
85
  if (!json) return images.map((image, index) => createPanorama(image, index, setLoadingState));
83
86
  return json.Floors[0].Units[0].Rooms.reduce((acc, jsonRoom, index) => {
84
87
  const roomImages = images.filter(img => {
85
- const panoramaIdIndex = img.indexOf(pathName);
86
- if (panoramaIdIndex === -1) return false;
87
- const panoramaId = imgExtentions.reduce((acc, extention) => {
88
- return acc.replace(extention, '');
89
- }, img.substring(panoramaIdIndex + pathName.length));
90
- return Number(panoramaId) === index;
88
+ const panoramaIdIndex = img.indexOf(pathName) + pathName.length;
89
+ if (panoramaIdIndex < pathName.length) return false;
90
+ const indexAsString = String(index);
91
+ const panoramaId = String(removeExtention(img.substring(panoramaIdIndex)));
92
+ const maxIndexLength = Math.max(indexAsString.length, panoramaId.length);
93
+ const imageInRoom = (0, _panoramaHelpers.getArrayFromNumber)(maxIndexLength).every(i => {
94
+ return panoramaId[i] === indexAsString[i];
95
+ });
96
+ return imageInRoom;
91
97
  });
92
98
  if (!roomImages.length) return acc;
93
99
  roomImages.forEach(image => {
@@ -59,9 +59,10 @@ class Store {
59
59
  json,
60
60
  panoramaImages
61
61
  } = this.config;
62
+ if (!json) return panoramaImages[0] || null;
62
63
  const roomIndex = json.Floors[0].Units[0].Rooms.findIndex(room => room.ID === this.hallRoomId);
63
64
  const image = panoramaImages.find(url => url.includes("".concat(roomIndex, ".png")));
64
- return image || panoramaImages[0];
65
+ return image || panoramaImages[0] || null;
65
66
  }
66
67
 
67
68
  setConfig(config) {
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
6
+ exports.getScale = exports.getRoomCoordinates = exports.getArrayFromNumber = exports.findWallVertices = void 0;
7
+
8
+ require("core-js/modules/web.dom-collections.iterator.js");
7
9
 
8
10
  require("core-js/modules/es.array.reduce.js");
9
11
 
@@ -11,6 +13,10 @@ var _react = _interopRequireDefault(require("react"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
16
+ const getArrayFromNumber = num => [...Array(num).keys()];
17
+
18
+ exports.getArrayFromNumber = getArrayFromNumber;
19
+
14
20
  const findWallVertices = (walls, wall, vertices) => {
15
21
  const currentWall = walls.find(el => el.ID === wall);
16
22
  return currentWall.Vertices.map(vertexId => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "HART Estate widget",
4
4
  "author": "HART",
5
5
  "keywords": [],
6
- "version": "0.0.37",
6
+ "version": "0.0.40",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",