• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reactjs and vuejs component of schema based json editor.

schema-based-json-editor

Dependency Status devDependency Status Build Status: Windows Github CI npm version Downloads type-coverage

features

  • reactjs component
  • vuejs component
  • common schema fields: title, description, default, readonly, $ref, propertyOrder, requiredWhen, optionalWhen, className, propertyName
  • object schema fields: properties, required, maxProperties, minProperties, collapsed
  • array schema fields: items, minItems, uniqueItems, enum, enumTitles, format('select2')
  • number and integer schema fields: minimum, exclusiveMinimum, maximum, exclusiveMaximum, enum, multipleOf, enumTitles, format('select' | 'radiobox')
  • string schema fields: format('textarea' | 'color' | 'date' | 'datetime' | 'datetime-local' | 'time' | 'month' | 'email' | 'uri' | 'url' | 'week' | 'hostname' | 'ipv4' | 'ipv6' | 'code' | 'markdown' | 'base64' | 'select' | 'radiobox' | 'json'), enum, minLength, maxLength, pattern, enumTitles
  • boolean schema fields: format('checkbox' | 'select' | 'select2')
  • image preview, code highlight, markdown preview
  • multi-language
  • react-composable-json-editor

reactjs component

gzip size

npm i react-schema-based-json-editor

import { JSONEditor } from "react-schema-based-json-editor";

or

<script src="./node_modules/react/umd/react.production.min.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.production.min.js"></script>
<script src="./node_modules/react-schema-based-json-editor/dist/react-schema-based-json-editor.min.js"></script>
<JSONEditor schema={schema}
    initialValue={initialValue}
    updateValue={this.updateValue}
    theme="bootstrap3"
    icon="fontawesome4">
</JSONEditor>

the online demo: https://plantain-00.github.io/schema-based-json-editor/packages/react/demo

vuejs component

gzip size

npm i vue-schema-based-json-editor

import { ArrayEditor, ObjectEditor, JSONEditor } from "vue-schema-based-json-editor";
app.component('array-editor', ArrayEditor)
app.component('object-editor', ObjectEditor)
app.component('json-editor', JSONEditor)

or

<script src="./node_modules/vue/dist/vue.min.js"></script>
<script src="./node_modules/vue-schema-based-json-editor/dist/vue-schema-based-json-editor.min.js"></script>
<json-editor :schema="schema"
    :initial-value="value"
    @update-value="updateValue($event)"
    theme="bootstrap3"
    icon="fontawesome4">
</json-editor>

the online demo: https://plantain-00.github.io/schema-based-json-editor/packages/vue/demo

react-composable-json-editor

gzip size

npm i react-composable-json-editor

import { useJsonEditorData, ObjectEditor, StringEditor, NumberEditor } from "react-composable-json-editor";

const { value, update, getArrayProps } = useJsonEditorData({
  stringExample: 'a string example',
  objectExample: {
    propertyExample1: '',
    propertyExample2: 0,
  },
})
<ObjectEditor
  properties={{
    'A string example': <StringEditor value={value.stringExample} setValue={update((draft, v) => draft.stringExample = v)} />,
    'A object example': <ObjectEditor
      properties={{
        'Property example 1': <StringEditor value={value.objectExample.propertyExample1} setValue={update((draft, v) => draft.objectExample.propertyExample1 = v)} />,
        'Property example 2': <NumberEditor value={value.objectExample.propertyExample2} setValue={update((draft, v) => draft.objectExample.propertyExample2 = v)} />,
      }}
    />,
  }}
/>

the online demo: https://plantain-00.github.io/schema-based-json-editor/packages/react-composable-json-editor/demo

properties and events of the component

name type description
schema Schema the json schema object
initialValue ValueType the initial json
updateValue (value: ValueType or undefined, isValid: boolean) => void the function that is invoked when the json is edited in the editor
theme string? support "bootstrap3" "bootstrap4" "bootstrap5" "antd3" "element-ui2" "iview2" "iview3" "blueprint1" "blueprint2" "blueprint3" for now
icon string? support "bootstrap3" "fontawesome4" "fontawesome5" "antd3" "element-ui2" "iview2" "iview3" "bootstrap-icons" for now
locale Locale? locale object
readonly boolean? readonly
dragula object? the dragula library object if you want to reorder array by drag and drop
markdownit object? the markdown-it library object if you want to preview markdown
hljs object? the highlight.js library object if you want to highlight code
forceHttps boolean? if true, the preview url of images will be https:// rather than http://
disableCollapse boolean? if true, the collapse button will be hidden
noSelect2 boolean? if true, use select rather than select2-component
minItemCountIfNeedFilter number? default 6(if item count > 6, filter is visible, otherwise hidden), so if 0, filter always visible, if Infinity, filter always hidden
monacoEditor object? the monacoEditor library object if you want to edit code with it

improve current theme

You can find css classes like schema-based-json-editor--*, you can set their styles to improve UI

The full list of the classes are in:

export const defaultTheme = {
  card: 'schema-based-json-editor--card',
  row: 'schema-based-json-editor--row',
  errorRow: 'schema-based-json-editor--error-row',
  input: 'schema-based-json-editor--input',
  errorInput: 'schema-based-json-editor--error-input',
  textarea: 'schema-based-json-editor--textarea',
  errorTextarea: 'schema-based-json-editor--error-textarea',
  checkbox: 'schema-based-json-editor--checkbox',
  radiobox: 'schema-based-json-editor--radiobox',
  button: 'schema-based-json-editor--button',
  buttonGroup: 'schema-based-json-editor--button-group',
  title: 'schema-based-json-editor--title',
  description: 'schema-based-json-editor--description',
  select: 'schema-based-json-editor--select'
}

You can also set className in schema to get fine grained style control

support other themes / icons / locales

import { themes, icons, locales } from 'schema-based-json-editor'

themes['new-theme-name'] = { ... }
icons['new-icon-name'] = { ... }
locales['new-locale-name'] = { ... }

the data structure of new themes / icons / locales are just like default ones:

export const bootstrap3Icon = {
  isText: false,
  collapse: 'glyphicon glyphicon-chevron-down',
  expand: 'glyphicon glyphicon-chevron-right',
  add: 'glyphicon glyphicon-plus',
  delete: 'glyphicon glyphicon-remove'
}

export const defaultLocale = {
  button: {
    collapse: 'Collapse',
    expand: 'Expand',
    add: 'Add',
    delete: 'Delete'
  },
  error: {
    minLength: 'Value must be at least {0} characters long.',
    maxLength: 'Value must be at most {0} characters long.',
    pattern: "Value doesn't match the pattern {0}.",
    minimum: 'Value must be >= {0}.',
    maximum: 'Value must be <= {0}.',
    largerThan: 'Value must be > {0}.',
    smallerThan: 'Value must be < {0}.',
    minItems: 'The length of the array must be >= {0}.',
    uniqueItems: 'The item in {0} and {1} must not be same.',
    multipleOf: 'Value must be multiple value of {0}.',
    minProperties: 'Properties count must be >= {0}.',
    maxProperties: 'Properties count must be <= {0}.'
  },
  info: {
    notExists: 'not exists',
    true: 'true',
    false: 'false',
    search: 'search'
  },
  markdownTipLocale: defaultMarkDownTipLocale,
  fileUploaderLocale: defaultFileUploaderLocale
}

non-standard fields

field type description
propertyOrder number? in a object, the property with smaller propertyOrder will be closer to the top
requiredWhen [string, '===' or 'in' or 'isUndefined', any]? in a object, the property is required when the condition is true, eg, ['name', '===', 'foo'] or ['name', 'in', ['foo', 'bar']] or ['name', 'isUndefined'], otherwise the property is hidden
optionalWhen [string, '===' or 'in' or 'isUndefined', any]? in a object, the property is optional when the condition is true, eg, ['name', '===', 'foo'] or ['name', 'in', ['foo', 'bar']] or ['name', 'isUndefined'], otherwise the property is hidden
collapsed boolean? if true, the object or array is collapsed by default
enumTitles string[]? works with enum field, are the titles of the enum
className string? custom class name
step number? or 'any' in a string, works with format time, or in a number
propertyName string? in a object, used as property name

change logs

https://github.com/plantain-00/schema-based-json-editor/tree/master/change_logs.md

More Repositories

1

type-coverage

A CLI tool to check type coverage for typescript code
TypeScript
1,232
star
2

tree-component

A reactjs and vuejs tree component.
TypeScript
146
star
3

types-as-schema

Genetate json schema, protobuf file, graphQL schema and reasonml/ocaml/rust types from typescript types.
TypeScript
40
star
4

ws-tool

A Develop Tool to Test WebSocket, Socket.IO, Stomp, Bayeux, HTTP, TCP, UDP, WebRTC, DNS API.
TypeScript
25
star
5

js-excel-template

A js excel template used in browser or nodejs environment.
TypeScript
24
star
6

select2-component

A vuejs and reactjs select component.
TypeScript
23
star
7

tour-component

A vuejs and reactjs tour component.
TypeScript
22
star
8

ws-heartbeat

Server-side and client-side heartbeat library for ws and browser-side Websocket.
TypeScript
18
star
9

blogs

something to share
JavaScript
16
star
10

file-uploader-component

A reactjs and vuejs component of file uploader.
TypeScript
12
star
11

ws-benchmark

A CLI tool for websocket, like apache bench for http.
TypeScript
12
star
12

relative-time-component

A auto-updated vuejs and reactjs relative time component.
TypeScript
10
star
13

package-dependency-graph

A CLI tool to generate a dependency graph of packages in a monorepo by graphviz or dagre.
TypeScript
10
star
14

ExcelFile.net

A Excel File operator based on NPOI.
C#
8
star
15

expression-engine

An expression tokenizer, parser and evaluator.
TypeScript
8
star
16

ts-csinterface

Adobe extensions CSInterface v7.0 library implementation in typescript (identical to original).
TypeScript
7
star
17

js-split-file

A library to split big file to small binary data for nodejs and browsers.
TypeScript
7
star
18

Bootstrap.Pagination

a Bootstrap pagination and pager for asp.net MVC and Webform
C#
7
star
19

rev-static

Static asset revisioning by appending content hash to filenames, then changing the names in html files.
TypeScript
7
star
20

no-unused-export

A CLI tool to check whether exported things in a module is used by other modules for Typescript.
TypeScript
7
star
21

deploy-robot

a test and deploy robot.
TypeScript
7
star
22

template-editor-demo

A poster template edit and generation design document and demo.
TypeScript
6
star
23

composable-editor-canvas

A composable editor canvas library.
TypeScript
6
star
24

clean-scripts

A CLI tool to make scripts in package.json clean.
TypeScript
4
star
25

rpc-on-ws

A lightweight RPC library on websocket connection.
TypeScript
4
star
26

code-count

A CLI tool to count code lines and characters.
TypeScript
4
star
27

monitor-a-list-from-redis

A simple tool to watch some realtime data from a redis source
TypeScript
3
star
28

weighted-picker

A library to pick a random item from weighted array.
TypeScript
3
star
29

grid-js-component

A reactjs and vuejs grid component.
TypeScript
3
star
30

optimize-yarn-lock

A CLI to optimize yarn.lock
TypeScript
3
star
31

simple-doc

A Server-less and Build-less markdown document application.
TypeScript
3
star
32

ps-extendscript-types

Photoshop extendscript typescript types.
TypeScript
3
star
33

markdown_to_pdf

A CLI tool to convert a markdown to a pdf file.
TypeScript
2
star
34

news-fetcher-client

The client side of a cross-platform tool to get and sync news.
TypeScript
2
star
35

protocol-first-design-demo

TypeScript
2
star
36

code-structure

A CLI tool to generate code structure for javascript or typescript source code.
TypeScript
2
star
37

prune-node-modules

A CLI tool to prune node_modules.
TypeScript
2
star
38

stringify2stream

A js library to stringify json to stream to avoid out-of-memory of JSON.stringify.
TypeScript
2
star
39

dns-protocol

A Library to encode and parse data for DNS protocol.
TypeScript
2
star
40

js-project-initializer

A tool to initialize a js project.
TypeScript
2
star
41

vscode-type-coverage

VSCode plugin for type-coverage. deprecated.
TypeScript
2
star
42

copy-tool

A tool to copy text or file from one place, and get it from another place
TypeScript
2
star
43

json-field-size

A CLI tool to calculate size of all fields in a json, for memory analysis.
TypeScript
1
star
44

ease-in-out

An ease-in-out no-css animation library.
TypeScript
1
star
45

image2base64-cli

A CLI tool to convert image file to base64 string.
TypeScript
1
star
46

Despise

a library to generate fake data for test, such as name, email, phone, number and so on.
C#
1
star
47

pagination-js-component

A vuejs and reactjs pagination component.
TypeScript
1
star
48

protocol-based-web-framework

A protocol and code generation based web framework.
TypeScript
1
star
49

DbHelper.Obsolete.Oracle

a oracle access helper.
C#
1
star
50

watch-then-execute

A CLI tool to execute script after source file changes.
TypeScript
1
star
51

git-commits-to-changelog

A CLI to generate changelog from git commits.
TypeScript
1
star
52

router-demo

Multiple-application SPA and SSR demo
TypeScript
1
star
53

Form.Recover

a library to recover form data from json(obsolete)
C#
1
star
54

queued-jobs

A library to handle jobs in a smooth way with help of queue for nodejs and browser
TypeScript
1
star
55

tab-container-component

A vuejs and reactjs tab container component.
TypeScript
1
star
56

badge-svg

A library to generate badge svg
TypeScript
1
star
57

reconnection

A javascript library for browser or nodejs client reconnection.
TypeScript
1
star
58

prerender-js

[Obsolete]A CLI tool to prerender a page and save html element by id to a file.
TypeScript
1
star