@dr.pogodin/react-utils 1.35.3 → 1.36.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 (185) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin/build.js +7 -6
  3. package/build/development/client/getInj.js +3 -10
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +2 -9
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/index.js +1 -15
  8. package/build/development/index.js.map +1 -1
  9. package/build/development/server/Cache.js +19 -19
  10. package/build/development/server/Cache.js.map +1 -1
  11. package/build/development/server/renderer.js +7 -4
  12. package/build/development/server/renderer.js.map +1 -1
  13. package/build/development/server/server.js +4 -1
  14. package/build/development/server/server.js.map +1 -1
  15. package/build/development/shared/components/Button/index.js +1 -16
  16. package/build/development/shared/components/Button/index.js.map +1 -1
  17. package/build/development/shared/components/Checkbox/index.js +1 -29
  18. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  19. package/build/development/shared/components/GenericLink/index.js +0 -15
  20. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  21. package/build/development/shared/components/Input/index.js +1 -8
  22. package/build/development/shared/components/Input/index.js.map +1 -1
  23. package/build/development/shared/components/MetaTags.js +0 -12
  24. package/build/development/shared/components/MetaTags.js.map +1 -1
  25. package/build/development/shared/components/Modal/index.js +2 -13
  26. package/build/development/shared/components/Modal/index.js.map +1 -1
  27. package/build/development/shared/components/PageLayout/index.js +1 -10
  28. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  29. package/build/development/shared/components/TextArea/index.js +1 -12
  30. package/build/development/shared/components/TextArea/index.js.map +1 -1
  31. package/build/development/shared/components/Throbber/index.js +1 -6
  32. package/build/development/shared/components/Throbber/index.js.map +1 -1
  33. package/build/development/shared/components/WithTooltip/Tooltip.js +1 -8
  34. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  35. package/build/development/shared/components/WithTooltip/index.js +1 -9
  36. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  37. package/build/development/shared/components/YouTubeVideo/index.js +2 -11
  38. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  39. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +1 -16
  40. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  41. package/build/development/shared/components/selectors/CustomDropdown/index.js +2 -12
  42. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  43. package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -12
  44. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  45. package/build/development/shared/components/selectors/Switch/index.js +21 -28
  46. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  47. package/build/development/shared/components/selectors/common.js +0 -19
  48. package/build/development/shared/components/selectors/common.js.map +1 -1
  49. package/build/development/shared/components/selectors/index.js +0 -13
  50. package/build/development/shared/components/selectors/index.js.map +1 -1
  51. package/build/development/shared/utils/globalState.js.map +1 -1
  52. package/build/development/shared/utils/jest/index.js +4 -2
  53. package/build/development/shared/utils/jest/index.js.map +1 -1
  54. package/build/development/shared/utils/splitComponent.js +21 -28
  55. package/build/development/shared/utils/splitComponent.js.map +1 -1
  56. package/build/development/web.bundle.js +28 -38
  57. package/build/production/client/getInj.js +3 -7
  58. package/build/production/client/getInj.js.map +1 -1
  59. package/build/production/client/index.js +1 -1
  60. package/build/production/client/index.js.map +1 -1
  61. package/build/production/index.js +1 -4
  62. package/build/production/index.js.map +1 -1
  63. package/build/production/server/Cache.js +3 -3
  64. package/build/production/server/Cache.js.map +1 -1
  65. package/build/production/server/renderer.js +2 -2
  66. package/build/production/server/renderer.js.map +1 -1
  67. package/build/production/server/server.js +1 -1
  68. package/build/production/server/server.js.map +1 -1
  69. package/build/production/shared/components/Button/index.js +3 -3
  70. package/build/production/shared/components/Button/index.js.map +1 -1
  71. package/build/production/shared/components/Checkbox/index.js +1 -16
  72. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  73. package/build/production/shared/components/GenericLink/index.js +2 -2
  74. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  75. package/build/production/shared/components/Input/index.js +2 -2
  76. package/build/production/shared/components/Input/index.js.map +1 -1
  77. package/build/production/shared/components/MetaTags.js +2 -2
  78. package/build/production/shared/components/MetaTags.js.map +1 -1
  79. package/build/production/shared/components/Modal/index.js +2 -2
  80. package/build/production/shared/components/Modal/index.js.map +1 -1
  81. package/build/production/shared/components/PageLayout/index.js +2 -2
  82. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  83. package/build/production/shared/components/TextArea/index.js +2 -2
  84. package/build/production/shared/components/TextArea/index.js.map +1 -1
  85. package/build/production/shared/components/Throbber/index.js +2 -2
  86. package/build/production/shared/components/Throbber/index.js.map +1 -1
  87. package/build/production/shared/components/WithTooltip/Tooltip.js +3 -3
  88. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  89. package/build/production/shared/components/WithTooltip/index.js +2 -2
  90. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  91. package/build/production/shared/components/YouTubeVideo/index.js +3 -3
  92. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  93. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  94. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  95. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  96. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  97. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  98. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  99. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  100. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  101. package/build/production/shared/components/selectors/common.js +2 -4
  102. package/build/production/shared/components/selectors/common.js.map +1 -1
  103. package/build/production/shared/components/selectors/index.js +1 -1
  104. package/build/production/shared/components/selectors/index.js.map +1 -1
  105. package/build/production/shared/utils/globalState.js.map +1 -1
  106. package/build/production/shared/utils/jest/index.js +1 -1
  107. package/build/production/shared/utils/jest/index.js.map +1 -1
  108. package/build/production/shared/utils/splitComponent.js +10 -12
  109. package/build/production/shared/utils/splitComponent.js.map +1 -1
  110. package/build/production/web.bundle.js +1 -1
  111. package/build/production/web.bundle.js.map +1 -1
  112. package/build/types-code/client/getInj.d.ts +0 -6
  113. package/build/types-code/client/index.d.ts +1 -2
  114. package/build/types-code/index.d.ts +2 -3
  115. package/build/types-code/server/Cache.d.ts +3 -11
  116. package/build/types-code/server/index.d.ts +0 -2
  117. package/build/types-code/server/renderer.d.ts +0 -1
  118. package/build/types-code/server/server.d.ts +0 -1
  119. package/build/types-code/shared/components/Button/index.d.ts +3 -4
  120. package/build/types-code/shared/components/Checkbox/index.d.ts +3 -12
  121. package/build/types-code/shared/components/Input/index.d.ts +4 -5
  122. package/build/types-code/shared/components/Link.d.ts +0 -1
  123. package/build/types-code/shared/components/Modal/index.d.ts +3 -4
  124. package/build/types-code/shared/components/NavLink.d.ts +0 -1
  125. package/build/types-code/shared/components/PageLayout/index.d.ts +4 -4
  126. package/build/types-code/shared/components/TextArea/index.d.ts +4 -5
  127. package/build/types-code/shared/components/Throbber/index.d.ts +4 -4
  128. package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +1 -1
  129. package/build/types-code/shared/components/WithTooltip/index.d.ts +2 -3
  130. package/build/types-code/shared/components/YouTubeVideo/index.d.ts +3 -4
  131. package/build/types-code/shared/components/selectors/CustomDropdown/Options/index.d.ts +1 -2
  132. package/build/types-code/shared/components/selectors/CustomDropdown/index.d.ts +2 -3
  133. package/build/types-code/shared/components/selectors/NativeDropdown/index.d.ts +2 -2
  134. package/build/types-code/shared/components/selectors/Switch/index.d.ts +4 -5
  135. package/build/types-code/shared/components/selectors/common.d.ts +5 -11
  136. package/build/types-code/shared/components/selectors/index.d.ts +1 -1
  137. package/build/types-code/shared/utils/globalState.d.ts +6 -2
  138. package/build/types-code/shared/utils/jest/index.d.ts +4 -1
  139. package/build/types-code/shared/utils/splitComponent.d.ts +0 -1
  140. package/build/types-code/shared/utils/webpack.d.ts +0 -1
  141. package/config/babel/node-ssr.js +1 -1
  142. package/config/babel/webpack.js +1 -1
  143. package/config/eslint/default.json +1 -0
  144. package/config/eslint/jest.json +1 -0
  145. package/config/eslint/typescript.js +7 -0
  146. package/config/typescript/base.json +9 -0
  147. package/config/webpack/app-base.d.ts +0 -1
  148. package/config/webpack/app-base.js +1 -1
  149. package/config/webpack/app-development.js +1 -1
  150. package/config/webpack/app-production.js +1 -1
  151. package/config/webpack/lib-base.js +1 -2
  152. package/config/webpack/lib-development.js +1 -1
  153. package/config/webpack/lib-production.js +1 -1
  154. package/package.json +28 -27
  155. package/src/client/getInj.ts +3 -9
  156. package/src/client/index.tsx +1 -3
  157. package/src/index.ts +1 -10
  158. package/src/server/Cache.ts +31 -30
  159. package/src/server/renderer.tsx +8 -5
  160. package/src/server/server.ts +6 -1
  161. package/src/shared/components/Button/index.tsx +2 -20
  162. package/src/shared/components/Checkbox/index.tsx +2 -37
  163. package/src/shared/components/GenericLink/index.tsx +0 -15
  164. package/src/shared/components/Input/index.tsx +6 -15
  165. package/src/shared/components/MetaTags.tsx +0 -12
  166. package/src/shared/components/Modal/index.tsx +3 -22
  167. package/src/shared/components/PageLayout/index.tsx +8 -24
  168. package/src/shared/components/TextArea/index.tsx +6 -24
  169. package/src/shared/components/Throbber/index.tsx +6 -18
  170. package/src/shared/components/WithTooltip/Tooltip.tsx +6 -14
  171. package/src/shared/components/WithTooltip/index.tsx +3 -24
  172. package/src/shared/components/YouTubeVideo/index.tsx +3 -20
  173. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +2 -20
  174. package/src/shared/components/selectors/CustomDropdown/index.tsx +3 -27
  175. package/src/shared/components/selectors/NativeDropdown/index.tsx +3 -27
  176. package/src/shared/components/selectors/Switch/index.tsx +34 -50
  177. package/src/shared/components/selectors/common.ts +13 -45
  178. package/src/shared/components/selectors/index.ts +0 -2
  179. package/src/shared/utils/globalState.ts +6 -0
  180. package/src/shared/utils/jest/index.tsx +13 -2
  181. package/src/shared/utils/splitComponent.tsx +24 -29
  182. package/tsconfig.configs.json +7 -3
  183. package/tsconfig.json +3 -10
  184. package/tsconfig.types.json +1 -7
  185. package/tstyche.config.json +6 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","require","_propTypes","_interopRequireDefault","_reactThemes","_jsxRuntime","defaultTheme","validThemeKeys","TextArea","disabled","onChange","onKeyDown","placeholder","theme","value","hiddenAreaRef","useRef","height","setHeight","useState","localValue","setLocalValue","undefined","useEffect","el","current","cb","scrollHeight","observer","ResizeObserver","observe","disconnect","jsxs","className","container","children","jsx","readOnly","ref","textarea","hidden","e","target","style","ThemedTextArea","themed","propTypes","PT","bool","func","string","themeType","isRequired","_default","exports","default"],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport PT from 'prop-types';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\nconst validThemeKeys = [\n 'container',\n 'hidden',\n 'textarea',\n] as const;\n\ntype Props = {\n disabled?: boolean;\n onChange?: React.ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n theme: Theme<typeof validThemeKeys>;\n value?: string;\n};\n\nconst TextArea: React.FunctionComponent<Props> = ({\n disabled,\n onChange,\n onKeyDown,\n placeholder,\n theme,\n value,\n}) => {\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const [localValue, setLocalValue] = useState(value || '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // This resizes the text area when its content is modified.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n return (\n <div className={theme.container}>\n <textarea\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n className={`${theme.textarea} ${theme.hidden}`}\n value={localValue}\n />\n <textarea\n disabled={disabled}\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={value === undefined ? ((e) => {\n setLocalValue(e.target.value);\n }) : onChange}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n style={{ height }}\n className={theme.textarea}\n value={localValue}\n />\n </div>\n );\n};\n\nconst ThemedTextArea = themed(\n TextArea,\n 'TextArea',\n validThemeKeys,\n defaultTheme,\n);\n\nTextArea.propTypes = {\n disabled: PT.bool,\n onChange: PT.func,\n onKeyDown: PT.func,\n placeholder: PT.string,\n theme: ThemedTextArea.themeType.isRequired,\n value: PT.string,\n};\n\nexport default ThemedTextArea;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAD,sBAAA,CAAAF,OAAA;AAA8D,IAAAI,WAAA,GAAAJ,OAAA;AAAA,MAAAK,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAI9D,MAAMC,cAAc,GAAG,CACrB,WAAW,EACX,QAAQ,EACR,UAAU,CACF;AAWV,MAAMC,QAAwC,GAAGA,CAAC;EAChDC,QAAQ;EACRC,QAAQ;EACRC,SAAS;EACTC,WAAW;EACXC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,aAAa,GAAG,IAAAC,aAAM,EAAsB,IAAI,CAAC;EACvD,MAAM,CAACC,MAAM,EAAEC,SAAS,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AAEI,KAAK,KAAKQ,SAAS,GAAKmB,CAAC,IAAK;QACtCpB,aAAa,CAACoB,CAAC,CAACC,MAAM,CAAC5B,KAAK,CAAC;MAC/B,CAAC,GAAIJ,QAAS;MACdC,SAAS,EAAEA,SAAU;MACrBC,WAAW,EAAEA,WAAY;MACzB+B,KAAK,EAAE;QAAE1B;MAAO,CAAE;MAClBgB,SAAS,EAAEpB,KAAK,CAAC0B,QAAS;MAC1BzB,KAAK,EAAEM;IAAW,CACnB,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAED,MAAMwB,cAAc,GAAG,IAAAC,oBAAM,EAC3BrC,QAAQ,EACR,UAAU,EACVD,cAAc,EACdD,YACF,CAAC;AAEDE,QAAQ,CAACsC,SAAS,GAAG;EACnBrC,QAAQ,EAAEsC,kBAAE,CAACC,IAAI;EACjBtC,QAAQ,EAAEqC,kBAAE,CAACE,IAAI;EACjBtC,SAAS,EAAEoC,kBAAE,CAACE,IAAI;EAClBrC,WAAW,EAAEmC,kBAAE,CAACG,MAAM;EACtBrC,KAAK,EAAE+B,cAAc,CAACO,SAAS,CAACC,UAAU;EAC1CtC,KAAK,EAAEiC,kBAAE,CAACG;AACZ,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaX,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","require","_reactThemes","_interopRequireDefault","_jsxRuntime","defaultTheme","TextArea","disabled","onChange","onKeyDown","placeholder","theme","value","hiddenAreaRef","useRef","height","setHeight","useState","localValue","setLocalValue","undefined","useEffect","el","current","cb","scrollHeight","observer","ResizeObserver","observe","disconnect","jsxs","className","container","children","jsx","readOnly","ref","textarea","hidden","e","target","style","_default","exports","default","themed"],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT =\n | 'container'\n | 'hidden'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n onChange?: React.ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n theme: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: React.FunctionComponent<Props> = ({\n disabled,\n onChange,\n onKeyDown,\n placeholder,\n theme,\n value,\n}) => {\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const [localValue, setLocalValue] = useState(value || '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // This resizes the text area when its content is modified.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n return (\n <div className={theme.container}>\n <textarea\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n className={`${theme.textarea} ${theme.hidden}`}\n value={localValue}\n />\n <textarea\n disabled={disabled}\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={value === undefined ? ((e) => {\n setLocalValue(e.target.value);\n }) : onChange}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n style={{ height }}\n className={theme.textarea}\n value={localValue}\n />\n </div>\n );\n};\n\nexport default themed(TextArea, 'TextArea', defaultTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8D,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,YAAA;EAAA;EAAA;EA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Q;MACRC,GAAG,EAAEvB,aAAc;MACnBkB,SAAS,EAAE,GAAGpB,KAAK,CAAC0B,QAAQ,IAAI1B,KAAK,CAAC2B,MAAM,EAAG;MAC/C1B,KAAK,EAAEM;IAAW,CACnB,CAAC,eACF,IAAAd,WAAA,CAAA8B,GAAA;MACE3B,QAAQ,EAAEA;MACV;MACA;MACA;MAAA;MACAC,QAAQ,EAAEI,KAAK,KAAKQ,SAAS,GAAKmB,CAAC,IAAK;QACtCpB,aAAa,CAACoB,CAAC,CAACC,MAAM,CAAC5B,KAAK,CAAC;MAC/B,CAAC,GAAIJ,QAAS;MACdC,SAAS,EAAEA,SAAU;MACrBC,WAAW,EAAEA,WAAY;MACzB+B,KAAK,EAAE;QAAE1B;MAAO,CAAE;MAClBgB,SAAS,EAAEpB,KAAK,CAAC0B,QAAS;MAC1BzB,KAAK,EAAEM;IAAW,CACnB,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAAC,IAAAwB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,oBAAM,EAACvC,QAAQ,EAAE,UAAU,EAAED,YAAY,CAAC","ignoreList":[]}
@@ -15,7 +15,6 @@ const defaultTheme = {
15
15
  "container": "-dr-pogodin-react-utils___src-shared-components-Throbber-theme___container___7zdld4",
16
16
  "circle": "-dr-pogodin-react-utils___src-shared-components-Throbber-theme___circle___dBrB4g"
17
17
  };
18
- const validThemeKeys = ['bouncing', 'circle', 'container'];
19
18
  /**
20
19
  * Throbber is an "action in progress" indicator, which renders
21
20
  * three bouncing circles as a simple pending activity indicator,
@@ -37,9 +36,5 @@ const Throbber = ({
37
36
  className: theme.circle
38
37
  })]
39
38
  });
40
- const ThemedThrobber = (0, _reactThemes.default)(Throbber, 'Throbber', validThemeKeys, defaultTheme);
41
- Throbber.propTypes = {
42
- theme: ThemedThrobber.themeType.isRequired
43
- };
44
- var _default = exports.default = ThemedThrobber;
39
+ var _default = exports.default = (0, _reactThemes.default)(Throbber, 'Throbber', defaultTheme);
45
40
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_reactThemes","_interopRequireDefault","require","_jsxRuntime","defaultTheme","validThemeKeys","Throbber","theme","jsxs","className","container","children","jsx","circle","ThemedThrobber","themed","propTypes","themeType","isRequired","_default","exports","default"],"sources":["../../../../../src/shared/components/Throbber/index.tsx"],"sourcesContent":["import themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\nconst validThemeKeys = [\n 'bouncing',\n 'circle',\n 'container',\n] as const;\n\ntype PropsT = {\n theme: Theme<typeof validThemeKeys>;\n};\n\n/**\n * Throbber is an \"action in progress\" indicator, which renders\n * three bouncing circles as a simple pending activity indicator,\n * and can be further themed to a certain degree.\n * @param {object} [props] Component properties.\n * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Throbber: React.FunctionComponent<PropsT> = ({ theme }) => (\n <span className={theme.container}>\n <span className={theme.circle} />\n <span className={theme.circle} />\n <span className={theme.circle} />\n </span>\n);\n\nconst ThemedThrobber = themed(\n Throbber,\n 'Throbber',\n validThemeKeys,\n defaultTheme,\n);\n\nThrobber.propTypes = {\n theme: ThemedThrobber.themeType.isRequired,\n};\n\nexport default ThemedThrobber;\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8D,IAAAC,WAAA,GAAAD,OAAA;AAAA,MAAAE,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAI9D,MAAMC,cAAc,GAAG,CACrB,UAAU,EACV,QAAQ,EACR,WAAW,CACH;AAMV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAyC,GAAGA,CAAC;EAAEC;AAAM,CAAC,kBAC1D,IAAAJ,WAAA,CAAAK,IAAA;EAAMC,SAAS,EAAEF,KAAK,CAACG,SAAU;EAAAC,QAAA,gBAC/B,IAAAR,WAAA,CAAAS,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC,eACjC,IAAAV,WAAA,CAAAS,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC,eACjC,IAAAV,WAAA,CAAAS,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC;AAAA,CAC7B,CACP;AAED,MAAMC,cAAc,GAAG,IAAAC,oBAAM,EAC3BT,QAAQ,EACR,UAAU,EACVD,cAAc,EACdD,YACF,CAAC;AAEDE,QAAQ,CAACU,SAAS,GAAG;EACnBT,KAAK,EAAEO,cAAc,CAACG,SAAS,CAACC;AAClC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaP,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_reactThemes","_interopRequireDefault","require","_jsxRuntime","defaultTheme","Throbber","theme","jsxs","className","container","children","jsx","circle","_default","exports","default","themed"],"sources":["../../../../../src/shared/components/Throbber/index.tsx"],"sourcesContent":["import themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT =\n | 'bouncing'\n | 'circle'\n | 'container';\n\ntype PropsT = {\n theme: Theme<ThemeKeyT>;\n};\n\n/**\n * Throbber is an \"action in progress\" indicator, which renders\n * three bouncing circles as a simple pending activity indicator,\n * and can be further themed to a certain degree.\n * @param {object} [props] Component properties.\n * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Throbber: React.FunctionComponent<PropsT> = ({ theme }) => (\n <span className={theme.container}>\n <span className={theme.circle} />\n <span className={theme.circle} />\n <span className={theme.circle} />\n </span>\n);\n\nexport default themed(Throbber, 'Throbber', defaultTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8D,IAAAC,WAAA,GAAAD,OAAA;AAAA,MAAAE,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAa9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAyC,GAAGA,CAAC;EAAEC;AAAM,CAAC,kBAC1D,IAAAH,WAAA,CAAAI,IAAA;EAAMC,SAAS,EAAEF,KAAK,CAACG,SAAU;EAAAC,QAAA,gBAC/B,IAAAP,WAAA,CAAAQ,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC,eACjC,IAAAT,WAAA,CAAAQ,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC,eACjC,IAAAT,WAAA,CAAAQ,GAAA;IAAMH,SAAS,EAAEF,KAAK,CAACM;EAAO,CAAE,CAAC;AAAA,CAC7B,CACP;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,oBAAM,EAACX,QAAQ,EAAE,UAAU,EAAED,YAAY,CAAC","ignoreList":[]}
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.validThemeKeys = exports.default = exports.PLACEMENTS = void 0;
6
+ exports.default = exports.PLACEMENTS = void 0;
8
7
  var _react = require("react");
9
8
  var _reactDom = require("react-dom");
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
9
  /**
12
10
  * The actual tooltip component. It is rendered outside the regular document
13
11
  * hierarchy, and with sub-components managed without React to achieve the best
@@ -25,7 +23,6 @@ let PLACEMENTS = exports.PLACEMENTS = /*#__PURE__*/function (PLACEMENTS) {
25
23
  }({});
26
24
  const ARROW_STYLE_DOWN = ['border-bottom-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
27
25
  const ARROW_STYLE_UP = ['border-top-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
28
- const validThemeKeys = exports.validThemeKeys = ['appearance', 'arrow', 'content', 'container'];
29
26
  /**
30
27
  * Creates tooltip components.
31
28
  * @ignore
@@ -273,9 +270,5 @@ const Tooltip = /*#__PURE__*/(0, _react.forwardRef)(({
273
270
  heap.lastPageX, heap.lastPageY, heap.lastPlacement, heap.lastElement]);
274
271
  return components ? /*#__PURE__*/(0, _reactDom.createPortal)(children, components.content) : null;
275
272
  });
276
- Tooltip.propTypes = {
277
- children: _propTypes.default.node,
278
- theme: _propTypes.default.shape({}).isRequired
279
- };
280
273
  var _default = exports.default = Tooltip;
281
274
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","names":["_react","require","_reactDom","_propTypes","_interopRequireDefault","PLACEMENTS","exports","ARROW_STYLE_DOWN","join","ARROW_STYLE_UP","validThemeKeys","createTooltipComponents","theme","arrow","document","createElement","setAttribute","content","container","appendChild","body","calcTooltipRects","tooltip","getBoundingClientRect","calcViewportRect","scrollX","scrollY","window","documentElement","clientHeight","clientWidth","left","right","top","bottom","calcPositionAboveXY","x","y","tooltipRects","arrowX","width","arrowY","height","containerX","containerY","baseArrowStyle","setComponentPositions","pageX","pageY","placement","element","viewportRect","pos","Math","max","maxX","min","containerStyle","arrowStyle","Tooltip","forwardRef","children","ref","current","heap","useRef","lastElement","undefined","lastPageX","lastPageY","lastPlacement","components","setComponents","useState","pointTo","useImperativeHandle","useEffect","removeChild","createPortal","propTypes","PT","node","shape","isRequired","_default","default"],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n/* global document, window */\n\nimport {\n type ReactNode,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport PT from 'prop-types';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/* Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport. */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n container: HTMLDivElement;\n arrow: HTMLDivElement;\n content: HTMLDivElement;\n};\n\ntype HeapT = {\n lastElement?: HTMLElement;\n lastPageX: number;\n lastPageY: number;\n lastPlacement?: PLACEMENTS | undefined;\n};\n\nexport const validThemeKeys = [\n 'appearance',\n 'arrow',\n 'content',\n 'container',\n] as const;\n\ntype TooltipThemeT = Theme<typeof validThemeKeys>;\n\n/**\n * Creates tooltip components.\n * @ignore\n * @param {object} theme Themes to use for tooltip container, arrow,\n * and content.\n * @return {object} Object with DOM references to the container components:\n * container, arrow, content.\n */\nfunction createTooltipComponents(theme: TooltipThemeT): ComponentsT {\n const arrow = document.createElement('div');\n if (theme.arrow) arrow.setAttribute('class', theme.arrow);\n\n const content = document.createElement('div');\n if (theme.content) content.setAttribute('class', theme.content);\n\n const container = document.createElement('div');\n if (theme.container) container.setAttribute('class', theme.container);\n\n container.appendChild(arrow);\n container.appendChild(content);\n document.body.appendChild(container);\n\n return { container, arrow, content };\n}\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n bottom: scrollY + clientHeight,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n/*\nconst HIT = {\n NONE: false,\n LEFT: 'LEFT',\n RIGHT: 'RIGHT',\n TOP: 'TOP',\n BOTTOM: 'BOTTOM',\n};\n*/\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n/*\nfunction checkViewportFit(pos, tooltipRects, viewportRect) {\n const { containerX, containerY } = pos;\n if (containerX < viewportRect.left + 6) return HIT.LEFT;\n if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n return HIT.NONE;\n}\n*/\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n/*\nfunction xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n if (pos.containerX < pageXOffset + 6) {\n pos.containerX = pageXOffset + 6;\n pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n } else {\n const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n if (containerX > maxX) {\n containerX = maxX;\n arrowX = Math.min(\n containerRect.width - 6,\n pageX - containerX - arrowRect.width / 2,\n );\n }\n }\n}\n*/\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip = forwardRef<unknown, {\n children?: ReactNode;\n theme: any;\n}>(({ children, theme }, ref) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const { current: heap } = useRef<HeapT>({\n lastElement: undefined,\n lastPageX: 0,\n lastPageY: 0,\n lastPlacement: undefined,\n });\n\n const [components, setComponents] = useState<ComponentsT | null>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n heap.lastElement = element;\n heap.lastPageX = pageX;\n heap.lastPageY = pageY;\n heap.lastPlacement = placement;\n\n if (components) {\n setComponentPositions(pageX, pageY, placement, element, components);\n }\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n /* Inits and destroys tooltip components. */\n useEffect(() => {\n const x = createTooltipComponents(theme);\n setComponents(x);\n return () => {\n document.body.removeChild(x.container);\n setComponents(null);\n };\n }, [theme]);\n\n useEffect(() => {\n if (components) {\n setComponentPositions(\n heap.lastPageX,\n heap.lastPageY,\n heap.lastPlacement,\n heap.lastElement,\n components,\n );\n }\n }, [\n components,\n // BEWARE: Careful about these dependencies - they are updated when mouse\n // is moved over the tool-tipped element, thus potentially may cause\n // unnecessary firing of this effect on each mouse event. It does not\n // happen now just because the mouse movements themselves are not causing\n // the component re-rendering, thus dependencies of this effect are not\n // really re-evaluated.\n heap.lastPageX,\n heap.lastPageY,\n heap.lastPlacement,\n heap.lastElement,\n ]);\n\n return components ? createPortal(children, components.content) : null;\n});\n\nTooltip.propTypes = {\n children: PT.node,\n theme: PT.shape({}).isRequired,\n};\n\nexport default Tooltip;\n"],"mappings":";;;;;;;AAOA,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AAlBA;AACA;AACA;AACA;AACA;AACA;AAiBA;AACA;AADA,IAEYI,UAAU,GAAAC,OAAA,CAAAD,UAAA,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAOtB,MAAME,gBAAgB,GAAG,CACvB,iCAAiC,EACjC,+BAA+B,EAC/B,gCAAgC,CACjC,CAACC,IAAI,CAAC,GAAG,CAAC;AAEX,MAAMC,cAAc,GAAG,CACrB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,CACjC,CAACD,IAAI,CAAC,GAAG,CAAC;AAeJ,MAAME,cAAc,GAAAJ,OAAA,CAAAI,cAAA,GAAG,CAC5B,YAAY,EACZ,OAAO,EACP,SAAS,EACT,WAAW,CACH;AAIV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAuBA,CAACC,KAAoB,EAAe;EAClE,MAAMC,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC3C,IAAIH,KAAK,CAACC,KAAK,EAAEA,KAAK,CAACG,YAAY,CAAC,OAAO,EAAEJ,KAAK,CAACC,KAAK,CAAC;EAEzD,MAAMI,OAAO,GAAGH,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC7C,IAAIH,KAAK,CAACK,OAAO,EAAEA,OAAO,CAACD,YAAY,CAAC,OAAO,EAAEJ,KAAK,CAACK,OAAO,CAAC;EAE/D,MAAMC,SAAS,GAAGJ,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC/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I,SAAS,EACdJ,IAAI,CAACK,SAAS,EACdL,IAAI,CAACM,aAAa,EAClBN,IAAI,CAACE,WAAW,CACjB,CAAC;EAEF,OAAOK,UAAU,gBAAG,IAAAO,sBAAY,EAACjB,QAAQ,EAAEU,UAAU,CAACtD,OAAO,CAAC,GAAG,IAAI;AACvE,CAAC,CAAC;AAEF0C,OAAO,CAACoB,SAAS,GAAG;EAClBlB,QAAQ,EAAEmB,kBAAE,CAACC,IAAI;EACjBrE,KAAK,EAAEoE,kBAAE,CAACE,KAAK,CAAC,CAAC,CAAC,CAAC,CAACC;AACtB,CAAC;AAAC,IAAAC,QAAA,GAAA9E,OAAA,CAAA+E,OAAA,GAEa1B,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"Tooltip.js","names":["_react","require","_reactDom","PLACEMENTS","exports","ARROW_STYLE_DOWN","join","ARROW_STYLE_UP","createTooltipComponents","theme","arrow","document","createElement","setAttribute","content","container","appendChild","body","calcTooltipRects","tooltip","getBoundingClientRect","calcViewportRect","scrollX","scrollY","window","documentElement","clientHeight","clientWidth","left","right","top","bottom","calcPositionAboveXY","x","y","tooltipRects","arrowX","width","arrowY","height","containerX","containerY","baseArrowStyle","setComponentPositions","pageX","pageY","placement","element","viewportRect","pos","Math","max","maxX","min","containerStyle","arrowStyle","Tooltip","forwardRef","children","ref","current","heap","useRef","lastElement","undefined","lastPageX","lastPageY","lastPlacement","components","setComponents","useState","pointTo","useImperativeHandle","useEffect","removeChild","createPortal","_default","default"],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n/* global document, window */\n\nimport {\n type ReactNode,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/* Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport. */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n container: HTMLDivElement;\n arrow: HTMLDivElement;\n content: HTMLDivElement;\n};\n\ntype HeapT = {\n lastElement?: HTMLElement;\n lastPageX: number;\n lastPageY: number;\n lastPlacement?: PLACEMENTS | undefined;\n};\n\nexport type ThemeKeysT =\n | 'appearance'\n | 'arrow'\n | 'content'\n | 'container';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\n/**\n * Creates tooltip components.\n * @ignore\n * @param {object} theme Themes to use for tooltip container, arrow,\n * and content.\n * @return {object} Object with DOM references to the container components:\n * container, arrow, content.\n */\nfunction createTooltipComponents(theme: TooltipThemeT): ComponentsT {\n const arrow = document.createElement('div');\n if (theme.arrow) arrow.setAttribute('class', theme.arrow);\n\n const content = document.createElement('div');\n if (theme.content) content.setAttribute('class', theme.content);\n\n const container = document.createElement('div');\n if (theme.container) container.setAttribute('class', theme.container);\n\n container.appendChild(arrow);\n container.appendChild(content);\n document.body.appendChild(container);\n\n return { container, arrow, content };\n}\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n bottom: scrollY + clientHeight,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n/*\nconst HIT = {\n NONE: false,\n LEFT: 'LEFT',\n RIGHT: 'RIGHT',\n TOP: 'TOP',\n BOTTOM: 'BOTTOM',\n};\n*/\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n/*\nfunction checkViewportFit(pos, tooltipRects, viewportRect) {\n const { containerX, containerY } = pos;\n if (containerX < viewportRect.left + 6) return HIT.LEFT;\n if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n return HIT.NONE;\n}\n*/\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n/*\nfunction xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n if (pos.containerX < pageXOffset + 6) {\n pos.containerX = pageXOffset + 6;\n pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n } else {\n const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n if (containerX > maxX) {\n containerX = maxX;\n arrowX = Math.min(\n containerRect.width - 6,\n pageX - containerX - arrowRect.width / 2,\n );\n }\n }\n}\n*/\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip = forwardRef<unknown, {\n children?: ReactNode;\n theme: any;\n}>(({ children, theme }, ref) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const { current: heap } = useRef<HeapT>({\n lastElement: undefined,\n lastPageX: 0,\n lastPageY: 0,\n lastPlacement: undefined,\n });\n\n const [components, setComponents] = useState<ComponentsT | null>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n heap.lastElement = element;\n heap.lastPageX = pageX;\n heap.lastPageY = pageY;\n heap.lastPlacement = placement;\n\n if (components) {\n setComponentPositions(pageX, pageY, placement, element, components);\n }\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n /* Inits and destroys tooltip components. */\n useEffect(() => {\n const x = createTooltipComponents(theme);\n setComponents(x);\n return () => {\n document.body.removeChild(x.container);\n setComponents(null);\n };\n }, [theme]);\n\n useEffect(() => {\n if (components) {\n setComponentPositions(\n heap.lastPageX,\n heap.lastPageY,\n heap.lastPlacement,\n heap.lastElement,\n components,\n );\n }\n }, [\n components,\n // BEWARE: Careful about these dependencies - they are updated when mouse\n // is moved over the tool-tipped element, thus potentially may cause\n // unnecessary firing of this effect on each mouse event. It does not\n // happen now just because the mouse movements themselves are not causing\n // the component re-rendering, thus dependencies of this effect are not\n // really re-evaluated.\n heap.lastPageX,\n heap.lastPageY,\n heap.lastPlacement,\n heap.lastElement,\n ]);\n\n return components ? createPortal(children, components.content) : null;\n});\n\nexport default Tooltip;\n"],"mappings":";;;;;;AAOA,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,SAAA,G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
6
6
  });
7
7
  exports.default = void 0;
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
8
  var _react = require("react");
10
9
  var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
11
10
  var _Tooltip = _interopRequireWildcard(require("./Tooltip"));
@@ -22,7 +21,6 @@ const defaultTheme = {
22
21
  "container": "-dr-pogodin-react-utils___src-shared-components-WithTooltip-default-theme___container___f9gY8K",
23
22
  "wrapper": "-dr-pogodin-react-utils___src-shared-components-WithTooltip-default-theme___wrapper___4qDBRM"
24
23
  };
25
- const validThemeKeys = [..._Tooltip.validThemeKeys, 'wrapper'];
26
24
  /**
27
25
  * Implements a simple to use and themeable tooltip component, _e.g._
28
26
  * ```js
@@ -123,14 +121,8 @@ const Wrapper = ({
123
121
  }) : null, children]
124
122
  });
125
123
  };
126
- const ThemedWrapper = (0, _reactThemes.default)(Wrapper, 'WithTooltip', ['appearance', 'arrow', 'container', 'content', 'wrapper'], defaultTheme);
124
+ const ThemedWrapper = (0, _reactThemes.default)(Wrapper, 'WithTooltip', defaultTheme);
127
125
  const e = ThemedWrapper;
128
126
  e.PLACEMENTS = _Tooltip.PLACEMENTS;
129
- Wrapper.propTypes = {
130
- children: _propTypes.default.node,
131
- placement: _propTypes.default.oneOf(Object.values(_Tooltip.PLACEMENTS)),
132
- theme: ThemedWrapper.themeType.isRequired,
133
- tip: _propTypes.default.node
134
- };
135
127
  var _default = exports.default = e;
136
128
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_reactThemes","_Tooltip","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","validThemeKeys","validTooltipThemeKeys","Wrapper","children","placement","PLACEMENTS","ABOVE_CURSOR","tip","theme","current","heap","useRef","lastCursorX","lastCursorY","triggeredByTouch","timerId","undefined","tooltipRef","wrapperRef","showTooltip","setShowTooltip","useState","updatePortalPosition","cursorX","cursorY","setTimeout","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","useEffect","listener","addEventListener","removeEventListener","jsxs","className","wrapper","onMouseLeave","onMouseMove","clientX","clientY","onClick","clearTimeout","onTouchStart","ref","role","jsx","ThemedWrapper","themed","propTypes","PT","node","oneOf","values","themeType","isRequired","_default","exports"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport PT from 'prop-types';\nimport {\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n validThemeKeys as validTooltipThemeKeys,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\nconst validThemeKeys = [...validTooltipThemeKeys, 'wrapper'] as const;\n\ntype PropsT = {\n children?: ReactNode;\n placement?: PLACEMENTS;\n tip?: ReactNode;\n theme: Theme<typeof validThemeKeys>;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n lastCursorX: number;\n lastCursorY: number;\n triggeredByTouch: boolean;\n timerId?: NodeJS.Timeout;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param {object} props Component properties.\n * @param {React.node} props.tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst Wrapper: React.FunctionComponent<PropsT> = ({\n children,\n placement = PLACEMENTS.ABOVE_CURSOR,\n tip,\n theme,\n}) => {\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n triggeredByTouch: false,\n timerId: undefined,\n });\n const tooltipRef = useRef<TooltipRefT>();\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (!showTooltip) {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n if (!heap.timerId) {\n heap.timerId = setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n }\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n } else {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap.lastCursorX + window.scrollX,\n heap.lastCursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n\n const listener = () => setShowTooltip(false);\n window.addEventListener('scroll', listener);\n return () => window.removeEventListener('scroll', listener);\n }\n return undefined;\n }, [\n heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={theme.wrapper}\n onMouseLeave={() => setShowTooltip(false)}\n onMouseMove={(e) => updatePortalPosition(e.clientX, e.clientY)}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\n >\n {\n showTooltip && tip !== null ? (\n <Tooltip ref={tooltipRef} theme={theme}>{tip}</Tooltip>\n ) : null\n }\n {children}\n </div>\n );\n};\n\nconst ThemedWrapper = themed(\n Wrapper,\n 'WithTooltip',\n [\n 'appearance',\n 'arrow',\n 'container',\n 'content',\n 'wrapper',\n ],\n defaultTheme,\n);\n\ntype ExportT = typeof ThemedWrapper & {\n PLACEMENTS: typeof PLACEMENTS;\n};\n\nconst e: ExportT = ThemedWrapper as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nWrapper.propTypes = {\n children: PT.node,\n placement: PT.oneOf(Object.values(PLACEMENTS)),\n theme: ThemedWrapper.themeType.isRequired,\n tip: PT.node,\n};\n\nexport default e;\n"],"mappings":";;;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAGmB,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,U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AC/B;IACF,CAAE;IACFmC,YAAY,EAAEA,CAAA,KAAM;MAClBvC,IAAI,CAACI,gBAAgB,GAAG,IAAI;IAC9B,CAAE;IACFoC,GAAG,EAAEhC,UAAW;IAChBiC,IAAI,EAAC,cAAc;IAAAhD,QAAA,GAGjBgB,WAAW,IAAIZ,GAAG,KAAK,IAAI,gBACzB,IAAA7B,WAAA,CAAA0E,GAAA,EAAC5E,QAAA,CAAAS,OAAO;MAACiE,GAAG,EAAEjC,UAAW;MAACT,KAAK,EAAEA,KAAM;MAAAL,QAAA,EAAEI;IAAG,CAAU,CAAC,GACrD,IAAI,EAETJ,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAED,MAAMkD,aAAa,GAAG,IAAAC,oBAAM,EAC1BpD,OAAO,EACP,aAAa,EACb,CACE,YAAY,EACZ,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,CACV,EACDH,YACF,CAAC;AAMD,MAAMnB,CAAU,GAAGyE,aAAwB;AAE3CzE,CAAC,CAACyB,UAAU,GAAGA,mBAAU;AAEzBH,OAAO,CAACqD,SAAS,GAAG;EAClBpD,QAAQ,EAAEqD,kBAAE,CAACC,IAAI;EACjBrD,SAAS,EAAEoD,kBAAE,CAACE,KAAK,CAACnE,MAAM,CAACoE,MAAM,CAACtD,mBAAU,CAAC,CAAC;EAC9CG,KAAK,EAAE6C,aAAa,CAACO,SAAS,CAACC,UAAU;EACzCtD,GAAG,EAAEiD,kBAAE,CAACC;AACV,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAA9E,OAAA,GAEaL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","require","_reactThemes","_interopRequireDefault","_Tooltip","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","Wrapper","children","placement","PLACEMENTS","ABOVE_CURSOR","tip","theme","current","heap","useRef","lastCursorX","lastCursorY","triggeredByTouch","timerId","undefined","tooltipRef","wrapperRef","showTooltip","setShowTooltip","useState","updatePortalPosition","cursorX","cursorY","setTimeout","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","useEffect","listener","addEventListener","removeEventListener","jsxs","className","wrapper","onMouseLeave","onMouseMove","clientX","clientY","onClick","clearTimeout","onTouchStart","ref","role","jsx","ThemedWrapper","themed","_default","exports"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n type ThemeKeysT as TooltipThemeKeysT,\n PLACEMENTS,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = {\n children?: ReactNode;\n placement?: PLACEMENTS;\n tip?: ReactNode;\n theme: Theme<'wrapper' | TooltipThemeKeysT>;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n lastCursorX: number;\n lastCursorY: number;\n triggeredByTouch: boolean;\n timerId?: NodeJS.Timeout;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param {object} props Component properties.\n * @param {React.node} props.tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst Wrapper: React.FunctionComponent<PropsT> = ({\n children,\n placement = PLACEMENTS.ABOVE_CURSOR,\n tip,\n theme,\n}) => {\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n triggeredByTouch: false,\n timerId: undefined,\n });\n const tooltipRef = useRef<TooltipRefT>();\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (!showTooltip) {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n if (!heap.timerId) {\n heap.timerId = setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n }\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n } else {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap.lastCursorX + window.scrollX,\n heap.lastCursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n\n const listener = () => setShowTooltip(false);\n window.addEventListener('scroll', listener);\n return () => window.removeEventListener('scroll', listener);\n }\n return undefined;\n }, [\n heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={theme.wrapper}\n onMouseLeave={() => setShowTooltip(false)}\n onMouseMove={(e) => updatePortalPosition(e.clientX, e.clientY)}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\n >\n {\n showTooltip && tip !== null ? (\n <Tooltip ref={tooltipRef} theme={theme}>{tip}</Tooltip>\n ) : null\n }\n {children}\n </div>\n );\n};\n\nconst ThemedWrapper = themed(Wrapper, 'WithTooltip', defaultTheme);\n\ntype ExportT = typeof ThemedWrapper & {\n PLACEMENTS: typeof PLACEMENTS;\n};\n\nconst e: ExportT = ThemedWrapper as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":";;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAGmB,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA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M;MAAAL,QAAA,EAAEI;IAAG,CAAU,CAAC,GACrD,IAAI,EAETJ,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAED,MAAMkD,aAAa,GAAG,IAAAC,oBAAM,EAACpD,OAAO,EAAE,aAAa,EAAED,YAAY,CAAC;AAMlE,MAAMnB,CAAU,GAAGuE,aAAwB;AAE3CvE,CAAC,CAACuB,UAAU,GAAGA,mBAAU;AAAC,IAAAkD,QAAA,GAAAC,OAAA,CAAArE,OAAA,GAEXL,CAAC","ignoreList":[]}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
8
  var _qs = _interopRequireDefault(require("qs"));
10
9
  var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
11
10
  var _Throbber = _interopRequireDefault(require("../Throbber"));
@@ -23,7 +22,6 @@ const throbberTheme = {
23
22
  "hoc": "-dr-pogodin-react-utils___src-shared-components-YouTubeVideo-throbber___hoc___7sH52O",
24
23
  "container": "-dr-pogodin-react-utils___src-shared-components-YouTubeVideo-throbber___container___jTxmOX"
25
24
  };
26
- const validThemeKeys = ['container', 'video'];
27
25
  /**
28
26
  * A component for embeding a YouTube video.
29
27
  * @param [props] Component properties.
@@ -49,7 +47,7 @@ const YouTubeVideo = ({
49
47
  let url = srcParts[0];
50
48
  const queryString = srcParts[1];
51
49
  const query = queryString ? _qs.default.parse(queryString) : {};
52
- const videoId = query.v || url.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
50
+ const videoId = query.v || url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
53
51
  url = `https://www.youtube.com/embed/${videoId}`;
54
52
  delete query.v;
55
53
  query.autoplay = autoplay ? '1' : '0';
@@ -71,12 +69,5 @@ const YouTubeVideo = ({
71
69
  })]
72
70
  });
73
71
  };
74
- const ThemedYouTubeVideo = (0, _reactThemes.default)(YouTubeVideo, 'YouTubeVideo', validThemeKeys, baseTheme);
75
- YouTubeVideo.propTypes = {
76
- autoplay: _propTypes.default.bool,
77
- src: _propTypes.default.string.isRequired,
78
- theme: ThemedYouTubeVideo.themeType.isRequired,
79
- title: _propTypes.default.string
80
- };
81
- var _default = exports.default = ThemedYouTubeVideo;
72
+ var _default = exports.default = (0, _reactThemes.default)(YouTubeVideo, 'YouTubeVideo', baseTheme);
82
73
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_qs","_reactThemes","_Throbber","_jsxRuntime","baseTheme","throbberTheme","validThemeKeys","YouTubeVideo","autoplay","src","theme","title","srcParts","split","url","queryString","query","qs","parse","videoId","v","match","stringify","jsxs","className","container","children","jsx","default","allow","allowFullScreen","video","ThemedYouTubeVideo","themed","propTypes","PT","bool","string","isRequired","themeType","_default","exports"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport qs from 'qs';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport baseTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\nconst validThemeKeys = ['container', 'video'] as const;\n\ntype ComponentThemeT = Theme<typeof validThemeKeys>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme: ComponentThemeT,\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: React.FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const srcParts = src.split('?');\n let url = srcParts[0];\n const queryString = srcParts[1];\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v || url.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={theme.container}>\n <Throbber theme={throbberTheme} />\n <iframe\n allow=\"autoplay\"\n allowFullScreen\n className={theme.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nconst ThemedYouTubeVideo = themed(\n YouTubeVideo,\n 'YouTubeVideo',\n validThemeKeys,\n baseTheme,\n);\n\nYouTubeVideo.propTypes = {\n autoplay: PT.bool,\n src: PT.string.isRequired,\n theme: ThemedYouTubeVideo.themeType.isRequired,\n title: PT.string,\n};\n\nexport default ThemedYouTubeVideo;\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAA2C,IAAAI,WAAA,GAAAJ,OAAA;AAAA,MAAAK,SAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,MAAAC,aAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAK3C,MAAMC,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,CAAU;AAWtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAA6C,GAAGA,CAAC;EACrDC,QAAQ;EACRC,GAAG;EACHC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,QAAQ,G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CAACO,SAAS,CAACD,UAAU;EAC9C3B,KAAK,EAAEwB,kBAAE,CAACE;AACZ,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAb,OAAA,GAEaI,kBAAkB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_qs","_interopRequireDefault","require","_reactThemes","_Throbber","_jsxRuntime","baseTheme","throbberTheme","YouTubeVideo","autoplay","src","theme","title","srcParts","split","url","queryString","query","qs","parse","videoId","v","match","stringify","jsxs","className","container","children","jsx","default","allow","allowFullScreen","video","_default","exports","themed"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport baseTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ComponentThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme: ComponentThemeT,\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: React.FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const srcParts = src.split('?');\n let url = srcParts[0];\n const queryString = srcParts[1];\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v || url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={theme.container}>\n <Throbber theme={throbberTheme} />\n <iframe\n allow=\"autoplay\"\n allowFullScreen\n className={theme.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default themed(YouTubeVideo, 'YouTubeVideo', baseTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AAA2C,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,SAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,MAAAC,aAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAc3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAA6C,GAAGA,CAAC;EACrDC,QAAQ;EACRC,GAAG;EACHC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,QAAQ,GAAGH,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC;EAC/B,IAAIC,GAAG,GAAGF,QAAQ,CAAC,CAAC,CAAC;EACrB,MAAMG,WAAW,GAAGH,QAAQ,CAAC,CAAC,CAAC;EAC/B,MAAMI,KAAK,GAAGD,WAAW,GAAGE,WAAE,CAACC,KAAK,CAACH,WAAW,CAAC,GAAG,CAAC,CAAC;EAEtD,MAAMI,OAAO,GAAGH,KAAK,CAACI,CAAC,IAAIN,GAAG,EAAEO,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;EACjEP,GAAG,GAAG,iCAAiCK,OAAO,EAAE;EAEhD,OAAOH,KAAK,CAACI,CAAC;EACdJ,KAAK,CAACR,QAAQ,GAAGA,QAAQ,GAAG,GAAG,GAAG,GAAG;EACrCM,GAAG,IAAI,IAAIG,WAAE,CAACK,SAAS,CAACN,KAAK,CAAC,EAAE;;EAEhC;EACA;;EAEA,oBACE,IAAAZ,WAAA,CAAAmB,IAAA;IAAKC,SAAS,EAAEd,KAAK,CAACe,SAAU;IAAAC,QAAA,gBAC9B,IAAAtB,WAAA,CAAAuB,GAAA,EAACxB,SAAA,CAAAyB,OAAQ;MAAClB,KAAK,EAAEJ;IAAc,CAAE,CAAC,eAClC,IAAAF,WAAA,CAAAuB,GAAA;MACEE,KAAK,EAAC,UAAU;MAChBC,eAAe;MACfN,SAAS,EAAEd,KAAK,CAACqB,KAAM;MACvBtB,GAAG,EAAEK,GAAI;MACTH,KAAK,EAAEA;IAAM,CACd,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAAC,IAAAqB,QAAA,GAAAC,OAAA,CAAAL,OAAA,GAEa,IAAAM,oBAAM,EAAC3B,YAAY,EAAE,cAAc,EAAEF,SAAS,CAAC","ignoreList":[]}
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.areEqual = areEqual;
8
7
  exports.default = void 0;
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
8
  var _react = require("react");
11
9
  var _Modal = require("../../../Modal");
12
10
  var _common = require("../../common");
@@ -42,7 +40,7 @@ const Options = /*#__PURE__*/(0, _react.forwardRef)(({
42
40
  const optionNodes = [];
43
41
  for (let i = 0; i < options.length; ++i) {
44
42
  const option = options[i];
45
- if (!filter || filter(option)) {
43
+ if (option !== undefined && (!filter || filter(option))) {
46
44
  const [iValue, iName] = (0, _common.optionValueName)(option);
47
45
  optionNodes.push( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
48
46
  className: optionClass,
@@ -86,18 +84,5 @@ const Options = /*#__PURE__*/(0, _react.forwardRef)(({
86
84
  })
87
85
  });
88
86
  });
89
- Options.propTypes = {
90
- containerClass: _propTypes.default.string.isRequired,
91
- containerStyle: _propTypes.default.shape({
92
- left: _propTypes.default.number.isRequired,
93
- top: _propTypes.default.number.isRequired,
94
- width: _propTypes.default.number.isRequired
95
- }),
96
- filter: _propTypes.default.func,
97
- onCancel: _propTypes.default.func.isRequired,
98
- onChange: _propTypes.default.func.isRequired,
99
- optionClass: _propTypes.default.string.isRequired,
100
- options: _common.optionsValidator.isRequired
101
- };
102
87
  var _default = exports.default = Options;
103
88
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_Modal","_common","_jsxRuntime","S","areEqual","a","b","left","top","width","Options","forwardRef","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","useRef","useImperativeHandle","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","i","length","option","iValue","iName","optionValueName","push","jsx","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","BaseModal","cancelOnScrolling","dontDisableScrolling","theme","ad","hoc","container","context","overlay","propTypes","PT","string","isRequired","shape","number","func","optionsValidator","_default","exports","default"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport { forwardRef, useImperativeHandle, useRef } from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport S from './style.scss';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionsValidator,\n optionValueName,\n} from '../../common';\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<React.ReactNode> | ValueT) => boolean;\n optionClass: string;\n options: OptionsT<React.ReactNode>;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n};\n\nconst Options = forwardRef<RefT, PropsT>(({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n}, ref) => {\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: React.ReactNode[] = [];\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\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 key={iValue}\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 containerStyle={containerStyle}\n dontDisableScrolling\n onCancel={onCancel}\n theme={{\n ad: '',\n hoc: '',\n container: containerClass,\n context: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n});\n\nOptions.propTypes = {\n containerClass: PT.string.isRequired,\n\n containerStyle: PT.shape({\n left: PT.number.isRequired,\n top: PT.number.isRequired,\n width: PT.number.isRequired,\n }),\n\n filter: PT.func,\n onCancel: PT.func.isRequired,\n onChange: PT.func.isRequired,\n optionClass: PT.string.isRequired,\n options: optionsValidator.isR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,WAAA,CAAA6C,GAAA;MAAK5B,GAAG,EAAEC,MAAO;MAAAmC,QAAA,EAAEhB;IAAW,CAAM;EAAC,CAC5B,CAAC;AAEhB,CAAC,CAAC;AAEF7B,OAAO,CAACuD,SAAS,GAAG;EAClBrD,cAAc,EAAEsD,kBAAE,CAACC,MAAM,CAACC,UAAU;EAEpCvD,cAAc,EAAEqD,kBAAE,CAACG,KAAK,CAAC;IACvB9D,IAAI,EAAE2D,kBAAE,CAACI,MAAM,CAACF,UAAU;IAC1B5D,GAAG,EAAE0D,kBAAE,CAACI,MAAM,CAACF,UAAU;IACzB3D,KAAK,EAAEyD,kBAAE,CAACI,MAAM,CAACF;EACnB,CAAC,CAAC;EAEFtD,MAAM,EAAEoD,kBAAE,CAACK,IAAI;EACfxD,QAAQ,EAAEmD,kBAAE,CAACK,IAAI,CAACH,UAAU;EAC5BpD,QAAQ,EAAEkD,kBAAE,CAACK,IAAI,CAACH,UAAU;EAC5BnD,WAAW,EAAEiD,kBAAE,CAACC,MAAM,CAACC,UAAU;EACjClD,OAAO,EAAEsD,wBAAgB,CAACJ;AAC5B,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEajE,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","require","_Modal","_common","_jsxRuntime","S","areEqual","a","b","left","top","width","Options","forwardRef","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","useRef","useImperativeHandle","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","i","length","option","iValue","iName","optionValueName","push","jsx","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","BaseModal","cancelOnScrolling","dontDisableScrolling","theme","ad","hoc","container","context","overlay","_default","exports","default"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import { forwardRef, useImperativeHandle, useRef } from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport S from './style.scss';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\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<React.ReactNode> | ValueT) => boolean;\n optionClass: string;\n options: Readonly<OptionsT<React.ReactNode>>;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n};\n\nconst Options = forwardRef<RefT, PropsT>(({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n}, ref) => {\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: React.ReactNode[] = [];\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!filter || filter(option))) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\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 key={iValue}\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 containerStyle={containerStyle}\n dontDisableScrolling\n onCancel={onCancel}\n theme={{\n ad: '',\n hoc: '',\n container: containerClass,\n context: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n});\n\nexport default Options;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AAKsB,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,CAAA;EAAA;AAAA;AAQf,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;AAgBA,MAAMC,OAAO,gBAAG,IAAAC,iBAAU,EAAe,CAAC;EACxCC,cAAc;EACdC,cAAc;EACdC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,WAAW;EACXC;AACF,CAAC,EAAEC,GAAG,KAAK;EACT,MAAMC,MAAM,GAAG,IAAAC,aAAM,EAAiB,IAAI,CAAC;EAE3C,IAAAC,0BAAmB,EAACH,GAAG,EAAE,OAAO;IAC9BI,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,CAAC,GAAGJ,MAAM,CAACK,OAAO,EAAEC,aAAa;MACvC,IAAI,CAACF,CAAC,EAAE,OAAOG,SAAS;MAExB,MAAMC,IAAI,GAAGR,MAAM,CAACK,OAAO,EAAEI,qBAAqB,CAAC,CAAC;MACpD,MAAMC,KAAK,GAAGC,MAAM,CAACC,gBAAgB,CAACR,CAAC,CAAC;MACxC,MAAMS,OAAO,GAAGC,UAAU,CAACJ,KAAK,CAACK,YAAY,CAAC;MAC9C,MAAMC,IAAI,GAAGF,UA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AAE;MACNC,GAAG,EAAE,EAAE;MACPC,SAAS,EAAElD,cAAc;MACzBmD,OAAO,EAAE,EAAE;MACXC,OAAO,EAAE7D,CAAC,CAAC6D;IACb,CAAE;IAAAT,QAAA,eAEF,IAAArD,WAAA,CAAA6C,GAAA;MAAK5B,GAAG,EAAEC,MAAO;MAAAmC,QAAA,EAAEhB;IAAW,CAAM;EAAC,CAC5B,CAAC;AAEhB,CAAC,CAAC;AAAC,IAAA0B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEYzD,OAAO","ignoreList":[]}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
8
  var _react = require("react");
10
9
  var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
11
10
  var _Options = _interopRequireWildcard(require("./Options"));
@@ -92,7 +91,7 @@ const BaseCustomDropdown = ({
92
91
  });
93
92
  for (let i = 0; i < options.length; ++i) {
94
93
  const option = options[i];
95
- if (!filter || filter(option)) {
94
+ if (option !== undefined && (!filter || filter(option))) {
96
95
  const [iValue, iName] = (0, _common.optionValueName)(option);
97
96
  if (iValue === value) {
98
97
  selected = iName;
@@ -140,14 +139,5 @@ const BaseCustomDropdown = ({
140
139
  }) : null]
141
140
  });
142
141
  };
143
- const ThemedCustomDropdown = (0, _reactThemes.default)(BaseCustomDropdown, 'CustomDropdown', _common.validThemeKeys, defaultTheme);
144
- BaseCustomDropdown.propTypes = {
145
- filter: _propTypes.default.func,
146
- label: _propTypes.default.node,
147
- onChange: _propTypes.default.func,
148
- options: _propTypes.default.arrayOf(_common.optionValidator.isRequired),
149
- theme: ThemedCustomDropdown.themeType.isRequired,
150
- value: _common.valueValidator
151
- };
152
- var _default = exports.default = ThemedCustomDropdown;
142
+ var _default = exports.default = (0, _reactThemes.default)(BaseCustomDropdown, 'CustomDropdown', defaultTheme);
153
143
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_reactThemes","_Options","_interopRequireWildcard","_common","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","BaseCustomDropdown","filter","label","onChange","options","theme","value","Error","active","setActive","useState","dropdownRef","useRef","opsRef","opsPos","setOpsPos","upward","setUpward","useEffect","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","areEqual","requestAnimationFrame","cancelAnimationFrame","openList","view","rect","stopPropagation","selected","jsx","Fragment","children","length","option","iValue","iName","optionValueName","containerClassName","container","opsContainerClass","select","jsxs","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass","ThemedCustomDropdown","themed","validThemeKeys","propTypes","PT","func","node","arrayOf","optionValidator","isRequired","themeType","valueValidator","_default","exports"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport { useEffect, useRef, useState } from 'react';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nimport {\n type PropsT,\n type ValueT,\n optionValidator,\n optionValueName,\n validThemeKeys,\n valueValidator,\n} from '../common';\n\nconst BaseCustomDropdown: React.FunctionComponent<\nPropsT<React.ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\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 top: anchor.top - opsRect.height - 1,\n left: anchor.left,\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 (let i = 0; i < options.length; ++i) {\n const option = options[i];\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 = theme.container;\n if (active) containerClassName += ` ${theme.active}`;\n\n let opsContainerClass = theme.select || '';\n if (upward) {\n containerClassName += ` ${theme.upward}`;\n opsContainerClass += ` ${theme.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null : (\n <div className={theme.label}>{label}</div>\n )}\n <div\n className={theme.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={theme.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={theme.option || ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nconst ThemedCustomDropdown = themed(\n BaseCustomDropdown,\n 'CustomDropdown',\n validThemeKeys,\n defaultTheme,\n);\n\nBaseCustomDropdown.propTypes = {\n filter: PT.func,\n label: PT.node,\n onChange: PT.func,\n options: PT.arrayOf(optionValidator.isRequired),\n theme: ThemedCustomDropdown.themeType.isRequired,\n value: valueValidator,\n};\n\nexport default ThemedCustomDropdown;\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAOmB,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,C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,CAAC,GACA,IAAI;EAAA,CAEP,CAAC;AAEV,CAAC;AAED,MAAM6D,oBAAoB,GAAG,IAAAC,oBAAM,EACjC3E,kBAAkB,EAClB,gBAAgB,EAChB4E,sBAAc,EACd7E,YACF,CAAC;AAEDC,kBAAkB,CAAC6E,SAAS,GAAG;EAC7B5E,MAAM,EAAE6E,kBAAE,CAACC,IAAI;EACf7E,KAAK,EAAE4E,kBAAE,CAACE,IAAI;EACd7E,QAAQ,EAAE2E,kBAAE,CAACC,IAAI;EACjB3E,OAAO,EAAE0E,kBAAE,CAACG,OAAO,CAACC,uBAAe,CAACC,UAAU,CAAC;EAC/C9E,KAAK,EAAEqE,oBAAoB,CAACU,SAAS,CAACD,UAAU;EAChD7E,KAAK,EAAE+E;AACT,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAtG,OAAA,GAEayF,oBAAoB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_react","require","_reactThemes","_interopRequireDefault","_Options","_interopRequireWildcard","_common","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","BaseCustomDropdown","filter","label","onChange","options","theme","value","Error","active","setActive","useState","dropdownRef","useRef","opsRef","opsPos","setOpsPos","upward","setUpward","useEffect","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","areEqual","requestAnimationFrame","cancelAnimationFrame","openList","view","rect","stopPropagation","selected","jsx","Fragment","children","length","option","iValue","iName","optionValueName","containerClassName","container","opsContainerClass","select","jsxs","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass","_default","exports","themed"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nconst BaseCustomDropdown: React.FunctionComponent<\nPropsT<React.ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\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 top: anchor.top - opsRect.height - 1,\n left: anchor.left,\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 (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!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 = theme.container;\n if (active) containerClassName += ` ${theme.active}`;\n\n let opsContainerClass = theme.select || '';\n if (upward) {\n containerClassName += ` ${theme.upward}`;\n opsContainerClass += ` ${theme.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null : (\n <div className={theme.label}>{label}</div>\n )}\n <div\n className={theme.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={theme.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={theme.option || ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default themed(BaseCustomDropdown, 'CustomDropdown', defaultTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAAsE,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA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SAAS,CAAC,KAAK,CAAC;QAChB,IAAIN,QAAQ,EAAEA,QAAQ,CAACqE,QAAQ,CAAC;MAClC,CAAE;MACFC,WAAW,EAAEpE,KAAK,CAAC8C,MAAM,IAAI,EAAG;MAChC/C,OAAO,EAAEA,OAAQ;MACjB6D,GAAG,EAAEpD;IAAO,CACb,CAAC,GACA,IAAI;EAAA,CAEP,CAAC;AAEV,CAAC;AAAC,IAAA6D,QAAA,GAAAC,OAAA,CAAA1F,OAAA,GAEa,IAAA2F,oBAAM,EAAC5E,kBAAkB,EAAE,gBAAgB,EAAED,YAAY,CAAC","ignoreList":[]}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
8
  var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
10
9
  var _common = require("../common");
11
10
  var _jsxRuntime = require("react/jsx-runtime");
@@ -55,7 +54,7 @@ const Dropdown = ({
55
54
  const optionElements = [];
56
55
  for (let i = 0; i < options.length; ++i) {
57
56
  const option = options[i];
58
- if (!filter || filter(option)) {
57
+ if (option !== undefined && (!filter || filter(option))) {
59
58
  const [iValue, iName] = (0, _common.optionValueName)(option);
60
59
  isValidValue ||= iValue === value;
61
60
  optionElements.push( /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
@@ -94,14 +93,5 @@ const Dropdown = ({
94
93
  })]
95
94
  });
96
95
  };
97
- const ThemedDropdown = (0, _reactThemes.default)(Dropdown, 'Dropdown', _common.validThemeKeys, defaultTheme);
98
- Dropdown.propTypes = {
99
- filter: _propTypes.default.func,
100
- label: _propTypes.default.node,
101
- onChange: _propTypes.default.func,
102
- options: _common.stringOptionsValidator,
103
- theme: ThemedDropdown.themeType.isRequired,
104
- value: _common.valueValidator
105
- };
106
- var _default = exports.default = ThemedDropdown;
96
+ var _default = exports.default = (0, _reactThemes.default)(Dropdown, 'Dropdown', defaultTheme);
107
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_reactThemes","_common","_jsxRuntime","defaultTheme","Dropdown","filter","label","onChange","options","theme","value","Error","isValidValue","optionElements","i","length","option","iValue","iName","optionValueName","push","jsx","className","children","hiddenOption","disabled","jsxs","container","undefined","dropdown","select","arrow","ThemedDropdown","themed","validThemeKeys","propTypes","PT","func","node","stringOptionsValidator","themeType","isRequired","valueValidator","_default","exports","default"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport PT from 'prop-types';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\nimport {\n type PropsT,\n optionValueName,\n stringOptionsValidator,\n validThemeKeys,\n valueValidator,\n} from '../common';\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: React.FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n let isValidValue = false;\n const optionElements = [];\n\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={theme.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 disabled\n className={theme.hiddenOption}\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n return (\n <div className={theme.container}>\n { label === undefined ? null : <div className={theme.label}>{label}</div> }\n <div className={theme.dropdown}>\n <select\n className={theme.select}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={theme.arrow} />\n </div>\n </div>\n );\n};\n\nconst ThemedDropdown = themed(\n Dropdown,\n 'Dropdown',\n validThemeKeys,\n defaultTheme,\n);\n\nDropdown.propTypes = {\n filter: PT.func,\n label: PT.node,\n onChange: PT.func,\n options: stringOptionsValidator,\n theme: ThemedDropdown.themeType.isRequired,\n value: valueValidator,\n};\n\nexport default ThemedDropdown;\n"],"mappings":";;;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AAMmB,IAAAG,WAAA,GAAAH,OAAA;AAdnB;AAAA,MAAAI,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAiD,GAAGA,CAAC;EACzDC,MAAM;EACNC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,IAAI,CAACF,OAAO,EAAE,MAAMG,KAAK,CAAC,gBAAgB,CAAC;EAE3C,IAAIC,YAAY,GAAG,KAAK;EACxB,MAAMC,cAAc,GAAG,EAAE;EAEzB,KAAK,IA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EACZX,cAAc;MAAA,CACT,CAAC,eACT,IAAAX,WAAA,CAAAmB,GAAA;QAAKC,SAAS,EAAEb,KAAK,CAACsB;MAAM,CAAE,CAAC;IAAA,CAC5B,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAED,MAAMC,cAAc,GAAG,IAAAC,oBAAM,EAC3B7B,QAAQ,EACR,UAAU,EACV8B,sBAAc,EACd/B,YACF,CAAC;AAEDC,QAAQ,CAAC+B,SAAS,GAAG;EACnB9B,MAAM,EAAE+B,kBAAE,CAACC,IAAI;EACf/B,KAAK,EAAE8B,kBAAE,CAACE,IAAI;EACd/B,QAAQ,EAAE6B,kBAAE,CAACC,IAAI;EACjB7B,OAAO,EAAE+B,8BAAsB;EAC/B9B,KAAK,EAAEuB,cAAc,CAACQ,SAAS,CAACC,UAAU;EAC1C/B,KAAK,EAAEgC;AACT,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEab,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_reactThemes","_interopRequireDefault","require","_common","_jsxRuntime","defaultTheme","Dropdown","filter","label","onChange","options","theme","value","Error","isValidValue","optionElements","i","length","option","undefined","iValue","iName","optionValueName","push","jsx","className","children","hiddenOption","disabled","jsxs","container","dropdown","select","arrow","_default","exports","default","themed"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\nimport { type PropsT, optionValueName } from '../common';\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: React.FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n let isValidValue = false;\n const optionElements = [];\n\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!filter || filter(option))) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={theme.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 disabled\n className={theme.hiddenOption}\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n return (\n <div className={theme.container}>\n { label === undefined ? null : <div className={theme.label}>{label}</div> }\n <div className={theme.dropdown}>\n <select\n className={theme.select}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={theme.arrow} />\n </div>\n </div>\n );\n};\n\nexport default themed(Dropdown, 'Dropdown', defaultTheme);\n"],"mappings":";;;;;;;AAEA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AAAyD,IAAAE,WAAA,GAAAF,OAAA;AANzD;AAAA,MAAAG,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAiD,GAAGA,CA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