gitoriaLog in with ident

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitede4d19aede4d19acomponents: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 220/0mreede4d19a/components/md-editor/demo.hl

2.6 KB

  1. // demo.hl — `/md-editor`: two editors on one page (the second starts empty and shows its placeholder), and the Markdown each holds
  2. // shown below. The editor announces a change with a bubbling DOM `input` event on its hidden field: `e.target.value` is the Markdown.
  3. parent '../main.hl'
  4. import MdEditor from './md-editor.hl'
  5. import { writeFile, mkDir, listDir, remove } from 'hl:fs'
  6. import { randomBytes } from 'hl:crypto'
  7. import { now } from 'hl:time'
  8. __title = 'Markdown editor · Hybriel components'
  9. static NL = "
  10. "
  11. String note = '# Hello' + NL + NL + 'Some **bold** and *italic* text with `code` and a [link](https://example.com).' + NL + NL + '- first' + NL + '- second'
  12. String summary = ''
  13. View {
  14. mdEditorDemo {
  15. h1 { "Markdown editor" }
  16. p { class = "muted" "Edit it visually: headings look like headings, bold is bold, lists are lists. The value below each editor is plain Markdown; paste Markdown in and it shows formatted." }
  17. form { id = "md-form" method = "get" action = "/md-editor" on input(e) { emit demoValue(e) }
  18. MdEditor { name = "note" value = note }
  19. h2 { "Value of “note”" }
  20. pre { id = "md-value" note }
  21. MdEditor { name = "summary" value = summary placeholder = "A second editor, empty: type here…" }
  22. h2 { "Value of “summary”" }
  23. pre { id = "md-value-summary" summary }
  24. p { button { type = "submit" "Send (posts both as Markdown)" } }
  25. }
  26. p { a { id = "readme" href = "/md-editor/README.md" "README (how to use it)" } }
  27. }
  28. }
  29. on demoValue(e) {
  30. if (e.target.name == 'note') { note = e.target.value }
  31. if (e.target.name == 'summary') { summary = e.target.value }
  32. }
  33. // WHERE THE FILES GO IS THE APP'S DECISION: the editor sends dropped / pasted / chosen files here (`emit server mdUpload`), this demo
  34. // keeps them in storage/md-files (served at /md-editor/files/…, see project.hl) under a random name, only with a known kind of
  35. // extension (nothing a browser would run), for one day. It answers the address of each file, in order.
  36. static kinds = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'txt', 'md', 'zip']
  37. on server mdUpload(files) {
  38. mkDir('storage/md-files')
  39. let urls = []
  40. for (f of files) {
  41. let dot = f.name.lastIndexOf('.')
  42. let ext = dot >= 0 ? f.name.slice(dot + 1).toLowerCase() : ''
  43. let known = false
  44. for (k of kinds) { if (k == ext) { known = true } }
  45. let stored = now() + '-' + randomBytes(6) + '.' + (known ? ext : 'bin')
  46. writeFile('storage/md-files/' + stored, f.bytes)
  47. urls.push('/md-editor/files/' + stored)
  48. }
  49. for (e of listDir('storage/md-files')) {
  50. let stamp = toNumber(e.name.slice(0, e.name.indexOf('-')))
  51. if (stamp != null && stamp < now() - 86400000) { remove(e.path) }
  52. }
  53. return urls
  54. }

Branches

Latest commits

  • 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
  • d32b44e2antcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 0fb80b57components: Hybriel master ff51cf46 (re-vendor round)mre
  • 57408b6ecomponents#14: installable app (manifest, service worker, offline index), own iconmre
  • 317bd09fdeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • becbd59bcomponents#13: modal dialog (<dialog> based, focus wrap, backdrop/Esc/x close with reason, scroll lock, footer buttons)mre
  • 367dd19adeploy.sh: never send .git or .gitignore to Byrodinmre
  • 4b4dabe5State of 2026-09-27, before the move to gitoriamre