@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
41 lines (40 loc) • 1.27 kB
JavaScript
// packages/editor/src/components/autocompleters/link.js
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 { Fragment, jsx, jsxs } from "react/jsx-runtime";
var SHOWN_SUGGESTIONS = 10;
var link_default = {
name: "links",
className: "editor-autocompleters__link",
triggerPrefix: "[[",
isDebounced: true,
async options(filterValue) {
const options = await apiFetch({
path: addQueryArgs("/wp/v2/search", {
per_page: SHOWN_SUGGESTIONS,
search: filterValue,
type: "post"
})
});
return options.filter((option) => option.title !== "");
},
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 }),
decodeEntities(item.title)
] });
},
getOptionCompletion(item) {
return /* @__PURE__ */ jsx("a", { href: item.url, children: item.title });
}
};
export {
link_default as default
};
//# sourceMappingURL=link.mjs.map