@entur/utils 0.4.4 → 0.4.5
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 +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/mergeRefs.d.ts +2 -0
- package/dist/utils.cjs.development.js +55 -0
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +55 -1
- package/dist/utils.esm.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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.5](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.4...@entur/utils@0.4.5) (2022-08-31)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @entur/utils
|
|
9
|
+
|
|
6
10
|
## [0.4.4](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.3...@entur/utils@0.4.4) (2022-08-24)
|
|
7
11
|
|
|
8
12
|
### Bug Fixes
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,60 @@ function useOnMount(callback) {
|
|
|
39
39
|
}, [callback]);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
43
|
+
if (!o) return;
|
|
44
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
45
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
46
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
47
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
48
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function _arrayLikeToArray(arr, len) {
|
|
52
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
53
|
+
|
|
54
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
55
|
+
|
|
56
|
+
return arr2;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
60
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
61
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
64
|
+
if (it) o = it;
|
|
65
|
+
var i = 0;
|
|
66
|
+
return function () {
|
|
67
|
+
if (i >= o.length) return {
|
|
68
|
+
done: true
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
done: false,
|
|
72
|
+
value: o[i++]
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
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
|
+
}
|
|
79
|
+
|
|
80
|
+
var mergeRefs = function mergeRefs() {
|
|
81
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
82
|
+
refs[_key] = arguments[_key];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return function (node) {
|
|
86
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
87
|
+
var ref = _step.value;
|
|
88
|
+
|
|
89
|
+
if (typeof ref === 'function') {
|
|
90
|
+
ref(node);
|
|
91
|
+
} else if (ref) ref.current = node;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
42
96
|
var packagesToCheck = /*#__PURE__*/new Set();
|
|
43
97
|
var checkTimeoutId;
|
|
44
98
|
|
|
@@ -76,6 +130,7 @@ function warnAboutMissingStyles() {
|
|
|
76
130
|
}
|
|
77
131
|
|
|
78
132
|
exports.debounce = debounce;
|
|
133
|
+
exports.mergeRefs = mergeRefs;
|
|
79
134
|
exports.useOnMount = useOnMount;
|
|
80
135
|
exports.useRandomId = useRandomId;
|
|
81
136
|
exports.warnAboutMissingStyles = warnAboutMissingStyles;
|
|
@@ -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<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","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","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,CAACD,MAAM,CAACH,OAAZ,EAAqB;AACnBG,MAAAA,MAAM,CAACH,OAAP,GAAiB,IAAjB;AACAE,MAAAA,QAAQ;AACT;AACF,GALD,EAKG,CAACA,QAAD,CALH;AAMD;;
|
|
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,CAACD,MAAM,CAACH,OAAZ,EAAqB;AACnB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,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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("tiny-warning");var t=r(e);function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}exports.debounce=function(e,r){var t;return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,o)}),r)}},exports.mergeRefs=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];return function(e){for(var t,n=o(r);!(t=n()).done;){var u=t.value;"function"==typeof u?u(e):u&&(u.current=e)}}},exports.useOnMount=function(e){var r=t.default.useRef(!1);t.default.useEffect((function(){r.current||(r.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+t.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"],"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 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","callback","hasRun","React","useRef","useEffect","
|
|
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"}
|
package/dist/utils.esm.js
CHANGED
|
@@ -30,6 +30,60 @@ function useOnMount(callback) {
|
|
|
30
30
|
}, [callback]);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
34
|
+
if (!o) return;
|
|
35
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
36
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
37
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
38
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
39
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _arrayLikeToArray(arr, len) {
|
|
43
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
44
|
+
|
|
45
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
46
|
+
|
|
47
|
+
return arr2;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
51
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
52
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
55
|
+
if (it) o = it;
|
|
56
|
+
var i = 0;
|
|
57
|
+
return function () {
|
|
58
|
+
if (i >= o.length) return {
|
|
59
|
+
done: true
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
done: false,
|
|
63
|
+
value: o[i++]
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
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
|
+
}
|
|
70
|
+
|
|
71
|
+
var mergeRefs = function mergeRefs() {
|
|
72
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
73
|
+
refs[_key] = arguments[_key];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return function (node) {
|
|
77
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
78
|
+
var ref = _step.value;
|
|
79
|
+
|
|
80
|
+
if (typeof ref === 'function') {
|
|
81
|
+
ref(node);
|
|
82
|
+
} else if (ref) ref.current = node;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
33
87
|
var packagesToCheck = /*#__PURE__*/new Set();
|
|
34
88
|
var checkTimeoutId;
|
|
35
89
|
|
|
@@ -66,5 +120,5 @@ function warnAboutMissingStyles() {
|
|
|
66
120
|
checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
|
|
67
121
|
}
|
|
68
122
|
|
|
69
|
-
export { debounce, useOnMount, useRandomId, warnAboutMissingStyles };
|
|
123
|
+
export { debounce, mergeRefs, useOnMount, useRandomId, warnAboutMissingStyles };
|
|
70
124
|
//# sourceMappingURL=utils.esm.js.map
|
package/dist/utils.esm.js.map
CHANGED
|
@@ -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<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","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","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;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;;
|
|
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;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,QAA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AACC,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/utils.esm.js",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"react-polymorphic-types": "^1.1.0",
|
|
31
31
|
"tiny-warning": "^1.0.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "8aec781ef750306fdf0c4042edabfad5b33cbdb8"
|
|
34
34
|
}
|