kitchen-simulator 1.0.0-alin.4 → 1.0.0-alin.45

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.
@@ -3,12 +3,15 @@ import React, { useState, useEffect } from 'react';
3
3
  import ContainerDimensions from 'react-container-dimensions';
4
4
  import mockProps from "./mocks/mockProps.json";
5
5
  import mockCategoryData from "./mocks/categoryData.json";
6
- import mockDataBundle from "./mocks/dataBundle.json";
7
- import cabinetPaylod from "./mocks/cabinetPayload.json";
6
+ import mockDataBundle from "./mocks/dataBundle2.json";
7
+ import cabinetPaylod from "./mocks/cabinetPayload2.json";
8
+ import doorStylePaylod from "./mocks/doorStylePayload.json";
9
+ import oStylePaylod from "./mocks/oStylePayload.json";
10
+ import rectangleData from "./mocks/rectangleShape.json";
8
11
  import ReactDOM from 'react-dom';
9
12
  import LiteRenderer from "./LiteRenderer";
10
13
  import { Button } from 'antd';
11
- import { LEFT, RIGHT, TOP, BOTTOM, EXTERNAL_EVENT_ADD_ITEM, EXTERNAL_EVENT_ADD_WALL, EXTERNAL_EVENT_TOGGLE_TO_3D, EXTERNAL_EVENT_TOGGLE_TO_2D, EXTERNAL_EVENT_TOGGLE_TO_ELEVATION, EXTERNAL_EVENT_MOVE_PAN, EXTERNAL_EVENT_NEW_PROJECT } from "./constants";
14
+ import { LEFT, RIGHT, TOP, BOTTOM, EXTERNAL_EVENT_ADD_ITEM, EXTERNAL_EVENT_ADD_WALL, EXTERNAL_EVENT_TOGGLE_TO_3D, EXTERNAL_EVENT_TOGGLE_TO_2D, EXTERNAL_EVENT_TOGGLE_TO_ELEVATION, EXTERNAL_EVENT_MOVE_PAN, EXTERNAL_EVENT_NEW_PROJECT, EXTERNAL_EVENT_CHANGE_DOORSTYLE, EXTERNAL_EVENT_SET_INITIAL_DATA, EXTERNAL_EVENT_ADD_ROOM_SHAPE, EXTERNAL_EVENT_ZOOM_IN, EXTERNAL_EVENT_ZOOM_OUT } from "./constants";
12
15
 
13
16
  // --- renderer props ---
14
17
  var options = {
@@ -22,6 +25,18 @@ function WorkSpace(props) {
22
25
  externalEvent = _useState2[0],
23
26
  setExternalEvent = _useState2[1];
24
27
  var offset = 5;
28
+ useEffect(function () {
29
+ var evt = {
30
+ type: EXTERNAL_EVENT_SET_INITIAL_DATA,
31
+ payload: {
32
+ doorStyle: {
33
+ doorStyle: doorStylePaylod,
34
+ oStyle: oStylePaylod
35
+ }
36
+ }
37
+ };
38
+ setExternalEvent(evt);
39
+ }, []);
25
40
  return /*#__PURE__*/React.createElement("div", {
26
41
  className: "flex gap-4"
27
42
  }, /*#__PURE__*/React.createElement(Button, {
@@ -107,6 +122,28 @@ function WorkSpace(props) {
107
122
  }
108
123
  }, /*#__PURE__*/React.createElement("img", {
109
124
  src: "/assets/img/svg/bottombar/arrow-right.svg"
125
+ })), /*#__PURE__*/React.createElement(Button, {
126
+ actionType: "primary",
127
+ onClick: function onClick() {
128
+ var evt = {
129
+ type: EXTERNAL_EVENT_ZOOM_IN,
130
+ payload: {}
131
+ };
132
+ setExternalEvent(evt);
133
+ }
134
+ }, /*#__PURE__*/React.createElement("img", {
135
+ src: "/assets/img/svg/bottombar/arrow-minus.svg"
136
+ })), /*#__PURE__*/React.createElement(Button, {
137
+ actionType: "primary",
138
+ onClick: function onClick() {
139
+ var evt = {
140
+ type: EXTERNAL_EVENT_ZOOM_OUT,
141
+ payload: {}
142
+ };
143
+ setExternalEvent(evt);
144
+ }
145
+ }, /*#__PURE__*/React.createElement("img", {
146
+ src: "/assets/img/svg/bottombar/arrow-plus.svg"
110
147
  })), /*#__PURE__*/React.createElement(Button, {
111
148
  actionType: "primary",
112
149
  onClick: function onClick() {
@@ -134,9 +171,30 @@ function WorkSpace(props) {
134
171
  };
135
172
  setExternalEvent(evt);
136
173
  }
137
- }, "Add B12 Cabinet"), /*#__PURE__*/React.createElement(LiteRenderer, {
138
- width: 1200,
139
- height: 953,
174
+ }, "Add B12 Cabinet"), /*#__PURE__*/React.createElement(Button, {
175
+ actionType: "danger",
176
+ onClick: function onClick() {
177
+ var evt = {
178
+ type: EXTERNAL_EVENT_CHANGE_DOORSTYLE,
179
+ payload: {
180
+ doorStyle: doorStylePaylod,
181
+ isAll: true
182
+ }
183
+ };
184
+ setExternalEvent(evt);
185
+ }
186
+ }, "DoorStyle (Change into Midtown White Shaker)"), /*#__PURE__*/React.createElement(Button, {
187
+ actionType: "danger",
188
+ onClick: function onClick() {
189
+ var evt = {
190
+ type: EXTERNAL_EVENT_ADD_ROOM_SHAPE,
191
+ payload: rectangleData
192
+ };
193
+ setExternalEvent(evt);
194
+ }
195
+ }, "Add Room shape(rectangle)"), /*#__PURE__*/React.createElement(LiteRenderer, {
196
+ width: props.width,
197
+ height: props.height,
140
198
  projectElement: mockProps.projectElement,
141
199
  categoryData: mockCategoryData,
142
200
  dataBundle: mockDataBundle,
@@ -158,4 +216,11 @@ function WorkSpace(props) {
158
216
  }
159
217
  }));
160
218
  }
161
- ReactDOM.render(/*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(WorkSpace, null)), document.getElementById('app'));
219
+ ReactDOM.render(/*#__PURE__*/React.createElement(ContainerDimensions, null, function (_ref) {
220
+ var width = _ref.width,
221
+ height = _ref.height;
222
+ return /*#__PURE__*/React.createElement(WorkSpace, {
223
+ width: width,
224
+ height: height
225
+ });
226
+ }), document.getElementById('app'));
package/es/index.js CHANGED
@@ -7,19 +7,21 @@ import LiteRenderer from "./LiteRenderer";
7
7
  export function renderKitchenSimulator(container) {
8
8
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9
9
  var currentProps = props;
10
- var render = function render(newProps) {
11
- ReactDOM.render(/*#__PURE__*/React.createElement(LiteRenderer, newProps), container);
12
- };
13
- render(props);
10
+
11
+ // Initial render
12
+ var root = ReactDOM.render(/*#__PURE__*/React.createElement(LiteRenderer, props), container);
14
13
  return {
15
- updateExternalEvent: function updateExternalEvent(externalEvent) {
16
- currentProps = _objectSpread(_objectSpread({}, currentProps), {}, {
17
- externalEvent: externalEvent
18
- });
19
- render(currentProps);
20
- },
21
- unmount: function unmount() {
22
- ReactDOM.unmountComponentAtNode(container);
14
+ root: root,
15
+ updateExternalEvent: function updateExternalEvent(newExternalEvent) {
16
+ var prevEvent = currentProps.externalEvent;
17
+ var isSameEvent = prevEvent && newExternalEvent && prevEvent.type === newExternalEvent.type && JSON.stringify(prevEvent.payload) === JSON.stringify(newExternalEvent.payload);
18
+ if (!isSameEvent) {
19
+ currentProps = _objectSpread(_objectSpread({}, currentProps), {}, {
20
+ externalEvent: newExternalEvent
21
+ });
22
+ ReactDOM.render(/*#__PURE__*/React.createElement(LiteRenderer, currentProps), container);
23
+ }
23
24
  }
24
25
  };
25
- }
26
+ }
27
+ export default renderKitchenSimulator;
@@ -105,7 +105,7 @@ export default function (state, action) {
105
105
  case SELECT_TOOL_DRAWING_ITEM_3D:
106
106
  return Item.selectToolDrawingItem3D(state, action.sceneComponentType).updatedState;
107
107
  case SET_DOOR_STYLE:
108
- return Item.setDoorStyle(state, action.doorStyle, action.pathes, action.isAll).updatedState;
108
+ return Item.setDoorStyle(state, action.doorStyle, action.isAll).updatedState;
109
109
  case SET_HANDLE_MATERIAL:
110
110
  return Item.setHandleMaterial(state, action.material).updatedState;
111
111
  case SET_DOOR_HANDLE:
@@ -873,18 +873,18 @@ export function getAllItemSnap(allItemRects) {
873
873
  var snap4 = itemrectInfo(rect.rect[3].x + ox0, rect.rect[3].y + oy0, nrot, cur && cur.size, rect.layoutpos, rect.is_corner);
874
874
  var sizeinfo = otherItems[index].cat && otherItems[index].cat.info.sizeinfo;
875
875
  if (sizeinfo) {
876
- var leftBlindLength = sizeinfo.leftBlindLength,
877
- rightBlindLength = sizeinfo.rightBlindLength;
878
- if (leftBlindLength > 0) {
879
- var vx = leftBlindLength - ch;
876
+ var left_blind_length = sizeinfo.left_blind_length,
877
+ right_blind_length = sizeinfo.right_blind_length;
878
+ if (left_blind_length > 0) {
879
+ var vx = left_blind_length - ch;
880
880
  var vy = cw;
881
881
  var dx = vx * cos + vy * sin;
882
882
  var dy = vx * sin - vy * cos;
883
883
  var snap6 = itemrectInfo(rect.rect[0].x + dx, rect.rect[0].y + dy, rect.rotRad + Math.PI / 2, cur && cur.size, rect.layoutpos, rect.is_corner);
884
884
  allItemSnap.push(snap6);
885
885
  }
886
- if (rightBlindLength > 0) {
887
- var _vx = ch - rightBlindLength;
886
+ if (right_blind_length > 0) {
887
+ var _vx = ch - right_blind_length;
888
888
  var _vy = cw;
889
889
  var _dx = _vx * cos + _vy * sin;
890
890
  var _dy = _vx * sin - _vy * cos;
@@ -4,7 +4,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  import { fromJS, List, Map, Record } from 'immutable';
7
- import { EXTERNAL_EVENT_ADD_WALL, EXTERNAL_EVENT_TOGGLE_TO_3D, EXTERNAL_EVENT_TOGGLE_TO_2D, EXTERNAL_EVENT_TOGGLE_TO_ELEVATION, EXTERNAL_EVENT_MOVE_PAN, MODE_IDLE, MODE_2D_PAN, EXTERNAL_EVENT_ADD_ITEM, ARRAY_3D_MODES, MODE_IDLE_3D, MODE_ELEVATION_VIEW, TOP, BOTTOM, LEFT, RIGHT, EXTERNAL_EVENT_NEW_PROJECT } from "../constants";
7
+ import { EXTERNAL_EVENT_ADD_WALL, EXTERNAL_EVENT_TOGGLE_TO_3D, EXTERNAL_EVENT_TOGGLE_TO_2D, EXTERNAL_EVENT_TOGGLE_TO_ELEVATION, EXTERNAL_EVENT_MOVE_PAN, MODE_IDLE, MODE_2D_PAN, EXTERNAL_EVENT_ADD_ITEM, ARRAY_3D_MODES, MODE_IDLE_3D, MODE_ELEVATION_VIEW, TOP, BOTTOM, LEFT, RIGHT, EXTERNAL_EVENT_NEW_PROJECT, EXTERNAL_EVENT_CHANGE_DOORSTYLE, EXTERNAL_EVENT_SET_INITIAL_DATA, EXTERNAL_EVENT_ADD_ROOM_SHAPE, EXTERNAL_EVENT_ZOOM_IN, EXTERNAL_EVENT_ZOOM_OUT, ZOOM_VARIABLE } from "../constants";
8
8
  import { isEmpty } from "./helper";
9
9
  import exporter from "../catalog/utils/exporter";
10
10
  import { render2DItem, render3DItem } from "../catalog/utils/item-loader";
@@ -62,42 +62,46 @@ var loadSVGsByItem = /*#__PURE__*/function () {
62
62
  return _ref.apply(this, arguments);
63
63
  };
64
64
  }();
65
- export function handleExternalEvent(_x2, _x3) {
65
+ var compareSVGRect = function compareSVGRect(value) {
66
+ return value.e <= 10 && value.e + value.a * value.SVGWidth + 10 >= value.viewerWidth && value.f <= 80 && value.f + value.d * value.SVGHeight + 10 >= value.viewerHeight ? true : false;
67
+ };
68
+ export function handleExternalEvent(_x2) {
66
69
  return _handleExternalEvent.apply(this, arguments);
67
70
  }
68
71
  function _handleExternalEvent() {
69
- _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(evt, props) {
70
- var state, sLineCnt, element, catalog, outlineSVGData, catalogInstance, elementJs, _evt$payload, moveType, moveValue, value, defaulTitle, _t2, _t3;
72
+ _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(props) {
73
+ var evt, state, sLineCnt, element, catalog, outlineSVGData, catalogInstance, elementJs, _evt$payload, moveType, moveValue, value, defaulTitle, _evt$payload2, doorStyle, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _t2, _t3;
71
74
  return _regeneratorRuntime.wrap(function (_context2) {
72
75
  while (1) switch (_context2.prev = _context2.next) {
73
76
  case 0:
74
- state = props.state;
77
+ evt = props.externalEvent;
78
+ state = props.state.get('KitchenConfigurator');
75
79
  _t2 = evt === null || evt === void 0 ? void 0 : evt.type;
76
- _context2.next = _t2 === EXTERNAL_EVENT_TOGGLE_TO_3D ? 1 : _t2 === EXTERNAL_EVENT_TOGGLE_TO_2D ? 2 : _t2 === EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 3 : _t2 === EXTERNAL_EVENT_ADD_WALL ? 4 : _t2 === EXTERNAL_EVENT_ADD_ITEM ? 5 : _t2 === EXTERNAL_EVENT_MOVE_PAN ? 9 : _t2 === EXTERNAL_EVENT_NEW_PROJECT ? 15 : 16;
80
+ _context2.next = _t2 === EXTERNAL_EVENT_TOGGLE_TO_3D ? 1 : _t2 === EXTERNAL_EVENT_TOGGLE_TO_2D ? 2 : _t2 === EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 3 : _t2 === EXTERNAL_EVENT_ADD_WALL ? 4 : _t2 === EXTERNAL_EVENT_ADD_ITEM ? 5 : _t2 === EXTERNAL_EVENT_MOVE_PAN ? 9 : _t2 === EXTERNAL_EVENT_NEW_PROJECT ? 15 : _t2 === EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 16 : _t2 === EXTERNAL_EVENT_SET_INITIAL_DATA ? 17 : _t2 === EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 18 : _t2 === EXTERNAL_EVENT_ZOOM_IN ? 19 : _t2 === EXTERNAL_EVENT_ZOOM_OUT ? 22 : 25;
77
81
  break;
78
82
  case 1:
79
83
  props.projectActions.setMode(MODE_IDLE_3D);
80
- return _context2.abrupt("continue", 16);
84
+ return _context2.abrupt("continue", 25);
81
85
  case 2:
82
86
  props.projectActions.setMode(MODE_IDLE);
83
- return _context2.abrupt("continue", 16);
87
+ return _context2.abrupt("continue", 25);
84
88
  case 3:
85
- sLineCnt = state.getIn(['KitchenConfigurator', 'scene', 'layers', 'layer-1', 'selected', 'lines']).size;
89
+ sLineCnt = state.getIn(['scene', 'layers', 'layer-1', 'selected', 'lines']).size;
86
90
  if (sLineCnt > 0) props.projectActions.setMode(MODE_ELEVATION_VIEW);
87
- return _context2.abrupt("continue", 16);
91
+ return _context2.abrupt("continue", 25);
88
92
  case 4:
89
93
  if (state.mode === MODE_IDLE || state.mode === MODE_2D_PAN) props.linesActions.selectToolDrawingLine('wall');else {
90
94
  props.projectActions.setMode(MODE_IDLE);
91
95
  props.linesActions.selectToolDrawingLine('wall');
92
96
  }
93
- return _context2.abrupt("continue", 16);
97
+ return _context2.abrupt("continue", 25);
94
98
  case 5:
95
99
  if (isEmpty(evt === null || evt === void 0 ? void 0 : evt.payload)) {
96
100
  _context2.next = 8;
97
101
  break;
98
102
  }
99
103
  element = evt.payload;
100
- catalog = state.getIn(['KitchenConfigurator', 'catalog']).toJS(); // add item to catalog of state
104
+ catalog = state.getIn(['catalog']).toJS(); // add item to catalog of state
101
105
  if (!isEmpty(catalog === null || catalog === void 0 ? void 0 : catalog.elements[element.name])) {
102
106
  _context2.next = 7;
103
107
  break;
@@ -114,6 +118,7 @@ function _handleExternalEvent() {
114
118
  render3DItem: render3DItem
115
119
  }));
116
120
  if (catalogInstance !== null && catalogInstance !== void 0 && catalogInstance.validateElement(elementJs)) {
121
+ catalogInstance.registerElement(elementJs);
117
122
  props.projectActions.addElementToCatalog(elementJs);
118
123
  }
119
124
  case 7:
@@ -122,10 +127,10 @@ function _handleExternalEvent() {
122
127
  props.projectActions.pushLastSelectedCatalogElementToHistory(element);
123
128
  props.projectActions.setIsCabinetDrawing(true);
124
129
  case 8:
125
- return _context2.abrupt("continue", 16);
130
+ return _context2.abrupt("continue", 25);
126
131
  case 9:
127
132
  _evt$payload = evt.payload, moveType = _evt$payload.moveType, moveValue = _evt$payload.moveValue;
128
- value = state.getIn(['KitchenConfigurator', 'viewer2D']).toJS();
133
+ value = state.getIn(['viewer2D']).toJS();
129
134
  _t3 = moveType;
130
135
  _context2.next = _t3 === TOP ? 10 : _t3 === BOTTOM ? 11 : _t3 === RIGHT ? 12 : _t3 === LEFT ? 13 : 14;
131
136
  break;
@@ -142,14 +147,79 @@ function _handleExternalEvent() {
142
147
  value.e -= moveValue;
143
148
  return _context2.abrupt("continue", 14);
144
149
  case 14:
145
- if (value.e <= 10 && value.e + value.a * value.SVGWidth + 10 >= value.viewerWidth && value.f <= 80 && value.f + value.d * value.SVGHeight + 10 >= value.viewerHeight) props.viewer2DActions.updateCameraView(value);
146
- return _context2.abrupt("continue", 16);
150
+ if (compareSVGRect(value)) props.viewer2DActions.updateCameraView(value);
151
+ return _context2.abrupt("continue", 25);
147
152
  case 15:
148
153
  defaulTitle = 'Untitle';
149
154
  props.projectActions.newProject();
150
155
  props.projectActions.rename(defaulTitle);
151
- return _context2.abrupt("continue", 16);
156
+ return _context2.abrupt("continue", 25);
152
157
  case 16:
158
+ _evt$payload2 = evt.payload, doorStyle = _evt$payload2.doorStyle, isAll = _evt$payload2.isAll;
159
+ props.itemsActions.setDoorStyle(doorStyle, isAll);
160
+ return _context2.abrupt("continue", 25);
161
+ case 17:
162
+ _doorStyle = evt.payload.doorStyle;
163
+ props.itemsActions.setInitialDoorStyle(_doorStyle.doorStyle, _doorStyle.oStyle);
164
+ return _context2.abrupt("continue", 25);
165
+ case 18:
166
+ props.projectActions.loadProject(evt.payload, props.categoryData);
167
+ return _context2.abrupt("continue", 25);
168
+ case 19:
169
+ _value = state.getIn(['viewer2D']).toJS();
170
+ _value.a -= 0.1;
171
+ _value.d -= 0.1;
172
+ _value.e += _value.SVGWidth * 0.1 / 2;
173
+ _value.f += _value.SVGHeight * 0.1 / 2;
174
+ _zoomValue = parseInt((_value.a - 0.5) / ZOOM_VARIABLE);
175
+ if (!(_zoomValue > 404)) {
176
+ _context2.next = 20;
177
+ break;
178
+ }
179
+ return _context2.abrupt("return");
180
+ case 20:
181
+ if (!(_zoomValue < 35 || Number.isNaN(_zoomValue))) {
182
+ _context2.next = 21;
183
+ break;
184
+ }
185
+ return _context2.abrupt("return");
186
+ case 21:
187
+ while (!(_value.e <= 10)) {
188
+ _value.e -= 0.1;
189
+ }
190
+ while (!(_value.e + _value.a * _value.SVGWidth + 10 >= _value.viewerWidth)) {
191
+ _value.e += 0.1;
192
+ }
193
+ while (!(_value.f <= 80)) {
194
+ _value.f -= 0.1;
195
+ }
196
+ while (!(_value.f + _value.a * _value.SVGHeight + 10 >= _value.viewerHeight)) {
197
+ _value.f += 0.1;
198
+ }
199
+ if (compareSVGRect(_value)) props.viewer2DActions.updateCameraView(_value);
200
+ return _context2.abrupt("continue", 25);
201
+ case 22:
202
+ _value2 = state.getIn(['viewer2D']).toJS();
203
+ _value2.a += 0.1;
204
+ _value2.d += 0.1;
205
+ _value2.e -= _value2.SVGWidth * 0.1 / 2;
206
+ _value2.f -= _value2.SVGHeight * 0.1 / 2;
207
+ _zoomValue2 = parseInt((_value2.a - 0.5) / ZOOM_VARIABLE);
208
+ if (!(_zoomValue2 > 404)) {
209
+ _context2.next = 23;
210
+ break;
211
+ }
212
+ return _context2.abrupt("return");
213
+ case 23:
214
+ if (!(_zoomValue2 < 35 || Number.isNaN(_zoomValue2))) {
215
+ _context2.next = 24;
216
+ break;
217
+ }
218
+ return _context2.abrupt("return");
219
+ case 24:
220
+ if (compareSVGRect(_value2)) props.viewer2DActions.updateCameraView(_value2);
221
+ return _context2.abrupt("continue", 25);
222
+ case 25:
153
223
  case "end":
154
224
  return _context2.stop();
155
225
  }
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports["default"] = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
11
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
13
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -33,7 +31,7 @@ var _objectsUtils = require("./utils/objects-utils");
33
31
  var _version = require("./version");
34
32
  var _isolateEventHandler = require("./utils/isolate-event-handler");
35
33
  var _excluded = ["width", "height", "state", "stateExtractor"];
36
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
34
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
37
35
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
38
36
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
39
37
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
@@ -112,7 +110,8 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
112
110
  redirectURL: '',
113
111
  snackBarMessage: '',
114
112
  isSaved: false,
115
- isLeaving: false
113
+ isLeaving: false,
114
+ stateCatalog: _this.props.catalog
116
115
  };
117
116
 
118
117
  // For UTM tracking
@@ -353,116 +352,17 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
353
352
  }, {
354
353
  key: "componentDidMount",
355
354
  value: function componentDidMount() {
356
- var _this3 = this;
357
355
  window.addEventListener('beforeunload', this.handleBeforeUnload);
358
356
  console.log('context =>', this.context);
359
357
  window.forRedo = [];
360
358
  var store = this.context.store;
361
359
  var _this$props2 = this.props,
362
- projectActions = _this$props2.projectActions,
363
- catalog = _this$props2.catalog,
364
360
  stateExtractor = _this$props2.stateExtractor,
365
- state = _this$props2.state,
366
361
  plugins = _this$props2.plugins;
367
- projectActions.initCatalog(catalog);
368
- var match = this.props.match;
369
- if (sessionStorage.getItem(window.location.href)) {
370
- var jsonData = sessionStorage.getItem(window.location.href);
371
- projectActions.loadProject(JSON.parse(jsonData), this.props.categoryData);
372
- sessionStorage.removeItem(window.location.href);
373
- return;
374
- }
375
362
  var newplugins = (0, _toConsumableArray2["default"])(plugins);
376
363
  newplugins.forEach(function (newplugin) {
377
364
  return newplugin(store, stateExtractor);
378
365
  });
379
- if (match && match.params.pid === undefined) {
380
- projectActions.newProject();
381
- sessionStorage.setItem('projectTitle', 'Untitled');
382
- projectActions.rename('Untitled');
383
- sessionStorage.removeItem('projectId');
384
- sessionStorage.removeItem('email');
385
- sessionStorage.removeItem('firstName');
386
- sessionStorage.removeItem('lastName');
387
- sessionStorage.removeItem('usedObjects');
388
- return;
389
- }
390
- if (match && match.params.pid !== undefined) {
391
- if (match.params.pid === 'new') {
392
- projectActions.newProject();
393
- sessionStorage.setItem('projectTitle', 'Untitled');
394
- projectActions.rename('Untitled');
395
- sessionStorage.removeItem('projectId');
396
- sessionStorage.removeItem('email');
397
- sessionStorage.removeItem('firstName');
398
- sessionStorage.removeItem('lastName');
399
- sessionStorage.removeItem('usedObjects');
400
- } else {
401
- _axios["default"].post("".concat(constants.API_SERVER_URL, "/api/project/loadPidProject"), {
402
- pid: match.params.pid,
403
- visualizerName: sessionStorage.getItem('visualizerName')
404
- }).then(/*#__PURE__*/function () {
405
- var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(response) {
406
- var projectElement, jsonData, _t;
407
- return _regenerator["default"].wrap(function (_context) {
408
- while (1) switch (_context.prev = _context.next) {
409
- case 0:
410
- projectElement = response.data.projectElement;
411
- if (!(projectElement.length === 0)) {
412
- _context.next = 1;
413
- break;
414
- }
415
- return _context.abrupt("return");
416
- case 1:
417
- sessionStorage.setItem('projectTitle', projectElement[0].title);
418
- projectActions.rename(projectElement[0].title);
419
- sessionStorage.setItem('projectId', projectElement[0].id);
420
- sessionStorage.setItem('email', projectElement[0].email);
421
- sessionStorage.setItem('firstName', projectElement[0].firstName);
422
- sessionStorage.setItem('lastName', projectElement[0].lastName);
423
- sessionStorage.setItem('phone', projectElement[0].phone);
424
- if (!projectElement[0].project_data) {
425
- _context.next = 2;
426
- break;
427
- }
428
- jsonData = JSON.parse(projectElement[0].project_data);
429
- _context.next = 5;
430
- break;
431
- case 2:
432
- _context.prev = 2;
433
- _context.next = 3;
434
- return _axios["default"].post("".concat(constants.API_SERVER_URL, "/api/project/loadPidData"), {
435
- pid: match.params.pid
436
- }).data.data;
437
- case 3:
438
- jsonData = _context.sent;
439
- _context.next = 5;
440
- break;
441
- case 4:
442
- _context.prev = 4;
443
- _t = _context["catch"](2);
444
- _this3.setState({
445
- isSnackBarOpen: true,
446
- snackBarMessage: _t
447
- });
448
- case 5:
449
- jsonData.isLoadingCabinet = false;
450
- projectActions.loadProject(jsonData, _this3.props.categoryData);
451
- case 6:
452
- case "end":
453
- return _context.stop();
454
- }
455
- }, _callee, null, [[2, 4]]);
456
- }));
457
- return function (_x) {
458
- return _ref.apply(this, arguments);
459
- };
460
- }());
461
- }
462
- sessionStorage.removeItem('user_type');
463
- sessionStorage.removeItem('project_type');
464
- sessionStorage.removeItem('project_timeline');
465
- }
466
366
  }
467
367
  }, {
468
368
  key: "componentWillUnmount",
@@ -476,6 +376,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
476
376
  }, {
477
377
  key: "componentWillReceiveProps",
478
378
  value: function componentWillReceiveProps(nextProps) {
379
+ var _oldState$catalog, _plannerState$catalog;
479
380
  var stateExtractor = nextProps.stateExtractor,
480
381
  state = nextProps.state,
481
382
  projectActions = nextProps.projectActions,
@@ -484,9 +385,18 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
484
385
 
485
386
  // handle external events
486
387
  if (this.props.externalEvent !== externalEvent) {
487
- (0, _isolateEventHandler.handleExternalEvent)(externalEvent, this.props);
388
+ (0, _isolateEventHandler.handleExternalEvent)(nextProps);
488
389
  }
489
390
  var plannerState = stateExtractor(state);
391
+ var oldState = stateExtractor(this.props.state);
392
+ if ((oldState === null || oldState === void 0 || (_oldState$catalog = oldState.catalog) === null || _oldState$catalog === void 0 ? void 0 : _oldState$catalog.elements) !== (plannerState === null || plannerState === void 0 || (_plannerState$catalog = plannerState.catalog) === null || _plannerState$catalog === void 0 ? void 0 : _plannerState$catalog.elements)) {
393
+ // copy state.catalog to the props.catalog
394
+ // let catalog = this.state.stateCatalog;
395
+ // console.log('111111', plannerState?.catalog?.elements.toJS());
396
+ // catalog.elements = plannerState?.catalog?.elements.toJS();
397
+ // console.log('222222', catalog);
398
+ // this.setState({ stateCatalog: catalog });
399
+ }
490
400
  var catalogReady = plannerState.getIn(['catalog', 'ready']);
491
401
  if (!catalogReady) {
492
402
  projectActions.initCatalog(catalog);
@@ -582,7 +492,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
582
492
  }, /*#__PURE__*/_react["default"].createElement(_export2.Content, (0, _extends2["default"])({
583
493
  width: contentW,
584
494
  height: contentH,
585
- catalog: this.props.catalog,
495
+ catalog: this.state.stateCatalog,
586
496
  state: extractedState,
587
497
  toolBar: this.state.toolbar,
588
498
  setToolbar: this.setToolbar,
@@ -498,7 +498,7 @@ function LiteRenderer(props) {
498
498
  }();
499
499
  initCatalog();
500
500
  // eslint-disable-next-line react-hooks/exhaustive-deps
501
- }, []);
501
+ }, [categoryData, data, id, catalogs, colorAlias, subgroups]);
502
502
 
503
503
  // Register items once SVGs are loaded
504
504
  (0, _react.useEffect)(function () {
@@ -538,6 +538,13 @@ function LiteRenderer(props) {
538
538
  (0, _react.useEffect)(function () {
539
539
  if (projectElement.length === 0) return;
540
540
  if (!catalogInitiated) return;
541
+ store.dispatch((0, _projectActions.initCatalog)(MyCatalog));
542
+ if (sessionStorage.getItem(window.location.href)) {
543
+ var _jsonData = sessionStorage.getItem(window.location.href);
544
+ store.dispatch((0, _projectActions.loadProject)(JSON.parse(_jsonData), categoryData));
545
+ sessionStorage.removeItem(window.location.href);
546
+ return;
547
+ }
541
548
  sessionStorage.setItem('projectTitle', projectElement[0].title);
542
549
  store.dispatch((0, _projectActions.rename)(projectElement[0].title));
543
550
  sessionStorage.setItem('projectId', projectElement[0].id);
@@ -274,11 +274,10 @@ function updateItemsAltitude(layerID, itemID, value) {
274
274
  value: value
275
275
  };
276
276
  }
277
- function setDoorStyle(doorStyle, pathes, isAll) {
277
+ function setDoorStyle(doorStyle, isAll) {
278
278
  return {
279
279
  type: _constants.SET_DOOR_STYLE,
280
280
  doorStyle: doorStyle,
281
- pathes: pathes,
282
281
  isAll: isAll
283
282
  };
284
283
  }
@@ -254,7 +254,10 @@ var Catalog = exports["default"] = /*#__PURE__*/function () {
254
254
  if (name === '') {
255
255
  throw new Error('Category has empty name');
256
256
  }
257
- return !this.hasCategory(name);
257
+ if (this.hasCategory(name)) {
258
+ throw new Error('Category has already been registered');
259
+ }
260
+ return true;
258
261
  }
259
262
 
260
263
  /**
package/lib/class/item.js CHANGED
@@ -1171,7 +1171,7 @@ var Item = exports["default"] = /*#__PURE__*/function () {
1171
1171
  }
1172
1172
  }, {
1173
1173
  key: "setDoorStyle",
1174
- value: function setDoorStyle(state, doorStyle, pathes, isAll) {
1174
+ value: function setDoorStyle(state, doorStyle, isAll) {
1175
1175
  var _this2 = this;
1176
1176
  var keys = Object.keys(doorStyle.doorStyles);
1177
1177
  keys = keys.filter(function (elem) {
@@ -487,6 +487,10 @@ var Project = exports["default"] = /*#__PURE__*/function () {
487
487
  };
488
488
  }
489
489
  var mode;
490
+ var isLineAction = false;
491
+ if (state.mode.includes('LINE')) {
492
+ isLineAction = true;
493
+ }
490
494
  if (state.mode == _constants.MODE_DRAWING_ITEM_3D) {
491
495
  mode = _constants.MODE_IDLE_3D;
492
496
  if (state.drawingSupport.has('currentID')) state = _export2.Layer.removeElement(state, state.scene.selectedLayer, 'items', state.drawingSupport.get('currentID')).updatedState;
@@ -529,6 +533,9 @@ var Project = exports["default"] = /*#__PURE__*/function () {
529
533
  draggingSupport: new _immutable.Map(),
530
534
  rotatingSupport: new _immutable.Map()
531
535
  });
536
+ if (isLineAction) {
537
+ state = _export2.Line.applyWallChanges(state, _constants.END_DRAWING_LINE).updatedState;
538
+ }
532
539
  return {
533
540
  updatedState: state
534
541
  };
@@ -613,7 +620,7 @@ var Project = exports["default"] = /*#__PURE__*/function () {
613
620
  updatedState: state
614
621
  };
615
622
  } catch (error) {
616
- console.log('initCatalogError', error);
623
+ console.log('addElementToCatalogError', error);
617
624
  return {
618
625
  updatedState: state
619
626
  };