gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0bcc62940bcc6294Mission 011: e2e-197, brief, report, LOGmre0bcc6294/plugins/web/client.hl

174.4 KB

  1. // The framework's client half — a file-class constructed ONCE in the browser by
  2. // the page's module script, with the seed the server rendered from. The
  3. // components are NOT preloaded: each mount carries the url its module is served
  4. // at and `hlLoad` fetches it when the mount happens. This file is the client
  5. // realm's entrypoint, and the page script sets that realm before constructing
  6. // it.
  7. //
  8. // Its whole job: CLAIM the DOM the server rendered for the mounted instances,
  9. // remember which elements read which member (the SITES), repaint a site when a
  10. // member is written, and turn a same-origin link into a navigation that fetches
  11. // the next route's tree and state and swaps the slot — the shell stays.
  12. import HlwView from './view.hl'
  13. import HlwRouter from './router.hl'
  14. seedText = '' // the server's seed, as JSON text (the one construction argument)
  15. seed = null // { page: { key module params state view }, shell: … | null }
  16. view = new HlwView
  17. router = null // the client's route table, from the seed
  18. shell = null // { key, instance, view, sites, root }
  19. page = null
  20. appHead = null // the app's manifest head defaults, off the seed: what a page
  21. // member that is null falls back to (title, description, image,
  22. // favicon, and the app's own meta list)
  23. slotEl = null // the shell element whose children are the route component
  24. // WHERE IN IT (ticket #81's finding): the shell's slot may stand beside other elements
  25. // of the shell — `body { header { … } slot }` — and the page's nodes are then not all
  26. // of slotEl's children. `slotAt` is the index of the page's first element among them,
  27. // and `slotStart` the open mark of the region the page is (a page in a shell stands
  28. // between two marks like every region), so the page is claimed from the right element
  29. // and a navigation replaces what stands between the marks and nothing of the shell's.
  30. slotAt = 0
  31. rowKidBound = {} // component key | for site → the host members its row children are bound to
  32. rowKidless = {} // component key | for site → true when its row body composes no child
  33. slotStart = null
  34. regionTable = {} // NAMED REGIONS (`slot { name = 'side' … }`) the shell's levels hold: name → { host start at desc kind }
  35. detachedSlot = null // the slot element a shell region's rebuild took out of the DOM (see paint)
  36. socket = null // the websocket carrier, while it is open
  37. socketOpened = false // it has opened (a socket that closes without opening is a failed reconnect)
  38. retryMs = 500 // the wait before the next reconnect: doubles per failure up to 4 s, reset on open
  39. probing = false // the probe of `/__hl/up` runs while a reconnect waits (ticket #153, probe())
  40. probeFailed = false // a probe found no server since the last socket opened
  41. // THE TAB ACROSS ITS SOCKETS (ticket #143): this document's id, the `n` of the last push it
  42. // dispatched, and whether a socket opened before — all three ride every `hello`, and the
  43. // server answers a reopened socket with what it missed
  44. tabId = null
  45. lastSeq = 0
  46. seenAbove = {} // 'n<n>' → true for a push dispatched past lastSeq (one a POST's ack carried)
  47. everOpened = false
  48. navigating = false // a navigation is running (show); navNext is the one asked for meanwhile
  49. navNext = null
  50. pinging = false // the ping interval is started once, with the first socket
  51. pongDue = null // the timer that takes the socket for dead when its pong is late
  52. nextId = 0 // the pairing id an emit's ack comes back on
  53. pending = {} // 'k<i>' → the resolver waiting for that ack
  54. // AN ANSWER THAT ARRIVES BEFORE ITS PAGE IS MOUNTED (ticket #80). A component's root
  55. // runs while `instantiate` constructs it, and an `emit server` there goes out at once
  56. // (over REST: the socket opens after boot). What the face raised for this tab comes
  57. // back in the ack, before `page` — or, on a navigation, the NEXT page — is the mount
  58. // that holds the listener; delivered then, it reached the old mounts or none and was
  59. // lost. While a mount is being built the frames wait here, and go out in arrival
  60. // order once it stands.
  61. mounting = false
  62. held = []
  63. forwarding = 0 // upward() is dispatching at the levels above a sender: their own listeners stay silent
  64. lateInner = null // the parent levels an arriving page brought below the shell (arrive), taken by the slot that opened
  65. delivering = 0 // outward() is dispatching a frame at the mounts: a page's forwarder (wireUp) stays silent then
  66. blueprints = {} // component key → { module, view }: every tree the page can
  67. // build, taken from each seed and never dropped (takeBlueprints)
  68. strict = false // the gates' client: a repaint that finds a stale site throws (staleSite)
  69. paintSet = null // the members the running repaintAll moved (a `for` over a row with a child steps over unchanged rows only if all are its own)
  70. painting = 0 // repaints running: 0 when the page stands still (the gates wait for it)
  71. turning = false // a patch is running (patch): the ones asked for meanwhile wait in patchQueue
  72. patchQueue = []
  73. sidNext = 0 // every site's own number, so a repaint can tell one that has left
  74. dropGen = 0 // counts the drops of sites (dropSitesIn): a repaint's list is checked again after one
  75. pendingDrops = [] // ranges that left holding a host's fill: that host's sites and children in them
  76. // go in settle(), once every mount on the walk has been written back
  77. pendingFills = [] // fills a region rebuild anchored but could not build in place:
  78. // the host is named by address and re-entered in settle() below
  79. // ownerId -> { key, chain, root } of the mount that owns that instance, and the reverse
  80. // (address -> ownerId, the check that an entry still names a live mount). A MOUNT RECORD
  81. // IS A VALUE, so finding a mount by walking the tree with `let kid = m.kids[k]` deep-copies
  82. // every subtree on every handler event; the index is filled where a mount is made
  83. // (`instantiateNode`, `mintFrom`) and emptied where one is replaced or removed
  84. // (`purgeMounts`), so a lookup is O(1) at any depth.
  85. mountIndex = {}
  86. mountAddr = {}
  87. lateJobs = [] // late patches (#98, #99): see latePatch
  88. lateDue = false
  89. // THE EVENTS A REFERENCE OVERWROTE ON THE COMPOSITION'S ROOT, while the walk is inside
  90. // that composition and has not yet reached an element. A composed child's View may be a
  91. // bare reference to another component (routger's dialog-form.hl is one), so the element
  92. // that FINALLY stands as the child's root can be any number of references deeper — this
  93. // rides down through them and is spent on the first elements the walk claims or builds,
  94. // which are exactly those roots.
  95. rootOverwrites = null
  96. // IS THE PAGE ON THE DOCUMENT? A shell decides per request whether its render contains
  97. // a `slot` (COMPONENTS §7, "THE PARENT IS THE GATE"): `if (loggedIn) { main { slot } }`
  98. // standing false renders no page at all, and there is then nothing to claim. False here
  99. // means there IS no page: the server did not construct it and the seed carries none
  100. // (creator, 2026-08-26 — the parent is the gate). It is asked for and constructed when
  101. // the region holding the slot turns true, and dropped again when it turns false.
  102. pageShown = false
  103. pageArrived = false // a region's rebuild constructed the page: its held frames go out after it
  104. // THE OFFLINE LAYER (COMPONENTS §10), live only when the seed says the app keeps pages
  105. // offline. `store` is the IndexedDB database, opened at boot; `unacked` holds what a
  106. // queueable emit sent on the socket carried until its ack, so a socket that closes
  107. // under it queues the emit instead of losing it; `flushing` is true while the queue
  108. // is replayed; `retryTimer` is the reconnect that is waiting.
  109. store = null
  110. unacked = {}
  111. replays = {} // 'k<i>' → what ends a replayed entry's wait when its socket closes
  112. // AN EMIT IN FLIGHT OUTLIVES ITS SOCKET (ticket #107). Every emit that went out on the
  113. // socket is here until its ack, as the frame it was: a socket that closes under it
  114. // hands it on to the POST fallback or the next socket, with the same `q`, and the
  115. // server's exactly-once path answers the repeat instead of running the face again.
  116. // `post` is true while the POST fallback carries it, `lost` once a POST failed.
  117. inflight = {} // 'k<i>' → { text; event; post; lost; }
  118. // A PAGE BEING LEFT starts nothing. Firefox closes the page's socket the moment a
  119. // document navigation starts, right after `beforeunload` and long before `pagehide`;
  120. // a reconnect or a POST made then, and an answer that loads a document, would cancel
  121. // the navigation the user started. `beforeunload` is only a maybe (a download, a
  122. // navigation the server answers with 204), so after it the page takes itself for
  123. // staying once `stayMs` have passed and it is still here.
  124. leaving = false
  125. stayTimer = null
  126. static stayMs = 3000
  127. flushing = false
  128. retryTimer = null
  129. owner = '' // whose the kept copy is (settleWho): the last user logged in
  130. onlineBound = false // the online/offline listeners are on the window (syncOnline)
  131. holding = false // an anonymous page over a user's copy: nothing is kept or laid over it
  132. heldBack = false // the server said a queued entry is for another user than the session's
  133. queueRetryTimer = null // a round that did not fully drain tries again after queueRetryWait
  134. // ---- THE PACKAGE'S BROWSER SURFACE: what `import { … } from 'hl:web'` binds ------
  135. //
  136. // A file's STATICS are what a braced import may take (the language's one rule for
  137. // `import { db } from './store.hl'`, and the same rule across a package's url),
  138. // so everything this half offers an app's component is declared here and nowhere
  139. // else. A static belongs to the CLASS, which is why these two reach each other
  140. // and why they are the SAME pair for every component module the page imports —
  141. // the browser loads this file once.
  142. //
  143. // `live` IS THE PAGE'S ONE CLIENT, written by the root below. The statics cannot
  144. // see an instance (they are evaluated at file load, before there is one), and a
  145. // static that is a FUNCTION does not need to: its body runs at the CALL, long
  146. // after the root has put the constructed client here.
  147. static live = { client = null }
  148. // PROGRAMMATIC NAVIGATION — the same act a click on a same-origin `<a>` performs,
  149. // asked for by code instead of by a pointer: a new history entry, then the next
  150. // route's tree and state over the boundary and into the shell's slot. A handler
  151. // that has just been told an id and must go to that thing's page has no link to
  152. // click, and this is what it calls instead. Everything about what a navigation IS
  153. // stays in `goTo` below; this is only the way in from outside the file.
  154. static navigate = (path) => { return live.client.goTo(path) }
  155. // A NOTIFICATION, now or at a set time (COMPONENTS §10, ticket #95). `at` is epoch
  156. // milliseconds. The browser is asked for permission the first time. It is shown by
  157. // the service worker when the app has one (so an installed app shows it as the app),
  158. // else by the page. A notification AT A SET TIME is a timer of this page: it fires
  159. // while the page is open — a browser offers no way to wake a closed app at a time
  160. // without a server push, and this does not pretend otherwise.
  161. static notify = (title, options) => { return live.client.showNotice(title, options) }
  162. static notifyAt = (at, title, options) => { return live.client.noticeAt(at, title, options) }
  163. // …or after `ms` milliseconds
  164. static notifyIn = (ms, title, options) => { return live.client.noticeIn(ms, title, options) }
  165. // FORGET WHAT THIS BROWSER KEPT OFFLINE (ticket #125): the kept state, the queue and the
  166. // worker's kept documents. hl:web does it itself when the session's user changes (a log-out
  167. // included) at the next page it is told about; an app that logs out in place calls this.
  168. // WEB PUSH (ticket #173): ask for permission, subscribe with the app's `pushKey`, and answer the
  169. // subscription as `{ endpoint, expirationTime, keys = { p256dh, auth } }` — or null when the browser
  170. // has no push, the key is not set or permission is refused. The app hands it on:
  171. // `let s = subscribePush() emit server savePush(s)`.
  172. static subscribePush = () => { return live.client.pushSubscribe() }
  173. static forgetOffline = () => { return live.client.forgetOffline() }
  174. // ---- boot: construct the instances the server rendered, claim their DOM ----------
  175. // THE PAGE'S CLIENT, PUBLISHED TO THE FILE'S OWN CLASS, before anything else the
  176. // root does: `boot()` below constructs the components, and a component's module
  177. // may reach `navigate` from the moment it is loaded.
  178. Client.live.client = this
  179. // A VIEW EXPRESSION in a module's code is evaluated by view.hl's one `evalExpr`, so the
  180. // language's own operators answer in the browser as they do on the server
  181. window.__hlX = (x, inst, rows) => { return view.evalExpr(x, inst, rows) }
  182. seed = resolveValues(JSON.parse(seedText))
  183. router = new HlwRouter(routes = seed.routes)
  184. boot()
  185. // THE VALUES TABLE (#180): the server writes a large value that stands in several places once,
  186. // in `seed.values[id]`, and a place holds `{ "$hlv": id }`. Every reference is resolved HERE,
  187. // as the seed is read (a navigation's answer too, in showOne) and each place gets a copy of its
  188. // own, built fresh: a child that changes its `items` does not change the page's `home`.
  189. resolveValues(s) {
  190. if (s == null || s.values == null) { return s }
  191. let table = s.values
  192. s.values = null
  193. if (s.page != null) { s.page = unshare(&table, s.page) }
  194. if (s.shell != null) { s.shell = unshare(&table, s.shell) }
  195. return s
  196. }
  197. unshare(&table, v) {
  198. if (hlTypeName(v) != 'Hybrid') { return v }
  199. if (v['$hlv'] != null) { return unshare(&table, table[v['$hlv']]) }
  200. let out = null
  201. if (Array.isArray(v)) {
  202. out = []
  203. for (x of v) { out.push(unshare(&table, x)) }
  204. } else {
  205. out = {}
  206. for (k of v.keys()) { out[k] = unshare(&table, v[k]) }
  207. }
  208. return out
  209. }
  210. boot() {
  211. mounting = true
  212. strict = seed.strict == true
  213. takeBlueprints(seed.blueprints)
  214. if (seed.shell != null) {
  215. shell = instantiate(seed.shell, [], 'shell')
  216. shell.isShell = true
  217. // (the BODY ELEMENT, nothing to do with `rootKind` below — a mount's `rootKind`
  218. // says which of the two roots it hangs from, 'page' or 'shell'. This field held
  219. // the DOM node under the same name until 2026-09-14, and the shell's address
  220. // therefore read as an element: every lift and every fill re-entry from a
  221. // composition IN THE SHELL resolved against the page instead, so a composed
  222. // control there wrote nothing — creator, W15.)
  223. shell.root = document.body
  224. // the body node's children are claimed against document.body, so the body
  225. // element takes the node itself here: a region hosted directly on it (an `if`
  226. // at the shell's root) rebuilds from it (measured 2026-09-13: a lone child
  227. // under `body` stayed on screen after its condition turned false)
  228. claim(&shell, document.body)
  229. }
  230. page = seed.page != null ? instantiate(seed.page, [], 'page') : null
  231. // no shell: the page IS the document's body content
  232. if (shell == null) { slotEl = document.body }
  233. // THE SHELL RENDERED NO SLOT — its region stood false for this request, so the
  234. // document carries no page. Claiming one anyway walked the page's tree against the
  235. // SHELL's own elements and silently attached the page's nodes to them ("claim: no
  236. // element for … under …" as soon as the two shapes differ), and the page never
  237. // appeared when the region later turned true. It waits instead.
  238. if (slotEl != null && page != null) {
  239. slotEl.__hlCur = slotStart
  240. claim(&page, slotEl, slotAt)
  241. pageShown = true
  242. }
  243. // the shell's named regions take their content: the filling level's, or their own default
  244. if (shell != null) { placeRegions(true) }
  245. // the head members are sites of this mount from here on. They are NOT painted
  246. // now: the server's `document()` already wrote them into this document, and a
  247. // write to one of them repaints it the way every other member's write does.
  248. appHead = seed.head
  249. if (page != null) { headSites(&page) }
  250. release()
  251. listen()
  252. syncOnline()
  253. if (seed.offline != null) { standIn() }
  254. if (seed.offline != null) { offlineBoot() }
  255. connect()
  256. }
  257. // A DOCUMENT THAT STANDS IN FOR THIS URL (#124): the worker answered an unvisited param page
  258. // with a kept document of the same component, so the seed's parameters are another url's.
  259. // This url's are the truth: they go into the instance, and what they feed is derived again
  260. // here (what only the server can derive stays as that document had it, until a push).
  261. standIn() {
  262. if (page == null || seed.page == null) { return null }
  263. let m = router.match(location.pathname)
  264. if (m == null || m.route.component != true) { return null }
  265. let mine = JSON.stringify(m.params)
  266. if (mine == JSON.stringify(seed.page.params)) { return null }
  267. for (k of m.params.keys()) { page.instance[k] = m.params[k] }
  268. seed.page.params = m.params
  269. patch(page.chain, 'page', moved(&page, m.params.keys()), [])
  270. return null
  271. }
  272. // THE NEXT PAGE INTO THE SLOT, and nothing else of the shell's: the slot's element may
  273. // hold the shell's own elements beside the page (`body { header { … } slot }`), which
  274. // emptying it took with the old page. The new page is built where the old one stood.
  275. placePage(&m) {
  276. if (!standing(slotEl, slotStart)) {
  277. // the page is all the slot's element holds: empty it, as it always was
  278. slotEl.replaceChildren()
  279. create(&m, slotEl)
  280. return null
  281. }
  282. for (n of between(slotStart)) { n.remove() }
  283. let frag = document.createDocumentFragment()
  284. let before = sidNext
  285. create(&m, frag)
  286. slotEl.insertBefore(frag, slotStart.__hlEnd)
  287. // the sites the walk registered on the fragment (a region at the page's root, a composed
  288. // child's) belong to the slot's element it landed in (#191: they stayed on the empty fragment,
  289. // and the first click on a child's button after a navigation did nothing)
  290. rehome(&m, frag, slotEl, before)
  291. return null
  292. }
  293. // the frames that waited for the mounts (above), now that they stand
  294. release() {
  295. mounting = false
  296. let frames = held
  297. held = []
  298. for (f of frames) { outward(f) }
  299. return null
  300. }
  301. // a mount's instance: the module LOADED (hlLoad — the loader primitive, which
  302. // on this target is the dynamic import of the url the server compiled the
  303. // component to), the class constructed, then the server's state laid over it.
  304. // The import is the browser's own cache: a second mount of the same component
  305. // fetches nothing.
  306. // The route's params and the server's state are the construction's NAMED
  307. // ARGUMENTS, pinned before the root runs — so a member the server evaluated
  308. // (a seeded one, declared without its initializer in this realm's projection)
  309. // is already there when a later line reads it, and a client-evaluable
  310. // initializer keeps the server's value instead of recomputing it.
  311. // THE BLUEPRINT TABLE, read by component key: the url the component's module is
  312. // served at and its View tree, one copy for the whole page. Every mount's tree is
  313. // read from here — the page's, the shell's, and every child's — and so is every
  314. // child the browser has to build itself.
  315. //
  316. // IT ONLY GROWS. Each seed carries the table for ITS route, and a navigation takes
  317. // the new entries WITHOUT dropping the old: a key is a component and a component is
  318. // one tree, so an entry is never wrong, and constructing a mount awaits its module —
  319. // long enough for a second navigation to have replaced the seed underneath it. A
  320. // table that was replaced left that half-built page reading the wrong route's
  321. // entries ("no blueprint for components/post.hl", on `/`, measured in the reference
  322. // gate 2026-09-13).
  323. takeBlueprints(table) {
  324. for (k of table.keys()) {
  325. if (blueprints[k] == null) { blueprints[k] = table[k] }
  326. }
  327. return null
  328. }
  329. blueprintOf(key) {
  330. return blueprints[key]
  331. }
  332. treeOf(key) {
  333. let bp = blueprintOf(key)
  334. // the table covers every component the page can reach, so this is a torn seed
  335. // and not a missing feature — say so loudly and paint nothing for that mount
  336. if (bp == null) { console.error('framework: the seed carries no blueprint for ' + key)
  337. return [] }
  338. return bp.view
  339. }
  340. // `chain` and `root` are the mount's ADDRESS: the kid keys from the page (or the
  341. // shell) down to it. A mount record is a value, so a site cannot hold the mount that
  342. // owns its fill — it holds this address, and `fillAt` re-enters the mount by
  343. // reference from the root when the fill has to be rebuilt (see settle below).
  344. instantiate(m, chain, root) {
  345. purgeMounts(chain, root)
  346. return instantiateNode(m, chain, root)
  347. }
  348. // a mount made at (chain, root) replaces whatever was there: forget it and everything under it
  349. purgeMounts(chain, root) {
  350. let base = addressOf(chain, root)
  351. let sep = chain.length == 0 ? '' : '/'
  352. let gone = []
  353. for (a of mountAddr.keys()) {
  354. if (a == base || a.startsWith(base + sep)) { gone.push(a) }
  355. }
  356. for (a of gone) {
  357. delete mountIndex['' + mountAddr[a]]
  358. delete mountAddr[a]
  359. }
  360. return null
  361. }
  362. registerMount(inst, key, chain, root) {
  363. let addr = addressOf(chain, root)
  364. if (mountAddr[addr] != null) { purgeMounts(chain, root) }
  365. let id = inst.__hlOwnerId
  366. if (id == null) { return null }
  367. mountIndex['' + id] = { key = key; chain = chain; root = root; }
  368. mountAddr[addr] = id
  369. if (root == 'page' && chain.length == 0) { wireUp(inst, key, levelCount() + 1) }
  370. if (root == 'shell' && chain.length > 0 && chain[chain.length - 1] == '^') { wireUp(inst, key, chain.length) }
  371. return null
  372. }
  373. // A PAGE'S EMIT REACHES ITS PARENT SHELL'S `on` (ticket #193). The levels stand in the
  374. // browser, so the page is its own instance and `emit shellSession(x)` in its View finds
  375. // no handler on it: the handler is the shell's. Every event the shell declares gets a
  376. // listener on the PAGE INSTANCE's own bus (the language's instance-scoped handler, the one
  377. // `on page.ev` registers, which every dispatch at that instance fires last) that hands the
  378. // emit to the shell's instance through the dispatch `outward` uses (`hlEmitArgs`) and
  379. // repaints what the shell's handler wrote. Server cost: none, nothing leaves the browser.
  380. wireUp(inst, key, depth) {
  381. if (seed.shell == null || window.__hlC == null) { return null }
  382. if (window.__hlC[key] == null || window.__hlC[key].on == null) { return null }
  383. // every event any level above this mount declares (a level's table is its own compiled `ev`)
  384. let seen = {}
  385. let at = seed.shell
  386. let i = 0
  387. while (at != null && i < depth) {
  388. let tbl = window.__hlC[at.key]
  389. if (tbl != null && tbl.ev != null) {
  390. for (ev of tbl.ev.keys()) {
  391. if (seen[ev] == null) { seen[ev] = true wireEvent(&inst, key, ev, depth) }
  392. }
  393. }
  394. at = at.kids['^']
  395. i = i + 1
  396. }
  397. return null
  398. }
  399. // how many parent levels stand above the page: the shell and every '^' kid below it
  400. levelCount() {
  401. let n = 0
  402. let at = shell
  403. while (at != null) { n = n + 1 at = at.kids['^'] }
  404. return n
  405. }
  406. wireEvent(&inst, key, ev, depth) {
  407. window.__hlC[key].on(&inst, ev, (a, b, c, d, e) => { return upward(ev, [a, b, c, d, e], depth) })
  408. return null
  409. }
  410. // The emit goes to the `depth` levels above its sender, nearest first, each level's handlers
  411. // once. `forwarding` keeps the dispatch AT a level (the levels' own listeners) silent.
  412. upward(ev, args, depth) {
  413. // a frame the server pushed reaches the shell on its own (outward), not through the page
  414. if (shell == null || delivering > 0 || forwarding > 0) { return null }
  415. let payload = args
  416. while (payload.length > 0 && payload[payload.length - 1] == null) { payload = payload.slice(0, payload.length - 1) }
  417. let lv = []
  418. let at = shell
  419. while (at != null && lv.length < depth) { lv.push(at) at = at.kids['^'] }
  420. forwarding = forwarding + 1
  421. let j = lv.length - 1
  422. while (j >= 0) {
  423. let m = lv[j]
  424. let tbl = window.__hlC[m.key]
  425. if (tbl != null && tbl.ev != null && tbl.ev[ev] != null) {
  426. let inst = m.instance
  427. hlEmitArgs(&inst, ev, payload)
  428. patch(m.chain, m.rootKind, eventWrites(m.key, ev), [])
  429. }
  430. j = j - 1
  431. }
  432. forwarding = forwarding - 1
  433. return null
  434. }
  435. instantiateNode(m, chain, root) {
  436. let args = {}
  437. for (k of m.state.keys()) { args[k] = m.state[k] }
  438. for (k of m.params.keys()) { args[k] = m.params[k] }
  439. let inst = hlLoad(m.module, args)
  440. // THE TREE COMES FROM THE TABLE, by this mount's key: a View belongs to the
  441. // COMPONENT, and the seed carries one copy of it however many mounts share it.
  442. let out = { key = m.key; instance = inst; view = treeOf(m.key); sites = []; isShell = chain.length > 0 && chain[chain.length - 1] == '^'; kids = {}; bindings = []; chain = chain; rootKind = root; }
  443. registerMount(inst, m.key, chain, root)
  444. // THE MIRROR: the components this one composes are instances here too, exactly
  445. // as the server stacked them — one per component node, constructed with the
  446. // bindings the server evaluated; a binding to a host MEMBER is remembered, so a
  447. // host write reaches the child's member and repaints the child's sites
  448. for (k of m.kids.keys()) { out.kids[k] = instantiateNode(m.kids[k], childChain(chain, k), root) }
  449. bindKids(&out, out.view)
  450. // A BOUND MEMBER'S VALUE IS THE HOST'S, HERE. The seed carried the server's
  451. // value, which is right for data and null for a FUNCTION (JSON has no form for
  452. // one) — and a function the host hands its child (`PostForm { onCancel = cancel
  453. // }`) is the way a child talks upward without knowing its host: it calls what it
  454. // was given, and the function writes the host's members through the instance
  455. // that wrote it. So every member binding is applied from the host instance now.
  456. for (b of out.bindings) {
  457. if (out.kids[b.kid] != null) {
  458. out.kids[b.kid].instance[b.target] = bindingValue(b, &out)
  459. }
  460. }
  461. return out
  462. }
  463. bindKids(&m, nodes) {
  464. for (n of nodes) {
  465. if (n.k == 'component') {
  466. // THE EDGE STANDS WHETHER OR NOT THE SERVER MOUNTED THE CHILD: a branch that does
  467. // not stand is not mounted, and the browser builds the child when it comes to
  468. // stand — which must then follow the host's member (every reader of `m.bindings`
  469. // passes over an edge whose child is not there)
  470. {
  471. // A BINDING IS A READ at the reference site: a member (`count = likes`)
  472. // or a field path off one (`postId = row.id`). Both follow the host's
  473. // write — the field path under the name it starts at.
  474. for (b of n.bindings) {
  475. // A MEMBER THAT ONLY FEEDS A BINDING still follows a write: `repaint`
  476. // walks the bindings after the sites, so a host member no element of the
  477. // host shows still reaches the child that was bound to it (measured
  478. // 2026-09-13 on the social app: `FollowButton { following =
  479. // authorFollowed }` stayed false). Under the digest that needed the
  480. // member to be in the compared map; under the write sets it needs
  481. // nothing but the edge itself.
  482. if (b.member != null) { m.bindings.push({ name = b.member; kid = view.kidKey(n.path); target = b.name; ref = null; }) }
  483. else if (b.ref != null) { m.bindings.push({ name = b.ref.name; kid = view.kidKey(n.path); target = b.name; ref = b.ref; }) }
  484. }
  485. }
  486. // the fill is THIS mount's fragment: a reference inside it binds against this instance
  487. if (n.fill != null) { bindKids(&m, n.fill) }
  488. } else if (n.k == 'el') {
  489. bindKids(&m, n.children)
  490. } else if (n.k == 'if') {
  491. bindKids(&m, n.then)
  492. bindKids(&m, n.other)
  493. }
  494. }
  495. return null
  496. }
  497. // a body-rooted View's children are the body's children
  498. childrenOf(nodes) {
  499. if (nodes.length == 1 && nodes[0].k == 'el' && nodes[0].tag == 'body') { return nodes[0].children }
  500. return nodes
  501. }
  502. // ---- WHAT THE COMPILE STEP ANSWERED, asked by name ---------------------------------
  503. // A local event's write set stands at its own listener and a region's names at its own
  504. // region: the compile step wrote them into the statements. These three are asked for by
  505. // NAME at run time and cannot be — an inbound frame names its event, a routine a host
  506. // handed down names the member that holds it, and a write set names the derivations
  507. // that follow it — so the component's compiled half carries them beside its walks.
  508. // Nothing here reduces a table: the answers are already the answers.
  509. eventWrites(key, event) {
  510. let names = compiledEntry(key, 'ev', event)
  511. return names == null ? [] : names
  512. }
  513. memberWrites(key, name) {
  514. let names = compiledEntry(key, 'mw', name)
  515. return names == null ? [] : names
  516. }
  517. derivationsOf(key) {
  518. if (window.__hlC == null || window.__hlC[key] == null) { return [] }
  519. return window.__hlC[key].dv
  520. }
  521. // one entry of one table of a compiled component, read in place: `compiledOf` hands a
  522. // copy of the whole compiled half, which a push to every mount cannot afford (#138)
  523. compiledEntry(key, table, name) {
  524. if (window.__hlC == null || window.__hlC[key] == null || window.__hlC[key][table] == null) { return null }
  525. return window.__hlC[key][table][name]
  526. }
  527. // ---- THE COMPILED COMPONENT: this framework's own output for this file ------------
  528. // The old hl:web walked a tree the seed carries — it pairs an element with a node, asks a table
  529. // what the element shows, and asks `view.value` what each bound spot holds. hl:web
  530. // ships the answers as the component's own code (plugins/web/compile.hl), and the
  531. // functions below are the FIXED runtime that code calls: the mount records, the keyed
  532. // region diff, the binding edges, the derivations, the socket and navigation stay here,
  533. // where they belong to the framework and not to any one component.
  534. //
  535. // EVERY CALL INTO GENERATED CODE PASSES BY REFERENCE. A plain call copies its
  536. // arguments (the language's value semantics), which for an instance holding a 2000-row
  537. // list would copy the list on every paint; `&` at the call site hands the value itself,
  538. // the way every walk in this file already hands a mount record.
  539. compiledOf(key) {
  540. let all = window.__hlC
  541. if (all == null) { return null }
  542. return all[key]
  543. }
  544. // one paint entry of a compiled component, read in place (compiledOf hands a copy of
  545. // the whole table, which a row repaint cannot afford per element)
  546. paintEntry(key, site) {
  547. if (window.__hlC == null || window.__hlC[key] == null) { return null }
  548. return window.__hlC[key].p[site]
  549. }
  550. // the walk of a component's whole View, of one `for` body, of an `if` branch, or of
  551. // the fragment a reference fills — each under its own site
  552. walkOf(key, slot, site) {
  553. // each slot is read in place off the global table (the `paintEntry` way): `compiledOf`
  554. // would copy the whole compiled component for every `if` site and every `for` row
  555. if (window.__hlC == null || window.__hlC[key] == null) { return null }
  556. if (slot == 'v') { return window.__hlC[key].v }
  557. if (slot == 'b') { return window.__hlC[key].b[site] }
  558. if (slot == 't') { return window.__hlC[key].t[site] }
  559. if (slot == 'e') { return window.__hlC[key].e[site] }
  560. if (slot == 'f') { return window.__hlC[key].f[site] }
  561. if (slot == 'd') { return window.__hlC[key].d[site] }
  562. if (slot == 'r') { return window.__hlC[key].r[site] }
  563. return null
  564. }
  565. // ONE ENTRY INTO GENERATED CODE. `f` is the walk, `m` the mount it runs for, `o` the
  566. // mount whose fragment a `slot` inside it would place.
  567. run(f, &m, &o, host, i, rows, rk, fill, cr, opt) {
  568. if (f == null) { return i }
  569. let c = this
  570. return f(&c, &m, &o, &host, i, &rows, rk, &fill, cr, &opt)
  571. }
  572. acqFail(tag, host) {
  573. console.error('claim: no element for', tag, 'under', host == null ? null : host.tagName)
  574. return null
  575. }
  576. // the classes a reference's `#Child` rule put on the composition root, beside whatever
  577. // class the root itself carries (view.hl withRootClasses, on the build walk)
  578. rootClasses(el, opt) {
  579. if (opt == null || opt.classes == null || opt.classes.length == 0) { return null }
  580. let add = ''
  581. for (c of opt.classes) { add = add == '' ? c : add + ' ' + c }
  582. let have = el.getAttribute('class')
  583. el.setAttribute('class', have == null || have == '' ? add : have + ' ' + add)
  584. return null
  585. }
  586. // AN ELEMENT THAT SHOWS SOMETHING is a site of this mount. The names come from the
  587. // generated call — the compile step read them off the View — and the two-way `value`
  588. // bind is applied where the element is a form control the member paints.
  589. siteAt(&m, el, names, site, valueMember, isSelect, rows) {
  590. let keep = []
  591. for (name of names) {
  592. // the SHELL's `slot` is where the route component hangs: swapped by navigation,
  593. // never painted (the compile step already drops `Style`, folded at build)
  594. if (!(name == 'slot' && m.isShell)) { keep.push(name) }
  595. }
  596. if (valueMember != null && rows[valueMember] == null && el.value != null) {
  597. bindValue(&m, valueMember, el, isSelect)
  598. }
  599. if (keep.length > 0) { m.sites.push({ sid = nextSid(); el = el; site = site; names = keep; region = false; rows = rows; }) }
  600. return null
  601. }
  602. applySelectAt(&m, el, v) {
  603. el.value = v == null ? '' : '' + v
  604. return null
  605. }
  606. // A HANDLER, WIRED AT CREATION. The literal is the element's own — its named entries
  607. // are the generated `__hlLit`, the `for` rows in scope ride on it, and the owner is the
  608. // instance BY REFERENCE (a handler writing a copy would repaint nothing).
  609. onAt(&m, el, event, site, rows, wrote, touched) {
  610. if (el.__hlLits == null) { el.__hlLits = {} }
  611. el.__hlLits[event] = literalFor(&m, el)
  612. let at = m.chain
  613. let root = m.rootKind
  614. let rowNames = rows == null ? [] : rows.keys()
  615. el.addEventListener(event, (ev) => {
  616. // THE DEFAULT ACTION OF `submit` IS A PAGE NAVIGATION (COMPONENTS.md §6b), so the
  617. // framework suppresses it itself — a handler declared with no parameter has no
  618. // `ev` to call `preventDefault()` on, and one declared with it may call it again,
  619. // harmlessly. This is the FIRST statement, unawaited, for the same reason `onClick`
  620. // claims a link before anything else: called after an `await`, it lands a
  621. // microtask late, once the browser already navigated (mission 132 / ticket submit).
  622. if (event == 'submit') { ev.preventDefault() }
  623. let lit = el.__hlLits[event]
  624. for (rk of rowNames) { lit[rk] = el.__hlRows[rk] }
  625. fire(&lit, event, ev)
  626. el.__hlLits[event] = lit
  627. patch(at, root, wrote, touched)
  628. })
  629. return null
  630. }
  631. // THE SHELL'S SLOT: where the route component hangs. On the build walk the re-created
  632. // element adopts the page's nodes, and a page the shell never rendered is built here.
  633. slotShell(&m, host, i, cr) {
  634. // A PARENT LEVEL BELOW THE SHELL (#194): this level's slot holds the next parent level,
  635. // kid '^' (the page stands in the innermost level's slot). It leaves no mark of its own.
  636. let inner = m.kids['^']
  637. // A SLOT THAT OPENS LATER (#194): the levels below this one were never built (the shell's
  638. // slot stood closed when the document was made). The answer for the route brings the
  639. // page AND every level between, so the level below this one is built from it now
  640. if (inner == null && cr && !pageShown && page == null) {
  641. page = arrive()
  642. if (lateInner != null) {
  643. m.kids['^'] = instantiate(lateInner, childChain(m.chain, '^'), m.rootKind)
  644. if (m.chain.length == 0 && seed.shell != null) { seed.shell.kids['^'] = lateInner }
  645. lateInner = null
  646. inner = m.kids['^']
  647. }
  648. }
  649. if (inner != null) {
  650. inner.chain = childChain(m.chain, '^')
  651. inner.rootKind = m.rootKind
  652. if (cr) { inner.sites = [] }
  653. let f = walkOf(inner.key, 'v', null)
  654. let out = run(f, &inner, &m, host, cr ? 0 : i, {}, '', null, cr, null)
  655. if (!cr) { i = out }
  656. if (cr || inner.bindings.length == 0) { inner.bindings = [] bindKids(&inner, inner.view) }
  657. m.kids['^'] = inner
  658. return i
  659. }
  660. slotEl = host
  661. if (!cr) {
  662. // claiming: the page's elements stand here, and the shell's own elements after
  663. // the slot come after them
  664. slotAt = i
  665. if (seed.page == null) { return i }
  666. // the page's region: its marks, and the elements between them the shell steps over
  667. slotStart = markAt(host, false, true)
  668. slotStart.__hlEnd = closeOf(slotStart)
  669. host.__hlCur = slotStart.__hlEnd
  670. let span = 0
  671. for (n of between(slotStart)) { if (n.nodeType == 1) { span = span + 1 } }
  672. return i + span
  673. }
  674. slotAt = host.children.length
  675. let start = markAt(host, true, true)
  676. if (detachedSlot != null && detachedSlot != host) {
  677. // the page's own nodes: what stood between its marks, or all of the old host's
  678. let moving = standing(detachedSlot, slotStart) ? between(slotStart) : Array.from(detachedSlot.childNodes)
  679. for (node of moving) { host.appendChild(node) }
  680. }
  681. detachedSlot = null
  682. if (!pageShown) {
  683. // THE PAGE ARRIVES WITH ITS SLOT: it was never constructed while the shell
  684. // placed none, so it is asked for now — the route's state, from the server
  685. if (page == null) { page = arrive() }
  686. if (page != null) {
  687. page.sites = []
  688. create(&page, host)
  689. headSites(&page)
  690. wearHead(&page)
  691. pageShown = true
  692. placeRegions(false)
  693. }
  694. }
  695. start.__hlEnd = markAt(host, true, false)
  696. slotStart = start
  697. return i
  698. }
  699. // THE ROUTE'S PAGE, for a slot that just opened: the navigation face answers it for
  700. // this path, told the slot stands here, and the mount is constructed from that. The
  701. // frames it raises wait until the rebuild that placed it is done (pageArrived).
  702. arrive() {
  703. // the answer carries the values table (#180) like a navigation's: resolved before anything reads it
  704. let next = resolveValues(emit server page(location.pathname + location.search, true))
  705. if (next == null || next.page == null) { return null }
  706. takeBlueprints(next.blueprints)
  707. seed.page = next.page
  708. lateInner = next.shell != null ? next.shell.kids['^'] : null
  709. mounting = true
  710. pageArrived = true
  711. return instantiate(next.page, [], 'page')
  712. }
  713. // THE SLOT CLOSED: the page is dropped, not kept aside — the next time the slot opens
  714. // it is constructed again. The head falls back to the app's own.
  715. dropPage() {
  716. slotEl = null
  717. pageShown = false
  718. page = null
  719. purgeMounts([], 'page')
  720. slotStart = null
  721. seed.page = null
  722. let none = { instance = {}; }
  723. wearHead(&none)
  724. announceMounts()
  725. return null
  726. }
  727. // a rebuild that constructed the page: what waited for it goes out, and the server
  728. // learns the tab mounts it
  729. arrived() {
  730. if (!pageArrived) { return null }
  731. pageArrived = false
  732. release()
  733. announceMounts()
  734. return null
  735. }
  736. // A CHILD'S SLOT: the fragment its HOST wrote, built in the host's frame. The fill names
  737. // that frame by address, and `run` re-enters it when this walk is not it.
  738. slotFill(&m, &o, host, i, fill, cr) {
  739. if (fill == null) { return i }
  740. if (cr && fill.detached) {
  741. let anchor = document.createComment('hl:slot')
  742. host.appendChild(anchor)
  743. pendingFills[] = { key = fill.key; site = fill.site; rows = fill.rows; rowKey = fill.rowKey; outer = fill.outer; chain = fill.chain; rootKind = fill.rootKind; anchor = anchor; }
  744. return i
  745. }
  746. if (ownsFill(o, fill)) {
  747. let f = walkOf(fill.key, 'f', fill.site)
  748. return run(f, &o, &o, host, i, fill.rows, fill.rowKey, fill.outer, cr, null)
  749. }
  750. return fillFromRoot(fill, host, i, cr)
  751. }
  752. // ---- NAMED REGIONS (D-CHAIN addendum) -------------------------------------------------
  753. // A level above declares `slot { name = 'side' … }`: a region between two marks, holding its
  754. // default (built in the declaring level's frame, walk 'd') or the fill a lower level wrote at its
  755. // View root (`side { … }`, built in THAT level's frame, walk 'r'). The region element stands; a
  756. // navigation rebuilds only what stands between the marks.
  757. namedRegionAt(&m, &o, host, i, site, name, rows, rk, fill, cr) {
  758. let desc = { key = m.key; site = site; rows = rows; rowKey = rk; outer = fill; chain = m.chain; rootKind = m.rootKind; slot = 'd'; }
  759. if (!cr) {
  760. // claiming: the region's marks are taken and its content is claimed once the page is (boot)
  761. let start = markAt(host, false, true)
  762. start.__hlEnd = closeOf(start)
  763. host.__hlCur = start.__hlEnd
  764. let span = 0
  765. for (n of between(start)) { if (n.nodeType == 1) { span = span + 1 } }
  766. regionTable[name] = { host = host; start = start; at = i; base = desc; desc = desc; kind = null; }
  767. return i + span
  768. }
  769. let start = markAt(host, true, true)
  770. start.__hlEnd = mark(false)
  771. host.appendChild(start.__hlEnd)
  772. let fd = fillerOf(name)
  773. // (a hybrid read off a table is a copy: the entry is written whole, never through a read of it)
  774. regionTable[name] = { host = host; start = start; at = 0; base = desc; desc = fd == null ? desc : fd; kind = fd == null ? 'd' : 'r'; }
  775. if (fd != null) {
  776. fillFromRoot(fd, host, 0, true)
  777. } else {
  778. run(walkOf(m.key, 'd', site), &m, &o, host, 0, rows, rk, fill, true, null)
  779. }
  780. // built in place before the close mark (the walk appended after it)
  781. host.appendChild(start.__hlEnd)
  782. return i
  783. }
  784. // the level below the declaring one that fills region `name`: the page first, then the levels
  785. // from the innermost out. A descriptor naming the filler's frame, or null (the default stands).
  786. fillerOf(name) {
  787. let cands = []
  788. if (page != null) { cands.push(page) }
  789. let lv = []
  790. let x = shell
  791. while (x != null && lv.length < 64) { lv.push(x) x = x.kids == null ? null : x.kids['^'] }
  792. let k = lv.length - 1
  793. while (k > 0) { cands.push(lv[k]) k = k - 1 }
  794. for (c of cands) {
  795. let site = regionFillSite(c.key, name)
  796. if (site != null) { return { key = c.key; site = site; rows = {}; rowKey = ''; outer = null; chain = c.chain; rootKind = c.rootKind; slot = 'r'; } }
  797. }
  798. return null
  799. }
  800. regionFillSite(key, name) {
  801. if (window.__hlC == null || window.__hlC[key] == null || window.__hlC[key].rn == null) { return null }
  802. return window.__hlC[key].rn[name]
  803. }
  804. // every named region takes what its level or the filler below it holds: after a page is claimed
  805. // (boot, `claim` true: the server's nodes are taken) or placed (navigation: rebuilt)
  806. placeRegions(claimIt) {
  807. if (!claimIt) {
  808. for (name of regionTable.keys()) { placeRegion(name, false) }
  809. return null
  810. }
  811. // claiming a region's default may claim regions inside it (their marks are taken on the way and
  812. // their content waits): pass again until every one that stands has its content
  813. let pass = 0
  814. let pending = true
  815. while (pending && pass < 16) {
  816. pending = false
  817. pass = pass + 1
  818. for (name of regionTable.keys()) {
  819. let r = regionTable[name]
  820. if (r.kind == null && standing(r.host, r.start)) { pending = true placeRegion(name, true) }
  821. }
  822. }
  823. return null
  824. }
  825. placeRegion(name, claimIt) {
  826. let r = regionTable[name]
  827. if (r == null || !standing(r.host, r.start)) { return null }
  828. let fd = fillerOf(name)
  829. let want = fd == null ? 'd' : 'r'
  830. if (claimIt) {
  831. let d = fd == null ? r.base : fd
  832. regionTable[name].kind = want
  833. regionTable[name].desc = d
  834. r.host.__hlCur = r.start
  835. regionClaim(d, r.host, r.at)
  836. return null
  837. }
  838. // the default stands and stays the default: its state and its nodes are not rebuilt
  839. if (want == 'd' && r.kind == 'd') { return null }
  840. let old = between(r.start)
  841. let owner = r.desc
  842. if (owner.rootKind == 'shell' || owner.slot == 'd') { regionDrop(owner, r.host, old) }
  843. for (n of old) { n.remove() }
  844. let d = fd == null ? r.base : fd
  845. regionTable[name].desc = d
  846. regionTable[name].kind = want
  847. regionBuild(d, r.host, r.start.__hlEnd)
  848. return null
  849. }
  850. // claims the server's nodes of a region's content, in the frame its descriptor names
  851. regionClaim(d, host, at) {
  852. fillFromRoot(d, host, at, false)
  853. return null
  854. }
  855. // builds a region's content in a fragment and puts it before the close mark; the sites the walk
  856. // registered on the fragment belong to the region's host (as `placePage` does)
  857. regionBuild(d, host, closeMark) {
  858. let frag = document.createDocumentFragment()
  859. let before = sidNext
  860. fillFromRoot(d, frag, 0, true)
  861. host.insertBefore(frag, closeMark)
  862. regionRehome(d, frag, host, before)
  863. return null
  864. }
  865. regionRehome(d, frag, host, before) {
  866. if (d.rootKind == 'shell') { if (shell != null) { regionRehomeAt(&shell, d, 0, frag, host, before) } }
  867. else if (page != null) { regionRehomeAt(&page, d, 0, frag, host, before) }
  868. return null
  869. }
  870. regionRehomeAt(&m, d, depth, frag, host, before) {
  871. if (depth >= d.chain.length) { rehome(&m, frag, host, before) return null }
  872. if (m.kids[d.chain[depth]] == null) { return null }
  873. regionRehomeAt(&m.kids[d.chain[depth]], d, depth + 1, frag, host, before)
  874. return null
  875. }
  876. // the sites of the nodes that leave belong to the frame that built them
  877. regionDrop(d, host, nodes) {
  878. if (d.rootKind == 'shell') { if (shell != null) { regionDropAt(&shell, d, 0, host, nodes) } }
  879. else if (page != null) { regionDropAt(&page, d, 0, host, nodes) }
  880. return null
  881. }
  882. regionDropAt(&m, d, depth, host, nodes) {
  883. if (depth >= d.chain.length) { dropSitesIn(&m, host, nodes) return null }
  884. if (m.kids[d.chain[depth]] == null) { return null }
  885. regionDropAt(&m.kids[d.chain[depth]], d, depth + 1, host, nodes)
  886. return null
  887. }
  888. // the fill's owner, re-entered from the page or the shell by the address it carries
  889. fillFromRoot(fill, host, at, cr) {
  890. if (fill.rootKind == 'shell') {
  891. if (shell == null) { return at }
  892. return fillInto(&shell, fill, 0, host, at, cr)
  893. }
  894. if (page == null) { return at }
  895. return fillInto(&page, fill, 0, host, at, cr)
  896. }
  897. fillInto(&m, fill, depth, host, at, cr) {
  898. if (depth >= fill.chain.length) {
  899. let f = walkOf(fill.key, fill.slot == null ? 'f' : fill.slot, fill.site)
  900. return run(f, &m, &m, host, at, fill.rows, fill.rowKey, fill.outer, cr, null)
  901. }
  902. if (m.kids[fill.chain[depth]] == null) { return at }
  903. return fillInto(&m.kids[fill.chain[depth]], fill, depth + 1, host, at, cr)
  904. }
  905. // the fill context a reference hands its child: the fragment's owner by address, the
  906. // host's rows and rowKey, and the fill the host itself was standing in
  907. fillFor(&m, spec, rows, rowKey, fill) {
  908. if (!spec.fill) { return null }
  909. return { key = m.key; site = spec.site; rows = rows; rowKey = rowKey; outer = fill; chain = m.chain; rootKind = m.rootKind; detached = false; }
  910. }
  911. // ---- THE MARKS: every region stands between two comments ---------------------------
  912. // THE INVARIANT (tickets #103, #104). Every region — an `if`, a `for`, each row of a
  913. // `for`, the shell's page — stands on its host between an OPEN mark (a comment `[`)
  914. // and a CLOSE mark (`]`), and ITS NODES ARE EXACTLY THE NODES BETWEEN THEM. A region
  915. // inside another one on the same host stands between the outer one's marks. So:
  916. // - a region's nodes are never remembered, they are read off the DOM between its
  917. // marks when they are needed — whatever a region inside it did since, they are
  918. // right (a list taken when the branch was built went stale, #103);
  919. // - a region is replaced by removing what stands between its marks and putting the
  920. // new nodes before its close mark; a row moves and leaves WITH its marks, so a row
  921. // is always whole and in its list;
  922. // - nothing outside a region is touched by it, and nothing inside it outlives it: the
  923. // sites registered in the nodes it drops are dropped with them, and a region whose
  924. // marks have left its host has nothing to paint.
  925. // The server writes the same marks (compile.hl `markOpen`), the claim walk takes them in
  926. // document order and the build walk makes them, so a region looks the same however it
  927. // came to stand — and text beside a region never runs into the region's own text.
  928. mark(open) { return document.createComment(open ? '[' : ']') }
  929. isMark(n) { return n != null && n.nodeType == 8 && (n.data == '[' || n.data == ']') }
  930. // the nodes strictly between a region's marks
  931. between(start) {
  932. let out = []
  933. let end = start.__hlEnd
  934. let n = start.nextSibling
  935. while (n != null && n != end) { out.push(n) n = n.nextSibling }
  936. return out
  937. }
  938. // …and with the marks themselves: a row as it moves or leaves
  939. spanOf(start) {
  940. let out = [start]
  941. for (n of between(start)) { out.push(n) }
  942. out.push(start.__hlEnd)
  943. return out
  944. }
  945. // a region stands while both its marks are on its host
  946. standing(host, start) {
  947. return start != null && start.parentNode == host && start.__hlEnd != null && start.__hlEnd.parentNode == host
  948. }
  949. // A REGION'S MARK, made (building) or taken (claiming). The claim takes the next mark
  950. // after the host's cursor: the walk meets the regions in document order, so it is this
  951. // region's. A page whose marks do not match its tree is said so, and gets a mark where
  952. // the walk stands.
  953. markAt(host, cr, open) {
  954. if (cr) {
  955. let made = mark(open)
  956. host.appendChild(made)
  957. return made
  958. }
  959. let n = host.__hlCur == null ? host.firstChild : host.__hlCur.nextSibling
  960. while (n != null && !isMark(n)) { n = n.nextSibling }
  961. let mk = null
  962. if (n != null && n.data == (open ? '[' : ']')) { mk = n }
  963. else {
  964. console.error('claim: no region mark under', host.tagName)
  965. mk = mark(open)
  966. host.insertBefore(mk, host.__hlCur == null ? host.firstChild : host.__hlCur.nextSibling)
  967. }
  968. host.__hlCur = mk
  969. return mk
  970. }
  971. // the close mark that pairs with an open one, past the regions inside it
  972. closeOf(start) {
  973. let depth = 0
  974. let n = start.nextSibling
  975. while (n != null) {
  976. if (isMark(n)) {
  977. if (n.data == '[') { depth = depth + 1 }
  978. else if (depth == 0) { return n }
  979. else { depth = depth - 1 }
  980. }
  981. n = n.nextSibling
  982. }
  983. let made = mark(false)
  984. start.parentNode.appendChild(made)
  985. return made
  986. }
  987. // THE SITES IN NODES THAT LEAVE go with them: an element's, a text leaf's, and a
  988. // region's whose open mark is among them. Marked and walked up once per site.
  989. //
  990. // NO CALL BETWEEN READING THE LIST AND WRITING IT BACK. Every call in this language is
  991. // awaited, and an await lets another repaint run — one that registers sites of its
  992. // own, which a list read before it and written after it would lose. The loops that
  993. // read `m.sites` and write it back hold property reads, index writes and `[] =` only.
  994. dropSitesIn(&m, host, nodes) {
  995. if (nodes.length == 0) { return null }
  996. for (n of nodes) { n.__hlGone = true }
  997. let kept = []
  998. let dropped = 0
  999. for (site of m.sites) {
  1000. let n = (site.region && site.el == host && site.start != null) ? site.start : site.el
  1001. let gone = false
  1002. while (n != null && n != host && !gone) {
  1003. if (n.__hlGone == true) { gone = true }
  1004. n = n.parentNode
  1005. }
  1006. if (gone) { dropped = dropped + 1 } else { kept[] = site }
  1007. }
  1008. if (dropped > 0) {
  1009. m.sites = kept
  1010. dropGen = dropGen + 1
  1011. }
  1012. for (n of nodes) { n.__hlGone = null }
  1013. return null
  1014. }
  1015. // THE SITES A WALK REGISTERED ON THE FRAGMENT IT BUILT INTO belong to the host it lands
  1016. // in — this mount's, and those of the children composed straight onto the fragment,
  1017. // whose own regions (a child's View may begin with an `if`) stand on the same host.
  1018. // Those children are named by address on the fragment as the walk composes them
  1019. // (kidAt, `__hlOnFrag`), so only they are re-entered.
  1020. rehome(&m, src, dst, before) {
  1021. sitesOnto(&m, src, dst, before)
  1022. let due = src.__hlOnFrag == null ? [] : src.__hlOnFrag
  1023. src.__hlOnFrag = null
  1024. let base = m.chain == null ? 0 : m.chain.length
  1025. for (chain of due) {
  1026. if (chain.length > base) { rehomeAt(&m, chain, base, src, dst) }
  1027. }
  1028. return null
  1029. }
  1030. // (`after`: the sites numbered after it are the walk's — an index would move when
  1031. // another repaint drops sites in the meantime)
  1032. sitesOnto(&m, src, dst, after) {
  1033. // sids only grow along m.sites, so the walk's sites are its tail: read it from the end
  1034. // and stop at the first older one (a scan of every site per row built was O(rows x sites))
  1035. let k = m.sites.length - 1
  1036. while (k >= 0 && m.sites[k].sid > after) {
  1037. if (m.sites[k].el == src) { m.sites[k].el = dst }
  1038. k = k - 1
  1039. }
  1040. return null
  1041. }
  1042. rehomeAt(&m, chain, depth, src, dst) {
  1043. if (depth >= chain.length) { sitesOnto(&m, src, dst, 0) return null }
  1044. if (m.kids[chain[depth]] == null) { return null }
  1045. rehomeAt(&m.kids[chain[depth]], chain, depth + 1, src, dst)
  1046. return null
  1047. }
  1048. // A RANGE LEAVES THE PAGE — a branch, a row: every site registered in it goes (at any
  1049. // depth: an element's, a text's, a region's whose marks are in it), and so does every
  1050. // child composed in it (its nodes carry its address), with its own sites, its children
  1051. // and its handlers.
  1052. // A range can hold a FILL — a host's fragment placed at this component's `slot` — whose
  1053. // sites and children are the host's: `fill` names that host (and the one it was filled
  1054. // by in turn), and those go in settle(), where a host is re-entered by its address after
  1055. // every mount on this walk has been written back.
  1056. dropRange(&m, host, nodes, fill) {
  1057. dropSitesIn(&m, host, nodes)
  1058. let others = disposeIn(&m, nodes)
  1059. let f = fill
  1060. while (f != null) {
  1061. pendingDrops.push({ chain = f.chain; rootKind = f.rootKind; host = host; nodes = nodes; kids = others; })
  1062. others = []
  1063. f = f.outer
  1064. }
  1065. return null
  1066. }
  1067. // THE CHILDREN COMPOSED IN NODES go: those of this mount at once, and the others (a
  1068. // host's, composed in its fill) are answered for the caller to hand on
  1069. disposeIn(&m, nodes) {
  1070. let chains = []
  1071. for (n of nodes) { kidsFiledIn(n, &chains) }
  1072. let base = m.chain == null ? [] : m.chain
  1073. let others = []
  1074. for (c of chains) {
  1075. // (a range inside a child never takes the child itself, nor a mount above it: the
  1076. // child's own nodes carry its address, a region of its own among them)
  1077. let above = c.length <= base.length && JSON.stringify(base.slice(0, c.length)) == JSON.stringify(c)
  1078. if (!above) {
  1079. if (c.length > base.length && JSON.stringify(c.slice(0, base.length)) == JSON.stringify(base)) { disposeAt(&m, c, base.length) }
  1080. else { others.push(c) }
  1081. }
  1082. }
  1083. return others
  1084. }
  1085. // the ranges a fill's host still has to let go of (see dropRange)
  1086. dropPending() {
  1087. if (pendingDrops.length == 0) { return null }
  1088. let due = pendingDrops.slice(0)
  1089. pendingDrops = []
  1090. for (d of due) {
  1091. if (d.rootKind == 'shell') {
  1092. if (shell != null) { dropAt(&shell, d, 0) }
  1093. } else if (page != null) { dropAt(&page, d, 0) }
  1094. }
  1095. return null
  1096. }
  1097. dropAt(&m, d, depth) {
  1098. if (depth >= d.chain.length) {
  1099. dropSitesIn(&m, d.host, d.nodes)
  1100. for (c of d.kids) { if (c.length > depth) { disposeAt(&m, c, depth) } }
  1101. return null
  1102. }
  1103. if (m.kids[d.chain[depth]] == null) { return null }
  1104. dropAt(&m.kids[d.chain[depth]], d, depth + 1)
  1105. return null
  1106. }
  1107. // a node in a range whose host's sites are still to go (dropPending)
  1108. dropDue(n) {
  1109. let top = n.getRootNode()
  1110. for (d of pendingDrops) { if (d.nodes.includes(top)) { return true } }
  1111. return false
  1112. }
  1113. // the children whose nodes are this node or stand under it (kidAt files them there)
  1114. kidsFiledIn(n, &out) {
  1115. if (n.__hlKidChains != null) { for (c of n.__hlKidChains) { out.push(c) } }
  1116. if (n.nodeType != 1) { return null }
  1117. let w = document.createTreeWalker(n, 4294967295)
  1118. let c = w.nextNode()
  1119. while (c != null) {
  1120. if (c.__hlKidChains != null) { for (k of c.__hlKidChains) { out.push(k) } }
  1121. c = w.nextNode()
  1122. }
  1123. return null
  1124. }
  1125. disposeAt(&m, chain, depth) {
  1126. if (depth == chain.length - 1) {
  1127. if (m.kids[chain[depth]] != null) {
  1128. purgeMounts(chain, m.rootKind)
  1129. delete m.kids[chain[depth]]
  1130. }
  1131. return null
  1132. }
  1133. if (m.kids[chain[depth]] == null) { return null }
  1134. disposeAt(&m.kids[chain[depth]], chain, depth + 1)
  1135. return null
  1136. }
  1137. // a node no longer on the page: not in the document, not in a fragment a walk is
  1138. // still building, not in the slot a shell's rebuild holds aside
  1139. placedOff(n) {
  1140. if (n.isConnected) { return false }
  1141. if (n.getRootNode().nodeType == 11) { return false }
  1142. if (detachedSlot != null && detachedSlot.contains(n)) { return false }
  1143. return true
  1144. }
  1145. nextSid() {
  1146. sidNext = sidNext + 1
  1147. return sidNext
  1148. }
  1149. isLive(&m, s) {
  1150. for (e of m.sites) { if (e.sid == s.sid) { return true } }
  1151. return false
  1152. }
  1153. liveSids(&m) {
  1154. let out = {}
  1155. for (e of m.sites) { out[e.sid] = true }
  1156. return out
  1157. }
  1158. // A SITE WHOSE NODES LEFT THE PAGE, found by a repaint. Every range that leaves takes
  1159. // its sites with it (dropRange), so this is a bug: the gates' client raises it as an
  1160. // uncaught exception (the page's error event, what every gate fails on), a page in the
  1161. // field says so on the console; neither paints it.
  1162. staleSite(s) {
  1163. let msg = 'hl:web: a repaint found a site whose nodes have left the page (site ' + s.site + ')'
  1164. if (strict) { window.reportError(window.Reflect.construct(window.Error, [msg])) }
  1165. else { console.error(msg) }
  1166. return null
  1167. }
  1168. // A RUN OF TEXT LEAVES BESIDE ELEMENTS OR REGIONS (compile.hl `mixed`): one text node,
  1169. // kept on the element under the run's index so a paint rewrites it and nothing else.
  1170. // `k` null is a text the walk only has to step over (literal, or painted as a site of
  1171. // its own by `textAt`). Built, it is appended. Claimed, it is the text node right
  1172. // after the host's cursor — the last node the walk took there — which the server may
  1173. // have run together with the readable form's line break after it, so it is split off
  1174. // by the value it has now. A run that rendered empty has no node and gets one.
  1175. leafAt(host, cr, i, k, text) {
  1176. let t = leafNode(host, cr, text)
  1177. if (k != null) {
  1178. if (host.__hlLeaves == null) { host.__hlLeaves = {} }
  1179. host.__hlLeaves[k] = t
  1180. }
  1181. return null
  1182. }
  1183. leafNode(host, cr, text) {
  1184. let t = null
  1185. if (cr) {
  1186. t = document.createTextNode(text)
  1187. host.appendChild(t)
  1188. return t
  1189. }
  1190. let at = host.__hlCur == null ? host.firstChild : host.__hlCur.nextSibling
  1191. if (at != null && at.nodeType == 3 && text != '') {
  1192. if (at.data == text) { t = at }
  1193. else if (at.data.startsWith(text)) { at.splitText(text.length) t = at }
  1194. else {
  1195. // a line break of the readable form in front of it (a filled slot's line)
  1196. let lead = at.data.length - at.data.trimStart().length
  1197. if (lead > 0 && at.data.startsWith(View.newline) && at.data.slice(lead).startsWith(text)) {
  1198. t = at.splitText(lead)
  1199. if (t.data != text) { t.splitText(text.length) }
  1200. }
  1201. }
  1202. }
  1203. if (t == null) {
  1204. t = document.createTextNode(text)
  1205. host.insertBefore(t, at)
  1206. }
  1207. host.__hlCur = t
  1208. return t
  1209. }
  1210. // A TEXT LEAF STANDING IN A LIST (an `if` branch, a `for` body): its own text node, and
  1211. // a site of the member it reads — or of the row it stands in — painted by rewriting it.
  1212. textAt(&m, host, cr, readFn, names, rows, rk) {
  1213. let inst = m.instance
  1214. let t = leafNode(host, cr, readFn(&inst, &rows))
  1215. if (names.length > 0 || (rk != null && rk != '')) {
  1216. m.sites.push({ sid = nextSid(); el = t; site = null; names = names; region = false; text = true; rows = rows; rowKey = rk; read = readFn; })
  1217. }
  1218. return null
  1219. }
  1220. paintText(&m, &s) {
  1221. let f = s.read
  1222. let v = f(&m.instance, &s.rows)
  1223. let t = s.el
  1224. if (t.data != v) { t.data = v }
  1225. return null
  1226. }
  1227. // ---- a `for`: the region, its rows, each between its marks -------------------------
  1228. forAt(&m, &o, host, i, site, rowName, listFn, rows, rk, fill, cr, names) {
  1229. let start = markAt(host, cr, true)
  1230. regionAt(&m, host, site, rows, rk, fill, true, rowName, listFn, names, start)
  1231. let box = { keys = []; rows = {}; }
  1232. let entries = listFn(&m.instance, &rows)
  1233. let body = walkOf(m.key, 'b', site)
  1234. if (entries != null) {
  1235. let keys = listKeys(&entries)
  1236. let ri = 0
  1237. for (entry of entries) {
  1238. let inner = rows + {}
  1239. inner[rowName] = entry
  1240. let rs = markAt(host, cr, true)
  1241. let out = run(body, &m, &o, host, cr ? 0 : i, inner, rk + '#' + keys[ri], fill, cr, null)
  1242. if (!cr) { i = out }
  1243. rs.__hlEnd = markAt(host, cr, false)
  1244. box.keys.push(keys[ri])
  1245. box.rows[keys[ri]] = { start = rs; entry = entry; }
  1246. ri = ri + 1
  1247. }
  1248. }
  1249. start.__hlEnd = markAt(host, cr, false)
  1250. start.__hlBox = box
  1251. return i
  1252. }
  1253. // an `if`: the branch that stands, between its marks
  1254. ifAt(&m, &o, host, i, site, condFn, rows, rk, fill, cr, names) {
  1255. let start = markAt(host, cr, true)
  1256. regionAt(&m, host, site, rows, rk, fill, false, null, condFn, names, start)
  1257. let side = condFn(&m.instance, &rows) ? 't' : 'e'
  1258. start.__hlSide = side
  1259. let out = run(walkOf(m.key, side, site), &m, &o, host, i, rows, rk, fill, cr, null)
  1260. start.__hlEnd = markAt(host, cr, false)
  1261. return out
  1262. }
  1263. // A REGION SITE carries what the patch needs and nothing else: the names its list or
  1264. // its condition reads (the compiler's answer, by this site), the read itself as the
  1265. // generated closure, and its open mark — the region itself, one per row it stands in.
  1266. regionAt(&m, host, site, rows, rowKey, fill, isFor, rowName, readFn, names, start) {
  1267. // a row-scoped read is its row's, and the language resolved it as one, so the
  1268. // compile step names none here: an empty set is a region no member can move. INSIDE
  1269. // A ROW it is still registered, with no names: the row's new record moves it
  1270. // (reseatRows, ticket #86). Outside one nothing ever can.
  1271. if (names == null) { names = [] }
  1272. if (names.length == 0 && (rowKey == null || rowKey == '')) { return null }
  1273. let held = null
  1274. if (fill != null) { held = fill + {} held.detached = true }
  1275. m.sites.push({ sid = nextSid(); el = host; site = site; names = names; region = true; rows = rows; rowKey = rowKey; fill = held; isFor = isFor; row = rowName; read = readFn; start = start; })
  1276. return null
  1277. }
  1278. // ---- a composed child --------------------------------------------------------------
  1279. // The reference's own description is written at its use site by the compile step: what
  1280. // it binds, what it overwrites, the classes it puts on the child's roots.
  1281. kidAt(&m, host, i, spec, rows, rk, fill, cr, opt) {
  1282. let kk = spec.kid + rk
  1283. if (m.kids[kk] == null) {
  1284. let minted = mintFrom(&m, spec, rows, childChain(m.chain, kk))
  1285. if (minted == null) { return i }
  1286. m.kids[kk] = minted
  1287. }
  1288. bindFrom(&m.kids[kk], &m, spec, rows)
  1289. if (cr) { m.kids[kk].sites = [] }
  1290. m.kids[kk].chain = childChain(m.chain, kk)
  1291. m.kids[kk].rootKind = m.rootKind
  1292. let firstAt = cr ? host.children.length : i
  1293. // WHAT A REFERENCE OVERWRITES REACHES THE FIRST ELEMENT, however deep. A child
  1294. // whose View is a bare reference to another component renders no element of its
  1295. // own, so the events the host overwrote travel on through it — the old hl:web kept that in
  1296. // a field that the first element consumes; here it rides on the option the walk is
  1297. // handed, and a reference with ons of its own replaces it.
  1298. let over = []
  1299. if (spec.ons != null && spec.ons.length > 0) { for (o of spec.ons) { over.push(o.event) } }
  1300. else if (opt != null && opt.over != null) { over = opt.over }
  1301. let kidOpt = { over = over; classes = spec.classes; }
  1302. let f = walkOf(m.kids[kk].key, 'v', null)
  1303. // a child composed straight onto a fragment has its regions on the host the fragment
  1304. // lands in: the fragment names it, for the re-homing (rehome)
  1305. if (cr && host.nodeType == 11) {
  1306. let onFrag = host.__hlOnFrag == null ? [] : host.__hlOnFrag
  1307. onFrag.push(m.kids[kk].chain)
  1308. host.__hlOnFrag = onFrag
  1309. }
  1310. let nodesBefore = host.childNodes.length
  1311. let curBefore = host.__hlCur
  1312. let out = run(f, &m.kids[kk], &m, host, cr ? 0 : i, {}, '', fillFor(&m, spec, rows, rk, fill), cr, kidOpt)
  1313. if (!cr) { i = out }
  1314. // THE NODES THE CHILD PUT ON ITS HOST CARRY ITS ADDRESS: when a range holding them
  1315. // leaves the page, the child goes with it (dropRange)
  1316. let made = []
  1317. if (cr) {
  1318. let k = nodesBefore
  1319. while (k < host.childNodes.length) { made.push(host.childNodes[k]) k = k + 1 }
  1320. } else {
  1321. let n = curBefore == null ? host.firstChild : curBefore.nextSibling
  1322. let stop = host.__hlCur == null ? null : host.__hlCur.nextSibling
  1323. while (n != null && n != stop) { made.push(n) n = n.nextSibling }
  1324. }
  1325. for (n of made) {
  1326. let filed = n.__hlKidChains == null ? [] : n.__hlKidChains
  1327. filed.push(m.kids[kk].chain)
  1328. n.__hlKidChains = filed
  1329. }
  1330. if (cr || m.kids[kk].bindings.length == 0) { m.kids[kk].bindings = [] bindKids(&m.kids[kk], m.kids[kk].view) }
  1331. let roots = rootsBetween(host, firstAt, cr ? host.children.length : i)
  1332. refOnsFrom(&m, spec, roots, rows)
  1333. for (el of roots) { el.__hlKid = true }
  1334. return i
  1335. }
  1336. // the value a binding of this reference carries, off the host instance
  1337. specValue(b, &m, rows) {
  1338. if (b.text != null) { return b.value }
  1339. if (b.member != null) { return view.value({ k = 'member'; name = b.member; }, m.instance, rows) }
  1340. if (b.ref != null) {
  1341. let inst = m.instance
  1342. let f = b.ref
  1343. return f(&inst, &rows)
  1344. }
  1345. return null
  1346. }
  1347. // A CHILD A REGION BUILDS is born with its address: the host's chain and its own key.
  1348. // Every patch, and every late patch a function or a waiting handler of it asks for, is
  1349. // filed and cancelled by that address (tickets #98, #99).
  1350. mintFrom(&m, spec, rows, chain) {
  1351. let bp = blueprintOf(spec.key)
  1352. if (bp == null) { return null }
  1353. let args = {}
  1354. for (b of spec.bindings) { args[b.name] = specValue(b, &m, rows) }
  1355. let inst = hlLoad(bp.module, args)
  1356. registerMount(inst, spec.key, chain, m.rootKind)
  1357. return { key = spec.key; instance = inst; view = bp.view; sites = []; isShell = false; kids = {}; bindings = []; chain = chain; rootKind = m.rootKind; }
  1358. }
  1359. bindFrom(&kid, &m, spec, rows) {
  1360. for (b of spec.bindings) { kid.instance[b.name] = specValue(b, &m, rows) }
  1361. return null
  1362. }
  1363. // A HANDLER WRITTEN ON A REFERENCE is the HOST's: its literal is minted here with the
  1364. // reference's bindings as its own entries, and its write set is filed under the
  1365. // reference's own `on` site in the host's table.
  1366. refOnsFrom(&m, spec, els, rows) {
  1367. if (spec.ons == null || spec.ons.length == 0) { return null }
  1368. let named = {}
  1369. for (b of spec.bindings) { named[b.name] = specValue(b, &m, rows) }
  1370. for (k of rows.keys()) { named[k] = rows[k] }
  1371. let inst = m.instance
  1372. let lit = hlLiteralNew(spec.site, named, &inst)
  1373. for (el of els) {
  1374. for (o of spec.ons) { listenRef(&m, &lit, el, o) }
  1375. }
  1376. return null
  1377. }
  1378. // ---- claim: walk the tree in lockstep with the DOM the same tree produced --------
  1379. // Round one granularity: an element whose children include a member is a SITE for
  1380. // each of those members; a repaint rewrites that element's children from the tree.
  1381. // `i` is the running index into `host.children`; a `for` consumes one run of
  1382. // elements per entry, an `if` the run of the branch that stands.
  1383. claim(&m, host, Number at = 0) {
  1384. let f = walkOf(m.key, 'v', null)
  1385. return run(f, &m, &m, host, at, {}, '', null, false, null)
  1386. }
  1387. // a kid's address: its host's, plus the key the host holds it under
  1388. childChain(chain, kk) {
  1389. let out = chain == null ? [] : chain.slice(0)
  1390. out.push(kk)
  1391. return out
  1392. }
  1393. // the keys a list has, in order: the record's id (view.rowKey), an index where the row
  1394. // is no record, and a suffix where one id stands twice. THE SERVER DOES NOT DEDUPE —
  1395. // its `mountKids` gives two rows of one id one mount key; a list with repeated ids is
  1396. // written down here rather than answered twice.
  1397. listKeys(&entries) {
  1398. let out = []
  1399. let seen = {}
  1400. for (let ri = 0; ri < entries.length; ri = ri + 1) {
  1401. let k = view.rowKey(&entries[ri], ri)
  1402. if (seen[k] != null) { k = k + ':' + ri }
  1403. seen[k] = true
  1404. out.push(k)
  1405. }
  1406. return out
  1407. }
  1408. // ---- the patch: old keys against new ---------------------------------------------
  1409. // A write to the list is answered by a DIFF and nothing else: the rows that are gone
  1410. // are removed, the rows that arrived are built, the rows that stayed are MOVED where
  1411. // the order changed and are left alone where it did not — and each of them is handed
  1412. // the record it now stands for, which rewrites only the attributes and the text the
  1413. // DOM does not already hold. The region's element is never emptied. Each row is the
  1414. // span between its own marks, and every row stands between the list's marks.
  1415. paintFor(&m, &s, lean) {
  1416. let host = s.el
  1417. let start = s.start
  1418. if (!standing(host, start)) {
  1419. // dropped while this paint was on its way (a paint that was running when the
  1420. // range holding it left, and comes back for another round): it is gone, and
  1421. // nothing is painted — a site still REGISTERED here is the bug
  1422. if (!isLive(&m, s)) { return null }
  1423. if (start != null && dropDue(start)) { return null }
  1424. return staleSite(s)
  1425. }
  1426. if (start.__hlBox == null) { return null }
  1427. // ONE PAINT OF A LIST AT A TIME. Building a row can wait (a composed child's module
  1428. // loads on first use), and a second write to the list in that time — a push right
  1429. // behind the handler's own write — read the start.__hlBox before the first paint had filed
  1430. // its row, and built the row again. A paint that arrives while one runs is
  1431. // remembered, and the running one paints again from the list as it then stands.
  1432. if (start.__hlBusy != null) { start.__hlBusy = 'again' return null }
  1433. start.__hlBusy = 'busy'
  1434. // A ROW WITH A COMPOSED CHILD IS STEPPED OVER only when the write moved no member the child is
  1435. // bound to (#181): its bound values (`lit = b3`) are host members, not the record, and a write
  1436. // that moved `L` (derived) may have moved them too — only rebindRow hands them down again
  1437. if (lean == true && rowHasKid(m.key, s.site)) {
  1438. if (paintSet == null) { lean = false }
  1439. else {
  1440. let bound = rowKidReads(m.key, s.site)
  1441. for (n of paintSet) { if (bound.includes(n)) { lean = false } }
  1442. }
  1443. }
  1444. let read = s.read
  1445. let entries = read(&m.instance, &s.rows)
  1446. if (entries == null) { entries = [] }
  1447. // the keys this list has now, in order
  1448. let keys = listKeys(&entries)
  1449. let next = []
  1450. let ri = 0
  1451. while (ri < entries.length) {
  1452. next.push({ key = keys[ri]; i = ri; })
  1453. ri = ri + 1
  1454. }
  1455. // 1. THE ROWS THAT ARE GONE: their nodes, their sites and their children's
  1456. // mounts leave together.
  1457. let keep = {}
  1458. for (r of next) { keep[r.key] = true }
  1459. for (k of start.__hlBox.keys) {
  1460. if (keep[k] == null) { dropRow(&m, &s, &start.__hlBox, k) }
  1461. }
  1462. // 2. THE ROWS IN ORDER. `at` is the node standing where the next row belongs: a
  1463. // row already there advances it, a row that is not is moved or built before it.
  1464. // A DELTA COSTS WHAT CHANGED (#181): each row carries the JSON of the record it was
  1465. // painted from (`sig`), and a row that stands in place with the same record, on a paint
  1466. // the list's own member started (`lean`), is stepped over — no copy of its record, no
  1467. // refresh, no rebind. A row is read by address (`entries[r.i]`), never put in a local.
  1468. let at = start.__hlEnd
  1469. let found = false
  1470. for (k of start.__hlBox.keys) {
  1471. if (!found && keep[k] != null && start.__hlBox.rows[k] != null) { at = start.__hlBox.rows[k].start found = true }
  1472. }
  1473. let placed = []
  1474. let changed = []
  1475. for (r of next) {
  1476. let hstart = start.__hlBox.rows[r.key] == null ? null : start.__hlBox.rows[r.key].start
  1477. let sig = JSON.stringify(entries[r.i])
  1478. if (start.__hlBox.rows[r.key] == null) {
  1479. buildRow(&m, &s, &start.__hlBox, r.key, &entries[r.i], at)
  1480. if (start.__hlBox.rows[r.key] != null) { start.__hlBox.rows[r.key].sig = sig }
  1481. } else if (hstart == at) {
  1482. // already in place: step over it
  1483. at = hstart.__hlEnd.nextSibling
  1484. if (!(lean == true && start.__hlBox.rows[r.key].sig == sig)) {
  1485. if (updateRow(&m, &s, &start.__hlBox, r.key, &entries[r.i], sig)) { changed.push(start.__hlBox.rows[r.key]) }
  1486. }
  1487. } else {
  1488. moveRow(host, &start.__hlBox.rows[r.key], at)
  1489. if (updateRow(&m, &s, &start.__hlBox, r.key, &entries[r.i], sig)) { changed.push(start.__hlBox.rows[r.key]) }
  1490. }
  1491. placed.push(r.key)
  1492. }
  1493. start.__hlBox.keys = placed
  1494. if (changed.length > 0) { reseatRows(&m, &s, changed) }
  1495. let again = start.__hlBusy == 'again'
  1496. start.__hlBusy = null
  1497. if (again) { paintFor(&m, &s, false) }
  1498. return null
  1499. }
  1500. // a row's own elements: the ones between its marks
  1501. rowEls(&held) {
  1502. let out = []
  1503. for (n of between(held.start)) { if (n.nodeType == 1) { out.push(n) } }
  1504. return out
  1505. }
  1506. // A ROW LEAVES: its span goes off the document, the sites that were registered inside
  1507. // it are dropped (they point at nodes nobody can see), and so do the mounts of the
  1508. // children it held — a child of a row is keyed by that row (view.rowKey).
  1509. dropRow(&m, &s, &box, key) {
  1510. let held = box.rows[key]
  1511. if (held == null) { return null }
  1512. let host = s.el
  1513. let nodes = spanOf(held.start)
  1514. dropRange(&m, host, nodes, s.fill)
  1515. for (n of nodes) { n.remove() }
  1516. delete box.rows[key]
  1517. return null
  1518. }
  1519. // A ROW MOVES, marks and all: `moveBefore` where the browser has it, because it keeps
  1520. // an element's state (focus, a playing video, an open dialog) across the move;
  1521. // `insertBefore` else.
  1522. moveRow(host, held, at) {
  1523. for (n of spanOf(held.start)) {
  1524. if (host.moveBefore != null) { host.moveBefore(n, at) }
  1525. else { host.insertBefore(n, at) }
  1526. }
  1527. return null
  1528. }
  1529. // A ROW ARRIVES: built into a fragment between its marks and put in with one insertion,
  1530. // because the walk appends and the row's place is where `at` stands — which may be in
  1531. // the middle of the region. What the walk registered on the fragment belongs to the host.
  1532. buildRow(&m, &s, &box, key, &entry, at) {
  1533. let host = s.el
  1534. let inner = s.rows + {}
  1535. inner[s.row] = entry
  1536. let bin = document.createDocumentFragment()
  1537. let body = walkOf(m.key, 'b', s.site)
  1538. let before = sidNext
  1539. let rs = markAt(bin, true, true)
  1540. run(body, &m, &m, bin, 0, inner, (s.rowKey == null ? '' : s.rowKey) + '#' + key, s.fill, true, null)
  1541. rs.__hlEnd = markAt(bin, true, false)
  1542. rehome(&m, bin, host, before)
  1543. // THE LIST LEFT WHILE THE ROW WAS BEING BUILT (a module to load is a wait, and a
  1544. // branch around the list can be replaced in it): the row never stands, and what
  1545. // its walk registered goes with it
  1546. if (!standing(host, s.start)) {
  1547. dropRange(&m, host, Array.from(bin.childNodes), s.fill)
  1548. return null
  1549. }
  1550. host.insertBefore(bin, at)
  1551. box.rows[key] = { start = rs; entry = entry; }
  1552. return null
  1553. }
  1554. // A ROW STAYS, AND THE RECORD IT SHOWS MAY BE ANOTHER ONE — `upsert` hands the row a
  1555. // new record under the same id, and `items[0].title = 'edited'` writes into the one it
  1556. // already has. Both are answered here: the row's elements are handed the record (their
  1557. // `__hlRows`, which is also what a handler on the row reads), and every attribute and
  1558. // text leaf is rewritten ONLY where the DOM does not already hold the value. That is
  1559. // why a push into 2000 rows costs no mutation on the 2000 that did not change.
  1560. updateRow(&m, &s, &box, key, &entry, sig) {
  1561. if (box.rows[key] == null) { return false }
  1562. // the row holds its own copy of the record, so the two are compared by what they say
  1563. // (read and written in place: a row held in a local, and put back, is a copy of its record twice per delta — #181)
  1564. let changed = box.rows[key].sig != sig
  1565. box.rows[key].entry = entry
  1566. box.rows[key].sig = sig
  1567. for (el of rowEls(&box.rows[key])) { refreshRow(&m, el, s.row, &entry) }
  1568. rebindRow(&m, &s, key, &entry)
  1569. return changed
  1570. }
  1571. // A ROW THAT NOW SHOWS ANOTHER RECORD HANDS IT TO THE SITES INSIDE IT (ticket #86). A
  1572. // row without an id is keyed by its place, so a new list of the same shape keeps every
  1573. // row — and refreshRow repaints only the row's own elements. The sites registered in
  1574. // the row still hold the rows of the moment they were built: a nested `for` read the
  1575. // old record's list, and a `td` inside it the old inner record. Each site whose element
  1576. // stands in a changed row takes the new record, and the regions among them are patched
  1577. // again, outermost first — a nested row that changed in turn does the same for its own.
  1578. // One pass over the sites, marked rows and an ancestor walk, not a scan per row.
  1579. reseatRows(&m, &s, changed) {
  1580. let host = s.el
  1581. // every node of a changed row carries its record for the walk up — its text and
  1582. // its regions' marks as well as its elements, so a text leaf or an `if` standing
  1583. // in the row directly on the host takes the record too
  1584. for (held of changed) { for (n of between(held.start)) { n.__hlReseat = held.entry } }
  1585. // (one pass that reads and writes the list back, with no call in it — see
  1586. // dropSitesIn — and the paints after it)
  1587. // (sites are read and written in place, by index: a site held in a local and put back is a copy of its
  1588. // rows — every record of every enclosing row — twice per site, and a row with a long list inside has a site per item: #198)
  1589. let hits = []
  1590. let k = 0
  1591. while (k < m.sites.length) {
  1592. if (m.sites[k].el != null && m.sites[k].rows != null && !(m.sites[k].region && m.sites[k].start == s.start)) {
  1593. let n = (m.sites[k].region && m.sites[k].el == host && m.sites[k].start != null) ? m.sites[k].start : m.sites[k].el
  1594. let hit = null
  1595. while (n != null && n != host && hit == null) {
  1596. if (n.__hlReseat != null) { hit = n }
  1597. n = n.parentNode
  1598. }
  1599. if (hit != null) {
  1600. m.sites[k].rows[s.row] = hit.__hlReseat
  1601. hits.push(k)
  1602. }
  1603. }
  1604. k = k + 1
  1605. }
  1606. let regions = []
  1607. let texts = []
  1608. for (h of hits) {
  1609. if (m.sites[h].region) { regions.push(m.sites[h].start) }
  1610. if (m.sites[h].text == true) { texts.push(h) }
  1611. }
  1612. for (held of changed) { for (n of between(held.start)) { n.__hlReseat = null } }
  1613. for (t of texts) { paintText(&m, &m.sites[t]) }
  1614. for (r of regions) {
  1615. // read again from the mount: a region an outer one already patched away is gone
  1616. let at = -1
  1617. for (let e = 0; e < m.sites.length; e = e + 1) { if (m.sites[e].region && m.sites[e].start == r) { at = e } }
  1618. if (at >= 0) {
  1619. if (m.sites[at].isFor) { paintFor(&m, &m.sites[at], false) } else { rebuildIf(&m, &m.sites[at], false) }
  1620. }
  1621. }
  1622. return null
  1623. }
  1624. // A ROW'S CHILDREN TAKE THEIR BINDINGS AGAIN. A reference inside a `for` body is not
  1625. // in `m.bindings` — that list is built from the View's own walk, which does not enter a
  1626. // `for` (the row is the scope, and there is one child per row) — so a host member that
  1627. // feeds a row's child used to reach it only because the region REBUILT and the child
  1628. // was minted again with the value of the moment (the framework gate's own case:
  1629. // home.hl writes `noteOpen`, every row's RowNote takes it and hands it to RowMark, and
  1630. // the grandchild's region appears). Nothing rebuilds any more, so the edge is walked
  1631. // here — and only what MOVED is written and repainted, or every list write would
  1632. // repaint every row's child.
  1633. rebindRow(&m, &s, key, &entry) {
  1634. // a row body with no composed child has nothing to take again: decided once per body
  1635. let bk = m.key + '|' + s.site
  1636. if (rowKidless[bk] == true) { return null }
  1637. if (rowKidless[bk] == null) { rowKidless[bk] = !rowHasKid(m.key, s.site) }
  1638. if (rowKidless[bk] == true) { return null }
  1639. let rk = (s.rowKey == null ? '' : s.rowKey) + '#' + key
  1640. let inner = s.rows + {}
  1641. inner[s.row] = entry
  1642. // (the seed's tree is read in place: a copy of it, or of the instance, per row per delta
  1643. // is what froze a streaming chat — #181)
  1644. if (blueprints[m.key] != null) { rebindIn(&m, &blueprints[m.key].view, s.site, &inner, rk) }
  1645. return null
  1646. }
  1647. // the host members the composed children of the `for` at `site` are bound to (read in place, once per body)
  1648. rowKidReads(key, site) {
  1649. let bk = key + '|' + site
  1650. if (rowKidBound[bk] != null) { return rowKidBound[bk] }
  1651. let out = []
  1652. if (blueprints[key] != null) { kidReadsIn(&blueprints[key].view, site, out) }
  1653. rowKidBound[bk] = out
  1654. return out
  1655. }
  1656. kidReadsIn(&nodes, site, &out) {
  1657. for (let i = 0; i < nodes.length; i = i + 1) {
  1658. if (nodes[i].k == 'for' && nodes[i].site == site) { bodyReads(&nodes[i].body, out) }
  1659. else if (nodes[i].k == 'el') { kidReadsIn(&nodes[i].children, site, out) }
  1660. else if (nodes[i].k == 'if') { kidReadsIn(&nodes[i].then, site, out) kidReadsIn(&nodes[i].other, site, out) }
  1661. else if (nodes[i].k == 'for') { kidReadsIn(&nodes[i].body, site, out) }
  1662. else if (nodes[i].k == 'component' && nodes[i].fill != null) { kidReadsIn(&nodes[i].fill, site, out) }
  1663. }
  1664. return null
  1665. }
  1666. // every name a composed child's binding reads, anywhere in these nodes
  1667. bodyReads(&nodes, &out) {
  1668. for (let i = 0; i < nodes.length; i = i + 1) {
  1669. if (nodes[i].k == 'component') {
  1670. for (let j = 0; j < nodes[i].bindings.length; j = j + 1) {
  1671. if (nodes[i].bindings[j].member != null) { out.push(nodes[i].bindings[j].member) }
  1672. else if (nodes[i].bindings[j].ref != null) { exprReads(&nodes[i].bindings[j].ref, out) }
  1673. }
  1674. if (nodes[i].fill != null) { bodyReads(&nodes[i].fill, out) }
  1675. } else if (nodes[i].k == 'el') { bodyReads(&nodes[i].children, out) }
  1676. else if (nodes[i].k == 'if') { bodyReads(&nodes[i].then, out) bodyReads(&nodes[i].other, out) }
  1677. else if (nodes[i].k == 'for') { bodyReads(&nodes[i].body, out) }
  1678. }
  1679. return null
  1680. }
  1681. exprReads(&x, &out) {
  1682. if (x == null) { return null }
  1683. if (x.k == 'member' || x.k == 'field') { out.push(x.name) return null }
  1684. if (x.k == 'expr') { exprReads(&x.x, out) return null }
  1685. if (x.k == 'bin') { exprReads(&x.l, out) exprReads(&x.r, out) return null }
  1686. if (x.k == 'un') { exprReads(&x.x, out) return null }
  1687. if (x.k == 'cond') { exprReads(&x.c, out) exprReads(&x.a, out) exprReads(&x.b, out) return null }
  1688. return null
  1689. }
  1690. // whether the body of the `for` at `site` holds a composed child — read in place, nothing copied
  1691. rowHasKid(key, site) {
  1692. if (blueprints[key] == null) { return false }
  1693. return kidIn(&blueprints[key].view, site, false)
  1694. }
  1695. // walks the tree by address to the `for` at `site`; asks (find false) or re-binds (find true) its body
  1696. kidIn(&nodes, site, inside) {
  1697. for (let i = 0; i < nodes.length; i = i + 1) {
  1698. if (nodes[i].k == 'for' && nodes[i].site == site) { if (bodyHasKid(&nodes[i].body)) { return true } }
  1699. else if (nodes[i].k == 'el') { if (kidIn(&nodes[i].children, site, inside)) { return true } }
  1700. else if (nodes[i].k == 'if') { if (kidIn(&nodes[i].then, site, inside) || kidIn(&nodes[i].other, site, inside)) { return true } }
  1701. else if (nodes[i].k == 'for') { if (kidIn(&nodes[i].body, site, inside)) { return true } }
  1702. else if (nodes[i].k == 'component' && nodes[i].fill != null) { if (kidIn(&nodes[i].fill, site, inside)) { return true } }
  1703. }
  1704. return false
  1705. }
  1706. // the row body of the `for` at `site`, bound again — found and walked by address (rebindNodes)
  1707. rebindIn(&m, &nodes, site, &rows, rk) {
  1708. for (let i = 0; i < nodes.length; i = i + 1) {
  1709. if (nodes[i].k == 'for' && nodes[i].site == site) { rebindNodes(&m, &nodes[i].body, &rows, rk) return true }
  1710. let got = false
  1711. if (nodes[i].k == 'el') { got = rebindIn(&m, &nodes[i].children, site, &rows, rk) }
  1712. else if (nodes[i].k == 'if') { got = rebindIn(&m, &nodes[i].then, site, &rows, rk) || rebindIn(&m, &nodes[i].other, site, &rows, rk) }
  1713. else if (nodes[i].k == 'for') { got = rebindIn(&m, &nodes[i].body, site, &rows, rk) }
  1714. else if (nodes[i].k == 'component' && nodes[i].fill != null) { got = rebindIn(&m, &nodes[i].fill, site, &rows, rk) }
  1715. if (got) { return true }
  1716. }
  1717. return false
  1718. }
  1719. bodyHasKid(&nodes) {
  1720. for (let i = 0; i < nodes.length; i = i + 1) {
  1721. if (nodes[i].k == 'component') { return true }
  1722. if (nodes[i].k == 'el' && bodyHasKid(&nodes[i].children)) { return true }
  1723. if (nodes[i].k == 'if' && (bodyHasKid(&nodes[i].then) || bodyHasKid(&nodes[i].other))) { return true }
  1724. if (nodes[i].k == 'for' && bodyHasKid(&nodes[i].body)) { return true }
  1725. }
  1726. return false
  1727. }
  1728. rebindNodes(&m, &nodes, &rows, rk) {
  1729. for (let i = 0; i < nodes.length; i = i + 1) {
  1730. if (nodes[i].k == 'component') {
  1731. let kk = view.kidKey(&nodes[i].path) + rk
  1732. if (m.kids[kk] != null) {
  1733. let moved = []
  1734. for (let j = 0; j < nodes[i].bindings.length; j = j + 1) {
  1735. let v = null
  1736. if (nodes[i].bindings[j].text != null) { v = view.refValue(&nodes[i].bindings[j]) }
  1737. else if (nodes[i].bindings[j].member != null) { v = view.value({ k = 'member'; name = nodes[i].bindings[j].member; }, &m.instance, &rows) }
  1738. else if (nodes[i].bindings[j].ref != null) { v = view.value(&nodes[i].bindings[j].ref, &m.instance, &rows) }
  1739. let name = nodes[i].bindings[j].name
  1740. if (m.kids[kk].instance[name] != v) { m.kids[kk].instance[name] = v moved.push(name) }
  1741. }
  1742. if (moved.length > 0) { repaintAll(&m.kids[kk], moved) }
  1743. }
  1744. if (nodes[i].fill != null) { rebindNodes(&m, &nodes[i].fill, &rows, rk) }
  1745. } else if (nodes[i].k == 'el') {
  1746. rebindNodes(&m, &nodes[i].children, &rows, rk)
  1747. } else if (nodes[i].k == 'if') {
  1748. rebindNodes(&m, &nodes[i].then, &rows, rk)
  1749. rebindNodes(&m, &nodes[i].other, &rows, rk)
  1750. }
  1751. }
  1752. return null
  1753. }
  1754. refreshRow(&m, el, name, &entry) {
  1755. // A COMPOSED CHILD'S DOM IS ITS OWN MOUNT'S: its elements read the CHILD's
  1756. // instance, and painting them from this one would show the wrong values. The walk
  1757. // stops at the roots a reference claimed (`__hlKid`, set where they are claimed
  1758. // and built) — and at any element another component's walk built (`__hlKey`): a
  1759. // root the child's own region built after the reference was claimed is its too.
  1760. // The walk goes on INTO it: a fill this host wrote stands inside the child's
  1761. // elements, and that is this host's row again.
  1762. if (el.__hlKid == true || (el.__hlKey != null && el.__hlKey != m.key)) {
  1763. let inside = Array.from(el.children)
  1764. for (k of inside) { refreshRow(&m, k, name, &entry) }
  1765. return null
  1766. }
  1767. if (el.__hlRows != null) {
  1768. el.__hlRows[name] = entry
  1769. // (The literal a handler on this element fires takes its row entries from
  1770. // `__hlRows` when it fires — see `bind` — so there is nothing to update here.
  1771. // A handler written on a REFERENCE (bindRefOns) mints one literal for the
  1772. // child's roots and does not: its bindings are re-applied by rebindRow, its
  1773. // own entries are not.)
  1774. }
  1775. rowPaint(&m, el)
  1776. let kids = Array.from(el.children)
  1777. for (k of kids) { refreshRow(&m, k, name, &entry) }
  1778. return null
  1779. }
  1780. // ONE ELEMENT OF A ROW, REDRAWN WHERE IT IS WRONG. The guard is the DOM's own value,
  1781. // not a remembered one: nothing is serialised and nothing is compared to a digest.
  1782. rowPaint(&m, el) {
  1783. let site = el.__hlSite
  1784. if (site == null) { return null }
  1785. let entry = paintEntry(el.__hlKey == null ? m.key : el.__hlKey, site)
  1786. if (entry == null) { return null }
  1787. let f = entry.r
  1788. if (f == null) { return null }
  1789. let e = el
  1790. f(&e, &m.instance, &el.__hlRows)
  1791. return null
  1792. }
  1793. bindValue(&m, name, el, isSelect) {
  1794. let held = m.instance[name] == null ? '' : '' + m.instance[name]
  1795. // A SELECT IS PAINTED BY THE MEMBER FIRST: what it shows is one of its options,
  1796. // and the member decides which. The server already marked it (view.hl `selected`),
  1797. // so this is a no-op there; on a select the client built it is the paint. Only
  1798. // then is the read-back right — before it, an unpainted select reports its FIRST
  1799. // option and the read-back would write that back into the member.
  1800. if (isSelect && held != '') { el.value = held }
  1801. if (el.value != held) { m.instance[name] = el.value liftValue(m.chain, m.rootKind, name, el.value) }
  1802. el.addEventListener('input', (ev) => {
  1803. m.instance[name] = el.value
  1804. // AND UP THROUGH THE REFERENCE THAT BOUND IT, if this control stands inside a
  1805. // composed child: the host's member is what the app reads (see liftValue)
  1806. liftValue(m.chain, m.rootKind, name, el.value)
  1807. })
  1808. return null
  1809. }
  1810. // ---- `value` IS TWO-WAY THROUGH A COMPOSITION TOO --------------------------------
  1811. // `value = member` on a control is the framework's two-way name: the member paints the
  1812. // field and the field writes the member (mission 132). A composed child is a mount of
  1813. // its own, so that write landed on the CHILD's member and stopped there — `Field
  1814. // { value = who }` left the host's `who` empty while the DOM held what was typed, and
  1815. // routger's login submit read null (creator, W12). The host→child binding is an edge
  1816. // the mount already carries; this is the SAME edge run backwards on input, and only
  1817. // for the name `value`: every other binding name stays one-way.
  1818. //
  1819. // The child cannot name its host (a mount record is a value), so it names it by the
  1820. // ADDRESS it already carries — the kid keys from the page or the shell — and the walk
  1821. // below re-enters the host by reference. It carries on upward as long as the reference
  1822. // it came through was itself a `value` binding, which is what makes a component whose
  1823. // View is a bare reference to a field reach the page's member through both hops.
  1824. liftValue(chain, root, target, value) {
  1825. if (target != 'value') { return null }
  1826. if (chain == null || chain.length == 0) { return null }
  1827. if (root == 'shell') {
  1828. if (shell == null) { return null }
  1829. liftInto(&shell, chain, 0, target, value)
  1830. } else {
  1831. if (page == null) { return null }
  1832. liftInto(&page, chain, 0, target, value)
  1833. }
  1834. return null
  1835. }
  1836. // walk the address down to the mount that HOLDS the last key — that mount is the host —
  1837. // and write what its reference bound to the child's `target`, repainting its own sites
  1838. liftInto(&m, chain, at, target, value) {
  1839. if (at >= chain.length - 1) {
  1840. for (b of m.bindings) {
  1841. // a field path (`value = row.text`) names no member to write back into
  1842. if (b.kid == chain[at] && b.target == target && b.ref == null) {
  1843. if (m.instance[b.name] != value) {
  1844. m.instance[b.name] = value
  1845. repaintAll(&m, [b.name])
  1846. }
  1847. liftValue(m.chain, m.rootKind, b.name, value)
  1848. }
  1849. }
  1850. return null
  1851. }
  1852. if (m.kids[chain[at]] == null) { return null }
  1853. liftInto(&m.kids[chain[at]], chain, at + 1, target, value)
  1854. return null
  1855. }
  1856. // THE ELEMENT'S LITERAL: a value of the class the module minted for the literal's

Only the first lines are shown.

Branches

Latest commits

  • 0bcc6294Mission 011: e2e-197, brief, report, LOGmre
  • 137303c5MainMenu marks the current page from the route (hybriel#197, server-rendered); current prop/item.current stay as fallback; tracker demo drops current; gate: SSR marker; docsmre
  • 9325b403Re-vendor Hybriel to master 7f13a82f (hl:web batch 2: #190 #193 #197 #194 named regions); plugins whole, bin/hybriel static build (git-ignored)mre
  • b31dc74dusage: calendar (theme 76f99f6-era ContentFirst, user menu, ☰ menu) and tracker (theme 76f99f6, modal + pagination current, own current marker until hybriel#197) rowsmre
  • 8a3d5d40Mission 010: brief, report, LOG, STATUSmre
  • a56abf1fSync components to components.hybriel 3794c59 (MdEditor real-key fixes); showcase real-key check on the md-editor pagemre
  • 76f99f64E2E in lisbeth's Chrome for the menu's current page (mission 009): tests/e2e-menu-current.mjs, reportmre
  • 159b1d53MainMenu/Sidebar: current page marked beyond colour, count badge, item current flag; gate 300/0 (mission 009)mre
  • 0573eed3usage: notes + tickets on MdEditor (md-editor.js retired), gitoria on theme dbe3de7, tracker theme oldermre
  • 78478f6eSync showcase to components.hybriel 1442e58: pick-mode page, comments attach, md-editor rows/files off; gates 285/0mre
  • 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