pollination-react-io 1.28.5 → 1.29.0
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.
|
@@ -2,4 +2,5 @@ import { PanelMessageOut } from './types';
|
|
|
2
2
|
export declare const usePollinationPanel: () => {
|
|
3
3
|
getFileBase64: (key?: any, accept?: any) => PanelMessageOut;
|
|
4
4
|
saveFileBase64: (key: string, file: File | Blob, subFolder: string, fileName: string) => Promise<PanelMessageOut>;
|
|
5
|
+
fromFileToBase64: (filePath: string) => PanelMessageOut;
|
|
5
6
|
};
|
package/build/index.esm.js
CHANGED
|
@@ -37948,9 +37948,15 @@ var usePollinationPanel = function () {
|
|
|
37948
37948
|
return;
|
|
37949
37949
|
return panel.GetArtifactAsBase64(key, accept);
|
|
37950
37950
|
}, [panel]);
|
|
37951
|
+
var fromFileToBase64 = useCallback(function (filePath) {
|
|
37952
|
+
if (!panel)
|
|
37953
|
+
return;
|
|
37954
|
+
return panel.FromFileToBase64(filePath);
|
|
37955
|
+
}, [panel]);
|
|
37951
37956
|
return {
|
|
37952
37957
|
getFileBase64: getFileBase64,
|
|
37953
|
-
saveFileBase64: saveFileBase64
|
|
37958
|
+
saveFileBase64: saveFileBase64,
|
|
37959
|
+
fromFileToBase64: fromFileToBase64
|
|
37954
37960
|
};
|
|
37955
37961
|
};
|
|
37956
37962
|
|
|
@@ -44249,7 +44255,11 @@ var RecipeInputsForm = function (_a) {
|
|
|
44249
44255
|
var inputProps = __assign({}, register(input.name, {
|
|
44250
44256
|
valueAsNumber: ['DAGIntegerInput', 'DAGNumberInput'].includes(input.type)
|
|
44251
44257
|
}));
|
|
44252
|
-
var handleReset = function () {
|
|
44258
|
+
var handleReset = function () {
|
|
44259
|
+
resetField(input.name, {
|
|
44260
|
+
defaultValue: defaultValue
|
|
44261
|
+
});
|
|
44262
|
+
};
|
|
44253
44263
|
return (React__default.createElement(FormInput, { key: "".concat(input.name, "-").concat(i), name: input.name, description: input.description, hidden: hidden, errorMessage: !input.required && errors[input.name] ? (_a = errors[input.name]) === null || _a === void 0 ? void 0 : _a.message : undefined }, (function () {
|
|
44254
44264
|
var _a;
|
|
44255
44265
|
switch (input.type) {
|
|
@@ -44293,9 +44303,11 @@ var RecipeInputsForm = function (_a) {
|
|
|
44293
44303
|
var key = _a[0], val = _a[1];
|
|
44294
44304
|
return (
|
|
44295
44305
|
// @ts-ignore
|
|
44296
|
-
val.type !== 'required'
|
|
44306
|
+
val.type !== 'required'
|
|
44307
|
+
? React__default.createElement("li", { key: key, style: { color: 'red', fontSize: '0.8rem', listStyle: 'none' } }, "".concat(key, " ").concat(val.message, "."))
|
|
44308
|
+
: React__default.createElement("li", { key: key, style: { color: 'red', fontSize: '0.8rem', listStyle: 'none' } }, "".concat(key, " is missing.")));
|
|
44297
44309
|
}))) :
|
|
44298
|
-
isSubmitSuccessful ? 'Study has been successfully submitted.' :
|
|
44310
|
+
isSubmitSuccessful ? 'Study has been successfully submitted.' : null },
|
|
44299
44311
|
React__default.createElement(Button, { type: 'submit', form: recipe.metadata.name, disabled: !isValid || loading, style: {
|
|
44300
44312
|
width: 'fit-content',
|
|
44301
44313
|
}, loading: loading }, "Create Study"))))));
|
|
@@ -47158,8 +47170,11 @@ var jszip_min = createCommonjsModule(function (module, exports) {
|
|
|
47158
47170
|
var shortDebounce = useDebounce(200);
|
|
47159
47171
|
var ICON_SIZE = 18;
|
|
47160
47172
|
var FilePreview = function (_a) {
|
|
47161
|
-
var projectOwner = _a.projectOwner, projectName = _a.projectName, jobId = _a.jobId, value = _a.value,
|
|
47173
|
+
var projectOwner = _a.projectOwner, projectName = _a.projectName, jobId = _a.jobId, value = _a.value, // cloud controller
|
|
47174
|
+
client = _a.client, inputProps = _a.inputProps, onPreviewChange = _a.onPreviewChange, // Use it for streamlit setComponentValue
|
|
47175
|
+
enableFilePicker = _a.enableFilePicker, localPath = _a.localPath // local controller
|
|
47162
47176
|
;
|
|
47177
|
+
var fromFileToBase64 = usePollinationPanel().fromFileToBase64;
|
|
47163
47178
|
var getExtension = function (fileName) {
|
|
47164
47179
|
if (!fileName)
|
|
47165
47180
|
return;
|
|
@@ -47168,13 +47183,14 @@ var FilePreview = function (_a) {
|
|
|
47168
47183
|
return arr.at(arr.length - 1);
|
|
47169
47184
|
}
|
|
47170
47185
|
};
|
|
47186
|
+
var host = getHost();
|
|
47171
47187
|
var _b = useState(value), selArtifact = _b[0], setSelArtifact = _b[1];
|
|
47188
|
+
var _c = useState(localPath), selFilePath = _c[0], setSelFilePath = _c[1];
|
|
47172
47189
|
var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
|
|
47173
|
-
var
|
|
47174
|
-
var
|
|
47175
|
-
var
|
|
47190
|
+
var _d = useState(), preview = _d[0], setPreview = _d[1];
|
|
47191
|
+
var _e = useState(), currBlob = _e[0], setCurrBlob = _e[1];
|
|
47192
|
+
var _f = useState(getExtension((value === null || value === void 0 ? void 0 : value.file_name) || getExtension(localPath))), currFileExtension = _f[0], setCurrFileExtension = _f[1];
|
|
47176
47193
|
var allowedFileTypes = ['application/zip', 'text/plain'];
|
|
47177
|
-
var host = getHost();
|
|
47178
47194
|
var parser = {
|
|
47179
47195
|
'text/plain': function (blob) {
|
|
47180
47196
|
var reader = new FileReader();
|
|
@@ -47214,13 +47230,70 @@ var FilePreview = function (_a) {
|
|
|
47214
47230
|
}); });
|
|
47215
47231
|
}
|
|
47216
47232
|
};
|
|
47217
|
-
// Internal onChange
|
|
47233
|
+
// Internal onChange cloud
|
|
47218
47234
|
var onChange = useCallback(function (selArtifact) {
|
|
47219
|
-
// console.log(selArtifact)
|
|
47220
47235
|
setSelArtifact(selArtifact);
|
|
47221
47236
|
!selArtifact && setPreview(undefined);
|
|
47222
47237
|
!selArtifact && setCurrFileExtension(undefined);
|
|
47223
47238
|
}, []);
|
|
47239
|
+
// Internal onChange local
|
|
47240
|
+
var onChangeLocal = useCallback(function (path) {
|
|
47241
|
+
setSelFilePath(path);
|
|
47242
|
+
!selFilePath && setPreview(undefined);
|
|
47243
|
+
!selFilePath && setCurrFileExtension(undefined);
|
|
47244
|
+
}, []);
|
|
47245
|
+
var base64AndFetch = function (path) {
|
|
47246
|
+
if (!path)
|
|
47247
|
+
return;
|
|
47248
|
+
var data = fromFileToBase64(path);
|
|
47249
|
+
var base64Data = data === null || data === void 0 ? void 0 : data.data;
|
|
47250
|
+
if (!base64Data)
|
|
47251
|
+
return;
|
|
47252
|
+
// bas64 mapping
|
|
47253
|
+
var t;
|
|
47254
|
+
switch (getExtension(path)) {
|
|
47255
|
+
case 'zip':
|
|
47256
|
+
t = 'application/zip';
|
|
47257
|
+
break;
|
|
47258
|
+
case 'vsf':
|
|
47259
|
+
t = 'text/plain';
|
|
47260
|
+
}
|
|
47261
|
+
fetchAndSet("data:".concat(t, ";base64,").concat(base64Data), path);
|
|
47262
|
+
};
|
|
47263
|
+
var fetchAndSet = function (url, path) {
|
|
47264
|
+
if (path === void 0) { path = undefined; }
|
|
47265
|
+
fetch(url)
|
|
47266
|
+
.then(function (response) { return response.blob()
|
|
47267
|
+
.then(function (blob) {
|
|
47268
|
+
var t = blob.type;
|
|
47269
|
+
if (!allowedFileTypes.includes(t)) {
|
|
47270
|
+
console.error("Cloud Artifact ".concat(t, " not supported."));
|
|
47271
|
+
setPreview(undefined);
|
|
47272
|
+
setCurrBlob(undefined);
|
|
47273
|
+
setCurrFileExtension(undefined);
|
|
47274
|
+
return;
|
|
47275
|
+
}
|
|
47276
|
+
switch (t) {
|
|
47277
|
+
case 'application/zip':
|
|
47278
|
+
parser['application/zip'](blob);
|
|
47279
|
+
break;
|
|
47280
|
+
case 'text/plain':
|
|
47281
|
+
parser['text/plain'](blob);
|
|
47282
|
+
break;
|
|
47283
|
+
default:
|
|
47284
|
+
setPreview(undefined);
|
|
47285
|
+
setCurrBlob(undefined);
|
|
47286
|
+
setCurrFileExtension(undefined);
|
|
47287
|
+
break;
|
|
47288
|
+
}
|
|
47289
|
+
setCurrBlob(blob);
|
|
47290
|
+
if (path) {
|
|
47291
|
+
setSelFilePath(path);
|
|
47292
|
+
}
|
|
47293
|
+
var ext = getExtension((selArtifact === null || selArtifact === void 0 ? void 0 : selArtifact.file_name) || path);
|
|
47294
|
+
setCurrFileExtension(ext);
|
|
47295
|
+
}); });
|
|
47296
|
+
};
|
|
47224
47297
|
var download = function (blob, fileName) {
|
|
47225
47298
|
var file = new File([blob], fileName);
|
|
47226
47299
|
var a = document.createElement('a');
|
|
@@ -47233,54 +47306,31 @@ var FilePreview = function (_a) {
|
|
|
47233
47306
|
a.click();
|
|
47234
47307
|
};
|
|
47235
47308
|
useEffect(function () {
|
|
47309
|
+
if (enableFilePicker) {
|
|
47310
|
+
base64AndFetch(selFilePath);
|
|
47311
|
+
return;
|
|
47312
|
+
}
|
|
47236
47313
|
downloadArtifact(selArtifact === null || selArtifact === void 0 ? void 0 : selArtifact.key, jobId)
|
|
47237
|
-
.then(
|
|
47238
|
-
|
|
47239
|
-
.then(function (response) { return response.blob()
|
|
47240
|
-
.then(function (blob) {
|
|
47241
|
-
var t = blob.type;
|
|
47242
|
-
if (!allowedFileTypes.includes(t)) {
|
|
47243
|
-
console.error("Cloud Artifact ".concat(t, " not supported."));
|
|
47244
|
-
setPreview(undefined);
|
|
47245
|
-
setCurrBlob(undefined);
|
|
47246
|
-
setCurrFileExtension(undefined);
|
|
47247
|
-
return;
|
|
47248
|
-
}
|
|
47249
|
-
switch (t) {
|
|
47250
|
-
case 'application/zip':
|
|
47251
|
-
parser['application/zip'](blob);
|
|
47252
|
-
break;
|
|
47253
|
-
case 'text/plain':
|
|
47254
|
-
parser['text/plain'](blob);
|
|
47255
|
-
break;
|
|
47256
|
-
default:
|
|
47257
|
-
setPreview(undefined);
|
|
47258
|
-
setCurrBlob(undefined);
|
|
47259
|
-
setCurrFileExtension(undefined);
|
|
47260
|
-
break;
|
|
47261
|
-
}
|
|
47262
|
-
setCurrBlob(blob);
|
|
47263
|
-
var ext = getExtension(selArtifact === null || selArtifact === void 0 ? void 0 : selArtifact.file_name);
|
|
47264
|
-
setCurrFileExtension(ext);
|
|
47265
|
-
}); });
|
|
47266
|
-
});
|
|
47267
|
-
}, [selArtifact, projectOwner, projectName]);
|
|
47314
|
+
.then(fetchAndSet);
|
|
47315
|
+
}, [selArtifact, selFilePath, projectOwner, projectName]);
|
|
47268
47316
|
shortDebounce(function () {
|
|
47269
47317
|
onPreviewChange && onPreviewChange(preview);
|
|
47270
47318
|
}, [onPreviewChange, preview]);
|
|
47271
|
-
// TODO: Add buttons latest part (e.g. download)
|
|
47272
47319
|
return (React__default.createElement(React__default.Fragment, null,
|
|
47273
|
-
!value && React__default.createElement(SelectCloudArtifacts, { projectOwner: projectOwner, projectName: projectName, value: selArtifact, hidden: false, client: client, jobId: jobId, fileNameMatch: typeof inputProps.accept === 'string'
|
|
47320
|
+
!value && !enableFilePicker && React__default.createElement(SelectCloudArtifacts, { projectOwner: projectOwner, projectName: projectName, value: selArtifact, hidden: false, client: client, jobId: jobId, fileNameMatch: typeof inputProps.accept === 'string'
|
|
47274
47321
|
? ".*(".concat(inputProps.accept.replace(/\./g, '').split(', ').join('$|'), "$)")
|
|
47275
47322
|
: undefined, onChange: onChange }),
|
|
47276
|
-
|
|
47323
|
+
!localPath && enableFilePicker && React__default.createElement(SelectLocalArtifactNative, { onChange: onChangeLocal, value: selFilePath, buttonLabel: "Select ".concat(inputProps.accept.split(',').length > 1 ?
|
|
47324
|
+
'any of' : 'an', " ").concat(inputProps.accept, " ").concat(inputProps.accept.split(',').length > 1 ? 'file types' : 'file', "."), fileMatchPattern: "File types ".concat(inputProps.accept, "|*").concat(inputProps.accept.split(', ').join(';*')) }),
|
|
47325
|
+
(selArtifact || selFilePath) && //
|
|
47277
47326
|
React__default.createElement(React__default.Fragment, null,
|
|
47327
|
+
(value || localPath) ? undefined : React__default.createElement("br", null),
|
|
47278
47328
|
(host !== 'web' && currFileExtension === 'vsf'
|
|
47279
47329
|
&& typeof preview === 'string') &&
|
|
47280
|
-
React__default.createElement(SendResults, { results: JSON.parse(preview), defaultKey: selArtifact.file_name, buttonLabel: 'Result Preview' }),
|
|
47330
|
+
React__default.createElement(SendResults, { results: JSON.parse(preview), defaultKey: (selArtifact === null || selArtifact === void 0 ? void 0 : selArtifact.file_name) || (selFilePath === null || selFilePath === void 0 ? void 0 : selFilePath.replace(/^.*[\\\/]/, '')), buttonLabel: 'Result Preview' }),
|
|
47281
47331
|
(host !== 'web' && currFileExtension === 'zip') &&
|
|
47282
47332
|
preview && typeof preview === 'string' &&
|
|
47283
|
-
React__default.createElement(SendResults, { results: JSON.parse(preview), defaultKey: selArtifact.file_name, buttonLabel: 'Result Preview' }),
|
|
47333
|
+
React__default.createElement(SendResults, { results: JSON.parse(preview), defaultKey: (selArtifact === null || selArtifact === void 0 ? void 0 : selArtifact.file_name) || (selFilePath === null || selFilePath === void 0 ? void 0 : selFilePath.replace(/^.*[\\\/]/, '')), buttonLabel: 'Result Preview' }),
|
|
47284
47334
|
(host === 'web') &&
|
|
47285
47335
|
React__default.createElement(Button, { type: 'button', onClick: function () { return download(currBlob, selArtifact.file_name); }, disabled: !currBlob, style: {
|
|
47286
47336
|
width: 'fit-content',
|