UNPKG

rete-readonly-plugin

Version:

Rete.js Readonly plugin ==== [![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua) [![Discord](https://img.shields.io/discord/1081223198055604244?color=%237289da&label=Discord)](h

77 lines (72 loc) 2.11 kB
/*! * 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