@yaks/browse 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +324 -2
  3. package/_dist/app.d.ts +8 -0
  4. package/_dist/app.d.ts.map +1 -0
  5. package/_dist/cli.d.ts +16 -0
  6. package/_dist/cli.d.ts.map +1 -0
  7. package/_dist/hosting.d.ts +24 -0
  8. package/_dist/hosting.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +7 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/types.d.ts +5 -0
  12. package/_dist/types.d.ts.map +1 -0
  13. package/_dist/url.d.ts +2 -0
  14. package/_dist/url.d.ts.map +1 -0
  15. package/app.js +10 -0
  16. package/app.js.map +1 -0
  17. package/app.ts +10 -0
  18. package/browser-links.js +22 -0
  19. package/browser-links.js.map +1 -0
  20. package/browser-links.ts +28 -0
  21. package/cli.js +172 -0
  22. package/cli.js.map +1 -0
  23. package/cli.ts +168 -0
  24. package/client.js +748 -0
  25. package/client.js.map +1 -0
  26. package/client.ts +734 -0
  27. package/clipboard.js +18 -0
  28. package/clipboard.js.map +1 -0
  29. package/clipboard.ts +17 -0
  30. package/commands.js +1157 -0
  31. package/commands.js.map +1 -0
  32. package/commands.ts +1108 -0
  33. package/components/Ansi.tsx +160 -0
  34. package/components/App.tsx +446 -0
  35. package/components/Canvas.tsx +625 -0
  36. package/components/Card.tsx +276 -0
  37. package/components/Chat.tsx +205 -0
  38. package/components/Configuration.tsx +218 -0
  39. package/components/Decision.tsx +49 -0
  40. package/components/Dot.tsx +52 -0
  41. package/components/Entity.tsx +609 -0
  42. package/components/Fault.tsx +43 -0
  43. package/components/Filter.tsx +103 -0
  44. package/components/Keybindings.tsx +100 -0
  45. package/components/Keys.tsx +67 -0
  46. package/components/Markdown.tsx +90 -0
  47. package/components/Navigation.tsx +161 -0
  48. package/components/New.tsx +490 -0
  49. package/components/Peek.tsx +168 -0
  50. package/components/Prio.tsx +20 -0
  51. package/components/Run.tsx +263 -0
  52. package/components/Search.tsx +280 -0
  53. package/components/Stamp.tsx +44 -0
  54. package/components/Status.tsx +514 -0
  55. package/components/Sync.tsx +173 -0
  56. package/components/Tile.tsx +50 -0
  57. package/components/answered.js +23 -0
  58. package/components/answered.js.map +1 -0
  59. package/components/answered.ts +25 -0
  60. package/components/comp.js +11 -0
  61. package/components/comp.js.map +1 -0
  62. package/components/comp.ts +10 -0
  63. package/components/drag.js +173 -0
  64. package/components/drag.js.map +1 -0
  65. package/components/drag.ts +198 -0
  66. package/components/fields.tsx +90 -0
  67. package/components/fixtures/README.md +10 -0
  68. package/components/fixtures/archetypes.json +3646 -0
  69. package/components/hits.js +63 -0
  70. package/components/hits.js.map +1 -0
  71. package/components/hits.ts +84 -0
  72. package/components/icons.tsx +177 -0
  73. package/components/inspect.tsx +331 -0
  74. package/components/mount.ts +79 -0
  75. package/components/nav.tsx +479 -0
  76. package/components/offers.js +26 -0
  77. package/components/offers.js.map +1 -0
  78. package/components/offers.ts +54 -0
  79. package/components/page.js +21 -0
  80. package/components/page.js.map +1 -0
  81. package/components/page.ts +18 -0
  82. package/components/read.js +5 -0
  83. package/components/read.js.map +1 -0
  84. package/components/read.ts +7 -0
  85. package/components/registry.js +285 -0
  86. package/components/registry.js.map +1 -0
  87. package/components/registry.ts +317 -0
  88. package/components/session_status.tsx +115 -0
  89. package/components/subscriptions.js +149 -0
  90. package/components/subscriptions.js.map +1 -0
  91. package/components/subscriptions.ts +161 -0
  92. package/components/title.tsx +21 -0
  93. package/components/useQuery.js +166 -0
  94. package/components/useQuery.js.map +1 -0
  95. package/components/useQuery.ts +211 -0
  96. package/components/views/Board.tsx +450 -0
  97. package/components/views/BoardTile.tsx +65 -0
  98. package/components/views/Dashboard.tsx +148 -0
  99. package/components/views/Debug.tsx +445 -0
  100. package/components/views/Dependency.tsx +51 -0
  101. package/components/views/Entry.tsx +500 -0
  102. package/components/views/Gist.tsx +28 -0
  103. package/components/views/Inline.tsx +54 -0
  104. package/components/views/Json.tsx +19 -0
  105. package/components/views/Layout.tsx +211 -0
  106. package/components/views/List.tsx +238 -0
  107. package/components/views/Md.tsx +43 -0
  108. package/components/views/Media.tsx +48 -0
  109. package/components/views/Memory.tsx +32 -0
  110. package/components/views/Relate.tsx +205 -0
  111. package/components/views/Search.tsx +42 -0
  112. package/components/views/Session.tsx +850 -0
  113. package/components/views/SessionManage.tsx +127 -0
  114. package/components/views/Show.tsx +758 -0
  115. package/components/views/Shown.tsx +72 -0
  116. package/components/views/Split.tsx +58 -0
  117. package/components/views/TaskTile.tsx +37 -0
  118. package/components/views/Title.tsx +105 -0
  119. package/components/views/Wake.tsx +77 -0
  120. package/components/views/Web.tsx +49 -0
  121. package/components/wells.js +30 -0
  122. package/components/wells.js.map +1 -0
  123. package/components/wells.ts +33 -0
  124. package/configuration.js +38 -0
  125. package/configuration.js.map +1 -0
  126. package/configuration.ts +41 -0
  127. package/decision_sync.js +88 -0
  128. package/decision_sync.js.map +1 -0
  129. package/decision_sync.ts +93 -0
  130. package/deno.json +1 -0
  131. package/domain-host.tsx +108 -0
  132. package/edge.js +193 -0
  133. package/edge.js.map +1 -0
  134. package/edge.ts +196 -0
  135. package/entry_log.js +241 -0
  136. package/entry_log.js.map +1 -0
  137. package/entry_log.ts +214 -0
  138. package/failure.js +22 -0
  139. package/failure.js.map +1 -0
  140. package/failure.ts +34 -0
  141. package/front.json +61 -0
  142. package/highlight.js +143 -0
  143. package/highlight.js.map +1 -0
  144. package/highlight.ts +149 -0
  145. package/history.js +68 -0
  146. package/history.js.map +1 -0
  147. package/history.ts +72 -0
  148. package/host_commands.js +107 -0
  149. package/host_commands.js.map +1 -0
  150. package/host_commands.ts +38 -0
  151. package/hosting.js +53 -0
  152. package/hosting.js.map +1 -0
  153. package/hosting.ts +72 -0
  154. package/idb.js +14 -0
  155. package/idb.js.map +1 -0
  156. package/idb.ts +15 -0
  157. package/index.js +232 -0
  158. package/index.js.map +1 -0
  159. package/index.ts +252 -0
  160. package/keybindings.js +136 -0
  161. package/keybindings.js.map +1 -0
  162. package/keybindings.ts +37 -0
  163. package/kit.js +103 -0
  164. package/kit.js.map +1 -0
  165. package/kit.ts +119 -0
  166. package/layout.js +254 -0
  167. package/layout.js.map +1 -0
  168. package/layout.ts +210 -0
  169. package/legacy_outbox.js +53 -0
  170. package/legacy_outbox.js.map +1 -0
  171. package/legacy_outbox.ts +63 -0
  172. package/live.js +2883 -0
  173. package/live.js.map +1 -0
  174. package/live.ts +3334 -0
  175. package/live_archetypes.js +92 -0
  176. package/live_archetypes.js.map +1 -0
  177. package/live_archetypes.ts +113 -0
  178. package/live_client.js +145 -0
  179. package/live_client.js.map +1 -0
  180. package/live_client.ts +120 -0
  181. package/main.tsx +5 -0
  182. package/mod.js +7 -0
  183. package/mod.js.map +1 -0
  184. package/mod.ts +7 -0
  185. package/mount.tsx +50 -0
  186. package/navigation.js +120 -0
  187. package/navigation.js.map +1 -0
  188. package/navigation.ts +152 -0
  189. package/near.js +83 -0
  190. package/near.js.map +1 -0
  191. package/near.ts +83 -0
  192. package/new.js +295 -0
  193. package/new.js.map +1 -0
  194. package/new.ts +361 -0
  195. package/outbox.js +112 -0
  196. package/outbox.js.map +1 -0
  197. package/outbox.ts +129 -0
  198. package/owner.js +39 -0
  199. package/owner.js.map +1 -0
  200. package/owner.ts +37 -0
  201. package/package.json +81 -4
  202. package/paste.js +157 -0
  203. package/paste.js.map +1 -0
  204. package/paste.ts +122 -0
  205. package/props.js +303 -0
  206. package/props.js.map +1 -0
  207. package/props.ts +358 -0
  208. package/providers.js +136 -0
  209. package/providers.js.map +1 -0
  210. package/providers.ts +194 -0
  211. package/query.js +987 -0
  212. package/query.js.map +1 -0
  213. package/query.ts +1113 -0
  214. package/remote.js +37 -0
  215. package/remote.js.map +1 -0
  216. package/remote.ts +46 -0
  217. package/resolver.js +149 -0
  218. package/resolver.js.map +1 -0
  219. package/resolver.ts +213 -0
  220. package/rfc2047.js +37 -0
  221. package/rfc2047.js.map +1 -0
  222. package/rfc2047.ts +40 -0
  223. package/row_holds.js +107 -0
  224. package/row_holds.js.map +1 -0
  225. package/row_holds.ts +93 -0
  226. package/served.ts +42 -0
  227. package/session_worktree.js +7 -0
  228. package/session_worktree.js.map +1 -0
  229. package/session_worktree.ts +16 -0
  230. package/sessions.js +57 -0
  231. package/sessions.js.map +1 -0
  232. package/sessions.ts +53 -0
  233. package/sha.js +161 -0
  234. package/sha.js.map +1 -0
  235. package/sha.ts +164 -0
  236. package/styles.css +2823 -0
  237. package/subs.js +36 -0
  238. package/subs.js.map +1 -0
  239. package/subs.ts +40 -0
  240. package/terminal-route.js +13 -0
  241. package/terminal-route.js.map +1 -0
  242. package/terminal-route.ts +17 -0
  243. package/terminal.js +251 -0
  244. package/terminal.js.map +1 -0
  245. package/terminal.ts +186 -0
  246. package/time.js +142 -0
  247. package/time.js.map +1 -0
  248. package/time.ts +133 -0
  249. package/title.js +25 -0
  250. package/title.js.map +1 -0
  251. package/title.ts +50 -0
  252. package/tui/doc.ts +6 -0
  253. package/tui/testing.ts +19 -0
  254. package/twin.js +11 -0
  255. package/twin.js.map +1 -0
  256. package/twin.ts +13 -0
  257. package/types.js +456 -0
  258. package/types.js.map +1 -0
  259. package/types.ts +1370 -0
  260. package/url.js +77 -0
  261. package/url.js.map +1 -0
  262. package/url.ts +85 -0
  263. package/verb.js +82 -0
  264. package/verb.js.map +1 -0
  265. package/verb.ts +137 -0
  266. package/warmth.js +41 -0
  267. package/warmth.js.map +1 -0
  268. package/warmth.ts +54 -0
  269. package/wire.js +86 -0
  270. package/wire.js.map +1 -0
  271. package/wire.ts +63 -0
@@ -0,0 +1,79 @@
1
+ // Test-only: mount a renderer through Preact and hand back the container to
2
+ // assert on. A renderer is a component — several hold hooks — so it must be
3
+ // MOUNTED, never called as a bare function, which bypasses Preact's hook
4
+ // dispatcher (registry.ts). Callers build the vnode the production way,
5
+ // `h(resolve(e, view).Render, props)`, and read the resulting DOM, under the
6
+ // page's UX host (registry.ts `ux`) as main.tsx mounts the app. Sets up a
7
+ // shared linkedom document, mounts into its own <main>, and returns that root
8
+ // plus a free() that unmounts and restores the document global. Pair every
9
+ // mount() with free() — a try/finally, or the end of the test.
10
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type ReactNode } from 'npm:react@19.3.0'
11
+ import { render } from 'jsr:@yaks/react@0.2.36/draw'
12
+ import { act } from 'jsr:@yaks/react@0.2.36/testing'
13
+ import { parseHTML } from 'npm:linkedom@^0.18.12'
14
+ import { Ux } from 'jsr:@yaks/ux@0.2.36'
15
+ import { ux } from './registry.ts'
16
+
17
+ // Linkedom shares element prototypes across documents but omits the browser's
18
+ // selection API. Completion fields restore their caret in a layout effect,
19
+ // including in tests that install a document of their own.
20
+ let { document, window } = parseHTML('<html><body></body></html>')
21
+ for (
22
+ let prototype of [
23
+ window.HTMLInputElement.prototype,
24
+ window.HTMLTextAreaElement.prototype,
25
+ ]
26
+ ) {
27
+ prototype.selectionStart = 0
28
+ prototype.selectionEnd = 0
29
+ prototype.setSelectionRange = function (start: number, end: number) {
30
+ this.selectionStart = start
31
+ this.selectionEnd = end
32
+ }
33
+ }
34
+ // Nor does it keep the focus: focus and blur move the document's
35
+ // activeElement, and say so, and an element taken out of the page lets go of
36
+ // it, as a browser's do.
37
+ let held = new WeakMap<object, Element | null>()
38
+ Object.defineProperty(window.Document.prototype, 'activeElement', {
39
+ get() {
40
+ let at = held.get(this)
41
+ return at?.isConnected ? at : null
42
+ },
43
+ configurable: true,
44
+ })
45
+ let element = window.HTMLElement.prototype
46
+ element.focus = function (this: HTMLElement) {
47
+ let doc = this.ownerDocument
48
+ if (doc.activeElement == this) return
49
+ ;(doc.activeElement as HTMLElement | null)?.blur()
50
+ held.set(doc, this)
51
+ this.dispatchEvent(new window.Event('focus'))
52
+ this.dispatchEvent(new window.Event('focusin', { bubbles: true }))
53
+ }
54
+ element.blur = function (this: HTMLElement) {
55
+ let doc = this.ownerDocument
56
+ if (doc.activeElement != this) return
57
+ held.set(doc, null)
58
+ this.dispatchEvent(new window.Event('blur'))
59
+ this.dispatchEvent(new window.Event('focusout', { bubbles: true }))
60
+ }
61
+ export let mount = (node: ReactNode) => {
62
+ let prior = Object.getOwnPropertyDescriptor(globalThis, 'document')
63
+ Object.defineProperty(globalThis, 'document', {
64
+ value: document,
65
+ configurable: true,
66
+ })
67
+ let root = document.createElement('main')
68
+ document.body.append(root)
69
+ act(() => render(h(Ux, { host: ux }, node), root))
70
+ return {
71
+ root,
72
+ free() {
73
+ render(null, root)
74
+ root.remove()
75
+ if (prior) Object.defineProperty(globalThis, 'document', prior)
76
+ else delete (globalThis as { document?: unknown }).document
77
+ },
78
+ }
79
+ }
@@ -0,0 +1,479 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { useObserved } from 'jsr:@yaks/ux@0.2.36'
3
+ import { localPath } from '../hosting.ts'
4
+ import { addressId, entityPath } from '../url.ts'
5
+ import { signal } from 'npm:@preact/signals-core@1.14.5'
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useRef } from 'npm:react@19.3.0'
7
+ import * as ui from 'jsr:@yaks/ui@0.2.36'
8
+ import { copy } from '../clipboard.ts'
9
+ import { usePlaceAt } from 'jsr:@yaks/ui@0.2.36'
10
+ import {
11
+ buriedId,
12
+ cache,
13
+ capable,
14
+ clientId,
15
+ ent,
16
+ findEid,
17
+ goneId,
18
+ mutate,
19
+ myCursor,
20
+ owner,
21
+ peeked,
22
+ resolveEid,
23
+ resolvingId,
24
+ serverEid,
25
+ } from '../live.ts'
26
+ import { type Action, actionsFor, resolve } from './registry.ts'
27
+ import { SHORT } from 'jsr:@yaks/id@0.2.36'
28
+ import { type Change, type Ent, IdError, idOf } from '../types.ts'
29
+ import { dragData } from './drag.ts'
30
+ import { cursorEid } from '../edge.ts'
31
+
32
+ // The door keeps history: one page at a time, each at its own address.
33
+ export { route } from '../history.ts'
34
+ import { go, route } from '../history.ts'
35
+ import { homeOffer } from './offers.ts'
36
+ import { historyPort } from 'jsr:@yaks/ui@0.2.36/history'
37
+
38
+ export let navigate = (to: string, options: { replace?: boolean } = {}) => {
39
+ let url = new URL(to, 'http://x')
40
+ peeked.value = null
41
+ go(localPath(url.pathname) + url.search + url.hash, options.replace)
42
+ mark()
43
+ }
44
+
45
+ // Whether a path is the app's own route shape — `/` or ONE extensionless
46
+ // segment (`/T-123`, `/home`). Multi-segment and dotted paths are real
47
+ // resources (/blob/<sha>, /logs/…, files) and keep native navigation.
48
+ export let appRoute = (path: string) =>
49
+ /^\/[^/?#.]*$/.test(path) &&
50
+ path != '/inspect'
51
+
52
+ // Pressing a link to an entity. Where a fine pointer reads, it peeks
53
+ // (./Peek.tsx): the entity floats over this page, which stays where it was,
54
+ // and one at a time, so a link pressed inside the peek shows its entity in
55
+ // the peek's place. A link to what is already shown, the peek's entity or the
56
+ // page's, opens its page: a second press, or a double click, is the way in.
57
+ // A coarse pointer and the terminal open the page at once, fullscreen being
58
+ // a phone's right answer.
59
+ type LinkEvent = Pick<
60
+ MouseEvent,
61
+ | 'button'
62
+ | 'ctrlKey'
63
+ | 'metaKey'
64
+ | 'shiftKey'
65
+ | 'currentTarget'
66
+ | 'target'
67
+ | 'preventDefault'
68
+ | 'stopPropagation'
69
+ >
70
+
71
+ export let openAt = (eid: string, ev: LinkEvent) => {
72
+ let at = route.peek()
73
+ let up = peeked.peek()
74
+ let now = up?.at == at ? up : null
75
+ if (!fine() || now?.eid == eid || screenTarget(at)?.eid == eid) {
76
+ return navigate(entityPath(idOf(ent(eid))))
77
+ }
78
+ let from = linkAt(ev)
79
+ let card = from?.closest('.Peek') as HTMLElement | null | undefined
80
+ peeked.value = card && now
81
+ ? {
82
+ ...now,
83
+ eid,
84
+ from: undefined,
85
+ left: card.offsetLeft,
86
+ top: card.offsetTop,
87
+ }
88
+ : { eid, at, from }
89
+ }
90
+
91
+ let fine = () => !!globalThis.matchMedia?.('(pointer: fine)').matches
92
+
93
+ // The link a press landed on: the element whose handler heard it, or, for a
94
+ // listener on the document, the nearest link around what was pressed.
95
+ let linkAt = (ev: LinkEvent): Element | undefined => {
96
+ let on = ev.currentTarget as Element | null | undefined
97
+ let at = ev.target as Element | null | undefined
98
+ return typeof on?.closest == 'function'
99
+ ? on
100
+ : at?.closest?.('a, [data-href]') ?? undefined
101
+ }
102
+
103
+ // A plain press on an in-app anchor no component owns (../browser-links.ts):
104
+ // an entity's own address opens as its links do, anything else is gone to.
105
+ export let visit = (to: string, ev: MouseEvent) => {
106
+ let url = new URL(to, 'http://x')
107
+ let id = !url.search && !url.hash &&
108
+ addressId(decodeURIComponent(url.pathname.slice(1)))
109
+ let eid = id ? routed(id) : undefined
110
+ if (eid) openAt(eid, ev)
111
+ else navigate(to)
112
+ }
113
+
114
+ // An id in the wild — T-num, bare num, raw eid, a sigilled eid fragment, or
115
+ // an alias — resolved in the host's order; undefined while unloaded or dead.
116
+ // An ambiguous fragment is refused, never treated as a miss. An alias resolves
117
+ // here as it does at the CLI and MCP id doors.
118
+ // Cache misses fall to serverEid — live.ts's addressed-sub sidecar —
119
+ // so a token naming a live-but-unloaded entity still navigates once the boot
120
+ // flip (T-18059) serves a partial working set. The fallback is async: it
121
+ // returns undefined the first miss and the eid once its one-row subscription
122
+ // lands (the caller re-renders on resolveGen). Fragments always ask the server
123
+ // because a partial cache cannot prove global uniqueness.
124
+ export let eidOf = (id: string) => {
125
+ // A partial cache cannot prove uniqueness across the graph.
126
+ if (SHORT.test(id)) return serverEid(id)
127
+ return findEid(id) ?? serverEid(id)
128
+ }
129
+
130
+ // Whether the route names an id the server is still resolving — the App shows
131
+ // a resolving state instead of a premature Lost while its one-row sub is open.
132
+ export let screenResolving = (at = route.value) => {
133
+ let id = addressId(
134
+ decodeURIComponent(new URL(at, 'http://x').pathname.slice(1)),
135
+ )
136
+ return !!id && resolvingId(id)
137
+ }
138
+
139
+ // Whether the route names an id the server says names nothing. The page draws
140
+ // Lost then, whatever its own read of that id was told.
141
+ export let screenGone = (at = route.value) => {
142
+ let id = screenId(at)
143
+ return !!id && goneId(id)
144
+ }
145
+
146
+ // The id the route names when the server says it names a deleted entity: the
147
+ // page reads that entity's last version and its history.
148
+ export let screenBuried = (at = route.value): string | undefined => {
149
+ let id = screenId(at)
150
+ return id && buriedId(id) ? id : undefined
151
+ }
152
+
153
+ let screenId = (at: string) =>
154
+ addressId(decodeURIComponent(new URL(at, 'http://x').pathname.slice(1)))
155
+
156
+ // The plain-click half of an in-app anchor: modifiers and middle-click keep
157
+ // their new-tab forms; a bare click (tap included) opens its entity as a link
158
+ // does (openAt) when the caller knows it, or goes to its href when that is
159
+ // all it has.
160
+ export let follow = (href: string, eid?: string) => (ev: LinkEvent) => {
161
+ if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.button != 0) return
162
+ ev.preventDefault()
163
+ ev.stopPropagation()
164
+ if (eid) openAt(eid, ev)
165
+ else navigate(href)
166
+ }
167
+
168
+ // A link inside another link keeps its tag and says data-href (@yaks/ui el),
169
+ // and no component owns its clicks. It resolves its entity at click time, so
170
+ // it opens like any chip, and double click goes to its page.
171
+ // Heard in the capture phase, ahead of the link around it, which would
172
+ // otherwise take the click as its own.
173
+ let demoted =
174
+ (open: (href: string) => (ev: MouseEvent) => void) => (ev: MouseEvent) => {
175
+ let href = (ev.target as Element | null)?.closest?.('[data-href]')
176
+ ?.getAttribute('data-href')
177
+ if (href) open(href)(ev)
178
+ }
179
+ let openDemoted = demoted((href) =>
180
+ follow(href, eidOf(decodeURIComponent(href.slice(1))))
181
+ )
182
+ let navigateDemoted = demoted((href) => follow(href))
183
+
184
+ // Ids in prose are data-ref anchors @yaks/markdown draws, so no component
185
+ // owns their clicks: one delegated listener gives every T-123 in any body the same in-app open as an Id chip. The id resolves
186
+ // against the live cache at click time; a ref the cache can't name (an
187
+ // unloaded or dead entity) falls through to its href, the honest 404.
188
+ let openRef = (ev: MouseEvent) => {
189
+ let a = (ev.target as Element | null)?.closest?.('a[data-ref]')
190
+ if (!a) return
191
+ let id = a.getAttribute('data-ref')!
192
+ let eid = eidOf(id)
193
+ if (eid) follow(entityPath(id), eid)(ev)
194
+ }
195
+
196
+ // Component-owned entity links carry menuAt directly. Rendered prose and
197
+ // other native anchors have no component to do that, so their root-relative
198
+ // entity href resolves here. External and app-chrome links fall through.
199
+ let menuRef = (ev: MouseEvent) => {
200
+ let a = (ev.target as Element | null)?.closest?.('a[href]')
201
+ let href = a?.getAttribute('href') ?? ''
202
+ let id = localPath(href).match(/^\/([^/?#]+)(?:\?[^#]*)?$/)?.[1]
203
+ let eid = id && eidOf(decodeURIComponent(id))
204
+ if (eid) menuAt(ent(eid))(ev)
205
+ }
206
+
207
+ // Startup, exported so either host's document can be proven against it. The
208
+ // TUI's fake document (@yaks/dom) carries only what preact reaches for, so
209
+ // an object guard is not enough here — `document?.member(…)` passes it and
210
+ // then throws on the missing member. Guard the METHOD, always.
211
+ type Host = {
212
+ addEventListener?: (
213
+ t: string,
214
+ fn: (ev: MouseEvent) => void,
215
+ capture?: boolean,
216
+ ) => void
217
+ }
218
+
219
+ export let wire = (doc: Host | undefined = globalThis.document) => {
220
+ doc?.addEventListener?.('click', openRef)
221
+ doc?.addEventListener?.('contextmenu', menuRef)
222
+ doc?.addEventListener?.('click', openDemoted, true)
223
+ doc?.addEventListener?.('dblclick', navigateDemoted, true)
224
+ }
225
+
226
+ wire()
227
+
228
+ // The pointer half of the internal-link contract: a real href keeps native
229
+ // new-tab gestures, plain click peeks (openAt), double click opens its page,
230
+ // and right-click opens the target entity's menu.
231
+ // For tiles whose wrapper already owns the drag (a board Item, a List Row).
232
+ export let clickProps = (e: Ent) => {
233
+ let href = entityPath(idOf(e))
234
+ return {
235
+ href,
236
+ onClick: follow(href, e.eid),
237
+ onDoubleClick: follow(href),
238
+ onContextMenu: menuAt(e),
239
+ }
240
+ }
241
+
242
+ // The whole contract, spreadable onto any anchor: the clicks above plus
243
+ // dragging it onto the canvas makes a card.
244
+ export let linkProps = (e: Ent) => ({
245
+ ...clickProps(e),
246
+ draggable: capable('canvas'),
247
+ onDragStart: (ev: DragEvent) =>
248
+ capable('canvas') && dragData(ev, e.eid, resolve(e).view),
249
+ })
250
+
251
+ // Resolve a route to {eid, view}: bare `/` is the owner in the home page a
252
+ // package offers (./offers.ts), and nothing where none does (the host's own
253
+ // list); an id is T-num / bare num / eid, looked up in the live cache. The
254
+ // argument is how a REMEMBERED route (below) is screened against the same
255
+ // resolver the screen uses — a route naming a dead entity resolves to
256
+ // nothing.
257
+ export let screenTarget = (at = route.value) => {
258
+ let url = new URL(at, 'http://x')
259
+ // `/?.task` and `/?page=<destination>` are pages of their own, not home.
260
+ if (
261
+ url.pathname == '/' &&
262
+ [...url.searchParams.keys()].some((k) => k != 'v' && k != 'task')
263
+ ) return null
264
+ let id = addressId(decodeURIComponent(url.pathname.slice(1)))
265
+ let home = homeOffer()
266
+ if (id) {
267
+ let eid = routed(id)
268
+ return eid ? { eid, view: url.searchParams.get('v') ?? undefined } : null
269
+ }
270
+ return home && owner.value ? { eid: owner.value, view: home.view } : null
271
+ }
272
+
273
+ // A route whose id the finder refuses (a handle written with a letter, an
274
+ // ambiguous fragment) names nothing the page can draw: the Lost face, as the
275
+ // host's own 404 for that path says, rather than an exception mid-render.
276
+ let routed = (id: string) => {
277
+ try {
278
+ return eidOf(id)
279
+ } catch (error) {
280
+ if (error instanceof IdError) return undefined
281
+ throw error
282
+ }
283
+ }
284
+
285
+ // Home always opens home. An explicit entity URL stays put; old ?task=
286
+ // links still resolve through their original door.
287
+ export let restore = () => {
288
+ let legacy = new URL(route.peek(), 'http://x').searchParams.get('task')
289
+ if (legacy) void grandfather(legacy)
290
+ }
291
+ let grandfather = async (legacy: string) => {
292
+ let at = route.peek()
293
+ let eid = await resolveEid(legacy)
294
+ if (eid && route.peek() == at) {
295
+ navigate(entityPath(idOf(ent(eid))), { replace: true })
296
+ }
297
+ }
298
+
299
+ // The cursor: publish WHERE this client now looks into the
300
+ // GRAPH (T-12788), so the fleet can see it (ui_state reports every open tab).
301
+ // UPDATE-ONLY: this write publishes position, and nothing reads it back to
302
+ // drive navigation — a cursor read must never influence rendering.
303
+ // One row per client, minted lazily beside the client
304
+ // entity the way the camera mints on first pan. Written on navigation only,
305
+ // never mid-gesture at navigation boundaries, and IDEMPOTENT: a
306
+ // write naming where the cursor already points is skipped, so a re-render never
307
+ // churns the row. Guarded for the TUI (no client, no localStorage) via loc/his.
308
+ let mark = () => {
309
+ let t = screenTarget()
310
+ if (!capable('canvas') || !historyPort()) return
311
+ if (!t) return // chrome and dead ends are not places
312
+ let client = clientId()
313
+ let cur = myCursor(client)
314
+ if (cur?.target == t.eid && (cur.view ?? null) == (t.view ?? null)) return
315
+ let eid = cursorEid(client) // identity never waits for the client-row sub
316
+ let batch: Change[] = []
317
+ // Mint the client entity when a cursor beats the canvas to it — a deep link
318
+ // never mounts the Canvas that otherwise mints it, so the reference would
319
+ // name a bare spine. Idempotent: skipped once the client row exists.
320
+ if (!cache.peek()[client]?.client) {
321
+ batch.push({
322
+ eid: client,
323
+ name: 'client',
324
+ comp: { eid: client, user_agent: navigator.userAgent },
325
+ })
326
+ }
327
+ batch.push({
328
+ eid,
329
+ name: 'cursor',
330
+ comp: { eid, client, target: t.eid, view: t.view ?? null },
331
+ })
332
+ // Publishing the cursor is a nicety, never a failure — the graph twin of
333
+ // guarded position write. A cursor write must never break the
334
+ // navigation that triggered it, so a bad graph state swallows here rather
335
+ // than throwing out of navigate().
336
+ try {
337
+ mutate(...batch)
338
+ } catch { /* the position is published best-effort, like navigation */ }
339
+ }
340
+
341
+ // The cursor is UPDATE-ONLY: the client PUBLISHES where it looks
342
+ // (mark() above) but never reads a cursor back to drive navigation. The read
343
+ // half — an effect that navigated the tab wherever the graph moved this
344
+ // client's cursor — let any writer (an agent's `show`, a stale server row)
345
+ // yank the tab, and did: a cursor left pointing at P-19 pulled every attempt to
346
+ // open something else straight back. Rendering answers to the URL and to
347
+ // gestures, not to graph state, so the coupling is gone rather than guarded.
348
+ // The `show` tool's "move a human's tab" rides on this read half and is
349
+ // withdrawn with it (see nav follow-up if it's ever wanted back read-free).
350
+
351
+ // The entity context menu: navigation first ("open here" is the
352
+ // deliberate in-place root change; new tab beside it), then whatever
353
+ // verbs the entity's components contribute (registry actionsFor —
354
+ // a task offers its status moves, a claim its release, …). align
355
+ // 'right' hangs the menu leftward from x — the titlebar dropdown
356
+ // anchors at the screen's far edge.
357
+ type MenuState = {
358
+ x: number
359
+ y: number
360
+ href: string
361
+ eid: string
362
+ acts?: never
363
+ align?: 'right'
364
+ } | {
365
+ x: number
366
+ y: number
367
+ acts: Action[]
368
+ href?: never
369
+ eid?: never
370
+ align?: 'right'
371
+ }
372
+ export let menu = signal<MenuState | null>(null)
373
+
374
+ // Right-click serving the entity's app menu instead of the browser's.
375
+ export let menuAt = (e: Ent) => (ev: MouseEvent) => {
376
+ ev.preventDefault()
377
+ ev.stopPropagation()
378
+ menu.value = {
379
+ x: ev.clientX,
380
+ y: ev.clientY,
381
+ href: entityPath(idOf(e)),
382
+ eid: e.eid,
383
+ }
384
+ }
385
+
386
+ // A point on empty canvas has no entity navigation, only the verbs its host
387
+ // gives it. The shared Menu still owns placement, dismissal and row styling.
388
+ export let actionsAt = (acts: Action[]) => (ev: MouseEvent) => {
389
+ ev.preventDefault()
390
+ ev.stopPropagation()
391
+ menu.value = { x: ev.clientX, y: ev.clientY, acts }
392
+ }
393
+
394
+ // A card is the menu target except where a nested control or link owns
395
+ // the gesture. Pinned and temporary cards share this boundary.
396
+ export let cardMenuAt = (e: Ent) => (ev: MouseEvent) => {
397
+ if (
398
+ ev.target instanceof Element &&
399
+ ev.target.closest('a, input, textarea, [contenteditable]')
400
+ ) return
401
+ menuAt(e)(ev)
402
+ }
403
+
404
+ let { Item, Rule } = ui.Menu
405
+
406
+ export let Menu = () => {
407
+ let m = useObserved(menu)
408
+ let root = useRef<HTMLDivElement>(null)
409
+ usePlaceAt(root, m)
410
+ if (!m) return null
411
+ let close = () => {
412
+ menu.value = null
413
+ }
414
+ let acts = m.acts ?? actionsFor(ent(m.eid))
415
+ return (
416
+ <ui.Menu
417
+ className='Overlay'
418
+ role='menu'
419
+ elRef={root}
420
+ onCancel={close}
421
+ onPointerDown={(e: Event) => e.stopPropagation()}
422
+ >
423
+ {m.eid && (
424
+ <>
425
+ <Item
426
+ type='button'
427
+ onClick={() => {
428
+ navigate(m.href)
429
+ close()
430
+ }}
431
+ >
432
+ open here
433
+ </Item>
434
+ <Item
435
+ type='button'
436
+ onClick={() => {
437
+ globalThis.open?.(m.href)
438
+ close()
439
+ }}
440
+ >
441
+ open in new tab
442
+ </Item>
443
+ <Item
444
+ type='button'
445
+ onClick={() => {
446
+ copy(location.origin + m.href)
447
+ close()
448
+ }}
449
+ >
450
+ copy link
451
+ </Item>
452
+ <Item
453
+ type='button'
454
+ onClick={() => {
455
+ copy(idOf(ent(m.eid)))
456
+ close()
457
+ }}
458
+ >
459
+ copy {idOf(ent(m.eid))}
460
+ </Item>
461
+ </>
462
+ )}
463
+ {m.eid && acts.length > 0 && <Rule />}
464
+ {acts.map((a, i) => (
465
+ <Item
466
+ key={i}
467
+ type='button'
468
+ mod={a.mod}
469
+ onClick={() => {
470
+ a.run()
471
+ close()
472
+ }}
473
+ >
474
+ {a.label}
475
+ </Item>
476
+ ))}
477
+ </ui.Menu>
478
+ )
479
+ }
@@ -0,0 +1,26 @@
1
+ // What packages offer the app's places from their `./views` facets, beside
2
+ // their renderers: the owner's home page, the tabs on what their views draw
3
+ // and the pages the sidebar lists. The door sets them once, before the app
4
+ // paints (./inspect.tsx `contribute`); a config whose packages offer none
5
+ // leaves `/` the host's own list and every entity on the app's own tabs.
6
+ let offered = {
7
+ tabs: [],
8
+ destinations: []
9
+ };
10
+ /** Set what the configured packages offer: a home page, and every tab and
11
+ * destination in the order the packages come. The function returned puts
12
+ * back what was offered before. */ export let offerPlaces = ({ home, tabs = [], destinations = [] })=>{
13
+ let prior = offered;
14
+ offered = {
15
+ home,
16
+ tabs,
17
+ destinations
18
+ };
19
+ return ()=>{
20
+ offered = prior;
21
+ };
22
+ };
23
+ /** The home page a package offers, if one does. */ export let homeOffer = ()=>offered.home;
24
+ /** The tabs packages offer, ahead of the app's own. */ export let tabOffers = ()=>offered.tabs;
25
+ /** The pages packages list in the sidebar. */ export let destinationOffers = ()=>offered.destinations;
26
+ //# sourceMappingURL=offers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offers.js","sources":["./offers.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,yEAAyE;AAoBzE,IAAI,UAAuE;EACzE,MAAM,EAAE;EACR,cAAc,EAAE;AAClB;AAEA;;iCAEiC,GACjC,OAAO,IAAI,cAAc,CACvB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,EAInC;EAED,IAAI,QAAQ;EACZ,UAAU;IAAE;IAAM;IAAM;EAAa;EACrC,OAAO;IACL,UAAU;EACZ;AACF,EAAC;AAED,iDAAiD,GACjD,OAAO,IAAI,YAAY,IAAwB,QAAQ,IAAI,CAAA;AAE3D,qDAAqD,GACrD,OAAO,IAAI,YAAY,IAAe,QAAQ,IAAI,CAAA;AAElD,4CAA4C,GAC5C,OAAO,IAAI,oBAAoB,IAAqB,QAAQ,YAAY,CAAA"}
@@ -0,0 +1,54 @@
1
+ // What packages offer the app's places from their `./views` facets, beside
2
+ // their renderers: the owner's home page, the tabs on what their views draw
3
+ // and the pages the sidebar lists. The door sets them once, before the app
4
+ // paints (./inspect.tsx `contribute`); a config whose packages offer none
5
+ // leaves `/` the host's own list and every entity on the app's own tabs.
6
+ import type { Bundle, Io } from 'jsr:@yaks/inspect@0.2.36'
7
+ import type { Destination } from '../navigation.ts'
8
+
9
+ /** A view a package offers as a place: a tab on each entity it draws. */
10
+ export type Offer = {
11
+ /** the view drawn there */
12
+ view: string
13
+ /** the glyph its tab or sidebar line wears, by name (./icons.tsx) */
14
+ icon: string
15
+ /** how many things wait there for the entity drawn: a hook, called as the
16
+ * place paints, through the same `io` as the package's views; undefined
17
+ * while it is unknown */
18
+ waiting?: (e: Bundle, io: Io) => number | undefined
19
+ }
20
+
21
+ /** The owner's home page: `/` draws the owner in `view`, and the sidebar's
22
+ * first line is `name`, wearing `icon` and what waits there. */
23
+ export type Home = Offer & { name: string }
24
+
25
+ let offered: { home?: Home; tabs: Offer[]; destinations: Destination[] } = {
26
+ tabs: [],
27
+ destinations: [],
28
+ }
29
+
30
+ /** Set what the configured packages offer: a home page, and every tab and
31
+ * destination in the order the packages come. The function returned puts
32
+ * back what was offered before. */
33
+ export let offerPlaces = (
34
+ { home, tabs = [], destinations = [] }: {
35
+ home?: Home
36
+ tabs?: Offer[]
37
+ destinations?: Destination[]
38
+ },
39
+ ): () => void => {
40
+ let prior = offered
41
+ offered = { home, tabs, destinations }
42
+ return () => {
43
+ offered = prior
44
+ }
45
+ }
46
+
47
+ /** The home page a package offers, if one does. */
48
+ export let homeOffer = (): Home | undefined => offered.home
49
+
50
+ /** The tabs packages offer, ahead of the app's own. */
51
+ export let tabOffers = (): Offer[] => offered.tabs
52
+
53
+ /** The pages packages list in the sidebar. */
54
+ export let destinationOffers = (): Destination[] => offered.destinations
@@ -0,0 +1,21 @@
1
+ // View state belongs to the page's graph. Stable places survive remounts;
2
+ // subscriptions last only as long as the parts that read them.
3
+ import { useRows } from "@yaks/ux";
4
+ import { derivedEid } from "@yaks/graph/identity";
5
+ import { front } from './fields.tsx';
6
+ export let usePage = (name, place)=>{
7
+ let eid = derivedEid(`${name}|${place}`);
8
+ let [row] = useRows(front, `.${name} .entity.eid=${eid}`);
9
+ return {
10
+ value: row?.[name],
11
+ set: (value)=>void front.mutate([
12
+ {
13
+ entity: {
14
+ eid
15
+ },
16
+ [name]: value
17
+ }
18
+ ])
19
+ };
20
+ };
21
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sources":["./page.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+DAA+D;AAC/D,SAAS,OAAO,wBAA6B;AAC7C,SAAS,UAAU,oCAAyC;AAC5D,SAAS,KAAK,QAAQ,eAAc;AAEpC,OAAO,IAAI,UAAU,CACnB,MACA;EAEA,IAAI,MAAM,WAAW,GAAG,KAAK,CAAC,EAAE,OAAO;EACvC,IAAI,CAAC,IAAI,GAAG,QAAQ,OAAO,CAAC,CAAC,EAAE,KAAK,aAAa,EAAE,KAAK;EACxD,OAAO;IACL,OAAO,KAAK,CAAC,KAAK;IAClB,KAAK,CAAC,QACJ,KAAK,MAAM,MAAM,CAAC;QAAC;UAAE,QAAQ;YAAE;UAAI;UAAG,CAAC,KAAK,EAAE;QAAM;OAAE;EAC1D;AACF,EAAC"}
@@ -0,0 +1,18 @@
1
+ // View state belongs to the page's graph. Stable places survive remounts;
2
+ // subscriptions last only as long as the parts that read them.
3
+ import { useRows } from '@yaks/ux'
4
+ import { derivedEid } from '@yaks/graph/identity'
5
+ import { front } from './fields.tsx'
6
+
7
+ export let usePage = <T extends Record<string, unknown>>(
8
+ name: string,
9
+ place: string,
10
+ ) => {
11
+ let eid = derivedEid(`${name}|${place}`)
12
+ let [row] = useRows(front, `.${name} .entity.eid=${eid}`)
13
+ return {
14
+ value: row?.[name] as T | undefined,
15
+ set: (value: Partial<T>) =>
16
+ void front.mutate([{ entity: { eid }, [name]: value }]),
17
+ }
18
+ }