kitchen-simulator 3.16.0 → 3.16.1-test-renderer-fix

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,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
@@ -7,79 +6,57 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
7
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
8
7
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
8
  import _inherits from "@babel/runtime/helpers/esm/inherits";
10
- var _excluded = ["width", "height", "configData", "options", "user", "auth", "featureFlags", "sentry", "analytics", "externalEvent", "onInternalEvent", "onError"];
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
+ var _excluded = ["width", "height", "configData", "externalEvent", "onInternalEvent", "onError"];
12
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
15
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
15
16
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
- import React, { useCallback, useEffect, useRef } from 'react';
17
+ // LiteRenderer.jsx
18
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
17
19
  import PropTypes from 'prop-types';
18
20
  import { Provider } from 'react-redux';
19
21
  import { createStore } from 'redux';
22
+ import { Map } from 'immutable';
23
+ import * as Sentry from '@sentry/react';
24
+ import * as THREE from 'three';
20
25
  import * as Models from "./models";
21
26
  import { State } from "./models";
22
27
  import PlannerReducer from "./reducers/reducer";
23
28
  import AppContext from "./AppContext";
24
29
  import Catalog from "./catalog/catalog";
25
- import { SVGLoader } from 'three/addons/loaders/SVGLoader';
26
- import { TOE_KICK_MOLDING } from "./constants";
27
30
  import * as Areas from "./catalog/areas/area/planner-element";
28
31
  import * as Lines from "./catalog/lines/wall/planner-element";
29
32
  import * as Holes from "./catalog/holes/export";
30
33
  import { ConsoleDebugger, Keyboard } from "./plugins/export";
31
- import { Map } from 'immutable';
32
- import * as Sentry from '@sentry/react';
33
- import * as THREE from 'three';
34
34
  import LiteKitchenConfigurator from "./LiteKitchenConfigurator";
35
- if (typeof window !== 'undefined') window.THREE = THREE;
35
+ var isBrowser = typeof window !== 'undefined';
36
+ if (isBrowser) window.THREE = THREE;
36
37
 
37
- /* ============================== component ============================= */
38
- var MyCatalog = new Catalog();
39
- var AppState = Map({
40
- KitchenConfigurator: new State()
41
- });
42
- console.log('Version: 378.45-202509_DIY-364-mbox-crash');
43
- isProduction && Sentry.init({
44
- dsn: process.env.SENTRY_DSN,
45
- environment: process.env.SENTRY_ENVIRONMENT
46
- });
47
-
48
- //define reducer
49
- var reducer = function reducer(state, action) {
50
- state = state || AppState;
51
- state = state.update('KitchenConfigurator', function (plannerState) {
52
- return PlannerReducer(plannerState, action);
38
+ // ---- Keep prior Sentry behavior but ensure it only initializes once ----
39
+ var __sentryInited = false;
40
+ function ensureSentryInit() {
41
+ if (!isBrowser) return;
42
+ // assumes isProduction exists in your build just like today
43
+ if (!isProduction) return;
44
+ if (__sentryInited) return;
45
+ __sentryInited = true;
46
+ Sentry.init({
47
+ dsn: process.env.SENTRY_DSN,
48
+ environment: process.env.SENTRY_ENVIRONMENT
53
49
  });
54
- return state;
55
- };
56
- var store = createStore(reducer, null, !isProduction && window.devToolsExtension ? window.devToolsExtension({
57
- features: {
58
- pause: true,
59
- // start/pause recording of dispatched actions
60
- lock: true,
61
- // lock/unlock dispatching actions and side effects
62
- persist: true,
63
- // persist states on page reloading
64
- "export": true,
65
- // export history of actions in a file
66
- "import": 'custom',
67
- // import history of actions from a file
68
- jump: true,
69
- // jump back and forth (time travelling)
70
- skip: true,
71
- // skip (cancel) actions
72
- reorder: true,
73
- // drag and drop actions in the history list
74
- dispatch: true,
75
- // dispatch custom actions or action creators
76
- test: true // generate tests for the selected actions
77
- },
78
- maxAge: 999999
79
- }) : function (f) {
80
- return f;
81
- });
82
- var plugins = [Keyboard(), ConsoleDebugger()];
50
+ }
51
+
52
+ // ---------------- error helpers ----------------
53
+ function safeJson(v) {
54
+ try {
55
+ return JSON.parse(JSON.stringify(v));
56
+ } catch (_unused) {
57
+ return undefined;
58
+ }
59
+ }
83
60
  function serializeError(err) {
84
61
  try {
85
62
  if (!err) return {
@@ -96,19 +73,12 @@ function serializeError(err) {
96
73
  message: String(err),
97
74
  raw: safeJson(err)
98
75
  };
99
- } catch (_unused) {
76
+ } catch (_unused2) {
100
77
  return {
101
78
  message: 'Error serializing error'
102
79
  };
103
80
  }
104
81
  }
105
- function safeJson(v) {
106
- try {
107
- return JSON.parse(JSON.stringify(v));
108
- } catch (_unused2) {
109
- return undefined;
110
- }
111
- }
112
82
 
113
83
  /* ---------- Error Boundary that pushes into buffer ---------- */
114
84
  var ToolErrorBoundary = /*#__PURE__*/function (_React$Component) {
@@ -136,35 +106,139 @@ var ToolErrorBoundary = /*#__PURE__*/function (_React$Component) {
136
106
  }
137
107
  }]);
138
108
  }(React.Component);
109
+ ToolErrorBoundary.propTypes = {
110
+ pushError: PropTypes.func.isRequired,
111
+ children: PropTypes.any
112
+ };
113
+
114
+ // ----------------- catalog init -----------------
115
+ function initCatalogOnce(catalog) {
116
+ if (!catalog) return;
117
+ if (catalog.__ksInitialized) return;
118
+ for (var x in Areas) catalog.registerElement(Areas[x]);
119
+ for (var _x in Lines) catalog.registerElement(Lines[_x]);
120
+ for (var _x2 in Holes) catalog.registerElement(Holes[_x2]);
121
+ catalog.registerCategory('Windows', 'Windows', [Holes.windowClear, Holes.windowCross, Holes.windowDoubleHung, Holes.windowVertical]);
122
+ catalog.registerCategory('Doors', 'Doors', [Holes.doorInterior, Holes.doorExterior, Holes.doorCloset, Holes.doorSliding, Holes.doorwayFramed, Holes.doorwayFrameless]);
123
+ catalog.__ksInitialized = true;
124
+ }
125
+
126
+ // ----------------- store factory -----------------
127
+ function createInstanceStore() {
128
+ var AppState = Map({
129
+ KitchenConfigurator: new State()
130
+ });
131
+ var reducer = function reducer(state, action) {
132
+ state = state || AppState;
133
+ return state.update('KitchenConfigurator', function (plannerState) {
134
+ return PlannerReducer(plannerState, action);
135
+ });
136
+ };
137
+ var enhancer = !isProduction && isBrowser && window.devToolsExtension ? window.devToolsExtension({
138
+ features: {
139
+ pause: true,
140
+ lock: true,
141
+ persist: true,
142
+ "export": true,
143
+ "import": 'custom',
144
+ jump: true,
145
+ skip: true,
146
+ reorder: true,
147
+ dispatch: true,
148
+ test: true
149
+ },
150
+ maxAge: 999999
151
+ }) : function (f) {
152
+ return f;
153
+ };
154
+ return createStore(reducer, null, enhancer);
155
+ }
156
+ function createPlugins() {
157
+ return [Keyboard(), ConsoleDebugger()];
158
+ }
139
159
  export default function LiteRenderer(props) {
160
+ ensureSentryInit();
140
161
  var width = props.width,
141
162
  height = props.height,
142
163
  configData = props.configData,
143
- options = props.options,
144
- user = props.user,
145
- auth = props.auth,
146
- featureFlags = props.featureFlags,
147
- sentry = props.sentry,
148
- analytics = props.analytics,
149
164
  externalEvent = props.externalEvent,
150
165
  onInternalEvent = props.onInternalEvent,
151
166
  onError = props.onError,
152
167
  passThrough = _objectWithoutProperties(props, _excluded);
153
168
 
169
+ // ✅ instance-scoped store (no module singleton)
170
+ var storeRef = useRef(null);
171
+ if (!storeRef.current) storeRef.current = createInstanceStore();
172
+
173
+ // ✅ instance-scoped catalog (no module singleton)
174
+ var catalogRef = useRef(null);
175
+ if (!catalogRef.current) {
176
+ catalogRef.current = new Catalog();
177
+ initCatalogOnce(catalogRef.current);
178
+ }
179
+
180
+ // ✅ stable plugins array
181
+ var plugins = useMemo(function () {
182
+ return createPlugins();
183
+ }, []);
184
+
185
+ // ✅ plugin lifecycle: supports cleanup if plugin returns function
186
+ var pluginCleanupsRef = useRef([]);
187
+ useEffect(function () {
188
+ var store = storeRef.current;
189
+ var stateExtractor = function stateExtractor(state) {
190
+ return state.get('KitchenConfigurator');
191
+ };
192
+ var cleanups = [];
193
+ var _iterator = _createForOfIteratorHelper(plugins),
194
+ _step;
195
+ try {
196
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
197
+ var p = _step.value;
198
+ try {
199
+ var maybeCleanup = p === null || p === void 0 ? void 0 : p(store, stateExtractor);
200
+ if (typeof maybeCleanup === 'function') cleanups.push(maybeCleanup);
201
+ } catch (_unused4) {
202
+ // keep prior behavior: do not crash
203
+ }
204
+ }
205
+ } catch (err) {
206
+ _iterator.e(err);
207
+ } finally {
208
+ _iterator.f();
209
+ }
210
+ pluginCleanupsRef.current = cleanups;
211
+ return function () {
212
+ var _iterator2 = _createForOfIteratorHelper(pluginCleanupsRef.current),
213
+ _step2;
214
+ try {
215
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
216
+ var fn = _step2.value;
217
+ try {
218
+ fn();
219
+ } catch (_unused3) {}
220
+ }
221
+ } catch (err) {
222
+ _iterator2.e(err);
223
+ } finally {
224
+ _iterator2.f();
225
+ }
226
+ pluginCleanupsRef.current = [];
227
+ };
228
+ }, [plugins]);
229
+
154
230
  /* ---------- track last external event ---------- */
155
231
  var lastExternalEventRef = useRef(null);
156
232
  useEffect(function () {
157
- if (externalEvent) {
158
- lastExternalEventRef.current = externalEvent;
159
- }
233
+ if (externalEvent) lastExternalEventRef.current = externalEvent;
160
234
  }, [externalEvent]);
161
235
 
162
236
  /* ---------- error buffer + last emitted bundle ---------- */
163
- var errorsBufferRef = useRef([]); // pending errors (not yet emitted)
237
+ var errorsBufferRef = useRef([]);
164
238
  var lastEmittedRef = useRef({
165
239
  externalEvent: null,
166
240
  errors: []
167
- }); // last bundle we sent
241
+ });
168
242
  var flushTimerRef = useRef(null);
169
243
  var emit = useCallback(function (external, errors) {
170
244
  var payload = {
@@ -173,13 +247,11 @@ export default function LiteRenderer(props) {
173
247
  };
174
248
  try {
175
249
  onError === null || onError === void 0 || onError(payload);
176
- } catch (_unused3) {}
250
+ } catch (_unused5) {}
177
251
  // eslint-disable-next-line no-console
178
252
  console.debug('[LiteRenderer:onError]', payload);
179
253
  lastEmittedRef.current = payload;
180
254
  }, [onError]);
181
-
182
- // batch short bursts (e.g., multiple async errors in same tick)
183
255
  var scheduleFlush = useCallback(function () {
184
256
  if (flushTimerRef.current) return;
185
257
  flushTimerRef.current = setTimeout(function () {
@@ -188,7 +260,7 @@ export default function LiteRenderer(props) {
188
260
  if (!errors.length) return;
189
261
  errorsBufferRef.current = [];
190
262
  emit(lastExternalEventRef.current, errors);
191
- }, 0); // micro-batch; increase (e.g. 50ms) if you want coarser batching
263
+ }, 0);
192
264
  }, [emit]);
193
265
  var pushError = useCallback(function (errPayload) {
194
266
  errorsBufferRef.current.push(_objectSpread({
@@ -199,6 +271,7 @@ export default function LiteRenderer(props) {
199
271
 
200
272
  /* ---------- global runtime + async error capture ---------- */
201
273
  useEffect(function () {
274
+ if (!isBrowser) return;
202
275
  var onWindowError = function onWindowError(event) {
203
276
  pushError({
204
277
  type: 'runtime-error',
@@ -230,64 +303,20 @@ export default function LiteRenderer(props) {
230
303
  var prev = prevExternalEventRef.current;
231
304
  if (prev === externalEvent) return;
232
305
  prevExternalEventRef.current = externalEvent;
233
-
234
- // if we already emitted something before, re-send it with the new event context
235
306
  var last = lastEmittedRef.current;
236
307
  if (last && last.errors && last.errors.length) {
237
308
  emit(lastExternalEventRef.current, last.errors);
238
309
  }
239
310
  }, [externalEvent, emit]);
240
- var id = configData.id,
241
- logoImg = configData.logoImg,
242
- companyUrl = configData.companyUrl;
243
- useEffect(function () {
244
- var initMyCatalog = /*#__PURE__*/function () {
245
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
246
- var x, _x, _x2;
247
- return _regeneratorRuntime.wrap(function (_context) {
248
- while (1) switch (_context.prev = _context.next) {
249
- case 0:
250
- for (x in Areas) MyCatalog.registerElement(Areas[x]);
251
- for (_x in Lines) MyCatalog.registerElement(Lines[_x]);
252
- for (_x2 in Holes) MyCatalog.registerElement(Holes[_x2]);
253
- MyCatalog.registerCategory('Windows', 'Windows', [Holes.windowClear, Holes.windowCross, Holes.windowDoubleHung, Holes.windowVertical]);
254
- MyCatalog.registerCategory('Doors', 'Doors', [Holes.doorInterior, Holes.doorExterior, Holes.doorCloset, Holes.doorSliding, Holes.doorwayFramed, Holes.doorwayFrameless]);
255
- case 1:
256
- case "end":
257
- return _context.stop();
258
- }
259
- }, _callee);
260
- }));
261
- return function initMyCatalog() {
262
- return _ref.apply(this, arguments);
263
- };
264
- }();
265
- var initCatalog = /*#__PURE__*/function () {
266
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
267
- return _regeneratorRuntime.wrap(function (_context2) {
268
- while (1) switch (_context2.prev = _context2.next) {
269
- case 0:
270
- _context2.next = 1;
271
- return initMyCatalog();
272
- case 1:
273
- case "end":
274
- return _context2.stop();
275
- }
276
- }, _callee2);
277
- }));
278
- return function initCatalog() {
279
- return _ref2.apply(this, arguments);
280
- };
281
- }();
282
- initCatalog();
283
- // eslint-disable-next-line react-hooks/exhaustive-deps
284
- }, [id]);
311
+ var _ref = configData || {},
312
+ logoImg = _ref.logoImg,
313
+ companyUrl = _ref.companyUrl;
285
314
  return /*#__PURE__*/React.createElement(AppContext.Provider, null, /*#__PURE__*/React.createElement(Provider, {
286
- store: store
315
+ store: storeRef.current
287
316
  }, /*#__PURE__*/React.createElement(ToolErrorBoundary, {
288
317
  pushError: pushError
289
318
  }, /*#__PURE__*/React.createElement(LiteKitchenConfigurator, _extends({
290
- catalog: MyCatalog,
319
+ catalog: catalogRef.current,
291
320
  width: width,
292
321
  height: height,
293
322
  logoImage: logoImg,
@@ -301,9 +330,6 @@ export default function LiteRenderer(props) {
301
330
  onInternalEvent: onInternalEvent
302
331
  }, passThrough)))));
303
332
  }
304
-
305
- /* ============================== prop types ============================== */
306
-
307
333
  LiteRenderer.propTypes = {
308
334
  width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
309
335
  height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),