Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
/ editor.js Public archive
forked from codex-team/editor.js

Modified version of Editor.js from codex-team which includes a custom metadata object assigned to each editor block.

License

Notifications You must be signed in to change notification settings

alibail/editor.js

 
 

Repository files navigation

Please note: The functionality this fork introduced is now present in the original project - please use the original editor.js.

This is a fork of the Editor.js project from the codex-team (https://editorjs.io) which contains the ability to assign a custom metadata object to the blocks within the editor.

Note: This code may not be actively maintained but is available for anyone who has these requirements.

Editor.js Version: 2.17

The project creates an additional metadata item assigned to all blocks within the editor, to which a unique block ID is assigned along with a blank string called data.

You can modify the metadata object by editing the file src/types-internal/block-data and changing the below to return the format you require;


 export interface MetaDataBlock {
   id?: string;
   data?: string;
 }
 

The code that creates the initial metadata object is located in file /mixin.ts and should be modified to meet your needs, the code below simply creates a unique ID for the block within the page and a blank data string.


 import {MetaDataBlock} from './types-internal/block-data';
 let counter = 0;
 export default {
   createMeta() {
     let id = 'block-' + counter;
     console.log ( 'Creating Meta: ' + id );
     const data = '';
     const existId = () => {
       if ( document.getElementById(id)) {
         return true; } else { return false; }
     };
     do {
       counter++;
       id = 'block-' + counter;
     } while (existId());
     return {id, data: ''};
   },
 };
 

Using this build

If the code meets your requirements you can use it directly by saving the file dist/editor.js in place of the file provided by the official project. Everything else remains the same as the official project including plugin compatibility.

Thanks to @nmannitz for their original modification adding an ID to the block.

About

Modified version of Editor.js from codex-team which includes a custom metadata object assigned to each editor block.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 88.5%
  • CSS 5.6%
  • HTML 4.9%
  • JavaScript 1.0%