Skip to content

Commit

Permalink
Deploying to gh-pages from @ c58e7a0 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Nov 14, 2023
1 parent 118d28f commit f2709cd
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 59 deletions.
14 changes: 13 additions & 1 deletion abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ActivityBlock extends Block {
if (history.length > 10) {
history = history.slice(history.length - 11, history.length - 1);
}
if (this.historyTracked) {
if (this.historyTracked && history[history.length - 1] !== this.activityType) {
history.push(this.activityType);
}
this.$['*history'] = history;
Expand All @@ -93,6 +93,10 @@ export class ActivityBlock extends Block {
return this[ACTIVE_PROP];
}

get couldOpenActivity() {
return true;
}

/**
* TODO: remove name argument
*
Expand Down Expand Up @@ -157,6 +161,14 @@ export class ActivityBlock extends Block {
while (nextActivity === this.activityType) {
nextActivity = history.pop();
}
let couldOpenActivity = !!nextActivity;
if (nextActivity) {
/** @type {Set<ActivityBlock>} */
let blocksRegistry = this.$['*blocksRegistry'];
const nextActivityBlock = [...blocksRegistry].find((block) => block.activityType === nextActivity);
couldOpenActivity = nextActivityBlock?.couldOpenActivity ?? false;
}
nextActivity = couldOpenActivity ? nextActivity : undefined;
this.$['*currentActivity'] = nextActivity;
this.$['*history'] = history;
if (!nextActivity) {
Expand Down
71 changes: 37 additions & 34 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { TypedCollection } from './TypedCollection.js';
import { uploadEntrySchema } from './uploadEntrySchema.js';

export class UploaderBlock extends ActivityBlock {
couldBeUploadCollectionOwner = false;
isUploadCollectionOwner = false;
isCtxOwner = false;

init$ = uploaderBlockCtx(this);

Expand Down Expand Up @@ -58,6 +57,15 @@ export class UploaderBlock extends ActivityBlock {
}
}

get hasCtxOwner() {
return this.hasBlockInCtx((block) => {
if (block instanceof UploaderBlock) {
return block.isCtxOwner && block.isConnected && block !== this;
}
return false;
});
}

initCallback() {
super.initCallback();

Expand All @@ -76,47 +84,42 @@ export class UploaderBlock extends ActivityBlock {
this.add('*uploadCollection', uploadCollection);
}

const hasUploadCollectionOwner = () =>
this.hasBlockInCtx((block) => {
if (block instanceof UploaderBlock) {
return block.isUploadCollectionOwner && block.isConnected && block !== this;
}
return false;
});

if (this.couldBeUploadCollectionOwner && !hasUploadCollectionOwner()) {
this.isUploadCollectionOwner = true;
if (!this.hasCtxOwner) {
this.initCtxOwner();
}
}

/** @private */
this._unobserveCollection = this.uploadCollection.observeCollection(this._handleCollectonUpdate);
destroyCallback() {
super.destroyCallback();
if (this.isCtxOwner) {
this._unobserveCollectionProperties?.();
this._unobserveCollection?.();
}
}

/** @private */
this._unobserveCollectionProperties = this.uploadCollection.observeProperties(
this._handleCollectionPropertiesUpdate
);
initCtxOwner() {
this.isCtxOwner = true;

this.subConfigValue('maxLocalFileSizeBytes', () => this._debouncedRunValidators());
this.subConfigValue('multipleMin', () => this._debouncedRunValidators());
this.subConfigValue('multipleMax', () => this._debouncedRunValidators());
this.subConfigValue('multiple', () => this._debouncedRunValidators());
this.subConfigValue('imgOnly', () => this._debouncedRunValidators());
this.subConfigValue('accept', () => this._debouncedRunValidators());
}
/** @private */
this._unobserveCollection = this.uploadCollection.observeCollection(this._handleCollectonUpdate);

if (this.__initialUploadMetadata) {
this.$['*uploadMetadata'] = this.__initialUploadMetadata;
}
/** @private */
this._unobserveCollectionProperties = this.uploadCollection.observeProperties(
this._handleCollectionPropertiesUpdate
);

this.subConfigValue('maxLocalFileSizeBytes', () => this._debouncedRunValidators());
this.subConfigValue('multipleMin', () => this._debouncedRunValidators());
this.subConfigValue('multipleMax', () => this._debouncedRunValidators());
this.subConfigValue('multiple', () => this._debouncedRunValidators());
this.subConfigValue('imgOnly', () => this._debouncedRunValidators());
this.subConfigValue('accept', () => this._debouncedRunValidators());
this.subConfigValue('maxConcurrentRequests', (value) => {
this.$['*uploadQueue'].concurrency = Number(value) || 1;
});
}

destroyCallback() {
super.destroyCallback();
if (this.isUploadCollectionOwner) {
this._unobserveCollectionProperties?.();
this._unobserveCollection?.();
if (this.__initialUploadMetadata) {
this.$['*uploadMetadata'] = this.__initialUploadMetadata;
}
}

Expand Down
4 changes: 4 additions & 0 deletions blocks/DropArea/DropArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export class DropArea extends UploaderBlock {
this.toggleAttribute('hidden', !value);
});

this.sub('isClickable', (value) => {
this.toggleAttribute('clickable', value);
});

if (this.$.isClickable) {
// @private
this._onAreaClicked = () => {
Expand Down
4 changes: 4 additions & 0 deletions blocks/DropArea/drop-area.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,7 @@ lr-drop-area[with-icon][fullscreen][drag-state='over'] > .content-wrapper {
:is(lr-drop-area[with-icon][fullscreen]) > .content-wrapper lr-icon:first-child {
transform: translateY(calc(var(--ui-size) * -1.5));
}

lr-drop-area[clickable] {
cursor: pointer;
}
13 changes: 6 additions & 7 deletions blocks/UploadList/UploadList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { debounce } from '../utils/debounce.js';
*/

export class UploadList extends UploaderBlock {
couldBeUploadCollectionOwner = true;
historyTracked = true;
activityType = ActivityBlock.activities.UPLOAD_LIST;

Expand Down Expand Up @@ -60,11 +59,7 @@ export class UploadList extends UploaderBlock {
this._updateUploadsState();
this._updateCountLimitMessage();

if (
this.$['*uploadList']?.length === 0 &&
!this.cfg.showEmptyList &&
this.$['*currentActivity'] === this.activityType
) {
if (!this.couldOpenActivity && this.$['*currentActivity'] === this.activityType) {
this.historyBack();
}
}, 0);
Expand Down Expand Up @@ -199,6 +194,10 @@ export class UploadList extends UploaderBlock {
return localizedText('total');
}

get couldOpenActivity() {
return this.cfg.showEmptyList || this.uploadCollection.size > 0;
}

initCallback() {
super.initCallback();

Expand All @@ -209,7 +208,7 @@ export class UploadList extends UploaderBlock {
this.subConfigValue('multipleMax', this._debouncedHandleCollectionUpdate);

this.sub('*currentActivity', (currentActivity) => {
if (this.uploadCollection?.size === 0 && !this.cfg.showEmptyList && currentActivity === this.activityType) {
if (!this.couldOpenActivity && currentActivity === this.activityType) {
this.$['*currentActivity'] = this.initActivity;
}
});
Expand Down
1 change: 1 addition & 0 deletions blocks/themes/lr-basic/l10n.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
--l10n-upload: 'Upload';
--l10n-add-more: 'Add more';
--l10n-cancel: 'Cancel';
--l10n-start-from-cancel: var(--l10n-cancel);
--l10n-clear: 'Clear';
--l10n-camera-shot: 'Shot';
--l10n-upload-url: 'Import';
Expand Down
27 changes: 23 additions & 4 deletions solutions/file-uploader/inline/FileUploaderInline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ export class FileUploaderInline extends SolutionBlock {

this.init$ = {
...this.init$,
couldBackHistory: false,
couldCancel: false,
cancel: () => {
if (this.couldHistoryBack) {
this.$['*historyBack']();
} else if (this.couldShowList) {
this.$['*currentActivity'] = ActivityBlock.activities.UPLOAD_LIST;
}
},
};
}

get couldHistoryBack() {
const history = this.$['*history'];
return history.length > 1 && history[history.length - 1] !== ActivityBlock.activities.START_FROM;
}

get couldShowList() {
return this.cfg.showEmptyList || this.$['*uploadList'].length > 0;
}

shadowReadyCallback() {
/** @type {import('../../../abstract/UploaderBlock.js').UploaderBlock} */
const uBlock = this.ref.uBlock;
Expand All @@ -29,7 +46,9 @@ export class FileUploaderInline extends SolutionBlock {
}
});

this.sub('*history', (history) => (this.$['couldBackHistory'] = history.length > 1));
this.sub('*history', () => {
this.$['couldCancel'] = this.couldHistoryBack || this.couldShowList;
});
}
}

Expand All @@ -38,9 +57,9 @@ FileUploaderInline.template = /* HTML */ ` <lr-start-from>
<lr-source-list wrap></lr-source-list>
<button
type="button"
l10n="cancel"
l10n="start-from-cancel"
class="cancel-btn secondary-btn"
set="onclick: *historyBack; @hidden: !couldBackHistory"
set="onclick: cancel; @hidden: !couldCancel"
></button>
<lr-copyright></lr-copyright>
</lr-start-from>
Expand Down
1 change: 0 additions & 1 deletion solutions/file-uploader/minimal/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ lr-drop-area {
text-align: center;
background-color: var(--clr-background);
border-radius: var(--border-radius-frame);
cursor: pointer;
}

lr-upload-list lr-activity-header {
Expand Down
2 changes: 1 addition & 1 deletion solutions/file-uploader/regular/FileUploaderRegular.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FileUploaderRegular.template = /* HTML */ `
<lr-start-from>
<lr-drop-area with-icon clickable></lr-drop-area>
<lr-source-list wrap></lr-source-list>
<button type="button" l10n="cancel" class="secondary-btn" set="onclick: *historyBack"></button>
<button type="button" l10n="start-from-cancel" class="secondary-btn" set="onclick: *historyBack"></button>
<lr-copyright></lr-copyright>
</lr-start-from>
<lr-upload-list></lr-upload-list>
Expand Down
4 changes: 2 additions & 2 deletions web/blocks.iife.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/blocks.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-basic.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-file-uploader-inline.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-file-uploader-inline.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-file-uploader-minimal.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/lr-file-uploader-minimal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-file-uploader-regular.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/lr-file-uploader-regular.min.js

Large diffs are not rendered by default.

0 comments on commit f2709cd

Please sign in to comment.