@codeleap/web 5.8.20 → 6.0.1
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/dist/components/ActionIcon/index.d.ts +1 -1
- package/dist/components/ActionIcon/index.js +1 -1
- package/dist/components/ActionIcon/index.js.map +1 -1
- package/dist/components/ActivityIndicator/index.d.ts +9 -2
- package/dist/components/ActivityIndicator/index.js +8 -16
- package/dist/components/ActivityIndicator/index.js.map +1 -1
- package/dist/components/Badge/index.d.ts +1 -1
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Badge/index.js.map +1 -1
- package/dist/components/Badge/types.d.ts +1 -2
- package/dist/components/Button/index.d.ts +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Carousel/index.d.ts +5 -0
- package/dist/components/Carousel/index.js +168 -0
- package/dist/components/Carousel/index.js.map +1 -0
- package/dist/components/Carousel/styles.d.ts +3 -0
- package/dist/components/Carousel/styles.js.map +1 -0
- package/dist/components/Carousel/types.d.ts +34 -0
- package/dist/components/{Grid → Carousel}/types.js.map +1 -1
- package/dist/components/Checkbox/index.d.ts +1 -1
- package/dist/components/Checkbox/index.js +2 -2
- package/dist/components/Checkbox/index.js.map +1 -1
- package/dist/components/Collapse/index.d.ts +1 -1
- package/dist/components/Collapse/index.js +3 -3
- package/dist/components/Collapse/index.js.map +1 -1
- package/dist/components/Collapse/types.d.ts +1 -2
- package/dist/components/ColorPicker/index.d.ts +1 -1
- package/dist/components/ColorPicker/index.js +4 -4
- package/dist/components/ColorPicker/index.js.map +1 -1
- package/dist/components/ColorPicker/types.d.ts +3 -3
- package/dist/components/CropPicker/index.d.ts +9 -2
- package/dist/components/CropPicker/index.js +6 -6
- package/dist/components/CropPicker/index.js.map +1 -1
- package/dist/components/CropPicker/types.d.ts +3 -1
- package/dist/components/DatePicker/components/DayContent.js +1 -1
- package/dist/components/DatePicker/components/DayContent.js.map +1 -1
- package/dist/components/DatePicker/components/Header.js +1 -1
- package/dist/components/DatePicker/components/Header.js.map +1 -1
- package/dist/components/DatePicker/components/OuterInput.js +2 -12
- package/dist/components/DatePicker/components/OuterInput.js.map +1 -1
- package/dist/components/DatePicker/components/YearContent.js +1 -1
- package/dist/components/DatePicker/components/YearContent.js.map +1 -1
- package/dist/components/DatePicker/index.d.ts +1 -1
- package/dist/components/DatePicker/index.js +12 -13
- package/dist/components/DatePicker/index.js.map +1 -1
- package/dist/components/DatePicker/types.d.ts +8 -6
- package/dist/components/Drawer/index.d.ts +1 -1
- package/dist/components/Drawer/index.js +2 -2
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/Dropzone/index.d.ts +9 -2
- package/dist/components/Dropzone/index.js +7 -6
- package/dist/components/Dropzone/index.js.map +1 -1
- package/dist/components/Dropzone/types.d.ts +3 -2
- package/dist/components/EmptyPlaceholder/index.d.ts +1 -1
- package/dist/components/EmptyPlaceholder/index.js +3 -3
- package/dist/components/EmptyPlaceholder/index.js.map +1 -1
- package/dist/components/EmptyPlaceholder/types.d.ts +2 -2
- package/dist/components/FileInput/index.d.ts +5 -9
- package/dist/components/FileInput/index.js +6 -5
- package/dist/components/FileInput/index.js.map +1 -1
- package/dist/components/FileInput/types.d.ts +2 -0
- package/dist/components/Icon/index.d.ts +1 -1
- package/dist/components/Icon/index.js.map +1 -1
- package/dist/components/InputBase/index.js +2 -2
- package/dist/components/InputBase/index.js.map +1 -1
- package/dist/components/InputBase/types.d.ts +0 -1
- package/dist/components/InputBase/useInputBase.d.ts +2 -3
- package/dist/components/InputBase/useInputBase.js +2 -3
- package/dist/components/InputBase/useInputBase.js.map +1 -1
- package/dist/components/InputBase/useInputBasePartialStyles.js +1 -2
- package/dist/components/InputBase/useInputBasePartialStyles.js.map +1 -1
- package/dist/components/InputBase/utils.d.ts +1 -1
- package/dist/components/InputBase/utils.js +3 -3
- package/dist/components/InputBase/utils.js.map +1 -1
- package/dist/components/List/index.d.ts +2 -3
- package/dist/components/List/index.js +87 -40
- package/dist/components/List/index.js.map +1 -1
- package/dist/components/List/styles.d.ts +2 -4
- package/dist/components/List/types.d.ts +10 -52
- package/dist/components/LoadingOverlay/index.d.ts +1 -1
- package/dist/components/LoadingOverlay/index.js +1 -1
- package/dist/components/LoadingOverlay/index.js.map +1 -1
- package/dist/components/MaskedTextInput/index.d.ts +7 -0
- package/dist/components/MaskedTextInput/index.js +69 -0
- package/dist/components/MaskedTextInput/index.js.map +1 -0
- package/dist/components/MaskedTextInput/mask.d.ts +8 -0
- package/dist/components/MaskedTextInput/mask.js +37 -0
- package/dist/components/MaskedTextInput/mask.js.map +1 -0
- package/dist/components/MaskedTextInput/types.d.ts +10 -0
- package/dist/components/MaskedTextInput/types.js.map +1 -0
- package/dist/components/Modal/index.d.ts +1 -1
- package/dist/components/Modal/index.js +6 -6
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/NumberIncrement/index.d.ts +1 -1
- package/dist/components/NumberIncrement/index.js +1 -3
- package/dist/components/NumberIncrement/index.js.map +1 -1
- package/dist/components/NumberIncrement/useNumberIncrement.d.ts +4 -4
- package/dist/components/NumberIncrement/useNumberIncrement.js +1 -2
- package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -1
- package/dist/components/Overlay/index.d.ts +1 -1
- package/dist/components/PaginationButtons/index.d.ts +1 -1
- package/dist/components/PaginationButtons/index.js +2 -2
- package/dist/components/PaginationButtons/index.js.map +1 -1
- package/dist/components/PaginationButtons/types.d.ts +1 -2
- package/dist/components/PaginationIndicator/index.d.ts +2 -3
- package/dist/components/PaginationIndicator/index.js +2 -2
- package/dist/components/PaginationIndicator/index.js.map +1 -1
- package/dist/components/PaginationIndicator/types.d.ts +3 -3
- package/dist/components/Progress/Bar/index.d.ts +1 -1
- package/dist/components/Progress/Bar/index.js +1 -1
- package/dist/components/Progress/Bar/index.js.map +1 -1
- package/dist/components/Progress/Bar/types.d.ts +2 -3
- package/dist/components/Progress/Circle/index.d.ts +1 -1
- package/dist/components/Progress/Circle/index.js +2 -2
- package/dist/components/Progress/Circle/index.js.map +1 -1
- package/dist/components/Progress/Circle/types.d.ts +1 -2
- package/dist/components/Progress/index.d.ts +0 -1
- package/dist/components/Progress/utils.js +1 -2
- package/dist/components/Progress/utils.js.map +1 -1
- package/dist/components/RadioInput/index.d.ts +1 -1
- package/dist/components/RadioInput/index.js +2 -2
- package/dist/components/RadioInput/index.js.map +1 -1
- package/dist/components/SearchInput/index.js.map +1 -1
- package/dist/components/SectionFilters/index.d.ts +1 -1
- package/dist/components/SectionFilters/index.js +4 -4
- package/dist/components/SectionFilters/index.js.map +1 -1
- package/dist/components/SectionFilters/types.d.ts +1 -2
- package/dist/components/SegmentedControl/index.d.ts +1 -1
- package/dist/components/SegmentedControl/index.js +12 -21
- package/dist/components/SegmentedControl/index.js.map +1 -1
- package/dist/components/SegmentedControl/types.d.ts +2 -2
- package/dist/components/Select/index.js +5 -5
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Select/styles.js +1 -2
- package/dist/components/Select/styles.js.map +1 -1
- package/dist/components/Select/types.d.ts +6 -6
- package/dist/components/Slider/index.d.ts +1 -1
- package/dist/components/Slider/index.js +3 -3
- package/dist/components/Slider/index.js.map +1 -1
- package/dist/components/Switch/index.d.ts +1 -1
- package/dist/components/Switch/index.js +2 -2
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Tag/index.d.ts +1 -1
- package/dist/components/Tag/index.js +1 -1
- package/dist/components/Tag/index.js.map +1 -1
- package/dist/components/Text/index.d.ts +10 -2
- package/dist/components/Text/index.js +12 -20
- package/dist/components/Text/index.js.map +1 -1
- package/dist/components/Text/types.d.ts +3 -2
- package/dist/components/TextEditor/index.d.ts +1 -1
- package/dist/components/TextEditor/index.js +21 -9
- package/dist/components/TextEditor/index.js.map +1 -1
- package/dist/components/TextEditor/types.d.ts +4 -5
- package/dist/components/TextInput/index.d.ts +9 -3
- package/dist/components/TextInput/index.js +14 -30
- package/dist/components/TextInput/index.js.map +1 -1
- package/dist/components/TextInput/types.d.ts +4 -40
- package/dist/components/TextInput/useTextInput.d.ts +2 -6
- package/dist/components/TextInput/useTextInput.js +7 -16
- package/dist/components/TextInput/useTextInput.js.map +1 -1
- package/dist/components/Tooltip/index.d.ts +1 -1
- package/dist/components/Tooltip/index.js +1 -1
- package/dist/components/Tooltip/index.js.map +1 -1
- package/dist/components/Tooltip/types.d.ts +1 -1
- package/dist/components/Touchable/index.d.ts +10 -2
- package/dist/components/Touchable/index.js +9 -19
- package/dist/components/Touchable/index.js.map +1 -1
- package/dist/components/Touchable/types.d.ts +2 -1
- package/dist/components/View/index.d.ts +10 -2
- package/dist/components/View/index.js +7 -7
- package/dist/components/View/index.js.map +1 -1
- package/dist/components/View/types.d.ts +2 -2
- package/dist/components/VirtualList/context.d.ts +3 -0
- package/dist/components/VirtualList/context.js +93 -0
- package/dist/components/VirtualList/context.js.map +1 -0
- package/dist/components/VirtualList/index.d.ts +5 -0
- package/dist/components/VirtualList/index.js +14 -0
- package/dist/components/VirtualList/index.js.map +1 -0
- package/dist/components/VirtualList/list.d.ts +3 -0
- package/dist/components/VirtualList/list.js +102 -0
- package/dist/components/VirtualList/list.js.map +1 -0
- package/dist/components/VirtualList/types.d.ts +33 -0
- package/dist/components/{Pager/styles.js → VirtualList/types.js} +1 -1
- package/dist/components/VirtualList/types.js.map +1 -0
- package/dist/components/components.d.ts +4 -2
- package/dist/components/components.js +4 -2
- package/dist/components/components.js.map +1 -1
- package/dist/lib/ListMasonry.js +3 -3
- package/dist/lib/ListMasonry.js.map +1 -1
- package/dist/lib/WebStyleRegistry.js.map +1 -1
- package/dist/lib/hooks/index.d.ts +0 -1
- package/dist/lib/hooks/index.js +0 -1
- package/dist/lib/hooks/index.js.map +1 -1
- package/dist/lib/hooks/useAnimatedStyle.d.ts +8 -4
- package/dist/lib/hooks/useAnimatedStyle.js.map +1 -1
- package/dist/lib/hooks/useAnimatedVariantStyles.d.ts +3 -3
- package/dist/lib/hooks/useAnimatedVariantStyles.js +1 -2
- package/dist/lib/hooks/useAnimatedVariantStyles.js.map +1 -1
- package/dist/lib/hooks/useBreakpointMatch.js +1 -2
- package/dist/lib/hooks/useBreakpointMatch.js.map +1 -1
- package/dist/lib/hooks/useClick.js +1 -2
- package/dist/lib/hooks/useClick.js.map +1 -1
- package/dist/lib/hooks/useClickOutside.d.ts +1 -2
- package/dist/lib/hooks/useClickOutside.js +2 -3
- package/dist/lib/hooks/useClickOutside.js.map +1 -1
- package/dist/lib/hooks/useCropPicker.d.ts +1 -2
- package/dist/lib/hooks/useCropPicker.js +19 -7
- package/dist/lib/hooks/useCropPicker.js.map +1 -1
- package/dist/lib/hooks/useFileInput.d.ts +1 -2
- package/dist/lib/hooks/useKeydown.js +2 -2
- package/dist/lib/hooks/useKeydown.js.map +1 -1
- package/dist/lib/hooks/useMediaQuery.js +2 -3
- package/dist/lib/hooks/useMediaQuery.js.map +1 -1
- package/dist/lib/hooks/usePageExitBlocker.js.map +1 -1
- package/dist/lib/hooks/usePagination.js +1 -2
- package/dist/lib/hooks/usePagination.js.map +1 -1
- package/dist/lib/hooks/usePopState.js.map +1 -1
- package/dist/lib/hooks/useRefresh.d.ts +1 -1
- package/dist/lib/hooks/useRefresh.js.map +1 -1
- package/dist/lib/hooks/useScrollEffect.js +1 -2
- package/dist/lib/hooks/useScrollEffect.js.map +1 -1
- package/dist/lib/hooks/useSearchParams.d.ts +0 -1
- package/dist/lib/hooks/useSearchParams.js +1 -2
- package/dist/lib/hooks/useSearchParams.js.map +1 -1
- package/dist/lib/hooks/useStaticAnimationStyles.js +1 -2
- package/dist/lib/hooks/useStaticAnimationStyles.js.map +1 -1
- package/dist/lib/hooks/useWindowSize.js +1 -2
- package/dist/lib/hooks/useWindowSize.js.map +1 -1
- package/dist/lib/tools/localStorage.js.map +1 -1
- package/dist/lib/tools/mediaQuery.js +3 -4
- package/dist/lib/tools/mediaQuery.js.map +1 -1
- package/dist/lib/tools/modal.js +3 -3
- package/dist/lib/tools/modal.js.map +1 -1
- package/dist/lib/utils/pollyfils/scroll.js.map +1 -1
- package/dist/lib/utils/stopPropagation.js +1 -2
- package/dist/lib/utils/stopPropagation.js.map +1 -1
- package/dist/lib/utils/test.js.map +1 -1
- package/dist/types/utility.d.ts +2 -2
- package/package.json +39 -39
- package/package.json.bak +24 -24
- package/src/components/ActionIcon/index.tsx +1 -1
- package/src/components/ActivityIndicator/index.tsx +3 -4
- package/src/components/Badge/types.ts +1 -1
- package/src/components/Carousel/index.tsx +230 -0
- package/src/components/{Pager → Carousel}/styles.ts +2 -2
- package/src/components/Carousel/types.ts +41 -0
- package/src/components/Checkbox/index.tsx +1 -1
- package/src/components/Collapse/index.tsx +1 -1
- package/src/components/Collapse/types.ts +1 -1
- package/src/components/ColorPicker/types.ts +3 -3
- package/src/components/CropPicker/index.tsx +4 -3
- package/src/components/CropPicker/types.ts +3 -1
- package/src/components/DatePicker/components/OuterInput.tsx +3 -12
- package/src/components/DatePicker/index.tsx +18 -10
- package/src/components/DatePicker/types.ts +8 -5
- package/src/components/Dropzone/index.tsx +3 -2
- package/src/components/Dropzone/types.ts +3 -1
- package/src/components/EmptyPlaceholder/types.ts +2 -2
- package/src/components/FileInput/index.tsx +4 -3
- package/src/components/FileInput/types.ts +2 -0
- package/src/components/InputBase/useInputBase.ts +1 -1
- package/src/components/InputBase/utils.ts +1 -1
- package/src/components/List/index.tsx +56 -78
- package/src/components/List/styles.ts +2 -10
- package/src/components/List/types.ts +10 -52
- package/src/components/MaskedTextInput/index.tsx +58 -0
- package/src/components/MaskedTextInput/mask.ts +41 -0
- package/src/components/MaskedTextInput/types.ts +18 -0
- package/src/components/NumberIncrement/index.tsx +1 -3
- package/src/components/PaginationButtons/types.ts +1 -1
- package/src/components/PaginationIndicator/types.ts +2 -2
- package/src/components/Progress/Bar/types.ts +2 -2
- package/src/components/Progress/Circle/types.ts +1 -1
- package/src/components/SectionFilters/types.ts +1 -1
- package/src/components/SegmentedControl/index.tsx +6 -5
- package/src/components/SegmentedControl/types.ts +2 -2
- package/src/components/Select/index.tsx +3 -3
- package/src/components/Select/types.ts +6 -6
- package/src/components/Switch/index.tsx +1 -1
- package/src/components/Text/index.tsx +4 -3
- package/src/components/Text/types.ts +3 -2
- package/src/components/TextEditor/index.tsx +20 -18
- package/src/components/TextEditor/types.ts +5 -5
- package/src/components/TextInput/index.tsx +14 -34
- package/src/components/TextInput/types.ts +5 -57
- package/src/components/TextInput/useTextInput.ts +10 -19
- package/src/components/Tooltip/types.ts +1 -1
- package/src/components/Touchable/index.tsx +4 -4
- package/src/components/Touchable/types.ts +2 -1
- package/src/components/View/index.tsx +6 -5
- package/src/components/View/types.ts +3 -3
- package/src/components/VirtualList/context.tsx +93 -0
- package/src/components/VirtualList/index.tsx +11 -0
- package/src/components/VirtualList/list.tsx +85 -0
- package/src/components/VirtualList/types.ts +38 -0
- package/src/components/components.ts +4 -2
- package/src/lib/hooks/index.ts +0 -1
- package/src/lib/hooks/useAnimatedStyle.ts +11 -7
- package/src/lib/hooks/useAnimatedVariantStyles.ts +2 -2
- package/src/lib/hooks/useClickOutside.ts +1 -1
- package/src/lib/hooks/useMediaQuery.ts +1 -1
- package/src/types/utility.ts +2 -2
- package/dist/components/Grid/index.d.ts +0 -13
- package/dist/components/Grid/index.js +0 -94
- package/dist/components/Grid/index.js.map +0 -1
- package/dist/components/Grid/styles.d.ts +0 -2
- package/dist/components/Grid/styles.js.map +0 -1
- package/dist/components/Grid/types.d.ts +0 -9
- package/dist/components/List/ListLayout.d.ts +0 -2
- package/dist/components/List/ListLayout.js +0 -39
- package/dist/components/List/ListLayout.js.map +0 -1
- package/dist/components/Pager/index.d.ts +0 -7
- package/dist/components/Pager/index.js +0 -118
- package/dist/components/Pager/index.js.map +0 -1
- package/dist/components/Pager/styles.d.ts +0 -3
- package/dist/components/Pager/styles.js.map +0 -1
- package/dist/components/Pager/types.d.ts +0 -27
- package/dist/components/Pager/types.js.map +0 -1
- package/dist/components/TextInput/mask.d.ts +0 -5
- package/dist/components/TextInput/mask.js +0 -110
- package/dist/components/TextInput/mask.js.map +0 -1
- package/dist/lib/deprecated/OSAlert.d.ts +0 -38
- package/dist/lib/deprecated/OSAlert.js +0 -139
- package/dist/lib/deprecated/OSAlert.js.map +0 -1
- package/dist/lib/deprecated/index.d.ts +0 -1
- package/dist/lib/deprecated/index.js +0 -22
- package/dist/lib/deprecated/index.js.map +0 -1
- package/dist/lib/hooks/useInfiniteScroll.d.ts +0 -22
- package/dist/lib/hooks/useInfiniteScroll.js +0 -98
- package/dist/lib/hooks/useInfiniteScroll.js.map +0 -1
- package/src/components/Grid/index.tsx +0 -126
- package/src/components/Grid/styles.ts +0 -3
- package/src/components/Grid/types.ts +0 -13
- package/src/components/List/ListLayout.tsx +0 -87
- package/src/components/Pager/index.tsx +0 -156
- package/src/components/Pager/types.ts +0 -35
- package/src/components/TextInput/mask.tsx +0 -117
- package/src/lib/deprecated/OSAlert.tsx +0 -200
- package/src/lib/deprecated/index.ts +0 -6
- package/src/lib/hooks/useInfiniteScroll.ts +0 -77
- /package/dist/components/{Grid → Carousel}/styles.js +0 -0
- /package/dist/components/{Grid → Carousel}/types.js +0 -0
- /package/dist/components/{Pager → MaskedTextInput}/types.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { onUpdate, useCallback } from '@codeleap/hooks'
|
|
3
|
-
import { BubbleMenu, FloatingMenu, EditorContent } from '@tiptap/react'
|
|
3
|
+
// import { BubbleMenu, FloatingMenu, EditorContent } from '@tiptap/react'
|
|
4
4
|
import { FileInput, Text, View } from '../components'
|
|
5
5
|
import { TextEditorProps } from './types'
|
|
6
6
|
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
@@ -49,25 +49,27 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
49
49
|
}, [editor, handleBlur, handleFocus])
|
|
50
50
|
|
|
51
51
|
const _BubbleMenu = useCallback(() => {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
return null
|
|
53
|
+
// return (
|
|
54
|
+
// // @ts-expect-error icss type
|
|
55
|
+
// <BubbleMenu css={[styles.bubbleMenu]} {...bubbleMenuProps} editor={editor}>
|
|
56
|
+
// <View style={styles.bubbleMenuInnerWrapper}>
|
|
57
|
+
// {bubbleMenuProps?.renderContent}
|
|
58
|
+
// </View>
|
|
59
|
+
// </BubbleMenu>
|
|
60
|
+
// )
|
|
60
61
|
}, [editor])
|
|
61
62
|
|
|
62
63
|
const _FloatingMenu = useCallback(() => {
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
return null
|
|
65
|
+
// return (
|
|
66
|
+
// // @ts-expect-error icss type
|
|
67
|
+
// <FloatingMenu css={[styles.floatingMenu]} {...floatingMenuProps} editor={editor}>
|
|
68
|
+
// <View style={styles.floatingMenuInnerWrapper}>
|
|
69
|
+
// {floatingMenuProps?.renderContent}
|
|
70
|
+
// </View>
|
|
71
|
+
// </FloatingMenu>
|
|
72
|
+
// )
|
|
71
73
|
}, [editor])
|
|
72
74
|
|
|
73
75
|
const editorStyles = [
|
|
@@ -92,7 +94,7 @@ export const TextEditor = (props: TextEditorProps) => {
|
|
|
92
94
|
{children}
|
|
93
95
|
<_BubbleMenu />
|
|
94
96
|
<_FloatingMenu />
|
|
95
|
-
<EditorContent editor={editor} />
|
|
97
|
+
{/* <EditorContent editor={editor} /> */}
|
|
96
98
|
{validation?.showError ? <Text text={validation?.message as string} style={styles['errorMessage:error']} /> : null}
|
|
97
99
|
<FileInput ref={fileInputRef} />
|
|
98
100
|
</View>
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { RefObject } from 'react'
|
|
2
2
|
import { AnyFunction } from '@codeleap/types'
|
|
3
3
|
import { StyledProp } from '@codeleap/styles'
|
|
4
|
-
import { BubbleMenuProps, Editor, FloatingMenuProps } from '@tiptap/react'
|
|
4
|
+
// import { BubbleMenuProps, Editor, FloatingMenuProps } from '@tiptap/react'
|
|
5
5
|
import { FileInputRef } from '../FileInput'
|
|
6
6
|
import { TextEditorComposition } from './styles'
|
|
7
7
|
import { Validator } from '@codeleap/form'
|
|
8
8
|
|
|
9
9
|
export type TextEditorProps = React.PropsWithChildren<{
|
|
10
|
-
editor:
|
|
10
|
+
editor: any & {
|
|
11
11
|
getText: AnyFunction
|
|
12
12
|
isEditable: boolean
|
|
13
13
|
on: AnyFunction
|
|
14
14
|
off: AnyFunction
|
|
15
15
|
}
|
|
16
16
|
style?: StyledProp<TextEditorComposition>
|
|
17
|
-
bubbleMenuProps?:
|
|
18
|
-
floatingMenuProps?:
|
|
19
|
-
toolbarComponent?:
|
|
17
|
+
bubbleMenuProps?: any & { renderContent: React.ReactNode }
|
|
18
|
+
floatingMenuProps?: any & { renderContent: React.ReactNode }
|
|
19
|
+
toolbarComponent?: React.ReactElement
|
|
20
20
|
fileInputRef?: RefObject<FileInputRef>
|
|
21
21
|
validate?: Validator<string, any, any>
|
|
22
22
|
}>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { TypeGuards } from '@codeleap/types'
|
|
2
|
-
import React, {
|
|
3
|
-
import TextareaAutosize from 'react-autosize
|
|
4
|
-
import InputMask from 'react-input-mask'
|
|
2
|
+
import React, { useImperativeHandle } from 'react'
|
|
3
|
+
import TextareaAutosize from 'react-textarea-autosize'
|
|
5
4
|
import { Touchable } from '../Touchable'
|
|
6
5
|
import { InputBase, selectInputBaseProps } from '../InputBase'
|
|
7
6
|
import { getTestId } from '../../lib/utils/test'
|
|
8
|
-
import {
|
|
9
|
-
import { AnyRecord, AppIcon, IJSX, StyledComponentProps
|
|
7
|
+
import { TextInputProps } from './types'
|
|
8
|
+
import { AnyRecord, AppIcon, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
10
9
|
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
11
10
|
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
12
11
|
import { useTextInput } from './useTextInput'
|
|
@@ -14,9 +13,8 @@ import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyle
|
|
|
14
13
|
|
|
15
14
|
export * from './types'
|
|
16
15
|
export * from './styles'
|
|
17
|
-
export * from './mask'
|
|
18
16
|
|
|
19
|
-
export const TextInput =
|
|
17
|
+
export const TextInput = (props: TextInputProps) => {
|
|
20
18
|
const allProps = {
|
|
21
19
|
...TextInput.defaultProps,
|
|
22
20
|
...props,
|
|
@@ -37,6 +35,7 @@ export const TextInput = forwardRef<InputRef, TextInputProps>((props, inputRef)
|
|
|
37
35
|
visibleIcon,
|
|
38
36
|
hiddenIcon,
|
|
39
37
|
focused,
|
|
38
|
+
ref: inputRef,
|
|
40
39
|
...textInputProps
|
|
41
40
|
} = others as TextInputProps
|
|
42
41
|
|
|
@@ -44,13 +43,11 @@ export const TextInput = forwardRef<InputRef, TextInputProps>((props, inputRef)
|
|
|
44
43
|
|
|
45
44
|
const {
|
|
46
45
|
isMultiline,
|
|
47
|
-
isMasked,
|
|
48
46
|
isFocused: isInputFocused,
|
|
49
47
|
secureTextEntry,
|
|
50
48
|
handleBlur,
|
|
51
49
|
handleFocus,
|
|
52
50
|
handleChange,
|
|
53
|
-
maskProps,
|
|
54
51
|
innerInputRef,
|
|
55
52
|
wrapperRef,
|
|
56
53
|
errorMessage,
|
|
@@ -70,28 +67,13 @@ export const TextInput = forwardRef<InputRef, TextInputProps>((props, inputRef)
|
|
|
70
67
|
focus: isFocused,
|
|
71
68
|
})
|
|
72
69
|
|
|
73
|
-
const InputElement =
|
|
70
|
+
const InputElement: any = isMultiline ? TextareaAutosize : 'input'
|
|
74
71
|
|
|
75
72
|
const isPressable = TypeGuards.isFunction(onPress)
|
|
76
73
|
|
|
77
|
-
const focus = () => {
|
|
78
|
-
if (isMasked) {
|
|
79
|
-
// @ts-expect-error
|
|
80
|
-
innerInputRef.current?.getInputDOMNode()?.focus()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
innerInputRef.current?.focus?.()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
74
|
useImperativeHandle(inputRef, () => {
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
isTextInput: true,
|
|
90
|
-
getInputRef: () => {
|
|
91
|
-
return innerInputRef.current as unknown as HTMLInputElement
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
}, [!!innerInputRef?.current?.focus])
|
|
75
|
+
return innerInputRef?.current
|
|
76
|
+
}, [])
|
|
95
77
|
|
|
96
78
|
const visibilityToggleProps = visibilityToggle ? {
|
|
97
79
|
onPress: toggleSecureTextEntry,
|
|
@@ -149,8 +131,8 @@ export const TextInput = forwardRef<InputRef, TextInputProps>((props, inputRef)
|
|
|
149
131
|
{...buttonModeProps}
|
|
150
132
|
{...secureTextProps}
|
|
151
133
|
{...textInputProps}
|
|
152
|
-
onBlur={handleBlur}
|
|
153
|
-
onFocus={handleFocus}
|
|
134
|
+
onBlur={handleBlur as any}
|
|
135
|
+
onFocus={handleFocus as any}
|
|
154
136
|
css={[
|
|
155
137
|
styles.input,
|
|
156
138
|
isMultiline && styles['input:multiline'],
|
|
@@ -171,17 +153,16 @@ export const TextInput = forwardRef<InputRef, TextInputProps>((props, inputRef)
|
|
|
171
153
|
caretColorStyle,
|
|
172
154
|
],
|
|
173
155
|
},
|
|
174
|
-
]}
|
|
175
|
-
{...maskProps}
|
|
176
|
-
value={inputValue}
|
|
156
|
+
] as any}
|
|
177
157
|
onChange={handleChange}
|
|
178
158
|
ref={innerInputRef}
|
|
159
|
+
value={inputValue}
|
|
179
160
|
data-testid={testId}
|
|
180
161
|
/>
|
|
181
162
|
</InputBase>
|
|
182
163
|
)
|
|
183
164
|
|
|
184
|
-
}
|
|
165
|
+
}
|
|
185
166
|
|
|
186
167
|
TextInput.styleRegistryName = 'TextInput'
|
|
187
168
|
TextInput.elements = [...InputBase.elements, 'input', 'placeholder', 'selection']
|
|
@@ -194,7 +175,6 @@ TextInput.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
|
194
175
|
TextInput.defaultProps = {
|
|
195
176
|
hiddenIcon: 'input-visiblity:hidden' as AppIcon,
|
|
196
177
|
visibleIcon: 'input-visiblity:visible' as AppIcon,
|
|
197
|
-
masking: null,
|
|
198
178
|
} as TextInputProps
|
|
199
179
|
|
|
200
180
|
WebStyleRegistry.registerComponent(TextInput)
|
|
@@ -4,10 +4,12 @@ import { InputBaseProps } from '../InputBase'
|
|
|
4
4
|
import { HTMLProps } from '../../types'
|
|
5
5
|
import { TextInputComposition } from './styles'
|
|
6
6
|
import { Field } from '@codeleap/form'
|
|
7
|
-
import {
|
|
7
|
+
import { RefObject } from 'react'
|
|
8
8
|
|
|
9
9
|
type NativeTextInputProps = HTMLProps<'input'>
|
|
10
10
|
|
|
11
|
+
export type InputRef = HTMLInputElement
|
|
12
|
+
|
|
11
13
|
export type TextInputProps =
|
|
12
14
|
Omit<InputBaseProps, 'style' | 'ref'> &
|
|
13
15
|
Omit<NativeTextInputProps, 'value' | 'crossOrigin' | 'ref' | 'style'> &
|
|
@@ -22,65 +24,11 @@ export type TextInputProps =
|
|
|
22
24
|
focused?: boolean
|
|
23
25
|
forceError?: string
|
|
24
26
|
rows?: number
|
|
25
|
-
masking?: TextInputMaskingProps
|
|
26
27
|
visibleIcon?: AppIcon
|
|
27
28
|
hiddenIcon?: AppIcon
|
|
28
29
|
field?: Field<string, any, any>
|
|
29
30
|
value?: string
|
|
30
31
|
onValueChange?: (value: string) => void
|
|
32
|
+
onChangeText?: NativeTextInputProps['onChange']
|
|
33
|
+
ref?: RefObject<InputRef | null>
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
export type InputRef = {
|
|
34
|
-
isTextInput?: boolean
|
|
35
|
-
focus: () => void
|
|
36
|
-
getInputRef: () => HTMLInputElement
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type beforeMaskedValueChangeArgs = {
|
|
40
|
-
state: {
|
|
41
|
-
value: string | undefined
|
|
42
|
-
selection: {
|
|
43
|
-
start: number
|
|
44
|
-
end: number
|
|
45
|
-
length?: number
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
userInput: null | string
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type FormatChar = `[${string}]`
|
|
52
|
-
|
|
53
|
-
export type MaskProps = {
|
|
54
|
-
obfuscated?: boolean
|
|
55
|
-
mask?: string
|
|
56
|
-
placeholder?: string
|
|
57
|
-
maskChar?: string
|
|
58
|
-
formatChars?: Record<string, FormatChar>
|
|
59
|
-
alwaysShowMask?: boolean
|
|
60
|
-
validator?: AnyFunction
|
|
61
|
-
maskType?: 'BRL' | 'INTERNATIONAL'
|
|
62
|
-
getRawValue?: (value: any) => string
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type TextInputMaskTypeProp =
|
|
66
|
-
| 'credit-card'
|
|
67
|
-
| 'cpf'
|
|
68
|
-
| 'cnpj'
|
|
69
|
-
| 'zip-code'
|
|
70
|
-
| 'cel-phone'
|
|
71
|
-
| 'custom'
|
|
72
|
-
|
|
73
|
-
export interface TextInputMaskingProps {
|
|
74
|
-
type: TextInputMaskTypeProp
|
|
75
|
-
options?: MaskProps
|
|
76
|
-
onChangeMask?: (
|
|
77
|
-
newState: beforeMaskedValueChangeArgs['state'],
|
|
78
|
-
oldState: beforeMaskedValueChangeArgs['state'],
|
|
79
|
-
userInput: beforeMaskedValueChangeArgs['userInput']
|
|
80
|
-
) => beforeMaskedValueChangeArgs['state']
|
|
81
|
-
saveFormatted?: boolean
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type InputMaskProps = {
|
|
85
|
-
masking: TextInputMaskingProps
|
|
86
|
-
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React, { useCallback, useState
|
|
1
|
+
import React, { useCallback, useState } from 'react'
|
|
2
2
|
import { TextInputProps } from './types'
|
|
3
3
|
import { TypeGuards } from '@codeleap/types'
|
|
4
|
-
import { getMaskInputProps } from './mask'
|
|
5
4
|
import { useInputBase } from '../InputBase/useInputBase'
|
|
6
5
|
import { fields } from '@codeleap/form'
|
|
7
6
|
|
|
@@ -10,11 +9,11 @@ export function useTextInput(props: Partial<TextInputProps>) {
|
|
|
10
9
|
onFocus,
|
|
11
10
|
onBlur,
|
|
12
11
|
field,
|
|
13
|
-
masking,
|
|
14
12
|
multiline: isMultiline,
|
|
15
13
|
forceError,
|
|
16
14
|
value,
|
|
17
15
|
onValueChange,
|
|
16
|
+
onChangeText,
|
|
18
17
|
rows: providedRows,
|
|
19
18
|
} = props
|
|
20
19
|
|
|
@@ -24,12 +23,6 @@ export function useTextInput(props: Partial<TextInputProps>) {
|
|
|
24
23
|
|
|
25
24
|
const toggleSecureTextEntry = () => setSecureTextEntry(s => !s)
|
|
26
25
|
|
|
27
|
-
const isMasked = !TypeGuards.isNil(masking)
|
|
28
|
-
|
|
29
|
-
const maskProps = useMemo(() => {
|
|
30
|
-
return isMasked ? getMaskInputProps({ masking }) : null
|
|
31
|
-
}, [masking])
|
|
32
|
-
|
|
33
26
|
const {
|
|
34
27
|
fieldHandle,
|
|
35
28
|
validation,
|
|
@@ -37,7 +30,11 @@ export function useTextInput(props: Partial<TextInputProps>) {
|
|
|
37
30
|
wrapperRef,
|
|
38
31
|
onInputValueChange,
|
|
39
32
|
inputValue,
|
|
40
|
-
} = useInputBase<string>(
|
|
33
|
+
} = useInputBase<string>(
|
|
34
|
+
field,
|
|
35
|
+
fields.text,
|
|
36
|
+
{ value, onValueChange: onValueChange ?? onChangeText as any },
|
|
37
|
+
{
|
|
41
38
|
revealValue() {
|
|
42
39
|
setSecureTextEntry(false)
|
|
43
40
|
},
|
|
@@ -61,14 +58,10 @@ export function useTextInput(props: Partial<TextInputProps>) {
|
|
|
61
58
|
}, [onFocus])
|
|
62
59
|
|
|
63
60
|
const handleChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
|
61
|
+
if (TypeGuards.isFunction(onChangeText)) return onChangeText(event)
|
|
64
62
|
const inputValue = event?.target?.value
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
? maskProps?.getRawValue(inputValue)
|
|
68
|
-
: inputValue
|
|
69
|
-
|
|
70
|
-
onInputValueChange(value)
|
|
71
|
-
}, [onInputValueChange])
|
|
63
|
+
onInputValueChange(inputValue)
|
|
64
|
+
}, [onInputValueChange, onChangeText])
|
|
72
65
|
|
|
73
66
|
const rows = providedRows ?? (isMultiline ? 2 : undefined)
|
|
74
67
|
|
|
@@ -79,9 +72,7 @@ export function useTextInput(props: Partial<TextInputProps>) {
|
|
|
79
72
|
const errorMessage = validation?.message || forceError
|
|
80
73
|
|
|
81
74
|
return {
|
|
82
|
-
maskProps,
|
|
83
75
|
isMultiline,
|
|
84
|
-
isMasked,
|
|
85
76
|
isFocused,
|
|
86
77
|
secureTextEntry,
|
|
87
78
|
handleBlur,
|
|
@@ -26,7 +26,7 @@ export type TooltipProps =
|
|
|
26
26
|
{
|
|
27
27
|
toggle?: AnyFunction
|
|
28
28
|
visible?: boolean
|
|
29
|
-
content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) =>
|
|
29
|
+
content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => React.ReactElement)
|
|
30
30
|
triggerWrapper?: React.ElementType
|
|
31
31
|
triggerWrapperProps?: Partial<ViewProps>
|
|
32
32
|
style?: StyledProp<TooltipComposition>
|
|
@@ -12,7 +12,7 @@ import { logger } from '@codeleap/logger'
|
|
|
12
12
|
export * from './styles'
|
|
13
13
|
export * from './types'
|
|
14
14
|
|
|
15
|
-
export const Touchable =
|
|
15
|
+
export const Touchable = (touchableProps: TouchableProps) => {
|
|
16
16
|
const allProps = {
|
|
17
17
|
...Touchable.defaultProps,
|
|
18
18
|
...touchableProps,
|
|
@@ -33,6 +33,7 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
|
|
|
33
33
|
analyticsEnabled,
|
|
34
34
|
analyticsName,
|
|
35
35
|
analyticsData,
|
|
36
|
+
ref,
|
|
36
37
|
...props
|
|
37
38
|
} = allProps
|
|
38
39
|
|
|
@@ -48,7 +49,7 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
|
|
|
48
49
|
}
|
|
49
50
|
})
|
|
50
51
|
|
|
51
|
-
const Component = component as unknown as ComponentType<HTMLAttributes<HTMLButtonElement>>
|
|
52
|
+
const Component: any = component as unknown as ComponentType<HTMLAttributes<HTMLButtonElement>>
|
|
52
53
|
|
|
53
54
|
const notPressable = !TypeGuards.isFunction(onPress) && !TypeGuards.isFunction(onClick)
|
|
54
55
|
|
|
@@ -102,12 +103,11 @@ export const Touchable = forwardRef<HTMLButtonElement, TouchableProps>((touchabl
|
|
|
102
103
|
onClick={handleClick}
|
|
103
104
|
onKeyDown={handleClick}
|
|
104
105
|
ref={ref}
|
|
105
|
-
// @ts-expect-error icss type
|
|
106
106
|
css={[styles.wrapper, disabled && styles['wrapper:disabled']]}
|
|
107
107
|
data-testid={testId}
|
|
108
108
|
/>
|
|
109
109
|
)
|
|
110
|
-
}
|
|
110
|
+
}
|
|
111
111
|
|
|
112
112
|
Touchable.styleRegistryName = 'Touchable'
|
|
113
113
|
Touchable.elements = ['wrapper']
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyFunction } from '@codeleap/types'
|
|
2
|
-
import { ComponentPropsWithRef, ElementType } from 'react'
|
|
2
|
+
import { ComponentPropsWithRef, ElementType, ReactNode } from 'react'
|
|
3
3
|
import { TouchableComposition } from './styles'
|
|
4
4
|
import { AnyRecord, StyledProp } from '@codeleap/styles'
|
|
5
5
|
|
|
@@ -19,4 +19,5 @@ export type TouchableProps<T extends ElementType = 'button'> =
|
|
|
19
19
|
analyticsEnabled?: boolean
|
|
20
20
|
analyticsName?: string
|
|
21
21
|
analyticsData?: Record<string, any>
|
|
22
|
+
children?: ReactNode
|
|
22
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypeGuards } from '@codeleap/types'
|
|
2
|
-
import React, { ElementType
|
|
3
|
-
import { motion } from '
|
|
2
|
+
import React, { ElementType } from 'react'
|
|
3
|
+
import { motion } from 'motion/react'
|
|
4
4
|
import { ViewProps } from './types'
|
|
5
5
|
import { getTestId } from '../../lib/utils/test'
|
|
6
6
|
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
@@ -10,7 +10,7 @@ import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from
|
|
|
10
10
|
export * from './styles'
|
|
11
11
|
export * from './types'
|
|
12
12
|
|
|
13
|
-
export const View =
|
|
13
|
+
export const View = (viewProps: ViewProps) => {
|
|
14
14
|
const {
|
|
15
15
|
component,
|
|
16
16
|
children,
|
|
@@ -23,6 +23,7 @@ export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
|
|
|
23
23
|
style,
|
|
24
24
|
animated,
|
|
25
25
|
animatedProps,
|
|
26
|
+
ref,
|
|
26
27
|
...props
|
|
27
28
|
} = {
|
|
28
29
|
...View.defaultProps,
|
|
@@ -31,7 +32,7 @@ export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
|
|
|
31
32
|
|
|
32
33
|
const styles = useStylesFor(View.styleRegistryName, style)
|
|
33
34
|
|
|
34
|
-
const Component:
|
|
35
|
+
const Component: any = animated ? (motion?.[component as string] || motion.div) : (component || 'div')
|
|
35
36
|
|
|
36
37
|
function handleHover(isMouseOverElement: boolean) {
|
|
37
38
|
onHover?.(isMouseOverElement)
|
|
@@ -56,7 +57,7 @@ export const View = forwardRef<HTMLDivElement, ViewProps>((viewProps, ref) => {
|
|
|
56
57
|
{children}
|
|
57
58
|
</Component>
|
|
58
59
|
)
|
|
59
|
-
}
|
|
60
|
+
}
|
|
60
61
|
|
|
61
62
|
View.styleRegistryName = 'View'
|
|
62
63
|
View.elements = ['wrapper']
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TargetAndTransition, MotionProps } from 'motion/react'
|
|
2
2
|
import { AnyRecord, StyledProp } from '@codeleap/styles'
|
|
3
3
|
import { ViewComposition } from './styles'
|
|
4
4
|
import { ComponentPropsWithRef, ElementType } from 'react'
|
|
5
5
|
|
|
6
6
|
export type ViewProps<T extends ElementType = 'div'> =
|
|
7
|
-
Omit<ComponentPropsWithRef<T>, 'style'> &
|
|
8
|
-
Omit<
|
|
7
|
+
Omit<ComponentPropsWithRef<T>, 'style' | 'children'> &
|
|
8
|
+
Omit<TargetAndTransition, 'style' | 'children'> &
|
|
9
9
|
{
|
|
10
10
|
component?: ElementType<AnyRecord>
|
|
11
11
|
debugName?: string
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useVirtualizer } from '@tanstack/react-virtual'
|
|
2
|
+
import { useRef, useCallback, use, createContext } from 'react'
|
|
3
|
+
import { VirtualListProps, VirtualListContextValue } from './types'
|
|
4
|
+
|
|
5
|
+
const VirtualListContext = createContext<VirtualListContextValue<any> | null>(null)
|
|
6
|
+
|
|
7
|
+
export function VirtualListProvider<T>(listProps: React.PropsWithChildren<VirtualListProps<T>>) {
|
|
8
|
+
const {
|
|
9
|
+
children,
|
|
10
|
+
estimateSize,
|
|
11
|
+
data,
|
|
12
|
+
hasNextPage,
|
|
13
|
+
fetchNextPage,
|
|
14
|
+
isFetchingNextPage,
|
|
15
|
+
...virtualizerOptions
|
|
16
|
+
} = listProps
|
|
17
|
+
|
|
18
|
+
const scrollRef = useRef<HTMLDivElement | null>(null)
|
|
19
|
+
|
|
20
|
+
const listLength = data?.length ?? 0
|
|
21
|
+
|
|
22
|
+
const virtualizerItemCount = hasNextPage ? listLength + 1 : listLength
|
|
23
|
+
|
|
24
|
+
const paginationIndicatorIndex = hasNextPage ? virtualizerItemCount - 1 : null
|
|
25
|
+
|
|
26
|
+
const lastItemIndex = hasNextPage ? virtualizerItemCount - 2 : virtualizerItemCount - 1
|
|
27
|
+
|
|
28
|
+
const virtualizer = useVirtualizer({
|
|
29
|
+
gap: 16,
|
|
30
|
+
overscan: 5,
|
|
31
|
+
...virtualizerOptions,
|
|
32
|
+
count: virtualizerItemCount,
|
|
33
|
+
getScrollElement: () => scrollRef.current,
|
|
34
|
+
estimateSize(index) {
|
|
35
|
+
if (index === paginationIndicatorIndex) {
|
|
36
|
+
return 100
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const item = data?.[index]
|
|
40
|
+
|
|
41
|
+
return item && estimateSize ? estimateSize(item) : 100
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const loadNextPage = useCallback(() => {
|
|
46
|
+
const items = virtualizer.getVirtualItems()
|
|
47
|
+
|
|
48
|
+
const [_, lastItem] = [...items].reverse()
|
|
49
|
+
|
|
50
|
+
if (!lastItem) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
lastItem.index >= data.length - 1 &&
|
|
56
|
+
hasNextPage &&
|
|
57
|
+
!isFetchingNextPage
|
|
58
|
+
) {
|
|
59
|
+
fetchNextPage?.()
|
|
60
|
+
}
|
|
61
|
+
}, [
|
|
62
|
+
virtualizer.getVirtualItems(),
|
|
63
|
+
data?.length,
|
|
64
|
+
hasNextPage,
|
|
65
|
+
isFetchingNextPage,
|
|
66
|
+
fetchNextPage,
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
const contextValue = {
|
|
70
|
+
virtualizer,
|
|
71
|
+
loadNextPage,
|
|
72
|
+
scrollRef,
|
|
73
|
+
virtualizerItemCount,
|
|
74
|
+
paginationIndicatorIndex,
|
|
75
|
+
lastItemIndex,
|
|
76
|
+
list: {
|
|
77
|
+
data,
|
|
78
|
+
hasNextPage,
|
|
79
|
+
fetchNextPage,
|
|
80
|
+
isFetchingNextPage,
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return <VirtualListContext value={contextValue}>
|
|
85
|
+
{children}
|
|
86
|
+
</VirtualListContext>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useVirtualListContext<T extends (val: VirtualListContextValue<any>) => any>(selector: T): ReturnType<T> {
|
|
90
|
+
const context = use(VirtualListContext)
|
|
91
|
+
|
|
92
|
+
return selector(context)
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VirtualListContainer, VirtualListItems } from './list'
|
|
2
|
+
import { VirtualListProvider } from './context'
|
|
3
|
+
import { memo } from 'react'
|
|
4
|
+
|
|
5
|
+
export function createVirtualList<T>() {
|
|
6
|
+
return {
|
|
7
|
+
Provider: VirtualListProvider<T>,
|
|
8
|
+
Container: memo(VirtualListContainer),
|
|
9
|
+
Items: memo(VirtualListItems<T>),
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useVirtualListContext } from './context'
|
|
2
|
+
import React, { useCallback, useEffect, useMemo } from 'react'
|
|
3
|
+
import { VirtualItem } from '@tanstack/react-virtual'
|
|
4
|
+
import { EmptyPlaceholder } from '../EmptyPlaceholder'
|
|
5
|
+
import { VirtualListItemsProps, VirtualListContainerProps } from './types'
|
|
6
|
+
|
|
7
|
+
export function VirtualListItems<T>(props: VirtualListItemsProps<T>) {
|
|
8
|
+
const { renderItem: Item, ListFooterComponent = () => null } = props
|
|
9
|
+
|
|
10
|
+
const virtualizer = useVirtualListContext(v => v.virtualizer)
|
|
11
|
+
const listItems = useVirtualListContext(v => v.list.data)
|
|
12
|
+
const paginationIndicatorIndex = useVirtualListContext(v => v.paginationIndicatorIndex)
|
|
13
|
+
const getNextPage = useVirtualListContext(v => v.loadNextPage)
|
|
14
|
+
|
|
15
|
+
const items = virtualizer.getVirtualItems()
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
getNextPage()
|
|
19
|
+
}, [getNextPage])
|
|
20
|
+
|
|
21
|
+
const ItemWrapper = useCallback((props: React.PropsWithChildren<{ item: VirtualItem }>) => {
|
|
22
|
+
const { item, children } = props
|
|
23
|
+
|
|
24
|
+
return <div
|
|
25
|
+
style={{
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
top: 0,
|
|
28
|
+
left: 0,
|
|
29
|
+
width: '100%',
|
|
30
|
+
transform: `translateY(${item.start}px)`,
|
|
31
|
+
}}
|
|
32
|
+
ref={virtualizer.measureElement}
|
|
33
|
+
data-index={item.index}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
}, [virtualizer.measureElement])
|
|
38
|
+
|
|
39
|
+
const renderItem = useCallback((item: VirtualItem) => {
|
|
40
|
+
const data = listItems[item.index]
|
|
41
|
+
|
|
42
|
+
const isPaginationIndicator = item.index === paginationIndicatorIndex
|
|
43
|
+
|
|
44
|
+
if (isPaginationIndicator) {
|
|
45
|
+
return <ItemWrapper key={item.key} item={item}>
|
|
46
|
+
<ListFooterComponent />
|
|
47
|
+
</ItemWrapper>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return <ItemWrapper key={item.key} item={item}>
|
|
51
|
+
<Item index={item.index} item={data} />
|
|
52
|
+
</ItemWrapper>
|
|
53
|
+
|
|
54
|
+
}, [Item, ItemWrapper, listItems, ListFooterComponent, paginationIndicatorIndex])
|
|
55
|
+
|
|
56
|
+
const containerStyle = useMemo(() => ({
|
|
57
|
+
height: `${virtualizer.getTotalSize()}px`,
|
|
58
|
+
width: '100%',
|
|
59
|
+
position: 'relative' as const,
|
|
60
|
+
}), [virtualizer.getTotalSize()])
|
|
61
|
+
|
|
62
|
+
return <div style={containerStyle}>
|
|
63
|
+
{items.map(renderItem)}
|
|
64
|
+
</div>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const VirtualListContainer = (props: VirtualListContainerProps) => {
|
|
68
|
+
const { children, placeholder, ...rest } = props
|
|
69
|
+
|
|
70
|
+
const scrollRef = useVirtualListContext(ctx => ctx.scrollRef)
|
|
71
|
+
|
|
72
|
+
const totalItemCount = useVirtualListContext(ctx => ctx.list?.data?.length)
|
|
73
|
+
|
|
74
|
+
if (!totalItemCount || totalItemCount <= 0) {
|
|
75
|
+
if (React.isValidElement(placeholder)) {
|
|
76
|
+
return <>{placeholder}</>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return <EmptyPlaceholder {...placeholder} />
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return <div ref={scrollRef} {...rest}>
|
|
83
|
+
{children}
|
|
84
|
+
</div>
|
|
85
|
+
}
|