collaborative-input
Version:
Collaborative input and textarea bindings to JSON CRDT
37 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollaborativeInput = void 0;
const tslib_1 = require("tslib");
const react_1 = require("react");
const index_1 = require("./index");
class CollaborativeInputState {
constructor(props) {
this.props = props;
this.unbind = () => {
var _a;
(_a = this._unbind) === null || _a === void 0 ? void 0 : _a.call(this);
this._unbind = void 0;
};
this.stop = this.unbind;
this.start = () => this.stop;
this.ref = (el) => {
if (!el)
return this.unbind();
const { str, polling } = this.props;
this._unbind = (0, index_1.bind)(str, el, !!polling);
};
}
}
const CollaborativeInput = (props) => {
const { str, polling, inp, input } = props, rest = tslib_1.__rest(props, ["str", "polling", "inp", "input"]);
// biome-ignore lint: hook dependency list manually managed
const state = (0, react_1.useMemo)(() => new CollaborativeInputState(props), [str, polling]);
// biome-ignore lint: hook dependency list manually managed
(0, react_1.useLayoutEffect)(state.start, [state]);
if (input)
return input(state.ref);
rest.ref = state.ref;
return (0, react_1.createElement)(rest.multiline ? 'textarea' : 'input', rest);
};
exports.CollaborativeInput = CollaborativeInput;
//# sourceMappingURL=CollaborativeInput.js.map