@entur/utils 0.4.6 → 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.
- package/dist/useRandomId.d.ts +1 -1
- package/dist/utils.cjs.development.js +8 -22
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +8 -22
- package/dist/utils.esm.js.map +1 -1
- package/package.json +8 -6
- package/CHANGELOG.md +0 -97
package/dist/useRandomId.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useRandomId: (prefix?: 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();
|
|
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
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
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
});
|
|
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,
|
|
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,GAAG,CAACO,OAAO;AACjC;;SCHgBC,UAAU,CAACC,QAAoB;EAC7C,IAAMC,MAAM,GAAGT,yBAAK,CAACC,MAAM,CAAU,KAAK,CAAC;EAE3CD,yBAAK,CAACU,SAAS,CAAC;IACd,IAAI,CAACD,MAAM,CAACH,OAAO,EAAE;MACnBG,MAAM,CAACH,OAAO,GAAG,I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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,
|
|
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();
|
|
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
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
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
});
|
|
119
|
-
|
|
104
|
+
});
|
|
105
|
+
// Finally. let's trigger a run of the checker.
|
|
120
106
|
checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
|
|
121
107
|
}
|
|
122
108
|
|
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/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,
|
|
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,YAA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S,CAAG,CAC1C,KAAK,CAAC;IACV,CACAO,IAAI,EAAE;;EAGT,IAAMC,mBAAmB,GAAGZ,cAAc,CAACa,MAAM,KAAK,CAAC;EACvD,wCAAAC,OAAO,CACLd,cAAc,CAACa,MAAM,KAAK,CAAC,wBAEzBD,mBAAmB,GACf,cAAc,GACXZ,cAAc,CAACa,MAAM,iBAC9B,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/utils.esm.js",
|
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"start": "dts watch --noClean",
|
|
21
|
-
"build": "dts build && cp src/*.scss dist",
|
|
22
|
-
"
|
|
23
|
-
"lint": "dts lint"
|
|
20
|
+
"start": "yarn run dts watch --noClean",
|
|
21
|
+
"build": "yarn run dts build && cp src/*.scss dist",
|
|
22
|
+
"lint": "yarn run dts lint"
|
|
24
23
|
},
|
|
25
24
|
"peerDependencies": {
|
|
26
25
|
"react": ">=16.8.0",
|
|
@@ -30,5 +29,8 @@
|
|
|
30
29
|
"react-polymorphic-types": "^1.1.0",
|
|
31
30
|
"tiny-warning": "^1.0.3"
|
|
32
31
|
},
|
|
33
|
-
"
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"dts-cli": "^1.1.6"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "8915b1630bd936740ba9a4a88883f3432948a80e"
|
|
34
36
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [0.4.6](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.5...@entur/utils@0.4.6) (2022-10-31)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- **style import warning:** remove ~ from import warning since it is deprecated ([c6a25fd](https://bitbucket.org/enturas/design-system/commits/c6a25fde98ec2f2821f678c6175c797ad10b7185))
|
|
11
|
-
|
|
12
|
-
## [0.4.5](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.4...@entur/utils@0.4.5) (2022-08-31)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @entur/utils
|
|
15
|
-
|
|
16
|
-
## [0.4.4](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.3...@entur/utils@0.4.4) (2022-08-24)
|
|
17
|
-
|
|
18
|
-
### Bug Fixes
|
|
19
|
-
|
|
20
|
-
- add parameter and return types ([861b878](https://bitbucket.org/enturas/design-system/commits/861b8782b1fae34242d64371a8af7887ac545df6))
|
|
21
|
-
|
|
22
|
-
## [0.4.3](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.2...@entur/utils@0.4.3) (2022-02-09)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @entur/utils
|
|
25
|
-
|
|
26
|
-
## [0.4.2](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.1...@entur/utils@0.4.2) (2021-06-25)
|
|
27
|
-
|
|
28
|
-
### Bug Fixes
|
|
29
|
-
|
|
30
|
-
- update dependencies ([80b9175](https://bitbucket.org/enturas/design-system/commits/80b9175b193d1154aa4ee6977c765e2c19b73415))
|
|
31
|
-
|
|
32
|
-
## [0.4.1](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.4.0...@entur/utils@0.4.1) (2021-02-17)
|
|
33
|
-
|
|
34
|
-
### Bug Fixes
|
|
35
|
-
|
|
36
|
-
- **dependency:** remove old polymorphism from dependencies ([c170645](https://bitbucket.org/enturas/design-system/commits/c1706459b36048952e9ca14cc51148054bf12bdc))
|
|
37
|
-
- **polymorphic:** add new polymorphism dependency ([7bf79cc](https://bitbucket.org/enturas/design-system/commits/7bf79cca1feccf7cfee11fc9f8ff1e5f1025a47f))
|
|
38
|
-
- **polymorphic:** remove old dependency as exports ([eb5f431](https://bitbucket.org/enturas/design-system/commits/eb5f43171cdc8099f9479bd6a7210c0a5fa2daa4))
|
|
39
|
-
|
|
40
|
-
# [0.4.0](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.3.0...@entur/utils@0.4.0) (2020-12-04)
|
|
41
|
-
|
|
42
|
-
### Features
|
|
43
|
-
|
|
44
|
-
- add polymorphic component dependecy as export ([5384642](https://bitbucket.org/enturas/design-system/commits/53846421f66f4b6193238d0d6cced8b09658d3b6))
|
|
45
|
-
|
|
46
|
-
# [0.3.0](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.9...@entur/utils@0.3.0) (2020-10-09)
|
|
47
|
-
|
|
48
|
-
### Features
|
|
49
|
-
|
|
50
|
-
- add useOnMount hook ([0f1fc26](https://bitbucket.org/enturas/design-system/commits/0f1fc2658a1263179be80b656828cf6373834702))
|
|
51
|
-
|
|
52
|
-
## [0.2.9](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.8...@entur/utils@0.2.9) (2020-06-17)
|
|
53
|
-
|
|
54
|
-
**Note:** Version bump only for package @entur/utils
|
|
55
|
-
|
|
56
|
-
## [0.2.8](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.7...@entur/utils@0.2.8) (2020-05-27)
|
|
57
|
-
|
|
58
|
-
**Note:** Version bump only for package @entur/utils
|
|
59
|
-
|
|
60
|
-
## [0.2.7](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.6...@entur/utils@0.2.7) (2020-05-26)
|
|
61
|
-
|
|
62
|
-
**Note:** Version bump only for package @entur/utils
|
|
63
|
-
|
|
64
|
-
## [0.2.6](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.5...@entur/utils@0.2.6) (2020-05-20)
|
|
65
|
-
|
|
66
|
-
**Note:** Version bump only for package @entur/utils
|
|
67
|
-
|
|
68
|
-
## [0.2.5](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.4...@entur/utils@0.2.5) (2020-04-27)
|
|
69
|
-
|
|
70
|
-
**Note:** Version bump only for package @entur/utils
|
|
71
|
-
|
|
72
|
-
## [0.2.4](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.3...@entur/utils@0.2.4) (2020-04-23)
|
|
73
|
-
|
|
74
|
-
**Note:** Version bump only for package @entur/utils
|
|
75
|
-
|
|
76
|
-
## [0.2.3](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.2...@entur/utils@0.2.3) (2020-02-05)
|
|
77
|
-
|
|
78
|
-
### Bug Fixes
|
|
79
|
-
|
|
80
|
-
- add new breakpoint mixin for new breakpoint token ([eb6cc7a](https://bitbucket.org/enturas/design-system/commits/eb6cc7a63ff345e9835ab209f035dd2d615d20f8))
|
|
81
|
-
- remove test-files from build process ([e0b24af](https://bitbucket.org/enturas/design-system/commits/e0b24af05d5c2ad8de4ae587d83c389495235890))
|
|
82
|
-
|
|
83
|
-
## [0.2.2](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.1...@entur/utils@0.2.2) (2020-01-27)
|
|
84
|
-
|
|
85
|
-
### Bug Fixes
|
|
86
|
-
|
|
87
|
-
- **types:** place types in the correct place ([acace09](https://bitbucket.org/enturas/design-system/commits/acace09ec0e258c5cff3a65e13ab29d6603780d9))
|
|
88
|
-
|
|
89
|
-
## [0.2.1](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.2.0...@entur/utils@0.2.1) (2020-01-14)
|
|
90
|
-
|
|
91
|
-
**Note:** Version bump only for package @entur/utils
|
|
92
|
-
|
|
93
|
-
# 0.2.0 (2020-01-08)
|
|
94
|
-
|
|
95
|
-
### Features
|
|
96
|
-
|
|
97
|
-
- add function to warn about missing style imports ([535e06c](https://bitbucket.org/enturas/design-system/commits/535e06c627708c3c69b002ceacaeba36950915be))
|