Skip to content

Commit eb34af9

Browse files
committed
WIP
1 parent a8b63cf commit eb34af9

File tree

85 files changed

+3120
-1449
lines changed

Some content is hidden

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

85 files changed

+3120
-1449
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
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

.github/workflows/codeql.yml

Lines changed: 1 addition & 2 deletions
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

.github/workflows/shipjs-manual-prepare.yml

Lines changed: 1 addition & 1 deletion
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"

.github/workflows/shipjs-trigger.yml

Lines changed: 1 addition & 1 deletion
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"

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

README.md

Lines changed: 4 additions & 4 deletions
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

abstract/ActivityBlock.js

Lines changed: 2 additions & 0 deletions
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]) {

abstract/Block.js

Lines changed: 37 additions & 18 deletions
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 };

abstract/TypedCollection.js

Lines changed: 4 additions & 4 deletions
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) {

abstract/TypedData.js

Lines changed: 4 additions & 4 deletions
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
}

0 commit comments

Comments
 (0)