Giter VIP home page Giter VIP logo

vue-json-component's Introduction

Vue JSON Component

npm version TypeScript npm bundle size License: MIT code style: prettier

Demo

A collapsable tree view for JSON. This package has some similarites with vue-json-tree-view so I'll address the differences below. I'm not contributing this back to that package because it would require breaking API changes, and the code is entirely different. Contributions welcome!

demo image

Philosophy

This package has a few major improvements over predecessors: builds, styles, and customization. For builds, this package ships CommonJS, Module, and UNPKG builds with no dependencies. vue-json-tree-view bundles in lots of dependencies -- including lodash. I also export global Vue imports, local Vue imports, and TypeScript declarations. The code itself is about as small as it can be while being easy to follow.

The styles in this package are all scoped, with key colors still being customizable. There are no extra margins or overflow rules and text properties are all inherited from the page. This makes the view much easier to integrate anywhere you need it.

The default color theme is based on solarized, and font weights are modified to increase readability. The component uses semantic HTML elements and tries to be fully keyboard accessible.

Usage

Install

npm i vue-json-component
yarn add vue-json-component

Import Locally

import { JSONView } from 'vue-json-component';
export default Vue.extend({
  components: { 'json-view': JSONView }
});

Import Globally

import JSONView from 'vue-json-component';
Vue.use(JSONView);

Use

<template>
  <json-view :data="data" />
</template>

Customize

The font size and font family are inherited from the page. The component now supports dark mode, and has switched to a CSS Variables based implementation.

Props

  • data (JSON): The valid JSON object you want rendered as a tree.
  • rootKey (String): The name of the top level root key; defaults to root.
  • maxDepth (Number): Depth of the tree that is open at first render; defaults to 1.
  • colorScheme (New) (String): Setting to 'dark' enables dark mode.

Styles

⚠️ This API has changed to CSS Variables. All of these can be customized for light and dark mode as is documented below.

--vjc-key-color: #0977e6;
--vjc-valueKey-color: #073642;
--vjc-string-color: #268bd2;
--vjc-number-color: #2aa198;
--vjc-boolean-color: #cb4b16;
--vjc-null-color: #6c71c4;
--vjc-arrow-size: 6px;
--vjc-arrow-color: #444;
--vjc-hover-color: rgba(0, 0, 0, 0.15);

Example

<template>
  <json-view
    :data="data"
    rootKey="view"
    :maxDepth="1"
    class="customize"
  />
</template>

<style lang="scss" scoped>
.customize {
  --vjc-valueKey-color: green;
}
.customize.dark {
  --vjc-valueKey-color: red;
}
</style>

Note: your styles will need to be scoped to override the scoped CSS Variables in the component.

Advanced Features

Selected Item Events

You can allow users to click elements, and receive an event when this occurs. The selected event will pass you the key, value, and path of the selected value. If you do not listen for the event, the styles will not indicate that values are clickable.

<json-view
  :data="data"
  v-on:selected="itemSelected"
/>

Event

  • key: string
  • value: string
  • path: string

Development

Install

yarn

Hot-Reload Hostapp

yarn serve

Build Component

yarn build

Lints and fixes files

yarn lint

Contributing

Contributions are welcome via pull request. If you want to discuss your feature before committing development time, feel free to open an issue and we can refine the idea.

Thanks!

vue-json-component's People

Contributors

adierkens avatar dependabot[bot] avatar tylerkrupicka 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

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-json-component's Issues

Props 'styles' not working

Hey, really nice work you did there, very useful !
Everything is working nice, except that I can't modify the style. I've been trying to directly write the object inside the props, or pass it an object written into a variable, but it has no effect.

Using your tree-component for displaying JSON data

Hi,

I want to build a Vue.js frontend (with TypeScript probably) for a versioned document store (https://sirix.io and https://github.com/sirixdb/sirix). That said I'm very new to the frontend world, in my day to day job I'm a backend engineer.

I'd like to begin with a simple tree-view maybe merging and displaying changes already in this view. However, to begin with I'd probably just want to display one revision of JSON-document, which is stored in a binary format in SirixDB. With a REST-API I can simply retrieve either the whole tree at once or... for instance always only the children which are visible in the tree-view.

I really like the look of your simple tree-component, especially as I don't have to convert the JSON data into another JSON format first. That said, I'd love to use a similar view for the XML-documents stored in SirixDB, too. Do you think that's relatively easy doable? Furthermore I like to change the indentation a bit and somehow I'm not really sure how I can serialize database resource internal stuff within my JsonSerializer as for instance unique node-Keys, which can be used to select a node directly (or what's the best JSON-format to add this type of metadata for object record keys for instance).

BTW: I'm always looking for collaborators, but yeah, maybe just a dream ;-) But I'm pretty sure that a great frontend, which displays the diffing capabilities of SirixDB in nice visualizations with D3js in the next step will make a huge difference :-)

kind regards
Johannes

Select a leaf item

Hi Tyler
Nice useful component, I like it. My question : is there a way to select a leaf item and get its value? I would like to emit it to the parent component.
Thank you

Luca

Error: Can't resolve 'tslib' in '/var/www/node_modules/vue-json-component/dist'

ERROR in ./node_modules/vue-json-component/dist/index.module.js
Module not found: Error: Can't resolve 'tslib' in '/var/www/node_modules/vue-json-component/dist'
 @ ./node_modules/vue-json-component/dist/index.module.js 1:0-33 429:40-48
 @ ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/Domain/Log/LogTable.vue?vue&type=script&lang=js&
 @ ./resources/js/Domain/Log/LogTable.vue?vue&type=script&lang=js&
 @ ./resources/js/Domain/Log/LogTable.vue
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/app.scss

yarn add tslib helped but seems that this is tricky workaround.

Viualize selected nodes

It would be awesome if the selected nodes had a slightly different styling. This way we could do:

data(){ 
    return {
        selectedPaths: [{ path: "root.foo.bar" }]
    }
}

This could then be supplied to the jsonView with:

<JSONView :data="model" @selected="updatePaths" v-if="loaded" :selection="selectedPaths" />

Problem with my version

hi. i fork your project for create my modified version of this vue-json-tree-view for a thesis project. I have some problem with build of this (maybe i'm not good at ts or idk).
I'm tryng to change the words at root node from nTot properties to nTot documents and each object from properties to fields .
Another work is to have pagination (the document/object that i represent have no name but your tool give a number. but for myself i create a pagination because of large number of objects but that aren't option for changing the first number of that document (it return to 0). if you can add these features i appreciate so much, or maybe you can give istruction fro building your project to my forked)

npm: command not found

I am trying to add Vue Json component to an existing project. I'm following the instructions but I am getting this error:

-bash: npm: command not found .

error in vue3

node_modules/vue-json-component/dist/index.module.js:1:25: error: Could not resolve "tslib" (mark it as external to exclude it from the bundle)

Broken for Vue3

I'm getting the following error when trying to use this component in a Vue 3 app.

✘ [ERROR] No matching export in "node_modules/vue/dist/vue.runtime.esm-bundler.js" for import "default"                                                                                                                                                                [80/1097]                                                                                                                                                                                                                                                                                    node_modules/vue-json-component/dist/index.module.js:2:7:
      2 │ import Vue from 'vue';                

11:48:01 AM [vite] error while updating dependencies:Error: Build failed with 1 error:                                                                                                                                                                                                                                               node_modules/vue-json-component/dist/index.module.js:2:7: ERROR: No matching export in "node_modules/vue/dist/vue.runtime.esm-bundler.js" for import "default"                                                                                                                      at failureErrorWithLog (/mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:1605:15)                                                                                                                                                                at /mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:1251:28
    at runOnEndCallbacks (/mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:1034:63)
    at buildResponseToResult (/mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:1249:7)
    at /mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:1358:14
    at /mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (/mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (/mnt/d/.../vue_7/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12) 

forms automatically submitted on interaction

When placed anywhere within a Vuetify v-form, ANY interaction with <json-view> (specifically, clicking on 'folder' node) automatically submits the form. Obviously, this is incorrect behavior. I can find no way to prevent this. Tried v-on:selected, which only appears to be fired on leaf node selection, not folder node selection, so it doesn't help.

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.