kitchen-simulator 7.0.6-react-18 → 7.0.8-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.
@@ -1,8 +1,6 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import React, { useCallback, useEffect, useRef, useState } from 'react';
5
- import { useResizeDetector } from 'react-resize-detector';
3
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
6
4
  import mockProps from "./mocks/mockProps.json";
7
5
  import projectItemsCatalog from "./mocks/projectItemsCatalog.json";
8
6
  import renderKitchenSimulator from "./index";
@@ -12,49 +10,58 @@ var options = {
12
10
  enable3D: true
13
11
  };
14
12
  export default function WorkSpaceHostMimic() {
15
- var _useResizeDetector = useResizeDetector(),
16
- width = _useResizeDetector.width,
17
- height = _useResizeDetector.height,
18
- sizeRef = _useResizeDetector.ref;
19
13
  var mountRef = useRef(null);
20
14
  var apiRef = useRef(null);
21
- var sentOnceRef = useRef(false);
22
- var _useState = useState(0),
23
- _useState2 = _slicedToArray(_useState, 2),
24
- inFlight = _useState2[0],
25
- setInFlight = _useState2[1];
26
- var rafRef = useRef(0);
27
- var onInternalEvent = /*#__PURE__*/function () {
15
+ var loadedRef = useRef(false);
16
+ var onInternalEvent = useCallback(/*#__PURE__*/function () {
28
17
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(evt, callback) {
29
- var _t;
30
18
  return _regeneratorRuntime.wrap(function (_context) {
31
19
  while (1) switch (_context.prev = _context.next) {
32
20
  case 0:
33
- console.log('EVENT:', evt.type, evt.value);
34
- _t = evt.type;
35
- _context.next = _t === INTERNAL_EVENT_ITEMS_CATALOG ? 1 : 3;
36
- break;
37
- case 1:
38
- _context.next = 2;
21
+ if (!(evt.type === INTERNAL_EVENT_ITEMS_CATALOG)) {
22
+ _context.next = 1;
23
+ break;
24
+ }
25
+ _context.next = 1;
39
26
  return callback(projectItemsCatalog);
40
- case 2:
41
- return _context.abrupt("continue", 3);
42
- case 3:
27
+ case 1:
43
28
  case "end":
44
29
  return _context.stop();
45
30
  }
46
31
  }, _callee);
47
32
  }));
48
- return function onInternalEvent(_x, _x2) {
33
+ return function (_x, _x2) {
49
34
  return _ref.apply(this, arguments);
50
35
  };
51
- }();
36
+ }(), []);
37
+ var renderWindow = useCallback(function () {
38
+ var _api$__render;
39
+ var api = apiRef.current;
40
+ if (!api) return;
41
+ console.log({
42
+ width: window.innerWidth,
43
+ height: window.innerHeight
44
+ });
45
+ (_api$__render = api.__render) === null || _api$__render === void 0 || _api$__render.call(api, {
46
+ width: window.innerWidth,
47
+ height: window.innerHeight,
48
+ configData: mockProps.configData,
49
+ options: options,
50
+ logoImg: '/assets/logo.png',
51
+ companyUrl: 'https://example.com',
52
+ toolbarButtons: [],
53
+ onInternalEvent: onInternalEvent,
54
+ onError: function onError(payload) {
55
+ return console.error('TOOL ERROR:', payload);
56
+ }
57
+ });
58
+ }, [onInternalEvent]);
52
59
  useEffect(function () {
53
60
  if (!mountRef.current) return;
54
61
  if (apiRef.current) return;
55
62
  var api = renderKitchenSimulator(mountRef.current, {
56
- width: width !== null && width !== void 0 ? width : window.innerWidth,
57
- height: height !== null && height !== void 0 ? height : window.innerHeight,
63
+ width: window.innerWidth,
64
+ height: window.innerHeight,
58
65
  configData: mockProps.configData,
59
66
  options: options,
60
67
  logoImg: '/assets/logo.png',
@@ -66,38 +73,36 @@ export default function WorkSpaceHostMimic() {
66
73
  }
67
74
  });
68
75
  apiRef.current = api;
69
- var unsub = typeof api.subscribeGltfInFlight === 'function' ? api.subscribeGltfInFlight(function (count) {
70
- return setInFlight(count);
71
- }) : null;
72
76
  _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
73
- var ok;
74
77
  return _regeneratorRuntime.wrap(function (_context2) {
75
78
  while (1) switch (_context2.prev = _context2.next) {
76
79
  case 0:
77
- if (!sentOnceRef.current) {
80
+ if (!loadedRef.current) {
78
81
  _context2.next = 1;
79
82
  break;
80
83
  }
81
84
  return _context2.abrupt("return");
82
85
  case 1:
83
- sentOnceRef.current = true;
84
-
85
- // await api.whenReady();
86
+ loadedRef.current = true;
86
87
 
87
- // send center with EMPTY payload
88
+ // ensure a render tick happened first
89
+ renderWindow();
88
90
  _context2.next = 2;
91
+ return new Promise(function (r) {
92
+ return requestAnimationFrame(function () {
93
+ return requestAnimationFrame(r);
94
+ });
95
+ });
96
+ case 2:
97
+ _context2.next = 3;
89
98
  return api.sendExternalEvents([{
90
99
  type: EXTERNAL_EVENT_LOAD_PROJECT,
91
- // send request for sync scene data to 3DTool
92
100
  payload: JSON.parse(mockProps.projectElement[0].project_data),
93
101
  framesPerEvent: 2,
94
102
  waitForGltfIdleAfterEachEvent: false
95
103
  }], {
96
104
  timeoutMs: 15000
97
105
  });
98
- case 2:
99
- ok = _context2.sent;
100
- if (!ok) console.warn('Centering timed out (fail-open).');
101
106
  case 3:
102
107
  case "end":
103
108
  return _context2.stop();
@@ -106,69 +111,22 @@ export default function WorkSpaceHostMimic() {
106
111
  }))();
107
112
  return function () {
108
113
  var _apiRef$current, _apiRef$current$unmou;
109
- try {
110
- unsub === null || unsub === void 0 || unsub();
111
- } catch (_unused) {}
112
114
  (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || (_apiRef$current$unmou = _apiRef$current.unmount) === null || _apiRef$current$unmou === void 0 || _apiRef$current$unmou.call(_apiRef$current);
113
115
  apiRef.current = null;
114
- sentOnceRef.current = false;
115
- };
116
- // eslint-disable-next-line react-hooks/exhaustive-deps
117
- }, []);
118
- useEffect(function () {
119
- var api = apiRef.current;
120
- if (!api) return;
121
- cancelAnimationFrame(rafRef.current);
122
- rafRef.current = requestAnimationFrame(function () {
123
- var _api$__render;
124
- (_api$__render = api.__render) === null || _api$__render === void 0 || _api$__render.call(api, {
125
- width: width !== null && width !== void 0 ? width : window.innerWidth,
126
- height: height !== null && height !== void 0 ? height : window.innerHeight,
127
- configData: mockProps.configData,
128
- options: options,
129
- logoImg: '/assets/logo.png',
130
- companyUrl: 'https://example.com',
131
- toolbarButtons: [],
132
- onInternalEvent: onInternalEvent,
133
- onError: function onError(payload) {
134
- return console.error('TOOL ERROR:', payload);
135
- }
136
- });
137
- });
138
- return function () {
139
- return cancelAnimationFrame(rafRef.current);
116
+ loadedRef.current = false;
140
117
  };
141
- }, [width, height, onInternalEvent]);
118
+ }, [onInternalEvent, renderWindow]);
142
119
  return /*#__PURE__*/React.createElement("div", {
143
120
  style: {
144
121
  width: '100vw',
145
- height: '100vh'
122
+ height: '100vh',
123
+ position: 'relative'
146
124
  }
147
125
  }, /*#__PURE__*/React.createElement("div", {
148
- ref: sizeRef,
149
- style: {
150
- width: '100%',
151
- height: '100%'
152
- }
153
- }, inFlight > 0 ? /*#__PURE__*/React.createElement("div", {
154
- style: {
155
- position: 'absolute',
156
- zIndex: 9999,
157
- top: 12,
158
- right: 12,
159
- padding: '8px 10px',
160
- borderRadius: 8,
161
- background: 'rgba(0,0,0,0.6)',
162
- color: 'white',
163
- fontSize: 12,
164
- pointerEvents: 'none'
165
- }
166
- }, "Loading 3D\u2026 (", inFlight, ")") : null, /*#__PURE__*/React.createElement("div", {
167
126
  ref: mountRef,
168
- id: "kitchen-simulator-container",
169
127
  style: {
170
128
  width: '100%',
171
129
  height: '100%'
172
130
  }
173
- })));
131
+ }));
174
132
  }
@@ -145,8 +145,26 @@ var Project = /*#__PURE__*/function () {
145
145
  var h = bb.maxY - bb.minY;
146
146
  if (w != 0 && Math.abs(w) != Infinity && h != 0 && Math.abs(h) != Infinity) {
147
147
  a = viewer.viewerHeight < h ? viewer.viewerHeight / h : (viewer.viewerHeight / h * 3 / 5 - 0.5) / constants.ZOOM_VARIABLE > 400 ? viewer.viewerHeight / h * 400 / ((viewer.viewerHeight / h - 0.5) / constants.ZOOM_VARIABLE) : viewer.viewerHeight / h * 3 / 5;
148
- e = (viewer.viewerWidth - (bb.maxX + bb.minX) * a) / 2;
149
- f = (viewer.viewerHeight - (bb.maxY + bb.minY) * a) / 2;
148
+ var scaledWidth = a * viewer.SVGWidth;
149
+ var scaledHeight = a * viewer.SVGHeight;
150
+
151
+ // Horizontal
152
+ if (scaledWidth <= viewer.viewerWidth) {
153
+ e = (viewer.viewerWidth - scaledWidth) / 2;
154
+ } else {
155
+ var maxE = 10;
156
+ var minE = viewer.viewerWidth - (scaledWidth + 10);
157
+ e = Math.min(maxE, Math.max(minE, e));
158
+ }
159
+
160
+ // Vertical
161
+ if (scaledHeight <= viewer.viewerHeight) {
162
+ f = (viewer.viewerHeight - scaledHeight) / 2;
163
+ } else {
164
+ var maxF = 80;
165
+ var minF = viewer.viewerHeight - (scaledHeight + 10);
166
+ f = Math.min(maxF, Math.max(minF, f));
167
+ }
150
168
  _viewer2D = _viewer2D.merge({
151
169
  a: a,
152
170
  d: a,
@@ -165,9 +183,11 @@ var Project = /*#__PURE__*/function () {
165
183
  doorStyle: doorStyle,
166
184
  viewer2D: _viewer2D
167
185
  });
186
+ state = centering2D(state, viewer2DActions);
168
187
  state = Item.setCounterTop(state, counterTop).updatedState;
169
188
  state = Area.setFloorStyles(state, floorStyle).updatedState;
170
189
  this.updateZoomScale(state, a);
190
+ viewer2DActions.updateCameraView(_viewer2D);
171
191
  return {
172
192
  updatedState: state
173
193
  };
@@ -1,5 +1,7 @@
1
1
  import { CHANGE_BASE_CABINET_MEASURE, CHANGE_WALL_CABINET_MEASURE, CHANGE_WALL_LENGTH_MEASURE, CHANGE_WINDOW_DOOR_MEASURE, MODE_2D_PAN, MODE_2D_ZOOM_IN, MODE_2D_ZOOM_OUT, SELECT_TOOL_PAN, SELECT_TOOL_ZOOM_IN, SELECT_TOOL_ZOOM_OUT, UPDATE_2D_CAMERA, UPDATE_CEIL_HEIGHT, UPDATE_CEIL_HEIGHT_UNIT } from "../constants";
2
2
  import { convert } from "../utils/convert-units-lite";
3
+ import { centering2D } from "../utils/helper";
4
+ import * as viewer2DActions from "../actions/viewer2d-actions";
3
5
  export default function (state, action) {
4
6
  var _state = state,
5
7
  scene = _state.scene;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitchen-simulator",
3
- "version": "7.0.6-react-18",
3
+ "version": "7.0.8-react-18",
4
4
  "description": "It is a kitchen simulator (self-contained micro-frontend).",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",