@deephaven/file-explorer 0.5.1 → 0.5.2-allpackages.16

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.
@@ -1,47 +1,19 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
-
7
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
8
-
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
-
11
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
12
-
13
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
-
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
-
17
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
-
19
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
2
 
21
3
  import { ValidationError } from '@deephaven/utils';
22
4
 
23
- var FileExistsError = /*#__PURE__*/function (_ValidationError) {
24
- _inherits(FileExistsError, _ValidationError);
25
-
26
- var _super = _createSuper(FileExistsError);
27
-
28
- function FileExistsError(info) {
29
- var _this;
30
-
31
- _classCallCheck(this, FileExistsError);
32
-
33
- _this = _super.call(this, 'Name already exists');
5
+ class FileExistsError extends ValidationError {
6
+ constructor(info) {
7
+ super('Name already exists');
34
8
 
35
- _defineProperty(_assertThisInitialized(_this), "isExistingFile", true);
9
+ _defineProperty(this, "isExistingFile", true);
36
10
 
37
- _defineProperty(_assertThisInitialized(_this), "info", void 0);
11
+ _defineProperty(this, "info", void 0);
38
12
 
39
- _this.info = info;
40
- return _this;
13
+ this.info = info;
41
14
  }
42
15
 
43
- return FileExistsError;
44
- }(ValidationError);
16
+ }
45
17
 
46
18
  export default FileExistsError;
47
19
  //# sourceMappingURL=FileExistsError.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/FileExistsError.ts"],"names":["ValidationError","FileExistsError","info"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAASA,eAAT,QAAgC,kBAAhC;;IAGMC,e;;;;;AAKJ,2BAAYC,IAAZ,EAAmC;AAAA;;AAAA;;AACjC,8BAAM,qBAAN;;AADiC,qEAJlB,IAIkB;;AAAA;;AAEjC,UAAKA,IAAL,GAAYA,IAAZ;AAFiC;AAGlC;;;EAR2BF,e;;AAW9B,eAAeC,eAAf","sourcesContent":["import { ValidationError } from '@deephaven/utils';\nimport { FileStorageItem } from './FileStorage';\n\nclass FileExistsError extends ValidationError {\n isExistingFile = true;\n\n info: FileStorageItem;\n\n constructor(info: FileStorageItem) {\n super('Name already exists');\n this.info = info;\n }\n}\n\nexport default FileExistsError;\n"],"file":"FileExistsError.js"}
1
+ {"version":3,"sources":["../src/FileExistsError.ts"],"names":["ValidationError","FileExistsError","constructor","info"],"mappings":";;AAAA,SAASA,eAAT,QAAgC,kBAAhC;;AAGA,MAAMC,eAAN,SAA8BD,eAA9B,CAA8C;AAK5CE,EAAAA,WAAW,CAACC,IAAD,EAAwB;AACjC,UAAM,qBAAN;;AADiC,4CAJlB,IAIkB;;AAAA;;AAEjC,SAAKA,IAAL,GAAYA,IAAZ;AACD;;AAR2C;;AAW9C,eAAeF,eAAf","sourcesContent":["import { ValidationError } from '@deephaven/utils';\nimport { FileStorageItem } from './FileStorage';\n\nclass FileExistsError extends ValidationError {\n isExistingFile = true;\n\n info: FileStorageItem;\n\n constructor(info: FileStorageItem) {\n super('Name already exists');\n this.info = info;\n }\n}\n\nexport default FileExistsError;\n"],"file":"FileExistsError.js"}
@@ -2,61 +2,34 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
2
2
 
3
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
4
 
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
-
7
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
-
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
-
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
-
17
5
  import { BasicModal } from '@deephaven/components';
18
6
  import Log from '@deephaven/log';
19
7
  import { PromiseUtils } from '@deephaven/utils';
20
8
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
21
- import { DEFAULT_ROW_HEIGHT } from './FileList';
22
- import { isDirectory } from './FileStorage';
9
+ import { DEFAULT_ROW_HEIGHT } from "./FileList.js";
10
+ import { isDirectory } from "./FileStorage.js";
23
11
  import "./FileExplorer.css";
24
- import FileListContainer from './FileListContainer';
25
- import FileUtils from './FileUtils';
26
- import FileExistsError from './FileExistsError';
27
- import FileNotFoundError from './FileNotFoundError';
12
+ import FileListContainer from "./FileListContainer.js";
13
+ import FileUtils from "./FileUtils.js";
14
+ import FileExistsError from "./FileExistsError.js";
15
+ import FileNotFoundError from "./FileNotFoundError.js";
28
16
  var log = Log.module('FileExplorer');
29
17
 
30
18
  /**
31
19
  * Component that displays and allows interaction with the file system in the provided FileStorage.
32
20
  */
33
- export var FileExplorer = function FileExplorer(props) {
34
- var storage = props.storage,
35
- _props$isMultiSelect = props.isMultiSelect,
36
- isMultiSelect = _props$isMultiSelect === void 0 ? false : _props$isMultiSelect,
37
- _props$onDelete = props.onDelete,
38
- onDelete = _props$onDelete === void 0 ? function () {
39
- return undefined;
40
- } : _props$onDelete,
41
- _props$onRename = props.onRename,
42
- onRename = _props$onRename === void 0 ? function () {
43
- return undefined;
44
- } : _props$onRename,
45
- onSelect = props.onSelect,
46
- _props$rowHeight = props.rowHeight,
47
- rowHeight = _props$rowHeight === void 0 ? DEFAULT_ROW_HEIGHT : _props$rowHeight;
48
-
49
- var _useState = useState([]),
50
- _useState2 = _slicedToArray(_useState, 2),
51
- itemsToDelete = _useState2[0],
52
- setItemsToDelete = _useState2[1];
53
-
54
- var _useState3 = useState(),
55
- _useState4 = _slicedToArray(_useState3, 2),
56
- table = _useState4[0],
57
- setTable = _useState4[1];
58
-
59
- useEffect(function () {
21
+ export var FileExplorer = props => {
22
+ var {
23
+ storage,
24
+ isMultiSelect = false,
25
+ onDelete = () => undefined,
26
+ onRename = () => undefined,
27
+ onSelect,
28
+ rowHeight = DEFAULT_ROW_HEIGHT
29
+ } = props;
30
+ var [itemsToDelete, setItemsToDelete] = useState([]);
31
+ var [table, setTable] = useState();
32
+ useEffect(() => {
60
33
  var tablePromise;
61
34
 
62
35
  function initTable() {
@@ -64,84 +37,57 @@ export var FileExplorer = function FileExplorer(props) {
64
37
  }
65
38
 
66
39
  function _initTable() {
67
- _initTable = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
68
- return regeneratorRuntime.wrap(function _callee$(_context) {
69
- while (1) {
70
- switch (_context.prev = _context.next) {
71
- case 0:
72
- log.debug('initTable');
73
- tablePromise = PromiseUtils.makeCancelable(storage.getTable(), function (t) {
74
- return t.close();
75
- });
76
- _context.prev = 2;
77
- _context.t0 = setTable;
78
- _context.next = 6;
79
- return tablePromise;
80
-
81
- case 6:
82
- _context.t1 = _context.sent;
83
- (0, _context.t0)(_context.t1);
84
- _context.next = 13;
85
- break;
86
-
87
- case 10:
88
- _context.prev = 10;
89
- _context.t2 = _context["catch"](2);
90
-
91
- if (!PromiseUtils.isCanceled(_context.t2)) {
92
- log.error('Unable to initialize table', _context.t2);
93
- }
94
-
95
- case 13:
96
- case "end":
97
- return _context.stop();
98
- }
40
+ _initTable = _asyncToGenerator(function* () {
41
+ log.debug('initTable');
42
+ tablePromise = PromiseUtils.makeCancelable(storage.getTable(), t => t.close());
43
+
44
+ try {
45
+ setTable(yield tablePromise);
46
+ } catch (e) {
47
+ if (!PromiseUtils.isCanceled(e)) {
48
+ log.error('Unable to initialize table', e);
99
49
  }
100
- }, _callee, null, [[2, 10]]);
101
- }));
50
+ }
51
+ });
102
52
  return _initTable.apply(this, arguments);
103
53
  }
104
54
 
105
55
  initTable();
106
- return function () {
56
+ return () => {
107
57
  tablePromise.cancel();
108
58
  };
109
59
  }, [storage]);
110
- var handleError = useCallback(function (e) {
60
+ var handleError = useCallback(e => {
111
61
  if (!PromiseUtils.isCanceled(e)) {
112
62
  log.error(e);
113
63
  }
114
64
  }, []);
115
- var handleDelete = useCallback(function (files) {
65
+ var handleDelete = useCallback(files => {
116
66
  log.debug('handleDelete, pending confirmation', files);
117
67
  setItemsToDelete(files);
118
68
  }, []);
119
- var handleDeleteConfirm = useCallback(function () {
69
+ var handleDeleteConfirm = useCallback(() => {
120
70
  log.debug('handleDeleteConfirm', itemsToDelete);
121
- itemsToDelete.forEach(function (file) {
122
- return storage.deleteFile(isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename);
123
- });
71
+ itemsToDelete.forEach(file => storage.deleteFile(isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename));
124
72
  onDelete(itemsToDelete);
125
73
  setItemsToDelete([]);
126
74
  }, [itemsToDelete, onDelete, storage]);
127
- var handleDeleteCancel = useCallback(function () {
75
+ var handleDeleteCancel = useCallback(() => {
128
76
  log.debug('handleDeleteCancel');
129
77
  setItemsToDelete([]);
130
78
  }, []);
131
- var handleMove = useCallback(function (files, path) {
132
- var filesToMove = FileUtils.reducePaths(files.map(function (file) {
133
- return isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename;
134
- }));
135
- filesToMove.forEach(function (file) {
79
+ var handleMove = useCallback((files, path) => {
80
+ var filesToMove = FileUtils.reducePaths(files.map(file => isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename));
81
+ filesToMove.forEach(file => {
136
82
  var newFile = FileUtils.isPath(file) ? "".concat(path).concat(FileUtils.getBaseName(file.substring(0, file.length - 1)), "/") : "".concat(path).concat(FileUtils.getBaseName(file));
137
- storage.moveFile(file, newFile).then(function () {
83
+ storage.moveFile(file, newFile).then(() => {
138
84
  // Each moved file triggers a rename so parent knows something has happened
139
85
  // We signal each individually if for some reason there's an error moving one of the files
140
86
  onRename(file, newFile);
141
- })["catch"](handleError);
87
+ }).catch(handleError);
142
88
  });
143
89
  }, [handleError, onRename, storage]);
144
- var handleRename = useCallback(function (item, newName) {
90
+ var handleRename = useCallback((item, newName) => {
145
91
  var name = item.filename;
146
92
  var isDir = isDirectory(item);
147
93
 
@@ -156,59 +102,36 @@ export var FileExplorer = function FileExplorer(props) {
156
102
  }
157
103
 
158
104
  log.debug2('handleRename', name, destination);
159
- storage.moveFile(name, destination)["catch"](handleError);
105
+ storage.moveFile(name, destination).catch(handleError);
160
106
  onRename(name, destination);
161
107
  }, [handleError, onRename, storage]);
162
108
  var handleValidateRename = useCallback( /*#__PURE__*/function () {
163
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(renameItem, newName) {
164
- var newValue, fileInfo;
165
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
166
- while (1) {
167
- switch (_context2.prev = _context2.next) {
168
- case 0:
169
- if (!(newName === renameItem.basename)) {
170
- _context2.next = 2;
171
- break;
172
- }
173
-
174
- return _context2.abrupt("return", undefined);
175
-
176
- case 2:
177
- FileUtils.validateName(newName);
178
- newValue = "".concat(FileUtils.getPath(renameItem.filename)).concat(newName);
179
- _context2.prev = 4;
180
- _context2.next = 7;
181
- return storage.info(newValue);
182
-
183
- case 7:
184
- fileInfo = _context2.sent;
185
- throw new FileExistsError(fileInfo);
186
-
187
- case 11:
188
- _context2.prev = 11;
189
- _context2.t0 = _context2["catch"](4);
190
-
191
- if (_context2.t0 instanceof FileNotFoundError) {
192
- _context2.next = 15;
193
- break;
194
- }
195
-
196
- throw _context2.t0;
197
-
198
- case 15:
199
- case "end":
200
- return _context2.stop();
201
- }
202
- }
203
- }, _callee2, null, [[4, 11]]);
204
- }));
109
+ var _ref = _asyncToGenerator(function* (renameItem, newName) {
110
+ if (newName === renameItem.basename) {
111
+ // Same name is fine
112
+ return undefined;
113
+ }
114
+
115
+ FileUtils.validateName(newName);
116
+ var newValue = "".concat(FileUtils.getPath(renameItem.filename)).concat(newName);
117
+
118
+ try {
119
+ var fileInfo = yield storage.info(newValue);
120
+ throw new FileExistsError(fileInfo);
121
+ } catch (e) {
122
+ if (!(e instanceof FileNotFoundError)) {
123
+ throw e;
124
+ } // The file does not exist, fine to save at that path
125
+
126
+ }
127
+ });
205
128
 
206
129
  return function (_x, _x2) {
207
130
  return _ref.apply(this, arguments);
208
131
  };
209
132
  }(), [storage]);
210
133
  var isDeleteConfirmationShown = itemsToDelete.length > 0;
211
- var deleteConfirmationMessage = useMemo(function () {
134
+ var deleteConfirmationMessage = useMemo(() => {
212
135
  if (itemsToDelete.length === 1) {
213
136
  return "Are you sure you want to delete \"".concat(itemsToDelete[0].filename, "\"?");
214
137
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/FileExplorer.tsx"],"names":["BasicModal","Log","PromiseUtils","React","useCallback","useEffect","useMemo","useState","DEFAULT_ROW_HEIGHT","isDirectory","FileListContainer","FileUtils","FileExistsError","FileNotFoundError","log","module","FileExplorer","props","storage","isMultiSelect","onDelete","undefined","onRename","onSelect","rowHeight","itemsToDelete","setItemsToDelete","table","setTable","tablePromise","initTable","debug","makeCancelable","getTable","t","close","isCanceled","error","cancel","handleError","e","handleDelete","files","handleDeleteConfirm","forEach","file","deleteFile","makePath","filename","handleDeleteCancel","handleMove","path","filesToMove","reducePaths","map","newFile","isPath","getBaseName","substring","length","moveFile","then","handleRename","item","newName","name","isDir","endsWith","destination","getParent","debug2","handleValidateRename","renameItem","basename","validateName","newValue","getPath","info","fileInfo","isDeleteConfirmationShown","deleteConfirmationMessage","displayName"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAASA,UAAT,QAA2B,uBAA3B;AACA,OAAOC,GAAP,MAAgB,gBAAhB;AACA,SAA4BC,YAA5B,QAAgD,kBAAhD;AACA,OAAOC,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,OAAxC,EAAiDC,QAAjD,QAAiE,OAAjE;AACA,SAASC,kBAAT,QAAmC,YAAnC;AACA,SAGEC,WAHF,QAIO,eAJP;AAKA;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,SAAP,MAAsB,aAAtB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AAEA,IAAMC,GAAG,GAAGb,GAAG,CAACc,MAAJ,CAAW,cAAX,CAAZ;;AAeA;AACA;AACA;AACA,OAAO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD,EAA2C;AACrE,MACEC,OADF,GAOID,KAPJ,CACEC,OADF;AAAA,6BAOID,KAPJ,CAEEE,aAFF;AAAA,MAEEA,aAFF,qCAEkB,KAFlB;AAAA,wBAOIF,KAPJ,CAGEG,QAHF;AAAA,MAGEA,QAHF,gCAGa;AAAA,WAAMC,SAAN;AAAA,GAHb;AAAA,wBAOIJ,KAPJ,CAIEK,QAJF;AAAA,MAIEA,QAJF,gCAIa;AAAA,WAAMD,SAAN;AAAA,GAJb;AAAA,MAKEE,QALF,GAOIN,KAPJ,CAKEM,QALF;AAAA,yBAOIN,KAPJ,CAMEO,SANF;AAAA,MAMEA,SANF,iCAMchB,kBANd;;AAQA,kBAA0CD,QAAQ,CAAoB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,QAAQ,EAAEvC,QANZ;AAOE,IAAA,SAAS,EAAEC,SAPb;AAQE,IAAA,KAAK,EAAEG,KART;AASE,IAAA,cAAc,EAAE4C;AATlB,IAFJ,eAcE,oBAAC,UAAD;AACE,IAAA,MAAM,EAAEQ,yBADV;AAEE,IAAA,UAAU,EAAEC,yBAFd;AAGE,IAAA,QAAQ,EAAC,8BAHX;AAIE,IAAA,QAAQ,EAAE/B,kBAJZ;AAKE,IAAA,SAAS,EAAEN,mBALb;AAME,IAAA,iBAAiB,EAAC;AANpB,IAdF,CADF;AAyBD,CAlKM;AAoKP3B,YAAY,CAACiE,WAAb,GAA2B,cAA3B;AAEA,eAAejE,YAAf","sourcesContent":["import { BasicModal } from '@deephaven/components';\nimport Log from '@deephaven/log';\nimport { CancelablePromise, PromiseUtils } from '@deephaven/utils';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { DEFAULT_ROW_HEIGHT } from './FileList';\nimport FileStorage, {\n FileStorageItem,\n FileStorageTable,\n isDirectory,\n} from './FileStorage';\nimport './FileExplorer.scss';\nimport FileListContainer from './FileListContainer';\nimport FileUtils from './FileUtils';\nimport FileExistsError from './FileExistsError';\nimport FileNotFoundError from './FileNotFoundError';\n\nconst log = Log.module('FileExplorer');\n\nexport interface FileExplorerProps {\n storage: FileStorage;\n\n isMultiSelect?: boolean;\n\n onDelete?: (files: FileStorageItem[]) => void;\n onRename?: (oldName: string, newName: string) => void;\n onSelect: (file: FileStorageItem) => void;\n\n /** Height of each item in the list */\n rowHeight?: number;\n}\n\n/**\n * Component that displays and allows interaction with the file system in the provided FileStorage.\n */\nexport const FileExplorer = (props: FileExplorerProps): JSX.Element => {\n const {\n storage,\n isMultiSelect = false,\n onDelete = () => undefined,\n onRename = () => undefined,\n onSelect,\n rowHeight = DEFAULT_ROW_HEIGHT,\n } = props;\n const [itemsToDelete, setItemsToDelete] = useState<FileStorageItem[]>([]);\n const [table, setTable] = useState<FileStorageTable>();\n\n useEffect(() => {\n let tablePromise: CancelablePromise<FileStorageTable>;\n async function initTable() {\n log.debug('initTable');\n\n tablePromise = PromiseUtils.makeCancelable(storage.getTable(), t =>\n t.close()\n );\n\n try {\n setTable(await tablePromise);\n } catch (e) {\n if (!PromiseUtils.isCanceled(e)) {\n log.error('Unable to initialize table', e);\n }\n }\n }\n initTable();\n return () => {\n tablePromise.cancel();\n };\n }, [storage]);\n\n const handleError = useCallback((e: Error) => {\n if (!PromiseUtils.isCanceled(e)) {\n log.error(e);\n }\n }, []);\n\n const handleDelete = useCallback((files: FileStorageItem[]) => {\n log.debug('handleDelete, pending confirmation', files);\n setItemsToDelete(files);\n }, []);\n\n const handleDeleteConfirm = useCallback(() => {\n log.debug('handleDeleteConfirm', itemsToDelete);\n itemsToDelete.forEach(file =>\n storage.deleteFile(\n isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename\n )\n );\n onDelete(itemsToDelete);\n setItemsToDelete([]);\n }, [itemsToDelete, onDelete, storage]);\n\n const handleDeleteCancel = useCallback(() => {\n log.debug('handleDeleteCancel');\n setItemsToDelete([]);\n }, []);\n\n const handleMove = useCallback(\n (files: FileStorageItem[], path: string) => {\n const filesToMove = FileUtils.reducePaths(\n files.map(file =>\n isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename\n )\n );\n\n filesToMove.forEach(file => {\n const newFile = FileUtils.isPath(file)\n ? `${path}${FileUtils.getBaseName(\n file.substring(0, file.length - 1)\n )}/`\n : `${path}${FileUtils.getBaseName(file)}`;\n storage\n .moveFile(file, newFile)\n .then(() => {\n // Each moved file triggers a rename so parent knows something has happened\n // We signal each individually if for some reason there's an error moving one of the files\n onRename(file, newFile);\n })\n .catch(handleError);\n });\n },\n [handleError, onRename, storage]\n );\n\n const handleRename = useCallback(\n (item: FileStorageItem, newName: string) => {\n let name = item.filename;\n const isDir = isDirectory(item);\n if (isDir && !name.endsWith('/')) {\n name = `${name}/`;\n }\n let destination = `${FileUtils.getParent(name)}${newName}`;\n if (isDir && !destination.endsWith('/')) {\n destination = `${destination}/`;\n }\n log.debug2('handleRename', name, destination);\n storage.moveFile(name, destination).catch(handleError);\n onRename(name, destination);\n },\n [handleError, onRename, storage]\n );\n\n const handleValidateRename = useCallback(\n async (renameItem: FileStorageItem, newName: string): Promise<void> => {\n if (newName === renameItem.basename) {\n // Same name is fine\n return undefined;\n }\n FileUtils.validateName(newName);\n\n const newValue = `${FileUtils.getPath(renameItem.filename)}${newName}`;\n try {\n const fileInfo = await storage.info(newValue);\n throw new FileExistsError(fileInfo);\n } catch (e) {\n if (!(e instanceof FileNotFoundError)) {\n throw e;\n }\n // The file does not exist, fine to save at that path\n }\n },\n [storage]\n );\n\n const isDeleteConfirmationShown = itemsToDelete.length > 0;\n const deleteConfirmationMessage = useMemo(() => {\n if (itemsToDelete.length === 1) {\n return `Are you sure you want to delete \"${itemsToDelete[0].filename}\"?`;\n }\n return `Are you sure you want to delete the selected files?`;\n }, [itemsToDelete]);\n\n return (\n <div className=\"file-explorer\">\n {table && (\n <FileListContainer\n isMultiSelect={isMultiSelect}\n showContextMenu\n onMove={handleMove}\n onDelete={handleDelete}\n onRename={handleRename}\n onSelect={onSelect}\n rowHeight={rowHeight}\n table={table}\n validateRename={handleValidateRename}\n />\n )}\n <BasicModal\n isOpen={isDeleteConfirmationShown}\n headerText={deleteConfirmationMessage}\n bodyText=\"You cannot undo this action.\"\n onCancel={handleDeleteCancel}\n onConfirm={handleDeleteConfirm}\n confirmButtonText=\"Delete\"\n />\n </div>\n );\n};\n\nFileExplorer.displayName = 'FileExplorer';\n\nexport default FileExplorer;\n"],"file":"FileExplorer.js"}
1
+ {"version":3,"sources":["../src/FileExplorer.tsx"],"names":["BasicModal","Log","PromiseUtils","React","useCallback","useEffect","useMemo","useState","DEFAULT_ROW_HEIGHT","isDirectory","FileListContainer","FileUtils","FileExistsError","FileNotFoundError","log","module","FileExplorer","props","storage","isMultiSelect","onDelete","undefined","onRename","onSelect","rowHeight","itemsToDelete","setItemsToDelete","table","setTable","tablePromise","initTable","debug","makeCancelable","getTable","t","close","e","isCanceled","error","cancel","handleError","handleDelete","files","handleDeleteConfirm","forEach","file","deleteFile","makePath","filename","handleDeleteCancel","handleMove","path","filesToMove","reducePaths","map","newFile","isPath","getBaseName","substring","length","moveFile","then","catch","handleRename","item","newName","name","isDir","endsWith","destination","getParent","debug2","handleValidateRename","renameItem","basename","validateName","newValue","getPath","fileInfo","info","isDeleteConfirmationShown","deleteConfirmationMessage","displayName"],"mappings":";;;;AAAA,SAASA,UAAT,QAA2B,uBAA3B;AACA,OAAOC,GAAP,MAAgB,gBAAhB;AACA,SAA4BC,YAA5B,QAAgD,kBAAhD;AACA,OAAOC,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,OAAxC,EAAiDC,QAAjD,QAAiE,OAAjE;SACSC,kB;SAIPC,W;;OAGKC,iB;OACAC,S;OACAC,e;OACAC,iB;AAEP,IAAMC,GAAG,GAAGb,GAAG,CAACc,MAAJ,CAAW,cAAX,CAAZ;;AAeA;AACA;AACA;AACA,OAAO,IAAMC,YAAY,GAAIC,KAAD,IAA2C;AACrE,MAAM;AACJC,IAAAA,OADI;AAEJC,IAAAA,aAAa,GAAG,KAFZ;AAGJC,IAAAA,QAAQ,GAAG,MAAMC,SAHb;AAIJC,IAAAA,QAAQ,GAAG,MAAMD,SAJb;AAKJE,IAAAA,QALI;AAMJC,IAAAA,SAAS,GAAGhB;AANR,MAOFS,KAPJ;AAQA,MAAM,CAACQ,aAAD,EAAgBC,gBAAhB,IAAoCnB,QAAQ,CAAoB,EAApB,CAAlD;AACA,MAAM,CAACoB,KAAD,EAAQC,QAAR,IAAoBrB,QAAQ,EAAlC;AAEAF,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIwB,YAAJ;;AADc,aAECC,SAFD;AAAA;AAAA;;AAAA;AAAA,qCAEd,aAA2B;AACzBhB,QAAAA,GAAG,CAACiB,KAAJ,CAAU,WAAV;AAEAF,QAAAA,YAAY,GAAG3B,YAAY,CAAC8B,c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ancelablePromise, PromiseUtils } from '@deephaven/utils';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { DEFAULT_ROW_HEIGHT } from './FileList';\nimport FileStorage, {\n FileStorageItem,\n FileStorageTable,\n isDirectory,\n} from './FileStorage';\nimport './FileExplorer.scss';\nimport FileListContainer from './FileListContainer';\nimport FileUtils from './FileUtils';\nimport FileExistsError from './FileExistsError';\nimport FileNotFoundError from './FileNotFoundError';\n\nconst log = Log.module('FileExplorer');\n\nexport interface FileExplorerProps {\n storage: FileStorage;\n\n isMultiSelect?: boolean;\n\n onDelete?: (files: FileStorageItem[]) => void;\n onRename?: (oldName: string, newName: string) => void;\n onSelect: (file: FileStorageItem) => void;\n\n /** Height of each item in the list */\n rowHeight?: number;\n}\n\n/**\n * Component that displays and allows interaction with the file system in the provided FileStorage.\n */\nexport const FileExplorer = (props: FileExplorerProps): JSX.Element => {\n const {\n storage,\n isMultiSelect = false,\n onDelete = () => undefined,\n onRename = () => undefined,\n onSelect,\n rowHeight = DEFAULT_ROW_HEIGHT,\n } = props;\n const [itemsToDelete, setItemsToDelete] = useState<FileStorageItem[]>([]);\n const [table, setTable] = useState<FileStorageTable>();\n\n useEffect(() => {\n let tablePromise: CancelablePromise<FileStorageTable>;\n async function initTable() {\n log.debug('initTable');\n\n tablePromise = PromiseUtils.makeCancelable(storage.getTable(), t =>\n t.close()\n );\n\n try {\n setTable(await tablePromise);\n } catch (e) {\n if (!PromiseUtils.isCanceled(e)) {\n log.error('Unable to initialize table', e);\n }\n }\n }\n initTable();\n return () => {\n tablePromise.cancel();\n };\n }, [storage]);\n\n const handleError = useCallback((e: Error) => {\n if (!PromiseUtils.isCanceled(e)) {\n log.error(e);\n }\n }, []);\n\n const handleDelete = useCallback((files: FileStorageItem[]) => {\n log.debug('handleDelete, pending confirmation', files);\n setItemsToDelete(files);\n }, []);\n\n const handleDeleteConfirm = useCallback(() => {\n log.debug('handleDeleteConfirm', itemsToDelete);\n itemsToDelete.forEach(file =>\n storage.deleteFile(\n isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename\n )\n );\n onDelete(itemsToDelete);\n setItemsToDelete([]);\n }, [itemsToDelete, onDelete, storage]);\n\n const handleDeleteCancel = useCallback(() => {\n log.debug('handleDeleteCancel');\n setItemsToDelete([]);\n }, []);\n\n const handleMove = useCallback(\n (files: FileStorageItem[], path: string) => {\n const filesToMove = FileUtils.reducePaths(\n files.map(file =>\n isDirectory(file) ? FileUtils.makePath(file.filename) : file.filename\n )\n );\n\n filesToMove.forEach(file => {\n const newFile = FileUtils.isPath(file)\n ? `${path}${FileUtils.getBaseName(\n file.substring(0, file.length - 1)\n )}/`\n : `${path}${FileUtils.getBaseName(file)}`;\n storage\n .moveFile(file, newFile)\n .then(() => {\n // Each moved file triggers a rename so parent knows something has happened\n // We signal each individually if for some reason there's an error moving one of the files\n onRename(file, newFile);\n })\n .catch(handleError);\n });\n },\n [handleError, onRename, storage]\n );\n\n const handleRename = useCallback(\n (item: FileStorageItem, newName: string) => {\n let name = item.filename;\n const isDir = isDirectory(item);\n if (isDir && !name.endsWith('/')) {\n name = `${name}/`;\n }\n let destination = `${FileUtils.getParent(name)}${newName}`;\n if (isDir && !destination.endsWith('/')) {\n destination = `${destination}/`;\n }\n log.debug2('handleRename', name, destination);\n storage.moveFile(name, destination).catch(handleError);\n onRename(name, destination);\n },\n [handleError, onRename, storage]\n );\n\n const handleValidateRename = useCallback(\n async (renameItem: FileStorageItem, newName: string): Promise<void> => {\n if (newName === renameItem.basename) {\n // Same name is fine\n return undefined;\n }\n FileUtils.validateName(newName);\n\n const newValue = `${FileUtils.getPath(renameItem.filename)}${newName}`;\n try {\n const fileInfo = await storage.info(newValue);\n throw new FileExistsError(fileInfo);\n } catch (e) {\n if (!(e instanceof FileNotFoundError)) {\n throw e;\n }\n // The file does not exist, fine to save at that path\n }\n },\n [storage]\n );\n\n const isDeleteConfirmationShown = itemsToDelete.length > 0;\n const deleteConfirmationMessage = useMemo(() => {\n if (itemsToDelete.length === 1) {\n return `Are you sure you want to delete \"${itemsToDelete[0].filename}\"?`;\n }\n return `Are you sure you want to delete the selected files?`;\n }, [itemsToDelete]);\n\n return (\n <div className=\"file-explorer\">\n {table && (\n <FileListContainer\n isMultiSelect={isMultiSelect}\n showContextMenu\n onMove={handleMove}\n onDelete={handleDelete}\n onRename={handleRename}\n onSelect={onSelect}\n rowHeight={rowHeight}\n table={table}\n validateRename={handleValidateRename}\n />\n )}\n <BasicModal\n isOpen={isDeleteConfirmationShown}\n headerText={deleteConfirmationMessage}\n bodyText=\"You cannot undo this action.\"\n onCancel={handleDeleteCancel}\n onConfirm={handleDeleteConfirm}\n confirmButtonText=\"Delete\"\n />\n </div>\n );\n};\n\nFileExplorer.displayName = 'FileExplorer';\n\nexport default FileExplorer;\n"],"file":"FileExplorer.js"}
@@ -15,6 +15,6 @@ var FILE_EXPLORER = {
15
15
  })
16
16
  };
17
17
  export default {
18
- FILE_EXPLORER: FILE_EXPLORER
18
+ FILE_EXPLORER
19
19
  };
20
20
  //# sourceMappingURL=FileExplorerShortcuts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/FileExplorerShortcuts.ts"],"names":["ShortcutRegistry","KEY","MODIFIER","FILE_EXPLORER","name","DELETE","createAndAdd","id","shortcut","macShortcut","CMD","BACKSPACE","RENAME","ENTER"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,GAA3B,EAAgCC,QAAhC,QAAgD,uBAAhD;AAEA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,IAAI,EAAE,eADc;AAEpBC,EAAAA,MAAM,EAAEL,gBAAgB,CAACM,YAAjB,CAA8B;AACpCC,IAAAA,EAAE,EAAE,sBADgC;AAEpCH,IAAAA,IAAI,EAAE,QAF8B;AAGpCI,IAAAA,QAAQ,EAAE,CAACP,GAAG,CAACI,MAAL,CAH0B;AAIpCI,IAAAA,WAAW,EAAE,CAACP,QAAQ,CAACQ,GAAV,EAAeT,GAAG,CAACU,SAAnB;AAJuB,GAA9B,CAFY;AAQpBC,EAAAA,MAAM,EAAEZ,gBAAgB,CAACM,YAAjB,CAA8B;AACpCC,IAAAA,EAAE,EAAE,sBADgC;AAEpCH,IAAAA,IAAI,EAAE,QAF8B;AAGpCI,IAAAA,QAAQ,EAAE,CAACP,GAAG,CAACY,KAAL,CAH0B;AAIpCJ,IAAAA,WAAW,EAAE,CAACR,GAAG,CAACY,KAAL;AAJuB,GAA9B;AARY,CAAtB;AAgBA,eAAe;AACbV,EAAAA,aAAa,EAAbA;AADa,CAAf","sourcesContent":["import { ShortcutRegistry, KEY, MODIFIER } from '@deephaven/components';\n\nconst FILE_EXPLORER = {\n name: 'File Explorer',\n DELETE: ShortcutRegistry.createAndAdd({\n id: 'FILE_EXPLORER.DELETE',\n name: 'Delete',\n shortcut: [KEY.DELETE],\n macShortcut: [MODIFIER.CMD, KEY.BACKSPACE],\n }),\n RENAME: ShortcutRegistry.createAndAdd({\n id: 'FILE_EXPLORER.RENAME',\n name: 'Rename',\n shortcut: [KEY.ENTER],\n macShortcut: [KEY.ENTER],\n }),\n};\n\nexport default {\n FILE_EXPLORER,\n};\n"],"file":"FileExplorerShortcuts.js"}
1
+ {"version":3,"sources":["../src/FileExplorerShortcuts.ts"],"names":["ShortcutRegistry","KEY","MODIFIER","FILE_EXPLORER","name","DELETE","createAndAdd","id","shortcut","macShortcut","CMD","BACKSPACE","RENAME","ENTER"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,GAA3B,EAAgCC,QAAhC,QAAgD,uBAAhD;AAEA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,IAAI,EAAE,eADc;AAEpBC,EAAAA,MAAM,EAAEL,gBAAgB,CAACM,YAAjB,CAA8B;AACpCC,IAAAA,EAAE,EAAE,sBADgC;AAEpCH,IAAAA,IAAI,EAAE,QAF8B;AAGpCI,IAAAA,QAAQ,EAAE,CAACP,GAAG,CAACI,MAAL,CAH0B;AAIpCI,IAAAA,WAAW,EAAE,CAACP,QAAQ,CAACQ,GAAV,EAAeT,GAAG,CAACU,SAAnB;AAJuB,GAA9B,CAFY;AAQpBC,EAAAA,MAAM,EAAEZ,gBAAgB,CAACM,YAAjB,CAA8B;AACpCC,IAAAA,EAAE,EAAE,sBADgC;AAEpCH,IAAAA,IAAI,EAAE,QAF8B;AAGpCI,IAAAA,QAAQ,EAAE,CAACP,GAAG,CAACY,KAAL,CAH0B;AAIpCJ,IAAAA,WAAW,EAAE,CAACR,GAAG,CAACY,KAAL;AAJuB,GAA9B;AARY,CAAtB;AAgBA,eAAe;AACbV,EAAAA;AADa,CAAf","sourcesContent":["import { ShortcutRegistry, KEY, MODIFIER } from '@deephaven/components';\n\nconst FILE_EXPLORER = {\n name: 'File Explorer',\n DELETE: ShortcutRegistry.createAndAdd({\n id: 'FILE_EXPLORER.DELETE',\n name: 'Delete',\n shortcut: [KEY.DELETE],\n macShortcut: [MODIFIER.CMD, KEY.BACKSPACE],\n }),\n RENAME: ShortcutRegistry.createAndAdd({\n id: 'FILE_EXPLORER.RENAME',\n name: 'Rename',\n shortcut: [KEY.ENTER],\n macShortcut: [KEY.ENTER],\n }),\n};\n\nexport default {\n FILE_EXPLORER,\n};\n"],"file":"FileExplorerShortcuts.js"}
@@ -2,12 +2,13 @@ import React from 'react';
2
2
  import { Button, DebouncedSearchInput } from '@deephaven/components';
3
3
  import { vsNewFile, vsNewFolder } from '@deephaven/icons';
4
4
  import "./FileExplorerToolbar.css";
5
- export var FileExplorerToolbar = function FileExplorerToolbar(_ref) {
6
- var createFile = _ref.createFile,
7
- createFolder = _ref.createFolder,
8
- onSearchChange = _ref.onSearchChange,
9
- _ref$defaultSearchTex = _ref.defaultSearchText,
10
- defaultSearchText = _ref$defaultSearchTex === void 0 ? '' : _ref$defaultSearchTex;
5
+ export var FileExplorerToolbar = (_ref) => {
6
+ var {
7
+ createFile,
8
+ createFolder,
9
+ onSearchChange,
10
+ defaultSearchText = ''
11
+ } = _ref;
11
12
  return /*#__PURE__*/React.createElement("div", {
12
13
  className: "file-explorer-toolbar"
13
14
  }, /*#__PURE__*/React.createElement("div", {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/FileExplorerToolbar.tsx"],"names":["React","Button","DebouncedSearchInput","vsNewFile","vsNewFolder","FileExplorerToolbar","createFile","createFolder","onSearchChange","defaultSearchText"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,MAAT,EAAiBC,oBAAjB,QAA6C,uBAA7C;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,kBAAvC;AACA;AASA,OAAO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB;AAAA,MACjCC,UADiC,QACjCA,UADiC;AAAA,MAEjCC,YAFiC,QAEjCA,YAFiC;AAAA,MAGjCC,cAHiC,QAGjCA,cAHiC;AAAA,mCAIjCC,iBAJiC;AAAA,MAIjCA,iBAJiC,sCAIb,EAJa;AAAA,sBAMjC;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE,oBAAC,MAAD;AACE,IAAA,IAAI,EAAC,OADP;AAEE,IAAA,IAAI,EAAEN,SAFR;AAGE,IAAA,OAAO,EAAC,cAHV;AAIE,IAAA,OAAO,EAAEG;AAJX,IADF,eAOE,oBAAC,MAAD;AACE,IAAA,IAAI,EAAC,OADP;AAEE,IAAA,IAAI,EAAEF,WAFR;AAGE,IAAA,OAAO,EAAC,YAHV;AAIE,IAAA,OAAO,EAAEG;AAJX,IAPF,CADF,EAeGC,cAAc,iBACb;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE,oBAAC,oBAAD;AACE,IAAA,KAAK,EAAEC,iBADT;AAEE,IAAA,QAAQ,EAAED,cAFZ;AAGE,IAAA,WAAW,EAAC;AAHd,IADF,CAhBJ,CANiC;AAAA,CAA5B;AAiCP,eAAeH,mBAAf","sourcesContent":["import React from 'react';\nimport { Button, DebouncedSearchInput } from '@deephaven/components';\nimport { vsNewFile, vsNewFolder } from '@deephaven/icons';\nimport './FileExplorerToolbar.scss';\n\ntype FileExplorerToolbarProps = {\n createFile(): void;\n createFolder(): void;\n onSearchChange?(text: string): void;\n defaultSearchText?: string;\n};\n\nexport const FileExplorerToolbar = ({\n createFile,\n createFolder,\n onSearchChange,\n defaultSearchText = '',\n}: FileExplorerToolbarProps): JSX.Element => (\n <div className=\"file-explorer-toolbar\">\n <div className=\"file-explorer-toolbar-buttons\">\n <Button\n kind=\"ghost\"\n icon={vsNewFile}\n tooltip=\"New notebook\"\n onClick={createFile}\n />\n <Button\n kind=\"ghost\"\n icon={vsNewFolder}\n tooltip=\"New folder\"\n onClick={createFolder}\n />\n </div>\n {onSearchChange && (\n <div className=\"file-explorer-toolbar-search\">\n <DebouncedSearchInput\n value={defaultSearchText}\n onChange={onSearchChange}\n placeholder=\"Search by name\"\n />\n </div>\n )}\n </div>\n);\n\nexport default FileExplorerToolbar;\n"],"file":"FileExplorerToolbar.js"}
1
+ {"version":3,"sources":["../src/FileExplorerToolbar.tsx"],"names":["React","Button","DebouncedSearchInput","vsNewFile","vsNewFolder","FileExplorerToolbar","createFile","createFolder","onSearchChange","defaultSearchText"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,MAAT,EAAiBC,oBAAjB,QAA6C,uBAA7C;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,kBAAvC;;AAUA,OAAO,IAAMC,mBAAmB,GAAG;AAAA,MAAC;AAClCC,IAAAA,UADkC;AAElCC,IAAAA,YAFkC;AAGlCC,IAAAA,cAHkC;AAIlCC,IAAAA,iBAAiB,GAAG;AAJc,GAAD;AAAA,sBAMjC;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE,oBAAC,MAAD;AACE,IAAA,IAAI,EAAC,OADP;AAEE,IAAA,IAAI,EAAEN,SAFR;AAGE,IAAA,OAAO,EAAC,cAHV;AAIE,IAAA,OAAO,EAAEG;AAJX,IADF,eAOE,oBAAC,MAAD;AACE,IAAA,IAAI,EAAC,OADP;AAEE,IAAA,IAAI,EAAEF,WAFR;AAGE,IAAA,OAAO,EAAC,YAHV;AAIE,IAAA,OAAO,EAAEG;AAJX,IAPF,CADF,EAeGC,cAAc,iBACb;AAAK,IAAA,SAAS,EAAC;AAAf,kBACE,oBAAC,oBAAD;AACE,IAAA,KAAK,EAAEC,iBADT;AAEE,IAAA,QAAQ,EAAED,cAFZ;AAGE,IAAA,WAAW,EAAC;AAHd,IADF,CAhBJ,CANiC;AAAA,CAA5B;AAiCP,eAAeH,mBAAf","sourcesContent":["import React from 'react';\nimport { Button, DebouncedSearchInput } from '@deephaven/components';\nimport { vsNewFile, vsNewFolder } from '@deephaven/icons';\nimport './FileExplorerToolbar.scss';\n\ntype FileExplorerToolbarProps = {\n createFile(): void;\n createFolder(): void;\n onSearchChange?(text: string): void;\n defaultSearchText?: string;\n};\n\nexport const FileExplorerToolbar = ({\n createFile,\n createFolder,\n onSearchChange,\n defaultSearchText = '',\n}: FileExplorerToolbarProps): JSX.Element => (\n <div className=\"file-explorer-toolbar\">\n <div className=\"file-explorer-toolbar-buttons\">\n <Button\n kind=\"ghost\"\n icon={vsNewFile}\n tooltip=\"New notebook\"\n onClick={createFile}\n />\n <Button\n kind=\"ghost\"\n icon={vsNewFolder}\n tooltip=\"New folder\"\n onClick={createFolder}\n />\n </div>\n {onSearchChange && (\n <div className=\"file-explorer-toolbar-search\">\n <DebouncedSearchInput\n value={defaultSearchText}\n onChange={onSearchChange}\n placeholder=\"Search by name\"\n />\n </div>\n )}\n </div>\n);\n\nexport default FileExplorerToolbar;\n"],"file":"FileExplorerToolbar.js"}