@keepkit/core 0.1.0 → 0.3.0
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 +16 -2
- package/dist/chunk-5QSZP6MT.js +1 -0
- package/dist/chunk-5QSZP6MT.js.map +1 -0
- package/dist/chunk-J7NKIOXV.js +142 -0
- package/dist/chunk-J7NKIOXV.js.map +1 -0
- package/dist/chunk-THZ3ACR2.js +41 -0
- package/dist/chunk-THZ3ACR2.js.map +1 -0
- package/dist/{chunk-H4A322SZ.js → chunk-X4UVKTBK.js} +215 -15
- package/dist/chunk-X4UVKTBK.js.map +1 -0
- package/dist/core.d.ts +66 -0
- package/dist/core.js +220 -0
- package/dist/core.js.map +1 -0
- package/dist/react.d.ts +159 -0
- package/dist/{index.js → react.js} +220 -364
- package/dist/react.js.map +1 -0
- package/dist/schema.d.ts +15 -0
- package/dist/schema.js +11 -0
- package/dist/schema.js.map +1 -0
- package/dist/storage.d.ts +227 -1
- package/dist/storage.js +8 -1
- package/dist/store-DyjKY0s4.d.ts +102 -0
- package/dist/types-BRfvVnCA.d.ts +164 -0
- package/package.json +13 -8
- package/dist/chunk-H4A322SZ.js.map +0 -1
- package/dist/index.d.ts +0 -224
- package/dist/index.js.map +0 -1
- package/dist/storage-DPIKGno6.d.ts +0 -316
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ButtonHTMLAttributes, MouseEvent, HTMLAttributes, ReactElement, PropsWithChildren, ComponentType } from 'react';
|
|
3
|
+
import { K as KeepItemMetadataRefresher, d as KeepItemRevalidator, R as RevalidateKeepItemsOptions, c as KeepItemRevalidationSummary, f as KeepListOptions, g as KeepStore, h as KeepStoreActions } from './store-DyjKY0s4.js';
|
|
4
|
+
export { b as KeepItemRevalidationResult, e as KeepItemStatus, k as isKeepItemMetadataStale } from './store-DyjKY0s4.js';
|
|
5
|
+
import { m as KeepItemInput, a as KeepItem, l as KeepEventHandlers, S as StorageAdapter, d as KeepPlugin, K as KeepSchema, b as KeepInvalidItemPolicy, t as KeepSyncState } from './types-BRfvVnCA.js';
|
|
6
|
+
|
|
7
|
+
type UseKeepItemResult<TMeta = Record<string, unknown>> = {
|
|
8
|
+
item: KeepItem<TMeta> | undefined;
|
|
9
|
+
isSaved: boolean;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
isMutating: boolean;
|
|
12
|
+
error: unknown | null;
|
|
13
|
+
save: () => Promise<void>;
|
|
14
|
+
remove: () => Promise<void>;
|
|
15
|
+
toggle: () => Promise<void>;
|
|
16
|
+
updateNote: (note?: string) => Promise<void>;
|
|
17
|
+
updateTags: (tags?: string[]) => Promise<void>;
|
|
18
|
+
refreshMetadata: (refresh: KeepItemMetadataRefresher<TMeta>) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
declare function useKeepItem<TMeta = Record<string, unknown>>(id: string, itemPayload?: KeepItemInput<TMeta>): UseKeepItemResult<TMeta>;
|
|
21
|
+
|
|
22
|
+
type UseKeepListResult<TMeta = Record<string, unknown>> = {
|
|
23
|
+
items: KeepItem<TMeta>[];
|
|
24
|
+
totalCount: number;
|
|
25
|
+
tags: string[];
|
|
26
|
+
tagCounts: Record<string, number>;
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
isHydrated: boolean;
|
|
29
|
+
isMutating: boolean;
|
|
30
|
+
error: unknown | null;
|
|
31
|
+
remove: (id: string) => Promise<void>;
|
|
32
|
+
removeBatch: (ids: string[]) => Promise<void>;
|
|
33
|
+
updateTagsBatch: (ids: string[], tags?: string[]) => Promise<void>;
|
|
34
|
+
addTagsBatch: (ids: string[], tags: string[]) => Promise<void>;
|
|
35
|
+
removeTagsBatch: (ids: string[], tags: string[]) => Promise<void>;
|
|
36
|
+
clear: () => Promise<void>;
|
|
37
|
+
refresh: () => Promise<void>;
|
|
38
|
+
revalidate: (revalidator: KeepItemRevalidator<TMeta>, options?: RevalidateKeepItemsOptions) => Promise<KeepItemRevalidationSummary<TMeta>>;
|
|
39
|
+
};
|
|
40
|
+
declare function useKeepList<TMeta = Record<string, unknown>>(options?: KeepListOptions<TMeta>): UseKeepListResult<TMeta>;
|
|
41
|
+
|
|
42
|
+
type KeepShortcutModifier = "meta" | "ctrl" | "alt" | "shift";
|
|
43
|
+
type KeepShortcutOptions<TMeta = Record<string, unknown>> = {
|
|
44
|
+
key: string;
|
|
45
|
+
modifier?: KeepShortcutModifier;
|
|
46
|
+
id?: string;
|
|
47
|
+
itemPayload?: KeepItemInput<TMeta>;
|
|
48
|
+
action?: "toggle" | "save" | "remove";
|
|
49
|
+
enabled?: boolean;
|
|
50
|
+
preventDefault?: boolean;
|
|
51
|
+
allowInEditable?: boolean;
|
|
52
|
+
onTrigger?: (event: KeyboardEvent) => void | Promise<void>;
|
|
53
|
+
onError?: (error: unknown) => void;
|
|
54
|
+
};
|
|
55
|
+
/** Bind a keyboard shortcut to a Keep action or an arbitrary command. */
|
|
56
|
+
declare function useKeepShortcut<TMeta = Record<string, unknown>>(options: KeepShortcutOptions<TMeta>): void;
|
|
57
|
+
|
|
58
|
+
type KeepButtonItem<TMeta = Record<string, unknown>> = KeepItemInput<TMeta> & {
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
type KeepButtonSharedProps<TMeta> = {
|
|
62
|
+
item: KeepButtonItem<TMeta>;
|
|
63
|
+
children?: ReactNode | ((state: KeepButtonState<TMeta>) => ReactNode);
|
|
64
|
+
savedLabel?: ReactNode;
|
|
65
|
+
unsavedLabel?: ReactNode;
|
|
66
|
+
savedAriaLabel?: string;
|
|
67
|
+
unsavedAriaLabel?: string;
|
|
68
|
+
getAriaLabel?: (state: KeepButtonState<TMeta>) => string;
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
onToggleError?: (error: unknown) => void;
|
|
71
|
+
};
|
|
72
|
+
type KeepButtonProps<TMeta = Record<string, unknown>> = KeepButtonSharedProps<TMeta> & ((Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "onClick" | "aria-pressed"> & {
|
|
73
|
+
asChild?: false;
|
|
74
|
+
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
75
|
+
}) | (Omit<HTMLAttributes<HTMLElement>, "children" | "onClick" | "aria-pressed"> & {
|
|
76
|
+
asChild: true;
|
|
77
|
+
children: ReactElement | ((state: KeepButtonState<TMeta>) => ReactElement);
|
|
78
|
+
onClick?: (event: MouseEvent<HTMLElement>) => void;
|
|
79
|
+
}));
|
|
80
|
+
type KeepButtonState<TMeta = Record<string, unknown>> = {
|
|
81
|
+
item: ReturnType<typeof useKeepItem<TMeta>>["item"];
|
|
82
|
+
isSaved: boolean;
|
|
83
|
+
isLoading: boolean;
|
|
84
|
+
isMutating: boolean;
|
|
85
|
+
error: unknown | null;
|
|
86
|
+
save: () => Promise<void>;
|
|
87
|
+
remove: () => Promise<void>;
|
|
88
|
+
toggle: () => Promise<void>;
|
|
89
|
+
updateNote: (note?: string) => Promise<void>;
|
|
90
|
+
updateTags: (tags?: string[]) => Promise<void>;
|
|
91
|
+
};
|
|
92
|
+
/** A style-free accessible save toggle. Consumers provide all visual styling. */
|
|
93
|
+
declare function KeepButton<TMeta = Record<string, unknown>>({ item, children, savedLabel, unsavedLabel, savedAriaLabel, unsavedAriaLabel, getAriaLabel, asChild, onToggleError, onClick, disabled, ...buttonProps }: KeepButtonProps<TMeta>): react.JSX.Element;
|
|
94
|
+
|
|
95
|
+
type KeepContextValue<TMeta = Record<string, unknown>> = {
|
|
96
|
+
items: KeepItem<TMeta>[];
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
isHydrated: boolean;
|
|
99
|
+
isMutating: boolean;
|
|
100
|
+
error: unknown | null;
|
|
101
|
+
syncState: KeepSyncState;
|
|
102
|
+
saveItem: (item: KeepItem<TMeta>) => Promise<void>;
|
|
103
|
+
updateNote: (id: string, note?: string) => Promise<void>;
|
|
104
|
+
updateTags: (id: string, tags?: string[]) => Promise<void>;
|
|
105
|
+
updateTagsBatch: (ids: string[], tags?: string[]) => Promise<void>;
|
|
106
|
+
addTagsBatch: (ids: string[], tags: string[]) => Promise<void>;
|
|
107
|
+
removeTagsBatch: (ids: string[], tags: string[]) => Promise<void>;
|
|
108
|
+
removeItem: (id: string) => Promise<void>;
|
|
109
|
+
removeItems: (ids: string[]) => Promise<void>;
|
|
110
|
+
clear: () => Promise<void>;
|
|
111
|
+
refresh: () => Promise<void>;
|
|
112
|
+
flushSync: () => Promise<void>;
|
|
113
|
+
refreshItemMetadata: (id: string, refresh: KeepItemMetadataRefresher<TMeta>) => Promise<void>;
|
|
114
|
+
revalidateItems: (revalidator: KeepItemRevalidator<TMeta>, options?: RevalidateKeepItemsOptions) => Promise<KeepItemRevalidationSummary<TMeta>>;
|
|
115
|
+
};
|
|
116
|
+
type KeepProviderProps<TMeta = Record<string, unknown>> = PropsWithChildren<KeepEventHandlers<TMeta> & {
|
|
117
|
+
storage?: StorageAdapter<TMeta>;
|
|
118
|
+
/**
|
|
119
|
+
* Optional server-provided snapshot rendered before the client adapter
|
|
120
|
+
* finishes hydrating. The adapter remains the source of truth after the
|
|
121
|
+
* first refresh.
|
|
122
|
+
*/
|
|
123
|
+
initialItems?: KeepItem<TMeta>[];
|
|
124
|
+
plugins?: KeepPlugin<TMeta>[];
|
|
125
|
+
schemaVersion?: number;
|
|
126
|
+
schema?: KeepSchema<TMeta>;
|
|
127
|
+
invalidItemPolicy?: KeepInvalidItemPolicy;
|
|
128
|
+
onInvalidItem?: (error: unknown, item: KeepItem<unknown>) => void;
|
|
129
|
+
migrateMeta?: (meta: unknown, fromVersion: number, toVersion: number, item: KeepItem<TMeta>) => TMeta | Promise<TMeta>;
|
|
130
|
+
}>;
|
|
131
|
+
type KeepStoreAccess<TMeta> = {
|
|
132
|
+
store: KeepStore<TMeta>;
|
|
133
|
+
actions: KeepStoreActions<TMeta>;
|
|
134
|
+
};
|
|
135
|
+
declare function KeepProvider<TMeta = Record<string, unknown>>({ storage, initialItems, onSave, onRemove, onNoteUpdate, onTagsUpdate, onChange, onError, plugins, schemaVersion, schema, invalidItemPolicy, onInvalidItem, migrateMeta, children, }: KeepProviderProps<TMeta>): react.JSX.Element;
|
|
136
|
+
declare function useKeepContext<TMeta = Record<string, unknown>>(): KeepContextValue<TMeta>;
|
|
137
|
+
declare function useKeepStore<TMeta = Record<string, unknown>>(): KeepStoreAccess<TMeta>;
|
|
138
|
+
|
|
139
|
+
type CreateKeepKitOptions<TMeta = Record<string, unknown>> = {
|
|
140
|
+
initialItems?: KeepProviderProps<TMeta>["initialItems"];
|
|
141
|
+
plugins?: KeepPlugin<TMeta>[];
|
|
142
|
+
schemaVersion?: number;
|
|
143
|
+
schema?: KeepSchema<TMeta>;
|
|
144
|
+
invalidItemPolicy?: KeepInvalidItemPolicy;
|
|
145
|
+
onInvalidItem?: KeepProviderProps<TMeta>["onInvalidItem"];
|
|
146
|
+
migrateMeta?: KeepProviderProps<TMeta>["migrateMeta"];
|
|
147
|
+
};
|
|
148
|
+
type KeepKit<TMeta> = {
|
|
149
|
+
KeepProvider: ComponentType<KeepProviderProps<TMeta>>;
|
|
150
|
+
KeepButton: ComponentType<KeepButtonProps<TMeta>>;
|
|
151
|
+
useKeepContext: () => ReturnType<typeof useKeepContext<TMeta>>;
|
|
152
|
+
useKeepItem: (id: string, itemPayload?: KeepItemInput<TMeta>) => UseKeepItemResult<TMeta>;
|
|
153
|
+
useKeepList: (options?: KeepListOptions<TMeta>) => UseKeepListResult<TMeta>;
|
|
154
|
+
useKeepShortcut: (options: KeepShortcutOptions<TMeta>) => void;
|
|
155
|
+
};
|
|
156
|
+
/** Create an app-specific, fully typed set of KeepKit components and hooks. */
|
|
157
|
+
declare function createKeepKit<TMeta = Record<string, unknown>>(options?: CreateKeepKitOptions<TMeta>): KeepKit<TMeta>;
|
|
158
|
+
|
|
159
|
+
export { type CreateKeepKitOptions, KeepButton, type KeepButtonItem, type KeepButtonProps, type KeepButtonState, type KeepContextValue, KeepItemMetadataRefresher, KeepItemRevalidationSummary, KeepItemRevalidator, type KeepKit, KeepListOptions, KeepProvider, type KeepProviderProps, type KeepShortcutModifier, type KeepShortcutOptions, RevalidateKeepItemsOptions, type UseKeepItemResult, type UseKeepListResult, createKeepKit, useKeepContext, useKeepItem, useKeepList, useKeepShortcut, useKeepStore };
|