@scicad/ui-plugin
Version:
Parent class of scicad ui plugins
140 lines (127 loc) • 5.05 kB
JavaScript
var UIPlugin =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
const Key = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"keyboard-shortcut\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
// const PhosphorWidgets = require('@phosphor/widgets');
const request = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"browser-request\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
const {MicropedeClient} = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"@micropede/client/src/client.js\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
if (!window.scicadPlugins)
window.scicadPlugins = new Map();
const APPNAME = 'scicad';
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
class UIPlugin extends MicropedeClient {
constructor(element, focusTracker, port, options) {
super(APPNAME, undefined, port, undefined, undefined, options);
this.element = element;
this.focusTracker = focusTracker;
this.port = port;
Key("delete", () => {
if (this.hasFocus) this.trigger("delete");
});
}
get isPlugin() { return true }
get element() {return this._element}
get hasFocus() {return this.element == this.focusTracker.currentWidget.node}
set element(element) {
element.tabIndex = 0; this._element = element;
}
changeElement(k,item) {
if (this[k]) this.element.removeChild(this[k]);
this.element.appendChild(item);
this[`_${k}`] = item;
}
static Widget(dock, focusTracker, PhosphorWidgets) {
/* Add plugin to specified dock panel */
return new Promise((resolve, reject) => {
request('/mqtt-ws-port', (er, response, body) => {
const widget = new PhosphorWidgets.Widget();
widget.addClass("content");
const port = parseInt(body);
let storageUrl = window.location.origin;
const options = {storageUrl: storageUrl, resubscribe: false};
const plugin = new this(widget.node,focusTracker, port, options);
widget.title.label = plugin.name.replace("-ui-plugin", "").capitalize();
widget.plugin = plugin;
widget.title.closable = false;
dock.addWidget(widget);
plugin.on("activate-tab", ()=> {
dock.activateWidget(widget);
})
// panel.activateWidget(widget);
focusTracker.add(widget);
resolve(widget);
});
});
}
}
module.exports = UIPlugin;
/***/ })
/******/ ]);