@tldiagram/core-ui 1.87.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/App.d.ts +1 -0
- package/dist/api/client.d.ts +143 -0
- package/dist/api/transport-vscode.d.ts +8 -0
- package/dist/api/transport.d.ts +1 -0
- package/dist/components/CodePreviewPanel-vscode.d.ts +7 -0
- package/dist/components/CodePreviewPanel.d.ts +9 -0
- package/dist/components/ConfirmDialog.d.ts +12 -0
- package/dist/components/ConnectorPanel.d.ts +21 -0
- package/dist/components/ContextBoundaryElement.d.ts +11 -0
- package/dist/components/ContextNeighborElement.d.ts +29 -0
- package/dist/components/ContextStraightConnector.d.ts +4 -0
- package/dist/components/CrossBranchControls.d.ts +9 -0
- package/dist/components/DependenciesOnboarding.d.ts +5 -0
- package/dist/components/DrawingCanvas.d.ts +39 -0
- package/dist/components/ElementLibrary-vscode.d.ts +7 -0
- package/dist/components/ElementLibrary.d.ts +22 -0
- package/dist/components/ElementNode.d.ts +36 -0
- package/dist/components/ElementPanel.d.ts +25 -0
- package/dist/components/ExploreOnboarding.d.ts +5 -0
- package/dist/components/ExplorePageOnboarding.d.ts +5 -0
- package/dist/components/ExportModal.d.ts +16 -0
- package/dist/components/FloatingEdge.d.ts +9 -0
- package/dist/components/GitSourceLinker.d.ts +8 -0
- package/dist/components/HeaderContext.d.ts +16 -0
- package/dist/components/Icons.d.ts +95 -0
- package/dist/components/ImportModal.d.ts +10 -0
- package/dist/components/InlineElementAdder.d.ts +17 -0
- package/dist/components/LayoutSection.d.ts +7 -0
- package/dist/components/LocalSourceLinker.d.ts +8 -0
- package/dist/components/MiniZoomOnboarding.d.ts +5 -0
- package/dist/components/NavBreadcrumb.d.ts +6 -0
- package/dist/components/NodeBody.d.ts +12 -0
- package/dist/components/NodeContainer.d.ts +8 -0
- package/dist/components/NodeHoverCard.d.ts +10 -0
- package/dist/components/PanelHeader.d.ts +8 -0
- package/dist/components/PanelUI.d.ts +3 -0
- package/dist/components/ProxyConnectorEdge.d.ts +4 -0
- package/dist/components/ProxyConnectorPanel.d.ts +9 -0
- package/dist/components/SafeBackground.d.ts +13 -0
- package/dist/components/ScrollIndicatorWrapper.d.ts +8 -0
- package/dist/components/SetChildModal.d.ts +10 -0
- package/dist/components/SetParentModal.d.ts +10 -0
- package/dist/components/SlidingPanel.d.ts +16 -0
- package/dist/components/TagUpsert.d.ts +8 -0
- package/dist/components/TopMenuBar.d.ts +8 -0
- package/dist/components/ViewBezierConnector.d.ts +4 -0
- package/dist/components/ViewDrawMenu.d.ts +22 -0
- package/dist/components/ViewEditorEdgeLabelLayout.d.ts +16 -0
- package/dist/components/ViewEditorOnboarding.d.ts +5 -0
- package/dist/components/ViewExplorer/TagManager/ColorPicker.d.ts +7 -0
- package/dist/components/ViewExplorer/TagManager/GroupNamingPopover.d.ts +10 -0
- package/dist/components/ViewExplorer/TagManager/LayerItem.d.ts +27 -0
- package/dist/components/ViewExplorer/TagManager/TagItem.d.ts +25 -0
- package/dist/components/ViewExplorer/TagManager/index.d.ts +21 -0
- package/dist/components/ViewExplorer/ViewNavigator.d.ts +11 -0
- package/dist/components/ViewExplorer/ViewSearch.d.ts +8 -0
- package/dist/components/ViewExplorer/ViewTree.d.ts +18 -0
- package/dist/components/ViewExplorer/index.d.ts +31 -0
- package/dist/components/ViewExplorer/types.d.ts +11 -0
- package/dist/components/ViewExplorer/utils.d.ts +6 -0
- package/dist/components/ViewExplorer-vscode.d.ts +6 -0
- package/dist/components/ViewFloatingMenu-vscode.d.ts +27 -0
- package/dist/components/ViewFloatingMenu.d.ts +39 -0
- package/dist/components/ViewGridNode.d.ts +29 -0
- package/dist/components/ViewHeaderButton.d.ts +11 -0
- package/dist/components/ViewPanel.d.ts +18 -0
- package/dist/components/ViewsGridOnboarding.d.ts +5 -0
- package/dist/components/ZUI/ZUICanvas.d.ts +18 -0
- package/dist/components/ZUI/index.d.ts +2 -0
- package/dist/components/ZUI/layout.d.ts +18 -0
- package/dist/components/ZUI/proxy.d.ts +25 -0
- package/dist/components/ZUI/renderer.d.ts +30 -0
- package/dist/components/ZUI/types.d.ts +140 -0
- package/dist/components/ZUI/useZUIInteraction.d.ts +21 -0
- package/dist/config/runtime-vscode.d.ts +22 -0
- package/dist/config/runtime.d.ts +5 -0
- package/dist/constants/colors.d.ts +27 -0
- package/dist/constants/diagramColors.d.ts +1 -0
- package/dist/context/ThemeContext.d.ts +27 -0
- package/dist/crossBranch/graph.d.ts +13 -0
- package/dist/crossBranch/resolve.d.ts +22 -0
- package/dist/crossBranch/settings.d.ts +6 -0
- package/dist/crossBranch/store.d.ts +11 -0
- package/dist/crossBranch/types.d.ts +96 -0
- package/dist/demo/DemoPage.d.ts +9 -0
- package/dist/demo/seed.d.ts +9 -0
- package/dist/demo/store.d.ts +137 -0
- package/dist/demo/viewEditor.d.ts +26 -0
- package/dist/favicon.svg +35 -0
- package/dist/hooks/useSafeFitView.d.ts +16 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +19966 -0
- package/dist/lib/vscodeBridge-vscode.d.ts +13 -0
- package/dist/lib/vscodeBridge.d.ts +5 -0
- package/dist/logo-120.png +0 -0
- package/dist/logo-bw.png +0 -0
- package/dist/logo-bw.svg +15 -0
- package/dist/logo-text.svg +51 -0
- package/dist/logo.svg +35 -0
- package/dist/pages/AppearanceSettings.d.ts +3 -0
- package/dist/pages/Dependencies.d.ts +1 -0
- package/dist/pages/InfiniteZoom.d.ts +7 -0
- package/dist/pages/Settings.d.ts +7 -0
- package/dist/pages/ViewEditor/components/EditorMenus.d.ts +24 -0
- package/dist/pages/ViewEditor/components/EditorOverlays.d.ts +30 -0
- package/dist/pages/ViewEditor/components/EmptyCanvasState.d.ts +7 -0
- package/dist/pages/ViewEditor/context.d.ts +13 -0
- package/dist/pages/ViewEditor/hooks/useCanvasInteractions.d.ts +201 -0
- package/dist/pages/ViewEditor/hooks/useDrawingEngine.d.ts +40 -0
- package/dist/pages/ViewEditor/hooks/useViewContextNeighbours.d.ts +20 -0
- package/dist/pages/ViewEditor/hooks/useViewData.d.ts +74 -0
- package/dist/pages/ViewEditor/index.d.ts +8 -0
- package/dist/pages/ViewEditor/utils.d.ts +14 -0
- package/dist/pages/Views.d.ts +6 -0
- package/dist/pages/ViewsGrid.d.ts +6 -0
- package/dist/pkg/importer/mermaid.d.ts +7 -0
- package/dist/pkg/importer/mermaid.test.d.ts +1 -0
- package/dist/platform/PlatformContext.d.ts +6 -0
- package/dist/platform/context.d.ts +3 -0
- package/dist/platform/local.d.ts +2 -0
- package/dist/platform/types.d.ts +17 -0
- package/dist/slots.d.ts +67 -0
- package/dist/theme.d.ts +2 -0
- package/dist/types/index.d.ts +193 -0
- package/dist/types/vscode-messages.d.ts +60 -0
- package/dist/utils/edgeDistribution.d.ts +34 -0
- package/dist/utils/githubApi.d.ts +4 -0
- package/dist/utils/githubCache.d.ts +17 -0
- package/dist/utils/ids.d.ts +2 -0
- package/dist/utils/technologyCatalog.d.ts +15 -0
- package/dist/utils/toast.d.ts +15 -0
- package/dist/utils/treesitter.d.ts +13 -0
- package/dist/utils/url.d.ts +12 -0
- package/package.json +159 -0
- package/src/App.tsx +141 -0
- package/src/api/client.ts +618 -0
- package/src/api/transport-vscode.ts +28 -0
- package/src/api/transport.ts +7 -0
- package/src/assets/logo-mark.svg +31 -0
- package/src/assets/logo-wordmark.svg +22 -0
- package/src/assets/logo.svg +35 -0
- package/src/components/CodePreviewPanel-vscode.tsx +85 -0
- package/src/components/CodePreviewPanel.tsx +384 -0
- package/src/components/ConfirmDialog.tsx +66 -0
- package/src/components/ConnectorPanel.tsx +403 -0
- package/src/components/ContextBoundaryElement.tsx +35 -0
- package/src/components/ContextNeighborElement.tsx +282 -0
- package/src/components/ContextStraightConnector.tsx +144 -0
- package/src/components/CrossBranchControls.tsx +105 -0
- package/src/components/DependenciesOnboarding.tsx +427 -0
- package/src/components/DrawingCanvas.tsx +391 -0
- package/src/components/ElementLibrary-vscode.tsx +9 -0
- package/src/components/ElementLibrary.tsx +512 -0
- package/src/components/ElementNode.tsx +1033 -0
- package/src/components/ElementPanel.tsx +928 -0
- package/src/components/ExploreOnboarding.tsx +347 -0
- package/src/components/ExplorePageOnboarding.tsx +383 -0
- package/src/components/ExportModal.tsx +132 -0
- package/src/components/FloatingEdge.tsx +115 -0
- package/src/components/GitSourceLinker.tsx +1053 -0
- package/src/components/HeaderContext.tsx +30 -0
- package/src/components/Icons.tsx +245 -0
- package/src/components/ImportModal.tsx +219 -0
- package/src/components/InlineElementAdder.tsx +216 -0
- package/src/components/LayoutSection.tsx +624 -0
- package/src/components/LocalSourceLinker.tsx +330 -0
- package/src/components/MiniZoomOnboarding.tsx +78 -0
- package/src/components/NavBreadcrumb.tsx +24 -0
- package/src/components/NodeBody.tsx +89 -0
- package/src/components/NodeContainer.tsx +58 -0
- package/src/components/NodeHoverCard.tsx +135 -0
- package/src/components/PanelHeader.tsx +36 -0
- package/src/components/PanelUI.tsx +24 -0
- package/src/components/ProxyConnectorEdge.tsx +169 -0
- package/src/components/ProxyConnectorPanel.tsx +130 -0
- package/src/components/SafeBackground.tsx +19 -0
- package/src/components/ScrollIndicatorWrapper.tsx +117 -0
- package/src/components/SetChildModal.tsx +191 -0
- package/src/components/SetParentModal.tsx +187 -0
- package/src/components/SlidingPanel.tsx +114 -0
- package/src/components/TagUpsert.tsx +142 -0
- package/src/components/TopMenuBar.tsx +380 -0
- package/src/components/ViewBezierConnector.tsx +143 -0
- package/src/components/ViewDrawMenu.tsx +270 -0
- package/src/components/ViewEditorEdgeLabelLayout.ts +189 -0
- package/src/components/ViewEditorOnboarding.tsx +445 -0
- package/src/components/ViewExplorer/TagManager/ColorPicker.tsx +49 -0
- package/src/components/ViewExplorer/TagManager/GroupNamingPopover.tsx +96 -0
- package/src/components/ViewExplorer/TagManager/LayerItem.tsx +228 -0
- package/src/components/ViewExplorer/TagManager/TagItem.tsx +242 -0
- package/src/components/ViewExplorer/TagManager/index.tsx +418 -0
- package/src/components/ViewExplorer/ViewNavigator.tsx +121 -0
- package/src/components/ViewExplorer/ViewSearch.tsx +33 -0
- package/src/components/ViewExplorer/ViewTree.tsx +98 -0
- package/src/components/ViewExplorer/index.tsx +384 -0
- package/src/components/ViewExplorer/types.ts +13 -0
- package/src/components/ViewExplorer/utils.ts +56 -0
- package/src/components/ViewExplorer-vscode.tsx +8 -0
- package/src/components/ViewFloatingMenu-vscode.tsx +248 -0
- package/src/components/ViewFloatingMenu.tsx +379 -0
- package/src/components/ViewGridNode.tsx +451 -0
- package/src/components/ViewHeaderButton.tsx +60 -0
- package/src/components/ViewPanel.tsx +162 -0
- package/src/components/ViewsGridOnboarding.tsx +400 -0
- package/src/components/ZUI/ZUICanvas.tsx +853 -0
- package/src/components/ZUI/index.ts +3 -0
- package/src/components/ZUI/layout.ts +323 -0
- package/src/components/ZUI/proxy.ts +278 -0
- package/src/components/ZUI/renderer.ts +1189 -0
- package/src/components/ZUI/types.ts +150 -0
- package/src/components/ZUI/useZUIInteraction.ts +720 -0
- package/src/config/runtime-vscode.ts +46 -0
- package/src/config/runtime.ts +30 -0
- package/src/constants/colors.ts +80 -0
- package/src/constants/diagramColors.ts +9 -0
- package/src/context/ThemeContext.tsx +158 -0
- package/src/crossBranch/graph.ts +207 -0
- package/src/crossBranch/resolve.ts +643 -0
- package/src/crossBranch/settings.ts +59 -0
- package/src/crossBranch/store.ts +71 -0
- package/src/crossBranch/types.ts +102 -0
- package/src/demo/DemoPage.tsx +184 -0
- package/src/demo/seed.ts +67 -0
- package/src/demo/store.ts +536 -0
- package/src/demo/viewEditor.ts +110 -0
- package/src/hooks/useSafeFitView.ts +60 -0
- package/src/index.css +309 -0
- package/src/index.ts +184 -0
- package/src/kafka-ss.png +0 -0
- package/src/lib/vscodeBridge-vscode.ts +27 -0
- package/src/lib/vscodeBridge.ts +7 -0
- package/src/main.tsx +46 -0
- package/src/pages/AppearanceSettings.tsx +135 -0
- package/src/pages/Dependencies.tsx +926 -0
- package/src/pages/InfiniteZoom.tsx +404 -0
- package/src/pages/Settings.tsx +91 -0
- package/src/pages/ViewEditor/EDGE_DISTRIBUTION.md +64 -0
- package/src/pages/ViewEditor/components/EditorMenus.tsx +112 -0
- package/src/pages/ViewEditor/components/EditorOverlays.tsx +172 -0
- package/src/pages/ViewEditor/components/EmptyCanvasState.tsx +42 -0
- package/src/pages/ViewEditor/context.tsx +21 -0
- package/src/pages/ViewEditor/hooks/useCanvasInteractions.ts +1349 -0
- package/src/pages/ViewEditor/hooks/useDrawingEngine.ts +127 -0
- package/src/pages/ViewEditor/hooks/useViewContextNeighbours.ts +501 -0
- package/src/pages/ViewEditor/hooks/useViewData.ts +491 -0
- package/src/pages/ViewEditor/index.tsx +1366 -0
- package/src/pages/ViewEditor/utils.ts +88 -0
- package/src/pages/Views.tsx +171 -0
- package/src/pages/ViewsGrid.tsx +1310 -0
- package/src/pkg/importer/mermaid.test.ts +141 -0
- package/src/pkg/importer/mermaid.ts +76 -0
- package/src/platform/PlatformContext.tsx +17 -0
- package/src/platform/context.ts +9 -0
- package/src/platform/local.tsx +15 -0
- package/src/platform/types.ts +19 -0
- package/src/slots.ts +92 -0
- package/src/styles/editor-panels.css +66 -0
- package/src/styles/theme.css +56 -0
- package/src/theme.ts +336 -0
- package/src/types/index.ts +234 -0
- package/src/types/offline-ambient.d.ts +14 -0
- package/src/types/vscode-messages.ts +32 -0
- package/src/utils/edgeDistribution.ts +103 -0
- package/src/utils/githubApi.ts +121 -0
- package/src/utils/githubCache.ts +108 -0
- package/src/utils/ids.ts +9 -0
- package/src/utils/technologyCatalog.ts +143 -0
- package/src/utils/toast.ts +100 -0
- package/src/utils/treesitter.ts +147 -0
- package/src/utils/url.ts +72 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import Parser from 'web-tree-sitter'
|
|
2
|
+
|
|
3
|
+
let parserInitialized = false
|
|
4
|
+
|
|
5
|
+
export async function initTreeSitter() {
|
|
6
|
+
if (parserInitialized) return
|
|
7
|
+
const VERSION = '0.21.0'
|
|
8
|
+
await Parser.init({
|
|
9
|
+
locateFile(scriptName: string) {
|
|
10
|
+
// In newer versions, the WASM file is named tree-sitter.wasm, but some loaders might still ask for web-tree-sitter.wasm
|
|
11
|
+
const name = scriptName === 'web-tree-sitter.wasm' ? 'tree-sitter.wasm' : scriptName
|
|
12
|
+
return `https://unpkg.com/web-tree-sitter@${VERSION}/${name}`
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
parserInitialized = true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SupportedLanguage = 'javascript' | 'typescript' | 'python' | 'java' | 'cpp' | 'go' | 'rust'
|
|
19
|
+
|
|
20
|
+
const EXT_TO_LANGUAGE: Record<string, SupportedLanguage> = {
|
|
21
|
+
'.js': 'javascript', '.jsx': 'javascript',
|
|
22
|
+
'.ts': 'typescript', '.tsx': 'typescript',
|
|
23
|
+
'.py': 'python', '.go': 'go', '.rs': 'rust',
|
|
24
|
+
'.java': 'java', '.cpp': 'cpp', '.cc': 'cpp', '.cxx': 'cpp', '.c': 'cpp', '.h': 'cpp',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function detectLanguage(path: string): SupportedLanguage | null {
|
|
28
|
+
const parts = path.split('.')
|
|
29
|
+
if (parts.length < 2) return null
|
|
30
|
+
const ext = '.' + parts.pop()!.toLowerCase()
|
|
31
|
+
return EXT_TO_LANGUAGE[ext] ?? null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const languageWasms: Record<SupportedLanguage, string> = {
|
|
35
|
+
javascript: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-javascript.wasm',
|
|
36
|
+
typescript: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-typescript.wasm',
|
|
37
|
+
python: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-python.wasm',
|
|
38
|
+
java: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-java.wasm',
|
|
39
|
+
cpp: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-cpp.wasm',
|
|
40
|
+
go: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-go.wasm',
|
|
41
|
+
rust: 'https://unpkg.com/tree-sitter-wasms@0.1.13/out/tree-sitter-rust.wasm',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parsers: Partial<Record<SupportedLanguage, Parser>> = {}
|
|
45
|
+
|
|
46
|
+
export async function getParser(language: SupportedLanguage): Promise<Parser> {
|
|
47
|
+
await initTreeSitter()
|
|
48
|
+
|
|
49
|
+
if (parsers[language]) {
|
|
50
|
+
return parsers[language]!
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const parser = new Parser()
|
|
54
|
+
const langWasmPath = languageWasms[language]
|
|
55
|
+
const Lang = await Parser.Language.load(langWasmPath)
|
|
56
|
+
parser.setLanguage(Lang)
|
|
57
|
+
parsers[language] = parser
|
|
58
|
+
return parser
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ParsedSymbol {
|
|
62
|
+
name: string
|
|
63
|
+
type: string
|
|
64
|
+
startLine: number
|
|
65
|
+
endLine: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Extract main symbols using tree-sitter cursor to avoid complex queries across languages.
|
|
69
|
+
export function extractSymbols(tree: Parser.Tree, language: SupportedLanguage): ParsedSymbol[] {
|
|
70
|
+
const symbols: ParsedSymbol[] = []
|
|
71
|
+
|
|
72
|
+
const isTargetNode = (nodeType: string) => {
|
|
73
|
+
switch (language) {
|
|
74
|
+
case 'javascript':
|
|
75
|
+
case 'typescript':
|
|
76
|
+
return ['class_declaration', 'function_declaration', 'method_definition', 'interface_declaration', 'type_alias_declaration'].includes(nodeType)
|
|
77
|
+
case 'python':
|
|
78
|
+
return ['class_definition', 'function_definition'].includes(nodeType)
|
|
79
|
+
case 'java':
|
|
80
|
+
return ['class_declaration', 'method_declaration', 'interface_declaration'].includes(nodeType)
|
|
81
|
+
case 'cpp':
|
|
82
|
+
return ['class_specifier', 'function_definition', 'struct_specifier'].includes(nodeType)
|
|
83
|
+
case 'go':
|
|
84
|
+
return ['function_declaration', 'method_declaration', 'type_declaration'].includes(nodeType)
|
|
85
|
+
case 'rust':
|
|
86
|
+
return ['function_item', 'struct_item', 'impl_item', 'trait_item'].includes(nodeType)
|
|
87
|
+
default:
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const getNameField = (node: Parser.SyntaxNode): string => {
|
|
93
|
+
// Attempt to find an identifier child
|
|
94
|
+
if (node.type === 'method_definition') {
|
|
95
|
+
const nameNode = node.childForFieldName('name')
|
|
96
|
+
if (nameNode) return nameNode.text
|
|
97
|
+
}
|
|
98
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
99
|
+
const child = node.child(i)
|
|
100
|
+
if (child && ['identifier', 'type_identifier', 'name'].includes(child.type)) {
|
|
101
|
+
return child.text
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return node.child(1)?.text || 'unknown'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const traverse = (node: Parser.SyntaxNode) => {
|
|
108
|
+
if (isTargetNode(node.type)) {
|
|
109
|
+
symbols.push({
|
|
110
|
+
name: getNameField(node),
|
|
111
|
+
type: node.type,
|
|
112
|
+
startLine: node.startPosition.row + 1,
|
|
113
|
+
endLine: node.endPosition.row + 1
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
118
|
+
const child = node.child(i)
|
|
119
|
+
if (child) traverse(child)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
traverse(tree.rootNode)
|
|
124
|
+
|
|
125
|
+
return symbols
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function findSymbolByName(
|
|
129
|
+
tree: Parser.Tree,
|
|
130
|
+
language: SupportedLanguage,
|
|
131
|
+
name: string,
|
|
132
|
+
type: string
|
|
133
|
+
): ParsedSymbol | null {
|
|
134
|
+
const all = extractSymbols(tree, language)
|
|
135
|
+
// Exact match
|
|
136
|
+
let found = all.find(s => s.name === name && s.type === type)
|
|
137
|
+
if (found) return found
|
|
138
|
+
|
|
139
|
+
// Partial type match (e.g., 'function_item' contains 'function')
|
|
140
|
+
if (type) {
|
|
141
|
+
found = all.find(s => s.name === name && (s.type.includes(type) || type.includes(s.type)))
|
|
142
|
+
if (found) return found
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Fallback to just name match
|
|
146
|
+
return all.find(s => s.name === name) ?? null
|
|
147
|
+
}
|
package/src/utils/url.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isNativeApp } from '../config/runtime'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a static asset path (like a logo or icon) taking into account
|
|
5
|
+
* the environment (dev vs production, web vs native Capacitor).
|
|
6
|
+
*/
|
|
7
|
+
export function resolveIconPath(path: string | null | undefined): string {
|
|
8
|
+
if (!path) return ''
|
|
9
|
+
|
|
10
|
+
// Absolute URLs and data URIs are returned as-is
|
|
11
|
+
if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('data:')) return path
|
|
12
|
+
|
|
13
|
+
// If running inside the native mobile app (Capacitor) OR inside an embedded
|
|
14
|
+
// webview that serves content from localhost (e.g. Capacitor production webview),
|
|
15
|
+
// static assets are typically available at the web root. However we must NOT treat
|
|
16
|
+
// the local dev server (like http://localhost:5173) as a native/webview environment.
|
|
17
|
+
// Use a conservative detection: file:// is always native; localhost/127.0.0.1 is
|
|
18
|
+
// treated as native only when served over HTTPS (Capacitor uses https://localhost)
|
|
19
|
+
// or when there is no non-default dev port present.
|
|
20
|
+
const runningOnLocalhost = typeof window !== 'undefined' && (() => {
|
|
21
|
+
// file: is unequivocally a native / packaged environment (Capacitor)
|
|
22
|
+
if (window.location.protocol === 'file:') return true
|
|
23
|
+
|
|
24
|
+
// Only consider plain localhost/127.0.0.1 further
|
|
25
|
+
const hostIsLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
|
26
|
+
if (!hostIsLocal) return false
|
|
27
|
+
|
|
28
|
+
// If served over HTTPS on localhost (Capacitor uses https://localhost) assume native/webview.
|
|
29
|
+
if (window.location.protocol === 'https:') return true
|
|
30
|
+
|
|
31
|
+
// If there's no explicit port (or it's the default HTTPS port), treat as native/webview.
|
|
32
|
+
// Dev servers usually expose a non-default port (like 5173) - those should NOT be treated as native.
|
|
33
|
+
const port = (window.location.port || '').trim()
|
|
34
|
+
if (!port || port === '443') return true
|
|
35
|
+
|
|
36
|
+
return false
|
|
37
|
+
})()
|
|
38
|
+
|
|
39
|
+
if (isNativeApp || runningOnLocalhost) {
|
|
40
|
+
// Strip the web app base prefix (/app/) if present - logo_url values saved from
|
|
41
|
+
// the web interface may have this prefix baked in, but on native assets live at root.
|
|
42
|
+
const stripped = path.startsWith('/app/') ? path.slice('/app'.length) : path
|
|
43
|
+
return stripped.startsWith('/') ? stripped : `/${stripped}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Use Vite's BASE_URL (import.meta.env.BASE_URL)
|
|
47
|
+
const base = import.meta.env.BASE_URL || '/'
|
|
48
|
+
const normalizedBase = base.endsWith('/') ? base : `${base}/`
|
|
49
|
+
|
|
50
|
+
// If the path already starts with the base, return it
|
|
51
|
+
if (path.startsWith(normalizedBase) || path === normalizedBase.slice(0, -1)) return path
|
|
52
|
+
|
|
53
|
+
const normalizedPath = path.startsWith('/') ? path.slice(1) : path
|
|
54
|
+
return `${normalizedBase}${normalizedPath}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Normalizes any git repository reference to an "owner/repo" slug:
|
|
59
|
+
* - SSH: git@github.com:owner/repo.git → owner/repo
|
|
60
|
+
* - HTTPS: https://github.com/owner/repo.git → owner/repo
|
|
61
|
+
* - Plain: owner/repo → owner/repo
|
|
62
|
+
*/
|
|
63
|
+
export function parseRepoSlug(repo: string): string {
|
|
64
|
+
// SSH format: git@host:owner/repo(.git)
|
|
65
|
+
const sshMatch = repo.match(/^git@[^:]+:(.+?)(?:\.git)?$/)
|
|
66
|
+
if (sshMatch) return sshMatch[1]
|
|
67
|
+
// HTTPS format: https://host/owner/repo(.git)
|
|
68
|
+
const httpsMatch = repo.match(/^https?:\/\/[^/]+\/(.+?)(?:\.git)?$/)
|
|
69
|
+
if (httpsMatch) return httpsMatch[1]
|
|
70
|
+
// Already owner/repo, strip optional .git suffix
|
|
71
|
+
return repo.replace(/\.git$/, '')
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|