@keepkit/ui 0.28.8 → 0.28.10
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 +225 -193
- package/dist/index.d.ts +51 -9
- package/dist/index.js +2321 -827
- package/dist/index.js.map +1 -1
- package/dist/styles/base.css +17 -9
- package/dist/styles/collection.css +153 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,312 +2,344 @@
|
|
|
2
2
|
|
|
3
3
|
[日本語](#日本語) | [English](#english)
|
|
4
4
|
|
|
5
|
+
Release: v0.28.10
|
|
6
|
+
|
|
5
7
|
## 日本語
|
|
6
8
|
|
|
7
|
-
React
|
|
9
|
+
KeepKitのReact向けUIパッケージです。`@keepkit/core`を含み、保存ボタンと一覧を共通のProviderで利用できます。
|
|
10
|
+
CSSは任意で、標準テーマでも独自のスタイルでも使えます。React 18以降に対応します。
|
|
11
|
+
|
|
12
|
+
### はじめる
|
|
8
13
|
|
|
9
14
|
```bash
|
|
10
15
|
pnpm add @keepkit/ui
|
|
11
16
|
```
|
|
12
17
|
|
|
13
|
-
## Minimal Starter Recipe
|
|
14
|
-
|
|
15
18
|
```tsx
|
|
16
19
|
import "@keepkit/ui/theme.css";
|
|
17
20
|
import { createBrowserStorageAdapter, createKeepKit } from "@keepkit/ui";
|
|
18
21
|
|
|
19
|
-
type
|
|
20
|
-
const keep = createKeepKit<
|
|
21
|
-
storage: createBrowserStorageAdapter({ key: "
|
|
22
|
+
type ArticleMeta = { title: string; url: string };
|
|
23
|
+
const keep = createKeepKit<ArticleMeta>({
|
|
24
|
+
storage: createBrowserStorageAdapter({ key: "my-app:items" }),
|
|
25
|
+
locale: "ja",
|
|
22
26
|
});
|
|
23
27
|
|
|
24
|
-
export function
|
|
28
|
+
export function App() {
|
|
25
29
|
return (
|
|
26
|
-
<keep.Provider
|
|
27
|
-
<keep.Button
|
|
30
|
+
<keep.Provider>
|
|
31
|
+
<keep.Button
|
|
32
|
+
item={{
|
|
33
|
+
id: "article-123",
|
|
34
|
+
targetType: "article",
|
|
35
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
28
38
|
<keep.Collection query={{ targetType: "article" }} />
|
|
29
39
|
</keep.Provider>
|
|
30
40
|
);
|
|
31
41
|
}
|
|
32
42
|
```
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
`createKeepKit<TMeta>()`は同じメタデータ型のコンポーネントとhooksを返します。
|
|
45
|
+
`locale`で組み込みラベルを切り替え、`labels`で文言を上書きできます。16言語に対応しています。
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
import "@keepkit/ui/theme.css";
|
|
38
|
-
import { createBrowserStorageAdapter, createKeepKit } from "@keepkit/ui";
|
|
47
|
+
### 一覧を拡張する
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
storage: createBrowserStorageAdapter({ key: "articles" }),
|
|
43
|
-
locale: "ja-JP",
|
|
44
|
-
labels: { save: "保存", remove: "削除" },
|
|
45
|
-
});
|
|
49
|
+
`keep.Collection`は検索・ソート・ページング、読み込み中・空・エラー表示を標準で備えます。
|
|
50
|
+
検索は既定で300msデバウンスされます。必要な機能を`features`で有効にします。
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
```tsx
|
|
53
|
+
export function Library() {
|
|
48
54
|
return (
|
|
49
55
|
<keep.Provider>
|
|
50
56
|
<keep.Collection
|
|
51
57
|
query={{ targetType: "article" }}
|
|
52
|
-
|
|
58
|
+
layout="auto"
|
|
59
|
+
urlSync
|
|
60
|
+
features={{ tagFilter: true, collectionFilter: true, bulkActions: true, savedViews: true }}
|
|
61
|
+
itemCardProps={{ href: (item) => item.meta.url }}
|
|
53
62
|
/>
|
|
63
|
+
<keep.Backup />
|
|
54
64
|
</keep.Provider>
|
|
55
65
|
);
|
|
56
66
|
}
|
|
57
67
|
```
|
|
58
68
|
|
|
59
|
-
`
|
|
69
|
+
`layout`は`list`、`grid`、`compact`、コンテナ幅に追従する`auto`から選べます。
|
|
70
|
+
`urlSync`は検索・タグ・ソート・ページをURLと戻る/進むに同期します。
|
|
71
|
+
Next.js Pages Routerでは`createNextPagesRouterAdapter(router)`を`urlAdapter`に渡します。
|
|
60
72
|
|
|
61
|
-
|
|
62
|
-
再発見には`useKeepItem(item).recordOpen()`で`lastOpenedAt`を記録し、`activity`クエリまたは`createRediscoveryQuery()` / `useKeepRediscovery()`を利用できます。`inactiveForMs`は未閲覧なら`savedAt`、閲覧済みなら`lastOpenedAt`を基準にし、開封記録だけでは`updatedAt`を変更しません。`<KeepRediscovery strategy="forgotten" limit={5} />`は低レベルの一覧プリセット、`<KeepRediscoveryPanel strategy="forgotten" limit={5} />`は表示理由とActivityバッジ付きの標準UIです。カード単位では`trackOpen`を指定したときだけ開封記録を有効にします。
|
|
63
|
-
保存確認から対象へ戻すには`revealRequest={{ requestId, itemId }}`を渡し、`onRevealResult`で結果を受け取れます。検索・タグ・保存先フィルターとページを調整して対象を表示します。
|
|
64
|
-
`KeepWorkspace`はこれらのプリミティブを一つにまとめ、`basic`、`standard`、`management`、`sync`のプリセットを提供します。`createKeepKit()`を利用する場合は同じ実装を`keep.Workspace`から型付きで利用できます。`modules`、`slots`、子コンポーネントごとのpropsで部分的に差し替えられます。
|
|
65
|
-
`KeepCollectionManager`は作成・名前変更・削除・件数表示をまとめたheadless UIです。`allowCreate`、`allowRename`、`allowDelete`、`showCounts`で機能を個別に切り替えられ、`collectionLabels`、`title`、`description`、`empty`で表示を差し替えられます。
|
|
66
|
-
標準ブラウザーストレージは空のコレクションと変更後の名前を再読み込み後も復元します。独自の`StorageAdapter`では`getCollections`、`setCollection`、`removeCollection`を実装して永続化できます。
|
|
67
|
-
画面領域を明示する場合は`surface="panel"`または領域別の`surface`と、`sectionGap="compact" | "comfortable"`を指定できます。空のslotは枠を生成せず、未指定時と`surface="plain"`では従来のDOM順序を維持します。
|
|
73
|
+
`reorderable`を有効にすると、明示ソートがない一覧は「手動順序」になります。日時ソートと切り替えられ、並べ替えは手動順序かつ`pinnedFirst`なしの場合に有効です。表示中の項目が占める位置だけを入れ替え、別ページ・非表示項目の位置を保ちます。矢印操作は即時保存、Escapeはつかみ状態の解除、保存済み順序の取り消しは5秒間のUndoで行います。
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
独自の`KeepSortSelect`では`onManualSort`を渡すと`value="manual"`を選択できます。既存の`onValueChange(value, sort)`は日時ソートのみを通知します。手動順序のURL/Saved Viewでは`sort`を省略します。URL同期が有効ならURLが優先し、`sort`省略は以前の日時ソートを解除します。通常の一覧は更新日時降順へ戻ります。同じURLへの遷移は省略し、履歴は既定でpush、`urlSync={{ history: "replace" }}`でreplaceを選べます。
|
|
76
|
+
|
|
77
|
+
未分類のSaved Viewは`organization.collection="unassigned"`で保存します。利用側の関数`query.filter`は引き続き保存できません。`revealRequest`はローカルの検索・タグ・整理・日時条件を解除しますが、利用側の固定`targetType`・`filter`で除外される対象には`excluded`を返します。`creatable`と`slots.toolbarEnd`は併用できます。
|
|
71
78
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
### 記事・リンクを再訪する一覧
|
|
80
|
+
|
|
81
|
+
記事向け表示は選択式です。既存の既定表示は変わりません。
|
|
82
|
+
|
|
83
|
+
`linkTarget="card"`の既定表示は通常の画像・静的内容をリンクにし、タグ・操作ボタン・編集フォームをリンク外に置きます。カスタム画像や`children`/`render`全体は自動で包みません。compoundの`Title`はタイトルリンクを提供します。カスタム構成では`KeepItemCard.Link`で非対話コンテンツを明示的に包みます。URL、router用`linkComponent`、外部リンク属性、利用不能状態、`trackOpen`/`onOpen`はrootと共有します。内側の`Title`は静的表示、`Content`は自動タグなしです。独自のボタンやフォームもリンク外に置いてください。
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<keep.Collection
|
|
87
|
+
layout="list"
|
|
88
|
+
query={{ sort: { by: "savedAt", direction: "desc" }, pinnedFirst: true }}
|
|
89
|
+
features={{ bulkActions: true, pin: true, archive: true }}
|
|
90
|
+
bulkActionsVariant="inline"
|
|
91
|
+
itemCardProps={{ presentation: "reading", href: (item) => item.meta.url, trackOpen: true }}
|
|
92
|
+
/>
|
|
75
93
|
```
|
|
76
|
-
一覧の標準カードで必要な機能だけを有効化する場合は、`features={{ pin: true, archive: true, tags: false }}`を指定できます。`pin` / `archive` はカード操作ボタン、`tags` はカード内のタグ表示を切り替えます。タグフィルターは`tagFilter`、タグ編集は`KeepTagEditor`で個別に制御でき、`itemCardProps`の明示指定が`features`より優先されます。
|
|
77
|
-
`KeepCollection`は検索語と選択タグを`KeepActiveFiltersSummary`のチップとして表示し、個別解除と「すべての条件をクリア」を提供します。`activeFilters`でこの領域を差し替えられます。標準の`KeepList` / `KeepCollection`は、全件0件の`empty-storage`と絞り込み結果0件の`empty-filtered`を区別し、後者では`onClearFilters`付きの解除ボタンを表示します。
|
|
78
|
-
`toolbarLayout="grouped"`と`toolbarVariant="panel"`を指定すると、`slots.toolbarStart` / `slots.toolbarEnd`を含む主操作、検索・ソート、フィルターの各グループをローカライズされた`role="group"`として描画します。狭い幅ではグループ内のコントロールを縦に折り返します。
|
|
79
|
-
`KeepItemCard`は`href`、`onOpen`、`linkTarget`、`linkComponent`に対応し、保存アイテムから詳細ページへ遷移できます。非公開・期限切れ等の`status`を持つアイテムは自動的にリンクを無効化します。`KeepBackup`はJSONのエクスポート、merge / replaceインポート、結果件数、容量エラー表示を提供します。
|
|
80
|
-
`KeepTourBar`(alias: `KeepNavigator`)は進行度、前へ・次へ、一覧へ戻る操作をURLまたはコールバックで提供します。`getItemHref`、`getBackHref`、`onNavigate`でホストのルーティングを注入できます。前後ボタンには隣接アイテム名のプレビューが付き、`getItemTitle`で表示名を差し替えられます。`keyboardShortcuts`を指定するとJ/Kまたは]/[で巡回でき、`useKeepTourShortcuts`ではキーと動作を個別に差し替えられます。`KeepReorderableList`はドラッグ操作と矢印キーによる並び替えを提供し、ドラッグ中の挿入位置を表示します。`KeepCollection reorderable`ではこの導線と標準Undoを差し替えなしで利用できます。
|
|
81
|
-
`KeepShortcutHint`はセマンティックな`<kbd>`バッジを表示します。`KeepTourBar showShortcutHint`は前へ/次へのキーを、`KeepNoteEditor showShortcutHint`は`Ctrl+Enter`を標準ボタン内に表示します。`mergeProps` / `createSlot`は`asChild`でclassName、style、ARIA属性、イベント、子と親のrefを合成し、`composeRefs`はcallback refとobject refをまとめる共通基盤です。フィルターチップは削除後に隣接チップへ戻り、ArrowLeft / ArrowRightで移動できます。
|
|
82
|
-
`KeepList`や`KeepCollection`のカードは検索語を大文字小文字を区別せず`<mark class="keep-highlight" data-highlight="true">`で表示します。単体の`KeepItemCard`では`highlightQuery`、任意のテキストでは`KeepHighlight`を使えます。`KeepItemCard.Media`は読み込み状態を`data-media-status`で公開し、失敗時は`fallback`または標準SVGへ切り替わります。
|
|
83
|
-
テーマCSSではハイライト用の`--keep-highlight-bg` / `--keep-highlight-fg`(ライト/ダーク対応)、タイトル2行・メモプレビュー3行の制限、メディアの固定アスペクト比を適用します。`KeepItemStatusBadge`は状態ラベルに加えてチェック・時計・進入禁止・鍵のSVGアイコンを表示し、状態ごとの形状とトーンを組み合わせます。個別の状態スタイルは`@keepkit/ui/styles/status.css`からも読み込めます。
|
|
84
|
-
外部URLの詳細リンクには`target="_blank"`と`rel="noreferrer"`が既定で補完され、利用できないカードには`aria-disabled="true"`と`data-item-status`が付与されます。同期競合ダイアログではローカルとリモートの更新日時・メモを並べて確認できます。
|
|
85
|
-
カードは`cardVariant="outlined" | "elevated" | "filled"`で面の表現を選べます。`--keep-card-border` / `--keep-card-shadow`と`--keep-surface-border` / `--keep-surface-background`はカード、ツールバー、Workspace領域を個別に調整するテーマトークンです。
|
|
86
|
-
|
|
87
|
-
`KeepList`は初回ロード中、`layout`に合う`KeepItemCardSkeleton`を既定で6枚表示します。`loadingCount`で枚数を変更でき、従来の`loading`または`renderLoading`で完全に差し替えられます。`layout="auto"`は画面幅ではなく配置コンテナ幅に追従し、サイドバーやモーダルでも1列から複数列へ切り替わります。スケルトンのパルスは`prefers-reduced-motion`で静止表示になります。
|
|
88
|
-
カードグループはRoving Tabindexを採用しており、カードにフォーカスして矢印キー、Home、Endで移動できます。
|
|
89
|
-
|
|
90
|
-
カードの一部だけを配置し直す場合はCompound APIを利用できます。画像alt、タイトルリンク、タグ一覧のARIAラベル、保存操作の状態は各パーツでも維持されます。
|
|
91
94
|
|
|
92
95
|
```tsx
|
|
93
|
-
<KeepItemCard item={item} href={
|
|
94
|
-
<KeepItemCard.
|
|
95
|
-
|
|
96
|
-
<KeepItemCard.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<KeepItemCard.Actions
|
|
100
|
-
<KeepItemCard.Save />
|
|
101
|
-
<KeepItemCard.Pin />
|
|
102
|
-
<KeepItemCard.Archive />
|
|
103
|
-
<KeepItemCard.Remove />
|
|
104
|
-
</KeepItemCard.Actions>
|
|
96
|
+
<KeepItemCard item={item} href={item.meta.url} trackOpen>
|
|
97
|
+
<KeepItemCard.Link>
|
|
98
|
+
<KeepItemCard.Media />
|
|
99
|
+
<KeepItemCard.Content />
|
|
100
|
+
</KeepItemCard.Link>
|
|
101
|
+
<KeepItemCard.Tags />
|
|
102
|
+
<KeepItemCard.Actions />
|
|
105
103
|
</KeepItemCard>
|
|
106
104
|
```
|
|
107
105
|
|
|
108
|
-
`
|
|
106
|
+
`presentation="reading"`はタイトル、URLの保存元、コレクション名、メモ、タグ、保存・訪問情報を表示します。画像は`getImageProps`で指定した場合だけ表示します。保存トグルは既定で非表示、編集・メモ・訪問情報は表示され、既存の表示フラグで上書きできます。`href`と`trackOpen`は明示指定です。編集は300msの自動保存と「完了」を使い、失敗時は下書きを残します。
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
const onFeedback = useKeepToastFeedback(toast);
|
|
112
|
-
<KeepKitProvider storage={storage} onFeedback={onFeedback}>{children}</KeepKitProvider>;
|
|
113
|
-
```
|
|
108
|
+
`bulkActionsVariant="inline"`は記事行で選択します。全選択は現在ページだけで、検索・フィルター・ページ・表示先を変えると選択を解除します。失敗した一括操作は選択を保持します。既定の`separate`は従来の選択用一覧を維持します。
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
Phase 4の状態UIとして`KeepItemStatusBadge`、`KeepStaleNotice`、`KeepPruneStaleButton`、`KeepSyncStatusBanner`、`KeepSyncRecoveryDialog`を利用できます。`import "@keepkit/ui/theme.css"`でテーマCSSを有効にできます。
|
|
110
|
+
独自の行には`KeepListSelection`(`selectedIds: readonly string[]`、`onSelectedIdsChange`、任意の`disabled`)を`KeepList.selection`に渡せます。`KeepList`と`KeepCollection`の`renderItem(item, state, selection?)`の第三引数は`KeepItemSelection`(`checked`、`onCheckedChange`、任意の`disabled`)で、`KeepItemCheckbox`にそのまま渡せます。従来の二引数コールバックも使用できます。
|
|
117
111
|
|
|
118
|
-
|
|
112
|
+
`KeepBulkActions`と`KeepCollection`の`confirmRemoval`は既定falseです。`confirmRemoval`を渡すと削除前に件数と確定・取消を表示します。確認開始時の全選択ID(ページ外も含む)を固定し、選択・scope・検索条件の変更で取り消します。失敗時は再試行でき、成功後は既存のUndoで復元できます。render-propsには`removalConfirmation`、`requestRemoval()`、`confirmRemoval()`、`cancelRemoval()`を公開します。
|
|
119
113
|
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
@import "tailwindcss";
|
|
123
|
-
@import "@keepkit/ui/tailwind.css";
|
|
114
|
+
```tsx
|
|
115
|
+
<keep.Collection confirmRemoval features={{ bulkActions: true }} />
|
|
124
116
|
```
|
|
125
117
|
|
|
118
|
+
### fallback分岐を確認・復元する
|
|
119
|
+
|
|
120
|
+
`KeepFallbackRecovery`はProviderと独立した画面です。対象adapterの`recovery`を明示的に渡します。表示や比較では書き込まず、競合の保存元を選び、所属などの変更プレビューを確認して適用します。未解決の競合や不整合がある場合は適用できません。データが変わった場合は再比較が必要です。「反映待ち」は修復内容が保存済みなので、再提出せず再試行します。
|
|
121
|
+
|
|
126
122
|
```tsx
|
|
127
|
-
import {
|
|
123
|
+
import { createBrowserStorageAdapter, KeepFallbackRecovery, KeepUiProvider } from "@keepkit/ui";
|
|
124
|
+
|
|
125
|
+
const storage = createBrowserStorageAdapter({ key: "my-app:items", scope: { userId: "alice" } });
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
function RecoveryScreen() {
|
|
128
|
+
return storage.recovery ? (
|
|
129
|
+
<KeepUiProvider locale="ja">
|
|
130
|
+
<KeepFallbackRecovery recovery={storage.recovery} />
|
|
131
|
+
</KeepUiProvider>
|
|
132
|
+
) : null;
|
|
133
|
+
}
|
|
132
134
|
```
|
|
133
135
|
|
|
134
|
-
|
|
136
|
+
`SyncStorageAdapter`経由では状態のみ表示します。修復は同期開始前のstandalone local adapterで行ってください。修復前バックアップは自動削除しません。導入時は旧実装のタブをすべて更新し、[Coreガイド](../keepkit/README.md)の保存制約を確認してください。
|
|
135
137
|
|
|
136
|
-
|
|
138
|
+
`KeepQuickEditor.closeLabel`で終了ボタンの文言を指定できます。`debounceMs={0}`による手動保存は維持され、完了・Escapeでの終了は保存成功後に行います。単独のエディターはTabを閉じ込めません。
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
### 用途別のコンポーネント
|
|
139
141
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<KeepItemCard
|
|
149
|
-
item={item}
|
|
150
|
-
href={`/guide/${item.id}`}
|
|
151
|
-
getImageProps={(entry) => ({ src: entry.meta.image, alt: entry.meta.title })}
|
|
152
|
-
/>
|
|
153
|
-
</KeepThemeProvider>;
|
|
154
|
-
```
|
|
142
|
+
| 用途 | API |
|
|
143
|
+
| --- | --- |
|
|
144
|
+
| 未分類の整理・検索条件の保存 | `keep.Inbox`、`keep.SavedViews` |
|
|
145
|
+
| コレクション管理 | `keep.CollectionManager` |
|
|
146
|
+
| 画面一式 | `keep.Workspace`。`basic` / `standard` / `management` / `sync`プリセット |
|
|
147
|
+
| メモ・タグ・保存直後の編集 | `KeepNoteEditor`、`KeepTagEditor`、`KeepSavePopover`、`KeepQuickEditor` |
|
|
148
|
+
| 再発見・巡回・並び替え | `KeepRediscoveryPanel`、`KeepTourBar`、`KeepFloatingTour`、`KeepReorderableList` |
|
|
149
|
+
| 復元・保存対象の状態・同期状態 | `KeepUndo`、`keep.Backup`、`KeepItemStatusBadge`、`KeepSyncStatusBanner`、`KeepSyncRecoveryDialog` |
|
|
155
150
|
|
|
156
|
-
|
|
151
|
+
各コンポーネントは同じProvider内に配置します。`renderItem`、slots、render propsで独自レイアウトへ組み込めます。
|
|
152
|
+
`KeepItemCard`の`Link` / `Media` / `Content` / `Title` / `Tags` / `Actions`でカードの一部だけを組み替えることもできます。
|
|
157
153
|
|
|
158
|
-
|
|
154
|
+
### テーマとアクセシビリティ
|
|
159
155
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
sort: { by: "updatedAt" as const, direction: "desc" as const },
|
|
166
|
-
pagination: { page: 1, pageSize: 20 },
|
|
167
|
-
};
|
|
156
|
+
通常は`@keepkit/ui/theme.css`を読み込みます。Tailwind CSS v4/shadcnではグローバルCSSに次を記載します。
|
|
157
|
+
|
|
158
|
+
```css
|
|
159
|
+
@import "tailwindcss";
|
|
160
|
+
@import "@keepkit/ui/tailwind.css";
|
|
168
161
|
```
|
|
169
162
|
|
|
170
|
-
|
|
163
|
+
Providerの`theme="ocean"`や`mode="light" | "dark" | "system"`、`density`、`radius`で見た目を調整できます。
|
|
164
|
+
`--keep-*`変数で上書きでき、Tailwind連携ではホストの色変数を継承します。
|
|
171
165
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
166
|
+
操作はキーボード・ARIAラベル・状態通知に対応します。`data-state`、`data-loading`、`data-disabled`は独自CSSでも利用できます。
|
|
167
|
+
カード一覧は矢印キー・Home・Endで移動でき、`trackOpen`を指定したカードでのみ開封を記録します。
|
|
168
|
+
|
|
169
|
+
### 保存と同期
|
|
176
170
|
|
|
177
|
-
|
|
171
|
+
ブラウザー内保存はIndexedDB優先・localStorage fallbackです。端末間同期にはアプリ側のdriver・認証・サーバーAPIが必要です。
|
|
172
|
+
バックアップは保存アイテム・コレクション定義・所属を含み、閲覧履歴・鑑賞記録・進行位置は含みません。
|
|
173
|
+
**Replace(置換)は既存データを置き換え、ロールバックしません。**
|
|
174
|
+
|
|
175
|
+
保存・同期の契約は[Core README](../keepkit/README.md)、デモとNext.jsサンプルは[リポジトリREADME](../../README.md)を参照してください。
|
|
178
176
|
|
|
179
177
|
## English
|
|
180
178
|
|
|
181
|
-
|
|
179
|
+
React UI for KeepKit, including `@keepkit/core`, with a shared provider for save buttons and collections.
|
|
180
|
+
CSS is optional: use the supplied theme or your own styles. Requires React 18 or later.
|
|
181
|
+
|
|
182
|
+
### Getting started
|
|
182
183
|
|
|
183
184
|
```bash
|
|
184
185
|
pnpm add @keepkit/ui
|
|
185
186
|
```
|
|
186
187
|
|
|
187
188
|
```tsx
|
|
189
|
+
import "@keepkit/ui/theme.css";
|
|
188
190
|
import { createBrowserStorageAdapter, createKeepKit } from "@keepkit/ui";
|
|
189
191
|
|
|
190
192
|
type ArticleMeta = { title: string; url: string };
|
|
191
193
|
const keep = createKeepKit<ArticleMeta>({
|
|
192
|
-
storage: createBrowserStorageAdapter({ key: "
|
|
193
|
-
|
|
194
|
+
storage: createBrowserStorageAdapter({ key: "my-app:items" }),
|
|
195
|
+
locale: "en",
|
|
194
196
|
});
|
|
195
197
|
|
|
196
|
-
function
|
|
198
|
+
export function App() {
|
|
197
199
|
return (
|
|
198
200
|
<keep.Provider>
|
|
201
|
+
<keep.Button
|
|
202
|
+
item={{
|
|
203
|
+
id: "article-123",
|
|
204
|
+
targetType: "article",
|
|
205
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
206
|
+
}}
|
|
207
|
+
/>
|
|
199
208
|
<keep.Collection query={{ targetType: "article" }} />
|
|
200
209
|
</keep.Provider>
|
|
201
210
|
);
|
|
202
211
|
}
|
|
203
212
|
```
|
|
204
213
|
|
|
205
|
-
`
|
|
214
|
+
`createKeepKit<TMeta>()` returns components and hooks sharing your metadata type.
|
|
215
|
+
Use `locale` for built-in labels and `labels` for overrides. Sixteen languages are supported.
|
|
216
|
+
|
|
217
|
+
### Extend the collection
|
|
206
218
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
`KeepWorkspace` composes these primitives into `basic`, `standard`, `management`, and `sync` presets. `createKeepKit()` exposes the same implementation as a typed `keep.Workspace`. Override individual areas through `modules`, `slots`, and child-component props.
|
|
210
|
-
`KeepCollectionManager` is a headless collection-management UI for creating, renaming, deleting, and counting collections. Toggle each capability with `allowCreate`, `allowRename`, `allowDelete`, and `showCounts`; customize `collectionLabels`, `title`, `description`, and `empty`.
|
|
211
|
-
Standard browser storage restores empty collections and renamed labels after reload. Custom `StorageAdapter` implementations can persist them by implementing `getCollections`, `setCollection`, and `removeCollection`.
|
|
212
|
-
Use `surface="panel"` or a per-region `surface` map together with `sectionGap="compact" | "comfortable"` to make workspace boundaries explicit. Empty slots do not create frames, and omitted `surface` or `surface="plain"` preserves the existing DOM order.
|
|
219
|
+
`keep.Collection` includes search, sorting, pagination, and loading, empty, and error states.
|
|
220
|
+
Search is debounced by 300ms by default. Enable additional controls through `features`.
|
|
213
221
|
|
|
214
222
|
```tsx
|
|
215
|
-
|
|
223
|
+
export function Library() {
|
|
224
|
+
return (
|
|
225
|
+
<keep.Provider>
|
|
226
|
+
<keep.Collection
|
|
227
|
+
query={{ targetType: "article" }}
|
|
228
|
+
layout="auto"
|
|
229
|
+
urlSync
|
|
230
|
+
features={{ tagFilter: true, collectionFilter: true, bulkActions: true, savedViews: true }}
|
|
231
|
+
itemCardProps={{ href: (item) => item.meta.url }}
|
|
232
|
+
/>
|
|
233
|
+
<keep.Backup />
|
|
234
|
+
</keep.Provider>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Choose `list`, `grid`, `compact`, or container-responsive `auto` for `layout`.
|
|
240
|
+
`urlSync` synchronizes search, tags, sorting, and pagination with the URL and browser history.
|
|
241
|
+
For Next.js Pages Router, pass `createNextPagesRouterAdapter(router)` as `urlAdapter`.
|
|
242
|
+
|
|
243
|
+
With `reorderable`, collections without an explicit sort default to manual order. The selector also supports date sorting; reorder handles appear only in manual order without `pinnedFirst`. Reordering replaces only the positions occupied by visible items, preserving other pages and hidden items. Arrow keys save immediately, Escape releases the grabbed item, and the existing five-second Undo restores committed order.
|
|
244
|
+
|
|
245
|
+
Pass `onManualSort` to a standalone `KeepSortSelect` to enable `value="manual"`. Its existing `onValueChange(value, sort)` callback still handles date sorts only. Manual-order URLs and Saved Views omit `sort`. Enabled URL synchronization takes priority; omitted `sort` clears the previous date sort. Ordinary collections fall back to newest update first. Unchanged URLs do not navigate; history defaults to push, with replace available through `urlSync={{ history: "replace" }}`.
|
|
246
|
+
|
|
247
|
+
Unassigned Saved Views use `organization.collection="unassigned"`. Host-supplied function filters remain unserializable. `revealRequest` clears local search, tag, organization, and date constraints, but returns `excluded` for items rejected by the host's fixed `targetType` or `filter`. `creatable` and `slots.toolbarEnd` can be combined.
|
|
248
|
+
|
|
249
|
+
### Revisit articles and links
|
|
250
|
+
|
|
251
|
+
The reading presentation is opt-in; existing defaults are preserved.
|
|
252
|
+
|
|
253
|
+
Default `linkTarget="card"` links ordinary media and static content, placing tags, actions, and edit forms outside the link. Custom images and entire `children` / `render` bodies are no longer automatically wrapped. Compound `Title` supplies a title link. Use `KeepItemCard.Link` to explicitly wrap non-interactive content in custom layouts. It shares the root URL, router `linkComponent`, external-link attributes, availability, and `trackOpen` / `onOpen`. Nested `Title` is static, and `Content` omits automatic tags. Keep custom buttons and forms outside the link as well.
|
|
216
254
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
255
|
+
```tsx
|
|
256
|
+
<keep.Collection
|
|
257
|
+
layout="list"
|
|
258
|
+
query={{ sort: { by: "savedAt", direction: "desc" }, pinnedFirst: true }}
|
|
259
|
+
features={{ bulkActions: true, pin: true, archive: true }}
|
|
260
|
+
bulkActionsVariant="inline"
|
|
261
|
+
itemCardProps={{ presentation: "reading", href: (item) => item.meta.url, trackOpen: true }}
|
|
262
|
+
/>
|
|
220
263
|
```
|
|
221
|
-
Enable only the standard card features you need with `features={{ pin: true, archive: true, tags: false }}`. `pin` and `archive` toggle card action buttons, while `tags` controls tag display inside cards. Tag filtering remains independently controlled by `tagFilter`, tag editing by `KeepTagEditor`, and explicit `itemCardProps` values take precedence over `features`.
|
|
222
|
-
`KeepCollection` renders the current search and tag filters as `KeepActiveFiltersSummary` chips with individual removal and a “Clear all filters” action. Replace that area with the `activeFilters` slot. Default `KeepList` / `KeepCollection` output distinguishes `empty-storage` from `empty-filtered`; the filtered state includes a reset button when `onClearFilters` is provided.
|
|
223
|
-
Set `toolbarLayout="grouped"` and `toolbarVariant="panel"` to render host `slots.toolbarStart` / `slots.toolbarEnd`, query controls, and filters as localized `role="group"` regions. The query and filter groups stack their controls at narrow widths.
|
|
224
|
-
|
|
225
|
-
The opt-in theme adds neutral borders, surfaces, shadows, focus treatment, and decorative action icons without changing accessible names. Regular remove, bulk-delete, and stale-prune actions use a subtle red outline and text with a light hover surface; solid red is reserved for error states that need confirmation. Target individual controls with `data-keep-action`, or override `--keep-icon-size`, `--keep-control-gap`, `--keep-shadow`, `--keep-success`, and `--keep-warning`. Consumers that omit the CSS keep the headless markup, and `KeepButton icons` continues to take precedence over the built-in icon.
|
|
226
|
-
`KeepItemCard` accepts `href`, `onOpen`, `linkTarget`, and `linkComponent` for detail-page navigation. Links are disabled for unavailable `status` values such as private or expired. `KeepBackup` provides JSON export, merge/replace import, result counts, and quota-error messaging.
|
|
227
|
-
`KeepTourBar` (aliased as `KeepNavigator`) provides progress, previous/next, and return-to-list actions through URLs or callbacks. Inject host routing with `getItemHref`, `getBackHref`, and `onNavigate`. Adjacent item titles are previewed below the navigation labels; customize them with `getItemTitle`. Set `keyboardShortcuts` for J/K or ]/[ tour navigation, or use `useKeepTourShortcuts` for custom bindings. `KeepReorderableList` supports drag and keyboard reordering and shows the active insertion position; `KeepCollection reorderable` includes that path and standard undo without a slot replacement.
|
|
228
|
-
`KeepTourProvider` / `useKeepTour` manage a session-scoped tour, and `KeepFloatingTour` renders controls in a body portal so the host layout needs no reserved space. Start with `start({ itemIds })`, configure `position`, `offset`, `zIndex`, and routing callbacks. Same-tab state resumes from `sessionStorage`; set `tour={{ sessionKey }}` on `KeepKitProvider` to namespace it.
|
|
229
|
-
`KeepShortcutHint` renders semantic `<kbd>` badges. `KeepTourBar showShortcutHint` displays the previous/next keys, while `KeepNoteEditor showShortcutHint` displays `Ctrl+Enter` in the save button. `mergeProps` / `createSlot` compose className, style, ARIA, events, and child/parent refs for `asChild` slots; `composeRefs` combines callback and object refs. Filter chips restore focus to an adjacent chip after removal and support ArrowLeft / ArrowRight navigation.
|
|
230
|
-
`KeepFloatingTour` is a fixed portal-rendered tour control that does not consume page layout space. Use `KeepTourProvider` / `useKeepTour` to start an ordered session with `start({ itemIds })` and configure host routing with `getItemHref`, `getBackHref`, or `onNavigate`.
|
|
231
|
-
Cards rendered by `KeepList` and `KeepCollection` highlight case-insensitive search matches with `<mark class="keep-highlight" data-highlight="true">`. Use `highlightQuery` on a standalone `KeepItemCard` or `KeepHighlight` for arbitrary text. `KeepItemCard.Media` exposes its loading state through `data-media-status` and replaces failed images with `fallback` or the built-in SVG placeholder.
|
|
232
|
-
The theme defines WCAG-oriented `--keep-highlight-bg` / `--keep-highlight-fg` pairs for light and dark modes, clamps titles to two lines and memo previews to three, and reserves a stable media aspect ratio. `KeepItemStatusBadge` combines visible status text with check, clock, ban, or lock SVG icons; import `@keepkit/ui/styles/status.css` when using the status styles independently.
|
|
233
|
-
External detail URLs receive `target="_blank"` and `rel="noreferrer"` defaults. Unavailable cards expose `aria-disabled="true"` and normalized `data-item-status` values, and the sync recovery dialog compares local and remote updated dates and notes side by side.
|
|
234
|
-
Choose `cardVariant="outlined" | "elevated" | "filled"` for card surfaces. Override `--keep-card-border` / `--keep-card-shadow` and `--keep-surface-border` / `--keep-surface-background` independently for cards, toolbars, and workspace regions.
|
|
235
|
-
|
|
236
|
-
During initial loading, `KeepList` renders six layout-matched `KeepItemCardSkeleton` placeholders by default. Change the count with `loadingCount`, or replace them with the existing `loading` prop or its `renderLoading` alias. `layout="auto"` responds to the available container width rather than viewport width, so embedded sidebars and dialogs collapse to one column. Skeleton pulses become static under `prefers-reduced-motion`.
|
|
237
|
-
Card groups use Roving Tabindex, so a focused card can move to adjacent cards with arrow keys or jump with Home and End.
|
|
238
|
-
|
|
239
|
-
Use the compound parts to rearrange only the card regions you own while preserving image alt text, linked headings, the labelled tag list, and action state:
|
|
240
264
|
|
|
241
265
|
```tsx
|
|
242
|
-
<KeepItemCard item={item} href={
|
|
243
|
-
<KeepItemCard.
|
|
244
|
-
|
|
245
|
-
<KeepItemCard.
|
|
246
|
-
|
|
247
|
-
|
|
266
|
+
<KeepItemCard item={item} href={item.meta.url} trackOpen>
|
|
267
|
+
<KeepItemCard.Link>
|
|
268
|
+
<KeepItemCard.Media />
|
|
269
|
+
<KeepItemCard.Content />
|
|
270
|
+
</KeepItemCard.Link>
|
|
271
|
+
<KeepItemCard.Tags />
|
|
248
272
|
<KeepItemCard.Actions />
|
|
249
273
|
</KeepItemCard>
|
|
250
274
|
```
|
|
251
275
|
|
|
252
|
-
`
|
|
276
|
+
`presentation="reading"` shows the title, URL source, collection name, note, tags, and save/open information. Images appear only when supplied through `getImageProps`. It hides the save toggle and shows editing, notes, and activity by default; existing visibility flags override these defaults. Supply `href` and `trackOpen` explicitly. Editing uses 300ms autosave and Done, retaining the draft on failure.
|
|
253
277
|
|
|
254
|
-
|
|
255
|
-
const onFeedback = useKeepToastFeedback(toast);
|
|
256
|
-
<KeepKitProvider storage={storage} onFeedback={onFeedback}>{children}</KeepKitProvider>;
|
|
257
|
-
```
|
|
278
|
+
`bulkActionsVariant="inline"` selects items on their article rows. Select-all targets only the current page; changes to search, filters, page, or view clear selection. Failed bulk operations retain selection. The default `separate` preserves the existing selection list.
|
|
258
279
|
|
|
259
|
-
|
|
260
|
-
Phase 4 adds `KeepItemStatusBadge`, `KeepStaleNotice`, `KeepPruneStaleButton`, `KeepSyncStatusBanner`, and `KeepSyncRecoveryDialog` for unavailable items, sync failures, conflict resolution, and backup recovery. Import `@keepkit/ui/theme.css` or `@keepkit/ui/tailwind.css` for the opt-in theme layer.
|
|
280
|
+
For custom rows, pass `KeepListSelection` (`selectedIds: readonly string[]`, `onSelectedIdsChange`, optional `disabled`) to `KeepList.selection`. The third argument of `KeepList` and `KeepCollection`'s `renderItem(item, state, selection?)` is `KeepItemSelection` (`checked`, `onCheckedChange`, optional `disabled`), ready to spread onto `KeepItemCheckbox`. Existing two-argument callbacks still work.
|
|
261
281
|
|
|
262
|
-
|
|
282
|
+
`KeepBulkActions` and `KeepCollection` default `confirmRemoval` to false. Enable it to show the count and confirm/cancel controls before removal. Confirmation freezes all selected IDs, including selections outside the page, and cancels when selection, scope, or query changes. Failures can be retried; successful removal retains existing Undo. Render props expose `removalConfirmation`, `requestRemoval()`, `confirmRemoval()`, and `cancelRemoval()`.
|
|
263
283
|
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
@import "tailwindcss";
|
|
267
|
-
@import "@keepkit/ui/tailwind.css";
|
|
284
|
+
```tsx
|
|
285
|
+
<keep.Collection confirmRemoval features={{ bulkActions: true }} />
|
|
268
286
|
```
|
|
269
287
|
|
|
288
|
+
### Compare and restore fallback branches
|
|
289
|
+
|
|
290
|
+
`KeepFallbackRecovery` works independently of KeepProvider and accepts the target adapter's `recovery` explicitly. Display and inspection do not write. Select the source for conflicting records, review dependent membership changes, then apply. Unresolved conflicts or inconsistent relationships prevent applying. Changed data requires another inspection. A pending projection means the repair is already saved: retry it instead of submitting it again.
|
|
291
|
+
|
|
270
292
|
```tsx
|
|
271
|
-
import {
|
|
293
|
+
import { createBrowserStorageAdapter, KeepFallbackRecovery, KeepUiProvider } from "@keepkit/ui";
|
|
294
|
+
|
|
295
|
+
const storage = createBrowserStorageAdapter({ key: "my-app:items", scope: { userId: "alice" } });
|
|
272
296
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
297
|
+
function RecoveryScreen() {
|
|
298
|
+
return storage.recovery ? (
|
|
299
|
+
<KeepUiProvider locale="en">
|
|
300
|
+
<KeepFallbackRecovery recovery={storage.recovery} />
|
|
301
|
+
</KeepUiProvider>
|
|
302
|
+
) : null;
|
|
303
|
+
}
|
|
276
304
|
```
|
|
277
305
|
|
|
278
|
-
|
|
306
|
+
A `SyncStorageAdapter` exposes status only. Repair through a standalone local adapter before starting sync. Pre-repair backups are not automatically deleted. Refresh all older tabs when adopting this journal, and check the storage limits in the [Core guide](../keepkit/README.md).
|
|
279
307
|
|
|
280
|
-
|
|
308
|
+
Use `KeepQuickEditor.closeLabel` to customize the completion button. Manual saving with `debounceMs={0}` is preserved; completion and Escape close only after successful saving. Standalone editors do not trap Tab.
|
|
281
309
|
|
|
282
|
-
|
|
310
|
+
### Components by task
|
|
283
311
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
getImageProps={(entry) => ({ src: entry.meta.image, alt: entry.meta.title })}
|
|
296
|
-
/>
|
|
297
|
-
</KeepThemeProvider>;
|
|
298
|
-
```
|
|
312
|
+
| Task | API |
|
|
313
|
+
| --- | --- |
|
|
314
|
+
| Inbox and saved queries | `keep.Inbox`, `keep.SavedViews` |
|
|
315
|
+
| Collection management | `keep.CollectionManager` |
|
|
316
|
+
| Complete screen | `keep.Workspace` with `basic` / `standard` / `management` / `sync` presets |
|
|
317
|
+
| Notes, tags, and editing after saving | `KeepNoteEditor`, `KeepTagEditor`, `KeepSavePopover`, `KeepQuickEditor` |
|
|
318
|
+
| Rediscovery, tours, and ordering | `KeepRediscoveryPanel`, `KeepTourBar`, `KeepFloatingTour`, `KeepReorderableList` |
|
|
319
|
+
| Undo, backup, availability, and sync | `KeepUndo`, `keep.Backup`, `KeepItemStatusBadge`, `KeepSyncStatusBanner`, `KeepSyncRecoveryDialog` |
|
|
320
|
+
|
|
321
|
+
Place components under the same provider. Use `renderItem`, slots, or render props for custom layouts.
|
|
322
|
+
Rearrange card regions through `KeepItemCard.Link` / `Media` / `Content` / `Title` / `Tags` / `Actions`.
|
|
299
323
|
|
|
300
|
-
|
|
324
|
+
### Theme and accessibility
|
|
301
325
|
|
|
302
|
-
|
|
303
|
-
|
|
326
|
+
Import `@keepkit/ui/theme.css` for the standard theme. For Tailwind CSS v4 or shadcn, add these global CSS imports:
|
|
327
|
+
|
|
328
|
+
```css
|
|
329
|
+
@import "tailwindcss";
|
|
330
|
+
@import "@keepkit/ui/tailwind.css";
|
|
331
|
+
```
|
|
304
332
|
|
|
305
|
-
|
|
333
|
+
Configure the provider with `theme="ocean"`, `mode="light" | "dark" | "system"`, `density`, and `radius`.
|
|
334
|
+
Override `--keep-*` variables as needed; the Tailwind integration inherits host color variables.
|
|
306
335
|
|
|
307
|
-
|
|
336
|
+
Controls support keyboard interaction, ARIA labels, and live announcements. Use `data-state`, `data-loading`, and `data-disabled` in custom CSS.
|
|
337
|
+
Card lists support arrow keys, Home, and End. Cards record opens only when `trackOpen` is enabled.
|
|
308
338
|
|
|
309
|
-
|
|
339
|
+
### Persistence and sync
|
|
310
340
|
|
|
311
|
-
|
|
341
|
+
Browser storage prefers IndexedDB with a localStorage fallback. Cross-device sync needs your app's driver, authentication, and server APIs.
|
|
342
|
+
Backups include saved items, collection definitions, and memberships; history, viewing records, and progress are excluded.
|
|
343
|
+
**Replace imports overwrite existing data and do not roll back.**
|
|
312
344
|
|
|
313
|
-
|
|
345
|
+
See the [Core README](../keepkit/README.md) for persistence contracts and the [repository README](../../README.md) for demos and Next.js examples.
|