• Stars
    star
    165
  • Rank 227,612 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An es-module wrapper around the monaco editor and prettier

Monacode

A thin es-module wrapper around the monaco editor and prettier

Exploring the feasibility of importing the monaco-editor (which powers VS Code) and prettier modules directly into the browser; aiming to make it one line easy to bring a native like code editing experiences to web applications without a build step.

Ships with all the features usually found in VS Code out of the box: things like code hints, type inference, minimap, command pallet, multi-cursor select, find and replace, code folding etc.

In addition to these features, prettier has been integrated so that hitting ⌘ + s will format the code.

monacode-demo

⚑️ Check out the hosted version at https://monacode.live

Usage

Install the module as an npm module and import it using the bare module specifier, or import it directly from unpkg:

import monacode from 'https://unpkg.com/monacode/index.min.js'; // 976Kb brotli

// Create a new editor and attach to the document body
const editor = monacode({
  container: document.body,
  value: 'const add = (x, y) => x + y;',
});

// Listen for changes within the editor
editor.getModel().onDidChangeContent((change) => {
  const newValue = editor.getValue();
  console.log(newValue);
});

It is also possible to embed the editor into your application using an iframe (see demo):

<iframe
  src="https://monacode.live?theme=vs-light&value=console.log('hey')"
></iframe>

Pass config options into the iframe as URL search parameters, making sure to URI encode values properly. Please note however, it is not currently possible to pass in nested config options.

API

The module exports a single default function which accepts a config object as an argument. The supplied config gets merged with a default config which itself is a subset of the options available to configure moanco editors. Some useful values to know include:

  • container: an HTML element that exists in the DOM (or a ref if using react/preact)
  • value: a string representing the initial code to be rendered within the editor
  • language: a string representing what language the editor should try syntax highlight and hint for
  • fontSize: a number indicating what pixel font size code should render at
  • theme: a string identifier of the desired theme or a url to a theme json file

Calling the default export returns an instance of the underlying monaco editor. Find out more about how to interact with the editor by reading the API documentation.

Development

Running the following command from the root of this project uses servor to start a dev server, then open your editor and browser on the appropriate localhost url.

npm start

Production

Running the following command from the root of this project uses esbuild build the source to a single index.min.js file. Currently this process takes ~1second and results in an output file weighing 4.6MB (commpresses down to less than 1MB with brotli).

npm run build

License

Licensed under the MIT License.

More Repositories

1

react-slack-clone

Complete chat application, built with Chatkit | by @lukejacksonn
JavaScript
1,349
star
2

perflink

Low friction JavaScript benchmarks that you can share via URL
JavaScript
1,206
star
3

servor

Dependency free file server for single page app development
JavaScript
1,026
star
4

ijk

Transforms arrays into virtual dom trees; a terse alternative to JSX and h
JavaScript
467
star
5

oceanwind

Compiles tailwind shorthand into css at runtime. Succeeded by Twind.
JavaScript
264
star
6

GreedyNav

A responsive navigation menu that stacks items into a dropdown menu when they overflow
JavaScript
232
star
7

es-react

ES6 module exposing the latest version of react and react-dom
JavaScript
231
star
8

csz

Runtime CSS modules with SASS like preprocessing
JavaScript
218
star
9

create-es-react-app

A create-react-app like template using only es-modules (no build step).
JavaScript
103
star
10

hyperapp-pwa

A minimalist, progressive web app compliant template for hyperapp projects
JavaScript
72
star
11

domz

A proxy function to help build virtual DOM trees from functions
JavaScript
62
star
12

hyperapp-electron

A minimal electron app starter with hyperapp, livereload and redux devtools
JavaScript
51
star
13

Actuate

One line easy actuation of CSS animation sequences
JavaScript
41
star
14

chattery

A GitHub action that creates chatrooms for pull requests
Ruby
29
star
15

esm

A single file es module prototyping tool
JavaScript
29
star
16

blub

[POC] resolving es module dependency graphs on the server
JavaScript
27
star
17

deployable

A ready-to-deploy static web app template and tutorial
HTML
25
star
18

hyperapp-firebase-auth

πŸ”₯ Drop in authentication for hyperapps using firebase
JavaScript
19
star
19

Lorem

Generates random lorem ipsum snippets
JavaScript
19
star
20

Malette

A color picker tool for the google material design palette
JavaScript
18
star
21

cube

Rubik's Cube simulator with F2L/OLL/PLL algorithms
JavaScript
16
star
22

hyperapp-wiki

Example of how hyperapp could be used to serve its on wiki with gh-pages
HTML
13
star
23

blog

A forkable personal blog that runs on GitHub pages. Demo πŸ‘‰
JavaScript
12
star
24

hyperapp-hn

First attempt at a community hacker news PWA built with HyperApp
JavaScript
10
star
25

vuid

❄️ Very unique identifiers in the browser using web cryptography (144b)
JavaScript
10
star
26

hyperapp-fetch

A component to fetch and cache data before rendering a view
JavaScript
10
star
27

tetris

The classic NES Tetris built with hyperapp
JavaScript
9
star
28

ipsums

Generate random amounts of lorem ipsum text
JavaScript
8
star
29

framer

Easily apply a frame overlay to an avatar photo
JavaScript
8
star
30

hyperapp-starter

A minimalist starter for hyperapp projects
JavaScript
6
star
31

Protohype

A set of aliases for commonly used CSS properties and values
CSS
5
star
32

hyperapp-router

A frontend router for hyperapp view switching
JavaScript
4
star
33

preroll

An opinionated web project builder with dev server
JavaScript
3
star
34

streamer

🚰 Streams of reasonably interesting data published reasonably stochastically
JavaScript
2
star
35

fb-sdk

Load and queue calls to the facebook sdk
JavaScript
2
star
36

dankon

πŸ—Ί Learn to express your gratitude in 140+ different languages
JavaScript
2
star
37

huy

useful h function ui elements
JavaScript
2
star
38

plural

picture-in-picture interface for youtube videos
JavaScript
2
star
39

hyperapp-two

A multi-page and multi-component boilerplate hyperapp project
JavaScript
2
star
40

xs

An extra small, stand alone web application template
HTML
1
star
41

youtube-eco

A chrome extension that optimizes youtube streaming quality
JavaScript
1
star
42

hyperapp-unite

A utility function for merging reducers, effects and routes with safe namespacing
JavaScript
1
star
43

Stash

A jQuery plugin that can instigate application/octet-stream downloads of local content
JavaScript
1
star
44

Browver

A JavaScript plugin that detects if a browser is too and points to the latest browser downloads..
JavaScript
1
star
45

lukejacksonn.github.io

My personal homepage to be hosted at http://lukejacksonn.com
HTML
1
star
46

gitinit

Create a new git repo based on an already existing repository
JavaScript
1
star
47

feeder

My awesome pusher feeds app (test)
JavaScript
1
star
48

loginn

A set of lambda functions and frontend components to aid authentication
JavaScript
1
star
49

create-pusher-app

An experiment with yeoman, hyperapp and the Pusher Feeds API
JavaScript
1
star
50

lukejacksonn

1
star