Giter Site home page Giter Site logo

ttseattle / roosterjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/roosterjs

0.0 2.0 0.0 3.56 MB

roosterjs is a framework-independent javascript rich text editor.

License: Other

HTML 0.55% JavaScript 3.31% TypeScript 95.62% CSS 0.52%

roosterjs's Introduction

Build Status

Rooster

Rooster is a framework-independent JavaScript rich-text editor neatly nested inside one HTML <div> 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.

Features

Packages

Rooster contains 6 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.

APIs

Rooster provides DOM level APIs (in roosterjs-editor-dom) 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 fromHtml(), 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-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:

class HelloRooster implements EditorPlugin {
    initialize(editor: Editor) {}

    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

or

npm install roosterjs --save

You can also install sub packages separately:

yarn add roosterjs-editor-core yarn add roosterjs-editor-api ...

or

npm install roosterjs-editor-core --save npm install roosterjs-editor-api --save ...

In order to run the code below, you may also need to install webpack:

yarn add webpack -g

or

npm install webpack -g

Usage

A quick start

  1. Create editor.htm contains a DIV with some styles, and a reference to a .js file:
<html>
    <body>
        <div id='editorDiv' style='width: 500px; height: 300px; overflow: auto;
        border: solid 1px black'></div>
        <script src='editor.js'></script>
    </body>
</html>
  1. Create source.js to import roosterjs and create an editor:
var roosterjs = require('roosterjs');
var editorDiv = document.getElementById('editorDiv');
var editor = roosterjs.createEditor(editorDiv);
editor.setContent('Welcome to <b>RoosterJs</b>!');
  1. Compile the javascript file using webpack:

webpack source.js editor.js

  1. Navigate to editor.htm, you will see a editor shown in the page.

Add some format buttons

  1. Add some buttons into editor.htm:
<html>
    <body>
        <div id='editorDiv' style='width: 500px; height: 300px; overflow: auto;
        border: solid 1px black'></div>
        <button id='buttonB'>B</button>
        <button id='buttonI'>I</button>
        <button id='buttonU'>U</button>
        <script src='editor.js'></script>
    </body>
</html>
  1. Add code to source.js to handle click event of the buttons:
var roosterjs = require('roosterjs');
var editorDiv = document.getElementById('editorDiv');
var editor = roosterjs.createEditor(editorDiv);
editor.setContent('Welcome to <b>RoosterJs</b>!');

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);
});
  1. Compile the javascript file using webpack:

webpack source.js editor.js

  1. 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:

    yarn

    or

    npm install
  2. Build the source code, and start the sample editor:

    yarn start
    

    or

    npm start
    
  3. Navigate to the sample editor at http://localhost:3000/

More documentation

We are still working on more documentation in roosterjs wiki.

License - MIT

License Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License.

roosterjs's People

Contributors

jiuqingsong avatar redmondbowang avatar lego6245 avatar kenotron avatar danielbarnes175 avatar adjective-object avatar microsoftopensource avatar richardcassan avatar msftgits avatar samuelmarks avatar samueledassatti avatar sebastienvillar avatar szincone avatar

Watchers

James Cloos avatar Tisha Trongtham avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.