-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTriggerMarkdownBlock.tsx
More file actions
67 lines (55 loc) · 2.11 KB
/
Copy pathTriggerMarkdownBlock.tsx
File metadata and controls
67 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { NodesAnimation } from "../animations/NodesAnimation"
import type { NodeItem, NodeSegment } from "../nodes/NodeDisplay"
interface TriggerMarkdownBlockProps {
source: string
title?: string
}
const colorCycle: NodeItem["color"][] = ["brand", "aqua", "yellow", "pink", "blue"]
const parseTriggerLine = (line: string, index: number): NodeItem => {
const trimmed = line.trim().replace(/;$/, "")
const match = trimmed.match(/^([^:\s]+):([^\s]+)\s+(.+)$/)
if (!match) {
return {
color: colorCycle[index % colorCycle.length],
outline: true,
segments: [{ type: "text", value: trimmed }],
}
}
const [, sourceSystem, targetNode, description] = match
const segments: NodeSegment[] = [
{ type: "reference", value: sourceSystem },
{ type: "node", value: targetNode },
{ type: "text", value: description },
]
return {
color: colorCycle[index % colorCycle.length],
outline: true,
segments,
}
}
const toNodes = (source: string) => {
let nodeIndex = 0
return source.split(/\r?\n/).flatMap((rawLine) => {
const line = rawLine.trim()
if (!line) return []
return [parseTriggerLine(line, nodeIndex++)]
})
}
export function TriggerMarkdownBlock({ source, title }: TriggerMarkdownBlockProps) {
const nodes = toNodes(source)
if (nodes.length <= 0) return
return (
<div className="my-6 overflow-hidden rounded-3xl bg-light ring ring-white/10">
{title && <div className="flex items-center gap-2 border-b border-white/10 bg-primary/50 px-6 py-3 text-xs font-semibold tracking-wide text-secondary">{title?.trim()}</div>}
<div
className="py-4"
style={{
maskImage: "linear-gradient(to right, transparent 0%, black 10%, black 90%, transparent 100%)",
WebkitMaskImage: "linear-gradient(to right, transparent 0%, black 10%, black 90%, transparent 100%)",
}}
>
<NodesAnimation nodes={nodes} />
</div>
</div>
)
}