kitchen-simulator 3.14.0 → 3.16.0-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.
@@ -8,12 +8,13 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
8
8
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
9
  import _inherits from "@babel/runtime/helpers/esm/inherits";
10
10
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
11
- var _excluded = ["width", "height", "state", "stateExtractor", "measurementUnit"];
11
+ var _excluded = ["width", "height", "extractedState", "measurementUnit"];
12
12
  var _templateObject, _templateObject2;
13
13
  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; }
14
14
  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; }
15
15
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
16
16
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
+ // LiteKitchenConfigurator.jsx
17
18
  import styled from 'styled-components';
18
19
  import { convert } from "./utils/convert-units-lite";
19
20
  import PropTypes from 'prop-types';
@@ -34,7 +35,7 @@ var wrapperStyle = {
34
35
  display: 'flex',
35
36
  flexFlow: 'row nowrap'
36
37
  };
37
- var WarningItem = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\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"])));
38
+ var WarningItem = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\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"])));
38
39
  var SubCategoryItemImage = styled.img(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\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) {
39
40
  return props.maskImage + '?nocache=2025';
40
41
  });
@@ -44,8 +45,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
44
45
  var _this;
45
46
  _classCallCheck(this, LiteKitchenConfigurator);
46
47
  _this = _callSuper(this, LiteKitchenConfigurator, [props]);
47
-
48
- // utm tracking
49
48
  var utmDetailParams = new URLSearchParams(_this.props.location && _this.props.location.search);
50
49
  var utmStrEncoded = utmDetailParams.get('details');
51
50
  var utmRequestData = null;
@@ -55,7 +54,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
55
54
  utmRequestData = JSON.parse(base64Decode(utmStrEncoded));
56
55
  utmRequestData = JSON.parse((_utmRequestData = utmRequestData) === null || _utmRequestData === void 0 ? void 0 : _utmRequestData.utm);
57
56
  } catch (e) {
58
- console.error('Cannot parse utm parameter: ', error);
57
+ console.error('Cannot parse utm parameter: ', e);
59
58
  utmRequestData = null;
60
59
  }
61
60
  }
@@ -74,7 +73,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
74
73
  myProjectsOpen: false,
75
74
  myProjectsToLogin: false,
76
75
  downloadPopupVisible: false,
77
- // For Toolbar Item
78
76
  toolbar: '',
79
77
  reviewQuotePopupOpened: false,
80
78
  floorOpened: false,
@@ -92,8 +90,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
92
90
  isSaved: false,
93
91
  isLeaving: false
94
92
  };
95
-
96
- // For UTM tracking
97
93
  _this.utm = {
98
94
  utm_source: ((_utmRequestData2 = utmRequestData) === null || _utmRequestData2 === void 0 ? void 0 : _utmRequestData2.source) || 'source',
99
95
  utm_medium: ((_utmRequestData3 = utmRequestData) === null || _utmRequestData3 === void 0 ? void 0 : _utmRequestData3.medium) || 'medium',
@@ -124,10 +120,12 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
124
120
  _this.setDownloadPopupVisible = _this.setDownloadPopupVisible.bind(_this);
125
121
  _this.neverShowInput = /*#__PURE__*/React.createRef(null);
126
122
  _this.setShowProperty = _this.setShowProperty.bind(_this);
123
+
124
+ // cache to avoid immutable merge allocations every render
125
+ _this._cachedViewer2DKey = null;
126
+ _this._cachedExtractedState = null;
127
127
  return _this;
128
128
  }
129
-
130
- // Toolbar control functions
131
129
  _inherits(LiteKitchenConfigurator, _Component);
132
130
  return _createClass(LiteKitchenConfigurator, [{
133
131
  key: "setToolbar",
@@ -211,26 +209,32 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
211
209
  }, {
212
210
  key: "openFloor",
213
211
  value: function openFloor() {
212
+ var _el$parentElement;
214
213
  this.setState({
215
214
  floorOpened: true
216
215
  });
217
- document.getElementById('make_floorplan_inactive').parentElement.parentElement.style.zIndex = 999;
216
+ var el = document.getElementById('make_floorplan_inactive');
217
+ el && ((_el$parentElement = el.parentElement) === null || _el$parentElement === void 0 ? void 0 : _el$parentElement.parentElement) && (el.parentElement.parentElement.style.zIndex = 999);
218
218
  }
219
219
  }, {
220
220
  key: "openCabinet",
221
221
  value: function openCabinet() {
222
+ var _el$parentElement2;
222
223
  this.setState({
223
224
  cabinetOpened: true
224
225
  });
225
- document.getElementById('add_cabinets_inactive').parentElement.parentElement.style.zIndex = 999;
226
+ var el = document.getElementById('add_cabinets_inactive');
227
+ el && ((_el$parentElement2 = el.parentElement) === null || _el$parentElement2 === void 0 ? void 0 : _el$parentElement2.parentElement) && (el.parentElement.parentElement.style.zIndex = 999);
226
228
  }
227
229
  }, {
228
230
  key: "toggleDoorStyle",
229
231
  value: function toggleDoorStyle(visible) {
232
+ var _el$parentElement3;
230
233
  this.setState({
231
234
  doorStyleOpen: visible
232
235
  });
233
- document.getElementById('select_doorstyle_inactive').parentElement.parentElement.style.zIndex = visible ? 999 : 6;
236
+ var el = document.getElementById('select_doorstyle_inactive');
237
+ el && ((_el$parentElement3 = el.parentElement) === null || _el$parentElement3 === void 0 ? void 0 : _el$parentElement3.parentElement) && (el.parentElement.parentElement.style.zIndex = visible ? 999 : 6);
234
238
  }
235
239
  }, {
236
240
  key: "replaceCabinet",
@@ -242,70 +246,72 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
242
246
  }, {
243
247
  key: "openAppliance",
244
248
  value: function openAppliance() {
249
+ var _el$parentElement4;
245
250
  this.setState({
246
251
  applianceOpened: true
247
252
  });
248
- document.getElementById('add_appliances_inactive').parentElement.parentElement.style.zIndex = 999;
253
+ var el = document.getElementById('add_appliances_inactive');
254
+ el && ((_el$parentElement4 = el.parentElement) === null || _el$parentElement4 === void 0 ? void 0 : _el$parentElement4.parentElement) && (el.parentElement.parentElement.style.zIndex = 999);
249
255
  }
250
256
  }, {
251
257
  key: "openFinishing",
252
258
  value: function openFinishing() {
259
+ var _el$parentElement5;
253
260
  this.setState({
254
261
  finishingOpened: true
255
262
  });
256
- document.getElementById('finishing_touches_inactive').parentElement.parentElement.style.zIndex = 999;
263
+ var el = document.getElementById('finishing_touches_inactive');
264
+ el && ((_el$parentElement5 = el.parentElement) === null || _el$parentElement5 === void 0 ? void 0 : _el$parentElement5.parentElement) && (el.parentElement.parentElement.style.zIndex = 999);
257
265
  }
258
266
  }, {
259
267
  key: "onReviewQuoteClicked",
260
268
  value: function onReviewQuoteClicked(visible) {
269
+ var _el$parentElement6;
261
270
  this.setState({
262
271
  reviewQuotePopupOpened: visible
263
272
  });
264
- document.getElementById('review_quote_inactive').parentElement.parentElement.style.zIndex = visible ? 999 : 6;
273
+ var el = document.getElementById('review_quote_inactive');
274
+ el && ((_el$parentElement6 = el.parentElement) === null || _el$parentElement6 === void 0 ? void 0 : _el$parentElement6.parentElement) && (el.parentElement.parentElement.style.zIndex = visible ? 999 : 6);
265
275
  }
266
276
  }, {
267
277
  key: "closeFloorTB",
268
278
  value: function closeFloorTB() {
279
+ var _el$parentElement7;
269
280
  this.setState({
270
281
  floorOpened: false
271
282
  });
272
- document.getElementById('make_floorplan_inactive') && (document.getElementById('make_floorplan_inactive').parentElement.parentElement.style.zIndex = 6);
283
+ var el = document.getElementById('make_floorplan_inactive');
284
+ el && ((_el$parentElement7 = el.parentElement) === null || _el$parentElement7 === void 0 ? void 0 : _el$parentElement7.parentElement) && (el.parentElement.parentElement.style.zIndex = 6);
273
285
  }
274
286
  }, {
275
287
  key: "closeCabinetTB",
276
288
  value: function closeCabinetTB() {
289
+ var _el$parentElement8;
277
290
  this.setState({
278
291
  cabinetOpened: false
279
292
  });
280
- document.getElementById('add_cabinets_inactive').parentElement.parentElement.style.zIndex = 6;
293
+ var el = document.getElementById('add_cabinets_inactive');
294
+ el && ((_el$parentElement8 = el.parentElement) === null || _el$parentElement8 === void 0 ? void 0 : _el$parentElement8.parentElement) && (el.parentElement.parentElement.style.zIndex = 6);
281
295
  }
282
296
  }, {
283
297
  key: "closeFinishingTB",
284
298
  value: function closeFinishingTB() {
299
+ var _el$parentElement9;
285
300
  this.setState({
286
301
  finishingOpened: false
287
302
  });
288
- document.getElementById('finishing_touches_inactive').parentElement.parentElement.style.zIndex = 6;
303
+ var el = document.getElementById('finishing_touches_inactive');
304
+ el && ((_el$parentElement9 = el.parentElement) === null || _el$parentElement9 === void 0 ? void 0 : _el$parentElement9.parentElement) && (el.parentElement.parentElement.style.zIndex = 6);
289
305
  }
290
306
  }, {
291
307
  key: "closeApplianceTB",
292
308
  value: function closeApplianceTB() {
309
+ var _el$parentElement0;
293
310
  this.setState({
294
311
  applianceOpened: false
295
312
  });
296
- document.getElementById('add_appliances_inactive').parentElement.parentElement.style.zIndex = 6;
297
- }
298
- }, {
299
- key: "closeDoorstyle",
300
- value: function closeDoorstyle() {
301
- this.setState({});
302
- document.getElementById('select_doorstyle_inactive').parentElement.parentElement.style.zIndex = 6;
303
- }
304
- }, {
305
- key: "closeReviewQuote",
306
- value: function closeReviewQuote() {
307
- this.setState({});
308
- document.getElementById('review_quote_inactive').parentElement.parentElement.style.zIndex = 6;
313
+ var el = document.getElementById('add_appliances_inactive');
314
+ el && ((_el$parentElement0 = el.parentElement) === null || _el$parentElement0 === void 0 ? void 0 : _el$parentElement0.parentElement) && (el.parentElement.parentElement.style.zIndex = 6);
309
315
  }
310
316
  }, {
311
317
  key: "getChildContext",
@@ -321,7 +327,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
321
327
  }, {
322
328
  key: "componentDidMount",
323
329
  value: function componentDidMount() {
324
- console.log('context =>', this.context);
325
330
  window.forRedo = [];
326
331
  var store = this.context.store;
327
332
  var _this$props = this.props,
@@ -333,21 +338,23 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
333
338
  });
334
339
  }
335
340
  }, {
336
- key: "componentWillReceiveProps",
337
- value: function componentWillReceiveProps(nextProps) {
338
- var stateExtractor = nextProps.stateExtractor,
339
- state = nextProps.state,
340
- projectActions = nextProps.projectActions,
341
- catalog = nextProps.catalog,
342
- externalEvent = nextProps.externalEvent,
343
- onInternalEvent = nextProps.onInternalEvent;
341
+ key: "componentDidUpdate",
342
+ value: function componentDidUpdate(prevProps) {
343
+ var _extractedState$getIn;
344
+ var _this$props2 = this.props,
345
+ externalEvent = _this$props2.externalEvent,
346
+ stateExtractor = _this$props2.stateExtractor,
347
+ extractedState = _this$props2.extractedState,
348
+ projectActions = _this$props2.projectActions,
349
+ catalog = _this$props2.catalog;
344
350
 
345
- // handle external events
346
- if (this.props.externalEvent !== externalEvent) {
347
- handleExternalEvent(nextProps);
351
+ // handle external events (same behavior as before)
352
+ if (prevProps.externalEvent !== externalEvent) {
353
+ handleExternalEvent(this.props);
348
354
  }
349
- var plannerState = stateExtractor(state);
350
- var catalogReady = plannerState.getIn(['catalog', 'ready']);
355
+
356
+ // init catalog once ready flag says not ready (same behavior)
357
+ var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn = extractedState.getIn) === null || _extractedState$getIn === void 0 ? void 0 : _extractedState$getIn.call(extractedState, ['catalog', 'ready']);
351
358
  if (!catalogReady) {
352
359
  projectActions.initCatalog(catalog);
353
360
  }
@@ -360,16 +367,55 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
360
367
  var layer = layers.get(selectedLayer);
361
368
  return layer.areas.size + layer.lines.size + layer.holes.size + layer.items.size === 0;
362
369
  }
370
+
371
+ // Compute viewer2D transform only when needed, and cache it.
372
+ // This preserves the exact visual result but avoids merge allocations every render.
373
+ }, {
374
+ key: "getExtractedStateWithViewer2DInit",
375
+ value: function getExtractedStateWithViewer2DInit(extractedState, width, height) {
376
+ if (!extractedState) return extractedState;
377
+ var _scene = extractedState.getIn(['scene']);
378
+ var len = convert(_scene.width).from(_scene.unit).to('cm');
379
+ var _viewer2D = extractedState.getIn(['viewer2D']);
380
+ if (!_viewer2D || _viewer2D.size <= 0) return extractedState;
381
+
382
+ // build a stable cache key based on inputs that affect the result
383
+ var v = _viewer2D.toJS();
384
+ 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);
385
+ if (this._cachedViewer2DKey === cacheKey && this._cachedExtractedState) {
386
+ return this._cachedExtractedState;
387
+ }
388
+
389
+ // your original logic
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
+
405
+ // no merge needed
406
+ this._cachedViewer2DKey = cacheKey;
407
+ this._cachedExtractedState = extractedState;
408
+ return extractedState;
409
+ }
363
410
  }, {
364
411
  key: "render",
365
412
  value: function render() {
366
- var _this$props2 = this.props,
367
- width = _this$props2.width,
368
- height = _this$props2.height,
369
- state = _this$props2.state,
370
- stateExtractor = _this$props2.stateExtractor,
371
- measurementUnit = _this$props2.measurementUnit,
372
- props = _objectWithoutProperties(_this$props2, _excluded);
413
+ var _this$props3 = this.props,
414
+ width = _this$props3.width,
415
+ height = _this$props3.height,
416
+ extractedState = _this$props3.extractedState,
417
+ measurementUnit = _this$props3.measurementUnit,
418
+ props = _objectWithoutProperties(_this$props3, _excluded);
373
419
  var _this$state = this.state,
374
420
  savePopupVisible = _this$state.savePopupVisible,
375
421
  quotePopupVisible = _this$state.quotePopupVisible,
@@ -377,40 +423,12 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
377
423
  signOpen = _this$state.signOpen,
378
424
  myProjectsOpen = _this$state.myProjectsOpen;
379
425
  var contentW = width - toolbarW;
380
- // let contentW = width - toolbarW - sidebarW;
381
- // let toolbarH = height - footerBarH;
382
- // let contentH = height - footerBarH;
383
- // let sidebarH = height - footerBarH;
384
- var toolbarH = height;
385
426
  var contentH = height;
386
- var sidebarH = height;
387
427
  var headerW = width;
388
428
  var headerH = 60;
389
- var extractedState = stateExtractor(state);
390
- var firstVisit = this.state.wizardStepOpend && this.isProjectEmpty(extractedState.scene);
429
+ var extracted = this.getExtractedStateWithViewer2DInit(extractedState, width, height);
430
+ var firstVisit = this.state.wizardStepOpend && this.isProjectEmpty(extracted.scene);
391
431
  var allVisible = firstVisit || signOpen || myProjectsOpen;
392
- var _scene = extractedState.getIn(['scene']);
393
- var len = convert(_scene.width).from(_scene.unit).to('cm');
394
- var _viewer2D = extractedState.getIn(['viewer2D']);
395
- if (_viewer2D.size > 0) {
396
- var scaleX = width / len * 3;
397
- var scaleY = height / len * 3;
398
- var scale = scaleX > scaleY ? scaleY : scaleX;
399
- var _e = width - len * scale,
400
- _f = height - len * scale;
401
- var viewer = _viewer2D.toJS();
402
- if (viewer.e === 0 && viewer.f === 0) {
403
- _viewer2D = _viewer2D.merge({
404
- e: viewer.viewerWidth / 2 - viewer.SVGWidth / 2,
405
- f: viewer.viewerHeight / 2 - viewer.SVGHeight / 2,
406
- a: 0.99,
407
- d: 0.99
408
- });
409
- }
410
- }
411
- extractedState = extractedState.merge({
412
- viewer2D: _viewer2D
413
- });
414
432
  return /*#__PURE__*/React.createElement("section", null, /*#__PURE__*/React.createElement("div", {
415
433
  style: _objectSpread(_objectSpread({}, wrapperStyle), {}, {
416
434
  height: height,
@@ -422,7 +440,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
422
440
  width: contentW,
423
441
  height: contentH,
424
442
  catalog: this.props.catalog,
425
- state: extractedState,
443
+ state: extracted,
426
444
  toolBar: this.state.toolbar,
427
445
  setToolbar: this.setToolbar,
428
446
  replaceCabinet: this.replaceCabinet,
@@ -464,7 +482,8 @@ LiteKitchenConfigurator.propTypes = {
464
482
  customContents: PropTypes.object,
465
483
  softwareSignature: PropTypes.string,
466
484
  configData: PropTypes.object,
467
- onInternalEvent: PropTypes.func
485
+ onInternalEvent: PropTypes.func,
486
+ extractedState: PropTypes.object // <-- new injected prop
468
487
  };
469
488
  LiteKitchenConfigurator.contextTypes = {
470
489
  store: PropTypes.object.isRequired
@@ -487,10 +506,14 @@ LiteKitchenConfigurator.defaultProps = {
487
506
  configData: {}
488
507
  };
489
508
 
490
- //redux connect
491
- function mapStateToProps(reduxState) {
509
+ // IMPORTANT: select only the extracted slice so top component doesn't rerender on every dispatch
510
+ function mapStateToProps(reduxState, ownProps) {
511
+ var stateExtractor = ownProps.stateExtractor || function (s) {
512
+ return s;
513
+ };
514
+ var extractedState = stateExtractor(reduxState);
492
515
  return {
493
- state: reduxState
516
+ extractedState: extractedState
494
517
  };
495
518
  }
496
519
  function mapDispatchToProps(dispatch) {