@zenify-omni/chat-ui-react-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +92 -0
- package/assets/asset-url.js +6 -0
- package/assets/icons/chatter_agent.js +27 -0
- package/assets/icons/chatter_chatbot.js +43 -0
- package/assets/icons/chatter_contact.js +36 -0
- package/assets/icons/email_icon.png +0 -0
- package/assets/icons/emoji/angry.svg +56 -0
- package/assets/icons/emoji/haha.svg +20 -0
- package/assets/icons/emoji/like.svg +10 -0
- package/assets/icons/emoji/like_out_line.png +0 -0
- package/assets/icons/emoji/love.svg +10 -0
- package/assets/icons/emoji/sad.svg +46 -0
- package/assets/icons/emoji/wow.svg +51 -0
- package/assets/icons/instagram.js +29 -0
- package/assets/icons/not_found.png +0 -0
- package/assets/icons/not_found_template.svg +9 -0
- package/assets/icons/phone_icon.png +0 -0
- package/assets/icons/shopee.js +17 -0
- package/assets/icons/sms_icon.png +0 -0
- package/assets/icons/tiktok.js +17 -0
- package/assets/icons/whatsapp.js +28 -0
- package/assets/icons/zalo.js +17 -0
- package/assets/icons/zalo_icon.png +0 -0
- package/assets/icons/zns_icon.png +0 -0
- package/assets/images/emoji.webp +0 -0
- package/assets/images/error.png +0 -0
- package/assets/images/menu.png +0 -0
- package/assets/images/money.png +0 -0
- package/assets/images/success.png +0 -0
- package/assets/public-urls.js +78 -0
- package/components/campaign-detail-route/select/group.js +38 -0
- package/components/campaign-detail-route/select/multi-groups.js +43 -0
- package/components/chat-route/chat-box/ads-context-card.js +143 -0
- package/components/chat-route/chat-box/chat-drop-file.js +18 -0
- package/components/chat-route/chat-box/chat-feedback/chat-insight.js +214 -0
- package/components/chat-route/chat-box/chat-feedback/index.js +127 -0
- package/components/chat-route/chat-box/chat-header-actions-inline.js +1055 -0
- package/components/chat-route/chat-box/chat-header.js +465 -0
- package/components/chat-route/chat-box/chat-input.js +1164 -0
- package/components/chat-route/chat-box/chat-message-action.js +399 -0
- package/components/chat-route/chat-box/chat-message-list.js +995 -0
- package/components/chat-route/chat-box/chat-message.js +2099 -0
- package/components/chat-route/chat-box/chat-reply-preview.js +317 -0
- package/components/chat-route/chat-box/common-groups-modal.js +430 -0
- package/components/chat-route/chat-box/constants.js +29 -0
- package/components/chat-route/chat-box/contact-card/index.js +87 -0
- package/components/chat-route/chat-box/edit-customer-alias-dialog.js +197 -0
- package/components/chat-route/chat-box/emoji-picker-combined.js +91 -0
- package/components/chat-route/chat-box/emoji-sprite.js +45 -0
- package/components/chat-route/chat-box/emojiMap.js +92 -0
- package/components/chat-route/chat-box/facebook-reconnect-notice.js +49 -0
- package/components/chat-route/chat-box/forward-message-modal.js +659 -0
- package/components/chat-route/chat-box/index.js +165 -0
- package/components/chat-route/chat-box/message-time.js +44 -0
- package/components/chat-route/chat-box/message-viewers.js +114 -0
- package/components/chat-route/chat-box/pasted-file-preview.js +138 -0
- package/components/chat-route/chat-box/pinned-messages.js +255 -0
- package/components/chat-route/chat-box/react-message/react-preview.js +83 -0
- package/components/chat-route/chat-box/react-message/reaction-button.js +200 -0
- package/components/chat-route/chat-box/right-side/chat-history.js +142 -0
- package/components/chat-route/chat-box/right-side/chat-tag-selector.js +232 -0
- package/components/chat-route/chat-box/right-side/create-personal-tag-modal.js +458 -0
- package/components/chat-route/chat-box/right-side/customer/customer-info-item.js +60 -0
- package/components/chat-route/chat-box/right-side/in-room-dialog.js +225 -0
- package/components/chat-route/chat-box/right-side/zalo-group/add-friend-dialog.js +154 -0
- package/components/chat-route/chat-box/right-side/zalo-group/send-message-dialog.js +165 -0
- package/components/chat-route/chat-box/send-contact-card-modal.js +102 -0
- package/components/chat-route/chat-box/send-contact-card.js +80 -0
- package/components/chat-route/chat-box/text-content.js +400 -0
- package/components/chat-route/chat-box/use-facebook-page-invalid.js +22 -0
- package/components/chat-route/chat-box/zalo-emoji-decoration.js +98 -0
- package/components/chat-route/chat-box/zalo-emoji-picker.js +74 -0
- package/components/chat-route/chat-box/zalo-personal-editor.js +590 -0
- package/components/chat-route/chat-box/zalo-reminder/create-zalo-reminder.js +868 -0
- package/components/chat-route/chat-box/zalo-reminder/use-send-zalo-reminder.js +98 -0
- package/components/chat-route/chat-box/zalo-reminder/zalo-reminder-content.js +294 -0
- package/components/chat-route/chat-box/zalo-rtf-utils.js +422 -0
- package/components/chat-route/chat-list/action-chat-item.js +116 -0
- package/components/chat-route/chat-list/assign-agent-dialog.js +170 -0
- package/components/chat-route/chat-list/assign-tag-dialog.js +242 -0
- package/components/chat-route/chat-list/chat-item-tags.js +105 -0
- package/components/chat-route/chat-list/chat-item.js +749 -0
- package/components/chat-route/chat-list/chat-list-item.js +370 -0
- package/components/chat-route/chat-list/chat-list-selection-bar.js +426 -0
- package/components/chat-route/chat-list/chat-search-preview.js +48 -0
- package/components/chat-route/chat-list/chat-sort-menu.js +89 -0
- package/components/chat-route/chat-list/edit-filter-modal.js +468 -0
- package/components/chat-route/chat-list/filter-chat-sources.js +222 -0
- package/components/chat-route/chat-list/filter-chat.js +501 -0
- package/components/chat-route/chat-list/filter-criteria-rows.js +845 -0
- package/components/chat-route/chat-list/filter-group-select.js +66 -0
- package/components/chat-route/chat-list/filter-pin-menu.js +165 -0
- package/components/chat-route/chat-list/friend-request/list-friend-request.js +287 -0
- package/components/chat-route/chat-list/index.js +243 -0
- package/components/chat-route/chat-list/inline-search-results.js +178 -0
- package/components/chat-route/chat-list/post-ids-field.js +104 -0
- package/components/chat-route/chat-list/quick-filter-bar.js +391 -0
- package/components/chat-route/chat-list/save-filter-popover.js +258 -0
- package/components/chat-route/chat-list/search-messages/index.js +225 -0
- package/components/chat-route/chat-list/search-result-header.js +51 -0
- package/components/chat-route/chat-list/util.js +604 -0
- package/components/chat-route/chat-toolbar.js +108 -0
- package/components/chat-route/hooks/use-reassign.js +111 -0
- package/components/chat-route/shared/close-conversation-dialog.js +111 -0
- package/components/chat-route/shared/force-transfer-dialog.js +109 -0
- package/components/chat-route/shared/in-queue-confirm-dialog.js +40 -0
- package/components/chat-route/util.js +146 -0
- package/components/chat-route/zalo/modal-action-zalo.js +76 -0
- package/components/chat-route/zalo/modal-add-friend-zalo.js +277 -0
- package/components/custom/SafeHTML.js +45 -0
- package/components/custom/audio-player.js +81 -0
- package/components/custom/avatar.js +95 -0
- package/components/custom/between-date-picker/index.js +86 -0
- package/components/custom/button-close.js +28 -0
- package/components/custom/button.js +80 -0
- package/components/custom/color-picker.js +81 -0
- package/components/custom/combobox.js +168 -0
- package/components/custom/custom-dialog.js +44 -0
- package/components/custom/custom-select.js +256 -0
- package/components/custom/cycle-value-helpers.js +11 -0
- package/components/custom/cycle-value.js +93 -0
- package/components/custom/date-time-picker/components/date-time-group.js +44 -0
- package/components/custom/date-time-picker/components/date-time-input.js +383 -0
- package/components/custom/date-time-picker/components/date-time-unit-input.js +138 -0
- package/components/custom/date-time-picker/components/month-year-picker.js +232 -0
- package/components/custom/date-time-picker/hooks/use-merge-refs.js +18 -0
- package/components/custom/date-time-picker/hooks/use-scroll-to-center.js +18 -0
- package/components/custom/date-time-picker/index.js +348 -0
- package/components/custom/field-file-upload/files-upload.js +87 -0
- package/components/custom/field-file-upload/image-upload.js +115 -0
- package/components/custom/field-file-upload/preview-images-modal.js +284 -0
- package/components/custom/field-file-upload/preview-list-file.js +134 -0
- package/components/custom/field-file-upload/preview-list-image.js +108 -0
- package/components/custom/field-file-upload/upload-custom.js +222 -0
- package/components/custom/field-generator.js +639 -0
- package/components/custom/field-layout-popover.js +304 -0
- package/components/custom/file-preview-modal.js +351 -0
- package/components/custom/html-edtior.js +100 -0
- package/components/custom/icon.js +49 -0
- package/components/custom/infinite-scroll-combobox.js +253 -0
- package/components/custom/inline-edit-popover.js +90 -0
- package/components/custom/inputs/calendar-input.js +0 -0
- package/components/custom/inputs/chip-input.js +136 -0
- package/components/custom/inputs/file-input.js +71 -0
- package/components/custom/inputs/mask-data/mask-data-input.js +80 -0
- package/components/custom/inputs/mask-data/mask-data-select.js +78 -0
- package/components/custom/inputs/mask-data/mask-data-textarea.js +75 -0
- package/components/custom/inputs/mask-data/reconcile-masked-edit.js +20 -0
- package/components/custom/jxl-decode.js +34 -0
- package/components/custom/jxl-image.js +68 -0
- package/components/custom/jxl-worker.js +12 -0
- package/components/custom/label.js +55 -0
- package/components/custom/layout.js +30 -0
- package/components/custom/multi-select-search-cc.js +179 -0
- package/components/custom/multiple-select-setting-tags.js +404 -0
- package/components/custom/multiple-selector.js +821 -0
- package/components/custom/pagination.js +95 -0
- package/components/custom/popup-confirm.js +120 -0
- package/components/custom/previews/facebook/facebook-appointment-booking-preview.js +83 -0
- package/components/custom/previews/facebook/facebook-audio-preview.js +130 -0
- package/components/custom/previews/facebook/facebook-event-preview.js +72 -0
- package/components/custom/previews/facebook/facebook-file-preview.js +95 -0
- package/components/custom/previews/facebook/facebook-group-preview.js +103 -0
- package/components/custom/previews/facebook/facebook-image-preview.js +81 -0
- package/components/custom/previews/facebook/facebook-page-preview.js +85 -0
- package/components/custom/previews/facebook/facebook-post-preview.js +77 -0
- package/components/custom/previews/facebook/facebook-reel-preview.js +83 -0
- package/components/custom/previews/facebook/facebook-sticker-preview.js +23 -0
- package/components/custom/previews/facebook/facebook-video-preview.js +114 -0
- package/components/custom/previews/facebook/index.js +24 -0
- package/components/custom/previews/file-preview.js +747 -0
- package/components/custom/previews/image-preview.js +288 -0
- package/components/custom/previews/instagram/index.js +4 -0
- package/components/custom/previews/instagram/instagram-share-post-preview.js +77 -0
- package/components/custom/previews/link-preview.js +166 -0
- package/components/custom/previews/product-preview.js +334 -0
- package/components/custom/previews/tiktok-order-preview.js +278 -0
- package/components/custom/previews/tiktok-product-preview.js +321 -0
- package/components/custom/previews/tiktok-voucher-preview.js +151 -0
- package/components/custom/previews/whatsapp/index.js +10 -0
- package/components/custom/previews/whatsapp/whatsapp-contact-card-preview.js +150 -0
- package/components/custom/previews/whatsapp/whatsapp-order-preview.js +38 -0
- package/components/custom/previews/whatsapp/whatsapp-poll-preview.js +29 -0
- package/components/custom/previews/whatsapp/whatsapp-product-preview.js +29 -0
- package/components/custom/retry-image.js +44 -0
- package/components/custom/search-input.js +26 -0
- package/components/custom/separator-with-text.js +14 -0
- package/components/custom/showToast.js +21 -0
- package/components/custom/sortable-header.js +62 -0
- package/components/custom/table-resize-line.js +92 -0
- package/components/custom/time-picker/index.js +73 -0
- package/components/custom/time-picker/time-picker-input.js +159 -0
- package/components/custom/time-picker/time-picker-utils.js +152 -0
- package/components/custom/viewers/audio-player.js +192 -0
- package/components/custom/viewers/code-viewer.js +140 -0
- package/components/custom/viewers/csv-viewer.js +174 -0
- package/components/custom/viewers/docx-viewer.js +145 -0
- package/components/custom/viewers/image-viewer.js +104 -0
- package/components/custom/viewers/markdown-viewer.js +124 -0
- package/components/custom/viewers/pdf-viewer.js +333 -0
- package/components/custom/viewers/spreadsheet-viewer.js +232 -0
- package/components/custom/viewers/unsupported-viewer.js +85 -0
- package/components/custom/viewers/video-player.js +241 -0
- package/components/customers-route/change-owner-modal.js +430 -0
- package/components/customers-route/contact-note-button.js +212 -0
- package/components/customers-route/customer-source.js +37 -0
- package/components/customers-route/table/columns.js +675 -0
- package/components/customers-route/table/edit-fields.js +125 -0
- package/components/customers-route/table/editable-cell.js +218 -0
- package/components/customers-route/table/note-cell.js +77 -0
- package/components/dialogs/invite-agent.js +677 -0
- package/components/error-boundary.js +53 -0
- package/components/leads-route/duplicate-phone-warning-toast.js +96 -0
- package/components/leads-route/table/columns.js +523 -0
- package/components/leads-route/table/contact-cell-name.js +82 -0
- package/components/leads-route/table/edit-fields.js +142 -0
- package/components/leads-route/table/editable-cell.js +228 -0
- package/components/org-tree/group-name-display.js +36 -0
- package/components/org-tree/group-tree-multi-select.js +208 -0
- package/components/org-tree/group-tree-select.js +220 -0
- package/components/posts-route/dialog-select-posts.js +284 -0
- package/components/reports-route/agents/multi-select-agents.js +55 -0
- package/components/reports-route/agents/multi-select-search-agents.js +43 -0
- package/components/settings-route/chat-layout/detail/constants.js +353 -0
- package/components/settings-route/chat-layout/detail/form.js +43 -0
- package/components/settings-route/chat-timeout/channel-multi-select.js +119 -0
- package/components/settings-route/multi-channel/facebook/hooks/use-facebook-sdk.js +3 -0
- package/components/settings-route/object-rule/util.js +79 -0
- package/components/settings-route/routing/settings-dialog.js +561 -0
- package/components/settings-route/switchboard/queue-new/constant.js +9 -0
- package/components/shared/linked-customer-fields/LinkedCustomerFields.js +91 -0
- package/components/shared/linked-customer-fields/use-linked-customer-fields.js +123 -0
- package/components/smartqc-route/qc-form/controls/multi-select-search-agents.js +50 -0
- package/components/ui/alert-dialog.js +112 -0
- package/components/ui/avatar.js +44 -0
- package/components/ui/badge.js +54 -0
- package/components/ui/button.js +48 -0
- package/components/ui/calendar.js +70 -0
- package/components/ui/card.js +58 -0
- package/components/ui/carousel.js +238 -0
- package/components/ui/checkbox.js +27 -0
- package/components/ui/command.js +111 -0
- package/components/ui/context-menu.js +154 -0
- package/components/ui/dialog.js +104 -0
- package/components/ui/dropdown-menu.js +169 -0
- package/components/ui/form.js +104 -0
- package/components/ui/input.js +115 -0
- package/components/ui/label.js +20 -0
- package/components/ui/popover.js +29 -0
- package/components/ui/radio-group.js +53 -0
- package/components/ui/scroll-area.js +38 -0
- package/components/ui/select.js +147 -0
- package/components/ui/separator.js +24 -0
- package/components/ui/sheet.js +113 -0
- package/components/ui/skeleton.js +17 -0
- package/components/ui/slider.js +26 -0
- package/components/ui/sonner.js +76 -0
- package/components/ui/switch.js +54 -0
- package/components/ui/table-v2.js +269 -0
- package/components/ui/table.js +245 -0
- package/components/ui/tabs.js +89 -0
- package/components/ui/textarea.js +33 -0
- package/components/ui/tooltip.js +40 -0
- package/components/workflow-editor/nodes/ticket/picker-field.js +233 -0
- package/components/zalo-login-qr.js +237 -0
- package/components/zalo-login-status-modal.js +45 -0
- package/config/env.js +27 -0
- package/config/hmr.js +8 -0
- package/config/navigation.js +54 -0
- package/config/runtime.js +46 -0
- package/config/theme.js +274 -0
- package/constants/brand-colors.js +32 -0
- package/constants/chat-icon.js +34 -0
- package/dist/chat.css +1 -0
- package/exceptions/throw-exception.js +15 -0
- package/hooks/use-chat-attachments.js +106 -0
- package/hooks/use-chat-configs.js +62 -0
- package/hooks/use-chat-customer.js +33 -0
- package/hooks/use-chat-display-config-sync.js +72 -0
- package/hooks/use-chat-permission.js +68 -0
- package/hooks/use-chat-room-detail.js +44 -0
- package/hooks/use-chat-selection.js +26 -0
- package/hooks/use-chat-sort.js +69 -0
- package/hooks/use-chat-surface.js +8 -0
- package/hooks/use-common-filter-options.js +70 -0
- package/hooks/use-crm-organization-filter-options.js +0 -0
- package/hooks/use-crm-organizations-data.js +23 -0
- package/hooks/use-debounce.js +14 -0
- package/hooks/use-dynamic-fields.js +7 -0
- package/hooks/use-facebook-notice.js +24 -0
- package/hooks/use-feature-flags.js +6 -0
- package/hooks/use-field-layout-override.js +46 -0
- package/hooks/use-file-upload.js +119 -0
- package/hooks/use-file-viewer.js +93 -0
- package/hooks/use-frozen-columns.js +29 -0
- package/hooks/use-horizontal-scroll.js +41 -0
- package/hooks/use-image-preview-queue.js +101 -0
- package/hooks/use-inline-editable-cell.js +97 -0
- package/hooks/use-intersection-observer.js +24 -0
- package/hooks/use-interval.js +20 -0
- package/hooks/use-latest-message-id.js +13 -0
- package/hooks/use-lead-filter-options.js +0 -0
- package/hooks/use-logout-listener.js +43 -0
- package/hooks/use-org-tree.js +43 -0
- package/hooks/use-permission.js +33 -0
- package/hooks/use-quick-filters.js +175 -0
- package/hooks/use-resizable-table.js +0 -0
- package/hooks/use-setting-common.js +389 -0
- package/hooks/use-settings.js +41 -0
- package/hooks/use-sort-bindings.js +24 -0
- package/hooks/use-table-display-config.js +0 -0
- package/hooks/use-tenant-config.js +99 -0
- package/hooks/use-update-user-config.js +150 -0
- package/hooks/use-zalo-connection.js +57 -0
- package/hooks/use-zalo-mention-list.js +31 -0
- package/index.css +624 -0
- package/index.js +100 -0
- package/lib/deal-name.js +27 -0
- package/lib/i18n/react.js +7 -0
- package/lib/i18n/use-language.js +0 -0
- package/lib/query-client.js +34 -0
- package/lib/utils.js +25 -0
- package/package.json +108 -0
- package/provider/chat-context.js +9 -0
- package/provider/chat-provider.js +177 -0
- package/provider/chat-room-context.js +9 -0
- package/provider/chat-room-hooks.js +8 -0
- package/provider/chat-room-provider.js +84 -0
- package/provider/hooks.js +22 -0
- package/provider/index.js +42 -0
- package/public/contact-card-user.svg +25 -0
- package/public/images/icons/facebook.svg +1 -0
- package/public/images/icons/instagram.svg +1 -0
- package/public/images/icons/shopee.svg +1 -0
- package/public/images/icons/whatsapp.svg +1 -0
- package/public/images/icons/zalo.png +0 -0
- package/public/images/images.jpg +0 -0
- package/public/images/ticket_sources/api.png +0 -0
- package/public/images/ticket_sources/email.png +0 -0
- package/public/images/ticket_sources/facebook.png +0 -0
- package/public/images/ticket_sources/hand.png +0 -0
- package/public/images/ticket_sources/instagram.png +0 -0
- package/public/images/ticket_sources/livechat.png +0 -0
- package/public/images/ticket_sources/shopee.svg +1 -0
- package/public/images/ticket_sources/sms.png +0 -0
- package/public/images/ticket_sources/telephone-call-in.png +0 -0
- package/public/images/ticket_sources/telephone-call-out.png +0 -0
- package/public/images/ticket_sources/tiktok.png +0 -0
- package/public/images/ticket_sources/tiktok_shop.png +0 -0
- package/public/images/ticket_sources/whatsapp.png +0 -0
- package/public/images/ticket_sources/whatsapp.svg +1 -0
- package/public/images/ticket_sources/zalo.png +0 -0
- package/public/placeholder.svg +13 -0
- package/store/app-status-store.js +17 -0
- package/store/chat-display-config-store.js +182 -0
- package/store/chat-display-config.resolvers.js +88 -0
- package/store/chat-store-helpers.js +62 -0
- package/store/chat-store.js +931 -0
- package/store/crm-organization-list-filter-store.js +126 -0
- package/store/customer-list-filter-store.js +139 -0
- package/store/devtools.js +9 -0
- package/store/duplicate-phone-warning-store.js +18 -0
- package/store/entity-extract-store.js +72 -0
- package/store/file-preview-store.js +27 -0
- package/store/filter-store.js +289 -0
- package/store/index.js +22 -0
- package/store/knowledge-crawl-store.js +53 -0
- package/store/lead-list-filter-store.js +142 -0
- package/store/list-pagination-state.js +44 -0
- package/store/lumi-learn-from-chat-store.js +69 -0
- package/store/merge-suggestion-store.js +27 -0
- package/store/notification-store.js +63 -0
- package/store/preview-image-store.js +22 -0
- package/store/settings-store/multi-channel/email-list-store.js +20 -0
- package/store/settings-store/multi-channel/facebook-list-store.js +22 -0
- package/store/settings-store/multi-channel/google-list-store.js +20 -0
- package/store/settings-store/multi-channel/instagram-list-store.js +20 -0
- package/store/settings-store/multi-channel/misa-list-store.js +20 -0
- package/store/settings-store/multi-channel/nhanhvn-list-store.js +20 -0
- package/store/settings-store/multi-channel/shopee-list-store.js +20 -0
- package/store/settings-store/multi-channel/shopee-order-list-store.js +20 -0
- package/store/settings-store/multi-channel/sms-list-store.js +20 -0
- package/store/settings-store/multi-channel/tiktok-business-list-store.js +20 -0
- package/store/settings-store/multi-channel/tiktok-list-store.js +20 -0
- package/store/settings-store/multi-channel/zalo-list-store.js +22 -0
- package/store/settings-store/multi-channel/zalo-user-list-store.js +25 -0
- package/store/smart-qc-store/smart-qc-list-filter-store.js +70 -0
- package/store/tenant-config-store.js +21 -0
- package/store/user-detail-store.js +17 -0
- package/store/user-status-store.js +33 -0
- package/store/workflow-store.js +24 -0
- package/store/workspace-store.js +32 -0
- package/tailwind-preset.js +129 -0
- package/utils/chat-actions.js +414 -0
- package/utils/chat_socket.js +1225 -0
- package/utils/extra-columns.js +108 -0
- package/utils/file.js +316 -0
- package/utils/html-to-plain-text.js +12 -0
- package/utils/notification.js +71 -0
- package/utils/replaceZaloSprite.js +64 -0
- package/utils/show-be-error.js +17 -0
- package/utils/typing_socket.js +101 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
DndContext,
|
|
5
|
+
closestCenter,
|
|
6
|
+
useSensor,
|
|
7
|
+
useSensors,
|
|
8
|
+
PointerSensor,
|
|
9
|
+
KeyboardSensor
|
|
10
|
+
} from "@dnd-kit/core";
|
|
11
|
+
import {
|
|
12
|
+
SortableContext,
|
|
13
|
+
verticalListSortingStrategy,
|
|
14
|
+
useSortable,
|
|
15
|
+
arrayMove
|
|
16
|
+
} from "@dnd-kit/sortable";
|
|
17
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
18
|
+
import {
|
|
19
|
+
Pin,
|
|
20
|
+
CircleMinus,
|
|
21
|
+
CirclePlus,
|
|
22
|
+
GripVertical,
|
|
23
|
+
Search
|
|
24
|
+
} from "lucide-react";
|
|
25
|
+
import {
|
|
26
|
+
Popover,
|
|
27
|
+
PopoverContent,
|
|
28
|
+
PopoverTrigger
|
|
29
|
+
} from "../ui/popover.js";
|
|
30
|
+
import { Button } from "./button.js";
|
|
31
|
+
import { useTranslation } from "react-i18next";
|
|
32
|
+
function normalize(str) {
|
|
33
|
+
return (str || "").toString().normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function SortableFieldRow({ id, label, onRemove, canRemove }) {
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const {
|
|
38
|
+
attributes,
|
|
39
|
+
listeners,
|
|
40
|
+
setNodeRef,
|
|
41
|
+
transform,
|
|
42
|
+
transition,
|
|
43
|
+
isDragging
|
|
44
|
+
} = useSortable({ id });
|
|
45
|
+
const style = {
|
|
46
|
+
transform: CSS.Transform.toString(transform),
|
|
47
|
+
transition,
|
|
48
|
+
opacity: isDragging ? 0.5 : 1
|
|
49
|
+
};
|
|
50
|
+
return /* @__PURE__ */ jsxs(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
ref: setNodeRef,
|
|
54
|
+
style,
|
|
55
|
+
className: "flex cursor-grab items-center gap-2 rounded-md px-1 py-1 hover:bg-surface-subtle active:cursor-grabbing",
|
|
56
|
+
onClick: () => canRemove && onRemove(id),
|
|
57
|
+
...attributes,
|
|
58
|
+
...listeners,
|
|
59
|
+
children: [
|
|
60
|
+
canRemove ? /* @__PURE__ */ jsx(
|
|
61
|
+
"button",
|
|
62
|
+
{
|
|
63
|
+
type: "button",
|
|
64
|
+
className: "shrink-0 text-destructive",
|
|
65
|
+
onClick: (e) => {
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
onRemove(id);
|
|
68
|
+
},
|
|
69
|
+
"aria-label": t("common:action.hideField", {
|
|
70
|
+
defaultValue: "\u1EA8n field"
|
|
71
|
+
}),
|
|
72
|
+
children: /* @__PURE__ */ jsx(CircleMinus, { size: 16, strokeWidth: 1.5 })
|
|
73
|
+
}
|
|
74
|
+
) : /* @__PURE__ */ jsx("span", { className: "size-4 shrink-0" }),
|
|
75
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 truncate text-sm leading-5 text-foreground", children: label }),
|
|
76
|
+
/* @__PURE__ */ jsx("span", { className: "flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground", children: /* @__PURE__ */ jsx(GripVertical, { size: 14, strokeWidth: 1.5 }) })
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function FieldLayoutPopover({
|
|
82
|
+
containerKey,
|
|
83
|
+
items = [],
|
|
84
|
+
fieldLabelMap = {},
|
|
85
|
+
fieldGroupMap,
|
|
86
|
+
canEditFieldLayout,
|
|
87
|
+
onApply,
|
|
88
|
+
// Mặc định chặn bỏ field cuối để vùng gọi không rỗng trắng. Nơi nào coi "không
|
|
89
|
+
// hiện field nào" là cấu hình hợp lệ thì bật cờ này.
|
|
90
|
+
allowEmpty = false,
|
|
91
|
+
triggerIcon: TriggerIcon = Pin,
|
|
92
|
+
triggerAriaLabel = "T\xF9y ch\u1EC9nh field hi\u1EC3n th\u1ECB",
|
|
93
|
+
shownLabel = "Th\xF4ng tin \u0111ang hi\u1EC3n th\u1ECB",
|
|
94
|
+
addLabel = "Th\xF4ng tin c\xF3 th\u1EC3 th\xEAm",
|
|
95
|
+
portalContainer
|
|
96
|
+
}) {
|
|
97
|
+
const { t } = useTranslation();
|
|
98
|
+
const [open, setOpen] = useState(false);
|
|
99
|
+
const [shownKeys, setShownKeys] = useState(
|
|
100
|
+
() => Array.isArray(items) ? items : []
|
|
101
|
+
);
|
|
102
|
+
const [search, setSearch] = useState("");
|
|
103
|
+
const labels = useMemo(
|
|
104
|
+
() => fieldLabelMap && typeof fieldLabelMap === "object" ? fieldLabelMap : {},
|
|
105
|
+
[fieldLabelMap]
|
|
106
|
+
);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (open) {
|
|
109
|
+
setShownKeys(Array.isArray(items) ? items : []);
|
|
110
|
+
setSearch("");
|
|
111
|
+
}
|
|
112
|
+
}, [open]);
|
|
113
|
+
const hiddenKeys = useMemo(
|
|
114
|
+
() => Object.keys(labels).filter((k) => !shownKeys.includes(k)).sort(
|
|
115
|
+
(a, b) => String(labels[a] || "").localeCompare(String(labels[b] || ""), "vi")
|
|
116
|
+
),
|
|
117
|
+
[labels, shownKeys]
|
|
118
|
+
);
|
|
119
|
+
const filteredHiddenKeys = useMemo(() => {
|
|
120
|
+
if (!search.trim()) return hiddenKeys;
|
|
121
|
+
const q = normalize(search);
|
|
122
|
+
return hiddenKeys.filter((k) => normalize(labels[k]).includes(q));
|
|
123
|
+
}, [hiddenKeys, search, labels]);
|
|
124
|
+
const hiddenKeysByGroup = useMemo(() => {
|
|
125
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const key of filteredHiddenKeys) {
|
|
127
|
+
const groupLabel = fieldGroupMap?.[key] ?? "";
|
|
128
|
+
if (!grouped.has(groupLabel)) grouped.set(groupLabel, []);
|
|
129
|
+
grouped.get(groupLabel).push(key);
|
|
130
|
+
}
|
|
131
|
+
return [...grouped.entries()];
|
|
132
|
+
}, [filteredHiddenKeys, fieldGroupMap]);
|
|
133
|
+
const sensors = useSensors(
|
|
134
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
|
|
135
|
+
useSensor(KeyboardSensor)
|
|
136
|
+
);
|
|
137
|
+
const handleDragEnd = ({ active, over }) => {
|
|
138
|
+
if (!over || active.id === over.id) return;
|
|
139
|
+
if (fieldGroupMap && fieldGroupMap[active.id] !== fieldGroupMap[over.id]) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
setShownKeys((prev) => {
|
|
143
|
+
const oldIndex = prev.indexOf(active.id);
|
|
144
|
+
const newIndex = prev.indexOf(over.id);
|
|
145
|
+
if (oldIndex === -1 || newIndex === -1) return prev;
|
|
146
|
+
return arrayMove(prev, oldIndex, newIndex);
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
const handleRemove = (key) => {
|
|
150
|
+
if (!allowEmpty && shownKeys.length <= 1) return;
|
|
151
|
+
setShownKeys((prev) => prev.filter((k) => k !== key));
|
|
152
|
+
};
|
|
153
|
+
const handleAdd = (key) => {
|
|
154
|
+
setShownKeys((prev) => prev.includes(key) ? prev : [...prev, key]);
|
|
155
|
+
};
|
|
156
|
+
const handleApply = () => {
|
|
157
|
+
const nextHiddenByKey = {};
|
|
158
|
+
const nextShownKeys = Array.isArray(shownKeys) ? shownKeys : [];
|
|
159
|
+
Object.keys(labels).forEach((k) => {
|
|
160
|
+
nextHiddenByKey[k] = !nextShownKeys.includes(k);
|
|
161
|
+
});
|
|
162
|
+
onApply(containerKey, nextShownKeys, nextHiddenByKey);
|
|
163
|
+
setOpen(false);
|
|
164
|
+
};
|
|
165
|
+
if (!canEditFieldLayout) return null;
|
|
166
|
+
return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
167
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
168
|
+
"button",
|
|
169
|
+
{
|
|
170
|
+
type: "button",
|
|
171
|
+
className: "flex size-[30px] shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 data-[state=open]:text-primary",
|
|
172
|
+
onClick: (e) => e.stopPropagation(),
|
|
173
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
174
|
+
"aria-label": triggerAriaLabel,
|
|
175
|
+
children: /* @__PURE__ */ jsx(TriggerIcon, { size: 17, strokeWidth: 1.4 })
|
|
176
|
+
}
|
|
177
|
+
) }),
|
|
178
|
+
/* @__PURE__ */ jsxs(
|
|
179
|
+
PopoverContent,
|
|
180
|
+
{
|
|
181
|
+
align: "end",
|
|
182
|
+
sideOffset: 6,
|
|
183
|
+
collisionPadding: 16,
|
|
184
|
+
container: portalContainer,
|
|
185
|
+
className: "flex max-h-[min(560px,var(--radix-popover-content-available-height))] w-[min(20rem,calc(100vw-2rem))] flex-col gap-0 rounded-lg border border-border-subtle p-0 shadow-[0px_40px_80px_-20px_rgba(15,23,42,0.24)]",
|
|
186
|
+
onClick: (e) => e.stopPropagation(),
|
|
187
|
+
children: [
|
|
188
|
+
/* @__PURE__ */ jsxs(
|
|
189
|
+
"div",
|
|
190
|
+
{
|
|
191
|
+
className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-3.5 py-3",
|
|
192
|
+
onWheel: (e) => e.stopPropagation(),
|
|
193
|
+
onTouchMove: (e) => e.stopPropagation(),
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsx("div", { className: "pb-1.5 text-[13px] font-semibold uppercase tracking-wide text-muted-foreground", children: shownLabel }),
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
DndContext,
|
|
198
|
+
{
|
|
199
|
+
sensors,
|
|
200
|
+
collisionDetection: closestCenter,
|
|
201
|
+
onDragEnd: handleDragEnd,
|
|
202
|
+
children: /* @__PURE__ */ jsx(
|
|
203
|
+
SortableContext,
|
|
204
|
+
{
|
|
205
|
+
items: shownKeys,
|
|
206
|
+
strategy: verticalListSortingStrategy,
|
|
207
|
+
children: shownKeys.map((key, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
208
|
+
fieldGroupMap && fieldGroupMap[key] !== fieldGroupMap[shownKeys[index - 1]] && fieldGroupMap[key] && /* @__PURE__ */ jsx("div", { className: "px-1 pb-0.5 pt-1.5 text-xs font-semibold text-muted-foreground", children: fieldGroupMap[key] }),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
SortableFieldRow,
|
|
211
|
+
{
|
|
212
|
+
id: key,
|
|
213
|
+
label: labels[key] || key,
|
|
214
|
+
onRemove: handleRemove,
|
|
215
|
+
canRemove: allowEmpty || shownKeys.length > 1
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
] }, key))
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
/* @__PURE__ */ jsx("div", { className: "my-2 border-t border-dashed border-border-subtle" }),
|
|
224
|
+
/* @__PURE__ */ jsx("div", { className: "pb-1.5 text-[13px] font-semibold uppercase tracking-wide text-muted-foreground", children: addLabel }),
|
|
225
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-1 flex items-center gap-2 rounded-md border border-border px-2.5 py-2", children: [
|
|
226
|
+
/* @__PURE__ */ jsx(
|
|
227
|
+
Search,
|
|
228
|
+
{
|
|
229
|
+
size: 14,
|
|
230
|
+
strokeWidth: 1.5,
|
|
231
|
+
className: "shrink-0 text-muted-foreground"
|
|
232
|
+
}
|
|
233
|
+
),
|
|
234
|
+
/* @__PURE__ */ jsx(
|
|
235
|
+
"input",
|
|
236
|
+
{
|
|
237
|
+
value: search,
|
|
238
|
+
onChange: (e) => setSearch(e.target.value),
|
|
239
|
+
placeholder: t("common:placeholder.search", {
|
|
240
|
+
defaultValue: "T\xECm ki\u1EBFm\u2026"
|
|
241
|
+
}),
|
|
242
|
+
className: "w-full text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
] }),
|
|
246
|
+
hiddenKeysByGroup.map(([groupLabel, keys]) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
247
|
+
groupLabel && /* @__PURE__ */ jsx("div", { className: "px-1 pb-0.5 pt-1.5 text-xs font-semibold text-muted-foreground", children: groupLabel }),
|
|
248
|
+
keys.map((key) => /* @__PURE__ */ jsxs(
|
|
249
|
+
"div",
|
|
250
|
+
{
|
|
251
|
+
className: "flex cursor-pointer items-center gap-2 rounded-md px-1 py-1 hover:bg-surface-subtle",
|
|
252
|
+
onClick: () => handleAdd(key),
|
|
253
|
+
children: [
|
|
254
|
+
/* @__PURE__ */ jsx(
|
|
255
|
+
"button",
|
|
256
|
+
{
|
|
257
|
+
type: "button",
|
|
258
|
+
className: "shrink-0 text-success",
|
|
259
|
+
onClick: (e) => {
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
handleAdd(key);
|
|
262
|
+
},
|
|
263
|
+
"aria-label": t("common:action.addFieldAlt", {
|
|
264
|
+
defaultValue: "Th\xEAm field"
|
|
265
|
+
}),
|
|
266
|
+
children: /* @__PURE__ */ jsx(CirclePlus, { size: 16, strokeWidth: 1.5 })
|
|
267
|
+
}
|
|
268
|
+
),
|
|
269
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 truncate text-sm leading-5 text-foreground", children: labels[key] || key })
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
key
|
|
273
|
+
))
|
|
274
|
+
] }, groupLabel))
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
),
|
|
278
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 rounded-b-lg border-t border-border-subtle bg-surface-subtle px-3.5 py-2.5", children: [
|
|
279
|
+
/* @__PURE__ */ jsx(
|
|
280
|
+
Button,
|
|
281
|
+
{
|
|
282
|
+
variant: "outline",
|
|
283
|
+
className: "h-9 rounded-lg border-border-subtle px-4 text-sm font-semibold text-muted-foreground",
|
|
284
|
+
onClick: () => setOpen(false),
|
|
285
|
+
children: t("common:action.cancelAlt", { defaultValue: "Hu\u1EF7" })
|
|
286
|
+
}
|
|
287
|
+
),
|
|
288
|
+
/* @__PURE__ */ jsx(
|
|
289
|
+
Button,
|
|
290
|
+
{
|
|
291
|
+
className: "h-9 rounded-lg bg-primary px-4 text-sm font-semibold hover:bg-primary/90",
|
|
292
|
+
onClick: handleApply,
|
|
293
|
+
children: t("common:action.apply", { defaultValue: "\xC1p d\u1EE5ng" })
|
|
294
|
+
}
|
|
295
|
+
)
|
|
296
|
+
] })
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
] });
|
|
301
|
+
}
|
|
302
|
+
export {
|
|
303
|
+
FieldLayoutPopover as default
|
|
304
|
+
};
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { lazy, Suspense, useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { Dialog, DialogContent, DialogTitle } from "../ui/dialog.js";
|
|
4
|
+
import { Badge } from "../ui/badge.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { Skeleton } from "../ui/skeleton.js";
|
|
7
|
+
import {
|
|
8
|
+
ChevronLeft,
|
|
9
|
+
ChevronRight,
|
|
10
|
+
Download,
|
|
11
|
+
Link2,
|
|
12
|
+
Maximize2,
|
|
13
|
+
Minimize2,
|
|
14
|
+
X,
|
|
15
|
+
FileText,
|
|
16
|
+
FileImage,
|
|
17
|
+
FileAudio,
|
|
18
|
+
FileVideo,
|
|
19
|
+
FileSpreadsheet,
|
|
20
|
+
FileCode,
|
|
21
|
+
File
|
|
22
|
+
} from "lucide-react";
|
|
23
|
+
import { cn } from "../../lib/utils.js";
|
|
24
|
+
import { saveAs } from "file-saver";
|
|
25
|
+
import { toast } from "sonner";
|
|
26
|
+
import useFilePreviewStore from "../../store/file-preview-store.js";
|
|
27
|
+
import { useFileViewer, VIEWER_TYPES } from "../../hooks/use-file-viewer.js";
|
|
28
|
+
import { formatBytes } from "../../utils/file.js";
|
|
29
|
+
import { useTranslation } from "react-i18next";
|
|
30
|
+
import i18n from "@zenify-omni/chat-js/lib/i18n/index.js";
|
|
31
|
+
const PdfViewer = lazy(() => import("./viewers/pdf-viewer.js"));
|
|
32
|
+
const DocxViewer = lazy(() => import("./viewers/docx-viewer.js"));
|
|
33
|
+
const SpreadsheetViewer = lazy(() => import("./viewers/spreadsheet-viewer.js"));
|
|
34
|
+
const CsvViewer = lazy(() => import("./viewers/csv-viewer.js"));
|
|
35
|
+
const ImageViewer = lazy(() => import("./viewers/image-viewer.js"));
|
|
36
|
+
const VideoPlayer = lazy(() => import("./viewers/video-player.js"));
|
|
37
|
+
const AudioPlayer = lazy(() => import("./viewers/audio-player.js"));
|
|
38
|
+
const MarkdownViewer = lazy(() => import("./viewers/markdown-viewer.js"));
|
|
39
|
+
const CodeViewer = lazy(() => import("./viewers/code-viewer.js"));
|
|
40
|
+
const UnsupportedViewer = lazy(() => import("./viewers/unsupported-viewer.js"));
|
|
41
|
+
const VIEWER_MAP = {
|
|
42
|
+
[VIEWER_TYPES.PDF]: PdfViewer,
|
|
43
|
+
[VIEWER_TYPES.DOCX]: DocxViewer,
|
|
44
|
+
[VIEWER_TYPES.SPREADSHEET]: SpreadsheetViewer,
|
|
45
|
+
[VIEWER_TYPES.CSV]: CsvViewer,
|
|
46
|
+
[VIEWER_TYPES.IMAGE]: ImageViewer,
|
|
47
|
+
[VIEWER_TYPES.VIDEO]: VideoPlayer,
|
|
48
|
+
[VIEWER_TYPES.AUDIO]: AudioPlayer,
|
|
49
|
+
[VIEWER_TYPES.MARKDOWN]: MarkdownViewer,
|
|
50
|
+
[VIEWER_TYPES.CODE]: CodeViewer,
|
|
51
|
+
[VIEWER_TYPES.UNSUPPORTED]: UnsupportedViewer
|
|
52
|
+
};
|
|
53
|
+
const MIME_BADGE = {
|
|
54
|
+
[VIEWER_TYPES.PDF]: {
|
|
55
|
+
label: "PDF",
|
|
56
|
+
className: "bg-[--label-red] text-destructive border-destructive/30"
|
|
57
|
+
},
|
|
58
|
+
[VIEWER_TYPES.DOCX]: {
|
|
59
|
+
label: "DOCX",
|
|
60
|
+
className: "bg-secondary text-primary border-primary/30"
|
|
61
|
+
},
|
|
62
|
+
[VIEWER_TYPES.SPREADSHEET]: {
|
|
63
|
+
label: "XLSX",
|
|
64
|
+
className: "bg-[--label-green] text-success border-success/30"
|
|
65
|
+
},
|
|
66
|
+
[VIEWER_TYPES.CSV]: {
|
|
67
|
+
label: "CSV",
|
|
68
|
+
className: "bg-muted text-chart-2 border-chart-8/40"
|
|
69
|
+
},
|
|
70
|
+
[VIEWER_TYPES.IMAGE]: {
|
|
71
|
+
label: "IMG",
|
|
72
|
+
className: "bg-muted text-chart-9 border-chart-9/40"
|
|
73
|
+
},
|
|
74
|
+
[VIEWER_TYPES.VIDEO]: {
|
|
75
|
+
label: "MP4",
|
|
76
|
+
className: "bg-muted text-chart-5 border-chart-5/40"
|
|
77
|
+
},
|
|
78
|
+
[VIEWER_TYPES.AUDIO]: {
|
|
79
|
+
label: "WAV",
|
|
80
|
+
className: "bg-[--label-orange] text-warning border-warning/40"
|
|
81
|
+
},
|
|
82
|
+
[VIEWER_TYPES.MARKDOWN]: {
|
|
83
|
+
label: "MD",
|
|
84
|
+
className: "bg-surface-subtle text-muted-foreground border-border-subtle"
|
|
85
|
+
},
|
|
86
|
+
[VIEWER_TYPES.CODE]: {
|
|
87
|
+
label: "CODE",
|
|
88
|
+
className: "bg-secondary text-primary border-primary/40"
|
|
89
|
+
},
|
|
90
|
+
[VIEWER_TYPES.UNSUPPORTED]: {
|
|
91
|
+
label: "FILE",
|
|
92
|
+
className: "bg-surface-subtle text-muted-foreground border-border-subtle"
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function getFileIcon(viewerType) {
|
|
96
|
+
const cls = "h-5 w-5";
|
|
97
|
+
switch (viewerType) {
|
|
98
|
+
case VIEWER_TYPES.PDF:
|
|
99
|
+
return /* @__PURE__ */ jsx(FileText, { className: cn(cls, "text-destructive") });
|
|
100
|
+
case VIEWER_TYPES.DOCX:
|
|
101
|
+
return /* @__PURE__ */ jsx(FileText, { className: cn(cls, "text-primary") });
|
|
102
|
+
case VIEWER_TYPES.SPREADSHEET:
|
|
103
|
+
return /* @__PURE__ */ jsx(FileSpreadsheet, { className: cn(cls, "text-success") });
|
|
104
|
+
case VIEWER_TYPES.CSV:
|
|
105
|
+
return /* @__PURE__ */ jsx(FileSpreadsheet, { className: cn(cls, "text-chart-8") });
|
|
106
|
+
case VIEWER_TYPES.IMAGE:
|
|
107
|
+
return /* @__PURE__ */ jsx(FileImage, { className: cn(cls, "text-chart-9") });
|
|
108
|
+
case VIEWER_TYPES.VIDEO:
|
|
109
|
+
return /* @__PURE__ */ jsx(FileVideo, { className: cn(cls, "text-chart-5") });
|
|
110
|
+
case VIEWER_TYPES.AUDIO:
|
|
111
|
+
return /* @__PURE__ */ jsx(FileAudio, { className: cn(cls, "text-warning") });
|
|
112
|
+
case VIEWER_TYPES.MARKDOWN:
|
|
113
|
+
return /* @__PURE__ */ jsx(FileCode, { className: cn(cls, "text-muted-foreground") });
|
|
114
|
+
case VIEWER_TYPES.CODE:
|
|
115
|
+
return /* @__PURE__ */ jsx(FileCode, { className: cn(cls, "text-chart-3") });
|
|
116
|
+
default:
|
|
117
|
+
return /* @__PURE__ */ jsx(File, { className: cn(cls, "text-muted-foreground") });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function ViewerSkeleton() {
|
|
121
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col gap-4 p-6", children: [
|
|
122
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-full" }),
|
|
123
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-3/4" }),
|
|
124
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-5/6" }),
|
|
125
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-2/3" }),
|
|
126
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-full" }),
|
|
127
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-4/5" })
|
|
128
|
+
] });
|
|
129
|
+
}
|
|
130
|
+
function FilePreviewModal() {
|
|
131
|
+
const { t } = useTranslation();
|
|
132
|
+
const { isOpen, files, currentIndex, closePreview, goNext, goPrev } = useFilePreviewStore();
|
|
133
|
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!isOpen) setIsFullscreen(false);
|
|
136
|
+
}, [isOpen]);
|
|
137
|
+
const file = files[currentIndex];
|
|
138
|
+
const viewerType = useFileViewer(file);
|
|
139
|
+
const ViewerComponent = viewerType ? VIEWER_MAP[viewerType] : null;
|
|
140
|
+
const badge = viewerType ? MIME_BADGE[viewerType] : null;
|
|
141
|
+
const displayName = file?.name ? (() => {
|
|
142
|
+
try {
|
|
143
|
+
return decodeURIComponent(file.name);
|
|
144
|
+
} catch {
|
|
145
|
+
return file.name;
|
|
146
|
+
}
|
|
147
|
+
})() : "";
|
|
148
|
+
const handleDownload = useCallback(async () => {
|
|
149
|
+
if (!file) return;
|
|
150
|
+
try {
|
|
151
|
+
const res = await fetch(file.url, { referrerPolicy: "no-referrer" });
|
|
152
|
+
const blob = await res.blob();
|
|
153
|
+
saveAs(blob, file.name);
|
|
154
|
+
} catch {
|
|
155
|
+
window.open(file.url, "_blank");
|
|
156
|
+
}
|
|
157
|
+
}, [file]);
|
|
158
|
+
const handleCopyLink = useCallback(() => {
|
|
159
|
+
if (!file?.url) return;
|
|
160
|
+
navigator.clipboard.writeText(file.url).then(
|
|
161
|
+
() => toast.success(
|
|
162
|
+
i18n.t("common:toast.linkCopied", {
|
|
163
|
+
defaultValue: "\u0110\xE3 sao ch\xE9p link"
|
|
164
|
+
})
|
|
165
|
+
)
|
|
166
|
+
);
|
|
167
|
+
}, [file]);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!isOpen) return;
|
|
170
|
+
const onKey = (e) => {
|
|
171
|
+
if (e.key === "ArrowRight") {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
goNext();
|
|
174
|
+
}
|
|
175
|
+
if (e.key === "ArrowLeft") {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
goPrev();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
window.addEventListener("keydown", onKey);
|
|
181
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
182
|
+
}, [isOpen, goNext, goPrev]);
|
|
183
|
+
if (!isOpen || !file) return null;
|
|
184
|
+
return /* @__PURE__ */ jsx(Dialog, { open: isOpen, onOpenChange: (open) => !open && closePreview(), children: /* @__PURE__ */ jsxs(
|
|
185
|
+
DialogContent,
|
|
186
|
+
{
|
|
187
|
+
showCloseButton: false,
|
|
188
|
+
className: cn(
|
|
189
|
+
"flex flex-col gap-0 overflow-hidden p-0",
|
|
190
|
+
isFullscreen ? "fixed inset-0 !left-0 !top-0 h-screen w-screen max-w-none !translate-x-0 !translate-y-0 rounded-none" : "h-[90vh] max-w-4xl"
|
|
191
|
+
),
|
|
192
|
+
"aria-label": t("common:dialog.previewTitle", {
|
|
193
|
+
displayName,
|
|
194
|
+
defaultValue: "Xem tr\u01B0\u1EDBc: {displayName}"
|
|
195
|
+
}),
|
|
196
|
+
"aria-describedby": void 0,
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: displayName }),
|
|
199
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-shrink-0 items-start justify-between border-b border-border px-4 py-3", children: [
|
|
200
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
201
|
+
/* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: getFileIcon(viewerType) }),
|
|
202
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
203
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
"span",
|
|
206
|
+
{
|
|
207
|
+
className: "max-w-[300px] truncate text-sm font-semibold text-foreground",
|
|
208
|
+
title: displayName,
|
|
209
|
+
children: displayName
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
badge && /* @__PURE__ */ jsx(Badge, { variant: "outline", className: badge.className, children: badge.label })
|
|
213
|
+
] }),
|
|
214
|
+
(file.sender || file.sentAt) && /* @__PURE__ */ jsxs("p", { className: "mt-0.5 text-xs text-muted-foreground", children: [
|
|
215
|
+
files.length > 1 && `${t("common:label.fileIndexCounter", {
|
|
216
|
+
current: currentIndex + 1,
|
|
217
|
+
total: files.length,
|
|
218
|
+
defaultValue: "T\u1EADp {current}/{total}"
|
|
219
|
+
})} \xB7 `,
|
|
220
|
+
file.sender && t("common:label.fromSender", {
|
|
221
|
+
sender: file.sender,
|
|
222
|
+
defaultValue: "T\u1EEB {sender}"
|
|
223
|
+
}),
|
|
224
|
+
file.sentAt && ` \xB7 ${file.sentAt}`
|
|
225
|
+
] })
|
|
226
|
+
] })
|
|
227
|
+
] }),
|
|
228
|
+
/* @__PURE__ */ jsxs("div", { className: "ml-4 flex flex-shrink-0 items-center gap-1", children: [
|
|
229
|
+
files.length > 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
Button,
|
|
232
|
+
{
|
|
233
|
+
variant: "ghost",
|
|
234
|
+
size: "icon",
|
|
235
|
+
className: "h-7 w-7",
|
|
236
|
+
disabled: currentIndex === 0,
|
|
237
|
+
onClick: goPrev,
|
|
238
|
+
"aria-label": t("common:action.previousFile", {
|
|
239
|
+
defaultValue: "File tr\u01B0\u1EDBc"
|
|
240
|
+
}),
|
|
241
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" })
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
/* @__PURE__ */ jsx(
|
|
245
|
+
Button,
|
|
246
|
+
{
|
|
247
|
+
variant: "ghost",
|
|
248
|
+
size: "icon",
|
|
249
|
+
className: "h-7 w-7",
|
|
250
|
+
disabled: currentIndex === files.length - 1,
|
|
251
|
+
onClick: goNext,
|
|
252
|
+
"aria-label": "File sau",
|
|
253
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" })
|
|
254
|
+
}
|
|
255
|
+
)
|
|
256
|
+
] }),
|
|
257
|
+
/* @__PURE__ */ jsx(
|
|
258
|
+
Button,
|
|
259
|
+
{
|
|
260
|
+
variant: "ghost",
|
|
261
|
+
size: "icon",
|
|
262
|
+
className: "h-7 w-7",
|
|
263
|
+
onClick: handleDownload,
|
|
264
|
+
"aria-label": t("common:action.download", {
|
|
265
|
+
defaultValue: "T\u1EA3i xu\u1ED1ng"
|
|
266
|
+
}),
|
|
267
|
+
children: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" })
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
/* @__PURE__ */ jsx(
|
|
271
|
+
Button,
|
|
272
|
+
{
|
|
273
|
+
variant: "ghost",
|
|
274
|
+
size: "icon",
|
|
275
|
+
className: "h-7 w-7",
|
|
276
|
+
onClick: handleCopyLink,
|
|
277
|
+
"aria-label": t("common:action.copyLink", {
|
|
278
|
+
defaultValue: "Sao ch\xE9p link"
|
|
279
|
+
}),
|
|
280
|
+
children: /* @__PURE__ */ jsx(Link2, { className: "h-4 w-4" })
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
/* @__PURE__ */ jsx(
|
|
284
|
+
Button,
|
|
285
|
+
{
|
|
286
|
+
variant: "ghost",
|
|
287
|
+
size: "icon",
|
|
288
|
+
className: "h-7 w-7",
|
|
289
|
+
onClick: () => setIsFullscreen((v) => !v),
|
|
290
|
+
"aria-label": isFullscreen ? t("common:action.minimize", { defaultValue: "Thu nh\u1ECF" }) : t("common:action.fullscreen", {
|
|
291
|
+
defaultValue: "To\xE0n m\xE0n h\xECnh"
|
|
292
|
+
}),
|
|
293
|
+
children: isFullscreen ? /* @__PURE__ */ jsx(Minimize2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Maximize2, { className: "h-4 w-4" })
|
|
294
|
+
}
|
|
295
|
+
),
|
|
296
|
+
/* @__PURE__ */ jsx(
|
|
297
|
+
Button,
|
|
298
|
+
{
|
|
299
|
+
variant: "ghost",
|
|
300
|
+
size: "icon",
|
|
301
|
+
className: "h-7 w-7",
|
|
302
|
+
onClick: closePreview,
|
|
303
|
+
"aria-label": t("common:action.close", { defaultValue: "\u0110\xF3ng" }),
|
|
304
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
] })
|
|
308
|
+
] }),
|
|
309
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 overflow-hidden", children: ViewerComponent && /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(ViewerSkeleton, {}), children: /* @__PURE__ */ jsx(ViewerComponent, { file, onDownload: handleDownload }) }) }),
|
|
310
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-shrink-0 items-center justify-between border-t border-border px-4 py-2", children: [
|
|
311
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
312
|
+
file.size ? formatBytes(file.size) : "",
|
|
313
|
+
file.name && ` \xB7 ${file.name.split(".").pop()?.toUpperCase()}`
|
|
314
|
+
] }),
|
|
315
|
+
files.length > 1 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
316
|
+
/* @__PURE__ */ jsx(
|
|
317
|
+
Button,
|
|
318
|
+
{
|
|
319
|
+
variant: "ghost",
|
|
320
|
+
size: "sm",
|
|
321
|
+
className: "h-7 text-xs",
|
|
322
|
+
disabled: currentIndex === 0,
|
|
323
|
+
onClick: goPrev,
|
|
324
|
+
children: t("common:action.previousAlt", { defaultValue: "< Tr\u01B0\u1EDBc" })
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
328
|
+
currentIndex + 1,
|
|
329
|
+
" / ",
|
|
330
|
+
files.length
|
|
331
|
+
] }),
|
|
332
|
+
/* @__PURE__ */ jsx(
|
|
333
|
+
Button,
|
|
334
|
+
{
|
|
335
|
+
variant: "ghost",
|
|
336
|
+
size: "sm",
|
|
337
|
+
className: "h-7 text-xs",
|
|
338
|
+
disabled: currentIndex === files.length - 1,
|
|
339
|
+
onClick: goNext,
|
|
340
|
+
children: "Sau >"
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
] })
|
|
344
|
+
] })
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
) });
|
|
348
|
+
}
|
|
349
|
+
export {
|
|
350
|
+
FilePreviewModal as default
|
|
351
|
+
};
|