Coder Social home page Coder Social logo

yace's Introduction

Y A C E build npm Coverage Status bundlephobia

yet another code editor

Features

  • ~1KB gzipped with zero dependencies.
  • binding hotkey and enhance with plugins.
  • adding any highlighter.

Installation

yace is published to npm, and accessible via the unpkg.com CDN:

via npm:

npm i yace

hotlinking from unpkg: (no build tool needed!)

import Yace from "https://unpkg.com/yace?module";

Usage

yace is working in browser and need DOM node e.g.:

<div id="editor"></div>

Initializing editor passing css selector and options:

import Yace from "yace";

const editor = new Yace("#editor", {
  value: "your awesome code",
  lineNumbers: true,
});

Examples

Live demo with codesandbox:

API

const editor = new Yace(selector, options);

Options

  • value — initial value.
  • lineNumber — show or hide line numbers, default false.
  • highlighter — function that takes current value and return highlighted html.
  • styles — styles for root component, e.g. { fontSize: "20px }.
  • plugins — array of plugins.

Plugin

Plugin is a function that called with textarea params {value, selectionStart, selectionEnd} as first argument and keydown DOM event as second argument and returns new textarea params {value, selectionStart, selectionEnd}.

onUpdate(callback)

It takes a callback that will be invoked when editor value is changed.

editor.onUpdate((value) => console.log(`new value: ${value}`));

update(params)

Update editor value and selections.

// update value
editor.update({ value: "new awesome code" });

// update selection
editor.update({ selectionStart: 0, selectionEnd: 4 });

destroy()

Remove all listeners.

editor.destroy();

value

Get the current editor's value.

editor.value; // => "your awesome code";

textarea

Get the textarea DOM element.

editor.textarea.focus();
editor.textarea.spellcheck = false;

License

MIT

yace's People

Contributors

petersolopov avatar marcisbee avatar dependabot[bot] avatar

Stargazers

Roman avatar

Watchers

James Cloos 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.