@dr.pogodin/react-utils 1.33.4 → 1.34.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.
- package/build/development/shared/components/Button/index.js +0 -38
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +0 -5
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +0 -12
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +0 -3
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +0 -8
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +0 -8
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +0 -5
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +0 -7
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +0 -3
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +1 -6
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +0 -4
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +0 -4
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +0 -7
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +0 -7
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +0 -6
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +16 -75
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +0 -3
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/web.bundle.js +22 -32
- package/build/production/shared/components/Button/index.js +1 -26
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +1 -1
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +1 -1
- 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 +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +1 -1
- 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 +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
- 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/utils/jest/index.js +7 -33
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +1 -1
- 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/shared/utils/jest/index.d.ts +3 -43
- package/config/eslint/default.json +2 -1
- package/config/eslint/jest.json +2 -1
- package/config/eslint/typescript.js +5 -0
- package/package.json +40 -39
- package/src/shared/components/Button/index.tsx +0 -38
- package/src/shared/components/Checkbox/index.tsx +0 -6
- package/src/shared/components/GenericLink/index.tsx +0 -13
- package/src/shared/components/Input/index.tsx +0 -4
- package/src/shared/components/MetaTags.tsx +0 -9
- package/src/shared/components/Modal/index.tsx +0 -10
- package/src/shared/components/PageLayout/index.tsx +0 -6
- package/src/shared/components/TextArea/index.tsx +0 -8
- package/src/shared/components/WithTooltip/Tooltip.tsx +0 -4
- package/src/shared/components/WithTooltip/index.tsx +1 -7
- package/src/shared/components/YouTubeVideo/index.tsx +0 -5
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -5
- package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -8
- package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -8
- package/src/shared/components/selectors/Switch/index.tsx +0 -7
- package/src/shared/utils/jest/index.tsx +14 -64
- package/src/shared/utils/splitComponent.tsx +1 -5
|
@@ -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","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","PLACEMENTS","propTypes","PT","node","oneOf","values","themeType","isRequired","defaultProps","ABOVE_CURSOR","_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,\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\nWrapper.defaultProps = {\n children: null,\n placement: PLACEMENTS.ABOVE_CURSOR,\n tip: null,\n};\n\nexport default e;\n"],"mappings":"gLAEA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,MAAA,CAAAD,OAAA,UAOA,IAAAE,YAAA,CAAAH,sBAAA,CAAAC,OAAA,8BAEA,IAAAG,QAAA,CAAAC,uBAAA,CAAAJ,OAAA,eAGmB,IAAAK,WAAA,CAAAL,OAAA,+BAAAM,yBAAAC,CAAA,wBAAAC,OAAA,iBAAAC,CAAA,KAAAD,OAAA,CAAAE,CAAA,KAAAF,OAAA,QAAAF,wBAAA,SAAAA,CAAAC,CAAA,SAAAA,CAAA,CAAAG,CAAA,CAAAD,CAAA,GAAAF,CAAA,WAAAH,wBAAAG,CAAA,CAAAE,CAAA,MAAAA,CAAA,EAAAF,CAAA,EAAAA,CAAA,CAAAI,UAAA,QAAAJ,CAAA,WAAAA,CAAA,mBAAAA,CAAA,qBAAAA,CAAA,QAAAK,OAA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9C,QAAA,EAGjBc,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACzB,GAAA3B,WAAA,CAAAwE,GAAA,EAAC1E,QAAA,CAAAS,OAAO,EAAC+D,GAAG,CAAEjC,UAAW,CAACT,KAAK,CAAEA,KAAM,CAAAH,QAAA,CAAEE,GAAG,CAAU,CAAC,CACrD,IAAI,CAETF,QAAQ,EACN,CAET,CAAC,CAED,KAAM,CAAAgD,aAAa,CAAG,GAAAC,oBAAM,EAC1BlD,OAAO,CACP,aAAa,CACb,CACE,YAAY,CACZ,OAAO,CACP,WAAW,CACX,SAAS,CACT,SAAS,CACV,CACDH,YACF,CAAC,CAMD,KAAM,CAAAnB,CAAU,CAAGuE,aAAwB,CAE3CvE,CAAC,CAACyE,UAAU,CAAGA,mBAAU,CAEzBnD,OAAO,CAACoD,SAAS,CAAG,CAClBnD,QAAQ,CAAEoD,kBAAE,CAACC,IAAI,CACjBpD,SAAS,CAAEmD,kBAAE,CAACE,KAAK,CAAClE,MAAM,CAACmE,MAAM,CAACL,mBAAU,CAAC,CAAC,CAC9C/C,KAAK,CAAE6C,aAAa,CAACQ,SAAS,CAACC,UAAU,CACzCvD,GAAG,CAAEkD,kBAAE,CAACC,IACV,CAAC,CAEDtD,OAAO,CAAC2D,YAAY,CAAG,CACrB1D,QAAQ,CAAE,IAAI,CACdC,SAAS,CAAEiD,mBAAU,CAACS,YAAY,CAClCzD,GAAG,CAAE,IACP,CAAC,CAAC,IAAA0D,QAAA,CAAAC,OAAA,CAAA/E,OAAA,CAEaL,CAAC","ignoreList":[]}
|
|
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":"gLAEA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,MAAA,CAAAD,OAAA,UAOA,IAAAE,YAAA,CAAAH,sBAAA,CAAAC,OAAA,8BAEA,IAAAG,QAAA,CAAAC,uBAAA,CAAAJ,OAAA,eAGmB,IAAAK,WAAA,CAAAL,OAAA,+BAAAM,yBAAAC,CAAA,wBAAAC,OAAA,iBAAAC,CAAA,KAAAD,OAAA,CAAAE,CAAA,KAAAF,OAAA,QAAAF,wBAAA,SAAAA,CAAAC,CAAA,SAAAA,CAAA,CAAAG,CAAA,CAAAD,CAAA,GAAAF,CAAA,WAAAH,wBAAAG,CAAA,CAAAE,CAAA,MAAAA,CAAA,EAAAF,C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CAAEA,CAAA,GAAM,CAClBvC,IAAI,CAACI,gBAAgB,CAAG,IAC1B,CAAE,CACFoC,GAAG,CAAEhC,UAAW,CAChBiC,IAAI,CAAC,cAAc,CAAAhD,QAAA,EAGjBgB,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACzB,GAAA7B,WAAA,CAAA0E,GAAA,EAAC5E,QAAA,CAAAS,OAAO,EAACiE,GAAG,CAAEjC,UAAW,CAACT,KAAK,CAAEA,KAAM,CAAAL,QAAA,CAAEI,GAAG,CAAU,CAAC,CACrD,IAAI,CAETJ,QAAQ,EACN,CAET,CAAC,CAED,KAAM,CAAAkD,aAAa,CAAG,GAAAC,oBAAM,EAC1BpD,OAAO,CACP,aAAa,CACb,CACE,YAAY,CACZ,OAAO,CACP,WAAW,CACX,SAAS,CACT,SAAS,CACV,CACDH,YACF,CAAC,CAMD,KAAM,CAAAnB,CAAU,CAAGyE,aAAwB,CAE3CzE,CAAC,CAACyB,UAAU,CAAGA,mBAAU,CAEzBH,OAAO,CAACqD,SAAS,CAAG,CAClBpD,QAAQ,CAAEqD,kBAAE,CAACC,IAAI,CACjBrD,SAAS,CAAEoD,kBAAE,CAACE,KAAK,CAACnE,MAAM,CAACoE,MAAM,CAACtD,mBAAU,CAAC,CAAC,CAC9CG,KAAK,CAAE6C,aAAa,CAACO,SAAS,CAACC,UAAU,CACzCtD,GAAG,CAAEiD,kBAAE,CAACC,IACV,CAAC,CAAC,IAAAK,QAAA,CAAAC,OAAA,CAAA9E,OAAA,CAEaL,CAAC","ignoreList":[]}
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* IFrame.
|
|
15
15
|
*/const YouTubeVideo=({autoplay,src,theme,title})=>{const srcParts=src.split("?");let url=srcParts[0];const queryString=srcParts[1];const query=queryString?_qs.default.parse(queryString):{};const videoId=query.v||url.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];url=`https://www.youtube.com/embed/${videoId}`;delete query.v;query.autoplay=autoplay?"1":"0";url+=`?${_qs.default.stringify(query)}`;// TODO: https://developers.google.com/youtube/player_parameters
|
|
16
16
|
// More query parameters can be exposed via the component props.
|
|
17
|
-
return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Throbber.default,{theme:throbberTheme}),/*#__PURE__*/(0,_jsxRuntime.jsx)("iframe",{allow:"autoplay",allowFullScreen:true,className:theme.video,src:url,title:title})]})};const ThemedYouTubeVideo=(0,_reactThemes.default)(YouTubeVideo,"YouTubeVideo",validThemeKeys,baseTheme);YouTubeVideo.propTypes={autoplay:_propTypes.default.bool,src:_propTypes.default.string.isRequired,theme:ThemedYouTubeVideo.themeType.isRequired,title:_propTypes.default.string};
|
|
17
|
+
return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Throbber.default,{theme:throbberTheme}),/*#__PURE__*/(0,_jsxRuntime.jsx)("iframe",{allow:"autoplay",allowFullScreen:true,className:theme.video,src:url,title:title})]})};const ThemedYouTubeVideo=(0,_reactThemes.default)(YouTubeVideo,"YouTubeVideo",validThemeKeys,baseTheme);YouTubeVideo.propTypes={autoplay:_propTypes.default.bool,src:_propTypes.default.string.isRequired,theme:ThemedYouTubeVideo.themeType.isRequired,title:_propTypes.default.string};var _default=exports.default=ThemedYouTubeVideo;
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_qs","_reactThemes","_Throbber","_jsxRuntime","baseTheme","throbberTheme","validThemeKeys","YouTubeVideo","autoplay","src","theme","title","srcParts","split","url","queryString","query","qs","parse","videoId","v","match","stringify","jsxs","className","container","children","jsx","default","allow","allowFullScreen","video","ThemedYouTubeVideo","themed","propTypes","PT","bool","string","isRequired","themeType","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_qs","_reactThemes","_Throbber","_jsxRuntime","baseTheme","throbberTheme","validThemeKeys","YouTubeVideo","autoplay","src","theme","title","srcParts","split","url","queryString","query","qs","parse","videoId","v","match","stringify","jsxs","className","container","children","jsx","default","allow","allowFullScreen","video","ThemedYouTubeVideo","themed","propTypes","PT","bool","string","isRequired","themeType","_default","exports"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport qs from 'qs';\n\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport baseTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\nconst validThemeKeys = ['container', 'video'] as const;\n\ntype ComponentThemeT = Theme<typeof validThemeKeys>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme: ComponentThemeT,\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: React.FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const srcParts = src.split('?');\n let url = srcParts[0];\n const queryString = srcParts[1];\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v || url.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={theme.container}>\n <Throbber theme={throbberTheme} />\n <iframe\n allow=\"autoplay\"\n allowFullScreen\n className={theme.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nconst ThemedYouTubeVideo = themed(\n YouTubeVideo,\n 'YouTubeVideo',\n validThemeKeys,\n baseTheme,\n);\n\nYouTubeVideo.propTypes = {\n autoplay: PT.bool,\n src: PT.string.isRequired,\n theme: ThemedYouTubeVideo.themeType.isRequired,\n title: PT.string,\n};\n\nexport default ThemedYouTubeVideo;\n"],"mappings":"gLAAA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,GAAA,CAAAF,sBAAA,CAAAC,OAAA,QAEA,IAAAE,YAAA,CAAAH,sBAAA,CAAAC,OAAA,8BAEA,IAAAG,SAAA,CAAAJ,sBAAA,CAAAC,OAAA,iBAA2C,IAAAI,WAAA,CAAAJ,OAAA,4BAAAK,SAAA,+FAAAC,aAAA,0EAK3C,KAAM,CAAAC,cAAc,CAAG,CAAC,WAAW,CAAE,OAAO,CAAU,CAWtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,YAA6C,CAAGA,CAAC,CACrDC,QAAQ,CACRC,GAAG,CACHC,KAAK,CACLC,KACF,CAAC,GAAK,CACJ,KAAM,CAAAC,QAAQ,CAAGH,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,CAC/B,GAAI,CAAAC,GAAG,CAAGF,QAAQ,CAAC,CAAC,CAAC,CACrB,KAAM,CAAAG,WAAW,CAAGH,QAAQ,CAAC,CAAC,CAAC,CAC/B,KAAM,CAAAI,KAAK,CAAGD,WAAW,CAAGE,WAAE,CAACC,KAAK,CAACH,WAAW,CAAC,CAAG,CAAC,CAAC,CAEtD,KAAM,CAAAI,OAAO,CAAGH,KAAK,CAACI,CAAC,EAAIN,GAAG,CAACO,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAChEP,GAAG,CAAI,iCAAgCK,OAAQ,EAAC,CAEhD,MAAO,CAAAH,KAAK,CAACI,CAAC,CACdJ,KAAK,CAACR,QAAQ,CAAGA,QAAQ,CAAG,GAAG,CAAG,GAAG,CACrCM,GAAG,EAAK,IAAGG,WAAE,CAACK,SAAS,CAACN,KAAK,CAAE,EAAC,CAEhC;AACA;AAEA,mBACE,GAAAb,WAAA,CAAAoB,IAAA,SAAKC,SAAS,CAAEd,KAAK,CAACe,SAAU,CAAAC,QAAA,eAC9B,GAAAvB,WAAA,CAAAwB,GAAA,EAACzB,SAAA,CAAA0B,OAAQ,EAAClB,KAAK,CAAEL,aAAc,CAAE,CAAC,cAClC,GAAAF,WAAA,CAAAwB,GAAA,YACEE,KAAK,CAAC,UAAU,CAChBC,eAAe,MACfN,SAAS,CAAEd,KAAK,CAACqB,KAAM,CACvBtB,GAAG,CAAEK,GAAI,CACTH,KAAK,CAAEA,KAAM,CACd,CAAC,EACC,CAET,CAAC,CAED,KAAM,CAAAqB,kBAAkB,CAAG,GAAAC,oBAAM,EAC/B1B,YAAY,CACZ,cAAc,CACdD,cAAc,CACdF,SACF,CAAC,CAEDG,YAAY,CAAC2B,SAAS,CAAG,CACvB1B,QAAQ,CAAE2B,kBAAE,CAACC,IAAI,CACjB3B,GAAG,CAAE0B,kBAAE,CAACE,MAAM,CAACC,UAAU,CACzB5B,KAAK,CAAEsB,kBAAkB,CAACO,SAAS,CAACD,UAAU,CAC9C3B,KAAK,CAAEwB,kBAAE,CAACE,MACZ,CAAC,CAAC,IAAAG,QAAA,CAAAC,OAAA,CAAAb,OAAA,CAEaI,kBAAkB","ignoreList":[]}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
// now we have no reason to deal with complications needed to support open
|
|
4
4
|
// dropdowns during the scrolling (that would need to re-position it in
|
|
5
5
|
// response to the position changes of the root dropdown element).
|
|
6
|
-
,{cancelOnScrolling:true,containerStyle:containerStyle,dontDisableScrolling:true,onCancel:onCancel,theme:{ad:"",hoc:"",container:containerClass,context:"",overlay:S.overlay},children:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{ref:opsRef,children:optionNodes})})});Options.propTypes={containerClass:_propTypes.default.string.isRequired,containerStyle:_propTypes.default.shape({left:_propTypes.default.number.isRequired,top:_propTypes.default.number.isRequired,width:_propTypes.default.number.isRequired}),filter:_propTypes.default.func,onCancel:_propTypes.default.func.isRequired,onChange:_propTypes.default.func.isRequired,optionClass:_propTypes.default.string.isRequired,options:_common.optionsValidator.isRequired};
|
|
6
|
+
,{cancelOnScrolling:true,containerStyle:containerStyle,dontDisableScrolling:true,onCancel:onCancel,theme:{ad:"",hoc:"",container:containerClass,context:"",overlay:S.overlay},children:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{ref:opsRef,children:optionNodes})})});Options.propTypes={containerClass:_propTypes.default.string.isRequired,containerStyle:_propTypes.default.shape({left:_propTypes.default.number.isRequired,top:_propTypes.default.number.isRequired,width:_propTypes.default.number.isRequired}),filter:_propTypes.default.func,onCancel:_propTypes.default.func.isRequired,onChange:_propTypes.default.func.isRequired,optionClass:_propTypes.default.string.isRequired,options:_common.optionsValidator.isRequired};var _default=exports.default=Options;
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_Modal","_common","_jsxRuntime","S","areEqual","a","b","left","top","width","Options","forwardRef","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","useRef","useImperativeHandle","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","i","length","option","iValue","iName","optionValueName","push","jsx","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","BaseModal","cancelOnScrolling","dontDisableScrolling","theme","ad","hoc","container","context","overlay","propTypes","PT","string","isRequired","shape","number","func","optionsValidator","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_react","_Modal","_common","_jsxRuntime","S","areEqual","a","b","left","top","width","Options","forwardRef","containerClass","containerStyle","filter","onCancel","onChange","optionClass","options","ref","opsRef","useRef","useImperativeHandle","measure","e","current","parentElement","undefined","rect","getBoundingClientRect","style","window","getComputedStyle","mBottom","parseFloat","marginBottom","mTop","marginTop","height","optionNodes","i","length","option","iValue","iName","optionValueName","push","jsx","className","onClick","stopPropagation","onKeyDown","key","role","tabIndex","children","BaseModal","cancelOnScrolling","dontDisableScrolling","theme","ad","hoc","container","context","overlay","propTypes","PT","string","isRequired","shape","number","func","optionsValidator","_default","exports","default"],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport { forwardRef, useImperativeHandle, useRef } from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport S from './style.scss';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionsValidator,\n optionValueName,\n} from '../../common';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<React.ReactNode> | ValueT) => boolean;\n optionClass: string;\n options: OptionsT<React.ReactNode>;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n};\n\nconst Options = forwardRef<RefT, PropsT>(({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n}, ref) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n const rect = opsRef.current?.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: React.ReactNode[] = [];\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n key={iValue}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n containerStyle={containerStyle}\n dontDisableScrolling\n onCancel={onCancel}\n theme={{\n ad: '',\n hoc: '',\n container: containerClass,\n context: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n});\n\nOptions.propTypes = {\n containerClass: PT.string.isRequired,\n\n containerStyle: PT.shape({\n left: PT.number.isRequired,\n top: PT.number.isRequired,\n width: PT.number.isRequired,\n }),\n\n filter: PT.func,\n onCancel: PT.func.isRequired,\n onChange: PT.func.isRequired,\n optionClass: PT.string.isRequired,\n options: optionsValidator.isRequired,\n};\n\nexport default Options;\n"],"mappings":"0MAAA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,MAAA,CAAAD,OAAA,UAEA,IAAAE,MAAA,CAAAF,OAAA,mBAIA,IAAAG,OAAA,CAAAH,OAAA,iBAMsB,IAAAI,WAAA,CAAAJ,OAAA,4BAAAK,CAAA,sBAQf,QAAS,CAAAC,QAAQA,CAACC,CAAiB,CAAEC,CAAiB,CAAW,CACtE,MAAO,CAAAD,CAAC,EAAEE,IAAI,GAAKD,CAAC,EAAEC,IAAI,EAAIF,CAAC,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AAE,CAACI,MAAM,CAACF,UAAU,CACzB3D,KAAK,CAAEyD,kBAAE,CAACI,MAAM,CAACF,UACnB,CAAC,CAAC,CAEFtD,MAAM,CAAEoD,kBAAE,CAACK,IAAI,CACfxD,QAAQ,CAAEmD,kBAAE,CAACK,IAAI,CAACH,UAAU,CAC5BpD,QAAQ,CAAEkD,kBAAE,CAACK,IAAI,CAACH,UAAU,CAC5BnD,WAAW,CAAEiD,kBAAE,CAACC,MAAM,CAACC,UAAU,CACjClD,OAAO,CAAEsD,wBAAgB,CAACJ,UAC5B,CAAC,CAAC,IAAAK,QAAA,CAAAC,OAAA,CAAAC,OAAA,CAEajE,OAAO","ignoreList":[]}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
// (if we first open it downward, it would flick if we immediately
|
|
5
5
|
// move it above, at least with the current position update via local
|
|
6
6
|
// react state, and not imperatively).
|
|
7
|
-
setOpsPos({left:view?.width||0,top:view?.height||0,width:rect.width});e.stopPropagation()};let selected=/*#__PURE__*/(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:"\u200C"});for(let i=0;i<options.length;++i){const option=options[i];if(!filter||filter(option)){const[iValue,iName]=(0,_common.optionValueName)(option);if(iValue===value){selected=iName;break}}}let containerClassName=theme.container;if(active)containerClassName+=` ${theme.active}`;let opsContainerClass=theme.select||"";if(upward){containerClassName+=` ${theme.upward}`;opsContainerClass+=` ${theme.upward}`}return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:containerClassName,children:[label===undefined?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}),/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.dropdown,onClick:openList,onKeyDown:e=>{if(e.key==="Enter")openList(e)},ref:dropdownRef,role:"listbox",tabIndex:0,children:[selected,/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.arrow})]}),active?/*#__PURE__*/(0,_jsxRuntime.jsx)(_Options.default,{containerClass:opsContainerClass,containerStyle:opsPos,onCancel:()=>{setActive(false)},onChange:newValue=>{setActive(false);if(onChange)onChange(newValue)},optionClass:theme.option||"",options:options,ref:opsRef}):null]})};const ThemedCustomDropdown=(0,_reactThemes.default)(BaseCustomDropdown,"CustomDropdown",_common.validThemeKeys,defaultTheme);BaseCustomDropdown.propTypes={filter:_propTypes.default.func,label:_propTypes.default.node,onChange:_propTypes.default.func,options:_propTypes.default.arrayOf(_common.optionValidator.isRequired),theme:ThemedCustomDropdown.themeType.isRequired,value:_common.valueValidator};
|
|
7
|
+
setOpsPos({left:view?.width||0,top:view?.height||0,width:rect.width});e.stopPropagation()};let selected=/*#__PURE__*/(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:"\u200C"});for(let i=0;i<options.length;++i){const option=options[i];if(!filter||filter(option)){const[iValue,iName]=(0,_common.optionValueName)(option);if(iValue===value){selected=iName;break}}}let containerClassName=theme.container;if(active)containerClassName+=` ${theme.active}`;let opsContainerClass=theme.select||"";if(upward){containerClassName+=` ${theme.upward}`;opsContainerClass+=` ${theme.upward}`}return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:containerClassName,children:[label===undefined?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}),/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.dropdown,onClick:openList,onKeyDown:e=>{if(e.key==="Enter")openList(e)},ref:dropdownRef,role:"listbox",tabIndex:0,children:[selected,/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.arrow})]}),active?/*#__PURE__*/(0,_jsxRuntime.jsx)(_Options.default,{containerClass:opsContainerClass,containerStyle:opsPos,onCancel:()=>{setActive(false)},onChange:newValue=>{setActive(false);if(onChange)onChange(newValue)},optionClass:theme.option||"",options:options,ref:opsRef}):null]})};const ThemedCustomDropdown=(0,_reactThemes.default)(BaseCustomDropdown,"CustomDropdown",_common.validThemeKeys,defaultTheme);BaseCustomDropdown.propTypes={filter:_propTypes.default.func,label:_propTypes.default.node,onChange:_propTypes.default.func,options:_propTypes.default.arrayOf(_common.optionValidator.isRequired),theme:ThemedCustomDropdown.themeType.isRequired,value:_common.valueValidator};var _default=exports.default=ThemedCustomDropdown;
|
|
8
8
|
//# 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","defaultProps","_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\nBaseCustomDropdown.defaultProps = {\n filter: undefined,\n label: undefined,\n onChange: undefined,\n options: [],\n value: undefined,\n};\n\nexport default ThemedCustomDropdown;\n"],"mappings":"gLAAA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,MAAA,CAAAD,OAAA,UAEA,IAAAE,YAAA,CAAAH,sBAAA,CAAAC,OAAA,8BAEA,IAAAG,QAAA,CAAAC,uBAAA,CAAAJ,OAAA,eAIA,IAAAK,OAAA,CAAAL,OAAA,cAOmB,IAAAM,WAAA,CAAAN,OAAA,+BAAAO,yBAAAC,CAAA,wBAAAC,OAAA,iBAAAC,CAAA,KAAAD,OAAA,CAAAE,CAAA,KAAAF,OAAA,QAAAF,wBAAA,SAAAA,CAAAC,CAAA,SAAAA,CAAA,CAAAG,CAAA,CAAAD,CAAA,GAAAF,CAAA,WAAAJ,wBAAAI,CAAA,CAAAE,CAAA,MAAAA,CAAA,EAAAF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E,QAAQ,EAAK,CACtB/D,SAAS,CAAC,KAAK,CAAC,CAChB,GAAIN,QAAQ,CAAEA,QAAQ,CAACqE,QAAQ,CACjC,CAAE,CACFC,WAAW,CAAEpE,KAAK,CAAC8C,MAAM,EAAI,EAAG,CAChC/C,OAAO,CAAEA,OAAQ,CACjB6D,GAAG,CAAEpD,MAAO,CACb,CAAC,CACA,IAAI,EAEP,CAET,CAAC,CAED,KAAM,CAAA6D,oBAAoB,CAAG,GAAAC,oBAAM,EACjC3E,kBAAkB,CAClB,gBAAgB,CAChB4E,sBAAc,CACd7E,YACF,CAAC,CAEDC,kBAAkB,CAAC6E,SAAS,CAAG,CAC7B5E,MAAM,CAAE6E,kBAAE,CAACC,IAAI,CACf7E,KAAK,CAAE4E,kBAAE,CAACE,IAAI,CACd7E,QAAQ,CAAE2E,kBAAE,CAACC,IAAI,CACjB3E,OAAO,CAAE0E,kBAAE,CAACG,OAAO,CAACC,uBAAe,CAACC,UAAU,CAAC,CAC/C9E,KAAK,CAAEqE,oBAAoB,CAACU,SAAS,CAACD,UAAU,CAChD7E,KAAK,CAAE+E,sBACT,CAAC,CAEDrF,kBAAkB,CAACsF,YAAY,CAAG,CAChCrF,MAAM,CAAEkB,SAAS,CACjBjB,KAAK,CAAEiB,SAAS,CAChBhB,QAAQ,CAAEgB,SAAS,CACnBf,OAAO,CAAE,EAAE,CACXE,KAAK,CAAEa,SACT,CAAC,CAAC,IAAAoE,QAAA,CAAAC,OAAA,CAAAvG,OAAA,CAEayF,oBAAoB","ignoreList":[]}
|
|
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":"gLAAA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,MAAA,CAAAD,OAAA,UAEA,IAAAE,YAAA,CAAAH,sBAAA,CAAAC,OAAA,8BAEA,IAAAG,QAAA,CAAAC,uBAAA,CAAAJ,OAAA,eAIA,IAAAK,OAAA,CAAAL,OAAA,cAOmB,IAAAM,WAAA,CAAAN,OAAA,+BAAAO,yBAAAC,CAAA,wBAAAC,OAAA,iBAAAC,CAAA,KAAAD,OAAA,CAAAE,CAAA,KAAAF,OAAA,QAAAF,wBAAA,SAAAA,CAAAC,CAAA,SAAAA,CAAA,CAAAG,CAAA,CAAAD,CAAA,GAAAF,CAAA,WAAAJ,wBAAAI,CAAA,CAAAE,CAAA,MAAAA,CAAA,EAAAF,CAAA,EAAAA,CAAA,CAAAI,UAAA,QAAAJ,CAAA,WAAAA,CAAA,mBAAAA,CAAA,qBAAAA,CAAA,QAAAK,OAAA,CAAAL,CAAA,MAAAG,CAAA,CAAAJ,wBAAA,CAAAG,CAAA,KAAAC,CAAA,EAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,SAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,MAAAQ,CAAA,EAAAC,SAAA,OAAAC,CAAA,CAAAC,MAAA,CAAAC,cAAA,EAAAD,MAAA,CAAAE,wBAAA,SAAAC,CAAA,IAAAd,CAAA,gBAAAc,CAAA,KAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,CAAAc,CAAA,OAAAG,CAAA,CAAAP,CAAA,CAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,CAAAc,CAAA,OAAAG,CAAA,GAAAA,CA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AO,CAAE0E,kBAAE,CAACG,OAAO,CAACC,uBAAe,CAACC,UAAU,CAAC,CAC/C9E,KAAK,CAAEqE,oBAAoB,CAACU,SAAS,CAACD,UAAU,CAChD7E,KAAK,CAAE+E,sBACT,CAAC,CAAC,IAAAC,QAAA,CAAAC,OAAA,CAAAtG,OAAA,CAEayF,oBAAoB","ignoreList":[]}
|
|
@@ -21,5 +21,5 @@ const defaultTheme={"context":"xHyZo4","ad":"ADu59e","hoc":"FTP2bb","dropdown":"
|
|
|
21
21
|
// any valid option. In Chrome, and some other browsers, we are able to hide
|
|
22
22
|
// it from the opened dropdown; in others, e.g. Safari, the best we can do is
|
|
23
23
|
// to show it as disabled.
|
|
24
|
-
const hiddenOption=isValidValue?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("option",{disabled:true,className:theme.hiddenOption,value:value,children:value},"__reactUtilsHiddenOption");return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[label===undefined?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}),/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.dropdown,children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)("select",{className:theme.select,onChange:onChange,value:value,children:[hiddenOption,optionElements]}),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.arrow})]})]})};const ThemedDropdown=(0,_reactThemes.default)(Dropdown,"Dropdown",_common.validThemeKeys,defaultTheme);Dropdown.propTypes={filter:_propTypes.default.func,label:_propTypes.default.node,onChange:_propTypes.default.func,options:_common.stringOptionsValidator,theme:ThemedDropdown.themeType.isRequired,value:_common.valueValidator};
|
|
24
|
+
const hiddenOption=isValidValue?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("option",{disabled:true,className:theme.hiddenOption,value:value,children:value},"__reactUtilsHiddenOption");return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[label===undefined?null:/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}),/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.dropdown,children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)("select",{className:theme.select,onChange:onChange,value:value,children:[hiddenOption,optionElements]}),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.arrow})]})]})};const ThemedDropdown=(0,_reactThemes.default)(Dropdown,"Dropdown",_common.validThemeKeys,defaultTheme);Dropdown.propTypes={filter:_propTypes.default.func,label:_propTypes.default.node,onChange:_propTypes.default.func,options:_common.stringOptionsValidator,theme:ThemedDropdown.themeType.isRequired,value:_common.valueValidator};var _default=exports.default=ThemedDropdown;
|
|
25
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_reactThemes","_common","_jsxRuntime","defaultTheme","Dropdown","filter","label","onChange","options","theme","value","Error","isValidValue","optionElements","i","length","option","iValue","iName","optionValueName","push","jsx","className","children","hiddenOption","disabled","jsxs","container","undefined","dropdown","select","arrow","ThemedDropdown","themed","validThemeKeys","propTypes","PT","func","node","stringOptionsValidator","themeType","isRequired","valueValidator","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_reactThemes","_common","_jsxRuntime","defaultTheme","Dropdown","filter","label","onChange","options","theme","value","Error","isValidValue","optionElements","i","length","option","iValue","iName","optionValueName","push","jsx","className","children","hiddenOption","disabled","jsxs","container","undefined","dropdown","select","arrow","ThemedDropdown","themed","validThemeKeys","propTypes","PT","func","node","stringOptionsValidator","themeType","isRequired","valueValidator","_default","exports","default"],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport PT from 'prop-types';\n\nimport themed from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\nimport {\n type PropsT,\n optionValueName,\n stringOptionsValidator,\n validThemeKeys,\n valueValidator,\n} from '../common';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: React.FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options) throw Error('Internal error');\n\n let isValidValue = false;\n const optionElements = [];\n\n for (let i = 0; i < options.length; ++i) {\n const option = options[i];\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={theme.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n disabled\n className={theme.hiddenOption}\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n return (\n <div className={theme.container}>\n { label === undefined ? null : <div className={theme.label}>{label}</div> }\n <div className={theme.dropdown}>\n <select\n className={theme.select}\n onChange={onChange}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={theme.arrow} />\n </div>\n </div>\n );\n};\n\nconst ThemedDropdown = themed(\n Dropdown,\n 'Dropdown',\n validThemeKeys,\n defaultTheme,\n);\n\nDropdown.propTypes = {\n filter: PT.func,\n label: PT.node,\n onChange: PT.func,\n options: stringOptionsValidator,\n theme: ThemedDropdown.themeType.isRequired,\n value: valueValidator,\n};\n\nexport default ThemedDropdown;\n"],"mappings":"gLAEA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBAEA,IAAAC,YAAA,CAAAF,sBAAA,CAAAC,OAAA,8BAIA,IAAAE,OAAA,CAAAF,OAAA,cAMmB,IAAAG,WAAA,CAAAH,OAAA,sBAdnB;AAAA,MAAAI,YAAA,6MAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,QAAiD,CAAGA,CAAC,CACzDC,MAAM,CACNC,KAAK,CACLC,QAAQ,CACRC,OAAO,CACPC,KAAK,CACLC,KACF,CAAC,GAAK,CACJ,GAAI,CAACF,OAAO,CAAE,KAAM,CAAAG,KAAK,CAAC,gBAAgB,CAAC,CAE3C,GAAI,CAAAC,YAAY,CAAG,KAAK,CACxB,KAAM,CAAAC,cAAc,CAAG,EAAE,CAEzB,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGN,OAAO,CAACO,MAAM,CAAE,EAAED,CAAC,CAAE,CACvC,KAAM,CAAAE,MAAM,CAAGR,OAAO,CAACM,CAAC,CAAC,CACzB,GAAI,CAACT,MAAM,EAAIA,MAAM,CAACW,MAAM,CAAC,CAAE,CAC7B,KAAM,CAACC,MAAM,CAAEC,KAAK,CAAC,CAAG,GAAAC,uBAAe,EAACH,MAAM,CAAC,CAC/CJ,YAAY,GAAKK,MAAM,GAAKP,KAAK,CACjCG,cAAc,CAACO,IAAI,cACjB,GAAAlB,WAAA,CAAAmB,GAAA,YAAQC,SAAS,CAAEb,KAAK,CAACO,MAAO,CAAcN,KAAK,CAAEO,MAAO,CAAAM,QAAA,CACzDL,KAAK,EAD8BD,MAE9B,CACV,CACF,CACF,CAEA;AACA;AACA;AACA;AACA,KAAM,CAAAO,YAAY,CAAGZ,YAAY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AA,CAEab,cAAc","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _propTypes=_interopRequireDefault(require("prop-types"));var _reactThemes=_interopRequireDefault(require("@dr.pogodin/react-themes"));var _common=require("../common");var _jsxRuntime=require("react/jsx-runtime");const defaultTheme={"context":"VMHfnP","ad":"HNliRC","hoc":"_2Ue-db","container":"AWNvRj","option":"fUfIAd","selected":"Wco-qk","options":"CZYtcC"};const validThemeKeys=["container","label","option","options","selected"];const BaseSwitch=({label,onChange,options,theme,value})=>{if(!options||!theme.option)throw Error("Internal error");const optionNodes=[];for(let i=0;i<options?.length;++i){const[iValue,iName]=(0,_common.optionValueName)(options[i]);let className=theme.option;let onPress;if(iValue===value)className+=` ${theme.selected}`;else if(onChange)onPress=()=>onChange(iValue);optionNodes.push(onPress?/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:className,onClick:onPress,onKeyDown:e=>{if(onPress&&e.key==="Enter")onPress()},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:className,children:iName},iValue))}return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[label?/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}):null,/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.options,children:optionNodes})]})};const ThemedSwitch=(0,_reactThemes.default)(BaseSwitch,"Switch",validThemeKeys,defaultTheme);BaseSwitch.propTypes={label:_propTypes.default.node,onChange:_propTypes.default.func,options:_common.optionsValidator,theme:ThemedSwitch.themeType.isRequired,value:_common.valueValidator};
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _propTypes=_interopRequireDefault(require("prop-types"));var _reactThemes=_interopRequireDefault(require("@dr.pogodin/react-themes"));var _common=require("../common");var _jsxRuntime=require("react/jsx-runtime");const defaultTheme={"context":"VMHfnP","ad":"HNliRC","hoc":"_2Ue-db","container":"AWNvRj","option":"fUfIAd","selected":"Wco-qk","options":"CZYtcC"};const validThemeKeys=["container","label","option","options","selected"];const BaseSwitch=({label,onChange,options,theme,value})=>{if(!options||!theme.option)throw Error("Internal error");const optionNodes=[];for(let i=0;i<options?.length;++i){const[iValue,iName]=(0,_common.optionValueName)(options[i]);let className=theme.option;let onPress;if(iValue===value)className+=` ${theme.selected}`;else if(onChange)onPress=()=>onChange(iValue);optionNodes.push(onPress?/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:className,onClick:onPress,onKeyDown:e=>{if(onPress&&e.key==="Enter")onPress()},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:className,children:iName},iValue))}return/*#__PURE__*/(0,_jsxRuntime.jsxs)("div",{className:theme.container,children:[label?/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.label,children:label}):null,/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:theme.options,children:optionNodes})]})};const ThemedSwitch=(0,_reactThemes.default)(BaseSwitch,"Switch",validThemeKeys,defaultTheme);BaseSwitch.propTypes={label:_propTypes.default.node,onChange:_propTypes.default.func,options:_common.optionsValidator,theme:ThemedSwitch.themeType.isRequired,value:_common.valueValidator};var _default=exports.default=ThemedSwitch;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_reactThemes","_common","_jsxRuntime","defaultTheme","validThemeKeys","BaseSwitch","label","onChange","options","theme","value","option","Error","optionNodes","i","length","iValue","iName","optionValueName","className","onPress","selected","push","jsx","onClick","onKeyDown","e","key","role","tabIndex","children","jsxs","container","ThemedSwitch","themed","propTypes","PT","node","func","optionsValidator","themeType","isRequired","valueValidator","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_propTypes","_interopRequireDefault","require","_reactThemes","_common","_jsxRuntime","defaultTheme","validThemeKeys","BaseSwitch","label","onChange","options","theme","value","option","Error","optionNodes","i","length","iValue","iName","optionValueName","className","onPress","selected","push","jsx","onClick","onKeyDown","e","key","role","tabIndex","children","jsxs","container","ThemedSwitch","themed","propTypes","PT","node","func","optionsValidator","themeType","isRequired","valueValidator","_default","exports","default"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import PT from 'prop-types';\nimport themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionsValidator,\n optionValueName,\n valueValidator,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\nconst validThemeKeys = [\n 'container',\n 'label',\n 'option',\n 'options',\n 'selected',\n] as const;\n\ntype PropsT = {\n label?: React.ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<React.ReactNode>>;\n theme: Theme<typeof validThemeKeys>;\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 [iValue, iName] = optionValueName(options[i]);\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 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\nconst ThemedSwitch = themed(\n BaseSwitch,\n 'Switch',\n validThemeKeys,\n defaultTheme,\n);\n\nBaseSwitch.propTypes = {\n label: PT.node,\n onChange: PT.func,\n options: optionsValidator,\n theme: ThemedSwitch.themeType.isRequired,\n value: valueValidator,\n};\n\nexport default ThemedSwitch;\n"],"mappings":"gLAAA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBACA,IAAAC,YAAA,CAAAF,sBAAA,CAAAC,OAAA,8BAEA,IAAAE,OAAA,CAAAF,OAAA,cAMmB,IAAAG,WAAA,CAAAH,OAAA,4BAAAI,YAAA,kIAInB,KAAM,CAAAC,cAAc,CAAG,CACrB,WAAW,CACX,OAAO,CACP,QAAQ,CACR,SAAS,CACT,UAAU,CACF,CAUV,KAAM,CAAAC,UAA2C,CAAGA,CAAC,CACnDC,KAAK,CACLC,QAAQ,CACRC,OAAO,CACPC,KAAK,CACLC,KACF,CAAC,GAAK,CACJ,GAAI,CAACF,OAAO,EAAI,CAACC,KAAK,CAACE,MAAM,CAAE,KAAM,CAAAC,KAAK,CAAC,gBAAgB,CAAC,CAE5D,KAAM,CAAAC,WAA8B,CAAG,EAAE,CACzC,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGN,OAAO,EAAEO,MAAM,CAAE,EAAED,CAAC,CAAE,CACxC,KAAM,CAACE,MAAM,CAAEC,KAAK,CAAC,CAAG,GAAAC,uBAAe,EAACV,OAAO,CAACM,CAAC,CAAC,CAAC,CAEnD,GAAI,CAAAK,SAAiB,CAAGV,KAAK,CAACE,MAAM,CACpC,GAAI,CAAAS,OAAiC,CACrC,GAAIJ,MAAM,GAAKN,KAAK,CAAES,SAAS,EAAK,IAAGV,KAAK,CAACY,QAAS,EAAC,CAAC,IACnD,IAAId,QAAQ,CAAEa,OAAO,CAAGA,CAAA,GAAMb,QAAQ,CAACS,MAAM,CAAC,CAEnDH,WAAW,CAACS,IAAI,CACdF,OAAO,cACL,GAAAlB,WAAA,CAAAqB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=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"act",{enumerable:true,get:function(){return
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"act",{enumerable:true,get:function(){return _react.act}});Object.defineProperty(exports,"getGlobal",{enumerable:true,get:function(){return _global.default}});exports.getMockUuid=getMockUuid;exports.mockClientSide=mockClientSide;exports.mockTimer=mockTimer;exports.mount=mount;exports.snapshot=snapshot;exports.unmockClientSide=unmockClientSide;var _mockdate=_interopRequireDefault(require("mockdate"));var _react=require("react");var _client=require("react-dom/client");var _react2=require("@testing-library/react");var _global=_interopRequireDefault(require("./global"));/* global jest, document */ /* eslint-disable import/no-extraneous-dependencies */ /**
|
|
2
2
|
* An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
|
|
3
|
-
* from `react
|
|
4
|
-
* @param {function} action
|
|
3
|
+
* from `react`.
|
|
5
4
|
*/global.IS_REACT_ACT_ENVIRONMENT=true;const originalProcessVersions=process.versions;/**
|
|
6
5
|
* Tricks **react-utils** into thinking the test is running within client-side
|
|
7
6
|
* (browser) environment.
|
|
@@ -22,34 +21,9 @@
|
|
|
22
21
|
* @param scene
|
|
23
22
|
* @return Created container DOM element with destroy() function
|
|
24
23
|
* attached.
|
|
25
|
-
*/function mount(scene){let root;const element=document.createElement("div");document.body.appendChild(element);const res=element;res.destroy=()=>{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @example
|
|
31
|
-
* import { JU } from '@dr.pogodin/react-utils';
|
|
32
|
-
* console.log(JU.render(<div>Example</div>));
|
|
33
|
-
*/function render(component){return _reactTestRenderer.default.create(component).toJSON()}/**
|
|
34
|
-
* Generates a shallow render of given ReactJS component, using
|
|
35
|
-
* [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)
|
|
36
|
-
* and returns the result.
|
|
37
|
-
* @param {object} component ReactJS component to render.
|
|
38
|
-
* @return {object} JSON representation of the shallow component's render tree.
|
|
39
|
-
*/function shallowRender(component){const renderer=(0,_shallow.createRenderer)();renderer.render(component);return renderer.getRenderOutput()}/**
|
|
40
|
-
* Makes a shallow snapshot test of the given ReactJS component, and also
|
|
41
|
-
* returns JSON representation of the rendered component tree. Under the hood
|
|
42
|
-
* it uses {@link module:JU.shallowRender shallowRender(..)} to generate
|
|
43
|
-
* the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,
|
|
44
|
-
* and finally returns the `RENDER_RESULT` to the caller.
|
|
45
|
-
* @param {object} component ReactJS component to render.
|
|
46
|
-
* @return {object} JSON representation of shallow render.
|
|
47
|
-
*/function shallowSnapshot(component){const res=shallowRender(component);expect(res).toMatchSnapshot();return res}/**
|
|
48
|
-
* Makes snapshot test of the given ReactJS component, and also returns JSON
|
|
49
|
-
* representation of the rendered component tree. Under the hood, it uses
|
|
50
|
-
* {@link module:JU.render render(..)} to render it, then executes
|
|
51
|
-
* `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.
|
|
52
|
-
* @param {object} component ReactJS component to render.
|
|
53
|
-
* @return {object} JSON render of the component.
|
|
54
|
-
*/function snapshot(component){const res=render(component);expect(res).toMatchSnapshot();return res}const simulate=exports.simulate=_testUtils.default.Simulate;
|
|
24
|
+
*/function mount(scene){let root;const element=document.createElement("div");document.body.appendChild(element);const res=element;res.destroy=()=>{// NOTE: As it seems @testing-library may reset this flag to false
|
|
25
|
+
// when it is simulating user events.
|
|
26
|
+
global.IS_REACT_ACT_ENVIRONMENT=true;(0,_react.act)(()=>root.unmount());res.remove()};// NOTE: As it seems @testing-library may reset this flag to false
|
|
27
|
+
// when it is simulating user events.
|
|
28
|
+
global.IS_REACT_ACT_ENVIRONMENT=true;(0,_react.act)(()=>{root=(0,_client.createRoot)(res);root.render(scene)});return res}function snapshot(element){const res=(0,_react2.render)(element).asFragment().firstChild;expect(res).toMatchSnapshot();return res}
|
|
55
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_react","_client","_react2","_global","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","set","Date","now","jest","advanceTimersByTime","mount","scene","root","element","document","createElement","body","appendChild","res","destroy","act","unmount","remove","createRoot","render","snapshot","asFragment","firstChild","expect","toMatchSnapshot"],"sources":["../../../../../src/shared/utils/jest/index.tsx"],"sourcesContent":["/* global jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { type ReactNode, act } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\n\nimport { render } from '@testing-library/react';\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react`.\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\ndeclare global {\n // eslint-disable-next-line no-var, vars-on-top\n var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;\n}\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => root.unmount());\n res.remove();\n };\n\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\nexport function snapshot(element: React.ReactElement) {\n const res = render(element).asFragment().firstChild;\n expect(res).toMatchSnapshot();\n return res;\n}\n"],"mappings":"ghBAGA,IAAAA,SAAA,CAAAC,sBAAA,CAAAC,OAAA,cACA,IAAAC,MAAA,CAAAD,OAAA,UACA,IAAAE,OAAA,CAAAF,OAAA,qBAEA,IAAAG,OAAA,CAAAH,OAAA,2BAQA,IAAAI,OAAA,CAAAL,sBAAA,CAAAC,OAAA,cAfA,4BACA,uDAQA;AACA;AACA;AACA,GAUAK,MAAM,CAACC,wBAAwB,CAAG,IAAI,CAEtC,KAAM,CAAAC,uBAAuB,CAAGC,OAAO,CAACC,QAAQ,CAEhD;AACA;AACA;AACA,GACO,QAAS,CAAAC,cAAcA,CAAA,CAAG,CAC/BC,MAAM,CAACC,cAAc,CAACJ,OAAO,CAAE,UAA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;AACAlC,MAAM,CAACC,wBAAwB,CAAG,IAAI,CAEtC,GAAAkC,UAAG,EAAC,IAAMR,IAAI,CAACS,OAAO,CAAC,CAAC,CAAC,CACzBH,GAAG,CAACI,MAAM,CAAC,CACb,CAAC,CAED;AACA;AACArC,MAAM,CAACC,wBAAwB,CAAG,IAAI,CAEtC,GAAAkC,UAAG,EAAC,IAAM,CACRR,IAAI,CAAG,GAAAW,kBAAU,EAACL,GAAG,CAAC,CACtBN,IAAI,CAACY,MAAM,CAACb,KAAK,CACnB,CAAC,CAAC,CACF,MAAO,CAAAO,GACT,CAEO,QAAS,CAAAO,QAAQA,CAACZ,OAA2B,CAAE,CACpD,KAAM,CAAAK,GAAG,CAAG,GAAAM,cAAM,EAACX,OAAO,CAAC,CAACa,UAAU,CAAC,CAAC,CAACC,UAAU,CACnDC,MAAM,CAACV,GAAG,CAAC,CAACW,eAAe,CAAC,CAAC,CAC7B,MAAO,CAAAX,GACT","ignoreList":[]}
|
|
@@ -47,5 +47,5 @@ if(_isomorphy.IS_CLIENT_SIDE){await bookStyleSheets(chunkName,clientChunkGroups,
|
|
|
47
47
|
// and also push it to the SSR chunks array.
|
|
48
48
|
if(_isomorphy.IS_SERVER_SIDE){const{chunkGroups,chunks}=(0,_globalState.getSsrContext)();assertChunkName(chunkName,chunkGroups);if(!chunks.includes(chunkName))chunks.push(chunkName)}// This takes care about stylesheets management every time an instance of
|
|
49
49
|
// this component is mounted / unmounted.
|
|
50
|
-
(0,_react.useInsertionEffect)(()=>{bookStyleSheets(chunkName,clientChunkGroups,true);return()=>freeStyleSheets(chunkName,clientChunkGroups)},[]);return/*#__PURE__*/(0,_jsxRuntime.jsx)(Component,{ref:ref,...rest,children:children})});return{default:Wrapper}});const CodeSplit=({children,...rest})=>/*#__PURE__*/(0,_jsxRuntime.jsx)(_react.Suspense,{fallback:placeholder,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(LazyComponent,{...rest,children:children})});CodeSplit.propTypes={children:_propTypes.default.node};
|
|
50
|
+
(0,_react.useInsertionEffect)(()=>{bookStyleSheets(chunkName,clientChunkGroups,true);return()=>freeStyleSheets(chunkName,clientChunkGroups)},[]);return/*#__PURE__*/(0,_jsxRuntime.jsx)(Component,{ref:ref,...rest,children:children})});return{default:Wrapper}});const CodeSplit=({children,...rest})=>/*#__PURE__*/(0,_jsxRuntime.jsx)(_react.Suspense,{fallback:placeholder,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(LazyComponent,{...rest,children:children})});CodeSplit.propTypes={children:_propTypes.default.node};return CodeSplit}
|
|
51
51
|
//# sourceMappingURL=splitComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitComponent.js","names":["_propTypes","_interopRequireDefault","require","_react","_jsUtils","_globalState","_isomorphy","_jsxRuntime","clientChunkGroups","IS_CLIENT_SIDE","default","CHUNK_GROUPS","refCounts","getPublicPath","getBuildInfo","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","Barrier","addEventListener","resolve","current","getLoadedStyleSheets","Set","styleSheets","i","length","href","add","assertChunkName","chunkName","chunkGroups","Error","bookStyleSheets","promises","assets","asset","endsWith","promise","push","Promise","allSettled","then","freeStyleSheets","remove","usedChunkNames","splitComponent","getComponent","placeholder","LazyComponent","lazy","resolved","Component","Wrapper","forwardRef","children","rest","ref","IS_SERVER_SIDE","chunks","getSsrContext","includes","useInsertionEffect","jsx","CodeSplit","Suspense","fallback","propTypes","PT","node","defaultProps","undefined"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n/* global document */\n\nimport PT from 'prop-types';\n\nimport {\n type ComponentType,\n type ReactNode,\n forwardRef,\n lazy,\n Suspense,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\n// Note: At the client side we can get chunk groups immediately when loading\n// the module; at the server-side we only can get them within React render flow.\n// Thus, we set and use the following variable at the client-side, and then when\n// needed on the server side, we'll fetch it differently.\nlet clientChunkGroups: ChunkGroupsT;\n\nif (IS_CLIENT_SIDE) {\n // eslint-disable-next-line global-require\n clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};\n}\n\nconst refCounts: { [path: string]: number } = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => res!.resolve());\n link.addEventListener('error', () => res!.resolve());\n }\n\n if (refCount) {\n const current = refCounts[path] || 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (let i = 0; i < styleSheets.length; ++i) {\n const { href } = styleSheets[i];\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n const loadedSheets = getLoadedStyleSheets();\n\n for (let i = 0; i < assets.length; ++i) {\n const asset = assets[i];\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n const assets = chunkGroups[chunkName];\n for (let i = 0; i < assets.length; ++i) {\n const asset = assets[i];\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n if (--refCounts[path] <= 0) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\nconst usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>,\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends { children?: ReactNode },\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>,\n placeholder?: ReactNode,\n}) {\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n if (usedChunkNames.has(chunkName)) {\n throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper = forwardRef((\n { children, ...rest }: ComponentPropsT,\n ref,\n ) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => freeStyleSheets(chunkName, clientChunkGroups);\n }, []);\n\n return (\n <Component ref={ref} {...rest as ComponentPropsT}>\n {children}\n </Component>\n );\n });\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent {...rest as Parameters<typeof LazyComponent>[0]}>\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n CodeSplit.propTypes = {\n children: PT.node,\n } as React.WeakValidationMap<ComponentPropsT>;\n\n CodeSplit.defaultProps = {\n children: undefined,\n } as Partial<ComponentPropsT>;\n\n return CodeSplit;\n}\n"],"mappings":"wQAGA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBAEA,IAAAC,MAAA,CAAAD,OAAA,UASA,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iB,CAC3D,CAAC,CAAE,EAAE,CAAC,CAEN,mBACE,GAAAD,WAAA,CAAAuE,GAAA,EAACX,SAAS,EAACK,GAAG,CAAEA,GAAI,IAAKD,IAAI,CAAAD,QAAA,CAC1BA,QAAQ,CACA,CAEf,CAAC,CAAC,CAEF,MAAO,CAAE5D,OAAO,CAAE0D,OAAQ,CAC5B,CAAC,CAAC,CAEF,KAAM,CAAAW,SAAmD,CAAGA,CAAC,CAC3DT,QAAQ,CACR,GAAGC,IACY,CAAC,gBAChB,GAAAhE,WAAA,CAAAuE,GAAA,EAAC3E,MAAA,CAAA6E,QAAQ,EAACC,QAAQ,CAAElB,WAAY,CAAAO,QAAA,cAC9B,GAAA/D,WAAA,CAAAuE,GAAA,EAACd,aAAa,KAAKO,IAAI,CAAAD,QAAA,CACpBA,QAAQ,CACI,CAAC,CACR,CACX,CAEDS,SAAS,CAACG,SAAS,CAAG,CACpBZ,QAAQ,CAAEa,kBAAE,CAACC,IACf,CAA6C,CAE7CL,SAAS,CAACM,YAAY,CAAG,CACvBf,QAAQ,CAAEgB,SACZ,CAA6B,CAE7B,MAAO,CAAAP,SACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["_propTypes","_interopRequireDefault","require","_react","_jsUtils","_globalState","_isomorphy","_jsxRuntime","clientChunkGroups","IS_CLIENT_SIDE","default","CHUNK_GROUPS","refCounts","getPublicPath","getBuildInfo","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","Barrier","addEventListener","resolve","current","getLoadedStyleSheets","Set","styleSheets","i","length","href","add","assertChunkName","chunkName","chunkGroups","Error","bookStyleSheets","promises","assets","asset","endsWith","promise","push","Promise","allSettled","then","freeStyleSheets","remove","usedChunkNames","splitComponent","getComponent","placeholder","LazyComponent","lazy","resolved","Component","Wrapper","forwardRef","children","rest","ref","IS_SERVER_SIDE","chunks","getSsrContext","includes","useInsertionEffect","jsx","CodeSplit","Suspense","fallback","propTypes","PT","node"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n/* global document */\n\nimport PT from 'prop-types';\n\nimport {\n type ComponentType,\n type ReactNode,\n forwardRef,\n lazy,\n Suspense,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\n// Note: At the client side we can get chunk groups immediately when loading\n// the module; at the server-side we only can get them within React render flow.\n// Thus, we set and use the following variable at the client-side, and then when\n// needed on the server side, we'll fetch it differently.\nlet clientChunkGroups: ChunkGroupsT;\n\nif (IS_CLIENT_SIDE) {\n // eslint-disable-next-line global-require\n clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};\n}\n\nconst refCounts: { [path: string]: number } = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => res!.resolve());\n link.addEventListener('error', () => res!.resolve());\n }\n\n if (refCount) {\n const current = refCounts[path] || 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (let i = 0; i < styleSheets.length; ++i) {\n const { href } = styleSheets[i];\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n const loadedSheets = getLoadedStyleSheets();\n\n for (let i = 0; i < assets.length; ++i) {\n const asset = assets[i];\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n const assets = chunkGroups[chunkName];\n for (let i = 0; i < assets.length; ++i) {\n const asset = assets[i];\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n if (--refCounts[path] <= 0) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\nconst usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>,\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends { children?: ReactNode },\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>,\n placeholder?: ReactNode,\n}) {\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n if (usedChunkNames.has(chunkName)) {\n throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper = forwardRef((\n { children, ...rest }: ComponentPropsT,\n ref,\n ) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => freeStyleSheets(chunkName, clientChunkGroups);\n }, []);\n\n return (\n <Component ref={ref} {...rest as ComponentPropsT}>\n {children}\n </Component>\n );\n });\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent {...rest as Parameters<typeof LazyComponent>[0]}>\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n CodeSplit.propTypes = {\n children: PT.node,\n } as PT.WeakValidationMap<ComponentPropsT>;\n\n return CodeSplit;\n}\n"],"mappings":"wQAGA,IAAAA,UAAA,CAAAC,sBAAA,CAAAC,OAAA,gBAEA,IAAAC,MAAA,CAAAD,OAAA,UASA,IAAAE,QAAA,CAAAF,OAAA,yBAEA,IAAAG,YAAA,CAAAH,OAAA,kBAEA,IAAAI,UAAA,CAAAJ,OAAA,gBAIqB,IAAAK,WAAA,CAAAL,OAAA,sBAtBrB,kDACA,sBAuBA;AACA;AACA;AACA;AACA,GAAI,CAAAM,iBAA+B,CAEnC,GAAIC,yBAAc,CAAE,CAClB;AACAD,iBAAiB,CAAGN,OAAO,sBAAgB,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACC,YAAY,EAAI,CAAC,CAC1E,CAEA,KAAM,CAAAC,SAAqC,CAAG,CAAC,CAAC,CAEhD,QAAS,CAAAC,aAAaA,CAAA,CAAG,CACvB,MAAO,GAAAC,uBAAY,EAAC,CAAC,CAACC,UACxB,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAC,cAAcA,CACrBC,IAAY,CACZC,YAAyB,CACzBC,QAAiB,CACU,CAC3B,GAAI,CAAAC,GAA8B,CAClC,KAAM,CAAAC,IAAI,CAAI,GAAER,aAAa,CAAC,CAAE,IAAGI,IAAK,EAAC,CACzC,KAAM,CAAAK,QAAQ,CAAI,GAAEC,QAAQ,CAACC,QAAQ,CAACC,MAAO,GAAEJ,IAAK,EAAC,CAErD,GAAI,CAACH,YAAY,CAACQ,GAAG,CAACJ,QAAQ,CAAC,CAAE,CAC/B,GAAI,CAAAK,IAAI,CAAGJ,QAAQ,CAACK,aAAa,CAAE,cAAaP,IAAK,IAAG,CAAC,CAEzD,GAAI,CAACM,IAAI,CAAE,CACTA,IAAI,CAAGJ,QAAQ,C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