@broberg/pwa 0.2.1 → 0.2.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/dist/react.d.cts +67 -0
- package/dist/react.d.ts +67 -0
- package/package.json +4 -4
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
interface PwaUpdaterOptions {
|
|
4
|
+
/** Service-worker script URL to register. Default `/sw.js`. */
|
|
5
|
+
swUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Register `swUrl` ourselves (manual `sw.js` style). Set `false` when the
|
|
8
|
+
* app already registers the SW (e.g. Serwist's `registerSW` / `@serwist/next`)
|
|
9
|
+
* — the updater then attaches to the existing registration via
|
|
10
|
+
* `navigator.serviceWorker.ready` instead of registering again. Default `true`.
|
|
11
|
+
*/
|
|
12
|
+
register?: boolean;
|
|
13
|
+
/** How often to poll `registration.update()` (ms). `0` disables. Default 60 min. */
|
|
14
|
+
pollIntervalMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Also check for an update when the tab regains focus / becomes visible.
|
|
17
|
+
* A constantly-focused tab never fires `visibilitychange`, so `focus` is the
|
|
18
|
+
* one that catches "user came back to the app". Default `true`.
|
|
19
|
+
*/
|
|
20
|
+
updateOnFocus?: boolean;
|
|
21
|
+
/** Reload the page once the new worker takes control. Default `true`. */
|
|
22
|
+
reloadOnControllerChange?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Consumer guard. When `true` the updater is an inert no-op (registers
|
|
25
|
+
* nothing). Pass your own policy, e.g. `disabled: isNativeCapacitor || isDev`
|
|
26
|
+
* — the package never hardcodes an environment or a `.native` check.
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* React binding for {@link createPwaUpdater}. Returns whether an update is
|
|
33
|
+
* ready plus the `applyUpdate` action. The controller is created once and
|
|
34
|
+
* torn down on unmount.
|
|
35
|
+
*/
|
|
36
|
+
declare function usePwaUpdate(options?: PwaUpdaterOptions): {
|
|
37
|
+
updateReady: boolean;
|
|
38
|
+
applyUpdate: () => void;
|
|
39
|
+
};
|
|
40
|
+
interface PwaUpdateBannerLabels {
|
|
41
|
+
title?: string;
|
|
42
|
+
body?: string;
|
|
43
|
+
update?: string;
|
|
44
|
+
dismiss?: string;
|
|
45
|
+
close?: string;
|
|
46
|
+
}
|
|
47
|
+
interface PwaUpdateBannerProps {
|
|
48
|
+
/** From `usePwaUpdate().updateReady`. Nothing renders when false. */
|
|
49
|
+
updateReady: boolean;
|
|
50
|
+
/** From `usePwaUpdate().applyUpdate`. */
|
|
51
|
+
onUpdate: () => void;
|
|
52
|
+
/** Optional dismiss handler (wired to both "Later" and the close ✕). */
|
|
53
|
+
onDismiss?: () => void;
|
|
54
|
+
/** Override any of the built-in strings (i18n). */
|
|
55
|
+
labels?: PwaUpdateBannerLabels;
|
|
56
|
+
/** Your class(es) — the skeleton carries NO colours or design-system styling. */
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unstyled, accessible "new version available" banner skeleton. It ships
|
|
61
|
+
* structure + a11y + stable testids only; you own the look via `className`
|
|
62
|
+
* and your design tokens. Prefer {@link usePwaUpdate} directly if you'd rather
|
|
63
|
+
* build the UI yourself.
|
|
64
|
+
*/
|
|
65
|
+
declare function PwaUpdateBanner({ updateReady, onUpdate, onDismiss, labels, className, }: PwaUpdateBannerProps): react.JSX.Element | null;
|
|
66
|
+
|
|
67
|
+
export { PwaUpdateBanner, type PwaUpdateBannerLabels, type PwaUpdateBannerProps, usePwaUpdate };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
interface PwaUpdaterOptions {
|
|
4
|
+
/** Service-worker script URL to register. Default `/sw.js`. */
|
|
5
|
+
swUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Register `swUrl` ourselves (manual `sw.js` style). Set `false` when the
|
|
8
|
+
* app already registers the SW (e.g. Serwist's `registerSW` / `@serwist/next`)
|
|
9
|
+
* — the updater then attaches to the existing registration via
|
|
10
|
+
* `navigator.serviceWorker.ready` instead of registering again. Default `true`.
|
|
11
|
+
*/
|
|
12
|
+
register?: boolean;
|
|
13
|
+
/** How often to poll `registration.update()` (ms). `0` disables. Default 60 min. */
|
|
14
|
+
pollIntervalMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Also check for an update when the tab regains focus / becomes visible.
|
|
17
|
+
* A constantly-focused tab never fires `visibilitychange`, so `focus` is the
|
|
18
|
+
* one that catches "user came back to the app". Default `true`.
|
|
19
|
+
*/
|
|
20
|
+
updateOnFocus?: boolean;
|
|
21
|
+
/** Reload the page once the new worker takes control. Default `true`. */
|
|
22
|
+
reloadOnControllerChange?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Consumer guard. When `true` the updater is an inert no-op (registers
|
|
25
|
+
* nothing). Pass your own policy, e.g. `disabled: isNativeCapacitor || isDev`
|
|
26
|
+
* — the package never hardcodes an environment or a `.native` check.
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* React binding for {@link createPwaUpdater}. Returns whether an update is
|
|
33
|
+
* ready plus the `applyUpdate` action. The controller is created once and
|
|
34
|
+
* torn down on unmount.
|
|
35
|
+
*/
|
|
36
|
+
declare function usePwaUpdate(options?: PwaUpdaterOptions): {
|
|
37
|
+
updateReady: boolean;
|
|
38
|
+
applyUpdate: () => void;
|
|
39
|
+
};
|
|
40
|
+
interface PwaUpdateBannerLabels {
|
|
41
|
+
title?: string;
|
|
42
|
+
body?: string;
|
|
43
|
+
update?: string;
|
|
44
|
+
dismiss?: string;
|
|
45
|
+
close?: string;
|
|
46
|
+
}
|
|
47
|
+
interface PwaUpdateBannerProps {
|
|
48
|
+
/** From `usePwaUpdate().updateReady`. Nothing renders when false. */
|
|
49
|
+
updateReady: boolean;
|
|
50
|
+
/** From `usePwaUpdate().applyUpdate`. */
|
|
51
|
+
onUpdate: () => void;
|
|
52
|
+
/** Optional dismiss handler (wired to both "Later" and the close ✕). */
|
|
53
|
+
onDismiss?: () => void;
|
|
54
|
+
/** Override any of the built-in strings (i18n). */
|
|
55
|
+
labels?: PwaUpdateBannerLabels;
|
|
56
|
+
/** Your class(es) — the skeleton carries NO colours or design-system styling. */
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unstyled, accessible "new version available" banner skeleton. It ships
|
|
61
|
+
* structure + a11y + stable testids only; you own the look via `className`
|
|
62
|
+
* and your design tokens. Prefer {@link usePwaUpdate} directly if you'd rather
|
|
63
|
+
* build the UI yourself.
|
|
64
|
+
*/
|
|
65
|
+
declare function PwaUpdateBanner({ updateReady, onUpdate, onDismiss, labels, className, }: PwaUpdateBannerProps): react.JSX.Element | null;
|
|
66
|
+
|
|
67
|
+
export { PwaUpdateBanner, type PwaUpdateBannerLabels, type PwaUpdateBannerProps, usePwaUpdate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/pwa",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Fleet PWA primitive: a framework-agnostic service-worker update-detection controller (new-version-available lifecycle) + a React hook and unstyled banner skeleton + a service-worker skip-waiting helper. Zero runtime deps; ship-dark.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "tsup",
|
|
43
|
+
"build": "rm -rf dist && tsup && node verify-exports.mjs",
|
|
44
44
|
"test": "vitest run",
|
|
45
45
|
"typecheck": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
48
|
+
"preact": ">=10.0.0",
|
|
49
|
+
"react": ">=18.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"react": {
|