[![](https://flat.badgen.net/npm/v/@editorjs/editorjs?icon=npm)](https://www.npmjs.com/package/@editorjs/editorjs) [![](https://flat.badgen.net/bundlephobia/min/@editorjs/editorjs?color=cyan)](https://www.npmjs.com/package/@editorjs/editorjs) [![](https://flat.badgen.net/bundlephobia/minzip/@editorjs/editorjs?color=green)](https://www.npmjs.com/package/@editorjs/editorjs) [![](https://flat.badgen.net/npm/license/@editorjs/editorjs)](https://www.npmjs.com/package/@editorjs/editorjs) ## Version 2.0 is here! We are glad to introduce the next version of Editor.js. Totally new core, structure and plugins β€” that was an impressive adventure πŸ€“. Welcome to testing stage. Please, join a [public Telegram-chat](//t.me/codex_editor) where you always find a support. ### Browsers support | [IE / Edge](http://godban.github.io/browsers-support-badges/)
IE / Edge | [Firefox](http://godban.github.io/browsers-support-badges/)
Firefox | [Chrome](http://godban.github.io/browsers-support-badges/)
Chrome | [Safari](http://godban.github.io/browsers-support-badges/)
Safari | [iOS Safari](http://godban.github.io/browsers-support-badges/)
iOS Safari | [Opera](http://godban.github.io/browsers-support-badges/)
Opera | | --------- | --------- | --------- | --------- | --------- | --------- | | Edge 12+ | Firefox 18+ | Chrome 49+ | Safari 10+ | Safari 10+ | Opera 36+ ### 2.7-2.9 changelog - `Fix` β€” Fix CMD+A Selection on multiple Editor instances - `New` β€” Toolbox now have beautiful helpers with Tool names and shortcuts - `Improvements` β€” Prevent navigating back on Firefox when Block is removing by backspace - `New` β€” Blocks selected with Rectangle Selection can be also removed, copied or cut - `New` β€” Migrate from `postcss-cssnext` to `postcss-preset-env` and disable `postcss-custom-properties` which conflicts with `postcss-preset-env` - `New` *RectangeSelection* β€” Ability to select Block or several Blocks with mouse ### 2.2β€”2.7 changelog - `New` *Sanitize API* β€” [Sanitize Config](https://github.com/codex-team/editor.js/blob/master/docs/tools.md#automatic-sanitize) of `Block Tools` now automatically extends by tags of `Inline Tools` that is enabled by current Tool by `inlineToolbar` option. You don't need more to specify `a, b, mark, code` manually. This feature will be added to fields that supports inline markup. - `New` *Block Selection* β€” Ability to select Block by `CMD+A`, and the whole Editor by double `CMD+A`. After that, you can copy (`CMD+C`), remove (`Backspace`) or clear (`Enter`) selected Blocks. - `New` *[Styles API](https://github.com/codex-team/editor.js/blob/master/types/api/styles.d.ts)* β€” Added `button` class for stylization of any buttons provided by Tools with one unified style. - `New` *[Notifier API](https://github.com/codex-team/editor.js/blob/master/docs/api.md#notifierapi)* β€” methods for showing user notifications: on success, errors, warnings, etc. - `New` *Block Tool* β€” [Table](http://github.com/codex-editor/table) constructor πŸ’ͺ - `New` If one of the Tools is unavailable on Editor initialization, its Blocks will be rendered with *Dummy Block*, describing that user can not edit content of this Block. Dummy Blocks can be moved, removed and saved as normal Blocks. So saved data won't be lost if one of the Tools is failed - `New` [Public TS-types](https://github.com/codex-team/editor.js/tree/master/types) are presented. - `Changes` *Tools API* β€” options `irreplaceable` and `contentless` was removed. - `Changes` *Tools API* β€” [Paste API](https://github.com/codex-team/editor.js/blob/master/docs/tools.md#paste-handling): tags, patterns and mime-types now should be specified by Tool's `pasteConfig` static property. Custom Paste Event should be handled by `onPaste(event)` that should not be static from now. - `Changes` *Tools API* β€” options `displayInToolbox ` and `toolboxIcon` was removed. Use [`toolbox`](https://github.com/codex-team/editor.js/blob/master/docs/tools.md#internal-tool-settings) instead, that should return object with `icon` and `title` field, or `false` if Tool should not be placed at the Toolbox. Also, there are a way to override `toolbox {icon, title}` settings provided by Tool with you own settings at the Initial Config. - `Improvements` β€” All Projects code now on TypeScript - `Improvements` β€” NPM package size decreased from 1300kb to 422kb - `Improvements` β€” Bundle size decreased from 438kb to 252kb - `Improvements` β€” `Inline Toolbar`: when you add a Link to the selected fragment, Editor will highlight this fragment even when Caret is placed into the URL-input. - `Improvements` β€” Block Settings won't be shown near empty Blocks of `initialType` by default. You should click on them instead. - `Improvements` β€” `onChange`-callback now will be fired even with children attributes changing. - `Improvements` β€” HTMLJantior package was updated due to found vulnerability - `Improvements` β€” Logging improved: now all Editor's logs will be preceded by beautiful label with current Editor version. - `Improvements` β€” Internal `isEmpty` checking was improved for Blocks with many children nodes (200 and more) - `Improvements` β€” Paste improvements: tags that can be substituted by Tool now will matched even on deep-level of pasted DOM three. - `Improvements` β€” There is no more Β«unavailableΒ» sound on copying Block by `CMD+C` on macOS - `Improvements` β€” Dozens of bugfixes and small improvements See a whole [Changelog](/docs/CHANGELOG.md) ## Documentation While we develop the new Documentation Site with all stuff, you can check some available docs at the [docs/](docs/) dir. - [Installation](docs/installation.md) - [How to use](docs/usage.md) - [How to create a Block Tool Plugin](docs/tools.md) - [How to create an Inline Tool Plugin](docs/tools-inline.md) - [API for Tools](docs/api.md) Sorry if we missed something. You can join a [Telegram-chat](//t.me/codex_editor) and ask a question. --- # So how to use Editor.js ## Basics Editor.js is a Block-Styled editor. Blocks are structural units, of which the Entry is composed. For example, `Paragraph`, `Heading`, `Image`, `Video`, `List` are Blocks. Each Block is represented by Plugin. We have [many](http://github.com/codex-editor/) ready-to-use Plugins and the [simple API](docs/tools.md) for creation new ones. So how to use the Editor after [Installation](docs/installation.md). - Create new Blocks by Enter or with the Plus Button - Press `TAB` or click on the Plus Button to view the Toolbox - Press `TAB` again to leaf Toolbox and select a Block you need. Then press Enter. ![](https://github.com/codex-editor/list/raw/master/assets/example.gif) - Select text fragment and apply a style or insert a link from the Inline Toolbar ![](https://capella.pics/7ccbcfcd-1c49-4674-bea7-71021468a1bd.jpg) - Use Β«three-dotsΒ» button on the right to open Block Settings. From here, you can move and delete a Block or apply Tool's settings, if it provided. For example, set a Heading level or List style. ![](https://capella.pics/01a55381-46cd-47c7-b92e-34765434f2ca.jpg) ## Shortcuts We really appreciate shortcuts. So there are few presets. Shortcut | Action | Restrictions -- | -- | -- `TAB` | Show/leaf a Toolbox. | On empty block `SHIFT+TAB` | Leaf back a Toolbox. | While Toolbox is opened `ENTER` | Create a Block | While Toolbox is opened and some Tool is selected `CMD+B` | Bold style | On selection `CMD+I` | Italic style | On selection `CMD+K` | Insert a link | On selection Also we support shortcuts on the all type of Tools. Specify a shortcut with the Tools configuration. For example: ```js var editor = EditorJS({ //... tools: { header: { class: Header, shortcut: 'CMD+SHIFT+H' }, list: { class: List, shortcut: 'CMD+SHIFT+L' } } //... }); ``` # Installation Guide There are few steps to run Editor.js on your site. 1. [Load Editor's core](#load-editors-core) 2. [Load Tools](#load-tools) 3. [Initialize Editor's instance](#create-editor-instance) ## Load Editor's core Firstly you need to get Editor.js itself. It is a [minified script](build/editor.js) with Editor's core and some default must-have tools. Choose the most usable method of getting Editor for you. - Node package - Source from CDN - Local file from project ### Node.js Install the package via NPM or Yarn ```shell npm i @editorjs/editorjs --save-dev ``` Include module in your application ```javascript const EditorJS = require('@editorjs/editorjs'); ``` ### Use from CDN You can load specific version of package from [jsDelivr CDN](https://www.jsdelivr.com/package/npm/@editorjs/editorjs). `https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest` Then require this script. ```html ``` ### Save sources to project Copy [editor.js](build/editor.js) file to your project and load it. ```html ``` ## Load Tools Each Block at the Editor.js represented by [Tools](docs/tools.md). There are simple external scripts with own logic. Probably you want to use several Block Tools that should be connected. For example check out our [Header](https://github.com/codex-editor/header) Tool that represents heading blocks. You can install Header Tool by the same way as the Editor (Node.js, CDN, local file). Check [Editor.js's community](https://github.com/codex-editor/) to see more ready-to-use Tools. **Example:** use Header from CDN ```html ``` ## Create Editor instance Create an instance of Editor.js and pass [Configuration Object](types/configs/editor-config.d.ts) with `holderId` and tools list. ```html
``` You can create a simple Editor with only default Paragraph Tool by passing a string with element's Id (wrapper for Editor) as a configuration param. Or use the default `editorjs` id for wrapper. ```javascript var editor = new EditorJS(); /** Zero-configuration */ // equals var editor = new EditorJS('editorjs'); ```` Or pass a whole settings object. ```javascript var editor = new EditorJS({ /** * Create a holder for the Editor and pass its ID */ holderId : 'editorjs', /** * Available Tools list. * Pass Tool's class or Settings object for each Tool you want to use */ tools: { header: { class: Header, inlineToolbar : true }, // ... }, /** * Previously saved data that should be rendered */ data: {} }); ``` ## Saving Data Call `editor.saver.save()` and handle returned Promise with saved data. ```javascript editor.saver.save() .then((savedData) => { console.log(savedData); }); ``` ## Example Take a look at the [example.html](example/example.html) to view more detailed examples. ## Credits and references - We use [HTMLJanitor](https://github.com/guardian/html-janitor) module in our Sanitizer module. # About team We are CodeX and we build products for developers and makers. Follow us on Twitter: [twitter.com/codex_team](https://twitter.com/codex_team) Feel free to contact: team@codex.so [codex.so](https://codex.so)