@keepkit/ui 0.8.0 → 0.10.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 CHANGED
@@ -10,6 +10,28 @@ Reactアプリケーション向けの標準利用パッケージです。`@keep
10
10
  pnpm add @keepkit/ui
11
11
  ```
12
12
 
13
+ ## Minimal Starter Recipe
14
+
15
+ ```tsx
16
+ import { createBrowserStorageAdapter, createKeepKit } from "@keepkit/ui";
17
+
18
+ type Meta = { title: string; url: string };
19
+ const keep = createKeepKit<Meta>({
20
+ storage: createBrowserStorageAdapter({ key: "demo:keeps" }),
21
+ });
22
+
23
+ export function SavedArticle({ article }: { article: Meta & { id: string } }) {
24
+ return (
25
+ <keep.Provider fallback={<p>Saved items are temporarily unavailable.</p>}>
26
+ <keep.Button item={{ id: article.id, targetType: "article", meta: article }} />
27
+ <keep.Collection query={{ targetType: "article" }} />
28
+ </keep.Provider>
29
+ );
30
+ }
31
+ ```
32
+
33
+ Every primitive exposes `data-state`; pending operations expose `data-loading="true"`, and disabled controls expose `data-disabled="true"`. Use these attributes from host CSS or Tailwind data variants. `KeepCollection` and `KeepList` accept `fallback`, `onBoundaryError`, and `boundaryResetKey` for local render-error isolation.
34
+
13
35
  ```tsx
14
36
  import { createBrowserStorageAdapter, createKeepKit } from "@keepkit/ui";
15
37
 
@@ -33,6 +55,7 @@ function SavedArticles() {
33
55
  ```
34
56
 
35
57
  `keep.Collection`は検索、ソート、ページング、loading / empty / error、ARIA live通知を標準で提供します。検索は既定で300msデバウンスされます。`features={{ tagFilter: true, bulkActions: true }}`でタグフィルターと一括操作も有効にできます。個別の`KeepList`、`KeepSearchInput`、`KeepSortSelect`、`KeepPagination`、`KeepItemCheckbox`、`KeepTagEditor`などは高度なレイアウト用に利用できます。`KeepBulkActions`はrender propsで操作UIを差し替えられ、`isAllSelected` / `toggleSelectAll`で表示中アイテムを一括操作できます。`KeepNoteEditor`は既定300msのデバウンス保存に対応し、`debounceMs={0}`でフォーム送信のみへ戻せます。通知領域だけを明示的に置く場合は`KeepAnnouncer`(`KeepAnnouncements`のalias)を使えます。
58
+ `KeepItemCard`は`href`、`onOpen`、`linkTarget`、`linkComponent`に対応し、保存アイテムから詳細ページへ遷移できます。非公開・期限切れ等の`status`を持つアイテムは自動的にリンクを無効化します。`KeepBackup`はJSONのエクスポート、merge / replaceインポート、結果件数、容量エラー表示を提供します。
36
59
 
37
60
  一覧のqueryは次の形式に統一されています。
38
61
 
@@ -82,6 +105,7 @@ function SavedArticles() {
82
105
  ```
83
106
 
84
107
  `keep.Collection` includes search, sorting, pagination, loading/empty/error states, and polite live announcements. Search is debounced by 300ms by default. Enable `features={{ tagFilter: true, bulkActions: true }}` for tag filtering and bulk operations. Use the individual `KeepList`, `KeepSearchInput`, `KeepSortSelect`, `KeepPagination`, `KeepItemCheckbox`, and `KeepTagEditor` primitives when you need a custom layout. `KeepBulkActions` supports render props and exposes `isAllSelected` / `toggleSelectAll` for visible-item selection. `KeepNoteEditor` auto-saves dirty notes after 300ms by default; set `debounceMs={0}` to use form submission only. Mount `KeepAnnouncer` (`KeepAnnouncements` alias) when you need the live region explicitly.
108
+ `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.
85
109
 
86
110
  Collection queries use one canonical shape: `targetType`, `tags`, `search`, `sort`, `pagination`, `filter`, and `savedBetween`. Saved item inputs contain only `id`, `meta`, `targetType`, `note`, and `tags`; KeepKit owns persistence timestamps.
87
111
 
package/dist/index.d.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, HTMLAttributes, ImgHTMLAttributes, ComponentType, InputHTMLAttributes, FormHTMLAttributes, SelectHTMLAttributes } from 'react';
3
- import { KeepListQuery, KeepItem, KeepItemInput } from '@keepkit/core/core';
2
+ import { HTMLAttributes, ReactNode, ImgHTMLAttributes, ComponentType, MouseEvent, HTMLAttributeAnchorTarget, InputHTMLAttributes, FormHTMLAttributes, SelectHTMLAttributes } from 'react';
3
+ import { ImportItemsResult, KeepListQuery, KeepItem, KeepItemInput } from '@keepkit/core/core';
4
4
  export { KeepItem, KeepItemInput, KeepListQuery, KeepSyncStatus } from '@keepkit/core/core';
5
- import { KeepButtonProps as KeepButtonProps$1, UseKeepListResult, CreateKeepKitOptions as CreateKeepKitOptions$1, KeepProviderProps, useKeepContext, useKeepItem, useKeepList, KeepShortcutOptions } from '@keepkit/core/react';
6
- export { KeepButtonState, KeepContextValue, KeepProvider, KeepProviderProps, KeepShortcutOptions, useKeepContext, useKeepItem, useKeepList, useKeepShortcut } from '@keepkit/core/react';
5
+ import { KeepButtonProps as KeepButtonProps$1, UseKeepListResult, KeepErrorBoundaryProps, CreateKeepKitOptions as CreateKeepKitOptions$1, KeepProviderProps, useKeepContext, useKeepItem, useKeepList, KeepShortcutOptions } from '@keepkit/core/react';
6
+ export { KeepButtonState, KeepContextValue, KeepErrorBoundary, KeepErrorBoundaryProps, KeepProvider, KeepProviderProps, KeepShortcutOptions, useKeepContext, useKeepItem, useKeepList, useKeepShortcut } from '@keepkit/core/react';
7
7
  export { FallbackStorageAdapter, IndexedDBAdapter, IndexedDBSyncQueueAdapter, LocalStorageAdapter, LocalStorageSyncQueueAdapter, SyncStorageAdapter, createBrowserStorageAdapter, createStorageAdapter } from '@keepkit/core/storage';
8
8
 
9
+ type KeepBackupProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, "children"> & {
10
+ filename?: string;
11
+ onExport?: (data: string) => void;
12
+ onImported?: (result: ImportItemsResult<TMeta>) => void;
13
+ };
14
+ /** Accessible JSON backup controls backed by the current KeepProvider storage. */
15
+ declare function KeepBackup<TMeta = Record<string, unknown>>({ filename, onExport, onImported, ...props }: KeepBackupProps<TMeta>): react.JSX.Element;
16
+
9
17
  type RenderProp<TState> = (state: TState) => ReactNode;
10
18
  type KeepButtonLabels = {
11
19
  saved?: ReactNode;
@@ -60,6 +68,14 @@ type KeepItemCardState<TMeta = Record<string, unknown>> = {
60
68
  isMutating: boolean;
61
69
  error: unknown | null;
62
70
  remove: () => Promise<void>;
71
+ status: KeepItem["status"];
72
+ };
73
+ type KeepItemCardLinkProps = {
74
+ href: string;
75
+ children?: ReactNode;
76
+ target?: HTMLAttributeAnchorTarget;
77
+ rel?: string;
78
+ onClick?: (event: MouseEvent<HTMLElement>) => void;
63
79
  };
64
80
  type KeepImageProps = ImgHTMLAttributes<HTMLImageElement> & {
65
81
  src: string;
@@ -81,9 +97,15 @@ type KeepItemCardProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HT
81
97
  showSaveButton?: boolean;
82
98
  saveButtonLabels?: KeepButtonLabels;
83
99
  asChild?: boolean;
100
+ href?: string | ((item: KeepItem<TMeta>) => string | undefined);
101
+ onOpen?: (item: KeepItem<TMeta>, event: MouseEvent<HTMLElement>) => void;
102
+ linkTarget?: "title" | "card";
103
+ linkComponent?: ComponentType<KeepItemCardLinkProps>;
104
+ linkTargetAttribute?: HTMLAttributeAnchorTarget;
105
+ linkRel?: string;
84
106
  };
85
107
  /** A low-dependency item presentation primitive. The default markup can be replaced with render props. */
86
- declare function KeepItemCard<TMeta = Record<string, unknown>>({ item, title, getTitle, getImageProps, imageComponent: ImageComponent, renderImage, imageAlt, render, children, removeLabel, onRemoveError, onRemoved, showSaveButton, saveButtonLabels, asChild, className, ...rootProps }: KeepItemCardProps<TMeta>): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
108
+ declare function KeepItemCard<TMeta = Record<string, unknown>>({ item, title, getTitle, getImageProps, imageComponent: ImageComponent, renderImage, imageAlt, render, children, removeLabel, onRemoveError, onRemoved, showSaveButton, saveButtonLabels, asChild, href: hrefOption, onOpen, linkTarget, linkComponent: LinkComponent, linkTargetAttribute, linkRel, className, ...rootProps }: KeepItemCardProps<TMeta>): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
87
109
 
88
110
  type KeepListState<TMeta = Record<string, unknown>> = UseKeepListResult<TMeta>;
89
111
  type KeepListProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, "children"> & {
@@ -95,9 +117,12 @@ type KeepListProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLEl
95
117
  error?: ReactNode | RenderProp<KeepListState<TMeta>>;
96
118
  itemCardProps?: Omit<KeepItemCardProps<TMeta>, "item" | "children" | "render">;
97
119
  asChild?: boolean;
120
+ fallback?: KeepErrorBoundaryProps["fallback"];
121
+ onBoundaryError?: KeepErrorBoundaryProps["onError"];
122
+ boundaryResetKey?: unknown;
98
123
  };
99
124
  /** A list primitive with built-in loading, empty, error, and removal states. */
100
- declare function KeepList<TMeta = Record<string, unknown>>({ query, children, renderItem, loading, empty, error: errorContent, itemCardProps, asChild, className, ...rootProps }: KeepListProps<TMeta>): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
125
+ declare function KeepList<TMeta = Record<string, unknown>>(props: KeepListProps<TMeta>): react.JSX.Element;
101
126
 
102
127
  type KeepCollectionFeature = "search" | "sort" | "pagination" | "tagFilter" | "bulkActions";
103
128
  type KeepCollectionProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, "children"> & {
@@ -109,9 +134,12 @@ type KeepCollectionProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<
109
134
  loading?: ReactNode | RenderProp<KeepListState<TMeta>>;
110
135
  empty?: ReactNode | RenderProp<KeepListState<TMeta>>;
111
136
  error?: ReactNode | RenderProp<KeepListState<TMeta>>;
137
+ fallback?: KeepErrorBoundaryProps["fallback"];
138
+ onBoundaryError?: KeepErrorBoundaryProps["onError"];
139
+ boundaryResetKey?: unknown;
112
140
  };
113
141
  /** A batteries-included collection with query controls and accessible status feedback. */
114
- declare function KeepCollection<TMeta = Record<string, unknown>>({ query, pageSize, features, renderItem, itemCardProps, loading, empty, error, className, ...rootProps }: KeepCollectionProps<TMeta>): react.JSX.Element;
142
+ declare function KeepCollection<TMeta = Record<string, unknown>>(props: KeepCollectionProps<TMeta>): react.JSX.Element;
115
143
 
116
144
  type KeepItemCheckboxProps<TMeta = Record<string, unknown>> = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "checked" | "defaultChecked" | "onChange"> & {
117
145
  item: KeepItem<TMeta>;
@@ -252,7 +280,7 @@ declare function KeepAnnouncements<TMeta = Record<string, unknown>>({ messages,
252
280
  /** Singular alias for applications that mount one announcer explicitly. */
253
281
  declare const KeepAnnouncer: typeof KeepAnnouncements;
254
282
 
255
- type KeepUiLabelKey = "save" | "saved" | "remove" | "loading" | "saving" | "syncing" | "error" | "allTags" | "filterTags" | "note" | "saveNote" | "noItems" | "loadingItems" | "errorItems" | "search" | "sort" | "newest" | "oldest" | "savedNewest" | "savedOldest" | "updatedNewest" | "updatedOldest" | "previousPage" | "nextPage" | "pagination" | "page" | "selectItems" | "selectedCount" | "deleteSelected" | "tagsToApply" | "applyTags" | "savedMessage" | "removedMessage" | "noteSavedMessage";
283
+ type KeepUiLabelKey = "save" | "saved" | "remove" | "loading" | "saving" | "syncing" | "error" | "allTags" | "filterTags" | "note" | "saveNote" | "noItems" | "loadingItems" | "errorItems" | "search" | "sort" | "newest" | "oldest" | "savedNewest" | "savedOldest" | "updatedNewest" | "updatedOldest" | "previousPage" | "nextPage" | "pagination" | "page" | "selectItems" | "selectedCount" | "deleteSelected" | "tagsToApply" | "applyTags" | "savedMessage" | "removedMessage" | "noteSavedMessage" | "exportData" | "importData" | "importMode" | "merge" | "replace" | "importedCount" | "failedCount" | "storageQuotaError" | "statusExpired" | "statusRemoved" | "statusDeleted" | "statusPrivate" | "statusUnknown";
256
284
  type KeepUiLabels = Partial<Record<KeepUiLabelKey, string>>;
257
285
  type KeepUiLabelContext = {
258
286
  locale?: string;
@@ -284,6 +312,7 @@ type CreateKeepKitOptions<TMeta = Record<string, unknown>> = CreateKeepKitOption
284
312
  type KeepKit<TMeta = Record<string, unknown>> = {
285
313
  Provider: ComponentType<KeepKitProviderProps<TMeta>>;
286
314
  Button: ComponentType<KeepButtonProps<TMeta>>;
315
+ Backup: ComponentType<KeepBackupProps<TMeta>>;
287
316
  Collection: ComponentType<KeepCollectionProps<TMeta>>;
288
317
  useContext: () => ReturnType<typeof useKeepContext<TMeta>>;
289
318
  useItem: (item?: KeepItemInput<TMeta>) => ReturnType<typeof useKeepItem<TMeta>>;
@@ -293,4 +322,4 @@ type KeepKit<TMeta = Record<string, unknown>> = {
293
322
  /** Create one typed application API for the core and standard UI layer. */
294
323
  declare function createKeepKit<TMeta = Record<string, unknown>>(options?: CreateKeepKitOptions<TMeta>): KeepKit<TMeta>;
295
324
 
296
- export { type CreateKeepKitOptions, KeepAnnouncements, type KeepAnnouncementsProps, KeepAnnouncer, KeepBulkActions, type KeepBulkActionsProps, type KeepBulkActionsState, KeepButton, type KeepButtonLabels, type KeepButtonProps, KeepCollection, type KeepCollectionFeature, type KeepCollectionProps, KeepEmptyState, type KeepEmptyStateProps, type KeepImageProps, KeepItemCard, type KeepItemCardProps, type KeepItemCardState, KeepItemCheckbox, type KeepItemCheckboxProps, type KeepKit, KeepKitProvider, type KeepKitProviderProps, KeepList, type KeepListProps, type KeepListState, KeepNoteEditor, type KeepNoteEditorProps, type KeepNoteEditorState, KeepPagination, type KeepPaginationProps, type KeepPaginationState, KeepSearchInput, type KeepSearchInputProps, KeepSortSelect, type KeepSortSelectProps, type KeepSortValue, KeepStatus, type KeepStatusLabels, type KeepStatusProps, type KeepStatusState, type KeepStatusValue, KeepTagEditor, type KeepTagEditorProps, type KeepTagEditorState, KeepTagFilter, type KeepTagFilterProps, type KeepTagFilterState, type KeepUiLabelContext, type KeepUiLabelKey, type KeepUiLabels, KeepUiProvider, type KeepUiProviderProps, type RenderProp, createKeepKit, isAllSelected, toggleSelectAll, useKeepUiLabels };
325
+ export { type CreateKeepKitOptions, KeepAnnouncements, type KeepAnnouncementsProps, KeepAnnouncer, KeepBackup, type KeepBackupProps, KeepBulkActions, type KeepBulkActionsProps, type KeepBulkActionsState, KeepButton, type KeepButtonLabels, type KeepButtonProps, KeepCollection, type KeepCollectionFeature, type KeepCollectionProps, KeepEmptyState, type KeepEmptyStateProps, type KeepImageProps, KeepItemCard, type KeepItemCardLinkProps, type KeepItemCardProps, type KeepItemCardState, KeepItemCheckbox, type KeepItemCheckboxProps, type KeepKit, KeepKitProvider, type KeepKitProviderProps, KeepList, type KeepListProps, type KeepListState, KeepNoteEditor, type KeepNoteEditorProps, type KeepNoteEditorState, KeepPagination, type KeepPaginationProps, type KeepPaginationState, KeepSearchInput, type KeepSearchInputProps, KeepSortSelect, type KeepSortSelectProps, type KeepSortValue, KeepStatus, type KeepStatusLabels, type KeepStatusProps, type KeepStatusState, type KeepStatusValue, KeepTagEditor, type KeepTagEditorProps, type KeepTagEditorState, KeepTagFilter, type KeepTagFilterProps, type KeepTagFilterState, type KeepUiLabelContext, type KeepUiLabelKey, type KeepUiLabels, KeepUiProvider, type KeepUiProviderProps, type RenderProp, createKeepKit, isAllSelected, toggleSelectAll, useKeepUiLabels };