components
All repositories: gitoria
6.1 KB
// files-upload.hl — THE FILE UPLOAD FOR SEVERAL FILES (ticket #5), pure Hybriel: a drop zone with a "Choose files" button (more than one// 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// `emit server uploadFile(file)` (the framework carries it over HTTP, in parts, with progress: hybriel#94), one file after the other in// 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// (an error or null = that file failed; the next one still goes). Files dropped during an upload wait in their row ("Waiting") and follow.// 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// 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.String dropText = 'Drop files here or'String chooseText = 'Choose files'sizeText(n) {if (n < 1024) { return n + ' B' }if (n < 1048576) { return (n / 1024).toFixed(1) + ' KB' }return (n / 1048576).toFixed(1) + ' MB'}View {filesUpload {dropZone { on dragover(e) { emit filesOver(e) } on dragleave(e) { emit filesLeave(e) } on drop(e) { emit filesDrop(e) }p { dropText }label { class = "choose" chooseText input { type = "file" multiple = "multiple" on change(e) { emit filesChosen(e) } } }}ul { class = "files" 'aria-live' = "polite" }output { class = "summary" }}}rootOf(node) { return node.closest('files-upload') }on filesOver(e) {e.preventDefault()rootOf(e.target).classList.add('over')}on filesLeave(e) { rootOf(e.target).classList.remove('over') }on filesDrop(e) {e.preventDefault()root = rootOf(e.target)root.classList.remove('over')add(root, e.dataTransfer.files)}on filesChosen(e) {root = rootOf(e.target)input = e.targetadd(root, input.files)input.value = ''}// the bar of the row being sent (one at a time)on client uploadProgress(p) {for (row of document.querySelectorAll('files-upload li.busy')) {let bar = row.querySelector('progress')bar.max = p.size > 0 ? p.size : 1bar.value = p.sent}}// one row per file, waiting; then the queue runs (unless it already does)add(root, files) {list = root.querySelector('ul.files')for (f of files) {let li = document.createElement('li')li.className = 'waiting'let name = document.createElement('strong')name.className = 'name'name.textContent = f.namelet size = document.createElement('span')size.className = 'size'size.textContent = sizeText(f.size)let bar = document.createElement('progress')bar.max = 100bar.value = 0let state = document.createElement('output')state.className = 'state'state.textContent = 'Waiting'li.appendChild(name)li.appendChild(size)li.appendChild(bar)li.appendChild(state)li.upload = flist.appendChild(li)}count(root)run(root)}// sends the waiting rows one after the otherrun(root) {if (root.classList.contains('busy')) { return null }root.classList.add('busy')let row = root.querySelector('li.waiting')while (row != null) {row.classList.remove('waiting')row.classList.add('busy')row.querySelector('.state').textContent = 'Uploading…'let saved = emit server uploadFile(row.upload)row.classList.remove('busy')row.upload = nulllet bar = row.querySelector('progress')if (saved == null) {row.classList.add('failed')row.querySelector('.state').textContent = 'Failed'} else {bar.max = 100bar.value = 100row.classList.add('done')row.querySelector('.state').textContent = 'Uploaded'}count(root)row = root.querySelector('li.waiting')}root.classList.remove('busy')}// "2 of 3 uploaded" (and how many failed)count(root) {all = root.querySelectorAll('ul.files li').lengthdone = root.querySelectorAll('ul.files li.done').lengthfailed = root.querySelectorAll('ul.files li.failed').lengthlet text = all == 0 ? '' : done + ' of ' + all + ' uploaded'if (failed > 0) { text = text + ', ' + failed + ' failed' }root.querySelector('output.summary').textContent = text}// ---- look: the component's own Style, the same base look as the one-file upload (black, white, the greys #555 #999 #ddd #f2f2f2;// 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// dashed one (it means "drop here"); rows are separated by space onlyStyle {'files-upload' { display = 'block' color = 'var(--color-text, #000)' }'files-upload drop-zone' { display = 'block' padding = '1rem' textAlign = 'center' border = '2px dashed var(--color-border, #999)' borderRadius = '.5rem' }'files-upload.over drop-zone' { borderColor = 'var(--color-accent, #000)' background = 'var(--color-surface, #f2f2f2)' }'files-upload drop-zone p' { margin = '0 0 .5rem' color = 'var(--color-text-muted, #555)' }'files-upload label.choose' { display = 'inline-block' padding = '.35rem .8rem' cursor = 'pointer' border = '0' borderRadius = '.35rem' background = 'var(--color-surface, #f2f2f2)' }'files-upload label.choose:hover' { filter = 'brightness(.93)' }'files-upload label.choose input' { display = 'none' }'files-upload ul.files' { listStyle = 'none' margin = '.8rem 0 0' padding = '0' }'files-upload ul.files li' { display = 'grid' gridTemplateColumns = '1fr auto' columnGap = '.6rem' marginBottom = '.7rem' }'files-upload ul.files .name' { overflowWrap = 'anywhere' }'files-upload ul.files .size' { color = 'var(--color-text-muted, #555)' textAlign = 'right' }'files-upload ul.files progress' { gridColumn = '1 / -1' width = '100%' margin = '.3rem 0' accentColor = 'var(--color-accent, #000)' }'files-upload ul.files .state' { gridColumn = '1 / -1' fontSize = '.9rem' color = 'var(--color-text-muted, #555)' }'files-upload ul.files li.done .state' { color = 'var(--color-success, #000)' }'files-upload ul.files li.failed .state' { color = 'var(--color-danger, #000)' fontWeight = '600' }'files-upload output.summary' { display = 'block' marginTop = '.3rem' fontWeight = '600' }}
Branches
Latest commits
- 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
- f2adb3f3components (mission 004) 1/3: Hybriel master a832f73b (incremental build cache, HL_CACHE_DIR, #151) — bin/hybriel sha256 e1b53f7ce687f5afbe3db34bcda69958f56e730571e4841923c9c8eb3d272db9 built from git archive a832f73b (HL_NO_PLUGINS=1 native/build.sh), the same nine plugins; container: HL_CACHE_DIR=/cache on volume hybriel-cache, /tmp tmpfs; tests wait COMPONENTS_COLD_MS (120 s) for every start; deploy.sh DEPLOY_URL_WAIT 120 s; gate 230/0 coldmre
- 91bd8a0dmission brief (w4)mre
- 3bc905c5components #15 (mission 003) 2/2: docs (README Look, STATUS, LOG), reportmre
- 5a98d77ecomponents #15 (mission 003) 1/2: black/white base look — greys for nuances, no WorldAPI fallbacks, no decorative frames; site + icon black/white; gate 230/0mre
- 3f93d716components code order (mission 002) 4/4: docs, tests/letcount.py, tests/same-output*, reportmre
- e747cfa0components code order (mission 002) 3/4: let only where reassigned (257 dropped, 0 never-reassigned left); gate 220/0, layouts gate 73/0, same outputmre
- 172914a3components code order (mission 002) 2/4: lib/uploads.hl (demo upload storage), thin demo handlers, project.hl map; gate 220/0, same outputmre
- d29f35b1components code order (mission 002) 1/4: styles.hl -> components/styles.hl; gate 220/0, same outputmre
- 09945750components: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, http1 773de63e); gate 220/0mre
- ede4d19acomponents: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 220/0mre
- 2bb9a935components: Hybriel master 8efba065 (re-vendor round 069: #126 memory, #48 lambda copy)mre
- e4f01768antcolony#40: mission references point to the moved missionsmre