kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
513 lines (512 loc) • 20.4 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.safeLoadMapList = exports.Vertex = exports.State = exports.Scene = exports.Line = exports.Layer = exports.Item = exports.Hole = exports.HistoryStructure = exports.Group = exports.Grid = exports.ElementsSet = exports.DefaultLayers = exports.DefaultGrids = exports.CatalogElement = exports.Catalog = exports.Area = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _immutable = require("immutable");
var _constants = require("./constants");
var _snap = require("./utils/snap");
var _helper = require("./utils/helper");
var _convertUnitsLite = require("./utils/convert-units-lite");
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; }
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; }
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)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var safeLoadMapList = exports.safeLoadMapList = function safeLoadMapList(mapList, Model, defaultMap) {
return mapList ? new _immutable.Map(mapList).map(function (m) {
return new Model(m);
}).toMap() : defaultMap || new _immutable.Map();
};
var Grid = exports.Grid = /*#__PURE__*/function (_Record) {
function Grid() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Grid);
return _callSuper(this, Grid, [_objectSpread(_objectSpread({}, json), {}, {
properties: (0, _immutable.fromJS)(json.properties || {})
})]);
}
(0, _inherits2["default"])(Grid, _Record);
return (0, _createClass2["default"])(Grid);
}((0, _immutable.Record)({
id: '',
type: '',
properties: (0, _immutable.Map)()
}, 'Grid'));
var DefaultGrids = exports.DefaultGrids = new _immutable.Map({
h1: new Grid({
id: 'h1',
type: 'horizontal-streak',
properties: {
step: 24,
colors: ['rgba(193, 202, 228, 0.45)'] // dot's color
}
}),
v1: new Grid({
id: 'v1',
type: 'vertical-streak',
properties: {
step: 24,
colors: ['rgba(193, 202, 228, 0.45)'] // dot's color
}
})
});
var ElementsSet = exports.ElementsSet = /*#__PURE__*/function (_Record2) {
function ElementsSet() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, ElementsSet);
return _callSuper(this, ElementsSet, [{
vertices: new _immutable.List(json.vertices || []),
lines: new _immutable.List(json.lines || []),
holes: new _immutable.List(json.holes || []),
areas: new _immutable.List(json.areas || []),
items: new _immutable.List(json.items || [])
}]);
}
(0, _inherits2["default"])(ElementsSet, _Record2);
return (0, _createClass2["default"])(ElementsSet);
}((0, _immutable.Record)({
vertices: new _immutable.List(),
lines: new _immutable.List(),
holes: new _immutable.List(),
areas: new _immutable.List(),
items: new _immutable.List()
}, 'ElementsSet'));
var sharedAttributes = {
id: '',
type: '',
prototype: '',
name: '',
misc: new _immutable.Map(),
selected: false,
properties: new _immutable.Map(),
style: '',
category: '',
visible: true
};
var Vertex = exports.Vertex = /*#__PURE__*/function (_Record3) {
function Vertex() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Vertex);
return _callSuper(this, Vertex, [_objectSpread(_objectSpread({}, json), {}, {
lines: new _immutable.List(json.lines || []),
areas: new _immutable.List(json.areas || [])
})]);
}
(0, _inherits2["default"])(Vertex, _Record3);
return (0, _createClass2["default"])(Vertex);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
x: -1,
y: -1,
prototype: 'vertices',
lines: new _immutable.List(),
areas: new _immutable.List()
}), 'Vertex'));
var Line = exports.Line = /*#__PURE__*/function (_Record4) {
function Line() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Line);
return _callSuper(this, Line, [_objectSpread(_objectSpread({}, json), {}, {
createdDateTime: json.createdDateTime !== undefined ? json.createdDateTime : new Date().getTime(),
properties: (0, _immutable.fromJS)(json.properties || {}),
vertices: new _immutable.List(json.vertices || []),
holes: new _immutable.List(json.holes || []),
relatedVertices: new _immutable.List(json.relatedVertices || []),
userData: {}
})]);
}
(0, _inherits2["default"])(Line, _Record4);
return (0, _createClass2["default"])(Line);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
createdDateTime: new Date().getTime(),
prototype: 'lines',
vertices: new _immutable.List(),
relatedVertices: new _immutable.List(),
holes: new _immutable.List(),
focus: false,
wallColor: '#dddddd',
userData: {}
}), 'Line'));
var Hole = exports.Hole = /*#__PURE__*/function (_Record5) {
function Hole() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Hole);
return _callSuper(this, Hole, [_objectSpread(_objectSpread({}, json), {}, {
properties: (0, _immutable.fromJS)(json.properties || {}),
userData: {}
})]);
}
(0, _inherits2["default"])(Hole, _Record5);
return (0, _createClass2["default"])(Hole);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'holes',
offset: -1,
x: 0,
y: 0,
rotation: 0,
line: '',
url: '',
userData: {}
}), 'Hole'));
var Area = exports.Area = /*#__PURE__*/function (_Record6) {
function Area() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Area);
return _callSuper(this, Area, [_objectSpread(_objectSpread({}, json), {}, {
properties: (0, _immutable.fromJS)(json.properties || {}),
vertices: new _immutable.List(json.vertices || [])
})]);
}
(0, _inherits2["default"])(Area, _Record6);
return (0, _createClass2["default"])(Area);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'areas',
vertices: new _immutable.List(),
holes: new _immutable.List(),
texture: {
roughness: 0.9,
metalness: 0,
uri: ''
}
}), 'Area'));
var Item = exports.Item = /*#__PURE__*/function (_Record7) {
function Item() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Item);
return _callSuper(this, Item, [_objectSpread(_objectSpread({}, json), {}, {
properties: (0, _immutable.fromJS)(json.properties || {})
})]);
}
(0, _inherits2["default"])(Item, _Record7);
return (0, _createClass2["default"])(Item);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'items',
x: 0,
y: 0,
rotation: 0,
submodule: new _immutable.List(),
normalMap: new _immutable.List(),
doorStyle: new _immutable.Map(),
animate: 0,
animValue: 0,
itemID: -1,
sku_number: '',
layoutpos: '',
cabinet_category: '',
counterTop: {
roughness: 0.9,
metalness: 0.1,
uri: ''
},
molding: [],
backsplashVisible: false,
applianceMaterial: {
roughness: 0.4,
metalness: 0.3
},
distArray: [[0, 0], [0, 0], [0, 0], [0, 0]]
}), 'Item'));
var Layer = exports.Layer = /*#__PURE__*/function (_Record8) {
function Layer() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Layer);
return _callSuper(this, Layer, [_objectSpread(_objectSpread({}, json), {}, {
vertices: safeLoadMapList(json.vertices, Vertex),
lines: safeLoadMapList(json.lines, Line),
holes: safeLoadMapList(json.holes, Hole),
areas: safeLoadMapList(json.areas, Area),
items: safeLoadMapList(json.items, Item),
doorStyle: json.doorStyle !== null ? json.doorStyle : null,
selected: new ElementsSet(json.selected)
})]);
}
(0, _inherits2["default"])(Layer, _Record8);
return (0, _createClass2["default"])(Layer);
}((0, _immutable.Record)({
id: '',
altitude: 0,
order: 0,
opacity: 1,
name: '',
visible: true,
vertices: new _immutable.Map(),
lines: new _immutable.Map(),
holes: new _immutable.Map(),
areas: new _immutable.Map(),
items: new _immutable.Map(),
selected: new ElementsSet(),
counterTop: {},
wallColor: {},
floorStyle: {},
doorHandle: '',
doorStyle: null,
molding: [],
backsplash: {
roughness: 0.2,
metalness: 0.1,
uri: ''
},
backsplashApplied: false,
ceilHeight: 96,
unit: _constants.UNIT_INCH
}, 'Layer'));
var Group = exports.Group = /*#__PURE__*/function (_Record9) {
function Group() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Group);
return _callSuper(this, Group, [_objectSpread(_objectSpread({}, json), {}, {
properties: (0, _immutable.fromJS)(json.properties || {}),
elements: (0, _immutable.fromJS)(json.elements || {})
})]);
}
(0, _inherits2["default"])(Group, _Record9);
return (0, _createClass2["default"])(Group);
}((0, _immutable.Record)(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'groups',
x: 0,
y: 0,
rotation: 0,
elements: new _immutable.Map()
}), 'Group'));
var DefaultLayers = exports.DefaultLayers = new _immutable.Map({
'layer-1': new Layer({
id: 'layer-1',
name: 'default'
})
});
var Scene = exports.Scene = /*#__PURE__*/function (_Record0) {
function Scene() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Scene);
var layers = safeLoadMapList(json.layers, Layer, DefaultLayers);
return _callSuper(this, Scene, [_objectSpread(_objectSpread({}, json), {}, {
// grids: safeLoadMapList(json.grids, Grid, DefaultGrids),
grids: DefaultGrids,
layers: layers,
selectedLayer: layers.first().id,
groups: safeLoadMapList(json.groups || {}, Group),
meta: json.meta ? (0, _immutable.fromJS)(json.meta) : new _immutable.Map(),
guides: !(0, _helper.isEmpty)(json.guides) ? (0, _immutable.fromJS)(json.guides) : new _immutable.Map({
horizontal: new _immutable.Map(),
vertical: new _immutable.Map(),
circular: new _immutable.Map()
})
})]);
}
(0, _inherits2["default"])(Scene, _Record0);
return (0, _createClass2["default"])(Scene);
}((0, _immutable.Record)({
unit: 'cm',
rulerUnit: 'in',
layers: new _immutable.Map(),
grids: new _immutable.Map(),
selectedLayer: null,
groups: new _immutable.Map(),
width: 3000,
height: 2000,
meta: new _immutable.Map(),
//additional info
guides: new _immutable.Map(),
title: '',
currentProjectID: null,
showfg: true,
showWallLengthMeasure: 1,
showBaseCabinetMeasure: 1,
showWallCabinetMeasure: 1,
showWindowDoorMeasure: 1,
isLoadingCabinet: false,
loadFlag: false,
isEndDragging: false,
setLineAttributes: false
}, 'Scene'));
var CatalogElement = exports.CatalogElement = /*#__PURE__*/function (_Record1) {
function CatalogElement() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, CatalogElement);
return _callSuper(this, CatalogElement, [_objectSpread(_objectSpread({}, json), {}, {
info: (0, _immutable.fromJS)(json.info),
properties: (0, _immutable.fromJS)(json.properties),
obj: (0, _immutable.fromJS)(json.obj)
})]);
}
(0, _inherits2["default"])(CatalogElement, _Record1);
return (0, _createClass2["default"])(CatalogElement);
}((0, _immutable.Record)({
itemID: -1,
name: '',
prototype: '',
info: new _immutable.Map(),
properties: new _immutable.Map(),
obj: new _immutable.Map(),
type: '',
cds: new _immutable.Map(),
customer_property: new _immutable.Map()
}, 'CatalogElement'));
var Catalog = exports.Catalog = /*#__PURE__*/function (_Record10) {
function Catalog() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, Catalog);
var elements = safeLoadMapList(json.elements, CatalogElement);
return _callSuper(this, Catalog, [{
elements: elements,
ready: !elements.isEmpty()
}]);
}
(0, _inherits2["default"])(Catalog, _Record10);
return (0, _createClass2["default"])(Catalog, [{
key: "factoryElement",
value: function factoryElement(type, options, initialProperties, state) {
if (!this.elements.has(type)) {
var catList = this.elements.map(function (element) {
return element.name;
}).toArray();
throw new Error("Element ".concat(type, " does not exist in catalog ").concat(catList));
}
var element = this.elements.get(type);
var properties = element.properties.map(function (value, key) {
return initialProperties && initialProperties.has(key) ? initialProperties.get(key) : value.get('defaultValue');
});
if (options) {
if (options.isDuplication) {
var layerID = state.scene.selectedLayer;
var currentItemID = state.scene.getIn(['layers', layerID, 'selected', 'items'])._tail.array[0];
var currentItem = state.scene.getIn(['layers', layerID, 'items', currentItemID]);
var sizeinfo = {
width: currentItem.properties.get('width'),
height: currentItem.properties.get('height'),
depth: currentItem.properties.get('depth')
};
properties = properties.set('width', sizeinfo.width).set('height', sizeinfo.height).set('depth', sizeinfo.depth);
if (currentItem.properties.get('oldDepth') !== undefined) properties = properties.set('oldDepth', currentItem.properties.get('oldDepth'));
if (currentItem.properties.get('oldWidth') !== undefined) properties = properties.set('oldWidth', currentItem.properties.get('oldWidth'));
if (currentItem.properties.get('oldHeight') !== undefined) properties = properties.set('oldHeight', currentItem.properties.get('oldHeight'));
} else if (element.prototype === 'holes') {} else {
var temp = {
width: element.getIn(['info', 'sizeinfo', 'width']),
height: element.getIn(['info', 'sizeinfo', 'height']),
depth: element.getIn(['info', 'sizeinfo', 'depth'])
};
var _sizeinfo = {
width: new _immutable.Map({
_length: temp.width,
_unit: 'in',
length: (0, _convertUnitsLite.convert)(temp.width).from('in').to('cm')
}),
height: new _immutable.Map({
_length: temp.height,
_unit: 'in',
length: (0, _convertUnitsLite.convert)(temp.height).from('in').to('cm')
}),
depth: new _immutable.Map({
_length: temp.depth,
_unit: 'in',
length: (0, _convertUnitsLite.convert)(temp.depth).from('in').to('cm')
})
};
properties = properties.set('width', _sizeinfo.width).set('height', _sizeinfo.height).set('depth', _sizeinfo.depth);
}
}
switch (element.prototype) {
case 'lines':
return new Line(options).merge({
properties: properties
});
case 'holes':
return new Hole(options).merge({
properties: properties
});
case 'areas':
return new Area(options).merge({
properties: properties
});
case 'items':
return new Item(options).merge({
properties: properties
});
default:
throw new Error('prototype not valid');
}
}
}]);
}((0, _immutable.Record)({
ready: false,
page: 'root',
path: new _immutable.List(),
elements: new _immutable.Map()
}, 'Catalog'));
var HistoryStructure = exports.HistoryStructure = /*#__PURE__*/function (_Record11) {
function HistoryStructure() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, HistoryStructure);
return _callSuper(this, HistoryStructure, [{
list: (0, _immutable.fromJS)(json.list || []),
first: new Scene(json.scene),
last: new Scene(json.last || json.scene)
}]);
}
(0, _inherits2["default"])(HistoryStructure, _Record11);
return (0, _createClass2["default"])(HistoryStructure);
}((0, _immutable.Record)({
list: new _immutable.List(),
first: null,
last: null
}, 'HistoryStructure'));
var State = exports.State = /*#__PURE__*/function (_Record12) {
function State() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2["default"])(this, State);
return _callSuper(this, State, [_objectSpread(_objectSpread({}, json), {}, {
scene: new Scene(json.scene),
sceneHistory: new HistoryStructure(json),
catalog: new Catalog(json.catalog || {}),
viewer2D: new _immutable.Map(json.viewer2D || {}),
replacingSupport: new _immutable.Map(json.drawingSupport || {}),
drawingSupport: new _immutable.Map(json.drawingSupport || {}),
draggingSupport: new _immutable.Map(json.draggingSupport || {}),
rotatingSupport: new _immutable.Map(json.rotatingSupport || {}),
misc: json.misc ? (0, _immutable.fromJS)(json.misc) : new _immutable.Map()
})]);
}
(0, _inherits2["default"])(State, _Record12);
return (0, _createClass2["default"])(State);
}((0, _immutable.Record)({
mode: _constants.MODE_IDLE,
scene: new Scene(),
sceneHistory: new HistoryStructure(),
catalog: new Catalog(),
viewer2D: new _immutable.Map(),
mouse: new _immutable.Map({
x: 0,
y: 0
}),
zoom: 0,
snapMask: _snap.SNAP_MASK,
snapElements: new _immutable.List(),
activeSnapElement: null,
replacingSupport: new _immutable.Map(),
drawingSupport: new _immutable.Map(),
draggingSupport: new _immutable.Map(),
rotatingSupport: new _immutable.Map(),
doorStyle: null,
oStyle: null,
errors: new _immutable.List(),
warnings: new _immutable.List(),
clipboardProperties: new _immutable.Map(),
selectedElementsHistory: new _immutable.List(),
misc: new _immutable.Map(),
//additional info
alterate: false,
isOpen: false,
popup: false,
openedType: 0,
login: false,
userId: 0,
isHelp: false,
isCabinetDrawing: false
}, 'State'));