GithubHelp home page GithubHelp logo

kyle-undefined / blazaco Goto Github PK

View Code? Open in Web Editor NEW
21.0 8.0 20.0 13.88 MB

A Blazor Component utilizing the Monaco editor by Microsoft

License: MIT License

C# 78.40% HTML 10.20% JavaScript 11.40%
blazor blazor-interop blazor-extensions blazor-client monaco monaco-editor

blazaco's Introduction

Blazaco (Dead) Maintainer

This project is dead, lost interest and life got in the way. However, there's a fantastic maintained version over at serdarciplak/BlazorMonaco

A Blazor Component utilizing the Monaco editor by Microsoft, inspired by BlazorBits. Built and tested for Blazor version 3.0.100-preview5-011568.

I built this after writing my own ShareX (image / code / link) API in Blazor, just seeing what all it's capable of, and was looking for a way to style the code page. Found the BlazorBits but noticed it wasn't on Nuget anymore and was outdated, so decided to build an updated version. Any feedback would greatly be appreciated.

Blazaco dependencies

  • Visual Studio 16.1.0 Preview 3
  • .NET Core 3.0.100-preview5-011568

Demo

Installation

  • Add the NuGet package to your Blazor Client project
dotnet add package Blazaco

// or

Install-Package Blazaco

Usage

  • Add the following to your root _ViewImports.cshtml file, or any file you want to use the Monaco Editor
@using Blazaco
@using Blazaco.Editor
@using Blazaco.Editor.Options // Only needed if you want to change defaults
  • Add the MonacoEditor Component anywhere in your file
<MonacoEditor ref="_editor" Model="@_editorModel" Width="500" Height="500" />

// or

<MonacoEditor ref="_editor" Model="@_editorModel" FullScreen="true" />

Note: You can have a set Width / Height (Defaults to 800 / 600) or have a Fullscreen mode

  • Add your MonacoEditor and EditorModel fields to your @functions
private EditorModel _editorModel { get; set; }
private MonacoEditor _editor;
  • Configure Blazaco settings in your OnInit or OnInitAsync
_editorModel = new EditorModel(); // Uses defaults

// or

var options = new EditorOptions()
{
    Value = "// Your Code Here!",
    Language = "csharp",
    Theme = "vs-dark"
};

_editorModel = new EditorModel(options);

// or

var options = new EditorOptions()
{
	Value = "// Your Code Here!",
	Language = "csharp",
	Theme = "vs-dark",
	Minimap = new MinimapOptions()
	{
		Enabled = false
	}
};

_editorModel = new EditorModel(options);

// or

_editorModel = new EditorModel(new EditorOptions()
{
	Value = "// Your Code Here!",
	Language = "csharp",
	Theme = "vs-dark",
	Minimap = new MinimapOptions()
	{
		Enabled = false
	}
});

Note: You can configure the Constructor Options based on these options

  • Add the monaco-editor folder and link the Javascript and CSS files in your index.html file
<head>
    <link rel="stylesheet" data-name="vs/editor/editor.main" href="monaco-editor/min/vs/editor/editor.main.css">
</head>
<body>
    <app></app>
    ...
    <script>var require = { paths: { 'vs': 'monaco-editor/min/vs' } };</script>
    <script src="monaco-editor/min/vs/loader.js"></script>
    <script src="monaco-editor/min/vs/editor/editor.main.nls.js"></script>
    <script src="monaco-editor/min/vs/editor/editor.main.js"></script>
    <script type="blazor-boot">
    </script>
	...
</body>

Interop

Currently I've only created a handful of Methods for Interop, as that's all I really need for my purposes. Current plans are to expand the Interop to allow more integration of the Monaco Editor API and make it more fleshed out.

  • InitializeEditor
    • Internal Method to Initialize the Monaco Editor with default or set settings
  • GetValue
    • Gets the Value from the Monaco Editor
  • SetValue
    • Sets the Value for the Monaco Editor to display
  • SetTheme
    • Sets the Theme for the Monaco Editor

Change log

Copyright

Copyright (c) 2019 Kyle Undefined under the MIT License.

blazaco's People

Contributors

derekchasse avatar kyle-undefined avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blazaco's Issues

Project still alive?

Do you plan on continuing developing Blazaco or do you plan on abandoning the project? Right now this version won't work with Blazor WebAssembly but there are pull requests fixing the problem.

If you don't plan on further spending time in this project can I maintain it or are you okay with my fork? I don't think there is much to add to it yet. The only thing that I would do is making sure it still builds and works with Blazor WebAssembly until the public apis are stable.

Broken with core 3.1

'MonacoEditor.OnAfterRenderAsync()': no suitable method found to override

I think maybe this needs to be changed to OnInitializedAsync() ?

_editor not found

Hi, great work! I am using this editor in my Blazor project that we are using internally here at my company.

I keep getting this error tho:
System.InvalidOperationException: Object of type 'Blazaco.Editor.MonacoEditor' does not have a property matching the name 'ref'.

I can see it in my Chrome dev-tools console.

I am using the await _editor.SetValue(<myCustomScript>);, and it also says that _editor is null.

What is kind of weird is that everything is working :) But its not that nice that this keeps spamming my console.

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.