@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,490 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // New: Debug on an empty entity. A person adds components by searching the
3
+ // vocabulary, types or picks each property, and may outline more entities
4
+ // like it, one a line, nested by indent. The batch they become shows as it is
5
+ // typed and is written whole on Create, held until the server takes it, so a
6
+ // refusal lands beside the field it names and nothing half-made shows. What
7
+ // is typed is the person's draft (../new.ts), kept and seen in every
8
+ // interface. Every control is a kit field or button, so a terminal draws and
9
+ // drives the same page.
10
+ /* @ts-types="npm:@types/react@19.3.0" */ import { type ReactNode, useLayoutEffect, useRef, useState } from 'npm:react@19.3.0'
11
+ import * as ui from 'jsr:@yaks/ui@0.2.36'
12
+ import { label, pickLine, reading, useDraft, useHits } from 'jsr:@yaks/ux@0.2.36'
13
+ import { drafts } from 'jsr:@yaks/draft@0.2.36/input'
14
+ import { editKeys } from 'jsr:@yaks/ux@0.2.36/edit-keys'
15
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
16
+ import {
17
+ ent,
18
+ findEid,
19
+ relations,
20
+ resolveGen,
21
+ resolvingId,
22
+ serverEid,
23
+ submit,
24
+ useHold,
25
+ } from '../live.ts'
26
+ import {
27
+ comps,
28
+ EID,
29
+ IdError,
30
+ idIn,
31
+ idOf,
32
+ type PropType,
33
+ typeName,
34
+ vocab,
35
+ } from '../types.ts'
36
+ import { entityPath } from '../url.ts'
37
+ import {
38
+ type At,
39
+ type Batch,
40
+ batch,
41
+ find,
42
+ like,
43
+ placed,
44
+ placeOf,
45
+ press,
46
+ type Said,
47
+ type Sketch,
48
+ sketchOf,
49
+ textOf,
50
+ written,
51
+ } from '../new.ts'
52
+ import { ux } from './registry.ts'
53
+ import { navigate } from './nav.tsx'
54
+ import { useReference } from './subscriptions.ts'
55
+ import { Id } from './views/Inline.tsx'
56
+
57
+ let Frame = ui.block('form', 'New', {
58
+ Context: 'p',
59
+ None: 'span',
60
+ Said: 'p',
61
+ Writes: 'pre',
62
+ Bar: 'div',
63
+ })
64
+ let { Context, None, Writes, Bar } = Frame
65
+ let { Item, Text, Note } = ui.Choices
66
+
67
+ // What can't be written as it stands, said in its place.
68
+ let Says = ({ said }: { said: Said[] }) => (
69
+ <>
70
+ {said.map((s, i) => (
71
+ <Frame.Said key={i}>
72
+ {s.line != null && `line ${s.line + 1}: `}
73
+ {s.said}
74
+ </Frame.Said>
75
+ ))}
76
+ </>
77
+ )
78
+
79
+ // An id as the address writes it, as an eid: the cache's, else the
80
+ // server's (resolveGen wakes this when it answers); nothing for one that
81
+ // names nothing.
82
+ let eidOf = (id?: string) => {
83
+ if (!id) return undefined
84
+ resolveGen.value
85
+ try {
86
+ return findEid(id) ?? serverEid(id)
87
+ } catch (error) {
88
+ if (error instanceof IdError) return undefined
89
+ throw error
90
+ }
91
+ }
92
+
93
+ // Where a new child goes in an entity's list: after what it holds.
94
+ let next = (eid?: string) => {
95
+ if (!eid) return 0
96
+ let kids = relations(eid).value.filter((d) => d.type == 'contains')
97
+ return Math.max(kids.length, ...kids.map((d) => (d.ord ?? -1) + 1))
98
+ }
99
+
100
+ // A property's typed text as its value, in the fleet's input language (P2, a
101
+ // relative time, a human id); throws what it cannot read.
102
+ let read = (comp: string, prop: string, text: string) =>
103
+ (reading(ux, { entity: { eid: '$1' } }, comp, prop, text)[comp] as Record<
104
+ string,
105
+ unknown
106
+ >)[prop]
107
+
108
+ // An eid as a person reads it, for what the batch shows; nothing for text.
109
+ let named = (v: string) => EID.test(v) ? idOf(ent(v)) : undefined
110
+
111
+ // A row a keyboard can take in both hosts: Enter or a press picks it.
112
+ let pickable = (pick: () => void) => ({
113
+ role: 'button',
114
+ tabIndex: 0,
115
+ onClick: pick,
116
+ onKeyDown: (ev: KeyboardEvent) => {
117
+ if (ev.key != 'Enter' && ev.key != ' ') return
118
+ ev.preventDefault()
119
+ pick()
120
+ },
121
+ })
122
+
123
+ // A search field whose Enter takes its first answer rather than the form's.
124
+ let Find = (
125
+ { place, hint, first }: { place: string; hint: string; first: () => void },
126
+ ) => (
127
+ <ui.Field
128
+ value={useDraft(place, drafts)}
129
+ placeholder={hint}
130
+ onInput={(ev: InputEvent) =>
131
+ drafts.type(place, (ev.currentTarget as HTMLInputElement).value)}
132
+ onKeyDown={(ev: KeyboardEvent) => {
133
+ if (ev.key != 'Enter') return
134
+ ev.preventDefault()
135
+ first()
136
+ }}
137
+ />
138
+ )
139
+
140
+ // A reference: the entity picked, with a way to let it go; or a search of
141
+ // the graph for the kind it names.
142
+ let Ref = (
143
+ { place, kind, text, set }: {
144
+ place: string
145
+ kind: string
146
+ text: string
147
+ set: (text: string) => void
148
+ },
149
+ ) => {
150
+ let q = useDraft(place, drafts)
151
+ let hits = useHits(
152
+ pickLine(q, kind == 'entity' ? '' : kind),
153
+ 6,
154
+ ux.find,
155
+ ux.settle,
156
+ )
157
+ let held = useReference(text || undefined).value
158
+ let pick = (b?: Bundle) => {
159
+ if (!b) return
160
+ set(b.entity.eid)
161
+ void drafts.spend(place)
162
+ }
163
+ if (text) {
164
+ return (
165
+ <>
166
+ <Id e={held ?? ent(text)} /> {held?.doc?.title ?? ''}{' '}
167
+ <ui.Button
168
+ type='button'
169
+ mod='quiet'
170
+ aria-label={`clear ${kind}`}
171
+ onClick={() => set('')}
172
+ >
173
+ ×
174
+ </ui.Button>
175
+ </>
176
+ )
177
+ }
178
+ return (
179
+ <>
180
+ <Find place={place} hint={`find ${kind}…`} first={() => pick(hits[0])} />
181
+ {q.trim() && (
182
+ <ui.Choices>
183
+ {hits.map((b) => (
184
+ <Item
185
+ key={b.entity.eid}
186
+ {...pickable(() => pick(b))}
187
+ >
188
+ <Text>{label(ux, b)}</Text>
189
+ </Item>
190
+ ))}
191
+ </ui.Choices>
192
+ )}
193
+ </>
194
+ )
195
+ }
196
+
197
+ // A closed set: its members, the one held marked; pressing it again lets it
198
+ // go.
199
+ let Pick = (
200
+ { values, text, set }: {
201
+ values: readonly string[]
202
+ text: string
203
+ set: (text: string) => void
204
+ },
205
+ ) => (
206
+ <ui.Tabs>
207
+ {values.map((v) => (
208
+ <ui.Tabs.Tab
209
+ key={v}
210
+ type='button'
211
+ mod={v == text && 'on'}
212
+ onClick={() => set(v == text ? '' : v)}
213
+ >
214
+ {v}
215
+ </ui.Tabs.Tab>
216
+ ))}
217
+ </ui.Tabs>
218
+ )
219
+
220
+ // A property's control, as its type says: typed, picked from a closed set,
221
+ // or a reference found in the graph.
222
+ let Input = (
223
+ { type, place, text, set }: {
224
+ type: PropType
225
+ place: string
226
+ text: string
227
+ set: (text: string) => void
228
+ },
229
+ ) =>
230
+ type == 'bool'
231
+ ? <Pick values={['true', 'false']} text={text} set={set} />
232
+ : typeof type == 'object' && 'enum' in type
233
+ ? <Pick values={type.enum} text={text} set={set} />
234
+ : typeof type == 'object' && 'eid' in type
235
+ ? <Ref place={place} kind={type.eid} text={text} set={set} />
236
+ : (
237
+ <ui.Field
238
+ className={type == 'body' ? 'New_Body New_Text' : undefined}
239
+ lines={type == 'body'}
240
+ value={text}
241
+ placeholder={typeName(type)}
242
+ onInput={(ev: InputEvent) =>
243
+ set((ev.currentTarget as HTMLInputElement).value)}
244
+ />
245
+ )
246
+
247
+ // The sketch's components, a row per property, each with what is said of
248
+ // it; a component with nothing to type is one row.
249
+ let Fields = (
250
+ { s, place, said, put }: {
251
+ s: Sketch
252
+ place: string
253
+ said: Said[]
254
+ put: (s: Sketch) => void
255
+ },
256
+ ) => (
257
+ <ui.Pairs>
258
+ {Object.entries(s.comps).flatMap(([comp, typed]) => {
259
+ let props = Object.entries(comps[comp] ?? {})
260
+ let drop = (
261
+ <ui.Button
262
+ type='button'
263
+ mod='quiet'
264
+ aria-label={`remove ${comp}`}
265
+ onClick={() => {
266
+ let { [comp]: _, ...rest } = s.comps
267
+ put({ ...s, comps: rest })
268
+ }}
269
+ >
270
+ ×
271
+ </ui.Button>
272
+ )
273
+ let row = (key: string, value: ReactNode, first: boolean) => [
274
+ <ui.Pairs.Key key={`${key}:k`}>{key}{first && drop}</ui.Pairs.Key>,
275
+ <ui.Pairs.Value key={`${key}:v`}>{value}</ui.Pairs.Value>,
276
+ ]
277
+ if (!props.length) return row(comp, <None>no properties</None>, true)
278
+ return props.flatMap(([prop, type], i) =>
279
+ row(
280
+ `${comp}.${prop}`,
281
+ <>
282
+ <Input
283
+ type={type}
284
+ place={`${place}|${comp}.${prop}`}
285
+ text={typed[prop] ?? ''}
286
+ set={(text) =>
287
+ put({
288
+ ...s,
289
+ comps: { ...s.comps, [comp]: { ...typed, [prop]: text } },
290
+ })}
291
+ />
292
+ <Says said={said.filter((x) => x.comp == comp && x.prop == prop)} />
293
+ </>,
294
+ i == 0,
295
+ )
296
+ )
297
+ })}
298
+ </ui.Pairs>
299
+ )
300
+
301
+ // Adding a component: a search of the vocabulary, each answer shown as
302
+ // `comp{prop, …}` and what it is.
303
+ let Add = (
304
+ { s, place, put }: { s: Sketch; place: string; put: (s: Sketch) => void },
305
+ ) => {
306
+ let at = `${place}|find`
307
+ let text = useDraft(at, drafts)
308
+ let hits = find(vocab, text, Object.keys(s.comps))
309
+ let add = (name?: string) => {
310
+ if (!name) return
311
+ put({ ...s, comps: { ...s.comps, [name]: {} } })
312
+ void drafts.spend(at)
313
+ }
314
+ return (
315
+ <>
316
+ <Find
317
+ place={at}
318
+ hint='add a component: type to search the vocabulary'
319
+ first={() => add(hits[0]?.name)}
320
+ />
321
+ {text.trim() && (
322
+ <ui.Choices>
323
+ {hits.map((h) => (
324
+ <Item key={h.name} {...pickable(() => add(h.name))}>
325
+ <Text>{h.signature}</Text>
326
+ <Note>{h.about}</Note>
327
+ </Item>
328
+ ))}
329
+ </ui.Choices>
330
+ )}
331
+ </>
332
+ )
333
+ }
334
+
335
+ // The outline: Enter keeps the line's indent, Tab and Shift+Tab move the
336
+ // line in and out, Escape leaves the field, everything typed kept.
337
+ let leave = editKeys({})
338
+ let Outline = (
339
+ { s, put }: { s: Sketch; put: (s: Sketch) => void },
340
+ ) => (
341
+ <ui.Field
342
+ className='New_Body'
343
+ lines
344
+ value={s.outline}
345
+ placeholder='Outline: one entity a line, like this one; indent a line to put it in the one above'
346
+ onInput={(ev: InputEvent) =>
347
+ put({ ...s, outline: (ev.currentTarget as HTMLTextAreaElement).value })}
348
+ onKeyDown={(ev: KeyboardEvent) => {
349
+ let el = ev.currentTarget as HTMLTextAreaElement
350
+ if (leave(ev)) return
351
+ if (ev.ctrlKey || ev.metaKey || ev.altKey) return
352
+ let to = press(el.value, el.selectionStart ?? 0, ev.key, ev.shiftKey)
353
+ if (!to) return
354
+ ev.preventDefault()
355
+ el.value = to.text
356
+ el.setSelectionRange(to.at, to.at)
357
+ el.setAttribute('data-caret', String(to.at))
358
+ put({ ...s, outline: to.text })
359
+ }}
360
+ />
361
+ )
362
+
363
+ // Where it is made, said once at the top.
364
+ let Where = ({ inEid, likeEid }: { inEid?: string; likeEid?: string }) =>
365
+ inEid || likeEid
366
+ ? (
367
+ <Context>
368
+ {inEid && (
369
+ <>
370
+ in <Id e={ent(inEid)} /> {ent(inEid).doc?.title ?? ''}
371
+ {' '}
372
+ </>
373
+ )}
374
+ {likeEid && likeEid != inEid && (
375
+ <>
376
+ like <Id e={ent(likeEid)} /> {ent(likeEid).doc?.title ?? ''}
377
+ </>
378
+ )}
379
+ </Context>
380
+ )
381
+ : null
382
+
383
+ // The id a made entity is read by, from the server's answer.
384
+ let madeId = (applied: Bundle[], alias?: string) => {
385
+ let b = applied.find((x) => x.$alias == alias)
386
+ return b &&
387
+ idIn(b.entity.eid, b)
388
+ }
389
+
390
+ // The entity to open once the batch is made: the sketch's own, else the one
391
+ // its outline went into, else its first line's.
392
+ let opened = (applied: Bundle[], b: Batch, inEid?: string) => {
393
+ let [first] = b.made
394
+ return first?.line == null
395
+ ? madeId(applied, first?.alias)
396
+ : inEid
397
+ ? idOf(ent(inEid))
398
+ : madeId(applied, first.alias)
399
+ }
400
+
401
+ export let New = ({ at }: { at: At }) => {
402
+ useHold(at.in && { entity: at.in }, at.like && { entity: at.like })
403
+ let inEid = eidOf(at.in), likeEid = eidOf(at.like ?? at.in)
404
+ let form = useRef<HTMLFormElement>(null)
405
+ let [refused, setRefused] = useState<Said>()
406
+ let [busy, setBusy] = useState(false)
407
+ let lost = [at.in, at.like].find((id) => id && !eidOf(id))
408
+ // The keyboard goes to the first field once there is one.
409
+ useLayoutEffect(() => {
410
+ form.current?.querySelector<HTMLElement>('input,textarea')?.focus()
411
+ }, [!!lost])
412
+ if (lost) {
413
+ return resolvingId(lost)
414
+ ? <ui.Loading>Loading {lost}…</ui.Loading>
415
+ : <p>{lost} names nothing here.</p>
416
+ }
417
+ let where: At = { in: inEid, like: at.like ? likeEid : undefined }
418
+ let place = placeOf(where)
419
+ let seed = likeEid ? like(vocab, ent(likeEid)) : { comps: {}, outline: '' }
420
+ let s = sketchOf(useDraft(place, drafts)) ?? seed
421
+ let put = (next: Sketch) => {
422
+ setRefused(undefined)
423
+ drafts.type(place, textOf(next))
424
+ }
425
+ let nests = !!vocab.comp('contains')
426
+ let b = batch(s, { vocab, read, in: inEid, ord: next(inEid) })
427
+ let said = [...b.said, ...refused ? [refused] : []]
428
+ let loose = said.filter((x) => !x.comp)
429
+ let ready = b.bundles.length > 0 && !b.said.length && !busy
430
+ let create = async (ev?: Event) => {
431
+ ev?.preventDefault()
432
+ if (!ready) return
433
+ setBusy(true)
434
+ try {
435
+ let applied = await submit(b.bundles)
436
+ void drafts.spend(place)
437
+ let to = opened(applied, b, inEid)
438
+ if (to) navigate(entityPath(to))
439
+ } catch (error) {
440
+ setRefused(placed(error, b, s))
441
+ } finally {
442
+ setBusy(false)
443
+ }
444
+ }
445
+ let entities = b.made.length, links = b.bundles.length - entities
446
+ return (
447
+ <Frame
448
+ elRef={form}
449
+ onSubmit={create}
450
+ onKeyDown={(ev: KeyboardEvent) => {
451
+ if (ev.key == 'Enter' && (ev.ctrlKey || ev.metaKey || ev.altKey)) {
452
+ void create(ev)
453
+ }
454
+ }}
455
+ >
456
+ <Where inEid={inEid} likeEid={likeEid} />
457
+ <Fields s={s} place={place} said={said} put={put} />
458
+ <Add s={s} place={place} put={put} />
459
+ {nests && <Outline s={s} put={put} />}
460
+ {entities > 0 && (
461
+ <ui.Section>
462
+ <ui.Section.Title>
463
+ Writes
464
+ <ui.Section.Count>
465
+ {entities} {entities == 1 ? 'entity' : 'entities'}
466
+ {links > 0 && `, ${links} ${links == 1 ? 'link' : 'links'}`}
467
+ </ui.Section.Count>
468
+ </ui.Section.Title>
469
+ <Writes>{b.bundles.map((x) => written(x, named)).join('\n')}</Writes>
470
+ </ui.Section>
471
+ )}
472
+ <Says said={loose} />
473
+ <Bar>
474
+ <ui.Button type='submit' mod='go' disabled={!ready}>
475
+ {busy ? 'Creating…' : 'Create'}
476
+ </ui.Button>
477
+ <ui.Button
478
+ type='button'
479
+ mod='quiet'
480
+ onClick={() => {
481
+ setRefused(undefined)
482
+ void drafts.spend(place)
483
+ }}
484
+ >
485
+ Discard
486
+ </ui.Button>
487
+ </Bar>
488
+ </Frame>
489
+ )
490
+ }
@@ -0,0 +1,168 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // The Peek: what a pressed link to an entity opens where a fine pointer reads
3
+ // (nav.tsx openAt). The entity floats over the page it was pressed on, whole,
4
+ // in the Full view its own page draws, with its title and body typed into
5
+ // right there; the page beneath stays where it was. One at a time: a link
6
+ // pressed inside it shows its entity in its place. Its Id and the head's open
7
+ // button go to the entity's page; Esc, q, the close button or a press anywhere
8
+ // else put it away. The head moves it and the corner sizes it. It is a layer
9
+ // (role dialog) to vim's keys (App.tsx, @yaks/ux/keys): Enter on a link opens
10
+ // it, the cursor walks inside it while it is up, and Esc or q sends it
11
+ // `cancel`, which puts it away and hands the cursor back to the link.
12
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useLayoutEffect, useRef } from 'npm:react@19.3.0'
13
+ import { Loading, Peek as Frame, place, Tabs } from 'jsr:@yaks/ui@0.2.36'
14
+ import { useObserved, Ux } from 'jsr:@yaks/ux@0.2.36'
15
+ import { ent, type Peeked, peeked, row, useHold } from '../live.ts'
16
+ import { entityPath } from '../url.ts'
17
+ import { idOf } from '../types.ts'
18
+ import { navigate, route } from './nav.tsx'
19
+ import { applicable, Entity, resolve } from './Entity.tsx'
20
+ import { Id } from './views/Inline.tsx'
21
+ import { Icon } from './icons.tsx'
22
+ import { moved, moveEl, resizeEl } from './drag.ts'
23
+
24
+ let { Head, Body, Grip } = Frame
25
+ let { Tab } = Tabs
26
+
27
+ let close = () => {
28
+ peeked.value = null
29
+ }
30
+
31
+ let patch = (p: Peeked, change: Partial<Peeked>) => {
32
+ if (peeked.peek() == p) peeked.value = { ...p, ...change }
33
+ }
34
+
35
+ // Where it floats: under the link pressed, or over it where only that side
36
+ // has room, and again as what it shows loads and its height settles, until
37
+ // it is moved or sized by hand. Opened without a link, it hangs from the top
38
+ // of the viewport's middle.
39
+ let usePlace = (el: { current: HTMLElement | null }, p: Peeked) =>
40
+ useLayoutEffect(() => {
41
+ let box = el.current
42
+ if (!box || p.left != null) return
43
+ let anchor = p.from?.getBoundingClientRect?.() ??
44
+ { left: innerWidth / 2, top: 48, bottom: 48, width: 0 } as DOMRect
45
+ let put = () => place(box, anchor, 'below')
46
+ put()
47
+ if (typeof ResizeObserver != 'function') return
48
+ let watch = new ResizeObserver(put)
49
+ watch.observe(box)
50
+ return () => watch.disconnect()
51
+ }, [p.from, p.left])
52
+
53
+ // While it is up, a press outside it (and outside the popovers and menus
54
+ // opened from it, which float in an Overlay of their own) puts it away. The
55
+ // link that opened it is not outside: pressing it again opens the entity's
56
+ // page.
57
+ let useDismiss = (p: Peeked) =>
58
+ useLayoutEffect(() => {
59
+ let away = (ev: Event) => {
60
+ let at = ev.target as Element | null
61
+ if (at?.closest?.('.Peek, .Overlay') || p.from?.contains(at)) return
62
+ close()
63
+ }
64
+ document.addEventListener('pointerdown', away)
65
+ return () => document.removeEventListener('pointerdown', away)
66
+ }, [p])
67
+
68
+ let Card = ({ p }: { p: Peeked }) => {
69
+ let root = useRef<HTMLDivElement>(null)
70
+ useHold({ entity: p.eid })
71
+ usePlace(root, p)
72
+ useDismiss(p)
73
+ let e = ent(p.eid)
74
+ let view = applicable(e).includes('Full') ? 'Full' : resolve(e).view
75
+ let open = () => navigate(entityPath(idOf(e)))
76
+
77
+ // The head carries it; a press on one of its links or buttons is that
78
+ // control's.
79
+ let move = (ev: PointerEvent) => {
80
+ let box = root.current!
81
+ if (ev.button != 0 || (ev.target as Element).closest('a, button')) return
82
+ let { offsetLeft: left, offsetTop: top } = box
83
+ moveEl(ev, box, () => 1, () => {}, (dx, dy) => {
84
+ let to = moved(left, top, dx, dy)
85
+ patch(p, { left: to.x, top: to.y })
86
+ })
87
+ }
88
+
89
+ let size = (ev: PointerEvent) => {
90
+ if (ev.button != 0) return
91
+ ev.stopPropagation()
92
+ let box = root.current!
93
+ let was = box.classList.contains('Peek-sized')
94
+ box.classList.add('Peek-sized')
95
+ let { offsetLeft: x, offsetTop: y, offsetWidth: w, offsetHeight: h } = box
96
+ resizeEl(
97
+ ev,
98
+ ev.currentTarget as HTMLElement,
99
+ box,
100
+ { x, y, w, h },
101
+ 'se',
102
+ () => 1,
103
+ (to) => patch(p, { left: x, top: y, w: to.w ?? w, h: to.h ?? h }),
104
+ () => was || box.classList.remove('Peek-sized'),
105
+ )
106
+ }
107
+
108
+ let ready = useObserved(row(p.eid))
109
+ return (
110
+ <Frame
111
+ elRef={root}
112
+ role='dialog'
113
+ aria-label={`${idOf(e)}, peeked`}
114
+ onCancel={close}
115
+ mod={!!(p.w || p.h) && 'sized'}
116
+ style={{
117
+ left: p.left == null ? undefined : `${p.left}px`,
118
+ top: p.top == null ? undefined : `${p.top}px`,
119
+ width: p.w ? `${p.w}px` : undefined,
120
+ height: p.h ? `${p.h}px` : undefined,
121
+ }}
122
+ >
123
+ <Head onPointerDown={move}>
124
+ <Id e={e} />
125
+ <Tabs>
126
+ <Tab
127
+ type='button'
128
+ aria-label='Open'
129
+ data-tip='open its page'
130
+ onClick={open}
131
+ >
132
+ <Icon name='arrow-up-right' />
133
+ </Tab>
134
+ <Tab
135
+ type='button'
136
+ aria-label='Close'
137
+ data-tip='close (Esc)'
138
+ onClick={close}
139
+ >
140
+ <Icon name='x' />
141
+ </Tab>
142
+ </Tabs>
143
+ </Head>
144
+ <Body>
145
+ {ready
146
+ ? (
147
+ // Its own owner, so its editors keep apart from the page's
148
+ // editors of the same values (@yaks/ux).
149
+ <Ux at='Peek'>
150
+ <Entity eid={p.eid} view={view} talkback={false} />
151
+ </Ux>
152
+ )
153
+ : <Loading />}
154
+ </Body>
155
+ <Grip
156
+ onPointerDown={size}
157
+ onDoubleClick={() => patch(p, { w: undefined, h: undefined })}
158
+ />
159
+ </Frame>
160
+ )
161
+ }
162
+
163
+ /** The peek over this page, if one is up. */
164
+ export let Peek = () => {
165
+ let p = useObserved(peeked)
166
+ let path = useObserved(route)
167
+ return p && p.at == path ? <Card key='peek' p={p} /> : null
168
+ }
@@ -0,0 +1,20 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ import { formatProp, propAt } from '../props.ts'
3
+ import { el } from 'jsr:@yaks/ui@0.2.36'
4
+
5
+ let Badge = el('span', 'Prio')
6
+
7
+ // The priority badge: P0 burns, P1 glows, P2 is the quiet default, P3+
8
+ // fades. The label shows the TRUE value (fractional board-order values
9
+ // like 1.5 included); only the colour tier is clamped to 0–3. Like the
10
+ // Dot, the badge is paint — a host that wants a control hangs it on here.
11
+ export let Prio = ({ p, ...rest }: { p: unknown; [x: string]: unknown }) => {
12
+ let face = formatProp(propAt('filed', 'priority')!, p)
13
+ if (!face) return null
14
+ let n = Number(face.slice(1))
15
+ return (
16
+ <Badge mod={String(Math.min(Math.max(Math.round(n), 0), 3))} {...rest}>
17
+ {face}
18
+ </Badge>
19
+ )
20
+ }