funda-ui 4.7.624 → 4.7.701
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/{publish/CascadingSelect → CascadingSelect}/index.js +2 -2
- package/{publish/CascadingSelectE2E → CascadingSelectE2E}/index.js +2 -2
- package/{publish/Chatbox → Chatbox}/index.js +3 -17
- package/{publish/lib/cjs/Checkbox → Checkbox}/index.js +3 -3
- package/{publish/lib/cjs/ColorPicker → ColorPicker}/index.js +3 -18
- package/{publish/lib/cjs/Date → Date}/index.js +3 -18
- package/{publish/lib/cjs/EventCalendarTimeline → EventCalendarTimeline}/index.d.ts +1 -1
- package/{publish/EventCalendarTimeline → EventCalendarTimeline}/index.js +11 -1
- package/{publish/File → File}/index.d.ts +9 -0
- package/{publish/lib/cjs/File → File}/index.js +245 -93
- package/{publish/lib/cjs/Input → Input}/index.js +3 -18
- package/{publish/lib/cjs/LiveSearch → LiveSearch}/index.js +3 -18
- package/{publish/NativeSelect → NativeSelect}/index.js +3 -3
- package/{publish/NumberInput → NumberInput}/index.js +3 -18
- package/{publish/lib/css/Tooltip → Popover}/index.css +69 -69
- package/Popover/index.d.ts +4 -0
- package/{publish/lib/cjs/Tooltip → Popover}/index.js +301 -271
- package/README.md +3 -116
- package/{publish/lib/cjs/Radio → Radio}/index.js +3 -3
- package/{publish/lib/cjs/RangeSlider → RangeSlider}/index.js +3 -18
- package/{publish/SearchBar → SearchBar}/index.js +3 -18
- package/{publish/Select → Select}/index.js +3 -2
- package/{publish/Switch → Switch}/index.js +3 -3
- package/TagInput/index.css +91 -0
- package/{publish/lib/cjs/TagInput → TagInput}/index.js +12 -23
- package/{publish/lib/cjs/Textarea → Textarea}/index.js +3 -17
- package/Utils/useSSE.d.ts +9 -0
- package/{publish/lib/cjs/Utils/useKeyPress.js → Utils/useSSE.js} +88 -77
- package/{publish/all.d.ts → all.d.ts} +1 -0
- package/{publish/all.js → all.js} +1 -0
- package/lib/cjs/CascadingSelect/index.js +2 -2
- package/lib/cjs/CascadingSelectE2E/index.js +2 -2
- package/lib/cjs/Chatbox/index.js +3 -17
- package/lib/cjs/Checkbox/index.js +3 -3
- package/lib/cjs/ColorPicker/index.js +3 -18
- package/lib/cjs/Date/index.js +3 -18
- package/lib/cjs/EventCalendarTimeline/index.d.ts +1 -1
- package/lib/cjs/EventCalendarTimeline/index.js +11 -1
- package/lib/cjs/File/index.d.ts +9 -0
- package/lib/cjs/File/index.js +245 -93
- package/lib/cjs/Input/index.js +3 -18
- package/lib/cjs/LiveSearch/index.js +3 -18
- package/lib/cjs/NativeSelect/index.js +3 -3
- package/lib/cjs/NumberInput/index.js +3 -18
- package/lib/cjs/Popover/index.d.ts +4 -0
- package/{publish/lib/cjs/DropdownMenu → lib/cjs/Popover}/index.js +553 -252
- package/lib/cjs/Radio/index.js +3 -3
- package/lib/cjs/RangeSlider/index.js +3 -18
- package/lib/cjs/SearchBar/index.js +3 -18
- package/lib/cjs/Select/index.js +3 -2
- package/lib/cjs/Switch/index.js +3 -3
- package/lib/cjs/TagInput/index.js +12 -23
- package/lib/cjs/Textarea/index.js +3 -17
- package/lib/cjs/Utils/useSSE.d.ts +9 -0
- package/{publish/lib/cjs/Utils/useAutosizeTextArea.js → lib/cjs/Utils/useSSE.js} +90 -110
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/css/Popover/index.css +198 -0
- package/lib/css/TagInput/index.css +31 -31
- package/lib/esm/CascadingSelect/index.tsx +2 -2
- package/lib/esm/CascadingSelectE2E/index.tsx +2 -2
- package/lib/esm/Checkbox/index.tsx +3 -3
- package/lib/esm/ColorPicker/index.tsx +4 -15
- package/lib/esm/EventCalendarTimeline/index.tsx +11 -2
- package/lib/esm/File/index.tsx +148 -23
- package/lib/esm/Input/index.tsx +6 -17
- package/lib/esm/NativeSelect/index.tsx +3 -3
- package/lib/esm/NumberInput/index.tsx +7 -15
- package/lib/esm/Popover/Popover.tsx +251 -0
- package/lib/esm/Popover/PopoverClose.tsx +51 -0
- package/lib/esm/Popover/PopoverContent.tsx +72 -0
- package/lib/esm/Popover/PopoverTrigger.tsx +62 -0
- package/{publish/lib/esm/Tooltip → lib/esm/Popover}/index.scss +61 -61
- package/lib/esm/Popover/index.tsx +4 -0
- package/lib/esm/Radio/index.tsx +3 -3
- package/lib/esm/SearchBar/index.tsx +8 -12
- package/lib/esm/Select/index.tsx +2 -2
- package/lib/esm/Switch/index.tsx +3 -3
- package/lib/esm/TagInput/index.scss +24 -24
- package/lib/esm/TagInput/index.tsx +13 -20
- package/lib/esm/Textarea/index.tsx +6 -14
- package/lib/esm/Utils/hooks/useSSE.tsx +109 -0
- package/lib/esm/index.js +1 -0
- package/package.json +1 -591
- package/.gitattributes +0 -2
- package/README_PUBLISH.md +0 -328
- package/logo.png +0 -0
- package/preview.png +0 -0
- package/publish/Checkbox/index.js +0 -673
- package/publish/ColorPicker/index.js +0 -662
- package/publish/Date/index.js +0 -6368
- package/publish/EventCalendarTimeline/index.d.ts +0 -100
- package/publish/File/index.js +0 -1751
- package/publish/Input/index.js +0 -1486
- package/publish/LICENSE +0 -21
- package/publish/LiveSearch/index.js +0 -4180
- package/publish/README.md +0 -328
- package/publish/Radio/index.js +0 -1838
- package/publish/RangeSlider/index.js +0 -2696
- package/publish/TagInput/index.css +0 -91
- package/publish/TagInput/index.js +0 -1227
- package/publish/Textarea/index.js +0 -1795
- package/publish/lib/cjs/Accordion/index.d.ts +0 -2
- package/publish/lib/cjs/Accordion/index.js +0 -667
- package/publish/lib/cjs/BackToTop/index.d.ts +0 -17
- package/publish/lib/cjs/BackToTop/index.js +0 -904
- package/publish/lib/cjs/CascadingSelect/index.d.ts +0 -80
- package/publish/lib/cjs/CascadingSelect/index.js +0 -3383
- package/publish/lib/cjs/CascadingSelectE2E/index.d.ts +0 -91
- package/publish/lib/cjs/CascadingSelectE2E/index.js +0 -3988
- package/publish/lib/cjs/Chatbox/index.d.ts +0 -101
- package/publish/lib/cjs/Chatbox/index.js +0 -7037
- package/publish/lib/cjs/Checkbox/index.d.ts +0 -28
- package/publish/lib/cjs/ColorPicker/index.d.ts +0 -27
- package/publish/lib/cjs/Date/index.d.ts +0 -70
- package/publish/lib/cjs/DigitalClock/index.d.ts +0 -7
- package/publish/lib/cjs/DigitalClock/index.js +0 -402
- package/publish/lib/cjs/DragDropList/index.d.ts +0 -45
- package/publish/lib/cjs/DragDropList/index.js +0 -1586
- package/publish/lib/cjs/DropdownMenu/index.d.ts +0 -38
- package/publish/lib/cjs/DynamicFields/index.d.ts +0 -40
- package/publish/lib/cjs/DynamicFields/index.js +0 -818
- package/publish/lib/cjs/EventCalendar/index.d.ts +0 -61
- package/publish/lib/cjs/EventCalendar/index.js +0 -3789
- package/publish/lib/cjs/EventCalendarTimeline/index.js +0 -6141
- package/publish/lib/cjs/File/index.d.ts +0 -40
- package/publish/lib/cjs/HorizontalScrollContent/index.d.ts +0 -14
- package/publish/lib/cjs/HorizontalScrollContent/index.js +0 -426
- package/publish/lib/cjs/Input/index.d.ts +0 -59
- package/publish/lib/cjs/LiveSearch/index.d.ts +0 -70
- package/publish/lib/cjs/MasonryLayout/index.d.ts +0 -14
- package/publish/lib/cjs/MasonryLayout/index.js +0 -689
- package/publish/lib/cjs/ModalDialog/index.d.ts +0 -83
- package/publish/lib/cjs/ModalDialog/index.js +0 -1719
- package/publish/lib/cjs/ModeSwitch/index.d.ts +0 -17
- package/publish/lib/cjs/ModeSwitch/index.js +0 -202
- package/publish/lib/cjs/MultilevelDropdownMenu/index.d.ts +0 -20
- package/publish/lib/cjs/MultilevelDropdownMenu/index.js +0 -930
- package/publish/lib/cjs/MultipleCheckboxes/index.d.ts +0 -66
- package/publish/lib/cjs/MultipleCheckboxes/index.js +0 -2337
- package/publish/lib/cjs/MultipleSelect/index.d.ts +0 -65
- package/publish/lib/cjs/MultipleSelect/index.js +0 -4197
- package/publish/lib/cjs/NativeSelect/index.d.ts +0 -37
- package/publish/lib/cjs/NativeSelect/index.js +0 -2052
- package/publish/lib/cjs/NumberInput/index.d.ts +0 -40
- package/publish/lib/cjs/NumberInput/index.js +0 -1191
- package/publish/lib/cjs/Pagination/index.d.ts +0 -51
- package/publish/lib/cjs/Pagination/index.js +0 -612
- package/publish/lib/cjs/Radio/index.d.ts +0 -45
- package/publish/lib/cjs/RangeSlider/index.d.ts +0 -22
- package/publish/lib/cjs/Refresher/index.d.ts +0 -22
- package/publish/lib/cjs/Refresher/index.js +0 -564
- package/publish/lib/cjs/RootPortal/index.d.ts +0 -9
- package/publish/lib/cjs/RootPortal/index.js +0 -148
- package/publish/lib/cjs/ScrollReveal/index.d.ts +0 -21
- package/publish/lib/cjs/ScrollReveal/index.js +0 -401
- package/publish/lib/cjs/Scrollbar/index.d.ts +0 -17
- package/publish/lib/cjs/Scrollbar/index.js +0 -1107
- package/publish/lib/cjs/SearchBar/index.d.ts +0 -41
- package/publish/lib/cjs/SearchBar/index.js +0 -701
- package/publish/lib/cjs/Select/index.d.ts +0 -107
- package/publish/lib/cjs/Select/index.js +0 -6540
- package/publish/lib/cjs/ShowMoreLess/index.d.ts +0 -36
- package/publish/lib/cjs/ShowMoreLess/index.js +0 -387
- package/publish/lib/cjs/SplitterPanel/index.d.ts +0 -20
- package/publish/lib/cjs/SplitterPanel/index.js +0 -800
- package/publish/lib/cjs/Stepper/index.d.ts +0 -26
- package/publish/lib/cjs/Stepper/index.js +0 -568
- package/publish/lib/cjs/Switch/index.d.ts +0 -25
- package/publish/lib/cjs/Switch/index.js +0 -630
- package/publish/lib/cjs/Table/index.d.ts +0 -12
- package/publish/lib/cjs/Table/index.js +0 -2311
- package/publish/lib/cjs/Tabs/index.d.ts +0 -3
- package/publish/lib/cjs/Tabs/index.js +0 -771
- package/publish/lib/cjs/TagInput/index.d.ts +0 -37
- package/publish/lib/cjs/Textarea/index.d.ts +0 -50
- package/publish/lib/cjs/Toast/index.d.ts +0 -3
- package/publish/lib/cjs/Toast/index.js +0 -1345
- package/publish/lib/cjs/Tooltip/index.d.ts +0 -38
- package/publish/lib/cjs/Tree/index.d.ts +0 -78
- package/publish/lib/cjs/Tree/index.js +0 -2330
- package/publish/lib/cjs/Utils/anim.d.ts +0 -11
- package/publish/lib/cjs/Utils/anim.js +0 -846
- package/publish/lib/cjs/Utils/bodyScrollLock.d.ts +0 -8
- package/publish/lib/cjs/Utils/bodyScrollLock.js +0 -311
- package/publish/lib/cjs/Utils/buffer.d.ts +0 -67
- package/publish/lib/cjs/Utils/buffer.js +0 -343
- package/publish/lib/cjs/Utils/cls.d.ts +0 -15
- package/publish/lib/cjs/Utils/cls.js +0 -124
- package/publish/lib/cjs/Utils/convert.d.ts +0 -25
- package/publish/lib/cjs/Utils/convert.js +0 -109
- package/publish/lib/cjs/Utils/date.d.ts +0 -227
- package/publish/lib/cjs/Utils/date.js +0 -587
- package/publish/lib/cjs/Utils/dom.d.ts +0 -13
- package/publish/lib/cjs/Utils/dom.js +0 -215
- package/publish/lib/cjs/Utils/easing.d.ts +0 -29
- package/publish/lib/cjs/Utils/easing.js +0 -221
- package/publish/lib/cjs/Utils/extract.d.ts +0 -66
- package/publish/lib/cjs/Utils/extract.js +0 -195
- package/publish/lib/cjs/Utils/format-string.d.ts +0 -65
- package/publish/lib/cjs/Utils/format-string.js +0 -167
- package/publish/lib/cjs/Utils/formdata.d.ts +0 -13
- package/publish/lib/cjs/Utils/formdata.js +0 -131
- package/publish/lib/cjs/Utils/getElementProperty.d.ts +0 -52
- package/publish/lib/cjs/Utils/getElementProperty.js +0 -189
- package/publish/lib/cjs/Utils/guid.d.ts +0 -7
- package/publish/lib/cjs/Utils/guid.js +0 -67
- package/publish/lib/cjs/Utils/initDefaultOptions.d.ts +0 -10
- package/publish/lib/cjs/Utils/initDefaultOptions.js +0 -607
- package/publish/lib/cjs/Utils/inputsCalculation.d.ts +0 -28
- package/publish/lib/cjs/Utils/inputsCalculation.js +0 -188
- package/publish/lib/cjs/Utils/math.d.ts +0 -77
- package/publish/lib/cjs/Utils/math.js +0 -305
- package/publish/lib/cjs/Utils/object.d.ts +0 -18
- package/publish/lib/cjs/Utils/object.js +0 -120
- package/publish/lib/cjs/Utils/os.d.ts +0 -2
- package/publish/lib/cjs/Utils/os.js +0 -104
- package/publish/lib/cjs/Utils/performance.d.ts +0 -3
- package/publish/lib/cjs/Utils/performance.js +0 -94
- package/publish/lib/cjs/Utils/sanitize.d.ts +0 -14
- package/publish/lib/cjs/Utils/sanitize.js +0 -87
- package/publish/lib/cjs/Utils/time.d.ts +0 -40
- package/publish/lib/cjs/Utils/time.js +0 -177
- package/publish/lib/cjs/Utils/tree.d.ts +0 -40
- package/publish/lib/cjs/Utils/tree.js +0 -195
- package/publish/lib/cjs/Utils/useAutosizeTextArea.d.ts +0 -10
- package/publish/lib/cjs/Utils/useBoundedDrag.d.ts +0 -125
- package/publish/lib/cjs/Utils/useBoundedDrag.js +0 -380
- package/publish/lib/cjs/Utils/useClickOutside.d.ts +0 -33
- package/publish/lib/cjs/Utils/useClickOutside.js +0 -166
- package/publish/lib/cjs/Utils/useComId.d.ts +0 -6
- package/publish/lib/cjs/Utils/useComId.js +0 -114
- package/publish/lib/cjs/Utils/useDebounce.d.ts +0 -20
- package/publish/lib/cjs/Utils/useDebounce.js +0 -138
- package/publish/lib/cjs/Utils/useDragDropPosition.d.ts +0 -166
- package/publish/lib/cjs/Utils/useDragDropPosition.js +0 -453
- package/publish/lib/cjs/Utils/useDraggable.d.ts +0 -62
- package/publish/lib/cjs/Utils/useDraggable.js +0 -348
- package/publish/lib/cjs/Utils/useHistoryTracker.d.ts +0 -166
- package/publish/lib/cjs/Utils/useHistoryTracker.js +0 -649
- package/publish/lib/cjs/Utils/useInterval.d.ts +0 -5
- package/publish/lib/cjs/Utils/useInterval.js +0 -168
- package/publish/lib/cjs/Utils/useIsMobile.d.ts +0 -2
- package/publish/lib/cjs/Utils/useIsMobile.js +0 -232
- package/publish/lib/cjs/Utils/useKeyPress.d.ts +0 -44
- package/publish/lib/cjs/Utils/useSessionStorageListener.d.ts +0 -2
- package/publish/lib/cjs/Utils/useSessionStorageListener.js +0 -157
- package/publish/lib/cjs/Utils/useStreamController.d.ts +0 -71
- package/publish/lib/cjs/Utils/useStreamController.js +0 -494
- package/publish/lib/cjs/Utils/useThrottle.d.ts +0 -2
- package/publish/lib/cjs/Utils/useThrottle.js +0 -136
- package/publish/lib/cjs/Utils/useWindowScroll.d.ts +0 -12
- package/publish/lib/cjs/Utils/useWindowScroll.js +0 -217
- package/publish/lib/cjs/Utils/validate.d.ts +0 -53
- package/publish/lib/cjs/Utils/validate.js +0 -536
- package/publish/lib/cjs/Utils/viewport.d.ts +0 -7
- package/publish/lib/cjs/Utils/viewport.js +0 -64
- package/publish/lib/cjs/index.d.ts +0 -49
- package/publish/lib/cjs/index.js +0 -50
- package/publish/lib/css/BackToTop/index.css +0 -34
- package/publish/lib/css/CascadingSelect/index.css +0 -245
- package/publish/lib/css/CascadingSelectE2E/index.css +0 -245
- package/publish/lib/css/Chatbox/index.css +0 -774
- package/publish/lib/css/ColorPicker/index.css +0 -58
- package/publish/lib/css/Date/index.css +0 -434
- package/publish/lib/css/DragDropList/index.css +0 -188
- package/publish/lib/css/DropdownMenu/index.css +0 -151
- package/publish/lib/css/EventCalendar/index.css +0 -300
- package/publish/lib/css/EventCalendarTimeline/index.css +0 -694
- package/publish/lib/css/HorizontalScrollContent/index.css +0 -70
- package/publish/lib/css/LiveSearch/index.css +0 -88
- package/publish/lib/css/MultilevelDropdownMenu/index.css +0 -38
- package/publish/lib/css/MultipleSelect/index.css +0 -313
- package/publish/lib/css/RangeSlider/index.css +0 -150
- package/publish/lib/css/Scrollbar/index.css +0 -176
- package/publish/lib/css/Select/index.css +0 -434
- package/publish/lib/css/ShowMoreLess/index.css +0 -23
- package/publish/lib/css/SplitterPanel/index.css +0 -63
- package/publish/lib/css/Stepper/index.css +0 -250
- package/publish/lib/css/Table/index.css +0 -584
- package/publish/lib/css/TagInput/index.css +0 -91
- package/publish/lib/css/Toast/index.css +0 -149
- package/publish/lib/css/Tree/index.css +0 -237
- package/publish/lib/esm/Accordion/Accordion.tsx +0 -185
- package/publish/lib/esm/Accordion/AccordionItem.tsx +0 -248
- package/publish/lib/esm/Accordion/index.tsx +0 -2
- package/publish/lib/esm/BackToTop/index.scss +0 -47
- package/publish/lib/esm/BackToTop/index.tsx +0 -177
- package/publish/lib/esm/CascadingSelect/Group.tsx +0 -83
- package/publish/lib/esm/CascadingSelect/index.scss +0 -330
- package/publish/lib/esm/CascadingSelect/index.tsx +0 -1397
- package/publish/lib/esm/CascadingSelectE2E/Group.tsx +0 -87
- package/publish/lib/esm/CascadingSelectE2E/index.scss +0 -333
- package/publish/lib/esm/CascadingSelectE2E/index.tsx +0 -1684
- package/publish/lib/esm/Chatbox/PureLoader.tsx +0 -47
- package/publish/lib/esm/Chatbox/TypingEffect.tsx +0 -56
- package/publish/lib/esm/Chatbox/index.scss +0 -966
- package/publish/lib/esm/Chatbox/index.tsx +0 -1742
- package/publish/lib/esm/Chatbox/utils/func.ts +0 -180
- package/publish/lib/esm/Checkbox/index.tsx +0 -206
- package/publish/lib/esm/ColorPicker/index.scss +0 -91
- package/publish/lib/esm/ColorPicker/index.tsx +0 -204
- package/publish/lib/esm/Date/Calendar.tsx +0 -723
- package/publish/lib/esm/Date/index.scss +0 -567
- package/publish/lib/esm/Date/index.tsx +0 -1797
- package/publish/lib/esm/Date/localization/en_US.js +0 -13
- package/publish/lib/esm/Date/localization/zh_CN.js +0 -12
- package/publish/lib/esm/DigitalClock/index.tsx +0 -74
- package/publish/lib/esm/DragDropList/index.scss +0 -245
- package/publish/lib/esm/DragDropList/index.tsx +0 -504
- package/publish/lib/esm/DropdownMenu/Option.tsx +0 -55
- package/publish/lib/esm/DropdownMenu/index.scss +0 -205
- package/publish/lib/esm/DropdownMenu/index.tsx +0 -378
- package/publish/lib/esm/DynamicFields/index.tsx +0 -409
- package/publish/lib/esm/EventCalendar/index.scss +0 -407
- package/publish/lib/esm/EventCalendar/index.tsx +0 -1005
- package/publish/lib/esm/EventCalendarTimeline/index.scss +0 -926
- package/publish/lib/esm/EventCalendarTimeline/index.tsx +0 -2686
- package/publish/lib/esm/File/index.tsx +0 -477
- package/publish/lib/esm/HorizontalScrollContent/index.scss +0 -87
- package/publish/lib/esm/HorizontalScrollContent/index.tsx +0 -171
- package/publish/lib/esm/Input/index.tsx +0 -641
- package/publish/lib/esm/LiveSearch/index.scss +0 -129
- package/publish/lib/esm/LiveSearch/index.tsx +0 -1058
- package/publish/lib/esm/MasonryLayout/index.tsx +0 -326
- package/publish/lib/esm/ModalDialog/index.tsx +0 -572
- package/publish/lib/esm/ModeSwitch/index.tsx +0 -82
- package/publish/lib/esm/MultilevelDropdownMenu/ItemList.tsx +0 -265
- package/publish/lib/esm/MultilevelDropdownMenu/index.scss +0 -79
- package/publish/lib/esm/MultilevelDropdownMenu/index.tsx +0 -77
- package/publish/lib/esm/MultipleCheckboxes/index.tsx +0 -849
- package/publish/lib/esm/MultipleSelect/index.scss +0 -398
- package/publish/lib/esm/MultipleSelect/index.tsx +0 -769
- package/publish/lib/esm/MultipleSelect/utils/func.ts +0 -63
- package/publish/lib/esm/NativeSelect/index.tsx +0 -396
- package/publish/lib/esm/NativeSelect/utils/func.ts +0 -51
- package/publish/lib/esm/NumberInput/index.tsx +0 -425
- package/publish/lib/esm/Pagination/index.tsx +0 -286
- package/publish/lib/esm/Pagination/pagination-navigators.tsx +0 -60
- package/publish/lib/esm/Radio/index.tsx +0 -694
- package/publish/lib/esm/RangeSlider/index.scss +0 -186
- package/publish/lib/esm/RangeSlider/index.tsx +0 -241
- package/publish/lib/esm/Refresher/index.tsx +0 -121
- package/publish/lib/esm/RootPortal/index.tsx +0 -59
- package/publish/lib/esm/ScrollReveal/index.tsx +0 -148
- package/publish/lib/esm/Scrollbar/index.scss +0 -221
- package/publish/lib/esm/Scrollbar/index.tsx +0 -561
- package/publish/lib/esm/SearchBar/index.tsx +0 -252
- package/publish/lib/esm/Select/index.scss +0 -639
- package/publish/lib/esm/Select/index.tsx +0 -3104
- package/publish/lib/esm/Select/utils/func.ts +0 -98
- package/publish/lib/esm/ShowMoreLess/index.scss +0 -27
- package/publish/lib/esm/ShowMoreLess/index.tsx +0 -145
- package/publish/lib/esm/SplitterPanel/index.scss +0 -82
- package/publish/lib/esm/SplitterPanel/index.tsx +0 -174
- package/publish/lib/esm/Stepper/index.scss +0 -315
- package/publish/lib/esm/Stepper/index.tsx +0 -325
- package/publish/lib/esm/Switch/index.tsx +0 -149
- package/publish/lib/esm/Table/Table.tsx +0 -351
- package/publish/lib/esm/Table/TableBody.tsx +0 -41
- package/publish/lib/esm/Table/TableCaption.tsx +0 -34
- package/publish/lib/esm/Table/TableCell.tsx +0 -126
- package/publish/lib/esm/Table/TableColgroup.tsx +0 -38
- package/publish/lib/esm/Table/TableContext.tsx +0 -26
- package/publish/lib/esm/Table/TableFoot.tsx +0 -28
- package/publish/lib/esm/Table/TableHead.tsx +0 -28
- package/publish/lib/esm/Table/TableRow.tsx +0 -76
- package/publish/lib/esm/Table/index.scss +0 -418
- package/publish/lib/esm/Table/index.tsx +0 -14
- package/publish/lib/esm/Table/utils/DragHandleSprite.tsx +0 -46
- package/publish/lib/esm/Table/utils/SortSprite.tsx +0 -63
- package/publish/lib/esm/Table/utils/TableFilter.tsx +0 -56
- package/publish/lib/esm/Table/utils/ToggleSelection.tsx +0 -255
- package/publish/lib/esm/Table/utils/func.ts +0 -182
- package/publish/lib/esm/Table/utils/hooks/useTableDraggable.tsx +0 -342
- package/publish/lib/esm/Table/utils/hooks/useTableKeyPress.tsx +0 -255
- package/publish/lib/esm/Table/utils/hooks/useTableResponsive.tsx +0 -92
- package/publish/lib/esm/Table/utils/hooks/useTableSort.tsx +0 -187
- package/publish/lib/esm/Tabs/TabList.tsx +0 -50
- package/publish/lib/esm/Tabs/TabPanel.tsx +0 -44
- package/publish/lib/esm/Tabs/Tabs.tsx +0 -282
- package/publish/lib/esm/Tabs/index.tsx +0 -3
- package/publish/lib/esm/TagInput/index.scss +0 -126
- package/publish/lib/esm/TagInput/index.tsx +0 -379
- package/publish/lib/esm/Textarea/index.tsx +0 -621
- package/publish/lib/esm/Toast/Item.tsx +0 -165
- package/publish/lib/esm/Toast/Toast.tsx +0 -391
- package/publish/lib/esm/Toast/ToastContext.tsx +0 -104
- package/publish/lib/esm/Toast/__toast.vanilla.js +0 -422
- package/publish/lib/esm/Toast/index.scss +0 -197
- package/publish/lib/esm/Toast/index.tsx +0 -3
- package/publish/lib/esm/Toast/types.ts +0 -60
- package/publish/lib/esm/Toast/useToast.tsx +0 -72
- package/publish/lib/esm/Tooltip/index.tsx +0 -416
- package/publish/lib/esm/Tree/TreeList.tsx +0 -600
- package/publish/lib/esm/Tree/index.scss +0 -384
- package/publish/lib/esm/Tree/index.tsx +0 -661
- package/publish/lib/esm/Tree/init-height.tsx +0 -40
- package/publish/lib/esm/Tree/utils/func.ts +0 -15
- package/publish/lib/esm/Utils/hooks/useAutosizeTextArea.tsx +0 -131
- package/publish/lib/esm/Utils/hooks/useBoundedDrag.tsx +0 -301
- package/publish/lib/esm/Utils/hooks/useClickOutside.tsx +0 -69
- package/publish/lib/esm/Utils/hooks/useComId.tsx +0 -13
- package/publish/lib/esm/Utils/hooks/useDebounce.tsx +0 -40
- package/publish/lib/esm/Utils/hooks/useDragDropPosition.tsx +0 -417
- package/publish/lib/esm/Utils/hooks/useDraggable.tsx +0 -265
- package/publish/lib/esm/Utils/hooks/useHistoryTracker.tsx +0 -554
- package/publish/lib/esm/Utils/hooks/useInterval.tsx +0 -74
- package/publish/lib/esm/Utils/hooks/useIsMobile.tsx +0 -139
- package/publish/lib/esm/Utils/hooks/useKeyPress.tsx +0 -104
- package/publish/lib/esm/Utils/hooks/useSessionStorageListener.tsx +0 -45
- package/publish/lib/esm/Utils/hooks/useStreamController.tsx +0 -277
- package/publish/lib/esm/Utils/hooks/useThrottle.tsx +0 -39
- package/publish/lib/esm/Utils/hooks/useWindowScroll.tsx +0 -83
- package/publish/lib/esm/Utils/libs/anim.ts +0 -96
- package/publish/lib/esm/Utils/libs/buffer.ts +0 -262
- package/publish/lib/esm/Utils/libs/cls.ts +0 -64
- package/publish/lib/esm/Utils/libs/convert.ts +0 -59
- package/publish/lib/esm/Utils/libs/date.ts +0 -598
- package/publish/lib/esm/Utils/libs/dom.ts +0 -150
- package/publish/lib/esm/Utils/libs/easing.ts +0 -201
- package/publish/lib/esm/Utils/libs/extract.ts +0 -160
- package/publish/lib/esm/Utils/libs/format-string.ts +0 -116
- package/publish/lib/esm/Utils/libs/formdata.ts +0 -93
- package/publish/lib/esm/Utils/libs/getElementProperty.ts +0 -150
- package/publish/lib/esm/Utils/libs/guid.ts +0 -16
- package/publish/lib/esm/Utils/libs/initDefaultOptions.ts +0 -43
- package/publish/lib/esm/Utils/libs/inputsCalculation.ts +0 -160
- package/publish/lib/esm/Utils/libs/math.ts +0 -276
- package/publish/lib/esm/Utils/libs/object.ts +0 -68
- package/publish/lib/esm/Utils/libs/os.ts +0 -63
- package/publish/lib/esm/Utils/libs/performance.ts +0 -47
- package/publish/lib/esm/Utils/libs/sanitize.ts +0 -55
- package/publish/lib/esm/Utils/libs/time.ts +0 -139
- package/publish/lib/esm/Utils/libs/tree.ts +0 -119
- package/publish/lib/esm/Utils/libs/validate.ts +0 -434
- package/publish/lib/esm/Utils/libs/viewport.ts +0 -20
- package/publish/lib/esm/Utils/plugins/bodyScrollLock.ts +0 -286
- package/publish/lib/esm/index.js +0 -47
- package/publish/package.json +0 -1
- /package/{publish/Accordion → Accordion}/index.d.ts +0 -0
- /package/{publish/Accordion → Accordion}/index.js +0 -0
- /package/{publish/BackToTop → BackToTop}/index.css +0 -0
- /package/{publish/BackToTop → BackToTop}/index.d.ts +0 -0
- /package/{publish/BackToTop → BackToTop}/index.js +0 -0
- /package/{publish/CascadingSelect → CascadingSelect}/index.css +0 -0
- /package/{publish/CascadingSelect → CascadingSelect}/index.d.ts +0 -0
- /package/{publish/CascadingSelectE2E → CascadingSelectE2E}/index.css +0 -0
- /package/{publish/CascadingSelectE2E → CascadingSelectE2E}/index.d.ts +0 -0
- /package/{publish/Chatbox → Chatbox}/index.css +0 -0
- /package/{publish/Chatbox → Chatbox}/index.d.ts +0 -0
- /package/{publish/Checkbox → Checkbox}/index.d.ts +0 -0
- /package/{publish/ColorPicker → ColorPicker}/index.css +0 -0
- /package/{publish/ColorPicker → ColorPicker}/index.d.ts +0 -0
- /package/{publish/Date → Date}/index.css +0 -0
- /package/{publish/Date → Date}/index.d.ts +0 -0
- /package/{publish/DigitalClock → DigitalClock}/index.d.ts +0 -0
- /package/{publish/DigitalClock → DigitalClock}/index.js +0 -0
- /package/{publish/DragDropList → DragDropList}/index.css +0 -0
- /package/{publish/DragDropList → DragDropList}/index.d.ts +0 -0
- /package/{publish/DragDropList → DragDropList}/index.js +0 -0
- /package/{publish/DropdownMenu → DropdownMenu}/index.css +0 -0
- /package/{publish/DropdownMenu → DropdownMenu}/index.d.ts +0 -0
- /package/{publish/DropdownMenu → DropdownMenu}/index.js +0 -0
- /package/{publish/DynamicFields → DynamicFields}/index.d.ts +0 -0
- /package/{publish/DynamicFields → DynamicFields}/index.js +0 -0
- /package/{publish/EventCalendar → EventCalendar}/index.css +0 -0
- /package/{publish/EventCalendar → EventCalendar}/index.d.ts +0 -0
- /package/{publish/EventCalendar → EventCalendar}/index.js +0 -0
- /package/{publish/EventCalendarTimeline → EventCalendarTimeline}/index.css +0 -0
- /package/{publish/HorizontalScrollContent → HorizontalScrollContent}/index.css +0 -0
- /package/{publish/HorizontalScrollContent → HorizontalScrollContent}/index.d.ts +0 -0
- /package/{publish/HorizontalScrollContent → HorizontalScrollContent}/index.js +0 -0
- /package/{publish/Input → Input}/index.d.ts +0 -0
- /package/{publish/LiveSearch → LiveSearch}/index.css +0 -0
- /package/{publish/LiveSearch → LiveSearch}/index.d.ts +0 -0
- /package/{publish/MasonryLayout → MasonryLayout}/index.d.ts +0 -0
- /package/{publish/MasonryLayout → MasonryLayout}/index.js +0 -0
- /package/{publish/ModalDialog → ModalDialog}/index.d.ts +0 -0
- /package/{publish/ModalDialog → ModalDialog}/index.js +0 -0
- /package/{publish/ModeSwitch → ModeSwitch}/index.d.ts +0 -0
- /package/{publish/ModeSwitch → ModeSwitch}/index.js +0 -0
- /package/{publish/MultilevelDropdownMenu → MultilevelDropdownMenu}/index.css +0 -0
- /package/{publish/MultilevelDropdownMenu → MultilevelDropdownMenu}/index.d.ts +0 -0
- /package/{publish/MultilevelDropdownMenu → MultilevelDropdownMenu}/index.js +0 -0
- /package/{publish/MultipleCheckboxes → MultipleCheckboxes}/index.d.ts +0 -0
- /package/{publish/MultipleCheckboxes → MultipleCheckboxes}/index.js +0 -0
- /package/{publish/MultipleSelect → MultipleSelect}/index.css +0 -0
- /package/{publish/MultipleSelect → MultipleSelect}/index.d.ts +0 -0
- /package/{publish/MultipleSelect → MultipleSelect}/index.js +0 -0
- /package/{publish/NativeSelect → NativeSelect}/index.d.ts +0 -0
- /package/{publish/NumberInput → NumberInput}/index.d.ts +0 -0
- /package/{publish/Pagination → Pagination}/index.d.ts +0 -0
- /package/{publish/Pagination → Pagination}/index.js +0 -0
- /package/{publish/Radio → Radio}/index.d.ts +0 -0
- /package/{publish/RangeSlider → RangeSlider}/index.css +0 -0
- /package/{publish/RangeSlider → RangeSlider}/index.d.ts +0 -0
- /package/{publish/Refresher → Refresher}/index.d.ts +0 -0
- /package/{publish/Refresher → Refresher}/index.js +0 -0
- /package/{publish/RootPortal → RootPortal}/index.d.ts +0 -0
- /package/{publish/RootPortal → RootPortal}/index.js +0 -0
- /package/{publish/ScrollReveal → ScrollReveal}/index.d.ts +0 -0
- /package/{publish/ScrollReveal → ScrollReveal}/index.js +0 -0
- /package/{publish/Scrollbar → Scrollbar}/index.css +0 -0
- /package/{publish/Scrollbar → Scrollbar}/index.d.ts +0 -0
- /package/{publish/Scrollbar → Scrollbar}/index.js +0 -0
- /package/{publish/SearchBar → SearchBar}/index.d.ts +0 -0
- /package/{publish/Select → Select}/index.css +0 -0
- /package/{publish/Select → Select}/index.d.ts +0 -0
- /package/{publish/ShowMoreLess → ShowMoreLess}/index.css +0 -0
- /package/{publish/ShowMoreLess → ShowMoreLess}/index.d.ts +0 -0
- /package/{publish/ShowMoreLess → ShowMoreLess}/index.js +0 -0
- /package/{publish/SplitterPanel → SplitterPanel}/index.css +0 -0
- /package/{publish/SplitterPanel → SplitterPanel}/index.d.ts +0 -0
- /package/{publish/SplitterPanel → SplitterPanel}/index.js +0 -0
- /package/{publish/Stepper → Stepper}/index.css +0 -0
- /package/{publish/Stepper → Stepper}/index.d.ts +0 -0
- /package/{publish/Stepper → Stepper}/index.js +0 -0
- /package/{publish/Switch → Switch}/index.d.ts +0 -0
- /package/{publish/Table → Table}/index.css +0 -0
- /package/{publish/Table → Table}/index.d.ts +0 -0
- /package/{publish/Table → Table}/index.js +0 -0
- /package/{publish/Tabs → Tabs}/index.d.ts +0 -0
- /package/{publish/Tabs → Tabs}/index.js +0 -0
- /package/{publish/TagInput → TagInput}/index.d.ts +0 -0
- /package/{publish/Textarea → Textarea}/index.d.ts +0 -0
- /package/{publish/Toast → Toast}/index.css +0 -0
- /package/{publish/Toast → Toast}/index.d.ts +0 -0
- /package/{publish/Toast → Toast}/index.js +0 -0
- /package/{publish/Tooltip → Tooltip}/index.css +0 -0
- /package/{publish/Tooltip → Tooltip}/index.d.ts +0 -0
- /package/{publish/Tooltip → Tooltip}/index.js +0 -0
- /package/{publish/Tree → Tree}/index.css +0 -0
- /package/{publish/Tree → Tree}/index.d.ts +0 -0
- /package/{publish/Tree → Tree}/index.js +0 -0
- /package/{publish/Utils → Utils}/anim.d.ts +0 -0
- /package/{publish/Utils → Utils}/anim.js +0 -0
- /package/{publish/Utils → Utils}/bodyScrollLock.d.ts +0 -0
- /package/{publish/Utils → Utils}/bodyScrollLock.js +0 -0
- /package/{publish/Utils → Utils}/buffer.d.ts +0 -0
- /package/{publish/Utils → Utils}/buffer.js +0 -0
- /package/{publish/Utils → Utils}/cls.d.ts +0 -0
- /package/{publish/Utils → Utils}/cls.js +0 -0
- /package/{publish/Utils → Utils}/convert.d.ts +0 -0
- /package/{publish/Utils → Utils}/convert.js +0 -0
- /package/{publish/Utils → Utils}/date.d.ts +0 -0
- /package/{publish/Utils → Utils}/date.js +0 -0
- /package/{publish/Utils → Utils}/dom.d.ts +0 -0
- /package/{publish/Utils → Utils}/dom.js +0 -0
- /package/{publish/Utils → Utils}/easing.d.ts +0 -0
- /package/{publish/Utils → Utils}/easing.js +0 -0
- /package/{publish/Utils → Utils}/extract.d.ts +0 -0
- /package/{publish/Utils → Utils}/extract.js +0 -0
- /package/{publish/Utils → Utils}/format-string.d.ts +0 -0
- /package/{publish/Utils → Utils}/format-string.js +0 -0
- /package/{publish/Utils → Utils}/formdata.d.ts +0 -0
- /package/{publish/Utils → Utils}/formdata.js +0 -0
- /package/{publish/Utils → Utils}/getElementProperty.d.ts +0 -0
- /package/{publish/Utils → Utils}/getElementProperty.js +0 -0
- /package/{publish/Utils → Utils}/guid.d.ts +0 -0
- /package/{publish/Utils → Utils}/guid.js +0 -0
- /package/{publish/Utils → Utils}/initDefaultOptions.d.ts +0 -0
- /package/{publish/Utils → Utils}/initDefaultOptions.js +0 -0
- /package/{publish/Utils → Utils}/inputsCalculation.d.ts +0 -0
- /package/{publish/Utils → Utils}/inputsCalculation.js +0 -0
- /package/{publish/Utils → Utils}/math.d.ts +0 -0
- /package/{publish/Utils → Utils}/math.js +0 -0
- /package/{publish/Utils → Utils}/object.d.ts +0 -0
- /package/{publish/Utils → Utils}/object.js +0 -0
- /package/{publish/Utils → Utils}/os.d.ts +0 -0
- /package/{publish/Utils → Utils}/os.js +0 -0
- /package/{publish/Utils → Utils}/performance.d.ts +0 -0
- /package/{publish/Utils → Utils}/performance.js +0 -0
- /package/{publish/Utils → Utils}/sanitize.d.ts +0 -0
- /package/{publish/Utils → Utils}/sanitize.js +0 -0
- /package/{publish/Utils → Utils}/time.d.ts +0 -0
- /package/{publish/Utils → Utils}/time.js +0 -0
- /package/{publish/Utils → Utils}/tree.d.ts +0 -0
- /package/{publish/Utils → Utils}/tree.js +0 -0
- /package/{publish/Utils → Utils}/useAutosizeTextArea.d.ts +0 -0
- /package/{publish/Utils → Utils}/useAutosizeTextArea.js +0 -0
- /package/{publish/Utils → Utils}/useBoundedDrag.d.ts +0 -0
- /package/{publish/Utils → Utils}/useBoundedDrag.js +0 -0
- /package/{publish/Utils → Utils}/useClickOutside.d.ts +0 -0
- /package/{publish/Utils → Utils}/useClickOutside.js +0 -0
- /package/{publish/Utils → Utils}/useComId.d.ts +0 -0
- /package/{publish/Utils → Utils}/useComId.js +0 -0
- /package/{publish/Utils → Utils}/useDebounce.d.ts +0 -0
- /package/{publish/Utils → Utils}/useDebounce.js +0 -0
- /package/{publish/Utils → Utils}/useDragDropPosition.d.ts +0 -0
- /package/{publish/Utils → Utils}/useDragDropPosition.js +0 -0
- /package/{publish/Utils → Utils}/useDraggable.d.ts +0 -0
- /package/{publish/Utils → Utils}/useDraggable.js +0 -0
- /package/{publish/Utils → Utils}/useHistoryTracker.d.ts +0 -0
- /package/{publish/Utils → Utils}/useHistoryTracker.js +0 -0
- /package/{publish/Utils → Utils}/useInterval.d.ts +0 -0
- /package/{publish/Utils → Utils}/useInterval.js +0 -0
- /package/{publish/Utils → Utils}/useIsMobile.d.ts +0 -0
- /package/{publish/Utils → Utils}/useIsMobile.js +0 -0
- /package/{publish/Utils → Utils}/useKeyPress.d.ts +0 -0
- /package/{publish/Utils → Utils}/useKeyPress.js +0 -0
- /package/{publish/Utils → Utils}/useSessionStorageListener.d.ts +0 -0
- /package/{publish/Utils → Utils}/useSessionStorageListener.js +0 -0
- /package/{publish/Utils → Utils}/useStreamController.d.ts +0 -0
- /package/{publish/Utils → Utils}/useStreamController.js +0 -0
- /package/{publish/Utils → Utils}/useThrottle.d.ts +0 -0
- /package/{publish/Utils → Utils}/useThrottle.js +0 -0
- /package/{publish/Utils → Utils}/useWindowScroll.d.ts +0 -0
- /package/{publish/Utils → Utils}/useWindowScroll.js +0 -0
- /package/{publish/Utils → Utils}/validate.d.ts +0 -0
- /package/{publish/Utils → Utils}/validate.js +0 -0
- /package/{publish/Utils → Utils}/viewport.d.ts +0 -0
- /package/{publish/Utils → Utils}/viewport.js +0 -0
|
@@ -1,1742 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useState, useRef, useImperativeHandle } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import Textarea from 'funda-textarea';
|
|
6
|
-
import RootPortal from 'funda-root-portal';
|
|
7
|
-
|
|
8
|
-
import useComId from 'funda-utils/dist/cjs/useComId';
|
|
9
|
-
import useDebounce from 'funda-utils/dist/cjs/useDebounce';
|
|
10
|
-
import useThrottle from 'funda-utils/dist/cjs/useThrottle';
|
|
11
|
-
import useClickOutside from 'funda-utils/dist/cjs/useClickOutside';
|
|
12
|
-
import useStreamController from 'funda-utils/dist/cjs/useStreamController';
|
|
13
|
-
import { htmlEncode } from 'funda-utils/dist/cjs/sanitize';
|
|
14
|
-
import { isJSON } from 'funda-utils/dist/cjs/validate';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// loader
|
|
19
|
-
import PureLoader from './PureLoader';
|
|
20
|
-
import TypingEffect from "./TypingEffect";
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
formatLatestDisplayContent,
|
|
24
|
-
formatName,
|
|
25
|
-
fixHtmlTags,
|
|
26
|
-
isStreamResponse,
|
|
27
|
-
toBoolean
|
|
28
|
-
} from './utils/func';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export interface CustomMethod {
|
|
32
|
-
name: string;
|
|
33
|
-
func: (...args: any[]) => any;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type MessageDetail = {
|
|
37
|
-
sender: string; // Sender's name
|
|
38
|
-
timestamp: string; // Time when the message was sent
|
|
39
|
-
content: string; // The message content
|
|
40
|
-
tag: string; // such as '[reply]'
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export type QuestionData = {
|
|
45
|
-
title: string;
|
|
46
|
-
list: Array<string>;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type SelectedOption = {
|
|
50
|
-
[key: string]: string | number;
|
|
51
|
-
curIndex: number;
|
|
52
|
-
curValue: string;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export interface FloatingButton {
|
|
56
|
-
label: string; // HTML string
|
|
57
|
-
value: string;
|
|
58
|
-
onClick: string;
|
|
59
|
-
active?: boolean; // Specify if the button should be active by default
|
|
60
|
-
isSelect?: boolean; // Mark whether it is a drop-down selection button
|
|
61
|
-
dynamicOptions?: boolean; // Mark whether to use dynamic options
|
|
62
|
-
defaultSelected?: number; // Specify default selected option index
|
|
63
|
-
[key: string]: any; // Allows dynamic `onSelect__<number>` attributes, such as `onSelect__1`, `onSelect__2`, ...
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export interface FloatingButtonSelectOption {
|
|
68
|
-
label: string;
|
|
69
|
-
value: string;
|
|
70
|
-
onClick: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface RequestConfig {
|
|
74
|
-
apiUrl: string;
|
|
75
|
-
requestBody: string; // JSON string for request body template
|
|
76
|
-
responseExtractor: string; // JSON path to extract response
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type CustomRequestConfig = {
|
|
80
|
-
requestBody: any;
|
|
81
|
-
apiUrl: string;
|
|
82
|
-
headers: any;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export type CustomRequestResponse = {
|
|
86
|
-
content: string | Response | null;
|
|
87
|
-
isStream: boolean;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export type CustomRequestFunction = (
|
|
91
|
-
message: string,
|
|
92
|
-
config: CustomRequestConfig,
|
|
93
|
-
customMethods: CustomMethod[],
|
|
94
|
-
conversationHistory: MessageDetail[],
|
|
95
|
-
) => Promise<CustomRequestResponse>;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export type ChatboxProps = {
|
|
99
|
-
debug?: boolean;
|
|
100
|
-
defaultRows?: number;
|
|
101
|
-
prefix?: string;
|
|
102
|
-
contentRef?: React.RefObject<any>;
|
|
103
|
-
model?: string;
|
|
104
|
-
baseUrl?: string;
|
|
105
|
-
apiKey?: string;
|
|
106
|
-
token?: string | (() => string);
|
|
107
|
-
defaultMessages?: MessageDetail[];
|
|
108
|
-
verbose?: boolean;
|
|
109
|
-
reasoningSwitchLabel?: string;
|
|
110
|
-
stopLabel?: React.ReactNode;
|
|
111
|
-
questionName?: React.ReactNode;
|
|
112
|
-
answerName?: React.ReactNode;
|
|
113
|
-
questionNameIcon?: string;
|
|
114
|
-
answerNameIcon?: string;
|
|
115
|
-
bubble?: boolean;
|
|
116
|
-
bubbleLabel?: string;
|
|
117
|
-
sendLabel?: string;
|
|
118
|
-
sendLoading?: boolean;
|
|
119
|
-
sendLoadingLabel?: string;
|
|
120
|
-
copyLabel?: string;
|
|
121
|
-
closeLabel?: string;
|
|
122
|
-
placeholder?: string;
|
|
123
|
-
noDataPlaceholder?: string;
|
|
124
|
-
requestConfig: RequestConfig;
|
|
125
|
-
headerConfig?: any;
|
|
126
|
-
maxHistoryLength?: number;
|
|
127
|
-
contextData?: Record<string, any>; // Dynamic JSON data
|
|
128
|
-
toolkitButtons?: FloatingButton[];
|
|
129
|
-
newChatButton?: FloatingButton;
|
|
130
|
-
customMethods?: CustomMethod[]; // [{"name": "method1", "func": "() => { console.log('test'); }"}, ...]
|
|
131
|
-
defaultQuestions?: QuestionData;
|
|
132
|
-
showCopyBtn?: boolean; // Whether to show copy button for each reply
|
|
133
|
-
autoCopyReply?: boolean; // Whether to automatically copy reply to clipboard
|
|
134
|
-
usePopUp?: boolean;
|
|
135
|
-
customRequest?: CustomRequestFunction;
|
|
136
|
-
renderParser?: (input: string) => Promise<string>;
|
|
137
|
-
requestBodyFormatter?: (body: any, contextData: Record<string, any>, conversationHistory: MessageDetail[]) => Promise<Record<string, any>>;
|
|
138
|
-
copiedContentFormatter?: (string: string) => string;
|
|
139
|
-
nameFormatter?: (input: string) => string;
|
|
140
|
-
onCopyCallback?: (res: Record<string, any>) => void;
|
|
141
|
-
onQuestionClick?: (text: string, methods: Record<string, Function>) => void;
|
|
142
|
-
onInputChange?: (controlRef: React.RefObject<any>, val: string) => any;
|
|
143
|
-
onInputCallback?: (input: string) => Promise<string>;
|
|
144
|
-
onChunk?: (controlRef: React.RefObject<any>, lastContent: string, conversationHistory: MessageDetail[]) => any;
|
|
145
|
-
onComplete?: (controlRef: React.RefObject<any>, lastContent: string, conversationHistory: MessageDetail[]) => any;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const Chatbox = (props: ChatboxProps) => {
|
|
150
|
-
|
|
151
|
-
const chatId = useComId().replace(/\-/g, '_');
|
|
152
|
-
|
|
153
|
-
// Store latest props in refs
|
|
154
|
-
const propsRef = useRef<any>(props);
|
|
155
|
-
|
|
156
|
-
// Store context data in ref to get latest values
|
|
157
|
-
const contextDataRef = useRef<Record<string, any> | undefined>(props.contextData);
|
|
158
|
-
|
|
159
|
-
// Store config in ref to get latest values
|
|
160
|
-
const configRef = useRef<RequestConfig>({
|
|
161
|
-
apiUrl: "{baseUrl}/v1/chat/completions",
|
|
162
|
-
requestBody: `{
|
|
163
|
-
"model": "{model}",
|
|
164
|
-
"messages": [{
|
|
165
|
-
"role": "user",
|
|
166
|
-
"content": "{message}"
|
|
167
|
-
}],
|
|
168
|
-
"stream": true
|
|
169
|
-
}`,
|
|
170
|
-
responseExtractor: "data.choices.0.delta.content"
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const tokenFormat = (inputTokenValue: any) => {
|
|
175
|
-
if (typeof inputTokenValue === 'undefined') return '';
|
|
176
|
-
|
|
177
|
-
// Resolve token value (string or function)
|
|
178
|
-
if (typeof inputTokenValue === 'function') {
|
|
179
|
-
return inputTokenValue();
|
|
180
|
-
} else {
|
|
181
|
-
return inputTokenValue || '';
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
//
|
|
188
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
189
|
-
const msgContainerRef = useRef<HTMLDivElement>(null);
|
|
190
|
-
const msInput = useRef<HTMLTextAreaElement>(null);
|
|
191
|
-
const inputContentRef = useRef<any>(null);
|
|
192
|
-
const [focused, setFocused] = useState(false);
|
|
193
|
-
|
|
194
|
-
const [loaderDisplay, setLoaderDisplay] = useState<boolean>(false);
|
|
195
|
-
const [loading, setLoading] = useState<boolean>(false);
|
|
196
|
-
const [thinking, setThinking] = useState<boolean>(false);
|
|
197
|
-
const [show, setShow] = useState<boolean>(false);
|
|
198
|
-
const [msgList, setMsgList] = useState<MessageDetail[]>([]);
|
|
199
|
-
const [elapsedTime, setElapsedTime] = useState<number>(0);
|
|
200
|
-
const [tempAnimText, setTempAnimText] = useState<string>('');
|
|
201
|
-
const [enableStreamMode, setEnableStreamMode] = useState<boolean>(true);
|
|
202
|
-
const animatedMessagesRef = useRef<Set<number>>(new Set()); // Add a ref to keep track of messages that have already been animated
|
|
203
|
-
|
|
204
|
-
// Keep track of whether the default values have been initialized
|
|
205
|
-
const [initializedDefaults, setInitializedDefaults] = useState<Record<string, boolean>>({});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
//
|
|
210
|
-
const timer = useRef<any>(null);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
//================================================================
|
|
214
|
-
// helper
|
|
215
|
-
//================================================================
|
|
216
|
-
const customMethodsRef = useRef<Record<string, Function>>({});
|
|
217
|
-
useEffect(() => {
|
|
218
|
-
if (props.customMethods && Array.isArray(props.customMethods)) {
|
|
219
|
-
const methodsMap: Record<string, Function> = {};
|
|
220
|
-
|
|
221
|
-
props.customMethods.forEach(method => {
|
|
222
|
-
if (typeof method.func === 'function') {
|
|
223
|
-
methodsMap[method.name] = method.func;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
customMethodsRef.current = methodsMap;
|
|
228
|
-
}
|
|
229
|
-
}, [props.customMethods]);
|
|
230
|
-
|
|
231
|
-
const exposedMethods = () => {
|
|
232
|
-
return {
|
|
233
|
-
chatOpen: () => {
|
|
234
|
-
setShow(true);
|
|
235
|
-
setTimeout(() => {
|
|
236
|
-
if (msInput.current) msInput.current.focus();
|
|
237
|
-
}, 0);
|
|
238
|
-
},
|
|
239
|
-
chatClose: () => {
|
|
240
|
-
setShow(false);
|
|
241
|
-
},
|
|
242
|
-
clearData: () => {
|
|
243
|
-
// Update both the conversation history and displayed messages
|
|
244
|
-
conversationHistory.current = [];
|
|
245
|
-
setMsgList([]);
|
|
246
|
-
|
|
247
|
-
},
|
|
248
|
-
sendMsg: () => {
|
|
249
|
-
handleClickSafe();
|
|
250
|
-
},
|
|
251
|
-
getHistory: () => conversationHistory.current,
|
|
252
|
-
trimHistory: (length?: number) => {
|
|
253
|
-
const maxLength = length || args().maxHistoryLength || 20;
|
|
254
|
-
if (conversationHistory.current.length > maxLength) {
|
|
255
|
-
conversationHistory.current = conversationHistory.current.slice(-maxLength);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
setHistory: (messages: MessageDetail[]) => {
|
|
259
|
-
// Update both the conversation history and displayed messages
|
|
260
|
-
conversationHistory.current = [...messages];
|
|
261
|
-
setMsgList([...messages]);
|
|
262
|
-
},
|
|
263
|
-
setVal: (v: string) => {
|
|
264
|
-
if (inputContentRef.current) inputContentRef.current.set(v);
|
|
265
|
-
},
|
|
266
|
-
getContextData: () => {
|
|
267
|
-
return contextDataRef.current;
|
|
268
|
-
},
|
|
269
|
-
setContextData: (v: Record<string, any>) => {
|
|
270
|
-
contextDataRef.current = v;
|
|
271
|
-
},
|
|
272
|
-
getMessages: () => {
|
|
273
|
-
return msgList;
|
|
274
|
-
},
|
|
275
|
-
setMessages: (v: MessageDetail[]) => {
|
|
276
|
-
setMsgList(v);
|
|
277
|
-
},
|
|
278
|
-
//
|
|
279
|
-
getCustomMethods: () => {
|
|
280
|
-
return Object.keys(customMethodsRef.current);
|
|
281
|
-
},
|
|
282
|
-
executeCustomMethod: (methodName: string, ...args: any[]) => {
|
|
283
|
-
if (methodName in customMethodsRef.current) {
|
|
284
|
-
try {
|
|
285
|
-
return customMethodsRef.current[methodName](...args);
|
|
286
|
-
} catch (error) {
|
|
287
|
-
console.error(`Error executing custom method ${methodName}:`, error);
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
console.warn(`Custom method ${methodName} not found`);
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const scrollToBottom = useThrottle(() => {
|
|
300
|
-
if (msgContainerRef.current) {
|
|
301
|
-
msgContainerRef.current.scrollTop = msgContainerRef.current.scrollHeight;
|
|
302
|
-
}
|
|
303
|
-
}, 300, []);
|
|
304
|
-
|
|
305
|
-
const args = () => {
|
|
306
|
-
const currentProps = propsRef.current;
|
|
307
|
-
if (typeof currentProps.headerConfig === 'undefined' || typeof configRef.current.apiUrl === 'undefined') {
|
|
308
|
-
return {};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const {
|
|
312
|
-
debug,
|
|
313
|
-
defaultRows,
|
|
314
|
-
prefix,
|
|
315
|
-
contentRef,
|
|
316
|
-
model,
|
|
317
|
-
baseUrl,
|
|
318
|
-
apiKey,
|
|
319
|
-
token,
|
|
320
|
-
verbose,
|
|
321
|
-
reasoningSwitchLabel,
|
|
322
|
-
stopLabel,
|
|
323
|
-
questionName,
|
|
324
|
-
answerName,
|
|
325
|
-
bubble,
|
|
326
|
-
bubbleLabel,
|
|
327
|
-
sendLabel,
|
|
328
|
-
sendLoading,
|
|
329
|
-
sendLoadingLabel,
|
|
330
|
-
copyLabel,
|
|
331
|
-
closeLabel,
|
|
332
|
-
placeholder,
|
|
333
|
-
noDataPlaceholder,
|
|
334
|
-
requestConfig,
|
|
335
|
-
headerConfig,
|
|
336
|
-
toolkitButtons,
|
|
337
|
-
newChatButton,
|
|
338
|
-
maxHistoryLength,
|
|
339
|
-
usePopUp,
|
|
340
|
-
customRequest,
|
|
341
|
-
onQuestionClick,
|
|
342
|
-
onCopyCallback,
|
|
343
|
-
renderParser,
|
|
344
|
-
requestBodyFormatter,
|
|
345
|
-
copiedContentFormatter,
|
|
346
|
-
nameFormatter,
|
|
347
|
-
showCopyBtn,
|
|
348
|
-
autoCopyReply,
|
|
349
|
-
onInputChange,
|
|
350
|
-
onInputCallback,
|
|
351
|
-
onChunk,
|
|
352
|
-
onComplete,
|
|
353
|
-
} = currentProps;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const {
|
|
357
|
-
apiUrl,
|
|
358
|
-
requestBody,
|
|
359
|
-
responseExtractor
|
|
360
|
-
} = configRef.current;
|
|
361
|
-
|
|
362
|
-
const latestContextData = contextDataRef.current ? contextDataRef.current : undefined;
|
|
363
|
-
|
|
364
|
-
let _requestBodyTmpl = requestBody.replace(/\'/g, '"'); // !!! REQUIRED !!!
|
|
365
|
-
let _isStream: boolean = true;
|
|
366
|
-
|
|
367
|
-
// request API
|
|
368
|
-
const requestApiUrl = apiUrl.replace(/\{baseUrl\}/g, baseUrl);
|
|
369
|
-
|
|
370
|
-
// header config
|
|
371
|
-
const _headerConfig = headerConfig.replace(/\{apiKey\}/g, apiKey)
|
|
372
|
-
.replace(/\{token\}/g, tokenFormat(token))
|
|
373
|
-
.replace(/\'/g, '"'); // !!! REQUIRED !!!
|
|
374
|
-
const headerConfigRes = typeof _headerConfig !== 'undefined' ? (isJSON(_headerConfig) ? JSON.parse(_headerConfig) : undefined) : {'Content-Type':'application/json'};
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
// Determine whether it is in JSON format
|
|
378
|
-
if (!isJSON(_requestBodyTmpl)) {
|
|
379
|
-
console.log('--> [ERROR] Wrong JSON format');
|
|
380
|
-
_requestBodyTmpl = '{}';
|
|
381
|
-
return {};
|
|
382
|
-
} else {
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
if (JSON.parse(_requestBodyTmpl).hasOwnProperty('stream')) {
|
|
386
|
-
_isStream = toBoolean(JSON.parse(_requestBodyTmpl).stream) === true;
|
|
387
|
-
}
|
|
388
|
-
} catch (err) {
|
|
389
|
-
console.error(err);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// Whether or not to show reasoning
|
|
395
|
-
const withReasoning = typeof verbose === 'undefined' ? true : verbose;
|
|
396
|
-
|
|
397
|
-
// Get latest name values
|
|
398
|
-
const _answerName: string = formatName(answerName, true, currentProps);
|
|
399
|
-
const _questionName: string = formatName(questionName, false, currentProps);
|
|
400
|
-
|
|
401
|
-
// Responder deconstruction
|
|
402
|
-
const responseExtractPath = responseExtractor.split('.');
|
|
403
|
-
|
|
404
|
-
return {
|
|
405
|
-
debug,
|
|
406
|
-
defaultRows,
|
|
407
|
-
prefix,
|
|
408
|
-
contentRef,
|
|
409
|
-
model,
|
|
410
|
-
baseUrl,
|
|
411
|
-
apiKey,
|
|
412
|
-
token,
|
|
413
|
-
verbose,
|
|
414
|
-
reasoningSwitchLabel,
|
|
415
|
-
stopLabel,
|
|
416
|
-
bubble,
|
|
417
|
-
bubbleLabel,
|
|
418
|
-
sendLabel,
|
|
419
|
-
sendLoading,
|
|
420
|
-
sendLoadingLabel,
|
|
421
|
-
copyLabel,
|
|
422
|
-
closeLabel,
|
|
423
|
-
placeholder,
|
|
424
|
-
noDataPlaceholder,
|
|
425
|
-
requestConfig,
|
|
426
|
-
maxHistoryLength,
|
|
427
|
-
toolkitButtons,
|
|
428
|
-
newChatButton,
|
|
429
|
-
usePopUp,
|
|
430
|
-
customRequest,
|
|
431
|
-
onQuestionClick,
|
|
432
|
-
onCopyCallback,
|
|
433
|
-
renderParser,
|
|
434
|
-
requestBodyFormatter,
|
|
435
|
-
copiedContentFormatter,
|
|
436
|
-
nameFormatter,
|
|
437
|
-
showCopyBtn,
|
|
438
|
-
autoCopyReply,
|
|
439
|
-
onInputChange,
|
|
440
|
-
onInputCallback,
|
|
441
|
-
onChunk,
|
|
442
|
-
onComplete,
|
|
443
|
-
|
|
444
|
-
//
|
|
445
|
-
defaultQuestionsRes: questions,
|
|
446
|
-
latestContextData,
|
|
447
|
-
questionNameRes: _questionName,
|
|
448
|
-
answerNameRes: _answerName,
|
|
449
|
-
isStream: _isStream,
|
|
450
|
-
headerConfigRes,
|
|
451
|
-
requestApiUrl,
|
|
452
|
-
requestBodyTmpl: _requestBodyTmpl,
|
|
453
|
-
responseExtractPath,
|
|
454
|
-
withReasoning,
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
//================================================================
|
|
460
|
-
// Clipboard
|
|
461
|
-
//================================================================
|
|
462
|
-
const chatboxCopyToClipboard = async (text: string) => {
|
|
463
|
-
|
|
464
|
-
let _content: string = text;
|
|
465
|
-
if (typeof args().copiedContentFormatter === 'function') {
|
|
466
|
-
_content = args().copiedContentFormatter(text);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
try {
|
|
470
|
-
// Try using the modern Clipboard API first
|
|
471
|
-
if (navigator.clipboard && window.isSecureContext) {
|
|
472
|
-
await navigator.clipboard.writeText(_content);
|
|
473
|
-
args().onCopyCallback?.({
|
|
474
|
-
success: true,
|
|
475
|
-
message: 'Text copied to clipboard',
|
|
476
|
-
});
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Fallback for older browsers
|
|
481
|
-
const textArea = document.createElement('textarea');
|
|
482
|
-
textArea.value = _content;
|
|
483
|
-
textArea.style.position = 'fixed';
|
|
484
|
-
textArea.style.left = '-999999px';
|
|
485
|
-
textArea.style.top = '-999999px';
|
|
486
|
-
document.body.appendChild(textArea);
|
|
487
|
-
textArea.focus();
|
|
488
|
-
textArea.select();
|
|
489
|
-
|
|
490
|
-
try {
|
|
491
|
-
document.execCommand('copy');
|
|
492
|
-
textArea.remove();
|
|
493
|
-
args().onCopyCallback?.({
|
|
494
|
-
success: true,
|
|
495
|
-
message: 'Text copied to clipboard',
|
|
496
|
-
});
|
|
497
|
-
return true;
|
|
498
|
-
} catch (err) {
|
|
499
|
-
textArea.remove();
|
|
500
|
-
return false;
|
|
501
|
-
}
|
|
502
|
-
} catch (err) {
|
|
503
|
-
args().onCopyCallback?.({
|
|
504
|
-
success: false,
|
|
505
|
-
message: `Failed to copy text: ${err}`,
|
|
506
|
-
});
|
|
507
|
-
return false;
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
//================================================================
|
|
513
|
-
// Custom Questions
|
|
514
|
-
//================================================================
|
|
515
|
-
const [questions, setQuestions] = useState<QuestionData | undefined>(props.defaultQuestions);
|
|
516
|
-
useEffect(() => {
|
|
517
|
-
if (props.defaultQuestions) {
|
|
518
|
-
setQuestions(props.defaultQuestions);
|
|
519
|
-
}
|
|
520
|
-
}, [props.defaultQuestions]);
|
|
521
|
-
const hasQuestion = () => {
|
|
522
|
-
return args().defaultQuestionsRes && (args().defaultQuestionsRes as QuestionData).list.length > 0;
|
|
523
|
-
};
|
|
524
|
-
const handleQuestionClick = (text: string) => {
|
|
525
|
-
if (inputContentRef.current) {
|
|
526
|
-
inputContentRef.current.set(text);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
args().onQuestionClick?.(text, exposedMethods());
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
//================================================================
|
|
534
|
-
// Custom buttons
|
|
535
|
-
//================================================================
|
|
536
|
-
const toolkitBtnsRef = useRef<any>(null);
|
|
537
|
-
const [activeButtons, setActiveButtons] = useState<Record<string, boolean>>({});
|
|
538
|
-
const closeDropdowns = () => {
|
|
539
|
-
setActiveButtons(prev => {
|
|
540
|
-
const newState = { ...prev };
|
|
541
|
-
// Turn off only buttons with "isSelect"
|
|
542
|
-
args().toolkitButtons?.forEach((btn: FloatingButton, index: number) => {
|
|
543
|
-
if (btn.isSelect) {
|
|
544
|
-
const _id = `${args().prefix || 'custom-'}chatbox-btn-tools-${chatId}${index}`;
|
|
545
|
-
newState[_id] = false;
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
return newState;
|
|
549
|
-
});
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
// The onClick action specifically used to perform the default options
|
|
553
|
-
const executeDefaultOptionAction = async (actionStr: string, buttonId: string) => {
|
|
554
|
-
try {
|
|
555
|
-
const actionFn = new Function('method', 'isActive', 'button', actionStr);
|
|
556
|
-
// To perform the action, pass false as the "isActive" parameter, as this is the default option
|
|
557
|
-
await actionFn(exposedMethods(), false, document.getElementById(buttonId));
|
|
558
|
-
} catch (error) {
|
|
559
|
-
console.error('Error executing default option action:', error);
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const executeButtonAction = async (actionStr: string, buttonId: string, buttonElement: HTMLButtonElement) => {
|
|
565
|
-
try {
|
|
566
|
-
const actionFn = new Function('method', 'isActive', 'button', actionStr);
|
|
567
|
-
|
|
568
|
-
// !!!REQUIRED "await"
|
|
569
|
-
// "customMethods" may be asynchronous
|
|
570
|
-
const result = await actionFn(exposedMethods(), !activeButtons[buttonId], buttonElement);
|
|
571
|
-
|
|
572
|
-
// If the returned result is an array, it is a dynamic option
|
|
573
|
-
if (Array.isArray(result) && Object.keys(dynamicOptions).length === 0) {
|
|
574
|
-
const options: FloatingButtonSelectOption[] = result.map(item => {
|
|
575
|
-
const [key, value] = Object.entries(item)[0];
|
|
576
|
-
const [label, val, onClick] = (value as string).split('{#}').map((s: string) => s.trim());
|
|
577
|
-
return { label, value: val, onClick };
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
// Update dynamic options
|
|
581
|
-
setDynamicOptions(prev => ({
|
|
582
|
-
...prev,
|
|
583
|
-
[buttonId]: options
|
|
584
|
-
}));
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// Update the button status
|
|
588
|
-
const newState = !activeButtons[buttonId];
|
|
589
|
-
setActiveButtons(prev => ({
|
|
590
|
-
...prev,
|
|
591
|
-
[buttonId]: newState
|
|
592
|
-
}));
|
|
593
|
-
|
|
594
|
-
return result;
|
|
595
|
-
} catch (error) {
|
|
596
|
-
console.error('Error executing button action:', error);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
// options
|
|
603
|
-
const [selectedOpt, setSelectedOpt] = useState<SelectedOption>({
|
|
604
|
-
curIndex: -1,
|
|
605
|
-
curValue: ''
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
// Store dynamic options
|
|
609
|
-
const [dynamicOptions, setDynamicOptions] = useState<Record<string, FloatingButtonSelectOption[]>>({});
|
|
610
|
-
|
|
611
|
-
const getButtonOptions = (btn: FloatingButton, buttonId: string): FloatingButtonSelectOption[] => {
|
|
612
|
-
// If you are using the dynamic option and already have a cache, return the option for caching
|
|
613
|
-
//---------
|
|
614
|
-
if (btn.dynamicOptions && dynamicOptions[buttonId]) {
|
|
615
|
-
return dynamicOptions[buttonId];
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// Use the static option from "props"
|
|
619
|
-
//---------
|
|
620
|
-
const options: FloatingButtonSelectOption[] = [];
|
|
621
|
-
let index = 1;
|
|
622
|
-
|
|
623
|
-
while (true) {
|
|
624
|
-
const optionKey = `onSelect__${index}`;
|
|
625
|
-
if (!(optionKey in btn)) break;
|
|
626
|
-
|
|
627
|
-
const [label, value, onClick] = btn[optionKey].split('{#}').map((s: string) => s.trim());
|
|
628
|
-
options.push({ label, value, onClick });
|
|
629
|
-
index++;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
return options;
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
const handleExecuteButtonSelect = (buttonId: string, option: FloatingButtonSelectOption, index: number, value: string, isDefaultSelection: boolean = false) => {
|
|
636
|
-
|
|
637
|
-
if (option.value === "cancel") {
|
|
638
|
-
setSelectedOpt(prev => {
|
|
639
|
-
const newLabels = { ...prev };
|
|
640
|
-
delete newLabels[buttonId]; // Deletes the saved selected label, which displays the default label
|
|
641
|
-
return {
|
|
642
|
-
...newLabels,
|
|
643
|
-
curIndex: index,
|
|
644
|
-
curValue: value
|
|
645
|
-
};
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
} else {
|
|
649
|
-
setSelectedOpt(prev => ({
|
|
650
|
-
...prev,
|
|
651
|
-
[buttonId]: option.label,
|
|
652
|
-
curIndex: index,
|
|
653
|
-
curValue: value
|
|
654
|
-
}));
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
// The button action is performed and the drop-down menu is closed only when it is not the default selection
|
|
659
|
-
if (!isDefaultSelection) {
|
|
660
|
-
executeButtonAction(option.onClick, buttonId, document.getElementById(buttonId) as HTMLButtonElement);
|
|
661
|
-
|
|
662
|
-
// Close the drop-down
|
|
663
|
-
closeDropdowns();
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
// click outside
|
|
669
|
-
useClickOutside({
|
|
670
|
-
enabled: Object.values(activeButtons).some(isActive => isActive),
|
|
671
|
-
isOutside: (event: any) => {
|
|
672
|
-
return event.target.closest('.toolkit-select-wrapper') === null;
|
|
673
|
-
},
|
|
674
|
-
handle: (event: any) => {
|
|
675
|
-
closeDropdowns();
|
|
676
|
-
}
|
|
677
|
-
}, [toolkitBtnsRef, activeButtons]);
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
//================================================================
|
|
682
|
-
// Conversation History
|
|
683
|
-
//================================================================
|
|
684
|
-
const conversationHistory = useRef<Array<MessageDetail>>([]);
|
|
685
|
-
const updateConversationHistory = (newMessage: MessageDetail) => {
|
|
686
|
-
const maxLength = args().maxHistoryLength || 20;
|
|
687
|
-
|
|
688
|
-
// Add new messages to your history
|
|
689
|
-
conversationHistory.current.push(newMessage);
|
|
690
|
-
|
|
691
|
-
// If the maximum length is exceeded, the oldest record is deleted
|
|
692
|
-
if (conversationHistory.current.length > maxLength) {
|
|
693
|
-
const removeCount = conversationHistory.current.length - maxLength;
|
|
694
|
-
conversationHistory.current = conversationHistory.current.slice(removeCount);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
//================================================================
|
|
701
|
-
// normal request
|
|
702
|
-
//================================================================
|
|
703
|
-
const abortController = useRef<any>(new AbortController()); // DO NOT USE "useState()"
|
|
704
|
-
|
|
705
|
-
const abortNormalRequest = () => {
|
|
706
|
-
console.log('--> Abort stream');
|
|
707
|
-
abortController.current.abort();
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
const reconnectNormalRequest = () => {
|
|
711
|
-
console.log('--> Reconnect stream');
|
|
712
|
-
abortController.current = new AbortController();
|
|
713
|
-
};
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
//================================================================
|
|
717
|
-
// stream controller
|
|
718
|
-
//================================================================
|
|
719
|
-
const abortStream = () => {
|
|
720
|
-
console.log('--> Abort stream');
|
|
721
|
-
streamController.abort();
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
// parse chunk data
|
|
725
|
-
const parseChunkData = async (chunk: string, index: number, complete: boolean) => {
|
|
726
|
-
|
|
727
|
-
// Store the final content and bind it to loading
|
|
728
|
-
let lastContent: string = '';
|
|
729
|
-
|
|
730
|
-
try {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
// Extract response using the path
|
|
734
|
-
const extractPath = args().responseExtractPath?.slice(1);
|
|
735
|
-
|
|
736
|
-
// Streaming data is JSON split by rows
|
|
737
|
-
const lines = chunk.split("\n").filter(line => line.trim() !== "");
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
for (const line of lines) {
|
|
741
|
-
|
|
742
|
-
// debug
|
|
743
|
-
if (args().debug && index < 10 && !complete) {
|
|
744
|
-
console.log(`--> (${index}) ${line}`);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
// Send the streamed data to the front end
|
|
748
|
-
if (line.indexOf('[DONE]') < 0) {
|
|
749
|
-
|
|
750
|
-
// STEP 1:
|
|
751
|
-
// ------
|
|
752
|
-
// Create a JSON string
|
|
753
|
-
const _content = `${line.replace(/^data:\s*/, '')}`;
|
|
754
|
-
|
|
755
|
-
// Determine whether it is in JSON format
|
|
756
|
-
if (!isJSON(_content)) {
|
|
757
|
-
console.log('--> [ERROR] Wrong JSON format');
|
|
758
|
-
|
|
759
|
-
//reset SSE
|
|
760
|
-
closeSSE();
|
|
761
|
-
break; // Exit the loop
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// STEP 2:
|
|
765
|
-
// ------
|
|
766
|
-
// Response body
|
|
767
|
-
let result = JSON.parse(_content);
|
|
768
|
-
|
|
769
|
-
//*******
|
|
770
|
-
// for Ollama API (STREAM END)
|
|
771
|
-
//*******
|
|
772
|
-
if (typeof result.done !== 'undefined') {
|
|
773
|
-
if (result.done === true) {
|
|
774
|
-
console.log('--> [DONE]');
|
|
775
|
-
|
|
776
|
-
//reset SSE
|
|
777
|
-
closeSSE();
|
|
778
|
-
break; // Exit the loop
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
//*******
|
|
783
|
-
// for OpenAI API
|
|
784
|
-
//*******
|
|
785
|
-
if (extractPath) {
|
|
786
|
-
for (const path of extractPath) {
|
|
787
|
-
result = result[path];
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
let content = result;
|
|
792
|
-
|
|
793
|
-
// STEP 3:
|
|
794
|
-
// ------
|
|
795
|
-
// 🚀 !! IMPORTANT: Skip the error content
|
|
796
|
-
if (typeof content === 'undefined') {
|
|
797
|
-
continue;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
// STEP 4:
|
|
802
|
-
// ------
|
|
803
|
-
// Update thinking state
|
|
804
|
-
if (content.includes('<think>')) {
|
|
805
|
-
setThinking(true);
|
|
806
|
-
}
|
|
807
|
-
if (content.includes('</think>')) {
|
|
808
|
-
setThinking(false);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
// STEP 5:
|
|
813
|
-
// ------
|
|
814
|
-
// Replace with a valid label
|
|
815
|
-
content = fixHtmlTags(content, args().withReasoning, args().reasoningSwitchLabel);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
// STEP 6:
|
|
820
|
-
// ------
|
|
821
|
-
// By updating the stream text, you can update the UI
|
|
822
|
-
tempLastContent.current += content;
|
|
823
|
-
lastContent += content;
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
// STEP 7:
|
|
827
|
-
// ------
|
|
828
|
-
let parsedContent = tempLastContent.current;
|
|
829
|
-
|
|
830
|
-
// If a render parser exists, it is used to process the string
|
|
831
|
-
if (typeof args().renderParser === 'function') {
|
|
832
|
-
parsedContent = await args().renderParser(parsedContent);
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
// STEP 8:
|
|
837
|
-
// ------
|
|
838
|
-
// Real-time output
|
|
839
|
-
if (args().withReasoning) {
|
|
840
|
-
setTempAnimText(formatLatestDisplayContent(parsedContent));
|
|
841
|
-
} else {
|
|
842
|
-
if (!thinking) {
|
|
843
|
-
setTempAnimText(formatLatestDisplayContent(parsedContent));
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
// STEP 9:
|
|
848
|
-
// ------
|
|
849
|
-
// Scroll to the bottom
|
|
850
|
-
scrollToBottom();
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
} else {
|
|
854
|
-
console.log('--> [DONE]');
|
|
855
|
-
|
|
856
|
-
//reset SSE
|
|
857
|
-
closeSSE();
|
|
858
|
-
|
|
859
|
-
break; // Exit the loop
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
}
|
|
863
|
-
} catch (error) {
|
|
864
|
-
console.error('--> Error processing chunk:', error);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
let latestRes = complete ? lastContent : tempLastContent.current;
|
|
870
|
-
|
|
871
|
-
// If a render parser exists, it is used to process the string
|
|
872
|
-
if (typeof args().renderParser === 'function') {
|
|
873
|
-
latestRes = await args().renderParser(latestRes);
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
return formatLatestDisplayContent(latestRes);
|
|
877
|
-
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
// Store the final content and bind it to loading
|
|
881
|
-
const tempLastContent = useRef<string>('');
|
|
882
|
-
const streamController = useStreamController({
|
|
883
|
-
onChunk: async (chunk: string, index: number) => {
|
|
884
|
-
|
|
885
|
-
// start (Execute it only once)
|
|
886
|
-
if (index === 0) {
|
|
887
|
-
// hide loader
|
|
888
|
-
setLoaderDisplay(false);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
//
|
|
892
|
-
const res = await parseChunkData(chunk, index, false);
|
|
893
|
-
|
|
894
|
-
//
|
|
895
|
-
args().onChunk?.(inputContentRef.current, res, conversationHistory.current);
|
|
896
|
-
},
|
|
897
|
-
onComplete: async (lastContent: string) => {
|
|
898
|
-
console.log('--> Stream complete');
|
|
899
|
-
|
|
900
|
-
const res = await parseChunkData(lastContent, 0 , true);
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
// Display AI reply
|
|
904
|
-
displayMessage(args().answerNameRes, res);
|
|
905
|
-
|
|
906
|
-
//
|
|
907
|
-
args().onComplete?.(inputContentRef.current, res, conversationHistory.current);
|
|
908
|
-
|
|
909
|
-
//
|
|
910
|
-
closeSSE();
|
|
911
|
-
},
|
|
912
|
-
onError: (error) => {
|
|
913
|
-
console.error('--> Stream error:', error);
|
|
914
|
-
closeSSE();
|
|
915
|
-
},
|
|
916
|
-
onAbort: () => {
|
|
917
|
-
console.log('--> Stream aborted');
|
|
918
|
-
closeSSE();
|
|
919
|
-
}
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
//================================================================
|
|
924
|
-
// Core
|
|
925
|
-
//================================================================
|
|
926
|
-
const closeSSE = () => {
|
|
927
|
-
|
|
928
|
-
// reset
|
|
929
|
-
setTempAnimText('');
|
|
930
|
-
tempLastContent.current = '';
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
// Stop the timer
|
|
934
|
-
clearInterval(timer.current);
|
|
935
|
-
timer.current = null;
|
|
936
|
-
|
|
937
|
-
// loading
|
|
938
|
-
setLoading(false);
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
const displayMessage = (sender: string | undefined, content: string) => {
|
|
943
|
-
const timestamp = new Date().toLocaleTimeString(); // Get the current time
|
|
944
|
-
const tag = sender === args().answerNameRes ? '[reply]' : '';
|
|
945
|
-
|
|
946
|
-
const newMessage: MessageDetail = {
|
|
947
|
-
sender: sender || '',
|
|
948
|
-
timestamp,
|
|
949
|
-
content,
|
|
950
|
-
tag
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
// update messages history
|
|
954
|
-
updateConversationHistory(newMessage);
|
|
955
|
-
|
|
956
|
-
// Update the message list state
|
|
957
|
-
setMsgList((prevMessages) => [...prevMessages, newMessage]);
|
|
958
|
-
|
|
959
|
-
// Auto copy reply if enabled
|
|
960
|
-
if (args().autoCopyReply && sender === args().answerNameRes) {
|
|
961
|
-
chatboxCopyToClipboard(content);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
const sendMessage = async () => {
|
|
967
|
-
if (rootRef.current === null || msgContainerRef.current === null || msInput.current === null) return;
|
|
968
|
-
|
|
969
|
-
const messageInput: any = msInput.current;
|
|
970
|
-
let message = htmlEncode(messageInput.value);
|
|
971
|
-
|
|
972
|
-
// It fires in real time as the user enters
|
|
973
|
-
// Sanitizing input is the process of securing/cleaning/filtering input data.
|
|
974
|
-
if (typeof args().onInputCallback === 'function') {
|
|
975
|
-
message = await args().onInputCallback(message);
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
if (message.trim() === '') {
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
// Start the timer
|
|
983
|
-
setElapsedTime(0); // Reset elapsed time
|
|
984
|
-
timer.current = setInterval(() => {
|
|
985
|
-
setElapsedTime((prev) => prev + 1); // Increment elapsed time every second
|
|
986
|
-
}, 1000);
|
|
987
|
-
|
|
988
|
-
// user message
|
|
989
|
-
|
|
990
|
-
let inputMsg = `${message}`;
|
|
991
|
-
// If a render parser exists, it is used to process the string
|
|
992
|
-
if (typeof args().renderParser === 'function') {
|
|
993
|
-
inputMsg = await args().renderParser(inputMsg);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
displayMessage(args().questionNameRes, inputMsg); // Display user message
|
|
997
|
-
|
|
998
|
-
// loading
|
|
999
|
-
setLoading(true);
|
|
1000
|
-
|
|
1001
|
-
// show loader
|
|
1002
|
-
setLoaderDisplay(true);
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
// clear
|
|
1006
|
-
if (inputContentRef.current) inputContentRef.current.clear();
|
|
1007
|
-
|
|
1008
|
-
try {
|
|
1009
|
-
const res: any = await mainRequest(message);
|
|
1010
|
-
|
|
1011
|
-
// reply (normal)
|
|
1012
|
-
//======================
|
|
1013
|
-
if (!res.useStreamRender) {
|
|
1014
|
-
const reply = res.reply;
|
|
1015
|
-
let replyRes = `${reply}`;
|
|
1016
|
-
|
|
1017
|
-
// If a render parser exists, it is used to process the string
|
|
1018
|
-
if (typeof args().renderParser === 'function') {
|
|
1019
|
-
replyRes = await args().renderParser(replyRes);
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
displayMessage(args().answerNameRes, replyRes); // Display AI reply
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
//
|
|
1026
|
-
args().onChunk?.(inputContentRef.current, replyRes, conversationHistory.current);
|
|
1027
|
-
args().onComplete?.(inputContentRef.current, replyRes, conversationHistory.current);
|
|
1028
|
-
|
|
1029
|
-
//reset SSE
|
|
1030
|
-
closeSSE();
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
} catch (error) {
|
|
1035
|
-
|
|
1036
|
-
// loading
|
|
1037
|
-
setLoading(false);
|
|
1038
|
-
|
|
1039
|
-
// Stop the timer
|
|
1040
|
-
clearInterval(timer.current);
|
|
1041
|
-
timer.current = null;
|
|
1042
|
-
|
|
1043
|
-
console.error('--> Error sending message:', error);
|
|
1044
|
-
displayMessage(args().answerNameRes, `Error: Unable to send message: ${String(error)}`); // Display AI reply
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
// clear
|
|
1049
|
-
messageInput.value = '';
|
|
1050
|
-
|
|
1051
|
-
// reset textarea height
|
|
1052
|
-
if (inputContentRef.current) inputContentRef.current.resetHeight();
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
// Scroll to the bottom
|
|
1056
|
-
scrollToBottom();
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
const handleClickSafe = useDebounce(() => {
|
|
1060
|
-
sendMessage();
|
|
1061
|
-
}, 300, []);
|
|
1062
|
-
|
|
1063
|
-
const handleClose = (e: React.MouseEvent) => {
|
|
1064
|
-
e.preventDefault();
|
|
1065
|
-
e.stopPropagation();
|
|
1066
|
-
setShow(false);
|
|
1067
|
-
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const mainRequest = async (msg: string) => {
|
|
1072
|
-
|
|
1073
|
-
const currentStreamMode: boolean | undefined = args().isStream;
|
|
1074
|
-
|
|
1075
|
-
// Update stream mode
|
|
1076
|
-
setEnableStreamMode(currentStreamMode as boolean);
|
|
1077
|
-
|
|
1078
|
-
try {
|
|
1079
|
-
|
|
1080
|
-
// Parse and interpolate request body template
|
|
1081
|
-
let requestBodyRes = JSON.parse(
|
|
1082
|
-
(args().requestBodyTmpl || '{}')
|
|
1083
|
-
.replace(/\{model\}/g, args().model)
|
|
1084
|
-
.replace(/\{message\}/g, msg)
|
|
1085
|
-
.replace(/\{chatId\}/g, chatId)
|
|
1086
|
-
.replace(/\{token\}/g, tokenFormat(args().token) as string)
|
|
1087
|
-
);
|
|
1088
|
-
|
|
1089
|
-
//
|
|
1090
|
-
// If a formatter function exists, it is used to process the request body
|
|
1091
|
-
if (typeof args().requestBodyFormatter === 'function') {
|
|
1092
|
-
requestBodyRes = await args().requestBodyFormatter(requestBodyRes, args().latestContextData, conversationHistory.current);
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
// Scroll to the bottom
|
|
1096
|
-
setTimeout(() => {
|
|
1097
|
-
// Scroll to the bottom
|
|
1098
|
-
scrollToBottom();
|
|
1099
|
-
}, 500);
|
|
1100
|
-
|
|
1101
|
-
{/* ======================================================== */}
|
|
1102
|
-
{/* ===================== CUSTOM REQUEST ================== */}
|
|
1103
|
-
{/* ======================================================== */}
|
|
1104
|
-
// Check if customRequest exists and use it
|
|
1105
|
-
if (typeof args().customRequest === 'function') {
|
|
1106
|
-
|
|
1107
|
-
// Update stream mode
|
|
1108
|
-
setEnableStreamMode(false);
|
|
1109
|
-
|
|
1110
|
-
let customResponse: any = await args().customRequest(
|
|
1111
|
-
msg,
|
|
1112
|
-
{
|
|
1113
|
-
requestBody: requestBodyRes,
|
|
1114
|
-
apiUrl: args().requestApiUrl || '',
|
|
1115
|
-
headers: args().headerConfigRes
|
|
1116
|
-
},
|
|
1117
|
-
customMethodsRef.current,
|
|
1118
|
-
conversationHistory.current
|
|
1119
|
-
);
|
|
1120
|
-
const { content, isStream } = customResponse;
|
|
1121
|
-
let contentRes: any = content;
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
// Update stream mode
|
|
1126
|
-
setEnableStreamMode(isStream);
|
|
1127
|
-
|
|
1128
|
-
// NORMAL
|
|
1129
|
-
//++++++++++++++++++++++++++++++++++++++++++++++++
|
|
1130
|
-
if (!isStream && typeof contentRes === 'string' && contentRes.trim() !== '') {
|
|
1131
|
-
// Replace with a valid label
|
|
1132
|
-
contentRes = fixHtmlTags(contentRes as string, args().withReasoning, args().reasoningSwitchLabel);
|
|
1133
|
-
|
|
1134
|
-
return {
|
|
1135
|
-
reply: formatLatestDisplayContent(contentRes),
|
|
1136
|
-
useStreamRender: false
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
// STREAM
|
|
1141
|
-
//++++++++++++++++++++++++++++++++++++++++++++++++
|
|
1142
|
-
if (isStream && isStreamResponse(contentRes as never)) {
|
|
1143
|
-
// Start streaming
|
|
1144
|
-
await streamController.start(contentRes as never);
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
return {
|
|
1148
|
-
reply: tempAnimText, // The final content will be in tempAnimText
|
|
1149
|
-
useStreamRender: true
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
// DEFAULT
|
|
1155
|
-
//++++++++++++++++++++++++++++++++++++++++++++++++
|
|
1156
|
-
if (contentRes === null) {
|
|
1157
|
-
// Update stream mode
|
|
1158
|
-
setEnableStreamMode(currentStreamMode as boolean);
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
if (currentStreamMode) {
|
|
1164
|
-
{/* ======================================================== */}
|
|
1165
|
-
{/* ======================== STREAM ====================== */}
|
|
1166
|
-
{/* ======================================================== */}
|
|
1167
|
-
const response: any = await fetch((args().requestApiUrl || ''), {
|
|
1168
|
-
method: "POST",
|
|
1169
|
-
body: JSON.stringify(requestBodyRes),
|
|
1170
|
-
headers: args().headerConfigRes
|
|
1171
|
-
});
|
|
1172
|
-
|
|
1173
|
-
if (!response.ok) {
|
|
1174
|
-
const _errInfo = `[ERROR] HTTP Error ${response.status}: ${response.statusText}`;
|
|
1175
|
-
|
|
1176
|
-
setTempAnimText(_errInfo);
|
|
1177
|
-
|
|
1178
|
-
// hide loader
|
|
1179
|
-
setLoaderDisplay(false);
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
return {
|
|
1183
|
-
reply: _errInfo,
|
|
1184
|
-
useStreamRender: false
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
// Start streaming
|
|
1189
|
-
await streamController.start(response);
|
|
1190
|
-
|
|
1191
|
-
return {
|
|
1192
|
-
reply: tempAnimText, // The final content will be in tempAnimText
|
|
1193
|
-
useStreamRender: true
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
} else {
|
|
1198
|
-
{/* ======================================================== */}
|
|
1199
|
-
{/* ======================== NORMAL ====================== */}
|
|
1200
|
-
{/* ======================================================== */}
|
|
1201
|
-
|
|
1202
|
-
// Extract response using the path
|
|
1203
|
-
const extractPath = args().responseExtractPath?.slice(1);
|
|
1204
|
-
|
|
1205
|
-
const response = await fetch((args().requestApiUrl || ''), {
|
|
1206
|
-
method: "POST",
|
|
1207
|
-
headers: args().headerConfigRes,
|
|
1208
|
-
body: JSON.stringify(requestBodyRes),
|
|
1209
|
-
signal: abortController.current.signal
|
|
1210
|
-
});
|
|
1211
|
-
|
|
1212
|
-
if (!response.ok) {
|
|
1213
|
-
const _errInfo = `[ERROR] HTTP Error ${response.status}: ${response.statusText}`;
|
|
1214
|
-
|
|
1215
|
-
// hide loader
|
|
1216
|
-
setLoaderDisplay(false);
|
|
1217
|
-
|
|
1218
|
-
return {
|
|
1219
|
-
reply: _errInfo,
|
|
1220
|
-
useStreamRender: false
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
const jsonResponse = await response.json();
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
// hide loader
|
|
1228
|
-
setLoaderDisplay(false);
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
let result: any = jsonResponse;
|
|
1232
|
-
if (extractPath) {
|
|
1233
|
-
for (const path of extractPath) {
|
|
1234
|
-
result = result[path];
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
let content = result;
|
|
1239
|
-
|
|
1240
|
-
// Replace with a valid label
|
|
1241
|
-
content = fixHtmlTags(content, args().withReasoning, args().reasoningSwitchLabel);
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
return {
|
|
1245
|
-
reply: formatLatestDisplayContent(content),
|
|
1246
|
-
useStreamRender: false
|
|
1247
|
-
};
|
|
1248
|
-
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
} catch (error) {
|
|
1254
|
-
const _err = `--> Error in mainRequest: ${error}`;
|
|
1255
|
-
console.error(_err);
|
|
1256
|
-
|
|
1257
|
-
//reset SSE
|
|
1258
|
-
closeSSE();
|
|
1259
|
-
|
|
1260
|
-
return {
|
|
1261
|
-
reply: _err,
|
|
1262
|
-
useStreamRender: false
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
// exposes the following methods
|
|
1270
|
-
useImperativeHandle(
|
|
1271
|
-
propsRef.current.contentRef,
|
|
1272
|
-
() => exposedMethods(),
|
|
1273
|
-
[propsRef.current.contentRef, inputContentRef, msInput, msgList],
|
|
1274
|
-
);
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
// Update ref when props change
|
|
1279
|
-
useEffect(() => {
|
|
1280
|
-
propsRef.current = props;
|
|
1281
|
-
}, [props]);
|
|
1282
|
-
|
|
1283
|
-
useEffect(() => {
|
|
1284
|
-
if (props.requestConfig) {
|
|
1285
|
-
configRef.current = props.requestConfig;
|
|
1286
|
-
}
|
|
1287
|
-
}, [props.requestConfig]);
|
|
1288
|
-
|
|
1289
|
-
useEffect(() => {
|
|
1290
|
-
contextDataRef.current = props.contextData;
|
|
1291
|
-
}, [props.contextData]);
|
|
1292
|
-
|
|
1293
|
-
useEffect(() => {
|
|
1294
|
-
if (Array.isArray(props.defaultMessages) && props.defaultMessages.length > 0) {
|
|
1295
|
-
// Update the default messages
|
|
1296
|
-
setMsgList(props.defaultMessages);
|
|
1297
|
-
}
|
|
1298
|
-
}, [props.defaultMessages]);
|
|
1299
|
-
|
|
1300
|
-
useEffect(() => {
|
|
1301
|
-
if (Array.isArray(props.defaultMessages) && props.defaultMessages.length > 0) {
|
|
1302
|
-
// Update the default messages
|
|
1303
|
-
setMsgList(props.defaultMessages);
|
|
1304
|
-
}
|
|
1305
|
-
}, [props.defaultMessages]);
|
|
1306
|
-
|
|
1307
|
-
useEffect(() => {
|
|
1308
|
-
// Bind chatboxCopyToClipboard to window so it can be called in HTML code
|
|
1309
|
-
(window as any).chatboxCopyToClipboard = chatboxCopyToClipboard;
|
|
1310
|
-
}, []);
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
// Initialize the default value of toolkit buttons
|
|
1315
|
-
useEffect(() => {
|
|
1316
|
-
if (args().toolkitButtons) {
|
|
1317
|
-
args().toolkitButtons.forEach((btn: FloatingButton, index: number) => {
|
|
1318
|
-
const _id = `${args().prefix || 'custom-'}chatbox-btn-tools-${chatId}${index}`;
|
|
1319
|
-
|
|
1320
|
-
if (btn.isSelect) {
|
|
1321
|
-
|
|
1322
|
-
if (!initializedDefaults[_id] && typeof btn.defaultSelected === 'number') {
|
|
1323
|
-
const options = getButtonOptions(btn, _id);
|
|
1324
|
-
|
|
1325
|
-
// If there is a default selected item, initialize the selected state
|
|
1326
|
-
if (btn.defaultSelected >= 0 && btn.defaultSelected < options.length) {
|
|
1327
|
-
const defaultOption = options[btn.defaultSelected];
|
|
1328
|
-
if (defaultOption) {
|
|
1329
|
-
// Update the selected status
|
|
1330
|
-
// console.log('--> defaultOption: ', defaultOption);
|
|
1331
|
-
|
|
1332
|
-
// Pass the "isDefaultSelection" parameter as true
|
|
1333
|
-
handleExecuteButtonSelect(_id, defaultOption, btn.defaultSelected, defaultOption.value, true);
|
|
1334
|
-
|
|
1335
|
-
// Perform the onClick action alone
|
|
1336
|
-
executeDefaultOptionAction(defaultOption.onClick, _id);
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
// Mark this button with the default value initialized
|
|
1340
|
-
setInitializedDefaults(prev => ({
|
|
1341
|
-
...prev,
|
|
1342
|
-
[_id]: true
|
|
1343
|
-
}));
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
} else if (btn.active) {
|
|
1349
|
-
// For non-select buttons, if defaultActive is true, execute the onClick action
|
|
1350
|
-
executeButtonAction(btn.onClick, _id, document.getElementById(_id) as HTMLButtonElement);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
})
|
|
1355
|
-
}
|
|
1356
|
-
}, [chatId, args().toolkitButtons]); // It is only executed when the component is first rendered and when toolkitButtons changes
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
return (
|
|
1360
|
-
<>
|
|
1361
|
-
|
|
1362
|
-
<RootPortal show={true} usePortal={args().usePopUp} containerClassName="Chatbox">
|
|
1363
|
-
|
|
1364
|
-
{/**------------- BUBBLE -------------*/}
|
|
1365
|
-
{args().bubble ? <>
|
|
1366
|
-
<div className={`${args().prefix || 'custom-'}chatbox-circle`} onClick={(e: React.MouseEvent) => {
|
|
1367
|
-
e.preventDefault();
|
|
1368
|
-
e.stopPropagation();
|
|
1369
|
-
setShow(true);
|
|
1370
|
-
}}
|
|
1371
|
-
>
|
|
1372
|
-
<span dangerouslySetInnerHTML={{ __html: `${args().bubbleLabel}` }}></span>
|
|
1373
|
-
</div>
|
|
1374
|
-
</> : null}
|
|
1375
|
-
{/**------------- BUBBLE -------------*/}
|
|
1376
|
-
|
|
1377
|
-
{/**------------- CLOSE BUTTON -------------*/}
|
|
1378
|
-
<button style={{ display: show ? 'block' : 'none' }} className={`${args().prefix || 'custom-'}chatbox-close`} aria-label={`${args().closeLabel || 'Close'}`} data-balloon-pos="left" tabIndex={-1} onClick={handleClose}>
|
|
1379
|
-
<svg width="30px" height="30px" viewBox="0 0 1024 1024" fill="#000000"><path d="M707.872 329.392L348.096 689.16l-31.68-31.68 359.776-359.768z" fill="#000" /><path d="M328 340.8l32-31.2 348 348-32 32z" fill="#000" /></svg>
|
|
1380
|
-
|
|
1381
|
-
</button>
|
|
1382
|
-
{/**------------- CLOSE BUTTON------------- */}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
<div style={{ display: show ? 'block' : 'none' }} className={`${args().prefix || 'custom-'}chatbox-container ${typeof args().usePopUp !== 'undefined' && args().usePopUp === false ? 'popup-none' : ''}`} ref={rootRef}>
|
|
1386
|
-
|
|
1387
|
-
{/**------------- NO DATA -------------*/}
|
|
1388
|
-
{msgList.length === 0 ? <>
|
|
1389
|
-
|
|
1390
|
-
<div className={`d-flex flex-column align-items-center justify-content-center ${hasQuestion() ? '' : 'h-50'}`}>
|
|
1391
|
-
<p>
|
|
1392
|
-
<svg width="70px" height="70px" viewBox="0 0 24 24" fill="none">
|
|
1393
|
-
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 13.5997 2.37562 15.1116 3.04346 16.4525C3.22094 16.8088 3.28001 17.2161 3.17712 17.6006L2.58151 19.8267C2.32295 20.793 3.20701 21.677 4.17335 21.4185L6.39939 20.8229C6.78393 20.72 7.19121 20.7791 7.54753 20.9565C8.88837 21.6244 10.4003 22 12 22Z" stroke="#858297" strokeWidth="1.5" />
|
|
1394
|
-
<path opacity="0.5" d="M8 10.5H16" stroke="#333" strokeWidth="1.5" strokeLinecap="round" />
|
|
1395
|
-
<path opacity="0.5" d="M8 14H13.5" stroke="#333" strokeWidth="1.5" strokeLinecap="round" />
|
|
1396
|
-
</svg>
|
|
1397
|
-
|
|
1398
|
-
</p>
|
|
1399
|
-
<p className="text-primary" dangerouslySetInnerHTML={{ __html: `${args().noDataPlaceholder}` }}></p>
|
|
1400
|
-
|
|
1401
|
-
{/** DEFAULT QUESTIONS */}
|
|
1402
|
-
{hasQuestion() && (
|
|
1403
|
-
<div className="default-questions">
|
|
1404
|
-
<div className="default-questions-title" dangerouslySetInnerHTML={{ __html: `${(args().defaultQuestionsRes as QuestionData).title}` }}></div>
|
|
1405
|
-
{(args().defaultQuestionsRes as QuestionData).list?.map((question: string, index: number) => (
|
|
1406
|
-
<div
|
|
1407
|
-
key={index}
|
|
1408
|
-
className="default-question-item"
|
|
1409
|
-
onClick={() => handleQuestionClick(question)}
|
|
1410
|
-
dangerouslySetInnerHTML={{ __html: `${question}` }}
|
|
1411
|
-
/>
|
|
1412
|
-
))}
|
|
1413
|
-
</div>
|
|
1414
|
-
)}
|
|
1415
|
-
{/** /DEFAULT QUESTIONS */}
|
|
1416
|
-
|
|
1417
|
-
</div>
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
</> : null}
|
|
1421
|
-
{/**------------- /NO DATA -------------*/}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
{/**------------- MESSAGES LIST -------------*/}
|
|
1425
|
-
{/** Prevent excessive height overflow */}
|
|
1426
|
-
<div className={`messages ${msgList.length === 0 ? 'd-none' : ''}`} ref={msgContainerRef}>
|
|
1427
|
-
|
|
1428
|
-
{msgList.map((msg, index) => {
|
|
1429
|
-
|
|
1430
|
-
const copyTargetId = `${args().prefix || 'custom-'}chatbox-content--${chatId}${index}`;
|
|
1431
|
-
const isAnimProgress = tempAnimText !== '' && msg.sender !== args().questionNameRes && index === msgList.length - 1 && loading;
|
|
1432
|
-
const hasAnimated = animatedMessagesRef.current.has(index);
|
|
1433
|
-
|
|
1434
|
-
// Mark the message as animated;
|
|
1435
|
-
animatedMessagesRef.current.add(index);
|
|
1436
|
-
|
|
1437
|
-
const timeShow = `<span class="qa-timestamp">${msg.timestamp}</span>${args().showCopyBtn && msg.tag?.indexOf('[reply]') >= 0 ?(`<button class="copy-btn" aria-label="${args().copyLabel || 'Copy'}" data-balloon-pos="up" onclick="window.chatboxCopyToClipboard(document.querySelector('#${copyTargetId} .qa-content-inner').innerHTML)"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M8 4v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7.242a2 2 0 0 0-.602-1.43L16.083 2.57A2 2 0 0 0 14.685 2H10a2 2 0 0 0-2 2z"/><path d="M16 18v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h2"/></svg></button>`) : ''}`;
|
|
1438
|
-
|
|
1439
|
-
return <div key={index} className={msg.tag?.indexOf('[reply]') < 0 ? 'request' : 'reply'} style={{ display: isAnimProgress ? 'none' : '' }}>
|
|
1440
|
-
<div className="qa-name" dangerouslySetInnerHTML={{ __html: `${msg.sender}` }}></div>
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
{msg.sender === args().questionNameRes ? <>
|
|
1444
|
-
<div className="qa-content" id={copyTargetId} dangerouslySetInnerHTML={{ __html: `<div class="qa-content-inner">${msg.content}</div> ${timeShow}` }}></div>
|
|
1445
|
-
</> : <>
|
|
1446
|
-
|
|
1447
|
-
{enableStreamMode ? <>
|
|
1448
|
-
<div className="qa-content" id={copyTargetId} dangerouslySetInnerHTML={{ __html: `<div class="qa-content-inner">${msg.content}</div> ${timeShow}` }}></div>
|
|
1449
|
-
</> : <>
|
|
1450
|
-
<div className="qa-content" id={copyTargetId}>
|
|
1451
|
-
{hasAnimated ? (
|
|
1452
|
-
<div dangerouslySetInnerHTML={{ __html: `<div class="qa-content-inner">${msg.content}</div> ${timeShow}` }}></div>
|
|
1453
|
-
) : (
|
|
1454
|
-
<TypingEffect
|
|
1455
|
-
onUpdate={() => {
|
|
1456
|
-
scrollToBottom();
|
|
1457
|
-
}}
|
|
1458
|
-
content={`<div class="qa-content-inner">${msg.content}</div> ${timeShow}`}
|
|
1459
|
-
speed={10}
|
|
1460
|
-
/>
|
|
1461
|
-
)}
|
|
1462
|
-
|
|
1463
|
-
</div>
|
|
1464
|
-
</>}
|
|
1465
|
-
</>}
|
|
1466
|
-
|
|
1467
|
-
</div>
|
|
1468
|
-
}
|
|
1469
|
-
)}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
{/* ======================================================== */}
|
|
1474
|
-
{/* ====================== STREAM begin ==================== */}
|
|
1475
|
-
{/* ======================================================== */}
|
|
1476
|
-
{enableStreamMode ? <>
|
|
1477
|
-
{/** ANIM TEXT (has loading) */}
|
|
1478
|
-
{loading ? <>
|
|
1479
|
-
<div className="reply reply-waiting">
|
|
1480
|
-
<div className="qa-name">
|
|
1481
|
-
<span dangerouslySetInnerHTML={{ __html: `${args().answerNameRes}` }} />
|
|
1482
|
-
{loaderDisplay ? <>
|
|
1483
|
-
<div className="msg-dotted-loader-container">
|
|
1484
|
-
<span className="msg-dotted-loader"></span>
|
|
1485
|
-
<span className="msg-dotted-loader-text">{args().sendLoadingLabel} ({elapsedTime}s)</span>
|
|
1486
|
-
</div>
|
|
1487
|
-
</> : null}
|
|
1488
|
-
|
|
1489
|
-
</div>
|
|
1490
|
-
|
|
1491
|
-
<div className="qa-content">
|
|
1492
|
-
<div className="qa-content" dangerouslySetInnerHTML={{ __html: `${tempAnimText}` }}></div>
|
|
1493
|
-
</div>
|
|
1494
|
-
</div>
|
|
1495
|
-
</> : null}
|
|
1496
|
-
{/** /ANIM TEXT (has loading) */}
|
|
1497
|
-
</> : null}
|
|
1498
|
-
{/* ======================================================== */}
|
|
1499
|
-
{/* ====================== STREAM end ===================== */}
|
|
1500
|
-
{/* ======================================================== */}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
{/* ======================================================== */}
|
|
1506
|
-
{/* ====================== NORMAL begin ==================== */}
|
|
1507
|
-
{/* ======================================================== */}
|
|
1508
|
-
{!enableStreamMode ? <>
|
|
1509
|
-
{/** ANIM TEXT (has loading) */}
|
|
1510
|
-
{loading ? <>
|
|
1511
|
-
<div className="reply reply-waiting">
|
|
1512
|
-
<div className="qa-name">
|
|
1513
|
-
<span dangerouslySetInnerHTML={{ __html: `${args().answerNameRes}` }} />
|
|
1514
|
-
<div className="msg-dotted-loader-container">
|
|
1515
|
-
<span className="msg-dotted-loader"></span>
|
|
1516
|
-
<span className="msg-dotted-loader-text">{args().sendLoadingLabel} ({elapsedTime}s)</span>
|
|
1517
|
-
</div>
|
|
1518
|
-
|
|
1519
|
-
</div>
|
|
1520
|
-
|
|
1521
|
-
{tempAnimText !== '' ? <>
|
|
1522
|
-
<div className="qa-content">
|
|
1523
|
-
<div className="qa-content" dangerouslySetInnerHTML={{ __html: `${tempAnimText}` }}></div>
|
|
1524
|
-
</div>
|
|
1525
|
-
</> : null}
|
|
1526
|
-
|
|
1527
|
-
</div>
|
|
1528
|
-
</> : null}
|
|
1529
|
-
{/** /ANIM TEXT (has loading) */}
|
|
1530
|
-
</> : null}
|
|
1531
|
-
{/* ======================================================== */}
|
|
1532
|
-
{/* ====================== NORMAL end ===================== */}
|
|
1533
|
-
{/* ======================================================== */}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
{/**------------- NEW CHAT BUTTON -------------*/}
|
|
1537
|
-
{args().newChatButton && msgList.length > 0 && !loading && (
|
|
1538
|
-
<div className="newchat-btn">
|
|
1539
|
-
<button
|
|
1540
|
-
id={`${args().prefix || 'custom-'}chatbox-btn-new-${chatId}`}
|
|
1541
|
-
onClick={(e: React.MouseEvent<HTMLButtonElement>) => executeButtonAction(args().newChatButton.onClick, `${args().prefix || 'custom-'}chatbox-btn-new-${chatId}`, e.currentTarget)}
|
|
1542
|
-
>
|
|
1543
|
-
<span dangerouslySetInnerHTML={{ __html: args().newChatButton?.label || '' }}></span>
|
|
1544
|
-
</button>
|
|
1545
|
-
</div>
|
|
1546
|
-
)}
|
|
1547
|
-
{/**------------- /NEW CHAT BUTTON -------------*/}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
</div>
|
|
1552
|
-
{/**------------- /MESSAGES LIST -------------*/}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
{/**------------- CONTROL AREA -------------*/}
|
|
1558
|
-
<div className={`msgcontrol ${focused ? 'focus' : ''}`}>
|
|
1559
|
-
|
|
1560
|
-
<Textarea
|
|
1561
|
-
ref={msInput}
|
|
1562
|
-
contentRef={inputContentRef}
|
|
1563
|
-
controlClassName="messageInput-control"
|
|
1564
|
-
wrapperClassName="messageInput"
|
|
1565
|
-
placeholder={args().placeholder}
|
|
1566
|
-
disabled={loading ? true : false}
|
|
1567
|
-
onKeyDown={(event: React.KeyboardEvent) => {
|
|
1568
|
-
// line breaks
|
|
1569
|
-
if ((event.key === 'Enter' || event.key === 'NumpadEnter') && (event.ctrlKey || event.metaKey)) {
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
if ((event.key === 'Enter' || event.key === 'NumpadEnter') && !event.shiftKey && !event.ctrlKey && !event.metaKey) {
|
|
1574
|
-
event.preventDefault(); // Prevent line breaks
|
|
1575
|
-
handleClickSafe();
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
}}
|
|
1579
|
-
onChange={(e: React.ChangeEvent<HTMLTextAreaElement> | React.KeyboardEvent<HTMLTextAreaElement> | null, el: HTMLTextAreaElement | null, value: string) => {
|
|
1580
|
-
args().onInputChange?.(inputContentRef.current, value);
|
|
1581
|
-
}}
|
|
1582
|
-
onFocus={() => {
|
|
1583
|
-
setFocused(true);
|
|
1584
|
-
}}
|
|
1585
|
-
onBlur={() => {
|
|
1586
|
-
setFocused(false);
|
|
1587
|
-
}}
|
|
1588
|
-
rows={args().defaultRows || 2}
|
|
1589
|
-
autoSize
|
|
1590
|
-
autoSizeMaxHeight={200}
|
|
1591
|
-
/>
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
{loading ? <>
|
|
1595
|
-
<button
|
|
1596
|
-
onClick={(e: React.MouseEvent) => {
|
|
1597
|
-
e.preventDefault();
|
|
1598
|
-
e.stopPropagation();
|
|
1599
|
-
|
|
1600
|
-
if (!enableStreamMode) {
|
|
1601
|
-
// normal request
|
|
1602
|
-
abortNormalRequest();
|
|
1603
|
-
} else {
|
|
1604
|
-
// stop stream
|
|
1605
|
-
abortStream();
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
//reset SSE
|
|
1609
|
-
closeSSE();
|
|
1610
|
-
}}
|
|
1611
|
-
className="is-suspended"
|
|
1612
|
-
dangerouslySetInnerHTML={{ __html: `${args().stopLabel || '<svg width="15px" height="15px" viewBox="0 0 24 24" fill="none"><path d="M2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12Z" fill="#1C274C"/></svg>'}` }}
|
|
1613
|
-
></button>
|
|
1614
|
-
</> : <>
|
|
1615
|
-
<button
|
|
1616
|
-
onClick={(e: React.MouseEvent) => {
|
|
1617
|
-
e.preventDefault();
|
|
1618
|
-
e.stopPropagation();
|
|
1619
|
-
|
|
1620
|
-
// normal request
|
|
1621
|
-
if (!enableStreamMode) {
|
|
1622
|
-
if (abortController.current.signal.aborted) {
|
|
1623
|
-
reconnectNormalRequest();
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
handleClickSafe();
|
|
1628
|
-
}}
|
|
1629
|
-
dangerouslySetInnerHTML={{ __html: `${args().sendLabel}` }}
|
|
1630
|
-
></button>
|
|
1631
|
-
</>}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
</div>
|
|
1635
|
-
{/**------------- /CONTROL AREA -------------*/}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
{/**------------- SEND LOADING -------------*/}
|
|
1640
|
-
{args().sendLoading ? <div className="loading"><div style={{ display: loading ? 'block' : 'none' }}><PureLoader prefix={args().prefix} customClassName="w-100" txt="" /></div></div> : null}
|
|
1641
|
-
{/**------------- /SEND LOADING -------------*/}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
{/**------------- TOOLKIT BUTTONS -------------*/}
|
|
1645
|
-
{args().toolkitButtons && args().toolkitButtons.length > 0 && (
|
|
1646
|
-
<div className="toolkit-btns" ref={toolkitBtnsRef}>
|
|
1647
|
-
{args().toolkitButtons.map((btn: FloatingButton, index: number) => {
|
|
1648
|
-
const _id = `${args().prefix || 'custom-'}chatbox-btn-tools-${chatId}${index}`;
|
|
1649
|
-
const isActive = activeButtons[_id];
|
|
1650
|
-
|
|
1651
|
-
if (btn.isSelect) {
|
|
1652
|
-
const options = getButtonOptions(btn, _id);
|
|
1653
|
-
|
|
1654
|
-
return (
|
|
1655
|
-
<div key={index} className="toolkit-select-wrapper">
|
|
1656
|
-
<button
|
|
1657
|
-
id={_id}
|
|
1658
|
-
data-value={btn.value || ''}
|
|
1659
|
-
className={`toolkit-select-btn ${isActive ? 'active' : ''} ${selectedOpt.curValue !== 'cancel' && typeof selectedOpt.curValue !== 'undefined' && selectedOpt.curValue !== '' ? 'opt-active' : ''}`}
|
|
1660
|
-
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
|
|
1661
|
-
e.preventDefault();
|
|
1662
|
-
setActiveButtons(prev => ({
|
|
1663
|
-
...prev,
|
|
1664
|
-
[_id]: !prev[_id]
|
|
1665
|
-
}));
|
|
1666
|
-
|
|
1667
|
-
//
|
|
1668
|
-
executeButtonAction(btn.onClick, _id, e.currentTarget);
|
|
1669
|
-
}}
|
|
1670
|
-
>
|
|
1671
|
-
<span dangerouslySetInnerHTML={{
|
|
1672
|
-
__html: selectedOpt[_id] as string || btn.label
|
|
1673
|
-
}}></span>
|
|
1674
|
-
|
|
1675
|
-
<span className="toolkit-select-arrow"><svg width="5px" height="5px" viewBox="0 -4.5 20 20">
|
|
1676
|
-
<g stroke="none" strokeWidth="1" fill="none">
|
|
1677
|
-
<g transform="translate(-180.000000, -6684.000000)" className="arrow-fill-g" fill="currentColor">
|
|
1678
|
-
<g transform="translate(56.000000, 160.000000)">
|
|
1679
|
-
<path d="M144,6525.39 L142.594,6524 L133.987,6532.261 L133.069,6531.38 L133.074,6531.385 L125.427,6524.045 L124,6525.414 C126.113,6527.443 132.014,6533.107 133.987,6535 C135.453,6533.594 134.024,6534.965 144,6525.39">
|
|
1680
|
-
</path>
|
|
1681
|
-
</g>
|
|
1682
|
-
</g>
|
|
1683
|
-
</g>
|
|
1684
|
-
</svg></span>
|
|
1685
|
-
</button>
|
|
1686
|
-
|
|
1687
|
-
{/* OPTIONS */}
|
|
1688
|
-
<div className={`toolkit-select-options ${isActive ? 'active' : ''}`}>
|
|
1689
|
-
|
|
1690
|
-
{options.length > 0 ? <>
|
|
1691
|
-
{options.map((option: FloatingButtonSelectOption, optIndex: number) => (
|
|
1692
|
-
<div
|
|
1693
|
-
key={optIndex}
|
|
1694
|
-
data-value={option.value || ''}
|
|
1695
|
-
className={`toolkit-select-option ${selectedOpt.curIndex === optIndex ? 'selected' : ''}`}
|
|
1696
|
-
onClick={() => handleExecuteButtonSelect(_id, option, optIndex, option.value)}
|
|
1697
|
-
>
|
|
1698
|
-
<span dangerouslySetInnerHTML={{ __html: option.label }}></span>
|
|
1699
|
-
</div>
|
|
1700
|
-
))}
|
|
1701
|
-
</> : <>
|
|
1702
|
-
<div className={`${args().prefix || 'custom-'}chatbox-mini-loader`}></div>
|
|
1703
|
-
</>}
|
|
1704
|
-
|
|
1705
|
-
</div>
|
|
1706
|
-
</div>
|
|
1707
|
-
);
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
// The rendering of the normal button
|
|
1711
|
-
return (
|
|
1712
|
-
<button
|
|
1713
|
-
key={index}
|
|
1714
|
-
id={_id}
|
|
1715
|
-
className={`${btn.value || ''} ${isActive ? 'active' : ''}`}
|
|
1716
|
-
onClick={(e: React.MouseEvent<HTMLButtonElement>) => executeButtonAction(btn.onClick, _id, e.currentTarget)}
|
|
1717
|
-
>
|
|
1718
|
-
<span dangerouslySetInnerHTML={{ __html: btn.label }}></span>
|
|
1719
|
-
</button>
|
|
1720
|
-
);
|
|
1721
|
-
})}
|
|
1722
|
-
</div>
|
|
1723
|
-
)}
|
|
1724
|
-
{/**------------- /TOOLKIT BUTTONS -------------*/}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
</div>
|
|
1729
|
-
|
|
1730
|
-
</RootPortal>
|
|
1731
|
-
|
|
1732
|
-
</>
|
|
1733
|
-
);
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
export default Chatbox;
|
|
1741
|
-
|
|
1742
|
-
|