@uploadcare/file-uploader 1.11.0-alpha.2 → 1.11.0-alpha.3
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/abstract/UploaderPublicApi.js +1 -1
- package/blocks/CameraSource/CameraSource.d.ts +22 -169
- package/blocks/CameraSource/CameraSource.d.ts.map +1 -1
- package/blocks/CameraSource/CameraSource.js +126 -803
- package/blocks/CameraSource/camera-source.css +7 -105
- package/blocks/CloudImageEditorActivity/index.css +3 -3
- package/blocks/Config/Config.d.ts +2 -4
- package/blocks/Config/Config.d.ts.map +1 -1
- package/blocks/Config/Config.js +0 -2
- package/blocks/Config/initialConfig.d.ts.map +1 -1
- package/blocks/Config/initialConfig.js +0 -6
- package/blocks/Config/normalizeConfigValue.d.ts.map +1 -1
- package/blocks/Config/normalizeConfigValue.js +1 -17
- package/blocks/ExternalSource/ExternalSource.d.ts +20 -50
- package/blocks/ExternalSource/ExternalSource.d.ts.map +1 -1
- package/blocks/ExternalSource/ExternalSource.js +96 -99
- package/blocks/ExternalSource/MessageBridge.d.ts +20 -0
- package/blocks/ExternalSource/MessageBridge.d.ts.map +1 -0
- package/blocks/ExternalSource/MessageBridge.js +71 -0
- package/blocks/ExternalSource/buildThemeDefinition.d.ts +3 -0
- package/blocks/ExternalSource/buildThemeDefinition.d.ts.map +1 -0
- package/blocks/ExternalSource/buildThemeDefinition.js +47 -0
- package/blocks/ExternalSource/external-source.css +37 -22
- package/blocks/ExternalSource/types.d.ts +113 -0
- package/blocks/ExternalSource/types.d.ts.map +1 -0
- package/blocks/ExternalSource/types.js +143 -0
- package/blocks/Modal/Modal.d.ts.map +1 -1
- package/blocks/Modal/Modal.js +4 -11
- package/blocks/Modal/modal.css +3 -54
- package/blocks/StartFrom/start-from.css +2 -6
- package/blocks/UploadList/upload-list.css +1 -11
- package/blocks/UrlSource/url-source.css +0 -8
- package/blocks/themes/uc-basic/common.css +0 -5
- package/blocks/themes/uc-basic/svg-sprite.d.ts +1 -1
- package/blocks/themes/uc-basic/svg-sprite.js +1 -1
- package/blocks/themes/uc-basic/theme.css +2 -3
- package/index.ssr.d.ts +0 -14
- package/index.ssr.d.ts.map +1 -1
- package/index.ssr.js +8 -81
- package/locales/file-uploader/ar.d.ts +2 -0
- package/locales/file-uploader/ar.js +2 -0
- package/locales/file-uploader/az.d.ts +2 -0
- package/locales/file-uploader/az.js +2 -0
- package/locales/file-uploader/ca.d.ts +2 -0
- package/locales/file-uploader/ca.js +2 -0
- package/locales/file-uploader/cs.d.ts +2 -0
- package/locales/file-uploader/cs.js +2 -0
- package/locales/file-uploader/da.d.ts +2 -0
- package/locales/file-uploader/da.js +2 -0
- package/locales/file-uploader/de.d.ts +2 -0
- package/locales/file-uploader/de.js +2 -0
- package/locales/file-uploader/el.d.ts +2 -0
- package/locales/file-uploader/el.js +2 -0
- package/locales/file-uploader/en.d.ts +2 -0
- package/locales/file-uploader/en.js +3 -1
- package/locales/file-uploader/es.d.ts +2 -0
- package/locales/file-uploader/es.js +2 -0
- package/locales/file-uploader/et.d.ts +2 -0
- package/locales/file-uploader/et.js +2 -0
- package/locales/file-uploader/fr.d.ts +2 -0
- package/locales/file-uploader/fr.js +2 -0
- package/locales/file-uploader/he.d.ts +2 -0
- package/locales/file-uploader/he.js +2 -0
- package/locales/file-uploader/hy.d.ts +2 -0
- package/locales/file-uploader/hy.js +2 -0
- package/locales/file-uploader/is.d.ts +2 -0
- package/locales/file-uploader/is.js +2 -0
- package/locales/file-uploader/it.d.ts +2 -0
- package/locales/file-uploader/it.js +2 -0
- package/locales/file-uploader/ja.d.ts +2 -0
- package/locales/file-uploader/ja.js +2 -0
- package/locales/file-uploader/ka.d.ts +2 -0
- package/locales/file-uploader/ka.js +2 -0
- package/locales/file-uploader/kk.d.ts +2 -0
- package/locales/file-uploader/kk.js +2 -0
- package/locales/file-uploader/ko.d.ts +2 -0
- package/locales/file-uploader/ko.js +2 -0
- package/locales/file-uploader/lv.d.ts +2 -0
- package/locales/file-uploader/lv.js +2 -0
- package/locales/file-uploader/nb.d.ts +2 -0
- package/locales/file-uploader/nb.js +2 -0
- package/locales/file-uploader/nl.d.ts +2 -0
- package/locales/file-uploader/nl.js +2 -0
- package/locales/file-uploader/pl.d.ts +2 -0
- package/locales/file-uploader/pl.js +2 -0
- package/locales/file-uploader/pt.d.ts +2 -0
- package/locales/file-uploader/pt.js +2 -0
- package/locales/file-uploader/ro.d.ts +2 -0
- package/locales/file-uploader/ro.js +2 -0
- package/locales/file-uploader/ru.d.ts +2 -0
- package/locales/file-uploader/ru.js +2 -0
- package/locales/file-uploader/sk.d.ts +2 -0
- package/locales/file-uploader/sk.js +2 -0
- package/locales/file-uploader/sr.d.ts +2 -0
- package/locales/file-uploader/sr.js +2 -0
- package/locales/file-uploader/sv.d.ts +2 -0
- package/locales/file-uploader/sv.js +2 -0
- package/locales/file-uploader/tr.d.ts +2 -0
- package/locales/file-uploader/tr.js +2 -0
- package/locales/file-uploader/uk.d.ts +2 -0
- package/locales/file-uploader/uk.js +2 -0
- package/locales/file-uploader/vi.d.ts +2 -0
- package/locales/file-uploader/vi.js +2 -0
- package/locales/file-uploader/zh-TW.d.ts +2 -0
- package/locales/file-uploader/zh-TW.js +2 -0
- package/locales/file-uploader/zh.d.ts +2 -0
- package/locales/file-uploader/zh.js +2 -0
- package/package.json +2 -4
- package/types/exported.d.ts +0 -21
- package/web/file-uploader.iife.min.js +4 -4
- package/web/file-uploader.min.js +4 -4
- package/web/uc-basic.min.css +1 -1
- package/web/uc-cloud-image-editor.min.css +1 -1
- package/web/uc-cloud-image-editor.min.js +4 -4
- package/web/uc-file-uploader-inline.min.css +1 -1
- package/web/uc-file-uploader-inline.min.js +4 -4
- package/web/uc-file-uploader-minimal.min.css +1 -1
- package/web/uc-file-uploader-minimal.min.js +3 -3
- package/web/uc-file-uploader-regular.min.css +1 -1
- package/web/uc-file-uploader-regular.min.js +4 -4
- package/web/uc-img.min.js +1 -1
- package/blocks/ExternalSource/buildStyles.d.ts +0 -27
- package/blocks/ExternalSource/buildStyles.d.ts.map +0 -1
- package/blocks/ExternalSource/buildStyles.js +0 -133
- package/blocks/ExternalSource/messages.d.ts +0 -3
- package/blocks/ExternalSource/messages.d.ts.map +0 -1
- package/blocks/ExternalSource/messages.js +0 -35
- package/blocks/LocalEditorImage/LocalEditorImage.d.ts +0 -22
- package/blocks/LocalEditorImage/LocalEditorImage.d.ts.map +0 -1
- package/blocks/LocalEditorImage/LocalEditorImage.js +0 -139
- package/blocks/LocalEditorImage/localEditorImage.css +0 -19
|
@@ -5,31 +5,12 @@ import { ActivityBlock } from '../../abstract/ActivityBlock.js';
|
|
|
5
5
|
import { UploaderBlock } from '../../abstract/UploaderBlock.js';
|
|
6
6
|
import { stringToArray } from '../../utils/stringToArray.js';
|
|
7
7
|
import { wildcardRegexp } from '../../utils/wildcardRegexp.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { buildThemeDefinition } from './buildThemeDefinition.js';
|
|
9
|
+
import { MessageBridge } from './MessageBridge.js';
|
|
10
10
|
import { queryString } from './query-string.js';
|
|
11
11
|
|
|
12
12
|
/** @typedef {{ externalSourceType: string }} ActivityParams */
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {{
|
|
16
|
-
* type: 'file-selected';
|
|
17
|
-
* obj_type: 'selected_file';
|
|
18
|
-
* filename: string;
|
|
19
|
-
* url: string;
|
|
20
|
-
* alternatives?: Record<string, string>;
|
|
21
|
-
* }} SelectedFileMessage
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {{
|
|
26
|
-
* type: 'embed-css';
|
|
27
|
-
* style: string;
|
|
28
|
-
* }} EmbedCssMessage
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/** @typedef {SelectedFileMessage | EmbedCssMessage} Message */
|
|
32
|
-
|
|
33
14
|
export class ExternalSource extends UploaderBlock {
|
|
34
15
|
couldBeCtxOwner = true;
|
|
35
16
|
activityType = ActivityBlock.activities.EXTERNAL;
|
|
@@ -41,12 +22,20 @@ export class ExternalSource extends UploaderBlock {
|
|
|
41
22
|
...this.init$,
|
|
42
23
|
activityIcon: '',
|
|
43
24
|
activityCaption: '',
|
|
25
|
+
|
|
26
|
+
/** @type {import('./types.js').InputMessageMap['selected-files-change']['selectedFiles']} */
|
|
44
27
|
selectedList: [],
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
total: 0,
|
|
29
|
+
|
|
30
|
+
isSelectionReady: false,
|
|
31
|
+
couldSelectAll: false,
|
|
32
|
+
couldDeselectAll: false,
|
|
33
|
+
showSelectionStatus: false,
|
|
34
|
+
counterText: '',
|
|
35
|
+
|
|
47
36
|
onDone: () => {
|
|
48
37
|
for (const message of this.$.selectedList) {
|
|
49
|
-
const url = this.
|
|
38
|
+
const url = this.extractUrlFromSelectedFile(message);
|
|
50
39
|
const { filename } = message;
|
|
51
40
|
const { externalSourceType } = this.activityParams;
|
|
52
41
|
this.api.addFileFromUrl(url, { fileName: filename, source: externalSourceType });
|
|
@@ -57,6 +46,14 @@ export class ExternalSource extends UploaderBlock {
|
|
|
57
46
|
onCancel: () => {
|
|
58
47
|
this.historyBack();
|
|
59
48
|
},
|
|
49
|
+
|
|
50
|
+
onSelectAll: () => {
|
|
51
|
+
this._messageBridge?.send({ type: 'select-all' });
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
onDeselectAll: () => {
|
|
55
|
+
this._messageBridge?.send({ type: 'deselect-all' });
|
|
56
|
+
},
|
|
60
57
|
};
|
|
61
58
|
}
|
|
62
59
|
|
|
@@ -69,12 +66,6 @@ export class ExternalSource extends UploaderBlock {
|
|
|
69
66
|
throw new Error(`External Source activity params not found`);
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
/**
|
|
73
|
-
* @private
|
|
74
|
-
* @type {HTMLIFrameElement | null}
|
|
75
|
-
*/
|
|
76
|
-
_iframe = null;
|
|
77
|
-
|
|
78
69
|
initCallback() {
|
|
79
70
|
super.initCallback();
|
|
80
71
|
this.registerActivity(this.activityType, {
|
|
@@ -108,24 +99,25 @@ export class ExternalSource extends UploaderBlock {
|
|
|
108
99
|
this.unmountIframe();
|
|
109
100
|
}
|
|
110
101
|
});
|
|
111
|
-
this.sub('selectedList', (list) => {
|
|
112
|
-
this.$.counter = list.length;
|
|
113
|
-
});
|
|
114
102
|
this.subConfigValue('multiple', (multiple) => {
|
|
115
|
-
this.$.
|
|
103
|
+
this.$.showSelectionStatus = multiple;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this.subConfigValue('localeName', (val) => {
|
|
107
|
+
this.setupL10n();
|
|
116
108
|
});
|
|
117
109
|
}
|
|
118
110
|
|
|
119
111
|
/**
|
|
120
112
|
* @private
|
|
121
|
-
* @param {
|
|
113
|
+
* @param {NonNullable<import('./types.js').InputMessageMap['selected-files-change']['selectedFiles']>[number]} selectedFile
|
|
122
114
|
*/
|
|
123
|
-
|
|
124
|
-
if (
|
|
115
|
+
extractUrlFromSelectedFile(selectedFile) {
|
|
116
|
+
if (selectedFile.alternatives) {
|
|
125
117
|
const preferredTypes = stringToArray(this.cfg.externalSourcesPreferredTypes);
|
|
126
118
|
for (const preferredType of preferredTypes) {
|
|
127
119
|
const regexp = wildcardRegexp(preferredType);
|
|
128
|
-
for (const [type, typeUrl] of Object.entries(
|
|
120
|
+
for (const [type, typeUrl] of Object.entries(selectedFile.alternatives)) {
|
|
129
121
|
if (regexp.test(type)) {
|
|
130
122
|
return typeUrl;
|
|
131
123
|
}
|
|
@@ -133,81 +125,71 @@ export class ExternalSource extends UploaderBlock {
|
|
|
133
125
|
}
|
|
134
126
|
}
|
|
135
127
|
|
|
136
|
-
return
|
|
128
|
+
return selectedFile.url;
|
|
137
129
|
}
|
|
138
130
|
|
|
139
131
|
/**
|
|
140
132
|
* @private
|
|
141
|
-
* @param {
|
|
133
|
+
* @param {import('./types.js').InputMessageMap['selected-files-change']} message
|
|
142
134
|
*/
|
|
143
|
-
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @private
|
|
149
|
-
* @param {SelectedFileMessage} message
|
|
150
|
-
*/
|
|
151
|
-
async handleFileSelected(message) {
|
|
152
|
-
if (!this.$.multiple && this.$.selectedList.length) {
|
|
135
|
+
async handleSelectedFilesChange(message) {
|
|
136
|
+
if (this.cfg.multiple !== message.isMultipleMode) {
|
|
137
|
+
console.error('Multiple mode mismatch');
|
|
153
138
|
return;
|
|
154
139
|
}
|
|
155
140
|
|
|
156
|
-
this
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
141
|
+
this.bindL10n('counterText', () =>
|
|
142
|
+
this.l10n('selected-count', {
|
|
143
|
+
count: message.selectedCount,
|
|
144
|
+
total: message.total,
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
this.set$({
|
|
149
|
+
isSelectionReady: message.isReady,
|
|
150
|
+
showSelectionStatus: message.isMultipleMode && message.total > 0,
|
|
151
|
+
couldSelectAll: message.selectedCount < message.total,
|
|
152
|
+
couldDeselectAll: message.selectedCount === message.total,
|
|
153
|
+
selectedList: message.selectedFiles,
|
|
154
|
+
});
|
|
161
155
|
}
|
|
162
156
|
|
|
163
157
|
/** @private */
|
|
164
158
|
handleIframeLoad() {
|
|
165
159
|
this.applyStyles();
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @private
|
|
170
|
-
* @param {string} propName
|
|
171
|
-
*/
|
|
172
|
-
getCssValue(propName) {
|
|
173
|
-
let style = window.getComputedStyle(this);
|
|
174
|
-
return style.getPropertyValue(propName).trim();
|
|
160
|
+
this.setupL10n();
|
|
175
161
|
}
|
|
176
162
|
|
|
177
163
|
/** @private */
|
|
178
164
|
applyStyles() {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
secondaryForegroundColor: this.getCssValue('--uc-secondary-foreground'),
|
|
185
|
-
secondaryHover: this.getCssValue('--uc-secondary-hover'),
|
|
186
|
-
linkColor: this.getCssValue('--uc-primary'),
|
|
187
|
-
linkColorHover: this.getCssValue('--uc-primary-hover'),
|
|
188
|
-
fontFamily: this.getCssValue('--uc-font-family'),
|
|
189
|
-
fontSize: this.getCssValue('--uc-font-size'),
|
|
190
|
-
};
|
|
165
|
+
this._messageBridge?.send({
|
|
166
|
+
type: 'set-theme-definition',
|
|
167
|
+
theme: buildThemeDefinition(this),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
191
170
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
171
|
+
/** @private */
|
|
172
|
+
setupL10n() {
|
|
173
|
+
this._messageBridge?.send({
|
|
174
|
+
type: 'set-locale-definition',
|
|
175
|
+
localeDefinition: this.cfg.localeName,
|
|
195
176
|
});
|
|
196
177
|
}
|
|
197
178
|
|
|
198
179
|
/** @private */
|
|
199
180
|
remoteUrl() {
|
|
200
|
-
const { pubkey, remoteTabSessionKey, socialBaseUrl } = this.cfg;
|
|
181
|
+
const { pubkey, remoteTabSessionKey, socialBaseUrl, multiple } = this.cfg;
|
|
201
182
|
const { externalSourceType } = this.activityParams;
|
|
202
183
|
const lang = this.l10n('social-source-lang')?.split('-')?.[0] || 'en';
|
|
203
184
|
const params = {
|
|
204
185
|
lang,
|
|
205
186
|
public_key: pubkey,
|
|
206
187
|
images_only: false.toString(),
|
|
207
|
-
pass_window_open: false,
|
|
208
188
|
session_key: remoteTabSessionKey,
|
|
189
|
+
wait_for_theme: true,
|
|
190
|
+
multiple: multiple.toString(),
|
|
209
191
|
};
|
|
210
|
-
const url = new URL(`/
|
|
192
|
+
const url = new URL(`/window4/${externalSourceType}`, socialBaseUrl);
|
|
211
193
|
url.search = queryString(params);
|
|
212
194
|
return url.toString();
|
|
213
195
|
}
|
|
@@ -231,31 +213,43 @@ export class ExternalSource extends UploaderBlock {
|
|
|
231
213
|
this.ref.iframeWrapper.innerHTML = '';
|
|
232
214
|
this.ref.iframeWrapper.appendChild(iframe);
|
|
233
215
|
|
|
234
|
-
|
|
216
|
+
if (!iframe.contentWindow) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this._messageBridge?.destroy();
|
|
221
|
+
|
|
222
|
+
/** @private */
|
|
223
|
+
this._messageBridge = new MessageBridge(iframe.contentWindow);
|
|
224
|
+
this._messageBridge.on('selected-files-change', this.handleSelectedFilesChange.bind(this));
|
|
235
225
|
|
|
236
|
-
this.
|
|
237
|
-
this.$.selectedList = [];
|
|
226
|
+
this.resetSelectionStatus();
|
|
238
227
|
}
|
|
239
228
|
|
|
240
229
|
/** @private */
|
|
241
230
|
unmountIframe() {
|
|
242
|
-
this.
|
|
231
|
+
this._messageBridge?.destroy();
|
|
232
|
+
this._messageBridge = undefined;
|
|
243
233
|
this.ref.iframeWrapper.innerHTML = '';
|
|
244
|
-
|
|
245
|
-
this
|
|
246
|
-
|
|
234
|
+
|
|
235
|
+
this.resetSelectionStatus();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** @private */
|
|
239
|
+
resetSelectionStatus() {
|
|
240
|
+
this.set$({
|
|
241
|
+
selectedList: [],
|
|
242
|
+
total: 0,
|
|
243
|
+
isSelectionReady: false,
|
|
244
|
+
couldSelectAll: false,
|
|
245
|
+
couldDeselectAll: false,
|
|
246
|
+
showSelectionStatus: false,
|
|
247
|
+
});
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
ExternalSource.template = /* HTML */ `
|
|
251
252
|
<uc-activity-header>
|
|
252
|
-
<button type="button" class="uc-mini-btn" set="onclick: *historyBack" l10n="@title:back">
|
|
253
|
-
<uc-icon name="back"></uc-icon>
|
|
254
|
-
</button>
|
|
255
|
-
<div>
|
|
256
|
-
<uc-icon set="@name: activityIcon"></uc-icon>
|
|
257
|
-
<span>{{activityCaption}}</span>
|
|
258
|
-
</div>
|
|
259
253
|
<button
|
|
260
254
|
type="button"
|
|
261
255
|
class="uc-mini-btn uc-close-btn"
|
|
@@ -269,12 +263,15 @@ ExternalSource.template = /* HTML */ `
|
|
|
269
263
|
<div ref="iframeWrapper" class="uc-iframe-wrapper"></div>
|
|
270
264
|
<div class="uc-toolbar">
|
|
271
265
|
<button type="button" class="uc-cancel-btn uc-secondary-btn" set="onclick: onCancel" l10n="cancel"></button>
|
|
272
|
-
<div
|
|
273
|
-
|
|
266
|
+
<div set="@hidden: !showSelectionStatus" class="uc-selection-status-box">
|
|
267
|
+
<span>{{counterText}}</span>
|
|
268
|
+
<button type="button" set="onclick: onSelectAll; @hidden: !couldSelectAll" l10n="select-all"></button>
|
|
269
|
+
<button type="button" set="onclick: onDeselectAll; @hidden: !couldDeselectAll" l10n="deselect-all"></button>
|
|
270
|
+
</div>
|
|
274
271
|
<button
|
|
275
272
|
type="button"
|
|
276
273
|
class="uc-done-btn uc-primary-btn"
|
|
277
|
-
set="onclick: onDone; @disabled: !
|
|
274
|
+
set="onclick: onDone; @disabled: !isSelectionReady"
|
|
278
275
|
l10n="done"
|
|
279
276
|
></button>
|
|
280
277
|
</div>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class MessageBridge {
|
|
2
|
+
/** @param {Window} context */
|
|
3
|
+
constructor(context: Window);
|
|
4
|
+
/** @type {Map<string, Set<import('./types').InputMessageHandler<import('./types').InputMessageType>>>} */
|
|
5
|
+
_handlerMap: Map<string, Set<import('./types').InputMessageHandler<import('./types').InputMessageType>>>;
|
|
6
|
+
/** @type {Window} */
|
|
7
|
+
_context: Window;
|
|
8
|
+
/** @param {MessageEvent} e */
|
|
9
|
+
_handleMessage: (e: MessageEvent) => void;
|
|
10
|
+
/**
|
|
11
|
+
* @template {import('./types').InputMessageType} T
|
|
12
|
+
* @param {T} type
|
|
13
|
+
* @param {import('./types').InputMessageHandler<T>} handler
|
|
14
|
+
*/
|
|
15
|
+
on<T extends "selected-files-change">(type: T, handler: import("./types").InputMessageHandler<T>): void;
|
|
16
|
+
/** @param {import('./types').OutputMessage} message */
|
|
17
|
+
send(message: import('./types').OutputMessage): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=MessageBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBridge.d.ts","sourceRoot":"","sources":["MessageBridge.js"],"names":[],"mappings":"AAgBA;IAOE,8BAA8B;IAC9B,qBADY,MAAM,EAKjB;IAXD,0GAA0G;IAC1G,aADW,IAAI,MAAM,EAAE,IAAI,OAAO,SAAS,EAAE,mBAAmB,CAAC,OAAO,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAC9E;IAExB,qBAAqB;IACrB,UADW,MAAM,CACR;IAST,8BAA8B;IAC9B,oBADY,YAAY,UAgBtB;IAEF;;;;OAIG;IACH,wGAOC;IAED,uDAAuD;IACvD,cADY,OAAO,SAAS,EAAE,aAAa,QAG1C;IAED,gBAEC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** @type {import('./types').InputMessageType[]} */
|
|
2
|
+
const MESSAGE_TYPE_WHITELIST = ['selected-files-change'];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {unknown} message
|
|
6
|
+
* @returns {message is import("./types").InputMessageMap[import("./types").InputMessageType]}
|
|
7
|
+
*/
|
|
8
|
+
const isWhitelistedMessage = (message) => {
|
|
9
|
+
if (!message) return false;
|
|
10
|
+
if (typeof message !== 'object') return false;
|
|
11
|
+
return (
|
|
12
|
+
'type' in message &&
|
|
13
|
+
MESSAGE_TYPE_WHITELIST.includes(/** @type {import('./types').InputMessageType} */ (message.type))
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class MessageBridge {
|
|
18
|
+
/** @type {Map<string, Set<import('./types').InputMessageHandler<import('./types').InputMessageType>>>} */
|
|
19
|
+
_handlerMap = new Map();
|
|
20
|
+
|
|
21
|
+
/** @type {Window} */
|
|
22
|
+
_context;
|
|
23
|
+
|
|
24
|
+
/** @param {Window} context */
|
|
25
|
+
constructor(context) {
|
|
26
|
+
this._context = context;
|
|
27
|
+
|
|
28
|
+
window.addEventListener('message', this._handleMessage);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @param {MessageEvent} e */
|
|
32
|
+
_handleMessage = (e) => {
|
|
33
|
+
if (e.source !== this._context) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const message = e.data;
|
|
37
|
+
if (!isWhitelistedMessage(message)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const handlers = this._handlerMap.get(message.type);
|
|
42
|
+
if (handlers) {
|
|
43
|
+
for (const handler of handlers) {
|
|
44
|
+
handler(message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @template {import('./types').InputMessageType} T
|
|
51
|
+
* @param {T} type
|
|
52
|
+
* @param {import('./types').InputMessageHandler<T>} handler
|
|
53
|
+
*/
|
|
54
|
+
on(type, handler) {
|
|
55
|
+
const handlers = this._handlerMap.get(type) ?? new Set();
|
|
56
|
+
if (!this._handlerMap.has(type)) {
|
|
57
|
+
this._handlerMap.set(type, handlers);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handlers.add(/** @type {import('./types').InputMessageHandler<import('./types').InputMessageType>} */ (handler));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @param {import('./types').OutputMessage} message */
|
|
64
|
+
send(message) {
|
|
65
|
+
this._context.postMessage(message, '*');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
destroy() {
|
|
69
|
+
window.removeEventListener('message', this._handleMessage);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildThemeDefinition.d.ts","sourceRoot":"","sources":["buildThemeDefinition.js"],"names":[],"mappings":"AAqCA,mCAAmC;AACnC,8CADY,WAAW,8DAStB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {HTMLElement} element
|
|
5
|
+
* @param {string} propName
|
|
6
|
+
*/
|
|
7
|
+
function getCssValue(element, propName) {
|
|
8
|
+
let style = window.getComputedStyle(element);
|
|
9
|
+
return style.getPropertyValue(propName).trim();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ucCustomProperties = /** @type {(keyof import('./types.js').ThemeDefinition)[]} */ ([
|
|
13
|
+
'--uc-font-family',
|
|
14
|
+
'--uc-font-size',
|
|
15
|
+
'--uc-line-height',
|
|
16
|
+
'--uc-button-size',
|
|
17
|
+
'--uc-preview-size',
|
|
18
|
+
'--uc-input-size',
|
|
19
|
+
'--uc-padding',
|
|
20
|
+
'--uc-radius',
|
|
21
|
+
'--uc-transition',
|
|
22
|
+
'--uc-background',
|
|
23
|
+
'--uc-foreground',
|
|
24
|
+
'--uc-primary',
|
|
25
|
+
'--uc-primary-hover',
|
|
26
|
+
'--uc-primary-transparent',
|
|
27
|
+
'--uc-primary-foreground',
|
|
28
|
+
'--uc-secondary',
|
|
29
|
+
'--uc-secondary-hover',
|
|
30
|
+
'--uc-secondary-foreground',
|
|
31
|
+
'--uc-muted',
|
|
32
|
+
'--uc-muted-foreground',
|
|
33
|
+
'--uc-destructive',
|
|
34
|
+
'--uc-destructive-foreground',
|
|
35
|
+
'--uc-border',
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/** @param {HTMLElement} element */
|
|
39
|
+
export function buildThemeDefinition(element) {
|
|
40
|
+
return ucCustomProperties.reduce((acc, prop) => {
|
|
41
|
+
const value = getCssValue(element, prop);
|
|
42
|
+
if (value) {
|
|
43
|
+
acc[prop] = value;
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, /** @type {Record<keyof import('./types.js').ThemeDefinition, string>} */ ({}));
|
|
47
|
+
}
|
|
@@ -5,15 +5,12 @@ uc-external-source {
|
|
|
5
5
|
height: 100%;
|
|
6
6
|
background-color: var(--uc-background);
|
|
7
7
|
overflow: hidden;
|
|
8
|
+
position: relative;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
[uc-modal] uc-external-source {
|
|
11
|
-
width:
|
|
12
|
-
|
|
13
|
-
calc(var(--uc-dialog-max-width) - var(--uc-padding) * 2)
|
|
14
|
-
);
|
|
15
|
-
height: var(--modal-content-height-fill, 100%);
|
|
16
|
-
max-height: var(--modal-max-content-height);
|
|
11
|
+
[uc-modal] > dialog:has(uc-external-source[active]) {
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: 100%;
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
uc-external-source > .uc-content {
|
|
@@ -23,13 +20,6 @@ uc-external-source > .uc-content {
|
|
|
23
20
|
grid-template-rows: 1fr min-content;
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
@media only screen and (max-width: 430px) {
|
|
27
|
-
uc-external-source {
|
|
28
|
-
width: calc(100vw - var(--uc-padding) * 2);
|
|
29
|
-
height: var(--modal-content-height-fill, 100%);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
23
|
uc-external-source iframe {
|
|
34
24
|
display: block;
|
|
35
25
|
width: 100%;
|
|
@@ -42,11 +32,11 @@ uc-external-source .uc-iframe-wrapper {
|
|
|
42
32
|
}
|
|
43
33
|
|
|
44
34
|
uc-external-source .uc-toolbar {
|
|
45
|
-
display:
|
|
35
|
+
display: flex;
|
|
36
|
+
width: 100%;
|
|
46
37
|
grid-gap: var(--uc-padding);
|
|
47
|
-
grid-template-columns: max-content 1fr max-content max-content;
|
|
48
38
|
align-items: center;
|
|
49
|
-
|
|
39
|
+
justify-content: space-between;
|
|
50
40
|
padding: var(--uc-padding);
|
|
51
41
|
border-top: 1px solid var(--uc-border);
|
|
52
42
|
}
|
|
@@ -55,11 +45,36 @@ uc-external-source .uc-back-btn {
|
|
|
55
45
|
padding-left: 0;
|
|
56
46
|
}
|
|
57
47
|
|
|
58
|
-
uc-external-source .uc-
|
|
48
|
+
uc-external-source .uc-selection-status-box {
|
|
49
|
+
color: var(--uc-foreground);
|
|
59
50
|
display: flex;
|
|
60
|
-
|
|
51
|
+
flex-direction: column;
|
|
61
52
|
align-items: center;
|
|
62
|
-
justify-content:
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
justify-content: center;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
uc-external-source .uc-selection-status-box button {
|
|
57
|
+
color: var(--uc-primary);
|
|
58
|
+
height: auto;
|
|
59
|
+
padding: 0;
|
|
60
|
+
background: none;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
uc-external-source .uc-selection-status-box button:hover {
|
|
64
|
+
text-decoration: underline;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
uc-external-source uc-activity-header {
|
|
68
|
+
position: absolute;
|
|
69
|
+
width: 100%;
|
|
70
|
+
justify-content: flex-end;
|
|
71
|
+
z-index: 1;
|
|
72
|
+
left: 0;
|
|
73
|
+
top: 0;
|
|
74
|
+
right: 0;
|
|
75
|
+
pointer-events: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
uc-external-source uc-activity-header .uc-close-btn {
|
|
79
|
+
pointer-events: auto;
|
|
65
80
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export type InstagramInfo = {
|
|
2
|
+
caption?: string | null;
|
|
3
|
+
created: number;
|
|
4
|
+
id: string;
|
|
5
|
+
public_page?: string;
|
|
6
|
+
username: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
name?: string;
|
|
9
|
+
modified?: number;
|
|
10
|
+
};
|
|
11
|
+
export type DoneSuccessResponse = {
|
|
12
|
+
error?: undefined;
|
|
13
|
+
info?: InstagramInfo;
|
|
14
|
+
alternatives?: Record<string, string>;
|
|
15
|
+
is_image?: boolean | null;
|
|
16
|
+
filename?: string;
|
|
17
|
+
obj_type: 'selected_file';
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
export type InputMessageMap = {
|
|
21
|
+
'selected-files-change': {
|
|
22
|
+
type: 'selected-files-change';
|
|
23
|
+
total: number;
|
|
24
|
+
selectedCount: number;
|
|
25
|
+
} & ({
|
|
26
|
+
isReady: false;
|
|
27
|
+
isMultipleMode: boolean;
|
|
28
|
+
selectedFiles: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
isReady: true;
|
|
31
|
+
isMultipleMode: true;
|
|
32
|
+
selectedFiles: DoneSuccessResponse[];
|
|
33
|
+
} | {
|
|
34
|
+
isReady: true;
|
|
35
|
+
isMultipleMode: false;
|
|
36
|
+
selectedFiles: [DoneSuccessResponse] | [];
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export type InputMessageType = keyof InputMessageMap;
|
|
40
|
+
export type InputMessage = InputMessageMap[InputMessageType];
|
|
41
|
+
export type InputMessageHandler<T extends "selected-files-change"> = (message: import('./types').InputMessageMap[T]) => void;
|
|
42
|
+
export type ThemeDefinition = {
|
|
43
|
+
'--uc-font-family': string;
|
|
44
|
+
'--uc-font-size': string;
|
|
45
|
+
'--uc-line-height': string;
|
|
46
|
+
'--uc-button-size': string;
|
|
47
|
+
'--uc-preview-size': string;
|
|
48
|
+
'--uc-input-size': string;
|
|
49
|
+
'--uc-padding': string;
|
|
50
|
+
'--uc-radius': string;
|
|
51
|
+
'--uc-transition': string;
|
|
52
|
+
'--uc-background': string;
|
|
53
|
+
'--uc-foreground': string;
|
|
54
|
+
'--uc-primary': string;
|
|
55
|
+
'--uc-primary-hover': string;
|
|
56
|
+
'--uc-primary-transparent': string;
|
|
57
|
+
'--uc-primary-foreground': string;
|
|
58
|
+
'--uc-secondary': string;
|
|
59
|
+
'--uc-secondary-hover': string;
|
|
60
|
+
'--uc-secondary-foreground': string;
|
|
61
|
+
'--uc-muted': string;
|
|
62
|
+
'--uc-muted-foreground': string;
|
|
63
|
+
'--uc-destructive': string;
|
|
64
|
+
'--uc-destructive-foreground': string;
|
|
65
|
+
'--uc-border': string;
|
|
66
|
+
'--uc-primary-rgb-light': string;
|
|
67
|
+
'--uc-primary-light': string;
|
|
68
|
+
'--uc-primary-hover-light': string;
|
|
69
|
+
'--uc-primary-transparent-light': string;
|
|
70
|
+
'--uc-background-light': string;
|
|
71
|
+
'--uc-foreground-light': string;
|
|
72
|
+
'--uc-primary-foreground-light': string;
|
|
73
|
+
'--uc-secondary-light': string;
|
|
74
|
+
'--uc-secondary-hover-light': string;
|
|
75
|
+
'--uc-secondary-foreground-light': string;
|
|
76
|
+
'--uc-muted-light': string;
|
|
77
|
+
'--uc-muted-foreground-light': string;
|
|
78
|
+
'--uc-destructive-light': string;
|
|
79
|
+
'--uc-destructive-foreground-light': string;
|
|
80
|
+
'--uc-border-light': string;
|
|
81
|
+
'--uc-primary-rgb-dark': string;
|
|
82
|
+
'--uc-primary-dark': string;
|
|
83
|
+
'--uc-primary-hover-dark': string;
|
|
84
|
+
'--uc-primary-transparent-dark': string;
|
|
85
|
+
'--uc-background-dark': string;
|
|
86
|
+
'--uc-foreground-dark': string;
|
|
87
|
+
'--uc-primary-foreground-dark': string;
|
|
88
|
+
'--uc-secondary-dark': string;
|
|
89
|
+
'--uc-secondary-hover-dark': string;
|
|
90
|
+
'--uc-secondary-foreground-dark': string;
|
|
91
|
+
'--uc-muted-dark': string;
|
|
92
|
+
'--uc-muted-foreground-dark': string;
|
|
93
|
+
'--uc-destructive-dark': string;
|
|
94
|
+
'--uc-destructive-foreground-dark': string;
|
|
95
|
+
'--uc-border-dark': string;
|
|
96
|
+
'--uc-primary-oklch-light': string;
|
|
97
|
+
'--uc-primary-oklch-dark': string;
|
|
98
|
+
};
|
|
99
|
+
export type OutputMessage = {
|
|
100
|
+
type: 'select-all';
|
|
101
|
+
} | {
|
|
102
|
+
type: 'deselect-all';
|
|
103
|
+
} | {
|
|
104
|
+
type: 'set-theme-definition';
|
|
105
|
+
theme: Record<string, string>;
|
|
106
|
+
} | {
|
|
107
|
+
type: 'set-locale-definition';
|
|
108
|
+
localeDefinition: string;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'set-embed-css';
|
|
111
|
+
css: Partial<ThemeDefinition>;
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"4BAGa;IACZ,OAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAW,EAAE,MAAM,CAAC;IACpB,EAAM,EAAE,MAAM,CAAC;IACf,WAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAY,EAAE,MAAM,CAAC;IACrB,IAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAY,CAAC,EAAE,MAAM,CAAC;CACnB;kCAIS;IACZ,KAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,YAAgB,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAY,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,QAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAY,EAAE,eAAe,CAAC;IAC9B,GAAO,EAAE,MAAM,CAAC;CACb;8BAIS;IACZ,uBAA2B,EAAE;QAC7B,IAAU,EAAE,uBAAuB,CAAC;QACpC,KAAW,EAAE,MAAM,CAAC;QACpB,aAAmB,EAAE,MAAM,CAAC;KACvB,GAAG,CACA;QACR,OAAiB,EAAE,KAAK,CAAC;QACzB,cAAwB,EAAE,OAAO,CAAC;QAClC,aAAuB,EAAE,SAAS,CAAC;KAC1B,GACD;QACR,OAAiB,EAAE,IAAI,CAAC;QACxB,cAAwB,EAAE,IAAI,CAAC;QAC/B,aAAuB,EAAE,mBAAmB,EAAE,CAAC;KACtC,GACD;QACR,OAAiB,EAAE,IAAI,CAAC;QACxB,cAAwB,EAAE,KAAK,CAAC;QAChC,aAAuB,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC;KAC3C,CACJ,CAAC;CACH;+BAGU,MAAM,eAAe;2BACrB,eAAe,CAAC,gBAAgB,CAAC;+EAIxB,OAAO,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI;8BAIvD;IACZ,kBAAsB,EAAE,MAAM,CAAC;IAC/B,gBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAsB,EAAE,MAAM,CAAC;IAC/B,kBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAuB,EAAE,MAAM,CAAC;IAChC,iBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAkB,EAAE,MAAM,CAAC;IAC3B,aAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAwB,EAAE,MAAM,CAAC;IACjC,0BAA8B,EAAE,MAAM,CAAC;IACvC,yBAA6B,EAAE,MAAM,CAAC;IACtC,gBAAoB,EAAE,MAAM,CAAC;IAC7B,sBAA0B,EAAE,MAAM,CAAC;IACnC,2BAA+B,EAAE,MAAM,CAAC;IACxC,YAAgB,EAAE,MAAM,CAAC;IACzB,uBAA2B,EAAE,MAAM,CAAC;IACpC,kBAAsB,EAAE,MAAM,CAAC;IAC/B,6BAAiC,EAAE,MAAM,CAAC;IAC1C,aAAiB,EAAE,MAAM,CAAC;IAC1B,wBAA4B,EAAE,MAAM,CAAC;IACrC,oBAAwB,EAAE,MAAM,CAAC;IACjC,0BAA8B,EAAE,MAAM,CAAC;IACvC,gCAAoC,EAAE,MAAM,CAAC;IAC7C,uBAA2B,EAAE,MAAM,CAAC;IACpC,uBAA2B,EAAE,MAAM,CAAC;IACpC,+BAAmC,EAAE,MAAM,CAAC;IAC5C,sBAA0B,EAAE,MAAM,CAAC;IACnC,4BAAgC,EAAE,MAAM,CAAC;IACzC,iCAAqC,EAAE,MAAM,CAAC;IAC9C,kBAAsB,EAAE,MAAM,CAAC;IAC/B,6BAAiC,EAAE,MAAM,CAAC;IAC1C,wBAA4B,EAAE,MAAM,CAAC;IACrC,mCAAuC,EAAE,MAAM,CAAC;IAChD,mBAAuB,EAAE,MAAM,CAAC;IAChC,uBAA2B,EAAE,MAAM,CAAC;IACpC,mBAAuB,EAAE,MAAM,CAAC;IAChC,yBAA6B,EAAE,MAAM,CAAC;IACtC,+BAAmC,EAAE,MAAM,CAAC;IAC5C,sBAA0B,EAAE,MAAM,CAAC;IACnC,sBAA0B,EAAE,MAAM,CAAC;IACnC,8BAAkC,EAAE,MAAM,CAAC;IAC3C,qBAAyB,EAAE,MAAM,CAAC;IAClC,2BAA+B,EAAE,MAAM,CAAC;IACxC,gCAAoC,EAAE,MAAM,CAAC;IAC7C,iBAAqB,EAAE,MAAM,CAAC;IAC9B,4BAAgC,EAAE,MAAM,CAAC;IACzC,uBAA2B,EAAE,MAAM,CAAC;IACpC,kCAAsC,EAAE,MAAM,CAAC;IAC/C,kBAAsB,EAAE,MAAM,CAAC;IAC/B,0BAA8B,EAAE,MAAM,CAAC;IACvC,yBAA6B,EAAE,MAAM,CAAC;CACnC;4BAIS;IACZ,IAAY,EAAE,YAAY,CAAC;CACpB,GACD;IACN,IAAY,EAAE,cAAc,CAAC;CACtB,GACD;IACN,IAAY,EAAE,sBAAsB,CAAC;IACrC,KAAa,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,GACD;IACN,IAAY,EAAE,uBAAuB,CAAC;IACtC,gBAAwB,EAAE,MAAM,CAAC;CAC1B,GACD;IACN,IAAY,EAAE,eAAe,CAAC;IAC9B,GAAW,EAAE,QAAQ,eAAe,CAAC,CAAC;CAC/B"}
|