@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,160 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // ANSI output rendered as inert Preact nodes. SGR presentation has a faithful
3
+ // HTML equivalent; terminal commands and control bytes have none, so they
4
+ // disappear rather than reaching the page or becoming visible garbage.
5
+
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import { Fragment } from 'npm:react@19.3.0'
7
+
8
+ type Face = {
9
+ bold?: boolean
10
+ dim?: boolean
11
+ italic?: boolean
12
+ underline?: boolean
13
+ strike?: boolean
14
+ color?: string
15
+ backgroundColor?: string
16
+ }
17
+
18
+ export type AnsiRun = { text: string; face: Face }
19
+
20
+ let BASIC = [
21
+ '#4b565c',
22
+ '#e67e80',
23
+ '#a7c080',
24
+ '#dbbc7f',
25
+ '#7fbbb3',
26
+ '#d699b6',
27
+ '#83c092',
28
+ '#d3c6aa',
29
+ '#7a8478',
30
+ '#e67e80',
31
+ '#a7c080',
32
+ '#dbbc7f',
33
+ '#7fbbb3',
34
+ '#d699b6',
35
+ '#83c092',
36
+ '#fff9e8',
37
+ ]
38
+
39
+ let color = (n: number) => {
40
+ if (n < 16) return BASIC[n]
41
+ if (n < 232) {
42
+ let i = n - 16
43
+ let part = (x: number) => x ? 55 + x * 40 : 0
44
+ return `rgb(${part(Math.floor(i / 36))}, ${part(Math.floor(i / 6) % 6)}, ${
45
+ part(i % 6)
46
+ })`
47
+ }
48
+ let gray = 8 + (n - 232) * 10
49
+ return `rgb(${gray}, ${gray}, ${gray})`
50
+ }
51
+
52
+ let paint = (face: Face, codes: number[]) => {
53
+ let next = { ...face }
54
+ for (let i = 0; i < codes.length; i++) {
55
+ let n = codes[i]
56
+ if (n == 0) next = {}
57
+ else if (n == 1) next.bold = true
58
+ else if (n == 2) next.dim = true
59
+ else if (n == 3) next.italic = true
60
+ else if (n == 4) next.underline = true
61
+ else if (n == 9) next.strike = true
62
+ else if (n == 22) delete next.bold, delete next.dim
63
+ else if (n == 23) delete next.italic
64
+ else if (n == 24) delete next.underline
65
+ else if (n == 29) delete next.strike
66
+ else if ((n >= 30 && n <= 37) || (n >= 90 && n <= 97)) {
67
+ next.color = BASIC[n < 90 ? n - 30 : n - 82]
68
+ } else if ((n >= 40 && n <= 47) || (n >= 100 && n <= 107)) {
69
+ next.backgroundColor = BASIC[n < 100 ? n - 40 : n - 92]
70
+ } else if (n == 39) delete next.color
71
+ else if (n == 49) delete next.backgroundColor
72
+ else if ((n == 38 || n == 48) && codes[i + 1] == 5) {
73
+ let value = codes[i + 2]
74
+ if (value >= 0 && value <= 255) {
75
+ next[n == 38 ? 'color' : 'backgroundColor'] = color(value)
76
+ }
77
+ i += 2
78
+ } else if ((n == 38 || n == 48) && codes[i + 1] == 2) {
79
+ let rgb = codes.slice(i + 2, i + 5)
80
+ if (rgb.length == 3 && rgb.every((x) => x >= 0 && x <= 255)) {
81
+ next[n == 38 ? 'color' : 'backgroundColor'] = `rgb(${rgb.join(', ')})`
82
+ }
83
+ i += 4
84
+ }
85
+ }
86
+ return next
87
+ }
88
+
89
+ // deno-lint-ignore no-control-regex -- these are precisely the unsafe terminal controls.
90
+ const controls = /[\x00-\x08\x0b-\x1f\x7f-\x9f]/g
91
+
92
+ // Drop only the control ranges; splitting every Unicode character into an
93
+ // array made ordinary tool output pay for a terminal parser on every paint.
94
+ let visible = (text: string) => text.replace(controls, '')
95
+
96
+ export let ansiRuns = (text: string): AnsiRun[] => {
97
+ if (!text.includes('\x1b')) {
98
+ let plain = visible(text)
99
+ return plain ? [{ text: plain, face: {} }] : []
100
+ }
101
+ let out: AnsiRun[] = [], face: Face = {}, at = 0
102
+ let push = (end: number) => {
103
+ let text = visible(textAt(at, end))
104
+ if (text) out.push({ text, face: { ...face } })
105
+ }
106
+ let textAt = (start: number, end: number) => text.slice(start, end)
107
+ for (let i = 0; i < text.length;) {
108
+ if (text[i] != '\x1b') {
109
+ i++
110
+ continue
111
+ }
112
+ push(i)
113
+ if (text[i + 1] == '[') {
114
+ let end = text.slice(i + 2).search(/[\x40-\x7e]/)
115
+ if (end < 0) return out
116
+ end += i + 2
117
+ if (text[end] == 'm') {
118
+ let raw = text.slice(i + 2, end)
119
+ let codes = raw ? raw.split(';').map(Number) : [0]
120
+ if (codes.every(Number.isFinite)) face = paint(face, codes)
121
+ }
122
+ at = i = end + 1
123
+ } else if (text[i + 1] == ']') {
124
+ let rest = text.slice(i + 2)
125
+ let bel = rest.indexOf('\x07')
126
+ let st = rest.indexOf('\x1b\\')
127
+ let end = bel < 0 ? st : st < 0 ? bel : Math.min(bel, st)
128
+ if (end < 0) return out
129
+ at = i = i + 2 + end + (end == st ? 2 : 1)
130
+ } else at = i = Math.min(i + 2, text.length)
131
+ }
132
+ push(text.length)
133
+ return out
134
+ }
135
+
136
+ let classes = (face: Face) =>
137
+ ['bold', 'dim', 'italic', 'underline', 'strike']
138
+ .filter((name) => face[name as keyof Face])
139
+ .map((name) => `Ansi-${name}`).join(' ')
140
+
141
+ export let Ansi = ({ text }: { text: string }) => (
142
+ <Fragment>
143
+ {ansiRuns(text).map((run, i) => {
144
+ let className = classes(run.face)
145
+ let style = {
146
+ ...run.face.color ? { color: run.face.color } : {},
147
+ ...run.face.backgroundColor
148
+ ? { backgroundColor: run.face.backgroundColor }
149
+ : {},
150
+ }
151
+ return className || style.color || style.backgroundColor
152
+ ? (
153
+ <span key={i} className={className || undefined} style={style}>
154
+ {run.text}
155
+ </span>
156
+ )
157
+ : run.text
158
+ })}
159
+ </Fragment>
160
+ )
@@ -0,0 +1,446 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { Refused, useObserved } from 'jsr:@yaks/ux@0.2.36'
3
+ import { useDerived } from './read.ts'
4
+ import { InspectPage, PagePart, PastPage } from './inspect.tsx'
5
+ import { hosting } from '../hosting.ts'
6
+ import { back, forward, left, scrolledTo } from '../history.ts'
7
+ import {
8
+ configAt,
9
+ destinationAt,
10
+ newAt,
11
+ newPath,
12
+ schemaAt,
13
+ } from '../navigation.ts'
14
+ import { addressId, entityPath, searchAt } from '../url.ts'
15
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useRef } from 'npm:react@19.3.0'
16
+ import { walk } from 'jsr:@yaks/ux@0.2.36/keys'
17
+ import { idOf } from '../types.ts'
18
+ import { config, ent, entityRead, mode, myClient, useHold } from '../live.ts'
19
+ import { block, Loading, Section, Shell, Tabs, Viewport } from 'jsr:@yaks/ui@0.2.36'
20
+ import { filterable, FilterInput } from './Filter.tsx'
21
+ import { applicable } from './registry.ts'
22
+ import { TabFace } from './Card.tsx'
23
+ import { Icon } from './icons.tsx'
24
+ import { homeOffer } from './offers.ts'
25
+ import {
26
+ follow,
27
+ Menu,
28
+ menu,
29
+ navigate,
30
+ route,
31
+ screenBuried,
32
+ screenGone,
33
+ screenResolving,
34
+ screenTarget,
35
+ } from './nav.tsx'
36
+ import { useDrafts } from '../domain-host.tsx'
37
+ import { Run, run } from './Run.tsx'
38
+ import { Search, searchOpen, SearchPage } from './Search.tsx'
39
+ import { Status } from './Status.tsx'
40
+ import { Entity } from './Entity.tsx'
41
+ import { tips } from 'jsr:@yaks/ui@0.2.36'
42
+ import { Keybindings } from './Keybindings.tsx'
43
+ import {
44
+ allDestinations,
45
+ Navigation,
46
+ openSidebar,
47
+ SidebarMenu,
48
+ sidebarOpen,
49
+ titleAt,
50
+ } from './Navigation.tsx'
51
+ import { QueryList } from './views/List.tsx'
52
+ import { Id } from './views/Inline.tsx'
53
+ import { refusalOf, retryOf } from './answered.ts'
54
+ import { Configuration } from './Configuration.tsx'
55
+ import { New } from './New.tsx'
56
+ import { Peek } from './Peek.tsx'
57
+ import { MarkdownHost } from './Markdown.tsx'
58
+ import { Fault } from './Fault.tsx'
59
+
60
+ tips() // mount the one delegated [data-tip] tooltip (idempotent)
61
+
62
+ let { Tab } = Tabs
63
+
64
+ // The URL named nothing the cache can resolve — a typo'd id, a dead
65
+ // entity, a foreign graph's number. The 404 face keeps the whole shell
66
+ // (the sidebar, `/` search, the : statusbar): a dead link offers the doors,
67
+ // never a blank wall.
68
+ let LostFrame = block('section', 'Lost', {
69
+ Code: 'p',
70
+ Id: 'code',
71
+ Hint: 'p',
72
+ Key: 'kbd',
73
+ })
74
+ let { Code, Hint } = LostFrame
75
+ let Lost = ({ at }: { at: string }) => {
76
+ let path = new URL(at, 'http://x').pathname
77
+ return (
78
+ <LostFrame>
79
+ <Code>404</Code>
80
+ <p>
81
+ <LostFrame.Id>{decodeURIComponent(path)}</LostFrame.Id>{' '}
82
+ names nothing here — a mistyped id, or an entity that's gone.
83
+ </p>
84
+ <Hint>
85
+ press <LostFrame.Key>/</LostFrame.Key> to search, or{' '}
86
+ <a href='/' onClick={follow('/')}>
87
+ head home
88
+ </a>
89
+ </Hint>
90
+ </LostFrame>
91
+ )
92
+ }
93
+
94
+ // The id is real but outside the working set, and its server resolve is in
95
+ // flight (nav.tsx screenResolving) — the honest interim between a cache miss
96
+ // and the answer, so a slow addressed subscription reads as "loading", never a false 404
97
+ // (M-16612). It settles to the entity or to Lost when the resolve lands.
98
+ let Resolving = ({ at }: { at: string }) => {
99
+ let path = new URL(at, 'http://x').pathname
100
+ return <Loading>Loading {decodeURIComponent(path)}…</Loading>
101
+ }
102
+
103
+ // The one page the address names, under its bar: `/` is home (the owner, in
104
+ // the home page a package offers, or the host's own list where none does),
105
+ // `/T-123` that entity with `?v=` picking its view, `/?.task` a search,
106
+ // `/?page=map` the schema and `/?page=<key>` a destination's list. The bar says what
107
+ // the page is and holds what it offers: a filter, its views, its menu.
108
+ export let Page = ({ at }: { at: string }) => {
109
+ // Hold a route sub for the entity while it's the page — under a partial
110
+ // cache an entity reached by direct URL is in no defining set, so this is
111
+ // what loads it; a no-op under a whole-graph cache.
112
+ let url = new URL(at, 'http://x')
113
+ let search = searchAt(at)
114
+ let making = newAt(at)
115
+ // `?at=<transaction>` reads the entity as it was just after it; an id that
116
+ // names a deleted entity reads what it held last.
117
+ let past = url.searchParams.get('at') ?? undefined
118
+ let scroll = useObserved(left)
119
+ let buried = useDerived(() => screenBuried(at), [at])
120
+ let place = destinationAt(at, allDestinations())
121
+ let t = useDerived(() => screenTarget(at), [at])
122
+ let home = url.pathname == '/' && !url.search
123
+ let offered = home ? homeOffer() : undefined
124
+ // The owner's home page holds what its view asks, never the owner's
125
+ // neighborhood, and opening it is not opening the owner.
126
+ // Keep the addressed subscription when its answer resolves a human id to
127
+ // a canonical eid. Its existing membership already proves that identity;
128
+ // replacing it would throw away readiness and fetch the same row again.
129
+ let rootEid = offered
130
+ ? undefined
131
+ : addressId(decodeURIComponent(url.pathname.slice(1))) ?? t?.eid
132
+ useHold(rootEid && { entity: rootEid })
133
+ let { read, e } = useDerived(() => {
134
+ let read = rootEid && config.host
135
+ ? entityRead(rootEid, undefined, t?.eid)
136
+ : undefined
137
+ let e = read?.ready ? read.value : t ? ent(t.eid) : undefined
138
+ return { read, e }
139
+ }, [rootEid, t])
140
+ let tabs = e ? applicable(e) : []
141
+ // A coarse pointer with no explicit view defaults a Canvas to List: its
142
+ // spatial face eagerly renders every pinned card and floods a phone (the
143
+ // mobile door, views/List.tsx). Other pages keep their first face.
144
+ let coarse = globalThis.matchMedia?.('(pointer: coarse)').matches
145
+ let view = t?.view && tabs.includes(t.view)
146
+ ? t.view
147
+ : coarse && tabs[0] == 'Canvas' && tabs.includes('List')
148
+ ? 'List'
149
+ : tabs[0]
150
+ let show = (v: string) => {
151
+ let url = new URL(at, 'http://x')
152
+ if (v == tabs[0]) url.searchParams.delete('v')
153
+ else url.searchParams.set('v', v)
154
+ navigate(url.pathname + url.search, { replace: true })
155
+ }
156
+ // Home is the owner in the home page a package offers, or the host's own
157
+ // list where none does; either way it is named for itself, never for the
158
+ // person.
159
+ let list = home && !offered
160
+ let named = titleAt(at)
161
+ let page = home ? undefined : e
162
+ let filter = place
163
+ ? place.query ? `destination:${place.key}` : undefined
164
+ : list
165
+ ? 'app-browse'
166
+ : page && filterable.has(view ?? '')
167
+ ? page.eid
168
+ : undefined
169
+ return (
170
+ <>
171
+ <Shell.Bar>
172
+ <SidebarMenu />
173
+ <Shell.Title>
174
+ {page
175
+ ? (
176
+ <>
177
+ <Id e={page} />
178
+ <Entity eid={page.eid} view='Bar.Title' />
179
+ </>
180
+ )
181
+ : search != null
182
+ ? (
183
+ <>
184
+ <Shell.Icon>
185
+ <Icon className='Shell_Glyph' name='search' size={16} />
186
+ </Shell.Icon>
187
+ Search
188
+ </>
189
+ )
190
+ : making
191
+ ? (
192
+ <>
193
+ <Shell.Icon>
194
+ <Icon className='Shell_Glyph' name='plus' size={16} />
195
+ </Shell.Icon>
196
+ New
197
+ </>
198
+ )
199
+ : named && (
200
+ <>
201
+ <Shell.Icon>
202
+ <Icon className='Shell_Glyph' name={named.icon} size={16} />
203
+ </Shell.Icon>
204
+ {named.name}
205
+ </>
206
+ )}
207
+ </Shell.Title>
208
+ <Shell.Tools>
209
+ {filter && <FilterInput eid={filter} />}
210
+ {page && (
211
+ <Tabs>
212
+ {tabs.length > 1 && tabs.map((v) => (
213
+ <Tab
214
+ type='button'
215
+ key={v}
216
+ mod={v == view && 'on'}
217
+ aria-label={v}
218
+ data-tip={v}
219
+ onClick={() => v != view && show(v)}
220
+ >
221
+ <TabFace view={v} eid={page.eid} />
222
+ </Tab>
223
+ ))}
224
+ {
225
+ /* The page's dropdown: the same menu a card's right-click
226
+ serves, hung from the bar's far edge. Pointerdown must not
227
+ bubble — the shell's close-on-press would eat the toggle. */
228
+ }
229
+ <Tab
230
+ type='button'
231
+ aria-label='Menu'
232
+ data-tip='menu'
233
+ onPointerDown={(ev: Event) => ev.stopPropagation()}
234
+ onClick={(
235
+ ev: MouseEvent & { currentTarget: HTMLElement },
236
+ ) => {
237
+ if (menu.value) {
238
+ menu.value = null
239
+ return
240
+ }
241
+ let r = ev.currentTarget.getBoundingClientRect()
242
+ menu.value = {
243
+ x: r.right,
244
+ y: r.bottom,
245
+ href: entityPath(idOf(page)),
246
+ eid: page.eid,
247
+ align: 'right',
248
+ }
249
+ }}
250
+ >
251
+ <Icon name='ellipsis-vertical' />
252
+ </Tab>
253
+ </Tabs>
254
+ )}
255
+ </Shell.Tools>
256
+ </Shell.Bar>
257
+ <Viewport
258
+ id={`browse:${at}`}
259
+ className='Shell_Body'
260
+ start={scroll}
261
+ onScroll={scrolledTo}
262
+ >
263
+ {configAt(at)
264
+ ? <Configuration />
265
+ : making
266
+ ? <New at={making} />
267
+ : schemaAt(at)
268
+ ? <InspectPage map />
269
+ : search != null
270
+ ? <SearchPage query={search} />
271
+ : place
272
+ ? (
273
+ <>
274
+ {place.view && <PagePart view={place.view} />}
275
+ {place.query && <QueryList eid={filter!} query={place.query} />}
276
+ </>
277
+ )
278
+ : !e && screenGone(at)
279
+ ? buried
280
+ ? (
281
+ <PastPage
282
+ eid={buried}
283
+ id={buried}
284
+ at={past}
285
+ lost={<Lost at={at} />}
286
+ />
287
+ )
288
+ : <Lost at={at} />
289
+ : read?.state.status == 'failed'
290
+ ? (
291
+ <Refused
292
+ failed='This page could not load.'
293
+ refused={refusalOf(read)!}
294
+ retry={retryOf(read)}
295
+ />
296
+ )
297
+ : read && !read.ready
298
+ ? <Loading />
299
+ : past && e
300
+ ? (
301
+ <PastPage
302
+ eid={e.eid}
303
+ id={idOf(e)}
304
+ at={past}
305
+ lost={<Lost at={at} />}
306
+ />
307
+ )
308
+ : offered && e
309
+ ? <Entity eid={e.eid} view={offered.view} />
310
+ : e
311
+ ? <Entity eid={e.eid} view={view} />
312
+ : list
313
+ ? (
314
+ <>
315
+ <Section>
316
+ <Section.Title>Browse the graph</Section.Title>
317
+ <Section.Sub>
318
+ {hosting().home
319
+ ? (
320
+ <>
321
+ Entities matching <code>{hosting().home!.query}</code>.
322
+ </>
323
+ )
324
+ : (
325
+ <>
326
+ Entities with documents, newest created first. Recent
327
+ shows entities you opened, most recently opened first.
328
+ </>
329
+ )} Use the filter to narrow this list.
330
+ </Section.Sub>
331
+ </Section>
332
+ <QueryList
333
+ eid='app-browse'
334
+ query={hosting().home?.query ?? '.doc'}
335
+ />
336
+ </>
337
+ )
338
+ : offered
339
+ ? (
340
+ <LostFrame>
341
+ <h1>{offered.name}</h1>
342
+ <p>No owner is named for this app.</p>
343
+ </LostFrame>
344
+ )
345
+ : screenResolving(at)
346
+ ? <Resolving at={at} />
347
+ : <Lost at={at} />}
348
+ </Viewport>
349
+ </>
350
+ )
351
+ }
352
+
353
+ export let App = () => {
354
+ // What the app draws for this person everywhere inside it: their drafts,
355
+ // and this tab's own screen rows (cursor, camera, folds, shelf).
356
+ useDrafts()
357
+ let me = useDerived(myClient, [])
358
+ let path = useObserved(route)
359
+ let sidebar = useDerived(sidebarOpen, [])
360
+ useHold(me && { client: me })
361
+ // `/` raises the search palette over ANY page — canvas, doc, board.
362
+ // The shell owns the hotkey and the one <Search> mount so any page can
363
+ // search; a pick opens the hit as the page in its default view.
364
+ useEffect(() => {
365
+ // `n` opens New the same way, unmodified, so a shortcut keeps its own.
366
+ let key = (e: KeyboardEvent) => {
367
+ let n = e.key == 'n' && !e.ctrlKey && !e.metaKey && !e.altKey
368
+ if (mode.value != 'normal' || e.repeat || e.key != '/' && !n) return
369
+ if (
370
+ e.target instanceof HTMLElement &&
371
+ e.target.matches('input, textarea, select, [contenteditable]')
372
+ ) return
373
+ e.preventDefault()
374
+ if (n) navigate(newPath())
375
+ else searchOpen.value = true
376
+ }
377
+ addEventListener('keydown', key)
378
+ return () => removeEventListener('keydown', key)
379
+ }, [])
380
+ // Vim's keys move a cursor over the whole frame, the sidebar and the page,
381
+ // or over the peek, menu or popover in front (@yaks/ux/keys); a walk from
382
+ // nowhere starts in the page. On the document, so a terminal's keydown
383
+ // reaches it as a browser's does. They rest on the command line and over a
384
+ // selection; insert mode is a field's own focus, which the walk leaves be.
385
+ let shell = useRef<HTMLElement>(null)
386
+ useEffect(() => {
387
+ let keys = walk({
388
+ surface: () => shell.current,
389
+ start: () => shell.current?.querySelector('.Shell_Main'),
390
+ back,
391
+ forward,
392
+ })
393
+ let key = (e: KeyboardEvent) =>
394
+ mode.value != 'command' && mode.value != 'visual' && keys.key(e)
395
+ document.addEventListener('keydown', key)
396
+ document.addEventListener('pointerdown', keys.point)
397
+ return () => {
398
+ document.removeEventListener('keydown', key)
399
+ document.removeEventListener('pointerdown', keys.point)
400
+ }
401
+ }, [])
402
+ return (
403
+ <MarkdownHost>
404
+ <Shell
405
+ elRef={shell}
406
+ mod={sidebar && 'open'}
407
+ onPointerDown={() => {
408
+ menu.value = null
409
+ run.value = null
410
+ }}
411
+ >
412
+ <Fault place='Navigation'>
413
+ <Navigation />
414
+ </Fault>
415
+ <Shell.Shade
416
+ type='button'
417
+ aria-label='Close navigation'
418
+ onClick={() => openSidebar(false)}
419
+ />
420
+ <Shell.Main>
421
+ <Fault key={path} place='Page'>
422
+ <Page at={path} />
423
+ </Fault>
424
+ <Fault place='Status'>
425
+ <Status />
426
+ </Fault>
427
+ </Shell.Main>
428
+ <Fault place='Peek'>
429
+ <Peek />
430
+ </Fault>
431
+ <Fault place='Menu'>
432
+ <Menu />
433
+ </Fault>
434
+ <Fault place='Run'>
435
+ <Run />
436
+ </Fault>
437
+ <Fault place='Search'>
438
+ <Search open={(eid) => navigate(entityPath(idOf(ent(eid))))} />
439
+ </Fault>
440
+ <Fault place='Keybindings'>
441
+ <Keybindings />
442
+ </Fault>
443
+ </Shell>
444
+ </MarkdownHost>
445
+ )
446
+ }