@dr.pogodin/react-utils 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/build/development/server/Cache.js +7 -7
  2. package/build/development/server/Cache.js.map +1 -1
  3. package/build/development/server/index.js +6 -3
  4. package/build/development/server/index.js.map +1 -1
  5. package/build/development/server/renderer.js +18 -7
  6. package/build/development/server/renderer.js.map +1 -1
  7. package/build/development/server/server.js +12 -6
  8. package/build/development/server/server.js.map +1 -1
  9. package/build/development/server/utils/errors.js +10 -10
  10. package/build/development/server/utils/errors.js.map +1 -1
  11. package/build/development/shared/components/Button/index.js +1 -1
  12. package/build/development/shared/components/Button/index.js.map +1 -1
  13. package/build/development/shared/components/Checkbox/index.js +5 -5
  14. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  15. package/build/development/shared/components/Input/index.js +3 -3
  16. package/build/development/shared/components/Input/index.js.map +1 -1
  17. package/build/development/shared/components/Modal/index.js +3 -0
  18. package/build/development/shared/components/Modal/index.js.map +1 -1
  19. package/build/development/shared/components/TextArea/index.js +3 -3
  20. package/build/development/shared/components/TextArea/index.js.map +1 -1
  21. package/build/development/shared/components/WithTooltip/Tooltip.js +2 -2
  22. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  23. package/build/development/shared/components/WithTooltip/index.js +3 -1
  24. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  25. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +4 -1
  26. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  27. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -4
  28. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/NativeDropdown/index.js +3 -3
  30. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/Switch/index.js +2 -2
  32. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  33. package/build/development/shared/utils/config.js.map +1 -1
  34. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +7 -6
  35. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  36. package/build/development/shared/utils/jest/index.js +2 -1
  37. package/build/development/shared/utils/jest/index.js.map +1 -1
  38. package/build/development/shared/utils/splitComponent.js +10 -8
  39. package/build/development/shared/utils/splitComponent.js.map +1 -1
  40. package/build/development/shared/utils/webpack.js +2 -1
  41. package/build/development/shared/utils/webpack.js.map +1 -1
  42. package/build/production/server/Cache.js +3 -3
  43. package/build/production/server/Cache.js.map +1 -1
  44. package/build/production/server/index.js +1 -1
  45. package/build/production/server/index.js.map +1 -1
  46. package/build/production/server/renderer.js +9 -9
  47. package/build/production/server/renderer.js.map +1 -1
  48. package/build/production/server/server.js +6 -6
  49. package/build/production/server/server.js.map +1 -1
  50. package/build/production/server/utils/errors.js +1 -1
  51. package/build/production/server/utils/errors.js.map +1 -1
  52. package/build/production/shared/components/Button/index.js +1 -1
  53. package/build/production/shared/components/Button/index.js.map +1 -1
  54. package/build/production/shared/components/Checkbox/index.js +1 -1
  55. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  56. package/build/production/shared/components/Input/index.js +1 -1
  57. package/build/production/shared/components/Input/index.js.map +1 -1
  58. package/build/production/shared/components/Modal/index.js +1 -1
  59. package/build/production/shared/components/Modal/index.js.map +1 -1
  60. package/build/production/shared/components/TextArea/index.js +1 -1
  61. package/build/production/shared/components/TextArea/index.js.map +1 -1
  62. package/build/production/shared/components/WithTooltip/Tooltip.js +1 -1
  63. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  64. package/build/production/shared/components/WithTooltip/index.js +2 -2
  65. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  66. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  67. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  68. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  69. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  70. package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
  71. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  72. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  73. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  74. package/build/production/shared/utils/config.js.map +1 -1
  75. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +2 -2
  76. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  77. package/build/production/shared/utils/jest/index.js +2 -2
  78. package/build/production/shared/utils/jest/index.js.map +1 -1
  79. package/build/production/shared/utils/splitComponent.js +3 -3
  80. package/build/production/shared/utils/splitComponent.js.map +1 -1
  81. package/build/production/shared/utils/webpack.js +3 -2
  82. package/build/production/shared/utils/webpack.js.map +1 -1
  83. package/build/types-code/shared/utils/config.d.ts +1 -1
  84. package/build/web/server/Cache.js +3 -3
  85. package/build/web/server/Cache.js.map +1 -1
  86. package/build/web/server/index.js +1 -1
  87. package/build/web/server/index.js.map +1 -1
  88. package/build/web/server/renderer.js +9 -9
  89. package/build/web/server/renderer.js.map +1 -1
  90. package/build/web/server/server.js +6 -6
  91. package/build/web/server/server.js.map +1 -1
  92. package/build/web/server/utils/errors.js +1 -1
  93. package/build/web/server/utils/errors.js.map +1 -1
  94. package/build/web/shared/components/Button/index.js +1 -1
  95. package/build/web/shared/components/Button/index.js.map +1 -1
  96. package/build/web/shared/components/Checkbox/index.js +1 -1
  97. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  98. package/build/web/shared/components/Input/index.js +1 -1
  99. package/build/web/shared/components/Input/index.js.map +1 -1
  100. package/build/web/shared/components/Modal/index.js +1 -1
  101. package/build/web/shared/components/Modal/index.js.map +1 -1
  102. package/build/web/shared/components/TextArea/index.js +1 -1
  103. package/build/web/shared/components/TextArea/index.js.map +1 -1
  104. package/build/web/shared/components/WithTooltip/Tooltip.js +1 -1
  105. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  106. package/build/web/shared/components/WithTooltip/index.js +2 -2
  107. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  108. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  109. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  110. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  111. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  112. package/build/web/shared/components/selectors/NativeDropdown/index.js +2 -2
  113. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  114. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  115. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  116. package/build/web/shared/utils/config.js.map +1 -1
  117. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +2 -2
  118. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  119. package/build/web/shared/utils/jest/index.js +2 -2
  120. package/build/web/shared/utils/jest/index.js.map +1 -1
  121. package/build/web/shared/utils/splitComponent.js +3 -3
  122. package/build/web/shared/utils/splitComponent.js.map +1 -1
  123. package/build/web/shared/utils/webpack.js +3 -2
  124. package/build/web/shared/utils/webpack.js.map +1 -1
  125. package/config/babel/webpack.js +6 -1
  126. package/config/webpack/app-base.js +16 -6
  127. package/config/webpack/app-development.js +2 -0
  128. package/package.json +21 -19
@@ -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";import defaultTheme from"./style.scss";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";import defaultTheme from"./style.scss";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":["el","hiddenAreaRef","localValue","containerClassName"],"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,MAAO,aAAY,oBAAqB,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,CAAC,CAE1D,kBAAoB,MAAM,CAAsB,IAAI,CAAC,CAErD,gCAAoC,QAAQ,CAAC,KAAW,EAAX,EAAW,CAAC,CACzD,GAAI,KAAK,GAAK,SAAiC,EAApB,UAAU,GAAK,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,iEAG5D,QACR,SAAW,aAAa,QAAQ,CAChC,GAAI,CAAC,EAAE,SAEP,SAAW,KACT,SAAS,CAAC,EAAE,aAAa,CAAC,CAC3B,CACD,eAAiB,GAAI,eAAc,CAAC,EAAE,CAAC,CACvC,QAAQ,QAAQ,CAAC,EAAE,CAAC,OAEb,KACL,QAAQ,WAAW,CAAC,CAAC,CACtB,CACF,CAAE,KAAE,sCAbL,SAAS,CAAC,EAaT,CAAE,EAAE,CAAC,2DASU,QACd,WAAW,aAAa,QAAQ,CAChC,GAAIA,IAAE,EAAE,SAAS,CAACA,IAAE,aAAa,CAAC,CAAC,CACpC,mDAAE,IAAC,UAAU,CAA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P,IAEO,yJA1DV,8BACaC,SAAkB,CAAlB,kBAAkB,CACpB,OAER,CAFQ,EAER,WAEA,EAAwE,CACzE,EAkBE,CACF,GA6BE,CACD,GAEO,EACL,CAAC,+FA3DN,IA2DM,CAET,CAED,cAAe,SAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["el","hiddenAreaRef","localValue","containerClassName"],"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":"4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ip.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":["arrowRef","contentRef","containerRef"],"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,gCAAV,UAAU,kCAAV,UAAU,gCAAV,UAAU,wCAAV,WAAU,MAOtB,KAAM,iBAAgB,CAAG,CACvB,iCAAiC,CACjC,+BAA+B,CAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAEX,KAAM,eAAc,CAAG,CACrB,8BAA8B,CAC9B,+BAA+B,CAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAiBX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,iBAAgB,CAAC,OAAoB,CAAiB,CAC7D,MAAO,CACL,KAAK,CAAE,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAC5C,SAAS,CAAE,OAAO,CAAC,SAAS,CAAC,qBAAqB,CAAC,CACrD,CAAC,CACH,CAEA;AACA;AACA;AACA;AACA,GACA,QAAS,iBAAgB,EAAG,CAC1B,KAAM,CAAE,OAAO,CAAE,OAAQ,CAAC,CAAG,MAAM,CACnC,KAAM,CAAE,eAAe,CAAE,CAAE,YAAY,CAAE,WAAY,CAAE,CAAC,CAAG,QAAQ,CACnE,MAAO,CACL,MAAM,CAAE,OAAO,CAAG,YAAY,CAC9B,IAAI,CAAE,OAAO,CACb,KAAK,CAAE,OAAO,CAAG,WAAW,CAC5B,GAAG,CAAE,OACP,CAAC,CACH,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,oBAA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Md,GAAI,CAAC,QAAQ,QAAiC,EAA1C,CAAsB,YAAY,QAA+B,EAAjE,CAA+C,UAAU,QAAQ,EACnE,KAAM,MAAK,CAAC,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,CACH,sBAfD,cAAgB,EAef,CAAC,0DACuB,QAAO,QAAU,CAAC,CAAC,sBAA5C,mBAAmB,CAAC,GAAG,CAAE,EAAmB,CAAC,+BAKvC,4BAAgB,SAAW,CAAX,KAAK,MAAM,CAAOA,GAAQ,CAAR,QAAQ,CAAG,CAAC,wFAC9C,4BAAgB,SAAa,CAAb,KAAK,QAAQ,CAAOC,GAAU,CAAV,UAAU,UAAG,QAAQ,CAAM,CAAC,+GAJ/D,4BAAY,cAEf,aAAgB,SAAe,CAAf,KAAK,UAAU,CAAOC,GAAY,CAAZ,YAAY,WAChD,EAA8C,CAC9C,EAAgE,EAC7D,CAAC,CAER,QAAQ,KACV,CAAC,mEARM,GAQN,CACF,CAED,cAAe,QAAO","ignoreList":[]}
1
+ {"version":3,"file":"Tooltip.js","names":["arrowRef","contentRef","containerRef"],"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,OAAS,YAAY,KAAQ,WAAW,CAAC,yDAIzC;AACA;AACA;AACA,GACA,UAAY,WAAU,uBAAV,UAAU,EAAV,UAAU,gCAAV,UAAU,kCAAV,UAAU,gCAAV,UAAU,wCAAV,WAAU,MAOtB,KAAM,iBAAgB,CAAG,CACvB,iCAAiC,CACjC,+BAA+B,CAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAEX,KAAM,eAAc,CAAG,CACrB,8BAA8B,CAC9B,+BAA+B,CAC/B,gCAAgC,CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAiBX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,iBAAgB,CAAC,OAAoB,CAAiB,CAC7D,MAAO,CACL,KAAK,CAAE,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAC5C,SAAS,CAAE,OAAO,CAAC,SAAS,CAAC,qBAAqB,CAAC,CACrD,CAAC,CACH,CAEA;AACA;AACA;AACA;AACA,GACA,QAAS,iBAAgB,EAAG,CAC1B,KAAM,CAAE,OAAO,CAAE,OAAQ,CAAC,CAAG,MAAM,CACnC,KAAM,CAAE,eAAe,CAAE,CAAE,YAAY,CAAE,WAAY,CAAE,CAAC,CAAG,QAAQ,CACnE,MAAO,CACL,MAAM,CAAE,OAAO,CAAG,YAAY,CAC9B,IAAI,CAAE,OAAO,CACb,KAAK,CAAE,OAAO,CAAG,WAAW,CAC5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AAY,CAAC,OAAO,CAAE,UAAU,CAAC,CACjD,CAEA,mCACA,KAAM,QAIJ,CAAG,oBAAC,4BAAwB,CAO5B,eAAiB,MAAM,CAAiB,IAAI,CAAC,CAC7C,mBAAqB,MAAM,CAAiB,IAAI,CAAC,CACjD,iBAAmB,MAAM,CAAiB,IAAI,CAAC,CAAC,0DAEhC,qCAMd,GAAI,CAAC,QAAQ,QAAiC,EAA1C,CAAsB,YAAY,QAA+B,EAAjE,CAA+C,UAAU,QAAQ,EACnE,KAAM,MAAK,CAAC,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,CACH,sBAfD,cAAgB,EAef,CAAC,0DACuB,QAAO,QAAU,CAAC,CAAC,sBAA5C,mBAAmB,CAAC,GAAG,CAAE,EAAmB,CAAC,+BAKvC,4BAAgB,SAAW,CAAX,KAAK,MAAM,CAAOA,GAAQ,CAAR,QAAQ,CAAG,CAAC,wFAC9C,4BAAgB,SAAa,CAAb,KAAK,QAAQ,CAAOC,GAAU,CAAV,UAAU,UAAG,QAAQ,CAAM,CAAC,+GAJ/D,4BAAY,cAEf,aAAgB,SAAe,CAAf,KAAK,UAAU,CAAOC,GAAY,CAAZ,YAAY,WAChD,EAA8C,CAC9C,EAAgE,EAC7D,CAAC,CAER,QAAQ,KACV,CAAC,mEARM,GAQN,CACF,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":["prev","listener","e"],"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,MAAO,aAAY,4BAA6B,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,I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zB;AACA,GAAI,GAAG,CAAE,GAAG,CAAC,OAAO,CAAG,IAAI,CAC7B,CAAE,CACF,IAAI,CAAC,cAAc,CACnB,KAAK,CAAE,KAEP;AAAA,IACI,cAAc,WAGhB,WAAW,EAAI,GAAG,GAAK,IAAI,cACvB,KAAC,OAAO,EAAC,GAAG,CAAE,UAAW,CAAC,KAAK,CAAE,MAAO,UAAE,GAAG,CAAU,CAAC,CACxD,IAAI,CAET,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,EAAU,CAAG,WAAsB,CAEzC,CAAC,CAAC,UAAU,CAAG,UAAU,CAEzB,cAAe,EAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["prev","listener","e"],"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 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,MAAO,aAAY,4BAA6B,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,C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AAI,CAAC,CAAC,CAAC,CACrC,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAE,KAAK,CAAC,OAAO,CAAC,CAElD,YAAY,GAAGA,GAAC,CAAC,CACnB,CAAE,CACF,GAAG,CAAG,IAAI,EAAK,CACb,UAAU,CAAC,OAAO,CAAG,IAAI,CAEzB;AACA,GAAI,GAAG,CAAE,GAAG,CAAC,OAAO,CAAG,IAAI,CAC7B,CAAE,CACF,IAAI,CAAC,cAAc,CACnB,KAAK,CAAE,KAEP;AAAA,IACI,cAAc,WAGhB,WAAW,EAAI,GAAG,GAAK,IAAI,cACvB,KAAC,OAAO,EAAC,GAAG,CAAE,UAAW,CAAC,KAAK,CAAE,MAAO,UAAE,GAAG,CAAU,CAAC,CACxD,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";import S from"./style.scss";import{jsx as _jsx}from"react/jsx-runtime";export function areEqual(a,b){return a?.left===b?.left&&a?.top===b?.top&&a?.width===b?.width;}const Options=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 _pushInstanceProperty from"core-js-pure/features/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";import S from"./style.scss";import{jsx as _jsx}from"react/jsx-runtime";export function areEqual(a,b){return a?.left===b?.left&&a?.top===b?.top&&a?.width===b?.width;}const Options=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);_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;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["optionClass","e","opsRef","containerStyle"],"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 overl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,IAAI,GAAK,OAAO,EACnB,QAAQ,CAAC,MAAM,CAAC,CAChBA,GAAC,gBAAgB,CAAC,CAAC,CACpB,CACF,CACI,IAAQ,CAAR,QAAQ,CACH,QAAC,CAAD,CAAC,UAEV,KAAK,EAdD,MAeF,CACP,CAAC,CACF,CACF,gIAaU,OACD,EAAE,WACK,cAAc,SAChB,EAAE,KACN,EAAE,SACE,CAAC,QACZ,CAAC,wEAED,4BAAUC,GAAM,CAAN,MAAM,UAAG,WAAW,CAAM,CAAC,qHAlBvC,qBAAC,SAAS,EAMR,iBAAiB,CAAjB,IAAiB,CACjB,oBAAoB,CAApB,IAAoB,CACV,QAAQ,CAAR,QAAQ,CACXC,KAAc,CAAd,cAAc,CACd,KAMN,CANM,EAMN,UAED,EAAqC,CAC5B,CAAC,oFAnBZ,GAmBY,CAEf,CAED,cAAe,QAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["optionClass","e","opsRef","containerStyle"],"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":"sHAAA,OAIE,mBAAmB,CACnB,MAAM,KACD,OAAO,CAAC,OAEN,SAAS,sCAMhB,eAAe,uBAGjB,MAAO,EAAC,oBAAqB,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,GAA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M,CAAC,qHAlBvC,qBAAC,SAAS,EAMR,iBAAiB,CAAjB,IAAiB,CACjB,oBAAoB,CAApB,IAAoB,CACV,QAAQ,CAAR,QAAQ,CACXC,KAAc,CAAd,cAAc,CACd,KAMN,CANM,EAMN,UAED,EAAqC,CAC5B,CAAC,oFAnBZ,GAmBY,CAEf,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";import defaultTheme from"./theme.scss";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{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";import defaultTheme from"./theme.scss";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":["id","selected","e","openList","dropdownRef","opsContainerClass","opsPos","opsRef","containerClassName"],"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,0BA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AN,KACG,OAAO,EACUC,cAAiB,CAAjB,iBAAiB,CACjBC,cAAM,CAAN,MAAM,CACZ,QAET,CAFS,KACR,SAAS,CAAC,KAAK,CAAC,CACjB,CACS,QAGT,CAHS,WACR,SAAS,CAAC,KAAK,CAAC,CAChB,GAAI,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAClC,CACY,WAAmB,CAAnB,MAAM,OAAa,EAAnB,EAAmB,CACvB,OAAO,CAAP,OAAO,CACXC,GAAM,CAAN,MAAM,CAER,CAAC,CAfR,IAeQ,sMAhCZ,8BAAgBC,SAAkB,CAAlB,kBAAkB,WAC/B,EAC8C,CAC/C,EAYM,CAEJ,EAeQ,EAEP,CAAC,oFAlCN,IAkCM,CAET,CAED,cAAe,eAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["id","selected","e","openList","dropdownRef","opsContainerClass","opsPos","opsRef","containerClassName"],"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":"4CAAA,OAGE,SAAS,CACT,MAAM,CACN,QAAQ,KACH,OAAO,CAEd,OAAS,QAAQ,KAAQ,0BAA0B,CAAC,OAEjB,eAAe,0BAE3C,QAAO,EAAmC,QAAQ,0BAEzD,MAAO,aAAY,oBAAqB,+EAExC,KAAM,eAEL,CAAG,oBAAC,mDAOJ,CACC,aAAe,QAAQ,CAAC,gBAAgB,CAAE,YAAY,CAAE,KAAK,CAAC,CAE9D,wBAA4B,QAAQ,CAAC,KAAK,CAAC,CAE3C,kBAAoB,MAAM,CAAiB,IAAI,CAAC,CAChD,aAAe,MAAM,CAAO,IAAI,CAAC,CAEjC,wBAA4B,QAAQ,CAAgB,CAAC,CACrD,wBAA4B,QAAQ,CAAC,KAAK,CAAC,CAAC,gCAElC,QACR,GAAI,CAAC,MAAM,SAEPA,GAAA,IACJ,SAAW,KACT,aAAe,WAAW,QAA+B,uBAAE,CAAD,CAAC,CAC3D,cAAgB,MAAM,QAAiB,SAAE,CAAD,CAAC,CACzC,GAAI,MAAiB,EAAjB,OAAiB,EACnB,eAAiB,MAAM,OAAO,CAAG,OAAO,OAAO,EAC1C,MAAM,eAAuB,QAAK,EAAlC,CAAkC,CAAC,CACxC,aAAe,MAAM,IAAI,CAAG,OAAO,OAAO,CAAG,CAAC,CAE9C,SAAW,CAAC,QAAkB,EAAnB,MAAmB,CAC9B,SAAS,CAAC,EAAE,CAAC,CAEb,UAAY,EAAE,CAAF,MACJ,MAAM,KAAK,KACZ,MAAM,IAAI,CAAG,OAAO,OAAO,CAAG,CAAC,OAC7B,MAAM,MAKf,CAAC,CARW,MAKJ,MAAM,KAAK,KACZ,MAAM,OAAO,OACX,MAAM,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B,EAAmB,EAAE,EAC/C,8CAII,QAAK,GAAK,SACoC,CAD9C,IAC8C,cAD9C,YACmB,SAAY,CAAZ,MAAM,MAAM,UAAG,KAAK,CAAM,CAAC,iHAIlC,SACT,GAAIC,GAAC,IAAI,GAAK,OAAO,EAAE,QAAQ,CAACA,GAAC,CAAC,CAAC,CACpC,wDAMD,4BAAgB,SAAY,CAAZ,MAAM,MAAM,CAAG,CAAC,4GAXlC,6BACa,SAAe,CAAf,MAAM,SAAS,CACjBC,OAAQ,CAAR,QAAQ,CACN,SAEV,CAFU,EAEV,CACIC,GAAW,CAAX,WAAW,CACX,IAAS,CAAT,SAAS,CACJ,QAAC,CAAD,CAAC,WAEV,QAAQ,CACT,EAAgC,EAC7B,CAAC,qMAEJ,SAAM,cAAN,KACG,OAAO,EACUC,cAAiB,CAAjB,iBAAiB,CACjBC,cAAM,CAAN,MAAM,CACZ,QAET,CAFS,KACR,SAAS,CAAC,KAAK,CAAC,CACjB,CACS,QAGT,CAHS,WACR,SAAS,CAAC,KAAK,CAAC,CAChB,GAAI,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAClC,CACY,WAAmB,CAAnB,MAAM,OAAa,EAAnB,EAAmB,CACvB,OAAO,CAAP,OAAO,CACXC,GAAM,CAAN,MAAM,CAER,CAAC,CAfR,IAeQ,sMAhCZ,8BAAgBC,SAAkB,CAAlB,kBAAkB,WAC/B,EAC8C,CAC/C,EAYM,CAEJ,EAeQ,EAEP,CAAC,oFAlCN,IAkCM,CAET,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 _pushInstanceProperty from"core-js-pure/features/instance/push.js";// Implements dropdown based on the native HTML <select> element.
2
2
  import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";import defaultTheme from"./theme.scss";/**
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
@@ -21,5 +21,5 @@ import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../co
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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AAK,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}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":"0EAAA;AAIA,OAAS,QAAQ,KAAQ,0BAA0B,CAAC,OAE9B,eAAe,oBAErC,MAAO,aAAY,oBAEnB;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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in/react-themes";import{optionValueName}from"../common.js";import defaultTheme from"./theme.scss";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 _pushInstanceProperty from"core-js-pure/features/instance/push.js";import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";import defaultTheme from"./theme.scss";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};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["onPress"],"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,MAAO,aAAY,oBAAqB,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,CACnCA,GAAA,SACJ,GAAI,MAAM,GAAK,KAAK,EAAE,mBAAS,CAAI,IAAI,QAAQ,SAAS,EAAE,OACrD,GAAI,QAAQ,EACf,OAAAA,CAAUA,KACR,QAAQ,CAAC,MAAM,CAAC,CACjB,CAFM,CAGR,CAED,iCAAW,OAAX,WAAW,CACT,OAAO,cAAP,YAGiB,SAAS,CAAT,SAAS,CAEXA,OAAO,CAAP,OAAO,CACL,SAEV,CAFU,IACT,GAAI,CAAC,IAAI,GAAK,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,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,CACF,wKAII,QAAK,cAAL,YAAwB,SAAc,CAAd,QAAQ,MAAM,UAAG,KAAK,CAAa,CAAC,CAA5D,IAA4D,6GAE7D,4BAAgB,SAAgB,CAAhB,QAAQ,QAAQ,UAC7B,WAAW,CACT,CAAC,8HALR,6BAAgB,SAAkB,CAAlB,QAAQ,UAAU,WAC/B,EAA4D,CAE7D,EAEM,EACH,CAAC,yEANN,GAMM,CAET","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["onPress"],"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":"sHAEA,OAAqB,QAAQ,KAAQ,0BAA0B,CAAC,OAK9D,eAAe,oBAGjB,MAAO,aAAY,oBAAqB,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,CACnCA,GAAA,SACJ,GAAI,MAAM,GAAK,KAAK,EAAE,mBAAS,CAAI,IAAI,QAAQ,SAAe,EAAvB,EAAuB,EAAE,OAC3D,GAAI,QAAQ,EACf,OAAAA,CAAUA,KACR,QAAQ,CAAC,MAAM,CAAC,CACjB,CAFM,CAGR,CAED,iCAAW,OAAX,WAAW,CACT,OAAO,cAAP,YAGiB,SAAS,CAAT,SAAS,CAEXA,OAAO,CAAP,OAAO,CACL,SAEV,CAFU,IACT,GAAI,CAAC,IAAI,GAAK,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,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,CACF,wKAII,QAAK,cAAL,YAAwB,SAAc,CAAd,QAAQ,MAAM,UAAG,KAAK,CAAa,CAAC,CAA5D,IAA4D,6GAE7D,4BAAgB,SAAgB,CAAhB,QAAQ,QAAQ,UAC7B,WAAW,CACT,CAAC,8HALR,6BAAgB,SAAkB,CAAlB,QAAQ,UAAU,WAC/B,EAA4D,CAE7D,EAEM,EACH,CAAC,yEANN,GAMM,CAET","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 _JSON$parse from"core-js-pure/features/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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register, { revert } from '@babel/register';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: Stats;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n // NOTE: This is a TS module in the source code, and it turn into JS\n // module in the distributed code, after Babel compilation. As we rely\n // on it for the forked NodeJS process, we need to resolve the correct\n // extention ourselves (as NodeJS will hit the given path, without any\n // additional resolutions / transformations).\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);\n\n const cp = fork(ssrModulePath);\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\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,QAAQ,CAAC,CAChD,IAAI,CAAC,OAAO,CAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CACjC,IAAI,CAAC,UAAU,CAAG,OAAO,CACzB,IAAI,CAAC,OAAO,CAAG,OAAO,CAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,CAAC,CACP,UAAU,CAAE,CAAC,KAAK,CAAE,MAAM,CAAE,KAAK,CAAE,MAAM,CAAE,MAAM,CACnD,CAAC,CAAC,CACJ,CAEA,KAAM,MAAK,EAAkB,CAC3B,KAAM,MAAK,CAAC,KAAK,CAAC,CAAC,CACnB,KAAM,KAAI,CAAC,UAAU,CAAC,CAAC,CAEvB;AACA,KAAM,CAAE,YAAa,CAAC,CAAG,KAAM,OAAM,gCAA6B,CAClE,YAAY,CAAC,SAAS,CAAE,IAAI,CAAC,CAE7B,GAAI,IAAI,CAAC,OAAO,CAAE,KAAM,KAAI,CAAC,MAAM,CAAC,CAAC,CACrC,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAAG,IAAI,CAClD,CAEA,KAAM,SAAQ,EAAkB,CAC9B,MAAO,KAAI,CAAC,MAAM,CAAC,6BAA6B,CAEhD,MAAM,CAAC,CAAC,CAER,KAAM,MAAK,CAAC,QAAQ,CAAC,CAAC,CACxB,CACF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register, { revert } from '@babel/register';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: Stats;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n if (!options.context) throw Error('Missing context');\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n // NOTE: This is a TS module in the source code, and it turn into JS\n // module in the distributed code, after Babel compilation. As we rely\n // on it for the forked NodeJS process, we need to resolve the correct\n // extention ourselves (as NodeJS will hit the given path, without any\n // additional resolutions / transformations).\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);\n\n const cp = fork(ssrModulePath);\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown(): Promise<void> {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n revert();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O,CAAC,QAAQ,CAAC,CAChD,IAAI,CAAC,OAAO,CAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CACjC,IAAI,CAAC,UAAU,CAAG,OAAO,CACzB,IAAI,CAAC,OAAO,CAAG,OAAO,CAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,CAAC,CACP,UAAU,CAAE,CAAC,KAAK,CAAE,MAAM,CAAE,KAAK,CAAE,MAAM,CAAE,MAAM,CACnD,CAAC,CAAC,CACJ,CAEA,KAAM,MAAK,EAAkB,CAC3B,KAAM,MAAK,CAAC,KAAK,CAAC,CAAC,CACnB,KAAM,KAAI,CAAC,UAAU,CAAC,CAAC,CAEvB;AACA,KAAM,CAAE,YAAa,CAAC,CAAG,KAAM,OAAM,gCAA6B,CAClE,YAAY,CAAC,SAAS,CAAE,IAAI,CAAC,CAE7B,GAAI,IAAI,CAAC,OAAO,CAAE,KAAM,KAAI,CAAC,MAAM,CAAC,CAAC,CACrC,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAAG,IAAI,CAClD,CAEA,KAAM,SAAQ,EAAkB,CAC9B,MAAO,KAAI,CAAC,MAAM,CAAC,6BAA6B,CAEhD,MAAM,CAAC,CAAC,CAER,KAAM,MAAK,CAAC,QAAQ,CAAC,CAAC,CACxB,CACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import _JSON$stringify from"core-js-pure/stable/json/stringify.js";/* global document *//* eslint-disable import/no-extraneous-dependencies */import mockdate from"mockdate";import{act}from"react";import{createRoot}from"react-dom/client";import{expect,jest}from"@jest/globals";import{render}from"@testing-library/react";/**
1
+ import _JSON$stringify from"core-js-pure/features/json/stringify.js";/* global document *//* eslint-disable import/no-extraneous-dependencies */import mockdate from"mockdate";import{act}from"react";import{createRoot}from"react-dom/client";import{expect,jest}from"@jest/globals";import{render}from"@testing-library/react";/**
2
2
  * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
3
3
  * from `react`.
4
4
  */export{act};export{default as getGlobal}from"./global.js";global.IS_REACT_ACT_ENVIRONMENT=true;const originalProcessVersions=process.versions;/**
@@ -49,6 +49,6 @@ return new Promise((resolve,reject)=>{let rejected=false;// BEWARE: The "promise
49
49
  // "reject" argument provided.
50
50
  void promise.then(()=>{if(!rejected){// TODO: These lines are the same as the lines below for sync variant of
51
51
  // the function. We should split and reuse them in both places.
52
- const nodes=res.asFragment().childNodes;expect(nodes.length>1?[...nodes]:nodes[0]).toMatchSnapshot();resolve(res);}},error=>{rejected=true;// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
52
+ if(!res)throw Error("Missing render result");const nodes=res.asFragment().childNodes;expect(nodes.length>1?[...nodes]:nodes[0]).toMatchSnapshot();resolve(res);}},error=>{rejected=true;// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
53
53
  reject(error);});});}const nodes=res.asFragment().childNodes;expect(nodes.length>1?[...nodes]:nodes[0]).toMatchSnapshot();return res;}
54
54
  //# sourceMappingURL=index.js.map