UNPKG

@turbox3d/design-engine

Version:

Large-scale design application engine library

115 lines 4.54 kB
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 _typeof from "@babel/runtime/helpers/esm/typeof"; 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; })(); } var __decorate = this && this.__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { Domain, mutation, reactor } from '@turbox3d/reactivity'; import { Command } from '@turbox3d/command-manager'; import SelectionCommand from '../selection-command/index'; import EntityObject from '../entity-object'; var Hint = /*#__PURE__*/function (_Domain) { function Hint() { _classCallCheck(this, Hint); return _callSuper(this, Hint, arguments); } _inherits(Hint, _Domain); return _createClass(Hint, [{ key: "hint", value: function hint(model) { this.hintedEntity = model; } }, { key: "unHint", value: function unHint() { this.hintedEntity = undefined; } }]); }(Domain); __decorate([reactor], Hint.prototype, "hintedEntity", void 0); __decorate([mutation()], Hint.prototype, "hint", null); __decorate([mutation()], Hint.prototype, "unHint", null); var HintCommand = /*#__PURE__*/function (_Command) { function HintCommand() { var _this; _classCallCheck(this, HintCommand); _this = _callSuper(this, HintCommand, arguments); _this.hintDomain = new Hint(); return _this; } /** * @param selectionCommand selection command 实例,hint 与 select 同时启用时需要传入 */ _inherits(HintCommand, _Command); return _createClass(HintCommand, [{ key: "active", value: function active(selectionCommand) { this.selection = selectionCommand; } /** 获取被 hover 的 entity */ }, { key: "getHintedEntity", value: function getHintedEntity() { return this.hintDomain.hintedEntity; } /** hint 指定 entity */ }, { key: "hint", value: function hint(model) { this.hintDomain.hint(model); } /** 取消 hint */ }, { key: "unHint", value: function unHint() { this.hintDomain.unHint(); } }, { key: "onHoverIn", value: function onHoverIn(viewEntity) { var model = EntityObject.getEntityById(viewEntity.id); if (!model) { this.hintDomain.unHint(); return; } if (!this.selection) { this.hintDomain.hint(model); return; } var path = model.getParentPathChain(); var selectedEntities = this.selection.getSelectedEntities(); if (selectedEntities.length && selectedEntities.includes(path[0])) { this.hintDomain.unHint(); return; } if (selectedEntities.length && selectedEntities.includes(model)) { this.hintDomain.unHint(); return; } var layerDepth = this.selection.getLayerDepth(); var pathLength = path.length; if (selectedEntities.length && selectedEntities[0].getRoot() !== path[0]) { var _index = this.selection.getSelectMode() === SelectionCommand.ESelectMode.OVERALL ? 1 : 2; this.hintDomain.hint(path[_index - 1]); return; } var index = Math.min(pathLength, layerDepth); this.hintDomain.hint(path[index - 1]); } }, { key: "onHoverOut", value: function onHoverOut() { this.hintDomain.unHint(); } }]); }(Command); export { HintCommand as default };