@dr.pogodin/react-utils 1.49.0 → 1.50.0

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 (213) hide show
  1. package/babel.scripts.config.js +19 -0
  2. package/build/development/client/getInj.js +18 -29
  3. package/build/development/client/getInj.js.map +1 -1
  4. package/build/development/client/index.js +11 -14
  5. package/build/development/client/index.js.map +1 -1
  6. package/build/development/client/init.js +9 -17
  7. package/build/development/client/init.js.map +1 -1
  8. package/build/development/index.js +26 -4
  9. package/build/development/index.js.map +1 -1
  10. package/build/development/server/Cache.js +15 -20
  11. package/build/development/server/Cache.js.map +1 -1
  12. package/build/development/server/index.js +142 -160
  13. package/build/development/server/index.js.map +1 -1
  14. package/build/development/server/renderer.js +150 -197
  15. package/build/development/server/renderer.js.map +1 -1
  16. package/build/development/server/server.js +63 -86
  17. package/build/development/server/server.js.map +1 -1
  18. package/build/development/server/utils/errors.js +72 -87
  19. package/build/development/server/utils/errors.js.map +1 -1
  20. package/build/development/shared/components/Button/index.js +8 -17
  21. package/build/development/shared/components/Button/index.js.map +1 -1
  22. package/build/development/shared/components/Checkbox/index.js +12 -5
  23. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  24. package/build/development/shared/components/GenericLink/index.js +54 -58
  25. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  26. package/build/development/shared/components/Input/index.js +16 -24
  27. package/build/development/shared/components/Input/index.js.map +1 -1
  28. package/build/development/shared/components/Link.js +2 -5
  29. package/build/development/shared/components/Link.js.map +1 -1
  30. package/build/development/shared/components/Modal/index.js +28 -41
  31. package/build/development/shared/components/Modal/index.js.map +1 -1
  32. package/build/development/shared/components/NavLink.js +2 -3
  33. package/build/development/shared/components/NavLink.js.map +1 -1
  34. package/build/development/shared/components/PageLayout/index.js +19 -20
  35. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  36. package/build/development/shared/components/TextArea/index.js +12 -28
  37. package/build/development/shared/components/TextArea/index.js.map +1 -1
  38. package/build/development/shared/components/Throbber/index.js +11 -12
  39. package/build/development/shared/components/Throbber/index.js.map +1 -1
  40. package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
  41. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  42. package/build/development/shared/components/WithTooltip/index.js +21 -28
  43. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  44. package/build/development/shared/components/YouTubeVideo/index.js +21 -25
  45. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  46. package/build/development/shared/components/index.js +1 -3
  47. package/build/development/shared/components/index.js.map +1 -1
  48. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
  49. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  50. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
  51. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  52. package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
  53. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  54. package/build/development/shared/components/selectors/Switch/index.js +4 -4
  55. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  56. package/build/development/shared/components/selectors/common.js +2 -5
  57. package/build/development/shared/components/selectors/common.js.map +1 -1
  58. package/build/development/shared/utils/config.js +11 -15
  59. package/build/development/shared/utils/config.js.map +1 -1
  60. package/build/development/shared/utils/globalState.js +1 -7
  61. package/build/development/shared/utils/globalState.js.map +1 -1
  62. package/build/development/shared/utils/index.js +2 -2
  63. package/build/development/shared/utils/index.js.map +1 -1
  64. package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
  65. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  66. package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
  67. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  68. package/build/development/shared/utils/isomorphy/index.js +17 -23
  69. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  70. package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
  71. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  72. package/build/development/shared/utils/jest/index.js +48 -72
  73. package/build/development/shared/utils/jest/index.js.map +1 -1
  74. package/build/development/shared/utils/splitComponent.js +67 -74
  75. package/build/development/shared/utils/splitComponent.js.map +1 -1
  76. package/build/development/shared/utils/time.js +25 -28
  77. package/build/development/shared/utils/time.js.map +1 -1
  78. package/build/development/shared/utils/webpack.js +22 -29
  79. package/build/development/shared/utils/webpack.js.map +1 -1
  80. package/build/production/client/getInj.js.map +1 -1
  81. package/build/production/client/index.js.map +1 -1
  82. package/build/production/index.js +26 -1
  83. package/build/production/index.js.map +1 -1
  84. package/build/production/server/Cache.js.map +1 -1
  85. package/build/production/server/index.js.map +1 -1
  86. package/build/production/server/renderer.js.map +1 -1
  87. package/build/production/server/server.js.map +1 -1
  88. package/build/production/shared/components/Button/index.js.map +1 -1
  89. package/build/production/shared/components/Checkbox/index.js +1 -1
  90. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  91. package/build/production/shared/components/GenericLink/index.js +2 -2
  92. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  93. package/build/production/shared/components/Input/index.js.map +1 -1
  94. package/build/production/shared/components/Link.js.map +1 -1
  95. package/build/production/shared/components/Modal/index.js.map +1 -1
  96. package/build/production/shared/components/NavLink.js.map +1 -1
  97. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  98. package/build/production/shared/components/TextArea/index.js.map +1 -1
  99. package/build/production/shared/components/Throbber/index.js.map +1 -1
  100. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  101. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  102. package/build/production/shared/components/index.js.map +1 -1
  103. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  105. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  106. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  107. package/build/production/shared/utils/config.js.map +1 -1
  108. package/build/production/shared/utils/index.js.map +1 -1
  109. package/build/production/shared/utils/jest/index.js.map +1 -1
  110. package/build/production/shared/utils/splitComponent.js +20 -3
  111. package/build/production/shared/utils/splitComponent.js.map +1 -1
  112. package/build/production/shared/utils/time.js.map +1 -1
  113. package/build/production/shared/utils/webpack.js.map +1 -1
  114. package/build/types-code/shared/components/Checkbox/index.d.ts +3 -2
  115. package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
  116. package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +2 -0
  117. package/build/web/client/getInj.js +10 -70
  118. package/build/web/client/getInj.js.map +1 -1
  119. package/build/web/client/index.js +2 -27
  120. package/build/web/client/index.js.map +1 -1
  121. package/build/web/client/init.js +10 -44
  122. package/build/web/client/init.js.map +1 -1
  123. package/build/web/index.js +26 -6
  124. package/build/web/index.js.map +1 -1
  125. package/build/web/server/Cache.js +3 -41
  126. package/build/web/server/Cache.js.map +1 -1
  127. package/build/web/server/index.js +7 -78
  128. package/build/web/server/index.js.map +1 -1
  129. package/build/web/server/renderer.js +61 -420
  130. package/build/web/server/renderer.js.map +1 -1
  131. package/build/web/server/server.js +38 -212
  132. package/build/web/server/server.js.map +1 -1
  133. package/build/web/server/utils/errors.js +9 -48
  134. package/build/web/server/utils/errors.js.map +1 -1
  135. package/build/web/server/utils/index.js +1 -2
  136. package/build/web/server/utils/index.js.map +1 -1
  137. package/build/web/shared/components/Button/index.js +12 -101
  138. package/build/web/shared/components/Button/index.js.map +1 -1
  139. package/build/web/shared/components/Checkbox/index.js +1 -35
  140. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  141. package/build/web/shared/components/Checkbox/theme.scss +22 -0
  142. package/build/web/shared/components/GenericLink/index.js +12 -65
  143. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  144. package/build/web/shared/components/GenericLink/style.scss +1 -0
  145. package/build/web/shared/components/Input/index.js +11 -69
  146. package/build/web/shared/components/Input/index.js.map +1 -1
  147. package/build/web/shared/components/Link.js +2 -12
  148. package/build/web/shared/components/Link.js.map +1 -1
  149. package/build/web/shared/components/Modal/index.js +10 -130
  150. package/build/web/shared/components/Modal/index.js.map +1 -1
  151. package/build/web/shared/components/NavLink.js +2 -10
  152. package/build/web/shared/components/NavLink.js.map +1 -1
  153. package/build/web/shared/components/PageLayout/index.js +2 -27
  154. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  155. package/build/web/shared/components/TextArea/index.js +21 -106
  156. package/build/web/shared/components/TextArea/index.js.map +1 -1
  157. package/build/web/shared/components/Throbber/index.js +2 -24
  158. package/build/web/shared/components/Throbber/index.js.map +1 -1
  159. package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
  160. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  161. package/build/web/shared/components/WithTooltip/index.js +12 -104
  162. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  163. package/build/web/shared/components/YouTubeVideo/index.js +5 -43
  164. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  165. package/build/web/shared/components/index.js +1 -15
  166. package/build/web/shared/components/index.js.map +1 -1
  167. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
  168. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  169. package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
  170. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  171. package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
  172. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  173. package/build/web/shared/components/selectors/Switch/index.js +1 -49
  174. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  175. package/build/web/shared/components/selectors/common.js +1 -10
  176. package/build/web/shared/components/selectors/common.js.map +1 -1
  177. package/build/web/shared/components/selectors/index.js +1 -3
  178. package/build/web/shared/components/selectors/index.js.map +1 -1
  179. package/build/web/shared/utils/config.js +6 -40
  180. package/build/web/shared/utils/config.js.map +1 -1
  181. package/build/web/shared/utils/globalState.js +2 -11
  182. package/build/web/shared/utils/globalState.js.map +1 -1
  183. package/build/web/shared/utils/index.js +1 -9
  184. package/build/web/shared/utils/index.js.map +1 -1
  185. package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
  186. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  187. package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
  188. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  189. package/build/web/shared/utils/isomorphy/index.js +5 -27
  190. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  191. package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
  192. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  193. package/build/web/shared/utils/jest/global.js +1 -3
  194. package/build/web/shared/utils/jest/global.js.map +1 -1
  195. package/build/web/shared/utils/jest/index.js +27 -146
  196. package/build/web/shared/utils/jest/index.js.map +1 -1
  197. package/build/web/shared/utils/splitComponent.js +34 -197
  198. package/build/web/shared/utils/splitComponent.js.map +1 -1
  199. package/build/web/shared/utils/time.js +5 -69
  200. package/build/web/shared/utils/time.js.map +1 -1
  201. package/build/web/shared/utils/webpack.js +6 -53
  202. package/build/web/shared/utils/webpack.js.map +1 -1
  203. package/config/babel/webpack.js +1 -1
  204. package/eslint.config.mjs +1 -0
  205. package/package.json +10 -13
  206. package/bin/build.js +0 -236
  207. package/config/webpack/lib-base.d.ts +0 -22
  208. package/config/webpack/lib-base.js +0 -167
  209. package/config/webpack/lib-development.d.ts +0 -5
  210. package/config/webpack/lib-development.js +0 -35
  211. package/config/webpack/lib-production.d.ts +0 -5
  212. package/config/webpack/lib-production.js +0 -42
  213. package/webpack.config.ts +0 -49
@@ -1,82 +1,7 @@
1
- import "core-js/modules/es.array.push.js";
2
- import "core-js/modules/es.iterator.constructor.js";
3
- import "core-js/modules/es.iterator.filter.js";
4
- import { useImperativeHandle, useRef } from 'react';
5
- import { BaseModal } from "../../../Modal";
6
- import { optionValueName } from "../../common";
7
- import S from "./style.scss";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- export function areEqual(a, b) {
10
- return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;
11
- }
12
- const Options = ({
13
- containerClass,
14
- containerStyle,
15
- filter,
16
- onCancel,
17
- onChange,
18
- optionClass,
19
- options,
20
- ref
21
- }) => {
22
- const opsRef = useRef(null);
23
- useImperativeHandle(ref, () => ({
24
- measure: () => {
25
- const e = opsRef.current?.parentElement;
26
- if (!e) return undefined;
27
- const rect = opsRef.current.getBoundingClientRect();
28
- const style = window.getComputedStyle(e);
29
- const mBottom = parseFloat(style.marginBottom);
30
- const mTop = parseFloat(style.marginTop);
31
- rect.height += mBottom + mTop;
32
- return rect;
33
- }
34
- }), []);
35
- const optionNodes = [];
36
- for (const option of options) {
37
- if (!filter || filter(option)) {
38
- const [iValue, iName] = optionValueName(option);
39
- optionNodes.push(/*#__PURE__*/_jsx("div", {
40
- className: optionClass,
41
- onClick: e => {
42
- onChange(iValue);
43
- e.stopPropagation();
44
- },
45
- onKeyDown: e => {
46
- if (e.key === 'Enter') {
47
- onChange(iValue);
48
- e.stopPropagation();
49
- }
50
- },
51
- role: "button",
52
- tabIndex: 0,
53
- children: iName
54
- }, iValue));
55
- }
56
- }
57
- return /*#__PURE__*/_jsx(BaseModal
58
- // Closes the dropdown (cancels the selection) on any page scrolling attempt.
59
- // This is the same native <select> elements do on scrolling, and at least for
60
- // now we have no reason to deal with complications needed to support open
61
- // dropdowns during the scrolling (that would need to re-position it in
62
- // response to the position changes of the root dropdown element).
63
- , {
64
- cancelOnScrolling: true,
65
- dontDisableScrolling: true,
66
- onCancel: onCancel,
67
- style: containerStyle,
68
- theme: {
69
- ad: '',
70
- container: containerClass,
71
- context: '',
72
- hoc: '',
73
- overlay: S.overlay
74
- },
75
- children: /*#__PURE__*/_jsx("div", {
76
- ref: opsRef,
77
- children: optionNodes
78
- })
79
- });
80
- };
81
- export default Options;
1
+ import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";import{useImperativeHandle,useRef}from"react";import{BaseModal}from"../../../Modal";import{optionValueName}from"../../common";import S from"./style.scss";import{jsx as _jsx}from"react/jsx-runtime";export function areEqual(a,b){return a?.left===b?.left&&a?.top===b?.top&&a?.width===b?.width;}const Options=({containerClass,containerStyle,filter,onCancel,onChange,optionClass,options,ref})=>{const opsRef=useRef(null);useImperativeHandle(ref,()=>({measure:()=>{const e=opsRef.current?.parentElement;if(!e)return undefined;const rect=opsRef.current.getBoundingClientRect();const style=window.getComputedStyle(e);const mBottom=parseFloat(style.marginBottom);const mTop=parseFloat(style.marginTop);rect.height+=mBottom+mTop;return rect;}}),[]);const optionNodes=[];for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);optionNodes.push(/*#__PURE__*/_jsx("div",{className:optionClass,onClick:e=>{onChange(iValue);e.stopPropagation();},onKeyDown:e=>{if(e.key==="Enter"){onChange(iValue);e.stopPropagation();}},role:"button",tabIndex:0,children:iName},iValue));}}return/*#__PURE__*/_jsx(BaseModal// Closes the dropdown (cancels the selection) on any page scrolling attempt.
2
+ // This is the same native <select> elements do on scrolling, and at least for
3
+ // now we have no reason to deal with complications needed to support open
4
+ // dropdowns during the scrolling (that would need to re-position it in
5
+ // response to the position changes of the root dropdown element).
6
+ ,{cancelOnScrolling:true,dontDisableScrolling:true,onCancel:onCancel,style:containerStyle,theme:{ad:"",container:containerClass,context:"",hoc:"",overlay:S.overlay},children:/*#__PURE__*/_jsx("div",{ref:opsRef,children:optionNodes})});};export default Options;
82
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useImperativeHandle","useRef","BaseModal","optionValueName","S","jsx","_jsx","areEqual","a","b","left","top","width","Options","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","option","iValue","iName","push","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","cancelOnScrolling","dontDisableScrolling","theme","ad","container","context","hoc","overlay"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;;AAAA,SAIEA,mBAAmB,EACnBC,MAAM,QACD,OAAO;AAEd,SAASC,SAAS;AAElB,SAIEC,eAAe;AAGjB,OAAOC,CAAC;AAAqB,SAAAC,GAAA,IAAAC,IAAA;AAQ7B,OAAO,SAASC,QAAQA,CAACC,CAAiB,EAAEC,CAAiB,EAAW;EACtE,OAAOD,CAAC,EAAEE,IAAI,KAAKD,CAAC,EAAEC,IAAI,IAAIF,CAAC,EAAEG,GAAG,KAAKF,CAAC,EAAEE,GAAG,IAAIH,CAAC,EAAEI,KAAK,KAAKH,CAAC,EAAEG,KAAK;AAC1E;AAiBA,MAAMC,OAAkC,GAAGA,CAAC;EAC1CC,cAAc;EACdC,cAAc;EACdC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,WAAW;EACXC,OAAO;EACPC;AACF,CAAC,KAAK;EACJ,MAAMC,MAAM,GAAGrB,MAAM,CAAiB,IAAI,CAAC;EAE3CD,mBAAmB,CAACqB,GAAG,EAAE,OAAO;IAC9BE,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,CAAC,GAAGF,MAAM,CAACG,OAAO,EAAEC,aAAa;MACvC,IAAI,CAACF,CAAC,EAAE,OAAOG,SAAS;MAExB,MAA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,EAAE,EAAE,EAAE;MACNC,SAAS,EAAE1C,cAAc;MACzB2C,OAAO,EAAE,EAAE;MACXC,GAAG,EAAE,EAAE;MACPC,OAAO,EAAEvD,CAAC,CAACuD;IACb,CAAE;IAAAR,QAAA,eAEF7C,IAAA;MAAKe,GAAG,EAAEC,MAAO;MAAA6B,QAAA,EAAEZ;IAAW,CAAM;EAAC,CAC5B,CAAC;AAEhB,CAAC;AAED,eAAe1B,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useImperativeHandle","useRef","BaseModal","optionValueName","S","jsx","_jsx","areEqual","a","b","left","top","width","Options","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","option","iValue","iName","push","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","cancelOnScrolling","dontDisableScrolling","theme","ad","container","context","hoc","overlay"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":"0IAAA,OAIEA,mBAAmB,CACnBC,MAAM,KACD,OAAO,CAEd,OAASC,SAAS,sBAElB,OAIEC,eAAe,oBAGjB,MAAO,CAAAC,CAAC,oBAAqB,OAAAC,GAAA,IAAAC,IAAA,yBAQ7B,MAAO,SAAS,CAAAC,QAAQA,CAACC,CAAiB,CAAEC,CAAiB,CAAW,CACtE,MAAO,CAAAD,CAAC,EAAEE,IAAI,GAAKD,CAAC,EAAEC,IAAI,EAAIF,CAAC,EAA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,CAAC,EAAK,CACdN,QAAQ,CAACuB,MAAM,CAAC,CAChBjB,CAAC,CAACsB,eAAe,CAAC,CAAC,CACrB,CAAE,CACFC,SAAS,CAAGvB,CAAC,EAAK,CAChB,GAAIA,CAAC,CAACwB,GAAG,GAAK,OAAO,CAAE,CACrB9B,QAAQ,CAACuB,MAAM,CAAC,CAChBjB,CAAC,CAACsB,eAAe,CAAC,CAAC,CACrB,CACF,CAAE,CACFG,IAAI,CAAC,QAAQ,CACbC,QAAQ,CAAE,CAAE,CAAAC,QAAA,CAEXT,KAAK,EAdDD,MAeF,CACP,CAAC,CACH,CACF,CAEA,mBACEnC,IAAA,CAACJ,SACC;AACA;AACA;AACA;AACA;AAAA,EACAkD,iBAAiB,MACjBC,oBAAoB,MACpBpC,QAAQ,CAAEA,QAAS,CACnBa,KAAK,CAAEf,cAAe,CACtBuC,KAAK,CAAE,CACLC,EAAE,CAAE,EAAE,CACNC,SAAS,CAAE1C,cAAc,CACzB2C,OAAO,CAAE,EAAE,CACXC,GAAG,CAAE,EAAE,CACPC,OAAO,CAAEvD,CAAC,CAACuD,OACb,CAAE,CAAAR,QAAA,cAEF7C,IAAA,QAAKe,GAAG,CAAEC,MAAO,CAAA6B,QAAA,CAAEZ,WAAW,CAAM,CAAC,CAC5B,CAAC,CAEhB,CAAC,CAED,cAAe,CAAA1B,OAAO","ignoreList":[]}
@@ -1,123 +1,8 @@
1
- import "core-js/modules/es.iterator.constructor.js";
2
- import "core-js/modules/es.iterator.filter.js";
3
- import { useEffect, useRef, useState } from 'react';
4
- import { useTheme } from '@dr.pogodin/react-themes';
5
- import { optionValueName } from "../common";
6
- import Options, { areEqual } from "./Options";
7
- import defaultTheme from "./theme.scss";
8
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
- const CustomDropdown = ({
10
- filter,
11
- label,
12
- onChange,
13
- options,
14
- theme,
15
- value
16
- }) => {
17
- const custom = useTheme('CustomDropdown', defaultTheme, theme);
18
- const [active, setActive] = useState(false);
19
- const dropdownRef = useRef(null);
20
- const opsRef = useRef(null);
21
- const [opsPos, setOpsPos] = useState();
22
- const [upward, setUpward] = useState(false);
23
- useEffect(() => {
24
- if (!active) return undefined;
25
- let id;
26
- const cb = () => {
27
- const anchor = dropdownRef.current?.getBoundingClientRect();
28
- const opsRect = opsRef.current?.measure();
29
- if (anchor && opsRect) {
30
- const fitsDown = anchor.bottom + opsRect.height < (window.visualViewport?.height ?? 0);
31
- const fitsUp = anchor.top - opsRect.height > 0;
32
- const up = !fitsDown && fitsUp;
33
- setUpward(up);
34
- const pos = up ? {
35
- left: anchor.left,
36
- top: anchor.top - opsRect.height - 1,
37
- width: anchor.width
38
- } : {
39
- left: anchor.left,
40
- top: anchor.bottom,
41
- width: anchor.width
42
- };
43
- setOpsPos(now => areEqual(now, pos) ? now : pos);
44
- }
45
- id = requestAnimationFrame(cb);
46
- };
47
- requestAnimationFrame(cb);
48
- return () => {
49
- cancelAnimationFrame(id);
50
- };
51
- }, [active]);
52
- const openList = e => {
53
- const view = window.visualViewport;
54
- const rect = dropdownRef.current.getBoundingClientRect();
55
- setActive(true);
56
-
57
- // NOTE: This first opens the dropdown off-screen, where it is measured
58
- // by an effect declared above, and then positioned below, or above
59
- // the original dropdown element, depending where it fits best
60
- // (if we first open it downward, it would flick if we immediately
61
- // move it above, at least with the current position update via local
62
- // react state, and not imperatively).
63
- setOpsPos({
64
- left: view?.width ?? 0,
65
- top: view?.height ?? 0,
66
- width: rect.width
67
- });
68
- e.stopPropagation();
69
- };
70
- let selected = /*#__PURE__*/_jsx(_Fragment, {
71
- children: "\u200C"
72
- });
73
- for (const option of options) {
74
- if (!filter || filter(option)) {
75
- const [iValue, iName] = optionValueName(option);
76
- if (iValue === value) {
77
- selected = iName;
78
- break;
79
- }
80
- }
81
- }
82
- let containerClassName = custom.container;
83
- if (active) containerClassName += ` ${custom.active}`;
84
- let opsContainerClass = custom.select ?? '';
85
- if (upward) {
86
- containerClassName += ` ${custom.upward}`;
87
- opsContainerClass += ` ${custom.upward}`;
88
- }
89
- return /*#__PURE__*/_jsxs("div", {
90
- className: containerClassName,
91
- children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {
92
- className: custom.label,
93
- children: label
94
- }), /*#__PURE__*/_jsxs("div", {
95
- className: custom.dropdown,
96
- onClick: openList,
97
- onKeyDown: e => {
98
- if (e.key === 'Enter') openList(e);
99
- },
100
- ref: dropdownRef,
101
- role: "listbox",
102
- tabIndex: 0,
103
- children: [selected, /*#__PURE__*/_jsx("div", {
104
- className: custom.arrow
105
- })]
106
- }), active ? /*#__PURE__*/_jsx(Options, {
107
- containerClass: opsContainerClass,
108
- containerStyle: opsPos,
109
- onCancel: () => {
110
- setActive(false);
111
- },
112
- onChange: newValue => {
113
- setActive(false);
114
- if (onChange) onChange(newValue);
115
- },
116
- optionClass: custom.option ?? '',
117
- options: options,
118
- ref: opsRef
119
- }) : null]
120
- });
121
- };
122
- export default CustomDropdown;
1
+ import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";import{useEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common";import Options,{areEqual}from"./Options";import defaultTheme from"./theme.scss";import{Fragment as _Fragment,jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CustomDropdown=({filter,label,onChange,options,theme,value})=>{const custom=useTheme("CustomDropdown",defaultTheme,theme);const[active,setActive]=useState(false);const dropdownRef=useRef(null);const opsRef=useRef(null);const[opsPos,setOpsPos]=useState();const[upward,setUpward]=useState(false);useEffect(()=>{if(!active)return undefined;let id;const cb=()=>{const anchor=dropdownRef.current?.getBoundingClientRect();const opsRect=opsRef.current?.measure();if(anchor&&opsRect){const fitsDown=anchor.bottom+opsRect.height<(window.visualViewport?.height??0);const fitsUp=anchor.top-opsRect.height>0;const up=!fitsDown&&fitsUp;setUpward(up);const pos=up?{left:anchor.left,top:anchor.top-opsRect.height-1,width:anchor.width}:{left:anchor.left,top:anchor.bottom,width:anchor.width};setOpsPos(now=>areEqual(now,pos)?now:pos);}id=requestAnimationFrame(cb);};requestAnimationFrame(cb);return()=>{cancelAnimationFrame(id);};},[active]);const openList=e=>{const view=window.visualViewport;const rect=dropdownRef.current.getBoundingClientRect();setActive(true);// NOTE: This first opens the dropdown off-screen, where it is measured
2
+ // by an effect declared above, and then positioned below, or above
3
+ // the original dropdown element, depending where it fits best
4
+ // (if we first open it downward, it would flick if we immediately
5
+ // move it above, at least with the current position update via local
6
+ // react state, and not imperatively).
7
+ setOpsPos({left:view?.width??0,top:view?.height??0,width:rect.width});e.stopPropagation();};let selected=/*#__PURE__*/_jsx(_Fragment,{children:"\u200C"});for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);if(iValue===value){selected=iName;break;}}}let containerClassName=custom.container;if(active)containerClassName+=` ${custom.active}`;let opsContainerClass=custom.select??"";if(upward){containerClassName+=` ${custom.upward}`;opsContainerClass+=` ${custom.upward}`;}return/*#__PURE__*/_jsxs("div",{className:containerClassName,children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:custom.label,children:label}),/*#__PURE__*/_jsxs("div",{className:custom.dropdown,onClick:openList,onKeyDown:e=>{if(e.key==="Enter")openList(e);},ref:dropdownRef,role:"listbox",tabIndex:0,children:[selected,/*#__PURE__*/_jsx("div",{className:custom.arrow})]}),active?/*#__PURE__*/_jsx(Options,{containerClass:opsContainerClass,containerStyle:opsPos,onCancel:()=>{setActive(false);},onChange:newValue=>{setActive(false);if(onChange)onChange(newValue);},optionClass:custom.option??"",options:options,ref:opsRef}):null]});};export default CustomDropdown;
123
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","optionValueName","Options","areEqual","defaultTheme","Fragment","_Fragment","jsx","_jsx","jsxs","_jsxs","CustomDropdown","filter","label","onChange","options","theme","value","custom","active","setActive","dropdownRef","opsRef","opsPos","setOpsPos","upward","setUpward","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","requestAnimationFrame","cancelAnimationFrame","openList","e","view","rect","stopPropagation","selected","children","option","iValue","iName","containerClassName","container","opsContainerClass","select","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container;\n if (active) containerClassName += ` ${custom.active}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward}`;\n opsContainerClass += ` ${custom.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":";;AAAA,SAGEA,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAASC,QAAQ,QAAQ,0BAA0B;AAEnD,SAAmCC,eAAe;AAElD,OAAOC,OAAO,IAAmCC,QAAQ;AAEzD,OAAOC,YAAY;AAAqB,SAAAC,QAA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ElD,MAAO;MACvBmD,QAAQ,EAAEA,CAAA,KAAM;QACdtD,SAAS,CAAC,KAAK,CAAC;MAClB,CAAE;MACFN,QAAQ,EAAG6D,QAAQ,IAAK;QACtBvD,SAAS,CAAC,KAAK,CAAC;QAChB,IAAIN,QAAQ,EAAEA,QAAQ,CAAC6D,QAAQ,CAAC;MAClC,CAAE;MACFC,WAAW,EAAE1D,MAAM,CAACsC,MAAM,IAAI,EAAG;MACjCzC,OAAO,EAAEA,OAAQ;MACjBqD,GAAG,EAAE9C;IAAO,CACb,CAAC,GACA,IAAI;EAAA,CAEP,CAAC;AAEV,CAAC;AAED,eAAeX,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","optionValueName","Options","areEqual","defaultTheme","Fragment","_Fragment","jsx","_jsx","jsxs","_jsxs","CustomDropdown","filter","label","onChange","options","theme","value","custom","active","setActive","dropdownRef","opsRef","opsPos","setOpsPos","upward","setUpward","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","requestAnimationFrame","cancelAnimationFrame","openList","e","view","rect","stopPropagation","selected","children","option","iValue","iName","containerClassName","container","opsContainerClass","select","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container;\n if (active) containerClassName += ` ${custom.active}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward}`;\n opsContainerClass += ` ${custom.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":"iGAAA,OAGEA,SAAS,CACTC,MAAM,CACNC,QAAQ,KACH,OAAO,CAEd,OAASC,QAAQ,KAAQ,0BAA0B,CAEnD,OAAmCC,eAAe,iBAElD,MAAO,CAAAC,OAAO,EAAmCC,QAAQ,iBAEzD,MAAO,CAAAC,YAAY,oBAAqB,OAAAC,QAAA,IAAAC,SAAA,CAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAExC,KAAM,CAAAC,cAEL,CAAGA,CAAC,CACHC,MAAM,CACNC,KAAK,CACLC,QAAQ,CACRC,OAAO,CACPC,KAAK,CACLC,KACF,CAAC,GAAK,CACJ,KAAM,CAAAC,MAAM,CAAGlB,QAAQ,CAAC,gBAAgB,CAAEI,YAAY,CAAEY,KAAK,CAAC,CAE9D,KAAM,CAACG,MAAM,CAAEC,SAAS,CAAC,CAAGrB,QAAQ,CAAC,KAAK,CAAC,CAE3C,KAAM,CAAAsB,WAAW,CAAGvB,MAAM,CAAiB,IAAI,CAAC,CAChD,KAAM,CAAAwB,MAAM,CAAGxB,MAAM,CAAO,IAAI,CAAC,CAEjC,KAAM,CAACyB,MAAM,CAAEC,SAAS,CAAC,CAAGzB,QAAQ,CAAgB,CAAC,CACrD,KAAM,CAAC0B,MAAM,CAAEC,SAAS,CAAC,CAAG3B,Q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
- import "core-js/modules/es.iterator.filter.js";
4
- // Implements dropdown based on the native HTML <select> element.
5
-
6
- import { useTheme } from '@dr.pogodin/react-themes';
7
- import { optionValueName } from "../common";
8
- import defaultTheme from "./theme.scss";
9
-
10
- /**
1
+ import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";// Implements dropdown based on the native HTML <select> element.
2
+ import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common";import defaultTheme from"./theme.scss";/**
11
3
  * Implements a themeable dropdown list. Internally it is rendered with help of
12
4
  * the standard HTML `<select>` element, thus the styling support is somewhat
13
5
  * limited.
@@ -25,62 +17,9 @@ import defaultTheme from "./theme.scss";
25
17
  * @param [props.value] Currently selected value.
26
18
  * @param [props....]
27
19
  * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
28
- */
29
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
30
- const Dropdown = ({
31
- filter,
32
- label,
33
- onChange,
34
- options,
35
- testId,
36
- theme,
37
- value
38
- }) => {
39
- let isValidValue = false;
40
- const optionElements = [];
41
- const composed = useTheme('Dropdown', defaultTheme, theme);
42
- for (const option of options) {
43
- if (!filter || filter(option)) {
44
- const [iValue, iName] = optionValueName(option);
45
- isValidValue ||= iValue === value;
46
- optionElements.push(/*#__PURE__*/_jsx("option", {
47
- className: composed.option,
48
- value: iValue,
49
- children: iName
50
- }, iValue));
51
- }
52
- }
53
-
54
- // NOTE: This element represents the current `value` when it does not match
55
- // any valid option. In Chrome, and some other browsers, we are able to hide
56
- // it from the opened dropdown; in others, e.g. Safari, the best we can do is
57
- // to show it as disabled.
58
- const hiddenOption = isValidValue ? null : /*#__PURE__*/_jsx("option", {
59
- className: composed.hiddenOption,
60
- disabled: true,
61
- value: value,
62
- children: value
63
- }, "__reactUtilsHiddenOption");
64
- let selectClassName = composed.select;
65
- if (!isValidValue) selectClassName += ` ${composed.invalid}`;
66
- return /*#__PURE__*/_jsxs("div", {
67
- className: composed.container,
68
- children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {
69
- className: composed.label,
70
- children: label
71
- }), /*#__PURE__*/_jsxs("div", {
72
- className: composed.dropdown,
73
- children: [/*#__PURE__*/_jsxs("select", {
74
- className: selectClassName,
75
- "data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
76
- onChange: onChange,
77
- value: value,
78
- children: [hiddenOption, optionElements]
79
- }), /*#__PURE__*/_jsx("div", {
80
- className: composed.arrow
81
- })]
82
- })]
83
- });
84
- };
85
- export default Dropdown;
20
+ */import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Dropdown=({filter,label,onChange,options,testId,theme,value})=>{let isValidValue=false;const optionElements=[];const composed=useTheme("Dropdown",defaultTheme,theme);for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);isValidValue||=iValue===value;optionElements.push(/*#__PURE__*/_jsx("option",{className:composed.option,value:iValue,children:iName},iValue));}}// NOTE: This element represents the current `value` when it does not match
21
+ // any valid option. In Chrome, and some other browsers, we are able to hide
22
+ // it from the opened dropdown; in others, e.g. Safari, the best we can do is
23
+ // to show it as disabled.
24
+ const hiddenOption=isValidValue?null:/*#__PURE__*/_jsx("option",{className:composed.hiddenOption,disabled:true,value:value,children:value},"__reactUtilsHiddenOption");let selectClassName=composed.select;if(!isValidValue)selectClassName+=` ${composed.invalid}`;return/*#__PURE__*/_jsxs("div",{className:composed.container,children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label}),/*#__PURE__*/_jsxs("div",{className:composed.dropdown,children:[/*#__PURE__*/_jsxs("select",{className:selectClassName,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,onChange:onChange,value:value,children:[hiddenOption,optionElements]}),/*#__PURE__*/_jsx("div",{className:composed.arrow})]})]});};export default Dropdown;
86
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useTheme","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","Dropdown","filter","label","onChange","options","testId","theme","value","isValidValue","optionElements","composed","option","iValue","iName","push","className","children","hiddenOption","disabled","selectClassName","select","invalid","container","undefined","dropdown","process","env","NODE_ENV","arrow"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select;\n if (!isValidValue) selectClassName += ` ${composed.invalid}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":";;;AAAA;;AAIA,SAASA,QAAQ,QAAQ,0BAA0B;AAEnD,SAAsBC,eAAe;AAErC,OAAOC,YAAY;;AAEnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAlBA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAmBA,MAAMC,QAA2C,GAAGA,CAAC;EACnDC,MAAM;EACNC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC,MAAM;EACNC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,IAAIC,YAAY,GAAG,KAAK;EACxB,MAAMC,cAAc,GAAG,EAAE;EAEzB,MAAMC,QAAQ,GAAGjB,QAAQ,CAAC,UAAU,EAAEE,YAAY,EAAEW,KAAK,CAAC;EAE1D,KAAK,MAAMK,MAAM,IAAIP,OAAO,EAAE;IAC5B,IAAI,CAACH,MAAM,IAAIA,MAAM,CAACU,MAAM,CAAC,EAAE;MAC7B,MAAM,CAACC,MAAM,EAAEC,KAAK,CAAC,GAAGnB,eAAe,CAACiB,MAAM,CAAC;MAC/CH,YAAY,KAAKI,MAAM,KAAKL,KAAK;MACjCE,cAAc,CAACK,IAAI,cACjBjB,IAAA;QAAQkB,SAAS,EAAEL,QAAQ,CAACC,MAAO;QAAcJ,KAAK,EAAEK,MAAO;QAAAI,QAAA,EAC5DH;MAAK,GADiCD,MAEjC,CACV,CAAC;IACH;EACF;;EAEA;EACA;EACA;EACA;EACA,MAAMK,YAAY,GAAGT,YAAY,GAAG,IAAI,gBACtCX,IAAA;IACEkB,SAAS,EAAEL,QAAQ,CAACO,YAAa;IACjCC,QAAQ;IAERX,KAAK,EAAEA,KAAM;IAAAS,QAAA,EAEZT;EAAK,GAHF,0BAIE,CACT;EAED,IAAIY,eAAe,GAAGT,QAAQ,CAACU,MAAM;EACrC,IAAI,CAACZ,YAAY,EAAEW,eAAe,IAAI,IAAIT,QAAQ,CAACW,OAAO,EAAE;EAE5D,oBACEtB,KAAA;IAAKgB,SAAS,EAAEL,QAAQ,CAACY,SAAU;IAAAN,QAAA,GAC/Bd,KAAK,KAAKqB,SAAS,GACjB,IAAI,gBAAG1B,IAAA;MAAKkB,SAAS,EAAEL,QAAQ,CAACR,KAAM;MAAAc,QAAA,EAAEd;IAAK,CAAM,CAAC,eACxDH,KAAA;MAAKgB,SAAS,EAAEL,QAAQ,CAACc,QAAS;MAAAR,QAAA,gBAChCjB,KAAA;QACEgB,SAAS,EAAEI,eAAgB;QAC3B,eAAaM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAGJ,SAAS,GAAGlB,MAAO;QACxEF,QAAQ,EAAEA,QAAS;QACnBI,KAAK,EAAEA,KAAM;QAAAS,QAAA,GAEZC,YAAY,EACZR,cAAc;MAAA,CACT,CAAC,eACTZ,IAAA;QAAKkB,SAAS,EAAEL,QAAQ,CAACkB;MAAM,CAAE,CAAC;IAAA,CAC/B,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAED,eAAe5B,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useTheme","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","Dropdown","filter","label","onChange","options","testId","theme","value","isValidValue","optionElements","composed","option","iValue","iName","push","className","children","hiddenOption","disabled","selectClassName","select","invalid","container","undefined","dropdown","process","env","NODE_ENV","arrow"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select;\n if (!isValidValue) selectClassName += ` ${composed.invalid}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":"0IAAA;AAIA,OAASA,QAAQ,KAAQ,0BAA0B,CAEnD,OAAsBC,eAAe,iBAErC,MAAO,CAAAC,YAAY,oBAEnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAlBA,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAmBA,KAAM,CAAAC,QAA2C,CAAGA,CAAC,CACnDC,MAAM,CACNC,KAAK,CACLC,QAAQ,CACRC,OAAO,CACPC,MAAM,CACNC,KAAK,CACLC,KACF,CAAC,GAAK,CACJ,GAAI,CAAAC,YAAY,CAAG,KAAK,CACxB,KAAM,CAAAC,cAAc,CAAG,EAAE,CAEzB,KAAM,CAAAC,QAAQ,CAAGjB,QAAQ,CAAC,UAAU,CAAEE,YAAY,CAAEW,KAAK,CAAC,CAE1D,IAAK,KAAM,CAAAK,MAAM,GAAI,CAAAP,OAAO,CAAE,CAC5B,GAAI,CAACH,MAAM,EAAIA,MAAM,CAACU,MAAM,CAAC,CAAE,CAC7B,KAAM,CAACC,MAAM,CAAEC,KAAK,CAAC,CAAGnB,eAAe,CAACiB,MAAM,CAAC,CAC/CH,YAAY,GAAKI,MAAM,GAAKL,KAAK,CACjCE,cAAc,CAACK,IAAI,cACjBjB,IAAA,WAAQkB,SAAS,CAAEL,QAAQ,CAACC,MAAO,CAAcJ,KAAK,CAAEK,MAAO,CAAAI,QAAA,CAC5DH,KAAK,EADiCD,MAEjC,CACV,CAAC,CACH,CACF,CAEA;AACA;AACA;AACA;AACA,KAAM,CAAAK,YAAY,CAAGT,YAAY,CAAG,IAAI,cACtCX,IAAA,WACEkB,SAAS,CAAEL,QAAQ,CAACO,YAAa,CACjCC,QAAQ,MAERX,KAAK,CAAEA,KAAM,CAAAS,QAAA,CAEZT,KAAK,EAHF,0BAIE,CACT,CAED,GAAI,CAAAY,eAAe,CAAGT,QAAQ,CAACU,MAAM,CACrC,GAAI,CAACZ,YAAY,CAAEW,eAAe,EAAI,IAAIT,QAAQ,CAACW,OAAO,EAAE,CAE5D,mBACEtB,KAAA,QAAKgB,SAAS,CAAEL,QAAQ,CAACY,SAAU,CAAAN,QAAA,EAC/Bd,KAAK,GAAKqB,SAAS,CACjB,IAAI,cAAG1B,IAAA,QAAKkB,SAAS,CAAEL,QAAQ,CAACR,KAAM,CAAAc,QAAA,CAAEd,KAAK,CAAM,CAAC,cACxDH,KAAA,QAAKgB,SAAS,CAAEL,QAAQ,CAACc,QAAS,CAAAR,QAAA,eAChCjB,KAAA,WACEgB,SAAS,CAAEI,eAAgB,CAC3B,cAAaM,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAGJ,SAAS,CAAGlB,MAAO,CACxEF,QAAQ,CAAEA,QAAS,CACnBI,KAAK,CAAEA,KAAM,CAAAS,QAAA,EAEZC,YAAY,CACZR,cAAc,EACT,CAAC,cACTZ,IAAA,QAAKkB,SAAS,CAAEL,QAAQ,CAACkB,KAAM,CAAE,CAAC,EAC/B,CAAC,EACH,CAAC,CAEV,CAAC,CAED,cAAe,CAAA5B,QAAQ","ignoreList":[]}
@@ -1,50 +1,2 @@
1
- import "core-js/modules/es.array.push.js";
2
- import { useTheme } from '@dr.pogodin/react-themes';
3
- import { optionValueName } from "../common";
4
- import defaultTheme from "./theme.scss";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- export const Switch = ({
7
- label,
8
- onChange,
9
- options,
10
- theme,
11
- value
12
- }) => {
13
- const composed = useTheme('Switch', defaultTheme, theme);
14
- if (!options || !composed.option) throw Error('Internal error');
15
- const optionNodes = [];
16
- for (const option of options) {
17
- const [iValue, iName] = optionValueName(option);
18
- let className = composed.option;
19
- let onPress;
20
- if (iValue === value) className += ` ${composed.selected}`;else if (onChange) {
21
- onPress = () => {
22
- onChange(iValue);
23
- };
24
- }
25
- optionNodes.push(onPress ? /*#__PURE__*/_jsx("div", {
26
- className: className,
27
- onClick: onPress,
28
- onKeyDown: e => {
29
- if (e.key === 'Enter') onPress();
30
- },
31
- role: "button",
32
- tabIndex: 0,
33
- children: iName
34
- }, iValue) : /*#__PURE__*/_jsx("div", {
35
- className: className,
36
- children: iName
37
- }, iValue));
38
- }
39
- return /*#__PURE__*/_jsxs("div", {
40
- className: composed.container,
41
- children: [label ? /*#__PURE__*/_jsx("div", {
42
- className: composed.label,
43
- children: label
44
- }) : null, /*#__PURE__*/_jsx("div", {
45
- className: composed.options,
46
- children: optionNodes
47
- })]
48
- });
49
- };
1
+ import"core-js/modules/es.array.push.js";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common";import defaultTheme from"./theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const Switch=({label,onChange,options,theme,value})=>{const composed=useTheme("Switch",defaultTheme,theme);if(!options||!composed.option)throw Error("Internal error");const optionNodes=[];for(const option of options){const[iValue,iName]=optionValueName(option);let className=composed.option;let onPress;if(iValue===value)className+=` ${composed.selected}`;else if(onChange){onPress=()=>{onChange(iValue);};}optionNodes.push(onPress?/*#__PURE__*/_jsx("div",{className:className,onClick:onPress,onKeyDown:e=>{if(e.key==="Enter")onPress();},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/_jsx("div",{className:className,children:iName},iValue));}return/*#__PURE__*/_jsxs("div",{className:composed.container,children:[label?/*#__PURE__*/_jsx("div",{className:composed.label,children:label}):null,/*#__PURE__*/_jsx("div",{className:composed.options,children:optionNodes})]});};
50
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useTheme","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","Switch","label","onChange","options","theme","value","composed","option","Error","optionNodes","iValue","iName","className","onPress","selected","push","onClick","onKeyDown","e","key","role","tabIndex","children","container"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":";AAEA,SAAqBA,QAAQ,QAAQ,0BAA0B;AAE/D,SAGEC,eAAe;AAGjB,OAAOC,YAAY;AAAqB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAYxC,OAAO,MAAMC,MAAiC,GAAGA,CAAC;EAChDC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,Q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AQ,CAACH,OAAQ;MAAAmB,QAAA,EAC9Bb;IAAW,CACT,CAAC;EAAA,CACH,CAAC;AAEV,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useTheme","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","Switch","label","onChange","options","theme","value","composed","option","Error","optionNodes","iValue","iName","className","onPress","selected","push","onClick","onKeyDown","e","key","role","tabIndex","children","container"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":"yCAEA,OAAqBA,QAAQ,KAAQ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AU,CAAAU,QAAA,CAAeX,KAAK,EAAdD,MAAoB,CAC1D,CAAC,CACH,CAEA,mBACEX,KAAA,QAAKa,SAAS,CAAEN,QAAQ,CAACiB,SAAU,CAAAD,QAAA,EAChCrB,KAAK,cAAGJ,IAAA,QAAKe,SAAS,CAAEN,QAAQ,CAACL,KAAM,CAAAqB,QAAA,CAAErB,KAAK,CAAM,CAAC,CAAG,IAAI,cAE7DJ,IAAA,QAAKe,SAAS,CAAEN,QAAQ,CAACH,OAAQ,CAAAmB,QAAA,CAC9Bb,WAAW,CACT,CAAC,EACH,CAAC,CAEV,CAAC","ignoreList":[]}
@@ -1,12 +1,3 @@
1
1
  // The stuff common between different dropdown implementations.
2
-
3
- function isValue(x) {
4
- const type = typeof x;
5
- return type === 'number' || type === 'string';
6
- }
7
-
8
- /** Returns option value and name as a tuple. */
9
- export function optionValueName(option) {
10
- return isValue(option) ? [option, option] : [option.value, option.name ?? option.value];
11
- }
2
+ function isValue(x){const type=typeof x;return type==="number"||type==="string";}/** Returns option value and name as a tuple. */export function optionValueName(option){return isValue(option)?[option,option]:[option.value,option.name??option.value];}
12
3
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","names":["isValue","x","type","optionValueName","option","value","name"],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\nexport type ThemeT = Theme<\n | 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is currently only valid for (native) <Dropdown>,\n // other kinds of selectors should be evaluated, and aligned with this\n // feature, if appropriate.\n | 'invalid'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward'\n>;\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: React.ReactNode;\n onChange?: OnChangeT;\n options: Readonly<OptionsT<NameT>>;\n testId?: string;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":"AAAA;;AA8CA,SAASA,OAAOA,CAAIC,CAAsB,EAAe;EACvD,MAAMC,IAAI,GAAG,OAAOD,CAAC;EACrB,OAAOC,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,QAAQ;AAC/C;;AAEA;AACA,OAAO,SAASC,eAAeA,CAC7BC,MAA+B,EACL;EAC1B,OAAOJ,OAAO,CAACI,MAAM,CAAC,GAClB,CAACA,MAAM,EAAEA,MAAM,CAAC,GAChB,CAACA,MAAM,CAACC,KAAK,EAAED,MAAM,CAACE,IAAI,IAAIF,MAAM,CAACC,KAAK,CAAC;AACjD","ignoreList":[]}
1
+ {"version":3,"file":"common.js","names":["isValue","x","type","optionValueName","option","value","name"],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\nexport type ThemeT = Theme<\n | 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is currently only valid for (native) <Dropdown>,\n // other kinds of selectors should be evaluated, and aligned with this\n // feature, if appropriate.\n | 'invalid'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward'\n>;\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: React.ReactNode;\n onChange?: OnChangeT;\n options: Readonly<OptionsT<NameT>>;\n testId?: string;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":"AAAA;AA8CA,QAAS,CAAAA,OAAOA,CAAIC,CAAsB,CAAe,CACvD,KAAM,CAAAC,IAAI,CAAG,MAAO,CAAAD,CAAC,CACrB,MAAO,CAAAC,IAAI,GAAK,QAAQ,EAAIA,IAAI,GAAK,QAAQ,CAC/C,CAEA,gDACA,MAAO,SAAS,CAAAC,eAAeA,CAC7BC,MAA+B,CACL,CAC1B,MAAO,CAAAJ,OAAO,CAACI,MAAM,CAAC,CAClB,CAACA,MAAM,CAAEA,MAAM,CAAC,CAChB,CAACA,MAAM,CAACC,KAAK,CAAED,MAAM,CAACE,IAAI,EAAIF,MAAM,CAACC,KAAK,CAAC,CACjD","ignoreList":[]}
@@ -1,4 +1,2 @@
1
- export { default as CustomDropdown } from "./CustomDropdown";
2
- export { default as Dropdown } from "./NativeDropdown";
3
- export { Switch } from "./Switch";
1
+ export{default as CustomDropdown}from"./CustomDropdown";export{default as Dropdown}from"./NativeDropdown";export{Switch}from"./Switch";
4
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default","CustomDropdown","Dropdown","Switch"],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { Switch } from './Switch';\n\nexport type { OptionT, OptionsT } from './common';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAClC,SAASD,OAAO,IAAIE,QAAQ;AAC5B,SAASC,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["default","CustomDropdown","Dropdown","Switch"],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { Switch } from './Switch';\n\nexport type { OptionT, OptionsT } from './common';\n"],"mappings":"AAAA,OAASA,OAAO,GAAI,CAAAC,cAAc,wBAClC,OAASD,OAAO,GAAI,CAAAE,QAAQ,wBAC5B,OAASC,MAAM","ignoreList":[]}