@contember/react-utils 1.3.0-alpha.2 → 1.3.0-alpha.21

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.
Files changed (149) hide show
  1. package/dist/development/context/createContext.cjs +10 -0
  2. package/dist/development/context/createContext.cjs.map +1 -0
  3. package/dist/development/context/createContext.js +10 -0
  4. package/dist/development/context/createContext.js.map +1 -0
  5. package/dist/development/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
  6. package/dist/development/context/createRequiredContext.cjs.map +1 -0
  7. package/dist/development/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
  8. package/dist/development/context/createRequiredContext.js.map +1 -0
  9. package/dist/development/debug-context/Context.cjs +4 -3
  10. package/dist/development/debug-context/Context.cjs.map +1 -1
  11. package/dist/development/debug-context/Context.js +4 -3
  12. package/dist/development/debug-context/Context.js.map +1 -1
  13. package/dist/development/hooks/useAutoHeightTextArea.cjs +1 -1
  14. package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -1
  15. package/dist/development/hooks/useAutoHeightTextArea.js +1 -1
  16. package/dist/development/hooks/useAutoHeightTextArea.js.map +1 -1
  17. package/dist/development/hooks/useCloseOnClickOutside.cjs +25 -0
  18. package/dist/development/hooks/useCloseOnClickOutside.cjs.map +1 -0
  19. package/dist/development/hooks/useCloseOnClickOutside.js +25 -0
  20. package/dist/development/hooks/useCloseOnClickOutside.js.map +1 -0
  21. package/dist/development/hooks/useCloseOnEscape.cjs +20 -0
  22. package/dist/development/hooks/useCloseOnEscape.cjs.map +1 -0
  23. package/dist/development/hooks/useCloseOnEscape.js +20 -0
  24. package/dist/development/hooks/useCloseOnEscape.js.map +1 -0
  25. package/dist/development/hooks/useConstantLengthInvariant.cjs.map +1 -1
  26. package/dist/development/hooks/useConstantLengthInvariant.js.map +1 -1
  27. package/dist/development/hooks/useConstantValueInvariant.cjs.map +1 -1
  28. package/dist/development/hooks/useConstantValueInvariant.js.map +1 -1
  29. package/dist/development/hooks/useId.cjs.map +1 -1
  30. package/dist/development/hooks/useId.js.map +1 -1
  31. package/dist/development/hooks/useStoredState.cjs +86 -12
  32. package/dist/development/hooks/useStoredState.cjs.map +1 -1
  33. package/dist/development/hooks/useStoredState.js +88 -14
  34. package/dist/development/hooks/useStoredState.js.map +1 -1
  35. package/dist/development/index.cjs +14 -4
  36. package/dist/development/index.cjs.map +1 -1
  37. package/dist/development/index.js +15 -5
  38. package/dist/development/index.js.map +1 -1
  39. package/dist/development/theming/ColorSchemeProvider.cjs +8 -10
  40. package/dist/development/theming/ColorSchemeProvider.cjs.map +1 -1
  41. package/dist/development/theming/ColorSchemeProvider.js +8 -10
  42. package/dist/development/theming/ColorSchemeProvider.js.map +1 -1
  43. package/dist/development/theming/contexts.cjs +2 -2
  44. package/dist/development/theming/contexts.cjs.map +1 -1
  45. package/dist/development/theming/contexts.js +2 -2
  46. package/dist/development/theming/contexts.js.map +1 -1
  47. package/dist/development/theming/useClassName.cjs.map +1 -1
  48. package/dist/development/theming/useClassName.js.map +1 -1
  49. package/dist/development/theming/useClassNameFactory.cjs.map +1 -1
  50. package/dist/development/theming/useClassNameFactory.js.map +1 -1
  51. package/dist/development/theming/useThemedClassNameFactory.cjs.map +1 -1
  52. package/dist/development/theming/useThemedClassNameFactory.js.map +1 -1
  53. package/dist/production/context/createContext.cjs +10 -0
  54. package/dist/production/context/createContext.cjs.map +1 -0
  55. package/dist/production/context/createContext.js +10 -0
  56. package/dist/production/context/createContext.js.map +1 -0
  57. package/dist/production/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
  58. package/dist/production/context/createRequiredContext.cjs.map +1 -0
  59. package/dist/production/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
  60. package/dist/production/context/createRequiredContext.js.map +1 -0
  61. package/dist/production/debug-context/Context.cjs +3 -2
  62. package/dist/production/debug-context/Context.cjs.map +1 -1
  63. package/dist/production/debug-context/Context.js +3 -2
  64. package/dist/production/debug-context/Context.js.map +1 -1
  65. package/dist/production/hooks/useAutoHeightTextArea.cjs +1 -1
  66. package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -1
  67. package/dist/production/hooks/useAutoHeightTextArea.js +1 -1
  68. package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -1
  69. package/dist/production/hooks/useChildrenAsLabel.cjs.map +1 -1
  70. package/dist/production/hooks/useChildrenAsLabel.js.map +1 -1
  71. package/dist/production/hooks/useCloseOnClickOutside.cjs +25 -0
  72. package/dist/production/hooks/useCloseOnClickOutside.cjs.map +1 -0
  73. package/dist/production/hooks/useCloseOnClickOutside.js +25 -0
  74. package/dist/production/hooks/useCloseOnClickOutside.js.map +1 -0
  75. package/dist/production/hooks/useCloseOnEscape.cjs +20 -0
  76. package/dist/production/hooks/useCloseOnEscape.cjs.map +1 -0
  77. package/dist/production/hooks/useCloseOnEscape.js +20 -0
  78. package/dist/production/hooks/useCloseOnEscape.js.map +1 -0
  79. package/dist/production/hooks/useId.cjs.map +1 -1
  80. package/dist/production/hooks/useId.js.map +1 -1
  81. package/dist/production/hooks/useStoredState.cjs +86 -12
  82. package/dist/production/hooks/useStoredState.cjs.map +1 -1
  83. package/dist/production/hooks/useStoredState.js +88 -14
  84. package/dist/production/hooks/useStoredState.js.map +1 -1
  85. package/dist/production/index.cjs +14 -4
  86. package/dist/production/index.cjs.map +1 -1
  87. package/dist/production/index.js +15 -5
  88. package/dist/production/index.js.map +1 -1
  89. package/dist/production/theming/ColorSchemeProvider.cjs +4 -6
  90. package/dist/production/theming/ColorSchemeProvider.cjs.map +1 -1
  91. package/dist/production/theming/ColorSchemeProvider.js +4 -6
  92. package/dist/production/theming/ColorSchemeProvider.js.map +1 -1
  93. package/dist/production/theming/contexts.cjs +2 -2
  94. package/dist/production/theming/contexts.cjs.map +1 -1
  95. package/dist/production/theming/contexts.js +2 -2
  96. package/dist/production/theming/contexts.js.map +1 -1
  97. package/dist/production/theming/useClassName.cjs.map +1 -1
  98. package/dist/production/theming/useClassName.js.map +1 -1
  99. package/dist/production/theming/useClassNameFactory.cjs.map +1 -1
  100. package/dist/production/theming/useClassNameFactory.js.map +1 -1
  101. package/dist/production/theming/useThemedClassNameFactory.cjs.map +1 -1
  102. package/dist/production/theming/useThemedClassNameFactory.js.map +1 -1
  103. package/dist/types/context/createContext.d.ts +3 -0
  104. package/dist/types/context/createContext.d.ts.map +1 -0
  105. package/dist/types/context/createRequiredContext.d.ts +3 -0
  106. package/dist/types/context/createRequiredContext.d.ts.map +1 -0
  107. package/dist/types/context/index.d.ts +2 -2
  108. package/dist/types/context/index.d.ts.map +1 -1
  109. package/dist/types/debug-context/Context.d.ts.map +1 -1
  110. package/dist/types/hooks/index.d.ts +2 -0
  111. package/dist/types/hooks/index.d.ts.map +1 -1
  112. package/dist/types/hooks/useCloseOnClickOutside.d.ts +7 -0
  113. package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +1 -0
  114. package/dist/types/hooks/useCloseOnEscape.d.ts +5 -0
  115. package/dist/types/hooks/useCloseOnEscape.d.ts.map +1 -0
  116. package/dist/types/hooks/useStoredState.d.ts +13 -1
  117. package/dist/types/hooks/useStoredState.d.ts.map +1 -1
  118. package/dist/types/theming/ColorSchemeProvider.d.ts +3 -4
  119. package/dist/types/theming/ColorSchemeProvider.d.ts.map +1 -1
  120. package/dist/types/tsconfig.tsbuildinfo +1 -1
  121. package/package.json +2 -2
  122. package/src/context/createContext.ts +9 -0
  123. package/src/context/{createNonNullableContextFactory.ts → createRequiredContext.ts} +6 -4
  124. package/src/context/index.ts +2 -2
  125. package/src/debug-context/Context.tsx +3 -3
  126. package/src/hooks/index.ts +2 -0
  127. package/src/hooks/useAutoHeightTextArea.ts +1 -1
  128. package/src/hooks/useCloseOnClickOutside.ts +27 -0
  129. package/src/hooks/useCloseOnEscape.ts +18 -0
  130. package/src/hooks/useStoredState.ts +100 -14
  131. package/src/theming/ColorSchemeProvider.tsx +8 -11
  132. package/src/theming/contexts.ts +2 -2
  133. package/dist/development/context/createNonNullableContextFactory.cjs.map +0 -1
  134. package/dist/development/context/createNonNullableContextFactory.js.map +0 -1
  135. package/dist/development/context/createOptionalContextFactory.cjs +0 -13
  136. package/dist/development/context/createOptionalContextFactory.cjs.map +0 -1
  137. package/dist/development/context/createOptionalContextFactory.js +0 -13
  138. package/dist/development/context/createOptionalContextFactory.js.map +0 -1
  139. package/dist/production/context/createNonNullableContextFactory.cjs.map +0 -1
  140. package/dist/production/context/createNonNullableContextFactory.js.map +0 -1
  141. package/dist/production/context/createOptionalContextFactory.cjs +0 -13
  142. package/dist/production/context/createOptionalContextFactory.cjs.map +0 -1
  143. package/dist/production/context/createOptionalContextFactory.js +0 -13
  144. package/dist/production/context/createOptionalContextFactory.js.map +0 -1
  145. package/dist/types/context/createNonNullableContextFactory.d.ts +0 -3
  146. package/dist/types/context/createNonNullableContextFactory.d.ts.map +0 -1
  147. package/dist/types/context/createOptionalContextFactory.d.ts +0 -3
  148. package/dist/types/context/createOptionalContextFactory.d.ts.map +0 -1
  149. package/src/context/createOptionalContextFactory.ts +0 -13
@@ -1 +1 @@
1
- {"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { assert, isNonEmptyString } from '@contember/utilities'\nimport { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tassert('prefix is non-empty string', prefix, isNonEmptyString)\n\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","createContext","isNoopScopedConsole","assert","isNonEmptyString","useContext","useMemo","noopScopedConsole","useRef","memo","console","jsx"],"mappings":";;;;;;AAKA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuBC,oBAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAAC,UAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACnEC,YAAAA,OAAA,8BAA8B,QAAQC,UAAAA,gBAAgB;AAE7D,QAAM,gBAAgB,0BAA0BC,iBAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgBC,MAAAA,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAAC;IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAMC,aAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgBC,WAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0BJ,iBAAW,oBAAoB,CAAC;AAEtF,QAAMK,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7CH;AAGF,SAAAI,2BAAA,IAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASD,WAAUH,UAAAA,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;;;;"}
1
+ {"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","createContext","isNoopScopedConsole","useContext","useMemo","noopScopedConsole","useRef","memo","console","jsx"],"mappings":";;;;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuBC,oBAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAAC,UAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0BC,iBAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgBC,MAAAA,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAAC;IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAMC,aAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgBC,WAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0BJ,iBAAW,oBAAoB,CAAC;AAEtF,QAAMK,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7CH;AAGF,SAAAI,2BAAA,IAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASD,WAAUH,UAAAA,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;;;;"}
@@ -1,5 +1,4 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { assert, isNonEmptyString } from "@contember/utilities";
3
2
  import { createContext, useContext, useMemo, useRef, memo } from "react";
4
3
  import { noopScopedConsole, isNoopScopedConsole } from "./Constants.js";
5
4
  function createPrefixedConsole(message, prefixedConsole) {
@@ -40,7 +39,9 @@ function parentScopedConsoleOrNone(parentConsole) {
40
39
  return isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
41
40
  }
42
41
  const useScopedConsoleRef = (prefix, override) => {
43
- assert("prefix is non-empty string", prefix, isNonEmptyString);
42
+ if (prefix.length === 0) {
43
+ throw new Error("Prefix must be non-empty string");
44
+ }
44
45
  const parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext));
45
46
  const scopedConsole = useMemo(() => {
46
47
  if (override !== false && (parentConsole || override)) {
@@ -1 +1 @@
1
- {"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { assert, isNonEmptyString } from '@contember/utilities'\nimport { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tassert('prefix is non-empty string', prefix, isNonEmptyString)\n\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","console"],"mappings":";;;;AAKA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuB,cAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACnE,SAAA,8BAA8B,QAAQ,gBAAgB;AAE7D,QAAM,gBAAgB,0BAA0B,WAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgB,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAA;AAAA,IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAM,OAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgB,KAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0B,WAAW,oBAAoB,CAAC;AAEtF,QAAMC,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7C;AAGF,SAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASA,WAAU,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;"}
1
+ {"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","console"],"mappings":";;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuB,cAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0B,WAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgB,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAA;AAAA,IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAM,OAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgB,KAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0B,WAAW,oBAAoB,CAAC;AAEtF,QAAMC,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7C;AAGF,SAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASA,WAAU,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;"}
@@ -12,7 +12,7 @@ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
12
12
  ref.style.minHeight = "";
13
13
  ref.style.maxHeight = "";
14
14
  if (minRows2 !== maxRows2) {
15
- const height = ref.scrollHeight;
15
+ const height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight;
16
16
  let minHeight;
17
17
  let maxHeight;
18
18
  ref.rows = minRows2;
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoHeightTextArea.cjs","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["useCallback","minRows","maxRows","px","useOnElementResize","unwrapRefValue","useLayoutEffect"],"mappings":";;;;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAUA,MAAA,YAAY,OAAO,KAAiCC,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAASC,UAAA,GAAG,MAAM;AACxB,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAELC,qBAAA,mBAAmB,aAAa,MAAM;AACrC,YAAQC,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAEDC,QAAAA,gBAAgB,MAAM;AACrB,YAAQD,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;;"}
1
+ {"version":3,"file":"useAutoHeightTextArea.cjs","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["useCallback","minRows","maxRows","px","useOnElementResize","unwrapRefValue","useLayoutEffect"],"mappings":";;;;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAUA,MAAA,YAAY,OAAO,KAAiCC,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI,eAAe,IAAI,eAAe,IAAI;AACrD,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAASC,UAAA,GAAG,MAAM;AACxB,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAELC,qBAAA,mBAAmB,aAAa,MAAM;AACrC,YAAQC,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAEDC,QAAAA,gBAAgB,MAAM;AACrB,YAAQD,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;;"}
@@ -10,7 +10,7 @@ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
10
10
  ref.style.minHeight = "";
11
11
  ref.style.maxHeight = "";
12
12
  if (minRows2 !== maxRows2) {
13
- const height = ref.scrollHeight;
13
+ const height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight;
14
14
  let minHeight;
15
15
  let maxHeight;
16
16
  ref.rows = minRows2;
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["minRows","maxRows"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,OAAO,KAAiCA,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
1
+ {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["minRows","maxRows"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,OAAO,KAAiCA,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI,eAAe,IAAI,eAAe,IAAI;AACrD,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useChildrenAsLabel.cjs","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":["Children","useMemo"],"mappings":";;;AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExBA,UAAAA,SAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;AACD;AAAA,MAGD;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAOC,MAAAA,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;;;"}
1
+ {"version":3,"file":"useChildrenAsLabel.cjs","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":["Children","useMemo"],"mappings":";;;AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExBA,UAAAA,SAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;;MAIF;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAOC,MAAAA,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useChildrenAsLabel.js","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":[],"mappings":";AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExB,aAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;AACD;AAAA,MAGD;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAO,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;"}
1
+ {"version":3,"file":"useChildrenAsLabel.js","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":[],"mappings":";AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExB,aAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;;MAIF;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAO,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
5
+ react.useEffect(() => {
6
+ if (isOpen) {
7
+ const closeOnClickOutside = (event) => {
8
+ const target = event.target;
9
+ if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
10
+ return;
11
+ }
12
+ if (contents.every((it) => it === null)) {
13
+ return;
14
+ }
15
+ close();
16
+ };
17
+ (outside ?? window).addEventListener("click", closeOnClickOutside);
18
+ return () => {
19
+ (outside ?? window).removeEventListener("click", closeOnClickOutside);
20
+ };
21
+ }
22
+ }, [close, isOpen, contents, outside]);
23
+ };
24
+ exports.useCloseOnClickOutside = useCloseOnClickOutside;
25
+ //# sourceMappingURL=useCloseOnClickOutside.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnClickOutside.cjs","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":["useEffect"],"mappings":";;;AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChLA,QAAAA,UAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;;"}
@@ -0,0 +1,25 @@
1
+ import { useEffect } from "react";
2
+ const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
3
+ useEffect(() => {
4
+ if (isOpen) {
5
+ const closeOnClickOutside = (event) => {
6
+ const target = event.target;
7
+ if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
8
+ return;
9
+ }
10
+ if (contents.every((it) => it === null)) {
11
+ return;
12
+ }
13
+ close();
14
+ };
15
+ (outside ?? window).addEventListener("click", closeOnClickOutside);
16
+ return () => {
17
+ (outside ?? window).removeEventListener("click", closeOnClickOutside);
18
+ };
19
+ }
20
+ }, [close, isOpen, contents, outside]);
21
+ };
22
+ export {
23
+ useCloseOnClickOutside
24
+ };
25
+ //# sourceMappingURL=useCloseOnClickOutside.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnClickOutside.js","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":[],"mappings":";AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChL,YAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useCloseOnEscape = ({ isOpen, close }) => {
5
+ react.useEffect(() => {
6
+ if (isOpen) {
7
+ const closeOnEscapeKey = (event) => {
8
+ if (event.key === "Escape") {
9
+ close();
10
+ }
11
+ };
12
+ window.addEventListener("keydown", closeOnEscapeKey);
13
+ return () => {
14
+ window.removeEventListener("keydown", closeOnEscapeKey);
15
+ };
16
+ }
17
+ }, [close, isOpen]);
18
+ };
19
+ exports.useCloseOnEscape = useCloseOnEscape;
20
+ //# sourceMappingURL=useCloseOnEscape.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnEscape.cjs","sources":["../../../src/hooks/useCloseOnEscape.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnEscape = ({ isOpen, close }: { isOpen: boolean, close: () => void }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnEscapeKey = (event: KeyboardEvent) => {\n\t\t\t\tif (event.key === 'Escape') {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\t\t\twindow.addEventListener('keydown', closeOnEscapeKey)\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener('keydown', closeOnEscapeKey)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen])\n}\n"],"names":["useEffect"],"mappings":";;;AAEO,MAAM,mBAAmB,CAAC,EAAE,QAAQ,YAAoD;AAC9FA,QAAAA,UAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,mBAAmB,CAAC,UAAyB;AAC9C,YAAA,MAAM,QAAQ,UAAU;AACrB;QACP;AAAA,MAAA;AAEM,aAAA,iBAAiB,WAAW,gBAAgB;AAEnD,aAAO,MAAM;AACL,eAAA,oBAAoB,WAAW,gBAAgB;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA,GACE,CAAC,OAAO,MAAM,CAAC;AACnB;;"}
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ const useCloseOnEscape = ({ isOpen, close }) => {
3
+ useEffect(() => {
4
+ if (isOpen) {
5
+ const closeOnEscapeKey = (event) => {
6
+ if (event.key === "Escape") {
7
+ close();
8
+ }
9
+ };
10
+ window.addEventListener("keydown", closeOnEscapeKey);
11
+ return () => {
12
+ window.removeEventListener("keydown", closeOnEscapeKey);
13
+ };
14
+ }
15
+ }, [close, isOpen]);
16
+ };
17
+ export {
18
+ useCloseOnEscape
19
+ };
20
+ //# sourceMappingURL=useCloseOnEscape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnEscape.js","sources":["../../../src/hooks/useCloseOnEscape.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnEscape = ({ isOpen, close }: { isOpen: boolean, close: () => void }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnEscapeKey = (event: KeyboardEvent) => {\n\t\t\t\tif (event.key === 'Escape') {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\t\t\twindow.addEventListener('keydown', closeOnEscapeKey)\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener('keydown', closeOnEscapeKey)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen])\n}\n"],"names":[],"mappings":";AAEO,MAAM,mBAAmB,CAAC,EAAE,QAAQ,YAAoD;AAC9F,YAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,mBAAmB,CAAC,UAAyB;AAC9C,YAAA,MAAM,QAAQ,UAAU;AACrB;QACP;AAAA,MAAA;AAEM,aAAA,iBAAiB,WAAW,gBAAgB;AAEnD,aAAO,MAAM;AACL,eAAA,oBAAoB,WAAW,gBAAgB;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA,GACE,CAAC,OAAO,MAAM,CAAC;AACnB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useId.cjs","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":["useMemo"],"mappings":";;;AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;AACrC;AAUO,SAAS,QAAQ;AACvB,SAAOA,cAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;;"}
1
+ {"version":3,"file":"useId.cjs","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":["useMemo"],"mappings":";;;AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE,CAAC;AACtC;AAUO,SAAS,QAAQ;AACvB,SAAOA,cAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;AACrC;AAUO,SAAS,QAAQ;AACvB,SAAO,QAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;"}
1
+ {"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE,CAAC;AACtC;AAUO,SAAS,QAAQ;AACvB,SAAO,QAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;"}
@@ -1,23 +1,97 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
- const createStoredStateHook = (getStorage) => {
5
- return (key, initializeValue) => {
6
- const storage = getStorage();
7
- const [value, setValue] = react.useState(() => {
8
- const value2 = storage.getItem(key);
9
- const parsedValue = value2 !== null ? JSON.parse(value2) : void 0;
10
- return initializeValue(parsedValue);
11
- });
12
- return [value, react.useCallback((value2) => {
4
+ const urlStateStorage = {
5
+ getItem(key) {
6
+ const searchParams = new URLSearchParams(window.location.search);
7
+ const value = searchParams.get(key[1]);
8
+ return value !== null && value !== void 0 ? JSON.parse(value) : null;
9
+ },
10
+ setItem(key, value) {
11
+ const searchParams = new URLSearchParams(window.location.search);
12
+ searchParams.set(key[1], JSON.stringify(value));
13
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
14
+ window.history.replaceState({}, "", newUrl);
15
+ }
16
+ };
17
+ const createStateStorage = (getStorage) => {
18
+ return {
19
+ getItem(key) {
20
+ const value = getStorage().getItem(key.join("-"));
21
+ return value !== null ? JSON.parse(value) : null;
22
+ },
23
+ setItem(key, value) {
24
+ getStorage().setItem(key.join("-"), JSON.stringify(value));
25
+ }
26
+ };
27
+ };
28
+ const sessionStateStorage = createStateStorage(() => sessionStorage);
29
+ const localStateStorage = createStateStorage(() => localStorage);
30
+ const nullStorage = {
31
+ getItem() {
32
+ return null;
33
+ },
34
+ setItem() {
35
+ }
36
+ };
37
+ const builtInStorages = {
38
+ url: urlStateStorage,
39
+ session: sessionStateStorage,
40
+ local: localStateStorage,
41
+ null: nullStorage
42
+ };
43
+ const useStoredState = (storageOrName, key, initializeValue) => {
44
+ const storage = react.useMemo(() => {
45
+ if (Array.isArray(storageOrName)) {
46
+ return createFallbackStorage(storageOrName);
47
+ }
48
+ return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
49
+ }, [storageOrName]);
50
+ const [value, setValue] = react.useState(() => {
51
+ const value2 = storage.getItem(key);
52
+ return initializeValue(value2);
53
+ });
54
+ return [
55
+ value,
56
+ react.useCallback((value2) => {
13
57
  setValue((current) => {
14
58
  const newValue = typeof value2 === "function" ? value2(current) : value2;
15
- storage.setItem(key, JSON.stringify(newValue));
59
+ storage.setItem(key, newValue);
16
60
  return newValue;
17
61
  });
18
- }, [key, storage])];
62
+ }, [key, storage])
63
+ ];
64
+ };
65
+ const useSessionStorageState = (key, initializeValue) => {
66
+ return useStoredState(sessionStateStorage, key, initializeValue);
67
+ };
68
+ const useLocalStorageState = (key, initializeValue) => {
69
+ return useStoredState(localStateStorage, key, initializeValue);
70
+ };
71
+ const createFallbackStorage = (storageTypes) => {
72
+ const resultStorages = storageTypes.map((it) => typeof it === "string" ? builtInStorages[it] : it);
73
+ return {
74
+ getItem(key) {
75
+ for (const storage of resultStorages) {
76
+ const value = storage.getItem(key);
77
+ if (value !== null) {
78
+ return value;
79
+ }
80
+ }
81
+ return null;
82
+ },
83
+ setItem(key, value) {
84
+ for (const storage of resultStorages) {
85
+ storage.setItem(key, value);
86
+ }
87
+ }
19
88
  };
20
89
  };
21
- const useSessionStorageState = createStoredStateHook(() => sessionStorage);
90
+ exports.localStateStorage = localStateStorage;
91
+ exports.nullStorage = nullStorage;
92
+ exports.sessionStateStorage = sessionStateStorage;
93
+ exports.urlStateStorage = urlStateStorage;
94
+ exports.useLocalStorageState = useLocalStorageState;
22
95
  exports.useSessionStorageState = useSessionStorageState;
96
+ exports.useStoredState = useStoredState;
23
97
  //# sourceMappingURL=useStoredState.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStoredState.cjs","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nconst createStoredStateHook = (getStorage: () => Storage) => {\n\treturn <V extends Serializable>(key: string, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\t\tconst storage = getStorage()\n\t\tconst [value, setValue] = useState<V>(() => {\n\t\t\tconst value = storage.getItem(key)\n\t\t\tconst parsedValue: V | undefined = value !== null ? JSON.parse(value) : undefined\n\t\t\treturn initializeValue(parsedValue)\n\t\t})\n\t\treturn [value, useCallback(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, JSON.stringify(newValue))\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage])]\n\t}\n\n}\n\nexport const useSessionStorageState = createStoredStateHook(() => sessionStorage)\n"],"names":["useState","value","useCallback"],"mappings":";;;AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAIA,eAAY,MAAM;AACrCC,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAOC,kBAAY,CAAAD,WAAS;AACnC,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AACvF,gBAAQ,QAAQ,KAAK,KAAK,UAAU,QAAQ,CAAC;AACtC,eAAA;AAAA,MAAA,CACP;AAAA,IACC,GAAA,CAAC,KAAK,OAAO,CAAC,CAAC;AAAA,EAAA;AAGpB;AAEa,MAAA,yBAAyB,sBAAsB,MAAM,cAAc;;"}
1
+ {"version":3,"file":"useStoredState.cjs","sources":["../../../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\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 createStateStorage = (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 = createStateStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorage(() => 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>(storageOrName: StateStorageOrName | StateStorageOrName[], key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\tif (Array.isArray(storageOrName)) {\n\t\t\treturn createFallbackStorage(storageOrName)\n\t\t}\n\t\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : 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\n\nconst createFallbackStorage = <V extends Serializable>(storageTypes: StateStorageOrName[]): StateStorage => {\n\tconst resultStorages = storageTypes.map(it => typeof it === 'string' ? builtInStorages[it] : it)\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of resultStorages) {\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 resultStorages) {\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":";;;AAeO,MAAM,kBAAgC;AAAA,EAC5C,QAAQ,KAAK;AACZ,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,UAAM,QAAQ,aAAa,IAAI,IAAI,CAAC,CAAC;AACrC,WAAO,UAAU,QAAQ,UAAU,SAAY,KAAK,MAAM,KAAK,IAAI;AAAA,EACpE;AAAA,EACA,QAAQ,KAAK,OAAO;AACnB,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,iBAAa,IAAI,IAAI,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC;AACxC,UAAA,SAAS,GAAG,OAAO,SAAS,QAAQ,IAAI,aAAa,SAAU,CAAA;AACrE,WAAO,QAAQ,aAAa,CAAC,GAAG,IAAI,MAAM;AAAA,EAC3C;AACD;AAEA,MAAM,qBAAqB,CAAC,eAA4C;AAChE,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,YAAM,QAAQ,aAAa,QAAQ,IAAI,KAAK,GAAG,CAAC;AAChD,aAAO,UAAU,OAAO,KAAK,MAAM,KAAK,IAAI;AAAA,IAC7C;AAAA,IACA,QAAQ,KAAK,OAAO;AACR,iBAAA,EAAE,QAAQ,IAAI,KAAK,GAAG,GAAG,KAAK,UAAU,KAAK,CAAC;AAAA,IAC1D;AAAA,EAAA;AAEF;AAEa,MAAA,sBAAsB,mBAAmB,MAAM,cAAc;AAC7D,MAAA,oBAAoB,mBAAmB,MAAM,YAAY;AAC/D,MAAM,cAA4B;AAAA,EACxC,UAAU;AACF,WAAA;AAAA,EACR;AAAA,EACA,UAAU;AAAA,EACV;AACD;AAEA,MAAM,kBAAkB;AAAA,EACvB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AACP;AAIO,MAAM,iBAAiB,CAAyB,eAA0D,KAAsB,oBAA2D;AAC3L,QAAA,UAAUA,MAAAA,QAAQ,MAAM;AACzB,QAAA,MAAM,QAAQ,aAAa,GAAG;AACjC,aAAO,sBAAsB,aAAa;AAAA,IAC3C;AACA,WAAO,OAAO,kBAAkB,WAAW,gBAAgB,aAAa,IAAI;AAAA,EAAA,GAC1E,CAAC,aAAa,CAAC;AAElB,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAY,MAAM;AACrCC,UAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,WAAO,gBAAgBA,MAAU;AAAA,EAAA,CACjC;AACM,SAAA;AAAA,IACN;AAAA,IACAC,MAAA,YAAY,CAAAD,WAAS;AACpB,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AAC/E,gBAAA,QAAQ,KAAK,QAAQ;AACtB,eAAA;AAAA,MAAA,CACP;AAAA,IAAA,GACC,CAAC,KAAK,OAAO,CAAC;AAAA,EAAA;AAEnB;AAEa,MAAA,yBAAyB,CAAyB,KAAsB,oBAA2D;AACxI,SAAA,eAAkB,qBAAqB,KAAK,eAAe;AACnE;AAEa,MAAA,uBAAuB,CAAyB,KAAsB,oBAA2D;AACtI,SAAA,eAAkB,mBAAmB,KAAK,eAAe;AACjE;AAGA,MAAM,wBAAwB,CAAyB,iBAAqD;AACrG,QAAA,iBAAiB,aAAa,IAAI,CAAM,OAAA,OAAO,OAAO,WAAW,gBAAgB,EAAE,IAAI,EAAE;AACxF,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,iBAAW,WAAW,gBAAgB;AAC/B,cAAA,QAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAI,UAAU,MAAM;AACZ,iBAAA;AAAA,QACR;AAAA,MACD;AACO,aAAA;AAAA,IACR;AAAA,IACA,QAAQ,KAAK,OAAO;AACnB,iBAAW,WAAW,gBAAgB;AAC7B,gBAAA,QAAQ,KAAK,KAAK;AAAA,MAC3B;AAAA,IACD;AAAA,EAAA;AAEF;;;;;;;;"}
@@ -1,23 +1,97 @@
1
- import { useState, useCallback } from "react";
2
- const createStoredStateHook = (getStorage) => {
3
- return (key, initializeValue) => {
4
- const storage = getStorage();
5
- const [value, setValue] = useState(() => {
6
- const value2 = storage.getItem(key);
7
- const parsedValue = value2 !== null ? JSON.parse(value2) : void 0;
8
- return initializeValue(parsedValue);
9
- });
10
- return [value, useCallback((value2) => {
1
+ import { useMemo, useState, useCallback } from "react";
2
+ const urlStateStorage = {
3
+ getItem(key) {
4
+ const searchParams = new URLSearchParams(window.location.search);
5
+ const value = searchParams.get(key[1]);
6
+ return value !== null && value !== void 0 ? JSON.parse(value) : null;
7
+ },
8
+ setItem(key, value) {
9
+ const searchParams = new URLSearchParams(window.location.search);
10
+ searchParams.set(key[1], JSON.stringify(value));
11
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
12
+ window.history.replaceState({}, "", newUrl);
13
+ }
14
+ };
15
+ const createStateStorage = (getStorage) => {
16
+ return {
17
+ getItem(key) {
18
+ const value = getStorage().getItem(key.join("-"));
19
+ return value !== null ? JSON.parse(value) : null;
20
+ },
21
+ setItem(key, value) {
22
+ getStorage().setItem(key.join("-"), JSON.stringify(value));
23
+ }
24
+ };
25
+ };
26
+ const sessionStateStorage = createStateStorage(() => sessionStorage);
27
+ const localStateStorage = createStateStorage(() => localStorage);
28
+ const nullStorage = {
29
+ getItem() {
30
+ return null;
31
+ },
32
+ setItem() {
33
+ }
34
+ };
35
+ const builtInStorages = {
36
+ url: urlStateStorage,
37
+ session: sessionStateStorage,
38
+ local: localStateStorage,
39
+ null: nullStorage
40
+ };
41
+ const useStoredState = (storageOrName, key, initializeValue) => {
42
+ const storage = useMemo(() => {
43
+ if (Array.isArray(storageOrName)) {
44
+ return createFallbackStorage(storageOrName);
45
+ }
46
+ return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
47
+ }, [storageOrName]);
48
+ const [value, setValue] = useState(() => {
49
+ const value2 = storage.getItem(key);
50
+ return initializeValue(value2);
51
+ });
52
+ return [
53
+ value,
54
+ useCallback((value2) => {
11
55
  setValue((current) => {
12
56
  const newValue = typeof value2 === "function" ? value2(current) : value2;
13
- storage.setItem(key, JSON.stringify(newValue));
57
+ storage.setItem(key, newValue);
14
58
  return newValue;
15
59
  });
16
- }, [key, storage])];
60
+ }, [key, storage])
61
+ ];
62
+ };
63
+ const useSessionStorageState = (key, initializeValue) => {
64
+ return useStoredState(sessionStateStorage, key, initializeValue);
65
+ };
66
+ const useLocalStorageState = (key, initializeValue) => {
67
+ return useStoredState(localStateStorage, key, initializeValue);
68
+ };
69
+ const createFallbackStorage = (storageTypes) => {
70
+ const resultStorages = storageTypes.map((it) => typeof it === "string" ? builtInStorages[it] : it);
71
+ return {
72
+ getItem(key) {
73
+ for (const storage of resultStorages) {
74
+ const value = storage.getItem(key);
75
+ if (value !== null) {
76
+ return value;
77
+ }
78
+ }
79
+ return null;
80
+ },
81
+ setItem(key, value) {
82
+ for (const storage of resultStorages) {
83
+ storage.setItem(key, value);
84
+ }
85
+ }
17
86
  };
18
87
  };
19
- const useSessionStorageState = createStoredStateHook(() => sessionStorage);
20
88
  export {
21
- useSessionStorageState
89
+ localStateStorage,
90
+ nullStorage,
91
+ sessionStateStorage,
92
+ urlStateStorage,
93
+ useLocalStorageState,
94
+ useSessionStorageState,
95
+ useStoredState
22
96
  };
23
97
  //# sourceMappingURL=useStoredState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStoredState.js","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nconst createStoredStateHook = (getStorage: () => Storage) => {\n\treturn <V extends Serializable>(key: string, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\t\tconst storage = getStorage()\n\t\tconst [value, setValue] = useState<V>(() => {\n\t\t\tconst value = storage.getItem(key)\n\t\t\tconst parsedValue: V | undefined = value !== null ? JSON.parse(value) : undefined\n\t\t\treturn initializeValue(parsedValue)\n\t\t})\n\t\treturn [value, useCallback(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, JSON.stringify(newValue))\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage])]\n\t}\n\n}\n\nexport const useSessionStorageState = createStoredStateHook(() => sessionStorage)\n"],"names":["value"],"mappings":";AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACrCA,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAO,YAAY,CAAAA,WAAS;AACnC,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AACvF,gBAAQ,QAAQ,KAAK,KAAK,UAAU,QAAQ,CAAC;AACtC,eAAA;AAAA,MAAA,CACP;AAAA,IACC,GAAA,CAAC,KAAK,OAAO,CAAC,CAAC;AAAA,EAAA;AAGpB;AAEa,MAAA,yBAAyB,sBAAsB,MAAM,cAAc;"}
1
+ {"version":3,"file":"useStoredState.js","sources":["../../../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\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 createStateStorage = (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 = createStateStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorage(() => 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>(storageOrName: StateStorageOrName | StateStorageOrName[], key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\tif (Array.isArray(storageOrName)) {\n\t\t\treturn createFallbackStorage(storageOrName)\n\t\t}\n\t\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : 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\n\nconst createFallbackStorage = <V extends Serializable>(storageTypes: StateStorageOrName[]): StateStorage => {\n\tconst resultStorages = storageTypes.map(it => typeof it === 'string' ? builtInStorages[it] : it)\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of resultStorages) {\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 resultStorages) {\n\t\t\t\tstorage.setItem(key, value)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"names":["value"],"mappings":";AAeO,MAAM,kBAAgC;AAAA,EAC5C,QAAQ,KAAK;AACZ,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,UAAM,QAAQ,aAAa,IAAI,IAAI,CAAC,CAAC;AACrC,WAAO,UAAU,QAAQ,UAAU,SAAY,KAAK,MAAM,KAAK,IAAI;AAAA,EACpE;AAAA,EACA,QAAQ,KAAK,OAAO;AACnB,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,iBAAa,IAAI,IAAI,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC;AACxC,UAAA,SAAS,GAAG,OAAO,SAAS,QAAQ,IAAI,aAAa,SAAU,CAAA;AACrE,WAAO,QAAQ,aAAa,CAAC,GAAG,IAAI,MAAM;AAAA,EAC3C;AACD;AAEA,MAAM,qBAAqB,CAAC,eAA4C;AAChE,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,YAAM,QAAQ,aAAa,QAAQ,IAAI,KAAK,GAAG,CAAC;AAChD,aAAO,UAAU,OAAO,KAAK,MAAM,KAAK,IAAI;AAAA,IAC7C;AAAA,IACA,QAAQ,KAAK,OAAO;AACR,iBAAA,EAAE,QAAQ,IAAI,KAAK,GAAG,GAAG,KAAK,UAAU,KAAK,CAAC;AAAA,IAC1D;AAAA,EAAA;AAEF;AAEa,MAAA,sBAAsB,mBAAmB,MAAM,cAAc;AAC7D,MAAA,oBAAoB,mBAAmB,MAAM,YAAY;AAC/D,MAAM,cAA4B;AAAA,EACxC,UAAU;AACF,WAAA;AAAA,EACR;AAAA,EACA,UAAU;AAAA,EACV;AACD;AAEA,MAAM,kBAAkB;AAAA,EACvB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AACP;AAIO,MAAM,iBAAiB,CAAyB,eAA0D,KAAsB,oBAA2D;AAC3L,QAAA,UAAU,QAAQ,MAAM;AACzB,QAAA,MAAM,QAAQ,aAAa,GAAG;AACjC,aAAO,sBAAsB,aAAa;AAAA,IAC3C;AACA,WAAO,OAAO,kBAAkB,WAAW,gBAAgB,aAAa,IAAI;AAAA,EAAA,GAC1E,CAAC,aAAa,CAAC;AAElB,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACrCA,UAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,WAAO,gBAAgBA,MAAU;AAAA,EAAA,CACjC;AACM,SAAA;AAAA,IACN;AAAA,IACA,YAAY,CAAAA,WAAS;AACpB,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AAC/E,gBAAA,QAAQ,KAAK,QAAQ;AACtB,eAAA;AAAA,MAAA,CACP;AAAA,IAAA,GACC,CAAC,KAAK,OAAO,CAAC;AAAA,EAAA;AAEnB;AAEa,MAAA,yBAAyB,CAAyB,KAAsB,oBAA2D;AACxI,SAAA,eAAkB,qBAAqB,KAAK,eAAe;AACnE;AAEa,MAAA,uBAAuB,CAAyB,KAAsB,oBAA2D;AACtI,SAAA,eAAkB,mBAAmB,KAAK,eAAe;AACjE;AAGA,MAAM,wBAAwB,CAAyB,iBAAqD;AACrG,QAAA,iBAAiB,aAAa,IAAI,CAAM,OAAA,OAAO,OAAO,WAAW,gBAAgB,EAAE,IAAI,EAAE;AACxF,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,iBAAW,WAAW,gBAAgB;AAC/B,cAAA,QAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAI,UAAU,MAAM;AACZ,iBAAA;AAAA,QACR;AAAA,MACD;AACO,aAAA;AAAA,IACR;AAAA,IACA,QAAQ,KAAK,OAAO;AACnB,iBAAW,WAAW,gBAAgB;AAC7B,gBAAA,QAAQ,KAAK,KAAK;AAAA,MAC3B;AAAA,IACD;AAAA,EAAA;AAEF;"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const createNonNullableContextFactory = require("./context/createNonNullableContextFactory.cjs");
4
- const createOptionalContextFactory = require("./context/createOptionalContextFactory.cjs");
3
+ const createRequiredContext = require("./context/createRequiredContext.cjs");
4
+ const createContext = require("./context/createContext.cjs");
5
5
  const Constants = require("./debug-context/Constants.cjs");
6
6
  const Context = require("./debug-context/Context.cjs");
7
7
  const unwrapRefValue = require("./hooks/unwrapRefValue.cjs");
@@ -10,6 +10,8 @@ const useAddClassNameDuringResize = require("./hooks/useAddClassNameDuringResize
10
10
  const useArrayMapMemo = require("./hooks/useArrayMapMemo.cjs");
11
11
  const useAutoHeightTextArea = require("./hooks/useAutoHeightTextArea.cjs");
12
12
  const useChildrenAsLabel = require("./hooks/useChildrenAsLabel.cjs");
13
+ const useCloseOnClickOutside = require("./hooks/useCloseOnClickOutside.cjs");
14
+ const useCloseOnEscape = require("./hooks/useCloseOnEscape.cjs");
13
15
  const useComposeRef = require("./hooks/useComposeRef.cjs");
14
16
  const useConstantLengthInvariant = require("./hooks/useConstantLengthInvariant.cjs");
15
17
  const useConstantValueInvariant = require("./hooks/useConstantValueInvariant.cjs");
@@ -50,8 +52,8 @@ const useClassName = require("./theming/useClassName.cjs");
50
52
  const useClassNameFactory = require("./theming/useClassNameFactory.cjs");
51
53
  const useThemedClassName = require("./theming/useThemedClassName.cjs");
52
54
  const useThemedClassNameFactory = require("./theming/useThemedClassNameFactory.cjs");
53
- exports.createNonNullableContextFactory = createNonNullableContextFactory.createNonNullableContextFactory;
54
- exports.createOptionalContextFactory = createOptionalContextFactory.createOptionalContextFactory;
55
+ exports.createRequiredContext = createRequiredContext.createRequiredContext;
56
+ exports.createContext = createContext.createContext;
55
57
  exports.isNoopScopedConsole = Constants.isNoopScopedConsole;
56
58
  exports.noopLog = Constants.noopLog;
57
59
  exports.noopLogged = Constants.noopLogged;
@@ -66,6 +68,8 @@ exports.useArrayMapMemo = useArrayMapMemo.useArrayMapMemo;
66
68
  exports.useAutoHeightTextArea = useAutoHeightTextArea.useAutoHeightTextArea;
67
69
  exports.getChildrenAsLabel = useChildrenAsLabel.getChildrenAsLabel;
68
70
  exports.useChildrenAsLabel = useChildrenAsLabel.useChildrenAsLabel;
71
+ exports.useCloseOnClickOutside = useCloseOnClickOutside.useCloseOnClickOutside;
72
+ exports.useCloseOnEscape = useCloseOnEscape.useCloseOnEscape;
69
73
  exports.useComposeRef = useComposeRef.useComposeRef;
70
74
  exports.useConstantLengthInvariant = useConstantLengthInvariant.useConstantLengthInvariant;
71
75
  exports.useConstantValueInvariant = useConstantValueInvariant.useConstantValueInvariant;
@@ -90,7 +94,13 @@ exports.useOnScrollWithin = useOnScrollWithin.useOnScrollWithin;
90
94
  exports.useOnWindowResize = useOnWindowResize.useOnWindowResize;
91
95
  exports.usePreviousValue = usePreviousValue.usePreviousValue;
92
96
  exports.useScrollOffsets = useScrollOffsets.useScrollOffsets;
97
+ exports.localStateStorage = useStoredState.localStateStorage;
98
+ exports.nullStorage = useStoredState.nullStorage;
99
+ exports.sessionStateStorage = useStoredState.sessionStateStorage;
100
+ exports.urlStateStorage = useStoredState.urlStateStorage;
101
+ exports.useLocalStorageState = useStoredState.useLocalStorageState;
93
102
  exports.useSessionStorageState = useStoredState.useSessionStorageState;
103
+ exports.useStoredState = useStoredState.useStoredState;
94
104
  exports.useUpdatedRef = useUpdatedRef.useUpdatedRef;
95
105
  exports.useWindowSize = useWindowSize.useWindowSize;
96
106
  exports.emptyArray = emptyArray.emptyArray;