@dimah-s3/react 2.0.0-beta.7 → 2.0.0-beta.9
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/{chunk-VJIUZK62.js → chunk-7YPJ65VI.js} +31 -49
- package/dist/chunk-7YPJ65VI.js.map +1 -0
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +79 -20
- package/dist/engine.js.map +1 -1
- package/dist/hooks/use-object-list.d.ts +33 -7
- package/dist/hooks/use-object-list.d.ts.map +1 -1
- package/dist/index.js +34 -7
- package/dist/index.js.map +1 -1
- package/dist/list/entries.d.ts.map +1 -1
- package/dist/list/memory-object-source.d.ts +7 -2
- package/dist/list/memory-object-source.d.ts.map +1 -1
- package/dist/list/read-object-list-level.d.ts +2 -0
- package/dist/list/read-object-list-level.d.ts.map +1 -1
- package/dist/list/types.d.ts +51 -1
- package/dist/list/types.d.ts.map +1 -1
- package/dist/translations/types.d.ts +12 -0
- package/dist/translations/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-VJIUZK62.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { ObjectListEntry, ObjectListFile, ObjectListFolder, ObjectListSort, ObjectListStatus, ObjectListUsageData, UseObjectListOptions } from "../list/types.js";
|
|
1
|
+
import { type APIError } from "@dimah-s3/core";
|
|
2
|
+
import type { ObjectListEntry, ObjectListFile, ObjectListFolder, ObjectListSearchScope, ObjectListSort, ObjectListStatus, ObjectListUsageData, UseObjectListOptions } from "../list/types.js";
|
|
3
3
|
import type { UploadRequestOptions } from "../types/upload.js";
|
|
4
|
-
export type { ObjectListEntry, ObjectListFile, ObjectListFileEntry, ObjectListFolder, ObjectListFolderEntry, ObjectListPage, ObjectListQuery, ObjectListQueryInput, ObjectListSort, ObjectListSortDirection, ObjectListSource, ObjectListStatus, ObjectListUsageData, UseObjectListOptions, } from "../list/types.js";
|
|
4
|
+
export type { ObjectListEntry, ObjectListFile, ObjectListFileEntry, ObjectListFolder, ObjectListFolderEntry, ObjectListPage, ObjectListQuery, ObjectListQueryInput, ObjectListSearchScope, ObjectListSort, ObjectListSortDirection, ObjectListSource, ObjectListStatus, ObjectListUsageData, UseObjectListOptions, } from "../list/types.js";
|
|
5
5
|
/** A value, or an updater from the current value. */
|
|
6
6
|
type Updater<T> = T | ((current: T) => T);
|
|
7
7
|
/** State and commands returned by {@link useObjectList}. */
|
|
@@ -16,8 +16,25 @@ export type UseObjectListReturn<TItem> = {
|
|
|
16
16
|
/** Open folder id. `null` is the root. */
|
|
17
17
|
parent: string | null;
|
|
18
18
|
sort: ObjectListSort | null;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Search text as typed. The query receives it trimmed, or `""` when it
|
|
21
|
+
* has only whitespace, joiners, or accents.
|
|
22
|
+
*/
|
|
20
23
|
search: string;
|
|
24
|
+
/** True while the query receives search text. */
|
|
25
|
+
isSearching: boolean;
|
|
26
|
+
/** Where a search looks. The query receives it with the search text. */
|
|
27
|
+
searchScope: ObjectListSearchScope;
|
|
28
|
+
/**
|
|
29
|
+
* The source's `searchScopes`: where it can search. Empty when it did
|
|
30
|
+
* not say.
|
|
31
|
+
*/
|
|
32
|
+
searchScopes: readonly ObjectListSearchScope[];
|
|
33
|
+
/**
|
|
34
|
+
* Files that match the search across every page, from the first page.
|
|
35
|
+
* `null` when the source did not send it, or nothing is searched.
|
|
36
|
+
*/
|
|
37
|
+
total: number | null;
|
|
21
38
|
/**
|
|
22
39
|
* Totals from the latest page that sent them. `null` when the source
|
|
23
40
|
* did not.
|
|
@@ -42,7 +59,11 @@ export type UseObjectListReturn<TItem> = {
|
|
|
42
59
|
refresh: () => Promise<void>;
|
|
43
60
|
/** Repeat the request that failed: the next page, or a reload. */
|
|
44
61
|
retry: () => Promise<void>;
|
|
45
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Open a folder and load its first page: a child of the open folder, a
|
|
64
|
+
* folder of the trail, or a search result with a `location`, whose whole
|
|
65
|
+
* path opens.
|
|
66
|
+
*/
|
|
46
67
|
openFolder: (folder: ObjectListFolder) => void;
|
|
47
68
|
/** Replace the path. Pass `[]` for the root. */
|
|
48
69
|
navigate: (trail: readonly ObjectListFolder[]) => void;
|
|
@@ -52,6 +73,8 @@ export type UseObjectListReturn<TItem> = {
|
|
|
52
73
|
setSort: (sort: ObjectListSort | null) => void;
|
|
53
74
|
/** Change the search text. Reloads the first page. Debounce it yourself. */
|
|
54
75
|
setSearch: (search: string) => void;
|
|
76
|
+
/** Change where a search looks. Reloads the first page while searching. */
|
|
77
|
+
setSearchScope: (scope: ObjectListSearchScope) => void;
|
|
55
78
|
/**
|
|
56
79
|
* Edit the loaded files without a request, for example after your own
|
|
57
80
|
* update. The next reload replaces them. Prefer `renameFile` when the
|
|
@@ -106,8 +129,11 @@ export type UseObjectListReturn<TItem> = {
|
|
|
106
129
|
* ```
|
|
107
130
|
*
|
|
108
131
|
* Changing the folder or `queryKey` clears the rows and shows the loading
|
|
109
|
-
* state. Changing the sort or search keeps the rows on
|
|
110
|
-
* first page arrives.
|
|
132
|
+
* state. Changing the sort, search, or search scope keeps the rows on
|
|
133
|
+
* screen until the new first page arrives.
|
|
134
|
+
*
|
|
135
|
+
* A source with `searchScopes` searches below the open folder, or
|
|
136
|
+
* everywhere, and says where each result lives (`entry.location`).
|
|
111
137
|
*/
|
|
112
138
|
export declare function useObjectList<TItem>(options: UseObjectListOptions<TItem>): UseObjectListReturn<TItem>;
|
|
113
139
|
//# sourceMappingURL=use-object-list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAUA,OAAO,EA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AAI,CAAC;IACpE,qCAAqC;IACrC,WAAW,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;IAC/C,2BAA2B;IAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;IAChC,yDAAyD;IACzD,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,cAAc,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,oBAAoB,CAAC,GAAG,SAAS,CAAC;IAC7E;;;;OAIG;IACH,YAAY,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC;IACxE;;;;;OAKG;IACH,UAAU,EACR,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IACrE;;;;OAIG;IACH,YAAY,EACR,CAAC,CACC,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,GACtC,SAAS,CAAC;CACf,CAAC;AAsDF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EACjC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACnC,mBAAmB,CAAC,KAAK,CAAC,CAkf5B"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { requireApi, loadRouteCatalog, toClientError, mergeRouteUploadPolicy, resolveRouteUploadPolicy, DEFAULT_MAX_FILES, runBeforeCallback, abortable, reportOperationOutcome, transferProgress, runStartCallback, notify, runAfterCallback, reuseObjectListEntries, formatAcceptLabels, formatFileSize, isRawAPIError, toTimestamp, uploadAbortReason, DEFAULT_CONCURRENT_FILES, mergeUploadRequest, resolveUploadRequest, hookFailed, uploadFile } from './chunk-
|
|
2
|
+
import { requireApi, loadRouteCatalog, toClientError, mergeRouteUploadPolicy, resolveRouteUploadPolicy, DEFAULT_MAX_FILES, runBeforeCallback, abortable, reportOperationOutcome, transferProgress, runStartCallback, notify, runAfterCallback, reuseObjectListEntries, formatAcceptLabels, formatFileSize, isRawAPIError, toTimestamp, uploadAbortReason, DEFAULT_CONCURRENT_FILES, mergeUploadRequest, resolveUploadRequest, hookFailed, uploadFile } from './chunk-7YPJ65VI.js';
|
|
3
3
|
import { createContext, useContext, useState, useEffect, useCallback, useId, useLayoutEffect, useSyncExternalStore, useRef, useMemo } from 'react';
|
|
4
4
|
import { TranslationProvider, useTranslations } from '@fuma-translate/react';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
import { createS3Client as createS3Client$1, parseFileName, fileNameFromKey, s3Error, DELETE_MANY_MAX_KEYS, APIError, normalizeObjectKey, isAPIError, S3_ERROR_CODES, validateFile } from '@dimah-s3/core';
|
|
6
|
+
import { createS3Client as createS3Client$1, parseFileName, fileNameFromKey, s3Error, DELETE_MANY_MAX_KEYS, APIError, normalizeObjectKey, normalizeSearchText, isAPIError, S3_ERROR_CODES, validateFile } from '@dimah-s3/core';
|
|
7
7
|
import { useDropzone } from 'react-dropzone';
|
|
8
8
|
|
|
9
9
|
var S3Context = createContext(null);
|
|
@@ -1979,8 +1979,10 @@ var EMPTY_SNAPSHOT = {
|
|
|
1979
1979
|
folders: [],
|
|
1980
1980
|
nextCursor: null,
|
|
1981
1981
|
usage: null,
|
|
1982
|
+
total: null,
|
|
1982
1983
|
pageCount: 0
|
|
1983
1984
|
};
|
|
1985
|
+
var NO_SCOPES = [];
|
|
1984
1986
|
var INITIAL_STATE = {
|
|
1985
1987
|
snapshot: EMPTY_SNAPSHOT,
|
|
1986
1988
|
pending: null,
|
|
@@ -2012,6 +2014,11 @@ function useObjectList(options) {
|
|
|
2012
2014
|
() => options.defaultSearch ?? "",
|
|
2013
2015
|
options.onSearchChange
|
|
2014
2016
|
);
|
|
2017
|
+
const [searchScope, setSearchScope] = useControllableState(
|
|
2018
|
+
options.searchScope,
|
|
2019
|
+
() => options.defaultSearchScope ?? "folder",
|
|
2020
|
+
options.onSearchScopeChange
|
|
2021
|
+
);
|
|
2015
2022
|
const searchParentRef = useRef(parent);
|
|
2016
2023
|
useLayoutEffect(() => {
|
|
2017
2024
|
if (searchParentRef.current === parent) return;
|
|
@@ -2019,21 +2026,24 @@ function useObjectList(options) {
|
|
|
2019
2026
|
setSearchValue("");
|
|
2020
2027
|
}, [parent, setSearchValue]);
|
|
2021
2028
|
const queryKey = JSON.stringify(options.queryKey ?? []);
|
|
2022
|
-
const trimmedSearch = search.trim();
|
|
2029
|
+
const trimmedSearch = normalizeSearchText(search) === "" ? "" : search.trim();
|
|
2023
2030
|
const request = useMemo(() => {
|
|
2024
2031
|
const scope = JSON.stringify([queryKey, parent]);
|
|
2025
2032
|
return {
|
|
2026
2033
|
key: JSON.stringify([
|
|
2027
2034
|
scope,
|
|
2028
2035
|
sort ? `${sort.field}:${sort.direction}` : "",
|
|
2029
|
-
trimmedSearch
|
|
2036
|
+
trimmedSearch,
|
|
2037
|
+
// The scope matters only while something is searched.
|
|
2038
|
+
trimmedSearch ? searchScope : ""
|
|
2030
2039
|
]),
|
|
2031
2040
|
scope,
|
|
2032
2041
|
parent,
|
|
2033
2042
|
sort,
|
|
2034
|
-
search: trimmedSearch
|
|
2043
|
+
search: trimmedSearch,
|
|
2044
|
+
searchScope
|
|
2035
2045
|
};
|
|
2036
|
-
}, [parent, queryKey, sort, trimmedSearch]);
|
|
2046
|
+
}, [parent, queryKey, searchScope, sort, trimmedSearch]);
|
|
2037
2047
|
const requestRef = useLiveRef(request);
|
|
2038
2048
|
const trailRef = useLiveRef(trail);
|
|
2039
2049
|
const [state, setState] = useState(INITIAL_STATE);
|
|
@@ -2068,6 +2078,7 @@ function useObjectList(options) {
|
|
|
2068
2078
|
parent: target.parent,
|
|
2069
2079
|
sort: target.sort,
|
|
2070
2080
|
search: target.search,
|
|
2081
|
+
searchScope: target.searchScope,
|
|
2071
2082
|
signal: controller.signal
|
|
2072
2083
|
};
|
|
2073
2084
|
try {
|
|
@@ -2095,6 +2106,7 @@ function useObjectList(options) {
|
|
|
2095
2106
|
let folders2 = [];
|
|
2096
2107
|
let serverTrail;
|
|
2097
2108
|
let usage = null;
|
|
2109
|
+
let total = null;
|
|
2098
2110
|
let cursor = null;
|
|
2099
2111
|
let pageCount = 0;
|
|
2100
2112
|
do {
|
|
@@ -2103,6 +2115,7 @@ function useObjectList(options) {
|
|
|
2103
2115
|
if (pageCount === 0) {
|
|
2104
2116
|
folders2 = page.folders ?? [];
|
|
2105
2117
|
if (page.trail) serverTrail = page.trail;
|
|
2118
|
+
if (target.search && page.total != null) total = page.total;
|
|
2106
2119
|
}
|
|
2107
2120
|
for (const item of page.items) items2.push(item);
|
|
2108
2121
|
usage = page.usage ?? usage;
|
|
@@ -2119,6 +2132,7 @@ function useObjectList(options) {
|
|
|
2119
2132
|
folders: folders2,
|
|
2120
2133
|
nextCursor: cursor,
|
|
2121
2134
|
usage,
|
|
2135
|
+
total,
|
|
2122
2136
|
pageCount
|
|
2123
2137
|
}
|
|
2124
2138
|
}));
|
|
@@ -2171,9 +2185,14 @@ function useObjectList(options) {
|
|
|
2171
2185
|
);
|
|
2172
2186
|
const openFolder = useCallback(
|
|
2173
2187
|
(folder) => {
|
|
2188
|
+
const { location, ...opened } = folder;
|
|
2189
|
+
if (location) {
|
|
2190
|
+
navigate([...location.map(plainFolder), opened]);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2174
2193
|
const current = trailRef.current;
|
|
2175
2194
|
const index = current.findIndex((entry) => entry.id === folder.id);
|
|
2176
|
-
navigate(index >= 0 ? current.slice(0, index + 1) : [...current,
|
|
2195
|
+
navigate(index >= 0 ? current.slice(0, index + 1) : [...current, opened]);
|
|
2177
2196
|
},
|
|
2178
2197
|
[navigate, trailRef]
|
|
2179
2198
|
);
|
|
@@ -2369,6 +2388,10 @@ function useObjectList(options) {
|
|
|
2369
2388
|
parent,
|
|
2370
2389
|
sort,
|
|
2371
2390
|
search,
|
|
2391
|
+
isSearching: trimmedSearch !== "",
|
|
2392
|
+
searchScope,
|
|
2393
|
+
searchScopes: options.searchScopes ?? NO_SCOPES,
|
|
2394
|
+
total: fresh && trimmedSearch ? snapshot.total : null,
|
|
2372
2395
|
usage: visible ? snapshot.usage : null,
|
|
2373
2396
|
error: fresh ? failure?.error ?? null : null,
|
|
2374
2397
|
status,
|
|
@@ -2385,6 +2408,7 @@ function useObjectList(options) {
|
|
|
2385
2408
|
goUp,
|
|
2386
2409
|
setSort: setSortValue,
|
|
2387
2410
|
setSearch: setSearchValue,
|
|
2411
|
+
setSearchScope,
|
|
2388
2412
|
setItems,
|
|
2389
2413
|
setFolders,
|
|
2390
2414
|
removeItems,
|
|
@@ -2423,6 +2447,9 @@ function readStatus({
|
|
|
2423
2447
|
function namesNeedReload(request) {
|
|
2424
2448
|
return request.sort?.field === "name" || request.search !== "";
|
|
2425
2449
|
}
|
|
2450
|
+
function plainFolder(folder) {
|
|
2451
|
+
return { id: folder.id, name: folder.name };
|
|
2452
|
+
}
|
|
2426
2453
|
function sortsEqual(a, b) {
|
|
2427
2454
|
return a === b || a?.field === b?.field && a?.direction === b?.direction;
|
|
2428
2455
|
}
|