kitchen-simulator 3.1.0-alpha.13 → 3.1.0-alpha.15

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.
@@ -331,38 +331,22 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
331
331
  }, {
332
332
  key: "componentDidUpdate",
333
333
  value: function componentDidUpdate(prevProps) {
334
- var _this3 = this;
335
334
  var ev = this.props.externalEvent;
336
-
337
- // nothing new
338
335
  if (!ev || ev === prevProps.externalEvent) return;
339
-
340
- // must have id to ack
341
336
  var eventId = ev.__eventId;
342
337
  if (eventId == null) return;
343
-
344
- // exactly-once guard
345
338
  if (this.lastProcessedExternalEventId === eventId) return;
346
339
  this.lastProcessedExternalEventId = eventId;
340
+ console.log('[Tool] got external', eventId, ev.type, !!this.props.onExternalEventProcessed);
347
341
  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);
360
- }
342
+ handleExternalEvent(this.props);
361
343
  } 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);
344
+ console.error('[Tool] handleExternalEvent crashed', e);
365
345
  throw e;
346
+ } finally {
347
+ var _this$props$onExterna, _this$props2;
348
+ (_this$props$onExterna = (_this$props2 = this.props).onExternalEventProcessed) === null || _this$props$onExterna === void 0 || _this$props$onExterna.call(_this$props2, eventId);
349
+ console.log('[Tool] ack external', eventId);
366
350
  }
367
351
  }
368
352
  }, {
@@ -376,13 +360,13 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
376
360
  }, {
377
361
  key: "render",
378
362
  value: function render() {
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);
363
+ var _this$props3 = this.props,
364
+ width = _this$props3.width,
365
+ height = _this$props3.height,
366
+ state = _this$props3.state,
367
+ stateExtractor = _this$props3.stateExtractor,
368
+ measurementUnit = _this$props3.measurementUnit,
369
+ props = _objectWithoutProperties(_this$props3, _excluded);
386
370
  var _this$state = this.state,
387
371
  savePopupVisible = _this$state.savePopupVisible,
388
372
  quotePopupVisible = _this$state.quotePopupVisible,
package/es/index.js CHANGED
@@ -62,14 +62,9 @@ export function renderKitchenSimulator(container) {
62
62
  var promise = new Promise(function (res) {
63
63
  return _resolve = res;
64
64
  });
65
-
66
- // failsafe: resolve after X ms no matter what (avoid host deadlock)
67
65
  var timeoutMs = (_ev$waitForAckMs = ev === null || ev === void 0 ? void 0 : ev.waitForAckMs) !== null && _ev$waitForAckMs !== void 0 ? _ev$waitForAckMs : 15000;
68
66
  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
- }
67
+ _this3.forceComplete(id, 'ack-timeout');
73
68
  }, timeoutMs);
74
69
  this.queue.push({
75
70
  id: id,
@@ -109,6 +104,22 @@ export function renderKitchenSimulator(container) {
109
104
  });
110
105
  });
111
106
  }
107
+ }, {
108
+ key: "forceComplete",
109
+ value: function forceComplete(id, reason) {
110
+ // only force-complete if this is still the in-flight event
111
+ if (this._currentId !== id) return;
112
+ console.warn('[Tool] force complete external event', id, reason);
113
+ try {
114
+ var _this$_currentResolve2;
115
+ (_this$_currentResolve2 = this._currentResolve) === null || _this$_currentResolve2 === void 0 || _this$_currentResolve2.call(this);
116
+ } finally {
117
+ this._currentResolve = null;
118
+ this._currentId = null;
119
+ this.processing = false;
120
+ this.processNext();
121
+ }
122
+ }
112
123
  }, {
113
124
  key: "render",
114
125
  value: function render() {
@@ -125,7 +136,7 @@ export function renderKitchenSimulator(container) {
125
136
  root = createRoot(container);
126
137
  container[ROOT_KEY] = root;
127
138
  }
128
- root.render(/*#__PURE__*/React.createElement(Wrapper, props), container);
139
+ root.render(/*#__PURE__*/React.createElement(Wrapper, props));
129
140
  return {
130
141
  // ✅ Promise-based API (use this from host)
131
142
  enqueueExternalEvent: function enqueueExternalEvent(ev) {
@@ -340,38 +340,22 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
340
340
  }, {
341
341
  key: "componentDidUpdate",
342
342
  value: function componentDidUpdate(prevProps) {
343
- var _this3 = this;
344
343
  var ev = this.props.externalEvent;
345
-
346
- // nothing new
347
344
  if (!ev || ev === prevProps.externalEvent) return;
348
-
349
- // must have id to ack
350
345
  var eventId = ev.__eventId;
351
346
  if (eventId == null) return;
352
-
353
- // exactly-once guard
354
347
  if (this.lastProcessedExternalEventId === eventId) return;
355
348
  this.lastProcessedExternalEventId = eventId;
349
+ console.log('[Tool] got external', eventId, ev.type, !!this.props.onExternalEventProcessed);
356
350
  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);
369
- }
351
+ (0, _isolateEventHandler.handleExternalEvent)(this.props);
370
352
  } 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);
353
+ console.error('[Tool] handleExternalEvent crashed', e);
374
354
  throw e;
355
+ } finally {
356
+ var _this$props$onExterna, _this$props2;
357
+ (_this$props$onExterna = (_this$props2 = this.props).onExternalEventProcessed) === null || _this$props$onExterna === void 0 || _this$props$onExterna.call(_this$props2, eventId);
358
+ console.log('[Tool] ack external', eventId);
375
359
  }
376
360
  }
377
361
  }, {
@@ -385,13 +369,13 @@ var LiteKitchenConfigurator = /*#__PURE__*/function (_Component) {
385
369
  }, {
386
370
  key: "render",
387
371
  value: function render() {
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);
372
+ var _this$props3 = this.props,
373
+ width = _this$props3.width,
374
+ height = _this$props3.height,
375
+ state = _this$props3.state,
376
+ stateExtractor = _this$props3.stateExtractor,
377
+ measurementUnit = _this$props3.measurementUnit,
378
+ props = (0, _objectWithoutProperties2["default"])(_this$props3, _excluded);
395
379
  var _this$state = this.state,
396
380
  savePopupVisible = _this$state.savePopupVisible,
397
381
  quotePopupVisible = _this$state.quotePopupVisible,
package/lib/index.js CHANGED
@@ -70,14 +70,9 @@ function renderKitchenSimulator(container) {
70
70
  var promise = new Promise(function (res) {
71
71
  return _resolve = res;
72
72
  });
73
-
74
- // failsafe: resolve after X ms no matter what (avoid host deadlock)
75
73
  var timeoutMs = (_ev$waitForAckMs = ev === null || ev === void 0 ? void 0 : ev.waitForAckMs) !== null && _ev$waitForAckMs !== void 0 ? _ev$waitForAckMs : 15000;
76
74
  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
- }
75
+ _this3.forceComplete(id, 'ack-timeout');
81
76
  }, timeoutMs);
82
77
  this.queue.push({
83
78
  id: id,
@@ -117,6 +112,22 @@ function renderKitchenSimulator(container) {
117
112
  });
118
113
  });
119
114
  }
115
+ }, {
116
+ key: "forceComplete",
117
+ value: function forceComplete(id, reason) {
118
+ // only force-complete if this is still the in-flight event
119
+ if (this._currentId !== id) return;
120
+ console.warn('[Tool] force complete external event', id, reason);
121
+ try {
122
+ var _this$_currentResolve2;
123
+ (_this$_currentResolve2 = this._currentResolve) === null || _this$_currentResolve2 === void 0 || _this$_currentResolve2.call(this);
124
+ } finally {
125
+ this._currentResolve = null;
126
+ this._currentId = null;
127
+ this.processing = false;
128
+ this.processNext();
129
+ }
130
+ }
120
131
  }, {
121
132
  key: "render",
122
133
  value: function render() {
@@ -133,7 +144,7 @@ function renderKitchenSimulator(container) {
133
144
  root = (0, _client.createRoot)(container);
134
145
  container[ROOT_KEY] = root;
135
146
  }
136
- root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, props), container);
147
+ root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, props));
137
148
  return {
138
149
  // ✅ Promise-based API (use this from host)
139
150
  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.13",
3
+ "version": "3.1.0-alpha.15",
4
4
  "description": "It is a kitchen simulator (self-contained micro-frontend).",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",