- ClayJS
- Reference
- Plugins
- unsent
unsent
Keeps text typed into editor chrome and not yet sent, outside the saved file, per record and per tab.
Keeps text a person typed into chrome and has not sent, so it outlives the view that held it. It loads by name: ask for unsent in the script tag’s plugin list.
What is kept#
An input or textarea inside clay="editor-ui" or clay="freeze" marked unsent="<name>" is kept per record (its nearest [data-id] ancestor, or the nearest ancestor’s unsent-key) and name in this tab, outside the file: reopening the detail, a sync redraw or a reload brings the text back, and the close warning stays on while any of it is kept. clay.unsent.list() says what is kept and clay.unsent.clear(input) drops one, for send and cancel; clay.unsent.size counts them and clay.unsent.drop(record, name) drops one by its record and name. A page’s Send or Discard calls clay.unsent.clear(input), which is what tells the exit that the draft is no longer pending. clay:unsent-changed fires on the document with {count} whenever one is kept or dropped, and clay:unsent-restored fires on the control with {base, current, stale}. Detail views: the record is the modal shows it with a card detail.
A draft for a record that does not exist yet#
A composer that will create the record has no record of its own to key on, so name the destination with unsent-key on the form that holds the field, and set it when the form mounts:
<form class="capture-form" clay="editor-ui" unsent-key="capture:l-ideas">
<label>Card title<textarea unsent="card" rows="2"></textarea></label>
<button type="submit">Add card</button>
</form>
clay.unsent.list() then reports record: "capture:l-ideas", which is a destination rather than a saved record. Keep the composer’s keys in their own namespace and recognize that prefix when deciding what to do with each draft: a draft whose list is gone is recoverable text with Copy text and Discard, not an insertion somewhere else.
Two rules keep a creating composer honest. Escape closes the form and leaves the text kept; only the exact revision that was sent is cleared, so text typed after the submit survives. And a blur during an IME composition adds nothing: compositionstart, compositionend and event.isComposing keep the draft, and the composition ending does not send it either.
The Kanban’s card and list composers are the reference implementation; the guide covers them in Detail views: the record is the modal and Commands.
Across a mode change#
unsent is a participant of the mode lifecycle, with the id clay:unsent and order 320. Switching without a reload describes how a participant is prepared, and Leaving edit how an exit refuses.
Its lease holds nothing: the drafts live outside the file and outside the edit session, so an exit tears down no buffer and every draft is still there, and still restored, after the page is back in view. Nothing is lost on exit.
A kept draft refuses the exit with pending-input and pending: ["unsent"]. Leaving edit with a half-written composer is then a choice the person makes: send it, discard it, or stay in edit. A draft that is sent or discarded is no longer pending, and the exit goes ahead.