Skip to content

Commit 295f777

Browse files
committed
chore: update symbiote to v2
1 parent a8b63cf commit 295f777

File tree

86 files changed

+3121
-1453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3121
-1453
lines changed

Diff for: .github/workflows/checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111
- uses: actions/setup-node@v2
1212
with:
13-
node-version: '16'
13+
node-version: '20'
1414
- name: Install dependencies
1515
working-directory: ./
1616
run: npm ci

Diff for: .github/workflows/codeql.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ jobs:
3131
with:
3232
languages: ${{ matrix.language }}
3333
queries: +security-and-quality
34-
paths-ignore:
35-
- '**/*.test-d.ts(x?)'
34+
paths-ignore: "**/*.test-d.ts(x?)"
3635
- name: Autobuild
3736
uses: github/codeql-action/autobuild@v2
3837

Diff for: .github/workflows/shipjs-manual-prepare.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
ref: main
1616
- uses: actions/setup-node@v2
1717
with:
18-
node-version: '16'
18+
node-version: '20'
1919
- run: npm ci
2020
- run: |
2121
git config --global user.email "github-actions[bot]@users.noreply.github.com"

Diff for: .github/workflows/shipjs-trigger.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/setup-node@v2
1717
with:
1818
registry-url: "https://registry.npmjs.org"
19-
node-version: '16'
19+
node-version: '20'
2020
- run: npm ci
2121
- run: |
2222
git config --global user.email "github-actions[bot]@users.noreply.github.com"

Diff for: .nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ We use [JSDoc type annotations](https://www.typescriptlang.org/docs/handbook/int
8585
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-regular.min.css"
8686
/>
8787

88-
<uc-file-uploader-regular ctx-name="my-uploader"> </uc-file-uploader-regular>
88+
<uc-file-uploader-regular ctx="my-uploader"> </uc-file-uploader-regular>
8989
```
9090

9191
3. Configure Uploadcare File Uploader and add your personal public key to the project. Discover the instructions in the [following section](#configuration).
@@ -109,7 +109,7 @@ UC.defineComponents(UC);
109109
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-regular.min.css"
110110
/>
111111

112-
<uc-file-uploader-inline ctx-name="my-uploader"> </uc-file-uploader-inline>
112+
<uc-file-uploader-inline ctx="my-uploader"> </uc-file-uploader-inline>
113113
```
114114

115115
4. Configure Uploadcare File Uploader and add your personal public key to the project. Discover the instructions in the [following section](#configuration).
@@ -123,10 +123,10 @@ All configurations in Uploadcare File Uploader are managed from `uc-config` bloc
123123
3. Add a `uc-config` block to your markup and replace `YOUR_PUBLIC_KEY` with your own public key:
124124

125125
```html
126-
<uc-config ctx-name="my-uploader" pubkey="YOUR_PUBLIC_KEY"></uc-config>
126+
<uc-config ctx="my-uploader" pubkey="YOUR_PUBLIC_KEY"></uc-config>
127127
```
128128

129-
4. Make sure that your config block uses the same `ctx-name` attribute value as your solution block.
129+
4. Make sure that your config block uses the same `ctx` attribute value as your solution block.
130130

131131
Discover more about Uploadcare File Uploader configuration in [our documentation](https://uploadcare.com/docs/file-uploader/configuration/?ref=github-readme).
132132

Diff for: abstract/ActivityBlock.js

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export class ActivityBlock extends Block {
5454
this.setAttribute('activity', this.activityType);
5555
}
5656
this.sub('*currentActivity', (/** @type {String} */ val) => {
57+
if (this.activityType === 'url') {
58+
}
5759
if (this.activityType !== val && this[ACTIVE_PROP]) {
5860
this._deactivate();
5961
} else if (this.activityType === val && !this[ACTIVE_PROP]) {

Diff for: abstract/Block.js

+37-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
// @ts-check
2-
import { BaseComponent, Data } from '@symbiotejs/symbiote';
2+
import { DICT, PubSub, Symbiote } from '@symbiotejs/symbiote';
3+
// @ts-ignore - something wrong with the tsd
4+
import { slotProcessor } from '@symbiotejs/symbiote/core/slotProcessor.js';
35
import { initialConfig } from '../blocks/Config/initialConfig.js';
46
import { EventEmitter } from '../blocks/UploadCtxProvider/EventEmitter.js';
57
import { WindowHeightTracker } from '../utils/WindowHeightTracker.js';
6-
import { extractFilename, extractCdnUrlModifiers, extractUuid } from '../utils/cdn-utils.js';
8+
import { extractCdnUrlModifiers, extractFilename, extractUuid } from '../utils/cdn-utils.js';
79
import { getLocaleDirection } from '../utils/getLocaleDirection.js';
810
import { getPluralForm } from '../utils/getPluralForm.js';
911
import { applyTemplateData, getPluralObjects } from '../utils/template-utils.js';
1012
import { waitForAttribute } from '../utils/waitForAttribute.js';
1113
import { blockCtx } from './CTX.js';
1214
import { LocaleManager, localeStateKey } from './LocaleManager.js';
15+
import { A11y } from './a11y.js';
1316
import { l10nProcessor } from './l10nProcessor.js';
1417
import { sharedConfigKey } from './sharedConfigKey.js';
15-
import { A11y } from './a11y.js';
18+
import { bindCompatibilityFallbackProcessor } from './bindCompatibilityFallbackProcessor.js';
1619

1720
const TAG_PREFIX = 'uc-';
21+
const CTX_NAME_FALLBACK_ATTR = 'ctx-name';
1822

1923
// @ts-ignore TODO: fix this
20-
export class Block extends BaseComponent {
24+
export class Block extends Symbiote {
2125
/** @type {string | null} */
2226
static StateConsumerScope = null;
2327

@@ -78,8 +82,12 @@ export class Block extends BaseComponent {
7882
super();
7983
/** @type {Map<string, Set<{ remove: () => void }>>} */
8084
this.l10nProcessorSubs = new Map();
81-
// @ts-ignore TODO: fix this
85+
// @ts-expect-error TODO: fix this
8286
this.addTemplateProcessor(l10nProcessor);
87+
this.addTemplateProcessor(slotProcessor);
88+
89+
// Prepend tpl processors with bind compatibility fallback processor
90+
this.tplProcessors = new Set([bindCompatibilityFallbackProcessor, ...this.tplProcessors]);
8391
}
8492

8593
/**
@@ -135,17 +143,29 @@ export class Block extends BaseComponent {
135143
this.processInnerHtml = true;
136144
}
137145
if (this.requireCtxName) {
138-
waitForAttribute({
139-
element: this,
140-
attribute: 'ctx-name',
141-
onSuccess: () => {
142-
// async wait for ctx-name attribute to be set, needed for Angular because it sets attributes after mount
146+
Promise.race([
147+
waitForAttribute({
148+
element: this,
149+
attribute: DICT.CTX_NAME_ATTR,
150+
}),
151+
waitForAttribute({
152+
element: this,
153+
attribute: CTX_NAME_FALLBACK_ATTR,
154+
}),
155+
]).then((result) => {
156+
if (result.success) {
157+
if (result.attribute === CTX_NAME_FALLBACK_ATTR) {
158+
const ctxName = result.value;
159+
this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxName}'`);
160+
}
161+
// async wait for ctx attribute to be set, needed for Angular because it sets attributes after mount
143162
// TODO: should be moved to the symbiote core
144163
super.connectedCallback();
145-
},
146-
onTimeout: () => {
147-
console.error('Attribute `ctx-name` is required and it is not set.');
148-
},
164+
} else {
165+
console.error(
166+
`Attribute "${DICT.CTX_NAME_ATTR}" or "${CTX_NAME_FALLBACK_ATTR}" is required and it is not set.`,
167+
);
168+
}
149169
});
150170
} else {
151171
super.connectedCallback();
@@ -217,7 +237,7 @@ export class Block extends BaseComponent {
217237

218238
// Destroy local context
219239
// TODO: this should be done inside symbiote
220-
Data.deleteCtx(this);
240+
PubSub.deleteCtx(this.localCtx.uid);
221241

222242
if (blocksRegistry?.size === 0) {
223243
setTimeout(() => {
@@ -233,7 +253,7 @@ export class Block extends BaseComponent {
233253
* @protected
234254
*/
235255
destroyCtxCallback() {
236-
Data.deleteCtx(this.ctxName);
256+
PubSub.deleteCtx(this.ctxName);
237257

238258
this.localeManager?.destroy();
239259
}
@@ -327,6 +347,7 @@ export class Block extends BaseComponent {
327347
const resolver = args[0];
328348
consoleArgs = resolver();
329349
}
350+
330351
console.log(`[${this.ctxName}]`, ...consoleArgs);
331352
}
332353

@@ -341,5 +362,3 @@ export class Block extends BaseComponent {
341362
}
342363
}
343364
}
344-
345-
export { BaseComponent };

Diff for: abstract/CTX.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const uploaderBlockCtx = (fnCtx) => ({
2525
'*uploadList': [],
2626
'*focusedEntry': null,
2727
'*uploadQueue': new Queue(1),
28-
/** @type {ReturnType<import('../types').OutputErrorCollection>[]} */
28+
/** @type {import('../types').OutputErrorCollection[]} */
2929
'*collectionErrors': [],
3030
/** @type {import('../types').OutputCollectionState | null} */
3131
'*collectionState': null,

Diff for: abstract/TypedCollection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Data, UID } from '@symbiotejs/symbiote';
1+
import { PubSub, UID } from '@symbiotejs/symbiote';
22
import { TypedData } from './TypedData.js';
33

44
export class TypedCollection {
@@ -22,9 +22,9 @@ export class TypedCollection {
2222
this.__ctxId = options.ctxName || UID.generate();
2323
/**
2424
* @private
25-
* @type {Data}
25+
* @type {PubSub}
2626
*/
27-
this.__data = Data.registerCtx({}, this.__ctxId);
27+
this.__data = PubSub.registerCtx({}, this.__ctxId);
2828
/**
2929
* @private
3030
* @type {string[]}
@@ -232,7 +232,7 @@ export class TypedCollection {
232232
}
233233

234234
destroy() {
235-
Data.deleteCtx(this.__ctxId);
235+
PubSub.deleteCtx(this.__ctxId);
236236
this.__propertyObservers = null;
237237
this.__collectionObservers = null;
238238
for (let id in this.__subsMap) {

Diff for: abstract/TypedData.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Data, UID } from '@symbiotejs/symbiote';
1+
import { PubSub, UID } from '@symbiotejs/symbiote';
22

33
const MSG_NAME = '[Typed State] Wrong property name: ';
44
const MSG_TYPE = '[Typed State] Wrong property type: ';
@@ -20,9 +20,9 @@ export class TypedData {
2020
}, {});
2121
/**
2222
* @private
23-
* @type {Data}
23+
* @type {PubSub}
2424
*/
25-
this.__data = Data.registerCtx(this.__schema, this.__ctxId);
25+
this.__data = PubSub.registerCtx(this.__schema, this.__ctxId);
2626
}
2727

2828
/** @returns {String} */
@@ -72,6 +72,6 @@ export class TypedData {
7272
}
7373

7474
remove() {
75-
Data.deleteCtx(this.__ctxId);
75+
PubSub.deleteCtx(this.__ctxId);
7676
}
7777
}

Diff for: abstract/UploaderBlock.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
import { ActivityBlock } from './ActivityBlock.js';
33

4-
import { Data } from '@symbiotejs/symbiote';
4+
import { PubSub } from '@symbiotejs/symbiote';
55
import { uploadFileGroup } from '@uploadcare/upload-client';
66
import { calculateMaxCenteredCropFrame } from '../blocks/CloudImageEditor/src/crop-utils.js';
77
import { parseCropPreset } from '../blocks/CloudImageEditor/src/lib/parseCropPreset.js';
@@ -234,7 +234,7 @@ export class UploaderBlock extends ActivityBlock {
234234

235235
if (changeMap.uploadProgress) {
236236
for (const entryId of changeMap.uploadProgress) {
237-
const { isUploading, silent } = Data.getCtx(entryId).store;
237+
const { isUploading, silent } = PubSub.getCtx(entryId).store;
238238
if (isUploading && !silent) {
239239
this.emit(EventType.FILE_UPLOAD_PROGRESS, this.api.getOutputItem(entryId));
240240
}
@@ -244,15 +244,15 @@ export class UploaderBlock extends ActivityBlock {
244244
}
245245
if (changeMap.isUploading) {
246246
for (const entryId of changeMap.isUploading) {
247-
const { isUploading, silent } = Data.getCtx(entryId).store;
247+
const { isUploading, silent } = PubSub.getCtx(entryId).store;
248248
if (isUploading && !silent) {
249249
this.emit(EventType.FILE_UPLOAD_START, this.api.getOutputItem(entryId));
250250
}
251251
}
252252
}
253253
if (changeMap.fileInfo) {
254254
for (const entryId of changeMap.fileInfo) {
255-
const { fileInfo, silent } = Data.getCtx(entryId).store;
255+
const { fileInfo, silent } = PubSub.getCtx(entryId).store;
256256
if (fileInfo && !silent) {
257257
this.emit(EventType.FILE_UPLOAD_SUCCESS, this.api.getOutputItem(entryId));
258258
}
@@ -263,7 +263,7 @@ export class UploaderBlock extends ActivityBlock {
263263
}
264264
if (changeMap.errors) {
265265
for (const entryId of changeMap.errors) {
266-
const { errors } = Data.getCtx(entryId).store;
266+
const { errors } = PubSub.getCtx(entryId).store;
267267
if (errors.length > 0) {
268268
this.emit(EventType.FILE_UPLOAD_FAILED, this.api.getOutputItem(entryId));
269269
this.emit(

Diff for: abstract/UploaderPublicApi.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// @ts-check
22
import { ActivityBlock } from './ActivityBlock.js';
33

4-
import { Data } from '@symbiotejs/symbiote';
4+
import { PubSub } from '@symbiotejs/symbiote';
55
import { EventType } from '../blocks/UploadCtxProvider/EventEmitter.js';
66
import { UploadSource } from '../blocks/utils/UploadSource.js';
77
import { serializeCsv } from '../blocks/utils/comma-separated.js';
88
import { IMAGE_ACCEPT_LIST, fileIsImage, mergeFileTypes } from '../utils/fileTypes.js';
99
import { parseCdnUrl } from '../utils/parseCdnUrl.js';
10-
import { buildOutputCollectionState } from './buildOutputCollectionState.js';
1110
import { stringToArray } from '../utils/stringToArray.js';
11+
import { buildOutputCollectionState } from './buildOutputCollectionState.js';
1212

1313
export class UploaderPublicApi {
1414
/**
@@ -176,7 +176,7 @@ export class UploaderPublicApi {
176176
* @returns {import('../types/exported.js').OutputFileEntry<TStatus>}
177177
*/
178178
getOutputItem = (entryId) => {
179-
const uploadEntryData = /** @type {import('./uploadEntrySchema.js').UploadEntry} */ (Data.getCtx(entryId).store);
179+
const uploadEntryData = /** @type {import('./uploadEntrySchema.js').UploadEntry} */ (PubSub.getCtx(entryId).store);
180180

181181
/** @type {import('@uploadcare/upload-client').UploadcareFile?} */
182182
const fileInfo = uploadEntryData.fileInfo;

Diff for: abstract/bindCompatibilityFallbackProcessor.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @ts-check
2+
3+
import { DICT } from '@symbiotejs/symbiote';
4+
5+
const FALLBACK_BIND_ATTR = 'set';
6+
7+
/** @param {DocumentFragment | import('@symbiotejs/symbiote').Symbiote<any>} fr */
8+
export function bindCompatibilityFallbackProcessor(fr) {
9+
[...fr.querySelectorAll(`[${FALLBACK_BIND_ATTR}]`)].forEach((el) => {
10+
const setAttrValue = el.getAttribute(FALLBACK_BIND_ATTR);
11+
if (setAttrValue) {
12+
el.removeAttribute(FALLBACK_BIND_ATTR);
13+
el.setAttribute(DICT.BIND_ATTR, setAttrValue);
14+
}
15+
});
16+
}

Diff for: abstract/defineComponents.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
const EXCLUDE_COMPONENTS = ['Symbiote', 'BaseComponent', 'UploaderBlock', 'ActivityBlock', 'Block', 'SolutionBlock'];
2+
13
/** @param {Object<string, any>} blockExports */
24
export function defineComponents(blockExports) {
35
for (let blockName in blockExports) {
6+
if (EXCLUDE_COMPONENTS.includes(blockName)) {
7+
continue;
8+
}
49
let tagName = [...blockName].reduce((name, char) => {
510
if (char.toUpperCase() === char) {
611
char = '-' + char.toLowerCase();

Diff for: abstract/l10nProcessor.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ export function l10nProcessor(fr, fnCtx) {
4848
// We don't need the leading * in the key because we use the key as a local context key relative to the global state
4949
const nodeStateKey = localeStateKey(mappedKey).replace('*', '');
5050
// If the key is not present in the node context, add it
51-
if (!fnCtx.nodeCtx.has(nodeStateKey)) {
52-
fnCtx.nodeCtx.add(nodeStateKey, mappedKey);
51+
if (!fnCtx.sharedCtx.has(nodeStateKey)) {
52+
fnCtx.sharedCtx.add(nodeStateKey, mappedKey);
5353
}
5454
// Subscribe on the global l10n key change
55-
const sub = fnCtx.nodeCtx.sub(nodeStateKey, () => {
55+
const sub = fnCtx.sharedCtx.sub(nodeStateKey, () => {
5656
el[/** @type {'textContent'} */ (elProp)] = fnCtx.l10n(mappedKey);
5757
});
5858
keySubs?.add(sub);

Diff for: abstract/uploadEntrySchema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const uploadEntrySchema = Object.freeze({
109109
},
110110
source: {
111111
type: String,
112-
value: false,
112+
value: null,
113113
nullable: true,
114114
},
115115
fullPath: {

0 commit comments

Comments
 (0)