@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,625 @@
|
|
|
1
|
+
/** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
|
|
2
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useLayoutEffect, useMemo, useRef } from 'npm:react@19.3.0'
|
|
3
|
+
import { effect, signal } from 'npm:@preact/signals-core@1.14.5'
|
|
4
|
+
import {
|
|
5
|
+
cache,
|
|
6
|
+
camera,
|
|
7
|
+
clientId,
|
|
8
|
+
ent,
|
|
9
|
+
hear,
|
|
10
|
+
mode,
|
|
11
|
+
mutate,
|
|
12
|
+
myCamera,
|
|
13
|
+
pinned,
|
|
14
|
+
rows,
|
|
15
|
+
toFront,
|
|
16
|
+
toPlane,
|
|
17
|
+
topZ,
|
|
18
|
+
uuid,
|
|
19
|
+
} from '../live.ts'
|
|
20
|
+
import { type Change } from '../types.ts'
|
|
21
|
+
import { cameraEid } from '../edge.ts'
|
|
22
|
+
import { cardCommands, run } from '../commands.ts'
|
|
23
|
+
import { pasted } from '../paste.ts'
|
|
24
|
+
import { block } from 'jsr:@yaks/ui@0.2.36'
|
|
25
|
+
import { resolve } from './registry.ts'
|
|
26
|
+
import { people } from './hits.ts'
|
|
27
|
+
import { usePinned } from './subscriptions.ts'
|
|
28
|
+
import { Card } from './Card.tsx'
|
|
29
|
+
import { actionsAt } from './nav.tsx'
|
|
30
|
+
|
|
31
|
+
let Frame = block('div', 'Canvas', { Plane: 'div' })
|
|
32
|
+
let { Plane } = Frame
|
|
33
|
+
|
|
34
|
+
// One zoom range for every camera move — pinch and frame-to-fit alike.
|
|
35
|
+
let ZOOM_MIN = 0.1
|
|
36
|
+
let ZOOM_MAX = 4
|
|
37
|
+
|
|
38
|
+
export let panEvents = (
|
|
39
|
+
elem: EventTarget,
|
|
40
|
+
move: (e: PointerEvent) => void,
|
|
41
|
+
settle: () => void,
|
|
42
|
+
) => {
|
|
43
|
+
let moving = (e: Event) => move(e as PointerEvent)
|
|
44
|
+
let quit = () => {
|
|
45
|
+
elem.removeEventListener('pointermove', moving)
|
|
46
|
+
elem.removeEventListener('pointerup', up)
|
|
47
|
+
elem.removeEventListener('pointercancel', quit)
|
|
48
|
+
}
|
|
49
|
+
let up = () => {
|
|
50
|
+
quit()
|
|
51
|
+
settle()
|
|
52
|
+
}
|
|
53
|
+
elem.addEventListener('pointermove', moving)
|
|
54
|
+
elem.addEventListener('pointerup', up)
|
|
55
|
+
elem.addEventListener('pointercancel', quit)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Where the search palette drops its pick: a card at the viewport
|
|
59
|
+
// centre, a third of the way down — computed from the camera alone, so
|
|
60
|
+
// the shell (App owns the palette) never reaches into a mounted canvas.
|
|
61
|
+
export let spawnHit = (canvas: string, target: string) => {
|
|
62
|
+
let { x, y, zoom, h } = camera.value
|
|
63
|
+
let card = uuid()
|
|
64
|
+
mutate(
|
|
65
|
+
{
|
|
66
|
+
eid: card,
|
|
67
|
+
name: 'card',
|
|
68
|
+
comp: { eid: card, target: target, view: resolve(ent(target)).view },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
eid: card,
|
|
72
|
+
name: 'pin',
|
|
73
|
+
comp: {
|
|
74
|
+
eid: card,
|
|
75
|
+
canvas: canvas,
|
|
76
|
+
// half a nominal card wide, titlebar under the point — the same
|
|
77
|
+
// landing spawnAt gives a centered drop.
|
|
78
|
+
x: Math.round(x - 240),
|
|
79
|
+
y: Math.round(y - h / 6 / zoom - 15),
|
|
80
|
+
w: 0,
|
|
81
|
+
h: 0,
|
|
82
|
+
z: topZ(canvas) + 1,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The pannable, zoomable plane of pinned cards. The camera is a per-client,
|
|
89
|
+
// per-canvas entity (canvases nest — a client has one camera per canvas it
|
|
90
|
+
// looks at), restored from the cache on mount and patched over the sync
|
|
91
|
+
// socket as pans, zooms, and resizes settle. x/y is the viewport center in
|
|
92
|
+
// plane coords: translate = viewport/2 - center * zoom.
|
|
93
|
+
export let Canvas = ({ eid }: { eid: string }) => {
|
|
94
|
+
let cards = usePinned(eid)
|
|
95
|
+
let el = useRef<HTMLDivElement>(null)
|
|
96
|
+
let plane = useRef<HTMLDivElement>(null)
|
|
97
|
+
let mouse = useRef<{ x: number; y: number } | null>(null) // paste lands here
|
|
98
|
+
let cam = useRef('') // this client's camera eid for THIS canvas
|
|
99
|
+
let timer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
100
|
+
let dirty = useRef(new Set<string>())
|
|
101
|
+
let gesture = useRef<
|
|
102
|
+
{
|
|
103
|
+
mode: 'scroll' | 'pan'
|
|
104
|
+
t: number
|
|
105
|
+
last: number // |delta| of the previous event
|
|
106
|
+
peak: number // max |delta| this gesture — decay reference
|
|
107
|
+
sign: number // direction of the dominant axis
|
|
108
|
+
} | null
|
|
109
|
+
>(null)
|
|
110
|
+
let glide = useMemo(() => signal(false), []) // one smooth transition, for zoom-to-card
|
|
111
|
+
|
|
112
|
+
// The latched card: <space> doesn't just frame a card, it follows it —
|
|
113
|
+
// when the pin changes shape (a tab switch, an edit growing the body),
|
|
114
|
+
// the camera re-frames with the same glide. Any manual camera move
|
|
115
|
+
// (pan, pinch, 0) lets go. The debounce keeps a drag-resize from
|
|
116
|
+
// fighting the camera mid-gesture: we glide once the shape settles.
|
|
117
|
+
let latched = useRef<HTMLElement | null>(null)
|
|
118
|
+
let ro = useRef<ResizeObserver | null>(null)
|
|
119
|
+
let settle = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
120
|
+
|
|
121
|
+
let unlatch = () => {
|
|
122
|
+
ro.current?.disconnect()
|
|
123
|
+
latched.current = null
|
|
124
|
+
if (settle.current) clearTimeout(settle.current)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Glide the camera to frame a pin, zoomed to fit with a margin. The
|
|
128
|
+
// margin applies BEFORE the clamp — clamping the raw fit first meant a
|
|
129
|
+
// card wider than ~4 viewports could never zoom far enough out.
|
|
130
|
+
let frame = (pin: HTMLElement) => {
|
|
131
|
+
let { w, h } = camera.value
|
|
132
|
+
let fit = Math.min(w / pin.offsetWidth, h / pin.offsetHeight) * 0.9
|
|
133
|
+
let z = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, fit))
|
|
134
|
+
glide.value = true
|
|
135
|
+
camera.value = {
|
|
136
|
+
x: pin.offsetLeft + pin.offsetWidth / 2,
|
|
137
|
+
y: pin.offsetTop + pin.offsetHeight / 2,
|
|
138
|
+
zoom: z,
|
|
139
|
+
w,
|
|
140
|
+
h,
|
|
141
|
+
}
|
|
142
|
+
queue('x', 'y', 'zoom')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let latch = (pin: HTMLElement) => {
|
|
146
|
+
unlatch()
|
|
147
|
+
if (pin.dataset.eid) toFront(pin.dataset.eid) // framing raises, too
|
|
148
|
+
frame(pin)
|
|
149
|
+
latched.current = pin
|
|
150
|
+
ro.current ??= new ResizeObserver(() => {
|
|
151
|
+
let el = latched.current
|
|
152
|
+
if (!el) return
|
|
153
|
+
if (!el.isConnected) return unlatch() // the card was closed
|
|
154
|
+
if (settle.current) clearTimeout(settle.current)
|
|
155
|
+
settle.current = setTimeout(() => frame(el), 150)
|
|
156
|
+
})
|
|
157
|
+
ro.current.observe(pin)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Comps travel as patches — send only the props that moved. Through
|
|
161
|
+
// mutate, not bare send: OUR cache must hear the save too, or a
|
|
162
|
+
// back-navigation remounts from a camera this client never told itself
|
|
163
|
+
// about — the spot you left is the spot you get back.
|
|
164
|
+
let save = (comp: Record<string, number | string>) => {
|
|
165
|
+
if (cam.current) mutate({ eid: cam.current, name: 'camera', comp })
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// The settle: snap to the pixel grid and persist whichever props moved.
|
|
169
|
+
// Snapping here, never mid-gesture — rounding a live pan or pinch reads
|
|
170
|
+
// as jitter, worst when zoomed in. Called by the debounce below, by
|
|
171
|
+
// unmount, and by pagehide — a pending save must not die with the view
|
|
172
|
+
// (the link-click and the refresh both used to eat the last gesture).
|
|
173
|
+
let flush = () => {
|
|
174
|
+
if (!dirty.current.size) return
|
|
175
|
+
if (timer.current) clearTimeout(timer.current)
|
|
176
|
+
timer.current = null
|
|
177
|
+
let { x, y, zoom, w, h } = camera.value
|
|
178
|
+
if (dirty.current.has('zoom') && Math.abs(zoom - 1) < 0.02) zoom = 1
|
|
179
|
+
x = (w / 2 - Math.round(w / 2 - x * zoom)) / zoom
|
|
180
|
+
y = (h / 2 - Math.round(h / 2 - y * zoom)) / zoom
|
|
181
|
+
camera.value = { ...camera.value, x, y, zoom }
|
|
182
|
+
dirty.current.add('x').add('y')
|
|
183
|
+
save(Object.fromEntries(
|
|
184
|
+
[...dirty.current].map((p) => [p, camera.value[p as 'x']]),
|
|
185
|
+
))
|
|
186
|
+
dirty.current.clear()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Debounced flush that remembers WHICH props moved across a burst, so an
|
|
190
|
+
// interleaved pan + zoom doesn't drop the zoom from the final patch.
|
|
191
|
+
let queue = (...props: (keyof typeof camera.value)[]) => {
|
|
192
|
+
for (let p of props) dirty.current.add(p)
|
|
193
|
+
if (timer.current) clearTimeout(timer.current)
|
|
194
|
+
timer.current = setTimeout(flush, 400)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Layout effect, not effect: the camera must be measured and restored
|
|
198
|
+
// BEFORE the first paint, or the screen flashes untransformed content.
|
|
199
|
+
useLayoutEffect(() => {
|
|
200
|
+
if (!el.current) return
|
|
201
|
+
let id = clientId()
|
|
202
|
+
let size = () => ({
|
|
203
|
+
w: el.current!.clientWidth,
|
|
204
|
+
h: el.current!.clientHeight,
|
|
205
|
+
})
|
|
206
|
+
let { w, h } = size()
|
|
207
|
+
|
|
208
|
+
// Restore if warm; a cold cache is not proof that the row is absent.
|
|
209
|
+
// Both paths name the same sentence, so minting is an idempotent patch.
|
|
210
|
+
cam.current = cameraEid(id, eid)
|
|
211
|
+
let mine = myCamera(id, eid)
|
|
212
|
+
if (mine) {
|
|
213
|
+
camera.value = { x: mine.x, y: mine.y, zoom: mine.zoom, w, h }
|
|
214
|
+
if (mine.w != w || mine.h != h) save({ w, h })
|
|
215
|
+
} else {
|
|
216
|
+
camera.value = { x: w / 2, y: h / 2, zoom: 1, w, h }
|
|
217
|
+
mutate(
|
|
218
|
+
{
|
|
219
|
+
eid: id,
|
|
220
|
+
name: 'client',
|
|
221
|
+
comp: { eid: id, user_agent: navigator.userAgent },
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
eid: cam.current,
|
|
225
|
+
name: 'camera',
|
|
226
|
+
comp: {
|
|
227
|
+
eid: cam.current,
|
|
228
|
+
client: id,
|
|
229
|
+
canvas: eid,
|
|
230
|
+
...camera.value,
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// A graph with exactly one person can only be that person's browser —
|
|
237
|
+
// bind the client to them on sight. Any other census (none, many)
|
|
238
|
+
// leaves the choice to the status row: identity is an assertion, and
|
|
239
|
+
// with candidates the user does the asserting.
|
|
240
|
+
//
|
|
241
|
+
// Ask the SERVER for the census (hits.ts), never the loaded cache: a
|
|
242
|
+
// partial cache can hold exactly one person while the graph holds many,
|
|
243
|
+
// and binding this browser to the wrong identity garbles its bylines —
|
|
244
|
+
// correctness, not just completeness. limit 2 is all "exactly one" needs.
|
|
245
|
+
// Fire-and-forget, aborted on unmount; the actor re-check guards a bind
|
|
246
|
+
// that raced the status row's own assertion.
|
|
247
|
+
let bind = new AbortController()
|
|
248
|
+
if (!cache.value[id]?.client?.actor) {
|
|
249
|
+
people(2, bind.signal)
|
|
250
|
+
.then((found) => {
|
|
251
|
+
if (found.length == 1 && !cache.value[id]?.client?.actor) {
|
|
252
|
+
mutate({
|
|
253
|
+
eid: id,
|
|
254
|
+
name: 'client',
|
|
255
|
+
comp: { eid: id, actor: found[0].entity.eid },
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
.catch(() => {})
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Another tab moving this camera moves ours too — but only the MOVE
|
|
263
|
+
// (x/y/zoom). w/h are THIS tab's viewport; letting another tab's size
|
|
264
|
+
// leak in skews frame-to-fit and centering (the row's w/h is just the
|
|
265
|
+
// last writer's, for agents' rough sense of what the human sees).
|
|
266
|
+
let unhear = hear((batch) => {
|
|
267
|
+
for (let c of batch) {
|
|
268
|
+
if (c.eid == cam.current && c.name == 'camera' && c.comp) {
|
|
269
|
+
let { x, y, zoom } = { ...camera.value, ...c.comp }
|
|
270
|
+
camera.value = { ...camera.value, x, y, zoom }
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
let resize = () => {
|
|
276
|
+
let { w, h } = size()
|
|
277
|
+
camera.value = { ...camera.value, w, h }
|
|
278
|
+
queue('w', 'h')
|
|
279
|
+
}
|
|
280
|
+
addEventListener('resize', resize)
|
|
281
|
+
|
|
282
|
+
// Normal-mode hotkeys: 0 resets zoom; <space> over a card glides the
|
|
283
|
+
// camera to frame it and latches on — the camera follows shape changes
|
|
284
|
+
// until a manual move lets go. Over the background, the target is the
|
|
285
|
+
// top of the stack: every interaction raises, so highest z IS the
|
|
286
|
+
// last card focused.
|
|
287
|
+
let key = (e: KeyboardEvent) => {
|
|
288
|
+
if (mode.value != 'normal' || e.repeat || e.defaultPrevented) return
|
|
289
|
+
if (
|
|
290
|
+
e.target instanceof HTMLElement &&
|
|
291
|
+
e.target.matches('input, textarea, select, [contenteditable]')
|
|
292
|
+
) return
|
|
293
|
+
if (e.key == '0') {
|
|
294
|
+
unlatch()
|
|
295
|
+
camera.value = { ...camera.value, zoom: 1 }
|
|
296
|
+
queue('zoom')
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
if (e.key != ' ') return
|
|
300
|
+
let top = pinned(eid).at(-1)
|
|
301
|
+
let pin = document.querySelector<HTMLElement>('.Pin:hover') ??
|
|
302
|
+
(top &&
|
|
303
|
+
document.querySelector<HTMLElement>(`.Pin[data-eid="${top.eid}"]`))
|
|
304
|
+
if (!pin) return
|
|
305
|
+
e.preventDefault()
|
|
306
|
+
latch(pin)
|
|
307
|
+
}
|
|
308
|
+
addEventListener('keydown', key)
|
|
309
|
+
|
|
310
|
+
// Paste lands at the cursor (or the viewport centre): the parser turns
|
|
311
|
+
// eids, T-123 ids, URLs, JSON, or plain text into the right entity and
|
|
312
|
+
// a card spawns on it.
|
|
313
|
+
let paste = (ev: ClipboardEvent) => {
|
|
314
|
+
if (
|
|
315
|
+
ev.target instanceof HTMLElement &&
|
|
316
|
+
ev.target.matches('input, textarea, select, [contenteditable]')
|
|
317
|
+
) return
|
|
318
|
+
let spec = pasted(ev.clipboardData?.getData('text/plain') ?? '')
|
|
319
|
+
if (!spec) return
|
|
320
|
+
ev.preventDefault()
|
|
321
|
+
let box = el.current!.getBoundingClientRect()
|
|
322
|
+
let { x, y } = mouse.current ??
|
|
323
|
+
{ x: box.left + box.width / 2, y: box.top + box.height / 2 }
|
|
324
|
+
spawnAt(spec.changes, spec.target, spec.view, spec.w ?? 0, x, y)
|
|
325
|
+
}
|
|
326
|
+
addEventListener('paste', paste)
|
|
327
|
+
// The refresh path: flush the pending camera save while the socket
|
|
328
|
+
// can still speak. Best effort — pagehide is the last reliable word.
|
|
329
|
+
addEventListener('pagehide', flush)
|
|
330
|
+
return () => {
|
|
331
|
+
unlatch()
|
|
332
|
+
flush() // a navigation inside the app must not eat the last gesture
|
|
333
|
+
unhear()
|
|
334
|
+
bind.abort()
|
|
335
|
+
removeEventListener('resize', resize)
|
|
336
|
+
removeEventListener('keydown', key)
|
|
337
|
+
removeEventListener('paste', paste)
|
|
338
|
+
removeEventListener('pagehide', flush)
|
|
339
|
+
}
|
|
340
|
+
}, [eid])
|
|
341
|
+
|
|
342
|
+
// Camera motion owns two DOM attributes, not the card tree. The signal
|
|
343
|
+
// effect runs before paint and updates those attributes without asking
|
|
344
|
+
// the renderer to reconcile any mounted card or board.
|
|
345
|
+
useLayoutEffect(() =>
|
|
346
|
+
effect(() => {
|
|
347
|
+
if (!el.current || !plane.current) return
|
|
348
|
+
let { x, y, zoom, w, h } = camera.value
|
|
349
|
+
let tx = w / 2 - x * zoom
|
|
350
|
+
let ty = h / 2 - y * zoom
|
|
351
|
+
el.current.style.backgroundPosition = `${tx}px ${ty}px`
|
|
352
|
+
el.current.style.backgroundSize = `${24 * zoom}px ${24 * zoom}px`
|
|
353
|
+
plane.current.style.transform =
|
|
354
|
+
`translate(${tx}px,${ty}px) scale(${zoom})`
|
|
355
|
+
el.current.classList.toggle('Canvas-glide', glide.value)
|
|
356
|
+
plane.current.classList.toggle('Canvas_Plane-glide', glide.value)
|
|
357
|
+
}), [])
|
|
358
|
+
|
|
359
|
+
let down = (e: PointerEvent & { currentTarget: HTMLDivElement }) => {
|
|
360
|
+
if (e.target instanceof Element && e.target.closest('.Pin')) return
|
|
361
|
+
unlatch()
|
|
362
|
+
glide.value = false
|
|
363
|
+
let elem = e.currentTarget
|
|
364
|
+
let from = camera.value
|
|
365
|
+
let sx = e.clientX
|
|
366
|
+
let sy = e.clientY
|
|
367
|
+
elem.setPointerCapture(e.pointerId)
|
|
368
|
+
let move = (e: PointerEvent) => {
|
|
369
|
+
camera.value = {
|
|
370
|
+
...from,
|
|
371
|
+
x: from.x - (e.clientX - sx) / from.zoom,
|
|
372
|
+
y: from.y - (e.clientY - sy) / from.zoom,
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
panEvents(elem, move, () => queue('x', 'y'))
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Can anything between the wheel target and the canvas still consume this
|
|
379
|
+
// delta? Direction-aware: a scroller at its end stops counting, so the
|
|
380
|
+
// gesture chains back into panning. Cards with nothing to scroll pan.
|
|
381
|
+
let consumes = (from: Element, to: Element, dx: number, dy: number) => {
|
|
382
|
+
let vertical = Math.abs(dy) >= Math.abs(dx)
|
|
383
|
+
for (let n: Element | null = from; n && n != to; n = n.parentElement) {
|
|
384
|
+
let s = getComputedStyle(n)
|
|
385
|
+
if (
|
|
386
|
+
vertical && /auto|scroll/.test(s.overflowY) &&
|
|
387
|
+
(dy < 0
|
|
388
|
+
? n.scrollTop > 0
|
|
389
|
+
: n.scrollTop + n.clientHeight < n.scrollHeight - 1)
|
|
390
|
+
) return true
|
|
391
|
+
if (
|
|
392
|
+
!vertical && /auto|scroll/.test(s.overflowX) &&
|
|
393
|
+
(dx < 0
|
|
394
|
+
? n.scrollLeft > 0
|
|
395
|
+
: n.scrollLeft + n.clientWidth < n.scrollWidth - 1)
|
|
396
|
+
) return true
|
|
397
|
+
}
|
|
398
|
+
return false
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Scroll pans; pinch (ctrl+wheel, per trackpad convention) zooms toward
|
|
402
|
+
// the cursor — the plane point under it stays put.
|
|
403
|
+
let wheel = (e: WheelEvent & { currentTarget: HTMLDivElement }) => {
|
|
404
|
+
glide.value = false
|
|
405
|
+
let { x, y, zoom, w, h } = camera.value
|
|
406
|
+
if (e.ctrlKey) {
|
|
407
|
+
e.preventDefault()
|
|
408
|
+
unlatch()
|
|
409
|
+
let z = Math.min(
|
|
410
|
+
ZOOM_MAX,
|
|
411
|
+
Math.max(ZOOM_MIN, zoom * Math.exp(-e.deltaY / 80)),
|
|
412
|
+
)
|
|
413
|
+
let r = e.currentTarget.getBoundingClientRect()
|
|
414
|
+
let cx = e.clientX - r.left - w / 2
|
|
415
|
+
let cy = e.clientY - r.top - h / 2
|
|
416
|
+
camera.value = {
|
|
417
|
+
x: x + cx * (1 / zoom - 1 / z),
|
|
418
|
+
y: y + cy * (1 / zoom - 1 / z),
|
|
419
|
+
zoom: z,
|
|
420
|
+
w,
|
|
421
|
+
h,
|
|
422
|
+
}
|
|
423
|
+
queue('x', 'y', 'zoom')
|
|
424
|
+
} else {
|
|
425
|
+
// Native scroll keeps the gesture only while something under the
|
|
426
|
+
// cursor can still move that way; otherwise the canvas pans. The
|
|
427
|
+
// decision LATCHES for the gesture's lifetime, so a flick that
|
|
428
|
+
// bottoms out a card doesn't dump its momentum into a pan. A
|
|
429
|
+
// gesture ends at 150ms of silence — or EARLY when a new flick
|
|
430
|
+
// shows through the momentum tail: the direction flips, or the
|
|
431
|
+
// magnitude jumps (>2× the last event) after clear decay (<40% of
|
|
432
|
+
// the gesture's peak). No gesture-phase API in Chromium; this is
|
|
433
|
+
// the observable signature of fingers coming back down.
|
|
434
|
+
let now = performance.now()
|
|
435
|
+
let g = gesture.current
|
|
436
|
+
let mag = Math.max(Math.abs(e.deltaX), Math.abs(e.deltaY))
|
|
437
|
+
let sign = Math.sign(
|
|
438
|
+
Math.abs(e.deltaY) >= Math.abs(e.deltaX) ? e.deltaY : e.deltaX,
|
|
439
|
+
)
|
|
440
|
+
let fresh = !g || now - g.t >= 150 ||
|
|
441
|
+
(sign != 0 && g.sign != 0 && sign != g.sign) ||
|
|
442
|
+
(g.last < g.peak * 0.4 && mag > g.last * 2 && mag > 4)
|
|
443
|
+
let mode = fresh
|
|
444
|
+
? (e.target instanceof Element &&
|
|
445
|
+
consumes(e.target, e.currentTarget, e.deltaX, e.deltaY)
|
|
446
|
+
? 'scroll' as const
|
|
447
|
+
: 'pan' as const)
|
|
448
|
+
: g!.mode
|
|
449
|
+
gesture.current = {
|
|
450
|
+
mode,
|
|
451
|
+
t: now,
|
|
452
|
+
last: mag,
|
|
453
|
+
peak: fresh ? mag : Math.max(g!.peak, mag),
|
|
454
|
+
sign: sign || (g?.sign ?? 0),
|
|
455
|
+
}
|
|
456
|
+
// A wheel raises the card only when the card consumes it. A canvas
|
|
457
|
+
// pan merely passing beneath the pointer is not a card interaction.
|
|
458
|
+
if (fresh && mode == 'scroll' && e.target instanceof Element) {
|
|
459
|
+
let pin = e.target.closest<HTMLElement>('.Pin')
|
|
460
|
+
if (pin?.dataset.eid) toFront(pin.dataset.eid)
|
|
461
|
+
}
|
|
462
|
+
if (mode == 'scroll') return // scrolling a card's body keeps the latch
|
|
463
|
+
e.preventDefault()
|
|
464
|
+
unlatch()
|
|
465
|
+
camera.value = {
|
|
466
|
+
...camera.value,
|
|
467
|
+
x: x + e.deltaX / zoom,
|
|
468
|
+
y: y + e.deltaY / zoom,
|
|
469
|
+
}
|
|
470
|
+
queue('x', 'y')
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Spawn a card+pin at a screen point, minting any comps first. With a
|
|
475
|
+
// grab offset the card lands where its drag ghost was dropped; without
|
|
476
|
+
// one it drops centered-x with the titlebar middle under the point.
|
|
477
|
+
let spawnAt = (
|
|
478
|
+
changes: Change[],
|
|
479
|
+
target: string,
|
|
480
|
+
view: string | undefined,
|
|
481
|
+
w: number,
|
|
482
|
+
sx: number,
|
|
483
|
+
sy: number,
|
|
484
|
+
ox?: number,
|
|
485
|
+
oy?: number,
|
|
486
|
+
) => {
|
|
487
|
+
if (changes.length) mutate(...changes)
|
|
488
|
+
let at = toPlane(sx, sy, el.current!.getBoundingClientRect())
|
|
489
|
+
let { zoom } = camera.value
|
|
490
|
+
let card = uuid()
|
|
491
|
+
mutate(
|
|
492
|
+
{
|
|
493
|
+
eid: card,
|
|
494
|
+
name: 'card',
|
|
495
|
+
comp: {
|
|
496
|
+
eid: card,
|
|
497
|
+
target: target,
|
|
498
|
+
view: view ?? resolve(ent(target)).view,
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
eid: card,
|
|
503
|
+
name: 'pin',
|
|
504
|
+
comp: {
|
|
505
|
+
eid: card,
|
|
506
|
+
canvas: eid,
|
|
507
|
+
// w=0 is auto (the Pin-auto clamp finds the width); center on a
|
|
508
|
+
// nominal card so the drop point still feels like the middle.
|
|
509
|
+
x: Math.round(at.x - (ox != null ? ox / zoom : (w || 480) / 2)),
|
|
510
|
+
y: Math.round(at.y - (oy != null ? oy / zoom : 15)),
|
|
511
|
+
w,
|
|
512
|
+
h: 0,
|
|
513
|
+
z: topZ(eid) + 1,
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// A drag dropped on the canvas spawns a new card: our own payloads carry
|
|
520
|
+
// the view + grab offset; anything from outside (desktop files, dragged
|
|
521
|
+
// links or text) runs the same pipeline as pasting.
|
|
522
|
+
let drop = async (e: DragEvent & { currentTarget: HTMLDivElement }) => {
|
|
523
|
+
let dt = e.dataTransfer
|
|
524
|
+
if (!dt) return
|
|
525
|
+
e.preventDefault()
|
|
526
|
+
let sx = e.clientX
|
|
527
|
+
let sy = e.clientY
|
|
528
|
+
let data = dt.getData('application/x-tasks-card')
|
|
529
|
+
if (data) {
|
|
530
|
+
let { target, view, w, ox, oy, pin } = JSON.parse(data)
|
|
531
|
+
// A List row carries its pin: MOVE that card here instead of cloning a
|
|
532
|
+
// new one — it lands under the ghost like a spawn does.
|
|
533
|
+
if (pin && cache.value[pin]?.pin) {
|
|
534
|
+
let at = toPlane(sx, sy, el.current!.getBoundingClientRect())
|
|
535
|
+
let { zoom } = camera.value
|
|
536
|
+
mutate({
|
|
537
|
+
eid: pin,
|
|
538
|
+
name: 'pin',
|
|
539
|
+
comp: {
|
|
540
|
+
canvas: eid,
|
|
541
|
+
x: Math.round(at.x - (ox != null ? ox / zoom : (w || 480) / 2)),
|
|
542
|
+
y: Math.round(at.y - (oy != null ? oy / zoom : 15)),
|
|
543
|
+
w: w || 0,
|
|
544
|
+
h: 0,
|
|
545
|
+
},
|
|
546
|
+
})
|
|
547
|
+
return
|
|
548
|
+
}
|
|
549
|
+
spawnAt([], target, view, w, sx, sy, ox, oy)
|
|
550
|
+
return
|
|
551
|
+
}
|
|
552
|
+
let texts: string[] = []
|
|
553
|
+
for (let f of dt.files) {
|
|
554
|
+
if (f.type.startsWith('text/') || !f.type) texts.push(await f.text())
|
|
555
|
+
}
|
|
556
|
+
if (!texts.length) {
|
|
557
|
+
let uri = dt.getData('text/uri-list').split('\n')
|
|
558
|
+
.find((l) => l && !l.startsWith('#'))
|
|
559
|
+
let t = uri ?? dt.getData('text/plain')
|
|
560
|
+
if (t) texts.push(t)
|
|
561
|
+
}
|
|
562
|
+
for (let [i, t] of texts.entries()) {
|
|
563
|
+
let spec = pasted(t)
|
|
564
|
+
if (spec) {
|
|
565
|
+
spawnAt(
|
|
566
|
+
spec.changes,
|
|
567
|
+
spec.target,
|
|
568
|
+
spec.view,
|
|
569
|
+
spec.w ?? 0,
|
|
570
|
+
sx + i * 24,
|
|
571
|
+
sy + i * 24,
|
|
572
|
+
)
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
let context = (e: MouseEvent) => {
|
|
578
|
+
if (e.target instanceof Element && e.target.closest('.Pin')) return
|
|
579
|
+
actionsAt(cardCommands.map((name) => ({
|
|
580
|
+
label: name,
|
|
581
|
+
run: () => {
|
|
582
|
+
let made = run(name, { eid, rows: rows() })
|
|
583
|
+
spawnAt(
|
|
584
|
+
made.changes ?? [],
|
|
585
|
+
made.card!,
|
|
586
|
+
undefined,
|
|
587
|
+
0,
|
|
588
|
+
e.clientX,
|
|
589
|
+
e.clientY,
|
|
590
|
+
)
|
|
591
|
+
},
|
|
592
|
+
})))(e)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return (
|
|
596
|
+
<Frame
|
|
597
|
+
elRef={el}
|
|
598
|
+
onPointerDown={down}
|
|
599
|
+
onPointerMove={(e: PointerEvent) => {
|
|
600
|
+
mouse.current = { x: e.clientX, y: e.clientY }
|
|
601
|
+
}}
|
|
602
|
+
onPointerLeave={() => {
|
|
603
|
+
mouse.current = null
|
|
604
|
+
}}
|
|
605
|
+
onWheel={wheel}
|
|
606
|
+
onDragOver={(e: DragEvent) => e.preventDefault()}
|
|
607
|
+
onDrop={drop}
|
|
608
|
+
onContextMenu={context}
|
|
609
|
+
// Double-click a board row: the task leaps out as its own card at
|
|
610
|
+
// the mouse — the click-shaped twin of dragging the row out. Links
|
|
611
|
+
// and buttons inside the row keep their own double-clicks.
|
|
612
|
+
onDoubleClick={(e: MouseEvent) => {
|
|
613
|
+
if (!(e.target instanceof Element)) return
|
|
614
|
+
if (e.target.closest('a, button, input, [contenteditable]')) return
|
|
615
|
+
let row = e.target.closest('.Board_Item') as HTMLElement | null
|
|
616
|
+
if (!row?.dataset.eid) return
|
|
617
|
+
spawnAt([], row.dataset.eid, 'Full', 0, e.clientX, e.clientY)
|
|
618
|
+
}}
|
|
619
|
+
>
|
|
620
|
+
<Plane elRef={plane}>
|
|
621
|
+
{cards.map((p) => <Card key={p.eid} p={p} />)}
|
|
622
|
+
</Plane>
|
|
623
|
+
</Frame>
|
|
624
|
+
)
|
|
625
|
+
}
|