@keepkit/core 0.1.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/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/chunk-H4A322SZ.js +768 -0
- package/dist/chunk-H4A322SZ.js.map +1 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +1093 -0
- package/dist/index.js.map +1 -0
- package/dist/storage-DPIKGno6.d.ts +316 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.js +29 -0
- package/dist/storage.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nitta-a
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# @keepkit/core
|
|
2
|
+
|
|
3
|
+
[日本語](#日本語) | [English](#english)
|
|
4
|
+
|
|
5
|
+
## 日本語
|
|
6
|
+
|
|
7
|
+
Reactアプリケーション向けの、ヘッドレスで非同期処理を前提とした保存・コレクション用プリミティブです。
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { KeepButton, KeepProvider, LocalStorageAdapter } from "@keepkit/core";
|
|
11
|
+
|
|
12
|
+
const storage = new LocalStorageAdapter({ key: "my-app:items" });
|
|
13
|
+
|
|
14
|
+
<KeepProvider storage={storage}>
|
|
15
|
+
<KeepButton
|
|
16
|
+
item={{
|
|
17
|
+
id: "article-123",
|
|
18
|
+
targetType: "article",
|
|
19
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
</KeepProvider>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`useKeepItem(id, payload)` では保存、切り替え、削除、ノート・タグ更新を行えます。`useKeepList()` ではコレクションの取得、タグ絞り込み・検索・ソート・ページネーション、`removeBatch` / `updateTagsBatch` / `addTagsBatch` / `removeTagsBatch` による一括操作ができます。`KeepProvider` は `isHydrated` / `isMutating` と typed storage errors を公開します。`LocalStorageAdapter` はSSR環境からimportでき、`StorageAdapter<TMeta>` または `createStorageAdapter` でサーバー側のストアに接続できます。
|
|
26
|
+
|
|
27
|
+
`exportItems(adapter)` / `importItems(adapter, json, { mode: "replace" | "merge" })` でversion付きJSONバックアップを扱えます。結果には `imported` / `failed` 件数が含まれます。
|
|
28
|
+
|
|
29
|
+
大規模アプリでは `SyncStorageAdapter` を使ってローカル保存とリモート同期を分離できます。`IndexedDBSyncQueueAdapter`(既定)または `LocalStorageSyncQueueAdapter` に操作を永続化し、オンライン復帰時に `flushSync()` で再送します。`KeepProvider` の `syncState` で `pending` / `syncing` / `conflict` / `error` を取得できます。
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
const storage = new SyncStorageAdapter({
|
|
33
|
+
local: new IndexedDBAdapter({ databaseName: "my-app" }),
|
|
34
|
+
remote: {
|
|
35
|
+
push: (operation) => api.syncKeepOperation(operation),
|
|
36
|
+
},
|
|
37
|
+
resolveConflict: (local, remote) => ({
|
|
38
|
+
...remote,
|
|
39
|
+
note: local?.note ?? remote.note,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
<KeepProvider
|
|
44
|
+
storage={storage}
|
|
45
|
+
schema={{ parse: (value) => validateMeta(value) }}
|
|
46
|
+
invalidItemPolicy="drop"
|
|
47
|
+
/>;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`useKeepList` は `savedBetween`、`search: { query, mode: "and" | "or" }`、`filterFn`、`tagCounts` をサポートします。TanStack Query や SWR のキャッシュ連携には、依存関係を core に追加しない `createKeepInvalidationPlugin` を利用できます。
|
|
51
|
+
|
|
52
|
+
詳細な使い方と開発コマンドは [ルートREADME](../../README.md) を、現在の変更内容は [リリースノート](../../RELEASE_NOTES.md) を参照してください。
|
|
53
|
+
|
|
54
|
+
## English
|
|
55
|
+
|
|
56
|
+
Headless, async-first save-and-collect primitives for React applications.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { KeepButton, KeepProvider, LocalStorageAdapter } from "@keepkit/core";
|
|
60
|
+
|
|
61
|
+
const storage = new LocalStorageAdapter({ key: "my-app:items" });
|
|
62
|
+
|
|
63
|
+
<KeepProvider storage={storage}>
|
|
64
|
+
<KeepButton
|
|
65
|
+
item={{
|
|
66
|
+
id: "article-123",
|
|
67
|
+
targetType: "article",
|
|
68
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
</KeepProvider>;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use `useKeepItem(id, payload)` for saving, toggling, removing, and updating notes or tags. Use `useKeepList()` to read, filter, sort, and perform bulk removal/tag updates. `KeepProvider` exposes `isHydrated`, `isMutating`, and typed storage errors. `LocalStorageAdapter` is safe to import in SSR environments; implement `StorageAdapter<TMeta>` or use `createStorageAdapter` to connect a server-backed store.
|
|
75
|
+
|
|
76
|
+
Use `exportItems(adapter)` and `importItems(adapter, json, { mode: "replace" | "merge" })` for versioned JSON backups. Results include imported and failed counts.
|
|
77
|
+
|
|
78
|
+
For larger applications, wrap a local adapter with `SyncStorageAdapter` to persist a durable offline queue and flush it with `flushSync()` when connectivity returns. Use `syncState` from `KeepProvider` for `pending`, `syncing`, `conflict`, and `error` feedback. `KeepProvider` also accepts a Zod-like `parse`, `safeParse`, or Standard Schema validator through `schema`; invalid stored records can be rejected or dropped with `invalidItemPolicy`.
|
|
79
|
+
|
|
80
|
+
`useKeepList` supports `savedBetween`, tokenized `search` with `and` / `or` modes, `filterFn`, and `tagCounts`. Use `createKeepInvalidationPlugin` to connect TanStack Query, SWR, or another cache without adding framework dependencies to core.
|
|
81
|
+
|
|
82
|
+
See the [root README](../../README.md) for detailed usage and development commands, and the [release notes](../../RELEASE_NOTES.md) for the current changes.
|