| 1 |
// BlockEditorProvider's sub-registry doesn't inherit core's default |
| 2 |
// __experimentalFetchLinkSuggestions; pass this in via settings or the |
| 3 |
// LinkControl falls back to treating the search term as a literal URL. |
| 4 |
import apiFetch from '@wordpress/api-fetch'; |
| 5 |
|
| 6 |
export function fetchLinkSuggestions(search, opts = {}) { |
| 7 |
const params = new URLSearchParams(); |
| 8 |
params.set('search', search || ''); |
| 9 |
params.set('per_page', String(opts.perPage || 10)); |
| 10 |
if (opts.type) params.set('type', opts.type); |
| 11 |
if (opts.subtype) params.set('subtype', opts.subtype); |
| 12 |
return apiFetch({ path: `/wp/v2/search?${params.toString()}` }).then( |
| 13 |
(results) => |
| 14 |
(results || []).map((r) => ({ |
| 15 |
id: r.id, |
| 16 |
url: r.url, |
| 17 |
title: r.title || r.url, |
| 18 |
type: r.subtype || r.type, |
| 19 |
kind: r.type, |
| 20 |
})), |
| 21 |
); |
| 22 |
} |
| 23 |
|