Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I make it work with React ? #6

Closed
chethan-devopsnow opened this issue Nov 25, 2021 · 8 comments
Closed

How do I make it work with React ? #6

chethan-devopsnow opened this issue Nov 25, 2021 · 8 comments
Assignees
Labels
documentation Improvements or additions to documentation inactive-issue question Further information is requested

Comments

@chethan-devopsnow
Copy link

chethan-devopsnow commented Nov 25, 2021

I am currently using
https://www.npmjs.com/package/@monaco-editor/react

@Pranomvignesh Pranomvignesh added documentation Improvements or additions to documentation question Further information is requested labels Nov 25, 2021
@Pranomvignesh
Copy link
Owner

Hi @chethan-devopsnow,
I haven't used this package https://www.npmjs.com/package/@monaco-editor/react, So I'm not able to help you with this now.
You can refer the documentation of constrained editor plugin here
Everything is written in plain JS, so it will work in React.

I will try to add usage examples for this package in the documentation in the future

@Pranomvignesh Pranomvignesh self-assigned this Nov 27, 2021
@UrielJavier
Copy link

I did something like this @chethan-devopsnow

import { useRef } from "react";
import Editor from "@monaco-editor/react";
import { constrainedEditor } from "constrained-editor-plugin";

function App() {
    const editorRef = useRef(null);
    let blocked = [];

    function handleEditorDidMount(editor, monaco) {
        editorRef.current = editor;

        const constrainedInstance = constrainedEditor(monaco);
        const model = editor.getModel();
        constrainedInstance.initializeIn(editor);

        blocked.push(
            {
                range: [1, 1, 2, 10],
                allowMultiline: true
            }
        );

        constrainedInstance.addRestrictionsTo(model, blocked);
    }

    return (
        <div className="App" >
            <Editor
                onMount={handleEditorDidMount}
            />
        </div>
    );
}

export default App;

@Pranomvignesh
Copy link
Owner

@UrielJavier Thanks for the suggestion.
@chethan-devopsnow I request you to try this snippet, and if it works please consider closing this issue

@HC-47
Copy link

HC-47 commented Jan 5, 2022

Hi, I came down to the same code, and I confirm it works as expected.

@Pranomvignesh
Copy link
Owner

This issue is stale because it has been open 30 days with no activity. Add required comments or this will be closed in 7 days.

@Pranomvignesh
Copy link
Owner

This issue was closed because it has been stalled for 7 days with no activity.

@shrinidhinhegde
Copy link

I can confirm this method works very well!

Just a small suggestion... please include this in the documentation somewhere

Thanks

This is really amazing!!

@polmann
Copy link

polmann commented Jan 4, 2023

import { constrainedEditor } from "constrained-editor-plugin";

so that import didn't work for me, I had to import it from dist for it to work:

import { constrainedEditor } from 'constrained-editor-plugin/dist/esm/constrainedEditor';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation inactive-issue question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants