@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,821 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
useMemo,
|
|
4
|
+
useCallback,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
forwardRef,
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useLayoutEffect
|
|
11
|
+
} from "react";
|
|
12
|
+
import { Command as CommandPrimitive, useCommandState } from "cmdk";
|
|
13
|
+
import { LoaderCircle, X } from "lucide-react";
|
|
14
|
+
import { Badge } from "../ui/badge.js";
|
|
15
|
+
import {
|
|
16
|
+
Command,
|
|
17
|
+
CommandGroup,
|
|
18
|
+
CommandItem,
|
|
19
|
+
CommandList
|
|
20
|
+
} from "../ui/command.js";
|
|
21
|
+
import { cn } from "../../lib/utils.js";
|
|
22
|
+
import useDebounce from "../../hooks/use-debounce.js";
|
|
23
|
+
import { cva } from "class-variance-authority";
|
|
24
|
+
import { Root, Anchor, Content } from "@radix-ui/react-popper";
|
|
25
|
+
import { useTranslation } from "react-i18next";
|
|
26
|
+
function transToGroupOption(options, groupBy) {
|
|
27
|
+
if (options.length === 0) {
|
|
28
|
+
return /* @__PURE__ */ new Map();
|
|
29
|
+
}
|
|
30
|
+
if (!groupBy) {
|
|
31
|
+
return /* @__PURE__ */ new Map([["", options]]);
|
|
32
|
+
}
|
|
33
|
+
const groupOption = /* @__PURE__ */ new Map();
|
|
34
|
+
options.forEach((option) => {
|
|
35
|
+
const key = option[groupBy] || "";
|
|
36
|
+
if (!groupOption.has(key)) {
|
|
37
|
+
groupOption.set(key, []);
|
|
38
|
+
}
|
|
39
|
+
groupOption.get(key).push(option);
|
|
40
|
+
});
|
|
41
|
+
return groupOption;
|
|
42
|
+
}
|
|
43
|
+
function removePickedOption(groupOption, picked) {
|
|
44
|
+
const cloneOption = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const [key, value] of groupOption.entries()) {
|
|
46
|
+
cloneOption.set(
|
|
47
|
+
key,
|
|
48
|
+
value.filter((val) => !picked.find((p) => p.value === val.value))
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return cloneOption;
|
|
52
|
+
}
|
|
53
|
+
function isOptionsExist(groupOption, targetOption) {
|
|
54
|
+
for (const value of groupOption.values()) {
|
|
55
|
+
if (value.some((option) => targetOption.find((p) => p.value === option.value))) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function isSameGroupOption(a, b) {
|
|
62
|
+
return JSON.stringify([...a.entries()]) === JSON.stringify([...b.entries()]);
|
|
63
|
+
}
|
|
64
|
+
const RENDER_WINDOW_SIZE = 200;
|
|
65
|
+
const CommandEmpty = forwardRef(({ className, ...props }, forwardedRef) => {
|
|
66
|
+
const render = useCommandState((state) => state.filtered.count === 0);
|
|
67
|
+
if (!render) return null;
|
|
68
|
+
return /* @__PURE__ */ jsx(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
ref: forwardedRef,
|
|
72
|
+
className: cn("py-6 text-center text-sm", className),
|
|
73
|
+
"cmdk-empty": "",
|
|
74
|
+
role: "presentation",
|
|
75
|
+
...props
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
CommandEmpty.displayName = "CommandEmpty";
|
|
80
|
+
const DefaultEmptyIndicator = () => {
|
|
81
|
+
const { t } = useTranslation();
|
|
82
|
+
return /* @__PURE__ */ jsx("p", { className: "text-center leading-10 text-muted-foreground", children: t("common:empty.noData", { defaultValue: "Kh\xF4ng c\xF3 d\u1EEF li\u1EC7u" }) });
|
|
83
|
+
};
|
|
84
|
+
const MultipleSelector = forwardRef(
|
|
85
|
+
({
|
|
86
|
+
value,
|
|
87
|
+
onChange,
|
|
88
|
+
placeholder,
|
|
89
|
+
defaultOptions: arrayDefaultOptions = [],
|
|
90
|
+
options: arrayOptions,
|
|
91
|
+
delay,
|
|
92
|
+
onSearch,
|
|
93
|
+
onSearchSync,
|
|
94
|
+
loadingIndicator,
|
|
95
|
+
emptyIndicator,
|
|
96
|
+
maxSelected = Number.MAX_SAFE_INTEGER,
|
|
97
|
+
onMaxSelected,
|
|
98
|
+
hidePlaceholderWhenSelected = true,
|
|
99
|
+
disabled,
|
|
100
|
+
groupBy,
|
|
101
|
+
className,
|
|
102
|
+
badgeClassName,
|
|
103
|
+
selectFirstItem = true,
|
|
104
|
+
creatable = false,
|
|
105
|
+
triggerSearchOnFocus = false,
|
|
106
|
+
preloadOnMount = false,
|
|
107
|
+
reloadTrigger,
|
|
108
|
+
commandProps,
|
|
109
|
+
inputProps,
|
|
110
|
+
hideClearAllButton = false,
|
|
111
|
+
onBlur = () => {
|
|
112
|
+
},
|
|
113
|
+
buildOption = (option) => option,
|
|
114
|
+
size,
|
|
115
|
+
isChange = true,
|
|
116
|
+
maxDisplayCount = Number.MAX_SAFE_INTEGER,
|
|
117
|
+
onLoadMore,
|
|
118
|
+
hasMore = false,
|
|
119
|
+
isLoadingMore = false,
|
|
120
|
+
loadMoreText = "\u0110ang t\u1EA3i th\xEAm...",
|
|
121
|
+
// Mặc định dropdown tự gọi onLoadMore để lấp đầy vùng hiển thị (tránh mở
|
|
122
|
+
// dropdown mà không tràn nên không có gì để cuộn tới sentinel). Caller nào
|
|
123
|
+
// muốn CHỈ tải thêm khi người dùng thật sự cuộn (vd nhắc thành viên nhóm Zalo —
|
|
124
|
+
// tải hết cả nhóm ngay khi mở dropdown là thừa, tốn API) thì truyền `true`.
|
|
125
|
+
disableAutoFillLoadMore = false,
|
|
126
|
+
// Managed pagination: bật bằng `paginated` + `onSearch`. Khi bật, component
|
|
127
|
+
// tự đếm page / tích luỹ option / tính hasMore / quản state loading — caller
|
|
128
|
+
// KHÔNG cần tự giữ state (options, page, hasMore, isLoadingMore, onLoadMore).
|
|
129
|
+
paginated = false,
|
|
130
|
+
pageSize = 20,
|
|
131
|
+
// Caret input cùng dòng với chip — default `true` cho UX gọn, tránh
|
|
132
|
+
// thừa 1 dòng trống bên dưới chip. Caller nào cần wrap xuống dòng
|
|
133
|
+
// riêng truyền `inlineInput={false}` để revert.
|
|
134
|
+
inlineInput = true,
|
|
135
|
+
renderBadgeLabel,
|
|
136
|
+
getBadgeStyle,
|
|
137
|
+
autoHeight = false,
|
|
138
|
+
...props
|
|
139
|
+
}, ref) => {
|
|
140
|
+
const textVariants = cva("", {
|
|
141
|
+
variants: {
|
|
142
|
+
size: {
|
|
143
|
+
small: "text-xs",
|
|
144
|
+
default: "text-sm"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
defaultVariants: {
|
|
148
|
+
size: "default"
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const inputRef = useRef(null);
|
|
152
|
+
const [open, setOpen] = useState(false);
|
|
153
|
+
const [onScrollbar, setOnScrollbar] = useState(false);
|
|
154
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
155
|
+
const dropdownRef = useRef(null);
|
|
156
|
+
const [selected, setSelected] = useState(value || []);
|
|
157
|
+
const [options, setOptions] = useState(
|
|
158
|
+
transToGroupOption(arrayDefaultOptions, groupBy)
|
|
159
|
+
);
|
|
160
|
+
const [inputValue, setInputValue] = useState("");
|
|
161
|
+
const debouncedSearchTerm = useDebounce(inputValue, delay || 500);
|
|
162
|
+
const hasSearchedRef = useRef(false);
|
|
163
|
+
const isFirstReloadRef = useRef(true);
|
|
164
|
+
const isPaginated = !!paginated && typeof onSearch === "function";
|
|
165
|
+
const pageRef = useRef(1);
|
|
166
|
+
const searchTermRef = useRef("");
|
|
167
|
+
const accumulatedRef = useRef([]);
|
|
168
|
+
const [managedHasMore, setManagedHasMore] = useState(false);
|
|
169
|
+
const [managedLoadingMore, setManagedLoadingMore] = useState(false);
|
|
170
|
+
const runPaginatedSearch = useCallback(
|
|
171
|
+
async (term, nextPage) => {
|
|
172
|
+
const offset = (nextPage - 1) * pageSize;
|
|
173
|
+
const res = await onSearch(term, {
|
|
174
|
+
page: nextPage,
|
|
175
|
+
pageSize,
|
|
176
|
+
limit: pageSize,
|
|
177
|
+
offset
|
|
178
|
+
});
|
|
179
|
+
const raw = Array.isArray(res) ? res : res?.items || [];
|
|
180
|
+
const items = raw.map(buildOption);
|
|
181
|
+
const more = Array.isArray(res) ? raw.length === pageSize : !!res?.hasMore;
|
|
182
|
+
return { items, more };
|
|
183
|
+
},
|
|
184
|
+
[onSearch, pageSize, buildOption]
|
|
185
|
+
);
|
|
186
|
+
const handleManagedLoadMore = useCallback(async () => {
|
|
187
|
+
if (managedLoadingMore || !managedHasMore) return;
|
|
188
|
+
setManagedLoadingMore(true);
|
|
189
|
+
try {
|
|
190
|
+
const nextPage = pageRef.current + 1;
|
|
191
|
+
const { items, more } = await runPaginatedSearch(
|
|
192
|
+
searchTermRef.current,
|
|
193
|
+
nextPage
|
|
194
|
+
);
|
|
195
|
+
pageRef.current = nextPage;
|
|
196
|
+
accumulatedRef.current = [...accumulatedRef.current, ...items];
|
|
197
|
+
setOptions(transToGroupOption(accumulatedRef.current, groupBy));
|
|
198
|
+
setManagedHasMore(more);
|
|
199
|
+
} finally {
|
|
200
|
+
setManagedLoadingMore(false);
|
|
201
|
+
}
|
|
202
|
+
}, [managedHasMore, managedLoadingMore, runPaginatedSearch, groupBy]);
|
|
203
|
+
const effectiveOnLoadMore = isPaginated ? handleManagedLoadMore : onLoadMore;
|
|
204
|
+
const effectiveHasMore = isPaginated ? managedHasMore : hasMore;
|
|
205
|
+
const effectiveIsLoadingMore = isPaginated ? managedLoadingMore : isLoadingMore;
|
|
206
|
+
useImperativeHandle(
|
|
207
|
+
ref,
|
|
208
|
+
() => ({
|
|
209
|
+
selectedValue: [...selected],
|
|
210
|
+
input: inputRef.current,
|
|
211
|
+
focus: () => inputRef?.current?.focus(),
|
|
212
|
+
reset: () => setSelected([])
|
|
213
|
+
}),
|
|
214
|
+
[selected]
|
|
215
|
+
);
|
|
216
|
+
useLayoutEffect(() => {
|
|
217
|
+
const cmdkLabels = document.querySelectorAll("label[cmdk-label]");
|
|
218
|
+
cmdkLabels.forEach((label) => {
|
|
219
|
+
label.remove();
|
|
220
|
+
});
|
|
221
|
+
}, []);
|
|
222
|
+
const handleClickOutside = (event) => {
|
|
223
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target) && inputRef.current && !inputRef.current.contains(event.target)) {
|
|
224
|
+
setOpen(false);
|
|
225
|
+
inputRef.current.blur();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const handleUnselect = useCallback(
|
|
229
|
+
(option) => {
|
|
230
|
+
if (!isChange) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const newOptions = selected.filter((s) => s.value !== option.value);
|
|
234
|
+
setSelected(newOptions);
|
|
235
|
+
onChange?.(newOptions);
|
|
236
|
+
},
|
|
237
|
+
[isChange, onChange, selected]
|
|
238
|
+
);
|
|
239
|
+
const handleKeyDown = useCallback(
|
|
240
|
+
(e) => {
|
|
241
|
+
const input = inputRef.current;
|
|
242
|
+
if (input) {
|
|
243
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
244
|
+
if (input.value === "" && selected.length > 0) {
|
|
245
|
+
const lastSelectOption = selected[selected.length - 1];
|
|
246
|
+
if (!lastSelectOption.fixed) {
|
|
247
|
+
handleUnselect(selected[selected.length - 1]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (e.key === "Escape") {
|
|
252
|
+
input.blur();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
[handleUnselect, selected]
|
|
257
|
+
);
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (open) {
|
|
260
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
261
|
+
document.addEventListener("touchend", handleClickOutside);
|
|
262
|
+
} else {
|
|
263
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
264
|
+
document.removeEventListener("touchend", handleClickOutside);
|
|
265
|
+
}
|
|
266
|
+
return () => {
|
|
267
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
268
|
+
document.removeEventListener("touchend", handleClickOutside);
|
|
269
|
+
};
|
|
270
|
+
}, [open]);
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
if (value) {
|
|
273
|
+
setSelected(value);
|
|
274
|
+
} else {
|
|
275
|
+
setSelected([]);
|
|
276
|
+
}
|
|
277
|
+
}, [value]);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
if (!onSearch || !preloadOnMount) return;
|
|
280
|
+
const loadInitial = async () => {
|
|
281
|
+
setIsLoading(true);
|
|
282
|
+
const res = await onSearch("");
|
|
283
|
+
setOptions(transToGroupOption(res?.map(buildOption) || [], groupBy));
|
|
284
|
+
setIsLoading(false);
|
|
285
|
+
};
|
|
286
|
+
void loadInitial();
|
|
287
|
+
}, []);
|
|
288
|
+
useEffect(() => {
|
|
289
|
+
if (reloadTrigger === void 0) return;
|
|
290
|
+
if (isFirstReloadRef.current) {
|
|
291
|
+
isFirstReloadRef.current = false;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (!onSearch || !preloadOnMount) return;
|
|
295
|
+
hasSearchedRef.current = false;
|
|
296
|
+
setInputValue("");
|
|
297
|
+
const reload = async () => {
|
|
298
|
+
setIsLoading(true);
|
|
299
|
+
const res = await onSearch("");
|
|
300
|
+
setOptions(transToGroupOption(res?.map(buildOption) || [], groupBy));
|
|
301
|
+
setIsLoading(false);
|
|
302
|
+
};
|
|
303
|
+
void reload();
|
|
304
|
+
}, [reloadTrigger]);
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
if (!arrayOptions || onSearch && !onLoadMore) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const newOption = transToGroupOption(arrayOptions || [], groupBy);
|
|
310
|
+
if (!isSameGroupOption(newOption, options)) {
|
|
311
|
+
setOptions(newOption);
|
|
312
|
+
}
|
|
313
|
+
}, [
|
|
314
|
+
arrayDefaultOptions,
|
|
315
|
+
arrayOptions,
|
|
316
|
+
groupBy,
|
|
317
|
+
onSearch,
|
|
318
|
+
onLoadMore,
|
|
319
|
+
options
|
|
320
|
+
]);
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
const doSearchSync = () => {
|
|
323
|
+
const res = onSearchSync?.(debouncedSearchTerm);
|
|
324
|
+
setOptions(transToGroupOption(res?.map(buildOption) || [], groupBy));
|
|
325
|
+
};
|
|
326
|
+
const exec = async () => {
|
|
327
|
+
if (!onSearchSync || !open) return;
|
|
328
|
+
if (triggerSearchOnFocus) {
|
|
329
|
+
doSearchSync();
|
|
330
|
+
}
|
|
331
|
+
if (debouncedSearchTerm) {
|
|
332
|
+
doSearchSync();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
void exec();
|
|
336
|
+
}, [debouncedSearchTerm, groupBy, open, triggerSearchOnFocus]);
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
const doSearch = async () => {
|
|
339
|
+
setIsLoading(true);
|
|
340
|
+
if (isPaginated) {
|
|
341
|
+
pageRef.current = 1;
|
|
342
|
+
searchTermRef.current = debouncedSearchTerm;
|
|
343
|
+
const { items, more } = await runPaginatedSearch(
|
|
344
|
+
debouncedSearchTerm,
|
|
345
|
+
1
|
|
346
|
+
);
|
|
347
|
+
accumulatedRef.current = items;
|
|
348
|
+
setOptions(transToGroupOption(items, groupBy));
|
|
349
|
+
setManagedHasMore(more);
|
|
350
|
+
} else {
|
|
351
|
+
const res = await onSearch?.(debouncedSearchTerm);
|
|
352
|
+
setOptions(transToGroupOption(res?.map(buildOption) || [], groupBy));
|
|
353
|
+
}
|
|
354
|
+
setIsLoading(false);
|
|
355
|
+
};
|
|
356
|
+
const exec = async () => {
|
|
357
|
+
if (!onSearch || !open) return;
|
|
358
|
+
if (preloadOnMount) {
|
|
359
|
+
if (debouncedSearchTerm) {
|
|
360
|
+
hasSearchedRef.current = true;
|
|
361
|
+
await doSearch();
|
|
362
|
+
} else if (hasSearchedRef.current) {
|
|
363
|
+
hasSearchedRef.current = false;
|
|
364
|
+
await doSearch();
|
|
365
|
+
} else {
|
|
366
|
+
const hasOptions = Array.from(options.values()).some(
|
|
367
|
+
(arr) => arr.length > 0
|
|
368
|
+
);
|
|
369
|
+
if (!hasOptions) {
|
|
370
|
+
await doSearch();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (triggerSearchOnFocus) {
|
|
376
|
+
await doSearch();
|
|
377
|
+
}
|
|
378
|
+
if (debouncedSearchTerm) {
|
|
379
|
+
await doSearch();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
void exec();
|
|
383
|
+
}, [
|
|
384
|
+
debouncedSearchTerm,
|
|
385
|
+
groupBy,
|
|
386
|
+
open,
|
|
387
|
+
triggerSearchOnFocus,
|
|
388
|
+
preloadOnMount
|
|
389
|
+
]);
|
|
390
|
+
const CreatableItem = () => {
|
|
391
|
+
if (!creatable) return void 0;
|
|
392
|
+
if (isOptionsExist(options, [{ value: inputValue, label: inputValue }]) || selected.find((s) => s.value === inputValue)) {
|
|
393
|
+
return void 0;
|
|
394
|
+
}
|
|
395
|
+
const Item = /* @__PURE__ */ jsx(
|
|
396
|
+
CommandItem,
|
|
397
|
+
{
|
|
398
|
+
value: inputValue,
|
|
399
|
+
className: cn("cursor-pointer", className),
|
|
400
|
+
onMouseDown: (e) => {
|
|
401
|
+
e.preventDefault();
|
|
402
|
+
e.stopPropagation();
|
|
403
|
+
},
|
|
404
|
+
onSelect: (value2) => {
|
|
405
|
+
if (!isChange) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (selected.length >= maxSelected) {
|
|
409
|
+
onMaxSelected?.(selected.length);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
setInputValue("");
|
|
413
|
+
const newOptions = [...selected, { value: value2, label: value2 }];
|
|
414
|
+
setSelected(newOptions);
|
|
415
|
+
onChange?.(newOptions);
|
|
416
|
+
},
|
|
417
|
+
children: props?.renderCreatableLabel?.(inputValue) || `Create "${inputValue}"`
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
if (!onSearch && inputValue.length > 0) {
|
|
421
|
+
return Item;
|
|
422
|
+
}
|
|
423
|
+
if (onSearch && debouncedSearchTerm.length > 0 && !isLoading) {
|
|
424
|
+
return Item;
|
|
425
|
+
}
|
|
426
|
+
return void 0;
|
|
427
|
+
};
|
|
428
|
+
const EmptyItem = useCallback(() => {
|
|
429
|
+
const indicator = emptyIndicator || /* @__PURE__ */ jsx(DefaultEmptyIndicator, {});
|
|
430
|
+
if (onSearch && !creatable && options.size === 0) {
|
|
431
|
+
return /* @__PURE__ */ jsx(CommandItem, { value: "-", disabled: true, children: indicator });
|
|
432
|
+
}
|
|
433
|
+
return /* @__PURE__ */ jsx(CommandEmpty, { children: indicator });
|
|
434
|
+
}, [creatable, emptyIndicator, onSearch, options]);
|
|
435
|
+
const selectables = useMemo(
|
|
436
|
+
() => removePickedOption(options, selected),
|
|
437
|
+
[options, selected]
|
|
438
|
+
);
|
|
439
|
+
const nonEmptySelectableEntries = useMemo(
|
|
440
|
+
() => Array.from(selectables.entries()).filter(
|
|
441
|
+
([, items]) => items.length > 0
|
|
442
|
+
),
|
|
443
|
+
[selectables]
|
|
444
|
+
);
|
|
445
|
+
const effectiveShouldFilter = commandProps?.shouldFilter !== void 0 ? commandProps.shouldFilter : !onSearch;
|
|
446
|
+
const totalSelectableCount = useMemo(
|
|
447
|
+
() => nonEmptySelectableEntries.reduce(
|
|
448
|
+
(sum, [, items]) => sum + items.length,
|
|
449
|
+
0
|
|
450
|
+
),
|
|
451
|
+
[nonEmptySelectableEntries]
|
|
452
|
+
);
|
|
453
|
+
const shouldWindow = !effectiveShouldFilter && totalSelectableCount > RENDER_WINDOW_SIZE;
|
|
454
|
+
const [renderLimit, setRenderLimit] = useState(RENDER_WINDOW_SIZE);
|
|
455
|
+
const localRevealObserverRef = useRef(null);
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
setRenderLimit(RENDER_WINDOW_SIZE);
|
|
458
|
+
}, [debouncedSearchTerm, open]);
|
|
459
|
+
const windowedSelectableEntries = useMemo(() => {
|
|
460
|
+
if (!shouldWindow) return nonEmptySelectableEntries;
|
|
461
|
+
let remaining = renderLimit;
|
|
462
|
+
const result = [];
|
|
463
|
+
for (const [key, items] of nonEmptySelectableEntries) {
|
|
464
|
+
if (remaining <= 0) break;
|
|
465
|
+
const slice = items.slice(0, remaining);
|
|
466
|
+
remaining -= slice.length;
|
|
467
|
+
result.push([key, slice]);
|
|
468
|
+
}
|
|
469
|
+
return result;
|
|
470
|
+
}, [shouldWindow, nonEmptySelectableEntries, renderLimit]);
|
|
471
|
+
const localRevealSentinelRef = useCallback((node) => {
|
|
472
|
+
if (localRevealObserverRef.current) {
|
|
473
|
+
localRevealObserverRef.current.disconnect();
|
|
474
|
+
localRevealObserverRef.current = null;
|
|
475
|
+
}
|
|
476
|
+
if (!node) return;
|
|
477
|
+
localRevealObserverRef.current = new IntersectionObserver((entries) => {
|
|
478
|
+
if (entries[0].isIntersecting) {
|
|
479
|
+
setRenderLimit((prev) => prev + RENDER_WINDOW_SIZE);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
localRevealObserverRef.current.observe(node);
|
|
483
|
+
}, []);
|
|
484
|
+
const observerRef = useRef(null);
|
|
485
|
+
const commandListRef = useRef(null);
|
|
486
|
+
const hasMoreRef = useRef(effectiveHasMore);
|
|
487
|
+
const isLoadingMoreRef = useRef(effectiveIsLoadingMore);
|
|
488
|
+
const hasOverflowedRef = useRef(false);
|
|
489
|
+
useEffect(() => {
|
|
490
|
+
hasMoreRef.current = effectiveHasMore;
|
|
491
|
+
}, [effectiveHasMore]);
|
|
492
|
+
useEffect(() => {
|
|
493
|
+
isLoadingMoreRef.current = effectiveIsLoadingMore;
|
|
494
|
+
}, [effectiveIsLoadingMore]);
|
|
495
|
+
useEffect(() => {
|
|
496
|
+
if (!open) hasOverflowedRef.current = false;
|
|
497
|
+
}, [open]);
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
if (disableAutoFillLoadMore || !open || !effectiveOnLoadMore || !effectiveHasMore || effectiveIsLoadingMore)
|
|
500
|
+
return;
|
|
501
|
+
if (hasOverflowedRef.current) return;
|
|
502
|
+
const element = commandListRef.current;
|
|
503
|
+
if (!element) return;
|
|
504
|
+
if (element.scrollHeight > element.clientHeight) {
|
|
505
|
+
hasOverflowedRef.current = true;
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (element.scrollHeight === element.clientHeight && nonEmptySelectableEntries.length > 0) {
|
|
509
|
+
effectiveOnLoadMore();
|
|
510
|
+
}
|
|
511
|
+
}, [
|
|
512
|
+
disableAutoFillLoadMore,
|
|
513
|
+
open,
|
|
514
|
+
options,
|
|
515
|
+
effectiveHasMore,
|
|
516
|
+
effectiveIsLoadingMore,
|
|
517
|
+
effectiveOnLoadMore,
|
|
518
|
+
nonEmptySelectableEntries
|
|
519
|
+
]);
|
|
520
|
+
const sentinelRef = useCallback(
|
|
521
|
+
(node) => {
|
|
522
|
+
if (observerRef.current) {
|
|
523
|
+
observerRef.current.disconnect();
|
|
524
|
+
observerRef.current = null;
|
|
525
|
+
}
|
|
526
|
+
if (!node || !effectiveOnLoadMore) return;
|
|
527
|
+
let wasNotIntersecting = false;
|
|
528
|
+
observerRef.current = new IntersectionObserver((entries) => {
|
|
529
|
+
const entry = entries[0];
|
|
530
|
+
if (!entry.isIntersecting) {
|
|
531
|
+
wasNotIntersecting = true;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (!wasNotIntersecting) return;
|
|
535
|
+
if (hasMoreRef.current && !isLoadingMoreRef.current) {
|
|
536
|
+
effectiveOnLoadMore();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
observerRef.current.observe(node);
|
|
540
|
+
},
|
|
541
|
+
[effectiveOnLoadMore]
|
|
542
|
+
);
|
|
543
|
+
const commandFilter = useCallback(() => {
|
|
544
|
+
if (commandProps?.filter) {
|
|
545
|
+
return commandProps.filter;
|
|
546
|
+
}
|
|
547
|
+
if (creatable) {
|
|
548
|
+
return (value2, search) => {
|
|
549
|
+
return value2.toLowerCase().includes(search.toLowerCase()) ? 1 : -1;
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return void 0;
|
|
553
|
+
}, [creatable, commandProps?.filter]);
|
|
554
|
+
const displayCount = typeof maxDisplayCount === "number" && maxDisplayCount > 0 ? maxDisplayCount : Number.MAX_SAFE_INTEGER;
|
|
555
|
+
const displayedSelected = selected.slice(0, displayCount);
|
|
556
|
+
const remainingCount = selected.length > displayCount ? selected.length - displayCount : 0;
|
|
557
|
+
return /* @__PURE__ */ jsx(
|
|
558
|
+
Command,
|
|
559
|
+
{
|
|
560
|
+
ref: dropdownRef,
|
|
561
|
+
...commandProps,
|
|
562
|
+
onKeyDown: (e) => {
|
|
563
|
+
handleKeyDown(e);
|
|
564
|
+
commandProps?.onKeyDown?.(e);
|
|
565
|
+
},
|
|
566
|
+
className: cn(
|
|
567
|
+
"h-auto overflow-visible bg-transparent",
|
|
568
|
+
commandProps?.className
|
|
569
|
+
),
|
|
570
|
+
shouldFilter: effectiveShouldFilter,
|
|
571
|
+
filter: commandFilter(),
|
|
572
|
+
onBlur,
|
|
573
|
+
children: /* @__PURE__ */ jsxs(Root, { children: [
|
|
574
|
+
/* @__PURE__ */ jsx(Anchor, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
575
|
+
"div",
|
|
576
|
+
{
|
|
577
|
+
className: cn(
|
|
578
|
+
autoHeight ? "flex min-h-9 items-start rounded-md border border-input bg-card px-2 py-2 text-sm shadow-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring" : "flex max-h-32 min-h-9 items-start overflow-y-auto rounded-md border border-input bg-card px-2 text-sm shadow-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring",
|
|
579
|
+
{
|
|
580
|
+
"py-3": !inlineInput && selected.length >= 1,
|
|
581
|
+
"cursor-text": !disabled && selected.length !== 0,
|
|
582
|
+
"bg-muted !py-0": disabled
|
|
583
|
+
},
|
|
584
|
+
className
|
|
585
|
+
),
|
|
586
|
+
onClick: () => {
|
|
587
|
+
if (disabled || !isChange) return;
|
|
588
|
+
inputRef?.current?.focus();
|
|
589
|
+
},
|
|
590
|
+
children: /* @__PURE__ */ jsxs(
|
|
591
|
+
"div",
|
|
592
|
+
{
|
|
593
|
+
className: cn(
|
|
594
|
+
"relative my-auto flex w-full flex-wrap items-center gap-2",
|
|
595
|
+
className
|
|
596
|
+
),
|
|
597
|
+
children: [
|
|
598
|
+
displayedSelected.map((option) => {
|
|
599
|
+
return /* @__PURE__ */ jsxs(
|
|
600
|
+
Badge,
|
|
601
|
+
{
|
|
602
|
+
variant: "chip",
|
|
603
|
+
className: cn(
|
|
604
|
+
"z-1 max-w-[220px] data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",
|
|
605
|
+
textVariants({ size }),
|
|
606
|
+
badgeClassName
|
|
607
|
+
),
|
|
608
|
+
style: getBadgeStyle ? getBadgeStyle(option) : void 0,
|
|
609
|
+
"data-fixed": option.fixed,
|
|
610
|
+
"data-disabled": disabled || void 0,
|
|
611
|
+
children: [
|
|
612
|
+
renderBadgeLabel ? renderBadgeLabel(option) : /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: option.label }),
|
|
613
|
+
/* @__PURE__ */ jsx(
|
|
614
|
+
"button",
|
|
615
|
+
{
|
|
616
|
+
type: "button",
|
|
617
|
+
className: cn(
|
|
618
|
+
"ml-1 shrink-0 rounded-full outline-none ring-offset-background focus:ring-1 focus:ring-ring",
|
|
619
|
+
(disabled || option.fixed) && "hidden"
|
|
620
|
+
),
|
|
621
|
+
onKeyDown: (e) => {
|
|
622
|
+
if (e.key === "Enter") {
|
|
623
|
+
handleUnselect(option);
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
onMouseDown: (e) => {
|
|
627
|
+
e.preventDefault();
|
|
628
|
+
e.stopPropagation();
|
|
629
|
+
},
|
|
630
|
+
onClick: () => handleUnselect(option),
|
|
631
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3 text-muted-foreground hover:text-foreground" })
|
|
632
|
+
}
|
|
633
|
+
)
|
|
634
|
+
]
|
|
635
|
+
},
|
|
636
|
+
option.key || option.value
|
|
637
|
+
);
|
|
638
|
+
}),
|
|
639
|
+
remainingCount > 0 && /* @__PURE__ */ jsxs(
|
|
640
|
+
Badge,
|
|
641
|
+
{
|
|
642
|
+
variant: "chip",
|
|
643
|
+
className: cn(
|
|
644
|
+
"z-1",
|
|
645
|
+
textVariants({ size }),
|
|
646
|
+
badgeClassName
|
|
647
|
+
),
|
|
648
|
+
children: [
|
|
649
|
+
"+",
|
|
650
|
+
remainingCount
|
|
651
|
+
]
|
|
652
|
+
}
|
|
653
|
+
),
|
|
654
|
+
/* @__PURE__ */ jsx(
|
|
655
|
+
CommandPrimitive.Input,
|
|
656
|
+
{
|
|
657
|
+
...inputProps,
|
|
658
|
+
ref: inputRef,
|
|
659
|
+
size: 1,
|
|
660
|
+
value: inputValue,
|
|
661
|
+
disabled,
|
|
662
|
+
onValueChange: (value2) => {
|
|
663
|
+
setInputValue(value2);
|
|
664
|
+
inputProps?.onValueChange?.(value2);
|
|
665
|
+
},
|
|
666
|
+
onBlur: (event) => {
|
|
667
|
+
if (!onScrollbar) {
|
|
668
|
+
setOpen(false);
|
|
669
|
+
}
|
|
670
|
+
inputProps?.onBlur?.(event);
|
|
671
|
+
},
|
|
672
|
+
onFocus: (event) => {
|
|
673
|
+
setOpen(true);
|
|
674
|
+
inputProps?.onFocus?.(event);
|
|
675
|
+
},
|
|
676
|
+
placeholder: hidePlaceholderWhenSelected && selected.length !== 0 ? "" : placeholder,
|
|
677
|
+
className: cn(
|
|
678
|
+
"min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground",
|
|
679
|
+
{
|
|
680
|
+
"w-full": hidePlaceholderWhenSelected,
|
|
681
|
+
"px-3 py-[0.35rem]": selected.length === 0,
|
|
682
|
+
"mt-1 basis-full": !inlineInput && selected.length !== 0
|
|
683
|
+
},
|
|
684
|
+
textVariants({ size }),
|
|
685
|
+
inputProps?.className
|
|
686
|
+
)
|
|
687
|
+
}
|
|
688
|
+
),
|
|
689
|
+
/* @__PURE__ */ jsx(
|
|
690
|
+
"button",
|
|
691
|
+
{
|
|
692
|
+
type: "button",
|
|
693
|
+
onClick: () => {
|
|
694
|
+
setSelected(selected.filter((s) => s.fixed));
|
|
695
|
+
onChange?.(selected.filter((s) => s.fixed));
|
|
696
|
+
},
|
|
697
|
+
className: cn(
|
|
698
|
+
"absolute right-0 top-[6px] h-[14px] w-[14px] p-0",
|
|
699
|
+
(hideClearAllButton || disabled || selected.length < 1 || selected.filter((s) => s.fixed).length === selected.length) && "hidden"
|
|
700
|
+
),
|
|
701
|
+
children: /* @__PURE__ */ jsx(X, { size: size == "small" ? 12 : 14 })
|
|
702
|
+
}
|
|
703
|
+
)
|
|
704
|
+
]
|
|
705
|
+
}
|
|
706
|
+
)
|
|
707
|
+
}
|
|
708
|
+
) }),
|
|
709
|
+
open && /* @__PURE__ */ jsx(
|
|
710
|
+
Content,
|
|
711
|
+
{
|
|
712
|
+
side: "bottom",
|
|
713
|
+
align: "start",
|
|
714
|
+
sideOffset: 5,
|
|
715
|
+
className: "z-[60] w-[var(--radix-popper-anchor-width)]",
|
|
716
|
+
children: /* @__PURE__ */ jsx(
|
|
717
|
+
CommandList,
|
|
718
|
+
{
|
|
719
|
+
ref: commandListRef,
|
|
720
|
+
className: cn(
|
|
721
|
+
"z-[60] w-full bg-popover text-popover-foreground shadow-md outline-none animate-in",
|
|
722
|
+
open && options.length > 0 && "rounded-md border"
|
|
723
|
+
),
|
|
724
|
+
onMouseLeave: () => {
|
|
725
|
+
setOnScrollbar(false);
|
|
726
|
+
},
|
|
727
|
+
onMouseEnter: () => {
|
|
728
|
+
setOnScrollbar(true);
|
|
729
|
+
},
|
|
730
|
+
onMouseUp: () => {
|
|
731
|
+
inputRef?.current?.focus();
|
|
732
|
+
},
|
|
733
|
+
children: isLoading ? /* @__PURE__ */ jsx(Fragment, { children: loadingIndicator }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
734
|
+
inputValue.length > 0 && EmptyItem(),
|
|
735
|
+
CreatableItem(),
|
|
736
|
+
!selectFirstItem && /* @__PURE__ */ jsx(CommandItem, { value: "-", className: "hidden" }),
|
|
737
|
+
windowedSelectableEntries.map(([key, dropdowns]) => {
|
|
738
|
+
const heading = props.renderGroupHeading?.(key) || key;
|
|
739
|
+
return /* @__PURE__ */ jsx(
|
|
740
|
+
CommandGroup,
|
|
741
|
+
{
|
|
742
|
+
heading,
|
|
743
|
+
className: "h-full overflow-auto",
|
|
744
|
+
children: /* @__PURE__ */ jsx(Fragment, { children: dropdowns.map((option) => {
|
|
745
|
+
const itemKey = option.key || option.value;
|
|
746
|
+
return /* @__PURE__ */ jsx(
|
|
747
|
+
CommandItem,
|
|
748
|
+
{
|
|
749
|
+
value: option.value,
|
|
750
|
+
disabled: option.disable,
|
|
751
|
+
keywords: [option.label],
|
|
752
|
+
onMouseDown: (e) => {
|
|
753
|
+
e.preventDefault();
|
|
754
|
+
e.stopPropagation();
|
|
755
|
+
},
|
|
756
|
+
onSelect: () => {
|
|
757
|
+
if (!isChange) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (selected.length >= maxSelected) {
|
|
761
|
+
onMaxSelected?.(selected.length);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
setInputValue("");
|
|
765
|
+
const newOptions = [...selected, option];
|
|
766
|
+
setSelected(newOptions);
|
|
767
|
+
onChange?.(newOptions);
|
|
768
|
+
},
|
|
769
|
+
className: cn(
|
|
770
|
+
"cursor-pointer",
|
|
771
|
+
textVariants({ size }),
|
|
772
|
+
option.disable && "cursor-default text-muted-foreground"
|
|
773
|
+
),
|
|
774
|
+
children: props?.renderOptionLabel ? props.renderOptionLabel(option) : option.label
|
|
775
|
+
},
|
|
776
|
+
itemKey
|
|
777
|
+
);
|
|
778
|
+
}) })
|
|
779
|
+
},
|
|
780
|
+
key
|
|
781
|
+
);
|
|
782
|
+
}),
|
|
783
|
+
shouldWindow && renderLimit < totalSelectableCount && /* @__PURE__ */ jsx(
|
|
784
|
+
"div",
|
|
785
|
+
{
|
|
786
|
+
ref: localRevealSentinelRef,
|
|
787
|
+
"aria-hidden": true,
|
|
788
|
+
className: "h-px"
|
|
789
|
+
}
|
|
790
|
+
),
|
|
791
|
+
effectiveIsLoadingMore && /* @__PURE__ */ jsxs(
|
|
792
|
+
CommandItem,
|
|
793
|
+
{
|
|
794
|
+
disabled: true,
|
|
795
|
+
value: "__load_more__",
|
|
796
|
+
className: cn(
|
|
797
|
+
"justify-center text-muted-foreground",
|
|
798
|
+
textVariants({ size })
|
|
799
|
+
),
|
|
800
|
+
children: [
|
|
801
|
+
/* @__PURE__ */ jsx(LoaderCircle, { className: "mr-2 h-4 w-4 animate-spin" }),
|
|
802
|
+
loadMoreText
|
|
803
|
+
]
|
|
804
|
+
}
|
|
805
|
+
),
|
|
806
|
+
effectiveOnLoadMore && /* @__PURE__ */ jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-px" })
|
|
807
|
+
] })
|
|
808
|
+
}
|
|
809
|
+
)
|
|
810
|
+
}
|
|
811
|
+
)
|
|
812
|
+
] })
|
|
813
|
+
}
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
MultipleSelector.displayName = "MultipleSelector";
|
|
818
|
+
var multiple_selector_default = MultipleSelector;
|
|
819
|
+
export {
|
|
820
|
+
multiple_selector_default as default
|
|
821
|
+
};
|