@inglorious/web 6.27.1 → 6.29.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/README.md +263 -203
- package/package.json +68 -56
- package/src/device/biometrics/index.js +86 -0
- package/src/device/compass/handlers.js +163 -0
- package/src/{sensors → device}/element-size/handlers.js +2 -2
- package/src/device/geolocation/index.js +120 -0
- package/src/{haptics → device/haptics}/index.js +1 -1
- package/src/device/local-notifications/index.js +133 -0
- package/src/{sensors → device}/media-query/handlers.js +2 -2
- package/src/{sensors → device}/network-status/handlers.js +1 -1
- package/src/{sensors → device}/page-visibility/handlers.js +1 -1
- package/src/{share → device/share}/index.js +1 -1
- package/src/{mobile → device/storage}/index.js +29 -17
- package/src/mount.js +1 -1
- package/src/{app-links → native/app-links}/index.js +1 -1
- package/src/{back-button → native/back-button}/index.js +1 -1
- package/src/native/index.js +17 -0
- package/src/{live-update → native/live-update}/index.js +1 -1
- package/src/{system-bars → native/system-bars}/index.js +1 -1
- package/src/{native-update → native/update}/index.js +1 -1
- package/types/device/biometrics.d.ts +51 -0
- package/types/{sensors → device}/compass.d.ts +0 -2
- package/types/{sensors → device}/geolocation.d.ts +25 -7
- package/types/device/local-notifications.d.ts +76 -0
- package/types/{mobile.d.ts → device/storage.d.ts} +12 -2
- package/types/{app-links.d.ts → native/app-links.d.ts} +1 -1
- package/types/native/index.d.ts +1 -0
- package/types/{live-update.d.ts → native/live-update.d.ts} +1 -1
- package/types/{native-update.d.ts → native/update.d.ts} +1 -1
- package/src/sensors/compass/handlers.js +0 -209
- package/src/sensors/geolocation/handlers.js +0 -168
- package/src/sensors/geolocation/index.js +0 -3
- /package/src/{sensors → device}/compass/index.js +0 -0
- /package/src/{sensors → device}/element-size/index.js +0 -0
- /package/src/{keyboard → device/keyboard}/index.js +0 -0
- /package/src/{sensors → device}/media-query/index.js +0 -0
- /package/src/{sensors → device}/network-status/index.js +0 -0
- /package/src/{sensors → device}/page-visibility/index.js +0 -0
- /package/types/{sensors → device}/element-size.d.ts +0 -0
- /package/types/{haptics.d.ts → device/haptics.d.ts} +0 -0
- /package/types/{keyboard.d.ts → device/keyboard.d.ts} +0 -0
- /package/types/{sensors → device}/media-query.d.ts +0 -0
- /package/types/{sensors → device}/network-status.d.ts +0 -0
- /package/types/{sensors → device}/page-visibility.d.ts +0 -0
- /package/types/{share.d.ts → device/share.d.ts} +0 -0
- /package/types/{back-button.d.ts → native/back-button.d.ts} +0 -0
- /package/types/{system-bars.d.ts → native/system-bars.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1276,16 +1276,21 @@ For ready-made UI primitives (controls, data display, navigation, feedback, layo
|
|
|
1276
1276
|
|
|
1277
1277
|
---
|
|
1278
1278
|
|
|
1279
|
-
##
|
|
1279
|
+
## Device
|
|
1280
1280
|
|
|
1281
|
-
`@inglorious/web
|
|
1281
|
+
`@inglorious/web/device/*` holds what the phone or browser can sense or do. Each works in a browser through its web API. In a native app, the ones with a Capacitor plugin use it, once you hand it over as `plugin`. Entity types answer to their own entity (`#id:event`) and keep listeners, observers and watches outside it. Besides the ones below, `ElementSize`, `MediaQuery`, `NetworkStatus` and `PageVisibility` follow an element's size, a media query, the connection and the page's visibility.
|
|
1282
|
+
|
|
1283
|
+
### Geolocation
|
|
1284
|
+
|
|
1285
|
+
`createGeolocation` from `@inglorious/web/device/geolocation` returns the type that keeps the device's position in the store. In a native app it uses [`@capacitor/geolocation`](https://capacitorjs.com/docs/apis/geolocation) when given as `plugin`, so iOS asks for the location once, for the app; elsewhere it uses `navigator.geolocation`.
|
|
1282
1286
|
|
|
1283
1287
|
```javascript
|
|
1284
1288
|
import { createStore } from "@inglorious/store"
|
|
1285
|
-
import { Geolocation } from "@
|
|
1289
|
+
import { Geolocation as GeolocationPlugin } from "@capacitor/geolocation"
|
|
1290
|
+
import { createGeolocation } from "@inglorious/web/device/geolocation"
|
|
1286
1291
|
|
|
1287
1292
|
const store = createStore({
|
|
1288
|
-
types: { Geolocation },
|
|
1293
|
+
types: { Geolocation: createGeolocation({ plugin: GeolocationPlugin }) },
|
|
1289
1294
|
autoCreateEntities: true,
|
|
1290
1295
|
})
|
|
1291
1296
|
|
|
@@ -1295,12 +1300,11 @@ store.getState().geolocation
|
|
|
1295
1300
|
|
|
1296
1301
|
The entity state contains:
|
|
1297
1302
|
|
|
1298
|
-
- `isSupported` — whether
|
|
1303
|
+
- `isSupported` — whether the position can be read here
|
|
1299
1304
|
- `isLoading` — whether a current-position request or first watch result is pending
|
|
1300
1305
|
- `isWatching` — whether a geolocation watch is active
|
|
1301
1306
|
- `position` — the latest normalized `{ coords, timestamp }` value
|
|
1302
1307
|
- `error` — the latest normalized `{ code, message }` error
|
|
1303
|
-
- `watchId` — the active browser watch id, or `null`
|
|
1304
1308
|
|
|
1305
1309
|
Events:
|
|
1306
1310
|
|
|
@@ -1309,16 +1313,16 @@ Events:
|
|
|
1309
1313
|
- `geolocationUnwatch` — stop the active watch
|
|
1310
1314
|
|
|
1311
1315
|
```javascript
|
|
1312
|
-
api.notify("geolocationRequest", {
|
|
1316
|
+
api.notify("#geolocation:geolocationRequest", {
|
|
1313
1317
|
enableHighAccuracy: true,
|
|
1314
1318
|
timeout: 5000,
|
|
1315
1319
|
})
|
|
1316
1320
|
|
|
1317
|
-
api.notify("geolocationWatch")
|
|
1318
|
-
api.notify("geolocationUnwatch")
|
|
1321
|
+
api.notify("#geolocation:geolocationWatch")
|
|
1322
|
+
api.notify("#geolocation:geolocationUnwatch")
|
|
1319
1323
|
```
|
|
1320
1324
|
|
|
1321
|
-
|
|
1325
|
+
#### Example: Show current location
|
|
1322
1326
|
|
|
1323
1327
|
```javascript
|
|
1324
1328
|
import { mount, html } from "@inglorious/web"
|
|
@@ -1347,17 +1351,17 @@ const renderApp = (api) => {
|
|
|
1347
1351
|
<p>Error: ${geolocation.error ? geolocation.error.message : "none"}</p>
|
|
1348
1352
|
<button
|
|
1349
1353
|
@click=${() =>
|
|
1350
|
-
api.notify("geolocationRequest", {
|
|
1354
|
+
api.notify("#geolocation:geolocationRequest", {
|
|
1351
1355
|
enableHighAccuracy: true,
|
|
1352
1356
|
timeout: 5000,
|
|
1353
1357
|
})}
|
|
1354
1358
|
>
|
|
1355
1359
|
Request Current Position
|
|
1356
1360
|
</button>
|
|
1357
|
-
<button @click=${() => api.notify("geolocationWatch")}>
|
|
1361
|
+
<button @click=${() => api.notify("#geolocation:geolocationWatch")}>
|
|
1358
1362
|
Start Watch
|
|
1359
1363
|
</button>
|
|
1360
|
-
<button @click=${() => api.notify("geolocationUnwatch")}>
|
|
1364
|
+
<button @click=${() => api.notify("#geolocation:geolocationUnwatch")}>
|
|
1361
1365
|
Stop Watch
|
|
1362
1366
|
</button>
|
|
1363
1367
|
</section>
|
|
@@ -1367,9 +1371,7 @@ const renderApp = (api) => {
|
|
|
1367
1371
|
mount(store, renderApp, document.getElementById("root"))
|
|
1368
1372
|
```
|
|
1369
1373
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
## Compass
|
|
1374
|
+
### Compass
|
|
1373
1375
|
|
|
1374
1376
|
`@inglorious/web` also includes a `Compass` type for managing device orientation and heading state inside the store.
|
|
1375
1377
|
|
|
@@ -1407,12 +1409,12 @@ Events:
|
|
|
1407
1409
|
- `compassError` — store a normalized compass error
|
|
1408
1410
|
|
|
1409
1411
|
```javascript
|
|
1410
|
-
api.notify("compassPermissionsRequest")
|
|
1411
|
-
api.notify("compassWatch")
|
|
1412
|
-
api.notify("compassUnwatch")
|
|
1412
|
+
api.notify("#compass:compassPermissionsRequest")
|
|
1413
|
+
api.notify("#compass:compassWatch")
|
|
1414
|
+
api.notify("#compass:compassUnwatch")
|
|
1413
1415
|
```
|
|
1414
1416
|
|
|
1415
|
-
|
|
1417
|
+
#### Example: Show heading and request permission
|
|
1416
1418
|
|
|
1417
1419
|
```javascript
|
|
1418
1420
|
import { mount, html } from "@inglorious/web"
|
|
@@ -1439,11 +1441,15 @@ const renderApp = (api) => {
|
|
|
1439
1441
|
}
|
|
1440
1442
|
</p>
|
|
1441
1443
|
<p>Error: ${compass.error ? compass.error.message : "none"}</p>
|
|
1442
|
-
<button @click=${() => api.notify("compassPermissionsRequest")}>
|
|
1444
|
+
<button @click=${() => api.notify("#compass:compassPermissionsRequest")}>
|
|
1443
1445
|
Request Permission
|
|
1444
1446
|
</button>
|
|
1445
|
-
<button @click=${() => api.notify("compassWatch")}>
|
|
1446
|
-
|
|
1447
|
+
<button @click=${() => api.notify("#compass:compassWatch")}>
|
|
1448
|
+
Start Compass
|
|
1449
|
+
</button>
|
|
1450
|
+
<button @click=${() => api.notify("#compass:compassUnwatch")}>
|
|
1451
|
+
Stop Compass
|
|
1452
|
+
</button>
|
|
1447
1453
|
</section>
|
|
1448
1454
|
`
|
|
1449
1455
|
}
|
|
@@ -1451,188 +1457,169 @@ const renderApp = (api) => {
|
|
|
1451
1457
|
mount(store, renderApp, document.getElementById("root"))
|
|
1452
1458
|
```
|
|
1453
1459
|
|
|
1454
|
-
|
|
1460
|
+
### Share
|
|
1455
1461
|
|
|
1456
|
-
|
|
1462
|
+
`@inglorious/web/device/share` is the type behind a share button. `share` hands a title, a text, a link or a file to whatever the device does best, and the entity says what happened:
|
|
1457
1463
|
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
- at launch, before anything is touched;
|
|
1463
|
-
- each time the app goes to the background or comes back to the foreground.
|
|
1464
|
-
|
|
1465
|
-
It also checks for a new version every hour and on every return to the foreground: a phone suspends an installed PWA rather than closing it, so the browser's own check may never come.
|
|
1464
|
+
- in a native app, the system's share sheet, through [`@capacitor/share`](https://capacitorjs.com/docs/apis/share) when you hand it over;
|
|
1465
|
+
- in a browser, a file (a `url` with a `fileName`) downloads, since a browser has nowhere better to put it;
|
|
1466
|
+
- otherwise the browser's share sheet where there is one (Web Share API), else the link is copied.
|
|
1466
1467
|
|
|
1467
1468
|
```javascript
|
|
1468
|
-
import {
|
|
1469
|
-
import {
|
|
1470
|
-
import { registerSW } from "virtual:pwa-register"
|
|
1469
|
+
import { Share } from "@capacitor/share"
|
|
1470
|
+
import { createShare } from "@inglorious/web/device/share"
|
|
1471
1471
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1472
|
+
const types = { Share: createShare({ plugin: Share }) }
|
|
1473
|
+
|
|
1474
|
+
api.notify("#share:share", {
|
|
1475
|
+
title: "My job",
|
|
1476
|
+
url: "https://example.com/jobs/1",
|
|
1477
|
+
})
|
|
1478
|
+
api.notify("#share:share", {
|
|
1479
|
+
title: "Wedding",
|
|
1480
|
+
url: icsUrl,
|
|
1481
|
+
fileName: "wedding.ics",
|
|
1482
|
+
})
|
|
1479
1483
|
```
|
|
1480
1484
|
|
|
1481
|
-
|
|
1485
|
+
`result` is `"shared"`, `"downloaded"`, `"copied"` or `"cancelled"`: closing the sheet is not an error. `status` and `error` (`"unsupported"` or `"failed"`) come from `handleRequest`. `canShare` says whether a link can be shared at all, to hide the button where it can't.
|
|
1482
1486
|
|
|
1483
|
-
###
|
|
1487
|
+
### Haptics
|
|
1484
1488
|
|
|
1485
|
-
|
|
1489
|
+
`@inglorious/web/device/haptics` plays taps the user can feel. In a native app it uses the system's haptics through [`@capacitor/haptics`](https://capacitorjs.com/docs/apis/haptics), once you hand the plugin over. Elsewhere it vibrates where the browser can (Chrome on Android), once the user has tapped the page; iOS browsers stay silent. Every call returns whether it played.
|
|
1486
1490
|
|
|
1487
1491
|
```javascript
|
|
1488
|
-
import {
|
|
1492
|
+
import { Haptics } from "@capacitor/haptics"
|
|
1493
|
+
import { haptics } from "@inglorious/web/device/haptics"
|
|
1489
1494
|
|
|
1490
|
-
|
|
1495
|
+
haptics.use(Haptics)
|
|
1491
1496
|
|
|
1492
|
-
|
|
1497
|
+
haptics.selection() // a toggle flipped, a threshold crossed
|
|
1498
|
+
haptics.impact("heavy") // "light", "medium" (default) or "heavy"
|
|
1499
|
+
haptics.notification("error") // "success" (default), "warning" or "error"
|
|
1493
1500
|
```
|
|
1494
1501
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
- `isUpdateReady` — a new version is waiting for the next reload
|
|
1502
|
+
Inglorious UI plays them too: `PullToRefresh` gives a tick when letting go would refresh.
|
|
1498
1503
|
|
|
1499
|
-
|
|
1504
|
+
### Local Notifications
|
|
1500
1505
|
|
|
1501
|
-
|
|
1502
|
-
- `pwaUpdateApply` — moves over to the waiting version now, reloading the page
|
|
1506
|
+
`createLocalNotifications` from `@inglorious/web/device/local-notifications` is the type behind reminders the device shows on its own, such as "your job starts in an hour". In a native app they go through [`@capacitor/local-notifications`](https://capacitorjs.com/docs/apis/local-notifications), once you hand the plugin over, and show even with the app closed. In a browser they show only while the page is open, through the Notification API.
|
|
1503
1507
|
|
|
1504
1508
|
```javascript
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1509
|
+
import { LocalNotifications } from "@capacitor/local-notifications"
|
|
1510
|
+
import { createLocalNotifications } from "@inglorious/web/device/local-notifications"
|
|
1511
|
+
|
|
1512
|
+
const types = {
|
|
1513
|
+
Reminders: createLocalNotifications({ plugin: LocalNotifications }),
|
|
1514
|
+
}
|
|
1515
|
+
const entities = { reminders: { type: "Reminders" } }
|
|
1516
|
+
|
|
1517
|
+
api.notify("#reminders:localNotificationSchedule", {
|
|
1518
|
+
id: 1,
|
|
1519
|
+
title: "Wedding in an hour",
|
|
1520
|
+
body: "Villa Erba, Cernobbio",
|
|
1521
|
+
at: new Date(start - HOUR),
|
|
1522
|
+
url: "/jobs/1",
|
|
1523
|
+
})
|
|
1524
|
+
api.notify("#reminders:localNotificationCancel", 1)
|
|
1513
1525
|
```
|
|
1514
1526
|
|
|
1515
|
-
|
|
1527
|
+
The entity's `permission` is `"granted"`, `"denied"`, `"prompt"` or `"unsupported"`, and `null` until the device says. `localNotificationsAsk` brings up the system's dialog: send it from a tap, which a browser requires.
|
|
1516
1528
|
|
|
1517
|
-
|
|
1529
|
+
An `id` is a whole number, which the app chooses so it can cancel the reminder later. A tap on a reminder with a `url` navigates there, through `onTap(url, api)` in the config, by default `#router:navigate`.
|
|
1518
1530
|
|
|
1519
|
-
|
|
1531
|
+
#### Secrets
|
|
1520
1532
|
|
|
1521
|
-
|
|
1533
|
+
`createSecureStorage` keeps what must stay private, such as a session's tokens, in the Keychain (iOS) or Keystore (Android), through the same [`@capgo/capacitor-native-biometric`](https://github.com/Cap-go/capacitor-native-biometric) plugin. A browser has nothing safer, so there it uses `localStorage`. It works wherever `createNativeStorage` does:
|
|
1522
1534
|
|
|
1523
1535
|
```javascript
|
|
1524
|
-
import {
|
|
1525
|
-
import {
|
|
1526
|
-
createNativeUpdate,
|
|
1527
|
-
watchNativeUpdate,
|
|
1528
|
-
} from "@inglorious/web/native-update"
|
|
1536
|
+
import { NativeBiometric } from "@capgo/capacitor-native-biometric"
|
|
1537
|
+
import { createSecureStorage } from "@inglorious/web/device/storage"
|
|
1529
1538
|
|
|
1530
|
-
const
|
|
1531
|
-
const entities = { nativeUpdate: { type: "NativeUpdate" } }
|
|
1539
|
+
const secrets = createSecureStorage({ plugin: NativeBiometric })
|
|
1532
1540
|
|
|
1533
|
-
|
|
1541
|
+
createClient(url, key, { auth: { storage: secrets } })
|
|
1534
1542
|
```
|
|
1535
1543
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
The adapter says where the minimum lives: `requirement(platform)` resolves to `{ minBuild, storeUrl }`, or `null` for no minimum. `supabaseNativeUpdate` from `@inglorious/supabase` reads it from a table.
|
|
1544
|
+
### Biometrics
|
|
1539
1545
|
|
|
1540
|
-
|
|
1546
|
+
`createBiometrics` from `@inglorious/web/device/biometrics` is the type behind "unlock with Face ID". In a native app, `verify` shows the system's biometric prompt through [`@capgo/capacitor-native-biometric`](https://github.com/Cap-go/capacitor-native-biometric), once you hand the plugin over. A browser has no equivalent, so there it is never available.
|
|
1541
1547
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1548
|
+
```javascript
|
|
1549
|
+
import { NativeBiometric } from "@capgo/capacitor-native-biometric"
|
|
1550
|
+
import { createBiometrics } from "@inglorious/web/device/biometrics"
|
|
1544
1551
|
|
|
1545
|
-
|
|
1552
|
+
const types = { Biometrics: createBiometrics({ plugin: NativeBiometric }) }
|
|
1553
|
+
const entities = { biometrics: { type: "Biometrics" } }
|
|
1546
1554
|
|
|
1547
|
-
|
|
1548
|
-
|
|
1555
|
+
api.notify("#biometrics:verify", { reason: "Unlock your account" })
|
|
1556
|
+
```
|
|
1549
1557
|
|
|
1550
|
-
|
|
1558
|
+
- `isAvailable`: whether the device can verify, to hide the button otherwise.
|
|
1559
|
+
- `biometryType`: `"face"`, `"fingerprint"`, `"iris"`, `"multiple"` or `"passcode"`, to name it.
|
|
1560
|
+
- `result`: `"verified"` or `"cancelled"`. Closing the prompt is not an error.
|
|
1561
|
+
- `status` and `error`: those of `handleRequest`, with `error` `"unavailable"` or `"failed"`.
|
|
1551
1562
|
|
|
1552
|
-
|
|
1563
|
+
On iOS, Face ID needs an `NSFaceIDUsageDescription` in `Info.plist`.
|
|
1553
1564
|
|
|
1554
|
-
|
|
1565
|
+
### Keyboard
|
|
1555
1566
|
|
|
1556
|
-
|
|
1567
|
+
Phones don't shrink the page for the on-screen keyboard: iOS never does, nor does Chrome on Android. Whatever sits at the bottom of the screen, such as a bottom sheet with an input, ends up behind it. `@inglorious/web/device/keyboard` reads the height the keyboard covers from the visual viewport and sets it as `--iw-keyboard-height` on `<html>`, with the `iw-keyboard-open` class while the keyboard is up. It needs no plugin and works in browsers and native apps alike. Where the page does shrink for the keyboard, as in an Android app, the class is still set but the height stays `0px`, since nothing is covered.
|
|
1557
1568
|
|
|
1558
1569
|
```javascript
|
|
1559
|
-
import {
|
|
1560
|
-
import { LiveUpdate } from "@capawesome/capacitor-live-update"
|
|
1561
|
-
import { createLiveUpdate, watchLiveUpdate } from "@inglorious/web/live-update"
|
|
1562
|
-
|
|
1563
|
-
const types = { LiveUpdate: createLiveUpdate({ plugin: LiveUpdate }) }
|
|
1564
|
-
const entities = { liveUpdate: { type: "LiveUpdate" } }
|
|
1570
|
+
import { watchKeyboard } from "@inglorious/web/device/keyboard"
|
|
1565
1571
|
|
|
1566
|
-
|
|
1567
|
-
plugin: LiveUpdate,
|
|
1568
|
-
app: App,
|
|
1569
|
-
store,
|
|
1570
|
-
manifestUrl,
|
|
1571
|
-
release: Number(import.meta.env.VITE_LIVE_UPDATE_RELEASE),
|
|
1572
|
-
})
|
|
1572
|
+
watchKeyboard()
|
|
1573
1573
|
```
|
|
1574
1574
|
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
`release` must grow with every build, like the build's timestamp, and only release builds should have one: a development build without it must not watch, or it would turn into the published code.
|
|
1575
|
+
Inglorious UI's bottom sheets, snackbars and toasts move above the keyboard, and its bottom navigation hides while the keyboard is up. Your own fixed elements can do the same:
|
|
1578
1576
|
|
|
1579
|
-
|
|
1577
|
+
```css
|
|
1578
|
+
.composer {
|
|
1579
|
+
position: fixed;
|
|
1580
|
+
bottom: var(--iw-keyboard-height, 0px);
|
|
1581
|
+
}
|
|
1582
|
+
```
|
|
1580
1583
|
|
|
1581
|
-
|
|
1584
|
+
It returns a function that stops following.
|
|
1582
1585
|
|
|
1583
|
-
|
|
1586
|
+
### Storage
|
|
1584
1587
|
|
|
1585
|
-
|
|
1588
|
+
iOS and Android can clear a WebView's `localStorage` when the device runs low on space. `createNativeStorage` keeps values in Capacitor Preferences instead, in the native app, and in `localStorage` in a browser. Give it to [`withStorage`](https://www.npmjs.com/package/@inglorious/store#withstorage):
|
|
1586
1589
|
|
|
1587
1590
|
```javascript
|
|
1588
|
-
import {
|
|
1589
|
-
import {
|
|
1591
|
+
import { Preferences } from "@capacitor/preferences"
|
|
1592
|
+
import { withStorage } from "@inglorious/store/storage"
|
|
1593
|
+
import { createNativeStorage } from "@inglorious/web/device/storage"
|
|
1590
1594
|
|
|
1591
|
-
const
|
|
1595
|
+
const preferences = createNativeStorage({ plugin: Preferences })
|
|
1592
1596
|
|
|
1593
1597
|
const types = {
|
|
1594
|
-
|
|
1598
|
+
Settings: [Settings, withStorage(["theme"], { storage: () => preferences })],
|
|
1595
1599
|
}
|
|
1596
|
-
|
|
1597
|
-
watchAuth(adapter, store) // keeps `user` in step with the session
|
|
1598
1600
|
```
|
|
1599
1601
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
The entity's `step` says what to ask for: `"email"`, `"password"`, `"signUp"`, `"code"` or `"reset"`. Its events take what the person typed: `emailSubmit(email)`, `signInSubmit(password)`, `signUpSubmit({ password, data })`, `codeSubmit(code)`, `resetSubmit({ code, password })`, and move between steps: `signUpShow`, `signInShow`, `codeRequest`, `codeResend`, `resetRequest`, `back`. Signed in, `signOut` and `accountEraseAsk`, then `accountErase` or `accountEraseCancel`. `isReady` turns true once the saved session is read: until then, render nothing rather than the sign-in screen.
|
|
1602
|
+
Preferences answers with promises, so in the native app the entity starts with its defaults and gets the stored fields back a moment later, through `storageRestore`. In a browser it uses `localStorage`.
|
|
1603
1603
|
|
|
1604
|
-
|
|
1604
|
+
It works as Supabase's session storage too, so signing in survives the same clean-ups:
|
|
1605
1605
|
|
|
1606
1606
|
```javascript
|
|
1607
|
-
|
|
1608
|
-
Auth: [
|
|
1609
|
-
createAuth({ adapter }),
|
|
1610
|
-
{
|
|
1611
|
-
signedIn(entity, { isNew }, api) {
|
|
1612
|
-
api.notify("#router:navigate", isNew ? "/onboarding" : "/")
|
|
1613
|
-
},
|
|
1614
|
-
},
|
|
1615
|
-
],
|
|
1616
|
-
}
|
|
1607
|
+
createClient(url, key, { auth: { storage: preferences } })
|
|
1617
1608
|
```
|
|
1618
1609
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
`status` is `"loading"` while waiting, and `error` is a key to put into words: `"invalidEmail"`, `"invalidCode"`, `"weakPassword"`, `"invalidCredentials"`, `"accountExists"`, `"rateLimited"`, `"captcha"`, `"network"` or `"unknown"`. An account not confirmed yet goes straight to the code.
|
|
1622
|
-
|
|
1623
|
-
The adapter talks to the backend. `supabaseAuth` from `@inglorious/supabase` is one; another backend needs `onSessionChange`, `signIn`, `signUp`, `sendCode`, `verifyCode`, `verifyLink`, `resendCode`, `sendResetCode`, `updatePassword`, `signOut`, `eraseAccount` and `errorCode`, plus `accountExists` to skip straight to the password or the new account, and `prepare(action)`, called once the next step is known (`"signIn"` or `"signUp"`), such as to solve a CAPTCHA before the person submits.
|
|
1610
|
+
---
|
|
1624
1611
|
|
|
1625
|
-
|
|
1612
|
+
## Native App
|
|
1626
1613
|
|
|
1627
|
-
|
|
1614
|
+
`@inglorious/web/native/*` holds what exists because the app is native. Each does nothing outside a native app, and `isNative()` from `@inglorious/web/native` says whether it is one.
|
|
1628
1615
|
|
|
1629
|
-
|
|
1616
|
+
### App Links
|
|
1630
1617
|
|
|
1631
|
-
With Universal Links (iOS) and App Links (Android), a link to the app's domain opens the installed app instead of the browser. `@inglorious/web/app-links` sends the router to that link's path, both for the link that started the app and for links that arrive while it runs. It does nothing outside a native app.
|
|
1618
|
+
With Universal Links (iOS) and App Links (Android), a link to the app's domain opens the installed app instead of the browser. `@inglorious/web/native/app-links` sends the router to that link's path, both for the link that started the app and for links that arrive while it runs. It does nothing outside a native app.
|
|
1632
1619
|
|
|
1633
1620
|
```javascript
|
|
1634
1621
|
import { App } from "@capacitor/app"
|
|
1635
|
-
import { watchAppLinks } from "@inglorious/web/app-links"
|
|
1622
|
+
import { watchAppLinks } from "@inglorious/web/native/app-links"
|
|
1636
1623
|
|
|
1637
1624
|
watchAppLinks(App, store)
|
|
1638
1625
|
```
|
|
@@ -1641,130 +1628,203 @@ watchAppLinks(App, store)
|
|
|
1641
1628
|
|
|
1642
1629
|
The operating system opens the app only when the domain vouches for it: iOS reads `/.well-known/apple-app-site-association` and Android `/.well-known/assetlinks.json`, and the app declares the domain (Associated Domains on iOS, an intent filter on Android). [`@inglorious/capacitor`](../capacitor) generates all of it from `native.appLinks` in `package.json`, and `@inglorious/create-app --mobile` sets it up.
|
|
1643
1630
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
## Back Button
|
|
1631
|
+
### Back Button
|
|
1647
1632
|
|
|
1648
|
-
On Android, the back button and the back gesture go back in history. `@inglorious/web/back-button` closes the app instead on a root path, a top-level page like a tab bar's, and when there is no history left, as other Android apps do. It does nothing outside a native app, and iOS has no back button.
|
|
1633
|
+
On Android, the back button and the back gesture go back in history. `@inglorious/web/native/back-button` closes the app instead on a root path, a top-level page like a tab bar's, and when there is no history left, as other Android apps do. It does nothing outside a native app, and iOS has no back button.
|
|
1649
1634
|
|
|
1650
1635
|
```javascript
|
|
1651
1636
|
import { App } from "@capacitor/app"
|
|
1652
|
-
import { watchBackButton } from "@inglorious/web/back-button"
|
|
1637
|
+
import { watchBackButton } from "@inglorious/web/native/back-button"
|
|
1653
1638
|
|
|
1654
1639
|
watchBackButton(App, { rootPaths: ["/", "/search", "/profile"] })
|
|
1655
1640
|
```
|
|
1656
1641
|
|
|
1657
1642
|
`rootPaths` defaults to `["/"]`; it returns a function that stops listening. Navigate between root paths with `{ to, replace: true }`, so switching tabs does not pile up history.
|
|
1658
1643
|
|
|
1659
|
-
|
|
1644
|
+
### System Bars
|
|
1660
1645
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
The status bar and Android's navigation bar follow the device's light or dark mode, so a light app on a phone in dark mode gets white icons on a white page. `@inglorious/web/system-bars` sets them from the app's own `color-scheme`, which every Inglorious UI theme sets, and follows it when the theme class changes. An app whose `color-scheme` is `light dark` keeps the device's style. It does nothing outside a native app.
|
|
1646
|
+
The status bar and Android's navigation bar follow the device's light or dark mode, so a light app on a phone in dark mode gets white icons on a white page. `@inglorious/web/native/system-bars` sets them from the app's own `color-scheme`, which every Inglorious UI theme sets, and follows it when the theme class changes. An app whose `color-scheme` is `light dark` keeps the device's style. It does nothing outside a native app.
|
|
1664
1647
|
|
|
1665
1648
|
```javascript
|
|
1666
1649
|
import { SystemBars } from "@capacitor/core"
|
|
1667
|
-
import { watchSystemBars } from "@inglorious/web/system-bars"
|
|
1650
|
+
import { watchSystemBars } from "@inglorious/web/native/system-bars"
|
|
1668
1651
|
|
|
1669
1652
|
watchSystemBars(SystemBars)
|
|
1670
1653
|
```
|
|
1671
1654
|
|
|
1672
1655
|
It returns a function that stops following.
|
|
1673
1656
|
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
## Keyboard
|
|
1657
|
+
### Native App Updates
|
|
1677
1658
|
|
|
1678
|
-
|
|
1659
|
+
A Capacitor app carries its web code inside the binary, so only the stores update it. `@inglorious/web/native/update` makes an update mandatory: the app reads a minimum build per platform, and a build below it is blocked until the user updates. `@inglorious/create-app --mobile --push` sets it up with Supabase.
|
|
1679
1660
|
|
|
1680
1661
|
```javascript
|
|
1681
|
-
import {
|
|
1662
|
+
import { App } from "@capacitor/app"
|
|
1663
|
+
import {
|
|
1664
|
+
createNativeUpdate,
|
|
1665
|
+
watchNativeUpdate,
|
|
1666
|
+
} from "@inglorious/web/native/update"
|
|
1682
1667
|
|
|
1683
|
-
|
|
1668
|
+
const types = { NativeUpdate: [createNativeUpdate({ adapter }), template] }
|
|
1669
|
+
const entities = { nativeUpdate: { type: "NativeUpdate" } }
|
|
1670
|
+
|
|
1671
|
+
watchNativeUpdate(App, store)
|
|
1684
1672
|
```
|
|
1685
1673
|
|
|
1686
|
-
|
|
1674
|
+
`watchNativeUpdate` reads the installed build at launch and on every resume, and does nothing outside a native app. `{ id }` as a third argument notifies another entity; it returns a function that stops watching.
|
|
1687
1675
|
|
|
1688
|
-
|
|
1689
|
-
.composer {
|
|
1690
|
-
position: fixed;
|
|
1691
|
-
bottom: var(--iw-keyboard-height, 0px);
|
|
1692
|
-
}
|
|
1693
|
-
```
|
|
1676
|
+
The adapter says where the minimum lives: `requirement(platform)` resolves to `{ minBuild, storeUrl }`, or `null` for no minimum. `supabaseNativeUpdate` from `@inglorious/supabase` reads it from a table.
|
|
1694
1677
|
|
|
1695
|
-
|
|
1678
|
+
The `nativeUpdate` entity contains:
|
|
1696
1679
|
|
|
1697
|
-
|
|
1680
|
+
- `isUpdateRequired` — the installed build is below the minimum
|
|
1681
|
+
- `storeUrl` — where the update button goes, or `null`
|
|
1698
1682
|
|
|
1699
|
-
|
|
1683
|
+
Events:
|
|
1700
1684
|
|
|
1701
|
-
|
|
1685
|
+
- `nativeUpdateCheck` — `{ platform, build }`, sent by `watchNativeUpdate`
|
|
1686
|
+
- `nativeUpdateApply` — opens the store
|
|
1702
1687
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1688
|
+
A failed check keeps the last answer, so nobody is blocked by being offline. Render the whole app as the update page while `isUpdateRequired`, and raise the minimum only once the new build is live in that store.
|
|
1689
|
+
|
|
1690
|
+
### Live Updates
|
|
1691
|
+
|
|
1692
|
+
A store release is only needed for native changes. `@inglorious/web/native/live-update` replaces the web code inside a Capacitor app with a newer published bundle, through [`@capawesome/capacitor-live-update`](https://capawesome.io/plugins/live-update/), whose open source plugin downloads from any URL. `publishLiveUpdate` from `@inglorious/supabase/live-update` publishes one.
|
|
1706
1693
|
|
|
1707
1694
|
```javascript
|
|
1708
|
-
import {
|
|
1709
|
-
import {
|
|
1695
|
+
import { App } from "@capacitor/app"
|
|
1696
|
+
import { LiveUpdate } from "@capawesome/capacitor-live-update"
|
|
1697
|
+
import {
|
|
1698
|
+
createLiveUpdate,
|
|
1699
|
+
watchLiveUpdate,
|
|
1700
|
+
} from "@inglorious/web/native/live-update"
|
|
1710
1701
|
|
|
1711
|
-
const types = {
|
|
1702
|
+
const types = { LiveUpdate: createLiveUpdate({ plugin: LiveUpdate }) }
|
|
1703
|
+
const entities = { liveUpdate: { type: "LiveUpdate" } }
|
|
1712
1704
|
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
url: icsUrl,
|
|
1720
|
-
fileName: "wedding.ics",
|
|
1705
|
+
watchLiveUpdate({
|
|
1706
|
+
plugin: LiveUpdate,
|
|
1707
|
+
app: App,
|
|
1708
|
+
store,
|
|
1709
|
+
manifestUrl,
|
|
1710
|
+
release: Number(import.meta.env.VITE_LIVE_UPDATE_RELEASE),
|
|
1721
1711
|
})
|
|
1722
1712
|
```
|
|
1723
1713
|
|
|
1724
|
-
`
|
|
1714
|
+
`watchLiveUpdate` tells the plugin the running bundle works, then reads the manifest at launch, every hour (`checkEveryMs`) and on each resume. The manifest is `{ release, minBuild, url, checksum, signature }`. A bundle is wanted when its `release` is newer than the running one and the installed build is at least `minBuild` (`isLiveUpdateWanted`). It downloads in the background, is applied on the next pause, and is announced as `#liveUpdate:liveUpdateReady` meanwhile; `liveUpdateApply` moves over at once. It does nothing outside a native app, and returns a function that stops watching.
|
|
1715
|
+
|
|
1716
|
+
`release` must grow with every build, like the build's timestamp, and only release builds should have one: a development build without it must not watch, or it would turn into the published code.
|
|
1717
|
+
|
|
1718
|
+
Set `publicKey` in the plugin's Capacitor config so it refuses unsigned bundles, and `readyTimeout` so a bundle that doesn't start is rolled back; with `autoBlockRolledBackBundles`, `watchLiveUpdate` never downloads it again.
|
|
1725
1719
|
|
|
1726
1720
|
---
|
|
1727
1721
|
|
|
1728
|
-
##
|
|
1722
|
+
## PWA Updates
|
|
1723
|
+
|
|
1724
|
+
`@inglorious/web/pwa` keeps an installed PWA on its latest version. It works with the service worker that [`vite-plugin-pwa`](https://vite-pwa-org.netlify.app/) generates, and `@inglorious/create-app --pwa` sets it up for you.
|
|
1729
1725
|
|
|
1730
|
-
|
|
1726
|
+
Updates are not optional. A new version downloads in the background, and is applied with a reload at the first moment nobody is in the middle of something:
|
|
1731
1727
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
import { withStorage } from "@inglorious/store/storage"
|
|
1735
|
-
import { createNativeStorage } from "@inglorious/web/mobile"
|
|
1728
|
+
- at launch, before anything is touched;
|
|
1729
|
+
- each time the app goes to the background or comes back to the foreground.
|
|
1736
1730
|
|
|
1737
|
-
|
|
1731
|
+
It also checks for a new version every hour and on every return to the foreground: a phone suspends an installed PWA rather than closing it, so the browser's own check may never come.
|
|
1738
1732
|
|
|
1739
|
-
|
|
1740
|
-
|
|
1733
|
+
```javascript
|
|
1734
|
+
import { isNative } from "@inglorious/web/native"
|
|
1735
|
+
import { watchPwaUpdate } from "@inglorious/web/pwa"
|
|
1736
|
+
import { registerSW } from "virtual:pwa-register"
|
|
1737
|
+
|
|
1738
|
+
if (!isNative()) {
|
|
1739
|
+
registerSW({
|
|
1740
|
+
onRegisteredSW(url, registration) {
|
|
1741
|
+
if (registration) watchPwaUpdate(registration)
|
|
1742
|
+
},
|
|
1743
|
+
})
|
|
1741
1744
|
}
|
|
1742
1745
|
```
|
|
1743
1746
|
|
|
1744
|
-
|
|
1747
|
+
Configure the plugin with `registerType: "prompt"` and `injectRegister: false`: the generated worker then waits for the `SKIP_WAITING` message this module sends, instead of taking over on its own.
|
|
1745
1748
|
|
|
1746
|
-
|
|
1749
|
+
### Offering "Update now"
|
|
1750
|
+
|
|
1751
|
+
A version that lands while someone is using the app waits for the next trip to the background. To offer it right away, pass the store and register the `PwaUpdate` type:
|
|
1747
1752
|
|
|
1748
1753
|
```javascript
|
|
1749
|
-
|
|
1754
|
+
import { PwaUpdate, watchPwaUpdate } from "@inglorious/web/pwa"
|
|
1755
|
+
|
|
1756
|
+
const store = createStore({ types: { PwaUpdate }, autoCreateEntities: true })
|
|
1757
|
+
|
|
1758
|
+
watchPwaUpdate(registration, store)
|
|
1750
1759
|
```
|
|
1751
1760
|
|
|
1752
|
-
|
|
1761
|
+
The `pwaUpdate` entity contains:
|
|
1762
|
+
|
|
1763
|
+
- `isUpdateReady` — a new version is waiting for the next reload
|
|
1753
1764
|
|
|
1754
|
-
|
|
1765
|
+
Events:
|
|
1766
|
+
|
|
1767
|
+
- `pwaUpdateReady` — sent by `watchPwaUpdate` when a version lands mid-session
|
|
1768
|
+
- `pwaUpdateApply` — moves over to the waiting version now, reloading the page
|
|
1755
1769
|
|
|
1756
1770
|
```javascript
|
|
1757
|
-
|
|
1758
|
-
|
|
1771
|
+
const renderUpdate = (api) =>
|
|
1772
|
+
when(
|
|
1773
|
+
api.getEntity("pwaUpdate").isUpdateReady,
|
|
1774
|
+
() =>
|
|
1775
|
+
html`<button @click=${() => api.notify("#pwaUpdate:pwaUpdateApply")}>
|
|
1776
|
+
Update now
|
|
1777
|
+
</button>`,
|
|
1778
|
+
)
|
|
1779
|
+
```
|
|
1759
1780
|
|
|
1760
|
-
|
|
1781
|
+
Inglorious UI's `Snackbar` is the usual place for it. `watchPwaUpdate` takes `{ id, checkEveryMs }` as a third argument, to announce to an entity with another id or to check more or less often, and returns a function that stops watching.
|
|
1761
1782
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1783
|
+
---
|
|
1784
|
+
|
|
1785
|
+
## Sign-in
|
|
1786
|
+
|
|
1787
|
+
`@inglorious/web/auth` is the type behind a sign-in screen. It walks from the email to a password, a new account or a code sent by email, holds the signed-in `user`, and erases the account on request, as the App Store and Google Play require of apps that create accounts. Codes rather than links work in a native app too, since nobody has to open anything.
|
|
1788
|
+
|
|
1789
|
+
```javascript
|
|
1790
|
+
import { supabaseAuth } from "@inglorious/supabase"
|
|
1791
|
+
import { createAuth, watchAuth } from "@inglorious/web/auth"
|
|
1792
|
+
|
|
1793
|
+
const adapter = supabaseAuth(supabase)
|
|
1794
|
+
|
|
1795
|
+
const types = {
|
|
1796
|
+
Auth: { ...createAuth({ adapter, methods: ["password", "code"] }), render },
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
watchAuth(adapter, store) // keeps `user` in step with the session
|
|
1765
1800
|
```
|
|
1766
1801
|
|
|
1767
|
-
|
|
1802
|
+
`methods` lists what the screen offers: `"password"` (sign in, create an account confirmed with a code, reset a forgotten password with a code) and `"code"` (sign in with a code alone, creating the account on first use).
|
|
1803
|
+
|
|
1804
|
+
The entity's `step` says what to ask for: `"email"`, `"password"`, `"signUp"`, `"code"` or `"reset"`. Its events take what the person typed: `emailSubmit(email)`, `signInSubmit(password)`, `signUpSubmit({ password, data })`, `codeSubmit(code)`, `resetSubmit({ code, password })`, and move between steps: `signUpShow`, `signInShow`, `codeRequest`, `codeResend`, `resetRequest`, `back`. Signed in, `signOut` and `accountEraseAsk`, then `accountErase` or `accountEraseCancel`. `isReady` turns true once the saved session is read: until then, render nothing rather than the sign-in screen.
|
|
1805
|
+
|
|
1806
|
+
Whoever signs in, by password, code, link or password reset, the entity gets `signedIn` with `{ user, isNew }`, `isNew` for an account just created. Add a handler to move on:
|
|
1807
|
+
|
|
1808
|
+
```javascript
|
|
1809
|
+
const types = {
|
|
1810
|
+
Auth: [
|
|
1811
|
+
createAuth({ adapter }),
|
|
1812
|
+
{
|
|
1813
|
+
signedIn(entity, { isNew }, api) {
|
|
1814
|
+
api.notify("#router:navigate", isNew ? "/onboarding" : "/")
|
|
1815
|
+
},
|
|
1816
|
+
},
|
|
1817
|
+
],
|
|
1818
|
+
}
|
|
1819
|
+
```
|
|
1820
|
+
|
|
1821
|
+
For a page that a confirmation email's link opens, `linkSubmit({ tokenHash })` signs in with the link instead of the code. Ask for a tap first: mail scanners open links too.
|
|
1822
|
+
|
|
1823
|
+
`status` is `"loading"` while waiting, and `error` is a key to put into words: `"invalidEmail"`, `"invalidCode"`, `"weakPassword"`, `"invalidCredentials"`, `"accountExists"`, `"rateLimited"`, `"captcha"`, `"network"` or `"unknown"`. An account not confirmed yet goes straight to the code.
|
|
1824
|
+
|
|
1825
|
+
The adapter talks to the backend. `supabaseAuth` from `@inglorious/supabase` is one; another backend needs `onSessionChange`, `signIn`, `signUp`, `sendCode`, `verifyCode`, `verifyLink`, `resendCode`, `sendResetCode`, `updatePassword`, `signOut`, `eraseAccount` and `errorCode`, plus `accountExists` to skip straight to the password or the new account, and `prepare(action)`, called once the next step is known (`"signIn"` or `"signUp"`), such as to solve a CAPTCHA before the person submits.
|
|
1826
|
+
|
|
1827
|
+
`create-app --auth` generates the screen, the account actions in the app bar, the Edge Function that erases accounts and the email templates.
|
|
1768
1828
|
|
|
1769
1829
|
---
|
|
1770
1830
|
|
|
@@ -2114,8 +2174,8 @@ import { render, trigger } from "@inglorious/web/test"
|
|
|
2114
2174
|
|
|
2115
2175
|
import { Form } from "@inglorious/web/form"
|
|
2116
2176
|
import { Router, setRoutes } from "@inglorious/web/router"
|
|
2117
|
-
import {
|
|
2118
|
-
import { Compass } from "@inglorious/web/
|
|
2177
|
+
import { createGeolocation } from "@inglorious/web/device/geolocation"
|
|
2178
|
+
import { Compass } from "@inglorious/web/device/compass"
|
|
2119
2179
|
```
|
|
2120
2180
|
|
|
2121
2181
|
This keeps `lit-html` as an internal implementation detail while still giving applications stable, tree-shakeable import paths.
|