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

@looker/code-editor

v0.1.37

Published

A syntax highlighter Viewer and Editor for Looker SDK supported languages.

Downloads

306

Readme

@looker/code-editor

This package contains code display and editor components that are used in Looker extensions such as the API Explorer and LookML Diagram.

Installation

Add dependency to your project using yarn or npm

yarn add @looker/code-editor

or

npm install @looker/code-editor

<CodeDisplay />

This component is a specialized <code /> or <pre /> that has various search, syntax highlighting and other display options. Use this component for read-only code display use cases. This component is used by this package's CodeEditor and Markdown component for inline and block code sections.

| Prop | Description | Default | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | | language | This prop configures the syntax highlighting language and accepts any react-prism-renderer supported language, as well as ruby, kotlin, swift, and csharp | json | | code | The code to be displayed and highlighted. | required | | pattern | The search pattern to be highlighted in the input code. | '' | | transparent | A flag for disabling the backgroundColor added by default. | false | | inline | When true, inline <code /> is used. <pre /> is used by default. | false | | lineNumbers | A flag for enabling line numbers. | false |

<CodeCopy />

This component wraps the <CodeDisplay /> component and adds a "copy to Clipboard" button

| Prop | Description | Default | | ------- | ----------------------------------------------------- | ---------- | | ... | All <CodeDisplay /> props are accepted | | | caption | An override for the Copy button text, which is "Copy" | optional |

<CodeEditor />

This component wraps the <CodeDisplay /> component and adds a hidden <textarea /> that allows for code editing.

| Prop | Description | Default | | -------- | ------------------------------------------ | ---------- | | ... | All <CodeDisplay /> props are accepted | | | onChange | An event handler for capturing user input. | required |

Example

const CodeBlockEditor: React.FC = () => {
  const [codeString, setCodeString] = useState(`
# GET /lookml_models -> Sequence[models.LookmlModel]
def all_lookml_models(
    self,
    # Requested fields.
    fields: Optional[str] = None,
    transport_options: Optional[transport.TransportOptions] = None,
) -> Sequence[models.LookmlModel]:
    """Get All LookML Models"""
    response = self.get(
                    f"/lookml_models",
            Sequence[models.LookmlModel],
            query_params={"fields": fields},
            transport_options=transport_options
    )
    assert isinstance(response, list)
    return responsebind
`)
  return (
    <CodeEditor
      code={codeString}
      onChange={setCodeString}
      language="python"
      lineNumbers={true}
    />
  )
}

<Markdown />

This component is a wrapper around a <ReactMarkdown /> component. It uses @looker/component renderers for text and <CodeDisplay /> for inline and block code. It has options for link handling and renderer overrides.

| Prop | Description | Default | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- | | source | The Markdown string to be rendered | required | | pattern | The search pattern to be highlighted in the source | '' | | transformLinkUri | A function for pre-processing the link before it is navigated to, used for removing <mark /> tags or modifying the destination. | optional | | linkClickHandler | An override for link click behavior. | optional | | paragraphOverride | An override for the default Paragraph renderer. | optional |

Using <CodeDisplay /> inside Markdown

This component checks for decorated code blocks. The following source would create a Ruby syntax highlighted code block.

When using the Ruby SDK this would be passed as a Ruby hash like:
```ruby
{
 :model=>"thelook",
 :view=>"inventory_items",
 :fields=>
  ["category.name",
   "inventory_items.days_in_inventory_tier",
   "products.count"],
 :filters=>{:"category.name"=>"socks"},
 :sorts=>["products.count desc 0"],
 :limit=>"500",
 :query_timezone=>"America/Los_Angeles",
}
```