kitchen-simulator 3.1.2 → 4.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.
Files changed (138) hide show
  1. package/README.md +0 -3
  2. package/es/AppContext.js +1 -1
  3. package/es/LiteKitchenConfigurator.js +15 -25
  4. package/es/LiteRenderer.js +2 -5
  5. package/es/actions/export.js +12 -25
  6. package/es/catalog/catalog.js +5 -21
  7. package/es/components/content.js +2 -5
  8. package/es/components/export.js +6 -4
  9. package/es/components/style/export.js +2 -28
  10. package/es/components/style/form-number-input.js +22 -11
  11. package/es/components/viewer2d/group.js +4 -5
  12. package/es/components/viewer2d/item.js +300 -316
  13. package/es/components/viewer2d/layer.js +1 -1
  14. package/es/components/viewer2d/line.js +47 -17
  15. package/es/components/viewer2d/rulerX.js +0 -3
  16. package/es/components/viewer2d/rulerY.js +0 -3
  17. package/es/components/viewer2d/scene.js +1 -4
  18. package/es/components/viewer2d/state.js +1 -1
  19. package/es/components/viewer2d/viewer2d.js +43 -28
  20. package/es/components/viewer3d/viewer3d-first-person.js +0 -8
  21. package/es/components/viewer3d/viewer3d.js +0 -9
  22. package/es/devLiteRenderer.js +148 -317
  23. package/es/index.js +12 -4
  24. package/es/mocks/appliancePayload.json +27 -0
  25. package/es/mocks/cabinetPayload.json +1914 -0
  26. package/es/mocks/cabinetPayload2.json +76 -0
  27. package/es/mocks/dataBundle2.json +4 -0
  28. package/es/mocks/distancePayload.json +6 -0
  29. package/es/mocks/doorStylePayload2.json +84 -0
  30. package/es/mocks/furnishingPayload.json +23 -0
  31. package/es/mocks/itemCDSPayload.json +27 -0
  32. package/es/mocks/lightingPayload.json +23 -0
  33. package/es/mocks/mockProps.json +43 -0
  34. package/es/mocks/mockProps2.json +9 -0
  35. package/es/mocks/moldingPayload.json +19 -0
  36. package/es/mocks/projectItemsCatalog.json +133 -0
  37. package/es/mocks/rectangleShape.json +238 -0
  38. package/es/mocks/replaceCabinetPayload.json +81 -0
  39. package/es/mocks/roomShapePayload.json +5 -0
  40. package/es/useAppContext.js +8 -0
  41. package/lib/AppContext.js +1 -1
  42. package/lib/LiteKitchenConfigurator.js +15 -25
  43. package/lib/LiteRenderer.js +2 -5
  44. package/lib/actions/export.js +39 -35
  45. package/lib/catalog/catalog.js +4 -20
  46. package/lib/components/content.js +2 -5
  47. package/lib/components/export.js +26 -6
  48. package/lib/components/style/export.js +1 -105
  49. package/lib/components/style/form-number-input.js +22 -11
  50. package/lib/components/viewer2d/group.js +4 -5
  51. package/lib/components/viewer2d/item.js +298 -314
  52. package/lib/components/viewer2d/layer.js +1 -1
  53. package/lib/components/viewer2d/line.js +47 -17
  54. package/lib/components/viewer2d/rulerX.js +0 -3
  55. package/lib/components/viewer2d/rulerY.js +0 -3
  56. package/lib/components/viewer2d/scene.js +1 -4
  57. package/lib/components/viewer2d/state.js +1 -1
  58. package/lib/components/viewer2d/viewer2d.js +42 -27
  59. package/lib/components/viewer3d/viewer3d-first-person.js +0 -8
  60. package/lib/components/viewer3d/viewer3d.js +0 -9
  61. package/lib/devLiteRenderer.js +147 -316
  62. package/lib/index.js +12 -4
  63. package/lib/mocks/appliancePayload.json +27 -0
  64. package/lib/mocks/cabinetPayload.json +1914 -0
  65. package/lib/mocks/cabinetPayload2.json +76 -0
  66. package/lib/mocks/dataBundle2.json +4 -0
  67. package/lib/mocks/distancePayload.json +6 -0
  68. package/lib/mocks/doorStylePayload2.json +84 -0
  69. package/lib/mocks/furnishingPayload.json +23 -0
  70. package/lib/mocks/itemCDSPayload.json +27 -0
  71. package/lib/mocks/lightingPayload.json +23 -0
  72. package/lib/mocks/mockProps.json +43 -0
  73. package/lib/mocks/mockProps2.json +9 -0
  74. package/lib/mocks/moldingPayload.json +19 -0
  75. package/lib/mocks/projectItemsCatalog.json +133 -0
  76. package/lib/mocks/rectangleShape.json +238 -0
  77. package/lib/mocks/replaceCabinetPayload.json +81 -0
  78. package/lib/mocks/roomShapePayload.json +5 -0
  79. package/lib/useAppContext.js +16 -0
  80. package/package.json +16 -21
  81. package/es/catalog/properties/export.js +0 -21
  82. package/es/catalog/properties/property-checkbox.js +0 -68
  83. package/es/catalog/properties/property-color.js +0 -39
  84. package/es/catalog/properties/property-enum.js +0 -50
  85. package/es/catalog/properties/property-hidden.js +0 -19
  86. package/es/catalog/properties/property-lenght-measure.js +0 -100
  87. package/es/catalog/properties/property-length-measure.js +0 -84
  88. package/es/catalog/properties/property-length-measure_hole.js +0 -100
  89. package/es/catalog/properties/property-number.js +0 -48
  90. package/es/catalog/properties/property-read-only.js +0 -26
  91. package/es/catalog/properties/property-string.js +0 -48
  92. package/es/catalog/properties/property-toggle.js +0 -39
  93. package/es/catalog/properties/shared-property-style.js +0 -14
  94. package/es/components/style/button.js +0 -106
  95. package/es/components/style/cancel-button.js +0 -21
  96. package/es/components/style/content-container.js +0 -30
  97. package/es/components/style/content-title.js +0 -25
  98. package/es/components/style/delete-button.js +0 -24
  99. package/es/components/style/form-block.js +0 -20
  100. package/es/components/style/form-color-input.js +0 -26
  101. package/es/components/style/form-label.js +0 -22
  102. package/es/components/style/form-number-input_2.js +0 -200
  103. package/es/components/style/form-select.js +0 -19
  104. package/es/components/style/form-slider.js +0 -60
  105. package/es/components/style/form-submit-button.js +0 -25
  106. package/es/components/style/form-text-input.js +0 -69
  107. package/es/plugins/SVGLoader.js +0 -1414
  108. package/es/styles/export.js +0 -5
  109. package/es/styles/tabs.css +0 -40
  110. package/lib/catalog/properties/export.js +0 -81
  111. package/lib/catalog/properties/property-checkbox.js +0 -76
  112. package/lib/catalog/properties/property-color.js +0 -47
  113. package/lib/catalog/properties/property-enum.js +0 -58
  114. package/lib/catalog/properties/property-hidden.js +0 -27
  115. package/lib/catalog/properties/property-lenght-measure.js +0 -108
  116. package/lib/catalog/properties/property-length-measure.js +0 -92
  117. package/lib/catalog/properties/property-length-measure_hole.js +0 -108
  118. package/lib/catalog/properties/property-number.js +0 -56
  119. package/lib/catalog/properties/property-read-only.js +0 -34
  120. package/lib/catalog/properties/property-string.js +0 -56
  121. package/lib/catalog/properties/property-toggle.js +0 -47
  122. package/lib/catalog/properties/shared-property-style.js +0 -21
  123. package/lib/components/style/button.js +0 -115
  124. package/lib/components/style/cancel-button.js +0 -29
  125. package/lib/components/style/content-container.js +0 -38
  126. package/lib/components/style/content-title.js +0 -35
  127. package/lib/components/style/delete-button.js +0 -34
  128. package/lib/components/style/form-block.js +0 -28
  129. package/lib/components/style/form-color-input.js +0 -34
  130. package/lib/components/style/form-label.js +0 -30
  131. package/lib/components/style/form-number-input_2.js +0 -209
  132. package/lib/components/style/form-select.js +0 -29
  133. package/lib/components/style/form-slider.js +0 -68
  134. package/lib/components/style/form-submit-button.js +0 -35
  135. package/lib/components/style/form-text-input.js +0 -78
  136. package/lib/plugins/SVGLoader.js +0 -1419
  137. package/lib/styles/export.js +0 -13
  138. package/lib/styles/tabs.css +0 -40
@@ -1,12 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useState } from 'react';
2
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import RulerDist from "./rulerDist";
5
5
  import { convert } from "../../utils/convert-units-lite";
6
6
  import { GeometryUtils } from "../../utils/export";
7
7
  import { MODE_ROTATING_ITEM, WALL_CABINET_LAYOUTPOS } from "../../constants";
8
- import { isEmpty, isWarningItem, returnReplaceableDeepSearchType } from "./utils";
8
+ import { isWarningItem } from "./utils";
9
9
  import { findCatalogElement } from "../../utils/geometry";
10
+ import { useAppContext } from "../../useAppContext";
10
11
  var STYLE_LINE = {
11
12
  fill: '#0096fd',
12
13
  stroke: '#0096fd'
@@ -21,14 +22,15 @@ var STYLE_CIRCLE2 = {
21
22
  stroke: '#0096fd',
22
23
  cursor: 'ew-resize'
23
24
  };
24
- export default function Item(_ref, _ref2) {
25
+ export default function Item(_ref) {
25
26
  var _element$render2D;
26
27
  var layer = _ref.layer,
27
28
  item = _ref.item,
28
29
  scene = _ref.scene,
29
30
  catalog = _ref.catalog,
30
31
  mode = _ref.mode;
31
- var itemsActions = _ref2.itemsActions;
32
+ var _useAppContext = useAppContext(),
33
+ itemsActions = _useAppContext.itemsActions;
32
34
  var x = item.x,
33
35
  y = item.y,
34
36
  rotation = item.rotation,
@@ -36,14 +38,8 @@ export default function Item(_ref, _ref2) {
36
38
  layoutpos = item.layoutpos;
37
39
  var showBaseCabinetMeasure = scene.showBaseCabinetMeasure,
38
40
  showWallCabinetMeasure = scene.showWallCabinetMeasure;
39
- var vertices = layer.vertices;
40
41
  var layerID = scene.selectedLayer;
41
42
  var element = catalog.getElement(item.type);
42
- var allLines;
43
- var curiteminfo;
44
- var allLineRects;
45
- var allItemRect;
46
- var width, height;
47
43
  var altitude = item.properties.getIn(['altitude', '_length']);
48
44
  var _useState = useState(false),
49
45
  _useState2 = _slicedToArray(_useState, 2),
@@ -53,118 +49,79 @@ export default function Item(_ref, _ref2) {
53
49
  _useState4 = _slicedToArray(_useState3, 2),
54
50
  antiClockRotateState = _useState4[0],
55
51
  setAntiClockRotateState = _useState4[1];
56
- var val = {
57
- pos: {
58
- x: item.x,
59
- y: item.y
60
- },
61
- rotRad: item.rotation / 180 * Math.PI
62
- };
63
- var tempWidth = item.properties.get('width');
64
- var tempHeight = item.properties.get('depth');
65
- if (tempWidth || tempHeight) {
66
- width = convert(tempWidth.get('_length')).from(tempWidth.get('_unit')).to('cm');
67
- height = convert(tempHeight.get('_length')).from(tempHeight.get('_unit')).to('cm');
68
- } else {
69
- width = convert(element.info.sizeinfo.width).from('in').to('cm');
70
- height = convert(element.info.sizeinfo.depth).from('in').to('cm');
71
- }
72
- var angle = rotation + 90;
73
- val.size = {
74
- width: width,
75
- height: height
76
- };
77
- function point(x, y) {
52
+
53
+ // ----- helpers -----
54
+ function point(px, py) {
78
55
  return {
79
- x: x,
80
- y: y
56
+ x: px,
57
+ y: py
81
58
  };
82
59
  }
83
60
  function getCalcRectFromItem(items) {
84
- var x = items.pos.x;
85
- var y = items.pos.y;
61
+ var ix = items.pos.x;
62
+ var iy = items.pos.y;
86
63
  var w = items.size.width / 2;
87
64
  var h = items.size.height / 2;
88
65
  var rotRad = items.rotRad;
89
66
  var mh = 3 * h / 4;
90
- var mx = x - w * Math.cos(rotRad) - mh * Math.sin(rotRad);
91
- var my = y - w * Math.sin(rotRad) + mh * Math.cos(rotRad);
92
- var m2x = x + w * Math.cos(rotRad) - mh * Math.sin(rotRad);
93
- var m2y = y + w * Math.sin(rotRad) + mh * Math.cos(rotRad);
94
- var m3x = x - h * Math.sin(rotRad);
95
- var m3y = y + h * Math.cos(rotRad);
96
- var m1x = x + h * Math.sin(rotRad);
97
- var m1y = y - h * Math.cos(rotRad);
98
- var x0 = mx + h * Math.sin(rotRad);
99
- var y0 = my - h * Math.cos(rotRad);
100
- var x3 = mx * 2 - x0;
101
- var y3 = my * 2 - y0;
102
- var x1 = x * 2 - x3;
103
- var y1 = y * 2 - y3;
104
- var x2 = x * 2 - x0;
105
- var y2 = y * 2 - y0;
67
+ var mx = ix - w * Math.cos(rotRad) - mh * Math.sin(rotRad);
68
+ var my = iy - w * Math.sin(rotRad) + mh * Math.cos(rotRad);
69
+ var m2x = ix + w * Math.cos(rotRad) - mh * Math.sin(rotRad);
70
+ var m2y = iy + w * Math.sin(rotRad) + mh * Math.cos(rotRad);
71
+ var m3x = ix - h * Math.sin(rotRad);
72
+ var m3y = iy + h * Math.cos(rotRad);
73
+ var m1x = ix + h * Math.sin(rotRad);
74
+ var m1y = iy - h * Math.cos(rotRad);
106
75
  return {
107
76
  rectCenterPoint: [[point(mx, my), 180], [point(m1x, m1y), -90], [point(m2x, m2y), 0], [point(m3x, m3y), 90]]
108
77
  };
109
78
  }
110
- function getAllItems() {
79
+ function getAllItemsRectangles(_ref2) {
80
+ var layer = _ref2.layer,
81
+ catalog = _ref2.catalog,
82
+ layoutpos = _ref2.layoutpos,
83
+ altitude = _ref2.altitude,
84
+ tempHeightLen = _ref2.tempHeightLen;
111
85
  var rectarray = [];
112
- var currentItem;
113
- var selectedItem;
86
+
87
+ // keeping your selectedItem logic (even though not used right now)
114
88
  if (layer.selected.items.size > 0) {
115
- selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
116
- var _catid = selectedItem.type;
117
- var _cat = findCatalogElement(catalog, _catid);
118
- currentItem = {
119
- selectedItem: selectedItem,
120
- cat: _cat
121
- };
89
+ var selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
90
+ var catid = selectedItem.type;
91
+ findCatalogElement(catalog, catid);
122
92
  }
123
- layer.items.forEach(function (item) {
93
+ layer.items.forEach(function (other) {
124
94
  var val = {
125
95
  pos: {
126
- x: item.x,
127
- y: item.y
96
+ x: other.x,
97
+ y: other.y
128
98
  },
129
- rotRad: item.rotation / 180 * Math.PI
99
+ rotRad: other.rotation / 180 * Math.PI
130
100
  };
131
- var catid = item.type;
132
- var cat = findCatalogElement(catalog, catid);
133
- var width = convert(item.properties.getIn(['width', '_length'])).from('in').to('cm');
134
- var height = convert(item.properties.getIn(['depth', '_length'])).from('in').to('cm');
135
- // let width = cat.info.sizeinfo.width;
136
- // let height = cat.info.sizeinfo.depth;
101
+ var widthCm = convert(other.properties.getIn(['width', '_length'])).from('in').to('cm');
102
+ var heightCm = convert(other.properties.getIn(['depth', '_length'])).from('in').to('cm');
137
103
  val.size = {
138
- width: width,
139
- height: height
104
+ width: widthCm,
105
+ height: heightCm
140
106
  };
141
- var otherItem = {
142
- item: item,
143
- cat: cat
144
- };
145
-
146
- // if (!GeometryUtils.needSnap(currentItem, otherItem)) {
147
- // return;
148
- // }
149
-
150
- if (!item.selected) {
151
- var detectObjectsAtSameAltitudeFlag = layoutpos === 'Base' ? item.properties.getIn(['altitude', '_length']) <= altitude + tempHeight.get('_length') : item.properties.getIn(['altitude', '_length']) + item.properties.getIn(['height', '_length']) >= altitude;
107
+ if (!other.selected) {
108
+ var detectObjectsAtSameAltitudeFlag = layoutpos === 'Base' ? other.properties.getIn(['altitude', '_length']) <= altitude + tempHeightLen : other.properties.getIn(['altitude', '_length']) + other.properties.getIn(['height', '_length']) >= altitude;
152
109
  if (detectObjectsAtSameAltitudeFlag) {
153
- var _x = val.pos.x;
154
- var _y = val.pos.y;
110
+ var ox = val.pos.x;
111
+ var oy = val.pos.y;
155
112
  var rotRad = val.rotRad;
156
113
  var w = val.size.width / 2;
157
114
  var h = val.size.height / 2;
158
- var mx = _x - w * Math.cos(rotRad);
159
- var my = _y - w * Math.sin(rotRad);
115
+ var mx = ox - w * Math.cos(rotRad);
116
+ var my = oy - w * Math.sin(rotRad);
160
117
  var x0 = mx + h * Math.sin(rotRad);
161
118
  var y0 = my - h * Math.cos(rotRad);
162
119
  var x3 = mx * 2 - x0;
163
120
  var y3 = my * 2 - y0;
164
- var x1 = _x * 2 - x3;
165
- var y1 = _y * 2 - y3;
166
- var x2 = _x * 2 - x0;
167
- var y2 = _y * 2 - y0;
121
+ var x1 = ox * 2 - x3;
122
+ var y1 = oy * 2 - y3;
123
+ var x2 = ox * 2 - x0;
124
+ var y2 = oy * 2 - y0;
168
125
  rectarray.push({
169
126
  rect: [point(x0, y0), point(x1, y1), point(x0, y0), point(x1, y1)]
170
127
  });
@@ -180,126 +137,156 @@ export default function Item(_ref, _ref2) {
180
137
  }
181
138
  }
182
139
  });
183
-
184
- // layer.holes.forEach(hole => {
185
- // let val = {pos:{x:hole.x, y:hole.y}, rotRad:hole.rotation};
186
- // let catid = hole.type;
187
- // let cat = catalog.elements[catid];
188
- // let width = hole.properties.getIn(['width']).getIn(['length']);
189
- // let height = hole.properties.getIn(['height']).getIn(['length']);
190
- // val.size = {width, height};
191
- // let otherItem = {
192
- // hole,
193
- // cat
194
- // }
195
-
196
- // // if (!GeometryUtils.needSnap(currentItem, otherItem)) {
197
- // // return;
198
- // // }
199
-
200
- // if (!hole.selected) {
201
- // let x = val.pos.x;
202
- // let y = val.pos.y;
203
- // let rotRad = val.rotRad;
204
- // let w = val.size.width / 2;
205
- // let mx = x - w * Math.cos(rotRad);
206
- // let my = y - w * Math.sin(rotRad);
207
- // let kx = x + w * Math.cos(rotRad);
208
- // let ky = y + w * Math.sin(rotRad);
209
- // let x0 = mx - 10 * Math.sin(rotRad);
210
- // let y0 = my + 10 * Math.cos(rotRad);
211
- // let x3 = mx + 10 * Math.sin(rotRad);
212
- // let y3 = my - 10 * Math.cos(rotRad);
213
- // let x1 = kx - 10 * Math.sin(rotRad);
214
- // let y1 = ky + 10 * Math.cos(rotRad);
215
- // let x2 = kx + 10 * Math.sin(rotRad);
216
- // let y2 = ky - 10 * Math.cos(rotRad);
217
- // rectarray.push({'rect':[point(x0,y0), point(x1,y1) ,point(x0,y0), point(x1,y1)]});
218
- // rectarray.push({'rect':[point(x1,y1), point(x2,y2), point(x1,y1), point(x2,y2)]}); // right
219
- // rectarray.push({'rect':[point(x2,y2), point(x3,y3), point(x2,y2), point(x3,y3)]}); // front
220
- // rectarray.push({'rect':[point(x3,y3), point(x0,y0), point(x3,y3), point(x0,y0)]}); // left
221
- // }
222
- // });
223
140
  return {
224
141
  others: rectarray
225
142
  };
226
143
  }
227
- allItemRect = getAllItems();
228
- allLines = GeometryUtils.getAllLines(layer);
229
- allLineRects = GeometryUtils.buildRectFromLines(layer, allLines);
230
- var allRect = allLineRects.concat(allItemRect.others);
231
- curiteminfo = getCalcRectFromItem(val);
232
144
 
233
- /**
234
- *
235
- * @param x y position
236
- * @param y x position
237
- * @param rotRad item's rotation in radian
238
- */
239
- var getDistant = function getDistant(x, y, rotRad) {
240
- var center_h = 3 * height / 8;
241
- var center_x = x;
242
- var center_y = y;
243
- var center_x1 = x - center_h * Math.sin(rotRad);
244
- var center_y1 = y + center_h * Math.cos(rotRad);
245
- var PointArray = [];
246
- curiteminfo.rectCenterPoint.forEach(function (centerpoint) {
247
- var comparelength = [];
248
- var a;
249
- var RectLineFuction;
250
- if (centerpoint[1] === 180 || centerpoint[1] === 0) RectLineFuction = GeometryUtils.linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x1, center_y1);else RectLineFuction = GeometryUtils.linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x, center_y);
251
- allRect.forEach(function (linerect) {
252
- var p0 = GeometryUtils.clone_point(linerect.rect[2]);
253
- var p1 = GeometryUtils.clone_point(linerect.rect[3]);
254
- var lineFunction = {};
255
- if (p0.x !== p1.x || p0.y !== p1.y) lineFunction = GeometryUtils.linePassingThroughTwoPoints(p0.x, p0.y, p1.x, p1.y);
256
- var coordinatePoint = GeometryUtils.twoLinesIntersection(lineFunction.a, lineFunction.b, lineFunction.c, RectLineFuction.a, RectLineFuction.b, RectLineFuction.c);
257
- if (coordinatePoint !== undefined) {
258
- if (GeometryUtils.pointsDistance(p0.x, p0.y, p1.x, p1.y) > GeometryUtils.pointsDistance(p0.x, p0.y, coordinatePoint.x, coordinatePoint.y) && GeometryUtils.pointsDistance(p0.x, p0.y, p1.x, p1.y) > GeometryUtils.pointsDistance(p1.x, p1.y, coordinatePoint.x, coordinatePoint.y)) {
259
- if (GeometryUtils.pointsDistance(coordinatePoint.x, coordinatePoint.y, center_x, center_y) > GeometryUtils.pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y)) {
260
- comparelength.push(GeometryUtils.pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y));
261
- a = Math.min.apply(null, comparelength);
262
- }
145
+ // ----- item size -----
146
+ var tempWidth = item.properties.get('width');
147
+ var tempHeight = item.properties.get('depth');
148
+ var _useMemo = useMemo(function () {
149
+ var w, h;
150
+ if (tempWidth || tempHeight) {
151
+ w = convert(tempWidth.get('_length')).from(tempWidth.get('_unit')).to('cm');
152
+ h = convert(tempHeight.get('_length')).from(tempHeight.get('_unit')).to('cm');
153
+ } else {
154
+ w = convert(element.info.sizeinfo.width).from('in').to('cm');
155
+ h = convert(element.info.sizeinfo.depth).from('in').to('cm');
156
+ }
157
+ return {
158
+ width: w,
159
+ height: h
160
+ };
161
+ }, [tempWidth, tempHeight, element]),
162
+ width = _useMemo.width,
163
+ height = _useMemo.height;
164
+ var nw = width / 2;
165
+ var nh = height / 2;
166
+
167
+ // val used in geometry calc
168
+ var val = useMemo(function () {
169
+ return {
170
+ pos: {
171
+ x: item.x,
172
+ y: item.y
173
+ },
174
+ rotRad: item.rotation / 180 * Math.PI,
175
+ size: {
176
+ width: width,
177
+ height: height
178
+ }
179
+ };
180
+ }, [item.x, item.y, item.rotation, width, height]);
181
+
182
+ // ----- heavy geometry (memoized) -----
183
+ var _useMemo2 = useMemo(function () {
184
+ var allItemRect = getAllItemsRectangles({
185
+ layer: layer,
186
+ catalog: catalog,
187
+ layoutpos: layoutpos,
188
+ altitude: altitude,
189
+ tempHeightLen: tempHeight ? tempHeight.get('_length') : 0
190
+ });
191
+ var allLines = GeometryUtils.getAllLines(layer);
192
+ var allLineRects = GeometryUtils.buildRectFromLines(layer, allLines);
193
+ var allRect = allLineRects.concat(allItemRect.others);
194
+ var curiteminfo = getCalcRectFromItem(val);
195
+ var getDistant = function getDistant(px, py, rotRad) {
196
+ var center_h = 3 * height / 8;
197
+ var center_x = px;
198
+ var center_y = py;
199
+ var center_x1 = px - center_h * Math.sin(rotRad);
200
+ var center_y1 = py + center_h * Math.cos(rotRad);
201
+ var PointArray = [];
202
+ curiteminfo.rectCenterPoint.forEach(function (centerpoint) {
203
+ var a;
204
+ var RectLineFuction;
205
+ if (centerpoint[1] === 180 || centerpoint[1] === 0) {
206
+ RectLineFuction = GeometryUtils.linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x1, center_y1);
207
+ } else {
208
+ RectLineFuction = GeometryUtils.linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x, center_y);
263
209
  }
210
+ var comparelength = [];
211
+ allRect.forEach(function (linerect) {
212
+ var p0 = GeometryUtils.clone_point(linerect.rect[2]);
213
+ var p1 = GeometryUtils.clone_point(linerect.rect[3]);
214
+ var lineFunction = {};
215
+ if (p0.x !== p1.x || p0.y !== p1.y) {
216
+ lineFunction = GeometryUtils.linePassingThroughTwoPoints(p0.x, p0.y, p1.x, p1.y);
217
+ }
218
+ var coordinatePoint = GeometryUtils.twoLinesIntersection(lineFunction.a, lineFunction.b, lineFunction.c, RectLineFuction.a, RectLineFuction.b, RectLineFuction.c);
219
+ if (coordinatePoint !== undefined) {
220
+ if (GeometryUtils.pointsDistance(p0.x, p0.y, p1.x, p1.y) > GeometryUtils.pointsDistance(p0.x, p0.y, coordinatePoint.x, coordinatePoint.y) && GeometryUtils.pointsDistance(p0.x, p0.y, p1.x, p1.y) > GeometryUtils.pointsDistance(p1.x, p1.y, coordinatePoint.x, coordinatePoint.y)) {
221
+ if (GeometryUtils.pointsDistance(coordinatePoint.x, coordinatePoint.y, center_x, center_y) > GeometryUtils.pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y)) {
222
+ comparelength.push(GeometryUtils.pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y));
223
+ a = Math.min.apply(null, comparelength);
224
+ }
225
+ }
226
+ }
227
+ });
228
+ PointArray.push([a, centerpoint[1]]);
229
+ });
230
+ return {
231
+ PointArray: PointArray
232
+ };
233
+ };
234
+ var _getDistant = getDistant(x, y, val.rotRad),
235
+ PointArray = _getDistant.PointArray;
236
+ var catid = item.type;
237
+ var catLocal = catalog.elements[catid];
238
+
239
+ // normalize like your original code
240
+ PointArray.forEach(function (pointElement, index) {
241
+ if (pointElement[0] == undefined) PointArray[index][0] = 0;
242
+ if (pointElement[1] === -90 && catLocal.info.is_corner !== 1) {
243
+ PointArray[index][0] -= 4;
264
244
  }
265
245
  });
266
- PointArray.push([a, centerpoint[1]]);
267
- });
268
- return {
269
- PointArray: PointArray
270
- };
271
- };
272
- var nw = width / 2;
273
- var nh = height / 2;
274
- var _getDistant = getDistant(x, y, val.rotRad),
275
- PointArray = _getDistant.PointArray;
276
- var catid = item.type;
277
- var cat = catalog.elements[catid];
278
- PointArray.forEach(function (pointElement, index) {
279
- if (pointElement[0] == undefined) PointArray[index][0] = 0;
280
- if (pointElement[1] === -90 && cat.info.is_corner !== 1) {
281
- PointArray[index][0] -= 4;
282
- }
283
- });
284
- if (Array.isArray(PointArray)) {
285
- itemsActions.storeDistArray(layerID, id, PointArray);
286
- }
287
- var renderedRuler = [];
288
- var ep = 0.1;
289
- if (item.selected) {
290
- PointArray.forEach(function (element, key) {
246
+ return {
247
+ pointArray: PointArray,
248
+ cat: catLocal
249
+ };
250
+ }, [layer, catalog, layoutpos, altitude, tempHeight, item.type, x, y, val, height]),
251
+ pointArray = _useMemo2.pointArray,
252
+ cat = _useMemo2.cat;
253
+
254
+ // ----- FIX: dispatch AFTER render (no setState/dispatch in render) -----
255
+ var lastSigRef = useRef('');
256
+ useEffect(function () {
257
+ if (!Array.isArray(pointArray)) return;
258
+
259
+ // small signature to prevent dispatching repeatedly with same values
260
+ // rounding reduces noise from floating point jitter
261
+ var sig = pointArray.map(function (_ref3) {
262
+ var _ref4 = _slicedToArray(_ref3, 2),
263
+ dist = _ref4[0],
264
+ dir = _ref4[1];
265
+ return "".concat(dir, ":").concat(Math.round((dist || 0) * 1000));
266
+ }).join('|');
267
+ if (sig === lastSigRef.current) return;
268
+ lastSigRef.current = sig;
269
+ itemsActions.storeDistArray(layerID, id, pointArray);
270
+ }, [itemsActions, layerID, id, pointArray]);
271
+
272
+ // ----- rulers -----
273
+ var renderedRuler = useMemo(function () {
274
+ var rulers = [];
275
+ var ep = 0.1;
276
+ if (!item.selected || !Array.isArray(pointArray)) return rulers;
277
+ pointArray.forEach(function (element, key) {
291
278
  var itemDistanceFromLine = element[0];
292
- var length = itemDistanceFromLine;
279
+ var dir = element[1];
293
280
  if (itemDistanceFromLine > ep || itemDistanceFromLine < -ep) {
294
- renderedRuler.push(/*#__PURE__*/React.createElement("g", {
281
+ rulers.push(/*#__PURE__*/React.createElement("g", {
295
282
  "data-element-root": true,
296
283
  "data-prototype": "rulerDist",
297
284
  "data-id": item.id,
298
285
  "data-selected": item.selected,
299
286
  "data-layer": layer.id,
300
287
  key: key,
301
- "data-length": length,
302
- "data-direct": element[1]
288
+ "data-length": itemDistanceFromLine,
289
+ "data-direct": dir
303
290
  }, /*#__PURE__*/React.createElement(RulerDist, {
304
291
  key: key,
305
292
  layer: layer,
@@ -307,126 +294,126 @@ export default function Item(_ref, _ref2) {
307
294
  rulerUnit: scene.rulerUnit,
308
295
  length: itemDistanceFromLine,
309
296
  angle: rotation,
310
- rotation: element[1],
311
- transform: "translate(".concat(element[1] === 180 ? -nw : element[1] === 0 ? nw : 0, ", ").concat(element[1] === 90 ? nh : element[1] === -90 ? cat.info.is_corner !== 1 ? -(nh + 4) : -nh : 0, ") rotate(").concat(element[1], ", 0, 0)")
297
+ rotation: dir,
298
+ transform: "translate(".concat(dir === 180 ? -nw : dir === 0 ? nw : 0, ", ").concat(dir === 90 ? nh : dir === -90 ? cat.info.is_corner !== 1 ? -(nh + 4) : -nh : 0, ") rotate(").concat(dir, ", 0, 0)")
312
299
  })));
313
300
  }
314
301
  });
315
- }
302
+ return rulers;
303
+ }, [item.selected, pointArray, item.id, layer, scene.unit, scene.rulerUnit, rotation, nw, nh, cat]);
304
+
305
+ // ----- rendered item -----
316
306
  var renderedItem = element === null || element === void 0 || (_element$render2D = element.render2D) === null || _element$render2D === void 0 ? void 0 : _element$render2D.call(element, item, layer, scene);
317
- var isSmall = false;
318
- if (width < 40) isSmall = true;
319
- var parts = [];
320
- var newWidth = item.toJS().properties.width.length;
321
- if (item.selected) parts = [/*#__PURE__*/React.createElement("g", {
322
- key: 0,
323
- "data-element-root": true,
324
- "data-prototype": item.prototype,
325
- "data-id": item.id,
326
- "data-selected": item.selected,
327
- "data-layer": layer.id,
328
- "data-part": "rotation-anchor",
329
- style: {
330
- cursor: 'w-resize'
331
- }
332
- }, /*#__PURE__*/React.createElement("image", {
333
- href: clockRotateState ? '/assets/img/svg/rotate.png' : '/assets/img/svg/blank_div.svg',
334
- style: {
335
- transform: "scale(-1, -1) translate(".concat(width / 2, "px, ").concat(height / 2, "px) rotate(25deg)")
336
- },
337
- height: "20",
338
- width: "20",
339
- onMouseEnter: function onMouseEnter() {
340
- setClockRotateState(true);
341
- setAntiClockRotateState(false);
342
- },
343
- onMouseLeave: function onMouseLeave() {
344
- return setClockRotateState(mode === MODE_ROTATING_ITEM ? true : false);
345
- }
346
- }), /*#__PURE__*/React.createElement("image", {
347
- href: antiClockRotateState ? '/assets/img/svg/rotate.png' : '/assets/img/svg/blank_div.svg',
348
- style: {
349
- transform: "scale(1, -1) translate(".concat(width / 2, "px, ").concat(height / 2, "px) rotate(25deg)")
350
- },
351
- height: "20",
352
- width: "20",
353
- onMouseEnter: function onMouseEnter() {
354
- setAntiClockRotateState(true);
355
- setClockRotateState(false);
356
- },
357
- onMouseLeave: function onMouseLeave() {
358
- return setAntiClockRotateState(mode === MODE_ROTATING_ITEM ? true : false);
359
- }
360
- })), /*#__PURE__*/React.createElement("g", {
361
- key: 1
362
- // transform={`translate(${-width / 2 - (!isSmall ? 40 : 0)},${height / 2 + 40})`}
363
- ,
364
- style: {
365
- cursor: 'pointer',
366
- transform: "rotate(".concat(360 - item.rotation, "deg) translate(").concat(-width / 2 - 27, "px, ", 0, "px)")
367
- },
368
- "data-element-root": true,
369
- "data-prototype": item.prototype,
370
- "data-id": item.id,
371
- "data-selected": item.selected,
372
- "data-layer": layer.id,
373
- "data-part": "duplicate"
374
- }, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("filter", {
375
- id: "shadow"
376
- }, /*#__PURE__*/React.createElement("feDropShadow", {
377
- dx: "0",
378
- dy: "0",
379
- stdDeviation: "0.6"
380
- }))), /*#__PURE__*/React.createElement("rect", {
381
- rx: "4",
382
- ry: "4",
383
- height: "22",
384
- width: "22",
385
- fill: "white",
386
- filter: "url(#shadow)"
387
- }), /*#__PURE__*/React.createElement("image", {
388
- href: "/assets/img/svg/duplicate.svg",
389
- x: "3",
390
- y: "-19",
391
- height: "16",
392
- width: "16",
393
- style: isWarningItem(item) ? {
394
- transform: 'rotateX(180deg)',
395
- opacity: 0.5
396
- } : {
397
- transform: 'rotateX(180deg)'
398
- }
399
- })), /*#__PURE__*/React.createElement("g", {
400
- key: 2
401
- // transform={`translate(${-width / 2 - (!isSmall ? 40 : 0)},${height / 2})`}
402
- ,
403
- style: {
404
- cursor: 'pointer',
405
- transform: "rotate(".concat(360 - item.rotation, "deg) translate(").concat(-width / 2 - 27, "px, ").concat(-27, "px)")
406
- },
407
- "data-element-root": true,
408
- "data-prototype": item.prototype,
409
- "data-id": item.id,
410
- "data-selected": item.selected,
411
- "data-layer": layer.id,
412
- "data-part": "remove"
413
- }, /*#__PURE__*/React.createElement("rect", {
414
- rx: "4",
415
- ry: "4",
416
- height: "22",
417
- width: "22",
418
- fill: "white",
419
- filter: "url(#shadow)"
420
- }), /*#__PURE__*/React.createElement("image", {
421
- href: "/assets/img/svg/delete.svg",
422
- x: "3",
423
- y: "-19",
424
- height: "16",
425
- width: "16",
426
- style: {
427
- transform: 'rotateX(180deg)'
428
- }
429
- }))];
307
+
308
+ // ----- action icons -----
309
+ var parts = useMemo(function () {
310
+ if (!item.selected) return [];
311
+ return [/*#__PURE__*/React.createElement("g", {
312
+ key: 0,
313
+ "data-element-root": true,
314
+ "data-prototype": item.prototype,
315
+ "data-id": item.id,
316
+ "data-selected": item.selected,
317
+ "data-layer": layer.id,
318
+ "data-part": "rotation-anchor",
319
+ style: {
320
+ cursor: 'w-resize'
321
+ }
322
+ }, /*#__PURE__*/React.createElement("image", {
323
+ href: clockRotateState ? '/assets/img/svg/rotate.png' : '/assets/img/svg/blank_div.svg',
324
+ style: {
325
+ transform: "scale(-1, -1) translate(".concat(width / 2, "px, ").concat(height / 2, "px) rotate(25deg)")
326
+ },
327
+ height: "20",
328
+ width: "20",
329
+ onMouseEnter: function onMouseEnter() {
330
+ setClockRotateState(true);
331
+ setAntiClockRotateState(false);
332
+ },
333
+ onMouseLeave: function onMouseLeave() {
334
+ return setClockRotateState(mode === MODE_ROTATING_ITEM ? true : false);
335
+ }
336
+ }), /*#__PURE__*/React.createElement("image", {
337
+ href: antiClockRotateState ? '/assets/img/svg/rotate.png' : '/assets/img/svg/blank_div.svg',
338
+ style: {
339
+ transform: "scale(1, -1) translate(".concat(width / 2, "px, ").concat(height / 2, "px) rotate(25deg)")
340
+ },
341
+ height: "20",
342
+ width: "20",
343
+ onMouseEnter: function onMouseEnter() {
344
+ setAntiClockRotateState(true);
345
+ setClockRotateState(false);
346
+ },
347
+ onMouseLeave: function onMouseLeave() {
348
+ return setAntiClockRotateState(mode === MODE_ROTATING_ITEM ? true : false);
349
+ }
350
+ })), /*#__PURE__*/React.createElement("g", {
351
+ key: 1,
352
+ style: {
353
+ cursor: 'pointer',
354
+ transform: "rotate(".concat(360 - item.rotation, "deg) translate(").concat(-width / 2 - 27, "px, ", 0, "px)")
355
+ },
356
+ "data-element-root": true,
357
+ "data-prototype": item.prototype,
358
+ "data-id": item.id,
359
+ "data-selected": item.selected,
360
+ "data-layer": layer.id,
361
+ "data-part": "duplicate"
362
+ }, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("filter", {
363
+ id: "shadow"
364
+ }, /*#__PURE__*/React.createElement("feDropShadow", {
365
+ dx: "0",
366
+ dy: "0",
367
+ stdDeviation: "0.6"
368
+ }))), /*#__PURE__*/React.createElement("rect", {
369
+ rx: "4",
370
+ ry: "4",
371
+ height: "22",
372
+ width: "22",
373
+ fill: "white",
374
+ filter: "url(#shadow)"
375
+ }), /*#__PURE__*/React.createElement("image", {
376
+ href: "/assets/img/svg/duplicate.svg",
377
+ x: "3",
378
+ y: "-19",
379
+ height: "16",
380
+ width: "16",
381
+ style: isWarningItem(item) ? {
382
+ transform: 'rotateX(180deg)',
383
+ opacity: 0.5
384
+ } : {
385
+ transform: 'rotateX(180deg)'
386
+ }
387
+ })), /*#__PURE__*/React.createElement("g", {
388
+ key: 2,
389
+ style: {
390
+ cursor: 'pointer',
391
+ transform: "rotate(".concat(360 - item.rotation, "deg) translate(").concat(-width / 2 - 27, "px, ").concat(-27, "px)")
392
+ },
393
+ "data-element-root": true,
394
+ "data-prototype": item.prototype,
395
+ "data-id": item.id,
396
+ "data-selected": item.selected,
397
+ "data-layer": layer.id,
398
+ "data-part": "remove"
399
+ }, /*#__PURE__*/React.createElement("rect", {
400
+ rx: "4",
401
+ ry: "4",
402
+ height: "22",
403
+ width: "22",
404
+ fill: "white",
405
+ filter: "url(#shadow)"
406
+ }), /*#__PURE__*/React.createElement("image", {
407
+ href: "/assets/img/svg/delete.svg",
408
+ x: "3",
409
+ y: "-19",
410
+ height: "16",
411
+ width: "16",
412
+ style: {
413
+ transform: 'rotateX(180deg)'
414
+ }
415
+ }))];
416
+ }, [item.selected, item.prototype, item.id, item.rotation, layer.id, clockRotateState, antiClockRotateState, width, height, mode, item]);
430
417
  var measure = item.layoutpos === WALL_CABINET_LAYOUTPOS ? showWallCabinetMeasure : showBaseCabinetMeasure;
431
418
  return /*#__PURE__*/React.createElement("g", {
432
419
  "data-element-root": true,
@@ -449,7 +436,4 @@ Item.propTypes = {
449
436
  layer: PropTypes.object.isRequired,
450
437
  scene: PropTypes.object.isRequired,
451
438
  catalog: PropTypes.object.isRequired
452
- };
453
- Item.contextTypes = {
454
- itemsActions: PropTypes.object.isRequired
455
439
  };