@keepkit/ui 0.10.0 → 0.11.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
@@ -57,6 +57,8 @@ function SavedArticles() {
57
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
58
  `KeepItemCard`は`href`、`onOpen`、`linkTarget`、`linkComponent`に対応し、保存アイテムから詳細ページへ遷移できます。非公開・期限切れ等の`status`を持つアイテムは自動的にリンクを無効化します。`KeepBackup`はJSONのエクスポート、merge / replaceインポート、結果件数、容量エラー表示を提供します。
59
59
 
60
+ v0.11.0では`KeepCollection urlSync layout="list" | "grid" | "compact"`、`KeepBulkActions selectionScope="page" | "query" | "all"`、`KeepUndo`を利用できます。`createNextPagesRouterAdapter`はNext.js Pages Router用の注入adapterです。`locale`は日本語・英語・韓国語・中国語に対応し、`labels`で上書きできます。
61
+
60
62
  一覧のqueryは次の形式に統一されています。
61
63
 
62
64
  ```tsx
@@ -107,6 +109,8 @@ function SavedArticles() {
107
109
  `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
110
  `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.
109
111
 
112
+ In v0.11.0, use `KeepCollection urlSync` with `layout="list" | "grid" | "compact"`, `KeepBulkActions selectionScope="page" | "query" | "all"`, and `KeepUndo`. `createNextPagesRouterAdapter` is the injected adapter for Next.js Pages Router. `locale` includes Japanese, English, Korean, and Chinese dictionaries; `labels` overrides individual entries.
113
+
110
114
  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.
111
115
 
112
116
  Framework-neutral APIs remain available from `@keepkit/core/core`, low-level React bindings from `@keepkit/core/react`, and storage adapters from `@keepkit/core/storage`.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { HTMLAttributes, ReactNode, ImgHTMLAttributes, ComponentType, MouseEvent, HTMLAttributeAnchorTarget, InputHTMLAttributes, FormHTMLAttributes, SelectHTMLAttributes } from 'react';
3
- import { ImportItemsResult, KeepListQuery, KeepItem, KeepItemInput } from '@keepkit/core/core';
4
- export { KeepItem, KeepItemInput, KeepListQuery, KeepSyncStatus } from '@keepkit/core/core';
3
+ import { ImportItemsResult, KeepListQuery, KeepItem, KeepUrlSyncOptions, KeepItemInput } from '@keepkit/core/core';
4
+ export { KeepItem, KeepItemInput, KeepListQuery, KeepScope, KeepSyncStatus, KeepUndoState, KeepUrlSyncOptions } from '@keepkit/core/core';
5
5
  import { KeepButtonProps as KeepButtonProps$1, UseKeepListResult, KeepErrorBoundaryProps, CreateKeepKitOptions as CreateKeepKitOptions$1, KeepProviderProps, useKeepContext, useKeepItem, useKeepList, KeepShortcutOptions } from '@keepkit/core/react';
6
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';
@@ -38,7 +38,10 @@ type KeepBulkActionsState<TMeta = Record<string, unknown>> = {
38
38
  remove: () => Promise<void>;
39
39
  updateTags: () => Promise<void>;
40
40
  isMutating: boolean;
41
+ selectionScope: KeepSelectionScope;
42
+ setSelectionScope: (scope: KeepSelectionScope) => void;
41
43
  };
44
+ type KeepSelectionScope = "page" | "query" | "all";
42
45
  /** Returns whether every visible item is selected. Empty lists are never all selected. */
43
46
  declare function isAllSelected<TMeta>(items: readonly Pick<KeepItem<TMeta>, "id">[], selectedIds: readonly string[]): boolean;
44
47
  /** Toggles only the visible items, preserving selections outside the current query or page. */
@@ -50,11 +53,13 @@ type KeepBulkActionsProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes
50
53
  onSelectedIdsChange?: (ids: string[]) => void;
51
54
  renderItem?: (item: KeepItem<TMeta>, selected: boolean) => ReactNode;
52
55
  onCompleted?: (action: "remove" | "tags", ids: string[]) => void;
56
+ selectionScope?: KeepSelectionScope;
57
+ onSelectionScopeChange?: (scope: KeepSelectionScope) => void;
53
58
  render?: RenderProp<KeepBulkActionsState<TMeta>>;
54
59
  children?: ReactNode | RenderProp<KeepBulkActionsState<TMeta>>;
55
60
  };
56
61
  /** Selects visible items and performs one storage operation for the whole selection. */
57
- declare function KeepBulkActions<TMeta = Record<string, unknown>>({ query, selectedIds: controlledSelectedIds, defaultSelectedIds, onSelectedIdsChange, renderItem, onCompleted, render, children, ...props }: KeepBulkActionsProps<TMeta>): react.JSX.Element;
62
+ declare function KeepBulkActions<TMeta = Record<string, unknown>>({ query, selectedIds: controlledSelectedIds, defaultSelectedIds, onSelectedIdsChange, renderItem, onCompleted, selectionScope: controlledScope, onSelectionScopeChange, render, children, ...props }: KeepBulkActionsProps<TMeta>): react.JSX.Element;
58
63
 
59
64
  type KeepButtonProps<TMeta = Record<string, unknown>> = KeepButtonProps$1<TMeta> & {
60
65
  labels?: KeepButtonLabels;
@@ -88,6 +93,8 @@ type KeepItemCardProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HT
88
93
  getImageProps?: (item: KeepItem<TMeta>, title: ReactNode) => KeepImageProps | undefined;
89
94
  imageComponent?: ComponentType<KeepImageProps>;
90
95
  renderImage?: (props: KeepImageProps, item: KeepItem<TMeta>) => ReactNode;
96
+ renderTags?: (tags: string[], item: KeepItem<TMeta>) => ReactNode;
97
+ showTags?: boolean;
91
98
  imageAlt?: string;
92
99
  render?: RenderProp<KeepItemCardState<TMeta>>;
93
100
  children?: ReactNode | RenderProp<KeepItemCardState<TMeta>>;
@@ -105,7 +112,7 @@ type KeepItemCardProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HT
105
112
  linkRel?: string;
106
113
  };
107
114
  /** A low-dependency item presentation primitive. The default markup can be replaced with render props. */
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>>;
115
+ declare function KeepItemCard<TMeta = Record<string, unknown>>({ item, title, getTitle, getImageProps, imageComponent: ImageComponent, renderImage, renderTags, showTags, 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>>;
109
116
 
110
117
  type KeepListState<TMeta = Record<string, unknown>> = UseKeepListResult<TMeta>;
111
118
  type KeepListProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, "children"> & {
@@ -116,6 +123,7 @@ type KeepListProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLEl
116
123
  empty?: ReactNode | RenderProp<KeepListState<TMeta>>;
117
124
  error?: ReactNode | RenderProp<KeepListState<TMeta>>;
118
125
  itemCardProps?: Omit<KeepItemCardProps<TMeta>, "item" | "children" | "render">;
126
+ layout?: KeepLayoutPreset;
119
127
  asChild?: boolean;
120
128
  fallback?: KeepErrorBoundaryProps["fallback"];
121
129
  onBoundaryError?: KeepErrorBoundaryProps["onError"];
@@ -124,10 +132,44 @@ type KeepListProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLEl
124
132
  /** A list primitive with built-in loading, empty, error, and removal states. */
125
133
  declare function KeepList<TMeta = Record<string, unknown>>(props: KeepListProps<TMeta>): react.JSX.Element;
126
134
 
135
+ type KeepUrlAdapter = {
136
+ getUrl: () => string;
137
+ subscribe?: (listener: () => void) => () => void;
138
+ navigate: (url: string, mode: "replace" | "push") => void;
139
+ };
140
+ type KeepPagesRouterLike = {
141
+ asPath?: string;
142
+ push: (url: string, as?: string, options?: {
143
+ shallow?: boolean;
144
+ }) => Promise<boolean> | boolean;
145
+ replace: (url: string, as?: string, options?: {
146
+ shallow?: boolean;
147
+ }) => Promise<boolean> | boolean;
148
+ events?: {
149
+ on: (event: string, listener: () => void) => void;
150
+ off: (event: string, listener: () => void) => void;
151
+ };
152
+ };
153
+ type KeepUrlSyncProps<TMeta = Record<string, unknown>> = {
154
+ enabled?: boolean;
155
+ query: KeepListQuery<TMeta>;
156
+ onQueryChange: (query: KeepListQuery<TMeta> | ((previous: KeepListQuery<TMeta>) => KeepListQuery<TMeta>)) => void;
157
+ options?: KeepUrlSyncOptions;
158
+ adapter?: KeepUrlAdapter;
159
+ };
160
+ /** Adapter for Next.js Pages Router. It intentionally uses structural typing and has no Next dependency. */
161
+ declare function createNextPagesRouterAdapter(router: KeepPagesRouterLike): KeepUrlAdapter;
162
+ /** Synchronizes collection filters with browser history and supports back/forward restoration. */
163
+ declare function useKeepUrlSync<TMeta = Record<string, unknown>>({ enabled, query, onQueryChange, options, adapter: providedAdapter, }: KeepUrlSyncProps<TMeta>): void;
164
+
127
165
  type KeepCollectionFeature = "search" | "sort" | "pagination" | "tagFilter" | "bulkActions";
166
+ type KeepLayoutPreset = "list" | "grid" | "compact";
128
167
  type KeepCollectionProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<HTMLElement>, "children"> & {
129
168
  query?: KeepListQuery<TMeta>;
130
169
  pageSize?: number;
170
+ layout?: KeepLayoutPreset;
171
+ urlSync?: boolean | KeepUrlSyncOptions;
172
+ urlAdapter?: KeepUrlAdapter;
131
173
  features?: Partial<Record<KeepCollectionFeature, boolean>>;
132
174
  renderItem?: (item: KeepItem<TMeta>, state: KeepListState<TMeta>) => ReactNode;
133
175
  itemCardProps?: Omit<KeepItemCardProps<TMeta>, "item" | "children" | "render">;
@@ -150,6 +192,13 @@ type KeepItemCheckboxProps<TMeta = Record<string, unknown>> = Omit<InputHTMLAttr
150
192
  /** A reusable accessible selection checkbox for a saved item. */
151
193
  declare function KeepItemCheckbox<TMeta = Record<string, unknown>>({ item, checked, label, onCheckedChange, "aria-label": ariaLabel, ...props }: KeepItemCheckboxProps<TMeta>): react.JSX.Element;
152
194
 
195
+ type KeepLayoutProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
196
+ layout?: KeepLayoutPreset;
197
+ children?: ReactNode;
198
+ };
199
+ /** A CSS-free layout wrapper with responsive grid presets and data attributes for host styling. */
200
+ declare function KeepLayout({ layout, children, style, ...props }: KeepLayoutProps): react.JSX.Element;
201
+
153
202
  type KeepNoteEditorState<TMeta = Record<string, unknown>> = {
154
203
  item: KeepItem<TMeta>;
155
204
  note: string;
@@ -213,6 +262,13 @@ type KeepTagFilterProps<TMeta = Record<string, unknown>> = Omit<HTMLAttributes<H
213
262
  /** An ARIA button group for tag filtering; consumers can connect value to a collection query. */
214
263
  declare function KeepTagFilter<TMeta = Record<string, unknown>>({ query, value: controlledValue, defaultValue, onChange, onValueChange, allLabel, ariaLabel, renderTag, render, children, asChild, className, ...rootProps }: KeepTagFilterProps<TMeta>): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
215
264
 
265
+ type KeepUndoProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
266
+ children?: ReactNode;
267
+ label?: ReactNode;
268
+ };
269
+ /** Presents the short-lived undo action created by removeWithUndo/removeBatchWithUndo. */
270
+ declare function KeepUndo({ children, label, ...props }: KeepUndoProps): react.JSX.Element | null;
271
+
216
272
  type KeepSearchInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "defaultValue" | "onChange"> & {
217
273
  value?: string;
218
274
  defaultValue?: string;
@@ -280,11 +336,12 @@ declare function KeepAnnouncements<TMeta = Record<string, unknown>>({ messages,
280
336
  /** Singular alias for applications that mount one announcer explicitly. */
281
337
  declare const KeepAnnouncer: typeof KeepAnnouncements;
282
338
 
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";
339
+ type KeepUiLabelKey = "save" | "saved" | "remove" | "loading" | "saving" | "syncing" | "error" | "allTags" | "tags" | "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" | "undo" | "undoAvailable" | "selectionScope" | "currentPage" | "searchResults" | "allItems" | "statusAvailable" | "noteSavedMessage" | "exportData" | "importData" | "importMode" | "merge" | "replace" | "importedCount" | "failedCount" | "storageQuotaError" | "statusExpired" | "statusRemoved" | "statusDeleted" | "statusPrivate" | "statusUnknown";
284
340
  type KeepUiLabels = Partial<Record<KeepUiLabelKey, string>>;
285
341
  type KeepUiLabelContext = {
286
342
  locale?: string;
287
343
  labels: Readonly<Record<KeepUiLabelKey, string>>;
344
+ customLabels?: KeepUiLabels;
288
345
  labelResolver?: (key: KeepUiLabelKey, context: {
289
346
  locale?: string;
290
347
  }) => string | undefined;
@@ -298,6 +355,7 @@ type KeepUiProviderProps = {
298
355
  /** Provides one locale-aware label source to every UI primitive. */
299
356
  declare function KeepUiProvider({ labels, locale, labelResolver, children }: KeepUiProviderProps): react.JSX.Element;
300
357
  declare function useKeepUiLabels(): KeepUiLabelContext;
358
+ declare function getKeepLocaleLabels(locale?: string): KeepUiLabels;
301
359
 
302
360
  type KeepKitProviderProps<TMeta = Record<string, unknown>> = Omit<KeepProviderProps<TMeta>, "children"> & Omit<KeepUiProviderProps, "children"> & {
303
361
  children?: ReactNode;
@@ -322,4 +380,4 @@ type KeepKit<TMeta = Record<string, unknown>> = {
322
380
  /** Create one typed application API for the core and standard UI layer. */
323
381
  declare function createKeepKit<TMeta = Record<string, unknown>>(options?: CreateKeepKitOptions<TMeta>): KeepKit<TMeta>;
324
382
 
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 };
383
+ 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, KeepLayout, type KeepLayoutPreset, type KeepLayoutProps, KeepList, type KeepListProps, type KeepListState, KeepNoteEditor, type KeepNoteEditorProps, type KeepNoteEditorState, type KeepPagesRouterLike, KeepPagination, type KeepPaginationProps, type KeepPaginationState, KeepSearchInput, type KeepSearchInputProps, type KeepSelectionScope, 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, KeepUndo, type KeepUndoProps, type KeepUrlAdapter, type RenderProp, createKeepKit, createNextPagesRouterAdapter, getKeepLocaleLabels, isAllSelected, toggleSelectAll, useKeepUiLabels, useKeepUrlSync };