Skip to content

Commit

Permalink
Merge branch 'main' into feat/async-secure-delivery-callback
Browse files Browse the repository at this point in the history
# Conflicts:
#	abstract/Block.js
  • Loading branch information
nd0ut committed Jul 16, 2024
2 parents 3917397 + dea43c7 commit f2c871e
Show file tree
Hide file tree
Showing 177 changed files with 2,401 additions and 3,882 deletions.
5 changes: 0 additions & 5 deletions .stylelintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ module.exports = {
files: ['blocks/**/*.css', 'solutions/**/*.css'],
ignoreFiles: ['**/test/**/*.css'],
plugins: ['./stylelint-force-app-name-prefix.cjs'],
rules: {
'plugin/stylelint-force-app-name-prefix': {
appName: 'lr',
},
},
},
],
};
76 changes: 74 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,81 @@
# [0.43.0](https://github.com/uploadcare/blocks/compare/v0.42.1...v0.43.0) (2024-06-14)
# [0.49.0](https://github.com/uploadcare/blocks/compare/v0.48.1...v0.49.0) (2024-07-03)

### BEAKING CHANGES

- **styles:** Added the `uc-` prefix to all class selectors ([#683](https://github.com/uploadcare/blocks/issues/683)) ([a3929d5](https://github.com/uploadcare/blocks/commit/a3929d599e23e221b2fe88b2d2489a35c8ee7899)).

See the [migration guide](https://uploadcare.com/docs/file-uploader/migration-to-0.49.0/) for details.

## [0.48.1](https://github.com/uploadcare/blocks/compare/v0.48.0...v0.48.1) (2024-07-02)

### Bug Fixes

- **a11y:** Added a type for the button ([#695](https://github.com/uploadcare/blocks/issues/695)) ([af1d6b6](https://github.com/uploadcare/blocks/commit/af1d6b63112cc383bcad52d099d84460da937ffa))

## [0.48.0](https://github.com/uploadcare/blocks/compare/v0.47.0...v0.48.0) (2024-07-02)

# [0.47.0](https://github.com/uploadcare/blocks/compare/v0.46.3...v0.47.0) (2024-07-02)

### BEAKING CHANGES

- Extract public api to the composition class at the Uploader API instance that you can get using `getAPI()` method of the `lr-upload-ctx-provider` block. ([#676](https://github.com/uploadcare/blocks/issues/676)) ([ea29dd2](https://github.com/uploadcare/blocks/commit/ea29dd2ebfc5b5897c7db8f6dbda608604eea86c)).

See the [migration guide](https://uploadcare.com/docs/file-uploader/migration-to-0.47.0/) for details.

## [0.46.3](https://github.com/uploadcare/blocks/compare/v0.46.2...v0.46.3) (2024-07-01)

### Bug Fixes

- **icons:** Added currentColor to icon edit-file ([#689](https://github.com/uploadcare/blocks/issues/689)) ([617d3cd](https://github.com/uploadcare/blocks/commit/617d3cd8e0cde8ecadd6024ce321b7ba507009f1))

## [0.46.2](https://github.com/uploadcare/blocks/compare/v0.46.1...v0.46.2) (2024-07-01)

### Bug Fixes

- **icons:** added icon edit file ([#687](https://github.com/uploadcare/blocks/issues/687)) ([2a869ab](https://github.com/uploadcare/blocks/commit/2a869abfdbe571aff52ccc5687a8c66e0d829cb5))

## [0.46.1](https://github.com/uploadcare/blocks/compare/v0.46.0...v0.46.1) (2024-06-28)

### Bug Fixes

- **events:** Added status after deleting files in idle ([#684](https://github.com/uploadcare/blocks/issues/684)) ([0e07ee3](https://github.com/uploadcare/blocks/commit/0e07ee3d82a326e56cab343dafdf7472f2d73216))

# [0.46.0](https://github.com/uploadcare/blocks/compare/v0.45.0...v0.46.0) (2024-06-24)

### Features

- added `collectionValidators` and `fileValidators`: Custom validators are now supported for collections and files. This enhancement allows for the addition of necessary checks for uploaded files and collections, providing flexibility and control over compliance with requirements ([#667](https://github.com/uploadcare/blocks/issues/667)) ([d3260b0](https://github.com/uploadcare/blocks/commit/d3260b0cce5ac6ca7cfd0aeb8aff0c9fc35036ed)). See docs [here](https://uploadcare.com/docs/file-uploader/validators).
- Significant improvements to accessibility and keyboard navigation, enhancing user experience and inclusivity ([#671](https://github.com/uploadcare/blocks/issues/671)) ([4acb8a0](https://github.com/uploadcare/blocks/commit/4acb8a0b7ea9c7a95be415627f7d4e1eb748fcf2))

# [0.45.0](https://github.com/uploadcare/blocks/compare/v0.44.0...v0.45.0) (2024-06-23)

### BEAKING CHANGES

- The previously deprecated API method `setUploadMetadata` has been removed. Use `metadata` instance property on `lr-config` block instead. See [metadata](https://uploadcare.com/docs/file-uploader/options/#metadata) for more details.
- The previously deprecated API method `addFiles` has been removed. Use `addFileFromObject`, `addFileFromUrl` or `addFileFromUuid` instead. See [File Uploader API](https://uploadcare.com/docs/file-uploader/api/#add-file-from-object) for more details.

See the [migration guide](https://uploadcare.com/docs/file-uploader/migration-to-0.45.0/) for details.

# [0.44.0](https://github.com/uploadcare/blocks/compare/v0.43.0...v0.44.0) (2024-06-21)

### BEAKING CHANGES

- All theme variables of the previous version are deprecated and won't affect the look anymore.
- The default button that opens the uploader dialog (SimpleBtn) component now uses independent variables.
- By default, the theme now uses OKLCH color space. You can still override it using other color spaces, but we recommend converting your colors to OKLCH.

See the [migration guide](https://uploadcare.com/docs/file-uploader/migration-to-0.44.0/) for details.

Full styling docs are available [here](https://uploadcare.com/docs/file-uploader/styling/).

### Features

- updated theming mechanics with oklch colors and reworked css properties ([#662](https://github.com/uploadcare/blocks/issues/662)) ([ee90e66](https://github.com/uploadcare/blocks/commit/ee90e66c076e21e1ee92b2f4c60f8eb955a7d5bc))

# [0.43.0](https://github.com/uploadcare/blocks/compare/v0.42.1...v0.43.0) (2024-06-14)

### Features

- added `collectionValidators` and `fileValidators`: Custom validators are now supported for collections and files. This enhancement allows for the addition of necessary checks for uploaded files and collections, providing flexibility and control over compliance with requirements ([#667](https://github.com/uploadcare/blocks/issues/667)) ([d3260b0](https://github.com/uploadcare/blocks/commit/d3260b0cce5ac6ca7cfd0aeb8aff0c9fc35036ed)). See docs [here](https://uploadcare.com/docs/file-uploader/validators).

## [0.42.1](https://github.com/uploadcare/blocks/compare/v0.42.0...v0.42.1) (2024-05-30)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ and [even more](<(https://uploadcare.com/features/?ref=github-readme)>).

See Uploadcare Blocks [in action](https://codesandbox.io/p/devbox/github/uploadcare/blocks-examples/tree/main/examples/js-uploader)!

<img alt="Uploadcare Blocks examples" src="https://ucarecdn.com/8035cdc7-f0b9-4ea9-8c15-05816f315481/">
<img alt="Uploadcare Blocks examples" src="https://ucarecdn.com/2883da9f-6962-49db-9947-f91a3e25be2f/-/preview/">

## Core features

Expand Down
18 changes: 9 additions & 9 deletions abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const ACTIVE_ATTR = 'active';
const ACTIVE_PROP = '___ACTIVITY_IS_ACTIVE___';

export class ActivityBlock extends Block {
/** @protected */
historyTracked = false;

init$ = activityBlockCtx(this);

_debouncedHistoryFlush = debounce(this._historyFlush.bind(this), 10);
Expand Down Expand Up @@ -37,6 +39,7 @@ export class ActivityBlock extends Block {
});
}

/** @protected */
initCallback() {
super.initCallback();
if (this.hasAttribute('current-activity')) {
Expand Down Expand Up @@ -131,21 +134,21 @@ export class ActivityBlock extends Block {
ActivityBlock._activityCallbacks.delete(this);
}

/** @protected */
destroyCallback() {
super.destroyCallback();
this._isActivityRegistered() && this.unregisterActivity();

/** @type {string | null} */
const currentActivity = this.$['*currentActivity'];

/** @type {Set<import('./Block').Block>} */
let blocksRegistry = this.$['*blocksRegistry'];
const hasCurrentActivityInCtx = !![...blocksRegistry].find(
const hasCurrentActivityInCtx = !![...this.blocksRegistry].find(
(block) => block instanceof ActivityBlock && block.activityType === currentActivity,
);

if (!hasCurrentActivityInCtx) {
this.$['*currentActivity'] = null;
this.setOrAddState('*modalActive', false);
}
}

Expand Down Expand Up @@ -177,10 +180,8 @@ export class ActivityBlock extends Block {
}
let couldOpenActivity = !!nextActivity;
if (nextActivity) {
/** @type {Set<ActivityBlock>} */
let blocksRegistry = this.$['*blocksRegistry'];
const nextActivityBlock = [...blocksRegistry].find((block) => block.activityType === nextActivity);
couldOpenActivity = nextActivityBlock?.couldOpenActivity ?? false;
const nextActivityBlock = [...this.blocksRegistry].find((block) => block.activityType === nextActivity);
couldOpenActivity = /** @type {ActivityBlock} */ (nextActivityBlock)?.couldOpenActivity ?? false;
}
nextActivity = couldOpenActivity ? nextActivity : undefined;
this.$['*currentActivity'] = nextActivity;
Expand All @@ -198,10 +199,9 @@ ActivityBlock.activities = Object.freeze({
DRAW: 'draw',
UPLOAD_LIST: 'upload-list',
URL: 'url',
CONFIRMATION: 'confirmation',
CLOUD_IMG_EDIT: 'cloud-image-edit',
EXTERNAL: 'external',
DETAILS: 'details',
});

/** @typedef {(typeof ActivityBlock)['activities'][keyof (typeof ActivityBlock)['activities']] | null} ActivityType */
/** @typedef {(typeof ActivityBlock)['activities'][keyof (typeof ActivityBlock)['activities']] | (string & {}) | null} ActivityType */
90 changes: 47 additions & 43 deletions abstract/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ import { blockCtx } from './CTX.js';
import { LocaleManager, localeStateKey } from './LocaleManager.js';
import { l10nProcessor } from './l10nProcessor.js';
import { sharedConfigKey } from './sharedConfigKey.js';
import { A11y } from './a11y.js';

const TAG_PREFIX = 'lr-';

// @ts-ignore TODO: fix this
export class Block extends BaseComponent {
/** @type {string | null} */
static StateConsumerScope = null;
static className = '';

/** @type {string[]} */
static styleAttrs = [];

/** @protected */
requireCtxName = false;
allowCustomTemplate = true;

/** @type {import('./ActivityBlock.js').ActivityType} */
activityType = null;

Expand Down Expand Up @@ -49,6 +54,7 @@ export class Block extends BaseComponent {
}

/**
* @private
* @param {string} key
* @param {number} count
* @returns {string}
Expand All @@ -62,6 +68,7 @@ export class Block extends BaseComponent {
/**
* @param {string} key
* @param {() => void} resolver
* @protected
*/
bindL10n(key, resolver) {
this.localeManager?.bindL10n(this, key, resolver);
Expand Down Expand Up @@ -94,10 +101,7 @@ export class Block extends BaseComponent {
* @returns {Boolean}
*/
hasBlockInCtx(callback) {
// @ts-ignore TODO: fix this
/** @type {Set} */
let blocksRegistry = this.$['*blocksRegistry'];
for (let block of blocksRegistry) {
for (let block of this.blocksRegistry) {
if (callback(block)) {
return true;
}
Expand All @@ -118,20 +122,12 @@ export class Block extends BaseComponent {
);
}

/** @param {import('./ActivityBlock.js').ActivityType} activityType */
setActivity(activityType) {
if (this.hasBlockInCtx((b) => b.activityType === activityType)) {
this.$['*currentActivity'] = activityType;
return;
}
console.warn(`Activity type "${activityType}" not found in the context`);
}

/** @protected */
connectedCallback() {
const className = /** @type {typeof Block} */ (this.constructor).className;
if (className) {
this.classList.toggle(`${TAG_PREFIX}${className}`, true);
}
const styleAttrs = /** @type {typeof Block} */ (this.constructor).styleAttrs;
styleAttrs.forEach((attr) => {
this.setAttribute(attr, '');
});

if (this.hasAttribute('retpl')) {
// @ts-ignore TODO: fix this
Expand All @@ -158,11 +154,13 @@ export class Block extends BaseComponent {
WindowHeightTracker.registerClient(this);
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
WindowHeightTracker.unregisterClient(this);
}

/** @protected */
initCallback() {
if (!this.has('*blocksRegistry')) {
this.add('*blocksRegistry', new Set());
Expand All @@ -178,20 +176,41 @@ export class Block extends BaseComponent {
this.add('*localeManager', new LocaleManager(this));
}

if (!this.has('*a11y')) {
this.add('*a11y', new A11y());
}

this.sub(localeStateKey('locale-id'), (localeId) => {
this.style.direction = getLocaleDirection(localeId);
const direction = getLocaleDirection(localeId);
this.style.direction = direction === 'ltr' ? '' : direction;
});
}

/** @returns {LocaleManager | null} */
/**
* @private
* @returns {LocaleManager | null}
*/
get localeManager() {
return this.has('*localeManager') ? this.$['*localeManager'] : null;
}

/**
* @returns {A11y | null}
* @protected
*/
get a11y() {
return this.has('*a11y') ? this.$['*a11y'] : null;
}

/** @type {Set<Block>} */
get blocksRegistry() {
return this.$['*blocksRegistry'];
}

/** @protected */
destroyCallback() {
/** @type {Set<Block>} */
let blocksRegistry = this.$['*blocksRegistry'];
blocksRegistry.delete(this);
let blocksRegistry = this.blocksRegistry;
blocksRegistry?.delete(this);

this.localeManager?.destroyL10nBindings(this);
this.l10nProcessorSubs = new Map();
Expand All @@ -200,7 +219,7 @@ export class Block extends BaseComponent {
// TODO: this should be done inside symbiote
Data.deleteCtx(this);

if (blocksRegistry.size === 0) {
if (blocksRegistry?.size === 0) {
setTimeout(() => {
// Destroy global context after all blocks are destroyed and all callbacks are run
this.destroyCtxCallback();
Expand All @@ -220,25 +239,10 @@ export class Block extends BaseComponent {
}

/**
* @param {Number} bytes
* @param {Number} [decimals]
* @param {String} url
* @returns {Promise<String>}
* @protected
*/
fileSizeFmt(bytes, decimals = 2) {
let units = ['B', 'KB', 'MB', 'GB', 'TB'];
/**
* @param {String} str
* @returns {String}
*/
if (bytes === 0) {
return `0 ${units[0]}`;
}
let k = 1024;
let dm = decimals < 0 ? 0 : decimals;
let i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / k ** i).toFixed(dm)) + ' ' + units[i];
}

/** @param {string} url */
async proxyUrl(url) {
if (this.cfg.secureDeliveryProxy && this.cfg.secureDeliveryProxyUrlResolver) {
console.warn(
Expand Down
6 changes: 2 additions & 4 deletions abstract/CTX.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export const blockCtx = () => ({});
/** @param {import('./Block').Block} fnCtx */
export const activityBlockCtx = (fnCtx) => ({
...blockCtx(),
'*currentActivity': '',
'*currentActivity': null,
'*currentActivityParams': {},
'*history': [],
'*historyBack': null,
'*closeModal': () => {
fnCtx.set$({
'*currentActivity': null,
'*modalActive': false,
'*currentActivity': '',
});
},
});
Expand All @@ -24,9 +24,7 @@ export const uploaderBlockCtx = (fnCtx) => ({
'*commonProgress': 0,
'*uploadList': [],
'*focusedEntry': null,
'*uploadMetadata': null,
'*uploadQueue': new Queue(1),
'*uploadCollection': null,
/** @type {ReturnType<import('../types').OutputErrorCollection>[]} */
'*collectionErrors': [],
/** @type {import('../types').OutputCollectionState | null} */
Expand Down
8 changes: 7 additions & 1 deletion abstract/SolutionBlock.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { uploaderBlockCtx } from './CTX.js';
import svgIconsSprite from '../blocks/themes/lr-basic/svg-sprite.js';
import { Block } from './Block.js';
import { uploaderBlockCtx } from './CTX.js';

export class SolutionBlock extends Block {
static styleAttrs = ['lr-wgt-common'];
requireCtxName = true;
init$ = uploaderBlockCtx(this);
_template = null;

initCallback() {
super.initCallback();
this.a11y?.registerBlock(this);
}

static set template(value) {
this._template = svgIconsSprite + value + /** HTML */ `<slot></slot>`;
}
Expand Down
Loading

0 comments on commit f2c871e

Please sign in to comment.