kitchen-simulator 7.0.1-react-18 → 7.0.4-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.
@@ -0,0 +1,164 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
5
+ import { useResizeDetector } from 'react-resize-detector';
6
+ import mockProps from "./mocks/mockProps.json";
7
+ import projectItemsCatalog from "./mocks/projectItemsCatalog.json";
8
+ import renderKitchenSimulator from "./index";
9
+ import { EXTERNAL_EVENT_CENTERING_2D, INTERNAL_EVENT_ITEMS_CATALOG } from "./constants";
10
+ var options = {
11
+ unit: 'in',
12
+ enable3D: true
13
+ };
14
+ export default function WorkSpaceHostMimic() {
15
+ var _useResizeDetector = useResizeDetector(),
16
+ width = _useResizeDetector.width,
17
+ height = _useResizeDetector.height,
18
+ sizeRef = _useResizeDetector.ref;
19
+ var mountRef = useRef(null);
20
+ 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 = useCallback(function (evt, callback) {
28
+ try {
29
+ if ((evt === null || evt === void 0 ? void 0 : evt.type) === INTERNAL_EVENT_ITEMS_CATALOG) {
30
+ // ✅ correct shape
31
+ callback === null || callback === void 0 || callback({
32
+ elements: projectItemsCatalog
33
+ });
34
+ } else {
35
+ callback === null || callback === void 0 || callback();
36
+ }
37
+ } catch (e) {
38
+ console.error('onInternalEvent failed', e);
39
+ try {
40
+ callback === null || callback === void 0 || callback();
41
+ } catch (_unused) {}
42
+ }
43
+ }, []);
44
+ useEffect(function () {
45
+ if (!mountRef.current) return;
46
+ if (apiRef.current) return;
47
+ var api = renderKitchenSimulator(mountRef.current, {
48
+ width: width !== null && width !== void 0 ? width : window.innerWidth,
49
+ height: height !== null && height !== void 0 ? height : window.innerHeight,
50
+ configData: mockProps.configData,
51
+ options: options,
52
+ logoImg: '/assets/logo.png',
53
+ companyUrl: 'https://example.com',
54
+ toolbarButtons: [],
55
+ onInternalEvent: onInternalEvent,
56
+ onError: function onError(payload) {
57
+ return console.error('TOOL ERROR:', payload);
58
+ }
59
+ });
60
+ apiRef.current = api;
61
+ var unsub = typeof api.subscribeGltfInFlight === 'function' ? api.subscribeGltfInFlight(function (count) {
62
+ return setInFlight(count);
63
+ }) : null;
64
+ _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
65
+ var ok;
66
+ return _regeneratorRuntime.wrap(function (_context) {
67
+ while (1) switch (_context.prev = _context.next) {
68
+ case 0:
69
+ if (!sentOnceRef.current) {
70
+ _context.next = 1;
71
+ break;
72
+ }
73
+ return _context.abrupt("return");
74
+ case 1:
75
+ sentOnceRef.current = true;
76
+ _context.next = 2;
77
+ return api.whenReady();
78
+ case 2:
79
+ _context.next = 3;
80
+ return api.sendExternalEvents([{
81
+ type: EXTERNAL_EVENT_CENTERING_2D,
82
+ payload: {},
83
+ framesPerEvent: 2,
84
+ waitForGltfIdleAfterEachEvent: false
85
+ }], {
86
+ timeoutMs: 15000
87
+ });
88
+ case 3:
89
+ ok = _context.sent;
90
+ if (!ok) console.warn('Centering timed out (fail-open).');
91
+ case 4:
92
+ case "end":
93
+ return _context.stop();
94
+ }
95
+ }, _callee);
96
+ }))();
97
+ return function () {
98
+ var _apiRef$current, _apiRef$current$unmou;
99
+ try {
100
+ unsub === null || unsub === void 0 || unsub();
101
+ } catch (_unused2) {}
102
+ (_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);
103
+ apiRef.current = null;
104
+ sentOnceRef.current = false;
105
+ };
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ }, []);
108
+ useEffect(function () {
109
+ var api = apiRef.current;
110
+ if (!api) return;
111
+ cancelAnimationFrame(rafRef.current);
112
+ rafRef.current = requestAnimationFrame(function () {
113
+ var _api$__render;
114
+ (_api$__render = api.__render) === null || _api$__render === void 0 || _api$__render.call(api, {
115
+ width: width !== null && width !== void 0 ? width : window.innerWidth,
116
+ height: height !== null && height !== void 0 ? height : window.innerHeight,
117
+ configData: mockProps.configData,
118
+ options: options,
119
+ logoImg: '/assets/logo.png',
120
+ companyUrl: 'https://example.com',
121
+ toolbarButtons: [],
122
+ onInternalEvent: onInternalEvent,
123
+ onError: function onError(payload) {
124
+ return console.error('TOOL ERROR:', payload);
125
+ }
126
+ });
127
+ });
128
+ return function () {
129
+ return cancelAnimationFrame(rafRef.current);
130
+ };
131
+ }, [width, height, onInternalEvent]);
132
+ return /*#__PURE__*/React.createElement("div", {
133
+ style: {
134
+ width: '100vw',
135
+ height: '100vh'
136
+ }
137
+ }, /*#__PURE__*/React.createElement("div", {
138
+ ref: sizeRef,
139
+ style: {
140
+ width: '100%',
141
+ height: '100%'
142
+ }
143
+ }, inFlight > 0 ? /*#__PURE__*/React.createElement("div", {
144
+ style: {
145
+ position: 'absolute',
146
+ zIndex: 9999,
147
+ top: 12,
148
+ right: 12,
149
+ padding: '8px 10px',
150
+ borderRadius: 8,
151
+ background: 'rgba(0,0,0,0.6)',
152
+ color: 'white',
153
+ fontSize: 12,
154
+ pointerEvents: 'none'
155
+ }
156
+ }, "Loading 3D\u2026 (", inFlight, ")") : null, /*#__PURE__*/React.createElement("div", {
157
+ ref: mountRef,
158
+ id: "kitchen-simulator-container",
159
+ style: {
160
+ width: '100%',
161
+ height: '100%'
162
+ }
163
+ })));
164
+ }