kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
128 lines (127 loc) • 5.47 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _regeneratorRuntime from "@babel/runtime/regenerator";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Layer, Grids } from "./export";
import { searchForSkuValue } from "./utils";
var Scene = /*#__PURE__*/function (_Component) {
function Scene() {
_classCallCheck(this, Scene);
return _callSuper(this, Scene, arguments);
}
_inherits(Scene, _Component);
return _createClass(Scene, [{
key: "componentWillReceiveProps",
value: function () {
var _componentWillReceiveProps = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(nextProps) {
var scene, catalog, height, layers, selectedLayer, msg, isNotFoundInElements, itemType;
return _regeneratorRuntime.wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
// console.log("componentDidMount", this.props.scene.hashCode(), nextProps.scene.hashCode());
if (this.props.scene.hashCode() !== nextProps.scene.hashCode()) {
scene = nextProps.scene, catalog = nextProps.catalog;
height = scene.height, layers = scene.layers;
selectedLayer = layers.get(scene.selectedLayer);
msg = '';
isNotFoundInElements = false;
itemType = '';
selectedLayer.items.valueSeq().forEach(function (item) {
if (!catalog.elements.hasOwnProperty(item.type)) {
itemType = item.type;
isNotFoundInElements = true;
}
});
// if(isNotFoundInElements){
// const deepSearchResult = await searchForSkuValue(catalog, selectedLayer, itemType)
// if(!deepSearchResult.isAvailable){
// msg += (`Element ${itemType} does not exist in catalog.\n`);
// }
// }
// if(msg !== '') {
// msg += `Do you want to initialize?`;
// confirm(msg)
// ? this.context.projectActions.newProject()
// : null
// }
}
case 1:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function componentWillReceiveProps(_x) {
return _componentWillReceiveProps.apply(this, arguments);
}
return componentWillReceiveProps;
}()
}, {
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps, nextState) {
return this.props.scene.hashCode() !== nextProps.scene.hashCode();
}
}, {
key: "render",
value: function render() {
var _this = this;
// console.log("scene", this);
var _this$props = this.props,
scene = _this$props.scene,
catalog = _this$props.catalog;
var height = scene.height,
layers = scene.layers;
var selectedLayer = layers.get(scene.selectedLayer);
return /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement(Grids, {
scene: scene
}), /*#__PURE__*/React.createElement("g", {
style: {
pointerEvents: 'none'
}
}, layers.entrySeq().filter(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
layerID = _ref2[0],
layer = _ref2[1];
return layerID !== scene.selectedLayer && layer.visible;
}).map(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
layerID = _ref4[0],
layer = _ref4[1];
return /*#__PURE__*/React.createElement(Layer, {
key: layerID,
layer: layer,
scene: scene,
catalog: catalog,
mode: _this.props.state.mode,
state: _this.props.state,
relatedLines: _this.props.relatedLines
});
})), /*#__PURE__*/React.createElement(Layer, {
key: selectedLayer.id,
layer: selectedLayer,
scene: scene,
catalog: catalog,
mode: this.props.state.mode,
state: this.props.state,
relatedLines: this.props.relatedLines
}));
}
}]);
}(Component);
export { Scene as default };
Scene.propTypes = {
scene: PropTypes.object.isRequired,
catalog: PropTypes.object.isRequired,
relatedLines: PropTypes.object.isRequired
};
Scene.contextTypes = {
projectActions: PropTypes.object.isRequired
};