Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Comments and Reactions

How the comment thread, the comment form and the reaction bar fit together, and the events your code handles to save what readers write.

Display here, storage with you

Three components cover reader response. None of them saves anything. Each one shows state you give it and fires an event when the reader does something. Your code sends that to a server and tells the component the result.

ComponentShowsYou write
<comment-thread> A list of comments with author, time, nesting, and Reply, Edit and Delete actions One <article data-comment> per comment
<comment-box> A Markdown editor with a preview and Submit and Cancel buttons Nothing, or a wrapping <form>
<reaction-bar> Emoji chips with counts, and a button that opens a palette of reactions to add One <button> per reaction and a <template> for the palette

The demo uses a mock server: a short delay, then the component is told the action succeeded. Reply to a comment, add a reaction and watch the event log underneath.

A thread

Render each comment as an <article data-comment> with an id. Its attributes carry the facts and a child marked data-comment-body carries the text. The component adds the header, a relative time and the action buttons around what you wrote.

Attribute on the commentEffect
data-author, data-author-href, data-author-avatarThe name, an optional profile link and an optional avatar
data-timeAn ISO 8601 time, shown as a relative time in the page's language
data-parentThe id of the comment this one replies to. Replies are indented under it.
data-mineThe current reader wrote it. Edit and Delete appear.
data-editedA time of last edit. An edited mark appears.

data-disabled on the thread removes every action, for a closed discussion.

Handling the actions

The thread fires three events. For a reply, pass the promise of your save to waitUntil(). The form shows as busy until it settles, closes when it resolves and keeps the reader's text when it rejects.

comment-thread:edit-request carries the comment's id and current text. Show an editor of your choice, then call updateComment(id, { bodyText, edited }).

addComment() and updateComment() take the text as bodyText, which is inserted as plain text, or as bodyHtml, which goes through the library's sanitizer first. Use bodyText unless your server has already turned the reader's Markdown into HTML.

The comment form

<comment-box> is the form for a new top-level comment, and the thread clones it from the <template data-reply-form> for replies. It is a form control: give it a name inside a <form> and its text is submitted with the form, with required, data-min-length and data-max-length as its validation.

Used alone, listen for comment-box:submit. It follows the same rule as a reply: do nothing and the box clears, call waitUntil(promise) to hold it busy until your save settles, or call preventDefault() to keep the text.

Reactions

Write a <button> for each reaction that already has a count, and a <template data-palette> listing every reaction a reader may add. data-reaction is the name your server knows it by. data-label gives the emoji a spoken name.

A click fires reaction-bar:toggle with the reaction, whether it is being added or removed, and the count and mine state from before the click. The chip then waits, ignoring further clicks, until you call setCount(). Call it with the new values when the save succeeds and with the old values when it fails.

A <reaction-bar> can sit inside a comment, as in the first demo, or under an article. data-disabled makes it read-only.

What is not here

  • Storage, accounts, moderation and spam control. Those are your server's job.
  • Comments pinned to a place in the text. <comment-wc> is an experimental stub for that. It needs the <review-surface> element from the separate vb-project-planning package, and without one its button is disabled.
  • Private notes for one reader. Those are Highlights and Annotations, and need no server.
↑