rete-readonly-plugin
Version:
Rete.js Readonly plugin ==== [](https://stand-with-ukraine.pp.ua) [](h
77 lines (72 loc) • 2.11 kB
JavaScript
/*!
* rete-readonly-plugin v2.0.1
* (c) 2024 Vitaliy Stoliarov
* Released under the MIT license.
* */
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { Scope } from 'rete';
/**
* Readonly plugin, disables all user interactions
* @priority 9
* @listens nodecreate
* @listens connectioncreate
* @listens nodetranslate
* @listens connectionpick
* @example const readonly = new ReadonlyPlugin<Schemes>();
*editor.use(readonly.root);
*editor.use(area);
*area.use(readonly.area);
*area.use(render);
*connection.use(readonly.connection);
*area.use(connection);
*/
var ReadonlyPlugin = /*#__PURE__*/function () {
function ReadonlyPlugin() {
var _this = this;
_classCallCheck(this, ReadonlyPlugin);
_defineProperty(this, "root", new Scope('readonly'));
_defineProperty(this, "area", new Scope('readonly'));
_defineProperty(this, "connection", new Scope('readonly'));
/**
* Readonly mode state
*/
_defineProperty(this, "enabled", false);
this.root.addPipe(function (context) {
if (!_this.enabled) return context;
if (context.type === 'nodecreate') return;
if (context.type === 'connectioncreate') return;
return context;
});
this.area.addPipe(function (context) {
if (!_this.enabled) return context;
if (context.type === 'nodetranslate') return;
return context;
});
this.connection.addPipe(function (context) {
if (!_this.enabled) return context;
if (context.type === 'connectionpick') return;
return context;
});
}
/**
* Enable the readonly mode
*/
return _createClass(ReadonlyPlugin, [{
key: "enable",
value: function enable() {
this.enabled = true;
}
/**
* Disable the readonly mode
*/
}, {
key: "disable",
value: function disable() {
this.enabled = false;
}
}]);
}();
export { ReadonlyPlugin };
//# sourceMappingURL=rete-readonly-plugin.esm.js.map