Coder Social home page Coder Social logo

schema-based-json-editor's Introduction

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

schema-based-json-editor's People

Contributors

dflock avatar lunochkin avatar plantain-00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

schema-based-json-editor's Issues

React component demo is not loaded - errors regarding update dependencies

Version(if relevant): latest

Environment(if relevant):

Hi,
When you try to load react component demo - it is not loaded and there are errors in the console (error description below)
image

Last commits did "update dependencies".
I moved 4 commits back (to commit edfc334) -
the issue was solved and react demo shows with no errors.

Please fix the issue so we can enjoy the package.

Thanks

how to reset to default/initial values after editing some values?

Version(if relevant): 1.0.0

Environment(if relevant):

I'm using angular version 8.0.0

In HTML page, I have 'save' and 'reset' buttons.
what I want here is, once the page is loaded, JSON editor should load with initial values and if the user edit some values and click on the 'reset' button. all values should get clear and reset it with some default/initial values.
is there any way to reset the values?

below is html and ts code

<json-editor [schema]="schema"
[initialValue]="initialValue"
(updateValue)="updateValue($event)"
theme="bootstrap3">

<button id="reset" class="btn btn-submit" (click)="reset()">Reset
Save

and in app.component.ts
schema = {
type : 'object',
title: 'json editor',
properties: {
color: {
type: 'string',
default: 'red'
},
engine: {
type: 'string',
default: '1111'
}, required: ['color','engine']
}

initialValue= {
color: 'green',
engine: '88'
};

updateValue({ value, isValid }: common.ValidityValue<common.ValueType>) {
this.currentValues = values;
}
reset() {
//??
}

angular/core conflict

Version(if relevant): 1.0.0

"@angular/core": "^4.0.0"

Environment(if relevant):

Code(if relevant):

// code here

Expected:

Actual:

Unexpected value 'JSONEditorModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
My application uses angular 4, and I want to import this library to my application, but it doesn't work, I think it's because this library uses angular 5, is there any solutions?

Angular4 - ERROR in JSONEditorComponent is not an NgModule

Tried to test it with Angular 4 and got this error on 'ng serve'
here is full errors stack:
ERROR in /Users/val.rudi/Documents/Nodejs/aero-admin/node_modules/schema-based-json-editor/typings/lib.d.ts (2,24): Cannot find module 'react'.

ERROR in /Users/val.rudi/Documents/Nodejs/aero-admin/node_modules/schema-based-json-editor/dist/common.d.ts (1,1): Cannot find type definition file for 'react'.

ERROR in /users/val.rudi/documents/nodejs/aero-admin/node_modules/@types/lodash/index.d.ts (19449,15): All declarations of 'WeakMap' must have identical type parameters.

ERROR in JSONEditorComponent is not an NgModule

Firefox only permits integer number (not floating point) in number fields

Sorry, it's me again: Nothing urgent but I discovered that Firefox does not like numbers (type number) that have a fractional part, e.g. 3.14159. The input field gets a red border. However, it seems that the input is still accepted so this is more an optical thing (that still might confuse users).

  • Version: 8.1.1
  • Environment: Firefox 78.8.0esr (64-bit) (Debian)

Steps to reproduce:

  1. Open your demo https://plantain-00.github.io/schema-based-json-editor/packages/vue/demo/ with Firefox
  2. Enter 123.5 in "a number example"
  • Expected: Input accepted
  • Actual: Input field gets red border (but number is accepted)

In Chrome everything works fine.

A possible fix seems to be to add a "step" attribute to the number input field. At least after doing so Firefox does add a red border anymore.

Thanks again for this wonderful component!

bootstrap-vue support

hi,

thank you for this package.

i'd like to add support for bootstrap-vue (https://bootstrap-vue.js.org) which is based on bootstrap4.

as i work in bootstrap-vue, i am limited both to Vue and to Bootstrap4. currently i'm getting messy results (visually).

am i right in understanding that bootstrap4 support was removed? (even if not, i'm not sure it would help me with bootstrap-vue)

are there any guidelines to adding support for a specific css suite?

any further information will be appreciated.

thanks

Vue3 Support ??

Version(if relevant): 1.0.0

Environment(if relevant):

Code(if relevant):

// code here

Expected:

Actual:

Editor doesnt appear in Vue application

Version(if relevant): 7.5.0

vue-schema-based-json-editor": "^7.5.0"
vue-template-compiler": "^2.5.16"

Environment(if relevant):

Mac Chrome VueJS 2.4.2

Code(if relevant):

<json-editor
:schema="schema"
:initial-value="value"
@update-value="updateValue($event)"
theme="bootstrap3"
icon="fontawesome4"
:locale="locale"
:dragula="dragula"
:markdownit="markdownit"
:hljs="hljs"
:force-https="false">
>

// code here

Expected:

I am trying to use the json editor in Vue JS. I provided the schema and data but nothing is appearing.
I created a minimal application and attached it.

I did review the sample application code but it appears it has already been packaged so i minimized and unreadable.

Actual:

The editor is not appearing on the screen. I placed text above and below, see my text but no editor.
No Error message

vue_schema.zip

Building tsc projects with `noImplicitAny` can't find lodash types.

Hello,

Thank you for schema-based-json . It's exactly what I need at the moment.

I ran into something when using strict noImplicitAny rules in tsconfig.js. I can work around this, but thought I should bring it up, incase it is something which you can address in future releases.

I hope this is enough information to help you.

Cheers!

Version(if relevant): 1.0.0

7.2.1

Environment(if relevant):

webpack 3.10
awesome-typescript-loader 3.1
typescript 2.5.2

Code(if relevant):

→ schema-based-json-editor/dist/index.d.ts:

import * as toNumber from "lodash.tonumber";
import * as toInteger from "lodash.tointeger";

→ tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "sourceMap": true,
    "declaration": true,
    "noImplicitAny": true,   ⬅
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "lib": ["es6", "dom"],
    "jsx": "react",
    "strictNullChecks": true
  },
  "include": [ "src/**/*"]
}
    webpack

Expected:

Build without errors

Actual:


ERROR in [at-loader] ./node_modules/schema-based-json-editor/dist/index.d.ts:1:27
    TS7016: Could not find a declaration file for module 'lodash.tonumber'. '/Users/npaessel/lab/cc/model-feedback/node_modules/lodash.tonumber/index.js' implicitly has an 'any' type.
  Try `npm install @types/lodash.tonumber` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash.tonumber';`

ERROR in [at-loader] ./node_modules/schema-based-json-editor/dist/index.d.ts:2:28
    TS7016: Could not find a declaration file for module 'lodash.tointeger'. '/Users/npaessel/lab/cc/model-feedback/node_modules/lodash.tointeger/index.js' implicitly has an 'any' type.
  Try `npm install @types/lodash.tointeger` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash.tointeger';`

Vue: <json-editor> not showing up

Hi all!

First thanks for the promising package, I would love to use it but sadly I don't succeed in having the simplest example work.
I am new to Vue, so maybe I am doing some newbie error. Let me know, happy to learn!

Version: 8.3.0 (also tested on 7)

package.json:

{
  "dependencies": {
    "vue": "^2.6.11",
    "vue-schema-based-json-editor": "^8.3.0",
  }
}

Code:

App.vue:

<template>
<div>
  <h2>test the json-editor</h2>
  <p>Upload a new model to the server</p>
  <json-editor :schema="schema"
    :initial-value="initialValue"
    @update-value="updateNumberExample($event)"
    theme="bootstrap5"
    icon="fontawesome4">
  </json-editor>
  <p>p post json-editor </p>
</div>

</template>

<script>
//import { ArrayEditor, ObjectEditor, JSONEditor } from "vue-schema-based-json-editor";

export default {
	name: 'App',
	components: {
            //ArrayEditor, ObjectEditor, JSONEditor
	},
	data() {
		return {
      schema: {
        "numberExample": {
          "type": "number",
          "title": "A number example",
          "description": "a number description example",
          "default": 123.4,
          "minimum": 10,
          "exclusiveMinimum": true,
          "maximum": 1000,
          "exclusiveMaximum": true
        }
      },
      initialValue: {
        numberExample: 123.4
      },
			
		};
	},
	methods: {
    updateNumberExample(c){
      console.log("updateNumberExample value:", c)
    },    
  },
  mounted(){
    console.log("JSONEditor")
    console.log("JSONEditor")
    console.log("this.schema")
    console.log(this.schema)
    console.log("this.initialValue")
    console.log(this.initialValue)
  }
};
</script>

main.js:

import Vue from 'vue';
import App from './App.vue';
import { ArrayEditor, ObjectEditor, JSONEditor } from "vue-schema-based-json-editor";

Vue.component('array-editor', ArrayEditor)
Vue.component('object-editor', ObjectEditor)
Vue.component('json-editor', JSONEditor)

new Vue( {
	render: h => h( App ),
} ).$mount( '#app' );

Expected:

The number example editor appear as in the demo

Actual:

The editor does not appear, with two possible results:

  • either there is only a single html comment <!----> where the <json-editor> should appear,
  • or I get a TypeError: _cache is undefined error stemming from some indexTemplateHtml JS object, stacktrace shown below.

I have not exactly figured out why I don't always get the same result.

Stacktrace:

TypeError: _cache is undefined
    indexTemplateHtml http://localhost:9080/main.da4909e4.js:27001
    _render http://localhost:9080/main.da4909e4.js:3665
    updateComponent http://localhost:9080/main.da4909e4.js:4187
    get http://localhost:9080/main.da4909e4.js:4601
    Watcher http://localhost:9080/main.da4909e4.js:4588
    mountComponent http://localhost:9080/main.da4909e4.js:4194
    $mount http://localhost:9080/main.da4909e4.js:8557
    init http://localhost:9080/main.da4909e4.js:3254
    createComponent http://localhost:9080/main.da4909e4.js:6098
    createElm http://localhost:9080/main.da4909e4.js:6046
    createChildren http://localhost:9080/main.da4909e4.js:6185
    createElm http://localhost:9080/main.da4909e4.js:6070
    patch http://localhost:9080/main.da4909e4.js:6656
    _update http://localhost:9080/main.da4909e4.js:4058
    updateComponent http://localhost:9080/main.da4909e4.js:4187
    get http://localhost:9080/main.da4909e4.js:4601
    Watcher http://localhost:9080/main.da4909e4.js:4588
    mountComponent http://localhost:9080/main.da4909e4.js:4194
    $mount http://localhost:9080/main.da4909e4.js:8557
    init http://localhost:9080/main.da4909e4.js:3254
    createComponent http://localhost:9080/main.da4909e4.js:6098
    createElm http://localhost:9080/main.da4909e4.js:6046
    patch http://localhost:9080/main.da4909e4.js:6691
    _update http://localhost:9080/main.da4909e4.js:4058
    updateComponent http://localhost:9080/main.da4909e4.js:4187
    get http://localhost:9080/main.da4909e4.js:4601
    Watcher http://localhost:9080/main.da4909e4.js:4588
    mountComponent http://localhost:9080/main.da4909e4.js:4194
    $mount http://localhost:9080/main.da4909e4.js:8557
    parcelRequire<["../src/main.js"]< http://localhost:9080/main.da4909e4.js:33344
    newRequire http://localhost:9080/main.da4909e4.js:47
    parcelRequire http://localhost:9080/main.da4909e4.js:81
    <anonymous> http://localhost:9080/main.da4909e4.js:120
main.da4909e4.js:2057:13

What's my problem? Did I miss something? is it linked to some weird ts to js transpilation issue?

avoid displaying search box

hi,

is there any way to prevent search boxes from being displayed?

often times, they are not necessary and simply take up space.

hacks are also welcome :)

thanks
sharon

itemTitle: item title is not updated for newly added items in list

Version(if relevant): 1.0.0

7.5.0

Environment(if relevant):

vue 2.6.10

Code(if relevant):

see vue demo in you readme

See section itemTitleExample with items having property propertyExample1 set to 'foo', 'bar' and so on.

Expected:

When I add new item and change propertyExample1, itemTitle updates, jsut as it does for old items

Actual:

itemTitle is just the index in the array and does not update

image

Cannot find module '../typings/lib'.

Thanks a lot for this JSON-EDITOR,

I'm really happy I can reuse my old schema in angular2 but the following bug happens.

Version(if relevant): 1.0.0

Latest
"schema-based-json-editor": "^5.0.0"

Environment(if relevant):

Ionic 3.6.0

Error:

The following error appears 6 times:
typescript: node_modules/schema-based-json-editor/angular.d.ts, line: 7
Cannot find module '../typings/lib'.

   L6:  schema: common.Schema;
   L7:  initialValue: common.ValueType;
   L8:  updateValue: EventEmitter<common.ValidityValue<string | number | boolean | any[] | {

And the next one, one time:
typescript: node_modules/schema-based-json-editor/common.d.ts, line: 1
File '/Users/numerized/Work/00_Github/vitapp-ionic2-couch-editor/node_modules/src/lib.d.ts' not found.

how to contribute

可否写个contribute guide,我尝试自己跑这个项目时遇到了困难

  1. 需要在根目录和每个package下面npm i
  2. 需要npm link packages/core

尝试上述操作后npm run dev或者npm run watch后仍然无法打开测试demo,看起来是packages/core下面的文件缺失

is there any method to get expand/collapse state of button?

Version(if relevant): 1.0.0

Environment(if relevant):

Angular 8

based on collapse or expand state, want to perform some operation.
Is there any event gets trigger when we click on collapse/expand button and is there a way to get the button state whether it's in an expanded state or not and for which property?

Thanks

Module not found with webpack and react

Version(if relevant): 6.0.4

Environment(if relevant):

Code(if relevant):

npm i schema-based-json-editor
./node_modules/.bin/webpack

my webpack config ,

var json = require('./package.json')
module.exports = {
    devtool: 'cheap-module-eval-source-map',
    entry: {
        index: path.resolve(__dirname, "app/index.js"),
        vendor: Object.keys(json.dependencies)
    },
    output: {
        path: path.resolve(__dirname, './static/dist/js'),
        filename: '[name].[chunkhash:8].js',
        publicPath: '/static/dist/js'
    },
    module: {
        loaders: [
            {
                exclude: /(node_modules|bower_components)/,
                test: /\.jsx?$/,
                loader: 'babel-loader',
                query: { presets: ['env', 'react', 'stage-2'] }
            },
            { test: /\.css$/, loader: 'style-loader!css-loader' }
        ]
    },
    plugins:.......

Expected:

build success

Actual:

[599] multi axios core-js es6-promise react react-bootstrap react-dom react-redux react-router-bootstrap react-router-dom redux redux-thunk schema-based-json-editor 160 bytes {0} [built]
+ 753 hidden modules

ERROR in multi axios core-js es6-promise react react-bootstrap react-dom react-redux react-router-bootstrap react-router-dom redux redux-thunk schema-based-json-editor
Module not found: Error: Can't resolve 'schema-based-json-editor' in '/Users/xincai/git/toilet-device-app/web'
@ multi axios core-js es6-promise react react-bootstrap react-dom react-redux react-router-bootstrap react-router-dom redux redux-thunk schema-based-json-editor

Module not found: Error: Can't resolve 'vue-class-component'

When trying to use the Vue-component i get the following error:

ERROR in ./~/schema-based-json-editor/dist/vue.js
Module not found: Error: Can't resolve 'vue-class-component' in '/Users/sli/Documents/shub/connectors/hbci_parser_api/src/web-frontend/node_modules/schema-based-json-editor/dist'
 @ ./~/schema-based-json-editor/dist/vue.js 3:28-58

As vue-class-component is imported/required in the compiled component, this module probable needs to be listed as npm dependency. In contrast to being a dev-dependency.

Unfortunately after installing it and being able to compile, the component causes an error (Uncaught ReferenceError: __extends is not defined) during runtime. I'll take a deeper look into it and keep you updated.

support vue2

is it possible to support vue2 so that my old vue2 based project can use it :-)

making a field read only

hi,

i hope to be able to contribute some day :) i see all those "help wanted" but haven't mastered the source well enough, hope to do so soon.

regarding a field that has an initial value which i don't want to be changed, i know there's such a flag in the editor, but can it be accessed here?

thanks a lot
sharon

when schema changes, fields are not updated

hi,

thanks for your support !

not sure if this is a bug in the editor itself or in the component, but when i change some field name, the changes are not reflected in the editor:

  • it seems like the "required" part is updated
  • but the field name itself is not. the result is that the field is not considered required anymore

you can replicate with the attached example, click on 'onClick1' and then 'onClick2'. the field 'firstName' is renamed in the schema by the code (see app.vue) to 'firstName2', but you can see that it's not reflected in the editor.

a workaround is also good at this point...

thanks
sharon
example.zip

JSONEditor component not re-rendering on change of props

Version: 8.3.0

Environment: Using create-react-app with typescript, packaged with npm.

Code:

I have a simple react application which has a 'user' page and an 'admin' page. For now this is not attached to any API calls, instead I have an array of objects stored inside 'templates', each object is a 'template' with information about fields required, their datatypes, any restrictions etc. The user page should have an interface where the user can select which collection to use, and a form which renders based on this selection. It also has a submit button to add their entry somewhere - this is still in development.

Below is the snippet of code relating to this issue.

import { JSONEditor, ObjectSchema, Schema, ValueType } from "react-schema-based-json-editor";
type JSXNode = JSX.Element | null;
interface field {
    "name": string,
    "description": string,
    "type": string,
    "value": string | number,
    "units": string,
    "options": string[],
    "validation": string
}

interface collection {
    "id": number,
    "version": string,
    "name": string,
    "beamline": string,
    "owner": string,
    "fields": field[]
}

templates: collection[] = [
    {
        "id": 1,
        "version": "v1.0.0",
        "name": "Ptychography",
        "beamline": "I14",
        "owner": "Testy McTestface",
        "fields": [
            {
                "name": "composition",
                "description": "Element composition of your sample",
                "type": "string",
                "value": "", // the default value to be used.
                "units": "",
                "options": []
            },
            {
                "name": "weight",
                "description": "Weight, in grams, of your sample",
                "type": "number",
                "value": 20, // the default value to be used.
                "units": "g",
                "options": []
            },
            {
                "name": "motor",
                "description": "The motor to be used - one of two.",
                "type": "string",
                "value": "", // the default value to be used.
                "units": "",
                "options": [
                    "motor1",
                    "motor2"
                ]
            }
        ]
    },
    {
        "id": 2,
        "version": "v1.0.0",
        "name": "Crystallography",
        "beamline": "B07",
        "owner": "Hakuna Matata",
        "fields": [
            {
                "name": "composition",
                "description": "Element composition of your sample",
                "type": "string",
                "value": "",
                "units": "",
                "options": []
            },
            {
                "name": "state",
                "description": "The state of matter to be used.",
                "type": "string",
                "value": "",
                "units": "",
                "options": []
            },
            {
                "name": "motor",
                "description": "The motor to be used - one of two.",
                "type": "string",
                "value": "motor1",
                "units": "",
                "options": [
                    "motor1",
                    "motor2"
                ]
            }
        ]
    }
}

// to be passed as input to JSONEditor element for schema.
function generateSchema(coll: collection | undefined): ObjectSchema | undefined {
	const schemaProperties: { [name: string]: Schema } | undefined = coll ?
		coll.fields.reduce<{ [name: string]: Schema }>((result, field) => {
			const schema: Schema = {
				type: field.type as "string",
				description: field.description,
				default: field.value,
				enum: field.options.length > 0 ? field.options : undefined,
			}
			return {
				[field.name]: schema,
				...result
			};
		}, {}) : undefined;

	if (schemaProperties && coll) {
		const generatedSchema: ObjectSchema = {
			title: coll.name,
			type: "object",
			properties: schemaProperties,
			required: Object.keys(schemaProperties),
			collapsed: false
		};
		return generatedSchema;
	}
	return undefined;
}

// to be passed as input to JSONEditor element for InitialValue.
function generateInitialVals(schema: ObjectSchema | undefined): ValueType | undefined {
	if (schema) {
		const initialVals = Object.entries(schema.properties).reduce<{ [name: string]: ValueType }>(
			(result, pair) => {
				const [k, v] = pair;
				result[k] = v.default;
				return result;
			}, {}
		)
		return initialVals;
	}
	return undefined;
}


function MakeForm(props: { useCollection: collection | undefined }): JSXNode {
	const coll: collection | undefined = props.useCollection;
	const collSchema = generateSchema(coll);
	const initialValue = generateInitialVals(collSchema);

	const [values, setValues] = useState<ValueType>(initialValue)

	if (!coll)
		return (
			<h1>Select a valid template</h1>
		)

	console.log("schema is: ", collSchema);


	const updateValue = (value: any, isValid: boolean) => {
		if (isValid) setValues({ ...value });
	};
	return (
		<div>
			<JSONEditor schema={collSchema as ObjectSchema} updateValue={updateValue} initialValue={initialValue} v-if="visible" theme="bootstrap5" />
		</div>
	);
}

function UserPage() {
	const collections = [...templates.map(item => item.name)];
	const [coll, setColl] = useState<string>("");

	return (
		<div className="App">
			<header className="App-header">Welcome, User!</header>
			<body className="App-body">
				<SelectCollection collections={collections} coll={coll} setColl={setColl} />
				<MakeForm useCollection={templates.find(c => c.name === coll)} />
				<SubmitButton />
			</body>
		</div>
	);
}

function App() {
  return (
    <div>
      <NavigationBar />
      <main>
        <Routes>
          <Route path="/" element={<h1>Home Page</h1>} /> 
          <Route path="/admin" element={<AdminPage />} />
          <Route path="/user" element={<UserPage />} />
        </Routes>
      </main>
    </div>
  )
}

In reality, the code from above is spread across multiple files, but is included here for completeness in one chunk. Finally, the index.tsx looks like the following:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.css';
import { BrowserRouter } from "react-router-dom";

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

reportWebVitals();

Expected:

When running npm start and navigating to /user, I expect to see a dropdown button (from my SelectCollection function component) which lets me select a template by name, i.e. 'Ptychography' or 'Crystallography'. When this is selected, the MakeForm component recieves a prop which is the actual collection corresponding to that name. It then should re-render and create a form based on a generated schema using this template. If I select another collection name from the dropdown which exists in the templates array such as 'Crystallography', I would expect the MakeForm component to re-render, and the resulting form from JSONEditor to change to reflect the changed schema.

Actual:

Once I select 'Ptychography', the form entries do not change if I then select 'Crystallography'. Instead, any form elements which are required only by 'Ptychography' now have a 'not exists' checkbox next to them. It seems as though the schema does not change, when in fact I can verify the schema is correctly being generated with console logging. Only if I refresh the page and select 'Crystallography' does the correct form show up.

It seems as though JSONEditor is just not re-rendering. A useEffect hook hasnt helped with this either.

Problems with peer dependencies in Angular

Version: 7.20.0

I run Angular 7:

CLI: "@angular/cli": "^7.0.4"

    "@angular/animations": "^7.0.2",
    "@angular/common": "^7.0.2",
    "@angular/compiler": "^7.0.2",
    "@angular/core": "^7.0.2",
    "@angular/forms": "^7.0.2",
    "@angular/http": "^7.0.2",
    "@angular/platform-browser": "^7.0.2",
    "@angular/platform-browser-dynamic": "^7.0.2",
    "@angular/router": "^7.0.2"

and I have issues installing/using your module.

Code:

npm WARN [email protected] requires a peer of @angular/common@5 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@5 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/forms@5 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/common@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/common@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/forms@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/common@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/forms@6 but none is installed. You must install peer dependencies yourself.

And if I install the dependencies manually and run the app:

ERROR in node_modules/angular-schema-based-json-editor/dist/index.component.d.ts(66,35): error TS2307: Cannot find module 'schema-based-json-editor/node_modules/markdown-tip'.
node_modules/schema-based-json-editor/dist/index.d.ts(385,8): error TS1192: Module '"<path to project>/node_modules/@types/dragula/index"' has no default export.
node_modules/schema-based-json-editor/dist/index.d.ts(386,8): error TS1192: Module '"<path to project>/node_modules/@types/markdown-it/index"' has no default export.
node_modules/schema-based-json-editor/dist/index.d.ts(386,22): error TS2305: Module '"<path to project>/node_modules/@types/markdown-it/index"' has no exported member 'MarkdownIt'.
node_modules/schema-based-json-editor/dist/index.d.ts(386,34): error TS2305: Module '"<path to project>/node_modules/@types/markdown-it/index"' has no exported member 'Token'.
node_modules/schema-based-json-editor/dist/index.d.ts(386,54): error TS2305: Module '"<path to project>/node_modules/@types/markdown-it/index"' has no exported member 'Renderer'.
node_modules/schema-based-json-editor/dist/index.d.ts(387,8): error TS1192: Module '"<path to project>/node_modules/@types/highlight.js/index"' has no default export.

Can you reproduce this issue?

'MarkdownIt' only refers to a type, but is being used as a value here

Hi!

Trying schema-based-json-editor version 5.1.2, I get an error when compiling my TypeScript:

 error  in /path/to/my/project/node_modules/schema-based-json-editor/libs.d.ts

(8,37): error TS2693: 'MarkdownIt' only refers to a type, but is being used as a value here.

According to my package-lock.json, my version of @types/markdown-it is 0.0.4 (as required).

I'm still a beginner with TypeScript so I don't really know where that is coming from.

How to control property title size in nested schema?

Version(if relevant): 1.0.0

7.20.3

Environment(if relevant):

Vue 2.6.6

My schema is few levels deep, i.e. object contains object which contains list, which contains object.
Title font size is the same for all titles, with default class h3. If I set className property in schema to something and override font-size property via css, font-size changes only for the titles of properties in deepest elements. I would like to to be able to set different font sizes for titles of objects/lists in my schema.

how to hide or remove 'not exists' checkbox.

Version(if relevant): 1.0.0

Environment(if relevant):

I'm using angular verrsion 8.0.0

Code(if relevant):

<json-editor [schema]="schema"
[initialValue]="value"

theme="bootstrap3"
icon="fontawesome4">

in appcomponent.ts file, I have defined schema object as below
schema = {
type : 'object',
title: 'schema generator',
description: 'dfdfd',
properties: {
stringExample : {
type: 'string',
title: 'A string example',
description: 'a string description',
default: 'a default string example',
minLength: 15,
maxLength: 20,
propertyOrder: 1
},
stringExample1 : {
type: 'string',
title: 'Name',
description: 'Name',
default: 'Rajesh',
minLength: 15,
maxLength: 20,
propertyOrder: 2
}
}
};

here I'm expecting to show only 2 text boxes but after executing above code, in addition with textboxes, it shows 2 checkboxes and 1 button control. 
checkboxes which has caption 'not exists' . Basically it toggles the other textbox visibility. 
is there any way to hide or unshow this checkbox and directly shows textboxes?


No style is applied

Version:

8.2.1

Code:

<JSONEditor
                schema={schema}
                initialValue={content}
                updateValue={() => console.log('UPDATED')}
                theme="bootstrap3"
                icon="bootstrap3"
            />

Expected:

bootstrap3 styles are applied

Actual:

bootstrap3 styles are not applied, despite bootstrap css is included on page.
Do you have any example how the styling can be applied in react app?
Thanks!

JavaScript error for non-required, non-existent array object members

Thanks for the wonderful project! I ran into an issue with the following JSON schema:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
    },
    "aliases": {
      "type": "array",
      "items": {
        "type": "string",
      }
    }
  }
}

The important thing is the aliases property and the fact that it is not required. Everything works fine as long as the aliases entry is present in the initial value:

value: {
  "name": "Michael",
  "aliases": ["Mike"]
}

However, as soon as it is omitted (which is allowed by the schema)

value: {
  "name": "Michael"
}

the browser console reports the error TypeError: _ctx.value is undefined (Firefox) or variables.js:75 Uncaught (in promise) TypeError: Cannot read property 'length' of undefined (Chromium)

The same error happens if the checkbox labeled "not exists" at the array property is checked.

Version: 8.1.0

Environment:

  • Firefox 78.8.0esr (64-bit);
  • Chromium: 88.0.4324.182 (Developer Build) built on Debian 10.8, running on Debian 10.8 (64-bit)

I hope this is the right place to report this ;-)

All buttons are not rendered correctly.

Version(if relevant): 7.7.3

Environment(if relevant): Mac Chrome Version 64.0.3282.186 (Official Build) (64-bit), Vue 2.5.2, theme: bootstrap4, icon: null

Expected:

Buttons in the vue.js example are rendered correctly. For instance, the collapse button that comes with the arrayExample is rendered as follows.
image

Actual:

When playing with this library, my buttons are not rendered correctly.
image
So visually, all buttons are not visible on the rendered page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.