gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitdbe3de79dbe3de79Display 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 toolsmredbe3de79/components/files-upload/files-upload.hl

6.1 KB

  1. // files-upload.hl — THE FILE UPLOAD FOR SEVERAL FILES (ticket #5), pure Hybriel: a drop zone with a "Choose files" button (more than one
  2. // at a time). Every dropped or chosen file gets its own row — name, size, a progress bar, its state — and goes to the app through
  3. // `emit server uploadFile(file)` (the framework carries it over HTTP, in parts, with progress: hybriel#94), one file after the other in
  4. // the order they came; the app's `on server uploadFile(file)` decides where it is stored and answers anything but null when it took it
  5. // (an error or null = that file failed; the next one still goes). Files dropped during an upload wait in their row ("Waiting") and follow.
  6. // The line under the rows counts what is uploaded. USE ONE PER PAGE (a composed component's members are the page's state). The rows are
  7. // written by DOM calls in the handlers: an emit blocks its handler, and `on client uploadProgress` paints the bar of the row that is sent.
  8. String dropText = 'Drop files here or'
  9. String chooseText = 'Choose files'
  10. sizeText(n) {
  11. if (n < 1024) { return n + ' B' }
  12. if (n < 1048576) { return (n / 1024).toFixed(1) + ' KB' }
  13. return (n / 1048576).toFixed(1) + ' MB'
  14. }
  15. View {
  16. filesUpload {
  17. dropZone { on dragover(e) { emit filesOver(e) } on dragleave(e) { emit filesLeave(e) } on drop(e) { emit filesDrop(e) }
  18. p { dropText }
  19. label { class = "choose" chooseText input { type = "file" multiple = "multiple" on change(e) { emit filesChosen(e) } } }
  20. }
  21. ul { class = "files" 'aria-live' = "polite" }
  22. output { class = "summary" }
  23. }
  24. }
  25. rootOf(node) { return node.closest('files-upload') }
  26. on filesOver(e) {
  27. e.preventDefault()
  28. rootOf(e.target).classList.add('over')
  29. }
  30. on filesLeave(e) { rootOf(e.target).classList.remove('over') }
  31. on filesDrop(e) {
  32. e.preventDefault()
  33. root = rootOf(e.target)
  34. root.classList.remove('over')
  35. add(root, e.dataTransfer.files)
  36. }
  37. on filesChosen(e) {
  38. root = rootOf(e.target)
  39. input = e.target
  40. add(root, input.files)
  41. input.value = ''
  42. }
  43. // the bar of the row being sent (one at a time)
  44. on client uploadProgress(p) {
  45. for (row of document.querySelectorAll('files-upload li.busy')) {
  46. let bar = row.querySelector('progress')
  47. bar.max = p.size > 0 ? p.size : 1
  48. bar.value = p.sent
  49. }
  50. }
  51. // one row per file, waiting; then the queue runs (unless it already does)
  52. add(root, files) {
  53. list = root.querySelector('ul.files')
  54. for (f of files) {
  55. let li = document.createElement('li')
  56. li.className = 'waiting'
  57. let name = document.createElement('strong')
  58. name.className = 'name'
  59. name.textContent = f.name
  60. let size = document.createElement('span')
  61. size.className = 'size'
  62. size.textContent = sizeText(f.size)
  63. let bar = document.createElement('progress')
  64. bar.max = 100
  65. bar.value = 0
  66. let state = document.createElement('output')
  67. state.className = 'state'
  68. state.textContent = 'Waiting'
  69. li.appendChild(name)
  70. li.appendChild(size)
  71. li.appendChild(bar)
  72. li.appendChild(state)
  73. li.upload = f
  74. list.appendChild(li)
  75. }
  76. count(root)
  77. run(root)
  78. }
  79. // sends the waiting rows one after the other
  80. run(root) {
  81. if (root.classList.contains('busy')) { return null }
  82. root.classList.add('busy')
  83. let row = root.querySelector('li.waiting')
  84. while (row != null) {
  85. row.classList.remove('waiting')
  86. row.classList.add('busy')
  87. row.querySelector('.state').textContent = 'Uploading…'
  88. let saved = emit server uploadFile(row.upload)
  89. row.classList.remove('busy')
  90. row.upload = null
  91. let bar = row.querySelector('progress')
  92. if (saved == null) {
  93. row.classList.add('failed')
  94. row.querySelector('.state').textContent = 'Failed'
  95. } else {
  96. bar.max = 100
  97. bar.value = 100
  98. row.classList.add('done')
  99. row.querySelector('.state').textContent = 'Uploaded'
  100. }
  101. count(root)
  102. row = root.querySelector('li.waiting')
  103. }
  104. root.classList.remove('busy')
  105. }
  106. // "2 of 3 uploaded" (and how many failed)
  107. count(root) {
  108. all = root.querySelectorAll('ul.files li').length
  109. done = root.querySelectorAll('ul.files li.done').length
  110. failed = root.querySelectorAll('ul.files li.failed').length
  111. let text = all == 0 ? '' : done + ' of ' + all + ' uploaded'
  112. if (failed > 0) { text = text + ', ' + failed + ' failed' }
  113. root.querySelector('output.summary').textContent = text
  114. }
  115. // ---- look: the component's own Style, the same base look as the one-file upload (black, white, the greys #555 #999 #ddd #f2f2f2;
  116. // root README "Look"); every colour is a semantic token with its base value as fallback. No frames: the one border is the drop zone's
  117. // dashed one (it means "drop here"); rows are separated by space only
  118. Style {
  119. 'files-upload' { display = 'block' color = 'var(--color-text, #000)' }
  120. 'files-upload drop-zone' { display = 'block' padding = '1rem' textAlign = 'center' border = '2px dashed var(--color-border, #999)' borderRadius = '.5rem' }
  121. 'files-upload.over drop-zone' { borderColor = 'var(--color-accent, #000)' background = 'var(--color-surface, #f2f2f2)' }
  122. 'files-upload drop-zone p' { margin = '0 0 .5rem' color = 'var(--color-text-muted, #555)' }
  123. 'files-upload label.choose' { display = 'inline-block' padding = '.35rem .8rem' cursor = 'pointer' border = '0' borderRadius = '.35rem' background = 'var(--color-surface, #f2f2f2)' }
  124. 'files-upload label.choose:hover' { filter = 'brightness(.93)' }
  125. 'files-upload label.choose input' { display = 'none' }
  126. 'files-upload ul.files' { listStyle = 'none' margin = '.8rem 0 0' padding = '0' }
  127. 'files-upload ul.files li' { display = 'grid' gridTemplateColumns = '1fr auto' columnGap = '.6rem' marginBottom = '.7rem' }
  128. 'files-upload ul.files .name' { overflowWrap = 'anywhere' }
  129. 'files-upload ul.files .size' { color = 'var(--color-text-muted, #555)' textAlign = 'right' }
  130. 'files-upload ul.files progress' { gridColumn = '1 / -1' width = '100%' margin = '.3rem 0' accentColor = 'var(--color-accent, #000)' }
  131. 'files-upload ul.files .state' { gridColumn = '1 / -1' fontSize = '.9rem' color = 'var(--color-text-muted, #555)' }
  132. 'files-upload ul.files li.done .state' { color = 'var(--color-success, #000)' }
  133. 'files-upload ul.files li.failed .state' { color = 'var(--color-danger, #000)' fontWeight = '600' }
  134. 'files-upload output.summary' { display = 'block' marginTop = '.3rem' fontWeight = '600' }
  135. }

Branches

Latest commits

  • 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
  • 2dbe0df5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored), compose cache volume + tmpfs /tmp, gate wait 120 s, report 004mre
  • 0adc551emission brief 004mre
  • 1376e905deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • c0fdbf6cdocker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • ecf70665usage: layouts on components a567b57mre
  • 315731efcomponents re-synced to components.hybriel a567b57 (md-editor tables)mre
  • b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemre
  • 0222f67ctheme: two corner radii only (radiusSmall 5px, radiusLarge 10px); check-theme flags any other radius; gate 76/0mre
  • 877b63acdesign rules: two radii only (5px small, 10px large)mre
  • 635234dfcomponents re-synced to components.hybriel 5a98d77 (#15 black/white base look); gate 73/0, check-theme 0, screenshots unchangedmre
  • 876b2064docs: workaround note for hybriel#130 (slot marker mid-line)mre
  • 85b56541layouts mission 002 3/3: same-output tests, letcount, shots ports, docs, reportmre
  • 0f325d3blayouts mission 002 2/3: code rules — styles.hl -> components/styles.hl, the one never-reassigned let dropped; gate 73/0, same outputmre
  • a3e74c8alayouts mission 002 1/3: components re-copied byte-verbatim from components.hybriel 3f93d71 by tools/sync-components.sh (+ --check, components/SOURCE); gate 73/0, check-theme 0mre
  • 80ce6ba9report 001 (mission 075)mre