Public
Edited
Jun 27, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
editor.setOption("lineNumbers", false)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function wrapCMOption(view, name, {doc = cmDoc, eventType = "input", get = ({value}) => value, validate, invalidation, block = true}) {
is.a(block, String) && (block = block.valueOf());
block = is.object(block)
? {valid: Boolean(block.valid), invalid: Boolean(block.invalid), mode: block.mode || "hard"}
: block
? {valid: true, invalid: true, mode: is.string(block) ? block.valueOf() : "hard"}
: {valid: false, invalid: false, mode: "soft"};
block.mode = block.mode == "soft" ? Event.prototype.stopPropagation : Event.prototype.stopImmediatePropagation;
Object.freeze(block);
function handler(e) {
let newVal = get.call(view, view, name);
if (newVal != doc.getEditor().getOption(name)) {
if (validate && !validate.call(view, newVal, name)) {
// invalid
block.invalid && block.mode.call(e);
} else {
// valid
block.valid && block.mode.call(e);
doc.getEditor().setOption(name, newVal);
}
}
}
handler.opts = { passive: true };
for (let type of to.multi(eventType)) {
view.addEventListener(type, handler, handler.opts);
}
invalidation?.then?.(() => {
for (let type of to.multi(eventType)) {
view.removeEventListener(type, handler, handler.opts);
}
doc = view = undefined;
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more