UNPKG

collaborative-editor

Version:

JSON CRDT str node bindings to any generic plain text editor.

52 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StoreStrFacade = void 0; class StoreStrFacade { /** * @param store JsonPatchStore instance which wraps a "str" node. */ constructor(store, strict = false) { this.store = store; this.strict = strict; this.view = store.getSnapshot; this.ins = (pos, str) => { store.update({ op: 'str_ins', path: [], pos, str }); }; this.del = (pos, len) => { store.update({ op: 'str_del', path: [], pos, len }); }; this.subscribe = store.subscribe; this.tick = strict ? undefined : () => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = this.store).api) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.asStr) === null || _d === void 0 ? void 0 : _d.call(_c).api.model.tick) !== null && _e !== void 0 ? _e : 0; }; } get findId() { var _a, _b, _c, _d; if (this.strict) return void 0; const str = (_d = (_c = (_b = (_a = this.store).api) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.asStr) === null || _d === void 0 ? void 0 : _d.call(_c); if (!str) return void 0; return str.findId.bind(str); } get findPos() { var _a, _b, _c, _d; if (this.strict) return void 0; const str = (_d = (_c = (_b = (_a = this.store).api) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.asStr) === null || _d === void 0 ? void 0 : _d.call(_c); if (!str) return void 0; return str.findPos.bind(str); } get transaction() { var _a, _b, _c, _d; if (this.strict) return void 0; const str = (_d = (_c = (_b = (_a = this.store).api) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.asStr) === null || _d === void 0 ? void 0 : _d.call(_c); if (!str) return void 0; return str.api.transaction.bind(str.api); } } exports.StoreStrFacade = StoreStrFacade; //# sourceMappingURL=StoreStrFacade.js.map