components
All repositories: gitoria
5.7 KB
// file-upload.hl — THE FILE UPLOAD (one file), pure Hybriel: a drop zone with a "Choose a file" button. The chosen or dropped file goes// to the app through `emit server saveFile(file)` (the framework carries it over HTTP, in parts, with progress: hybriel#94); the app's// `on server saveFile(file)` decides where it is stored and answers anything but null when it took it (a face that raises an error or// answers null = the upload failed). Name, size and progress show while it goes; a finished file is listed under "Uploaded".// One file at a time: a drop of several takes the first, a file dropped during an upload is ignored. USE ONE PER PAGE (a composed// component's members are the page's state). The page is written by DOM calls in the handlers: the emit blocks its handler, and// `on client uploadProgress` paints the bar meanwhile.String dropText = 'Drop a file here or'String chooseText = 'Choose a file'String uploadedTitle = 'Uploaded'sizeText(n) {if (n < 1024) { return n + ' B' }if (n < 1048576) { return (n / 1024).toFixed(1) + ' KB' }return (n / 1048576).toFixed(1) + ' MB'}View {fileUpload {dropZone { on dragover(e) { emit uploadOver(e) } on dragleave(e) { emit uploadLeave(e) } on drop(e) { emit uploadDrop(e) }p { dropText }label { class = "choose" chooseText input { type = "file" on change(e) { emit uploadChosen(e) } } }uploadStatus { 'aria-live' = "polite"strong { class = "name" }span { class = "size" }progress { max = "100" value = "0" }output { class = "state" }}}uploadedList {h2 { uploadedTitle }ul { class = "uploaded" }}}}rootOf(node) { return node.closest('file-upload') }on uploadOver(e) {e.preventDefault()rootOf(e.target).classList.add('over')}on uploadLeave(e) { rootOf(e.target).classList.remove('over') }on uploadDrop(e) {e.preventDefault()root = rootOf(e.target)root.classList.remove('over')if (e.dataTransfer.files.length > 0) { send(root, e.dataTransfer.files[0]) }}on uploadChosen(e) {root = rootOf(e.target)input = e.targetif (input.files.length > 0) { send(root, input.files[0]) }input.value = ''}on client uploadProgress(p) {for (root of document.querySelectorAll('file-upload.busy')) {let bar = root.querySelector('progress')bar.max = p.size > 0 ? p.size : 1bar.value = p.sent}}send(root, file) {if (root.classList.contains('busy')) { return null }root.classList.add('busy')root.classList.remove('done')root.classList.remove('failed')root.classList.add('shown')root.querySelector('.name').textContent = file.nameroot.querySelector('.size').textContent = sizeText(file.size)bar = root.querySelector('progress')bar.max = 100bar.value = 0state = root.querySelector('.state')state.textContent = 'Uploading…'saved = emit server saveFile(file)root.classList.remove('busy')if (saved == null) {root.classList.add('failed')state.textContent = 'Failed'return null}bar.max = 100bar.value = 100root.classList.add('done')state.textContent = 'Uploaded'li = document.createElement('li')li.textContent = file.name + ' — ' + sizeText(file.size)root.querySelector('ul.uploaded').appendChild(li)}// ---- look: the component's own Style; the base look is black, white and the greys #555 #999 #ddd #f2f2f2 (shared/base.hl names them;// README "Look"); every colour is a semantic token with its base value as fallback, so an app that declares the tokens (layouts.worldapi.org's// theme) restyles it. No frames: the one border is the drop zone's dashed one (it means "drop here")Style {fileUpload {display = 'block'color = 'var(--color-text, #000)'dropZone {display = 'block'padding = '1rem'textAlign = 'center'border = '2px dashed var(--color-border, #999)'borderRadius = '.5rem'p {margin = '0 0 .5rem'color = 'var(--color-text-muted, #555)'}}// Class or attribute assigned by the View or code; no compound-selector form.'label.choose' {display = 'inline-block'padding = '.35rem .8rem'cursor = 'pointer'border = '0'borderRadius = '.35rem'background = 'var(--color-surface, #f2f2f2)'hover { filter = 'brightness(.93)' }input { display = 'none' }}uploadStatus {display = 'none'marginTop = '.8rem'textAlign = 'left'// Class or attribute assigned by the View or code; no compound-selector form.'.name' { overflowWrap = 'anywhere' }// Class or attribute assigned by the View or code; no compound-selector form.'.size' {marginLeft = '.6rem'color = 'var(--color-text-muted, #555)'}// Class or attribute assigned by the View or code; no compound-selector form.'.state' { fontSize = '.9rem' }}progress {display = 'block'width = '100%'margin = '.4rem 0'accentColor = 'var(--color-accent, #000)'}uploadedList {h2 {margin = '1rem 0 .3rem'fontSize = '1rem'}}// Class or attribute assigned by the View or code; no compound-selector form.'ul.uploaded' {margin = '0'paddingLeft = '1.2rem'}}// No language form for class or attribute on the component root.'file-upload.over drop-zone' {borderColor = 'var(--color-accent, #000)'background = 'var(--color-surface, #f2f2f2)'}// No language form for class or attribute on the component root.'file-upload.shown upload-status' { display = 'block' }// No language form for class or attribute on the component root.'file-upload.done .state' { color = 'var(--color-success, #000)' }// No language form for class or attribute on the component root.'file-upload.failed .state' { color = 'var(--color-danger, #000)' }// No language form for pseudo-element.'file-upload ul.uploaded:empty::after' {content = '"Nothing yet."'marginLeft = '-1.2rem'color = 'var(--color-text-muted, #555)'}}
Branches
Latest commits
- df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
- 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
- 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
- 9b872cedRecord IC28 deployment and live icon verificationmre
- 46fefaa7Count the icons entry in the offline home-page checkmre
- c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre
- 5e090ffdRecord IC28 review evidence and gate resultsmre
- adfe2c4dAdd shuffle, repeat and repeatOne shared iconsmre
- c96709c8media-player: skip = false and repeat = 'one' options (jukebox#19)mre
- bd4aa808Record VL24 deployment and live verificationmre
- e5b98ecfRun virtual-list gate before deploymentmre
- 2e9b4a8evirtual-list: into main, with centerId and scrollTop/onScroll (jukebox#20)mre
- 69954249Align all plugin sources with Hybriel day38bmre
- f740f666Re-vendor components to Hybriel set day38bmre
- 8176eb14Record CS23b deployment and live verificationmre
- 84e3ddaaRemove blank line before pagination Style closing bracemre
- a92298ddRecord exact CSS and same-date proof after specificity reviewmre
- c71a0abePreserve consumer theme specificity with nested tag rulesmre
- 64a2bc27Document CS23b style formatting proof and review statusmre