@entur/utils 0.5.0-RC.0 → 0.5.0-RC.2
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 +10 -0
- package/dist/ConditionalWrapper.d.ts +1 -1
- package/dist/useOnEscape.d.ts +1 -1
- package/dist/useRandomId.d.ts +1 -1
- package/dist/utils.cjs.development.js +16 -45
- 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 +16 -45
- package/dist/utils.esm.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.5.0-RC.2](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.5.0-RC.1...@entur/utils@0.5.0-RC.2) (2022-11-22)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **useOnEscape:** commit for force updating utils-packages for publishing ([4c1082c](https://bitbucket.org/enturas/design-system/commits/4c1082c872a546c6c848aed2e2ae80e2d4599d11))
|
|
11
|
+
|
|
12
|
+
# [0.5.0-RC.1](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.5.0-RC.0...@entur/utils@0.5.0-RC.1) (2022-11-21)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @entur/utils
|
|
15
|
+
|
|
6
16
|
# [0.5.0-RC.0](https://bitbucket.org/enturas/design-system/compare/@entur/utils@0.5.0-alpha.0...@entur/utils@0.5.0-RC.0) (2022-11-21)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @entur/utils
|
package/dist/useOnEscape.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare const useOnEscape: (ref: React.RefObject<
|
|
2
|
+
export declare const useOnEscape: (ref: React.RefObject<HTMLElement>, handler: () => void) => void;
|
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;
|
|
@@ -102,10 +93,8 @@ var useOnClickOutside = function useOnClickOutside(refs, handler) {
|
|
|
102
93
|
})) {
|
|
103
94
|
return;
|
|
104
95
|
}
|
|
105
|
-
|
|
106
96
|
handler();
|
|
107
97
|
};
|
|
108
|
-
|
|
109
98
|
document.addEventListener('mousedown', listener);
|
|
110
99
|
document.addEventListener('touchstart', listener);
|
|
111
100
|
return function () {
|
|
@@ -114,71 +103,58 @@ var useOnClickOutside = function useOnClickOutside(refs, handler) {
|
|
|
114
103
|
};
|
|
115
104
|
}, [refs, handler]);
|
|
116
105
|
};
|
|
117
|
-
|
|
118
106
|
var elementContainsEventTarget = function elementContainsEventTarget(element, event) {
|
|
119
107
|
if (!element) {
|
|
120
108
|
return false;
|
|
121
109
|
}
|
|
122
|
-
|
|
123
110
|
if (element.contains(event.target)) {
|
|
124
111
|
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
}
|
|
113
|
+
// For elements inside a Shadow DOM we need to check the composedPath
|
|
128
114
|
if (event.composed && event.composedPath) {
|
|
129
115
|
var contains = event.composedPath().find(function (target) {
|
|
130
116
|
if (target === window) {
|
|
131
117
|
return false;
|
|
132
118
|
}
|
|
133
|
-
|
|
134
119
|
return element.contains(target);
|
|
135
120
|
});
|
|
136
121
|
return contains ? true : false;
|
|
137
122
|
}
|
|
138
|
-
|
|
139
123
|
return false;
|
|
140
124
|
};
|
|
141
125
|
|
|
142
126
|
var useOnEscape = function useOnEscape(ref, handler) {
|
|
143
127
|
React.useEffect(function () {
|
|
144
128
|
var _ref$current;
|
|
145
|
-
|
|
146
129
|
var runIfKeyIsEscape = function runIfKeyIsEscape(event) {
|
|
147
|
-
console.log('lol');
|
|
148
130
|
if (event.key === 'Escape') handler();
|
|
149
131
|
};
|
|
150
|
-
|
|
151
132
|
(_ref$current = ref.current) == null ? void 0 : _ref$current.addEventListener('keydown', runIfKeyIsEscape);
|
|
152
133
|
return function () {
|
|
153
134
|
var _ref$current2;
|
|
154
|
-
|
|
155
135
|
return (_ref$current2 = ref.current) == null ? void 0 : _ref$current2.removeEventListener('keydown', runIfKeyIsEscape);
|
|
156
136
|
};
|
|
157
137
|
}, [ref, handler]);
|
|
158
138
|
};
|
|
159
139
|
|
|
160
140
|
// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs
|
|
161
|
-
|
|
162
141
|
var getWindowDimensions = function getWindowDimensions() {
|
|
163
142
|
var _window = window,
|
|
164
|
-
|
|
165
|
-
|
|
143
|
+
width = _window.innerWidth,
|
|
144
|
+
height = _window.innerHeight;
|
|
166
145
|
return {
|
|
167
146
|
width: width,
|
|
168
147
|
height: height
|
|
169
148
|
};
|
|
170
149
|
};
|
|
171
|
-
|
|
172
150
|
var useWindowDimensions = function useWindowDimensions() {
|
|
173
151
|
var _useState = React.useState(getWindowDimensions()),
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
152
|
+
windowDimensions = _useState[0],
|
|
153
|
+
setWindowDimensions = _useState[1];
|
|
177
154
|
React.useEffect(function () {
|
|
178
155
|
function handleResize() {
|
|
179
156
|
setWindowDimensions(getWindowDimensions());
|
|
180
157
|
}
|
|
181
|
-
|
|
182
158
|
window.addEventListener('resize', handleResize);
|
|
183
159
|
return function () {
|
|
184
160
|
return window.removeEventListener('resize', handleResize);
|
|
@@ -189,44 +165,39 @@ var useWindowDimensions = function useWindowDimensions() {
|
|
|
189
165
|
|
|
190
166
|
var ConditionalWrapper = function ConditionalWrapper(_ref) {
|
|
191
167
|
var condition = _ref.condition,
|
|
192
|
-
|
|
193
|
-
|
|
168
|
+
wrapper = _ref.wrapper,
|
|
169
|
+
children = _ref.children;
|
|
194
170
|
return condition ? wrapper(children) : React__default["default"].createElement(React__default["default"].Fragment, null, children);
|
|
195
171
|
};
|
|
196
172
|
|
|
197
173
|
var packagesToCheck = /*#__PURE__*/new Set();
|
|
198
174
|
var checkTimeoutId;
|
|
199
|
-
|
|
200
175
|
function checkAndWarn() {
|
|
201
176
|
var missingImports = Array.from(packagesToCheck).filter(function (namespace) {
|
|
202
177
|
return parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--eds-" + namespace)) !== 1;
|
|
203
|
-
}).sort();
|
|
204
|
-
|
|
178
|
+
}).sort();
|
|
179
|
+
// Finally, we warn about those pesky imports
|
|
205
180
|
var singleMissingImport = missingImports.length === 1;
|
|
206
181
|
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) {
|
|
207
182
|
return "\t@import '~@entur/" + namespace + "/dist/styles.css';";
|
|
208
183
|
}).join('\n') + "\n") ;
|
|
209
184
|
}
|
|
210
185
|
/** Warns the developer if they have forgotten to include styles */
|
|
211
|
-
|
|
212
|
-
|
|
213
186
|
function warnAboutMissingStyles() {
|
|
214
187
|
// We skip this check in production, and when we build static sites
|
|
215
188
|
if (typeof window === 'undefined') {
|
|
216
189
|
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
190
|
+
}
|
|
191
|
+
// First, let's clear earlier calls to setTimeout
|
|
192
|
+
window.clearTimeout(checkTimeoutId);
|
|
193
|
+
// Next, let's add all namespaces to the set of packages to check
|
|
222
194
|
for (var _len = arguments.length, namespaces = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
223
195
|
namespaces[_key] = arguments[_key];
|
|
224
196
|
}
|
|
225
|
-
|
|
226
197
|
namespaces.forEach(function (namespace) {
|
|
227
198
|
return packagesToCheck.add(namespace);
|
|
228
|
-
});
|
|
229
|
-
|
|
199
|
+
});
|
|
200
|
+
// Finally. let's trigger a run of the checker.
|
|
230
201
|
checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
|
|
231
202
|
}
|
|
232
203
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs.development.js","sources":["../src/debounce.ts","../src/useRandomId.ts","../src/useOnMount.ts","../src/mergeRefs.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../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 React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLDivElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLDivElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n console.log('lol');\n\n if (event.key === 'Escape') handler();\n };\n\n ref.current?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => ref.current?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\nconst getWindowDimensions = () => {\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = () => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '~@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (!__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","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","console","log","key","getWindowDimensions","width","innerWidth","height","innerHeight","useWindowDimensions","useState","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ICXYG,SAAS,GAAG,SAAZA,SAAY;oCACpBC;AAAAA,IAAAA;;;AAEH,SAAO,UAACC,IAAD;AACL,yDAAkBD,IAAlB,wCAAwB;AAAA,UAAbb,GAAa;;AACtB,UAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,QAAAA,GAAG,CAACc,IAAD,CAAH;AACD,OAFD,MAEO,IAAId,GAAJ,EAASA,GAAG,CAACO,OAAJ,GAAcO,IAAd;AACjB;AACF,GAND;AAOD;;ICRYC,iBAAiB,GAAG,SAApBA,iBAAoB,CAC/BF,IAD+B,EA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AM,CAACjC,UAAP,CAAkBwD,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/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../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 React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLDivElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n ref.current?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => ref.current?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\nconst getWindowDimensions = () => {\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = () => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '~@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (!__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","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","getWindowDimensions","width","innerWidth","height","innerHeight","useWindowDimensions","useState","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;;;;;;;;;;AAAgB,SAAAA,QAAQ,CACtBC,EAAK,EACLC,KAAa,EAAA;AAEb,EAAA,IAAIC,EAAO,CAAA;AACX,EAAA,OAAO,YAAY;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAARC,IAAI,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;MAAJA,IAAI,CAAA,IAAA,CAAA,GAAA,SAAA,CAA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AAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EARwCkB,UAAoB,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;IAApBA,UAAoB,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAS5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAb,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGtB,MAAM,CAACjC,UAAU,CAACwD,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("tiny-warning");var t=n(e);function r(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function o(e,n){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,n){if(e){if("string"==typeof e)return r(e,n);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)?r(e,n):void 0}}(e))||n&&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.")}var u=function(){var e=window;return{width:e.innerWidth,height:e.innerHeight}};exports.ConditionalWrapper=function(e){var n=e.children;return e.condition?(0,e.wrapper)(n):t.default.createElement(t.default.Fragment,null,n)},exports.debounce=function(e,n){var t;return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,o)}),n)}},exports.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){for(var t,r=o(n);!(t=r()).done;){var u=t.value;"function"==typeof u?u(e):u&&(u.current=e)}}},exports.useOnClickOutside=function(n,t){e.useEffect((function(){var e=function(e){n.some((function(n){return function(e,n){return!(!e||!(e.contains(n.target)||n.composed&&n.composedPath&&n.composedPath().find((function(n){return n!==window&&e.contains(n)}))))}(n.current,e)}))||t()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[n,t])},exports.useOnEscape=function(n,t){e.useEffect((function(){var e,r=function(e){
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("tiny-warning");var t=n(e);function r(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function o(e,n){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,n){if(e){if("string"==typeof e)return r(e,n);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)?r(e,n):void 0}}(e))||n&&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.")}var u=function(){var e=window;return{width:e.innerWidth,height:e.innerHeight}};exports.ConditionalWrapper=function(e){var n=e.children;return e.condition?(0,e.wrapper)(n):t.default.createElement(t.default.Fragment,null,n)},exports.debounce=function(e,n){var t;return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,o)}),n)}},exports.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){for(var t,r=o(n);!(t=r()).done;){var u=t.value;"function"==typeof u?u(e):u&&(u.current=e)}}},exports.useOnClickOutside=function(n,t){e.useEffect((function(){var e=function(e){n.some((function(n){return function(e,n){return!(!e||!(e.contains(n.target)||n.composed&&n.composedPath&&n.composedPath().find((function(n){return n!==window&&e.contains(n)}))))}(n.current,e)}))||t()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[n,t])},exports.useOnEscape=function(n,t){e.useEffect((function(){var e,r=function(e){"Escape"===e.key&&t()};return null==(e=n.current)||e.addEventListener("keydown",r),function(){var e;return null==(e=n.current)?void 0:e.removeEventListener("keydown",r)}}),[n,t])},exports.useOnMount=function(e){var n=t.default.useRef(!1);t.default.useEffect((function(){n.current||(n.current=!0,e())}),[e])},exports.useRandomId=function(e){return e+"-"+t.default.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var n=e.useState(u()),t=n[0],r=n[1];return e.useEffect((function(){function e(){r(u())}return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),t},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/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/debounce.ts","../src/
|
|
1
|
+
{"version":3,"file":"utils.cjs.production.min.js","sources":["../src/mergeRefs.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../src/debounce.ts","../src/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useOnMount.ts","../src/useRandomId.ts","../src/warnAboutMissingStyles.ts"],"sourcesContent":["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","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\nconst getWindowDimensions = () => {\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = () => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","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, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLDivElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n ref.current?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => ref.current?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\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","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":["mergeRefs","getWindowDimensions","_window","window","width","innerWidth","height","innerHeight","_ref","children","condition","wrapper","React","createElement","Fragment","fn","delay","id","_len","arguments","length","args","Array","_key","clearTimeout","setTimeout","refs","node","_step","_iterator","_createForOfIteratorHelperLoose","done","ref","value","current","handler","useEffect","listener","event","some","element","contains","target","composed","composedPath","find","elementContainsEventTarget","document","addEventListener","removeEventListener","_ref$current","runIfKeyIsEscape","key","_ref$current2","callback","hasRun","useRef","prefix","String","Math","random","substring","_useState","useState","windowDimensions","setWindowDimensions","handleResize"],"mappings":"4/BAAaA,ICGPC,EAAsB,WAC1B,IAAAC,EAAmDC,OACnD,MAAO,CACLC,QAFMC,WAGNC,SAHyBC,YAK7B,6BCDkC,SAAHC,GAAA,IAG7BC,IAAAA,SAAQ,SAFRC,WAGyCC,IAFzCA,SAEiDF,GAAYG,EAAA,QAAAC,cAAAD,EAAAA,QAAAE,SAAA,KAAGL,EAAY,mBCZ9D,SACdM,EACAC,GAEA,IAAIC,EACJ,OAAO,WAAY,IAAA,IAAAC,EAAAC,UAAAC,OAARC,EAAI,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAJF,EAAIE,GAAAJ,UAAAI,GACbC,aAAaP,GACbA,EAAKQ,YAAW,WAAA,OAAMV,EAAMM,WAAAA,EAAAA,EAAK,GAAEL,GAEvC,oBHTyB,WAErB,IAAA,IAAAE,EAAAC,UAAAC,OADCM,EAA2D,IAAA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SAACG,GAE1B,OAAUA,EAAM,IADJ7C,EAAAA,QAAM4C,OAAOE,OAAOC,KAAKC,UAAUC,UAAU,IACjC3B,OAC1B,8BNMmC,WACjC,IAAA4B,EAAgDC,WAC9C9D,KADK+D,EAAgBF,EAAA,GAAEG,EAAmBH,EAAA,GAa5C,OATA1B,EAAAA,WAAU,WACR,SAAS8B,IACPD,EAAoBhE,IACtB,CAGA,OADAE,OAAO6C,iBAAiB,SAAUkB,GAC3B,WAAA,OAAM/D,OAAO8C,oBAAoB,SAAUiB,EAAa,CAChE,GAAE,IAEIF,CACT,iCOagB,WAahB"}
|
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;
|
|
@@ -93,10 +84,8 @@ var useOnClickOutside = function useOnClickOutside(refs, handler) {
|
|
|
93
84
|
})) {
|
|
94
85
|
return;
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
handler();
|
|
98
88
|
};
|
|
99
|
-
|
|
100
89
|
document.addEventListener('mousedown', listener);
|
|
101
90
|
document.addEventListener('touchstart', listener);
|
|
102
91
|
return function () {
|
|
@@ -105,71 +94,58 @@ var useOnClickOutside = function useOnClickOutside(refs, handler) {
|
|
|
105
94
|
};
|
|
106
95
|
}, [refs, handler]);
|
|
107
96
|
};
|
|
108
|
-
|
|
109
97
|
var elementContainsEventTarget = function elementContainsEventTarget(element, event) {
|
|
110
98
|
if (!element) {
|
|
111
99
|
return false;
|
|
112
100
|
}
|
|
113
|
-
|
|
114
101
|
if (element.contains(event.target)) {
|
|
115
102
|
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
103
|
+
}
|
|
104
|
+
// For elements inside a Shadow DOM we need to check the composedPath
|
|
119
105
|
if (event.composed && event.composedPath) {
|
|
120
106
|
var contains = event.composedPath().find(function (target) {
|
|
121
107
|
if (target === window) {
|
|
122
108
|
return false;
|
|
123
109
|
}
|
|
124
|
-
|
|
125
110
|
return element.contains(target);
|
|
126
111
|
});
|
|
127
112
|
return contains ? true : false;
|
|
128
113
|
}
|
|
129
|
-
|
|
130
114
|
return false;
|
|
131
115
|
};
|
|
132
116
|
|
|
133
117
|
var useOnEscape = function useOnEscape(ref, handler) {
|
|
134
118
|
useEffect(function () {
|
|
135
119
|
var _ref$current;
|
|
136
|
-
|
|
137
120
|
var runIfKeyIsEscape = function runIfKeyIsEscape(event) {
|
|
138
|
-
console.log('lol');
|
|
139
121
|
if (event.key === 'Escape') handler();
|
|
140
122
|
};
|
|
141
|
-
|
|
142
123
|
(_ref$current = ref.current) == null ? void 0 : _ref$current.addEventListener('keydown', runIfKeyIsEscape);
|
|
143
124
|
return function () {
|
|
144
125
|
var _ref$current2;
|
|
145
|
-
|
|
146
126
|
return (_ref$current2 = ref.current) == null ? void 0 : _ref$current2.removeEventListener('keydown', runIfKeyIsEscape);
|
|
147
127
|
};
|
|
148
128
|
}, [ref, handler]);
|
|
149
129
|
};
|
|
150
130
|
|
|
151
131
|
// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs
|
|
152
|
-
|
|
153
132
|
var getWindowDimensions = function getWindowDimensions() {
|
|
154
133
|
var _window = window,
|
|
155
|
-
|
|
156
|
-
|
|
134
|
+
width = _window.innerWidth,
|
|
135
|
+
height = _window.innerHeight;
|
|
157
136
|
return {
|
|
158
137
|
width: width,
|
|
159
138
|
height: height
|
|
160
139
|
};
|
|
161
140
|
};
|
|
162
|
-
|
|
163
141
|
var useWindowDimensions = function useWindowDimensions() {
|
|
164
142
|
var _useState = useState(getWindowDimensions()),
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
143
|
+
windowDimensions = _useState[0],
|
|
144
|
+
setWindowDimensions = _useState[1];
|
|
168
145
|
useEffect(function () {
|
|
169
146
|
function handleResize() {
|
|
170
147
|
setWindowDimensions(getWindowDimensions());
|
|
171
148
|
}
|
|
172
|
-
|
|
173
149
|
window.addEventListener('resize', handleResize);
|
|
174
150
|
return function () {
|
|
175
151
|
return window.removeEventListener('resize', handleResize);
|
|
@@ -180,44 +156,39 @@ var useWindowDimensions = function useWindowDimensions() {
|
|
|
180
156
|
|
|
181
157
|
var ConditionalWrapper = function ConditionalWrapper(_ref) {
|
|
182
158
|
var condition = _ref.condition,
|
|
183
|
-
|
|
184
|
-
|
|
159
|
+
wrapper = _ref.wrapper,
|
|
160
|
+
children = _ref.children;
|
|
185
161
|
return condition ? wrapper(children) : React.createElement(React.Fragment, null, children);
|
|
186
162
|
};
|
|
187
163
|
|
|
188
164
|
var packagesToCheck = /*#__PURE__*/new Set();
|
|
189
165
|
var checkTimeoutId;
|
|
190
|
-
|
|
191
166
|
function checkAndWarn() {
|
|
192
167
|
var missingImports = Array.from(packagesToCheck).filter(function (namespace) {
|
|
193
168
|
return parseInt(window.getComputedStyle(document.documentElement).getPropertyValue("--eds-" + namespace)) !== 1;
|
|
194
|
-
}).sort();
|
|
195
|
-
|
|
169
|
+
}).sort();
|
|
170
|
+
// Finally, we warn about those pesky imports
|
|
196
171
|
var singleMissingImport = missingImports.length === 1;
|
|
197
172
|
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) {
|
|
198
173
|
return "\t@import '~@entur/" + namespace + "/dist/styles.css';";
|
|
199
174
|
}).join('\n') + "\n") : void 0;
|
|
200
175
|
}
|
|
201
176
|
/** Warns the developer if they have forgotten to include styles */
|
|
202
|
-
|
|
203
|
-
|
|
204
177
|
function warnAboutMissingStyles() {
|
|
205
178
|
// We skip this check in production, and when we build static sites
|
|
206
179
|
if (!(process.env.NODE_ENV !== "production") || typeof window === 'undefined') {
|
|
207
180
|
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
181
|
+
}
|
|
182
|
+
// First, let's clear earlier calls to setTimeout
|
|
183
|
+
window.clearTimeout(checkTimeoutId);
|
|
184
|
+
// Next, let's add all namespaces to the set of packages to check
|
|
213
185
|
for (var _len = arguments.length, namespaces = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
214
186
|
namespaces[_key] = arguments[_key];
|
|
215
187
|
}
|
|
216
|
-
|
|
217
188
|
namespaces.forEach(function (namespace) {
|
|
218
189
|
return packagesToCheck.add(namespace);
|
|
219
|
-
});
|
|
220
|
-
|
|
190
|
+
});
|
|
191
|
+
// Finally. let's trigger a run of the checker.
|
|
221
192
|
checkTimeoutId = window.setTimeout(checkAndWarn, 1000);
|
|
222
193
|
}
|
|
223
194
|
|
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/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../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 React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLDivElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLDivElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n console.log('lol');\n\n if (event.key === 'Escape') handler();\n };\n\n ref.current?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => ref.current?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\nconst getWindowDimensions = () => {\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = () => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '~@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (!__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","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","console","log","key","getWindowDimensions","width","innerWidth","height","innerHeight","useWindowDimensions","useState","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ICXYG,SAAS,GAAG,SAAZA,SAAY;oCACpBC;AAAAA,IAAAA;;;AAEH,SAAO,UAACC,IAAD;AACL,yDAAkBD,IAAlB,wCAAwB;AAAA,UAAbb,GAAa;;AACtB,UAAI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A,EAAAA,MAAM,CAAClC,YAAP,CAAoBwD,cAApB;;oCANwCkB;AAAAA,IAAAA;;;AASxCA,EAAAA,UAAU,CAACC,OAAX,CAAmB,UAAAb,SAAS;AAAA,WAAIR,eAAe,CAACsB,GAAhB,CAAoBd,SAApB,CAAJ;AAAA,GAA5B;;AAGAN,EAAAA,cAAc,GAAGtB,MAAM,CAACjC,UAAP,CAAkBwD,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/useOnClickOutside.ts","../src/useOnEscape.ts","../src/useWindowDimensions.ts","../src/ConditionalWrapper.tsx","../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 React, { useEffect } from 'react';\n\nexport const useOnClickOutside = (\n refs: React.RefObject<HTMLDivElement>[],\n handler: () => void,\n) => {\n useEffect(() => {\n const listener = (event: Event) => {\n // If the ref contains the clicked element, then the click is not outside\n if (refs.some(ref => elementContainsEventTarget(ref.current, event))) {\n return;\n }\n\n handler();\n };\n\n document.addEventListener('mousedown', listener);\n document.addEventListener('touchstart', listener);\n\n return () => {\n document.removeEventListener('mousedown', listener);\n document.removeEventListener('touchstart', listener);\n };\n }, [refs, handler]);\n};\n\nconst elementContainsEventTarget = (\n element: HTMLElement | null,\n event: Event,\n) => {\n if (!element) {\n return false;\n }\n\n if (element.contains(event.target as Node)) {\n return true;\n }\n\n // For elements inside a Shadow DOM we need to check the composedPath\n if (event.composed && event.composedPath) {\n const contains = event.composedPath().find(target => {\n if (target === window) {\n return false;\n }\n return element.contains(target as Node);\n });\n return contains ? true : false;\n }\n\n return false;\n};\n","import React, { useEffect } from 'react';\n\nexport const useOnEscape = (\n ref: React.RefObject<HTMLElement>,\n handler: () => void,\n) => {\n useEffect(() => {\n const runIfKeyIsEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape') handler();\n };\n\n ref.current?.addEventListener('keydown', runIfKeyIsEscape);\n\n return () => ref.current?.removeEventListener('keydown', runIfKeyIsEscape);\n }, [ref, handler]);\n};\n","// from https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs\nimport { useState, useEffect } from 'react';\n\nconst getWindowDimensions = () => {\n const { innerWidth: width, innerHeight: height } = window;\n return {\n width,\n height,\n };\n};\n\nexport const useWindowDimensions = () => {\n const [windowDimensions, setWindowDimensions] = useState(\n getWindowDimensions(),\n );\n\n useEffect(() => {\n function handleResize() {\n setWindowDimensions(getWindowDimensions());\n }\n\n window.addEventListener('resize', handleResize);\n return () => window.removeEventListener('resize', handleResize);\n }, []);\n\n return windowDimensions;\n};\n","import React from 'react';\n\ntype ConditionalWrapperType = {\n condition: boolean;\n wrapper: any;\n children: any;\n};\n\nexport const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: ConditionalWrapperType) => (condition ? wrapper(children) : <>{children}</>);\n","import warning from 'tiny-warning';\n\nconst packagesToCheck: Set<string> = new Set();\nlet checkTimeoutId: number;\n\nfunction checkAndWarn() {\n const missingImports = Array.from(packagesToCheck)\n .filter(\n namespace =>\n parseInt(\n window\n .getComputedStyle(document.documentElement)\n .getPropertyValue(`--eds-${namespace}`),\n ) !== 1,\n )\n .sort();\n\n // Finally, we warn about those pesky imports\n const singleMissingImport = missingImports.length === 1;\n warning(\n missingImports.length === 0,\n `You are missing ${\n singleMissingImport\n ? 'a CSS import'\n : `${missingImports.length} CSS imports`\n }!\n\nPlease add the following CSS import${\n singleMissingImport ? '' : 's'\n } somewhere in your app:\n\n${missingImports\n .map(namespace => `\\t@import '~@entur/${namespace}/dist/styles.css';`)\n .join('\\n')}\n`,\n );\n}\n\n/** Warns the developer if they have forgotten to include styles */\nexport function warnAboutMissingStyles(...namespaces: string[]): void {\n // We skip this check in production, and when we build static sites\n if (!__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","useOnClickOutside","handler","listener","event","some","elementContainsEventTarget","document","addEventListener","removeEventListener","element","contains","target","composed","composedPath","find","window","useOnEscape","runIfKeyIsEscape","key","getWindowDimensions","width","innerWidth","height","innerHeight","useWindowDimensions","useState","windowDimensions","setWindowDimensions","handleResize","ConditionalWrapper","condition","wrapper","children","createElement","Fragment","packagesToCheck","Set","checkTimeoutId","checkAndWarn","missingImports","Array","from","filter","namespace","parseInt","getComputedStyle","documentElement","getPropertyValue","sort","singleMissingImport","length","warning","map","join","warnAboutMissingStyles","namespaces","forEach","add"],"mappings":";;;AAAgB,SAAAA,QAAQ,CACtBC,EAAK,EACLC,KAAa,EAAA;AAEb,EAAA,IAAIC,EAAO,CAAA;AACX,EAAA,OAAO,YAAY;AAAA,IAAA,KAAA,I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EU,IAAI,CAAC,IAAI,CAAC,GAEV,IAAA,CAAA,GAAA,KAAA,CAAA,CAAA;AACH,CAAA;AAEA;AACgB,SAAAC,sBAAsB,GAAwB;AAC5D;AACA,EAAA,IAAI,wCAAQ,IAAI,OAAOvC,MAAM,KAAK,WAAW,EAAE;AAC7C,IAAA,OAAA;AACD,GAAA;AACD;AACAA,EAAAA,MAAM,CAAClC,YAAY,CAACwD,cAAc,CAAC,CAAA;AAEnC;AAAA,EAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EARwCkB,UAAoB,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IAAA,EAAA,EAAA;IAApBA,UAAoB,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA,IAAA,CAAA,CAAA;AAAA,GAAA;AAS5DA,EAAAA,UAAU,CAACC,OAAO,CAAC,UAAAb,SAAS,EAAA;AAAA,IAAA,OAAIR,eAAe,CAACsB,GAAG,CAACd,SAAS,CAAC,CAAA;GAAC,CAAA,CAAA;AAE/D;EACAN,cAAc,GAAGtB,MAAM,CAACjC,UAAU,CAACwD,YAAY,EAAE,IAAI,CAAC,CAAA;AACxD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur/utils",
|
|
3
|
-
"version": "0.5.0-RC.
|
|
3
|
+
"version": "0.5.0-RC.2",
|
|
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": "c994dd720e55fc4652ef5f05d7235d61b6bbfbf9"
|
|
34
34
|
}
|