@contember/react-utils 2.1.0-beta.2 → 2.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/debug-context/Constants.cjs.map +1 -1
- package/dist/development/src/debug-context/Constants.js.map +1 -1
- package/dist/development/src/debug-context/Context.cjs.map +1 -1
- package/dist/development/src/debug-context/Context.js.map +1 -1
- package/dist/development/src/hooks/useArrayMapMemo.cjs.map +1 -1
- package/dist/development/src/hooks/useArrayMapMemo.js.map +1 -1
- package/dist/development/src/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/development/src/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/development/src/hooks/useConstantLengthInvariant.cjs.map +1 -1
- package/dist/development/src/hooks/useConstantLengthInvariant.js.map +1 -1
- package/dist/development/src/hooks/useConstantValueInvariant.cjs.map +1 -1
- package/dist/development/src/hooks/useConstantValueInvariant.js.map +1 -1
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.cjs.map +1 -1
- package/dist/development/src/hooks/useOnElementClickOutsideCallback.js.map +1 -1
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -1
- package/dist/development/src/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -1
- package/dist/development/src/hooks/useOnElementResize.cjs.map +1 -1
- package/dist/development/src/hooks/useOnElementResize.js.map +1 -1
- package/dist/development/src/hooks/useOnWindowResize.cjs.map +1 -1
- package/dist/development/src/hooks/useOnWindowResize.js.map +1 -1
- package/dist/development/src/hooks/useStoredState.cjs.map +1 -1
- package/dist/development/src/hooks/useStoredState.js.map +1 -1
- package/dist/development/src/hooks/useWindowSize.cjs.map +1 -1
- package/dist/development/src/hooks/useWindowSize.js.map +1 -1
- package/dist/production/src/debug-context/Constants.cjs.map +1 -1
- package/dist/production/src/debug-context/Constants.js.map +1 -1
- package/dist/production/src/debug-context/Context.cjs.map +1 -1
- package/dist/production/src/debug-context/Context.js.map +1 -1
- package/dist/production/src/hooks/useArrayMapMemo.cjs.map +1 -1
- package/dist/production/src/hooks/useArrayMapMemo.js.map +1 -1
- package/dist/production/src/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/production/src/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/production/src/hooks/useConstantLengthInvariant.cjs.map +1 -1
- package/dist/production/src/hooks/useConstantLengthInvariant.js.map +1 -1
- package/dist/production/src/hooks/useConstantValueInvariant.cjs.map +1 -1
- package/dist/production/src/hooks/useConstantValueInvariant.js.map +1 -1
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.cjs.map +1 -1
- package/dist/production/src/hooks/useOnElementClickOutsideCallback.js.map +1 -1
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -1
- package/dist/production/src/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -1
- package/dist/production/src/hooks/useOnElementResize.cjs.map +1 -1
- package/dist/production/src/hooks/useOnElementResize.js.map +1 -1
- package/dist/production/src/hooks/useOnWindowResize.cjs.map +1 -1
- package/dist/production/src/hooks/useOnWindowResize.js.map +1 -1
- package/dist/production/src/hooks/useStoredState.cjs.map +1 -1
- package/dist/production/src/hooks/useStoredState.js.map +1 -1
- package/dist/production/src/hooks/useWindowSize.cjs.map +1 -1
- package/dist/production/src/hooks/useWindowSize.js.map +1 -1
- package/dist/types/context/index.d.ts +2 -2
- package/dist/types/context/index.d.ts.map +1 -1
- package/dist/types/debug-context/Constants.d.ts +1 -1
- package/dist/types/debug-context/Constants.d.ts.map +1 -1
- package/dist/types/debug-context/Context.d.ts +1 -1
- package/dist/types/debug-context/Context.d.ts.map +1 -1
- package/dist/types/debug-context/index.d.ts +3 -3
- package/dist/types/debug-context/index.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +24 -24
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useAutoHeightTextArea.d.ts +1 -1
- package/dist/types/hooks/useAutoHeightTextArea.d.ts.map +1 -1
- package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts +1 -1
- package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts.map +1 -1
- package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts +1 -1
- package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts.map +1 -1
- package/dist/types/hooks/useOnElementResize.d.ts +1 -1
- package/dist/types/hooks/useOnElementResize.d.ts.map +1 -1
- package/dist/types/hooks/useStoredState.d.ts +106 -1
- package/dist/types/hooks/useStoredState.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/referentiallyStable/index.d.ts +7 -7
- package/dist/types/referentiallyStable/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context/index.ts +2 -2
- package/src/debug-context/Constants.ts +1 -1
- package/src/debug-context/Context.tsx +2 -2
- package/src/debug-context/index.ts +3 -3
- package/src/hooks/index.ts +24 -24
- package/src/hooks/useArrayMapMemo.ts +1 -1
- package/src/hooks/useAutoHeightTextArea.ts +2 -2
- package/src/hooks/useConstantLengthInvariant.ts +1 -1
- package/src/hooks/useConstantValueInvariant.ts +1 -1
- package/src/hooks/useOnElementClickOutsideCallback.ts +1 -1
- package/src/hooks/useOnElementMouseEnterDelayedCallback.ts +1 -1
- package/src/hooks/useOnElementResize.ts +2 -2
- package/src/hooks/useOnWindowResize.ts +1 -1
- package/src/hooks/useStoredState.ts +106 -1
- package/src/hooks/useWindowSize.ts +1 -1
- package/src/index.ts +5 -5
- package/src/referentiallyStable/index.ts +7 -7
- package/src/types/index.ts +2 -2
- package/tests/hooks/useChildrenAsLabel.test.tsx +1 -1
- package/tests/hooks/useId.test.ts +1 -1
|
@@ -1 +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;;"}
|
|
1
|
+
{"version":3,"file":"useOnElementClickOutsideCallback.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;;"}
|
|
@@ -1 +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;"}
|
|
1
|
+
{"version":3,"file":"useOnElementClickOutsideCallback.js","sources":["../../../../../packages/react-utils/src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;"}
|
|
@@ -1 +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;;"}
|
|
1
|
+
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.cjs","sources":["../../../../../packages/react-utils/src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;;"}
|
|
@@ -1 +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;"}
|
|
1
|
+
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.js","sources":["../../../../../packages/react-utils/src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;"}
|
|
@@ -1 +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;;"}
|
|
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/index.js'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;;"}
|
|
@@ -1 +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;"}
|
|
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/index.js'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue.js'\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;"}
|
|
@@ -1 +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;;"}
|
|
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/index.js'\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;;"}
|
|
@@ -1 +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;"}
|
|
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/index.js'\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;"}
|
|
@@ -1 +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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"}
|
|
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/index.js'\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\n/**\n * `urlStateStorage` is a `StateStorage` implementation that persists state in the URL query parameters.\n * This allows state persistence across page reloads and enables sharing state via URL.\n *\n * ## Example: Storing state in the URL\n * ```tsx\n * urlStateStorage.setItem(['app', 'theme'], 'dark'); // URL updates to: `?theme=\"dark\"`\n * console.log(urlStateStorage.getItem(['app', 'theme'])); // Output: \"dark\"\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\n/**\n * A `StateStorage` instance that persists state using `sessionStorage`.\n *\n * This storage mechanism automatically serializes and deserializes stored values using JSON.\n * It is useful for storing temporary state that should persist across page reloads but be cleared when the session ends.\n *\n * ## Example: Storing a theme preference in session storage\n * ```tsx\n * sessionStateStorage.setItem(['app', 'theme'], 'dark');\n * console.log(sessionStateStorage.getItem(['app', 'theme'])); // Output: \"dark\"\n * ```\n */\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\n/**\n * A `StateStorage` instance that persists state using `localStorage`.\n *\n * This storage mechanism automatically serializes and deserializes stored values using JSON.\n * It is useful for storing persistent state that remains available even after closing and reopening the browser.\n *\n * ## Example: Storing a username in local storage\n * ```tsx\n * localStateStorage.setItem(['user', 'name'], 'Alice');\n * console.log(localStateStorage.getItem(['user', 'name'])); // Output: \"Alice\"\n * ```\n */\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\n/**\n * `useStoredState` provides a persistent state using different storage options such as\n * URL, `sessionStorage`, `localStorage`, or a custom storage mechanism.\n *\n * This hook initializes state from the selected storage and updates it whenever the state changes.\n *\n * ## Example: Using session storage\n * ```tsx\n * const [count, setCount] = useStoredState<number>('session', ['app', 'counter'], storedValue => storedValue ?? 0);\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(prev => prev + 1)}>Increment</button>\n * </div>\n * );\n * ```\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\n/**\n * `useSessionStorageState` is a specialized hook for persisting state in `sessionStorage`.\n * It initializes state from `sessionStorage` on first render and updates it whenever the state changes.\n *\n * ## Example: Persisting theme in session storage\n * ```tsx\n * const [theme, setTheme] = useSessionStorageState(['app', 'theme'], storedValue => storedValue ?? 'light');\n *\n * return (\n * <div>\n * <p>Current Theme: {theme}</p>\n * <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>\n * Toggle Theme\n * </button>\n * </div>\n * );\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\n/**\n * `useLocalStorageState` is a specialized hook for persisting state in `localStorage`.\n * It initializes state from `localStorage` on first render and updates it whenever the state changes.\n *\n * ## Example: Persisting username in local storage\n * ```tsx\n * const [username, setUsername] = useLocalStorageState(['user', 'name'], storedValue => storedValue ?? 'Guest');\n *\n * return (\n * <div>\n * <p>Username: {username}</p>\n * <input\n * type=\"text\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * placeholder=\"Enter your name\"\n * />\n * </div>\n * );\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\n/**\n * Retrieves the appropriate storage mechanism based on the provided storage type or custom storage instance.\n * Supports fallback mechanisms when multiple storage options are provided as an array.\n *\n * ## Example: Using a single storage type\n * ```tsx\n * const storage = getStateStorage('local'); // Retrieves localStorage\n * ```\n *\n * ## Example: Using fallback storages\n * ```tsx\n * const storage = getStateStorage(['session', 'local']); // Uses sessionStorage, falls back to localStorage\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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"}
|
|
@@ -1 +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":";
|
|
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/index.js'\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\n/**\n * `urlStateStorage` is a `StateStorage` implementation that persists state in the URL query parameters.\n * This allows state persistence across page reloads and enables sharing state via URL.\n *\n * ## Example: Storing state in the URL\n * ```tsx\n * urlStateStorage.setItem(['app', 'theme'], 'dark'); // URL updates to: `?theme=\"dark\"`\n * console.log(urlStateStorage.getItem(['app', 'theme'])); // Output: \"dark\"\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\n/**\n * A `StateStorage` instance that persists state using `sessionStorage`.\n *\n * This storage mechanism automatically serializes and deserializes stored values using JSON.\n * It is useful for storing temporary state that should persist across page reloads but be cleared when the session ends.\n *\n * ## Example: Storing a theme preference in session storage\n * ```tsx\n * sessionStateStorage.setItem(['app', 'theme'], 'dark');\n * console.log(sessionStateStorage.getItem(['app', 'theme'])); // Output: \"dark\"\n * ```\n */\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\n/**\n * A `StateStorage` instance that persists state using `localStorage`.\n *\n * This storage mechanism automatically serializes and deserializes stored values using JSON.\n * It is useful for storing persistent state that remains available even after closing and reopening the browser.\n *\n * ## Example: Storing a username in local storage\n * ```tsx\n * localStateStorage.setItem(['user', 'name'], 'Alice');\n * console.log(localStateStorage.getItem(['user', 'name'])); // Output: \"Alice\"\n * ```\n */\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\n/**\n * `useStoredState` provides a persistent state using different storage options such as\n * URL, `sessionStorage`, `localStorage`, or a custom storage mechanism.\n *\n * This hook initializes state from the selected storage and updates it whenever the state changes.\n *\n * ## Example: Using session storage\n * ```tsx\n * const [count, setCount] = useStoredState<number>('session', ['app', 'counter'], storedValue => storedValue ?? 0);\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(prev => prev + 1)}>Increment</button>\n * </div>\n * );\n * ```\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\n/**\n * `useSessionStorageState` is a specialized hook for persisting state in `sessionStorage`.\n * It initializes state from `sessionStorage` on first render and updates it whenever the state changes.\n *\n * ## Example: Persisting theme in session storage\n * ```tsx\n * const [theme, setTheme] = useSessionStorageState(['app', 'theme'], storedValue => storedValue ?? 'light');\n *\n * return (\n * <div>\n * <p>Current Theme: {theme}</p>\n * <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>\n * Toggle Theme\n * </button>\n * </div>\n * );\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\n/**\n * `useLocalStorageState` is a specialized hook for persisting state in `localStorage`.\n * It initializes state from `localStorage` on first render and updates it whenever the state changes.\n *\n * ## Example: Persisting username in local storage\n * ```tsx\n * const [username, setUsername] = useLocalStorageState(['user', 'name'], storedValue => storedValue ?? 'Guest');\n *\n * return (\n * <div>\n * <p>Username: {username}</p>\n * <input\n * type=\"text\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * placeholder=\"Enter your name\"\n * />\n * </div>\n * );\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\n/**\n * Retrieves the appropriate storage mechanism based on the provided storage type or custom storage instance.\n * Supports fallback mechanisms when multiple storage options are provided as an array.\n *\n * ## Example: Using a single storage type\n * ```tsx\n * const storage = getStateStorage('local'); // Retrieves localStorage\n * ```\n *\n * ## Example: Using fallback storages\n * ```tsx\n * const storage = getStateStorage(['session', 'local']); // Uses sessionStorage, falls back to localStorage\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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.cjs","sources":["../../../../../packages/react-utils/src/hooks/useWindowSize.ts"],"sourcesContent":["import { useMemo, useState } from 'react'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nexport function useWindowSize() {\n\tconst [width, setWidth] = useState(window.innerWidth)\n\tconst [height, setHeight] = useState(window.innerHeight)\n\n\tuseOnWindowResize(() => {\n\t\tconst { innerHeight, innerWidth } = window\n\t\tif (innerHeight !== height) {\n\t\t\tsetHeight(innerHeight)\n\t\t}\n\n\t\tif (innerWidth !== width) {\n\t\t\tsetWidth(innerWidth)\n\t\t}\n\t})\n\n\treturn useMemo(() => ({ height, width }), [height, width])\n}\n"],"names":["useState","useOnWindowResize","useMemo"],"mappings":";;;;AAGO,SAAS,gBAAgB;AAC/B,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAS,OAAO,UAAU;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAIA,MAAAA,SAAS,OAAO,WAAW;AAEvDC,oBAAAA,kBAAkB,MAAM;AACvB,UAAM,EAAE,aAAa,WAAA,IAAe;AACpC,QAAI,gBAAgB,QAAQ;AAC3B,gBAAU,WAAW;AAAA,IACtB;AAEA,QAAI,eAAe,OAAO;AACzB,eAAS,UAAU;AAAA,IACpB;AAAA,EACD,CAAC;AAED,SAAOC,MAAAA,QAAQ,OAAO,EAAE,QAAQ,UAAU,CAAC,QAAQ,KAAK,CAAC;AAC1D;;"}
|
|
1
|
+
{"version":3,"file":"useWindowSize.cjs","sources":["../../../../../packages/react-utils/src/hooks/useWindowSize.ts"],"sourcesContent":["import { useMemo, useState } from 'react'\nimport { useOnWindowResize } from './useOnWindowResize.js'\n\nexport function useWindowSize() {\n\tconst [width, setWidth] = useState(window.innerWidth)\n\tconst [height, setHeight] = useState(window.innerHeight)\n\n\tuseOnWindowResize(() => {\n\t\tconst { innerHeight, innerWidth } = window\n\t\tif (innerHeight !== height) {\n\t\t\tsetHeight(innerHeight)\n\t\t}\n\n\t\tif (innerWidth !== width) {\n\t\t\tsetWidth(innerWidth)\n\t\t}\n\t})\n\n\treturn useMemo(() => ({ height, width }), [height, width])\n}\n"],"names":["useState","useOnWindowResize","useMemo"],"mappings":";;;;AAGO,SAAS,gBAAgB;AAC/B,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAS,OAAO,UAAU;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAIA,MAAAA,SAAS,OAAO,WAAW;AAEvDC,oBAAAA,kBAAkB,MAAM;AACvB,UAAM,EAAE,aAAa,WAAA,IAAe;AACpC,QAAI,gBAAgB,QAAQ;AAC3B,gBAAU,WAAW;AAAA,IACtB;AAEA,QAAI,eAAe,OAAO;AACzB,eAAS,UAAU;AAAA,IACpB;AAAA,EACD,CAAC;AAED,SAAOC,MAAAA,QAAQ,OAAO,EAAE,QAAQ,UAAU,CAAC,QAAQ,KAAK,CAAC;AAC1D;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.js","sources":["../../../../../packages/react-utils/src/hooks/useWindowSize.ts"],"sourcesContent":["import { useMemo, useState } from 'react'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nexport function useWindowSize() {\n\tconst [width, setWidth] = useState(window.innerWidth)\n\tconst [height, setHeight] = useState(window.innerHeight)\n\n\tuseOnWindowResize(() => {\n\t\tconst { innerHeight, innerWidth } = window\n\t\tif (innerHeight !== height) {\n\t\t\tsetHeight(innerHeight)\n\t\t}\n\n\t\tif (innerWidth !== width) {\n\t\t\tsetWidth(innerWidth)\n\t\t}\n\t})\n\n\treturn useMemo(() => ({ height, width }), [height, width])\n}\n"],"names":[],"mappings":";;AAGO,SAAS,gBAAgB;AAC/B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,OAAO,UAAU;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,OAAO,WAAW;AAEvD,oBAAkB,MAAM;AACvB,UAAM,EAAE,aAAa,WAAA,IAAe;AACpC,QAAI,gBAAgB,QAAQ;AAC3B,gBAAU,WAAW;AAAA,IACtB;AAEA,QAAI,eAAe,OAAO;AACzB,eAAS,UAAU;AAAA,IACpB;AAAA,EACD,CAAC;AAED,SAAO,QAAQ,OAAO,EAAE,QAAQ,UAAU,CAAC,QAAQ,KAAK,CAAC;AAC1D;"}
|
|
1
|
+
{"version":3,"file":"useWindowSize.js","sources":["../../../../../packages/react-utils/src/hooks/useWindowSize.ts"],"sourcesContent":["import { useMemo, useState } from 'react'\nimport { useOnWindowResize } from './useOnWindowResize.js'\n\nexport function useWindowSize() {\n\tconst [width, setWidth] = useState(window.innerWidth)\n\tconst [height, setHeight] = useState(window.innerHeight)\n\n\tuseOnWindowResize(() => {\n\t\tconst { innerHeight, innerWidth } = window\n\t\tif (innerHeight !== height) {\n\t\t\tsetHeight(innerHeight)\n\t\t}\n\n\t\tif (innerWidth !== width) {\n\t\t\tsetWidth(innerWidth)\n\t\t}\n\t})\n\n\treturn useMemo(() => ({ height, width }), [height, width])\n}\n"],"names":[],"mappings":";;AAGO,SAAS,gBAAgB;AAC/B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,OAAO,UAAU;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,OAAO,WAAW;AAEvD,oBAAkB,MAAM;AACvB,UAAM,EAAE,aAAa,WAAA,IAAe;AACpC,QAAI,gBAAgB,QAAQ;AAC3B,gBAAU,WAAW;AAAA,IACtB;AAEA,QAAI,eAAe,OAAO;AACzB,eAAS,UAAU;AAAA,IACpB;AAAA,EACD,CAAC;AAED,SAAO,QAAQ,OAAO,EAAE,QAAQ,UAAU,CAAC,QAAQ,KAAK,CAAC;AAC1D;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './createRequiredContext';
|
|
2
|
-
export * from './createContext';
|
|
1
|
+
export * from './createRequiredContext.js';
|
|
2
|
+
export * from './createContext.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ScopedConsoleContextType } from './Types';
|
|
1
|
+
import type { ScopedConsoleContextType } from './Types.js';
|
|
2
2
|
export declare function noopLog(...parameters: any[]): void;
|
|
3
3
|
export declare function noopLogged<T>(message: string, value: T): T;
|
|
4
4
|
export declare const noopScopedConsole: ScopedConsoleContextType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,wBAAgB,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,QAAI;AAEhD,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAE1D;AAED,eAAO,MAAM,iBAAiB,EAAE,wBAS9B,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { ScopedConsoleContextType } from './Types';
|
|
2
|
+
import { ScopedConsoleContextType } from './Types.js';
|
|
3
3
|
export declare const ScopedConsoleContext: import("react").Context<ScopedConsoleContextType>;
|
|
4
4
|
export declare const useScopedConsoleRef: (prefix: string, override?: boolean) => import("react").RefObject<ScopedConsoleContextType>;
|
|
5
5
|
export type DebugChildrenProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAA+B,MAAM,OAAO,CAAA;AAEnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAA+B,MAAM,OAAO,CAAA;AAEnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAmCrD,eAAO,MAAM,oBAAoB,mDAAiD,CAAA;AAOlF,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,WAAW,OAAO,wDAkBrE,CAAA;AAED,MAAM,MAAM,kBAAkB,GAC3B;IAAE,MAAM,CAAC,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvD,eAAO,MAAM,aAAa,0DAYxB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './Constants';
|
|
2
|
-
export * from './Context';
|
|
3
|
-
export * from './Types';
|
|
1
|
+
export * from './Constants.js';
|
|
2
|
+
export * from './Context.js';
|
|
3
|
+
export * from './Types.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/debug-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/debug-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export * from './unwrapRefValue';
|
|
2
|
-
export * from './useAbortController';
|
|
3
|
-
export * from './useArrayMapMemo';
|
|
4
|
-
export * from './useAutoHeightTextArea';
|
|
5
|
-
export * from './useChildrenAsLabel';
|
|
6
|
-
export * from './useComposeRef';
|
|
7
|
-
export * from './useConstantLengthInvariant';
|
|
8
|
-
export * from './useConstantValueInvariant';
|
|
9
|
-
export * from './useDebounce';
|
|
10
|
-
export * from './useDebounceCallback';
|
|
11
|
-
export * from './useDocumentTitle';
|
|
12
|
-
export * from './useExpectSameValueReference';
|
|
13
|
-
export * from './useForceRender';
|
|
14
|
-
export * from './useId';
|
|
15
|
-
export * from './useIsMounted';
|
|
16
|
-
export * from './useObjectMemo';
|
|
17
|
-
export * from './useOnElementClickOutsideCallback';
|
|
18
|
-
export * from './useOnElementMouseEnterDelayedCallback';
|
|
19
|
-
export * from './useOnElementResize';
|
|
20
|
-
export * from './useOnWindowResize';
|
|
21
|
-
export * from './usePreviousValue';
|
|
22
|
-
export * from './useStoredState';
|
|
23
|
-
export * from './useUpdatedRef';
|
|
24
|
-
export * from './useWindowSize';
|
|
1
|
+
export * from './unwrapRefValue.js';
|
|
2
|
+
export * from './useAbortController.js';
|
|
3
|
+
export * from './useArrayMapMemo.js';
|
|
4
|
+
export * from './useAutoHeightTextArea.js';
|
|
5
|
+
export * from './useChildrenAsLabel.js';
|
|
6
|
+
export * from './useComposeRef.js';
|
|
7
|
+
export * from './useConstantLengthInvariant.js';
|
|
8
|
+
export * from './useConstantValueInvariant.js';
|
|
9
|
+
export * from './useDebounce.js';
|
|
10
|
+
export * from './useDebounceCallback.js';
|
|
11
|
+
export * from './useDocumentTitle.js';
|
|
12
|
+
export * from './useExpectSameValueReference.js';
|
|
13
|
+
export * from './useForceRender.js';
|
|
14
|
+
export * from './useId.js';
|
|
15
|
+
export * from './useIsMounted.js';
|
|
16
|
+
export * from './useObjectMemo.js';
|
|
17
|
+
export * from './useOnElementClickOutsideCallback.js';
|
|
18
|
+
export * from './useOnElementMouseEnterDelayedCallback.js';
|
|
19
|
+
export * from './useOnElementResize.js';
|
|
20
|
+
export * from './useOnWindowResize.js';
|
|
21
|
+
export * from './usePreviousValue.js';
|
|
22
|
+
export * from './useStoredState.js';
|
|
23
|
+
export * from './useUpdatedRef.js';
|
|
24
|
+
export * from './useWindowSize.js';
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kCAAkC,CAAA;AAChD,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uCAAuC,CAAA;AACrD,cAAc,4CAA4C,CAAA;AAC1D,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
1
|
+
import { RefObjectOrElement } from './unwrapRefValue.js';
|
|
2
2
|
export declare const useAutoHeightTextArea: (textAreaRef: RefObjectOrElement<HTMLTextAreaElement>, value: string, minRows: number, maxRows: number) => void;
|
|
3
3
|
//# sourceMappingURL=useAutoHeightTextArea.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoHeightTextArea.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,
|
|
1
|
+
{"version":3,"file":"useAutoHeightTextArea.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,qBAAqB,CAAA;AAOxE,eAAO,MAAM,qBAAqB,GACjC,aAAa,kBAAkB,CAAC,mBAAmB,CAAC,EACpD,OAAO,MAAM,EACb,SAAS,MAAM,EACf,SAAS,MAAM,SA0Cf,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
1
|
+
import { RefObjectOrElement } from './unwrapRefValue.js';
|
|
2
2
|
export declare function useOnElementClickOutsideCallback(refOrElement: RefObjectOrElement<HTMLElement>, callback: (event: MouseEvent) => void): void;
|
|
3
3
|
//# sourceMappingURL=useOnElementClickOutsideCallback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnElementClickOutsideCallback.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementClickOutsideCallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,
|
|
1
|
+
{"version":3,"file":"useOnElementClickOutsideCallback.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementClickOutsideCallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,qBAAqB,CAAA;AAExE,wBAAgB,gCAAgC,CAC/C,YAAY,EAAE,kBAAkB,CAAC,WAAW,CAAC,EAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GACnC,IAAI,CAgBN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,
|
|
1
|
+
{"version":3,"file":"useOnElementMouseEnterDelayedCallback.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,qBAAqB,CAAA;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,qCAAqC,CACpD,YAAY,EAAE,kBAAkB,CAAC,WAAW,CAAC,EAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACrC,SAAS,GAAE,MAAY,GACrB,IAAI,CAmCN"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RefObjectOrElement } from './unwrapRefValue';
|
|
1
|
+
import { RefObjectOrElement } from './unwrapRefValue.js';
|
|
2
2
|
export declare function useOnElementResize(refOrElement: RefObjectOrElement<HTMLElement | null> | null, callback: (entries: ResizeObserverEntry) => void, options?: ResizeObserverOptions, timeout?: number): void;
|
|
3
3
|
//# sourceMappingURL=useOnElementResize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnElementResize.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementResize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,
|
|
1
|
+
{"version":3,"file":"useOnElementResize.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOnElementResize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,qBAAqB,CAAA;AAExE,wBAAgB,kBAAkB,CACjC,YAAY,EAAE,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,IAAI,EAC3D,QAAQ,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,EAChD,OAAO,GAAE,qBAA0B,EACnC,OAAO,GAAE,MAAY,GACnB,IAAI,CA2CN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Serializable } from '../types';
|
|
1
|
+
import { Serializable } from '../types/index.js';
|
|
2
2
|
export type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;
|
|
3
3
|
export type StateStorageKey = [uniquePrefix: string, key: string];
|
|
4
4
|
export type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;
|
|
@@ -6,13 +6,118 @@ export interface StateStorage {
|
|
|
6
6
|
getItem(key: StateStorageKey): Serializable;
|
|
7
7
|
setItem(key: StateStorageKey, value: Serializable): void;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* `urlStateStorage` is a `StateStorage` implementation that persists state in the URL query parameters.
|
|
11
|
+
* This allows state persistence across page reloads and enables sharing state via URL.
|
|
12
|
+
*
|
|
13
|
+
* ## Example: Storing state in the URL
|
|
14
|
+
* ```tsx
|
|
15
|
+
* urlStateStorage.setItem(['app', 'theme'], 'dark'); // URL updates to: `?theme="dark"`
|
|
16
|
+
* console.log(urlStateStorage.getItem(['app', 'theme'])); // Output: "dark"
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
9
19
|
export declare const urlStateStorage: StateStorage;
|
|
20
|
+
/**
|
|
21
|
+
* A `StateStorage` instance that persists state using `sessionStorage`.
|
|
22
|
+
*
|
|
23
|
+
* This storage mechanism automatically serializes and deserializes stored values using JSON.
|
|
24
|
+
* It is useful for storing temporary state that should persist across page reloads but be cleared when the session ends.
|
|
25
|
+
*
|
|
26
|
+
* ## Example: Storing a theme preference in session storage
|
|
27
|
+
* ```tsx
|
|
28
|
+
* sessionStateStorage.setItem(['app', 'theme'], 'dark');
|
|
29
|
+
* console.log(sessionStateStorage.getItem(['app', 'theme'])); // Output: "dark"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
10
32
|
export declare const sessionStateStorage: StateStorage;
|
|
33
|
+
/**
|
|
34
|
+
* A `StateStorage` instance that persists state using `localStorage`.
|
|
35
|
+
*
|
|
36
|
+
* This storage mechanism automatically serializes and deserializes stored values using JSON.
|
|
37
|
+
* It is useful for storing persistent state that remains available even after closing and reopening the browser.
|
|
38
|
+
*
|
|
39
|
+
* ## Example: Storing a username in local storage
|
|
40
|
+
* ```tsx
|
|
41
|
+
* localStateStorage.setItem(['user', 'name'], 'Alice');
|
|
42
|
+
* console.log(localStateStorage.getItem(['user', 'name'])); // Output: "Alice"
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
11
45
|
export declare const localStateStorage: StateStorage;
|
|
12
46
|
export declare const nullStorage: StateStorage;
|
|
13
47
|
export type StateStorageOrName = StateStorage | 'url' | 'session' | 'local' | 'null';
|
|
48
|
+
/**
|
|
49
|
+
* `useStoredState` provides a persistent state using different storage options such as
|
|
50
|
+
* URL, `sessionStorage`, `localStorage`, or a custom storage mechanism.
|
|
51
|
+
*
|
|
52
|
+
* This hook initializes state from the selected storage and updates it whenever the state changes.
|
|
53
|
+
*
|
|
54
|
+
* ## Example: Using session storage
|
|
55
|
+
* ```tsx
|
|
56
|
+
* const [count, setCount] = useStoredState<number>('session', ['app', 'counter'], storedValue => storedValue ?? 0);
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <div>
|
|
60
|
+
* <p>Count: {count}</p>
|
|
61
|
+
* <button onClick={() => setCount(prev => prev + 1)}>Increment</button>
|
|
62
|
+
* </div>
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
14
66
|
export declare const useStoredState: <V extends Serializable>(storageOrName: StateStorageOrName | StateStorageOrName[], key: StateStorageKey, initializeValue: ValueInitializer<V>) => [V, SetState<V>];
|
|
67
|
+
/**
|
|
68
|
+
* `useSessionStorageState` is a specialized hook for persisting state in `sessionStorage`.
|
|
69
|
+
* It initializes state from `sessionStorage` on first render and updates it whenever the state changes.
|
|
70
|
+
*
|
|
71
|
+
* ## Example: Persisting theme in session storage
|
|
72
|
+
* ```tsx
|
|
73
|
+
* const [theme, setTheme] = useSessionStorageState(['app', 'theme'], storedValue => storedValue ?? 'light');
|
|
74
|
+
*
|
|
75
|
+
* return (
|
|
76
|
+
* <div>
|
|
77
|
+
* <p>Current Theme: {theme}</p>
|
|
78
|
+
* <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
|
79
|
+
* Toggle Theme
|
|
80
|
+
* </button>
|
|
81
|
+
* </div>
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
15
85
|
export declare const useSessionStorageState: <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>) => [V, SetState<V>];
|
|
86
|
+
/**
|
|
87
|
+
* `useLocalStorageState` is a specialized hook for persisting state in `localStorage`.
|
|
88
|
+
* It initializes state from `localStorage` on first render and updates it whenever the state changes.
|
|
89
|
+
*
|
|
90
|
+
* ## Example: Persisting username in local storage
|
|
91
|
+
* ```tsx
|
|
92
|
+
* const [username, setUsername] = useLocalStorageState(['user', 'name'], storedValue => storedValue ?? 'Guest');
|
|
93
|
+
*
|
|
94
|
+
* return (
|
|
95
|
+
* <div>
|
|
96
|
+
* <p>Username: {username}</p>
|
|
97
|
+
* <input
|
|
98
|
+
* type="text"
|
|
99
|
+
* value={username}
|
|
100
|
+
* onChange={(e) => setUsername(e.target.value)}
|
|
101
|
+
* placeholder="Enter your name"
|
|
102
|
+
* />
|
|
103
|
+
* </div>
|
|
104
|
+
* );
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
16
107
|
export declare const useLocalStorageState: <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>) => [V, SetState<V>];
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves the appropriate storage mechanism based on the provided storage type or custom storage instance.
|
|
110
|
+
* Supports fallback mechanisms when multiple storage options are provided as an array.
|
|
111
|
+
*
|
|
112
|
+
* ## Example: Using a single storage type
|
|
113
|
+
* ```tsx
|
|
114
|
+
* const storage = getStateStorage('local'); // Retrieves localStorage
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* ## Example: Using fallback storages
|
|
118
|
+
* ```tsx
|
|
119
|
+
* const storage = getStateStorage(['session', 'local']); // Uses sessionStorage, falls back to localStorage
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
17
122
|
export declare const getStateStorage: (storageOrName: StateStorageOrName | StateStorageOrName[]) => StateStorage;
|
|
18
123
|
//# sourceMappingURL=useStoredState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStoredState.d.ts","sourceRoot":"","sources":["../../../src/hooks/useStoredState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useStoredState.d.ts","sourceRoot":"","sources":["../../../src/hooks/useStoredState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAA;AACvF,MAAM,MAAM,eAAe,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAEjE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,CAAA;AAExF,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,GAAG,EAAE,eAAe,GAAG,YAAY,CAAA;IAE3C,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;CACxD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,YAY7B,CAAA;AAcD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,cAA4D,CAAA;AAC5F;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,cAA0D,CAAA;AACxF,eAAO,MAAM,WAAW,EAAE,YAMzB,CAAA;AASD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAA;AAEpF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,EACpD,eAAe,kBAAkB,GAAG,kBAAkB,EAAE,EACxD,KAAK,eAAe,EACpB,iBAAiB,gBAAgB,CAAC,CAAC,CAAC,KAClC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAmBjB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,YAAY,EAAE,KAAK,eAAe,EAAE,iBAAiB,gBAAgB,CAAC,CAAC,CAAC,KAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAE1I,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,YAAY,EAAE,KAAK,eAAe,EAAE,iBAAiB,gBAAgB,CAAC,CAAC,CAAC,KAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAExI,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,eAAe,kBAAkB,GAAG,kBAAkB,EAAE,iBAKvF,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './context';
|
|
2
|
-
export * from './debug-context';
|
|
3
|
-
export * from './hooks';
|
|
4
|
-
export * from './referentiallyStable';
|
|
5
|
-
export * from './types';
|
|
1
|
+
export * from './context/index.js';
|
|
2
|
+
export * from './debug-context/index.js';
|
|
3
|
+
export * from './hooks/index.js';
|
|
4
|
+
export * from './referentiallyStable/index.js';
|
|
5
|
+
export * from './types/index.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kBAAkB,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './emptyArray';
|
|
2
|
-
export * from './emptyObject';
|
|
3
|
-
export * from './identityFunction';
|
|
4
|
-
export * from './noop';
|
|
5
|
-
export * from './returnFalse';
|
|
6
|
-
export * from './returnTrue';
|
|
7
|
-
export * from './useReferentiallyStableCallback';
|
|
1
|
+
export * from './emptyArray.js';
|
|
2
|
+
export * from './emptyObject.js';
|
|
3
|
+
export * from './identityFunction.js';
|
|
4
|
+
export * from './noop.js';
|
|
5
|
+
export * from './returnFalse.js';
|
|
6
|
+
export * from './returnTrue.js';
|
|
7
|
+
export * from './useReferentiallyStableCallback.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/referentiallyStable/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/referentiallyStable/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qCAAqC,CAAA"}
|