@keepkit/core 0.28.15 → 0.28.17

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  persistKeepItems,
3
3
  removeKeepItems
4
- } from "./chunk-WKXLHEAK.js";
4
+ } from "./chunk-HTTOCLOC.js";
5
5
 
6
6
  // src/features/items/navigation.ts
7
7
  function orderKeepItems(items) {
@@ -273,4 +273,4 @@ export {
273
273
  reconcileKeepItems,
274
274
  KeepStore
275
275
  };
276
- //# sourceMappingURL=chunk-36NNVLEU.js.map
276
+ //# sourceMappingURL=chunk-OLGYOC3D.js.map
package/dist/core.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { S as StorageAdapter, d as KeepCollectionMembership, K as KeepItem, e as KeepScope, R as RemoteSyncDriver, f as KeepPluginContext, g as KeepPlugin, h as SyncOperation, i as KeepCollectionSyncOperation, j as KeepMembershipSyncOperation, k as SyncScope, l as SyncCapableStorageAdapter, m as RemoteSyncResult, n as KeepCollectionSyncResult, o as KeepCollectionDefinition, p as KeepSyncAuthError } from './types-KNIY89_m.js';
2
- export { F as FallbackRecoveryJournal, q as FallbackRecoveryJournalState, r as FallbackRecoveryJournalV2, s as FallbackRecoveryOperation, t as FallbackRecoverySnapshot, I as ImportItemsOptions, u as ImportItemsResult, v as KEEP_BACKUP_FORMAT, w as KEEP_BACKUP_VERSION, x as KeepAction, y as KeepBackup, z as KeepBackupAppliedCounts, A as KeepBackupDataType, B as KeepBackupImportError, C as KeepBackupParseError, D as KeepBackupSummary, E as KeepBackupV1, G as KeepBackupV2, b as KeepChangeContext, H as KeepChangePhase, J as KeepCollectionSyncConflict, L as KeepConflictContext, M as KeepConflictResolver, N as KeepErrorContext, O as KeepErrorHandler, P as KeepEventHandlers, Q as KeepInvalidItemPolicy, T as KeepItemInput, a as KeepItemStatus, U as KeepRecoveryInspection, V as KeepRecoveryResult, W as KeepRecoveryRow, X as KeepRecoveryState, Y as KeepSchema, Z as KeepSchemaParseResult, _ as KeepStorageAccessError, $ as KeepStorageError, a0 as KeepStorageOperation, a1 as KeepStorageParseError, a2 as KeepStorageQuotaError, a3 as KeepStorageRecovery, a4 as KeepStorageSerializationError, a5 as KeepSyncAuthStatus, a6 as KeepSyncConflict, a7 as KeepSyncQueueOperation, a8 as KeepSyncRejectedOperation, a9 as KeepSyncResolution, aa as KeepSyncState, ab as KeepSyncStatus, c as KeepUndoState, ac as LocalStorageRecoveryJournal, ad as ScopedStorageAdapter, ae as ScopedSyncQueueAdapter, af as SyncQueueAdapter, ag as createScopedStorageAdapter, ah as exportItems, ai as formatItemsAsMarkdown, aj as getKeepScopeKey, ak as importItems, al as inspectKeepBackup, am as isKeepSyncAuthError, an as isSameKeepScope, ao as normalizeKeepTags } from './types-KNIY89_m.js';
3
- import { K as KeepListQuery } from './store-D-ZFtgDn.js';
4
- export { D as DEFAULT_KEEP_URL_PARAMS, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, c as KeepItemMetadataRefresher, d as KeepItemResolver, e as KeepItemRevalidationRecord, f as KeepItemRevalidationResult, g as KeepItemRevalidationSummary, h as KeepItemRevalidator, i as KeepNavigationState, j as KeepRediscoveryOptions, k as KeepRediscoveryStrategy, l as KeepStore, m as KeepStoreActions, n as KeepStoreState, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, r as createInboxQuery, s as createRediscoveryQuery, t as decodeKeepListQuery, u as encodeKeepListQuery, v as getKeepNavigationState, w as getTagCounts, x as isKeepItemMetadataStale, y as mergeKeepListQueryFromUrl, z as moveKeepItem, A as orderKeepItems, B as queryKeepItems, C as reconcileKeepItems, E as reorderKeepItems, F as revalidateKeepItems, G as serializeKeepListQuery } from './store-D-ZFtgDn.js';
1
+ import { S as StorageAdapter, d as KeepCollectionMembership, K as KeepItem, e as KeepScope, R as RemoteSyncDriver, f as KeepPluginContext, g as KeepPlugin, h as SyncOperation, i as KeepCollectionSyncOperation, j as KeepMembershipSyncOperation, k as SyncScope, l as SyncCapableStorageAdapter, m as RemoteSyncResult, n as KeepCollectionSyncResult, o as KeepCollectionDefinition, p as KeepSyncAuthError } from './types-Bnc0c8CB.js';
2
+ export { F as FallbackRecoveryJournal, q as FallbackRecoveryJournalState, r as FallbackRecoveryJournalV2, s as FallbackRecoveryOperation, t as FallbackRecoverySnapshot, I as ImportItemsOptions, u as ImportItemsResult, v as KEEP_BACKUP_FORMAT, w as KEEP_BACKUP_VERSION, x as KeepAction, y as KeepBackup, z as KeepBackupAppliedCounts, A as KeepBackupDataType, B as KeepBackupImportError, C as KeepBackupParseError, D as KeepBackupSummary, E as KeepBackupV1, G as KeepBackupV2, b as KeepChangeContext, H as KeepChangePhase, J as KeepCollectionSyncConflict, L as KeepConflictContext, M as KeepConflictResolver, N as KeepErrorContext, O as KeepErrorHandler, P as KeepEventHandlers, Q as KeepInvalidItemPolicy, T as KeepItemInput, a as KeepItemStatus, U as KeepRecoveryInspection, V as KeepRecoveryResult, W as KeepRecoveryRow, X as KeepRecoveryState, Y as KeepSchema, Z as KeepSchemaParseResult, _ as KeepStorageAccessError, $ as KeepStorageError, a0 as KeepStorageOperation, a1 as KeepStorageParseError, a2 as KeepStorageQuotaError, a3 as KeepStorageRecovery, a4 as KeepStorageSerializationError, a5 as KeepSyncAuthStatus, a6 as KeepSyncConflict, a7 as KeepSyncQueueOperation, a8 as KeepSyncRejectedOperation, a9 as KeepSyncResolution, aa as KeepSyncState, ab as KeepSyncStatus, c as KeepUndoState, ac as LocalStorageRecoveryJournal, ad as ScopedStorageAdapter, ae as ScopedSyncQueueAdapter, af as SyncQueueAdapter, ag as createScopedStorageAdapter, ah as exportItems, ai as formatItemsAsMarkdown, aj as getKeepScopeKey, ak as importItems, al as inspectKeepBackup, am as isKeepSyncAuthError, an as isSameKeepScope, ao as normalizeKeepTags } from './types-Bnc0c8CB.js';
3
+ import { K as KeepListQuery } from './store-3LwroO9A.js';
4
+ export { D as DEFAULT_KEEP_URL_PARAMS, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, c as KeepItemMetadataRefresher, d as KeepItemResolver, e as KeepItemRevalidationRecord, f as KeepItemRevalidationResult, g as KeepItemRevalidationSummary, h as KeepItemRevalidator, i as KeepNavigationState, j as KeepRediscoveryOptions, k as KeepRediscoveryStrategy, l as KeepStore, m as KeepStoreActions, n as KeepStoreState, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, r as createInboxQuery, s as createRediscoveryQuery, t as decodeKeepListQuery, u as encodeKeepListQuery, v as getKeepNavigationState, w as getTagCounts, x as isKeepItemMetadataStale, y as mergeKeepListQueryFromUrl, z as moveKeepItem, A as orderKeepItems, B as queryKeepItems, C as reconcileKeepItems, E as reorderKeepItems, F as revalidateKeepItems, G as serializeKeepListQuery } from './store-3LwroO9A.js';
5
5
  export { KeepSchemaValidationError, parseKeepMeta, validateKeepItem } from './schema.js';
6
6
  import { SyncStorageAdapterOptions, BrowserStorageAdapterOptions } from './storage.js';
7
7
  export { DEFAULT_INDEXEDDB_DATABASE, DEFAULT_INDEXEDDB_STORE, DEFAULT_STORAGE_KEY, DEFAULT_SYNC_QUEUE_DATABASE, DEFAULT_SYNC_QUEUE_KEY, DEFAULT_SYNC_QUEUE_STORE, FallbackStorageAdapter, FallbackStorageAdapterOptions, FallbackSyncQueueAdapter, FallbackSyncQueueAdapterOptions, IndexedDBAdapter, IndexedDBAdapterOptions, IndexedDBSyncQueueAdapter, IndexedDBSyncQueueOptions, LocalStorageAdapter, LocalStorageAdapterOptions, LocalStorageSyncQueueAdapter, LocalStorageSyncQueueOptions, RecoveryJournalFactoryContext, StorageAdapterFactoryOptions, SyncStorageAdapter, createBrowserStorageAdapter, createStorageAdapter } from './storage.js';
package/dist/core.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  reconcileKeepItems,
12
12
  reorderKeepItems,
13
13
  revalidateKeepItems
14
- } from "./chunk-36NNVLEU.js";
14
+ } from "./chunk-OLGYOC3D.js";
15
15
  import {
16
16
  DEFAULT_INDEXEDDB_DATABASE,
17
17
  DEFAULT_INDEXEDDB_STORE,
@@ -55,7 +55,7 @@ import {
55
55
  migrateLegacyCollectionMemberships,
56
56
  normalizeKeepTags,
57
57
  withLocalStorageWriteLock
58
- } from "./chunk-WKXLHEAK.js";
58
+ } from "./chunk-HTTOCLOC.js";
59
59
  import {
60
60
  KeepSchemaValidationError,
61
61
  parseKeepMeta,
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { c as KeepItemMetadataRefresher, h as KeepItemRevalidator, d as KeepItemResolver, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, R as RevalidateKeepItemsOptions, g as KeepItemRevalidationSummary, l as KeepStore, m as KeepStoreActions, K as KeepListQuery, i as KeepNavigationState, j as KeepRediscoveryOptions } from './store-D-ZFtgDn.js';
2
- export { f as KeepItemRevalidationResult, k as KeepRediscoveryStrategy, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, s as createRediscoveryQuery, x as isKeepItemMetadataStale } from './store-D-ZFtgDn.js';
3
- import { T as KeepItemInput, K as KeepItem, P as KeepEventHandlers, S as StorageAdapter, g as KeepPlugin, Y as KeepSchema, Q as KeepInvalidItemPolicy, b as KeepChangeContext, aa as KeepSyncState, c as KeepUndoState, I as ImportItemsOptions, u as ImportItemsResult } from './types-KNIY89_m.js';
4
- export { a as KeepItemStatus, e as KeepScope, ad as ScopedStorageAdapter } from './types-KNIY89_m.js';
1
+ import { c as KeepItemMetadataRefresher, h as KeepItemRevalidator, d as KeepItemResolver, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, R as RevalidateKeepItemsOptions, g as KeepItemRevalidationSummary, l as KeepStore, m as KeepStoreActions, K as KeepListQuery, i as KeepNavigationState, j as KeepRediscoveryOptions } from './store-3LwroO9A.js';
2
+ export { f as KeepItemRevalidationResult, k as KeepRediscoveryStrategy, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, s as createRediscoveryQuery, x as isKeepItemMetadataStale } from './store-3LwroO9A.js';
3
+ import { T as KeepItemInput, K as KeepItem, P as KeepEventHandlers, S as StorageAdapter, g as KeepPlugin, Y as KeepSchema, Q as KeepInvalidItemPolicy, b as KeepChangeContext, aa as KeepSyncState, c as KeepUndoState, I as ImportItemsOptions, u as ImportItemsResult } from './types-Bnc0c8CB.js';
4
+ export { a as KeepItemStatus, e as KeepScope, ad as ScopedStorageAdapter } from './types-Bnc0c8CB.js';
5
5
  import * as react from 'react';
6
6
  import { ReactNode, Ref, ButtonHTMLAttributes, MouseEvent, HTMLAttributes, ReactElement, ErrorInfo, Component, PropsWithChildren, ComponentType } from 'react';
7
7
 
package/dist/react.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  queryKeepItems,
10
10
  reorderKeepItems,
11
11
  revalidateKeepItems
12
- } from "./chunk-36NNVLEU.js";
12
+ } from "./chunk-OLGYOC3D.js";
13
13
  import {
14
14
  createBrowserStorageAdapter,
15
15
  exportItems,
@@ -18,7 +18,7 @@ import {
18
18
  normalizeKeepTags,
19
19
  persistKeepItems,
20
20
  removeKeepItems
21
- } from "./chunk-WKXLHEAK.js";
21
+ } from "./chunk-HTTOCLOC.js";
22
22
  import {
23
23
  parseKeepMeta
24
24
  } from "./chunk-5W4QSJHV.js";
@@ -184,6 +184,7 @@ function KeepProviderContent({
184
184
  const pendingRefreshesRef = useRef(0);
185
185
  const pendingMutationsRef = useRef(0);
186
186
  const undoRef = useRef(void 0);
187
+ const undoGenerationRef = useRef(0);
187
188
  const autoRevalidationRef = useRef(autoRevalidation);
188
189
  autoRevalidationRef.current = autoRevalidation;
189
190
  const didMountRevalidateRef = useRef(false);
@@ -311,6 +312,15 @@ function KeepProviderContent({
311
312
  useEffect(() => {
312
313
  void refresh();
313
314
  }, [refresh]);
315
+ useEffect(
316
+ () => () => {
317
+ undoGenerationRef.current += 1;
318
+ if (undoRef.current?.timer) clearTimeout(undoRef.current.timer);
319
+ undoRef.current = void 0;
320
+ store.setState({ undo: EMPTY_UNDO_STATE, lastChange: void 0 });
321
+ },
322
+ [storage, store]
323
+ );
314
324
  useEffect(() => {
315
325
  if (!storage.subscribe) return;
316
326
  return storage.subscribe(() => void refresh());
@@ -320,6 +330,7 @@ function KeepProviderContent({
320
330
  return storage.subscribeScope(() => {
321
331
  undoRef.current?.timer && clearTimeout(undoRef.current.timer);
322
332
  undoRef.current = void 0;
333
+ undoGenerationRef.current += 1;
323
334
  itemsRef.current = [];
324
335
  store.setState({
325
336
  items: [],
@@ -327,7 +338,8 @@ function KeepProviderContent({
327
338
  isHydrated: false,
328
339
  isLoading: true,
329
340
  error: null,
330
- undo: EMPTY_UNDO_STATE
341
+ undo: EMPTY_UNDO_STATE,
342
+ lastChange: void 0
331
343
  });
332
344
  void refresh();
333
345
  });
@@ -780,6 +792,7 @@ function KeepProviderContent({
780
792
  );
781
793
  const rememberUndo = useCallback(
782
794
  (removedItems) => {
795
+ undoGenerationRef.current += 1;
783
796
  undoRef.current?.timer && clearTimeout(undoRef.current.timer);
784
797
  const startedAt = Date.now();
785
798
  const expiresAt = startedAt + Math.max(0, undoTimeoutMs);
@@ -820,22 +833,38 @@ function KeepProviderContent({
820
833
  return;
821
834
  }
822
835
  if (pending.timer) clearTimeout(pending.timer);
836
+ const generation = undoGenerationRef.current;
837
+ const previousUndo = store.getSnapshot().undo;
823
838
  undoRef.current = void 0;
824
839
  store.setState({ undo: { canUndo: false, ids: [] } });
825
- await runMutation("undo", void 0, (previous) => {
826
- const restored = new Map(pending.items.map((item) => [item.id, item]));
827
- const next = [...previous.filter((item) => !restored.has(item.id)), ...pending.items].sort(
828
- (a, b) => b.updatedAt - a.updatedAt
829
- );
830
- return {
831
- next,
832
- persist: async () => {
833
- await persistKeepItems(storage, pending.items);
834
- },
835
- onSuccess: [() => handlersRef.current.onUndo?.(pending.items)],
836
- pluginContext: { action: "undo", items: pending.items }
837
- };
838
- });
840
+ try {
841
+ await runMutation("undo", void 0, (previous) => {
842
+ const restored = new Map(pending.items.map((item) => [item.id, item]));
843
+ const next = [...previous.filter((item) => !restored.has(item.id)), ...pending.items].sort(
844
+ (a, b) => b.updatedAt - a.updatedAt
845
+ );
846
+ return {
847
+ next,
848
+ persist: async () => {
849
+ await persistKeepItems(storage, pending.items);
850
+ },
851
+ onSuccess: [() => handlersRef.current.onUndo?.(pending.items)],
852
+ pluginContext: { action: "undo", items: pending.items }
853
+ };
854
+ });
855
+ } catch (error2) {
856
+ const remaining = pending.expiresAt - Date.now();
857
+ if (remaining > 0 && generation === undoGenerationRef.current && !undoRef.current && previousUndo) {
858
+ pending.timer = setTimeout(() => {
859
+ if (undoRef.current !== pending) return;
860
+ undoRef.current = void 0;
861
+ store.setState({ undo: { canUndo: false, ids: [] } });
862
+ }, remaining);
863
+ undoRef.current = pending;
864
+ store.setState({ undo: previousUndo });
865
+ }
866
+ throw error2;
867
+ }
839
868
  }, [runMutation, storage, store]);
840
869
  useEffect(() => {
841
870
  if (syncState.status !== "error" || !undoRef.current) return;
@@ -1291,7 +1320,7 @@ function KeepButton({
1291
1320
  }) {
1292
1321
  const state = useKeepItem(item);
1293
1322
  const { isSaved, toggle } = state;
1294
- const isDisabled = disabled ?? state.isMutating;
1323
+ const isDisabled = Boolean(disabled || state.isLoading || state.isMutating);
1295
1324
  async function handleClick(event) {
1296
1325
  if (isDisabled) return;
1297
1326
  if (asChild) {
@@ -1310,11 +1339,17 @@ function KeepButton({
1310
1339
  }
1311
1340
  const content = typeof children === "function" ? children(state) : children ?? (isSaved ? savedLabel : unsavedLabel);
1312
1341
  function handleElementClick(event) {
1313
- if (isDisabled) return;
1342
+ if (isDisabled) {
1343
+ if (asChild) event.preventDefault();
1344
+ return;
1345
+ }
1314
1346
  if (asChild && isValidElement(content)) {
1315
1347
  content.props.onClick?.(event);
1316
1348
  }
1317
- if (!event.defaultPrevented) void handleClick(event);
1349
+ if (!event.defaultPrevented) {
1350
+ void handleClick(event);
1351
+ if (asChild && event.currentTarget instanceof HTMLAnchorElement) event.preventDefault();
1352
+ }
1318
1353
  }
1319
1354
  function handleKeyDown(event) {
1320
1355
  if (asChild && isValidElement(content)) {