kitchen-simulator 7.0.3-react-18 → 7.0.5-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,6 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import React, { useEffect, useRef } from 'react';
4
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
4
5
  import { useResizeDetector } from 'react-resize-detector';
5
6
  import mockProps from "./mocks/mockProps.json";
6
7
  import projectItemsCatalog from "./mocks/projectItemsCatalog.json";
@@ -10,68 +11,47 @@ var options = {
10
11
  unit: 'in',
11
12
  enable3D: true
12
13
  };
13
- var onInternalEvent = /*#__PURE__*/function () {
14
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(evt, callback) {
15
- var _t, _t2;
16
- return _regeneratorRuntime.wrap(function (_context) {
17
- while (1) switch (_context.prev = _context.next) {
18
- case 0:
19
- console.log('INTERNAL:', evt.type);
20
- _context.prev = 1;
21
- if (!(evt.type === INTERNAL_EVENT_ITEMS_CATALOG)) {
22
- _context.next = 3;
23
- break;
24
- }
25
- _context.next = 2;
26
- return callback === null || callback === void 0 ? void 0 : callback(projectItemsCatalog);
27
- case 2:
28
- return _context.abrupt("return");
29
- case 3:
30
- _context.next = 4;
31
- return callback === null || callback === void 0 ? void 0 : callback();
32
- case 4:
33
- _context.next = 9;
34
- break;
35
- case 5:
36
- _context.prev = 5;
37
- _t = _context["catch"](1);
38
- console.error('onInternalEvent failed', _t);
39
- // still try to ack to avoid deadlocks
40
- _context.prev = 6;
41
- _context.next = 7;
42
- return callback === null || callback === void 0 ? void 0 : callback();
43
- case 7:
44
- _context.next = 9;
45
- break;
46
- case 8:
47
- _context.prev = 8;
48
- _t2 = _context["catch"](6);
49
- case 9:
50
- case "end":
51
- return _context.stop();
52
- }
53
- }, _callee, null, [[1, 5], [6, 8]]);
54
- }));
55
- return function onInternalEvent(_x, _x2) {
56
- return _ref.apply(this, arguments);
57
- };
58
- }();
59
- function WorkSpaceHostMimic() {
14
+ export default function WorkSpaceHostMimic() {
60
15
  var _useResizeDetector = useResizeDetector(),
61
16
  width = _useResizeDetector.width,
62
17
  height = _useResizeDetector.height,
63
18
  sizeRef = _useResizeDetector.ref;
64
-
65
- // ✅ pure JS refs
66
19
  var mountRef = useRef(null);
67
20
  var apiRef = useRef(null);
68
- console.log('render WorkSpaceHostMimic');
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 () {
28
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(evt, callback) {
29
+ var _t;
30
+ return _regeneratorRuntime.wrap(function (_context) {
31
+ while (1) switch (_context.prev = _context.next) {
32
+ 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;
39
+ return callback(projectItemsCatalog);
40
+ case 2:
41
+ return _context.abrupt("continue", 3);
42
+ case 3:
43
+ case "end":
44
+ return _context.stop();
45
+ }
46
+ }, _callee);
47
+ }));
48
+ return function onInternalEvent(_x, _x2) {
49
+ return _ref.apply(this, arguments);
50
+ };
51
+ }();
69
52
  useEffect(function () {
70
- if (!mountRef.current) {
71
- console.log('mountRef not ready');
72
- return;
73
- }
74
- console.log('Initializing simulator');
53
+ if (!mountRef.current) return;
54
+ if (apiRef.current) return;
75
55
  var api = renderKitchenSimulator(mountRef.current, {
76
56
  width: width !== null && width !== void 0 ? width : window.innerWidth,
77
57
  height: height !== null && height !== void 0 ? height : window.innerHeight,
@@ -86,28 +66,39 @@ function WorkSpaceHostMimic() {
86
66
  }
87
67
  });
88
68
  apiRef.current = api;
89
- console.log('Sending immediate external events');
69
+ var unsub = typeof api.subscribeGltfInFlight === 'function' ? api.subscribeGltfInFlight(function (count) {
70
+ return setInFlight(count);
71
+ }) : null;
90
72
  _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
73
+ var ok;
91
74
  return _regeneratorRuntime.wrap(function (_context2) {
92
75
  while (1) switch (_context2.prev = _context2.next) {
93
76
  case 0:
94
- _context2.next = 1;
95
- return api.whenReady();
77
+ if (!sentOnceRef.current) {
78
+ _context2.next = 1;
79
+ break;
80
+ }
81
+ return _context2.abrupt("return");
96
82
  case 1:
97
- api.sendExternalEvents({
83
+ sentOnceRef.current = true;
84
+
85
+ // await api.whenReady();
86
+
87
+ // ✅ send center with EMPTY payload
88
+ _context2.next = 2;
89
+ return api.sendExternalEvents([{
98
90
  type: EXTERNAL_EVENT_LOAD_PROJECT,
99
91
  // send request for sync scene data to 3DTool
100
92
  payload: JSON.parse(mockProps.projectElement[0].project_data),
101
93
  framesPerEvent: 2,
102
- waitForGltfIdleAfterEachEvent: true
103
- });
104
- api.sendExternalEvents({
105
- type: EXTERNAL_EVENT_CENTERING_2D,
106
- payload: {},
107
- framesPerEvent: 1,
108
- waitForGltfIdleAfterEachEvent: true
94
+ waitForGltfIdleAfterEachEvent: false
95
+ }], {
96
+ timeoutMs: 15000
109
97
  });
110
98
  case 2:
99
+ ok = _context2.sent;
100
+ if (!ok) console.warn('Centering timed out (fail-open).');
101
+ case 3:
111
102
  case "end":
112
103
  return _context2.stop();
113
104
  }
@@ -115,31 +106,39 @@ function WorkSpaceHostMimic() {
115
106
  }))();
116
107
  return function () {
117
108
  var _apiRef$current, _apiRef$current$unmou;
118
- console.log('Unmounting simulator');
109
+ try {
110
+ unsub === null || unsub === void 0 || unsub();
111
+ } catch (_unused) {}
119
112
  (_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);
120
113
  apiRef.current = null;
114
+ sentOnceRef.current = false;
121
115
  };
116
+ // eslint-disable-next-line react-hooks/exhaustive-deps
122
117
  }, []);
123
-
124
- // Resize mimic
125
118
  useEffect(function () {
126
- var _api$__render;
127
119
  var api = apiRef.current;
128
120
  if (!api) return;
129
- (_api$__render = api.__render) === null || _api$__render === void 0 || _api$__render.call(api, {
130
- width: width !== null && width !== void 0 ? width : window.innerWidth,
131
- height: height !== null && height !== void 0 ? height : window.innerHeight,
132
- configData: mockProps.configData,
133
- options: options,
134
- logoImg: '/assets/logo.png',
135
- companyUrl: 'https://example.com',
136
- toolbarButtons: [],
137
- onInternalEvent: onInternalEvent,
138
- onError: function onError(payload) {
139
- return console.error('TOOL ERROR:', payload);
140
- }
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
+ });
141
137
  });
142
- }, [width, height]);
138
+ return function () {
139
+ return cancelAnimationFrame(rafRef.current);
140
+ };
141
+ }, [width, height, onInternalEvent]);
143
142
  return /*#__PURE__*/React.createElement("div", {
144
143
  style: {
145
144
  width: '100vw',
@@ -151,7 +150,20 @@ function WorkSpaceHostMimic() {
151
150
  width: '100%',
152
151
  height: '100%'
153
152
  }
154
- }, /*#__PURE__*/React.createElement("div", {
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", {
155
167
  ref: mountRef,
156
168
  id: "kitchen-simulator-container",
157
169
  style: {
@@ -159,5 +171,4 @@ function WorkSpaceHostMimic() {
159
171
  height: '100%'
160
172
  }
161
173
  })));
162
- }
163
- export default WorkSpaceHostMimic;
174
+ }
@@ -147,18 +147,12 @@ var Project = /*#__PURE__*/function () {
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
149
  f = (viewer.viewerHeight - (viewer.SVGHeight * 2 - bb.maxY - bb.minY) * a) / 2;
150
- while (!(e <= 10)) {
151
- e -= 0.1;
152
- }
153
- while (!(e + a * viewer.SVGWidth + 10 >= viewer.viewerWidth)) {
154
- e += 0.1;
155
- }
156
- while (!(f <= 80)) {
157
- f -= 0.1;
158
- }
159
- while (!(f + a * viewer.SVGHeight + 10 >= viewer.viewerHeight)) {
160
- f += 0.1;
161
- }
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));
162
156
  _viewer2D = _viewer2D.merge({
163
157
  a: a,
164
158
  d: a,
package/es/index.js CHANGED
@@ -374,10 +374,6 @@ export function renderKitchenSimulator(container) {
374
374
  }
375
375
  var setExternalEventFn = null;
376
376
  var destroyed = false;
377
- var resolveReady = null;
378
- var readyPromise = new Promise(function (res) {
379
- return resolveReady = res;
380
- });
381
377
  var queue = [];
382
378
  var pendingMarkers = new Set();
383
379
  var MARKER = Symbol('marker');
@@ -533,8 +529,7 @@ export function renderKitchenSimulator(container) {
533
529
  return _createClass(Wrapper, [{
534
530
  key: "componentDidMount",
535
531
  value: function componentDidMount() {
536
- var _this3 = this,
537
- _resolveReady;
532
+ var _this3 = this;
538
533
  this._mounted = true;
539
534
  setExternalEventFn = function setExternalEventFn(newEvent) {
540
535
  if (!_this3._mounted) return;
@@ -542,9 +537,6 @@ export function renderKitchenSimulator(container) {
542
537
  externalEvent: newEvent
543
538
  });
544
539
  };
545
- (_resolveReady = resolveReady) === null || _resolveReady === void 0 || _resolveReady();
546
- resolveReady = null;
547
- drain(); // now it can actually process queued events
548
540
  }
549
541
  }, {
550
542
  key: "componentWillUnmount",
@@ -565,9 +557,6 @@ export function renderKitchenSimulator(container) {
565
557
  __render: function __render(nextProps) {
566
558
  root.render(/*#__PURE__*/React.createElement(Wrapper, nextProps));
567
559
  },
568
- whenReady: function whenReady() {
569
- return readyPromise;
570
- },
571
560
  // ✅ host can query current inFlight
572
561
  getGltfInFlight: function getGltfInFlight() {
573
562
  return gltfTracker.getInFlight();
@@ -599,7 +588,7 @@ export function renderKitchenSimulator(container) {
599
588
  __marker: MARKER,
600
589
  token: token
601
590
  });
602
- if (setExternalEventFn) drain();
591
+ drain();
603
592
 
604
593
  // resolve when marker cleared
605
594
  return new Promise(function (resolve) {
@@ -657,12 +646,9 @@ export function renderKitchenSimulator(container) {
657
646
  pendingMarkers.clear();
658
647
  },
659
648
  unmount: function unmount() {
660
- var _resolveReady2;
661
649
  destroyed = true;
662
650
  api.clearQueue();
663
651
  gltfTracker.uninstall();
664
- (_resolveReady2 = resolveReady) === null || _resolveReady2 === void 0 || _resolveReady2();
665
- resolveReady = null;
666
652
  var doUnmount = function doUnmount() {
667
653
  try {
668
654
  root.unmount();
@@ -341,20 +341,12 @@ export var updateViwer2D = function updateViwer2D(value) {
341
341
  var _zoomValue = parseInt((value.a - 0.5) / ZOOM_VARIABLE);
342
342
  if (_zoomValue > MAX_ZOOM_IN_SCALE) return;
343
343
  if (_zoomValue < 0 || Number.isNaN(_zoomValue)) return;
344
-
345
- // modify e, f to fit to SVG
346
- while (!(value.e <= 10)) {
347
- value.e -= 0.1;
348
- }
349
- while (!(value.e + value.a * value.SVGWidth + 10 >= value.viewerWidth)) {
350
- value.e += 0.1;
351
- }
352
- while (!(value.f <= 80)) {
353
- value.f -= 0.1;
354
- }
355
- while (!(value.f + value.a * value.SVGHeight + 10 >= value.viewerHeight)) {
356
- value.f += 0.1;
357
- }
344
+ var maxE = 10;
345
+ var minE = value.viewerWidth - (value.a * value.SVGWidth + 10);
346
+ value.e = Math.min(maxE, Math.max(minE, value.e));
347
+ var maxF = 80;
348
+ var minF = value.viewerHeight - (value.a * value.SVGHeight + 10);
349
+ value.f = Math.min(maxF, Math.max(minF, value.f));
358
350
  if (viewer2DActions && compareSVGRect(value)) viewer2DActions.updateCameraView(value);
359
351
  };
360
352
  export function centering2D(state) {
@@ -902,8 +902,8 @@ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, ca
902
902
  var xp = (lengthValue + halfWidthLength) * Math.cos(alpha) + x0;
903
903
  var yp = (lengthValue + halfWidthLength) * Math.sin(alpha) + y0;
904
904
  var offset = GeometryUtils.pointPositionOnLineSegment(x0, y0, x1, y1, xp, yp);
905
- /*
906
- if (x0 > x1) offset = 1 - offset;
905
+ /*
906
+ if (x0 > x1) offset = 1 - offset;
907
907
  */
908
908
  var endAt = MathUtils.toFixedFloat(lineLength - lineLength * offset - halfWidthLength, PRECISION);
909
909
  var offsetUnit = attributesFormData.getIn(['offsetB', '_unit']);
@@ -940,8 +940,8 @@ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, ca
940
940
  var _xp = _x0 - (_lengthValue + _halfWidthLength) * Math.cos(_alpha);
941
941
  var _yp = _y2 - (_lengthValue + _halfWidthLength) * Math.sin(_alpha);
942
942
  var _offset = GeometryUtils.pointPositionOnLineSegment(_x9, _y, _x0, _y2, _xp, _yp);
943
- /*
944
- if (x0 > x1) offset = 1 - offset;
943
+ /*
944
+ if (x0 > x1) offset = 1 - offset;
945
945
  */
946
946
  var startAt = MathUtils.toFixedFloat(_lineLength * _offset - _halfWidthLength, PRECISION);
947
947
  var _offsetUnit = attributesFormData.getIn(['offsetA', '_unit']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitchen-simulator",
3
- "version": "7.0.3-react-18",
3
+ "version": "7.0.5-react-18",
4
4
  "description": "It is a kitchen simulator (self-contained micro-frontend).",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",