feat(documents): Create-from entry points, including a highlighted selection (#14) - #125
Merged
Merged
Conversation
…lection + Create on every document browser row and in the editor opens the shared preview/edit/confirm window on a `document` source, and highlighting markdown in the editor offers the same four destinations for a `docElements` source — the document id plus the selected passage, which is the only identity a selection has. Both entry points only ever send ids: the server re-fetches and re-authorizes the document and derives the result from its own copy. Everything the window shows is seeded locally so the mapping is visible before anything is created: - Document → list: each heading and bullet point becomes its own row, previewed through the Section / Text / Type columns the server derives them into. A document with neither falls back to the blocks it does have rather than previewing an empty list. - Document → message: markdown flattened to plain text with paragraphs kept and code blocks — fenced and indented — dropped. Shown as a preview only; the body the composer receives is still built and size-checked server-side. Both conversions are pure functions (`documentListRows`, `markdownToPlainText`) so the rules are pinned by unit tests rather than through the UI. Additive changes in :core:materialize, kept to what the document entry points need: `MaterializePreview` gained `documentMarkdown` (a source that already is a document is previewed verbatim instead of re-rendered from rows) and `draftBody` (the message destination shows the draft before it is asked for), and the window ViewModel gained `reset()` so closing the window ends the flow — it keeps the edits across recomposition, so only the host can say when a flow is over. Closes #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14. Part of epic #10. Opens #15's shared window.
What changed
CreateFromMenuoffering theweb's own four labels (To List / To Doc / To List & Doc / To Message), opening Create from…: the preview / edit / confirm window #15's
MaterializeWindowwith aMaterializeSource.Document(documentId).TextFieldValue, so a highlightedrange is known. While something is highlighted, a "Selection · + Create" bar opens the same window
with
MaterializeSource.DocumentSelection(documentId, markdown)(wire kinddocElements).domain/DocumentElements.kt:documentListRows()(one row per heading and bullet, falling back to every parsed block when adocument has neither) and
markdownToPlainText()(paragraphs kept, bullets marked•, inlinemarkdown flattened, code blocks dropped — fenced and indented).
The element-identity caveat resolved — and the open question from #15 answered
create-from.txtstatesdocElementscarriesdocumentId+markdown: string: a selection has noid, the markdown is its identity, which is exactly how #11 already models it. Nothing was invented.
Corroborated against the live web client — the public JS bundle contains the real Create-from window,
which supplied what neither the help centre nor the OpenAPI spec states:
document/docElementsare Section / Text / Type, withsourceKeysection/text/type— so no source key here is a guess. (This is the question Create from…: the preview / edit / confirm window #15 leftopen for the entry-point issues; it is now answered for documents.)
heading|list-item, falling back to all elements;relativePathdefaults (Copy of X,slug-<id8>.md,X (selection)).Nothing was written to the account — the authed probe was blocked in that environment.
:core:materialize— three additive, defaulted changesMaterializePreview.documentMarkdown(a source that already is a document is previewed verbatimrather than re-rendered as bullets-from-rows),
MaterializePreview.draftBody, andMaterializeWindowViewModel.reset()— withoutreset(), dismissing and reopening the same launchresurrected the previous success pane, because
start()deliberately keeps edits acrossrecomposition.
Deviations worth knowing
drops indented ones too (CommonMark-ish — it must start a block, so nested bullets and list
continuations are unaffected).
varies by the destination the menu picked (
To Doc→ "Copy of …").ToMessageDraftstill sends nocontent, so the server builds andsizes the real body.
Verification
./gradlew :app:assembleDebug testDebugUnitTest→ BUILD SUCCESSFUL, 1391 tests, 0 failures(
:feature:documents218,:core:materialize69, both re-run with--rerun-tasks).New:
DocumentElementsTest(18 — heading/bullet rows including nested bullets, mixed content, adocument with neither; plain text preserving paragraphs, dropping fenced/tilde/unterminated/indented
code, bullets, inline flattening),
DocumentMaterializeLaunchTest(9),SelectionPinTest(6 — atap that blurs the field must not steal the selection out from under the action), plus editor and
browser ViewModel cases. Compose entry-point tests compile, not executed (no emulator).
Follow-ups
DocumentsRoute/DocumentEditorRouteexposeonOpenList: (String) -> Unit = {}, but wiring it needs the app NavHost — out of scope here.KDoc). A selection is unaffected, since its markdown is sent.
sourceKeys match the web client exactly but were not confirmed against a livePOST /api/materializeresponse; a server-side rename would show empty cells rather than an error.