@freedam/picker 0.0.0-stage → 1.2.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/CHANGELOG.md +82 -0
- package/README.md +122 -2
- package/dist/chunk-SF2R2FAB.js +2 -0
- package/dist/chunk-SF2R2FAB.js.map +1 -0
- package/dist/element-D6ex-aQ4.d.ts +401 -0
- package/dist/element.d.ts +1 -0
- package/dist/element.js +2 -0
- package/dist/element.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +471 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/picker.global.js +1 -0
- package/package.json +69 -5
- package/schema/payload.schema.json +316 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codes the picker page sends in an `error` message.
|
|
3
|
+
*
|
|
4
|
+
* Keep in sync with `App\Enums\PickerErrorCode`: `tests/Unit/Enums/PickerErrorCodeTest.php`
|
|
5
|
+
* reads this list and fails when the two differ. `auth_required` belongs to
|
|
6
|
+
* the iframe modes and `guest_access_unavailable` to the access without an
|
|
7
|
+
* account (version 1.1); the picker never sends `auth_required` in a popup.
|
|
8
|
+
*/
|
|
9
|
+
declare const SERVER_ERROR_CODES: readonly ["origin_denied", "feature_unavailable", "integration_suspended", "integration_unavailable", "insert_failed", "auth_required", "guest_access_unavailable"];
|
|
10
|
+
/** Codes the SDK raises itself, without the picker page. */
|
|
11
|
+
declare const SDK_ERROR_CODES: readonly ["popup_blocked", "invalid_options"];
|
|
12
|
+
type PickerServerErrorCode = (typeof SERVER_ERROR_CODES)[number];
|
|
13
|
+
type PickerSdkErrorCode = (typeof SDK_ERROR_CODES)[number];
|
|
14
|
+
type PickerErrorCode = PickerServerErrorCode | PickerSdkErrorCode;
|
|
15
|
+
/**
|
|
16
|
+
* English messages for the developer console. The picker page shows its own
|
|
17
|
+
* translated text to the person using it.
|
|
18
|
+
*/
|
|
19
|
+
declare const ERROR_MESSAGES: Record<PickerErrorCode, string>;
|
|
20
|
+
/** Error passed to `onError` and used to reject the promise of `open()`. */
|
|
21
|
+
declare class FreedamPickerError extends Error {
|
|
22
|
+
readonly code: PickerErrorCode;
|
|
23
|
+
constructor(code: PickerErrorCode, detail?: string);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Types of one inserted asset, as the picker sends it in a `select` message.
|
|
28
|
+
*
|
|
29
|
+
* Written by hand from `schema/payload.schema.json`, which is the reference.
|
|
30
|
+
* `tests/payload-schema.test.ts` checks typed examples of each variant
|
|
31
|
+
* against the schema: a field added to one and not the other fails it.
|
|
32
|
+
* Keys are snake_case, like the Freedam API.
|
|
33
|
+
*/
|
|
34
|
+
/** Position from the top-left corner, in percent: usable as `object-position: x% y%`. */
|
|
35
|
+
interface PickerFocusPoint {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
}
|
|
39
|
+
/** A named format of the publication channel, offered by the integration's profile. */
|
|
40
|
+
interface PickerFormat {
|
|
41
|
+
/** Name used in URL options (`fmt=hero`). */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Width to height, e.g. `16:9`. */
|
|
44
|
+
ratio: string;
|
|
45
|
+
url: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Metadata fields the integration's profile exposes. A field the profile
|
|
49
|
+
* exposes is always present, `null` when empty or hidden from the person who
|
|
50
|
+
* inserted the asset; a field it does not expose is absent.
|
|
51
|
+
*/
|
|
52
|
+
interface PickerMetadata {
|
|
53
|
+
title?: string | null;
|
|
54
|
+
description?: string | null;
|
|
55
|
+
alt?: string | null;
|
|
56
|
+
credit?: string | null;
|
|
57
|
+
copyright?: string | null;
|
|
58
|
+
keywords?: string[] | null;
|
|
59
|
+
/** Workspace metadata fields, by field key. Dates are `YYYY-MM-DD`. */
|
|
60
|
+
custom?: Record<string, PickerMetadataValue>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A value as the Freedam API returns it: a list for several values, a map of
|
|
64
|
+
* language code to text for a multilingual field, `YYYY-MM-DD` for a date.
|
|
65
|
+
*/
|
|
66
|
+
type PickerMetadataValue = string | number | boolean | null | Array<string | number | boolean> | Record<string, string>;
|
|
67
|
+
/** Fields shared by every asset type. */
|
|
68
|
+
interface PickerAssetBase {
|
|
69
|
+
/** Global asset ID, usable with `GET /api/v1/assets/{gaid}`. */
|
|
70
|
+
gaid: string;
|
|
71
|
+
/** Asset version at insertion. URLs always serve the current version. */
|
|
72
|
+
version: number;
|
|
73
|
+
mime_type: string;
|
|
74
|
+
/** Size of the original file, in bytes. */
|
|
75
|
+
file_size: number;
|
|
76
|
+
width: number | null;
|
|
77
|
+
height: number | null;
|
|
78
|
+
/** Main URL for what the person chose in the picker. */
|
|
79
|
+
url: string;
|
|
80
|
+
/**
|
|
81
|
+
* Signed URL of the asset's image (the image itself, a video's poster,
|
|
82
|
+
* a document's first page) with the literal text `{options}` where the
|
|
83
|
+
* URL options go: replace it with `w=800`, `w=800,h=600`, `fmt=hero`…
|
|
84
|
+
*/
|
|
85
|
+
url_template: string;
|
|
86
|
+
/**
|
|
87
|
+
* Widths `url_template` serves with `w=`, in pixels, smallest first: the
|
|
88
|
+
* channel's width tiers up to the original's width (version 1.2). The
|
|
89
|
+
* smallest tier when the original is narrower than it; every tier when
|
|
90
|
+
* the original's width is unknown. A width above the channel maximum
|
|
91
|
+
* answers 400, so build `srcset` from this list.
|
|
92
|
+
*/
|
|
93
|
+
widths: number[];
|
|
94
|
+
formats: PickerFormat[];
|
|
95
|
+
focus_point: PickerFocusPoint | null;
|
|
96
|
+
/** Image at least 400 pixels wide. */
|
|
97
|
+
thumbnail_url: string;
|
|
98
|
+
metadata: PickerMetadata;
|
|
99
|
+
/** Usage recorded at insertion; `DELETE /api/v1/usages/{usage_id}` removes it. */
|
|
100
|
+
usage_id: string;
|
|
101
|
+
/** Authorizes the usage operations of this insertion, and nothing else. */
|
|
102
|
+
usage_token: string;
|
|
103
|
+
}
|
|
104
|
+
/** Image file format chosen in the picker; `null` lets the browser negotiate it. */
|
|
105
|
+
type PickerFileFormat = 'avif' | 'webp' | 'jpeg';
|
|
106
|
+
interface PickerImageChoice {
|
|
107
|
+
/** Format name, or `null` for the original ratio. */
|
|
108
|
+
format: string | null;
|
|
109
|
+
file_format: PickerFileFormat | null;
|
|
110
|
+
}
|
|
111
|
+
interface PickerImage extends PickerAssetBase {
|
|
112
|
+
type: 'image';
|
|
113
|
+
choice: PickerImageChoice;
|
|
114
|
+
}
|
|
115
|
+
interface PickerSubtitle {
|
|
116
|
+
language: string;
|
|
117
|
+
label: string;
|
|
118
|
+
url: string;
|
|
119
|
+
is_default: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface PickerVideoChoice {
|
|
122
|
+
autoplay: boolean;
|
|
123
|
+
/** Always `true` when `autoplay` is `true`. */
|
|
124
|
+
muted: boolean;
|
|
125
|
+
loop: boolean;
|
|
126
|
+
controls: boolean;
|
|
127
|
+
/** Start position, in seconds. */
|
|
128
|
+
start: number;
|
|
129
|
+
/**
|
|
130
|
+
* Subtitles shown when playback starts: `null` for the video's default
|
|
131
|
+
* track, `'off'` for none, otherwise the language code of one of `subtitles`.
|
|
132
|
+
*/
|
|
133
|
+
subtitle_language: string | null;
|
|
134
|
+
}
|
|
135
|
+
interface PickerVideo extends PickerAssetBase {
|
|
136
|
+
type: 'video';
|
|
137
|
+
/** Equal to `player_url`. */
|
|
138
|
+
url: string;
|
|
139
|
+
player_url: string;
|
|
140
|
+
/** Responsive `<iframe>` of `player_url`. */
|
|
141
|
+
embed_html: string;
|
|
142
|
+
/** HLS manifest. */
|
|
143
|
+
stream_url: string;
|
|
144
|
+
poster_url: string;
|
|
145
|
+
/** In seconds; `null` when unknown. */
|
|
146
|
+
duration: number | null;
|
|
147
|
+
subtitles: PickerSubtitle[];
|
|
148
|
+
choice: PickerVideoChoice;
|
|
149
|
+
}
|
|
150
|
+
/** What the host inserts: a link to `url`, the `preview_url` image linked to `url`, or `embed_html`. */
|
|
151
|
+
type PickerDocumentForm = 'link' | 'thumbnail' | 'viewer';
|
|
152
|
+
/** Which file `url` delivers. */
|
|
153
|
+
type PickerDocumentFile = 'original' | 'pdf';
|
|
154
|
+
interface PickerDocumentChoice {
|
|
155
|
+
form: PickerDocumentForm;
|
|
156
|
+
file: PickerDocumentFile;
|
|
157
|
+
}
|
|
158
|
+
interface PickerDocument extends PickerAssetBase {
|
|
159
|
+
type: 'document';
|
|
160
|
+
/** `download_url` or `pdf_url`, as `choice.file` says. */
|
|
161
|
+
url: string;
|
|
162
|
+
download_url: string;
|
|
163
|
+
/** Equal to `download_url` for a PDF; `null` when no PDF version exists. */
|
|
164
|
+
pdf_url: string | null;
|
|
165
|
+
/** First page, served as an image; `null` when the document has no preview. */
|
|
166
|
+
preview_url: string | null;
|
|
167
|
+
/** Page-by-page viewer; `null` when no PDF version exists. */
|
|
168
|
+
viewer_url: string | null;
|
|
169
|
+
/** Responsive `<iframe>` of `viewer_url`; `null` when no PDF version exists. */
|
|
170
|
+
embed_html: string | null;
|
|
171
|
+
page_count: number | null;
|
|
172
|
+
extension: string;
|
|
173
|
+
choice: PickerDocumentChoice;
|
|
174
|
+
}
|
|
175
|
+
type PickerAsset = PickerImage | PickerVideo | PickerDocument;
|
|
176
|
+
type PickerAssetType = PickerAsset['type'];
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Protocol between the picker window (served on the workspace host) and the
|
|
180
|
+
* host page that opened it.
|
|
181
|
+
*
|
|
182
|
+
* This file is the only definition of the protocol: the SDK imports it, and
|
|
183
|
+
* the Freedam application imports it through the `@freedam/picker-protocol`
|
|
184
|
+
* alias (tsconfig.json and vite.config.ts) for the picker page's side.
|
|
185
|
+
*
|
|
186
|
+
* The protocol version is independent of the SDK version. A receiver ignores
|
|
187
|
+
* any message `type` it does not know, so adding a message is compatible.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
declare const PROTOCOL_VERSION = 1;
|
|
191
|
+
type PickerProtocolVersion = typeof PROTOCOL_VERSION;
|
|
192
|
+
/** Value of `source` in every message, to discard other scripts' messages quickly. */
|
|
193
|
+
declare const MESSAGE_SOURCE = "freedam-picker";
|
|
194
|
+
/** Most assets one insertion can return. */
|
|
195
|
+
declare const MAX_SELECTION = 50;
|
|
196
|
+
declare const PICKER_MODES: readonly ["popup", "modal", "inline", "tab"];
|
|
197
|
+
/**
|
|
198
|
+
* How the picker opens: in a popup window on the workspace host (`popup`),
|
|
199
|
+
* in an iframe over the host page (`modal`, version 1.1), in an iframe
|
|
200
|
+
* inside an element of the host page (`inline`, version 1.1) or in a new
|
|
201
|
+
* tab of the browser (`tab`, version 1.2).
|
|
202
|
+
*/
|
|
203
|
+
type PickerMode = (typeof PICKER_MODES)[number];
|
|
204
|
+
/** Modes that show the picker in a window of its own, which posts to `window.opener`. */
|
|
205
|
+
type PickerWindowMode = Extract<PickerMode, 'popup' | 'tab'>;
|
|
206
|
+
/** Modes that show the picker in an iframe of the host page. */
|
|
207
|
+
type PickerFrameMode = Exclude<PickerMode, PickerWindowMode>;
|
|
208
|
+
/** Smallest height of the inline iframe, in CSS pixels. */
|
|
209
|
+
declare const INLINE_MIN_HEIGHT = 480;
|
|
210
|
+
/** Values of the `types` option (version 1.2): the payload's asset types. */
|
|
211
|
+
declare const PICKER_ASSET_TYPES: readonly ["image", "video", "document"];
|
|
212
|
+
declare const SELECT_MODES: readonly ["single", "multiple"];
|
|
213
|
+
type PickerSelectMode = (typeof SELECT_MODES)[number];
|
|
214
|
+
/** Interface languages of Freedam. */
|
|
215
|
+
declare const PICKER_LOCALES: readonly ["en", "fr", "de", "es", "pt-BR", "zh-CN"];
|
|
216
|
+
type PickerLocale = (typeof PICKER_LOCALES)[number];
|
|
217
|
+
declare const PICKER_THEMES: readonly ["light", "dark", "auto"];
|
|
218
|
+
type PickerTheme = (typeof PICKER_THEMES)[number];
|
|
219
|
+
/** Sort fields, as for `sort_by` in `GET /api/v1/assets`. */
|
|
220
|
+
declare const SORT_FIELDS: readonly ["created_at", "updated_at", "title", "original_filename", "size", "relevance"];
|
|
221
|
+
type SortField = (typeof SORT_FIELDS)[number];
|
|
222
|
+
declare const SORT_DIRECTIONS: readonly ["asc", "desc"];
|
|
223
|
+
type SortDirection = (typeof SORT_DIRECTIONS)[number];
|
|
224
|
+
/**
|
|
225
|
+
* One condition of a filter tree, as for `filters` in `GET /api/v1/assets`,
|
|
226
|
+
* e.g. `{ type: 'filter', field: 'asset.file_category', operator: 'equals', value: 'Image' }`.
|
|
227
|
+
* The server validates fields, operators and values.
|
|
228
|
+
*/
|
|
229
|
+
interface RuleFilter {
|
|
230
|
+
type: 'filter';
|
|
231
|
+
field: string;
|
|
232
|
+
operator: string;
|
|
233
|
+
value?: unknown;
|
|
234
|
+
}
|
|
235
|
+
interface RuleGroup {
|
|
236
|
+
type: 'group';
|
|
237
|
+
operator: 'and' | 'or';
|
|
238
|
+
rules: RuleTree[];
|
|
239
|
+
}
|
|
240
|
+
type RuleTree = RuleFilter | RuleGroup;
|
|
241
|
+
/**
|
|
242
|
+
* Query parameters of the opening URL `https://{workspace}/picker/{integration}`.
|
|
243
|
+
* None of them is a secret. The picker page keeps them for the whole session
|
|
244
|
+
* of its window, including the reload after the person signs in.
|
|
245
|
+
*/
|
|
246
|
+
interface PickerOpenQuery {
|
|
247
|
+
protocol: `${PickerProtocolVersion}`;
|
|
248
|
+
/** Origin of the host page, checked by the server against the integration's origins. */
|
|
249
|
+
origin: string;
|
|
250
|
+
/** Random nonce, 22 base64url characters, repeated in every message. */
|
|
251
|
+
channel: string;
|
|
252
|
+
/** The server also reads it to start the iframe's own session (`modal`, `inline`). */
|
|
253
|
+
mode: PickerMode;
|
|
254
|
+
select: PickerSelectMode;
|
|
255
|
+
/** 1 to MAX_SELECTION, only with `select=multiple`. */
|
|
256
|
+
max?: string;
|
|
257
|
+
q?: string;
|
|
258
|
+
/** RuleTree as JSON. */
|
|
259
|
+
filters?: string;
|
|
260
|
+
sort_by?: SortField;
|
|
261
|
+
sort_direction?: SortDirection;
|
|
262
|
+
/** Comma-separated GAIDs; the picker ignores those the person cannot see. */
|
|
263
|
+
preselected?: string;
|
|
264
|
+
/**
|
|
265
|
+
* Comma-separated asset types, version 1.2. The picker offers only these
|
|
266
|
+
* among the integration's own types; a type the integration does not
|
|
267
|
+
* offer is ignored.
|
|
268
|
+
*/
|
|
269
|
+
types?: string;
|
|
270
|
+
/** Key of the integration's access without an account (`fdpk_…`), version 1.1. */
|
|
271
|
+
public_key?: string;
|
|
272
|
+
locale?: PickerLocale;
|
|
273
|
+
theme?: PickerTheme;
|
|
274
|
+
}
|
|
275
|
+
/** Fields of every message. */
|
|
276
|
+
interface PickerMessageBase {
|
|
277
|
+
source: typeof MESSAGE_SOURCE;
|
|
278
|
+
protocol: PickerProtocolVersion;
|
|
279
|
+
channel: string;
|
|
280
|
+
}
|
|
281
|
+
/** The picker page is interactive. Sent on every page load, including after sign-in. */
|
|
282
|
+
interface PickerReadyMessage extends PickerMessageBase {
|
|
283
|
+
type: 'ready';
|
|
284
|
+
integration: string;
|
|
285
|
+
}
|
|
286
|
+
/** The insertion succeeded; the picker window closes next. */
|
|
287
|
+
interface PickerSelectMessage extends PickerMessageBase {
|
|
288
|
+
type: 'select';
|
|
289
|
+
assets: PickerAsset[];
|
|
290
|
+
}
|
|
291
|
+
/** The person pressed Cancel; the picker window closes next. */
|
|
292
|
+
interface PickerCancelMessage extends PickerMessageBase {
|
|
293
|
+
type: 'cancel';
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The picker in an iframe shows its sign-in screen (version 1.1): the page
|
|
297
|
+
* loaded and waits for the person, and `ready` follows once they have
|
|
298
|
+
* signed in or continued without an account.
|
|
299
|
+
*/
|
|
300
|
+
interface PickerSignInMessage extends PickerMessageBase {
|
|
301
|
+
type: 'sign_in';
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Height the picker's content needs, in CSS pixels (version 1.1). The SDK
|
|
305
|
+
* applies it to the inline iframe, never below INLINE_MIN_HEIGHT, and
|
|
306
|
+
* ignores it in the other modes.
|
|
307
|
+
*/
|
|
308
|
+
interface PickerResizeMessage extends PickerMessageBase {
|
|
309
|
+
type: 'resize';
|
|
310
|
+
height: number;
|
|
311
|
+
}
|
|
312
|
+
/** An error the picker page also shows to the person; the window stays open. */
|
|
313
|
+
interface PickerErrorMessage extends PickerMessageBase {
|
|
314
|
+
type: 'error';
|
|
315
|
+
code: PickerServerErrorCode;
|
|
316
|
+
}
|
|
317
|
+
type PickerToHostMessage = PickerReadyMessage | PickerSelectMessage | PickerCancelMessage | PickerErrorMessage | PickerSignInMessage | PickerResizeMessage;
|
|
318
|
+
/**
|
|
319
|
+
* The host page removes the picker's iframe (version 1.1): sent by the SDK
|
|
320
|
+
* to the iframe, with the workspace origin as `targetOrigin`, just before it
|
|
321
|
+
* removes it after an insertion or a cancellation, or when the person
|
|
322
|
+
* closes the modal. The picker page does not answer it.
|
|
323
|
+
*/
|
|
324
|
+
interface HostCloseMessage extends PickerMessageBase {
|
|
325
|
+
type: 'close';
|
|
326
|
+
}
|
|
327
|
+
/** Messages of the host page to the picker; only the iframe modes send one. */
|
|
328
|
+
type HostToPickerMessage = HostCloseMessage;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* `<freedam-picker>`: a click inside the element opens the picker with the
|
|
332
|
+
* element's attributes as options. No shadow DOM, no style, no text: the
|
|
333
|
+
* host page puts its own button inside.
|
|
334
|
+
*
|
|
335
|
+
* ```html
|
|
336
|
+
* <freedam-picker workspace="acme.example.com" integration="int_8f3k2" select="multiple" max="5">
|
|
337
|
+
* <button type="button">Insert from Freedam</button>
|
|
338
|
+
* </freedam-picker>
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* `mode="modal"` shows the picker over the page; `mode="inline"` shows it in
|
|
342
|
+
* the element whose `id` is in the `container` attribute (or in the
|
|
343
|
+
* `container` property).
|
|
344
|
+
*
|
|
345
|
+
* Importing this module defines the element (`import '@freedam/picker/element'`);
|
|
346
|
+
* the script-tag build defines it too. A second definition is skipped, so the
|
|
347
|
+
* module can load twice.
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
declare const ELEMENT_NAME = "freedam-picker";
|
|
351
|
+
/** Events the element dispatches; they bubble and cross shadow roots. */
|
|
352
|
+
interface FreedamPickerEventMap {
|
|
353
|
+
'freedam-ready': CustomEvent<Record<string, never>>;
|
|
354
|
+
'freedam-select': CustomEvent<{
|
|
355
|
+
assets: PickerAsset[];
|
|
356
|
+
}>;
|
|
357
|
+
'freedam-cancel': CustomEvent<Record<string, never>>;
|
|
358
|
+
'freedam-error': CustomEvent<{
|
|
359
|
+
error: FreedamPickerError;
|
|
360
|
+
}>;
|
|
361
|
+
'freedam-close': CustomEvent<Record<string, never>>;
|
|
362
|
+
}
|
|
363
|
+
declare const BaseElement: typeof HTMLElement;
|
|
364
|
+
declare class FreedamPickerElement extends BaseElement {
|
|
365
|
+
private filtersValue;
|
|
366
|
+
private preselectedValue;
|
|
367
|
+
private containerValue;
|
|
368
|
+
constructor();
|
|
369
|
+
/** Initial filters; set this property instead of the `filters` attribute to pass an object. */
|
|
370
|
+
get filters(): RuleTree | undefined;
|
|
371
|
+
set filters(value: RuleTree | undefined);
|
|
372
|
+
/** GAIDs selected when the picker opens; set this property instead of the `preselected` attribute to pass an array. */
|
|
373
|
+
get preselected(): string[] | undefined;
|
|
374
|
+
set preselected(value: string[] | undefined);
|
|
375
|
+
/**
|
|
376
|
+
* Element that receives the picker with `mode="inline"`; set this property
|
|
377
|
+
* or the `container` attribute, which holds the element's `id`.
|
|
378
|
+
*/
|
|
379
|
+
get container(): HTMLElement | undefined;
|
|
380
|
+
set container(value: HTMLElement | undefined);
|
|
381
|
+
/**
|
|
382
|
+
* Opens the picker with the element's attributes, as a click inside it
|
|
383
|
+
* does. Call it from a click handler: browsers block windows opened
|
|
384
|
+
* outside a user gesture.
|
|
385
|
+
*/
|
|
386
|
+
open(): Promise<PickerAsset[] | null>;
|
|
387
|
+
private options;
|
|
388
|
+
private emit;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Defines `<freedam-picker>` unless the page already has it, for example when
|
|
392
|
+
* the script is loaded twice or with both the npm and the script-tag builds.
|
|
393
|
+
*/
|
|
394
|
+
declare function defineFreedamPickerElement(): void;
|
|
395
|
+
declare global {
|
|
396
|
+
interface HTMLElementTagNameMap {
|
|
397
|
+
'freedam-picker': FreedamPickerElement;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export { SORT_DIRECTIONS as $, type PickerImageChoice as A, type PickerMessageBase as B, type PickerMetadata as C, type PickerMetadataValue as D, ERROR_MESSAGES as E, FreedamPickerError as F, type PickerOpenQuery as G, type HostCloseMessage as H, INLINE_MIN_HEIGHT as I, type PickerReadyMessage as J, type PickerResizeMessage as K, type PickerSdkErrorCode as L, MAX_SELECTION as M, type PickerSelectMessage as N, type PickerServerErrorCode as O, type PickerSelectMode as P, type PickerSignInMessage as Q, type RuleTree as R, type SortField as S, type PickerSubtitle as T, type PickerToHostMessage as U, type PickerVideo as V, type PickerVideoChoice as W, type RuleFilter as X, type RuleGroup as Y, SDK_ERROR_CODES as Z, SERVER_ERROR_CODES as _, type SortDirection as a, SORT_FIELDS as a0, ELEMENT_NAME as a1, defineFreedamPickerElement as a2, type PickerAssetType as b, type PickerLocale as c, type PickerTheme as d, type PickerMode as e, type PickerAsset as f, FreedamPickerElement as g, type FreedamPickerEventMap as h, type HostToPickerMessage as i, PICKER_ASSET_TYPES as j, PICKER_LOCALES as k, PICKER_MODES as l, PICKER_THEMES as m, PROTOCOL_VERSION as n, type PickerCancelMessage as o, type PickerDocument as p, type PickerDocumentChoice as q, type PickerDocumentFile as r, type PickerDocumentForm as s, type PickerErrorCode as t, type PickerErrorMessage as u, type PickerFileFormat as v, type PickerFocusPoint as w, type PickerFormat as x, type PickerFrameMode as y, type PickerImage as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { a1 as ELEMENT_NAME, g as FreedamPickerElement, h as FreedamPickerEventMap, a2 as defineFreedamPickerElement } from './element-D6ex-aQ4.js';
|
package/dist/element.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as i,n as c}from"./chunk-SF2R2FAB.js";var l="freedam-picker",m="[data-freedam-picker-inline], [data-freedam-picker-overlay]",f=typeof HTMLElement>"u"?class{}:HTMLElement,s=class extends f{constructor(){super(),this.addEventListener("click",e=>{e.target instanceof Element&&e.target.closest(m)!==null||this.open().catch(()=>{})})}get filters(){return this.filtersValue}set filters(e){this.filtersValue=e}get preselected(){return this.preselectedValue}set preselected(e){this.preselectedValue=e}get container(){return this.containerValue}set container(e){this.containerValue=e}open(){let e;try{e=this.options()}catch(n){return n instanceof i&&this.emit("freedam-error",{error:n}),Promise.reject(n)}return c(e)}options(){let e=r=>this.getAttribute(r)??void 0,n=e("max"),o=e("sort-by"),d=e("sort-direction"),a=e("container");return{workspace:e("workspace"),integration:e("integration"),publicKey:e("public-key"),select:e("select"),max:n===void 0?void 0:Number(n),q:e("q"),filters:this.filtersValue??p(e("filters")),sort:o===void 0&&d===void 0?void 0:{by:o,direction:d},preselected:this.preselectedValue??u(e("preselected")),types:E(u(e("types"))),locale:e("locale"),theme:e("theme"),mode:e("mode"),container:this.containerValue??(a===void 0?void 0:document.getElementById(a)??void 0),onReady:()=>this.emit("freedam-ready",{}),onSelect:r=>this.emit("freedam-select",{assets:r}),onCancel:()=>this.emit("freedam-cancel",{}),onError:r=>this.emit("freedam-error",{error:r}),onClose:()=>this.emit("freedam-close",{})}}emit(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0,composed:!0}))}};function p(t){if(t!==void 0)try{return JSON.parse(t)}catch{throw new i("invalid_options","The `filters` attribute must be JSON.")}}function u(t){return t?.split(",").map(e=>e.trim()).filter(e=>e!=="")}function E(t){return t===void 0||t.length===0?void 0:t}function h(){typeof customElements<"u"&&customElements.get(l)===void 0&&customElements.define(l,s)}h();export{l as ELEMENT_NAME,s as FreedamPickerElement,h as defineFreedamPickerElement};
|
|
2
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/element.ts"],"sourcesContent":["/**\n * `<freedam-picker>`: a click inside the element opens the picker with the\n * element's attributes as options. No shadow DOM, no style, no text: the\n * host page puts its own button inside.\n *\n * ```html\n * <freedam-picker workspace=\"acme.example.com\" integration=\"int_8f3k2\" select=\"multiple\" max=\"5\">\n * <button type=\"button\">Insert from Freedam</button>\n * </freedam-picker>\n * ```\n *\n * `mode=\"modal\"` shows the picker over the page; `mode=\"inline\"` shows it in\n * the element whose `id` is in the `container` attribute (or in the\n * `container` property).\n *\n * Importing this module defines the element (`import '@freedam/picker/element'`);\n * the script-tag build defines it too. A second definition is skipped, so the\n * module can load twice.\n */\nimport { FreedamPickerError } from './errors';\nimport { open } from './open';\nimport type { PickerOptions } from './options';\nimport type { PickerAsset } from './payload';\nimport type { RuleTree } from './protocol';\n\nexport const ELEMENT_NAME = 'freedam-picker';\n\n/** Elements the SDK adds to the page for the iframe modes. */\nconst SDK_CONTROLS = '[data-freedam-picker-inline], [data-freedam-picker-overlay]';\n\n/** Attributes read when the picker opens. None is observed: changing one affects the next opening only. */\ntype ElementAttribute =\n | 'workspace'\n | 'integration'\n | 'select'\n | 'max'\n | 'q'\n | 'sort-by'\n | 'sort-direction'\n | 'locale'\n | 'theme'\n | 'filters'\n | 'preselected'\n | 'types'\n | 'public-key'\n | 'mode'\n | 'container';\n\n/** Events the element dispatches; they bubble and cross shadow roots. */\nexport interface FreedamPickerEventMap {\n 'freedam-ready': CustomEvent<Record<string, never>>;\n 'freedam-select': CustomEvent<{ assets: PickerAsset[] }>;\n 'freedam-cancel': CustomEvent<Record<string, never>>;\n 'freedam-error': CustomEvent<{ error: FreedamPickerError }>;\n 'freedam-close': CustomEvent<Record<string, never>>;\n}\n\n// Lets the module load where HTMLElement does not exist (server rendering);\n// the element is only defined in a browser.\nconst BaseElement: typeof HTMLElement = typeof HTMLElement === 'undefined' ? (class {} as typeof HTMLElement) : HTMLElement;\n\nexport class FreedamPickerElement extends BaseElement {\n private filtersValue: RuleTree | undefined;\n\n private preselectedValue: string[] | undefined;\n\n private containerValue: HTMLElement | undefined;\n\n constructor() {\n super();\n this.addEventListener('click', (event) => {\n // A click on the SDK's own controls (the fallback's buttons in an\n // inline container placed inside this element) is not a request\n // to open: after Cancel it would open the picker again.\n if (event.target instanceof Element && event.target.closest(SDK_CONTROLS) !== null) {\n return;\n }\n // Errors reach the page as freedam-error events.\n this.open().catch(() => undefined);\n });\n }\n\n /** Initial filters; set this property instead of the `filters` attribute to pass an object. */\n get filters(): RuleTree | undefined {\n return this.filtersValue;\n }\n\n set filters(value: RuleTree | undefined) {\n this.filtersValue = value;\n }\n\n /** GAIDs selected when the picker opens; set this property instead of the `preselected` attribute to pass an array. */\n get preselected(): string[] | undefined {\n return this.preselectedValue;\n }\n\n set preselected(value: string[] | undefined) {\n this.preselectedValue = value;\n }\n\n /**\n * Element that receives the picker with `mode=\"inline\"`; set this property\n * or the `container` attribute, which holds the element's `id`.\n */\n get container(): HTMLElement | undefined {\n return this.containerValue;\n }\n\n set container(value: HTMLElement | undefined) {\n this.containerValue = value;\n }\n\n /**\n * Opens the picker with the element's attributes, as a click inside it\n * does. Call it from a click handler: browsers block windows opened\n * outside a user gesture.\n */\n open(): Promise<PickerAsset[] | null> {\n let options: PickerOptions;\n try {\n options = this.options();\n } catch (error) {\n if (error instanceof FreedamPickerError) {\n this.emit('freedam-error', { error });\n }\n\n return Promise.reject(error);\n }\n\n return open(options);\n }\n\n private options(): PickerOptions {\n const attribute = (name: ElementAttribute): string | undefined => this.getAttribute(name) ?? undefined;\n const max = attribute('max');\n const sortBy = attribute('sort-by');\n const sortDirection = attribute('sort-direction');\n const containerId = attribute('container');\n\n return {\n workspace: attribute('workspace') as string,\n integration: attribute('integration') as string,\n publicKey: attribute('public-key'),\n select: attribute('select') as PickerOptions['select'],\n max: max === undefined ? undefined : Number(max),\n q: attribute('q'),\n filters: this.filtersValue ?? parseFilters(attribute('filters')),\n sort: sortBy === undefined && sortDirection === undefined ? undefined : ({ by: sortBy, direction: sortDirection } as PickerOptions['sort']),\n preselected: this.preselectedValue ?? parseList(attribute('preselected')),\n types: nonEmpty(parseList(attribute('types'))) as PickerOptions['types'],\n locale: attribute('locale') as PickerOptions['locale'],\n theme: attribute('theme') as PickerOptions['theme'],\n mode: attribute('mode') as PickerOptions['mode'],\n container: this.containerValue ?? (containerId === undefined ? undefined : ((document.getElementById(containerId) ?? undefined) as HTMLElement | undefined)),\n onReady: () => this.emit('freedam-ready', {}),\n onSelect: (assets) => this.emit('freedam-select', { assets }),\n onCancel: () => this.emit('freedam-cancel', {}),\n onError: (error) => this.emit('freedam-error', { error }),\n onClose: () => this.emit('freedam-close', {}),\n };\n }\n\n private emit<K extends keyof FreedamPickerEventMap>(type: K, detail: FreedamPickerEventMap[K]['detail']): void {\n this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));\n }\n}\n\nfunction parseFilters(value: string | undefined): RuleTree | undefined {\n if (value === undefined) {\n return undefined;\n }\n try {\n return JSON.parse(value) as RuleTree;\n } catch {\n throw new FreedamPickerError('invalid_options', 'The `filters` attribute must be JSON.');\n }\n}\n\n/** A comma-separated attribute (`preselected`, `types`) as a list, without blanks. */\nfunction parseList(value: string | undefined): string[] | undefined {\n return value\n ?.split(',')\n .map((item) => item.trim())\n .filter((item) => item !== '');\n}\n\n/** An empty `types` attribute means no restriction, as a missing one. */\nfunction nonEmpty(list: string[] | undefined): string[] | undefined {\n return list === undefined || list.length === 0 ? undefined : list;\n}\n\n/**\n * Defines `<freedam-picker>` unless the page already has it, for example when\n * the script is loaded twice or with both the npm and the script-tag builds.\n */\nexport function defineFreedamPickerElement(): void {\n if (typeof customElements !== 'undefined' && customElements.get(ELEMENT_NAME) === undefined) {\n customElements.define(ELEMENT_NAME, FreedamPickerElement);\n }\n}\n\ndefineFreedamPickerElement();\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'freedam-picker': FreedamPickerElement;\n }\n}\n"],"mappings":"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","names":["ELEMENT_NAME","SDK_CONTROLS","BaseElement","FreedamPickerElement","event","value","options","error","FreedamPickerError","open","attribute","name","max","sortBy","sortDirection","containerId","parseFilters","parseList","nonEmpty","assets","type","detail","item","list","defineFreedamPickerElement"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var $=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var pe=(e,r)=>{for(var t in r)$(e,t,{get:r[t],enumerable:!0})},me=(e,r,t,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ue(r))!fe.call(e,i)&&i!==t&&$(e,i,{get:()=>r[i],enumerable:!(l=de(r,i))||l.enumerable});return e};var ge=e=>me($({},"__esModule",{value:!0}),e);var Ae={};pe(Ae,{ERROR_MESSAGES:()=>I,FreedamPickerError:()=>g,INLINE_MIN_HEIGHT:()=>_,MAX_SELECTION:()=>O,PICKER_ASSET_TYPES:()=>v,PICKER_LOCALES:()=>x,PICKER_MODES:()=>H,PICKER_THEMES:()=>D,PROTOCOL_VERSION:()=>S,SDK_ERROR_CODES:()=>q,SERVER_ERROR_CODES:()=>U,SORT_DIRECTIONS:()=>N,SORT_FIELDS:()=>L,VERSION:()=>ce,open:()=>ae});module.exports=ge(Ae);var U=["origin_denied","feature_unavailable","integration_suspended","integration_unavailable","insert_failed","auth_required","guest_access_unavailable"],q=["popup_blocked","invalid_options"],I={origin_denied:"This page is not allowed to open the picker: the integration does not exist or does not list this origin.",feature_unavailable:"The asset picker is not available on this workspace.",integration_suspended:"This integration is suspended.",integration_unavailable:"This integration cannot be used: its profile or publication channel is missing or disabled.",insert_failed:"The selected assets could not be inserted.",auth_required:"The picker cannot run in an iframe of this page: the person continues in a separate window.",guest_access_unavailable:"This integration does not allow access without an account.",popup_blocked:"The browser blocked the picker window. Call open() from a click handler.",invalid_options:"Invalid picker options."},j=["insert_failed","guest_access_unavailable"];function X(e){return U.includes(e)}var g=class extends Error{constructor(r,t){super(t===void 0?I[r]:`${I[r]} ${t}`),this.name="FreedamPickerError",this.code=r}};var S=1,F="freedam-picker",Y="/picker/",O=50;var H=["popup","modal","inline","tab"],_=480;var v=["image","video","document"],Q=["single","multiple"],x=["en","fr","de","es","pt-BR","zh-CN"],D=["light","dark","auto"],L=["created_at","updated_at","title","original_filename","size","relevance"],N=["asc","desc"];var ke=["onReady","onSelect","onCancel","onError","onClose"],Ee=/^fdpk_[A-Za-z0-9]{32}$/,Pe=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*(?::\d{1,5})?$/i;function a(e){return new g("invalid_options",e)}function R(e,r){return e.includes(r)}function z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ye(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function ee(e){if(!z(e))throw a("open() expects an options object.");if(typeof e.workspace!="string"||!Pe.test(e.workspace)||!he(e.workspace))throw a('`workspace` must be the host of the workspace, without scheme or path, e.g. "acme.example.com".');if(typeof e.integration!="string"||!/^\S+$/.test(e.integration))throw a("`integration` must be the key of the integration, without spaces.");if(e.publicKey!==void 0&&(typeof e.publicKey!="string"||!Ee.test(e.publicKey)))throw a('`publicKey` must be the key of the access without an account: "fdpk_" followed by 32 letters and digits.');if(e.select!==void 0&&!R(Q,e.select))throw a('`select` must be "single" or "multiple".');if(e.max!==void 0){if(e.select!=="multiple")throw a('`max` requires `select: "multiple"`.');if(typeof e.max!="number"||!Number.isInteger(e.max)||e.max<1||e.max>50)throw a(`\`max\` must be an integer from 1 to ${50}.`)}if(e.q!==void 0&&(typeof e.q!="string"||e.q.length>500))throw a(`\`q\` must be a string of ${500} characters at most.`);if(e.filters!==void 0){if(!z(e.filters))throw a("`filters` must be a filter or group object.");try{JSON.stringify(e.filters)}catch{throw a("`filters` must be serializable to JSON.")}}if(e.sort!==void 0){if(!z(e.sort)||!R(L,e.sort.by))throw a(`\`sort.by\` must be one of ${L.join(", ")}.`);if(e.sort.direction!==void 0&&!R(N,e.sort.direction))throw a('`sort.direction` must be "asc" or "desc".')}if(e.preselected!==void 0){let r=e.preselected;if(!Array.isArray(r)||!r.every(t=>typeof t=="string"&&t!==""&&!t.includes(",")))throw a("`preselected` must be an array of GAIDs.")}if(e.types!==void 0){let r=e.types;if(!Array.isArray(r)||r.length===0||!r.every(t=>R(v,t)))throw a(`\`types\` must be a non-empty array of ${v.join(", ")}.`)}if(e.locale!==void 0&&!R(x,e.locale))throw a(`\`locale\` must be one of ${x.join(", ")}.`);if(e.theme!==void 0&&!R(D,e.theme))throw a('`theme` must be "light", "dark" or "auto".');if(e.mode!==void 0&&!R(H,e.mode))throw a('`mode` must be "popup", "tab", "modal" or "inline".');if(e.mode==="inline"){if(!ye(e.container)||!e.container.isConnected)throw a('`mode: "inline"` requires `container`, an element of the page.')}else if(e.container!==void 0)throw a('`container` requires `mode: "inline"`.');for(let r of ke)if(e[r]!==void 0&&typeof e[r]!="function")throw a(`\`${r}\` must be a function.`)}function he(e){try{return K(e),!0}catch{return!1}}function K(e){return new URL(`https://${e}`).origin}function re(e){if(!/^https?:\/\//.test(e))throw a("The host page must be served over HTTP or HTTPS.");return e}function te(){let e=new Uint8Array(16);crypto.getRandomValues(e);let r="";for(let t of e)r+=String.fromCharCode(t);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function W(e,r,t,l=e.mode??"popup"){let i=new URL(`${Y}${encodeURIComponent(e.integration)}`,K(e.workspace)),n=i.searchParams;n.set("protocol",String(1)),n.set("origin",r),n.set("channel",t),n.set("mode",l),n.set("select",e.select??"single"),e.max!==void 0&&n.set("max",String(e.max)),e.publicKey!==void 0&&n.set("public_key",e.publicKey),e.q!==void 0&&e.q!==""&&n.set("q",e.q),e.filters!==void 0&&n.set("filters",JSON.stringify(e.filters)),e.sort!==void 0&&(n.set("sort_by",e.sort.by),e.sort.direction!==void 0&&n.set("sort_direction",e.sort.direction)),e.preselected!==void 0&&e.preselected.length>0&&n.set("preselected",e.preselected.join(",")),e.types!==void 0&&n.set("types",[...new Set(e.types)].join(",")),e.locale!==void 0&&n.set("locale",e.locale),e.theme!==void 0&&n.set("theme",e.theme);let o=i.toString();if(o.length>6e3)throw a(`The picker URL would exceed ${6e3} characters: shorten \`filters\`, \`q\` or \`preselected\`.`);return o}var xe=1100,be=760,_e=1e4,Re="2147483000",we={en:{message:"Freedam cannot be shown in this page. Continue in a separate window.",open:"Open Freedam",cancel:"Cancel",close:"Close"},fr:{message:"Freedam ne peut pas s\u2019afficher dans cette page. Continuez dans une fen\xEAtre s\xE9par\xE9e.",open:"Ouvrir Freedam",cancel:"Annuler",close:"Fermer"},de:{message:"Freedam kann auf dieser Seite nicht angezeigt werden. Fahren Sie in einem separaten Fenster fort.",open:"Freedam \xF6ffnen",cancel:"Abbrechen",close:"Schlie\xDFen"},es:{message:"Freedam no se puede mostrar en esta p\xE1gina. Contin\xFAe en una ventana aparte.",open:"Abrir Freedam",cancel:"Cancelar",close:"Cerrar"},"pt-BR":{message:"O Freedam n\xE3o pode ser exibido nesta p\xE1gina. Continue em uma janela separada.",open:"Abrir o Freedam",cancel:"Cancelar",close:"Fechar"},"zh-CN":{message:"\u65E0\u6CD5\u5728\u6B64\u9875\u9762\u4E2D\u663E\u793A Freedam\u3002\u8BF7\u5728\u5355\u72EC\u7684\u7A97\u53E3\u4E2D\u7EE7\u7EED\u3002",open:"\u6253\u5F00 Freedam",cancel:"\u53D6\u6D88",close:"\u5173\u95ED"}};function Ce(e){let r=[e,document.documentElement.lang,typeof navigator>"u"?void 0:navigator.language];for(let t of r){if(typeof t!="string"||t==="")continue;let l=x.find(o=>o.toLowerCase()===t.toLowerCase());if(l!==void 0)return l;let i=t.split("-")[0].toLowerCase(),n=x.find(o=>o.split("-")[0]===i);if(n!==void 0)return n}return"en"}function y(e,r={}){let t=document.createElement(e);return Object.assign(t.style,r),t}function ne(e,r){let t=y("button",{font:"inherit",fontWeight:"600",padding:"10px 18px",borderRadius:"8px",cursor:"pointer",border:r?"1px solid #111827":"1px solid #d1d5db",background:r?"#111827":"#ffffff",color:r?"#ffffff":"#111827"});return t.type="button",t.textContent=e,t}function oe(e){let r=we[Ce(e.locale)],t=document.activeElement instanceof HTMLElement?document.activeElement:null,l=[],i=!1,n=y("iframe",{display:"block",width:"100%",height:"100%",border:"0",background:"#ffffff"});n.src=e.url,n.name=`freedam-picker-${e.channel}`,n.title="Freedam",n.setAttribute("data-freedam-picker",e.mode);let o,c;if(e.mode==="modal"){o=y("div",{position:"fixed",top:"0",right:"0",bottom:"0",left:"0",zIndex:Re,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",background:"rgba(17, 24, 39, 0.6)"}),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.setAttribute("aria-label","Freedam"),o.setAttribute("data-freedam-picker-overlay",""),c=y("div",{position:"relative",width:"100%",height:"100%",overflow:"hidden",background:"#ffffff",boxShadow:"0 24px 48px rgba(0, 0, 0, 0.3)"});let d=y("button",{position:"absolute",top:"6px",right:"8px",width:"32px",height:"32px",padding:"0",border:"0",borderRadius:"16px",background:"transparent",color:"#ffffff",fontSize:"24px",lineHeight:"32px",cursor:"pointer"});d.type="button",d.textContent="\xD7",d.setAttribute("aria-label",r.close),d.setAttribute("data-freedam-picker-close",""),d.addEventListener("click",()=>e.onDismiss()),o.append(c,d);let s=typeof window.matchMedia=="function"?window.matchMedia(`(max-width: ${640-.02}px)`):null,p=()=>{let f=s?.matches===!0;Object.assign(o.style,{padding:f?"44px 0 0":"48px 24px 24px"}),Object.assign(c.style,{maxWidth:f?"none":`${xe}px`,maxHeight:f?"none":`${be}px`,borderRadius:f?"0":"12px"})};p(),s!==null&&(s.addEventListener("change",p),l.push(()=>s.removeEventListener("change",p)));let u=f=>{if(f.key==="Escape"){e.onDismiss();return}if(f.key!=="Tab")return;let C=Array.from(o.querySelectorAll("button, iframe")),E=C[0],T=C[C.length-1],M=document.activeElement;E===void 0||T===void 0||(!(M instanceof Node)||!o.contains(M)?(f.preventDefault(),E.focus()):f.shiftKey&&M===E?(f.preventDefault(),T.focus()):!f.shiftKey&&M===T&&(f.preventDefault(),E.focus()))};document.addEventListener("keydown",u),l.push(()=>document.removeEventListener("keydown",u));let k=document.documentElement,A=k.style.overflow;k.style.overflow="hidden",l.push(()=>{k.style.overflow=A}),c.append(n),document.body.append(o)}else o=y("div",{display:"block",width:"100%",height:"100%",minHeight:`${480}px`}),o.setAttribute("data-freedam-picker-inline",""),c=o,n.style.minHeight=`${480}px`,c.append(n),e.container.append(o);e.mode==="modal"&&n.focus();let b=()=>c.querySelector("[data-freedam-picker-open]");return{mode:e.mode,target:()=>n.isConnected?n.contentWindow:null,isClosed:()=>i||!o.isConnected,focus:()=>(b()??n).focus(),close:(d=!0)=>{if(i)return;i=!0;let s=n.isConnected?n.contentWindow:null;if(s!==null){let p={source:F,protocol:1,channel:e.channel,type:"close"};s.postMessage(p,e.origin)}o.remove();for(let p of l)p();d&&e.mode==="modal"&&t!==null&&t.isConnected&&t.focus()},showFallback:()=>{if(i||b()!==null)return;let d=y("div",{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"16px",boxSizing:"border-box",width:"100%",height:"100%",minHeight:e.mode==="inline"?`${480}px`:"0",padding:"24px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',fontSize:"15px",lineHeight:"1.5",textAlign:"center"});d.setAttribute("data-freedam-picker-fallback","");let s=y("p",{margin:"0",maxWidth:"420px"});s.textContent=r.message;let p=y("div",{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"8px"}),u=ne(r.open,!0);u.setAttribute("data-freedam-picker-open",""),u.addEventListener("click",()=>e.onOpenWindow());let k=ne(r.cancel,!1);k.setAttribute("data-freedam-picker-cancel",""),k.addEventListener("click",()=>e.onDismiss()),p.append(u,k),d.append(s,p),n.remove(),c.append(d),e.mode==="modal"&&u.focus()},resize:d=>{e.mode!=="inline"||!Number.isFinite(d)||(n.style.height=`${Math.round(Math.min(_e,Math.max(480,d)))}px`,o.style.height="auto")}}}function G(e,r){let t=Math.min(1100,window.screen.availWidth||1100),l=Math.min(760,window.screen.availHeight||760),i=Math.round(window.screenX+(window.outerWidth-t)/2),n=Math.round(window.screenY+(window.outerHeight-l)/2);return se(window.open(e,`freedam-picker-${r}`,`popup=yes,width=${t},height=${l},left=${i},top=${n}`))}function ie(e,r){return se(window.open(e,`freedam-picker-${r}`))}function se(e){return e?{target:()=>e,isClosed:()=>e.closed,focus:()=>e.focus(),close:()=>e.close()}:null}var Te=500,Me=1e3,Oe=15e3,w=null;function ve(){return navigator.userActivation?.isActive===!0}function h(e,...r){if(typeof e=="function")try{e(...r)}catch(t){setTimeout(()=>{throw t})}}function Le(e,r){if(typeof e!="object"||e===null)return!1;let t=e;return t.source===F&&t.protocol===1&&t.channel===r&&typeof t.type=="string"}function ae(e){if(w!==null&&!w.surface().isClosed())return w.surface().focus(),w.promise;let r,t,l,i;try{ee(e),l=K(e.workspace),i=te();let s=re(window.location.origin);r=W(e,s,i),t=W(e,s,i,"popup")}catch(s){if(!(s instanceof g))throw s;return h(e?.onError,s),Promise.reject(s)}let n=e.mode??"popup",o,c=null,b={dismiss:()=>{},openWindow:()=>{}};if(n==="popup"||n==="tab"){let s=n==="tab"?ie(r,i):G(r,i);if(s===null){let p=new g("popup_blocked");return h(e.onError,p),Promise.reject(p)}o=s}else c=oe({url:r,channel:i,origin:l,mode:n,container:e.container,locale:e.locale,onDismiss:()=>b.dismiss(),onOpenWindow:()=>b.openWindow()}),o=c;let d=new Promise((s,p)=>{let u=!1,k=!1,A,f,C=()=>{if(c!==null){c.close(),E();return}A=setTimeout(()=>{o.isClosed()||o.close()},Me)},E=()=>{o.isClosed()&&(c?.close(),clearInterval(le),clearTimeout(A),clearTimeout(f),window.removeEventListener("message",V),w?.promise===d&&(w=null),u||(u=!0,h(e.onCancel),s(null)),h(e.onClose))},T=()=>{if(c===null||u)return!1;let P=G(t,i);return P===null?!1:(clearTimeout(f),c.close(!1),c=null,o=P,!0)};b.dismiss=()=>{o.close(),E()},b.openWindow=()=>{if(!T()&&!u){u=!0;let P=new g("popup_blocked");h(e.onError,P),p(P),o.close(),E()}};let M=()=>{ve()&&T()||c?.showFallback()},V=P=>{if(u||P.origin!==l||P.source!==o.target())return;let m=P.data;if(Le(m,i))switch(clearTimeout(f),m.type){case"ready":k||(k=!0,h(e.onReady));break;case"resize":typeof m.height=="number"&&c?.resize(m.height);break;case"select":if(!Array.isArray(m.assets))return;u=!0,h(e.onSelect,m.assets),s(m.assets),C();break;case"cancel":u=!0,h(e.onCancel),s(null),C();break;case"error":{if(!X(m.code))return;if(m.code==="auth_required"){M();return}let B=new g(m.code);h(e.onError,B),j.includes(m.code)||(u=!0,p(B));break}}},le=setInterval(E,Te);c!==null&&(f=setTimeout(()=>{u||c?.showFallback()},Oe)),window.addEventListener("message",V)});return w={surface:()=>o,promise:d},d}var ce="1.2.0";
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|