Socket
Book a DemoInstallSign in
Socket

@automattic/editor-autocompleter

Package Overview
Dependencies
Maintainers
49
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automattic/editor-autocompleter

Autocompleters for Gutenberg

latest
Source
npmnpm
Version
1.4.0
Version published
Weekly downloads
3
Maintainers
49
Weekly downloads
 
Created
Source

Editor Autocompleter

Autocompleters for the Gutenberg editor. Provides:

  • User completor (@name)
  • Tag completer (#tag)
  • Cross-post completer (+xpost)

The completers require Gutenberg to function but are independant of WordPress. A data source (local or remote) needs to be supplied.

Matches are highlighted within the autocompleter.

Usage

npm install @automattic/isolated-block-editor" --save

Then include in your code with something like this:

import { tagCompleter, xpostCompleter, userCompleter } from '@automattic/editor-autocompleter';
import '@automattic/editor-autocompleter/dist/style.scss';
import apiFetch from '@wordpress/api-fetch';

function tagFetcher( search: string ) {
	return apiFetch( { path: '/api/tags?s=' + encodeURIComponent( search ) } );
}

function userFetcher( search: string ) {
	return apiFetch( { path: '/api/user?s=' + encodeURIComponent( search ) } );
}

function xpostFetcher( search: string ) {
	return apiFetch( { path: '/api/xpost?s=' + encodeURIComponent( search ) } );
}

function addCompleters( completers = [] ) {
	// Add tag completer
	completers.push( tagCompleter( tagFetcher, true ) );

	// Add xpost completer
	completers.push( xpostCompleter( xpostFetcher ) );

	// Override the standard user completer with a custom one
	return completers
		.filter( ( filter ) => filter.name !== 'users' )
		.concat( [ userCompleter( useUserFetcher ) ] );
}

addFilter(
	'editor.Autocomplete.completers',
	'my-program/autocompleters',
	addCompleters
);

Each autocompleter takes a 'fetcher' and an optional isRemote flag. The fetcher is a function that returns either a promise (i.e. from a remote API call), or a plain array of values.

If the isRemote flag is set to true then a loading indicator will be shown if the returned data is not immediate.

Releasing

To make a release, ensure you are on the trunk branch. Do not update the version number in package.json - the release process will do this for you. Then run:

GITHUB_TOKEN=<TOKEN> yarn dist

FAQs

Package last updated on 21 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts