@keepkit/core 0.27.3 → 0.28.1
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/README.md +6 -2
- package/dist/{chunk-XUHRDJD6.js → chunk-HDML3IDX.js} +55 -68
- package/dist/chunk-HDML3IDX.js.map +1 -0
- package/dist/{chunk-O6FNZ5N2.js → chunk-JGGKIE3O.js} +42 -38
- package/dist/chunk-JGGKIE3O.js.map +1 -0
- package/dist/core.d.ts +5 -5
- package/dist/core.js +39 -6
- package/dist/core.js.map +1 -1
- package/dist/react.d.ts +18 -6
- package/dist/react.js +80 -79
- package/dist/react.js.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{scope-kVcPskvM.d.ts → scope-BsU6xvN9.d.ts} +1 -1
- package/dist/storage.d.ts +3 -3
- package/dist/storage.js +1 -1
- package/dist/{store-pfMOz7sn.d.ts → store-DbAAC4yU.d.ts} +23 -5
- package/dist/{types-6ex9EBjM.d.ts → types-CJIbuqTO.d.ts} +3 -1
- package/package.json +1 -1
- package/dist/chunk-O6FNZ5N2.js.map +0 -1
- package/dist/chunk-XUHRDJD6.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
KeepStore,
|
|
4
|
+
createRediscoveryQuery,
|
|
4
5
|
exportItems,
|
|
5
6
|
getKeepNavigationState,
|
|
6
7
|
importItems,
|
|
@@ -10,14 +11,17 @@ import {
|
|
|
10
11
|
queryKeepItems,
|
|
11
12
|
reorderKeepItems,
|
|
12
13
|
revalidateKeepItems
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JGGKIE3O.js";
|
|
14
15
|
import {
|
|
15
16
|
parseKeepMeta
|
|
16
17
|
} from "./chunk-5W4QSJHV.js";
|
|
17
18
|
import {
|
|
18
19
|
createBrowserStorageAdapter,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
isRecord,
|
|
21
|
+
normalizeKeepTags,
|
|
22
|
+
persistKeepItems,
|
|
23
|
+
removeKeepItems
|
|
24
|
+
} from "./chunk-HDML3IDX.js";
|
|
21
25
|
|
|
22
26
|
// src/react/components/KeepButton.tsx
|
|
23
27
|
import {
|
|
@@ -261,8 +265,7 @@ function KeepProviderContent({
|
|
|
261
265
|
next = validated;
|
|
262
266
|
}
|
|
263
267
|
if (needsMigrationPersist) {
|
|
264
|
-
|
|
265
|
-
else for (const item of next) await storage.set(item);
|
|
268
|
+
await persistKeepItems(storage, next);
|
|
266
269
|
}
|
|
267
270
|
setItems(next);
|
|
268
271
|
store.setState({ error: null });
|
|
@@ -328,6 +331,20 @@ function KeepProviderContent({
|
|
|
328
331
|
},
|
|
329
332
|
[enqueueOperation, reportError, runAfterPlugins, runBeforePlugins, setItems, store]
|
|
330
333
|
);
|
|
334
|
+
const updateItem = useCallback(
|
|
335
|
+
(action, id, update, onSuccess) => runMutation(action, id, (previous) => {
|
|
336
|
+
const current = previous.find((item) => item.id === id);
|
|
337
|
+
if (!current) return void 0;
|
|
338
|
+
const next = update(current);
|
|
339
|
+
return {
|
|
340
|
+
next: previous.map((item) => item.id === id ? next : item),
|
|
341
|
+
persist: () => storage.set(next),
|
|
342
|
+
onSuccess: () => onSuccess?.(next),
|
|
343
|
+
pluginContext: { action, id, item: next }
|
|
344
|
+
};
|
|
345
|
+
}),
|
|
346
|
+
[runMutation, storage]
|
|
347
|
+
);
|
|
331
348
|
const saveItem = useCallback(
|
|
332
349
|
async (item) => {
|
|
333
350
|
let normalizedItem;
|
|
@@ -377,8 +394,7 @@ function KeepProviderContent({
|
|
|
377
394
|
next,
|
|
378
395
|
persist: async () => {
|
|
379
396
|
try {
|
|
380
|
-
|
|
381
|
-
else for (const item of changedItems) await storage.set(item);
|
|
397
|
+
await persistKeepItems(storage, changedItems);
|
|
382
398
|
} catch (cause) {
|
|
383
399
|
await restoreItems(storage, previous);
|
|
384
400
|
throw cause;
|
|
@@ -401,8 +417,7 @@ function KeepProviderContent({
|
|
|
401
417
|
next,
|
|
402
418
|
persist: async () => {
|
|
403
419
|
try {
|
|
404
|
-
|
|
405
|
-
else for (const item of changedItems) await storage.set(item);
|
|
420
|
+
await persistKeepItems(storage, changedItems);
|
|
406
421
|
} catch (cause) {
|
|
407
422
|
await restoreItems(storage, previous);
|
|
408
423
|
throw cause;
|
|
@@ -417,51 +432,36 @@ function KeepProviderContent({
|
|
|
417
432
|
const updateNote = useCallback(
|
|
418
433
|
async (id, note) => {
|
|
419
434
|
const nextNote = note?.trim() || void 0;
|
|
420
|
-
await
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
persist: () => storage.set(next),
|
|
427
|
-
onSuccess: () => handlersRef.current.onNoteUpdate?.(id, nextNote),
|
|
428
|
-
pluginContext: { action: "updateNote", id, item: next }
|
|
429
|
-
};
|
|
430
|
-
});
|
|
435
|
+
await updateItem(
|
|
436
|
+
"updateNote",
|
|
437
|
+
id,
|
|
438
|
+
(current) => ({ ...current, note: nextNote, updatedAt: Date.now() }),
|
|
439
|
+
() => handlersRef.current.onNoteUpdate?.(id, nextNote)
|
|
440
|
+
);
|
|
431
441
|
},
|
|
432
|
-
[
|
|
442
|
+
[updateItem]
|
|
433
443
|
);
|
|
434
444
|
const updateTags = useCallback(
|
|
435
445
|
async (id, tags) => {
|
|
436
446
|
const nextTags = normalizeKeepTags(tags);
|
|
437
|
-
await
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
persist: () => storage.set(next),
|
|
444
|
-
onSuccess: () => handlersRef.current.onTagsUpdate?.(id, nextTags),
|
|
445
|
-
pluginContext: { action: "updateTags", id, item: next }
|
|
446
|
-
};
|
|
447
|
-
});
|
|
447
|
+
await updateItem(
|
|
448
|
+
"updateTags",
|
|
449
|
+
id,
|
|
450
|
+
(current) => ({ ...current, tags: nextTags, updatedAt: Date.now() }),
|
|
451
|
+
() => handlersRef.current.onTagsUpdate?.(id, nextTags)
|
|
452
|
+
);
|
|
448
453
|
},
|
|
449
|
-
[
|
|
454
|
+
[updateItem]
|
|
455
|
+
);
|
|
456
|
+
const recordOpen = useCallback(
|
|
457
|
+
(id, openedAt = Date.now()) => updateItem("open", id, (current) => ({ ...current, lastOpenedAt: openedAt, updatedAt: Date.now() })),
|
|
458
|
+
[updateItem]
|
|
450
459
|
);
|
|
451
460
|
const setArchive = useCallback(
|
|
452
461
|
async (id, archived) => {
|
|
453
|
-
await
|
|
454
|
-
const current = previous.find((item) => item.id === id);
|
|
455
|
-
if (!current) return void 0;
|
|
456
|
-
const next = { ...current, archived, updatedAt: Date.now() };
|
|
457
|
-
return {
|
|
458
|
-
next: previous.map((item) => item.id === id ? next : item),
|
|
459
|
-
persist: () => storage.set(next),
|
|
460
|
-
pluginContext: { action: "archive", id, item: next }
|
|
461
|
-
};
|
|
462
|
-
});
|
|
462
|
+
await updateItem("archive", id, (current) => ({ ...current, archived, updatedAt: Date.now() }));
|
|
463
463
|
},
|
|
464
|
-
[
|
|
464
|
+
[updateItem]
|
|
465
465
|
);
|
|
466
466
|
const toggleArchive = useCallback(
|
|
467
467
|
(id) => {
|
|
@@ -474,39 +474,27 @@ function KeepProviderContent({
|
|
|
474
474
|
const unarchiveItem = useCallback((id) => setArchive(id, false), [setArchive]);
|
|
475
475
|
const togglePin = useCallback(
|
|
476
476
|
async (id) => {
|
|
477
|
-
await
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
next: previous.map((item) => item.id === id ? next : item),
|
|
483
|
-
persist: () => storage.set(next),
|
|
484
|
-
pluginContext: { action: "pin", id, item: next }
|
|
485
|
-
};
|
|
486
|
-
});
|
|
477
|
+
await updateItem("pin", id, (current) => ({
|
|
478
|
+
...current,
|
|
479
|
+
pinned: current.pinned !== true,
|
|
480
|
+
updatedAt: Date.now()
|
|
481
|
+
}));
|
|
487
482
|
},
|
|
488
|
-
[
|
|
483
|
+
[updateItem]
|
|
489
484
|
);
|
|
490
485
|
const moveToCollection = useCallback(
|
|
491
486
|
async (id, collectionId) => {
|
|
492
487
|
const nextCollectionId = collectionId?.trim() || void 0;
|
|
493
|
-
await
|
|
494
|
-
const current = previous.find((item) => item.id === id);
|
|
495
|
-
if (!current) return void 0;
|
|
488
|
+
await updateItem("collection", id, (current) => {
|
|
496
489
|
const { collectionId: _oldCollectionId, ...withoutCollection } = current;
|
|
497
|
-
|
|
490
|
+
return {
|
|
498
491
|
...withoutCollection,
|
|
499
492
|
...nextCollectionId ? { collectionId: nextCollectionId } : {},
|
|
500
493
|
updatedAt: Date.now()
|
|
501
494
|
};
|
|
502
|
-
return {
|
|
503
|
-
next: previous.map((item) => item.id === id ? next : item),
|
|
504
|
-
persist: () => storage.set(next),
|
|
505
|
-
pluginContext: { action: "collection", id, item: next }
|
|
506
|
-
};
|
|
507
495
|
});
|
|
508
496
|
},
|
|
509
|
-
[
|
|
497
|
+
[updateItem]
|
|
510
498
|
);
|
|
511
499
|
const createCollection = useCallback(
|
|
512
500
|
async (id, name) => {
|
|
@@ -724,8 +712,7 @@ function KeepProviderContent({
|
|
|
724
712
|
return {
|
|
725
713
|
next,
|
|
726
714
|
persist: async () => {
|
|
727
|
-
|
|
728
|
-
else for (const item of pending.items) await storage.set(item);
|
|
715
|
+
await persistKeepItems(storage, pending.items);
|
|
729
716
|
},
|
|
730
717
|
onSuccess: () => handlersRef.current.onUndo?.(pending.items),
|
|
731
718
|
pluginContext: { action: "undo", items: pending.items }
|
|
@@ -763,13 +750,11 @@ function KeepProviderContent({
|
|
|
763
750
|
await runBeforePlugins(pluginContext);
|
|
764
751
|
if (summary.updatedItems.length > 0) {
|
|
765
752
|
persistenceStarted = true;
|
|
766
|
-
|
|
767
|
-
else for (const item of summary.updatedItems) await storage.set(item);
|
|
753
|
+
await persistKeepItems(storage, summary.updatedItems);
|
|
768
754
|
}
|
|
769
755
|
if (summary.removedIds.length > 0) {
|
|
770
756
|
persistenceStarted = true;
|
|
771
|
-
|
|
772
|
-
else for (const id of summary.removedIds) await storage.remove(id);
|
|
757
|
+
await removeKeepItems(storage, summary.removedIds);
|
|
773
758
|
}
|
|
774
759
|
setItems(summary.items);
|
|
775
760
|
store.setState({ error: null });
|
|
@@ -889,6 +874,7 @@ function KeepProviderContent({
|
|
|
889
874
|
syncState,
|
|
890
875
|
undo,
|
|
891
876
|
saveItem,
|
|
877
|
+
recordOpen,
|
|
892
878
|
updateNote,
|
|
893
879
|
updateTags,
|
|
894
880
|
toggleArchive,
|
|
@@ -934,6 +920,7 @@ function KeepProviderContent({
|
|
|
934
920
|
refresh,
|
|
935
921
|
removeItem,
|
|
936
922
|
saveItem,
|
|
923
|
+
recordOpen,
|
|
937
924
|
removeItemWithUndo,
|
|
938
925
|
removeItemsWithUndo,
|
|
939
926
|
undoLastRemoval,
|
|
@@ -962,6 +949,7 @@ function KeepProviderContent({
|
|
|
962
949
|
const actions = useMemo(
|
|
963
950
|
() => ({
|
|
964
951
|
saveItem,
|
|
952
|
+
recordOpen,
|
|
965
953
|
updateNote,
|
|
966
954
|
updateTags,
|
|
967
955
|
toggleArchive,
|
|
@@ -998,6 +986,7 @@ function KeepProviderContent({
|
|
|
998
986
|
removeTagsBatch,
|
|
999
987
|
renameCollection,
|
|
1000
988
|
saveItem,
|
|
989
|
+
recordOpen,
|
|
1001
990
|
updateNote,
|
|
1002
991
|
updateTags,
|
|
1003
992
|
toggleArchive,
|
|
@@ -1036,11 +1025,7 @@ async function parseKeepMetaItem(item, schema) {
|
|
|
1036
1025
|
}
|
|
1037
1026
|
async function restoreItems(storage, items) {
|
|
1038
1027
|
try {
|
|
1039
|
-
|
|
1040
|
-
await storage.setMany(items);
|
|
1041
|
-
return;
|
|
1042
|
-
}
|
|
1043
|
-
for (const item of items) await storage.set(item);
|
|
1028
|
+
await persistKeepItems(storage, items);
|
|
1044
1029
|
} catch {
|
|
1045
1030
|
}
|
|
1046
1031
|
}
|
|
@@ -1102,6 +1087,7 @@ function useKeepItem(input) {
|
|
|
1102
1087
|
});
|
|
1103
1088
|
}, [actions, currentOrder, input, item?.savedAt]);
|
|
1104
1089
|
const remove = useCallback3(() => actions.removeItem(id), [actions, id]);
|
|
1090
|
+
const recordOpen = useCallback3((openedAt) => actions.recordOpen(id, openedAt), [actions, id]);
|
|
1105
1091
|
const removeWithUndo = useCallback3(() => actions.removeItemWithUndo(id), [actions, id]);
|
|
1106
1092
|
const toggle = useCallback3(() => item ? remove() : save(), [item, remove, save]);
|
|
1107
1093
|
const updateNote = useCallback3((note) => actions.updateNote(id, note), [actions, id]);
|
|
@@ -1125,6 +1111,7 @@ function useKeepItem(input) {
|
|
|
1125
1111
|
isMutating,
|
|
1126
1112
|
error,
|
|
1127
1113
|
save,
|
|
1114
|
+
recordOpen,
|
|
1128
1115
|
remove,
|
|
1129
1116
|
removeWithUndo,
|
|
1130
1117
|
undo: actions.undoLastRemoval,
|
|
@@ -1301,9 +1288,6 @@ function getCollectionName(value, fallback) {
|
|
|
1301
1288
|
if (isRecord(value) && typeof value.name === "string" && value.name.trim()) return value.name.trim();
|
|
1302
1289
|
return fallback;
|
|
1303
1290
|
}
|
|
1304
|
-
function isRecord(value) {
|
|
1305
|
-
return typeof value === "object" && value !== null;
|
|
1306
|
-
}
|
|
1307
1291
|
|
|
1308
1292
|
// src/react/hooks/useKeepList.ts
|
|
1309
1293
|
import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
|
|
@@ -1311,6 +1295,7 @@ function useKeepList(query = {}) {
|
|
|
1311
1295
|
const { store, actions } = useKeepStore();
|
|
1312
1296
|
const {
|
|
1313
1297
|
archiveScope,
|
|
1298
|
+
activity,
|
|
1314
1299
|
archived,
|
|
1315
1300
|
collectionId,
|
|
1316
1301
|
filter,
|
|
@@ -1325,6 +1310,7 @@ function useKeepList(query = {}) {
|
|
|
1325
1310
|
const queryOptions = useMemo3(
|
|
1326
1311
|
() => ({
|
|
1327
1312
|
archiveScope,
|
|
1313
|
+
activity,
|
|
1328
1314
|
archived,
|
|
1329
1315
|
collectionId,
|
|
1330
1316
|
filter,
|
|
@@ -1338,6 +1324,7 @@ function useKeepList(query = {}) {
|
|
|
1338
1324
|
}),
|
|
1339
1325
|
[
|
|
1340
1326
|
archiveScope,
|
|
1327
|
+
activity,
|
|
1341
1328
|
archived,
|
|
1342
1329
|
collectionId,
|
|
1343
1330
|
filter,
|
|
@@ -1512,6 +1499,17 @@ function useKeepNavigator(options = {}) {
|
|
|
1512
1499
|
return { ...navigation, goToNext, goToPrev, goToIndex, goToItem };
|
|
1513
1500
|
}
|
|
1514
1501
|
|
|
1502
|
+
// src/react/hooks/useKeepRediscovery.ts
|
|
1503
|
+
import { useMemo as useMemo5 } from "react";
|
|
1504
|
+
function useKeepRediscovery(options) {
|
|
1505
|
+
const { strategy, inactiveForMs, limit } = options;
|
|
1506
|
+
const query = useMemo5(() => {
|
|
1507
|
+
const base = createRediscoveryQuery({ strategy, inactiveForMs });
|
|
1508
|
+
return limit === void 0 ? base : { ...base, pagination: { page: 1, pageSize: Math.max(1, limit) } };
|
|
1509
|
+
}, [inactiveForMs, limit, strategy]);
|
|
1510
|
+
return { ...useKeepList(query), query };
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1515
1513
|
// src/react/hooks/useKeepShortcut.ts
|
|
1516
1514
|
import { useEffect as useEffect2 } from "react";
|
|
1517
1515
|
function useKeepShortcut(options) {
|
|
@@ -1578,6 +1576,7 @@ function createKeepKit(options = {}) {
|
|
|
1578
1576
|
useItem: (item) => useKeepItem(item),
|
|
1579
1577
|
useCollections: (collectionsOptions) => useKeepCollections(collectionsOptions),
|
|
1580
1578
|
useList: (query) => useKeepList(query),
|
|
1579
|
+
useRediscovery: (rediscoveryOptions) => useKeepRediscovery(rediscoveryOptions),
|
|
1581
1580
|
useNavigator: (navigatorOptions) => useKeepNavigator(navigatorOptions),
|
|
1582
1581
|
useShortcut: (shortcutOptions) => useKeepShortcut(shortcutOptions)
|
|
1583
1582
|
};
|
|
@@ -1587,12 +1586,14 @@ export {
|
|
|
1587
1586
|
KeepErrorBoundary,
|
|
1588
1587
|
KeepProvider,
|
|
1589
1588
|
createKeepKit,
|
|
1589
|
+
createRediscoveryQuery,
|
|
1590
1590
|
isKeepItemMetadataStale,
|
|
1591
1591
|
useKeepCollections,
|
|
1592
1592
|
useKeepContext,
|
|
1593
1593
|
useKeepItem,
|
|
1594
1594
|
useKeepList,
|
|
1595
1595
|
useKeepNavigator,
|
|
1596
|
+
useKeepRediscovery,
|
|
1596
1597
|
useKeepShortcut,
|
|
1597
1598
|
useKeepStore
|
|
1598
1599
|
};
|