@valu/block-components 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.
@@ -0,0 +1,203 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import { Icon } from '@wordpress/components';
4
+
5
+ /**
6
+ * Anything `<Icon icon={…}>` from @wordpress/components accepts:
7
+ * a JSX element, a React component, a Dashicon string, an SVG, etc.
8
+ */
9
+ type ContentPickerIcon = ComponentProps<typeof Icon>['icon'];
10
+ /**
11
+ * Map of post-type / taxonomy / `user` slug to an icon renderer.
12
+ *
13
+ * @example
14
+ * icons={{
15
+ * product: myProductIcon, // custom component
16
+ * category: category, // from @wordpress/icons
17
+ * post_tag: tag,
18
+ * }}
19
+ */
20
+ type ContentPickerIconMap = Record<string, ContentPickerIcon>;
21
+ /**
22
+ * What kind of WordPress entity this picker searches.
23
+ * - `post` — posts, pages, or any custom post type
24
+ * - `term` — taxonomy terms
25
+ * - `user` — users
26
+ */
27
+ type ContentKind = 'post' | 'term' | 'user';
28
+ type ContentStatus = 'publish' | 'future' | 'draft' | 'pending' | 'private' | 'trash' | 'auto-draft' | 'inherit';
29
+ type ContentPickerVariant = 'popover' | 'inline';
30
+ /** Reason a picked item can't be displayed normally. */
31
+ type MissingReason = 'deleted' | 'trash';
32
+ /**
33
+ * The shape of a picked / suggested content item.
34
+ *
35
+ * `key` is a stable client-side uuid — use it for React keys so duplicates
36
+ * and reorders don't collide. `id` is the WordPress entity id.
37
+ */
38
+ interface ContentItem {
39
+ key: string;
40
+ id: number;
41
+ type: string;
42
+ kind: ContentKind;
43
+ title: string;
44
+ url?: string;
45
+ status?: ContentStatus;
46
+ thumbnailUrl?: string;
47
+ excerpt?: string;
48
+ /** Raw REST record — lets consumer filters reach beyond the normalized shape. */
49
+ raw?: unknown;
50
+ }
51
+ /** A picked item that has been resolved against the current entity store. */
52
+ interface ResolvedContentItem extends ContentItem {
53
+ missing?: MissingReason;
54
+ }
55
+ /** i18n bag for user-visible strings. All optional — sensible defaults are used. */
56
+ interface ContentPickerLabels {
57
+ input?: string;
58
+ help?: string;
59
+ empty?: string;
60
+ loading?: string;
61
+ selectedSingular?: string;
62
+ selectedPlural?: string;
63
+ limitReached?: string;
64
+ remove?: string;
65
+ moveUp?: string;
66
+ moveDown?: string;
67
+ dragHandle?: string;
68
+ statusDraft?: string;
69
+ statusPending?: string;
70
+ statusPrivate?: string;
71
+ statusFuture?: string;
72
+ statusTrash?: string;
73
+ missing?: string;
74
+ change?: string;
75
+ openSuggestions?: string;
76
+ closeSuggestions?: string;
77
+ resultsCount?: (n: number) => string;
78
+ }
79
+ interface RequestContext {
80
+ query: string;
81
+ page: number;
82
+ kind: ContentKind;
83
+ }
84
+ interface FilterContext {
85
+ query: string;
86
+ kind: ContentKind;
87
+ }
88
+ interface SuggestionRenderState {
89
+ highlighted: boolean;
90
+ selected: boolean;
91
+ }
92
+ interface ContentPickerProps {
93
+ /** Accessible name for the picker. Required. */
94
+ label: string;
95
+ /** Hide the label visually but keep it for screen readers. */
96
+ hideLabelFromVision?: boolean;
97
+ /** Help text shown under the input. */
98
+ help?: string;
99
+ /** Which entity kind to search. @default 'post' */
100
+ kind?: ContentKind;
101
+ /**
102
+ * Which sub-types to search within the kind.
103
+ * For posts: post type slugs, defaults to `['post', 'page']`.
104
+ * For terms: taxonomy slugs, defaults to `['category', 'post_tag']`.
105
+ * Ignored for users.
106
+ */
107
+ types?: string[];
108
+ /** Visual variant. @default 'popover' */
109
+ variant?: ContentPickerVariant;
110
+ /** Controlled value. Omit for uncontrolled. */
111
+ value?: ContentItem[];
112
+ /** Uncontrolled initial value. */
113
+ defaultValue?: ContentItem[];
114
+ /** Called with the full new array whenever the selection changes. */
115
+ onChange?: (items: ContentItem[]) => void;
116
+ /** Maximum items the user can pick. `1` = single-select. @default Infinity */
117
+ maxItems?: number;
118
+ /** Allow drag-to-reorder. @default true when maxItems > 1 */
119
+ orderable?: boolean;
120
+ /** Input placeholder text. */
121
+ placeholder?: string;
122
+ /** Items per page from the REST search endpoint. @default 10 */
123
+ perPage?: number;
124
+ /** Debounce between keystrokes and the search request, in ms. @default 250 */
125
+ inputDelayMs?: number;
126
+ /** In `popover` variant, fetch suggestions immediately when the popover opens. */
127
+ fetchOnOpen?: boolean;
128
+ /** Exclude the current post being edited from the results. @default true */
129
+ excludeCurrentPost?: boolean;
130
+ /** Prevent duplicate items in the selection. @default true */
131
+ uniqueItems?: boolean;
132
+ /** Group suggestions by type heading. @default true when types.length > 1 */
133
+ groupByType?: boolean;
134
+ /**
135
+ * Hide the `All / Post / Page / …` chip row that normally appears under the
136
+ * search input when the picker is configured with more than one `types` entry.
137
+ * @default false
138
+ */
139
+ disableTypeFilter?: boolean;
140
+ /**
141
+ * Show each item's URL (slug) beneath the title in the suggestion list.
142
+ * @default true
143
+ */
144
+ showUrl?: boolean;
145
+ /**
146
+ * Show a small "POST" / "PAGE" / "CATEGORY" pill on each selected row.
147
+ * @default true when the picker is configured with more than one `types` entry
148
+ */
149
+ showTypeBadge?: boolean;
150
+ /**
151
+ * Icon overrides keyed by post-type or taxonomy slug (or `'user'`).
152
+ * By default only users render an icon; all other items render without
153
+ * a leading icon unless they have a featured image thumbnail.
154
+ */
155
+ icons?: ContentPickerIconMap;
156
+ /**
157
+ * Final filter over the normalized suggestion list, after exclusion and
158
+ * dedupe. Replaces the old `searchResultFilter` / `pickedItemFilter`.
159
+ */
160
+ filter?: (items: ContentItem[], ctx: FilterContext) => ContentItem[];
161
+ /**
162
+ * Rewrite the REST path before it is fetched. Use to add custom query
163
+ * params (e.g. `_fields`, meta filters). Replaces the old
164
+ * `queryFilter` / `queryFieldsFilter`.
165
+ */
166
+ request?: (path: string, ctx: RequestContext) => string;
167
+ /** Custom renderer for a suggestion row. */
168
+ renderSuggestion?: (item: ContentItem, state: SuggestionRenderState) => ReactNode;
169
+ /** Custom renderer for a selected-item row. */
170
+ renderSelected?: (item: ResolvedContentItem) => ReactNode;
171
+ /** Custom renderer for a group heading. */
172
+ renderGroupHeading?: (type: string, items: ContentItem[]) => ReactNode;
173
+ /** i18n overrides. */
174
+ labels?: ContentPickerLabels;
175
+ /** Extra class on the root element. */
176
+ className?: string;
177
+ /** Explicit id for the root element; used as prefix for ARIA ids. */
178
+ id?: string;
179
+ }
180
+
181
+ /**
182
+ * `<ContentPicker />` — search for and attach WordPress posts, pages,
183
+ * custom post types, taxonomy terms, or users to a block.
184
+ *
185
+ * The component is **controlled** when `value` is defined, and
186
+ * **uncontrolled** (with optional `defaultValue`) otherwise. In both modes
187
+ * `onChange` fires with the full next array.
188
+ *
189
+ * @example
190
+ * <ContentPicker
191
+ * label="Related posts"
192
+ * variant="popover"
193
+ * kind="post"
194
+ * types={['post', 'page']}
195
+ * maxItems={5}
196
+ * orderable
197
+ * value={related}
198
+ * onChange={setRelated}
199
+ * />
200
+ */
201
+ declare const ContentPicker: ({ label, hideLabelFromVision, help, kind, types, variant, value: controlledValue, defaultValue, onChange, maxItems, orderable, placeholder, perPage, inputDelayMs, fetchOnOpen, excludeCurrentPost, uniqueItems, groupByType, showTypeBadge, icons, disableTypeFilter, showUrl, filter, request, renderSuggestion, renderSelected, renderGroupHeading, labels, className, id, }: ContentPickerProps) => react_jsx_runtime.JSX.Element;
202
+
203
+ export { type ContentItem, type ContentKind, ContentPicker, type ContentPickerIcon, type ContentPickerIconMap, type ContentPickerLabels, type ContentPickerProps, type ContentPickerVariant, type ContentStatus, type FilterContext, type MissingReason, type RequestContext, type ResolvedContentItem, type SuggestionRenderState };