kitchen-simulator 3.16.0 → 3.16.1-test-renderer-fix

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.
@@ -31,8 +31,8 @@ var _translator = _interopRequireDefault(require("./translator/translator"));
31
31
  var _objectsUtils = require("./utils/objects-utils");
32
32
  var _version = require("./version");
33
33
  var _isolateEventHandler = require("./utils/isolate-event-handler");
34
- var _excluded = ["width", "height", "state", "stateExtractor", "measurementUnit"];
35
- var _templateObject, _templateObject2;
34
+ var _excluded = ["width", "height", "extractedState"];
35
+ var _templateObject, _templateObject2; // LiteKitchenConfigurator.jsx
36
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 _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
37
  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
38
  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; }
@@ -43,7 +43,7 @@ var wrapperStyle = {
43
43
  display: 'flex',
44
44
  flexFlow: 'row nowrap'
45
45
  };
46
- var WarningItem = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n opacity: 0.8;\n position: absolute;\n border-radius: 6px;\n z-index: 11;\n background-color: #ff7400;\n width: max-content;\n align-items: center;\n padding: 10px;\n display: none;\n box-shadow: 0px 3px 5px -1px rgba(0, 0, 0, 0.2),\n 0px 6px 10px 0px rgba(0, 0, 0, 0.39), 0px 1px 18px 0px rgba(0, 0, 0, 0.12);\n top: -50px;\n left: 5px;\n color: white;\n"])));
46
+ var WarningItem = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n opacity: 0.8;\n position: absolute;\n border-radius: 6px;\n z-index: 11;\n background-color: #ff7400;\n width: max-content;\n align-items: center;\n padding: 10px;\n display: none;\n box-shadow:\n 0px 3px 5px -1px rgba(0, 0, 0, 0.2),\n 0px 6px 10px 0px rgba(0, 0, 0, 0.39),\n 0px 1px 18px 0px rgba(0, 0, 0, 0.12);\n top: -50px;\n left: 5px;\n color: white;\n"])));
47
47
  var SubCategoryItemImage = _styledComponents["default"].img(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n background-color: ", ";\n height: 30px;\n width: 30px;\n -webkit-mask-image: url(", ");\n -webkit-mask-size: calc(100% - 2px) calc(100% - 2px);\n -webkit-mask-repeat: no-repeat;\n -webkit-mask-position: 1px 1px;\n"])), constants.SECONDARY_PURPLE_COLOR, function (props) {
48
48
  return props.maskImage + '?nocache=2025';
49
49
  });
@@ -53,8 +53,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
53
53
  var _this;
54
54
  (0, _classCallCheck2["default"])(this, LiteKitchenConfigurator);
55
55
  _this = _callSuper(this, LiteKitchenConfigurator, [props]);
56
-
57
- // utm tracking
58
56
  var utmDetailParams = new URLSearchParams(_this.props.location && _this.props.location.search);
59
57
  var utmStrEncoded = utmDetailParams.get('details');
60
58
  var utmRequestData = null;
@@ -64,7 +62,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
64
62
  utmRequestData = JSON.parse((0, _helper.base64Decode)(utmStrEncoded));
65
63
  utmRequestData = JSON.parse((_utmRequestData = utmRequestData) === null || _utmRequestData === void 0 ? void 0 : _utmRequestData.utm);
66
64
  } catch (e) {
67
- console.error('Cannot parse utm parameter: ', error);
65
+ console.error('Cannot parse utm parameter: ', e);
68
66
  utmRequestData = null;
69
67
  }
70
68
  }
@@ -83,7 +81,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
83
81
  myProjectsOpen: false,
84
82
  myProjectsToLogin: false,
85
83
  downloadPopupVisible: false,
86
- // For Toolbar Item
87
84
  toolbar: '',
88
85
  reviewQuotePopupOpened: false,
89
86
  floorOpened: false,
@@ -101,8 +98,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
101
98
  isSaved: false,
102
99
  isLeaving: false
103
100
  };
104
-
105
- // For UTM tracking
106
101
  _this.utm = {
107
102
  utm_source: ((_utmRequestData2 = utmRequestData) === null || _utmRequestData2 === void 0 ? void 0 : _utmRequestData2.source) || 'source',
108
103
  utm_medium: ((_utmRequestData3 = utmRequestData) === null || _utmRequestData3 === void 0 ? void 0 : _utmRequestData3.medium) || 'medium',
@@ -133,10 +128,12 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
133
128
  _this.setDownloadPopupVisible = _this.setDownloadPopupVisible.bind(_this);
134
129
  _this.neverShowInput = /*#__PURE__*/_react["default"].createRef(null);
135
130
  _this.setShowProperty = _this.setShowProperty.bind(_this);
131
+
132
+ // cache for viewer2D init so we don't allocate merges every render
133
+ _this._cachedViewer2DKey = null;
134
+ _this._cachedExtractedState = null;
136
135
  return _this;
137
136
  }
138
-
139
- // Toolbar control functions
140
137
  (0, _inherits2["default"])(LiteKitchenConfigurator, _Component);
141
138
  return (0, _createClass2["default"])(LiteKitchenConfigurator, [{
142
139
  key: "setToolbar",
@@ -220,26 +217,32 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
220
217
  }, {
221
218
  key: "openFloor",
222
219
  value: function openFloor() {
220
+ var _el$parentElement;
223
221
  this.setState({
224
222
  floorOpened: true
225
223
  });
226
- document.getElementById('make_floorplan_inactive').parentElement.parentElement.style.zIndex = 999;
224
+ var el = document.getElementById('make_floorplan_inactive');
225
+ if (el !== null && el !== void 0 && (_el$parentElement = el.parentElement) !== null && _el$parentElement !== void 0 && _el$parentElement.parentElement) el.parentElement.parentElement.style.zIndex = 999;
227
226
  }
228
227
  }, {
229
228
  key: "openCabinet",
230
229
  value: function openCabinet() {
230
+ var _el$parentElement2;
231
231
  this.setState({
232
232
  cabinetOpened: true
233
233
  });
234
- document.getElementById('add_cabinets_inactive').parentElement.parentElement.style.zIndex = 999;
234
+ var el = document.getElementById('add_cabinets_inactive');
235
+ if (el !== null && el !== void 0 && (_el$parentElement2 = el.parentElement) !== null && _el$parentElement2 !== void 0 && _el$parentElement2.parentElement) el.parentElement.parentElement.style.zIndex = 999;
235
236
  }
236
237
  }, {
237
238
  key: "toggleDoorStyle",
238
239
  value: function toggleDoorStyle(visible) {
240
+ var _el$parentElement3;
239
241
  this.setState({
240
242
  doorStyleOpen: visible
241
243
  });
242
- document.getElementById('select_doorstyle_inactive').parentElement.parentElement.style.zIndex = visible ? 999 : 6;
244
+ var el = document.getElementById('select_doorstyle_inactive');
245
+ if (el !== null && el !== void 0 && (_el$parentElement3 = el.parentElement) !== null && _el$parentElement3 !== void 0 && _el$parentElement3.parentElement) el.parentElement.parentElement.style.zIndex = visible ? 999 : 6;
243
246
  }
244
247
  }, {
245
248
  key: "replaceCabinet",
@@ -251,70 +254,72 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
251
254
  }, {
252
255
  key: "openAppliance",
253
256
  value: function openAppliance() {
257
+ var _el$parentElement4;
254
258
  this.setState({
255
259
  applianceOpened: true
256
260
  });
257
- document.getElementById('add_appliances_inactive').parentElement.parentElement.style.zIndex = 999;
261
+ var el = document.getElementById('add_appliances_inactive');
262
+ if (el !== null && el !== void 0 && (_el$parentElement4 = el.parentElement) !== null && _el$parentElement4 !== void 0 && _el$parentElement4.parentElement) el.parentElement.parentElement.style.zIndex = 999;
258
263
  }
259
264
  }, {
260
265
  key: "openFinishing",
261
266
  value: function openFinishing() {
267
+ var _el$parentElement5;
262
268
  this.setState({
263
269
  finishingOpened: true
264
270
  });
265
- document.getElementById('finishing_touches_inactive').parentElement.parentElement.style.zIndex = 999;
271
+ var el = document.getElementById('finishing_touches_inactive');
272
+ if (el !== null && el !== void 0 && (_el$parentElement5 = el.parentElement) !== null && _el$parentElement5 !== void 0 && _el$parentElement5.parentElement) el.parentElement.parentElement.style.zIndex = 999;
266
273
  }
267
274
  }, {
268
275
  key: "onReviewQuoteClicked",
269
276
  value: function onReviewQuoteClicked(visible) {
277
+ var _el$parentElement6;
270
278
  this.setState({
271
279
  reviewQuotePopupOpened: visible
272
280
  });
273
- document.getElementById('review_quote_inactive').parentElement.parentElement.style.zIndex = visible ? 999 : 6;
281
+ var el = document.getElementById('review_quote_inactive');
282
+ if (el !== null && el !== void 0 && (_el$parentElement6 = el.parentElement) !== null && _el$parentElement6 !== void 0 && _el$parentElement6.parentElement) el.parentElement.parentElement.style.zIndex = visible ? 999 : 6;
274
283
  }
275
284
  }, {
276
285
  key: "closeFloorTB",
277
286
  value: function closeFloorTB() {
287
+ var _el$parentElement7;
278
288
  this.setState({
279
289
  floorOpened: false
280
290
  });
281
- document.getElementById('make_floorplan_inactive') && (document.getElementById('make_floorplan_inactive').parentElement.parentElement.style.zIndex = 6);
291
+ var el = document.getElementById('make_floorplan_inactive');
292
+ if (el !== null && el !== void 0 && (_el$parentElement7 = el.parentElement) !== null && _el$parentElement7 !== void 0 && _el$parentElement7.parentElement) el.parentElement.parentElement.style.zIndex = 6;
282
293
  }
283
294
  }, {
284
295
  key: "closeCabinetTB",
285
296
  value: function closeCabinetTB() {
297
+ var _el$parentElement8;
286
298
  this.setState({
287
299
  cabinetOpened: false
288
300
  });
289
- document.getElementById('add_cabinets_inactive').parentElement.parentElement.style.zIndex = 6;
301
+ var el = document.getElementById('add_cabinets_inactive');
302
+ if (el !== null && el !== void 0 && (_el$parentElement8 = el.parentElement) !== null && _el$parentElement8 !== void 0 && _el$parentElement8.parentElement) el.parentElement.parentElement.style.zIndex = 6;
290
303
  }
291
304
  }, {
292
305
  key: "closeFinishingTB",
293
306
  value: function closeFinishingTB() {
307
+ var _el$parentElement9;
294
308
  this.setState({
295
309
  finishingOpened: false
296
310
  });
297
- document.getElementById('finishing_touches_inactive').parentElement.parentElement.style.zIndex = 6;
311
+ var el = document.getElementById('finishing_touches_inactive');
312
+ if (el !== null && el !== void 0 && (_el$parentElement9 = el.parentElement) !== null && _el$parentElement9 !== void 0 && _el$parentElement9.parentElement) el.parentElement.parentElement.style.zIndex = 6;
298
313
  }
299
314
  }, {
300
315
  key: "closeApplianceTB",
301
316
  value: function closeApplianceTB() {
317
+ var _el$parentElement0;
302
318
  this.setState({
303
319
  applianceOpened: false
304
320
  });
305
- document.getElementById('add_appliances_inactive').parentElement.parentElement.style.zIndex = 6;
306
- }
307
- }, {
308
- key: "closeDoorstyle",
309
- value: function closeDoorstyle() {
310
- this.setState({});
311
- document.getElementById('select_doorstyle_inactive').parentElement.parentElement.style.zIndex = 6;
312
- }
313
- }, {
314
- key: "closeReviewQuote",
315
- value: function closeReviewQuote() {
316
- this.setState({});
317
- document.getElementById('review_quote_inactive').parentElement.parentElement.style.zIndex = 6;
321
+ var el = document.getElementById('add_appliances_inactive');
322
+ if (el !== null && el !== void 0 && (_el$parentElement0 = el.parentElement) !== null && _el$parentElement0 !== void 0 && _el$parentElement0.parentElement) el.parentElement.parentElement.style.zIndex = 6;
318
323
  }
319
324
  }, {
320
325
  key: "getChildContext",
@@ -330,36 +335,36 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
330
335
  }, {
331
336
  key: "componentDidMount",
332
337
  value: function componentDidMount() {
333
- console.log('context =>', this.context);
334
338
  window.forRedo = [];
335
339
  var store = this.context.store;
336
340
  var _this$props = this.props,
337
341
  stateExtractor = _this$props.stateExtractor,
338
342
  plugins = _this$props.plugins;
343
+
344
+ // keep old behavior: run plugins once on mount
339
345
  var newplugins = (0, _toConsumableArray2["default"])(plugins);
340
346
  newplugins.forEach(function (newplugin) {
341
347
  return newplugin(store, stateExtractor);
342
348
  });
343
349
  }
344
350
  }, {
345
- key: "componentWillReceiveProps",
346
- value: function componentWillReceiveProps(nextProps) {
347
- var stateExtractor = nextProps.stateExtractor,
348
- state = nextProps.state,
349
- projectActions = nextProps.projectActions,
350
- catalog = nextProps.catalog,
351
- externalEvent = nextProps.externalEvent,
352
- onInternalEvent = nextProps.onInternalEvent;
351
+ key: "componentDidUpdate",
352
+ value: function componentDidUpdate(prevProps) {
353
+ var _extractedState$getIn;
354
+ var _this$props2 = this.props,
355
+ externalEvent = _this$props2.externalEvent,
356
+ extractedState = _this$props2.extractedState,
357
+ projectActions = _this$props2.projectActions,
358
+ catalog = _this$props2.catalog;
353
359
 
354
- // handle external events
355
- if (this.props.externalEvent !== externalEvent) {
356
- (0, _isolateEventHandler.handleExternalEvent)(nextProps);
357
- }
358
- var plannerState = stateExtractor(state);
359
- var catalogReady = plannerState.getIn(['catalog', 'ready']);
360
- if (!catalogReady) {
361
- projectActions.initCatalog(catalog);
360
+ // same behavior: handle external event when it changes
361
+ if (prevProps.externalEvent !== externalEvent) {
362
+ (0, _isolateEventHandler.handleExternalEvent)(this.props);
362
363
  }
364
+
365
+ // same behavior: init catalog until ready
366
+ var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn = extractedState.getIn) === null || _extractedState$getIn === void 0 ? void 0 : _extractedState$getIn.call(extractedState, ['catalog', 'ready']);
367
+ if (!catalogReady) projectActions.initCatalog(catalog);
363
368
  }
364
369
  }, {
365
370
  key: "isProjectEmpty",
@@ -369,16 +374,45 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
369
374
  var layer = layers.get(selectedLayer);
370
375
  return layer.areas.size + layer.lines.size + layer.holes.size + layer.items.size === 0;
371
376
  }
377
+ }, {
378
+ key: "getExtractedStateWithViewer2DInit",
379
+ value: function getExtractedStateWithViewer2DInit(extractedState, width, height) {
380
+ if (!extractedState) return extractedState;
381
+ var _scene = extractedState.getIn(['scene']);
382
+ var len = (0, _convertUnitsLite.convert)(_scene.width).from(_scene.unit).to('cm');
383
+ var _viewer2D = extractedState.getIn(['viewer2D']);
384
+ if (!_viewer2D || _viewer2D.size <= 0) return extractedState;
385
+ var v = _viewer2D.toJS();
386
+ var cacheKey = "".concat(width, ":").concat(height, ":").concat(len, ":").concat(v.e, ":").concat(v.f, ":").concat(v.viewerWidth, ":").concat(v.viewerHeight, ":").concat(v.SVGWidth, ":").concat(v.SVGHeight, ":").concat(v.a, ":").concat(v.d);
387
+ if (this._cachedViewer2DKey === cacheKey && this._cachedExtractedState) {
388
+ return this._cachedExtractedState;
389
+ }
390
+ if (v.e === 0 && v.f === 0) {
391
+ _viewer2D = _viewer2D.merge({
392
+ e: v.viewerWidth / 2 - v.SVGWidth / 2,
393
+ f: v.viewerHeight / 2 - v.SVGHeight / 2,
394
+ a: 0.99,
395
+ d: 0.99
396
+ });
397
+ var merged = extractedState.merge({
398
+ viewer2D: _viewer2D
399
+ });
400
+ this._cachedViewer2DKey = cacheKey;
401
+ this._cachedExtractedState = merged;
402
+ return merged;
403
+ }
404
+ this._cachedViewer2DKey = cacheKey;
405
+ this._cachedExtractedState = extractedState;
406
+ return extractedState;
407
+ }
372
408
  }, {
373
409
  key: "render",
374
410
  value: function render() {
375
- var _this$props2 = this.props,
376
- width = _this$props2.width,
377
- height = _this$props2.height,
378
- state = _this$props2.state,
379
- stateExtractor = _this$props2.stateExtractor,
380
- measurementUnit = _this$props2.measurementUnit,
381
- props = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded);
411
+ var _this$props3 = this.props,
412
+ width = _this$props3.width,
413
+ height = _this$props3.height,
414
+ extractedState = _this$props3.extractedState,
415
+ props = (0, _objectWithoutProperties2["default"])(_this$props3, _excluded);
382
416
  var _this$state = this.state,
383
417
  savePopupVisible = _this$state.savePopupVisible,
384
418
  quotePopupVisible = _this$state.quotePopupVisible,
@@ -386,40 +420,10 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
386
420
  signOpen = _this$state.signOpen,
387
421
  myProjectsOpen = _this$state.myProjectsOpen;
388
422
  var contentW = width - toolbarW;
389
- // let contentW = width - toolbarW - sidebarW;
390
- // let toolbarH = height - footerBarH;
391
- // let contentH = height - footerBarH;
392
- // let sidebarH = height - footerBarH;
393
- var toolbarH = height;
394
423
  var contentH = height;
395
- var sidebarH = height;
396
- var headerW = width;
397
- var headerH = 60;
398
- var extractedState = stateExtractor(state);
399
- var firstVisit = this.state.wizardStepOpend && this.isProjectEmpty(extractedState.scene);
424
+ var extracted = this.getExtractedStateWithViewer2DInit(extractedState, width, height);
425
+ var firstVisit = this.state.wizardStepOpend && this.isProjectEmpty(extracted.scene);
400
426
  var allVisible = firstVisit || signOpen || myProjectsOpen;
401
- var _scene = extractedState.getIn(['scene']);
402
- var len = (0, _convertUnitsLite.convert)(_scene.width).from(_scene.unit).to('cm');
403
- var _viewer2D = extractedState.getIn(['viewer2D']);
404
- if (_viewer2D.size > 0) {
405
- var scaleX = width / len * 3;
406
- var scaleY = height / len * 3;
407
- var scale = scaleX > scaleY ? scaleY : scaleX;
408
- var _e = width - len * scale,
409
- _f = height - len * scale;
410
- var viewer = _viewer2D.toJS();
411
- if (viewer.e === 0 && viewer.f === 0) {
412
- _viewer2D = _viewer2D.merge({
413
- e: viewer.viewerWidth / 2 - viewer.SVGWidth / 2,
414
- f: viewer.viewerHeight / 2 - viewer.SVGHeight / 2,
415
- a: 0.99,
416
- d: 0.99
417
- });
418
- }
419
- }
420
- extractedState = extractedState.merge({
421
- viewer2D: _viewer2D
422
- });
423
427
  return /*#__PURE__*/_react["default"].createElement("section", null, /*#__PURE__*/_react["default"].createElement("div", {
424
428
  style: _objectSpread(_objectSpread({}, wrapperStyle), {}, {
425
429
  height: height,
@@ -431,7 +435,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
431
435
  width: contentW,
432
436
  height: contentH,
433
437
  catalog: this.props.catalog,
434
- state: extractedState,
438
+ state: extracted,
435
439
  toolBar: this.state.toolbar,
436
440
  setToolbar: this.setToolbar,
437
441
  replaceCabinet: this.replaceCabinet,
@@ -468,12 +472,11 @@ LiteKitchenConfigurator.propTypes = {
468
472
  width: _propTypes["default"].number.isRequired,
469
473
  height: _propTypes["default"].number.isRequired,
470
474
  stateExtractor: _propTypes["default"].func.isRequired,
471
- sidebarComponents: _propTypes["default"].array,
472
- footerbarComponents: _propTypes["default"].array,
473
- customContents: _propTypes["default"].object,
474
- softwareSignature: _propTypes["default"].string,
475
475
  configData: _propTypes["default"].object,
476
- onInternalEvent: _propTypes["default"].func
476
+ onInternalEvent: _propTypes["default"].func,
477
+ extractedState: _propTypes["default"].object,
478
+ // ✅ injected by connect
479
+ externalEvent: _propTypes["default"].object
477
480
  };
478
481
  LiteKitchenConfigurator.contextTypes = {
479
482
  store: _propTypes["default"].object.isRequired
@@ -496,10 +499,15 @@ LiteKitchenConfigurator.defaultProps = {
496
499
  configData: {}
497
500
  };
498
501
 
499
- //redux connect
500
- function mapStateToProps(reduxState) {
502
+ // ✅ Only select the slice you actually use.
503
+ // This preserves behavior but massively reduces rerenders.
504
+ function mapStateToProps(reduxState, ownProps) {
505
+ var stateExtractor = ownProps.stateExtractor || function (s) {
506
+ return s;
507
+ };
508
+ var extractedState = stateExtractor(reduxState);
501
509
  return {
502
- state: reduxState
510
+ extractedState: extractedState
503
511
  };
504
512
  }
505
513
  function mapDispatchToProps(dispatch) {