@tristan2828/ui-foundation 4.155.2 → 4.157.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/conventions/docs/cell-patterns.md +27 -24
- package/conventions/docs/reminders.md +114 -5
- package/dist/api/gateway/push.d.ts +12 -0
- package/dist/api/gateway/push.js +32 -0
- package/dist/api/schema.d.ts +132 -2
- package/dist/components/app/allow-reminders.js +2 -1
- package/dist/components/app/milkdown-editor.js +16 -3
- package/dist/components/app/notes-outline.d.ts +7 -2
- package/dist/components/app/notes-outline.js +14 -6
- package/dist/components/app/notification-settings.d.ts +38 -0
- package/dist/components/app/notification-settings.js +128 -0
- package/dist/components/app/push-status-words.d.ts +27 -0
- package/dist/components/app/push-status-words.js +14 -0
- package/dist/components/app/rich-text-fold.d.ts +4 -1
- package/dist/components/app/rich-text-fold.js +59 -21
- package/dist/hooks/fold-store.d.ts +19 -0
- package/dist/hooks/fold-store.js +41 -0
- package/dist/hooks/use-push-devices.d.ts +37 -0
- package/dist/hooks/use-push-devices.js +72 -0
- package/dist/hooks/use-push-permission.d.ts +26 -3
- package/dist/hooks/use-push-permission.js +59 -7
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/lib/markdown-fold.d.ts +6 -2
- package/dist/lib/push-endpoint-hash.d.ts +6 -0
- package/dist/lib/push-endpoint-hash.js +12 -0
- package/dist/mocks/index.d.ts +1 -1
- package/dist/mocks/index.js +1 -1
- package/dist/mocks/push.d.ts +8 -0
- package/dist/mocks/push.js +60 -9
- package/openapi/foundation.yaml +119 -2
- package/package.json +1 -1
|
@@ -26,26 +26,26 @@
|
|
|
26
26
|
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 636–715
|
|
27
27
|
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 717–758
|
|
28
28
|
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 760–832
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines 834–
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 834–1705
|
|
30
30
|
- [Presets: one line per field](#presets-one-line-per-field) · lines 1240–1312
|
|
31
31
|
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1314–1350
|
|
32
32
|
- [A link and its label](#a-link-and-its-label) · lines 1352–1376
|
|
33
33
|
- [A list of sub-items](#a-list-of-sub-items) · lines 1378–1511
|
|
34
|
-
- [On a page of the app's own: `EditInPlaceScope`](#on-a-page-of-the-apps-own-editinplacescope) · lines 1513–
|
|
35
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
36
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
37
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
38
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
39
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
40
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
41
|
-
- [28. A list's rows: hover, lines, rows per page](#28-a-lists-rows-hover-lines-rows-per-page) · lines
|
|
42
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
43
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
44
|
-
- [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines
|
|
45
|
-
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines
|
|
46
|
-
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines
|
|
47
|
-
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines
|
|
48
|
-
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines
|
|
34
|
+
- [On a page of the app's own: `EditInPlaceScope`](#on-a-page-of-the-apps-own-editinplacescope) · lines 1513–1622
|
|
35
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1624–1698
|
|
36
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1700–1705
|
|
37
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1707–1773
|
|
38
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1775–1829
|
|
39
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1831–1913
|
|
40
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1915–1940
|
|
41
|
+
- [28. A list's rows: hover, lines, rows per page](#28-a-lists-rows-hover-lines-rows-per-page) · lines 1942–1975
|
|
42
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1977–2028
|
|
43
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 2030–2104
|
|
44
|
+
- [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines 2050–2104
|
|
45
|
+
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 2106–2318
|
|
46
|
+
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2267–2318
|
|
47
|
+
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2320–2354
|
|
48
|
+
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2356–2403
|
|
49
49
|
|
|
50
50
|
<!-- /index -->
|
|
51
51
|
|
|
@@ -1556,14 +1556,17 @@ const body = editInPlace<string>({
|
|
|
1556
1556
|
router's updates to `flushSync`. With the other, the hidden tab is
|
|
1557
1557
|
still in front for a moment, and a key typed right after the switch
|
|
1558
1558
|
goes into it.
|
|
1559
|
-
- **An outline beside a long note** is `NotesOutline`, given the
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1559
|
+
- **An outline beside a long note** is `NotesOutline`, given the
|
|
1560
|
+
editor's `foldKey`: its headings as a list to jump with (each opens
|
|
1561
|
+
its section and brings it into view), with Fold All and Open All. Put
|
|
1562
|
+
it beside the editor (in a rail, or above the note on a phone). It
|
|
1563
|
+
needs no `markdown`: it lists the headings of the mounted editor with
|
|
1564
|
+
that key, a frame after one is added, renamed or toggled, and parses
|
|
1565
|
+
nothing, so typing in a paragraph and saving never touch it. Beside
|
|
1566
|
+
`<Markdown>`, or for the moment before the editor is up, pass
|
|
1567
|
+
`markdown` and it reads that instead. An app that draws its own list
|
|
1568
|
+
reads the same headings with `useFoldHeadings(foldKey)` (`null` with
|
|
1569
|
+
no editor under the key).
|
|
1567
1570
|
- **An editor that is the page** (a note the app opens on) takes
|
|
1568
1571
|
`autoFocus="end"`, the caret after its last words, in view, and
|
|
1569
1572
|
`tabStaysInText`: Tab on a plain line stays in the text (Esc, then
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Reminders
|
|
2
2
|
|
|
3
|
+
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
|
+
## Index
|
|
5
|
+
|
|
6
|
+
- [Allowing reminders](#allowing-reminders) · lines 40–72
|
|
7
|
+
- [A settings page: this device, a test and the devices](#a-settings-page-this-device-a-test-and-the-devices) · lines 74–146
|
|
8
|
+
- [On iPhone and iPad](#on-iphone-and-ipad) · lines 148–154
|
|
9
|
+
- [The app's own icon](#the-apps-own-icon) · lines 156–186
|
|
10
|
+
- [Home-screen shortcuts](#home-screen-shortcuts) · lines 188–204
|
|
11
|
+
- [A reminder is the app's own row](#a-reminder-is-the-apps-own-row) · lines 206–261
|
|
12
|
+
- [Repeating reminders](#repeating-reminders) · lines 263–340
|
|
13
|
+
- [A Done button on the notification](#a-done-button-on-the-notification) · lines 342–385
|
|
14
|
+
- [Testing](#testing) · lines 387–403
|
|
15
|
+
|
|
16
|
+
<!-- /index -->
|
|
17
|
+
|
|
3
18
|
A notification at a time the user chose ("time for your morning routine",
|
|
4
19
|
"a short break at 3 pm", a habit, a medication) that reaches them with the
|
|
5
20
|
app closed. It's Web Push: the browser subscribes with its push service
|
|
@@ -12,7 +27,9 @@ to the device, where the app's service worker shows it.
|
|
|
12
27
|
| `pwa({ name })` | `vite.config.ts`, from `@tristan2828/ui-foundation/vite` | The app installable: a manifest, icons in the theme's colours (or the app's own), and `/push-sw.js`, the service worker that shows pushes and opens their path |
|
|
13
28
|
| `usePushPermission()` | the package | Whether this device gets reminders, and `enable`/`disable` |
|
|
14
29
|
| `AllowReminders` | the package | The control: says what reminders are, then asks, on a click |
|
|
15
|
-
|
|
|
30
|
+
| `ThisDeviceSetting`, `TestNotificationSetting`, `NotificationDevices` | the package | A settings page's rows: this device's switch, a test send to it, and the account's devices (renamed, removed) |
|
|
31
|
+
| `usePushDevices(push)` | the package | The account's devices for those rows, this one marked: `rename`, `remove`, `sendTest` |
|
|
32
|
+
| `/push/public-key`, `/push/subscriptions`, `/push/subscriptions/{id}`, `/push/subscriptions/{id}/test` | `openapi.yaml`, the foundation's part (optional) | The VAPID key to subscribe with; this device's subscription saved or dropped; the devices listed and renamed; a test sent |
|
|
16
33
|
| `foundation_backend.push` | `ui-foundation-backend` | `send_push(session, user_id, title, body, url)`: encrypted (RFC 8291), signed (VAPID), to every device the user allowed; optionally a `PushAction` button and `renotify` |
|
|
17
34
|
| `foundation_backend.reminders`, `reminders` | `ui-foundation-backend` | A reminder row (when, which days, the text, the path), and the `send-reminders` job that sends each one when it's due |
|
|
18
35
|
|
|
@@ -44,6 +61,89 @@ const push = usePushPermission()
|
|
|
44
61
|
| `blocked` | The person said no | Where to allow it again |
|
|
45
62
|
| `unsupported` | No push in this browser | That it can't |
|
|
46
63
|
| `mock` | The app runs on MSW | That reminders need the real backend |
|
|
64
|
+
| `unavailable` | The backend has push turned off (`GET /push/subscriptions` is a 404) | That the app's server doesn't send notifications yet |
|
|
65
|
+
|
|
66
|
+
`unavailable` is a status added after the first six: code of the app's
|
|
67
|
+
own that switches over `PushStatus` gives it a case.
|
|
68
|
+
|
|
69
|
+
A device removed from another one (the list below) is found the next
|
|
70
|
+
time `usePushPermission` works its status out: the browser is still
|
|
71
|
+
subscribed, but the account's list hasn't got it, so it unsubscribes
|
|
72
|
+
quietly and reads `off`. Nothing is ever sent to it.
|
|
73
|
+
|
|
74
|
+
## A settings page: this device, a test and the devices
|
|
75
|
+
|
|
76
|
+
Three rows of a settings page (design-language.md "A settings page"), in
|
|
77
|
+
one `SettingsCard`:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import {
|
|
81
|
+
NotificationDevices,
|
|
82
|
+
SettingsCard,
|
|
83
|
+
TestNotificationSetting,
|
|
84
|
+
ThisDeviceSetting,
|
|
85
|
+
usePushPermission,
|
|
86
|
+
} from '@tristan2828/ui-foundation'
|
|
87
|
+
|
|
88
|
+
const push = usePushPermission()
|
|
89
|
+
<SettingsCard>
|
|
90
|
+
<ThisDeviceSetting push={push} />
|
|
91
|
+
<TestNotificationSetting push={push} />
|
|
92
|
+
<NotificationDevices push={push} />
|
|
93
|
+
</SettingsCard>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- **`ThisDeviceSetting`**, "On This Device": a switch that asks the
|
|
97
|
+
browser only from its click. Where it can't be switched (`blocked`,
|
|
98
|
+
`needs-install`, `unsupported`, `mock`, `unavailable`) it is off and
|
|
99
|
+
disabled, and its help line says what to do: the same words
|
|
100
|
+
`AllowReminders` shows.
|
|
101
|
+
- **`TestNotificationSetting`**, "Send a Test": one notification to this
|
|
102
|
+
device, opening the page it was sent from (`url` to say otherwise). Its
|
|
103
|
+
answer is on its own help line, with no toast: sent, "Wait N seconds
|
|
104
|
+
and try again", or that the device can't be reached any more (its push
|
|
105
|
+
service said it's gone, so the backend deleted it).
|
|
106
|
+
- **`NotificationDevices`**, "Devices": the account's devices, this one
|
|
107
|
+
first and marked This Device, then the newest. Each name is edited in
|
|
108
|
+
place (1 to 60 characters, ✓ Saved); one saved before names reads
|
|
109
|
+
"Unknown device". Each shows "Added Nov 25, 2026" and Remove, a hard
|
|
110
|
+
delete's confirm ("Removed iPhone, Safari"). Removing this device turns
|
|
111
|
+
it off; another stops getting notifications at once and turns itself off
|
|
112
|
+
the next time it opens. The list has its four states (loading, empty,
|
|
113
|
+
an error with Try again, the devices); `unavailable` says so, and isn't
|
|
114
|
+
an error.
|
|
115
|
+
- The rows share one request for the list with `usePushPermission`'s
|
|
116
|
+
status check. Each fetches it itself; a story or test passes
|
|
117
|
+
`devices` (usePushDevices' shape) to show any state.
|
|
118
|
+
- The names edit inside the page's `EditInPlaceScope` when there is one,
|
|
119
|
+
and inside their own otherwise. Either needs the data router every app
|
|
120
|
+
has.
|
|
121
|
+
|
|
122
|
+
What the backend does:
|
|
123
|
+
|
|
124
|
+
| Route | Does | Refuses |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `GET /push/subscriptions` | The user's devices, newest first: `id`, `name`, `createdAt`, `endpointHash`. Never an endpoint or a key | 404 with push off |
|
|
127
|
+
| `PATCH /push/subscriptions/{id}` | Renames it, trimmed | 422 under 1 or over 60 characters; 404 for another user's |
|
|
128
|
+
| `POST /push/subscriptions/{id}/test` | One notification ("Test notification") to that device only, opening `url` (the app's own path) | 404 for another user's, or one its push service says is gone (deleted); 429 with `Retry-After` after 5 a minute per user; 502 when the push service refuses it otherwise |
|
|
129
|
+
|
|
130
|
+
- **Names**: a new device is named from its request's User-Agent, as
|
|
131
|
+
"<platform>, <browser>" (`foundation_backend.push.device_name`):
|
|
132
|
+
"iPhone, Safari", "iPhone, Home Screen app" (the installed app says no
|
|
133
|
+
browser), "Android, Samsung Internet", "Windows, Edge", "Mac, Firefox",
|
|
134
|
+
"Chromebook, Chrome". Whichever half is known, or no name. An iPad that
|
|
135
|
+
reports itself as a Mac is "Mac, Safari"; the user can rename it.
|
|
136
|
+
- **Subscribing again** (new keys, or `disable()` learning its id) keeps
|
|
137
|
+
the name and when the device was first added, and names a device that
|
|
138
|
+
had none. `created_at` is when it was first added.
|
|
139
|
+
- **This Device** is found by hash: the browser hashes its own
|
|
140
|
+
subscription's endpoint (SHA-256, base64url, no padding; the package's
|
|
141
|
+
`hashEndpoint`) and finds the row with that `endpointHash`.
|
|
142
|
+
- **The column**: `push_subscriptions.name` (varchar 60, null), with its
|
|
143
|
+
comment, and `created_at`'s comment rewritten. The backend package's
|
|
144
|
+
reference migration is `migrations/0016_push_device_names.py`; copy it
|
|
145
|
+
into the app's own chain, renumbered (the template carries it as
|
|
146
|
+
`0019_push_device_names.py`).
|
|
47
147
|
|
|
48
148
|
## On iPhone and iPad
|
|
49
149
|
|
|
@@ -288,7 +388,16 @@ reminders.register(
|
|
|
288
388
|
|
|
289
389
|
Under MSW the page is held by MSW's service worker, so `usePushPermission`
|
|
290
390
|
reads `mock` and never subscribes: screens show the `mock` state, and a
|
|
291
|
-
Playwright spec checks it the same way. The
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`
|
|
391
|
+
Playwright spec checks it the same way. The device list works under MSW:
|
|
392
|
+
`seedMockPushDevices([{ name, createdAt }])` (from the package's
|
|
393
|
+
`/mocks`) puts devices in it, none of them This Device, and
|
|
394
|
+
`resetMockPush()` clears them. A 404 for `GET /push/subscriptions` (an MSW
|
|
395
|
+
override) shows `unavailable`. Send a Test can't be pressed there (the
|
|
396
|
+
status is `mock`); its answers are the package's own tests. The rest is
|
|
397
|
+
the backend's: its tests decrypt every message as a browser would.
|
|
398
|
+
|
|
399
|
+
To try it end to end, run the real backend with push on, turn
|
|
400
|
+
notifications on in the browser, and press Send a Test on the settings
|
|
401
|
+
page. `python -m foundation_backend.scripts.send_test_push <email>` (from
|
|
402
|
+
`backend/`) still sends to every device of an account, for a check on the
|
|
403
|
+
server itself.
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { components } from "../schema.js";
|
|
2
2
|
export type PushSubscriptionRequest = components["schemas"]["PushSubscriptionRequest"];
|
|
3
|
+
/** One device on the account that gets notifications. Never its endpoint or keys. */
|
|
4
|
+
export type PushDevice = components["schemas"]["PushDevice"];
|
|
3
5
|
/** The key to subscribe with. A 404 is a backend with push turned off. */
|
|
4
6
|
export declare function getPushPublicKey(): Promise<string>;
|
|
5
7
|
/** Saves the subscription; the same device again answers the same id. */
|
|
6
8
|
export declare function savePushSubscription(subscription: PushSubscriptionRequest): Promise<number>;
|
|
7
9
|
/** Already gone (404) counts as done. */
|
|
8
10
|
export declare function deletePushSubscription(id: number): Promise<void>;
|
|
11
|
+
/** The signed-in user's devices, newest first. A 404 is a backend with push turned off. */
|
|
12
|
+
export declare function listPushDevices(): Promise<PushDevice[]>;
|
|
13
|
+
/** Renames one; 1 to 60 characters once trimmed (a 422 otherwise). */
|
|
14
|
+
export declare function renamePushDevice(id: number, name: string): Promise<PushDevice>;
|
|
15
|
+
/**
|
|
16
|
+
* One notification to that device, opening `url` (the app's own path).
|
|
17
|
+
* A 404 is a device that can't be reached any more (the backend deleted
|
|
18
|
+
* it); a 429 is `rate_limited` with `retryAfterSeconds`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sendTestPush(id: number, url: string): Promise<void>;
|
package/dist/api/gateway/push.js
CHANGED
|
@@ -23,3 +23,35 @@ export async function deletePushSubscription(id) {
|
|
|
23
23
|
if (res.status !== 204 && res.status !== 404)
|
|
24
24
|
throw toAppError(res.status, res.body, res.headers);
|
|
25
25
|
}
|
|
26
|
+
/** The signed-in user's devices, newest first. A 404 is a backend with push turned off. */
|
|
27
|
+
export async function listPushDevices() {
|
|
28
|
+
const res = await safeFetch("/push/subscriptions");
|
|
29
|
+
if (res.status !== 200)
|
|
30
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
31
|
+
return res.body;
|
|
32
|
+
}
|
|
33
|
+
/** Renames one; 1 to 60 characters once trimmed (a 422 otherwise). */
|
|
34
|
+
export async function renamePushDevice(id, name) {
|
|
35
|
+
const res = await safeFetch(`/push/subscriptions/${id}`, {
|
|
36
|
+
method: "PATCH",
|
|
37
|
+
headers: { "content-type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ name }),
|
|
39
|
+
});
|
|
40
|
+
if (res.status !== 200)
|
|
41
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
42
|
+
return res.body;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One notification to that device, opening `url` (the app's own path).
|
|
46
|
+
* A 404 is a device that can't be reached any more (the backend deleted
|
|
47
|
+
* it); a 429 is `rate_limited` with `retryAfterSeconds`.
|
|
48
|
+
*/
|
|
49
|
+
export async function sendTestPush(id, url) {
|
|
50
|
+
const res = await safeFetch(`/push/subscriptions/${id}/test`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "content-type": "application/json" },
|
|
53
|
+
body: JSON.stringify({ url }),
|
|
54
|
+
});
|
|
55
|
+
if (res.status !== 204)
|
|
56
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
57
|
+
}
|
package/dist/api/schema.d.ts
CHANGED
|
@@ -158,11 +158,15 @@ export interface paths {
|
|
|
158
158
|
path?: never;
|
|
159
159
|
cookie?: never;
|
|
160
160
|
};
|
|
161
|
-
|
|
161
|
+
/**
|
|
162
|
+
* The signed-in user's devices that get notifications, newest first
|
|
163
|
+
* @description Never an endpoint or a key: a browser finds its own device by endpointHash. A plain array (a user has at most 20). 404 when the backend has push turned off.
|
|
164
|
+
*/
|
|
165
|
+
get: operations["listPushDevices"];
|
|
162
166
|
put?: never;
|
|
163
167
|
/**
|
|
164
168
|
* Save this device's push subscription for the signed-in user
|
|
165
|
-
* @description The browser's PushSubscription.toJSON(). The same endpoint again replaces its keys and owner and answers the same id. The endpoint must be a push service's (422 otherwise): the backend POSTs to it.
|
|
169
|
+
* @description The browser's PushSubscription.toJSON(). The same endpoint again replaces its keys and owner, keeps its name and when it was first added, and answers the same id. A new device is named from the request's User-Agent. The endpoint must be a push service's (422 otherwise): the backend POSTs to it.
|
|
166
170
|
*/
|
|
167
171
|
post: operations["savePushSubscription"];
|
|
168
172
|
delete?: never;
|
|
@@ -185,6 +189,30 @@ export interface paths {
|
|
|
185
189
|
delete: operations["deletePushSubscription"];
|
|
186
190
|
options?: never;
|
|
187
191
|
head?: never;
|
|
192
|
+
/**
|
|
193
|
+
* Rename one of the signed-in user's devices
|
|
194
|
+
* @description The name is trimmed, then 1 to 60 characters (422 otherwise). 404 for another user's device.
|
|
195
|
+
*/
|
|
196
|
+
patch: operations["renamePushDevice"];
|
|
197
|
+
trace?: never;
|
|
198
|
+
};
|
|
199
|
+
"/push/subscriptions/{id}/test": {
|
|
200
|
+
parameters: {
|
|
201
|
+
query?: never;
|
|
202
|
+
header?: never;
|
|
203
|
+
path?: never;
|
|
204
|
+
cookie?: never;
|
|
205
|
+
};
|
|
206
|
+
get?: never;
|
|
207
|
+
put?: never;
|
|
208
|
+
/**
|
|
209
|
+
* Send one test notification to one of the signed-in user's devices
|
|
210
|
+
* @description To that device only. 404 for another user's device, or for one its push service says is gone (its row is deleted). 429 after 5 a minute per user. 502 when the push service refused it for another reason.
|
|
211
|
+
*/
|
|
212
|
+
post: operations["sendTestPush"];
|
|
213
|
+
delete?: never;
|
|
214
|
+
options?: never;
|
|
215
|
+
head?: never;
|
|
188
216
|
patch?: never;
|
|
189
217
|
trace?: never;
|
|
190
218
|
};
|
|
@@ -259,6 +287,25 @@ export interface components {
|
|
|
259
287
|
PushSubscriptionCreated: {
|
|
260
288
|
id: number;
|
|
261
289
|
};
|
|
290
|
+
PushDevice: {
|
|
291
|
+
id: number;
|
|
292
|
+
/** @description What the device is called: from its user agent when first saved ("iPhone, Home Screen app"), or as renamed. null for a device saved before names. */
|
|
293
|
+
name: string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Format: date-time
|
|
296
|
+
* @description When the device was first added. Subscribing again keeps it.
|
|
297
|
+
*/
|
|
298
|
+
createdAt: string;
|
|
299
|
+
/** @description The endpoint's SHA-256, base64url without padding: how a browser finds its own device here without the list holding endpoints. */
|
|
300
|
+
endpointHash: string;
|
|
301
|
+
};
|
|
302
|
+
PushDeviceRename: {
|
|
303
|
+
name: string;
|
|
304
|
+
};
|
|
305
|
+
PushTestRequest: {
|
|
306
|
+
/** @description The app's own path the notification opens, starting with one /. */
|
|
307
|
+
url: string;
|
|
308
|
+
};
|
|
262
309
|
/** @description A repeating schedule (RecurrenceField, foundation_backend.recurrence). The rule's days, each at every one of its times, read in its zone. */
|
|
263
310
|
Recurrence: {
|
|
264
311
|
/** @description RFC 5545's RRULE value, without DTSTART: FREQ (daily, weekly, monthly, yearly), INTERVAL, BYMONTH, BYMONTHDAY (-1 is the last day), BYDAY (an nth for monthly and yearly: 2TU, -1FR), UNTIL (a date, YYYYMMDD, the last day it can fall on) or COUNT (occurrences, each time of each day), and WKST (the day weeks start on, MO when left out: it moves an every-N-weeks rule's weeks). "FREQ=MONTHLY;BYDAY=2TU", "FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;WKST=SU". */
|
|
@@ -567,6 +614,29 @@ export interface operations {
|
|
|
567
614
|
500: components["responses"]["ServerError"];
|
|
568
615
|
};
|
|
569
616
|
};
|
|
617
|
+
listPushDevices: {
|
|
618
|
+
parameters: {
|
|
619
|
+
query?: never;
|
|
620
|
+
header?: never;
|
|
621
|
+
path?: never;
|
|
622
|
+
cookie?: never;
|
|
623
|
+
};
|
|
624
|
+
requestBody?: never;
|
|
625
|
+
responses: {
|
|
626
|
+
/** @description OK. */
|
|
627
|
+
200: {
|
|
628
|
+
headers: {
|
|
629
|
+
[name: string]: unknown;
|
|
630
|
+
};
|
|
631
|
+
content: {
|
|
632
|
+
"application/json": components["schemas"]["PushDevice"][];
|
|
633
|
+
};
|
|
634
|
+
};
|
|
635
|
+
401: components["responses"]["UnauthorizedError"];
|
|
636
|
+
404: components["responses"]["NotFoundError"];
|
|
637
|
+
500: components["responses"]["ServerError"];
|
|
638
|
+
};
|
|
639
|
+
};
|
|
570
640
|
savePushSubscription: {
|
|
571
641
|
parameters: {
|
|
572
642
|
query?: never;
|
|
@@ -618,4 +688,64 @@ export interface operations {
|
|
|
618
688
|
500: components["responses"]["ServerError"];
|
|
619
689
|
};
|
|
620
690
|
};
|
|
691
|
+
renamePushDevice: {
|
|
692
|
+
parameters: {
|
|
693
|
+
query?: never;
|
|
694
|
+
header?: never;
|
|
695
|
+
path: {
|
|
696
|
+
id: number;
|
|
697
|
+
};
|
|
698
|
+
cookie?: never;
|
|
699
|
+
};
|
|
700
|
+
requestBody: {
|
|
701
|
+
content: {
|
|
702
|
+
"application/json": components["schemas"]["PushDeviceRename"];
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
responses: {
|
|
706
|
+
/** @description Renamed. */
|
|
707
|
+
200: {
|
|
708
|
+
headers: {
|
|
709
|
+
[name: string]: unknown;
|
|
710
|
+
};
|
|
711
|
+
content: {
|
|
712
|
+
"application/json": components["schemas"]["PushDevice"];
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
401: components["responses"]["UnauthorizedError"];
|
|
716
|
+
404: components["responses"]["NotFoundError"];
|
|
717
|
+
422: components["responses"]["ValidationError"];
|
|
718
|
+
500: components["responses"]["ServerError"];
|
|
719
|
+
};
|
|
720
|
+
};
|
|
721
|
+
sendTestPush: {
|
|
722
|
+
parameters: {
|
|
723
|
+
query?: never;
|
|
724
|
+
header?: never;
|
|
725
|
+
path: {
|
|
726
|
+
id: number;
|
|
727
|
+
};
|
|
728
|
+
cookie?: never;
|
|
729
|
+
};
|
|
730
|
+
requestBody: {
|
|
731
|
+
content: {
|
|
732
|
+
"application/json": components["schemas"]["PushTestRequest"];
|
|
733
|
+
};
|
|
734
|
+
};
|
|
735
|
+
responses: {
|
|
736
|
+
/** @description Taken by the device's push service. */
|
|
737
|
+
204: {
|
|
738
|
+
headers: {
|
|
739
|
+
[name: string]: unknown;
|
|
740
|
+
};
|
|
741
|
+
content?: never;
|
|
742
|
+
};
|
|
743
|
+
401: components["responses"]["UnauthorizedError"];
|
|
744
|
+
404: components["responses"]["NotFoundError"];
|
|
745
|
+
422: components["responses"]["ValidationError"];
|
|
746
|
+
429: components["responses"]["RateLimitedError"];
|
|
747
|
+
500: components["responses"]["ServerError"];
|
|
748
|
+
502: components["responses"]["ServerError"];
|
|
749
|
+
};
|
|
750
|
+
};
|
|
621
751
|
}
|
|
@@ -4,8 +4,9 @@ import { cn } from 'cn';
|
|
|
4
4
|
import { Button } from '../ui/button.js';
|
|
5
5
|
import { Skeleton } from '../ui/skeleton.js';
|
|
6
6
|
import { Notice } from './notice.js';
|
|
7
|
+
import { PUSH_STATUS_WORDS } from './push-status-words.js';
|
|
7
8
|
const DEFAULT_DESCRIPTION = 'Get a notification on this device at the times you set, even when the app is closed. Your browser will ask first.';
|
|
8
9
|
export function AllowReminders({ push, description = DEFAULT_DESCRIPTION, className }) {
|
|
9
10
|
const { status, pending, error } = push;
|
|
10
|
-
return (_jsxs("div", { "data-slot": "allow-reminders", className: cn('flex flex-col gap-3', className), "aria-busy": status === undefined || pending, children: [status === undefined && _jsx(Skeleton, { className: "h-9 w-full max-w-md" }), status === 'off' && (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm text-foreground", children: description }), _jsx("div", { children: _jsxs(Button, { onClick: push.enable, disabled: pending, children: [_jsx(BellIcon, { "aria-hidden": "true" }), pending ? 'Turning on…' : 'Allow Reminders'] }) })] })), status === 'on' && (_jsx(Notice, { tone: "success", icon: BellIcon, action: _jsxs(Button, { size: "sm", variant: "outline", onClick: push.disable, disabled: pending, children: [_jsx(BellOffIcon, { "aria-hidden": "true" }), pending ? 'Turning off…' : 'Turn Off'] }), children: "Reminders are on for this device." })), status === 'needs-install' && (_jsx(Notice, { title:
|
|
11
|
+
return (_jsxs("div", { "data-slot": "allow-reminders", className: cn('flex flex-col gap-3', className), "aria-busy": status === undefined || pending, children: [status === undefined && _jsx(Skeleton, { className: "h-9 w-full max-w-md" }), status === 'off' && (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm text-foreground", children: description }), _jsx("div", { children: _jsxs(Button, { onClick: push.enable, disabled: pending, children: [_jsx(BellIcon, { "aria-hidden": "true" }), pending ? 'Turning on…' : 'Allow Reminders'] }) })] })), status === 'on' && (_jsx(Notice, { tone: "success", icon: BellIcon, action: _jsxs(Button, { size: "sm", variant: "outline", onClick: push.disable, disabled: pending, children: [_jsx(BellOffIcon, { "aria-hidden": "true" }), pending ? 'Turning off…' : 'Turn Off'] }), children: "Reminders are on for this device." })), status === 'needs-install' && (_jsx(Notice, { title: PUSH_STATUS_WORDS['needs-install'].title, children: PUSH_STATUS_WORDS['needs-install'].text })), status === 'blocked' && (_jsx(Notice, { tone: "warning", title: PUSH_STATUS_WORDS.blocked.title, icon: BellOffIcon, children: PUSH_STATUS_WORDS.blocked.text })), (status === 'unsupported' || status === 'mock' || status === 'unavailable') && (_jsx("p", { className: "text-sm text-muted-foreground", children: PUSH_STATUS_WORDS[status].text })), error && (_jsx("p", { role: "alert", className: "text-sm text-destructive-text", children: error }))] }));
|
|
11
12
|
}
|
|
@@ -97,7 +97,7 @@ import { DEFAULT_HIGHLIGHT, highlightHandler, isHighlightColor, remarkHighlightN
|
|
|
97
97
|
import { textTopHeading } from '../../lib/markdown-top-heading.js';
|
|
98
98
|
import { MarkdownMergeError, markdownStyle, mergeMarkdown } from '../../lib/markdown-merge.js';
|
|
99
99
|
import { holdPendingEdit } from '../../lib/pending-edits.js';
|
|
100
|
-
import { foldStore, listenForOtherTabs } from '../../hooks/fold-store.js';
|
|
100
|
+
import { foldStore, headingStore, listenForOtherTabs } from '../../hooks/fold-store.js';
|
|
101
101
|
import { toggleFold } from '../../lib/markdown-fold.js';
|
|
102
102
|
import { DEFAULT_HEADING_LEVEL } from './prose-look.js';
|
|
103
103
|
import { foldPlugin, setFolds, shownEnd } from './rich-text-fold.js';
|
|
@@ -564,10 +564,21 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
564
564
|
};
|
|
565
565
|
openLinkRef.current = openLink;
|
|
566
566
|
// Folding by headings, with `foldKey` (read once, when it mounts):
|
|
567
|
-
// the fold store is the state, the plugin draws it
|
|
567
|
+
// the fold store is the state, the plugin draws it, and publishes the
|
|
568
|
+
// headings for NotesOutline under the same key.
|
|
569
|
+
const headingsOwner = {};
|
|
568
570
|
const folds = foldKey === undefined
|
|
569
571
|
? []
|
|
570
|
-
: [
|
|
572
|
+
: [
|
|
573
|
+
$prose(() => foldPlugin({
|
|
574
|
+
initial: foldStore.get(foldKey),
|
|
575
|
+
onChange: (folded) => foldStore.set(foldKey, folded),
|
|
576
|
+
onHeadings: (headings) => {
|
|
577
|
+
if (!cancelled)
|
|
578
|
+
headingStore.publish(foldKey, headingsOwner, headings);
|
|
579
|
+
},
|
|
580
|
+
})),
|
|
581
|
+
];
|
|
571
582
|
const onFold = foldKey === undefined ? undefined : (id) => foldStore.set(foldKey, toggleFold(foldStore.get(foldKey), id));
|
|
572
583
|
let stopFolds = () => { };
|
|
573
584
|
// Paste, copy, the editor's own keys and the placeholder.
|
|
@@ -993,6 +1004,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
993
1004
|
emit();
|
|
994
1005
|
cancelled = true;
|
|
995
1006
|
stopFolds();
|
|
1007
|
+
if (foldKey !== undefined)
|
|
1008
|
+
headingStore.withdraw(foldKey, headingsOwner);
|
|
996
1009
|
setEditorState(null);
|
|
997
1010
|
setEditorView(null);
|
|
998
1011
|
const editor = editorRef.current;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export type NotesOutlineProps = {
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The text whose headings are listed, beside <Markdown>. Beside a
|
|
4
|
+
* RichTextEditor with the same `foldKey` it isn't needed: the editor's
|
|
5
|
+
* headings are listed, current as it's edited, and this text is read
|
|
6
|
+
* only while no editor with the key is mounted.
|
|
7
|
+
*/
|
|
8
|
+
markdown?: string;
|
|
4
9
|
/** The `foldKey` of the <Markdown> or RichTextEditor showing the text. */
|
|
5
10
|
foldKey: string;
|
|
6
11
|
/**
|
|
@@ -8,13 +8,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
8
8
|
// (`depth`), so a long text's outline stays a list of its parts.
|
|
9
9
|
//
|
|
10
10
|
// The jump lands on the heading's fold button, so from the keyboard the
|
|
11
|
-
// next Enter folds what was just opened.
|
|
12
|
-
//
|
|
11
|
+
// next Enter folds what was just opened. Beside a RichTextEditor with
|
|
12
|
+
// the same `foldKey`, the outline lists the editor's own headings, as it
|
|
13
|
+
// edits (src/hooks/fold-store.ts's heading store), and parses nothing;
|
|
14
|
+
// otherwise it reads the Markdown it's given.
|
|
13
15
|
import { useMemo } from 'react';
|
|
14
16
|
import { ChevronRightIcon } from 'lucide-react';
|
|
15
17
|
import { cn } from 'cn';
|
|
16
18
|
import { Button } from '../ui/button.js';
|
|
17
|
-
import { useFolds } from '../../hooks/fold-store.js';
|
|
19
|
+
import { useFoldHeadings, useFolds } from '../../hooks/fold-store.js';
|
|
18
20
|
import { usePrefersReducedMotion } from '../../hooks/use-prefers-reduced-motion.js';
|
|
19
21
|
import { allFoldable, markdownFoldPlan, openTo } from '../../lib/markdown-fold.js';
|
|
20
22
|
const INDENT = ['pl-2', 'pl-6', 'pl-10', 'pl-14', 'pl-18', 'pl-22'];
|
|
@@ -32,9 +34,15 @@ function headingElement(foldKey, id) {
|
|
|
32
34
|
export function NotesOutline({ markdown, foldKey, depth = 2, minHeadings = 2, 'aria-label': ariaLabel = 'Outline', className, }) {
|
|
33
35
|
const [folded, setFolded] = useFolds(foldKey);
|
|
34
36
|
const reducedMotion = usePrefersReducedMotion();
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
37
|
+
const live = useFoldHeadings(foldKey);
|
|
38
|
+
// Parsed only with no editor publishing under the key.
|
|
39
|
+
const parsed = useMemo(() => (live || markdown === undefined ? null : markdownFoldPlan(markdown).headings), [live, markdown]);
|
|
40
|
+
const headings = live ?? parsed;
|
|
41
|
+
if (!headings)
|
|
42
|
+
return null;
|
|
43
|
+
const plan = { headings };
|
|
44
|
+
const top = Math.min(...headings.map((heading) => heading.level));
|
|
45
|
+
const listed = headings.filter((heading) => heading.level < top + depth);
|
|
38
46
|
if (listed.length < minHeadings)
|
|
39
47
|
return null;
|
|
40
48
|
const foldable = allFoldable(plan);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PushDevices } from '../../hooks/use-push-devices.js';
|
|
3
|
+
import type { PushPermission } from '../../hooks/use-push-permission.js';
|
|
4
|
+
export type ThisDeviceSettingProps = {
|
|
5
|
+
/** usePushPermission()'s result. */
|
|
6
|
+
push: PushPermission;
|
|
7
|
+
/** Defaults to "On This Device". */
|
|
8
|
+
label?: string;
|
|
9
|
+
/** The help line while it can be switched; defaults to what it does. */
|
|
10
|
+
help?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/** This device's notifications as a settings row with a switch, turned on from its click. */
|
|
13
|
+
export declare function ThisDeviceSetting({ push, label, help }: ThisDeviceSettingProps): import("react").JSX.Element;
|
|
14
|
+
export type TestNotificationSettingProps = {
|
|
15
|
+
push: PushPermission;
|
|
16
|
+
/** The app's own path the notification opens. Defaults to this page's. */
|
|
17
|
+
url?: string;
|
|
18
|
+
/** usePushDevices(push)'s result; left out, it's fetched. */
|
|
19
|
+
devices?: PushDevices;
|
|
20
|
+
/** Defaults to "Send a Test". */
|
|
21
|
+
label?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Send a Test: one notification to this device, its result on the row's own line. */
|
|
24
|
+
export declare function TestNotificationSetting({ devices, label, ...props }: TestNotificationSettingProps): import("react").JSX.Element;
|
|
25
|
+
export type NotificationDevicesProps = {
|
|
26
|
+
push: PushPermission;
|
|
27
|
+
/** usePushDevices(push)'s result; left out, it's fetched. */
|
|
28
|
+
devices?: PushDevices;
|
|
29
|
+
/** Defaults to "Devices". */
|
|
30
|
+
label?: string;
|
|
31
|
+
help?: ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The account's devices that get notifications, as a settings row with the
|
|
35
|
+
* list under its label: each named (renamed in place), when it was added,
|
|
36
|
+
* This Device on this one, and Remove.
|
|
37
|
+
*/
|
|
38
|
+
export declare function NotificationDevices({ push, devices, label, help }: NotificationDevicesProps): import("react").JSX.Element;
|