components
All repositories: gitoria
5.1 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 {'file-upload' { display = 'block' color = 'var(--color-text, #000)' }'file-upload drop-zone' { display = 'block' padding = '1rem' textAlign = 'center' border = '2px dashed var(--color-border, #999)' borderRadius = '.5rem' }'file-upload.over drop-zone' { borderColor = 'var(--color-accent, #000)' background = 'var(--color-surface, #f2f2f2)' }'file-upload drop-zone p' { margin = '0 0 .5rem' color = 'var(--color-text-muted, #555)' }'file-upload label.choose' { display = 'inline-block' padding = '.35rem .8rem' cursor = 'pointer' border = '0' borderRadius = '.35rem' background = 'var(--color-surface, #f2f2f2)' }'file-upload label.choose:hover' { filter = 'brightness(.93)' }'file-upload label.choose input' { display = 'none' }'file-upload upload-status' { display = 'none' marginTop = '.8rem' textAlign = 'left' }'file-upload.shown upload-status' { display = 'block' }'file-upload upload-status .name' { overflowWrap = 'anywhere' }'file-upload upload-status .size' { marginLeft = '.6rem' color = 'var(--color-text-muted, #555)' }'file-upload progress' { display = 'block' width = '100%' margin = '.4rem 0' accentColor = 'var(--color-accent, #000)' }'file-upload.done .state' { color = 'var(--color-success, #000)' }'file-upload.failed .state' { color = 'var(--color-danger, #000)' }'file-upload upload-status .state' { fontSize = '.9rem' }'file-upload uploaded-list h2' { margin = '1rem 0 .3rem' fontSize = '1rem' }'file-upload ul.uploaded' { margin = '0' paddingLeft = '1.2rem' }'file-upload ul.uploaded:empty::after' { content = '"Nothing yet."' marginLeft = '-1.2rem' color = 'var(--color-text-muted, #555)' }}
Branches
Latest commits
- 9e1ab228MP: report, LOG line, STATUS entrymre
- dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
- e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
- 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
- 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
- 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre
- 0a9216fbMdEditor: a Table button in the toolbar, a typed pipe row fills the cells, tables take the page theme's look; gate checks updated for 12 toolbar buttonsmre
- f9d405c8comments: reactions row half as far from its comment (creator 2026-10-24: 'half this distance please'); the 44 px tap targets staymre
- 4922f9cfsessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0355975areports/MC-mobile.md, LOG, STATUS (MC)mre
- 3f0a7229Month view, date picker, range picker: names follow the page language (English by default, not the browser's), weekday/month names formatted in UTC (a UTC+12 zone showed Tue first), 44 px day cells and buttons, Send row air; gate checks at 390 px for every page, popup and dialog (MC)mre
- 29eb07eaPhone: 44 px targets on the site (brand, home links, buttons), comments, modal and pagination; the header is the brand alone on a phone; comments demo: labelled 'You are' group with the chosen user pressed (MC)mre
- d1cc83e2reports/E2-toolbar.mdmre
- 214c3183MdEditor on a phone: toolbar as two even rows of 44 px targets (no clipped icon, no swipe), 'Markdown source' label 15 px, table head 16 px; gate checks (E2)mre
- 9215bbaareports/F5-empty.mdmre
- 134b4e3eMdEditor: an editor the framework puts into the page is built at once (page observer), a surface put in anew under a built editor is redrawn; gates for both (hybriel#211)mre
- 0dce2899reports/K1-bubble.mdmre
- 6b0936a0comments: 'edited' foldable also drops the theme's border, margin and radius (display: contents alone left them computed)mre
- 8d79ff79comments bubble hugs its content: a readonly md-editor surface gets no inline min-height (it beat the stylesheet's min-height 0); 'edited' is a quiet label beside the time, versions unframed; gate checksmre
- ef253fecreports/F4-icons.mdmre