@codeleap/web 6.8.0 → 7.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/ActivityIndicator/index.js +28 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/styles.js +2 -0
- package/dist/components/ActivityIndicator/styles.js.map +1 -0
- package/dist/components/ActivityIndicator/types.js +2 -0
- package/dist/components/ActivityIndicator/types.js.map +1 -0
- package/dist/components/Badge/index.js +68 -0
- package/dist/components/Badge/index.js.map +1 -0
- package/dist/components/Badge/styles.js +2 -0
- package/dist/components/Badge/styles.js.map +1 -0
- package/dist/components/Badge/types.js +2 -0
- package/dist/components/Badge/types.js.map +1 -0
- package/dist/components/Button/index.js +52 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Button/styles.js +2 -0
- package/dist/components/Button/styles.js.map +1 -0
- package/dist/components/Button/types.js +2 -0
- package/dist/components/Button/types.js.map +1 -0
- package/dist/components/Calendar/index.js +50 -0
- package/dist/components/Calendar/index.js.map +1 -0
- package/dist/components/Calendar/styles.js +2 -0
- package/dist/components/Calendar/styles.js.map +1 -0
- package/dist/components/Calendar/types.js +2 -0
- package/dist/components/Calendar/types.js.map +1 -0
- package/dist/components/Carousel/index.js +129 -0
- package/dist/components/Carousel/index.js.map +1 -0
- package/dist/components/Carousel/styles.js +2 -0
- package/dist/components/Carousel/styles.js.map +1 -0
- package/dist/components/Carousel/types.js +2 -0
- package/dist/components/Carousel/types.js.map +1 -0
- package/dist/components/Checkbox/index.js +44 -0
- package/dist/components/Checkbox/index.js.map +1 -0
- package/dist/components/Checkbox/styles.js +2 -0
- package/dist/components/Checkbox/styles.js.map +1 -0
- package/dist/components/Checkbox/types.js +2 -0
- package/dist/components/Checkbox/types.js.map +1 -0
- package/dist/components/Collapse/index.js +27 -0
- package/dist/components/Collapse/index.js.map +1 -0
- package/dist/components/Collapse/styles.js +2 -0
- package/dist/components/Collapse/styles.js.map +1 -0
- package/dist/components/Collapse/types.js +2 -0
- package/dist/components/Collapse/types.js.map +1 -0
- package/dist/components/ColorPicker/index.js +65 -0
- package/dist/components/ColorPicker/index.js.map +1 -0
- package/dist/components/ColorPicker/styles.js +2 -0
- package/dist/components/ColorPicker/styles.js.map +1 -0
- package/dist/components/ColorPicker/types.js +2 -0
- package/dist/components/ColorPicker/types.js.map +1 -0
- package/dist/components/CropPicker/hooks.js +130 -0
- package/dist/components/CropPicker/hooks.js.map +1 -0
- package/dist/components/CropPicker/index.js +38 -0
- package/dist/components/CropPicker/index.js.map +1 -0
- package/dist/components/CropPicker/styles.js +2 -0
- package/dist/components/CropPicker/styles.js.map +1 -0
- package/dist/components/CropPicker/types.js +2 -0
- package/dist/components/CropPicker/types.js.map +1 -0
- package/dist/components/CropPicker/utils.js +70 -0
- package/dist/components/CropPicker/utils.js.map +1 -0
- package/dist/components/DatePicker/index.js +70 -0
- package/dist/components/DatePicker/index.js.map +1 -0
- package/dist/components/DatePicker/styles.js +2 -0
- package/dist/components/DatePicker/styles.js.map +1 -0
- package/dist/components/DatePicker/types.js +2 -0
- package/dist/components/DatePicker/types.js.map +1 -0
- package/dist/components/Drawer/index.js +50 -0
- package/dist/components/Drawer/index.js.map +1 -0
- package/dist/components/Drawer/styles.js +2 -0
- package/dist/components/Drawer/styles.js.map +1 -0
- package/dist/components/Drawer/types.js +2 -0
- package/dist/components/Drawer/types.js.map +1 -0
- package/dist/components/Dropzone/context.js +39 -0
- package/dist/components/Dropzone/context.js.map +1 -0
- package/dist/components/Dropzone/elements.js +51 -0
- package/dist/components/Dropzone/elements.js.map +1 -0
- package/dist/components/Dropzone/index.js +71 -0
- package/dist/components/Dropzone/index.js.map +1 -0
- package/dist/components/Dropzone/styles.js +2 -0
- package/dist/components/Dropzone/styles.js.map +1 -0
- package/dist/components/Dropzone/types.js +2 -0
- package/dist/components/Dropzone/types.js.map +1 -0
- package/dist/components/Dropzone/useDropzone.js +17 -0
- package/dist/components/Dropzone/useDropzone.js.map +1 -0
- package/dist/components/EmptyPlaceholder/index.js +65 -0
- package/dist/components/EmptyPlaceholder/index.js.map +1 -0
- package/dist/components/EmptyPlaceholder/styles.js +2 -0
- package/dist/components/EmptyPlaceholder/styles.js.map +1 -0
- package/dist/components/EmptyPlaceholder/types.js +2 -0
- package/dist/components/EmptyPlaceholder/types.js.map +1 -0
- package/dist/components/Field/context.js +52 -0
- package/dist/components/Field/context.js.map +1 -0
- package/dist/components/Field/elements.js +84 -0
- package/dist/components/Field/elements.js.map +1 -0
- package/dist/components/Field/index.js +37 -0
- package/dist/components/Field/index.js.map +1 -0
- package/dist/components/Field/styles.js +2 -0
- package/dist/components/Field/styles.js.map +1 -0
- package/dist/components/Field/types.js +2 -0
- package/dist/components/Field/types.js.map +1 -0
- package/dist/components/Field/useFieldInput.js +47 -0
- package/dist/components/Field/useFieldInput.js.map +1 -0
- package/dist/components/FileInput/index.js +55 -0
- package/dist/components/FileInput/index.js.map +1 -0
- package/dist/components/FileInput/types.js +2 -0
- package/dist/components/FileInput/types.js.map +1 -0
- package/dist/components/Icon/index.js +51 -0
- package/dist/components/Icon/index.js.map +1 -0
- package/dist/components/Icon/styles.js +2 -0
- package/dist/components/Icon/styles.js.map +1 -0
- package/dist/components/Icon/types.js +2 -0
- package/dist/components/Icon/types.js.map +1 -0
- package/dist/components/List/context.js +76 -0
- package/dist/components/List/context.js.map +1 -0
- package/dist/components/List/elements.js +123 -0
- package/dist/components/List/elements.js.map +1 -0
- package/dist/components/List/index.js +35 -0
- package/dist/components/List/index.js.map +1 -0
- package/dist/components/List/scroll.js +75 -0
- package/dist/components/List/scroll.js.map +1 -0
- package/dist/components/List/styles.js +2 -0
- package/dist/components/List/styles.js.map +1 -0
- package/dist/components/List/types.js +2 -0
- package/dist/components/List/types.js.map +1 -0
- package/dist/components/LoadingOverlay/index.js +32 -0
- package/dist/components/LoadingOverlay/index.js.map +1 -0
- package/dist/components/LoadingOverlay/styles.js +2 -0
- package/dist/components/LoadingOverlay/styles.js.map +1 -0
- package/dist/components/LoadingOverlay/types.js +2 -0
- package/dist/components/LoadingOverlay/types.js.map +1 -0
- package/dist/components/MaskedTextInput/index.js +34 -0
- package/dist/components/MaskedTextInput/index.js.map +1 -0
- package/dist/components/MaskedTextInput/mask.js +34 -0
- package/dist/components/MaskedTextInput/mask.js.map +1 -0
- package/dist/components/MaskedTextInput/types.js +2 -0
- package/dist/components/MaskedTextInput/types.js.map +1 -0
- package/dist/components/Modal/context.js +36 -0
- package/dist/components/Modal/context.js.map +1 -0
- package/dist/components/Modal/elements.js +66 -0
- package/dist/components/Modal/elements.js.map +1 -0
- package/dist/components/Modal/index.js +34 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/styles.js +2 -0
- package/dist/components/Modal/styles.js.map +1 -0
- package/dist/components/Modal/types.js +2 -0
- package/dist/components/Modal/types.js.map +1 -0
- package/dist/components/NumberIncrement/index.js +65 -0
- package/dist/components/NumberIncrement/index.js.map +1 -0
- package/dist/components/NumberIncrement/styles.js +2 -0
- package/dist/components/NumberIncrement/styles.js.map +1 -0
- package/dist/components/NumberIncrement/types.js +2 -0
- package/dist/components/NumberIncrement/types.js.map +1 -0
- package/dist/components/NumberIncrement/useNumberIncrement.js +113 -0
- package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -0
- package/dist/components/Overlay/index.js +44 -0
- package/dist/components/Overlay/index.js.map +1 -0
- package/dist/components/Overlay/styles.js +2 -0
- package/dist/components/Overlay/styles.js.map +1 -0
- package/dist/components/Overlay/types.js +2 -0
- package/dist/components/Overlay/types.js.map +1 -0
- package/dist/components/PaginationButtons/index.js +100 -0
- package/dist/components/PaginationButtons/index.js.map +1 -0
- package/dist/components/PaginationButtons/styles.js +2 -0
- package/dist/components/PaginationButtons/styles.js.map +1 -0
- package/dist/components/PaginationButtons/types.js +2 -0
- package/dist/components/PaginationButtons/types.js.map +1 -0
- package/dist/components/PaginationIndicator/index.js +41 -0
- package/dist/components/PaginationIndicator/index.js.map +1 -0
- package/dist/components/PaginationIndicator/styles.js +2 -0
- package/dist/components/PaginationIndicator/styles.js.map +1 -0
- package/dist/components/PaginationIndicator/types.js +2 -0
- package/dist/components/PaginationIndicator/types.js.map +1 -0
- package/dist/components/Progress/Bar/Segmented.js +37 -0
- package/dist/components/Progress/Bar/Segmented.js.map +1 -0
- package/dist/components/Progress/Bar/index.js +44 -0
- package/dist/components/Progress/Bar/index.js.map +1 -0
- package/dist/components/Progress/Bar/styles.js +2 -0
- package/dist/components/Progress/Bar/styles.js.map +1 -0
- package/dist/components/Progress/Bar/types.js +2 -0
- package/dist/components/Progress/Bar/types.js.map +1 -0
- package/dist/components/Progress/Circle/Segmented.js +60 -0
- package/dist/components/Progress/Circle/Segmented.js.map +1 -0
- package/dist/components/Progress/Circle/index.js +65 -0
- package/dist/components/Progress/Circle/index.js.map +1 -0
- package/dist/components/Progress/Circle/styles.js +2 -0
- package/dist/components/Progress/Circle/styles.js.map +1 -0
- package/dist/components/Progress/Circle/types.js +2 -0
- package/dist/components/Progress/Circle/types.js.map +1 -0
- package/dist/components/Progress/index.js +3 -0
- package/dist/components/Progress/index.js.map +1 -0
- package/dist/components/Progress/utils.js +4 -0
- package/dist/components/Progress/utils.js.map +1 -0
- package/dist/components/RadioInput/index.js +47 -0
- package/dist/components/RadioInput/index.js.map +1 -0
- package/dist/components/RadioInput/styles.js +2 -0
- package/dist/components/RadioInput/styles.js.map +1 -0
- package/dist/components/RadioInput/types.js +2 -0
- package/dist/components/RadioInput/types.js.map +1 -0
- package/dist/components/SearchInput/index.js +61 -0
- package/dist/components/SearchInput/index.js.map +1 -0
- package/dist/components/SectionFilters/index.js +148 -0
- package/dist/components/SectionFilters/index.js.map +1 -0
- package/dist/components/SectionFilters/styles.js +2 -0
- package/dist/components/SectionFilters/styles.js.map +1 -0
- package/dist/components/SectionFilters/types.js +2 -0
- package/dist/components/SectionFilters/types.js.map +1 -0
- package/dist/components/Select/context.js +156 -0
- package/dist/components/Select/context.js.map +1 -0
- package/dist/components/Select/elements.js +47 -0
- package/dist/components/Select/elements.js.map +1 -0
- package/dist/components/Select/index.js +53 -0
- package/dist/components/Select/index.js.map +1 -0
- package/dist/components/Select/styles.js +2 -0
- package/dist/components/Select/styles.js.map +1 -0
- package/dist/components/Select/types.js +2 -0
- package/dist/components/Select/types.js.map +1 -0
- package/dist/components/Select/useTriggerWidth.js +27 -0
- package/dist/components/Select/useTriggerWidth.js.map +1 -0
- package/dist/components/Slider/index.js +139 -0
- package/dist/components/Slider/index.js.map +1 -0
- package/dist/components/Slider/styles.js +2 -0
- package/dist/components/Slider/styles.js.map +1 -0
- package/dist/components/Slider/types.js +2 -0
- package/dist/components/Slider/types.js.map +1 -0
- package/dist/components/Switch/index.js +48 -0
- package/dist/components/Switch/index.js.map +1 -0
- package/dist/components/Switch/styles.js +2 -0
- package/dist/components/Switch/styles.js.map +1 -0
- package/dist/components/Switch/types.js +2 -0
- package/dist/components/Switch/types.js.map +1 -0
- package/dist/components/Tag/index.js +53 -0
- package/dist/components/Tag/index.js.map +1 -0
- package/dist/components/Tag/styles.js +2 -0
- package/dist/components/Tag/styles.js.map +1 -0
- package/dist/components/Tag/types.js +2 -0
- package/dist/components/Tag/types.js.map +1 -0
- package/dist/components/Text/index.js +94 -0
- package/dist/components/Text/index.js.map +1 -0
- package/dist/components/Text/styles.js +2 -0
- package/dist/components/Text/styles.js.map +1 -0
- package/dist/components/Text/types.js +2 -0
- package/dist/components/Text/types.js.map +1 -0
- package/dist/components/TextEditor/index.js +90 -0
- package/dist/components/TextEditor/index.js.map +1 -0
- package/dist/components/TextEditor/styles.js +2 -0
- package/dist/components/TextEditor/styles.js.map +1 -0
- package/dist/components/TextEditor/types.js +2 -0
- package/dist/components/TextEditor/types.js.map +1 -0
- package/dist/components/TextInput/index.js +65 -0
- package/dist/components/TextInput/index.js.map +1 -0
- package/dist/components/TextInput/styles.js +2 -0
- package/dist/components/TextInput/styles.js.map +1 -0
- package/dist/components/TextInput/types.js +2 -0
- package/dist/components/TextInput/types.js.map +1 -0
- package/dist/components/TextInput/useTextInput.js +64 -0
- package/dist/components/TextInput/useTextInput.js.map +1 -0
- package/dist/components/Tooltip/index.js +94 -0
- package/dist/components/Tooltip/index.js.map +1 -0
- package/dist/components/Tooltip/styles.js +2 -0
- package/dist/components/Tooltip/styles.js.map +1 -0
- package/dist/components/Tooltip/types.js +2 -0
- package/dist/components/Tooltip/types.js.map +1 -0
- package/dist/components/Touchable/index.js +80 -0
- package/dist/components/Touchable/index.js.map +1 -0
- package/dist/components/Touchable/styles.js +2 -0
- package/dist/components/Touchable/styles.js.map +1 -0
- package/dist/components/Touchable/types.js +2 -0
- package/dist/components/Touchable/types.js.map +1 -0
- package/dist/components/View/index.js +39 -0
- package/dist/components/View/index.js.map +1 -0
- package/dist/components/View/styles.js +2 -0
- package/dist/components/View/styles.js.map +1 -0
- package/dist/components/View/types.js +2 -0
- package/dist/components/View/types.js.map +1 -0
- package/dist/components/components.js +42 -0
- package/dist/components/components.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/ListMasonry.js +86 -0
- package/dist/lib/ListMasonry.js.map +1 -0
- package/dist/lib/ThemeVariables.js +22 -0
- package/dist/lib/ThemeVariables.js.map +1 -0
- package/dist/lib/WebStyleRegistry.js +69 -0
- package/dist/lib/WebStyleRegistry.js.map +1 -0
- package/dist/lib/hooks/index.js +23 -0
- package/dist/lib/hooks/index.js.map +1 -0
- package/dist/lib/hooks/useAnimatedStyle.js +23 -0
- package/dist/lib/hooks/useAnimatedStyle.js.map +1 -0
- package/dist/lib/hooks/useAnimatedVariantStyles.js +20 -0
- package/dist/lib/hooks/useAnimatedVariantStyles.js.map +1 -0
- package/dist/lib/hooks/useAsyncSelect.js +57 -0
- package/dist/lib/hooks/useAsyncSelect.js.map +1 -0
- package/dist/lib/hooks/useBreakpointMatch.js +108 -0
- package/dist/lib/hooks/useBreakpointMatch.js.map +1 -0
- package/dist/lib/hooks/useClick.js +38 -0
- package/dist/lib/hooks/useClick.js.map +1 -0
- package/dist/lib/hooks/useClickOutside.js +31 -0
- package/dist/lib/hooks/useClickOutside.js.map +1 -0
- package/dist/lib/hooks/useFileInput.js +17 -0
- package/dist/lib/hooks/useFileInput.js.map +1 -0
- package/dist/lib/hooks/useIsomorphicEffect.js +7 -0
- package/dist/lib/hooks/useIsomorphicEffect.js.map +1 -0
- package/dist/lib/hooks/useKeydown.js +39 -0
- package/dist/lib/hooks/useKeydown.js.map +1 -0
- package/dist/lib/hooks/useListFocus.js +46 -0
- package/dist/lib/hooks/useListFocus.js.map +1 -0
- package/dist/lib/hooks/useMediaQuery.js +25 -0
- package/dist/lib/hooks/useMediaQuery.js.map +1 -0
- package/dist/lib/hooks/usePageExitBlocker.js +44 -0
- package/dist/lib/hooks/usePageExitBlocker.js.map +1 -0
- package/dist/lib/hooks/usePagination.js +90 -0
- package/dist/lib/hooks/usePagination.js.map +1 -0
- package/dist/lib/hooks/usePopState.js +31 -0
- package/dist/lib/hooks/usePopState.js.map +1 -0
- package/dist/lib/hooks/usePopoverDismiss.js +32 -0
- package/dist/lib/hooks/usePopoverDismiss.js.map +1 -0
- package/dist/lib/hooks/useRefresh.js +67 -0
- package/dist/lib/hooks/useRefresh.js.map +1 -0
- package/dist/lib/hooks/useScrollEffect.js +19 -0
- package/dist/lib/hooks/useScrollEffect.js.map +1 -0
- package/dist/lib/hooks/useSearchParams.js +48 -0
- package/dist/lib/hooks/useSearchParams.js.map +1 -0
- package/dist/lib/hooks/useStaticAnimationStyles.js +16 -0
- package/dist/lib/hooks/useStaticAnimationStyles.js.map +1 -0
- package/dist/lib/hooks/useStylesFor.js +36 -0
- package/dist/lib/hooks/useStylesFor.js.map +1 -0
- package/dist/lib/hooks/useTouchableEvents.js +34 -0
- package/dist/lib/hooks/useTouchableEvents.js.map +1 -0
- package/dist/lib/hooks/useWindowFocus.js +30 -0
- package/dist/lib/hooks/useWindowFocus.js.map +1 -0
- package/dist/lib/hooks/useWindowSize.js +29 -0
- package/dist/lib/hooks/useWindowSize.js.map +1 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/tools/index.js +4 -0
- package/dist/lib/tools/index.js.map +1 -0
- package/dist/lib/tools/localStorage.js +155 -0
- package/dist/lib/tools/localStorage.js.map +1 -0
- package/dist/lib/tools/mediaQuery.js +33 -0
- package/dist/lib/tools/mediaQuery.js.map +1 -0
- package/dist/lib/tools/modal.js +55 -0
- package/dist/lib/tools/modal.js.map +1 -0
- package/dist/lib/utils/attributes.js +23 -0
- package/dist/lib/utils/attributes.js.map +1 -0
- package/dist/lib/utils/cache.js +10 -0
- package/dist/lib/utils/cache.js.map +1 -0
- package/dist/lib/utils/index.js +6 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/pollyfils/scroll.js +66 -0
- package/dist/lib/utils/pollyfils/scroll.js.map +1 -0
- package/dist/lib/utils/stopPropagation.js +19 -0
- package/dist/lib/utils/stopPropagation.js.map +1 -0
- package/dist/lib/utils/test.js +14 -0
- package/dist/lib/utils/test.js.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utility.js +2 -0
- package/dist/types/utility.js.map +1 -0
- package/package.json +18 -18
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks hover and pressed interaction states for a `Touchable`-like element
|
|
4
|
+
* using pointer events. Uses `setPointerCapture` / `releasePointerCapture` so
|
|
5
|
+
* that `isPressed` stays accurate even when the pointer leaves the element
|
|
6
|
+
* while held down. Both states are forced to `false` when `disabled` is `true`.
|
|
7
|
+
*/
|
|
8
|
+
export function useTouchableInteraction(disabled = false) {
|
|
9
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
10
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
11
|
+
return {
|
|
12
|
+
eventHandlers: {
|
|
13
|
+
onPointerEnter: () => setIsHovering(true),
|
|
14
|
+
onPointerLeave: () => {
|
|
15
|
+
setIsHovering(false);
|
|
16
|
+
setIsPressed(false);
|
|
17
|
+
},
|
|
18
|
+
onPointerDown: (e) => {
|
|
19
|
+
setIsPressed(true);
|
|
20
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
21
|
+
},
|
|
22
|
+
onPointerUp: (e) => {
|
|
23
|
+
setIsPressed(false);
|
|
24
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
25
|
+
},
|
|
26
|
+
onPointerCancel: () => {
|
|
27
|
+
setIsPressed(false);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
isHovering: isHovering && !disabled,
|
|
31
|
+
isPressed: isPressed && !disabled,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=useTouchableEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTouchableEvents.js","sourceRoot":"","sources":["../../../src/lib/hooks/useTouchableEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAQ,GAAG,KAAK;IACtD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEjD,OAAO;QACL,aAAa,EAAE;YACb,cAAc,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YAEzC,cAAc,EAAE,GAAG,EAAE;gBACnB,aAAa,CAAC,KAAK,CAAC,CAAA;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAA;YACrB,CAAC;YAED,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE;gBACnB,YAAY,CAAC,IAAI,CAAC,CAAA;gBAClB,CAAC,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;YAChD,CAAC;YAED,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE;gBACjB,YAAY,CAAC,KAAK,CAAC,CAAA;gBACnB,CAAC,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;YACpD,CAAC;YAED,eAAe,EAAE,GAAG,EAAE;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAA;YACrB,CAAC;SACF;QACD,UAAU,EAAE,UAAU,IAAI,CAAC,QAAQ;QACnC,SAAS,EAAE,SAAS,IAAI,CAAC,QAAQ;KAClC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` when the browser window has focus, `false` when it is blurred.
|
|
5
|
+
* Calls `options.onFocus` and `options.onBlur` side-effect callbacks as needed.
|
|
6
|
+
* The listeners are re-registered when `deps` change.
|
|
7
|
+
*/
|
|
8
|
+
export const useWindowFocus = (options = {}, deps = []) => {
|
|
9
|
+
const [focused, setFocused] = useState(true);
|
|
10
|
+
const onFocus = () => {
|
|
11
|
+
setFocused(true);
|
|
12
|
+
if (TypeGuards.isFunction(options?.onFocus))
|
|
13
|
+
options?.onFocus();
|
|
14
|
+
};
|
|
15
|
+
const onBlur = () => {
|
|
16
|
+
setFocused(false);
|
|
17
|
+
if (TypeGuards.isFunction(options?.onBlur))
|
|
18
|
+
options?.onBlur();
|
|
19
|
+
};
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
window.addEventListener('focus', onFocus);
|
|
22
|
+
window.addEventListener('blur', onBlur);
|
|
23
|
+
return () => {
|
|
24
|
+
window.removeEventListener('focus', onFocus);
|
|
25
|
+
window.removeEventListener('blur', onBlur);
|
|
26
|
+
};
|
|
27
|
+
}, deps);
|
|
28
|
+
return focused;
|
|
29
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
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useDebounceCallback } from '@codeleap/hooks';
|
|
2
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Returns `[innerWidth, innerHeight]` and keeps the value in sync with window
|
|
5
|
+
* resize events. When `live` is `false` (default), resize updates are debounced
|
|
6
|
+
* by 300 ms to avoid flooding renders. Pass `live: true` for immediate updates.
|
|
7
|
+
* SSR returns `[1920, 1080]` as a placeholder.
|
|
8
|
+
*/
|
|
9
|
+
export function useWindowSize(live = false) {
|
|
10
|
+
const [size, setSize] = useState(() => {
|
|
11
|
+
if (typeof window === 'undefined')
|
|
12
|
+
return [1920, 1080];
|
|
13
|
+
return [window.innerWidth, window.innerHeight];
|
|
14
|
+
});
|
|
15
|
+
const handler = useCallback(() => {
|
|
16
|
+
setSize([window.innerWidth, window.innerHeight]);
|
|
17
|
+
}, [setSize]);
|
|
18
|
+
const debouncedHandleResize = useDebounceCallback(handler, 300);
|
|
19
|
+
const handleResize = live ? handler : debouncedHandleResize.debounce;
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
handleResize();
|
|
22
|
+
window.addEventListener('resize', handleResize);
|
|
23
|
+
return () => {
|
|
24
|
+
window.removeEventListener('resize', handleResize);
|
|
25
|
+
};
|
|
26
|
+
}, [handleResize]);
|
|
27
|
+
return size;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=useWindowSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWindowSize.js","sourceRoot":"","sources":["../../../src/lib/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGxD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAI,GAAC,KAAK;IACtC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QACpC,IAAG,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,CAAC,IAAI,EAAC,IAAI,CAAC,CAAA;QACpD,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAA;IAClD,CAAC,EAAC,CAAC,OAAO,CAAC,CAAC,CAAA;IAEZ,MAAM,qBAAqB,GAAG,mBAAmB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE/D,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC,QAAQ,CAAA;IAEpE,SAAS,CAAC,GAAG,EAAE;QACb,YAAY,EAAE,CAAA;QAEd,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAE/C,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QACpD,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TypeGuards } from '@codeleap/types';
|
|
3
|
+
/**
|
|
4
|
+
* Type-safe wrapper around `window.localStorage`.
|
|
5
|
+
*
|
|
6
|
+
* Instantiate with a key map (`{ tokenKey: 'auth_token', ... }`) so all reads
|
|
7
|
+
* and writes are validated against the map's keys at compile time. Values are
|
|
8
|
+
* automatically JSON-serialised on write and JSON-parsed on read; strings are
|
|
9
|
+
* stored as-is. Returns safe no-ops when called server-side.
|
|
10
|
+
*
|
|
11
|
+
* Use `use()` to get a React state pair that stays in sync with storage across
|
|
12
|
+
* tabs via the `storage` event.
|
|
13
|
+
*/
|
|
14
|
+
export class LocalStorage {
|
|
15
|
+
storageKeys;
|
|
16
|
+
storageListeners = [];
|
|
17
|
+
constructor(keys) {
|
|
18
|
+
this.storageKeys = keys;
|
|
19
|
+
}
|
|
20
|
+
getLocalStorage() {
|
|
21
|
+
if (typeof window === 'undefined') {
|
|
22
|
+
return {
|
|
23
|
+
getItem: () => null,
|
|
24
|
+
setItem: () => null,
|
|
25
|
+
clear: () => null,
|
|
26
|
+
removeItem: () => null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return localStorage;
|
|
30
|
+
}
|
|
31
|
+
getStorageKey(key) {
|
|
32
|
+
return String(this.storageKeys[key] ?? key);
|
|
33
|
+
}
|
|
34
|
+
parseValue(value) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(value);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
serializeValue(value) {
|
|
43
|
+
if (TypeGuards.isString(value))
|
|
44
|
+
return value;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(value);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
replaceItem(key, value) {
|
|
53
|
+
const storageKey = this.getStorageKey(key);
|
|
54
|
+
const storage = this.getLocalStorage();
|
|
55
|
+
storage.removeItem(storageKey);
|
|
56
|
+
const serializedValue = this.serializeValue(value);
|
|
57
|
+
storage.setItem(storageKey, serializedValue);
|
|
58
|
+
return serializedValue;
|
|
59
|
+
}
|
|
60
|
+
getItem(key, parseValue = true) {
|
|
61
|
+
const storageKey = this.getStorageKey(key);
|
|
62
|
+
const storage = this.getLocalStorage();
|
|
63
|
+
let value = storage.getItem(storageKey);
|
|
64
|
+
if (parseValue) {
|
|
65
|
+
value = this.parseValue(value);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
removeItem(key) {
|
|
70
|
+
const storageKey = this.getStorageKey(key);
|
|
71
|
+
const storage = this.getLocalStorage();
|
|
72
|
+
storage.removeItem(storageKey);
|
|
73
|
+
}
|
|
74
|
+
setItem(key, value) {
|
|
75
|
+
const storageKey = this.getStorageKey(key);
|
|
76
|
+
const storage = this.getLocalStorage();
|
|
77
|
+
const serializedValue = this.serializeValue(value);
|
|
78
|
+
storage.setItem(storageKey, serializedValue);
|
|
79
|
+
return serializedValue;
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
const storage = this.getLocalStorage();
|
|
83
|
+
storage.clear();
|
|
84
|
+
}
|
|
85
|
+
multiSet(keyValuePairs) {
|
|
86
|
+
for (const [key, value] of keyValuePairs) {
|
|
87
|
+
this.setItem(key, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
multiRemove(keys) {
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
this.removeItem(key);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
multiGet(keys) {
|
|
96
|
+
const storage = this.getLocalStorage();
|
|
97
|
+
const values = {};
|
|
98
|
+
for (const key of keys) {
|
|
99
|
+
const storageKey = this.getStorageKey(key);
|
|
100
|
+
const value = storage.getItem(storageKey);
|
|
101
|
+
values[key] = value;
|
|
102
|
+
}
|
|
103
|
+
return values;
|
|
104
|
+
}
|
|
105
|
+
use(key, initialValue = null, options = {}) {
|
|
106
|
+
const { disableListen = false, setItemValueOnMutate = true, getItemValueOnMount = true, parseValueOnGet = true, } = options;
|
|
107
|
+
const [value, _setValue] = useState(() => {
|
|
108
|
+
return getItemValueOnMount ? (this.getItem(key, parseValueOnGet) ?? initialValue) : initialValue;
|
|
109
|
+
});
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const handler = () => {
|
|
112
|
+
let _initialValue = initialValue;
|
|
113
|
+
let storedValue = this.getItem(key, parseValueOnGet);
|
|
114
|
+
if (!TypeGuards.isNil(storedValue) && getItemValueOnMount) {
|
|
115
|
+
_initialValue = this.parseValue(storedValue);
|
|
116
|
+
}
|
|
117
|
+
_setValue(_initialValue);
|
|
118
|
+
};
|
|
119
|
+
handler();
|
|
120
|
+
return disableListen ? null : this.listen(key, handler);
|
|
121
|
+
}, []);
|
|
122
|
+
const setValue = (to) => {
|
|
123
|
+
return _setValue((prev) => {
|
|
124
|
+
let newValue = prev;
|
|
125
|
+
if (!TypeGuards.isFunction(to)) {
|
|
126
|
+
newValue = to;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const fn = to;
|
|
130
|
+
newValue = fn(value);
|
|
131
|
+
}
|
|
132
|
+
if (setItemValueOnMutate) {
|
|
133
|
+
this.setItem(key, newValue);
|
|
134
|
+
}
|
|
135
|
+
return newValue;
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
return [value, setValue];
|
|
139
|
+
}
|
|
140
|
+
listen(key, handler) {
|
|
141
|
+
const trigger = (event) => {
|
|
142
|
+
const storageKey = this.getStorageKey(key);
|
|
143
|
+
if (event?.key === storageKey) {
|
|
144
|
+
handler(key, event, this.parseValue(event?.newValue));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const newLength = this.storageListeners.push(trigger);
|
|
148
|
+
window.addEventListener('storage', trigger);
|
|
149
|
+
return () => {
|
|
150
|
+
this.storageListeners.splice(newLength - 1, 1);
|
|
151
|
+
window.removeEventListener('storage', trigger);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=localStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorage.js","sourceRoot":"","sources":["../../../src/lib/tools/localStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAa5C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAChB,WAAW,CAAG;IAEb,gBAAgB,GAAsC,EAAE,CAAA;IAEhE,YAAY,IAAO;QACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAEM,eAAe;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO;gBACL,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;gBACnB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;gBACnB,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;gBACjB,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI;aAChB,CAAA;QACV,CAAC;QAED,OAAO,YAAY,CAAA;IACrB,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAA;IAC7C,CAAC;IAEO,UAAU,CAAC,KAAU;QAC3B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAA;QACd,CAAC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AChC,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;gBACtB,CAAC;gBAED,IAAI,oBAAoB,EAAE,CAAC;oBACzB,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;gBAC7B,CAAC;gBAED,OAAO,QAAQ,CAAA;YACjB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA;QAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC1B,CAAC;IAEM,MAAM,CAAC,GAAW,EAAE,OAAoC;QAC7D,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;YACtC,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;YAE1C,IAAI,KAAK,EAAE,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;YACvD,CAAC;QACH,CAAC,CAAA;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACrD,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAE3C,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;YAC9C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attaches a `change` listener to a `MediaQueryList` with a fallback to the
|
|
3
|
+
* deprecated `addListener` API for Safari ≤ Catalina. Returns a cleanup
|
|
4
|
+
* function that removes the listener.
|
|
5
|
+
*/
|
|
6
|
+
export function attachMediaListener(query, callback) {
|
|
7
|
+
try {
|
|
8
|
+
query.addEventListener('change', callback);
|
|
9
|
+
return () => query.removeEventListener('change', callback);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
query.addListener(callback);
|
|
13
|
+
return () => query.removeListener(callback);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Strips the `@media screen and ` prefix so the string can be passed to `window.matchMedia`. */
|
|
17
|
+
export function getMediaQuery(query) {
|
|
18
|
+
if (!query)
|
|
19
|
+
return '';
|
|
20
|
+
return query?.trim()?.replace('@media screen and ', '');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Evaluates a media query string synchronously via `window.matchMedia`. Returns
|
|
24
|
+
* `initialValue` on the server or in environments without `matchMedia`.
|
|
25
|
+
*/
|
|
26
|
+
export function isMediaQuery(query, initialValue = false) {
|
|
27
|
+
const media = getMediaQuery(query);
|
|
28
|
+
if (typeof window !== 'undefined' && 'matchMedia' in window) {
|
|
29
|
+
return window.matchMedia(media).matches;
|
|
30
|
+
}
|
|
31
|
+
return initialValue;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=mediaQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaQuery.js","sourceRoot":"","sources":["../../../src/lib/tools/mediaQuery.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAqB,EAAE,QAA4B;IACrF,IAAI,CAAC;QACH,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC1C,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC5D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC3B,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IACrB,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;AACzD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,YAAY,GAAG,KAAK;IAC9D,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;IAElC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;QAC5D,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAA;IACzC,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
import { globalState } from '@codeleap/store';
|
|
3
|
+
const overlapIndex = 99;
|
|
4
|
+
export const modalsState = globalState({ currentModal: null, indexes: {} });
|
|
5
|
+
/**
|
|
6
|
+
* Updates the stacking-order index for a modal in `modalsState`.
|
|
7
|
+
* When a modal becomes invisible its index is reset to `99`; when it becomes
|
|
8
|
+
* visible its index is set above the current highest-indexed modal.
|
|
9
|
+
*/
|
|
10
|
+
export function modalInferIndexes(visible, id) {
|
|
11
|
+
const indexes = { ...modalsState.value?.indexes };
|
|
12
|
+
if (!visible) {
|
|
13
|
+
indexes[id] = overlapIndex;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
let currentIndex = 0;
|
|
17
|
+
for (const key in indexes) {
|
|
18
|
+
if (indexes[key] > currentIndex) {
|
|
19
|
+
currentIndex = indexes[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
indexes[id] = currentIndex + overlapIndex;
|
|
23
|
+
}
|
|
24
|
+
modalsState.set({ indexes });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Locks or unlocks `document.documentElement` body scroll when a modal opens
|
|
28
|
+
* or closes. Tracks which modal holds the scroll lock in `modalsState` so
|
|
29
|
+
* multiple modals do not release each other's lock prematurely. A no-op when a
|
|
30
|
+
* different modal already owns the lock.
|
|
31
|
+
*/
|
|
32
|
+
export function modalScrollLock(to, modalIdentifier) {
|
|
33
|
+
let modalId = modalsState.value?.currentModal;
|
|
34
|
+
const alreadyDifferentOpenedModal = !TypeGuards.isNil(modalId) && modalIdentifier !== modalId;
|
|
35
|
+
if (alreadyDifferentOpenedModal)
|
|
36
|
+
return;
|
|
37
|
+
if (TypeGuards.isNil(modalId) && to === true) {
|
|
38
|
+
modalsState.set({ currentModal: modalIdentifier });
|
|
39
|
+
modalId = modalIdentifier;
|
|
40
|
+
}
|
|
41
|
+
else if (!TypeGuards.isNil(modalId) && to === false) {
|
|
42
|
+
modalsState.set({ currentModal: null });
|
|
43
|
+
}
|
|
44
|
+
const htmlStyle = document?.documentElement?.style;
|
|
45
|
+
if (htmlStyle.overflowX !== 'hidden') {
|
|
46
|
+
htmlStyle.overflowX = 'hidden';
|
|
47
|
+
}
|
|
48
|
+
if (to) {
|
|
49
|
+
htmlStyle.overflowY = 'hidden';
|
|
50
|
+
}
|
|
51
|
+
else if (modalIdentifier === modalId && to === false) {
|
|
52
|
+
htmlStyle.overflowY = 'auto';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.js","sourceRoot":"","sources":["../../../src/lib/tools/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAmE,EAAE,YAAY,EAAE,IA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,GAAG,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,SAAS,GAAG,QAAQ,EAAE,eAAe,EAAE,KAAK,CAAA;IAElD,IAAI,SAAS,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QACrC,SAAS,CAAC,SAAS,GAAG,QAAQ,CAAA;IAChC,CAAC;IAED,IAAI,EAAE,EAAE,CAAC;QACP,SAAS,CAAC,SAAS,GAAG,QAAQ,CAAA;IAChC,CAAC;SAAM,IAAI,eAAe,KAAK,OAAO,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;QACvD,SAAS,CAAC,SAAS,GAAG,MAAM,CAAA;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
const camelToKebabCase = (value) => {
|
|
3
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Converts a record (or array of records) of camelCase attributes into
|
|
7
|
+
* `data-kebab-case` HTML attribute pairs. `null` / `undefined` values are
|
|
8
|
+
* omitted. Multiple records are merged left-to-right; keys are sorted for
|
|
9
|
+
* stable output.
|
|
10
|
+
*/
|
|
11
|
+
export function toDataAttrs(value) {
|
|
12
|
+
const attrList = (Array.isArray(value) ? value : [value]).filter(Boolean);
|
|
13
|
+
const allAttrs = attrList.map(attributeSet => Object.fromEntries(Object
|
|
14
|
+
.entries(attributeSet ?? {})
|
|
15
|
+
.filter(([_, v]) => !TypeGuards.isNil(v))
|
|
16
|
+
.toSorted((a, b) => a[0].localeCompare(b[0]))
|
|
17
|
+
.map(([key, v]) => {
|
|
18
|
+
const normalizedKey = camelToKebabCase(key);
|
|
19
|
+
return [`data-${normalizedKey}`, String(v)];
|
|
20
|
+
})));
|
|
21
|
+
return allAttrs.reduce((acc, obj) => ({ ...acc, ...obj }), {});
|
|
22
|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;IAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAiB,CAAA;AAChF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import createCache from '@emotion/cache';
|
|
2
|
+
/** Creates a new Emotion cache scoped to the `codeleap-web` key. */
|
|
3
|
+
export const createCodeleapWebCache = () => {
|
|
4
|
+
return createCache({
|
|
5
|
+
key: 'codeleap-web',
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
/** Shared Emotion cache instance for the web package. Pass to `CacheProvider` for SSR style extraction. */
|
|
9
|
+
export const codeleapWebCache = createCodeleapWebCache();
|
|
10
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/lib/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAA;AAExC,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,WAAW,CAAC;QACjB,GAAG,EAAE,cAAc;KACpB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,2GAA2G;AAC3G,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// native smooth scrolling for Chrome, Firefox & Opera
|
|
2
|
+
// @see: https://caniuse.com/#feat=css-scroll-behavior
|
|
3
|
+
const nativeSmoothScrollTo = (elem, pad = 0) => {
|
|
4
|
+
if (!window)
|
|
5
|
+
return;
|
|
6
|
+
window.scroll({
|
|
7
|
+
behavior: 'smooth',
|
|
8
|
+
left: 0,
|
|
9
|
+
top: elem.getBoundingClientRect().top + window.pageYOffset + pad,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
// polyfilled smooth scrolling for IE, Edge & Safari
|
|
13
|
+
const smoothScrollTo = (to, duration) => {
|
|
14
|
+
if (!document)
|
|
15
|
+
return;
|
|
16
|
+
const element = document.scrollingElement || document.documentElement, start = element.scrollTop, change = to - start, startDate = +new Date();
|
|
17
|
+
// t = current time
|
|
18
|
+
// b = start value
|
|
19
|
+
// c = change in value
|
|
20
|
+
// d = duration
|
|
21
|
+
const easeInOutQuad = (t, b, c, d) => {
|
|
22
|
+
t /= d / 2;
|
|
23
|
+
if (t < 1)
|
|
24
|
+
return (c / 2) * t * t + b;
|
|
25
|
+
t--;
|
|
26
|
+
return (-c / 2) * (t * (t - 2) - 1) + b;
|
|
27
|
+
};
|
|
28
|
+
const animateScroll = () => {
|
|
29
|
+
const currentDate = +new Date();
|
|
30
|
+
const currentTime = currentDate - startDate;
|
|
31
|
+
element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration));
|
|
32
|
+
if (currentTime < duration) {
|
|
33
|
+
requestAnimationFrame(animateScroll);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
element.scrollTop = to;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
animateScroll();
|
|
40
|
+
};
|
|
41
|
+
// detect support for the behavior property in ScrollOptions
|
|
42
|
+
// smooth scrolling stub
|
|
43
|
+
/**
|
|
44
|
+
* Smooth-scrolls the page to the element matching `elemSelector`. Uses the
|
|
45
|
+
* native `scroll-behavior: smooth` CSS property when supported; falls back to a
|
|
46
|
+
* JS easing animation (easeInOutQuad, 600 ms) for IE / Edge / older Safari.
|
|
47
|
+
* `padOffsets[0]` adds a top offset to the final scroll position.
|
|
48
|
+
*/
|
|
49
|
+
export const scrollToElem = (elemSelector, padOffsets = [0, 0]) => {
|
|
50
|
+
if (!document)
|
|
51
|
+
return;
|
|
52
|
+
const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style || {};
|
|
53
|
+
if (!elemSelector) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const elem = document.querySelector(elemSelector);
|
|
57
|
+
if (elem) {
|
|
58
|
+
if (supportsNativeSmoothScroll) {
|
|
59
|
+
nativeSmoothScrollTo(elem, padOffsets[0]);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
smoothScrollTo(elem.offsetTop + padOffsets[0], 600);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../../src/lib/utils/pollyfils/scroll.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,sDAAsD;AACtD,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAM;IACnB,MAAM,CAAC,MAAM,CAAC;QACZ,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,CAAC;QACP,GAAG,EAAE,IAAI,CAAC,qBAAqB,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,WAAW,GAAG,GAAG;KACjE,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,oDAAoD;AACpD,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE;IACtC,IAAI,CAAC,QAAQ;QAAE,OAAM;IACrB,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,IAAI,QAAQ,CAAC,eAAe,EACnE,KAAK,GAAG,OAAO,CAAC,SAAS,EACzB,MAAM,GAAG,EAAE,GAA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AAI,QAAQ,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAA;IAC1D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAM;IACR,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;IACjD,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,0BAA0B,EAAE,CAAC;YAC/B,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3C,CAAC;aAAM,CAAC;YACN,cAAc,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QACrD,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `stopPropagation`, `preventDefault`, and `stopImmediatePropagation` on
|
|
3
|
+
* an event, swallowing any individual failures. Handles both native DOM events
|
|
4
|
+
* and React synthetic events via `nativeEvent`.
|
|
5
|
+
*/
|
|
6
|
+
export function stopPropagation(event) {
|
|
7
|
+
const tryCalls = [
|
|
8
|
+
event?.stopPropagation.bind(event),
|
|
9
|
+
event?.preventDefault.bind(event),
|
|
10
|
+
event.nativeEvent?.stopImmediatePropagation.bind(event.nativeEvent),
|
|
11
|
+
];
|
|
12
|
+
for (const call of tryCalls) {
|
|
13
|
+
try {
|
|
14
|
+
call();
|
|
15
|
+
}
|
|
16
|
+
catch (e) { }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=stopPropagation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stopPropagation.js","sourceRoot":"","sources":["../../../src/lib/utils/stopPropagation.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAU;IACxC,MAAM,QAAQ,GAAG;QACf,KAAK,EAAE,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC;QAClC,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC;QACjC,KAAK,CAAC,WAAW,EAAE,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAgB;KACnF,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,IAAI,EAAE,CAAA;QACR,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
/**
|
|
3
|
+
* Derives a normalised test identifier from component props. Checks
|
|
4
|
+
* `testId`, `data-testid`, `id`, and `debugName` in that order; spaces are
|
|
5
|
+
* replaced with underscores and the result is lowercased.
|
|
6
|
+
*/
|
|
7
|
+
export const getTestId = (props) => {
|
|
8
|
+
let id = props?.testId || props?.['data-testid'] || props?.id || props?.debugName;
|
|
9
|
+
if (TypeGuards.isString(id)) {
|
|
10
|
+
id = id?.replace(/\s/g, '_').toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
return id;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../../src/lib/utils/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAA0B,EAAE,EAAE;IACtD,IAAI,EAAE,GAAG,KAAK,EAAE,MAAM,IAAI,KAAK,EAAE,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,EAAE,IAAI,KAAK,EAAE,SAAS,CAAA;IAEjF,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5B,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;IAC5C,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/web",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "UNLICENSED",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codeleap/config": "
|
|
26
|
-
"@codeleap/form": "
|
|
27
|
-
"@codeleap/hooks": "
|
|
28
|
-
"@codeleap/logger": "
|
|
29
|
-
"@codeleap/query": "
|
|
30
|
-
"@codeleap/styles": "
|
|
31
|
-
"@codeleap/types": "
|
|
32
|
-
"@codeleap/utils": "
|
|
33
|
-
"@codeleap/store": "
|
|
25
|
+
"@codeleap/config": "7.0.1",
|
|
26
|
+
"@codeleap/form": "7.0.1",
|
|
27
|
+
"@codeleap/hooks": "7.0.1",
|
|
28
|
+
"@codeleap/logger": "7.0.1",
|
|
29
|
+
"@codeleap/query": "7.0.1",
|
|
30
|
+
"@codeleap/styles": "7.0.1",
|
|
31
|
+
"@codeleap/types": "7.0.1",
|
|
32
|
+
"@codeleap/utils": "7.0.1",
|
|
33
|
+
"@codeleap/store": "7.0.1",
|
|
34
34
|
"@tanstack/react-query": "5.100.9"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"uuid": "13.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@codeleap/types": "
|
|
64
|
-
"@codeleap/utils": "
|
|
65
|
-
"@codeleap/hooks": "
|
|
66
|
-
"@codeleap/query": "
|
|
67
|
-
"@codeleap/logger": "
|
|
68
|
-
"@codeleap/styles": "
|
|
69
|
-
"@codeleap/store": "
|
|
63
|
+
"@codeleap/types": "7.0.1",
|
|
64
|
+
"@codeleap/utils": "7.0.1",
|
|
65
|
+
"@codeleap/hooks": "7.0.1",
|
|
66
|
+
"@codeleap/query": "7.0.1",
|
|
67
|
+
"@codeleap/logger": "7.0.1",
|
|
68
|
+
"@codeleap/styles": "7.0.1",
|
|
69
|
+
"@codeleap/store": "7.0.1",
|
|
70
70
|
"@emotion/react": "11.14.0",
|
|
71
71
|
"@reach/router": "^1.3.4",
|
|
72
72
|
"dayjs": "1.11.18",
|