@dimah-s3/react 2.0.0-beta.1 → 2.0.0-beta.3
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/helpers/format-dimah-error.d.ts.map +1 -1
- package/dist/hooks/use-object-list.d.ts +16 -2
- package/dist/hooks/use-object-list.d.ts.map +1 -1
- package/dist/index.js +108 -3
- package/dist/index.js.map +1 -1
- package/dist/list/types.d.ts +24 -0
- package/dist/list/types.d.ts.map +1 -1
- package/dist/translations/types.d.ts +5 -0
- package/dist/translations/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-dimah-error.d.ts","sourceRoot":"","sources":["../../src/helpers/format-dimah-error.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"format-dimah-error.d.ts","sourceRoot":"","sources":["../../src/helpers/format-dimah-error.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CA+KhE"}
|
|
@@ -53,8 +53,9 @@ export type UseObjectListReturn<TItem> = {
|
|
|
53
53
|
/** Change the search text. Reloads the first page. Debounce it yourself. */
|
|
54
54
|
setSearch: (search: string) => void;
|
|
55
55
|
/**
|
|
56
|
-
* Edit the loaded files without a request, for example after
|
|
57
|
-
* The next reload replaces them.
|
|
56
|
+
* Edit the loaded files without a request, for example after your own
|
|
57
|
+
* update. The next reload replaces them. Prefer `renameFile` when the
|
|
58
|
+
* source can rename.
|
|
58
59
|
*/
|
|
59
60
|
setItems: (items: Updater<readonly TItem[]>) => void;
|
|
60
61
|
/** Edit the loaded folders without a request. */
|
|
@@ -73,6 +74,19 @@ export type UseObjectListReturn<TItem> = {
|
|
|
73
74
|
* `createFolder`.
|
|
74
75
|
*/
|
|
75
76
|
createFolder: ((name: string) => Promise<ObjectListFolder>) | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Renames a file through the source and replaces the loaded row.
|
|
79
|
+
* Rejects with an `APIError`. The same name does nothing. A name sort
|
|
80
|
+
* or a search reloads afterwards, and so does a source that returns
|
|
81
|
+
* nothing. Set when the source has `renameFile`.
|
|
82
|
+
*/
|
|
83
|
+
renameFile: ((item: TItem, name: string) => Promise<TItem | void>) | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Renames a folder through the source, replaces the loaded row, and
|
|
86
|
+
* updates that id in the breadcrumb. Rejects with an `APIError`. The
|
|
87
|
+
* same name does nothing. Set when the source has `renameFolder`.
|
|
88
|
+
*/
|
|
89
|
+
renameFolder: ((folder: ObjectListFolder, name: string) => Promise<ObjectListFolder | void>) | undefined;
|
|
76
90
|
};
|
|
77
91
|
/**
|
|
78
92
|
* Page through a folder catalog without knowing the backend.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,YAAY,EACV,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,qDAAqD;AACrD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GA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uE;IACvE,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,4EAA4E;IAC5E,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC
|
|
1
|
+
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,YAAY,EACV,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,qDAAqD;AACrD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAE1C,4DAA4D;AAC5D,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI;IACvC,iEAAiE;IACjE,OAAO,EAAE,SAAS,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3C,KAAK,EAAE,SAAS,KAAK,EAAE,CAAC;IACxB,gDAAgD;IAChD,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACrC,yCAAyC;IACzC,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACnC,0CAA0C;IAC1C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;I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C;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;AAgDF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EACjC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACnC,mBAAmB,CAAC,KAAK,CAAC,CAyd5B"}
|
package/dist/index.js
CHANGED
|
@@ -2001,13 +2001,17 @@ function useObjectList(options) {
|
|
|
2001
2001
|
const pageTarget = mode === "refresh" ? Math.max(1, current.snapshot.pageCount) : 1;
|
|
2002
2002
|
const items2 = [];
|
|
2003
2003
|
let folders2 = [];
|
|
2004
|
+
let serverTrail;
|
|
2004
2005
|
let usage = null;
|
|
2005
2006
|
let cursor = null;
|
|
2006
2007
|
let pageCount = 0;
|
|
2007
2008
|
do {
|
|
2008
2009
|
const page = await opts.query({ ...input, cursor });
|
|
2009
2010
|
if (!isCurrent()) return;
|
|
2010
|
-
if (pageCount === 0)
|
|
2011
|
+
if (pageCount === 0) {
|
|
2012
|
+
folders2 = page.folders ?? [];
|
|
2013
|
+
if (page.trail) serverTrail = page.trail;
|
|
2014
|
+
}
|
|
2011
2015
|
for (const item of page.items) items2.push(item);
|
|
2012
2016
|
usage = page.usage ?? usage;
|
|
2013
2017
|
cursor = page.nextCursor || null;
|
|
@@ -2026,6 +2030,10 @@ function useObjectList(options) {
|
|
|
2026
2030
|
pageCount
|
|
2027
2031
|
}
|
|
2028
2032
|
}));
|
|
2033
|
+
if (serverTrail && (target.parent === null ? serverTrail.length === 0 : serverTrail.at(-1)?.id === target.parent)) {
|
|
2034
|
+
trailRef.current = serverTrail;
|
|
2035
|
+
setTrailState(serverTrail);
|
|
2036
|
+
}
|
|
2029
2037
|
} catch (err) {
|
|
2030
2038
|
if (!isCurrent()) return;
|
|
2031
2039
|
const error = toClientError(err);
|
|
@@ -2037,7 +2045,7 @@ function useObjectList(options) {
|
|
|
2037
2045
|
}));
|
|
2038
2046
|
}
|
|
2039
2047
|
},
|
|
2040
|
-
[optionsRef, requestRef, update]
|
|
2048
|
+
[optionsRef, requestRef, trailRef, update]
|
|
2041
2049
|
);
|
|
2042
2050
|
useEffect(() => {
|
|
2043
2051
|
if (!enabled) return;
|
|
@@ -2148,6 +2156,96 @@ function useObjectList(options) {
|
|
|
2148
2156
|
},
|
|
2149
2157
|
[optionsRef, requestRef, update]
|
|
2150
2158
|
);
|
|
2159
|
+
const settleRename = useCallback(
|
|
2160
|
+
async (scope, replaced) => {
|
|
2161
|
+
if (requestRef.current.scope !== scope) return;
|
|
2162
|
+
if (!replaced || namesNeedReload(requestRef.current)) {
|
|
2163
|
+
await run("refresh");
|
|
2164
|
+
}
|
|
2165
|
+
},
|
|
2166
|
+
[requestRef, run]
|
|
2167
|
+
);
|
|
2168
|
+
const renameFile = useCallback(
|
|
2169
|
+
async (item, name) => {
|
|
2170
|
+
const rename = optionsRef.current.renameFile;
|
|
2171
|
+
if (!rename) {
|
|
2172
|
+
throw new Error("[dimah-s3] The source has no renameFile.");
|
|
2173
|
+
}
|
|
2174
|
+
const { getFile: read, getKey: keyOf } = optionsRef.current;
|
|
2175
|
+
if ((read ? read(item).name : keyOf(item)) === name) return item;
|
|
2176
|
+
const key = keyOf(item);
|
|
2177
|
+
const { scope } = requestRef.current;
|
|
2178
|
+
let next;
|
|
2179
|
+
try {
|
|
2180
|
+
next = await rename({ item, name });
|
|
2181
|
+
} catch (err) {
|
|
2182
|
+
throw toClientError(err);
|
|
2183
|
+
}
|
|
2184
|
+
if (next) {
|
|
2185
|
+
const replacement = next;
|
|
2186
|
+
update((draft) => {
|
|
2187
|
+
if (draft.snapshot.scope !== scope) return draft;
|
|
2188
|
+
const idOf = optionsRef.current.getKey;
|
|
2189
|
+
return {
|
|
2190
|
+
...draft,
|
|
2191
|
+
snapshot: {
|
|
2192
|
+
...draft.snapshot,
|
|
2193
|
+
items: draft.snapshot.items.map(
|
|
2194
|
+
(current) => idOf(current) === key ? replacement : current
|
|
2195
|
+
)
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
await settleRename(scope, next != null);
|
|
2201
|
+
return next;
|
|
2202
|
+
},
|
|
2203
|
+
[optionsRef, requestRef, settleRename, update]
|
|
2204
|
+
);
|
|
2205
|
+
const renameFolder = useCallback(
|
|
2206
|
+
async (folder, name) => {
|
|
2207
|
+
const rename = optionsRef.current.renameFolder;
|
|
2208
|
+
if (!rename) {
|
|
2209
|
+
throw new Error("[dimah-s3] The source has no renameFolder.");
|
|
2210
|
+
}
|
|
2211
|
+
if (folder.name === name) return folder;
|
|
2212
|
+
const { scope } = requestRef.current;
|
|
2213
|
+
let next;
|
|
2214
|
+
try {
|
|
2215
|
+
next = await rename({ folder, name });
|
|
2216
|
+
} catch (err) {
|
|
2217
|
+
throw toClientError(err);
|
|
2218
|
+
}
|
|
2219
|
+
if (next) {
|
|
2220
|
+
const replacement = next;
|
|
2221
|
+
update((draft) => {
|
|
2222
|
+
if (draft.snapshot.scope !== scope) return draft;
|
|
2223
|
+
return {
|
|
2224
|
+
...draft,
|
|
2225
|
+
snapshot: {
|
|
2226
|
+
...draft.snapshot,
|
|
2227
|
+
folders: draft.snapshot.folders.map(
|
|
2228
|
+
(current) => current.id === folder.id ? replacement : current
|
|
2229
|
+
)
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
});
|
|
2233
|
+
const currentTrail = trailRef.current;
|
|
2234
|
+
if (currentTrail.some(
|
|
2235
|
+
(entry) => entry.id === folder.id && entry.name !== replacement.name
|
|
2236
|
+
)) {
|
|
2237
|
+
const renamedTrail = currentTrail.map(
|
|
2238
|
+
(entry) => entry.id === folder.id ? { ...entry, name: replacement.name } : entry
|
|
2239
|
+
);
|
|
2240
|
+
trailRef.current = renamedTrail;
|
|
2241
|
+
setTrailState(renamedTrail);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
await settleRename(scope, next != null);
|
|
2245
|
+
return next;
|
|
2246
|
+
},
|
|
2247
|
+
[optionsRef, requestRef, settleRename, trailRef, update]
|
|
2248
|
+
);
|
|
2151
2249
|
const setSort = useCallback(
|
|
2152
2250
|
(next) => setSortValue(next),
|
|
2153
2251
|
[setSortValue]
|
|
@@ -2210,7 +2308,9 @@ function useObjectList(options) {
|
|
|
2210
2308
|
getKey,
|
|
2211
2309
|
getFile,
|
|
2212
2310
|
uploadOptions: options.uploadOptions,
|
|
2213
|
-
createFolder: options.createFolder ? createFolder : void 0
|
|
2311
|
+
createFolder: options.createFolder ? createFolder : void 0,
|
|
2312
|
+
renameFile: options.renameFile ? renameFile : void 0,
|
|
2313
|
+
renameFolder: options.renameFolder ? renameFolder : void 0
|
|
2214
2314
|
};
|
|
2215
2315
|
}
|
|
2216
2316
|
function readStatus({
|
|
@@ -2228,6 +2328,9 @@ function readStatus({
|
|
|
2228
2328
|
if (pending === "refresh") return hasRows ? "refreshing" : "loading";
|
|
2229
2329
|
return failure ? "error" : "ready";
|
|
2230
2330
|
}
|
|
2331
|
+
function namesNeedReload(request) {
|
|
2332
|
+
return request.sort?.field === "name" || request.search !== "";
|
|
2333
|
+
}
|
|
2231
2334
|
function sortsEqual(a, b) {
|
|
2232
2335
|
return a === b || a?.field === b?.field && a?.direction === b?.direction;
|
|
2233
2336
|
}
|
|
@@ -2599,6 +2702,8 @@ function useFormatDimahError() {
|
|
|
2599
2702
|
});
|
|
2600
2703
|
case "FOLDER_INVALID":
|
|
2601
2704
|
return t("Folder name is invalid", { note: "API error" });
|
|
2705
|
+
case "FOLDER_NOT_FOUND":
|
|
2706
|
+
return t("Folder not found", { note: "API error" });
|
|
2602
2707
|
case "FOLDER_EXISTS":
|
|
2603
2708
|
return t("A folder with this name already exists", {
|
|
2604
2709
|
note: "API error"
|