@tldiagram/core-ui 1.90.1 → 1.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +6768 -7231
- package/dist/pages/ViewEditor/hooks/useCanvasInteractions.d.ts +1 -1
- package/package.json +1 -1
- package/src/App.tsx +0 -4
- package/src/index.ts +0 -1
- package/src/pages/ViewEditor/components/EditorMenus.tsx +6 -4
- package/src/pages/ViewEditor/components/EditorOverlays.tsx +3 -2
- package/src/pages/ViewEditor/components/EmptyCanvasState.tsx +3 -2
- package/src/pages/ViewEditor/hooks/useCanvasInteractions.ts +17 -26
- package/src/pages/ViewEditor/hooks/useViewContextNeighbours.ts +1 -1
- package/src/pages/ViewEditor/index.tsx +103 -40
- package/dist/demo/DemoPage.d.ts +0 -9
- package/dist/demo/seed.d.ts +0 -9
- package/dist/demo/store.d.ts +0 -137
- package/src/demo/DemoPage.tsx +0 -184
- package/src/demo/seed.ts +0 -67
- package/src/demo/store.ts +0 -536
package/src/demo/DemoPage.tsx
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Demo entry point.
|
|
3
|
-
* Overrides the real `api` singleton with localStorage-backed implementations
|
|
4
|
-
* and patches window.history to redirect /views/:id → /demo/:id, all for the
|
|
5
|
-
* lifetime of this component. Restores everything on unmount.
|
|
6
|
-
* No auth required; served at /demo and /demo/:id routes.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import React, { useEffect, useState } from 'react'
|
|
10
|
-
import { useNavigate } from 'react-router-dom'
|
|
11
|
-
import { Box } from '@chakra-ui/react'
|
|
12
|
-
import { api } from '../api/client'
|
|
13
|
-
import ViewEditor from '../pages/ViewEditor'
|
|
14
|
-
import { HeaderProvider } from '../components/HeaderContext'
|
|
15
|
-
import { ThemeProvider } from '../context/ThemeContext'
|
|
16
|
-
import { demoApi, initDemoStore } from './store'
|
|
17
|
-
import { DEMO_VIEW_EDITOR_OPTIONS } from './viewEditor'
|
|
18
|
-
|
|
19
|
-
// ── Override helpers ──────────────────────────────────────────────────────────
|
|
20
|
-
|
|
21
|
-
type ApiOverride = Record<string, unknown>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Swap api methods + patch window.history so any /views/:id navigation is
|
|
25
|
-
* silently rewritten to /demo/:id before React Router processes it.
|
|
26
|
-
* Returns a function that restores everything.
|
|
27
|
-
*/
|
|
28
|
-
function applyOverrides(): () => void {
|
|
29
|
-
const originals: [obj: ApiOverride, key: string, original: unknown][] = []
|
|
30
|
-
|
|
31
|
-
function swap(obj: ApiOverride, key: string, replacement: unknown) {
|
|
32
|
-
originals.push([obj, key, obj[key]])
|
|
33
|
-
obj[key] = replacement
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// elements
|
|
37
|
-
const realElements = api.elements as unknown as ApiOverride
|
|
38
|
-
const demoElements = demoApi.elements as ApiOverride
|
|
39
|
-
for (const key of ['list', 'get', 'create', 'update', 'delete', 'placements']) {
|
|
40
|
-
swap(realElements, key, demoElements[key])
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// workspace.elements
|
|
44
|
-
const realWsElements = (api.workspace as unknown as ApiOverride).elements as ApiOverride
|
|
45
|
-
const demoWsElements = demoApi.workspace.elements as ApiOverride
|
|
46
|
-
for (const key of ['list', 'get', 'create', 'update', 'delete', 'placements']) {
|
|
47
|
-
swap(realWsElements, key, demoWsElements[key])
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// workspace.orgs.tagColors
|
|
51
|
-
const realTagColors = ((api.workspace as unknown as ApiOverride).orgs as ApiOverride).tagColors as ApiOverride
|
|
52
|
-
const demoTagColors = demoApi.workspace.orgs.tagColors as ApiOverride
|
|
53
|
-
for (const key of ['list', 'set']) {
|
|
54
|
-
swap(realTagColors, key, demoTagColors[key])
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// workspace.views top-level methods + nested namespaces
|
|
58
|
-
const realViews = (api.workspace as unknown as ApiOverride).views as ApiOverride
|
|
59
|
-
const demoViews = demoApi.workspace.views as ApiOverride
|
|
60
|
-
for (const key of ['list', 'get', 'content', 'tree', 'create', 'update', 'delete', 'thumbnail', 'rename', 'setLevel', 'reparent']) {
|
|
61
|
-
swap(realViews, key, demoViews[key])
|
|
62
|
-
}
|
|
63
|
-
for (const ns of ['placements', 'layers', 'reactions', 'threads']) {
|
|
64
|
-
const realNs = realViews[ns] as ApiOverride
|
|
65
|
-
const demoNs = demoViews[ns] as ApiOverride
|
|
66
|
-
for (const key of Object.keys(demoNs)) {
|
|
67
|
-
swap(realNs, key, demoNs[key])
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// workspace.connectors
|
|
72
|
-
const realConnectors = (api.workspace as unknown as ApiOverride).connectors as ApiOverride
|
|
73
|
-
const demoConnectors = demoApi.workspace.connectors as ApiOverride
|
|
74
|
-
for (const key of ['list', 'create', 'update', 'delete']) {
|
|
75
|
-
swap(realConnectors, key, demoConnectors[key])
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// explore.load (cross-branch graph snapshot)
|
|
79
|
-
const realExplore = (api as unknown as ApiOverride).explore as ApiOverride
|
|
80
|
-
swap(realExplore, 'load', demoApi.explore.load)
|
|
81
|
-
|
|
82
|
-
// ── Patch window.history so /views/:id → /demo/:id before React Router sees it
|
|
83
|
-
const origPush = window.history.pushState.bind(window.history)
|
|
84
|
-
const origReplace = window.history.replaceState.bind(window.history)
|
|
85
|
-
|
|
86
|
-
function rewriteUrl(url: string | URL | null | undefined): string | URL | null | undefined {
|
|
87
|
-
if (typeof url !== 'string') return url
|
|
88
|
-
return url.replace(/\/views\/(\d+)/, '/demo/$1')
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
window.history.pushState = (state, title, url) => origPush(state, title, rewriteUrl(url))
|
|
92
|
-
window.history.replaceState = (state, title, url) => origReplace(state, title, rewriteUrl(url))
|
|
93
|
-
|
|
94
|
-
return () => {
|
|
95
|
-
for (const [obj, key, original] of originals) {
|
|
96
|
-
obj[key] = original
|
|
97
|
-
}
|
|
98
|
-
window.history.pushState = origPush
|
|
99
|
-
window.history.replaceState = origReplace
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ── Inner component overrides applied before children mount ─────────────────
|
|
104
|
-
|
|
105
|
-
function DemoApp({
|
|
106
|
-
revealProgress,
|
|
107
|
-
}: {
|
|
108
|
-
revealProgress: number
|
|
109
|
-
}) {
|
|
110
|
-
// useState initializer runs synchronously during the first render of this
|
|
111
|
-
// component instance, before any child component mounts or any hook effect
|
|
112
|
-
// runs. This guarantees api overrides are in place for ViewEditor's first fetch.
|
|
113
|
-
const [restore] = useState<() => void>(() => {
|
|
114
|
-
initDemoStore()
|
|
115
|
-
return applyOverrides()
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
useEffect(() => restore, [restore])
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<ViewEditor
|
|
122
|
-
demoOptions={{ ...DEMO_VIEW_EDITOR_OPTIONS, revealProgress }}
|
|
123
|
-
/>
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// ── DemoNavigator: redirects bare /demo to the first root view ────────────────
|
|
128
|
-
|
|
129
|
-
export function DemoNavigator() {
|
|
130
|
-
const navigate = useNavigate()
|
|
131
|
-
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
// Call demoApi directly no need to apply global overrides here, which
|
|
134
|
-
// would otherwise be cleaned up after DemoApp mounts and clobber its patches.
|
|
135
|
-
initDemoStore()
|
|
136
|
-
demoApi.workspace.views.tree().then((tree) => {
|
|
137
|
-
const root = tree.find((v) => v.parent_view_id === null)
|
|
138
|
-
navigate(root ? `/demo/${root.id}` : '/demo/1', { replace: true })
|
|
139
|
-
}).catch(() => navigate('/demo/1', { replace: true }))
|
|
140
|
-
}, [navigate])
|
|
141
|
-
|
|
142
|
-
return null
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ── DemoPage ──────────────────────────────────────────────────────────────────
|
|
146
|
-
|
|
147
|
-
export default function DemoPage() {
|
|
148
|
-
const [revealProgress, setRevealProgress] = useState(() => (window.self === window.top ? 1 : 0))
|
|
149
|
-
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
if (window.self === window.top) {
|
|
152
|
-
setRevealProgress(1)
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const handleMessage = (event: MessageEvent) => {
|
|
157
|
-
const data = event.data as { type?: unknown; progress?: unknown } | null
|
|
158
|
-
if (!data || data.type !== 'tldiagram-demo-progress') return
|
|
159
|
-
|
|
160
|
-
const nextProgress = Number(data.progress)
|
|
161
|
-
if (!Number.isFinite(nextProgress)) return
|
|
162
|
-
|
|
163
|
-
setRevealProgress(Math.max(0, Math.min(1, nextProgress)))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
window.addEventListener('message', handleMessage)
|
|
167
|
-
return () => window.removeEventListener('message', handleMessage)
|
|
168
|
-
}, [])
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<ThemeProvider
|
|
172
|
-
storagePrefix="diag:demo"
|
|
173
|
-
defaultAccent="#63b3ed"
|
|
174
|
-
defaultBackground="#0d121e"
|
|
175
|
-
defaultElementColor="#2d3748"
|
|
176
|
-
>
|
|
177
|
-
<Box minH="100vh" bg="var(--bg-canvas)" style={{ '--editor-top-offset': '0px' } as React.CSSProperties}>
|
|
178
|
-
<HeaderProvider>
|
|
179
|
-
<DemoApp revealProgress={revealProgress} />
|
|
180
|
-
</HeaderProvider>
|
|
181
|
-
</Box>
|
|
182
|
-
</ThemeProvider>
|
|
183
|
-
)
|
|
184
|
-
}
|
package/src/demo/seed.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { LibraryElement, PlacedElement, Connector, ViewTreeNode, ViewLayer } from '../types'
|
|
2
|
-
|
|
3
|
-
const NOW = new Date().toISOString()
|
|
4
|
-
|
|
5
|
-
export const DEMO_ELEMENTS: LibraryElement[] = [
|
|
6
|
-
{ id: 1, name: 'User', kind: 'person', description: 'End user of the system', technology: null, url: null, logo_url: "https://tldiagram.com/app/icons/azure-users.png", technology_connectors: [], tags: ['external'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
7
|
-
{ id: 2, name: 'Web App', kind: 'service', description: 'React single-page application', technology: 'React', url: null, logo_url: "https://tldiagram.com/app/icons/react.png", technology_connectors: [], tags: ['frontend'], has_view: true, view_label: null, created_at: NOW, updated_at: NOW },
|
|
8
|
-
{ id: 3, name: 'API Gateway', kind: 'service', description: 'REST API gateway', technology: 'Golang', url: null, logo_url: "https://tldiagram.com/app/icons/golang.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
9
|
-
{ id: 4, name: 'Auth Service', kind: 'service', description: 'Handles authentication & sessions', technology: 'Go', url: null, logo_url: "https://tldiagram.com/app/icons/golang.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
10
|
-
{ id: 5, name: 'Frontend', kind: 'service', description: 'React frontend bundle', technology: 'React', url: null, logo_url: null, technology_connectors: [], tags: ['frontend'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
11
|
-
{ id: 6, name: 'Backend', kind: 'service', description: 'Core business logic API', technology: 'Go', url: null, logo_url: "https://tldiagram.com/app/icons/golang.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
12
|
-
{ id: 7, name: 'PostgreSQL', kind: 'database', description: 'Primary relational database', technology: 'PostgreSQL', url: null, logo_url: null, technology_connectors: [], tags: ['data'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
13
|
-
{ id: 8, name: 'Redis Cache', kind: 'database', description: 'In-memory cache and session store', technology: 'Redis', url: null, logo_url: null, technology_connectors: [], tags: ['data'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
14
|
-
{ id: 9, name: 'CDN', kind: 'service', description: 'Content delivery network', technology: 'Cloudflare', url: null, logo_url: null, technology_connectors: [], tags: ['external', 'infrastructure'], has_view: false, view_label: null, created_at: NOW, updated_at: NOW },
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
export const DEMO_VIEWS: ViewTreeNode[] = [
|
|
18
|
-
{
|
|
19
|
-
id: 1, name: 'System Context', description: 'Top-level system context view', level_label: 'Context', level: 1, depth: 0,
|
|
20
|
-
owner_element_id: null, parent_view_id: null, created_at: NOW, updated_at: NOW, children: [
|
|
21
|
-
{
|
|
22
|
-
id: 2, name: 'Web App – Containers', description: 'Container-level view of the Web App', level_label: 'Container', level: 2, depth: 1,
|
|
23
|
-
owner_element_id: 2, parent_view_id: 1, created_at: NOW, updated_at: NOW, children: [],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
type ViewPlacements = Record<number, PlacedElement[]>
|
|
30
|
-
type ViewConnectors = Record<number, Connector[]>
|
|
31
|
-
|
|
32
|
-
export const DEMO_PLACEMENTS: ViewPlacements = {
|
|
33
|
-
1: [
|
|
34
|
-
{ id: 101, view_id: 1, element_id: 1, position_x: 80, position_y: 200, name: 'User', kind: 'person', description: 'End user of the system', technology: null, url: null, logo_url: "https://tldiagram.com/app/icons/azure-users.png", technology_connectors: [], tags: ['external'], has_view: false, view_label: null },
|
|
35
|
-
{ id: 102, view_id: 1, element_id: 2, position_x: 380, position_y: 200, name: 'Web App', kind: 'service', description: 'React single-page application', technology: 'React', url: null, logo_url: "https://tldiagram.com/app/icons/react.png", technology_connectors: [], tags: ['frontend'], has_view: true, view_label: null },
|
|
36
|
-
{ id: 103, view_id: 1, element_id: 3, position_x: 680, position_y: 200, name: 'API Gateway', kind: 'service', description: 'REST API gateway', technology: 'Go', url: null, logo_url: "https://tldiagram.com/app/icons/golang.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null },
|
|
37
|
-
{ id: 104, view_id: 1, element_id: 4, position_x: 380, position_y: 400, name: 'Auth Service', kind: 'service', description: 'Handles authentication & sessions', technology: 'Auth0', url: null, logo_url: "https://tldiagram.com/app/icons/auth0.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null },
|
|
38
|
-
{ id: 105, view_id: 1, element_id: 9, position_x: 380, position_y: 0, name: 'CDN', kind: 'service', description: 'Content delivery network', technology: 'Cloudflare', url: null, logo_url: "https://tldiagram.com/app/icons/cloudflare.png", technology_connectors: [], tags: ['external', 'infrastructure'], has_view: false, view_label: null },
|
|
39
|
-
{ id: 106, view_id: 1, element_id: 10, position_x: 680, position_y: 0, name: 'Stripe', kind: 'service', description: 'Payment', technology: 'Stripe', url: null, logo_url: "https://tldiagram.com/app/icons/stripe.png", technology_connectors: [], tags: ['external', 'billing'], has_view: false, view_label: null },
|
|
40
|
-
],
|
|
41
|
-
2: [
|
|
42
|
-
{ id: 201, view_id: 2, element_id: 5, position_x: 80, position_y: 200, name: 'Frontend', kind: 'service', description: 'React frontend bundle', technology: 'React', url: null, logo_url: "https://tldiagram.com/app/icons/react.png", technology_connectors: [], tags: ['frontend'], has_view: false, view_label: null },
|
|
43
|
-
{ id: 202, view_id: 2, element_id: 6, position_x: 380, position_y: 200, name: 'Backend', kind: 'service', description: 'Core business logic API', technology: 'Go', url: null, logo_url: "https://tldiagram.com/app/icons/golang.png", technology_connectors: [], tags: ['backend'], has_view: false, view_label: null },
|
|
44
|
-
{ id: 203, view_id: 2, element_id: 7, position_x: 680, position_y: 200, name: 'PostgreSQL', kind: 'database', description: 'Primary relational database', technology: 'PostgreSQL', url: null, logo_url: "https://tldiagram.com/app/icons/postgresql.png", technology_connectors: [], tags: ['data'], has_view: false, view_label: null },
|
|
45
|
-
{ id: 204, view_id: 2, element_id: 8, position_x: 680, position_y: 400, name: 'Redis Cache', kind: 'database', description: 'In-memory cache and session store', technology: 'Redis', url: null, logo_url: "https://tldiagram.com/app/icons/redis.png", technology_connectors: [], tags: ['data'], has_view: false, view_label: null },
|
|
46
|
-
],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const DEMO_CONNECTORS: ViewConnectors = {
|
|
50
|
-
1: [
|
|
51
|
-
{ id: 1001, view_id: 1, source_element_id: 1, target_element_id: 2, label: 'Uses', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'right', target_handle: 'left', created_at: NOW, updated_at: NOW },
|
|
52
|
-
{ id: 1002, view_id: 1, source_element_id: 2, target_element_id: 3, label: 'API calls', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'right', target_handle: 'left', created_at: NOW, updated_at: NOW },
|
|
53
|
-
{ id: 1003, view_id: 1, source_element_id: 2, target_element_id: 4, label: 'Auth', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'bottom', target_handle: 'top', created_at: NOW, updated_at: NOW },
|
|
54
|
-
{ id: 1004, view_id: 1, source_element_id: 2, target_element_id: 9, label: 'Serves via', description: null, relationship: null, direction: 'backward', style: 'bezier', url: null, source_handle: 'top', target_handle: 'bottom', created_at: NOW, updated_at: NOW },
|
|
55
|
-
{ id: 1005, view_id: 1, source_element_id: 3, target_element_id: 10, label: 'Billing', description: null, relationship: null, direction: 'both', style: 'bezier', url: null, source_handle: 'top', target_handle: 'bottom', created_at: NOW, updated_at: NOW },
|
|
56
|
-
],
|
|
57
|
-
2: [
|
|
58
|
-
{ id: 2001, view_id: 2, source_element_id: 5, target_element_id: 6, label: 'HTTP/JSON', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'right', target_handle: 'left', created_at: NOW, updated_at: NOW },
|
|
59
|
-
{ id: 2002, view_id: 2, source_element_id: 6, target_element_id: 7, label: 'Reads / Writes', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'right', target_handle: 'left', created_at: NOW, updated_at: NOW },
|
|
60
|
-
{ id: 2003, view_id: 2, source_element_id: 6, target_element_id: 8, label: 'Cache', description: null, relationship: null, direction: 'forward', style: 'bezier', url: null, source_handle: 'bottom', target_handle: 'left', created_at: NOW, updated_at: NOW },
|
|
61
|
-
],
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const DEMO_LAYERS: Record<number, ViewLayer[]> = {
|
|
65
|
-
1: [],
|
|
66
|
-
2: [],
|
|
67
|
-
}
|