@dr.pogodin/react-utils 1.53.0 → 1.54.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 (141) hide show
  1. package/build/development/client/index.js +2 -0
  2. package/build/development/client/index.js.map +1 -1
  3. package/build/development/index.js +2 -2
  4. package/build/development/index.js.map +1 -1
  5. package/build/development/shared/components/Button/index.js +149 -71
  6. package/build/development/shared/components/Button/index.js.map +1 -1
  7. package/build/development/shared/components/Checkbox/index.js +77 -24
  8. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  9. package/build/development/shared/components/GenericLink/index.js +133 -54
  10. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  11. package/build/development/shared/components/Input/index.js +168 -45
  12. package/build/development/shared/components/Input/index.js.map +1 -1
  13. package/build/development/shared/components/Link.js +23 -13
  14. package/build/development/shared/components/Link.js.map +1 -1
  15. package/build/development/shared/components/Modal/index.js +203 -87
  16. package/build/development/shared/components/Modal/index.js.map +1 -1
  17. package/build/development/shared/components/NavLink.js +16 -7
  18. package/build/development/shared/components/NavLink.js.map +1 -1
  19. package/build/development/shared/components/PageLayout/index.js +77 -15
  20. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  21. package/build/development/shared/components/TextArea/index.js +169 -68
  22. package/build/development/shared/components/TextArea/index.js.map +1 -1
  23. package/build/development/shared/components/Throbber/index.js +51 -13
  24. package/build/development/shared/components/Throbber/index.js.map +1 -1
  25. package/build/development/shared/components/WithTooltip/Tooltip.js +73 -34
  26. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  27. package/build/development/shared/components/WithTooltip/index.js +19 -19
  28. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  29. package/build/development/shared/components/YouTubeVideo/index.js +66 -23
  30. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +104 -56
  32. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  33. package/build/development/shared/components/selectors/CustomDropdown/index.js +173 -75
  34. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  35. package/build/development/shared/components/selectors/Switch/index.js +86 -36
  36. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  37. package/build/development/shared/utils/globalState.js +2 -2
  38. package/build/development/shared/utils/globalState.js.map +1 -1
  39. package/build/development/shared/utils/index.js +1 -1
  40. package/build/development/shared/utils/index.js.map +1 -1
  41. package/build/development/shared/utils/splitComponent.js +125 -55
  42. package/build/development/shared/utils/splitComponent.js.map +1 -1
  43. package/build/development/shared/utils/time.js +55 -20
  44. package/build/development/shared/utils/time.js.map +1 -1
  45. package/build/production/client/index.js +2 -2
  46. package/build/production/client/index.js.map +1 -1
  47. package/build/production/index.js +1 -1
  48. package/build/production/index.js.map +1 -1
  49. package/build/production/shared/components/Button/index.js +2 -13
  50. package/build/production/shared/components/Button/index.js.map +1 -1
  51. package/build/production/shared/components/Checkbox/index.js +1 -1
  52. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  53. package/build/production/shared/components/GenericLink/index.js +2 -15
  54. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  55. package/build/production/shared/components/Input/index.js +2 -11
  56. package/build/production/shared/components/Input/index.js.map +1 -1
  57. package/build/production/shared/components/Link.js +2 -4
  58. package/build/production/shared/components/Link.js.map +1 -1
  59. package/build/production/shared/components/Modal/index.js +2 -10
  60. package/build/production/shared/components/Modal/index.js.map +1 -1
  61. package/build/production/shared/components/NavLink.js +1 -4
  62. package/build/production/shared/components/NavLink.js.map +1 -1
  63. package/build/production/shared/components/PageLayout/index.js +2 -2
  64. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  65. package/build/production/shared/components/TextArea/index.js +1 -21
  66. package/build/production/shared/components/TextArea/index.js.map +1 -1
  67. package/build/production/shared/components/Throbber/index.js +2 -2
  68. package/build/production/shared/components/Throbber/index.js.map +1 -1
  69. package/build/production/shared/components/WithTooltip/Tooltip.js +2 -7
  70. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  71. package/build/production/shared/components/WithTooltip/index.js +3 -3
  72. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  73. package/build/production/shared/components/YouTubeVideo/index.js +2 -5
  74. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  75. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -6
  76. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  77. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -7
  78. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  79. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  80. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  81. package/build/production/shared/utils/globalState.js +1 -1
  82. package/build/production/shared/utils/globalState.js.map +1 -1
  83. package/build/production/shared/utils/index.js +1 -1
  84. package/build/production/shared/utils/index.js.map +1 -1
  85. package/build/production/shared/utils/splitComponent.js +3 -10
  86. package/build/production/shared/utils/splitComponent.js.map +1 -1
  87. package/build/production/shared/utils/time.js +2 -2
  88. package/build/production/shared/utils/time.js.map +1 -1
  89. package/build/types-code/index.d.ts +2 -2
  90. package/build/types-code/shared/utils/globalState.d.ts +2 -2
  91. package/build/types-code/shared/utils/index.d.ts +1 -1
  92. package/build/types-code/shared/utils/splitComponent.d.ts +1 -0
  93. package/build/web/client/index.js +2 -2
  94. package/build/web/client/index.js.map +1 -1
  95. package/build/web/index.js +1 -1
  96. package/build/web/index.js.map +1 -1
  97. package/build/web/shared/components/Button/index.js +2 -13
  98. package/build/web/shared/components/Button/index.js.map +1 -1
  99. package/build/web/shared/components/Checkbox/index.js +1 -1
  100. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  101. package/build/web/shared/components/GenericLink/index.js +2 -15
  102. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  103. package/build/web/shared/components/Input/index.js +2 -11
  104. package/build/web/shared/components/Input/index.js.map +1 -1
  105. package/build/web/shared/components/Link.js +2 -4
  106. package/build/web/shared/components/Link.js.map +1 -1
  107. package/build/web/shared/components/Modal/index.js +2 -10
  108. package/build/web/shared/components/Modal/index.js.map +1 -1
  109. package/build/web/shared/components/NavLink.js +1 -4
  110. package/build/web/shared/components/NavLink.js.map +1 -1
  111. package/build/web/shared/components/PageLayout/index.js +2 -2
  112. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  113. package/build/web/shared/components/TextArea/index.js +1 -21
  114. package/build/web/shared/components/TextArea/index.js.map +1 -1
  115. package/build/web/shared/components/Throbber/index.js +2 -2
  116. package/build/web/shared/components/Throbber/index.js.map +1 -1
  117. package/build/web/shared/components/WithTooltip/Tooltip.js +2 -7
  118. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  119. package/build/web/shared/components/WithTooltip/index.js +3 -3
  120. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  121. package/build/web/shared/components/YouTubeVideo/index.js +2 -5
  122. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  123. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -6
  124. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  125. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -7
  126. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  127. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  128. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  129. package/build/web/shared/utils/globalState.js +1 -1
  130. package/build/web/shared/utils/globalState.js.map +1 -1
  131. package/build/web/shared/utils/index.js +1 -1
  132. package/build/web/shared/utils/index.js.map +1 -1
  133. package/build/web/shared/utils/splitComponent.js +3 -10
  134. package/build/web/shared/utils/splitComponent.js.map +1 -1
  135. package/build/web/shared/utils/time.js +2 -2
  136. package/build/web/shared/utils/time.js.map +1 -1
  137. package/config/babel/webpack.d.ts +1 -0
  138. package/config/babel/webpack.js +10 -12
  139. package/package.json +10 -8
  140. package/tsconfig.json +1 -1
  141. package/tsconfig.types.json +1 -1
@@ -89,9 +89,9 @@ const WithTooltip = ({
89
89
  // the tooltip is fully mounted, and that is delayed to future rendering
90
90
  // cycle due to the implementation).
91
91
  if (tooltipRef.current) {
92
- setHeap(prev => {
93
- tooltipRef.current?.pointTo(prev.lastCursorX + window.scrollX, prev.lastCursorY + window.scrollY, placement, wrapperRef.current);
94
- return prev;
92
+ setHeap(prev_0 => {
93
+ tooltipRef.current?.pointTo(prev_0.lastCursorX + window.scrollX, prev_0.lastCursorY + window.scrollY, placement, wrapperRef.current);
94
+ return prev_0;
95
95
  });
96
96
  }
97
97
  const listener = () => {
@@ -107,7 +107,7 @@ const WithTooltip = ({
107
107
  let container = custom.wrapper;
108
108
  if (classNameProp) container += ` ${classNameProp}`;
109
109
  useEffect(() => {
110
- const listener = () => {
110
+ const listener_0 = () => {
111
111
  setShowTooltip(false);
112
112
  heap.triggeredByTouch = false;
113
113
  if (heap.timerId) {
@@ -116,11 +116,11 @@ const WithTooltip = ({
116
116
  heap.triggeredByTouch = false;
117
117
  }
118
118
  };
119
- window.addEventListener("touchcancel", listener);
120
- window.addEventListener("touchend", listener);
119
+ window.addEventListener("touchcancel", listener_0);
120
+ window.addEventListener("touchend", listener_0);
121
121
  return () => {
122
- window.removeEventListener("touchcancel", listener);
123
- window.removeEventListener("touchend", listener);
122
+ window.removeEventListener("touchcancel", listener_0);
123
+ window.removeEventListener("touchend", listener_0);
124
124
  };
125
125
  }, [heap]);
126
126
  return /*#__PURE__*/_jsxs("div", {
@@ -136,34 +136,34 @@ const WithTooltip = ({
136
136
  }
137
137
  onClick?.(e);
138
138
  },
139
- onContextMenu: e => {
140
- e.preventDefault();
141
- onContextMenu?.(e);
139
+ onContextMenu: e_0 => {
140
+ e_0.preventDefault();
141
+ onContextMenu?.(e_0);
142
142
  },
143
- onMouseLeave: e => {
143
+ onMouseLeave: e_1 => {
144
144
  setShowTooltip(false);
145
- onMouseLeave?.(e);
145
+ onMouseLeave?.(e_1);
146
146
  },
147
- onMouseMove: e => {
147
+ onMouseMove: e_2 => {
148
148
  // NOTE: Because on touch devices mouse move events are still fired
149
149
  // after touch is released, to emulate mouse clicks for old websites.
150
150
  // If we don't ignore it here, the tooltip will appear after the touch
151
151
  // is released.
152
152
  if (!heap.ignoreMouseMove) {
153
- updatePortalPosition(e.clientX, e.clientY);
153
+ updatePortalPosition(e_2.clientX, e_2.clientY);
154
154
  }
155
- onMouseMove?.(e);
155
+ onMouseMove?.(e_2);
156
156
  },
157
- onTouchStart: e => {
157
+ onTouchStart: e_3 => {
158
158
  setHeap({
159
159
  ...heap,
160
160
  ignoreMouseMove: true,
161
161
  triggeredByTouch: true
162
162
  }); // TODO: I guess, it should be something more complex here,
163
163
  // to actually respond to the first / whatever touch we need.
164
- const touch = e.targetTouches.item(0);
164
+ const touch = e_3.targetTouches.item(0);
165
165
  updatePortalPosition(touch.clientX, touch.clientY);
166
- onTouchStart?.(e);
166
+ onTouchStart?.(e_3);
167
167
  },
168
168
  ref: node => {
169
169
  wrapperRef.current = node; // eslint-disable-next-line no-param-reassign
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","heap","setHeap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","current","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","prev","res","setTimeout","p","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"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,SAKEA,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,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cAAc;IAAAd,QAAA,GAGhByB,WAAW,IAAIZ,GAAG,KAAK,IAAI,gBACvBjB,IAAA,CAACJ,OAAO;MAACkB,GAAG,EAAEa,UAAW;MAACX,KAAK,EAAEG,MAAO;MAAAf,QAAA,EAAEa;IAAG,CAAU,CAAC,GACxD,IAAI,EAETb,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAMmD,CAAU,GAAGpD,WAAsB;AAEzCoD,CAAC,CAAC1D,UAAU,GAAGA,UAAU;AAEzB,eAAe0D,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","heap","setHeap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","current","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","prev","res","setTimeout","p","prev_0","listener","addEventListener","removeEventListener","container","wrapper","listener_0","clearTimeout","e","e_0","preventDefault","e_1","e_2","ignoreMouseMove","clientX","clientY","e_3","touch","targetTouches","item","node","role"],"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,SAKEA,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,OAAO,IACZC,UAAU;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAIoC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAsC,GAAGA,CAAC;E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A,UAAU;AAEzB,eAAe4D,CAAC","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import { c as _c } from "react/compiler-runtime";
1
2
  import qs from "qs";
2
3
  import { useTheme } from "@dr.pogodin/react-themes";
3
4
  import Throbber from "../Throbber/index.js";
@@ -29,36 +30,78 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /**
29
30
  * @param [props.title] The `title` attribute to add to the player
30
31
  * IFrame.
31
32
  */
32
- const YouTubeVideo = ({
33
- autoplay,
34
- src,
35
- theme,
36
- title
37
- }) => {
33
+ const YouTubeVideo = t0 => {
34
+ const $ = _c(13);
35
+ const {
36
+ autoplay,
37
+ src,
38
+ theme,
39
+ title
40
+ } = t0;
38
41
  const custom = useTheme("YouTubeVideo", defaultTheme, theme);
39
- const srcParts = src.split("?");
40
- let [url] = srcParts;
41
- const [, queryString] = srcParts;
42
- const query = queryString ? qs.parse(queryString) : {};
43
- const videoId = query.v ?? url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
44
- url = `https://www.youtube.com/embed/${videoId}`;
45
- delete query.v;
46
- query.autoplay = autoplay ? "1" : "0";
47
- url += `?${qs.stringify(query)}`; // TODO: https://developers.google.com/youtube/player_parameters
48
- // More query parameters can be exposed via the component props.
49
- return /*#__PURE__*/_jsxs("div", {
50
- className: custom.container,
51
- children: [/*#__PURE__*/_jsx(Throbber, {
42
+ let t1;
43
+ let t2;
44
+ let url;
45
+ if ($[0] !== autoplay || $[1] !== src) {
46
+ const srcParts = src.split("?");
47
+ [url] = srcParts;
48
+ const [, queryString] = srcParts;
49
+ const query = queryString ? qs.parse(queryString) : {};
50
+ const videoId = query.v ?? url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
51
+ url = `https://www.youtube.com/embed/${videoId}`;
52
+ delete query.v;
53
+ query.autoplay = autoplay ? "1" : "0";
54
+ t2 = url;
55
+ t1 = qs.stringify(query);
56
+ $[0] = autoplay;
57
+ $[1] = src;
58
+ $[2] = t1;
59
+ $[3] = t2;
60
+ $[4] = url;
61
+ } else {
62
+ t1 = $[2];
63
+ t2 = $[3];
64
+ url = $[4];
65
+ }
66
+ url = t2 + `?${t1}`;
67
+ let t3;
68
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
69
+ t3 = /*#__PURE__*/_jsx(Throbber, {
52
70
  theme: throbberTheme
53
- }), /*#__PURE__*/_jsx("iframe", {
54
- // eslint-disable-line react/iframe-missing-sandbox
71
+ });
72
+ $[5] = t3;
73
+ } else {
74
+ t3 = $[5];
75
+ }
76
+ let t4;
77
+ if ($[6] !== custom.video || $[7] !== title || $[8] !== url) {
78
+ t4 = /*#__PURE__*/_jsx("iframe", {
55
79
  allow: "autoplay",
56
80
  allowFullScreen: true,
57
81
  className: custom.video,
58
82
  src: url,
59
83
  title: title
60
- })]
61
- });
84
+ });
85
+ $[6] = custom.video;
86
+ $[7] = title;
87
+ $[8] = url;
88
+ $[9] = t4;
89
+ } else {
90
+ t4 = $[9];
91
+ }
92
+ let t5;
93
+ if ($[10] !== custom.container || $[11] !== t4) {
94
+ t5 = /*#__PURE__*/_jsxs("div", {
95
+ className: custom.container,
96
+ children: [t3, t4]
97
+ });
98
+ $[10] = custom.container;
99
+ $[11] = t4;
100
+ $[12] = t5;
101
+ } else {
102
+ t5 = $[12];
103
+ }
104
+ return t5;
62
105
  };
63
106
  export default YouTubeVideo;
64
107
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["qs","useTheme","Throbber","defaultTheme","throbberTheme","jsx","_jsx","jsxs","_jsxs","YouTubeVideo","autoplay","src","theme","title","custom","srcParts","split","url","queryString","query","parse","videoId","v","match","stringify","className","container","children","allow","allowFullScreen","video"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\nimport type { FunctionComponent } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport defaultTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme?: ThemeT;\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const custom = useTheme('YouTubeVideo', defaultTheme, theme);\n\n const srcParts = src.split('?');\n let [url] = srcParts;\n const [, queryString] = srcParts;\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v ?? url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId as string}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={custom.container}>\n <Throbber theme={throbberTheme} />\n {/* TODO: I guess, we better add the sanbox, but right now I don't have\n time to carefully explore which restrictions should be lifted to allow\n embed YouTube player to work... sometime later we'll take care of it */\n }\n <iframe // eslint-disable-line react/iframe-missing-sandbox\n allow=\"autoplay\"\n allowFullScreen\n className={custom.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default YouTubeVideo;\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAGnB,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,QAAQ;AAAA,MAAAC,YAAA;EAAA;EAAA;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;MACTJ,KAAK,EAAEA;IAAM,CACd,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAED,eAAeJ,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["qs","useTheme","Throbber","defaultTheme","throbberTheme","jsx","_jsx","jsxs","_jsxs","YouTubeVideo","t0","$","_c","autoplay","src","theme","title","custom","t1","t2","url","srcParts","split","queryString","query","parse","videoId","v","match","stringify","t3","Symbol","for","t4","video","allow","allowFullScreen","className","t5","container","children"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\nimport type { FunctionComponent } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport defaultTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme?: ThemeT;\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const custom = useTheme('YouTubeVideo', defaultTheme, theme);\n\n const srcParts = src.split('?');\n let [url] = srcParts;\n const [, queryString] = srcParts;\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v ?? url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId as string}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={custom.container}>\n <Throbber theme={throbberTheme} />\n {/* TODO: I guess, we better add the sanbox, but right now I don't have\n time to carefully explore which restrictions should be lifted to allow\n embed YouTube player to work... sometime later we'll take care of it */\n }\n <iframe // eslint-disable-line react/iframe-missing-sandbox\n allow=\"autoplay\"\n allowFullScreen\n className={custom.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default YouTubeVideo;\n"],"mappings":";AAAA,OAAOA,EAAE,MAAM,IAAI;AAGnB,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,QAAQ;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,MAAAC,aAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAG6B,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BAW5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAuC,GAAGC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAAC;IAAAC,QAAA;IAAAC,GAAA;IAAAC,KAAA;IAAAC;EAAA,IAAAN,EAKhD;EACC,MAAAO,MAAA,GAAehB,QAAQ,CAAC,cAAc,EAAEE,YAAY,EAAEY,KAAK,CAAC;EAAC,IAAAG,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAC,GAAA;EAAA,IAAAT,CAAA,QAAAE,QAAA,IAAAF,CAAA,QAAAG,GAAA;IAE7D,MAAAO,QAAA,GAAiBP,GAAG,CAAAQ,KAAM,CAAC,GAAG,CAAC;IAC/B,CAAAF,GAAA,IAAYC,QAAQ;IACpB,SAAAE,WAAA,IAAwBF,QAAQ;IAChC,MAAAG,KAAA,GAAcD,WAAW,GAAGvB,EAAE,CAAAyB,KAAM,CAACF,WAAgB,CAAC,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,MAAAS,GAAA;IAAAT,CAAA,MAAAsB,EAAA;EAAA;IAAAA,EAAA,GAAAtB,CAAA;EAAA;EAAA,IAAA2B,EAAA;EAAA,IAAA3B,CAAA,SAAAM,MAAA,CAAAsB,SAAA,IAAA5B,CAAA,SAAAsB,EAAA;IAZJK,EAAA,gBAAA9B,KAAA;MAAgB6B,SAAgB,EAAhBpB,MAAM,CAAAsB,SAAU;MAAAC,QAAA,GAC9BV,EAAkC,EAKlCG,EAME;IAAA,CACC,CAAC;IAAAtB,CAAA,OAAAM,MAAA,CAAAsB,SAAA;IAAA5B,CAAA,OAAAsB,EAAA;IAAAtB,CAAA,OAAA2B,EAAA;EAAA;IAAAA,EAAA,GAAA3B,CAAA;EAAA;EAAA,OAbN2B,EAaM;AAAA,CAET;AAED,eAAe7B,YAAY","ignoreList":[]}
@@ -2,6 +2,7 @@ import "core-js/modules/es.iterator.filter.js";
2
2
  import "core-js/modules/es.array.push.js";
3
3
  import "core-js/modules/es.iterator.constructor.js";
4
4
  import "core-js/modules/es.iterator.filter.js";
5
+ import { c as _c } from "react/compiler-runtime";
5
6
  import { useImperativeHandle, useRef } from "react";
6
7
  import { BaseModal } from "../../../Modal/index.js";
7
8
  import { optionValueName } from "../../common.js";
@@ -12,73 +13,120 @@ import { jsx as _jsx } from "react/jsx-runtime";
12
13
  export function areEqual(a, b) {
13
14
  return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;
14
15
  }
15
- const Options = ({
16
- containerClass,
17
- containerStyle,
18
- filter,
19
- onCancel,
20
- onChange,
21
- optionClass,
22
- options,
23
- ref
24
- }) => {
16
+ const Options = t0 => {
17
+ const $ = _c(16);
18
+ const {
19
+ containerClass,
20
+ containerStyle,
21
+ filter,
22
+ onCancel,
23
+ onChange,
24
+ optionClass,
25
+ options,
26
+ ref
27
+ } = t0;
25
28
  const opsRef = useRef(null);
26
- useImperativeHandle(ref, () => ({
27
- measure: () => {
28
- const e = opsRef.current?.parentElement;
29
- if (!e) return undefined;
30
- const rect = opsRef.current.getBoundingClientRect();
31
- const style = window.getComputedStyle(e);
32
- const mBottom = parseFloat(style.marginBottom);
33
- const mTop = parseFloat(style.marginTop);
34
- rect.height += mBottom + mTop;
35
- return rect;
36
- }
37
- }), []);
38
- const optionNodes = [];
39
- for (const option of options) {
40
- if (!filter || filter(option)) {
41
- const [iValue, iName] = optionValueName(option);
42
- optionNodes.push(/*#__PURE__*/_jsx("div", {
43
- className: optionClass,
44
- onClick: e => {
45
- onChange(iValue);
46
- e.stopPropagation();
47
- },
48
- onKeyDown: e => {
49
- if (e.key === "Enter") {
29
+ let t1;
30
+ let t2;
31
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32
+ t1 = () => ({
33
+ measure: () => {
34
+ const e = opsRef.current?.parentElement;
35
+ if (!e) {
36
+ return;
37
+ }
38
+ const rect = opsRef.current.getBoundingClientRect();
39
+ const style = window.getComputedStyle(e);
40
+ const mBottom = parseFloat(style.marginBottom);
41
+ const mTop = parseFloat(style.marginTop);
42
+ rect.height = rect.height + (mBottom + mTop);
43
+ return rect;
44
+ }
45
+ });
46
+ t2 = [];
47
+ $[0] = t1;
48
+ $[1] = t2;
49
+ } else {
50
+ t1 = $[0];
51
+ t2 = $[1];
52
+ }
53
+ useImperativeHandle(ref, t1, t2);
54
+ let optionNodes;
55
+ if ($[2] !== filter || $[3] !== onChange || $[4] !== optionClass || $[5] !== options) {
56
+ optionNodes = [];
57
+ for (const option of options) {
58
+ if (!filter || filter(option)) {
59
+ const [iValue, iName] = optionValueName(option);
60
+ optionNodes.push(/*#__PURE__*/_jsx("div", {
61
+ className: optionClass,
62
+ onClick: e_0 => {
50
63
  onChange(iValue);
51
- e.stopPropagation();
52
- }
53
- },
54
- role: "button",
55
- tabIndex: 0,
56
- children: iName
57
- }, iValue));
64
+ e_0.stopPropagation();
65
+ },
66
+ onKeyDown: e_1 => {
67
+ if (e_1.key === "Enter") {
68
+ onChange(iValue);
69
+ e_1.stopPropagation();
70
+ }
71
+ },
72
+ role: "button",
73
+ tabIndex: 0,
74
+ children: iName
75
+ }, iValue));
76
+ }
58
77
  }
78
+ $[2] = filter;
79
+ $[3] = onChange;
80
+ $[4] = optionClass;
81
+ $[5] = options;
82
+ $[6] = optionNodes;
83
+ } else {
84
+ optionNodes = $[6];
59
85
  }
60
- return /*#__PURE__*/_jsx(BaseModal // Closes the dropdown (cancels the selection) on any page scrolling attempt.
61
- // This is the same native <select> elements do on scrolling, and at least for
62
- // now we have no reason to deal with complications needed to support open
63
- // dropdowns during the scrolling (that would need to re-position it in
64
- // response to the position changes of the root dropdown element).
65
- , {
66
- cancelOnScrolling: true,
67
- dontDisableScrolling: true,
68
- onCancel: onCancel,
69
- style: containerStyle,
70
- theme: {
86
+ let t3;
87
+ if ($[7] !== containerClass) {
88
+ t3 = {
71
89
  ad: "",
72
90
  container: containerClass,
73
91
  context: "",
74
92
  hoc: "",
75
93
  overlay: S.overlay
76
- },
77
- children: /*#__PURE__*/_jsx("div", {
94
+ };
95
+ $[7] = containerClass;
96
+ $[8] = t3;
97
+ } else {
98
+ t3 = $[8];
99
+ }
100
+ let t4;
101
+ if ($[9] !== optionNodes) {
102
+ t4 = /*#__PURE__*/_jsx("div", {
78
103
  ref: opsRef,
79
104
  children: optionNodes
80
- })
81
- });
105
+ });
106
+ $[9] = optionNodes;
107
+ $[10] = t4;
108
+ } else {
109
+ t4 = $[10];
110
+ }
111
+ let t5;
112
+ if ($[11] !== containerStyle || $[12] !== onCancel || $[13] !== t3 || $[14] !== t4) {
113
+ t5 = /*#__PURE__*/_jsx(BaseModal, {
114
+ cancelOnScrolling: true,
115
+ dontDisableScrolling: true,
116
+ onCancel: onCancel,
117
+ style: containerStyle,
118
+ theme: t3,
119
+ children: t4
120
+ });
121
+ $[11] = containerStyle;
122
+ $[12] = onCancel;
123
+ $[13] = t3;
124
+ $[14] = t4;
125
+ $[15] = t5;
126
+ } else {
127
+ t5 = $[15];
128
+ }
129
+ return t5;
82
130
  };
83
131
  export default Options;
84
132
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useImperativeHandle","useRef","BaseModal","optionValueName","S","jsx","_jsx","areEqual","a","b","left","top","width","Options","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","option","iValue","iName","push","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","cancelOnScrolling","dontDisableScrolling","theme","ad","container","context","hoc","overlay"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;;;AAAA,SAIEA,mBAAmB,EACnBC,MAAM,QACD,OAAO;AAEd,SAASC,SAAS;AAAA,SAMhBC,eAAe;AAAA,MAAAC,CAAA;EAAA;AAAA;AAGY,SAAAC,GAAA,IAAAC,IAAA;AAQ7B,OAAO,SAASC,QAAQA,CAACC,CAAiB,EAAEC,CAAiB,EAAW;EACtE,OAAOD,CAAC,EAAEE,IAAI,KAAKD,CAAC,EAAEC,IAAI,IAAIF,CAAC,EAAEG,GAAG,KAAKF,CAAC,EAAEE,GAAG,IAAIH,CAAC,EAAEI,KAAK,KAAKH,CAAC,EAAEG,KAAK;AAC1E;AAiBA,MAAMC,OAAkC,GAAGA,CAAC;EAC1CC,cAAc;EACdC,cAAc;EACdC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,WAAW;EACXC,OAAO;EACPC;AACF,CAAC,KAAK;EACJ,MAAMC,MAAM,GAA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AEXT;MAAK,GAdDD,MAeF,CACP,CAAC;IACH;EACF;EAEA,oBACEnC,IAAA,CAACJ,SACC;EACA;EACA;EACA;EACA;EAAA;IACAkD,iBAAiB;IACjBC,oBAAoB;IACpBpC,QAAQ,EAAEA,QAAS;IACnBa,KAAK,EAAEf,cAAe;IACtBuC,KAAK,EAAE;MACLC,EAAE,EAAE,EAAE;MACNC,SAAS,EAAE1C,cAAc;MACzB2C,OAAO,EAAE,EAAE;MACXC,GAAG,EAAE,EAAE;MACPC,OAAO,EAAEvD,CAAC,CAACuD;IACb,CAAE;IAAAR,QAAA,eAEF7C,IAAA;MAAKe,GAAG,EAAEC,MAAO;MAAA6B,QAAA,EAAEZ;IAAW,CAAM;EAAC,CAC5B,CAAC;AAEhB,CAAC;AAED,eAAe1B,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useImperativeHandle","useRef","BaseModal","optionValueName","S","jsx","_jsx","areEqual","a","b","left","top","width","Options","t0","$","_c","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","t1","t2","Symbol","for","measure","e","current","parentElement","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","option","iValue","iName","push","className","onClick","e_0","stopPropagation","onKeyDown","e_1","key","role","tabIndex","children","t3","ad","container","context","hoc","overlay","t4","t5","cancelOnScrolling","dontDisableScrolling","theme"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current!.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;;;;AAAA,SAIEA,mBAAmB,EACnBC,MAAM,QACD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