@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
8 lines (7 loc) • 2.09 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/autocompleters/link.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Icon, page, post } from '@wordpress/icons';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst SHOWN_SUGGESTIONS = 10;\n\n/**\n * A link completer for posts and pages.\n *\n * @type {Object}\n */\nexport default {\n\tname: 'links',\n\tclassName: 'editor-autocompleters__link',\n\ttriggerPrefix: '[[',\n\tisDebounced: true,\n\tasync options( filterValue ) {\n\t\tconst options = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\tper_page: SHOWN_SUGGESTIONS,\n\t\t\t\tsearch: filterValue,\n\t\t\t\ttype: 'post',\n\t\t\t} ),\n\t\t} );\n\n\t\treturn options.filter( ( option ) => option.title !== '' );\n\t},\n\tgetOptionKeywords( item ) {\n\t\tconst expansionWords = item.title.split( /\\s+/ );\n\t\treturn [ ...expansionWords ];\n\t},\n\tgetOptionLabel( item ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<Icon icon={ item.subtype === 'page' ? page : post } />\n\t\t\t\t{ decodeEntities( item.title ) }\n\t\t\t</>\n\t\t);\n\t},\n\tgetOptionCompletion( item ) {\n\t\treturn <a href={ item.url }>{ item.title }</a>;\n\t},\n};\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,iBAA6B;AAC7B,mBAAiC;AACjC,2BAA+B;AA+B5B;AA7BH,IAAM,oBAAoB;AAO1B,IAAO,eAAQ;AAAA,EACd,MAAM;AAAA,EACN,WAAW;AAAA,EACX,eAAe;AAAA,EACf,aAAa;AAAA,EACb,MAAM,QAAS,aAAc;AAC5B,UAAM,UAAU,UAAM,iBAAAA,SAAU;AAAA,MAC/B,UAAM,yBAAc,iBAAiB;AAAA,QACpC,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,MAAM;AAAA,MACP,CAAE;AAAA,IACH,CAAE;AAEF,WAAO,QAAQ,OAAQ,CAAE,WAAY,OAAO,UAAU,EAAG;AAAA,EAC1D;AAAA,EACA,kBAAmB,MAAO;AACzB,UAAM,iBAAiB,KAAK,MAAM,MAAO,KAAM;AAC/C,WAAO,CAAE,GAAG,cAAe;AAAA,EAC5B;AAAA,EACA,eAAgB,MAAO;AACtB,WACC,4EACC;AAAA,kDAAC,qBAAK,MAAO,KAAK,YAAY,SAAS,oBAAO,mBAAO;AAAA,UACnD,qCAAgB,KAAK,KAAM;AAAA,OAC9B;AAAA,EAEF;AAAA,EACA,oBAAqB,MAAO;AAC3B,WAAO,4CAAC,OAAE,MAAO,KAAK,KAAQ,eAAK,OAAO;AAAA,EAC3C;AACD;",
"names": ["apiFetch"]
}