@trackunit/react-components 1.18.21 → 1.19.0
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/index.cjs.js
CHANGED
|
@@ -9260,87 +9260,6 @@ const useElevatedState = (initialState, customState) => {
|
|
|
9260
9260
|
return react.useMemo(() => customState ?? [fallbackValue, fallbackSetter], [customState, fallbackValue, fallbackSetter]);
|
|
9261
9261
|
};
|
|
9262
9262
|
|
|
9263
|
-
// ============================================================================
|
|
9264
|
-
// Permission Helper
|
|
9265
|
-
// ============================================================================
|
|
9266
|
-
/**
|
|
9267
|
-
* Query the current geolocation permission state without triggering a prompt.
|
|
9268
|
-
* Returns `null` when the Permissions API is unavailable or the browser throws.
|
|
9269
|
-
*/
|
|
9270
|
-
const queryGeolocationPermission = async () => {
|
|
9271
|
-
try {
|
|
9272
|
-
const status = await navigator.permissions.query({ name: "geolocation" });
|
|
9273
|
-
return status.state;
|
|
9274
|
-
}
|
|
9275
|
-
catch {
|
|
9276
|
-
return null;
|
|
9277
|
-
}
|
|
9278
|
-
};
|
|
9279
|
-
// ============================================================================
|
|
9280
|
-
// Position Helper
|
|
9281
|
-
// ============================================================================
|
|
9282
|
-
/** Wrap `getCurrentPosition` in a Promise that resolves to `GeoJsonPosition | null`. */
|
|
9283
|
-
const getCurrentPosition = () => new Promise(resolve => {
|
|
9284
|
-
if (typeof navigator === "undefined") {
|
|
9285
|
-
resolve(null);
|
|
9286
|
-
return;
|
|
9287
|
-
}
|
|
9288
|
-
navigator.geolocation.getCurrentPosition(pos => resolve([pos.coords.longitude, pos.coords.latitude]), () => resolve(null));
|
|
9289
|
-
});
|
|
9290
|
-
/**
|
|
9291
|
-
* Lightweight geolocation hook.
|
|
9292
|
-
*
|
|
9293
|
-
* By default does nothing on mount — the consumer decides when (and how) to
|
|
9294
|
-
* request a position via `getPosition`. Set `requestOnMount: true` to
|
|
9295
|
-
* automatically populate `position` when permission is already granted.
|
|
9296
|
-
*
|
|
9297
|
-
* @example
|
|
9298
|
-
* ```ts
|
|
9299
|
-
* // Auto-populate position if permission is already granted
|
|
9300
|
-
* const { position, getPosition } = useGeolocation({ requestOnMount: true });
|
|
9301
|
-
*
|
|
9302
|
-
* // User-initiated request (e.g. "My Location" button)
|
|
9303
|
-
* onClick: () => {
|
|
9304
|
-
* void getPosition().then(pos => { if (pos) fitBounds(pos); });
|
|
9305
|
-
* }
|
|
9306
|
-
* ```
|
|
9307
|
-
*/
|
|
9308
|
-
const useGeolocation = (options) => {
|
|
9309
|
-
const [position, setPosition] = react.useState(null);
|
|
9310
|
-
const getPosition = react.useCallback(async (opts) => {
|
|
9311
|
-
const prompt = opts?.prompt !== false;
|
|
9312
|
-
if (!prompt) {
|
|
9313
|
-
const permissionState = await queryGeolocationPermission();
|
|
9314
|
-
if (permissionState !== "granted")
|
|
9315
|
-
return null;
|
|
9316
|
-
}
|
|
9317
|
-
const pos = await getCurrentPosition();
|
|
9318
|
-
if (pos !== null) {
|
|
9319
|
-
setPosition(pos);
|
|
9320
|
-
}
|
|
9321
|
-
return pos;
|
|
9322
|
-
}, []);
|
|
9323
|
-
useWatch({
|
|
9324
|
-
value: options?.requestOnMount ?? false,
|
|
9325
|
-
onChange: () => {
|
|
9326
|
-
void queryGeolocationPermission()
|
|
9327
|
-
.then(state => {
|
|
9328
|
-
if (state !== "granted")
|
|
9329
|
-
return;
|
|
9330
|
-
return getCurrentPosition();
|
|
9331
|
-
})
|
|
9332
|
-
.then(pos => {
|
|
9333
|
-
if (pos !== null && pos !== undefined) {
|
|
9334
|
-
setPosition(pos);
|
|
9335
|
-
}
|
|
9336
|
-
});
|
|
9337
|
-
},
|
|
9338
|
-
immediate: true,
|
|
9339
|
-
skip: options?.requestOnMount !== true,
|
|
9340
|
-
});
|
|
9341
|
-
return react.useMemo(() => ({ position, getPosition }), [position, getPosition]);
|
|
9342
|
-
};
|
|
9343
|
-
|
|
9344
9263
|
/**
|
|
9345
9264
|
* The useHover hook returns a onMouseEnter, onMouseLeave and a boolean indicating whether the element is being hovered.
|
|
9346
9265
|
* The boolean will be true if the element is being hovered, and false if it is not.
|
|
@@ -10347,7 +10266,6 @@ exports.useDebounce = useDebounce;
|
|
|
10347
10266
|
exports.useDevicePixelRatio = useDevicePixelRatio;
|
|
10348
10267
|
exports.useElevatedReducer = useElevatedReducer;
|
|
10349
10268
|
exports.useElevatedState = useElevatedState;
|
|
10350
|
-
exports.useGeolocation = useGeolocation;
|
|
10351
10269
|
exports.useGridAreas = useGridAreas;
|
|
10352
10270
|
exports.useHover = useHover;
|
|
10353
10271
|
exports.useInfiniteScroll = useInfiniteScroll;
|
package/index.esm.js
CHANGED
|
@@ -9258,87 +9258,6 @@ const useElevatedState = (initialState, customState) => {
|
|
|
9258
9258
|
return useMemo(() => customState ?? [fallbackValue, fallbackSetter], [customState, fallbackValue, fallbackSetter]);
|
|
9259
9259
|
};
|
|
9260
9260
|
|
|
9261
|
-
// ============================================================================
|
|
9262
|
-
// Permission Helper
|
|
9263
|
-
// ============================================================================
|
|
9264
|
-
/**
|
|
9265
|
-
* Query the current geolocation permission state without triggering a prompt.
|
|
9266
|
-
* Returns `null` when the Permissions API is unavailable or the browser throws.
|
|
9267
|
-
*/
|
|
9268
|
-
const queryGeolocationPermission = async () => {
|
|
9269
|
-
try {
|
|
9270
|
-
const status = await navigator.permissions.query({ name: "geolocation" });
|
|
9271
|
-
return status.state;
|
|
9272
|
-
}
|
|
9273
|
-
catch {
|
|
9274
|
-
return null;
|
|
9275
|
-
}
|
|
9276
|
-
};
|
|
9277
|
-
// ============================================================================
|
|
9278
|
-
// Position Helper
|
|
9279
|
-
// ============================================================================
|
|
9280
|
-
/** Wrap `getCurrentPosition` in a Promise that resolves to `GeoJsonPosition | null`. */
|
|
9281
|
-
const getCurrentPosition = () => new Promise(resolve => {
|
|
9282
|
-
if (typeof navigator === "undefined") {
|
|
9283
|
-
resolve(null);
|
|
9284
|
-
return;
|
|
9285
|
-
}
|
|
9286
|
-
navigator.geolocation.getCurrentPosition(pos => resolve([pos.coords.longitude, pos.coords.latitude]), () => resolve(null));
|
|
9287
|
-
});
|
|
9288
|
-
/**
|
|
9289
|
-
* Lightweight geolocation hook.
|
|
9290
|
-
*
|
|
9291
|
-
* By default does nothing on mount — the consumer decides when (and how) to
|
|
9292
|
-
* request a position via `getPosition`. Set `requestOnMount: true` to
|
|
9293
|
-
* automatically populate `position` when permission is already granted.
|
|
9294
|
-
*
|
|
9295
|
-
* @example
|
|
9296
|
-
* ```ts
|
|
9297
|
-
* // Auto-populate position if permission is already granted
|
|
9298
|
-
* const { position, getPosition } = useGeolocation({ requestOnMount: true });
|
|
9299
|
-
*
|
|
9300
|
-
* // User-initiated request (e.g. "My Location" button)
|
|
9301
|
-
* onClick: () => {
|
|
9302
|
-
* void getPosition().then(pos => { if (pos) fitBounds(pos); });
|
|
9303
|
-
* }
|
|
9304
|
-
* ```
|
|
9305
|
-
*/
|
|
9306
|
-
const useGeolocation = (options) => {
|
|
9307
|
-
const [position, setPosition] = useState(null);
|
|
9308
|
-
const getPosition = useCallback(async (opts) => {
|
|
9309
|
-
const prompt = opts?.prompt !== false;
|
|
9310
|
-
if (!prompt) {
|
|
9311
|
-
const permissionState = await queryGeolocationPermission();
|
|
9312
|
-
if (permissionState !== "granted")
|
|
9313
|
-
return null;
|
|
9314
|
-
}
|
|
9315
|
-
const pos = await getCurrentPosition();
|
|
9316
|
-
if (pos !== null) {
|
|
9317
|
-
setPosition(pos);
|
|
9318
|
-
}
|
|
9319
|
-
return pos;
|
|
9320
|
-
}, []);
|
|
9321
|
-
useWatch({
|
|
9322
|
-
value: options?.requestOnMount ?? false,
|
|
9323
|
-
onChange: () => {
|
|
9324
|
-
void queryGeolocationPermission()
|
|
9325
|
-
.then(state => {
|
|
9326
|
-
if (state !== "granted")
|
|
9327
|
-
return;
|
|
9328
|
-
return getCurrentPosition();
|
|
9329
|
-
})
|
|
9330
|
-
.then(pos => {
|
|
9331
|
-
if (pos !== null && pos !== undefined) {
|
|
9332
|
-
setPosition(pos);
|
|
9333
|
-
}
|
|
9334
|
-
});
|
|
9335
|
-
},
|
|
9336
|
-
immediate: true,
|
|
9337
|
-
skip: options?.requestOnMount !== true,
|
|
9338
|
-
});
|
|
9339
|
-
return useMemo(() => ({ position, getPosition }), [position, getPosition]);
|
|
9340
|
-
};
|
|
9341
|
-
|
|
9342
9261
|
/**
|
|
9343
9262
|
* The useHover hook returns a onMouseEnter, onMouseLeave and a boolean indicating whether the element is being hovered.
|
|
9344
9263
|
* The boolean will be true if the element is being hovered, and false if it is not.
|
|
@@ -10206,4 +10125,4 @@ const useWindowActivity = ({ onFocus, onBlur, skip = false } = { onBlur: undefin
|
|
|
10206
10125
|
return useMemo(() => ({ focused }), [focused]);
|
|
10207
10126
|
};
|
|
10208
10127
|
|
|
10209
|
-
export { ActionRenderer, Alert, Badge, Breadcrumb, BreadcrumbContainer, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, DEFAULT_SKELETON_PREFERENCE_CARD_PROPS, DetailsList, EmptyState, EmptyValue, ExternalLink, GridAreas, Heading, Highlight, HorizontalOverflowScroller, Icon, IconButton, Indicator, KPI, KPICard, KPICardSkeleton, KPISkeleton, List, ListItem, MenuDivider, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, PageHeaderKpiMetrics, PageHeaderSecondaryActions, PageHeaderTitle, Pagination, Polygon, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Portal, PreferenceCard, PreferenceCardSkeleton, Prompt, ROLE_CARD, SectionHeader, SegmentedValueBar, Sidebar, SkeletonBlock, SkeletonLabel, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, ToggleGroup, Tooltip, TrendIndicator, TrendIndicators, ValueBar, ZStack, createGrid, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaContainerStyles, cvaContentContainer, cvaContentWrapper, cvaDescriptionCard, cvaIconBackground, cvaIconButton, cvaImgStyles, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaInputContainer, cvaInteractableItem, cvaList, cvaListContainer, cvaListItem$1 as cvaListItem, cvaMenu, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, cvaMenuList, cvaMenuListDivider, cvaMenuListItem, cvaMenuListMultiSelect, cvaPageHeader, cvaPageHeaderContainer, cvaPageHeaderHeading, cvaPreferenceCard, cvaTitleCard, cvaToggleGroup, cvaToggleGroupWithSlidingBackground, cvaToggleItem, cvaToggleItemContent, cvaToggleItemText, cvaZStackContainer, cvaZStackItem, defaultPageSize, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, noPagination, preferenceCardGrid, useBidirectionalScroll, useClickOutside, useContainerBreakpoints, useContinuousTimeout, useCopyToClipboard, useCursorUrlSync, useCustomEncoding, useDebounce, useDevicePixelRatio, useElevatedReducer, useElevatedState,
|
|
10128
|
+
export { ActionRenderer, Alert, Badge, Breadcrumb, BreadcrumbContainer, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, DEFAULT_SKELETON_PREFERENCE_CARD_PROPS, DetailsList, EmptyState, EmptyValue, ExternalLink, GridAreas, Heading, Highlight, HorizontalOverflowScroller, Icon, IconButton, Indicator, KPI, KPICard, KPICardSkeleton, KPISkeleton, List, ListItem, MenuDivider, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, PageHeaderKpiMetrics, PageHeaderSecondaryActions, PageHeaderTitle, Pagination, Polygon, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Portal, PreferenceCard, PreferenceCardSkeleton, Prompt, ROLE_CARD, SectionHeader, SegmentedValueBar, Sidebar, SkeletonBlock, SkeletonLabel, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, ToggleGroup, Tooltip, TrendIndicator, TrendIndicators, ValueBar, ZStack, createGrid, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaContainerStyles, cvaContentContainer, cvaContentWrapper, cvaDescriptionCard, cvaIconBackground, cvaIconButton, cvaImgStyles, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaInputContainer, cvaInteractableItem, cvaList, cvaListContainer, cvaListItem$1 as cvaListItem, cvaMenu, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, cvaMenuList, cvaMenuListDivider, cvaMenuListItem, cvaMenuListMultiSelect, cvaPageHeader, cvaPageHeaderContainer, cvaPageHeaderHeading, cvaPreferenceCard, cvaTitleCard, cvaToggleGroup, cvaToggleGroupWithSlidingBackground, cvaToggleItem, cvaToggleItemContent, cvaToggleItemText, cvaZStackContainer, cvaZStackItem, defaultPageSize, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, noPagination, preferenceCardGrid, useBidirectionalScroll, useClickOutside, useContainerBreakpoints, useContinuousTimeout, useCopyToClipboard, useCursorUrlSync, useCustomEncoding, useDebounce, useDevicePixelRatio, useElevatedReducer, useElevatedState, useGridAreas, useHover, useInfiniteScroll, useIsFirstRender, useIsFullscreen, useIsTextTruncated, useKeyboardShortcut, useList, useListItemHeight, useLocalStorage, useLocalStorageReducer, useMeasure, useMergeRefs, useModifierKey, useOverflowItems, usePopoverContext, usePrevious, usePrompt, useRandomCSSLengths, useRelayPagination, useResize, useScrollBlock, useScrollDetection, useSelfUpdatingRef, useSessionStorage, useSessionStorageReducer, useTextSearch, useTimeout, useViewportBreakpoints, useWatch, useWindowActivity };
|
package/package.json
CHANGED
|
@@ -161,11 +161,6 @@ type BrowserShortcutKeys<TShortcut> = TShortcut extends BrowserReservedModC ? "m
|
|
|
161
161
|
type BrowserReservedErrorMessage<TShortcut> = ReservedMessage<"Browser", BrowserShortcutKeys<TShortcut>, BrowserShortcutFeature<TShortcut>>;
|
|
162
162
|
/** Union of all reserved shortcuts (app + browser) */
|
|
163
163
|
type ReservedShortcut = AppReservedShortcut | BrowserReservedShortcut;
|
|
164
|
-
/**
|
|
165
|
-
* Type predicate that returns true if the shortcut is reserved.
|
|
166
|
-
* Reserved shortcuts cannot be used without explicit ts-expect-error.
|
|
167
|
-
*/
|
|
168
|
-
export type IsReservedShortcut<TShortcut extends ShortcutDefinition> = TShortcut extends ReservedShortcut ? true : false;
|
|
169
164
|
/** Maps any reserved shortcut to its specific error message */
|
|
170
165
|
type ReservedErrorMessage<TShortcut> = TShortcut extends AppReservedShortcut ? AppReservedErrorMessage<TShortcut> : TShortcut extends BrowserReservedShortcut ? BrowserReservedErrorMessage<TShortcut> : never;
|
|
171
166
|
/**
|
package/src/index.d.ts
CHANGED
|
@@ -121,7 +121,6 @@ export * from "./hooks/useDebounce";
|
|
|
121
121
|
export * from "./hooks/useDevicePixelRatio";
|
|
122
122
|
export * from "./hooks/useElevatedReducer";
|
|
123
123
|
export * from "./hooks/useElevatedState";
|
|
124
|
-
export * from "./hooks/useGeolocation";
|
|
125
124
|
export * from "./hooks/useHover";
|
|
126
125
|
export * from "./hooks/useInfiniteScroll";
|
|
127
126
|
export * from "./hooks/useIsFirstRender";
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
type GeoJsonPosition = [number, number] | [number, number, number];
|
|
2
|
-
type UseGeolocationReturn = Readonly<{
|
|
3
|
-
/** Last successfully resolved position as [longitude, latitude], or null if no position has been obtained yet */
|
|
4
|
-
position: GeoJsonPosition | null;
|
|
5
|
-
/**
|
|
6
|
-
* Get the current geographic position.
|
|
7
|
-
*
|
|
8
|
-
* - `prompt: true` (default) — calls `getCurrentPosition` directly, which may
|
|
9
|
-
* show the browser permission dialog if permission hasn't been granted yet.
|
|
10
|
-
* Intended for user-initiated actions (e.g. "My Location" button).
|
|
11
|
-
*
|
|
12
|
-
* - `prompt: false` — checks the permission state first and only retrieves the
|
|
13
|
-
* position if permission is already `"granted"`. Never triggers a prompt.
|
|
14
|
-
* Returns `null` when permission is not granted or the API is unavailable.
|
|
15
|
-
*
|
|
16
|
-
* On success, also updates the `position` state so dependent renders pick it up.
|
|
17
|
-
*/
|
|
18
|
-
getPosition: (options?: Readonly<{
|
|
19
|
-
prompt?: boolean;
|
|
20
|
-
}>) => Promise<GeoJsonPosition | null>;
|
|
21
|
-
}>;
|
|
22
|
-
type UseGeolocationOptions = Readonly<{
|
|
23
|
-
/**
|
|
24
|
-
* When `true`, passively checks geolocation permission on mount and
|
|
25
|
-
* populates `position` if permission is already `"granted"`.
|
|
26
|
-
* Never triggers a browser prompt.
|
|
27
|
-
*
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
requestOnMount?: boolean;
|
|
31
|
-
}>;
|
|
32
|
-
/**
|
|
33
|
-
* Lightweight geolocation hook.
|
|
34
|
-
*
|
|
35
|
-
* By default does nothing on mount — the consumer decides when (and how) to
|
|
36
|
-
* request a position via `getPosition`. Set `requestOnMount: true` to
|
|
37
|
-
* automatically populate `position` when permission is already granted.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* // Auto-populate position if permission is already granted
|
|
42
|
-
* const { position, getPosition } = useGeolocation({ requestOnMount: true });
|
|
43
|
-
*
|
|
44
|
-
* // User-initiated request (e.g. "My Location" button)
|
|
45
|
-
* onClick: () => {
|
|
46
|
-
* void getPosition().then(pos => { if (pos) fitBounds(pos); });
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare const useGeolocation: (options?: UseGeolocationOptions) => UseGeolocationReturn;
|
|
51
|
-
export {};
|