@lowdefy/blocks-files 0.0.0-experimental-20260707082859
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +40 -0
- package/dist/blocks/Download/Download.js +74 -0
- package/dist/blocks/Download/meta.js +82 -0
- package/dist/blocks/Upload/Upload.js +111 -0
- package/dist/blocks/Upload/meta.js +193 -0
- package/dist/blocks/UploadDragger/UploadDragger.js +124 -0
- package/dist/blocks/UploadDragger/meta.js +142 -0
- package/dist/blocks/UploadDragger/style.module.css +30 -0
- package/dist/blocks/UploadPhoto/UploadPhoto.js +126 -0
- package/dist/blocks/UploadPhoto/meta.js +136 -0
- package/dist/blocks/utils/getEmitFileContent.js +47 -0
- package/dist/blocks/utils/getOnPaste.js +48 -0
- package/dist/blocks/utils/getUploadRequest.js +59 -0
- package/dist/blocks/utils/useFileList.js +140 -0
- package/dist/blocks.js +18 -0
- package/dist/metas.js +18 -0
- package/dist/schemas/uploadTheme.js +53 -0
- package/dist/types.js +19 -0
- package/dist/utils/getLegacyObjectUrl.js +31 -0
- package/dist/utils/getUploadPolicy.js +37 -0
- package/dist/utils/readFileAsBase64.js +28 -0
- package/dist/utils/uploadFile.js +65 -0
- package/dist/withTheme.js +40 -0
- package/package.json +70 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { ServiceError } from '@lowdefy/errors';
|
|
16
|
+
// Uploads a file to the target described by an upload-policy descriptor:
|
|
17
|
+
// { method, url, key, bucket, fields | headers }.
|
|
18
|
+
// - method 'POST' (default): multipart form upload — append the policy fields,
|
|
19
|
+
// then the file (S3, R2, MinIO, GCS POST policy).
|
|
20
|
+
// - method 'PUT': the signed url already targets the object — set headers and
|
|
21
|
+
// send the file as the raw request body (Azure SAS, presigned PUT).
|
|
22
|
+
// Object identity (key/bucket) is read from the descriptor top level by
|
|
23
|
+
// callers, never from fields — the PUT branch has no fields object.
|
|
24
|
+
function uploadFile({ descriptor, file, onProgress = ()=>null }) {
|
|
25
|
+
const { method = 'POST', url, fields = {}, headers = {} } = descriptor;
|
|
26
|
+
return new Promise((resolve, reject)=>{
|
|
27
|
+
const xhr = new XMLHttpRequest();
|
|
28
|
+
xhr.upload.onprogress = async (event)=>{
|
|
29
|
+
if (event.lengthComputable) {
|
|
30
|
+
await onProgress(event);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
xhr.addEventListener('load', ()=>{
|
|
34
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
35
|
+
resolve();
|
|
36
|
+
} else {
|
|
37
|
+
reject(new Error(`File upload failed with status ${xhr.status}.`));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
xhr.addEventListener('error', ()=>{
|
|
41
|
+
reject(new ServiceError(`File upload failed for "${file.name}" — CORS or network error. ` + `Check that the storage bucket CORS configuration allows requests from this origin.`, {
|
|
42
|
+
service: 'FileStorage'
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
xhr.addEventListener('abort', ()=>{
|
|
46
|
+
reject(new Error(`File upload aborted for "${file.name}".`));
|
|
47
|
+
});
|
|
48
|
+
if (method.toUpperCase() === 'PUT') {
|
|
49
|
+
xhr.open('put', url);
|
|
50
|
+
Object.keys(headers).forEach((header)=>{
|
|
51
|
+
xhr.setRequestHeader(header, headers[header]);
|
|
52
|
+
});
|
|
53
|
+
xhr.send(file);
|
|
54
|
+
} else {
|
|
55
|
+
const formData = new FormData();
|
|
56
|
+
Object.keys(fields).forEach((field)=>{
|
|
57
|
+
formData.append(field, fields[field]);
|
|
58
|
+
});
|
|
59
|
+
formData.append('file', file);
|
|
60
|
+
xhr.open('post', url);
|
|
61
|
+
xhr.send(formData);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export default uploadFile;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import React from 'react';
|
|
16
|
+
import { ConfigProvider } from 'antd';
|
|
17
|
+
import { type } from '@lowdefy/helpers';
|
|
18
|
+
function withTheme(antdComponentName, BlockComponent) {
|
|
19
|
+
const Wrapped = (props)=>{
|
|
20
|
+
const { theme, ...restProperties } = props.properties;
|
|
21
|
+
// Only intercept object themes (design tokens for ConfigProvider).
|
|
22
|
+
// String themes (e.g. Menu's 'dark'/'light') pass through to the component.
|
|
23
|
+
if (!type.isObject(theme)) {
|
|
24
|
+
return /*#__PURE__*/ React.createElement(BlockComponent, props);
|
|
25
|
+
}
|
|
26
|
+
return /*#__PURE__*/ React.createElement(ConfigProvider, {
|
|
27
|
+
theme: {
|
|
28
|
+
components: {
|
|
29
|
+
[antdComponentName]: theme
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/ React.createElement(BlockComponent, {
|
|
33
|
+
...props,
|
|
34
|
+
properties: restProperties
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
Wrapped.displayName = BlockComponent.displayName || BlockComponent.name;
|
|
38
|
+
return Wrapped;
|
|
39
|
+
}
|
|
40
|
+
export default withTheme;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lowdefy/blocks-files",
|
|
3
|
+
"version": "0.0.0-experimental-20260707082859",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Lowdefy provider-neutral file upload and download blocks.",
|
|
6
|
+
"homepage": "https://lowdefy.com",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"lowdefy",
|
|
9
|
+
"lowdefy blocks",
|
|
10
|
+
"file upload",
|
|
11
|
+
"file download",
|
|
12
|
+
"lowdefy plugin"
|
|
13
|
+
],
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/lowdefy/lowdefy/issues"
|
|
16
|
+
},
|
|
17
|
+
"contributors": [
|
|
18
|
+
{
|
|
19
|
+
"name": "Sam Tolmay",
|
|
20
|
+
"url": "https://github.com/SamTolmay"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Gerrie van Wyk",
|
|
24
|
+
"url": "https://github.com/Gervwyk"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
"./*": "./dist/*",
|
|
34
|
+
"./blocks": "./dist/blocks.js",
|
|
35
|
+
"./metas": "./dist/metas.js",
|
|
36
|
+
"./types": "./dist/types.js"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/*"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@lowdefy/block-utils": "0.0.0-experimental-20260707082859",
|
|
43
|
+
"@lowdefy/blocks-antd": "0.0.0-experimental-20260707082859",
|
|
44
|
+
"@lowdefy/errors": "0.0.0-experimental-20260707082859",
|
|
45
|
+
"@lowdefy/helpers": "0.0.0-experimental-20260707082859"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"antd": ">=6",
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"react-dom": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@lowdefy/block-dev-e2e": "0.0.0-experimental-20260707082859",
|
|
54
|
+
"@lowdefy/e2e-utils": "0.0.0-experimental-20260707082859",
|
|
55
|
+
"@playwright/test": "1.59.1",
|
|
56
|
+
"@swc/cli": "0.8.1",
|
|
57
|
+
"@swc/core": "1.15.32",
|
|
58
|
+
"copyfiles": "2.4.1"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --cli-config-file ../../../../.swc-cli.json && pnpm copyfiles",
|
|
65
|
+
"clean": "rm -rf dist",
|
|
66
|
+
"copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
|
|
67
|
+
"e2e": "playwright test --config e2e/playwright.config.js",
|
|
68
|
+
"e2e:ui": "playwright test --config e2e/playwright.config.js --ui"
|
|
69
|
+
}
|
|
70
|
+
}
|