I made it this far:
component.json
{
"id": "c_d1e83236ff73c1fdd7223f359a0ce9e7",
"name": "ResizeAndUpload",
"description": "",
"showInToolbox": true,
"faIcon": "pencil-ruler",
"type": "custom",
"category": "Custom Components",
"properties": [
{
"label": "Max Width",
"name": "maxWidth",
"type": "number",
"defaultValue": "100",
"handlerId": "maxWidth"
},
{
"name": "maxHeight",
"label": "Max Height",
"type": "number",
"defaultValue": "100",
"handlerId": "maxHeight"
},
{
"name": "directory",
"label": "Directory",
"type": "text",
"handlerId": "directory"
},
{
"name": "buttonLabel",
"label": "Button Label",
"type": "text",
"defaultValue": "File Upload",
"handlerId": "buttonLabel"
},
{
"name": "accept",
"label": "Accept",
"type": "text",
"defaultValue": "image/*",
"handlerId": "accept"
},
{
"name": "overwriteFiles",
"label": "Overwrite Files",
"type": "checkbox",
"handlerId": "overwriteFiles"
},
{
"name": "backgroundColor",
"handlerId": "backgroundColor",
"label": "Background Color",
"type": "text",
"defaultValue": "#FFFFFF"
},
{
"name": "color",
"label": "Color",
"handlerId": "color",
"type": "text",
"defaultValue": "#000000"
}
],
"eventHandlers": [
{
"name": "onBeforeUpload",
"label": "on Before Upload",
"contextBlocks": [
{
"id": "files",
"label": "Files"
}
]
},
{
"name": "onUploadSuccess",
"label": "on Upload Success",
"contextBlocks": [
{
"id": "uploadedFiles",
"label": "Uploaded Files"
}
]
},
{
"name": "onUploadFail",
"label": "on Upload Failed",
"contextBlocks": [
{
"id": "error",
"label": "Error"
}
]
},
{
"name": "onFileNameAssignment",
"label": "File Name Logic",
"contextBlocks": []
},
{
"name": "onButtonLabelAssignment",
"label": "Button Label Logic"
}
],
"actions": [
{
"id": "Reset",
"hasReturn": false,
"inputs": [],
"label": "resize & upload"
}
]
}
bundle.js
define([
'https://cdnjs.cloudflare.com/ajax/libs/compressorjs/1.1.1/compressor.min.js'
], (Compressor) => {
const customHTML = '<label for="myfile">Select a file:</label><input type="file" id="myfile" name="myfile" accept="">'
function compress(e) {
const file = e.target.files[0]
if (!file) {
return
}
new Compressor(file, {
maxWidth: maxWidth,
maxHeight: maxHeight,
success(result) {
Backendless.Files.upload(result, directory, overwriteFiles)
},
error(err) {
console.log(err.message)
},
})
}
return function CustomComponent({ component }) {
const elRef = React.useRef(null)
React.useEffect(() => {
const $el = elRef.current
$el.innerHTML = customHTML
const $input = $el.querySelector('input')
$input.addEventListener('change', compress, false)
}, [])
return React.createElement('div', {
className: 'my-custom-component-container',
ref: elRef,
})
}
});
But now I don’t get how I can really link the values I can set in the properties and the variables in the bundle.js.
At least when things are hardcoded, it runs fine, which is already a huge step forward.
And I would also need to see where the various handlers I defined can be effectively fired. I used the same names as those used in the app’s main.js, for example onFileNameAssignment, onUploadSuccess or onBeforeUpload, but they don’t seem to run.
In case you need to look into it, my app id is D7075715-5086-625A-FFAB-39C2F40FB200 and I made a page with this logic called test-page
.