npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-monaco-surfer

v0.5.0

Published

A wrapper around [react-monaco-editor](https://github.com/react-monaco-editor/react-monaco-editor) for Code Surfing.

Downloads

3

Readme

React-Monaco-Surfer

A wrapper around react-monaco-editor for Code Surfing.

This wrapper helps you add your code to the react-monaco-editor in a particular format to provide you some pre-build features such as highlighting some part of the code or adding buttons to some part of the text when selected. Also you can track the movement of the cursor in the editor to handle it accordingly

All the features provided by react-monaco-editor remain intact and can be passed in reactMonacoProps.

Installation

npm install react-monaco-surfer

or

yarn add react-monaco-surfer

Peer Dependencies

Please MAKE SURE to add these to your project before starting with react-monaco-surfer.

Usage

App.ts(Check examples folder for better understanding)

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import MonacoSurfer from 'react-monaco-surfer';
import * as SurferTypes from 'react-monaco-surfer/dist/index.d.';
import * as monacoEditorTypes from 'monaco-editor/esm/vs/editor/editor.api';
import CodeBits from './codeBits';

// Mention styles for highlighted text and remaining text in this.
import './index.css';

const editorWillMount = (monaco: typeof monacoEditorTypes) => {
  // Handle editor starts mounting here!!
};

const onChange = (
  newValue: string,
  event: monacoEditorTypes.editor.IModelContentChangedEvent
) => {
  // Handle on text changed in editor!!
};

class App extends React.Component {
  state = {
    highlightedCodePaths: undefined,
  };

  shouldComponentUpdate(nextProps, nextState) {
    if (
      JSON.stringify(nextState) === JSON.stringify(this.state) &&
      JSON.stringify(nextProps) === JSON.stringify(this.props)
    )
      return false;
    return true;
  }

  render() {
    return (
      <MonacoSurfer
        codeBits={CodeBits}
        highlightedCodePaths={this.state.highlightedCodePaths}
        scrollToPath={PATH}
        onClickBit={(codeBit: SurferTypes.CodeBit, codeBitPath: string) => {
          this.setState({
            highlightedCodePaths: codeBitPath,
          });
        }}
        addActionButtons={(
          codeBit: SurferTypes.CodeBit,
          codeBitPath: string
        ) => {
          return ()=>(
            <div>
              <text>
                Action Buttons
              </text>
            </div>
          );
        }}
        reactMonacoProps={{
          width:'100%',
          height:'100%',
          onChange: onChange,
          editorWillMount: editorWillMount,
        }}
      ></MonacoSurfer>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));

codeBits.ts(Syntax for the codeBits)

export default {
  start: '<View>\n',
  end: '</View>\n',
  children: [
    {
      start: '\t<View>\n',
      end: '\t</View>\n',
      children: [
        {
          start: '\t\t<View>\n',
          end: '\t\t</View>\n',
          children: [
            {
              start: '\t\t\t<Text>',
              end: '\t\t\t</Text>\n',
              children: [
                {
                  start: '',
                  end: '',
                  children: '\t\t\t\tEnter some text here',
                },
              ],
            },
            {
              start: '\t\t\t<Text>\n',
              end: '\t\t\t</Text>\n',
              children: '\t\t\t\tEnter some text here\n',
            },
          ],
        },
      ],
    },
    {
      start: '\t<View>\n',
      end: '\t</View>\n',
      children: [
        {
          start: '\t\t<Text>\n',
          end: '\t\t</Text>\n',
          children: '\t\t\tSome other text here\n',
        },
      ],
    },
  ],
};

Properties

  • codeBits:MANDATORY Object in the format CodeBit (check src/index.d.ts for better understanding).

  • highlightedCodePaths:OPTIONAL Mention the paths to code-bit to highlight it.

  • scrollToPath:OPTIONAL Path to scroll to a particular component.

  • onClickBit: OPTIONAL Handle clicks on any part of the code. Params :

    • codeBit: Gives object for selected codeBit.
    • codeBitPath: Gives path for selected codeBit.
  • reactMonacoProps:MANDATORY Can add all props of react-monaco-editor here.

  • addActionButtons:OPTIONAL Handle adding action buttons on selected part of the code. Params :

    • codeBit: Gives object for selected codeBit.

    • codeBitPath: Gives path for selected codeBit. Return:

    • React Element, check example

Required CSS classes

.dull{
  // any styles for un-highlighted text
  opacity: 0.4;
}

and

.selected-component{
  // any styles for highlighted text
  opacity: 1;
}

Contributing

Refer to CONTRIBUTING.md

Maintainers

ChandanCC and Himanshu Satija

License

MIT