@wordpress/block-editor
Version:
51 lines (50 loc) • 1.49 kB
JavaScript
// packages/block-editor/src/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;
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 });
}
};
}
var link_default = createLinkCompleter();
export {
link_default as default
};
//# sourceMappingURL=link.js.map