@contember/react-utils 2.1.0-alpha.37 → 2.1.0-alpha.39
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/development/index.cjs +86 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +86 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/context/createContext.cjs +10 -0
- package/dist/development/src/context/createContext.cjs.map +1 -0
- package/dist/development/src/context/createContext.js +10 -0
- package/dist/development/src/context/createContext.js.map +1 -0
- package/dist/development/src/context/createRequiredContext.cjs +18 -0
- package/dist/development/src/context/createRequiredContext.cjs.map +1 -0
- package/dist/development/src/context/createRequiredContext.js +18 -0
- package/dist/development/src/context/createRequiredContext.js.map +1 -0
- package/dist/development/src/debug-context/Constants.cjs +25 -0
- package/dist/development/src/debug-context/Constants.cjs.map +1 -0
- package/dist/development/src/debug-context/Constants.js +25 -0
- package/dist/development/src/debug-context/Constants.js.map +1 -0
- package/dist/development/src/debug-context/Context.cjs +72 -0
- package/dist/development/src/debug-context/Context.cjs.map +1 -0
- package/dist/development/src/debug-context/Context.js +72 -0
- package/dist/development/src/debug-context/Context.js.map +1 -0
- package/dist/development/src/hooks/unwrapRefValue.cjs +11 -0
- package/dist/development/src/hooks/unwrapRefValue.cjs.map +1 -0
- package/dist/development/src/hooks/unwrapRefValue.js +11 -0
- package/dist/development/src/hooks/unwrapRefValue.js.map +1 -0
- package/dist/development/src/hooks/useAbortController.cjs +17 -0
- package/dist/development/src/hooks/useAbortController.cjs.map +1 -0
- package/dist/development/src/hooks/useAbortController.js +17 -0
- package/dist/development/src/hooks/useAbortController.js.map +1 -0
- package/dist/development/src/hooks/useArrayMapMemo.cjs +11 -0
- package/dist/development/src/hooks/useArrayMapMemo.cjs.map +1 -0
- package/dist/development/src/hooks/useArrayMapMemo.js +11 -0
- package/dist/development/src/hooks/useArrayMapMemo.js.map +1 -0
- package/dist/development/src/hooks/useAutoHeightTextArea.cjs +43 -0
- package/dist/development/src/hooks/useAutoHeightTextArea.cjs.map +1 -0
- package/dist/development/src/hooks/useAutoHeightTextArea.js +43 -0
- package/dist/development/src/hooks/useAutoHeightTextArea.js.map +1 -0
- package/dist/development/src/hooks/useChildrenAsLabel.cjs +53 -0
- package/dist/development/src/hooks/useChildrenAsLabel.cjs.map +1 -0
- package/dist/development/src/hooks/useChildrenAsLabel.js +53 -0
- package/dist/development/src/hooks/useChildrenAsLabel.js.map +1 -0
- package/dist/development/src/hooks/useComposeRef.cjs +31 -0
- package/dist/development/src/hooks/useComposeRef.cjs.map +1 -0
- package/dist/development/src/hooks/useComposeRef.js +31 -0
- package/dist/development/src/hooks/useComposeRef.js.map +1 -0
- package/dist/development/src/hooks/useConstantLengthInvariant.cjs +15 -0
- package/dist/development/src/hooks/useConstantLengthInvariant.cjs.map +1 -0
- package/dist/development/src/hooks/useConstantLengthInvariant.js +15 -0
- package/dist/development/src/hooks/useConstantLengthInvariant.js.map +1 -0
- package/dist/development/src/hooks/useConstantValueInvariant.cjs +15 -0
- package/dist/development/src/hooks/useConstantValueInvariant.cjs.map +1 -0
- package/dist/development/src/hooks/useConstantValueInvariant.js +15 -0
- package/dist/development/src/hooks/useConstantValueInvariant.js.map +1 -0
- package/dist/development/src/hooks/useDebounce.cjs +15 -0
- package/dist/development/src/hooks/useDebounce.cjs.map +1 -0
- package/dist/development/src/hooks/useDebounce.js +15 -0
- package/dist/development/src/hooks/useDebounce.js.map +1 -0
- package/dist/development/src/hooks/useDebounceCallback.cjs +19 -0
- package/dist/development/src/hooks/useDebounceCallback.cjs.map +1 -0
- package/dist/development/src/hooks/useDebounceCallback.js +19 -0
- package/dist/development/src/hooks/useDebounceCallback.js.map +1 -0
- package/dist/development/src/hooks/useDocumentTitle.cjs +22 -0
- package/dist/development/src/hooks/useDocumentTitle.cjs.map +1 -0
- package/dist/development/src/hooks/useDocumentTitle.js +22 -0
- package/dist/development/src/hooks/useDocumentTitle.js.map +1 -0
- package/dist/development/src/hooks/useExpectSameValueReference.cjs +24 -0
- package/dist/development/src/hooks/useExpectSameValueReference.cjs.map +1 -0
- package/dist/development/src/hooks/useExpectSameValueReference.js +24 -0
- package/dist/development/src/hooks/useExpectSameValueReference.js.map +1 -0
- package/dist/development/src/hooks/useForceRender.cjs +9 -0
- package/dist/development/src/hooks/useForceRender.cjs.map +1 -0
- package/dist/development/src/hooks/useForceRender.js +9 -0
- package/dist/development/src/hooks/useForceRender.js.map +1 -0
- package/dist/development/src/hooks/useId.cjs +13 -0
- package/dist/development/src/hooks/useId.cjs.map +1 -0
- package/dist/development/src/hooks/useId.js +13 -0
- package/dist/development/src/hooks/useId.js.map +1 -0
- package/dist/development/src/hooks/useIsMounted.cjs +18 -0
- package/dist/development/src/hooks/useIsMounted.cjs.map +1 -0
- package/dist/development/src/hooks/useIsMounted.js +18 -0
- package/dist/development/src/hooks/useIsMounted.js.map +1 -0
- package/dist/development/src/hooks/useObjectMemo.cjs +27 -0
- package/dist/development/src/hooks/useObjectMemo.cjs.map +1 -0
- package/dist/development/src/hooks/useObjectMemo.js +27 -0
- package/dist/development/src/hooks/useObjectMemo.js.map +1 -0
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.cjs +20 -0
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.js +20 -0
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.js.map +1 -0
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
- package/dist/development/src/hooks/useOnElementResize.cjs +42 -0
- package/dist/development/src/hooks/useOnElementResize.cjs.map +1 -0
- package/dist/development/src/hooks/useOnElementResize.js +42 -0
- package/dist/development/src/hooks/useOnElementResize.js.map +1 -0
- package/dist/development/src/hooks/useOnWindowResize.cjs +36 -0
- package/dist/development/src/hooks/useOnWindowResize.cjs.map +1 -0
- package/dist/development/src/hooks/useOnWindowResize.js +36 -0
- package/dist/development/src/hooks/useOnWindowResize.js.map +1 -0
- package/dist/development/src/hooks/usePreviousValue.cjs +12 -0
- package/dist/development/src/hooks/usePreviousValue.cjs.map +1 -0
- package/dist/development/src/hooks/usePreviousValue.js +12 -0
- package/dist/development/src/hooks/usePreviousValue.js.map +1 -0
- package/dist/development/src/hooks/useStoredState.cjs +100 -0
- package/dist/development/src/hooks/useStoredState.cjs.map +1 -0
- package/dist/development/src/hooks/useStoredState.js +100 -0
- package/dist/development/src/hooks/useStoredState.js.map +1 -0
- package/dist/development/src/hooks/useUpdatedRef.cjs +10 -0
- package/dist/development/src/hooks/useUpdatedRef.cjs.map +1 -0
- package/dist/development/src/hooks/useUpdatedRef.js +10 -0
- package/dist/development/src/hooks/useUpdatedRef.js.map +1 -0
- package/dist/development/src/hooks/useWindowSize.cjs +20 -0
- package/dist/development/src/hooks/useWindowSize.cjs.map +1 -0
- package/dist/development/src/hooks/useWindowSize.js +20 -0
- package/dist/development/src/hooks/useWindowSize.js.map +1 -0
- package/dist/development/src/referentiallyStable/emptyArray.cjs +5 -0
- package/dist/development/src/referentiallyStable/emptyArray.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/emptyArray.js +5 -0
- package/dist/development/src/referentiallyStable/emptyArray.js.map +1 -0
- package/dist/development/src/referentiallyStable/emptyObject.cjs +5 -0
- package/dist/development/src/referentiallyStable/emptyObject.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/emptyObject.js +5 -0
- package/dist/development/src/referentiallyStable/emptyObject.js.map +1 -0
- package/dist/development/src/referentiallyStable/identityFunction.cjs +5 -0
- package/dist/development/src/referentiallyStable/identityFunction.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/identityFunction.js +5 -0
- package/dist/development/src/referentiallyStable/identityFunction.js.map +1 -0
- package/dist/development/src/referentiallyStable/noop.cjs +5 -0
- package/dist/development/src/referentiallyStable/noop.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/noop.js +5 -0
- package/dist/development/src/referentiallyStable/noop.js.map +1 -0
- package/dist/development/src/referentiallyStable/returnFalse.cjs +5 -0
- package/dist/development/src/referentiallyStable/returnFalse.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/returnFalse.js +5 -0
- package/dist/development/src/referentiallyStable/returnFalse.js.map +1 -0
- package/dist/development/src/referentiallyStable/returnTrue.cjs +5 -0
- package/dist/development/src/referentiallyStable/returnTrue.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/returnTrue.js +5 -0
- package/dist/development/src/referentiallyStable/returnTrue.js.map +1 -0
- package/dist/development/src/referentiallyStable/useReferentiallyStableCallback.cjs +15 -0
- package/dist/development/src/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
- package/dist/development/src/referentiallyStable/useReferentiallyStableCallback.js +15 -0
- package/dist/development/src/referentiallyStable/useReferentiallyStableCallback.js.map +1 -0
- package/dist/production/index.cjs +86 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +86 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/context/createContext.cjs +10 -0
- package/dist/production/src/context/createContext.cjs.map +1 -0
- package/dist/production/src/context/createContext.js +10 -0
- package/dist/production/src/context/createContext.js.map +1 -0
- package/dist/production/src/context/createRequiredContext.cjs +18 -0
- package/dist/production/src/context/createRequiredContext.cjs.map +1 -0
- package/dist/production/src/context/createRequiredContext.js +18 -0
- package/dist/production/src/context/createRequiredContext.js.map +1 -0
- package/dist/production/src/debug-context/Constants.cjs +25 -0
- package/dist/production/src/debug-context/Constants.cjs.map +1 -0
- package/dist/production/src/debug-context/Constants.js +25 -0
- package/dist/production/src/debug-context/Constants.js.map +1 -0
- package/dist/production/src/debug-context/Context.cjs +68 -0
- package/dist/production/src/debug-context/Context.cjs.map +1 -0
- package/dist/production/src/debug-context/Context.js +68 -0
- package/dist/production/src/debug-context/Context.js.map +1 -0
- package/dist/production/src/hooks/unwrapRefValue.cjs +11 -0
- package/dist/production/src/hooks/unwrapRefValue.cjs.map +1 -0
- package/dist/production/src/hooks/unwrapRefValue.js +11 -0
- package/dist/production/src/hooks/unwrapRefValue.js.map +1 -0
- package/dist/production/src/hooks/useAbortController.cjs +17 -0
- package/dist/production/src/hooks/useAbortController.cjs.map +1 -0
- package/dist/production/src/hooks/useAbortController.js +17 -0
- package/dist/production/src/hooks/useAbortController.js.map +1 -0
- package/dist/production/src/hooks/useArrayMapMemo.cjs +9 -0
- package/dist/production/src/hooks/useArrayMapMemo.cjs.map +1 -0
- package/dist/production/src/hooks/useArrayMapMemo.js +9 -0
- package/dist/production/src/hooks/useArrayMapMemo.js.map +1 -0
- package/dist/production/src/hooks/useAutoHeightTextArea.cjs +43 -0
- package/dist/production/src/hooks/useAutoHeightTextArea.cjs.map +1 -0
- package/dist/production/src/hooks/useAutoHeightTextArea.js +43 -0
- package/dist/production/src/hooks/useAutoHeightTextArea.js.map +1 -0
- package/dist/production/src/hooks/useChildrenAsLabel.cjs +51 -0
- package/dist/production/src/hooks/useChildrenAsLabel.cjs.map +1 -0
- package/dist/production/src/hooks/useChildrenAsLabel.js +51 -0
- package/dist/production/src/hooks/useChildrenAsLabel.js.map +1 -0
- package/dist/production/src/hooks/useComposeRef.cjs +31 -0
- package/dist/production/src/hooks/useComposeRef.cjs.map +1 -0
- package/dist/production/src/hooks/useComposeRef.js +31 -0
- package/dist/production/src/hooks/useComposeRef.js.map +1 -0
- package/dist/production/src/hooks/useConstantLengthInvariant.cjs +6 -0
- package/dist/production/src/hooks/useConstantLengthInvariant.cjs.map +1 -0
- package/dist/production/src/hooks/useConstantLengthInvariant.js +6 -0
- package/dist/production/src/hooks/useConstantLengthInvariant.js.map +1 -0
- package/dist/production/src/hooks/useConstantValueInvariant.cjs +6 -0
- package/dist/production/src/hooks/useConstantValueInvariant.cjs.map +1 -0
- package/dist/production/src/hooks/useConstantValueInvariant.js +6 -0
- package/dist/production/src/hooks/useConstantValueInvariant.js.map +1 -0
- package/dist/production/src/hooks/useDebounce.cjs +15 -0
- package/dist/production/src/hooks/useDebounce.cjs.map +1 -0
- package/dist/production/src/hooks/useDebounce.js +15 -0
- package/dist/production/src/hooks/useDebounce.js.map +1 -0
- package/dist/production/src/hooks/useDebounceCallback.cjs +19 -0
- package/dist/production/src/hooks/useDebounceCallback.cjs.map +1 -0
- package/dist/production/src/hooks/useDebounceCallback.js +19 -0
- package/dist/production/src/hooks/useDebounceCallback.js.map +1 -0
- package/dist/production/src/hooks/useDocumentTitle.cjs +22 -0
- package/dist/production/src/hooks/useDocumentTitle.cjs.map +1 -0
- package/dist/production/src/hooks/useDocumentTitle.js +22 -0
- package/dist/production/src/hooks/useDocumentTitle.js.map +1 -0
- package/dist/production/src/hooks/useExpectSameValueReference.cjs +15 -0
- package/dist/production/src/hooks/useExpectSameValueReference.cjs.map +1 -0
- package/dist/production/src/hooks/useExpectSameValueReference.js +15 -0
- package/dist/production/src/hooks/useExpectSameValueReference.js.map +1 -0
- package/dist/production/src/hooks/useForceRender.cjs +9 -0
- package/dist/production/src/hooks/useForceRender.cjs.map +1 -0
- package/dist/production/src/hooks/useForceRender.js +9 -0
- package/dist/production/src/hooks/useForceRender.js.map +1 -0
- package/dist/production/src/hooks/useId.cjs +13 -0
- package/dist/production/src/hooks/useId.cjs.map +1 -0
- package/dist/production/src/hooks/useId.js +13 -0
- package/dist/production/src/hooks/useId.js.map +1 -0
- package/dist/production/src/hooks/useIsMounted.cjs +18 -0
- package/dist/production/src/hooks/useIsMounted.cjs.map +1 -0
- package/dist/production/src/hooks/useIsMounted.js +18 -0
- package/dist/production/src/hooks/useIsMounted.js.map +1 -0
- package/dist/production/src/hooks/useObjectMemo.cjs +27 -0
- package/dist/production/src/hooks/useObjectMemo.cjs.map +1 -0
- package/dist/production/src/hooks/useObjectMemo.js +27 -0
- package/dist/production/src/hooks/useObjectMemo.js.map +1 -0
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.cjs +20 -0
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.js +20 -0
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.js.map +1 -0
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
- package/dist/production/src/hooks/useOnElementResize.cjs +42 -0
- package/dist/production/src/hooks/useOnElementResize.cjs.map +1 -0
- package/dist/production/src/hooks/useOnElementResize.js +42 -0
- package/dist/production/src/hooks/useOnElementResize.js.map +1 -0
- package/dist/production/src/hooks/useOnWindowResize.cjs +36 -0
- package/dist/production/src/hooks/useOnWindowResize.cjs.map +1 -0
- package/dist/production/src/hooks/useOnWindowResize.js +36 -0
- package/dist/production/src/hooks/useOnWindowResize.js.map +1 -0
- package/dist/production/src/hooks/usePreviousValue.cjs +12 -0
- package/dist/production/src/hooks/usePreviousValue.cjs.map +1 -0
- package/dist/production/src/hooks/usePreviousValue.js +12 -0
- package/dist/production/src/hooks/usePreviousValue.js.map +1 -0
- package/dist/production/src/hooks/useStoredState.cjs +100 -0
- package/dist/production/src/hooks/useStoredState.cjs.map +1 -0
- package/dist/production/src/hooks/useStoredState.js +100 -0
- package/dist/production/src/hooks/useStoredState.js.map +1 -0
- package/dist/production/src/hooks/useUpdatedRef.cjs +10 -0
- package/dist/production/src/hooks/useUpdatedRef.cjs.map +1 -0
- package/dist/production/src/hooks/useUpdatedRef.js +10 -0
- package/dist/production/src/hooks/useUpdatedRef.js.map +1 -0
- package/dist/production/src/hooks/useWindowSize.cjs +20 -0
- package/dist/production/src/hooks/useWindowSize.cjs.map +1 -0
- package/dist/production/src/hooks/useWindowSize.js +20 -0
- package/dist/production/src/hooks/useWindowSize.js.map +1 -0
- package/dist/production/src/referentiallyStable/emptyArray.cjs +5 -0
- package/dist/production/src/referentiallyStable/emptyArray.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/emptyArray.js +5 -0
- package/dist/production/src/referentiallyStable/emptyArray.js.map +1 -0
- package/dist/production/src/referentiallyStable/emptyObject.cjs +5 -0
- package/dist/production/src/referentiallyStable/emptyObject.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/emptyObject.js +5 -0
- package/dist/production/src/referentiallyStable/emptyObject.js.map +1 -0
- package/dist/production/src/referentiallyStable/identityFunction.cjs +5 -0
- package/dist/production/src/referentiallyStable/identityFunction.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/identityFunction.js +5 -0
- package/dist/production/src/referentiallyStable/identityFunction.js.map +1 -0
- package/dist/production/src/referentiallyStable/noop.cjs +5 -0
- package/dist/production/src/referentiallyStable/noop.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/noop.js +5 -0
- package/dist/production/src/referentiallyStable/noop.js.map +1 -0
- package/dist/production/src/referentiallyStable/returnFalse.cjs +5 -0
- package/dist/production/src/referentiallyStable/returnFalse.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/returnFalse.js +5 -0
- package/dist/production/src/referentiallyStable/returnFalse.js.map +1 -0
- package/dist/production/src/referentiallyStable/returnTrue.cjs +5 -0
- package/dist/production/src/referentiallyStable/returnTrue.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/returnTrue.js +5 -0
- package/dist/production/src/referentiallyStable/returnTrue.js.map +1 -0
- package/dist/production/src/referentiallyStable/useReferentiallyStableCallback.cjs +15 -0
- package/dist/production/src/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
- package/dist/production/src/referentiallyStable/useReferentiallyStableCallback.js +15 -0
- package/dist/production/src/referentiallyStable/useReferentiallyStableCallback.js.map +1 -0
- package/dist/types/context/createContext.d.ts +3 -0
- package/dist/types/context/createContext.d.ts.map +1 -0
- package/dist/types/context/createRequiredContext.d.ts +3 -0
- package/dist/types/context/createRequiredContext.d.ts.map +1 -0
- package/dist/types/context/index.d.ts +3 -0
- package/dist/types/context/index.d.ts.map +1 -0
- package/dist/types/debug-context/Constants.d.ts +6 -0
- package/dist/types/debug-context/Constants.d.ts.map +1 -0
- package/dist/types/debug-context/Context.d.ts +15 -0
- package/dist/types/debug-context/Context.d.ts.map +1 -0
- package/dist/types/debug-context/Types.d.ts +13 -0
- package/dist/types/debug-context/Types.d.ts.map +1 -0
- package/dist/types/debug-context/index.d.ts +4 -0
- package/dist/types/debug-context/index.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +25 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/unwrapRefValue.d.ts +9 -0
- package/dist/types/hooks/unwrapRefValue.d.ts.map +1 -0
- package/dist/types/hooks/useAbortController.d.ts +2 -0
- package/dist/types/hooks/useAbortController.d.ts.map +1 -0
- package/dist/types/hooks/useArrayMapMemo.d.ts +10 -0
- package/dist/types/hooks/useArrayMapMemo.d.ts.map +1 -0
- package/dist/types/hooks/useAutoHeightTextArea.d.ts +3 -0
- package/dist/types/hooks/useAutoHeightTextArea.d.ts.map +1 -0
- package/dist/types/hooks/useChildrenAsLabel.d.ts +16 -0
- package/dist/types/hooks/useChildrenAsLabel.d.ts.map +1 -0
- package/dist/types/hooks/useComposeRef.d.ts +16 -0
- package/dist/types/hooks/useComposeRef.d.ts.map +1 -0
- package/dist/types/hooks/useConstantLengthInvariant.d.ts +2 -0
- package/dist/types/hooks/useConstantLengthInvariant.d.ts.map +1 -0
- package/dist/types/hooks/useConstantValueInvariant.d.ts +2 -0
- package/dist/types/hooks/useConstantValueInvariant.d.ts.map +1 -0
- package/dist/types/hooks/useDebounce.d.ts +2 -0
- package/dist/types/hooks/useDebounce.d.ts.map +1 -0
- package/dist/types/hooks/useDebounceCallback.d.ts +2 -0
- package/dist/types/hooks/useDebounceCallback.d.ts.map +1 -0
- package/dist/types/hooks/useDocumentTitle.d.ts +2 -0
- package/dist/types/hooks/useDocumentTitle.d.ts.map +1 -0
- package/dist/types/hooks/useExpectSameValueReference.d.ts +24 -0
- package/dist/types/hooks/useExpectSameValueReference.d.ts.map +1 -0
- package/dist/types/hooks/useForceRender.d.ts +2 -0
- package/dist/types/hooks/useForceRender.d.ts.map +1 -0
- package/dist/types/hooks/useId.d.ts +10 -0
- package/dist/types/hooks/useId.d.ts.map +1 -0
- package/dist/types/hooks/useIsMounted.d.ts +2 -0
- package/dist/types/hooks/useIsMounted.d.ts.map +1 -0
- package/dist/types/hooks/useObjectMemo.d.ts +2 -0
- package/dist/types/hooks/useObjectMemo.d.ts.map +1 -0
- package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts +3 -0
- package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts.map +1 -0
- package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts +14 -0
- package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts.map +1 -0
- package/dist/types/hooks/useOnElementResize.d.ts +3 -0
- package/dist/types/hooks/useOnElementResize.d.ts.map +1 -0
- package/dist/types/hooks/useOnWindowResize.d.ts +2 -0
- package/dist/types/hooks/useOnWindowResize.d.ts.map +1 -0
- package/dist/types/hooks/usePreviousValue.d.ts +2 -0
- package/dist/types/hooks/usePreviousValue.d.ts.map +1 -0
- package/dist/types/hooks/useStoredState.d.ts +18 -0
- package/dist/types/hooks/useStoredState.d.ts.map +1 -0
- package/dist/types/hooks/useUpdatedRef.d.ts +8 -0
- package/dist/types/hooks/useUpdatedRef.d.ts.map +1 -0
- package/dist/types/hooks/useWindowSize.d.ts +5 -0
- package/dist/types/hooks/useWindowSize.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/referentiallyStable/emptyArray.d.ts +2 -0
- package/dist/types/referentiallyStable/emptyArray.d.ts.map +1 -0
- package/dist/types/referentiallyStable/emptyObject.d.ts +2 -0
- package/dist/types/referentiallyStable/emptyObject.d.ts.map +1 -0
- package/dist/types/referentiallyStable/identityFunction.d.ts +2 -0
- package/dist/types/referentiallyStable/identityFunction.d.ts.map +1 -0
- package/dist/types/referentiallyStable/index.d.ts +8 -0
- package/dist/types/referentiallyStable/index.d.ts.map +1 -0
- package/dist/types/referentiallyStable/noop.d.ts +2 -0
- package/dist/types/referentiallyStable/noop.d.ts.map +1 -0
- package/dist/types/referentiallyStable/returnFalse.d.ts +2 -0
- package/dist/types/referentiallyStable/returnFalse.d.ts.map +1 -0
- package/dist/types/referentiallyStable/returnTrue.d.ts +2 -0
- package/dist/types/referentiallyStable/returnTrue.d.ts.map +1 -0
- package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts +3 -0
- package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/PropsWithRequiredChildren.d.ts +5 -0
- package/dist/types/types/PropsWithRequiredChildren.d.ts.map +1 -0
- package/dist/types/types/Serializable.d.ts +4 -0
- package/dist/types/types/Serializable.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
const compareObjects = (a, b) => {
|
|
3
|
+
if (a === b) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
const aEntries = Object.entries(a);
|
|
7
|
+
if (aEntries.length !== Object.keys(b).length) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
for (const [key, val] of aEntries) {
|
|
11
|
+
if (!(key in b) || b[key] !== val) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
const useObjectMemo = (value) => {
|
|
18
|
+
const valueRef = useRef(value);
|
|
19
|
+
if (!compareObjects(valueRef.current, value)) {
|
|
20
|
+
valueRef.current = value;
|
|
21
|
+
}
|
|
22
|
+
return valueRef.current;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
useObjectMemo
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useObjectMemo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectMemo.js","sources":["../../../../../packages/react-utils/src/hooks/useObjectMemo.ts"],"sourcesContent":["import { useRef } from 'react'\n\nconst compareObjects = (a: object, b: object): boolean => {\n\tif (a === b) {\n\t\treturn true\n\t}\n\tconst aEntries = Object.entries(a)\n\tif (aEntries.length !== Object.keys(b).length) {\n\t\treturn false\n\t}\n\tfor (const [key, val] of aEntries) {\n\t\tif (!(key in b) || (b as any)[key] !== val) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nexport const useObjectMemo = <A extends object>(value: A): A => {\n\tconst valueRef = useRef(value)\n\tif (!compareObjects(valueRef.current, value)) {\n\t\tvalueRef.current = value\n\t}\n\treturn valueRef.current\n}\n"],"names":[],"mappings":";AAEA,MAAM,iBAAiB,CAAC,GAAW,MAAuB;AACzD,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AACA,QAAM,WAAW,OAAO,QAAQ,CAAC;AACjC,MAAI,SAAS,WAAW,OAAO,KAAK,CAAC,EAAE,QAAQ;AAC9C,WAAO;AAAA,EACR;AACA,aAAW,CAAC,KAAK,GAAG,KAAK,UAAU;AAClC,QAAI,EAAE,OAAO,MAAO,EAAU,GAAG,MAAM,KAAK;AAC3C,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;AAEO,MAAM,gBAAgB,CAAmB,UAAgB;AAC/D,QAAM,WAAW,OAAO,KAAK;AAC7B,MAAI,CAAC,eAAe,SAAS,SAAS,KAAK,GAAG;AAC7C,aAAS,UAAU;AAAA,EACpB;AACA,SAAO,SAAS;AACjB;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const unwrapRefValue = require("./unwrapRefValue.cjs");
|
|
5
|
+
function useOnElementClickOutsideCallback(refOrElement, callback) {
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
const refValue = unwrapRefValue.unwrapRefValue(refOrElement);
|
|
8
|
+
const handleClickOutside = (event) => {
|
|
9
|
+
if (refValue && !refValue.contains(event.target)) {
|
|
10
|
+
callback(event);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
14
|
+
return () => {
|
|
15
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
16
|
+
};
|
|
17
|
+
}, [callback, refOrElement]);
|
|
18
|
+
}
|
|
19
|
+
exports.useOnElementClickOutsideCallback = useOnElementClickOutsideCallback;
|
|
20
|
+
//# sourceMappingURL=useOnElementClickOutsideCallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementClickOutsideCallback.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementClickOutsideCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (refValue && !refValue.contains(event.target as Node)) {\n\t\t\t\tcallback(event)\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('mousedown', handleClickOutside)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', handleClickOutside)\n\t\t}\n\t}, [callback, refOrElement])\n}\n"],"names":["useEffect","unwrapRefValue"],"mappings":";;;;AAGO,SAAS,iCACf,cACA,UACO;AACPA,QAAAA,UAAU,MAAM;AACf,UAAM,WAAWC,eAAAA,eAAe,YAAY;AAE5C,UAAM,qBAAqB,CAAC,UAAsB;AACjD,UAAI,YAAY,CAAC,SAAS,SAAS,MAAM,MAAc,GAAG;AACzD,iBAAS,KAAK;AAAA,MACf;AAAA,IACD;AAEA,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AACZ,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAC7D;AAAA,EACD,GAAG,CAAC,UAAU,YAAY,CAAC;AAC5B;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { unwrapRefValue } from "./unwrapRefValue.js";
|
|
3
|
+
function useOnElementClickOutsideCallback(refOrElement, callback) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const refValue = unwrapRefValue(refOrElement);
|
|
6
|
+
const handleClickOutside = (event) => {
|
|
7
|
+
if (refValue && !refValue.contains(event.target)) {
|
|
8
|
+
callback(event);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
12
|
+
return () => {
|
|
13
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
14
|
+
};
|
|
15
|
+
}, [callback, refOrElement]);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useOnElementClickOutsideCallback
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useOnElementClickOutsideCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementClickOutsideCallback.js","sources":["../../../../../packages/react-utils/src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementClickOutsideCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (refValue && !refValue.contains(event.target as Node)) {\n\t\t\t\tcallback(event)\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('mousedown', handleClickOutside)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', handleClickOutside)\n\t\t}\n\t}, [callback, refOrElement])\n}\n"],"names":[],"mappings":";;AAGO,SAAS,iCACf,cACA,UACO;AACP,YAAU,MAAM;AACf,UAAM,WAAW,eAAe,YAAY;AAE5C,UAAM,qBAAqB,CAAC,UAAsB;AACjD,UAAI,YAAY,CAAC,SAAS,SAAS,MAAM,MAAc,GAAG;AACzD,iBAAS,KAAK;AAAA,MACf;AAAA,IACD;AAEA,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AACZ,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAC7D;AAAA,EACD,GAAG,CAAC,UAAU,YAAY,CAAC;AAC5B;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const unwrapRefValue = require("./unwrapRefValue.cjs");
|
|
5
|
+
function useOnElementMouseEnterDelayedCallback(refOrElement, callback, timeoutMs = 300) {
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
const refValue = unwrapRefValue.unwrapRefValue(refOrElement);
|
|
8
|
+
if (refValue) {
|
|
9
|
+
let handleMouseEnter = function(event) {
|
|
10
|
+
clearTimeout(timeoutID);
|
|
11
|
+
timeoutID = setTimeout(() => {
|
|
12
|
+
callback(event);
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
}, handleMouseLeave = function() {
|
|
15
|
+
clearTimeout(timeoutID);
|
|
16
|
+
}, handleMouseDown = function(event) {
|
|
17
|
+
clearTimeout(timeoutID);
|
|
18
|
+
callback(event);
|
|
19
|
+
};
|
|
20
|
+
let timeoutID;
|
|
21
|
+
refValue.addEventListener("mouseenter", handleMouseEnter);
|
|
22
|
+
refValue.addEventListener("mouseleave", handleMouseLeave);
|
|
23
|
+
refValue.addEventListener("mousedown", handleMouseDown);
|
|
24
|
+
return () => {
|
|
25
|
+
refValue.removeEventListener("mouseover", handleMouseEnter);
|
|
26
|
+
refValue.removeEventListener("mouseleave", handleMouseLeave);
|
|
27
|
+
refValue.removeEventListener("mousedown", handleMouseDown);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}, [callback, refOrElement, timeoutMs]);
|
|
31
|
+
}
|
|
32
|
+
exports.useOnElementMouseEnterDelayedCallback = useOnElementMouseEnterDelayedCallback;
|
|
33
|
+
//# sourceMappingURL=useOnElementMouseEnterDelayedCallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Calls the callback when the mouse enters the element, but only after a timeout, e.g. for tooltips or dropdown menus.\n *\n * Calls the callback immediately if the mouse is pressed down with `event.type` of `mousedown`. This is useful for\n * dropdown menus, where the user may click on the menu item before the callback is called resulting in the menu\n * opening and closing immediately.\n *\n * @param refOrElement - The element or ref to the element to attach the event listener to.\n * @param callback - The callback to call when the mouse enters the element.\n * @param timeoutMs - The timeout in milliseconds to wait before calling the callback.\n */\nexport function useOnElementMouseEnterDelayedCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n\ttimeoutMs: number = 300,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tif (refValue) {\n\t\t\tlet timeoutID: ReturnType<typeof setTimeout> | undefined\n\n\t\t\tfunction handleMouseEnter(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tcallback(event)\n\t\t\t\t}, timeoutMs)\n\t\t\t}\n\n\t\t\tfunction handleMouseLeave() {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t}\n\n\t\t\tfunction handleMouseDown(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tcallback(event)\n\t\t\t}\n\n\t\t\trefValue.addEventListener('mouseenter', handleMouseEnter)\n\t\t\trefValue.addEventListener('mouseleave', handleMouseLeave)\n\t\t\trefValue.addEventListener('mousedown', handleMouseDown)\n\n\t\t\treturn () => {\n\t\t\t\trefValue.removeEventListener('mouseover', handleMouseEnter)\n\t\t\t\trefValue.removeEventListener('mouseleave', handleMouseLeave)\n\t\t\t\trefValue.removeEventListener('mousedown', handleMouseDown)\n\t\t\t}\n\t\t}\n\t}, [callback, refOrElement, timeoutMs])\n}\n"],"names":["useEffect","unwrapRefValue"],"mappings":";;;;AAcO,SAAS,sCACf,cACA,UACA,YAAoB,KACb;AACPA,QAAAA,UAAU,MAAM;AACf,UAAM,WAAWC,eAAAA,eAAe,YAAY;AAE5C,QAAI,UAAU;AAGb,UAAS,mBAAT,SAA0B,OAAmB;AAC5C,qBAAa,SAAS;AAEtB,oBAAY,WAAW,MAAM;AAC5B,mBAAS,KAAK;AAAA,QACf,GAAG,SAAS;AAAA,MACb,GAES,mBAAT,WAA4B;AAC3B,qBAAa,SAAS;AAAA,MACvB,GAES,kBAAT,SAAyB,OAAmB;AAC3C,qBAAa,SAAS;AACtB,iBAAS,KAAK;AAAA,MACf;AAjBA,UAAI;AAmBJ,eAAS,iBAAiB,cAAc,gBAAgB;AACxD,eAAS,iBAAiB,cAAc,gBAAgB;AACxD,eAAS,iBAAiB,aAAa,eAAe;AAEtD,aAAO,MAAM;AACZ,iBAAS,oBAAoB,aAAa,gBAAgB;AAC1D,iBAAS,oBAAoB,cAAc,gBAAgB;AAC3D,iBAAS,oBAAoB,aAAa,eAAe;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,GAAG,CAAC,UAAU,cAAc,SAAS,CAAC;AACvC;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { unwrapRefValue } from "./unwrapRefValue.js";
|
|
3
|
+
function useOnElementMouseEnterDelayedCallback(refOrElement, callback, timeoutMs = 300) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const refValue = unwrapRefValue(refOrElement);
|
|
6
|
+
if (refValue) {
|
|
7
|
+
let handleMouseEnter = function(event) {
|
|
8
|
+
clearTimeout(timeoutID);
|
|
9
|
+
timeoutID = setTimeout(() => {
|
|
10
|
+
callback(event);
|
|
11
|
+
}, timeoutMs);
|
|
12
|
+
}, handleMouseLeave = function() {
|
|
13
|
+
clearTimeout(timeoutID);
|
|
14
|
+
}, handleMouseDown = function(event) {
|
|
15
|
+
clearTimeout(timeoutID);
|
|
16
|
+
callback(event);
|
|
17
|
+
};
|
|
18
|
+
let timeoutID;
|
|
19
|
+
refValue.addEventListener("mouseenter", handleMouseEnter);
|
|
20
|
+
refValue.addEventListener("mouseleave", handleMouseLeave);
|
|
21
|
+
refValue.addEventListener("mousedown", handleMouseDown);
|
|
22
|
+
return () => {
|
|
23
|
+
refValue.removeEventListener("mouseover", handleMouseEnter);
|
|
24
|
+
refValue.removeEventListener("mouseleave", handleMouseLeave);
|
|
25
|
+
refValue.removeEventListener("mousedown", handleMouseDown);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}, [callback, refOrElement, timeoutMs]);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
useOnElementMouseEnterDelayedCallback
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=useOnElementMouseEnterDelayedCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.js","sources":["../../../../../packages/react-utils/src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Calls the callback when the mouse enters the element, but only after a timeout, e.g. for tooltips or dropdown menus.\n *\n * Calls the callback immediately if the mouse is pressed down with `event.type` of `mousedown`. This is useful for\n * dropdown menus, where the user may click on the menu item before the callback is called resulting in the menu\n * opening and closing immediately.\n *\n * @param refOrElement - The element or ref to the element to attach the event listener to.\n * @param callback - The callback to call when the mouse enters the element.\n * @param timeoutMs - The timeout in milliseconds to wait before calling the callback.\n */\nexport function useOnElementMouseEnterDelayedCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n\ttimeoutMs: number = 300,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tif (refValue) {\n\t\t\tlet timeoutID: ReturnType<typeof setTimeout> | undefined\n\n\t\t\tfunction handleMouseEnter(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tcallback(event)\n\t\t\t\t}, timeoutMs)\n\t\t\t}\n\n\t\t\tfunction handleMouseLeave() {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t}\n\n\t\t\tfunction handleMouseDown(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tcallback(event)\n\t\t\t}\n\n\t\t\trefValue.addEventListener('mouseenter', handleMouseEnter)\n\t\t\trefValue.addEventListener('mouseleave', handleMouseLeave)\n\t\t\trefValue.addEventListener('mousedown', handleMouseDown)\n\n\t\t\treturn () => {\n\t\t\t\trefValue.removeEventListener('mouseover', handleMouseEnter)\n\t\t\t\trefValue.removeEventListener('mouseleave', handleMouseLeave)\n\t\t\t\trefValue.removeEventListener('mousedown', handleMouseDown)\n\t\t\t}\n\t\t}\n\t}, [callback, refOrElement, timeoutMs])\n}\n"],"names":[],"mappings":";;AAcO,SAAS,sCACf,cACA,UACA,YAAoB,KACb;AACP,YAAU,MAAM;AACf,UAAM,WAAW,eAAe,YAAY;AAE5C,QAAI,UAAU;AAGb,UAAS,mBAAT,SAA0B,OAAmB;AAC5C,qBAAa,SAAS;AAEtB,oBAAY,WAAW,MAAM;AAC5B,mBAAS,KAAK;AAAA,QACf,GAAG,SAAS;AAAA,MACb,GAES,mBAAT,WAA4B;AAC3B,qBAAa,SAAS;AAAA,MACvB,GAES,kBAAT,SAAyB,OAAmB;AAC3C,qBAAa,SAAS;AACtB,iBAAS,KAAK;AAAA,MACf;AAjBA,UAAI;AAmBJ,eAAS,iBAAiB,cAAc,gBAAgB;AACxD,eAAS,iBAAiB,cAAc,gBAAgB;AACxD,eAAS,iBAAiB,aAAa,eAAe;AAEtD,aAAO,MAAM;AACZ,iBAAS,oBAAoB,aAAa,gBAAgB;AAC1D,iBAAS,oBAAoB,cAAc,gBAAgB;AAC3D,iBAAS,oBAAoB,aAAa,eAAe;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,GAAG,CAAC,UAAU,cAAc,SAAS,CAAC;AACvC;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const unwrapRefValue = require("./unwrapRefValue.cjs");
|
|
5
|
+
const Context = require("../debug-context/Context.cjs");
|
|
6
|
+
function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
|
|
7
|
+
const scopedConsoleRef = Context.useScopedConsoleRef("useOnElementResize");
|
|
8
|
+
const { box = "border-box" } = options;
|
|
9
|
+
const callbackRef = React.useRef(callback);
|
|
10
|
+
callbackRef.current = callback;
|
|
11
|
+
const lastTimeStamp = React.useRef(0);
|
|
12
|
+
React.useLayoutEffect(() => {
|
|
13
|
+
const element = unwrapRefValue.unwrapRefValue(refOrElement);
|
|
14
|
+
if (!element) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!(element instanceof HTMLElement)) {
|
|
18
|
+
throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
|
|
19
|
+
}
|
|
20
|
+
let timeoutID;
|
|
21
|
+
function debouncedOnChange([entry]) {
|
|
22
|
+
const timeStamp = Date.now();
|
|
23
|
+
const delta = timeStamp - lastTimeStamp.current;
|
|
24
|
+
clearTimeout(timeoutID);
|
|
25
|
+
const timeoutFinal = delta > timeout ? 0 : timeout;
|
|
26
|
+
timeoutID = setTimeout(() => {
|
|
27
|
+
const message = timeoutFinal > 0 ? "element.resize:debounced" : "element.resize:immediate";
|
|
28
|
+
scopedConsoleRef.current.warned(message, null);
|
|
29
|
+
callbackRef.current(entry);
|
|
30
|
+
lastTimeStamp.current = timeStamp;
|
|
31
|
+
}, timeoutFinal);
|
|
32
|
+
}
|
|
33
|
+
const resizeObserver = new ResizeObserver(debouncedOnChange);
|
|
34
|
+
resizeObserver.observe(element, { box });
|
|
35
|
+
return () => {
|
|
36
|
+
clearTimeout(timeoutID);
|
|
37
|
+
resizeObserver.unobserve(element);
|
|
38
|
+
};
|
|
39
|
+
}, [box, refOrElement, scopedConsoleRef, timeout]);
|
|
40
|
+
}
|
|
41
|
+
exports.useOnElementResize = useOnElementResize;
|
|
42
|
+
//# sourceMappingURL=useOnElementResize.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementResize.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnElementResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementResize(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (entries: ResizeObserverEntry) => void,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): void {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementResize')\n\n\tconst { box = 'border-box' } = options\n\tconst callbackRef = useRef(callback)\n\tcallbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\t\tif (!element) {\n\t\t\treturn\n\t\t}\n\t\tif (!(element instanceof HTMLElement)) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\n\t\tlet timeoutID: ReturnType<typeof setTimeout>\n\n\t\tfunction debouncedOnChange([entry]: ResizeObserverEntry[]) {\n\t\t\tconst timeStamp = Date.now()\n\t\t\tconst delta = timeStamp - lastTimeStamp.current\n\n\t\t\tclearTimeout(timeoutID)\n\t\t\tconst timeoutFinal = delta > timeout ? 0 : timeout\n\n\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\tconst message = timeoutFinal > 0 ? 'element.resize:debounced' : 'element.resize:immediate'\n\t\t\t\tscopedConsoleRef.current.warned(message, null)\n\t\t\t\tcallbackRef.current(entry)\n\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t}, timeoutFinal)\n\t\t}\n\n\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\tresizeObserver.observe(element, { box })\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\tresizeObserver.unobserve(element)\n\t\t}\n\t}, [box, refOrElement, scopedConsoleRef, timeout])\n}\n"],"names":["useScopedConsoleRef","useRef","useLayoutEffect","unwrapRefValue"],"mappings":";;;;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAA,GACjC,UAAkB,KACX;AACP,QAAM,mBAAmBA,QAAAA,oBAAoB,oBAAoB;AAEjE,QAAM,EAAE,MAAM,aAAA,IAAiB;AAC/B,QAAM,cAAcC,MAAAA,OAAO,QAAQ;AACnC,cAAY,UAAU;AACtB,QAAM,gBAAgBA,MAAAA,OAAe,CAAC;AAEtCC,QAAAA,gBAAgB,MAAM;AACrB,UAAM,UAAUC,eAAAA,eAAe,YAAY;AAC3C,QAAI,CAAC,SAAS;AACb;AAAA,IACD;AACA,QAAI,EAAE,mBAAmB,cAAc;AACtC,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAEA,QAAI;AAEJ,aAAS,kBAAkB,CAAC,KAAK,GAA0B;AAC1D,YAAM,YAAY,KAAK,IAAA;AACvB,YAAM,QAAQ,YAAY,cAAc;AAExC,mBAAa,SAAS;AACtB,YAAM,eAAe,QAAQ,UAAU,IAAI;AAE3C,kBAAY,WAAW,MAAM;AAC5B,cAAM,UAAU,eAAe,IAAI,6BAA6B;AAChE,yBAAiB,QAAQ,OAAO,SAAS,IAAI;AAC7C,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU;AAAA,MACzB,GAAG,YAAY;AAAA,IAChB;AAEA,UAAM,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,mBAAe,QAAQ,SAAS,EAAE,IAAA,CAAK;AAEvC,WAAO,MAAM;AACZ,mBAAa,SAAS;AACtB,qBAAe,UAAU,OAAO;AAAA,IACjC;AAAA,EACD,GAAG,CAAC,KAAK,cAAc,kBAAkB,OAAO,CAAC;AAClD;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useRef, useLayoutEffect } from "react";
|
|
2
|
+
import { unwrapRefValue } from "./unwrapRefValue.js";
|
|
3
|
+
import { useScopedConsoleRef } from "../debug-context/Context.js";
|
|
4
|
+
function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
|
|
5
|
+
const scopedConsoleRef = useScopedConsoleRef("useOnElementResize");
|
|
6
|
+
const { box = "border-box" } = options;
|
|
7
|
+
const callbackRef = useRef(callback);
|
|
8
|
+
callbackRef.current = callback;
|
|
9
|
+
const lastTimeStamp = useRef(0);
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
const element = unwrapRefValue(refOrElement);
|
|
12
|
+
if (!element) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!(element instanceof HTMLElement)) {
|
|
16
|
+
throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
|
|
17
|
+
}
|
|
18
|
+
let timeoutID;
|
|
19
|
+
function debouncedOnChange([entry]) {
|
|
20
|
+
const timeStamp = Date.now();
|
|
21
|
+
const delta = timeStamp - lastTimeStamp.current;
|
|
22
|
+
clearTimeout(timeoutID);
|
|
23
|
+
const timeoutFinal = delta > timeout ? 0 : timeout;
|
|
24
|
+
timeoutID = setTimeout(() => {
|
|
25
|
+
const message = timeoutFinal > 0 ? "element.resize:debounced" : "element.resize:immediate";
|
|
26
|
+
scopedConsoleRef.current.warned(message, null);
|
|
27
|
+
callbackRef.current(entry);
|
|
28
|
+
lastTimeStamp.current = timeStamp;
|
|
29
|
+
}, timeoutFinal);
|
|
30
|
+
}
|
|
31
|
+
const resizeObserver = new ResizeObserver(debouncedOnChange);
|
|
32
|
+
resizeObserver.observe(element, { box });
|
|
33
|
+
return () => {
|
|
34
|
+
clearTimeout(timeoutID);
|
|
35
|
+
resizeObserver.unobserve(element);
|
|
36
|
+
};
|
|
37
|
+
}, [box, refOrElement, scopedConsoleRef, timeout]);
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
useOnElementResize
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useOnElementResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnElementResize.js","sources":["../../../../../packages/react-utils/src/hooks/useOnElementResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementResize(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (entries: ResizeObserverEntry) => void,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): void {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementResize')\n\n\tconst { box = 'border-box' } = options\n\tconst callbackRef = useRef(callback)\n\tcallbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\t\tif (!element) {\n\t\t\treturn\n\t\t}\n\t\tif (!(element instanceof HTMLElement)) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\n\t\tlet timeoutID: ReturnType<typeof setTimeout>\n\n\t\tfunction debouncedOnChange([entry]: ResizeObserverEntry[]) {\n\t\t\tconst timeStamp = Date.now()\n\t\t\tconst delta = timeStamp - lastTimeStamp.current\n\n\t\t\tclearTimeout(timeoutID)\n\t\t\tconst timeoutFinal = delta > timeout ? 0 : timeout\n\n\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\tconst message = timeoutFinal > 0 ? 'element.resize:debounced' : 'element.resize:immediate'\n\t\t\t\tscopedConsoleRef.current.warned(message, null)\n\t\t\t\tcallbackRef.current(entry)\n\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t}, timeoutFinal)\n\t\t}\n\n\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\tresizeObserver.observe(element, { box })\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\tresizeObserver.unobserve(element)\n\t\t}\n\t}, [box, refOrElement, scopedConsoleRef, timeout])\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAA,GACjC,UAAkB,KACX;AACP,QAAM,mBAAmB,oBAAoB,oBAAoB;AAEjE,QAAM,EAAE,MAAM,aAAA,IAAiB;AAC/B,QAAM,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACtB,QAAM,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,MAAM;AACrB,UAAM,UAAU,eAAe,YAAY;AAC3C,QAAI,CAAC,SAAS;AACb;AAAA,IACD;AACA,QAAI,EAAE,mBAAmB,cAAc;AACtC,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAEA,QAAI;AAEJ,aAAS,kBAAkB,CAAC,KAAK,GAA0B;AAC1D,YAAM,YAAY,KAAK,IAAA;AACvB,YAAM,QAAQ,YAAY,cAAc;AAExC,mBAAa,SAAS;AACtB,YAAM,eAAe,QAAQ,UAAU,IAAI;AAE3C,kBAAY,WAAW,MAAM;AAC5B,cAAM,UAAU,eAAe,IAAI,6BAA6B;AAChE,yBAAiB,QAAQ,OAAO,SAAS,IAAI;AAC7C,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU;AAAA,MACzB,GAAG,YAAY;AAAA,IAChB;AAEA,UAAM,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,mBAAe,QAAQ,SAAS,EAAE,IAAA,CAAK;AAEvC,WAAO,MAAM;AACZ,mBAAa,SAAS;AACtB,qBAAe,UAAU,OAAO;AAAA,IACjC;AAAA,EACD,GAAG,CAAC,KAAK,cAAc,kBAAkB,OAAO,CAAC;AAClD;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const Context = require("../debug-context/Context.cjs");
|
|
5
|
+
function useOnWindowResize(callback, interval = 300) {
|
|
6
|
+
const scopedConsoleRef = Context.useScopedConsoleRef("useOnWindowResize");
|
|
7
|
+
const callbackRef = React.useRef(callback);
|
|
8
|
+
callbackRef.current = callback;
|
|
9
|
+
const lastTimeStamp = React.useRef(0);
|
|
10
|
+
React.useLayoutEffect(() => {
|
|
11
|
+
let timeoutID;
|
|
12
|
+
function debouncedHandler(event) {
|
|
13
|
+
clearTimeout(timeoutID);
|
|
14
|
+
const delta = event.timeStamp - lastTimeStamp.current;
|
|
15
|
+
scopedConsoleRef.current.logged("window.resize:delta", delta);
|
|
16
|
+
if (delta > interval) {
|
|
17
|
+
scopedConsoleRef.current.warned("event:window.resize:immediately", null);
|
|
18
|
+
callbackRef.current(event);
|
|
19
|
+
lastTimeStamp.current = event.timeStamp;
|
|
20
|
+
} else {
|
|
21
|
+
timeoutID = setTimeout(() => {
|
|
22
|
+
scopedConsoleRef.current.warned("event:window.resize:debounced", null);
|
|
23
|
+
lastTimeStamp.current = event.timeStamp;
|
|
24
|
+
callbackRef.current(event);
|
|
25
|
+
}, interval);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
window.addEventListener("resize", debouncedHandler);
|
|
29
|
+
return () => {
|
|
30
|
+
clearTimeout(timeoutID);
|
|
31
|
+
window.removeEventListener("resize", debouncedHandler);
|
|
32
|
+
};
|
|
33
|
+
}, [callbackRef, interval, scopedConsoleRef]);
|
|
34
|
+
}
|
|
35
|
+
exports.useOnWindowResize = useOnWindowResize;
|
|
36
|
+
//# sourceMappingURL=useOnWindowResize.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnWindowResize.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnWindowResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\n\nexport function useOnWindowResize(\n\tcallback: (event: Event) => void,\n\tinterval: number = 300,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnWindowResize')\n\n\tconst callbackRef = useRef(callback)\n\tcallbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: ReturnType<typeof setTimeout>\n\n\t\tfunction debouncedHandler(event: Event) {\n\t\t\tclearTimeout(timeoutID)\n\n\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\tscopedConsoleRef.current.logged('window.resize:delta', delta)\n\n\t\t\tif (delta > interval) {\n\t\t\t\tscopedConsoleRef.current.warned('event:window.resize:immediately', null)\n\t\t\t\tcallbackRef.current(event)\n\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t} else {\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('event:window.resize:debounced', null)\n\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t}, interval)\n\t\t\t}\n\t\t}\n\n\t\twindow.addEventListener('resize', debouncedHandler)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t}\n\t}, [callbackRef, interval, scopedConsoleRef])\n}\n"],"names":["useScopedConsoleRef","useRef","useLayoutEffect"],"mappings":";;;;AAGO,SAAS,kBACf,UACA,WAAmB,KAClB;AACD,QAAM,mBAAmBA,QAAAA,oBAAoB,mBAAmB;AAEhE,QAAM,cAAcC,MAAAA,OAAO,QAAQ;AACnC,cAAY,UAAU;AACtB,QAAM,gBAAgBA,MAAAA,OAAe,CAAC;AAGtCC,QAAAA,gBAAgB,MAAM;AACrB,QAAI;AAEJ,aAAS,iBAAiB,OAAc;AACvC,mBAAa,SAAS;AAEtB,YAAM,QAAQ,MAAM,YAAY,cAAc;AAC9C,uBAAiB,QAAQ,OAAO,uBAAuB,KAAK;AAE5D,UAAI,QAAQ,UAAU;AACrB,yBAAiB,QAAQ,OAAO,mCAAmC,IAAI;AACvE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU,MAAM;AAAA,MAC/B,OAAO;AACN,oBAAY,WAAW,MAAM;AAC5B,2BAAiB,QAAQ,OAAO,iCAAiC,IAAI;AACrE,wBAAc,UAAU,MAAM;AAC9B,sBAAY,QAAQ,KAAK;AAAA,QAC1B,GAAG,QAAQ;AAAA,MACZ;AAAA,IACD;AAEA,WAAO,iBAAiB,UAAU,gBAAgB;AAElD,WAAO,MAAM;AACZ,mBAAa,SAAS;AACtB,aAAO,oBAAoB,UAAU,gBAAgB;AAAA,IACtD;AAAA,EACD,GAAG,CAAC,aAAa,UAAU,gBAAgB,CAAC;AAC7C;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useRef, useLayoutEffect } from "react";
|
|
2
|
+
import { useScopedConsoleRef } from "../debug-context/Context.js";
|
|
3
|
+
function useOnWindowResize(callback, interval = 300) {
|
|
4
|
+
const scopedConsoleRef = useScopedConsoleRef("useOnWindowResize");
|
|
5
|
+
const callbackRef = useRef(callback);
|
|
6
|
+
callbackRef.current = callback;
|
|
7
|
+
const lastTimeStamp = useRef(0);
|
|
8
|
+
useLayoutEffect(() => {
|
|
9
|
+
let timeoutID;
|
|
10
|
+
function debouncedHandler(event) {
|
|
11
|
+
clearTimeout(timeoutID);
|
|
12
|
+
const delta = event.timeStamp - lastTimeStamp.current;
|
|
13
|
+
scopedConsoleRef.current.logged("window.resize:delta", delta);
|
|
14
|
+
if (delta > interval) {
|
|
15
|
+
scopedConsoleRef.current.warned("event:window.resize:immediately", null);
|
|
16
|
+
callbackRef.current(event);
|
|
17
|
+
lastTimeStamp.current = event.timeStamp;
|
|
18
|
+
} else {
|
|
19
|
+
timeoutID = setTimeout(() => {
|
|
20
|
+
scopedConsoleRef.current.warned("event:window.resize:debounced", null);
|
|
21
|
+
lastTimeStamp.current = event.timeStamp;
|
|
22
|
+
callbackRef.current(event);
|
|
23
|
+
}, interval);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
window.addEventListener("resize", debouncedHandler);
|
|
27
|
+
return () => {
|
|
28
|
+
clearTimeout(timeoutID);
|
|
29
|
+
window.removeEventListener("resize", debouncedHandler);
|
|
30
|
+
};
|
|
31
|
+
}, [callbackRef, interval, scopedConsoleRef]);
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useOnWindowResize
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=useOnWindowResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnWindowResize.js","sources":["../../../../../packages/react-utils/src/hooks/useOnWindowResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\n\nexport function useOnWindowResize(\n\tcallback: (event: Event) => void,\n\tinterval: number = 300,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnWindowResize')\n\n\tconst callbackRef = useRef(callback)\n\tcallbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: ReturnType<typeof setTimeout>\n\n\t\tfunction debouncedHandler(event: Event) {\n\t\t\tclearTimeout(timeoutID)\n\n\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\tscopedConsoleRef.current.logged('window.resize:delta', delta)\n\n\t\t\tif (delta > interval) {\n\t\t\t\tscopedConsoleRef.current.warned('event:window.resize:immediately', null)\n\t\t\t\tcallbackRef.current(event)\n\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t} else {\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('event:window.resize:debounced', null)\n\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t}, interval)\n\t\t\t}\n\t\t}\n\n\t\twindow.addEventListener('resize', debouncedHandler)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t}\n\t}, [callbackRef, interval, scopedConsoleRef])\n}\n"],"names":[],"mappings":";;AAGO,SAAS,kBACf,UACA,WAAmB,KAClB;AACD,QAAM,mBAAmB,oBAAoB,mBAAmB;AAEhE,QAAM,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACtB,QAAM,gBAAgB,OAAe,CAAC;AAGtC,kBAAgB,MAAM;AACrB,QAAI;AAEJ,aAAS,iBAAiB,OAAc;AACvC,mBAAa,SAAS;AAEtB,YAAM,QAAQ,MAAM,YAAY,cAAc;AAC9C,uBAAiB,QAAQ,OAAO,uBAAuB,KAAK;AAE5D,UAAI,QAAQ,UAAU;AACrB,yBAAiB,QAAQ,OAAO,mCAAmC,IAAI;AACvE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU,MAAM;AAAA,MAC/B,OAAO;AACN,oBAAY,WAAW,MAAM;AAC5B,2BAAiB,QAAQ,OAAO,iCAAiC,IAAI;AACrE,wBAAc,UAAU,MAAM;AAC9B,sBAAY,QAAQ,KAAK;AAAA,QAC1B,GAAG,QAAQ;AAAA,MACZ;AAAA,IACD;AAEA,WAAO,iBAAiB,UAAU,gBAAgB;AAElD,WAAO,MAAM;AACZ,mBAAa,SAAS;AACtB,aAAO,oBAAoB,UAAU,gBAAgB;AAAA,IACtD;AAAA,EACD,GAAG,CAAC,aAAa,UAAU,gBAAgB,CAAC;AAC7C;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const usePreviousValue = (value) => {
|
|
5
|
+
const ref = React.useRef(value);
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
ref.current = value;
|
|
8
|
+
});
|
|
9
|
+
return ref.current;
|
|
10
|
+
};
|
|
11
|
+
exports.usePreviousValue = usePreviousValue;
|
|
12
|
+
//# sourceMappingURL=usePreviousValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviousValue.cjs","sources":["../../../../../packages/react-utils/src/hooks/usePreviousValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport const usePreviousValue = <Value>(value: Value) => {\n\tconst ref = useRef<Value>(value)\n\tuseEffect(() => {\n\t\tref.current = value\n\t})\n\treturn ref.current\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AAEO,MAAM,mBAAmB,CAAQ,UAAiB;AACxD,QAAM,MAAMA,MAAAA,OAAc,KAAK;AAC/BC,QAAAA,UAAU,MAAM;AACf,QAAI,UAAU;AAAA,EACf,CAAC;AACD,SAAO,IAAI;AACZ;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
const usePreviousValue = (value) => {
|
|
3
|
+
const ref = useRef(value);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
ref.current = value;
|
|
6
|
+
});
|
|
7
|
+
return ref.current;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
usePreviousValue
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=usePreviousValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviousValue.js","sources":["../../../../../packages/react-utils/src/hooks/usePreviousValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport const usePreviousValue = <Value>(value: Value) => {\n\tconst ref = useRef<Value>(value)\n\tuseEffect(() => {\n\t\tref.current = value\n\t})\n\treturn ref.current\n}\n"],"names":[],"mappings":";AAEO,MAAM,mBAAmB,CAAQ,UAAiB;AACxD,QAAM,MAAM,OAAc,KAAK;AAC/B,YAAU,MAAM;AACf,QAAI,UAAU;AAAA,EACf,CAAC;AACD,SAAO,IAAI;AACZ;"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const urlStateStorage = {
|
|
5
|
+
getItem(key) {
|
|
6
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
7
|
+
const value = searchParams.get(key[1]);
|
|
8
|
+
return value !== null && value !== void 0 ? JSON.parse(value) : null;
|
|
9
|
+
},
|
|
10
|
+
setItem(key, value) {
|
|
11
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
12
|
+
searchParams.set(key[1], JSON.stringify(value));
|
|
13
|
+
const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
|
|
14
|
+
window.history.replaceState({}, "", newUrl);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const createStateStorageFromNativeStorage = (getStorage) => {
|
|
18
|
+
return {
|
|
19
|
+
getItem(key) {
|
|
20
|
+
const value = getStorage().getItem(key.join("-"));
|
|
21
|
+
return value !== null ? JSON.parse(value) : null;
|
|
22
|
+
},
|
|
23
|
+
setItem(key, value) {
|
|
24
|
+
getStorage().setItem(key.join("-"), JSON.stringify(value));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage);
|
|
29
|
+
const localStateStorage = createStateStorageFromNativeStorage(() => localStorage);
|
|
30
|
+
const nullStorage = {
|
|
31
|
+
getItem() {
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
setItem() {
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const builtInStorages = {
|
|
38
|
+
url: urlStateStorage,
|
|
39
|
+
session: sessionStateStorage,
|
|
40
|
+
local: localStateStorage,
|
|
41
|
+
null: nullStorage
|
|
42
|
+
};
|
|
43
|
+
const useStoredState = (storageOrName, key, initializeValue) => {
|
|
44
|
+
const storage = React.useMemo(() => {
|
|
45
|
+
return getStateStorage(storageOrName);
|
|
46
|
+
}, [storageOrName]);
|
|
47
|
+
const [value, setValue] = React.useState(() => {
|
|
48
|
+
const value2 = storage.getItem(key);
|
|
49
|
+
return initializeValue(value2);
|
|
50
|
+
});
|
|
51
|
+
return [
|
|
52
|
+
value,
|
|
53
|
+
React.useCallback((value2) => {
|
|
54
|
+
setValue((current) => {
|
|
55
|
+
const newValue = typeof value2 === "function" ? value2(current) : value2;
|
|
56
|
+
storage.setItem(key, newValue);
|
|
57
|
+
return newValue;
|
|
58
|
+
});
|
|
59
|
+
}, [key, storage])
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
const useSessionStorageState = (key, initializeValue) => {
|
|
63
|
+
return useStoredState(sessionStateStorage, key, initializeValue);
|
|
64
|
+
};
|
|
65
|
+
const useLocalStorageState = (key, initializeValue) => {
|
|
66
|
+
return useStoredState(localStateStorage, key, initializeValue);
|
|
67
|
+
};
|
|
68
|
+
const getStateStorage = (storageOrName) => {
|
|
69
|
+
if (Array.isArray(storageOrName)) {
|
|
70
|
+
return createFallbackStorage(storageOrName.map((it) => typeof it === "string" ? builtInStorages[it] : it));
|
|
71
|
+
}
|
|
72
|
+
return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
|
|
73
|
+
};
|
|
74
|
+
const createFallbackStorage = (storageTypes) => {
|
|
75
|
+
return {
|
|
76
|
+
getItem(key) {
|
|
77
|
+
for (const storage of storageTypes) {
|
|
78
|
+
const value = storage.getItem(key);
|
|
79
|
+
if (value !== null) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
},
|
|
85
|
+
setItem(key, value) {
|
|
86
|
+
for (const storage of storageTypes) {
|
|
87
|
+
storage.setItem(key, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
exports.getStateStorage = getStateStorage;
|
|
93
|
+
exports.localStateStorage = localStateStorage;
|
|
94
|
+
exports.nullStorage = nullStorage;
|
|
95
|
+
exports.sessionStateStorage = sessionStateStorage;
|
|
96
|
+
exports.urlStateStorage = urlStateStorage;
|
|
97
|
+
exports.useLocalStorageState = useLocalStorageState;
|
|
98
|
+
exports.useSessionStorageState = useSessionStorageState;
|
|
99
|
+
exports.useStoredState = useStoredState;
|
|
100
|
+
//# sourceMappingURL=useStoredState.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoredState.cjs","sources":["../../../../../packages/react-utils/src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void\nexport type StateStorageKey = [uniquePrefix: string, key: string]\n\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V\n\nexport interface StateStorage {\n\tgetItem(key: StateStorageKey): Serializable\n\n\tsetItem(key: StateStorageKey, value: Serializable): void\n}\n\nexport const urlStateStorage: StateStorage = {\n\tgetItem(key) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tconst value = searchParams.get(key[1])\n\t\treturn value !== null && value !== undefined ? JSON.parse(value) : null\n\t},\n\tsetItem(key, value) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tsearchParams.set(key[1], JSON.stringify(value))\n\t\tconst newUrl = `${window.location.pathname}?${searchParams.toString()}`\n\t\twindow.history.replaceState({}, '', newUrl)\n\t},\n}\n\nconst createStateStorageFromNativeStorage = (getStorage: () => Storage): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tconst value = getStorage().getItem(key.join('-'))\n\t\t\treturn value !== null ? JSON.parse(value) : null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tgetStorage().setItem(key.join('-'), JSON.stringify(value))\n\t\t},\n\t}\n}\n\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorageFromNativeStorage(() => localStorage)\nexport const nullStorage: StateStorage = {\n\tgetItem() {\n\t\treturn null\n\t},\n\tsetItem() {\n\t},\n}\n\nconst builtInStorages = {\n\turl: urlStateStorage,\n\tsession: sessionStateStorage,\n\tlocal: localStateStorage,\n\tnull: nullStorage,\n}\n\nexport type StateStorageOrName = StateStorage | 'url' | 'session' | 'local' | 'null'\n\nexport const useStoredState = <V extends Serializable>(\n\tstorageOrName: StateStorageOrName | StateStorageOrName[],\n\tkey: StateStorageKey,\n\tinitializeValue: ValueInitializer<V>,\n): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\treturn getStateStorage(storageOrName)\n\t}, [storageOrName])\n\n\tconst [value, setValue] = useState<V>(() => {\n\t\tconst value = storage.getItem(key)\n\t\treturn initializeValue(value as V)\n\t})\n\treturn [\n\t\tvalue,\n\t\tuseCallback(value => {\n\t\t\tsetValue(current => {\n\t\t\t\tconst newValue = typeof value === 'function' ? (value as (current: V) => V)(current) : value\n\t\t\t\tstorage.setItem(key, newValue)\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage]),\n\t]\n}\n\nexport const useSessionStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(sessionStateStorage, key, initializeValue)\n}\n\nexport const useLocalStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(localStateStorage, key, initializeValue)\n}\n\nexport const getStateStorage = (storageOrName: StateStorageOrName | StateStorageOrName[]) => {\n\tif (Array.isArray(storageOrName)) {\n\t\treturn createFallbackStorage(storageOrName.map(it => typeof it === 'string' ? builtInStorages[it] : it))\n\t}\n\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : storageOrName\n}\n\nconst createFallbackStorage = (storageTypes: StateStorage[]): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tconst value = storage.getItem(key)\n\t\t\t\tif (value !== null) {\n\t\t\t\t\treturn value\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tstorage.setItem(key, value)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"names":["useMemo","useState","value","useCallback"],"mappings":"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"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useMemo, useState, useCallback } from "react";
|
|
2
|
+
const urlStateStorage = {
|
|
3
|
+
getItem(key) {
|
|
4
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
5
|
+
const value = searchParams.get(key[1]);
|
|
6
|
+
return value !== null && value !== void 0 ? JSON.parse(value) : null;
|
|
7
|
+
},
|
|
8
|
+
setItem(key, value) {
|
|
9
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
10
|
+
searchParams.set(key[1], JSON.stringify(value));
|
|
11
|
+
const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
|
|
12
|
+
window.history.replaceState({}, "", newUrl);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const createStateStorageFromNativeStorage = (getStorage) => {
|
|
16
|
+
return {
|
|
17
|
+
getItem(key) {
|
|
18
|
+
const value = getStorage().getItem(key.join("-"));
|
|
19
|
+
return value !== null ? JSON.parse(value) : null;
|
|
20
|
+
},
|
|
21
|
+
setItem(key, value) {
|
|
22
|
+
getStorage().setItem(key.join("-"), JSON.stringify(value));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage);
|
|
27
|
+
const localStateStorage = createStateStorageFromNativeStorage(() => localStorage);
|
|
28
|
+
const nullStorage = {
|
|
29
|
+
getItem() {
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
setItem() {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const builtInStorages = {
|
|
36
|
+
url: urlStateStorage,
|
|
37
|
+
session: sessionStateStorage,
|
|
38
|
+
local: localStateStorage,
|
|
39
|
+
null: nullStorage
|
|
40
|
+
};
|
|
41
|
+
const useStoredState = (storageOrName, key, initializeValue) => {
|
|
42
|
+
const storage = useMemo(() => {
|
|
43
|
+
return getStateStorage(storageOrName);
|
|
44
|
+
}, [storageOrName]);
|
|
45
|
+
const [value, setValue] = useState(() => {
|
|
46
|
+
const value2 = storage.getItem(key);
|
|
47
|
+
return initializeValue(value2);
|
|
48
|
+
});
|
|
49
|
+
return [
|
|
50
|
+
value,
|
|
51
|
+
useCallback((value2) => {
|
|
52
|
+
setValue((current) => {
|
|
53
|
+
const newValue = typeof value2 === "function" ? value2(current) : value2;
|
|
54
|
+
storage.setItem(key, newValue);
|
|
55
|
+
return newValue;
|
|
56
|
+
});
|
|
57
|
+
}, [key, storage])
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
const useSessionStorageState = (key, initializeValue) => {
|
|
61
|
+
return useStoredState(sessionStateStorage, key, initializeValue);
|
|
62
|
+
};
|
|
63
|
+
const useLocalStorageState = (key, initializeValue) => {
|
|
64
|
+
return useStoredState(localStateStorage, key, initializeValue);
|
|
65
|
+
};
|
|
66
|
+
const getStateStorage = (storageOrName) => {
|
|
67
|
+
if (Array.isArray(storageOrName)) {
|
|
68
|
+
return createFallbackStorage(storageOrName.map((it) => typeof it === "string" ? builtInStorages[it] : it));
|
|
69
|
+
}
|
|
70
|
+
return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
|
|
71
|
+
};
|
|
72
|
+
const createFallbackStorage = (storageTypes) => {
|
|
73
|
+
return {
|
|
74
|
+
getItem(key) {
|
|
75
|
+
for (const storage of storageTypes) {
|
|
76
|
+
const value = storage.getItem(key);
|
|
77
|
+
if (value !== null) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
},
|
|
83
|
+
setItem(key, value) {
|
|
84
|
+
for (const storage of storageTypes) {
|
|
85
|
+
storage.setItem(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
getStateStorage,
|
|
92
|
+
localStateStorage,
|
|
93
|
+
nullStorage,
|
|
94
|
+
sessionStateStorage,
|
|
95
|
+
urlStateStorage,
|
|
96
|
+
useLocalStorageState,
|
|
97
|
+
useSessionStorageState,
|
|
98
|
+
useStoredState
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=useStoredState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoredState.js","sources":["../../../../../packages/react-utils/src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void\nexport type StateStorageKey = [uniquePrefix: string, key: string]\n\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V\n\nexport interface StateStorage {\n\tgetItem(key: StateStorageKey): Serializable\n\n\tsetItem(key: StateStorageKey, value: Serializable): void\n}\n\nexport const urlStateStorage: StateStorage = {\n\tgetItem(key) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tconst value = searchParams.get(key[1])\n\t\treturn value !== null && value !== undefined ? JSON.parse(value) : null\n\t},\n\tsetItem(key, value) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tsearchParams.set(key[1], JSON.stringify(value))\n\t\tconst newUrl = `${window.location.pathname}?${searchParams.toString()}`\n\t\twindow.history.replaceState({}, '', newUrl)\n\t},\n}\n\nconst createStateStorageFromNativeStorage = (getStorage: () => Storage): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tconst value = getStorage().getItem(key.join('-'))\n\t\t\treturn value !== null ? JSON.parse(value) : null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tgetStorage().setItem(key.join('-'), JSON.stringify(value))\n\t\t},\n\t}\n}\n\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorageFromNativeStorage(() => localStorage)\nexport const nullStorage: StateStorage = {\n\tgetItem() {\n\t\treturn null\n\t},\n\tsetItem() {\n\t},\n}\n\nconst builtInStorages = {\n\turl: urlStateStorage,\n\tsession: sessionStateStorage,\n\tlocal: localStateStorage,\n\tnull: nullStorage,\n}\n\nexport type StateStorageOrName = StateStorage | 'url' | 'session' | 'local' | 'null'\n\nexport const useStoredState = <V extends Serializable>(\n\tstorageOrName: StateStorageOrName | StateStorageOrName[],\n\tkey: StateStorageKey,\n\tinitializeValue: ValueInitializer<V>,\n): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\treturn getStateStorage(storageOrName)\n\t}, [storageOrName])\n\n\tconst [value, setValue] = useState<V>(() => {\n\t\tconst value = storage.getItem(key)\n\t\treturn initializeValue(value as V)\n\t})\n\treturn [\n\t\tvalue,\n\t\tuseCallback(value => {\n\t\t\tsetValue(current => {\n\t\t\t\tconst newValue = typeof value === 'function' ? (value as (current: V) => V)(current) : value\n\t\t\t\tstorage.setItem(key, newValue)\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage]),\n\t]\n}\n\nexport const useSessionStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(sessionStateStorage, key, initializeValue)\n}\n\nexport const useLocalStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(localStateStorage, key, initializeValue)\n}\n\nexport const getStateStorage = (storageOrName: StateStorageOrName | StateStorageOrName[]) => {\n\tif (Array.isArray(storageOrName)) {\n\t\treturn createFallbackStorage(storageOrName.map(it => typeof it === 'string' ? builtInStorages[it] : it))\n\t}\n\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : storageOrName\n}\n\nconst createFallbackStorage = (storageTypes: StateStorage[]): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tconst value = storage.getItem(key)\n\t\t\t\tif (value !== null) {\n\t\t\t\t\treturn value\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tstorage.setItem(key, value)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"names":["value"],"mappings":"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"}
|