@dr.pogodin/react-utils 1.35.5 → 1.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/build/development/index.js +0 -6
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +19 -19
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/renderer.js +7 -4
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +4 -1
- package/build/development/server/server.js.map +1 -1
- package/build/development/shared/components/Button/index.js +1 -16
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +1 -29
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +0 -15
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +1 -8
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +0 -12
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +2 -13
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +1 -10
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +1 -12
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +1 -6
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +1 -8
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +1 -9
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +2 -11
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +1 -16
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +2 -12
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -12
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +21 -28
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +0 -19
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +0 -13
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +4 -2
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +11 -12
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/web.bundle.js +26 -36
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/renderer.js +2 -2
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js +3 -3
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -16
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +2 -2
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +2 -2
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +2 -2
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -2
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +2 -2
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +3 -3
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +2 -2
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +3 -3
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -4
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +5 -5
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/index.d.ts +1 -2
- package/build/types-code/server/Cache.d.ts +3 -11
- package/build/types-code/server/index.d.ts +0 -2
- package/build/types-code/server/renderer.d.ts +0 -1
- package/build/types-code/server/server.d.ts +0 -1
- package/build/types-code/shared/components/Button/index.d.ts +3 -4
- package/build/types-code/shared/components/Checkbox/index.d.ts +3 -12
- package/build/types-code/shared/components/Input/index.d.ts +4 -5
- package/build/types-code/shared/components/Link.d.ts +0 -1
- package/build/types-code/shared/components/Modal/index.d.ts +3 -4
- package/build/types-code/shared/components/NavLink.d.ts +0 -1
- package/build/types-code/shared/components/PageLayout/index.d.ts +4 -4
- package/build/types-code/shared/components/TextArea/index.d.ts +4 -5
- package/build/types-code/shared/components/Throbber/index.d.ts +4 -4
- package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +1 -1
- package/build/types-code/shared/components/WithTooltip/index.d.ts +2 -3
- package/build/types-code/shared/components/YouTubeVideo/index.d.ts +3 -4
- package/build/types-code/shared/components/selectors/CustomDropdown/Options/index.d.ts +1 -2
- package/build/types-code/shared/components/selectors/CustomDropdown/index.d.ts +2 -3
- package/build/types-code/shared/components/selectors/NativeDropdown/index.d.ts +2 -2
- package/build/types-code/shared/components/selectors/Switch/index.d.ts +4 -5
- package/build/types-code/shared/components/selectors/common.d.ts +4 -10
- package/build/types-code/shared/components/selectors/index.d.ts +1 -1
- package/build/types-code/shared/utils/globalState.d.ts +1 -2
- package/build/types-code/shared/utils/jest/index.d.ts +4 -1
- package/build/types-code/shared/utils/splitComponent.d.ts +0 -1
- package/build/types-code/shared/utils/webpack.d.ts +0 -1
- package/config/babel/node-ssr.js +1 -1
- package/config/babel/webpack.js +1 -1
- package/config/eslint/default.json +1 -0
- package/config/eslint/jest.json +1 -0
- package/config/eslint/typescript.js +7 -0
- package/config/typescript/base.json +9 -0
- package/config/webpack/app-base.d.ts +0 -1
- package/config/webpack/app-base.js +1 -1
- package/config/webpack/app-development.js +1 -1
- package/config/webpack/app-production.js +1 -1
- package/config/webpack/lib-base.js +1 -2
- package/config/webpack/lib-development.js +1 -1
- package/config/webpack/lib-production.js +1 -1
- package/package.json +16 -17
- package/src/index.ts +0 -1
- package/src/server/Cache.ts +31 -30
- package/src/server/renderer.tsx +8 -5
- package/src/server/server.ts +6 -1
- package/src/shared/components/Button/index.tsx +2 -20
- package/src/shared/components/Checkbox/index.tsx +2 -37
- package/src/shared/components/GenericLink/index.tsx +0 -15
- package/src/shared/components/Input/index.tsx +6 -15
- package/src/shared/components/MetaTags.tsx +0 -12
- package/src/shared/components/Modal/index.tsx +3 -22
- package/src/shared/components/PageLayout/index.tsx +8 -24
- package/src/shared/components/TextArea/index.tsx +6 -24
- package/src/shared/components/Throbber/index.tsx +6 -18
- package/src/shared/components/WithTooltip/Tooltip.tsx +6 -14
- package/src/shared/components/WithTooltip/index.tsx +3 -24
- package/src/shared/components/YouTubeVideo/index.tsx +3 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +2 -20
- package/src/shared/components/selectors/CustomDropdown/index.tsx +3 -27
- package/src/shared/components/selectors/NativeDropdown/index.tsx +3 -27
- package/src/shared/components/selectors/Switch/index.tsx +34 -50
- package/src/shared/components/selectors/common.ts +12 -44
- package/src/shared/components/selectors/index.ts +0 -2
- package/src/shared/utils/jest/index.tsx +13 -2
- package/src/shared/utils/splitComponent.tsx +14 -11
- package/tsconfig.configs.json +7 -3
- package/tsconfig.json +3 -10
- package/tsconfig.types.json +1 -7
- package/tstyche.config.json +6 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_reactThemes","_Tooltip","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","validThemeKeys","validTooltipThemeKeys","Wrapper","children","placement","PLACEMENTS","ABOVE_CURSOR","tip","theme","current","heap","useRef","lastCursorX","lastCursorY","triggeredByTouch","timerId","undefined","tooltipRef","wrapperRef","showTooltip","setShowTooltip","useState","updatePortalPosition","cursorX","cursorY","setTimeout","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","useEffect","listener","addEventListener","removeEventListener","jsxs","className","wrapper","onMouseLeave","onMouseMove","clientX","clientY","onClick","clearTimeout","onTouchStart","ref","role","jsx","ThemedWrapper","themed","propTypes","PT","node","oneOf","values","themeType","isRequired","_default","exports"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport PT from 'prop-types';\nimport {\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n validThemeKeys as validTooltipThemeKeys,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\nconst validThemeKeys = [...validTooltipThemeKeys, 'wrapper'] as const;\n\ntype PropsT = {\n children?: ReactNode;\n placement?: PLACEMENTS;\n tip?: ReactNode;\n theme: Theme<typeof validThemeKeys>;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n lastCursorX: number;\n lastCursorY: number;\n triggeredByTouch: boolean;\n timerId?: NodeJS.Timeout;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param {object} props Component properties.\n * @param {React.node} props.tip – Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst Wrapper: React.FunctionComponent<PropsT> = ({\n children,\n placement = PLACEMENTS.ABOVE_CURSOR,\n tip,\n theme,\n}) => {\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n triggeredByTouch: false,\n timerId: undefined,\n });\n const tooltipRef = useRef<TooltipRefT>();\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (!showTooltip) {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n if (!heap.timerId) {\n heap.timerId = setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n }\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n } else {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap.lastCursorX + window.scrollX,\n heap.lastCursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n\n const listener = () => setShowTooltip(false);\n window.addEventListener('scroll', listener);\n return () => window.removeEventListener('scroll', listener);\n }\n return undefined;\n }, [\n heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={theme.wrapper}\n onMouseLeave={() => setShowTooltip(false)}\n onMouseMove={(e) => updatePortalPosition(e.clientX, e.clientY)}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\n >\n {\n showTooltip && tip !== null ? (\n <Tooltip ref={tooltipRef} theme={theme}>{tip}</Tooltip>\n ) : null\n }\n {children}\n </div>\n );\n};\n\nconst ThemedWrapper = themed(\n Wrapper,\n 'WithTooltip',\n [\n 'appearance',\n 'arrow',\n 'container',\n 'content',\n 'wrapper',\n ],\n defaultTheme,\n);\n\ntype ExportT = typeof ThemedWrapper & {\n PLACEMENTS: typeof PLACEMENTS;\n};\n\nconst e: ExportT = ThemedWrapper as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nWrapper.propTypes = {\n children: PT.node,\n placement: PT.oneOf(Object.values(PLACEMENTS)),\n theme: ThemedWrapper.themeType.isRequired,\n tip: PT.node,\n};\n\nexport default e;\n"],"mappings":";;;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAGmB,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAA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A,EAAEI;IAAG,CAAU,CAAC,GACrD,IAAI,EAETJ,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAED,MAAMkD,aAAa,GAAG,IAAAC,oBAAM,EAC1BpD,OAAO,EACP,aAAa,EACb,CACE,YAAY,EACZ,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,CACV,EACDH,YACF,CAAC;AAMD,MAAMnB,CAAU,GAAGyE,aAAwB;AAE3CzE,CAAC,CAACyB,UAAU,GAAGA,mBAAU;AAEzBH,OAAO,CAACqD,SAAS,GAAG;EAClBpD,QAAQ,EAAEqD,kBAAE,CAACC,IAAI;EACjBrD,SAAS,EAAEoD,kBAAE,CAACE,KAAK,CAACnE,MAAM,CAACoE,MAAM,CAACtD,mBAAU,CAAC,CAAC;EAC9CG,KAAK,EAAE6C,aAAa,CAACO,SAAS,CAACC,UAAU;EACzCtD,GAAG,EAAEiD,kBAAE,CAACC;AACV,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAA9E,OAAA,GAEaL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","require","_reactThemes","_interopRequireDefault","_Tooltip","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","Wrapper","children","placement","PLACEMENTS","ABOVE_CURSOR","tip","theme","current","heap","useRef","lastCursorX","lastCursorY","triggeredByTouch","timerId","undefined","tooltipRef","wrapperRef","showTooltip","setShowTooltip","useState","updatePortalPosition","cursorX","cursorY","setTimeout","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","useEffect","listener","addEventListener","removeEventListener","jsxs","className","wrapper","onMouseLeave","onMouseMove","clientX","clientY","onClick","clearTimeout","onTouchStart","ref","role","jsx","ThemedWrapper","themed","_default","exports"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n type ThemeKeysT as TooltipThemeKeysT,\n PLACEMENTS,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = {\n children?: ReactNode;\n placement?: PLACEMENTS;\n tip?: ReactNode;\n theme: Theme<'wrapper' | TooltipThemeKeysT>;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n lastCursorX: number;\n lastCursorY: number;\n triggeredByTouch: boolean;\n timerId?: NodeJS.Timeout;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param {object} props Component properties.\n * @param {React.node} props.tip – Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst Wrapper: React.FunctionComponent<PropsT> = ({\n children,\n placement = PLACEMENTS.ABOVE_CURSOR,\n tip,\n theme,\n}) => {\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n triggeredByTouch: false,\n timerId: undefined,\n });\n const tooltipRef = useRef<TooltipRefT>();\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (!showTooltip) {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n if (!heap.timerId) {\n heap.timerId = setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n }\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n } else {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap.lastCursorX + window.scrollX,\n heap.lastCursorY + window.scrollY,\n placement!,\n wrapperRef.current!,\n );\n }\n\n const listener = () => setShowTooltip(false);\n window.addEventListener('scroll', listener);\n return () => window.removeEventListener('scroll', listener);\n }\n return undefined;\n }, [\n heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={theme.wrapper}\n onMouseLeave={() => setShowTooltip(false)}\n onMouseMove={(e) => updatePortalPosition(e.clientX, e.clientY)}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\n >\n {\n showTooltip && tip !== null ? (\n <Tooltip ref={tooltipRef} theme={theme}>{tip}</Tooltip>\n ) : null\n }\n {children}\n </div>\n );\n};\n\nconst ThemedWrapper = themed(Wrapper, 'WithTooltip', defaultTheme);\n\ntype ExportT = typeof ThemedWrapper & {\n PLACEMENTS: typeof PLACEMENTS;\n};\n\nconst e: ExportT = ThemedWrapper as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":";;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAGmB,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,E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 -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
8
|
var _qs = _interopRequireDefault(require("qs"));
|
|
10
9
|
var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
|
|
11
10
|
var _Throbber = _interopRequireDefault(require("../Throbber"));
|
|
@@ -23,7 +22,6 @@ const throbberTheme = {
|
|
|
23
22
|
"hoc": "-dr-pogodin-react-utils___src-shared-components-YouTubeVideo-throbber___hoc___7sH52O",
|
|
24
23
|
"container": "-dr-pogodin-react-utils___src-shared-components-YouTubeVideo-throbber___container___jTxmOX"
|
|
25
24
|
};
|
|
26
|
-
const validThemeKeys = ['container', 'video'];
|
|
27
25
|
/**
|
|
28
26
|
* A component for embeding a YouTube video.
|
|
29
27
|
* @param [props] Component properties.
|
|
@@ -49,7 +47,7 @@ const YouTubeVideo = ({
|
|
|
49
47
|
let url = srcParts[0];
|
|
50
48
|
const queryString = srcParts[1];
|
|
51
49
|
const query = queryString ? _qs.default.parse(queryString) : {};
|
|
52
|
-
const videoId = query.v || url
|
|
50
|
+
const videoId = query.v || url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
|
|
53
51
|
url = `https://www.youtube.com/embed/${videoId}`;
|
|
54
52
|
delete query.v;
|
|
55
53
|
query.autoplay = autoplay ? '1' : '0';
|
|
@@ -71,12 +69,5 @@ const YouTubeVideo = ({
|
|
|
71
69
|
})]
|
|
72
70
|
});
|
|
73
71
|
};
|
|
74
|
-
|
|
75
|
-
YouTubeVideo.propTypes = {
|
|
76
|
-
autoplay: _propTypes.default.bool,
|
|
77
|
-
src: _propTypes.default.string.isRequired,
|
|
78
|
-
theme: ThemedYouTubeVideo.themeType.isRequired,
|
|
79
|
-
title: _propTypes.default.string
|
|
80
|
-
};
|
|
81
|
-
var _default = exports.default = ThemedYouTubeVideo;
|
|
72
|
+
var _default = exports.default = (0, _reactThemes.default)(YouTubeVideo, 'YouTubeVideo', baseTheme);
|
|
82
73
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_qs","_interopRequireDefault","require","_reactThemes","_Throbber","_jsxRuntime","baseTheme","throbberTheme","YouTubeVideo","autoplay","src","theme","title","srcParts","split","url","queryString","query","qs","parse","videoId","v","match","stringify","jsxs","className","container","children","jsx","default","allow","allowFullScreen","video","_default","exports","themed"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport baseTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ComponentThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme: ComponentThemeT,\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: React.FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const srcParts = src.split('?');\n let url = srcParts[0];\n const queryString = srcParts[1];\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v || url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={theme.container}>\n <Throbber theme={throbberTheme} />\n <iframe\n allow=\"autoplay\"\n allowFullScreen\n className={theme.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default themed(YouTubeVideo, 'YouTubeVideo', baseTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AAA2C,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,SAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,MAAAC,aAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAc3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAA6C,GAAGA,CAAC;EACrDC,QAAQ;EACRC,GAAG;EACHC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,QAAQ,GAAGH,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC;EAC/B,IAAIC,GAAG,GAAGF,QAAQ,CAAC,CAAC,CAAC;EACrB,MAAMG,WAAW,GAAGH,QAAQ,CAAC,CAAC,CAAC;EAC/B,MAAMI,KAAK,GAAGD,WAAW,GAAGE,WAAE,CAACC,KAAK,CAACH,WAAW,CAAC,GAAG,CAAC,CAAC;EAEtD,MAAMI,OAAO,GAAGH,KAAK,CAACI,CAAC,IAAIN,GAAG,EAAEO,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;EACjEP,GAAG,GAAG,iCAAiCK,OAAO,EAAE;EAEhD,OAAOH,KAAK,CAACI,CAAC;EACdJ,KAAK,CAACR,QAAQ,GAAGA,QAAQ,GAAG,GAAG,GAAG,GAAG;EACrCM,GAAG,IAAI,IAAIG,WAAE,CAACK,SAAS,CAACN,KAAK,CAAC,EAAE;;EAEhC;EACA;;EAEA,oBACE,IAAAZ,WAAA,CAAAmB,IAAA;IAAKC,SAAS,EAAEd,KAAK,CAACe,SAAU;IAAAC,QAAA,gBAC9B,IAAAtB,WAAA,CAAAuB,GAAA,EAACxB,SAAA,CAAAyB,OAAQ;MAAClB,KAAK,EAAEJ;IAAc,CAAE,CAAC,eAClC,IAAAF,WAAA,CAAAuB,GAAA;MACEE,KAAK,EAAC,UAAU;MAChBC,eAAe;MACfN,SAAS,EAAEd,KAAK,CAACqB,KAAM;MACvBtB,GAAG,EAAEK,GAAI;MACTH,KAAK,EAAEA;IAAM,CACd,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAAC,IAAAqB,QAAA,GAAAC,OAAA,CAAAL,OAAA,GAEa,IAAAM,oBAAM,EAAC3B,YAAY,EAAE,cAAc,EAAEF,SAAS,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.areEqual = areEqual;
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
8
|
var _react = require("react");
|
|
11
9
|
var _Modal = require("../../../Modal");
|
|
12
10
|
var _common = require("../../common");
|
|
@@ -42,7 +40,7 @@ const Options = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
42
40
|
const optionNodes = [];
|
|
43
41
|
for (let i = 0; i < options.length; ++i) {
|
|
44
42
|
const option = options[i];
|
|
45
|
-
if (!filter || filter(option)) {
|
|
43
|
+
if (option !== undefined && (!filter || filter(option))) {
|
|
46
44
|
const [iValue, iName] = (0, _common.optionValueName)(option);
|
|
47
45
|
optionNodes.push( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
48
46
|
className: optionClass,
|
|
@@ -86,18 +84,5 @@ const Options = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
86
84
|
})
|
|
87
85
|
});
|
|
88
86
|
});
|
|
89
|
-
Options.propTypes = {
|
|
90
|
-
containerClass: _propTypes.default.string.isRequired,
|
|
91
|
-
containerStyle: _propTypes.default.shape({
|
|
92
|
-
left: _propTypes.default.number.isRequired,
|
|
93
|
-
top: _propTypes.default.number.isRequired,
|
|
94
|
-
width: _propTypes.default.number.isRequired
|
|
95
|
-
}),
|
|
96
|
-
filter: _propTypes.default.func,
|
|
97
|
-
onCancel: _propTypes.default.func.isRequired,
|
|
98
|
-
onChange: _propTypes.default.func.isRequired,
|
|
99
|
-
optionClass: _propTypes.default.string.isRequired,
|
|
100
|
-
options: _common.optionsValidator.isRequired
|
|
101
|
-
};
|
|
102
87
|
var _default = exports.default = Options;
|
|
103
88
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","require","_Modal","_common","_jsxRuntime","S","areEqual","a","b","left","top","width","Options","forwardRef","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","useRef","useImperativeHandle","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","i","length","option","iValue","iName","optionValueName","push","jsx","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","BaseModal","cancelOnScrolling","dontDisableScrolling","theme","ad","hoc","container","context","overlay","_default","exports","default"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import { forwardRef, useImperativeHandle, useRef } from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport S from './style.scss';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<React.ReactNode> | ValueT) => boolean;\n optionClass: string;\n options: Readonly<OptionsT<React.ReactNode>>;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n};\n\nconst Options = forwardRef<RefT, PropsT>(({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n}, ref) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current?.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: React.ReactNode[] = [];\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!filter || filter(option))) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n key={iValue}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n containerStyle={containerStyle}\n dontDisableScrolling\n onCancel={onCancel}\n theme={{\n ad: '',\n hoc: '',\n container: containerClass,\n context: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n});\n\nexport default Options;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AAKsB,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,CAAA;EAAA;AAAA;AAQf,SAASC,QAAQA,CAACC,CAAiB,EAAEC,CAAiB,EAAW;EACtE,OAAOD,CAAC,EAAEE,IAAI,KAAKD,CAAC,EAAEC,IAAI,IAAIF,CAAC,EAAEG,GAAG,KAAKF,CAAC,EAAEE,GAAG,IAAIH,CAAC,EAAEI,KAAK,KAAKH,CAAC,EAAEG,KAAK;AAC1E;AAgBA,MAAMC,OAAO,gBAAG,IAAAC,iBAAU,EAAe,CAAC;EACxCC,cAAc;EACdC,cAAc;EACdC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,WAAW;EACXC;AACF,CAAC,EAAEC,GAAG,KAAK;EACT,MAAMC,MAAM,GAAG,IAAAC,aAAM,EAAiB,IAAI,CAAC;EAE3C,IAAAC,0BAAmB,EAACH,GAAG,EAAE,OAAO;IAC9BI,OAAO,EAAEA,CAAA,KAAM;MACb,MAAMC,CAAC,GAAGJ,MAAM,CAACK,OAAO,EAAEC,aAAa;MACvC,IAAI,CAACF,CAAC,EAAE,OAAOG,SAAS;MAExB,MAAMC,IAAI,GAAGR,MAAM,CAACK,OAAO,EAAEI,qBAAqB,CAAC,CAAC;MACpD,MAAMC,KAAK,GAAGC,MAAM,CAACC,gBAAgB,CAACR,CAAC,CAAC;MACxC,MAAMS,OAAO,GAAGC,UAAU,CAACJ,KAAK,CAACK,YAAY,CAAC;MAC9C,MAAMC,IAAI,GAAGF,UAAU,CAACJ,KAAK,CAACO,SAAS,CAAC;MAExCT,IAAI,CAACU,MAAM,IAAIL,OAAO,GAAGG,IAAI;MAE7B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EAAE7D,CAAC,CAAC6D;IACb,CAAE;IAAAT,QAAA,eAEF,IAAArD,WAAA,CAAA6C,GAAA;MAAK5B,GAAG,EAAEC,MAAO;MAAAmC,QAAA,EAAEhB;IAAW,CAAM;EAAC,CAC5B,CAAC;AAEhB,CAAC,CAAC;AAAC,IAAA0B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEYzD,OAAO","ignoreList":[]}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
8
|
var _react = require("react");
|
|
10
9
|
var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
|
|
11
10
|
var _Options = _interopRequireWildcard(require("./Options"));
|
|
@@ -92,7 +91,7 @@ const BaseCustomDropdown = ({
|
|
|
92
91
|
});
|
|
93
92
|
for (let i = 0; i < options.length; ++i) {
|
|
94
93
|
const option = options[i];
|
|
95
|
-
if (!filter || filter(option)) {
|
|
94
|
+
if (option !== undefined && (!filter || filter(option))) {
|
|
96
95
|
const [iValue, iName] = (0, _common.optionValueName)(option);
|
|
97
96
|
if (iValue === value) {
|
|
98
97
|
selected = iName;
|
|
@@ -140,14 +139,5 @@ const BaseCustomDropdown = ({
|
|
|
140
139
|
}) : null]
|
|
141
140
|
});
|
|
142
141
|
};
|
|
143
|
-
|
|
144
|
-
BaseCustomDropdown.propTypes = {
|
|
145
|
-
filter: _propTypes.default.func,
|
|
146
|
-
label: _propTypes.default.node,
|
|
147
|
-
onChange: _propTypes.default.func,
|
|
148
|
-
options: _propTypes.default.arrayOf(_common.optionValidator.isRequired),
|
|
149
|
-
theme: ThemedCustomDropdown.themeType.isRequired,
|
|
150
|
-
value: _common.valueValidator
|
|
151
|
-
};
|
|
152
|
-
var _default = exports.default = ThemedCustomDropdown;
|
|
142
|
+
var _default = exports.default = (0, _reactThemes.default)(BaseCustomDropdown, 'CustomDropdown', defaultTheme);
|
|
153
143
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_reactThemes","_Options","_interopRequireWildcard","_common","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","BaseCustomDropdown","filter","label","onChange","options","theme","value","Error","active","setActive","useState","dropdownRef","useRef","opsRef","opsPos","setOpsPos","upward","setUpward","useEffect","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","areEqual","requestAnimationFrame","cancelAnimationFrame","openList","view","rect","stopPropagation","selected","jsx","Fragment","children","length","option","iValue","iName","optionValueName","containerClassName","container","opsContainerClass","select","jsxs","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass","ThemedCustomDropdown","themed","validThemeKeys","propTypes","PT","func","node","arrayOf","optionValidator","isRequired","themeType","valueValidator","_default","exports"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport { useEffect, useRef, useState } from 'react';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nimport {\n type PropsT,\n type ValueT,\n optionValidator,\n optionValueName,\n validThemeKeys,\n valueValidator,\n} from '../common';\n\nconst BaseCustomDropdown: React.FunctionComponent<\nPropsT<React.ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n top: anchor.top - opsRect.height - 1,\n left: anchor.left,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width || 0,\n top: view?.height || 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>‌</>;\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = theme.container;\n if (active) containerClassName += ` ${theme.active}`;\n\n let opsContainerClass = theme.select || '';\n if (upward) {\n containerClassName += ` ${theme.upward}`;\n opsContainerClass += ` ${theme.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null : (\n <div className={theme.label}>{label}</div>\n )}\n <div\n className={theme.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={theme.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={theme.option || ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nconst ThemedCustomDropdown = themed(\n BaseCustomDropdown,\n 'CustomDropdown',\n validThemeKeys,\n defaultTheme,\n);\n\nBaseCustomDropdown.propTypes = {\n filter: PT.func,\n label: PT.node,\n onChange: PT.func,\n options: PT.arrayOf(optionValidator.isRequired),\n theme: ThemedCustomDropdown.themeType.isRequired,\n value: valueValidator,\n};\n\nexport default ThemedCustomDropdown;\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAOmB,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,C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AAI,EAAG;MAChC/C,OAAO,EAAEA,OAAQ;MACjB6D,GAAG,EAAEpD;IAAO,CACb,CAAC,GACA,IAAI;EAAA,CAEP,CAAC;AAEV,CAAC;AAED,MAAM6D,oBAAoB,GAAG,IAAAC,oBAAM,EACjC3E,kBAAkB,EAClB,gBAAgB,EAChB4E,sBAAc,EACd7E,YACF,CAAC;AAEDC,kBAAkB,CAAC6E,SAAS,GAAG;EAC7B5E,MAAM,EAAE6E,kBAAE,CAACC,IAAI;EACf7E,KAAK,EAAE4E,kBAAE,CAACE,IAAI;EACd7E,QAAQ,EAAE2E,kBAAE,CAACC,IAAI;EACjB3E,OAAO,EAAE0E,kBAAE,CAACG,OAAO,CAACC,uBAAe,CAACC,UAAU,CAAC;EAC/C9E,KAAK,EAAEqE,oBAAoB,CAACU,SAAS,CAACD,UAAU;EAChD7E,KAAK,EAAE+E;AACT,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAtG,OAAA,GAEayF,oBAAoB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","require","_reactThemes","_interopRequireDefault","_Options","_interopRequireWildcard","_common","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","BaseCustomDropdown","filter","label","onChange","options","theme","value","Error","active","setActive","useState","dropdownRef","useRef","opsRef","opsPos","setOpsPos","upward","setUpward","useEffect","undefined","id","cb","anchor","current","getBoundingClientRect","opsRect","measure","fitsDown","bottom","height","window","visualViewport","fitsUp","top","up","pos","left","width","now","areEqual","requestAnimationFrame","cancelAnimationFrame","openList","view","rect","stopPropagation","selected","jsx","Fragment","children","length","option","iValue","iName","optionValueName","containerClassName","container","opsContainerClass","select","jsxs","className","dropdown","onClick","onKeyDown","key","ref","role","tabIndex","arrow","containerClass","containerStyle","onCancel","newValue","optionClass","_default","exports","themed"],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nconst BaseCustomDropdown: React.FunctionComponent<\nPropsT<React.ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n top: anchor.top - opsRect.height - 1,\n left: anchor.left,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n const rect = dropdownRef.current!.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width || 0,\n top: view?.height || 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>‌</>;\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!filter || filter(option))) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = theme.container;\n if (active) containerClassName += ` ${theme.active}`;\n\n let opsContainerClass = theme.select || '';\n if (upward) {\n containerClassName += ` ${theme.upward}`;\n opsContainerClass += ` ${theme.upward}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null : (\n <div className={theme.label}>{label}</div>\n )}\n <div\n className={theme.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={theme.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={theme.option || ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default themed(BaseCustomDropdown, 'CustomDropdown', defaultTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,QAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAAsE,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,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,CAAC,KAAK,CAAC;MAClB,CAAE;MACFN,QAAQ,EAAGqE,QAAQ,IAAK;QACtB/D,SAAS,CAAC,KAAK,CAAC;QAChB,IAAIN,QAAQ,EAAEA,QAAQ,CAACqE,QAAQ,CAAC;MAClC,CAAE;MACFC,WAAW,EAAEpE,KAAK,CAAC8C,MAAM,IAAI,EAAG;MAChC/C,OAAO,EAAEA,OAAQ;MACjB6D,GAAG,EAAEpD;IAAO,CACb,CAAC,GACA,IAAI;EAAA,CAEP,CAAC;AAEV,CAAC;AAAC,IAAA6D,QAAA,GAAAC,OAAA,CAAA1F,OAAA,GAEa,IAAA2F,oBAAM,EAAC5E,kBAAkB,EAAE,gBAAgB,EAAED,YAAY,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
8
|
var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
|
|
10
9
|
var _common = require("../common");
|
|
11
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -55,7 +54,7 @@ const Dropdown = ({
|
|
|
55
54
|
const optionElements = [];
|
|
56
55
|
for (let i = 0; i < options.length; ++i) {
|
|
57
56
|
const option = options[i];
|
|
58
|
-
if (!filter || filter(option)) {
|
|
57
|
+
if (option !== undefined && (!filter || filter(option))) {
|
|
59
58
|
const [iValue, iName] = (0, _common.optionValueName)(option);
|
|
60
59
|
isValidValue ||= iValue === value;
|
|
61
60
|
optionElements.push( /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
|
|
@@ -94,14 +93,5 @@ const Dropdown = ({
|
|
|
94
93
|
})]
|
|
95
94
|
});
|
|
96
95
|
};
|
|
97
|
-
|
|
98
|
-
Dropdown.propTypes = {
|
|
99
|
-
filter: _propTypes.default.func,
|
|
100
|
-
label: _propTypes.default.node,
|
|
101
|
-
onChange: _propTypes.default.func,
|
|
102
|
-
options: _common.stringOptionsValidator,
|
|
103
|
-
theme: ThemedDropdown.themeType.isRequired,
|
|
104
|
-
value: _common.valueValidator
|
|
105
|
-
};
|
|
106
|
-
var _default = exports.default = ThemedDropdown;
|
|
96
|
+
var _default = exports.default = (0, _reactThemes.default)(Dropdown, 'Dropdown', defaultTheme);
|
|
107
97
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_reactThemes","_interopRequireDefault","require","_common","_jsxRuntime","defaultTheme","Dropdown","filter","label","onChange","options","theme","value","Error","isValidValue","optionElements","i","length","option","undefined","iValue","iName","optionValueName","push","jsx","className","children","hiddenOption","disabled","jsxs","container","dropdown","select","arrow","_default","exports","default","themed"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\nimport { type PropsT, optionValueName } from '../common';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: React.FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n let isValidValue = false;\n const optionElements = [];\n\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (option !== undefined && (!filter || filter(option))) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={theme.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n disabled\n className={theme.hiddenOption}\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n return (\n <div className={theme.container}>\n { label === undefined ? null : <div className={theme.label}>{label}</div> }\n <div className={theme.dropdown}>\n <select\n className={theme.select}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={theme.arrow} />\n </div>\n </div>\n );\n};\n\nexport default themed(Dropdown, 'Dropdown', defaultTheme);\n"],"mappings":";;;;;;;AAEA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AAAyD,IAAAE,WAAA,GAAAF,OAAA;AANzD;AAAA,MAAAG,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAiD,GAAGA,CAAC;EACzDC,MAAM;EACNC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,IAAI,CAACF,OAAO,EAAE,MAAMG,KAAK,CAAC,gBAAgB,CAAC;EAE3C,IAAIC,YAAY,GAAG,KAAK;EACxB,MAAMC,cAAc,GAAG,EAAE;EAEzB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,OAAO,CA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,CACT,CAAC,eACT,IAAAX,WAAA,CAAAoB,GAAA;QAAKC,SAAS,EAAEd,KAAK,CAACsB;MAAM,CAAE,CAAC;IAAA,CAC5B,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,oBAAM,EAAC/B,QAAQ,EAAE,UAAU,EAAED,YAAY,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
8
|
var _reactThemes = _interopRequireDefault(require("@dr.pogodin/react-themes"));
|
|
10
9
|
var _common = require("../common");
|
|
11
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -18,7 +17,6 @@ const defaultTheme = {
|
|
|
18
17
|
"selected": "-dr-pogodin-react-utils___src-shared-components-selectors-Switch-theme___selected___Wco-qk",
|
|
19
18
|
"options": "-dr-pogodin-react-utils___src-shared-components-selectors-Switch-theme___options___CZYtcC"
|
|
20
19
|
};
|
|
21
|
-
const validThemeKeys = ['container', 'label', 'option', 'options', 'selected'];
|
|
22
20
|
const BaseSwitch = ({
|
|
23
21
|
label,
|
|
24
22
|
onChange,
|
|
@@ -29,23 +27,26 @@ const BaseSwitch = ({
|
|
|
29
27
|
if (!options || !theme.option) throw Error('Internal error');
|
|
30
28
|
const optionNodes = [];
|
|
31
29
|
for (let i = 0; i < options?.length; ++i) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
className
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
const option = options[i];
|
|
31
|
+
if (option !== undefined) {
|
|
32
|
+
const [iValue, iName] = (0, _common.optionValueName)(option);
|
|
33
|
+
let className = theme.option;
|
|
34
|
+
let onPress;
|
|
35
|
+
if (iValue === value) className += ` ${theme.selected}`;else if (onChange) onPress = () => onChange(iValue);
|
|
36
|
+
optionNodes.push(onPress ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
37
|
+
className: className,
|
|
38
|
+
onClick: onPress,
|
|
39
|
+
onKeyDown: e => {
|
|
40
|
+
if (onPress && e.key === 'Enter') onPress();
|
|
41
|
+
},
|
|
42
|
+
role: "button",
|
|
43
|
+
tabIndex: 0,
|
|
44
|
+
children: iName
|
|
45
|
+
}, iValue) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
46
|
+
className: className,
|
|
47
|
+
children: iName
|
|
48
|
+
}, iValue));
|
|
49
|
+
}
|
|
49
50
|
}
|
|
50
51
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
51
52
|
className: theme.container,
|
|
@@ -58,13 +59,5 @@ const BaseSwitch = ({
|
|
|
58
59
|
})]
|
|
59
60
|
});
|
|
60
61
|
};
|
|
61
|
-
|
|
62
|
-
BaseSwitch.propTypes = {
|
|
63
|
-
label: _propTypes.default.node,
|
|
64
|
-
onChange: _propTypes.default.func,
|
|
65
|
-
options: _common.optionsValidator,
|
|
66
|
-
theme: ThemedSwitch.themeType.isRequired,
|
|
67
|
-
value: _common.valueValidator
|
|
68
|
-
};
|
|
69
|
-
var _default = exports.default = ThemedSwitch;
|
|
62
|
+
var _default = exports.default = (0, _reactThemes.default)(BaseSwitch, 'Switch', defaultTheme);
|
|
70
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_reactThemes","_interopRequireDefault","require","_common","_jsxRuntime","defaultTheme","BaseSwitch","label","onChange","options","theme","value","option","Error","optionNodes","i","length","undefined","iValue","iName","optionValueName","className","onPress","selected","push","jsx","onClick","onKeyDown","e","key","role","tabIndex","children","jsxs","container","_default","exports","default","themed"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import themed, { type Theme } 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 ThemeKeyT =\n | 'container'\n | 'label'\n | 'option'\n | 'options'\n | 'selected';\n\ntype PropsT = {\n label?: React.ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<React.ReactNode>>;\n theme: Theme<ThemeKeyT>;\n value?: ValueT;\n};\n\nconst BaseSwitch: React.FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options || !theme.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (let i = 0; i < options?.length; ++i) {\n const option = options[i];\n if (option !== undefined) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = theme.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${theme.selected}`;\n else if (onChange) onPress = () => onChange(iValue);\n\n optionNodes.push(\n onPress ? (\n <div\n className={className}\n onClick={onPress}\n onKeyDown={(e) => {\n if (onPress && e.key === 'Enter') onPress();\n }}\n key={iValue}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n ) : (\n <div className={className} key={iValue}>{iName}</div>\n ),\n );\n }\n }\n\n return (\n <div className={theme.container}>\n {label ? <div className={theme.label}>{label}</div> : null}\n <div className={theme.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n\nexport default themed(BaseSwitch, 'Switch', defaultTheme);\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAImB,IAAAE,WAAA,GAAAF,OAAA;AAAA,MAAAG,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AA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EAEA,oBACE,IAAAd,WAAA,CAAA6B,IAAA;IAAKZ,SAAS,EAAEX,KAAK,CAACwB,SAAU;IAAAF,QAAA,GAC7BzB,KAAK,gBAAG,IAAAH,WAAA,CAAAqB,GAAA;MAAKJ,SAAS,EAAEX,KAAK,CAACH,KAAM;MAAAyB,QAAA,EAAEzB;IAAK,CAAM,CAAC,GAAG,IAAI,eAC1D,IAAAH,WAAA,CAAAqB,GAAA;MAAKJ,SAAS,EAAEX,KAAK,CAACD,OAAQ;MAAAuB,QAAA,EAC3BlB;IAAW,CACT,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAAC,IAAAqB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,oBAAM,EAAChC,UAAU,EAAE,QAAQ,EAAED,YAAY,CAAC","ignoreList":[]}
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.optionValidator = void 0;
|
|
8
6
|
exports.optionValueName = optionValueName;
|
|
9
|
-
exports.valueValidator = exports.validThemeKeys = exports.stringOptionsValidator = exports.stringOptionValidator = exports.optionsValidator = void 0;
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
7
|
// The stuff common between different dropdown implementations.
|
|
12
8
|
|
|
13
|
-
const validThemeKeys = exports.validThemeKeys = ['active', 'arrow', 'container', 'dropdown', 'hiddenOption', 'label', 'option', 'select',
|
|
14
|
-
// TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it
|
|
15
|
-
// into a separate theme spec for that component.
|
|
16
|
-
'upward'];
|
|
17
|
-
const valueValidator = exports.valueValidator = _propTypes.default.oneOfType([_propTypes.default.number.isRequired, _propTypes.default.string.isRequired]);
|
|
18
|
-
const optionValidator = exports.optionValidator = _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
19
|
-
name: _propTypes.default.node,
|
|
20
|
-
value: valueValidator.isRequired
|
|
21
|
-
}).isRequired, _propTypes.default.number.isRequired, _propTypes.default.string.isRequired]);
|
|
22
|
-
const optionsValidator = exports.optionsValidator = _propTypes.default.arrayOf(optionValidator.isRequired);
|
|
23
|
-
const stringOptionValidator = exports.stringOptionValidator = _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
24
|
-
name: _propTypes.default.string,
|
|
25
|
-
value: valueValidator.isRequired
|
|
26
|
-
}).isRequired, _propTypes.default.number.isRequired, _propTypes.default.string.isRequired]);
|
|
27
|
-
const stringOptionsValidator = exports.stringOptionsValidator = _propTypes.default.arrayOf(stringOptionValidator.isRequired);
|
|
28
9
|
function isValue(x) {
|
|
29
10
|
const type = typeof x;
|
|
30
11
|
return type === 'number' || type === 'string';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","names":["
|
|
1
|
+
{"version":3,"file":"common.js","names":["isValue","x","type","optionValueName","option","value","name"],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\ntype ThemeKeyT =\n | 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward';\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: React.ReactNode;\n onChange?: OnChangeT;\n options?: Readonly<OptionsT<NameT>>;\n theme: Theme<ThemeKeyT>;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":";;;;;;AAAA;;AAuCA,SAASA,OAAOA,CAAIC,CAAsB,EAAe;EACvD,MAAMC,IAAI,GAAG,OAAOD,CAAC;EACrB,OAAOC,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,QAAQ;AAC/C;;AAEA;AACO,SAASC,eAAeA,CAC7BC,MAA+B,EACL;EAC1B,OAAOJ,OAAO,CAACI,MAAM,CAAC,GAClB,CAACA,MAAM,EAAEA,MAAM,CAAC,GAChB,CAACA,MAAM,CAACC,KAAK,EAAED,MAAM,CAACE,IAAI,IAAIF,MAAM,CAACC,KAAK,CAAC;AACjD","ignoreList":[]}
|
|
@@ -22,20 +22,7 @@ Object.defineProperty(exports, "Switch", {
|
|
|
22
22
|
return _Switch.default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
Object.defineProperty(exports, "optionValidator", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _common.optionValidator;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "optionsValidator", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _common.optionsValidator;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
25
|
var _CustomDropdown = _interopRequireDefault(require("./CustomDropdown"));
|
|
38
26
|
var _NativeDropdown = _interopRequireDefault(require("./NativeDropdown"));
|
|
39
27
|
var _Switch = _interopRequireDefault(require("./Switch"));
|
|
40
|
-
var _common = require("./common");
|
|
41
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_CustomDropdown","_interopRequireDefault","require","_NativeDropdown","_Switch"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_CustomDropdown","_interopRequireDefault","require","_NativeDropdown","_Switch"],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { default as Switch } from './Switch';\n\nexport {\n type OptionT,\n type OptionsT,\n} from './common';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -107,12 +107,14 @@ function mount(scene) {
|
|
|
107
107
|
});
|
|
108
108
|
return res;
|
|
109
109
|
}
|
|
110
|
-
function snapshot(element) {
|
|
110
|
+
async function snapshot(element, options) {
|
|
111
111
|
let res;
|
|
112
|
-
(0, _react.act)(() => {
|
|
112
|
+
const promise = (0, _react.act)(() => {
|
|
113
113
|
res = (0, _react2.render)(element);
|
|
114
|
+
return options?.await;
|
|
114
115
|
});
|
|
115
116
|
if (res === undefined) throw Error('Render failed');
|
|
117
|
+
if (options?.await) await promise;
|
|
116
118
|
const nodes = res.asFragment().childNodes;
|
|
117
119
|
expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();
|
|
118
120
|
return res;
|