@widgetic/file-browser 0.5.48 → 0.5.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/dragSelectedToFolder.js +115 -104
- package/dist/components/FolderTree.svelte.d.ts +7 -4
- package/dist/components/core/FileBrowser.svelte +1 -3
- package/dist/components/core/dropzoneClick.js +2 -3
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/config.js +3 -4
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +3 -4
- package/dist/mediaLibrary/context.js +3 -4
- package/dist/mediaLibrary/errors.js +35 -46
- package/dist/mediaLibrary/normalize.js +42 -45
- package/dist/mediaLibrary/paging.js +45 -100
- package/dist/mediaLibrary/resolve.js +95 -214
- package/dist/mediaLibrary/treeOps.js +20 -40
- package/dist/mediaLibrary/urls.js +10 -12
- package/dist/mediaLibrary/widgetic.js +54 -140
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +37 -44
- package/dist/stores/folderCountStore.js +11 -12
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +178 -217
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +94 -117
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +1 -0
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +42 -57
- package/dist/utils/dateUtils.js +9 -11
- package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
- package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
- package/dist/utils/dragToFolder/springStep.js +3 -4
- package/dist/utils/fileGoneProbe.js +16 -65
- package/dist/utils/fileKinds.js +13 -14
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +332 -440
- package/dist/utils/fileTypes.js +14 -19
- package/dist/utils/fileUtils.js +31 -85
- package/dist/utils/folderUtils.js +4 -5
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +15 -26
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +4 -5
- package/dist/utils/imageTransform.js +14 -27
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +39 -55
- package/dist/utils/pendingUploadDeletes.js +113 -289
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +11 -13
- package/dist/utils/previewNavigation.js +7 -10
- package/dist/utils/recentFiles.js +6 -16
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.js +29 -61
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +12 -14
- package/dist/utils/searchDropdownPhase.js +2 -2
- package/dist/utils/searchItems.js +14 -30
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.js +36 -111
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.js +66 -138
- package/dist/utils/uploadListReconcile.js +11 -24
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +11 -13
- package/dist/utils/uploadRefusals.js +24 -40
- package/dist/utils/uploadResponseMapping.js +8 -9
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +133 -270
- package/dist/utils/videoFrame.js +2 -2
- package/dist/utils/widgeticDelete.js +30 -103
- package/dist/utils/widgeticTusUpload.js +105 -189
- package/dist/utils/widgeticUpload.js +62 -130
- package/dist/utils/xhrMultipartUpload.js +116 -164
- package/package.json +1 -1
|
@@ -1,69 +1,44 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
/**
|
|
22
2
|
* Takes every item whose id is in `ids` out of the tree, at any depth. A folder goes with everything in it (the files in a
|
|
23
3
|
* folder are not listed on their own: they come back with the folder).
|
|
24
4
|
*/
|
|
25
5
|
export function removeItemsFromTree(root, ids) {
|
|
26
|
-
|
|
6
|
+
const removed = [];
|
|
27
7
|
function walk(node, parentId) {
|
|
28
|
-
|
|
8
|
+
const children = node.children;
|
|
29
9
|
if (!children || children.length === 0)
|
|
30
10
|
return node;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
children.forEach(
|
|
11
|
+
const kept = [];
|
|
12
|
+
let changed = false;
|
|
13
|
+
children.forEach((child, index) => {
|
|
34
14
|
if (ids.has(child.id)) {
|
|
35
|
-
removed.push({ item: child, parentId
|
|
15
|
+
removed.push({ item: child, parentId, index });
|
|
36
16
|
changed = true;
|
|
37
17
|
return;
|
|
38
18
|
}
|
|
39
|
-
|
|
19
|
+
const nextChild = child.type === 'folder' ? walk(child, child.id) : child;
|
|
40
20
|
if (nextChild !== child)
|
|
41
21
|
changed = true;
|
|
42
22
|
kept.push(nextChild);
|
|
43
23
|
});
|
|
44
|
-
return changed ?
|
|
24
|
+
return changed ? { ...node, children: kept } : node;
|
|
45
25
|
}
|
|
46
|
-
|
|
47
|
-
return { root: nextRoot, removed
|
|
26
|
+
const nextRoot = walk(root, null);
|
|
27
|
+
return { root: nextRoot, removed };
|
|
48
28
|
}
|
|
49
29
|
/** Every file in an item: the item itself when it is a file, else the files of its folders, at any depth. */
|
|
50
30
|
export function filesOfItems(items) {
|
|
51
|
-
|
|
31
|
+
const files = [];
|
|
52
32
|
function walk(node) {
|
|
53
|
-
var _a;
|
|
54
33
|
if (node.type === 'file') {
|
|
55
34
|
files.push(node);
|
|
56
35
|
return;
|
|
57
36
|
}
|
|
58
|
-
for (
|
|
59
|
-
var child = _b[_i];
|
|
37
|
+
for (const child of node.children ?? [])
|
|
60
38
|
walk(child);
|
|
61
|
-
}
|
|
62
39
|
}
|
|
63
|
-
for (
|
|
64
|
-
var item = items_1[_i];
|
|
40
|
+
for (const item of items)
|
|
65
41
|
walk(item);
|
|
66
|
-
}
|
|
67
42
|
return files;
|
|
68
43
|
}
|
|
69
44
|
/**
|
|
@@ -71,54 +46,47 @@ export function filesOfItems(items) {
|
|
|
71
46
|
* is not made again: the item goes to the root. An item whose id is already in the tree is left as it is.
|
|
72
47
|
*/
|
|
73
48
|
export function putItemsBackInTree(root, removed) {
|
|
74
|
-
var _a;
|
|
75
49
|
if (removed.length === 0)
|
|
76
50
|
return root;
|
|
77
|
-
|
|
51
|
+
const knownIds = new Set();
|
|
78
52
|
(function collect(node) {
|
|
79
|
-
var _a;
|
|
80
53
|
knownIds.add(node.id);
|
|
81
|
-
for (
|
|
82
|
-
var child = _b[_i];
|
|
54
|
+
for (const child of node.children ?? [])
|
|
83
55
|
collect(child);
|
|
84
|
-
}
|
|
85
56
|
})(root);
|
|
86
57
|
// Ascending positions, so that several items of one folder go back one after the other without moving each other.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (
|
|
90
|
-
var entry = ordered_1[_i];
|
|
58
|
+
const ordered = [...removed].sort((a, b) => a.index - b.index);
|
|
59
|
+
const byParent = new Map();
|
|
60
|
+
for (const entry of ordered) {
|
|
91
61
|
if (knownIds.has(entry.item.id))
|
|
92
62
|
continue;
|
|
93
|
-
|
|
94
|
-
byParent.set(parentId,
|
|
63
|
+
const parentId = entry.parentId !== null && knownIds.has(entry.parentId) ? entry.parentId : null;
|
|
64
|
+
byParent.set(parentId, [...(byParent.get(parentId) ?? []), entry]);
|
|
95
65
|
}
|
|
96
66
|
if (byParent.size === 0)
|
|
97
67
|
return root;
|
|
98
68
|
function withItemsInserted(children, entries) {
|
|
99
|
-
|
|
100
|
-
for (
|
|
101
|
-
var entry = entries_1[_i];
|
|
69
|
+
const next = [...children];
|
|
70
|
+
for (const entry of entries)
|
|
102
71
|
next.splice(Math.min(entry.index, next.length), 0, entry.item);
|
|
103
|
-
}
|
|
104
72
|
return next;
|
|
105
73
|
}
|
|
106
74
|
function walk(node, nodeKey) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
75
|
+
const entries = byParent.get(nodeKey);
|
|
76
|
+
let children = node.children;
|
|
77
|
+
let changed = false;
|
|
110
78
|
if (children) {
|
|
111
|
-
|
|
112
|
-
if (walked.some(
|
|
79
|
+
const walked = children.map((child) => (child.type === 'folder' ? walk(child, child.id) : child));
|
|
80
|
+
if (walked.some((child, position) => child !== children[position])) {
|
|
113
81
|
children = walked;
|
|
114
82
|
changed = true;
|
|
115
83
|
}
|
|
116
84
|
}
|
|
117
85
|
if (entries && entries.length > 0) {
|
|
118
|
-
children = withItemsInserted(children
|
|
86
|
+
children = withItemsInserted(children ?? [], entries);
|
|
119
87
|
changed = true;
|
|
120
88
|
}
|
|
121
|
-
return changed ?
|
|
89
|
+
return changed ? { ...node, children } : node;
|
|
122
90
|
}
|
|
123
91
|
return walk(root, null);
|
|
124
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
|
|
2
2
|
export function buildFileUrl(basePath, filePath) {
|
|
3
3
|
if (!filePath)
|
|
4
4
|
return filePath;
|
|
@@ -6,14 +6,14 @@ export function buildFileUrl(basePath, filePath) {
|
|
|
6
6
|
return filePath;
|
|
7
7
|
}
|
|
8
8
|
if (!basePath)
|
|
9
|
-
return filePath.startsWith('/') ? filePath :
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
return filePath.startsWith('/') ? filePath : `/${filePath}`;
|
|
10
|
+
const normalizedBase = basePath.endsWith('/') ? basePath : `${basePath}/`;
|
|
11
|
+
const cleanPath = filePath.startsWith('/') ? filePath : `/${filePath}`;
|
|
12
12
|
if (cleanPath.startsWith(normalizedBase)) {
|
|
13
13
|
return cleanPath;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return
|
|
15
|
+
const cleanRelative = filePath.startsWith('/') ? filePath.slice(1) : filePath;
|
|
16
|
+
return `${normalizedBase}${cleanRelative}`;
|
|
17
17
|
}
|
|
18
18
|
export function resolveFileItemUrl(item, basePath) {
|
|
19
19
|
if (item.type !== 'file' || !item.url)
|
package/dist/utils/safeText.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* A name like `x"; } body { display: none }` is a fine file name for a library to hold. These helpers make sure it
|
|
5
5
|
* can only ever be shown, never run as markup or style.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const HTML_ENTITIES = {
|
|
8
8
|
'&': '&',
|
|
9
9
|
'<': '<',
|
|
10
10
|
'>': '>',
|
|
@@ -13,7 +13,7 @@ var HTML_ENTITIES = {
|
|
|
13
13
|
};
|
|
14
14
|
/** Makes text safe to put inside HTML: `& < > " '` become entities. */
|
|
15
15
|
export function escapeHtml(text) {
|
|
16
|
-
return text.replace(/[&<>"']/g,
|
|
16
|
+
return text.replace(/[&<>"']/g, (character) => HTML_ENTITIES[character]);
|
|
17
17
|
}
|
|
18
18
|
function escapeRegExp(text) {
|
|
19
19
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -30,17 +30,15 @@ export function highlightMatchesAsHtml(name, term, highlightClass) {
|
|
|
30
30
|
if (!term)
|
|
31
31
|
return escapeHtml(name);
|
|
32
32
|
// One capturing group, so `split` keeps the matches at the odd positions.
|
|
33
|
-
|
|
33
|
+
const parts = name.split(new RegExp(`(${escapeRegExp(term)})`, 'gi'));
|
|
34
34
|
return parts
|
|
35
|
-
.map(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
: escapeHtml(part);
|
|
39
|
-
})
|
|
35
|
+
.map((part, index) => index % 2 === 1
|
|
36
|
+
? `<span class="${escapeHtml(highlightClass)}">${escapeHtml(part)}</span>`
|
|
37
|
+
: escapeHtml(part))
|
|
40
38
|
.join('');
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const MAX_FONT_FAMILY_LENGTH = 64;
|
|
41
|
+
const FALLBACK_FONT_FAMILY = 'Uploaded font';
|
|
44
42
|
/**
|
|
45
43
|
* The name a font file is registered and styled under: its file name without the extension, reduced to letters,
|
|
46
44
|
* digits, spaces, underscores and hyphens.
|
|
@@ -50,8 +48,8 @@ var FALLBACK_FONT_FAMILY = 'Uploaded font';
|
|
|
50
48
|
* registered and where it is used, so the two always agree.
|
|
51
49
|
*/
|
|
52
50
|
export function toSafeFontFamilyName(fileName) {
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
const withoutExtension = typeof fileName === 'string' ? fileName.replace(/\.[^/.]+$/, '') : '';
|
|
52
|
+
const safeName = withoutExtension
|
|
55
53
|
.replace(/[^\p{L}\p{N} _-]/gu, '')
|
|
56
54
|
.trim()
|
|
57
55
|
.slice(0, MAX_FONT_FAMILY_LENGTH)
|
|
@@ -63,6 +61,6 @@ export function toSafeFontFamilyName(fileName) {
|
|
|
63
61
|
* `%XX` so the address stays inside it.
|
|
64
62
|
*/
|
|
65
63
|
export function toCssUrlLiteral(address) {
|
|
66
|
-
|
|
67
|
-
return
|
|
64
|
+
const escaped = address.replace(/["\\\n\r\f]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')}`);
|
|
65
|
+
return `url("${escaped}")`;
|
|
68
66
|
}
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* nothing is drawn (the empty card is never drawn before an answer exists).
|
|
6
6
|
*/
|
|
7
7
|
export function resolveSearchDropdownPhase(input) {
|
|
8
|
-
|
|
8
|
+
const { panelOpen, trimmedTerm, settledTerm, queryInFlight, resultCount } = input;
|
|
9
9
|
if (!panelOpen || !trimmedTerm)
|
|
10
10
|
return 'idle';
|
|
11
11
|
if (resultCount > 0)
|
|
12
12
|
return 'results';
|
|
13
|
-
|
|
13
|
+
const answerIsPending = queryInFlight || settledTerm !== trimmedTerm;
|
|
14
14
|
if (answerIsPending && settledTerm === '')
|
|
15
15
|
return 'pending';
|
|
16
16
|
return 'empty';
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
1
|
import { getFileTypeOf } from './fileKinds';
|
|
11
2
|
/** Whether a file matches the current type filter (folders are handled separately). */
|
|
12
3
|
export function matchesFileFilter(item, currentFilter) {
|
|
@@ -14,7 +5,7 @@ export function matchesFileFilter(item, currentFilter) {
|
|
|
14
5
|
return true;
|
|
15
6
|
if (item.type === 'folder')
|
|
16
7
|
return true;
|
|
17
|
-
|
|
8
|
+
const fileType = getFileTypeOf(item);
|
|
18
9
|
return fileType === currentFilter;
|
|
19
10
|
}
|
|
20
11
|
/**
|
|
@@ -22,7 +13,7 @@ export function matchesFileFilter(item, currentFilter) {
|
|
|
22
13
|
* skipping the synthetic item named `Root`. Folders always participate; files only if they match the type filter.
|
|
23
14
|
*/
|
|
24
15
|
export function searchFileSystem(item, termLower, currentFilter) {
|
|
25
|
-
|
|
16
|
+
let results = [];
|
|
26
17
|
if (item.name.toLowerCase().includes(termLower) && item.name !== 'Root') {
|
|
27
18
|
if (item.type === 'folder') {
|
|
28
19
|
results.push(item);
|
|
@@ -32,7 +23,7 @@ export function searchFileSystem(item, termLower, currentFilter) {
|
|
|
32
23
|
}
|
|
33
24
|
}
|
|
34
25
|
if (item.type === 'folder' && item.children) {
|
|
35
|
-
results = results.concat(item.children.flatMap(
|
|
26
|
+
results = results.concat(item.children.flatMap((child) => searchFileSystem(child, termLower, currentFilter)));
|
|
36
27
|
}
|
|
37
28
|
return results;
|
|
38
29
|
}
|
|
@@ -44,53 +35,46 @@ export function findItemPath(root, target) {
|
|
|
44
35
|
return [root.id];
|
|
45
36
|
}
|
|
46
37
|
if (root.type === 'folder' && root.children) {
|
|
47
|
-
for (
|
|
48
|
-
|
|
49
|
-
var path = findItemPath(child, target);
|
|
38
|
+
for (const child of root.children) {
|
|
39
|
+
const path = findItemPath(child, target);
|
|
50
40
|
if (path) {
|
|
51
|
-
return
|
|
41
|
+
return [root.id, ...path];
|
|
52
42
|
}
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
45
|
return null;
|
|
56
46
|
}
|
|
57
47
|
/** Joins the names of a location in a result line ("Files / Uploads"): a path separator, not a word, so it is not translated. */
|
|
58
|
-
export
|
|
48
|
+
export const SEARCH_LOCATION_SEPARATOR = ' / ';
|
|
59
49
|
/**
|
|
60
50
|
* Breadcrumb-style location for a search result: translated root label plus parent folder names (not the result name).
|
|
61
51
|
* `idPath` is from {@link findItemPath} for the result item.
|
|
62
52
|
*/
|
|
63
53
|
export function parentFolderLocationLabel(root, idPath, rootDisplayLabel, listSeparator) {
|
|
64
|
-
var _a;
|
|
65
54
|
if (!idPath.length)
|
|
66
55
|
return '';
|
|
67
56
|
/** The tree root row in search is still "in" the library; show the same word as the header. */
|
|
68
57
|
if (idPath.length === 1) {
|
|
69
58
|
return rootDisplayLabel;
|
|
70
59
|
}
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
const parts = [];
|
|
61
|
+
let node = root;
|
|
73
62
|
parts.push(rootDisplayLabel);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
for (let i = 1; i < idPath.length - 1; i++) {
|
|
64
|
+
const segmentId = idPath[i];
|
|
65
|
+
const child = node.children?.find((c) => c.id === segmentId);
|
|
77
66
|
if (!child)
|
|
78
|
-
|
|
67
|
+
break;
|
|
79
68
|
parts.push(child.name);
|
|
80
69
|
if (child.type === 'folder') {
|
|
81
70
|
node = child;
|
|
82
71
|
}
|
|
83
|
-
};
|
|
84
|
-
for (var i = 1; i < idPath.length - 1; i++) {
|
|
85
|
-
var state_1 = _loop_1(i);
|
|
86
|
-
if (state_1 === "break")
|
|
87
|
-
break;
|
|
88
72
|
}
|
|
89
73
|
return parts.join(listSeparator);
|
|
90
74
|
}
|
|
91
75
|
/** Drops `Root` if it slipped in; folders stay visible even when empty. */
|
|
92
76
|
export function filterSearchResults(items, currentFilter) {
|
|
93
|
-
return items.filter(
|
|
77
|
+
return items.filter((item) => {
|
|
94
78
|
if (item.name === 'Root')
|
|
95
79
|
return false;
|
|
96
80
|
if (item.type === 'folder')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Pure helpers for search result list keyboard / reset behavior (SearchDropdown). */
|
|
2
2
|
export function searchResultIds(items) {
|
|
3
3
|
return items
|
|
4
|
-
.map(
|
|
4
|
+
.map((item, index) => item.id ?? `${item.type ?? 'item'}-${index}`)
|
|
5
5
|
.join('\0');
|
|
6
6
|
}
|
|
7
7
|
/** True when the active row should reset to the first result (new result set). */
|
|
@@ -31,12 +31,12 @@ export function lastSearchIndex(resultCount) {
|
|
|
31
31
|
export function pageSearchIndex(currentIndex, resultCount, pageSize, direction) {
|
|
32
32
|
if (resultCount <= 0)
|
|
33
33
|
return -1;
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const safePage = Math.max(1, pageSize);
|
|
35
|
+
const base = currentIndex < 0 ? 0 : currentIndex;
|
|
36
36
|
if (direction === 'down') {
|
|
37
|
-
|
|
37
|
+
const next = base + safePage;
|
|
38
38
|
return next >= resultCount ? resultCount - 1 : next;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
const previous = base - safePage;
|
|
41
41
|
return previous < 0 ? 0 : previous;
|
|
42
42
|
}
|
package/dist/utils/uploadAuth.js
CHANGED
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
/**
|
|
38
2
|
* The access token of a call to the Widgetic API, and what to do when the API refuses it.
|
|
39
3
|
*
|
|
@@ -42,7 +6,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
42
6
|
* again"). A page that gives `getAccessToken` has the File Browser ask for the token each time it is needed, and ask
|
|
43
7
|
* for a fresh one when the API still refuses it, so the visitor never sees the failure.
|
|
44
8
|
*/
|
|
45
|
-
|
|
9
|
+
const BEARER_PREFIX = /^Bearer\s+/i;
|
|
46
10
|
/** A token without a leading "Bearer ", which every request adds itself. */
|
|
47
11
|
export function bareToken(token) {
|
|
48
12
|
return token.trim().replace(BEARER_PREFIX, '');
|
|
@@ -52,89 +16,50 @@ export function bareToken(token) {
|
|
|
52
16
|
* set with. A function that throws or answers with nothing falls back to the config's token; the request that follows
|
|
53
17
|
* says whether that one is still good.
|
|
54
18
|
*/
|
|
55
|
-
export function currentAccessToken(config) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
fromPage = _a.sent();
|
|
68
|
-
if (typeof fromPage === 'string' && bareToken(fromPage) !== '')
|
|
69
|
-
return [2 /*return*/, bareToken(fromPage)];
|
|
70
|
-
return [3 /*break*/, 4];
|
|
71
|
-
case 3:
|
|
72
|
-
error_1 = _a.sent();
|
|
73
|
-
console.warn('[FileBrowser] The page could not give an access token; using the one it set', error_1);
|
|
74
|
-
return [3 /*break*/, 4];
|
|
75
|
-
case 4: return [2 /*return*/, bareToken(config.accessToken)];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
19
|
+
export async function currentAccessToken(config) {
|
|
20
|
+
if (typeof config.getAccessToken === 'function') {
|
|
21
|
+
try {
|
|
22
|
+
const fromPage = await config.getAccessToken('initial');
|
|
23
|
+
if (typeof fromPage === 'string' && bareToken(fromPage) !== '')
|
|
24
|
+
return bareToken(fromPage);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.warn('[FileBrowser] The page could not give an access token; using the one it set', error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return bareToken(config.accessToken);
|
|
79
31
|
}
|
|
80
32
|
/**
|
|
81
33
|
* A new token after the API refused `refusedToken`, or `null` when there is none to try: the page gave no function, its
|
|
82
34
|
* function failed, or it handed back the token that was refused (asking again with it would only fail again).
|
|
83
35
|
*/
|
|
84
|
-
export function renewedAccessToken(config, refusedToken) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
renewed = _a.sent();
|
|
98
|
-
if (typeof renewed !== 'string' || bareToken(renewed) === '')
|
|
99
|
-
return [2 /*return*/, null];
|
|
100
|
-
return [2 /*return*/, bareToken(renewed) === bareToken(refusedToken) ? null : bareToken(renewed)];
|
|
101
|
-
case 3:
|
|
102
|
-
error_2 = _a.sent();
|
|
103
|
-
console.warn('[FileBrowser] The page could not renew the access token', error_2);
|
|
104
|
-
return [2 /*return*/, null];
|
|
105
|
-
case 4: return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
36
|
+
export async function renewedAccessToken(config, refusedToken) {
|
|
37
|
+
if (typeof config.getAccessToken !== 'function')
|
|
38
|
+
return null;
|
|
39
|
+
try {
|
|
40
|
+
const renewed = await config.getAccessToken('expired', refusedToken);
|
|
41
|
+
if (typeof renewed !== 'string' || bareToken(renewed) === '')
|
|
42
|
+
return null;
|
|
43
|
+
return bareToken(renewed) === bareToken(refusedToken) ? null : bareToken(renewed);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.warn('[FileBrowser] The page could not renew the access token', error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
109
49
|
}
|
|
110
50
|
/**
|
|
111
51
|
* Runs a request that ends in an answer with an HTTP `status` (a fetch `Response`, an upload result): with the current
|
|
112
52
|
* token, and once more with a fresh one when the API answers 401. Any other answer, and a 401 that no fresh token can
|
|
113
53
|
* fix, is returned as it is. A request whose `signal` was aborted is not started again.
|
|
114
54
|
*/
|
|
115
|
-
export function withTokenRetriedOnce(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return [4 /*yield*/, request(accessToken)];
|
|
126
|
-
case 2:
|
|
127
|
-
firstAnswer = _b.sent();
|
|
128
|
-
if (firstAnswer.status !== 401 || ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted))
|
|
129
|
-
return [2 /*return*/, firstAnswer];
|
|
130
|
-
return [4 /*yield*/, renewedAccessToken(config, accessToken)];
|
|
131
|
-
case 3:
|
|
132
|
-
renewedToken = _b.sent();
|
|
133
|
-
if (renewedToken === null)
|
|
134
|
-
return [2 /*return*/, firstAnswer];
|
|
135
|
-
console.warn('[FileBrowser] The API refused the access token; trying once more with a fresh one');
|
|
136
|
-
return [2 /*return*/, request(renewedToken)];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
55
|
+
export async function withTokenRetriedOnce(config, request, options = {}) {
|
|
56
|
+
const accessToken = await currentAccessToken(config);
|
|
57
|
+
const firstAnswer = await request(accessToken);
|
|
58
|
+
if (firstAnswer.status !== 401 || options.signal?.aborted)
|
|
59
|
+
return firstAnswer;
|
|
60
|
+
const renewedToken = await renewedAccessToken(config, accessToken);
|
|
61
|
+
if (renewedToken === null)
|
|
62
|
+
return firstAnswer;
|
|
63
|
+
console.warn('[FileBrowser] The API refused the access token; trying once more with a fresh one');
|
|
64
|
+
return request(renewedToken);
|
|
140
65
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Keeps upload row / panel progress values from moving backward (e.g. 100 → 0 when switching to indeterminate).
|
|
3
3
|
*/
|
|
4
4
|
export function monotonicDisplayProgress(previous, next) {
|
|
5
|
-
|
|
5
|
+
const clamped = Math.min(100, Math.max(0, Math.round(next)));
|
|
6
6
|
if (previous === undefined || !Number.isFinite(previous))
|
|
7
7
|
return clamped;
|
|
8
8
|
return Math.max(previous, clamped);
|