Export template source from be30143a326d5d7d7b0cbabea5bc5ac0301ef5b9:examples/local-first/packages/language-reader-presentation

This commit is contained in:
Quixos Template Publisher
2000-01-01 00:00:00 +00:00
commit 19b330933d
61 changed files with 9997 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { useCrdtText, useLiveField, type ExactReference } from "@quixos/camino-react";
import { interfaces } from "./gen/client.js";
/** Clear only the submitted text, preserving a newer collaborative draft. */
export function usePrompt(reference: ExactReference, path: "name" | "change" | "followup" | "generate") {
const operation = interfaces.ReadingNavigation.prompts.edit;
const draft = useCrdtText({ key: reference.object + "/prompt/" + path, operation, reference, path: [path] });
const field = useLiveField({ key: reference.object + "/prompt-clear/" + path, operation, reference });
return {
...draft,
clearSubmitted(expected: string) {
const current = field.current();
if (current.status !== "ready") return;
const snapshot = current.binding.getSnapshot();
if (snapshot.value[path] === expected)
current.binding.edit((editor) => editor.spliceText([path], 0, expected.length, ""), snapshot);
},
};
}