UNPKG

@metacell/geppetto-meta-client

Version:

Geppetto web frontend. Geppetto is an open-source platform to build web-based tools to visualize and simulate neuroscience data and models.

152 lines (151 loc) 8.11 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } 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) { _defineProperty(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 _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import * as FlexLayout from 'flexlayout-react'; import { layoutActions } from './actions'; import * as General from '../actions'; import { WidgetStatus } from './model'; import layoutInitialState from './defaultLayout'; export { layoutInitialState }; /** * Layout state update handling. * Logic comes from the layout manager. * * @alias layoutReducer * @memberof Control */ export var layout = function layout() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : layoutInitialState; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case layoutActions.SET_LAYOUT: { return _objectSpread(_objectSpread({}, state), action.data); } case layoutActions.UPDATE_LAYOUT: { return _objectSpread(_objectSpread({}, state), action.data); } case General.IMPORT_APPLICATION_STATE: { var incomingState = action.data.redux.layout; return incomingState; } default: return state; } }; /** * Ensure there is one only active widget in the same panel * @param {*} widgets * @param {*} param1 */ function updateWidgetStatus(widgets, _ref) { var status = _ref.status, panelName = _ref.panelName; if (status !== WidgetStatus.ACTIVE) { return widgets; } return Object.fromEntries(Object.values(widgets).filter(function (widget) { return widget; }).map(function (widget) { return [widget.id, _objectSpread(_objectSpread({}, widget), {}, { status: widget.panelName === panelName ? WidgetStatus.HIDDEN : widget.status })]; })); } function removeUndefined(obj) { return Object.keys(obj).forEach(function (key) { return obj[key] === undefined ? delete obj[key] : ''; }); } function extractPanelName(action) { return action.data.component === "Plot" ? "bottomPanel" : "leftPanel"; } export var widgets = function widgets() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var action = arguments.length > 1 ? arguments[1] : undefined; if (action.data) { removeUndefined(action.data); // Prevent deletion in case of unpolished update action } switch (action.type) { case layoutActions.ADD_WIDGET: case layoutActions.ACTIVATE_WIDGET: case layoutActions.UPDATE_WIDGET: { var newWidget = _objectSpread(_objectSpread({}, state[action.data.id]), {}, { panelName: extractPanelName(action) }, action.data); return _objectSpread(_objectSpread({}, updateWidgetStatus(state, newWidget)), {}, _defineProperty({}, action.data.id, newWidget)); } case layoutActions.SET_WIDGETS: { return _objectSpread({}, action.data); } case layoutActions.ADD_WIDGETS: { return _objectSpread(_objectSpread({}, state), action.data); } case layoutActions.REMOVE_WIDGET: case layoutActions.DESTROY_WIDGET: { var newWidgets = _objectSpread({}, state); delete newWidgets[action.data.id]; return newWidgets; } case layoutActions.UPDATE_LAYOUT: { var model = FlexLayout.Model.fromJson(action.data); var updatedWidgets = _objectSpread({}, state); var parents = new Set(Object.keys(updatedWidgets).map(function (widgetId) { return model.getNodeById(widgetId); }).filter(function (n) { return n; }).map(function (n) { return n === null || n === void 0 ? void 0 : n.getParent(); })); var _iterator = _createForOfIteratorHelper(parents), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var parent = _step.value; for (var i in parent.getChildren()) { var node = parent.getChildren()[i]; if (!updatedWidgets[node.getId()]) { continue; } updatedWidgets[node.getId()] = _objectSpread({}, updatedWidgets[node.getId()]); updatedWidgets[node.getId()].name = node.getName(); if (parent.getType() !== 'border') { // want to restore previous position when activated updatedWidgets[node.getId()].pos = Number.parseInt(i); } updatedWidgets[node.getId()].panelName = parent.getId(); if (parent.isMaximized() && node.isVisible()) { updatedWidgets[node.getId()].status = WidgetStatus.MAXIMIZED; } else if (parent.getType() === 'border') { updatedWidgets[node.getId()].status = WidgetStatus.MINIMIZED; } else if (parent.getSelectedNode().getId() == node.getId()) { updatedWidgets[node.getId()].status = WidgetStatus.ACTIVE; } else { updatedWidgets[node.getId()].status = WidgetStatus.HIDDEN; } } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return updatedWidgets; } default: return state; } };