@entur/utils 0.12.0 → 0.12.2-RC.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/dist/color-utils.scss +3 -2
- package/dist/mergeRefs.d.ts +1 -2
- package/dist/utils.cjs.development.js +7 -7
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +7 -7
- package/dist/utils.esm.js.map +1 -1
- package/package.json +6 -3
package/dist/color-utils.scss
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
@use "sass:color";
|
|
1
2
|
/// Slightly lighten a color
|
|
2
3
|
/// @access public
|
|
3
4
|
/// @param {Color} $color - color to tint
|
|
4
5
|
/// @param {Number} $percentage - percentage of `$color` in returned color
|
|
5
6
|
/// @return {Color}
|
|
6
7
|
@function tint($color, $percentage) {
|
|
7
|
-
@return mix(white, $color, $percentage);
|
|
8
|
+
@return color.mix(white, $color, $percentage);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/// Slightly darken a color
|
|
@@ -13,5 +14,5 @@
|
|
|
13
14
|
/// @param {Number} $percentage - percentage of `$color` in returned color
|
|
14
15
|
/// @return {Color}
|
|
15
16
|
@function shade($color, $percentage) {
|
|
16
|
-
@return mix(black, $color, $percentage);
|
|
17
|
+
@return color.mix(black, $color, $percentage);
|
|
17
18
|
}
|
package/dist/mergeRefs.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const mergeRefs: <T extends HTMLElement>(...refs: (import("react").MutableRefObject<T> | import("react").ForwardedRef<T> | ((node: T | null) => void) | undefined)[]) => (node: T) => void;
|
|
1
|
+
export declare const mergeRefs: <T extends HTMLElement>(...refs: (React.MutableRefObject<T> | React.ForwardedRef<T> | ((node: T | null) => void) | undefined)[]) => (node: T) => void;
|
|
@@ -112,7 +112,7 @@ var useOnEscape = function useOnEscape(ref, handler) {
|
|
|
112
112
|
if (event.key === 'Escape') handler();
|
|
113
113
|
};
|
|
114
114
|
var currentRef = ref.current;
|
|
115
|
-
currentRef == null
|
|
115
|
+
currentRef == null || currentRef.addEventListener('keydown', runIfKeyIsEscape);
|
|
116
116
|
return function () {
|
|
117
117
|
return currentRef == null ? void 0 : currentRef.removeEventListener('keydown', runIfKeyIsEscape);
|
|
118
118
|
};
|
|
@@ -172,9 +172,9 @@ function checkAndWarn() {
|
|
|
172
172
|
}
|
|
173
173
|
/** Warns the developer if they have forgotten to include styles */
|
|
174
174
|
function warnAboutMissingStyles() {
|
|
175
|
-
var _process
|
|
175
|
+
var _process;
|
|
176
176
|
// We skip this check in production, and when we build static sites
|
|
177
|
-
if (typeof window === 'undefined' || typeof process !== 'undefined' && ((_process = process) == null
|
|
177
|
+
if (typeof window === 'undefined' || typeof process !== 'undefined' && ((_process = process) == null || (_process = _process.env) == null ? void 0 : _process.TEST) === 'true') {
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
// First, let's clear earlier calls to setTimeout
|
|
@@ -191,19 +191,19 @@ function warnAboutMissingStyles() {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
// with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react
|
|
194
|
-
var
|
|
194
|
+
var _getNodeText = function getNodeText(node) {
|
|
195
195
|
var _node$props$children, _node$props;
|
|
196
196
|
if (node === null || node === undefined) return '';
|
|
197
197
|
if (['string', 'number'].includes(typeof node)) return node.toString();
|
|
198
|
-
if (node instanceof Array) return node.map(
|
|
198
|
+
if (node instanceof Array) return node.map(_getNodeText).join('').trim();
|
|
199
199
|
if (typeof node === 'object')
|
|
200
200
|
// @ts-expect-error props does exist for react nodes
|
|
201
|
-
return
|
|
201
|
+
return _getNodeText((_node$props$children = (_node$props = node.props) == null ? void 0 : _node$props.children) != null ? _node$props$children : '').trim();
|
|
202
202
|
return 'unknown';
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
exports.ConditionalWrapper = ConditionalWrapper;
|
|
206
|
-
exports.getNodeText =
|
|
206
|
+
exports.getNodeText = _getNodeText;
|
|
207
207
|
exports.mergeRefs = mergeRefs;
|
|
208
208
|
exports.useDebounce = useDebounce;
|
|
209
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","../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,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,I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ACauB,WAAW,GAAG,SAAdA,WAAW,CACtBnE,IAA6D,EACnD;AAAA,EAAA,IAAA,oBAAA,EAAA,WAAA,CAAA;EACV,IAAIA,IAAI,KAAK,IAAI,IAAIA,IAAI,KAAK2B,SAAS,EAAE,OAAO,EAAE,CAAA;AAClD,EAAA,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAACyC,QAAQ,CAAC,OAAOpE,IAAI,CAAC,EAAE,OAAOA,IAAI,CAACqE,QAAQ,EAAE,CAAA;AACtE,EAAA,IAAIrE,IAAI,YAAY8C,KAAK,EAAE,OAAO9C,IAAI,CAAC0D,GAAG,CAACS,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;;;;;;;;;;;;;;"}
|
|
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","_len","arguments","length","args","Array","_key","setTimeout","apply","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","_i","_refs","useForceUpdate","_useState","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","_window","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","_ref","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","process","warning","map","join","warnAboutMissingStyles","_process","env","TEST","namespaces","forEach","add","getNodeText","_node$props$children","_node$props","includes","toString","trim","props"],"mappings":";;;;;;;AAEgB,SAAAA,WAAWA,CACzBC,QAAW,EACXC,YAAoB,EAAA;AAEpB,EAAA,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;AAClC,OAAA;KACD,CAAA;GACF,EAAE,EAAE,CAAC,CAAA;AAEN,EAAA,IAAME,aAAa,GAAG,SAAhBA,aAAaA,GAAsB;AAAA,IAAA,KAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAfC,IAAW,GAAAC,IAAAA,KAAA,CAAAJ,IAAA,GAAAK,IAAA,GAAA,CAAA,EAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA,EAAA,EAAA;AAAXF,MAAAA,IAAW,CAAAE,IAAA,CAAAJ,GAAAA,SAAA,CAAAI,IAAA,CAAA,CAAA;AAAA,KAAA;IACnC,IAAIX,UAAU,CAACG,OAAO,EAAE;AACtBC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC,CAAA;AAClC,KAAA;AAEAH,IAAAA,UAAU,CAACG,OAAO,GAAGS,UAAU,CAAC,YAAK;AACnCd,MAAAA,QAAQ,CAAAe,KAAA,CAAIJ,KAAAA,CAAAA,EAAAA,IAAI,CAAC,CAAA;KAClB,EAAEV,YAAY,CAAC,CAAA;GACjB,CAAA;AAED,EAAA,OAAOM,aAAkB,CAAA;AAC3B;;ICzBaS,WAAW,GAAG,SAAdA,WAAWA,CAAIC,MAAe,EAAY;AACrD,EAAA,IAAMC,GAAG,GAAGC,KAAK,CAAChB,MAAM,CAACiB,MAAM,CAACC,IAAI,CAACC,MAAM,EAAE,CAAC,CAAC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CAACa,IAAI,EAAE,CAAA;EACvE,IAAI,OAAO7E,IAAI,KAAK,QAAQ;AAC1B;IACA,OAAOwE,YAAW,EAAAC,oBAAA,GAAA,CAAAC,WAAA,GAAC1E,IAAI,CAAC8E,KAAK,KAAA,IAAA,GAAA,KAAA,CAAA,GAAVJ,WAAA,CAAY9B,QAAQ,YAAA6B,oBAAA,GAAI,EAAE,CAAC,CAACI,IAAI,EAAE,CAAA;AACvD,EAAA,OAAO,SAAS,CAAA;AAClB;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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}}
|
|
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}},t=function(n){var e,r;return null==n?"":["string","number"].includes(typeof n)?n.toString():n instanceof Array?n.map(t).join("").trim():"object"==typeof n?t(null!=(e=null==(r=n.props)?void 0:r.children)?e:"").trim():"unknown"};exports.ConditionalWrapper=function(e){var t=e.children;return e.condition?(0,e.wrapper)(t):n.createElement(n.Fragment,null,t)},exports.getNodeText=t,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/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,W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ElE,GAAE,IAEIF,CACT,iCSGgB,WAiBhB"}
|
|
1
|
+
{"version":3,"file":"utils.cjs.production.min.js","sources":["../src/useWindowDimensions.ts","../src/getNodeText.ts","../src/ConditionalWrapper.tsx","../src/mergeRefs.ts","../src/useDebounce.ts","../src/useForceUpdate.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useOnMount.ts","../src/useRandomId.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["// 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","// 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 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","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 { 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":["getWindowDimensions","window","width","undefined","height","_window","innerWidth","innerHeight","getNodeText","node","_node$props$children","_node$props","includes","toString","Array","map","join","trim","props","children","_ref","condition","wrapper","React","createElement","Fragment","_len","arguments","length","refs","_key","_i","_refs","ref","current","callBack","debounceTime","timeoutRef","useRef","useEffect","clearTimeout","args","setTimeout","apply","setValue","useState","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":"uHAQMA,EAAsB,WAC1B,GAAsB,oBAAXC,OACT,MAAO,CAAEC,WAAOC,EAAWC,YAAQD,GAErC,IAAAE,EAAmDJ,OACnD,MAAO,CACLC,MAFuBG,EAAjBC,WAGNF,OAH4CC,EAAnBE,YAK7B,EChBaC,EAAc,SACzBC,GACU,IAAAC,EAAAC,EACV,OAAIF,QAA4C,GAC5C,CAAC,SAAU,UAAUG,gBAAgBH,GAAcA,EAAKI,WACxDJ,aAAgBK,MAAcL,EAAKM,IAAIP,GAAaQ,KAAK,IAAIC,OAC7C,iBAATR,EAEFD,SAAWE,EAAW,OAAXC,EAACF,EAAKS,YAAK,EAAVP,EAAYQ,UAAQT,EAAI,IAAIO,OAC1C,SACT,6BCHkC,SAAHG,GAAA,IAG7BD,EAAQC,EAARD,SAAQ,OAFCC,EAATC,WAGyCC,EAFlCF,EAAPE,SAEiDH,GAAYI,EAAAC,cAAAD,EAAAE,SAAA,KAAGN,EAAY,0CCZrD,WAOrB,IAAA,IAAAO,EAAAC,UAAAC,OANCC,EAKAf,IAAAA,MAAAY,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IALAD,EAKAC,GAAAH,UAAAG,GAEH,OAAO,SAACrB,GACN,IAAA,IAAAsB,EAAA,EAAAC,EAAkBH,EAAIE,EAAAC,EAAAJ,OAAAG,IAAE,CAAnB,IAAME,EAAGD,EAAAD,GACO,mBAARE,EACTA,EAAIx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,GAEjC,WAAA,aAAME,SAAAA,EAAYH,oBAAoB,UAAWC,EAAiB,CAC3E,GAAG,CAAC5B,EAAKc,GACX,qBCdM,SAAqBiB,GACzB,IAAMC,EAAS1C,EAAMe,QAAgB,GAErCf,EAAMgB,WAAU,WACT0B,EAAO/B,UACV+B,EAAO/B,SAAU,EACjB8B,IAEJ,GAAG,CAACA,GACN,sBCT2B,SAACE,GAE1B,OAAUA,EAAM,IADJ3C,EAAMe,OAAO6B,OAAOC,KAAKC,UAAUC,UAAU,IACjCpC,OAC1B,8BTcmC,WACjC,IAAAqC,EAAgD1B,WAC9C7C,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,iCUGgB,WAiBhB"}
|
package/dist/utils.esm.js
CHANGED
|
@@ -108,7 +108,7 @@ var useOnEscape = function useOnEscape(ref, handler) {
|
|
|
108
108
|
if (event.key === 'Escape') handler();
|
|
109
109
|
};
|
|
110
110
|
var currentRef = ref.current;
|
|
111
|
-
currentRef == null
|
|
111
|
+
currentRef == null || currentRef.addEventListener('keydown', runIfKeyIsEscape);
|
|
112
112
|
return function () {
|
|
113
113
|
return currentRef == null ? void 0 : currentRef.removeEventListener('keydown', runIfKeyIsEscape);
|
|
114
114
|
};
|
|
@@ -168,9 +168,9 @@ function checkAndWarn() {
|
|
|
168
168
|
}
|
|
169
169
|
/** Warns the developer if they have forgotten to include styles */
|
|
170
170
|
function warnAboutMissingStyles() {
|
|
171
|
-
var _process
|
|
171
|
+
var _process;
|
|
172
172
|
// We skip this check in production, and when we build static sites
|
|
173
|
-
if (!(process.env.NODE_ENV !== "production") || typeof window === 'undefined' || typeof process !== 'undefined' && ((_process = process) == null
|
|
173
|
+
if (!(process.env.NODE_ENV !== "production") || typeof window === 'undefined' || typeof process !== 'undefined' && ((_process = process) == null || (_process = _process.env) == null ? void 0 : _process.TEST) === 'true') {
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
176
|
// First, let's clear earlier calls to setTimeout
|
|
@@ -187,16 +187,16 @@ function warnAboutMissingStyles() {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// with inspiration from https://stackoverflow.com/questions/50428910/get-text-content-from-node-in-react
|
|
190
|
-
var
|
|
190
|
+
var _getNodeText = function getNodeText(node) {
|
|
191
191
|
var _node$props$children, _node$props;
|
|
192
192
|
if (node === null || node === undefined) return '';
|
|
193
193
|
if (['string', 'number'].includes(typeof node)) return node.toString();
|
|
194
|
-
if (node instanceof Array) return node.map(
|
|
194
|
+
if (node instanceof Array) return node.map(_getNodeText).join('').trim();
|
|
195
195
|
if (typeof node === 'object')
|
|
196
196
|
// @ts-expect-error props does exist for react nodes
|
|
197
|
-
return
|
|
197
|
+
return _getNodeText((_node$props$children = (_node$props = node.props) == null ? void 0 : _node$props.children) != null ? _node$props$children : '').trim();
|
|
198
198
|
return 'unknown';
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
export { ConditionalWrapper, getNodeText, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
|
|
201
|
+
export { ConditionalWrapper, _getNodeText as getNodeText, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
|
|
202
202
|
//# sourceMappingURL=utils.esm.js.map
|
package/dist/utils.esm.js.map
CHANGED
|
@@ -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","../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,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,EAAE,OAAOA,IAAI,CAACqE,QAAQ,EAAE,CAAA;AACtE,EAAA,IAAIrE,IAAI,YAAY8C,KAAK,EAAE,OAAO9C,IAAI,CAAC0D,GAAG,CAACS,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;;;;"}
|
|
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","_len","arguments","length","args","Array","_key","setTimeout","apply","useRandomId","prefix","ref","React","String","Math","random","substring","useOnMount","callback","hasRun","mergeRefs","refs","node","_i","_refs","useForceUpdate","_useState","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","_window","innerWidth","innerHeight","useWindowDimensions","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","_ref","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","process","env","NODE_ENV","warning","map","join","warnAboutMissingStyles","_process","TEST","namespaces","forEach","add","getNodeText","_node$props$children","_node$props","includes","toString","trim","props"],"mappings":";;;AAEgB,SAAAA,WAAWA,CACzBC,QAAW,EACXC,YAAoB,EAAA;AAEpB,EAAA,IAAMC,UAAU,GAAGC,MAAM,EAAiC,CAAA;AAE1DC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAA,OAAO,YAAK;MACV,IAAI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AA,GAAA,KAAA,CAAA,GAAVJ,WAAA,CAAY/B,QAAQ,YAAA8B,oBAAA,GAAI,EAAE,CAAC,CAACI,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.12.0",
|
|
3
|
+
"version": "0.12.2-RC.0",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/utils.esm.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://
|
|
13
|
+
"url": "https://github.com/entur/design-system.git",
|
|
14
14
|
"directory": "packages/utils"
|
|
15
15
|
},
|
|
16
16
|
"publishConfig": {
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"tiny-warning": "^1.0.3"
|
|
30
30
|
},
|
|
31
|
-
"
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"dts-cli": "2.0.5"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "d7913682a41ade219cbd4dfc6e45060152c7fa0a"
|
|
32
35
|
}
|