@widgetic/file-browser 0.5.46 → 0.5.48
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 +104 -115
- package/dist/components/FolderTree.svelte.d.ts +2 -6
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +249 -32
- package/dist/components/core/FileUploader.svelte +134 -54
- package/dist/components/core/RecentFiles.svelte +74 -19
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +6 -8
- package/dist/components/core/UploadPanel.svelte +7 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
- package/dist/components/core/UploadRow.svelte +9 -4
- package/dist/components/core/UploadRow.svelte.d.ts +2 -0
- package/dist/components/core/dropzoneClick.d.ts +28 -0
- package/dist/components/core/dropzoneClick.js +32 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/config.js +4 -3
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +2 -1
- package/dist/i18n/messages.d.ts +15 -1
- package/dist/i18n/messages.js +17 -3
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +4 -3
- package/dist/mediaLibrary/context.js +4 -3
- package/dist/mediaLibrary/errors.js +46 -35
- package/dist/mediaLibrary/normalize.js +45 -42
- package/dist/mediaLibrary/paging.js +100 -45
- package/dist/mediaLibrary/resolve.js +214 -95
- package/dist/mediaLibrary/treeOps.js +40 -20
- package/dist/mediaLibrary/urls.js +12 -10
- package/dist/mediaLibrary/widgetic.js +140 -54
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +1 -1
- package/dist/stores/fileStore.js +44 -37
- package/dist/stores/folderCountStore.js +12 -11
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +217 -178
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +117 -94
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.d.ts +10 -0
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +0 -1
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +57 -42
- package/dist/utils/dateUtils.js +11 -9
- package/dist/utils/deleteSelectionAction.d.ts +26 -0
- package/dist/utils/deleteSelectionAction.js +23 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
- package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
- package/dist/utils/dragToFolder/springStep.js +4 -3
- package/dist/utils/fileGoneProbe.js +65 -16
- package/dist/utils/fileKinds.js +14 -13
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +440 -333
- package/dist/utils/fileTypes.js +19 -14
- package/dist/utils/fileUtils.js +85 -31
- package/dist/utils/folderUtils.js +5 -4
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +26 -15
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +5 -4
- package/dist/utils/imageTransform.js +27 -14
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +55 -39
- package/dist/utils/pendingUploadDeletes.d.ts +102 -0
- package/dist/utils/pendingUploadDeletes.js +400 -0
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +13 -11
- package/dist/utils/previewNavigation.js +10 -7
- package/dist/utils/recentFiles.js +16 -6
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.d.ts +30 -0
- package/dist/utils/removeItems.js +124 -0
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +14 -12
- package/dist/utils/searchDropdownPhase.d.ts +14 -3
- package/dist/utils/searchDropdownPhase.js +13 -9
- package/dist/utils/searchItems.js +30 -14
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.d.ts +24 -0
- package/dist/utils/uploadAuth.js +140 -0
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.d.ts +76 -0
- package/dist/utils/uploadLimits.js +242 -0
- package/dist/utils/uploadListReconcile.js +24 -11
- package/dist/utils/uploadPanelDismiss.d.ts +13 -0
- package/dist/utils/uploadPanelDismiss.js +11 -0
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +13 -11
- package/dist/utils/uploadRefusals.d.ts +42 -0
- package/dist/utils/uploadRefusals.js +86 -0
- package/dist/utils/uploadResponseMapping.js +9 -8
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +270 -133
- package/dist/utils/videoFrame.d.ts +23 -0
- package/dist/utils/videoFrame.js +26 -0
- package/dist/utils/widgeticDelete.js +103 -28
- package/dist/utils/widgeticTusUpload.js +189 -105
- package/dist/utils/widgeticUpload.js +133 -59
- package/dist/utils/xhrMultipartUpload.js +164 -116
- package/package.json +3 -3
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* 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
|
+
* folder are not listed on their own: they come back with the folder).
|
|
24
|
+
*/
|
|
25
|
+
export function removeItemsFromTree(root, ids) {
|
|
26
|
+
var removed = [];
|
|
27
|
+
function walk(node, parentId) {
|
|
28
|
+
var children = node.children;
|
|
29
|
+
if (!children || children.length === 0)
|
|
30
|
+
return node;
|
|
31
|
+
var kept = [];
|
|
32
|
+
var changed = false;
|
|
33
|
+
children.forEach(function (child, index) {
|
|
34
|
+
if (ids.has(child.id)) {
|
|
35
|
+
removed.push({ item: child, parentId: parentId, index: index });
|
|
36
|
+
changed = true;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var nextChild = child.type === 'folder' ? walk(child, child.id) : child;
|
|
40
|
+
if (nextChild !== child)
|
|
41
|
+
changed = true;
|
|
42
|
+
kept.push(nextChild);
|
|
43
|
+
});
|
|
44
|
+
return changed ? __assign(__assign({}, node), { children: kept }) : node;
|
|
45
|
+
}
|
|
46
|
+
var nextRoot = walk(root, null);
|
|
47
|
+
return { root: nextRoot, removed: removed };
|
|
48
|
+
}
|
|
49
|
+
/** Every file in an item: the item itself when it is a file, else the files of its folders, at any depth. */
|
|
50
|
+
export function filesOfItems(items) {
|
|
51
|
+
var files = [];
|
|
52
|
+
function walk(node) {
|
|
53
|
+
var _a;
|
|
54
|
+
if (node.type === 'file') {
|
|
55
|
+
files.push(node);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
for (var _i = 0, _b = (_a = node.children) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
|
|
59
|
+
var child = _b[_i];
|
|
60
|
+
walk(child);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
64
|
+
var item = items_1[_i];
|
|
65
|
+
walk(item);
|
|
66
|
+
}
|
|
67
|
+
return files;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Puts items back where `removeItemsFromTree` took them from: in their folder, at their position. A folder that is gone too
|
|
71
|
+
* 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
|
+
*/
|
|
73
|
+
export function putItemsBackInTree(root, removed) {
|
|
74
|
+
var _a;
|
|
75
|
+
if (removed.length === 0)
|
|
76
|
+
return root;
|
|
77
|
+
var knownIds = new Set();
|
|
78
|
+
(function collect(node) {
|
|
79
|
+
var _a;
|
|
80
|
+
knownIds.add(node.id);
|
|
81
|
+
for (var _i = 0, _b = (_a = node.children) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
|
|
82
|
+
var child = _b[_i];
|
|
83
|
+
collect(child);
|
|
84
|
+
}
|
|
85
|
+
})(root);
|
|
86
|
+
// Ascending positions, so that several items of one folder go back one after the other without moving each other.
|
|
87
|
+
var ordered = __spreadArray([], removed, true).sort(function (a, b) { return a.index - b.index; });
|
|
88
|
+
var byParent = new Map();
|
|
89
|
+
for (var _i = 0, ordered_1 = ordered; _i < ordered_1.length; _i++) {
|
|
90
|
+
var entry = ordered_1[_i];
|
|
91
|
+
if (knownIds.has(entry.item.id))
|
|
92
|
+
continue;
|
|
93
|
+
var parentId = entry.parentId !== null && knownIds.has(entry.parentId) ? entry.parentId : null;
|
|
94
|
+
byParent.set(parentId, __spreadArray(__spreadArray([], ((_a = byParent.get(parentId)) !== null && _a !== void 0 ? _a : []), true), [entry], false));
|
|
95
|
+
}
|
|
96
|
+
if (byParent.size === 0)
|
|
97
|
+
return root;
|
|
98
|
+
function withItemsInserted(children, entries) {
|
|
99
|
+
var next = __spreadArray([], children, true);
|
|
100
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
101
|
+
var entry = entries_1[_i];
|
|
102
|
+
next.splice(Math.min(entry.index, next.length), 0, entry.item);
|
|
103
|
+
}
|
|
104
|
+
return next;
|
|
105
|
+
}
|
|
106
|
+
function walk(node, nodeKey) {
|
|
107
|
+
var entries = byParent.get(nodeKey);
|
|
108
|
+
var children = node.children;
|
|
109
|
+
var changed = false;
|
|
110
|
+
if (children) {
|
|
111
|
+
var walked = children.map(function (child) { return (child.type === 'folder' ? walk(child, child.id) : child); });
|
|
112
|
+
if (walked.some(function (child, position) { return child !== children[position]; })) {
|
|
113
|
+
children = walked;
|
|
114
|
+
changed = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (entries && entries.length > 0) {
|
|
118
|
+
children = withItemsInserted(children !== null && children !== void 0 ? children : [], entries);
|
|
119
|
+
changed = true;
|
|
120
|
+
}
|
|
121
|
+
return changed ? __assign(__assign({}, node), { children: children }) : node;
|
|
122
|
+
}
|
|
123
|
+
return walk(root, null);
|
|
124
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var 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 : "/".concat(filePath);
|
|
10
|
+
var normalizedBase = basePath.endsWith('/') ? basePath : "".concat(basePath, "/");
|
|
11
|
+
var cleanPath = filePath.startsWith('/') ? filePath : "/".concat(filePath);
|
|
12
12
|
if (cleanPath.startsWith(normalizedBase)) {
|
|
13
13
|
return cleanPath;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return
|
|
15
|
+
var cleanRelative = filePath.startsWith('/') ? filePath.slice(1) : filePath;
|
|
16
|
+
return "".concat(normalizedBase).concat(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
|
+
var HTML_ENTITIES = {
|
|
8
8
|
'&': '&',
|
|
9
9
|
'<': '<',
|
|
10
10
|
'>': '>',
|
|
@@ -13,7 +13,7 @@ const 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, (character)
|
|
16
|
+
return text.replace(/[&<>"']/g, function (character) { return HTML_ENTITIES[character]; });
|
|
17
17
|
}
|
|
18
18
|
function escapeRegExp(text) {
|
|
19
19
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -30,15 +30,17 @@ 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
|
+
var parts = name.split(new RegExp("(".concat(escapeRegExp(term), ")"), 'gi'));
|
|
34
34
|
return parts
|
|
35
|
-
.map((part, index)
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
.map(function (part, index) {
|
|
36
|
+
return index % 2 === 1
|
|
37
|
+
? "<span class=\"".concat(escapeHtml(highlightClass), "\">").concat(escapeHtml(part), "</span>")
|
|
38
|
+
: escapeHtml(part);
|
|
39
|
+
})
|
|
38
40
|
.join('');
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
var MAX_FONT_FAMILY_LENGTH = 64;
|
|
43
|
+
var FALLBACK_FONT_FAMILY = 'Uploaded font';
|
|
42
44
|
/**
|
|
43
45
|
* The name a font file is registered and styled under: its file name without the extension, reduced to letters,
|
|
44
46
|
* digits, spaces, underscores and hyphens.
|
|
@@ -48,8 +50,8 @@ const FALLBACK_FONT_FAMILY = 'Uploaded font';
|
|
|
48
50
|
* registered and where it is used, so the two always agree.
|
|
49
51
|
*/
|
|
50
52
|
export function toSafeFontFamilyName(fileName) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
var withoutExtension = typeof fileName === 'string' ? fileName.replace(/\.[^/.]+$/, '') : '';
|
|
54
|
+
var safeName = withoutExtension
|
|
53
55
|
.replace(/[^\p{L}\p{N} _-]/gu, '')
|
|
54
56
|
.trim()
|
|
55
57
|
.slice(0, MAX_FONT_FAMILY_LENGTH)
|
|
@@ -61,6 +63,6 @@ export function toSafeFontFamilyName(fileName) {
|
|
|
61
63
|
* `%XX` so the address stays inside it.
|
|
62
64
|
*/
|
|
63
65
|
export function toCssUrlLiteral(address) {
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
+
var escaped = address.replace(/["\\\n\r\f]/g, function (character) { return "%".concat(character.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')); });
|
|
67
|
+
return "url(\"".concat(escaped, "\")");
|
|
66
68
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What the search panel draws:
|
|
3
|
+
* - `idle`: nothing (closed, or no text).
|
|
4
|
+
* - `pending`: the first answer for the typed text is not there yet. Nothing is drawn: no "Loading…" row and no empty card.
|
|
5
|
+
* - `results`: the list of what was found.
|
|
6
|
+
* - `empty`: the card that says nothing was found.
|
|
7
|
+
*/
|
|
8
|
+
export type SearchDropdownPhase = 'idle' | 'pending' | 'results' | 'empty';
|
|
2
9
|
export type SearchDropdownPhaseInput = {
|
|
3
10
|
panelOpen: boolean;
|
|
4
11
|
trimmedTerm: string;
|
|
@@ -9,9 +16,13 @@ export type SearchDropdownPhaseInput = {
|
|
|
9
16
|
resultCount: number;
|
|
10
17
|
};
|
|
11
18
|
/**
|
|
12
|
-
* When the panel is open with text
|
|
13
|
-
*
|
|
19
|
+
* When the panel is open with text, it never shows a loading state. While the search for the typed text is pending, the
|
|
20
|
+
* panel keeps what it shows: the previous results, or the empty card when the last answer was "nothing found" (so the card
|
|
21
|
+
* does not blink out and back in while the person goes on typing). Before the first answer there is nothing to keep, so
|
|
22
|
+
* nothing is drawn (the empty card is never drawn before an answer exists).
|
|
14
23
|
*/
|
|
15
24
|
export declare function resolveSearchDropdownPhase(input: SearchDropdownPhaseInput): SearchDropdownPhase;
|
|
16
25
|
export declare function shouldShowSearchEmptyState(phase: SearchDropdownPhase): boolean;
|
|
17
26
|
export declare function shouldShowSearchResultsList(phase: SearchDropdownPhase, resultCount: number): boolean;
|
|
27
|
+
/** The card under the field is drawn only for a list or for the empty message; while the first answer is pending it is not drawn at all. */
|
|
28
|
+
export declare function shouldShowSearchPanel(phase: SearchDropdownPhase): boolean;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* When the panel is open with text
|
|
3
|
-
*
|
|
2
|
+
* When the panel is open with text, it never shows a loading state. While the search for the typed text is pending, the
|
|
3
|
+
* panel keeps what it shows: the previous results, or the empty card when the last answer was "nothing found" (so the card
|
|
4
|
+
* does not blink out and back in while the person goes on typing). Before the first answer there is nothing to keep, so
|
|
5
|
+
* nothing is drawn (the empty card is never drawn before an answer exists).
|
|
4
6
|
*/
|
|
5
7
|
export function resolveSearchDropdownPhase(input) {
|
|
6
|
-
|
|
8
|
+
var panelOpen = input.panelOpen, trimmedTerm = input.trimmedTerm, settledTerm = input.settledTerm, queryInFlight = input.queryInFlight, resultCount = input.resultCount;
|
|
7
9
|
if (!panelOpen || !trimmedTerm)
|
|
8
10
|
return 'idle';
|
|
9
|
-
if (queryInFlight || settledTerm !== trimmedTerm) {
|
|
10
|
-
if (resultCount > 0)
|
|
11
|
-
return 'results';
|
|
12
|
-
return 'loading';
|
|
13
|
-
}
|
|
14
11
|
if (resultCount > 0)
|
|
15
12
|
return 'results';
|
|
13
|
+
var answerIsPending = queryInFlight || settledTerm !== trimmedTerm;
|
|
14
|
+
if (answerIsPending && settledTerm === '')
|
|
15
|
+
return 'pending';
|
|
16
16
|
return 'empty';
|
|
17
17
|
}
|
|
18
18
|
export function shouldShowSearchEmptyState(phase) {
|
|
19
19
|
return phase === 'empty';
|
|
20
20
|
}
|
|
21
21
|
export function shouldShowSearchResultsList(phase, resultCount) {
|
|
22
|
-
return resultCount > 0 &&
|
|
22
|
+
return resultCount > 0 && phase === 'results';
|
|
23
|
+
}
|
|
24
|
+
/** The card under the field is drawn only for a list or for the empty message; while the first answer is pending it is not drawn at all. */
|
|
25
|
+
export function shouldShowSearchPanel(phase) {
|
|
26
|
+
return phase === 'results' || phase === 'empty';
|
|
23
27
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
};
|
|
1
10
|
import { getFileTypeOf } from './fileKinds';
|
|
2
11
|
/** Whether a file matches the current type filter (folders are handled separately). */
|
|
3
12
|
export function matchesFileFilter(item, currentFilter) {
|
|
@@ -5,7 +14,7 @@ export function matchesFileFilter(item, currentFilter) {
|
|
|
5
14
|
return true;
|
|
6
15
|
if (item.type === 'folder')
|
|
7
16
|
return true;
|
|
8
|
-
|
|
17
|
+
var fileType = getFileTypeOf(item);
|
|
9
18
|
return fileType === currentFilter;
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
@@ -13,7 +22,7 @@ export function matchesFileFilter(item, currentFilter) {
|
|
|
13
22
|
* skipping the synthetic item named `Root`. Folders always participate; files only if they match the type filter.
|
|
14
23
|
*/
|
|
15
24
|
export function searchFileSystem(item, termLower, currentFilter) {
|
|
16
|
-
|
|
25
|
+
var results = [];
|
|
17
26
|
if (item.name.toLowerCase().includes(termLower) && item.name !== 'Root') {
|
|
18
27
|
if (item.type === 'folder') {
|
|
19
28
|
results.push(item);
|
|
@@ -23,7 +32,7 @@ export function searchFileSystem(item, termLower, currentFilter) {
|
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
if (item.type === 'folder' && item.children) {
|
|
26
|
-
results = results.concat(item.children.flatMap((child)
|
|
35
|
+
results = results.concat(item.children.flatMap(function (child) { return searchFileSystem(child, termLower, currentFilter); }));
|
|
27
36
|
}
|
|
28
37
|
return results;
|
|
29
38
|
}
|
|
@@ -35,46 +44,53 @@ export function findItemPath(root, target) {
|
|
|
35
44
|
return [root.id];
|
|
36
45
|
}
|
|
37
46
|
if (root.type === 'folder' && root.children) {
|
|
38
|
-
for (
|
|
39
|
-
|
|
47
|
+
for (var _i = 0, _a = root.children; _i < _a.length; _i++) {
|
|
48
|
+
var child = _a[_i];
|
|
49
|
+
var path = findItemPath(child, target);
|
|
40
50
|
if (path) {
|
|
41
|
-
return [root.id,
|
|
51
|
+
return __spreadArray([root.id], path, true);
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
return null;
|
|
46
56
|
}
|
|
47
57
|
/** Joins the names of a location in a result line ("Files / Uploads"): a path separator, not a word, so it is not translated. */
|
|
48
|
-
export
|
|
58
|
+
export var SEARCH_LOCATION_SEPARATOR = ' / ';
|
|
49
59
|
/**
|
|
50
60
|
* Breadcrumb-style location for a search result: translated root label plus parent folder names (not the result name).
|
|
51
61
|
* `idPath` is from {@link findItemPath} for the result item.
|
|
52
62
|
*/
|
|
53
63
|
export function parentFolderLocationLabel(root, idPath, rootDisplayLabel, listSeparator) {
|
|
64
|
+
var _a;
|
|
54
65
|
if (!idPath.length)
|
|
55
66
|
return '';
|
|
56
67
|
/** The tree root row in search is still "in" the library; show the same word as the header. */
|
|
57
68
|
if (idPath.length === 1) {
|
|
58
69
|
return rootDisplayLabel;
|
|
59
70
|
}
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
var parts = [];
|
|
72
|
+
var node = root;
|
|
62
73
|
parts.push(rootDisplayLabel);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
var _loop_1 = function (i) {
|
|
75
|
+
var segmentId = idPath[i];
|
|
76
|
+
var child = (_a = node.children) === null || _a === void 0 ? void 0 : _a.find(function (c) { return c.id === segmentId; });
|
|
66
77
|
if (!child)
|
|
67
|
-
break;
|
|
78
|
+
return "break";
|
|
68
79
|
parts.push(child.name);
|
|
69
80
|
if (child.type === 'folder') {
|
|
70
81
|
node = child;
|
|
71
82
|
}
|
|
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;
|
|
72
88
|
}
|
|
73
89
|
return parts.join(listSeparator);
|
|
74
90
|
}
|
|
75
91
|
/** Drops `Root` if it slipped in; folders stay visible even when empty. */
|
|
76
92
|
export function filterSearchResults(items, currentFilter) {
|
|
77
|
-
return items.filter((item)
|
|
93
|
+
return items.filter(function (item) {
|
|
78
94
|
if (item.name === 'Root')
|
|
79
95
|
return false;
|
|
80
96
|
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((item, index)
|
|
4
|
+
.map(function (item, index) { var _a, _b; return (_a = item.id) !== null && _a !== void 0 ? _a : "".concat((_b = item.type) !== null && _b !== void 0 ? _b : 'item', "-").concat(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
|
+
var safePage = Math.max(1, pageSize);
|
|
35
|
+
var base = currentIndex < 0 ? 0 : currentIndex;
|
|
36
36
|
if (direction === 'down') {
|
|
37
|
-
|
|
37
|
+
var next = base + safePage;
|
|
38
38
|
return next >= resultCount ? resultCount - 1 : next;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
var previous = base - safePage;
|
|
41
41
|
return previous < 0 ? 0 : previous;
|
|
42
42
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FileBrowserUploadConfig } from '../stores/uploadApiStore';
|
|
2
|
+
/** A token without a leading "Bearer ", which every request adds itself. */
|
|
3
|
+
export declare function bareToken(token: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* The token to call the API with now: the one the page's `getAccessToken('initial')` gives, else the token the config was
|
|
6
|
+
* set with. A function that throws or answers with nothing falls back to the config's token; the request that follows
|
|
7
|
+
* says whether that one is still good.
|
|
8
|
+
*/
|
|
9
|
+
export declare function currentAccessToken(config: FileBrowserUploadConfig): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* A new token after the API refused `refusedToken`, or `null` when there is none to try: the page gave no function, its
|
|
12
|
+
* function failed, or it handed back the token that was refused (asking again with it would only fail again).
|
|
13
|
+
*/
|
|
14
|
+
export declare function renewedAccessToken(config: FileBrowserUploadConfig, refusedToken: string): Promise<string | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Runs a request that ends in an answer with an HTTP `status` (a fetch `Response`, an upload result): with the current
|
|
17
|
+
* token, and once more with a fresh one when the API answers 401. Any other answer, and a 401 that no fresh token can
|
|
18
|
+
* fix, is returned as it is. A request whose `signal` was aborted is not started again.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withTokenRetriedOnce<Answer extends {
|
|
21
|
+
status?: number;
|
|
22
|
+
}>(config: FileBrowserUploadConfig, request: (accessToken: string) => Promise<Answer>, options?: {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<Answer>;
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
/**
|
|
38
|
+
* The access token of a call to the Widgetic API, and what to do when the API refuses it.
|
|
39
|
+
*
|
|
40
|
+
* A page that sets the upload config holds a token that was good at that moment; its session is renewed while the
|
|
41
|
+
* File Browser stays open, and a token kept from before the renewal is refused with a 401 ("I have to refresh and try
|
|
42
|
+
* again"). A page that gives `getAccessToken` has the File Browser ask for the token each time it is needed, and ask
|
|
43
|
+
* for a fresh one when the API still refuses it, so the visitor never sees the failure.
|
|
44
|
+
*/
|
|
45
|
+
var BEARER_PREFIX = /^Bearer\s+/i;
|
|
46
|
+
/** A token without a leading "Bearer ", which every request adds itself. */
|
|
47
|
+
export function bareToken(token) {
|
|
48
|
+
return token.trim().replace(BEARER_PREFIX, '');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The token to call the API with now: the one the page's `getAccessToken('initial')` gives, else the token the config was
|
|
52
|
+
* set with. A function that throws or answers with nothing falls back to the config's token; the request that follows
|
|
53
|
+
* says whether that one is still good.
|
|
54
|
+
*/
|
|
55
|
+
export function currentAccessToken(config) {
|
|
56
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
57
|
+
var fromPage, error_1;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
if (!(typeof config.getAccessToken === 'function')) return [3 /*break*/, 4];
|
|
62
|
+
_a.label = 1;
|
|
63
|
+
case 1:
|
|
64
|
+
_a.trys.push([1, 3, , 4]);
|
|
65
|
+
return [4 /*yield*/, config.getAccessToken('initial')];
|
|
66
|
+
case 2:
|
|
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
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A new token after the API refused `refusedToken`, or `null` when there is none to try: the page gave no function, its
|
|
82
|
+
* function failed, or it handed back the token that was refused (asking again with it would only fail again).
|
|
83
|
+
*/
|
|
84
|
+
export function renewedAccessToken(config, refusedToken) {
|
|
85
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
86
|
+
var renewed, error_2;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
if (typeof config.getAccessToken !== 'function')
|
|
91
|
+
return [2 /*return*/, null];
|
|
92
|
+
_a.label = 1;
|
|
93
|
+
case 1:
|
|
94
|
+
_a.trys.push([1, 3, , 4]);
|
|
95
|
+
return [4 /*yield*/, config.getAccessToken('expired', refusedToken)];
|
|
96
|
+
case 2:
|
|
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
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Runs a request that ends in an answer with an HTTP `status` (a fetch `Response`, an upload result): with the current
|
|
112
|
+
* 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
|
+
* fix, is returned as it is. A request whose `signal` was aborted is not started again.
|
|
114
|
+
*/
|
|
115
|
+
export function withTokenRetriedOnce(config_1, request_1) {
|
|
116
|
+
return __awaiter(this, arguments, Promise, function (config, request, options) {
|
|
117
|
+
var accessToken, firstAnswer, renewedToken;
|
|
118
|
+
var _a;
|
|
119
|
+
if (options === void 0) { options = {}; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0: return [4 /*yield*/, currentAccessToken(config)];
|
|
123
|
+
case 1:
|
|
124
|
+
accessToken = _b.sent();
|
|
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
|
+
});
|
|
140
|
+
}
|
|
@@ -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
|
+
var 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);
|