@contember/react-utils 1.3.0-alpha.9 → 2.0.0-alpha.2
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/context/createContext.cjs +10 -0
- package/dist/development/context/createContext.cjs.map +1 -0
- package/dist/development/context/createContext.js +10 -0
- package/dist/development/context/createContext.js.map +1 -0
- package/dist/development/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
- package/dist/development/context/createRequiredContext.cjs.map +1 -0
- package/dist/development/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
- package/dist/development/context/createRequiredContext.js.map +1 -0
- package/dist/development/hooks/useAutoHeightTextArea.cjs +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.js +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/development/hooks/useStoredState.cjs +89 -12
- package/dist/development/hooks/useStoredState.cjs.map +1 -1
- package/dist/development/hooks/useStoredState.js +91 -14
- package/dist/development/hooks/useStoredState.js.map +1 -1
- package/dist/development/index.cjs +11 -41
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +12 -42
- package/dist/development/index.js.map +1 -1
- package/dist/production/context/createContext.cjs +10 -0
- package/dist/production/context/createContext.cjs.map +1 -0
- package/dist/production/context/createContext.js +10 -0
- package/dist/production/context/createContext.js.map +1 -0
- package/dist/production/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
- package/dist/production/context/createRequiredContext.cjs.map +1 -0
- package/dist/production/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
- package/dist/production/context/createRequiredContext.js.map +1 -0
- package/dist/production/hooks/useAutoHeightTextArea.cjs +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.js +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/production/hooks/useStoredState.cjs +89 -12
- package/dist/production/hooks/useStoredState.cjs.map +1 -1
- package/dist/production/hooks/useStoredState.js +91 -14
- package/dist/production/hooks/useStoredState.js.map +1 -1
- package/dist/production/index.cjs +11 -41
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +12 -42
- package/dist/production/index.js.map +1 -1
- 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 +2 -2
- package/dist/types/context/index.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +0 -10
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useArrayMapMemo.d.ts.map +1 -1
- package/dist/types/hooks/useConstantLengthInvariant.d.ts.map +1 -1
- package/dist/types/hooks/useConstantValueInvariant.d.ts.map +1 -1
- package/dist/types/hooks/useDebounce.d.ts.map +1 -1
- package/dist/types/hooks/useObjectMemo.d.ts.map +1 -1
- package/dist/types/hooks/usePreviousValue.d.ts.map +1 -1
- package/dist/types/hooks/useStoredState.d.ts +14 -1
- package/dist/types/hooks/useStoredState.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/referentiallyStable/identityFunction.d.ts.map +1 -1
- package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/context/createContext.ts +9 -0
- package/src/context/{createNonNullableContextFactory.ts → createRequiredContext.ts} +6 -4
- package/src/context/index.ts +2 -2
- package/src/hooks/index.ts +0 -10
- package/src/hooks/useAutoHeightTextArea.ts +1 -1
- package/src/hooks/useStoredState.ts +103 -14
- package/src/index.ts +0 -1
- package/dist/development/context/createNonNullableContextFactory.cjs.map +0 -1
- package/dist/development/context/createNonNullableContextFactory.js.map +0 -1
- package/dist/development/context/createOptionalContextFactory.cjs +0 -13
- package/dist/development/context/createOptionalContextFactory.cjs.map +0 -1
- package/dist/development/context/createOptionalContextFactory.js +0 -13
- package/dist/development/context/createOptionalContextFactory.js.map +0 -1
- package/dist/development/hooks/useAddClassNameDuringResize.cjs +0 -32
- package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +0 -1
- package/dist/development/hooks/useAddClassNameDuringResize.js +0 -32
- package/dist/development/hooks/useAddClassNameDuringResize.js.map +0 -1
- package/dist/development/hooks/useCloseOnClickOutside.cjs +0 -25
- package/dist/development/hooks/useCloseOnClickOutside.cjs.map +0 -1
- package/dist/development/hooks/useCloseOnClickOutside.js +0 -25
- package/dist/development/hooks/useCloseOnClickOutside.js.map +0 -1
- package/dist/development/hooks/useCloseOnEscape.cjs +0 -20
- package/dist/development/hooks/useCloseOnEscape.cjs.map +0 -1
- package/dist/development/hooks/useCloseOnEscape.js +0 -20
- package/dist/development/hooks/useCloseOnEscape.js.map +0 -1
- package/dist/development/hooks/useContainerWidth.cjs +0 -14
- package/dist/development/hooks/useContainerWidth.cjs.map +0 -1
- package/dist/development/hooks/useContainerWidth.js +0 -14
- package/dist/development/hooks/useContainerWidth.js.map +0 -1
- package/dist/development/hooks/useElementSize.cjs +0 -37
- package/dist/development/hooks/useElementSize.cjs.map +0 -1
- package/dist/development/hooks/useElementSize.js +0 -37
- package/dist/development/hooks/useElementSize.js.map +0 -1
- package/dist/development/hooks/useElementTopOffset.cjs +0 -29
- package/dist/development/hooks/useElementTopOffset.cjs.map +0 -1
- package/dist/development/hooks/useElementTopOffset.js +0 -29
- package/dist/development/hooks/useElementTopOffset.js.map +0 -1
- package/dist/development/hooks/useEventHandler.cjs +0 -19
- package/dist/development/hooks/useEventHandler.cjs.map +0 -1
- package/dist/development/hooks/useEventHandler.js +0 -19
- package/dist/development/hooks/useEventHandler.js.map +0 -1
- package/dist/development/hooks/useOnElementMutation.cjs +0 -35
- package/dist/development/hooks/useOnElementMutation.cjs.map +0 -1
- package/dist/development/hooks/useOnElementMutation.js +0 -35
- package/dist/development/hooks/useOnElementMutation.js.map +0 -1
- package/dist/development/hooks/useOnScrollWithin.cjs +0 -52
- package/dist/development/hooks/useOnScrollWithin.cjs.map +0 -1
- package/dist/development/hooks/useOnScrollWithin.js +0 -52
- package/dist/development/hooks/useOnScrollWithin.js.map +0 -1
- package/dist/development/hooks/useScrollOffsets.cjs +0 -67
- package/dist/development/hooks/useScrollOffsets.cjs.map +0 -1
- package/dist/development/hooks/useScrollOffsets.js +0 -67
- package/dist/development/hooks/useScrollOffsets.js.map +0 -1
- package/dist/development/theming/ColorSchemeProvider.cjs +0 -16
- package/dist/development/theming/ColorSchemeProvider.cjs.map +0 -1
- package/dist/development/theming/ColorSchemeProvider.js +0 -16
- package/dist/development/theming/ColorSchemeProvider.js.map +0 -1
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs +0 -6
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
- package/dist/development/theming/GlobalClassNamePrefixContext.js +0 -6
- package/dist/development/theming/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/development/theming/contexts.cjs +0 -12
- package/dist/development/theming/contexts.cjs.map +0 -1
- package/dist/development/theming/contexts.js +0 -12
- package/dist/development/theming/contexts.js.map +0 -1
- package/dist/development/theming/useClassName.cjs +0 -17
- package/dist/development/theming/useClassName.cjs.map +0 -1
- package/dist/development/theming/useClassName.js +0 -17
- package/dist/development/theming/useClassName.js.map +0 -1
- package/dist/development/theming/useClassNameFactory.cjs +0 -22
- package/dist/development/theming/useClassNameFactory.cjs.map +0 -1
- package/dist/development/theming/useClassNameFactory.js +0 -22
- package/dist/development/theming/useClassNameFactory.js.map +0 -1
- package/dist/development/theming/useThemedClassName.cjs +0 -17
- package/dist/development/theming/useThemedClassName.cjs.map +0 -1
- package/dist/development/theming/useThemedClassName.js +0 -17
- package/dist/development/theming/useThemedClassName.js.map +0 -1
- package/dist/development/theming/useThemedClassNameFactory.cjs +0 -29
- package/dist/development/theming/useThemedClassNameFactory.cjs.map +0 -1
- package/dist/development/theming/useThemedClassNameFactory.js +0 -29
- package/dist/development/theming/useThemedClassNameFactory.js.map +0 -1
- package/dist/production/context/createNonNullableContextFactory.cjs.map +0 -1
- package/dist/production/context/createNonNullableContextFactory.js.map +0 -1
- package/dist/production/context/createOptionalContextFactory.cjs +0 -13
- package/dist/production/context/createOptionalContextFactory.cjs.map +0 -1
- package/dist/production/context/createOptionalContextFactory.js +0 -13
- package/dist/production/context/createOptionalContextFactory.js.map +0 -1
- package/dist/production/hooks/useAddClassNameDuringResize.cjs +0 -32
- package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +0 -1
- package/dist/production/hooks/useAddClassNameDuringResize.js +0 -32
- package/dist/production/hooks/useAddClassNameDuringResize.js.map +0 -1
- package/dist/production/hooks/useCloseOnClickOutside.cjs +0 -25
- package/dist/production/hooks/useCloseOnClickOutside.cjs.map +0 -1
- package/dist/production/hooks/useCloseOnClickOutside.js +0 -25
- package/dist/production/hooks/useCloseOnClickOutside.js.map +0 -1
- package/dist/production/hooks/useCloseOnEscape.cjs +0 -20
- package/dist/production/hooks/useCloseOnEscape.cjs.map +0 -1
- package/dist/production/hooks/useCloseOnEscape.js +0 -20
- package/dist/production/hooks/useCloseOnEscape.js.map +0 -1
- package/dist/production/hooks/useContainerWidth.cjs +0 -14
- package/dist/production/hooks/useContainerWidth.cjs.map +0 -1
- package/dist/production/hooks/useContainerWidth.js +0 -14
- package/dist/production/hooks/useContainerWidth.js.map +0 -1
- package/dist/production/hooks/useElementSize.cjs +0 -37
- package/dist/production/hooks/useElementSize.cjs.map +0 -1
- package/dist/production/hooks/useElementSize.js +0 -37
- package/dist/production/hooks/useElementSize.js.map +0 -1
- package/dist/production/hooks/useElementTopOffset.cjs +0 -29
- package/dist/production/hooks/useElementTopOffset.cjs.map +0 -1
- package/dist/production/hooks/useElementTopOffset.js +0 -29
- package/dist/production/hooks/useElementTopOffset.js.map +0 -1
- package/dist/production/hooks/useEventHandler.cjs +0 -19
- package/dist/production/hooks/useEventHandler.cjs.map +0 -1
- package/dist/production/hooks/useEventHandler.js +0 -19
- package/dist/production/hooks/useEventHandler.js.map +0 -1
- package/dist/production/hooks/useOnElementMutation.cjs +0 -35
- package/dist/production/hooks/useOnElementMutation.cjs.map +0 -1
- package/dist/production/hooks/useOnElementMutation.js +0 -35
- package/dist/production/hooks/useOnElementMutation.js.map +0 -1
- package/dist/production/hooks/useOnScrollWithin.cjs +0 -52
- package/dist/production/hooks/useOnScrollWithin.cjs.map +0 -1
- package/dist/production/hooks/useOnScrollWithin.js +0 -52
- package/dist/production/hooks/useOnScrollWithin.js.map +0 -1
- package/dist/production/hooks/useScrollOffsets.cjs +0 -67
- package/dist/production/hooks/useScrollOffsets.cjs.map +0 -1
- package/dist/production/hooks/useScrollOffsets.js +0 -67
- package/dist/production/hooks/useScrollOffsets.js.map +0 -1
- package/dist/production/theming/ColorSchemeProvider.cjs +0 -12
- package/dist/production/theming/ColorSchemeProvider.cjs.map +0 -1
- package/dist/production/theming/ColorSchemeProvider.js +0 -12
- package/dist/production/theming/ColorSchemeProvider.js.map +0 -1
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs +0 -6
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
- package/dist/production/theming/GlobalClassNamePrefixContext.js +0 -6
- package/dist/production/theming/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/production/theming/contexts.cjs +0 -12
- package/dist/production/theming/contexts.cjs.map +0 -1
- package/dist/production/theming/contexts.js +0 -12
- package/dist/production/theming/contexts.js.map +0 -1
- package/dist/production/theming/useClassName.cjs +0 -17
- package/dist/production/theming/useClassName.cjs.map +0 -1
- package/dist/production/theming/useClassName.js +0 -17
- package/dist/production/theming/useClassName.js.map +0 -1
- package/dist/production/theming/useClassNameFactory.cjs +0 -22
- package/dist/production/theming/useClassNameFactory.cjs.map +0 -1
- package/dist/production/theming/useClassNameFactory.js +0 -22
- package/dist/production/theming/useClassNameFactory.js.map +0 -1
- package/dist/production/theming/useThemedClassName.cjs +0 -17
- package/dist/production/theming/useThemedClassName.cjs.map +0 -1
- package/dist/production/theming/useThemedClassName.js +0 -17
- package/dist/production/theming/useThemedClassName.js.map +0 -1
- package/dist/production/theming/useThemedClassNameFactory.cjs +0 -29
- package/dist/production/theming/useThemedClassNameFactory.cjs.map +0 -1
- package/dist/production/theming/useThemedClassNameFactory.js +0 -29
- package/dist/production/theming/useThemedClassNameFactory.js.map +0 -1
- package/dist/types/context/createNonNullableContextFactory.d.ts +0 -3
- package/dist/types/context/createNonNullableContextFactory.d.ts.map +0 -1
- package/dist/types/context/createOptionalContextFactory.d.ts +0 -3
- package/dist/types/context/createOptionalContextFactory.d.ts.map +0 -1
- package/dist/types/hooks/useAddClassNameDuringResize.d.ts +0 -13
- package/dist/types/hooks/useAddClassNameDuringResize.d.ts.map +0 -1
- package/dist/types/hooks/useCloseOnClickOutside.d.ts +0 -7
- package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +0 -1
- package/dist/types/hooks/useCloseOnEscape.d.ts +0 -5
- package/dist/types/hooks/useCloseOnEscape.d.ts.map +0 -1
- package/dist/types/hooks/useContainerWidth.d.ts +0 -4
- package/dist/types/hooks/useContainerWidth.d.ts.map +0 -1
- package/dist/types/hooks/useElementSize.d.ts +0 -16
- package/dist/types/hooks/useElementSize.d.ts.map +0 -1
- package/dist/types/hooks/useElementTopOffset.d.ts +0 -3
- package/dist/types/hooks/useElementTopOffset.d.ts.map +0 -1
- package/dist/types/hooks/useEventHandler.d.ts +0 -10
- package/dist/types/hooks/useEventHandler.d.ts.map +0 -1
- package/dist/types/hooks/useOnElementMutation.d.ts +0 -3
- package/dist/types/hooks/useOnElementMutation.d.ts.map +0 -1
- package/dist/types/hooks/useOnScrollWithin.d.ts +0 -10
- package/dist/types/hooks/useOnScrollWithin.d.ts.map +0 -1
- package/dist/types/hooks/useScrollOffsets.d.ts +0 -14
- package/dist/types/hooks/useScrollOffsets.d.ts.map +0 -1
- package/dist/types/theming/ColorSchemeProvider.d.ts +0 -6
- package/dist/types/theming/ColorSchemeProvider.d.ts.map +0 -1
- package/dist/types/theming/GlobalClassNamePrefixContext.d.ts +0 -2
- package/dist/types/theming/GlobalClassNamePrefixContext.d.ts.map +0 -1
- package/dist/types/theming/contexts.d.ts +0 -12
- package/dist/types/theming/contexts.d.ts.map +0 -1
- package/dist/types/theming/index.d.ts +0 -8
- package/dist/types/theming/index.d.ts.map +0 -1
- package/dist/types/theming/useClassName.d.ts +0 -11
- package/dist/types/theming/useClassName.d.ts.map +0 -1
- package/dist/types/theming/useClassNameFactory.d.ts +0 -17
- package/dist/types/theming/useClassNameFactory.d.ts.map +0 -1
- package/dist/types/theming/useThemedClassName.d.ts +0 -39
- package/dist/types/theming/useThemedClassName.d.ts.map +0 -1
- package/dist/types/theming/useThemedClassNameFactory.d.ts +0 -3
- package/dist/types/theming/useThemedClassNameFactory.d.ts.map +0 -1
- package/src/context/createOptionalContextFactory.ts +0 -13
- package/src/hooks/useAddClassNameDuringResize.ts +0 -56
- package/src/hooks/useCloseOnClickOutside.ts +0 -27
- package/src/hooks/useCloseOnEscape.ts +0 -18
- package/src/hooks/useContainerWidth.ts +0 -13
- package/src/hooks/useElementSize.ts +0 -56
- package/src/hooks/useElementTopOffset.ts +0 -35
- package/src/hooks/useEventHandler.ts +0 -24
- package/src/hooks/useOnElementMutation.ts +0 -42
- package/src/hooks/useOnScrollWithin.ts +0 -68
- package/src/hooks/useScrollOffsets.ts +0 -87
- package/src/theming/ColorSchemeProvider.tsx +0 -16
- package/src/theming/GlobalClassNamePrefixContext.ts +0 -3
- package/src/theming/contexts.ts +0 -18
- package/src/theming/index.ts +0 -7
- package/src/theming/useClassName.ts +0 -28
- package/src/theming/useClassNameFactory.ts +0 -50
- package/src/theming/useThemedClassName.ts +0 -54
- package/src/theming/useThemedClassNameFactory.ts +0 -44
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useElementTopOffset.d.ts","sourceRoot":"","sources":["../../../src/hooks/useElementTopOffset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAA;AAE5D,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,SAAS,CAgCpF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EventHandler, SyntheticEvent } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Similar to useEvent with inferred type for the event parameter according to event type
|
|
4
|
-
*
|
|
5
|
-
* @param type - String, keyof DocumentEventMap, e.g. 'click', 'keydown',...
|
|
6
|
-
* @param callback - EventHandler
|
|
7
|
-
* @returns Stable reference callback
|
|
8
|
-
*/
|
|
9
|
-
export declare function useEventHandler<E extends SyntheticEvent<any>>(type: E['type'], callback: EventHandler<E>): EventHandler<E>;
|
|
10
|
-
//# sourceMappingURL=useEventHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEventHandler.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAqB,MAAM,OAAO,CAAA;AAEvE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAc1H"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
2
|
-
export declare function useOnElementMutation(refOrElement: RefObjectOrElement<HTMLElement | undefined>, callback: MutationCallback, options?: MutationObserverInit): void;
|
|
3
|
-
//# sourceMappingURL=useOnElementMutation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useOnElementMutation.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementMutation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,kBAAkB,CAAA;AAErE,wBAAgB,oBAAoB,CACnC,YAAY,EAAE,kBAAkB,CAAC,WAAW,GAAG,SAAS,CAAC,EACzD,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,oBAA2E,QAiCpF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
2
|
-
/**
|
|
3
|
-
* Invokes callback on scroll event within the scroll container
|
|
4
|
-
*
|
|
5
|
-
* @param refOrElement - Scroll container
|
|
6
|
-
* @param callback - Callback that is invoked on scroll event
|
|
7
|
-
* @param interval - Specifies how often should scroll event invoke callback
|
|
8
|
-
*/
|
|
9
|
-
export declare function useOnScrollWithin(refOrElement: RefObjectOrElement<HTMLElement | null> | null, callback: (event: Event) => void, interval?: number): void;
|
|
10
|
-
//# sourceMappingURL=useOnScrollWithin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useOnScrollWithin.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnScrollWithin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,kBAAkB,CAAA;AAErE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,IAAI,EAC3D,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAChC,QAAQ,GAAE,MAAkB,QAqD5B"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
2
|
-
export type Offsets = {
|
|
3
|
-
bottom: number;
|
|
4
|
-
left: number;
|
|
5
|
-
right: number;
|
|
6
|
-
top: number;
|
|
7
|
-
};
|
|
8
|
-
export declare function useScrollOffsets(refOrElement: RefObjectOrElement<HTMLElement | null> | null, interval?: number): {
|
|
9
|
-
bottom: number;
|
|
10
|
-
left: number;
|
|
11
|
-
right: number;
|
|
12
|
-
top: number;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=useScrollOffsets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useScrollOffsets.d.ts","sourceRoot":"","sources":["../../../src/hooks/useScrollOffsets.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,kBAAkB,CAAA;AAIrE,MAAM,MAAM,OAAO,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ,CAAA;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,QAAQ,GAAE,MAAkB;;;;;EAiCzH"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type ColorSchemeProviderProps = {
|
|
2
|
-
children: React.ReactNode;
|
|
3
|
-
scheme?: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const ColorSchemeProvider: import("react").MemoExoticComponent<({ children, scheme }: ColorSchemeProviderProps) => import("react/jsx-runtime").JSX.Element>;
|
|
6
|
-
//# sourceMappingURL=ColorSchemeProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ColorSchemeProvider.d.ts","sourceRoot":"","sources":["../../../src/theming/ColorSchemeProvider.tsx"],"names":[],"mappings":"AAGA,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,mBAAmB,6DAA+B,wBAAwB,6CAMrF,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalClassNamePrefixContext.d.ts","sourceRoot":"","sources":["../../../src/theming/GlobalClassNamePrefixContext.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,4BAA4B,iCAAgC,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_COLOR_SCHEME = "system";
|
|
2
|
-
/**
|
|
3
|
-
* @group UI
|
|
4
|
-
*
|
|
5
|
-
* @description
|
|
6
|
-
* Provides the current color scheme, possible values are `'light'`, `'dark'` or `'system'`.
|
|
7
|
-
*
|
|
8
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export declare const ColorSchemeContext: import("react").Context<string>, useColorScheme: () => string;
|
|
12
|
-
//# sourceMappingURL=contexts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../../src/theming/contexts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAG5C;;;;;;;;GAQG;AACH,eAAO,MAAO,kBAAkB,mCAAE,cAAc,cAG/C,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './ColorSchemeProvider';
|
|
2
|
-
export * from './GlobalClassNamePrefixContext';
|
|
3
|
-
export * from './contexts';
|
|
4
|
-
export * from './useClassName';
|
|
5
|
-
export * from './useClassNameFactory';
|
|
6
|
-
export * from './useThemedClassName';
|
|
7
|
-
export * from './useThemedClassNameFactory';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theming/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,6BAA6B,CAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NestedClassName } from '@contember/utilities';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for component class name accepting outer class name
|
|
4
|
-
*
|
|
5
|
-
* @param componentClassName - Component class name
|
|
6
|
-
* @param additionalClassName - Additional class name
|
|
7
|
-
* @param prefixOverride - Context component prefix override
|
|
8
|
-
* @returns Prefixed component class name.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useClassName(componentClassName: NestedClassName, additionalClassName?: NestedClassName, prefixOverride?: string | null | undefined): string;
|
|
11
|
-
//# sourceMappingURL=useClassName.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useClassName.d.ts","sourceRoot":"","sources":["../../../src/theming/useClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA2C,MAAM,sBAAsB,CAAA;AAI/F;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC3B,kBAAkB,EAAE,eAAe,EACnC,mBAAmB,GAAE,eAAsB,EAC3C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,UAY1C"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NestedClassName } from '@contember/utilities';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for component class name accepting outer class name
|
|
4
|
-
*
|
|
5
|
-
* Returns a reusable function almost that is handy for components
|
|
6
|
-
* with many sub-component parts that should inherit the root component
|
|
7
|
-
* name.
|
|
8
|
-
*
|
|
9
|
-
* Also, product of the factory is a function that can be used outside of rules of hooks.
|
|
10
|
-
*
|
|
11
|
-
* @param componentClassName - Component class name
|
|
12
|
-
* @param glue - String to use to glue component and sub-component suffix
|
|
13
|
-
* @param prefixOverride - Context component prefix override
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare function useClassNameFactory(componentClassName: NestedClassName, glue?: string | null, prefixOverride?: string | null | undefined): (suffix?: string | null | undefined, additionalClassName?: NestedClassName) => string;
|
|
17
|
-
//# sourceMappingURL=useClassNameFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useClassNameFactory.d.ts","sourceRoot":"","sources":["../../../src/theming/useClassNameFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA2C,MAAM,sBAAsB,CAAA;AAK/F;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAClC,kBAAkB,EAAE,eAAe,EACnC,IAAI,GAAE,MAAM,GAAG,IAAU,EACzB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,aAUjC,MAAM,GAAG,IAAI,GAAG,SAAS,wBACZ,eAAe,KAClC,MAAM,CAeT"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { NestedClassName } from '@contember/utilities';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for component class name accepting outer class name with theme-* and scheme-* class manes
|
|
4
|
-
*
|
|
5
|
-
* It looks for theme CSS classes in the given class name, deduplicates them and returns final theme class name with scheme CSS class set
|
|
6
|
-
* @internal
|
|
7
|
-
*
|
|
8
|
-
* @param componentClassName - Component class name
|
|
9
|
-
* @param additionalClassName - Additional class name
|
|
10
|
-
* @param prefixOverride - Context component prefix override
|
|
11
|
-
* @returns string
|
|
12
|
-
* @see useColorScheme
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* function Button({ className }: { className?: string | string[] }) {
|
|
17
|
-
* const [contentThemeClassName, controlsThemeClassName] = useThemedClassName(className)
|
|
18
|
-
*
|
|
19
|
-
* return (
|
|
20
|
-
* <div className={contentThemeClassName}>
|
|
21
|
-
* <button className={controlsThemeClassName}>Click me</button>
|
|
22
|
-
* </div>
|
|
23
|
-
* )
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* function App() {
|
|
27
|
-
* return (
|
|
28
|
-
* <Button className="theme-default theme-danger:hover" />
|
|
29
|
-
* )
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* // renders:
|
|
33
|
-
* // <div class="scheme-system theme-default-content theme-danger-content:hover">
|
|
34
|
-
* // <button class="scheme-system theme-default-controls theme-danger-controls:hover">Click me</button>
|
|
35
|
-
* // </div>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function useThemedClassName(componentClassName: NestedClassName, additionalClassName: NestedClassName, prefixOverride?: string | null | undefined): string;
|
|
39
|
-
//# sourceMappingURL=useThemedClassName.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useThemedClassName.d.ts","sourceRoot":"","sources":["../../../src/theming/useThemedClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA+C,MAAM,sBAAsB,CAAA;AAInG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,kBAAkB,CACjC,kBAAkB,EAAE,eAAe,EACnC,mBAAmB,EAAE,eAAe,EACpC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACxC,MAAM,CASR"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { NestedClassName } from '@contember/utilities';
|
|
2
|
-
export declare function useThemedClassNameFactory(componentClassName: NestedClassName, glue?: string | null, prefixOverride?: string | null | undefined): (suffix?: string | null | undefined, additionalClassName?: NestedClassName) => string;
|
|
3
|
-
//# sourceMappingURL=useThemedClassNameFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useThemedClassNameFactory.d.ts","sourceRoot":"","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwF,MAAM,sBAAsB,CAAA;AAM5I,wBAAgB,yBAAyB,CACxC,kBAAkB,EAAE,eAAe,EACnC,IAAI,GAAE,MAAM,GAAG,IAAU,EACzB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,aAYjC,MAAM,GAAG,IAAI,GAAG,SAAS,wBACZ,eAAe,KAClC,MAAM,CAoBT"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'react'
|
|
2
|
-
import { createContext, useContext } from 'react'
|
|
3
|
-
|
|
4
|
-
export function createOptionalContextFactory<T>(name: string, initialValue: T): [Context<T>, () => T] {
|
|
5
|
-
const OptionalContext = createContext<T>(initialValue)
|
|
6
|
-
OptionalContext.displayName = name
|
|
7
|
-
|
|
8
|
-
const useOptionalContext = () => {
|
|
9
|
-
return useContext(OptionalContext) ?? initialValue
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return [OptionalContext, useOptionalContext]
|
|
13
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useRef } from 'react'
|
|
2
|
-
import { useReferentiallyStableCallback } from '../referentiallyStable'
|
|
3
|
-
import { useOnWindowResize } from './useOnWindowResize'
|
|
4
|
-
|
|
5
|
-
function addClassName(
|
|
6
|
-
className: string,
|
|
7
|
-
element: HTMLElement,
|
|
8
|
-
) {
|
|
9
|
-
if (element.classList.contains(className)) {
|
|
10
|
-
element.classList.remove(className)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function removeClassName(
|
|
15
|
-
className: string,
|
|
16
|
-
element: HTMLElement,
|
|
17
|
-
) {
|
|
18
|
-
if (!element.classList.contains(className)) {
|
|
19
|
-
element.classList.add(className)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Adds CSS class during resize event to element
|
|
25
|
-
*
|
|
26
|
-
* - Falls back to document.body when no element is specified
|
|
27
|
-
* - Adds CSS class to element also on the initial load
|
|
28
|
-
* - Uses element.classList directly
|
|
29
|
-
*
|
|
30
|
-
* @param className - CSS class to apply during the resize event
|
|
31
|
-
* @param timeoutToRestore - Timeout in milliseconds to wait before finally removing the CSS class
|
|
32
|
-
* @param element - Optional HTML element to apply CSS class to
|
|
33
|
-
*/
|
|
34
|
-
export function useAddClassNameDuringResize(
|
|
35
|
-
className: string,
|
|
36
|
-
timeoutToRestore: number = 300,
|
|
37
|
-
element?: HTMLElement,
|
|
38
|
-
) {
|
|
39
|
-
const timeoutID = useRef<number>()
|
|
40
|
-
|
|
41
|
-
const addTemporaryClassName = useReferentiallyStableCallback(() => {
|
|
42
|
-
clearTimeout(timeoutID.current)
|
|
43
|
-
removeClassName(className, element ?? document.body)
|
|
44
|
-
|
|
45
|
-
timeoutID.current = setTimeout(() => {
|
|
46
|
-
addClassName(className, element ?? document.body)
|
|
47
|
-
}, timeoutToRestore)
|
|
48
|
-
|
|
49
|
-
return () => {
|
|
50
|
-
clearTimeout(timeoutID.current)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
useLayoutEffect(addTemporaryClassName, [addTemporaryClassName])
|
|
55
|
-
useOnWindowResize(addTemporaryClassName)
|
|
56
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
if (isOpen) {
|
|
6
|
-
const closeOnClickOutside = (event: Event) => {
|
|
7
|
-
const target = event.target
|
|
8
|
-
if (
|
|
9
|
-
target instanceof Node &&
|
|
10
|
-
(!document.body.contains(target) ||
|
|
11
|
-
target === document.body ||
|
|
12
|
-
contents.some(it => it && it.contains(target)))
|
|
13
|
-
) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
if (contents.every(it => it === null)) {
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
close()
|
|
20
|
-
}
|
|
21
|
-
(outside ?? window).addEventListener('click', closeOnClickOutside)
|
|
22
|
-
return () => {
|
|
23
|
-
(outside ?? window).removeEventListener('click', closeOnClickOutside)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}, [close, isOpen, contents, outside])
|
|
27
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useCloseOnEscape = ({ isOpen, close }: { isOpen: boolean, close: () => void }) => {
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
if (isOpen) {
|
|
6
|
-
const closeOnEscapeKey = (event: KeyboardEvent) => {
|
|
7
|
-
if (event.key === 'Escape') {
|
|
8
|
-
close()
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
window.addEventListener('keydown', closeOnEscapeKey)
|
|
12
|
-
|
|
13
|
-
return () => {
|
|
14
|
-
window.removeEventListener('keydown', closeOnEscapeKey)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}, [close, isOpen])
|
|
18
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react'
|
|
2
|
-
import { useWindowSize } from './useWindowSize'
|
|
3
|
-
|
|
4
|
-
export type ContainerWidthContextType = number
|
|
5
|
-
export const ContainerWidthContext = createContext<ContainerWidthContextType | null | undefined>(undefined)
|
|
6
|
-
ContainerWidthContext.displayName = 'ContainerWidthContext'
|
|
7
|
-
|
|
8
|
-
export function useContainerWidth(): number {
|
|
9
|
-
const maybeContainerWidth = useContext(ContainerWidthContext)
|
|
10
|
-
const { width: windowWidth } = useWindowSize()
|
|
11
|
-
|
|
12
|
-
return maybeContainerWidth ?? windowWidth
|
|
13
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { getElementDimensionsCallback, getSizeFromResizeObserverEntryFactory } from '@contember/utilities'
|
|
2
|
-
import { useLayoutEffect, useMemo, useState } from 'react'
|
|
3
|
-
import { useScopedConsoleRef } from '../debug-context'
|
|
4
|
-
import { useReferentiallyStableCallback } from '../referentiallyStable'
|
|
5
|
-
import { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'
|
|
6
|
-
import { useOnElementResize } from './useOnElementResize'
|
|
7
|
-
|
|
8
|
-
export type ElementSize = {
|
|
9
|
-
height: number
|
|
10
|
-
width: number
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Measure HTMLElement
|
|
15
|
-
*
|
|
16
|
-
* @param refOrElement - HTMLElement passed directly or indirectly as RefObject
|
|
17
|
-
* @returns Size vector consisting of width and height properties
|
|
18
|
-
*/
|
|
19
|
-
export function useElementSize(
|
|
20
|
-
refOrElement: RefObjectOrElement<HTMLElement>,
|
|
21
|
-
options: ResizeObserverOptions = {},
|
|
22
|
-
timeout: number = 300,
|
|
23
|
-
): { height: number | undefined, width: number | undefined } {
|
|
24
|
-
const { logged } = useScopedConsoleRef('useElementSize').current
|
|
25
|
-
|
|
26
|
-
const { box = 'border-box' } = options
|
|
27
|
-
const getSizeFromResizeObserverEntry = useMemo(() => getSizeFromResizeObserverEntryFactory(box), [box])
|
|
28
|
-
|
|
29
|
-
const [width, setWidth] = useState<number | undefined>()
|
|
30
|
-
const [height, setHeight] = useState<number | undefined>()
|
|
31
|
-
|
|
32
|
-
logged('dimensions', { width, height })
|
|
33
|
-
|
|
34
|
-
const maybeSetNewDimensions = useReferentiallyStableCallback((dimensions: ElementSize) => {
|
|
35
|
-
if (width !== dimensions.width) {
|
|
36
|
-
setWidth(dimensions.width)
|
|
37
|
-
}
|
|
38
|
-
if (height !== dimensions.height) {
|
|
39
|
-
setHeight(dimensions.height)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
useOnElementResize(refOrElement, entry => {
|
|
44
|
-
const dimensions = logged('useOnElementResize => entry:dimensions', getSizeFromResizeObserverEntry(entry))
|
|
45
|
-
maybeSetNewDimensions(dimensions)
|
|
46
|
-
}, { box }, timeout)
|
|
47
|
-
|
|
48
|
-
useLayoutEffect(() => {
|
|
49
|
-
const element = unwrapRefValue(refOrElement)
|
|
50
|
-
if (element) {
|
|
51
|
-
getElementDimensionsCallback(element, dimensions => maybeSetNewDimensions(dimensions))
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return { height, width }
|
|
56
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { RefObject, useLayoutEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export function useElementTopOffset(ref?: RefObject<HTMLElement>): number | undefined {
|
|
4
|
-
const [offsetTop, setOffsetTop] = useState<number | undefined>(undefined)
|
|
5
|
-
|
|
6
|
-
useLayoutEffect(() => {
|
|
7
|
-
if (!ref?.current) {
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const element = ref.current
|
|
12
|
-
|
|
13
|
-
function updateTopOffsetCallback() {
|
|
14
|
-
setOffsetTop(element.offsetTop)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function updateTopOffsetHandler() {
|
|
18
|
-
requestAnimationFrame(updateTopOffsetCallback)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
updateTopOffsetHandler()
|
|
22
|
-
|
|
23
|
-
const observer = new ResizeObserver(() => {
|
|
24
|
-
requestAnimationFrame(updateTopOffsetCallback)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
observer.observe(element)
|
|
28
|
-
|
|
29
|
-
return () => {
|
|
30
|
-
observer.unobserve(element)
|
|
31
|
-
}
|
|
32
|
-
}, [ref])
|
|
33
|
-
|
|
34
|
-
return offsetTop
|
|
35
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EventHandler, SyntheticEvent, useEffect, useRef } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Similar to useEvent with inferred type for the event parameter according to event type
|
|
5
|
-
*
|
|
6
|
-
* @param type - String, keyof DocumentEventMap, e.g. 'click', 'keydown',...
|
|
7
|
-
* @param callback - EventHandler
|
|
8
|
-
* @returns Stable reference callback
|
|
9
|
-
*/
|
|
10
|
-
export function useEventHandler<E extends SyntheticEvent<any>>(type: E['type'], callback: EventHandler<E>): EventHandler<E> {
|
|
11
|
-
const callbackRef = useRef(callback); callbackRef.current = callback
|
|
12
|
-
|
|
13
|
-
const stableHandler = useRef(function (event: any) {
|
|
14
|
-
return callbackRef.current(event)
|
|
15
|
-
}).current
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
return () => {
|
|
19
|
-
callbackRef.current = () => { }
|
|
20
|
-
}
|
|
21
|
-
}, [])
|
|
22
|
-
|
|
23
|
-
return stableHandler
|
|
24
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import deepEqual from 'fast-deep-equal/es6/index.js'
|
|
2
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
3
|
-
import { useScopedConsoleRef } from '../debug-context'
|
|
4
|
-
import { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'
|
|
5
|
-
|
|
6
|
-
export function useOnElementMutation(
|
|
7
|
-
refOrElement: RefObjectOrElement<HTMLElement | undefined>,
|
|
8
|
-
callback: MutationCallback,
|
|
9
|
-
options: MutationObserverInit = { attributes: true, childList: true, subtree: true },
|
|
10
|
-
) {
|
|
11
|
-
const scopedConsoleRef = useScopedConsoleRef('useOnElementMutation')
|
|
12
|
-
|
|
13
|
-
const callbackRef = useRef(callback); callbackRef.current = callback
|
|
14
|
-
const optionsRef = useRef<MutationObserverInit>(options); optionsRef.current = options
|
|
15
|
-
|
|
16
|
-
const [optionsState, setOptionsState] = useState<MutationObserverInit>(options)
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (!deepEqual(optionsRef.current, options)) {
|
|
20
|
-
setOptionsState(options)
|
|
21
|
-
}
|
|
22
|
-
}, [options])
|
|
23
|
-
|
|
24
|
-
useLayoutEffect(() => {
|
|
25
|
-
const element = unwrapRefValue(refOrElement)
|
|
26
|
-
|
|
27
|
-
if (element) {
|
|
28
|
-
function handler(mutations: MutationRecord[], observer: MutationObserver) {
|
|
29
|
-
scopedConsoleRef.current.logged('element.mutations', mutations)
|
|
30
|
-
callbackRef.current(mutations, observer)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const observer = new MutationObserver(handler)
|
|
34
|
-
|
|
35
|
-
observer.observe(element, optionsState)
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
observer.disconnect()
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}, [optionsState, refOrElement, scopedConsoleRef])
|
|
42
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useRef } from 'react'
|
|
2
|
-
import { useScopedConsoleRef } from '../debug-context'
|
|
3
|
-
import { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Invokes callback on scroll event within the scroll container
|
|
7
|
-
*
|
|
8
|
-
* @param refOrElement - Scroll container
|
|
9
|
-
* @param callback - Callback that is invoked on scroll event
|
|
10
|
-
* @param interval - Specifies how often should scroll event invoke callback
|
|
11
|
-
*/
|
|
12
|
-
export function useOnScrollWithin(
|
|
13
|
-
refOrElement: RefObjectOrElement<HTMLElement | null> | null,
|
|
14
|
-
callback: (event: Event) => void,
|
|
15
|
-
interval: number = 1000 / 60,
|
|
16
|
-
) {
|
|
17
|
-
const scopedConsoleRef = useScopedConsoleRef('useOnScrollWithin')
|
|
18
|
-
|
|
19
|
-
const callbackRef = useRef(callback); callbackRef.current = callback
|
|
20
|
-
const lastTimeStamp = useRef<number>(0)
|
|
21
|
-
|
|
22
|
-
useLayoutEffect(() => {
|
|
23
|
-
const element = unwrapRefValue(refOrElement)
|
|
24
|
-
|
|
25
|
-
let timeoutID: number | undefined = undefined
|
|
26
|
-
|
|
27
|
-
if (element) {
|
|
28
|
-
function debouncedHandler(event: Event) {
|
|
29
|
-
clearTimeout(timeoutID)
|
|
30
|
-
|
|
31
|
-
const delta = event.timeStamp - lastTimeStamp.current
|
|
32
|
-
scopedConsoleRef.current.logged('event:element.scroll:delta', delta)
|
|
33
|
-
|
|
34
|
-
if (delta > interval) {
|
|
35
|
-
scopedConsoleRef.current.warned('event:element.scroll:immediately', event)
|
|
36
|
-
callbackRef.current(event)
|
|
37
|
-
lastTimeStamp.current = event.timeStamp
|
|
38
|
-
} else {
|
|
39
|
-
timeoutID = setTimeout(() => {
|
|
40
|
-
scopedConsoleRef.current.warned('event:element.scroll:debounced', event)
|
|
41
|
-
lastTimeStamp.current = event.timeStamp
|
|
42
|
-
callbackRef.current(event)
|
|
43
|
-
}, interval)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (element instanceof HTMLElement) {
|
|
48
|
-
if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
|
|
49
|
-
window.addEventListener('scroll', debouncedHandler, { capture: true, passive: true })
|
|
50
|
-
window.addEventListener('resize', debouncedHandler)
|
|
51
|
-
|
|
52
|
-
return () => {
|
|
53
|
-
window.removeEventListener('scroll', debouncedHandler)
|
|
54
|
-
window.removeEventListener('resize', debouncedHandler)
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
element.addEventListener('scroll', debouncedHandler, { passive: true, capture: true })
|
|
58
|
-
|
|
59
|
-
return () => {
|
|
60
|
-
element.removeEventListener('scroll', debouncedHandler)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
throw new Error('Exhaustive error: Expecting element to be instance of HTMLElement')
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, [interval, refOrElement, scopedConsoleRef])
|
|
68
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { assert, getElementDimensions } from '@contember/utilities'
|
|
2
|
-
import { useLayoutEffect, useMemo, useState } from 'react'
|
|
3
|
-
import { useScopedConsoleRef } from '../debug-context'
|
|
4
|
-
import { useReferentiallyStableCallback } from '../referentiallyStable'
|
|
5
|
-
import { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'
|
|
6
|
-
import { useOnScrollWithin } from './useOnScrollWithin'
|
|
7
|
-
import { useOnWindowResize } from './useOnWindowResize'
|
|
8
|
-
|
|
9
|
-
export type Offsets = {
|
|
10
|
-
bottom: number;
|
|
11
|
-
left: number;
|
|
12
|
-
right: number;
|
|
13
|
-
top: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function useScrollOffsets(refOrElement: RefObjectOrElement<HTMLElement | null> | null, interval: number = 1000 / 60) {
|
|
17
|
-
const { logged } = useScopedConsoleRef('useScrollOffsets').current
|
|
18
|
-
|
|
19
|
-
const [top, setTop] = useState(0)
|
|
20
|
-
const [bottom, setBottom] = useState(0)
|
|
21
|
-
const [left, setLeft] = useState(0)
|
|
22
|
-
const [right, setRight] = useState(0)
|
|
23
|
-
|
|
24
|
-
const updateScrollOffsetsState = useReferentiallyStableCallback((offsets: Offsets) => {
|
|
25
|
-
logged('Update the offsets:', {
|
|
26
|
-
previous: { bottom, left, right, top },
|
|
27
|
-
next: offsets,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (offsets.bottom !== bottom) setBottom(offsets.bottom)
|
|
31
|
-
if (offsets.left !== left) setLeft(offsets.left)
|
|
32
|
-
if (offsets.right !== right) setRight(offsets.right)
|
|
33
|
-
if (offsets.top !== top) setTop(offsets.top)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const handler = useReferentiallyStableCallback(() => {
|
|
37
|
-
const maybeScrollContent = unwrapRefValue(refOrElement) ?? document
|
|
38
|
-
|
|
39
|
-
if (maybeScrollContent) {
|
|
40
|
-
getElementScrollOffsets(maybeScrollContent).then(updateScrollOffsetsState)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
useOnScrollWithin(refOrElement, handler, interval)
|
|
45
|
-
useOnWindowResize(handler)
|
|
46
|
-
useLayoutEffect(handler, [handler])
|
|
47
|
-
|
|
48
|
-
return useMemo(() => ({ bottom, left, right, top }), [bottom, left, right, top])
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function isIntrinsicScrollElement(element: unknown): element is Document {
|
|
52
|
-
return element instanceof HTMLBodyElement
|
|
53
|
-
|| element instanceof HTMLHtmlElement
|
|
54
|
-
|| element instanceof DocumentType
|
|
55
|
-
|| element instanceof Document
|
|
56
|
-
|| element instanceof HTMLDocument
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getIntrinsicScrollContainer(element: HTMLElement | Document): HTMLElement {
|
|
60
|
-
const html = document.body.parentElement
|
|
61
|
-
assert('HTML element exists', html, (value): value is HTMLElement => value instanceof HTMLElement)
|
|
62
|
-
|
|
63
|
-
if (isIntrinsicScrollElement(element)) {
|
|
64
|
-
return html
|
|
65
|
-
} else {
|
|
66
|
-
return element
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function getElementScrollOffsets(element: HTMLElement | Document): Promise<Offsets> {
|
|
71
|
-
const isIntrinsicScrolling = isIntrinsicScrollElement(element)
|
|
72
|
-
const scrollContainer = getIntrinsicScrollContainer(element)
|
|
73
|
-
|
|
74
|
-
const { scrollLeft, scrollTop, scrollHeight, scrollWidth } = scrollContainer
|
|
75
|
-
const { height: scrollContainerHeight, width: scrollContainerWidth } = await getElementDimensions(scrollContainer)
|
|
76
|
-
|
|
77
|
-
const height = isIntrinsicScrolling ? window.innerHeight : scrollContainerHeight
|
|
78
|
-
const width = isIntrinsicScrolling ? window.innerWidth : scrollContainerWidth
|
|
79
|
-
|
|
80
|
-
const left = Math.round(scrollLeft)
|
|
81
|
-
const top = Math.round(scrollTop)
|
|
82
|
-
|
|
83
|
-
const right = Math.round(scrollWidth - width - left)
|
|
84
|
-
const bottom = Math.round(scrollHeight - height - top)
|
|
85
|
-
|
|
86
|
-
return { bottom, left, right, top }
|
|
87
|
-
}
|