npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gechiui/edit-post

v5.0.27

Published

Edit Post module for GeChiUI.

Downloads

6

Readme

Edit Post

Edit Post Module for GeChiUI.

This package is meant to be used only with GeChiUI core. Feel free to use it in your own project but please keep in mind that it might never get fully documented.

Installation

Install the module

npm install @gechiui/edit-post

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @gechiui/babel-preset-default in your code.

Extending the post editor UI

Extending the editor UI can be accomplished with the registerPlugin API, allowing you to define all your plugin's UI elements in one place.

Refer to the plugins module documentation for more information.

The components exported through the API can be used with the registerPlugin (see documentation) API. They can be found in the global variable gc.editPost when defining gc-edit-post as a script dependency.

API

initializeEditor

Initializes and returns an instance of Editor.

Parameters

  • id string: Unique identifier for editor instance.
  • postType string: Post type of the post to edit.
  • postId Object: ID of the post to edit.
  • settings ?Object: Editor settings object.
  • initialEdits Object: Programmatic edits to apply initially, to be considered as non-user-initiated (bypass for unsaved changes prompt).

PluginBlockSettingsMenuItem

Renders a new item in the block settings menu.

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginBlockSettingsMenuItem = gc.editPost.PluginBlockSettingsMenuItem;

function doOnClick() {
	// To be called when the user clicks the menu item.
}

function MyPluginBlockSettingsMenuItem() {
	return gc.element.createElement( PluginBlockSettingsMenuItem, {
		allowedBlocks: [ 'core/paragraph' ],
		icon: 'dashicon-name',
		label: __( 'Menu item text' ),
		onClick: doOnClick,
	} );
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginBlockSettingsMenuItem } from '@gechiui/edit-post';

const doOnClick = () => {
	// To be called when the user clicks the menu item.
};

const MyPluginBlockSettingsMenuItem = () => (
	<PluginBlockSettingsMenuItem
		allowedBlocks={ [ 'core/paragraph' ] }
		icon="dashicon-name"
		label={ __( 'Menu item text' ) }
		onClick={ doOnClick }
	/>
);

Parameters

  • props Object: Component props.
  • props.allowedBlocks [Array]: An array containing a list of block names for which the item should be shown. If not present, it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the allowed list.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element.
  • props.label string: The menu item text.
  • props.onClick Function: Callback function to be executed when the user click the menu item.
  • props.small [boolean]: Whether to render the label or not.
  • props.role [string]: The ARIA role for the menu item.

Returns

  • GCComponent: The component to be rendered.

PluginDocumentSettingPanel

Renders items below the Status & Availability panel in the Document Sidebar.

Usage

// Using ES5 syntax
var el = gc.element.createElement;
var __ = gc.i18n.__;
var registerPlugin = gc.plugins.registerPlugin;
var PluginDocumentSettingPanel = gc.editPost.PluginDocumentSettingPanel;

function MyDocumentSettingPlugin() {
	return el(
		PluginDocumentSettingPanel,
		{
			className: 'my-document-setting-plugin',
			title: 'My Panel',
		},
		__( 'My Document Setting Panel' )
	);
}

registerPlugin( 'my-document-setting-plugin', {
	render: MyDocumentSettingPlugin,
} );
// Using ESNext syntax
import { registerPlugin } from '@gechiui/plugins';
import { PluginDocumentSettingPanel } from '@gechiui/edit-post';

const MyDocumentSettingTest = () => (
	<PluginDocumentSettingPanel
		className="my-document-setting-plugin"
		title="My Panel"
	>
		<p>My Document Setting Panel</p>
	</PluginDocumentSettingPanel>
);

registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );

Parameters

  • props Object: Component properties.
  • props.name [string]: The machine-friendly name for the panel.
  • props.className [string]: An optional class name added to the row.
  • props.title [string]: The title of the panel
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered when the sidebar is pinned to toolbar.

Returns

  • GCComponent: The component to be rendered.

PluginMoreMenuItem

Renders a menu item in Plugins group in More Menu drop down, and can be used to as a button or link depending on the props provided. The text within the component appears as the menu item label.

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginMoreMenuItem = gc.editPost.PluginMoreMenuItem;
var moreIcon = gc.element.createElement( 'svg' ); //... svg element.

function onButtonClick() {
	alert( 'Button clicked.' );
}

function MyButtonMoreMenuItem() {
	return gc.element.createElement(
		PluginMoreMenuItem,
		{
			icon: moreIcon,
			onClick: onButtonClick,
		},
		__( 'My button title' )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginMoreMenuItem } from '@gechiui/edit-post';
import { more } from '@gechiui/icons';

function onButtonClick() {
	alert( 'Button clicked.' );
}

const MyButtonMoreMenuItem = () => (
	<PluginMoreMenuItem icon={ more } onClick={ onButtonClick }>
		{ __( 'My button title' ) }
	</PluginMoreMenuItem>
);

Parameters

  • props Object: Component properties.
  • props.href [string]: When href is provided then the menu item is represented as an anchor rather than button. It corresponds to the href attribute of the anchor.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered to the left of the menu item label.
  • props.onClick [Function]: The callback function to be executed when the user clicks the menu item.
  • props.other [...*]: Any additional props are passed through to the underlying MenuItem component.

Returns

  • GCComponent: The component to be rendered.

PluginPostPublishPanel

Renders provided content to the post-publish panel in the publish flow (side panel that opens after a user publishes the post).

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginPostPublishPanel = gc.editPost.PluginPostPublishPanel;

function MyPluginPostPublishPanel() {
	return gc.element.createElement(
		PluginPostPublishPanel,
		{
			className: 'my-plugin-post-publish-panel',
			title: __( 'My panel title' ),
			initialOpen: true,
		},
		__( 'My panel content' )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginPostPublishPanel } from '@gechiui/edit-post';

const MyPluginPostPublishPanel = () => (
	<PluginPostPublishPanel
		className="my-plugin-post-publish-panel"
		title={ __( 'My panel title' ) }
		initialOpen={ true }
	>
		{ __( 'My panel content' ) }
	</PluginPostPublishPanel>
);

Parameters

  • props Object: Component properties.
  • props.className [string]: An optional class name added to the panel.
  • props.title [string]: Title displayed at the top of the panel.
  • props.initialOpen [boolean]: Whether to have the panel initially opened. When no title is provided it is always opened.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered when the sidebar is pinned to toolbar.

Returns

  • GCComponent: The component to be rendered.

PluginPostStatusInfo

Renders a row in the Status & visibility panel of the Document sidebar. It should be noted that this is named and implemented around the function it serves and not its location, which may change in future iterations.

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginPostStatusInfo = gc.editPost.PluginPostStatusInfo;

function MyPluginPostStatusInfo() {
	return gc.element.createElement(
		PluginPostStatusInfo,
		{
			className: 'my-plugin-post-status-info',
		},
		__( 'My post status info' )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginPostStatusInfo } from '@gechiui/edit-post';

const MyPluginPostStatusInfo = () => (
	<PluginPostStatusInfo className="my-plugin-post-status-info">
		{ __( 'My post status info' ) }
	</PluginPostStatusInfo>
);

Parameters

  • props Object: Component properties.
  • props.className [string]: An optional class name added to the row.
  • props.children GCElement: Children to be rendered.

Returns

  • GCComponent: The component to be rendered.

PluginPrePublishPanel

Renders provided content to the pre-publish side panel in the publish flow (side panel that opens when a user first pushes "Publish" from the main editor).

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginPrePublishPanel = gc.editPost.PluginPrePublishPanel;

function MyPluginPrePublishPanel() {
	return gc.element.createElement(
		PluginPrePublishPanel,
		{
			className: 'my-plugin-pre-publish-panel',
			title: __( 'My panel title' ),
			initialOpen: true,
		},
		__( 'My panel content' )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginPrePublishPanel } from '@gechiui/edit-post';

const MyPluginPrePublishPanel = () => (
	<PluginPrePublishPanel
		className="my-plugin-pre-publish-panel"
		title={ __( 'My panel title' ) }
		initialOpen={ true }
	>
		{ __( 'My panel content' ) }
	</PluginPrePublishPanel>
);

Parameters

  • props Object: Component props.
  • props.className [string]: An optional class name added to the panel.
  • props.title [string]: Title displayed at the top of the panel.
  • props.initialOpen [boolean]: Whether to have the panel initially opened. When no title is provided it is always opened.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered when the sidebar is pinned to toolbar.

Returns

  • GCComponent: The component to be rendered.

PluginSidebar

Renders a sidebar when activated. The contents within the PluginSidebar will appear as content within the sidebar. It also automatically renders a corresponding PluginSidebarMenuItem component when isPinnable flag is set to true. If you wish to display the sidebar, you can with use the PluginSidebarMoreMenuItem component or the gc.data.dispatch API:

gc.data
	.dispatch( 'core/edit-post' )
	.openGeneralSidebar( 'plugin-name/sidebar-name' );

Related

  • PluginSidebarMoreMenuItem

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var el = gc.element.createElement;
var PanelBody = gc.components.PanelBody;
var PluginSidebar = gc.editPost.PluginSidebar;
var moreIcon = gc.element.createElement( 'svg' ); //... svg element.

function MyPluginSidebar() {
	return el(
		PluginSidebar,
		{
			name: 'my-sidebar',
			title: 'My sidebar title',
			icon: moreIcon,
		},
		el( PanelBody, {}, __( 'My sidebar content' ) )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PanelBody } from '@gechiui/components';
import { PluginSidebar } from '@gechiui/edit-post';
import { more } from '@gechiui/icons';

const MyPluginSidebar = () => (
	<PluginSidebar name="my-sidebar" title="My sidebar title" icon={ more }>
		<PanelBody>{ __( 'My sidebar content' ) }</PanelBody>
	</PluginSidebar>
);

Parameters

  • props Object: Element props.
  • props.name string: A string identifying the sidebar. Must be unique for every sidebar registered within the scope of your plugin.
  • props.className [string]: An optional class name added to the sidebar body.
  • props.title string: Title displayed at the top of the sidebar.
  • props.isPinnable [boolean]: Whether to allow to pin sidebar to the toolbar. When set to true it also automatically renders a corresponding menu item.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered when the sidebar is pinned to toolbar.

PluginSidebarMoreMenuItem

Renders a menu item in Plugins group in More Menu drop down, and can be used to activate the corresponding PluginSidebar component. The text within the component appears as the menu item label.

Usage

// Using ES5 syntax
var __ = gc.i18n.__;
var PluginSidebarMoreMenuItem = gc.editPost.PluginSidebarMoreMenuItem;
var moreIcon = gc.element.createElement( 'svg' ); //... svg element.

function MySidebarMoreMenuItem() {
	return gc.element.createElement(
		PluginSidebarMoreMenuItem,
		{
			target: 'my-sidebar',
			icon: moreIcon,
		},
		__( 'My sidebar title' )
	);
}
// Using ESNext syntax
import { __ } from '@gechiui/i18n';
import { PluginSidebarMoreMenuItem } from '@gechiui/edit-post';
import { more } from '@gechiui/icons';

const MySidebarMoreMenuItem = () => (
	<PluginSidebarMoreMenuItem target="my-sidebar" icon={ more }>
		{ __( 'My sidebar title' ) }
	</PluginSidebarMoreMenuItem>
);

Parameters

  • props Object: Component props.
  • props.target string: A string identifying the target sidebar you wish to be activated by this menu item. Must be the same as the name prop you have given to that sidebar.
  • props.icon [GCBlockTypeIconRender]: The Dashicon icon slug string, or an SVG GC element, to be rendered to the left of the menu item label.

Returns

  • GCComponent: The component to be rendered.

reinitializeEditor

Reinitializes the editor after the user chooses to reboot the editor after an unhandled error occurs, replacing previously mounted editor element using an initial state from prior to the crash.

Parameters

  • postType Object: Post type of the post to edit.
  • postId Object: ID of the post to edit.
  • target Element: DOM node in which editor is rendered.
  • settings ?Object: Editor settings object.
  • initialEdits Object: Programmatic edits to apply initially, to be considered as non-user-initiated (bypass for unsaved changes prompt).

store

Store definition for the edit post namespace.

Related

Type

  • Object