CODECRUSH

Extensible and powerful code editor for Javascript

v0.0.6

Star

Core package

If you want to use the editor for your vanilla js without any framework.

Installation

Choose your favorite package manager


_10
pnpm install codecrush-core


_10
npm install codecrush-core


_10
yarn add codecrush-core

Getting started


_15
import { initEditor } from "codecrush-core";
_15
import "codecrush-core/dist/index.css"; // styles from the core package
_15
_15
const app = document.getElementById("app");
_15
_15
if (app) {
_15
initEditor({
_15
height: 400,
_15
id: "js-editor",
_15
parent: app,
_15
theme: "material-darker",
_15
}).then(() => {
_15
console.log("editor loaded");
_15
});
_15
}

Themes

List of all themes included


_12
export type EditorThemes =
_12
| "dracula-soft"
_12
| "material-darker"
_12
| "material-default"
_12
| "material-ocean"
_12
| "material-palenight"
_12
| "nord"
_12
| "one-dark-pro"
_12
| "poimandres"
_12
| "rose-pine-moon"
_12
| "rose-pine"
_12
| "slack-dark";

Extending the editor

You can create custom components for the editor. The following example we create a component to register in the activity bar which key is pressed.

In this case we'll be using onReady and onKeyPressed events provided by the editor.


_30
import { initEditor, Component, ActivityBarComponent } from "codecrush-core";
_30
import "codecrush-core/dist/index.css"; // styles from the core package
_30
_30
class Example extends Component {
_30
onReady() {
_30
const activityBar =
_30
this.editor.getComponent<ActivityBarComponent>("activity-bar"); // get the activity bar
_30
activityBar.registerActivity("key-pressed", "Keyboard: ", false); // register a new entry with id and text
_30
}
_30
_30
onKeyPressed(key: string) {
_30
const activityBar =
_30
this.editor.getComponent<ActivityBarComponent>("activity-bar");
_30
activityBar.updateActivity("key-pressed", "Keyboard: " + key); //update the activity when the key is pressed
_30
}
_30
}
_30
_30
const app = document.getElementById("app");
_30
_30
if (app) {
_30
initEditor({
_30
height: 400,
_30
id: "js-editor",
_30
parent: app,
_30
theme: "material-darker",
_30
components: [Example],
_30
}).then(() => {
_30
console.log("editor loaded");
_30
});
_30
}

Codecrush React

A wrapper for the core package for react.

Installation

Choose your favorite package manager


_10
pnpm install codecrush-core codecrush-react


_10
npm install codecrush-core codecrush-react


_10
yarn add codecrush-core codecrush-react

Getting started


_12
import { Editor } from "codecrush-react";
_12
import "codecrush-core/dist/index.css"; // styles from the core package
_12
_12
function App() {
_12
return (
_12
<div className="App">
_12
<Editor height={400} id="js-editor" theme="material-darker" />
_12
</div>
_12
);
_12
}
_12
_12
export default App;

Themes

List of all themes included


_12
export type EditorThemes =
_12
| "dracula-soft"
_12
| "material-darker"
_12
| "material-default"
_12
| "material-ocean"
_12
| "material-palenight"
_12
| "nord"
_12
| "one-dark-pro"
_12
| "poimandres"
_12
| "rose-pine-moon"
_12
| "rose-pine"
_12
| "slack-dark";

Extending the editor

You can create custom components for the editor. The following example we create a component to register in the activity bar which key is pressed.

In this case we'll be using onReady and onKeyPressed events provided by the editor.


_32
import { Editor } from "codecrush-react";
_32
import "codecrush-core/dist/index.css"; // styles from the core package
_32
import { Component, ActivityBarComponent } from "codecrush-core";
_32
_32
class Example extends Component {
_32
onReady() {
_32
const activityBar =
_32
this.editor.getComponent<ActivityBarComponent>("activity-bar"); // get the activity bar
_32
activityBar.registerActivity("key-pressed", "Keyboard: "); // register a new entry with id and text
_32
}
_32
_32
onKeyPressed(key: string) {
_32
const activityBar =
_32
this.editor.getComponent <ActivityBarComponent>("activity-bar");
_32
activityBar.updateActivity("key-pressed", "Keyboard: " + key); //update the activity when the key is pressed
_32
}
_32
}
_32
_32
function App() {
_32
return (
_32
<div className="App">
_32
<Editor
_32
height={400}
_32
id="js-editor"
_32
theme="material-darker"
_32
components={[Example]}
_32
/>
_32
</div>
_32
);
_32
}
_32
_32
export default App;

Made by JosueRhea