• Stars
    star
    192
  • Rank 194,875 (Top 4 %)
  • Language
    CSS
  • Created about 3 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Repackages Gutenberg's editor playground as a full-featured multi-instance editor that does not require WordPress.

Isolated Block Editor

Repackages Gutenberg's editor playground as a full-featured multi-instance editor that does not require WordPress.

The key features are:

  • Extends the Gutenberg playground editor to match a full editor
  • Allows multiple onscreen instances with seperate data stores and keyboard handlers
  • Undo history

And a full list of features:

  • Dynamic switching of data stores for compatability with third-party blocks
  • Works at sizes smaller than full screen
  • Block allow and disallow list, per instance
  • Preferences (saved to localStorage) and options (saved to memory), per instance
  • Overriding of key Gutenberg store functions
  • Patterns, reusable blocks, groups, and template support
  • Block inserter in a popover
  • Block inspector in a popover
  • Built in toolbar with options for displaying a more menu, block inspector, and block buttons
  • Fullscreen mode (requires additional CSS)
  • Preview mode (requires additional CSS and JS)
  • Visual & code editor
  • PHP (WordPress) code to load the editor outside of wp-admin
  • Menu for custom links
  • Re-routing of WordPress API requests

The Isolated Block Editor is provided in three forms:

  • ES6 module
  • CommonJS module
  • Standalone JavaScript file, for inclusion on any browser page

Requires: Gutenberg 13.3.0

Examples:

  • Plain Text Editor - standalone JS and CSS file that can replace any textarea on any page with a full Gutenberg editor
  • Gutenberg Everywhere - a WordPress plugin to add Gutenberg to comments, WP admin pages, bbPress, and BuddyPress
  • Gutenberg Chrome Extension - a Chrome extension that allows Gutenberg to be used on any page
  • Gutenberg Desktop - a desktop editor that supports the loading and saving of HTML and Markdown files
  • P2 - WordPress as a collaborative workspace (coming soon for self-hosted)
  • Editor Block - a block that allows an editor to be added to a page (coming soon)

Do you use this in your own project? Let us know!

Why would I use this?

Gutenberg already provides a playground which allows it to be used outside of WordPress. This is actually used as the basis for the Isolated Block Editor.

However, it provides a limited set of features, and extending it further into a usable editor can take some effort. For example, it doesn't include any undo history.

The Isolated Block Editor is a full editor that handles a lot of these complexities. It should not be considered a replacement for the Gutenberg playground, but more of an opinionated layer on top.

This should be considered experimental, and subject to changes.

Bundling and WordPress

The Isolated Block Editor aims to provide an editor that is as isolated from WordPress as possible. However, it can still be used on a WordPress site, and the decision comes down to the bundling:

  • Bundled without Gutenberg - if used on a WordPress site then you can use the Gutenberg code already included with WordPress. You will need a working WordPress site, but do not need to include Gutenberg within your editor
  • Bundled with Gutenberg - Gutenberg is included within the editor and there is no dependency on WordPress or PHP

Examples are provided for both situations (see Plain text editor for bundled and Gutenberg Everywhere for unbundled).

The key difference is in the Webpack config. If you don't want to bundle Gutenberg with your editor then you can use the DependencyExtractionWebpackPlugin plugin:

plugins: [
	new DependencyExtractionWebpackPlugin( { injectPolyfill: true } )
]

Alternatively you can use the @wordpress/scripts build system, which automatically runs DependencyExtractionWebpackPlugin:

wp-scripts start

You can use the provided iso-gutenberg.php file to help when using the IsolatedBlockEditor on a WordPress site. It will load Gutenberg and set up your configuration.

Standalone Module

You can use the provided isolated-block-editor.js, core.css, and isolated-block-editor.css files on any web page, regardless of whether it is on WordPress. It will provide two global functions which can turn a textarea into a block editor. Here's an example:

<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="isolated-block-editor.js"></script>
<link rel="stylesheet" href="core.css" />
<link rel="stylesheet" href="isolated-block-editor.css" />

<body>
	<textarea id="editor"></textarea>

	<script>
		wp.attachEditor( document.getElementById( 'editor' ) );
	</script>
</body>

Note that you must load React before loading the editor.

You can find an example in src/browser/index.html.

CSS

If you are using on a WordPress site then WordPress will load the core Gutenberg CSS as part of the iso-gutenberg.php script.

If you are not using on a WordPress site then you will need to load the core CSS yourself. You can either do this by including the following modules and importing directly:

  • @wordpress/components
  • @wordpress/block-editor
  • @wordpress/block-library
  • @wordpress/format-library
@import '@wordpress/components/build-style/style.css';
@import '@wordpress/block-editor/build-style/style.css';
@import '@wordpress/block-library/build-style/style.css';
@import '@wordpress/block-library/build-style/editor.css';
@import '@wordpress/block-library/build-style/theme.css';
@import '@wordpress/format-library/build-style/style.css';

Alternatively you can directly import the bundled build-browser/core.css CSS:

import '@automattic/isolated-block-editor/build-browser/core.css';

Using

The module is currently only available on Github and can be added with:

npm install @automattic/[email protected]" --save (where 1.2.0 is the version you want to use)

Future

The code here deals with two kinds of problems:

  • Adding features to the Gutenberg playground - these are already provided by Gutenberg, but are packaged up here for you
  • Adding workarounds to Gutenberg - these are situations where Gutenberg doesn't provide a feature, or doesn't export a feature, and so a workaround is needed.

It is hoped that most of the workarounds can be migrated back to Gutenberg so that they are no longer needed. Sometimes these workarounds involve duplicating parts of Gutenberg, which is not ideal. It is possible that the Isolated Block Editor may no longer be needed as a seperate entity.

Development

If multiple editors are on-screen then the IsolatedBlockEditor will ensure that the wp global refers to the currently focussed instance. This should make it more compatible with plugins and third-party code that uses the wp global.

Usage

Include the IsolatedBlockEditor module and then create an instance:

import IsolatedBlockEditor from '@automattic/isolated-block-editor';

render(
	<IsolatedBlockEditor
		settings={ settings }
		onSaveContent={ ( html ) => saveContent( html ) }
		onLoad={ ( parse ) => loadInitialContent( parse ) }
		onError={ () => document.location.reload() }
	>
	</IsolatedBlockEditor>,
	document.querySelector( '#editor' )
);

The IsolatedBlockEditor also exports the following support components:

  • EditorLoaded - Include this to be notified when the editor is loading and has loaded
  • DocumentSection - Wrap up a component to appear in the document tab of the inspector
  • ToolbarSlot - Insert content into the toolbar
  • FooterSlot - Insert content into the footer
  • EditorHeadingSlot - Insert content at the beginning of the editor area. Suitable for titles.
  • ActionArea - Insert content into the actions sidebar
  • CollaborativeEditing - Enable real-time collaborative editing
import IsolatedBlockEditor, { EditorLoaded, DocumentSection, ToolbarSlot, CollaborativeEditing } from 'isolated-block-editor';

render(
	<IsolatedBlockEditor
		settings={ settings }
		onSaveContent={ ( html ) => saveContent( html ) }
		onLoad={ ( parse ) => loadInitialContent( parse ) }
		onError={ () => document.location.reload() }
	>
		<EditorLoaded onLoaded={ () => {} } onLoading={ () => {} } />
		<DocumentSection>Extra Information</DocumentSection>
		<CollaborativeEditing settings={ collabSettings } />

		<ToolbarSlot>
			<button>Beep!</button>
		</ToolbarSlot>
	</IsolatedBlockEditor>,
	document.querySelector( '#editor' )
);

The following function is also provided:

  • initializeEditor - Call this to initialize the editor if it needs to be done before being used.

Props

settings

  • iso [object] - IsolatedBlockEditor settings object

  • iso.preferencesKey [string|null] - Preferences key. Default to null to disable

  • iso.defaultPreferences {object} - Default preferences

  • iso.persistenceKey [string|null] - Persistence key. Default to null to disable

  • iso.customStores [array] - Array of store objects, in a form suitable for passing to Gutenberg's createReduxStore

  • iso.blocks [object] - Block restrictions

  • iso.blocks.allowBlocks [string[]] - list of block names to allow, defaults to none

  • iso.blocks.disallowBlocks [string[]] - list of block names to disallow, defaults to none

  • iso.disallowEmbed [string[]] - List of embed names to remove, defaults to none.

  • iso.toolbar [Object] - Toolbar settings

  • iso.toolbar.inserter [boolean] - Enable or disable the toolbar block inserter, defaults to true

  • iso.toolbar.inspector [boolean] - Enable or disable the toolbar block inspector, defaults to false

  • iso.toolbar.navigation [boolean] - Enable or disable the toolbar navigation button, defaults to false

  • iso.toolbar.undo [boolean] - Enable or disable the toolbar undo/redo buttons, defaults to true

  • iso.toolbar.documentInspector [string|null] - Set to a string to show as a new tab in the inspector and filled with DocumentSection, otherwise defaults to no new tab

  • iso.moreMenu [Object] - More menu settings

  • iso.moreMenu.editor [boolean] - Enable or disable the editor sub menu (visual/code editing), defaults to false

  • iso.moreMenu.fullscreen [boolean] - Enable or disable the fullscreen option, defaults to false

  • iso.moreMenu.preview [boolean] - Enable or disable the preview option, defaults to false

  • iso.moreMenu.topToolbar [boolean] - Enable or disable the 'top toolbar' option, defaults to false

  • iso.linkMenu [array] - Link menu settings. Array of title and url, defaults to none

  • iso.currentPattern [string] - The pattern to start with, defaults to none

  • iso.allowApi [boolean] - Allow API requests, defaults to false

  • editor [object] - Gutenberg settings object

A settings object that contains all settings for the IsolatedBlockEditor, as well as for Gutenberg. Any settings not provided will use defaults.

The block allow and disallow list works as follows:

  • All blocks are allowed, unless the allowBlocks option is set which defines the list of allowed blocks
  • Anything in the disallowBlocks list is removed from the list of allowed blocks.

onSaveContent

  • content - content to be saved, as an HTML string

Save callback that saves the content as an HTML string. Will be called for each change in the editor content.

onSaveBlocks

  • blocks [Array] - blocks to be saved
  • ignoredContent [Array]- array of HTML strings of content that can be ignored

Save callback that is supplied with a list of blocks and a list of ignored content. This gives more control than onSaveContent, and is used if you want to filter the saved blocks. For example, if you are using a template then it will appear in the ignoredContent, and you can then ignore the onSaveBlocks call if it matches the blocks.

onLoad

  • parse [string] - Gutenberg parse function that parses HTML as a string and returns blocks

Load the initial content into the editor. This is a callback that runs after the editor has been created, and is supplied with a parse function that is specific to this editor instance. This should be used so that the appropriate blocks are available.

__experimentalUndoManager

An alternative history undo/redo manager to be used by the editor. The passed in object must contain an undo and a redo methods, as well as a undoStack and a redoStack array properties containing the corresponding history. If not provided, the default history management will be used. This property is experimental and can change or be removed at any time.

__experimentalOnInput

An optional callback that will be passed down to the Gutenberg editor if provided.This property is experimental and can change or be removed at any time.

__experimentalOnChange

An optional callback that will be passed down to the Gutenberg editor if provided.This property is experimental and can change or be removed at any time.

__experimentalValue

An optional value (blocks) for the editor to show. If provided, it will be used as the internal value/blocks to display.This property is experimental and can change or be removed at any time.

__experimentalOnSelection

An optional callback that will be called when the selection changes in the editor. The only parameter passed to the callback will be the new selection value.

onError

Callback if an error occurs.

className

Additional class name attached to the editor.

renderMoreMenu

  • menuSettings [object] - settings for this particular editor
  • onClose [func] - Callback to close the more menu

Render additional components in the more menu.

Note: this needs improving or replacing with something more flexible

children

Add any components to customise the editor. These components will have access to the editor's Redux store.

Media uploader

If you want to make use of a media uploader and media library then you must set this up similar using the editor.MediaUpload filter. For example, if you want to use the Gutenberg media library then this would be:

import { MediaUpload } from '@wordpress/media-utils';

addFilter( 'editor.MediaUpload', 'your-namespace/media-upload', () => MediaUpload );

You will also need to pass in the media uploader as part of the editor settings:

import { mediaUpload } from '@wordpress/editor';

const settings = { your settings };

settings.editor.mediaUpload = mediaUpload;

In versions earlier than 2.21.0 this was automatically done, but this meant that you were unable to modify or disable it.

Extending

Custom behaviour can be added through child components. These components will have access to the isolated/editor store, as well as to the editor instance versions of core/block-editor.

Gutenberg requirements

Gutenberg uses iframes to display various parts of the editor, and it uses the global window.__editorAssets to store styles and scripts that will be added to this iframe. You may need to also use this.

The default is:

window.__editorAssets = { styles: '', scripts: '' }

The values should be full <link> and <script> tags.

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

Common Problems

If Storybook complains about different ES6 problems then it can sometimes be solved with npx yarn-deduplicate --scopes @babel

More Repositories

1

mongoose

MongoDB object modeling designed to work in an asynchronous environment.
JavaScript
26,622
star
2

wp-calypso

The JavaScript and API powered WordPress.com
JavaScript
12,359
star
3

_s

Hi. I'm a starter theme called _s, or underscores, if you like. I'm a theme meant for hacking so don't use me as a Parent Theme. Instead try turning me into the next, most awesome, WordPress theme out there. That's what I'm here for.
CSS
10,849
star
4

node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
JavaScript
9,820
star
5

kue

Kue is a priority job queue backed by redis, built for node.js.
JavaScript
9,434
star
6

simplenote-electron

Simplenote for Web, Windows, and Linux
TypeScript
4,517
star
7

juice

Juice inlines CSS stylesheets into your HTML source.
JavaScript
3,037
star
8

pocket-casts-android

Pocket Casts Android ๐ŸŽง
Kotlin
2,440
star
9

cli-table

Pretty unicode tables for the CLI with Node.JS
JavaScript
2,243
star
10

expect.js

Minimalistic BDD-style assertions for Node.JS and the browser.
JavaScript
2,098
star
11

simplenote-ios

Simplenote for iOS
Swift
1,976
star
12

monk

The wise MongoDB API
JavaScript
1,845
star
13

knox

S3 Lib
JavaScript
1,738
star
14

simplenote-android

Simplenote for Android
Java
1,688
star
15

jetpack

Security, performance, marketing, and design tools โ€” Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
PHP
1,550
star
16

pocket-casts-ios

Pocket Casts iOS app ๐ŸŽง
Swift
1,464
star
17

simplenote-macos

Simplenote for macOS
Swift
1,420
star
18

antiscroll

OS X Lion style cross-browser native scrolling on the web that gets out of the way.
JavaScript
1,079
star
19

wp-desktop

WordPress.com for Desktop
981
star
20

WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
PHP
874
star
21

browser-repl

Launch a repl on your command line to any browser in the cloud.
JavaScript
728
star
22

themes

Free WordPress themes made by Automattic for WordPress.org and WordPress.com.
CSS
693
star
23

legalmattic

Democratizing WordPress.com legalese since 2014!
672
star
24

wpcom.js

WordPress.com JavaScript API client designed for Node.js and browsers
JavaScript
658
star
25

Picard

A prototype theme that uses React and WP-API
CSS
631
star
26

fb-instant-articles

Archived (see Readme). Enable Facebook Instant Articles on your WordPress site.
PHP
628
star
27

sensei

Sensei LMS - Online Courses, Quizzes, & Learning
PHP
514
star
28

developer

In your WordPress, developing locally
PHP
470
star
29

wordpress-activitypub

ActivityPub for WordPress
PHP
442
star
30

theme-components

A collection of patterns for creating a custom starter WordPress theme.
PHP
404
star
31

wp-super-cache

WP Super Cache: A fast caching engine for WordPress
PHP
399
star
32

Edit-Flow

WordPress plugin to accelerate your editorial workflow
PHP
341
star
33

o2

The o2 plugin for WordPress โ€” blogging at the speed of thought
JavaScript
332
star
34

newspack-plugin

An advanced open-source publishing and revenue-generating platform for news organizations.
PHP
310
star
35

liveblog

Liveblogging done right. Using WordPress.
PHP
304
star
36

batcache

A memcached HTML page cache for WordPress.
PHP
278
star
37

Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
PHP
275
star
38

newspack-theme

A theme for Newspack.
PHP
265
star
39

vip-quickstart

Retired
PHP
265
star
40

Iris

A(n awesome) Color Picker
JavaScript
257
star
41

babble

Multilingual WordPress done right.
PHP
244
star
42

syntaxhighlighter

WordPress plugin that makes it easy to post syntax-highlighted code snippets.
CSS
237
star
43

VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
PHP
210
star
44

underscores.me

PHP
209
star
45

newspack-blocks

Gutenberg blocks for the Newspack project.
PHP
193
star
46

custom-metadata

A WordPress plugin that provides an easy way to add custom fields to your object types (post, pages, custom post types, users)
PHP
191
star
47

camptix

Moved to https://github.com/WordPress/wordcamp.org/
PHP
182
star
48

browserbuild

JavaScript
170
star
49

woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
PHP
162
star
50

vip-go-mu-plugins

The development repo for mu-plugins used on the WordPress VIP Platform.
PHP
158
star
51

Documattic

WordPress presentations and resources shared by WordPress.com VIP
JavaScript
156
star
52

google-docs-add-on

Publish to WordPress from Google Docs
JavaScript
152
star
53

mydb

JavaScript
150
star
54

vip-scanner

Deprecated: Scan all sorts of themes and files and things! Use PHPCS and the VIP coding standards instead
PHP
140
star
55

wp-memcached

Memcached Object Cache for WordPress.
PHP
139
star
56

Genericons

A public mirror of changes to the Genericon release.
CSS
136
star
57

regenerate-thumbnails

WordPress plugin for regenerating thumbnails of uploaded images. Over 1 million active users and counting.
PHP
131
star
58

media-explorer

With Media Explorer, you can now search for tweets and videos on Twitter and YouTube directly from the Add Media screen in WordPress.
PHP
124
star
59

Rewrite-Rules-Inspector

WordPress plugin to inspect your rewrite rules.
PHP
123
star
60

PhpStorm-Resources

PhpStorm is making inroads at Automattic. Here you'll find various helpful files we've made.
123
star
61

wordbless

WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment
PHP
122
star
62

vip-go-mu-plugins-built

The generated repo for mu-plugins used on the VIP Go platform.
PHP
120
star
63

social-logos

A repository of all the social logos we use on WordPress.com
JavaScript
119
star
64

Cron-Control

A fresh take on running WordPress's cron system, allowing parallel processing
PHP
116
star
65

block-experiments

A monorepo of Block Experiments
JavaScript
114
star
66

genericons-neue

Genericons Neue are generic looking icons, suitable for a blog or simple website
HTML
114
star
67

nginx-http-concat

WordPress plugin to perform CSS and JavaScript concatenation of individual script files into one resource request.
PHP
114
star
68

php-thrift-sql

A PHP library for connecting to Hive or Impala over Thrift
PHP
113
star
69

wp-e2e-tests

Automated end-to-end tests for WordPress.com
JavaScript
112
star
70

ad-code-manager

Easily manage the ad codes that need to appear in your templates
PHP
112
star
71

gridicons

The WordPress.com icon set
PHP
108
star
72

woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
JavaScript
104
star
73

es-backbone

ElasticSearch Backbone library for quickly building Faceted Search front ends.
JavaScript
103
star
74

syndication

Syndicate your WordPress content.
PHP
102
star
75

theme-tools

Tools for making better themes, better.
JavaScript
99
star
76

mShots

Website Thumbnail/Snapshot Service
JavaScript
94
star
77

prefork

PHP class for pre-loading heavy PHP apps before serving requests
PHP
94
star
78

phpcs-neutron-standard

A set of phpcs sniffs for PHP >7 development
PHP
93
star
79

newspack-newsletters

Author email newsletters in WordPress
PHP
89
star
80

musictheme

A theme for bands and musicians that uses an experimental Gutenberg layout.
CSS
89
star
81

gutenberg-themes-sketch

A set of Sketch files to help you design block-driven WordPress themes.
88
star
82

zoninator

Curation made easy! Create "zones" then add and order your content straight from the WordPress Dashboard.
PHP
85
star
83

cloudup-cli

cloudup command-line executable
JavaScript
83
star
84

go-search-replace

๐Ÿš€ Search & replace URLs in WordPress SQL files.
Go
81
star
85

lazy-load

Lazy load images on your WordPress site to improve page load times and server bandwidth.
JavaScript
77
star
86

gutenberg-ramp

Control conditions under which Gutenberg loads - either from your theme code or from a UI
PHP
75
star
87

measure-builds-gradle-plugin

Gradle Plugin for reporting build time metrics.
Kotlin
74
star
88

auto-update

Objective-C
73
star
89

wpes-lib

WordPress-Elasticsearch Lib
PHP
73
star
90

vip-go-skeleton

The base repository structure for all VIP Go sites
PHP
72
star
91

msm-sitemap

Comprehensive sitemaps for your WordPress VIP site. Joint collaboration between Metro.co.uk, WordPress VIP, Alley Interactive, Maker Media, 10up, and others.
PHP
70
star
92

jurassic.ninja

A frontend to launching ephemeral WordPress instances that auto-destroy after some time
PHP
69
star
93

gutenberg-block-styles

An example of a simple plugin that adds a block style to Gutenberg.
PHP
68
star
94

atd-chrome

After the Deadline extension for Chrome
JavaScript
66
star
95

wp-api-console

WordPress (.com and .org) API Console written in React/Redux
JavaScript
66
star
96

eventbrite-api

The Eventbrite API plugin brings the power of Eventbrite to WordPress, for both users and developers.
PHP
65
star
97

mongo-query

mongo query API component
JavaScript
65
star
98

site-logo

Add a logo to your WordPress site. Set it once, and all themes that support it will display it automatically.
PHP
65
star
99

vip-go-nextjs-skeleton

A Next.js boilerplate for decoupled WordPress on VIP.
TypeScript
65
star
100

newspack-popups

AMP-compatible popup notifications.
PHP
61
star