Color utilities for roosterjs
npm install roosterjs-color-utils
element. Editing operations performed by end users are
handled in simple ways to generate the final HTML.
To view the sample site, please click the link below:
RoosterJs Sample Site.
Upgrade from RoosterJs 7.\*
Please see here.
Features
$3
Rooster contains 6 basic packages.
1. roosterjs:
A facade of all Rooster code for those who want a quick start. Use the
createEditor() function in roosterjs to create an editor with default
configurations.
2. roosterjs-editor-core:
Defines the core editor and plugin infrastructure. Use roosterjs-editor-core
instead of roosterjs to build and customize your own editor.
3. roosterjs-editor-api:
Defines APIs for editor operations. Use these APIs to modify content and
formatting in the editor you built using roosterjs-editor-core.
4. roosterjs-editor-dom:
Defines APIs for DOM operations. Use roosterjs-editor-api instead unless
you want to access DOM API directly.
5. roosterjs-editor-plugins:
Defines basic plugins for common features. Examples: making hyperlinks,
pasting HTML content, inserting inline images.
6. roosterjs-editor-types:
Defines public interfaces and enumerations.
There are also some extension packages to provide additional functionalities.
1. roosterjs-color-utils:
Provide color transformation utility to make editor work under dark mode.
2. roosterjs-react:
Provide a React wrapper of roosterjs so it can be easily used with React.
3. roosterjs-editor-types-compatible:
Provide types that are compatible with isolatedModules mode. When using isolatedModules mode,
"const enum" will not work correctly, this package provides enums with prefix "Compatible" in
their names and they have the same value with const enums in roosterjs-editor-types package
$3
Rooster provides DOM level APIs (in roosterjs-editor-dom), core APIs (in roosterjs-editor-core), and formatting APIs
(in roosterjs-editor-api) to perform editing operations.
roosterjs-editor-dom provides several levels of DOM operations:
- Perform basic DOM operations such as wrap(), unwrap(), ...
- Wrap a given DOM node with InlineElement or BlockElement and perform
operations with DOM Walker API.
- Perform DOM operations on a given scope using scopers.
- Travel among InlineElements and BlockElements with scope using
ContentTraverser API.
roosterjs-editor-core provides APIs for editor core. Editor class will call such
APIs to perform basic editor operations. These APIs are overridable by specifying
API overrides in Editor options when creating the editor.
roosterjs-editor-api provides APIs for scenario-based operations triggered by
user interaction.
Plugins
Rooster supports plugins. You can use built-in plugins or build your own.
Plugins call APIs to communicate with the editor. When an operation is
performed by the user or when content is changed by code, the editor will
trigger events for the plugins to handle.
Here's a sample plugin which will show a dialog containing "Hello Rooster" when
an "a" is typed in the editor:
``typescript
class HelloRooster implements EditorPlugin {
getName() {
return 'HelloRooster';
}
initialize(editor: IEditor) {}
dispose() {}
onPluginEvent(e: PluginEvent) {
if (e.eventType == PluginEventType.KeyPress && e.rawEvent.which == 65) {
alert('Hello Rooster');
}
}
}
`
Installation
Install via NPM or Yarn:
yarn add roosterjs
You can also install sub packages separately:
yarn add roosterjs-editor-core
yarn add roosterjs-editor-api
...
In order to run the code below, you may also need to install webpack:
yarn add webpack -g
Usage
$3
1. Create editor.htm contains a DIV with some styles, and a reference to a
.js file:
`html
id="editorDiv"
style="width: 500px; height: 300px; overflow: auto;
border: solid 1px black"
>
`
2. Create source.js to import roosterjs and create an editor:
`javascript
var roosterjs = require('roosterjs');
var editorDiv = document.getElementById('editorDiv');
var editor = roosterjs.createEditor(editorDiv);
editor.setContent('Welcome to RoosterJs!');
`
3. Compile the javascript file using webpack:
webpack source.js editor.js
4. Navigate to editor.htm, you will see a editor shown in the page.
$3
1. Add some buttons into editor.htm:
`html
id="editorDiv"
style="width: 500px; height: 300px; overflow: auto;
border: solid 1px black"
>
2. Add code to source.js to handle click event of the buttons:
`javascript
var roosterjs = require('roosterjs');
var editorDiv = document.getElementById('editorDiv');
var editor = roosterjs.createEditor(editorDiv);
editor.setContent('Welcome to RoosterJs!');
document.getElementById('buttonB').addEventListener('click', function () {
roosterjs.toggleBold(editor);
});
document.getElementById('buttonI').addEventListener('click', function () {
roosterjs.toggleItalic(editor);
});
document.getElementById('buttonU').addEventListener('click', function () {
roosterjs.toggleUnderline(editor);
});
`
3. Compile the javascript file using webpack:
webpack source.js editor.js
4. Navigate to editor.htm, you will see buttons with bold, italic, underline
actions in the page.
Sample code
To view the sample site, please click here.
To build the sample site code yourself, follow these instructions:
1. Get dependencies using yarn or npm:
`cmd
yarn
`
2. Build the source code, and start the sample editor:
`
yarn start
`
or
`
npm start
`
Debugging
There are two options for debugging:
1. Debugging from VSCode
- Ensure the sample editor is running
- Set the breakpoints within VSCode
- Select "Debug app in Chrome" from the VSCode debugging configuration dropdown

- Run the scenario that needs to be debugged
2. Debugging directly from the development tools within the web browser
- The directions for how to do this are specific to each web browser. By opening the developer
tools for the web browser that Rooster is running on, you will be able to set breakpoints in
the code and debug accordingly.
Running tests
There are two ways that tests can be run:
1. Run all tests or a single test from VSCode
- (Skip if running all tests) Ensure the file that you want to test is selected (ie: toggleBold.ts
or toggleBoldTest.ts)
- Select "Test all files" or "Test current file" from the VSCode debugging configuration dropdown
2. Run all tests from command line
`
yarn test
``