@sixb/app 0.2.4 → 0.2.5
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/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/ctm.png +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +3 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +3 -1
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +1 -1
- package/dist/agent/components/composer-settings.d.ts.map +1 -1
- package/dist/agent/components/composer.d.ts +22 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-meter.d.ts +1 -1
- package/dist/agent/components/context-meter.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +5 -2
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts +20 -0
- package/dist/agent/components/pending-messages.d.ts.map +1 -0
- package/dist/agent/components/sandbox-recovery.d.ts +11 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +1 -1
- package/dist/agent/components/threads-button.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +3 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +5 -0
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +10 -4
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +68 -0
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +114 -0
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/inbox-handoff.d.ts +10 -0
- package/dist/agent/inbox-handoff.d.ts.map +1 -0
- package/dist/agent/live-run.d.ts +8 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/search/interpret.d.ts +101 -0
- package/dist/agent/search/interpret.d.ts.map +1 -0
- package/dist/agent/search/search-tool-view.d.ts +10 -0
- package/dist/agent/search/search-tool-view.d.ts.map +1 -0
- package/dist/agent/thread-state.d.ts +26 -0
- package/dist/agent/thread-state.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/tool-views/registry.d.ts +5 -6
- package/dist/agent/tool-views/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/editor/block-handle.d.ts +20 -0
- package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
- package/dist/artifacts/editor/blocks.d.ts +34 -0
- package/dist/artifacts/editor/blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/callout-view.d.ts +7 -0
- package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
- package/dist/artifacts/editor/document-editor.d.ts +30 -0
- package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
- package/dist/artifacts/editor/figure-view.d.ts +12 -0
- package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
- package/dist/artifacts/editor/find-blocks.d.ts +6 -0
- package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/markdown-document.d.ts +12 -0
- package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
- package/dist/artifacts/editor/messages.d.ts +4 -0
- package/dist/artifacts/editor/messages.d.ts.map +1 -0
- package/dist/artifacts/editor/schema.d.ts +21 -0
- package/dist/artifacts/editor/schema.d.ts.map +1 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
- package/dist/artifacts/editor/slash-menu.d.ts +43 -0
- package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
- package/dist/artifacts/editor/upload.d.ts +12 -0
- package/dist/artifacts/editor/upload.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +5 -0
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
- package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/commands.d.ts +93 -0
- package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/entry.d.ts +2 -0
- package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/frame.d.ts +5 -0
- package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/keys.d.ts +8 -0
- package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
- package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/schema.d.ts +34 -0
- package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/style.d.ts +2 -0
- package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +2 -2
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/live/boards.d.ts +2 -0
- package/dist/artifacts/live/boards.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +32 -0
- package/dist/artifacts/live/document.d.ts.map +1 -0
- package/dist/artifacts/live/header.d.ts +4 -4
- package/dist/artifacts/live/header.d.ts.map +1 -1
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts +2 -0
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/live/view.d.ts +4 -3
- package/dist/artifacts/live/view.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +226 -2
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/pdf.d.ts +8 -0
- package/dist/artifacts/pdf.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +80 -0
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts +3 -3
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
- package/dist/artifacts/renderers/designed-document.d.ts +28 -0
- package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +2 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
- package/dist/artifacts/renderers/document.d.ts +9 -1
- package/dist/artifacts/renderers/document.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts +145 -0
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/page-editor.d.ts +16 -0
- package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/page.d.ts +10 -1
- package/dist/artifacts/renderers/page.d.ts.map +1 -1
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/{chunk-kymx9y5e.js → chunk-4fex83k2.js} +10874 -4690
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-yrcm1pbg.js → chunk-4wm09prf.js} +491 -2128
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-pxd07kvx.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-970s5nkn.js → chunk-69qgh20f.js} +1 -1
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +5 -5
- package/dist/pages/console/data/messages.d.ts +6 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages.js +12 -5
- package/dist/pages.js.map +6 -6
- package/dist/shell/search-command.d.ts.map +1 -1
- package/package.json +22 -5
- package/src/agent/activity-label.ts +3 -0
- package/src/agent/agent-chat.tsx +56 -37
- package/src/agent/agent-execution-trace.tsx +2 -2
- package/src/agent/agent-panel.tsx +6 -4
- package/src/agent/agent.css +254 -0
- package/src/agent/artifact-panel.tsx +77 -22
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +69 -29
- package/src/agent/components/message-parts.tsx +367 -59
- package/src/agent/components/message-view.tsx +12 -2
- package/src/agent/components/pending-messages.tsx +338 -0
- package/src/agent/components/sandbox-recovery.tsx +36 -17
- package/src/agent/components/threads-button.tsx +3 -2
- package/src/agent/components/transcript.tsx +63 -34
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/interpret.ts +31 -7
- package/src/agent/hooks/use-agent-conversation.ts +348 -100
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +87 -11
- package/src/agent/i18n/fr.ts +83 -12
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/search/interpret.ts +367 -0
- package/src/agent/search/search-tool-view.tsx +235 -0
- package/src/agent/thread-state.ts +114 -0
- package/src/agent/tool-views/built-in.tsx +16 -0
- package/src/agent/tool-views/registry.tsx +28 -2
- package/src/agent/types.ts +7 -0
- package/src/agent/view-file/view-file-tool-view.tsx +33 -19
- package/src/artifacts/artifacts.css +398 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/editor/block-handle.tsx +278 -0
- package/src/artifacts/editor/blocks.ts +216 -0
- package/src/artifacts/editor/callout-view.tsx +31 -0
- package/src/artifacts/editor/document-editor.tsx +484 -0
- package/src/artifacts/editor/figure-view.tsx +66 -0
- package/src/artifacts/editor/find-blocks.ts +19 -0
- package/src/artifacts/editor/markdown-document.tsx +72 -0
- package/src/artifacts/editor/messages.ts +4 -0
- package/src/artifacts/editor/schema.ts +159 -0
- package/src/artifacts/editor/selection-toolbar.tsx +364 -0
- package/src/artifacts/editor/slash-menu.tsx +251 -0
- package/src/artifacts/editor/upload.ts +40 -0
- package/src/artifacts/file-source.ts +11 -0
- package/src/artifacts/frame-editor/bundle.ts +8 -0
- package/src/artifacts/frame-editor/commands.ts +565 -0
- package/src/artifacts/frame-editor/entry.ts +6 -0
- package/src/artifacts/frame-editor/frame.ts +847 -0
- package/src/artifacts/frame-editor/generated/editor.txt +149 -0
- package/src/artifacts/frame-editor/generated.d.ts +5 -0
- package/src/artifacts/frame-editor/keys.ts +323 -0
- package/src/artifacts/frame-editor/protocol.ts +151 -0
- package/src/artifacts/frame-editor/schema.ts +293 -0
- package/src/artifacts/frame-editor/style.ts +58 -0
- package/src/artifacts/frame.tsx +11 -3
- package/src/artifacts/live/boards.ts +46 -3
- package/src/artifacts/live/document.ts +89 -0
- package/src/artifacts/live/header.tsx +9 -14
- package/src/artifacts/live/presence.ts +5 -1
- package/src/artifacts/live/session.ts +4 -2
- package/src/artifacts/live/view.ts +14 -8
- package/src/artifacts/messages.ts +138 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
- package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
- package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
- package/src/artifacts/renderers/canvas/comments.ts +8 -4
- package/src/artifacts/renderers/designed-document.tsx +277 -0
- package/src/artifacts/renderers/document-tree.ts +9 -0
- package/src/artifacts/renderers/document.tsx +13 -102
- package/src/artifacts/renderers/live-frame.ts +163 -0
- package/src/artifacts/renderers/page-editor.tsx +613 -0
- package/src/artifacts/renderers/page.tsx +21 -4
- package/src/artifacts/viewer.tsx +87 -41
- package/src/index.ts +6 -0
- package/src/pages/console/data/messages.ts +6 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/shell/search-command.tsx +2 -0
- package/dist/chunk-kymx9y5e.js.map +0 -211
- package/dist/chunk-yrcm1pbg.js.map +0 -34
- /package/dist/{chunk-pxd07kvx.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-970s5nkn.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -18,6 +18,8 @@ import { cn } from "@sixb/ui/lib/utils"
|
|
|
18
18
|
import {
|
|
19
19
|
Check,
|
|
20
20
|
CornerDownRight,
|
|
21
|
+
Eye,
|
|
22
|
+
Lock,
|
|
21
23
|
MessageSquare,
|
|
22
24
|
MessageSquarePlus,
|
|
23
25
|
MoreHorizontal,
|
|
@@ -34,6 +36,7 @@ import {
|
|
|
34
36
|
useRef,
|
|
35
37
|
useState,
|
|
36
38
|
} from "react"
|
|
39
|
+
import { useSharedGuest } from "../../../shared-session"
|
|
37
40
|
import { GuestBadge } from "../../guest-badge"
|
|
38
41
|
import { useArtifactMessages } from "../../messages"
|
|
39
42
|
import { PersonAvatar } from "../../person-avatar"
|
|
@@ -49,6 +52,10 @@ import {
|
|
|
49
52
|
// who wrote it and its replies, resolved, reopened, replied to or deleted in place. The reader
|
|
50
53
|
// picks some to send to the Agent, which puts them, quoted with where they are, in the message
|
|
51
54
|
// they are writing. Beside the canvas while it is wide, a sheet over its foot on a phone.
|
|
55
|
+
//
|
|
56
|
+
// A member is told who reads what: a reply in a guest's thread reaches the guest, and once guests
|
|
57
|
+
// comment on the canvas, the team's own threads are marked internal. A guest reads only their
|
|
58
|
+
// link's threads, as the API lists them, and is told nothing of the others.
|
|
52
59
|
|
|
53
60
|
export type CommentFilter = "open" | "resolved"
|
|
54
61
|
|
|
@@ -102,6 +109,11 @@ export function CommentsPanel({
|
|
|
102
109
|
const [sent, setSent] = useState(false)
|
|
103
110
|
const [failure, setFailure] = useState<string | null>(null)
|
|
104
111
|
|
|
112
|
+
// Guests reach the canvas once one has commented: the team's own threads then say so. A guest
|
|
113
|
+
// is listed no thread of the team's.
|
|
114
|
+
const member = useSharedGuest() === null
|
|
115
|
+
const guestsHere = threads.some((thread) => thread.comment.author.type === "guest")
|
|
116
|
+
|
|
105
117
|
// What is chosen stays among the threads shown.
|
|
106
118
|
useEffect(() => {
|
|
107
119
|
setChosen((current) => {
|
|
@@ -254,6 +266,12 @@ export function CommentsPanel({
|
|
|
254
266
|
choosing={choosing}
|
|
255
267
|
chosen={chosen.has(thread.comment.id)}
|
|
256
268
|
nameOf={nameOf}
|
|
269
|
+
guest={
|
|
270
|
+
member && thread.comment.author.type === "guest"
|
|
271
|
+
? (nameOf(thread.comment)?.name ?? messages.guest)
|
|
272
|
+
: null
|
|
273
|
+
}
|
|
274
|
+
internal={guestsHere && thread.comment.author.type !== "guest"}
|
|
257
275
|
manages={canManage(thread.comment)}
|
|
258
276
|
onChoose={(next) =>
|
|
259
277
|
setChosen((current) => {
|
|
@@ -315,6 +333,8 @@ function ThreadCard({
|
|
|
315
333
|
choosing,
|
|
316
334
|
chosen,
|
|
317
335
|
nameOf,
|
|
336
|
+
guest,
|
|
337
|
+
internal,
|
|
318
338
|
manages,
|
|
319
339
|
onChoose,
|
|
320
340
|
onActivate,
|
|
@@ -328,6 +348,10 @@ function ThreadCard({
|
|
|
328
348
|
readonly choosing: boolean
|
|
329
349
|
readonly chosen: boolean
|
|
330
350
|
readonly nameOf: (comment: ArtifactComment) => CommentAuthor | null
|
|
351
|
+
/** The guest who started the thread, who reads its replies, as a member is told. */
|
|
352
|
+
readonly guest: string | null
|
|
353
|
+
/** The team's own thread, on a canvas guests comment on. */
|
|
354
|
+
readonly internal: boolean
|
|
331
355
|
readonly manages: boolean
|
|
332
356
|
readonly onChoose: (chosen: boolean) => void
|
|
333
357
|
readonly onActivate: () => void
|
|
@@ -419,7 +443,11 @@ function ThreadCard({
|
|
|
419
443
|
) : null}
|
|
420
444
|
</div>
|
|
421
445
|
|
|
422
|
-
<Message
|
|
446
|
+
<Message
|
|
447
|
+
comment={comment}
|
|
448
|
+
nameOf={nameOf}
|
|
449
|
+
{...(internal ? { badge: <InternalBadge /> } : {})}
|
|
450
|
+
/>
|
|
423
451
|
{replies.map((reply) => (
|
|
424
452
|
<div key={reply.id} className="mt-2.5 border-l-2 border-border/70 pl-2.5">
|
|
425
453
|
<Message comment={reply} nameOf={nameOf} />
|
|
@@ -431,6 +459,17 @@ function ThreadCard({
|
|
|
431
459
|
compact
|
|
432
460
|
autoFocus={replying}
|
|
433
461
|
placeholder={messages.replyPlaceholder}
|
|
462
|
+
notice={
|
|
463
|
+
guest ? (
|
|
464
|
+
<p
|
|
465
|
+
title={messages.guestSeesHint}
|
|
466
|
+
className="m-0 flex items-center gap-1 text-[11px] leading-4 text-muted-foreground [&_svg]:size-3 [&_svg]:shrink-0"
|
|
467
|
+
>
|
|
468
|
+
<Eye aria-hidden="true" />
|
|
469
|
+
<span className="min-w-0 truncate">{messages.guestSees(guest)}</span>
|
|
470
|
+
</p>
|
|
471
|
+
) : undefined
|
|
472
|
+
}
|
|
434
473
|
onSubmit={async (body) => {
|
|
435
474
|
await onReply(body)
|
|
436
475
|
setReplying(false)
|
|
@@ -469,6 +508,20 @@ function ThreadCard({
|
|
|
469
508
|
)
|
|
470
509
|
}
|
|
471
510
|
|
|
511
|
+
/** Beside a thread only the team reads, on a canvas guests comment on. */
|
|
512
|
+
function InternalBadge() {
|
|
513
|
+
const messages = useArtifactMessages().canvas.comments
|
|
514
|
+
return (
|
|
515
|
+
<span
|
|
516
|
+
title={messages.internalHint}
|
|
517
|
+
className="inline-flex h-4 shrink-0 items-center gap-0.5 rounded-full px-1.5 text-[10.5px] leading-none font-medium tracking-[0.01em] text-muted-foreground ring-1 ring-border/70 ring-inset [&_svg]:size-2.5"
|
|
518
|
+
>
|
|
519
|
+
<Lock aria-hidden="true" />
|
|
520
|
+
{messages.internal}
|
|
521
|
+
</span>
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
|
|
472
525
|
/** Where a thread is: its board, and its element by its first words, or that it is gone. */
|
|
473
526
|
function Where({ place }: { readonly place: ThreadPlace }) {
|
|
474
527
|
const messages = useArtifactMessages().canvas.comments
|
|
@@ -497,9 +550,12 @@ function Where({ place }: { readonly place: ThreadPlace }) {
|
|
|
497
550
|
function Message({
|
|
498
551
|
comment,
|
|
499
552
|
nameOf,
|
|
553
|
+
badge,
|
|
500
554
|
}: {
|
|
501
555
|
readonly comment: ArtifactComment
|
|
502
556
|
readonly nameOf: (comment: ArtifactComment) => CommentAuthor | null
|
|
557
|
+
/** At the end of its author's line: what the thread is, such as internal. */
|
|
558
|
+
readonly badge?: ReactNode
|
|
503
559
|
}) {
|
|
504
560
|
const messages = useArtifactMessages().canvas.comments
|
|
505
561
|
const when = useWhen()
|
|
@@ -520,6 +576,7 @@ function Message({
|
|
|
520
576
|
<time dateTime={comment.createdAt} className="shrink-0 text-muted-foreground">
|
|
521
577
|
{when(comment.createdAt)}
|
|
522
578
|
</time>
|
|
579
|
+
{badge ? <span className="ml-auto flex shrink-0 pl-1">{badge}</span> : null}
|
|
523
580
|
</div>
|
|
524
581
|
<p className="m-0 mt-1 text-sm leading-5 break-words whitespace-pre-wrap text-foreground">
|
|
525
582
|
{comment.body}
|
|
@@ -199,14 +199,17 @@ export interface CommentAuthor {
|
|
|
199
199
|
/**
|
|
200
200
|
* Who wrote a comment: the reader themselves, else the name the API gives its author, and the
|
|
201
201
|
* Agent for them when its run wrote it. A shared link's guest is marked as one, for everyone, and
|
|
202
|
-
* is "you" to themselves.
|
|
202
|
+
* is "you" to themselves. A guest never learns a member's email: one without a profile name is a
|
|
203
|
+
* team member to them, as on the canvas's presence. Null for an author the project cannot name.
|
|
203
204
|
*/
|
|
204
205
|
export function useCommentAuthors(): (
|
|
205
206
|
comment: Pick<ArtifactComment, "author" | "authorName" | "origin">
|
|
206
207
|
) => CommentAuthor | null {
|
|
207
208
|
const user = useCurrentUser()
|
|
208
209
|
const guest = useSharedGuest()
|
|
209
|
-
const
|
|
210
|
+
const all = useArtifactMessages()
|
|
211
|
+
const messages = all.canvas.comments
|
|
212
|
+
const unnamed = guest ? all.live.teamMember : null
|
|
210
213
|
|
|
211
214
|
return ({ author, authorName, origin }) => {
|
|
212
215
|
if (author.type === "guest") {
|
|
@@ -216,10 +219,11 @@ export function useCommentAuthors(): (
|
|
|
216
219
|
|
|
217
220
|
const own = author.type === "user" && author.id === user?.id
|
|
218
221
|
if (origin) {
|
|
219
|
-
const name = own ? messages.you.toLowerCase() : (authorName ?? messages.someone)
|
|
222
|
+
const name = own ? messages.you.toLowerCase() : (authorName ?? unnamed ?? messages.someone)
|
|
220
223
|
return { name: messages.agentFor(name), you: false, agent: true }
|
|
221
224
|
}
|
|
222
225
|
if (own) return { name: user.displayName ?? user.email ?? authorName ?? "", you: true }
|
|
223
|
-
|
|
226
|
+
const name = authorName ?? unnamed
|
|
227
|
+
return name ? { name, you: false } : null
|
|
224
228
|
}
|
|
225
229
|
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type { FrameEditTarget, FrameEmbed, FrameEvent } from "@sixb/core/artifacts"
|
|
2
|
+
import { mergeBoardText } from "@sixb/core/artifacts/live"
|
|
3
|
+
import { isMobileViewport, useIsMobile } from "@sixb/ui/hooks"
|
|
4
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
5
|
+
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react"
|
|
6
|
+
import { useArtifactEditing } from "../edit-session"
|
|
7
|
+
import { ArtifactFrame, type ArtifactFrameHandle } from "../frame"
|
|
8
|
+
import { FrameEmbeds } from "../frame-embeds"
|
|
9
|
+
import { useLiveBoardSource, useLivePageHeld } from "../live/boards"
|
|
10
|
+
import { liveDocumentOf } from "../live/document"
|
|
11
|
+
import { useLiveArtifactState, useViewerLiveArtifact } from "../live/hooks"
|
|
12
|
+
import type { LiveArtifact } from "../live/session"
|
|
13
|
+
import { useArtifactMessages } from "../messages"
|
|
14
|
+
import { type ArtifactVersion, useFileText, versionFileSource } from "../queries"
|
|
15
|
+
import { useArtifactThemeAttributes } from "../theme"
|
|
16
|
+
import { useFrameEditing, useLiveFrame } from "./live-frame"
|
|
17
|
+
import { ViewerLoading, ViewerNotice } from "./notice"
|
|
18
|
+
import { FrameScreen, usePageEvents } from "./page"
|
|
19
|
+
import { PageEditor } from "./page-editor"
|
|
20
|
+
|
|
21
|
+
/** How wide a designed document draws without paper: a Letter sheet's width. */
|
|
22
|
+
const SHEET_WIDTH = 816
|
|
23
|
+
|
|
24
|
+
/** Whether a version is a designed document, `document.html` with its own stylesheets. */
|
|
25
|
+
export function isDesignedDocument(version: Pick<ArtifactVersion, "outline">): boolean {
|
|
26
|
+
return version.outline.kind === "document" && version.outline.format === "html"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A designed document: its `document.html` in a sandboxed frame, styled by its own stylesheets.
|
|
31
|
+
* With paper, it shows as the pages it prints on. A phone shows those too small to read, so there
|
|
32
|
+
* it is one sheet whose text wraps to the screen, with a gap where each page breaks. The view
|
|
33
|
+
* follows the window across that width; there is nothing to choose. The artifacts it embeds are
|
|
34
|
+
* drawn over it where it puts them.
|
|
35
|
+
*
|
|
36
|
+
* Held live and edited, it is one sheet the reader edits in place, for everyone at once: as a page
|
|
37
|
+
* of notes, block by block, when the live document holds it as blocks (./page-editor.tsx); else
|
|
38
|
+
* its words, element by element. Once they are done, it stays that sheet until the stored version
|
|
39
|
+
* holds their changes, then shows its pages again.
|
|
40
|
+
*/
|
|
41
|
+
export function DesignedDocumentRenderer({
|
|
42
|
+
version,
|
|
43
|
+
part,
|
|
44
|
+
}: {
|
|
45
|
+
readonly version: ArtifactVersion
|
|
46
|
+
/** The section to open at, by its slug. */
|
|
47
|
+
readonly part?: string
|
|
48
|
+
}) {
|
|
49
|
+
const live = useViewerLiveArtifact()
|
|
50
|
+
const state = useLiveArtifactState(live)
|
|
51
|
+
const editing = useArtifactEditing()
|
|
52
|
+
const held = live && state.synced && !state.left ? live : null
|
|
53
|
+
const typing = editing && state.access === "edit" ? held : null
|
|
54
|
+
const settling = useSettling(version, held, typing !== null)
|
|
55
|
+
// A page held as blocks is edited with the editor in its frame; one held as text, as a board is.
|
|
56
|
+
const blocks = useLivePageHeld(held, version.entry)
|
|
57
|
+
const shown = typing ?? settling
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<DocumentStage version={version}>
|
|
61
|
+
{shown && blocks ? (
|
|
62
|
+
<PageEditor version={version} live={shown} editable={typing !== null} />
|
|
63
|
+
) : typing ? (
|
|
64
|
+
<DocumentEditor version={version} live={typing} typing />
|
|
65
|
+
) : settling ? (
|
|
66
|
+
<DocumentEditor version={version} live={settling} typing={false} />
|
|
67
|
+
) : (
|
|
68
|
+
<DocumentReader version={version} {...(part ? { part } : {})} />
|
|
69
|
+
)}
|
|
70
|
+
</DocumentStage>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The artifact's theme around whichever frame shows the document. */
|
|
75
|
+
function DocumentStage({
|
|
76
|
+
version,
|
|
77
|
+
children,
|
|
78
|
+
}: {
|
|
79
|
+
readonly version: ArtifactVersion
|
|
80
|
+
readonly children: ReactNode
|
|
81
|
+
}) {
|
|
82
|
+
const theme = useArtifactThemeAttributes(version)
|
|
83
|
+
return (
|
|
84
|
+
<div
|
|
85
|
+
data-sixb-artifact=""
|
|
86
|
+
className={cn("flex min-h-0 flex-1 flex-col bg-background", theme.className)}
|
|
87
|
+
style={theme.style}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</div>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The live artifact while the stored version does not yet hold what the reader typed, from the
|
|
96
|
+
* moment they stop editing; null otherwise. Their words are written back a moment after they
|
|
97
|
+
* stop, and the version that holds them arrives after that.
|
|
98
|
+
*/
|
|
99
|
+
function useSettling(
|
|
100
|
+
version: ArtifactVersion,
|
|
101
|
+
live: LiveArtifact | null,
|
|
102
|
+
typing: boolean
|
|
103
|
+
): LiveArtifact | null {
|
|
104
|
+
const [settling, setSettling] = useState(false)
|
|
105
|
+
// Set as the render that ends typing is made, so the pages never show in between.
|
|
106
|
+
const [typed, setTyped] = useState(typing)
|
|
107
|
+
if (typed !== typing) {
|
|
108
|
+
setTyped(typing)
|
|
109
|
+
setSettling(!typing)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const following = settling ? live : null
|
|
113
|
+
const source = useLiveBoardSource(following, version.entry)
|
|
114
|
+
const stored = useFileText(following ? versionFileSource(version, version.entry) : null).text
|
|
115
|
+
const caughtUp = source === null || (stored !== undefined && stored === source)
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (settling && caughtUp) setSettling(false)
|
|
118
|
+
}, [settling, caughtUp])
|
|
119
|
+
|
|
120
|
+
return following && !caughtUp ? following : null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The document as a reader opens it: its pages, or one sheet on a phone. */
|
|
124
|
+
function DocumentReader({
|
|
125
|
+
version,
|
|
126
|
+
part,
|
|
127
|
+
}: {
|
|
128
|
+
readonly version: ArtifactVersion
|
|
129
|
+
readonly part?: string
|
|
130
|
+
}) {
|
|
131
|
+
const messages = useArtifactMessages()
|
|
132
|
+
const frame = useRef<ArtifactFrameHandle | null>(null)
|
|
133
|
+
// The hook answers false until its effect runs, so the first render reads the width itself.
|
|
134
|
+
const phone = useIsMobile() || isMobileViewport()
|
|
135
|
+
const pages = version.outline.kind === "document" && !!version.outline.paper && !phone
|
|
136
|
+
const [embeds, setEmbeds] = useState<readonly FrameEmbed[]>([])
|
|
137
|
+
// The embeds a view reported are placed for its layout, not the next one's.
|
|
138
|
+
const [laidOut, setLaidOut] = useState(pages)
|
|
139
|
+
if (laidOut !== pages) {
|
|
140
|
+
setLaidOut(pages)
|
|
141
|
+
setEmbeds([])
|
|
142
|
+
}
|
|
143
|
+
const onEvent = usePageEvents(version, { onEmbeds: setEmbeds })
|
|
144
|
+
const scroll = useCallback((delta: { readonly x: number; readonly y: number }) => {
|
|
145
|
+
frame.current?.send("scroll", delta).catch(() => {})
|
|
146
|
+
}, [])
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<ArtifactFrame
|
|
150
|
+
handle={frame}
|
|
151
|
+
version={version}
|
|
152
|
+
title={messages.document.frame(version.title)}
|
|
153
|
+
start={{ pages, ...(part ? { section: part } : {}) }}
|
|
154
|
+
onEvent={onEvent}
|
|
155
|
+
className="flex-1"
|
|
156
|
+
fallback={<ViewerLoading label={messages.viewer.loading} />}
|
|
157
|
+
failure={<ViewerNotice title={messages.document.loadFailed} />}
|
|
158
|
+
overlay={<FrameEmbeds version={version} embeds={embeds} onScroll={scroll} />}
|
|
159
|
+
/>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The document as one sheet that follows its live document, element by element, as
|
|
165
|
+
* ../live-frame.ts describes. Typing, a click on a text element puts the caret in it, and what
|
|
166
|
+
* the reader types is written into `document.html` for everyone, under their own undo.
|
|
167
|
+
*/
|
|
168
|
+
function DocumentEditor({
|
|
169
|
+
version,
|
|
170
|
+
live,
|
|
171
|
+
typing,
|
|
172
|
+
}: {
|
|
173
|
+
readonly version: ArtifactVersion
|
|
174
|
+
readonly live: LiveArtifact
|
|
175
|
+
readonly typing: boolean
|
|
176
|
+
}) {
|
|
177
|
+
const messages = useArtifactMessages()
|
|
178
|
+
const file = version.entry
|
|
179
|
+
const editor = liveDocumentOf(live)
|
|
180
|
+
const frame = useLiveFrame({ version, file, live })
|
|
181
|
+
const [embeds, setEmbeds] = useState<readonly FrameEmbed[]>([])
|
|
182
|
+
const pageEvents = usePageEvents(frame.shows, { onEmbeds: setEmbeds })
|
|
183
|
+
const [selected, setSelected] = useState<FrameEditTarget | null>(null)
|
|
184
|
+
// The element picked, as the event handler reads it: what the frame says the reader typed is
|
|
185
|
+
// taken only for it, and nothing while the frame's elements are not the document's.
|
|
186
|
+
const picked = useRef<FrameEditTarget | null>(null)
|
|
187
|
+
picked.current = typing ? selected : null
|
|
188
|
+
const moved = useRef(frame.moved)
|
|
189
|
+
moved.current = frame.moved
|
|
190
|
+
|
|
191
|
+
// While the reader types in it, the frame keeps the version it loaded.
|
|
192
|
+
const { hold } = frame
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
hold(typing && selected?.kind === "text")
|
|
195
|
+
}, [hold, typing, selected])
|
|
196
|
+
|
|
197
|
+
// Once the frame's elements no longer match the document's, nothing stays picked: its address
|
|
198
|
+
// may name another element now.
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
if (!typing || frame.moved) {
|
|
201
|
+
picked.current = null
|
|
202
|
+
setSelected(null)
|
|
203
|
+
}
|
|
204
|
+
}, [typing, frame.moved])
|
|
205
|
+
|
|
206
|
+
const onEdit = (event: FrameEvent) => {
|
|
207
|
+
if (moved.current || !typing) return
|
|
208
|
+
if (event.event === "edit.select") {
|
|
209
|
+
// Typing in another element is a step of its own for undo.
|
|
210
|
+
editor.stopCapturing()
|
|
211
|
+
picked.current = event.params.target
|
|
212
|
+
setSelected(event.params.target)
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
if (event.event !== "edit.text") return
|
|
216
|
+
|
|
217
|
+
// Only the words of the element the reader picked, a text, are taken.
|
|
218
|
+
const chosen = picked.current
|
|
219
|
+
const { address, base, text } = event.params
|
|
220
|
+
if (chosen?.kind !== "text" || chosen.address !== address) return
|
|
221
|
+
try {
|
|
222
|
+
editor.editFile(file, (source) => mergeBoardText(source, address, base, text))
|
|
223
|
+
} catch {
|
|
224
|
+
// The element is no longer text there: the document changed under the reader.
|
|
225
|
+
picked.current = null
|
|
226
|
+
setSelected(null)
|
|
227
|
+
frame.resync()
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
useFrameEditing({ frame, on: typing, typing, onEdit })
|
|
231
|
+
|
|
232
|
+
const onEvent = useCallback(
|
|
233
|
+
(event: FrameEvent) => {
|
|
234
|
+
if (event.event === "ready") {
|
|
235
|
+
picked.current = null
|
|
236
|
+
setSelected(null)
|
|
237
|
+
frame.ready()
|
|
238
|
+
}
|
|
239
|
+
pageEvents(event)
|
|
240
|
+
},
|
|
241
|
+
[frame, pageEvents]
|
|
242
|
+
)
|
|
243
|
+
const scroll = useCallback(
|
|
244
|
+
(delta: { readonly x: number; readonly y: number }) => {
|
|
245
|
+
frame.handle.current?.send("scroll", delta).catch(() => {})
|
|
246
|
+
},
|
|
247
|
+
[frame.handle]
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<ArtifactFrame
|
|
252
|
+
handle={frame.handle}
|
|
253
|
+
version={frame.shows}
|
|
254
|
+
title={messages.document.frame(version.title)}
|
|
255
|
+
editable
|
|
256
|
+
onEvent={onEvent}
|
|
257
|
+
className="flex-1"
|
|
258
|
+
fallback={<ViewerLoading label={messages.viewer.loading} />}
|
|
259
|
+
failure={<ViewerNotice title={messages.document.loadFailed} />}
|
|
260
|
+
overlay={<FrameEmbeds version={frame.shows} embeds={embeds} onScroll={scroll} />}
|
|
261
|
+
/>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A designed document's first page, live and scaled down to its card: as a sheet of its paper
|
|
267
|
+
* when it has one, else the top of its one sheet.
|
|
268
|
+
*/
|
|
269
|
+
export function DesignedDocumentScreen({ version }: { readonly version: ArtifactVersion }) {
|
|
270
|
+
const paper = version.outline.kind === "document" ? version.outline.paper : undefined
|
|
271
|
+
// The stage's padding on either side of the sheet, as the kit lays pages out.
|
|
272
|
+
return paper ? (
|
|
273
|
+
<FrameScreen version={version} width={paper.width + 32} start={{ pages: true }} />
|
|
274
|
+
) : (
|
|
275
|
+
<FrameScreen version={version} width={SHEET_WIDTH + 64} />
|
|
276
|
+
)
|
|
277
|
+
}
|
|
@@ -34,6 +34,15 @@ export function rehypeArtifactDocument() {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** Turns `> [!NOTE]` (and TIP, IMPORTANT, WARNING, CAUTION) quotes into callout asides. */
|
|
38
|
+
export function rehypeCallouts() {
|
|
39
|
+
return (tree: TreeRoot) => {
|
|
40
|
+
visitElements(tree, (element) => {
|
|
41
|
+
if (element.tagName === "blockquote") shapeCallout(element)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
function markTitleAndLede(tree: TreeRoot): void {
|
|
38
47
|
const elements = tree.children.filter(isElement)
|
|
39
48
|
const [first, second] = elements
|
|
@@ -8,15 +8,7 @@ import {
|
|
|
8
8
|
MessageSquareWarning,
|
|
9
9
|
OctagonAlert,
|
|
10
10
|
} from "lucide-react"
|
|
11
|
-
import {
|
|
12
|
-
type ComponentProps,
|
|
13
|
-
type ReactNode,
|
|
14
|
-
useCallback,
|
|
15
|
-
useEffect,
|
|
16
|
-
useMemo,
|
|
17
|
-
useRef,
|
|
18
|
-
useState,
|
|
19
|
-
} from "react"
|
|
11
|
+
import { type ComponentProps, type ReactNode, useCallback, useEffect, useMemo, useRef } from "react"
|
|
20
12
|
import { useCopyFeedback } from "../copy-feedback"
|
|
21
13
|
import { type ArtifactMessages, useArtifactMessages } from "../messages"
|
|
22
14
|
import {
|
|
@@ -40,7 +32,7 @@ const REHYPE_PLUGINS: MarkdownProps["rehypePlugins"] = [
|
|
|
40
32
|
|
|
41
33
|
/**
|
|
42
34
|
* A document as a page to read: its title and lede, a measured column, figures with captions,
|
|
43
|
-
*
|
|
35
|
+
* and callouts. It draws only on theme tokens, so the app's
|
|
44
36
|
* theme, dark mode, and the artifact's own `theme.json` all apply.
|
|
45
37
|
*/
|
|
46
38
|
export function DocumentRenderer({
|
|
@@ -59,14 +51,6 @@ export function DocumentRenderer({
|
|
|
59
51
|
const file = useFileText(source)
|
|
60
52
|
const theme = useArtifactThemeAttributes(version)
|
|
61
53
|
const scrollRef = useRef<HTMLDivElement | null>(null)
|
|
62
|
-
const headings = useMemo(
|
|
63
|
-
() =>
|
|
64
|
-
version.outline.kind === "document"
|
|
65
|
-
? version.outline.headings.filter((heading) => heading.depth === 2 || heading.depth === 3)
|
|
66
|
-
: [],
|
|
67
|
-
[version.outline]
|
|
68
|
-
)
|
|
69
|
-
const activeSlug = useActiveHeading(scrollRef, headings, file.text)
|
|
70
54
|
|
|
71
55
|
const scrollToSection = useCallback((slug: string) => {
|
|
72
56
|
const heading = scrollRef.current?.querySelector(`[id="${CSS.escape(slug)}"]`)
|
|
@@ -104,93 +88,20 @@ export function DocumentRenderer({
|
|
|
104
88
|
)}
|
|
105
89
|
style={theme.style}
|
|
106
90
|
>
|
|
107
|
-
<div className="
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</Markdown>
|
|
117
|
-
</article>
|
|
118
|
-
{headings.length > 1 ? (
|
|
119
|
-
<nav
|
|
120
|
-
aria-label={messages.document.outline}
|
|
121
|
-
className="sticky top-14 hidden w-48 shrink-0 self-start @4xl:block"
|
|
122
|
-
>
|
|
123
|
-
<p className="mb-3 text-xs font-semibold text-muted-foreground">
|
|
124
|
-
{messages.document.outline}
|
|
125
|
-
</p>
|
|
126
|
-
<ol className="flex flex-col gap-2 text-[13px] leading-snug">
|
|
127
|
-
{headings.map((heading) => (
|
|
128
|
-
<li key={heading.slug} className={heading.depth === 3 ? "pl-3" : undefined}>
|
|
129
|
-
<a
|
|
130
|
-
href={`#${heading.slug}`}
|
|
131
|
-
onClick={(event) => {
|
|
132
|
-
event.preventDefault()
|
|
133
|
-
scrollToSection(heading.slug)
|
|
134
|
-
}}
|
|
135
|
-
aria-current={activeSlug === heading.slug ? "location" : undefined}
|
|
136
|
-
className={cn(
|
|
137
|
-
"block transition-colors hover:text-foreground",
|
|
138
|
-
activeSlug === heading.slug
|
|
139
|
-
? "font-medium text-foreground"
|
|
140
|
-
: "text-muted-foreground"
|
|
141
|
-
)}
|
|
142
|
-
>
|
|
143
|
-
{heading.text}
|
|
144
|
-
</a>
|
|
145
|
-
</li>
|
|
146
|
-
))}
|
|
147
|
-
</ol>
|
|
148
|
-
</nav>
|
|
149
|
-
) : null}
|
|
91
|
+
<div className="sixb-document-page">
|
|
92
|
+
<Markdown
|
|
93
|
+
className="sixb-document"
|
|
94
|
+
components={components}
|
|
95
|
+
rehypePlugins={REHYPE_PLUGINS}
|
|
96
|
+
urlTransform={artifactUrlTransform}
|
|
97
|
+
>
|
|
98
|
+
{file.text}
|
|
99
|
+
</Markdown>
|
|
150
100
|
</div>
|
|
151
101
|
</div>
|
|
152
102
|
)
|
|
153
103
|
}
|
|
154
104
|
|
|
155
|
-
/**
|
|
156
|
-
* The section the reader is in: the last heading that has scrolled past the reading line. The
|
|
157
|
-
* document scrolls itself when its host gives it a height, and scrolls with the page when the host
|
|
158
|
-
* lets it grow, so this follows whichever element scrolls.
|
|
159
|
-
*/
|
|
160
|
-
function useActiveHeading(
|
|
161
|
-
scrollRef: { readonly current: HTMLDivElement | null },
|
|
162
|
-
headings: readonly { readonly slug: string }[],
|
|
163
|
-
content: string | undefined
|
|
164
|
-
): string | null {
|
|
165
|
-
const [active, setActive] = useState<string | null>(null)
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
const container = scrollRef.current
|
|
168
|
-
if (!container || content === undefined || headings.length === 0) return
|
|
169
|
-
let frame = 0
|
|
170
|
-
const update = () => {
|
|
171
|
-
frame = 0
|
|
172
|
-
const top = Math.max(container.getBoundingClientRect().top, 0) + 96
|
|
173
|
-
let current: string | null = headings[0]?.slug ?? null
|
|
174
|
-
for (const heading of headings) {
|
|
175
|
-
const element = container.querySelector(`[id="${CSS.escape(heading.slug)}"]`)
|
|
176
|
-
if (element && element.getBoundingClientRect().top <= top) current = heading.slug
|
|
177
|
-
}
|
|
178
|
-
setActive(current)
|
|
179
|
-
}
|
|
180
|
-
const schedule = () => {
|
|
181
|
-
if (!frame) frame = requestAnimationFrame(update)
|
|
182
|
-
}
|
|
183
|
-
update()
|
|
184
|
-
// Scroll events do not bubble; capturing at the document sees every scrolling element.
|
|
185
|
-
document.addEventListener("scroll", schedule, { capture: true, passive: true })
|
|
186
|
-
return () => {
|
|
187
|
-
document.removeEventListener("scroll", schedule, { capture: true })
|
|
188
|
-
if (frame) cancelAnimationFrame(frame)
|
|
189
|
-
}
|
|
190
|
-
}, [scrollRef, headings, content])
|
|
191
|
-
return active
|
|
192
|
-
}
|
|
193
|
-
|
|
194
105
|
export function documentComponents(
|
|
195
106
|
version: ArtifactVersion,
|
|
196
107
|
latestVersion: number,
|
|
@@ -302,7 +213,7 @@ const CALLOUT_ICONS: Record<CalloutKind, typeof Info> = {
|
|
|
302
213
|
caution: OctagonAlert,
|
|
303
214
|
}
|
|
304
215
|
|
|
305
|
-
function Callout({
|
|
216
|
+
export function Callout({
|
|
306
217
|
kind,
|
|
307
218
|
label,
|
|
308
219
|
children,
|
|
@@ -329,6 +240,6 @@ function headingText(version: ArtifactVersion, slug: string): string {
|
|
|
329
240
|
return headings.find((heading) => heading.slug === slug)?.text ?? slug
|
|
330
241
|
}
|
|
331
242
|
|
|
332
|
-
function isCalloutKind(value: unknown): value is CalloutKind {
|
|
243
|
+
export function isCalloutKind(value: unknown): value is CalloutKind {
|
|
333
244
|
return typeof value === "string" && (CALLOUT_KINDS as readonly string[]).includes(value)
|
|
334
245
|
}
|