@terreno/ui 0.12.0 → 0.12.1
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/Toast.d.ts +1 -1
- package/dist/Toast.js +2 -1
- package/dist/Toast.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +8 -2
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/package.json +1 -1
- package/src/Toast.test.tsx +8 -2
- package/src/Toast.tsx +4 -3
- package/src/UserInactivity.test.tsx +4 -4
- package/src/WebAddressAutocomplete.test.tsx +137 -0
- package/src/WebAddressAutocomplete.tsx +17 -6
package/dist/Toast.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const useToast: () => {
|
|
|
17
17
|
warn: (title: string, options?: UseToastVariantOptions) => string;
|
|
18
18
|
error: (title: string, options?: UseToastVariantOptions) => string;
|
|
19
19
|
show: (title: string, options?: UseToastOptions) => string;
|
|
20
|
-
catch: (error:
|
|
20
|
+
catch: (error: unknown, message?: string, options?: UseToastVariantOptions) => void;
|
|
21
21
|
};
|
|
22
22
|
export declare const Toast: ({ title, variant, secondary, size, onDismiss, persistent, subtitle, }: ToastProps) => React.ReactElement;
|
|
23
23
|
export {};
|
package/dist/Toast.js
CHANGED
|
@@ -30,7 +30,8 @@ export const useToast = () => {
|
|
|
30
30
|
console.error(exceptionMsg);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
|
|
33
|
+
const errorObj = error;
|
|
34
|
+
exceptionMsg = (_b = (_a = errorObj === null || errorObj === void 0 ? void 0 : errorObj.message) !== null && _a !== void 0 ? _a : errorObj === null || errorObj === void 0 ? void 0 : errorObj.error) !== null && _b !== void 0 ? _b : String(error);
|
|
34
35
|
console.error(`${message}: ${exceptionMsg}`);
|
|
35
36
|
}
|
|
36
37
|
show(exceptionMsg, Object.assign(Object.assign({}, options), { variant: "error" }));
|
package/dist/Toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AACjC,OAAO,EAAC,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAEtD,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC;AAYnC,MAAM,CAAC,MAAM,QAAQ,GAAG,GAQtB,EAAE;IACF,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,OAAyB,EAAU,EAAE;QAChE,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;YAC1E,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,SAAS,iCACb,OAAO,EAAE,MAAM,IACZ,OAAO,KACV,KAAK,GACN,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE;YACvB,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB;SACtD,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":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ps.googleapis.com/maps/api/js?key=${googleMapsApiKey}&libraries=places&callback=${callbackName}`;
|
|
16
16
|
script.async = true;
|
|
17
17
|
script.defer = true;
|
|
18
|
-
script.onerror = () =>
|
|
18
|
+
script.onerror = () => {
|
|
19
|
+
reject(new Error("Google Maps script failed to load"));
|
|
20
|
+
};
|
|
19
21
|
document.head.appendChild(script);
|
|
20
22
|
return;
|
|
21
23
|
});
|
|
@@ -54,7 +56,11 @@ export const WebAddressAutocomplete = ({ disabled, googleMapsApiKey, includeCoun
|
|
|
54
56
|
window[callbackName] = null;
|
|
55
57
|
};
|
|
56
58
|
}, [googleMapsApiKey, includeCounty, handleAutoCompleteChange]);
|
|
57
|
-
return (_jsx(TextField, { disabled: disabled, inputRef: scriptLoaded
|
|
59
|
+
return (_jsx(TextField, { disabled: disabled, inputRef: scriptLoaded
|
|
60
|
+
? (ref) => {
|
|
61
|
+
autocompleteInputRef.current = ref;
|
|
62
|
+
}
|
|
63
|
+
: undefined, onChange: (value) => {
|
|
58
64
|
handleAddressChange(value);
|
|
59
65
|
}, placeholder: "Enter an address", type: "text", value: inputValue }));
|
|
60
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebAddressAutocomplete.js","sourceRoot":"","sources":["../src/WebAddressAutocomplete.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAoB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"WebAddressAutocomplete.js","sourceRoot":"","sources":["../src/WebAddressAutocomplete.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAoB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAIrE,OAAO,EAAC,8BAA8B,EAAC,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,wBAAwB,EAAC,MAAM,aAAa,CAAC;AAIrD,MAAM,sBA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AC;YACH,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,CAAC,KAAK,EAAQ,EAAE;YACxB,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,EACD,WAAW,EAAC,kBAAkB,EAC9B,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,UAAU,GACjB,CACH,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/Toast.test.tsx
CHANGED
|
@@ -6,11 +6,17 @@ import {Toast, useToast} from "./Toast";
|
|
|
6
6
|
import {ToastProvider} from "./ToastNotifications";
|
|
7
7
|
import {renderWithTheme} from "./test-utils";
|
|
8
8
|
|
|
9
|
+
interface RafGlobal {
|
|
10
|
+
requestAnimationFrame: (callback: FrameRequestCallback) => number;
|
|
11
|
+
cancelAnimationFrame: (id: number) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
beforeAll(() => {
|
|
10
|
-
|
|
15
|
+
const g = globalThis as unknown as RafGlobal;
|
|
16
|
+
g.requestAnimationFrame = (callback: FrameRequestCallback) => {
|
|
11
17
|
return setTimeout(() => callback(Date.now()), 0) as unknown as number;
|
|
12
18
|
};
|
|
13
|
-
|
|
19
|
+
g.cancelAnimationFrame = (id: number) => {
|
|
14
20
|
clearTimeout(id);
|
|
15
21
|
};
|
|
16
22
|
});
|
package/src/Toast.tsx
CHANGED
|
@@ -28,7 +28,7 @@ export const useToast = (): {
|
|
|
28
28
|
warn: (title: string, options?: UseToastVariantOptions) => string;
|
|
29
29
|
error: (title: string, options?: UseToastVariantOptions) => string;
|
|
30
30
|
show: (title: string, options?: UseToastOptions) => string;
|
|
31
|
-
catch: (error:
|
|
31
|
+
catch: (error: unknown, message?: string, options?: UseToastVariantOptions) => void;
|
|
32
32
|
} => {
|
|
33
33
|
const toast = useToastNotifications();
|
|
34
34
|
const show = (title: string, options?: UseToastOptions): string => {
|
|
@@ -47,14 +47,15 @@ export const useToast = (): {
|
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
return {
|
|
50
|
-
catch: (error:
|
|
50
|
+
catch: (error: unknown, message?: string, options?: UseToastVariantOptions): void => {
|
|
51
51
|
let exceptionMsg;
|
|
52
52
|
if (isAPIError(error)) {
|
|
53
53
|
// Get the error without details.
|
|
54
54
|
exceptionMsg = `${message}: ${printAPIError(error)}`;
|
|
55
55
|
console.error(exceptionMsg);
|
|
56
56
|
} else {
|
|
57
|
-
|
|
57
|
+
const errorObj = error as {message?: string; error?: string} | null | undefined;
|
|
58
|
+
exceptionMsg = errorObj?.message ?? errorObj?.error ?? String(error);
|
|
58
59
|
console.error(`${message}: ${exceptionMsg}`);
|
|
59
60
|
}
|
|
60
61
|
show(exceptionMsg, {...options, variant: "error"});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {act} from "@testing-library/react-native";
|
|
3
|
-
import {Keyboard} from "react-native";
|
|
3
|
+
import {type EmitterSubscription, Keyboard} from "react-native";
|
|
4
4
|
|
|
5
5
|
import {Text} from "./Text";
|
|
6
6
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -115,8 +115,8 @@ describe("UserInactivity", () => {
|
|
|
115
115
|
const removeHide = mock(() => {});
|
|
116
116
|
const removeShow = mock(() => {});
|
|
117
117
|
const addListenerSpy = spyOn(Keyboard, "addListener")
|
|
118
|
-
.mockReturnValueOnce({remove: removeHide} as
|
|
119
|
-
.mockReturnValueOnce({remove: removeShow} as
|
|
118
|
+
.mockReturnValueOnce({remove: removeHide} as unknown as EmitterSubscription)
|
|
119
|
+
.mockReturnValueOnce({remove: removeShow} as unknown as EmitterSubscription);
|
|
120
120
|
|
|
121
121
|
const {unmount} = renderWithTheme(
|
|
122
122
|
<UserInactivity onAction={onAction}>
|
|
@@ -142,7 +142,7 @@ describe("UserInactivity", () => {
|
|
|
142
142
|
if (event === "keyboardDidHide") {
|
|
143
143
|
capturedHideCallback = callback;
|
|
144
144
|
}
|
|
145
|
-
return {remove: mock(() => {})} as
|
|
145
|
+
return {remove: mock(() => {})} as unknown as EmitterSubscription;
|
|
146
146
|
}
|
|
147
147
|
);
|
|
148
148
|
|
|
@@ -177,4 +177,141 @@ describe("WebAddressAutocomplete", () => {
|
|
|
177
177
|
expect(handleAddressChange).toHaveBeenCalledWith("321 Pine");
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
|
+
|
|
181
|
+
describe("when Google Maps script is not yet loaded", () => {
|
|
182
|
+
interface ScriptElementShape {
|
|
183
|
+
src?: string;
|
|
184
|
+
async?: boolean;
|
|
185
|
+
defer?: boolean;
|
|
186
|
+
onerror?: () => void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface GoogleMapsWindow {
|
|
190
|
+
google?: {
|
|
191
|
+
maps?: {
|
|
192
|
+
places?: {
|
|
193
|
+
Autocomplete?: unknown;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
[key: string]: unknown;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface MinimalDocument {
|
|
201
|
+
createElement: (tag: string) => ScriptElementShape;
|
|
202
|
+
head: {appendChild: (node: ScriptElementShape) => void};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface TestGlobals {
|
|
206
|
+
window?: GoogleMapsWindow;
|
|
207
|
+
document?: MinimalDocument;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const testGlobal = globalThis as TestGlobals;
|
|
211
|
+
const originalWindow = testGlobal.window;
|
|
212
|
+
const originalDocument = testGlobal.document;
|
|
213
|
+
|
|
214
|
+
let createdScript: ScriptElementShape;
|
|
215
|
+
let appendedScripts: ScriptElementShape[];
|
|
216
|
+
let originalConsoleWarn: typeof console.warn;
|
|
217
|
+
let warnings: unknown[][];
|
|
218
|
+
|
|
219
|
+
beforeEach(() => {
|
|
220
|
+
createdScript = {};
|
|
221
|
+
appendedScripts = [];
|
|
222
|
+
warnings = [];
|
|
223
|
+
originalConsoleWarn = console.warn;
|
|
224
|
+
console.warn = (...args: unknown[]): void => {
|
|
225
|
+
warnings.push(args);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
testGlobal.window = {};
|
|
229
|
+
testGlobal.document = {
|
|
230
|
+
createElement: (_tag: string) => {
|
|
231
|
+
createdScript = {};
|
|
232
|
+
return createdScript;
|
|
233
|
+
},
|
|
234
|
+
head: {
|
|
235
|
+
appendChild: (node) => {
|
|
236
|
+
appendedScripts.push(node);
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
afterEach(() => {
|
|
243
|
+
console.warn = originalConsoleWarn;
|
|
244
|
+
testGlobal.window = originalWindow ?? {};
|
|
245
|
+
testGlobal.document = originalDocument;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("loads the Google Maps script and resolves via the global callback", async () => {
|
|
249
|
+
const handleAutoCompleteChange = mock((_arg: AddressInterface) => {});
|
|
250
|
+
|
|
251
|
+
renderWithTheme(
|
|
252
|
+
<WebAddressAutocomplete
|
|
253
|
+
googleMapsApiKey="my-api-key"
|
|
254
|
+
handleAddressChange={() => {}}
|
|
255
|
+
handleAutoCompleteChange={handleAutoCompleteChange}
|
|
256
|
+
inputValue=""
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
// Effect runs synchronously during render, which pushes the script tag to head.
|
|
261
|
+
expect(appendedScripts.length).toBe(1);
|
|
262
|
+
expect(createdScript.src).toContain(
|
|
263
|
+
"https://maps.googleapis.com/maps/api/js?key=my-api-key&libraries=places&callback=initAutocomplete"
|
|
264
|
+
);
|
|
265
|
+
expect(createdScript.async).toBe(true);
|
|
266
|
+
expect(createdScript.defer).toBe(true);
|
|
267
|
+
expect(typeof createdScript.onerror).toBe("function");
|
|
268
|
+
|
|
269
|
+
// The component installed a global callback that resolves loadGooglePlacesScript.
|
|
270
|
+
const win = testGlobal.window as GoogleMapsWindow;
|
|
271
|
+
const cb = win.initAutocomplete;
|
|
272
|
+
expect(typeof cb).toBe("function");
|
|
273
|
+
|
|
274
|
+
// Make Autocomplete available, simulating a successful script load, then fire the callback.
|
|
275
|
+
const autocompleteConstructor = mock((_input: unknown, _opts: unknown) => ({
|
|
276
|
+
addListener: () => {},
|
|
277
|
+
getPlace: () => null,
|
|
278
|
+
}));
|
|
279
|
+
win.google = {
|
|
280
|
+
maps: {
|
|
281
|
+
places: {
|
|
282
|
+
Autocomplete: autocompleteConstructor,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
await act(async () => {
|
|
288
|
+
(cb as () => void)();
|
|
289
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
expect(autocompleteConstructor).toHaveBeenCalled();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("invokes setScriptLoaded(false) and warns when the script fails to load", async () => {
|
|
296
|
+
renderWithTheme(
|
|
297
|
+
<WebAddressAutocomplete
|
|
298
|
+
googleMapsApiKey="my-api-key"
|
|
299
|
+
handleAddressChange={() => {}}
|
|
300
|
+
handleAutoCompleteChange={() => {}}
|
|
301
|
+
inputValue=""
|
|
302
|
+
/>
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
expect(appendedScripts.length).toBe(1);
|
|
306
|
+
expect(typeof createdScript.onerror).toBe("function");
|
|
307
|
+
|
|
308
|
+
await act(async () => {
|
|
309
|
+
createdScript.onerror?.();
|
|
310
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// The .catch path warns and falls back to plain TextField.
|
|
314
|
+
expect(warnings.length).toBeGreaterThan(0);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
180
317
|
});
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import {type ReactElement, useEffect, useRef, useState} from "react";
|
|
2
|
+
import type {TextInput} from "react-native";
|
|
2
3
|
|
|
3
4
|
import type {AddressAutocompleteProps} from "./Common";
|
|
4
5
|
import {GOOGLE_PLACES_API_RESTRICTIONS} from "./Constants";
|
|
5
6
|
import {TextField} from "./TextField";
|
|
6
7
|
import {processAddressComponents} from "./Utilities";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
type WindowWithCallbacks = Window & Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
const loadGooglePlacesScript = (googleMapsApiKey: string, callbackName: string): Promise<void> => {
|
|
9
12
|
return new Promise<void>((resolve, reject): undefined => {
|
|
10
13
|
if (window.google?.maps?.places) {
|
|
11
14
|
resolve();
|
|
12
15
|
return;
|
|
13
16
|
}
|
|
14
|
-
(window as
|
|
17
|
+
(window as unknown as WindowWithCallbacks)[callbackName] = (): void => resolve();
|
|
15
18
|
const script: HTMLScriptElement = document.createElement("script");
|
|
16
19
|
|
|
17
20
|
script.src = `https://maps.googleapis.com/maps/api/js?key=${googleMapsApiKey}&libraries=places&callback=${callbackName}`;
|
|
18
21
|
script.async = true;
|
|
19
22
|
script.defer = true;
|
|
20
|
-
script.onerror = ():
|
|
23
|
+
script.onerror = (): void => {
|
|
24
|
+
reject(new Error("Google Maps script failed to load"));
|
|
25
|
+
};
|
|
21
26
|
document.head.appendChild(script);
|
|
22
27
|
return;
|
|
23
28
|
});
|
|
@@ -32,7 +37,7 @@ export const WebAddressAutocomplete = ({
|
|
|
32
37
|
handleAutoCompleteChange,
|
|
33
38
|
}: AddressAutocompleteProps): ReactElement => {
|
|
34
39
|
const [scriptLoaded, setScriptLoaded] = useState(true);
|
|
35
|
-
const autocompleteInputRef = useRef(null);
|
|
40
|
+
const autocompleteInputRef = useRef<TextInput | null>(null);
|
|
36
41
|
|
|
37
42
|
// Load the Google Maps script and initialize the autocomplete.
|
|
38
43
|
useEffect(() => {
|
|
@@ -65,14 +70,20 @@ export const WebAddressAutocomplete = ({
|
|
|
65
70
|
});
|
|
66
71
|
// Cleanup
|
|
67
72
|
return () => {
|
|
68
|
-
(window as
|
|
73
|
+
(window as unknown as WindowWithCallbacks)[callbackName] = null;
|
|
69
74
|
};
|
|
70
75
|
}, [googleMapsApiKey, includeCounty, handleAutoCompleteChange]);
|
|
71
76
|
|
|
72
77
|
return (
|
|
73
78
|
<TextField
|
|
74
79
|
disabled={disabled}
|
|
75
|
-
inputRef={
|
|
80
|
+
inputRef={
|
|
81
|
+
scriptLoaded
|
|
82
|
+
? (ref: TextInput | null): void => {
|
|
83
|
+
autocompleteInputRef.current = ref;
|
|
84
|
+
}
|
|
85
|
+
: undefined
|
|
86
|
+
}
|
|
76
87
|
onChange={(value): void => {
|
|
77
88
|
handleAddressChange(value);
|
|
78
89
|
}}
|