kitchen-simulator 2.0.3 → 2.0.4-op-event

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,15 +1,17 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
4
  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; }
4
5
  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
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
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, EXTERNAL_EVENT_CHANGE_DOORSTYLE, EXTERNAL_EVENT_SET_INITIAL_DATA, EXTERNAL_EVENT_ADD_ROOM_SHAPE, EXTERNAL_EVENT_ZOOM_IN, EXTERNAL_EVENT_ZOOM_OUT, ZOOM_VARIABLE, EXTERNAL_EVENT_UNDO, EXTERNAL_EVENT_REDO, EXTERNAL_EVENT_SET_MOLDING, EXTERNAL_EVENT_PROJECT_SETTING, PROJECT_SETTING_OPTION, EXTERNAL_EVENT_CHANGE_DISTANCE, EXTERNAL_EVENT_SYNC_SCENE, INTERNAL_EVENT_SYNC_SCENE, EXTERNAL_EVENT_LOAD_PROJECT } from "../constants";
7
+ import { Seq, fromJS, List, Map, Record } from 'immutable';
8
+ 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, MODE_DRAWING_LINE, 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, EXTERNAL_EVENT_UNDO, EXTERNAL_EVENT_REDO, EXTERNAL_EVENT_SET_MOLDING, EXTERNAL_EVENT_PROJECT_SETTING, PROJECT_SETTING_OPTION, EXTERNAL_EVENT_SYNC_SCENE, INTERNAL_EVENT_SYNC_SCENE, EXTERNAL_EVENT_LOAD_PROJECT, INTERNAL_EVENT_ITEMS_CATALOG, EXTERNAL_EVENT_UPDATE_ATTRIBUTE, LEFT_DIST_ANG, RIGHT_DIST_ANG, BACK_DIST_ANG, FRONT_DIST_ANG, ATT_ITEM_POS, ATT_LINE_LENGTH, ATT_VERTEXT_ONE, ATT_VERTEXT_TWO, ATT_HOLE_OFFSET_A, ATT_HOLE_OFFSET_B, UNIT_CENTIMETER, UNIT_INCH } from "../constants";
8
9
  import { isEmpty } from "./helper";
9
10
  import exporter from "../catalog/utils/exporter";
10
11
  import { render2DItem, render3DItem } from "../catalog/utils/item-loader";
11
- import Catalog from "../catalog/catalog";
12
- import { CatalogElement, safeLoadMapList } from "../models";
12
+ import { convert } from "./convert-units-lite";
13
+ import { GeometryUtils } from "./export";
14
+ var PRECISION = 2;
13
15
  var loadSVGsByItem = /*#__PURE__*/function () {
14
16
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(item) {
15
17
  var _parsed$xml$viewBox, _parsed$xml$viewBox2, response, svgText, loader, parsed, _t;
@@ -65,12 +67,12 @@ var loadSVGsByItem = /*#__PURE__*/function () {
65
67
  var compareSVGRect = function compareSVGRect(value) {
66
68
  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
69
  };
68
- function loadJSON(_x2, _x3, _x4) {
70
+ function loadJSON(_x2) {
69
71
  return _loadJSON.apply(this, arguments);
70
72
  }
71
73
  /********Parse TempPlaceholder from cabinetPayloadData **************/
72
74
  function _loadJSON() {
73
- _loadJSON = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(path, success, error) {
75
+ _loadJSON = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(path) {
74
76
  return _regeneratorRuntime.wrap(function (_context2) {
75
77
  while (1) switch (_context2.prev = _context2.next) {
76
78
  case 0:
@@ -96,10 +98,9 @@ function _loadJSON() {
96
98
  }));
97
99
  return _loadJSON.apply(this, arguments);
98
100
  }
99
- export function parseTempPlaceholdersFromCabinetPayload(_x5) {
101
+ function parseTempPlaceholdersFromCabinetPayload(_x3) {
100
102
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
101
103
  }
102
-
103
104
  /***** Update cabinetPayloadData with updatedTempPlaceholders *****/
104
105
  function _parseTempPlaceholdersFromCabinetPayload() {
105
106
  _parseTempPlaceholdersFromCabinetPayload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(cabinetPayload) {
@@ -429,7 +430,8 @@ function _parseTempPlaceholdersFromCabinetPayload() {
429
430
  });
430
431
  tempPlaceholdersData.push({
431
432
  id: parseInt(el, 10),
432
- placeholders: tempData
433
+ placeholders: tempData,
434
+ structure: cabinetPayload.structure_json.tempPlaceholders[0].structure
433
435
  });
434
436
  return _context3.abrupt("return", tempPlaceholdersData);
435
437
  case 5:
@@ -440,7 +442,7 @@ function _parseTempPlaceholdersFromCabinetPayload() {
440
442
  }));
441
443
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
442
444
  }
443
- export function updateCabinetPayload(_x6) {
445
+ function updateCabinetPayload(_x4) {
444
446
  return _updateCabinetPayload.apply(this, arguments);
445
447
  }
446
448
  function _updateCabinetPayload() {
@@ -470,9 +472,9 @@ function _updateCabinetPayload() {
470
472
  }));
471
473
  return _updateCabinetPayload.apply(this, arguments);
472
474
  }
473
- function addItemToCatalog(_x7, _x8, _x9, _x0) {
475
+ function addItemToCatalog(_x5, _x6, _x7, _x8) {
474
476
  return _addItemToCatalog.apply(this, arguments);
475
- }
477
+ } // Get attributs of current selected element
476
478
  function _addItemToCatalog() {
477
479
  _addItemToCatalog = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(element, state, catalogInstance, projectActions) {
478
480
  var elementJs, catalog, updatedStructureJson, outlineSVGData;
@@ -518,105 +520,470 @@ function _addItemToCatalog() {
518
520
  }));
519
521
  return _addItemToCatalog.apply(this, arguments);
520
522
  }
523
+ function initAttrData(element, layer, state) {
524
+ element = _typeof(element.misc) === 'object' ? element.set('misc', new Map(element.misc)) : element;
525
+ switch (element.prototype) {
526
+ case 'items':
527
+ {
528
+ return new Map(element);
529
+ }
530
+ case 'lines':
531
+ {
532
+ var v_a = layer.vertices.get(element.vertices.get(0));
533
+ var v_b = layer.vertices.get(element.vertices.get(1));
534
+ var distance = GeometryUtils.pointsDistance(v_a.x, v_a.y, v_b.x, v_b.y);
535
+ var _unit = element.misc.get('_unitLength') || UNIT_INCH;
536
+ var _length = convert(distance).from(UNIT_CENTIMETER).to(_unit);
537
+ if (state.mode == MODE_DRAWING_LINE) {
538
+ return new Map({
539
+ vertexOne: v_a,
540
+ vertexTwo: v_b,
541
+ lineLength: new Map({
542
+ length: distance,
543
+ _length: _length,
544
+ _unit: _unit
545
+ }),
546
+ focus: element.focus
547
+ });
548
+ } else {
549
+ var allLines = layer.lines.toArray();
550
+ var relatedLine = allLines.filter(function (line) {
551
+ return line.vertices.toArray().includes(v_b.id) && line.id != element.id;
552
+ })[0];
553
+ var relatedVertexID = relatedLine && (relatedLine.vertices.toArray()[0] == v_b.id ? relatedLine.vertices.toArray()[1] : relatedLine.vertices.toArray()[0]);
554
+ var v_d = relatedVertexID && layer.getIn(['vertices', relatedVertexID]);
555
+ var lineToExtend = relatedVertexID && allLines.filter(function (line) {
556
+ return line.vertices.toArray().includes(relatedVertexID) && line.id != relatedLine.id;
557
+ })[0];
558
+ var v_c = lineToExtend && layer.getIn(['vertices', lineToExtend.vertices.toArray()[0] == v_d.id ? lineToExtend.vertices.toArray()[1] : lineToExtend.vertices.toArray()[0]]);
559
+ return new Map({
560
+ vertexOne: v_a,
561
+ vertexTwo: v_b,
562
+ vertexThree: v_c,
563
+ vertexFour: v_d,
564
+ lineToExtend: lineToExtend,
565
+ lineLength: new Map({
566
+ length: distance,
567
+ _length: _length,
568
+ _unit: _unit
569
+ }),
570
+ focus: element.focus
571
+ });
572
+ }
573
+ }
574
+ case 'holes':
575
+ {
576
+ var line = layer.lines.get(element.line);
577
+ var _layer$vertices$get = layer.vertices.get(line.vertices.get(0)),
578
+ x0 = _layer$vertices$get.x,
579
+ y0 = _layer$vertices$get.y;
580
+ var _layer$vertices$get2 = layer.vertices.get(line.vertices.get(1)),
581
+ x1 = _layer$vertices$get2.x,
582
+ y1 = _layer$vertices$get2.y;
583
+ var lineLength = GeometryUtils.pointsDistance(x0, y0, x1, y1);
584
+ var startAt = lineLength * element.offset - element.properties.get('width').get('length') / 2;
585
+ var endAt = lineLength - lineLength * element.offset - element.properties.get('width').get('length') / 2;
586
+ var _unitA = element.misc.get('_unitA') || UNIT_INCH;
587
+ var _lengthA = convert(x0 > x1 ? endAt : startAt).from(UNIT_CENTIMETER).to(_unitA);
588
+ var _unitB = element.misc.get('_unitB') || UNIT_INCH;
589
+ var _lengthB = convert(x0 > x1 ? startAt : endAt).from(UNIT_CENTIMETER).to(_unitB);
590
+ return new Map({
591
+ offset: element.offset,
592
+ offsetA: new Map({
593
+ length: MathUtils.toFixedFloat(x0 > x1 ? endAt : startAt, PRECISION),
594
+ _length: MathUtils.toFixedFloat(_lengthA, PRECISION),
595
+ _unit: _unitA
596
+ }),
597
+ offsetB: new Map({
598
+ length: MathUtils.toFixedFloat(x0 > x1 ? startAt : endAt, PRECISION),
599
+ _length: MathUtils.toFixedFloat(_lengthB, PRECISION),
600
+ _unit: _unitB
601
+ })
602
+ });
603
+ }
604
+ case 'areas':
605
+ {
606
+ return new Map({});
607
+ }
608
+ default:
609
+ return null;
610
+ }
611
+ }
612
+ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, projectActions) {
613
+ var attributesFormData = initAttrData(element, layer, state);
614
+ var value = attrPayload.value;
615
+ var attributeName = attrPayload.attributeName;
616
+ // pre process
617
+ if (attributeName === ATT_ITEM_POS) {
618
+ // calculate the new position of movement
619
+ var rotRad = (value.directionAng + element.rotation) / 180 * Math.PI;
620
+ var newX = element.x + convert((value.oldDistance - value.newDistance) * Math.cos(rotRad)).from('in').to('cm');
621
+ var newY = element.y + convert((value.oldDistance - value.newDistance) * Math.sin(rotRad)).from('in').to('cm');
622
+ // const reversedDirection =
623
+ // value.directionAng === LEFT_DIST_ANG
624
+ // ? RIGHT_DIST_ANG
625
+ // : value.directionAng === RIGHT_DIST_ANG
626
+ // ? LEFT_DIST_ANG
627
+ // : value.directionAng === BACK_DIST_ANG
628
+ // ? FRONT_DIST_ANG
629
+ // : BACK_DIST_ANG;
630
+ // let dist = convert(
631
+ // element.distArray?.find(v => v[1] === reversedDirection)
632
+ // ? element.distArray?.find(v => v[1] === reversedDirection)[0]
633
+ // : 0
634
+ // )
635
+ // .from('cm')
636
+ // .to('in');
637
+ // if (dist + (value.oldDistance - value.newDistance) <= 0 || value.newDistance < 0) {
638
+ // // confirm "The item will be placed outside the floor plan. Are you sure?"
639
+ // setPopupOpen(true);
640
+ // return;
641
+ // }
642
+ value = {
643
+ x: newX,
644
+ y: newY
645
+ };
646
+ } else if (attributeName === ATT_LINE_LENGTH || attributeName === ATT_HOLE_OFFSET_A || attributeName === ATT_HOLE_OFFSET_B) {
647
+ var att = attributesFormData.has(attributeName) ? attributesFormData.get(attributeName) : element[attributeName];
648
+ if (att) value = att.merge({
649
+ _length: value,
650
+ _unit: UNIT_INCH,
651
+ length: convert(value).from(UNIT_INCH).to(UNIT_CENTIMETER)
652
+ });
653
+ }
654
+ // make the new attrivutes
655
+ switch (element.prototype) {
656
+ case 'items':
657
+ {
658
+ if (attributeName == ATT_ITEM_POS) {
659
+ var xVal = value.x;
660
+ var yVal = value.y;
661
+ attributesFormData = attributesFormData.set('x', xVal);
662
+ attributesFormData = attributesFormData.set('y', yVal);
663
+ } else {
664
+ attributesFormData = attributesFormData.set(attributeName, value);
665
+ }
666
+ break;
667
+ }
668
+ case 'lines':
669
+ {
670
+ switch (attributeName) {
671
+ case ATT_LINE_LENGTH:
672
+ {
673
+ var v_0 = attributesFormData.get('vertexOne');
674
+ var v_1 = attributesFormData.get('vertexTwo');
675
+ var v_b_new = GeometryUtils.extendLine(v_0.x, v_0.y, v_1.x, v_1.y, value.get('length'), PRECISION);
676
+ attributesFormData = attributesFormData.withMutations(function (attr) {
677
+ attr.set('vertexTwo', v_1.merge(v_b_new));
678
+ attr.set('lineLength', value);
679
+ });
680
+ break;
681
+ }
682
+ case ATT_VERTEXT_ONE:
683
+ case ATT_VERTEXT_TWO:
684
+ {
685
+ attributesFormData = attributesFormData.withMutations(function (attr) {
686
+ attr.set(attributeName, attr.get(attributeName).merge(value));
687
+ var newDistance = GeometryUtils.verticesDistance(attr.get('vertexOne'), attr.get('vertexTwo'));
688
+ attr.mergeIn(['lineLength'], attr.get('lineLength').merge({
689
+ length: newDistance,
690
+ _length: convert(newDistance).from(UNIT_CENTIMETER).to(attr.get('lineLength').get('_unit'))
691
+ }));
692
+ });
693
+ break;
694
+ }
695
+ default:
696
+ {
697
+ attributesFormData = attributesFormData.set(attributeName, value);
698
+ break;
699
+ }
700
+ }
701
+ break;
702
+ }
703
+ case 'holes':
704
+ {
705
+ switch (attributeName) {
706
+ case ATT_HOLE_OFFSET_A:
707
+ {
708
+ var line = layer.lines.get(element.line);
709
+ var _layer$vertices$get3 = layer.vertices.get(line.vertices.get(0)),
710
+ x0 = _layer$vertices$get3.x,
711
+ y0 = _layer$vertices$get3.y;
712
+ var _layer$vertices$get4 = layer.vertices.get(line.vertices.get(1)),
713
+ x1 = _layer$vertices$get4.x,
714
+ y1 = _layer$vertices$get4.y;
715
+ var alpha = GeometryUtils.angleBetweenTwoPoints(x0, y0, x1, y1);
716
+ var lineLength = GeometryUtils.pointsDistance(x0, y0, x1, y1);
717
+ var widthLength = element.properties.get('width').get('length');
718
+ var halfWidthLength = widthLength / 2;
719
+ var lengthValue = value.get('length');
720
+ lengthValue = Math.max(lengthValue, 0);
721
+ lengthValue = Math.min(lengthValue, lineLength - widthLength);
722
+ var xp = (lengthValue + halfWidthLength) * Math.cos(alpha) + x0;
723
+ var yp = (lengthValue + halfWidthLength) * Math.sin(alpha) + y0;
724
+ var offset = GeometryUtils.pointPositionOnLineSegment(x0, y0, x1, y1, xp, yp);
725
+ /*
726
+ if (x0 > x1) offset = 1 - offset;
727
+ */
728
+ var endAt = MathUtils.toFixedFloat(lineLength - lineLength * offset - halfWidthLength, PRECISION);
729
+ var offsetUnit = attributesFormData.getIn(['offsetB', '_unit']);
730
+ var offsetB = new Map({
731
+ length: endAt,
732
+ _length: convert(endAt).from(UNIT_CENTIMETER).to(offsetUnit),
733
+ _unit: offsetUnit
734
+ });
735
+ attributesFormData = attributesFormData.set('offsetB', offsetB).set('offset', offset);
736
+ var offsetAttribute = new Map({
737
+ length: MathUtils.toFixedFloat(lengthValue, PRECISION),
738
+ _unit: value.get('_unit'),
739
+ _length: MathUtils.toFixedFloat(convert(lengthValue).from(UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
740
+ });
741
+ attributesFormData = attributesFormData.set(attributeName, offsetAttribute);
742
+ break;
743
+ }
744
+ case ATT_HOLE_OFFSET_B:
745
+ {
746
+ var _line = layer.lines.get(element.line);
747
+ var _layer$vertices$get5 = layer.vertices.get(_line.vertices.get(0)),
748
+ _x9 = _layer$vertices$get5.x,
749
+ _y = _layer$vertices$get5.y;
750
+ var _layer$vertices$get6 = layer.vertices.get(_line.vertices.get(1)),
751
+ _x0 = _layer$vertices$get6.x,
752
+ _y2 = _layer$vertices$get6.y;
753
+ var _alpha = GeometryUtils.angleBetweenTwoPoints(_x9, _y, _x0, _y2);
754
+ var _lineLength = GeometryUtils.pointsDistance(_x9, _y, _x0, _y2);
755
+ var _widthLength = element.properties.get('width').get('length');
756
+ var _halfWidthLength = _widthLength / 2;
757
+ var _lengthValue = value.get('length');
758
+ _lengthValue = Math.max(_lengthValue, 0);
759
+ _lengthValue = Math.min(_lengthValue, _lineLength - _widthLength);
760
+ var _xp = _x0 - (_lengthValue + _halfWidthLength) * Math.cos(_alpha);
761
+ var _yp = _y2 - (_lengthValue + _halfWidthLength) * Math.sin(_alpha);
762
+ var _offset = GeometryUtils.pointPositionOnLineSegment(_x9, _y, _x0, _y2, _xp, _yp);
763
+ /*
764
+ if (x0 > x1) offset = 1 - offset;
765
+ */
766
+ var startAt = MathUtils.toFixedFloat(_lineLength * _offset - _halfWidthLength, PRECISION);
767
+ var _offsetUnit = attributesFormData.getIn(['offsetA', '_unit']);
768
+ var offsetA = new Map({
769
+ length: startAt,
770
+ _length: convert(startAt).from(UNIT_CENTIMETER).to(_offsetUnit),
771
+ _unit: _offsetUnit
772
+ });
773
+ attributesFormData = attributesFormData.set('offsetA', offsetA).set('offset', _offset);
774
+ var _offsetAttribute = new Map({
775
+ length: MathUtils.toFixedFloat(_lengthValue, PRECISION),
776
+ _unit: value.get('_unit'),
777
+ _length: MathUtils.toFixedFloat(convert(_lengthValue).from(UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
778
+ });
779
+ attributesFormData = attributesFormData.set(attributeName, _offsetAttribute);
780
+ break;
781
+ }
782
+ default:
783
+ {
784
+ attributesFormData = attributesFormData.set(attributeName, value);
785
+ break;
786
+ }
787
+ }
788
+ break;
789
+ }
790
+ default:
791
+ break;
792
+ }
793
+
794
+ // update attribute action
795
+ switch (element.prototype) {
796
+ case 'items':
797
+ {
798
+ projectActions.setItemsAttributes(attributesFormData);
799
+ break;
800
+ }
801
+ case 'lines':
802
+ {
803
+ projectActions.setLinesAttributes(attributesFormData);
804
+ break;
805
+ }
806
+ case 'holes':
807
+ {
808
+ projectActions.setHolesAttributes(attributesFormData);
809
+ break;
810
+ }
811
+ }
812
+ }
521
813
  export function handleExternalEvent(_x1) {
522
814
  return _handleExternalEvent.apply(this, arguments);
523
815
  }
524
816
  function _handleExternalEvent() {
525
- _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(props) {
526
- var evt, state, i, _evt$payload, _evt$payload2, sLineCnt, element, _evt$payload3, moveType, moveValue, value, defaulTitle, _evt$payload4, doorStyle, itemCDS, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _evt$payload5, moldingInfo, isGlobal, _evt$payload6, option, _value3, distancePayload, _props$onInternalEven, _t5, _t6;
527
- return _regeneratorRuntime.wrap(function (_context6) {
528
- while (1) switch (_context6.prev = _context6.next) {
817
+ _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(props) {
818
+ var evt, state, _evt$payload, cdsItems, itemKeys, _loop3, i, _props$onInternalEven, sLineCnt, element, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, _evt$payload3, moveType, moveValue, value, defaulTitle, _evt$payload4, doorStyle, itemCDS, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _evt$payload5, moldingInfo, isGlobal, _evt$payload6, option, _value3, layerId, layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i2, _i3, _i4, _props$onInternalEven2, _t5, _t6;
819
+ return _regeneratorRuntime.wrap(function (_context8) {
820
+ while (1) switch (_context8.prev = _context8.next) {
529
821
  case 0:
530
822
  console.log('***external event****', props.externalEvent);
531
823
  evt = props.externalEvent;
532
824
  state = props.state.get('KitchenConfigurator');
533
825
  _t5 = evt === null || evt === void 0 ? void 0 : evt.type;
534
- _context6.next = _t5 === EXTERNAL_EVENT_LOAD_PROJECT ? 1 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_3D ? 5 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_2D ? 6 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 7 : _t5 === EXTERNAL_EVENT_ADD_WALL ? 8 : _t5 === EXTERNAL_EVENT_ADD_ITEM ? 9 : _t5 === EXTERNAL_EVENT_MOVE_PAN ? 12 : _t5 === EXTERNAL_EVENT_NEW_PROJECT ? 18 : _t5 === EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 19 : _t5 === EXTERNAL_EVENT_SET_INITIAL_DATA ? 20 : _t5 === EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 21 : _t5 === EXTERNAL_EVENT_ZOOM_IN ? 22 : _t5 === EXTERNAL_EVENT_ZOOM_OUT ? 25 : _t5 === EXTERNAL_EVENT_UNDO ? 28 : _t5 === EXTERNAL_EVENT_REDO ? 29 : _t5 === EXTERNAL_EVENT_SET_MOLDING ? 30 : _t5 === EXTERNAL_EVENT_PROJECT_SETTING ? 31 : _t5 === EXTERNAL_EVENT_CHANGE_DISTANCE ? 32 : _t5 === EXTERNAL_EVENT_SYNC_SCENE ? 33 : 34;
826
+ _context8.next = _t5 === EXTERNAL_EVENT_LOAD_PROJECT ? 1 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_3D ? 5 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_2D ? 6 : _t5 === EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 7 : _t5 === EXTERNAL_EVENT_ADD_WALL ? 8 : _t5 === EXTERNAL_EVENT_ADD_ITEM ? 9 : _t5 === EXTERNAL_EVENT_MOVE_PAN ? 12 : _t5 === EXTERNAL_EVENT_NEW_PROJECT ? 18 : _t5 === EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 19 : _t5 === EXTERNAL_EVENT_SET_INITIAL_DATA ? 20 : _t5 === EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 21 : _t5 === EXTERNAL_EVENT_ZOOM_IN ? 22 : _t5 === EXTERNAL_EVENT_ZOOM_OUT ? 25 : _t5 === EXTERNAL_EVENT_UNDO ? 28 : _t5 === EXTERNAL_EVENT_REDO ? 29 : _t5 === EXTERNAL_EVENT_SET_MOLDING ? 30 : _t5 === EXTERNAL_EVENT_PROJECT_SETTING ? 31 : _t5 === EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? 32 : _t5 === EXTERNAL_EVENT_SYNC_SCENE ? 33 : 34;
535
827
  break;
536
828
  case 1:
829
+ // prepare item data request
830
+ cdsItems = [];
831
+ itemKeys = Object.keys(evt === null || evt === void 0 || (_evt$payload = evt.payload) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.layers['layer-1']) === null || _evt$payload === void 0 ? void 0 : _evt$payload.items) || [];
832
+ _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() {
833
+ var _evt$payload2, _it$doorStyle2;
834
+ var it;
835
+ return _regeneratorRuntime.wrap(function (_context7) {
836
+ while (1) switch (_context7.prev = _context7.next) {
837
+ case 0:
838
+ it = evt === null || evt === void 0 || (_evt$payload2 = evt.payload) === null || _evt$payload2 === void 0 || (_evt$payload2 = _evt$payload2.layers['layer-1']) === null || _evt$payload2 === void 0 ? void 0 : _evt$payload2.items[itemKeys[i]];
839
+ if (!cdsItems.some(function (v) {
840
+ var _it$doorStyle;
841
+ return it.type === v.type && ((_it$doorStyle = it.doorStyle) === null || _it$doorStyle === void 0 || (_it$doorStyle = _it$doorStyle.doorStyles) === null || _it$doorStyle === void 0 ? void 0 : _it$doorStyle.cabinet_door_style_id) === v.cdsId;
842
+ })) cdsItems.push({
843
+ type: it.type,
844
+ cdsId: (_it$doorStyle2 = it.doorStyle) === null || _it$doorStyle2 === void 0 || (_it$doorStyle2 = _it$doorStyle2.doorStyles) === null || _it$doorStyle2 === void 0 ? void 0 : _it$doorStyle2.cabinet_door_style_id
845
+ });
846
+ case 1:
847
+ case "end":
848
+ return _context7.stop();
849
+ }
850
+ }, _loop3);
851
+ });
537
852
  i = 0;
538
853
  case 2:
539
- if (!(i < (evt === null || evt === void 0 || (_evt$payload = evt.payload) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.catalogItems) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.elements) === null || _evt$payload === void 0 ? void 0 : _evt$payload.length))) {
540
- _context6.next = 4;
854
+ if (!(i < itemKeys.length)) {
855
+ _context8.next = 4;
541
856
  break;
542
857
  }
543
- _context6.next = 3;
544
- return addItemToCatalog(evt === null || evt === void 0 || (_evt$payload2 = evt.payload) === null || _evt$payload2 === void 0 || (_evt$payload2 = _evt$payload2.catalogItems) === null || _evt$payload2 === void 0 ? void 0 : _evt$payload2.elements[i], state, props.catalog, props.projectActions);
858
+ return _context8.delegateYield(_loop3(), "t0", 3);
545
859
  case 3:
546
860
  i++;
547
- _context6.next = 2;
861
+ _context8.next = 2;
548
862
  break;
549
863
  case 4:
550
- props.projectActions.loadProject(evt.payload.sceneData);
551
- return _context6.abrupt("continue", 34);
864
+ // request item catalog data to host app
865
+ if (cdsItems.length > 0) {
866
+ (_props$onInternalEven = props.onInternalEvent) === null || _props$onInternalEven === void 0 || _props$onInternalEven.call(props, {
867
+ type: INTERNAL_EVENT_ITEMS_CATALOG,
868
+ value: {
869
+ cdsItems: cdsItems
870
+ }
871
+ }, /*#__PURE__*/function () {
872
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(result) {
873
+ var _i, _result$elements;
874
+ return _regeneratorRuntime.wrap(function (_context6) {
875
+ while (1) switch (_context6.prev = _context6.next) {
876
+ case 0:
877
+ _i = 0;
878
+ case 1:
879
+ if (!(_i < (result === null || result === void 0 || (_result$elements = result.elements) === null || _result$elements === void 0 ? void 0 : _result$elements.length))) {
880
+ _context6.next = 3;
881
+ break;
882
+ }
883
+ _context6.next = 2;
884
+ return addItemToCatalog(result.elements[_i], state, props.catalog, props.projectActions);
885
+ case 2:
886
+ _i++;
887
+ _context6.next = 1;
888
+ break;
889
+ case 3:
890
+ props.projectActions.loadProject(evt.payload);
891
+ case 4:
892
+ case "end":
893
+ return _context6.stop();
894
+ }
895
+ }, _callee6);
896
+ }));
897
+ return function (_x10) {
898
+ return _ref2.apply(this, arguments);
899
+ };
900
+ }());
901
+ }
902
+ return _context8.abrupt("continue", 34);
552
903
  case 5:
553
904
  props.projectActions.setMode(MODE_IDLE_3D);
554
- return _context6.abrupt("continue", 34);
905
+ return _context8.abrupt("continue", 34);
555
906
  case 6:
556
907
  props.projectActions.setMode(MODE_IDLE);
557
- return _context6.abrupt("continue", 34);
908
+ return _context8.abrupt("continue", 34);
558
909
  case 7:
559
910
  sLineCnt = state.getIn(['scene', 'layers', 'layer-1', 'selected', 'lines']).size;
560
911
  if (sLineCnt > 0) props.projectActions.setMode(MODE_ELEVATION_VIEW);
561
- return _context6.abrupt("continue", 34);
912
+ return _context8.abrupt("continue", 34);
562
913
  case 8:
563
914
  if (state.mode === MODE_IDLE || state.mode === MODE_2D_PAN) props.linesActions.selectToolDrawingLine('wall');else {
564
915
  props.projectActions.setMode(MODE_IDLE);
565
916
  props.linesActions.selectToolDrawingLine('wall');
566
917
  }
567
- return _context6.abrupt("continue", 34);
918
+ return _context8.abrupt("continue", 34);
568
919
  case 9:
569
920
  if (isEmpty(evt === null || evt === void 0 ? void 0 : evt.payload)) {
570
- _context6.next = 11;
921
+ _context8.next = 11;
571
922
  break;
572
923
  }
573
924
  element = evt.payload;
574
- _context6.next = 10;
925
+ _context8.next = 10;
575
926
  return addItemToCatalog(element, state, props.catalog, props.projectActions);
576
927
  case 10:
577
928
  // start drawing item
578
- ARRAY_3D_MODES.includes(state.mode) ? props.itemsActions.selectToolDrawingItem3D(element.name) : props.itemsActions.selectToolDrawingItem(element.name);
929
+ if (ARRAY_3D_MODES.includes(state.mode)) {
930
+ // in 3d view
931
+ props.itemsActions.selectToolDrawingItem3D(element.name);
932
+ } else {
933
+ // in 2d view
934
+ // create cabinet
935
+ props.itemsActions.selectToolDrawingItem(element.name);
936
+ // mapping the initial position of client coord to viewer2D coord
937
+ _evt$payload$initialP = evt.payload.initialPosition, mouseX = _evt$payload$initialP.mouseX, mouseY = _evt$payload$initialP.mouseY;
938
+ v2d = (_state$viewer2D = state.viewer2D) === null || _state$viewer2D === void 0 ? void 0 : _state$viewer2D.toJS();
939
+ if (mouseX && mouseY && v2d) {
940
+ vPosX = (mouseX - v2d.e) / v2d.a;
941
+ vPosY = (mouseY - v2d.f) / v2d.d;
942
+ layerID = state.scene.selectedLayer; // move cabinet to initial position
943
+ props.itemsActions.updateDrawingItem(layerID, vPosX, -vPosY + state.scene.height);
944
+ }
945
+ }
579
946
  props.projectActions.pushLastSelectedCatalogElementToHistory(element);
580
947
  props.projectActions.setIsCabinetDrawing(true);
581
948
  case 11:
582
- return _context6.abrupt("continue", 34);
949
+ return _context8.abrupt("continue", 34);
583
950
  case 12:
584
951
  _evt$payload3 = evt.payload, moveType = _evt$payload3.moveType, moveValue = _evt$payload3.moveValue;
585
952
  value = state.getIn(['viewer2D']).toJS();
586
953
  _t6 = moveType;
587
- _context6.next = _t6 === TOP ? 13 : _t6 === BOTTOM ? 14 : _t6 === RIGHT ? 15 : _t6 === LEFT ? 16 : 17;
954
+ _context8.next = _t6 === TOP ? 13 : _t6 === BOTTOM ? 14 : _t6 === RIGHT ? 15 : _t6 === LEFT ? 16 : 17;
588
955
  break;
589
956
  case 13:
590
957
  value.f -= moveValue;
591
- return _context6.abrupt("continue", 17);
958
+ return _context8.abrupt("continue", 17);
592
959
  case 14:
593
960
  value.f += moveValue;
594
- return _context6.abrupt("continue", 17);
961
+ return _context8.abrupt("continue", 17);
595
962
  case 15:
596
963
  value.e += moveValue;
597
- return _context6.abrupt("continue", 17);
964
+ return _context8.abrupt("continue", 17);
598
965
  case 16:
599
966
  value.e -= moveValue;
600
- return _context6.abrupt("continue", 17);
967
+ return _context8.abrupt("continue", 17);
601
968
  case 17:
602
969
  if (compareSVGRect(value)) props.viewer2DActions.updateCameraView(value);
603
- return _context6.abrupt("continue", 34);
970
+ return _context8.abrupt("continue", 34);
604
971
  case 18:
605
972
  defaulTitle = 'Untitle';
606
973
  props.projectActions.newProject();
607
974
  props.projectActions.rename(defaulTitle);
608
- return _context6.abrupt("continue", 34);
975
+ return _context8.abrupt("continue", 34);
609
976
  case 19:
610
977
  _evt$payload4 = evt.payload, doorStyle = _evt$payload4.doorStyle, itemCDS = _evt$payload4.itemCDS, isAll = _evt$payload4.isAll;
611
978
  props.itemsActions.setDoorStyle(doorStyle, itemCDS, isAll);
612
- return _context6.abrupt("continue", 34);
979
+ return _context8.abrupt("continue", 34);
613
980
  case 20:
614
981
  _doorStyle = evt.payload.doorStyle;
615
982
  props.itemsActions.setInitialDoorStyle(_doorStyle.doorStyle);
616
- return _context6.abrupt("continue", 34);
983
+ return _context8.abrupt("continue", 34);
617
984
  case 21:
618
985
  props.projectActions.loadProject(evt.payload);
619
- return _context6.abrupt("continue", 34);
986
+ return _context8.abrupt("continue", 34);
620
987
  case 22:
621
988
  _value = state.getIn(['viewer2D']).toJS();
622
989
  _value.a -= 0.1;
@@ -625,16 +992,16 @@ function _handleExternalEvent() {
625
992
  _value.f += _value.SVGHeight * 0.1 / 2;
626
993
  _zoomValue = parseInt((_value.a - 0.5) / ZOOM_VARIABLE);
627
994
  if (!(_zoomValue > 404)) {
628
- _context6.next = 23;
995
+ _context8.next = 23;
629
996
  break;
630
997
  }
631
- return _context6.abrupt("return");
998
+ return _context8.abrupt("return");
632
999
  case 23:
633
1000
  if (!(_zoomValue < 35 || Number.isNaN(_zoomValue))) {
634
- _context6.next = 24;
1001
+ _context8.next = 24;
635
1002
  break;
636
1003
  }
637
- return _context6.abrupt("return");
1004
+ return _context8.abrupt("return");
638
1005
  case 24:
639
1006
  while (!(_value.e <= 10)) {
640
1007
  _value.e -= 0.1;
@@ -649,7 +1016,7 @@ function _handleExternalEvent() {
649
1016
  _value.f += 0.1;
650
1017
  }
651
1018
  if (compareSVGRect(_value)) props.viewer2DActions.updateCameraView(_value);
652
- return _context6.abrupt("continue", 34);
1019
+ return _context8.abrupt("continue", 34);
653
1020
  case 25:
654
1021
  _value2 = state.getIn(['viewer2D']).toJS();
655
1022
  _value2.a += 0.1;
@@ -658,29 +1025,29 @@ function _handleExternalEvent() {
658
1025
  _value2.f -= _value2.SVGHeight * 0.1 / 2;
659
1026
  _zoomValue2 = parseInt((_value2.a - 0.5) / ZOOM_VARIABLE);
660
1027
  if (!(_zoomValue2 > 404)) {
661
- _context6.next = 26;
1028
+ _context8.next = 26;
662
1029
  break;
663
1030
  }
664
- return _context6.abrupt("return");
1031
+ return _context8.abrupt("return");
665
1032
  case 26:
666
1033
  if (!(_zoomValue2 < 35 || Number.isNaN(_zoomValue2))) {
667
- _context6.next = 27;
1034
+ _context8.next = 27;
668
1035
  break;
669
1036
  }
670
- return _context6.abrupt("return");
1037
+ return _context8.abrupt("return");
671
1038
  case 27:
672
1039
  if (compareSVGRect(_value2)) props.viewer2DActions.updateCameraView(_value2);
673
- return _context6.abrupt("continue", 34);
1040
+ return _context8.abrupt("continue", 34);
674
1041
  case 28:
675
1042
  props.projectActions.undo();
676
- return _context6.abrupt("continue", 34);
1043
+ return _context8.abrupt("continue", 34);
677
1044
  case 29:
678
1045
  props.projectActions.redo();
679
- return _context6.abrupt("continue", 34);
1046
+ return _context8.abrupt("continue", 34);
680
1047
  case 30:
681
1048
  _evt$payload5 = evt.payload, moldingInfo = _evt$payload5.moldingInfo, isGlobal = _evt$payload5.isGlobal;
682
1049
  props.itemsActions.setMolding(moldingInfo, isGlobal);
683
- return _context6.abrupt("continue", 34);
1050
+ return _context8.abrupt("continue", 34);
684
1051
  case 31:
685
1052
  _evt$payload6 = evt.payload, option = _evt$payload6.option, _value3 = _evt$payload6.value;
686
1053
  if (option === PROJECT_SETTING_OPTION.UPDATE_CEIL_HEIGHT) {
@@ -695,13 +1062,18 @@ function _handleExternalEvent() {
695
1062
  } else if (option === PROJECT_SETTING_OPTION.CHANGE_WINDOW_DOOR_MEASURE) {
696
1063
  props.viewer2DActions.changeWindowDoorMeasure(_value3);
697
1064
  }
698
- return _context6.abrupt("continue", 34);
1065
+ return _context8.abrupt("continue", 34);
699
1066
  case 32:
700
- distancePayload = evt.payload;
701
- props.itemsActions.changeDistance(distancePayload);
1067
+ layerId = state.getIn(['scene', 'selectedLayer']);
1068
+ layer = state.getIn(['scene', 'layers', layerId]);
1069
+ _layer$getIn = layer.getIn(['selected']), selectedLines = _layer$getIn.lines, selectedHoles = _layer$getIn.holes, selectedItems = _layer$getIn.items;
1070
+ for (_i2 = 0; _i2 < selectedLines.size; _i2++) updateAttributeOfSelectedElement(layer.getIn(['lines', selectedLines.get(_i2)]), evt.payload, state, layer, props.projectActions);
1071
+ for (_i3 = 0; _i3 < selectedHoles.size; _i3++) updateAttributeOfSelectedElement(layer.getIn(['holes', selectedHoles.get(_i3)]), evt.payload, state, layer, props.projectActions);
1072
+ for (_i4 = 0; _i4 < selectedItems.size; _i4++) updateAttributeOfSelectedElement(layer.getIn(['items', selectedItems.get(_i4)]), evt.payload, state, layer, props.projectActions);
1073
+ return _context8.abrupt("continue", 34);
702
1074
  case 33:
703
1075
  // send scene object from 3DTool to HostApp using internalEvent
704
- (_props$onInternalEven = props.onInternalEvent) === null || _props$onInternalEven === void 0 || _props$onInternalEven.call(props, {
1076
+ (_props$onInternalEven2 = props.onInternalEvent) === null || _props$onInternalEven2 === void 0 || _props$onInternalEven2.call(props, {
705
1077
  type: INTERNAL_EVENT_SYNC_SCENE,
706
1078
  value: {
707
1079
  scene: state.scene.toJS()
@@ -709,9 +1081,9 @@ function _handleExternalEvent() {
709
1081
  });
710
1082
  case 34:
711
1083
  case "end":
712
- return _context6.stop();
1084
+ return _context8.stop();
713
1085
  }
714
- }, _callee6);
1086
+ }, _callee7);
715
1087
  }));
716
1088
  return _handleExternalEvent.apply(this, arguments);
717
1089
  }