kitchen-simulator 7.0.1-react-18 → 7.0.3-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.
- package/es/WorkSpace.js +18 -846
- package/es/WorkSpaceHostMimic.js +163 -0
- package/es/WorkSpaceOriginal.js +845 -0
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
|
+
import { useResizeDetector } from 'react-resize-detector';
|
|
5
|
+
import mockProps from "./mocks/mockProps.json";
|
|
6
|
+
import projectItemsCatalog from "./mocks/projectItemsCatalog.json";
|
|
7
|
+
import renderKitchenSimulator from "./index";
|
|
8
|
+
import { EXTERNAL_EVENT_CENTERING_2D, EXTERNAL_EVENT_LOAD_PROJECT, INTERNAL_EVENT_ITEMS_CATALOG } from "./constants";
|
|
9
|
+
var options = {
|
|
10
|
+
unit: 'in',
|
|
11
|
+
enable3D: true
|
|
12
|
+
};
|
|
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() {
|
|
60
|
+
var _useResizeDetector = useResizeDetector(),
|
|
61
|
+
width = _useResizeDetector.width,
|
|
62
|
+
height = _useResizeDetector.height,
|
|
63
|
+
sizeRef = _useResizeDetector.ref;
|
|
64
|
+
|
|
65
|
+
// ✅ pure JS refs
|
|
66
|
+
var mountRef = useRef(null);
|
|
67
|
+
var apiRef = useRef(null);
|
|
68
|
+
console.log('render WorkSpaceHostMimic');
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
if (!mountRef.current) {
|
|
71
|
+
console.log('mountRef not ready');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
console.log('Initializing simulator');
|
|
75
|
+
var api = renderKitchenSimulator(mountRef.current, {
|
|
76
|
+
width: width !== null && width !== void 0 ? width : window.innerWidth,
|
|
77
|
+
height: height !== null && height !== void 0 ? height : window.innerHeight,
|
|
78
|
+
configData: mockProps.configData,
|
|
79
|
+
options: options,
|
|
80
|
+
logoImg: '/assets/logo.png',
|
|
81
|
+
companyUrl: 'https://example.com',
|
|
82
|
+
toolbarButtons: [],
|
|
83
|
+
onInternalEvent: onInternalEvent,
|
|
84
|
+
onError: function onError(payload) {
|
|
85
|
+
return console.error('TOOL ERROR:', payload);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
apiRef.current = api;
|
|
89
|
+
console.log('Sending immediate external events');
|
|
90
|
+
_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
91
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
92
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
_context2.next = 1;
|
|
95
|
+
return api.whenReady();
|
|
96
|
+
case 1:
|
|
97
|
+
api.sendExternalEvents({
|
|
98
|
+
type: EXTERNAL_EVENT_LOAD_PROJECT,
|
|
99
|
+
// send request for sync scene data to 3DTool
|
|
100
|
+
payload: JSON.parse(mockProps.projectElement[0].project_data),
|
|
101
|
+
framesPerEvent: 2,
|
|
102
|
+
waitForGltfIdleAfterEachEvent: true
|
|
103
|
+
});
|
|
104
|
+
api.sendExternalEvents({
|
|
105
|
+
type: EXTERNAL_EVENT_CENTERING_2D,
|
|
106
|
+
payload: {},
|
|
107
|
+
framesPerEvent: 1,
|
|
108
|
+
waitForGltfIdleAfterEachEvent: true
|
|
109
|
+
});
|
|
110
|
+
case 2:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context2.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee2);
|
|
115
|
+
}))();
|
|
116
|
+
return function () {
|
|
117
|
+
var _apiRef$current, _apiRef$current$unmou;
|
|
118
|
+
console.log('Unmounting simulator');
|
|
119
|
+
(_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
|
+
apiRef.current = null;
|
|
121
|
+
};
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
// Resize mimic
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
var _api$__render;
|
|
127
|
+
var api = apiRef.current;
|
|
128
|
+
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
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}, [width, height]);
|
|
143
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
144
|
+
style: {
|
|
145
|
+
width: '100vw',
|
|
146
|
+
height: '100vh'
|
|
147
|
+
}
|
|
148
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
ref: sizeRef,
|
|
150
|
+
style: {
|
|
151
|
+
width: '100%',
|
|
152
|
+
height: '100%'
|
|
153
|
+
}
|
|
154
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
155
|
+
ref: mountRef,
|
|
156
|
+
id: "kitchen-simulator-container",
|
|
157
|
+
style: {
|
|
158
|
+
width: '100%',
|
|
159
|
+
height: '100%'
|
|
160
|
+
}
|
|
161
|
+
})));
|
|
162
|
+
}
|
|
163
|
+
export default WorkSpaceHostMimic;
|