@entur/utils 0.4.6-beta.2 → 0.4.7

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 +1 @@
1
- export declare const useRandomId: (prefix?: string | undefined) => string;
1
+ export declare const useRandomId: (prefix?: string) => string;
@@ -16,7 +16,6 @@ function debounce(fn, delay) {
16
16
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17
17
  args[_key] = arguments[_key];
18
18
  }
19
-
20
19
  clearTimeout(id);
21
20
  id = setTimeout(function () {
22
21
  return fn.apply(void 0, args);
@@ -47,19 +46,14 @@ function _unsupportedIterableToArray(o, minLen) {
47
46
  if (n === "Map" || n === "Set") return Array.from(o);
48
47
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
49
48
  }
50
-
51
49
  function _arrayLikeToArray(arr, len) {
52
50
  if (len == null || len > arr.length) len = arr.length;
53
-
54
51
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
55
-
56
52
  return arr2;
57
53
  }
58
-
59
54
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
60
55
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
61
56
  if (it) return (it = it.call(o)).next.bind(it);
62
-
63
57
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
64
58
  if (it) o = it;
65
59
  var i = 0;
@@ -73,7 +67,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
73
67
  };
74
68
  };
75
69
  }
76
-
77
70
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
71
  }
79
72
 
@@ -81,11 +74,9 @@ var mergeRefs = function mergeRefs() {
81
74
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
82
75
  refs[_key] = arguments[_key];
83
76
  }
84
-
85
77
  return function (node) {
86
78
  for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
87
79
  var ref = _step.value;
88
-
89
80
  if (typeof ref === 'function') {
90
81
  ref(node);
91
82
  } else if (ref) ref.current = node;
@@ -95,37 +86,32 @@ var mergeRefs = function mergeRefs() {
95
86
 
96
87
  var packagesToCheck = /*#__PURE__*/new Set();
97
88
  var checkTimeoutId;
98
-
99
89
  function checkAndWarn() {
100
90
  var missingImports = Array.from(packagesToCheck).filter(function (namespace) {
101
91
  return parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--eds-" + namespace)) !== 1;
102
- }).sort(); // Finally, we warn about those pesky imports
103
-
92
+ }).sort();
93
+ // Finally, we warn about those pesky imports
104
94
  var singleMissingImport = missingImports.length === 1;
105
95
  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) {
106
- return "\t@import '~@entur/" + namespace + "/dist/styles.css';";
96
+ return "\t@import '@entur/" + namespace + "/dist/styles.css';";
107
97
  }).join('\n') + "\n") ;
108
98
  }
109
99
  /** Warns the developer if they have forgotten to include styles */
110
-
111
-
112
100
  function warnAboutMissingStyles() {
113
101
  // We skip this check in production, and when we build static sites
114
102
  if (typeof window === 'undefined') {
115
103
  return;
116
- } // First, let's clear earlier calls to setTimeout
117
-
118
-
119
- window.clearTimeout(checkTimeoutId); // Next, let's add all namespaces to the set of packages to check
120
-
104
+ }
105
+ // First, let's clear earlier calls to setTimeout
106
+ window.clearTimeout(checkTimeoutId);
107
+ // Next, let's add all namespaces to the set of packages to check
121
108
  for (var _len = arguments.length, namespaces = new Array(_len), _key = 0; _key < _len; _key++) {
122
109
  namespaces[_key] = arguments[_key];
123
110
  }
124
-
125
111
  namespaces.forEach(function (namespace) {
126
112
  return packagesToCheck.add(namespace);
127
- }); // Finally. let's trigger a run of the checker.
128
-
113
+ });
114
+ // Finally. let's trigger a run of the checker.
129
115
  checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
130
116
  }
131
117
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../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>[]\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 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","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,SACdC,IACAC;AAEA,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;;ICPYK,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,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C,EAA+C;AAC7C;AACD;;;AAEDA,EAAAA,MAAM,CAAC7B,YAAP,CAAoBqB,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,CAAC5B,UAAP,CAAkBqB,YAAlB,EAAgC,IAAhC,CAAjB;AACD;;;;;;;;"}
1
+ {"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../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>[]\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 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","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,QAAQ,CACtBC,EAAK,EACLC,KAAa;EAEb,IAAIC,EAAO;EACX,OAAO;sCAAIC,IAAI;MAAJA,IAAI;;IACbC,YAAY,CAACF,EAAE,CAAC;IAChBA,EAAE,GAAGG,UAAU,CAAC;MAAA,OAAML,EAAE,eAAIG,IAAI,CAAC;OAAEF,KAAK,CAAC;GAC1C;AACH;;ICPaK,WAAW,GAAG,SAAdA,WAAW,CAAIC,MAAe;EACzC,IAAMC,GAAG,GAAGC,yBAAK,CAACC,MAAM,CAACC,MAAM,CAACC,IAAI,CAACC,MAAM,EAAE,CAAC,CAACC,SAAS,CAAC,CAAC,CAAC,CAAC;EAC5D,OAAUP,MAAM,SAAIC,G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yBA,SAAS;GAAoB,CAAC,CACpEY,IAAI,CAAC,IAAI,CAAC,QAEV;AACH;AAEA;SACgBC,sBAAsB;;EAEpC,IAAgB,OAAOX,MAAM,KAAK,WAAW,EAAE;IAC7C;;;EAGFA,MAAM,CAAC7B,YAAY,CAACqB,cAAc,CAAC;;EAEnC,kCARwCoB,UAAoB;IAApBA,UAAoB;;EAS5DA,UAAU,CAACC,OAAO,CAAC,UAAAf,SAAS;IAAA,OAAIR,eAAe,CAACwB,GAAG,CAAChB,SAAS,CAAC;IAAC;;EAG/DN,cAAc,GAAGQ,MAAM,CAAC5B,UAAU,CAACqB,YAAY,EAAE,IAAI,CAAC;AACxD;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/debounce.ts","../src/mergeRefs.ts","../src/useOnMount.ts","../src/useRandomId.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","export const mergeRefs = <T extends HTMLElement>(\n ...refs: React.MutableRefObject<T>[] | React.ForwardedRef<T>[]\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 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"],"names":["fn","delay","id","args","clearTimeout","setTimeout","refs","node","ref","current","callback","hasRun","React","useRef","useEffect","prefix","String","Math","random","substring"],"mappings":"shCACEA,EACAC,OAEIC,SACG,sCAAIC,2BAAAA,kBACTC,aAAaF,GACbA,EAAKG,YAAW,kBAAML,eAAMG,KAAOF,uBCPd,sCACpBK,2BAAAA,yBAEI,SAACC,iBACYD,kBAAM,KAAbE,UACU,mBAARA,EACTA,EAAID,GACKC,IAAKA,EAAIC,QAAUF,kCCLTG,OACnBC,EAASC,UAAMC,QAAgB,GAErCD,UAAME,WAAU,WACTH,EAAOF,UACVE,EAAOF,SAAU,EACjBC,OAED,CAACA,yBCRqB,SAACK,UAEhBA,MADEH,UAAMC,OAAOG,OAAOC,KAAKC,UAAUC,UAAU,IACjCV"}
1
+ {"version":3,"file":"utils.cjs.production.min.js","sources":["../src/debounce.ts","../src/mergeRefs.ts","../src/useOnMount.ts","../src/useRandomId.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","export const mergeRefs = <T extends HTMLElement>(\n ...refs: React.MutableRefObject<T>[] | React.ForwardedRef<T>[]\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 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"],"names":["fn","delay","id","args","clearTimeout","setTimeout","refs","node","ref","current","callback","hasRun","React","useRef","useEffect","prefix","String","Math","random","substring"],"mappings":"shCACEA,EACAC,GAEA,IAAIC,EACJ,OAAO,sCAAIC,2BAAAA,kBACTC,aAAaF,GACbA,EAAKG,YAAW,WAAA,OAAML,eAAMG,KAAOF,uBCPd,sCACpBK,2BAAAA,kBAEH,OAAO,SAACC,GACN,cAAkBD,kBAAM,CAAA,IAAbE,UACU,mBAARA,EACTA,EAAID,GACKC,IAAKA,EAAIC,QAAUF,kCCLTG,GACzB,IAAMC,EAASC,UAAMC,QAAgB,GAErCD,UAAME,WAAU,WACTH,EAAOF,UACVE,EAAOF,SAAU,EACjBC,OAED,CAACA,yBCRqB,SAACK,GAE1B,OAAUA,MADEH,UAAMC,OAAOG,OAAOC,KAAKC,UAAUC,UAAU,IACjCV"}
package/dist/utils.esm.js CHANGED
@@ -7,7 +7,6 @@ function debounce(fn, delay) {
7
7
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
8
8
  args[_key] = arguments[_key];
9
9
  }
10
-
11
10
  clearTimeout(id);
12
11
  id = setTimeout(function () {
13
12
  return fn.apply(void 0, args);
@@ -38,19 +37,14 @@ function _unsupportedIterableToArray(o, minLen) {
38
37
  if (n === "Map" || n === "Set") return Array.from(o);
39
38
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
40
39
  }
41
-
42
40
  function _arrayLikeToArray(arr, len) {
43
41
  if (len == null || len > arr.length) len = arr.length;
44
-
45
42
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
46
-
47
43
  return arr2;
48
44
  }
49
-
50
45
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
51
46
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
52
47
  if (it) return (it = it.call(o)).next.bind(it);
53
-
54
48
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
55
49
  if (it) o = it;
56
50
  var i = 0;
@@ -64,7 +58,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
64
58
  };
65
59
  };
66
60
  }
67
-
68
61
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
69
62
  }
70
63
 
@@ -72,11 +65,9 @@ var mergeRefs = function mergeRefs() {
72
65
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
73
66
  refs[_key] = arguments[_key];
74
67
  }
75
-
76
68
  return function (node) {
77
69
  for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
78
70
  var ref = _step.value;
79
-
80
71
  if (typeof ref === 'function') {
81
72
  ref(node);
82
73
  } else if (ref) ref.current = node;
@@ -86,37 +77,32 @@ var mergeRefs = function mergeRefs() {
86
77
 
87
78
  var packagesToCheck = /*#__PURE__*/new Set();
88
79
  var checkTimeoutId;
89
-
90
80
  function checkAndWarn() {
91
81
  var missingImports = Array.from(packagesToCheck).filter(function (namespace) {
92
82
  return parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--eds-" + namespace)) !== 1;
93
- }).sort(); // Finally, we warn about those pesky imports
94
-
83
+ }).sort();
84
+ // Finally, we warn about those pesky imports
95
85
  var singleMissingImport = missingImports.length === 1;
96
86
  process.env.NODE_ENV !== "production" ? 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) {
97
- return "\t@import '~@entur/" + namespace + "/dist/styles.css';";
87
+ return "\t@import '@entur/" + namespace + "/dist/styles.css';";
98
88
  }).join('\n') + "\n") : void 0;
99
89
  }
100
90
  /** Warns the developer if they have forgotten to include styles */
101
-
102
-
103
91
  function warnAboutMissingStyles() {
104
92
  // We skip this check in production, and when we build static sites
105
93
  if (!(process.env.NODE_ENV !== "production") || typeof window === 'undefined') {
106
94
  return;
107
- } // First, let's clear earlier calls to setTimeout
108
-
109
-
110
- window.clearTimeout(checkTimeoutId); // Next, let's add all namespaces to the set of packages to check
111
-
95
+ }
96
+ // First, let's clear earlier calls to setTimeout
97
+ window.clearTimeout(checkTimeoutId);
98
+ // Next, let's add all namespaces to the set of packages to check
112
99
  for (var _len = arguments.length, namespaces = new Array(_len), _key = 0; _key < _len; _key++) {
113
100
  namespaces[_key] = arguments[_key];
114
101
  }
115
-
116
102
  namespaces.forEach(function (namespace) {
117
103
  return packagesToCheck.add(namespace);
118
- }); // Finally. let's trigger a run of the checker.
119
-
104
+ });
105
+ // Finally. let's trigger a run of the checker.
120
106
  checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
121
107
  }
122
108
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../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>[]\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 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","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,SACdC,IACAC;AAEA,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;;ICPYK,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;AAC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B;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,CAAC7B,YAAP,CAAoBqB,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,CAAC5B,UAAP,CAAkBqB,YAAlB,EAAgC,IAAhC,CAAjB;AACD;;;;"}
1
+ {"version":3,"file":"utils.esm.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../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>[]\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 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","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,QAAQ,CACtBC,EAAK,EACLC,KAAa;EAEb,IAAIC,EAAO;EACX,OAAO;sCAAIC,IAAI;MAAJA,IAAI;;IACbC,YAAY,CAACF,EAAE,CAAC;IAChBA,EAAE,GAAGG,UAAU,CAAC;MAAA,OAAML,EAAE,eAAIG,IAAI,CAAC;OAAEF,KAAK,CAAC;GAC1C;AACH;;ICPaK,WAAW,GAAG,SAAdA,WAAW,CAAIC,MAAe;EACzC,IAAMC,GAAG,GAAGC,KAAK,CAACC,MAAM,CAACC,MAAM,CA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9B,kDAGED,mBAAmB,GAAG,EAAE,GAAG,GAC7B,oCAEFZ,cAAc,CACbe,GAAG,CAAC,UAAAX,SAAS;IAAA,8BAAyBA,SAAS;GAAoB,CAAC,CACpEY,IAAI,CAAC,IAAI,CAAC,QAEV;AACH;AAEA;SACgBC,sBAAsB;;EAEpC,IAAI,wCAAQ,IAAI,OAAOX,MAAM,KAAK,WAAW,EAAE;IAC7C;;;EAGFA,MAAM,CAAC7B,YAAY,CAACqB,cAAc,CAAC;;EAEnC,kCARwCoB,UAAoB;IAApBA,UAAoB;;EAS5DA,UAAU,CAACC,OAAO,CAAC,UAAAf,SAAS;IAAA,OAAIR,eAAe,CAACwB,GAAG,CAAChB,SAAS,CAAC;IAAC;;EAG/DN,cAAc,GAAGQ,MAAM,CAAC5B,UAAU,CAACqB,YAAY,EAAE,IAAI,CAAC;AACxD;;;;"}
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
- "//": "Add a change to utils",
3
2
  "name": "@entur/utils",
4
- "version": "0.4.6-beta.2",
3
+ "version": "0.4.7",
5
4
  "license": "EUPL-1.2",
6
5
  "main": "dist/index.js",
7
6
  "module": "dist/utils.esm.js",
@@ -33,5 +32,5 @@
33
32
  "devDependencies": {
34
33
  "dts-cli": "^1.1.6"
35
34
  },
36
- "gitHead": "89c8eee86c247794134c34484a205e0f7f65d0a5"
35
+ "gitHead": "8915b1630bd936740ba9a4a88883f3432948a80e"
37
36
  }