@krosoft/react 0.0.203 → 0.0.205
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/pwa/PwaUpdater.d.ts +31 -0
- package/dist/pwa/PwaUpdater.d.ts.map +1 -0
- package/dist/pwa/index.d.ts +2 -0
- package/dist/pwa/index.d.ts.map +1 -0
- package/dist/pwa/index.js +35 -0
- package/package.json +8 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface PwaUpdaterProps {
|
|
2
|
+
/** Intervalle entre deux vérifications de mise à jour. Une heure par défaut. */
|
|
3
|
+
checkIntervalMs?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Enregistre le service worker et propose la mise à jour à l'utilisateur.
|
|
7
|
+
*
|
|
8
|
+
* Le nouveau service worker reste en attente : c'est l'action « Actualiser » du toast
|
|
9
|
+
* qui l'active et recharge la page, jamais un rechargement automatique en pleine saisie.
|
|
10
|
+
* Le toast est fermable (croix ou balayage) : l'utilisateur peut reporter la mise à jour,
|
|
11
|
+
* elle sera reproposée au prochain chargement tant qu'elle n'est pas appliquée.
|
|
12
|
+
*
|
|
13
|
+
* L'application hôte doit :
|
|
14
|
+
*
|
|
15
|
+
* - configurer `VitePWA({ registerType: "prompt" })` — en `autoUpdate`, le service
|
|
16
|
+
* worker prend la main tout seul et le toast n'a plus rien à proposer ;
|
|
17
|
+
* - monter `<Sonner />` ;
|
|
18
|
+
* - fournir les clés `pwa.updateAvailable` et `pwa.updateAction`.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { PwaUpdater } from "@krosoft/react/pwa";
|
|
22
|
+
*
|
|
23
|
+
* <PwaUpdater />
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Ne pas y associer `reloadOnServiceWorkerUpdate()` de `@krosoft/core/pwa` : cette
|
|
27
|
+
* fonction est faite pour le mode `autoUpdate` et rechargerait les autres onglets
|
|
28
|
+
* ouverts sans leur demander leur avis.
|
|
29
|
+
*/
|
|
30
|
+
export declare const PwaUpdater: ({ checkIntervalMs }?: PwaUpdaterProps) => null;
|
|
31
|
+
//# sourceMappingURL=PwaUpdater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PwaUpdater.d.ts","sourceRoot":"","sources":["../../src/pwa/PwaUpdater.tsx"],"names":[],"mappings":"AAUA,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GAAI,sBAAiD,eAAoB,KAAG,IAoClG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pwa/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect as n } from "react";
|
|
2
|
+
import { useTranslation as a } from "react-i18next";
|
|
3
|
+
import { toast as u } from "sonner";
|
|
4
|
+
import { useRegisterSW as d } from "virtual:pwa-register/react";
|
|
5
|
+
const f = 3600 * 1e3, v = ({ checkIntervalMs: i = f } = {}) => {
|
|
6
|
+
const { t: e } = a(), {
|
|
7
|
+
needRefresh: [t, r],
|
|
8
|
+
updateServiceWorker: o
|
|
9
|
+
} = d({
|
|
10
|
+
onRegisteredSW(l, s) {
|
|
11
|
+
s && setInterval(() => void s.update(), i);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return n(() => {
|
|
15
|
+
t && u(e("pwa.updateAvailable"), {
|
|
16
|
+
// Aucune expiration : la proposition reste tant que l'utilisateur ne tranche pas.
|
|
17
|
+
duration: 1 / 0,
|
|
18
|
+
// Sans ce bouton, un toast permanent ne se fermerait qu'au balayage sur mobile.
|
|
19
|
+
closeButton: !0,
|
|
20
|
+
dismissible: !0,
|
|
21
|
+
action: {
|
|
22
|
+
label: e("pwa.updateAction"),
|
|
23
|
+
onClick: () => {
|
|
24
|
+
o(!0);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
onDismiss: () => {
|
|
28
|
+
r(!1);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}, [t, r, e, o]), null;
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
v as PwaUpdater
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krosoft/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.205",
|
|
4
4
|
"description": "Krosoft shared React package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"next-themes": ">=0.4.6",
|
|
35
35
|
"react": ">=19.2.8",
|
|
36
36
|
"react-i18next": ">=17.0.12",
|
|
37
|
-
"react-router-dom": ">=7.18.2"
|
|
37
|
+
"react-router-dom": ">=7.18.2",
|
|
38
|
+
"vite-plugin-pwa": ">=1.3.0"
|
|
38
39
|
},
|
|
39
40
|
"peerDependenciesMeta": {
|
|
40
41
|
"next-themes": {
|
|
@@ -42,6 +43,9 @@
|
|
|
42
43
|
},
|
|
43
44
|
"react-router-dom": {
|
|
44
45
|
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"vite-plugin-pwa": {
|
|
48
|
+
"optional": true
|
|
45
49
|
}
|
|
46
50
|
},
|
|
47
51
|
"dependencies": {
|
|
@@ -91,7 +95,7 @@
|
|
|
91
95
|
"zod": "^4.4.3"
|
|
92
96
|
},
|
|
93
97
|
"devDependencies": {
|
|
94
|
-
"@krosoft/core": "^0.0.
|
|
98
|
+
"@krosoft/core": "^0.0.58",
|
|
95
99
|
"@krosoft/tooling-eslint-react": "^0.0.26",
|
|
96
100
|
"@krosoft/tooling-prettier": "^0.0.18",
|
|
97
101
|
"@krosoft/tooling-tsconfig-react": "^0.0.10",
|
|
@@ -117,6 +121,7 @@
|
|
|
117
121
|
"tsc-alias": "^1.9.2",
|
|
118
122
|
"typescript": "^5.9.3",
|
|
119
123
|
"vite": "^6.4.3",
|
|
124
|
+
"vite-plugin-pwa": "^1.3.0",
|
|
120
125
|
"vitest": "^4.1.11"
|
|
121
126
|
}
|
|
122
127
|
}
|