components
All repositories: gitoria
22.0 KB
// comments.hl — THE COMMENTS BLOCK (layouts#2; shape of hybriel's demo-social-network), pure Hybriel: "1 comment" / "n comments",// then every comment — an avatar (the initial), a bubble with the name, the time, "edited" (the earlier versions fold out) and the// text as formatted Markdown; under it a like (♥ and the count) and, for the comment's author, Edit / Delete — and the form below,// typed in the Markdown editor (components/md-editor). `Comments { comments = list user = me onPost = posted onEdit = edited// onDelete = deleted onLike = liked }`.// GENERIC: no app data, no storage. The host passes the comments (a list of records, below) and the current user's name, and// hands four functions (hybriel#87: a child talks upward by calling a function its host gives it); the host decides what is// stored and gives a new list back — the block shows what it is given. A comment record:// { id, author, when, text (Markdown), likes (a number), liked (true when `user` likes it), history ([{ when, text }], the// earlier versions, oldest first; empty = never edited) }// Edit / Delete show where `author == user`; with `user` empty there is no form and the like does nothing.// The text is drawn by MdEditor's own renderer (`readonly = "true"`). The editor builds its content in the browser once per element;// hl:web builds a composed child anew when a value bound into it changes, so a changed text (an edit here, or a new list from a push)// is drawn anew, and the rows are keyed by `id`, so a deleted comment takes its own editor with it.// The per-comment state (which one is being edited / asked to be deleted) is one member each: one block per page (a composed// component's members are the page's state).// ATTACHMENTS (mission 009, tickets#27): a comment record may carry `files` ([{ name, url, image (true = a picture), size (bytes) }]):// pictures show as thumbnails that open the full picture, any other file as a row (kind, name, size); a file without `url` (the// viewer may not fetch it) shows as a row without a link. `attach = "true"` puts the form inside the shared FilesUpload in pick mode// (components/files-upload/): files dropped, chosen, photographed or pasted (Ctrl+V, also into the editor: its files = "off") wait// as thumbnails / rows under the editor, and the host hears them with the text: `onPost(text, files)` (browser Files — the host sends// them with its own face; the framework uploads them first). Without `attach` nothing changes: `onPost(text)`.// A STATE CHANGE IN THE FORM'S FOOTER (tickets UX mission): `states = [{ value, label }]` (the host's choices, the current one left out) puts// `State [select]` in front of the post button, right side of the form's footer; the select starts on "no change". The button says what// happens: "Comment" (text or files, no state), "Set to <state>" (a state and nothing to say), "Comment and set to <state>" (both). The// host hears `onPost(text, files, state)` (state '' = unchanged; the third argument only comes when `states` is not empty).import MdEditor from '../md-editor/md-editor.hl'import FilesUpload from '../files-upload/files-upload.hl'Hybrid comments = []String user = ''onPost = nullonEdit = nullonDelete = nullonLike = nullString oneLabel = 'comment'String manyLabel = 'comments'String emptyText = 'No comments yet.'String placeholder = 'Write a comment…'String postLabel = 'Comment'String editLabel = 'Edit'String deleteLabel = 'Delete'String saveLabel = 'Save'String cancelLabel = 'Cancel'String askText = 'Delete this comment?'String keepLabel = 'Keep'String editedLabel = 'edited'String likeLabel = 'Like'String signInText = ''// attachments in the form (above): "true" turns them on; the size limit per file (bytes, 0 = none) and the chooser's `accept`String attach = 'false'Number maxFileSize = 0String accept = ''String attachText = 'Drop or paste files here, or'String chooseText = 'Choose files'String cameraText = 'Camera'String filesLabel = 'Attachments'// the state choice in the footer (`states` empty = none): its label, the first choice, and what the button says with a state chosenHybrid states = []String stateLabel = 'State'String keepText = 'no change'String stateOnlyLabel = 'Set to'String bothLabel = 'Comment and set to'String editingId = ''String askingId = ''Number formSeq = 0Hybrid shown = rowsOf(comments, user, editingId, askingId)String countText = countOf(comments)Boolean hasNone = comments.length == 0Boolean canWrite = user != ''Boolean cannotWrite = user == '' && signInText != ''Hybrid forms = [{ id = 'new-' + formSeq }]// the files waiting in the form (browser Files, the FilesUpload's list: this block is its host) — sent with the next postHybrid attached = []Boolean attaching = canWrite && attach == 'true'Boolean plainForm = canWrite && attach != 'true'picked = (list) => { attached = list }// the state select's choice ('' = no change) and whether the editor holds any text: they decide what the post button saysString chosen = ''Boolean typed = falseHybrid choices = choicesOf(states)Boolean stating = canWrite && states.length > 0String buttonText = buttonOf(typed, attached, chosen, states)// the select's choices: "no change" first, then the host's stateschoicesOf(list) {out = [{ value = '' label = keepText }]for (o of list) { out.push({ value = '' + o.value label = '' + o.label }) }return out}// what the post button says: "Comment", "Set to review" (only a state), "Comment and set to review" (text or files and a state)buttonOf(hasText, files, state, list) {if (state == '') { return postLabel }let name = statefor (o of list) { if ('' + o.value == state) { name = '' + o.label } }return ((hasText || files.length > 0) ? bothLabel : stateOnlyLabel) + ' ' + name}// "1 comment", "n comments"countOf(list) { return list.length == 1 ? '1 ' + oneLabel : list.length + ' ' + manyLabel }initialOf(name) {t = ('' + name).trim()return t == '' ? '?' : t.slice(0, 1).toUpperCase()}// "5 B", "1.2 KB", "3.4 MB" — whole numbers only (rounded to tenths by hand: the server side has no toFixed, hybriel#182)sizeTextOf(n) {if (n == null || n < 0) { return '' }if (n < 1024) { return n + ' B' }if (n < 1048576) { return tenthsOf(n, 1024) + ' KB' }return tenthsOf(n, 1048576) + ' MB'}tenthsOf(n, unit) {x = n * 20 + unitt = (x - x % (2 * unit)) / (2 * unit)return (t - t % 10) / 10 + '.' + t % 10}// "PNG", "PDF": the box a file row showskindOf(name) {t = '' + namedot = t.lastIndexOf('.')return dot > 0 && dot < t.length - 1 ? t.slice(dot + 1, dot + 5).toUpperCase() : 'FILE'}// what each attached file of a comment shows: a thumbnail (a picture the viewer may fetch), a linked row, or a plain row (no url)filesOf(list) {out = []if (list == null) { return out }for (f of list) {let url = f.url != null ? '' + f.url : ''let thumb = f.image == true && url != ''out.push({ name = f.name url = url size = sizeTextOf(f.size) kind = kindOf(f.name) thumb = thumb linked = !thumb && url != '' plain = url == '' })}return out}// what one comment shows: the host's record, and what this block works out for the user lookingrowsOf(list, me, editing, asking) {out = []for (c of list) {let mine = me != '' && c.author == melet past = c.history != null ? c.history : []let count = c.likes != null ? c.likes : 0let isEditing = mine && '' + c.id == editinglet isAsking = mine && '' + c.id == asking && !isEditinglet attachedFiles = filesOf(c.files)out.push({id = '' + c.idauthor = c.authorinitial = initialOf(c.author)when = c.when != null ? c.when : ''text = c.textlikes = countlikeText = (c.liked == true ? '♥ ' : '♡ ') + countpressed = c.liked == true ? 'true' : 'false'edited = past.length > 0history = pasteditedTitle = past.length == 1 ? 'Edited once' : 'Edited ' + past.length + ' times'mine = mineediting = isEditingnotEditing = !isEditingasking = isAskingoffering = mine && !isEditing && !isAskingfiles = attachedFileshasFiles = attachedFiles.length > 0})}return out}View {commentsBlock {h2 { class = "comments-count" countText }if (hasNone) { p { class = "comments-empty" emptyText } }ol { class = "comment-list"for (c of shown) {li { class = "comment" 'data-id' = c.idcommentAvatar { 'aria-hidden' = "true" c.initial }commentMain {commentBubble {commentMeta {strong { class = "comment-author" c.author }time { c.when }if (c.edited) { details { class = "comment-history"summary { editedLabel }p { class = "comment-history-title" c.editedTitle }ol { for (h of c.history) { li { time { h.when } pre { h.text } } } }} }}if (c.notEditing) { MdEditor { name = "comment-text" value = c.text readonly = "true" } }if (c.editing) { form { class = "comment-edit" 'data-id' = c.id on submit(e) { emit commentsSave(e) }MdEditor { name = "comment-edit" value = c.text }commentButtons {button { type = "button" class = "comment-cancel" cancelLabel on click(e) { emit commentsCancel(e) } }button { type = "submit" class = "comment-save" saveLabel }}} }if (c.hasFiles) { ul { class = "comment-files" 'aria-label' = filesLabelfor (f of c.files) { li {if (f.thumb) { a { class = "comment-thumb" href = f.url target = "_blank" rel = "noopener" title = f.nameimg { src = f.url alt = f.name loading = "lazy" }} }if (f.linked) { a { class = "comment-file" href = f.url target = "_blank" rel = "noopener"span { class = "kind" 'aria-hidden' = "true" f.kind }fileInfo { strong { class = "name" f.name } span { class = "size" f.size } }} }if (f.plain) { span { class = "comment-file"span { class = "kind" 'aria-hidden' = "true" f.kind }fileInfo { strong { class = "name" f.name } span { class = "size" f.size } }} }} }} }}commentActions {button { type = "button" class = "comment-like" 'data-id' = c.id 'aria-pressed' = c.pressed title = likeLabel c.likeText on click(e) { emit commentsLike(e) } }if (c.offering) {button { type = "button" class = "comment-edit-start" 'data-id' = c.id editLabel on click(e) { emit commentsEdit(e) } }button { type = "button" class = "comment-delete" 'data-id' = c.id deleteLabel on click(e) { emit commentsAsk(e) } }}if (c.asking) { commentAsk {span { askText }button { type = "button" class = "comment-delete-yes" 'data-id' = c.id deleteLabel on click(e) { emit commentsDelete(e) } }button { type = "button" class = "comment-delete-keep" keepLabel on click(e) { emit commentsKeep(e) } }} }}}}}}if (plainForm) { for (f of forms) { form { class = "comment-form" on submit(e) { emit commentsPost(e) } on input(e) { emit commentsTyping(e) }MdEditor { name = "comment-new" value = "" placeholder = placeholder rows = 3 }commentButtons {if (stating) { label { class = "comment-state" stateLabel select { name = "state" value = chosen on change(e) { emit commentsState(e) } for (o of choices) { option { value = o.value o.label } } } } }button { type = "submit" class = "comment-post" buttonText }}} } }if (attaching) { FilesUpload { mode = "pick" files = attached onChange = picked maxSize = maxFileSize accept = accept pickText = attachText chooseText = chooseText cameraText = cameraTextfor (f of forms) { form { class = "comment-form" on submit(e) { emit commentsPost(e) } on input(e) { emit commentsTyping(e) }MdEditor { name = "comment-new" value = "" placeholder = placeholder rows = 3 files = "off" }commentButtons {if (stating) { label { class = "comment-state" stateLabel select { name = "state" value = chosen on change(e) { emit commentsState(e) } for (o of choices) { option { value = o.value o.label } } } } }button { type = "submit" class = "comment-post" buttonText }}} }} }if (cannotWrite) { p { class = "comments-sign-in" signInText } }}}idOf(e) {el = e.target.closest('[data-id]')return el == null ? '' : el.getAttribute('data-id')}// the Markdown the editor of a form holds now (its hidden field, kept up to date by every keystroke)typedIn(form) {f = form.querySelector('md-editor input.value')return f == null ? '' : f.value}// post: the host is told the text (and, with attach, the waiting files: a post may be files only); answering false keeps text and// files in the form (e.g. the server refused), else the form starts emptyon commentsPost(e) {e.preventDefault()text = typedIn(e.target)if (onPost == null) { return null }if (attach == 'true') {if (text.trim() == '' && attached.length == 0 && chosen == '') { return null }sent = states.length > 0 ? onPost(text, attached, chosen) : onPost(text, attached)if (sent != false) {attached = []chosen = ''typed = falseformSeq = formSeq + 1}return null}if (text.trim() == '' && chosen == '') { return null }ok = states.length > 0 ? onPost(text, [], chosen) : onPost(text)if (ok != false) {chosen = ''typed = falseformSeq = formSeq + 1}}// every keystroke in a form's editor: is there any text (the button's words change with it)on commentsTyping(e) {form = e.target.closest('form')if (form == null) { return null }typed = typedIn(form).trim() != ''}on commentsState(e) { chosen = e.target.value }on commentsEdit(e) {askingId = ''editingId = idOf(e)}on commentsCancel(e) { editingId = '' }on commentsSave(e) {e.preventDefault()id = idOf(e)text = typedIn(e.target)let old = ''for (c of comments) { if ('' + c.id == id) { old = c.text } }if (text.trim() != '' && text != old && onEdit != null) { onEdit(id, text) }editingId = ''}on commentsAsk(e) {editingId = ''askingId = idOf(e)}on commentsKeep(e) { askingId = '' }on commentsDelete(e) {id = idOf(e)askingId = ''if (onDelete != null) { onDelete(id) }}on commentsLike(e) {if (user == '' || onLike == null) { return null }onLike(idOf(e))}// ---- look: the component's own Style; the base look is black, white and the greys #555 #999 #ddd #f2f2f2 (shared/base.hl names them;// root README "Look"); every colour is a semantic token with its base value as fallback, so an app that declares the tokens// (layouts.worldapi.org's theme) restyles it. No frames: the bubble is a grey field on the page, the avatar a grey disc.Style {'comments-block' { display = 'block' color = 'var(--color-text, #000)' }'comments-block h2.comments-count' { margin = '0 0 .8rem' fontSize = '1.05rem' }'comments-block .comments-empty, comments-block .comments-sign-in' { margin = '0 0 .8rem' color = 'var(--color-text-muted, #555)' }'comments-block ol.comment-list' { display = 'flex' flexDirection = 'column' gap = '.9rem' margin = '0 0 1rem' padding = '0' listStyle = 'none' }'comments-block li.comment' { display = 'flex' gap = '.6rem' alignItems = 'flex-start' }'comments-block comment-avatar' { flex = 'none' display = 'grid' placeItems = 'center' width = '2.2rem' height = '2.2rem' borderRadius = '50%' fontWeight = '700' color = 'var(--color-text, #000)' background = 'var(--color-surface, #ddd)' }'comments-block comment-main' { display = 'block' flex = '1' minWidth = '0' }'comments-block comment-bubble' { display = 'block' padding = '.5rem .8rem .6rem' background = 'var(--color-background-sunken, #f2f2f2)' borderRadius = 'var(--radius-small, 5px) var(--radius-large, 10px) var(--radius-large, 10px) var(--radius-large, 10px)' }'comments-block comment-meta' { display = 'flex' flexWrap = 'wrap' alignItems = 'baseline' gap = '.2rem .6rem' marginBottom = '.2rem' }'comments-block .comment-author' { fontSize = '.95rem' color = 'var(--color-text-strong, #000)' overflowWrap = 'anywhere' }'comments-block comment-meta time' { fontSize = '.8rem' color = 'var(--color-text-muted, #555)' }// "edited": a quiet label next to the time (the foldable's own frame, grey header and margins of an app theme are switched off: the// theme styles every details/summary as a framed foldable, which is wrong for a history note); open, the earlier versions run in// under the line, muted, no frame'comments-block details.comment-history' { display = 'contents' margin = '0' padding = '0' border = '0' borderRadius = '0' background = 'transparent' }'comments-block details.comment-history::details-content' { display = 'contents' }'comments-block details.comment-history summary' { display = 'inline' minHeight = '0' border = '0' background = 'transparent' fontSize = '.8rem' fontWeight = '400' color = 'var(--color-text-muted, #555)' cursor = 'pointer' textDecoration = 'underline dotted' textUnderlineOffset = '.15em' padding = '.85rem .5rem' margin = '-.85rem -.5rem' }'comments-block details.comment-history summary:hover' { background = 'transparent' color = 'var(--color-text, #000)' }'comments-block details.comment-history summary:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '2px' }'comments-block details.comment-history > :not(summary)' { flexBasis = '100%' margin = '0' fontSize = '.8rem' color = 'var(--color-text-muted, #555)' }'comments-block .comment-history-title' { margin = '.2rem 0 0' fontWeight = '600' }'comments-block details.comment-history ol' { padding = '0' listStyle = 'none' }'comments-block details.comment-history li' { display = 'block' margin = '.2rem 0 0' }'comments-block details.comment-history pre' { margin = '0' padding = '0' fontFamily = 'inherit' fontSize = '.85rem' whiteSpace = 'pre-wrap' overflowWrap = 'anywhere' color = 'var(--color-text-muted, #555)' background = 'transparent' }'comments-block comment-actions' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.1rem .3rem' marginTop = '-.375rem' fontSize = '.85rem' }'comments-block button' { font = 'inherit' fontWeight = '600' minHeight = '2.75rem' minWidth = '2.75rem' padding = '.25rem .6rem' color = 'var(--color-text-muted, #555)' background = 'transparent' border = '0' borderRadius = 'var(--radius-small, 5px)' cursor = 'pointer' }'comments-block button:hover' { color = 'var(--color-text, #000)' background = 'var(--color-surface, #f2f2f2)' }'comments-block button:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '1px' }'comments-block button.comment-like[aria-pressed="true"]' { color = 'var(--color-text-strong, #000)' }'comments-block comment-ask' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.3rem' }'comments-block button.comment-delete-yes, comments-block button.comment-save, comments-block button.comment-post' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' }'comments-block button.comment-delete-yes:hover, comments-block button.comment-save:hover, comments-block button.comment-post:hover' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' filter = 'brightness(1.3)' }'comments-block form.comment-edit' { display = 'block' marginTop = '.3rem' }'comments-block form.comment-edit md-editor' { background = 'var(--color-background, #fff)' }'comments-block form.comment-form' { display = 'block' }'comments-block comment-buttons' { display = 'flex' flexWrap = 'wrap' justifyContent = 'flex-end' alignItems = 'center' gap = '.4rem' marginTop = '.4rem' }// the state choice before the post button: a small label and a select, the label does not take the page's block margins'comments-block label.comment-state' { display = 'inline-flex' alignItems = 'center' gap = '.5rem' margin = '0' fontSize = '.9rem' fontWeight = '400' color = 'var(--color-text-muted, #555)' }'comments-block label.comment-state select' { background = 'var(--color-surface, #ddd)' color = 'var(--color-text, #000)' }'comments-block button.comment-post' { minHeight = '2.75rem' minWidth = '2.75rem' padding = '.25rem 1rem' }// attachments: thumbnails in a wrapping row (each a 44 px+ target that opens the picture), file rows under them; no frames'comments-block ul.comment-files' { display = 'flex' flexWrap = 'wrap' gap = '.4rem' margin = '.4rem 0 .1rem' padding = '0' listStyle = 'none' }'comments-block ul.comment-files li' { display = 'block' minWidth = '0' maxWidth = '100%' }'comments-block a.comment-thumb' { display = 'block' width = '6rem' height = '6rem' borderRadius = 'var(--radius-small, 5px)' overflow = 'hidden' background = 'var(--color-surface, #ddd)' }'comments-block a.comment-thumb img' { display = 'block' width = '100%' height = '100%' objectFit = 'cover' }'comments-block a.comment-thumb:focus-visible, comments-block a.comment-file:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '1px' }'comments-block .comment-file' { display = 'flex' alignItems = 'center' gap = '.5rem' minHeight = '2.75rem' padding = '.2rem .6rem .2rem .2rem' boxSizing = 'border-box' maxWidth = '100%' color = 'var(--color-text, #000)' textDecoration = 'none' background = 'var(--color-background, #fff)' borderRadius = 'var(--radius-small, 5px)' }'comments-block a.comment-file:hover' { background = 'var(--color-surface, #f2f2f2)' }'comments-block .comment-file .kind' { flex = 'none' display = 'grid' placeItems = 'center' width = '2.4rem' height = '2.4rem' fontSize = '.7rem' fontWeight = '700' color = 'var(--color-text-muted, #555)' background = 'var(--color-surface, #ddd)' borderRadius = 'var(--radius-small, 5px)' }'comments-block .comment-file file-info' { display = 'flex' flexDirection = 'column' minWidth = '0' }'comments-block .comment-file .name' { fontSize = '.9rem' overflowWrap = 'anywhere' }'comments-block .comment-file .size' { fontSize = '.8rem' color = 'var(--color-text-muted, #555)' }// inside the upload box the form dissolves into it (the box is the composer: the editor, the files, the footer)'comments-block files-upload form.comment-form' { display = 'contents' }}
Branches
Latest commits
- ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
- 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
- 9e1ab228MP: report, LOG line, STATUS entrymre
- dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
- e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
- 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
- 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
- 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre
- 0a9216fbMdEditor: a Table button in the toolbar, a typed pipe row fills the cells, tables take the page theme's look; gate checks updated for 12 toolbar buttonsmre
- f9d405c8comments: reactions row half as far from its comment (creator 2026-10-24: 'half this distance please'); the 44 px tap targets staymre
- 4922f9cfsessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0355975areports/MC-mobile.md, LOG, STATUS (MC)mre
- 3f0a7229Month view, date picker, range picker: names follow the page language (English by default, not the browser's), weekday/month names formatted in UTC (a UTC+12 zone showed Tue first), 44 px day cells and buttons, Send row air; gate checks at 390 px for every page, popup and dialog (MC)mre
- 29eb07eaPhone: 44 px targets on the site (brand, home links, buttons), comments, modal and pagination; the header is the brand alone on a phone; comments demo: labelled 'You are' group with the chosen user pressed (MC)mre
- d1cc83e2reports/E2-toolbar.mdmre
- 214c3183MdEditor on a phone: toolbar as two even rows of 44 px targets (no clipped icon, no swipe), 'Markdown source' label 15 px, table head 16 px; gate checks (E2)mre
- 9215bbaareports/F5-empty.mdmre
- 134b4e3eMdEditor: an editor the framework puts into the page is built at once (page observer), a surface put in anew under a built editor is redrawn; gates for both (hybriel#211)mre
- 0dce2899reports/K1-bubble.mdmre
- 6b0936a0comments: 'edited' foldable also drops the theme's border, margin and radius (display: contents alone left them computed)mre