@wcstack/notification 1.15.0 → 1.16.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.ja.md +40 -1
- package/README.md +36 -1
- package/dist/index.d.ts +3 -2
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -8,7 +8,7 @@ Notifications API をリアクティブな state と state 駆動のコマンド
|
|
|
8
8
|
`@wcstack/state` と組み合わせると、`<wcs-notify>` はパス契約で直接バインドできます:
|
|
9
9
|
|
|
10
10
|
- **command サーフェス**: `request`, `notify`, `close`, `closeAll`
|
|
11
|
-
- **input サーフェス**: `notice`(reactive な表示), `mode`, `body`, `icon`, `badge`, `tag`, `lang`, `dir`, `require-interaction`, `silent`, `renotify`
|
|
11
|
+
- **input サーフェス**: `notice`(reactive な表示), `mode`, `body`, `icon`, `badge`, `tag`, `lang`, `dir`, `require-interaction`, `silent`, `renotify`, `manual`
|
|
12
12
|
- **output state サーフェス**: `permission`, `granted`, `denied`, `prompt`, `unsupported`, `error`, `clicked`, `closed`, `shown`
|
|
13
13
|
|
|
14
14
|
`@wcstack/notification` は [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md)(Core / Shell / Binding Contract)アーキテクチャに従います:
|
|
@@ -90,6 +90,10 @@ npm install @wcstack/notification
|
|
|
90
90
|
|
|
91
91
|
### 4. クリックを読む
|
|
92
92
|
|
|
93
|
+
```html
|
|
94
|
+
<wcs-notify data-wcs="command.notify: $command.notify; eventToken.clicked: opened"></wcs-notify>
|
|
95
|
+
```
|
|
96
|
+
|
|
93
97
|
`clicked` / `closed` / `shown` は `{ tag, data, action }` を運びます。`tag` は通知の識別子(あなたの `options.tag`、省略時は生成された `wcs-<n>`)、`data` は `options.data` に渡した値、`action` は Service Worker のアクションボタン id(コンストラクタ経路では常に `""`)です。
|
|
94
98
|
|
|
95
99
|
完全なデモは `examples/state-notification-chat` を参照。
|
|
@@ -155,10 +159,45 @@ wireNotificationClicks();
|
|
|
155
159
|
## 注意・制限
|
|
156
160
|
|
|
157
161
|
- **通知はページより長生きする。** `<wcs-notify>` の切断(または Core の `dispose()`)は購読を解除しますが、開いている通知は**閉じません** —— 通知はページの終了後も残ることが意図です。閉じるには `close` / `closeAll` を使ってください。
|
|
162
|
+
- **`mode` は接続時に固定される。** バックエンドは要素の接続時(`observe(mode)`)に一度だけ選択され、`mode` の `observedAttributes` エントリはありません。接続済みの要素で `mode` 属性を変更しても、要素を再接続(削除して再挿入)するまで効果はありません。
|
|
163
|
+
- **SW バックエンドは `close` を中継しない。** `@wcstack/notification/sw` ヘルパは `notificationclick` のみを配線し、`notificationclose` は配線しません。そのため `sw` バックエンドでは `closed` / `wcs-notify:close` は発火しません(close 用のワーカー越え中継がない)。`clicked` はクリック中継で動作しますが、`closed` は constructor バックエンド限定の信号です。
|
|
158
164
|
- **Push API はスコープ外。** 本パッケージは Notifications API(ローカル通知)をラップします。サーバ起点の Push は別の関心事です。
|
|
159
165
|
- **サイレント失敗(zero-log)。** wcstack のゼロ依存哲学に沿い、`<wcs-notify>` は決してログ出力も throw もしません。API 不在 → `permission = "unsupported"`、未許可や表示失敗 → `error` プロパティ。`error` / `permission` をバインドして反応してください。
|
|
160
166
|
- **SSR(`@wcstack/server`)。** `static hasConnectedCallbackPromise = true` を宣言し `connectedCallbackPromise` を公開するため、サーバレンダラは接続時の権限プローブが解決するまで待ってからスナップショットします。
|
|
161
167
|
|
|
168
|
+
## 設定
|
|
169
|
+
|
|
170
|
+
`<wcs-notify>` はクリック **autoTrigger** を同梱しており、**既定で有効**です。有効な場合、最初に接続した `<wcs-notify>` が document レベルの `click` リスナーを 1 つ設置します。トリガ属性(`data-notifytarget="<id>"`)を持つ要素をクリックすると、その `id` の `<wcs-notify>` の `notify()` が呼ばれます:
|
|
171
|
+
|
|
172
|
+
```html
|
|
173
|
+
<wcs-notify id="app-notify"></wcs-notify>
|
|
174
|
+
<button data-notifytarget="app-notify" data-notifybody="新着メッセージが1件あります">
|
|
175
|
+
通知する
|
|
176
|
+
</button>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- タイトルは `data-notifytitle` があればそれ、無ければトリガ要素の trim 済み `textContent`。body は任意の `data-notifybody`。
|
|
180
|
+
- **document 全域**のクリックリスナーが既定で設置されるため、ショートカットを使わないなら無効化してください。設定は `bootstrapNotification(userConfig?)`(要素登録と設定適用を 1 回で行う)で適用し、`getConfig()` で実効設定(deep-frozen)を読み取れます:
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { bootstrapNotification, getConfig } from "@wcstack/notification";
|
|
184
|
+
|
|
185
|
+
// <wcs-notify> を登録しつつ document クリックリスナーを無効化:
|
|
186
|
+
bootstrapNotification({ autoTrigger: false });
|
|
187
|
+
// あるいはトリガ属性名を変更:
|
|
188
|
+
bootstrapNotification({ triggerAttribute: "data-notify" });
|
|
189
|
+
|
|
190
|
+
getConfig(); // deep-frozen の実効設定を読む
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
| 設定キー | 型 | 既定 | 説明 |
|
|
194
|
+
| ------------------ | --------- | ------------------- | ------------------------------------------------------------------ |
|
|
195
|
+
| `autoTrigger` | `boolean` | `true` | `data-notifytarget` 用の document レベルクリックリスナーを設置。 |
|
|
196
|
+
| `triggerAttribute` | `string` | `data-notifytarget` | クリック要素が `<wcs-notify>` を id で指すのに使う属性。 |
|
|
197
|
+
| `tagNames.notify` | `string` | `wcs-notify` | 登録するカスタム要素タグ名。 |
|
|
198
|
+
|
|
199
|
+
`bootstrapNotification()` は要素が接続される**前に**呼ぶと変更が反映されます。
|
|
200
|
+
|
|
162
201
|
## ヘッドレス利用(`NotificationCore`)
|
|
163
202
|
|
|
164
203
|
Core は DOM 依存が無く、`@wc-bindable/core` の `bind()` と直接使えます:
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ It is an **async primitive node** that turns the Notifications API into reactive
|
|
|
8
8
|
With `@wcstack/state`, `<wcs-notify>` can be bound directly through path contracts:
|
|
9
9
|
|
|
10
10
|
- **command surface**: `request`, `notify`, `close`, `closeAll`
|
|
11
|
-
- **input surface**: `notice` (reactive show), `mode`, `body`, `icon`, `badge`, `tag`, `lang`, `dir`, `require-interaction`, `silent`, `renotify`
|
|
11
|
+
- **input surface**: `notice` (reactive show), `mode`, `body`, `icon`, `badge`, `tag`, `lang`, `dir`, `require-interaction`, `silent`, `renotify`, `manual`
|
|
12
12
|
- **output state surface**: `permission`, `granted`, `denied`, `prompt`, `unsupported`, `error`, `clicked`, `closed`, `shown`
|
|
13
13
|
|
|
14
14
|
`@wcstack/notification` follows the [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md) (Core / Shell / Binding Contract) architecture:
|
|
@@ -159,10 +159,45 @@ It relays each click over `BroadcastChannel("wcs-notify")` (primary) and `client
|
|
|
159
159
|
## Notes & limitations
|
|
160
160
|
|
|
161
161
|
- **Notifications outlive the page.** Disconnecting `<wcs-notify>` (or calling `dispose()` on the Core) detaches its subscriptions but does **not** close open notifications — a notification is meant to persist past the page. Use `close` / `closeAll` to dismiss.
|
|
162
|
+
- **`mode` is fixed at connect time.** The backend is chosen once, when the element connects (`observe(mode)`); there is no `observedAttributes` entry for `mode`. Changing the `mode` attribute on an already-connected element has no effect until you re-connect it (remove and re-insert).
|
|
163
|
+
- **The SW backend does not relay `close`.** The `@wcstack/notification/sw` helper wires `notificationclick` only, not `notificationclose`. So under the `sw` backend `closed` / `wcs-notify:close` never fires (there is no cross-worker relay for close). `clicked` still works via the click relay; `closed` is a constructor-backend-only signal.
|
|
162
164
|
- **Push API is out of scope.** This package wraps the Notifications API (local notifications). Server-initiated Push is a separate concern.
|
|
163
165
|
- **Silent failure handling (zero-log).** Consistent with wcstack's zero-dependency philosophy, `<wcs-notify>` never logs or throws. A missing API → `permission = "unsupported"`; a not-granted permission or a show failure → the `error` property. Bind `error` / `permission` to react.
|
|
164
166
|
- **SSR (`@wcstack/server`).** Declares `static hasConnectedCallbackPromise = true` and exposes `connectedCallbackPromise`, so the server renderer waits for the connect-time permission probe before snapshotting.
|
|
165
167
|
|
|
168
|
+
## Configuration
|
|
169
|
+
|
|
170
|
+
`<wcs-notify>` ships a **click autoTrigger** that is **enabled by default**. When enabled, the first `<wcs-notify>` to connect installs a single document-level `click` listener. A click on any element carrying the trigger attribute (`data-notifytarget="<id>"`) calls `notify()` on the `<wcs-notify>` with that `id`:
|
|
171
|
+
|
|
172
|
+
```html
|
|
173
|
+
<wcs-notify id="app-notify"></wcs-notify>
|
|
174
|
+
<button data-notifytarget="app-notify" data-notifybody="You have 1 new message">
|
|
175
|
+
Notify me
|
|
176
|
+
</button>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- The title is `data-notifytitle` if present, otherwise the trigger element's trimmed `textContent`; the body is the optional `data-notifybody`.
|
|
180
|
+
- Because it is a **document-wide** click listener installed by default, disable it if you do not use the shortcut. Configuration is applied through `bootstrapNotification(userConfig?)` (which registers the element and applies the config in one call); `getConfig()` reads back the effective, deep-frozen config:
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { bootstrapNotification, getConfig } from "@wcstack/notification";
|
|
184
|
+
|
|
185
|
+
// Register <wcs-notify> and opt out of the document click listener:
|
|
186
|
+
bootstrapNotification({ autoTrigger: false });
|
|
187
|
+
// Or rename the trigger attribute:
|
|
188
|
+
bootstrapNotification({ triggerAttribute: "data-notify" });
|
|
189
|
+
|
|
190
|
+
getConfig(); // read the (deep-frozen) effective config
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
| Config key | Type | Default | Description |
|
|
194
|
+
| ------------------ | --------- | ------------------- | ----------------------------------------------------------------- |
|
|
195
|
+
| `autoTrigger` | `boolean` | `true` | Install the document-level click listener for `data-notifytarget`. |
|
|
196
|
+
| `triggerAttribute` | `string` | `data-notifytarget` | Attribute a clickable element uses to target a `<wcs-notify>` by id. |
|
|
197
|
+
| `tagNames.notify` | `string` | `wcs-notify` | Custom-element tag name to register. |
|
|
198
|
+
|
|
199
|
+
Call `setConfig()` / `bootstrapNotification()` **before** the elements connect for the change to take effect.
|
|
200
|
+
|
|
166
201
|
## Headless usage (`NotificationCore`)
|
|
167
202
|
|
|
168
203
|
The Core has no DOM dependency and can be used directly with `bind()` from `@wc-bindable/core`:
|
package/dist/index.d.ts
CHANGED
|
@@ -51,8 +51,9 @@ type NotificationPermissionRaw = "default" | "granted" | "denied";
|
|
|
51
51
|
* Which API actually shows the notification.
|
|
52
52
|
* - `"constructor"` — `new Notification(title, options)` (desktop only).
|
|
53
53
|
* - `"sw"` — `ServiceWorkerRegistration.showNotification()` (required on mobile/Android Chrome).
|
|
54
|
-
* - `"auto"` —
|
|
55
|
-
*
|
|
54
|
+
* - `"auto"` — always try the `Notification` constructor first (no registration
|
|
55
|
+
* pre-check), and fall back to the SW backend only if the constructor throws a
|
|
56
|
+
* `TypeError` (e.g. on mobile, where `new Notification()` is illegal).
|
|
56
57
|
*/
|
|
57
58
|
type NotifyBackend = "auto" | "sw" | "constructor";
|
|
58
59
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/notification",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Declarative desktop-notification component for Web Components. Framework-agnostic Notifications API wrapper via wc-bindable-protocol, with Service Worker support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|