diff --git a/apps/web/src/components/ui/report/AppReport.stories.tsx b/apps/web/src/components/ui/report/AppReport.stories.tsx index b255ddb02..cfd86917d 100644 --- a/apps/web/src/components/ui/report/AppReport.stories.tsx +++ b/apps/web/src/components/ui/report/AppReport.stories.tsx @@ -1,6 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; import { AppReport } from './AppReport'; -import type { Value } from 'platejs'; import { ReportElement } from '@buster/server-shared/reports'; const meta = { @@ -77,8 +76,34 @@ const sampleValue = [ { type: 'code_block', lang: 'javascript', - children: [{ text: 'const greeting = "Hello, World!";\nconsole.log(greeting);' }] + children: [ + { + type: 'code_line', + children: [{ text: 'const greeting = "Hello, World!";' }] + }, + { + type: 'code_line', + children: [{ text: 'console.log(greeting);' }] + }, + { + type: 'code_line', + children: [{ text: '}' }] + } + ] }, + { + children: [ + { children: [{ text: 'function hello() {' }], type: 'code_line' }, + { + children: [{ text: " console.info('Code blocks are supported!');" }], + type: 'code_line' + }, + { children: [{ text: '}' }], type: 'code_line' } + ], + lang: 'javascript', + type: 'code_block' + }, + { type: 'h1', children: [{ text: 'Hello' }] diff --git a/apps/web/src/components/ui/report/elements/BlockDraggable.tsx b/apps/web/src/components/ui/report/elements/BlockDraggable.tsx index 99c1e2a5e..5c4dc4c01 100644 --- a/apps/web/src/components/ui/report/elements/BlockDraggable.tsx +++ b/apps/web/src/components/ui/report/elements/BlockDraggable.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; import { DndPlugin, useDraggable, useDropLine } from '@platejs/dnd'; import { BlockSelectionPlugin } from '@platejs/selection/react'; import { GripDotsVertical } from '@/components/ui/icons'; -import { getContainerTypes, getPluginByType, isType, KEYS, type TElement } from 'platejs'; +import { getPluginByType, isType, KEYS, type TElement } from 'platejs'; import { type PlateEditor, type PlateElementProps, diff --git a/apps/web/src/components/ui/report/elements/CodeBlockNode.tsx b/apps/web/src/components/ui/report/elements/CodeBlockNode.tsx index 6744159b7..a3dd61dfa 100644 --- a/apps/web/src/components/ui/report/elements/CodeBlockNode.tsx +++ b/apps/web/src/components/ui/report/elements/CodeBlockNode.tsx @@ -9,10 +9,10 @@ import { type PlateElementProps, type PlateLeafProps, PlateElement, - PlateLeaf, - useSelected + PlateLeaf } from 'platejs/react'; import { useEditorRef, useElement, useReadOnly } from 'platejs/react'; + import { Button } from '@/components/ui/buttons'; import { Command, @@ -33,11 +33,9 @@ export function CodeBlockElement(props: PlateElementProps) { return ( -
+
           {props.children}
         
diff --git a/packages/server-shared/src/reports/report-elements.ts b/packages/server-shared/src/reports/report-elements.ts index d04d5ebe4..d4f7025f4 100644 --- a/packages/server-shared/src/reports/report-elements.ts +++ b/packages/server-shared/src/reports/report-elements.ts @@ -46,10 +46,17 @@ export const BlockquoteElement = z }) .merge(AttributesSchema); +const CodeLineElement = z.object({ + type: z.literal('code_line'), + children: z.array(SimpleTextSchema), +}); + export const CodeBlockElement = z.object({ type: z.literal('code_block'), - lang: z.enum(['sql', 'yaml', 'javascript', 'typescript', 'python', 'bash', 'json']), - children: z.array(SimpleTextSchema), + lang: z + .enum(['sql', 'yaml', 'javascript', 'typescript', 'python', 'bash', 'json']) + .default('sql'), + children: z.array(CodeLineElement), }); export const CalloutElement = z