@keepkit/core 0.28.1 → 0.28.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/react.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  queryKeepItems,
12
12
  reorderKeepItems,
13
13
  revalidateKeepItems
14
- } from "./chunk-JGGKIE3O.js";
14
+ } from "./chunk-IIGN4U7N.js";
15
15
  import {
16
16
  parseKeepMeta
17
17
  } from "./chunk-5W4QSJHV.js";
@@ -21,7 +21,7 @@ import {
21
21
  normalizeKeepTags,
22
22
  persistKeepItems,
23
23
  removeKeepItems
24
- } from "./chunk-HDML3IDX.js";
24
+ } from "./chunk-MZFZQIM5.js";
25
25
 
26
26
  // src/react/components/KeepButton.tsx
27
27
  import {
@@ -454,7 +454,7 @@ function KeepProviderContent({
454
454
  [updateItem]
455
455
  );
456
456
  const recordOpen = useCallback(
457
- (id, openedAt = Date.now()) => updateItem("open", id, (current) => ({ ...current, lastOpenedAt: openedAt, updatedAt: Date.now() })),
457
+ (id, openedAt = Date.now()) => updateItem("open", id, (current) => ({ ...current, lastOpenedAt: openedAt })),
458
458
  [updateItem]
459
459
  );
460
460
  const setArchive = useCallback(
@@ -496,6 +496,60 @@ function KeepProviderContent({
496
496
  },
497
497
  [updateItem]
498
498
  );
499
+ const updateItemsBatch = useCallback(
500
+ (action, ids, update) => {
501
+ const idSet = new Set(ids);
502
+ return runMutation(action, void 0, (previous) => {
503
+ const currentItems = previous.filter((item) => idSet.has(item.id));
504
+ const updatedItems = currentItems.map(update);
505
+ if (updatedItems.length === 0) return void 0;
506
+ const updatedById = new Map(updatedItems.map((item) => [item.id, item]));
507
+ return {
508
+ next: previous.map((item) => updatedById.get(item.id) ?? item),
509
+ persist: async () => {
510
+ try {
511
+ await persistKeepItems(storage, updatedItems);
512
+ } catch (cause) {
513
+ await restoreItems(storage, currentItems);
514
+ throw cause;
515
+ }
516
+ },
517
+ pluginContext: { action, items: updatedItems }
518
+ };
519
+ });
520
+ },
521
+ [runMutation, storage]
522
+ );
523
+ const archiveBatch = useCallback(
524
+ (ids) => updateItemsBatch("archive", ids, (item) => ({ ...item, archived: true, updatedAt: Date.now() })),
525
+ [updateItemsBatch]
526
+ );
527
+ const unarchiveBatch = useCallback(
528
+ (ids) => updateItemsBatch("archive", ids, (item) => ({ ...item, archived: false, updatedAt: Date.now() })),
529
+ [updateItemsBatch]
530
+ );
531
+ const pinBatch = useCallback(
532
+ (ids) => updateItemsBatch("pin", ids, (item) => ({ ...item, pinned: true, updatedAt: Date.now() })),
533
+ [updateItemsBatch]
534
+ );
535
+ const unpinBatch = useCallback(
536
+ (ids) => updateItemsBatch("pin", ids, (item) => ({ ...item, pinned: false, updatedAt: Date.now() })),
537
+ [updateItemsBatch]
538
+ );
539
+ const moveToCollectionBatch = useCallback(
540
+ (ids, collectionId) => {
541
+ const nextCollectionId = collectionId?.trim() || void 0;
542
+ return updateItemsBatch("collection", ids, (item) => {
543
+ const { collectionId: _oldCollectionId, ...withoutCollection } = item;
544
+ return {
545
+ ...withoutCollection,
546
+ ...nextCollectionId ? { collectionId: nextCollectionId } : {},
547
+ updatedAt: Date.now()
548
+ };
549
+ });
550
+ },
551
+ [updateItemsBatch]
552
+ );
499
553
  const createCollection = useCallback(
500
554
  async (id, name) => {
501
555
  const trimmedId = id.trim();
@@ -882,6 +936,11 @@ function KeepProviderContent({
882
936
  unarchiveItem,
883
937
  togglePin,
884
938
  moveToCollection,
939
+ archiveBatch,
940
+ unarchiveBatch,
941
+ pinBatch,
942
+ unpinBatch,
943
+ moveToCollectionBatch,
885
944
  createCollection,
886
945
  renameCollection,
887
946
  removeCollection,
@@ -931,6 +990,11 @@ function KeepProviderContent({
931
990
  unarchiveItem,
932
991
  togglePin,
933
992
  moveToCollection,
993
+ archiveBatch,
994
+ unarchiveBatch,
995
+ pinBatch,
996
+ unpinBatch,
997
+ moveToCollectionBatch,
934
998
  createCollection,
935
999
  renameCollection,
936
1000
  removeCollection,
@@ -957,6 +1021,11 @@ function KeepProviderContent({
957
1021
  unarchiveItem,
958
1022
  togglePin,
959
1023
  moveToCollection,
1024
+ archiveBatch,
1025
+ unarchiveBatch,
1026
+ pinBatch,
1027
+ unpinBatch,
1028
+ moveToCollectionBatch,
960
1029
  createCollection,
961
1030
  renameCollection,
962
1031
  removeCollection,
@@ -994,6 +1063,11 @@ function KeepProviderContent({
994
1063
  unarchiveItem,
995
1064
  togglePin,
996
1065
  moveToCollection,
1066
+ archiveBatch,
1067
+ unarchiveBatch,
1068
+ pinBatch,
1069
+ unpinBatch,
1070
+ moveToCollectionBatch,
997
1071
  updateTagsBatch,
998
1072
  refreshItemMetadata,
999
1073
  revalidateItems,
@@ -1298,6 +1372,7 @@ function useKeepList(query = {}) {
1298
1372
  activity,
1299
1373
  archived,
1300
1374
  collectionId,
1375
+ organization,
1301
1376
  filter,
1302
1377
  pagination,
1303
1378
  pinnedFirst,
@@ -1313,6 +1388,7 @@ function useKeepList(query = {}) {
1313
1388
  activity,
1314
1389
  archived,
1315
1390
  collectionId,
1391
+ organization,
1316
1392
  filter,
1317
1393
  pagination,
1318
1394
  pinnedFirst,
@@ -1327,6 +1403,7 @@ function useKeepList(query = {}) {
1327
1403
  activity,
1328
1404
  archived,
1329
1405
  collectionId,
1406
+ organization,
1330
1407
  filter,
1331
1408
  pagination,
1332
1409
  pinnedFirst,
@@ -1397,6 +1474,14 @@ function useKeepList(query = {}) {
1397
1474
  (id, collectionId2) => actions.moveToCollection(id, collectionId2),
1398
1475
  [actions]
1399
1476
  );
1477
+ const archiveBatch = useCallback4((ids) => actions.archiveBatch(ids), [actions]);
1478
+ const unarchiveBatch = useCallback4((ids) => actions.unarchiveBatch(ids), [actions]);
1479
+ const pinBatch = useCallback4((ids) => actions.pinBatch(ids), [actions]);
1480
+ const unpinBatch = useCallback4((ids) => actions.unpinBatch(ids), [actions]);
1481
+ const moveToCollectionBatch = useCallback4(
1482
+ (ids, collectionId2) => actions.moveToCollectionBatch(ids, collectionId2),
1483
+ [actions]
1484
+ );
1400
1485
  return {
1401
1486
  items: result.items,
1402
1487
  totalCount: result.totalCount,
@@ -1424,6 +1509,11 @@ function useKeepList(query = {}) {
1424
1509
  unarchive,
1425
1510
  togglePin,
1426
1511
  moveToCollection,
1512
+ archiveBatch,
1513
+ unarchiveBatch,
1514
+ pinBatch,
1515
+ unpinBatch,
1516
+ moveToCollectionBatch,
1427
1517
  reorder: actions.reorderItems,
1428
1518
  move: actions.moveItem,
1429
1519
  clear: actions.clear,