gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit99db79f099db79f0re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre99db79f0/components/comments/README.md

6.4 KB

  1. # Comments
  2. A comment thread (layouts#2; shape of hybriel's demo-social-network): **"1 comment" / "n comments"**, then every comment — an
  3. avatar (the initial of the name), a bubble with the **name**, the **time**, **"edited"** (the earlier versions fold out) and the
  4. **text as formatted Markdown**; under it a **like** (♥ and the count) and, for the comment's author, **Edit / Delete** (Delete asks
  5. first) — and the **form below**, typed in the Markdown editor. Live demo: https://components.hybriel.worldapi.org/comments
  6. ## Files
  7. Copy `components/comments/` (`comments.hl`) **and** `components/md-editor/` (`md-editor.hl`, mission 006 or later — it needs its
  8. `readonly` attribute): `comments.hl` imports `../md-editor/md-editor.hl`. Both carry their own `Style`; every colour is a semantic
  9. token with a black/white/grey fallback (root README "Look").
  10. ## Use it in an app
  11. The block is generic: no app data, no storage. **The host passes the comments and the current user, hears what the user did through
  12. four functions it hands (hybriel#87), decides what is stored, and gives a new list back** — the block shows the list it is given.
  13. ```
  14. import Comments from './comments/comments.hl'
  15. Hybrid thread = commentsOf(ticketId, me) // the app's own records, in the shape below
  16. String me = session != null ? session.user.name : ''
  17. posted = (text) => { thread = emit server commentPost(ticketId, text) } // the face stores it and answers the new list
  18. edited = (id, text) => { thread = emit server commentEdit(ticketId, id, text) }
  19. deleted = (id) => { thread = emit server commentDelete(ticketId, id) }
  20. liked = (id) => { thread = emit server commentLike(ticketId, id) }
  21. View { Comments { comments = thread user = me onPost = posted onEdit = edited onDelete = deleted onLike = liked } }
  22. ```
  23. ### Data in
  24. | Member | Meaning |
  25. |---|---|
  26. | `comments` | the list, oldest first: `{ id, author, when, text, likes, liked, history }` (below) |
  27. | `user` | the current user's name (compared with `author`); `''` = nobody: no form, no Edit / Delete, the like does nothing |
  28. A comment: `id` (any text or number, unique in the list — the rows are keyed by it), `author` (the name shown, and who may edit),
  29. `when` (the time as the app writes it, e.g. "Oct 17, 09:12"), `text` (Markdown), `likes` (a number), `liked` (`true` when `user`
  30. likes it), `history` (the earlier versions, oldest first: `[{ when, text }]`; empty or missing = never edited). The app checks
  31. the rights again on the server — the block only hides what the user may not do.
  32. ### Data out — the four functions
  33. | Function | Called when | With |
  34. |---|---|---|
  35. | `onPost(text)` | the form is sent (the Comment button, or Ctrl+Enter in the editor); empty text sends nothing | the Markdown typed |
  36. | `onEdit(id, text)` | Save of an edit with a changed, non-empty text | the comment's id, the new Markdown |
  37. | `onDelete(id)` | Delete, then Delete again in "Delete this comment?" (Keep takes it back) | the comment's id |
  38. | `onLike(id)` | the like is pressed (only with a `user`) | the comment's id — the host switches `liked` and the count |
  39. With `attach = "true"` (below) it is `onPost(text, files)`: `files` are the browser Files waiting in the form (a post may be files only).
  40. `onPost` may answer `false` to keep the text in the editor (e.g. the server refused it); anything else empties the form. Edit / Delete
  41. show only where `author == user`.
  42. ### Attachments (`attach = "true"`, optional)
  43. Without `attach` nothing changes (`onPost(text)`, no files). With it the form sits inside the shared FilesUpload (pick mode, imported
  44. from `../files-upload/files-upload.hl` — copy that folder too): choose / camera / drop / paste files, they wait as thumbnails, and
  45. `onPost(text, files)` gets the text and the browser Files; the host stores them. Answering `false` keeps text and files. Members:
  46. `maxFileSize` (bytes per file), `accept`, `attachText`, `chooseText`, `cameraText`, `filesLabel`. The editor in the form has
  47. `files = "off"` (no File button; pasted / dropped files go to the FilesUpload).
  48. **Files per comment:** a comment record may carry `files: [{ name, url, image, size }]`. Pictures (`image`) show as 6 rem thumbnails
  49. (`a.comment-thumb`, opens the full picture in a new tab); other files are rows (`a.comment-file`: kind, name, size). A file without
  50. `url` shows as a row without link (`span.comment-file`) — e.g. for users who may not fetch it. Sizes are written by integer maths.
  51. ### Texts
  52. `oneLabel` ("comment"), `manyLabel` ("comments"), `emptyText` ("No comments yet."), `placeholder` ("Write a comment…"), `postLabel`
  53. ("Comment"), `editLabel`, `deleteLabel`, `saveLabel`, `cancelLabel`, `askText` ("Delete this comment?"), `keepLabel`, `editedLabel`
  54. ("edited"), `likeLabel` (the like's title), `signInText` (shown instead of the form when there is no user; empty = nothing).
  55. ## How it is built
  56. - Every text is drawn by MdEditor's own renderer: `MdEditor { value = text readonly = "true" }` — the same Markdown subset the form
  57. makes, so a comment looks as it was typed. MdEditor builds its content in the browser once per element; hl:web builds a composed
  58. child anew when a value bound into it changes, so a changed text — an edit here, or a new list the host got from a push — is drawn
  59. anew (gate: "bob edits his comment elsewhere"), and a deleted comment takes its row with it (the rows are keyed by `id`).
  60. - The text is drawn in the browser: the server's HTML carries each comment's Markdown in the editor's hidden field, not formatted.
  61. - The form is an MdEditor in a one-row list too: after a post its key changes and an empty editor takes its place.
  62. - Which comment is being edited / asked about is one member each (`editingId`, `askingId`): **one block per page** (a composed
  63. component's members are the page's state).
  64. - "edited" is a `<details>` with the earlier versions as their Markdown source (oldest first, "Edited once" / "Edited n times").
  65. - Pure Hybriel: no `.js`, no network calls of its own.
  66. ## Markup
  67. `<comments-block>`: `h2.comments-count`, `p.comments-empty`, `ol.comment-list` > `li.comment[data-id]` > `<comment-avatar>` +
  68. `<comment-main>` (`<comment-bubble>` with `<comment-meta>` — `strong.comment-author`, `time`, `details.comment-history` — and the
  69. text `md-editor[data-readonly="true"]` or `form.comment-edit`; `<comment-actions>` with `button.comment-like[aria-pressed]`,
  70. `button.comment-edit-start`, `button.comment-delete`, `<comment-ask>`), then `form.comment-form` (MdEditor + `button.comment-post`)
  71. or `p.comments-sign-in`.

Branches

Latest commits

  • 99db79f0re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • 30353f60tests: e2e-md-showcase Chrome range from LAYOUTS_GATE_CHROME_MD, default unchangedmre
  • 16a7878cre-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 6af559e8docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 5599cf56deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • 0bcc6294Mission 011: e2e-197, brief, report, LOGmre
  • 137303c5MainMenu marks the current page from the route (hybriel#197, server-rendered); current prop/item.current stay as fallback; tracker demo drops current; gate: SSR marker; docsmre
  • 9325b403Re-vendor Hybriel to master 7f13a82f (hl:web batch 2: #190 #193 #197 #194 named regions); plugins whole, bin/hybriel static build (git-ignored)mre
  • b31dc74dusage: calendar (theme 76f99f6-era ContentFirst, user menu, ☰ menu) and tracker (theme 76f99f6, modal + pagination current, own current marker until hybriel#197) rowsmre
  • 8a3d5d40Mission 010: brief, report, LOG, STATUSmre
  • a56abf1fSync components to components.hybriel 3794c59 (MdEditor real-key fixes); showcase real-key check on the md-editor pagemre
  • 76f99f64E2E in lisbeth's Chrome for the menu's current page (mission 009): tests/e2e-menu-current.mjs, reportmre
  • 159b1d53MainMenu/Sidebar: current page marked beyond colour, count badge, item current flag; gate 300/0 (mission 009)mre
  • 0573eed3usage: notes + tickets on MdEditor (md-editor.js retired), gitoria on theme dbe3de7, tracker theme oldermre
  • 78478f6eSync showcase to components.hybriel 1442e58: pick-mode page, comments attach, md-editor rows/files off; gates 285/0mre
  • dbe3de79Display bugs from a real Chrome walk (mission 007): Settings page and in-shell doc reader instead of raw .md links, closed phone search hidden whatever a page says, /elements form rules scoped, three-pane danger contrast; display audit gate (132 -> 244 checks), walk + Settings e2e toolsmre
  • 1875a051Theme: 44 px tap targets mobile first (layoutTap), 16 px fields, desktop denser only in @media 60rem; 390 px tap audit + gate checks (mission 006)mre
  • 3d4f8e19Sync showcase to components.hybriel 9db927d: comments and files-upload pages, pagination onPage, md-editor readonly, gate 99 checksmre
  • 64d635acmission brief 005mre
  • 0d0fef25paths: projects moved into /media/STORAGE/projects/WorldAPI/mre