likec4 1.0.0-rc.1 → 1.0.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.
@@ -0,0 +1,53 @@
1
+ import { LikeC4Browser, type LikeC4ViewBaseProps, LikeC4ViewElement as LikeC4ViewComponent } from 'likec4/react'
2
+ import { useState } from 'react'
3
+ import { createPortal } from 'react-dom'
4
+ import { isLikeC4ViewId, type LikeC4ViewId, LikeC4Views } from 'virtual:likec4/views'
5
+
6
+ type LikeC4ViewProps = LikeC4ViewBaseProps<LikeC4ViewId>
7
+
8
+ export { isLikeC4ViewId }
9
+
10
+ export function LikeC4View({
11
+ viewId,
12
+ interactive = true,
13
+ colorScheme,
14
+ injectFontCss = true,
15
+ ...props
16
+ }: LikeC4ViewProps) {
17
+ const view = LikeC4Views[viewId]
18
+
19
+ const [browserViewId, onNavigateTo] = useState(null as LikeC4ViewId | null)
20
+
21
+ const browserView = browserViewId ? LikeC4Views[browserViewId] : null
22
+
23
+ if (!view) {
24
+ throw new Error(`View with id ${viewId} not found`)
25
+ }
26
+
27
+ if (browserViewId && !browserView) {
28
+ throw new Error(`View with id ${browserViewId} not found`)
29
+ }
30
+
31
+ return (
32
+ <>
33
+ <LikeC4ViewComponent<LikeC4ViewId>
34
+ view={view}
35
+ colorScheme={colorScheme}
36
+ injectFontCss={injectFontCss}
37
+ onNavigateTo={interactive ? onNavigateTo : undefined}
38
+ {...props}
39
+ />
40
+ {browserView && (createPortal(
41
+ <LikeC4Browser<LikeC4ViewId>
42
+ view={browserView}
43
+ injectFontCss={false}
44
+ colorScheme={colorScheme}
45
+ onNavigateTo={onNavigateTo}
46
+ onClose={() => onNavigateTo(null)}
47
+ />,
48
+ document.body,
49
+ view.id
50
+ ))}
51
+ </>
52
+ )
53
+ }
@@ -0,0 +1,13 @@
1
+ export const ComponentName = {
2
+ View: WEBCOMPONENT_PREFIX + '-view',
3
+ Browser: WEBCOMPONENT_PREFIX + '-browser'
4
+ }
5
+
6
+ let BASE = import.meta.env.BASE_URL
7
+ if (!BASE.endsWith('/')) {
8
+ BASE = BASE + '/'
9
+ }
10
+
11
+ export const useHasHistory = __USE_HASH_HISTORY__
12
+
13
+ export const basepath = useHasHistory ? '/' : BASE