@dr.pogodin/react-utils 1.57.1 → 1.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/build/development/client/getInj.js +17 -2
  2. package/build/development/client/getInj.js.map +1 -1
  3. package/build/development/server/Cache.js +42 -10
  4. package/build/development/server/Cache.js.map +1 -1
  5. package/build/development/server/index.js +6 -3
  6. package/build/development/server/index.js.map +1 -1
  7. package/build/development/server/renderer.js +67 -10
  8. package/build/development/server/renderer.js.map +1 -1
  9. package/build/development/server/server.js +17 -9
  10. package/build/development/server/server.js.map +1 -1
  11. package/build/development/server/utils/errors.js +11 -11
  12. package/build/development/server/utils/errors.js.map +1 -1
  13. package/build/development/server/utils/modules.js +35 -1
  14. package/build/development/server/utils/modules.js.map +1 -1
  15. package/build/development/shared/components/Button/index.js +1 -1
  16. package/build/development/shared/components/Button/index.js.map +1 -1
  17. package/build/development/shared/components/Checkbox/index.js +5 -5
  18. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  19. package/build/development/shared/components/Input/index.js +3 -3
  20. package/build/development/shared/components/Input/index.js.map +1 -1
  21. package/build/development/shared/components/Modal/index.js +3 -0
  22. package/build/development/shared/components/Modal/index.js.map +1 -1
  23. package/build/development/shared/components/TextArea/index.js +3 -3
  24. package/build/development/shared/components/TextArea/index.js.map +1 -1
  25. package/build/development/shared/components/WithTooltip/Tooltip.js +2 -2
  26. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  27. package/build/development/shared/components/WithTooltip/index.js +3 -1
  28. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +8 -2
  30. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/CustomDropdown/index.js +10 -4
  32. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  33. package/build/development/shared/components/selectors/NativeDropdown/index.js +7 -4
  34. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  35. package/build/development/shared/components/selectors/Switch/index.js +3 -3
  36. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  37. package/build/development/shared/utils/config.js.map +1 -1
  38. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +11 -10
  39. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  40. package/build/development/shared/utils/jest/index.js +4 -3
  41. package/build/development/shared/utils/jest/index.js.map +1 -1
  42. package/build/development/shared/utils/splitComponent.js +86 -10
  43. package/build/development/shared/utils/splitComponent.js.map +1 -1
  44. package/build/development/shared/utils/webpack.js +5 -2
  45. package/build/development/shared/utils/webpack.js.map +1 -1
  46. package/build/production/client/getInj.js +1 -1
  47. package/build/production/client/getInj.js.map +1 -1
  48. package/build/production/server/Cache.js +4 -4
  49. package/build/production/server/Cache.js.map +1 -1
  50. package/build/production/server/index.js +1 -1
  51. package/build/production/server/index.js.map +1 -1
  52. package/build/production/server/renderer.js +12 -12
  53. package/build/production/server/renderer.js.map +1 -1
  54. package/build/production/server/server.js +7 -7
  55. package/build/production/server/server.js.map +1 -1
  56. package/build/production/server/utils/errors.js +2 -2
  57. package/build/production/server/utils/errors.js.map +1 -1
  58. package/build/production/server/utils/modules.js +1 -1
  59. package/build/production/server/utils/modules.js.map +1 -1
  60. package/build/production/shared/components/Button/index.js +1 -1
  61. package/build/production/shared/components/Button/index.js.map +1 -1
  62. package/build/production/shared/components/Checkbox/index.js +1 -1
  63. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  64. package/build/production/shared/components/Input/index.js +1 -1
  65. package/build/production/shared/components/Input/index.js.map +1 -1
  66. package/build/production/shared/components/Modal/index.js +1 -1
  67. package/build/production/shared/components/Modal/index.js.map +1 -1
  68. package/build/production/shared/components/TextArea/index.js +1 -1
  69. package/build/production/shared/components/TextArea/index.js.map +1 -1
  70. package/build/production/shared/components/WithTooltip/Tooltip.js +1 -1
  71. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  72. package/build/production/shared/components/WithTooltip/index.js +2 -2
  73. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  74. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  75. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  76. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  77. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  78. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  79. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  80. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  81. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  82. package/build/production/shared/utils/config.js.map +1 -1
  83. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +3 -3
  84. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  85. package/build/production/shared/utils/jest/index.js +4 -4
  86. package/build/production/shared/utils/jest/index.js.map +1 -1
  87. package/build/production/shared/utils/splitComponent.js +5 -5
  88. package/build/production/shared/utils/splitComponent.js.map +1 -1
  89. package/build/production/shared/utils/webpack.js +4 -3
  90. package/build/production/shared/utils/webpack.js.map +1 -1
  91. package/build/types-code/shared/utils/config.d.ts +1 -1
  92. package/build/web/client/getInj.js +1 -1
  93. package/build/web/client/getInj.js.map +1 -1
  94. package/build/web/server/Cache.js +4 -4
  95. package/build/web/server/Cache.js.map +1 -1
  96. package/build/web/server/index.js +1 -1
  97. package/build/web/server/index.js.map +1 -1
  98. package/build/web/server/renderer.js +12 -12
  99. package/build/web/server/renderer.js.map +1 -1
  100. package/build/web/server/server.js +7 -7
  101. package/build/web/server/server.js.map +1 -1
  102. package/build/web/server/utils/errors.js +2 -2
  103. package/build/web/server/utils/errors.js.map +1 -1
  104. package/build/web/server/utils/modules.js +1 -1
  105. package/build/web/server/utils/modules.js.map +1 -1
  106. package/build/web/shared/components/Button/index.js +1 -1
  107. package/build/web/shared/components/Button/index.js.map +1 -1
  108. package/build/web/shared/components/Checkbox/index.js +1 -1
  109. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  110. package/build/web/shared/components/Input/index.js +1 -1
  111. package/build/web/shared/components/Input/index.js.map +1 -1
  112. package/build/web/shared/components/Modal/index.js +1 -1
  113. package/build/web/shared/components/Modal/index.js.map +1 -1
  114. package/build/web/shared/components/TextArea/index.js +1 -1
  115. package/build/web/shared/components/TextArea/index.js.map +1 -1
  116. package/build/web/shared/components/WithTooltip/Tooltip.js +1 -1
  117. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  118. package/build/web/shared/components/WithTooltip/index.js +2 -2
  119. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  120. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  121. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  122. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  123. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  124. package/build/web/shared/components/selectors/NativeDropdown/index.js +3 -3
  125. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  126. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  127. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  128. package/build/web/shared/utils/config.js.map +1 -1
  129. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +3 -3
  130. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  131. package/build/web/shared/utils/jest/index.js +4 -4
  132. package/build/web/shared/utils/jest/index.js.map +1 -1
  133. package/build/web/shared/utils/splitComponent.js +5 -5
  134. package/build/web/shared/utils/splitComponent.js.map +1 -1
  135. package/build/web/shared/utils/webpack.js +4 -3
  136. package/build/web/shared/utils/webpack.js.map +1 -1
  137. package/config/babel/webpack.js +15 -1
  138. package/package.json +21 -21
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n const elems = containerRef.current!.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":"4CAAA,OAIE,SAAS,CACT,OAAO,CACP,MAAM,KACD,OAAO,CAEd,OAAS,YAAY,KAAQ,WAAW,CAExC,OAAqB,QAAQ,KAAQ,0BAA0B,CAE/D,2JAC8B,yDAmB9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,UAAoC,CAAG,oBAAC,kIAW7C,CACC,mBAAqB,MAAM,CAAwB,IAAI,CAAC,CACxD,iBAAmB,MAAM,CAAwB,IAAI,CAAC,CAAC,4DAG7C,QACR,GAAI,iBAA6B,EAA7B,QAA6B,EAC/B,MAAM,iBAAiB,CAAC,QAAQ,CAAE,QAAQ,CAAC,CAC3C,MAAM,iBAAiB,CAAC,OAAO,CAAE,QAAQ,CAAC,EAC3C,MACM,KACL,GAAI,iBAA6B,EAA7B,QAA6B,EAC/B,MAAM,oBAAoB,CAAC,QAAQ,CAAE,QAAQ,CAAC,CAC9C,MAAM,oBAAoB,CAAC,OAAO,CAAE,QAAQ,CAAC,EAC9C,CACF,EACF,CAAE,IAAC,iBAAiB,CAAE,QAAQ,CAAC,6EAXhC,SAAS,CAAC,EAWT,CAAE,EAA6B,CAAC,+CAGvB,QACR,GAAI,CAAC,oBAAoB,EACvB,QAAQ,KAAK,UAAU,IAAI,CAAC,CAAC,yBAAyB,CAAC,EACxD,MACM,KACL,GAAI,CAAC,oBAAoB,EACvB,QAAQ,KAAK,UAAU,OAAO,CAAC,CAAC,yBAAyB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,iBAA0D,CAC9D,OAER,CAFQ,KAER,CACQ,OAER,CAFQ,MAER,CACI,GAAY,CAAZ,YAAY,CACZ,IAAQ,CAAR,QAAQ,CACN,KAAuB,CAAvB,GAAuB,UAE7B,QAAQ,CACN,CAAC,iJACN,6BACW,OAER,CAFQ,KACP,UAAU,QAAe,OAAE,CAAD,CAAC,EAC5B,CAGS,QAAC,CAAD,CAAC,CACZ,CAAC,iEAnED,6BAAY,cAEf,uBACG,SAAS,CACV,GA4BE,CAYF,GAeM,CACN,GAOE,CACD,SAAS,EACP,CAAC,CAER,QAAQ,KACV,CAAC,sDAxEM,IAwEN,EACF,CAED,sCACA,OAAS,SAAS,EAElB,KAAM,MAEL,CAAG,oDAAC,mBAAkB,2DACrB,eAAiB,QAAQ,CAAC,OAAO,CAAE,YAAY,CAAE,KAAK,CAAC,CAAC,wCAGjD,qBAAC,SAAS,KAAK,IAAI,CAAS,KAAQ,CAAR,QAAQ,CAAG,CAAC,sDAAxC,GAAwC,EAChD,CAED,cAAe,MAAK,CAhJyB,oBA0GjC,GAAC,gBAAgB,CAAC,CAAC,EA1Gc,uBA6GjC,KAAK,gBAAgB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n if (!containerRef.current) throw Error('Missing container reference');\n const elems = containerRef.current.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":"4CAAA,OAIE,SAAS,CACT,OAAO,CACP,MAAM,KACD,OAAO,CAEd,OAAS,YAAY,KAAQ,WAAW,CAExC,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C,CAER,QAAQ,KACV,CAAC,sDAxEM,IAwEN,EACF,CAED,sCACA,OAAS,SAAS,EAElB,KAAM,MAEL,CAAG,oDAAC,mBAAkB,2DACrB,eAAiB,QAAQ,CAAC,OAAO,CAAE,YAAY,CAAE,KAAK,CAAC,CAAC,wCAGjD,qBAAC,SAAS,KAAK,IAAI,CAAS,KAAQ,CAAR,QAAQ,CAAG,CAAC,sDAAxC,GAAwC,EAChD,CAED,cAAe,MAAK,CAjJyB,oBA2GjC,GAAC,gBAAgB,CAAC,CAAC,EA3Gc,uBA8GjC,KAAK,gBAAgB,CAAC,CAAC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import{c as _c}from"react/compiler-runtime";import{useEffect,useLayoutEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";const defaultTheme={"context":"tECG8C","ad":"epeH4O","hoc":"_2kFnSt","container":"lV5ZyX","label":"_7qDPW1","textarea":"gkaNJJ","error":"ObwtG4","errorMessage":"ikIw0x","hidden":"-UyujK"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TextArea=t0=>{const $=_c(39);const{disabled,error,label,onBlur,onChange,onKeyDown,placeholder,ref,testId,theme,value}=t0;const custom=useTheme("TextArea",defaultTheme,theme);const hiddenAreaRef=useRef(null);const[height,setHeight]=useState();const textAreaRef=useRef(null);const[localValue,setLocalValue]=useState(value??"");if(value!==undefined&&localValue!==value){setLocalValue(value);}let t1;let t2;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=()=>{const el=hiddenAreaRef.current;if(!el){return;}const cb=()=>{setHeight(el.scrollHeight);};const observer=new ResizeObserver(cb);observer.observe(el);return()=>{observer.disconnect();};};t2=[];$[0]=t1;$[1]=t2;}else{t1=$[0];t2=$[1];}useEffect(t1,t2);let t3;if($[2]===Symbol.for("react.memo_cache_sentinel")){t3=()=>{const el_0=hiddenAreaRef.current;if(el_0){setHeight(el_0.scrollHeight);}};$[2]=t3;}else{t3=$[2];}let t4;if($[3]!==localValue){t4=[localValue];$[3]=localValue;$[4]=t4;}else{t4=$[4];}useLayoutEffect(t3,t4);let containerClassName=custom.container;if(error){containerClassName=containerClassName+` ${custom.error}`;}let t5;if($[5]===Symbol.for("react.memo_cache_sentinel")){t5=()=>{textAreaRef.current?.focus();};$[5]=t5;}else{t5=$[5];}let t6;if($[6]!==custom.label||$[7]!==label){t6=label===undefined?null:/*#__PURE__*/_jsx("div",{className:custom.label,children:label});$[6]=custom.label;$[7]=label;$[8]=t6;}else{t6=$[8];}const t7=`${custom.textarea} ${custom.hidden}`;const t8=localValue||" ";let t9;if($[9]!==t7||$[10]!==t8){t9=/*#__PURE__*/_jsx("textarea",{className:t7,readOnly:true,ref:hiddenAreaRef,tabIndex:-1,value:t8});$[9]=t7;$[10]=t8;$[11]=t9;}else{t9=$[11];}const t10=process.env.NODE_ENV==="production"?undefined:testId;let t11;if($[12]!==onChange||$[13]!==value){t11=value===undefined?e=>{setLocalValue(e.target.value);}:onChange;$[12]=onChange;$[13]=value;$[14]=t11;}else{t11=$[14];}let t12;if($[15]!==ref){t12=node=>{textAreaRef.current=node;if(typeof ref==="function"){ref(node);}else{if(ref){ref.current=node;}}};$[15]=ref;$[16]=t12;}else{t12=$[16];}let t13;if($[17]!==height){t13={height};$[17]=height;$[18]=t13;}else{t13=$[18];}let t14;if($[19]!==custom.textarea||$[20]!==disabled||$[21]!==localValue||$[22]!==onBlur||$[23]!==onKeyDown||$[24]!==placeholder||$[25]!==t10||$[26]!==t11||$[27]!==t12||$[28]!==t13){t14=/*#__PURE__*/_jsx("textarea",{className:custom.textarea,"data-testid":t10,disabled:disabled,onBlur:onBlur,onChange:t11,onKeyDown:onKeyDown,placeholder:placeholder,ref:t12,style:t13,value:localValue});$[19]=custom.textarea;$[20]=disabled;$[21]=localValue;$[22]=onBlur;$[23]=onKeyDown;$[24]=placeholder;$[25]=t10;$[26]=t11;$[27]=t12;$[28]=t13;$[29]=t14;}else{t14=$[29];}let t15;if($[30]!==custom.errorMessage||$[31]!==error){t15=error&&error!==true?/*#__PURE__*/_jsx("div",{className:custom.errorMessage,children:error}):null;$[30]=custom.errorMessage;$[31]=error;$[32]=t15;}else{t15=$[32];}let t16;if($[33]!==containerClassName||$[34]!==t14||$[35]!==t15||$[36]!==t6||$[37]!==t9){t16=/*#__PURE__*/_jsxs("div",{className:containerClassName,onFocus:t5,children:[t6,t9,t14,t15]});$[33]=containerClassName;$[34]=t14;$[35]=t15;$[36]=t6;$[37]=t9;$[38]=t16;}else{t16=$[38];}return t16;};export default TextArea;
1
+ import{c as _c}from"react/compiler-runtime";import{useEffect,useLayoutEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";const defaultTheme={"context":"tECG8C","ad":"epeH4O","hoc":"_2kFnSt","container":"lV5ZyX","label":"_7qDPW1","textarea":"gkaNJJ","error":"ObwtG4","errorMessage":"ikIw0x","hidden":"-UyujK"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TextArea=t0=>{const $=_c(39);const{disabled,error,label,onBlur,onChange,onKeyDown,placeholder,ref,testId,theme,value}=t0;const custom=useTheme("TextArea",defaultTheme,theme);const hiddenAreaRef=useRef(null);const[height,setHeight]=useState();const textAreaRef=useRef(null);const[localValue,setLocalValue]=useState(value??"");if(value!==undefined&&localValue!==value){setLocalValue(value);}let t1;let t2;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=()=>{const el=hiddenAreaRef.current;if(!el){return;}const cb=()=>{setHeight(el.scrollHeight);};const observer=new ResizeObserver(cb);observer.observe(el);return()=>{observer.disconnect();};};t2=[];$[0]=t1;$[1]=t2;}else{t1=$[0];t2=$[1];}useEffect(t1,t2);let t3;if($[2]===Symbol.for("react.memo_cache_sentinel")){t3=()=>{const el_0=hiddenAreaRef.current;if(el_0){setHeight(el_0.scrollHeight);}};$[2]=t3;}else{t3=$[2];}let t4;if($[3]!==localValue){t4=[localValue];$[3]=localValue;$[4]=t4;}else{t4=$[4];}useLayoutEffect(t3,t4);let containerClassName=custom.container??"";if(error){containerClassName=containerClassName+` ${custom.error??""}`;}let t5;if($[5]===Symbol.for("react.memo_cache_sentinel")){t5=()=>{textAreaRef.current?.focus();};$[5]=t5;}else{t5=$[5];}let t6;if($[6]!==custom.label||$[7]!==label){t6=label===undefined?null:/*#__PURE__*/_jsx("div",{className:custom.label,children:label});$[6]=custom.label;$[7]=label;$[8]=t6;}else{t6=$[8];}const t7=`${custom.textarea??""} ${custom.hidden??""}`;const t8=localValue||" ";let t9;if($[9]!==t7||$[10]!==t8){t9=/*#__PURE__*/_jsx("textarea",{className:t7,readOnly:true,ref:hiddenAreaRef,tabIndex:-1,value:t8});$[9]=t7;$[10]=t8;$[11]=t9;}else{t9=$[11];}const t10=process.env.NODE_ENV==="production"?undefined:testId;let t11;if($[12]!==onChange||$[13]!==value){t11=value===undefined?e=>{setLocalValue(e.target.value);}:onChange;$[12]=onChange;$[13]=value;$[14]=t11;}else{t11=$[14];}let t12;if($[15]!==ref){t12=node=>{textAreaRef.current=node;if(typeof ref==="function"){ref(node);}else{if(ref){ref.current=node;}}};$[15]=ref;$[16]=t12;}else{t12=$[16];}let t13;if($[17]!==height){t13={height};$[17]=height;$[18]=t13;}else{t13=$[18];}let t14;if($[19]!==custom.textarea||$[20]!==disabled||$[21]!==localValue||$[22]!==onBlur||$[23]!==onKeyDown||$[24]!==placeholder||$[25]!==t10||$[26]!==t11||$[27]!==t12||$[28]!==t13){t14=/*#__PURE__*/_jsx("textarea",{className:custom.textarea,"data-testid":t10,disabled:disabled,onBlur:onBlur,onChange:t11,onKeyDown:onKeyDown,placeholder:placeholder,ref:t12,style:t13,value:localValue});$[19]=custom.textarea;$[20]=disabled;$[21]=localValue;$[22]=onBlur;$[23]=onKeyDown;$[24]=placeholder;$[25]=t10;$[26]=t11;$[27]=t12;$[28]=t13;$[29]=t14;}else{t14=$[29];}let t15;if($[30]!==custom.errorMessage||$[31]!==error){t15=error&&error!==true?/*#__PURE__*/_jsx("div",{className:custom.errorMessage,children:error}):null;$[30]=custom.errorMessage;$[31]=error;$[32]=t15;}else{t15=$[32];}let t16;if($[33]!==containerClassName||$[34]!==t14||$[35]!==t15||$[36]!==t6||$[37]!==t9){t16=/*#__PURE__*/_jsxs("div",{className:containerClassName,onFocus:t5,children:[t6,t9,t14,t15]});$[33]=containerClassName;$[34]=t14;$[35]=t15;$[36]=t6;$[37]=t9;$[38]=t16;}else{t16=$[38];}return t16;};export default TextArea;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\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 // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container;\n if (error) containerClassName += ` ${custom.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea} ${custom.hidden}`}\n\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\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\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={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />\n {error &&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MAAM,MAAM,UAAG,KAAK,CAAM,CAAC,qDAE5D,YAAG,MAAM,SAAS,IAAI,MAAM,OAAO,EAAE,CAgBzC,mBAAiB,EAAjB,GAAiB,kCAjB1B,iCACa,SAAqC,CAArC,EAAqC,CAKhD,QAAQ,CAAR,IAAQ,CACH,GAAa,CAAb,aAAa,CAIR,QAAE,CAAF,EAAE,CAML,KAAiB,CAAjB,EAAiB,CACzB,CAAC,2CAGa,iBAAO,IAAI,SAAS,GAAK,YAAiC,CAA1D,SAA0D,CAA1D,MAA0D,6CAQrE,SAAK,GAAK,SAGI,CAHd,IAEI,aAAa,CAAC,CAAC,OAAO,MAAM,CAAC,EACnB,CAHd,QAGc,+EAKX,WACH,WAAW,SAAW,IAAH,CAEnB,GAAI,MAAO,IAAG,GAAK,UAAU,EAAE,GAAG,CAAC,IAAI,CAAC,OAGnC,GAAI,GAAG,EAAE,GAAG,SAAW,IAAH,EAAQ,EAClC,iEAEM,WAAS,CAAC,+NA3BnB,kCACa,SAAe,CAAf,MAAM,SAAS,CACb,iBAA0D,CAC7D,QAAQ,CAAR,QAAQ,CACV,MAAM,CAAN,MAAM,CAMZ,QAGc,CAHd,GAGc,CAEL,SAAS,CAAT,SAAS,CACP,WAAW,CAAX,WAAW,CAEnB,GAOJ,CAPI,GAOJ,CAEM,KAAU,CAAV,GAAU,CACV,KAAU,CAAV,UAAU,CAClB,CAAC,gOACD,SAAuB,EAAd,KAAK,GAAK,IAEZ,cAFP,YACmB,SAAmB,CAAnB,MAAM,aAAa,UAAG,KAAK,CACxC,CAAC,CAFP,IAEO,2JA1DV,8BACa,SAAkB,CAAlB,kBAAkB,CACpB,OAER,CAFQ,EAER,WAEA,EAAwE,CACzE,EAkBE,CACF,GA6BE,CACD,GAEO,EACL,CAAC,iGA3DN,IA2DM,EAET,CAED,cAAe,SAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\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 // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container ?? '';\n if (error) containerClassName += ` ${custom.error ?? ''}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea ?? ''} ${custom.hidden ?? ''}`}\n\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\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\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={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />\n {error && error !== true\n ? <div className={custom.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default TextArea;\n"],"mappings":"4CAAA,OAOE,SAAS,CACT,eAAe,CACf,MAAM,CACN,QAAQ,KACH,OAAO,CAEd,OAAqB,QAAQ,KAAQ,0BAA0B,CAE/D,4LAAwC,yDAmBxC,KAAM,SAAkC,CAAG,oBAAC,2FAY3C,CACC,aAAe,QAAQ,CAAC,UAAU,CAAE,YAAY,CAAE,KAAK,CAAC,CAExD,oBAAsB,MAAM,CAAsB,IAAI,CAAC,CACvD,wBAA4B,QAAQ,CAAqB,CAA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D,SAA0D,CAA1D,MAA0D,6CAQrE,SAAK,GAAK,SAGI,CAHd,IAEI,aAAa,CAAC,CAAC,OAAO,MAAM,CAAC,EACnB,CAHd,QAGc,+EAKX,WACH,WAAW,SAAW,IAAH,CAEnB,GAAI,MAAO,IAAG,GAAK,UAAU,EAAE,GAAG,CAAC,IAAI,CAAC,OAGnC,GAAI,GAAG,EAAE,GAAG,SAAW,IAAH,EAAQ,EAClC,iEAEM,WAAS,CAAC,+NA3BnB,kCACa,SAAe,CAAf,MAAM,SAAS,CACb,iBAA0D,CAC7D,QAAQ,CAAR,QAAQ,CACV,MAAM,CAAN,MAAM,CAMZ,QAGc,CAHd,GAGc,CAEL,SAAS,CAAT,SAAS,CACP,WAAW,CAAX,WAAW,CAEnB,GAOJ,CAPI,GAOJ,CAEM,KAAU,CAAV,GAAU,CACV,KAAU,CAAV,UAAU,CAClB,CAAC,gOACD,SAAuB,EAAd,KAAK,GAAK,IAEZ,cAFP,YACmB,SAAmB,CAAnB,MAAM,aAAa,UAAG,KAAK,CACxC,CAAC,CAFP,IAEO,2JA1DV,8BACa,SAAkB,CAAlB,kBAAkB,CACpB,OAER,CAFQ,EAER,WAEA,EAAwE,CACzE,EAkBE,CACF,GA6BE,CACD,GAEO,EACL,CAAC,iGA3DN,IA2DM,EAET,CAED,cAAe,SAAQ","ignoreList":[]}
@@ -88,5 +88,5 @@ baseArrowStyle:ARROW_STYLE_DOWN};}// const HIT = {
88
88
  * @param tooltip
89
89
  * @param tooltip.arrow DOM reference to the tooltip arrow.
90
90
  * @param tooltip.container DOM reference to the tooltip container.
91
- */function setComponentPositions(pageX,pageY,placement,element,tooltip){const tooltipRects=calcTooltipRects(tooltip);const viewportRect=calcViewportRect();/* Default container coords: tooltip at the top. */const pos=calcPositionAboveXY(pageX,pageY,tooltipRects);if(pos.containerX<viewportRect.left+6){pos.containerX=viewportRect.left+6;pos.arrowX=Math.max(6,pageX-pos.containerX-tooltipRects.arrow.width/2);}else{const maxX=viewportRect.right-6-tooltipRects.container.width;if(pos.containerX>maxX){pos.containerX=maxX;pos.arrowX=Math.min(tooltipRects.container.width-6,pageX-pos.containerX-tooltipRects.arrow.width/2);}}/* If tooltip has not enough space on top - make it bottom tooltip. */if(pos.containerY<viewportRect.top+6){pos.containerY+=tooltipRects.container.height+2*tooltipRects.arrow.height;pos.arrowY-=tooltipRects.container.height+tooltipRects.arrow.height;pos.baseArrowStyle=ARROW_STYLE_UP;}const containerStyle=`left:${pos.containerX}px;top:${pos.containerY}px`;tooltip.container.setAttribute("style",containerStyle);const arrowStyle=`${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;tooltip.arrow.setAttribute("style",arrowStyle);}/* The Tooltip component itself. */const Tooltip=t0=>{const $=_c(11);const{children,ref,theme}=t0;const arrowRef=useRef(null);const containerRef=useRef(null);const contentRef=useRef(null);let t1;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=(pageX,pageY,placement,element)=>{if(!arrowRef.current||!containerRef.current||!contentRef.current){throw Error("Internal error");}setComponentPositions(pageX,pageY,placement,element,{arrow:arrowRef.current,container:containerRef.current,content:contentRef.current});};$[0]=t1;}else{t1=$[0];}const pointTo=t1;let t2;if($[1]===Symbol.for("react.memo_cache_sentinel")){t2=()=>({pointTo});$[1]=t2;}else{t2=$[1];}useImperativeHandle(ref,t2);let t3;if($[2]!==theme.arrow){t3=/*#__PURE__*/_jsx("div",{className:theme.arrow,ref:arrowRef});$[2]=theme.arrow;$[3]=t3;}else{t3=$[3];}let t4;if($[4]!==children||$[5]!==theme.content){t4=/*#__PURE__*/_jsx("div",{className:theme.content,ref:contentRef,children:children});$[4]=children;$[5]=theme.content;$[6]=t4;}else{t4=$[6];}let t5;if($[7]!==t3||$[8]!==t4||$[9]!==theme.container){t5=/*#__PURE__*/createPortal(/*#__PURE__*/_jsxs("div",{className:theme.container,ref:containerRef,children:[t3,t4]}),document.body);$[7]=t3;$[8]=t4;$[9]=theme.container;$[10]=t5;}else{t5=$[10];}return t5;};export default Tooltip;
91
+ */function setComponentPositions(pageX,pageY,placement,element,tooltip){const tooltipRects=calcTooltipRects(tooltip);const viewportRect=calcViewportRect();/* Default container coords: tooltip at the top. */const pos=calcPositionAboveXY(pageX,pageY,tooltipRects);if(pos.containerX<viewportRect.left+6){pos.containerX=viewportRect.left+6;pos.arrowX=Math.max(6,pageX-pos.containerX-tooltipRects.arrow.width/2);}else{const maxX=viewportRect.right-6-tooltipRects.container.width;if(pos.containerX>maxX){pos.containerX=maxX;pos.arrowX=Math.min(tooltipRects.container.width-6,pageX-pos.containerX-tooltipRects.arrow.width/2);}}/* If tooltip has not enough space on top - make it bottom tooltip. */if(pos.containerY<viewportRect.top+6){pos.containerY+=tooltipRects.container.height+2*tooltipRects.arrow.height;pos.arrowY-=tooltipRects.container.height+tooltipRects.arrow.height;pos.baseArrowStyle=ARROW_STYLE_UP;}const containerStyle=`left:${pos.containerX.toString()}px;top:${pos.containerY.toString()}px`;tooltip.container.setAttribute("style",containerStyle);const arrowStyle=`${pos.baseArrowStyle};left:${pos.arrowX.toString()}px;top:${pos.arrowY.toString()}px`;tooltip.arrow.setAttribute("style",arrowStyle);}/* The Tooltip component itself. */const Tooltip=t0=>{const $=_c(11);const{children,ref,theme}=t0;const arrowRef=useRef(null);const containerRef=useRef(null);const contentRef=useRef(null);let t1;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=(pageX,pageY,placement,element)=>{if(!arrowRef.current||!containerRef.current||!contentRef.current){throw Error("Internal error");}setComponentPositions(pageX,pageY,placement,element,{arrow:arrowRef.current,container:containerRef.current,content:contentRef.current});};$[0]=t1;}else{t1=$[0];}const pointTo=t1;let t2;if($[1]===Symbol.for("react.memo_cache_sentinel")){t2=()=>({pointTo});$[1]=t2;}else{t2=$[1];}useImperativeHandle(ref,t2);let t3;if($[2]!==theme.arrow){t3=/*#__PURE__*/_jsx("div",{className:theme.arrow,ref:arrowRef});$[2]=theme.arrow;$[3]=t3;}else{t3=$[3];}let t4;if($[4]!==children||$[5]!==theme.content){t4=/*#__PURE__*/_jsx("div",{className:theme.content,ref:contentRef,children:children});$[4]=children;$[5]=theme.content;$[6]=t4;}else{t4=$[6];}let t5;if($[7]!==t3||$[8]!==t4||$[9]!==theme.container){t5=/*#__PURE__*/createPortal(/*#__PURE__*/_jsxs("div",{className:theme.container,ref:containerRef,children:[t3,t4]}),document.body);$[7]=t3;$[8]=t4;$[9]=theme.container;$[10]=t5;}else{t5=$[10];}return t5;};export default Tooltip;
92
92
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","names":[],"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\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\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 arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\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 bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\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// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function 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 * 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// function 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 * 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: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\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 arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"4CAAA;AACA;AACA;AACA;AACA,GAEA,OAIE,mBAAmB,CACnB,MAAM,KACD,OAAO,CAEd,OAAS,YAAY,KAAQ,WAAW,CAAC,yDAIzC;AACA;AACA;AACA,GACA,UAAY,WAAU,uBAAV,UAAU,EAAV,UAAU,gCAA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,QAAU,CAAC,CAAC,wBAA5C,mBAAmB,CAAC,GAAG,CAAE,EAAmB,CAAC,+BAKvC,4BAAgB,SAAW,CAAX,KAAK,MAAM,CAAO,GAAQ,CAAR,QAAQ,CAAG,CAAC,0FAC9C,4BAAgB,SAAa,CAAb,KAAK,QAAQ,CAAO,GAAU,CAAV,UAAU,UAAG,QAAQ,CAAM,CAAC,iHAJ/D,4BAAY,cAEf,aAAgB,SAAe,CAAf,KAAK,UAAU,CAAO,GAAY,CAAZ,YAAY,WAChD,EAA8C,CAC9C,EAAgE,EAC7D,CAAC,CAER,QAAQ,KACV,CAAC,qEARM,GAQN,EACF,CAED,cAAe,QAAO","ignoreList":[]}
1
+ {"version":3,"file":"Tooltip.js","names":[],"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\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\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 arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\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 bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\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// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function 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 * 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// function 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 * 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.toString()}px;top:${pos.containerY.toString()}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX.toString()}px;top:${pos.arrowY.toString()}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\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 arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"4CAAA;AACA;AACA;AACA;AACA,GAEA,OAIE,mBAAmB,CACnB,MAAM,KACD,OAAO,CAEd,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gBAAgB,CAAC,CAAC,CAGhC,qBAAqB,CAAC,KAAK,CAAE,KAAK,CAAE,SAAS,CAAE,OAAO,CAAE,OAC/C,QAAQ,QAAQ,WACZ,YAAY,QAAQ,SACtB,UAAU,QACrB,CAAC,CAAC,EACH,wBAfD,cAAgB,EAef,CAAC,0DACuB,QAAO,QAAU,CAAC,CAAC,wBAA5C,mBAAmB,CAAC,GAAG,CAAE,EAAmB,CAAC,+BAKvC,4BAAgB,SAAW,CAAX,KAAK,MAAM,CAAO,GAAQ,CAAR,QAAQ,CAAG,CAAC,0FAC9C,4BAAgB,SAAa,CAAb,KAAK,QAAQ,CAAO,GAAU,CAAV,UAAU,UAAG,QAAQ,CAAM,CAAC,iHAJ/D,4BAAY,cAEf,aAAgB,SAAe,CAAf,KAAK,UAAU,CAAO,GAAY,CAAZ,YAAY,WAChD,EAA8C,CAC9C,EAAgE,EAC7D,CAAC,CAER,QAAQ,KACV,CAAC,qEARM,GAQN,EACF,CAED,cAAe,QAAO","ignoreList":[]}
@@ -11,7 +11,7 @@
11
11
  * @param tip &ndash; Anything React is able to render,
12
12
  * _e.g._ a tooltip text. This will be the tooltip content.
13
13
  * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
14
- */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const[heap,setHeap]=useState({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{setHeap(prev=>{const res={...prev,lastCursorX:cursorX,lastCursorY:cursorY};// If tooltip was triggered by a touch, we delay its opening by a bit,
14
+ */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const[heap,setHeap]=useState({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){if(!wrapperRef.current)throw Error("Missing reference");const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{setHeap(prev=>{const res={...prev,lastCursorX:cursorX,lastCursorY:cursorY};// If tooltip was triggered by a touch, we delay its opening by a bit,
15
15
  // to ensure it was not a touch-click - in the case of touch click we
16
16
  // want to do the click, rather than show the tooltip, and the delay
17
17
  // gives click handler a chance to abort the tooltip openning.
@@ -21,7 +21,7 @@ if(res.triggeredByTouch){res.timerId??=setTimeout(()=>{setHeap(p=>({...p,timerId
21
21
  // once opened (because similar call above does not have effect until
22
22
  // the tooltip is fully mounted, and that is delayed to future rendering
23
23
  // cycle due to the implementation).
24
- if(tooltipRef.current){setHeap(prev_0=>{tooltipRef.current?.pointTo(prev_0.lastCursorX+window.scrollX,prev_0.lastCursorY+window.scrollY,placement,wrapperRef.current);return prev_0;});}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper;if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener_0=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener_0);window.addEventListener("touchend",listener_0);return()=>{window.removeEventListener("touchcancel",listener_0);window.removeEventListener("touchend",listener_0);};},[heap]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);setHeap({...heap,timerId:undefined,triggeredByTouch:false});}onClick?.(e);},onContextMenu:e_0=>{e_0.preventDefault();onContextMenu?.(e_0);},onMouseLeave:e_1=>{setShowTooltip(false);onMouseLeave?.(e_1);},onMouseMove:e_2=>{// NOTE: Because on touch devices mouse move events are still fired
24
+ if(tooltipRef.current){setHeap(prev_0=>{if(!wrapperRef.current)throw Error("Missing reference");tooltipRef.current?.pointTo(prev_0.lastCursorX+window.scrollX,prev_0.lastCursorY+window.scrollY,placement,wrapperRef.current);return prev_0;});}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper??"";if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener_0=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener_0);window.addEventListener("touchend",listener_0);return()=>{window.removeEventListener("touchcancel",listener_0);window.removeEventListener("touchend",listener_0);};},[heap]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);setHeap({...heap,timerId:undefined,triggeredByTouch:false});}onClick?.(e);},onContextMenu:e_0=>{e_0.preventDefault();onContextMenu?.(e_0);},onMouseLeave:e_1=>{setShowTooltip(false);onMouseLeave?.(e_1);},onMouseMove:e_2=>{// NOTE: Because on touch devices mouse move events are still fired
25
25
  // after touch is released, to emulate mouse clicks for old websites.
26
26
  // If we don't ignore it here, the tooltip will appear after the touch
27
27
  // is released.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\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 ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\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 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 WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\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 } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\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 (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\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 setHeap((prev) => {\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,OAKE,SAAS,CACT,MAAM,CACN,QAAQ,KACH,OAAO,CAEd,OAAqB,QAAQ,KAAQ,0BAA0B,CAAC,MAEzD,QAAO,EACZ,UAAU,oBAIZ,sJAAgD,yDA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,YAAsC,CAAG,CAAC,CAC9C,QAAQ,CACR,SAAS,CAAE,aAAa,CACxB,OAAO,CACP,aAAa,CACb,YAAY,CACZ,WAAW,CACX,YAAY,CACZ,SAAS,CAAG,UAAU,CAAC,YAAY,CACnC,GAAG,CACH,KAAK,CACL,KAAK,CACL,GAAG,CACH,GAAG,cACL,CAAC,GAAK,CACJ,KAAM,OAAM,CAAG,QAAQ,CAAC,aAAa,CAAE,YAAY,CAAE,KAAK,CAAC,CAE3D,KAAM,CAAC,IAAI,CAAE,OAAO,CAAC,CAAG,QAAQ,CAAQ,CACtC,WAAW,CAAE,CAAC,CACd,WAAW,CAAE,CAAC,CACd,OAAO,CAAE,SAAS,CAClB,gBAAgB,CAAE,KACpB,CAAC,CAAC,CAEF,KAAM,WAAU,CAAG,MAAM,CAAc,IAAI,CAAC,CAC5C,KAAM,WAAU,CAAG,MAAM,CAAiB,IAAI,CAAC,CAC/C,KAAM,CAAC,WAAW,CAAE,cAAc,CAAC,CAAG,QAAQ,CAAC,KAAK,CAAC,CAErD,KAAM,qBAAoB,CAAG,CAAC,OAAe,CAAE,OAAe,GAAK,CACjE,GAAI,WAAW,CAAE,CACf,KAAM,YAAW,CAAG,UAAU,CAAC,OAAO,CAAE,qBAAqB,CAAC,CAAC,CAC/D,GACE,OAAO,CAAG,WAAW,CAAC,IAAI,EACvB,OAAO,CAAG,WAAW,CAAC,KAAK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]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\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 ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\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 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 WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n if (!wrapperRef.current) throw Error('Missing reference');\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 } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\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 (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\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 setHeap((prev) => {\n if (!wrapperRef.current) throw Error('Missing reference');\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper ?? '';\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEM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IAAI,CAET,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,EAAU,CAAG,WAAsB,CAEzC,CAAC,CAAC,UAAU,CAAG,UAAU,CAEzB,cAAe,EAAC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import _pushInstanceProperty from"core-js-pure/stable/instance/push.js";import{c as _c}from"react/compiler-runtime";import{useImperativeHandle,useRef}from"react";import{BaseModal}from"../../../Modal/index.js";import{optionValueName}from"../../common.js";const S={"overlay":"ntZ5My"};import{jsx as _jsx}from"react/jsx-runtime";export function areEqual(a,b){return a?.left===b?.left&&a?.top===b?.top&&a?.width===b?.width;}const Options=t0=>{const $=_c(16);const{containerClass,containerStyle,filter,onCancel,onChange,optionClass,options,ref}=t0;const opsRef=useRef(null);let t1;let t2;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=()=>({measure:()=>{const e=opsRef.current?.parentElement;if(!e){return;}const rect=opsRef.current.getBoundingClientRect();const style=window.getComputedStyle(e);const mBottom=parseFloat(style.marginBottom);const mTop=parseFloat(style.marginTop);rect.height=rect.height+(mBottom+mTop);return rect;}});t2=[];$[0]=t1;$[1]=t2;}else{t1=$[0];t2=$[1];}useImperativeHandle(ref,t1,t2);let optionNodes;if($[2]!==filter||$[3]!==onChange||$[4]!==optionClass||$[5]!==options){optionNodes=[];for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);_pushInstanceProperty(optionNodes).call(optionNodes,/*#__PURE__*/_jsx("div",{className:optionClass,onClick:e_0=>{onChange(iValue);e_0.stopPropagation();},onKeyDown:e_1=>{if(e_1.key==="Enter"){onChange(iValue);e_1.stopPropagation();}},role:"button",tabIndex:0,children:iName},iValue));}}$[2]=filter;$[3]=onChange;$[4]=optionClass;$[5]=options;$[6]=optionNodes;}else{optionNodes=$[6];}let t3;if($[7]!==containerClass){t3={ad:"",container:containerClass,context:"",hoc:"",overlay:S.overlay};$[7]=containerClass;$[8]=t3;}else{t3=$[8];}let t4;if($[9]!==optionNodes){t4=/*#__PURE__*/_jsx("div",{ref:opsRef,children:optionNodes});$[9]=optionNodes;$[10]=t4;}else{t4=$[10];}let t5;if($[11]!==containerStyle||$[12]!==onCancel||$[13]!==t3||$[14]!==t4){t5=/*#__PURE__*/_jsx(BaseModal,{cancelOnScrolling:true,dontDisableScrolling:true,onCancel:onCancel,style:containerStyle,theme:t3,children:t4});$[11]=containerStyle;$[12]=onCancel;$[13]=t3;$[14]=t4;$[15]=t5;}else{t5=$[15];}return t5;};export default Options;
1
+ import"core-js/modules/es.iterator.filter.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";import{c as _c}from"react/compiler-runtime";import{useImperativeHandle,useRef}from"react";import{BaseModal}from"../../../Modal/index.js";import{optionValueName}from"../../common.js";const S={"overlay":"ntZ5My"};import{jsx as _jsx}from"react/jsx-runtime";export function areEqual(a,b){return a?.left===b?.left&&a?.top===b?.top&&a?.width===b?.width;}const Options=t0=>{const $=_c(16);const{containerClass,containerStyle,filter,onCancel,onChange,optionClass,options,ref}=t0;const opsRef=useRef(null);let t1;let t2;if($[0]===Symbol.for("react.memo_cache_sentinel")){t1=()=>({measure:()=>{const e=opsRef.current?.parentElement;if(!e){return;}if(!opsRef.current){throw Error("Missing reference");}const rect=opsRef.current.getBoundingClientRect();const style=window.getComputedStyle(e);const mBottom=parseFloat(style.marginBottom);const mTop=parseFloat(style.marginTop);rect.height=rect.height+(mBottom+mTop);return rect;}});t2=[];$[0]=t1;$[1]=t2;}else{t1=$[0];t2=$[1];}useImperativeHandle(ref,t1,t2);let optionNodes;if($[2]!==filter||$[3]!==onChange||$[4]!==optionClass||$[5]!==options){optionNodes=[];for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);optionNodes.push(/*#__PURE__*/_jsx("div",{className:optionClass,onClick:e_0=>{onChange(iValue);e_0.stopPropagation();},onKeyDown:e_1=>{if(e_1.key==="Enter"){onChange(iValue);e_1.stopPropagation();}},role:"button",tabIndex:0,children:iName},iValue));}}$[2]=filter;$[3]=onChange;$[4]=optionClass;$[5]=options;$[6]=optionNodes;}else{optionNodes=$[6];}let t3;if($[7]!==containerClass){t3={ad:"",container:containerClass,context:"",hoc:"",overlay:S.overlay};$[7]=containerClass;$[8]=t3;}else{t3=$[8];}let t4;if($[9]!==optionNodes){t4=/*#__PURE__*/_jsx("div",{ref:opsRef,children:optionNodes});$[9]=optionNodes;$[10]=t4;}else{t4=$[10];}let t5;if($[11]!==containerStyle||$[12]!==onCancel||$[13]!==t3||$[14]!==t4){t5=/*#__PURE__*/_jsx(BaseModal,{cancelOnScrolling:true,dontDisableScrolling:true,onCancel:onCancel,style:containerStyle,theme:t3,children:t4});$[11]=containerStyle;$[12]=onCancel;$[13]=t3;$[14]=t4;$[15]=t5;}else{t5=$[15];}return t5;};export default Options;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":"oHAAA,OAIE,mBAAmB,CACnB,MAAM,KACD,OAAO,CAAC,OAEN,SAAS,sCAMhB,eAAe,uBAGjB,6BAA6B,2CAQ7B,MAAO,SAAS,SAAQ,CAAC,CAAiB,CAAE,CAAiB,CAAW,CACtE,MAAO,EAAC,EAAE,IAAI,GAAK,CAAC,EAAE,IAAI,EAAI,CAAC,EAAE,GAAG,GAAK,CAAC,EAAE,GAAG,EAAI,CAAC,EAAE,KAAK,GAAK,CAAC,EAAE,KAAK,CAC1E,CAiBA,KAAM,QA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CAAd,cAAc,CACd,KAMN,CANM,EAMN,UAED,EAAqC,CAC5B,CAAC,sFAnBZ,GAmBY,EAEf,CAED,cAAe,QAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n if (!opsRef.current) throw Error('Missing reference');\n const rect = opsRef.current.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":"oOAAA,OAIE,mBAAmB,CACnB,MAAM,KACD,OAAO,CAAC,OAEN,SAAS,sCAMhB,eAAe,uBAGjB,6BAA6B,2CAQ7B,MAAO,SAAS,SAAQ,CAAC,CAAiB,CAAE,CAAiB,CAAW,CACtE,MAAO,EAAC,EAAE,IAAI,GAAK,CAAC,EAAE,IAAI,EAAI,CAAC,EAAE,GAAG,GAAK,CAAC,EAAE,GAAG,EAAI,CAAC,EAAE,KAAK,GAAK,CAAC,EAAE,KAAK,CAC1E,CAiBA,KAAM,QAAkC,CAAG,oBAAC,wFAS3C,CACC,aAAe,MAAM,CAAiB,IAAI,CAAC,CAAC,iEAEnB,QAAO,SACrB,KACP,QAAU,MAAM,QAAuB,gBACvC,GAAI,CAAC,CAAC,UAEN,GAAI,CAAC,MAAM,QAAQ,EAAE,KAAM,MAAK,CAAC,mBAAmB,CAAC,CAAC,CACtD,WAAa,MAAM,QAAQ,sBAAsB,CAAC,CAAC,CACnD,YAAc,MAAM,iBAAiB,CAAC,CAAC,CAAC,CACxC,cAAgB,UAAU,CAAC,KAAK,aAAa,CAAC,CAC9C,WAAa,UAAU,CAAC,KAAK,UAAU,CAAC,CAExC,IAAI,QAAJ,IAAI,OAAO,EAAI,OAAO,CAAG,IAAI,CAAlB,OAEJ,KAAI,EAEf,CAAC,CAAC,CAAE,KAAE,wCAfN,mBAAmB,CAAC,GAAG,CAAE,EAevB,CAAE,EAAE,CAAC,wFAEP,YAAiC,EAAE,CACnC,IAAK,YAAY,GAAI,QAAO,EAC1B,GAAI,CAAC,MAAwB,EAAd,MAAM,CAAC,MAAM,CAAC,EAC3B,oBAAwB,eAAe,CAAC,MAAM,CAAC,CAC/C,WAAW,KAAK,cACd,YACa,SAAW,CAAX,WAAW,CAEb,OAGR,CAHQ,MACP,QAAQ,CAAC,MAAM,CAAC,CAChB,GAAC,gBAAgB,CAAC,CAAC,EACpB,CACU,SAKV,CALU,MACT,GAAI,GAAC,IAAI,GAAK,OAAO,EACnB,QAAQ,CAAC,MAAM,CAAC,CAChB,GAAC,gBAAgB,CAAC,CAAC,EACpB,CACF,CACI,IAAQ,CAAR,QAAQ,CACH,QAAC,CAAD,CAAC,UAEV,KAAK,EAdD,MAeF,CACP,CAAC,EACF,CACF,kIAaU,OACD,EAAE,WACK,cAAc,SAChB,EAAE,KACN,EAAE,SACE,CAAC,QACZ,CAAC,0EAED,4BAAU,GAAM,CAAN,MAAM,UAAG,WAAW,CAAM,CAAC,uHAlBvC,qBAAC,SAAS,EAMR,iBAAiB,CAAjB,IAAiB,CACjB,oBAAoB,CAApB,IAAoB,CACV,QAAQ,CAAR,QAAQ,CACX,KAAc,CAAd,cAAc,CACd,KAMN,CANM,EAMN,UAED,EAAqC,CAC5B,CAAC,sFAnBZ,GAmBY,EAEf,CAED,cAAe,QAAO","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import{c as _c}from"react/compiler-runtime";import{useEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";import Options,{areEqual}from"./Options/index.js";const defaultTheme={"context":"SNj3wp","ad":"T6eOJ-","hoc":"KG-OKN","container":"SzHHPE","label":"KTG4ai","dropdown":"xdotm7","option":"y-WCDM","select":"PP5Siy","arrow":"_7-A7Lh","active":"RoOAZK","upward":"_--5Xpy"};import{Fragment as _Fragment,jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CustomDropdown=t0=>{const $=_c(31);const{filter,label,onChange,options,theme,value}=t0;const custom=useTheme("CustomDropdown",defaultTheme,theme);const[active,setActive]=useState(false);const dropdownRef=useRef(null);const opsRef=useRef(null);const[opsPos,setOpsPos]=useState();const[upward,setUpward]=useState(false);let t1;let t2;if($[0]!==active){t1=()=>{if(!active){return;}let id;const cb=()=>{const anchor=dropdownRef.current?.getBoundingClientRect();const opsRect=opsRef.current?.measure();if(anchor&&opsRect){const fitsDown=anchor.bottom+opsRect.height<(window.visualViewport?.height??0);const fitsUp=anchor.top-opsRect.height>0;const up=!fitsDown&&fitsUp;setUpward(up);const pos=up?{left:anchor.left,top:anchor.top-opsRect.height-1,width:anchor.width}:{left:anchor.left,top:anchor.bottom,width:anchor.width};setOpsPos(now=>areEqual(now,pos)?now:pos);}id=requestAnimationFrame(cb);};requestAnimationFrame(cb);return()=>{cancelAnimationFrame(id);};};t2=[active];$[0]=active;$[1]=t1;$[2]=t2;}else{t1=$[1];t2=$[2];}useEffect(t1,t2);let t3;if($[3]===Symbol.for("react.memo_cache_sentinel")){t3=e=>{const view=window.visualViewport;const rect=dropdownRef.current.getBoundingClientRect();setActive(true);setOpsPos({left:view?.width??0,top:view?.height??0,width:rect.width});e.stopPropagation();};$[3]=t3;}else{t3=$[3];}const openList=t3;let t4;if($[4]===Symbol.for("react.memo_cache_sentinel")){t4=/*#__PURE__*/_jsx(_Fragment,{children:"‌"});$[4]=t4;}else{t4=$[4];}let selected=t4;if($[5]!==filter||$[6]!==options||$[7]!==value){for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);if(iValue===value){selected=iName;break;}}}$[5]=filter;$[6]=options;$[7]=value;$[8]=selected;}else{selected=$[8];}let containerClassName=custom.container;if(active){containerClassName=containerClassName+` ${custom.active}`;}let opsContainerClass=custom.select??"";if(upward){containerClassName=containerClassName+` ${custom.upward}`;opsContainerClass=opsContainerClass+` ${custom.upward}`;}let t5;if($[9]!==custom.label||$[10]!==label){t5=label===undefined?null:/*#__PURE__*/_jsx("div",{className:custom.label,children:label});$[9]=custom.label;$[10]=label;$[11]=t5;}else{t5=$[11];}let t6;if($[12]===Symbol.for("react.memo_cache_sentinel")){t6=e_0=>{if(e_0.key==="Enter"){openList(e_0);}};$[12]=t6;}else{t6=$[12];}let t7;if($[13]!==custom.arrow){t7=/*#__PURE__*/_jsx("div",{className:custom.arrow});$[13]=custom.arrow;$[14]=t7;}else{t7=$[14];}let t8;if($[15]!==custom.dropdown||$[16]!==selected||$[17]!==t7){t8=/*#__PURE__*/_jsxs("div",{className:custom.dropdown,onClick:openList,onKeyDown:t6,ref:dropdownRef,role:"listbox",tabIndex:0,children:[selected,t7]});$[15]=custom.dropdown;$[16]=selected;$[17]=t7;$[18]=t8;}else{t8=$[18];}let t9;if($[19]!==active||$[20]!==custom.option||$[21]!==onChange||$[22]!==opsContainerClass||$[23]!==opsPos||$[24]!==options){t9=active?/*#__PURE__*/_jsx(Options,{containerClass:opsContainerClass,containerStyle:opsPos,onCancel:()=>{setActive(false);},onChange:newValue=>{setActive(false);if(onChange){onChange(newValue);}},optionClass:custom.option??"",options:options,ref:opsRef}):null;$[19]=active;$[20]=custom.option;$[21]=onChange;$[22]=opsContainerClass;$[23]=opsPos;$[24]=options;$[25]=t9;}else{t9=$[25];}let t10;if($[26]!==containerClassName||$[27]!==t5||$[28]!==t8||$[29]!==t9){t10=/*#__PURE__*/_jsxs("div",{className:containerClassName,children:[t5,t8,t9]});$[26]=containerClassName;$[27]=t5;$[28]=t8;$[29]=t9;$[30]=t10;}else{t10=$[30];}return t10;};export default CustomDropdown;
1
+ import"core-js/modules/es.iterator.filter.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";import{c as _c}from"react/compiler-runtime";import{useEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";import Options,{areEqual}from"./Options/index.js";const defaultTheme={"context":"SNj3wp","ad":"T6eOJ-","hoc":"KG-OKN","container":"SzHHPE","label":"KTG4ai","dropdown":"xdotm7","option":"y-WCDM","select":"PP5Siy","arrow":"_7-A7Lh","active":"RoOAZK","upward":"_--5Xpy"};import{Fragment as _Fragment,jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const CustomDropdown=t0=>{const $=_c(31);const{filter,label,onChange,options,theme,value}=t0;const custom=useTheme("CustomDropdown",defaultTheme,theme);const[active,setActive]=useState(false);const dropdownRef=useRef(null);const opsRef=useRef(null);const[opsPos,setOpsPos]=useState();const[upward,setUpward]=useState(false);let t1;let t2;if($[0]!==active){t1=()=>{if(!active){return;}let id;const cb=()=>{const anchor=dropdownRef.current?.getBoundingClientRect();const opsRect=opsRef.current?.measure();if(anchor&&opsRect){const fitsDown=anchor.bottom+opsRect.height<(window.visualViewport?.height??0);const fitsUp=anchor.top-opsRect.height>0;const up=!fitsDown&&fitsUp;setUpward(up);const pos=up?{left:anchor.left,top:anchor.top-opsRect.height-1,width:anchor.width}:{left:anchor.left,top:anchor.bottom,width:anchor.width};setOpsPos(now=>areEqual(now,pos)?now:pos);}id=requestAnimationFrame(cb);};requestAnimationFrame(cb);return()=>{cancelAnimationFrame(id);};};t2=[active];$[0]=active;$[1]=t1;$[2]=t2;}else{t1=$[1];t2=$[2];}useEffect(t1,t2);let t3;if($[3]===Symbol.for("react.memo_cache_sentinel")){t3=e=>{const view=window.visualViewport;if(!dropdownRef.current){throw Error("Missing dropdown reference");}const rect=dropdownRef.current.getBoundingClientRect();setActive(true);setOpsPos({left:view?.width??0,top:view?.height??0,width:rect.width});e.stopPropagation();};$[3]=t3;}else{t3=$[3];}const openList=t3;let t4;if($[4]===Symbol.for("react.memo_cache_sentinel")){t4=/*#__PURE__*/_jsx(_Fragment,{children:"‌"});$[4]=t4;}else{t4=$[4];}let selected=t4;if($[5]!==filter||$[6]!==options||$[7]!==value){for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);if(iValue===value){selected=iName;break;}}}$[5]=filter;$[6]=options;$[7]=value;$[8]=selected;}else{selected=$[8];}let containerClassName=custom.container??"";if(active){containerClassName=containerClassName+` ${custom.active??""}`;}let opsContainerClass=custom.select??"";if(upward){containerClassName=containerClassName+` ${custom.upward??""}`;opsContainerClass=opsContainerClass+` ${custom.upward??""}`;}let t5;if($[9]!==custom.label||$[10]!==label){t5=label===undefined?null:/*#__PURE__*/_jsx("div",{className:custom.label,children:label});$[9]=custom.label;$[10]=label;$[11]=t5;}else{t5=$[11];}let t6;if($[12]===Symbol.for("react.memo_cache_sentinel")){t6=e_0=>{if(e_0.key==="Enter"){openList(e_0);}};$[12]=t6;}else{t6=$[12];}let t7;if($[13]!==custom.arrow){t7=/*#__PURE__*/_jsx("div",{className:custom.arrow});$[13]=custom.arrow;$[14]=t7;}else{t7=$[14];}let t8;if($[15]!==custom.dropdown||$[16]!==selected||$[17]!==t7){t8=/*#__PURE__*/_jsxs("div",{className:custom.dropdown,onClick:openList,onKeyDown:t6,ref:dropdownRef,role:"listbox",tabIndex:0,children:[selected,t7]});$[15]=custom.dropdown;$[16]=selected;$[17]=t7;$[18]=t8;}else{t8=$[18];}let t9;if($[19]!==active||$[20]!==custom.option||$[21]!==onChange||$[22]!==opsContainerClass||$[23]!==opsPos||$[24]!==options){t9=active?/*#__PURE__*/_jsx(Options,{containerClass:opsContainerClass,containerStyle:opsPos,onCancel:()=>{setActive(false);},onChange:newValue=>{setActive(false);if(onChange){onChange(newValue);}},optionClass:custom.option??"",options:options,ref:opsRef}):null;$[19]=active;$[20]=custom.option;$[21]=onChange;$[22]=opsContainerClass;$[23]=opsPos;$[24]=options;$[25]=t9;}else{t9=$[25];}let t10;if($[26]!==containerClassName||$[27]!==t5||$[28]!==t8||$[29]!==t9){t10=/*#__PURE__*/_jsxs("div",{className:containerClassName,children:[t5,t8,t9]});$[26]=containerClassName;$[27]=t5;$[28]=t8;$[29]=t9;$[30]=t10;}else{t10=$[30];}return t10;};export default CustomDropdown;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container;\n if (active) containerClassName += ` ${custom.active}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward}`;\n opsContainerClass += ` ${custom.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":"4CAAA,OAGE,SAAS,CACT,MAAM,CACN,QAAQ,KACH,OAAO,CAEd,OAAS,QAAQ,KAAQ,0BAA0B,CAAC,OAEjB,eAAe,0BAE3C,QAAO,EAAmC,QAAQ,0BAEzD,0NAAwC,+EAExC,KAAM,eAEL,CAAG,oBAAC,mDAOJ,CACC,aAAe,QAAQ,CAAC,gBAAgB,CAAE,YAAY,CAAE,KAAK,CAAC,CAE9D,wBAA4B,QAAQ,CAAC,KAAK,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QAAQ,CAAC,QAAQ,CAAC,EAAC,CAClC,CACY,WAAmB,CAAnB,MAAM,OAAa,EAAnB,EAAmB,CACvB,OAAO,CAAP,OAAO,CACX,GAAM,CAAN,MAAM,CAER,CAAC,CAfR,IAeQ,wMAhCZ,8BAAgB,SAAkB,CAAlB,kBAAkB,WAC/B,EAC8C,CAC/C,EAYM,CAEJ,EAeQ,EAEP,CAAC,sFAlCN,IAkCM,EAET,CAED,cAAe,eAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n if (!dropdownRef.current) throw Error('Missing dropdown reference');\n const rect = dropdownRef.current.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>&zwnj;</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container ?? '';\n if (active) containerClassName += ` ${custom.active ?? ''}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward ?? ''}`;\n opsContainerClass += ` ${custom.upward ?? ''}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":"2LAAA,OAGE,SAAS,CACT,MAAM,CACN,QAAQ,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,SAAe,CAAf,MAAM,SAAS,CACjB,OAAQ,CAAR,QAAQ,CACN,SAEV,CAFU,EAEV,CACI,GAAW,CAAX,WAAW,CACX,IAAS,CAAT,SAAS,CACJ,QAAC,CAAD,CAAC,WAEV,QAAQ,CACT,EAAgC,EAC7B,CAAC,uMAEJ,SAAM,cAAN,KACG,OAAO,EACU,cAAiB,CAAjB,iBAAiB,CACjB,cAAM,CAAN,MAAM,CACZ,QAET,CAFS,KACR,SAAS,CAAC,KAAK,CAAC,EACjB,CACS,QAGT,CAHS,WACR,SAAS,CAAC,KAAK,CAAC,CAChB,GAAI,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAC,CAClC,CACY,WAAmB,CAAnB,MAAM,OAAa,EAAnB,EAAmB,CACvB,OAAO,CAAP,OAAO,CACX,GAAM,CAAN,MAAM,CAER,CAAC,CAfR,IAeQ,wMAhCZ,8BAAgB,SAAkB,CAAlB,kBAAkB,WAC/B,EAC8C,CAC/C,EAYM,CAEJ,EAeQ,EAEP,CAAC,sFAlCN,IAkCM,EAET,CAED,cAAe,eAAc","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import _pushInstanceProperty from"core-js-pure/stable/instance/push.js";// Implements dropdown based on the native HTML <select> element.
1
+ import"core-js/modules/es.iterator.filter.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.filter.js";// Implements dropdown based on the native HTML <select> element.
2
2
  import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";const defaultTheme={"context":"WbwY1Y","ad":"AP5hsY","hoc":"ODAJeW","dropdown":"wabw76","arrow":"WFSB9z","container":"vE9M8Z","active":"sfLSJA","label":"bQLBhS","option":"wgCtdC","hiddenOption":"ty19C2","select":"ntbzPR","invalid":"_3CzMM4"};/**
3
3
  * Implements a themeable dropdown list. Internally it is rendered with help of
4
4
  * the standard HTML `<select>` element, thus the styling support is somewhat
@@ -17,9 +17,9 @@ import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../co
17
17
  * @param [props.value] Currently selected value.
18
18
  * @param [props....]
19
19
  * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
20
- */import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Dropdown=({filter,label,onChange,onClick,options,testId,theme,value})=>{let isValidValue=false;const optionElements=[];const composed=useTheme("Dropdown",defaultTheme,theme);for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);isValidValue||=iValue===value;_pushInstanceProperty(optionElements).call(optionElements,/*#__PURE__*/_jsx("option",{className:composed.option,value:iValue,children:iName},iValue));}}// NOTE: This element represents the current `value` when it does not match
20
+ */import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Dropdown=({filter,label,onChange,onClick,options,testId,theme,value})=>{let isValidValue=false;const optionElements=[];const composed=useTheme("Dropdown",defaultTheme,theme);for(const option of options){if(!filter||filter(option)){const[iValue,iName]=optionValueName(option);isValidValue||=iValue===value;optionElements.push(/*#__PURE__*/_jsx("option",{className:composed.option,value:iValue,children:iName},iValue));}}// NOTE: This element represents the current `value` when it does not match
21
21
  // any valid option. In Chrome, and some other browsers, we are able to hide
22
22
  // it from the opened dropdown; in others, e.g. Safari, the best we can do is
23
23
  // to show it as disabled.
24
- const hiddenOption=isValidValue?null:/*#__PURE__*/_jsx("option",{className:composed.hiddenOption,disabled:true,value:value,children:value},"__reactUtilsHiddenOption");let selectClassName=composed.select;if(!isValidValue)selectClassName+=` ${composed.invalid}`;return/*#__PURE__*/_jsxs("div",{className:composed.container,children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label}),/*#__PURE__*/_jsxs("div",{className:composed.dropdown,children:[/*#__PURE__*/_jsxs("select",{className:selectClassName,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,onChange:onChange,onClick:onClick,value:value,children:[hiddenOption,optionElements]}),/*#__PURE__*/_jsx("div",{className:composed.arrow})]})]});};export default Dropdown;
24
+ const hiddenOption=isValidValue?null:/*#__PURE__*/_jsx("option",{className:composed.hiddenOption,disabled:true,value:value,children:value},"__reactUtilsHiddenOption");let selectClassName=composed.select??"";if(!isValidValue)selectClassName+=` ${composed.invalid??""}`;return/*#__PURE__*/_jsxs("div",{className:composed.container,children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label}),/*#__PURE__*/_jsxs("div",{className:composed.dropdown,children:[/*#__PURE__*/_jsxs("select",{className:selectClassName,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,onChange:onChange,onClick:onClick,value:value,children:[hiddenOption,optionElements]}),/*#__PURE__*/_jsx("div",{className:composed.arrow})]})]});};export default Dropdown;
25
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n onClick,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select;\n if (!isValidValue) selectClassName += ` ${composed.invalid}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n onClick={onClick}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":"wEAAA;AAIA,OAAS,QAAQ,KAAQ,0BAA0B,CAAC,OAE9B,eAAe,oBAErC,kPAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAlBA,yDAmBA,KAAM,SAA2C,CAAG,CAAC,CACnD,MAAM,CACN,KAAK,CACL,QAAQ,CACR,OAAO,CACP,OAAO,CACP,MAAM,CACN,KAAK,CACL,KACF,CAAC,GAAK,CACJ,GAAI,aAAY,CAAG,KAAK,CACxB,KAAM,eAAc,CAAG,EAAE,CAEzB,KAAM,SAAQ,CAAG,QAAQ,CAAC,UAAU,CAAE,YAAY,CAAE,KAAK,CAAC,CAE1D,IAAK,KAAM,OAAM,GAAI,QAAO,CAAE,CAC5B,GAAI,CAAC,MAAM,EAAI,MAAM,CAAC,MAAM,CAAC,CAAE,CAC7B,KAAM,CAAC,MAAM,CAAE,KAAK,CAAC,CAAG,eAAe,CAAC,MAAM,CAAC,CAC/C,YAAY,GAAK,MAAM,GAAK,KAAK,CACjC,oCAAc,OAAd,cAAc,cACZ,eAAQ,SAAS,CAAE,QAAQ,CAAC,MAAO,CAAc,KAAK,CAAE,MAAO,UAC5D,KAAK,EADiC,MAEjC,CACV,CAAC,CACH,CACF,CAEA;AACA;AACA;AACA;AACA,KAAM,aAAY,CAAG,YAAY,CAAG,IAAI,cACtC,eACE,SAAS,CAAE,QAAQ,CAAC,YAAa,CACjC,QAAQ,MAER,KAAK,CAAE,KAAM,UAEZ,KAAK,EAHF,0BAIE,CACT,CAED,GAAI,gBAAe,CAAG,QAAQ,CAAC,MAAM,CACrC,GAAI,CAAC,YAAY,CAAE,eAAe,EAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,CAE5D,mBACE,aAAK,SAAS,CAAE,QAAQ,CAAC,SAAU,WAC/B,KAAK,GAAK,SAAS,CACjB,IAAI,cAAG,YAAK,SAAS,CAAE,QAAQ,CAAC,KAAM,UAAE,KAAK,CAAM,CAAC,cACxD,aAAK,SAAS,CAAE,QAAQ,CAAC,QAAS,wBAChC,gBACE,SAAS,CAAE,eAAgB,CAC3B,cAAa,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAK,YAAY,CAAG,SAAS,CAAG,MAAO,CACxE,QAAQ,CAAE,QAAS,CACnB,OAAO,CAAE,OAAQ,CACjB,KAAK,CAAE,KAAM,WAEZ,YAAY,CACZ,cAAc,EACT,CAAC,cACT,YAAK,SAAS,CAAE,QAAQ,CAAC,KAAM,CAAE,CAAC,EAC/B,CAAC,EACH,CAAC,CAEV,CAAC,CAED,cAAe,SAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n onClick,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select ?? '';\n if (!isValidValue) selectClassName += ` ${composed.invalid ?? ''}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n onClick={onClick}\n value={value}\n >\n {hiddenOption}\n {optionElements}\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KAAK,GAAK,SAAS,CACjB,IAAI,cAAG,YAAK,SAAS,CAAE,QAAQ,CAAC,KAAM,UAAE,KAAK,CAAM,CAAC,cACxD,aAAK,SAAS,CAAE,QAAQ,CAAC,QAAS,wBAChC,gBACE,SAAS,CAAE,eAAgB,CAC3B,cAAa,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAK,YAAY,CAAG,SAAS,CAAG,MAAO,CACxE,QAAQ,CAAE,QAAS,CACnB,OAAO,CAAE,OAAQ,CACjB,KAAK,CAAE,KAAM,WAEZ,YAAY,CACZ,cAAc,EACT,CAAC,cACT,YAAK,SAAS,CAAE,QAAQ,CAAC,KAAM,CAAE,CAAC,EAC/B,CAAC,EACH,CAAC,CAEV,CAAC,CAED,cAAe,SAAQ","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import _pushInstanceProperty from"core-js-pure/stable/instance/push.js";import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";const defaultTheme={"context":"akD3dQ","ad":"xcXtdE","hoc":"N3iziJ","container":"BYeWyJ","option":"_7MFXEN","selected":"CDbWAd","options":"_9-eOZo"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const Switch=t0=>{const $=_c(16);const{label,onChange,options,theme,value}=t0;const composed=useTheme("Switch",defaultTheme,theme);if(!options||!composed.option){throw Error("Internal error");}let optionNodes;if($[0]!==composed.option||$[1]!==composed.selected||$[2]!==onChange||$[3]!==options||$[4]!==value){optionNodes=[];for(const option of options){const[iValue,iName]=optionValueName(option);let className=composed.option;let onPress;if(iValue===value){className=className+` ${composed.selected}`;}else{if(onChange){onPress=()=>{onChange(iValue);};}}_pushInstanceProperty(optionNodes).call(optionNodes,onPress?/*#__PURE__*/_jsx("div",{className:className,onClick:onPress,onKeyDown:e=>{if(e.key==="Enter"){onPress();}},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/_jsx("div",{className:className,children:iName},iValue));}$[0]=composed.option;$[1]=composed.selected;$[2]=onChange;$[3]=options;$[4]=value;$[5]=optionNodes;}else{optionNodes=$[5];}let t1;if($[6]!==composed.label||$[7]!==label){t1=label?/*#__PURE__*/_jsx("div",{className:composed.label,children:label}):null;$[6]=composed.label;$[7]=label;$[8]=t1;}else{t1=$[8];}let t2;if($[9]!==composed.options||$[10]!==optionNodes){t2=/*#__PURE__*/_jsx("div",{className:composed.options,children:optionNodes});$[9]=composed.options;$[10]=optionNodes;$[11]=t2;}else{t2=$[11];}let t3;if($[12]!==composed.container||$[13]!==t1||$[14]!==t2){t3=/*#__PURE__*/_jsxs("div",{className:composed.container,children:[t1,t2]});$[12]=composed.container;$[13]=t1;$[14]=t2;$[15]=t3;}else{t3=$[15];}return t3;};
1
+ import"core-js/modules/es.array.push.js";import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";const defaultTheme={"context":"akD3dQ","ad":"xcXtdE","hoc":"N3iziJ","container":"BYeWyJ","option":"_7MFXEN","selected":"CDbWAd","options":"_9-eOZo"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const Switch=t0=>{const $=_c(16);const{label,onChange,options,theme,value}=t0;const composed=useTheme("Switch",defaultTheme,theme);if(!options||!composed.option){throw Error("Internal error");}let optionNodes;if($[0]!==composed.option||$[1]!==composed.selected||$[2]!==onChange||$[3]!==options||$[4]!==value){optionNodes=[];for(const option of options){const[iValue,iName]=optionValueName(option);let className=composed.option;let onPress;if(iValue===value){className=className+` ${composed.selected??""}`;}else{if(onChange){onPress=()=>{onChange(iValue);};}}optionNodes.push(onPress?/*#__PURE__*/_jsx("div",{className:className,onClick:onPress,onKeyDown:e=>{if(e.key==="Enter"){onPress();}},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/_jsx("div",{className:className,children:iName},iValue));}$[0]=composed.option;$[1]=composed.selected;$[2]=onChange;$[3]=options;$[4]=value;$[5]=optionNodes;}else{optionNodes=$[5];}let t1;if($[6]!==composed.label||$[7]!==label){t1=label?/*#__PURE__*/_jsx("div",{className:composed.label,children:label}):null;$[6]=composed.label;$[7]=label;$[8]=t1;}else{t1=$[8];}let t2;if($[9]!==composed.options||$[10]!==optionNodes){t2=/*#__PURE__*/_jsx("div",{className:composed.options,children:optionNodes});$[9]=composed.options;$[10]=optionNodes;$[11]=t2;}else{t2=$[11];}let t3;if($[12]!==composed.container||$[13]!==t1||$[14]!==t2){t3=/*#__PURE__*/_jsxs("div",{className:composed.container,children:[t1,t2]});$[12]=composed.container;$[13]=t1;$[14]=t2;$[15]=t3;}else{t3=$[15];}return t3;};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":"oHAEA,OAAqB,QAAQ,KAAQ,0BAA0B,CAAC,OAK9D,eAAe,oBAGjB,qJAAwC,yDAYxC,MAAO,MAAM,OAAiC,CAAG,oBAAC,4CAMjD,CACC,eAAiB,QAAQ,CAAC,QAAQ,CAAE,YAAY,CAAE,KAAK,CAAC,CAExD,GAAI,CAAC,OAA2B,EAA5B,CAAa,QAAQ,OAAO,EAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CAAC,qHAEhE,YAAuC,EAAE,CACzC,IAAK,YAAY,GAAI,QAAO,EAC1B,oBAAwB,eAAe,CAAC,MAAM,CAAC,CAE/C,cAAwB,QAAQ,OAAO,CACnC,YACJ,GAAI,MAAM,GAAK,KAAK,EAAE,mBAAS,CAAI,IAAI,QAAQ,SAAS,EAAE,OACrD,GAAI,QAAQ,EACf,QAAU,KACR,QAAQ,CAAC,MAAM,CAAC,EACjB,CAFM,CAGR,CAED,iCAAW,OAAX,WAAW,CACT,OAAO,cAAP,YAGiB,SAAS,CAAT,SAAS,CAEX,OAAO,CAAP,OAAO,CACL,SAEV,CAFU,IACT,GAAI,CAAC,IAAI,GAAK,OAAO,EAAE,OAAO,CAAC,CAAC,EAAC,CAClC,CACI,IAAQ,CAAR,QAAQ,CACH,QAAC,CAAD,CAAC,UAEV,KAAK,EARD,MAW6C,CAAC,cAfzD,YAeoB,SAAS,CAAT,SAAS,UAAgB,KAAK,EAAd,MAAoB,CAC1D,CAAC,EACF,0KAII,QAAK,cAAL,YAAwB,SAAc,CAAd,QAAQ,MAAM,UAAG,KAAK,CAAa,CAAC,CAA5D,IAA4D,+GAE7D,4BAAgB,SAAgB,CAAhB,QAAQ,QAAQ,UAC7B,WAAW,CACT,CAAC,gIALR,6BAAgB,SAAkB,CAAlB,QAAQ,UAAU,WAC/B,EAA4D,CAE7D,EAEM,EACH,CAAC,2EANN,GAMM,EAET","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected ?? ''}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":"qFAEA,OAAqB,QAAQ,KAAQ,0BAA0B,CAAC,OAK9D,eAAe,oBAGjB,qJAAwC,yDAYxC,MAAO,MAAM,OAAiC,CAAG,oBAAC,4CAMjD,CACC,eAAiB,QAAQ,CAAC,QAAQ,CAAE,YAAY,CAAE,KAAK,CAAC,CAExD,GAAI,CAAC,OAA2B,EAA5B,CAAa,QAAQ,OAAO,EAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CAAC,qHAEhE,YAAuC,EAAE,CACzC,IAAK,YAAY,GAAI,QAAO,EAC1B,oBAAwB,eAAe,CAAC,MAAM,CAAC,CAE/C,cAAwB,QAAQ,OAAO,CACnC,YACJ,GAAI,MAAM,GAAK,KAAK,EAAE,mBAAS,CAAI,IAAI,QAAQ,SAAe,EAAvB,EAAuB,EAAE,OAC3D,GAAI,QAAQ,EACf,QAAU,KACR,QAAQ,CAAC,MAAM,CAAC,EACjB,CAFM,CAGR,CAED,WAAW,KAAK,CACd,OAAO,cAAP,YAGiB,SAAS,CAAT,SAAS,CAEX,OAAO,CAAP,OAAO,CACL,SAEV,CAFU,IACT,GAAI,CAAC,IAAI,GAAK,OAAO,EAAE,OAAO,CAAC,CAAC,EAAC,CAClC,CACI,IAAQ,CAAR,QAAQ,CACH,QAAC,CAAD,CAAC,UAEV,KAAK,EARD,MAW6C,CAAC,cAfzD,YAeoB,SAAS,CAAT,SAAS,UAAgB,KAAK,EAAd,MAAoB,CAC1D,CAAC,EACF,0KAII,QAAK,cAAL,YAAwB,SAAc,CAAd,QAAQ,MAAM,UAAG,KAAK,CAAa,CAAC,CAA5D,IAA4D,+GAE7D,4BAAgB,SAAgB,CAAhB,QAAQ,QAAQ,UAC7B,WAAW,CACT,CAAC,gIALR,6BAAgB,SAAkB,CAAlB,QAAQ,UAAU,WAC/B,EAA4D,CAE7D,EAEM,EACH,CAAC,2EANN,GAMM,EAET","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":[],"sources":["../../../../src/shared/utils/config.ts"],"sourcesContent":["/* global document */\n\nimport { parseCookie } from 'cookie';\n\nimport clientGetInj from '../../client/getInj';\n\nimport { IS_CLIENT_SIDE } from './isomorphy/environment-check';\nimport { requireWeak } from './webpack';\n\ntype ConfigT = Record<string, unknown>;\n\nlet config: ConfigT | Promise<ConfigT> | undefined;\n\n/**\n * Injects CSRF token into config (on client-side only).\n *\n * BEWARE: It mutates the argument, and also returns it as the result,\n * for chaining.\n */\nfunction injectCsrfToken(cfg: ConfigT): ConfigT {\n // The safeguard for \"document\" is necessary because in non-Node environments,\n // like React Native, IS_CLIENT_SIDE is \"true\", however \"document\" and a bunch\n // of other browser-world features are not available.\n if (IS_CLIENT_SIDE && typeof document !== 'undefined') {\n // eslint-disable-next-line no-param-reassign\n cfg.CSRF = parseCookie(document.cookie).csrfToken;\n }\n\n return cfg;\n}\n\nexport function getConfig<T extends ConfigT>(sync: true): T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T {\n if (!config) {\n if (IS_CLIENT_SIDE) {\n const inj = clientGetInj();\n config = inj instanceof Promise\n ? inj.then((injection) => {\n const res = injectCsrfToken(injection.CONFIG ?? {});\n config = res;\n return res;\n })\n : injectCsrfToken(inj.CONFIG ?? {});\n } else {\n const weak = requireWeak<ConfigT>('config');\n if (!weak) throw Error('Internal error');\n config = weak;\n }\n }\n\n if (sync && (config instanceof Promise)) {\n throw Error('The config is not available yet');\n }\n\n return config as T;\n}\n"],"mappings":"AAAA,qBAEA,OAAS,WAAW,KAAQ,QAAQ,CAAC,MAE9B,aAAY,qCAEV,cAAc,+CACd,WAAW,oBAIpB,GAAI,OAA8C,CAElD;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,gBAAe,CAAC,GAAY,CAAW,CAC9C;AACA;AACA;AACA,GAAI,cAAc,EAAI,MAAO,SAAQ,GAAK,WAAW,CAAE,CACrD;AACA,GAAG,CAAC,IAAI,CAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,CACnD,CAEA,MAAO,IAAG,CACZ,CAMA,MAAO,SAAS,UAAS,CAAoB,IAAc,CAAkB,CAC3E,GAAI,CAAC,MAAM,CAAE,CACX,GAAI,cAAc,CAAE,CAClB,KAAM,IAAG,CAAG,YAAY,CAAC,CAAC,CAC1B,MAAM,CAAG,GAAG,WAAY,QAAO,CAC3B,GAAG,CAAC,IAAI,CAAE,SAAS,EAAK,CACxB,KAAM,IAAG,CAAG,eAAe,CAAC,SAAS,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACnD,MAAM,CAAG,GAAG,CACZ,MAAO,IAAG,CACZ,CAAC,CAAC,CACA,eAAe,CAAC,GAAG,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACvC,CAAC,IAAM,CACL,KAAM,KAAI,CAAG,WAAW,CAAU,QAAQ,CAAC,CAC3C,GAAI,CAAC,IAAI,CAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CACxC,MAAM,CAAG,IAAI,CACf,CACF,CAEA,GAAI,IAAI,EAAK,MAAM,WAAY,QAAQ,CAAE,CACvC,KAAM,MAAK,CAAC,iCAAiC,CAAC,CAChD,CAEA,MAAO,OAAM,CACf","ignoreList":[]}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../../src/shared/utils/config.ts"],"sourcesContent":["/* global document */\n\nimport { parseCookie } from 'cookie';\n\nimport clientGetInj from '../../client/getInj';\n\nimport { IS_CLIENT_SIDE } from './isomorphy/environment-check';\nimport { requireWeak } from './webpack';\n\ntype ConfigT = Record<string, unknown>;\n\nlet config: ConfigT | Promise<ConfigT> | undefined;\n\n/**\n * Injects CSRF token into config (on client-side only).\n *\n * BEWARE: It mutates the argument, and also returns it as the result,\n * for chaining.\n */\nfunction injectCsrfToken(cfg: ConfigT): ConfigT {\n // The safeguard for \"document\" is necessary because in non-Node environments,\n // like React Native, IS_CLIENT_SIDE is \"true\", however \"document\" and a bunch\n // of other browser-world features are not available.\n if (IS_CLIENT_SIDE && typeof document !== 'undefined') {\n // eslint-disable-next-line no-param-reassign\n cfg.CSRF = parseCookie(document.cookie).csrfToken;\n }\n\n return cfg;\n}\n\nexport function getConfig(sync: true): ConfigT;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T {\n if (!config) {\n if (IS_CLIENT_SIDE) {\n const inj = clientGetInj();\n config = inj instanceof Promise\n ? inj.then((injection) => {\n const res = injectCsrfToken(injection.CONFIG ?? {});\n config = res;\n return res;\n })\n : injectCsrfToken(inj.CONFIG ?? {});\n } else {\n const weak = requireWeak<ConfigT>('config');\n if (!weak) throw Error('Internal error');\n config = weak;\n }\n }\n\n if (sync && (config instanceof Promise)) {\n throw Error('The config is not available yet');\n }\n\n return config as T;\n}\n"],"mappings":"AAAA,qBAEA,OAAS,WAAW,KAAQ,QAAQ,CAAC,MAE9B,aAAY,qCAEV,cAAc,+CACd,WAAW,oBAIpB,GAAI,OAA8C,CAElD;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,gBAAe,CAAC,GAAY,CAAW,CAC9C;AACA;AACA;AACA,GAAI,cAAc,EAAI,MAAO,SAAQ,GAAK,WAAW,CAAE,CACrD;AACA,GAAG,CAAC,IAAI,CAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,CACnD,CAEA,MAAO,IAAG,CACZ,CAMA,MAAO,SAAS,UAAS,CAAoB,IAAc,CAAkB,CAC3E,GAAI,CAAC,MAAM,CAAE,CACX,GAAI,cAAc,CAAE,CAClB,KAAM,IAAG,CAAG,YAAY,CAAC,CAAC,CAC1B,MAAM,CAAG,GAAG,WAAY,QAAO,CAC3B,GAAG,CAAC,IAAI,CAAE,SAAS,EAAK,CACxB,KAAM,IAAG,CAAG,eAAe,CAAC,SAAS,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACnD,MAAM,CAAG,GAAG,CACZ,MAAO,IAAG,CACZ,CAAC,CAAC,CACA,eAAe,CAAC,GAAG,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACvC,CAAC,IAAM,CACL,KAAM,KAAI,CAAG,WAAW,CAAU,QAAQ,CAAC,CAC3C,GAAI,CAAC,IAAI,CAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CACxC,MAAM,CAAG,IAAI,CACf,CACF,CAEA,GAAI,IAAI,EAAK,MAAM,WAAY,QAAQ,CAAE,CACvC,KAAM,MAAK,CAAC,iCAAiC,CAAC,CAChD,CAEA,MAAO,OAAM,CACf","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import _JSON$parse from"core-js-pure/stable/json/parse.js";/**
1
+ import"core-js/modules/es.json.parse.js";/**
2
2
  * Jest environment for end-to-end SSR and client-side testing. It relies on
3
3
  * the standard react-utils mechanics to execute SSR of given scene, and also
4
4
  * Webpack build of the code for client-side execution, it further exposes
@@ -19,7 +19,7 @@ import _JSON$parse from"core-js-pure/stable/json/parse.js";/**
19
19
  }throw Error(`Module "${module}" was not found, neither as TS, nor as JS`);}export default class E2eSsrEnv extends JsdomEnv{pragmas;ssrRequest;rootDir;testFolder;withSsr;webpackStats;/**
20
20
  * Loads Webpack config, and exposes it to the environment via global
21
21
  * webpackConfig object.
22
- */async loadWebpackConfig(){const optionsString=this.pragmas["webpack-config-options"];const options=optionsString?_JSON$parse(optionsString):{};defaults(options,{context:this.testFolder,fs:this.global.webpackOutputFs});const factoryPath=this.pragmas["webpack-config-factory"];let factory=await import(/* webpackChunkName: "not-a-valid-chunk" */path.resolve(this.rootDir,factoryPath));factory="default"in factory?factory.default:factory;this.global.webpackConfig=factory(options);const fs=this.global.webpackOutputFs;let buildInfo=`${options.context}/.build-info`;if(fs.existsSync(buildInfo)){buildInfo=fs.readFileSync(buildInfo,"utf8");this.global.buildInfo=_JSON$parse(buildInfo);}}/**
22
+ */async loadWebpackConfig(){const optionsString=this.pragmas["webpack-config-options"];const options=optionsString?JSON.parse(optionsString):{};defaults(options,{context:this.testFolder,fs:this.global.webpackOutputFs});const factoryPath=this.pragmas["webpack-config-factory"];let factory=await import(/* webpackChunkName: "not-a-valid-chunk" */path.resolve(this.rootDir,factoryPath));factory="default"in factory?factory.default:factory;this.global.webpackConfig=factory(options);const fs=this.global.webpackOutputFs;if(!options.context)throw Error("Missing context");let buildInfo=`${options.context}/.build-info`;if(fs.existsSync(buildInfo)){buildInfo=fs.readFileSync(buildInfo,"utf8");this.global.buildInfo=JSON.parse(buildInfo);}}/**
23
23
  * Executes Webpack build.
24
24
  * @return {Promise}
25
25
  */async runWebpack(){await this.loadWebpackConfig();if(!this.global.webpackConfig)throw Error("Failed to load Webpack config");const compiler=webpack(this.global.webpackConfig);// TODO: The "as typeof compiler.outputFileSystem" piece below is
@@ -34,7 +34,7 @@ this.webpackStats=stats;done();});});}async runSsr(){// NOTE: This is a TS modul
34
34
  // on it for the forked NodeJS process, we need to resolve the correct
35
35
  // extention ourselves (as NodeJS will hit the given path, without any
36
36
  // additional resolutions / transformations).
37
- const ssrModulePath=await findModule(`${import.meta.dirname}/ssr-preload`);const cp=fork(ssrModulePath);const optionsString=this.pragmas["ssr-options"];const options=optionsString?_JSON$parse(optionsString):{};options.buildInfo??=this.global.buildInfo;if(!this.webpackStats)throw Error("Missing Webpack stats");options.chunkGroups=deduceChunkGroups(this.webpackStats);return new Promise((resolve,reject)=>{cp.on("exit",code=>{if(code)reject(Error("SSR process crashed"));});cp.on("message",message=>{this.global.ssrMarkup=message.markup;this.global.ssrOptions=options;this.global.ssrStatus=message.status;cp.kill();resolve();});if(!this.global.webpackConfig)throw Error("Missing Webpack config");cp.send({options,root:options.root==="TEST"?this.testFolder:process.cwd(),ssrRequest:this.ssrRequest,testFolder:this.testFolder,webpackConfig:this.global.webpackConfig});});}constructor(config,context){const pragmas=context.docblockPragmas;const requestString=pragmas["ssr-request"];const request=requestString?_JSON$parse(requestString):{};request.url??="/";// This ensures the initial JsDom URL matches the value we use for SSR.
37
+ const ssrModulePath=await findModule(`${import.meta.dirname}/ssr-preload`);const cp=fork(ssrModulePath);const optionsString=this.pragmas["ssr-options"];const options=optionsString?JSON.parse(optionsString):{};options.buildInfo??=this.global.buildInfo;if(!this.webpackStats)throw Error("Missing Webpack stats");options.chunkGroups=deduceChunkGroups(this.webpackStats);return new Promise((resolve,reject)=>{cp.on("exit",code=>{if(code)reject(Error("SSR process crashed"));});cp.on("message",message=>{this.global.ssrMarkup=message.markup;this.global.ssrOptions=options;this.global.ssrStatus=message.status;cp.kill();resolve();});if(!this.global.webpackConfig)throw Error("Missing Webpack config");cp.send({options,root:options.root==="TEST"?this.testFolder:process.cwd(),ssrRequest:this.ssrRequest,testFolder:this.testFolder,webpackConfig:this.global.webpackConfig});});}constructor(config,context){const pragmas=context.docblockPragmas;const requestString=pragmas["ssr-request"];const request=requestString?JSON.parse(requestString):{};request.url??="/";// This ensures the initial JsDom URL matches the value we use for SSR.
38
38
  set(config.projectConfig,"testEnvironmentOptions.url",`http://localhost${request.url}`);super(config,context);this.global.dom=this.dom;this.global.webpackOutputFs=createFsFromVolume(new Volume);// Extracts necessary settings from config and context.
39
39
  const{projectConfig}=config;this.rootDir=projectConfig.rootDir;this.testFolder=path.dirname(context.testPath);this.withSsr=!pragmas["no-ssr"];this.ssrRequest=request;this.pragmas=pragmas;// BEWARE: Anything imported prior to this register() call seems to be
40
40
  // transpiled again by Babel if loaded after this call. This causes very