@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
package/README.md CHANGED
@@ -61,6 +61,285 @@ pnpm link --global @widgetic/file-browser
61
61
  <FileBrowser />
62
62
  ```
63
63
 
64
+ ## Using your own media library
65
+
66
+ By default the File Browser shows the Widgetic account's uploads. A platform that already has a media library of its
67
+ own (a CMS, an S3 bucket, a DAM) can hand the File Browser that library instead, as plain functions. The File Browser
68
+ then lists, uploads, renames and deletes through those functions and never talks to Widgetic.
69
+
70
+ ```svelte
71
+ <script lang="ts">
72
+ import { FileBrowser, type MediaLibraryProvider } from '@widgetic/file-browser';
73
+
74
+ const mediaLibrary: MediaLibraryProvider = {
75
+ id: 'acme-assets',
76
+ label: 'Acme assets', // the title above the files. Default: "My uploads"
77
+
78
+ // Required. One page of the library, newest files first.
79
+ async list({ cursor, limit, signal }) {
80
+ const response = await fetch(`/api/assets?cursor=${cursor ?? ''}&limit=${limit}`, { signal });
81
+ if (!response.ok) throw Object.assign(new Error('Could not load your files'), { status: response.status });
82
+ const page = await response.json();
83
+ return {
84
+ items: page.assets.map((asset) => ({
85
+ id: asset.id,
86
+ name: asset.fileName,
87
+ url: asset.publicUrl,
88
+ mimeType: asset.contentType,
89
+ size: asset.bytes,
90
+ })),
91
+ nextCursor: page.next ?? null, // null (or leaving it out) means this was the last page
92
+ };
93
+ },
94
+
95
+ // Optional. Leave a function out and its button is not shown.
96
+ async upload({ file, onProgress, signal }) { /* store the file, call onProgress(0..100), return it as a MediaLibraryFile */ },
97
+ async rename({ id, name, signal }) { /* rename it; return the file as it is now, or nothing */ },
98
+ async delete({ id, signal }) { /* remove it */ },
99
+ };
100
+ </script>
101
+
102
+ <FileBrowser
103
+ {mediaLibrary}
104
+ on:select={(event) => console.log('picked', event.detail.files)}
105
+ on:error={(event) => console.warn('media library problem', event.detail)}
106
+ />
107
+ ```
108
+
109
+ ### What the File Browser does with a library
110
+
111
+ - **One flat list.** A media library has no folders, so there is no New folder, Move, breadcrumb or Recent files.
112
+ - **Pages.** It calls `list` with `limit: 100` and the previous page's `nextCursor` until there is no next page. It
113
+ reads at most **1,000 files** (and at most 50 pages) and then shows "Only the newest files are shown." Search and
114
+ the type filter only look at the files that were loaded.
115
+ - **Only the actions the library can do.** Upload needs `upload`, Rename needs `rename`, Delete needs `delete`.
116
+ Download is always offered. `capabilities` can switch actions off (`capabilities: { delete: false }`), never on.
117
+ - **Nothing is kept on the visitor's device.** No local cache, no saved file tree, and the picked files are not
118
+ remembered between visits (a shared browser must not show the next visitor the previous one's picks). Pass
119
+ `persistSelection` to keep them anyway.
120
+ - **Library mode ignores** `data`, `useDemoContent`, `enableLocalCache` and the Widgetic upload settings.
121
+ - **The library's own failures are shown as they are.** The message of the error you throw reaches the visitor (cut
122
+ at 300 characters): a screen with "Try again" when the first page cannot be read, a notice when a later page fails,
123
+ a message in the upload panel, a toast for rename and delete. Toasts are drawn by the design system's
124
+ `<ToasterModal />`: **pass `renderToaster` and the File Browser draws one itself**, in the language of `locale` and
125
+ `messages` (`toast.regionLabel` and `toast.closeLabel` are what a screen reader hears). An app that renders its own
126
+ `<ToasterModal />` (the Widgetic site's layout does) leaves `renderToaster` off, or its toasts would be drawn twice.
127
+ With neither, a refused rename or delete shows the visitor nothing and the `error` event is the only sign.
128
+ - **Calls are given 30 seconds** (`list`, `rename`, `delete`). An upload has no time limit, the visitor can cancel it.
129
+ `signal` is aborted when the visitor cancels, or the File Browser is closed: stop your request then.
130
+
131
+ ### A file (`MediaLibraryFile`)
132
+
133
+ | Field | | |
134
+ | --- | --- | --- |
135
+ | `id` | required | Stable and unique in the library. Handed back unchanged on `select`, `rename` and `delete`. |
136
+ | `name` | required | Shown to the visitor, with its extension (`logo.png`). |
137
+ | `url` | required | Where the visitor's browser fetches the file. |
138
+ | `mimeType` | optional | Tells images, audio, video and documents apart when the extension cannot (see below). |
139
+ | `size` | optional | Bytes. |
140
+ | `modified` | optional | ISO 8601 string, `Date`, or milliseconds since 1970. |
141
+ | `thumbnail` | optional | A small preview picture. Without it an image is drawn from `url` and any other file gets its type icon. |
142
+ | `hash` | optional | Handed back as is. Never interpreted. |
143
+
144
+ **Which tab a file lands under** (Images, Video, Audio, Documents, Fonts, SVG) is decided in this order: the
145
+ extension in its `url`, the extension in its `name`, then its `mimeType`. A file nothing says anything about is a
146
+ document. So `/media/8f3a2c` with `name: 'logo.png'`, or a `blob:` address with `mimeType: 'image/png'`, is an image.
147
+ Give a `name` with its extension, or a `mimeType`, whenever your addresses carry no extension: otherwise those files
148
+ only show up under "All" and "Documents".
149
+
150
+ Everything a library returns is treated as untrusted. A file without an `id`, `name` or usable `url`, or with a
151
+ duplicate `id`, is skipped (with a console warning) instead of breaking the list. Ids longer than 512 characters are
152
+ refused, names longer than 255 are cut, and a page uses at most its first 1,000 files. Addresses must be `http:`,
153
+ `https:`, a path on the page's own site, or `blob:`; a thumbnail may also be a small `data:` picture. `javascript:`
154
+ and every other kind of address is refused. Names are always shown as text, never as HTML.
155
+
156
+ A file on another website needs a CORS header (`Access-Control-Allow-Origin`) for the previews that read it with a
157
+ script: text, PDF and font previews. Pictures, audio and video are shown without it.
158
+
159
+ ### Errors
160
+
161
+ Throw anything from a library function: an `Error` (its message is shown), or an object with a `status` (HTTP). The
162
+ File Browser maps it to a code:
163
+
164
+ | Code | When |
165
+ | --- | --- |
166
+ | `UNAUTHORIZED` | `status` 401 |
167
+ | `FORBIDDEN` | `status` 403 |
168
+ | `NOT_FOUND` | `status` 404 |
169
+ | `NETWORK` | `fetch` could not reach the server (a `TypeError`) |
170
+ | `INVALID_RESPONSE` | `list` did not answer with `{ items: [...] }`, or keeps returning the same files |
171
+ | `NOT_SUPPORTED` | the library has no function for this (for example no `upload`) |
172
+ | `FAILED` | anything else |
173
+
174
+ An `AbortError` is a cancellation, not a failure: nothing is shown and no `error` event is sent.
175
+
176
+ ### Events
177
+
178
+ - `select` — `{ files }`: the files the visitor picked, as the File Browser holds them (`id`, `name`, `url`, ...).
179
+ - `error` — `{ message, code, action, file? }` for a problem with the library. `action` is `setup` (the
180
+ `mediaLibrary` option is not a media library), `load`, `upload`, `rename` or `delete`; `file` is the file name for an
181
+ upload. Listen to it to log problems or to refresh your own token (`UNAUTHORIZED`).
182
+
183
+ ### The Widgetic library as a provider
184
+
185
+ `createWidgeticMediaLibrary({ apiBasePath, getAccessToken })` is the Widgetic upload library (`GET /v1/uploads`,
186
+ `POST /v1/uploads`) as a provider. `getAccessToken('initial' | 'expired', refusedToken?)` is called before every
187
+ request, and again with `'expired'` (and the token the API refused) when it answers 401, after which the request is
188
+ tried once more. It has no Rename or Delete: the API cannot do them yet.
189
+
190
+ ## Languages
191
+
192
+ The File Browser shows English until it is told otherwise. Two props change that, a third says which way it is read, and
193
+ all of them can change while the File Browser is open:
194
+
195
+ ```svelte
196
+ <FileBrowser
197
+ locale="de"
198
+ messages={{
199
+ 'action.cancel': 'Abbrechen',
200
+ 'action.delete': 'Löschen',
201
+ 'toolbar.deleteMany': '{count, plural, one {# Datei löschen} other {# Dateien löschen}}',
202
+ }}
203
+ />
204
+ ```
205
+
206
+ - **`locale`** is a BCP 47 language tag (`de`, `pt-BR`, `ar-EG`). It decides the plural rules and how numbers, dates,
207
+ "2 days ago" and file sizes are written (all through `Intl`). It translates nothing. Blank or left out is English. A
208
+ tag the browser does not know is said once in the console and numbers and dates stay English.
209
+ - **`messages`** replaces words. Every word the File Browser shows is a message with a key; give the keys you want
210
+ to change and every key you leave out stays English, so a language can be added one screen at a time. A key that does
211
+ not exist is ignored and the console says which key you probably meant.
212
+ - **`dir`** is `'ltr'` or `'rtl'`. It is not a word and it is not taken from `locale`: it says which way the screen is
213
+ read, and `dir="rtl"` turns the File Browser around for a language that is written right to left. Left out, the File
214
+ Browser is read the way the screen around it is (inside the composition editor it turns around with it), and left to right
215
+ when nothing around it says. See "Right to left" below.
216
+
217
+ `FILE_BROWSER_MESSAGES` is the list: an object of every key and its English text (the keys are grouped by where the words
218
+ appear), and it is the list to hand to a translator:
219
+
220
+ ```ts
221
+ import { FILE_BROWSER_MESSAGES } from '@widgetic/file-browser';
222
+
223
+ console.log(Object.keys(FILE_BROWSER_MESSAGES).length); // every word of the File Browser
224
+ console.log(FILE_BROWSER_MESSAGES['toolbar.deleteMany']); // '{count, plural, one {Delete # file} other {Delete # files}}'
225
+ ```
226
+
227
+ | Keys start with | The words of |
228
+ | --- | --- |
229
+ | `action.`, `list.separator` | buttons that appear in several places (Cancel, Delete, Rename, Select, Add to Editor) |
230
+ | `search.`, `filter.`, `filterName.`, `filterOption.`, `sort.`, `breadcrumbs.` | the bar above the files and the path |
231
+ | `empty.` | what the list says when there is nothing to show |
232
+ | `library.`, `libraryError.` | the page's own media library: its name, and what the File Browser says when it gave no reason |
233
+ | `size.`, `date.` | file sizes ("1.5 MB") and "2 days ago" |
234
+ | `fileKind.`, `fileTypes.` | the kinds of file inside a sentence ("Upload image files") |
235
+ | `upload.` | the upload panel, its progress and its problems |
236
+ | `dialog.` | Rename, New folder and Delete: titles, hints and the sentences about a name that is not allowed |
237
+ | `toast.` | the messages that pop up after an action |
238
+ | `folder.`, `item.`, `recent.`, `menu.`, `newFolder.` | folders and items in the list, and their menus |
239
+ | `selectedFiles.`, `toolbar.` | the bar over a selection and the list of selected files |
240
+ | `searchModal.`, `moveDialog.` | the search window and the Move window |
241
+ | `preview.`, `metadata.`, `fontPreview.` | the previews and the details of a file |
242
+
243
+ ### Writing a message
244
+
245
+ A message is text. Two kinds of `{...}` have a meaning:
246
+
247
+ | Write | It shows |
248
+ | --- | --- |
249
+ | `{name}` | a value the File Browser puts in. A number is written the way the locale writes numbers (`1,234` or `1.234`). |
250
+ | `{count, plural, one {# file} other {# files}}` | the branch that fits the number in the page's language. `other` is required; `=0 {none}` matches exactly 0; `#` is the number. A language with more forms says so: Polish uses `one`, `few`, `many` and `other`. |
251
+
252
+ `\{`, `\}`, `\#` and `\\` write that character itself. An apostrophe is only an apostrophe: `Delete '{name}'?` works.
253
+ Each English message names the values it is given (`'filter.by': 'Filter by {type}'`): a translation may leave one out,
254
+ and it may use a value in any order, but it cannot ask for a value the message is never given (it would show as
255
+ written, `{kind}`).
256
+
257
+ ```ts
258
+ // Polish: "1 plik", "2 pliki", "5 plików", "1,5 pliku"
259
+ 'toolbar.deleteMany': '{count, plural, one {Usuń # plik} few {Usuń # pliki} many {Usuń # plików} other {Usuń # pliku}}'
260
+ ```
261
+
262
+ ### Finding a mistake before a visitor does
263
+
264
+ `checkFileBrowserMessages(messages)` checks a `messages` object without showing anything, and `describeMessageProblem`
265
+ turns each problem into a sentence. It finds a key that does not exist (with the nearest real one), a value that is not
266
+ text, a template that does not parse, and a message that asks for a value it is never given. An empty list means every
267
+ message will be used. Put it in a test of your page:
268
+
269
+ ```ts
270
+ import { checkFileBrowserMessages, describeMessageProblem } from '@widgetic/file-browser';
271
+ import german from './file-browser.de.json';
272
+
273
+ expect(checkFileBrowserMessages(german).map(describeMessageProblem)).toEqual([]);
274
+ ```
275
+
276
+ While the File Browser runs, a message that cannot be used is never thrown: the English text of that key is shown and
277
+ the console says `[FileBrowser] ...` once.
278
+
279
+ ### Right to left
280
+
281
+ Arabic, Hebrew, Persian, Urdu and the other languages that are written from right to left start a line on the right.
282
+ `dir="rtl"` makes the File Browser read that way, and `resolveTextDirection(locale)` from `@widgetic/design-system/i18n`
283
+ answers "which way is this language written" (`'rtl'` or `'ltr'`, never an error, `'ltr'` for a blank or unreadable tag):
284
+
285
+ ```svelte
286
+ <script>
287
+ import { FileBrowser } from '@widgetic/file-browser';
288
+ import { resolveTextDirection } from '@widgetic/design-system/i18n';
289
+
290
+ export let locale = 'ar';
291
+ </script>
292
+
293
+ <FileBrowser {locale} dir={resolveTextDirection(locale)} />
294
+ ```
295
+
296
+ - **`dir` is a prop of its own.** The File Browser is also a part of other screens (the file picker of the composition
297
+ editor, and so the widget creator), and the screen around it decides, not the words: the File Browser in a picker inside
298
+ an Arabic editor is read right to left whatever its own `locale`, and one inside an English editor left to right. Left out,
299
+ it follows that screen (a component above it that calls `provideTextDirection(store)` from
300
+ `@widgetic/design-system/components/textDirection`); a `dir` that is given wins over it. The page around it does not
301
+ decide either: a File Browser on a page that is written right to left stays left to right until it is given
302
+ `dir="rtl"` or sits in a screen that is.
303
+ - **What turns around.** The list starts on the right and the row that does not fit goes on under it. The search box, the
304
+ sort and filter controls, the selection bar, the path bar, the upload panel and the windows (Rename, New folder, Delete,
305
+ Move, search, the selected files and the preview) are laid out from the right, and the close button of a window is in the
306
+ corner where a line starts. Menus open toward the end of the line, and the pop-up of an action comes up in the bottom
307
+ corner where a line starts. Arrows that mean back and forward are mirrored; in the preview the arrow key that points
308
+ toward the end of the line goes on to the next file.
309
+ - **Names of files and folders** are read by their own first letter (`dir="auto"`), so a Latin name such as
310
+ `2024 report.pdf` is not put in the wrong order in a row of Arabic ones. On a left to right screen nothing is added.
311
+ - **A name inside a sentence** ("Failed to delete 2024 report.pdf") sits between two invisible marks, the Unicode
312
+ isolates U+2068 and U+2069, whenever `locale` is a language written right to left, so the words around it cannot turn it
313
+ around (a name that starts with a digit or has a hyphen would be). A screen reader does not say them; a test that
314
+ compares the text of a pop-up has to leave them out. The translator does this for every package that uses it, whatever
315
+ `dir` says.
316
+ - **What stays left to right on purpose:** the time line of the video player, because time runs from left to right in every
317
+ language.
318
+ - **Not looked at in a browser yet:** the folder tree, the Move window, the search window and the list of recent files use
319
+ the same placement as the rest and are covered by the source check below, but no browser test opens them in Arabic.
320
+ - **Keeping it so.** `tests/rtl/sourcePlacement.test.ts` reads the whole source with `auditPhysicalPlacement` from
321
+ `@widgetic/design-system/rtl/audit` and fails on a class or a style that puts something on a physical side (`left`,
322
+ `right`, `ml-`, `pr-`, `text-left`, `border-l`, `rounded-tl` ...). Write the logical one (`start`, `end`, `ms-`, `pe-`,
323
+ `text-start`, `border-s`, `rounded-ss`) or say why with the note `rtl-ok` on the same line or the line above.
324
+
325
+ ### What stays as it is
326
+
327
+ - **Words that belong to someone else.** The File Browser shows what your media library says as it says it: the message
328
+ of an error you throw from `list`, `upload`, `rename` or `delete` is not translated (the `libraryError.` messages are
329
+ only used when the library gave no reason), and neither are your file names, your library's `label`, or the names
330
+ of folders a visitor made. The same goes for a sentence Widgetic's API sends back.
331
+ - **`error` events.** `event.detail.message` stays English: it is for your logs, not for the visitor.
332
+ - **Right to left.** The words and the numbers follow `locale` and the layout follows `dir`; the two are set apart on
333
+ purpose (see "Right to left" above), so a page that gives a right to left `locale` and no `dir` has the words in
334
+ Arabic and a layout that reads left to right.
335
+ - **The design system.** The File Browser needs `@widgetic/design-system` **0.5.16 or newer**. Its words are made by the
336
+ design system's `@widgetic/design-system/i18n` (the same translator the editor and the other packages use), and the
337
+ words of the Rename and New folder windows, the close button of every window, the path bar and the PDF viewer come
338
+ from the design system too. With an older one the File Browser does not load: update the design system.
339
+
340
+ The `@widgetic/ui-sdk` module of the File Browser takes the same `locale` and `messages`, and adds `setLanguage()`; see
341
+ its README, "Speaking your visitors' language".
342
+
64
343
  ## Available Components
65
344
 
66
345
  The package exports all components from:
@@ -1,6 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { FileSystemItem } from '../types';
3
3
  import { getFolderIcon } from '../utils/folderUtils';
4
+ import { useI18n } from '../i18n';
5
+ import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
4
6
  // Import IconArrowBounce
5
7
  import { IconArrowBounce } from '@widgetic/design-system/icons';
6
8
 
@@ -17,11 +19,16 @@
17
19
  // New props for custom styling
18
20
  export let customClasses = "";
19
21
  export let iconSize = "40"; // Now expecting a number string for direct width/height
20
- export let textClass = "text-base flex-grow text-left";
22
+ export let textClass = "text-base flex-grow text-start";
21
23
  export let selectedIconClass = "w-5 h-5 text-[hsl(var(--info))]";
22
- export let currentLocationClass = "text-sm text-[hsl(var(--info))] mr-2";
24
+ export let currentLocationClass = "text-sm text-[hsl(var(--info))] me-2";
23
25
  export let selectedIcon = IconArrowBounce;
24
26
 
27
+ const { t } = useI18n();
28
+ // The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
29
+ const textDirection = useTextDirection();
30
+ $: nameDirection = dirForUserText($textDirection);
31
+
25
32
  // Filter children to only include folders
26
33
  $: folderChildren = folder.children?.filter(item => item.type === 'folder') || [];
27
34
  $: isSelected = selectedFolder?.id === folder.id;
@@ -63,18 +70,18 @@
63
70
  />
64
71
  </div>
65
72
  </div>
66
- <span class="flex-grow text-left {isCurrentLocation ? 'text-[hsl(var(--grey3))]' : 'text-[hsl(var(--grey7))]'} {isSelected ? 'font-bold' : 'font-normal'} body-medium truncate">{folder.name}</span>
67
- <div class="flex items-center ml-auto">
73
+ <span dir={nameDirection} class="flex-grow text-start {isCurrentLocation ? 'text-[hsl(var(--grey3))]' : 'text-[hsl(var(--grey7))]'} {isSelected ? 'font-bold' : 'font-normal'} body-medium truncate">{folder.name}</span>
74
+ <div class="flex items-center ms-auto">
68
75
  {#if isCurrentLocation}
69
- <span class="h6 text-[hsl(var(--sage-green))] relative z-10">current location</span>
76
+ <span class="h6 text-[hsl(var(--sage-green))] relative z-10">{$t('folder.currentLocation')}</span>
70
77
  {/if}
71
78
  {#if isSelected}
72
- <svelte:component this={selectedIcon} class="{selectedIconClass}" />
79
+ <svelte:component this={selectedIcon} class="{selectedIconClass} rtl:-scale-x-100" />
73
80
  {/if}
74
81
  </div>
75
82
  </button>
76
83
  {#if folderChildren.length > 0}
77
- <div class="pl-8">
84
+ <div class="ps-8">
78
85
  {#each folderChildren as child}
79
86
  <svelte:self
80
87
  folder={child}
@@ -102,7 +109,7 @@
102
109
  .folder-item::before {
103
110
  content: '';
104
111
  position: absolute;
105
- left: 0;
112
+ inset-inline-start: 0;
106
113
  top: 0;
107
114
  bottom: 0;
108
115
  width: 2px;
@@ -112,7 +119,7 @@
112
119
 
113
120
  /* Apply appropriate padding for icon placement */
114
121
  .folder-button {
115
- padding-right: 24px;
122
+ padding-inline-end: 24px;
116
123
  }
117
124
 
118
125
  /* Explicitly handle the selected state to override the default hover */
@@ -13,14 +13,10 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
13
13
  z_$$bindings?: Bindings;
14
14
  }
15
15
  declare const FolderTree: $$__sveltets_2_IsomorphicComponent<{
16
- folder: FileSystemItem & {
17
- displayChildren?: FileSystemItem[];
18
- };
16
+ folder: any;
19
17
  selectedFolder: FileSystemItem | undefined;
20
18
  immediateParentId: string | null;
21
- onSelect: (folder: FileSystemItem & {
22
- displayChildren?: FileSystemItem[];
23
- }) => void;
19
+ onSelect: (folder: any) => void;
24
20
  getFolderIconForItem: (folder: FileSystemItem) => string;
25
21
  customClasses?: string;
26
22
  iconSize?: string;