@wcstack/share 1.20.0 → 1.21.1

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 CHANGED
@@ -88,6 +88,12 @@ npm install @wcstack/share
88
88
  | `loading` | `wcs-share:loading-changed` | `share()` 呼び出しが進行中なら `true`。 |
89
89
  | `error` | `wcs-share:error` | 真のプラットフォーム障害(ユーザーが共有シートをキャンセルした場合を**除く**すべて)。まだ失敗が無い場合、または次の `share()` 呼び出しでリセットされた後は `null`。 |
90
90
  | `cancelled` | `wcs-share:cancelled-changed` | ユーザーがネイティブ共有シートを閉じた(`AbortError`)場合に `true`。`error` を条件にしたバインディングが日常的なキャンセルに反応しないよう、`error` とは独立している。 |
91
+ | `errorInfo` | `wcs-share:error-info-changed` | serializable な失敗 taxonomy(安定 `code` / `phase` / `recoverable`)、または `null`。追加的で `error` の shape は不変。`code` は unsupported なら `capability-missing`、真の失敗なら `share-failed`。 |
92
+
93
+ **並行制御。** 共有シートはシステムに1つのモーダル面なので、`<wcs-share>` は共有
94
+ io-core lane を `exhaust` policy で用いる: 1つの `share()` が進行中の間、2回目の呼び出しは
95
+ 冪等な **no-op**(2つ目のシートを開かず `null` を返す)となり、進行中の呼び出しの結果を
96
+ 汚さない。
91
97
 
92
98
  `cancelled` と `error` はどちらも、実際に `navigator.share()` を呼び出す `share()` 呼び出しの **開始時** にリセットされる(`false` / `null`)ため、前回の呼び出しの古い結果がその呼び出しの結果に残り続けることはありません。唯一の例外が unsupported 早期リターン(`navigator.share` が存在しない場合。後述)です — このリセットが走る前に return するため、前回呼び出しの `cancelled` が `true` のまま残り、新たに設定された unsupported の `error` と同時に立つことがあります。`navigator.share` がセッション途中で消失するのは非現実的なため、これは限定的なエッジケースです。
93
99
 
package/README.md CHANGED
@@ -88,6 +88,12 @@ Because `share()` must run from within a real user gesture (a click handler), th
88
88
  | `loading` | `wcs-share:loading-changed` | `true` while a `share()` call is in flight. |
89
89
  | `error` | `wcs-share:error` | A genuine platform failure (anything **other than** the user cancelling the share sheet). `null` when there has been no failure yet, or after the next `share()` call resets it. |
90
90
  | `cancelled` | `wcs-share:cancelled-changed` | `true` when the user dismissed the native share sheet (`AbortError`). Kept independent of `error` so bindings gated on `error` do not react to routine cancellation. |
91
+ | `errorInfo` | `wcs-share:error-info-changed` | Serializable failure taxonomy (stable `code` / `phase` / `recoverable`), or `null`. Additive — the `error` shape is unchanged; `code` is `capability-missing` when unsupported or `share-failed` on a genuine failure. |
92
+
93
+ **Concurrency.** A share sheet is a single system-modal surface, so `<wcs-share>`
94
+ runs its calls through the shared io-core lane with the `exhaust` policy: while one
95
+ `share()` is in flight, a second call is an idempotent **no-op** (it returns `null`
96
+ without opening a second sheet), leaving the in-flight call's result untouched.
91
97
 
92
98
  `cancelled` and `error` are both reset (`false` / `null`) at the **start** of a `share()` call that goes on to actually invoke `navigator.share()`, so a stale outcome from a previous call never lingers into that call's result. The one exception is the unsupported early-return (`navigator.share` missing, see below): it returns before that reset runs, so a `cancelled` left over from an earlier call can still read `true` alongside the freshly-set unsupported `error`. This is a narrow edge case in practice — a page losing `navigator.share` mid-session is not a realistic scenario.
93
99
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,56 @@
1
+ /**
2
+ * platform-capability.ts
3
+ *
4
+ * Phase 6(docs/architecture-hardening/09-remediation-design.md §7.2 /
5
+ * 07-browser-capability-variance.md)の browser capability 判定と error taxonomy の
6
+ * 汎用プリミティブ。node 固有の capability registry / error code は各パッケージが
7
+ * 別ファイルで宣言し、この汎用層(型 + assess 機構)を import する。
8
+ *
9
+ * 原則:
10
+ * - feature detection は境界(利用直前)で行う。module 評価時に browser global を
11
+ * 参照しない(SSR / worker で import が失敗しない)。
12
+ * - capability ID(`web.fetch` 等)は文字列を global property path として eval せず、
13
+ * registry が ID ごとに副作用のない presence probe を対応付ける。
14
+ * - availability / permission / readiness / activity / operation error を 1 つの
15
+ * `ready / unsupported / error` enum に畳まない。required 欠如は開始しない、
16
+ * optional 欠如は宣言済み fallback で readiness を `degraded` にする。
17
+ *
18
+ * 配置: 本ファイルは /io-core/ の単一正典であり、scripts/sync-io-core.mjs が
19
+ * 各 IO ノードの src/core/ へ生成コピー (AUTO-GENERATED, 編集禁止) を配布する。
20
+ * `protocol/wcBindable.ts` と同じ copy-distribution 方式で、ランタイム依存を導入せず
21
+ * 各パッケージのバンドルへ inline される (zero-runtime-dep / 自己完結 CDN を維持)。
22
+ * 編集はこの正典に対して行い、`node scripts/sync-io-core.mjs` で再配布する。
23
+ *
24
+ * pure(module 評価時に browser global 非参照)。
25
+ */
26
+ type Availability = "available" | "missing" | "unknown";
27
+ type PermissionState = "granted" | "denied" | "prompt" | "not-applicable" | "unknown";
28
+ type Readiness = "idle" | "ready" | "degraded";
29
+ type Activity = "inactive" | "active";
30
+ type PreconditionState = "satisfied" | "required" | "not-applicable";
31
+ /** operation error の phase(taxonomy)。 */
32
+ type WcsIoErrorPhase = "probe" | "start" | "execute" | "decode" | "commit" | "dispose";
33
+ /** serializable な error info(non-cloneable な cause とは分離。DevTools / remote へは info のみ)。 */
34
+ interface WcsIoErrorInfo {
35
+ readonly code: string;
36
+ readonly phase: WcsIoErrorPhase;
37
+ readonly recoverable: boolean;
38
+ readonly capabilityId?: string;
39
+ readonly message: string;
40
+ }
41
+ interface PlatformAssessment {
42
+ readonly availability: ReadonlyMap<string, Availability>;
43
+ readonly permission: PermissionState;
44
+ readonly readiness: Readiness;
45
+ readonly activity: Activity;
46
+ readonly preconditions: {
47
+ readonly secureContext: PreconditionState;
48
+ readonly userActivation: PreconditionState;
49
+ };
50
+ readonly epoch: number;
51
+ readonly lastError?: WcsIoErrorInfo;
52
+ }
53
+
1
54
  interface IWcBindableProperty {
2
55
  readonly name: string;
3
56
  readonly event: string;
@@ -13,7 +66,8 @@ interface IWcBindableCommand {
13
66
  }
14
67
  interface IWcBindable {
15
68
  readonly protocol: "wc-bindable";
16
- readonly version: 1;
69
+ /** Integer protocol version. All versions >= 1 are core-compatible. */
70
+ readonly version: number;
17
71
  readonly properties: readonly IWcBindableProperty[];
18
72
  readonly inputs?: readonly IWcBindableInput[];
19
73
  readonly commands?: readonly IWcBindableCommand[];
@@ -73,6 +127,8 @@ interface WcsShareCoreValues {
73
127
  * routine cancellation (docs/web-share-tag-design.md §3).
74
128
  */
75
129
  cancelled: boolean;
130
+ /** Last failure's serializable taxonomy (stable code/phase/recoverable), or null. */
131
+ errorInfo: WcsIoErrorInfo | null;
76
132
  }
77
133
  /**
78
134
  * Value types for the Shell (`<wcs-share>`) — identical observable surface to
@@ -89,24 +145,28 @@ declare function getConfig(): IConfig;
89
145
  * Headless Web Share primitive. A thin, framework-agnostic wrapper around
90
146
  * `navigator.share(data)` exposed through the wc-bindable protocol.
91
147
  *
92
- * This is a simplified derivative of `FetchCore._doFetch`
93
- * (docs/web-share-tag-design.md §2): it keeps the single `_gen` generation
94
- * guard, the same-value-guarded private setters, and the never-throw
95
- * try/catch wrapper, but drops `AbortController`/`abort()` entirely —
96
- * `navigator.share()` accepts no `AbortSignal` and there is no platform
97
- * mechanism for a caller to cancel an in-flight share dialog. A share dialog
98
- * is also a single system-modal surface (at most one open at a time), so the
99
- * "a new call supersedes the previous one" plumbing that `FetchCore` needs
100
- * has no counterpart here either.
148
+ * Concurrency is owned by the shared `OperationLane` (io-core) with the `exhaust`
149
+ * policy: a share dialog is a single system-modal surface, so while one share() is
150
+ * in flight a new call is rejected as an idempotent no-op instead of starting a
151
+ * second `navigator.share()`. This replaces the earlier dispose-only `_gen` guard,
152
+ * which relied on the platform rejecting the second call with `InvalidStateError`
153
+ * — but that let the rejected second call reset/overwrite the still-pending first
154
+ * call's `error`/`loading` state. The lane's owner generation still invalidates any
155
+ * in-flight share() on dispose() (a late resolve fails the commit guard).
156
+ *
157
+ * `navigator.share()` accepts no `AbortSignal` and there is no platform mechanism
158
+ * to cancel an in-flight share dialog, so the lane runs with `withSignal: false`.
101
159
  */
102
160
  declare class ShareCore extends EventTarget {
103
161
  static wcBindable: IWcBindable;
162
+ private static readonly REQUIRED_CAPABILITIES;
104
163
  private _target;
105
164
  private _value;
106
165
  private _loading;
107
166
  private _error;
108
167
  private _cancelled;
109
- private _gen;
168
+ private _errorInfo;
169
+ private _lane;
110
170
  private _ready;
111
171
  constructor(target?: EventTarget);
112
172
  get ready(): Promise<void>;
@@ -114,13 +174,31 @@ declare class ShareCore extends EventTarget {
114
174
  get loading(): boolean;
115
175
  get error(): any;
116
176
  get cancelled(): boolean;
177
+ /**
178
+ * The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /
179
+ * `recoverable` / `capabilityId`), or null. Exposed as an additive wc-bindable
180
+ * property (event `wcs-share:error-info-changed`); the existing `error`
181
+ * property/event are unchanged.
182
+ */
183
+ get errorInfo(): WcsIoErrorInfo | null;
184
+ /**
185
+ * Whether the required platform capability (`web.share`) is available right now —
186
+ * decided by call-time feature detection, not User-Agent. Core-only, additive.
187
+ */
188
+ get supported(): boolean;
189
+ /**
190
+ * Full platform assessment (availability / readiness / preconditions), probed at
191
+ * call time. Core-only opt-in dev / sidecar view.
192
+ */
193
+ get platformAssessment(): PlatformAssessment;
117
194
  observe(): Promise<void>;
118
195
  dispose(): void;
119
196
  private _setLoading;
120
197
  private _setValue;
121
198
  private _setError;
122
199
  private _setCancelled;
123
- private _api;
200
+ private _setErrorInfo;
201
+ private _commitErrorInfo;
124
202
  share(data?: WcsShareData): Promise<WcsShareData | null>;
125
203
  }
126
204
 
@@ -145,6 +223,7 @@ declare class WcsShare extends HTMLElement {
145
223
  get loading(): boolean;
146
224
  get error(): any;
147
225
  get cancelled(): boolean;
226
+ get errorInfo(): WcsIoErrorInfo | null;
148
227
  get connectedCallbackPromise(): Promise<void>;
149
228
  share(data?: WcsShareData): Promise<WcsShareData | null>;
150
229
  /**
@@ -166,5 +245,19 @@ declare class WcsShare extends HTMLElement {
166
245
  disconnectedCallback(): void;
167
246
  }
168
247
 
169
- export { ShareCore, WcsShare, bootstrapShare, getConfig };
170
- export type { IWritableConfig, IWritableTagNames, WcsShareCoreValues, WcsShareData, WcsShareValues };
248
+ /**
249
+ * shareCapabilities.ts
250
+ *
251
+ * Web Share node 固有の capability registry と error code。汎用の assess 機構・型は
252
+ * `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から
253
+ * import する。node 固有の宣言はこのハンドライトファイルに置き、生成コピーとは分離する。
254
+ */
255
+
256
+ /** 安定した share error code(taxonomy)。値は公開キーとして固定。 */
257
+ declare const WCS_SHARE_ERROR_CODE: {
258
+ readonly CapabilityMissing: "capability-missing";
259
+ readonly ShareFailed: "share-failed";
260
+ };
261
+
262
+ export { ShareCore, WCS_SHARE_ERROR_CODE, WcsShare, bootstrapShare, getConfig };
263
+ export type { IWritableConfig, IWritableTagNames, WcsIoErrorInfo, WcsIoErrorPhase, WcsShareCoreValues, WcsShareData, WcsShareValues };