@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,532 @@
|
|
|
1
|
+
import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
2
|
+
import { $isHeadingNode, $isQuoteNode } from '@lexical/rich-text';
|
|
3
|
+
import { $forEachSelectedTextNode, $isAtNodeEnd, $patchStyleText } from '@lexical/selection';
|
|
4
|
+
import { $isTableSelection } from '@lexical/table';
|
|
5
|
+
import { mergeRegister, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
6
|
+
import type { PropertiesHyphenFallback } from 'csstype';
|
|
7
|
+
import InlineStyleParser from 'inline-style-parser';
|
|
8
|
+
import {
|
|
9
|
+
$addUpdateTag,
|
|
10
|
+
$caretRangeFromSelection,
|
|
11
|
+
$createParagraphNode,
|
|
12
|
+
$getNodeByKey,
|
|
13
|
+
$getPreviousSelection,
|
|
14
|
+
$getSelection,
|
|
15
|
+
$getState,
|
|
16
|
+
$isRangeSelection,
|
|
17
|
+
$isTextNode,
|
|
18
|
+
$setSelection,
|
|
19
|
+
$setState,
|
|
20
|
+
COMMAND_PRIORITY_EDITOR,
|
|
21
|
+
createCommand,
|
|
22
|
+
createState,
|
|
23
|
+
type DOMConversionMap,
|
|
24
|
+
type DOMExportOutput,
|
|
25
|
+
type ElementNode,
|
|
26
|
+
isDocumentFragment,
|
|
27
|
+
isHTMLElement,
|
|
28
|
+
type LexicalEditor,
|
|
29
|
+
type LexicalNode,
|
|
30
|
+
type RangeSelection,
|
|
31
|
+
RootNode,
|
|
32
|
+
SKIP_DOM_SELECTION_TAG,
|
|
33
|
+
TextNode,
|
|
34
|
+
type ValueOrUpdater,
|
|
35
|
+
} from 'lexical';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an object containing all the styles and their values provided in the CSS string.
|
|
39
|
+
* @param css - The CSS string of styles and their values.
|
|
40
|
+
* @returns The styleObject containing all the styles and their values.
|
|
41
|
+
*/
|
|
42
|
+
export function getStyleObjectFromRawCSS(css: string): StyleObject {
|
|
43
|
+
let styleObject: undefined | Record<string, string>;
|
|
44
|
+
for (const token of InlineStyleParser(css, { silent: true })) {
|
|
45
|
+
if (token.type === 'declaration' && token.value) {
|
|
46
|
+
styleObject = styleObject || {};
|
|
47
|
+
styleObject[token.property] = token.value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return styleObject || NO_STYLE;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
54
|
+
|
|
55
|
+
export type StyleObject = Prettify<{
|
|
56
|
+
[K in keyof PropertiesHyphenFallback]?:
|
|
57
|
+
| undefined
|
|
58
|
+
// This is simplified to not deal with arrays or numbers.
|
|
59
|
+
// This is an example after all!
|
|
60
|
+
| Extract<PropertiesHyphenFallback[K], string>;
|
|
61
|
+
}>;
|
|
62
|
+
|
|
63
|
+
export type StyleTuple = Exclude<
|
|
64
|
+
{
|
|
65
|
+
[K in keyof StyleObject]: [K, null | Exclude<StyleObject[K], undefined>];
|
|
66
|
+
}[keyof StyleObject],
|
|
67
|
+
undefined
|
|
68
|
+
>;
|
|
69
|
+
|
|
70
|
+
export const NO_STYLE: StyleObject = Object.freeze({});
|
|
71
|
+
|
|
72
|
+
function parse(v: unknown): StyleObject {
|
|
73
|
+
return typeof v === 'string' ? getStyleObjectFromRawCSS(v) : NO_STYLE;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function unparse(style: StyleObject): string {
|
|
77
|
+
const styles: string[] = [];
|
|
78
|
+
for (const [k, v] of Object.entries(style)) {
|
|
79
|
+
if (k && v) {
|
|
80
|
+
styles.push(`${k}: ${v};`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return styles.sort().join(' ');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isEqualValue(
|
|
87
|
+
a: StyleObject[keyof StyleObject],
|
|
88
|
+
b: StyleObject[keyof StyleObject],
|
|
89
|
+
): boolean {
|
|
90
|
+
return a === b || (!a && !b);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isEqual(a: StyleObject, b: StyleObject): boolean {
|
|
94
|
+
if (a === b) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
for (const k in a) {
|
|
98
|
+
if (!(k in b && isEqualValue(a[k as keyof StyleObject], b[k as keyof StyleObject]))) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const k in b) {
|
|
103
|
+
if (!(k in a)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const styleState = createState('style', {
|
|
111
|
+
isEqual,
|
|
112
|
+
parse,
|
|
113
|
+
unparse,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export function $getStyleProperty<Prop extends keyof StyleObject>(
|
|
117
|
+
node: LexicalNode,
|
|
118
|
+
prop: Prop,
|
|
119
|
+
): undefined | StyleObject[Prop] {
|
|
120
|
+
return $getStyleObject(node)[prop];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getStyleObjectDirect(node: LexicalNode): StyleObject {
|
|
124
|
+
return $getState(node, styleState, 'direct');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function $getStyleObject(node: LexicalNode): StyleObject {
|
|
128
|
+
return $getState(node, styleState);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function $setStyleObject<T extends LexicalNode>(
|
|
132
|
+
node: T,
|
|
133
|
+
valueOrUpdater: ValueOrUpdater<StyleObject>,
|
|
134
|
+
): T {
|
|
135
|
+
return $setState(node, styleState, valueOrUpdater);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function $removeStyleProperty<T extends LexicalNode, Prop extends keyof StyleObject>(
|
|
139
|
+
node: T,
|
|
140
|
+
prop: Prop,
|
|
141
|
+
): T {
|
|
142
|
+
return $setStyleObject(node, (prevStyle) => {
|
|
143
|
+
if (prop in prevStyle) {
|
|
144
|
+
const { [prop]: _ignore, ...nextStyle } = prevStyle;
|
|
145
|
+
return nextStyle;
|
|
146
|
+
}
|
|
147
|
+
return prevStyle;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function $setStyleProperty<T extends LexicalNode, Prop extends keyof StyleObject>(
|
|
152
|
+
node: T,
|
|
153
|
+
prop: Prop,
|
|
154
|
+
value: ValueOrUpdater<StyleObject[Prop]>,
|
|
155
|
+
): T {
|
|
156
|
+
return $setStyleObject(node, (prevStyle) => {
|
|
157
|
+
const prevValue = prevStyle[prop];
|
|
158
|
+
const nextValue = typeof value === 'function' ? value(prevValue) : value;
|
|
159
|
+
return prevValue === nextValue ? prevStyle : { ...prevStyle, [prop]: nextValue };
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function applyStyle(element: HTMLElement, styleObject: StyleObject): void {
|
|
164
|
+
for (const k_ in styleObject) {
|
|
165
|
+
const k = k_ as keyof StyleObject;
|
|
166
|
+
element.style.setProperty(k, styleObject[k] ?? null);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function diffStyleObjects(prevStyles: StyleObject, nextStyles: StyleObject): StyleObject {
|
|
171
|
+
let styleDiff: undefined | Record<string, string | undefined>;
|
|
172
|
+
if (prevStyles !== nextStyles) {
|
|
173
|
+
for (const k_ in nextStyles) {
|
|
174
|
+
const k = k_ as keyof StyleObject;
|
|
175
|
+
const nextV = nextStyles[k];
|
|
176
|
+
const prevV = prevStyles[k];
|
|
177
|
+
if (!isEqualValue(nextV, prevV)) {
|
|
178
|
+
styleDiff = styleDiff || {};
|
|
179
|
+
styleDiff[k] = nextV;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const k in prevStyles) {
|
|
183
|
+
if (!(k in nextStyles)) {
|
|
184
|
+
styleDiff = styleDiff || {};
|
|
185
|
+
styleDiff[k] = undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return styleDiff || NO_STYLE;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function mergeStyleObjects(prevStyles: StyleObject, nextStyles: StyleObject): StyleObject {
|
|
193
|
+
return prevStyles === NO_STYLE || prevStyles === nextStyles
|
|
194
|
+
? nextStyles
|
|
195
|
+
: { ...prevStyles, ...nextStyles };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function styleObjectToArray(styleObject: StyleObject): StyleTuple[] {
|
|
199
|
+
const entries: StyleTuple[] = [];
|
|
200
|
+
for (const k_ in styleObject) {
|
|
201
|
+
const k = k_ as keyof StyleObject;
|
|
202
|
+
entries.push([k, styleObject[k] ?? null] as StyleTuple);
|
|
203
|
+
}
|
|
204
|
+
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
205
|
+
return entries;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const PATCH_TEXT_STYLE_COMMAND = createCommand<
|
|
209
|
+
StyleObject | ((prevStyles: StyleObject) => StyleObject)
|
|
210
|
+
>('PATCH_TEXT_STYLE_COMMAND');
|
|
211
|
+
|
|
212
|
+
function $nodeHasStyle(node: LexicalNode): boolean {
|
|
213
|
+
return !isEqual(NO_STYLE, $getStyleObject(node));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function $selectionHasStyle(): boolean {
|
|
217
|
+
const selection = $getSelection();
|
|
218
|
+
if ($isRangeSelection(selection)) {
|
|
219
|
+
const caretRange = $caretRangeFromSelection(selection);
|
|
220
|
+
for (const slice of caretRange.getTextSlices()) {
|
|
221
|
+
if (slice && $nodeHasStyle(slice.caret.origin)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
for (const caret of caretRange.iterNodeCarets('root')) {
|
|
226
|
+
if ($isTextNode(caret.origin) && $nodeHasStyle(caret.origin)) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function $patchSelectedTextStyle(
|
|
235
|
+
styleObjectOrCallback: StyleObject | ((prevStyles: StyleObject) => StyleObject),
|
|
236
|
+
): boolean {
|
|
237
|
+
let selection = $getSelection();
|
|
238
|
+
if (!selection) {
|
|
239
|
+
const prevSelection = $getPreviousSelection();
|
|
240
|
+
if (!prevSelection) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
selection = prevSelection.clone();
|
|
244
|
+
$setSelection(selection);
|
|
245
|
+
}
|
|
246
|
+
const styleCallback =
|
|
247
|
+
typeof styleObjectOrCallback === 'function'
|
|
248
|
+
? styleObjectOrCallback
|
|
249
|
+
: (prevStyles: StyleObject) => mergeStyleObjects(prevStyles, styleObjectOrCallback);
|
|
250
|
+
if ($isRangeSelection(selection) && selection.isCollapsed()) {
|
|
251
|
+
const node = selection.focus.getNode();
|
|
252
|
+
if ($isTextNode(node)) {
|
|
253
|
+
$setStyleObject(node, styleCallback);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
$forEachSelectedTextNode((node) => $setStyleObject(node, styleCallback));
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const PREV_STYLE_STATE = Symbol.for('styleState');
|
|
262
|
+
interface HTMLElementWithManagedStyle extends HTMLElement {
|
|
263
|
+
// Store the last reconciled style object directly on the DOM
|
|
264
|
+
// so we don't have to track the previous DOM
|
|
265
|
+
// which can happen even when nodeMutation is 'updated'
|
|
266
|
+
[PREV_STYLE_STATE]?: StyleObject;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
interface LexicalNodeWithUnknownStyle extends LexicalNode {
|
|
270
|
+
// This property exists on all TextNode and ElementNode
|
|
271
|
+
// and likely also some DecoratorNode by convention.
|
|
272
|
+
// We use it as a heuristic to see if the style has likely
|
|
273
|
+
// been overwritten to see if we should apply a diff
|
|
274
|
+
// or all styles.
|
|
275
|
+
__style?: unknown;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function styleStringChanged(
|
|
279
|
+
node: LexicalNodeWithUnknownStyle,
|
|
280
|
+
prevNode: LexicalNodeWithUnknownStyle,
|
|
281
|
+
): boolean {
|
|
282
|
+
return typeof node.__style === 'string' && prevNode.__style !== node.__style;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getPreviousStyleObject(
|
|
286
|
+
node: LexicalNode,
|
|
287
|
+
prevNode: null | LexicalNode,
|
|
288
|
+
dom: HTMLElementWithManagedStyle,
|
|
289
|
+
): StyleObject {
|
|
290
|
+
const prevStyleObject = dom[PREV_STYLE_STATE];
|
|
291
|
+
return prevStyleObject && prevNode && !styleStringChanged(node, prevNode)
|
|
292
|
+
? prevStyleObject
|
|
293
|
+
: NO_STYLE;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// This applies the style to the DOM of any node
|
|
297
|
+
function makeStyleUpdateListener(editor: LexicalEditor): () => void {
|
|
298
|
+
return mergeRegister(
|
|
299
|
+
editor.registerMutationListener(RootNode, () => {
|
|
300
|
+
// UpdateListener will only get the mutatedNodes payload when
|
|
301
|
+
// at least one MutationListener is registered
|
|
302
|
+
}),
|
|
303
|
+
editor.registerUpdateListener((payload) => {
|
|
304
|
+
const { prevEditorState, mutatedNodes } = payload;
|
|
305
|
+
editor.getEditorState().read(
|
|
306
|
+
() => {
|
|
307
|
+
if (mutatedNodes) {
|
|
308
|
+
for (const nodes of mutatedNodes.values()) {
|
|
309
|
+
for (const [nodeKey, nodeMutation] of nodes) {
|
|
310
|
+
if (nodeMutation === 'destroyed') {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const node = $getNodeByKey(nodeKey);
|
|
314
|
+
const dom: null | HTMLElementWithManagedStyle = editor.getElementByKey(nodeKey);
|
|
315
|
+
if (!dom || !node) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const prevNode = $getNodeByKey(nodeKey, prevEditorState);
|
|
319
|
+
const prevStyleObject = getPreviousStyleObject(node, prevNode, dom);
|
|
320
|
+
const nextStyleObject = $getStyleObject(node);
|
|
321
|
+
dom[PREV_STYLE_STATE] = nextStyleObject;
|
|
322
|
+
applyStyle(dom, diffStyleObjects(prevStyleObject, nextStyleObject));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{ editor },
|
|
328
|
+
);
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// TODO https://github.com/facebook/lexical/issues/7259
|
|
334
|
+
// there should be a better way to do this, this does not compose with other exportDOM overrides
|
|
335
|
+
export function $exportNodeStyle(editor: LexicalEditor, target: LexicalNode): DOMExportOutput {
|
|
336
|
+
const output = target.exportDOM(editor);
|
|
337
|
+
const style = $getStyleObject(target);
|
|
338
|
+
if (style === NO_STYLE) {
|
|
339
|
+
return output;
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
...output,
|
|
343
|
+
after: (generatedElement) => {
|
|
344
|
+
const el = output.after ? output.after(generatedElement) : generatedElement;
|
|
345
|
+
if (isHTMLElement(el)) {
|
|
346
|
+
applyStyle(el, style);
|
|
347
|
+
} else if (isDocumentFragment(el)) {
|
|
348
|
+
// Work around a bug in the type
|
|
349
|
+
return el;
|
|
350
|
+
}
|
|
351
|
+
return el;
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const IGNORE_STYLES = new Set<keyof StyleObject>([
|
|
357
|
+
'font-weight',
|
|
358
|
+
'text-decoration',
|
|
359
|
+
'font-style',
|
|
360
|
+
'vertical-align',
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
export type StyleMapping = (input: StyleObject) => StyleObject;
|
|
364
|
+
|
|
365
|
+
// TODO there's no reasonable way to hook into importDOM/exportDOM from a plug-in https://github.com/facebook/lexical/issues/7259
|
|
366
|
+
export function constructStyleImportMap(
|
|
367
|
+
styleMapping: StyleMapping = (input) => input,
|
|
368
|
+
): DOMConversionMap {
|
|
369
|
+
const importMap: DOMConversionMap = {};
|
|
370
|
+
|
|
371
|
+
// Wrap all TextNode importers with a function that also imports
|
|
372
|
+
// styles that are not otherwise imported
|
|
373
|
+
for (const [tag, fn] of Object.entries(TextNode.importDOM() || {})) {
|
|
374
|
+
importMap[tag] = (importNode) => {
|
|
375
|
+
const importer = fn(importNode);
|
|
376
|
+
if (!importer) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
...importer,
|
|
381
|
+
conversion: (element) => {
|
|
382
|
+
const output = importer.conversion(element);
|
|
383
|
+
if (
|
|
384
|
+
output?.forChild === undefined ||
|
|
385
|
+
output.after !== undefined ||
|
|
386
|
+
output.node !== null ||
|
|
387
|
+
!element.hasAttribute('style')
|
|
388
|
+
) {
|
|
389
|
+
return output;
|
|
390
|
+
}
|
|
391
|
+
let extraStyles: undefined | Record<string, string>;
|
|
392
|
+
for (const k of element.style) {
|
|
393
|
+
if (IGNORE_STYLES.has(k as keyof StyleObject)) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
extraStyles = extraStyles || {};
|
|
397
|
+
extraStyles[k] = element.style.getPropertyValue(k);
|
|
398
|
+
}
|
|
399
|
+
if (extraStyles) {
|
|
400
|
+
const { forChild } = output;
|
|
401
|
+
return {
|
|
402
|
+
...output,
|
|
403
|
+
forChild: (child, parent) => {
|
|
404
|
+
const node = forChild(child, parent);
|
|
405
|
+
return $isTextNode(node)
|
|
406
|
+
? $setStyleObject(node, styleMapping(extraStyles as StyleObject))
|
|
407
|
+
: node;
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return output;
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return importMap;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export function registerStyleState(editor: LexicalEditor): () => void {
|
|
420
|
+
return mergeRegister(
|
|
421
|
+
editor.registerCommand(
|
|
422
|
+
PATCH_TEXT_STYLE_COMMAND,
|
|
423
|
+
$patchSelectedTextStyle,
|
|
424
|
+
COMMAND_PRIORITY_EDITOR,
|
|
425
|
+
),
|
|
426
|
+
makeStyleUpdateListener(editor),
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {
|
|
431
|
+
const anchor = selection.anchor;
|
|
432
|
+
const focus = selection.focus;
|
|
433
|
+
const anchorNode = selection.anchor.getNode();
|
|
434
|
+
const focusNode = selection.focus.getNode();
|
|
435
|
+
if (anchorNode === focusNode) {
|
|
436
|
+
return anchorNode;
|
|
437
|
+
}
|
|
438
|
+
const isBackward = selection.isBackward();
|
|
439
|
+
if (isBackward) {
|
|
440
|
+
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
441
|
+
} else {
|
|
442
|
+
return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Patches the selection with the updated font size.
|
|
448
|
+
*/
|
|
449
|
+
export const updateFontSizeInSelection = (
|
|
450
|
+
editor: LexicalEditor,
|
|
451
|
+
newFontSize: string | null,
|
|
452
|
+
_updateType: unknown,
|
|
453
|
+
skipRefocus: boolean,
|
|
454
|
+
) => {
|
|
455
|
+
editor.update(() => {
|
|
456
|
+
if (skipRefocus) {
|
|
457
|
+
$addUpdateTag(SKIP_DOM_SELECTION_TAG);
|
|
458
|
+
}
|
|
459
|
+
if (editor.isEditable()) {
|
|
460
|
+
const selection = $getSelection();
|
|
461
|
+
if (selection !== null) {
|
|
462
|
+
$patchStyleText(selection, {
|
|
463
|
+
'font-size': newFontSize + 'px',
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
export function clearFormatting(editor: LexicalEditor, skipRefocus = false) {
|
|
471
|
+
editor.update(() => {
|
|
472
|
+
if (skipRefocus) {
|
|
473
|
+
$addUpdateTag(SKIP_DOM_SELECTION_TAG);
|
|
474
|
+
}
|
|
475
|
+
const selection = $getSelection();
|
|
476
|
+
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
477
|
+
const anchor = selection.anchor;
|
|
478
|
+
const focus = selection.focus;
|
|
479
|
+
const nodes = selection.getNodes();
|
|
480
|
+
const extractedNodes = selection.extract();
|
|
481
|
+
|
|
482
|
+
if (anchor.key === focus.key && anchor.offset === focus.offset) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
nodes.forEach((node, idx) => {
|
|
487
|
+
// We split the first and last node by the selection
|
|
488
|
+
// So that we don't format unselected text inside those nodes
|
|
489
|
+
if ($isTextNode(node)) {
|
|
490
|
+
// Use a separate variable to ensure TS does not lose the refinement
|
|
491
|
+
let textNode = node;
|
|
492
|
+
if (idx === 0 && anchor.offset !== 0) {
|
|
493
|
+
textNode = textNode.splitText(anchor.offset)[1] || textNode;
|
|
494
|
+
}
|
|
495
|
+
if (idx === nodes.length - 1) {
|
|
496
|
+
textNode = textNode.splitText(focus.offset)[0] || textNode;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* If the selected text has one format applied
|
|
500
|
+
* selecting a portion of the text, could
|
|
501
|
+
* clear the format to the wrong portion of the text.
|
|
502
|
+
*
|
|
503
|
+
* The cleared text is based on the length of the selected text.
|
|
504
|
+
*/
|
|
505
|
+
// We need this in case the selected text only has one format
|
|
506
|
+
const extractedTextNode = extractedNodes[0];
|
|
507
|
+
if (nodes.length === 1 && $isTextNode(extractedTextNode)) {
|
|
508
|
+
textNode = extractedTextNode;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (textNode.__style !== '') {
|
|
512
|
+
textNode.setStyle('');
|
|
513
|
+
}
|
|
514
|
+
if (textNode.__format !== 0) {
|
|
515
|
+
textNode.setFormat(0);
|
|
516
|
+
}
|
|
517
|
+
const nearestBlockElement = $getNearestBlockElementAncestorOrThrow(textNode);
|
|
518
|
+
if (nearestBlockElement.__format !== 0) {
|
|
519
|
+
nearestBlockElement.setFormat('');
|
|
520
|
+
}
|
|
521
|
+
if (nearestBlockElement.__indent !== 0) {
|
|
522
|
+
nearestBlockElement.setIndent(0);
|
|
523
|
+
}
|
|
524
|
+
} else if ($isHeadingNode(node) || $isQuoteNode(node)) {
|
|
525
|
+
node.replace($createParagraphNode(), true);
|
|
526
|
+
} else if ($isDecoratorBlockNode(node)) {
|
|
527
|
+
node.setFormat('');
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './spinner';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
|
+
"component": "spinner",
|
|
4
|
+
"purpose": "Animated Lottie loading indicator in four fixed sizes, from an inline 16px mark to a 96px full-panel loading state.",
|
|
5
|
+
"useWhen": [
|
|
6
|
+
"Something is loading and its final layout is unknown, so a placeholder shape can't stand in for it",
|
|
7
|
+
"A full panel or canvas is waiting for its first content (size xl)",
|
|
8
|
+
"A short inline wait next to a status text (size sm or md)"
|
|
9
|
+
],
|
|
10
|
+
"avoidWhen": [
|
|
11
|
+
"The layout of the content that is loading is known — use ui/skeleton in its shape",
|
|
12
|
+
"A button's own action is running — use the loading state of ui/button",
|
|
13
|
+
"The assistant is reasoning or calling tools before an answer — use web-chat-ui/chat-thinking-process"
|
|
14
|
+
],
|
|
15
|
+
"uxPrinciples": [
|
|
16
|
+
"A spinner says only 'wait': pair it with text saying what is loading when the wait is more than a moment.",
|
|
17
|
+
"One spinner per region — several spinning at once read as a broken page."
|
|
18
|
+
],
|
|
19
|
+
"accessibility": {
|
|
20
|
+
"required": [
|
|
21
|
+
"The spinner has no role, label or live region and announces nothing; put it inside, or next to, an element with role=status and a visible or visually hidden text ('Loading documents…')",
|
|
22
|
+
"Remove it (and update the status text) when loading ends, so assistive tech hears the change"
|
|
23
|
+
],
|
|
24
|
+
"keyboard": ["Not interactive and never focusable"],
|
|
25
|
+
"aria": ["No ARIA attributes; the status semantics belong to the consumer's wrapper"],
|
|
26
|
+
"focus": ["No focus behaviour; it ignores pointer events"]
|
|
27
|
+
},
|
|
28
|
+
"behaviour": {
|
|
29
|
+
"states": ["playing (looping)", "still (first frame)"],
|
|
30
|
+
"rules": [
|
|
31
|
+
"size sets the box: sm is 16px, md 24px, lg 32px, xl 96px for a full-panel loading state",
|
|
32
|
+
"autoplay=true plays and loops the animation; false shows a still first frame",
|
|
33
|
+
"The animation is fetched at runtime from lottie.host (SOURCE_ANIMATION), so the host app's CSP and network must allow that origin, and the box is empty until it loads",
|
|
34
|
+
"It renders an inline-flex box with pointer-events disabled and takes no className or other props, so place and space it with its wrapper"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"composition": {
|
|
38
|
+
"allowedParents": [],
|
|
39
|
+
"allowedChildren": [],
|
|
40
|
+
"avoidCombinations": [
|
|
41
|
+
"Spinner and ui/skeleton for the same region at once — pick one loading pattern",
|
|
42
|
+
"Spinner over stale content — remove or replace the content while it reloads"
|
|
43
|
+
],
|
|
44
|
+
"contexts": ["centre of an empty panel or canvas", "inline beside a status line"]
|
|
45
|
+
},
|
|
46
|
+
"content": {
|
|
47
|
+
"labelRules": [
|
|
48
|
+
"The status text next to it names what is loading, in sentence case with an ellipsis ('Loading documents…')"
|
|
49
|
+
],
|
|
50
|
+
"helperTextRules": [],
|
|
51
|
+
"errorRules": [
|
|
52
|
+
"When loading fails, replace the spinner with an error message and a retry action — never leave it spinning"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"aiDecisionRules": [
|
|
56
|
+
{
|
|
57
|
+
"condition": "The shape of the loading content is known (a list, a card, a paragraph)",
|
|
58
|
+
"decision": "Use ui/skeleton instead of Spinner",
|
|
59
|
+
"reason": "A skeleton keeps the layout stable and shows what is coming"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"condition": "A whole panel or canvas has nothing to show yet",
|
|
63
|
+
"decision": "Centre a Spinner with size='xl' in a role=status wrapper with a short text",
|
|
64
|
+
"reason": "xl is the full-panel size; the wrapper gives screen readers the announcement the spinner lacks"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"condition": "The user has asked for reduced motion or the wait is paused",
|
|
68
|
+
"decision": "Render it with autoplay={false}",
|
|
69
|
+
"reason": "It then shows a still first frame instead of looping"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"relatedComponents": ["ui/skeleton", "ui/button", "web-chat-ui/chat-thinking-process"]
|
|
73
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
3
|
+
import { Spinner } from './spinner';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Spinner> = {
|
|
6
|
+
title: 'Chatbot/Spinner',
|
|
7
|
+
component: Spinner,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
argTypes: {
|
|
10
|
+
size: {
|
|
11
|
+
control: 'select',
|
|
12
|
+
options: ['sm', 'md', 'lg', 'xl'],
|
|
13
|
+
description:
|
|
14
|
+
'Box size: `sm` 16px, `md` 24px, `lg` 32px, `xl` 96px for a full-panel loading state.',
|
|
15
|
+
table: { defaultValue: { summary: 'md' } },
|
|
16
|
+
},
|
|
17
|
+
autoplay: {
|
|
18
|
+
control: 'boolean',
|
|
19
|
+
description: 'Plays and loops the animation. Turn it off to show a still first frame.',
|
|
20
|
+
table: { defaultValue: { summary: 'true' } },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
args: {
|
|
24
|
+
size: 'md',
|
|
25
|
+
autoplay: true,
|
|
26
|
+
},
|
|
27
|
+
decorators: [
|
|
28
|
+
(Story) => (
|
|
29
|
+
<div className="max-w-[420px]">
|
|
30
|
+
<Story />
|
|
31
|
+
</div>
|
|
32
|
+
),
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default meta;
|
|
37
|
+
type Story = StoryObj<typeof Spinner>;
|
|
38
|
+
|
|
39
|
+
export const Default: Story = {};
|
|
40
|
+
|
|
41
|
+
export const Playground: Story = {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@swisper.ai/web-core';
|
|
4
|
+
|
|
5
|
+
type Size = 'sm' | 'md' | 'lg' | 'xl';
|
|
6
|
+
|
|
7
|
+
export const SOURCE_ANIMATION =
|
|
8
|
+
'https://lottie.host/444a46a4-65b4-4483-b3a8-675160a79dad/LgQ8IVLAzA.lottie';
|
|
9
|
+
|
|
10
|
+
export interface SpinnerProps {
|
|
11
|
+
size?: Size;
|
|
12
|
+
autoplay?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Spinner({ size = 'md', autoplay = true }: SpinnerProps) {
|
|
16
|
+
return (
|
|
17
|
+
<span
|
|
18
|
+
data-testid="spinner"
|
|
19
|
+
data-size={size}
|
|
20
|
+
className={cn(
|
|
21
|
+
'pointer-events-none',
|
|
22
|
+
'inline-flex items-center justify-center',
|
|
23
|
+
'data-[size=sm]:size-16', // 16px
|
|
24
|
+
'data-[size=md]:size-24', // 24px
|
|
25
|
+
'data-[size=lg]:size-32', // 32px
|
|
26
|
+
'data-[size=xl]:size-[96px]', // 96px
|
|
27
|
+
)}
|
|
28
|
+
>
|
|
29
|
+
<DotLottieReact src={SOURCE_ANIMATION} loop={autoplay} autoplay={autoplay} />
|
|
30
|
+
</span>
|
|
31
|
+
);
|
|
32
|
+
}
|