UNPKG

alinea

Version:
54 lines (52 loc) 1.14 kB
import "../../chunks/chunk-NZLE2WMY.js"; // src/core/shape/ScalarShape.ts var ScalarShape = class { constructor(label, initialValue, searchable) { this.label = label; this.initialValue = initialValue; this.searchable = searchable; } create() { return this.initialValue; } toY(value) { return value; } toV1(value) { return value; } fromY(yValue) { return yValue; } applyY(value, parent, key) { const current = parent.get(key); if (current !== value) parent.set(key, value); } init(parent, key) { if (!parent.has(key)) parent.set(key, this.toY(this.create())); } watch(parent, key) { return (fun) => { function w(event) { if (event.keysChanged.has(key)) fun(); } parent.observe(w); return () => parent.unobserve(w); }; } mutator(parent, key) { return (value) => { parent.set(key, value); }; } async applyLinks() { } searchableText(value) { if (!this.searchable) return ""; const stringified = String(value ?? ""); return stringified ? ` ${stringified}` : ""; } }; export { ScalarShape };