@uploadcare/file-uploader 1.17.2 → 1.17.3-alpha.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.
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["Config.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH,gCAXU,CACT,UAAc,EACd,0BAA8B,EAC9B,gCAAoC,EACpC,gCAAoC,EACpC,kBAAsB,EACtB,gBAAoB,EACpB,sBAA0B,EAC1B,sBAA0B,CACvB,CAWF;qBAyNY,OAAO,2BAA2B,EAAE,UAAU,CAAC,OAAO,WAAW,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC;AAAlH,6HAA6H;AAG7H,qBAAiC,MAAM,CAA4C;AA/LnF;IAkBE;;;;OAIG;IACH,+BAYC;IAED;;;;OAIG;IACH,2BAQC;IAED;;;;OAIG;IACH,kBAyBC;IAED;;;OAGG;IACH,kBAIC;IAED;;;;OAIG;IACH,wCAJW,MAAM,iBACN,OAAO,aACP,OAAO,QAoBjB;IA0CD;;;;OAIG;IACH,+BAJW,MAAM,OAAO,gBAAgB,UAC7B,MAAM,UACN,MAAM,QAahB;CACF;sBAjPqB,yBAAyB;AAwD/C,0CAA0C;AAC1C,gCAAoC,MAAM,CAAC,MAAM,OAAO,aAAa,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAGjG"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["Config.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH,gCAXU,CACT,UAAc,EACd,0BAA8B,EAC9B,gCAAoC,EACpC,gCAAoC,EACpC,kBAAsB,EACtB,gBAAoB,EACpB,sBAA0B,EAC1B,sBAA0B,CACvB,CAWF;qBA8NY,OAAO,2BAA2B,EAAE,UAAU,CAAC,OAAO,WAAW,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC;AAAlH,6HAA6H;AAG7H,qBAAiC,MAAM,CAA4C;AApMnF;IAkBE;;;;OAIG;IACH,+BAYC;IAED;;;;OAIG;IACH,2BAQC;IAED;;;;OAIG;IACH,kBAwBC;IAED;;;OAGG;IACH,kBAIC;IAED;;;;OAIG;IACH,wCAJW,MAAM,iBACN,OAAO,aACP,OAAO,QAoBjB;IAgDD;;;;OAIG;IACH,+BAJW,MAAM,OAAO,gBAAgB,UAC7B,MAAM,UACN,MAAM,QAahB;CACF;sBAtPqB,yBAAyB;AAwD/C,0CAA0C;AAC1C,gCAAoC,MAAM,CAAC,MAAM,OAAO,aAAa,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAGjG"}
@@ -142,7 +142,6 @@ class ConfigClass extends Block {
142
142
  runAssertions(this.cfg);
143
143
  runSideEffects({
144
144
  key,
145
- value: normalizedValue ?? null,
146
145
  setValue: this._setValue.bind(this),
147
146
  getValue: this._getValue.bind(this),
148
147
  });
@@ -220,6 +219,12 @@ class ConfigClass extends Block {
220
219
  return this._getValue(key);
221
220
  },
222
221
  });
222
+
223
+ runSideEffects({
224
+ key,
225
+ setValue: this._setValue.bind(this),
226
+ getValue: this._getValue.bind(this),
227
+ });
223
228
  }
224
229
  }
225
230
 
@@ -1,6 +1,7 @@
1
1
  export const DEFAULT_CDN_CNAME: "https://ucarecdn.com";
2
2
  export const DEFAULT_BASE_URL: "https://upload.uploadcare.com";
3
3
  export const DEFAULT_SOCIAL_BASE_URL: "https://social.uploadcare.com";
4
+ export const DEFAULT_PREFIXED_CDN_BASE_DOMAIN: "https://ucarecd.net";
4
5
  /** @type {import('../../types/exported').ConfigType} */
5
6
  export const initialConfig: import("../../types/exported").ConfigType;
6
7
  //# sourceMappingURL=initialConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initialConfig.d.ts","sourceRoot":"","sources":["initialConfig.js"],"names":[],"mappings":"AAKA,gCAAiC,sBAAsB,CAAC;AACxD,+BAAgC,+BAA+B,CAAC;AAChE,sCAAuC,+BAA+B,CAAC;AAEvE,wDAAwD;AACxD,4BADW,OAAO,sBAAsB,EAAE,UAAU,CA4ElD"}
1
+ {"version":3,"file":"initialConfig.d.ts","sourceRoot":"","sources":["initialConfig.js"],"names":[],"mappings":"AAKA,gCAAiC,sBAAsB,CAAC;AACxD,+BAAgC,+BAA+B,CAAC;AAChE,sCAAuC,+BAA+B,CAAC;AACvE,+CAAgD,qBAAqB,CAAC;AAEtE,wDAAwD;AACxD,4BADW,OAAO,sBAAsB,EAAE,UAAU,CA4ElD"}
@@ -6,6 +6,7 @@ import { serializeCsv } from '../utils/comma-separated.js';
6
6
  export const DEFAULT_CDN_CNAME = 'https://ucarecdn.com';
7
7
  export const DEFAULT_BASE_URL = 'https://upload.uploadcare.com';
8
8
  export const DEFAULT_SOCIAL_BASE_URL = 'https://social.uploadcare.com';
9
+ export const DEFAULT_PREFIXED_CDN_BASE_DOMAIN = 'https://ucarecd.net';
9
10
 
10
11
  /** @type {import('../../types/exported').ConfigType} */
11
12
  export const initialConfig = {
@@ -1,7 +1,11 @@
1
- export function runSideEffects<T extends keyof import("../../types").ConfigType>({ key, value, setValue, getValue }: {
1
+ export function runSideEffects<T extends keyof import("../../types").ConfigType>({ key, setValue, getValue }: {
2
2
  key: T;
3
- value: import("../../types").ConfigType[T];
4
- setValue: (key: T, value: import("../../types").ConfigType[T]) => void;
5
- getValue: (key: T) => import("../../types").ConfigType[T];
3
+ setValue: <TSetValue extends keyof import("../../types").ConfigType>(key: TSetValue, value: import("../../types").ConfigType[TSetValue]) => void;
4
+ getValue: <TGetValue extends keyof import("../../types").ConfigType>(key: TGetValue) => import("../../types").ConfigType[TGetValue];
6
5
  }): void;
6
+ export type ComputedPropertyDeclaration<TKey extends keyof import("../../types").ConfigType, TDeps extends Exclude<keyof import("../../types").ConfigType, TKey>[]> = {
7
+ key: TKey;
8
+ deps: TDeps;
9
+ fn: (args: Record<TKey, import("../../types").ConfigType[TKey]> & { [K in TDeps[number]]: import("../../types").ConfigType[K]; }) => import("../../types").ConfigType[TKey] | Promise<import("../../types").ConfigType[TKey]>;
10
+ };
7
11
  //# sourceMappingURL=side-effects.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"side-effects.d.ts","sourceRoot":"","sources":["side-effects.js"],"names":[],"mappings":"AAWO,+BAR+C,CAAC,SAA1C,MAAO,OAAO,aAAa,EAAE,UAAW,sCAC1C;IACN,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAC3C,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACvE,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CAC3D,QAsBH"}
1
+ {"version":3,"file":"side-effects.d.ts","sourceRoot":"","sources":["side-effects.js"],"names":[],"mappings":"AAsFO,+BAZ+C,CAAC,SAA1C,MAAO,OAAO,aAAa,EAAE,UAAW,+BAC1C;IACN,GAAG,EAAE,CAAC,CAAC;IACP,QAAQ,EAAE,CAAC,SAAS,SAAS,MAAM,OAAO,aAAa,EAAE,UAAU,EACjE,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC,SAAS,CAAC,KAC/C,IAAI,CAAC;IACV,QAAQ,EAAE,CAAC,SAAS,SAAS,MAAM,OAAO,aAAa,EAAE,UAAU,EACjE,GAAG,EAAE,SAAS,KACX,OAAO,aAAa,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;CAClD,QAiCH;wCA9GqD,IAAI,SAA7C,MAAO,OAAO,aAAa,EAAE,UAAW,EACkB,KAAK,SAA9D,OAAO,CAAC,MAAM,OAAO,aAAa,EAAE,UAAU,EAAE,IAAI,CAAC,EAAG;SAExD,IAAI;UACJ,KAAK;QACL,CACT,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,aAAa,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,GAC1D,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,GAC1D,KACE,OAAO,aAAa,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,aAAa,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC"}
@@ -1,32 +1,118 @@
1
+ // @ts-check
2
+
3
+ import { getPrefixedCdnBase } from '@uploadcare/cname-prefix';
1
4
  import { deserializeCsv, serializeCsv } from '../utils/comma-separated.js';
5
+ import { DEFAULT_CDN_CNAME, DEFAULT_PREFIXED_CDN_BASE_DOMAIN } from './initialConfig.js';
6
+
7
+ /**
8
+ * @template {keyof import('../../types').ConfigType} TKey
9
+ * @template {Exclude<keyof import('../../types').ConfigType, TKey>[]} TDeps
10
+ * @typedef {Object} ComputedPropertyDeclaration
11
+ * @property {TKey} key
12
+ * @property {TDeps} deps
13
+ * @property {(
14
+ * args: Record<TKey, import('../../types').ConfigType[TKey]> & {
15
+ * [K in TDeps[number]]: import('../../types').ConfigType[K];
16
+ * },
17
+ * ) => import('../../types').ConfigType[TKey] | Promise<import('../../types').ConfigType[TKey]>} fn
18
+ */
19
+
20
+ /**
21
+ * @template {keyof import('../../types').ConfigType} TKey
22
+ * @template {Exclude<keyof import('../../types').ConfigType, TKey>[]} TDeps
23
+ * @param {ComputedPropertyDeclaration<TKey, TDeps>} declaration
24
+ */
25
+ function defineComputedProperty(declaration) {
26
+ return declaration;
27
+ }
28
+
29
+ const COMPUTED_PROPERTIES = [
30
+ defineComputedProperty({
31
+ key: 'cameraModes',
32
+ deps: ['enableVideoRecording'],
33
+ fn: ({ cameraModes, enableVideoRecording }) => {
34
+ if (enableVideoRecording === null) {
35
+ return cameraModes;
36
+ }
37
+ let cameraModesCsv = deserializeCsv(cameraModes);
38
+ if (enableVideoRecording && !cameraModesCsv.includes('video')) {
39
+ cameraModesCsv = cameraModesCsv.concat('video');
40
+ } else if (!enableVideoRecording) {
41
+ cameraModesCsv = cameraModesCsv.filter((mode) => mode !== 'video');
42
+ }
43
+ return serializeCsv(cameraModesCsv);
44
+ },
45
+ }),
46
+ defineComputedProperty({
47
+ key: 'cameraModes',
48
+ deps: ['defaultCameraMode'],
49
+ fn: ({ cameraModes, defaultCameraMode }) => {
50
+ if (defaultCameraMode === null) {
51
+ return cameraModes;
52
+ }
53
+ let cameraModesCsv = deserializeCsv(cameraModes);
54
+ cameraModesCsv = cameraModesCsv.sort((a, b) => {
55
+ if (a === defaultCameraMode) return -1;
56
+ if (b === defaultCameraMode) return 1;
57
+ return 0;
58
+ });
59
+ return serializeCsv(cameraModesCsv);
60
+ },
61
+ }),
62
+ defineComputedProperty({
63
+ key: 'cdnCname',
64
+ deps: ['pubkey'],
65
+ fn: ({ pubkey, cdnCname }) => {
66
+ if (cdnCname !== DEFAULT_CDN_CNAME) {
67
+ return cdnCname;
68
+ }
69
+ return getPrefixedCdnBase(pubkey, DEFAULT_PREFIXED_CDN_BASE_DOMAIN);
70
+ },
71
+ }),
72
+ ];
2
73
 
3
74
  /**
4
75
  * @template {keyof import('../../types').ConfigType} T
5
76
  * @param {{
6
77
  * key: T;
7
- * value: import('../../types').ConfigType[T];
8
- * setValue: (key: T, value: import('../../types').ConfigType[T]) => void;
9
- * getValue: (key: T) => import('../../types').ConfigType[T];
78
+ * setValue: <TSetValue extends keyof import('../../types').ConfigType>(
79
+ * key: TSetValue,
80
+ * value: import('../../types').ConfigType[TSetValue],
81
+ * ) => void;
82
+ * getValue: <TGetValue extends keyof import('../../types').ConfigType>(
83
+ * key: TGetValue,
84
+ * ) => import('../../types').ConfigType[TGetValue];
10
85
  * }} options
11
86
  */
12
- export const runSideEffects = ({ key, value, setValue, getValue }) => {
13
- if (key === 'enableVideoRecording' && value !== null) {
14
- let cameraModes = deserializeCsv(getValue('cameraModes'));
15
- if (value && !cameraModes.includes('video')) {
16
- cameraModes = cameraModes.concat('video');
17
- } else if (!value) {
18
- cameraModes = cameraModes.filter((mode) => mode !== 'video');
87
+ export const runSideEffects = ({ key, setValue, getValue }) => {
88
+ for (const computed of COMPUTED_PROPERTIES) {
89
+ if (computed.deps.includes(key)) {
90
+ const args = {
91
+ [computed.key]: getValue(computed.key),
92
+ ...computed.deps.reduce(
93
+ (acc, dep) => ({
94
+ ...acc,
95
+ [dep]: getValue(dep),
96
+ }),
97
+ /**
98
+ * @type {Record<typeof computed.key, import('../../types').ConfigType[typeof computed.key]> & {
99
+ * [K in (typeof computed.deps)[number]]: import('../../types').ConfigType[K];
100
+ * }}
101
+ */ ({}),
102
+ ),
103
+ };
104
+ const result = computed.fn(args);
105
+ if (result instanceof Promise) {
106
+ // There could be a race condition here if the value is changed too frequently,
107
+ // but we assume that the async computed properties are not expected to change often
108
+ result
109
+ .then((resolvedValue) => setValue(computed.key, resolvedValue))
110
+ .catch((error) => {
111
+ console.error(`Failed to compute value for "${computed.key}"`, error);
112
+ });
113
+ } else {
114
+ setValue(computed.key, result);
115
+ }
19
116
  }
20
- setValue('cameraModes', serializeCsv(cameraModes));
21
- }
22
-
23
- if (key === 'defaultCameraMode' && value !== null) {
24
- let cameraModes = deserializeCsv(getValue('cameraModes'));
25
- cameraModes = cameraModes.sort((a, b) => {
26
- if (a === value) return -1;
27
- if (b === value) return 1;
28
- return 0;
29
- });
30
- setValue('cameraModes', serializeCsv(cameraModes));
31
117
  }
32
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/file-uploader",
3
- "version": "1.17.2",
3
+ "version": "1.17.3-alpha.0",
4
4
  "description": "Building blocks for Uploadcare products integration",
5
5
  "keywords": [
6
6
  "web components",
@@ -141,6 +141,7 @@
141
141
  "license": "MIT",
142
142
  "dependencies": {
143
143
  "@symbiotejs/symbiote": "^1.11.7",
144
+ "@uploadcare/cname-prefix": "^6.15.2",
144
145
  "@uploadcare/image-shrink": "^6.14.1",
145
146
  "@uploadcare/upload-client": "^6.14.1",
146
147
  "keyux": "^0.7.1"