import React from 'react'
import { Meta, StoryObj } from '@storybook/react'
import JsonView from '../index'
import { argTypes, largeArray } from './share'
import { stringifyForCopying } from '../utils'
type TYPE_FC = typeof JsonView
export default {
title: 'Editable',
component: JsonView,
argTypes,
args: {
enableClipboard: true,
editable: true,
src: {
string: 'string',
longString: 'long string long string long string long string long string long string',
number: 123456,
boolean: false,
null: null,
func: function () {
console.log('Hello World')
},
Symbol: Symbol('JSON View'),
obj: {
k1: 123,
k2: '123',
k3: false
},
arr: ['string', 123456, false, null]
},
onEdit: ({ newValue, src, oldValue, indexOrName }) => {
console.log('[onEdit]', indexOrName, newValue, oldValue, src)
},
onDelete: ({ value, src, indexOrName }) => {
console.log('[onDelete]', indexOrName, value, src)
},
onAdd: ({ src, indexOrName }) => {
console.log('[onAdd]', indexOrName, src)
},
onChange: ({ src, indexOrName }) => {
console.log('[onChange]', indexOrName, src)
}
},
decorators: [
Story => (
)
]
} as Meta
export const Primary: StoryObj = {}
export const DisplaySize: StoryObj = {
args: {
src: {
string: 'string',
longString: 'long string long string long string long string long string long string',
number: 123456,
boolean: false,
null: null,
func: function () {},
Symbol: Symbol('JSON View'),
arr: ['string', 123456, false, null],
nest: {
nest: {
nest: {
nest: {
over: 'over'
}
}
}
}
},
displaySize: 'collapsed'
}
}
export const XS: StoryObj = {
decorators: [
Story => (
)
]
}
export const LG: StoryObj = {
decorators: [
Story => (
)
]
}
export const XL: StoryObj = {
decorators: [
Story => (
)
]
}
export const String: StoryObj = {
args: {
src: 'string'
}
}
export const LongString: StoryObj = {
args: {
src: 'long string long string long string long string'
}
}
export const Number: StoryObj = {
args: {
src: 12312312321
}
}
export const Null: StoryObj = {
args: {
src: null
}
}
export const Boolean: StoryObj = {
args: {
src: true
}
}
export const Undefined: StoryObj = {
args: {
src: undefined
}
}
export const Collapsed_Boolean: StoryObj = {
args: {
src: {
string: 'string',
longString: 'long string long string long string long string long string long string',
number: 123456,
boolean: false,
null: null,
func: function () {},
Symbol: Symbol('JSON View'),
obj: {
k1: 123,
k2: '123',
k3: false
},
arr: ['string', 123456, false, null]
},
collapsed: true
},
decorators: [
Story => (
)
]
}
export const Collapsed_Number: StoryObj = {
args: {
src: {
boolean: false,
null: null,
obj: {
k1: 123,
k2: '123',
k3: false,
k4: {
k: {
k: {
k: 'k5'
}
}
}
},
arr: ['string', 123456, false, null, [123, 123, 123, [123, 123, 123]]]
},
collapsed: 2
},
decorators: [
Story => (
)
]
}
export const Editable_Options: StoryObj = {
args: {
src: {
boolean: false,
null: null,
obj: {
k1: 123,
k2: '123',
k3: false,
k4: {
k: {
k: {
k: 'k5'
}
}
}
},
arr: ['string', 123456, false, null, [123, 123, 123, [123, 123, 123]]]
},
editable: {
add: false,
edit: true,
delete: false
}
},
decorators: [
Story => (
)
]
}
export const MatchesURL: StoryObj = {
args: {
src: {
string: 'string',
link: 'https://www.google.com/',
number: 123456,
boolean: false,
null: null,
func: function () {},
Symbol: Symbol('JSON View'),
obj: {
k1: 123,
k2: '123',
k3: false
},
arr: ['string', 123456, false, null]
},
matchesURL: true,
editable: true
}
}
export const CustomizeCopy: StoryObj = {
args: {
src: {
string: 'string',
link: 'https://www.google.com/',
number: 123456,
boolean: false,
null: null,
func: function () {},
Symbol: Symbol('JSON View'),
obj: {
k1: 123,
k2: '123',
k3: false
},
arr: ['string', 123456, false, null]
},
editable: true,
customizeCopy: (node: any) => stringifyForCopying(node, 4)
}
}
export const LargeArray: StoryObj = {
args: {
src: {
obj: {
k1: 123,
k2: '123',
k3: false
},
largeArray: largeArray
},
editable: true,
displaySize: true,
collapsed: 2
}
}