kitchen-simulator 4.1.2-react-18 → 4.1.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/index.js +52 -15
- package/lib/index.js +52 -15
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -9,33 +9,70 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import { createRoot } from 'react-dom/client';
|
|
11
11
|
import LiteRenderer from "./LiteRenderer";
|
|
12
|
-
import { flushSync } from 'react-dom';
|
|
13
12
|
export function renderKitchenSimulator(container) {
|
|
14
13
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
// Internal wrapper that exposes a state setter
|
|
14
|
+
var apiRef = null;
|
|
18
15
|
var Wrapper = /*#__PURE__*/function (_React$Component) {
|
|
19
16
|
function Wrapper(p) {
|
|
20
17
|
var _this;
|
|
21
18
|
_classCallCheck(this, Wrapper);
|
|
22
19
|
_this = _callSuper(this, Wrapper, [p]);
|
|
23
20
|
_this.state = {
|
|
24
|
-
externalEvent:
|
|
21
|
+
externalEvent: null
|
|
22
|
+
};
|
|
23
|
+
_this.queue = [];
|
|
24
|
+
_this.processing = false;
|
|
25
|
+
apiRef = {
|
|
26
|
+
enqueueExternalEvent: function enqueueExternalEvent(ev) {
|
|
27
|
+
return _this.enqueue(ev);
|
|
28
|
+
},
|
|
29
|
+
unmount: function unmount() {}
|
|
25
30
|
};
|
|
26
|
-
setExternalEventFn = _this.setExternalEvent.bind(_this);
|
|
27
31
|
return _this;
|
|
28
32
|
}
|
|
29
33
|
_inherits(Wrapper, _React$Component);
|
|
30
34
|
return _createClass(Wrapper, [{
|
|
31
|
-
key: "
|
|
32
|
-
value: function
|
|
35
|
+
key: "enqueue",
|
|
36
|
+
value: function enqueue(ev) {
|
|
37
|
+
if (!ev) return;
|
|
38
|
+
this.queue.push(ev);
|
|
39
|
+
if (!this.processing) this.processNext();
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "processNext",
|
|
43
|
+
value: function processNext() {
|
|
33
44
|
var _this2 = this;
|
|
34
|
-
|
|
45
|
+
var next = this.queue.shift();
|
|
46
|
+
if (!next) {
|
|
47
|
+
this.processing = false;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.processing = true;
|
|
51
|
+
|
|
52
|
+
// Separate task => prevents React 18 batching from collapsing updates
|
|
53
|
+
setTimeout(function () {
|
|
54
|
+
// setting null first ensures `prevProps.externalEvent !== externalEvent`
|
|
55
|
+
// even if two events are referentially equal or key logic is weird
|
|
35
56
|
_this2.setState({
|
|
36
|
-
externalEvent:
|
|
57
|
+
externalEvent: null
|
|
58
|
+
}, function () {
|
|
59
|
+
_this2.setState({
|
|
60
|
+
externalEvent: next
|
|
61
|
+
});
|
|
37
62
|
});
|
|
38
|
-
});
|
|
63
|
+
}, 0);
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "componentDidUpdate",
|
|
67
|
+
value: function componentDidUpdate(prevProps, prevState) {
|
|
68
|
+
var _this3 = this;
|
|
69
|
+
// When the event was delivered, schedule the next one
|
|
70
|
+
if (prevState.externalEvent !== this.state.externalEvent) {
|
|
71
|
+
// Give LiteKitchenConfigurator a chance to react in its componentDidUpdate
|
|
72
|
+
setTimeout(function () {
|
|
73
|
+
return _this3.processNext();
|
|
74
|
+
}, 0);
|
|
75
|
+
}
|
|
39
76
|
}
|
|
40
77
|
}, {
|
|
41
78
|
key: "render",
|
|
@@ -45,17 +82,17 @@ export function renderKitchenSimulator(container) {
|
|
|
45
82
|
}));
|
|
46
83
|
}
|
|
47
84
|
}]);
|
|
48
|
-
}(React.Component);
|
|
85
|
+
}(React.Component);
|
|
49
86
|
var root = createRoot(container);
|
|
50
87
|
root.render(/*#__PURE__*/React.createElement(Wrapper, props));
|
|
51
88
|
return {
|
|
52
89
|
updateExternalEvent: function updateExternalEvent(newExternalEvent) {
|
|
53
|
-
var
|
|
54
|
-
(
|
|
90
|
+
var _apiRef, _apiRef$enqueueExtern;
|
|
91
|
+
(_apiRef = apiRef) === null || _apiRef === void 0 || (_apiRef$enqueueExtern = _apiRef.enqueueExternalEvent) === null || _apiRef$enqueueExtern === void 0 || _apiRef$enqueueExtern.call(_apiRef, newExternalEvent);
|
|
55
92
|
},
|
|
56
93
|
unmount: function unmount() {
|
|
57
94
|
root.unmount();
|
|
58
|
-
|
|
95
|
+
apiRef = null;
|
|
59
96
|
}
|
|
60
97
|
};
|
|
61
98
|
}
|
package/lib/index.js
CHANGED
|
@@ -15,35 +15,72 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
|
|
|
15
15
|
var _react = _interopRequireDefault(require("react"));
|
|
16
16
|
var _client = require("react-dom/client");
|
|
17
17
|
var _LiteRenderer = _interopRequireDefault(require("./LiteRenderer"));
|
|
18
|
-
var _reactDom = require("react-dom");
|
|
19
18
|
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)); }
|
|
20
19
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
20
|
function renderKitchenSimulator(container) {
|
|
22
21
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
// Internal wrapper that exposes a state setter
|
|
22
|
+
var apiRef = null;
|
|
26
23
|
var Wrapper = /*#__PURE__*/function (_React$Component) {
|
|
27
24
|
function Wrapper(p) {
|
|
28
25
|
var _this;
|
|
29
26
|
(0, _classCallCheck2["default"])(this, Wrapper);
|
|
30
27
|
_this = _callSuper(this, Wrapper, [p]);
|
|
31
28
|
_this.state = {
|
|
32
|
-
externalEvent:
|
|
29
|
+
externalEvent: null
|
|
30
|
+
};
|
|
31
|
+
_this.queue = [];
|
|
32
|
+
_this.processing = false;
|
|
33
|
+
apiRef = {
|
|
34
|
+
enqueueExternalEvent: function enqueueExternalEvent(ev) {
|
|
35
|
+
return _this.enqueue(ev);
|
|
36
|
+
},
|
|
37
|
+
unmount: function unmount() {}
|
|
33
38
|
};
|
|
34
|
-
setExternalEventFn = _this.setExternalEvent.bind(_this);
|
|
35
39
|
return _this;
|
|
36
40
|
}
|
|
37
41
|
(0, _inherits2["default"])(Wrapper, _React$Component);
|
|
38
42
|
return (0, _createClass2["default"])(Wrapper, [{
|
|
39
|
-
key: "
|
|
40
|
-
value: function
|
|
43
|
+
key: "enqueue",
|
|
44
|
+
value: function enqueue(ev) {
|
|
45
|
+
if (!ev) return;
|
|
46
|
+
this.queue.push(ev);
|
|
47
|
+
if (!this.processing) this.processNext();
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "processNext",
|
|
51
|
+
value: function processNext() {
|
|
41
52
|
var _this2 = this;
|
|
42
|
-
|
|
53
|
+
var next = this.queue.shift();
|
|
54
|
+
if (!next) {
|
|
55
|
+
this.processing = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.processing = true;
|
|
59
|
+
|
|
60
|
+
// Separate task => prevents React 18 batching from collapsing updates
|
|
61
|
+
setTimeout(function () {
|
|
62
|
+
// setting null first ensures `prevProps.externalEvent !== externalEvent`
|
|
63
|
+
// even if two events are referentially equal or key logic is weird
|
|
43
64
|
_this2.setState({
|
|
44
|
-
externalEvent:
|
|
65
|
+
externalEvent: null
|
|
66
|
+
}, function () {
|
|
67
|
+
_this2.setState({
|
|
68
|
+
externalEvent: next
|
|
69
|
+
});
|
|
45
70
|
});
|
|
46
|
-
});
|
|
71
|
+
}, 0);
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "componentDidUpdate",
|
|
75
|
+
value: function componentDidUpdate(prevProps, prevState) {
|
|
76
|
+
var _this3 = this;
|
|
77
|
+
// When the event was delivered, schedule the next one
|
|
78
|
+
if (prevState.externalEvent !== this.state.externalEvent) {
|
|
79
|
+
// Give LiteKitchenConfigurator a chance to react in its componentDidUpdate
|
|
80
|
+
setTimeout(function () {
|
|
81
|
+
return _this3.processNext();
|
|
82
|
+
}, 0);
|
|
83
|
+
}
|
|
47
84
|
}
|
|
48
85
|
}, {
|
|
49
86
|
key: "render",
|
|
@@ -53,17 +90,17 @@ function renderKitchenSimulator(container) {
|
|
|
53
90
|
}));
|
|
54
91
|
}
|
|
55
92
|
}]);
|
|
56
|
-
}(_react["default"].Component);
|
|
93
|
+
}(_react["default"].Component);
|
|
57
94
|
var root = (0, _client.createRoot)(container);
|
|
58
95
|
root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, props));
|
|
59
96
|
return {
|
|
60
97
|
updateExternalEvent: function updateExternalEvent(newExternalEvent) {
|
|
61
|
-
var
|
|
62
|
-
(
|
|
98
|
+
var _apiRef, _apiRef$enqueueExtern;
|
|
99
|
+
(_apiRef = apiRef) === null || _apiRef === void 0 || (_apiRef$enqueueExtern = _apiRef.enqueueExternalEvent) === null || _apiRef$enqueueExtern === void 0 || _apiRef$enqueueExtern.call(_apiRef, newExternalEvent);
|
|
63
100
|
},
|
|
64
101
|
unmount: function unmount() {
|
|
65
102
|
root.unmount();
|
|
66
|
-
|
|
103
|
+
apiRef = null;
|
|
67
104
|
}
|
|
68
105
|
};
|
|
69
106
|
}
|