1.0.0-Alpha31 • Published 2 years ago

blaze-expression-monaco v1.0.0-Alpha31

Weekly downloads
8
License
Apache-2.0
Repository
github
Last release
2 years ago

Blaze-Expression Monaco Editor

An integration for Blaze-Expression with the Monaco editor.

Installation

npm install blaze-expression-monaco

Usage

You can parse the JSON representation of a domain model with symbols and create a monaco editor.

import * as expression from 'blaze-expression-monaco';
expression.BlazeExpressionContributor.createEditor(
    monaco,
    {
        domElement: document.getElementById('editorId'),
        jsonContext: modelAndSymbolJsonPayload,
        singleLineMode: true
    }
);

In a web application this will roughly look like the following

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="style.css">
    <script src="webjars/monaco-editor/0.20.0/min/vs/loader.js"></script>
</head>
<body>
    <!-- The webpacked JS file -->
    <script src="js/main.js"></script>
    <script>
        require.config({ paths: { 'vs': 'webjars/monaco-editor/0.20.0/min/vs' }});

        // Await loading of the editor
        require(['vs/editor/editor.main'], function() {
            var request = new XMLHttpRequest();
            // Load the domain model JSON payload
            request.open("GET","/api/model");
            request.addEventListener('load', function(event) {
                if (request.status >= 200 && request.status < 300) {
                    var json = request.responseText;
                    var symbols = JSON.stringify({
                        post: {type: "Post", doc: "The current post"}
                    });
                    // Concatenate the symbols to the domain model json payload
                    var modelAndSymbolJsonPayload = json.substring(0, json.length - 1) + ',"symbols":' + symbols + '}';
                    // Create the monaco editor for the div with the id containerSingleLine
                    BlazeExpressionContributor.createEditor(
                        monaco,
                        {
                            domElement: document.getElementById('containerSingleLine'),
                            jsonContext: modelAndSymbolJsonPayload,
                            singleLineMode: true
                        }
                    );
                } else {
                    console.warn(request.statusText, request.responseText);
                }
            });
            request.send();
        });
    </script>
    <div id="containerSingleLine" style="width:800px;height:1.2em;border:1px solid grey">
        <textarea style="display: none">SUBSTRING(post.writer.name, 1)</textarea>
    </div>
</body>
</html>

Take a look at the following example project: https://github.com/Blazebit/blaze-expression/examples/web-editor

Licensing

This distribution, as a whole, is licensed under the terms of the Apache License, Version 2.0 (see LICENSE.txt).

References

Project Site: https://expression.blazebit.com (coming at some point)

1.0.0-Alpha31

2 years ago

1.0.0-Alpha30

2 years ago

1.0.0-Alpha29

2 years ago

1.0.0-Alpha28

2 years ago

1.0.0-Alpha27

2 years ago

1.0.0-Alpha26

2 years ago

1.0.0-Alpha25

2 years ago

1.0.0-Alpha24

2 years ago

1.0.0-Alpha23

3 years ago

1.0.0-Alpha22

3 years ago

1.0.0-Alpha21

3 years ago

1.0.0-Alpha20

3 years ago

1.0.0-Alpha19

3 years ago

1.0.0-Alpha18

3 years ago

1.0.0-Alpha17

3 years ago

1.0.0-Alpha16

3 years ago

1.0.0-Alpha14

3 years ago

1.0.0-Alpha13

4 years ago

1.0.0-Alpha12

4 years ago

1.0.0-Alpha11

4 years ago

1.0.0-Alpha10

4 years ago

1.0.0-Alpha9

4 years ago

1.0.0-Alpha8

4 years ago