Skip to content

Commit 9735ca8

Browse files
improvement(files): keep the diff parser out of the editor bundle
1 parent 3431935 commit 9735ca8

6 files changed

Lines changed: 16 additions & 22 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/code-block.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Check, ChevronDown, Code, Duplicate, Eye, Wrap } from '@sim/emcn/icons'
1212
import type { ReactNodeViewProps } from '@tiptap/react'
1313
import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react'
1414
import { DASHBOARD_EMBED_LANGUAGE } from '@/lib/dashboards/embed-language'
15-
import { DIFF_EMBED_LANGUAGE } from '@/lib/diff/unified'
15+
import { DIFF_EMBED_LANGUAGE } from '@/lib/diff/embed-language'
1616
import { MarkdownStreamingContext } from '@/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-streaming-context'
1717
import { looksLikeMermaid, MermaidDiagram } from '../mermaid-diagram'
1818
import { MarkdownCodeBlock } from './code-block-schema'

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.css‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@
283283
overflow-x: auto;
284284
}
285285

286-
/* A rendered Mermaid diagram sits on the workflow canvas surface: flat page background, a hairline
287-
frame, centered. */
286+
/* A rendered Mermaid diagram matches the workflow canvas surface. */
288287
.rich-markdown-prose .mermaid-diagram-frame {
289288
display: flex;
290289
justify-content: center;

‎apps/sim/components/diff/diff-embed.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { type ComponentType, type ReactNode, useMemo } from 'react'
3+
import type { ComponentType, ReactNode } from 'react'
44
import { cn } from '@sim/emcn'
55
import { ArrowUpRight, Database, File } from '@sim/emcn/icons'
66
import { getErrorMessage } from '@sim/utils/errors'
@@ -223,7 +223,6 @@ function ExcerptCard({ heading, diff, side }: ExcerptCardProps) {
223223
)
224224
}
225225

226-
/** An edit, line by line: tinted rows with word-level changes. */
227226
function CodeDiff({ diff, heading }: CodeDiffProps) {
228227
const Icon = heading.icon
229228
return (
@@ -262,7 +261,7 @@ function parse(
262261
export function DiffEmbed({ source, isStreaming }: DiffEmbedProps) {
263262
const params = useParams()
264263
const workspaceId = typeof params.workspaceId === 'string' ? params.workspaceId : null
265-
const parsed = useMemo(() => parse(source), [source])
264+
const parsed = parse(source)
266265
const diff = parsed.diff
267266
const comparison = Boolean(
268267
diff?.oldSource && diff.newSource && !sameSource(diff.oldSource, diff.newSource)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** The fence language that renders a unified diff in markdown; kept apart from the parser. */
2+
export const DIFF_EMBED_LANGUAGE = 'diff'

‎apps/sim/lib/diff/unified.test.ts‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ describe('parseUnifiedDiff', () => {
4747
})
4848
})
4949

50+
it('names each side of a two-document comparison', () => {
51+
const diff = parseUnifiedDiff(
52+
'--- sim:knowledge/kb/old\n+++ sim:knowledge/kb/new\n-Refunds are available within 14 days.\n+Annual plans can be refunded within 30 days.'
53+
)
54+
expect([diff.oldSource, diff.newSource]).toEqual([
55+
{ kind: 'knowledge', knowledgeBaseId: 'kb', documentId: 'old' },
56+
{ kind: 'knowledge', knowledgeBaseId: 'kb', documentId: 'new' },
57+
])
58+
})
59+
5060
it.each([
5161
['a knowledge source without a document', '--- sim:knowledge/kb_1\n-x\n+y', 'sim:knowledge/'],
5262
['a line without a marker', '@@ x @@\n-a\nplain', 'Line 3'],
@@ -55,16 +65,3 @@ describe('parseUnifiedDiff', () => {
5565
expect(() => parseUnifiedDiff(text)).toThrow(message)
5666
})
5767
})
58-
59-
describe('two-document comparisons', () => {
60-
const diff = parseUnifiedDiff(
61-
'--- sim:knowledge/kb/old\n+++ sim:knowledge/kb/new\n-Refunds are available within 14 days.\n+Annual plans can be refunded within 30 days.'
62-
)
63-
64-
it('names each side', () => {
65-
expect([diff.oldSource, diff.newSource]).toEqual([
66-
{ kind: 'knowledge', knowledgeBaseId: 'kb', documentId: 'old' },
67-
{ kind: 'knowledge', knowledgeBaseId: 'kb', documentId: 'new' },
68-
])
69-
})
70-
})

‎apps/sim/lib/diff/unified.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/** The fence language that renders a unified diff in markdown; kept apart from the parser. */
2-
export const DIFF_EMBED_LANGUAGE = 'diff'
3-
41
/** A workspace resource a diff was taken from, named in its `---` / `+++` header lines. */
52
export type DiffSource =
63
| { kind: 'file'; fileId: string }

0 commit comments

Comments
 (0)