@wcstack/clipboard 1.12.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 +203 -0
- package/README.md +205 -0
- package/dist/auto.js +3 -0
- package/dist/auto.min.js +3 -0
- package/dist/index.d.ts +291 -0
- package/dist/index.esm.js +711 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
interface ITagNames {
|
|
2
|
+
readonly clipboard: string;
|
|
3
|
+
}
|
|
4
|
+
interface IWritableTagNames {
|
|
5
|
+
clipboard?: string;
|
|
6
|
+
}
|
|
7
|
+
interface IConfig {
|
|
8
|
+
readonly autoTrigger: boolean;
|
|
9
|
+
readonly triggerAttribute: string;
|
|
10
|
+
readonly tagNames: ITagNames;
|
|
11
|
+
}
|
|
12
|
+
interface IWritableConfig {
|
|
13
|
+
autoTrigger?: boolean;
|
|
14
|
+
triggerAttribute?: string;
|
|
15
|
+
tagNames?: IWritableTagNames;
|
|
16
|
+
}
|
|
17
|
+
interface IWcBindableProperty {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly event: string;
|
|
20
|
+
readonly getter?: (event: Event) => any;
|
|
21
|
+
}
|
|
22
|
+
interface IWcBindableInput {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly attribute?: string;
|
|
25
|
+
}
|
|
26
|
+
interface IWcBindableCommand {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly async?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface IWcBindable {
|
|
31
|
+
readonly protocol: "wc-bindable";
|
|
32
|
+
readonly version: number;
|
|
33
|
+
readonly properties: IWcBindableProperty[];
|
|
34
|
+
readonly inputs?: IWcBindableInput[];
|
|
35
|
+
readonly commands?: IWcBindableCommand[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Permission state for the Clipboard API, mirroring the Permissions API
|
|
39
|
+
* `PermissionState` plus `"unsupported"` for environments without
|
|
40
|
+
* `navigator.permissions` (or where the `clipboard-read` / `clipboard-write`
|
|
41
|
+
* permissions cannot be queried — e.g. Firefox, which does not expose them).
|
|
42
|
+
*/
|
|
43
|
+
type ClipboardPermissionState = "prompt" | "granted" | "denied" | "unsupported";
|
|
44
|
+
/**
|
|
45
|
+
* Normalized snapshot of a single `ClipboardItem` read via `read()`. Unlike the
|
|
46
|
+
* live `ClipboardItem` (whose `getType()` returns a fresh promise each call),
|
|
47
|
+
* every representation is eagerly resolved to a `Blob` so the data can flow
|
|
48
|
+
* through declarative binding without further async work.
|
|
49
|
+
*/
|
|
50
|
+
interface WcsClipboardReadItem {
|
|
51
|
+
/** MIME types present in this item (e.g. `["text/plain", "text/html"]`). */
|
|
52
|
+
types: string[];
|
|
53
|
+
/** Resolved blobs keyed by MIME type. */
|
|
54
|
+
data: Record<string, Blob>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Payload carried by the `wcs-clipboard:read` event — the result of a
|
|
58
|
+
* `readText()` or `read()` call.
|
|
59
|
+
*
|
|
60
|
+
* - `text` is the `text/plain` content when available (always set by
|
|
61
|
+
* `readText()`, and extracted from a `text/plain` representation by `read()`),
|
|
62
|
+
* otherwise `null`.
|
|
63
|
+
* - `items` is the structured snapshot from a rich `read()`, or `null` for a
|
|
64
|
+
* plain `readText()`.
|
|
65
|
+
*/
|
|
66
|
+
interface WcsClipboardReadDetail {
|
|
67
|
+
text: string | null;
|
|
68
|
+
items: WcsClipboardReadItem[] | null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Normalized Clipboard API failure. `name` mirrors the `DOMException.name`
|
|
72
|
+
* (e.g. `NotAllowedError`, `NotFoundError`); `unsupported` is surfaced as
|
|
73
|
+
* `NotSupportedError` when `navigator.clipboard` is absent (non-secure context
|
|
74
|
+
* or unsupported browser).
|
|
75
|
+
*/
|
|
76
|
+
interface WcsClipboardErrorDetail {
|
|
77
|
+
name: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Value types for ClipboardCore (headless) — the observable state properties.
|
|
82
|
+
* Use with `bind()` from `@wc-bindable/core` for compile-time type checking.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const core = new ClipboardCore();
|
|
87
|
+
* bind(core, (name: keyof WcsClipboardCoreValues, value) => { ... });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
interface WcsClipboardCoreValues {
|
|
91
|
+
text: string | null;
|
|
92
|
+
items: WcsClipboardReadItem[] | null;
|
|
93
|
+
loading: boolean;
|
|
94
|
+
error: WcsClipboardErrorDetail | null;
|
|
95
|
+
readPermission: ClipboardPermissionState;
|
|
96
|
+
writePermission: ClipboardPermissionState;
|
|
97
|
+
monitoring: boolean;
|
|
98
|
+
copied: string | null;
|
|
99
|
+
cut: string | null;
|
|
100
|
+
pasted: string | null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Value types for the Shell (`<wcs-clipboard>`) — identical observable surface
|
|
104
|
+
* to the Core.
|
|
105
|
+
*/
|
|
106
|
+
type WcsClipboardValues = WcsClipboardCoreValues;
|
|
107
|
+
interface WcsClipboardInputs {
|
|
108
|
+
/**
|
|
109
|
+
* When present, start monitoring document `copy` / `cut` / `paste` events on
|
|
110
|
+
* connect, publishing them as the `copied` / `cut` / `pasted` properties.
|
|
111
|
+
*/
|
|
112
|
+
monitor: boolean;
|
|
113
|
+
}
|
|
114
|
+
interface WcsClipboardCoreCommands {
|
|
115
|
+
writeText(text: string): Promise<void>;
|
|
116
|
+
write(items: ClipboardItem[]): Promise<void>;
|
|
117
|
+
readText(): Promise<void>;
|
|
118
|
+
read(): Promise<void>;
|
|
119
|
+
startMonitor(): void;
|
|
120
|
+
stopMonitor(): void;
|
|
121
|
+
}
|
|
122
|
+
/** Commands exposed on the Shell — identical surface to the Core. */
|
|
123
|
+
type WcsClipboardCommands = WcsClipboardCoreCommands;
|
|
124
|
+
|
|
125
|
+
declare function bootstrapClipboard(userConfig?: IWritableConfig): void;
|
|
126
|
+
|
|
127
|
+
declare function getConfig(): IConfig;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Headless clipboard primitive. A thin, framework-agnostic wrapper around the
|
|
131
|
+
* Clipboard API exposed through the wc-bindable protocol.
|
|
132
|
+
*
|
|
133
|
+
* It has two surfaces, mirroring the two distinct shapes of clipboard access:
|
|
134
|
+
* - **commands** — `writeText()` / `write()` push to the clipboard;
|
|
135
|
+
* `readText()` / `read()` pull from it. These are the `state → element`
|
|
136
|
+
* (command-token) and `element → state` (read result) paths. All four are
|
|
137
|
+
* async and never reject: failures surface through the `error` property so
|
|
138
|
+
* they flow into the declarative state, symmetrical with FetchCore /
|
|
139
|
+
* GeolocationCore.
|
|
140
|
+
* - **monitor** — `startMonitor()` / `stopMonitor()` subscribe to the document's
|
|
141
|
+
* `copy` / `cut` / `paste` events and republish them as the `copied` / `cut` /
|
|
142
|
+
* `pasted` properties (like TimerCore's continuous `start()` / `stop()`),
|
|
143
|
+
* toggling the `monitoring` flag. This is the event-token showcase: a user
|
|
144
|
+
* paste flows element → state declaratively.
|
|
145
|
+
*
|
|
146
|
+
* Clipboard also has permission gates, like GeolocationCore but doubled: read
|
|
147
|
+
* and write are separate permissions (`clipboard-read` / `clipboard-write`).
|
|
148
|
+
* `readPermission` / `writePermission` reflect `navigator.permissions.query`
|
|
149
|
+
* (`prompt` / `granted` / `denied`, or `unsupported`) and track their live
|
|
150
|
+
* `change` events.
|
|
151
|
+
*/
|
|
152
|
+
declare class ClipboardCore extends EventTarget {
|
|
153
|
+
static wcBindable: IWcBindable;
|
|
154
|
+
private _target;
|
|
155
|
+
private _text;
|
|
156
|
+
private _items;
|
|
157
|
+
private _loading;
|
|
158
|
+
private _error;
|
|
159
|
+
private _readPermission;
|
|
160
|
+
private _writePermission;
|
|
161
|
+
private _monitoring;
|
|
162
|
+
private _copied;
|
|
163
|
+
private _cut;
|
|
164
|
+
private _pasted;
|
|
165
|
+
private _readStatus;
|
|
166
|
+
private _writeStatus;
|
|
167
|
+
private _permissionSubscribed;
|
|
168
|
+
private _permGen;
|
|
169
|
+
private _acqGen;
|
|
170
|
+
constructor(target?: EventTarget);
|
|
171
|
+
get text(): string | null;
|
|
172
|
+
get items(): WcsClipboardReadItem[] | null;
|
|
173
|
+
get loading(): boolean;
|
|
174
|
+
get error(): WcsClipboardErrorDetail | null;
|
|
175
|
+
get readPermission(): ClipboardPermissionState;
|
|
176
|
+
get writePermission(): ClipboardPermissionState;
|
|
177
|
+
get monitoring(): boolean;
|
|
178
|
+
get copied(): string | null;
|
|
179
|
+
get cut(): string | null;
|
|
180
|
+
get pasted(): string | null;
|
|
181
|
+
private _setRead;
|
|
182
|
+
private _setLoading;
|
|
183
|
+
private _setError;
|
|
184
|
+
private _setReadPermission;
|
|
185
|
+
private _setWritePermission;
|
|
186
|
+
private _setMonitoring;
|
|
187
|
+
private _setCopied;
|
|
188
|
+
private _setCut;
|
|
189
|
+
private _setPasted;
|
|
190
|
+
/**
|
|
191
|
+
* Write plain text to the clipboard. Resolves once the write settles or fails
|
|
192
|
+
* — never rejects: failures surface through `error`. Requires transient
|
|
193
|
+
* activation (a user gesture), so call from a click handler / command-token.
|
|
194
|
+
*/
|
|
195
|
+
writeText(text: string): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Write rich `ClipboardItem`s (images, HTML, multiple MIME types) to the
|
|
198
|
+
* clipboard. Resolves once the write settles or fails — never rejects.
|
|
199
|
+
*/
|
|
200
|
+
write(items: ClipboardItem[]): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Read plain text from the clipboard, publishing it via `text` and the
|
|
203
|
+
* `wcs-clipboard:read` event. Resolves once the read settles or fails — never
|
|
204
|
+
* rejects. Requires focus + read permission.
|
|
205
|
+
*/
|
|
206
|
+
readText(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Read rich `ClipboardItem`s from the clipboard, eagerly resolving every
|
|
209
|
+
* representation to a `Blob`. A `text/plain` representation is also surfaced
|
|
210
|
+
* via `text`. Resolves once the read settles or fails — never rejects.
|
|
211
|
+
*/
|
|
212
|
+
read(): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Begin monitoring document `copy` / `cut` / `paste` events, republishing
|
|
215
|
+
* them as the `copied` / `cut` / `pasted` properties. Idempotent while already
|
|
216
|
+
* monitoring (mirrors GeolocationCore.watch()).
|
|
217
|
+
*/
|
|
218
|
+
startMonitor(): void;
|
|
219
|
+
stopMonitor(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Re-establish the permission `change` subscriptions after a dispose() — e.g.
|
|
222
|
+
* the Shell element was disconnected and then reconnected (reparented). No-op
|
|
223
|
+
* while a subscription is already live, so the first connect after
|
|
224
|
+
* construction does not double-subscribe.
|
|
225
|
+
*/
|
|
226
|
+
reinitPermission(): void;
|
|
227
|
+
/**
|
|
228
|
+
* Detach the live permission `change` listeners and any monitor listeners, and
|
|
229
|
+
* neutralize in-flight async ops. Call from the Shell's `disconnectedCallback`
|
|
230
|
+
* so a removed element does not leak subscriptions or dispatch on a torn-down
|
|
231
|
+
* element. A later reconnect can re-subscribe via reinitPermission().
|
|
232
|
+
*/
|
|
233
|
+
dispose(): void;
|
|
234
|
+
private _runWrite;
|
|
235
|
+
private _runRead;
|
|
236
|
+
/**
|
|
237
|
+
* Shared async-op lifecycle for read/write: capability check, loading toggle,
|
|
238
|
+
* generation guard, never-reject error handling. When `op` returns a read
|
|
239
|
+
* detail it is published; when it returns null (a write) nothing is published.
|
|
240
|
+
*/
|
|
241
|
+
private _runOp;
|
|
242
|
+
private _onCopy;
|
|
243
|
+
private _onCut;
|
|
244
|
+
private _onPaste;
|
|
245
|
+
private _removeMonitorListeners;
|
|
246
|
+
private _selectionText;
|
|
247
|
+
private _initPermissions;
|
|
248
|
+
private _queryPermission;
|
|
249
|
+
private _onReadChange;
|
|
250
|
+
private _onWriteChange;
|
|
251
|
+
private _hasClipboard;
|
|
252
|
+
private _normalizeItems;
|
|
253
|
+
private _normalizeError;
|
|
254
|
+
private _unsupportedError;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare class WcsClipboard extends HTMLElement {
|
|
258
|
+
static wcBindable: IWcBindable;
|
|
259
|
+
private _core;
|
|
260
|
+
constructor();
|
|
261
|
+
get monitor(): boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Reflects the `monitor` boolean attribute only — it does NOT start or stop
|
|
264
|
+
* monitoring by itself. The attribute is read at connect time (see
|
|
265
|
+
* connectedCallback); toggling `el.monitor` after connect just flips the
|
|
266
|
+
* attribute. To start/stop monitoring imperatively, call `startMonitor()` /
|
|
267
|
+
* `stopMonitor()`.
|
|
268
|
+
*/
|
|
269
|
+
set monitor(value: boolean);
|
|
270
|
+
get text(): string | null;
|
|
271
|
+
get items(): WcsClipboardReadItem[] | null;
|
|
272
|
+
get loading(): boolean;
|
|
273
|
+
get error(): WcsClipboardErrorDetail | null;
|
|
274
|
+
get readPermission(): ClipboardPermissionState;
|
|
275
|
+
get writePermission(): ClipboardPermissionState;
|
|
276
|
+
get monitoring(): boolean;
|
|
277
|
+
get copied(): string | null;
|
|
278
|
+
get cut(): string | null;
|
|
279
|
+
get pasted(): string | null;
|
|
280
|
+
writeText(text: string): Promise<void>;
|
|
281
|
+
write(items: ClipboardItem[]): Promise<void>;
|
|
282
|
+
readText(): Promise<void>;
|
|
283
|
+
read(): Promise<void>;
|
|
284
|
+
startMonitor(): void;
|
|
285
|
+
stopMonitor(): void;
|
|
286
|
+
connectedCallback(): void;
|
|
287
|
+
disconnectedCallback(): void;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { ClipboardCore, WcsClipboard, bootstrapClipboard, getConfig };
|
|
291
|
+
export type { ClipboardPermissionState, IWritableConfig, IWritableTagNames, WcsClipboardCommands, WcsClipboardCoreCommands, WcsClipboardCoreValues, WcsClipboardErrorDetail, WcsClipboardInputs, WcsClipboardReadDetail, WcsClipboardReadItem, WcsClipboardValues };
|