@entur/utils 0.9.4 → 0.10.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.
@@ -1,7 +1,7 @@
1
- type ConditionalWrapperType = {
2
- condition: boolean;
3
- wrapper: any;
4
- children: any;
5
- };
6
- export declare const ConditionalWrapper: ({ condition, wrapper, children, }: ConditionalWrapperType) => any;
7
- export {};
1
+ type ConditionalWrapperType = {
2
+ condition: boolean;
3
+ wrapper: any;
4
+ children: any;
5
+ };
6
+ export declare const ConditionalWrapper: ({ condition, wrapper, children, }: ConditionalWrapperType) => any;
7
+ export {};
@@ -1,41 +1,41 @@
1
- /** These polymorphic types are derrived from Ben Ilegbodu's article available at the following link:
2
- * https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/
3
- */
4
- import React from 'react';
5
- export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;
6
- type AsProp<C extends React.ElementType> = {
7
- /**
8
- * An override of the default HTML tag.
9
- * Can also be another React component.
10
- */
11
- as?: C;
12
- };
13
- /**
14
- * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props
15
- * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding
16
- * set of props.
17
- */
18
- export type ExtendableProps<ExtendedProps = Record<string, unknown>, OverrideProps = Record<string, unknown>> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;
19
- /**
20
- * Allows for inheriting the props from the specified element type so that
21
- * props like children, className & style work, as well as element-specific
22
- * attributes like aria roles. The component (`C`) must be passed in.
23
- */
24
- export type InheritableElementProps<C extends React.ElementType, Props = Record<string, unknown>> = ExtendableProps<PropsOf<C>, Props>;
25
- /**
26
- * A more sophisticated version of `InheritableElementProps` where
27
- * the passed in `as` prop will determine which props can be included
28
- */
29
- export type PolymorphicComponentProps<C extends React.ElementType, Props = Record<string, unknown>> = InheritableElementProps<C, Props & AsProp<C>>;
30
- /**
31
- * Utility type to extract the `ref` prop from a polymorphic component
32
- */
33
- export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref'];
34
- /**
35
- * A wrapper of `PolymorphicComponentProps` that also includes the `ref`
36
- * prop for the polymorphic component
37
- */
38
- export type PolymorphicComponentPropsWithRef<C extends React.ElementType, Props = Record<string, unknown>> = PolymorphicComponentProps<C, Props> & {
39
- ref?: PolymorphicRef<C>;
40
- };
41
- export {};
1
+ /** These polymorphic types are derrived from Ben Ilegbodu's article available at the following link:
2
+ * https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/
3
+ */
4
+ import React from 'react';
5
+ export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;
6
+ type AsProp<C extends React.ElementType> = {
7
+ /**
8
+ * An override of the default HTML tag.
9
+ * Can also be another React component.
10
+ */
11
+ as?: C;
12
+ };
13
+ /**
14
+ * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props
15
+ * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding
16
+ * set of props.
17
+ */
18
+ export type ExtendableProps<ExtendedProps = Record<string, unknown>, OverrideProps = Record<string, unknown>> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;
19
+ /**
20
+ * Allows for inheriting the props from the specified element type so that
21
+ * props like children, className & style work, as well as element-specific
22
+ * attributes like aria roles. The component (`C`) must be passed in.
23
+ */
24
+ export type InheritableElementProps<C extends React.ElementType, Props = Record<string, unknown>> = ExtendableProps<PropsOf<C>, Props>;
25
+ /**
26
+ * A more sophisticated version of `InheritableElementProps` where
27
+ * the passed in `as` prop will determine which props can be included
28
+ */
29
+ export type PolymorphicComponentProps<C extends React.ElementType, Props = Record<string, unknown>> = InheritableElementProps<C, Props & AsProp<C>>;
30
+ /**
31
+ * Utility type to extract the `ref` prop from a polymorphic component
32
+ */
33
+ export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref'];
34
+ /**
35
+ * A wrapper of `PolymorphicComponentProps` that also includes the `ref`
36
+ * prop for the polymorphic component
37
+ */
38
+ export type PolymorphicComponentPropsWithRef<C extends React.ElementType, Props = Record<string, unknown>> = PolymorphicComponentProps<C, Props> & {
39
+ ref?: PolymorphicRef<C>;
40
+ };
41
+ export {};
@@ -1,13 +1,13 @@
1
- @import '~@entur/tokens/dist/styles.scss';
1
+ @use '~@entur/tokens/dist/styles.scss' as t;
2
2
 
3
3
  @mixin for-desktop {
4
- @media screen and (min-width: #{$breakpoints-large}) {
4
+ @media screen and (min-width: #{t.$breakpoints-large}) {
5
5
  @content;
6
6
  }
7
7
  }
8
8
 
9
9
  @mixin for-large-desktop {
10
- @media screen and (min-width: #{$breakpoints-extra-large}) {
10
+ @media screen and (min-width: #{t.$breakpoints-extra-large}) {
11
11
  @content;
12
12
  }
13
13
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './debounce';
2
- export * from './PolymorphicComponent';
3
- export * from './useRandomId';
4
- export * from './useOnMount';
5
- export * from './mergeRefs';
6
- export * from './useForceUpdate';
7
- export * from './useOnClickOutside';
8
- export * from './useOnEscape';
9
- export * from './useWindowDimensions';
10
- export * from './ConditionalWrapper';
11
- export * from './warnAboutMissingStyles';
1
+ export * from './PolymorphicComponent';
2
+ export * from './useDebounce';
3
+ export * from './useRandomId';
4
+ export * from './useOnMount';
5
+ export * from './mergeRefs';
6
+ export * from './useForceUpdate';
7
+ export * from './useOnClickOutside';
8
+ export * from './useOnEscape';
9
+ export * from './useWindowDimensions';
10
+ export * from './ConditionalWrapper';
11
+ export * from './warnAboutMissingStyles';
@@ -1,2 +1,2 @@
1
- /// <reference types="react" />
2
- export declare const mergeRefs: <T extends HTMLElement>(...refs: (import("react").MutableRefObject<T> | import("react").ForwardedRef<T> | undefined)[]) => (node: T) => void;
1
+ /// <reference types="react" />
2
+ export declare const mergeRefs: <T extends HTMLElement>(...refs: (import("react").MutableRefObject<T> | import("react").ForwardedRef<T> | undefined)[]) => (node: T) => void;
@@ -0,0 +1 @@
1
+ export declare function useDebounce<T extends (...args: any[]) => any>(callBack: T, debounceTime: number): T;
@@ -1 +1 @@
1
- export declare const useForceUpdate: () => () => void;
1
+ export declare const useForceUpdate: () => () => void;
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const useOnClickOutside: (refs: React.RefObject<HTMLDivElement>[], handler: () => void) => void;
1
+ import React from 'react';
2
+ export declare const useOnClickOutside: (refs: React.RefObject<HTMLDivElement>[], handler: () => void) => void;
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const useOnEscape: (ref: React.RefObject<HTMLElement>, handler: () => void) => void;
1
+ import React from 'react';
2
+ export declare const useOnEscape: (ref: React.RefObject<HTMLElement>, handler: () => void) => void;
@@ -1 +1 @@
1
- export declare function useOnMount(callback: () => void): void;
1
+ export declare function useOnMount(callback: () => void): void;
@@ -1 +1 @@
1
- export declare const useRandomId: (prefix?: string) => string;
1
+ export declare const useRandomId: (prefix?: string) => string;
@@ -1,6 +1,6 @@
1
- type WindowDimensions = {
2
- width: number | undefined;
3
- height: number | undefined;
4
- };
5
- export declare const useWindowDimensions: () => WindowDimensions;
6
- export {};
1
+ type WindowDimensions = {
2
+ width: number | undefined;
3
+ height: number | undefined;
4
+ };
5
+ export declare const useWindowDimensions: () => WindowDimensions;
6
+ export {};
@@ -5,32 +5,37 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var warning = require('tiny-warning');
7
7
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
11
- var warning__default = /*#__PURE__*/_interopDefaultLegacy(warning);
12
-
13
- function debounce(fn, delay) {
14
- var id;
15
- return function () {
8
+ function useDebounce(callBack, debounceTime) {
9
+ var timeoutRef = React.useRef();
10
+ React.useEffect(function () {
11
+ return function () {
12
+ if (timeoutRef.current) {
13
+ clearTimeout(timeoutRef.current);
14
+ }
15
+ };
16
+ }, []);
17
+ var debouncedFunc = function debouncedFunc() {
16
18
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17
19
  args[_key] = arguments[_key];
18
20
  }
19
- clearTimeout(id);
20
- id = setTimeout(function () {
21
- return fn.apply(void 0, args);
22
- }, delay);
21
+ if (timeoutRef.current) {
22
+ clearTimeout(timeoutRef.current);
23
+ }
24
+ timeoutRef.current = setTimeout(function () {
25
+ callBack.apply(void 0, args);
26
+ }, debounceTime);
23
27
  };
28
+ return debouncedFunc;
24
29
  }
25
30
 
26
31
  var useRandomId = function useRandomId(prefix) {
27
- var ref = React__default["default"].useRef(String(Math.random()).substring(2));
32
+ var ref = React.useRef(String(Math.random()).substring(2));
28
33
  return prefix + "-" + ref.current;
29
34
  };
30
35
 
31
36
  function useOnMount(callback) {
32
- var hasRun = React__default["default"].useRef(false);
33
- React__default["default"].useEffect(function () {
37
+ var hasRun = React.useRef(false);
38
+ React.useEffect(function () {
34
39
  if (!hasRun.current) {
35
40
  hasRun.current = true;
36
41
  callback();
@@ -150,7 +155,7 @@ var ConditionalWrapper = function ConditionalWrapper(_ref) {
150
155
  var condition = _ref.condition,
151
156
  wrapper = _ref.wrapper,
152
157
  children = _ref.children;
153
- return condition ? wrapper(children) : React__default["default"].createElement(React__default["default"].Fragment, null, children);
158
+ return condition ? wrapper(children) : React.createElement(React.Fragment, null, children);
154
159
  };
155
160
 
156
161
  var packagesToCheck = /*#__PURE__*/new Set();
@@ -161,7 +166,7 @@ function checkAndWarn() {
161
166
  }).sort();
162
167
  // Finally, we warn about those pesky imports
163
168
  var singleMissingImport = missingImports.length === 1;
164
- warning__default["default"](missingImports.length === 0, "You are missing " + (singleMissingImport ? 'a CSS import' : missingImports.length + " CSS imports") + "!\n\nPlease add the following CSS import" + (singleMissingImport ? '' : 's') + " somewhere in your app:\n\n" + missingImports.map(function (namespace) {
169
+ warning(missingImports.length === 0, "You are missing " + (singleMissingImport ? 'a CSS import' : missingImports.length + " CSS imports") + "!\n\nPlease add the following CSS import" + (singleMissingImport ? '' : 's') + " somewhere in your app:\n\n" + missingImports.map(function (namespace) {
165
170
  return "\t@import '@entur/" + namespace + "/dist/styles.css';";
166
171
  }).join('\n') + "\n") ;
167
172
  }
@@ -185,8 +190,8 @@ function warnAboutMissingStyles() {
185
190
  }
186
191
 
187
192
  exports.ConditionalWrapper = ConditionalWrapper;
188
- exports.debounce = debounce;
189
193
  exports.mergeRefs = mergeRefs;
194
+ exports.useDebounce = useDebounce;
190
195
  exports.useForceUpdate = useForceUpdate;
191
196
  exports.useOnClickOutside = useOnClickOutside;
192
197
  exports.useOnEscape = useOnEscape;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.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":["export function debounce<T extends (...args: any[]) => any>(\n fn: T,\n delay: number,\n): (...args: Parameters<T>) => void {\n let id: any;\n return (...args) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\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: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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":["debounce","fn","delay","id","args","clearTimeout","setTimeout","useRandomId","prefix","ref","React","useRef","String","Math","random","substring","current","useOnMount","callback","hasRun","useEffect","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","namespaces","forEach","add"],"mappings":";;;;;;;;;;;;AAAgB,SAAAA,QAAQ,CACtBC,EAAK,EACLC,KAAa,EAAA;AAEb,EAAA,IAAIC,EAAO,CAAA;AACX,EAAA,OAAO,YAAY;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAARC,IAAI,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAJA,IAAI,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,KAAA;IACbC,YAAY,CAACF,EAAE,CAAC,CAAA;IAChBA,EAAE,GAAGG,UAAU,CAAC,YAAA;MAAA,OAAML,EAAE,CAAIG,KAAAA,CAAAA,KAAAA,CAAAA,EAAAA,IAAI,CAAC,CAAA;AAAA,KAAA,EAAEF,KAAK,CAAC,CAAA;GAC1C,CAAA;AACH;;ICPaK,WAAW,GAAG,SAAdA,WAAW,CAAIC,MAAe,EAAY;AACrD,EAAA,IAAMC,GAAG,GAAGC,yBAAK,CAACC,MAAM,CAACC,MAAM,CAACC,IAAI,CAACC,MAAM,EAAE,CAAC,CAACC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5D,EAAA,OAAUP,MAAM,GAAA,GAAA,GAAIC,GAAG,CAACO,OAAO,CAAA;AACjC;;ACHM,SAAUC,UAAU,CAACC,QAAoB,EAAA;AAC7C,EAAA,I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A,UAAoB,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAS5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAb,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAACrC,UAAU,CAAC6D,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"],"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: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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","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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AAC,GAEV,IAAA,CAAA,CAAA,CAAA;AACH,CAAA;AAEA;AACgB,SAAAC,sBAAsB,GAAwB;AAC5D;AACA,EAAA,IAAgB,OAAOxC,MAAM,KAAK,WAAW,EAAE;AAC7C,IAAA,OAAA;AACD,GAAA;AACD;AACAA,EAAAA,MAAM,CAACrC,YAAY,CAAC4D,cAAc,CAAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EARwCkB,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;AAS5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAb,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAAClC,UAAU,CAAC0D,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("tiny-warning");var t=n(e),r=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(e){var n=e.children;return e.condition?(0,e.wrapper)(n):t.default.createElement(t.default.Fragment,null,n)},exports.debounce=function(e,n){var t;return function(){for(var r=arguments.length,u=new Array(r),o=0;o<r;o++)u[o]=arguments[o];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,u)}),n)}},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.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(e){var n=t.default.useRef(!1);t.default.useEffect((function(){n.current||(n.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+t.default.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var n=e.useState(r()),t=n[0],u=n[1];return e.useEffect((function(){function e(){u(r())}if("undefined"!=typeof window)return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),t},exports.warnAboutMissingStyles=function(){};
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(){};
2
2
  //# sourceMappingURL=utils.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/debounce.ts","../src/mergeRefs.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","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 function debounce<T extends (...args: any[]) => any>(\n fn: T,\n delay: number,\n): (...args: Parameters<T>) => void {\n let id: any;\n return (...args) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\n}\n","export const mergeRefs = <T extends HTMLElement>(\n ...refs: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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","_ref","children","condition","wrapper","React","createElement","Fragment","fn","delay","id","_len","arguments","length","args","Array","_key","clearTimeout","setTimeout","refs","node","_i","_refs","ref","current","useState","setValue","value","handler","useEffect","listener","event","some","element","contains","target","composed","composedPath","find","elementContainsEventTarget","document","addEventListener","removeEventListener","runIfKeyIsEscape","key","currentRef","callback","hasRun","useRef","prefix","String","Math","random","substring","_useState","windowDimensions","setWindowDimensions","handleResize"],"mappings":"sMAQMA,EAAsB,WAC1B,GAAsB,oBAAXC,OACT,MAAO,CAAEC,WAAOC,EAAWC,YAAQD,GAErC,IAAAE,EAAmDJ,OACnD,MAAO,CACLC,QAFMI,WAGNF,SAHyBG,yCCJK,SAAHC,GAAA,IAG7BC,IAAAA,SAAQ,SAFRC,WAGyCC,IAFzCA,SAEiDF,GAAYG,EAAA,QAAAC,cAAAD,EAAAA,QAAAE,SAAA,KAAGL,qBCZlD,SACdM,EACAC,GAEA,IAAIC,EACJ,OAAO,WAAY,IAAA,IAAAC,EAAAC,UAAAC,OAARC,EAAI,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAJF,EAAIE,GAAAJ,UAAAI,GACbC,aAAaP,GACbA,EAAKQ,YAAW,WAAA,OAAMV,EAAMM,WAAAA,EAAAA,KAAOL,uBCPd,WAErB,IAAA,IAAAE,EAAAC,UAAAC,OADCM,EAAuE,IAAAJ,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAvEG,EAAuEH,GAAAJ,UAAAI,GAE1E,OAAO,SAACI,GACN,IAAA,IAAAC,EAAA,EAAAC,EAAkBH,EAAME,EAAAC,EAAAT,OAAAQ,IAAA,CAAnB,IAAME,EAAGD,EAA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4B,IACPD,EAAoB/D,KAGtB,GAAsB,oBAAXC,OAET,OADAA,OAAO+C,iBAAiB,SAAUgB,GAC3B,WAAA,OAAM/D,OAAOgD,oBAAoB,SAAUe,MAEnD,IAEIF,kCSIO"}
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: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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","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,WAahB"}
package/dist/utils.esm.js CHANGED
@@ -1,17 +1,27 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, { useRef, useEffect, useState } from 'react';
2
2
  import warning from 'tiny-warning';
3
3
 
4
- function debounce(fn, delay) {
5
- var id;
6
- return function () {
4
+ function useDebounce(callBack, debounceTime) {
5
+ var timeoutRef = useRef();
6
+ useEffect(function () {
7
+ return function () {
8
+ if (timeoutRef.current) {
9
+ clearTimeout(timeoutRef.current);
10
+ }
11
+ };
12
+ }, []);
13
+ var debouncedFunc = function debouncedFunc() {
7
14
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
8
15
  args[_key] = arguments[_key];
9
16
  }
10
- clearTimeout(id);
11
- id = setTimeout(function () {
12
- return fn.apply(void 0, args);
13
- }, delay);
17
+ if (timeoutRef.current) {
18
+ clearTimeout(timeoutRef.current);
19
+ }
20
+ timeoutRef.current = setTimeout(function () {
21
+ callBack.apply(void 0, args);
22
+ }, debounceTime);
14
23
  };
24
+ return debouncedFunc;
15
25
  }
16
26
 
17
27
  var useRandomId = function useRandomId(prefix) {
@@ -175,5 +185,5 @@ function warnAboutMissingStyles() {
175
185
  checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
176
186
  }
177
187
 
178
- export { ConditionalWrapper, debounce, mergeRefs, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
188
+ export { ConditionalWrapper, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles };
179
189
  //# sourceMappingURL=utils.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../src/debounce.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":["export function debounce<T extends (...args: any[]) => any>(\n fn: T,\n delay: number,\n): (...args: Parameters<T>) => void {\n let id: any;\n return (...args) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\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: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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":["debounce","fn","delay","id","args","clearTimeout","setTimeout","useRandomId","prefix","ref","React","useRef","String","Math","random","substring","current","useOnMount","callback","hasRun","useEffect","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","namespaces","forEach","add"],"mappings":";;;AAAgB,SAAAA,QAAQ,CACtBC,EAAK,EACLC,KAAa,EAAA;AAEb,EAAA,IAAIC,EAAO,CAAA;AACX,EAAA,OAAO,YAAY;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAARC,IAAI,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAJA,IAAI,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,KAAA;IACb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A,cAAc,CACba,GAAG,CAAC,UAAAT,SAAS,EAAA;AAAA,IAAA,OAAA,oBAAA,GAAyBA,SAAS,GAAA,oBAAA,CAAA;AAAA,GAAoB,CAAC,CACpEU,IAAI,CAAC,IAAI,CAAC,GAEV,IAAA,CAAA,GAAA,KAAA,CAAA,CAAA;AACH,CAAA;AAEA;AACgB,SAAAC,sBAAsB,GAAwB;AAC5D;AACA,EAAA,IAAI,wCAAQ,IAAI,OAAOxC,MAAM,KAAK,WAAW,EAAE;AAC7C,IAAA,OAAA;AACD,GAAA;AACD;AACAA,EAAAA,MAAM,CAACtC,YAAY,CAAC6D,cAAc,CAAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EARwCkB,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;AAS5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAb,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAACrC,UAAU,CAAC6D,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"],"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: (React.MutableRefObject<T> | React.ForwardedRef<T> | undefined)[]\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<HTMLDivElement>[],\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 (!__DEV__ || typeof window === 'undefined') {\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","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;AACj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,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGvB,MAAM,CAAClC,UAAU,CAAC0D,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;"}
@@ -1,2 +1,2 @@
1
- /** Warns the developer if they have forgotten to include styles */
2
- export declare function warnAboutMissingStyles(...namespaces: string[]): void;
1
+ /** Warns the developer if they have forgotten to include styles */
2
+ export declare function warnAboutMissingStyles(...namespaces: string[]): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entur/utils",
3
- "version": "0.9.4",
3
+ "version": "0.10.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": "0da1a9e2532f60cc1a456a79ad3aa689514ca2c7"
31
+ "gitHead": "55899d49a6bab285199abb7c6709da8088e5a2e3"
32
32
  }
@@ -1 +0,0 @@
1
- export declare function debounce<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void;