UNPKG

hbp-quickfire

Version:

A library of useful user-interface components built with React on top of React Bootstrap and MobX

44 lines (33 loc) 13.8 kB
var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _dec, _desc, _value, _class, _descriptor;function _initDefineProp(target, property, descriptor, context) {if (!descriptor) return;Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 });}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object['ke' + 'ys'](descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object['define' + 'Property'](target, property, desc);desc = null;}return desc;}function _initializerWarningHelper(descriptor, context) {throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');} /* * Copyright (c) Human Brain Project * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { observable, action } from "mobx"; /** * A Store handling a virtual clipboard of text selected inside the current browser window. * Importing this module will always return the same instance of that store * @memberof Stores * @namespace ClipboardStore * @class ClipboardStore */var ClipboardStore = (_dec = action.bound, (_class = function () {function ClipboardStore() {_classCallCheck(this, ClipboardStore);_initDefineProp(this, "selection", _descriptor, this);document.addEventListener("selectionchange", this._selectionEventHandler);}_createClass(ClipboardStore, [{ key: "_selectionEventHandler", value: function _selectionEventHandler() { var currentSelection = document. getSelection(). toString(). trim(); if (currentSelection) { this.selection = currentSelection.trim(); } } }, { key: "reset", /** * Clear the value stored in the virtual clipboard * @memberof Stores.ClipboardStore */value: function reset() { this.selection = ""; } }]);return ClipboardStore;}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "selection", [observable], { enumerable: true, initializer: function initializer() {return "";} }), _applyDecoratedDescriptor(_class.prototype, "_selectionEventHandler", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_selectionEventHandler"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "reset", [action], Object.getOwnPropertyDescriptor(_class.prototype, "reset"), _class.prototype)), _class)); export default new ClipboardStore();