@keepkit/ui 0.28.16 → 0.28.18
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 +226 -5
- package/dist/chunk-4O5N26YS.js +218 -0
- package/dist/chunk-4O5N26YS.js.map +1 -0
- package/dist/chunk-5ETQGHPV.js +307 -0
- package/dist/chunk-5ETQGHPV.js.map +1 -0
- package/dist/chunk-5SFHCUDA.js +200 -0
- package/dist/chunk-5SFHCUDA.js.map +1 -0
- package/dist/chunk-6753KF4D.js +357 -0
- package/dist/chunk-6753KF4D.js.map +1 -0
- package/dist/chunk-6JKG6SKJ.js +234 -0
- package/dist/chunk-6JKG6SKJ.js.map +1 -0
- package/dist/chunk-7DCSOVGM.js +23 -0
- package/dist/chunk-7DCSOVGM.js.map +1 -0
- package/dist/chunk-7DOB3Z6F.js +565 -0
- package/dist/chunk-7DOB3Z6F.js.map +1 -0
- package/dist/chunk-AQOSZ6AW.js +287 -0
- package/dist/chunk-AQOSZ6AW.js.map +1 -0
- package/dist/chunk-BJCZ7MFN.js +322 -0
- package/dist/chunk-BJCZ7MFN.js.map +1 -0
- package/dist/chunk-BW4SUJIX.js +135 -0
- package/dist/chunk-BW4SUJIX.js.map +1 -0
- package/dist/chunk-BYYWJGSN.js +220 -0
- package/dist/chunk-BYYWJGSN.js.map +1 -0
- package/dist/chunk-CIVXLU4D.js +111 -0
- package/dist/chunk-CIVXLU4D.js.map +1 -0
- package/dist/chunk-DMDBZJPO.js +37 -0
- package/dist/chunk-DMDBZJPO.js.map +1 -0
- package/dist/chunk-DQ5RMIU5.js +112 -0
- package/dist/chunk-DQ5RMIU5.js.map +1 -0
- package/dist/chunk-G2JWJKST.js +95 -0
- package/dist/chunk-G2JWJKST.js.map +1 -0
- package/dist/chunk-G76JVCNJ.js +55 -0
- package/dist/chunk-G76JVCNJ.js.map +1 -0
- package/dist/chunk-GZEFBTVD.js +37 -0
- package/dist/chunk-GZEFBTVD.js.map +1 -0
- package/dist/chunk-HFXB4S72.js +160 -0
- package/dist/chunk-HFXB4S72.js.map +1 -0
- package/dist/chunk-JJ4L5AKR.js +389 -0
- package/dist/chunk-JJ4L5AKR.js.map +1 -0
- package/dist/chunk-K2L44I7D.js +152 -0
- package/dist/chunk-K2L44I7D.js.map +1 -0
- package/dist/chunk-LKNVVPTN.js +210 -0
- package/dist/chunk-LKNVVPTN.js.map +1 -0
- package/dist/chunk-M3UORQXZ.js +2983 -0
- package/dist/chunk-M3UORQXZ.js.map +1 -0
- package/dist/chunk-M46GROWD.js +116 -0
- package/dist/chunk-M46GROWD.js.map +1 -0
- package/dist/chunk-MMGM7JIE.js +141 -0
- package/dist/chunk-MMGM7JIE.js.map +1 -0
- package/dist/chunk-NOPTRHRR.js +26 -0
- package/dist/chunk-NOPTRHRR.js.map +1 -0
- package/dist/chunk-NSYL6RSY.js +20 -0
- package/dist/chunk-NSYL6RSY.js.map +1 -0
- package/dist/chunk-NVFKN4NU.js +94 -0
- package/dist/chunk-NVFKN4NU.js.map +1 -0
- package/dist/chunk-P2WLTFPG.js +46 -0
- package/dist/chunk-P2WLTFPG.js.map +1 -0
- package/dist/chunk-PE57SLZO.js +798 -0
- package/dist/chunk-PE57SLZO.js.map +1 -0
- package/dist/chunk-PHFY6LQT.js +167 -0
- package/dist/chunk-PHFY6LQT.js.map +1 -0
- package/dist/chunk-PZHARNLY.js +208 -0
- package/dist/chunk-PZHARNLY.js.map +1 -0
- package/dist/chunk-Q6AFJL4Y.js +318 -0
- package/dist/chunk-Q6AFJL4Y.js.map +1 -0
- package/dist/chunk-Q7IEJ2YF.js +49 -0
- package/dist/chunk-Q7IEJ2YF.js.map +1 -0
- package/dist/chunk-QOCX37A5.js +69 -0
- package/dist/chunk-QOCX37A5.js.map +1 -0
- package/dist/chunk-RIWL3IPZ.js +46 -0
- package/dist/chunk-RIWL3IPZ.js.map +1 -0
- package/dist/chunk-RKYQGWKB.js +229 -0
- package/dist/chunk-RKYQGWKB.js.map +1 -0
- package/dist/chunk-SYLOO5TX.js +504 -0
- package/dist/chunk-SYLOO5TX.js.map +1 -0
- package/dist/chunk-URE4EGL2.js +206 -0
- package/dist/chunk-URE4EGL2.js.map +1 -0
- package/dist/chunk-VM4ROXYF.js +114 -0
- package/dist/chunk-VM4ROXYF.js.map +1 -0
- package/dist/chunk-VTPSR3LD.js +16 -0
- package/dist/chunk-VTPSR3LD.js.map +1 -0
- package/dist/chunk-WB6NBGC2.js +112 -0
- package/dist/chunk-WB6NBGC2.js.map +1 -0
- package/dist/chunk-XJFMMRQR.js +110 -0
- package/dist/chunk-XJFMMRQR.js.map +1 -0
- package/dist/chunk-XKWDO5VL.js +156 -0
- package/dist/chunk-XKWDO5VL.js.map +1 -0
- package/dist/chunk-XVOLYEUK.js +65 -0
- package/dist/chunk-XVOLYEUK.js.map +1 -0
- package/dist/chunk-YCUQ2YTP.js +169 -0
- package/dist/chunk-YCUQ2YTP.js.map +1 -0
- package/dist/chunk-ZCDLWGQV.js +140 -0
- package/dist/chunk-ZCDLWGQV.js.map +1 -0
- package/dist/collection-select-X6WKM--x.d.ts +25 -0
- package/dist/entries/active-filters-summary.d.ts +58 -0
- package/dist/entries/active-filters-summary.js +10 -0
- package/dist/entries/active-filters-summary.js.map +1 -0
- package/dist/entries/announcements.d.ts +4 -0
- package/dist/entries/announcements.js +11 -0
- package/dist/entries/announcements.js.map +1 -0
- package/dist/entries/announcer.d.ts +4 -0
- package/dist/entries/announcer.js +11 -0
- package/dist/entries/announcer.js.map +1 -0
- package/dist/entries/archive-button.d.ts +4 -0
- package/dist/entries/archive-button.js +9 -0
- package/dist/entries/archive-button.js.map +1 -0
- package/dist/entries/archive-scope-select.d.ts +13 -0
- package/dist/entries/archive-scope-select.js +9 -0
- package/dist/entries/archive-scope-select.js.map +1 -0
- package/dist/entries/archive-undo.d.ts +6 -0
- package/dist/entries/archive-undo.js +10 -0
- package/dist/entries/archive-undo.js.map +1 -0
- package/dist/entries/backup.d.ts +19 -0
- package/dist/entries/backup.js +10 -0
- package/dist/entries/backup.js.map +1 -0
- package/dist/entries/bulk-actions.d.ts +60 -0
- package/dist/entries/bulk-actions.js +12 -0
- package/dist/entries/bulk-actions.js.map +1 -0
- package/dist/entries/button.d.ts +21 -0
- package/dist/entries/button.js +10 -0
- package/dist/entries/button.js.map +1 -0
- package/dist/entries/collection-create.d.ts +19 -0
- package/dist/entries/collection-create.js +10 -0
- package/dist/entries/collection-create.js.map +1 -0
- package/dist/entries/collection-filter.d.ts +3 -0
- package/dist/entries/collection-filter.js +10 -0
- package/dist/entries/collection-filter.js.map +1 -0
- package/dist/entries/collection-manager.d.ts +29 -0
- package/dist/entries/collection-manager.js +12 -0
- package/dist/entries/collection-manager.js.map +1 -0
- package/dist/entries/collection-select.d.ts +3 -0
- package/dist/entries/collection-select.js +10 -0
- package/dist/entries/collection-select.js.map +1 -0
- package/dist/entries/collection.d.ts +11 -0
- package/dist/entries/collection.js +32 -0
- package/dist/entries/collection.js.map +1 -0
- package/dist/entries/empty-state.d.ts +17 -0
- package/dist/entries/empty-state.js +10 -0
- package/dist/entries/empty-state.js.map +1 -0
- package/dist/entries/error-boundary.d.ts +1 -0
- package/dist/entries/error-boundary.js +8 -0
- package/dist/entries/error-boundary.js.map +1 -0
- package/dist/entries/fallback-recovery.d.ts +12 -0
- package/dist/entries/fallback-recovery.js +9 -0
- package/dist/entries/fallback-recovery.js.map +1 -0
- package/dist/entries/floating-tour.d.ts +23 -0
- package/dist/entries/floating-tour.js +14 -0
- package/dist/entries/floating-tour.js.map +1 -0
- package/dist/entries/highlight.d.ts +2 -0
- package/dist/entries/highlight.js +8 -0
- package/dist/entries/highlight.js.map +1 -0
- package/dist/entries/inbox.d.ts +19 -0
- package/dist/entries/inbox.js +33 -0
- package/dist/entries/inbox.js.map +1 -0
- package/dist/entries/item-card-skeleton.d.ts +20 -0
- package/dist/entries/item-card-skeleton.js +8 -0
- package/dist/entries/item-card-skeleton.js.map +1 -0
- package/dist/entries/item-card.d.ts +412 -0
- package/dist/entries/item-card.js +17 -0
- package/dist/entries/item-card.js.map +1 -0
- package/dist/entries/item-checkbox.d.ts +14 -0
- package/dist/entries/item-checkbox.js +8 -0
- package/dist/entries/item-checkbox.js.map +1 -0
- package/dist/entries/item-status-badge.d.ts +13 -0
- package/dist/entries/item-status-badge.js +10 -0
- package/dist/entries/item-status-badge.js.map +1 -0
- package/dist/entries/kit-provider.d.ts +18 -0
- package/dist/entries/kit-provider.js +14 -0
- package/dist/entries/kit-provider.js.map +1 -0
- package/dist/entries/last-activity.d.ts +12 -0
- package/dist/entries/last-activity.js +9 -0
- package/dist/entries/last-activity.js.map +1 -0
- package/dist/entries/layout.d.ts +21 -0
- package/dist/entries/layout.js +9 -0
- package/dist/entries/layout.js.map +1 -0
- package/dist/entries/list.d.ts +11 -0
- package/dist/entries/list.js +23 -0
- package/dist/entries/list.js.map +1 -0
- package/dist/entries/navigator.d.ts +4 -0
- package/dist/entries/navigator.js +11 -0
- package/dist/entries/navigator.js.map +1 -0
- package/dist/entries/note-editor.d.ts +32 -0
- package/dist/entries/note-editor.js +11 -0
- package/dist/entries/note-editor.js.map +1 -0
- package/dist/entries/pagination.d.ts +3 -0
- package/dist/entries/pagination.js +9 -0
- package/dist/entries/pagination.js.map +1 -0
- package/dist/entries/pin-button.d.ts +4 -0
- package/dist/entries/pin-button.js +9 -0
- package/dist/entries/pin-button.js.map +1 -0
- package/dist/entries/provider.d.ts +1 -0
- package/dist/entries/provider.js +8 -0
- package/dist/entries/provider.js.map +1 -0
- package/dist/entries/prune-stale-button.d.ts +3 -0
- package/dist/entries/prune-stale-button.js +12 -0
- package/dist/entries/prune-stale-button.js.map +1 -0
- package/dist/entries/quick-editor.d.ts +3 -0
- package/dist/entries/quick-editor.js +11 -0
- package/dist/entries/quick-editor.js.map +1 -0
- package/dist/entries/rediscovery-panel.d.ts +12 -0
- package/dist/entries/rediscovery-panel.js +24 -0
- package/dist/entries/rediscovery-panel.js.map +1 -0
- package/dist/entries/rediscovery.d.ts +12 -0
- package/dist/entries/rediscovery.js +24 -0
- package/dist/entries/rediscovery.js.map +1 -0
- package/dist/entries/reorderable-list.d.ts +35 -0
- package/dist/entries/reorderable-list.js +10 -0
- package/dist/entries/reorderable-list.js.map +1 -0
- package/dist/entries/save-popover.d.ts +39 -0
- package/dist/entries/save-popover.js +15 -0
- package/dist/entries/save-popover.js.map +1 -0
- package/dist/entries/save-view-button.d.ts +3 -0
- package/dist/entries/save-view-button.js +9 -0
- package/dist/entries/save-view-button.js.map +1 -0
- package/dist/entries/saved-views.d.ts +3 -0
- package/dist/entries/saved-views.js +9 -0
- package/dist/entries/saved-views.js.map +1 -0
- package/dist/entries/search-input.d.ts +3 -0
- package/dist/entries/search-input.js +9 -0
- package/dist/entries/search-input.js.map +1 -0
- package/dist/entries/shortcut-hint.d.ts +11 -0
- package/dist/entries/shortcut-hint.js +8 -0
- package/dist/entries/shortcut-hint.js.map +1 -0
- package/dist/entries/sort-select.d.ts +3 -0
- package/dist/entries/sort-select.js +9 -0
- package/dist/entries/sort-select.js.map +1 -0
- package/dist/entries/stale-notice.d.ts +3 -0
- package/dist/entries/stale-notice.js +12 -0
- package/dist/entries/stale-notice.js.map +1 -0
- package/dist/entries/status.d.ts +4 -0
- package/dist/entries/status.js +11 -0
- package/dist/entries/status.js.map +1 -0
- package/dist/entries/sync-recovery-dialog.d.ts +18 -0
- package/dist/entries/sync-recovery-dialog.js +11 -0
- package/dist/entries/sync-recovery-dialog.js.map +1 -0
- package/dist/entries/sync-status-banner.d.ts +12 -0
- package/dist/entries/sync-status-banner.js +10 -0
- package/dist/entries/sync-status-banner.js.map +1 -0
- package/dist/entries/tag-editor.d.ts +22 -0
- package/dist/entries/tag-editor.js +10 -0
- package/dist/entries/tag-editor.js.map +1 -0
- package/dist/entries/tag-filter.d.ts +33 -0
- package/dist/entries/tag-filter.js +10 -0
- package/dist/entries/tag-filter.js.map +1 -0
- package/dist/entries/theme-provider.d.ts +2 -0
- package/dist/entries/theme-provider.js +9 -0
- package/dist/entries/theme-provider.js.map +1 -0
- package/dist/entries/tour-bar.d.ts +4 -0
- package/dist/entries/tour-bar.js +11 -0
- package/dist/entries/tour-bar.js.map +1 -0
- package/dist/entries/tour-provider.d.ts +3 -0
- package/dist/entries/tour-provider.js +8 -0
- package/dist/entries/tour-provider.js.map +1 -0
- package/dist/entries/ui-provider.d.ts +5 -0
- package/dist/entries/ui-provider.js +8 -0
- package/dist/entries/ui-provider.js.map +1 -0
- package/dist/entries/undo.d.ts +11 -0
- package/dist/entries/undo.js +10 -0
- package/dist/entries/undo.js.map +1 -0
- package/dist/entries/workspace.d.ts +59 -0
- package/dist/entries/workspace.js +37 -0
- package/dist/entries/workspace.js.map +1 -0
- package/dist/highlight-BFeqa6kU.d.ts +40 -0
- package/dist/index.d.ts +63 -1404
- package/dist/index.js +214 -10128
- package/dist/index.js.map +1 -1
- package/dist/list-C350Dche.d.ts +141 -0
- package/dist/pin-button-DK3j0atw.d.ts +27 -0
- package/dist/quick-editor-BpsvwjQS.d.ts +61 -0
- package/dist/rediscovery-F5gTtPUz.d.ts +20 -0
- package/dist/saved-views-BXIyAVBn.d.ts +14 -0
- package/dist/sort-select-DBlR6ubA.d.ts +40 -0
- package/dist/stale-notice-DczSweyn.d.ts +24 -0
- package/dist/status-xiIQ206y.d.ts +31 -0
- package/dist/styles/base.css +100 -55
- package/dist/styles/collection.css +2 -4
- package/dist/tailwind.css +0 -30
- package/dist/theme-provider-DFMkjkmm.d.ts +37 -0
- package/dist/tour-bar-iiXvVYE8.d.ts +51 -0
- package/dist/tour-provider-BqhPK2vS.d.ts +40 -0
- package/dist/ui-context-BE201rLI.d.ts +70 -0
- package/dist/ui-provider-Bqziw03k.d.ts +7 -0
- package/package.json +226 -2
|
@@ -0,0 +1,798 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeepTagFilter
|
|
3
|
+
} from "./chunk-YCUQ2YTP.js";
|
|
4
|
+
import {
|
|
5
|
+
KeepSaveViewButton,
|
|
6
|
+
KeepSavedViews
|
|
7
|
+
} from "./chunk-6JKG6SKJ.js";
|
|
8
|
+
import {
|
|
9
|
+
KeepPagination,
|
|
10
|
+
KeepSearchInput,
|
|
11
|
+
KeepSortSelect
|
|
12
|
+
} from "./chunk-PZHARNLY.js";
|
|
13
|
+
import {
|
|
14
|
+
KeepList,
|
|
15
|
+
reorderVisibleItems
|
|
16
|
+
} from "./chunk-RKYQGWKB.js";
|
|
17
|
+
import {
|
|
18
|
+
KeepBulkActions,
|
|
19
|
+
KeepRemovalConfirmation,
|
|
20
|
+
useKeepBulkActions
|
|
21
|
+
} from "./chunk-SYLOO5TX.js";
|
|
22
|
+
import {
|
|
23
|
+
KeepCollectionCreate
|
|
24
|
+
} from "./chunk-M46GROWD.js";
|
|
25
|
+
import {
|
|
26
|
+
KeepCollectionFilter
|
|
27
|
+
} from "./chunk-CIVXLU4D.js";
|
|
28
|
+
import {
|
|
29
|
+
useKeepIcon
|
|
30
|
+
} from "./chunk-NOPTRHRR.js";
|
|
31
|
+
import {
|
|
32
|
+
KeepActiveFiltersSummary
|
|
33
|
+
} from "./chunk-JJ4L5AKR.js";
|
|
34
|
+
import {
|
|
35
|
+
KeepArchiveScopeSelect
|
|
36
|
+
} from "./chunk-Q7IEJ2YF.js";
|
|
37
|
+
import {
|
|
38
|
+
copyQueryValue,
|
|
39
|
+
equalQueryValue,
|
|
40
|
+
getErrorMessage,
|
|
41
|
+
hasRenderableContent,
|
|
42
|
+
resolveContent,
|
|
43
|
+
sortToValue
|
|
44
|
+
} from "./chunk-LKNVVPTN.js";
|
|
45
|
+
import {
|
|
46
|
+
useUiLabel,
|
|
47
|
+
useUiLabelVisibility
|
|
48
|
+
} from "./chunk-M3UORQXZ.js";
|
|
49
|
+
|
|
50
|
+
// src/adapters/url-sync.tsx
|
|
51
|
+
import {
|
|
52
|
+
DEFAULT_KEEP_URL_PARAMS,
|
|
53
|
+
decodeKeepListQuery,
|
|
54
|
+
encodeKeepListQuery
|
|
55
|
+
} from "@keepkit/core/core";
|
|
56
|
+
import { useEffect, useRef } from "react";
|
|
57
|
+
function createNextPagesRouterAdapter(router) {
|
|
58
|
+
const getUrl = () => router.asPath ?? (typeof window === "undefined" ? "/" : window.location.href);
|
|
59
|
+
return {
|
|
60
|
+
getUrl,
|
|
61
|
+
subscribe: router.events ? (listener) => {
|
|
62
|
+
router.events?.on("routeChangeComplete", listener);
|
|
63
|
+
return () => router.events?.off("routeChangeComplete", listener);
|
|
64
|
+
} : void 0,
|
|
65
|
+
navigate: (url, mode) => {
|
|
66
|
+
void router[mode](url, void 0, { shallow: true });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function useKeepUrlSync({
|
|
71
|
+
enabled = true,
|
|
72
|
+
query,
|
|
73
|
+
onQueryChange,
|
|
74
|
+
options = {},
|
|
75
|
+
adapter: providedAdapter
|
|
76
|
+
}) {
|
|
77
|
+
const browserAdapterRef = useRef(getBrowserAdapter());
|
|
78
|
+
const adapter = providedAdapter ?? browserAdapterRef.current;
|
|
79
|
+
const onQueryChangeRef = useRef(onQueryChange);
|
|
80
|
+
onQueryChangeRef.current = onQueryChange;
|
|
81
|
+
const skipWriteRef = useRef(true);
|
|
82
|
+
const params = options.params;
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!enabled) return;
|
|
85
|
+
const read = () => {
|
|
86
|
+
const url = adapter.getUrl();
|
|
87
|
+
const decoded = decodeKeepListQuery(url, { params });
|
|
88
|
+
skipWriteRef.current = true;
|
|
89
|
+
onQueryChangeRef.current((previousQuery) => ({
|
|
90
|
+
...previousQuery,
|
|
91
|
+
...decoded.search ? { search: decoded.search } : { search: void 0 },
|
|
92
|
+
...decoded.tags ? { tags: decoded.tags } : { tags: void 0 },
|
|
93
|
+
collectionId: decoded.collectionId,
|
|
94
|
+
sort: decoded.sort,
|
|
95
|
+
pagination: previousQuery.pagination ? { ...previousQuery.pagination, page: decoded.pagination?.page ?? 1 } : decoded.pagination,
|
|
96
|
+
activity: decoded.activity,
|
|
97
|
+
organization: decoded.organization,
|
|
98
|
+
pinnedFirst: decoded.pinnedFirst,
|
|
99
|
+
savedBetween: decoded.savedBetween,
|
|
100
|
+
...decoded.archiveScope !== void 0 ? { archived: decoded.archived, archiveScope: decoded.archiveScope } : decoded.archived !== void 0 ? { archived: decoded.archived, archiveScope: void 0 } : { archived: void 0, archiveScope: void 0 }
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
read();
|
|
104
|
+
return adapter.subscribe?.(read);
|
|
105
|
+
}, [adapter, enabled, params]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!enabled) return;
|
|
108
|
+
if (skipWriteRef.current) {
|
|
109
|
+
skipWriteRef.current = false;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const currentUrl = new URL(adapter.getUrl(), "http://keepkit.invalid");
|
|
113
|
+
const previousUrl = `${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}`;
|
|
114
|
+
const urlParams = { ...DEFAULT_KEEP_URL_PARAMS, ...params };
|
|
115
|
+
for (const key of Object.values(urlParams)) currentUrl.searchParams.delete(key);
|
|
116
|
+
const nextParams = encodeKeepListQuery(query, { params });
|
|
117
|
+
nextParams.forEach((value, key) => {
|
|
118
|
+
currentUrl.searchParams.append(key, value);
|
|
119
|
+
});
|
|
120
|
+
const nextUrl = `${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}`;
|
|
121
|
+
if (nextUrl === previousUrl) return;
|
|
122
|
+
adapter.navigate(nextUrl, options.history ?? "push");
|
|
123
|
+
}, [adapter, enabled, options.history, params, query]);
|
|
124
|
+
}
|
|
125
|
+
function getBrowserAdapter() {
|
|
126
|
+
return {
|
|
127
|
+
getUrl: () => typeof window === "undefined" ? "/" : window.location.href,
|
|
128
|
+
subscribe: (listener) => {
|
|
129
|
+
if (typeof window === "undefined") return () => void 0;
|
|
130
|
+
window.addEventListener("popstate", listener);
|
|
131
|
+
return () => window.removeEventListener("popstate", listener);
|
|
132
|
+
},
|
|
133
|
+
navigate: (url, mode) => {
|
|
134
|
+
if (typeof window === "undefined") return;
|
|
135
|
+
window.history[mode === "push" ? "pushState" : "replaceState"]({}, "", url);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/features/collection/KeepCollection.tsx
|
|
141
|
+
import { KeepErrorBoundary } from "@keepkit/core/react";
|
|
142
|
+
import { useEffect as useEffect4, useId, useRef as useRef3, useState as useState3 } from "react";
|
|
143
|
+
|
|
144
|
+
// src/features/collection/hooks/useKeepCollection.ts
|
|
145
|
+
import { queryKeepItems } from "@keepkit/core/core";
|
|
146
|
+
import { useKeepList } from "@keepkit/core/react";
|
|
147
|
+
import { useCallback, useEffect as useEffect2, useMemo, useState } from "react";
|
|
148
|
+
var DEFAULT_SORT = { by: "updatedAt", direction: "desc" };
|
|
149
|
+
var UNCATEGORIZED = "__uncategorized__";
|
|
150
|
+
function useKeepCollection({
|
|
151
|
+
query,
|
|
152
|
+
pageSize,
|
|
153
|
+
urlSync,
|
|
154
|
+
urlAdapter,
|
|
155
|
+
features,
|
|
156
|
+
archiveScope,
|
|
157
|
+
reorderable
|
|
158
|
+
}) {
|
|
159
|
+
const enabled = {
|
|
160
|
+
search: true,
|
|
161
|
+
sort: true,
|
|
162
|
+
pagination: true,
|
|
163
|
+
tagFilter: false,
|
|
164
|
+
collectionFilter: false,
|
|
165
|
+
bulkActions: false,
|
|
166
|
+
tags: true,
|
|
167
|
+
pin: false,
|
|
168
|
+
archive: false,
|
|
169
|
+
note: false,
|
|
170
|
+
savedViews: false,
|
|
171
|
+
...features
|
|
172
|
+
};
|
|
173
|
+
const [searchValue, setSearchValue] = useState(query.search?.query ?? "");
|
|
174
|
+
const [queryOverride, setQueryOverride] = useState({});
|
|
175
|
+
const defaultSort = reorderable || !enabled.sort ? void 0 : DEFAULT_SORT;
|
|
176
|
+
const [sort, setSort] = useState(query.sort ?? defaultSort);
|
|
177
|
+
const [activeTags, setActiveTags] = useState(query.tags ?? []);
|
|
178
|
+
const [activeCollection, setActiveCollection] = useState(getCollectionValue(query));
|
|
179
|
+
const [activeActivity, setActiveActivity] = useState(query.activity);
|
|
180
|
+
const [activeOrganization, setActiveOrganization] = useState(query.organization);
|
|
181
|
+
const [activeSavedBetween, setActiveSavedBetween] = useState(query.savedBetween);
|
|
182
|
+
const [page, setPage] = useState(query.pagination?.page ?? 1);
|
|
183
|
+
const initialArchiveScope = archiveScope ?? query.archiveScope ?? scopeFromArchived(query.archived);
|
|
184
|
+
const [activeArchiveScope, setActiveArchiveScope] = useState(initialArchiveScope);
|
|
185
|
+
const applyQuery = useCallback(
|
|
186
|
+
(next) => {
|
|
187
|
+
setQueryOverride(next);
|
|
188
|
+
setSearchValue(next.search?.query ?? "");
|
|
189
|
+
setSort(next.sort ?? defaultSort);
|
|
190
|
+
setActiveTags(next.tags ?? []);
|
|
191
|
+
setActiveCollection(getCollectionValue(next));
|
|
192
|
+
setActiveActivity(next.activity);
|
|
193
|
+
setActiveOrganization(next.organization);
|
|
194
|
+
setActiveSavedBetween(next.savedBetween);
|
|
195
|
+
setActiveArchiveScope(next.archiveScope ?? scopeFromArchived(next.archived));
|
|
196
|
+
setPage(next.pagination?.page ?? 1);
|
|
197
|
+
},
|
|
198
|
+
[defaultSort]
|
|
199
|
+
);
|
|
200
|
+
useEffect2(() => {
|
|
201
|
+
if (archiveScope !== void 0) setActiveArchiveScope(archiveScope);
|
|
202
|
+
}, [archiveScope]);
|
|
203
|
+
const defaultPageSize = Number.isFinite(pageSize) ? Math.max(1, Math.floor(pageSize)) : 20;
|
|
204
|
+
const requestedPageSize = queryOverride.pagination?.pageSize ?? query.pagination?.pageSize ?? defaultPageSize;
|
|
205
|
+
const resolvedPageSize = Number.isFinite(requestedPageSize) ? Math.max(1, Math.floor(requestedPageSize)) : defaultPageSize;
|
|
206
|
+
const resolvedQuery = useMemo(
|
|
207
|
+
() => ({
|
|
208
|
+
...query,
|
|
209
|
+
...queryOverride,
|
|
210
|
+
targetType: query.targetType ?? queryOverride.targetType,
|
|
211
|
+
activity: activeActivity,
|
|
212
|
+
organization: activeOrganization,
|
|
213
|
+
savedBetween: activeSavedBetween,
|
|
214
|
+
archiveScope: activeArchiveScope,
|
|
215
|
+
archived: activeArchiveScope === "active" ? false : activeArchiveScope === "archived" ? true : void 0,
|
|
216
|
+
search: { ...query.search, ...queryOverride.search, query: searchValue },
|
|
217
|
+
sort,
|
|
218
|
+
tags: activeTags.length > 0 ? activeTags : void 0,
|
|
219
|
+
collectionId: activeCollection && activeCollection !== UNCATEGORIZED ? activeCollection : void 0,
|
|
220
|
+
filter: query.filter,
|
|
221
|
+
pagination: enabled.pagination || query.pagination || queryOverride.pagination ? { ...query.pagination, ...queryOverride.pagination, page, pageSize: resolvedPageSize } : void 0
|
|
222
|
+
}),
|
|
223
|
+
[
|
|
224
|
+
activeCollection,
|
|
225
|
+
activeActivity,
|
|
226
|
+
activeOrganization,
|
|
227
|
+
activeSavedBetween,
|
|
228
|
+
activeTags,
|
|
229
|
+
enabled.pagination,
|
|
230
|
+
page,
|
|
231
|
+
query,
|
|
232
|
+
queryOverride,
|
|
233
|
+
resolvedPageSize,
|
|
234
|
+
searchValue,
|
|
235
|
+
sort,
|
|
236
|
+
activeArchiveScope
|
|
237
|
+
]
|
|
238
|
+
);
|
|
239
|
+
useKeepUrlSync({
|
|
240
|
+
enabled: Boolean(urlSync),
|
|
241
|
+
query: resolvedQuery,
|
|
242
|
+
onQueryChange: (nextOrUpdater) => {
|
|
243
|
+
const next = typeof nextOrUpdater === "function" ? nextOrUpdater(resolvedQuery) : nextOrUpdater;
|
|
244
|
+
applyQuery(next);
|
|
245
|
+
},
|
|
246
|
+
options: typeof urlSync === "object" ? urlSync : {},
|
|
247
|
+
adapter: urlAdapter
|
|
248
|
+
});
|
|
249
|
+
const list = useKeepList(resolvedQuery);
|
|
250
|
+
const allState = useKeepList({ archiveScope: "all" });
|
|
251
|
+
const reveal = useCallback(
|
|
252
|
+
(itemId) => {
|
|
253
|
+
const target = allState.items.find((item) => item.id === itemId);
|
|
254
|
+
if (!target) return "not-found";
|
|
255
|
+
const nextQuery = {
|
|
256
|
+
...resolvedQuery,
|
|
257
|
+
targetType: query.targetType,
|
|
258
|
+
filter: query.filter,
|
|
259
|
+
search: { ...resolvedQuery.search, query: "" },
|
|
260
|
+
tags: void 0,
|
|
261
|
+
collectionId: void 0,
|
|
262
|
+
activity: void 0,
|
|
263
|
+
organization: void 0,
|
|
264
|
+
savedBetween: void 0,
|
|
265
|
+
archiveScope: target.archived === true ? "archived" : "active",
|
|
266
|
+
archived: target.archived === true
|
|
267
|
+
};
|
|
268
|
+
const candidates = queryKeepItems(allState.items, { ...nextQuery, pagination: void 0 }).items;
|
|
269
|
+
const index = candidates.findIndex((item) => item.id === itemId);
|
|
270
|
+
if (index < 0) return "excluded";
|
|
271
|
+
const pageSize2 = nextQuery.pagination ? Math.max(1, resolvedPageSize) : Math.max(1, candidates.length);
|
|
272
|
+
const nextPage = Math.floor(index / pageSize2) + 1;
|
|
273
|
+
applyQuery({
|
|
274
|
+
...nextQuery,
|
|
275
|
+
...nextQuery.pagination ? { pagination: { ...nextQuery.pagination, page: nextPage } } : {}
|
|
276
|
+
});
|
|
277
|
+
return "visible";
|
|
278
|
+
},
|
|
279
|
+
[allState.items, applyQuery, query, resolvedPageSize, resolvedQuery]
|
|
280
|
+
);
|
|
281
|
+
return {
|
|
282
|
+
enabled,
|
|
283
|
+
searchValue,
|
|
284
|
+
sortValue: sort === void 0 ? "manual" : sortToValue(sort),
|
|
285
|
+
activeTags,
|
|
286
|
+
activeCollection,
|
|
287
|
+
activity: activeActivity,
|
|
288
|
+
archiveScope: activeArchiveScope,
|
|
289
|
+
resolvedPageSize,
|
|
290
|
+
resolvedQuery,
|
|
291
|
+
list,
|
|
292
|
+
allState,
|
|
293
|
+
setSearchValue: (value) => {
|
|
294
|
+
setSearchValue(value);
|
|
295
|
+
setPage(1);
|
|
296
|
+
},
|
|
297
|
+
setSortValue: (_value, nextSort) => {
|
|
298
|
+
setSort(nextSort);
|
|
299
|
+
setPage(1);
|
|
300
|
+
},
|
|
301
|
+
setManualSort: () => {
|
|
302
|
+
setSort(void 0);
|
|
303
|
+
setPage(1);
|
|
304
|
+
},
|
|
305
|
+
setTag: (value) => {
|
|
306
|
+
setActiveTags(value ? [value] : []);
|
|
307
|
+
setPage(1);
|
|
308
|
+
},
|
|
309
|
+
setTags: (values) => {
|
|
310
|
+
setActiveTags(values);
|
|
311
|
+
setPage(1);
|
|
312
|
+
},
|
|
313
|
+
toggleTag: (tag) => {
|
|
314
|
+
setActiveTags(
|
|
315
|
+
(current) => current.includes(tag) ? current.filter((entry) => entry !== tag) : [...current, tag]
|
|
316
|
+
);
|
|
317
|
+
setPage(1);
|
|
318
|
+
},
|
|
319
|
+
setCollection: (value) => {
|
|
320
|
+
setActiveCollection(value);
|
|
321
|
+
setActiveOrganization((current) => {
|
|
322
|
+
if (value === UNCATEGORIZED) return { ...current, collection: "unassigned" };
|
|
323
|
+
if (current?.collection !== "unassigned") return current;
|
|
324
|
+
const { collection: _collection, ...organization } = current;
|
|
325
|
+
return organization.tags || organization.note ? organization : void 0;
|
|
326
|
+
});
|
|
327
|
+
setPage(1);
|
|
328
|
+
},
|
|
329
|
+
setActivity: (value) => {
|
|
330
|
+
setActiveActivity(value);
|
|
331
|
+
setPage(1);
|
|
332
|
+
},
|
|
333
|
+
setOrganization: (value) => {
|
|
334
|
+
setActiveOrganization(value);
|
|
335
|
+
setActiveCollection((current) => {
|
|
336
|
+
if (value?.collection === "unassigned") return UNCATEGORIZED;
|
|
337
|
+
return current === UNCATEGORIZED ? void 0 : current;
|
|
338
|
+
});
|
|
339
|
+
setPage(1);
|
|
340
|
+
},
|
|
341
|
+
setSavedBetween: (value) => {
|
|
342
|
+
setActiveSavedBetween(value);
|
|
343
|
+
setPage(1);
|
|
344
|
+
},
|
|
345
|
+
applyQuery,
|
|
346
|
+
setArchiveScope: (value) => {
|
|
347
|
+
setActiveArchiveScope(value);
|
|
348
|
+
setPage(1);
|
|
349
|
+
},
|
|
350
|
+
removeTag: (tagToRemove) => {
|
|
351
|
+
setActiveTags((current) => current.filter((tag) => tag !== tagToRemove));
|
|
352
|
+
setPage(1);
|
|
353
|
+
},
|
|
354
|
+
clearFilters: (preserveArchiveScope = false) => {
|
|
355
|
+
setQueryOverride({});
|
|
356
|
+
setSearchValue("");
|
|
357
|
+
setActiveTags([]);
|
|
358
|
+
setActiveCollection(void 0);
|
|
359
|
+
setActiveActivity(void 0);
|
|
360
|
+
setActiveOrganization(void 0);
|
|
361
|
+
setActiveSavedBetween(void 0);
|
|
362
|
+
if (!preserveArchiveScope) setActiveArchiveScope("active");
|
|
363
|
+
setPage(1);
|
|
364
|
+
},
|
|
365
|
+
resetFilters: () => applyQuery({ ...query, archiveScope: initialArchiveScope }),
|
|
366
|
+
canReset: hasInitialFilterState(query, initialArchiveScope, reorderable),
|
|
367
|
+
setPage,
|
|
368
|
+
reveal
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function hasInitialFilterState(query, archiveScope, reorderable) {
|
|
372
|
+
return Boolean(
|
|
373
|
+
query.search?.query?.trim() || query.tags?.length || query.collectionId || query.activity || query.organization || query.pinnedFirst || query.savedBetween || archiveScope !== "active" || query.pagination?.page !== void 0 && query.pagination.page !== 1 || query.sort && (reorderable || query.sort.by !== "updatedAt" || query.sort.direction !== "desc")
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
function getCollectionValue(query) {
|
|
377
|
+
return query.collectionId ?? (query.organization?.collection === "unassigned" ? UNCATEGORIZED : void 0);
|
|
378
|
+
}
|
|
379
|
+
function scopeFromArchived(archived) {
|
|
380
|
+
return archived === true ? "archived" : "active";
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/features/collection/KeepInlineSelection.tsx
|
|
384
|
+
import { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
|
|
385
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
386
|
+
function KeepInlineSelection({
|
|
387
|
+
query,
|
|
388
|
+
children,
|
|
389
|
+
confirmRemoval = false
|
|
390
|
+
}) {
|
|
391
|
+
const [selecting, setSelecting] = useState2(false);
|
|
392
|
+
const [selectedIds, setSelectedIds] = useState2([]);
|
|
393
|
+
const previousQuery = useRef2(copyQueryValue(query));
|
|
394
|
+
useEffect3(() => {
|
|
395
|
+
if (equalQueryValue(previousQuery.current, query)) return;
|
|
396
|
+
previousQuery.current = copyQueryValue(query);
|
|
397
|
+
setSelectedIds([]);
|
|
398
|
+
}, [query]);
|
|
399
|
+
const { state } = useKeepBulkActions({
|
|
400
|
+
query,
|
|
401
|
+
controlledSelectedIds: selectedIds,
|
|
402
|
+
defaultSelectedIds: [],
|
|
403
|
+
onSelectedIdsChange: setSelectedIds,
|
|
404
|
+
onCompleted: void 0,
|
|
405
|
+
controlledScope: "page",
|
|
406
|
+
onSelectionScopeChange: void 0,
|
|
407
|
+
confirmRemoval
|
|
408
|
+
});
|
|
409
|
+
const removalTrigger = useRef2(null);
|
|
410
|
+
const selectLabel = useUiLabel("selectItems");
|
|
411
|
+
const doneLabel = useUiLabel("done");
|
|
412
|
+
const pageLabel = useUiLabel("currentPage");
|
|
413
|
+
const countLabel = useUiLabel("selectedCount");
|
|
414
|
+
const collectionLabel = useUiLabel("collection");
|
|
415
|
+
const uncategorizedLabel = useUiLabel("uncategorized");
|
|
416
|
+
const moveLabel = useUiLabel("moveSelected");
|
|
417
|
+
const archiveLabel = useUiLabel("archive");
|
|
418
|
+
const unarchiveLabel = useUiLabel("unarchive");
|
|
419
|
+
const pinLabel = useUiLabel("pin");
|
|
420
|
+
const unpinLabel = useUiLabel("unpin");
|
|
421
|
+
const tagsLabel = useUiLabel("tagsToApply");
|
|
422
|
+
const applyTagsLabel = useUiLabel("applyTags");
|
|
423
|
+
const addTagsLabel = useUiLabel("addTags");
|
|
424
|
+
const removeTagsLabel = useUiLabel("removeTags");
|
|
425
|
+
const removeLabel = useUiLabel("deleteSelected");
|
|
426
|
+
const showRemoveLabel = useUiLabelVisibility("deleteSelected");
|
|
427
|
+
const removeIcon = useKeepIcon("remove");
|
|
428
|
+
const moreLabel = useUiLabel("moreActions");
|
|
429
|
+
const errorLabel = useUiLabel("error");
|
|
430
|
+
const run = (operation) => void operation().catch(() => void 0);
|
|
431
|
+
const archivedOnly = query.archiveScope === "archived" || query.archived === true;
|
|
432
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
433
|
+
/* @__PURE__ */ jsxs("fieldset", { "data-keepkit": "inline-selection", "aria-label": selectLabel, "aria-busy": state.isMutating, children: [
|
|
434
|
+
/* @__PURE__ */ jsx(
|
|
435
|
+
"button",
|
|
436
|
+
{
|
|
437
|
+
type: "button",
|
|
438
|
+
"aria-pressed": selecting,
|
|
439
|
+
disabled: state.isMutating || !selecting && state.items.length === 0,
|
|
440
|
+
onClick: () => {
|
|
441
|
+
setSelecting(!selecting);
|
|
442
|
+
setSelectedIds([]);
|
|
443
|
+
},
|
|
444
|
+
children: selecting ? doneLabel : selectLabel
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
selecting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
448
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
449
|
+
/* @__PURE__ */ jsx(
|
|
450
|
+
"input",
|
|
451
|
+
{
|
|
452
|
+
type: "checkbox",
|
|
453
|
+
checked: state.allSelected,
|
|
454
|
+
onChange: state.toggleAll,
|
|
455
|
+
disabled: state.isMutating || !state.items.length
|
|
456
|
+
}
|
|
457
|
+
),
|
|
458
|
+
selectLabel,
|
|
459
|
+
" \u2014 ",
|
|
460
|
+
pageLabel
|
|
461
|
+
] }),
|
|
462
|
+
/* @__PURE__ */ jsxs("span", { role: "status", children: [
|
|
463
|
+
state.selectedCount,
|
|
464
|
+
" ",
|
|
465
|
+
countLabel
|
|
466
|
+
] })
|
|
467
|
+
] }) : null,
|
|
468
|
+
selecting && state.selectedCount > 0 ? /* @__PURE__ */ jsxs("fieldset", { disabled: state.isMutating, children: [
|
|
469
|
+
/* @__PURE__ */ jsxs("legend", { children: [
|
|
470
|
+
state.selectedCount,
|
|
471
|
+
" ",
|
|
472
|
+
countLabel
|
|
473
|
+
] }),
|
|
474
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
475
|
+
collectionLabel,
|
|
476
|
+
/* @__PURE__ */ jsxs("select", { value: state.collectionId, onChange: (event) => state.setCollectionId(event.currentTarget.value), children: [
|
|
477
|
+
/* @__PURE__ */ jsx("option", { value: "", children: uncategorizedLabel }),
|
|
478
|
+
state.collections.map((collection) => /* @__PURE__ */ jsx("option", { value: collection.id, children: collection.name }, collection.id))
|
|
479
|
+
] })
|
|
480
|
+
] }),
|
|
481
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.moveToCollection), children: moveLabel }),
|
|
482
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(archivedOnly ? state.unarchive : state.archive), children: archivedOnly ? unarchiveLabel : archiveLabel }),
|
|
483
|
+
/* @__PURE__ */ jsxs("details", { children: [
|
|
484
|
+
/* @__PURE__ */ jsx("summary", { children: moreLabel }),
|
|
485
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
486
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
487
|
+
tagsLabel,
|
|
488
|
+
/* @__PURE__ */ jsx("input", { value: state.tagsInput, onChange: (event) => state.setTagsInput(event.currentTarget.value) })
|
|
489
|
+
] }),
|
|
490
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.addTags), children: addTagsLabel }),
|
|
491
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.removeTags), children: removeTagsLabel }),
|
|
492
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.updateTags), children: applyTagsLabel }),
|
|
493
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.pin), children: pinLabel }),
|
|
494
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run(state.unpin), children: unpinLabel }),
|
|
495
|
+
/* @__PURE__ */ jsxs(
|
|
496
|
+
"button",
|
|
497
|
+
{
|
|
498
|
+
ref: removalTrigger,
|
|
499
|
+
type: "button",
|
|
500
|
+
"aria-label": showRemoveLabel ? void 0 : removeLabel,
|
|
501
|
+
onClick: () => run(state.remove),
|
|
502
|
+
children: [
|
|
503
|
+
removeIcon,
|
|
504
|
+
showRemoveLabel ? removeLabel : null
|
|
505
|
+
]
|
|
506
|
+
}
|
|
507
|
+
)
|
|
508
|
+
] })
|
|
509
|
+
] })
|
|
510
|
+
] }) : null,
|
|
511
|
+
/* @__PURE__ */ jsx(KeepRemovalConfirmation, { state, triggerRef: removalTrigger }),
|
|
512
|
+
selecting && state.error ? /* @__PURE__ */ jsx("p", { role: "alert", children: getErrorMessage(state.error, errorLabel) }) : null
|
|
513
|
+
] }),
|
|
514
|
+
children(
|
|
515
|
+
selecting ? { selectedIds, onSelectedIdsChange: setSelectedIds, disabled: state.isMutating } : void 0
|
|
516
|
+
)
|
|
517
|
+
] });
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/features/collection/KeepCollection.tsx
|
|
521
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
522
|
+
var EMPTY_QUERY = {};
|
|
523
|
+
function KeepCollection(props) {
|
|
524
|
+
const { fallback, onBoundaryError, boundaryResetKey, ...collectionProps } = props;
|
|
525
|
+
const content = /* @__PURE__ */ jsx2(KeepCollectionContent, { ...collectionProps });
|
|
526
|
+
if (fallback === void 0 && onBoundaryError === void 0) return content;
|
|
527
|
+
return /* @__PURE__ */ jsx2(KeepErrorBoundary, { fallback, onError: onBoundaryError, resetKey: boundaryResetKey, children: content });
|
|
528
|
+
}
|
|
529
|
+
function KeepCollectionContent({
|
|
530
|
+
query = EMPTY_QUERY,
|
|
531
|
+
pageSize = 20,
|
|
532
|
+
layout = "list",
|
|
533
|
+
toolbarVariant = "plain",
|
|
534
|
+
toolbarLayout = "flat",
|
|
535
|
+
collapsibleFilters = false,
|
|
536
|
+
urlSync = false,
|
|
537
|
+
urlAdapter,
|
|
538
|
+
archiveScope,
|
|
539
|
+
onArchiveScopeChange,
|
|
540
|
+
reorderable = false,
|
|
541
|
+
onReorder,
|
|
542
|
+
features,
|
|
543
|
+
bulkActionsVariant = "separate",
|
|
544
|
+
confirmRemoval = false,
|
|
545
|
+
slots,
|
|
546
|
+
collectionLabels,
|
|
547
|
+
creatable = false,
|
|
548
|
+
renderItem,
|
|
549
|
+
itemCardProps,
|
|
550
|
+
loading,
|
|
551
|
+
renderLoading,
|
|
552
|
+
loadingCount,
|
|
553
|
+
activeFilters,
|
|
554
|
+
empty,
|
|
555
|
+
error,
|
|
556
|
+
revealRequest,
|
|
557
|
+
onRevealResult,
|
|
558
|
+
className,
|
|
559
|
+
...rootProps
|
|
560
|
+
}) {
|
|
561
|
+
const view = useKeepCollection({ query, pageSize, urlSync, urlAdapter, features, archiveScope, reorderable });
|
|
562
|
+
const revealRequestId = useRef3(void 0);
|
|
563
|
+
useEffect4(() => {
|
|
564
|
+
if (!view.list.isHydrated || !revealRequest || revealRequestId.current === revealRequest.requestId) return;
|
|
565
|
+
revealRequestId.current = revealRequest.requestId;
|
|
566
|
+
const status = view.reveal(revealRequest.itemId);
|
|
567
|
+
onRevealResult?.({ ...revealRequest, status });
|
|
568
|
+
}, [onRevealResult, revealRequest, view.list.isHydrated, view.reveal]);
|
|
569
|
+
const [reorderUndoIds, setReorderUndoIds] = useState3(null);
|
|
570
|
+
const [reorderError, setReorderError] = useState3(false);
|
|
571
|
+
const reorderUndoLabel = useUiLabel("undoReorder");
|
|
572
|
+
const reorderFailedLabel = useUiLabel("reorderFailed");
|
|
573
|
+
const handleReorder = async (orderedIds) => {
|
|
574
|
+
const previousIds = view.list.items.map((item) => item.id);
|
|
575
|
+
const itemsById = new Map(view.list.items.map((item) => [item.id, item]));
|
|
576
|
+
const orderedItems = orderedIds.flatMap((id) => {
|
|
577
|
+
const item = itemsById.get(id);
|
|
578
|
+
return item ? [item] : [];
|
|
579
|
+
});
|
|
580
|
+
setReorderError(false);
|
|
581
|
+
setReorderUndoIds(previousIds);
|
|
582
|
+
await onReorder?.(orderedItems);
|
|
583
|
+
};
|
|
584
|
+
useEffect4(() => {
|
|
585
|
+
if (!reorderUndoIds) return;
|
|
586
|
+
const timer = window.setTimeout(() => setReorderUndoIds(null), 5e3);
|
|
587
|
+
return () => window.clearTimeout(timer);
|
|
588
|
+
}, [reorderUndoIds]);
|
|
589
|
+
const undoReorder = async () => {
|
|
590
|
+
if (!reorderUndoIds) return;
|
|
591
|
+
const previous = reorderUndoIds;
|
|
592
|
+
const existingIds = new Set(view.allState.items.map((item) => item.id));
|
|
593
|
+
const remainingIds = previous.filter((id) => existingIds.has(id));
|
|
594
|
+
setReorderError(false);
|
|
595
|
+
try {
|
|
596
|
+
await view.list.reorder(reorderVisibleItems(view.allState.items, remainingIds));
|
|
597
|
+
setReorderUndoIds(null);
|
|
598
|
+
} catch {
|
|
599
|
+
setReorderError(true);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const resolvedItemCardProps = {
|
|
603
|
+
...itemCardProps,
|
|
604
|
+
collectionLabels: itemCardProps?.collectionLabels ?? collectionLabels,
|
|
605
|
+
showTags: itemCardProps?.showTags ?? view.enabled.tags,
|
|
606
|
+
onTagClick: itemCardProps?.onTagClick ?? (view.enabled.tagFilter ? (tag) => view.toggleTag(tag) : void 0),
|
|
607
|
+
showPinButton: itemCardProps?.showPinButton ?? view.enabled.pin,
|
|
608
|
+
showArchiveButton: itemCardProps?.showArchiveButton ?? view.enabled.archive,
|
|
609
|
+
showEditButton: itemCardProps?.showEditButton ?? features?.note ?? (itemCardProps?.presentation === "reading" || view.enabled.note),
|
|
610
|
+
showNote: itemCardProps?.showNote ?? features?.note ?? (itemCardProps?.presentation === "reading" || view.enabled.note)
|
|
611
|
+
};
|
|
612
|
+
const toolbarId = useId();
|
|
613
|
+
const [filtersOpen, setFiltersOpen] = useState3(false);
|
|
614
|
+
const structuredToolbar = collapsibleFilters || toolbarLayout === "grouped" || toolbarVariant === "panel" || creatable || slots?.toolbarStart !== void 0 || slots?.toolbarEnd !== void 0;
|
|
615
|
+
const hasQueryControls = view.enabled.search || view.enabled.sort;
|
|
616
|
+
const hasFilterControls = view.enabled.tagFilter || view.enabled.collectionFilter || archiveScope !== void 0;
|
|
617
|
+
const queryControls = hasQueryControls ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
618
|
+
view.enabled.search ? /* @__PURE__ */ jsx2(KeepSearchInput, { value: view.searchValue, onValueChange: view.setSearchValue }) : null,
|
|
619
|
+
view.enabled.sort ? /* @__PURE__ */ jsx2(
|
|
620
|
+
KeepSortSelect,
|
|
621
|
+
{
|
|
622
|
+
value: view.sortValue,
|
|
623
|
+
onValueChange: view.setSortValue,
|
|
624
|
+
onManualSort: reorderable ? view.setManualSort : void 0
|
|
625
|
+
}
|
|
626
|
+
) : null
|
|
627
|
+
] }) : null;
|
|
628
|
+
const filterControls = hasFilterControls ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
629
|
+
view.enabled.tagFilter ? /* @__PURE__ */ jsx2(KeepTagFilter, { query, values: view.activeTags, onValuesChange: view.setTags }) : null,
|
|
630
|
+
view.enabled.collectionFilter ? /* @__PURE__ */ jsx2(
|
|
631
|
+
KeepCollectionFilter,
|
|
632
|
+
{
|
|
633
|
+
value: view.activeCollection ?? "",
|
|
634
|
+
onValueChange: view.setCollection,
|
|
635
|
+
collectionLabels
|
|
636
|
+
}
|
|
637
|
+
) : null,
|
|
638
|
+
archiveScope !== void 0 ? /* @__PURE__ */ jsx2(
|
|
639
|
+
KeepArchiveScopeSelect,
|
|
640
|
+
{
|
|
641
|
+
value: view.archiveScope,
|
|
642
|
+
onValueChange: (next) => {
|
|
643
|
+
view.setArchiveScope(next);
|
|
644
|
+
onArchiveScopeChange?.(next);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
) : null
|
|
648
|
+
] }) : null;
|
|
649
|
+
const toolbarStartLabel = useUiLabel("toolbarStart");
|
|
650
|
+
const toolbarQueryLabel = useUiLabel("toolbarQuery");
|
|
651
|
+
const toolbarFiltersLabel = useUiLabel("toolbarFilters");
|
|
652
|
+
const toolbarEndLabel = useUiLabel("toolbarEnd");
|
|
653
|
+
const uncategorizedLabel = useUiLabel("uncategorized");
|
|
654
|
+
const activeCollectionLabel = view.activeCollection === "__uncategorized__" ? uncategorizedLabel : view.activeCollection === void 0 ? void 0 : collectionLabels?.[view.activeCollection] ?? view.activeCollection;
|
|
655
|
+
const toolbarStartContent = slots?.toolbarStart === void 0 ? null : resolveContent(slots.toolbarStart, view.list);
|
|
656
|
+
const creatableContent = creatable ? /* @__PURE__ */ jsx2(KeepCollectionCreate, {}) : null;
|
|
657
|
+
const toolbarEndContent = /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
658
|
+
creatableContent,
|
|
659
|
+
slots?.toolbarEnd === void 0 ? null : resolveContent(slots.toolbarEnd, view.list)
|
|
660
|
+
] });
|
|
661
|
+
const hasToolbarContent = hasQueryControls || hasFilterControls || hasRenderableContent(toolbarStartContent) || hasRenderableContent(toolbarEndContent);
|
|
662
|
+
const renderToolbarGroup = (group, content, label) => {
|
|
663
|
+
if (!hasRenderableContent(content)) return null;
|
|
664
|
+
const labelId = `${toolbarId}-${group}`;
|
|
665
|
+
return /* @__PURE__ */ jsxs2(
|
|
666
|
+
"fieldset",
|
|
667
|
+
{
|
|
668
|
+
"data-keepkit": "collection-toolbar-group",
|
|
669
|
+
"data-group": group,
|
|
670
|
+
role: "group",
|
|
671
|
+
"aria-labelledby": labelId,
|
|
672
|
+
children: [
|
|
673
|
+
/* @__PURE__ */ jsx2("legend", { id: labelId, "data-keepkit": "collection-toolbar-label", children: label }),
|
|
674
|
+
/* @__PURE__ */ jsx2("div", { "data-keepkit": "collection-toolbar-content", children: content })
|
|
675
|
+
]
|
|
676
|
+
}
|
|
677
|
+
);
|
|
678
|
+
};
|
|
679
|
+
const toolbar = !structuredToolbar ? /* @__PURE__ */ jsxs2("div", { children: [
|
|
680
|
+
queryControls,
|
|
681
|
+
filterControls
|
|
682
|
+
] }) : !hasToolbarContent ? null : /* @__PURE__ */ jsxs2("div", { "data-keepkit": "collection-toolbar", "data-variant": toolbarVariant, "data-layout": toolbarLayout, children: [
|
|
683
|
+
renderToolbarGroup("toolbarStart", toolbarStartContent, toolbarStartLabel),
|
|
684
|
+
renderToolbarGroup("query", queryControls, toolbarQueryLabel),
|
|
685
|
+
hasFilterControls && collapsibleFilters ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
686
|
+
/* @__PURE__ */ jsx2(
|
|
687
|
+
"button",
|
|
688
|
+
{
|
|
689
|
+
type: "button",
|
|
690
|
+
"aria-expanded": filtersOpen,
|
|
691
|
+
"aria-controls": `${toolbarId}-filter-controls`,
|
|
692
|
+
onClick: () => setFiltersOpen(!filtersOpen),
|
|
693
|
+
children: toolbarFiltersLabel
|
|
694
|
+
}
|
|
695
|
+
),
|
|
696
|
+
/* @__PURE__ */ jsx2("div", { id: `${toolbarId}-filter-controls`, hidden: !filtersOpen, children: renderToolbarGroup("filters", filterControls, toolbarFiltersLabel) })
|
|
697
|
+
] }) : renderToolbarGroup("filters", filterControls, toolbarFiltersLabel),
|
|
698
|
+
renderToolbarGroup("toolbarEnd", toolbarEndContent, toolbarEndLabel)
|
|
699
|
+
] });
|
|
700
|
+
const renderList = (selection) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
701
|
+
/* @__PURE__ */ jsx2(
|
|
702
|
+
KeepList,
|
|
703
|
+
{
|
|
704
|
+
query: view.resolvedQuery,
|
|
705
|
+
selection,
|
|
706
|
+
renderItem,
|
|
707
|
+
itemCardProps: resolvedItemCardProps,
|
|
708
|
+
layout,
|
|
709
|
+
loading,
|
|
710
|
+
renderLoading,
|
|
711
|
+
loadingCount,
|
|
712
|
+
onClearFilters: () => view.clearFilters(true),
|
|
713
|
+
reorderable,
|
|
714
|
+
onReorder: reorderable ? handleReorder : void 0,
|
|
715
|
+
empty: view.list.totalCount === 0 && view.allState.totalCount > 0 ? void 0 : empty,
|
|
716
|
+
error
|
|
717
|
+
}
|
|
718
|
+
),
|
|
719
|
+
view.enabled.pagination ? /* @__PURE__ */ jsx2(
|
|
720
|
+
KeepPagination,
|
|
721
|
+
{
|
|
722
|
+
totalCount: view.list.totalCount,
|
|
723
|
+
pageSize: view.resolvedPageSize,
|
|
724
|
+
page: view.list.page,
|
|
725
|
+
onPageChange: view.setPage
|
|
726
|
+
}
|
|
727
|
+
) : null
|
|
728
|
+
] });
|
|
729
|
+
return /* @__PURE__ */ jsxs2(
|
|
730
|
+
"section",
|
|
731
|
+
{
|
|
732
|
+
...rootProps,
|
|
733
|
+
className,
|
|
734
|
+
"data-keepkit": "collection",
|
|
735
|
+
"data-layout": layout,
|
|
736
|
+
"data-toolbar-variant": toolbarVariant !== "plain" ? toolbarVariant : void 0,
|
|
737
|
+
"data-toolbar-layout": toolbarLayout !== "flat" ? toolbarLayout : void 0,
|
|
738
|
+
"aria-busy": view.list.isLoading || view.list.isMutating || rootProps["aria-busy"],
|
|
739
|
+
"data-state": getCollectionState(view.list),
|
|
740
|
+
"data-loading": view.list.isLoading || view.list.isMutating ? "true" : void 0,
|
|
741
|
+
children: [
|
|
742
|
+
toolbar,
|
|
743
|
+
view.enabled.savedViews ? /* @__PURE__ */ jsxs2("div", { "data-keepkit": "saved-view-controls", children: [
|
|
744
|
+
/* @__PURE__ */ jsx2(KeepSavedViews, { onApply: view.applyQuery }),
|
|
745
|
+
/* @__PURE__ */ jsx2(KeepSaveViewButton, { query: view.resolvedQuery })
|
|
746
|
+
] }) : null,
|
|
747
|
+
activeFilters === void 0 ? /* @__PURE__ */ jsx2(
|
|
748
|
+
KeepActiveFiltersSummary,
|
|
749
|
+
{
|
|
750
|
+
search: view.searchValue,
|
|
751
|
+
tags: view.activeTags,
|
|
752
|
+
collection: view.activeCollection,
|
|
753
|
+
collectionLabel: activeCollectionLabel,
|
|
754
|
+
organization: view.activeCollection === "__uncategorized__" ? { ...view.resolvedQuery.organization, collection: void 0 } : view.resolvedQuery.organization,
|
|
755
|
+
savedBetween: view.resolvedQuery.savedBetween,
|
|
756
|
+
activity: view.activity,
|
|
757
|
+
archiveScope: view.archiveScope,
|
|
758
|
+
totalCount: view.list.totalCount,
|
|
759
|
+
onSearchChange: view.setSearchValue,
|
|
760
|
+
onTagChange: view.removeTag,
|
|
761
|
+
onCollectionChange: view.setCollection,
|
|
762
|
+
onOrganizationChange: view.setOrganization,
|
|
763
|
+
onSavedBetweenChange: view.setSavedBetween,
|
|
764
|
+
onActivityChange: view.setActivity,
|
|
765
|
+
onArchiveScopeChange: (next) => {
|
|
766
|
+
view.setArchiveScope(next);
|
|
767
|
+
onArchiveScopeChange?.(next);
|
|
768
|
+
},
|
|
769
|
+
onClear: () => view.clearFilters(),
|
|
770
|
+
onReset: view.resetFilters,
|
|
771
|
+
canReset: view.canReset
|
|
772
|
+
}
|
|
773
|
+
) : resolveContent(activeFilters, view.list),
|
|
774
|
+
view.enabled.bulkActions && bulkActionsVariant === "inline" ? /* @__PURE__ */ jsx2(KeepInlineSelection, { query: view.resolvedQuery, confirmRemoval, children: renderList }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
775
|
+
renderList(),
|
|
776
|
+
view.enabled.bulkActions ? /* @__PURE__ */ jsx2(KeepBulkActions, { query: view.resolvedQuery, confirmRemoval }) : null
|
|
777
|
+
] }),
|
|
778
|
+
reorderable && reorderUndoIds ? /* @__PURE__ */ jsxs2("div", { "data-keepkit": "reorder-feedback", role: "status", "aria-live": "polite", children: [
|
|
779
|
+
reorderError ? /* @__PURE__ */ jsx2("p", { role: "alert", children: reorderFailedLabel }) : null,
|
|
780
|
+
/* @__PURE__ */ jsx2("button", { type: "button", "data-keep-action": "undo-reorder", onClick: () => void undoReorder(), children: reorderUndoLabel })
|
|
781
|
+
] }) : null
|
|
782
|
+
]
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
function getCollectionState(list) {
|
|
787
|
+
if (list.error && list.items.length === 0) return "error";
|
|
788
|
+
if (list.isLoading && !list.isHydrated) return "loading";
|
|
789
|
+
if (list.isHydrated && list.items.length === 0) return "empty";
|
|
790
|
+
return "ready";
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export {
|
|
794
|
+
createNextPagesRouterAdapter,
|
|
795
|
+
useKeepUrlSync,
|
|
796
|
+
KeepCollection
|
|
797
|
+
};
|
|
798
|
+
//# sourceMappingURL=chunk-PE57SLZO.js.map
|