extract reusable functions from plainTextView#27572
Conversation
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (628 lines, 6 files), I've queued these reviewers:
How this works
|
| * React hook that two-way binds an (uncontrolled) text input to a | ||
| * {@link @fluidframework/tree#TextAsTree.Tree}, returning spreadable input props. |
There was a problem hiding this comment.
This isn't really what I'd been imagining. While the 2-way binding could be convenient for some cases, I'm not sure how universally applicable it will be. The caveats called out in the remarks below seem to support this concern.
My assumption is that we would just have a simple 1-way sync from tree -> string. This is simple, and I would think pretty generally applicable. I.e., something like:
Usage:
const { text, selection } = useTreeSynchronizedString(tree, initialSelection);Implementation:
function useTreeSynchronizedString(tree: TextAsTree.Tree, initialSelection?: SelectionRange): {
text: string,
selection: SelectionRange | undefined
} : {
// useEffect block that binds character-change listener and recomputes `text` and `selection` any time the text tree changes
// I think this mostly just amounts to calling `applyTextOps` on any change
}The app author is still responsible for providing the mapping in the other direction.
I think this would be a lot less complex. And an application author that wants to do something like what you've built below could easily use our code as reference / a starting place to create such a utility. But I worry that this code is simultaneously complex and may or may not be widely applicable.
What do you think? I am curious what led you to this larger scope - I could easily be missing something here.
There was a problem hiding this comment.
I started with a smaller scope, but kept expanding it to optimize for "ease of use" for the boards prototype, and ended up basically re-wrapping our existing example without noticing. Your suggestion makes a lot more sense, and I updated with your suggestions :)
Bundle size comparisonBase commit: The PR's CI build failed — fix the build and the comment will update once the next run succeeds. |
Description
Extracts reusable functions from plainTextView for shared use in our example app, and boards.