gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit15be2ac015be2ac0comments: attach (FilesUpload pick), onPost(text, files), files per comment; md-editor files=off; README, gate fixmre15be2ac0/components/files-upload/README.md

7.4 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): a paste (Ctrl+V) or a
  40. drop there is caught too, while text pastes and text drags stay in the field.
  41. ### Full host example: a chat input (text + attachments + Send)
  42. ```
  43. import FilesUpload from './files-upload/files-upload.hl'
  44. Hybrid attached = [] // the collected files (browser Files), owned by this page
  45. Hybrid messages = []
  46. picked = (list) => { attached = list } // the component tells every change: a pick, a paste, a ✕
  47. View {
  48. chat {
  49. ol { for (m of messages) { li { m.text } } }
  50. FilesUpload { mode = "pick" files = attached onChange = picked maxSize = 10485760 accept = "image/*,.pdf,.txt,.md"
  51. form { on submit(e) { emit chatSubmit(e) }
  52. textarea { name = "text" placeholder = "Write a message…" }
  53. button { type = "submit" "Send" }
  54. }
  55. }
  56. }
  57. }
  58. on chatSubmit(e) {
  59. e.preventDefault()
  60. form = e.target
  61. text = form.querySelector('textarea').value
  62. if (text.trim() == '' && attached.length == 0) { return null }
  63. message = emit server chatSend(text, attached) // the framework uploads every file first (hybriel#94), then the face runs
  64. if (message == null) { return null } // refused (e.g. a file over uploadMax): the files stay, the user can retry
  65. messages.push(message)
  66. attached = [] // clears the component's rows
  67. form.reset()
  68. }
  69. on server chatSend(text, files) {
  70. // files: a list of { name, type, size, bytes } in the order shown; store them where you want
  71. for (f of files) { writeFile('storage/attachments/' + safeName(f.name), f.bytes) }
  72. return { text = text files = files.length }
  73. }
  74. ```
  75. ### Interface
  76. | Member | Meaning |
  77. |---|---|
  78. | `mode` | `"pick"` (default `"upload"`) |
  79. | `files` | **in**: the host's list of browser `File`s, shown in this order (bind the host's member; `[]` = no rows) |
  80. | `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 |
  81. | `maxSize` | bytes, 0 = none: a bigger file gets a row "Too big — at most …" with its own ✕, and is not handed to the host |
  82. | `accept` | the "Choose files" input's `accept` (default all files) |
  83. | texts | `pickText` ("Drop or paste files here, or"), `chooseText` ("Choose files"), `cameraText` ("Camera"), `removeText` ("Remove", the ✕'s label: "Remove photo.png"), `tooBigText` ("Too big — at most") |
  84. - **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
  85. uploaded by the framework in 1 MiB parts before the face runs; the face gets `{ name, type, size, bytes }` for each. **Clear** =
  86. `attached = []`. Nothing is sent by the component itself; it never calls a face in this mode.
  87. - The refused rows belong to the last pick: a new pick replaces them, their ✕ dismisses one, and they go when the host empties a
  88. list that had files (after its Send).
  89. - **Phone:** "Choose files" offers the phone's own choice (gallery, camera, files); on a touch screen (`pointer: coarse`) a
  90. **Camera** button (`accept="image/*" capture="environment"`) opens the camera straight away. Every button is 44 × 44 px or more.
  91. - Thumbnails are object URLs of the Files (pure Hybriel: `window.URL.createObjectURL`), given back (`revokeObjectURL`) once drawn.
  92. ## Markup and states
  93. `<files-upload>` holds `<drop-zone>` (class `over` while files are dragged over; the hidden `<input type="file" multiple>` in
  94. `label.choose`), `<ul class="files">` with one `<li>` per file (`strong.name`, `span.size`, `<progress>`, `<output class="state">`;
  95. class `waiting`, `busy`, `done` or `failed`) and `<output class="summary">`. Class `busy` on `<files-upload>` while it sends.
  96. Pick mode: `<files-upload>` > `<pick-area>` (class `over` on `<files-upload>` while files are dragged over it) with
  97. `<ul class="files picked">` — `li.picked[data-i]` (`img.thumb` or `span.kind`, `<file-info>` with `strong.name` + `span.size`,
  98. `button.remove`) and `li.refused` (`span.kind` "!", `<file-info>` with `strong.name`, `span.size`, `output.state`, `button.remove`) —,
  99. `<output class="summary">`, the host's content, and `<drop-zone>` with `p`, `label.choose` and `label.camera` (each holding its hidden input).

Branches

Latest commits

  • 15be2ac0comments: attach (FilesUpload pick), onPost(text, files), files per comment; md-editor files=off; README, gate fixmre
  • 1f8d79d6comments (mission 009 WIP, tickets#27): attachments — attach="true" puts the form in FilesUpload pick mode, onPost(text, files), files per comment (thumbnails open full size, file rows, no url = no link); MdEditor files="off"; demo with attachments; gate m009 checks (WIP: 356/1)mre
  • 13389d67mission 008: report, LOG, STATUSmre
  • ab47e4a2files-upload (mission 008, #18 for hycon#46): pick-first-send-later mode — host-owned list (files + onChange), slot for the host's input area, Ctrl+V paste (both modes), thumbnails, name+size rows, ✕ remove, maxSize per file, Camera on touch screens, 44 px targets; demo /files-upload/pick; gate 343/0 (19 new, 18 fail on the old code)mre
  • 172e66bemission brief 008mre
  • 9db927dfpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 00a95329components (mission 007): re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ git-ignored), gate 324/0 old and new, real-data copy unchanged, report 007, same-output.mjs ports overridablemre
  • fe50766bmission brief 007mre
  • 2dce51b8components (mission 006) 4/4: docs (README comments + gate 324, STATUS, LOG), report reports/006-comments.mdmre
  • 9ec7273ecomponents layouts#2 (mission 006) 3/4: comments — each text is MdEditor readonly directly in its row (hl:web builds a composed child anew when a bound value changes, so the keyed one-row list was not needed); demo 'bob edits his comment elsewhere (a push)' + gate check that a text the host changes from outside is drawn anew; theme radii (var(--radius-small/large) with 5px/10px fallbacks: layouts' check-theme 0 problems with comments.hl copied in); README 'How it is built'; gate 324/0 (34 comments checks)mre
  • fd57c18bcomponents layouts#2 (mission 006) 2/3: comments block (components/comments, demo /comments) — pure Hybriel: '1 comment' / 'n comments', avatar initial, bubble with name, time, 'edited' (<details> with the earlier versions), the text drawn by MdEditor readonly (one-row list keyed by id + text, so an edit redraws), like ♥ n (aria-pressed), Edit / Delete (asks first) only where author == user, the form below in MdEditor (Comment button or Ctrl+Enter; a fresh editor after a post). Host passes comments + user and hands onPost / onEdit / onDelete / onLike (hybriel#87); demo keeps a mock thread from lib/comments.hl in the page, switches alice / bob / nobody. Home entry, routes, map line, README; base-look gate covers comments; 33 gate checks with real clicks / keysmre
  • 850a376bcomponents (mission 006) 1/3: MdEditor readonly = "true" — the Markdown shown formatted and nothing else (no toolbar, link form, file rows, placeholder, source view or switch; article contenteditable false, tabindex -1, role document; no field background or focus ring); the mount only loads the value. For the comments block, which draws every comment with the editor's own renderermre
  • ee9f1b57mission brief w6mre
  • fe691586components (mission 005) 4/4: docs (README components + gate 290, STATUS, LOG), report reports/005-fixes-16-17-5.mdmre
  • f1ebab53components #5 (mission 005) 3/4: file upload for several files (components/files-upload, demo /files-upload) — pure Hybriel, each file through emit server uploadFile (hybriel#94), drop or choose many, a row per file with live progress, one after the other in order, a drop during an upload waits, a file over uploadMax fails in its row and the next goes, 'n of m uploaded'; home entry, routes, map line, README; pagination keyboard focus ring #555 (Chrome painted its own orange one); docker-compose init: true (hybriel#156); gate 290/0 (17 #5 checks with real file drops, 1 #16 focus check)mre
  • 3b73ae5bcomponents #16 (mission 005) 2/4: Pagination tells the host the target page — the host hands onPage (hybriel#87: a function, not emit), called on every click that changes the page (pointer, Enter/Space, script click; Previous/Next/numbers/first/last; not … or the current page) with the target read from the clicked button's data-page before the rebuild; demo shows what the page was told; README Data out; 15 gate checks (14 fail on the old pagination)mre
  • 6b27c0f0components #17 (mission 005) 1/4: md-editor keeps backslash + r — parseInto dropped the two characters '\r' (C:\root -> C:oot) instead of a real carriage return; CR now decoded from JSON (String.fromCharCode does not parse in a member), real CRs also go from pasted plain text; 5 gate checks (3 fail on the old md-editor.hl)mre
  • 1a5dc327mission brief w5mre
  • a567b579components (mission 004) 3/3: docs (README Hybriel a832f73b + tables, STATUS, LOG), report reports/004-md-editor-tables.mdmre
  • 70fe7ab5components (mission 004) 2/3: GitHub pipe tables in the Hybriel MdEditor (creator notes#5; behaviour of notes md-editor.js 9acc27f, no JavaScript) — parse/render (header, :--/:-:/--: alignment, \| in cells and code, inline Markdown in cells, outer pipes optional), padded writer, unchanged table byte for byte, typing | a | b | Enter |---|---| Enter makes a table, Tab/Shift+Tab, Enter new row, Enter in empty last row leaves, Backspace/Delete never merge, selection across a table empties cells, pasted HTML table -> table, thin #999 lines, wide table scrolls in its box; demo third editor 'plan'; gate 252/0 (22 new table checks, 20 fail on the old md-editor.hl)mre