Skip to content

Commit

Permalink
feat: added export UploadSource, ExternalUploadSource
Browse files Browse the repository at this point in the history
  • Loading branch information
egordidenko committed Sep 2, 2024
1 parent 75ad4de commit e13e3b8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
16 changes: 8 additions & 8 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,12 @@ export class UploaderBlock extends ActivityBlock {
const data = entriesIds.map((itemId) => this.api.getOutputItem(itemId));
return data;
}

getList() {
return UploaderBlock.sourceTypes;
}
}

/** @enum {String} */
/**
* @deprecated Use list sources ExternalUploadSource from from blocks/utils/UploadSource.js
* @enum {String}
*/
UploaderBlock.extSrcList = Object.freeze({
FACEBOOK: 'facebook',
DROPBOX: 'dropbox',
Expand All @@ -440,13 +439,14 @@ UploaderBlock.extSrcList = Object.freeze({
HUDDLE: 'huddle',
});

/** @enum {String} */
/**
* @deprecated Use list sources UploadSource from from blocks/utils/UploadSource.js
* @enum {String}
*/
UploaderBlock.sourceTypes = Object.freeze({
LOCAL: 'local',
URL: 'url',
CAMERA: 'camera',
DRAW: 'draw',
...UploaderBlock.extSrcList,
});

/** @typedef {(typeof UploaderBlock)['sourceTypes']} SourceTypes */
5 changes: 0 additions & 5 deletions abstract/UploaderPublicApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,6 @@ export class UploaderPublicApi {
return this._ctx.$['*currentActivity'];
};

/** @returns {Readonly<import('./UploaderBlock.js').SourceTypes>} */
getSourceTypes = () => {
return this._ctx.getList();
};

/** @param {boolean} opened */
setModalState = (opened) => {
if (opened && !this._ctx.$['*currentActivity']) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/DropArea/DropArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class DropArea extends UploaderBlock {
this.subConfigValue('sourceList', (value) => {
const list = stringToArray(value);
// Enable drop area if local files are allowed
this.$.isEnabled = list.includes(UploaderBlock.sourceTypes.LOCAL);
this.$.isEnabled = list.includes(UploadSource.LOCAL);
// Show drop area if it's enabled or default slot is overrided
this.$.isVisible = this.$.isEnabled || !this.querySelector('[data-default-slot]');
});
Expand Down
9 changes: 5 additions & 4 deletions blocks/SourceBtn/SourceBtn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { UploaderBlock } from '../../abstract/UploaderBlock.js';
import { ActivityBlock } from '../../abstract/ActivityBlock.js';
import { ExternalUploadSource, UploadSource } from '../utils/UploadSource.js';

const L10N_PREFIX = 'src-type-';

Expand Down Expand Up @@ -37,19 +38,19 @@ export class SourceBtn extends UploaderBlock {

initTypes() {
this.registerType({
type: UploaderBlock.sourceTypes.LOCAL,
type: UploadSource.LOCAL,
activate: () => {
this.api.openSystemDialog();
return false;
},
});
this.registerType({
type: UploaderBlock.sourceTypes.URL,
type: UploadSource.URL,
activity: ActivityBlock.activities.URL,
textKey: 'from-url',
});
this.registerType({
type: UploaderBlock.sourceTypes.CAMERA,
type: UploadSource.CAMERA,
activity: ActivityBlock.activities.CAMERA,
activate: () => {
const supportsCapture = 'capture' in document.createElement('input');
Expand All @@ -65,7 +66,7 @@ export class SourceBtn extends UploaderBlock {
icon: 'edit-draw',
});

for (let externalSourceType of Object.values(UploaderBlock.extSrcList)) {
for (let externalSourceType of Object.values(ExternalUploadSource)) {
this.registerType({
type: externalSourceType,
activity: ActivityBlock.activities.EXTERNAL,
Expand Down
2 changes: 1 addition & 1 deletion blocks/UrlSource/UrlSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class UrlSource extends UploaderBlock {
e.preventDefault();

let url = this.ref.input['value'];
this.api.addFileFromUrl(url, { source: UploadSource.URL_TAB });
this.api.addFileFromUrl(url, { source: UploadSource.URL });
this.$['*currentActivity'] = ActivityBlock.activities.UPLOAD_LIST;
},
onCancel: () => {
Expand Down
21 changes: 20 additions & 1 deletion blocks/utils/UploadSource.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
// @ts-check
export const ExternalUploadSource = Object.freeze({
FACEBOOK: 'facebook',
DROPBOX: 'dropbox',
GDRIVE: 'gdrive',
GPHOTOS: 'gphotos',
INSTAGRAM: 'instagram',
FLICKR: 'flickr',
VK: 'vk',
EVERNOTE: 'evernote',
BOX: 'box',
ONEDRIVE: 'onedrive',
HUDDLE: 'huddle',
});

export const UploadSource = Object.freeze({
LOCAL: 'local',
DROP_AREA: 'drop-area',
URL_TAB: 'url-tab',
CAMERA: 'camera',
EXTERNAL: 'external',
API: 'js-api',
URL: 'url',
DRAW: 'draw',
...ExternalUploadSource,
});

/** @typedef {typeof UploadSource} SourceTypes */
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export { defineComponents } from './abstract/defineComponents.js';
export { defineLocale } from './abstract/localeRegistry.js';
export { loadFileUploaderFrom } from './abstract/loadFileUploaderFrom.js';
export { toKebabCase } from './utils/toKebabCase.js';
export { UploadSource, ExternalUploadSource } from './blocks/utils/UploadSource.js';

export * from './env.js';

Expand Down

0 comments on commit e13e3b8

Please sign in to comment.