@burdenoff/microfe-files 2026.1120.1 → 2026.1123.2

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.
Files changed (97) hide show
  1. package/dist/files/FilesRoutes.js +27 -21
  2. package/dist/files/FilesRoutes.js.map +1 -1
  3. package/dist/files/components/CopyDialog.js +12 -12
  4. package/dist/files/components/EmptyState.js +6 -6
  5. package/dist/files/components/EmptyState.js.map +1 -1
  6. package/dist/files/components/FileBrowser.js +4 -4
  7. package/dist/files/components/FileBrowser.js.map +1 -1
  8. package/dist/files/components/FileCard.js +4 -4
  9. package/dist/files/components/FileCard.js.map +1 -1
  10. package/dist/files/components/FileInfoPanel.js +18 -18
  11. package/dist/files/components/FileVersionPanel.js +4 -4
  12. package/dist/files/components/FolderCard.js +4 -4
  13. package/dist/files/components/FolderCard.js.map +1 -1
  14. package/dist/files/components/MoveDialog.js +10 -10
  15. package/dist/files/components/SearchBar.js +7 -7
  16. package/dist/files/components/ShareAccessParts.js +15 -15
  17. package/dist/files/components/ShareDialog.js +27 -27
  18. package/dist/files/components/SharedFolderView.js +9 -9
  19. package/dist/files/components/ToolbarMoreMenu.js +9 -9
  20. package/dist/files/components/UploadQueue.js +30 -30
  21. package/dist/files/components/UploadVisibilitySelect.js +4 -4
  22. package/dist/files/hooks/useCreateFolderShare.d.ts +2 -0
  23. package/dist/files/hooks/useCreateFolderShare.js +1 -1
  24. package/dist/files/hooks/useCreateFolderShare.js.map +1 -1
  25. package/dist/files/hooks/useCreateShare.d.ts +2 -0
  26. package/dist/files/hooks/useCreateShare.js +1 -1
  27. package/dist/files/hooks/useCreateShare.js.map +1 -1
  28. package/dist/files/pages/BrowserPage.js +22 -22
  29. package/dist/files/pages/BrowserPage.js.map +1 -1
  30. package/dist/files/pages/ShareAccessPage.js +4 -4
  31. package/dist/files/pages/ShareAccessPage.js.map +1 -1
  32. package/dist/files/types.d.ts +22 -0
  33. package/dist/files/utils/fileKind.d.ts +6 -0
  34. package/dist/files/utils/fileKind.js +49 -10
  35. package/dist/files/utils/fileKind.js.map +1 -1
  36. package/dist/files/v2/DialogShell.d.ts +28 -0
  37. package/dist/files/v2/DialogShell.js +47 -0
  38. package/dist/files/v2/DialogShell.js.map +1 -0
  39. package/dist/files/v2/FilesDialogs.d.ts +35 -0
  40. package/dist/files/v2/FilesDialogs.js +104 -0
  41. package/dist/files/v2/FilesDialogs.js.map +1 -0
  42. package/dist/files/v2/FilesListParts.d.ts +45 -0
  43. package/dist/files/v2/FilesListParts.js +344 -0
  44. package/dist/files/v2/FilesListParts.js.map +1 -0
  45. package/dist/files/v2/FilesPage.d.ts +15 -0
  46. package/dist/files/v2/FilesPage.js +340 -0
  47. package/dist/files/v2/FilesPage.js.map +1 -0
  48. package/dist/files/v2/FilesPageParts.d.ts +41 -0
  49. package/dist/files/v2/FilesPageParts.js +147 -0
  50. package/dist/files/v2/FilesPageParts.js.map +1 -0
  51. package/dist/files/v2/FilesV2Routes.d.ts +8 -0
  52. package/dist/files/v2/FilesV2Routes.js +41 -0
  53. package/dist/files/v2/FilesV2Routes.js.map +1 -0
  54. package/dist/files/v2/ShareDialogV2.d.ts +10 -0
  55. package/dist/files/v2/ShareDialogV2.js +401 -0
  56. package/dist/files/v2/ShareDialogV2.js.map +1 -0
  57. package/dist/files/v2/UploadDialog.d.ts +14 -0
  58. package/dist/files/v2/UploadDialog.js +171 -0
  59. package/dist/files/v2/UploadDialog.js.map +1 -0
  60. package/dist/files/v2/filesModel.d.ts +164 -0
  61. package/dist/files/v2/filesModel.js +247 -0
  62. package/dist/files/v2/filesModel.js.map +1 -0
  63. package/dist/files/v2/uploadLine.d.ts +36 -0
  64. package/dist/files/v2/uploadLine.js +33 -0
  65. package/dist/files/v2/uploadLine.js.map +1 -0
  66. package/dist/files/v2/useFilesPage.d.ts +28 -0
  67. package/dist/files/v2/useFilesPage.js +118 -0
  68. package/dist/files/v2/useFilesPage.js.map +1 -0
  69. package/dist/files/v2/useFilesV2Actions.d.ts +24 -0
  70. package/dist/files/v2/useFilesV2Actions.js +243 -0
  71. package/dist/files/v2/useFilesV2Actions.js.map +1 -0
  72. package/dist/files/v2/useFilesV2List.d.ts +24 -0
  73. package/dist/files/v2/useFilesV2List.js +159 -0
  74. package/dist/files/v2/useFilesV2List.js.map +1 -0
  75. package/dist/files/v2/useFilesV2Uploads.d.ts +87 -0
  76. package/dist/files/v2/useFilesV2Uploads.js +279 -0
  77. package/dist/files/v2/useFilesV2Uploads.js.map +1 -0
  78. package/dist/files/v2/useNow.d.ts +6 -0
  79. package/dist/files/v2/useNow.js +13 -0
  80. package/dist/files/v2/useNow.js.map +1 -0
  81. package/dist/files/v2/useShareV2.d.ts +39 -0
  82. package/dist/files/v2/useShareV2.js +89 -0
  83. package/dist/files/v2/useShareV2.js.map +1 -0
  84. package/dist/files/v2/whoCanSee.d.ts +9 -0
  85. package/dist/files/v2/whoCanSee.js +48 -0
  86. package/dist/files/v2/whoCanSee.js.map +1 -0
  87. package/dist/generated/global-types.d.ts +450 -6
  88. package/dist/generated/wspace-operations.d.ts +249 -0
  89. package/dist/generated/wspace-operations.js +4631 -1
  90. package/dist/generated/wspace-operations.js.map +1 -1
  91. package/dist/generated/wspace-types.d.ts +6866 -105
  92. package/dist/generated/wspace-types.js +9 -3
  93. package/dist/generated/wspace-types.js.map +1 -1
  94. package/dist/translations/en.d.ts +277 -0
  95. package/dist/translations/en.js +265 -0
  96. package/dist/translations/en.js.map +1 -1
  97. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilesV2Actions.js","names":["message","error","nameProblem","name","value","words","useFilesV2Actions","tr","useTr","navigate","useNavigate","notify","useNotify","confirm","useConfirm","prompt","usePrompt","filesContext","useFilesContext","deleteFile","useDeleteFile","deleteFolder","useDeleteFolder","restoreFile","useRestoreFile","restoreFolder","useRestoreFolder","purgeFile","usePermanentlyDeleteFile","purgeFolder","usePermanentlyDeleteFolder","star","useToggleStar","renameFile","useRenameFile","renameFolder","useRenameFolder","createFolder","useCreateFolder","failed","useCallback","nameWords","restoreOne","row","trashOne","purgeOne","trash","emitFilesEvent","refetch","restore","deleteForever","toggleStar","rename","newFolder","input","folderId","data","isQuotaExhaustedError","download","url","file","anchor","reportBulk","outcome","summarizeFailedNames","settle","byKey","rows","runPerItem","target","run","failedKeys"],"sources":["../../../src/files/v2/useFilesV2Actions.ts"],"sourcesContent":["/**\n * What can be done to the Files page's rows (Workspace pages v2, BOFF-15821).\n *\n * - Move to Trash puts the item back with Undo (the toast) — it is reversible,\n * so it does not ask first. Moving many at once asks once.\n * - Delete forever asks with the shared confirm (BOFF-15689), never the\n * browser's.\n * - Rename and New folder ask for the name with the shared prompt.\n * Every action refreshes the list once the server has answered.\n */\n\nimport { useCallback } from \"react\";\nimport { useNavigate } from \"react-router\";\nimport { useConfirm, useNotify, usePrompt } from \"@burdenoff/fe-libs/ui\";\nimport { useCreateFolder } from \"../hooks/useCreateFolder\";\nimport { useDeleteFile } from \"../hooks/useDeleteFile\";\nimport { useDeleteFolder } from \"../hooks/useDeleteFolder\";\nimport { usePermanentlyDeleteFile } from \"../hooks/usePermanentlyDeleteFile\";\nimport { usePermanentlyDeleteFolder } from \"../hooks/usePermanentlyDeleteFolder\";\nimport { useRenameFile } from \"../hooks/useRenameFile\";\nimport { useRenameFolder } from \"../hooks/useRenameFolder\";\nimport { useRestoreFile } from \"../hooks/useRestoreFile\";\nimport { useRestoreFolder } from \"../hooks/useRestoreFolder\";\nimport { useToggleStar } from \"../hooks/useToggleStar\";\nimport { useFilesContext } from \"../providers/FilesProvider\";\nimport type { FileItem } from \"../types\";\nimport { runPerItem, summarizeFailedNames } from \"../utils/bulkResults\";\nimport { emitFilesEvent } from \"../utils/events\";\nimport { isQuotaExhaustedError } from \"../utils/quotaUtils\";\nimport { useTr } from \"../../shared/hooks/useTr\";\nimport type { FilesRow } from \"./filesModel\";\n\nconst message = (error: unknown) =>\n error instanceof Error && error.message ? error.message : undefined;\n\n/** A file or folder name that the server accepts: no path separators. */\nexport function nameProblem(\n value: string,\n words: { empty: string; slash: string },\n): string | null {\n const name = value.trim();\n if (!name) return words.empty;\n if (/[\\\\/]/.test(name)) return words.slash;\n return null;\n}\n\nexport function useFilesV2Actions({\n refetch,\n folderId,\n}: {\n refetch: () => void;\n /** The folder being browsed, for New folder. */\n folderId: string | undefined;\n}) {\n const tr = useTr();\n const navigate = useNavigate();\n const notify = useNotify();\n const confirm = useConfirm();\n const prompt = usePrompt();\n const filesContext = useFilesContext();\n const deleteFile = useDeleteFile();\n const deleteFolder = useDeleteFolder();\n const restoreFile = useRestoreFile();\n const restoreFolder = useRestoreFolder();\n const purgeFile = usePermanentlyDeleteFile();\n const purgeFolder = usePermanentlyDeleteFolder();\n const star = useToggleStar();\n const renameFile = useRenameFile();\n const renameFolder = useRenameFolder();\n const createFolder = useCreateFolder();\n\n const failed = useCallback(\n (title: string, error: unknown) =>\n notify({\n tone: \"error\",\n title,\n description: message(error),\n urgent: true,\n }),\n [notify],\n );\n\n const nameWords = {\n empty: tr(\"files.v2.name.empty\", \"Give it a name\"),\n slash: tr(\"files.v2.name.slash\", \"A name can’t contain / or \\\\\"),\n };\n\n const restoreOne = useCallback(\n (row: FilesRow) =>\n row.kind === \"file\"\n ? restoreFile.mutateAsync({ id: row.item.id })\n : restoreFolder.mutateAsync({ id: row.item.id }),\n [restoreFile, restoreFolder],\n );\n\n const trashOne = useCallback(\n (row: FilesRow) =>\n row.kind === \"file\"\n ? deleteFile.mutateAsync({ id: row.item.id })\n : deleteFolder.mutateAsync({ id: row.item.id, recursive: true }),\n [deleteFile, deleteFolder],\n );\n\n const purgeOne = useCallback(\n (row: FilesRow) =>\n row.kind === \"file\"\n ? purgeFile.mutateAsync({ id: row.item.id })\n : purgeFolder.mutateAsync({ id: row.item.id }),\n [purgeFile, purgeFolder],\n );\n\n /** Move to Trash, with Undo. */\n const trash = async (row: FilesRow) => {\n try {\n await trashOne(row);\n if (row.kind === \"file\") {\n emitFilesEvent(filesContext, \"files.file.deleted\", {\n fileId: row.item.id,\n fileName: row.item.name,\n permanent: false,\n });\n } else {\n emitFilesEvent(filesContext, \"files.folder.deleted\", {\n folderId: row.item.id,\n folderName: row.item.name,\n permanent: false,\n });\n }\n refetch();\n notify({\n title: tr(\"files.v2.trash.moved\", \"{{name}} moved to the Trash\", {\n name: row.item.name,\n }),\n undo: async () => {\n await restoreOne(row);\n refetch();\n },\n });\n } catch (error) {\n failed(\n tr(\"files.v2.trash.failed\", \"Couldn’t move {{name}} to the Trash\", {\n name: row.item.name,\n }),\n error,\n );\n }\n };\n\n const restore = async (row: FilesRow) => {\n try {\n await restoreOne(row);\n refetch();\n notify({\n tone: \"success\",\n title: tr(\"files.v2.restore.done\", \"{{name}} is back\", {\n name: row.item.name,\n }),\n });\n } catch (error) {\n failed(\n tr(\"files.v2.restore.failed\", \"Couldn’t restore {{name}}\", {\n name: row.item.name,\n }),\n error,\n );\n }\n };\n\n /** Delete forever: the shared confirm first. */\n const deleteForever = async (row: FilesRow) => {\n const ok = await confirm({\n title:\n row.kind === \"folder\"\n ? tr(\"files.v2.purge.titleFolder\", \"Delete “{{name}}” for good?\", {\n name: row.item.name,\n })\n : tr(\"files.v2.purge.titleFile\", \"Delete “{{name}}” for good?\", {\n name: row.item.name,\n }),\n description:\n row.kind === \"folder\"\n ? tr(\n \"files.v2.purge.descriptionFolder\",\n \"The folder and everything in it are gone for everyone, and can’t be brought back.\",\n )\n : tr(\n \"files.v2.purge.descriptionFile\",\n \"It’s gone for everyone, and can’t be brought back.\",\n ),\n tone: \"danger\",\n confirmLabel: tr(\"files.v2.purge.confirm\", \"Delete forever\"),\n });\n if (!ok) return;\n try {\n await purgeOne(row);\n refetch();\n notify({\n tone: \"success\",\n title: tr(\"files.v2.purge.done\", \"{{name}} deleted for good\", {\n name: row.item.name,\n }),\n });\n } catch (error) {\n failed(\n tr(\"files.v2.purge.failed\", \"Couldn’t delete {{name}}\", {\n name: row.item.name,\n }),\n error,\n );\n }\n };\n\n const toggleStar = async (row: FilesRow) => {\n try {\n await star.mutateAsync({ id: row.item.id, type: row.kind });\n refetch();\n } catch (error) {\n failed(\n tr(\"files.v2.star.failed\", \"Couldn’t change the star on {{name}}\", {\n name: row.item.name,\n }),\n error,\n );\n }\n };\n\n const rename = async (row: FilesRow) => {\n const next = await prompt({\n title:\n row.kind === \"folder\"\n ? tr(\"files.v2.rename.titleFolder\", \"Rename folder\")\n : tr(\"files.v2.rename.titleFile\", \"Rename file\"),\n label: tr(\"files.v2.rename.label\", \"Name\"),\n defaultValue: row.item.name,\n submitLabel: tr(\"files.v2.rename.submit\", \"Rename\"),\n maxLength: 255,\n validate: (value) => nameProblem(value, nameWords),\n });\n const name = next?.trim();\n if (!name || name === row.item.name) return;\n try {\n if (row.kind === \"file\") {\n await renameFile.mutateAsync({ fileId: row.item.id, newName: name });\n } else {\n await renameFolder.mutateAsync({\n folderId: row.item.id,\n newName: name,\n });\n }\n refetch();\n notify({\n tone: \"success\",\n title: tr(\"files.v2.rename.done\", \"Renamed to {{name}}\", { name }),\n });\n } catch (error) {\n failed(\n tr(\"files.v2.rename.failed\", \"Couldn’t rename {{name}}\", {\n name: row.item.name,\n }),\n error,\n );\n }\n };\n\n const newFolder = async () => {\n const value = await prompt({\n title: tr(\"files.v2.newFolder.title\", \"New folder\"),\n label: tr(\"files.v2.newFolder.label\", \"Name\"),\n placeholder: tr(\n \"files.v2.newFolder.placeholder\",\n \"For example: Contracts 2027\",\n ),\n submitLabel: tr(\"files.v2.newFolder.submit\", \"Create folder\"),\n maxLength: 255,\n validate: (input) => nameProblem(input, nameWords),\n });\n const name = value?.trim();\n if (!name) return;\n try {\n const { data, error } = await createFolder.mutateAsync({\n name,\n parentFolderId: folderId,\n });\n if (error) throw error;\n if (data) {\n emitFilesEvent(filesContext, \"files.folder.created\", {\n folderName: name,\n parentFolderId: folderId,\n });\n }\n refetch();\n notify({\n tone: \"success\",\n title: tr(\"files.v2.newFolder.done\", \"{{name}} created\", { name }),\n });\n } catch (error) {\n if (isQuotaExhaustedError(error)) {\n const viewBilling = await confirm({\n title: tr(\n \"files.v2.newFolder.quotaTitle\",\n \"You’ve reached your folder limit\",\n ),\n description: tr(\n \"files.v2.newFolder.quotaDescription\",\n \"Upgrade your plan or add folders to your plan to make more.\",\n ),\n confirmLabel: tr(\"files.v2.upload.viewBilling\", \"View billing\"),\n cancelLabel: tr(\"files.v2.common.notNow\", \"Not now\"),\n });\n if (viewBilling) navigate(\"/billing\");\n return;\n }\n failed(\n tr(\"files.v2.newFolder.failed\", \"Couldn’t create the folder\"),\n error,\n );\n }\n };\n\n const download = (file: FileItem) => {\n const url = file.downloadUrl || file.url;\n if (!url) {\n notify({\n tone: \"error\",\n title: tr(\n \"files.v2.download.unavailable\",\n \"This file can’t be downloaded right now\",\n ),\n });\n return;\n }\n const anchor = document.createElement(\"a\");\n anchor.href = url;\n anchor.download = file.name;\n anchor.rel = \"noopener noreferrer\";\n anchor.style.display = \"none\";\n document.body.appendChild(anchor);\n anchor.click();\n anchor.remove();\n emitFilesEvent(filesContext, \"files.file.downloaded\", {\n fileId: file.id,\n fileName: file.name,\n });\n };\n\n /** Settles a bulk action item by item and says what did not work. */\n const reportBulk = (\n outcome: { succeeded: readonly FilesRow[]; failed: readonly FilesRow[] },\n words: { done: string; partial: (names: string) => string },\n ) => {\n refetch();\n if (outcome.failed.length === 0) {\n notify({ tone: \"success\", title: words.done });\n return;\n }\n notify({\n tone: \"error\",\n urgent: true,\n title: words.partial(\n summarizeFailedNames(\n outcome.failed.map((row) => ({\n id: row.item.id,\n name: row.item.name,\n type: row.kind,\n })),\n 3,\n (count) => tr(\"files.v2.bulk.more\", \"+{{count}} more\", { count }),\n ),\n ),\n });\n };\n\n const settle = async (\n rows: readonly FilesRow[],\n run: (row: FilesRow) => Promise<unknown>,\n ) => {\n const byKey = new Map(rows.map((row) => [row.key, row]));\n const outcome = await runPerItem(\n rows.map((row) => ({ id: row.key, name: row.item.name, type: row.kind })),\n (target) => {\n const row = byKey.get(target.id);\n return row ? run(row) : Promise.reject(new Error(\"Not on this page\"));\n },\n );\n const failedKeys = new Set(outcome.failed.map((target) => target.id));\n return {\n succeeded: rows.filter((row) => !failedKeys.has(row.key)),\n failed: rows.filter((row) => failedKeys.has(row.key)),\n };\n };\n\n const bulkTrash = async (rows: readonly FilesRow[]) => {\n const ok = await confirm({\n title: tr(\n \"files.v2.bulk.trashTitle\",\n \"Move {{count}} items to the Trash?\",\n {\n count: rows.length,\n },\n ),\n description: tr(\n \"files.v2.bulk.trashDescription\",\n \"You can bring them back from the Trash.\",\n ),\n confirmLabel: tr(\"files.v2.bulk.trashConfirm\", \"Move to Trash\"),\n });\n if (!ok) return false;\n const outcome = await settle(rows, trashOne);\n reportBulk(outcome, {\n done: tr(\"files.v2.bulk.trashed\", \"{{count}} items moved to the Trash\", {\n count: outcome.succeeded.length,\n }),\n partial: (names) =>\n tr(\n \"files.v2.bulk.trashPartial\",\n \"Moved {{done}} of {{total}}. Couldn’t move {{names}}.\",\n { done: outcome.succeeded.length, total: rows.length, names },\n ),\n });\n return true;\n };\n\n const bulkRestore = async (rows: readonly FilesRow[]) => {\n const outcome = await settle(rows, restoreOne);\n reportBulk(outcome, {\n done: tr(\"files.v2.bulk.restored\", \"{{count}} items are back\", {\n count: outcome.succeeded.length,\n }),\n partial: (names) =>\n tr(\n \"files.v2.bulk.restorePartial\",\n \"Restored {{done}} of {{total}}. Couldn’t restore {{names}}.\",\n { done: outcome.succeeded.length, total: rows.length, names },\n ),\n });\n return true;\n };\n\n const bulkDeleteForever = async (rows: readonly FilesRow[]) => {\n const ok = await confirm({\n title: tr(\n \"files.v2.bulk.purgeTitle\",\n \"Delete {{count}} items for good?\",\n {\n count: rows.length,\n },\n ),\n description: tr(\n \"files.v2.bulk.purgeDescription\",\n \"They’re gone for everyone, and can’t be brought back.\",\n ),\n tone: \"danger\",\n confirmLabel: tr(\"files.v2.purge.confirm\", \"Delete forever\"),\n });\n if (!ok) return false;\n const outcome = await settle(rows, purgeOne);\n reportBulk(outcome, {\n done: tr(\"files.v2.bulk.purged\", \"{{count}} items deleted for good\", {\n count: outcome.succeeded.length,\n }),\n partial: (names) =>\n tr(\n \"files.v2.bulk.purgePartial\",\n \"Deleted {{done}} of {{total}}. Couldn’t delete {{names}}.\",\n { done: outcome.succeeded.length, total: rows.length, names },\n ),\n });\n return true;\n };\n\n return {\n reportFailure: failed,\n trash,\n restore,\n deleteForever,\n toggleStar,\n rename,\n newFolder,\n download,\n bulkTrash,\n bulkRestore,\n bulkDeleteForever,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,IAAMA,KAAW,MACfC,aAAiB,SAASA,EAAM,UAAUA,EAAM,UAAU,KAAA;AAG5D,SAAgBC,EACd,GACA,GACe;CACf,IAAMC,IAAOC,EAAM,KAAK;CAGxB,OAFKD,IACD,QAAQ,KAAKA,CAAI,IAAUE,EAAM,QAC9B,OAFWA,EAAM;AAG1B;AAEA,SAAgBC,EAAkB,EAChC,YACA,eAKC;CACD,IAAMC,IAAKC,EAAM,GACXC,IAAWC,GAAY,GACvBC,IAASC,EAAU,GACnBC,IAAUC,EAAW,GACrBC,IAASC,EAAU,GACnBC,IAAeC,EAAgB,GAC/BC,IAAaC,EAAc,GAC3BC,IAAeC,EAAgB,GAC/BC,IAAcC,EAAe,GAC7BC,IAAgBC,EAAiB,GACjCC,IAAYC,EAAyB,GACrCC,IAAcC,EAA2B,GACzCC,IAAOC,EAAc,GACrBC,IAAaC,EAAc,GAC3BC,IAAeC,EAAgB,GAC/BC,IAAeC,EAAgB,GAE/BC,IAASC,GACZ,GAAe,MACd7B,EAAO;EACL,MAAM;EACN;EACA,aAAaX,EAAQC,CAAK;EAC1B,QAAQ;CACV,CAAC,GACH,CAACU,CAAM,CACT,GAEM8B,IAAY;EAChB,OAAOlC,EAAG,uBAAuB,gBAAgB;EACjD,OAAOA,EAAG,uBAAuB,8BAA8B;CACjE,GAEMmC,IAAaF,GAChB,MACCG,EAAI,SAAS,S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AAU,OAC3B,CAAC;IACD,UAAU,MACRxD,EACE,gCACA,+DACA;KAAE,MAAMwD,EAAQ,UAAU;KAAQ,OAAOI,EAAK;KAAQ;IAAM,CAC9D;GACJ,CAAC,GACM;EACT;EA6CE,0BA3C+B,MAA8B;GAgB7D,IAAI,CAAC,MAfYtD,EAAQ;IACvB,OAAON,EACL,4BACA,oCACA,EACE,OAAO4D,EAAK,OACd,CACF;IACA,aAAa5D,EACX,kCACA,uDACF;IACA,MAAM;IACN,cAAcA,EAAG,0BAA0B,gBAAgB;GAC7D,CAAC,GACQ,OAAO;GAChB,IAAMwD,IAAU,MAAME,EAAOE,GAAMtB,CAAQ;GAY3C,OAXAiB,EAAWC,GAAS;IAClB,MAAMxD,EAAG,wBAAwB,oCAAoC,EACnE,OAAOwD,EAAQ,UAAU,OAC3B,CAAC;IACD,UAAU,MACRxD,EACE,8BACA,6DACA;KAAE,MAAMwD,EAAQ,UAAU;KAAQ,OAAOI,EAAK;KAAQ;IAAM,CAC9D;GACJ,CAAC,GACM;EACT;CAcA;AACF"}
@@ -0,0 +1,24 @@
1
+ import { FilesListQuery, FilesListRequest, FilesRow } from './filesModel';
2
+ export interface FilesV2ListInput extends FilesListQuery {
3
+ /** 1-based, from the address. */
4
+ page: number;
5
+ pageSize: number;
6
+ /** Nothing is asked until the host gave a workspace. */
7
+ skip?: boolean;
8
+ }
9
+ export interface FilesV2List {
10
+ /** The page's rows: folders first, then files. */
11
+ rows: FilesRow[];
12
+ /** Matching folders and files in all; undefined until both halves said. */
13
+ total: number | undefined;
14
+ /** The same, keeping the last count while the next page loads (the count line). */
15
+ shownTotal: number | undefined;
16
+ /** The first answer for these settings has not come yet. */
17
+ loading: boolean;
18
+ /** Either half failed: the page shows the error state, never "empty". */
19
+ error: unknown;
20
+ refetch: () => void;
21
+ /** Where the rows came from (a search looks in every folder). */
22
+ request: FilesListRequest;
23
+ }
24
+ export declare function useFilesV2List(input: FilesV2ListInput): FilesV2List;
@@ -0,0 +1,159 @@
1
+ import { FilesV2FilesDocument as e, FilesV2FoldersDocument as t, FilesV2SearchFilesDocument as n, FilesV2SearchFoldersDocument as r, FilesV2StarredFilesDocument as i, FilesV2StarredFoldersDocument as a } from "../../generated/wspace-operations.js";
2
+ import { fileViewModel as o, folderViewModel as s } from "../utils/fileViewModel.js";
3
+ import { fileRow as c, filesListRequest as l, folderRow as u, joinCombinedPage as d, planCombinedPage as f, searchToSend as p } from "./filesModel.js";
4
+ import { useCallback as m, useMemo as h } from "react";
5
+ import { useQuery as g } from "@apollo/client/react";
6
+ // src/files/v2/useFilesV2List.ts
7
+ var _ = (e) => e ? {
8
+ offset: e.offset,
9
+ limit: e.limit
10
+ } : void 0;
11
+ function v(e, t, n, r) {
12
+ let i = e[t], { list: a, refetch: o } = i;
13
+ return {
14
+ items: h(() => a ? r(a) : void 0, [a, r]),
15
+ total: a?.total,
16
+ shownTotal: a?.total ?? i.previous?.total,
17
+ loading: !n && i.loading,
18
+ error: n ? void 0 : i.error,
19
+ refetch: m(() => {
20
+ n || o();
21
+ }, [n, o])
22
+ };
23
+ }
24
+ var y = (e) => e.folders.map((e) => u(s(e))), b = (e) => e.files.map((e) => c(o(e)));
25
+ function x(e, n, i, o) {
26
+ let s = o || !n, c = g(t, {
27
+ variables: {
28
+ filter: e.folderFilter,
29
+ sort: e.folderSort,
30
+ pagination: _(n)
31
+ },
32
+ skip: s || e.source !== "list"
33
+ }), l = g(a, {
34
+ variables: { pagination: _(n) },
35
+ skip: s || e.source !== "starred"
36
+ }), u = g(r, {
37
+ variables: {
38
+ query: i,
39
+ filter: e.folderFilter,
40
+ pagination: _(n)
41
+ },
42
+ skip: s || e.source !== "search"
43
+ });
44
+ return v({
45
+ list: {
46
+ ...c,
47
+ list: c.data?.getFolders,
48
+ previous: c.previousData?.getFolders
49
+ },
50
+ starred: {
51
+ ...l,
52
+ list: l.data?.getStarredFolders,
53
+ previous: l.previousData?.getStarredFolders
54
+ },
55
+ search: {
56
+ ...u,
57
+ list: u.data?.searchFolders,
58
+ previous: u.previousData?.searchFolders
59
+ }
60
+ }, e.source, s, y);
61
+ }
62
+ function S(t, r, a, o) {
63
+ let s = o || !r, c = g(e, {
64
+ variables: {
65
+ folderId: t.folderId,
66
+ filter: t.fileFilter,
67
+ sort: t.fileSort,
68
+ pagination: _(r)
69
+ },
70
+ skip: s || t.source !== "list"
71
+ }), l = g(i, {
72
+ variables: { pagination: _(r) },
73
+ skip: s || t.source !== "starred"
74
+ }), u = g(n, {
75
+ variables: {
76
+ query: a,
77
+ filter: t.fileFilter,
78
+ pagination: _(r)
79
+ },
80
+ skip: s || t.source !== "search"
81
+ });
82
+ return v({
83
+ list: {
84
+ ...c,
85
+ list: c.data?.getFiles,
86
+ previous: c.previousData?.getFiles
87
+ },
88
+ starred: {
89
+ ...l,
90
+ list: l.data?.getStarredFiles,
91
+ previous: l.previousData?.getStarredFiles
92
+ },
93
+ search: {
94
+ ...u,
95
+ list: u.data?.searchFiles,
96
+ previous: u.previousData?.searchFiles
97
+ }
98
+ }, t.source, s, b);
99
+ }
100
+ function C(e) {
101
+ let { tab: t, folderId: n, search: r, kind: i, visibility: a, sort: o, page: s, pageSize: c } = e, u = e.skip === !0, g = p(r), _ = h(() => l({
102
+ tab: t,
103
+ folderId: n,
104
+ search: g,
105
+ kind: i,
106
+ visibility: a,
107
+ sort: o
108
+ }), [
109
+ t,
110
+ n,
111
+ g,
112
+ i,
113
+ a,
114
+ o
115
+ ]), v = f({
116
+ page: s,
117
+ pageSize: c,
118
+ includeFolders: _.includeFolders,
119
+ includeFiles: _.includeFiles,
120
+ folderTotal: void 0
121
+ }).folders, y = x(_, v, g, u), b = S(_, f({
122
+ page: s,
123
+ pageSize: c,
124
+ includeFolders: _.includeFolders,
125
+ includeFiles: _.includeFiles,
126
+ folderTotal: y.total
127
+ }).files, g, u), { includeFolders: C, includeFiles: w } = _, T = h(() => {
128
+ let e = d({
129
+ page: s,
130
+ pageSize: c,
131
+ folders: C ? y.items : [],
132
+ folderTotal: C ? y.total : 0,
133
+ files: w ? b.items : []
134
+ });
135
+ return [...e.folders, ...e.files];
136
+ }, [
137
+ s,
138
+ c,
139
+ C,
140
+ w,
141
+ y.items,
142
+ y.total,
143
+ b.items
144
+ ]), E = (e, t) => e === void 0 || t === void 0 ? void 0 : e + t, D = E(C ? y.total : 0, w ? b.total : 0), O = E(C ? y.shownTotal : 0, w ? b.shownTotal : 0), k = !u && (C && y.items === void 0 || w && b.items === void 0), { refetch: A } = y, { refetch: j } = b, M = m(() => {
145
+ A(), j();
146
+ }, [A, j]);
147
+ return {
148
+ rows: T,
149
+ total: D,
150
+ shownTotal: O,
151
+ loading: k && !y.error && !b.error,
152
+ error: y.error ?? b.error,
153
+ refetch: M,
154
+ request: _
155
+ };
156
+ }
157
+ export { C as useFilesV2List };
158
+
159
+ //# sourceMappingURL=useFilesV2List.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilesV2List.js","names":["pagination","plan","useHalf","active","answers","source","useMemo","list","rowsOf","off","useCallback","refetch","folderRows","folderRow","folderViewModel","folder","fileRows","fileRow","fileViewModel","file","useFolderHalf","skip","useQuery","FilesV2FoldersDocument","request","starred","FilesV2StarredFoldersDocument","searched","FilesV2SearchFoldersDocument","search","useFileHalf","FilesV2FilesDocument","FilesV2StarredFilesDocument","FilesV2SearchFilesDocument","useFilesV2List","input","sent","searchToSend","filesListRequest","tab","folderId","kind","visibility","sort","folderPlan","planCombinedPage","folders","files","rows","joined","joinCombinedPage","includeFolders","includeFiles","page","pageSize","sum","a","b","total","shownTotal","waiting","refetchFolders","refetchFiles"],"sources":["../../../src/files/v2/useFilesV2List.ts"],"sourcesContent":["/**\n * The Files page's list (Workspace pages v2, BOFF-15821): one page of folders,\n * then files, read from the server a page at a time (the old page read the\n * first 100 of each and paged nothing).\n *\n * Folders and files are separate server lists. Each half asks the source the\n * tab needs (`getFolders` / `getFiles`, the starred lists, or the searches);\n * `planCombinedPage` says which slice of each fills the page.\n */\n\nimport { useCallback, useMemo } from \"react\";\nimport { useQuery } from \"@apollo/client/react\";\nimport {\n FilesV2FilesDocument,\n FilesV2FoldersDocument,\n FilesV2SearchFilesDocument,\n FilesV2SearchFoldersDocument,\n FilesV2StarredFilesDocument,\n FilesV2StarredFoldersDocument,\n type FileCard_FileFragment,\n type FilePreviewModal_FileFragment,\n type FolderCard_FolderFragment,\n} from \"../../generated/wspace-operations\";\nimport { fileViewModel, folderViewModel } from \"../utils/fileViewModel\";\nimport {\n fileRow,\n filesListRequest,\n folderRow,\n joinCombinedPage,\n planCombinedPage,\n searchToSend,\n type FilesListQuery,\n type FilesListRequest,\n type FilesRow,\n type FilesSource,\n type SlicePlan,\n} from \"./filesModel\";\n\nexport interface FilesV2ListInput extends FilesListQuery {\n /** 1-based, from the address. */\n page: number;\n pageSize: number;\n /** Nothing is asked until the host gave a workspace. */\n skip?: boolean;\n}\n\nexport interface FilesV2List {\n /** The page's rows: folders first, then files. */\n rows: FilesRow[];\n /** Matching folders and files in all; undefined until both halves said. */\n total: number | undefined;\n /** The same, keeping the last count while the next page loads (the count line). */\n shownTotal: number | undefined;\n /** The first answer for these settings has not come yet. */\n loading: boolean;\n /** Either half failed: the page shows the error state, never \"empty\". */\n error: unknown;\n refetch: () => void;\n /** Where the rows came from (a search looks in every folder). */\n request: FilesListRequest;\n}\n\ninterface Half<T> {\n items: T[] | undefined;\n total: number | undefined;\n /** The last total, while a new page loads (for the count line). */\n shownTotal: number | undefined;\n loading: boolean;\n error: unknown;\n refetch: () => void;\n}\n\nconst pagination = (plan: SlicePlan | null) =>\n plan ? { offset: plan.offset, limit: plan.limit } : undefined;\n\n/** What a half needs from whichever query its source names. */\ninterface SourceAnswer<L> {\n list: L | undefined;\n previous: L | undefined;\n loading: boolean;\n error?: unknown;\n refetch: () => unknown;\n}\n\n/** One half's answer, from the query of the request's source (the others are skipped). */\nfunction useHalf<L extends { total: number }>(\n answers: Readonly<Record<FilesSource, SourceAnswer<L>>>,\n source: FilesSource,\n off: boolean,\n rowsOf: (list: L) => FilesRow[],\n): Half<FilesRow> {\n const active = answers[source];\n const { list, refetch } = active;\n const items = useMemo(\n () => (list ? rowsOf(list) : undefined),\n [list, rowsOf],\n );\n return {\n items,\n total: list?.total,\n shownTotal: list?.total ?? active.previous?.total,\n loading: !off && active.loading,\n error: off ? undefined : active.error,\n refetch: useCallback(() => {\n if (!off) void refetch();\n }, [off, refetch]),\n };\n}\n\ntype FolderList = { total: number; folders: FolderCard_FolderFragment[] };\ntype FileList = {\n total: number;\n files: (FileCard_FileFragment & FilePreviewModal_FileFragment)[];\n};\n\nconst folderRows = (list: FolderList) =>\n list.folders.map((folder) => folderRow(folderViewModel(folder)));\nconst fileRows = (list: FileList) =>\n list.files.map((file) => fileRow(fileViewModel(file)));\n\n/** The folders half: whichever source the request names, the others skipped. */\nfunction useFolderHalf(\n request: FilesListRequest,\n plan: SlicePlan | null,\n search: string,\n skip: boolean,\n): Half<FilesRow> {\n const off = skip || !plan;\n const list = useQuery(FilesV2FoldersDocument, {\n variables: {\n filter: request.folderFilter,\n sort: request.folderSort,\n pagination: pagination(plan),\n },\n skip: off || request.source !== \"list\",\n });\n const starred = useQuery(FilesV2StarredFoldersDocument, {\n variables: { pagination: pagination(plan) },\n skip: off || request.source !== \"starred\",\n });\n const searched = useQuery(FilesV2SearchFoldersDocument, {\n variables: {\n query: search,\n filter: request.folderFilter,\n pagination: pagination(plan),\n },\n skip: off || request.source !== \"search\",\n });\n return useHalf<FolderList>(\n {\n list: {\n ...list,\n list: list.data?.getFolders,\n previous: list.previousData?.getFolders,\n },\n starred: {\n ...starred,\n list: starred.data?.getStarredFolders,\n previous: starred.previousData?.getStarredFolders,\n },\n search: {\n ...searched,\n list: searched.data?.searchFolders,\n previous: searched.previousData?.searchFolders,\n },\n },\n request.source,\n off,\n folderRows,\n );\n}\n\n/** The files half, like the folders one. */\nfunction useFileHalf(\n request: FilesListRequest,\n plan: SlicePlan | null,\n search: string,\n skip: boolean,\n): Half<FilesRow> {\n const off = skip || !plan;\n const list = useQuery(FilesV2FilesDocument, {\n variables: {\n folderId: request.folderId,\n filter: request.fileFilter,\n sort: request.fileSort,\n pagination: pagination(plan),\n },\n skip: off || request.source !== \"list\",\n });\n const starred = useQuery(FilesV2StarredFilesDocument, {\n variables: { pagination: pagination(plan) },\n skip: off || request.source !== \"starred\",\n });\n const searched = useQuery(FilesV2SearchFilesDocument, {\n variables: {\n query: search,\n filter: request.fileFilter,\n pagination: pagination(plan),\n },\n skip: off || request.source !== \"search\",\n });\n return useHalf<FileList>(\n {\n list: {\n ...list,\n list: list.data?.getFiles,\n previous: list.previousData?.getFiles,\n },\n starred: {\n ...starred,\n list: starred.data?.getStarredFiles,\n previous: starred.previousData?.getStarredFiles,\n },\n search: {\n ...searched,\n list: searched.data?.searchFiles,\n previous: searched.previousData?.searchFiles,\n },\n },\n request.source,\n off,\n fileRows,\n );\n}\n\nexport function useFilesV2List(input: FilesV2ListInput): FilesV2List {\n const { tab, folderId, search, kind, visibility, sort, page, pageSize } =\n input;\n const skip = input.skip === true;\n const sent = searchToSend(search);\n const request = useMemo(\n () =>\n filesListRequest({ tab, folderId, search: sent, kind, visibility, sort }),\n [tab, folderId, sent, kind, visibility, sort],\n );\n\n // Folders first: their slice never depends on the files.\n const folderPlan = planCombinedPage({\n page,\n pageSize,\n includeFolders: request.includeFolders,\n includeFiles: request.includeFiles,\n folderTotal: undefined,\n }).folders;\n const folders = useFolderHalf(request, folderPlan, sent, skip);\n\n // Files continue where the folders end (page 1 needs no count).\n const filesPlan = planCombinedPage({\n page,\n pageSize,\n includeFolders: request.includeFolders,\n includeFiles: request.includeFiles,\n folderTotal: folders.total,\n });\n const files = useFileHalf(request, filesPlan.files, sent, skip);\n\n const { includeFolders, includeFiles } = request;\n const rows = useMemo(() => {\n const joined = joinCombinedPage({\n page,\n pageSize,\n folders: includeFolders ? folders.items : [],\n folderTotal: includeFolders ? folders.total : 0,\n files: includeFiles ? files.items : [],\n });\n return [...joined.folders, ...joined.files];\n }, [\n page,\n pageSize,\n includeFolders,\n includeFiles,\n folders.items,\n folders.total,\n files.items,\n ]);\n\n const sum = (a: number | undefined, b: number | undefined) =>\n a === undefined || b === undefined ? undefined : a + b;\n const total = sum(\n includeFolders ? folders.total : 0,\n includeFiles ? files.total : 0,\n );\n const shownTotal = sum(\n includeFolders ? folders.shownTotal : 0,\n includeFiles ? files.shownTotal : 0,\n );\n\n const waiting =\n !skip &&\n ((includeFolders && folders.items === undefined) ||\n (includeFiles && files.items === undefined));\n const { refetch: refetchFolders } = folders;\n const { refetch: refetchFiles } = files;\n const refetch = useCallback(() => {\n refetchFolders();\n refetchFiles();\n }, [refetchFolders, refetchFiles]);\n\n return {\n rows,\n total,\n shownTotal,\n loading: waiting && !folders.error && !files.error,\n error: folders.error ?? files.error,\n refetch,\n request,\n };\n}\n"],"mappings":";;;;;;AAwEA,IAAMA,KAAc,MAClBC,IAAO;CAAE,QAAQA,EAAK;CAAQ,OAAOA,EAAK;AAAM,IAAI,KAAA;AAYtD,SAASC,EACP,GACA,GACA,GACA,GACgB;CAChB,IAAMC,IAASC,EAAQC,IACjB,EAAE,SAAM,eAAYF;CAK1B,OAAO;EACL,OALYG,QACLC,IAAOC,EAAOD,CAAI,IAAI,KAAA,GAC7B,CAACA,GAAMC,CAAM,CAGb;EACA,OAAOD,GAAM;EACb,YAAYA,GAAM,SAASJ,EAAO,UAAU;EAC5C,SAAS,CAACM,KAAON,EAAO;EACxB,OAAOM,IAAM,KAAA,IAAYN,EAAO;EAChC,SAASO,QAAkB;GACzB,AAAKD,KAAKE,EAAa;EACzB,GAAG,CAACF,GAAKE,CAAO,CAAC;CACnB;AACF;AAQA,IAAMC,KAAc,MAClBL,EAAK,QAAQ,KAAK,MAAWM,EAAUC,EAAgBC,CAAM,CAAC,CAAC,GAC3DC,KAAY,MAChBT,EAAK,MAAM,KAAK,MAASU,EAAQC,EAAcC,CAAI,CAAC,CAAC;AAGvD,SAASC,EACP,GACA,GACA,GACA,GACgB;CAChB,IAAMX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S,GAAGA,EAAO,KAAK;CAC5C,GAAG;EACDI;EACAC;EACAH;EACAC;EACAN,EAAQ;EACRA,EAAQ;EACRC,EAAM;CACR,CAAC,GAEKQ,KAAO,GAAuB,MAClCC,MAAM,KAAA,KAAaC,MAAM,KAAA,IAAY,KAAA,IAAYD,IAAIC,GACjDC,IAAQH,EACZJ,IAAiBL,EAAQ,QAAQ,GACjCM,IAAeL,EAAM,QAAQ,CAC/B,GACMY,IAAaJ,EACjBJ,IAAiBL,EAAQ,aAAa,GACtCM,IAAeL,EAAM,aAAa,CACpC,GAEMa,IACJ,CAACvC,MACC8B,KAAkBL,EAAQ,UAAU,KAAA,KACnCM,KAAgBL,EAAM,UAAU,KAAA,IAC/B,EAAE,SAASc,MAAmBf,GAC9B,EAAE,SAASgB,MAAiBf,GAC5BpC,IAAUD,QAAkB;EAEhC,AADAmD,EAAe,GACfC,EAAa;CACf,GAAG,CAACD,GAAgBC,CAAY,CAAC;CAEjC,OAAO;EACL;EACA;EACA;EACA,SAASF,KAAW,CAACd,EAAQ,SAAS,CAACC,EAAM;EAC7C,OAAOD,EAAQ,SAASC,EAAM;EAC9B;EACA;CACF;AACF"}
@@ -0,0 +1,87 @@
1
+ import { MadeUploadFolders, UploadFolderBase, UploadItem } from '../types';
2
+ import { UploadVisibility } from '../utils/uploadVisibility';
3
+ /** A file picked for upload, with its folder path inside a chosen folder. */
4
+ export interface PickedFile {
5
+ file: File;
6
+ /** "Reports/2026" for a file of a chosen folder; "" for a loose file. */
7
+ folderPath: string;
8
+ }
9
+ /** The folder path of a picked file (`webkitRelativePath` without the name). */
10
+ export declare function folderPathOf(file: File): string;
11
+ /** Every folder a set of paths needs, parents first ("A", "A/B", "A/B/C"). */
12
+ export declare function foldersToCreate(paths: readonly string[]): string[];
13
+ /** Makes one folder, with the upload's visibility. */
14
+ export type CreateUploadFolder = (folder: {
15
+ name: string;
16
+ parentId: string | undefined;
17
+ visibility: UploadVisibility;
18
+ }) => Promise<string>;
19
+ export interface UploadFolderTree {
20
+ /** Each path's folder id ("" is where the chosen folder goes). */
21
+ ids: Map<string, string | undefined>;
22
+ /** Each path that could not be made (or is inside one), with that folder's name. */
23
+ failed: Map<string, string>;
24
+ }
25
+ /**
26
+ * Makes a chosen folder's folders, parents first, each with the upload's
27
+ * visibility (the files get it too, so whoever may see them can reach them).
28
+ * A folder being made or made already (`made`, shared by an upload and its
29
+ * retries) is not made twice; one that fails is tried again next time, and
30
+ * nothing inside it is made.
31
+ */
32
+ export declare function makeUploadFolders(paths: readonly string[], base: UploadFolderBase, made: MadeUploadFolders, create: CreateUploadFolder): Promise<UploadFolderTree>;
33
+ export interface PreparedUpload {
34
+ /** Every picked file, as a queue row. */
35
+ items: UploadItem[];
36
+ /** The rows to send: their folder was made, or they need none. */
37
+ pending: UploadItem[];
38
+ }
39
+ /**
40
+ * The queue rows of a prepared upload. A file whose folder was made (or that
41
+ * needs none) waits to be sent; one whose folder could not be made fails, and
42
+ * keeps its folder so that Retry makes it first. Never sent anywhere else.
43
+ */
44
+ export declare function uploadItems(picked: readonly PickedFile[], tree: UploadFolderTree, context: {
45
+ stamp: number;
46
+ base: UploadFolderBase;
47
+ made: MadeUploadFolders;
48
+ /** Each picked file's thumbnail, in order. */
49
+ thumbnails: readonly (string | undefined)[];
50
+ folderFailed: (name: string) => string;
51
+ }): PreparedUpload;
52
+ /**
53
+ * After preparing an upload: send what waits. With nothing to send (no folder
54
+ * of any file could be made), refresh the list now, or the folders that were
55
+ * made would not show until something else refreshes it.
56
+ */
57
+ export declare function nextAfterPreparing(prepared: PreparedUpload): "send" | "refresh";
58
+ /**
59
+ * After a Retry made its file's folder: send the file. Cancelled meanwhile, or
60
+ * its folder still not made: send nothing, but refresh the list, since folders
61
+ * may have been made on the way.
62
+ */
63
+ export declare function nextAfterRetryFolders(outcome: {
64
+ cancelled: boolean;
65
+ lost: boolean;
66
+ }): "send" | "refresh";
67
+ export interface UploadRequest {
68
+ picked: readonly PickedFile[];
69
+ visibility: UploadVisibility;
70
+ /** The folder being browsed; undefined for the top level. */
71
+ folderId: string | undefined;
72
+ }
73
+ export declare function useFilesV2Uploads({ onUploaded }: {
74
+ onUploaded: () => void;
75
+ }): {
76
+ upload: ({ picked, visibility, folderId }: UploadRequest) => Promise<void>;
77
+ uploading: boolean;
78
+ queue: {
79
+ items: UploadItem[];
80
+ isOpen: boolean;
81
+ onClose: () => void;
82
+ onPause: (id: string) => void;
83
+ onResume: (id: string) => undefined;
84
+ onRetry: (id: string) => undefined;
85
+ onCancel: (id: string) => void;
86
+ };
87
+ };
@@ -0,0 +1,279 @@
1
+ import { useCreateFolder as e } from "../hooks/useCreateFolder.js";
2
+ import { useUploadFile as t } from "../hooks/useUploadFile.js";
3
+ import { useUploadQueueState as n } from "../hooks/useUploadQueueState.js";
4
+ import { useFilesContext as r } from "../providers/FilesProvider.js";
5
+ import { emitFilesEvent as i } from "../utils/events.js";
6
+ import { isQuotaExhaustedError as a } from "../utils/quotaUtils.js";
7
+ import { generateThumbnail as o } from "../utils/thumbnail.js";
8
+ import { useTr as s } from "../../shared/hooks/useTr.js";
9
+ import { createUploadLine as c } from "./uploadLine.js";
10
+ import { useCallback as l, useRef as u, useState as d } from "react";
11
+ import { useNavigate as f } from "react-router";
12
+ import { useConfirm as p, useNotify as m } from "@burdenoff/fe-libs/ui";
13
+ // src/files/v2/useFilesV2Uploads.ts
14
+ function h(e) {
15
+ let t = (e.webkitRelativePath || "").split("/").filter(Boolean);
16
+ return t.length > 1 ? t.slice(0, -1).join("/") : "";
17
+ }
18
+ function g(e) {
19
+ let t = /* @__PURE__ */ new Set();
20
+ for (let n of e) {
21
+ let e = n.split("/").filter(Boolean);
22
+ for (let n = 1; n <= e.length; n += 1) t.add(e.slice(0, n).join("/"));
23
+ }
24
+ return [...t].sort((e, t) => e.split("/").length - t.split("/").length || e.localeCompare(t));
25
+ }
26
+ async function _(e, t, n, r) {
27
+ let i = /* @__PURE__ */ new Map([["", t.id]]), a = /* @__PURE__ */ new Map();
28
+ for (let o of g(e)) {
29
+ let e = o.split("/"), s = e.slice(0, -1).join("/"), c = e[e.length - 1] ?? o, l = a.get(s);
30
+ if (l !== void 0) {
31
+ a.set(o, l);
32
+ continue;
33
+ }
34
+ let u = n.get(o);
35
+ if (!u) {
36
+ let e = r({
37
+ name: c,
38
+ parentId: i.get(s),
39
+ visibility: t.visibility
40
+ });
41
+ n.set(o, e), e.catch(() => {
42
+ n.get(o) === e && n.delete(o);
43
+ }), u = e;
44
+ }
45
+ try {
46
+ i.set(o, await u);
47
+ } catch {
48
+ a.set(o, c);
49
+ }
50
+ }
51
+ return {
52
+ ids: i,
53
+ failed: a
54
+ };
55
+ }
56
+ function v(e, t, n) {
57
+ let r = e.map((e, r) => {
58
+ let i = {
59
+ id: `${n.stamp}-${r}-${e.file.name}`,
60
+ file: e.file,
61
+ progress: 0,
62
+ visibility: n.base.visibility,
63
+ thumbnailUrl: n.thumbnails[r]
64
+ }, a = t.failed.get(e.folderPath);
65
+ return a === void 0 ? {
66
+ ...i,
67
+ status: "pending",
68
+ folderId: t.ids.get(e.folderPath)
69
+ } : {
70
+ ...i,
71
+ status: "failed",
72
+ error: n.folderFailed(a),
73
+ pendingFolder: {
74
+ path: e.folderPath,
75
+ base: n.base,
76
+ made: n.made
77
+ }
78
+ };
79
+ });
80
+ return {
81
+ items: r,
82
+ pending: r.filter((e) => e.status === "pending")
83
+ };
84
+ }
85
+ function y(e) {
86
+ return e.pending.length > 0 ? "send" : "refresh";
87
+ }
88
+ function b(e) {
89
+ return e.cancelled || e.lost ? "refresh" : "send";
90
+ }
91
+ function x({ onUploaded: h }) {
92
+ let g = s(), x = f(), S = p(), C = m(), w = r(), T = t(), E = e(), D = n(), { setUploadQueue: O, setIsUploadPanelOpen: k, setUploading: A } = D, j = u(!1), [M] = d(() => c()), N = u(null), P = u(/* @__PURE__ */ new Set()), F = u(/* @__PURE__ */ new Set()), I = l(async () => {
93
+ j.current || (j.current = !0, await S({
94
+ title: g("files.v2.upload.quotaTitle", "Your storage is full"),
95
+ description: g("files.v2.upload.quotaDescription", "Upgrade your plan, or delete files you no longer need, to upload more."),
96
+ confirmLabel: g("files.v2.upload.viewBilling", "View billing"),
97
+ cancelLabel: g("files.v2.common.notNow", "Not now")
98
+ }) && x("/billing"));
99
+ }, [
100
+ S,
101
+ x,
102
+ g
103
+ ]), L = l(async (e) => {
104
+ let t = (t) => O((n) => n.map((n) => n.id === e.id ? {
105
+ ...n,
106
+ ...t
107
+ } : n));
108
+ t({
109
+ status: "uploading",
110
+ error: void 0
111
+ });
112
+ try {
113
+ let n = await T.mutateAsync({
114
+ file: e.file,
115
+ folderId: e.folderId,
116
+ visibility: e.visibility,
117
+ onProgress: (n) => {
118
+ n >= 90 && (N.current = e.id), t({ progress: n });
119
+ }
120
+ });
121
+ return t({
122
+ status: "completed",
123
+ progress: 100
124
+ }), i(w, "files.file.uploaded", {
125
+ fileId: n.id,
126
+ fileName: n.name,
127
+ folderId: e.folderId
128
+ }), !0;
129
+ } catch (n) {
130
+ let r = n instanceof Error ? n.message : g("files.v2.upload.failed", "Couldn’t upload it");
131
+ return r === "Upload paused" ? t({ status: "paused" }) : a(n) ? (t({
132
+ status: "failed",
133
+ error: g("files.v2.upload.quotaShort", "Storage is full")
134
+ }), I()) : (t({
135
+ status: "failed",
136
+ error: r
137
+ }), i(w, "files.api.failed", {
138
+ action: "uploadFile",
139
+ fileName: e.file.name,
140
+ message: r
141
+ })), !1;
142
+ } finally {
143
+ N.current === e.id && (N.current = null);
144
+ }
145
+ }, [
146
+ I,
147
+ w,
148
+ O,
149
+ g,
150
+ T
151
+ ]), R = l(async ({ name: e, parentId: t, visibility: n }) => {
152
+ let { data: r } = await E.mutateAsync({
153
+ name: e,
154
+ parentFolderId: t,
155
+ visibility: n
156
+ });
157
+ if (!r?.id) throw Error("The folder was not made");
158
+ return r.id;
159
+ }, [E]), z = l((e) => g("files.v2.upload.folderFailed", "Couldn’t make the folder “{{name}}”, so this file wasn’t uploaded.", { name: e }), [g]), B = l(() => {
160
+ M.run({
161
+ send: L,
162
+ onStart: () => A(!0),
163
+ onIdle: (e) => {
164
+ A(!1), h(), e > 0 && C({
165
+ tone: "success",
166
+ title: e === 1 ? g("files.v2.upload.doneOne", "Uploaded 1 file") : g("files.v2.upload.doneMany", "Uploaded {{count}} files", { count: e })
167
+ });
168
+ }
169
+ });
170
+ }, [
171
+ M,
172
+ C,
173
+ h,
174
+ L,
175
+ A,
176
+ g
177
+ ]), V = l(async ({ picked: e, visibility: t, folderId: n }) => {
178
+ if (e.length === 0) return;
179
+ j.current = !1;
180
+ let r = [...new Set(e.map((e) => e.folderPath).filter(Boolean))], i = /* @__PURE__ */ new Map(), a = {
181
+ id: n,
182
+ visibility: t
183
+ }, [s, c] = await Promise.all([_(r, a, i, R), Promise.all(e.map(async (e) => await o(e.file) ?? void 0))]), l = v(e, s, {
184
+ stamp: Date.now(),
185
+ base: a,
186
+ made: i,
187
+ thumbnails: c,
188
+ folderFailed: z
189
+ });
190
+ O((e) => [...e, ...l.items]), k(!0), y(l) === "send" ? (M.add(l.pending), B()) : h();
191
+ }, [
192
+ R,
193
+ B,
194
+ z,
195
+ M,
196
+ h,
197
+ k,
198
+ O
199
+ ]), { uploadQueue: H } = D, U = l(async (e) => {
200
+ let t = H.find((t) => t.id === e);
201
+ if (t?.status !== "failed" && t?.status !== "paused" || P.current.has(e)) return;
202
+ P.current.add(e), F.current.delete(e);
203
+ let n = (t) => O((n) => n.map((n) => n.id === e ? {
204
+ ...n,
205
+ ...t
206
+ } : n));
207
+ try {
208
+ let r = t.folderId, i = t.pendingFolder;
209
+ if (i) {
210
+ n({
211
+ status: "pending",
212
+ error: void 0
213
+ });
214
+ let t = await _([i.path], i.base, i.made, R), a = F.current.has(e), o = t.failed.get(i.path);
215
+ if (b({
216
+ cancelled: a,
217
+ lost: o !== void 0
218
+ }) === "refresh") {
219
+ !a && o !== void 0 && n({
220
+ status: "failed",
221
+ error: z(o)
222
+ }), h();
223
+ return;
224
+ }
225
+ r = t.ids.get(i.path);
226
+ }
227
+ let a = {
228
+ ...t,
229
+ folderId: r,
230
+ pendingFolder: void 0,
231
+ status: "pending",
232
+ progress: 0,
233
+ error: void 0
234
+ };
235
+ n(a), M.add([a]), B();
236
+ } finally {
237
+ P.current.delete(e);
238
+ }
239
+ }, [
240
+ R,
241
+ B,
242
+ z,
243
+ M,
244
+ h,
245
+ O,
246
+ H
247
+ ]), W = l((e) => {
248
+ N.current !== e && (M.active() === e ? T.pause() : M.remove(e), O((t) => t.map((t) => t.id === e ? {
249
+ ...t,
250
+ status: "paused"
251
+ } : t)));
252
+ }, [
253
+ M,
254
+ O,
255
+ T
256
+ ]), { cancelUpload: G } = D, K = l((e) => {
257
+ N.current !== e && (F.current.add(e), !M.remove(e) && M.active() === e && T.pause(), G(e));
258
+ }, [
259
+ G,
260
+ M,
261
+ T
262
+ ]);
263
+ return {
264
+ upload: V,
265
+ uploading: D.uploading,
266
+ queue: {
267
+ items: D.uploadQueue,
268
+ isOpen: D.isUploadPanelOpen,
269
+ onClose: () => k(!1),
270
+ onPause: W,
271
+ onResume: (e) => void U(e),
272
+ onRetry: (e) => void U(e),
273
+ onCancel: K
274
+ }
275
+ };
276
+ }
277
+ export { h as folderPathOf, g as foldersToCreate, _ as makeUploadFolders, y as nextAfterPreparing, b as nextAfterRetryFolders, v as uploadItems, x as useFilesV2Uploads };
278
+
279
+ //# sourceMappingURL=useFilesV2Uploads.js.map