@uploadcare/file-uploader 1.24.0 → 1.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/env.js CHANGED
@@ -25,7 +25,7 @@
25
25
  */
26
26
 
27
27
  // package.json
28
- var version = "1.24.0";
28
+ var version = "1.24.1";
29
29
 
30
30
  // src/env.ts
31
31
  var PACKAGE_NAME = "blocks";
package/dist/index.js CHANGED
@@ -1216,7 +1216,7 @@ import { TelemetryAPIService } from "@uploadcare/quality-insights";
1216
1216
  import { Queue as Queue2 } from "@uploadcare/upload-client";
1217
1217
 
1218
1218
  // package.json
1219
- var version = "1.24.0";
1219
+ var version = "1.24.1";
1220
1220
 
1221
1221
  // src/env.ts
1222
1222
  var PACKAGE_NAME = "blocks";
@@ -8179,6 +8179,110 @@ var runAssertions = debounce((cfg) => {
8179
8179
  }
8180
8180
  }, 0);
8181
8181
 
8182
+ // src/blocks/Config/computed-properties.ts
8183
+ import { getPrefixedCdnBaseAsync, isPrefixedCdnBase } from "@uploadcare/cname-prefix/async";
8184
+
8185
+ // src/utils/isPromiseLike.ts
8186
+ var isPromiseLike = (value) => {
8187
+ return value instanceof Promise || Boolean(
8188
+ value && typeof value === "object" && "then" in value && typeof value.then === "function"
8189
+ );
8190
+ };
8191
+
8192
+ // src/blocks/Config/computed-properties.ts
8193
+ var defineComputedProperty = (declaration) => declaration;
8194
+ var COMPUTED_PROPERTIES = [
8195
+ defineComputedProperty({
8196
+ key: "cameraModes",
8197
+ deps: ["enableVideoRecording"],
8198
+ fn: ({ cameraModes, enableVideoRecording }) => {
8199
+ if (enableVideoRecording === null) {
8200
+ return cameraModes;
8201
+ }
8202
+ let cameraModesCsv = deserializeCsv(cameraModes);
8203
+ if (enableVideoRecording && !cameraModesCsv.includes("video")) {
8204
+ cameraModesCsv = cameraModesCsv.concat("video");
8205
+ } else if (!enableVideoRecording) {
8206
+ cameraModesCsv = cameraModesCsv.filter((mode) => mode !== "video");
8207
+ }
8208
+ return serializeCsv(cameraModesCsv);
8209
+ }
8210
+ }),
8211
+ defineComputedProperty({
8212
+ key: "cameraModes",
8213
+ deps: ["defaultCameraMode"],
8214
+ fn: ({ cameraModes, defaultCameraMode }) => {
8215
+ if (defaultCameraMode === null) {
8216
+ return cameraModes;
8217
+ }
8218
+ let cameraModesCsv = deserializeCsv(cameraModes);
8219
+ cameraModesCsv = cameraModesCsv.sort((a, b) => {
8220
+ if (a === defaultCameraMode) return -1;
8221
+ if (b === defaultCameraMode) return 1;
8222
+ return 0;
8223
+ });
8224
+ return serializeCsv(cameraModesCsv);
8225
+ }
8226
+ }),
8227
+ defineComputedProperty({
8228
+ key: "cdnCname",
8229
+ deps: ["pubkey", "cdnCnamePrefixed"],
8230
+ fn: ({ pubkey, cdnCname, cdnCnamePrefixed }) => {
8231
+ if (pubkey && (cdnCname === DEFAULT_CDN_CNAME || isPrefixedCdnBase(cdnCname, cdnCnamePrefixed))) {
8232
+ return getPrefixedCdnBaseAsync(pubkey, cdnCnamePrefixed);
8233
+ }
8234
+ return cdnCname;
8235
+ }
8236
+ })
8237
+ ];
8238
+ var abortControllers = /* @__PURE__ */ new Map();
8239
+ var computeProperty = ({ key, setValue, getValue }) => {
8240
+ for (const computed of COMPUTED_PROPERTIES) {
8241
+ if (computed.deps.includes(key)) {
8242
+ const args = {
8243
+ [computed.key]: getValue(computed.key)
8244
+ };
8245
+ for (const dep of computed.deps) {
8246
+ args[dep] = getValue(dep);
8247
+ }
8248
+ const abortController = new AbortController();
8249
+ abortControllers.get(computed.key)?.abort();
8250
+ abortControllers.set(computed.key, abortController);
8251
+ let result;
8252
+ try {
8253
+ result = computed.fn(args, {
8254
+ signal: abortController.signal
8255
+ });
8256
+ } catch (error) {
8257
+ if (abortControllers.get(computed.key) === abortController) {
8258
+ abortControllers.delete(computed.key);
8259
+ }
8260
+ console.error(`Failed to compute value for "${computed.key}"`, error);
8261
+ return;
8262
+ }
8263
+ if (isPromiseLike(result)) {
8264
+ result.then((resolvedValue) => {
8265
+ if (abortController.signal.aborted) {
8266
+ return;
8267
+ }
8268
+ setValue(computed.key, resolvedValue);
8269
+ }).catch((error) => {
8270
+ if (abortController.signal.aborted) {
8271
+ return;
8272
+ }
8273
+ console.error(`Failed to compute value for "${computed.key}"`, error);
8274
+ }).finally(() => {
8275
+ if (abortControllers.get(computed.key) === abortController) {
8276
+ abortControllers.delete(computed.key);
8277
+ }
8278
+ });
8279
+ } else {
8280
+ setValue(computed.key, result);
8281
+ }
8282
+ }
8283
+ }
8284
+ };
8285
+
8182
8286
  // src/blocks/Config/validatorsType.ts
8183
8287
  var asString = (value) => String(value);
8184
8288
  var asNumber2 = (value) => {
@@ -8338,89 +8442,6 @@ var normalizeConfigValue = (key, value) => {
8338
8442
  }
8339
8443
  };
8340
8444
 
8341
- // src/blocks/Config/side-effects.ts
8342
- import { getPrefixedCdnBaseAsync, isPrefixedCdnBase } from "@uploadcare/cname-prefix/async";
8343
-
8344
- // src/utils/isPromiseLike.ts
8345
- var isPromiseLike = (value) => {
8346
- return value instanceof Promise || Boolean(
8347
- value && typeof value === "object" && "then" in value && typeof value.then === "function"
8348
- );
8349
- };
8350
-
8351
- // src/blocks/Config/side-effects.ts
8352
- var defineComputedProperty = (declaration) => declaration;
8353
- var COMPUTED_PROPERTIES = [
8354
- defineComputedProperty({
8355
- key: "cameraModes",
8356
- deps: ["enableVideoRecording"],
8357
- fn: ({ cameraModes, enableVideoRecording }) => {
8358
- if (enableVideoRecording === null) {
8359
- return cameraModes;
8360
- }
8361
- let cameraModesCsv = deserializeCsv(cameraModes);
8362
- if (enableVideoRecording && !cameraModesCsv.includes("video")) {
8363
- cameraModesCsv = cameraModesCsv.concat("video");
8364
- } else if (!enableVideoRecording) {
8365
- cameraModesCsv = cameraModesCsv.filter((mode) => mode !== "video");
8366
- }
8367
- return serializeCsv(cameraModesCsv);
8368
- }
8369
- }),
8370
- defineComputedProperty({
8371
- key: "cameraModes",
8372
- deps: ["defaultCameraMode"],
8373
- fn: ({ cameraModes, defaultCameraMode }) => {
8374
- if (defaultCameraMode === null) {
8375
- return cameraModes;
8376
- }
8377
- let cameraModesCsv = deserializeCsv(cameraModes);
8378
- cameraModesCsv = cameraModesCsv.sort((a, b) => {
8379
- if (a === defaultCameraMode) return -1;
8380
- if (b === defaultCameraMode) return 1;
8381
- return 0;
8382
- });
8383
- return serializeCsv(cameraModesCsv);
8384
- }
8385
- }),
8386
- defineComputedProperty({
8387
- key: "cdnCname",
8388
- deps: ["pubkey", "cdnCnamePrefixed"],
8389
- fn: ({ pubkey, cdnCname, cdnCnamePrefixed }) => {
8390
- if (pubkey && (cdnCname === DEFAULT_CDN_CNAME || isPrefixedCdnBase(cdnCname, cdnCnamePrefixed))) {
8391
- return getPrefixedCdnBaseAsync(pubkey, cdnCnamePrefixed);
8392
- }
8393
- return cdnCname;
8394
- }
8395
- })
8396
- ];
8397
- var runSideEffects = ({ key, setValue, getValue }) => {
8398
- for (const computed of COMPUTED_PROPERTIES) {
8399
- if (computed.deps.includes(key)) {
8400
- const args = {
8401
- [computed.key]: getValue(computed.key)
8402
- };
8403
- for (const dep of computed.deps) {
8404
- args[dep] = getValue(dep);
8405
- }
8406
- const result = computed.fn(args);
8407
- if (isPromiseLike(result)) {
8408
- const prevValue = getValue(computed.key);
8409
- result.then((resolvedValue) => {
8410
- const currentValue = getValue(computed.key);
8411
- if (currentValue === prevValue) {
8412
- setValue(computed.key, resolvedValue);
8413
- }
8414
- }).catch((error) => {
8415
- console.error(`Failed to compute value for "${computed.key}"`, error);
8416
- });
8417
- } else {
8418
- setValue(computed.key, result);
8419
- }
8420
- }
8421
- }
8422
- };
8423
-
8424
8445
  // src/blocks/Config/Config.ts
8425
8446
  var allConfigKeys = [
8426
8447
  // "debug" option should go first to be able to print debug messages from the very beginning
@@ -8490,11 +8511,6 @@ var Config = class extends Block {
8490
8511
  this._flushValueToState(key, normalizedValue);
8491
8512
  this.debugPrint(`[uc-config] "${key}"`, normalizedValue);
8492
8513
  runAssertions(this.cfg);
8493
- runSideEffects({
8494
- key,
8495
- setValue: this._setValue.bind(this),
8496
- getValue: this._getValue.bind(this)
8497
- });
8498
8514
  }
8499
8515
  _getValue(key) {
8500
8516
  const anyThis = this;
@@ -8540,10 +8556,14 @@ var Config = class extends Block {
8540
8556
  return this._getValue(key);
8541
8557
  }
8542
8558
  });
8543
- runSideEffects({
8544
- key,
8545
- setValue: this._setValue.bind(this),
8546
- getValue: this._getValue.bind(this)
8559
+ }
8560
+ for (const key of allConfigKeys) {
8561
+ this.sub(sharedConfigKey(key), () => {
8562
+ computeProperty({
8563
+ key,
8564
+ setValue: this._setValue.bind(this),
8565
+ getValue: this._getValue.bind(this)
8566
+ });
8547
8567
  });
8548
8568
  }
8549
8569
  }
@@ -9112,8 +9132,10 @@ var isWhitelistedMessage = (message) => {
9112
9132
  var MessageBridge = class {
9113
9133
  _handlerMap = /* @__PURE__ */ new Map();
9114
9134
  _context;
9115
- constructor(context) {
9135
+ _getTargetOrigin;
9136
+ constructor(context, getTargetOrigin) {
9116
9137
  this._context = context;
9138
+ this._getTargetOrigin = getTargetOrigin;
9117
9139
  window.addEventListener("message", this._handleMessage);
9118
9140
  }
9119
9141
  _handleMessage = (e) => {
@@ -9139,7 +9161,8 @@ var MessageBridge = class {
9139
9161
  handlers.add(handler);
9140
9162
  }
9141
9163
  send(message) {
9142
- this._context.postMessage(message, "*");
9164
+ const targetOrigin = this._getTargetOrigin();
9165
+ this._context.postMessage(message, targetOrigin);
9143
9166
  }
9144
9167
  destroy() {
9145
9168
  window.removeEventListener("message", this._handleMessage);
@@ -9289,11 +9312,9 @@ var ExternalSource = class extends UploaderBlock {
9289
9312
  showSelectionStatus: message.isMultipleMode && message.total > 0,
9290
9313
  couldSelectAll: message.selectedCount < message.total,
9291
9314
  couldDeselectAll: message.selectedCount === message.total,
9292
- selectedList: message.selectedFiles
9315
+ selectedList: message.selectedFiles,
9316
+ showDoneBtn: message.total > 0
9293
9317
  });
9294
- if (!this.$.showDoneBtn && message.isReady) {
9295
- this.$.showDoneBtn = true;
9296
- }
9297
9318
  }
9298
9319
  handleIframeLoad() {
9299
9320
  this.applyEmbedCss(this.cfg.externalSourcesEmbedCss);
@@ -9355,7 +9376,7 @@ var ExternalSource = class extends UploaderBlock {
9355
9376
  return;
9356
9377
  }
9357
9378
  this._messageBridge?.destroy();
9358
- this._messageBridge = new MessageBridge(iframe.contentWindow);
9379
+ this._messageBridge = new MessageBridge(iframe.contentWindow, () => this.cfg.socialBaseUrl);
9359
9380
  this._messageBridge.on("selected-files-change", this.handleSelectedFilesChange.bind(this));
9360
9381
  this._messageBridge.on("toolbar-state-change", this.handleToolbarStateChange.bind(this));
9361
9382
  this.resetSelectionStatus();
@@ -9572,6 +9593,7 @@ var FileItem = class _FileItem extends FileItemConfig {
9572
9593
  const errorText = entry.getValue("errors")?.[0]?.message;
9573
9594
  const source = entry.getValue("source");
9574
9595
  const externalUrl = entry.getValue("externalUrl");
9596
+ const isFinished = state === FileItemState.FINISHED;
9575
9597
  const isUploading = state === FileItemState.UPLOADING;
9576
9598
  const isQueuedForUploading = state === FileItemState.QUEUED_UPLOADING;
9577
9599
  const isQueuedForValidation = state === FileItemState.QUEUED_VALIDATION;
@@ -9580,7 +9602,7 @@ var FileItem = class _FileItem extends FileItemConfig {
9580
9602
  let hint = "";
9581
9603
  if (errorText) {
9582
9604
  hint = "";
9583
- } else if (externalUrl && source && Object.values(ExternalUploadSource).includes(source)) {
9605
+ } else if (!isFinished && externalUrl && source && Object.values(ExternalUploadSource).includes(source)) {
9584
9606
  hint = this.l10n("waiting-for", { source: this.l10n(`src-type-${source}`) });
9585
9607
  }
9586
9608
  this.set$({
package/dist/index.ssr.js CHANGED
@@ -1132,7 +1132,7 @@ export const ModalEvents = {
1132
1132
  DESTROY: "modal:destroy",
1133
1133
  };
1134
1134
  export const PACKAGE_NAME = `blocks`;
1135
- export const PACKAGE_VERSION = `1.24.0`;
1135
+ export const PACKAGE_VERSION = `1.24.1`;
1136
1136
  export const PresenceToggle = class {
1137
1137
  static template = `<slot></slot> `;
1138
1138
  static reg = () => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/file-uploader",
3
- "version": "1.24.0",
3
+ "version": "1.24.1",
4
4
  "description": "Building blocks for Uploadcare products integration",
5
5
  "keywords": [
6
6
  "web components",