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

@sagold/rje-code-widgets

v0.33.8

Published

<p align="center"> <img src="https://github.com/sagold/json-editor/blob/main/packages/react-json-editor/docs/he-full-2000x564.png?raw=true" width="100%" alt="_react-json-editor"> <img src="../../images/title-rje-code-widgets-700.png" width="350px"

Downloads

281

Readme

Additional code widgets for @sagold/react-json-editor to edit code formatted strings, json and json with json-schema validation using CodeMirror and @uiw/react-codemirror.

install

yarn add @sagold/rje-code-widgets

Npm package version Types

include css

@import "@sagold/rje-code-widgets/rje-code-widgets.css";

Json Widget

Specific code editor supporting json syntax highlighting, linting and inline json-schema validation. The editor supports all kinds of data and json as strings.

To add the plugin to available widgets you have to pass it to the widget plugin registry:

import { defaultWidgets } from "@sagold/react-json-editor";
import { JsonWidgetPlugin } from "@sagold/rje-code-widgets";

<JsonForm widgets={[JsonWidgetPlugin, ...defaultWidgets]} />

To use the plugin for a specific json-schema use "format": "json:

{
  "type": "object",
  "format": "json",
  "properties": {}
}

Or use the inline option to trigger the editor by widget: "json":

import { Widget } from "@sagold/react-json-editor";

<Widget node={node} editor={editor} options={{ widget: "json" }} />

For information on widgets see @sagold/react-json-editor#widgets

Widget Options

You can configure your editor within your json-schema using the options property. JsonWidget supports all defaultOptions where approriate. What follows is a list of additionally supported options by JsonWidget:

liveUpdate: boolean

With "liveUpdate": true JsonWidget will commit every changed character back to the editor. Default behaviour is to send data in blur, which can also be set explicetly by "liveUpdate": false, e.g.

{
  "type": "array",
  "format": "json",
  "options": { 
    "liveUpdate": true
  }
}

height: number

Set the height of the code editor to a specific value

indentWithTab: boolean

Set to true, if the editor should indent using tabs instead of spaces

minHeight: number

Set the minimum height of the code editor to a specific value

maxHeight: number

Set the maximum height of the code editor to a specific value

schema: JSONSchema

JsonWidget exclusive json-schema for a json type string which consists of stringified json-data. Pass either a valid json-schema or a reference to your local schema, e.g.

{
  "type": "string",
  "format": "json",
  "default": "{}",
  "options": { 
    "schema": { "$ref": "#/$defs/inline-json" } 
  },
  "$defs": {
    "inline-json": {
      "type": "object"
    }
  }
}

setup: ReactCodeMirrorProps['basicSetup']

JsonWidget passes all basicSetup options to react-codemirror, e.g.

{
  "type": "object",
  "format": "json",
  "options": { 
    "setup": {
      "lineNumbers": false,
      "highlightActiveLineGutter": true,
      "closeBrackets": true,
      "autocompletion": false
    }
  }
}

For more details see the props documentation of @uiw/react-codemirror.

theme: "light" | "dark"

Renders the editor in a light or dark theme, where light is the default.

Custom Code Widgets

Code widgets have to be created manually for your specific languages. For this, a createCodeWidget helper is exposed.

  • extensions documentation: https://github.com/uiwjs/react-codemirror#support-language

create a custom code widget

import { JsonForm, defaultWidgets } from "@sagold/react-json-editor";
import { createCodeWidgetPlugin } from "@sagold/rje-code-widgets";
import { linter, lintGutter } from '@codemirror/lint';
import { css } from "@codemirror/lang-css";

const CssCodeWidgetPlugin = createCodeWidgetPlugin({
  extensions: [css(), lintGutter()],
  format: "css"
});

function Form(schema, data) {
  return <JsonForm
    schema={schema}
    data={data} 
    widgets={[CssCodeWidgetPlugin, ...defaultWidgets]}
  />;
}