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 ff6647a
Show file tree
Hide file tree
Showing 7 changed files with 88 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
53 changes: 53 additions & 0 deletions blocks/EditorFilerobotImage/EditorFilerobotImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { uploadFile } from '@uploadcare/upload-client';

Check warning on line 1 in blocks/EditorFilerobotImage/EditorFilerobotImage.js

View workflow job for this annotation

GitHub Actions / build

'uploadFile' is defined but never used
import { ActivityBlock } from '../../abstract/ActivityBlock.js';
import { UploaderBlock } from '../../abstract/UploaderBlock.js';
import FilerobotImageEditor from 'filerobot-image-editor';

Check warning on line 4 in blocks/EditorFilerobotImage/EditorFilerobotImage.js

View workflow job for this annotation

GitHub Actions / build

'FilerobotImageEditor' is defined but never used

export class EditorFilerobotImage extends UploaderBlock {
couldBeCtxOwner = true;
activityType = ActivityBlock.activities.EDITOR_FILEROBOT_IMAGE;
static styleAttrs = ['uc-editor-filerobot-image'];

get activityParams() {
const params = super.activityParams;
if ('internalId' in params) {
return params;
}
throw new Error(`Cloud Image Editor activity params not found`);
}

initCallback() {
super.initCallback();

this.registerActivity(this.activityType, {
onActivate: () => this.mounted(),
onDeactivate: () => this.unmounted(),
});

console.log('EditorFilerobotImage');
}

mounted() {
const { internalId } = this.activityParams;
this._entry = this.uploadCollection.read(internalId);

if (!this._entry) {
throw new Error(`Entry with internalId "${internalId}" not found`);
}

const file = this._entry.getValue('file');

Check warning on line 38 in blocks/EditorFilerobotImage/EditorFilerobotImage.js

View workflow job for this annotation

GitHub Actions / build

'file' is assigned a value but never used
const cdnUrl = this._entry.getValue('cdnUrl');

Check warning on line 39 in blocks/EditorFilerobotImage/EditorFilerobotImage.js

View workflow job for this annotation

GitHub Actions / build

'cdnUrl' is assigned a value but never used

const instance = null;

this._instance = instance;
}

unmounted() {
this._instance = undefined;
this._entry = undefined;
this.innerHTML = '';
}
}

EditorFilerobotImage.template = ``;
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 */

0 comments on commit ff6647a

Please sign in to comment.