UNPKG

@wordpress/block-editor

Version:
61 lines (59 loc) 1.73 kB
/** * WordPress dependencies */ // Disable Reason: Needs to be refactored. // eslint-disable-next-line no-restricted-imports import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; import { Icon, page, post } from '@wordpress/icons'; import { decodeEntities } from '@wordpress/html-entities'; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; const SHOWN_SUGGESTIONS = 10; /** * Creates a suggestion list for links to posts or pages. * * @return {Object} A links completer. */ function createLinkCompleter() { return { name: 'links', className: 'block-editor-autocompleters__link', triggerPrefix: '[[', options: async letters => { let options = await apiFetch({ path: addQueryArgs('/wp/v2/search', { per_page: SHOWN_SUGGESTIONS, search: letters, type: 'post', order_by: 'menu_order' }) }); options = options.filter(option => option.title !== ''); return options; }, getOptionKeywords(item) { const expansionWords = item.title.split(/\s+/); return [...expansionWords]; }, getOptionLabel(item) { return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Icon, { icon: item.subtype === 'page' ? page : post }, "icon"), decodeEntities(item.title)] }); }, getOptionCompletion(item) { return /*#__PURE__*/_jsx("a", { href: item.url, children: item.title }); } }; } /** * Creates a suggestion list for links to posts or pages.. * * @return {Object} A link completer. */ export default createLinkCompleter(); //# sourceMappingURL=link.js.map