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

Is there a bundled version of the component? #267

Closed
raquelhortab opened this issue Feb 14, 2022 · 7 comments
Closed

Is there a bundled version of the component? #267

raquelhortab opened this issue Feb 14, 2022 · 7 comments
Labels

Comments

@raquelhortab
Copy link

Hi, I was wondering if there is any way I can use this component by importing a bundled version via a script tag (to be used with react-dom). The thing is I am not using node but a really old version of ruby on rails and I need to use the .js versions of react components.

jaywcjlove added a commit that referenced this issue Feb 14, 2022
jaywcjlove added a commit that referenced this issue Feb 14, 2022
@jaywcjlove
Copy link
Member

I think maybe it's what you want. @raquelhortab
https://codepen.io/jaywcjlove/pen/podWJra?editors=0010

<script src="https://unpkg.com/@uiw/react-codemirror/dist/codemirror.min.js"></script>

@raquelhortab
Copy link
Author

Looks like it! trying it first thing tomorrow, thank you very much!

@raquelhortab
Copy link
Author

Yes that is what I was looking for, thank you very much !

@raquelhortab
Copy link
Author

@jaywcjlove how should I use language modes with the bundled version?

if I need to use:
extensions={[javascript({ jsx: true })]}

I am guessing I need a bundled version of the javscript extension as well? I do have a javascript.js file that works with the conventional Codemirror editors, but that one only defines an editor mode, I am not sure it's the same as the npm version.

@jaywcjlove
Copy link
Member

@raquelhortab You need the bundled version of the javascript extension.

@jaywcjlove
Copy link
Member

jaywcjlove commented Feb 16, 2022

@raquelhortab I looked at the official example and made changes that should meet your needs.
https://codepen.io/jaywcjlove/pen/podWJra?editors=0010

@uiw/[email protected] Example:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script src="https://unpkg.com/@babel/[email protected]/babel.min.js" crossorigin></script>
    <script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
    <script src="https://codemirror.net/6/codemirror.js"></script>
    <script src="https://unpkg.com/@uiw/react-codemirror/dist/codemirror.min.js"></script>
  </head>
  <body>
    <div id="container" style="padding: 24px"></div>
    <script>
      window.require = function (module) {
        if (!module) {
          throw new Error('this is a fake require only use for import fusion next');
        }
        if (window.CM && window.CM[module]) {
          return window.CM[module];
        }
        return window[module];
      };
    </script>
    <script type="text/babel">
      import CodeMirror from '@uiw/codemirror';
      import { javascript } from '@codemirror/lang-javascript';

      const Demo = () => {
        return (
          <div>
            <CodeMirror
              value="console.log('hello world!')"
              height="200px"
              extensions={[javascript({ jsx: true })]}
              onChange={(value, viewUpdate) => {
                console.log('value:', value);
              }}
            />
          </div>
        );
      };

      ReactDOM.render(<Demo />, document.getElementById('container'));
    </script>
  </body>
</html>
Example @uiw/[email protected]
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="https://unpkg.com/@babel/[email protected]/babel.min.js" crossorigin></script>
  <script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
  <script src="https://codemirror.net/6/codemirror.js"></script>
  <script src="https://unpkg.com/@uiw/[email protected]/dist/codemirror.min.js"></script>
</head>
<body>
  <div id="container" style="padding: 24px"></div>
  <script type="text/babel">
    const { javascript } = CM["@codemirror/lang-javascript"];
    const ReactCodeMirror = codemirror.default;
    const Demo = () => {
      return (
        <div>
          <ReactCodeMirror
            value="console.log('hello world!')"
            height="200px"
            extensions={[javascript({ jsx: true })]}
            onChange={(value, viewUpdate) => {
              console.log('value:', value);
            }}
          />
        </div>
      );
    }

    ReactDOM.render(<Demo />, document.getElementById("container"));
  </script>
</body>
</html>

@raquelhortab
Copy link
Author

@jaywcjlove

Wow that is fantastic, it'll be very useful, thank you very much for the effort and time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants