@entur/utils 0.15.3 → 0.16.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,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
- export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;
2
+ export type PropsOf<C extends keyof React.JSX.IntrinsicElements | React.JSXElementConstructor<any>> = React.JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;
3
3
  type AsProp<C extends React.ElementType> = {
4
4
  /**
5
5
  * An override of the default HTML tag.
@@ -35,4 +35,11 @@ export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWi
35
35
  export type PolymorphicComponentPropsWithRef<C extends React.ElementType, Props = Record<string, unknown>> = PolymorphicComponentProps<C, Props> & {
36
36
  ref?: PolymorphicRef<C>;
37
37
  };
38
+ /**
39
+ * `React.forwardRef` for components with an `as` prop. Type the result with
40
+ * the component's own polymorphic call signature, since `forwardRef` drops
41
+ * the generic element type. Props and ref are untyped here, so keep the render
42
+ * function in line with `Component`.
43
+ */
44
+ export declare const forwardRefPolymorphic: <Component extends (props: any) => React.ReactElement | null>(render: (props: any, ref: any) => React.ReactNode) => Component;
38
45
  export {};
package/dist/utils.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const warning = require("tiny-warning");
5
+ const forwardRefPolymorphic = (render) => React.forwardRef(render);
5
6
  function useDebounce(callBack, debounceTime) {
6
7
  const timeoutRef = React.useRef();
7
8
  React.useEffect(() => {
@@ -174,6 +175,7 @@ function useControllableProp({
174
175
  return prop === void 0 ? [internalState, setInternalState] : [prop, updater];
175
176
  }
176
177
  exports.ConditionalWrapper = ConditionalWrapper;
178
+ exports.forwardRefPolymorphic = forwardRefPolymorphic;
177
179
  exports.getActiveElement = getActiveElement;
178
180
  exports.getNodeText = getNodeText;
179
181
  exports.mergeRefs = mergeRefs;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","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/getActiveElement.ts","../src/getNodeText.ts","../src/useControllableProp.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 { useId } from 'react';\n\n/**\n * @deprecated Use `useId()` from React directly instead.\n * Will be removed in a future major version.\n *\n * ```diff\n * - import { useRandomId } from '@entur/utils';\n * - const id = useRandomId('eds-my-component');\n * + import { useId } from 'react';\n * + const id = `eds-my-component${useId()}`;\n * ```\n */\nexport const useRandomId = (prefix?: string): string => {\n const id = useId();\n return prefix ? `${prefix}${id}` : id;\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;\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 { useSyncExternalStore } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('resize', callback);\n return () => window.removeEventListener('resize', callback);\n};\n\nlet cachedSnapshot: WindowDimensions = { width: undefined, height: undefined };\n\nconst getSnapshot = (): WindowDimensions => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n if (cachedSnapshot.width !== width || cachedSnapshot.height !== height) {\n cachedSnapshot = { width, height };\n }\n return cachedSnapshot;\n};\n\nconst serverSnapshot: WindowDimensions = {\n width: undefined,\n height: undefined,\n};\nconst getServerSnapshot = () => serverSnapshot;\n\nexport const useWindowDimensions = (): WindowDimensions => {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n","type 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 typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true') ||\n (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'production')\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","/**\n * Returns the active element, drilling into shadow roots.\n * `document.activeElement` stops at the shadow host — this\n * follows the chain into nested shadow roots.\n *\n * Use this instead of `document.activeElement` whenever the result is\n * compared to an element that may live inside a shadow root.\n *\n * Returns `null` when there is no DOM, so it is safe to call during\n * server rendering.\n */\nexport function getActiveElement(root?: Document | ShadowRoot): Element | null {\n const target =\n root ?? (typeof document === 'undefined' ? undefined : document);\n const active = target?.activeElement ?? null;\n if (active?.shadowRoot) {\n return getActiveElement(active.shadowRoot);\n }\n return active;\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 { useEffect, useState } from 'react';\nexport type UseControllablePropType<T> = {\n prop?: T;\n updater?: (value?: T) => void;\n defaultValue: T;\n};\nexport function useControllableProp<T>({\n prop,\n updater = () => undefined,\n defaultValue,\n}: UseControllablePropType<T>): [T, (arg: T) => void] {\n const [internalState, setInternalState] = useState<T>(defaultValue);\n useEffect(() => {\n if (prop !== undefined) {\n setInternalState(prop);\n }\n }, [prop]);\n return prop === undefined\n ? [internalState, setInternalState]\n : [prop, updater];\n}\n"],"names":["useRef","useEffect","useId","useState","useSyncExternalStore"],"mappings":";;;;AAEO,SAAS,YACd,UACA,cACA;AACA,QAAM,aAAaA,MAAAA,OAAA;AAEnBC,QAAAA,UAAU,MAAM;AACd,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,qBAAa,WAAW,OAAO;AAAA,MACjC;AAAA,IACF;AAAA,EACF,GAAG,CAAA,CAAE;AAEL,QAAM,gBAAgB,IAAI,SAAgB;AACxC,QAAI,WAAW,SAAS;AACtB,mBAAa,WAAW,OAAO;AAAA,IACjC;AAEA,eAAW,UAAU,WAAW,MAAM;AACpC,eAAS,GAA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K,OAAO,YAAY,EAAE,EAAE,KAAA;AACjD,SAAO;AACT;ACLO,SAAS,oBAAuB;AAAA,EACrC;AAAA,EACA,UAAU,MAAM;AAAA,EAChB;AACF,GAAsD;AACpD,QAAM,CAAC,eAAe,gBAAgB,IAAID,MAAAA,SAAY,YAAY;AAClEF,QAAAA,UAAU,MAAM;AACd,QAAI,SAAS,QAAW;AACtB,uBAAiB,IAAI;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AACT,SAAO,SAAS,SACZ,CAAC,eAAe,gBAAgB,IAChC,CAAC,MAAM,OAAO;AACpB;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.cjs","sources":["../src/PolymorphicComponent.tsx","../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/getActiveElement.ts","../src/getNodeText.ts","../src/useControllableProp.ts"],"sourcesContent":["/** These polymorphic types are derrived from Ben Ilegbodu's article available at the following link:\n * https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/\n */\n\nimport React from 'react';\n\n// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts\n// A more precise version of just React.ComponentPropsWithoutRef on its own\nexport type PropsOf<\n C extends\n | keyof React.JSX.IntrinsicElements\n | React.JSXElementConstructor<any>,\n> = React.JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;\n\ntype AsProp<C extends React.ElementType> = {\n /**\n * An override of the default HTML tag.\n * Can also be another React component.\n */\n as?: C;\n};\n\n/**\n * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props\n * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding\n * set of props.\n */\nexport type ExtendableProps<\n ExtendedProps = Record<string, unknown>,\n OverrideProps = Record<string, unknown>,\n> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;\n\n/**\n * Allows for inheriting the props from the specified element type so that\n * props like children, className & style work, as well as element-specific\n * attributes like aria roles. The component (`C`) must be passed in.\n */\nexport type InheritableElementProps<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = ExtendableProps<PropsOf<C>, Props>;\n\n/**\n * A more sophisticated version of `InheritableElementProps` where\n * the passed in `as` prop will determine which props can be included\n */\nexport type PolymorphicComponentProps<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = InheritableElementProps<C, Props & AsProp<C>>;\n\n/**\n * Utility type to extract the `ref` prop from a polymorphic component\n */\nexport type PolymorphicRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>['ref'];\n/**\n * A wrapper of `PolymorphicComponentProps` that also includes the `ref`\n * prop for the polymorphic component\n */\nexport type PolymorphicComponentPropsWithRef<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> };\n\n/**\n * `React.forwardRef` for components with an `as` prop. Type the result with\n * the component's own polymorphic call signature, since `forwardRef` drops\n * the generic element type. Props and ref are untyped here, so keep the render\n * function in line with `Component`.\n */\nexport const forwardRefPolymorphic = <\n Component extends (props: any) => React.ReactElement | null,\n>(\n render: (props: any, ref: any) => React.ReactNode,\n): Component => React.forwardRef(render) as unknown as Component;\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 { useId } from 'react';\n\n/**\n * @deprecated Use `useId()` from React directly instead.\n * Will be removed in a future major version.\n *\n * ```diff\n * - import { useRandomId } from '@entur/utils';\n * - const id = useRandomId('eds-my-component');\n * + import { useId } from 'react';\n * + const id = `eds-my-component${useId()}`;\n * ```\n */\nexport const useRandomId = (prefix?: string): string => {\n const id = useId();\n return prefix ? `${prefix}${id}` : id;\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;\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 { useSyncExternalStore } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('resize', callback);\n return () => window.removeEventListener('resize', callback);\n};\n\nlet cachedSnapshot: WindowDimensions = { width: undefined, height: undefined };\n\nconst getSnapshot = (): WindowDimensions => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n if (cachedSnapshot.width !== width || cachedSnapshot.height !== height) {\n cachedSnapshot = { width, height };\n }\n return cachedSnapshot;\n};\n\nconst serverSnapshot: WindowDimensions = {\n width: undefined,\n height: undefined,\n};\nconst getServerSnapshot = () => serverSnapshot;\n\nexport const useWindowDimensions = (): WindowDimensions => {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n","type 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 typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true') ||\n (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'production')\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","/**\n * Returns the active element, drilling into shadow roots.\n * `document.activeElement` stops at the shadow host — this\n * follows the chain into nested shadow roots.\n *\n * Use this instead of `document.activeElement` whenever the result is\n * compared to an element that may live inside a shadow root.\n *\n * Returns `null` when there is no DOM, so it is safe to call during\n * server rendering.\n */\nexport function getActiveElement(root?: Document | ShadowRoot): Element | null {\n const target =\n root ?? (typeof document === 'undefined' ? undefined : document);\n const active = target?.activeElement ?? null;\n if (active?.shadowRoot) {\n return getActiveElement(active.shadowRoot);\n }\n return active;\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 { useEffect, useState } from 'react';\nexport type UseControllablePropType<T> = {\n prop?: T;\n updater?: (value?: T) => void;\n defaultValue: T;\n};\nexport function useControllableProp<T>({\n prop,\n updater = () => undefined,\n defaultValue,\n}: UseControllablePropType<T>): [T, (arg: T) => void] {\n const [internalState, setInternalState] = useState<T>(defaultValue);\n useEffect(() => {\n if (prop !== undefined) {\n setInternalState(prop);\n }\n }, [prop]);\n return prop === undefined\n ? [internalState, setInternalState]\n : [prop, updater];\n}\n"],"names":["useRef","useEffect","useId","useState","useSyncExternalStore"],"mappings":";;;;AAuEO,MAAM,wBAAwB,CAGnC,WACc,MAAM,WAAW,MAAM;ACzEhC,SAAS,YACd,UACA,cACA;AACA,QAAM,aAAaA,MAAAA,OAAA;AAEnBC,QAAAA,UAAU,MAAM;AACd,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,qBAAa,WAAW,OAAO;AAAA,MACjC;AAAA,IACF;AAAA,EACF,GAAG,CAAA,CAAE;AAEL,QAAM,gBAAgB,IAAI,SAAgB;AACxC,QAAI,WAAW,SAAS;AACtB,mBAAa,WAAW,OAAO;AAAA,IACjC;AAEA,eAAW,UAAU,WAAW,MAAM;AACpC,eAAS,GAAG,IAAI;AAAA,IAClB,GAAG,YAAY;AAAA,EACjB;AAEA,SAAO;AACT;ACdO,MAAM,cAAc,CAAC,WAA4B;AACtD,QAAM,KAAKC,MAAAA,MAAA;AACX,SAAO,SAAS,GAAG,MAAM,GAAG,EAAE,KAAK;AACrC;ACdO,SAAS,WAAW,UAA4B;AACrD,QAAM,SAAS,MAAM,OAAgB,KAAK;AAE1C,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,UAAU;AACjB,eAAA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AACf;ACXO,MAAM,YAAY,IACpB,SAMA;AACH,SAAO,CAAC,SAAY;AAClB,eAAW,OAAO,MAAM;AACtB,UAAI,OAAO,QAAQ,YAAY;AAC7B,YAAI,IAAI;AAAA,MACV,WAAW,IAAK,KAAI,UAAU;AAAA,IAChC;AAAA,EACF;AACF;ACbO,MAAM,iBAAiB,MAAM;AAClC,QAAM,CAAC,GAAG,QAAQ,IAAIC,MAAAA,SAAS,CAAC;AAChC,SAAO,MA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AQ,CAAA,cAAa,gBAAgB,IAAI,SAAS,CAAC;AAG9D,mBAAiB,OAAO,WAAW,cAAc,GAAI;AACvD;AC7CO,SAAS,iBAAiB,MAA8C;AAC7E,QAAM,SACJ,SAAS,OAAO,aAAa,cAAc,SAAY;AACzD,QAAM,SAAS,QAAQ,iBAAiB;AACxC,MAAI,QAAQ,YAAY;AACtB,WAAO,iBAAiB,OAAO,UAAU;AAAA,EAC3C;AACA,SAAO;AACT;AClBO,MAAM,cAAc,CACzB,SACW;AACX,MAAI,SAAS,QAAQ,SAAS,OAAW,QAAO;AAChD,MAAI,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAO,IAAI,EAAG,QAAO,KAAK,SAAA;AAC5D,MAAI,gBAAgB,MAAO,QAAO,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,EAAE,KAAA;AACjE,MAAI,OAAO,SAAS;AAElB,WAAO,YAAY,KAAK,OAAO,YAAY,EAAE,EAAE,KAAA;AACjD,SAAO;AACT;ACLO,SAAS,oBAAuB;AAAA,EACrC;AAAA,EACA,UAAU,MAAM;AAAA,EAChB;AACF,GAAsD;AACpD,QAAM,CAAC,eAAe,gBAAgB,IAAID,MAAAA,SAAY,YAAY;AAClEF,QAAAA,UAAU,MAAM;AACd,QAAI,SAAS,QAAW;AACtB,uBAAiB,IAAI;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AACT,SAAO,SAAS,SACZ,CAAC,eAAe,gBAAgB,IAChC,CAAC,MAAM,OAAO;AACpB;;;;;;;;;;;;;;;"}
package/dist/utils.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import React, { useRef, useEffect, useId, useState, useSyncExternalStore } from "react";
2
2
  import warning from "tiny-warning";
3
+ const forwardRefPolymorphic = (render) => React.forwardRef(render);
3
4
  function useDebounce(callBack, debounceTime) {
4
5
  const timeoutRef = useRef();
5
6
  useEffect(() => {
@@ -173,6 +174,7 @@ function useControllableProp({
173
174
  }
174
175
  export {
175
176
  ConditionalWrapper,
177
+ forwardRefPolymorphic,
176
178
  getActiveElement,
177
179
  getNodeText,
178
180
  mergeRefs,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","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/getActiveElement.ts","../src/getNodeText.ts","../src/useControllableProp.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 { useId } from 'react';\n\n/**\n * @deprecated Use `useId()` from React directly instead.\n * Will be removed in a future major version.\n *\n * ```diff\n * - import { useRandomId } from '@entur/utils';\n * - const id = useRandomId('eds-my-component');\n * + import { useId } from 'react';\n * + const id = `eds-my-component${useId()}`;\n * ```\n */\nexport const useRandomId = (prefix?: string): string => {\n const id = useId();\n return prefix ? `${prefix}${id}` : id;\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;\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 { useSyncExternalStore } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('resize', callback);\n return () => window.removeEventListener('resize', callback);\n};\n\nlet cachedSnapshot: WindowDimensions = { width: undefined, height: undefined };\n\nconst getSnapshot = (): WindowDimensions => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n if (cachedSnapshot.width !== width || cachedSnapshot.height !== height) {\n cachedSnapshot = { width, height };\n }\n return cachedSnapshot;\n};\n\nconst serverSnapshot: WindowDimensions = {\n width: undefined,\n height: undefined,\n};\nconst getServerSnapshot = () => serverSnapshot;\n\nexport const useWindowDimensions = (): WindowDimensions => {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n","type 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 typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true') ||\n (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'production')\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","/**\n * Returns the active element, drilling into shadow roots.\n * `document.activeElement` stops at the shadow host — this\n * follows the chain into nested shadow roots.\n *\n * Use this instead of `document.activeElement` whenever the result is\n * compared to an element that may live inside a shadow root.\n *\n * Returns `null` when there is no DOM, so it is safe to call during\n * server rendering.\n */\nexport function getActiveElement(root?: Document | ShadowRoot): Element | null {\n const target =\n root ?? (typeof document === 'undefined' ? undefined : document);\n const active = target?.activeElement ?? null;\n if (active?.shadowRoot) {\n return getActiveElement(active.shadowRoot);\n }\n return active;\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 { useEffect, useState } from 'react';\nexport type UseControllablePropType<T> = {\n prop?: T;\n updater?: (value?: T) => void;\n defaultValue: T;\n};\nexport function useControllableProp<T>({\n prop,\n updater = () => undefined,\n defaultValue,\n}: UseControllablePropType<T>): [T, (arg: T) => void] {\n const [internalState, setInternalState] = useState<T>(defaultValue);\n useEffect(() => {\n if (prop !== undefined) {\n setInternalState(prop);\n }\n }, [prop]);\n return prop === undefined\n ? [internalState, setInternalState]\n : [prop, updater];\n}\n"],"names":[],"mappings":";;AAEO,SAAS,YACd,UACA,cACA;AACA,QAAM,aAAa,OAAA;AAEnB,YAAU,MAAM;AACd,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,qBAAa,WAAW,OAAO;AAAA,MACjC;AAAA,IACF;AAAA,EACF,GAAG,CAAA,CAAE;AAEL,QAAM,gBAAgB,IAAI,SAAgB;AACxC,QAAI,WAAW,SAAS;AACtB,mBAAa,WAAW,OAAO;AAAA,IACjC;AAEA,eAAW,UAAU,WAAW,MAAM;AACpC,eAAS,GAAG,IAAI;AAAA,IAClB,GAAG,YAAY;A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;AAAA,EACrC;AAAA,EACA,UAAU,MAAM;AAAA,EAChB;AACF,GAAsD;AACpD,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAY,YAAY;AAClE,YAAU,MAAM;AACd,QAAI,SAAS,QAAW;AACtB,uBAAiB,IAAI;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AACT,SAAO,SAAS,SACZ,CAAC,eAAe,gBAAgB,IAChC,CAAC,MAAM,OAAO;AACpB;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../src/PolymorphicComponent.tsx","../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/getActiveElement.ts","../src/getNodeText.ts","../src/useControllableProp.ts"],"sourcesContent":["/** These polymorphic types are derrived from Ben Ilegbodu's article available at the following link:\n * https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/\n */\n\nimport React from 'react';\n\n// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts\n// A more precise version of just React.ComponentPropsWithoutRef on its own\nexport type PropsOf<\n C extends\n | keyof React.JSX.IntrinsicElements\n | React.JSXElementConstructor<any>,\n> = React.JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;\n\ntype AsProp<C extends React.ElementType> = {\n /**\n * An override of the default HTML tag.\n * Can also be another React component.\n */\n as?: C;\n};\n\n/**\n * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props\n * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding\n * set of props.\n */\nexport type ExtendableProps<\n ExtendedProps = Record<string, unknown>,\n OverrideProps = Record<string, unknown>,\n> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;\n\n/**\n * Allows for inheriting the props from the specified element type so that\n * props like children, className & style work, as well as element-specific\n * attributes like aria roles. The component (`C`) must be passed in.\n */\nexport type InheritableElementProps<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = ExtendableProps<PropsOf<C>, Props>;\n\n/**\n * A more sophisticated version of `InheritableElementProps` where\n * the passed in `as` prop will determine which props can be included\n */\nexport type PolymorphicComponentProps<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = InheritableElementProps<C, Props & AsProp<C>>;\n\n/**\n * Utility type to extract the `ref` prop from a polymorphic component\n */\nexport type PolymorphicRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>['ref'];\n/**\n * A wrapper of `PolymorphicComponentProps` that also includes the `ref`\n * prop for the polymorphic component\n */\nexport type PolymorphicComponentPropsWithRef<\n C extends React.ElementType,\n Props = Record<string, unknown>,\n> = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> };\n\n/**\n * `React.forwardRef` for components with an `as` prop. Type the result with\n * the component's own polymorphic call signature, since `forwardRef` drops\n * the generic element type. Props and ref are untyped here, so keep the render\n * function in line with `Component`.\n */\nexport const forwardRefPolymorphic = <\n Component extends (props: any) => React.ReactElement | null,\n>(\n render: (props: any, ref: any) => React.ReactNode,\n): Component => React.forwardRef(render) as unknown as Component;\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 { useId } from 'react';\n\n/**\n * @deprecated Use `useId()` from React directly instead.\n * Will be removed in a future major version.\n *\n * ```diff\n * - import { useRandomId } from '@entur/utils';\n * - const id = useRandomId('eds-my-component');\n * + import { useId } from 'react';\n * + const id = `eds-my-component${useId()}`;\n * ```\n */\nexport const useRandomId = (prefix?: string): string => {\n const id = useId();\n return prefix ? `${prefix}${id}` : id;\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;\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 { useSyncExternalStore } from 'react';\n\ntype WindowDimensions = {\n width: number | undefined;\n height: number | undefined;\n};\n\nconst subscribe = (callback: () => void) => {\n window.addEventListener('resize', callback);\n return () => window.removeEventListener('resize', callback);\n};\n\nlet cachedSnapshot: WindowDimensions = { width: undefined, height: undefined };\n\nconst getSnapshot = (): WindowDimensions => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n if (cachedSnapshot.width !== width || cachedSnapshot.height !== height) {\n cachedSnapshot = { width, height };\n }\n return cachedSnapshot;\n};\n\nconst serverSnapshot: WindowDimensions = {\n width: undefined,\n height: undefined,\n};\nconst getServerSnapshot = () => serverSnapshot;\n\nexport const useWindowDimensions = (): WindowDimensions => {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n","type 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 typeof window === 'undefined' ||\n (typeof process !== 'undefined' && process?.env?.TEST === 'true') ||\n (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'production')\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","/**\n * Returns the active element, drilling into shadow roots.\n * `document.activeElement` stops at the shadow host — this\n * follows the chain into nested shadow roots.\n *\n * Use this instead of `document.activeElement` whenever the result is\n * compared to an element that may live inside a shadow root.\n *\n * Returns `null` when there is no DOM, so it is safe to call during\n * server rendering.\n */\nexport function getActiveElement(root?: Document | ShadowRoot): Element | null {\n const target =\n root ?? (typeof document === 'undefined' ? undefined : document);\n const active = target?.activeElement ?? null;\n if (active?.shadowRoot) {\n return getActiveElement(active.shadowRoot);\n }\n return active;\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 { useEffect, useState } from 'react';\nexport type UseControllablePropType<T> = {\n prop?: T;\n updater?: (value?: T) => void;\n defaultValue: T;\n};\nexport function useControllableProp<T>({\n prop,\n updater = () => undefined,\n defaultValue,\n}: UseControllablePropType<T>): [T, (arg: T) => void] {\n const [internalState, setInternalState] = useState<T>(defaultValue);\n useEffect(() => {\n if (prop !== undefined) {\n setInternalState(prop);\n }\n }, [prop]);\n return prop === undefined\n ? [internalState, setInternalState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,QAAQ,iBAAiB;AACxC,MAAI,QAAQ,YAAY;AACtB,WAAO,iBAAiB,OAAO,UAAU;AAAA,EAC3C;AACA,SAAO;AACT;AClBO,MAAM,cAAc,CACzB,SACW;AACX,MAAI,SAAS,QAAQ,SAAS,OAAW,QAAO;AAChD,MAAI,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAO,IAAI,EAAG,QAAO,KAAK,SAAA;AAC5D,MAAI,gBAAgB,MAAO,QAAO,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,EAAE,KAAA;AACjE,MAAI,OAAO,SAAS;AAElB,WAAO,YAAY,KAAK,OAAO,YAAY,EAAE,EAAE,KAAA;AACjD,SAAO;AACT;ACLO,SAAS,oBAAuB;AAAA,EACrC;AAAA,EACA,UAAU,MAAM;AAAA,EAChB;AACF,GAAsD;AACpD,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAY,YAAY;AAClE,YAAU,MAAM;AACd,QAAI,SAAS,QAAW;AACtB,uBAAiB,IAAI;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AACT,SAAO,SAAS,SACZ,CAAC,eAAe,gBAAgB,IAChC,CAAC,MAAM,OAAO;AACpB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entur/utils",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "license": "EUPL-1.2",
5
5
  "main": "dist/utils.cjs",
6
6
  "module": "dist/utils.mjs",
@@ -38,7 +38,8 @@
38
38
  "scripts": {
39
39
  "start": "vite build --watch",
40
40
  "build": "vite build && cp src/**/*.scss dist",
41
- "test": "jest"
41
+ "test": "jest",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit --rootDir ../.."
42
43
  },
43
44
  "peerDependencies": {
44
45
  "react": ">=18.0.0",
@@ -58,5 +59,5 @@
58
59
  "vite": "^7.3.2",
59
60
  "vite-plugin-dts": "^4.5.4"
60
61
  },
61
- "gitHead": "8caab317746945d60c1c6341ea8148a73a464db2"
62
+ "gitHead": "6bd3e1062ff4ee94e96ff26b8f961dd4e57c33e1"
62
63
  }