awv3
Version:
⚡ AWV3 embedded CAD
100 lines (84 loc) • 2.94 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
var _class, _temp;
var _templateObject = /*#__PURE__*/ _taggedTemplateLiteralLoose(["element must be initialized with a plugin"], ["element must be initialized with a plugin"]);
import Lifecycle from './lifecycle.js';
import { errUndefined } from '../core/helpers';
import { actions } from './store/elements';
import { actions as pluginActions } from './store/plugins';
var Element = (_temp = _class =
/*#__PURE__*/
function (_Lifecycle) {
_inheritsLoose(Element, _Lifecycle);
function Element(plugin, props) {
var _this;
if (plugin === void 0) {
plugin = errUndefined(_templateObject);
}
var reflectedProps = _extends({
name: '',
type: '',
hint: '',
disabled: false,
hover: false,
visible: true,
active: true,
collapsed: false,
tooltip: undefined,
children: [],
color: undefined,
focus: false,
flex: 1,
margin: true,
lastEvent: {},
index: 0
}, props, {
plugin: plugin.id,
managed: true
});
_this = _Lifecycle.call(this, plugin.session, actions, function (state) {
return state.elements[_this.id];
}, reflectedProps) || this; // TODO: see todo below
_this.__plugin = plugin;
plugin.dependencies.push(_assertThisInitialized(_this));
return _this;
}
var _proto = Element.prototype;
_proto.addChild = function addChild(element) {
this.store.dispatch(actions.addChild(this.id, element instanceof Element ? element.id : element));
};
_proto.removeChild = function removeChild(element) {
this.store.dispatch(actions.removeChild(this.id, element instanceof Element ? element.id : element));
};
_proto.removeAllChilds = function removeAllChilds() {
this.store.dispatch(actions.removeAllChilds(this.id));
}; // TODO: this can (and should) be abstracted in lifecycle and in the store via thunk
_proto.__onDestroyed = function __onDestroyed() {
var index = this.__plugin.dependencies.indexOf(this);
if (index > -1) this.__plugin.dependencies.splice(index, 1);
this.store.dispatch(pluginActions.removeElement(this.__plugin.id, this.id));
};
return Element;
}(Lifecycle()), Object.defineProperty(_class, "Type", {
configurable: true,
enumerable: true,
writable: true,
value: {
Group: 'Group',
Label: 'Label',
Input: 'Input',
Button: 'Button',
Checkbox: 'Checkbox',
Dropdown: 'Dropdown',
Selection: 'Selection',
Console: 'Console',
Spacer: 'Spacer',
Divider: 'Divider',
Slider: 'Slider',
Link: 'Link',
Custom: 'Custom'
}
}), _temp);
export { Element as default };