Coder Social home page Coder Social logo

simple-monaco's Introduction

uwu simple-monaco components

These are components that wrap Microsoft's great Monaco editor (from vscode!) for the primary web UI frameworks, with a unified API.

Scroll down for generic docs, all props are reactive, comes with typescript defs/source when applicable.

Packages

pkg src npm
react packages/react @uwu/monaco-react
vue packages/vue @uwu/monaco-vue
svelte packages/svelte @uwu/monaco-svelte
solid packages/solid @uwu/monaco-solid
voby packages/voby @uwu/monaco-voby

Important notes

You may use any theme from here by name.

You can use monaco from an npm package by passing it as noCDN. This will only do anything on the first render of any <Monaco>, and will apply to all later uses of the component.

If you do not do this, monaco will just be loaded from jsDelivr.

To learn how the loading process works more in depth, please check the docs for @uwu/simple-monaco-core.

API

A UI component for the relevant framework is default exported. It does not take children and has the following props:

value (REQUIRED)

The current text value of the editor.

framework type notes
react string
vue N/A use v-model
svelte Writable<string> must be a svelte store
solid string
voby Observable<string>

valOut

The setter of the state/signal.

framework type notes
react (string) => void
vue N/A use v-model
svelte N/A use the value store
solid Setter<string>
voby N/A Observable<> is writable

lang (REQUIRED)

The programming language to use. Influences highlighting, completion, etc.

type notes
string

theme

The colour theme to use to highlight code. As mentioned before, a theme from here by name, a theme object and name, or url to a theme.

All instances must share the same theme for weird Monaco reasons.

type notes
string | [string, IStandaloneThemeData]

readonly

When set, the user cannot edit the contents of the editor. Setting value works fine.

type notes
boolean

height

Sets the height of the monaco editor.

type notes
string defaults to 30rem

width

Sets the height of the monaco editor.

type notes
string defaults to 20rem

otherCfg

Other configuration options to pass to the monaco editor (eg autolayout)

type notes
core.OtherCfg defaults to {}

noCDN

Pass an instance of the monaco library instead of loading it from jsDelivr.

type notes
Monaco

filename

This is used to set the "URL" of the model open in the editor. Mostly this isnt necessary, but is sometimes necessary for things such as enabling JSX support in the typescript language via extension. This doesn't show in the UI as monaco does not have the vscode tabbar.

This will be constructed into a URL for you of the form inmemory://sm-model/.... (The default URLs used by monaco are inmemory://model/1, then 2, 3, etc).

type notes
string

editorRef

An escape hatch that gives you out the editor instance used by the component. This is to keep this simple library from becoming too big as if you need this your case is likely not simple.

With this you are god.

framework type notes
react ((core.WrappedEditor) => void) | Ref<core.WrappedEditor>
vue N/A use the editorRef event.
svelte ((core.WrappedEditor) => void) | Writable<core.WrappedEditor> must be a svelte store
solid ((core.WrappedEditor) => void)
voby ((core.WrappedEditor) => void) ObservableLike is compatible with this signature

simple-monaco's People

Contributors

yellowsink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

zxol raxdiam

simple-monaco's Issues

Loading theme resource error due to cross-origin policy

I'm using your Monaco Editor plugin for solidjs, worked perfectly until recently. Seems broken on loading theme resource with error message in browser console:

[Error] Failed to load resource: Cross-origin redirection to https://esm.sh/[email protected]/themes/Dracula.json denied by Cross-Origin Resource Sharing policy: Origin [my site host] is not allowed by Access-Control-Allow-Origin. Status code: 301 (Dracula.json, line 0)

Seems esm.sh has changed their cross-origin policy?

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.