kitchen-simulator 5.10.14-react.18 → 6.0.1-react.18

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.
@@ -20,7 +20,8 @@ import React, { Component } from 'react';
20
20
  import { connect } from 'react-redux';
21
21
  import { bindActionCreators } from 'redux';
22
22
  import * as constants from "./constants";
23
- import actions from "./actions/export";
23
+ import { base64Decode } from "./utils/helper";
24
+ import actions, { projectActions } from "./actions/export";
24
25
  import Catalog from "./catalog/catalog";
25
26
  import { Content } from "./components/export";
26
27
  import Translator from "./translator/translator";
@@ -42,20 +43,6 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
42
43
  var _this;
43
44
  _classCallCheck(this, LiteKitchenConfigurator);
44
45
  _this = _callSuper(this, LiteKitchenConfigurator, [props]);
45
-
46
- // ---- guards / schedulers ----
47
- _this._catalogInitRequested = false;
48
- _this._lastHandledExternalEvent = null;
49
- _this._handlingExternalEvent = false;
50
- _this._scheduledExternalEventTimeout = null;
51
-
52
- // viewer2D init guard (prevents dispatch loops)
53
- _this._viewer2DInitKeyDone = null;
54
-
55
- // cache for viewer2D init (no merging in render)
56
- _this._lastExtractedStateRef = null;
57
- _this._cachedViewer2DKey = null;
58
- _this._cachedExtractedState = null;
59
46
  _this.state = {
60
47
  savePopupVisible: false,
61
48
  quotePopupVisible: false,
@@ -88,6 +75,7 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
88
75
  isSaved: false,
89
76
  isLeaving: false
90
77
  };
78
+ _this._catalogInitRequested = false;
91
79
  _this.openFloor = _this.openFloor.bind(_this);
92
80
  _this.openCabinet = _this.openCabinet.bind(_this);
93
81
  _this.openFinishing = _this.openFinishing.bind(_this);
@@ -107,10 +95,13 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
107
95
  _this.setDownloadPopupVisible = _this.setDownloadPopupVisible.bind(_this);
108
96
  _this.neverShowInput = /*#__PURE__*/React.createRef(null);
109
97
  _this.setShowProperty = _this.setShowProperty.bind(_this);
98
+
99
+ // cache for viewer2D init so we don't allocate merges every render
100
+ _this._lastExtractedStateRef = null;
101
+ _this._cachedViewer2DKey = null;
102
+ _this._cachedExtractedState = null;
110
103
  return _this;
111
104
  }
112
-
113
- // ---------------- UI setters (unchanged) ----------------
114
105
  _inherits(LiteKitchenConfigurator, _Component);
115
106
  return _createClass(LiteKitchenConfigurator, [{
116
107
  key: "setToolbar",
@@ -298,154 +289,92 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
298
289
  var el = document.getElementById('add_appliances_inactive');
299
290
  if (el !== null && el !== void 0 && (_el$parentElement0 = el.parentElement) !== null && _el$parentElement0 !== void 0 && _el$parentElement0.parentElement) el.parentElement.parentElement.style.zIndex = 6;
300
291
  }
301
-
302
- // ---------------- viewer2D init (SAFE, guarded) ----------------
303
- }, {
304
- key: "maybeInitViewer2D",
305
- value: function maybeInitViewer2D(extractedState, width, height) {
306
- var _extractedState$getIn;
307
- var viewer2DActions = this.props.viewer2DActions;
308
- var viewer2D = extractedState === null || extractedState === void 0 || (_extractedState$getIn = extractedState.getIn) === null || _extractedState$getIn === void 0 ? void 0 : _extractedState$getIn.call(extractedState, ['viewer2D']);
309
- if (!viewer2D || viewer2D.size <= 0) return;
310
- var v = viewer2D.toJS();
311
- if (!v) return;
312
-
313
- // Only init when e/f are exactly zero
314
- if (v.e !== 0 || v.f !== 0) return;
315
- var key = "".concat(width, ":").concat(height, ":").concat(v.viewerWidth, ":").concat(v.viewerHeight, ":").concat(v.SVGWidth, ":").concat(v.SVGHeight);
316
-
317
- // ✅ prevent dispatch loop: do it once per signature
318
- if (this._viewer2DInitKeyDone === key) return;
319
- this._viewer2DInitKeyDone = key;
320
- var payload = {
321
- e: v.viewerWidth / 2 - v.SVGWidth / 2,
322
- f: v.viewerHeight / 2 - v.SVGHeight / 2,
323
- a: 0.99,
324
- d: 0.99
325
- };
326
- viewer2DActions.updateViewer2D(payload);
327
- }
328
292
  }, {
329
293
  key: "componentDidMount",
330
294
  value: function componentDidMount() {
331
- var _extractedState$getIn2;
295
+ var _extractedState$getIn;
296
+ window.forRedo = [];
332
297
  var _this$props = this.props,
333
298
  catalog = _this$props.catalog,
334
299
  extractedState = _this$props.extractedState,
335
- projectActions = _this$props.projectActions,
336
- width = _this$props.width,
337
- height = _this$props.height;
338
-
339
- // init catalog once
340
- var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn2 = extractedState.getIn) === null || _extractedState$getIn2 === void 0 ? void 0 : _extractedState$getIn2.call(extractedState, ['catalog', 'ready']);
300
+ projectActions = _this$props.projectActions;
301
+ var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn = extractedState.getIn) === null || _extractedState$getIn === void 0 ? void 0 : _extractedState$getIn.call(extractedState, ['catalog', 'ready']);
341
302
  if (!catalogReady && !this._catalogInitRequested) {
342
303
  this._catalogInitRequested = true;
343
- console.log('[LiteKitchenConfigurator] initCatalog (mount)');
344
304
  projectActions.initCatalog(catalog);
345
305
  }
346
-
347
- // viewer2D init (safe)
348
- this.maybeInitViewer2D(extractedState, width, height);
349
306
  }
350
307
  }, {
351
308
  key: "componentDidUpdate",
352
309
  value: function componentDidUpdate(prevProps) {
353
- var _this2 = this,
354
- _extractedState$getIn3;
310
+ var _extractedState$getIn2;
355
311
  var _this$props2 = this.props,
356
312
  externalEvent = _this$props2.externalEvent,
357
313
  extractedState = _this$props2.extractedState,
358
314
  projectActions = _this$props2.projectActions,
359
- catalog = _this$props2.catalog,
360
- width = _this$props2.width,
361
- height = _this$props2.height;
315
+ catalog = _this$props2.catalog;
362
316
 
363
- // viewer2D init only when relevant inputs change
364
- if (prevProps.extractedState !== extractedState || prevProps.width !== width || prevProps.height !== height) {
365
- this.maybeInitViewer2D(extractedState, width, height);
366
- }
367
-
368
- // ---- (A) External event handling (defer OUTSIDE RAF) ----
317
+ // handle external event when it changes
369
318
  if (prevProps.externalEvent !== externalEvent && externalEvent) {
370
- if (this._lastHandledExternalEvent === externalEvent) {
371
- console.warn('[LiteKitchenConfigurator] externalEvent already handled (same ref), skipping');
372
- } else if (this._handlingExternalEvent) {
373
- console.warn('[LiteKitchenConfigurator] externalEvent handling already in progress, skipping');
374
- } else {
375
- this._lastHandledExternalEvent = externalEvent;
376
- this._handlingExternalEvent = true;
377
- var propsSnapshot = this.props;
378
- var type = (externalEvent === null || externalEvent === void 0 ? void 0 : externalEvent.type) || 'unknown';
379
- if (this._scheduledExternalEventTimeout) {
380
- clearTimeout(this._scheduledExternalEventTimeout);
381
- this._scheduledExternalEventTimeout = null;
382
- }
383
- this._scheduledExternalEventTimeout = setTimeout(function () {
384
- _this2._scheduledExternalEventTimeout = null;
385
- console.time("[handleExternalEvent] ".concat(type));
386
- try {
387
- handleExternalEvent(propsSnapshot);
388
- } catch (e) {
389
- console.error('[LiteKitchenConfigurator] handleExternalEvent crashed', e);
390
- } finally {
391
- console.timeEnd("[handleExternalEvent] ".concat(type));
392
- _this2._handlingExternalEvent = false;
393
- }
394
- }, 0);
395
- }
319
+ handleExternalEvent(this.props);
396
320
  }
397
-
398
- // ---- (B) initCatalog: request once until ready ----
399
- var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn3 = extractedState.getIn) === null || _extractedState$getIn3 === void 0 ? void 0 : _extractedState$getIn3.call(extractedState, ['catalog', 'ready']);
321
+ var catalogReady = extractedState === null || extractedState === void 0 || (_extractedState$getIn2 = extractedState.getIn) === null || _extractedState$getIn2 === void 0 ? void 0 : _extractedState$getIn2.call(extractedState, ['catalog', 'ready']);
400
322
  if (catalogReady) {
401
- if (this._catalogInitRequested) console.log('[LiteKitchenConfigurator] catalog ready');
402
- this._catalogInitRequested = false;
403
- } else {
404
- if (!this._catalogInitRequested) {
405
- this._catalogInitRequested = true;
406
- console.log('[LiteKitchenConfigurator] initCatalog (update)');
407
- projectActions.initCatalog(catalog);
408
- }
323
+ this._catalogInitRequested = false; // allow re-init if state resets later
324
+ } else if (!this._catalogInitRequested) {
325
+ this._catalogInitRequested = true;
326
+ projectActions.initCatalog(catalog);
409
327
  }
410
328
  }
411
329
  }, {
412
- key: "componentWillUnmount",
413
- value: function componentWillUnmount() {
414
- if (this._scheduledExternalEventTimeout) {
415
- clearTimeout(this._scheduledExternalEventTimeout);
416
- this._scheduledExternalEventTimeout = null;
417
- }
330
+ key: "isProjectEmpty",
331
+ value: function isProjectEmpty(scene) {
332
+ var layers = scene.layers,
333
+ selectedLayer = scene.selectedLayer;
334
+ var layer = layers.get(selectedLayer);
335
+ return layer.areas.size + layer.lines.size + layer.holes.size + layer.items.size === 0;
418
336
  }
419
-
420
- // ✅ IMPORTANT: do NOT mutate/merge redux state in render
421
337
  }, {
422
338
  key: "getExtractedStateWithViewer2DInit",
423
339
  value: function getExtractedStateWithViewer2DInit(extractedState, width, height) {
424
340
  if (!extractedState) return extractedState;
341
+
342
+ // ✅ If the extractedState reference changed, drop cache immediately.
425
343
  if (this._lastExtractedStateRef !== extractedState) {
426
344
  this._lastExtractedStateRef = extractedState;
427
345
  this._cachedViewer2DKey = null;
428
346
  this._cachedExtractedState = null;
429
347
  }
430
- var viewer2D = extractedState.getIn(['viewer2D']);
431
- if (!viewer2D || viewer2D.size <= 0) return extractedState;
432
- var v = viewer2D.toJS();
433
- if (!v) return extractedState;
434
- if (v.e !== 0 || v.f !== 0) return extractedState;
435
-
436
- // Keep cache (doesn't change state), mostly no-op now
437
- var cacheKey = "".concat(width, ":").concat(height, ":").concat(v.viewerWidth, ":").concat(v.viewerHeight, ":").concat(v.SVGWidth, ":").concat(v.SVGHeight);
348
+ var _viewer2D = extractedState.getIn(['viewer2D']);
349
+ if (!_viewer2D || _viewer2D.size <= 0) return extractedState;
350
+ var e = _viewer2D.get('e');
351
+ var f = _viewer2D.get('f');
352
+ if (e !== 0 || f !== 0) return extractedState;
353
+ var viewerWidth = _viewer2D.get('viewerWidth');
354
+ var viewerHeight = _viewer2D.get('viewerHeight');
355
+ var SVGWidth = _viewer2D.get('SVGWidth');
356
+ var SVGHeight = _viewer2D.get('SVGHeight');
357
+ var cacheKey = "".concat(width, ":").concat(height, ":").concat(viewerWidth, ":").concat(viewerHeight, ":").concat(SVGWidth, ":").concat(SVGHeight);
438
358
  if (this._cachedViewer2DKey === cacheKey && this._cachedExtractedState) {
439
359
  return this._cachedExtractedState;
440
360
  }
361
+ var centeredViewer2D = _viewer2D.merge({
362
+ e: viewerWidth / 2 - SVGWidth / 2,
363
+ f: viewerHeight / 2 - SVGHeight / 2,
364
+ a: 0.99,
365
+ d: 0.99
366
+ });
367
+ var merged = extractedState.merge({
368
+ viewer2D: centeredViewer2D
369
+ });
441
370
  this._cachedViewer2DKey = cacheKey;
442
- this._cachedExtractedState = extractedState;
443
- return extractedState;
371
+ this._cachedExtractedState = merged;
372
+ return merged;
444
373
  }
445
374
  }, {
446
375
  key: "render",
447
376
  value: function render() {
448
- var _this3 = this;
377
+ var _this2 = this;
449
378
  var _this$props3 = this.props,
450
379
  width = _this$props3.width,
451
380
  height = _this$props3.height,
@@ -454,12 +383,14 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
454
383
  var _this$state = this.state,
455
384
  savePopupVisible = _this$state.savePopupVisible,
456
385
  quotePopupVisible = _this$state.quotePopupVisible,
457
- assistPopupVisible = _this$state.assistPopupVisible;
386
+ assistPopupVisible = _this$state.assistPopupVisible,
387
+ signOpen = _this$state.signOpen,
388
+ myProjectsOpen = _this$state.myProjectsOpen;
458
389
  var contentW = width - toolbarW;
459
390
  var contentH = height;
460
391
  var extracted = this.getExtractedStateWithViewer2DInit(extractedState, width, height);
461
392
  var ctxValue = _objectSpread(_objectSpread({}, objectsMap(actions, function (actionNamespace) {
462
- return _this3.props[actionNamespace];
393
+ return _this2.props[actionNamespace];
463
394
  })), {}, {
464
395
  translator: this.props.translator,
465
396
  catalog: this.props.catalog
@@ -517,6 +448,7 @@ LiteKitchenConfigurator.propTypes = {
517
448
  configData: PropTypes.object,
518
449
  onInternalEvent: PropTypes.func,
519
450
  extractedState: PropTypes.object,
451
+ // ✅ injected by connect
520
452
  externalEvent: PropTypes.object
521
453
  };
522
454
  LiteKitchenConfigurator.defaultProps = {
@@ -530,6 +462,9 @@ LiteKitchenConfigurator.defaultProps = {
530
462
  customContents: {},
531
463
  configData: {}
532
464
  };
465
+
466
+ // ✅ Only select the slice you actually use.
467
+ // This preserves behavior but massively reduces rerenders.
533
468
  function mapStateToProps(reduxState, ownProps) {
534
469
  var stateExtractor = ownProps.stateExtractor || function (s) {
535
470
  return s;
@@ -25,6 +25,7 @@ import * as THREE from 'three';
25
25
  import * as Models from "./models";
26
26
  import { State } from "./models";
27
27
  import PlannerReducer from "./reducers/reducer";
28
+ import AppContext from "./AppContext";
28
29
  import Catalog from "./catalog/catalog";
29
30
  import * as Areas from "./catalog/areas/area/planner-element";
30
31
  import * as Lines from "./catalog/lines/wall/planner-element";
@@ -1,4 +1,4 @@
1
- import { UPDATE_CEIL_HEIGHT_UNIT, UPDATE_CEIL_HEIGHT, UPDATE_2D_CAMERA, SELECT_TOOL_PAN, SELECT_TOOL_ZOOM_IN, SELECT_TOOL_ZOOM_OUT, CHANGE_WALL_LENGTH_MEASURE, CHANGE_BASE_CABINET_MEASURE, CHANGE_WALL_CABINET_MEASURE, CHANGE_WINDOW_DOOR_MEASURE, UPDATE_VIEWER2D } from "../constants";
1
+ import { UPDATE_CEIL_HEIGHT_UNIT, UPDATE_CEIL_HEIGHT, UPDATE_2D_CAMERA, SELECT_TOOL_PAN, SELECT_TOOL_ZOOM_IN, SELECT_TOOL_ZOOM_OUT, CHANGE_WALL_LENGTH_MEASURE, CHANGE_BASE_CABINET_MEASURE, CHANGE_WALL_CABINET_MEASURE, CHANGE_WINDOW_DOOR_MEASURE } from "../constants";
2
2
  export function updateCeilHeight(value) {
3
3
  return {
4
4
  type: UPDATE_CEIL_HEIGHT,
@@ -55,10 +55,4 @@ export function selectToolZoomIn() {
55
55
  return {
56
56
  type: SELECT_TOOL_ZOOM_IN
57
57
  };
58
- }
59
- export function updateViewer2D(viewer2D) {
60
- return {
61
- type: UPDATE_VIEWER2D,
62
- viewer2D: viewer2D
63
- };
64
58
  }
package/es/constants.js CHANGED
@@ -12,7 +12,6 @@ export var NEW_PROJECT = 'NEW_PROJECT';
12
12
  export var LOAD_PROJECT = 'LOAD_PROJECT';
13
13
  export var SAVE_PROJECT = 'SAVE_PROJECT';
14
14
  export var OPEN_CATALOG = 'OPEN_CATALOG';
15
- export var UPDATE_VIEWER2D = 'UPDATE_VIEWER2D';
16
15
  export var SELECT_TOOL_EDIT = 'SELECT_TOOL_EDIT';
17
16
  export var UNSELECT_ALL = 'UNSELECT_ALL';
18
17
  export var SELECT_ALL = 'SELECT_ALL';