@swisper.ai/web-chat-ui 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +251 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts +64 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts +26 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -0
- package/dist/components/canvas-shell/index.d.ts +2 -0
- package/dist/components/canvas-shell/index.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts +21 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts +24 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +28 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts +12 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts +19 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +1 -0
- package/dist/components/card-item-picker/index.d.ts +9 -0
- package/dist/components/card-item-picker/index.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.d.ts +4 -0
- package/dist/components/chat-card/chat-card.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.stories.d.ts +11 -0
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts +22 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts +20 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts +28 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts +36 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -0
- package/dist/components/chat-card/components/index.d.ts +5 -0
- package/dist/components/chat-card/components/index.d.ts.map +1 -0
- package/dist/components/chat-card/context.d.ts +13 -0
- package/dist/components/chat-card/context.d.ts.map +1 -0
- package/dist/components/chat-card/contexts.d.ts +16 -0
- package/dist/components/chat-card/contexts.d.ts.map +1 -0
- package/dist/components/chat-card/hooks.d.ts +13 -0
- package/dist/components/chat-card/hooks.d.ts.map +1 -0
- package/dist/components/chat-card/index.d.ts +6 -0
- package/dist/components/chat-card/index.d.ts.map +1 -0
- package/dist/components/chat-card/types.d.ts +21 -0
- package/dist/components/chat-card/types.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts +43 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts +17 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -0
- package/dist/components/chat-card-container/index.d.ts +3 -0
- package/dist/components/chat-card-container/index.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.d.ts +51 -0
- package/dist/components/chat-container/chat-container.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.stories.d.ts +21 -0
- package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -0
- package/dist/components/chat-container/index.d.ts +3 -0
- package/dist/components/chat-container/index.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.d.ts +35 -0
- package/dist/components/chat-input/chat-input.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.stories.d.ts +14 -0
- package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -0
- package/dist/components/chat-input/index.d.ts +3 -0
- package/dist/components/chat-input/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts +8 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts +7 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/hooks.d.ts +2 -0
- package/dist/components/chat-input/plugins/hooks.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/index.d.ts +8 -0
- package/dist/components/chat-input/plugins/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/utils.d.ts +4 -0
- package/dist/components/chat-input/plugins/utils.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/transformers.d.ts +3 -0
- package/dist/components/chat-input/transformers.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-item.d.ts +8 -0
- package/dist/components/chat-list/chat-list-item.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-items.d.ts +11 -0
- package/dist/components/chat-list/chat-list-items.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.d.ts +63 -0
- package/dist/components/chat-list/chat-list.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.stories.d.ts +13 -0
- package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -0
- package/dist/components/chat-list/index.d.ts +4 -0
- package/dist/components/chat-list/index.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.d.ts +17 -0
- package/dist/components/chat-message/chat-message.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.stories.d.ts +11 -0
- package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -0
- package/dist/components/chat-message/index.d.ts +2 -0
- package/dist/components/chat-message/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +9 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +30 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +11 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/index.d.ts +4 -0
- package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts +5 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts +48 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts +7 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +1 -0
- package/dist/components/chat-message-history/index.d.ts +2 -0
- package/dist/components/chat-message-history/index.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -0
- package/dist/components/chat-message-response/index.d.ts +2 -0
- package/dist/components/chat-message-response/index.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +25 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +7 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/index.d.ts +2 -0
- package/dist/components/chat-message-toolbar/index.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.d.ts +24 -0
- package/dist/components/chat-messages/chat-messages.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts +8 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -0
- package/dist/components/chat-messages/index.d.ts +2 -0
- package/dist/components/chat-messages/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts +114 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +10 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-card/index.d.ts +4 -0
- package/dist/components/chat-notification-card/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/types.d.ts +2 -0
- package/dist/components/chat-notification-card/types.d.ts.map +1 -0
- package/dist/components/chat-notification-card/utils.d.ts +3 -0
- package/dist/components/chat-notification-card/utils.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +12 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +8 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/index.d.ts +2 -0
- package/dist/components/chat-notification-popup/index.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts +17 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts +2 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +27 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +9 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/index.d.ts +3 -0
- package/dist/components/chat-prompt-box/index.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.d.ts +23 -0
- package/dist/components/chat-reply/chat-reply.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts +7 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -0
- package/dist/components/chat-reply/index.d.ts +2 -0
- package/dist/components/chat-reply/index.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts +37 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +9 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -0
- package/dist/components/chat-suggestion/index.d.ts +2 -0
- package/dist/components/chat-suggestion/index.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +47 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +10 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/index.d.ts +2 -0
- package/dist/components/chat-thinking-process/index.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.d.ts +78 -0
- package/dist/components/chat-thread/chat-thread.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts +14 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -0
- package/dist/components/chat-thread/index.d.ts +2 -0
- package/dist/components/chat-thread/index.d.ts.map +1 -0
- package/dist/components/deprecated-empty-state.d.ts +22 -0
- package/dist/components/deprecated-empty-state.d.ts.map +1 -0
- package/dist/components/index.d.ts +27 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/hooks.d.ts +9 -0
- package/dist/components/markdown-viewer/hooks.d.ts.map +1 -0
- package/dist/components/markdown-viewer/index.d.ts +3 -0
- package/dist/components/markdown-viewer/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts +10 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +9 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -0
- package/dist/components/markdown-viewer/types.d.ts +9 -0
- package/dist/components/markdown-viewer/types.d.ts.map +1 -0
- package/dist/components/markdown-viewer/utils.d.ts +3 -0
- package/dist/components/markdown-viewer/utils.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/index.d.ts +2 -0
- package/dist/components/new-chat-trigger/index.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts +8 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts.map +1 -0
- package/dist/components/rich-text-area/constants/index.d.ts +3 -0
- package/dist/components/rich-text-area/constants/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/hooks.d.ts +3 -0
- package/dist/components/rich-text-area/hooks.d.ts.map +1 -0
- package/dist/components/rich-text-area/html-config.d.ts +4 -0
- package/dist/components/rich-text-area/html-config.d.ts.map +1 -0
- package/dist/components/rich-text-area/index.d.ts +7 -0
- package/dist/components/rich-text-area/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts +18 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts +24 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts +10 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts +19 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts +12 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/index.d.ts +11 -0
- package/dist/components/rich-text-area/plugins/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts +20 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts +7 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -0
- package/dist/components/rich-text-area/styled.d.ts +3 -0
- package/dist/components/rich-text-area/styled.d.ts.map +1 -0
- package/dist/components/rich-text-area/transformers.d.ts +16 -0
- package/dist/components/rich-text-area/transformers.d.ts.map +1 -0
- package/dist/components/rich-text-area/types.d.ts +8 -0
- package/dist/components/rich-text-area/types.d.ts.map +1 -0
- package/dist/components/rich-text-area/utils/index.d.ts +6 -0
- package/dist/components/rich-text-area/utils/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +11 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/image-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/image-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/index.d.ts +14 -0
- package/dist/components/rich-text-field/components/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/link-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/link-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/size-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/size-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts +6 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/constants.d.ts +57 -0
- package/dist/components/rich-text-field/constants.d.ts.map +1 -0
- package/dist/components/rich-text-field/context.d.ts +26 -0
- package/dist/components/rich-text-field/context.d.ts.map +1 -0
- package/dist/components/rich-text-field/index.d.ts +3 -0
- package/dist/components/rich-text-field/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts +17 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts +10 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -0
- package/dist/components/rich-text-field/utils.d.ts +1759 -0
- package/dist/components/rich-text-field/utils.d.ts.map +1 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.d.ts.map +1 -0
- package/dist/components/spinner/spinner.d.ts +9 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -0
- package/dist/components/spinner/spinner.stories.d.ts +8 -0
- package/dist/components/spinner/spinner.stories.d.ts.map +1 -0
- package/dist/contexts/chat-context/chat-context.d.ts +20 -0
- package/dist/contexts/chat-context/chat-context.d.ts.map +1 -0
- package/dist/contexts/chat-context/index.d.ts +2 -0
- package/dist/contexts/chat-context/index.d.ts.map +1 -0
- package/dist/contexts/chat-context/utils.d.ts +3 -0
- package/dist/contexts/chat-context/utils.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts +20 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/index.d.ts +2 -0
- package/dist/contexts/chat-conversation-context/index.d.ts.map +1 -0
- package/dist/contexts/index.d.ts +3 -0
- package/dist/contexts/index.d.ts.map +1 -0
- package/dist/docs/agent.stories.d.ts +41 -0
- package/dist/docs/agent.stories.d.ts.map +1 -0
- package/dist/docs/chat-panel.d.ts +33 -0
- package/dist/docs/chat-panel.d.ts.map +1 -0
- package/dist/docs/chatbot-panel.d.ts +20 -0
- package/dist/docs/chatbot-panel.d.ts.map +1 -0
- package/dist/docs/chatbot.stories.d.ts +11 -0
- package/dist/docs/chatbot.stories.d.ts.map +1 -0
- package/dist/domain/actions/constants.d.ts +2 -0
- package/dist/domain/actions/constants.d.ts.map +1 -0
- package/dist/domain/actions/hooks/index.d.ts +3 -0
- package/dist/domain/actions/hooks/index.d.ts.map +1 -0
- package/dist/domain/actions/index.d.ts +5 -0
- package/dist/domain/actions/index.d.ts.map +1 -0
- package/dist/domain/actions/types.d.ts +7 -0
- package/dist/domain/actions/types.d.ts.map +1 -0
- package/dist/domain/actions/utils/index.d.ts +11 -0
- package/dist/domain/actions/utils/index.d.ts.map +1 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts +6 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts.map +1 -0
- package/dist/hooks/use-chat-stream-message.d.ts +42 -0
- package/dist/hooks/use-chat-stream-message.d.ts.map +1 -0
- package/dist/hooks/use-current-chat-id.d.ts +2 -0
- package/dist/hooks/use-current-chat-id.d.ts.map +1 -0
- package/dist/hooks/use-is-current-chat-new.d.ts +2 -0
- package/dist/hooks/use-is-current-chat-new.d.ts.map +1 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts +9 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts.map +1 -0
- package/dist/hooks/use-on-chat-changed.d.ts +9 -0
- package/dist/hooks/use-on-chat-changed.d.ts.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +4404 -0
- package/dist/index.es.js.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +95 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +24 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts +3 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +84 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +45 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +37 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +81 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts +5 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +31 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +12 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +19 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +35 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts +4 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/index.d.ts +4 -0
- package/dist/layouts/index.d.ts.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/use-streaming-markdown.d.ts +18 -0
- package/dist/utils/use-streaming-markdown.d.ts.map +1 -0
- package/package.json +155 -0
- package/src/__tests__/setup.ts +5 -0
- package/src/components/canvas-shell/canvas-shell.json +126 -0
- package/src/components/canvas-shell/canvas-shell.stories.tsx +194 -0
- package/src/components/canvas-shell/canvas-shell.test.tsx +205 -0
- package/src/components/canvas-shell/canvas-shell.tsx +250 -0
- package/src/components/canvas-shell/index.ts +19 -0
- package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +279 -0
- package/src/components/card-item-picker/card-item-picker-context.tsx +44 -0
- package/src/components/card-item-picker/card-item-picker-list.tsx +95 -0
- package/src/components/card-item-picker/card-item-picker-row-parts.tsx +96 -0
- package/src/components/card-item-picker/card-item-picker-row.tsx +109 -0
- package/src/components/card-item-picker/card-item-picker.json +147 -0
- package/src/components/card-item-picker/card-item-picker.stories.tsx +158 -0
- package/src/components/card-item-picker/index.ts +24 -0
- package/src/components/chat-card/__tests__/chat-card.spec.tsx +118 -0
- package/src/components/chat-card/chat-card.json +162 -0
- package/src/components/chat-card/chat-card.stories.tsx +349 -0
- package/src/components/chat-card/chat-card.tsx +106 -0
- package/src/components/chat-card/components/chat-card-body.tsx +115 -0
- package/src/components/chat-card/components/chat-card-footer.tsx +95 -0
- package/src/components/chat-card/components/chat-card-form.tsx +120 -0
- package/src/components/chat-card/components/chat-card-header.tsx +240 -0
- package/src/components/chat-card/components/index.ts +4 -0
- package/src/components/chat-card/context.tsx +34 -0
- package/src/components/chat-card/contexts.tsx +42 -0
- package/src/components/chat-card/hooks.ts +51 -0
- package/src/components/chat-card/index.ts +5 -0
- package/src/components/chat-card/types.ts +23 -0
- package/src/components/chat-card-container/chat-card-container.json +84 -0
- package/src/components/chat-card-container/chat-card-container.stories.tsx +149 -0
- package/src/components/chat-card-container/chat-card-container.tsx +75 -0
- package/src/components/chat-card-container/index.ts +2 -0
- package/src/components/chat-container/chat-container.json +93 -0
- package/src/components/chat-container/chat-container.stories.tsx +179 -0
- package/src/components/chat-container/chat-container.tsx +231 -0
- package/src/components/chat-container/index.ts +2 -0
- package/src/components/chat-input/chat-input.json +106 -0
- package/src/components/chat-input/chat-input.stories.tsx +291 -0
- package/src/components/chat-input/chat-input.tsx +220 -0
- package/src/components/chat-input/index.ts +2 -0
- package/src/components/chat-input/plugins/auto-focus-plugin.tsx +43 -0
- package/src/components/chat-input/plugins/controlled-value-plugin.tsx +47 -0
- package/src/components/chat-input/plugins/disabled-plugin.tsx +18 -0
- package/src/components/chat-input/plugins/focus-plugin.tsx +44 -0
- package/src/components/chat-input/plugins/has-value-plugin.tsx +51 -0
- package/src/components/chat-input/plugins/hooks.ts +7 -0
- package/src/components/chat-input/plugins/index.ts +7 -0
- package/src/components/chat-input/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/chat-input/plugins/utils.ts +48 -0
- package/src/components/chat-input/plugins/value-plugin.tsx +35 -0
- package/src/components/chat-input/transformers.ts +4 -0
- package/src/components/chat-list/chat-list-item.tsx +33 -0
- package/src/components/chat-list/chat-list-items.tsx +144 -0
- package/src/components/chat-list/chat-list.json +117 -0
- package/src/components/chat-list/chat-list.stories.tsx +332 -0
- package/src/components/chat-list/chat-list.tsx +278 -0
- package/src/components/chat-list/index.ts +18 -0
- package/src/components/chat-message/chat-message.json +105 -0
- package/src/components/chat-message/chat-message.stories.tsx +95 -0
- package/src/components/chat-message/chat-message.tsx +66 -0
- package/src/components/chat-message/index.ts +1 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +74 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +110 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +131 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +142 -0
- package/src/components/chat-message-attachment-card/index.ts +12 -0
- package/src/components/chat-message-attachment-card/utils.ts +41 -0
- package/src/components/chat-message-history/chat-message-history.json +99 -0
- package/src/components/chat-message-history/chat-message-history.stories.tsx +136 -0
- package/src/components/chat-message-history/chat-message-history.tsx +277 -0
- package/src/components/chat-message-history/index.ts +13 -0
- package/src/components/chat-message-response/chat-message-response.json +68 -0
- package/src/components/chat-message-response/chat-message-response.stories.tsx +63 -0
- package/src/components/chat-message-response/chat-message-response.tsx +24 -0
- package/src/components/chat-message-response/index.ts +1 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.json +100 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +62 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +97 -0
- package/src/components/chat-message-toolbar/index.ts +6 -0
- package/src/components/chat-messages/chat-messages.json +95 -0
- package/src/components/chat-messages/chat-messages.stories.tsx +284 -0
- package/src/components/chat-messages/chat-messages.tsx +264 -0
- package/src/components/chat-messages/index.ts +10 -0
- package/src/components/chat-notification-card/chat-notification-card.json +135 -0
- package/src/components/chat-notification-card/chat-notification-card.stories.tsx +290 -0
- package/src/components/chat-notification-card/chat-notification-card.tsx +684 -0
- package/src/components/chat-notification-card/index.ts +3 -0
- package/src/components/chat-notification-card/types.ts +1 -0
- package/src/components/chat-notification-card/utils.ts +34 -0
- package/src/components/chat-notification-popup/chat-notification-popup.json +97 -0
- package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +80 -0
- package/src/components/chat-notification-popup/chat-notification-popup.tsx +36 -0
- package/src/components/chat-notification-popup/index.ts +1 -0
- package/src/components/chat-prompt-box/chat-prompt-box-context.tsx +62 -0
- package/src/components/chat-prompt-box/chat-prompt-box-focus-plugin.tsx +22 -0
- package/src/components/chat-prompt-box/chat-prompt-box.json +106 -0
- package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +117 -0
- package/src/components/chat-prompt-box/chat-prompt-box.tsx +296 -0
- package/src/components/chat-prompt-box/index.ts +16 -0
- package/src/components/chat-reply/chat-reply.json +79 -0
- package/src/components/chat-reply/chat-reply.stories.tsx +72 -0
- package/src/components/chat-reply/chat-reply.tsx +103 -0
- package/src/components/chat-reply/index.ts +1 -0
- package/src/components/chat-suggestion/chat-suggestion.json +108 -0
- package/src/components/chat-suggestion/chat-suggestion.stories.tsx +147 -0
- package/src/components/chat-suggestion/chat-suggestion.tsx +184 -0
- package/src/components/chat-suggestion/index.ts +8 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +110 -0
- package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +202 -0
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +268 -0
- package/src/components/chat-thinking-process/index.ts +9 -0
- package/src/components/chat-thread/__tests__/chat-thread.spec.tsx +385 -0
- package/src/components/chat-thread/chat-thread.json +120 -0
- package/src/components/chat-thread/chat-thread.stories.tsx +218 -0
- package/src/components/chat-thread/chat-thread.tsx +549 -0
- package/src/components/chat-thread/index.ts +18 -0
- package/src/components/deprecated-empty-state.ts +39 -0
- package/src/components/index.ts +26 -0
- package/src/components/markdown-viewer/hooks.ts +59 -0
- package/src/components/markdown-viewer/index.ts +2 -0
- package/src/components/markdown-viewer/markdown-viewer.json +84 -0
- package/src/components/markdown-viewer/markdown-viewer.stories.tsx +110 -0
- package/src/components/markdown-viewer/markdown-viewer.tsx +95 -0
- package/src/components/markdown-viewer/types.ts +10 -0
- package/src/components/markdown-viewer/utils.ts +5 -0
- package/src/components/new-chat-trigger/index.ts +1 -0
- package/src/components/new-chat-trigger/new-chat-trigger.tsx +29 -0
- package/src/components/rich-text-area/constants/index.ts +10 -0
- package/src/components/rich-text-area/hooks.ts +24 -0
- package/src/components/rich-text-area/html-config.ts +195 -0
- package/src/components/rich-text-area/index.ts +6 -0
- package/src/components/rich-text-area/nodes/div-block-node.tsx +145 -0
- package/src/components/rich-text-area/nodes/image-node.tsx +100 -0
- package/src/components/rich-text-area/plugins/blur-plugin.tsx +36 -0
- package/src/components/rich-text-area/plugins/controlled-plugin.tsx +23 -0
- package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +101 -0
- package/src/components/rich-text-area/plugins/disabled-plugin.tsx +17 -0
- package/src/components/rich-text-area/plugins/file-attachment-plugin.tsx +57 -0
- package/src/components/rich-text-area/plugins/focus-plugin.tsx +44 -0
- package/src/components/rich-text-area/plugins/html-paste-plugin.tsx +104 -0
- package/src/components/rich-text-area/plugins/image-drop-plugin.tsx +56 -0
- package/src/components/rich-text-area/plugins/index.ts +10 -0
- package/src/components/rich-text-area/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/rich-text-area/plugins/value-plugin.tsx +46 -0
- package/src/components/rich-text-area/rich-text-area.json +102 -0
- package/src/components/rich-text-area/rich-text-area.stories.tsx +140 -0
- package/src/components/rich-text-area/rich-text-area.tsx +156 -0
- package/src/components/rich-text-area/styled.tsx +20 -0
- package/src/components/rich-text-area/transformers.ts +175 -0
- package/src/components/rich-text-area/types.ts +8 -0
- package/src/components/rich-text-area/utils/index.ts +77 -0
- package/src/components/rich-text-field/components/alignment-select.tsx +103 -0
- package/src/components/rich-text-field/components/attachment-button.tsx +25 -0
- package/src/components/rich-text-field/components/bold-button.tsx +21 -0
- package/src/components/rich-text-field/components/clean-format-button.tsx +44 -0
- package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +69 -0
- package/src/components/rich-text-field/components/image-button.tsx +11 -0
- package/src/components/rich-text-field/components/index.ts +14 -0
- package/src/components/rich-text-field/components/italic-button.tsx +21 -0
- package/src/components/rich-text-field/components/link-button.tsx +11 -0
- package/src/components/rich-text-field/components/size-select.tsx +27 -0
- package/src/components/rich-text-field/components/text-color-button.tsx +41 -0
- package/src/components/rich-text-field/components/toolbar-button.tsx +27 -0
- package/src/components/rich-text-field/components/toolbar-select.tsx +19 -0
- package/src/components/rich-text-field/components/typography-select.tsx +27 -0
- package/src/components/rich-text-field/components/underline-button.tsx +21 -0
- package/src/components/rich-text-field/constants.ts +33 -0
- package/src/components/rich-text-field/context.tsx +251 -0
- package/src/components/rich-text-field/index.tsx +6 -0
- package/src/components/rich-text-field/rich-text-field.json +118 -0
- package/src/components/rich-text-field/rich-text-field.stories.tsx +218 -0
- package/src/components/rich-text-field/rich-text-field.tsx +93 -0
- package/src/components/rich-text-field/utils.ts +532 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner/spinner.json +73 -0
- package/src/components/spinner/spinner.stories.tsx +41 -0
- package/src/components/spinner/spinner.tsx +32 -0
- package/src/contexts/chat-context/chat-context.tsx +97 -0
- package/src/contexts/chat-context/index.ts +1 -0
- package/src/contexts/chat-context/utils.ts +7 -0
- package/src/contexts/chat-conversation-context/chat-conversation-context.tsx +608 -0
- package/src/contexts/chat-conversation-context/index.ts +1 -0
- package/src/contexts/index.ts +2 -0
- package/src/docs/agent.stories.tsx +567 -0
- package/src/docs/chat-panel.tsx +174 -0
- package/src/docs/chatbot-panel.tsx +381 -0
- package/src/docs/chatbot.mdx +144 -0
- package/src/docs/chatbot.stories.tsx +63 -0
- package/src/domain/actions/constants.ts +1 -0
- package/src/domain/actions/hooks/index.ts +22 -0
- package/src/domain/actions/index.ts +4 -0
- package/src/domain/actions/types.ts +6 -0
- package/src/domain/actions/utils/index.ts +112 -0
- package/src/domain/index.ts +1 -0
- package/src/hooks/index.tsx +10 -0
- package/src/hooks/use-chat-prompt-placeholder.ts +7 -0
- package/src/hooks/use-chat-stream-message.ts +189 -0
- package/src/hooks/use-current-chat-id.ts +6 -0
- package/src/hooks/use-is-current-chat-new.ts +6 -0
- package/src/hooks/use-loaded-chat-ids.ts +32 -0
- package/src/hooks/use-on-chat-changed.ts +33 -0
- package/src/index.css +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +204 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +116 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +190 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +250 -0
- package/src/layouts/chat-card-list-layout/index.ts +11 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +73 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +282 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +131 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +78 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +273 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +291 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +135 -0
- package/src/layouts/chat-card-three-column-layout/index.ts +24 -0
- package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +109 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +97 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +21 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +138 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +132 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +65 -0
- package/src/layouts/chat-card-two-column-layout/index.ts +17 -0
- package/src/layouts/index.ts +3 -0
- package/src/types.ts +29 -0
- package/src/utils/use-streaming-markdown.ts +113 -0
- package/tailwind.css +7 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
+
import type { ComponentProps, MouseEvent, ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Children,
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useState,
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
import { Button } from '@swisper.ai/ui';
|
|
15
|
+
import type { ButtonProps } from '@swisper.ai/ui';
|
|
16
|
+
import { cn } from '@swisper.ai/web-core';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How many items are rendered before the reveal.
|
|
20
|
+
*
|
|
21
|
+
* Three, because the collapsed list has to read as "there is more here" at a glance.
|
|
22
|
+
* One or two look like the whole answer and the button gets ignored; from five up the
|
|
23
|
+
* collapsed state is already taller than a phone viewport, which is the thing this
|
|
24
|
+
* layout exists to prevent.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_VISIBLE_COUNT = 3;
|
|
27
|
+
|
|
28
|
+
interface ChatCardListLayoutContextValue {
|
|
29
|
+
visibleCount: number;
|
|
30
|
+
isExpanded: boolean;
|
|
31
|
+
expand: () => void;
|
|
32
|
+
hiddenCount: number;
|
|
33
|
+
setHiddenCount: (count: number) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ChatCardListLayoutContext = createContext<ChatCardListLayoutContextValue>(null!);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reads the layout's state from any descendant.
|
|
40
|
+
*
|
|
41
|
+
* Exported so a consumer can put the hidden count in their own label ("Show 5 more") or
|
|
42
|
+
* build a trigger that isn't a `Button`. `hiddenCount` is `0` on the first render and
|
|
43
|
+
* correct from the first layout effect onwards — see `ChatCardListLayoutItems`.
|
|
44
|
+
*/
|
|
45
|
+
export function useChatCardListLayoutContext() {
|
|
46
|
+
const context = useContext(ChatCardListLayoutContext);
|
|
47
|
+
|
|
48
|
+
if (!context) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
'[web-chat-ui] "useChatCardListLayoutContext" must be used within a ChatCardListLayout. ' +
|
|
51
|
+
'ChatCardListLayoutItems and ChatCardListLayoutShowMore both read it, so both must be ' +
|
|
52
|
+
'rendered inside the ChatCardListLayout element, not as siblings of it.',
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return context;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ChatCardListLayoutProps extends ComponentProps<'div'> {
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
/**
|
|
62
|
+
* How many items `ChatCardListLayoutItems` renders while collapsed.
|
|
63
|
+
*
|
|
64
|
+
* Clamped at zero: a negative value would reach `Array.slice` as a count from the end
|
|
65
|
+
* and quietly render the *last* n items, which is the opposite of what the caller
|
|
66
|
+
* asked for.
|
|
67
|
+
*/
|
|
68
|
+
visibleCount?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Expanded state for the uncontrolled case. Set it when the surrounding message is
|
|
71
|
+
* restored from history and the reader had already expanded this list.
|
|
72
|
+
*/
|
|
73
|
+
defaultExpanded?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Controlled expanded state. Pass it only if something outside owns the state —
|
|
76
|
+
* driving it back to `false` re-collapses the list and brings the button back, which
|
|
77
|
+
* the uncontrolled component deliberately cannot do.
|
|
78
|
+
*/
|
|
79
|
+
expanded?: boolean;
|
|
80
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
81
|
+
asChild?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Holds a list of chat cards and reveals the overflow behind a one-way "show more".
|
|
86
|
+
*
|
|
87
|
+
* Structure and state only — the sole class it emits is the `group/chat-card-list-layout`
|
|
88
|
+
* marker, which paints nothing and exists so descendants can react to the expanded state
|
|
89
|
+
* with `group-data-[expanded=true]/chat-card-list-layout:…`. Direction, gap and every
|
|
90
|
+
* other visual decision come from the consumer's `className`, so the same layout serves
|
|
91
|
+
* a stacked card list and a horizontal strip without a variant prop.
|
|
92
|
+
*
|
|
93
|
+
* The three parts exist because the pieces of information live in different places: only
|
|
94
|
+
* `ChatCardListLayoutItems` knows how many children there are, only
|
|
95
|
+
* `ChatCardListLayoutShowMore` needs to know whether any are hidden, and this root owns
|
|
96
|
+
* the state that joins them. Slicing here instead would mean telling item children apart
|
|
97
|
+
* from the button by inspecting `child.type`, which breaks the moment either is wrapped.
|
|
98
|
+
*/
|
|
99
|
+
export const ChatCardListLayout = forwardRef<HTMLDivElement, ChatCardListLayoutProps>(
|
|
100
|
+
function ChatCardListLayout(
|
|
101
|
+
{
|
|
102
|
+
children,
|
|
103
|
+
className,
|
|
104
|
+
visibleCount = DEFAULT_VISIBLE_COUNT,
|
|
105
|
+
defaultExpanded = false,
|
|
106
|
+
expanded,
|
|
107
|
+
onExpandedChange,
|
|
108
|
+
asChild = false,
|
|
109
|
+
...rest
|
|
110
|
+
},
|
|
111
|
+
ref,
|
|
112
|
+
) {
|
|
113
|
+
const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);
|
|
114
|
+
const [hiddenCount, setHiddenCount] = useState(0);
|
|
115
|
+
|
|
116
|
+
const isExpanded = expanded ?? internalExpanded;
|
|
117
|
+
|
|
118
|
+
const expand = useCallback(() => {
|
|
119
|
+
if (expanded === undefined) {
|
|
120
|
+
setInternalExpanded(true);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
onExpandedChange?.(true);
|
|
124
|
+
}, [expanded, onExpandedChange]);
|
|
125
|
+
|
|
126
|
+
const contextValue = useMemo(
|
|
127
|
+
() => ({
|
|
128
|
+
visibleCount: Math.max(0, visibleCount),
|
|
129
|
+
isExpanded,
|
|
130
|
+
expand,
|
|
131
|
+
hiddenCount,
|
|
132
|
+
setHiddenCount,
|
|
133
|
+
}),
|
|
134
|
+
[visibleCount, isExpanded, expand, hiddenCount],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const Component = asChild ? Slot : 'div';
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<ChatCardListLayoutContext.Provider value={contextValue}>
|
|
141
|
+
<Component
|
|
142
|
+
ref={ref}
|
|
143
|
+
data-testid="chat-card-list-layout"
|
|
144
|
+
data-expanded={isExpanded}
|
|
145
|
+
className={cn(
|
|
146
|
+
'group/chat-card-list-layout',
|
|
147
|
+
'flex flex-col items-start gap-[8px]',
|
|
148
|
+
className,
|
|
149
|
+
)}
|
|
150
|
+
{...rest}
|
|
151
|
+
>
|
|
152
|
+
{children}
|
|
153
|
+
</Component>
|
|
154
|
+
</ChatCardListLayoutContext.Provider>
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
ChatCardListLayout.displayName = 'ChatCardListLayout';
|
|
160
|
+
|
|
161
|
+
export interface ChatCardListLayoutItemsProps {
|
|
162
|
+
children: ReactNode;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Renders the visible slice of the list, and nothing else — no wrapper element.
|
|
167
|
+
*
|
|
168
|
+
* A `div` here would sit between the root's `className` and the cards, so a consumer's
|
|
169
|
+
* `flex`/`grid` on the root would apply to this one wrapper instead of to the items and
|
|
170
|
+
* the layout would silently collapse to a single column. There is no `className` prop
|
|
171
|
+
* for the same reason: there is no node to hang it on.
|
|
172
|
+
*
|
|
173
|
+
* Hidden items are sliced away rather than hidden with CSS, so they never mount: no DOM,
|
|
174
|
+
* no image or data fetches from cards nobody has asked for, and nothing invisible in the
|
|
175
|
+
* tab order.
|
|
176
|
+
*
|
|
177
|
+
* Only one of these per layout. Two would race on `hiddenCount` and the last effect
|
|
178
|
+
* would win; summing across instances is buildable but nothing needs it yet.
|
|
179
|
+
*/
|
|
180
|
+
export function ChatCardListLayoutItems({ children }: ChatCardListLayoutItemsProps) {
|
|
181
|
+
const { visibleCount, isExpanded, setHiddenCount } = useChatCardListLayoutContext();
|
|
182
|
+
|
|
183
|
+
// `Children.toArray` flattens fragments and drops `null`/`undefined`/booleans, so a
|
|
184
|
+
// conditionally rendered card counts only when it actually renders. Reading
|
|
185
|
+
// `Children.count` instead would count the holes and the button would offer to reveal
|
|
186
|
+
// items that do not exist.
|
|
187
|
+
const items = Children.toArray(children);
|
|
188
|
+
const hiddenCount = isExpanded ? 0 : Math.max(0, items.length - visibleCount);
|
|
189
|
+
|
|
190
|
+
// A layout effect, not `useEffect`: `hiddenCount` starts at 0, so the button renders
|
|
191
|
+
// `null` on the first pass and this correction has to land before the browser paints.
|
|
192
|
+
// With `useEffect` the button would visibly pop in after the list.
|
|
193
|
+
useLayoutEffect(() => {
|
|
194
|
+
setHiddenCount(hiddenCount);
|
|
195
|
+
}, [hiddenCount, setHiddenCount]);
|
|
196
|
+
|
|
197
|
+
return <>{isExpanded ? items : items.slice(0, visibleCount)}</>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface ChatCardListLayoutShowMoreProps extends Omit<ButtonProps, 'children'> {
|
|
201
|
+
/**
|
|
202
|
+
* The label. Required on purpose: a default `'Show more'` baked into the package would
|
|
203
|
+
* be untranslatable by the app that ships it, and this is the one string in the layout
|
|
204
|
+
* a reader actually sees.
|
|
205
|
+
*/
|
|
206
|
+
children: ReactNode;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The reveal trigger. Renders nothing once there is nothing left to reveal — either the
|
|
211
|
+
* list is expanded, or it never overflowed — which is what makes the button a one-shot
|
|
212
|
+
* affordance rather than a toggle.
|
|
213
|
+
*
|
|
214
|
+
* It sets no `variant`, `size` or `className` of its own so the design system's `Button`
|
|
215
|
+
* defaults apply untouched and a consumer's props are not fighting ours.
|
|
216
|
+
*/
|
|
217
|
+
export const ChatCardListLayoutShowMore = forwardRef<
|
|
218
|
+
// The same element union `Button` forwards: it renders a `span` when `isSemantic` is
|
|
219
|
+
// false, and narrowing to `HTMLButtonElement` here would make a plain object ref fail
|
|
220
|
+
// to type-check against it.
|
|
221
|
+
HTMLButtonElement | HTMLSpanElement,
|
|
222
|
+
ChatCardListLayoutShowMoreProps
|
|
223
|
+
>(function ChatCardListLayoutShowMore({ children, onClick, className, ...rest }, ref) {
|
|
224
|
+
const { isExpanded, hiddenCount, expand } = useChatCardListLayoutContext();
|
|
225
|
+
|
|
226
|
+
function handleClick(event: MouseEvent<HTMLButtonElement>) {
|
|
227
|
+
expand();
|
|
228
|
+
onClick?.(event);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (isExpanded || hiddenCount === 0) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
<Button
|
|
237
|
+
ref={ref}
|
|
238
|
+
variant="tertiary"
|
|
239
|
+
size="sm"
|
|
240
|
+
data-testid="chat-card-list-layout-show-more"
|
|
241
|
+
onClick={handleClick}
|
|
242
|
+
className={cn('mx-auto', className)}
|
|
243
|
+
{...rest}
|
|
244
|
+
>
|
|
245
|
+
{children}
|
|
246
|
+
</Button>
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
ChatCardListLayoutShowMore.displayName = 'ChatCardListLayoutShowMore';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ChatCardListLayout,
|
|
3
|
+
ChatCardListLayoutItems,
|
|
4
|
+
ChatCardListLayoutShowMore,
|
|
5
|
+
useChatCardListLayoutContext,
|
|
6
|
+
} from './chat-card-list-layout';
|
|
7
|
+
export type {
|
|
8
|
+
ChatCardListLayoutProps,
|
|
9
|
+
ChatCardListLayoutItemsProps,
|
|
10
|
+
ChatCardListLayoutShowMoreProps,
|
|
11
|
+
} from './chat-card-list-layout';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { resolveLayout } from '../chat-card-three-column-layout.sizing';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The thresholds are the whole feature: every pane decision, in CSS and in the render
|
|
7
|
+
* props, comes from this function. Each boundary is tested at its exact pixel and one
|
|
8
|
+
* below, so an off-by-one (a `>` for a `>=`, a forgotten gap) shows up here instead of as
|
|
9
|
+
* a pane that floats with room to spare.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
describe('size tiers', () => {
|
|
13
|
+
// md from 640; lg = 290 list + 8 gap + 400 min Main; xl = 2 × 358 + 2 × 8 + 400
|
|
14
|
+
test.each([
|
|
15
|
+
[639, 'sm'],
|
|
16
|
+
[640, 'md'],
|
|
17
|
+
[697, 'md'],
|
|
18
|
+
[698, 'lg'],
|
|
19
|
+
[1131, 'lg'],
|
|
20
|
+
[1132, 'xl'],
|
|
21
|
+
])('at %ipx the layout is %s', (width, expected) => {
|
|
22
|
+
expect(resolveLayout(width, 'responsive').size).toBe(expected);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('with responsive placement', () => {
|
|
27
|
+
test.each([
|
|
28
|
+
[500, { isListFloating: true, isDetailsFloating: true, isDetailsSheet: true }],
|
|
29
|
+
[660, { isListFloating: true, isDetailsFloating: true, isDetailsSheet: false }],
|
|
30
|
+
[800, { isListFloating: false, isDetailsFloating: true, isDetailsSheet: false }],
|
|
31
|
+
[1200, { isListFloating: false, isDetailsFloating: false, isDetailsSheet: false }],
|
|
32
|
+
])('at %ipx resolves %o', (width, expected) => {
|
|
33
|
+
expect(resolveLayout(width, 'responsive')).toMatchObject(expected);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// The bug that motivated measuring the layout: Details only got its column at a 1366px
|
|
37
|
+
// viewport, so a card with 1200px of room still floated it.
|
|
38
|
+
test('gives details its column once the layout has room, whatever the viewport', () => {
|
|
39
|
+
expect(resolveLayout(1200, 'responsive').isDetailsFloating).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('with floating placement', () => {
|
|
44
|
+
// The tiers still apply to List; only Details is kept off its column.
|
|
45
|
+
test.each([
|
|
46
|
+
[500, 'sm', true],
|
|
47
|
+
[800, 'lg', false],
|
|
48
|
+
[1920, 'xl', false],
|
|
49
|
+
])('at %ipx is %s with list floating: %s, and details floats', (width, size, isListFloating) => {
|
|
50
|
+
expect(resolveLayout(width, 'floating')).toMatchObject({
|
|
51
|
+
size,
|
|
52
|
+
isListFloating,
|
|
53
|
+
isDetailsFloating: true,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('before the layout is measured', () => {
|
|
59
|
+
// SSR and the first client render have no width; the wide form is the safer guess
|
|
60
|
+
// because SSR HTML is mostly seen on desktops.
|
|
61
|
+
test('resolves to xl', () => {
|
|
62
|
+
expect(resolveLayout('unset', 'responsive')).toEqual({
|
|
63
|
+
size: 'xl',
|
|
64
|
+
isListFloating: false,
|
|
65
|
+
isDetailsFloating: false,
|
|
66
|
+
isDetailsSheet: false,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('still floats details with floating placement', () => {
|
|
71
|
+
expect(resolveLayout('unset', 'floating').isDetailsFloating).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { act, cleanup, render, screen } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ChatCardThreeColumnLayout,
|
|
6
|
+
ChatCardThreeColumnLayoutDetails,
|
|
7
|
+
ChatCardThreeColumnLayoutList,
|
|
8
|
+
ChatCardThreeColumnLayoutMain,
|
|
9
|
+
ChatCardThreeColumnLayoutPanel,
|
|
10
|
+
} from '../chat-card-three-column-layout';
|
|
11
|
+
import type { ChatCardThreeColumnLayoutProps } from '../chat-card-three-column-layout';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The thresholds have their own table in `chat-card-three-column-layout.sizing.test.ts`.
|
|
15
|
+
* What this file locks is the wiring: the root measures itself, and the width it measures
|
|
16
|
+
* reaches both halves of the contract. That means the data attributes the CSS keys on and
|
|
17
|
+
* the `isFloating` each render prop receives. If they disagree, mobile content gets drawn
|
|
18
|
+
* in a desktop column, and no single-width visual check would notice.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type ResizeCallback = (
|
|
22
|
+
entries: { borderBoxSize: { inlineSize: number; blockSize: number }[] }[],
|
|
23
|
+
) => void;
|
|
24
|
+
|
|
25
|
+
let layoutWidth = 1440;
|
|
26
|
+
const observers = new Set<ResizeCallback>();
|
|
27
|
+
|
|
28
|
+
/** A `ResizeObserver` whose callbacks `resizeTo` fires by hand; jsdom has none and lays nothing out. */
|
|
29
|
+
class ResizeObserverStub {
|
|
30
|
+
constructor(private readonly callback: ResizeCallback) {}
|
|
31
|
+
observe() {
|
|
32
|
+
observers.add(this.callback);
|
|
33
|
+
}
|
|
34
|
+
disconnect() {
|
|
35
|
+
observers.delete(this.callback);
|
|
36
|
+
}
|
|
37
|
+
unobserve() {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function resizeTo(width: number) {
|
|
41
|
+
layoutWidth = width;
|
|
42
|
+
act(() =>
|
|
43
|
+
observers.forEach((callback) =>
|
|
44
|
+
callback([{ borderBoxSize: [{ inlineSize: width, blockSize: 480 }] }]),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
layoutWidth = 1440;
|
|
51
|
+
vi.stubGlobal('ResizeObserver', ResizeObserverStub);
|
|
52
|
+
// `useElementMeasure` reads `offsetWidth` for the first measurement, before any observer fires
|
|
53
|
+
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(() => layoutWidth);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
cleanup();
|
|
58
|
+
observers.clear();
|
|
59
|
+
vi.unstubAllGlobals();
|
|
60
|
+
vi.restoreAllMocks();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function renderLayout(props: Partial<ChatCardThreeColumnLayoutProps> = {}) {
|
|
64
|
+
return render(
|
|
65
|
+
<ChatCardThreeColumnLayout {...props}>
|
|
66
|
+
<ChatCardThreeColumnLayoutList>
|
|
67
|
+
{(isFloating) => <span>{isFloating ? 'list: strip' : 'list: column'}</span>}
|
|
68
|
+
</ChatCardThreeColumnLayoutList>
|
|
69
|
+
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
70
|
+
<ChatCardThreeColumnLayoutDetails>
|
|
71
|
+
{(isFloating) => <span>{isFloating ? 'details: floating' : 'details: column'}</span>}
|
|
72
|
+
</ChatCardThreeColumnLayoutDetails>
|
|
73
|
+
</ChatCardThreeColumnLayout>,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function text(container: HTMLElement) {
|
|
78
|
+
return container.textContent ?? '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function root() {
|
|
82
|
+
return screen.getByTestId('chat-card-three-column-layout');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function details() {
|
|
86
|
+
return screen.getByTestId('chat-card-three-column-layout-details');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
describe('the measured width', () => {
|
|
90
|
+
test.each([
|
|
91
|
+
[500, 'list: strip', 'details: floating'],
|
|
92
|
+
[800, 'list: column', 'details: floating'],
|
|
93
|
+
[1200, 'list: column', 'details: column'],
|
|
94
|
+
])('at %ipx renders "%s" and "%s"', (width, list, detailsText) => {
|
|
95
|
+
layoutWidth = width;
|
|
96
|
+
const { container } = renderLayout();
|
|
97
|
+
|
|
98
|
+
expect(text(container)).toContain(list);
|
|
99
|
+
expect(text(container)).toContain(detailsText);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// The CSS switches on these attributes, so they must carry the same decision the render
|
|
103
|
+
// props received. That agreement is why the layout is resolved once, at the root.
|
|
104
|
+
test('reaches the attributes the CSS keys on', () => {
|
|
105
|
+
layoutWidth = 800;
|
|
106
|
+
renderLayout();
|
|
107
|
+
|
|
108
|
+
expect(root().getAttribute('data-list-floating')).toBe('false');
|
|
109
|
+
expect(root().getAttribute('data-details-floating')).toBe('true');
|
|
110
|
+
expect(details().getAttribute('data-floating')).toBe('true');
|
|
111
|
+
expect(details().getAttribute('data-sheet')).toBe('false');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// `data-size` picks the grid template (290px list at lg, 358px at xl)
|
|
115
|
+
test.each([
|
|
116
|
+
[500, 'sm'],
|
|
117
|
+
[800, 'lg'],
|
|
118
|
+
[1200, 'xl'],
|
|
119
|
+
])('at %ipx publishes size %s', (width, size) => {
|
|
120
|
+
layoutWidth = width;
|
|
121
|
+
renderLayout();
|
|
122
|
+
|
|
123
|
+
expect(root().getAttribute('data-size')).toBe(size);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('marks a floating details pane as a sheet on a narrow layout', () => {
|
|
127
|
+
layoutWidth = 500;
|
|
128
|
+
renderLayout();
|
|
129
|
+
|
|
130
|
+
expect(details().getAttribute('data-sheet')).toBe('true');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('keeps details floating with floating placement, however wide', () => {
|
|
134
|
+
layoutWidth = 1920;
|
|
135
|
+
const { container } = renderLayout({ detailsPlacement: 'floating' });
|
|
136
|
+
|
|
137
|
+
expect(text(container)).toContain('details: floating');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('resizing', () => {
|
|
142
|
+
test('swaps the render-prop content when a threshold is crossed', () => {
|
|
143
|
+
const { container } = renderLayout();
|
|
144
|
+
|
|
145
|
+
resizeTo(500);
|
|
146
|
+
|
|
147
|
+
expect(text(container)).toContain('list: strip');
|
|
148
|
+
expect(text(container)).toContain('details: floating');
|
|
149
|
+
|
|
150
|
+
resizeTo(1440);
|
|
151
|
+
|
|
152
|
+
expect(text(container)).toContain('list: column');
|
|
153
|
+
expect(text(container)).toContain('details: column');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// The pane element must survive the switch, and only its content changes. Remounting the
|
|
157
|
+
// pane would drop the consumer's scroll position and any state above the render prop.
|
|
158
|
+
test('keeps the same pane element across a threshold', () => {
|
|
159
|
+
renderLayout();
|
|
160
|
+
const before = screen.getByTestId('chat-card-three-column-layout-list');
|
|
161
|
+
|
|
162
|
+
resizeTo(500);
|
|
163
|
+
|
|
164
|
+
expect(screen.getByTestId('chat-card-three-column-layout-list')).toBe(before);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('the root element', () => {
|
|
169
|
+
// The root needs its own ref for measuring as well as the consumer's; losing either is silent.
|
|
170
|
+
test('still forwards the consumer ref', () => {
|
|
171
|
+
const ref = { current: null as HTMLDivElement | null };
|
|
172
|
+
render(
|
|
173
|
+
<ChatCardThreeColumnLayout ref={ref}>
|
|
174
|
+
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
175
|
+
</ChatCardThreeColumnLayout>,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
expect(ref.current).toBe(root());
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('the parts', () => {
|
|
183
|
+
test('accept plain children as well as a render prop', () => {
|
|
184
|
+
render(
|
|
185
|
+
<ChatCardThreeColumnLayout>
|
|
186
|
+
<ChatCardThreeColumnLayoutList>plain list</ChatCardThreeColumnLayoutList>
|
|
187
|
+
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
188
|
+
<ChatCardThreeColumnLayoutDetails>plain details</ChatCardThreeColumnLayoutDetails>
|
|
189
|
+
</ChatCardThreeColumnLayout>,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(screen.getByText('plain list')).not.toBeNull();
|
|
193
|
+
expect(screen.getByText('plain details')).not.toBeNull();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// The root grid only grows a third track via `:has(> [data-slot=…-details])`, so the
|
|
197
|
+
// slot must land on the element the consumer asked for, including through `asChild`.
|
|
198
|
+
test('render into the consumer element with asChild', () => {
|
|
199
|
+
render(
|
|
200
|
+
<ChatCardThreeColumnLayout>
|
|
201
|
+
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
202
|
+
<ChatCardThreeColumnLayoutDetails asChild>
|
|
203
|
+
<section aria-label="details">details</section>
|
|
204
|
+
</ChatCardThreeColumnLayoutDetails>
|
|
205
|
+
</ChatCardThreeColumnLayout>,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const section = screen.getByRole('region', { name: 'details' });
|
|
209
|
+
|
|
210
|
+
expect(section.getAttribute('data-slot')).toBe('chat-card-three-column-layout-details');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test.each([
|
|
214
|
+
[
|
|
215
|
+
'ChatCardThreeColumnLayoutList',
|
|
216
|
+
<ChatCardThreeColumnLayoutList key="list">x</ChatCardThreeColumnLayoutList>,
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
'ChatCardThreeColumnLayoutMain',
|
|
220
|
+
<ChatCardThreeColumnLayoutMain key="main">x</ChatCardThreeColumnLayoutMain>,
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
'ChatCardThreeColumnLayoutDetails',
|
|
224
|
+
<ChatCardThreeColumnLayoutDetails key="details">x</ChatCardThreeColumnLayoutDetails>,
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
'ChatCardThreeColumnLayoutPanel',
|
|
228
|
+
<ChatCardThreeColumnLayoutPanel key="panel">x</ChatCardThreeColumnLayoutPanel>,
|
|
229
|
+
],
|
|
230
|
+
])('%s throws outside the layout', (name, element) => {
|
|
231
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
232
|
+
|
|
233
|
+
expect(() => render(element)).toThrow(new RegExp(`\\[web-chat-ui\\] "${name}"`));
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('the panel', () => {
|
|
238
|
+
function renderWithPanel() {
|
|
239
|
+
return render(
|
|
240
|
+
<ChatCardThreeColumnLayout>
|
|
241
|
+
<ChatCardThreeColumnLayoutList>list</ChatCardThreeColumnLayoutList>
|
|
242
|
+
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
243
|
+
<ChatCardThreeColumnLayoutDetails>details</ChatCardThreeColumnLayoutDetails>
|
|
244
|
+
<ChatCardThreeColumnLayoutPanel>reviews</ChatCardThreeColumnLayoutPanel>
|
|
245
|
+
</ChatCardThreeColumnLayout>,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function panel() {
|
|
250
|
+
return screen.getByTestId('chat-card-three-column-layout-panel');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// The CSS spans the panel from column 2 while List is a column, and over all of it once
|
|
254
|
+
// List floats; this attribute is the switch.
|
|
255
|
+
test.each([
|
|
256
|
+
[500, 'true'],
|
|
257
|
+
[800, 'false'],
|
|
258
|
+
[1200, 'false'],
|
|
259
|
+
])('at %ipx publishes list-floating %s', (width, listFloating) => {
|
|
260
|
+
layoutWidth = width;
|
|
261
|
+
renderWithPanel();
|
|
262
|
+
|
|
263
|
+
expect(panel().getAttribute('data-list-floating')).toBe(listFloating);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('follows List when the layout is resized', () => {
|
|
267
|
+
renderWithPanel();
|
|
268
|
+
|
|
269
|
+
resizeTo(500);
|
|
270
|
+
|
|
271
|
+
expect(panel().getAttribute('data-list-floating')).toBe('true');
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// The point of the panel over a replacement view: the map and the open item keep their state.
|
|
275
|
+
test('leaves Main and Details mounted underneath', () => {
|
|
276
|
+
const { container } = renderWithPanel();
|
|
277
|
+
|
|
278
|
+
expect(text(container)).toContain('map');
|
|
279
|
+
expect(text(container)).toContain('details');
|
|
280
|
+
expect(text(container)).toContain('reviews');
|
|
281
|
+
});
|
|
282
|
+
});
|