Skip to content
QuireKit MSFE
Developer docs
v0.0.0 · Experimental

Reading and saving

Read Markdown on demand and connect storage or external updates through incremental events.

Read the complete source

Call getMarkdown() when saving, exporting, or submitting. The result is Markdown text with the original file-format policy supported by the editor preserved.

ts

Read Markdown in the example captures a snapshot. After further edits, read it again to obtain the latest text.

Preparing the editor…

Subscribe to incremental changes

onChange supplies documentId, revision, changes, selection, and origin. Use it to mark unsaved changes or connect incremental host storage. Rendering a toolbar does not require reading the entire document on each keystroke.

ts

For autosave, the application schedules writes and handles failures, retries, and submission order. A successful server response should not automatically replace the full editor content.

External updates

applyChanges() accepts the expected document identity and base revision. Offsets must refer to that revision; stale revisions are rejected. After rejection, obtain the latest state and resolve the conflict.

ts

Versioned changes alone are not a multi-user collaboration protocol. To switch to a different document, use replaceDocument(markdown, documentId).

A complete serialized autosave adapter

This TypeScript module serializes writes for one document and reads snapshots only when saving. If source changes during a request, it saves the next version after completion. Failures retain dirty state; the next edit or explicit flush() retries. Responses never replace editor text.

recipes/autosave.tsts
ts

The host supplies /api/documents/:id. The adapter starts saving after the first source change; loading a document does not mark it dirty. A settled flush is not proof of success: status/error report failures, which require retained feedback and retry controls.

Server concurrency and offline use

Local revision is not a server version. Multiple clients need server ETags, versions or a collaboration protocol. Handle 409/412 with merge or conflict UI instead of retrying an overwrite indefinitely.

Offline storage belongs to the host and can retain exact Markdown plus server version. Do not display server-saved status before durable acknowledgement. Arbitrary asynchronous requests cannot be assumed to complete during beforeunload.

Replacement and external echoes

Resolve unsaved state, end the old save session, replace the document, then create a fresh session. The old document scope cancels in-flight resources.

For same-document external edits, applyChanges() offsets belong to the logical text at baseRevision. Success advances revision. Mark origins and suppress same-source echoes in host listeners. On stale-target, remap or merge; do not merely substitute the latest baseRevision while keeping old offsets.

File responsibilities

The editor receives decoded strings. Byte encoding, file BOM handling, names, access control, attachments and downloads belong to the application. Use getMarkdown() for serialized text and state.doc for editing offsets. Rendered HTML and component state are not recoverable Markdown archives.

MSFE · QuireKitYour Markdown source stays yours.