@entur/utils 0.3.0 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.4.3](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.2...@entur/utils@0.4.3) (2022-02-09)
7
+
8
+ **Note:** Version bump only for package @entur/utils
9
+
10
+ ## [0.4.2](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.1...@entur/utils@0.4.2) (2021-06-25)
11
+
12
+ ### Bug Fixes
13
+
14
+ - update dependencies ([80b9175](https://bitbucket.org/enturas/design-system/commits/80b9175b193d1154aa4ee6977c765e2c19b73415))
15
+
16
+ ## [0.4.1](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.0...@entur/utils@0.4.1) (2021-02-17)
17
+
18
+ ### Bug Fixes
19
+
20
+ - **dependency:** remove old polymorphism from dependencies ([c170645](https://bitbucket.org/enturas/design-system/commits/c1706459b36048952e9ca14cc51148054bf12bdc))
21
+ - **polymorphic:** add new polymorphism dependency ([7bf79cc](https://bitbucket.org/enturas/design-system/commits/7bf79cca1feccf7cfee11fc9f8ff1e5f1025a47f))
22
+ - **polymorphic:** remove old dependency as exports ([eb5f431](https://bitbucket.org/enturas/design-system/commits/eb5f43171cdc8099f9479bd6a7210c0a5fa2daa4))
23
+
24
+ # [0.4.0](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.3.0...@entur/utils@0.4.0) (2020-12-04)
25
+
26
+ ### Features
27
+
28
+ - add polymorphic component dependecy as export ([5384642](https://bitbucket.org/enturas/design-system/commits/53846421f66f4b6193238d0d6cced8b09658d3b6))
29
+
6
30
  # [0.3.0](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.9...@entur/utils@0.3.0) (2020-10-09)
7
31
 
8
32
  ### Features
@@ -0,0 +1,2 @@
1
+ import type { PolymorphicPropsWithoutRef, PolymorphicPropsWithRef, PolymorphicForwardRefExoticComponent } from 'react-polymorphic-types';
2
+ export { PolymorphicPropsWithoutRef, PolymorphicPropsWithRef, PolymorphicForwardRefExoticComponent, };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './debounce';
2
+ export * from './PolymorphicComponent';
2
3
  export * from './useRandomId';
3
4
  export * from './useOnMount';
4
5
  export * from './warnAboutMissingStyles';
@@ -2,10 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
5
+ var React = require('react');
6
+ var warning = require('tiny-warning');
6
7
 
7
- var React = _interopDefault(require('react'));
8
- var warning = _interopDefault(require('tiny-warning'));
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);
9
12
 
10
13
  function debounce(fn, delay) {
11
14
  var id;
@@ -22,13 +25,13 @@ function debounce(fn, delay) {
22
25
  }
23
26
 
24
27
  var useRandomId = function useRandomId(prefix) {
25
- var ref = React.useRef(String(Math.random()).substring(2));
28
+ var ref = React__default["default"].useRef(String(Math.random()).substring(2));
26
29
  return prefix + "-" + ref.current;
27
30
  };
28
31
 
29
32
  function useOnMount(callback) {
30
- var hasRun = React.useRef(false);
31
- React.useEffect(function () {
33
+ var hasRun = React__default["default"].useRef(false);
34
+ React__default["default"].useEffect(function () {
32
35
  if (!hasRun.current) {
33
36
  hasRun.current = true;
34
37
  callback();
@@ -45,7 +48,7 @@ function checkAndWarn() {
45
48
  }).sort(); // Finally, we warn about those pesky imports
46
49
 
47
50
  var singleMissingImport = missingImports.length === 1;
48
- 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) {
51
+ 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) {
49
52
  return "\t@import '~@entur/" + namespace + "/dist/styles.css';";
50
53
  }).join('\n') + "\n") ;
51
54
  }
@@ -54,7 +57,7 @@ function checkAndWarn() {
54
57
 
55
58
  function warnAboutMissingStyles() {
56
59
  // We skip this check in production, and when we build static sites
57
- if ( typeof window === 'undefined') {
60
+ if (typeof window === 'undefined') {
58
61
  return;
59
62
  } // First, let's clear earlier calls to setTimeout
60
63
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: 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","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[]) {\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","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","window","getComputedStyle","document","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;;;;;;;SAAgBA,SAASC,IAAcC;AACrC,MAAIC,EAAJ;AACA,SAAO;sCAAIC;AAAAA,MAAAA;;;AACTC,IAAAA,YAAY,CAACF,EAAD,CAAZ;AACAA,IAAAA,EAAE,GAAGG,UAAU,CAAC;AAAA,aAAML,EAAE,MAAF,SAAMG,IAAN,CAAN;AAAA,KAAD,EAAoBF,KAApB,CAAf;AACD,GAHD;AAID;;ICJYK,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD;AACzB,MAAMC,GAAG,GAAGC,KAAK,CAACC,MAAN,CAAaC,MAAM,CAACC,IAAI,CAACC,MAAL,EAAD,CAAN,CAAsBC,SAAtB,CAAgC,CAAhC,CAAb,CAAZ;AACA,SAAUP,MAAV,SAAoBC,GAA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CAAoBhB,SAApB,CAAJ;AAAA,GAA5B;;AAGAN,EAAAA,cAAc,GAAGQ,MAAM,CAACzB,UAAP,CAAkBkB,YAAlB,EAAgC,IAAhC,CAAjB;AACD;;;;;;;"}
1
+ {"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: 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","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[]) {\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","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","window","getComputedStyle","document","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;;;;;;;;;;SAAgBA,SAASC,IAAcC;AACrC,MAAIC,EAAJ;AACA,SAAO;sCAAIC;AAAAA,MAAAA;;;AACTC,IAAAA,YAAY,CAACF,EAAD,CAAZ;AACAA,IAAAA,EAAE,GAAGG,UAAU,CAAC;AAAA,aAAML,EAAE,MAAF,SAAMG,IAAN,CAAN;AAAA,KAAD,EAAoBF,KAApB,CAAf;AACD,GAHD;AAID;;ICJYK,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD;AACzB,MAAMC,GAAG,GAAGC,yBAAK,CAACC,MAAN,CAAaC,MAAM,CAACC,IAAI,CAACC,MAAL,EAAD,CAAN,CAAsBC,SAAtB,CAAgC,CAAhC,CAAb,CAAZ;AACA,SAAUP,MAAV,SAAoBC,GAAG,CAACO,OAAxB;AACD;;SCHeC,WAAWC;AACzB,MAAMC,MAAM,GAAGT,yBAAK,CAACC,MAAN,CAAsB,KAAtB,CAAf;AAEAD,EAAAA,yBAAK,CAACU,SAAN,CAAgB;AACd,QAAI,CAACD,MAAM,CAACH,OAAZ,EAAqB;AACnBG,MAAAA,MAAM,CAACH,OAAP,GAAiB,IAAjB;AACAE,MAAAA,QAAQ;AACT;AACF,GALD,EAKG,CAACA,QAAD,CALH;AAMD;;ACTD,IAAMG,eAAe,gBAAgB,IAAIC,GAAJ,EAArC;AACA,IAAIC,cAAJ;;AAEA,SAASC,YAAT;AACE,MAAMC,cAAc,GAAGC,KAAK,CAACC,IAAN,CAAWN,eAAX,EACpBO,MADoB,CAEnB,UAAAC,SAAS;AAAA,WACPC,QAAQ,CACNC,MAAM,CACHC,gBADH,CACoBC,QAAQ,CAACC,eAD7B,EAEGC,gBAFH,YAE6BN,SAF7B,CADM,CAAR,KAIM,CALC;AAAA,GAFU,EASpBO,IAToB,EAAvB;;AAYA,MAAMC,mBAAmB,GAAGZ,cAAc,CAACa,MAAf,KAA0B,CAAtD;AACA,EAAAC,2BAAO,CACLd,cAAc,CAACa,MAAf,KAA0B,CADrB,wBAGHD,mBAAmB,GACf,cADe,GAEZZ,cAAc,CAACa,MAFH,iBAHhB,kDASHD,mBAAmB,GAAG,EAAH,GAAQ,GATxB,oCAYPZ,cAAc,CACbe,GADD,CACK,UAAAX,SAAS;AAAA,mCAA0BA,SAA1B;AAAA,GADd,EAECY,IAFD,CAEM,IAFN,CAZO,QAAP;AAiBD;AAED;;;SACgBC;AACd;AACA,MAAgB,OAAOX,MAAP,KAAkB,WAAlC,EAA+C;AAC7C;AACD;;;AAEDA,EAAAA,MAAM,CAAC1B,YAAP,CAAoBkB,cAApB;;oCANwCoB;AAAAA,IAAAA;;;AASxCA,EAAAA,UAAU,CAACC,OAAX,CAAmB,UAAAf,SAAS;AAAA,WAAIR,eAAe,CAACwB,GAAhB,CAAoBhB,SAApB,CAAJ;AAAA,GAA5B;;AAGAN,EAAAA,cAAc,GAAGQ,MAAM,CAACzB,UAAP,CAAkBkB,YAAlB,EAAgC,IAAhC,CAAjB;AACD;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e;require("tiny-warning"),exports.debounce=function(e,t){var r;return function(){for(var n=arguments.length,u=new Array(n),o=0;o<n;o++)u[o]=arguments[o];clearTimeout(r),r=setTimeout((function(){return e.apply(void 0,u)}),t)}},exports.useOnMount=function(e){var r=t.useRef(!1);t.useEffect((function(){r.current||(r.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+t.useRef(String(Math.random()).substring(2)).current},exports.warnAboutMissingStyles=function(){};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("tiny-warning");var r=t(e);exports.debounce=function(e,t){var r;return function(){for(var n=arguments.length,u=new Array(n),o=0;o<n;o++)u[o]=arguments[o];clearTimeout(r),r=setTimeout((function(){return e.apply(void 0,u)}),t)}},exports.useOnMount=function(e){var t=r.default.useRef(!1);r.default.useEffect((function(){t.current||(t.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+r.default.useRef(String(Math.random()).substring(2)).current},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/debounce.ts","../src/useOnMount.ts","../src/useRandomId.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\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) => {\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[]) {\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":["fn","delay","id","args","clearTimeout","setTimeout","callback","hasRun","React","useRef","useEffect","current","prefix","String","Math","random","substring"],"mappings":"kMAAyBA,EAAcC,OACjCC,SACG,sCAAIC,2BAAAA,kBACTC,aAAaF,GACbA,EAAKG,YAAW,kBAAML,eAAMG,KAAOF,iCCFZK,OACnBC,EAASC,EAAMC,QAAgB,GAErCD,EAAME,WAAU,WACTH,EAAOI,UACVJ,EAAOI,SAAU,EACjBL,OAED,CAACA,yBCRqB,SAACM,UAEhBA,MADEJ,EAAMC,OAAOI,OAAOC,KAAKC,UAAUC,UAAU,IACjCL,wCCmC1B"}
1
+ {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/debounce.ts","../src/useOnMount.ts","../src/useRandomId.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\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) => {\n const ref = React.useRef(String(Math.random()).substring(2));\n return `${prefix}-${ref.current}`;\n};\n"],"names":["fn","delay","id","args","clearTimeout","setTimeout","callback","hasRun","React","useRef","useEffect","current","prefix","String","Math","random","substring"],"mappings":"gOAAyBA,EAAcC,OACjCC,SACG,sCAAIC,2BAAAA,kBACTC,aAAaF,GACbA,EAAKG,YAAW,kBAAML,eAAMG,KAAOF,iCCFZK,OACnBC,EAASC,UAAMC,QAAgB,GAErCD,UAAME,WAAU,WACTH,EAAOI,UACVJ,EAAOI,SAAU,EACjBL,OAED,CAACA,yBCRqB,SAACM,UAEhBA,MADEJ,UAAMC,OAAOI,OAAOC,KAAKC,UAAUC,UAAU,IACjCL"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: 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","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[]) {\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","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","window","getComputedStyle","document","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;SAAgBA,SAASC,IAAcC;AACrC,MAAIC,EAAJ;AACA,SAAO;sCAAIC;AAAAA,MAAAA;;;AACTC,IAAAA,YAAY,CAACF,EAAD,CAAZ;AACAA,IAAAA,EAAE,GAAGG,UAAU,CAAC;AAAA,aAAML,EAAE,MAAF,SAAMG,IAAN,CAAN;AAAA,KAAD,EAAoBF,KAApB,CAAf;AACD,GAHD;AAID;;ICJYK,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD;AACzB,MAAMC,GAAG,GAAGC,KAAK,CAACC,MAAN,CAAaC,MAAM,CAACC,IAAI,CAACC,MAAL,EAAD,CAAN,CAAsBC,SAAtB,CAAgC,CAAhC,CAAb,CAAZ;AACA,SAAUP,MAAV,SAAoBC,GAAG,CAACO,OAAxB;AACD,CAHM;;SCASC,WAAWC;AACzB,MAAMC,MAAM,GAAGT,KAAK,CAACC,MAAN,CAAsB,KAAtB,CAAf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EAAgC,IAAhC,CAAjB;AACD;;;;"}
1
+ {"version":3,"file":"utils.esm.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["export function debounce(fn: Function, delay: number) {\n let id: any;\n return (...args: any) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), delay);\n };\n}\n","import React from 'react';\n\nexport const useRandomId = (prefix?: 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","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[]) {\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","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","window","getComputedStyle","document","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;SAAgBA,SAASC,IAAcC;AACrC,MAAIC,EAAJ;AACA,SAAO;sCAAIC;AAAAA,MAAAA;;;AACTC,IAAAA,YAAY,CAACF,EAAD,CAAZ;AACAA,IAAAA,EAAE,GAAGG,UAAU,CAAC;AAAA,aAAML,EAAE,MAAF,SAAMG,IAAN,CAAN;AAAA,KAAD,EAAoBF,KAApB,CAAf;AACD,GAHD;AAID;;ICJYK,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD;AACzB,MAAMC,GAAG,GAAGC,KAAK,CAACC,MAAN,CAAaC,MAAM,CAACC,IAAI,CAACC,MAAL,EAAD,CAAN,CAAsBC,SAAtB,CAAgC,CAAhC,CAAb,CAAZ;AACA,SAAUP,MAAV,SAAoBC,GAAG,CAACO,OAAxB;AACD;;SCHeC,WAAWC;AACzB,MAAMC,MAAM,GAAGT,KAAK,CAACC,MAAN,CAAsB,KAAtB,CAAf;AAEAD,EAAAA,KAAK,CAACU,SAAN,CAAgB;AACd,QAAI,CAACD,MAAM,CAACH,OAAZ,EAAqB;AACnBG,MAAAA,MAAM,CAACH,OAAP,GAAiB,IAAjB;AACAE,MAAAA,QAAQ;AACT;AACF,GALD,EAKG,CAACA,QAAD,CALH;AAMD;;ACTD,IAAMG,eAAe,gBAAgB,IAAIC,GAAJ,EAArC;AACA,IAAIC,cAAJ;;AAEA,SAASC,YAAT;AACE,MAAMC,cAAc,GAAGC,KAAK,CAACC,IAAN,CAAWN,eAAX,EACpBO,MADoB,CAEnB,UAAAC,SAAS;AAAA,WACPC,QAAQ,CACNC,MAAM,CACHC,gBADH,CACoBC,QAAQ,CAACC,eAD7B,EAEGC,gBAFH,YAE6BN,SAF7B,CADM,CAAR,KAIM,CALC;AAAA,GAFU,EASpBO,IAToB,EAAvB;;AAYA,MAAMC,mBAAmB,GAAGZ,cAAc,CAACa,MAAf,KAA0B,CAAtD;AACA,0CAAAC,OAAO,CACLd,cAAc,CAACa,MAAf,KAA0B,CADrB,wBAGHD,mBAAmB,GACf,cADe,GAEZZ,cAAc,CAACa,MAFH,iBAHhB,kDASHD,mBAAmB,GAAG,EAAH,GAAQ,GATxB,oCAYPZ,cAAc,CACbe,GADD,CACK,UAAAX,SAAS;AAAA,mCAA0BA,SAA1B;AAAA,GADd,EAECY,IAFD,CAEM,IAFN,CAZO,QAAP;AAiBD;AAED;;;SACgBC;AACd;AACA,MAAI,4CAAY,OAAOX,MAAP,KAAkB,WAAlC,EAA+C;AAC7C;AACD;;;AAEDA,EAAAA,MAAM,CAAC1B,YAAP,CAAoBkB,cAApB;;oCANwCoB;AAAAA,IAAAA;;;AASxCA,EAAAA,UAAU,CAACC,OAAX,CAAmB,UAAAf,SAAS;AAAA,WAAIR,eAAe,CAACwB,GAAhB,CAAoBhB,SAApB,CAAJ;AAAA,GAA5B;;AAGAN,EAAAA,cAAc,GAAGQ,MAAM,CAACzB,UAAP,CAAkBkB,YAAlB,EAAgC,IAAhC,CAAjB;AACD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entur/utils",
3
- "version": "0.3.0",
3
+ "version": "0.4.3",
4
4
  "license": "EUPL-1.2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/utils.esm.js",
@@ -17,17 +17,18 @@
17
17
  "access": "public"
18
18
  },
19
19
  "scripts": {
20
- "start": "tsdx watch --noClean",
21
- "build": "tsdx build && cp src/*.scss dist",
22
- "test": "tsdx test --env=jsdom",
23
- "lint": "tsdx lint"
20
+ "start": "dts watch --noClean",
21
+ "build": "dts build && cp src/*.scss dist",
22
+ "test": "dts test --env=jsdom",
23
+ "lint": "dts lint"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": ">=16.8.0",
27
27
  "react-dom": ">=16.8.0"
28
28
  },
29
29
  "dependencies": {
30
+ "react-polymorphic-types": "^1.1.0",
30
31
  "tiny-warning": "^1.0.3"
31
32
  },
32
- "gitHead": "eac1b4d7beec09ac6b5eb132e25dc999b68abe08"
33
+ "gitHead": "61e643371cfc5653c93160b7c220152e5b2bafeb"
33
34
  }