@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.
- package/LICENSE +202 -0
- package/README.md +324 -2
- package/_dist/app.d.ts +8 -0
- package/_dist/app.d.ts.map +1 -0
- package/_dist/cli.d.ts +16 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/hosting.d.ts +24 -0
- package/_dist/hosting.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/types.d.ts +5 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/url.d.ts +2 -0
- package/_dist/url.d.ts.map +1 -0
- package/app.js +10 -0
- package/app.js.map +1 -0
- package/app.ts +10 -0
- package/browser-links.js +22 -0
- package/browser-links.js.map +1 -0
- package/browser-links.ts +28 -0
- package/cli.js +172 -0
- package/cli.js.map +1 -0
- package/cli.ts +168 -0
- package/client.js +748 -0
- package/client.js.map +1 -0
- package/client.ts +734 -0
- package/clipboard.js +18 -0
- package/clipboard.js.map +1 -0
- package/clipboard.ts +17 -0
- package/commands.js +1157 -0
- package/commands.js.map +1 -0
- package/commands.ts +1108 -0
- package/components/Ansi.tsx +160 -0
- package/components/App.tsx +446 -0
- package/components/Canvas.tsx +625 -0
- package/components/Card.tsx +276 -0
- package/components/Chat.tsx +205 -0
- package/components/Configuration.tsx +218 -0
- package/components/Decision.tsx +49 -0
- package/components/Dot.tsx +52 -0
- package/components/Entity.tsx +609 -0
- package/components/Fault.tsx +43 -0
- package/components/Filter.tsx +103 -0
- package/components/Keybindings.tsx +100 -0
- package/components/Keys.tsx +67 -0
- package/components/Markdown.tsx +90 -0
- package/components/Navigation.tsx +161 -0
- package/components/New.tsx +490 -0
- package/components/Peek.tsx +168 -0
- package/components/Prio.tsx +20 -0
- package/components/Run.tsx +263 -0
- package/components/Search.tsx +280 -0
- package/components/Stamp.tsx +44 -0
- package/components/Status.tsx +514 -0
- package/components/Sync.tsx +173 -0
- package/components/Tile.tsx +50 -0
- package/components/answered.js +23 -0
- package/components/answered.js.map +1 -0
- package/components/answered.ts +25 -0
- package/components/comp.js +11 -0
- package/components/comp.js.map +1 -0
- package/components/comp.ts +10 -0
- package/components/drag.js +173 -0
- package/components/drag.js.map +1 -0
- package/components/drag.ts +198 -0
- package/components/fields.tsx +90 -0
- package/components/fixtures/README.md +10 -0
- package/components/fixtures/archetypes.json +3646 -0
- package/components/hits.js +63 -0
- package/components/hits.js.map +1 -0
- package/components/hits.ts +84 -0
- package/components/icons.tsx +177 -0
- package/components/inspect.tsx +331 -0
- package/components/mount.ts +79 -0
- package/components/nav.tsx +479 -0
- package/components/offers.js +26 -0
- package/components/offers.js.map +1 -0
- package/components/offers.ts +54 -0
- package/components/page.js +21 -0
- package/components/page.js.map +1 -0
- package/components/page.ts +18 -0
- package/components/read.js +5 -0
- package/components/read.js.map +1 -0
- package/components/read.ts +7 -0
- package/components/registry.js +285 -0
- package/components/registry.js.map +1 -0
- package/components/registry.ts +317 -0
- package/components/session_status.tsx +115 -0
- package/components/subscriptions.js +149 -0
- package/components/subscriptions.js.map +1 -0
- package/components/subscriptions.ts +161 -0
- package/components/title.tsx +21 -0
- package/components/useQuery.js +166 -0
- package/components/useQuery.js.map +1 -0
- package/components/useQuery.ts +211 -0
- package/components/views/Board.tsx +450 -0
- package/components/views/BoardTile.tsx +65 -0
- package/components/views/Dashboard.tsx +148 -0
- package/components/views/Debug.tsx +445 -0
- package/components/views/Dependency.tsx +51 -0
- package/components/views/Entry.tsx +500 -0
- package/components/views/Gist.tsx +28 -0
- package/components/views/Inline.tsx +54 -0
- package/components/views/Json.tsx +19 -0
- package/components/views/Layout.tsx +211 -0
- package/components/views/List.tsx +238 -0
- package/components/views/Md.tsx +43 -0
- package/components/views/Media.tsx +48 -0
- package/components/views/Memory.tsx +32 -0
- package/components/views/Relate.tsx +205 -0
- package/components/views/Search.tsx +42 -0
- package/components/views/Session.tsx +850 -0
- package/components/views/SessionManage.tsx +127 -0
- package/components/views/Show.tsx +758 -0
- package/components/views/Shown.tsx +72 -0
- package/components/views/Split.tsx +58 -0
- package/components/views/TaskTile.tsx +37 -0
- package/components/views/Title.tsx +105 -0
- package/components/views/Wake.tsx +77 -0
- package/components/views/Web.tsx +49 -0
- package/components/wells.js +30 -0
- package/components/wells.js.map +1 -0
- package/components/wells.ts +33 -0
- package/configuration.js +38 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +41 -0
- package/decision_sync.js +88 -0
- package/decision_sync.js.map +1 -0
- package/decision_sync.ts +93 -0
- package/deno.json +1 -0
- package/domain-host.tsx +108 -0
- package/edge.js +193 -0
- package/edge.js.map +1 -0
- package/edge.ts +196 -0
- package/entry_log.js +241 -0
- package/entry_log.js.map +1 -0
- package/entry_log.ts +214 -0
- package/failure.js +22 -0
- package/failure.js.map +1 -0
- package/failure.ts +34 -0
- package/front.json +61 -0
- package/highlight.js +143 -0
- package/highlight.js.map +1 -0
- package/highlight.ts +149 -0
- package/history.js +68 -0
- package/history.js.map +1 -0
- package/history.ts +72 -0
- package/host_commands.js +107 -0
- package/host_commands.js.map +1 -0
- package/host_commands.ts +38 -0
- package/hosting.js +53 -0
- package/hosting.js.map +1 -0
- package/hosting.ts +72 -0
- package/idb.js +14 -0
- package/idb.js.map +1 -0
- package/idb.ts +15 -0
- package/index.js +232 -0
- package/index.js.map +1 -0
- package/index.ts +252 -0
- package/keybindings.js +136 -0
- package/keybindings.js.map +1 -0
- package/keybindings.ts +37 -0
- package/kit.js +103 -0
- package/kit.js.map +1 -0
- package/kit.ts +119 -0
- package/layout.js +254 -0
- package/layout.js.map +1 -0
- package/layout.ts +210 -0
- package/legacy_outbox.js +53 -0
- package/legacy_outbox.js.map +1 -0
- package/legacy_outbox.ts +63 -0
- package/live.js +2883 -0
- package/live.js.map +1 -0
- package/live.ts +3334 -0
- package/live_archetypes.js +92 -0
- package/live_archetypes.js.map +1 -0
- package/live_archetypes.ts +113 -0
- package/live_client.js +145 -0
- package/live_client.js.map +1 -0
- package/live_client.ts +120 -0
- package/main.tsx +5 -0
- package/mod.js +7 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/mount.tsx +50 -0
- package/navigation.js +120 -0
- package/navigation.js.map +1 -0
- package/navigation.ts +152 -0
- package/near.js +83 -0
- package/near.js.map +1 -0
- package/near.ts +83 -0
- package/new.js +295 -0
- package/new.js.map +1 -0
- package/new.ts +361 -0
- package/outbox.js +112 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +129 -0
- package/owner.js +39 -0
- package/owner.js.map +1 -0
- package/owner.ts +37 -0
- package/package.json +81 -4
- package/paste.js +157 -0
- package/paste.js.map +1 -0
- package/paste.ts +122 -0
- package/props.js +303 -0
- package/props.js.map +1 -0
- package/props.ts +358 -0
- package/providers.js +136 -0
- package/providers.js.map +1 -0
- package/providers.ts +194 -0
- package/query.js +987 -0
- package/query.js.map +1 -0
- package/query.ts +1113 -0
- package/remote.js +37 -0
- package/remote.js.map +1 -0
- package/remote.ts +46 -0
- package/resolver.js +149 -0
- package/resolver.js.map +1 -0
- package/resolver.ts +213 -0
- package/rfc2047.js +37 -0
- package/rfc2047.js.map +1 -0
- package/rfc2047.ts +40 -0
- package/row_holds.js +107 -0
- package/row_holds.js.map +1 -0
- package/row_holds.ts +93 -0
- package/served.ts +42 -0
- package/session_worktree.js +7 -0
- package/session_worktree.js.map +1 -0
- package/session_worktree.ts +16 -0
- package/sessions.js +57 -0
- package/sessions.js.map +1 -0
- package/sessions.ts +53 -0
- package/sha.js +161 -0
- package/sha.js.map +1 -0
- package/sha.ts +164 -0
- package/styles.css +2823 -0
- package/subs.js +36 -0
- package/subs.js.map +1 -0
- package/subs.ts +40 -0
- package/terminal-route.js +13 -0
- package/terminal-route.js.map +1 -0
- package/terminal-route.ts +17 -0
- package/terminal.js +251 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +186 -0
- package/time.js +142 -0
- package/time.js.map +1 -0
- package/time.ts +133 -0
- package/title.js +25 -0
- package/title.js.map +1 -0
- package/title.ts +50 -0
- package/tui/doc.ts +6 -0
- package/tui/testing.ts +19 -0
- package/twin.js +11 -0
- package/twin.js.map +1 -0
- package/twin.ts +13 -0
- package/types.js +456 -0
- package/types.js.map +1 -0
- package/types.ts +1370 -0
- package/url.js +77 -0
- package/url.js.map +1 -0
- package/url.ts +85 -0
- package/verb.js +82 -0
- package/verb.js.map +1 -0
- package/verb.ts +137 -0
- package/warmth.js +41 -0
- package/warmth.js.map +1 -0
- package/warmth.ts +54 -0
- package/wire.js +86 -0
- package/wire.js.map +1 -0
- package/wire.ts +63 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// The reactive query hook — the door a component uses to ask "which entities
|
|
2
|
+
// match this query", in place of `Object.values(cache.value).filter` (T-17036,
|
|
3
|
+
// the 16ms frame budget). It parses the query once, holds a NARROW result
|
|
4
|
+
// signal for the component's life (releasing it on unmount), and reads it — so
|
|
5
|
+
// the component re-renders only when its RESULT changes, never on an unrelated
|
|
6
|
+
// patch. The query is the query.ts filter grammar boards and graph_query speak
|
|
7
|
+
// (`.task.status=open`, `.deliver.to=S-31`, …); references resolve to eids at
|
|
8
|
+
// parse.
|
|
9
|
+
//
|
|
10
|
+
// The signal's backing is the store-agnostic seam (live.ts queryEids): today an
|
|
11
|
+
// in-memory index, tomorrow an IDB indexed cursor — the call site never
|
|
12
|
+
// changes (T-17046).
|
|
13
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useLayoutEffect, useMemo, useRef } from 'react'
|
|
14
|
+
import {
|
|
15
|
+
type Backlink,
|
|
16
|
+
ent,
|
|
17
|
+
findEid,
|
|
18
|
+
linksVia,
|
|
19
|
+
loaded,
|
|
20
|
+
problem,
|
|
21
|
+
queryEids,
|
|
22
|
+
querySubscription,
|
|
23
|
+
type SubscriptionRead,
|
|
24
|
+
useHold,
|
|
25
|
+
} from '../live.js'
|
|
26
|
+
import { parseQuery, type Pred, resolveRefs } from '../query.js'
|
|
27
|
+
import { type Ent, vocab } from '../types.js'
|
|
28
|
+
|
|
29
|
+
import { useDerived } from './read.js'
|
|
30
|
+
|
|
31
|
+
// A query that does not parse fails where it was asked, never in the render
|
|
32
|
+
// around it: the hook reports it once and answers a failed read, so the view
|
|
33
|
+
// that asked paints its own failure and the rest of the page paints whole. A
|
|
34
|
+
// refused `.chat.actor=` in the chat once blanked every entity page, and a
|
|
35
|
+
// board's saved query is typed by a person.
|
|
36
|
+
let resolve = (query: string): Pred[] | Error => {
|
|
37
|
+
try {
|
|
38
|
+
return resolveRefs(parseQuery(query), findEid)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return error instanceof Error ? error : new Error(String(error))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let usePreds = (query: string) => {
|
|
45
|
+
let preds = useMemo(() => resolve(query), [query])
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
if (!(preds instanceof Error)) return
|
|
48
|
+
console.error(`query ${JSON.stringify(query)}:`, preds)
|
|
49
|
+
problem.value = `query could not be read: ${preds.message}`
|
|
50
|
+
}, [preds])
|
|
51
|
+
return preds
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let refused = (query: string, error: Error): QueryResult => ({
|
|
55
|
+
eids: [],
|
|
56
|
+
subscription: {
|
|
57
|
+
sub: '',
|
|
58
|
+
state: { status: 'failed', reason: error.message, reference: query },
|
|
59
|
+
},
|
|
60
|
+
ready: true,
|
|
61
|
+
loaded,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export type QueryResult = {
|
|
65
|
+
eids: string[]
|
|
66
|
+
subscription?: SubscriptionRead
|
|
67
|
+
ready: boolean
|
|
68
|
+
loaded: typeof loaded
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Windowed/server-owned callers opt into the authored line: re-serializing
|
|
72
|
+
// bound predicates can decline valid grammar (edge riders, time comparisons,
|
|
73
|
+
// reverse hops) into a local cache scan. Legacy local callers keep that path.
|
|
74
|
+
// The result and addressed read state of one direct query. Most callers need
|
|
75
|
+
// only eids; query-driven UI also consumes a refusal so it never paints a
|
|
76
|
+
// local partial set as the server's answer.
|
|
77
|
+
export let useQueryResult = (
|
|
78
|
+
query: string,
|
|
79
|
+
enabled = true,
|
|
80
|
+
direct = false,
|
|
81
|
+
): QueryResult => {
|
|
82
|
+
// A disabled read asks nothing, so its line is never read: one built from
|
|
83
|
+
// what is not there yet (an empty id list) must not fail the view.
|
|
84
|
+
let preds = usePreds(enabled ? query : '')
|
|
85
|
+
let source = direct ? query : undefined
|
|
86
|
+
useHold(enabled && !(preds instanceof Error) && { query: preds, source })
|
|
87
|
+
return useDerived(() => {
|
|
88
|
+
if (preds instanceof Error) return refused(query, preds)
|
|
89
|
+
let subscription = enabled ? querySubscription(preds, source) : undefined
|
|
90
|
+
return {
|
|
91
|
+
eids: enabled ? queryEids(preds).value : [],
|
|
92
|
+
subscription,
|
|
93
|
+
ready: !subscription || subscription.state.status == 'ready',
|
|
94
|
+
loaded,
|
|
95
|
+
}
|
|
96
|
+
}, [query, preds, source, enabled])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// A window the reader grows by scrolling, a page at a time: a board's list, a
|
|
100
|
+
// board's column. `line` asks for the first rows of `base`, and growing the
|
|
101
|
+
// window asks the server a new line, whose answer takes a round trip. Until it
|
|
102
|
+
// lands, the rows the smaller window answered stay, so the next page appends
|
|
103
|
+
// under the reader instead of the list emptying and repainting from the top.
|
|
104
|
+
// A different base starts from nothing: its rows are another list's.
|
|
105
|
+
export let usePage = (
|
|
106
|
+
base: string,
|
|
107
|
+
line: string,
|
|
108
|
+
enabled = true,
|
|
109
|
+
): QueryResult => {
|
|
110
|
+
let page = useQueryResult(line, enabled, true)
|
|
111
|
+
let shown = useRef<{ base: string; eids: string[] } | undefined>(undefined)
|
|
112
|
+
if (page.ready) shown.current = { base, eids: page.eids }
|
|
113
|
+
let kept = shown.current?.base == base ? shown.current.eids : undefined
|
|
114
|
+
return page.ready || !kept ? page : { ...page, eids: kept }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The matching eids, as a live array. Prefer this when the caller only needs
|
|
118
|
+
// ids (membership, a count); `useQuery` assembles the Ents.
|
|
119
|
+
export let useQueryEids = (query: string, direct = false): string[] =>
|
|
120
|
+
useQueryResult(query, true, direct).eids
|
|
121
|
+
|
|
122
|
+
// The matching entities, assembled. Each rides its own `row` signal, so the
|
|
123
|
+
// list re-renders on membership change and each row on its own edits.
|
|
124
|
+
export let useQuery = (query: string, direct = false): Ent[] => {
|
|
125
|
+
let eids = useQueryEids(query, direct)
|
|
126
|
+
return useDerived(() => eids.map(ent), [eids])
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The open card's reverse lists (T-21489), held for the view's life. Each is an
|
|
130
|
+
// EID-KEYED server sub — "comments aimed at X", "entities referencing X" — so
|
|
131
|
+
// the set is complete even when the cache is partial (a referrer outside the
|
|
132
|
+
// working set still counts, T-18094), opened on mount and torn down with the
|
|
133
|
+
// last unmount: cards accumulate no subs as they open and close. The plain
|
|
134
|
+
// live.ts backlinks door reads locally from the rows a mounted view holds;
|
|
135
|
+
// it never opens an unowned server subscription.
|
|
136
|
+
export let useCommentsOn = (target: string): Ent[] =>
|
|
137
|
+
useQuery(
|
|
138
|
+
vocab.prop('comment', 'target') ? `.comment.target=${target}` : '',
|
|
139
|
+
)
|
|
140
|
+
.slice()
|
|
141
|
+
.sort((a, b) => a.num - b.num)
|
|
142
|
+
|
|
143
|
+
// The commits landed for an entity — the structured rows that sit in the
|
|
144
|
+
// same rail as its comments (M-31946 §7). `commit` is @yaks/git's, so a graph
|
|
145
|
+
// without that plugin has none to ask for: the query would name a component
|
|
146
|
+
// its vocabulary lacks. The vocabulary is loaded before this module runs
|
|
147
|
+
// (types.ts), so the choice is made once.
|
|
148
|
+
export let useCommitsOn = (target: string): Ent[] =>
|
|
149
|
+
useQuery(vocab.prop('commit', 'target') ? `.commit.target=${target}` : '')
|
|
150
|
+
.slice()
|
|
151
|
+
.sort((a, b) => a.num - b.num)
|
|
152
|
+
|
|
153
|
+
// `via` — WHICH column points here — reads off each referrer's own row signal
|
|
154
|
+
// (linksVia), so a retarget wakes the face without a membership change.
|
|
155
|
+
let backlinkComps = () =>
|
|
156
|
+
[...new Set(vocab.refProps().map(([comp]) => comp))]
|
|
157
|
+
.map((comp) => `&?${comp}`).join('')
|
|
158
|
+
|
|
159
|
+
/** How many referrers a view holds: the newest. A project, a person or a long
|
|
160
|
+
* session is referenced tens of thousands of times, and every referrer comes
|
|
161
|
+
* with each of its reference components, so the whole set is a read that runs
|
|
162
|
+
* for seconds and a page no one can scroll. The rest is the inspector's
|
|
163
|
+
* `.refs=<id>`. */
|
|
164
|
+
export let BACKLINKS = 200
|
|
165
|
+
|
|
166
|
+
/** What points at `target`, by which property, and whether there may be more
|
|
167
|
+
* than the window holds. */
|
|
168
|
+
export let useBacklinks = (
|
|
169
|
+
target: string,
|
|
170
|
+
): { links: Backlink[]; more: boolean } => {
|
|
171
|
+
let from = useQueryEids(
|
|
172
|
+
`.refs=${target}${backlinkComps()}&.limit=${BACKLINKS}`,
|
|
173
|
+
)
|
|
174
|
+
return {
|
|
175
|
+
links: useDerived(() => from.flatMap((eid) => linksVia(eid, target)), [
|
|
176
|
+
from,
|
|
177
|
+
target,
|
|
178
|
+
]),
|
|
179
|
+
more: from.length >= BACKLINKS,
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// EID-keyed lookups belong to the mounted view, never an unheld render read.
|
|
184
|
+
export let useBoardsOver = (target: string): string[] =>
|
|
185
|
+
useQueryEids(vocab.prop('board', 'query') ? `.board.query~=${target}` : '')
|
|
186
|
+
|
|
187
|
+
export let useChatFor = (
|
|
188
|
+
actor: string | undefined,
|
|
189
|
+
target: string,
|
|
190
|
+
): Ent | undefined => {
|
|
191
|
+
let [eid] = useQueryResult(
|
|
192
|
+
actor && vocab.prop('chat', 'actor') && vocab.prop('chat', 'target')
|
|
193
|
+
? `.chat.actor=${actor}&.chat.target=${target}`
|
|
194
|
+
: '',
|
|
195
|
+
!!actor && !!vocab.prop('chat', 'actor') && !!vocab.prop('chat', 'target'),
|
|
196
|
+
).eids
|
|
197
|
+
return useDerived(() => eid ? ent(eid) : undefined, [eid])
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// The comments a session's transcript cites: those the session, or one of its
|
|
201
|
+
// entries, holds an edge to. A comment delivered to a graph-native session is
|
|
202
|
+
// cited, not said, so this is how its thread hears a comment on whatever the
|
|
203
|
+
// session works on. Edges are entities, so this is an ordinary row query.
|
|
204
|
+
let citedLine = (session: string) =>
|
|
205
|
+
vocab.prop('comment', 'target') && vocab.prop('edge', 'to') &&
|
|
206
|
+
vocab.prop('entry', 'session')
|
|
207
|
+
? `.comment&(.edges_to.edge.from=${session}|.edges_to.edge.from.entry.session=${session})`
|
|
208
|
+
: ''
|
|
209
|
+
|
|
210
|
+
export let useCitedComments = (session: string): Ent[] =>
|
|
211
|
+
useQuery(citedLine(session), true).slice().sort((a, b) => a.num - b.num)
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
|
|
2
|
+
import { adopt, parse } from 'jsr:@yaks/query@0.2.36'
|
|
3
|
+
import { vocab } from '../../types.ts'
|
|
4
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useLayoutEffect, useRef, useState } from 'npm:react@19.3.0'
|
|
5
|
+
import { type Change, type Ent, statusOf } from '../../types.ts'
|
|
6
|
+
import {
|
|
7
|
+
boardTally,
|
|
8
|
+
byPriority,
|
|
9
|
+
byWarmth,
|
|
10
|
+
clientSubscription,
|
|
11
|
+
ent,
|
|
12
|
+
foldFor,
|
|
13
|
+
mutate,
|
|
14
|
+
myClient,
|
|
15
|
+
statuses,
|
|
16
|
+
subWindow,
|
|
17
|
+
useHold,
|
|
18
|
+
uuid,
|
|
19
|
+
} from '../../live.ts'
|
|
20
|
+
import { spec, taskChanges } from '../../client.ts'
|
|
21
|
+
import { fieldsOf, orderOf, parseQuery, windowOf } from '../../query.ts'
|
|
22
|
+
import { drafts, useDraft } from 'jsr:@yaks/draft@0.2.36/input'
|
|
23
|
+
import { bundlesOf } from '../../wire.ts'
|
|
24
|
+
import { editKeys } from 'jsr:@yaks/ux@0.2.36/edit-keys'
|
|
25
|
+
import { useBoardTally } from '../subscriptions.ts'
|
|
26
|
+
import { answeredOf, retryOf } from '../answered.ts'
|
|
27
|
+
import { block, Field } from 'jsr:@yaks/ui@0.2.36'
|
|
28
|
+
import { Answer } from 'jsr:@yaks/ux@0.2.36'
|
|
29
|
+
import { Dot } from '../Dot.tsx'
|
|
30
|
+
import { Prio } from '../Prio.tsx'
|
|
31
|
+
import { useFilteredQuery } from '../Filter.tsx'
|
|
32
|
+
import { dragData } from '../drag.ts'
|
|
33
|
+
import { Entity } from '../Entity.tsx'
|
|
34
|
+
import { usePage } from '../useQuery.ts'
|
|
35
|
+
|
|
36
|
+
let Frame = block('div', 'Board', {
|
|
37
|
+
Col: 'div',
|
|
38
|
+
ColName: 'div',
|
|
39
|
+
Count: 'span',
|
|
40
|
+
Scroll: 'div',
|
|
41
|
+
Item: 'div',
|
|
42
|
+
Add: 'div',
|
|
43
|
+
More: 'button',
|
|
44
|
+
Chips: 'div',
|
|
45
|
+
Chip: 'span',
|
|
46
|
+
})
|
|
47
|
+
let { Col, ColName, Count, Scroll, Item, Add, More, Chips, Chip } = Frame
|
|
48
|
+
|
|
49
|
+
// A column asks for a screenful, not a 400-row page sorted after delivery.
|
|
50
|
+
// Priority ordering belongs before the server window; explicit saved bounds
|
|
51
|
+
// are ceilings, so scrolling never widens a deliberately limited board.
|
|
52
|
+
export let columnLine = (q: string, status: string, limit: number): string => {
|
|
53
|
+
if (!q.trim()) return ''
|
|
54
|
+
let preds = parseQuery(q)
|
|
55
|
+
let bound = windowOf(preds).limit
|
|
56
|
+
let fields = fieldsOf(preds) ? '' : '&.fields=' + [
|
|
57
|
+
'doc.title',
|
|
58
|
+
'task.status',
|
|
59
|
+
'filed.priority',
|
|
60
|
+
'filed.project',
|
|
61
|
+
'filed.domain',
|
|
62
|
+
'filed.assignee',
|
|
63
|
+
'claim.session',
|
|
64
|
+
'completed.at',
|
|
65
|
+
'cancelled.at',
|
|
66
|
+
'blocked.on',
|
|
67
|
+
'created.at',
|
|
68
|
+
'created.by',
|
|
69
|
+
'updated.at',
|
|
70
|
+
'updated.by',
|
|
71
|
+
'proposed.at',
|
|
72
|
+
'decided.verdict',
|
|
73
|
+
].join(',')
|
|
74
|
+
return q + '&.task&.task.status=' + status +
|
|
75
|
+
(orderOf(preds) ? '' : '&.order=filed.priority') +
|
|
76
|
+
'&.limit=' + Math.min(bound ?? Infinity, limit) + fields
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// A board as kanban over its saved QUERY (board.query, query.ts grammar):
|
|
80
|
+
// membership is never stored, a task is here because it matches. Columns
|
|
81
|
+
// derived from task status, ordered by priority. Every task row is
|
|
82
|
+
// draggable — dropped on another column (or another spot in its own) it
|
|
83
|
+
// patches status + priority (midpoint of its new neighbours), plus
|
|
84
|
+
// whatever scalar equalities the query demands, so a foreign task JOINS
|
|
85
|
+
// the board it lands on; dragged out to the canvas it spawns a Task card
|
|
86
|
+
// (the standard drag payload — Canvas owns that drop).
|
|
87
|
+
// The quick-add box, under the header above the rows: ONE growing row —
|
|
88
|
+
// Shift+Enter starts the body and the box follows (CSS field-sizing) —
|
|
89
|
+
// with the parse shown live as chips while you type, so 'P1 .domain=Eng
|
|
90
|
+
// Ship it' announces what Enter will file. Enter files and clears for
|
|
91
|
+
// the next title (filing a list is one uninterrupted keyboard); Escape
|
|
92
|
+
// closes. Uncontrolled on purpose: the DOM owns the text, and the draft
|
|
93
|
+
// supplies it for the chips. The line is the person's draft per (board,
|
|
94
|
+
// column) (../drafts.ts): Board keeps a column with one open, here and in
|
|
95
|
+
// every interface that draws the board, so a half-typed task is never lost
|
|
96
|
+
// or hidden. Blur keeps it; filing spends it, in the same change as the task
|
|
97
|
+
// it became, and Escape discards it. Opened by a press, the box takes the
|
|
98
|
+
// keyboard; opened by its draft, it waits for one.
|
|
99
|
+
export let QuickAdd = (
|
|
100
|
+
{ dkey, file, close, focus = true }: {
|
|
101
|
+
dkey: string
|
|
102
|
+
file: (text: string) => Change[] | undefined
|
|
103
|
+
close: () => void
|
|
104
|
+
focus?: boolean
|
|
105
|
+
},
|
|
106
|
+
) => {
|
|
107
|
+
let box = useRef<HTMLTextAreaElement>(null)
|
|
108
|
+
let { text, sync, spend } = useDraft(dkey, box)
|
|
109
|
+
useEffect(() => void (focus && box.current?.focus()), [])
|
|
110
|
+
let { body, grouped } = spec(text)
|
|
111
|
+
let p = grouped.filed?.priority
|
|
112
|
+
let chips = Object.entries(grouped).flatMap(([comp, props]) =>
|
|
113
|
+
props == null
|
|
114
|
+
? [`${comp}=false`]
|
|
115
|
+
: Object.keys(props).length == 0
|
|
116
|
+
? [`${comp}=true`]
|
|
117
|
+
: Object.entries(props)
|
|
118
|
+
.filter(([prop]) => comp != 'filed' || prop != 'priority')
|
|
119
|
+
.map(([prop, v]) => `${prop}=${v}`)
|
|
120
|
+
)
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
{(p != null || chips.length > 0 || !!body) && (
|
|
124
|
+
<Chips>
|
|
125
|
+
{p != null && <Prio p={Number(p)} />}
|
|
126
|
+
{chips.map((x) => <Chip key={x}>{x}</Chip>)}
|
|
127
|
+
{!!body && <Chip mod='body'>+ body</Chip>}
|
|
128
|
+
</Chips>
|
|
129
|
+
)}
|
|
130
|
+
<Field
|
|
131
|
+
className='Board_New'
|
|
132
|
+
lines
|
|
133
|
+
elRef={box}
|
|
134
|
+
placeholder='P1 .filed.domain=Eng title…'
|
|
135
|
+
onInput={(ev: InputEvent) =>
|
|
136
|
+
sync(ev.currentTarget as HTMLTextAreaElement)}
|
|
137
|
+
onKeyDown={editKeys({
|
|
138
|
+
keep: (t) => {
|
|
139
|
+
let line = t as HTMLTextAreaElement
|
|
140
|
+
let filed = file(line.value)
|
|
141
|
+
if (!filed) return
|
|
142
|
+
spend(bundlesOf(filed))
|
|
143
|
+
line.value = ''
|
|
144
|
+
},
|
|
145
|
+
cancel: () => {
|
|
146
|
+
spend()
|
|
147
|
+
close()
|
|
148
|
+
},
|
|
149
|
+
})}
|
|
150
|
+
onBlur={close}
|
|
151
|
+
/>
|
|
152
|
+
</>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// The quick-add draft key for one column: the same in every interface, so
|
|
157
|
+
// each reopens the exact box that was being typed in.
|
|
158
|
+
let addKey = (eid: string, status: string) => `new:${eid}:${status}`
|
|
159
|
+
|
|
160
|
+
export let Board = ({ e }: { e: Ent }) => {
|
|
161
|
+
let root = useRef<HTMLDivElement>(null)
|
|
162
|
+
let [pageSize, setPageSize] = useState(0)
|
|
163
|
+
let [limits, setLimits] = useState<Record<string, number>>({})
|
|
164
|
+
let saved = String(e.board?.query ?? '')
|
|
165
|
+
let query = useFilteredQuery(e.eid, saved)
|
|
166
|
+
useLayoutEffect(() => {
|
|
167
|
+
let node = root.current
|
|
168
|
+
let measure = () =>
|
|
169
|
+
setPageSize(Math.max(4, Math.ceil((node?.clientHeight || 480) / 64) + 2))
|
|
170
|
+
measure()
|
|
171
|
+
if (!node || !globalThis.ResizeObserver) return
|
|
172
|
+
let observer = new ResizeObserver(measure)
|
|
173
|
+
observer.observe(node)
|
|
174
|
+
return () => observer.disconnect()
|
|
175
|
+
}, [])
|
|
176
|
+
useEffect(() => setLimits({}), [e.eid, query])
|
|
177
|
+
let invalid = ''
|
|
178
|
+
try {
|
|
179
|
+
parseQuery(query)
|
|
180
|
+
} catch (err) {
|
|
181
|
+
invalid = String(err)
|
|
182
|
+
}
|
|
183
|
+
// Statuses is a fixed vocabulary: one held page per column. No member
|
|
184
|
+
// outside those pages is needed to paint or count the board.
|
|
185
|
+
let pages = statuses.map((s) =>
|
|
186
|
+
usePage(
|
|
187
|
+
`${s}:${query}`,
|
|
188
|
+
invalid ? '' : columnLine(query, s, Math.max(pageSize, limits[s] ?? 0)),
|
|
189
|
+
pageSize > 0 && !!query.trim() && !invalid,
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
let boardRead = pages.find((p) => p.subscription?.state.status == 'failed')
|
|
193
|
+
?.subscription
|
|
194
|
+
// The member sub is a WINDOW now (live.ts boardLine), so the rows a column
|
|
195
|
+
// holds are a page of it — while the COUNT a column names is the whole
|
|
196
|
+
// truth, and it comes from the same aggregate the tile reads (T-22509): one
|
|
197
|
+
// indexed group-by instead of a membership stream nobody paints. A column
|
|
198
|
+
// reading its own length would report the page as the set.
|
|
199
|
+
// The tally answers the SAVED query, so it stops being this board's truth the
|
|
200
|
+
// moment the titlebar's ephemeral filter narrows what's on screen — then the
|
|
201
|
+
// held rows are the only set anyone is claiming.
|
|
202
|
+
useBoardTally(e)
|
|
203
|
+
let counts = query != saved ? undefined : boardTally(e)
|
|
204
|
+
// Which column's quick-create box was opened by a press ('' = none): one
|
|
205
|
+
// at a time, since the box is a keyboard and there's one keyboard. A
|
|
206
|
+
// column whose draft holds a half-typed task stays open too, wherever it
|
|
207
|
+
// was typed (a reload, another tab, the terminal), until it is filed or
|
|
208
|
+
// discarded.
|
|
209
|
+
let [adding, setAdding] = useState('')
|
|
210
|
+
let drafted = (s: string) => !!drafts.text(addKey(e.eid, s))
|
|
211
|
+
// A board that says .order=hot ranks its columns by warmth, not
|
|
212
|
+
// priority — the Front page: attention IS the ordering. Drag-drop
|
|
213
|
+
// still writes priorities (adopt semantics unchanged); the ranking is
|
|
214
|
+
// read-time only, like everything hot().
|
|
215
|
+
let order = byPriority
|
|
216
|
+
try {
|
|
217
|
+
if (orderOf(parseQuery(String(e.board?.query ?? ''))) == 'hot') {
|
|
218
|
+
order = byWarmth(Date.now())
|
|
219
|
+
}
|
|
220
|
+
} catch { /* boardTasks below surfaces the bad query */ }
|
|
221
|
+
// Double-click a column name to fold the column to a vertical header.
|
|
222
|
+
// Folds are graph state like camera — a `fold` entity per (client,
|
|
223
|
+
// board), so they persist, sync across this client's tabs, and agents
|
|
224
|
+
// can see them. The TUI has no client identity; it just never folds.
|
|
225
|
+
let me = myClient()
|
|
226
|
+
useHold(me && { client: me })
|
|
227
|
+
// The ephemeral filter (typed in the titlebar) ANDs into the saved
|
|
228
|
+
// query at read time only — drops and quick-adds still adopt from
|
|
229
|
+
// board.query alone, so a glance never leaks into what a filed task
|
|
230
|
+
// carries.
|
|
231
|
+
let screen = me ? clientSubscription(me) : undefined
|
|
232
|
+
let row = me ? foldFor(me, e.eid) : null
|
|
233
|
+
let tasks: Ent[] = []
|
|
234
|
+
let broken = invalid
|
|
235
|
+
if (!broken) {
|
|
236
|
+
try {
|
|
237
|
+
tasks = [...new Set(pages.flatMap((p) => p.eids))].map(ent)
|
|
238
|
+
} catch (err) {
|
|
239
|
+
broken = String(err instanceof Error ? err.message : err)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// The board answers its columns once this client's folds have arrived, or
|
|
243
|
+
// is refused: a bad query, a column's refusal, or the folds'.
|
|
244
|
+
let refusal = boardRead ?? screen
|
|
245
|
+
let folds = screen?.state.status != 'loading'
|
|
246
|
+
let columns = broken
|
|
247
|
+
? { rows: [], ready: false, refused: broken }
|
|
248
|
+
: answeredOf(folds ? [...statuses] : [], {
|
|
249
|
+
ready: folds,
|
|
250
|
+
subscription: refusal,
|
|
251
|
+
})
|
|
252
|
+
let folded = new Set(
|
|
253
|
+
String(row?.statuses ?? '').split(',').filter(Boolean),
|
|
254
|
+
)
|
|
255
|
+
let fold = (s: string) => {
|
|
256
|
+
if (!me) return
|
|
257
|
+
folded.has(s) ? folded.delete(s) : folded.add(s)
|
|
258
|
+
mutate({
|
|
259
|
+
eid: row?.eid ?? uuid(),
|
|
260
|
+
name: 'fold',
|
|
261
|
+
comp: {
|
|
262
|
+
client: me,
|
|
263
|
+
board: e.eid,
|
|
264
|
+
statuses: [...folded].join(','),
|
|
265
|
+
},
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
let drop = (
|
|
269
|
+
ev: DragEvent & { currentTarget: HTMLElement },
|
|
270
|
+
status: string,
|
|
271
|
+
) => {
|
|
272
|
+
let data = ev.dataTransfer?.getData('application/x-tasks-card')
|
|
273
|
+
if (!data) return
|
|
274
|
+
let { target } = JSON.parse(data)
|
|
275
|
+
if (!ent(target).task) return // not a task: let the canvas spawn it
|
|
276
|
+
ev.preventDefault()
|
|
277
|
+
ev.stopPropagation()
|
|
278
|
+
// The new neighbours: this column's tasks (minus the dragged one), in
|
|
279
|
+
// render order; the drop's insertion index comes from the row midpoints.
|
|
280
|
+
let list = tasks
|
|
281
|
+
.filter((k) => k.task && statusOf(k) == status && k.eid != target)
|
|
282
|
+
.sort(byPriority)
|
|
283
|
+
let rows = [...ev.currentTarget.querySelectorAll('.Board_Item')]
|
|
284
|
+
.filter((r) => (r as HTMLElement).dataset.eid != target)
|
|
285
|
+
let i = rows.findIndex((r) => {
|
|
286
|
+
let box = r.getBoundingClientRect()
|
|
287
|
+
return ev.clientY < box.top + box.height / 2
|
|
288
|
+
})
|
|
289
|
+
if (i < 0) i = list.length
|
|
290
|
+
let prev = list[i - 1]?.filed?.priority
|
|
291
|
+
let next = list[i]?.filed?.priority
|
|
292
|
+
let priority = prev == null && next == null
|
|
293
|
+
? 0
|
|
294
|
+
: prev == null
|
|
295
|
+
? next! - 1
|
|
296
|
+
: next == null
|
|
297
|
+
? prev + 1
|
|
298
|
+
: (prev + next) / 2
|
|
299
|
+
let grouped = adopt(parse(String(e.board?.query ?? '')), vocab)
|
|
300
|
+
mutate(
|
|
301
|
+
...Object.entries(grouped).filter(([name]) =>
|
|
302
|
+
name != 'task' && name != 'filed'
|
|
303
|
+
)
|
|
304
|
+
.map(([name, comp]) => ({ eid: target, name, comp })),
|
|
305
|
+
{ eid: target, name: 'task', comp: { ...grouped.task, status } },
|
|
306
|
+
{
|
|
307
|
+
eid: target,
|
|
308
|
+
name: 'filed',
|
|
309
|
+
comp: {
|
|
310
|
+
...grouped.filed,
|
|
311
|
+
priority,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Quick-create: a task born INTO the column it was typed in. The line
|
|
318
|
+
// is PARSED, not just taken (client.ts spec): 'P1 .filed.domain=Eng Ship it'
|
|
319
|
+
// sets priority and domain, Shift+Enter lines become the body. The
|
|
320
|
+
// column's status and the query's scalar equalities (adopt(), the
|
|
321
|
+
// drop's own path) ride along, but what you TYPED wins over the auto
|
|
322
|
+
// top-landing priority. Lands at the top where the typist is looking.
|
|
323
|
+
let create = (status: string, list: Ent[], text: string) => {
|
|
324
|
+
let { title, body, grouped } = spec(text)
|
|
325
|
+
if (!title) return
|
|
326
|
+
for (
|
|
327
|
+
let [comp, values] of Object.entries(
|
|
328
|
+
adopt(parse(String(e.board?.query ?? '')), vocab),
|
|
329
|
+
)
|
|
330
|
+
) {
|
|
331
|
+
grouped[comp] = { ...values, ...grouped[comp] }
|
|
332
|
+
}
|
|
333
|
+
return taskChanges(uuid(), {
|
|
334
|
+
...grouped,
|
|
335
|
+
doc: { title, body, ...grouped.doc },
|
|
336
|
+
task: { ...grouped.task, status },
|
|
337
|
+
filed: {
|
|
338
|
+
priority: (list[0]?.filed?.priority ?? 1) - 1,
|
|
339
|
+
...grouped.filed,
|
|
340
|
+
},
|
|
341
|
+
}, true)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<Frame elRef={root}>
|
|
346
|
+
<Answer
|
|
347
|
+
answered={columns}
|
|
348
|
+
empty='No columns'
|
|
349
|
+
loading='Loading board preferences…'
|
|
350
|
+
failed='The board could not load.'
|
|
351
|
+
retry={retryOf(refusal)}
|
|
352
|
+
>
|
|
353
|
+
{(cols) =>
|
|
354
|
+
cols.map((s, i) => {
|
|
355
|
+
let list = tasks.filter((k) => k.task && statusOf(k) == s).sort(
|
|
356
|
+
order,
|
|
357
|
+
)
|
|
358
|
+
let read = pages[i]
|
|
359
|
+
let win = read.subscription
|
|
360
|
+
? subWindow(read.subscription.sub)
|
|
361
|
+
: undefined
|
|
362
|
+
let total = counts?.[s] ?? win?.total ?? list.length
|
|
363
|
+
let bound = windowOf(parseQuery(query)).limit
|
|
364
|
+
let more = Math.max(
|
|
365
|
+
0,
|
|
366
|
+
Math.min(total, bound ?? Infinity) - list.length,
|
|
367
|
+
)
|
|
368
|
+
let grow = () => {
|
|
369
|
+
if (!read.ready || !more) return
|
|
370
|
+
setLimits((ls) => ({
|
|
371
|
+
...ls,
|
|
372
|
+
[s]: Math.max(pageSize, ls[s] ?? 0) + pageSize,
|
|
373
|
+
}))
|
|
374
|
+
}
|
|
375
|
+
return (
|
|
376
|
+
<Col
|
|
377
|
+
key={s}
|
|
378
|
+
mod={folded.has(s) && 'folded'}
|
|
379
|
+
// the drop target cancels dragover ITSELF — leaning on an
|
|
380
|
+
// ancestor's cancel is how fullscreen boards lost their drops
|
|
381
|
+
onDragOver={(ev: DragEvent) => ev.preventDefault()}
|
|
382
|
+
onDrop={(ev: DragEvent & { currentTarget: HTMLElement }) =>
|
|
383
|
+
drop(ev, s)}
|
|
384
|
+
>
|
|
385
|
+
<ColName onDoubleClick={() => fold(s)}>
|
|
386
|
+
<Dot status={s} />
|
|
387
|
+
{s}
|
|
388
|
+
<Count>
|
|
389
|
+
{counts?.[s] ?? win?.total ??
|
|
390
|
+
(read.ready ? list.length : '…')}
|
|
391
|
+
</Count>
|
|
392
|
+
{!folded.has(s) && adding != s && !drafted(s) && (
|
|
393
|
+
<Add onClick={() => setAdding(s)} title={`new ${s} task`}>
|
|
394
|
+
+
|
|
395
|
+
</Add>
|
|
396
|
+
)}
|
|
397
|
+
</ColName>
|
|
398
|
+
{!folded.has(s) && (adding == s || drafted(s)) && (
|
|
399
|
+
<QuickAdd
|
|
400
|
+
dkey={addKey(e.eid, s)}
|
|
401
|
+
file={(text) => create(s, list, text)}
|
|
402
|
+
close={() => setAdding('')}
|
|
403
|
+
focus={adding == s}
|
|
404
|
+
/>
|
|
405
|
+
)}
|
|
406
|
+
{!folded.has(s) && (
|
|
407
|
+
<Scroll
|
|
408
|
+
onScroll={(ev: Event) => {
|
|
409
|
+
let node = ev.currentTarget as HTMLElement
|
|
410
|
+
if (
|
|
411
|
+
node.scrollHeight - node.scrollTop - node.clientHeight <
|
|
412
|
+
160
|
|
413
|
+
) grow()
|
|
414
|
+
}}
|
|
415
|
+
>
|
|
416
|
+
<Answer
|
|
417
|
+
answered={answeredOf(list, read)}
|
|
418
|
+
empty={`No ${s} tasks`}
|
|
419
|
+
loading={list.length ? 'Loading more…' : 'Loading…'}
|
|
420
|
+
>
|
|
421
|
+
{(rows) => (
|
|
422
|
+
<>
|
|
423
|
+
{rows.map((k) => (
|
|
424
|
+
<Item
|
|
425
|
+
key={k.eid}
|
|
426
|
+
draggable
|
|
427
|
+
data-eid={k.eid}
|
|
428
|
+
onDragStart={(ev: DragEvent) =>
|
|
429
|
+
dragData(ev, k.eid, 'Full')}
|
|
430
|
+
>
|
|
431
|
+
<Entity eid={k.eid} view='Board.List.Tile' />
|
|
432
|
+
</Item>
|
|
433
|
+
))}
|
|
434
|
+
{read.ready && more > 0 && (
|
|
435
|
+
<More type='button' onClick={grow}>
|
|
436
|
+
+{more} more
|
|
437
|
+
</More>
|
|
438
|
+
)}
|
|
439
|
+
</>
|
|
440
|
+
)}
|
|
441
|
+
</Answer>
|
|
442
|
+
</Scroll>
|
|
443
|
+
)}
|
|
444
|
+
</Col>
|
|
445
|
+
)
|
|
446
|
+
})}
|
|
447
|
+
</Answer>
|
|
448
|
+
</Frame>
|
|
449
|
+
)
|
|
450
|
+
}
|