@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,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TRANSFORMERS,
|
|
3
|
+
type TextMatchTransformer,
|
|
4
|
+
type ElementTransformer,
|
|
5
|
+
} from '@lexical/markdown';
|
|
6
|
+
import { $isParagraphNode, $isTextNode, $createTextNode, type ElementFormatType } from 'lexical';
|
|
7
|
+
|
|
8
|
+
import { ImageNode, $createImageNode, $isImageNode } from './nodes/image-node';
|
|
9
|
+
|
|
10
|
+
export { TRANSFORMERS as MARKDOWN_TRANSFORMERS };
|
|
11
|
+
|
|
12
|
+
export function extractFontStyles(style: string) {
|
|
13
|
+
const fontSizeRegex = /font-size\s*:\s*([^;]+)/i;
|
|
14
|
+
const fontFamilyRegex = /font-family\s*:\s*([^;]+)/i;
|
|
15
|
+
const colorRegex = /(?<![\w-])color\s*:\s*([^;]+)/i;
|
|
16
|
+
|
|
17
|
+
const fontSizeMatch = fontSizeRegex.exec(style);
|
|
18
|
+
const fontFamilyMatch = fontFamilyRegex.exec(style);
|
|
19
|
+
const colorMatch = colorRegex.exec(style);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
fontSize: fontSizeMatch ? fontSizeMatch[1].trim() : null,
|
|
23
|
+
fontFamily: fontFamilyMatch ? fontFamilyMatch[1].trim() : null,
|
|
24
|
+
color: colorMatch ? colorMatch[1].trim() : null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const FONT_STYLE_EXPORT: TextMatchTransformer = {
|
|
29
|
+
type: 'text-match',
|
|
30
|
+
trigger: '', // not used for export
|
|
31
|
+
regExp: /./, // not used for export
|
|
32
|
+
importRegExp: /./, // not used for export
|
|
33
|
+
dependencies: [],
|
|
34
|
+
|
|
35
|
+
export: (node) => {
|
|
36
|
+
if (!$isTextNode(node)) return null;
|
|
37
|
+
|
|
38
|
+
const style = node.getStyle() ?? '';
|
|
39
|
+
const text = node.getTextContent();
|
|
40
|
+
const fontStyles = extractFontStyles(style);
|
|
41
|
+
|
|
42
|
+
if (fontStyles.fontSize || fontStyles.fontFamily || fontStyles.color) {
|
|
43
|
+
let styleStr = '';
|
|
44
|
+
|
|
45
|
+
if (fontStyles.fontSize) {
|
|
46
|
+
styleStr += `font-size: ${fontStyles.fontSize};`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (fontStyles.fontFamily) {
|
|
50
|
+
styleStr += `font-family: ${fontStyles.fontFamily};`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (fontStyles.color) {
|
|
54
|
+
styleStr += `color: ${fontStyles.color};`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return `<span style="${styleStr}">${text}</span>`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const FONT_STYLE_IMPORT: TextMatchTransformer = {
|
|
65
|
+
type: 'text-match',
|
|
66
|
+
trigger: '',
|
|
67
|
+
regExp: /<span\s+style="([^"]+)">(.+?)<\/span>/,
|
|
68
|
+
importRegExp: /<span\s+style="([^"]+)">(.+?)<\/span>/,
|
|
69
|
+
dependencies: [],
|
|
70
|
+
replace: (textNode, match) => {
|
|
71
|
+
const [, style, content] = match;
|
|
72
|
+
const newNode = $createTextNode(content);
|
|
73
|
+
|
|
74
|
+
// Preserve existing format (bold/underline) from the original node
|
|
75
|
+
newNode.setFormat(textNode.getFormat());
|
|
76
|
+
newNode.setStyle(style);
|
|
77
|
+
textNode.replace(newNode);
|
|
78
|
+
return newNode;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const UNDERLINE_TRANSFORMER: TextMatchTransformer = {
|
|
83
|
+
type: 'text-match',
|
|
84
|
+
trigger: '',
|
|
85
|
+
regExp: /<ins>(.*?)<\/ins>/,
|
|
86
|
+
importRegExp: /<ins>(.*?)<\/ins>/,
|
|
87
|
+
dependencies: [],
|
|
88
|
+
replace: (textNode, match) => {
|
|
89
|
+
const newNode = $createTextNode(match[1]);
|
|
90
|
+
newNode.setFormat(textNode.getFormat());
|
|
91
|
+
if (!newNode.hasFormat('underline')) {
|
|
92
|
+
newNode.toggleFormat('underline');
|
|
93
|
+
}
|
|
94
|
+
textNode.replace(newNode);
|
|
95
|
+
return newNode;
|
|
96
|
+
},
|
|
97
|
+
export: (node) => {
|
|
98
|
+
if (!$isTextNode(node) || !node.hasFormat('underline')) return null;
|
|
99
|
+
return `<ins>${node.getTextContent()}</ins>`;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getAlignment = (style: string) => {
|
|
104
|
+
const alignmentRegex = /text-align:\s*(\w+)/i;
|
|
105
|
+
const alignmentMatch = alignmentRegex.exec(style);
|
|
106
|
+
return alignmentMatch ? (alignmentMatch[1].trim() as ElementFormatType) : null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const ALIGNMENT_TRANSFORMER: ElementTransformer = {
|
|
110
|
+
type: 'element',
|
|
111
|
+
dependencies: [],
|
|
112
|
+
regExp: /<div\s+style="([^"]+)">(.*?)<\/div>/,
|
|
113
|
+
replace: (parentNode, children, match) => {
|
|
114
|
+
const alignment = getAlignment(match[1]);
|
|
115
|
+
if (!alignment) return false;
|
|
116
|
+
|
|
117
|
+
if (!match[2]) return;
|
|
118
|
+
|
|
119
|
+
const child = children[0];
|
|
120
|
+
if ($isTextNode(child)) {
|
|
121
|
+
child.setTextContent(match[2]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
parentNode.setFormat(alignment);
|
|
125
|
+
parentNode.append(...children);
|
|
126
|
+
},
|
|
127
|
+
export: (node, exportChildren) => {
|
|
128
|
+
if (!$isParagraphNode(node)) return null;
|
|
129
|
+
const alignment = node.getFormatType();
|
|
130
|
+
if (!alignment || alignment === 'left') return null;
|
|
131
|
+
|
|
132
|
+
const children = exportChildren(node);
|
|
133
|
+
return `<div style="text-align: ${alignment}">${children}</div>`;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const IMAGE_EXPORT_TRANSFORMER: TextMatchTransformer = {
|
|
138
|
+
type: 'text-match',
|
|
139
|
+
trigger: '',
|
|
140
|
+
regExp: /./,
|
|
141
|
+
importRegExp: /./,
|
|
142
|
+
dependencies: [ImageNode],
|
|
143
|
+
export: (node) => {
|
|
144
|
+
if (!$isImageNode(node)) return null;
|
|
145
|
+
return `<img src="${node.__src}" alt="${node.__altText}" />`;
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const IMAGE_IMPORT_TRANSFORMER: TextMatchTransformer = {
|
|
150
|
+
type: 'text-match',
|
|
151
|
+
trigger: '',
|
|
152
|
+
regExp: /<img\s+src="([^"]+)"\s+alt="([^"]*)"[^>]*\/?>/,
|
|
153
|
+
importRegExp: /<img\s+src="([^"]+)"\s+alt="([^"]*)"[^>]*\/?>/,
|
|
154
|
+
dependencies: [ImageNode],
|
|
155
|
+
replace: (textNode, match) => {
|
|
156
|
+
const [, src, alt] = match;
|
|
157
|
+
const imageNode = $createImageNode(src, alt);
|
|
158
|
+
textNode.replace(imageNode);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export const EXPORT_TRANSFORMERS = [
|
|
163
|
+
...TRANSFORMERS,
|
|
164
|
+
FONT_STYLE_EXPORT,
|
|
165
|
+
UNDERLINE_TRANSFORMER,
|
|
166
|
+
ALIGNMENT_TRANSFORMER,
|
|
167
|
+
IMAGE_EXPORT_TRANSFORMER,
|
|
168
|
+
];
|
|
169
|
+
export const IMPORT_TRANSFORMERS = [
|
|
170
|
+
...TRANSFORMERS,
|
|
171
|
+
FONT_STYLE_IMPORT,
|
|
172
|
+
UNDERLINE_TRANSFORMER,
|
|
173
|
+
ALIGNMENT_TRANSFORMER,
|
|
174
|
+
IMAGE_IMPORT_TRANSFORMER,
|
|
175
|
+
];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { $generateNodesFromDOM } from '@lexical/html';
|
|
2
|
+
import { type LexicalEditor, type LexicalNode } from 'lexical';
|
|
3
|
+
import {
|
|
4
|
+
$getRoot,
|
|
5
|
+
$isTextNode,
|
|
6
|
+
$createParagraphNode,
|
|
7
|
+
$createRangeSelection,
|
|
8
|
+
$setSelection,
|
|
9
|
+
$selectAll,
|
|
10
|
+
$getSelection,
|
|
11
|
+
$isRangeSelection,
|
|
12
|
+
} from 'lexical';
|
|
13
|
+
|
|
14
|
+
export function scrollRichTextAreaToBottom(editor: LexicalEditor): void {
|
|
15
|
+
const rootElement = editor.getRootElement();
|
|
16
|
+
if (!rootElement) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
rootElement.scrollTop = rootElement.scrollHeight;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function $setSelectionToEnd() {
|
|
23
|
+
const root = $getRoot();
|
|
24
|
+
const lastDescendant = root.getLastDescendant();
|
|
25
|
+
|
|
26
|
+
if (lastDescendant && $isTextNode(lastDescendant)) {
|
|
27
|
+
const selection = $createRangeSelection();
|
|
28
|
+
const endOffset = lastDescendant.getTextContentSize();
|
|
29
|
+
selection.anchor.set(lastDescendant.getKey(), endOffset, 'text');
|
|
30
|
+
selection.focus.set(lastDescendant.getKey(), endOffset, 'text');
|
|
31
|
+
$setSelection(selection);
|
|
32
|
+
} else {
|
|
33
|
+
$selectAll();
|
|
34
|
+
const selection = $getSelection();
|
|
35
|
+
if ($isRangeSelection(selection)) {
|
|
36
|
+
const focusNode = selection.focus.getNode();
|
|
37
|
+
const focusOffset = $isTextNode(focusNode) ? focusNode.getTextContentSize() : 0;
|
|
38
|
+
selection.anchor.set(selection.focus.key, selection.focus.offset, selection.focus.type);
|
|
39
|
+
selection.focus.set(selection.focus.key, focusOffset, selection.focus.type);
|
|
40
|
+
$setSelection(selection);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getHTMLNodesFromValue(editor: LexicalEditor, html: string): LexicalNode[] {
|
|
46
|
+
const parser = new DOMParser();
|
|
47
|
+
const dom = parser.parseFromString(html, 'text/html');
|
|
48
|
+
const nodes = $generateNodesFromDOM(editor, dom);
|
|
49
|
+
|
|
50
|
+
return nodes.map((node) => {
|
|
51
|
+
if ($isTextNode(node)) {
|
|
52
|
+
const p = $createParagraphNode();
|
|
53
|
+
p.append(node);
|
|
54
|
+
return p;
|
|
55
|
+
}
|
|
56
|
+
return node;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function $replaceEditorHTMLContent(editor: LexicalEditor, html: string): void {
|
|
61
|
+
const root = $getRoot();
|
|
62
|
+
root.clear();
|
|
63
|
+
getHTMLNodesFromValue(editor, html).forEach((node) => root.append(node));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function $replaceEditorSelectionHTMLContent(editor: LexicalEditor, html: string): void {
|
|
67
|
+
const selection = $getSelection();
|
|
68
|
+
const nodes = getHTMLNodesFromValue(editor, html);
|
|
69
|
+
|
|
70
|
+
if ($isRangeSelection(selection)) {
|
|
71
|
+
selection.insertNodes(nodes);
|
|
72
|
+
} else {
|
|
73
|
+
const root = $getRoot();
|
|
74
|
+
root.clear();
|
|
75
|
+
nodes.forEach((node) => root.append(node));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { mergeRegister } from '@lexical/utils';
|
|
2
|
+
import {
|
|
3
|
+
$getSelection,
|
|
4
|
+
$isElementNode,
|
|
5
|
+
$isRangeSelection,
|
|
6
|
+
COMMAND_PRIORITY_LOW,
|
|
7
|
+
FORMAT_ELEMENT_COMMAND,
|
|
8
|
+
type ElementFormatType,
|
|
9
|
+
SELECTION_CHANGE_COMMAND,
|
|
10
|
+
} from 'lexical';
|
|
11
|
+
import { type ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
FormatAlignCenterIcon,
|
|
15
|
+
FormatAlignLeftIcon,
|
|
16
|
+
FormatAlignRightIcon,
|
|
17
|
+
} from '@swisper.ai/icons';
|
|
18
|
+
import { cn } from '@swisper.ai/web-core';
|
|
19
|
+
|
|
20
|
+
import { useRichTextAreaEditor } from '../../rich-text-area/hooks';
|
|
21
|
+
import { DEFAULT_ALIGNMENT } from '../constants';
|
|
22
|
+
import { type RichTextFieldAlignment } from '../context';
|
|
23
|
+
|
|
24
|
+
import { ToolbarSelect } from './toolbar-select';
|
|
25
|
+
|
|
26
|
+
function toAlignment(format: ElementFormatType): RichTextFieldAlignment {
|
|
27
|
+
if (format === 'center' || format === 'right') {
|
|
28
|
+
return format;
|
|
29
|
+
}
|
|
30
|
+
if (format === 'end') {
|
|
31
|
+
return 'right';
|
|
32
|
+
}
|
|
33
|
+
return 'left';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ALIGNMENT_OPTIONS_MAP: Record<RichTextFieldAlignment, { label: string; icon: ReactNode }> = {
|
|
37
|
+
left: { label: 'Left', icon: <FormatAlignLeftIcon fontSize="inherit" /> },
|
|
38
|
+
center: { label: 'Center', icon: <FormatAlignCenterIcon fontSize="inherit" /> },
|
|
39
|
+
right: { label: 'Right', icon: <FormatAlignRightIcon fontSize="inherit" /> },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface AlignmentSelectProps {
|
|
43
|
+
className?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function AlignmentSelect({ className }: AlignmentSelectProps) {
|
|
47
|
+
const editor = useRichTextAreaEditor();
|
|
48
|
+
const [value, setValue] = useState<RichTextFieldAlignment>(DEFAULT_ALIGNMENT);
|
|
49
|
+
|
|
50
|
+
const options = useMemo(
|
|
51
|
+
() =>
|
|
52
|
+
Object.entries(ALIGNMENT_OPTIONS_MAP).map(([value, { label, icon }]) => ({
|
|
53
|
+
value: value as RichTextFieldAlignment,
|
|
54
|
+
label,
|
|
55
|
+
icon,
|
|
56
|
+
})),
|
|
57
|
+
[],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const $updateValue = useCallback(() => {
|
|
61
|
+
const selection = $getSelection();
|
|
62
|
+
if ($isRangeSelection(selection)) {
|
|
63
|
+
const node = selection.anchor.getNode();
|
|
64
|
+
const parent = node.getParent();
|
|
65
|
+
const element = $isElementNode(node) ? node : parent;
|
|
66
|
+
if ($isElementNode(element)) {
|
|
67
|
+
setValue(toAlignment(element.getFormatType() || DEFAULT_ALIGNMENT));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
return mergeRegister(
|
|
74
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
75
|
+
editorState.read(() => {
|
|
76
|
+
$updateValue();
|
|
77
|
+
});
|
|
78
|
+
}),
|
|
79
|
+
editor.registerCommand(
|
|
80
|
+
SELECTION_CHANGE_COMMAND,
|
|
81
|
+
() => {
|
|
82
|
+
$updateValue();
|
|
83
|
+
return false;
|
|
84
|
+
},
|
|
85
|
+
COMMAND_PRIORITY_LOW,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}, [editor, $updateValue]);
|
|
89
|
+
|
|
90
|
+
function handleChange(value: string) {
|
|
91
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, value as ElementFormatType);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<ToolbarSelect
|
|
96
|
+
shouldShowOnlyIcon
|
|
97
|
+
options={options}
|
|
98
|
+
value={value}
|
|
99
|
+
onChange={handleChange}
|
|
100
|
+
className={cn('w-[56px]!', className)}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AttachmentsIcon } from '@swisper.ai/icons';
|
|
2
|
+
|
|
3
|
+
import { useRichTextAreaEditor } from '../../rich-text-area/hooks';
|
|
4
|
+
import { ATTACH_FILE_COMMAND } from '../../rich-text-area/plugins/file-attachment-plugin';
|
|
5
|
+
|
|
6
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
7
|
+
|
|
8
|
+
export function AttachmentButton(props: ToolbarButtonProps) {
|
|
9
|
+
const editor = useRichTextAreaEditor();
|
|
10
|
+
|
|
11
|
+
function handleClick() {
|
|
12
|
+
editor.dispatchCommand(ATTACH_FILE_COMMAND, undefined);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<ToolbarButton
|
|
17
|
+
data-testid="attachment-button"
|
|
18
|
+
aria-label="Add Attachment"
|
|
19
|
+
onClick={handleClick}
|
|
20
|
+
{...props}
|
|
21
|
+
>
|
|
22
|
+
<AttachmentsIcon />
|
|
23
|
+
</ToolbarButton>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FormatBoldIcon } from '@swisper.ai/icons';
|
|
2
|
+
|
|
3
|
+
import { useRichTextFieldContext } from '../context';
|
|
4
|
+
|
|
5
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
6
|
+
|
|
7
|
+
export function BoldButton({ ...props }: ToolbarButtonProps) {
|
|
8
|
+
const { isBold, onBold } = useRichTextFieldContext();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<ToolbarButton
|
|
12
|
+
data-testid="bold-button"
|
|
13
|
+
aria-label="Format Bold"
|
|
14
|
+
isActive={isBold}
|
|
15
|
+
onClick={onBold}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
<FormatBoldIcon />
|
|
19
|
+
</ToolbarButton>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
2
|
+
import { $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
import { FormatCleanIcon } from '@swisper.ai/icons';
|
|
6
|
+
|
|
7
|
+
import { useRichTextAreaEditor } from '../../rich-text-area/hooks';
|
|
8
|
+
import { $patchSelectedTextStyle, NO_STYLE } from '../utils';
|
|
9
|
+
|
|
10
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
11
|
+
|
|
12
|
+
export function CleanFormatButton({ ...props }: ToolbarButtonProps) {
|
|
13
|
+
const editor = useRichTextAreaEditor();
|
|
14
|
+
|
|
15
|
+
const handleClick = useCallback(() => {
|
|
16
|
+
editor.update(() => {
|
|
17
|
+
const selection = $getSelection();
|
|
18
|
+
if ($isRangeSelection(selection)) {
|
|
19
|
+
$patchSelectedTextStyle(() => NO_STYLE);
|
|
20
|
+
|
|
21
|
+
for (const node of selection.extract()) {
|
|
22
|
+
if ($isTextNode(node)) {
|
|
23
|
+
node.setFormat(0);
|
|
24
|
+
node.setStyle('');
|
|
25
|
+
|
|
26
|
+
const blockElement = $getNearestBlockElementAncestorOrThrow(node);
|
|
27
|
+
blockElement.setFormat('');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}, [editor]);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ToolbarButton
|
|
36
|
+
data-testid="clean-format-button"
|
|
37
|
+
aria-label="Reset Formatting"
|
|
38
|
+
onClick={handleClick}
|
|
39
|
+
{...props}
|
|
40
|
+
>
|
|
41
|
+
<FormatCleanIcon />
|
|
42
|
+
</ToolbarButton>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Divider } from '@swisper.ai/ui';
|
|
4
|
+
import { cn } from '@swisper.ai/web-core';
|
|
5
|
+
|
|
6
|
+
import { AlignmentSelect } from './alignment-select';
|
|
7
|
+
import { AttachmentButton } from './attachment-button';
|
|
8
|
+
import { BoldButton } from './bold-button';
|
|
9
|
+
import { CleanFormatButton } from './clean-format-button';
|
|
10
|
+
import { ImageButton } from './image-button';
|
|
11
|
+
import { ItalicButton } from './italic-button';
|
|
12
|
+
import { LinkButton } from './link-button';
|
|
13
|
+
import { SizeSelect } from './size-select';
|
|
14
|
+
import { TextColorButton } from './text-color-button';
|
|
15
|
+
import { TypographySelect } from './typography-select';
|
|
16
|
+
import { UnderlineButton } from './underline-button';
|
|
17
|
+
|
|
18
|
+
interface FormattingToolbarPluginProps {
|
|
19
|
+
className?: string;
|
|
20
|
+
children?: ({ hasAttachments }: { hasAttachments: boolean }) => ReactNode;
|
|
21
|
+
hasAttachments?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DefaultFormattingToolbarChildren = ({ hasAttachments }: { hasAttachments: boolean }) => (
|
|
25
|
+
<>
|
|
26
|
+
<TypographySelect />
|
|
27
|
+
<SizeSelect />
|
|
28
|
+
|
|
29
|
+
<Divider orientation="vertical" />
|
|
30
|
+
|
|
31
|
+
<BoldButton />
|
|
32
|
+
<ItalicButton />
|
|
33
|
+
<UnderlineButton />
|
|
34
|
+
<TextColorButton />
|
|
35
|
+
|
|
36
|
+
<Divider orientation="vertical" />
|
|
37
|
+
<LinkButton isDisabled />
|
|
38
|
+
<AttachmentButton isDisabled={!hasAttachments} />
|
|
39
|
+
<ImageButton isDisabled />
|
|
40
|
+
|
|
41
|
+
<Divider orientation="vertical" />
|
|
42
|
+
|
|
43
|
+
<AlignmentSelect />
|
|
44
|
+
|
|
45
|
+
<Divider orientation="vertical" />
|
|
46
|
+
|
|
47
|
+
<CleanFormatButton />
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export function FormattingToolbarPlugin({
|
|
52
|
+
className,
|
|
53
|
+
children = DefaultFormattingToolbarChildren,
|
|
54
|
+
hasAttachments = false,
|
|
55
|
+
}: FormattingToolbarPluginProps) {
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
data-testid="formatting-toolbar"
|
|
59
|
+
className={cn(
|
|
60
|
+
'flex items-center gap-[2px]',
|
|
61
|
+
'px-[16px] py-[8px] overflow-x-auto',
|
|
62
|
+
'bg-paper-elevation-1 border-b border-divider-border-base',
|
|
63
|
+
className,
|
|
64
|
+
)}
|
|
65
|
+
>
|
|
66
|
+
{children({ hasAttachments })}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ImageIcon } from '@swisper.ai/icons';
|
|
2
|
+
|
|
3
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
4
|
+
|
|
5
|
+
export function ImageButton({ ...props }: ToolbarButtonProps) {
|
|
6
|
+
return (
|
|
7
|
+
<ToolbarButton data-testid="image-button" aria-label="Add Image" {...props}>
|
|
8
|
+
<ImageIcon />
|
|
9
|
+
</ToolbarButton>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { FormattingToolbarPlugin } from './formatting-toolbar-plugin';
|
|
2
|
+
|
|
3
|
+
export { SizeSelect } from './size-select';
|
|
4
|
+
export { TypographySelect } from './typography-select';
|
|
5
|
+
export { AlignmentSelect } from './alignment-select';
|
|
6
|
+
export { BoldButton } from './bold-button';
|
|
7
|
+
export { ItalicButton } from './italic-button';
|
|
8
|
+
export { UnderlineButton } from './underline-button';
|
|
9
|
+
export { TextColorButton } from './text-color-button';
|
|
10
|
+
export { LinkButton } from './link-button';
|
|
11
|
+
export { AttachmentButton } from './attachment-button';
|
|
12
|
+
export { ImageButton } from './image-button';
|
|
13
|
+
export { CleanFormatButton } from './clean-format-button';
|
|
14
|
+
export { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FormatItalicIcon } from '@swisper.ai/icons';
|
|
2
|
+
|
|
3
|
+
import { useRichTextFieldContext } from '../context';
|
|
4
|
+
|
|
5
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
6
|
+
|
|
7
|
+
export function ItalicButton({ ...props }: ToolbarButtonProps) {
|
|
8
|
+
const { isItalic, onItalic } = useRichTextFieldContext();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<ToolbarButton
|
|
12
|
+
data-testid="italic-button"
|
|
13
|
+
aria-label="Format Italics"
|
|
14
|
+
isActive={isItalic}
|
|
15
|
+
onClick={onItalic}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
<FormatItalicIcon />
|
|
19
|
+
</ToolbarButton>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LinkOnIcon, LinkOffIcon } from '@swisper.ai/icons';
|
|
2
|
+
|
|
3
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
4
|
+
|
|
5
|
+
export function LinkButton({ isActive, ...props }: ToolbarButtonProps) {
|
|
6
|
+
return (
|
|
7
|
+
<ToolbarButton data-testid="link-button" aria-label="Add Link" {...props}>
|
|
8
|
+
{isActive ? <LinkOnIcon /> : <LinkOffIcon />}
|
|
9
|
+
</ToolbarButton>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@swisper.ai/web-core';
|
|
4
|
+
|
|
5
|
+
import { FONT_SIZE_OPTIONS } from '../constants';
|
|
6
|
+
import { useRichTextFieldContext } from '../context';
|
|
7
|
+
|
|
8
|
+
import { ToolbarSelect } from './toolbar-select';
|
|
9
|
+
|
|
10
|
+
export interface SizeSelectProps {
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SizeSelect({ className }: SizeSelectProps) {
|
|
15
|
+
const { fontSize, onFontSize } = useRichTextFieldContext();
|
|
16
|
+
const options = useMemo(() => [...FONT_SIZE_OPTIONS], []);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ToolbarSelect
|
|
20
|
+
data-testid="size-select"
|
|
21
|
+
options={options}
|
|
22
|
+
value={fontSize}
|
|
23
|
+
onChange={onFontSize}
|
|
24
|
+
className={cn('w-[72px] gap-0', className)}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ChangeEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FormatColorIcon } from '@swisper.ai/icons';
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_TEXT_COLOR } from '../constants';
|
|
6
|
+
import { useRichTextFieldContext } from '../context';
|
|
7
|
+
|
|
8
|
+
import { ToolbarButton, type ToolbarButtonProps } from './toolbar-button';
|
|
9
|
+
|
|
10
|
+
export function TextColorButton({ ...props }: ToolbarButtonProps) {
|
|
11
|
+
const { textColor, onTextColor } = useRichTextFieldContext();
|
|
12
|
+
const isDefaultColor = textColor === DEFAULT_TEXT_COLOR;
|
|
13
|
+
|
|
14
|
+
function handleColorChange(e: ChangeEvent<HTMLInputElement>) {
|
|
15
|
+
onTextColor(e.target.value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div style={{ position: 'relative' }}>
|
|
20
|
+
<ToolbarButton data-testid="text-color-button" aria-label="Text Color" {...props}>
|
|
21
|
+
<span style={!isDefaultColor ? { color: textColor } : {}}>
|
|
22
|
+
<FormatColorIcon />
|
|
23
|
+
</span>
|
|
24
|
+
</ToolbarButton>
|
|
25
|
+
<input
|
|
26
|
+
type="color"
|
|
27
|
+
value={textColor}
|
|
28
|
+
onChange={handleColorChange}
|
|
29
|
+
tabIndex={-1}
|
|
30
|
+
style={{
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
inset: 0,
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: '100%',
|
|
35
|
+
opacity: 0,
|
|
36
|
+
cursor: 'pointer',
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IconButton, type IconButtonProps } from '@swisper.ai/ui';
|
|
2
|
+
import { cn } from '@swisper.ai/web-core';
|
|
3
|
+
|
|
4
|
+
export interface ToolbarButtonProps extends IconButtonProps {
|
|
5
|
+
isActive?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function ToolbarButton({
|
|
9
|
+
className,
|
|
10
|
+
children,
|
|
11
|
+
isActive,
|
|
12
|
+
isDisabled = false,
|
|
13
|
+
...rest
|
|
14
|
+
}: ToolbarButtonProps) {
|
|
15
|
+
return (
|
|
16
|
+
<IconButton
|
|
17
|
+
isActive={isActive}
|
|
18
|
+
className={cn('border-none bg-transparent', className)}
|
|
19
|
+
size="sm"
|
|
20
|
+
variant="tertiary"
|
|
21
|
+
isDisabled={isDisabled}
|
|
22
|
+
{...rest}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
</IconButton>
|
|
26
|
+
);
|
|
27
|
+
}
|