kitchen-simulator 7.0.6-react-18 → 7.0.7-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,54 @@ 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
+ (_api$__render = api.__render) === null || _api$__render === void 0 || _api$__render.call(api, {
42
+ width: window.innerWidth,
43
+ height: window.innerHeight,
44
+ configData: mockProps.configData,
45
+ options: options,
46
+ logoImg: '/assets/logo.png',
47
+ companyUrl: 'https://example.com',
48
+ toolbarButtons: [],
49
+ onInternalEvent: onInternalEvent,
50
+ onError: function onError(payload) {
51
+ return console.error('TOOL ERROR:', payload);
52
+ }
53
+ });
54
+ }, [onInternalEvent]);
52
55
  useEffect(function () {
53
56
  if (!mountRef.current) return;
54
57
  if (apiRef.current) return;
55
58
  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,
59
+ width: window.innerWidth,
60
+ height: window.innerHeight,
58
61
  configData: mockProps.configData,
59
62
  options: options,
60
63
  logoImg: '/assets/logo.png',
@@ -66,38 +69,36 @@ export default function WorkSpaceHostMimic() {
66
69
  }
67
70
  });
68
71
  apiRef.current = api;
69
- var unsub = typeof api.subscribeGltfInFlight === 'function' ? api.subscribeGltfInFlight(function (count) {
70
- return setInFlight(count);
71
- }) : null;
72
72
  _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
73
- var ok;
74
73
  return _regeneratorRuntime.wrap(function (_context2) {
75
74
  while (1) switch (_context2.prev = _context2.next) {
76
75
  case 0:
77
- if (!sentOnceRef.current) {
76
+ if (!loadedRef.current) {
78
77
  _context2.next = 1;
79
78
  break;
80
79
  }
81
80
  return _context2.abrupt("return");
82
81
  case 1:
83
- sentOnceRef.current = true;
82
+ loadedRef.current = true;
84
83
 
85
- // await api.whenReady();
86
-
87
- // ✅ send center with EMPTY payload
84
+ // ensure a render tick happened first
85
+ renderWindow();
88
86
  _context2.next = 2;
87
+ return new Promise(function (r) {
88
+ return requestAnimationFrame(function () {
89
+ return requestAnimationFrame(r);
90
+ });
91
+ });
92
+ case 2:
93
+ _context2.next = 3;
89
94
  return api.sendExternalEvents([{
90
95
  type: EXTERNAL_EVENT_LOAD_PROJECT,
91
- // send request for sync scene data to 3DTool
92
96
  payload: JSON.parse(mockProps.projectElement[0].project_data),
93
97
  framesPerEvent: 2,
94
98
  waitForGltfIdleAfterEachEvent: false
95
99
  }], {
96
100
  timeoutMs: 15000
97
101
  });
98
- case 2:
99
- ok = _context2.sent;
100
- if (!ok) console.warn('Centering timed out (fail-open).');
101
102
  case 3:
102
103
  case "end":
103
104
  return _context2.stop();
@@ -106,69 +107,22 @@ export default function WorkSpaceHostMimic() {
106
107
  }))();
107
108
  return function () {
108
109
  var _apiRef$current, _apiRef$current$unmou;
109
- try {
110
- unsub === null || unsub === void 0 || unsub();
111
- } catch (_unused) {}
112
110
  (_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
111
  apiRef.current = null;
114
- sentOnceRef.current = false;
112
+ loadedRef.current = false;
115
113
  };
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);
140
- };
141
- }, [width, height, onInternalEvent]);
114
+ }, [onInternalEvent, renderWindow]);
142
115
  return /*#__PURE__*/React.createElement("div", {
143
116
  style: {
144
117
  width: '100vw',
145
- height: '100vh'
118
+ height: '100vh',
119
+ position: 'relative'
146
120
  }
147
121
  }, /*#__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
122
  ref: mountRef,
168
- id: "kitchen-simulator-container",
169
123
  style: {
170
124
  width: '100%',
171
125
  height: '100%'
172
126
  }
173
- })));
127
+ }));
174
128
  }
@@ -146,7 +146,13 @@ var Project = /*#__PURE__*/function () {
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
148
  e = (viewer.viewerWidth - (bb.maxX + bb.minX) * a) / 2;
149
- f = (viewer.viewerHeight - (bb.maxY + bb.minY) * a) / 2;
149
+ f = (viewer.viewerHeight - (viewer.SVGHeight * 2 - bb.maxY - bb.minY) * a) / 2;
150
+ var maxE = 10;
151
+ var minE = viewer.viewerWidth - (a * viewer.SVGWidth + 10);
152
+ e = Math.min(maxE, Math.max(minE, e));
153
+ var maxF = 80;
154
+ var minF = viewer.viewerHeight - (a * viewer.SVGHeight + 10);
155
+ f = Math.min(maxF, Math.max(minF, f));
150
156
  _viewer2D = _viewer2D.merge({
151
157
  a: a,
152
158
  d: a,
@@ -168,6 +174,7 @@ var Project = /*#__PURE__*/function () {
168
174
  state = Item.setCounterTop(state, counterTop).updatedState;
169
175
  state = Area.setFloorStyles(state, floorStyle).updatedState;
170
176
  this.updateZoomScale(state, a);
177
+ viewer2DActions.updateCameraView(_viewer2D);
171
178
  return {
172
179
  updatedState: state
173
180
  };
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.7-react-18",
4
4
  "description": "It is a kitchen simulator (self-contained micro-frontend).",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",