Getting started in JavaScript Headless Editor
The Essential JS 2 for JavaScript (global script) is an ES5-formatted pure JavaScript framework that can be directly used in the latest web browsers.
Dependencies
The following list of dependencies are required to use the Headless Editor library in the application.
|-- @syncfusion/ej2-headless-editor
|-- @syncfusion/ej2-base
|-- prosemirror-history
|-- prosemirror-commands
|-- prosemirror-inputrules
|-- prosemirror-keymap
|-- prosemirror-model
|-- prosemirror-schema-basic
|-- prosemirror-schema-list
|-- prosemirror-state
|-- prosemirror-transform
|-- prosemirror-view
|-- prosemirror-tablesSetup for local development
Refer to the following steps to set up your local environment.
Step 1: Create an app folder my-app for Essential JS 2 JavaScript controls.
Step 2: Create a my-app/resources folder to store local script and style files.
Step 3: Open Visual Studio Code and create my-app/index.js and my-app/index.html files for initializing the Essential JS 2 Headless Editor library.
Adding Headless Editor styles
Add the following styles inside the my-app/index.html file to include the tailwind3 theme styles:
<link href="https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/styles/tailwind3.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/35.1.37/ej2-headless-editor/styles/tailwind3.css" rel="stylesheet">Ensure that all Headless Editor theme style files are loaded in the exact order shown above. The order is important because these styles have dependencies, and loading them incorrectly may cause styling issues in the controls. You can also refer to the themes section for details about built-in themes and CSS references for individual controls.
Adding Headless Editor scripts
Add the following scripts inside the my-app/index.html file to include the Headless Editor functionality:
<script src="https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/35.1.37/ej2-headless-editor/dist/global/ej2-headless-editor.min.js" type="text/javascript"></script>Ensure that all Headless Editor script files are loaded in the correct order and included before initializing the control. The order is important because the scripts have dependencies, and loading them incorrectly may prevent the Headless Editor from working properly or cause runtime errors. Make sure the required base and dependent scripts are included along with the Headless Editor script.
Adding Headless Editor library
Add the Headless Editor library to the application as follows. Place the target element in index.html and the initialization code in index.js using the sample below.
The Headless Editor can be initialized on a div element, as shown below:
var headlessEditor = ej.headlesseditor.HeadlessEditor.create({
extensions: [basicExtensions, placeholderExtension]
});
var container = document.getElementById('headless-editor');
if (container) {
headlessEditor.mount(container);
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion Javascript Headless Editor</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/styles/tailwind3.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/35.1.37/ej2-headless-editor/styles/tailwind3.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="headless-editor"></div>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Run the Application
Run the index.html file through a local web server (for example, npx http-server or VS Code Live Server). Opening the file directly with file:// may break script loading.
The Syncfusion® JavaScript Headless Editor is displayed as shown below.
