kitchen-simulator 3.1.15 → 3.3.0

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.
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
3
  import _typeof from "@babel/runtime/helpers/esm/typeof";
3
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
@@ -481,59 +482,116 @@ function addItemToCatalog(_x5, _x6, _x7, _x8) {
481
482
  } // Get attributs of current selected element
482
483
  function _addItemToCatalog() {
483
484
  _addItemToCatalog = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(element, state, catalogInstance, projectActions) {
484
- var _element, _element2;
485
- var elementJs, catalog, outlineSVGData, _element$structure_js, _element$structure_js2, _element$structure_js3, updatedStructureJson;
485
+ var _elementJs, _elementJs3;
486
+ var elementJs, outlineSVGData, _state$getIn, _elementJs$structure_, _elementJs$structure_2, _elementJs$structure_3, cds, _cds$find, _elementJs2, currentCdsId, cdsIdx, ttph, updatedStructureJson, catalogElements, catalogElementKeys, catalogItem, k, _catalogElements$cata, tempPlaceholderArray, _catalogItem$structur, newTempPlaceholderArray, mergedTempPlaceholder;
486
487
  return _regeneratorRuntime.wrap(function (_context5) {
487
488
  while (1) switch (_context5.prev = _context5.next) {
488
489
  case 0:
489
- if (!isEmpty((_element = element) === null || _element === void 0 ? void 0 : _element.name)) {
490
+ if (!isEmpty(element === null || element === void 0 ? void 0 : element.name)) {
490
491
  _context5.next = 1;
491
492
  break;
492
493
  }
493
494
  return _context5.abrupt("return");
494
495
  case 1:
495
- elementJs = element;
496
- catalog = state.getIn(['catalog']).toJS(); // add item to catalog of state
497
- // if (isEmpty(catalog?.elements[element.name])) {
496
+ // clone element
497
+ elementJs = Object.assign({}, element); // if (isEmpty(catalog?.elements[element.name])) {
498
498
  _context5.next = 2;
499
- return loadSVGsByItem(element);
499
+ return loadSVGsByItem(elementJs);
500
500
  case 2:
501
501
  outlineSVGData = _context5.sent;
502
- if (!(((_element2 = element) === null || _element2 === void 0 ? void 0 : _element2.type) === 'cabinet')) {
502
+ if (!(((_elementJs = elementJs) === null || _elementJs === void 0 ? void 0 : _elementJs.type) === 'cabinet')) {
503
503
  _context5.next = 4;
504
504
  break;
505
505
  }
506
+ // move the tempPlaceholder of current door style to first of tempPlaceholders array
507
+ cds = (_state$getIn = state.getIn(['scene', 'layers', 'layer-1', 'doorStyle'])) === null || _state$getIn === void 0 ? void 0 : _state$getIn.cds;
508
+ if (cds) {
509
+ currentCdsId = (_cds$find = cds.find(function (c) {
510
+ return c.itemID === elementJs.itemID;
511
+ })) === null || _cds$find === void 0 ? void 0 : _cds$find.cabinet_door_style_id;
512
+ cdsIdx = (_elementJs2 = elementJs) === null || _elementJs2 === void 0 || (_elementJs2 = _elementJs2.structure_json) === null || _elementJs2 === void 0 || (_elementJs2 = _elementJs2.tempPlaceholders) === null || _elementJs2 === void 0 ? void 0 : _elementJs2.findIndex(function (tph) {
513
+ return tph.id === currentCdsId;
514
+ }); // swap
515
+ if (currentCdsId && cdsIdx >= 0) {
516
+ ttph = elementJs.structure_json.tempPlaceholders[0];
517
+ elementJs.structure_json.tempPlaceholders[0] = elementJs.structure_json.tempPlaceholders[cdsIdx];
518
+ elementJs.structure_json.tempPlaceholders[cdsIdx] = ttph;
519
+ }
520
+ }
506
521
  // make placeholders of element and tempPlaceholder
507
- updatedStructureJson = _objectSpread(_objectSpread({}, element.structure_json), (_element$structure_js = (_element$structure_js2 = element.structure_json) === null || _element$structure_js2 === void 0 || (_element$structure_js2 = _element$structure_js2.tempPlaceholders[0]) === null || _element$structure_js2 === void 0 ? void 0 : _element$structure_js2.structure) !== null && _element$structure_js !== void 0 ? _element$structure_js : {});
508
- element.structure_json = updatedStructureJson;
509
- element = _objectSpread(_objectSpread({}, element), {}, {
522
+ updatedStructureJson = _objectSpread(_objectSpread({}, elementJs.structure_json), (_elementJs$structure_ = (_elementJs$structure_2 = elementJs.structure_json) === null || _elementJs$structure_2 === void 0 || (_elementJs$structure_2 = _elementJs$structure_2.tempPlaceholders[0]) === null || _elementJs$structure_2 === void 0 ? void 0 : _elementJs$structure_2.structure) !== null && _elementJs$structure_ !== void 0 ? _elementJs$structure_ : {});
523
+ elementJs.structure_json = updatedStructureJson;
524
+ elementJs = _objectSpread(_objectSpread({}, elementJs), {}, {
510
525
  cds: {
511
- data: [_objectSpread({}, element.customer_property)],
512
- itemID: element.itemID
526
+ data: [_objectSpread({}, elementJs.customer_property)],
527
+ itemID: elementJs.itemID
513
528
  }
514
529
  });
515
- if (isEmpty((_element$structure_js3 = element.structure_json) === null || _element$structure_js3 === void 0 ? void 0 : _element$structure_js3.tempPlaceholders)) {
530
+ if (isEmpty((_elementJs$structure_3 = elementJs.structure_json) === null || _elementJs$structure_3 === void 0 ? void 0 : _elementJs$structure_3.tempPlaceholders)) {
516
531
  _context5.next = 4;
517
532
  break;
518
533
  }
519
534
  _context5.next = 3;
520
- return updateCabinetPayload(element);
535
+ return updateCabinetPayload(elementJs);
521
536
  case 3:
522
537
  elementJs = _context5.sent;
523
538
  case 4:
524
539
  elementJs = _objectSpread(_objectSpread({}, elementJs), {}, {
525
540
  outlineSVGData: outlineSVGData,
526
- type: element.type,
541
+ type: elementJs.type,
527
542
  render2DItem: render2DItem
528
543
  });
529
- if (element.type === 'appliance' || element.type === 'furnishing') elementJs.render3DItem = render3DApplianceItem;else if (element.type === 'lighting') elementJs.render3DItem = render3DLightingItem;else elementJs.render3DItem = render3DItem;
544
+ if (elementJs.type === 'appliance' || elementJs.type === 'furnishing') elementJs.render3DItem = render3DApplianceItem;else if (elementJs.type === 'lighting') elementJs.render3DItem = render3DLightingItem;else elementJs.render3DItem = render3DItem;
545
+
546
+ /***** join new tempPlaceholder to the old element - start *****/
547
+ // get catalog item by itemID
548
+ catalogElements = state.getIn(['catalog', 'elements']).toJS();
549
+ catalogElementKeys = Object.keys(catalogElements);
550
+ catalogItem = null;
551
+ k = 0;
552
+ case 5:
553
+ if (!(k < catalogElementKeys.length)) {
554
+ _context5.next = 7;
555
+ break;
556
+ }
557
+ if (!(((_catalogElements$cata = catalogElements[catalogElementKeys[k]]) === null || _catalogElements$cata === void 0 ? void 0 : _catalogElements$cata.itemID) === elementJs.itemID)) {
558
+ _context5.next = 6;
559
+ break;
560
+ }
561
+ catalogItem = catalogElements[catalogElementKeys[k]];
562
+ return _context5.abrupt("continue", 7);
563
+ case 6:
564
+ k++;
565
+ _context5.next = 5;
566
+ break;
567
+ case 7:
568
+ // get old tempPlaceholder array from catalog item
569
+ tempPlaceholderArray = null;
570
+ if (!isEmpty(catalogItem)) {
571
+ tempPlaceholderArray = (_catalogItem$structur = catalogItem.structure_json) === null || _catalogItem$structur === void 0 ? void 0 : _catalogItem$structur.tempPlaceholders;
572
+ }
573
+
574
+ // join new tempPlaceholder array to old one
575
+ newTempPlaceholderArray = [];
576
+ (_elementJs3 = elementJs) === null || _elementJs3 === void 0 || (_elementJs3 = _elementJs3.structure_json) === null || _elementJs3 === void 0 || (_elementJs3 = _elementJs3.tempPlaceholders) === null || _elementJs3 === void 0 || _elementJs3.forEach(function (tph) {
577
+ var _tempPlaceholderArray;
578
+ if (!((_tempPlaceholderArray = tempPlaceholderArray) !== null && _tempPlaceholderArray !== void 0 && _tempPlaceholderArray.some(function (otph) {
579
+ return otph.id === tph.id;
580
+ }))) newTempPlaceholderArray.push(tph);
581
+ });
582
+ mergedTempPlaceholder = null;
583
+ if (isEmpty(tempPlaceholderArray)) mergedTempPlaceholder = newTempPlaceholderArray;else if (isEmpty(newTempPlaceholderArray)) mergedTempPlaceholder = tempPlaceholderArray;else mergedTempPlaceholder = [].concat(_toConsumableArray(tempPlaceholderArray), newTempPlaceholderArray);
584
+
585
+ // rplace new array to the elementJS
586
+ if (!isEmpty(mergedTempPlaceholder)) elementJs.structure_json.tempPlaceholders = mergedTempPlaceholder;
587
+ /***** join new tempPlaceholder to the old element - end *****/
588
+
530
589
  elementJs = exporter(elementJs);
531
590
  if (catalogInstance !== null && catalogInstance !== void 0 && catalogInstance.validateElement(elementJs)) {
532
591
  catalogInstance.registerElement(elementJs);
533
592
  projectActions.addElementToCatalog(elementJs);
534
593
  }
535
- // }
536
- case 5:
594
+ case 8:
537
595
  case "end":
538
596
  return _context5.stop();
539
597
  }
@@ -722,11 +780,11 @@ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, ca
722
780
  attributesFormData = attributesFormData.set('y', yVal);
723
781
  } else {
724
782
  attributesFormData = attributesFormData.set(attributeName, value);
725
- // update the distances from wall
726
- var _GeometryUtils$calcDi = GeometryUtils.calcDistancesFromItemToWalls(attributesFormData, layer),
727
- PointArray = _GeometryUtils$calcDi.PointArray;
728
- attributesFormData = attributesFormData.set('distArray', PointArray);
729
783
  }
784
+ // update the distances from wall
785
+ var _GeometryUtils$calcDi = GeometryUtils.calcDistancesFromItemToWalls(attributesFormData, layer),
786
+ PointArray = _GeometryUtils$calcDi.PointArray;
787
+ attributesFormData = attributesFormData.set('distArray', PointArray);
730
788
  break;
731
789
  }
732
790
  case 'lines':
@@ -1093,7 +1151,7 @@ export function handleExternalEvent(_x10) {
1093
1151
  function _handleExternalEvent() {
1094
1152
  _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(props) {
1095
1153
  var _evt$payload3, _evt$payload4;
1096
- var evt, state, layerId, layer, _evt$payload, cdsItems, itemKeys, _loop3, i, _props$onInternalEven, sLineCnt, _state$getIn, element, cds, _cds$find, currentCdsId, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, defaulTitle, _Object$keys, _evt$payload5, doorStyle, itemCDS, isAll, _layerId, _cdsItems, allItems, selectedItemId, _itemKeys, _loop4, _i2, _props$onInternalEven2, _evt$payload6, roomShapeType, width, height, _doorStyle, value, _value, _evt$payload7, moldingInfo, isGlobal, distElement, _distElement, _evt$payload8, option, _value2, _layerId2, _layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i4, _i5, _i6, _evt$payload9, _evt$payload0, _evt$payload1, _evt$payload10, _layerID, _layer2, orginalItemInfo, originalItem, originalItemPos, replaceItem, _props$onInternalEven3, sceneData, currentTexture, _t5, _t6;
1154
+ var evt, state, layerId, layer, _evt$payload, cdsItems, itemKeys, _loop3, i, _props$onInternalEven, sLineCnt, element, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, defaulTitle, _Object$keys, _evt$payload5, doorStyle, itemCDS, isAll, _layerId, _cdsItems, allItems, selectedItemId, _itemKeys, _loop4, _i2, _props$onInternalEven2, _evt$payload6, roomShapeType, width, height, _doorStyle, value, _value, _evt$payload7, moldingInfo, isGlobal, distElement, _distElement, _evt$payload8, option, _value2, _layerId2, _layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i4, _i5, _i6, _evt$payload9, _evt$payload0, _evt$payload1, _evt$payload10, _layerID, _layer2, orginalItemInfo, originalItem, originalItemPos, replaceItem, _props$onInternalEven3, sceneData, currentTexture, _t5, _t6;
1097
1155
  return _regeneratorRuntime.wrap(function (_context1) {
1098
1156
  while (1) switch (_context1.prev = _context1.next) {
1099
1157
  case 0:
@@ -1210,19 +1268,7 @@ function _handleExternalEvent() {
1210
1268
  _context1.next = 11;
1211
1269
  break;
1212
1270
  }
1213
- element = evt.payload; ///// filter the tempPlaceholders using layer-doorstyle-cds
1214
- cds = (_state$getIn = state.getIn(['scene', 'layers', 'layer-1', 'doorStyle'])) === null || _state$getIn === void 0 ? void 0 : _state$getIn.cds;
1215
- if (cds) {
1216
- currentCdsId = (_cds$find = cds.find(function (c) {
1217
- return c.itemID === element.itemID;
1218
- })) === null || _cds$find === void 0 ? void 0 : _cds$find.cabinet_door_style_id;
1219
- if (currentCdsId && element.structure_json.tempPlaceholders.length > 0) {
1220
- element.structure_json.tempPlaceholders[0] = element.structure_json.tempPlaceholders.find(function (tPlaceholder) {
1221
- return tPlaceholder.id === currentCdsId;
1222
- });
1223
- }
1224
- }
1225
- /////
1271
+ element = evt.payload;
1226
1272
  _context1.next = 10;
1227
1273
  return addItemToCatalog(element, state, props.catalog, props.projectActions);
1228
1274
  case 10:
@@ -144,6 +144,7 @@ function _default(_ref) {
144
144
  img: base,
145
145
  obj: obj_property,
146
146
  cds: cds,
147
+ structure_json: structure_json,
147
148
  render2D: function render2D(element, layer, scene) {
148
149
  return render2DItem.call(this, element, layer, scene, sizeinfo, layoutpos, is_corner, shape_svg);
149
150
  },
@@ -222,6 +222,31 @@ function createWarningObject() {
222
222
  warningObj.name = 'warningObj';
223
223
  return warningObj;
224
224
  }
225
+ function swapLengthProperty(diffs) {
226
+ var idx1 = diffs.findIndex(function (v) {
227
+ return v.path[v.path.length - 1] === 'length';
228
+ });
229
+ var idx2 = diffs.findIndex(function (v) {
230
+ return v.path[v.path.length - 1] === '_length';
231
+ });
232
+ if (idx1 < 0 || idx2 < 0) return diffs;
233
+ if (idx1 > idx2) return diffs;
234
+ if (diffs[idx1].op === diffs[idx2].op) {
235
+ var isSwap = true;
236
+ for (var i = 0; i < diffs[idx1].path.length - 2; i++) {
237
+ if (diffs[idx1].path[i] !== diffs[idx2].path[i]) {
238
+ isSwap = false;
239
+ break;
240
+ }
241
+ }
242
+ if (isSwap) {
243
+ var temp = diffs[idx1];
244
+ diffs[idx1] = diffs[idx2];
245
+ diffs[idx2] = temp;
246
+ }
247
+ }
248
+ return diffs;
249
+ }
225
250
  function updateScene(planData, sceneData, oldSceneData, diffArray, actions, catalog) {
226
251
  var _draggingItem$toJS, _filteredDiffs, _filteredDiffs2;
227
252
  var mode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
@@ -239,6 +264,9 @@ function updateScene(planData, sceneData, oldSceneData, diffArray, actions, cata
239
264
  value: el.value
240
265
  };
241
266
  });
267
+
268
+ // move "length" to after "_length"
269
+ splitted = swapLengthProperty(splitted);
242
270
  var filteredDiffs = filterDiffs(splitted, sceneData, oldSceneData);
243
271
  //***testing additional filter***
244
272
  filteredDiffs = filteredDiffs.filter(function (_ref) {
@@ -3453,9 +3481,11 @@ function updateMoldingGroupArray(MGArray, selItem, planData, layer) {
3453
3481
  // refresh mesh of the updating molding groups
3454
3482
  new_MGArray.forEach(function (mg, index) {
3455
3483
  if (mg.items[0].molding.some(function (mol) {
3456
- return mol.location_type === mg.location_type;
3484
+ return (0, _helper.isImmutable)(mol) ? mol.toJS().location_type === mg.location_type : mol.location_type === mg.location_type;
3457
3485
  })) {
3458
- var molding = mg.items[0].molding.filter(function (mol) {
3486
+ var molding = (0, _helper.isImmutable)(mg.items[0].molding) ? mg.items[0].molding.filter(function (mol) {
3487
+ return mol.toJS().location_type === mg.location_type;
3488
+ }).toJS()[0] : mg.items[0].molding.filter(function (mol) {
3459
3489
  return mol.location_type === mg.location_type;
3460
3490
  })[0];
3461
3491
  if (mg.molding === null || mg.molding.itemID !== mol.itemID || mg.lines === null || mg.points === null) {
@@ -1496,8 +1496,8 @@ var Scene3DViewer = exports["default"] = /*#__PURE__*/function (_React$Component
1496
1496
  }
1497
1497
  gridMatrix.copy(gridPlane.matrixWorld).invert();
1498
1498
  var addItemToolObj = function addItemToolObj() {
1499
- var _intersects$_i;
1500
- var selectedItem = planData.sceneGraph.layers[selectedObject.layerID].items[selectedObject.itemID];
1499
+ var _planData$sceneGraph, _selectedObject, _intersects$_i;
1500
+ var selectedItem = (_planData$sceneGraph = planData.sceneGraph) === null || _planData$sceneGraph === void 0 || (_planData$sceneGraph = _planData$sceneGraph.layers[selectedObject.layerID]) === null || _planData$sceneGraph === void 0 ? void 0 : _planData$sceneGraph.items[(_selectedObject = selectedObject) === null || _selectedObject === void 0 ? void 0 : _selectedObject.itemID];
1501
1501
  if ((0, _util.isUndefined)(selectedItem)) return;
1502
1502
  selectedElement = _this2.props.state.scene.layers.get(selectedObject.layerID).items.get(selectedObject.itemID);
1503
1503
  var itemPos = selectedItem.position.clone();
@@ -1598,6 +1598,7 @@ var Scene3DViewer = exports["default"] = /*#__PURE__*/function (_React$Component
1598
1598
  selectedObj = allItemRect.cur;
1599
1599
  }
1600
1600
  } else {
1601
+ var _planData$sceneGraph2, _selectedObject2, _selectedObject3;
1601
1602
  (0, _sceneCreator.visibleTransformBox)(false);
1602
1603
  var alti = 0;
1603
1604
  if (allItemRect && allItemRect.cur && allItemRect.cur.itemInfo !== undefined) {
@@ -1607,16 +1608,17 @@ var Scene3DViewer = exports["default"] = /*#__PURE__*/function (_React$Component
1607
1608
  alti = (0, _convertUnitsLite.convert)(alti).from(_unit2).to(_this2.props.state.scene.unit);
1608
1609
  }
1609
1610
  getPoint(event, alti);
1611
+ var _selectedItem = planData === null || planData === void 0 || (_planData$sceneGraph2 = planData.sceneGraph) === null || _planData$sceneGraph2 === void 0 || (_planData$sceneGraph2 = _planData$sceneGraph2.layers[(_selectedObject2 = selectedObject) === null || _selectedObject2 === void 0 ? void 0 : _selectedObject2.layerID]) === null || _planData$sceneGraph2 === void 0 ? void 0 : _planData$sceneGraph2.items[(_selectedObject3 = selectedObject) === null || _selectedObject3 === void 0 ? void 0 : _selectedObject3.itemID];
1612
+ if (isSelected && !(0, _helper.isEmpty)(_selectedItem)) addItemToolObj();
1610
1613
  if (bRotate) {
1611
- addItemToolObj();
1612
1614
  _this2.setState({
1613
1615
  toolObj: toolObj
1614
1616
  });
1615
1617
  _this2.context.itemsActions.endRotatingItem3D(Point.x, Point.y);
1616
1618
  bRotate = false;
1617
- } else if (bMove) {
1619
+ }
1620
+ if (bMove) {
1618
1621
  bMove = false;
1619
- addItemToolObj();
1620
1622
  _this2.setState({
1621
1623
  toolObj: toolObj
1622
1624
  });
@@ -1636,7 +1638,7 @@ var Scene3DViewer = exports["default"] = /*#__PURE__*/function (_React$Component
1636
1638
  _item3D.position.z = targetPoint.z;
1637
1639
  _item3D.visible = true;
1638
1640
  }
1639
- } else {}
1641
+ }
1640
1642
  if (bMoveUP) {
1641
1643
  bMoveUP = false;
1642
1644
  }