@lostgradient/cinder 0.14.0 → 0.16.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 +16 -0
- package/README.md +9 -9
- package/components.json +2 -143
- package/dist/components/access-gate/index.js +379 -327
- package/dist/components/alert-dialog/index.js +170 -172
- package/dist/components/confirm-dialog/index.js +170 -172
- package/dist/components/drawer/index.js +11 -11
- package/dist/components/focus-trap/index.d.ts +1 -0
- package/dist/components/focus-trap/index.js +171 -1
- package/dist/components/icons/index.d.ts +80 -1
- package/dist/components/icons/index.js +1256 -0
- package/dist/components/markdown-editor/index.js +170 -170
- package/dist/components/modal/index.js +20 -20
- package/dist/components/review-editor/index.js +170 -187
- package/dist/components/sheet/index.js +11 -11
- package/dist/components/sidebar/index.js +37 -37
- package/dist/index.d.ts +0 -8
- package/dist/index.js +23202 -30164
- package/dist/server/components/access-gate/index.js +7 -10
- package/dist/server/components/alert-dialog/index.js +4 -4
- package/dist/server/components/approval-card/index.js +6 -6
- package/dist/server/components/autocomplete/index.js +4 -4
- package/dist/server/components/choice-grid/index.js +2 -2
- package/dist/server/components/color-field/index.js +2 -2
- package/dist/server/components/combobox/index.js +3 -3
- package/dist/server/components/command-item/index.js +3 -5
- package/dist/server/components/command-menu/index.js +3 -5
- package/dist/server/components/confirm-dialog/index.js +4 -4
- package/dist/server/components/context-menu/index.js +7 -7
- package/dist/server/components/data-table/index.js +3 -3
- package/dist/server/components/date-picker/index.js +4 -4
- package/dist/server/components/date-range-field/index.js +4 -4
- package/dist/server/components/diff-viewer/index.js +9 -11
- package/dist/server/components/drawer/index.js +4 -4
- package/dist/server/components/dropdown/index.js +7 -7
- package/dist/server/components/faceted-filter-bar/index.js +2 -2
- package/dist/server/components/focus-trap/index.js +7 -2
- package/dist/server/components/icons/index.js +156 -0
- package/dist/server/components/inline-loading/index.js +1 -1
- package/dist/server/components/json-schema-editor/index.js +11 -13
- package/dist/server/components/load-more/index.js +2 -3
- package/dist/server/components/markdown-editor/index.js +13 -12
- package/dist/server/components/menu-bar/index.js +4 -4
- package/dist/server/components/modal/index.js +4 -4
- package/dist/server/components/popover/index.js +3 -3
- package/dist/server/components/review-editor/index.js +169 -122
- package/dist/server/components/schedule-builder/index.js +5 -5
- package/dist/server/components/schema-form/index.js +1 -1
- package/dist/server/components/segment/index.js +3 -3
- package/dist/server/components/segmented-control/index.js +4 -4
- package/dist/server/components/selection-popover/index.js +3 -3
- package/dist/server/components/sheet/index.js +3 -3
- package/dist/server/components/sidebar/index.js +4 -4
- package/dist/server/components/table/index.js +3 -3
- package/dist/server/components/tag-input/index.js +2 -2
- package/dist/server/index.js +272 -316
- package/dist/server/{index.server-dwwqssey.js → index.server-0qh3v3nq.js} +1 -1
- package/dist/server/index.server-25wmev4e.js +2 -0
- package/dist/server/{index.server-zdm63dt8.js → index.server-2c56kqws.js} +107 -25
- package/dist/server/{index.server-y4n8vc08.js → index.server-2pc5cv6c.js} +1 -1
- package/dist/server/{index.server-1vsv7ngz.js → index.server-3g76h7z7.js} +12 -2
- package/dist/server/{index.server-xz99aed4.js → index.server-45n4s30n.js} +12 -12
- package/dist/server/{index.server-zzd5wpbw.js → index.server-4dfs3xwn.js} +1 -1
- package/dist/server/{index.server-vhyjjx9z.js → index.server-4jkqgp17.js} +7 -9
- package/dist/server/{index.server-bmxbsk4y.js → index.server-51sxnete.js} +18 -18
- package/dist/server/{index.server-1bwvsnjk.js → index.server-6rv1rfwq.js} +37 -14
- package/dist/server/{index.server-np3c7kx0.js → index.server-7798gc22.js} +1 -1
- package/dist/server/{index.server-2m1kenak.js → index.server-7kjw6qw5.js} +1 -1
- package/dist/server/{index.server-tfftb7hs.js → index.server-7zpzspk6.js} +1 -1
- package/dist/server/{index.server-7yvpb6z7.js → index.server-894t97kv.js} +4 -4
- package/dist/server/{index.server-47v2fhp4.js → index.server-8b35ekqg.js} +1 -1
- package/dist/server/{index.server-j5hn2qds.js → index.server-8nm871y8.js} +80 -30
- package/dist/server/{index.server-h0cvwvhy.js → index.server-9drzqktm.js} +1 -1
- package/dist/server/{index.server-x9s4m9eg.js → index.server-agsdwg53.js} +1 -1
- package/dist/server/{index.server-hpeavvnq.js → index.server-b4gp066a.js} +1 -1
- package/dist/server/{index.server-gkazv439.js → index.server-bf7d81b4.js} +7 -7
- package/dist/server/{index.server-krqvnt6p.js → index.server-d4ft97bx.js} +4 -2
- package/dist/server/{index.server-t1x9h8cb.js → index.server-dg19y3m7.js} +1 -1
- package/dist/server/{index.server-jt1twhgk.js → index.server-dq0k0qf6.js} +10 -10
- package/dist/server/{index.server-pxq277t5.js → index.server-frb9e55d.js} +1 -1
- package/dist/server/{index.server-9kz37z89.js → index.server-g3726bja.js} +1 -1
- package/dist/server/index.server-gyzmkrnz.js +2 -0
- package/dist/server/{index.server-mr68brd6.js → index.server-jgdtsvz2.js} +1 -1
- package/dist/server/{index.server-p56xxef1.js → index.server-m8ya4p7w.js} +1 -1
- package/dist/server/{index.server-1nq7z1qw.js → index.server-mda2y5g6.js} +1 -1
- package/dist/server/{index.server-jdcq5zza.js → index.server-mehav5vs.js} +7 -7
- package/dist/server/{index.server-e89qfamd.js → index.server-mknhgg07.js} +4 -4
- package/dist/server/{index.server-j570vb03.js → index.server-mvjzcna5.js} +1 -1
- package/dist/server/index.server-n4jxy52q.js +2 -0
- package/dist/server/{index.server-h89zk5ev.js → index.server-ne4gzxvz.js} +7 -7
- package/dist/server/{index.server-eftvmq3f.js → index.server-pfbzz3x7.js} +1 -1
- package/dist/server/{index.server-zrh23kty.js → index.server-pyjzfjfn.js} +1 -1
- package/dist/server/{index.server-rga8sc7j.js → index.server-q1d48s9t.js} +40 -36
- package/dist/server/{index.server-46cjwcqw.js → index.server-qv0kkre4.js} +5 -5
- package/dist/server/{index.server-yhzydqxe.js → index.server-r82zjq88.js} +5 -5
- package/dist/server/{index.server-9ykk1kbg.js → index.server-rbd5ys4z.js} +1 -1
- package/dist/server/{index.server-tcay903b.js → index.server-tnecnach.js} +4 -4
- package/dist/server/{index.server-9ra3xv88.js → index.server-x66zvjfc.js} +9 -9
- package/dist/server/{index.server-6sh11ap6.js → index.server-y4kfz0er.js} +1 -1
- package/dist/server/{index.server-n82rcv0m.js → index.server-z721a5gp.js} +4 -4
- package/dist/server/{index.server-mm1xa3kr.js → index.server-zdhv33ph.js} +51 -20
- package/dist/server/{index.server-t3hknp1c.js → index.server-zm04d9eq.js} +4 -4
- package/dist/server/{index.server-nx9c2ep1.js → index.server-zncgb7mw.js} +2 -2
- package/package.json +14 -135
- package/src/components/focus-trap/index.ts +1 -0
- package/src/components/icons/index.ts +82 -40
- package/src/index.ts +0 -34
- package/src/styles/components.css +0 -4
- package/dist/components/chat/adapter/chat-adapter.d.ts +0 -123
- package/dist/components/chat/adapter/index.d.ts +0 -8
- package/dist/components/chat/artifact/artifact-panel.svelte.d.ts +0 -15
- package/dist/components/chat/artifact/artifact-viewer.svelte.d.ts +0 -10
- package/dist/components/chat/artifact/chat-artifact-layout.svelte.d.ts +0 -23
- package/dist/components/chat/artifact/index.d.ts +0 -3
- package/dist/components/chat/builders.d.ts +0 -25
- package/dist/components/chat/chat.css +0 -16
- package/dist/components/chat/chat.css.d.ts +0 -1
- package/dist/components/chat/chat.schema.d.ts +0 -3
- package/dist/components/chat/chat.schema.js +0 -366
- package/dist/components/chat/chat.svelte.d.ts +0 -31
- package/dist/components/chat/chat.types.d.ts +0 -268
- package/dist/components/chat/chat.variables.d.ts +0 -2
- package/dist/components/chat/chat.variables.js +0 -61
- package/dist/components/chat/container/chat-events.d.ts +0 -22
- package/dist/components/chat/container/chat-history-trigger.svelte.d.ts +0 -15
- package/dist/components/chat/container/chat-jump-controls.svelte.d.ts +0 -24
- package/dist/components/chat/container/chat-participant-typing.svelte.d.ts +0 -31
- package/dist/components/chat/container/chat-search-bar.svelte.d.ts +0 -38
- package/dist/components/chat/container/chat-status-announcer.svelte.d.ts +0 -21
- package/dist/components/chat/container/chat.svelte.d.ts +0 -17
- package/dist/components/chat/container/index.d.ts +0 -12
- package/dist/components/chat/container/scroll-utilities.d.ts +0 -119
- package/dist/components/chat/container/use-chat-disclosure-state.svelte.d.ts +0 -58
- package/dist/components/chat/container/use-chat-keyboard-nav.svelte.d.ts +0 -57
- package/dist/components/chat/container/use-chat-message-groups.svelte.d.ts +0 -74
- package/dist/components/chat/container/use-chat-read-receipts.svelte.d.ts +0 -51
- package/dist/components/chat/container/use-chat-scroll-state.svelte.d.ts +0 -111
- package/dist/components/chat/container/use-chat-search.svelte.d.ts +0 -82
- package/dist/components/chat/container/use-chat-typing-indicator.svelte.d.ts +0 -76
- package/dist/components/chat/container/use-chat-unread-state.svelte.d.ts +0 -80
- package/dist/components/chat/container/use-chat-virtualizer.svelte.d.ts +0 -47
- package/dist/components/chat/conversation-model.d.ts +0 -16
- package/dist/components/chat/export/conversation-export-actions.svelte.d.ts +0 -17
- package/dist/components/chat/export/index.d.ts +0 -8
- package/dist/components/chat/index.d.ts +0 -23
- package/dist/components/chat/index.js +0 -11305
- package/dist/components/chat/input/attachment-kind.d.ts +0 -10
- package/dist/components/chat/input/chat-attachment-preview.svelte.d.ts +0 -8
- package/dist/components/chat/input/chat-attachment-serialization.d.ts +0 -9
- package/dist/components/chat/input/chat-attachment.d.ts +0 -11
- package/dist/components/chat/input/chat-input.svelte.d.ts +0 -79
- package/dist/components/chat/input/index.d.ts +0 -5
- package/dist/components/chat/message/chat-date-separator.svelte.d.ts +0 -12
- package/dist/components/chat/message/chat-message-parts-renderer.svelte.d.ts +0 -4
- package/dist/components/chat/message/chat-message-parts.d.ts +0 -96
- package/dist/components/chat/message/chat-message.svelte.d.ts +0 -91
- package/dist/components/chat/message/chat-read-receipt.svelte.d.ts +0 -27
- package/dist/components/chat/message/image-lightbox.svelte.d.ts +0 -17
- package/dist/components/chat/message/index.d.ts +0 -6
- package/dist/components/chat/message/markdown-preview.svelte.d.ts +0 -8
- package/dist/components/chat/message/message-attachments.svelte.d.ts +0 -17
- package/dist/components/chat/message/message-content.svelte.d.ts +0 -18
- package/dist/components/chat/message/parts/image-part.svelte.d.ts +0 -17
- package/dist/components/chat/message/parts/markdown-part.svelte.d.ts +0 -8
- package/dist/components/chat/message/parts/reasoning-part.svelte.d.ts +0 -12
- package/dist/components/chat/message/parts/step-part.svelte.d.ts +0 -8
- package/dist/components/chat/message/parts/suggestion-part.svelte.d.ts +0 -18
- package/dist/components/chat/message/parts/tool-approval-part.svelte.d.ts +0 -12
- package/dist/components/chat/message/parts/tool-call-part.svelte.d.ts +0 -12
- package/dist/components/chat/message/parts/tool-result-part.svelte.d.ts +0 -8
- package/dist/components/chat/message/tool-call-group.svelte.d.ts +0 -15
- package/dist/components/chat/message/tool-payload-code.svelte.d.ts +0 -9
- package/dist/components/chat/utilities/conversation.d.ts +0 -12
- package/dist/components/chat/utilities/index.d.ts +0 -9
- package/dist/components/chat/utilities/types.d.ts +0 -262
- package/dist/components/chat/utilities/utilities.d.ts +0 -140
- package/dist/components/chat-composer-popover/chat-composer-popover-filter.d.ts +0 -11
- package/dist/components/chat-composer-popover/chat-composer-popover.css +0 -7
- package/dist/components/chat-composer-popover/chat-composer-popover.css.d.ts +0 -1
- package/dist/components/chat-composer-popover/chat-composer-popover.schema.d.ts +0 -3
- package/dist/components/chat-composer-popover/chat-composer-popover.schema.js +0 -150
- package/dist/components/chat-composer-popover/chat-composer-popover.svelte.d.ts +0 -46
- package/dist/components/chat-composer-popover/chat-composer-popover.types.d.ts +0 -77
- package/dist/components/chat-composer-popover/chat-composer-popover.variables.d.ts +0 -2
- package/dist/components/chat-composer-popover/chat-composer-popover.variables.js +0 -61
- package/dist/components/chat-composer-popover/index.d.ts +0 -6
- package/dist/components/chat-composer-popover/index.js +0 -3285
- package/dist/components/chat-conversation-header/chat-conversation-header.css +0 -51
- package/dist/components/chat-conversation-header/chat-conversation-header.css.d.ts +0 -1
- package/dist/components/chat-conversation-header/chat-conversation-header.schema.d.ts +0 -3
- package/dist/components/chat-conversation-header/chat-conversation-header.schema.js +0 -94
- package/dist/components/chat-conversation-header/chat-conversation-header.svelte.d.ts +0 -19
- package/dist/components/chat-conversation-header/chat-conversation-header.types.d.ts +0 -18
- package/dist/components/chat-conversation-header/chat-conversation-header.variables.d.ts +0 -2
- package/dist/components/chat-conversation-header/chat-conversation-header.variables.js +0 -61
- package/dist/components/chat-conversation-header/index.d.ts +0 -5
- package/dist/components/chat-conversation-header/index.js +0 -4278
- package/dist/components/chat-conversation-list/chat-conversation-list.css +0 -127
- package/dist/components/chat-conversation-list/chat-conversation-list.css.d.ts +0 -1
- package/dist/components/chat-conversation-list/chat-conversation-list.schema.d.ts +0 -3
- package/dist/components/chat-conversation-list/chat-conversation-list.schema.js +0 -105
- package/dist/components/chat-conversation-list/chat-conversation-list.svelte.d.ts +0 -21
- package/dist/components/chat-conversation-list/chat-conversation-list.types.d.ts +0 -17
- package/dist/components/chat-conversation-list/chat-conversation-list.variables.d.ts +0 -2
- package/dist/components/chat-conversation-list/chat-conversation-list.variables.js +0 -61
- package/dist/components/chat-conversation-list/conversation-summary.d.ts +0 -30
- package/dist/components/chat-conversation-list/index.d.ts +0 -6
- package/dist/components/chat-conversation-list/index.js +0 -536
- package/dist/server/components/chat/index.js +0 -121
- package/dist/server/components/chat-composer-popover/index.js +0 -26
- package/dist/server/components/chat-conversation-header/index.js +0 -41
- package/dist/server/components/chat-conversation-list/index.js +0 -19
- package/dist/server/index.server-2bbwajb2.js +0 -54
- package/dist/server/index.server-2hqrv7ca.js +0 -9
- package/dist/server/index.server-67qgdypc.js +0 -9
- package/dist/server/index.server-6hnfzc7f.js +0 -263
- package/dist/server/index.server-8rmtb8vx.js +0 -175
- package/dist/server/index.server-a59y47rw.js +0 -59
- package/dist/server/index.server-bfkka7x4.js +0 -2
- package/dist/server/index.server-f2me5abn.js +0 -4230
- package/dist/server/index.server-kb6w1a7c.js +0 -27
- package/dist/server/index.server-nphtb2ey.js +0 -76
- package/dist/server/index.server-qkfd0qa7.js +0 -2
- package/dist/server/index.server-rf67m8v5.js +0 -2
- package/dist/server/index.server-rqe5bqgm.js +0 -37
- package/dist/server/index.server-xtjjmsyq.js +0 -315
- package/dist/server/index.server-yq9evnp4.js +0 -38
- package/dist/server/index.server-z1qvwaem.js +0 -74
- package/dist/server/index.server-z7hxtqs1.js +0 -83
- package/src/components/chat/adapter/chat-adapter.ts +0 -132
- package/src/components/chat/adapter/index.ts +0 -15
- package/src/components/chat/artifact/artifact-panel.svelte +0 -112
- package/src/components/chat/artifact/artifact-viewer.svelte +0 -101
- package/src/components/chat/artifact/chat-artifact-layout.svelte +0 -56
- package/src/components/chat/artifact/index.ts +0 -3
- package/src/components/chat/builders.ts +0 -464
- package/src/components/chat/chat.css +0 -16
- package/src/components/chat/chat.examples.json +0 -61
- package/src/components/chat/chat.schema.json +0 -290
- package/src/components/chat/chat.schema.ts +0 -335
- package/src/components/chat/chat.svelte +0 -67
- package/src/components/chat/chat.types.ts +0 -284
- package/src/components/chat/chat.variables.json +0 -1
- package/src/components/chat/chat.variables.ts +0 -3
- package/src/components/chat/container/chat-events.ts +0 -26
- package/src/components/chat/container/chat-history-trigger.svelte +0 -95
- package/src/components/chat/container/chat-jump-controls.svelte +0 -191
- package/src/components/chat/container/chat-participant-typing.svelte +0 -128
- package/src/components/chat/container/chat-search-bar.svelte +0 -219
- package/src/components/chat/container/chat-status-announcer.svelte +0 -22
- package/src/components/chat/container/chat.svelte +0 -1879
- package/src/components/chat/container/index.ts +0 -64
- package/src/components/chat/container/scroll-utilities.ts +0 -204
- package/src/components/chat/container/use-chat-disclosure-state.svelte.ts +0 -62
- package/src/components/chat/container/use-chat-keyboard-nav.svelte.ts +0 -153
- package/src/components/chat/container/use-chat-message-groups.svelte.ts +0 -146
- package/src/components/chat/container/use-chat-read-receipts.svelte.ts +0 -62
- package/src/components/chat/container/use-chat-scroll-state.svelte.ts +0 -292
- package/src/components/chat/container/use-chat-search.svelte.ts +0 -116
- package/src/components/chat/container/use-chat-typing-indicator.svelte.ts +0 -153
- package/src/components/chat/container/use-chat-unread-state.svelte.ts +0 -170
- package/src/components/chat/container/use-chat-virtualizer.svelte.ts +0 -260
- package/src/components/chat/conversation-model.ts +0 -45
- package/src/components/chat/export/conversation-export-actions.svelte +0 -174
- package/src/components/chat/export/index.ts +0 -9
- package/src/components/chat/index.ts +0 -138
- package/src/components/chat/input/attachment-kind.ts +0 -28
- package/src/components/chat/input/chat-attachment-preview.svelte +0 -223
- package/src/components/chat/input/chat-attachment-serialization.ts +0 -63
- package/src/components/chat/input/chat-attachment.ts +0 -12
- package/src/components/chat/input/chat-input.svelte +0 -810
- package/src/components/chat/input/index.ts +0 -9
- package/src/components/chat/message/chat-date-separator.svelte +0 -87
- package/src/components/chat/message/chat-message-parts-renderer.svelte +0 -139
- package/src/components/chat/message/chat-message-parts.ts +0 -163
- package/src/components/chat/message/chat-message.svelte +0 -861
- package/src/components/chat/message/chat-read-receipt.svelte +0 -85
- package/src/components/chat/message/image-lightbox.svelte +0 -255
- package/src/components/chat/message/index.ts +0 -6
- package/src/components/chat/message/markdown-preview.svelte +0 -77
- package/src/components/chat/message/message-attachments.svelte +0 -178
- package/src/components/chat/message/message-content.svelte +0 -132
- package/src/components/chat/message/parts/image-part.svelte +0 -11
- package/src/components/chat/message/parts/markdown-part.svelte +0 -17
- package/src/components/chat/message/parts/reasoning-part.svelte +0 -274
- package/src/components/chat/message/parts/step-part.svelte +0 -127
- package/src/components/chat/message/parts/suggestion-part.svelte +0 -83
- package/src/components/chat/message/parts/tool-approval-part.svelte +0 -298
- package/src/components/chat/message/parts/tool-call-part.svelte +0 -19
- package/src/components/chat/message/parts/tool-result-part.svelte +0 -65
- package/src/components/chat/message/tool-call-group.svelte +0 -274
- package/src/components/chat/message/tool-payload-code.svelte +0 -35
- package/src/components/chat/utilities/conversation.ts +0 -44
- package/src/components/chat/utilities/index.ts +0 -33
- package/src/components/chat/utilities/types.ts +0 -288
- package/src/components/chat/utilities/utilities.ts +0 -507
- package/src/components/chat-composer-popover/chat-composer-popover-filter.ts +0 -68
- package/src/components/chat-composer-popover/chat-composer-popover.css +0 -7
- package/src/components/chat-composer-popover/chat-composer-popover.examples.json +0 -13
- package/src/components/chat-composer-popover/chat-composer-popover.schema.json +0 -90
- package/src/components/chat-composer-popover/chat-composer-popover.schema.ts +0 -95
- package/src/components/chat-composer-popover/chat-composer-popover.svelte +0 -234
- package/src/components/chat-composer-popover/chat-composer-popover.types.ts +0 -88
- package/src/components/chat-composer-popover/chat-composer-popover.variables.json +0 -1
- package/src/components/chat-composer-popover/chat-composer-popover.variables.ts +0 -3
- package/src/components/chat-composer-popover/index.ts +0 -19
- package/src/components/chat-conversation-header/chat-conversation-header.css +0 -51
- package/src/components/chat-conversation-header/chat-conversation-header.examples.json +0 -13
- package/src/components/chat-conversation-header/chat-conversation-header.schema.json +0 -34
- package/src/components/chat-conversation-header/chat-conversation-header.schema.ts +0 -38
- package/src/components/chat-conversation-header/chat-conversation-header.svelte +0 -49
- package/src/components/chat-conversation-header/chat-conversation-header.types.ts +0 -20
- package/src/components/chat-conversation-header/chat-conversation-header.variables.json +0 -1
- package/src/components/chat-conversation-header/chat-conversation-header.variables.ts +0 -3
- package/src/components/chat-conversation-header/index.ts +0 -9
- package/src/components/chat-conversation-list/chat-conversation-list.css +0 -127
- package/src/components/chat-conversation-list/chat-conversation-list.examples.json +0 -13
- package/src/components/chat-conversation-list/chat-conversation-list.schema.json +0 -45
- package/src/components/chat-conversation-list/chat-conversation-list.schema.ts +0 -52
- package/src/components/chat-conversation-list/chat-conversation-list.svelte +0 -75
- package/src/components/chat-conversation-list/chat-conversation-list.types.ts +0 -18
- package/src/components/chat-conversation-list/chat-conversation-list.variables.json +0 -1
- package/src/components/chat-conversation-list/chat-conversation-list.variables.ts +0 -3
- package/src/components/chat-conversation-list/conversation-summary.ts +0 -88
- package/src/components/chat-conversation-list/index.ts +0 -11
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runes helper for chat scroll state management.
|
|
3
|
-
*
|
|
4
|
-
* Manages:
|
|
5
|
-
* - atBottom state for auto-scroll decisions
|
|
6
|
-
* - showJumpButton state for jump-to-latest visibility
|
|
7
|
-
* - Scroll event listener attachment
|
|
8
|
-
* - IntersectionObserver for bottom sentinel
|
|
9
|
-
* - Imperative scroll methods
|
|
10
|
-
*/
|
|
11
|
-
import { useReducedMotion } from '../../../utilities/use-reduced-motion.svelte.ts';
|
|
12
|
-
import { isAtBottom as checkIsAtBottom, DEFAULT_SCROLL_CONFIGURATION, shouldShowJumpToLatest, } from './scroll-utilities';
|
|
13
|
-
/**
|
|
14
|
-
* Cleanup resources.
|
|
15
|
-
*
|
|
16
|
-
* No-op: this helper owns no long-lived resources. IntersectionObserver
|
|
17
|
-
* cleanup is handled by the disconnect function returned from
|
|
18
|
-
* `createSentinelObserver`. Exposed for API symmetry with consumers that
|
|
19
|
-
* call `destroy()` unconditionally on teardown.
|
|
20
|
-
*/
|
|
21
|
-
const destroy = () => { };
|
|
22
|
-
// ==========================================================================
|
|
23
|
-
// Utilities
|
|
24
|
-
// ==========================================================================
|
|
25
|
-
// ==========================================================================
|
|
26
|
-
// Helper
|
|
27
|
-
// ==========================================================================
|
|
28
|
-
/**
|
|
29
|
-
* Creates reactive state and methods for managing chat scroll behavior.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```svelte
|
|
33
|
-
* <script lang="ts">
|
|
34
|
-
* import { useChatScrollState } from './use-chat-scroll-state.svelte';
|
|
35
|
-
*
|
|
36
|
-
* const scrollState = useChatScrollState({
|
|
37
|
-
* bottomThreshold: 150,
|
|
38
|
-
* jumpThreshold: 200,
|
|
39
|
-
* onScrollStateChange: (event) => console.log('Scroll:', event),
|
|
40
|
-
* onReachBottom: () => unreadState.markAllAsRead(),
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* const scrollAttachment = scrollState.createScrollAttachment();
|
|
44
|
-
*
|
|
45
|
-
* // Wire the bottom sentinel with useIntersection via {@attach}. Wrap in $derived so
|
|
46
|
-
* // the observer is stable across re-renders (recreated only when root/threshold change).
|
|
47
|
-
* const sentinelAttach = $derived(
|
|
48
|
-
* useIntersection(scrollState.handleSentinelEntry, {
|
|
49
|
-
* root: viewport,
|
|
50
|
-
* rootMargin: `0px 0px 150px 0px`,
|
|
51
|
-
* }),
|
|
52
|
-
* );
|
|
53
|
-
* </script>
|
|
54
|
-
*
|
|
55
|
-
* <div bind:this={viewport} {@attach scrollAttachment}>
|
|
56
|
-
* <!-- content -->
|
|
57
|
-
* <div {@attach sentinelAttach}></div>
|
|
58
|
-
* </div>
|
|
59
|
-
*
|
|
60
|
-
* {#if scrollState.showJumpButton}
|
|
61
|
-
* <button onclick={() => scrollState.jumpToLatest(viewport)}>
|
|
62
|
-
* Jump to latest
|
|
63
|
-
* </button>
|
|
64
|
-
* {/if}
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function useChatScrollState(options) {
|
|
68
|
-
const { bottomThreshold = DEFAULT_SCROLL_CONFIGURATION.bottomThreshold, getBottomThreshold, jumpThreshold = DEFAULT_SCROLL_CONFIGURATION.jumpThreshold, getJumpThreshold, onScrollStateChange, onReachBottom, } = options ?? {};
|
|
69
|
-
// Shared reduced-motion preference (OVERLAY-POLICY: use the shared hook, not inline matchMedia).
|
|
70
|
-
const reducedMotion = useReducedMotion();
|
|
71
|
-
/**
|
|
72
|
-
* Returns the appropriate scroll behavior based on user preference.
|
|
73
|
-
* Respects prefers-reduced-motion by using 'auto' instead of 'smooth'.
|
|
74
|
-
*/
|
|
75
|
-
function getScrollBehavior() {
|
|
76
|
-
return reducedMotion.current ? 'auto' : 'smooth';
|
|
77
|
-
}
|
|
78
|
-
// Reactive state
|
|
79
|
-
let atBottom = $state(true);
|
|
80
|
-
let showJumpButton = $state(false);
|
|
81
|
-
// Non-reactive bookkeeping
|
|
82
|
-
let scrollTicking = false;
|
|
83
|
-
let isUserScrolling = false; // Prevents auto-scroll from interrupting user-initiated smooth scroll
|
|
84
|
-
// Cancel function for the in-flight withForcedLayout session, if any. A new
|
|
85
|
-
// session cancels the previous one's listeners/timer before starting its
|
|
86
|
-
// own — see withForcedLayout below for why this matters.
|
|
87
|
-
let activeForcedLayoutCancel = null;
|
|
88
|
-
/**
|
|
89
|
-
* Set atBottom state directly.
|
|
90
|
-
*/
|
|
91
|
-
function setAtBottom(value) {
|
|
92
|
-
atBottom = value;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Create a scroll event listener attachment for the viewport.
|
|
96
|
-
*/
|
|
97
|
-
function createScrollAttachment() {
|
|
98
|
-
return (element) => {
|
|
99
|
-
function handleScroll() {
|
|
100
|
-
if (scrollTicking)
|
|
101
|
-
return;
|
|
102
|
-
scrollTicking = true;
|
|
103
|
-
requestAnimationFrame(() => {
|
|
104
|
-
const state = {
|
|
105
|
-
scrollTop: element.scrollTop,
|
|
106
|
-
scrollHeight: element.scrollHeight,
|
|
107
|
-
clientHeight: element.clientHeight,
|
|
108
|
-
};
|
|
109
|
-
const scrolledToBottom = checkIsAtBottom(state, getBottomThreshold?.() ?? bottomThreshold);
|
|
110
|
-
const shouldShowJump = shouldShowJumpToLatest(state, getJumpThreshold?.() ?? jumpThreshold);
|
|
111
|
-
// Update reactive state
|
|
112
|
-
atBottom = scrolledToBottom;
|
|
113
|
-
showJumpButton = shouldShowJump;
|
|
114
|
-
// Clear unread when scrolled to bottom
|
|
115
|
-
if (scrolledToBottom) {
|
|
116
|
-
onReachBottom?.();
|
|
117
|
-
}
|
|
118
|
-
// Emit scroll state change
|
|
119
|
-
onScrollStateChange?.({
|
|
120
|
-
atBottom: scrolledToBottom,
|
|
121
|
-
scrollTop: state.scrollTop,
|
|
122
|
-
scrollHeight: state.scrollHeight,
|
|
123
|
-
});
|
|
124
|
-
scrollTicking = false;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
element.addEventListener('scroll', handleScroll, { passive: true });
|
|
128
|
-
return () => element.removeEventListener('scroll', handleScroll);
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* IntersectionObserver callback for the bottom sentinel element.
|
|
133
|
-
* Exposed for use with useIntersection attachment-based wiring.
|
|
134
|
-
*/
|
|
135
|
-
function handleSentinelEntry(entry) {
|
|
136
|
-
const sentinelVisible = entry.isIntersecting;
|
|
137
|
-
if (sentinelVisible && !atBottom) {
|
|
138
|
-
atBottom = true;
|
|
139
|
-
onReachBottom?.();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create an IntersectionObserver for the bottom sentinel.
|
|
144
|
-
* @deprecated Prefer `{@attach useIntersection(scrollState.handleSentinelEntry, { root: viewport, rootMargin })}` on the sentinel element.
|
|
145
|
-
*/
|
|
146
|
-
function createSentinelObserver(viewport, sentinel) {
|
|
147
|
-
if (!viewport || !sentinel)
|
|
148
|
-
return;
|
|
149
|
-
const observer = new IntersectionObserver(([entry]) => {
|
|
150
|
-
if (!entry)
|
|
151
|
-
return;
|
|
152
|
-
handleSentinelEntry(entry);
|
|
153
|
-
}, {
|
|
154
|
-
root: viewport,
|
|
155
|
-
threshold: 0,
|
|
156
|
-
rootMargin: `0px 0px ${getBottomThreshold?.() ?? bottomThreshold}px 0px`,
|
|
157
|
-
});
|
|
158
|
-
observer.observe(sentinel);
|
|
159
|
-
return () => observer.disconnect();
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Forces every row to lay out at its real height before a programmatic
|
|
163
|
-
* scroll-to-bottom, then restores the content-visibility optimization once
|
|
164
|
-
* the scroll settles.
|
|
165
|
-
*
|
|
166
|
-
* Off-screen `.chat-message` rows use `content-visibility: auto` with a
|
|
167
|
-
* 180px estimate (`contain-intrinsic-size`) until they're painted. Calling
|
|
168
|
-
* `scrollTo({ top: viewport.scrollHeight, behavior: 'smooth' })` captures a
|
|
169
|
-
* target computed from those estimates; as the animation scrolls estimated
|
|
170
|
-
* rows into view, they resize to their real height, which shifts content
|
|
171
|
-
* under the fixed pixel target mid-flight — visible as a jerk right as the
|
|
172
|
-
* scroll finishes. Forcing layout up front (`data-cinder-force-visible`)
|
|
173
|
-
* makes the target accurate from the start.
|
|
174
|
-
*
|
|
175
|
-
* The `scrollend` listener restores the optimization as soon as the
|
|
176
|
-
* animation actually finishes. The timeout is a backstop for environments
|
|
177
|
-
* without `scrollend` support and for a zero-distance scroll (already at
|
|
178
|
-
* the bottom), where neither `scroll` nor `scrollend` ever fires — but it
|
|
179
|
-
* re-arms on every `scroll` tick rather than firing once on a fixed clock,
|
|
180
|
-
* so a scroll animation that legitimately runs longer than the backstop
|
|
181
|
-
* duration (a long transcript, a slower device) can never have the
|
|
182
|
-
* optimization restored out from under it mid-flight, which would let
|
|
183
|
-
* off-screen rows resize again before the scroll settles — the exact jerk
|
|
184
|
-
* this exists to prevent.
|
|
185
|
-
*
|
|
186
|
-
* A second call before the first session settles (e.g. a double-click on
|
|
187
|
-
* jump-to-latest, or auto-scroll firing while a prior scroll is still in
|
|
188
|
-
* flight) cancels the earlier session's listeners/timer first. Without
|
|
189
|
-
* this, the OLDER session's own scrollend/backstop could still fire and
|
|
190
|
-
* strip the attribute while the NEWER scroll animation is still running —
|
|
191
|
-
* the same jerk this whole mechanism exists to prevent, just reintroduced
|
|
192
|
-
* by an overlapping call instead of a single long one.
|
|
193
|
-
*/
|
|
194
|
-
function withForcedLayout(viewport, scroll) {
|
|
195
|
-
activeForcedLayoutCancel?.();
|
|
196
|
-
viewport.setAttribute('data-cinder-force-visible', '');
|
|
197
|
-
// Force a synchronous layout so scrollHeight (read inside `scroll`)
|
|
198
|
-
// reflects every row's real height, not the content-visibility estimate.
|
|
199
|
-
void viewport.offsetHeight;
|
|
200
|
-
let settled = false;
|
|
201
|
-
let backstop;
|
|
202
|
-
const backstopDuration = reducedMotion.current ? 50 : 500;
|
|
203
|
-
function cancel() {
|
|
204
|
-
if (settled)
|
|
205
|
-
return;
|
|
206
|
-
settled = true;
|
|
207
|
-
clearTimeout(backstop);
|
|
208
|
-
viewport.removeEventListener('scrollend', restore);
|
|
209
|
-
viewport.removeEventListener('scroll', armBackstop);
|
|
210
|
-
}
|
|
211
|
-
const restore = () => {
|
|
212
|
-
if (settled)
|
|
213
|
-
return;
|
|
214
|
-
cancel();
|
|
215
|
-
activeForcedLayoutCancel = null;
|
|
216
|
-
viewport.removeAttribute('data-cinder-force-visible');
|
|
217
|
-
};
|
|
218
|
-
function armBackstop() {
|
|
219
|
-
clearTimeout(backstop);
|
|
220
|
-
backstop = setTimeout(restore, backstopDuration);
|
|
221
|
-
}
|
|
222
|
-
activeForcedLayoutCancel = cancel;
|
|
223
|
-
viewport.addEventListener('scrollend', restore, { once: true });
|
|
224
|
-
viewport.addEventListener('scroll', armBackstop, { passive: true });
|
|
225
|
-
// Covers the zero-distance case (already at bottom): no scroll/scrollend
|
|
226
|
-
// event will ever fire, so this is the only thing that restores it.
|
|
227
|
-
armBackstop();
|
|
228
|
-
scroll();
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Scroll to the bottom of the viewport.
|
|
232
|
-
*/
|
|
233
|
-
function scrollToBottom(viewport) {
|
|
234
|
-
if (!viewport)
|
|
235
|
-
return;
|
|
236
|
-
withForcedLayout(viewport, () => {
|
|
237
|
-
viewport.scrollTo({ top: viewport.scrollHeight, behavior: getScrollBehavior() });
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Scroll to the top of the viewport.
|
|
242
|
-
*/
|
|
243
|
-
function scrollToTop(viewport) {
|
|
244
|
-
viewport?.scrollTo({ top: 0, behavior: getScrollBehavior() });
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Jump to the latest message with animation.
|
|
248
|
-
*/
|
|
249
|
-
function jumpToLatest(viewport, onComplete) {
|
|
250
|
-
if (!viewport)
|
|
251
|
-
return;
|
|
252
|
-
// Prevent auto-scroll from interrupting the smooth scroll animation
|
|
253
|
-
isUserScrolling = true;
|
|
254
|
-
withForcedLayout(viewport, () => {
|
|
255
|
-
viewport.scrollTo({ top: viewport.scrollHeight, behavior: getScrollBehavior() });
|
|
256
|
-
});
|
|
257
|
-
onReachBottom?.();
|
|
258
|
-
onComplete?.();
|
|
259
|
-
// Focus last message for keyboard users and clear the user scrolling flag
|
|
260
|
-
// after animation completes (typical smooth scroll takes ~300-500ms)
|
|
261
|
-
// For reduced motion, use minimal delay since scroll is instant
|
|
262
|
-
const scrollDuration = reducedMotion.current ? 50 : 500;
|
|
263
|
-
setTimeout(() => {
|
|
264
|
-
isUserScrolling = false;
|
|
265
|
-
const wrappers = viewport.querySelectorAll('.chat-message-wrapper');
|
|
266
|
-
const lastWrapper = wrappers.length > 0 ? wrappers[wrappers.length - 1] : null;
|
|
267
|
-
const lastMessage = lastWrapper?.querySelector('.chat-message') ?? null;
|
|
268
|
-
lastMessage?.focus();
|
|
269
|
-
}, scrollDuration);
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
get atBottom() {
|
|
273
|
-
return atBottom;
|
|
274
|
-
},
|
|
275
|
-
get showJumpButton() {
|
|
276
|
-
return showJumpButton;
|
|
277
|
-
},
|
|
278
|
-
setAtBottom,
|
|
279
|
-
createScrollAttachment,
|
|
280
|
-
createSentinelObserver,
|
|
281
|
-
handleSentinelEntry,
|
|
282
|
-
scrollToBottom,
|
|
283
|
-
scrollToTop,
|
|
284
|
-
jumpToLatest,
|
|
285
|
-
getScrollBehavior,
|
|
286
|
-
destroy,
|
|
287
|
-
// Exposed helper for auto-scroll logic, used by the parent component
|
|
288
|
-
get isUserScrolling() {
|
|
289
|
-
return isUserScrolling;
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runes helper for in-conversation message search.
|
|
3
|
-
*
|
|
4
|
-
* Manages:
|
|
5
|
-
* - Search query state
|
|
6
|
-
* - Open/closed state for the search bar
|
|
7
|
-
* - Derived list of matching messages (with their indices)
|
|
8
|
-
* - Current match index for navigation
|
|
9
|
-
*/
|
|
10
|
-
import { getMessageText } from '../utilities/utilities.js';
|
|
11
|
-
// ==========================================================================
|
|
12
|
-
// Helper
|
|
13
|
-
// ==========================================================================
|
|
14
|
-
/**
|
|
15
|
-
* Creates reactive state and methods for in-conversation search.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```svelte
|
|
19
|
-
* <script lang="ts">
|
|
20
|
-
* import { useChatSearch } from './use-chat-search.svelte';
|
|
21
|
-
*
|
|
22
|
-
* const searchState = useChatSearch({
|
|
23
|
-
* getMessages: () => messages,
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* // Open with Ctrl/Cmd+F
|
|
27
|
-
* function handleKeyDown(event: KeyboardEvent) {
|
|
28
|
-
* if ((event.ctrlKey || event.metaKey) && event.key === 'f') {
|
|
29
|
-
* event.preventDefault();
|
|
30
|
-
* searchState.open();
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* </script>
|
|
34
|
-
*
|
|
35
|
-
* {#if searchState.isOpen}
|
|
36
|
-
* <ChatSearchBar
|
|
37
|
-
* query={searchState.query}
|
|
38
|
-
* matchCount={searchState.matchCount}
|
|
39
|
-
* currentMatchIndex={searchState.currentMatchIndex}
|
|
40
|
-
* onquerychange={searchState.setQuery}
|
|
41
|
-
* onnext={searchState.nextMatch}
|
|
42
|
-
* onprevious={searchState.previousMatch}
|
|
43
|
-
* onclose={searchState.close}
|
|
44
|
-
* />
|
|
45
|
-
* {/if}
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export function useChatSearch(options) {
|
|
49
|
-
const { getMessages } = options;
|
|
50
|
-
// Reactive state
|
|
51
|
-
let query = $state('');
|
|
52
|
-
let isOpen = $state(false);
|
|
53
|
-
let currentMatchIndex = $state(0);
|
|
54
|
-
const matches = $derived.by(() => {
|
|
55
|
-
const trimmedQuery = query.trim();
|
|
56
|
-
if (!trimmedQuery)
|
|
57
|
-
return [];
|
|
58
|
-
const lowercasedQuery = trimmedQuery.toLowerCase();
|
|
59
|
-
const messages = getMessages();
|
|
60
|
-
return messages
|
|
61
|
-
.map((message, messageIndex) => ({ message, messageIndex }))
|
|
62
|
-
.filter(({ message }) => getMessageText(message).toLowerCase().includes(lowercasedQuery));
|
|
63
|
-
});
|
|
64
|
-
const matchCount = $derived(matches.length);
|
|
65
|
-
// Clamp currentMatchIndex when the matches array shrinks (e.g., messages edited or deleted).
|
|
66
|
-
// Derived instead of $effect so this works outside component context (e.g., in unit tests).
|
|
67
|
-
const clampedMatchIndex = $derived(matchCount > 0 ? Math.min(currentMatchIndex, matchCount - 1) : 0);
|
|
68
|
-
const currentMatch = $derived(matches[clampedMatchIndex] ?? null);
|
|
69
|
-
function open() {
|
|
70
|
-
isOpen = true;
|
|
71
|
-
}
|
|
72
|
-
function close() {
|
|
73
|
-
isOpen = false;
|
|
74
|
-
query = '';
|
|
75
|
-
currentMatchIndex = 0;
|
|
76
|
-
}
|
|
77
|
-
function nextMatch() {
|
|
78
|
-
if (matchCount > 0) {
|
|
79
|
-
currentMatchIndex = (clampedMatchIndex + 1) % matchCount;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function previousMatch() {
|
|
83
|
-
if (matchCount > 0) {
|
|
84
|
-
currentMatchIndex = (clampedMatchIndex - 1 + matchCount) % matchCount;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function setQuery(value) {
|
|
88
|
-
query = value;
|
|
89
|
-
currentMatchIndex = 0;
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
get query() {
|
|
93
|
-
return query;
|
|
94
|
-
},
|
|
95
|
-
get isOpen() {
|
|
96
|
-
return isOpen;
|
|
97
|
-
},
|
|
98
|
-
get matches() {
|
|
99
|
-
return matches;
|
|
100
|
-
},
|
|
101
|
-
get matchCount() {
|
|
102
|
-
return matchCount;
|
|
103
|
-
},
|
|
104
|
-
get currentMatch() {
|
|
105
|
-
return currentMatch;
|
|
106
|
-
},
|
|
107
|
-
get currentMatchIndex() {
|
|
108
|
-
return clampedMatchIndex;
|
|
109
|
-
},
|
|
110
|
-
open,
|
|
111
|
-
close,
|
|
112
|
-
nextMatch,
|
|
113
|
-
previousMatch,
|
|
114
|
-
setQuery,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-participant typing indicator state for the Chat component.
|
|
3
|
-
*
|
|
4
|
-
* Merges two sources of typing state:
|
|
5
|
-
* 1. The `typingParticipants` prop — a plain array of {@link TypingParticipant}
|
|
6
|
-
* objects passed directly by the consumer (no adapter required).
|
|
7
|
-
* 2. The adapter's `onTypingChange` push handler, forwarded by the container
|
|
8
|
-
* via the `onAdapterTypingChange` callback below.
|
|
9
|
-
*
|
|
10
|
-
* The adapter path produces only a boolean (isTyping). When an adapter delivers
|
|
11
|
-
* a typing-start event without participant metadata, a synthetic participant is
|
|
12
|
-
* inserted with id `'__adapter__'` and a fallback name so the indicator can still
|
|
13
|
-
* render. This keeps the render path uniform (always off a participant list).
|
|
14
|
-
*
|
|
15
|
-
* Accessibility contract (enforced in the component, not here):
|
|
16
|
-
* - A single always-in-DOM `<div aria-live="polite" aria-atomic="true">` outside
|
|
17
|
-
* the `role="log"` div; text is `""` when nobody is typing.
|
|
18
|
-
* - Announcements are debounced 400 ms to filter keystroke-level noise
|
|
19
|
-
* (inter-key intervals ~100–200ms) while staying within the ~300–500ms
|
|
20
|
-
* responsiveness window expected by NVDA/JAWS.
|
|
21
|
-
* - The announced text contains no trailing ellipsis (just names).
|
|
22
|
-
*
|
|
23
|
-
* @module
|
|
24
|
-
*/
|
|
25
|
-
/** Debounce window for aria-live announcements (ms).
|
|
26
|
-
*
|
|
27
|
-
* 400ms filters keystroke-level noise (inter-key intervals ~100–200ms at normal
|
|
28
|
-
* WPM) while staying within the ~300–500ms responsiveness window expected by
|
|
29
|
-
* NVDA/JAWS users. The previous 2000ms value caused announcements to arrive
|
|
30
|
-
* stale or be permanently suppressed in fast-update scenarios. */
|
|
31
|
-
const DEBOUNCE_MS = 400;
|
|
32
|
-
const ADAPTER_PARTICIPANT_ID = '__adapter__';
|
|
33
|
-
const ADAPTER_PARTICIPANT_NAME = 'Someone';
|
|
34
|
-
/**
|
|
35
|
-
* Derive the visible typing label from a participant list.
|
|
36
|
-
*
|
|
37
|
-
* Truncation rules:
|
|
38
|
-
* - 0 participants → `""` (empty — indicator hidden)
|
|
39
|
-
* - 1 participant → `"Alice is typing…"`
|
|
40
|
-
* - 2 participants → `"Alice and Bob are typing…"`
|
|
41
|
-
* - 3–4 participants → `"3 people are typing…"`
|
|
42
|
-
* - 5+ participants → `"Several people are typing…"`
|
|
43
|
-
*/
|
|
44
|
-
export function deriveTypingLabel(participants) {
|
|
45
|
-
const count = participants.length;
|
|
46
|
-
if (count === 0)
|
|
47
|
-
return '';
|
|
48
|
-
if (count === 1)
|
|
49
|
-
return `${participants[0].name} is typing…`;
|
|
50
|
-
if (count === 2)
|
|
51
|
-
return `${participants[0].name} and ${participants[1].name} are typing…`;
|
|
52
|
-
if (count <= 4)
|
|
53
|
-
return `${count} people are typing…`;
|
|
54
|
-
return 'Several people are typing…';
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Derive the announced text for the `aria-live` region. Same as the visible
|
|
58
|
-
* label but WITHOUT the trailing ellipsis (screen readers add their own pause).
|
|
59
|
-
*/
|
|
60
|
-
export function deriveAnnouncedLabel(participants) {
|
|
61
|
-
const count = participants.length;
|
|
62
|
-
if (count === 0)
|
|
63
|
-
return '';
|
|
64
|
-
if (count === 1)
|
|
65
|
-
return `${participants[0].name} is typing`;
|
|
66
|
-
if (count === 2)
|
|
67
|
-
return `${participants[0].name} and ${participants[1].name} are typing`;
|
|
68
|
-
if (count <= 4)
|
|
69
|
-
return `${count} people are typing`;
|
|
70
|
-
return 'Several people are typing';
|
|
71
|
-
}
|
|
72
|
-
export function useChatTypingIndicator(options) {
|
|
73
|
-
// Adapter typing state: true = adapter says someone is typing
|
|
74
|
-
let adapterIsTyping = $state(false);
|
|
75
|
-
// Debounced announced label (for aria-live). Starts empty and updates after a
|
|
76
|
-
// 400 ms delay when participants appear, or immediately when they all clear.
|
|
77
|
-
let announcedLabel = $state('');
|
|
78
|
-
let debounceHandle;
|
|
79
|
-
// Merged participant list. When the consumer passes a DEFINED `typingParticipants`
|
|
80
|
-
// prop (even an empty array), it is AUTHORITATIVE — the adapter's synthetic
|
|
81
|
-
// participant is ignored so a controlled consumer can clear stale typing state
|
|
82
|
-
// with `typingParticipants={[]}`. The adapter path only contributes when the
|
|
83
|
-
// prop is omitted (undefined).
|
|
84
|
-
const mergedParticipants = $derived.by(() => {
|
|
85
|
-
const propParticipants = options.getTypingParticipants();
|
|
86
|
-
if (propParticipants !== undefined)
|
|
87
|
-
return propParticipants;
|
|
88
|
-
if (!adapterIsTyping)
|
|
89
|
-
return [];
|
|
90
|
-
return [{ id: ADAPTER_PARTICIPANT_ID, name: ADAPTER_PARTICIPANT_NAME }];
|
|
91
|
-
});
|
|
92
|
-
const typingLabel = $derived(deriveTypingLabel(mergedParticipants));
|
|
93
|
-
const participantCount = $derived(mergedParticipants.length);
|
|
94
|
-
// Extract the announcement text as a primitive $derived so the effect only
|
|
95
|
-
// re-runs when the *string value* changes — not when mergedParticipants produces
|
|
96
|
-
// a new array reference with the same count (e.g. participant-object churn at
|
|
97
|
-
// count >= 3 where the label is "3 people are typing"). This prevents spurious
|
|
98
|
-
// debounce restarts that would permanently delay the announcement.
|
|
99
|
-
const announcementText = $derived(deriveAnnouncedLabel(mergedParticipants));
|
|
100
|
-
// Reactively update the debounced announced label whenever typingLabel changes.
|
|
101
|
-
$effect(() => {
|
|
102
|
-
const current = typingLabel;
|
|
103
|
-
if (current === '') {
|
|
104
|
-
// Clear immediately so the live region is silenced as soon as typing stops.
|
|
105
|
-
clearTimeout(debounceHandle);
|
|
106
|
-
debounceHandle = undefined;
|
|
107
|
-
announcedLabel = '';
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Non-empty: debounce the announcement so very brief typing bursts are not
|
|
111
|
-
// announced to screen readers.
|
|
112
|
-
if (debounceHandle !== undefined) {
|
|
113
|
-
clearTimeout(debounceHandle);
|
|
114
|
-
}
|
|
115
|
-
// Read the stable primitive $derived (not mergedParticipants) — avoids
|
|
116
|
-
// re-triggering the effect on participant-object churn at stable counts.
|
|
117
|
-
const text = announcementText;
|
|
118
|
-
debounceHandle = setTimeout(() => {
|
|
119
|
-
debounceHandle = undefined;
|
|
120
|
-
announcedLabel = text;
|
|
121
|
-
}, DEBOUNCE_MS);
|
|
122
|
-
return () => {
|
|
123
|
-
clearTimeout(debounceHandle);
|
|
124
|
-
debounceHandle = undefined;
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
function handleAdapterTypingChange(isTyping) {
|
|
128
|
-
adapterIsTyping = isTyping;
|
|
129
|
-
}
|
|
130
|
-
function reset() {
|
|
131
|
-
// Clear ONLY the adapter-derived flag. The announced label and its debounce
|
|
132
|
-
// are owned by the $effect, which is keyed on `typingLabel`: clearing
|
|
133
|
-
// `adapterIsTyping` recomputes `mergedParticipants` → `typingLabel`, and the
|
|
134
|
-
// effect then clears or preserves the announcement as appropriate. Forcibly
|
|
135
|
-
// clearing `announcedLabel`/the timer here would wipe a still-active
|
|
136
|
-
// PROP-driven announcement (the effect would not re-run because `typingLabel`
|
|
137
|
-
// is unchanged) — violating the prop-remains-authoritative invariant.
|
|
138
|
-
adapterIsTyping = false;
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
get typingLabel() {
|
|
142
|
-
return typingLabel;
|
|
143
|
-
},
|
|
144
|
-
get announcedLabel() {
|
|
145
|
-
return announcedLabel;
|
|
146
|
-
},
|
|
147
|
-
get participantCount() {
|
|
148
|
-
return participantCount;
|
|
149
|
-
},
|
|
150
|
-
handleAdapterTypingChange,
|
|
151
|
-
reset,
|
|
152
|
-
};
|
|
153
|
-
}
|