@marver-design/marver 0.23.1 → 0.25.0
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/CHANGELOG.md +66 -0
- package/README.md +3 -1
- package/dist/anchor-DVV732zR.mjs +33 -0
- package/dist/anchor-check-BE5VVN6Q.mjs +135 -0
- package/dist/{bake-DQtnDB8-.mjs → bake-D8byeRzB.mjs} +1 -1
- package/dist/{boards-BRLnoTC3.mjs → board-tree-DRioF94d.mjs} +21 -277
- package/dist/boards-CGg6piKF.mjs +342 -0
- package/dist/{boards-Dv-Ipd8G.mjs → boards-Csxj2WJn.mjs} +23 -9
- package/dist/{build-_ndp_dXn.mjs → build-BHoWLvSj.mjs} +63 -37
- package/dist/cli.mjs +31 -17
- package/dist/{collab-mAiNZlDj.mjs → collab-gqNdScUE.mjs} +39 -9
- package/dist/{comments-DZyobpxG.mjs → comments-Zoch254k.mjs} +19 -1
- package/dist/{comments-BlqyZh3D.mjs → comments-pTLlhjh4.mjs} +150 -20
- package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
- package/dist/{context-CdkNiKdJ.mjs → context-D2ugHqwO.mjs} +17 -123
- package/dist/{daemon-BvMPdQ3k.mjs → daemon-Cl8KXGW4.mjs} +146 -64
- package/dist/{dev-Cf-4eqaC.mjs → dev-DJdgow47.mjs} +23 -11
- package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
- package/dist/imports-WBSnnHLb.mjs +143 -0
- package/dist/{init-hfZV7TwY.mjs → init-DO4DhUt_.mjs} +28 -6
- package/dist/link-C-qUIuKU.mjs +160 -0
- package/dist/{board-status-BZSzc9Hp.mjs → manifest-DnAte_fB.mjs} +537 -13
- package/dist/marks-DFuintmJ.mjs +50 -0
- package/dist/marks-koRsbHfe.mjs +397 -0
- package/dist/{marver-id-gate-B_idGdHm.mjs → marver-id-gate-DGANtVyC.mjs} +2 -2
- package/dist/perf-CCisg-ny.mjs +49 -0
- package/dist/perf-QJIWtTw1.mjs +68 -0
- package/dist/{plugin-DoXql0ZZ.mjs → plugin-CTyhjwoJ.mjs} +469 -82
- package/dist/{poster-XBmUvQiL.mjs → poster-D0cbV7hi.mjs} +1 -1
- package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
- package/dist/{publish-bakes-KKTHWqq3.mjs → publish-bakes--l8ot2eQ.mjs} +9 -9
- package/dist/{serve-z5qtj_wJ.mjs → serve-wv2QWdxB.mjs} +6 -6
- package/dist/{share-BD-wcDQq.mjs → share-ScamJcks.mjs} +1 -1
- package/dist/{shot-DOD8v6fJ.mjs → shot-CckrGW-J.mjs} +19 -11
- package/dist/{shot-Dh6fV1Lm.mjs → shot-jdO_B6Qw.mjs} +1 -1
- package/dist/{summary-C7CAypbB.mjs → summary-CrW88e3q.mjs} +1 -1
- package/dist/{sync-DoA1vf4u.mjs → sync-C3035OnJ.mjs} +18 -8
- package/dist/{work-ClFFq0Qh.mjs → work-CpJn1gwY.mjs} +8 -4
- package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
- package/docs/boards-and-folders.md +70 -4
- package/docs/live-jam.md +12 -4
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +2 -1
- package/src/client/frame-host/inspect.js +195 -84
- package/src/client/frame-host/main.tsx +7 -2
- package/src/client/frame-host/registry.ts +5 -5
- package/src/client/shell/App.tsx +98 -30
- package/src/client/shell/BoardList.tsx +74 -16
- package/src/client/shell/Comments.tsx +79 -34
- package/src/client/shell/ContextMenu.tsx +5 -2
- package/src/client/shell/LockedApp.tsx +45 -12
- package/src/client/shell/Play.tsx +35 -32
- package/src/client/shell/Toolbar.tsx +3 -1
- package/src/client/shell/canvas/Canvas.tsx +2 -0
- package/src/client/shell/canvas/FrameNode.tsx +15 -5
- package/src/client/shell/canvas/sleep.ts +4 -3
- package/src/client/shell/canvas/updates.ts +55 -0
- package/src/client/shell/comments-store.ts +48 -17
- package/src/client/shell/goto.ts +11 -14
- package/src/client/shell/hash.ts +12 -5
- package/src/client/shell/icons.tsx +1 -2
- package/src/client/shell/legacy-links.ts +67 -0
- package/src/client/shell/marks-ui.tsx +117 -0
- package/src/client/shell/pin-layout.ts +37 -0
- package/src/client/shell/store.ts +377 -67
- package/src/client/shell/styles.css +32 -8
- package/src/client/stage/main.tsx +19 -2
- package/src/shared/anchor.ts +57 -0
- package/src/shared/board-tree.ts +27 -10
- package/src/shared/events.ts +19 -10
- package/src/shared/marks.ts +70 -0
- package/templates/AGENTS-embedded.md +34 -15
- package/templates/AGENTS-studio.md +34 -15
- package/templates/instructions/boards.md +9 -5
- package/templates/instructions/iterate.md +20 -10
- package/templates/instructions/jam.md +13 -4
- package/templates/instructions/publish.md +2 -1
- package/templates/instructions/reference/deck-story.md +2 -2
- package/dist/link-BodAbIQz.mjs +0 -132
- package/dist/manifest-TpfDWldB.mjs +0 -528
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calm updates, the shell's half (spec 26 Part 2): a node an edit made stale reloads through the
|
|
3
|
+
* same boot queue a board uses (admission.ts) - at most four at a time, the one nearest the centre
|
|
4
|
+
* of the view first - and only while it is on screen (or within half a screen of it) and not in use.
|
|
5
|
+
* Further off it waits until it comes near; in use (interact, a drag, laser or comment on it) it waits for a safe point; while
|
|
6
|
+
* the play stage covers the canvas, the canvas counts as off screen. A job checks all of that again
|
|
7
|
+
* when its turn comes.
|
|
8
|
+
*/
|
|
9
|
+
import { admit, release } from './admission.ts'
|
|
10
|
+
import { frameIsLeased, useStore, type Node } from '../store.ts'
|
|
11
|
+
|
|
12
|
+
const rect = (key: string) => document.querySelector(`[data-node="${CSS.escape(key)}"]`)?.getBoundingClientRect()
|
|
13
|
+
const view = () => document.querySelector('.sh-canvas')?.getBoundingClientRect()
|
|
14
|
+
|
|
15
|
+
/** On screen at any zoom - or within half a screen of it, so a small pan shows fresh frames and a
|
|
16
|
+
* camera still moving between two places does not starve the frames on its way. */
|
|
17
|
+
function onScreen(key: string): boolean {
|
|
18
|
+
const r = rect(key), c = view()
|
|
19
|
+
if (!r || !c) return false
|
|
20
|
+
const mx = c.width / 2, my = c.height / 2
|
|
21
|
+
return r.right > c.left - mx && r.left < c.right + mx && r.bottom > c.top - my && r.top < c.bottom + my
|
|
22
|
+
}
|
|
23
|
+
const rank = (key: string) => () => {
|
|
24
|
+
const r = rect(key), c = view()
|
|
25
|
+
return r && c ? Math.hypot(r.x + r.width / 2 - c.x - c.width / 2, r.y + r.height / 2 - c.y - c.height / 2) : Infinity
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ready = (n: Node) => {
|
|
29
|
+
const s = useStore.getState()
|
|
30
|
+
// a document to replace (ready, or errored), never one still booting for the first time
|
|
31
|
+
return !!n.stale && !n.missing && (n.status === 'ready' || n.status === 'error') && !s.play && !frameIsLeased(n.frame, s) && onScreen(n.key)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let ticker: ReturnType<typeof setInterval> | undefined
|
|
35
|
+
|
|
36
|
+
/** Give every stale node that may reload now a place in the queue. Stale nodes off screen are looked
|
|
37
|
+
* at again on a slow tick (a pan or a zoom brings them in), stopped once none is left. */
|
|
38
|
+
export function pumpUpdates(): void {
|
|
39
|
+
const s = useStore.getState()
|
|
40
|
+
const stale = s.nodes.filter((n) => n.stale && !n.missing)
|
|
41
|
+
if (!stale.length) { clearInterval(ticker); ticker = undefined; return }
|
|
42
|
+
ticker ??= setInterval(pumpUpdates, 400)
|
|
43
|
+
for (const n of stale) {
|
|
44
|
+
if (!ready(n)) continue
|
|
45
|
+
admit({
|
|
46
|
+
key: n.key,
|
|
47
|
+
rank: rank(n.key),
|
|
48
|
+
start: () => {
|
|
49
|
+
const now = useStore.getState().nodes.find((x) => x.key === n.key)
|
|
50
|
+
if (!now || !ready(now)) { release(n.key); return } // scrolled away or taken in use while it queued
|
|
51
|
+
useStore.getState().startReload(n.key) // released when its document is ready (FrameNode)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
* on which one it is beyond capability flags the endpoints themselves report.
|
|
6
6
|
*/
|
|
7
7
|
import { create } from 'zustand'
|
|
8
|
-
import { replay, type CommentEvent, type Thread } from '../../shared/events.ts'
|
|
8
|
+
import { asks, replay, type CommentEvent, type Thread } from '../../shared/events.ts'
|
|
9
9
|
import { mentionPeople, mentionsIn } from './mentions.ts'
|
|
10
10
|
import { playPing } from './sound.ts'
|
|
11
11
|
import { ROUTE } from '../const.ts'
|
|
12
|
+
import { ALL_SCENES } from '../../shared/board-tree.ts'
|
|
13
|
+
import { UNPLACED } from './hash.ts'
|
|
14
|
+
|
|
15
|
+
/** What the Not on a board view says when asked for a comment: a note needs a board to live on. */
|
|
16
|
+
export const NO_COMMENTS_HERE = 'pin it on a board to comment'
|
|
12
17
|
|
|
13
18
|
export interface Me {
|
|
14
19
|
email: string
|
|
@@ -53,6 +58,8 @@ interface CommentsState {
|
|
|
53
58
|
* path as the poll, so dedup + the reply notification behave identically. ANY board:
|
|
54
59
|
* notifications must reach the user wherever they are on the canvas. */
|
|
55
60
|
poke(board?: string): void
|
|
61
|
+
/** A thread by id, from any board's log - one sweep first when it is not loaded yet. */
|
|
62
|
+
findThread(id: string): Promise<Thread | null>
|
|
56
63
|
/** `board` routes the write to a thread's ORIGIN log; default = the active board. */
|
|
57
64
|
send(events: CommentEvent[], board?: string): Promise<boolean>
|
|
58
65
|
create(body: string): Promise<void>
|
|
@@ -109,22 +116,31 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
109
116
|
// log), keyed on the event id via `union`'s fresh filter so it fires exactly once. The pill's
|
|
110
117
|
// board is the THREAD's origin board, so View can navigate there. One ping per batch, like a
|
|
111
118
|
// person's - except for a jam job's opening "On it" line (ids `jam-e<attempt>-…`, daemon.ts): the pill
|
|
112
|
-
// shows it, the ping waits for the answer.
|
|
119
|
+
// shows it, the ping waits for the answer. A jam job whose final block asks what its opening
|
|
120
|
+
// line already said re-flags that line (an edit carrying `asks`): the question gets its notice.
|
|
113
121
|
const notifyAgent = (fresh: CommentEvent[]) => {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
const news = fresh.flatMap((e) => {
|
|
123
|
+
if (!e.agent) return []
|
|
124
|
+
if (e.type === 'reply' || e.type === 'create') return [{ e, threadId: e.parentId ?? e.commentId ?? '', body: e.body, ask: asks(e, e.type === 'create') }]
|
|
125
|
+
if (e.type !== 'edit' || e.asks !== true) return []
|
|
126
|
+
const t = get().threads.find((t) => t.id === e.commentId || t.replies.some((r) => r.id === e.commentId))
|
|
127
|
+
return t ? [{ e, threadId: t.id, body: (t.id === e.commentId ? t : t.replies.find((r) => r.id === e.commentId))?.body, ask: true }] : []
|
|
128
|
+
})
|
|
129
|
+
if (!news.length) return
|
|
130
|
+
if (news.some(({ e }) => !/^jam-e\d+-/.test(e.id))) playPing()
|
|
117
131
|
void import('./store.ts').then(({ useStore }) => {
|
|
118
132
|
const s = useStore.getState()
|
|
119
|
-
for (const e of
|
|
120
|
-
const threadId = e.parentId ?? e.commentId ?? ''
|
|
133
|
+
for (const { e, threadId, body, ask } of news) {
|
|
121
134
|
// the FRAME is the news: resolve the reply's thread -> frame -> manifest title + intent
|
|
122
135
|
const t = get().threads.find((t) => t.id === threadId)
|
|
123
136
|
const entry = t?.frame ? s.manifest?.frames.find((f) => f.id === t.frame) : undefined
|
|
124
137
|
s.jamToast({
|
|
125
138
|
threadId, board: t?.board ?? e.board ?? get().board ?? '', ts: e.ts,
|
|
126
|
-
preview: (
|
|
139
|
+
preview: (body ?? '').replace(/\s+/g, ' ').slice(0, 90),
|
|
127
140
|
frame: t?.frame, frameTitle: entry?.title ?? t?.frame, intent: entry?.intent,
|
|
141
|
+
// a message that asks stands alone; the rest fold into the board's round (the writer's
|
|
142
|
+
// `asks`, else the old rule: a note asks, a reply asks when it ends in "?")
|
|
143
|
+
round: !ask,
|
|
128
144
|
})
|
|
129
145
|
}
|
|
130
146
|
})
|
|
@@ -186,16 +202,18 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
186
202
|
const stamped = (events: CommentEvent[] | undefined, board: string): CommentEvent[] =>
|
|
187
203
|
(events ?? []).map((e) => (e.board ? e : { ...e, board }))
|
|
188
204
|
/** Every board that could hold a log: the switcher list plus the active board -
|
|
189
|
-
* the sum of what this client can navigate to
|
|
190
|
-
*
|
|
205
|
+
* the sum of what this client can navigate to - and the old all-scenes log, whose threads
|
|
206
|
+
* outlive their board (spec 26) until a published canvas says it has none. Transport
|
|
207
|
+
* failure = just the active board; the next sweep widens again. */
|
|
208
|
+
let allScenesOff = false
|
|
191
209
|
const watchNames = async (): Promise<string[]> => {
|
|
192
|
-
const names = new Set<string>()
|
|
210
|
+
const names = new Set<string>(allScenesOff ? [] : [ALL_SCENES])
|
|
193
211
|
try {
|
|
194
212
|
const { fetchBoardNames } = await import('./store.ts')
|
|
195
213
|
for (const n of await fetchBoardNames()) names.add(n)
|
|
196
214
|
} catch { /* keep what we have */ }
|
|
197
215
|
const b = get().board
|
|
198
|
-
if (b) names.add(b)
|
|
216
|
+
if (b && b !== UNPLACED) names.add(b)
|
|
199
217
|
return [...names]
|
|
200
218
|
}
|
|
201
219
|
/** One sweep across every board's log - the notification feed and the frame-scoped
|
|
@@ -204,7 +222,10 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
204
222
|
if (apiOff) return
|
|
205
223
|
const names = await watchNames()
|
|
206
224
|
const results = await Promise.all(names.map((n) =>
|
|
207
|
-
api(`comments/${n}`).then((r) =>
|
|
225
|
+
api(`comments/${n}`).then((r) => {
|
|
226
|
+
if (n === ALL_SCENES && r.status === 404) allScenesOff = true // a canvas published before 0.25 serves none
|
|
227
|
+
return r.ok ? stamped(r.data.events as CommentEvent[] | undefined, n) : null
|
|
228
|
+
})))
|
|
208
229
|
union(results.flatMap((evs) => evs ?? []))
|
|
209
230
|
names.forEach((n, i) => { if (results[i] !== null) baselinedBoards.add(n) })
|
|
210
231
|
}
|
|
@@ -216,7 +237,7 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
216
237
|
|
|
217
238
|
poke(board) {
|
|
218
239
|
const b = board ?? get().board
|
|
219
|
-
if (!b || apiOff) return
|
|
240
|
+
if (!b || apiOff || b === UNPLACED) return
|
|
220
241
|
void api(`comments/${b}`).then((r) => {
|
|
221
242
|
if (!r.ok) return
|
|
222
243
|
union(stamped(r.data.events, b)) // brand-new events still notify via the bootTs rule
|
|
@@ -227,7 +248,7 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
227
248
|
async load(board) {
|
|
228
249
|
// threads are frame-scoped and global - a board switch keeps them all (the same
|
|
229
250
|
// frame on another board keeps its pins); only the open card and a draft reset
|
|
230
|
-
if (get().board !== board) set({ board, active: null, draft: null })
|
|
251
|
+
if (get().board !== board) set({ board, active: null, draft: null, ...(board === UNPLACED ? { commentMode: false } : {}) })
|
|
231
252
|
else set({ board })
|
|
232
253
|
const me = await api('me')
|
|
233
254
|
if (me.status === 404) { apiOff = true; return } // static serve: no comments API at all
|
|
@@ -326,7 +347,13 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
326
347
|
await get().send([{ id: uuid(), ts: Date.now(), type: reopen ? 'reopen' : 'resolve', commentId: threadId }], origin)
|
|
327
348
|
},
|
|
328
349
|
|
|
329
|
-
|
|
350
|
+
async findThread(id) {
|
|
351
|
+
if (!get().threads.some((t) => t.id === id)) await fetchAll()
|
|
352
|
+
return get().threads.find((t) => t.id === id) ?? null
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
// the Not on a board view shows threads but takes no new ones (spec 26): a note needs a board
|
|
356
|
+
setMode(on) { if (on && get().board === UNPLACED) return; set({ commentMode: on, ...(on ? { show: true } : { draft: null }) }) },
|
|
330
357
|
setShow(show) { set({ show }) },
|
|
331
358
|
setShowAnchor(showAnchor) { set({ showAnchor }) },
|
|
332
359
|
setActive(active) {
|
|
@@ -337,7 +364,11 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
337
364
|
set({ active, mentionSeen })
|
|
338
365
|
} else set({ active })
|
|
339
366
|
},
|
|
340
|
-
setDraft(draft) {
|
|
367
|
+
setDraft(draft) {
|
|
368
|
+
const board = draft ? draft.board ?? get().board ?? undefined : undefined
|
|
369
|
+
if (board === UNPLACED) return
|
|
370
|
+
set({ draft: draft ? { ...draft, board } : null })
|
|
371
|
+
},
|
|
341
372
|
dismissIdentity() { set({ needsIdentity: false }) }, // inviteToken survives dismissal - commenting later reopens the claim
|
|
342
373
|
|
|
343
374
|
async signIn(email, password) {
|
package/src/client/shell/goto.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* and a sticky note's link (shell DOM, spec 18). On this board: select and fit. Elsewhere: follow
|
|
4
4
|
* the frame home (below). Never edits a board unless no board pins the target.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { fetchMembership, useStore } from './store.ts'
|
|
7
|
+
import { UNPLACED } from './hash.ts'
|
|
7
8
|
import { canvasCtl } from './canvas/ctl.ts'
|
|
8
9
|
|
|
9
10
|
/** Navigate to a frame id. `carry` keeps interact mode across the hop (a link inside an
|
|
@@ -35,10 +36,7 @@ async function gotoAcrossBoards(target: string, carry: boolean) {
|
|
|
35
36
|
const seq = navigated()
|
|
36
37
|
let home: string | null = null
|
|
37
38
|
try {
|
|
38
|
-
|
|
39
|
-
for (const name of names) {
|
|
40
|
-
if ((await boardFrames(name)).includes(target)) { home = name; break }
|
|
41
|
-
}
|
|
39
|
+
home = (await fetchMembership()).boards.find((b) => b.name !== s.board && b.frames.includes(target))?.name ?? null
|
|
42
40
|
} catch {
|
|
43
41
|
// a transport failure is NOT proof the frame is unpinned - spawning here would
|
|
44
42
|
// recreate the board mutation this function exists to prevent
|
|
@@ -61,12 +59,14 @@ async function gotoAcrossBoards(target: string, carry: boolean) {
|
|
|
61
59
|
/** Navigation supersedes any goto or reveal still on its way - its board lookup (gotoSeq) AND a board
|
|
62
60
|
* switch it already started (a switch to the board on screen cancels any pending one: store.ts) - so
|
|
63
61
|
* a slow lookup can never yank the view away from where the human has gone since. Every entry point
|
|
64
|
-
* calls it: a pasted link, back/forward, a goto, a reveal. */
|
|
62
|
+
* calls it: a pasted link, back/forward, a goto, a reveal, a board picked in the sidebar. */
|
|
65
63
|
export function navigated(): number {
|
|
66
64
|
const s = useStore.getState()
|
|
67
65
|
if (s.board) void s.switchBoard(s.board)
|
|
68
66
|
return ++gotoSeq
|
|
69
67
|
}
|
|
68
|
+
/** Is this still the latest navigation - nothing newer since `navigated()` handed it out? */
|
|
69
|
+
export const isLatest = (seq: number): boolean => seq === gotoSeq
|
|
70
70
|
|
|
71
71
|
/** Switch to `home` and select + fit `target` there once the board commits - unless the human has
|
|
72
72
|
* moved on: newer navigation, or a board they switched to themselves while the lookup ran. */
|
|
@@ -90,9 +90,9 @@ async function landOn(home: string, target: string, carry: boolean, seq: number,
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/** Show a frame where it lives, for a LINK (a pasted canvas link naming a frame the board does
|
|
93
|
-
* not show, the way back from a focus link): this board, else the first
|
|
94
|
-
*
|
|
95
|
-
* must not edit a board. */
|
|
93
|
+
* not show, the way back from a focus link): this board, else the first board that shows it
|
|
94
|
+
* (archive boards last), else - a frame on no board - the Not on a board view. Unlike a goto it
|
|
95
|
+
* never spawns - opening a link must not edit a board. */
|
|
96
96
|
export async function revealFrame(target: string): Promise<void> {
|
|
97
97
|
const s = useStore.getState()
|
|
98
98
|
const here = s.nodes.find((n) => n.frame === target && !n.missing)
|
|
@@ -107,11 +107,8 @@ export async function revealFrame(target: string): Promise<void> {
|
|
|
107
107
|
const from = s.board
|
|
108
108
|
let home: string | null = null
|
|
109
109
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
if ((await boardFrames(name)).includes(target)) { home = name; break }
|
|
113
|
-
}
|
|
114
|
-
if (!home && all.includes('all-scenes')) home = 'all-scenes'
|
|
110
|
+
const m = await fetchMembership()
|
|
111
|
+
home = m.boards.find((b) => b.name !== s.board && b.frames.includes(target))?.name ?? (m.unplaced.includes(target) && s.board !== UNPLACED ? UNPLACED : null)
|
|
115
112
|
} catch {
|
|
116
113
|
return useStore.getState().toast(`could not read the boards - try again`)
|
|
117
114
|
}
|
package/src/client/shell/hash.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* shell writes it as board/selection/play change and parses it once on boot; camera
|
|
5
5
|
* intent is always fit semantics (fit-all / fit-selection), never raw coordinates.
|
|
6
6
|
*
|
|
7
|
-
* #/
|
|
7
|
+
* #/ the landing board, fit all
|
|
8
8
|
* #/b/<board> board, fit all
|
|
9
|
+
* #/b/~unplaced the Not on a board view (UNPLACED)
|
|
10
|
+
* #/b/all-scenes... a link from before 0.25: lands on a real board (legacy-links.ts)
|
|
9
11
|
* #/b/<board>?n=k1,k2 board with nodes selected, camera fit to selection
|
|
10
12
|
* #/b/<board>?f=<scene/frame>,... the same, by FRAME id - the link an agent can write
|
|
11
13
|
* (node keys are the shell's; `marver link` prints these)
|
|
@@ -33,6 +35,9 @@ export interface HashState {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const BOARD_RE = /^[a-z0-9][a-z0-9-]*$/
|
|
38
|
+
/** The Not on a board view (spec 26, Part 7): a temporary board of the frames no board shows,
|
|
39
|
+
* never saved. Off the board-name grammar, so no board file can ever be called this. */
|
|
40
|
+
export const UNPLACED = '~unplaced'
|
|
36
41
|
const isFrameId = (at: string) => /^[\w./-]{1,200}$/.test(at) && !at.includes('..')
|
|
37
42
|
|
|
38
43
|
/** The node keys a link names on the loaded board: its keys (`n`), the nodes showing its frames
|
|
@@ -64,7 +69,7 @@ export function parseHash(hash: string = location.hash): HashState {
|
|
|
64
69
|
const m = path.match(/^\/(b|p)\/([^/?]+)$/)
|
|
65
70
|
if (!m) return {}
|
|
66
71
|
const board = decodeURIComponent(m[2])
|
|
67
|
-
if (!BOARD_RE.test(board)) return {}
|
|
72
|
+
if (!BOARD_RE.test(board) && board !== UNPLACED) return {}
|
|
68
73
|
if (m[1] === 'b') {
|
|
69
74
|
const list = (k: string) => (params.get(k) ?? '').split(',').map((s) => s.trim()).filter(Boolean)
|
|
70
75
|
const n = list('n')
|
|
@@ -100,7 +105,7 @@ export function buildHash(s: HashState): string {
|
|
|
100
105
|
if (s.play.slides) p.set('slides', '1')
|
|
101
106
|
return `#/p/${s.board}?${p}`
|
|
102
107
|
}
|
|
103
|
-
if (!s.board
|
|
108
|
+
if (!s.board) return '#/'
|
|
104
109
|
const p = new URLSearchParams()
|
|
105
110
|
if (s.n?.length) p.set('n', s.n.join(','))
|
|
106
111
|
if (s.c) p.set('c', s.c)
|
|
@@ -116,5 +121,7 @@ export function writeHash(s: HashState, push = false) {
|
|
|
116
121
|
else history.replaceState(null, '', h)
|
|
117
122
|
}
|
|
118
123
|
|
|
119
|
-
/** The hash as it stood when the app loaded - boot intent, captured once
|
|
120
|
-
|
|
124
|
+
/** The hash as it stood when the app loaded - boot intent, captured once; re-aimed only when an old
|
|
125
|
+
* link resolves to where it lands now (legacy-links.ts), before the board boots. */
|
|
126
|
+
export let bootHash = parseHash()
|
|
127
|
+
export function retargetBoot(h: HashState) { bootHash = h }
|
|
@@ -75,13 +75,12 @@ export function IntentGlyph({ intent, size = 14, ...rest }: IconProps & { intent
|
|
|
75
75
|
/** The slide badge (v1.5): a 16:9 stage with the play wedge - a deck frame. */
|
|
76
76
|
export const SlideFrameIcon = icon(<path d="M192,48H64A16,16,0,0,0,48,64V192a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64A16,16,0,0,0,192,48Zm0,144H64V64H192V192ZM240,56V200a8,8,0,0,1-16,0V56a8,8,0,0,1,16,0ZM32,56V200a8,8,0,0,1-16,0V56a8,8,0,0,1,16,0Z" />)
|
|
77
77
|
export const PanelHollowIcon = icon(<><rect x="32" y="48" width="192" height="160" rx="32" fill="none" stroke="currentColor" strokeWidth="16" /><rect x="72" y="88" width="48" height="80" rx="24" fill="none" stroke="currentColor" strokeWidth="14" /></>)
|
|
78
|
-
/** Board glyphs: CardsThree = the built-in `all-scenes` board; Cards = curated boards. */
|
|
79
|
-
export const CardsThreeIcon = icon(<path d="M208,88H48a16,16,0,0,0-16,16v96a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104A16,16,0,0,0,208,88Zm0,112H48V104H208v96ZM48,64a8,8,0,0,1,8-8H200a8,8,0,0,1,0,16H56A8,8,0,0,1,48,64ZM64,32a8,8,0,0,1,8-8H184a8,8,0,0,1,0,16H72A8,8,0,0,1,64,32Z" />)
|
|
80
78
|
export const FrameCornersIcon = icon(<path d="M160 48h40a8 8 0 0 1 8 8v40M208 160v40a8 8 0 0 1-8 8h-40M96 208H56a8 8 0 0 1-8-8v-40M48 96V56a8 8 0 0 1 8-8h40" fill="none" stroke="currentColor" strokeWidth="16" strokeLinecap="round" strokeLinejoin="round" />)
|
|
81
79
|
export const ArrowLeftIcon = icon(<path d="M224,128a8,8,0,0,1-8,8H59.31l58.35,58.34a8,8,0,0,1-11.32,11.32l-72-72a8,8,0,0,1,0-11.32l72-72a8,8,0,0,1,11.32,11.32L59.31,120H216A8,8,0,0,1,224,128Z" />)
|
|
82
80
|
export const ArrowRightIcon = icon(<path d="M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z" />)
|
|
83
81
|
/** Variants/experimentation mark: the flask (Phosphor). */
|
|
84
82
|
export const VariantsIcon = icon(<path d="M223.45,208.19,168,101.11V40h8a8,8,0,0,0,0-16H80a8,8,0,0,0,0,16h8v61.11L32.55,208.19A16,16,0,0,0,46.86,232H209.14a16,16,0,0,0,14.31-23.81ZM102.13,108.5A8,8,0,0,0,104,103.35V40h48v63.35a8,8,0,0,0,1.87,5.15L179.36,157c-11.71,2.87-26.5.66-44.16-6.64-14.08-5.82-27.34-8.53-39.66-8.16ZM46.86,216,84.36,143.6c11.68-2.9,26.47-.68,44.13,6.61,13.09,5.42,25.36,8.11,36.65,8.11a67.86,67.86,0,0,0,22.53-3.72L209.14,216Z" />)
|
|
83
|
+
/** The board glyph, for a board with no type. */
|
|
85
84
|
export const CardsIcon = icon(<path d="M184,72H40A16,16,0,0,0,24,88V200a16,16,0,0,0,16,16H184a16,16,0,0,0,16-16V88A16,16,0,0,0,184,72Zm0,128H40V88H184V200ZM232,56V176a8,8,0,0,1-16,0V56H64a8,8,0,0,1,0-16H216A16,16,0,0,1,232,56Z" />)
|
|
86
85
|
/** Viewport-name -> device glyph; unknown custom names fall back to the generic Devices. */
|
|
87
86
|
export function deviceIcon(name: string | null, size = 14) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links from before 0.25 (spec 26, Part 7). The built-in All Scenes board is gone, but links naming
|
|
3
|
+
* it live on in messages, docs and threads - each one lands on a real board:
|
|
4
|
+
*
|
|
5
|
+
* ?c=<thread> the first board (sidebar order, archive boards last) that shows its frame
|
|
6
|
+
* ?f= / ?s= the board that shows most of them (the first on a tie), those selected, and a
|
|
7
|
+
* notice naming where the others are; the Not on a board view only when none
|
|
8
|
+
* of them is on a board
|
|
9
|
+
* ?n=<keys> the keys turned back into frames - from a leftover all-scenes.json (in dev,
|
|
10
|
+
* or as the build shipped it), or the keys the old board minted (keys.ts) -
|
|
11
|
+
* then as above; none recovered: the landing board, with a notice
|
|
12
|
+
* #/p/all-scenes plays on the first board that shows its frame; device, theme and mode kept
|
|
13
|
+
* #/b/all-scenes the landing board
|
|
14
|
+
*/
|
|
15
|
+
import { ALL_SCENES } from '../../shared/board-tree.ts'
|
|
16
|
+
import { stableNodeKey } from './keys.ts'
|
|
17
|
+
import { UNPLACED, type HashState } from './hash.ts'
|
|
18
|
+
import { ALL_SCENES_KEYS, boardLabel, fetchMembership, PUBLISHED } from './store.ts'
|
|
19
|
+
import { useComments } from './comments-store.ts'
|
|
20
|
+
import { ROUTE } from '../const.ts'
|
|
21
|
+
|
|
22
|
+
export const isLegacyLink = (h: HashState): boolean => h.board === ALL_SCENES
|
|
23
|
+
|
|
24
|
+
/** Where an old link lands now: the hash to apply instead (no board = the landing board), and what
|
|
25
|
+
* to say about it. */
|
|
26
|
+
export async function landLegacy(h: HashState): Promise<{ hash: HashState; notice: string | null }> {
|
|
27
|
+
const { board: _old, n, f, s, c, ...rest } = h
|
|
28
|
+
let m: Awaited<ReturnType<typeof fetchMembership>>
|
|
29
|
+
try { m = await fetchMembership() } catch { return { hash: rest, notice: 'could not read the boards - opened the first one' } }
|
|
30
|
+
const live = [...new Set([...m.boards.flatMap((b) => b.frames), ...m.unplaced])]
|
|
31
|
+
// a frame on no board has the Not on a board view in dev; a published canvas ships no such frame
|
|
32
|
+
const home = (frame: string): string | undefined =>
|
|
33
|
+
m.boards.find((b) => b.frames.includes(frame))?.name ?? (!PUBLISHED && m.unplaced.includes(frame) ? UNPLACED : undefined)
|
|
34
|
+
|
|
35
|
+
if (h.play) return { hash: { ...rest, board: h.play.at ? home(h.play.at) : undefined }, notice: null }
|
|
36
|
+
if (c) {
|
|
37
|
+
const t = await useComments.getState().findThread(c)
|
|
38
|
+
return { hash: { ...rest, board: t?.frame ? home(t.frame) : undefined, c, ...(t?.frame ? { f: [t.frame] } : {}) }, notice: t ? null : 'that thread is not on this canvas any more' }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const frames = new Set([...(f ?? []), ...live.filter((id) => s?.some((sc) => id.startsWith(`${sc}/`)))].filter((id) => live.includes(id)))
|
|
42
|
+
if (n?.length) {
|
|
43
|
+
// node keys: the leftover file's, else the ones the old board gave each frame (it minted them all)
|
|
44
|
+
const byKey = new Map([...live.map((id) => [stableNodeKey(ALL_SCENES, id, 0), id] as const), ...Object.entries(ALL_SCENES_KEYS)])
|
|
45
|
+
if (!PUBLISHED) {
|
|
46
|
+
try {
|
|
47
|
+
const leftover = (await (await fetch(`${ROUTE}/api/boards/${ALL_SCENES}`)).json())?.board as { nodes?: { key?: unknown; frame?: unknown }[] } | null
|
|
48
|
+
for (const node of Array.isArray(leftover?.nodes) ? leftover.nodes : []) if (typeof node?.key === 'string' && typeof node.frame === 'string') byKey.set(node.key, node.frame)
|
|
49
|
+
} catch { /* no leftover, or not JSON: the minted keys stand */ }
|
|
50
|
+
}
|
|
51
|
+
for (const k of n) { const id = byKey.get(k); if (id && live.includes(id)) frames.add(id) }
|
|
52
|
+
if (!frames.size) return { hash: rest, notice: 'the frames that link named could not be found - opened the first board' }
|
|
53
|
+
}
|
|
54
|
+
if (!frames.size) return { hash: rest, notice: null }
|
|
55
|
+
|
|
56
|
+
// the board that shows most of them, the first in sidebar order on a tie
|
|
57
|
+
const asked = [...frames]
|
|
58
|
+
let best: { name: string; frames: string[] } | null = null, most = 0
|
|
59
|
+
for (const b of m.boards) { const k = asked.filter((id) => b.frames.includes(id)).length; if (k > most) { best = b; most = k } }
|
|
60
|
+
if (!best) {
|
|
61
|
+
const anyUnplaced = !PUBLISHED && asked.some((id) => m.unplaced.includes(id))
|
|
62
|
+
return { hash: { ...rest, ...(anyUnplaced ? { board: UNPLACED, f: asked } : {}) }, notice: anyUnplaced ? null : 'those frames are on no board - opened the first one' }
|
|
63
|
+
}
|
|
64
|
+
const here = asked.filter((id) => best!.frames.includes(id))
|
|
65
|
+
const elsewhere = asked.filter((id) => !here.includes(id)).map((id) => { const b = home(id); return `${id} is ${b === UNPLACED ? 'on no board' : b ? `on ${boardLabel(b)}` : 'not shipped'}` })
|
|
66
|
+
return { hash: { ...rest, board: best.name, f: here }, notice: elsewhere.length ? `${here.length} of ${asked.length} here - ${elsewhere.join('; ')}` : null }
|
|
67
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar marks in the shell (spec 25, variant B - one slot). Colour on a row's icon and title
|
|
3
|
+
* carries the state (blue new, orange needs you); the row's one right-hand slot holds what matters
|
|
4
|
+
* most: a question's numbered bubble, then the row's own count or status, then a frame's dot.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, type HTMLAttributes, type ReactNode } from 'react'
|
|
7
|
+
import { create } from 'zustand'
|
|
8
|
+
import { useStore, PUBLISHED, shownRev } from './store.ts'
|
|
9
|
+
import { useComments } from './comments-store.ts'
|
|
10
|
+
import { frameMark, isNew, questions, type Ask, type FrameMark } from '../../shared/marks.ts'
|
|
11
|
+
|
|
12
|
+
/** Every frame's mark, derived ONCE per change of marks, threads or manifest. Rows and headers read
|
|
13
|
+
* one string each, so a change re-renders only what it changes - never the whole shell. */
|
|
14
|
+
interface View { q: Map<string, Ask>; frame: Record<string, string>; fresh: Record<string, true> }
|
|
15
|
+
const useMarkView = create<View>(() => ({ q: new Map(), frame: {}, fresh: {} }))
|
|
16
|
+
const derive = () => {
|
|
17
|
+
const { marks, manifest } = useStore.getState()
|
|
18
|
+
// a published canvas shows no marks at all: no seen state there, and its threads are not yours
|
|
19
|
+
const q = PUBLISHED ? new Map<string, Ask>() : questions(useComments.getState().threads)
|
|
20
|
+
const frame: Record<string, string> = {}, fresh: Record<string, true> = {}
|
|
21
|
+
for (const f of manifest?.frames ?? []) {
|
|
22
|
+
const m = frameMark(marks, q, f.id)
|
|
23
|
+
if (m) frame[f.id] = m.kind === 'new' ? 'new' : `${m.kind}:${m.n}`
|
|
24
|
+
if (isNew(marks, f.id)) fresh[f.id] = true
|
|
25
|
+
}
|
|
26
|
+
useMarkView.setState({ q, frame, fresh })
|
|
27
|
+
}
|
|
28
|
+
useStore.subscribe((s, p) => { if (s.marks !== p.marks || s.manifest !== p.manifest) derive() })
|
|
29
|
+
useComments.subscribe((s, p) => { if (s.threads !== p.threads) derive() })
|
|
30
|
+
|
|
31
|
+
export const asksNow = (): Map<string, Ask> => useMarkView.getState().q
|
|
32
|
+
/** Open Marver questions per frame - for the board list, a light component that rolls up per board. */
|
|
33
|
+
export const useAsks = (): Map<string, Ask> => useMarkView((s) => s.q)
|
|
34
|
+
|
|
35
|
+
const parse = (k: string): FrameMark => {
|
|
36
|
+
if (!k) return null
|
|
37
|
+
if (k === 'new') return { kind: 'new' }
|
|
38
|
+
const [kind, n] = k.split(':')
|
|
39
|
+
return { kind: kind as 'ask' | 'answered', n: Number(n) }
|
|
40
|
+
}
|
|
41
|
+
export const useFrameMark = (id: string): FrameMark => parse(useMarkView((s) => s.frame[id] ?? ''))
|
|
42
|
+
|
|
43
|
+
/** A row standing for many frames: open questions and new frames among `ids`, as one primitive -
|
|
44
|
+
* the row re-renders only when the pair changes. */
|
|
45
|
+
export function useRollup(ids: readonly string[]): { asks: number; fresh: number } {
|
|
46
|
+
const k = useMarkView((s) => {
|
|
47
|
+
let asks = 0, fresh = 0
|
|
48
|
+
for (const id of new Set(ids)) { const f = s.frame[id]; if (f?.startsWith('ask:')) asks += Number(f.slice(4)); if (s.fresh[id]) fresh++ }
|
|
49
|
+
return `${asks}:${fresh}`
|
|
50
|
+
})
|
|
51
|
+
const [asks, fresh] = k.split(':').map(Number)
|
|
52
|
+
return { asks, fresh }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The row's tone class: blue for new, orange for a question (answered or not). */
|
|
56
|
+
export const toneOf = (m: FrameMark): string => (!m ? '' : m.kind === 'new' ? ' mk-new' : ' mk-ask')
|
|
57
|
+
|
|
58
|
+
export const Bubble = ({ n, hollow }: { n: number; hollow?: boolean }) => (
|
|
59
|
+
<i className={`mk-bubble${hollow ? ' hollow' : ''}`} data-mark={hollow ? 'answered' : 'ask'}
|
|
60
|
+
aria-label={hollow ? `${n} answered, waiting on the agent` : `${n} waiting on you`}>{n}</i>
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
/** A frame row's slot: the bubble, or the blue dot. */
|
|
64
|
+
export function FrameSlot({ m }: { m: FrameMark }) {
|
|
65
|
+
if (!m) return null
|
|
66
|
+
if (m.kind === 'new') return <i className="mk-slot"><i className="mk-dot" data-mark="new" aria-label="new" /></i>
|
|
67
|
+
return <i className="mk-slot"><Bubble n={m.n} hollow={m.kind === 'answered'} /></i>
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A sidebar frame row that wears its frame's mark: the tone on the row, the slot at its end. */
|
|
71
|
+
export function MarkedRow({ frame, className, children, ...rest }: { frame: string; className: string; children: ReactNode } & HTMLAttributes<HTMLDivElement>) {
|
|
72
|
+
const m = useFrameMark(frame)
|
|
73
|
+
return <div className={className + toneOf(m)} {...rest}>{children}<FrameSlot m={m} /></div>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Looking at a frame counts as seeing it (spec 25): any part of it in the window for two seconds,
|
|
77
|
+
* at a readable zoom (scale 0.5 or more) - for the revision its document shows (spec 26): a frame
|
|
78
|
+
* still loading, stale, or showing an older revision than its last edit is not showing that edit, and
|
|
79
|
+
* the clock starts again when a new revision is up. In focus or play the stage counts the same way,
|
|
80
|
+
* once an Update it holds is applied. Polls once a second, and only frames that are new. */
|
|
81
|
+
export function useSeenOnScreen() {
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (PUBLISHED) return
|
|
84
|
+
const since = new Map<string, number>() // "where@changed:shown" -> when it came into view
|
|
85
|
+
const tick = () => {
|
|
86
|
+
const s = useStore.getState(), m = s.marks
|
|
87
|
+
const now = Date.now()
|
|
88
|
+
const shown = new Map<string, string>() // clock key -> node key (or 'stage'); a newer change or document restarts the clock
|
|
89
|
+
if (m && !document.hidden && s.play) {
|
|
90
|
+
const st = s.stageShown, f = st?.at
|
|
91
|
+
if (st && f && !s.playUpdateRevision && isNew(m, f)) {
|
|
92
|
+
const [e, r] = st.shown.split(':')
|
|
93
|
+
if (e === m.epoch && Number(r) >= (m.doc[f] ?? 0)) shown.set(`play:${f}@${m.changed[f] ?? 0}:${st.shown}`, 'stage')
|
|
94
|
+
}
|
|
95
|
+
} else if (m && !document.hidden && s.scale >= 0.5) {
|
|
96
|
+
// in view: some of it inside the window and not all of that under the open sidebar
|
|
97
|
+
const P = document.querySelector('.sh-panel:not(.closed)')?.getBoundingClientRect()
|
|
98
|
+
const W = window.innerWidth, H = window.innerHeight
|
|
99
|
+
for (const n of s.nodes) {
|
|
100
|
+
if (n.status !== 'ready' || n.stale || !isNew(m, n.frame) || shownRev(n, m) < (m.doc[n.frame] ?? 0)) continue
|
|
101
|
+
const r = document.querySelector<HTMLElement>(`.sh-node[data-node="${CSS.escape(n.key)}"]`)?.getBoundingClientRect()
|
|
102
|
+
if (!r) continue
|
|
103
|
+
const x0 = Math.max(r.left, 0), x1 = Math.min(r.right, W), y0 = Math.max(r.top, 0), y1 = Math.min(r.bottom, H)
|
|
104
|
+
if (x0 >= x1 || y0 >= y1) continue
|
|
105
|
+
if (P && x0 >= P.left && x1 <= P.right && y0 >= P.top && y1 <= P.bottom) continue
|
|
106
|
+
shown.set(`${n.key}@${m.changed[n.frame] ?? 0}:${n.shown}`, n.key)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const k of [...since.keys()]) if (!shown.has(k)) since.delete(k)
|
|
110
|
+
const due: string[] = []
|
|
111
|
+
for (const [k, where] of shown) { const t = since.get(k) ?? now; since.set(k, t); if (now - t >= 2000) due.push(where) }
|
|
112
|
+
if (due.length) s.look(due)
|
|
113
|
+
}
|
|
114
|
+
const id = setInterval(tick, 1000)
|
|
115
|
+
return () => clearInterval(id)
|
|
116
|
+
}, [])
|
|
117
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where comment markers sit (spec 26, Part 6): no two overlap, and they stay put.
|
|
3
|
+
*
|
|
4
|
+
* Each thread has a fixed attach point (its element's first line end, or where a person clicked);
|
|
5
|
+
* the marker is placed near it. Placement uses ONE marker size in screen space - the face (avatars,
|
|
6
|
+
* a count) draws inside it - so a reply or a new participant never moves anything. One pass in
|
|
7
|
+
* thread creation order moves a marker that would touch an earlier one down by its height plus
|
|
8
|
+
* 6 px; a moved marker keeps a thin line to its point. Threads with no point - legacy frame-level
|
|
9
|
+
* pins, orphans whose element is gone - line up in a column down from the frame's top-right corner.
|
|
10
|
+
*
|
|
11
|
+
* Pure: the canvas (node px, `inv` = world px per screen px) and the stage (screen px, inv 1) call
|
|
12
|
+
* the same function, and the tests read it directly.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The marker's box in screen px (CSS `.cm-pin` keeps its face inside it) and the gap between two. */
|
|
16
|
+
export const MARKER = { w: 80, h: 34, gap: 6 }
|
|
17
|
+
|
|
18
|
+
/** A placed marker: its tail (bottom-left, where `.cm-pin` hangs from) and, when it was moved off
|
|
19
|
+
* its point, the point the leader line runs up to. */
|
|
20
|
+
export interface Placed { x: number; y: number; lead?: { x: number; y: number }; column: boolean }
|
|
21
|
+
|
|
22
|
+
export function placeMarkers(items: readonly { id: string; point: { x: number; y: number } | null }[], frameW: number, inv: number): Map<string, Placed> {
|
|
23
|
+
const w = MARKER.w * inv, h = MARKER.h * inv, gap = MARKER.gap * inv, tail = 2 * inv
|
|
24
|
+
const boxes: { l: number; r: number; t: number; b: number }[] = []
|
|
25
|
+
const out = new Map<string, Placed>()
|
|
26
|
+
let slot = 0
|
|
27
|
+
for (const it of items) {
|
|
28
|
+
// a column slot hangs its box from the frame's top-right corner, 8 px in
|
|
29
|
+
const x = it.point ? it.point.x : frameW - 8 * inv - w + tail
|
|
30
|
+
let y = it.point ? it.point.y : 8 * inv + h + slot++ * (h + gap)
|
|
31
|
+
const touches = () => boxes.some((o) => x - tail < o.r + gap && o.l < x - tail + w + gap && y - h < o.b + gap && o.t < y + gap)
|
|
32
|
+
for (let i = 0; i < 500 && touches(); i++) y += h + gap
|
|
33
|
+
boxes.push({ l: x - tail, r: x - tail + w, t: y - h, b: y })
|
|
34
|
+
out.set(it.id, { x, y, column: !it.point, ...(it.point && y !== it.point.y ? { lead: it.point } : {}) })
|
|
35
|
+
}
|
|
36
|
+
return out
|
|
37
|
+
}
|