@swisper.ai/web-chat-ui 0.0.2 → 0.0.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/README.md +9 -12
- package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
- package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
- package/dist/components/chat-card/chat-card.d.ts +1 -0
- package/dist/components/chat-card/chat-card.d.ts.map +1 -1
- package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
- package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
- package/dist/components/chat-card/contexts.d.ts +2 -0
- package/dist/components/chat-card/contexts.d.ts.map +1 -1
- package/dist/components/chat-card/hooks.d.ts +1 -0
- package/dist/components/chat-card/hooks.d.ts.map +1 -1
- package/dist/components/chat-card/types.d.ts +3 -0
- package/dist/components/chat-card/types.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
- package/dist/components/chat-container/chat-container.d.ts.map +1 -1
- package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
- package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
- package/dist/components/chat-input/chat-input.d.ts +30 -2
- package/dist/components/chat-input/chat-input.d.ts.map +1 -1
- package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
- package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +4 -1
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -1
- package/dist/components/chat-input/plugins/value-plugin.d.ts +4 -1
- package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list-item.d.ts +6 -0
- package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list-items.d.ts +12 -1
- package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list.d.ts +36 -2
- package/dist/components/chat-list/chat-list.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
- package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
- package/dist/components/chat-message/chat-message.d.ts +12 -1
- package/dist/components/chat-message/chat-message.d.ts.map +1 -1
- package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
- package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
- package/dist/components/chat-message/index.d.ts +1 -1
- package/dist/components/chat-message/index.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
- package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/index.d.ts +1 -1
- package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
- package/dist/components/chat-messages/chat-messages.d.ts +34 -2
- package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
- package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
- package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
- package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
- package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
- package/dist/components/chat-reply/chat-reply.d.ts +11 -0
- package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
- package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
- package/dist/components/chat-reply/index.d.ts +1 -1
- package/dist/components/chat-reply/index.d.ts.map +1 -1
- package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
- package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
- package/dist/components/chat-suggestion/index.d.ts +2 -1
- package/dist/components/chat-suggestion/index.d.ts.map +1 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
- package/dist/components/chat-thread/chat-thread.d.ts +17 -2
- package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
- package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
- package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
- package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +4 -1
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts +4 -1
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
- package/dist/components/rich-text-area/styled.d.ts +6 -2
- package/dist/components/rich-text-area/styled.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/index.d.ts +5 -5
- package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
- package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
- package/dist/components/topmenu/index.d.ts +2 -0
- package/dist/components/topmenu/index.d.ts.map +1 -0
- package/dist/components/topmenu/topmenu.d.ts +22 -0
- package/dist/components/topmenu/topmenu.d.ts.map +1 -0
- package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
- package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
- package/dist/docs/agent.stories.d.ts.map +1 -1
- package/dist/docs/chat-panel.d.ts +7 -5
- package/dist/docs/chat-panel.d.ts.map +1 -1
- package/dist/docs/chatbot-panel.d.ts.map +1 -1
- package/dist/docs/chatbot.stories.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +1801 -1806
- package/dist/index.es.js.map +1 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
- package/package.json +16 -10
- package/src/__storybook__/parent-block.tsx +21 -0
- package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
- package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
- package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
- package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
- package/src/components/canvas-shell/__stories__/types.ts +47 -0
- package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
- package/src/components/canvas-shell/canvas-shell.json +24 -0
- package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
- package/src/components/canvas-shell/canvas-shell.tsx +44 -17
- package/src/components/chat-card/__stories__/fixtures.ts +119 -0
- package/src/components/chat-card/__stories__/types.ts +44 -0
- package/src/components/chat-card/chat-card.json +67 -3
- package/src/components/chat-card/chat-card.stories.tsx +872 -148
- package/src/components/chat-card/chat-card.tsx +2 -0
- package/src/components/chat-card/components/chat-card-body.tsx +12 -0
- package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
- package/src/components/chat-card/components/chat-card-form.tsx +21 -2
- package/src/components/chat-card/components/chat-card-header.tsx +39 -2
- package/src/components/chat-card/contexts.tsx +2 -0
- package/src/components/chat-card/hooks.ts +1 -0
- package/src/components/chat-card/types.ts +3 -0
- package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
- package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
- package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
- package/src/components/chat-card-container/__stories__/types.ts +16 -0
- package/src/components/chat-card-container/chat-card-container.json +7 -0
- package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
- package/src/components/chat-card-container/chat-card-container.tsx +5 -0
- package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
- package/src/components/chat-container/__stories__/fixtures.ts +27 -0
- package/src/components/chat-container/__stories__/measure.ts +22 -0
- package/src/components/chat-container/__stories__/types.ts +7 -0
- package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
- package/src/components/chat-container/chat-container.json +9 -1
- package/src/components/chat-container/chat-container.stories.tsx +538 -106
- package/src/components/chat-container/chat-container.tsx +3 -0
- package/src/components/chat-input/__stories__/fixtures.ts +31 -0
- package/src/components/chat-input/__tests__/chat-input.spec.tsx +100 -0
- package/src/components/chat-input/chat-input.json +11 -2
- package/src/components/chat-input/chat-input.stories.tsx +660 -197
- package/src/components/chat-input/chat-input.tsx +39 -5
- package/src/components/chat-input/plugins/controlled-value-plugin.tsx +16 -3
- package/src/components/chat-input/plugins/value-plugin.tsx +19 -4
- package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
- package/src/components/chat-list/__stories__/fixtures.ts +94 -0
- package/src/components/chat-list/__stories__/types.ts +13 -0
- package/src/components/chat-list/chat-list-item.tsx +6 -0
- package/src/components/chat-list/chat-list-items.tsx +16 -0
- package/src/components/chat-list/chat-list.json +24 -2
- package/src/components/chat-list/chat-list.stories.tsx +631 -215
- package/src/components/chat-list/chat-list.tsx +51 -4
- package/src/components/chat-message/__stories__/fixtures.ts +53 -0
- package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
- package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
- package/src/components/chat-message/chat-message.json +10 -1
- package/src/components/chat-message/chat-message.stories.tsx +282 -20
- package/src/components/chat-message/chat-message.tsx +16 -1
- package/src/components/chat-message/index.ts +8 -1
- package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
- package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
- package/src/components/chat-message-attachment-card/index.ts +6 -0
- package/src/components/chat-message-attachment-card/utils.ts +1 -0
- package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
- package/src/components/chat-message-response/chat-message-response.json +5 -0
- package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
- package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
- package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
- package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
- package/src/components/chat-message-toolbar/index.ts +4 -0
- package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
- package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
- package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
- package/src/components/chat-messages/__stories__/types.ts +5 -0
- package/src/components/chat-messages/chat-messages.json +30 -12
- package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
- package/src/components/chat-messages/chat-messages.tsx +46 -3
- package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
- package/src/components/chat-notification-card/__stories__/types.ts +13 -0
- package/src/components/chat-notification-card/chat-notification-card.json +52 -2
- package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
- package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
- package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
- package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
- package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
- package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
- package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
- package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
- package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
- package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
- package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
- package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
- package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
- package/src/components/chat-reply/chat-reply.json +10 -0
- package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
- package/src/components/chat-reply/chat-reply.tsx +15 -0
- package/src/components/chat-reply/index.ts +10 -1
- package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
- package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
- package/src/components/chat-suggestion/chat-suggestion.json +62 -20
- package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
- package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
- package/src/components/chat-suggestion/index.ts +9 -0
- package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
- package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
- package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
- package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
- package/src/components/chat-thread/__stories__/snippets.ts +129 -0
- package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
- package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
- package/src/components/chat-thread/__stories__/types.ts +12 -0
- package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
- package/src/components/chat-thread/chat-thread.json +23 -3
- package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
- package/src/components/chat-thread/chat-thread.tsx +64 -16
- package/src/components/index.ts +1 -3
- package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
- package/src/components/markdown-viewer/markdown-viewer.json +7 -1
- package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
- package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
- package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
- package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +114 -0
- package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +20 -3
- package/src/components/rich-text-area/plugins/value-plugin.tsx +16 -3
- package/src/components/rich-text-area/rich-text-area.json +7 -4
- package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
- package/src/components/rich-text-area/rich-text-area.tsx +27 -4
- package/src/components/rich-text-area/styled.tsx +11 -5
- package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
- package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
- package/src/components/rich-text-field/components/index.ts +8 -5
- package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
- package/src/components/rich-text-field/rich-text-field.json +3 -1
- package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
- package/src/components/rich-text-field/rich-text-field.tsx +23 -0
- package/src/components/topmenu/index.ts +1 -0
- package/src/components/topmenu/topmenu.json +107 -0
- package/src/components/topmenu/topmenu.stories.tsx +334 -0
- package/src/components/topmenu/topmenu.tsx +71 -0
- package/src/docs/agent.stories.tsx +16 -16
- package/src/docs/chat-panel.tsx +37 -32
- package/src/docs/chatbot-panel.tsx +11 -2
- package/src/docs/chatbot.mdx +17 -12
- package/src/docs/chatbot.stories.tsx +7 -8
- package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
- package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
- package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
- package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
- package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
- package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
- package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
- package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
- package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
- package/dist/components/card-item-picker/index.d.ts +0 -9
- package/dist/components/card-item-picker/index.d.ts.map +0 -1
- package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
- package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
- package/dist/components/chat-message-history/index.d.ts +0 -2
- package/dist/components/chat-message-history/index.d.ts.map +0 -1
- package/dist/components/spinner/index.d.ts +0 -2
- package/dist/components/spinner/index.d.ts.map +0 -1
- package/dist/components/spinner/spinner.d.ts +0 -9
- package/dist/components/spinner/spinner.d.ts.map +0 -1
- package/dist/components/spinner/spinner.stories.d.ts +0 -8
- package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
- package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
- package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
- package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
- package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
- package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
- package/src/components/card-item-picker/card-item-picker.json +0 -147
- package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
- package/src/components/card-item-picker/index.ts +0 -24
- package/src/components/chat-message-history/chat-message-history.json +0 -99
- package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
- package/src/components/chat-message-history/chat-message-history.tsx +0 -277
- package/src/components/chat-message-history/index.ts +0 -13
- package/src/components/spinner/index.ts +0 -1
- package/src/components/spinner/spinner.json +0 -73
- package/src/components/spinner/spinner.stories.tsx +0 -41
- package/src/components/spinner/spinner.tsx +0 -32
|
@@ -7,7 +7,7 @@ import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
|
7
7
|
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
8
8
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
9
9
|
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
10
|
-
import { createContext, forwardRef, useContext, useMemo, useState } from 'react';
|
|
10
|
+
import { createContext, forwardRef, useContext, useMemo, useRef, useState } from 'react';
|
|
11
11
|
import type { CSSProperties, ComponentPropsWithoutRef, KeyboardEvent, ReactNode } from 'react';
|
|
12
12
|
|
|
13
13
|
import { Typography } from '@swisper.ai/ui';
|
|
@@ -37,6 +37,10 @@ interface ChatInputContextValue {
|
|
|
37
37
|
|
|
38
38
|
const ChatInputContext = createContext<ChatInputContextValue>(null!);
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The editor state `ChatInput` tracks (`isFocused`, `hasValue`, `hasError`) and its setters.
|
|
42
|
+
* Throws when called outside a `ChatInput`.
|
|
43
|
+
*/
|
|
40
44
|
export function useChatInputContext() {
|
|
41
45
|
const context = useContext(ChatInputContext);
|
|
42
46
|
|
|
@@ -65,9 +69,14 @@ export const DEFAULT_CONFIG: ChatInputConfig = {
|
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
export interface ChatInputProps extends ComponentPropsWithoutRef<'div'> {
|
|
72
|
+
/** Lexical composer config, read once on mount. Override only to add nodes or retheme. */
|
|
68
73
|
initialConfig?: ChatInputConfig;
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Root of the composer: holds the Lexical editor and puts its state on the wrapper as
|
|
78
|
+
* `data-focused`, `data-empty` and `data-error`. Ships unstyled.
|
|
79
|
+
*/
|
|
71
80
|
export const ChatInput = forwardRef<HTMLDivElement, ChatInputProps>(function ChatInput(
|
|
72
81
|
{ className, children, initialConfig = DEFAULT_CONFIG, ...rest },
|
|
73
82
|
ref,
|
|
@@ -93,6 +102,7 @@ export const ChatInput = forwardRef<HTMLDivElement, ChatInputProps>(function Cha
|
|
|
93
102
|
<LexicalComposer initialConfig={initialConfig}>
|
|
94
103
|
<div
|
|
95
104
|
ref={ref}
|
|
105
|
+
data-slot="chat-input"
|
|
96
106
|
data-testid="chat-input"
|
|
97
107
|
data-focused={isFocused}
|
|
98
108
|
data-empty={!hasValue}
|
|
@@ -110,7 +120,7 @@ export const ChatInput = forwardRef<HTMLDivElement, ChatInputProps>(function Cha
|
|
|
110
120
|
|
|
111
121
|
ChatInput.displayName = 'ChatInput';
|
|
112
122
|
|
|
113
|
-
export
|
|
123
|
+
export interface ChatInputPlaceholderProps extends ComponentPropsWithoutRef<'span'> {}
|
|
114
124
|
|
|
115
125
|
export const ChatInputPlaceholder = forwardRef<HTMLSpanElement, ChatInputPlaceholderProps>(
|
|
116
126
|
function ChatInputPlaceholder({ className, children, ...rest }, ref) {
|
|
@@ -124,9 +134,11 @@ export const ChatInputPlaceholder = forwardRef<HTMLSpanElement, ChatInputPlaceho
|
|
|
124
134
|
'text-text-tertiary',
|
|
125
135
|
className,
|
|
126
136
|
)}
|
|
137
|
+
asChild
|
|
127
138
|
{...rest}
|
|
128
139
|
>
|
|
129
|
-
{
|
|
140
|
+
{/* Typography stamps its own data-slot unless it renders as its child. */}
|
|
141
|
+
<p data-slot="chat-input-placeholder">{children}</p>
|
|
130
142
|
</Typography>
|
|
131
143
|
);
|
|
132
144
|
},
|
|
@@ -135,19 +147,37 @@ export const ChatInputPlaceholder = forwardRef<HTMLSpanElement, ChatInputPlaceho
|
|
|
135
147
|
ChatInputPlaceholder.displayName = 'ChatInputPlaceholder';
|
|
136
148
|
|
|
137
149
|
export interface ChatInputTextareaProps {
|
|
150
|
+
/** Classes for the editable element (`data-slot="chat-input-editable"`), not its wrapper. */
|
|
138
151
|
className?: string;
|
|
152
|
+
/** Inline styles for the wrapper around the editable element. */
|
|
139
153
|
style?: CSSProperties | undefined;
|
|
154
|
+
/** Classes for the placeholder (`data-slot="chat-input-placeholder"`). */
|
|
140
155
|
placeholderClassName?: string;
|
|
156
|
+
/** Shown while the editor is empty; also the editable's `aria-placeholder`. */
|
|
141
157
|
placeholder?: string;
|
|
158
|
+
/** Custom Lexical plugins; rendered inside the composer, after the built-in ones. */
|
|
142
159
|
children?: ReactNode;
|
|
160
|
+
/**
|
|
161
|
+
* Content as Markdown. When it differs from the editor's, it replaces the content; a late
|
|
162
|
+
* render of a value `onChange` already emitted is ignored.
|
|
163
|
+
*/
|
|
143
164
|
value?: string;
|
|
165
|
+
/** Focuses the editor on mount, caret at the end. Skipped when disabled or read-only. */
|
|
144
166
|
autoFocus?: boolean;
|
|
167
|
+
/** Blocks editing and selection and dims the wrapper (`data-disabled`). */
|
|
145
168
|
isDisabled?: boolean;
|
|
169
|
+
/** Blocks editing but keeps the text selectable (`data-readonly`). */
|
|
146
170
|
isReadOnly?: boolean;
|
|
171
|
+
/** Called with the content as Markdown on every edit. */
|
|
147
172
|
onChange?: (value: string) => void;
|
|
173
|
+
/** Key handler on the editable element; implement send-on-Enter here. */
|
|
148
174
|
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
149
175
|
}
|
|
150
176
|
|
|
177
|
+
/**
|
|
178
|
+
* The editable area of a `ChatInput`. Its value is a Markdown string; paste inserts plain
|
|
179
|
+
* text. Must be rendered inside a `ChatInput`.
|
|
180
|
+
*/
|
|
151
181
|
export const ChatInputTextarea = forwardRef<HTMLDivElement, ChatInputTextareaProps>(
|
|
152
182
|
function ChatInputTextarea(
|
|
153
183
|
{
|
|
@@ -168,11 +198,14 @@ export const ChatInputTextarea = forwardRef<HTMLDivElement, ChatInputTextareaPro
|
|
|
168
198
|
) {
|
|
169
199
|
const { setHasValue, setIsFocused } = useChatInputContext();
|
|
170
200
|
const isReadOnlyState = isReadOnly && !isDisabled;
|
|
201
|
+
const emittedValuesRef = useRef<string[]>([]);
|
|
171
202
|
|
|
172
203
|
return (
|
|
173
204
|
<div
|
|
205
|
+
data-slot="chat-input-textarea"
|
|
174
206
|
data-testid="chat-input-textarea"
|
|
175
207
|
data-disabled={isDisabled}
|
|
208
|
+
data-readonly={isReadOnlyState}
|
|
176
209
|
aria-disabled={isDisabled}
|
|
177
210
|
aria-readonly={isReadOnlyState}
|
|
178
211
|
className={cn(
|
|
@@ -188,6 +221,7 @@ export const ChatInputTextarea = forwardRef<HTMLDivElement, ChatInputTextareaPro
|
|
|
188
221
|
contentEditable={
|
|
189
222
|
<ContentEditable
|
|
190
223
|
ref={ref}
|
|
224
|
+
data-slot="chat-input-editable"
|
|
191
225
|
className={cn('min-h-[26px]!', 'overflow-y-auto text-wrap outline-none', className)}
|
|
192
226
|
aria-label="Chat input"
|
|
193
227
|
aria-placeholder={placeholder}
|
|
@@ -204,8 +238,8 @@ export const ChatInputTextarea = forwardRef<HTMLDivElement, ChatInputTextareaPro
|
|
|
204
238
|
|
|
205
239
|
<HistoryPlugin />
|
|
206
240
|
<DisabledPlugin isDisabled={isDisabled} isReadOnly={isReadOnly} />
|
|
207
|
-
<ControlledValuePlugin value={value} />
|
|
208
|
-
<ValuePlugin onChange={onChange} />
|
|
241
|
+
<ControlledValuePlugin value={value} emittedValuesRef={emittedValuesRef} />
|
|
242
|
+
<ValuePlugin onChange={onChange} emittedValuesRef={emittedValuesRef} />
|
|
209
243
|
<MarkdownPlainPastePlugin />
|
|
210
244
|
<HasValuePlugin onHasValueChange={setHasValue} />
|
|
211
245
|
<FocusPlugin onFocusChange={setIsFocused} />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $convertFromMarkdownString, $convertToMarkdownString } from '@lexical/markdown';
|
|
2
2
|
import { $addUpdateTag, SKIP_DOM_SELECTION_TAG } from 'lexical';
|
|
3
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { type MutableRefObject, useEffect, useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
import { EXPORT_TRANSFORMERS, IMPORT_TRANSFORMERS } from '../transformers';
|
|
6
6
|
|
|
@@ -9,9 +9,11 @@ import { $setSelectionToEnd } from './utils';
|
|
|
9
9
|
|
|
10
10
|
interface ControlledValuePluginProps {
|
|
11
11
|
value?: string;
|
|
12
|
+
/** The values `ValuePlugin` gave to `onChange` that the parent has not rendered back yet. */
|
|
13
|
+
emittedValuesRef?: MutableRefObject<string[]>;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export function ControlledValuePlugin({ value }: ControlledValuePluginProps) {
|
|
16
|
+
export function ControlledValuePlugin({ value, emittedValuesRef }: ControlledValuePluginProps) {
|
|
15
17
|
const editor = useChatInputEditor();
|
|
16
18
|
const previousValueRef = useRef<string | undefined>();
|
|
17
19
|
|
|
@@ -26,6 +28,17 @@ export function ControlledValuePlugin({ value }: ControlledValuePluginProps) {
|
|
|
26
28
|
|
|
27
29
|
previousValueRef.current = value;
|
|
28
30
|
|
|
31
|
+
// The parent renders back each value `onChange` gave it, and that render can land after later
|
|
32
|
+
// keystrokes. Such a value is an echo of an older edit, not a change to apply: applying it
|
|
33
|
+
// would drop what was typed since.
|
|
34
|
+
if (emittedValuesRef && value !== undefined) {
|
|
35
|
+
const echoIndex = emittedValuesRef.current.lastIndexOf(value);
|
|
36
|
+
emittedValuesRef.current.splice(0, echoIndex === -1 ? Infinity : echoIndex + 1);
|
|
37
|
+
if (echoIndex !== -1) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
let currentValue = '';
|
|
30
43
|
editor.getEditorState().read(() => {
|
|
31
44
|
currentValue = $convertToMarkdownString(EXPORT_TRANSFORMERS);
|
|
@@ -41,7 +54,7 @@ export function ControlledValuePlugin({ value }: ControlledValuePluginProps) {
|
|
|
41
54
|
{ discrete: true },
|
|
42
55
|
);
|
|
43
56
|
}
|
|
44
|
-
}, [editor, value]);
|
|
57
|
+
}, [editor, value, emittedValuesRef]);
|
|
45
58
|
|
|
46
59
|
return null;
|
|
47
60
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { $convertToMarkdownString } from '@lexical/markdown';
|
|
2
2
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
3
3
|
import type { EditorState, LexicalEditor } from 'lexical';
|
|
4
|
-
import { useCallback } from 'react';
|
|
4
|
+
import { type MutableRefObject, useCallback } from 'react';
|
|
5
5
|
|
|
6
6
|
import { EXPORT_TRANSFORMERS } from '../transformers';
|
|
7
7
|
|
|
8
|
+
/** How many emitted values to remember; a parent that never echoes them back must not grow the list. */
|
|
9
|
+
const MAX_EMITTED_VALUES = 50;
|
|
10
|
+
|
|
8
11
|
interface ValuePluginProps {
|
|
9
12
|
onChange?: (value: string) => void;
|
|
13
|
+
/** Receives every value given to `onChange`, so `ControlledValuePlugin` can tell an echo of one. */
|
|
14
|
+
emittedValuesRef?: MutableRefObject<string[]>;
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
export function ValuePlugin({ onChange }: ValuePluginProps) {
|
|
17
|
+
export function ValuePlugin({ onChange, emittedValuesRef }: ValuePluginProps) {
|
|
13
18
|
const handleChange = useCallback(
|
|
14
19
|
(editorState: EditorState, _editor: LexicalEditor, tags: Set<string>) => {
|
|
15
20
|
if (tags.has('focus')) {
|
|
@@ -22,13 +27,23 @@ export function ValuePlugin({ onChange }: ValuePluginProps) {
|
|
|
22
27
|
|
|
23
28
|
try {
|
|
24
29
|
editorState.read(() => {
|
|
25
|
-
|
|
30
|
+
const value = $convertToMarkdownString(EXPORT_TRANSFORMERS);
|
|
31
|
+
|
|
32
|
+
if (emittedValuesRef) {
|
|
33
|
+
emittedValuesRef.current.push(value);
|
|
34
|
+
emittedValuesRef.current.splice(
|
|
35
|
+
0,
|
|
36
|
+
emittedValuesRef.current.length - MAX_EMITTED_VALUES,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onChange(value);
|
|
26
41
|
});
|
|
27
42
|
} catch (error) {
|
|
28
43
|
console.error('ValuePlugin error:', error);
|
|
29
44
|
}
|
|
30
45
|
},
|
|
31
|
-
[onChange],
|
|
46
|
+
[onChange, emittedValuesRef],
|
|
32
47
|
);
|
|
33
48
|
|
|
34
49
|
return <OnChangePlugin onChange={handleChange} />;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Typography } from '@swisper.ai/ui';
|
|
2
|
+
|
|
3
|
+
import { ChatListItem } from '../chat-list-item';
|
|
4
|
+
|
|
5
|
+
import type { Chat } from './types';
|
|
6
|
+
|
|
7
|
+
export interface ChatRowProps {
|
|
8
|
+
chat: Chat;
|
|
9
|
+
isSelected: boolean;
|
|
10
|
+
onOpen: (chatId: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** One row of the list: a link to the chat with its title, when it was last updated, and a preview. */
|
|
14
|
+
export function ChatRow({ chat, isSelected, onOpen }: ChatRowProps) {
|
|
15
|
+
return (
|
|
16
|
+
<ChatListItem isSelected={isSelected} asChild>
|
|
17
|
+
<a
|
|
18
|
+
href={`/chat/${chat.chatId}`}
|
|
19
|
+
aria-current={isSelected ? 'page' : undefined}
|
|
20
|
+
className="flex min-w-0 flex-col gap-4 rounded-sm px-12 py-8 hover:bg-secondary-states-hover focus-visible:ring-2 focus-visible:ring-primary-focus-visible focus-visible:ring-inset data-[selected=true]:bg-menuitem-background-active-level1"
|
|
21
|
+
onClick={(event) => {
|
|
22
|
+
// A story has no router: the consumer keeps the open chat in state instead.
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
onOpen(chat.chatId);
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<span className="flex items-baseline gap-8">
|
|
28
|
+
<Typography variant="body-small-high" className="min-w-0 flex-1 truncate" asChild>
|
|
29
|
+
<span>{chat.title}</span>
|
|
30
|
+
</Typography>
|
|
31
|
+
<Typography variant="caption-md" className="shrink-0 text-text-secondary" asChild>
|
|
32
|
+
<span>{chat.updatedAt}</span>
|
|
33
|
+
</Typography>
|
|
34
|
+
</span>
|
|
35
|
+
<Typography variant="caption-md" className="truncate text-text-secondary" asChild>
|
|
36
|
+
<span>{chat.preview}</span>
|
|
37
|
+
</Typography>
|
|
38
|
+
</a>
|
|
39
|
+
</ChatListItem>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Chat, ChatPage } from './types';
|
|
2
|
+
|
|
3
|
+
/** Page size of the sidebar's chats request. */
|
|
4
|
+
export const CHAT_PAGE_SIZE = 12;
|
|
5
|
+
|
|
6
|
+
const CHAT_TOPICS: Pick<Chat, 'title' | 'preview'>[] = [
|
|
7
|
+
{ title: 'Train to Zurich on Friday', preview: 'The 07:32 from Bern gets you there by 08:28.' },
|
|
8
|
+
{ title: 'Reply to the landlord', preview: 'Here is a shorter version of the second paragraph.' },
|
|
9
|
+
{
|
|
10
|
+
title:
|
|
11
|
+
'Summary of the quarterly board deck, with the open questions for finance and the follow-ups for the product leads',
|
|
12
|
+
preview: 'Revenue is up 8% on the previous quarter; three questions are still open.',
|
|
13
|
+
},
|
|
14
|
+
{ title: 'Dinner ideas for six', preview: 'A lemon risotto works if two guests are vegetarian.' },
|
|
15
|
+
{ title: 'Lisbon trip in May', preview: 'I found four direct flights that leave after 17:00.' },
|
|
16
|
+
{
|
|
17
|
+
title: 'Unread email from this morning',
|
|
18
|
+
preview: 'You have 14 unread emails; 3 need a reply.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: 'Birthday present for Nora',
|
|
22
|
+
preview: 'A ceramics course is CHF 180 for four evenings.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: 'Notes from the kickoff call',
|
|
26
|
+
preview: 'Actions: send the timeline, book the workshop.',
|
|
27
|
+
},
|
|
28
|
+
{ title: 'Translate the offer to French', preview: 'Voici la traduction de la première page.' },
|
|
29
|
+
{ title: 'Health insurance comparison', preview: 'The second model saves about CHF 40 a month.' },
|
|
30
|
+
{
|
|
31
|
+
title: 'Weekend hike near Lucerne',
|
|
32
|
+
preview: 'The Rigi panorama trail takes about three hours.',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: 'Agenda for the team offsite',
|
|
36
|
+
preview: 'Day one opens with the roadmap review at 09:00.',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: 'Explain a rent reduction request',
|
|
40
|
+
preview: 'You can ask once the reference rate drops.',
|
|
41
|
+
},
|
|
42
|
+
{ title: 'Packing list for a ski week', preview: 'Added sunscreen, a spare pair of gloves and…' },
|
|
43
|
+
{
|
|
44
|
+
title: 'Rewrite my LinkedIn summary',
|
|
45
|
+
preview: 'This version leads with the migration project.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: 'Tax deductions for commuting',
|
|
49
|
+
preview: 'Public transport passes are deductible in full.',
|
|
50
|
+
},
|
|
51
|
+
{ title: 'Book a table for Thursday', preview: 'The 19:30 slot for four is still free.' },
|
|
52
|
+
{ title: 'Compare two phone plans', preview: 'The cheaper plan has no roaming outside Europe.' },
|
|
53
|
+
{
|
|
54
|
+
title: 'Parent-teacher meeting questions',
|
|
55
|
+
preview: 'Start with how the reading group is going.',
|
|
56
|
+
},
|
|
57
|
+
{ title: 'Fix the spreadsheet formula', preview: 'The range in column D stops one row short.' },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// The first five chats were updated today and show a time; older ones show day and month.
|
|
61
|
+
const TODAY_TIMES = ['16:42', '14:05', '11:30', '09:12', '08:47'];
|
|
62
|
+
const TODAY = new Date(2026, 9, 3);
|
|
63
|
+
|
|
64
|
+
function formatUpdatedAt(index: number) {
|
|
65
|
+
if (index < TODAY_TIMES.length) {
|
|
66
|
+
return TODAY_TIMES[index];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const date = new Date(TODAY);
|
|
70
|
+
date.setDate(TODAY.getDate() - (index - TODAY_TIMES.length + 1));
|
|
71
|
+
|
|
72
|
+
return `${String(date.getDate()).padStart(2, '0')}/${String(date.getMonth() + 1).padStart(2, '0')}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Every chat on the server, newest first: the topics repeat, the ids and dates do not. */
|
|
76
|
+
export const CHATS: Chat[] = Array.from({ length: CHAT_TOPICS.length * 4 }, (_, index) => ({
|
|
77
|
+
...CHAT_TOPICS[index % CHAT_TOPICS.length],
|
|
78
|
+
chatId: `chat_${String(index + 1).padStart(3, '0')}`,
|
|
79
|
+
updatedAt: formatUpdatedAt(index),
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
/** What the chats endpoint returns for one page. */
|
|
83
|
+
export function getChatPage(offset: number, limit: number): ChatPage {
|
|
84
|
+
return { chats: CHATS.slice(offset, offset + limit), count: CHATS.length };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const FIRST_CHAT_PAGE: ChatPage = getChatPage(0, CHAT_PAGE_SIZE);
|
|
88
|
+
|
|
89
|
+
/** A page small enough to leave room under it, so the load-more row is in view. */
|
|
90
|
+
export const SHORT_CHAT_PAGE: ChatPage = getChatPage(0, 6);
|
|
91
|
+
|
|
92
|
+
export const ALL_CHATS_PAGE: ChatPage = getChatPage(0, CHATS.length);
|
|
93
|
+
|
|
94
|
+
export const NO_CHATS_PAGE: ChatPage = { chats: [], count: 0 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** One conversation as the sidebar lists it. `updatedAt` is already formatted the way the row shows it. */
|
|
2
|
+
export interface Chat {
|
|
3
|
+
chatId: string;
|
|
4
|
+
title: string;
|
|
5
|
+
preview: string;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** One page of the chats endpoint: its rows and the number of chats on the server. */
|
|
10
|
+
export interface ChatPage {
|
|
11
|
+
chats: Chat[];
|
|
12
|
+
count: number;
|
|
13
|
+
}
|
|
@@ -5,10 +5,16 @@ import { cn } from '@swisper.ai/web-core';
|
|
|
5
5
|
|
|
6
6
|
export interface ChatListItemProps extends ComponentPropsWithoutRef<'div'> {
|
|
7
7
|
children?: ReactNode;
|
|
8
|
+
/** Merges the item's props onto its only child, e.g. a link or a button, without adding a `div`. */
|
|
8
9
|
asChild?: boolean;
|
|
10
|
+
/** Marks the open conversation: sets `data-selected` and `aria-selected`. */
|
|
9
11
|
isSelected?: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
/**
|
|
15
|
+
* One row's content, returned from the `ChatListItems` render function. It has no role, tab stop or
|
|
16
|
+
* look of its own: render it `asChild` over a link or button and style that from `data-selected`.
|
|
17
|
+
*/
|
|
12
18
|
export const ChatListItem = forwardRef<HTMLDivElement, ChatListItemProps>(function ChatListItem(
|
|
13
19
|
{ children, className, asChild = false, isSelected = false, ...rest },
|
|
14
20
|
ref,
|
|
@@ -9,18 +9,30 @@ import { useChatListContext } from './chat-list';
|
|
|
9
9
|
const LOAD_MORE_KEY = 'chat-list-load-more';
|
|
10
10
|
|
|
11
11
|
export interface ChatListItemsProps {
|
|
12
|
+
/** Render function called with each loaded row's index; return a `ChatListItem`. */
|
|
12
13
|
children: (index: number) => ReactNode;
|
|
13
14
|
className?: string;
|
|
15
|
+
/** Classes for the `ul` that holds the rows; merged after its defaults. */
|
|
14
16
|
listClassName?: string;
|
|
17
|
+
/** Classes for every `li`, the load-more row included; merged after its defaults. */
|
|
18
|
+
rowClassName?: string;
|
|
19
|
+
/** First guess of a row's height in pixels; rows are measured after they render. */
|
|
15
20
|
estimateSize?: number;
|
|
21
|
+
/** Rows rendered beyond the visible ones, above and below. */
|
|
16
22
|
overscan?: number;
|
|
23
|
+
/** Space between rows, in pixels. */
|
|
17
24
|
gap?: number;
|
|
18
25
|
}
|
|
19
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The scrolling, virtualised rows of a `ChatList`. While `hasMore` is true it appends one row with
|
|
29
|
+
* the `ChatListLoadMore` content and calls `onLoadMore` when that row comes into range.
|
|
30
|
+
*/
|
|
20
31
|
export const ChatListItems = memo(function ChatListItems({
|
|
21
32
|
children,
|
|
22
33
|
className,
|
|
23
34
|
listClassName,
|
|
35
|
+
rowClassName,
|
|
24
36
|
estimateSize = 54,
|
|
25
37
|
overscan = 6,
|
|
26
38
|
gap = 4,
|
|
@@ -104,6 +116,7 @@ export const ChatListItems = memo(function ChatListItems({
|
|
|
104
116
|
className={cn('min-h-0 flex-1', 'overflow-auto', className)}
|
|
105
117
|
>
|
|
106
118
|
<ul
|
|
119
|
+
data-slot="chat-list-items-list"
|
|
107
120
|
role="list"
|
|
108
121
|
aria-label="Chats"
|
|
109
122
|
className={cn(
|
|
@@ -121,11 +134,14 @@ export const ChatListItems = memo(function ChatListItems({
|
|
|
121
134
|
return (
|
|
122
135
|
<li
|
|
123
136
|
key={virtualItem.key}
|
|
137
|
+
data-slot="chat-list-items-row"
|
|
124
138
|
data-index={virtualItem.index}
|
|
139
|
+
data-load-more={isLoaderRow}
|
|
125
140
|
ref={virtualizer.measureElement}
|
|
126
141
|
role={isLoaderRow ? 'status' : 'listitem'}
|
|
127
142
|
aria-live={isLoaderRow ? 'polite' : undefined}
|
|
128
143
|
aria-busy={isLoaderRow ? isLoadingMore : undefined}
|
|
144
|
+
className={rowClassName}
|
|
129
145
|
style={{
|
|
130
146
|
position: 'absolute',
|
|
131
147
|
top: 0,
|
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
3
|
"component": "chat-list",
|
|
4
4
|
"purpose": "Virtualised, paginated list of the user's conversations for a navigation sidebar, with infinite loading and built-in slots for the first-page skeleton, the load-more row, the empty state and the error state.",
|
|
5
|
+
"anatomy": [
|
|
6
|
+
"import {",
|
|
7
|
+
" ChatList,",
|
|
8
|
+
" ChatListItems,",
|
|
9
|
+
" ChatListItem,",
|
|
10
|
+
" ChatListSkeleton,",
|
|
11
|
+
" ChatListLoadMore,",
|
|
12
|
+
" ChatListEmptyState,",
|
|
13
|
+
" ChatListError,",
|
|
14
|
+
"} from '@swisper.ai/web-chat-ui';",
|
|
15
|
+
"",
|
|
16
|
+
"<ChatList>",
|
|
17
|
+
" <ChatListItems>",
|
|
18
|
+
" <ChatListItem />",
|
|
19
|
+
" </ChatListItems>",
|
|
20
|
+
" <ChatListSkeleton />",
|
|
21
|
+
" <ChatListLoadMore />",
|
|
22
|
+
" <ChatListEmptyState />",
|
|
23
|
+
" <ChatListError />",
|
|
24
|
+
"</ChatList>"
|
|
25
|
+
],
|
|
5
26
|
"useWhen": [
|
|
6
27
|
"A sidebar or drawer lists past conversations to switch between",
|
|
7
28
|
"The list is long or paginated and loads more pages as the user scrolls",
|
|
@@ -47,14 +68,15 @@
|
|
|
47
68
|
"getItemKey returns a stable key per index (the chat id), so rows keep their identity as pages load",
|
|
48
69
|
"hasMore defaults to loadedCount < totalCount, and to false when totalCount is unknown; pass hasMore when the server only says whether another page exists",
|
|
49
70
|
"While hasMore is true, ChatListItems appends one extra row at the end holding the ChatListLoadMore content",
|
|
50
|
-
"onLoadMore fires when the last rendered row reaches the end of the loaded rows, hasMore is true and isLoadingMore is false; set isLoadingMore as soon as the request starts
|
|
71
|
+
"onLoadMore fires when the last rendered row reaches the end of the loaded rows, hasMore is true and isLoadingMore is false; set isLoadingMore as soon as the request starts, and make the handler ignore a call while a request is in flight, because it can fire again before isLoadingMore reaches the list",
|
|
51
72
|
"isLoading with no loaded rows shows ChatListSkeleton in place of the rows; ChatListSkeleton draws into a container that ChatListItems provides, so both must be rendered",
|
|
52
73
|
"ChatListSkeleton renders rows default Skeleton rows (title and preview) unless you pass your own children; rows past the list's height are clipped",
|
|
53
74
|
"ChatListEmptyState shows only when nothing is loaded, nothing is loading and there is no error",
|
|
54
75
|
"ChatListError shows only when hasError is true and no rows are loaded; a failed later page leaves the loaded rows on screen without an error",
|
|
55
76
|
"ChatListError renders children, or else the error's message, or \"An error occurred\"",
|
|
56
77
|
"ChatListLoadMore renders nothing in place; it registers its children as the content of the load-more row",
|
|
57
|
-
"Rows are measured after render, so items may vary in height; estimateSize is only the first guess, and gap is the space between rows"
|
|
78
|
+
"Rows are measured after render, so items may vary in height; estimateSize is only the first guess, and gap is the space between rows",
|
|
79
|
+
"Inner elements take their own class props, merged after the defaults: listClassName (the ul) and rowClassName (every li; the load-more row has data-load-more=true) on ChatListItems, rowClassName on ChatListSkeleton's default rows, messageClassName on ChatListError's default message"
|
|
58
80
|
]
|
|
59
81
|
},
|
|
60
82
|
"composition": {
|