@putkoff/abstract-utilities 0.1.105 → 0.1.107

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/dist/cjs/index.js CHANGED
@@ -4,86 +4,6 @@ var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
 
6
6
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
-
24
- function __rest(s, e) {
25
- var t = {};
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
27
- t[p] = s[p];
28
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
29
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
31
- t[p[i]] = s[p[i]];
32
- }
33
- return t;
34
- }
35
-
36
- function __awaiter(thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- }
45
-
46
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
47
- var e = new Error(message);
48
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
49
- };
50
-
51
- /** Helper function to trigger file download */
52
- function triggerDownload(blob, filename) {
53
- const url = URL.createObjectURL(blob);
54
- const a = Object.assign(document.createElement("a"), {
55
- href: url,
56
- download: filename,
57
- });
58
- document.body.appendChild(a);
59
- a.click();
60
- a.remove();
61
- URL.revokeObjectURL(url);
62
- console.log(`✅ Successfully downloaded: ${filename}`);
63
- }
64
-
65
- /** Non-React “direct download” used by some old links (kept for parity) */
66
- function directDownload(relPath, filename) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const token = localStorage.getItem("token");
69
- if (!token)
70
- throw new Error("No auth token found");
71
- const res = yield fetch("/secure-files/download", {
72
- method: "POST",
73
- headers: {
74
- Authorization: `Bearer ${token}`,
75
- "Content-Type": "application/json",
76
- Accept: "application/octet-stream",
77
- },
78
- body: JSON.stringify({ rel_path: relPath }),
79
- });
80
- if (!res.ok)
81
- throw new Error(`Download failed: ${res.status}`);
82
- const blob = yield res.blob();
83
- triggerDownload(blob, filename);
84
- });
85
- }
86
-
87
7
  /**
88
8
  ***Changes**:
89
9
  *- Updated import path for `InputProps` to `../../types/interfaces`.
@@ -180,6 +100,105 @@ function decodeJwt(token) {
180
100
  return JSON.parse(jsonText);
181
101
  }
182
102
 
103
+ const PROTOCOL = 'https://';
104
+ const DOMAIN_NAME = 'abstractendeavors';
105
+ const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
106
+ const SUB_DIR = 'secure-files';
107
+ const PROD_PREFIX = `/${SUB_DIR}/`;
108
+ const API_PREFIX = `/${SUB_DIR}/api`;
109
+ const DEV_PREFIX = `/${SUB_DIR}-dev/`;
110
+
111
+ function get_window() {
112
+ try {
113
+ if (typeof window !== 'undefined') {
114
+ return window;
115
+ }
116
+ }
117
+ catch (err) {
118
+ alert(err);
119
+ }
120
+ return null;
121
+ }
122
+ function get_window_location() {
123
+ try {
124
+ const Window = get_window();
125
+ if (!Window) {
126
+ return BASE_URL;
127
+ }
128
+ return Window.location;
129
+ }
130
+ catch (err) {
131
+ alert(err);
132
+ }
133
+ return null;
134
+ }
135
+ function get_window_pathname() {
136
+ try {
137
+ const Window = get_window();
138
+ if (!Window) {
139
+ return DEV_PREFIX;
140
+ }
141
+ return Window.location.pathname;
142
+ }
143
+ catch (err) {
144
+ alert(err);
145
+ }
146
+ return null;
147
+ }
148
+ function get_window_parts() {
149
+ try {
150
+ return get_window_location();
151
+ }
152
+ catch (err) {
153
+ alert(err);
154
+ }
155
+ return null;
156
+ }
157
+
158
+ /******************************************************************************
159
+ Copyright (c) Microsoft Corporation.
160
+
161
+ Permission to use, copy, modify, and/or distribute this software for any
162
+ purpose with or without fee is hereby granted.
163
+
164
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
165
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
166
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
167
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
168
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
169
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
170
+ PERFORMANCE OF THIS SOFTWARE.
171
+ ***************************************************************************** */
172
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
173
+
174
+
175
+ function __rest(s, e) {
176
+ var t = {};
177
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
178
+ t[p] = s[p];
179
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
180
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
181
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
182
+ t[p[i]] = s[p[i]];
183
+ }
184
+ return t;
185
+ }
186
+
187
+ function __awaiter(thisArg, _arguments, P, generator) {
188
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
189
+ return new (P || (P = Promise))(function (resolve, reject) {
190
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
191
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
192
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
193
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
194
+ });
195
+ }
196
+
197
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
198
+ var e = new Error(message);
199
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
200
+ };
201
+
183
202
  function assertPath(path) {
184
203
  if (typeof path !== 'string') {
185
204
  throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
@@ -1213,336 +1232,6 @@ function fetchSharePatch(file) {
1213
1232
  });
1214
1233
  }
1215
1234
 
1216
- function downloadFile(item) {
1217
- return __awaiter(this, void 0, void 0, function* () {
1218
- const token = requireToken();
1219
- const { filepath, filename } = item;
1220
- const body = { rel_path: filepath };
1221
- const headers = {
1222
- Authorization: `Bearer ${token}`,
1223
- Accept: "application/octet-stream",
1224
- "Content-Type": "application/json"
1225
- };
1226
- const blob = yield secureFetchIt("download", body, "POST", headers, true, true);
1227
- if (!blob || blob.size === 0) {
1228
- throw new Error(`Received empty file data for “${filename}”`);
1229
- }
1230
- triggerDownload(blob, filename);
1231
- });
1232
- }
1233
-
1234
- function downloadSelect(relPath, filename) {
1235
- return __awaiter(this, void 0, void 0, function* () {
1236
- const token = requireToken();
1237
- const body = { rel_path: relPath };
1238
- const headers = {
1239
- Authorization: `Bearer ${token}`,
1240
- Accept: "application/octet-stream",
1241
- "Content-Type": "application/json"
1242
- };
1243
- const blob = yield secureFetchIt("download", body, "POST", headers, true, true);
1244
- if (!blob || blob.size === 0) {
1245
- throw new Error(`Received empty file data for “${filename}”`);
1246
- }
1247
- triggerDownload(blob, filename);
1248
- });
1249
- }
1250
-
1251
- /** Given a checkbox inside a table-row → download that row’s file. */
1252
- function downloadRow(cb) {
1253
- return __awaiter(this, void 0, void 0, function* () {
1254
- var _a, _b;
1255
- const row = cb.closest("tr");
1256
- const relPath = cb.value;
1257
- const filename = ((_b = (_a = row === null || row === void 0 ? void 0 : row.children[1]) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || "downloaded_file";
1258
- if (relPath)
1259
- yield downloadSelect(relPath, filename);
1260
- });
1261
- }
1262
- /** Bulk download: pass a NodeList or array of checkboxes. */
1263
- function downloadSelected(checkboxes) {
1264
- return __awaiter(this, void 0, void 0, function* () {
1265
- const list = Array.from(checkboxes);
1266
- if (!list.length) {
1267
- alert("No files selected.");
1268
- return;
1269
- }
1270
- for (const cb of list) {
1271
- yield downloadRow(cb);
1272
- }
1273
- });
1274
- }
1275
-
1276
- /**
1277
- * Classic “select all rows” logic (still handy in non-React views
1278
- * such as the admin dashboard).
1279
- */
1280
- function syncHeaderCheckbox() {
1281
- const all = document.querySelectorAll(".file-checkbox");
1282
- const checked = document.querySelectorAll(".file-checkbox:checked");
1283
- const header = document.getElementById("select-all-checkbox");
1284
- header.indeterminate =
1285
- checked.length > 0 && checked.length < all.length;
1286
- header.checked = checked.length === all.length;
1287
- }
1288
-
1289
- /** Wire up header + row checkboxes once the table is in the DOM. */
1290
- function initSelectAll() {
1291
- const header = document.getElementById("select-all-checkbox");
1292
- const btn = document.getElementById("select-all");
1293
- // 1) header → toggle all
1294
- header.addEventListener("change", (e) => {
1295
- const on = e.target.checked;
1296
- document
1297
- .querySelectorAll(".file-checkbox")
1298
- .forEach((cb) => (cb.checked = on));
1299
- });
1300
- // 2) button → toggle all
1301
- btn.addEventListener("click", () => {
1302
- const cbs = Array.from(document.querySelectorAll(".file-checkbox"));
1303
- if (!cbs.length) {
1304
- alert("No files to select.");
1305
- return;
1306
- }
1307
- const anyUnchecked = cbs.some((cb) => !cb.checked);
1308
- cbs.forEach((cb) => (cb.checked = anyUnchecked));
1309
- syncHeaderCheckbox();
1310
- });
1311
- // 3) row boxes → keep header state
1312
- document
1313
- .querySelectorAll(".file-checkbox")
1314
- .forEach((cb) => cb.addEventListener("change", syncHeaderCheckbox));
1315
- syncHeaderCheckbox();
1316
- }
1317
-
1318
- /** Utility for other screens: toggle a list of checkboxes on/off. */
1319
- function toggleCheckboxes(cbs) {
1320
- if (!cbs.length) {
1321
- alert("No files to select.");
1322
- return;
1323
- }
1324
- const anyUnchecked = cbs.some((cb) => !cb.checked);
1325
- cbs.forEach((cb) => (cb.checked = anyUnchecked));
1326
- syncHeaderCheckbox();
1327
- }
1328
-
1329
- /** Generic PATCH helper kept for other admin forms */
1330
- function patchFileSetting(fileId, field, value) {
1331
- return __awaiter(this, void 0, void 0, function* () {
1332
- const res = yield fetch(`/files/${fileId}/settings/${field}`, {
1333
- method: "PATCH",
1334
- headers: { "Content-Type": "application/json" },
1335
- body: JSON.stringify({ value }),
1336
- });
1337
- if (!res.ok) {
1338
- const err = yield res.json();
1339
- throw new Error(err.error || res.statusText);
1340
- }
1341
- return (yield res.json());
1342
- });
1343
- }
1344
-
1345
- /** Classic file-upload for the fallback HTML page. */
1346
- function uploadFile(file, subdir) {
1347
- return __awaiter(this, void 0, void 0, function* () {
1348
- var _a, _b;
1349
- const fileInput = file || document.getElementById("file-browser");
1350
- const subdirInput = subdir || document.getElementById("subdir");
1351
- const banner = document.getElementById("banner");
1352
- if (!((_a = fileInput.files) === null || _a === void 0 ? void 0 : _a.length)) {
1353
- alert("No file selected.");
1354
- return;
1355
- }
1356
- const formData = new FormData();
1357
- formData.append("file", fileInput.files[0]);
1358
- formData.append("subdir", subdirInput.value.trim());
1359
- try {
1360
- const json = yield secureFetchIt("upload", formData, "POST", null, false, true);
1361
- banner.textContent = `Uploaded: ${json.filepath}`;
1362
- fileInput.value = "";
1363
- subdirInput.value = "";
1364
- window.location.reload(); // no-op in React view
1365
- }
1366
- catch (err) {
1367
- console.error("Upload failed", err);
1368
- alert((_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : "Upload failed.");
1369
- }
1370
- });
1371
- }
1372
-
1373
- function uploadFiles(file_1) {
1374
- return __awaiter(this, arguments, void 0, function* (file, subdir = '') {
1375
- var _a;
1376
- if (!(file instanceof File)) {
1377
- throw new Error('Invalid file: Must be a File object.');
1378
- }
1379
- if (typeof subdir !== 'string') {
1380
- throw new Error('Invalid subdir: Must be a string.');
1381
- }
1382
- const formData = new FormData();
1383
- formData.append('file', file);
1384
- formData.append('subdir', subdir.trim());
1385
- try {
1386
- const json = yield secureFetchIt('upload', formData, 'POST', null, false, false);
1387
- if (!json || typeof json !== 'object') {
1388
- throw new Error('Invalid response from server.');
1389
- }
1390
- if (!('filepath' in json) || typeof json.filepath !== 'string' || !json.filepath) {
1391
- throw new Error('Server response missing or invalid filepath.');
1392
- }
1393
- return { filepath: json.filepath };
1394
- }
1395
- catch (err) {
1396
- throw new Error(`Upload failed: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error'}`);
1397
- }
1398
- });
1399
- }
1400
-
1401
- function removeFile(item) {
1402
- return __awaiter(this, void 0, void 0, function* () {
1403
- const token = requireToken();
1404
- const body = item;
1405
- const headers = {
1406
- Authorization: `Bearer ${token}`,
1407
- Accept: "application/octet-stream",
1408
- "Content-Type": "application/json"
1409
- };
1410
- const resp = yield secureFetchIt("remove", body, "POST", headers, false, true);
1411
- if (!resp || resp === false || (resp === null || resp === void 0 ? void 0 : resp.result) === false) {
1412
- throw new Error(`could not delete data: “${item.filename}”`);
1413
- }
1414
- });
1415
- }
1416
-
1417
- /** Bulk download: pass a NodeList or array of checkboxes. */
1418
- function removeSelected(checkboxes) {
1419
- return __awaiter(this, void 0, void 0, function* () {
1420
- const list = Array.from(checkboxes);
1421
- if (!list.length) {
1422
- alert("No files selected.");
1423
- return;
1424
- }
1425
- for (const cb of list) {
1426
- yield removeFile(cb);
1427
- }
1428
- });
1429
- }
1430
-
1431
- /** Given a checkbox inside a table-row → download that row’s file. */
1432
- function removeRow(cb) {
1433
- return __awaiter(this, void 0, void 0, function* () {
1434
- const row = cb.closest("tr");
1435
- alertit(row);
1436
- if (row && (row === null || row === void 0 ? void 0 : row.id))
1437
- yield removeFile(row);
1438
- });
1439
- }
1440
-
1441
- /** GET /secure-list */
1442
- function listFiles() {
1443
- return __awaiter(this, arguments, void 0, function* (setFiles = null) {
1444
- /** ← your request already returns the raw array */
1445
- const apiRows = yield secureFetchIt("list", null, "GET", null, false, true);
1446
- /** map API → UI ------------------------------------------------ */
1447
- const rows = apiRows.map((r) => ({
1448
- id: r.id,
1449
- filename: r.filename,
1450
- uploader_id: r.uploader_id,
1451
- filepath: r.filepath,
1452
- created_at: r.created_at,
1453
- download_count: r.download_count,
1454
- download_limit: r.download_limit,
1455
- shareable: Boolean(r.shareable),
1456
- needsPassword: !!r.share_password,
1457
- share_password: r.share_password,
1458
- }));
1459
- setFiles(rows);
1460
- });
1461
- }
1462
-
1463
- function getToggleShare(file) {
1464
- if (file == true || (file === null || file === void 0 ? void 0 : file.shareable) == true) {
1465
- return false;
1466
- }
1467
- return false;
1468
- }
1469
- function updateFileShare(file) {
1470
- let updated = file;
1471
- const boolIt = getToggleShare(updated);
1472
- updated = Object.assign(Object.assign({}, file), { shareable: boolIt });
1473
- return updated;
1474
- }
1475
- /**
1476
- * Custom hook to toggle share settings on a file item
1477
- */
1478
- function toggleShare(file) {
1479
- return __awaiter(this, void 0, void 0, function* () {
1480
- const updated = updateFileShare(file);
1481
- try {
1482
- const resp = yield fetchSharePatch(updated);
1483
- }
1484
- catch (err) {
1485
- console.error('Failed to toggle share settings', err);
1486
- // Optionally revert UI state or show an error message
1487
- }
1488
- });
1489
- }
1490
-
1491
- const PROTOCOL = 'https://';
1492
- const DOMAIN_NAME = 'abstractendeavors';
1493
- const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
1494
- const SUB_DIR = 'secure-files';
1495
- const PROD_PREFIX = `/${SUB_DIR}/`;
1496
- const API_PREFIX = `/${SUB_DIR}/api`;
1497
- const DEV_PREFIX = `/${SUB_DIR}-dev/`;
1498
-
1499
- function get_window() {
1500
- try {
1501
- if (typeof window !== 'undefined') {
1502
- return window;
1503
- }
1504
- }
1505
- catch (err) {
1506
- alert(err);
1507
- }
1508
- return null;
1509
- }
1510
- function get_window_location() {
1511
- try {
1512
- const Window = get_window();
1513
- if (!Window) {
1514
- return BASE_URL;
1515
- }
1516
- return Window.location;
1517
- }
1518
- catch (err) {
1519
- alert(err);
1520
- }
1521
- return null;
1522
- }
1523
- function get_window_pathname() {
1524
- try {
1525
- const Window = get_window();
1526
- if (!Window) {
1527
- return DEV_PREFIX;
1528
- }
1529
- return Window.location.pathname;
1530
- }
1531
- catch (err) {
1532
- alert(err);
1533
- }
1534
- return null;
1535
- }
1536
- function get_window_parts() {
1537
- try {
1538
- return get_window_location();
1539
- }
1540
- catch (err) {
1541
- alert(err);
1542
- }
1543
- return null;
1544
- }
1545
-
1546
1235
  function Button(_a) {
1547
1236
  var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
1548
1237
  const base = 'rounded px-3 py-1 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors duration-150';
@@ -1578,132 +1267,14 @@ function Spinner() {
1578
1267
  return (jsxRuntime.jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
1579
1268
  }
1580
1269
 
1581
- /**
1582
- * Custom hook that returns a memoized loadFiles callback
1583
- */
1584
- const useLoadFiles = (setLoading, setError, setFiles) => {
1585
- return react.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
1586
- setLoading(true);
1587
- setError(null);
1588
- try {
1589
- /** ← your request already returns the raw array */
1590
- const apiRows = yield secureFetchIt("list", null, "GET", null, false, true);
1591
- /** map API → UI ------------------------------------------------ */
1592
- const rows = apiRows.map((r) => ({
1593
- id: r.id,
1594
- filename: r.filename,
1595
- uploader_id: r.uploader_id,
1596
- filepath: r.filepath,
1597
- created_at: r.created_at,
1598
- download_count: r.download_count,
1599
- download_limit: r.download_limit,
1600
- shareable: Boolean(r.shareable),
1601
- needsPassword: !!r.share_password,
1602
- share_password: r.share_password,
1603
- }));
1604
- setFiles(rows);
1605
- }
1606
- catch (err) {
1607
- setError(err instanceof Error ? err
1608
- : new Error("Unknown error loading files"));
1609
- }
1610
- finally {
1611
- setLoading(false);
1612
- }
1613
- }), [setLoading, setError, setFiles]);
1614
- };
1615
-
1616
- /**
1617
- * Custom hook to toggle share settings on a file item
1618
- */
1619
- const useToggleShare = (setFiles) => {
1620
- return react.useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
1621
- const updated = Object.assign(Object.assign({}, file), { shareable: !file.shareable });
1622
- if (!updated.shareable) {
1623
- updated.needsPassword = false;
1624
- updated.share_password = null;
1625
- updated.download_limit = null;
1626
- }
1627
- try {
1628
- yield fetchSharePatch(updated);
1629
- setFiles((curr) => curr.map((f) => (f.id === file.id ? updated : f)));
1630
- }
1631
- catch (err) {
1632
- console.error('Failed to toggle share settings', err);
1633
- // Optionally revert UI state or show an error message
1634
- }
1635
- }), [setFiles]);
1636
- };
1637
-
1638
- /**
1639
- * Custom hook for optimistic share-setting patch updates
1640
- */
1641
- /**
1642
- * Custom hook to toggle share settings on a file item
1643
- */
1644
- const usePatchShareSettings = (setFiles) => {
1645
- return react.useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
1646
- if (!file.shareable) {
1647
- file.needsPassword = false;
1648
- file.share_password = null;
1649
- file.download_limit = null;
1650
- }
1651
- try {
1652
- yield fetchSharePatch(file);
1653
- setFiles((curr) => curr.map((f) => (f.id === file.id ? file : f)));
1654
- }
1655
- catch (err) {
1656
- console.error('Failed to toggle share settings', err);
1657
- // Optionally revert UI state or show an error message
1658
- }
1659
- }), [setFiles]);
1660
- };
1661
-
1662
- /**
1663
- * Custom hook to toggle share settings on a file item
1664
- */
1665
- const useDeleteFile = (setFiles) => {
1666
- return react.useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
1667
- try {
1668
- yield removeFile(file);
1669
- window.location.reload();
1670
- }
1671
- catch (err) {
1672
- console.error('Failed to toggle share settings', err);
1673
- // Optionally revert UI state or show an error message
1674
- }
1675
- }), [setFiles]);
1676
- };
1677
-
1678
- function useFiles() {
1679
- const [files, setFiles] = react.useState([]);
1680
- const [loading, setLoading] = react.useState(false);
1681
- const [error, setError] = react.useState(null);
1682
- const loadCallback = useLoadFiles(setLoading, setError, setFiles);
1683
- const toggleShareCallback = useToggleShare(setFiles);
1684
- const patchShareSettingsCallback = usePatchShareSettings(setFiles);
1685
- const deleteFileCallback = useDeleteFile(setFiles);
1686
- react.useEffect(() => {
1687
- loadCallback();
1688
- }, [loadCallback]);
1689
- return {
1690
- files,
1691
- loading,
1692
- error,
1693
- load: loadCallback,
1694
- toggleShare: toggleShareCallback,
1695
- patchShareSettings: patchShareSettingsCallback,
1696
- deleteFile: deleteFileCallback,
1697
- setFiles,
1698
- setLoading,
1699
- setError,
1700
- };
1701
- }
1702
-
1703
1270
  Object.defineProperty(exports, "useCallback", {
1704
1271
  enumerable: true,
1705
1272
  get: function () { return react.useCallback; }
1706
1273
  });
1274
+ Object.defineProperty(exports, "useEffect", {
1275
+ enumerable: true,
1276
+ get: function () { return react.useEffect; }
1277
+ });
1707
1278
  Object.defineProperty(exports, "useRef", {
1708
1279
  enumerable: true,
1709
1280
  get: function () { return react.useRef; }
@@ -1727,11 +1298,6 @@ exports.alertit = alertit;
1727
1298
  exports.currentUsername = currentUsername;
1728
1299
  exports.currentUsernames = currentUsernames;
1729
1300
  exports.decodeJwt = decodeJwt;
1730
- exports.directDownload = directDownload;
1731
- exports.downloadFile = downloadFile;
1732
- exports.downloadRow = downloadRow;
1733
- exports.downloadSelect = downloadSelect;
1734
- exports.downloadSelected = downloadSelected;
1735
1301
  exports.eatAll = eatAll;
1736
1302
  exports.eatEnd = eatEnd;
1737
1303
  exports.eatInner = eatInner;
@@ -1767,7 +1333,6 @@ exports.getSchemasDirPath = getSchemasDirPath;
1767
1333
  exports.getSchemasPath = getSchemasPath;
1768
1334
  exports.getSrcDir = getSrcDir;
1769
1335
  exports.getSubstring = getSubstring;
1770
- exports.getToggleShare = getToggleShare;
1771
1336
  exports.getToken = getToken;
1772
1337
  exports.get_app_config_url = get_app_config_url;
1773
1338
  exports.get_basename = get_basename;
@@ -1779,33 +1344,15 @@ exports.get_window = get_window;
1779
1344
  exports.get_window_location = get_window_location;
1780
1345
  exports.get_window_parts = get_window_parts;
1781
1346
  exports.get_window_pathname = get_window_pathname;
1782
- exports.initSelectAll = initSelectAll;
1783
1347
  exports.isLoggedIn = isLoggedIn;
1784
1348
  exports.isTokenExpired = isTokenExpired;
1785
- exports.listFiles = listFiles;
1786
1349
  exports.make_path = make_path;
1787
1350
  exports.make_sanitized_path = make_sanitized_path;
1788
1351
  exports.normalizeUrl = normalizeUrl;
1789
- exports.patchFileSetting = patchFileSetting;
1790
- exports.removeFile = removeFile;
1791
- exports.removeRow = removeRow;
1792
- exports.removeSelected = removeSelected;
1793
1352
  exports.requestPatch = requestPatch;
1794
1353
  exports.requireToken = requireToken;
1795
1354
  exports.sanitizeFilename = sanitizeFilename;
1796
1355
  exports.secureFetchIt = secureFetchIt;
1797
1356
  exports.stripPrefixes = stripPrefixes;
1798
- exports.syncHeaderCheckbox = syncHeaderCheckbox;
1799
- exports.toggleCheckboxes = toggleCheckboxes;
1800
- exports.toggleShare = toggleShare;
1801
- exports.triggerDownload = triggerDownload;
1802
1357
  exports.truncateString = truncateString;
1803
- exports.updateFileShare = updateFileShare;
1804
- exports.uploadFile = uploadFile;
1805
- exports.uploadFiles = uploadFiles;
1806
- exports.useDeleteFile = useDeleteFile;
1807
- exports.useFiles = useFiles;
1808
- exports.useLoadFiles = useLoadFiles;
1809
- exports.usePatchShareSettings = usePatchShareSettings;
1810
- exports.useToggleShare = useToggleShare;
1811
1358
  //# sourceMappingURL=index.js.map