kitchen-simulator 3.1.0-alpha.12 → 3.1.0-alpha.14

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.
@@ -329,50 +329,40 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
329
329
  });
330
330
  }
331
331
  }, {
332
- key: "componentWillReceiveProps",
333
- value: function componentWillReceiveProps(nextProps) {
334
- var stateExtractor = nextProps.stateExtractor,
335
- state = nextProps.state,
336
- projectActions = nextProps.projectActions,
337
- catalog = nextProps.catalog,
338
- externalEvent = nextProps.externalEvent,
339
- onInternalEvent = nextProps.onInternalEvent;
332
+ key: "componentDidUpdate",
333
+ value: function componentDidUpdate(prevProps) {
334
+ var _this3 = this;
335
+ var ev = this.props.externalEvent;
340
336
 
341
- // handle external events
342
- if (externalEvent && externalEvent.__eventId != null) {
343
- var eventId = externalEvent.__eventId;
337
+ // nothing new
338
+ if (!ev || ev === prevProps.externalEvent) return;
344
339
 
345
- // exactly-once guard
346
- if (this.lastProcessedExternalEventId !== eventId) {
347
- this.lastProcessedExternalEventId = eventId;
348
- try {
349
- var result = handleExternalEvent(nextProps);
340
+ // must have id to ack
341
+ var eventId = ev.__eventId;
342
+ if (eventId == null) return;
350
343
 
351
- // if handleExternalEvent ever becomes async, handle it
352
- if (result && typeof result.then === 'function') {
353
- result.then(function () {
354
- var _nextProps$onExternal;
355
- return (_nextProps$onExternal = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal === void 0 ? void 0 : _nextProps$onExternal.call(nextProps, eventId);
356
- })["catch"](function () {
357
- var _nextProps$onExternal2;
358
- return (_nextProps$onExternal2 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal2 === void 0 ? void 0 : _nextProps$onExternal2.call(nextProps, eventId);
359
- });
360
- } else {
361
- var _nextProps$onExternal3;
362
- (_nextProps$onExternal3 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal3 === void 0 || _nextProps$onExternal3.call(nextProps, eventId);
363
- }
364
- } catch (e) {
365
- var _nextProps$onExternal4;
366
- // don’t deadlock the host queue
367
- (_nextProps$onExternal4 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal4 === void 0 || _nextProps$onExternal4.call(nextProps, eventId);
368
- throw e;
369
- }
344
+ // exactly-once guard
345
+ if (this.lastProcessedExternalEventId === eventId) return;
346
+ this.lastProcessedExternalEventId = eventId;
347
+ try {
348
+ var result = handleExternalEvent(this.props);
349
+
350
+ // if it returns a promise, ack after it resolves/rejects
351
+ if (result && typeof result.then === 'function') {
352
+ result["finally"](function () {
353
+ var _this3$props$onExtern, _this3$props;
354
+ (_this3$props$onExtern = (_this3$props = _this3.props).onExternalEventProcessed) === null || _this3$props$onExtern === void 0 || _this3$props$onExtern.call(_this3$props, eventId);
355
+ });
356
+ } else {
357
+ var _this$props$onExterna, _this$props2;
358
+ // sync case
359
+ (_this$props$onExterna = (_this$props2 = this.props).onExternalEventProcessed) === null || _this$props$onExterna === void 0 || _this$props$onExterna.call(_this$props2, eventId);
370
360
  }
371
- }
372
- var plannerState = stateExtractor(state);
373
- var catalogReady = plannerState.getIn(['catalog', 'ready']);
374
- if (!catalogReady) {
375
- projectActions.initCatalog(catalog);
361
+ } catch (e) {
362
+ var _this$props$onExterna2, _this$props3;
363
+ // never deadlock the host queue
364
+ (_this$props$onExterna2 = (_this$props3 = this.props).onExternalEventProcessed) === null || _this$props$onExterna2 === void 0 || _this$props$onExterna2.call(_this$props3, eventId);
365
+ throw e;
376
366
  }
377
367
  }
378
368
  }, {
@@ -386,13 +376,13 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
386
376
  }, {
387
377
  key: "render",
388
378
  value: function render() {
389
- var _this$props2 = this.props,
390
- width = _this$props2.width,
391
- height = _this$props2.height,
392
- state = _this$props2.state,
393
- stateExtractor = _this$props2.stateExtractor,
394
- measurementUnit = _this$props2.measurementUnit,
395
- props = _objectWithoutProperties(_this$props2, _excluded);
379
+ var _this$props4 = this.props,
380
+ width = _this$props4.width,
381
+ height = _this$props4.height,
382
+ state = _this$props4.state,
383
+ stateExtractor = _this$props4.stateExtractor,
384
+ measurementUnit = _this$props4.measurementUnit,
385
+ props = _objectWithoutProperties(_this$props4, _excluded);
396
386
  var _this$state = this.state,
397
387
  savePopupVisible = _this$state.savePopupVisible,
398
388
  quotePopupVisible = _this$state.quotePopupVisible,
package/es/index.js CHANGED
@@ -12,6 +12,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
12
12
  import React from 'react';
13
13
  import ReactDOM from 'react-dom';
14
14
  import LiteRenderer from "./LiteRenderer";
15
+ import { createRoot } from 'react-dom/client';
15
16
  export function renderKitchenSimulator(container) {
16
17
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
18
  var apiRef = null;
@@ -53,16 +54,30 @@ export function renderKitchenSimulator(container) {
53
54
  return _createClass(Wrapper, [{
54
55
  key: "enqueue",
55
56
  value: function enqueue(ev) {
57
+ var _ev$waitForAckMs,
58
+ _this3 = this;
56
59
  if (!ev) return Promise.resolve();
57
60
  var id = ++idSeq;
58
- var resolve;
61
+ var _resolve;
59
62
  var promise = new Promise(function (res) {
60
- return resolve = res;
63
+ return _resolve = res;
61
64
  });
65
+
66
+ // failsafe: resolve after X ms no matter what (avoid host deadlock)
67
+ var timeoutMs = (_ev$waitForAckMs = ev === null || ev === void 0 ? void 0 : ev.waitForAckMs) !== null && _ev$waitForAckMs !== void 0 ? _ev$waitForAckMs : 15000;
68
+ var t = setTimeout(function () {
69
+ if (_this3._currentId === id) {
70
+ console.warn('External event ack timeout', id, ev);
71
+ _this3.onExternalEventProcessed(id); // force-drain
72
+ }
73
+ }, timeoutMs);
62
74
  this.queue.push({
63
75
  id: id,
64
76
  ev: ev,
65
- resolve: resolve
77
+ resolve: function resolve() {
78
+ clearTimeout(t);
79
+ _resolve();
80
+ }
66
81
  });
67
82
  if (!this.processing) this.processNext();
68
83
  return promise;
@@ -70,7 +85,7 @@ export function renderKitchenSimulator(container) {
70
85
  }, {
71
86
  key: "processNext",
72
87
  value: function processNext() {
73
- var _this3 = this;
88
+ var _this4 = this;
74
89
  var next = this.queue.shift();
75
90
  if (!next) {
76
91
  this.processing = false;
@@ -87,9 +102,9 @@ export function renderKitchenSimulator(container) {
87
102
  this.setState({
88
103
  externalEvent: null
89
104
  }, function () {
90
- _this3._currentResolve = next.resolve;
91
- _this3._currentId = next.id;
92
- _this3.setState({
105
+ _this4._currentResolve = next.resolve;
106
+ _this4._currentId = next.id;
107
+ _this4.setState({
93
108
  externalEvent: payload
94
109
  });
95
110
  });
@@ -104,7 +119,13 @@ export function renderKitchenSimulator(container) {
104
119
  }
105
120
  }]);
106
121
  }(React.Component);
107
- ReactDOM.render(/*#__PURE__*/React.createElement(Wrapper, props), container);
122
+ var ROOT_KEY = '__kitchenSimulatorRoot__';
123
+ var root = container[ROOT_KEY];
124
+ if (!root) {
125
+ root = createRoot(container);
126
+ container[ROOT_KEY] = root;
127
+ }
128
+ root.render(/*#__PURE__*/React.createElement(Wrapper, props));
108
129
  return {
109
130
  // ✅ Promise-based API (use this from host)
110
131
  enqueueExternalEvent: function enqueueExternalEvent(ev) {
@@ -338,50 +338,40 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
338
338
  });
339
339
  }
340
340
  }, {
341
- key: "componentWillReceiveProps",
342
- value: function componentWillReceiveProps(nextProps) {
343
- var stateExtractor = nextProps.stateExtractor,
344
- state = nextProps.state,
345
- projectActions = nextProps.projectActions,
346
- catalog = nextProps.catalog,
347
- externalEvent = nextProps.externalEvent,
348
- onInternalEvent = nextProps.onInternalEvent;
341
+ key: "componentDidUpdate",
342
+ value: function componentDidUpdate(prevProps) {
343
+ var _this3 = this;
344
+ var ev = this.props.externalEvent;
349
345
 
350
- // handle external events
351
- if (externalEvent && externalEvent.__eventId != null) {
352
- var eventId = externalEvent.__eventId;
346
+ // nothing new
347
+ if (!ev || ev === prevProps.externalEvent) return;
353
348
 
354
- // exactly-once guard
355
- if (this.lastProcessedExternalEventId !== eventId) {
356
- this.lastProcessedExternalEventId = eventId;
357
- try {
358
- var result = (0, _isolateEventHandler.handleExternalEvent)(nextProps);
349
+ // must have id to ack
350
+ var eventId = ev.__eventId;
351
+ if (eventId == null) return;
359
352
 
360
- // if handleExternalEvent ever becomes async, handle it
361
- if (result && typeof result.then === 'function') {
362
- result.then(function () {
363
- var _nextProps$onExternal;
364
- return (_nextProps$onExternal = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal === void 0 ? void 0 : _nextProps$onExternal.call(nextProps, eventId);
365
- })["catch"](function () {
366
- var _nextProps$onExternal2;
367
- return (_nextProps$onExternal2 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal2 === void 0 ? void 0 : _nextProps$onExternal2.call(nextProps, eventId);
368
- });
369
- } else {
370
- var _nextProps$onExternal3;
371
- (_nextProps$onExternal3 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal3 === void 0 || _nextProps$onExternal3.call(nextProps, eventId);
372
- }
373
- } catch (e) {
374
- var _nextProps$onExternal4;
375
- // don’t deadlock the host queue
376
- (_nextProps$onExternal4 = nextProps.onExternalEventProcessed) === null || _nextProps$onExternal4 === void 0 || _nextProps$onExternal4.call(nextProps, eventId);
377
- throw e;
378
- }
353
+ // exactly-once guard
354
+ if (this.lastProcessedExternalEventId === eventId) return;
355
+ this.lastProcessedExternalEventId = eventId;
356
+ try {
357
+ var result = (0, _isolateEventHandler.handleExternalEvent)(this.props);
358
+
359
+ // if it returns a promise, ack after it resolves/rejects
360
+ if (result && typeof result.then === 'function') {
361
+ result["finally"](function () {
362
+ var _this3$props$onExtern, _this3$props;
363
+ (_this3$props$onExtern = (_this3$props = _this3.props).onExternalEventProcessed) === null || _this3$props$onExtern === void 0 || _this3$props$onExtern.call(_this3$props, eventId);
364
+ });
365
+ } else {
366
+ var _this$props$onExterna, _this$props2;
367
+ // sync case
368
+ (_this$props$onExterna = (_this$props2 = this.props).onExternalEventProcessed) === null || _this$props$onExterna === void 0 || _this$props$onExterna.call(_this$props2, eventId);
379
369
  }
380
- }
381
- var plannerState = stateExtractor(state);
382
- var catalogReady = plannerState.getIn(['catalog', 'ready']);
383
- if (!catalogReady) {
384
- projectActions.initCatalog(catalog);
370
+ } catch (e) {
371
+ var _this$props$onExterna2, _this$props3;
372
+ // never deadlock the host queue
373
+ (_this$props$onExterna2 = (_this$props3 = this.props).onExternalEventProcessed) === null || _this$props$onExterna2 === void 0 || _this$props$onExterna2.call(_this$props3, eventId);
374
+ throw e;
385
375
  }
386
376
  }
387
377
  }, {
@@ -395,13 +385,13 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
395
385
  }, {
396
386
  key: "render",
397
387
  value: function render() {
398
- var _this$props2 = this.props,
399
- width = _this$props2.width,
400
- height = _this$props2.height,
401
- state = _this$props2.state,
402
- stateExtractor = _this$props2.stateExtractor,
403
- measurementUnit = _this$props2.measurementUnit,
404
- props = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded);
388
+ var _this$props4 = this.props,
389
+ width = _this$props4.width,
390
+ height = _this$props4.height,
391
+ state = _this$props4.state,
392
+ stateExtractor = _this$props4.stateExtractor,
393
+ measurementUnit = _this$props4.measurementUnit,
394
+ props = (0, _objectWithoutProperties2["default"])(_this$props4, _excluded);
405
395
  var _this$state = this.state,
406
396
  savePopupVisible = _this$state.savePopupVisible,
407
397
  quotePopupVisible = _this$state.quotePopupVisible,
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
16
16
  var _react = _interopRequireDefault(require("react"));
17
17
  var _reactDom = _interopRequireDefault(require("react-dom"));
18
18
  var _LiteRenderer = _interopRequireDefault(require("./LiteRenderer"));
19
+ var _client = require("react-dom/client");
19
20
  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; }
20
21
  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) { (0, _defineProperty2["default"])(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; }
21
22
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
@@ -61,16 +62,30 @@ function renderKitchenSimulator(container) {
61
62
  return (0, _createClass2["default"])(Wrapper, [{
62
63
  key: "enqueue",
63
64
  value: function enqueue(ev) {
65
+ var _ev$waitForAckMs,
66
+ _this3 = this;
64
67
  if (!ev) return Promise.resolve();
65
68
  var id = ++idSeq;
66
- var resolve;
69
+ var _resolve;
67
70
  var promise = new Promise(function (res) {
68
- return resolve = res;
71
+ return _resolve = res;
69
72
  });
73
+
74
+ // failsafe: resolve after X ms no matter what (avoid host deadlock)
75
+ var timeoutMs = (_ev$waitForAckMs = ev === null || ev === void 0 ? void 0 : ev.waitForAckMs) !== null && _ev$waitForAckMs !== void 0 ? _ev$waitForAckMs : 15000;
76
+ var t = setTimeout(function () {
77
+ if (_this3._currentId === id) {
78
+ console.warn('External event ack timeout', id, ev);
79
+ _this3.onExternalEventProcessed(id); // force-drain
80
+ }
81
+ }, timeoutMs);
70
82
  this.queue.push({
71
83
  id: id,
72
84
  ev: ev,
73
- resolve: resolve
85
+ resolve: function resolve() {
86
+ clearTimeout(t);
87
+ _resolve();
88
+ }
74
89
  });
75
90
  if (!this.processing) this.processNext();
76
91
  return promise;
@@ -78,7 +93,7 @@ function renderKitchenSimulator(container) {
78
93
  }, {
79
94
  key: "processNext",
80
95
  value: function processNext() {
81
- var _this3 = this;
96
+ var _this4 = this;
82
97
  var next = this.queue.shift();
83
98
  if (!next) {
84
99
  this.processing = false;
@@ -95,9 +110,9 @@ function renderKitchenSimulator(container) {
95
110
  this.setState({
96
111
  externalEvent: null
97
112
  }, function () {
98
- _this3._currentResolve = next.resolve;
99
- _this3._currentId = next.id;
100
- _this3.setState({
113
+ _this4._currentResolve = next.resolve;
114
+ _this4._currentId = next.id;
115
+ _this4.setState({
101
116
  externalEvent: payload
102
117
  });
103
118
  });
@@ -112,7 +127,13 @@ function renderKitchenSimulator(container) {
112
127
  }
113
128
  }]);
114
129
  }(_react["default"].Component);
115
- _reactDom["default"].render(/*#__PURE__*/_react["default"].createElement(Wrapper, props), container);
130
+ var ROOT_KEY = '__kitchenSimulatorRoot__';
131
+ var root = container[ROOT_KEY];
132
+ if (!root) {
133
+ root = (0, _client.createRoot)(container);
134
+ container[ROOT_KEY] = root;
135
+ }
136
+ root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, props));
116
137
  return {
117
138
  // ✅ Promise-based API (use this from host)
118
139
  enqueueExternalEvent: function enqueueExternalEvent(ev) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitchen-simulator",
3
- "version": "3.1.0-alpha.12",
3
+ "version": "3.1.0-alpha.14",
4
4
  "description": "It is a kitchen simulator (self-contained micro-frontend).",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",