gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6372b06d6372b06dTickets conductor: worker port slotmre6372b06d/components/files-upload/README.md

7.9 KB

  1. # File upload, several files
  2. A dashed drop zone with a "Choose files" button that takes several files at once. Every dropped or chosen file gets its own
  3. row — name, size, a progress bar and its state (Waiting, Uploading…, Uploaded, Failed) — and the line under the rows counts
  4. them: "3 of 3 uploaded". Files go one after the other in the order they came; files dropped while others are still uploading
  5. wait in their row and follow. A failed file does not stop the others. Live demo: https://components.hybriel.worldapi.org/files-upload
  6. **Two modes** (`mode`): **upload at once** (the default, `mode = "upload"`, all of the above) and **pick first, send later**
  7. (`mode = "pick"`, ticket #18, for chat attachments — HyperConductor hycon#46): dropped, chosen, pasted (Ctrl+V) or photographed
  8. files are only collected; the host sends them with its own message and empties the list. Live demo:
  9. https://components.hybriel.worldapi.org/files-upload/pick
  10. ## Files
  11. Copy the folder `components/files-upload/`: `files-upload.hl` is the component (both modes; it carries its own `Style`). `demo.hl`
  12. and `demo-pick.hl` are this site's demo pages, not needed in an app.
  13. ## Use it in an app
  14. Copy the folder `components/files-upload/` (`files-upload.hl`; it carries its own `Style`, colours are semantic tokens with a
  15. black/white/grey fallback, the one border is the drop zone's dashed one), compose it, and write the face that stores a file:
  16. ```
  17. import FilesUpload from './files-upload.hl'
  18. View { FilesUpload { } }
  19. on server uploadFile(file) {
  20. // file.name, file.type, file.size, file.bytes — store it where you want (called once per file)
  21. writeFile('storage/uploads/' + name, file.bytes)
  22. return { ok = true }
  23. }
  24. ```
  25. - The component sends each file with `emit server uploadFile(file)`; the framework carries it over HTTP in 1 MiB parts with
  26. progress (hybriel#94). Pure Hybriel: no `.js`, no network calls of its own.
  27. - The face decides where the file goes and how big it may be (`uploadMax` of the WebFramework; this site: 5 MiB). Answer anything
  28. but `null` when it is stored; `null`, an error or a file over `uploadMax` shows "Failed" in that row.
  29. - Face names are global to the app (`uploadFile`; the one-file upload uses `saveFile`): one face per app for each.
  30. - `dropText`, `chooseText` are the texts. One component per page (composed members are the page's state).
  31. - Progress comes from `on client uploadProgress`, shown by the component itself in the row being sent.
  32. - A **Ctrl+V** of files (a screenshot, a copied image or file) on the focused drop zone uploads them like a drop. A text paste does nothing.
  33. - `maxSize` (bytes, default 0 = none): a bigger file gets its row with "Too big — at most 2.0 MB" and is not sent (the app's
  34. `uploadMax` still holds for the rest).
  35. ## Pick first, send later (`mode = "pick"`)
  36. Files are **collected, not sent**: an image shows as a thumbnail, any other file as a row with its kind ("PDF"), name and size,
  37. each with a **✕** that takes it away. A line under them says "3 files · 1.2 MB". **The host owns the list** — the pattern of the
  38. Comments block (hybriel#87): it binds its list into `files`, hears every change through the function `onChange`, and at its Send
  39. passes the list to its own face and empties it. **Its input area goes inside the component** (the slot), and everything is
  40. **one box**: the host's field on top, the picked files right under it, and a footer with the small "Choose files" (and, on a touch
  41. screen, "Camera") button at the left and the host's own buttons — its Send — at the right end. A drop or a paste (Ctrl+V)
  42. anywhere in the box is caught, while text pastes and text drags stay in the field. The host's `<form>` dissolves into the box
  43. (`display: contents`): its first field (a `textarea` or an `md-editor`) is the top row, every other direct child of the form
  44. (a button, a button group) goes to the right end of the footer.
  45. ### Full host example: a chat input (text + attachments + Send)
  46. ```
  47. import FilesUpload from './files-upload/files-upload.hl'
  48. Hybrid attached = [] // the collected files (browser Files), owned by this page
  49. Hybrid messages = []
  50. picked = (list) => { attached = list } // the component tells every change: a pick, a paste, a ✕
  51. View {
  52. chat {
  53. ol { for (m of messages) { li { m.text } } }
  54. FilesUpload { mode = "pick" files = attached onChange = picked maxSize = 10485760 accept = "image/*,.pdf,.txt,.md"
  55. form { on submit(e) { emit chatSubmit(e) }
  56. textarea { name = "text" placeholder = "Write a message…" }
  57. button { type = "submit" "Send" }
  58. }
  59. }
  60. }
  61. }
  62. on chatSubmit(e) {
  63. e.preventDefault()
  64. form = e.target
  65. text = form.querySelector('textarea').value
  66. if (text.trim() == '' && attached.length == 0) { return null }
  67. message = emit server chatSend(text, attached) // the framework uploads every file first (hybriel#94), then the face runs
  68. if (message == null) { return null } // refused (e.g. a file over uploadMax): the files stay, the user can retry
  69. messages.push(message)
  70. attached = [] // clears the component's rows
  71. form.reset()
  72. }
  73. on server chatSend(text, files) {
  74. // files: a list of { name, type, size, bytes } in the order shown; store them where you want
  75. for (f of files) { writeFile('storage/attachments/' + safeName(f.name), f.bytes) }
  76. return { text = text files = files.length }
  77. }
  78. ```
  79. ### Interface
  80. | Member | Meaning |
  81. |---|---|
  82. | `mode` | `"pick"` (default `"upload"`) |
  83. | `files` | **in**: the host's list of browser `File`s, shown in this order (bind the host's member; `[]` = no rows) |
  84. | `onChange(list)` | **out**: called with the NEW list after every drop, choose, paste, photo and ✕; the host stores it (`attached = list`) — without it nothing is collected |
  85. | `maxSize` | bytes, 0 = none: a bigger file gets a row "Too big — at most …" with its own ✕, and is not handed to the host |
  86. | `accept` | the "Choose files" input's `accept` (default all files) |
  87. | texts | `pickText` (the tooltip of "Choose files"), `chooseText` ("Choose files"), `cameraText` ("Camera"), `removeText` ("Remove", the ✕'s label: "Remove photo.png"), `tooBigText` ("Too big — at most") |
  88. - **Send** = the host's own face with the list as an argument: `emit server chatSend(text, attached)`. A list of Files in an emit is
  89. uploaded by the framework in 1 MiB parts before the face runs; the face gets `{ name, type, size, bytes }` for each. **Clear** =
  90. `attached = []`. Nothing is sent by the component itself; it never calls a face in this mode.
  91. - The refused rows belong to the last pick: a new pick replaces them, their ✕ dismisses one, and they go when the host empties a
  92. list that had files (after its Send).
  93. - **Phone:** "Choose files" offers the phone's own choice (gallery, camera, files); on a touch screen (`pointer: coarse`) a
  94. **Camera** button (`accept="image/*" capture="environment"`) opens the camera straight away. Every button is 44 × 44 px or more.
  95. - Thumbnails are object URLs of the Files (pure Hybriel: `window.URL.createObjectURL`), given back (`revokeObjectURL`) once drawn.
  96. ## Markup and states
  97. `<files-upload>` holds `<drop-zone>` (class `over` while files are dragged over; the hidden `<input type="file" multiple>` in
  98. `label.choose`), `<ul class="files">` with one `<li>` per file (`strong.name`, `span.size`, `<progress>`, `<output class="state">`;
  99. class `waiting`, `busy`, `done` or `failed`) and `<output class="summary">`. Class `busy` on `<files-upload>` while it sends.
  100. Pick mode: `<files-upload>` > `<pick-area>` (class `over` on `<files-upload>` while files are dragged over it) with
  101. `<ul class="files picked">` — `li.picked[data-i]` (`img.thumb` or `span.kind`, `<file-info>` with `strong.name` + `span.size`,
  102. `button.remove`) and `li.refused` (`span.kind` "!", `<file-info>` with `strong.name`, `span.size`, `output.state`, `button.remove`) —,
  103. `<output class="summary">`, the host's content (first, in the DOM), and the footer's `label.choose` and `label.camera` (each holding its hidden input; there is no drop zone in pick mode — the whole box takes the drop).

Branches

Latest commits

  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre