pollination-react-io 1.77.4 → 1.78.1

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/build/index.js CHANGED
@@ -40868,6 +40868,13 @@ var useRuns = function (client) {
40868
40868
  return dayjs_min.duration(dayjs_min().utc()
40869
40869
  .diff(dayjs_min(status.started_at).utc())); // if cloudjob -> utc(true)
40870
40870
  };
40871
+ var getTrigger = function (item) {
40872
+ var _a;
40873
+ if (!((_a = item === null || item === void 0 ? void 0 : item.status) === null || _a === void 0 ? void 0 : _a.finished_at))
40874
+ return;
40875
+ var days = dayjs_min().diff(item.status.finished_at, 'days');
40876
+ return days >= 14;
40877
+ };
40871
40878
  var listRuns = React.useCallback(function (projectOwner, projectName, jobId, page, perPage, statusFilter) {
40872
40879
  if (!client || !client.runs)
40873
40880
  return;
@@ -40914,6 +40921,7 @@ var useRuns = function (client) {
40914
40921
  statusMap: statusMap,
40915
40922
  getSummaryColor: getSummaryColor,
40916
40923
  getDuration: getDuration,
40924
+ getTrigger: getTrigger
40917
40925
  };
40918
40926
  };
40919
40927
 
@@ -54879,6 +54887,19 @@ var FileUnknownFilled = function FileUnknownFilled(props, ref) {
54879
54887
  FileUnknownFilled.displayName = 'FileUnknownFilled';
54880
54888
  var FileUnknownFilled$1 = /*#__PURE__*/React__namespace.forwardRef(FileUnknownFilled);
54881
54889
 
54890
+ // This icon file is generated automatically.
54891
+ var FileZipFilled$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M854.6 288.7c6 6 9.4 14.1 9.4 22.6V928c0 17.7-14.3 32-32 32H192c-17.7 0-32-14.3-32-32V96c0-17.7 14.3-32 32-32h424.7c8.5 0 16.7 3.4 22.7 9.4l215.2 215.3zM790.2 326L602 137.8V326h188.2zM296 136v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm64 64v64h64v-64h-64zm-64 64v64h64v-64h-64zm0 64v160h128V584H296zm48 48h32v64h-32v-64z" } }] }, "name": "file-zip", "theme": "filled" };
54892
+ var FileZipFilledSvg = FileZipFilled$2;
54893
+
54894
+ var FileZipFilled = function FileZipFilled(props, ref) {
54895
+ return /*#__PURE__*/React__namespace.createElement(AntdIcon, _objectSpread2$1(_objectSpread2$1({}, props), {}, {
54896
+ ref: ref,
54897
+ icon: FileZipFilledSvg
54898
+ }));
54899
+ };
54900
+ FileZipFilled.displayName = 'FileZipFilled';
54901
+ var FileZipFilled$1 = /*#__PURE__*/React__namespace.forwardRef(FileZipFilled);
54902
+
54882
54903
  // This icon file is generated automatically.
54883
54904
  var FolderFilled$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M880 298.4H521L403.7 186.2a8.15 8.15 0 00-5.5-2.2H144c-17.7 0-32 14.3-32 32v592c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V330.4c0-17.7-14.3-32-32-32z" } }] }, "name": "folder", "theme": "filled" };
54884
54905
  var FolderFilledSvg = FolderFilled$2;
@@ -55970,6 +55991,8 @@ var getFileIcon = function (size, type) {
55970
55991
  case 'svg':
55971
55992
  case 'hdr':
55972
55993
  return React__default["default"].createElement(FileImageFilled$1, { style: { fontSize: size, color: '#862E9C' } });
55994
+ case 'zip':
55995
+ return React__default["default"].createElement(FileZipFilled$1, { style: { fontSize: size, color: '#f2b24d' } });
55973
55996
  default:
55974
55997
  return React__default["default"].createElement(FileUnknownFilled$1, { style: { fontSize: size } });
55975
55998
  }
@@ -55980,6 +56003,11 @@ var CADtypeEnum;
55980
56003
  CADtypeEnum[CADtypeEnum["HBJSON"] = 0] = "HBJSON";
55981
56004
  CADtypeEnum[CADtypeEnum["VSF"] = 1] = "VSF";
55982
56005
  })(CADtypeEnum || (CADtypeEnum = {}));
56006
+ /**
56007
+ * Download a file
56008
+ * @param blob Blob to convert
56009
+ * @param fileName File name to download
56010
+ */
55983
56011
  var download = function (blob, fileName) {
55984
56012
  var file = new File([blob], fileName);
55985
56013
  var a = document.createElement('a');
@@ -55992,38 +56020,83 @@ var download = function (blob, fileName) {
55992
56020
  a.click();
55993
56021
  };
55994
56022
  var FileCard = function (_a) {
55995
- var _b, _c;
55996
- var projectOwner = _a.projectOwner, projectName = _a.projectName, client = _a.client, run = _a.run, label = _a.label, path = _a.path, file = _a.file, description = _a.description, onClicked = _a.onClicked, _d = _a.isCloud, isCloud = _d === void 0 ? true : _d;
56023
+ var _b;
56024
+ var projectOwner = _a.projectOwner, projectName = _a.projectName, client = _a.client, run = _a.run, label = _a.label, path = _a.path, file = _a.file, description = _a.description, onClicked = _a.onClicked, _c = _a.isCloud, isCloud = _c === void 0 ? true : _c;
55997
56025
  var host = getHost();
55998
56026
  var fromFileToBase64 = usePollinationPanel().fromFileToBase64;
55999
- var _e = useVSFToHTML(), loading = _e.loading, html = _e.html, fetchHTML = _e.fetchHTML;
56000
- var _f = React.useState(false), open = _f[0], setOpen = _f[1];
56001
- var _g = React.useState(false), infoOver = _g[0], setInfoOver = _g[1];
56002
- var _h = React.useState(false), downloadOver = _h[0], setDownloadOver = _h[1];
56003
- var _j = React.useState(false), htmlOver = _j[0], setHtmlOver = _j[1];
56004
- var _k = React.useState(true), isLoading = _k[0], setIsLoading = _k[1];
56005
- var _l = React.useState(false), isInactive = _l[0], setIsInactive = _l[1];
56027
+ var _d = useVSFToHTML(), loading = _d.loading, html = _d.html, fetchHTML = _d.fetchHTML;
56028
+ var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
56029
+ var _e = React.useState(false), open = _e[0], setOpen = _e[1];
56030
+ // Hover effects
56031
+ var _f = React.useState(false), infoOver = _f[0], setInfoOver = _f[1];
56032
+ var _g = React.useState(false), downloadOver = _g[0], setDownloadOver = _g[1];
56033
+ var _h = React.useState(false), htmlOver = _h[0], setHtmlOver = _h[1];
56034
+ var _j = React.useState(true), isLoading = _j[0], setIsLoading = _j[1];
56035
+ var _k = React.useState(false), isInactive = _k[0], setIsInactive = _k[1];
56006
56036
  // Data to use for CAD injections
56007
- var _m = React.useState(), CADdata = _m[0], setCADdata = _m[1];
56037
+ var _l = React.useState(), CADdata = _l[0], setCADdata = _l[1];
56008
56038
  // File to send to parent
56009
- var _o = React.useState(), currFile = _o[0], setCurrFile = _o[1];
56010
- // /**
56011
- // * Check if run id is a valid UUID or file path (Local sim)
56012
- // * @param str run id
56013
- // * @returns true or false
56014
- // */
56015
- // const checkIfValidUUID = (str: string): boolean => {
56016
- // const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi
56017
- // return regexExp.test(str)
56018
- // }
56019
- // const isCloud = useMemo(() => checkIfValidUUID(runId), [runId])
56020
- var downloadArtifact = useArtifacts(projectOwner, projectName, client).downloadArtifact;
56021
- var setCADintegration = React.useCallback(function (file) {
56039
+ var _m = React.useState(), currFile = _m[0], setCurrFile = _m[1];
56040
+ // HTML integration
56041
+ var _o = React.useState(false), hasHtml = _o[0], setHasHtml = _o[1];
56042
+ // ZIP integration
56043
+ var _p = React.useState(), innerName = _p[0], setInnerName = _p[1];
56044
+ /**
56045
+ * Get file name to use
56046
+ */
56047
+ var filename = React.useMemo(function () {
56048
+ if (!path)
56049
+ return;
56050
+ return innerName !== null && innerName !== void 0 ? innerName : path.split('/').reverse()[0];
56051
+ }, [path, innerName]);
56052
+ /**
56053
+ * Get file from a ZIP file.
56054
+ * 1 zip = 1 file for now
56055
+ */
56056
+ var getFileFromZip = React.useCallback(function (file) {
56022
56057
  if (!file)
56023
56058
  return;
56059
+ var archive = new jszip_min();
56060
+ archive.loadAsync(file)
56061
+ .then(function (zip) { return __awaiter$1(void 0, void 0, void 0, function () {
56062
+ var entries, listOfPromises, promiseOfList;
56063
+ return __generator$1(this, function (_a) {
56064
+ entries = Object.keys(zip.files).map(function (name) { return zip.files[name]; });
56065
+ listOfPromises = entries.map(function (entry) {
56066
+ return entry
56067
+ .async('blob')
56068
+ .then(function (blob) { return [entry.name, blob]; });
56069
+ });
56070
+ promiseOfList = Promise.all(listOfPromises);
56071
+ promiseOfList.then(function (list) {
56072
+ list.forEach(function (_a) {
56073
+ var name = _a[0], f = _a[1];
56074
+ // 1 zip = 1 file
56075
+ // I assume text/plain
56076
+ setInnerName(name);
56077
+ var blob = f.slice(0, f.size, 'text/plain');
56078
+ setCurrFile(blob);
56079
+ if (name.endsWith('vsf')) {
56080
+ setHasHtml(true);
56081
+ fetchHTML(blob);
56082
+ setCADintegration(blob, name);
56083
+ }
56084
+ });
56085
+ });
56086
+ return [2 /*return*/];
56087
+ });
56088
+ }); });
56089
+ }, [file]);
56090
+ /**
56091
+ * Get CAD data to use with the panel
56092
+ */
56093
+ var setCADintegration = React.useCallback(function (file, name) {
56094
+ if (name === void 0) { name = undefined; }
56095
+ if (!file || !filename)
56096
+ return;
56024
56097
  if (host === 'web')
56025
56098
  return;
56026
- if (path.endsWith('hbjson')
56099
+ if (filename.endsWith('hbjson')
56027
56100
  && host === 'rhino') {
56028
56101
  var reader_1 = new FileReader();
56029
56102
  reader_1.readAsText(file);
@@ -56036,7 +56109,7 @@ var FileCard = function (_a) {
56036
56109
  });
56037
56110
  };
56038
56111
  }
56039
- else if (path.endsWith('vsf')
56112
+ else if ((filename.endsWith('vsf') || (name === null || name === void 0 ? void 0 : name.endsWith('vsf')))
56040
56113
  && (host === 'rhino' || host === 'revit')) {
56041
56114
  var reader_2 = new FileReader();
56042
56115
  reader_2.readAsText(file);
@@ -56049,7 +56122,7 @@ var FileCard = function (_a) {
56049
56122
  });
56050
56123
  };
56051
56124
  }
56052
- }, [file]);
56125
+ }, [file, filename]);
56053
56126
  /**
56054
56127
  * Fetch file from cloud
56055
56128
  */
@@ -56062,15 +56135,32 @@ var FileCard = function (_a) {
56062
56135
  setCurrFile(undefined);
56063
56136
  setCADintegration(undefined);
56064
56137
  setIsLoading(false);
56138
+ setHasHtml(false);
56139
+ setInnerName(undefined);
56065
56140
  return;
56066
56141
  }
56067
56142
  res.blob()
56068
56143
  .then(function (blob) {
56069
- setCurrFile(blob);
56070
- if (path === null || path === void 0 ? void 0 : path.endsWith('vsf')) {
56071
- fetchHTML(blob);
56144
+ // File is a ZIP
56145
+ if (blob.type === 'application/zip') {
56146
+ getFileFromZip(blob);
56147
+ }
56148
+ else {
56149
+ setCurrFile(blob);
56150
+ setInnerName(undefined);
56151
+ if (path === null || path === void 0 ? void 0 : path.endsWith('vsf')) {
56152
+ setHasHtml(true);
56153
+ fetchHTML(blob); // HTML button
56154
+ setCADintegration(blob);
56155
+ }
56156
+ else if (path === null || path === void 0 ? void 0 : path.endsWith('hbjson')) {
56157
+ setHasHtml(false);
56158
+ setCADintegration(blob);
56159
+ }
56160
+ else {
56161
+ setHasHtml(false);
56162
+ }
56072
56163
  }
56073
- setCADintegration(blob);
56074
56164
  setIsLoading(false);
56075
56165
  setIsInactive(false);
56076
56166
  });
@@ -56081,11 +56171,6 @@ var FileCard = function (_a) {
56081
56171
  setIsInactive(true);
56082
56172
  });
56083
56173
  };
56084
- var filename = React.useMemo(function () {
56085
- if (!path)
56086
- return;
56087
- return path.split('/').reverse()[0];
56088
- }, [path]);
56089
56174
  /**
56090
56175
  * Read local file as base64 - Panel only
56091
56176
  */
@@ -56151,12 +56236,11 @@ var FileCard = function (_a) {
56151
56236
  React__default["default"].createElement("div", { style: { float: 'left', margin: '0 8px 0 0' } }, !isLoading ? React__default["default"].createElement("div", { title: !isInactive
56152
56237
  ? 'Open the viewer'
56153
56238
  : 'File is missing. Check run workspace' },
56154
- React__default["default"].createElement("span", { style: { margin: '0 8px 0 0' } }, path && getFileIcon(18, ((_c = (_b = path.split('/')
56155
- .reverse()[0]) === null || _b === void 0 ? void 0 : _b.split('.')) === null || _c === void 0 ? void 0 : _c.pop()) || '')),
56239
+ React__default["default"].createElement("span", { style: { margin: '0 8px 0 0' } }, path && filename && getFileIcon(18, ((_b = filename === null || filename === void 0 ? void 0 : filename.split('.')) === null || _b === void 0 ? void 0 : _b.pop()) || '')),
56156
56240
  label)
56157
56241
  : React__default["default"].createElement(LoadingIcon, { size: 14 })),
56158
56242
  !isLoading && React__default["default"].createElement("div", { style: { textAlign: 'right' } },
56159
- (filename && filename.endsWith('vsf')) && (loading ? React__default["default"].createElement(LoadingIcon, { size: 14 }) :
56243
+ (filename && hasHtml) && (loading ? React__default["default"].createElement(LoadingIcon, { size: 14 }) :
56160
56244
  (React__default["default"].createElement("button", { style: { all: 'unset', margin: '0 0 0 8px' }, title: 'Download HTML', onMouseOver: function () { return setHtmlOver(true); }, onMouseLeave: function () { return setHtmlOver(false); }, onClick: function (event) {
56161
56245
  if (!html)
56162
56246
  return;
@@ -56226,11 +56310,13 @@ styleInject(css_248z$2);
56226
56310
 
56227
56311
  var RunContent = function (_a) {
56228
56312
  var inputData = _a.inputData, projectOwner = _a.projectOwner, projectName = _a.projectName, run = _a.run, client = _a.client, title = _a.title, style = _a.style, getFileCard = _a.getFileCard, getFolderCard = _a.getFolderCard, _b = _a.isCloud, isCloud = _b === void 0 ? true : _b;
56313
+ var getTrigger = useRuns(client).getTrigger;
56229
56314
  var _c = React.useState([]), currData = _c[0], setCurrData = _c[1];
56230
56315
  var fileExplorer = usePollinationPanel().fileExplorer;
56231
56316
  var _d = React.useState([]), currParams = _d[0], setCurrParams = _d[1];
56232
56317
  var _e = React.useState([]), currFiles = _e[0], setCurrFiles = _e[1];
56233
56318
  var _f = React.useState([]), currFolders = _f[0], setCurrFolders = _f[1];
56319
+ var trigger = React.useMemo(function () { return isCloud ? getTrigger(run) : false; }, [run, isCloud]);
56234
56320
  React.useEffect(function () { return setCurrData(inputData); }, [inputData]);
56235
56321
  React.useEffect(function () {
56236
56322
  if (!currData || currData.length == 0)
@@ -56239,15 +56325,28 @@ var RunContent = function (_a) {
56239
56325
  var files = [];
56240
56326
  var folders = [];
56241
56327
  currData.forEach(function (i) {
56328
+ var _a, _b, _c, _d;
56242
56329
  switch (i.type) {
56243
56330
  case 'StepFileInput':
56331
+ files.push({ run: run, label: i.name,
56332
+ path: (_a = i.source) === null || _a === void 0 ? void 0 : _a.path, description: i.description });
56333
+ break;
56244
56334
  case 'StepFileOutput':
56335
+ var filePath = trigger
56336
+ ? "outputs/".concat(i.name, "/").concat(run.id, ".zip")
56337
+ : (_b = i.source) === null || _b === void 0 ? void 0 : _b.path;
56245
56338
  files.push({ run: run, label: i.name,
56246
- path: i.source.path, description: i.description });
56339
+ path: filePath, description: i.description });
56247
56340
  break;
56248
56341
  case 'StepFolderInput':
56342
+ folders.push({ label: i.name, path: (_c = i.source) === null || _c === void 0 ? void 0 : _c.path,
56343
+ description: i.description });
56344
+ break;
56249
56345
  case 'StepFolderOutput':
56250
- folders.push({ label: i.name, path: i.source.path,
56346
+ var folderPath = trigger
56347
+ ? "outputs/".concat(i.name)
56348
+ : (_d = i.source) === null || _d === void 0 ? void 0 : _d.path;
56349
+ folders.push({ label: i.name, path: folderPath,
56251
56350
  description: i.description });
56252
56351
  break;
56253
56352
  default: