-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathlayout.tsx
More file actions
208 lines (188 loc) · 8.35 KB
/
layout.tsx
File metadata and controls
208 lines (188 loc) · 8.35 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import type { Metadata, Viewport } from 'next'
import { PublicEnvScript } from 'next-runtime-env'
import { BrandedLayout } from '@/components/branded-layout'
import { generateThemeCSS } from '@/lib/branding/inject-theme'
import { generateBrandedMetadata, generateStructuredData } from '@/lib/branding/metadata'
import { PostHogProvider } from '@/app/_shell/providers/posthog-provider'
import '@/app/_styles/globals.css'
import { OneDollarStats } from '@/components/analytics/onedollarstats'
import { HydrationErrorHandler } from '@/app/_shell/hydration-error-handler'
import { QueryProvider } from '@/app/_shell/providers/query-provider'
import { SessionProvider } from '@/app/_shell/providers/session-provider'
import { ThemeProvider } from '@/app/_shell/providers/theme-provider'
import { TooltipProvider } from '@/app/_shell/providers/tooltip-provider'
import { season } from '@/app/_styles/fonts/season/season'
export const viewport: Viewport = {
width: 'device-width',
initialScale: 1,
maximumScale: 1,
userScalable: false,
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#ffffff' },
{ media: '(prefers-color-scheme: dark)', color: '#0c0c0c' },
],
}
export const metadata: Metadata = generateBrandedMetadata()
export default function RootLayout({ children }: { children: React.ReactNode }) {
const structuredData = generateStructuredData()
const themeCSS = generateThemeCSS()
return (
<html lang='en' suppressHydrationWarning>
<head>
{/* Structured Data for SEO */}
<script
type='application/ld+json'
dangerouslySetInnerHTML={{
__html: JSON.stringify(structuredData),
}}
/>
{/*
Workspace layout dimensions: set CSS vars before hydration to avoid layout jump.
IMPORTANT: These hardcoded values must stay in sync with stores/constants.ts
We cannot use imports here since this is a blocking script that runs before React.
*/}
<script
id='workspace-layout-dimensions'
dangerouslySetInnerHTML={{
__html: `
(function () {
try {
var path = window.location.pathname;
if (path.indexOf('/workspace/') === -1) {
return;
}
} catch (e) {
return;
}
// Sidebar width
try {
var stored = localStorage.getItem('sidebar-state');
if (stored) {
var parsed = JSON.parse(stored);
var state = parsed && parsed.state;
var width = state && state.sidebarWidth;
var maxSidebarWidth = window.innerWidth * 0.3;
if (width >= 232 && width <= maxSidebarWidth) {
document.documentElement.style.setProperty('--sidebar-width', width + 'px');
} else if (width > maxSidebarWidth) {
document.documentElement.style.setProperty('--sidebar-width', maxSidebarWidth + 'px');
}
}
} catch (e) {
// Fallback handled by CSS defaults
}
// Panel width and active tab
try {
var panelStored = localStorage.getItem('panel-state');
if (panelStored) {
var panelParsed = JSON.parse(panelStored);
var panelState = panelParsed && panelParsed.state;
var panelWidth = panelState && panelState.panelWidth;
var maxPanelWidth = window.innerWidth * 0.4;
if (panelWidth >= 290 && panelWidth <= maxPanelWidth) {
document.documentElement.style.setProperty('--panel-width', panelWidth + 'px');
} else if (panelWidth > maxPanelWidth) {
document.documentElement.style.setProperty('--panel-width', maxPanelWidth + 'px');
}
var activeTab = panelState && panelState.activeTab;
if (activeTab) {
document.documentElement.setAttribute('data-panel-active-tab', activeTab);
}
}
} catch (e) {
// Fallback handled by CSS defaults
}
// Toolbar triggers height
try {
var toolbarStored = localStorage.getItem('toolbar-state');
if (toolbarStored) {
var toolbarParsed = JSON.parse(toolbarStored);
var toolbarState = toolbarParsed && toolbarParsed.state;
var toolbarTriggersHeight = toolbarState && toolbarState.toolbarTriggersHeight;
if (
toolbarTriggersHeight !== undefined &&
toolbarTriggersHeight >= 30 &&
toolbarTriggersHeight <= 800
) {
document.documentElement.style.setProperty(
'--toolbar-triggers-height',
toolbarTriggersHeight + 'px'
);
}
}
} catch (e) {
// Fallback handled by CSS defaults
}
// Editor connections height
try {
var editorStored = localStorage.getItem('panel-editor-state');
if (editorStored) {
var editorParsed = JSON.parse(editorStored);
var editorState = editorParsed && editorParsed.state;
var connectionsHeight = editorState && editorState.connectionsHeight;
if (connectionsHeight !== undefined && connectionsHeight >= 30 && connectionsHeight <= 300) {
document.documentElement.style.setProperty(
'--editor-connections-height',
connectionsHeight + 'px'
);
}
}
} catch (e) {
// Fallback handled by CSS defaults
}
// Terminal height
try {
var terminalStored = localStorage.getItem('terminal-state');
if (terminalStored) {
var terminalParsed = JSON.parse(terminalStored);
var terminalState = terminalParsed && terminalParsed.state;
var terminalHeight = terminalState && terminalState.terminalHeight;
var maxTerminalHeight = window.innerHeight * 0.7;
if (terminalHeight >= 30 && terminalHeight <= maxTerminalHeight) {
document.documentElement.style.setProperty('--terminal-height', terminalHeight + 'px');
} else if (terminalHeight > maxTerminalHeight) {
document.documentElement.style.setProperty('--terminal-height', maxTerminalHeight + 'px');
}
}
} catch (e) {
// Fallback handled by CSS defaults
}
})();
`,
}}
/>
{/* Theme CSS Override */}
{themeCSS && (
<style
id='theme-override'
dangerouslySetInnerHTML={{
__html: themeCSS,
}}
/>
)}
{/* Basic head hints that are not covered by the Metadata API */}
<meta name='color-scheme' content='light dark' />
<meta name='format-detection' content='telephone=no' />
<meta httpEquiv='x-ua-compatible' content='ie=edge' />
{/* OneDollarStats Analytics */}
<script defer src='https://assets.onedollarstats.com/stonks.js' />
<PublicEnvScript />
</head>
<body className={`${season.variable} font-season`} suppressHydrationWarning>
<HydrationErrorHandler />
<OneDollarStats />
<PostHogProvider>
<ThemeProvider>
<QueryProvider>
<SessionProvider>
<TooltipProvider>
<BrandedLayout>{children}</BrandedLayout>
</TooltipProvider>
</SessionProvider>
</QueryProvider>
</ThemeProvider>
</PostHogProvider>
</body>
</html>
)
}