-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS Objects in Knobs addon #1460
Conversation
@z4o4z looks cool! will check it out later today. in the meantime how big (KB) is the ace-editor/brace dependency? |
@shilman Hi, all new libs(react-ace, brace, brace/mode/javascript, brace/theme/github) have size about 710kb (not gzip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the ability to read a knobs object. it's been really annoying seeing [object],[object]
I'll leave it up to others whether the editor is worth adding to our codebase.
const { knob } = this.props; | ||
const getSpaces = level => Array.from({ length: level * 2 }, () => ' ').join(''); | ||
|
||
function toString(obj, spaceLevel = 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason why were manually converting objects? seems kind of fragile.
we can probably just do json.stringify
and then pass it through some js beautifier or insert spaces ourselves.
kind of an edge case, but if there's a circular dependency somewhere, this would hang too.
i.e.: const obj = { key: this }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @danielduan . I didn't use json.stringify because I tried to add support for functions. In future we can add support for other JS features(regexp, Map, Set, and etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. thanks @z4o4z
@tmeasday @ndelangen any thoughts on this re: code bloat with the new editor? |
@z4o4z Finally had a chance to test this out. Love ❤️ the Object support and the function support is really funky and cool. I also think:
What do you think? I'm happy to do some of this work, or load-balance. |
For @ndelangen |
Hi @shilman, Excellent suggestions! I will add demos to
|
minor linting error:
|
@z4o4z Can you take another look at this? I think the snapshots are outdated! |
@ndelangen yep |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks! |
}), | ||
onChange: PropTypes.func, | ||
}; | ||
|
||
ObjectType.serialize = object => JSON.stringify(object); | ||
ObjectType.deserialize = value => (value ? JSON.parse(value) : {}); | ||
ObjectType.deserialize = value => eval(`(${value})`); // eslint-disable-line no-eval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some XSS protection here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we afraid of users scripting themselves or a knob url link with something potentially malicious inside it?
I think we can get around this by not allowing the javascript to be serialized into the URL if it's a real concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, mostly the latter. Storybooks are often hosted at some path of the main website, so you can make cookies leak this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎖 for you @Hypnosphi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it shouldn't be deserialized from URL, either. And it would be a regression comparing to what we have now
Maybe we should try to do plain JSON.parse
first, and just give up if it fails AND the value comes from URL
@z4o4z do you think you can remove the js object serialization so we can move this PR forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1460 (comment)
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Issue:
#1187 #1186
What I did
Added JS Objects support to Knobs addon
Added react-ace as code editor
How to test
npm run storybook
- look at 'with object' story