@entur/utils 0.11.2 → 0.12.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.
@@ -0,0 +1 @@
1
+ export declare const getNodeText: (node: React.ReactNode | string | number | string[] | number[]) => string;
package/dist/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './useWindowDimensions';
10
10
  export * from './ConditionalWrapper';
11
11
  export * from './warnAboutMissingStyles';
12
12
  export * from './types';
13
+ export * from './getNodeText';
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export declare const useOnClickOutside: (refs: React.RefObject<HTMLElement>[], handler: () => void) => void;
2
+ export declare const useOnClickOutside: (refs: (React.RefObject<HTMLElement> | React.MutableRefObject<any>)[], handler: () => void) => void;
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export declare const useOnEscape: (ref: React.RefObject<HTMLElement>, handler: () => void) => void;
2
+ export declare const useOnEscape: (ref: React.RefObject<any> | React.MutableRefObject<any>, handler: () => void) => void;
@@ -190,7 +190,20 @@ function warnAboutMissingStyles() {
190
190
  checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
191
191
  }
192
192
 
193
+ // with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react
194
+ var getNodeText = function getNodeText(node) {
195
+ var _node$props$children, _node$props;
196
+ if (node === null || node === undefined) return '';
197
+ if (['string', 'number'].includes(typeof node)) return node.toString();
198
+ if (node instanceof Array) return node.map(getNodeText).join('').trim();
199
+ if (typeof node === 'object')
200
+ // @ts-expect-error props does exist for react nodes
201
+ return getNodeText((_node$props$children = (_node$props = node.props) == null ? void 0 : _node$props.children) != null ? _node$props$children : '').trim();
202
+ return 'unknown';
203
+ };
204
+
193
205
  exports.ConditionalWrapper = ConditionalWrapper;
206
+ exports.getNodeText = getNodeText;
194
207
  exports.mergeRefs = mergeRefs;
195
208
  exports.useDebounce = useDebounce;
196
209
  exports.useForceUpdate = useForceUpdate;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.development.js","sources":["../src/useDebounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/warnAboutMissingStyles.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n"],"names":["useDebounce","callBack","debounceTime","timeoutRef","useRef","useEffect","current","clearTimeout","debouncedFunc","args","setTimeout","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","useForceUpdate","useState","setValue","value","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","currentRef","getWindowDimensions","width","undefined","height","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","process","env","TEST","namespaces","forEach","add"],"mappings":";;;;;;;AAEgB,SAAAA,WAAW,CACzBC,QAAW,EACXC,YAAoB,EAAA;EAEpB,IAAMC,UAAU,GAAGC,YAAM,EAAiC,CAAA;AAE1DC,EAAAA,eAAS,CAAC,YAAK;AACb,IAAA,OAAO,YAAK;MACV,IAAIF,UAAU,CAACG,OAAO,EAAE;AACtBC,QAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,OAAA;KACF,CAAA;GACF,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,IAAME,aAAa,GAAG,SAAhBA,aAAa,GAAsB;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAAfC,IAAW,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAXA,IAAW,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,KAAA;IACnC,IAAIN,UAAU,CAACG,OAAO,EAAE;AACtBC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,KAAA;AAEDH,IAAAA,UAAU,CAACG,OAAO,GAAGI,UAAU,CAAC,YAAK;MACnCT,QAAQ,CAAA,KAAA,CAAA,KAAA,CAAA,EAAIQ,IAAI,CAAC,CAAA;KAClB,EAAEP,YAAY,CAAC,CAAA;GACjB,CAAA;AAED,EAAA,OAAOM,aAAkB,CAAA;AAC3B;;ICzBaG,WAAW,GAAG,SAAdA,WAAW,CAAIC,MAAe,EAAY;AACrD,EAAA,IAAMC,GAAG,GAAGC,KAAK,CAACV,MAAM,CAACW,MAAM,CAACC,IAAI,CAACC,MAAM,EAAE,CA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QAASC,CAAAA,GAAG,qBAAZ,YAAcC,CAAAA,IAAI,MAAK,MAAO,EACjE;AACA,IAAA,OAAA;AACD,GAAA;AACD;AACA3C,EAAAA,MAAM,CAACrC,YAAY,CAAC4D,cAAc,CAAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAZwCqB,UAAoB,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;IAApBA,UAAoB,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAa5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAhB,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACyB,GAAG,CAACjB,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAAClC,UAAU,CAAC0D,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.cjs.development.js","sources":["../src/useDebounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/warnAboutMissingStyles.ts","../src/getNodeText.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: (React.RefObject<HTMLElement> | React.MutableRefObject<any>)[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<any> | React.MutableRefObject<any>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n","// with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react\nexport const getNodeText = (\n node: React.ReactNode | string | number | string[] | number[],\n): string => {\n if (node === null || node === undefined) return '';\n if (['string', 'number'].includes(typeof node)) return node.toString();\n if (node instanceof Array) return node.map(getNodeText).join('').trim();\n if (typeof node === 'object')\n // @ts-expect-error props does exist for react nodes\n return getNodeText(node.props?.children ?? '').trim();\n return 'unknown';\n};\n"],"names":["useDebounce","callBack","debounceTime","timeoutRef","useRef","useEffect","current","clearTimeout","debouncedFunc","args","setTimeout","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","useForceUpdate","useState","setValue","value","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","currentRef","getWindowDimensions","width","undefined","height","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","process","env","TEST","namespaces","forEach","add","getNodeText","includes","toString","trim","props"],"mappings":";;;;;;;AAEgB,SAAAA,WAAW,CACzBC,QAAW,EACXC,YAAoB,EAAA;EAEpB,IAA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 -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");require("tiny-warning");var n=function(){if("undefined"==typeof window)return{width:void 0,height:void 0};var e=window;return{width:e.innerWidth,height:e.innerHeight}};exports.ConditionalWrapper=function(n){var t=n.children;return n.condition?(0,n.wrapper)(t):e.createElement(e.Fragment,null,t)},exports.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){for(var t=0,r=n;t<r.length;t++){var u=r[t];"function"==typeof u?u(e):u&&(u.current=e)}}},exports.useDebounce=function(n,t){var r=e.useRef();return e.useEffect((function(){return function(){r.current&&clearTimeout(r.current)}}),[]),function(){for(var e=arguments.length,u=new Array(e),o=0;o<e;o++)u[o]=arguments[o];r.current&&clearTimeout(r.current),r.current=setTimeout((function(){n.apply(void 0,u)}),t)}},exports.useForceUpdate=function(){var n=e.useState(0)[1];return function(){return n((function(e){return e+1}))}},exports.useOnClickOutside=function(n,t){e.useEffect((function(){var e=function(e){n.some((function(n){return function(e,n){return!(!e||!(e.contains(n.target)||n.composed&&n.composedPath&&n.composedPath().find((function(n){return n!==window&&e.contains(n)}))))}(n.current,e)}))||t()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[n,t])},exports.useOnEscape=function(n,t){e.useEffect((function(){var e=function(e){"Escape"===e.key&&t()},r=n.current;return null==r||r.addEventListener("keydown",e),function(){return null==r?void 0:r.removeEventListener("keydown",e)}}),[n,t])},exports.useOnMount=function(n){var t=e.useRef(!1);e.useEffect((function(){t.current||(t.current=!0,n())}),[n])},exports.useRandomId=function(n){return n+"-"+e.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var t=e.useState(n()),r=t[0],u=t[1];return e.useEffect((function(){function e(){u(n())}if("undefined"!=typeof window)return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),r},exports.warnAboutMissingStyles=function(){};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react");require("tiny-warning");var e=function(){if("undefined"==typeof window)return{width:void 0,height:void 0};var n=window;return{width:n.innerWidth,height:n.innerHeight}};exports.ConditionalWrapper=function(e){var t=e.children;return e.condition?(0,e.wrapper)(t):n.createElement(n.Fragment,null,t)},exports.getNodeText=function n(e){var t,r;return null==e?"":["string","number"].includes(typeof e)?e.toString():e instanceof Array?e.map(n).join("").trim():"object"==typeof e?n(null!=(t=null==(r=e.props)?void 0:r.children)?t:"").trim():"unknown"},exports.mergeRefs=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return function(n){for(var t=0,r=e;t<r.length;t++){var o=r[t];"function"==typeof o?o(n):o&&(o.current=n)}}},exports.useDebounce=function(e,t){var r=n.useRef();return n.useEffect((function(){return function(){r.current&&clearTimeout(r.current)}}),[]),function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];r.current&&clearTimeout(r.current),r.current=setTimeout((function(){e.apply(void 0,o)}),t)}},exports.useForceUpdate=function(){var e=n.useState(0)[1];return function(){return e((function(n){return n+1}))}},exports.useOnClickOutside=function(e,t){n.useEffect((function(){var n=function(n){e.some((function(e){return function(n,e){return!(!n||!(n.contains(e.target)||e.composed&&e.composedPath&&e.composedPath().find((function(e){return e!==window&&n.contains(e)}))))}(e.current,n)}))||t()};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),function(){document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n)}}),[e,t])},exports.useOnEscape=function(e,t){n.useEffect((function(){var n=function(n){"Escape"===n.key&&t()},r=e.current;return null==r||r.addEventListener("keydown",n),function(){return null==r?void 0:r.removeEventListener("keydown",n)}}),[e,t])},exports.useOnMount=function(e){var t=n.useRef(!1);n.useEffect((function(){t.current||(t.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+n.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var t=n.useState(e()),r=t[0],o=t[1];return n.useEffect((function(){function n(){o(e())}if("undefined"!=typeof window)return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),r},exports.warnAboutMissingStyles=function(){};
2
2
  //# sourceMappingURL=utils.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/mergeRefs.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/useDebounce.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useOnMount.ts","../src/useRandomId.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n"],"names":["mergeRefs","getWindowDimensions","window","width","undefined","height","_window","innerWidth","innerHeight","_ref","children","condition","wrapper","React","createElement","Fragment","_len","arguments","length","refs","Array","_key","node","_i","_refs","ref","current","callBack","debounceTime","timeoutRef","useRef","useEffect","clearTimeout","args","setTimeout","apply","useState","setValue","value","handler","listener","event","some","element","contains","target","composed","composedPath","find","elementContainsEventTarget","document","addEventListener","removeEventListener","runIfKeyIsEscape","key","currentRef","callback","hasRun","prefix","String","Math","random","substring","_useState","windowDimensions","setWindowDimensions","handleResize"],"mappings":"mHAAaA,ICQPC,EAAsB,WAC1B,GAAsB,oBAAXC,OACT,MAAO,CAAEC,WAAOC,EAAWC,YAAQD,GAErC,IAAAE,EAAmDJ,OACnD,MAAO,CACLC,QAFMI,WAGNF,SAHyBG,YAK7B,6BCTkC,SAAHC,GAAA,IAG7BC,IAAAA,SAAQ,SAFRC,WAGyCC,IAFzCA,SAEiDF,GAAYG,EAAAC,cAAAD,EAAAE,SAAA,KAAGL,EAAY,oBFZrD,WAOrB,IAAA,IAAAM,EAAAC,UAAAC,OANCC,EAKA,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IALAF,EAKAE,GAAAJ,UAAAI,GAEH,OAAO,SAACC,GACN,IAAA,IAAAC,EAAA,EAAAC,EAAkBL,EAAMI,EAAAC,EAAAN,OAAAK,IAAA,CAAnB,IAAME,EAAGD,EAAAD,GACO,mBAARE,EACTA,EAAIH,GACKG,IAAKA,EAAIC,QAAUJ,EAC/B,EAEL,sBGbgB,SACdK,EACAC,GAEA,IAAMC,EAAaC,EAAAA,SAoBnB,OAlBAC,EAAAA,WAAU,WACR,OAAO,WACDF,EAAWH,SACbM,aAAaH,EAAWH,SAG7B,GAAE,IAEmB,WAAmB,IAAA,IAAAV,EAAAC,UAAAC,OAAfe,EAAW,IAAAb,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAXY,EAAWZ,GAAAJ,UAAAI,GAC/BQ,EAAWH,SACbM,aAAaH,EAAWH,SAG1BG,EAAWH,QAAUQ,YAAW,WAC9BP,EAAQQ,WAAA,EAAIF,EACb,GAAEL,GAIP,yBCzB8B,WACNQ,IAAZC,EAAYD,WAAS,GAAb,GAClB,OAAO,WAAA,OAAMC,GAAS,SAAAC,GAA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OAAOiD,iBAAiB,SAAUe,GAC3B,WAAA,OAAMhE,OAAOkD,oBAAoB,SAAUc,EAAa,CAElE,GAAE,IAEIF,CACT,iCQGgB,WAiBhB"}
1
+ {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/mergeRefs.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/getNodeText.ts","../src/useDebounce.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useOnMount.ts","../src/useRandomId.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","// with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react\nexport const getNodeText = (\n node: React.ReactNode | string | number | string[] | number[],\n): string => {\n if (node === null || node === undefined) return '';\n if (['string', 'number'].includes(typeof node)) return node.toString();\n if (node instanceof Array) return node.map(getNodeText).join('').trim();\n if (typeof node === 'object')\n // @ts-expect-error props does exist for react nodes\n return getNodeText(node.props?.children ?? '').trim();\n return 'unknown';\n};\n","import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: (React.RefObject<HTMLElement> | React.MutableRefObject<any>)[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<any> | React.MutableRefObject<any>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n"],"names":["mergeRefs","getWindowDimensions","window","width","undefined","height","_window","innerWidth","innerHeight","_ref","children","condition","wrapper","React","createElement","Fragment","getNodeText","node","_node$props$children","_node$props","includes","toString","Array","map","join","trim","props","_len","arguments","length","refs","_key","_i","_refs","ref","current","callBack","debounceTime","timeoutRef","useRef","useEffect","clearTimeout","args","setTimeout","apply","useState","setValue","value","handler","listener","event","some","element","contains","target","composed","composedPath","find","elementContainsEventTarget","document","addEventListener","removeEventListener","runIfKeyIsEscape","key","currentRef","callback","hasRun","prefix","String","Math","random","substring","_useState","windowDimensions","setWindowDimensions","handleResize"],"mappings":"mHAAaA,ICQPC,EAAsB,WAC1B,GAAsB,oBAAXC,OACT,MAAO,CAAEC,WAAOC,EAAWC,YAAQD,GAErC,IAAAE,EAAmDJ,OACnD,MAAO,CACLC,QAFMI,WAGNF,SAHyBG,YAK7B,6BCTkC,SAAHC,GAAA,IAG7BC,IAAAA,SAAQ,SAFRC,WAGyCC,IAFzCA,SAEiDF,GAAYG,EAAAC,cAAAD,EAAAE,SAAA,KAAGL,EAAY,sBCXnD,SAAdM,EACXC,GACU,IAAAC,EAAAC,EACV,OAAIF,QAA4C,GAC5C,CAAC,SAAU,UAAUG,gBAAgBH,GAAcA,EAAKI,WACxDJ,aAAgBK,MAAcL,EAAKM,IAAIP,GAAaQ,KAAK,IAAIC,OAC7C,iBAATR,EAEFD,EAAoC,OAAzBE,EAAW,OAAXC,EAACF,EAAKS,YAAK,EAAVP,EAAYT,UAAYQ,EAAA,IAAIO,OAC1C,SACT,oBHXyB,WAOrB,IAAA,IAAAE,EAAAC,UAAAC,OANCC,EAKA,IAAAR,MAAAK,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IALAD,EAKAC,GAAAH,UAAAG,GAEH,OAAO,SAACd,GACN,IAAA,IAAAe,EAAA,EAAAC,EAAkBH,EAAME,EAAAC,EAAAJ,OAAAG,IAA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GvB,OAFU,MAAV6B,GAAAA,EAAYJ,iBAAiB,UAAWE,GAEjC,WAAA,aAAME,SAAAA,EAAYH,oBAAoB,UAAWC,EAAiB,CAC3E,GAAG,CAAC5B,EAAKc,GACX,qBCdM,SAAqBiB,GACzB,IAAMC,EAASrD,EAAM0B,QAAgB,GAErC1B,EAAM2B,WAAU,WACT0B,EAAO/B,UACV+B,EAAO/B,SAAU,EACjB8B,IAEJ,GAAG,CAACA,GACN,sBCT2B,SAACE,GAE1B,OAAUA,EAAM,IADJtD,EAAM0B,OAAO6B,OAAOC,KAAKC,UAAUC,UAAU,IACjCpC,OAC1B,8BRcmC,WACjC,IAAAqC,EAAgD3B,WAC9C5C,KADKwE,EAAgBD,EAAA,GAAEE,EAAmBF,EAAA,GAe5C,OAXAhC,EAAAA,WAAU,WACR,SAASmC,IACPD,EAAoBzE,IACtB,CAEA,GAAsB,oBAAXC,OAET,OADAA,OAAO0D,iBAAiB,SAAUe,GAC3B,WAAA,OAAMzE,OAAO2D,oBAAoB,SAAUc,EAAa,CAElE,GAAE,IAEIF,CACT,iCSGgB,WAiBhB"}
package/dist/utils.esm.js CHANGED
@@ -186,5 +186,17 @@ function warnAboutMissingStyles() {
186
186
  checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
187
187
  }
188
188
 
189
- export { ConditionalWrapper, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
189
+ // with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react
190
+ var getNodeText = function getNodeText(node) {
191
+ var _node$props$children, _node$props;
192
+ if (node === null || node === undefined) return '';
193
+ if (['string', 'number'].includes(typeof node)) return node.toString();
194
+ if (node instanceof Array) return node.map(getNodeText).join('').trim();
195
+ if (typeof node === 'object')
196
+ // @ts-expect-error props does exist for react nodes
197
+ return getNodeText((_node$props$children = (_node$props = node.props) == null ? void 0 : _node$props.children) != null ? _node$props$children : '').trim();
198
+ return 'unknown';
199
+ };
200
+
201
+ export { ConditionalWrapper, getNodeText, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
190
202
  //# sourceMappingURL=utils.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../src/useDebounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/warnAboutMissingStyles.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n"],"names":["useDebounce","callBack","debounceTime","timeoutRef","useRef","useEffect","current","clearTimeout","debouncedFunc","args","setTimeout","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","useForceUpdate","useState","setValue","value","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","currentRef","getWindowDimensions","width","undefined","height","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","process","env","TEST","namespaces","forEach","add"],"mappings":";;;AAEgB,SAAAA,WAAW,CACzBC,QAAW,EACXC,YAAoB,EAAA;EAEpB,IAAMC,UAAU,GAAGC,MAAM,EAAiC,CAAA;AAE1DC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAA,OAAO,YAAK;MACV,IAAIF,UAAU,CAACG,OAAO,EAAE;AACtBC,QAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,OAAA;KACF,CAAA;GACF,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,IAAME,aAAa,GAAG,SAAhBA,aAAa,GAAsB;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAAfC,IAAW,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAXA,IAAW,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,KAAA;IACnC,IAAIN,UAAU,CAACG,OAAO,EAAE;AACtBC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,KAAA;AAEDH,IAAAA,UAAU,CAACG,OAAO,GAAGI,UAAU,CAAC,YAAK;MACnCT,QAAQ,CAAA,KAAA,CAAA,KAAA,CAAA,EAAIQ,IAAI,CAAC,CAAA;KAClB,EAAEP,YAAY,CAAC,CAAA;GACjB,CAAA;AAED,EAAA,OAA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,KAAA,CAAA,CAAA;AACH,CAAA;AAEA;AACgB,SAAAC,sBAAsB,GAAwB;AAAA,EAAA,IAAA,QAAA,EAAA,YAAA,CAAA;AAC5D;EACA,IACE,EAAA,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,CAAQ,IACR,OAAOxC,MAAM,KAAK,WAAW,IAC5B,OAAOyC,OAAO,KAAK,WAAW,IAAI,CAAAA,CAAAA,QAAAA,GAAAA,OAAO,qCAAP,QAASC,CAAAA,GAAG,qBAAZ,YAAcC,CAAAA,IAAI,MAAK,MAAO,EACjE;AACA,IAAA,OAAA;AACD,GAAA;AACD;AACA3C,EAAAA,MAAM,CAACrC,YAAY,CAAC4D,cAAc,CAAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAZwCqB,UAAoB,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;IAApBA,UAAoB,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAa5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAhB,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACyB,GAAG,CAACjB,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAAClC,UAAU,CAAC0D,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;"}
1
+ {"version":3,"file":"utils.esm.js","sources":["../src/useDebounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/warnAboutMissingStyles.ts","../src/getNodeText.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nexport function useDebounce<T extends (...args: any[]) => any>(\n callBack: T,\n debounceTime: number,\n) {\n const timeoutRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n const debouncedFunc = (...args: any[]) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n callBack(...args);\n }, debounceTime);\n };\n\n return debouncedFunc as T;\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: string): string => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n","import React from 'react';\n\nexport function useOnMount(callback: () => void): void {\n const hasRun = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!hasRun.current) {\n hasRun.current = true;\n callback();\n }\n }, [callback]);\n}\n","export const mergeRefs = <T extends HTMLElement>(\n ...refs: (\n | React.MutableRefObject<T>\n | React.ForwardedRef<T>\n | ((node: T | null) => void)\n | undefined\n )[]\n) => {\n return (node: T) => {\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) ref.current = node;\n }\n };\n};\n","import { useState } from 'react';\n\nexport const useForceUpdate = () => {\n const [_, setValue] = useState(0);\n return () => setValue(value => value + 1);\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: (React.RefObject<HTMLElement> | React.MutableRefObject<any>)[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<any> | React.MutableRefObject<any>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n const currentRef = ref.current;\n currentRef?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => currentRef?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst getWindowDimensions = () => {\n if (typeof window === 'undefined')\n return { width: undefined, height: undefined };\n\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = (): WindowDimensions => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (\n !__DEV__ ||\n typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true')\n ) {\n return;\n }\n // First, let's clear earlier calls to setTimeout\n window.clearTimeout(checkTimeoutId);\n\n // Next, let's add all namespaces to the set of packages to check\n namespaces.forEach(namespace => packagesToCheck.add(namespace));\n\n // Finally. let's trigger a run of the checker.\n checkTimeoutId = window.setTimeout(checkAndWarn, 1000);\n}\n","// with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react\nexport const getNodeText = (\n node: React.ReactNode | string | number | string[] | number[],\n): string => {\n if (node === null || node === undefined) return '';\n if (['string', 'number'].includes(typeof node)) return node.toString();\n if (node instanceof Array) return node.map(getNodeText).join('').trim();\n if (typeof node === 'object')\n // @ts-expect-error props does exist for react nodes\n return getNodeText(node.props?.children ?? '').trim();\n return 'unknown';\n};\n"],"names":["useDebounce","callBack","debounceTime","timeoutRef","useRef","useEffect","current","clearTimeout","debouncedFunc","args","setTimeout","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","useForceUpdate","useState","setValue","value","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","currentRef","getWindowDimensions","width","undefined","height","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","process","env","TEST","namespaces","forEach","add","getNodeText","includes","toString","trim","props"],"mappings":";;;AAEgB,SAAAA,WAAW,CACzBC,QAAW,EACXC,YAAoB,EAAA;EAEpB,IAAMC,UAAU,GAAGC,MAAM,EAAiC,CAAA;AAE1DC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAA,OAAO,YAAK;MACV,IAAIF,UAAU,CAACG,OAAO,EAAE;AACtBC,QAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,OAAA;KACF,CAAA;GACF,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,IAAME,aAAa,GAAG,SAAhBA,aAAa,GAAsB;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAAfC,IAAW,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAXA,IAAW,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,KAAA;IACnC,IAAIN,UAAU,CAACG,OAAO,EAAE;AACtBC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AACjC,KAAA;AAEDH,IAAAA,UAAU,CAACG,OAAO,GAAGI,UAAU,CAAC,YAAK;MACnCT,QAAQ,CAAA,KAAA,CAAA,KAAA,CAAA,EAAIQ,IAAI,CAAC,CAAA;KAClB,EAAEP,YAAY,CAAC,CAAA;GACjB,CAAA;AAED,EAAA,OAAOM,aAAkB,CAAA;AAC3B;;ICzBaG,WAAW,GAAG,SAAdA,WAAW,CAAIC,MAAe,EAAY;AACrD,EAAA,IAAMC,GAAG,GAAGC,KAAK,CAAC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AACS,WAAW,CAAC,CAACR,IAAI,CAAC,EAAE,CAAC,CAACW,IAAI,EAAE,CAAA;EACvE,IAAI,OAAOtE,IAAI,KAAK,QAAQ;AAC1B;AACA,IAAA,OAAOmE,WAAW,CAAA,CAAA,oBAAA,GAAA,CAAA,WAAA,GAACnE,IAAI,CAACuE,KAAK,KAAA,IAAA,GAAA,KAAA,CAAA,GAAV,WAAYjC,CAAAA,QAAQ,KAAI,IAAA,GAAA,oBAAA,GAAA,EAAE,CAAC,CAACgC,IAAI,EAAE,CAAA;AACvD,EAAA,OAAO,SAAS,CAAA;AAClB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entur/utils",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "license": "EUPL-1.2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/utils.esm.js",
@@ -28,5 +28,5 @@
28
28
  "dependencies": {
29
29
  "tiny-warning": "^1.0.3"
30
30
  },
31
- "gitHead": "c5713d9ad333e17ca5714d86181baba74c56e0eb"
31
+ "gitHead": "b038c9f7061c44765606ab8b7519c205ca633635"
32
32
  }