-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add JSON object navigation #32
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
Conversation
| const encodeLog = (log: SandpackConsoleData): Message => { | ||
| // deep copy the log.data array | ||
| if (!log.data) { | ||
| return Decode([]) as Message; | ||
| } | ||
| const modifiedDataArray = log.data as [Message, string]; | ||
| if (Array.isArray(modifiedDataArray)) { | ||
| // Due to formatting changes with console-feed's encode function in v3.4 | ||
| // we need to manually add in the remainder key to note that there | ||
| // are no more items remaining | ||
| modifiedDataArray.push("__console_feed_remaining__0"); | ||
| // Objects all need to have a constructor property now too | ||
| // unless it is null | ||
| modifiedDataArray.forEach((dataItem) => { | ||
| if ( | ||
| typeof dataItem !== "string" && | ||
| (dataItem as unknown as SandpackEncodedLog)?.["@t"] | ||
| ) { | ||
| const sandpackEncodedLog = dataItem as unknown as SandpackEncodedLog; | ||
| if (sandpackEncodedLog["@t"] === "[[undefined]]") { | ||
| return; | ||
| } | ||
|
|
||
| // Hey keep going and actually write this as a function to note | ||
| // that we are essentially an adapter for v3.3 and the newest version of console-feed | ||
| const constructorType = sandpackEncodedLog?.["@t"]?.slice(2, -2); | ||
| Object.assign(dataItem, { | ||
| constructor: { | ||
| name: constructorType, | ||
| }, | ||
| }); | ||
| delete sandpackEncodedLog["@t"]; | ||
| } | ||
| }); | ||
| } | ||
| return Decode([{ ...log, data: modifiedDataArray }]) as Message; | ||
| }; |
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.
This is the adapter required to go from v3.3 to v3.8 or newer. Sandpack already encodes the console messages with console-feed but using v3.3, causing some odd crashes and type issues since we are using 3.8 to decode. We could also use v3.3 for console-feed but we lose React 19 support.
| background: "var(--sp-colors-surface1)", | ||
| lineHeight: "var(--sp-font-lineHeight)", | ||
| }} |
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.
These tokens will be replaced in the following PR for styles.
| export const ConsoleOutputWithDifferentDataTypes: Story = { | ||
| args: { | ||
| defaultValue: `// Console output with different data types | ||
| // This story stress tests the console output with various JavaScript data types | ||
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.
This adds a stress test for the console output.
| // Disable unused exports rule for Storybook files | ||
| { | ||
| files: ["**/*.stories.{ts,tsx}", ".storybook/*.{ts,tsx}"], | ||
| rules: { | ||
| "fast-import/no-unused-exports": "off", | ||
| }, | ||
| }, |
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.
Disabling these rules just for storybook files
packages/docs-md/src/components/TryItNow/ConsoleOutput/index.tsx
Outdated
Show resolved
Hide resolved
nebrius
left a comment
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.
Meant to hit approve. Looks good aside from two small things.
* add basic storybook setup * add basic nesting view to jsonViewer * add indentation levels and basic color mapping * add nesting example and fix comma bug * add no wrap to avoid breaking spaces * add null syntax coloring * fix expansion bug with duplicate keys * refactor for perf improvements * add proper color theming to json viewer * update dependencies * add console-feed and console-feed adapter * removing testing output * add more comments * update package-lock * remove ref from SandpackPreview * disable import rules for eslint * remove storybook from tsconfig * ignore bootstrap storybook files in eslint * remove unneeded type and add image types to lfs gitattributes
This PR adds