From a417064e11e9771ce95f052e557efa469b732c2a Mon Sep 17 00:00:00 2001 From: Luke Hoggatt Date: Wed, 13 Sep 2023 10:52:25 -0500 Subject: [PATCH] greatly simply file browser to just select stuff remove reasons why this component would randomly reload after selecting a file --- st_file_browser/__init__.py | 7 +--- .../frontend/build/asset-manifest.json | 8 ++--- st_file_browser/frontend/build/index.html | 2 +- ...ifest.a0596225e23638cb17232461d8504d40.js} | 6 ++-- .../frontend/build/service-worker.js | 2 +- .../build/static/js/main.4551d177.chunk.js | 2 ++ .../static/js/main.4551d177.chunk.js.map | 1 + .../build/static/js/main.8be435cb.chunk.js | 2 -- .../static/js/main.8be435cb.chunk.js.map | 1 - .../frontend/src/StFileBrowser.tsx | 32 ------------------- 10 files changed, 13 insertions(+), 50 deletions(-) rename st_file_browser/frontend/build/{precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js => precache-manifest.a0596225e23638cb17232461d8504d40.js} (89%) create mode 100644 st_file_browser/frontend/build/static/js/main.4551d177.chunk.js create mode 100644 st_file_browser/frontend/build/static/js/main.4551d177.chunk.js.map delete mode 100644 st_file_browser/frontend/build/static/js/main.8be435cb.chunk.js delete mode 100644 st_file_browser/frontend/build/static/js/main.8be435cb.chunk.js.map diff --git a/st_file_browser/__init__.py b/st_file_browser/__init__.py index 1d3d800..8177719 100644 --- a/st_file_browser/__init__.py +++ b/st_file_browser/__init__.py @@ -76,11 +76,7 @@ def st_file_browser( file_ignores=None, select_filetype_ignores=None, extentions=None, - show_delete_file=False, show_choose_file=False, - show_download_file=True, - show_new_folder=False, - show_upload_file=False, limit=10000, key=None, use_cache=False, @@ -108,9 +104,8 @@ def st_file_browser( event = _component_func( files=files, + path=path, show_choose_file=show_choose_file, - show_download_file=show_download_file, - show_delete_file=show_delete_file, ignore_file_select_event=ignore_file_select_event, key=key, ) diff --git a/st_file_browser/frontend/build/asset-manifest.json b/st_file_browser/frontend/build/asset-manifest.json index 44dcced..195b68c 100644 --- a/st_file_browser/frontend/build/asset-manifest.json +++ b/st_file_browser/frontend/build/asset-manifest.json @@ -1,14 +1,14 @@ { "files": { - "main.js": "./static/js/main.8be435cb.chunk.js", - "main.js.map": "./static/js/main.8be435cb.chunk.js.map", + "main.js": "./static/js/main.4551d177.chunk.js", + "main.js.map": "./static/js/main.4551d177.chunk.js.map", "runtime-main.js": "./static/js/runtime-main.5606d314.js", "runtime-main.js.map": "./static/js/runtime-main.5606d314.js.map", "static/css/2.5a3919a9.chunk.css": "./static/css/2.5a3919a9.chunk.css", "static/js/2.0e6934a9.chunk.js": "./static/js/2.0e6934a9.chunk.js", "static/js/2.0e6934a9.chunk.js.map": "./static/js/2.0e6934a9.chunk.js.map", "index.html": "./index.html", - "precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js": "./precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js", + "precache-manifest.a0596225e23638cb17232461d8504d40.js": "./precache-manifest.a0596225e23638cb17232461d8504d40.js", "service-worker.js": "./service-worker.js", "static/css/2.5a3919a9.chunk.css.map": "./static/css/2.5a3919a9.chunk.css.map", "static/js/2.0e6934a9.chunk.js.LICENSE.txt": "./static/js/2.0e6934a9.chunk.js.LICENSE.txt", @@ -18,6 +18,6 @@ "static/js/runtime-main.5606d314.js", "static/css/2.5a3919a9.chunk.css", "static/js/2.0e6934a9.chunk.js", - "static/js/main.8be435cb.chunk.js" + "static/js/main.4551d177.chunk.js" ] } \ No newline at end of file diff --git a/st_file_browser/frontend/build/index.html b/st_file_browser/frontend/build/index.html index c0a30fd..8169fc0 100644 --- a/st_file_browser/frontend/build/index.html +++ b/st_file_browser/frontend/build/index.html @@ -1 +1 @@ -Streamlit Component
\ No newline at end of file +Streamlit Component
\ No newline at end of file diff --git a/st_file_browser/frontend/build/precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js b/st_file_browser/frontend/build/precache-manifest.a0596225e23638cb17232461d8504d40.js similarity index 89% rename from st_file_browser/frontend/build/precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js rename to st_file_browser/frontend/build/precache-manifest.a0596225e23638cb17232461d8504d40.js index 8a41f71..4323db7 100644 --- a/st_file_browser/frontend/build/precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js +++ b/st_file_browser/frontend/build/precache-manifest.a0596225e23638cb17232461d8504d40.js @@ -1,6 +1,6 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([ { - "revision": "72c17be733e6957ca328e5a7ed2fd2a8", + "revision": "0cca5067d8c6de5d954432987ef27a01", "url": "./index.html" }, { @@ -16,8 +16,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([ "url": "./static/js/2.0e6934a9.chunk.js.LICENSE.txt" }, { - "revision": "ccfb7f702176a8fa1c4c", - "url": "./static/js/main.8be435cb.chunk.js" + "revision": "e51e5392a52097788e7e", + "url": "./static/js/main.4551d177.chunk.js" }, { "revision": "44e7e8c245c21e8f352f", diff --git a/st_file_browser/frontend/build/service-worker.js b/st_file_browser/frontend/build/service-worker.js index ded19d8..bbc4fbc 100644 --- a/st_file_browser/frontend/build/service-worker.js +++ b/st_file_browser/frontend/build/service-worker.js @@ -14,7 +14,7 @@ importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); importScripts( - "./precache-manifest.f6ea30157b08e5c9621b26aa22315f1c.js" + "./precache-manifest.a0596225e23638cb17232461d8504d40.js" ); self.addEventListener('message', (event) => { diff --git a/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js b/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js new file mode 100644 index 0000000..f7bc207 --- /dev/null +++ b/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js @@ -0,0 +1,2 @@ +(this.webpackJsonpstreamlit_file_browser=this.webpackJsonpstreamlit_file_browser||[]).push([[0],{127:function(e,n,t){"use strict";t.r(n);var a=t(5),l=t.n(a),o=t(48),r=t.n(o),i=t(9),c=t(0),s=t(1),d=t(12),E=t(2),u=t(3),m=t(14),F=t(36),h=t.n(F),f=t(6),D=function(e){var n=e.selectedItems,t=e.isFolder,a=e.icons,o=e.nameFilter,r=e.canCreateFolder,i=e.onCreateFolder,c=e.canRenameFile,s=e.onRenameFile,d=e.canRenameFolder,E=e.onRenameFolder,u=e.canDeleteFile,m=e.onDeleteFile,F=(e.canDeleteFolder,e.onDeleteFolder,e.canDownloadFile),h=e.onDownloadFile,D=e.canDownloadFolder,O=e.onDownloadFolder,g=e.canChooseFile,C=e.onChooseFile,L=e.canChooseFolder,R=e.onChooseFolder,_=[];if(n.length){var v=n.filter((function(e){return e.action}));if(v.length===n.length&&1===Object(f.a)(new Set(v)).length){var b;switch(v[0].action){case"delete":b="Deleting ...";break;case"rename":b="Renaming ...";break;default:b="Moving ..."}_=l.a.createElement("div",{className:"item-actions"},a.Loading," ",b)}else{t&&r&&!o&&_.push(l.a.createElement("li",{key:"action-add-folder"},l.a.createElement("a",{onClick:i,href:"#",role:"button"},a.Folder,"\xa0Add Subfolder")));var p=n.find((function(e){return!e.keyDerived}));p||t||!c||1!==n.length?!p&&t&&d&&_.push(l.a.createElement("li",{key:"action-rename"},l.a.createElement("a",{onClick:E,href:"#",role:"button"},a.Rename,"\xa0Rename"))):_.push(l.a.createElement("li",{key:"action-rename"},l.a.createElement("a",{onClick:s,href:"#",role:"button"},a.Rename,"\xa0Rename"))),p||t||!u||_.push(l.a.createElement("li",{key:"action-delete"},l.a.createElement("a",{onClick:m,href:"#",role:"button"},a.Delete,"\xa0Delete"))),(!t&&F||t&&D)&&_.push(l.a.createElement("li",{key:"action-download"},l.a.createElement("a",{onClick:t?O:h,href:"#",role:"button"},a.Download,"\xa0Download"))),(!t&&g||t&&L)&&_.push(l.a.createElement("li",{key:"action-choose"},l.a.createElement("a",{onClick:t?R:C,href:"#",role:"button"},l.a.createElement("i",{className:"fa fa-plus","aria-hidden":"true"}),"\xa0Choose"))),_=_.length?l.a.createElement("ul",{className:"item-actions"},_):l.a.createElement("div",{className:"item-actions"},"\xa0")}}else r&&!o&&_.push(l.a.createElement("li",{key:"action-add-folder"},l.a.createElement("a",{onClick:i,href:"#",role:"button"},a.Folder,"\xa0Add Folder"))),_=_.length?l.a.createElement("ul",{className:"item-actions"},_):l.a.createElement("div",{className:"item-actions"},"\xa0");return _};D.defaultProps={selectedItems:[],isFolder:!1,icons:{},nameFilter:"",canCreateFolder:!1,onCreateFolder:null,canRenameFile:!1,onRenameFile:null,canRenameFolder:!1,onRenameFolder:null,canDeleteFile:!1,onDeleteFile:null,canDeleteFolder:!1,onDeleteFolder:null,canDownloadFile:!1,onDownloadFile:null,canDownloadFolder:!1,onDownloadFolder:null,canChooseFile:!1,onChooseFile:null,canChooseFolder:!1,onChooseFolder:null};var O=D,g=(t(122),t(123),function(e){return e.SELECT_FILE="SELECT_FILE",e.SELECT_FOLDER="SELECT_FOLDER",e.DOWNLOAD="DOWNLOAD",e.DELETE_FILE="DELETE_FILE",e.DELETE_FOLDER="DELETE_FOLDER",e.RENAME_FOLDER="RENAME_FOLDER",e.RENAME_FILE="RENAME_FILE",e.CREATE_FILE="CREATE_FILE",e.CREATE_FOLDER="CREATE_FOLDER",e.MOVE_FILE="MOVE_FILE",e.MOVE_FOLDER="MOVE_FOLDER",e.CHOOSE_FILE="CHOOSE_FILE",e}(g||{})),C=function(e){Object(E.a)(t,e);var n=Object(u.a)(t);function t(e){var a;return Object(c.a)(this,t),(a=n.call(this,e)).args=void 0,a.folderOpenHandler=function(e){return a.ajustHeight()},a.folderCloseHandler=function(e){return a.ajustHeight()},a.fileSelectedHandler=function(e){if(!a.args.ignore_file_select_event){var n=a.args.files.find((function(n){return n.path===e.key}));n&&(t={type:g.SELECT_FILE,target:n},m.a.setComponentValue(t))}var t},a.convertFiles=function(e){return e.map((function(e){return{key:e.path,modified:e.update_time||0,size:e.size||0}}))},a.noop=function(){return l.a.createElement(l.a.Fragment,null)},a.render=function(){var e=Object(d.a)(a);return l.a.createElement("div",null,l.a.createElement(h.a,Object.assign({},a.args,{showActionBar:!0,canFilter:!0,detailRenderer:a.noop,icons:F.Icons.FontAwesome(4),files:a.convertFiles(a.args.files),onFolderOpen:a.folderOpenHandler,onFolderClose:a.folderCloseHandler,onSelect:a.fileSelectedHandler,actionRenderer:function(){return O(Object(i.a)(Object(i.a)({},arguments.length<=0?void 0:arguments[0]),{canChooseFile:e.args.show_choose_file}))}})))},a.args=e.args,a}return Object(s.a)(t,[{key:"ajustHeight",value:function(e){var n=document.getElementById("root");if(n){var t=Math.min(n.clientHeight,n.scrollHeight,n.offsetHeight);m.a.setFrameHeight(t-(e||0)),setTimeout(m.a.setFrameHeight,1)}}},{key:"componentDidMount",value:function(){this.ajustHeight()}},{key:"componentDidUpdate",value:function(){this.ajustHeight()}}]),t}(m.b),L=Object(m.c)(C),R=function(e){Object(E.a)(t,e);var n=Object(u.a)(t);function t(e){var a;return Object(c.a)(this,t),(a=n.call(this,e)).args=void 0,a.args=e.args,a}return Object(s.a)(t,[{key:"render",value:function(){return l.a.createElement("div",null,l.a.createElement(L,this.props))}}]),t}(m.b),_=Object(m.c)(R);r.a.render(l.a.createElement(l.a.StrictMode,null,l.a.createElement(_,null)),document.getElementById("root"))},54:function(e,n,t){e.exports=t(127)}},[[54,1,2]]]); +//# sourceMappingURL=main.4551d177.chunk.js.map \ No newline at end of file diff --git a/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js.map b/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js.map new file mode 100644 index 0000000..1be5f60 --- /dev/null +++ b/st_file_browser/frontend/build/static/js/main.4551d177.chunk.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["actions.jsx","StFileBrowser.tsx","index.tsx"],"names":["Actions","props","selectedItems","isFolder","icons","nameFilter","canCreateFolder","onCreateFolder","canRenameFile","onRenameFile","canRenameFolder","onRenameFolder","canDeleteFile","onDeleteFile","canDownloadFile","canDeleteFolder","onDeleteFolder","onDownloadFile","canDownloadFolder","onDownloadFolder","canChooseFile","onChooseFile","canChooseFolder","onChooseFolder","actions","length","selectedItemsAction","filter","item","action","_toConsumableArray","Set","actionText","React","createElement","className","Loading","push","key","onClick","href","role","Folder","itemsWithoutKeyDerived","find","keyDerived","Rename","Delete","Download","aria-hidden","defaultProps","StreamlitEventType","FileBrowserNative","_StreamlitComponentBa","_inherits","_super","_createSuper","_this","_classCallCheck","call","args","folderOpenHandler","opts","ajustHeight","folderCloseHandler","fileSelectedHandler","ignore_file_select_event","file","files","path","event","type","SELECT_FILE","target","Streamlit","setComponentValue","convertFiles","map","modified","update_time","size","noop","Fragment","render","that","_assertThisInitialized","FileBrowser","Object","assign","showActionBar","canFilter","detailRenderer","Icons","FontAwesome","onFolderOpen","onFolderClose","onSelect","actionRenderer","_objectSpread","arguments","undefined","show_choose_file","_createClass","value","revoke_step","root","document","getElementById","height","Math","min","clientHeight","scrollHeight","offsetHeight","setFrameHeight","setTimeout","this","StreamlitComponentBase","StreamlitFileBrowserNative","withStreamlitConnection","FileBrowserWrapper","_StreamlitComponentBa2","_super2","_this2","ReactDOM","StrictMode","StFileBrowser"],"mappings":"yPAGMA,EAAU,SAACC,GACf,IACEC,EA+BED,EA/BFC,cACAC,EA8BEF,EA9BFE,SACAC,EA6BEH,EA7BFG,MACAC,EA4BEJ,EA5BFI,WAEAC,EA0BEL,EA1BFK,gBACAC,EAyBEN,EAzBFM,eAEAC,EAuBEP,EAvBFO,cACAC,EAsBER,EAtBFQ,aAEAC,EAoBET,EApBFS,gBACAC,EAmBEV,EAnBFU,eAEAC,EAiBEX,EAjBFW,cACAC,EAgBEZ,EAhBFY,aAKAC,GAWEb,EAdFc,gBAcEd,EAbFe,eAaEf,EAXFa,iBACAG,EAUEhB,EAVFgB,eAEAC,EAQEjB,EARFiB,kBACAC,EAOElB,EAPFkB,iBAEAC,EAKEnB,EALFmB,cACAC,EAIEpB,EAJFoB,aAEAC,EAEErB,EAFFqB,gBACAC,EACEtB,EADFsB,eAIEC,EAAU,GAEd,GAAItB,EAAcuB,OAAQ,CAExB,IAAMC,EAAsBxB,EAAcyB,QAAO,SAAAC,GAAI,OAAIA,E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YAAAlD,EAAA,EAAAd,IAAA,cAAAiE,MAED,SAAYC,GACV,IAAMC,EAAOC,SAASC,eAAe,QACrC,GAAIF,EAAM,CACR,IAAMG,EAASC,KAAKC,IAClBL,EAAKM,aACLN,EAAKO,aACLP,EAAKQ,cAEPvC,IAAUwC,eAAeN,GAAUJ,GAA4B,IAC/DW,WAAWzC,IAAUwC,eAAgB,MAExC,CAAA5E,IAAA,oBAAAiE,MAED,WACEa,KAAKrD,gBACN,CAAAzB,IAAA,qBAAAiE,MAED,WACEa,KAAKrD,kBACNX,EA3BoB,CAASiE,KA2E1BC,EAA6BC,YAAwBnE,GAErDoE,EAAkB,SAAAC,GAAAnE,YAAAkE,EAAAC,GAAA,IAAAC,EAAAlE,YAAAgE,GAGtB,SAAAA,EAAYvH,GAAwB,IAAD0H,EAEX,OAFWjE,YAAA,KAAA8D,IACjCG,EAAAD,EAAA/D,KAAA,KAAM1D,IAHA2D,UAAI,EAIV+D,EAAK/D,KAAO3D,EAAM2D,KAAI+D,EASvB,OARArB,YAAAkB,EAAA,EAAAlF,IAAA,SAAAiE,MAED,WACI,OACEtE,IAAAC,cAAA,WACED,IAAAC,cAACoF,EAA+BF,KAAKnH,YAG5CuH,EAdqB,CAASH,KAiBlBE,cAAwBC,GC1JvCI,IAASzC,OACPlD,IAAAC,cAACD,IAAM4F,WAAU,KACf5F,IAAAC,cAAC4F,EAAa,OAEhBpB,SAASC,eAAe,U","file":"static/js/main.4551d177.chunk.js","sourcesContent":["import React from 'react'\r\nimport PropTypes from 'prop-types'\r\n\r\nconst Actions = (props) => {\r\n const {\r\n selectedItems,\r\n isFolder,\r\n icons,\r\n nameFilter,\r\n\r\n canCreateFolder,\r\n onCreateFolder,\r\n\r\n canRenameFile,\r\n onRenameFile,\r\n\r\n canRenameFolder,\r\n onRenameFolder,\r\n\r\n canDeleteFile,\r\n onDeleteFile,\r\n\r\n canDeleteFolder,\r\n onDeleteFolder,\r\n\r\n canDownloadFile,\r\n onDownloadFile,\r\n\r\n canDownloadFolder,\r\n onDownloadFolder,\r\n\r\n canChooseFile,\r\n onChooseFile,\r\n\r\n canChooseFolder,\r\n onChooseFolder,\r\n } = props\r\n\r\n /** @type any */\r\n let actions = []\r\n\r\n if (selectedItems.length) {\r\n // Something is selected. Build custom actions depending on what it is.\r\n const selectedItemsAction = selectedItems.filter(item => item.action)\r\n if (selectedItemsAction.length === selectedItems.length && [...new Set(selectedItemsAction)].length === 1) {\r\n // Selected item has an active action against it. Disable all other actions.\r\n let actionText\r\n switch (selectedItemsAction[0].action) {\r\n case 'delete':\r\n actionText = 'Deleting ...'\r\n break\r\n\r\n case 'rename':\r\n actionText = 'Renaming ...'\r\n break\r\n\r\n default:\r\n actionText = 'Moving ...'\r\n break\r\n }\r\n\r\n actions = (\r\n // TODO: Enable plugging in custom spinner.\r\n
\r\n {icons.Loading} {actionText}\r\n
\r\n )\r\n } else {\r\n if (isFolder && canCreateFolder && !nameFilter) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Folder}\r\n  Add Subfolder\r\n \r\n
  • \r\n )\r\n }\r\n\r\n const itemsWithoutKeyDerived = selectedItems.find(item => !item.keyDerived)\r\n if (!itemsWithoutKeyDerived && !isFolder && canRenameFile && selectedItems.length === 1) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Rename}\r\n  Rename\r\n \r\n
  • \r\n )\r\n } else if (!itemsWithoutKeyDerived && isFolder && canRenameFolder) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Rename}\r\n  Rename\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (!itemsWithoutKeyDerived && !isFolder && canDeleteFile) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Delete}\r\n  Delete\r\n \r\n
  • \r\n )\r\n }\r\n // else if (!itemsWithoutKeyDerived && isFolder && canDeleteFolder) {\r\n // actions.push(\r\n //
  • \r\n // \r\n // {icons.Delete}\r\n //  Delete\r\n // \r\n //
  • \r\n // )\r\n // }\r\n\r\n if ((!isFolder && canDownloadFile) || (isFolder && canDownloadFolder)) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Download}\r\n  Download\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if ((!isFolder && canChooseFile) || (isFolder && canChooseFolder)) {\r\n actions.push(\r\n
  • \r\n \r\n \r\n  Choose\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (actions.length) {\r\n actions = ()\r\n } else {\r\n actions = (
     
    )\r\n }\r\n }\r\n } else {\r\n // Nothing selected: We're in the 'root' folder. Only allowed action is adding a folder.\r\n if (canCreateFolder && !nameFilter) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Folder}\r\n  Add Folder\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (actions.length) {\r\n actions = ()\r\n } else {\r\n actions = (
     
    )\r\n }\r\n }\r\n\r\n return actions\r\n}\r\n\r\nActions.propTypes = {\r\n selectedItems: PropTypes.arrayOf(PropTypes.object),\r\n isFolder: PropTypes.bool,\r\n icons: PropTypes.object,\r\n nameFilter: PropTypes.string,\r\n\r\n canCreateFolder: PropTypes.bool,\r\n onCreateFolder: PropTypes.func,\r\n\r\n canRenameFile: PropTypes.bool,\r\n onRenameFile: PropTypes.func,\r\n\r\n canRenameFolder: PropTypes.bool,\r\n onRenameFolder: PropTypes.func,\r\n\r\n canDeleteFile: PropTypes.bool,\r\n onDeleteFile: PropTypes.func,\r\n\r\n canDeleteFolder: PropTypes.bool,\r\n onDeleteFolder: PropTypes.func,\r\n\r\n canDownloadFile: PropTypes.bool,\r\n onDownloadFile: PropTypes.func,\r\n\r\n canDownloadFolder: PropTypes.bool,\r\n onDownloadFolder: PropTypes.func,\r\n\r\n canChooseFile: PropTypes.bool,\r\n onChooseFile: PropTypes.func,\r\n\r\n canChooseFolder: PropTypes.bool,\r\n onChooseFolder: PropTypes.func,\r\n}\r\n\r\nActions.defaultProps = {\r\n selectedItems: [],\r\n isFolder: false,\r\n icons: {},\r\n nameFilter: '',\r\n\r\n canCreateFolder: false,\r\n onCreateFolder: null,\r\n\r\n canRenameFile: false,\r\n onRenameFile: null,\r\n\r\n canRenameFolder: false,\r\n onRenameFolder: null,\r\n\r\n canDeleteFile: false,\r\n onDeleteFile: null,\r\n\r\n canDeleteFolder: false,\r\n onDeleteFolder: null,\r\n\r\n canDownloadFile: false,\r\n onDownloadFile: null,\r\n\r\n canDownloadFolder: false,\r\n onDownloadFolder: null,\r\n\r\n canChooseFile: false,\r\n onChooseFile: null,\r\n\r\n canChooseFolder: false,\r\n onChooseFolder: null,\r\n}\r\n\r\nexport default Actions\r\n","import React from \"react\"\r\nimport {\r\n Streamlit,\r\n StreamlitComponentBase,\r\n withStreamlitConnection,\r\n ComponentProps,\r\n} from \"streamlit-component-lib\"\r\nimport FileBrowser, {\r\n Icons,\r\n FileBrowserFile,\r\n FileBrowserFolder,\r\n} from \"react-keyed-file-browser\"\r\n\r\nimport get from 'lodash.get'\r\nimport IframeResizer from 'iframe-resizer-react'\r\nimport Actions from \"./actions\"\r\nimport \"react-keyed-file-browser/dist/react-keyed-file-browser.css\"\r\nimport \"font-awesome/css/font-awesome.min.css\"\r\n\r\ninterface File {\r\n path: string\r\n name?: string\r\n size?: number\r\n create_time?: number\r\n update_time?: number\r\n access_time?: number\r\n}\r\n\r\nenum StreamlitEventType {\r\n SELECT_FILE = \"SELECT_FILE\",\r\n SELECT_FOLDER = \"SELECT_FOLDER\",\r\n DOWNLOAD = \"DOWNLOAD\",\r\n DELETE_FILE = \"DELETE_FILE\",\r\n DELETE_FOLDER = \"DELETE_FOLDER\",\r\n RENAME_FOLDER = \"RENAME_FOLDER\",\r\n RENAME_FILE = \"RENAME_FILE\",\r\n CREATE_FILE = \"CREATE_FILE\",\r\n CREATE_FOLDER = \"CREATE_FOLDER\",\r\n MOVE_FILE = \"MOVE_FILE\",\r\n MOVE_FOLDER = \"MOVE_FOLDER\",\r\n CHOOSE_FILE = \"CHOOSE_FILE\",\r\n}\r\n\r\ninterface StreamlitEvent {\r\n type: StreamlitEventType\r\n target: File | File[]\r\n}\r\n\r\ninterface State {\r\n numClicks: number\r\n isFocused: boolean\r\n}\r\n\r\ninterface IArgs {\r\n files: File[]\r\n path: string\r\n show_choose_file: boolean\r\n ignore_file_select_event: boolean\r\n}\r\n\r\nconst noticeStreamlit = (event: StreamlitEvent) =>\r\n Streamlit.setComponentValue(event)\r\n\r\n \r\nclass FileBrowserNative extends StreamlitComponentBase {\r\n private args: IArgs\r\n\r\n constructor(props: ComponentProps) {\r\n super(props)\r\n this.args = props.args\r\n }\r\n\r\n ajustHeight(revoke_step?: number) {\r\n const root = document.getElementById(\"root\")\r\n if (root) {\r\n const height = Math.min(\r\n root.clientHeight,\r\n root.scrollHeight,\r\n root.offsetHeight\r\n )\r\n Streamlit.setFrameHeight(height - (revoke_step ? revoke_step : 0))\r\n setTimeout(Streamlit.setFrameHeight, 1)\r\n }\r\n }\r\n\r\n componentDidMount() {\r\n this.ajustHeight()\r\n }\r\n\r\n componentDidUpdate() {\r\n this.ajustHeight()\r\n }\r\n\r\n folderOpenHandler = (opts: FileBrowserFolder) => this.ajustHeight()\r\n folderCloseHandler = (opts: FileBrowserFolder) => this.ajustHeight()\r\n\r\n fileSelectedHandler = (opts: FileBrowserFile) => {\r\n if (!this.args.ignore_file_select_event) {\r\n const file = this.args.files.find((file) => file.path === opts.key)\r\n file &&\r\n noticeStreamlit({ type: StreamlitEventType.SELECT_FILE, target: file })\r\n }\r\n }\r\n\r\n convertFiles = (files: File[]): FileBrowserFile[] =>\r\n files.map((file) => ({\r\n key: file.path,\r\n modified: file.update_time || 0,\r\n size: file.size || 0,\r\n }))\r\n\r\n noop = () => <>\r\n public render = () => {\r\n let that = this\r\n return (\r\n
    \r\n {\r\n return Actions({\r\n ...args[0],\r\n ...{\r\n canChooseFile: that.args.show_choose_file,\r\n },\r\n })\r\n }}\r\n />\r\n
    \r\n )\r\n }\r\n}\r\nconst StreamlitFileBrowserNative = withStreamlitConnection(FileBrowserNative)\r\n\r\nclass FileBrowserWrapper extends StreamlitComponentBase {\r\n private args: IArgs\r\n \r\n constructor(props: ComponentProps) {\r\n super(props)\r\n this.args = props.args\r\n }\r\n\r\n public render(): React.ReactNode {\r\n return (\r\n
    \r\n \r\n
    \r\n )\r\n }\r\n}\r\n\r\nexport default withStreamlitConnection(FileBrowserWrapper)\r\n","import React from \"react\"\r\nimport ReactDOM from \"react-dom\"\r\nimport StFileBrowser from \"./StFileBrowser\"\r\n\r\nReactDOM.render(\r\n \r\n \r\n ,\r\n document.getElementById(\"root\")\r\n)\r\n"],"sourceRoot":""} \ No newline at end of file diff --git a/st_file_browser/frontend/build/static/js/main.8be435cb.chunk.js b/st_file_browser/frontend/build/static/js/main.8be435cb.chunk.js deleted file mode 100644 index 6f4ebf5..0000000 --- a/st_file_browser/frontend/build/static/js/main.8be435cb.chunk.js +++ /dev/null @@ -1,2 +0,0 @@ -(this.webpackJsonpstreamlit_file_browser=this.webpackJsonpstreamlit_file_browser||[]).push([[0],{127:function(e,n,t){"use strict";t.r(n);var a=t(5),l=t.n(a),o=t(48),r=t.n(o),i=t(9),c=t(0),s=t(1),d=t(12),u=t(2),E=t(3),F=t(14),f=t(36),m=t.n(f),h=t(6),g=function(e){var n=e.selectedItems,t=e.isFolder,a=e.icons,o=e.nameFilter,r=e.canCreateFolder,i=e.onCreateFolder,c=e.canRenameFile,s=e.onRenameFile,d=e.canRenameFolder,u=e.onRenameFolder,E=e.canDeleteFile,F=e.onDeleteFile,f=(e.canDeleteFolder,e.onDeleteFolder,e.canDownloadFile),m=e.onDownloadFile,g=e.canDownloadFolder,D=e.onDownloadFolder,p=e.canChooseFile,O=e.onChooseFile,C=e.canChooseFolder,L=e.onChooseFolder,_=[];if(n.length){var v=n.filter((function(e){return e.action}));if(v.length===n.length&&1===Object(h.a)(new Set(v)).length){var R;switch(v[0].action){case"delete":R="Deleting ...";break;case"rename":R="Renaming ...";break;default:R="Moving ..."}_=l.a.createElement("div",{className:"item-actions"},a.Loading," ",R)}else{t&&r&&!o&&_.push(l.a.createElement("li",{key:"action-add-folder"},l.a.createElement("a",{onClick:i,href:"#",role:"button"},a.Folder,"\xa0Add Subfolder")));var b=n.find((function(e){return!e.keyDerived}));b||t||!c||1!==n.length?!b&&t&&d&&_.push(l.a.createElement("li",{key:"action-rename"},l.a.createElement("a",{onClick:u,href:"#",role:"button"},a.Rename,"\xa0Rename"))):_.push(l.a.createElement("li",{key:"action-rename"},l.a.createElement("a",{onClick:s,href:"#",role:"button"},a.Rename,"\xa0Rename"))),b||t||!E||_.push(l.a.createElement("li",{key:"action-delete"},l.a.createElement("a",{onClick:F,href:"#",role:"button"},a.Delete,"\xa0Delete"))),(!t&&f||t&&g)&&_.push(l.a.createElement("li",{key:"action-download"},l.a.createElement("a",{onClick:t?D:m,href:"#",role:"button"},a.Download,"\xa0Download"))),(!t&&p||t&&C)&&_.push(l.a.createElement("li",{key:"action-choose"},l.a.createElement("a",{onClick:t?L:O,href:"#",role:"button"},l.a.createElement("i",{className:"fa fa-plus","aria-hidden":"true"}),"\xa0Choose"))),_=_.length?l.a.createElement("ul",{className:"item-actions"},_):l.a.createElement("div",{className:"item-actions"},"\xa0")}}else r&&!o&&_.push(l.a.createElement("li",{key:"action-add-folder"},l.a.createElement("a",{onClick:i,href:"#",role:"button"},a.Folder,"\xa0Add Folder"))),_=_.length?l.a.createElement("ul",{className:"item-actions"},_):l.a.createElement("div",{className:"item-actions"},"\xa0");return _};g.defaultProps={selectedItems:[],isFolder:!1,icons:{},nameFilter:"",canCreateFolder:!1,onCreateFolder:null,canRenameFile:!1,onRenameFile:null,canRenameFolder:!1,onRenameFolder:null,canDeleteFile:!1,onDeleteFile:null,canDeleteFolder:!1,onDeleteFolder:null,canDownloadFile:!1,onDownloadFile:null,canDownloadFolder:!1,onDownloadFolder:null,canChooseFile:!1,onChooseFile:null,canChooseFolder:!1,onChooseFolder:null};var D=g,p=(t(122),t(123),function(e){return e.SELECT_FILE="SELECT_FILE",e.SELECT_FOLDER="SELECT_FOLDER",e.DOWNLOAD="DOWNLOAD",e.DELETE_FILE="DELETE_FILE",e.DELETE_FOLDER="DELETE_FOLDER",e.RENAME_FOLDER="RENAME_FOLDER",e.RENAME_FILE="RENAME_FILE",e.CREATE_FILE="CREATE_FILE",e.CREATE_FOLDER="CREATE_FOLDER",e.MOVE_FILE="MOVE_FILE",e.MOVE_FOLDER="MOVE_FOLDER",e.CHOOSE_FILE="CHOOSE_FILE",e}(p||{})),O=function(e){return F.a.setComponentValue(e)},C=function(e){Object(u.a)(t,e);var n=Object(E.a)(t);function t(e){var a;return Object(c.a)(this,t),(a=n.call(this,e)).args=void 0,a.folderOpenHandler=function(e){return a.ajustHeight()},a.folderCloseHandler=function(e){return a.ajustHeight()},a.fileSelectedHandler=function(e){if(!a.args.ignore_file_select_event){var n=a.args.files.find((function(n){return n.path===e.key}));n&&O({type:p.SELECT_FILE,target:n})}},a.deleteFileHandler=function(e){var n=a.args.files.filter((function(n){return"string"===typeof e?e===n.path:e.includes(n.path)}));console.log("deleteFileHandler","key",e,"files ",n),n.length&&O({type:p.DELETE_FILE,target:n});var t=a.args.files.filter((function(n){return"string"===typeof e?e!==n.path:!e.includes(n.path)}));a.args.files=t},a.chooseHandler=function(e){var n=a.args.files.filter((function(n){return e.includes(n.path)}));n.length&&O({type:p.CHOOSE_FILE,target:n})},a.convertFiles=function(e){return e.map((function(e){return{key:e.path,modified:e.update_time||0,size:e.size||0}}))},a.noop=function(){return l.a.createElement(l.a.Fragment,null)},a.render=function(){var e=Object(d.a)(a);return l.a.createElement("div",null,l.a.createElement(m.a,Object.assign({},a.args,{showActionBar:!0,canFilter:!0,detailRenderer:a.noop,icons:f.Icons.FontAwesome(4),files:a.convertFiles(a.args.files),onFolderOpen:a.folderOpenHandler,onFolderClose:a.folderCloseHandler,onSelect:a.fileSelectedHandler,onDeleteFile:a.deleteFileHandler,actionRenderer:function(){for(var n=arguments.length,t=new Array(n),a=0;a {\r\n const {\r\n selectedItems,\r\n isFolder,\r\n icons,\r\n nameFilter,\r\n\r\n canCreateFolder,\r\n onCreateFolder,\r\n\r\n canRenameFile,\r\n onRenameFile,\r\n\r\n canRenameFolder,\r\n onRenameFolder,\r\n\r\n canDeleteFile,\r\n onDeleteFile,\r\n\r\n canDeleteFolder,\r\n onDeleteFolder,\r\n\r\n canDownloadFile,\r\n onDownloadFile,\r\n\r\n canDownloadFolder,\r\n onDownloadFolder,\r\n\r\n canChooseFile,\r\n onChooseFile,\r\n\r\n canChooseFolder,\r\n onChooseFolder,\r\n } = props\r\n\r\n /** @type any */\r\n let actions = []\r\n\r\n if (selectedItems.length) {\r\n // Something is selected. Build custom actions depending on what it is.\r\n const selectedItemsAction = selectedItems.filter(item => item.action)\r\n if (selectedItemsAction.length === selectedItems.length && [...new Set(selectedItemsAction)].length === 1) {\r\n // Selected item has an active action against it. Disable all other actions.\r\n let actionText\r\n switch (selectedItemsAction[0].action) {\r\n case 'delete':\r\n actionText = 'Deleting ...'\r\n break\r\n\r\n case 'rename':\r\n actionText = 'Renaming ...'\r\n break\r\n\r\n default:\r\n actionText = 'Moving ...'\r\n break\r\n }\r\n\r\n actions = (\r\n // TODO: Enable plugging in custom spinner.\r\n
    \r\n {icons.Loading} {actionText}\r\n
    \r\n )\r\n } else {\r\n if (isFolder && canCreateFolder && !nameFilter) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Folder}\r\n  Add Subfolder\r\n \r\n
  • \r\n )\r\n }\r\n\r\n const itemsWithoutKeyDerived = selectedItems.find(item => !item.keyDerived)\r\n if (!itemsWithoutKeyDerived && !isFolder && canRenameFile && selectedItems.length === 1) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Rename}\r\n  Rename\r\n \r\n
  • \r\n )\r\n } else if (!itemsWithoutKeyDerived && isFolder && canRenameFolder) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Rename}\r\n  Rename\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (!itemsWithoutKeyDerived && !isFolder && canDeleteFile) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Delete}\r\n  Delete\r\n \r\n
  • \r\n )\r\n }\r\n // else if (!itemsWithoutKeyDerived && isFolder && canDeleteFolder) {\r\n // actions.push(\r\n //
  • \r\n // \r\n // {icons.Delete}\r\n //  Delete\r\n // \r\n //
  • \r\n // )\r\n // }\r\n\r\n if ((!isFolder && canDownloadFile) || (isFolder && canDownloadFolder)) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Download}\r\n  Download\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if ((!isFolder && canChooseFile) || (isFolder && canChooseFolder)) {\r\n actions.push(\r\n
  • \r\n \r\n \r\n  Choose\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (actions.length) {\r\n actions = (
      {actions}
    )\r\n } else {\r\n actions = (
     
    )\r\n }\r\n }\r\n } else {\r\n // Nothing selected: We're in the 'root' folder. Only allowed action is adding a folder.\r\n if (canCreateFolder && !nameFilter) {\r\n actions.push(\r\n
  • \r\n \r\n {icons.Folder}\r\n  Add Folder\r\n \r\n
  • \r\n )\r\n }\r\n\r\n if (actions.length) {\r\n actions = (
      {actions}
    )\r\n } else {\r\n actions = (
     
    )\r\n }\r\n }\r\n\r\n return actions\r\n}\r\n\r\nActions.propTypes = {\r\n selectedItems: PropTypes.arrayOf(PropTypes.object),\r\n isFolder: PropTypes.bool,\r\n icons: PropTypes.object,\r\n nameFilter: PropTypes.string,\r\n\r\n canCreateFolder: PropTypes.bool,\r\n onCreateFolder: PropTypes.func,\r\n\r\n canRenameFile: PropTypes.bool,\r\n onRenameFile: PropTypes.func,\r\n\r\n canRenameFolder: PropTypes.bool,\r\n onRenameFolder: PropTypes.func,\r\n\r\n canDeleteFile: PropTypes.bool,\r\n onDeleteFile: PropTypes.func,\r\n\r\n canDeleteFolder: PropTypes.bool,\r\n onDeleteFolder: PropTypes.func,\r\n\r\n canDownloadFile: PropTypes.bool,\r\n onDownloadFile: PropTypes.func,\r\n\r\n canDownloadFolder: PropTypes.bool,\r\n onDownloadFolder: PropTypes.func,\r\n\r\n canChooseFile: PropTypes.bool,\r\n onChooseFile: PropTypes.func,\r\n\r\n canChooseFolder: PropTypes.bool,\r\n onChooseFolder: PropTypes.func,\r\n}\r\n\r\nActions.defaultProps = {\r\n selectedItems: [],\r\n isFolder: false,\r\n icons: {},\r\n nameFilter: '',\r\n\r\n canCreateFolder: false,\r\n onCreateFolder: null,\r\n\r\n canRenameFile: false,\r\n onRenameFile: null,\r\n\r\n canRenameFolder: false,\r\n onRenameFolder: null,\r\n\r\n canDeleteFile: false,\r\n onDeleteFile: null,\r\n\r\n canDeleteFolder: false,\r\n onDeleteFolder: null,\r\n\r\n canDownloadFile: false,\r\n onDownloadFile: null,\r\n\r\n canDownloadFolder: false,\r\n onDownloadFolder: null,\r\n\r\n canChooseFile: false,\r\n onChooseFile: null,\r\n\r\n canChooseFolder: false,\r\n onChooseFolder: null,\r\n}\r\n\r\nexport default Actions\r\n","import React from \"react\"\r\nimport {\r\n Streamlit,\r\n StreamlitComponentBase,\r\n withStreamlitConnection,\r\n ComponentProps,\r\n} from \"streamlit-component-lib\"\r\nimport FileBrowser, {\r\n Icons,\r\n FileBrowserFile,\r\n FileBrowserFolder,\r\n} from \"react-keyed-file-browser\"\r\n\r\nimport get from 'lodash.get'\r\nimport IframeResizer from 'iframe-resizer-react'\r\nimport Actions from \"./actions\"\r\nimport \"react-keyed-file-browser/dist/react-keyed-file-browser.css\"\r\nimport \"font-awesome/css/font-awesome.min.css\"\r\n\r\ninterface File {\r\n path: string\r\n name?: string\r\n size?: number\r\n create_time?: number\r\n update_time?: number\r\n access_time?: number\r\n}\r\n\r\nenum StreamlitEventType {\r\n SELECT_FILE = \"SELECT_FILE\",\r\n SELECT_FOLDER = \"SELECT_FOLDER\",\r\n DOWNLOAD = \"DOWNLOAD\",\r\n DELETE_FILE = \"DELETE_FILE\",\r\n DELETE_FOLDER = \"DELETE_FOLDER\",\r\n RENAME_FOLDER = \"RENAME_FOLDER\",\r\n RENAME_FILE = \"RENAME_FILE\",\r\n CREATE_FILE = \"CREATE_FILE\",\r\n CREATE_FOLDER = \"CREATE_FOLDER\",\r\n MOVE_FILE = \"MOVE_FILE\",\r\n MOVE_FOLDER = \"MOVE_FOLDER\",\r\n CHOOSE_FILE = \"CHOOSE_FILE\",\r\n}\r\n\r\ninterface StreamlitEvent {\r\n type: StreamlitEventType\r\n target: File | File[]\r\n}\r\n\r\ninterface State {\r\n numClicks: number\r\n isFocused: boolean\r\n}\r\n\r\ninterface IArgs {\r\n files: File[]\r\n path: string\r\n show_download_file: boolean\r\n show_delete_file: boolean\r\n show_choose_file: boolean\r\n show_new_folder: boolean\r\n show_upload_file: boolean\r\n ignore_file_select_event: boolean\r\n}\r\n\r\nconst noticeStreamlit = (event: StreamlitEvent) =>\r\n Streamlit.setComponentValue(event)\r\n\r\n \r\nclass FileBrowserNative extends StreamlitComponentBase {\r\n private args: IArgs\r\n\r\n constructor(props: ComponentProps) {\r\n super(props)\r\n this.args = props.args\r\n }\r\n\r\n ajustHeight(revoke_step?: number) {\r\n const root = document.getElementById(\"root\")\r\n if (root) {\r\n const height = Math.min(\r\n root.clientHeight,\r\n root.scrollHeight,\r\n root.offsetHeight\r\n )\r\n Streamlit.setFrameHeight(height - (revoke_step ? revoke_step : 0))\r\n setTimeout(Streamlit.setFrameHeight, 1)\r\n }\r\n }\r\n\r\n componentDidMount() {\r\n this.ajustHeight()\r\n }\r\n\r\n componentDidUpdate() {\r\n this.ajustHeight()\r\n }\r\n\r\n folderOpenHandler = (opts: FileBrowserFolder) => this.ajustHeight()\r\n folderCloseHandler = (opts: FileBrowserFolder) => this.ajustHeight()\r\n\r\n fileSelectedHandler = (opts: FileBrowserFile) => {\r\n if (!this.args.ignore_file_select_event) {\r\n const file = this.args.files.find((file) => file.path === opts.key)\r\n file &&\r\n noticeStreamlit({ type: StreamlitEventType.SELECT_FILE, target: file })\r\n }\r\n }\r\n\r\n deleteFileHandler = (fileKey: string | string[]) => {\r\n const files = this.args.files.filter((file) => typeof fileKey === 'string' ? fileKey === file.path : fileKey.includes(file.path))\r\n console.log(\"deleteFileHandler\", \"key\", fileKey, \"files \", files)\r\n\r\n files.length &&\r\n noticeStreamlit({ type: StreamlitEventType.DELETE_FILE, target: files })\r\n\r\n const remainingFiles = this.args.files.filter((file) => typeof fileKey === 'string' ? fileKey !== file.path : !fileKey.includes(file.path))\r\n this.args.files = remainingFiles\r\n }\r\n\r\n chooseHandler = (keys: string[]) => {\r\n const files = this.args.files.filter((file) => keys.includes(file.path))\r\n files.length &&\r\n noticeStreamlit({ type: StreamlitEventType.CHOOSE_FILE, target: files })\r\n }\r\n\r\n convertFiles = (files: File[]): FileBrowserFile[] =>\r\n files.map((file) => ({\r\n key: file.path,\r\n modified: file.update_time || 0,\r\n size: file.size || 0,\r\n }))\r\n\r\n noop = () => <>\r\n public render = () => {\r\n let that = this\r\n return (\r\n
    \r\n {\r\n return Actions({\r\n ...args[0],\r\n ...{\r\n canChooseFile: that.args.show_choose_file,\r\n canDownloadFile: false,\r\n canDeleteFile: that.args.show_delete_file,\r\n onChooseFile: (keys: string[]) =>\r\n that.chooseHandler(\r\n args[0].selectedItems.map((i: any) => i.key)\r\n ),\r\n onDeleteFile: (fileKey: string[]) =>\r\n that.deleteFileHandler(\r\n args[0].selectedItems.map((i: any) => i.key)\r\n ),\r\n },\r\n })\r\n }}\r\n />\r\n
    \r\n )\r\n }\r\n}\r\nconst StreamlitFileBrowserNative = withStreamlitConnection(FileBrowserNative)\r\n\r\nclass FileBrowserWrapper extends StreamlitComponentBase {\r\n private args: IArgs\r\n \r\n constructor(props: ComponentProps) {\r\n super(props)\r\n this.args = props.args\r\n }\r\n\r\n public render(): React.ReactNode {\r\n return (\r\n
    \r\n \r\n
    \r\n )\r\n }\r\n}\r\n\r\nexport default withStreamlitConnection(FileBrowserWrapper)\r\n","import React from \"react\"\r\nimport ReactDOM from \"react-dom\"\r\nimport StFileBrowser from \"./StFileBrowser\"\r\n\r\nReactDOM.render(\r\n \r\n \r\n ,\r\n document.getElementById(\"root\")\r\n)\r\n"],"sourceRoot":""} \ No newline at end of file diff --git a/st_file_browser/frontend/src/StFileBrowser.tsx b/st_file_browser/frontend/src/StFileBrowser.tsx index f39ff76..ef8b79a 100644 --- a/st_file_browser/frontend/src/StFileBrowser.tsx +++ b/st_file_browser/frontend/src/StFileBrowser.tsx @@ -54,11 +54,7 @@ interface State { interface IArgs { files: File[] path: string - show_download_file: boolean - show_delete_file: boolean show_choose_file: boolean - show_new_folder: boolean - show_upload_file: boolean ignore_file_select_event: boolean } @@ -106,23 +102,6 @@ class FileBrowserNative extends StreamlitComponentBase { } } - deleteFileHandler = (fileKey: string | string[]) => { - const files = this.args.files.filter((file) => typeof fileKey === 'string' ? fileKey === file.path : fileKey.includes(file.path)) - console.log("deleteFileHandler", "key", fileKey, "files ", files) - - files.length && - noticeStreamlit({ type: StreamlitEventType.DELETE_FILE, target: files }) - - const remainingFiles = this.args.files.filter((file) => typeof fileKey === 'string' ? fileKey !== file.path : !fileKey.includes(file.path)) - this.args.files = remainingFiles - } - - chooseHandler = (keys: string[]) => { - const files = this.args.files.filter((file) => keys.includes(file.path)) - files.length && - noticeStreamlit({ type: StreamlitEventType.CHOOSE_FILE, target: files }) - } - convertFiles = (files: File[]): FileBrowserFile[] => files.map((file) => ({ key: file.path, @@ -145,22 +124,11 @@ class FileBrowserNative extends StreamlitComponentBase { onFolderOpen={this.folderOpenHandler} onFolderClose={this.folderCloseHandler} onSelect={this.fileSelectedHandler} - onDeleteFile={this.deleteFileHandler} actionRenderer={(...args: any) => { return Actions({ ...args[0], ...{ canChooseFile: that.args.show_choose_file, - canDownloadFile: false, - canDeleteFile: that.args.show_delete_file, - onChooseFile: (keys: string[]) => - that.chooseHandler( - args[0].selectedItems.map((i: any) => i.key) - ), - onDeleteFile: (fileKey: string[]) => - that.deleteFileHandler( - args[0].selectedItems.map((i: any) => i.key) - ), }, }) }}