@widgetic/file-browser 0.5.24 → 0.5.26

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/README.md +279 -0
  2. package/dist/components/FolderTree.svelte +16 -9
  3. package/dist/components/FolderTree.svelte.d.ts +2 -6
  4. package/dist/components/core/FileBrowser.svelte +529 -127
  5. package/dist/components/core/FileBrowser.svelte.d.ts +40 -1
  6. package/dist/components/core/FileUploader.svelte +130 -57
  7. package/dist/components/core/Header.svelte +13 -2
  8. package/dist/components/core/Header.svelte.d.ts +1 -0
  9. package/dist/components/core/RecentFiles.svelte +41 -29
  10. package/dist/components/core/UploadStatus.svelte +14 -7
  11. package/dist/components/core/UploadStatusList.svelte +13 -21
  12. package/dist/components/items/FileItem.svelte +28 -15
  13. package/dist/components/items/FolderItem.svelte +13 -6
  14. package/dist/components/modals/MoveDialog.svelte +49 -38
  15. package/dist/components/modals/NewFolderButton.svelte +5 -2
  16. package/dist/components/modals/SearchModal.svelte +25 -26
  17. package/dist/components/modals/SearchModal.svelte.d.ts +1 -1
  18. package/dist/components/modals/SelectedFilesModal.svelte +23 -14
  19. package/dist/components/modals/SelectedFilesModal.svelte.d.ts +1 -1
  20. package/dist/components/previews/AudioPlayer.svelte +5 -2
  21. package/dist/components/previews/ErrorPreview.svelte +7 -4
  22. package/dist/components/previews/ErrorPreview.svelte.d.ts +1 -1
  23. package/dist/components/previews/FilePreview.svelte +25 -9
  24. package/dist/components/previews/FontPreview.svelte +18 -9
  25. package/dist/components/previews/FontPreview.svelte.d.ts +1 -1
  26. package/dist/components/previews/TextPreview.svelte +12 -5
  27. package/dist/components/previews/VideoPlayer.svelte +11 -7
  28. package/dist/components/ui/ControlToolbar.svelte +50 -28
  29. package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
  30. package/dist/components/ui/DragSelect.svelte +3 -2
  31. package/dist/components/ui/DropdownMenu.svelte +35 -14
  32. package/dist/components/ui/FileIcon.svelte +8 -5
  33. package/dist/components/ui/FileIcon.svelte.d.ts +1 -0
  34. package/dist/components/ui/FileMetadata.svelte +16 -15
  35. package/dist/components/ui/SearchResults.svelte +9 -2
  36. package/dist/i18n/context.d.ts +28 -0
  37. package/dist/i18n/context.js +17 -0
  38. package/dist/i18n/errors.d.ts +11 -0
  39. package/dist/i18n/errors.js +19 -0
  40. package/dist/i18n/index.d.ts +15 -0
  41. package/dist/i18n/index.js +18 -0
  42. package/dist/i18n/messages.d.ts +281 -0
  43. package/dist/i18n/messages.js +294 -0
  44. package/dist/i18n/text.d.ts +19 -0
  45. package/dist/i18n/text.js +35 -0
  46. package/dist/index.d.ts +3 -0
  47. package/dist/index.js +4 -0
  48. package/dist/mediaLibrary/capabilities.d.ts +22 -0
  49. package/dist/mediaLibrary/capabilities.js +42 -0
  50. package/dist/mediaLibrary/context.d.ts +17 -0
  51. package/dist/mediaLibrary/context.js +16 -0
  52. package/dist/mediaLibrary/errors.d.ts +42 -0
  53. package/dist/mediaLibrary/errors.js +114 -0
  54. package/dist/mediaLibrary/index.d.ts +10 -0
  55. package/dist/mediaLibrary/index.js +9 -0
  56. package/dist/mediaLibrary/normalize.d.ts +39 -0
  57. package/dist/mediaLibrary/normalize.js +139 -0
  58. package/dist/mediaLibrary/paging.d.ts +37 -0
  59. package/dist/mediaLibrary/paging.js +62 -0
  60. package/dist/mediaLibrary/resolve.d.ts +39 -0
  61. package/dist/mediaLibrary/resolve.js +137 -0
  62. package/dist/mediaLibrary/treeOps.d.ts +24 -0
  63. package/dist/mediaLibrary/treeOps.js +67 -0
  64. package/dist/mediaLibrary/types.d.ts +126 -0
  65. package/dist/mediaLibrary/types.js +11 -0
  66. package/dist/mediaLibrary/urls.d.ts +30 -0
  67. package/dist/mediaLibrary/urls.js +59 -0
  68. package/dist/mediaLibrary/widgetic.d.ts +39 -0
  69. package/dist/mediaLibrary/widgetic.js +89 -0
  70. package/dist/stores/fileStore.d.ts +2 -2
  71. package/dist/stores/folderCountStore.js +2 -2
  72. package/dist/stores/navigationStore.d.ts +1 -1
  73. package/dist/stores/persistentSelectStore.d.ts +11 -1
  74. package/dist/stores/persistentSelectStore.js +26 -0
  75. package/dist/utils/dateUtils.d.ts +11 -2
  76. package/dist/utils/dateUtils.js +20 -15
  77. package/dist/utils/fileKinds.d.ts +44 -0
  78. package/dist/utils/fileKinds.js +96 -0
  79. package/dist/utils/fileNames.d.ts +7 -0
  80. package/dist/utils/fileNames.js +19 -0
  81. package/dist/utils/fileOperations.js +2 -11
  82. package/dist/utils/fileTypes.d.ts +11 -2
  83. package/dist/utils/fileTypes.js +26 -14
  84. package/dist/utils/fileUtils.d.ts +8 -1
  85. package/dist/utils/fileUtils.js +22 -7
  86. package/dist/utils/folderUtils.js +3 -2
  87. package/dist/utils/previewKeys.d.ts +12 -0
  88. package/dist/utils/previewKeys.js +14 -0
  89. package/dist/utils/safeText.d.ts +29 -0
  90. package/dist/utils/safeText.js +66 -0
  91. package/dist/utils/userUploadsStorage.d.ts +4 -1
  92. package/dist/utils/userUploadsStorage.js +5 -2
  93. package/dist/utils/widgeticTusUpload.d.ts +10 -0
  94. package/dist/utils/widgeticTusUpload.js +61 -3
  95. package/dist/utils/widgeticUpload.d.ts +3 -0
  96. package/dist/utils/widgeticUpload.js +7 -2
  97. package/package.json +5 -2
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Every word the File Browser shows, in English: the one place to read them, and the keys a page can replace with the
3
+ * `messages` option (or `setLanguage()` of the module).
4
+ *
5
+ * A message is plain text. `{name}` is a value the File Browser puts in; `{count, plural, one {# file} other {# files}}`
6
+ * picks the form that fits a number in the page's language. `\{`, `\}`, `\#` and `\\` write those characters
7
+ * themselves. See `translator.ts` for the whole format.
8
+ *
9
+ * Keys are grouped by where the words appear. A key that is left out of a page's `messages` keeps the English text
10
+ * below, so a language can be added a screen at a time.
11
+ */
12
+ export const FILE_BROWSER_MESSAGES = {
13
+ // ===== Words that appear in several places =====
14
+ 'action.cancel': 'Cancel',
15
+ 'action.confirm': 'Confirm',
16
+ 'action.create': 'Create',
17
+ 'action.delete': 'Delete',
18
+ 'action.done': 'Done',
19
+ 'action.download': 'Download',
20
+ 'action.move': 'Move',
21
+ 'action.rename': 'Rename',
22
+ 'action.tryAgain': 'Try again',
23
+ 'action.preview': 'Preview',
24
+ 'action.play': 'Play',
25
+ 'action.pause': 'Pause',
26
+ 'action.mute': 'Mute',
27
+ 'action.unmute': 'Unmute',
28
+ 'action.select': 'Select',
29
+ 'action.selected': 'Selected',
30
+ 'action.clearItems': 'Clear items',
31
+ /** The button that hands the picked files to the page. The module shows "Select" here. */
32
+ 'action.addToEditor': 'Add to Editor',
33
+ /** Put between names in a list of names ("a.png, b.png"). */
34
+ 'list.separator': ', ',
35
+ 'toast.inBackground': 'This will happen in the background',
36
+ 'toast.unknownError': 'Unknown error occurred',
37
+ /** What a screen reader hears for the region that holds the pop-ups. The library adds the key that moves focus to it. */
38
+ 'toast.regionLabel': 'Notifications',
39
+ /** What a screen reader hears for the button that closes a pop-up. */
40
+ 'toast.closeLabel': 'Close notification',
41
+ // ===== The bar above the files =====
42
+ 'search.placeholder': 'Search...',
43
+ 'filter.by': 'Filter by {type}',
44
+ 'filterName.all': 'All',
45
+ 'filterName.image': 'Image',
46
+ 'filterName.audio': 'Audio',
47
+ 'filterName.video': 'Video',
48
+ 'filterName.document': 'Document',
49
+ 'filterName.font': 'Font',
50
+ 'filterName.svg': 'SVG',
51
+ 'filterOption.all': 'All',
52
+ 'filterOption.image': 'Images',
53
+ 'filterOption.video': 'Videos',
54
+ 'filterOption.document': 'Documents',
55
+ 'filterOption.audio': 'Audio',
56
+ 'filterOption.font': 'Fonts',
57
+ 'filterOption.svg': 'SVG',
58
+ 'sort.name': 'Name',
59
+ 'sort.date': 'Date',
60
+ 'sort.size': 'Size',
61
+ 'breadcrumbs.back': 'Back',
62
+ 'breadcrumbs.forward': 'Forward',
63
+ /** The first step of the path above the files. */
64
+ 'breadcrumbs.root': 'File browser',
65
+ /** What a screen reader says for the path above the files. */
66
+ 'breadcrumbs.label': 'breadcrumb',
67
+ // ===== What the list says when there is nothing to show =====
68
+ 'empty.library': 'No files yet!',
69
+ 'empty.libraryFiltered': 'No files of this type!',
70
+ 'empty.folder': 'No files in this folder!',
71
+ // ===== The page's own media library =====
72
+ 'library.partialNotice': 'Some files could not be loaded.',
73
+ 'library.truncatedNotice': 'Only the newest files are shown.',
74
+ 'library.notSetUp': 'The media library is not set up correctly.',
75
+ /** The name of the folder that holds the files, when the page's library does not name itself. */
76
+ 'library.defaultLabel': 'My uploads',
77
+ /** Why a call to the library failed, when the library gave no reason of its own. */
78
+ 'libraryError.loadFailed': 'Could not load the files',
79
+ 'libraryError.uploadFailed': 'The upload failed',
80
+ 'libraryError.renameFailed': 'Could not rename the file',
81
+ 'libraryError.deleteFailed': 'Could not delete the file',
82
+ 'libraryError.unreachable': 'Could not reach the media library',
83
+ 'libraryError.timeout': 'The media library did not answer in time',
84
+ 'libraryError.renameNotAllowed': 'This media library does not allow renaming files',
85
+ 'libraryError.deleteNotAllowed': 'This media library does not allow deleting files',
86
+ 'libraryError.fileGone': 'The file is no longer in the list',
87
+ 'libraryError.repeatedPage': 'The media library keeps returning the same files, so the rest was not loaded',
88
+ 'libraryError.accessToken': 'Could not get an access token from the page',
89
+ 'libraryError.accessTokenRenew': 'Could not get a fresh access token from the page',
90
+ 'libraryError.fileTooLarge': 'Files over {limit} MB cannot be uploaded here yet',
91
+ 'libraryError.uploadNotAllowed': 'This media library does not accept uploads',
92
+ // ===== Sizes of files: {size} is the number, written the way the language writes numbers =====
93
+ 'size.bytes': '{size} Bytes',
94
+ 'size.kb': '{size} KB',
95
+ 'size.mb': '{size} MB',
96
+ 'size.gb': '{size} GB',
97
+ 'size.tb': '{size} TB',
98
+ // ===== The kinds of file, as they appear inside a sentence ("Upload image files") =====
99
+ 'fileKind.any': 'any',
100
+ 'fileKind.image': 'image',
101
+ 'fileKind.video': 'video',
102
+ 'fileKind.audio': 'audio',
103
+ 'fileKind.document': 'document',
104
+ 'fileKind.font': 'font',
105
+ 'fileKind.svg': 'SVG',
106
+ /** {types} is a list of extensions (".jpg, .png"). */
107
+ 'fileTypes.allowed': 'Allowed types: {types}',
108
+ 'fileTypes.allowedSvg': 'Allowed types: SVG files (.svg)',
109
+ 'fileTypes.allowedDocument': 'Allowed types: document files ({types})',
110
+ /** One sentence listing every kind with its extensions (each a list joined with "list.separator"). */
111
+ 'fileTypes.addAll': 'Add images ({images}), audio ({audio}), video ({video}), documents ({documents}), fonts ({fonts}) or vector graphics ({svg}).',
112
+ 'fileTypes.fontNaming': 'Font naming convention:\nFontFamily-Weight.extension\n\nExample:\nGeistMono-Black.ttf',
113
+ // ===== Uploading =====
114
+ /** {types} is the kinds of file taken: the words of "fileKind.*" joined with "list.separator" ("image, video"). */
115
+ 'upload.uploading': 'Uploading...',
116
+ 'upload.foldersNotAllowed': 'Folders cannot be uploaded',
117
+ 'upload.invalidType': 'Invalid file type. Please use {types} files only.',
118
+ 'upload.dropActive': 'Drop to upload {types} files',
119
+ 'upload.button': 'Upload {types} files',
120
+ 'upload.dragHint': 'or drag and drop {types} files here',
121
+ /** On a small screen the sentence is one link. The words of "upload.chooseOrDropLink" inside it are underlined. */
122
+ 'upload.chooseOrDrop': 'Upload or drop {types} files here',
123
+ 'upload.chooseOrDropLink': 'Upload',
124
+ 'upload.panelTitle': 'File Upload Progress',
125
+ 'upload.progress': '{total, plural, other {{done}/# files uploaded}}',
126
+ 'upload.failedCount': '{count} failed',
127
+ 'upload.expandPanel': 'Expand panel',
128
+ 'upload.collapsePanel': 'Collapse panel',
129
+ 'upload.expandUploader': 'Expand uploader',
130
+ 'upload.collapseUploader': 'Collapse uploader',
131
+ 'upload.closeUploader': 'Close uploader',
132
+ 'upload.cancel': 'Cancel upload',
133
+ 'upload.retry': 'Retry upload',
134
+ 'upload.retryFailed': 'Retry failed uploads?',
135
+ 'upload.clearCompleted': 'Clear completed uploads',
136
+ 'upload.completedAlt': 'Completed',
137
+ 'upload.networkError': 'Network error',
138
+ 'upload.unknownError': 'Unknown error',
139
+ 'upload.skippedOne': 'Skipped duplicate file: {name}',
140
+ 'upload.skippedMany': '{count, plural, one {Skipped # duplicate file} other {Skipped # duplicate files}}',
141
+ 'upload.time.calculating': 'calculating...',
142
+ 'upload.time.lessThanSecond': 'less than a second',
143
+ 'upload.time.seconds': '{count, plural, one {# second} other {# seconds}}',
144
+ 'upload.time.minutes': '{count, plural, one {# minute} other {# minutes}}',
145
+ /** {time} is a time from "upload.time.*" ("5 seconds"). */
146
+ 'upload.timeLeft': '{time} left',
147
+ 'upload.complete': 'Upload complete.',
148
+ 'upload.removeFile': 'Remove file',
149
+ 'upload.uploadingProgress': '{total, plural, other {Uploading {done}/# files}}',
150
+ 'upload.filesTotal': '{count, plural, one {# file} other {# files}}',
151
+ 'upload.completeCount': '{done}/{total} complete',
152
+ // ===== Asking before a change =====
153
+ 'dialog.delete.folderTitle': 'Delete folder',
154
+ 'dialog.delete.itemsTitle': 'Delete items',
155
+ 'dialog.delete.fileTitle': 'Delete file',
156
+ 'dialog.delete.folderMessage': "Delete '{name}' and all content inside?",
157
+ 'dialog.delete.itemsMessage': '{count, plural, one {Are you sure you want to delete # item?} other {Are you sure you want to delete # items?}}',
158
+ 'dialog.delete.fileMessage': "Delete '{name}'?",
159
+ 'dialog.newFolder.placeholder': 'folder name...',
160
+ 'dialog.newFolder.invalidTitle': 'Invalid folder name',
161
+ 'dialog.newFolder.required': 'Folder name is required',
162
+ 'dialog.newFolder.invalidCharacters': 'Folder name can only contain letters, numbers, and spaces',
163
+ /** {max} is put in by the dialog: it knows its own limit. */
164
+ 'dialog.newFolder.tooLong': 'Folder name cannot exceed {max} characters',
165
+ /** The hint in the empty name field of the rename window, for a file and for a folder. */
166
+ 'dialog.rename.filePlaceholder': 'file name...',
167
+ 'dialog.rename.folderPlaceholder': 'folder name...',
168
+ 'dialog.rename.invalidTitle': 'Invalid name',
169
+ 'dialog.rename.enterName': 'Please enter a name',
170
+ 'dialog.rename.enterDifferentName': 'Please enter a different name',
171
+ 'dialog.rename.enterValidName': 'Please enter a valid name',
172
+ 'dialog.rename.tooShort': 'Name must be at least 1 character long',
173
+ /** {max} is put in by the dialog: it knows its own limit. */
174
+ 'dialog.rename.tooLong': 'Name must be {max} characters or less',
175
+ /** What a screen reader says for the X that closes a window. */
176
+ 'dialog.close': 'Close modal',
177
+ // ===== Messages that pop up after an action =====
178
+ 'toast.rename.started': 'Renaming "{name}"...',
179
+ 'toast.rename.done': 'Item renamed',
180
+ 'toast.rename.doneDetail': 'Successfully renamed "{oldName}" to "{newName}"',
181
+ 'toast.rename.failed': 'Rename failed',
182
+ 'toast.rename.noChange': 'No changes were made',
183
+ 'toast.rename.noItem': 'No valid item selected',
184
+ 'toast.rename.unknownError': 'An unknown error occurred',
185
+ 'toast.delete.started': '{count, plural, one {Deleting "{name}"...} other {Deleting # items...}}',
186
+ 'toast.delete.doneFolder': 'Deleted folder "{name}"',
187
+ 'toast.delete.doneFile': 'Deleted "{name}"',
188
+ 'toast.delete.doneMany': '{count, plural, one {Deleted # item} other {Deleted # items}}',
189
+ 'toast.delete.doneFolderDetail': 'Folder and its contents were deleted successfully',
190
+ 'toast.delete.doneFileDetail': 'Item was deleted successfully',
191
+ 'toast.delete.doneManyDetail': '{count, plural, one {# item was deleted successfully} other {# items were deleted successfully}}',
192
+ 'toast.delete.doneNames': 'Deleted: {names}',
193
+ 'toast.delete.failedOne': 'Failed to delete "{name}"',
194
+ 'toast.delete.failedMany': '{count, plural, one {Failed to delete # item} other {Failed to delete # items}}',
195
+ 'toast.delete.failedNames': 'Failed to delete: {names}',
196
+ 'toast.delete.failedSome': 'Some items could not be deleted',
197
+ 'toast.delete.failedAll': 'Failed to delete items',
198
+ 'toast.folder.created': 'Folder created',
199
+ 'toast.folder.createdDetail': 'Created folder "{name}"',
200
+ 'toast.folder.failed': 'Failed to create folder',
201
+ 'toast.navigation.failed': 'Navigation failed',
202
+ 'toast.navigation.noFolder': 'Could not find the target folder location',
203
+ 'toast.navigation.error': 'An error occurred while navigating to the target folder',
204
+ 'toast.filesAdded': 'Files added',
205
+ 'toast.filesAddedDetail': '{count, plural, one {Added # file to the editor} other {Added # files to the editor}}',
206
+ // ===== Folders and items in the list =====
207
+ 'folder.currentLocation': 'current location',
208
+ 'folder.open': 'Open folder {name}',
209
+ 'folder.empty': 'Empty',
210
+ 'folder.itemCount': '{count, plural, one {# item} other {# items}}',
211
+ 'item.previewLabel': 'Preview {name}',
212
+ 'item.audioFile': 'Audio file',
213
+ 'item.documentFile': 'Document file',
214
+ 'item.deleteMissing': 'Delete missing file',
215
+ 'item.folder': 'Folder',
216
+ 'recent.title': 'Recent Files',
217
+ 'recent.empty': 'No recent files available!',
218
+ 'newFolder.alt': 'New Folder',
219
+ 'newFolder.label': 'New folder',
220
+ 'search.noResults': 'No results found',
221
+ 'menu.open': 'Open menu',
222
+ 'menu.moreOptions': 'More options',
223
+ // ===== The bar over a selection, and the list of selected files =====
224
+ 'toolbar.more': '+{count} more',
225
+ 'toolbar.moveMany': '{count, plural, one {Move # file} other {Move # files}}',
226
+ 'toolbar.deleteMany': '{count, plural, one {Delete # file} other {Delete # files}}',
227
+ 'selectedFiles.title': 'Selected files',
228
+ 'selectedFiles.empty': 'No files selected',
229
+ 'selectedFiles.count': '{count, plural, one {# file selected} other {# files selected}}',
230
+ 'selectedFiles.confirmMany': '{count, plural, one {Use # file} other {Use # files}}',
231
+ // ===== Search window =====
232
+ 'searchModal.placeholder': 'Search files and folders...',
233
+ 'searchModal.jumpToFolder': 'Jump to folder',
234
+ 'searchModal.empty': 'No files found',
235
+ // ===== Moving files =====
236
+ /** {name} is the file or folder, cut at 30 characters. */
237
+ 'moveDialog.titleOne': 'Move "{name}"',
238
+ 'moveDialog.titleMany': '{count, plural, one {Move # item} other {Move # items}}',
239
+ /** The name of the top of the library in the folder list of the move window. */
240
+ 'moveDialog.rootName': 'File browser',
241
+ 'moveDialog.movingTo': 'Moving to {name}',
242
+ 'moveDialog.confirmFolder': 'Move folder',
243
+ 'moveDialog.confirmItem': 'Move to folder',
244
+ 'moveDialog.confirmMany': '{count, plural, one {Move # item} other {Move # items}}',
245
+ 'moveDialog.failedFolder': 'Failed to move folder',
246
+ 'moveDialog.failedItems': 'Failed to move items',
247
+ 'moveDialog.noTarget': 'No target folder selected',
248
+ 'moveDialog.noItems': 'No items selected to move',
249
+ 'moveDialog.pickDestination': 'Please select a destination folder',
250
+ 'moveDialog.noneMoved': 'No items were moved successfully',
251
+ 'moveDialog.partialTitle': 'Some items moved',
252
+ /** {moved} of {total}. */
253
+ 'moveDialog.partialDetail': '{total, plural, other {Moved {moved} out of # items}}',
254
+ 'moveDialog.doneFolder': 'Folder moved',
255
+ 'moveDialog.doneOne': 'Item moved',
256
+ 'moveDialog.doneMany': 'Items moved',
257
+ 'moveDialog.doneFolderDetail': 'Moved folder "{name}" successfully',
258
+ 'moveDialog.doneItemsDetail': '{count, plural, one {Moved # item successfully} other {Moved # items successfully}}',
259
+ // ===== Previews =====
260
+ 'preview.audioFailed': 'Audio failed to load',
261
+ 'preview.audioUnsupported': 'Your browser does not support the audio element.',
262
+ 'preview.videoFailed': 'Video failed to load',
263
+ 'preview.videoUnsupported': 'Your browser does not support the video tag.',
264
+ 'preview.errorAlt': 'Error',
265
+ 'preview.fileNotFound': 'File not found',
266
+ 'preview.loading': 'Loading...',
267
+ 'preview.textFailed': 'Failed to load text file',
268
+ /** {reason} is what the server said ("Not Found"). */
269
+ 'preview.textFailedReason': 'Failed to load text file: {reason}',
270
+ 'preview.unavailable': 'Preview not available for this file type.',
271
+ 'preview.pdfLoading': 'Loading PDF...',
272
+ 'preview.pdfFailed': 'Failed to load PDF',
273
+ /** {page} and {total} are put in by the PDF viewer ({total} is "?" until the number of pages is known). */
274
+ 'preview.pdfPage': 'Page {page} of {total}',
275
+ 'preview.pdfPreviousPage': 'Previous page',
276
+ 'preview.pdfNextPage': 'Next page',
277
+ /** The sentence a font is shown in. Use a sentence that shows the letters of your language. */
278
+ 'fontPreview.sample': 'The quick brown fox jumps over the lazy dog',
279
+ 'fontPreview.sampleShort': 'The quick fox',
280
+ 'metadata.title': 'File Information',
281
+ 'metadata.name': 'Name:',
282
+ 'metadata.type': 'Type:',
283
+ 'metadata.size': 'Size:',
284
+ 'metadata.modified': 'Last Modified:',
285
+ 'metadata.notAvailable': 'N/A',
286
+ // ===== How long ago =====
287
+ 'date.fewSecondsAgo': 'A few seconds ago',
288
+ 'date.hoursAgo': '{count, plural, one {# hour ago} other {# hours ago}}',
289
+ 'date.daysAgo': '{count, plural, one {# day ago} other {# days ago}}',
290
+ 'date.weeksAgo': '{count, plural, one {# week ago} other {# weeks ago}}',
291
+ 'date.aboutAMonthAgo': 'About a month ago',
292
+ 'date.severalMonthsAgo': 'Several months ago',
293
+ 'date.overAYearAgo': 'Over a year ago'
294
+ };
@@ -0,0 +1,19 @@
1
+ import type { Translate } from './context';
2
+ /** A sentence cut around the words of it that are a link: what comes before, the link, what comes after. */
3
+ export interface SentenceWithLink {
4
+ before: string;
5
+ /** Empty when the sentence does not contain the link's words. */
6
+ link: string;
7
+ after: string;
8
+ }
9
+ /**
10
+ * Finds the words that act as a link inside a sentence, so the screen can underline just those. The two come from two
11
+ * messages (the sentence and the link), so a language can put the link anywhere in its sentence. A link that the
12
+ * sentence does not contain gives the sentence whole, with nothing underlined.
13
+ */
14
+ export declare function splitAround(sentence: string, link: string): SentenceWithLink;
15
+ /**
16
+ * The word for a kind of file ("image", "document", "SVG") in the page's language, for a sentence like "Upload image
17
+ * files". A kind the catalog has no word for is shown as it came.
18
+ */
19
+ export declare function kindWord(kind: string, translate: Translate): string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Finds the words that act as a link inside a sentence, so the screen can underline just those. The two come from two
3
+ * messages (the sentence and the link), so a language can put the link anywhere in its sentence. A link that the
4
+ * sentence does not contain gives the sentence whole, with nothing underlined.
5
+ */
6
+ export function splitAround(sentence, link) {
7
+ const index = link === '' ? -1 : sentence.indexOf(link);
8
+ if (index < 0)
9
+ return { before: sentence, link: '', after: '' };
10
+ return { before: sentence.slice(0, index), link, after: sentence.slice(index + link.length) };
11
+ }
12
+ /**
13
+ * The word for a kind of file ("image", "document", "SVG") in the page's language, for a sentence like "Upload image
14
+ * files". A kind the catalog has no word for is shown as it came.
15
+ */
16
+ export function kindWord(kind, translate) {
17
+ switch (kind) {
18
+ case 'any':
19
+ return translate('fileKind.any');
20
+ case 'svg':
21
+ return translate('fileKind.svg');
22
+ case 'document':
23
+ return translate('fileKind.document');
24
+ case 'image':
25
+ return translate('fileKind.image');
26
+ case 'video':
27
+ return translate('fileKind.video');
28
+ case 'audio':
29
+ return translate('fileKind.audio');
30
+ case 'font':
31
+ return translate('fileKind.font');
32
+ default:
33
+ return kind;
34
+ }
35
+ }
package/dist/index.d.ts CHANGED
@@ -3,5 +3,8 @@ export * from './components';
3
3
  export * from './stores';
4
4
  export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, type FileBrowserUploadConfig, } from './stores/uploadApiStore';
5
5
  export * from './utils';
6
+ export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
7
+ export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
8
+ export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
6
9
  export * from './types';
7
10
  export type { FileSystemItem, FileSystemRoot, FolderItemWithCount } from './types';
package/dist/index.js CHANGED
@@ -7,5 +7,9 @@ export * from './stores';
7
7
  export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, } from './stores/uploadApiStore';
8
8
  // Export all utilities
9
9
  export * from './utils';
10
+ export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
11
+ // Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
12
+ // a page or a build step can run on its own messages.
13
+ export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, } from './i18n';
10
14
  // Export types
11
15
  export * from './types';
@@ -0,0 +1,22 @@
1
+ import type { MediaLibraryCapabilities, MediaLibraryProvider } from './types';
2
+ /**
3
+ * What the File Browser offers when it was not given a media library: everything it has always offered. The Widgetic
4
+ * site and the editor use it this way, so they behave exactly as before.
5
+ */
6
+ export declare const LEGACY_CAPABILITIES: Readonly<MediaLibraryCapabilities>;
7
+ /**
8
+ * What the File Browser offers when the media library it was given cannot be used: nothing, so no button leads to
9
+ * something that cannot work. (The screen says what is wrong.)
10
+ */
11
+ export declare const NO_CAPABILITIES: Readonly<MediaLibraryCapabilities>;
12
+ /**
13
+ * What the File Browser offers for a library it was given.
14
+ *
15
+ * A library can only take actions away. Rename, Delete and Upload need the library's matching function, so the
16
+ * File Browser never shows a button that has nothing behind it.
17
+ *
18
+ * A library is one flat list of files, so New folder and Move are never offered: a folder made in the File Browser
19
+ * would exist only until the File Browser is closed, which looks like a feature that works and then loses the
20
+ * visitor's work. (Folders need a library that has folders of its own; the contract does not have them yet.)
21
+ */
22
+ export declare function capabilitiesOf(provider: Pick<MediaLibraryProvider, 'capabilities' | 'upload' | 'rename' | 'delete'>): MediaLibraryCapabilities;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What the File Browser offers when it was not given a media library: everything it has always offered. The Widgetic
3
+ * site and the editor use it this way, so they behave exactly as before.
4
+ */
5
+ export const LEGACY_CAPABILITIES = Object.freeze({
6
+ upload: true,
7
+ rename: true,
8
+ delete: true,
9
+ download: true,
10
+ folders: true
11
+ });
12
+ /**
13
+ * What the File Browser offers when the media library it was given cannot be used: nothing, so no button leads to
14
+ * something that cannot work. (The screen says what is wrong.)
15
+ */
16
+ export const NO_CAPABILITIES = Object.freeze({
17
+ upload: false,
18
+ rename: false,
19
+ delete: false,
20
+ download: false,
21
+ folders: false
22
+ });
23
+ /**
24
+ * What the File Browser offers for a library it was given.
25
+ *
26
+ * A library can only take actions away. Rename, Delete and Upload need the library's matching function, so the
27
+ * File Browser never shows a button that has nothing behind it.
28
+ *
29
+ * A library is one flat list of files, so New folder and Move are never offered: a folder made in the File Browser
30
+ * would exist only until the File Browser is closed, which looks like a feature that works and then loses the
31
+ * visitor's work. (Folders need a library that has folders of its own; the contract does not have them yet.)
32
+ */
33
+ export function capabilitiesOf(provider) {
34
+ const declared = provider.capabilities ?? {};
35
+ return {
36
+ upload: typeof provider.upload === 'function' && declared.upload !== false,
37
+ rename: typeof provider.rename === 'function' && declared.rename !== false,
38
+ delete: typeof provider.delete === 'function' && declared.delete !== false,
39
+ download: declared.download !== false,
40
+ folders: false
41
+ };
42
+ }
@@ -0,0 +1,17 @@
1
+ import type { ResolvedMediaLibrary } from './resolve';
2
+ import type { MediaLibraryCapabilities } from './types';
3
+ /**
4
+ * What the File Browser's parts need to know about the library, shared with them through Svelte's component context.
5
+ *
6
+ * Context belongs to one File Browser instance, so two File Browsers on a page (with two libraries) never mix.
7
+ */
8
+ export interface MediaLibraryContext {
9
+ /** The library the host supplied, or `null` when the File Browser works as it always has (legacy settings). */
10
+ library: ResolvedMediaLibrary | null;
11
+ /** Which actions to offer. Everything, when there is no library. */
12
+ capabilities: MediaLibraryCapabilities;
13
+ }
14
+ /** Called by the File Browser while it is created, so everything inside it can find the library. */
15
+ export declare function provideMediaLibraryContext(context: MediaLibraryContext): void;
16
+ /** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it reads as legacy. */
17
+ export declare function useMediaLibraryContext(): MediaLibraryContext;
@@ -0,0 +1,16 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { LEGACY_CAPABILITIES } from './capabilities';
3
+ const MEDIA_LIBRARY_CONTEXT_KEY = Symbol('widgetic-file-browser-media-library');
4
+ /** What a part of the File Browser sees when no library was supplied: the way it has always worked. */
5
+ const LEGACY_CONTEXT = Object.freeze({
6
+ library: null,
7
+ capabilities: LEGACY_CAPABILITIES
8
+ });
9
+ /** Called by the File Browser while it is created, so everything inside it can find the library. */
10
+ export function provideMediaLibraryContext(context) {
11
+ setContext(MEDIA_LIBRARY_CONTEXT_KEY, context);
12
+ }
13
+ /** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it reads as legacy. */
14
+ export function useMediaLibraryContext() {
15
+ return getContext(MEDIA_LIBRARY_CONTEXT_KEY) ?? LEGACY_CONTEXT;
16
+ }
@@ -0,0 +1,42 @@
1
+ import type { FileBrowserMessageKey } from '../i18n/messages';
2
+ import type { MessageValues } from '@widgetic/design-system/i18n';
3
+ import type { MediaLibraryErrorCode } from './types';
4
+ /** A failed call to a media library, with a reason the File Browser can act on. */
5
+ export declare class MediaLibraryError extends Error {
6
+ readonly code: MediaLibraryErrorCode;
7
+ /** The HTTP status behind the failure, when there was one. */
8
+ readonly status: number | undefined;
9
+ /**
10
+ * The catalog message that says the same thing in the visitor's language. Set when `message` is the File Browser's
11
+ * own English text (not one the library wrote): the visitor then reads the translation, while the `error` event and
12
+ * the console keep the English `message`. Absent when the library supplied the text, which is shown as it is.
13
+ */
14
+ readonly messageKey: FileBrowserMessageKey | undefined;
15
+ /** The values the message at `messageKey` asks for (a size limit, a count), when it asks for any. */
16
+ readonly messageValues: MessageValues | undefined;
17
+ constructor(code: MediaLibraryErrorCode, message: string, options?: {
18
+ status?: number;
19
+ cause?: unknown;
20
+ messageKey?: FileBrowserMessageKey;
21
+ messageValues?: MessageValues;
22
+ });
23
+ }
24
+ /** The error code that fits an HTTP status. */
25
+ export declare function codeForHttpStatus(status: number): MediaLibraryErrorCode;
26
+ /** True when something was cancelled with an AbortController (fetch and friends throw an `AbortError`). */
27
+ export declare function isAbortError(error: unknown): boolean;
28
+ /**
29
+ * True when a call ended because it was cancelled on purpose (the visitor pressed Cancel, or the File Browser was
30
+ * closed): either a raw `AbortError` or a {@link MediaLibraryError} coded `ABORTED`. Not a failure to show.
31
+ */
32
+ export declare function isCancellation(error: unknown): boolean;
33
+ /**
34
+ * Turns whatever a library's function threw (or rejected with) into a {@link MediaLibraryError}.
35
+ *
36
+ * A library is another party's code: it may throw an Error, a string, a fetch `Response`-like object or nothing at
37
+ * all. The visitor gets the library's own message when it has one, otherwise the File Browser's `fallbackMessage`
38
+ * (and, for the visitor's language, `fallbackKey`: the catalog message that says the same).
39
+ */
40
+ export declare function toMediaLibraryError(error: unknown, fallbackMessage: string, fallbackKey?: FileBrowserMessageKey): MediaLibraryError;
41
+ /** True when the failure means the credentials were refused, so refreshing them and trying again may help. */
42
+ export declare function isUnauthorized(error: unknown): boolean;
@@ -0,0 +1,114 @@
1
+ /** The longest message taken from a library's own error. Longer ones are cut so a toast stays readable. */
2
+ const MAX_MESSAGE_LENGTH = 300;
3
+ /** What Chrome, Firefox, Safari and React Native write in the TypeError of a `fetch` that could not reach the server. */
4
+ const BROWSER_NETWORK_FAILURE_TEXT = /failed to fetch|networkerror|network request failed|load failed/i;
5
+ /** A failed call to a media library, with a reason the File Browser can act on. */
6
+ export class MediaLibraryError extends Error {
7
+ code;
8
+ /** The HTTP status behind the failure, when there was one. */
9
+ status;
10
+ /**
11
+ * The catalog message that says the same thing in the visitor's language. Set when `message` is the File Browser's
12
+ * own English text (not one the library wrote): the visitor then reads the translation, while the `error` event and
13
+ * the console keep the English `message`. Absent when the library supplied the text, which is shown as it is.
14
+ */
15
+ messageKey;
16
+ /** The values the message at `messageKey` asks for (a size limit, a count), when it asks for any. */
17
+ messageValues;
18
+ constructor(code, message, options = {}) {
19
+ super(message);
20
+ this.name = 'MediaLibraryError';
21
+ this.code = code;
22
+ this.status = options.status;
23
+ this.messageKey = options.messageKey;
24
+ this.messageValues = options.messageValues;
25
+ if (options.cause !== undefined) {
26
+ this.cause = options.cause;
27
+ }
28
+ }
29
+ }
30
+ /** The error code that fits an HTTP status. */
31
+ export function codeForHttpStatus(status) {
32
+ if (status === 401)
33
+ return 'UNAUTHORIZED';
34
+ if (status === 403)
35
+ return 'FORBIDDEN';
36
+ if (status === 404)
37
+ return 'NOT_FOUND';
38
+ return 'FAILED';
39
+ }
40
+ /** True when something was cancelled with an AbortController (fetch and friends throw an `AbortError`). */
41
+ export function isAbortError(error) {
42
+ if (error === null || typeof error !== 'object')
43
+ return false;
44
+ return error.name === 'AbortError';
45
+ }
46
+ /**
47
+ * True when a call ended because it was cancelled on purpose (the visitor pressed Cancel, or the File Browser was
48
+ * closed): either a raw `AbortError` or a {@link MediaLibraryError} coded `ABORTED`. Not a failure to show.
49
+ */
50
+ export function isCancellation(error) {
51
+ return isAbortError(error) || (error instanceof MediaLibraryError && error.code === 'ABORTED');
52
+ }
53
+ /** The HTTP status a thrown value carries, if it carries one in any of the usual places. */
54
+ function statusOf(error) {
55
+ if (error === null || typeof error !== 'object')
56
+ return undefined;
57
+ const candidate = error;
58
+ for (const value of [candidate.status, candidate.statusCode, candidate.response?.status]) {
59
+ if (typeof value === 'number' && Number.isInteger(value) && value >= 100 && value <= 599)
60
+ return value;
61
+ }
62
+ return undefined;
63
+ }
64
+ /** The library's own words, cleaned and cut; `null` when it said nothing usable. */
65
+ function ownTextOf(text) {
66
+ if (typeof text !== 'string')
67
+ return null;
68
+ const trimmed = text.trim();
69
+ if (trimmed === '')
70
+ return null;
71
+ return trimmed.length > MAX_MESSAGE_LENGTH ? `${trimmed.slice(0, MAX_MESSAGE_LENGTH)}…` : trimmed;
72
+ }
73
+ /**
74
+ * Turns whatever a library's function threw (or rejected with) into a {@link MediaLibraryError}.
75
+ *
76
+ * A library is another party's code: it may throw an Error, a string, a fetch `Response`-like object or nothing at
77
+ * all. The visitor gets the library's own message when it has one, otherwise the File Browser's `fallbackMessage`
78
+ * (and, for the visitor's language, `fallbackKey`: the catalog message that says the same).
79
+ */
80
+ export function toMediaLibraryError(error, fallbackMessage, fallbackKey) {
81
+ if (error instanceof MediaLibraryError)
82
+ return error;
83
+ if (isAbortError(error)) {
84
+ return new MediaLibraryError('ABORTED', 'The request was cancelled', { cause: error });
85
+ }
86
+ const status = statusOf(error);
87
+ const ownText = ownTextOf(typeof error === 'string'
88
+ ? error
89
+ : error !== null && typeof error === 'object'
90
+ ? error.message
91
+ : undefined);
92
+ const message = ownText ?? fallbackMessage;
93
+ // Only the File Browser's own words are translated; what the library wrote is shown as it is.
94
+ const messageKey = ownText === null ? fallbackKey : undefined;
95
+ if (status !== undefined) {
96
+ return new MediaLibraryError(codeForHttpStatus(status), message, { status, cause: error, messageKey });
97
+ }
98
+ // `fetch` rejects with a TypeError when the server cannot be reached at all. The browser's own text for it
99
+ // ("Failed to fetch") is English whatever the visitor's language, so the visitor reads our sentence instead; the
100
+ // host's `error` event still carries what the browser said. A TypeError the library threw with words of its own
101
+ // is not a network failure, and its words are shown.
102
+ if (error instanceof TypeError) {
103
+ const isBrowserNetworkText = ownText !== null && BROWSER_NETWORK_FAILURE_TEXT.test(ownText);
104
+ return new MediaLibraryError('NETWORK', ownText ?? 'Could not reach the media library', {
105
+ cause: error,
106
+ messageKey: ownText === null || isBrowserNetworkText ? 'libraryError.unreachable' : undefined
107
+ });
108
+ }
109
+ return new MediaLibraryError('FAILED', message, { cause: error, messageKey });
110
+ }
111
+ /** True when the failure means the credentials were refused, so refreshing them and trying again may help. */
112
+ export function isUnauthorized(error) {
113
+ return error instanceof MediaLibraryError && error.code === 'UNAUTHORIZED';
114
+ }
@@ -0,0 +1,10 @@
1
+ export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest } from './types';
2
+ export { MediaLibraryError, isAbortError, isCancellation, isUnauthorized, toMediaLibraryError } from './errors';
3
+ export { LEGACY_CAPABILITIES, NO_CAPABILITIES, capabilitiesOf } from './capabilities';
4
+ export { appendNewFiles, createLibraryRoot, removeFiles, replaceFile, upsertFile } from './treeOps';
5
+ export { toSafeMediaUrl } from './urls';
6
+ export { normalizeMediaLibraryFile, normalizeMediaLibraryPage } from './normalize';
7
+ export { DEFAULT_LIBRARY_LABEL, resolveMediaLibrary, type ResolvedMediaLibrary } from './resolve';
8
+ export { loadLibraryPages, type LoadedLibrary } from './paging';
9
+ export { createWidgeticMediaLibrary, type TokenReason, type WidgeticMediaLibraryOptions } from './widgetic';
10
+ export { provideMediaLibraryContext, useMediaLibraryContext, type MediaLibraryContext } from './context';