Skip to content

Commit 1f119c9

Browse files
committed
chore: export version
1 parent 534a1be commit 1f119c9

File tree

8 files changed

+50
-55
lines changed

8 files changed

+50
-55
lines changed

apps/preview/app/src/components/nav-button.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ interface NavButtonProps extends React.ComponentPropsWithoutRef<'header'> {
1414
label: string;
1515
}
1616

17+
const variants = {
18+
active: { opacity: 1 },
19+
inactive: { opacity: 0 }
20+
};
21+
1722
export const NavButton = ({ activeView, addClassNames, label }: NavButtonProps) => (
1823
<ToggleGroup.Item value={label}>
1924
<motion.div className={classnames(button, addClassNames)}>
20-
{activeView === label && (
21-
<motion.span
22-
layoutId="topbar"
23-
className={motionSpan}
24-
initial={{ opacity: 0 }}
25-
animate={{ opacity: 1 }}
26-
exit={{ opacity: 0 }}
27-
/>
28-
)}
25+
<motion.span
26+
animate={activeView === label ? 'active' : 'inactive'}
27+
initial={'inactive'}
28+
variants={variants}
29+
layoutId="topbar"
30+
className={motionSpan}
31+
exit={'inactive'}
32+
/>
2933
<span className={classnames(span, { 'text-cta-text': activeView === label })}>{label}</span>
3034
</motion.div>
3135
</ToggleGroup.Item>

apps/preview/app/src/components/nav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const Nav = React.forwardRef<React.ElementRef<'header'>, Readonly<NavProp
4242
</div>
4343
)}
4444
</div>
45-
45+
{/* <div>activeView: {activeView}</div> */}
4646
{!!title && (
4747
<div className="flex flex-row items-center gap-4">
4848
<Popover.Root>

apps/preview/app/src/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import { gather } from './templates';
99

1010
setup();
1111

12+
// if (import.meta.hot) {
13+
// import.meta.hot.accept((mod) => {
14+
// console.log(mod);
15+
// });
16+
// }
17+
1218
const router = getRouter(await gather());
1319
const rootElement = document.getElementById('root');
1420
const root = ReactDOM.createRoot(rootElement);

apps/preview/app/src/routes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
1+
import { createHashRouter, type RouteObject } from 'react-router-dom';
22

33
import { Error } from './error.tsx';
44
import { Home } from './home.tsx';
@@ -40,7 +40,7 @@ const getRoutes = (templates: TemplateData[]) => {
4040

4141
export const getRouter = (templates: Record<string, TemplateData>) => {
4242
const { routes, templateParts } = getRoutes(Object.values(templates));
43-
const router = createBrowserRouter([
43+
const router = createHashRouter([
4444
{
4545
element: (
4646
<Layout>

apps/preview/app/src/templates.ts

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,23 @@
1-
import { config } from './config.js';
21
import { parseName } from './helpers';
3-
import type { TemplatePart, TemplateData } from './types.ts';
2+
import type { PreviewImportContent, TemplatePart, TemplateData } from './types.ts';
43

54
export const gather = async () => {
6-
const relativePath = config.relativePath.endsWith('/')
7-
? config.relativePath
8-
: `${config.relativePath}/`;
9-
const buildPath = config.buildPath.endsWith('/') ? config.buildPath : `${config.buildPath}/`;
10-
const absBuildPath = `/${buildPath.replace(/(\.\.\/)+/, '')}`;
11-
12-
const htmlFiles = import.meta.glob(`@jsxemailbuild/**/*.html`, {
13-
eager: true,
14-
import: 'default',
15-
query: '?raw'
16-
});
17-
const plainFiles = import.meta.glob(`@jsxemailbuild/**/*.txt`, {
18-
eager: true,
19-
import: 'default',
20-
query: '?raw'
21-
});
22-
const sourceFiles = import.meta.glob(`@jsxemailsrc/**/*.{jsx,tsx}`, {
23-
eager: true,
24-
import: 'default',
25-
query: '?raw'
5+
const imports = import.meta.glob<PreviewImportContent>(`@jsxemailbuild/**/*.js`, {
6+
import: 'default'
267
});
27-
// @ts-ignore
28-
const { default: templateNameMap } = await import(`@jsxemailbuild/template-name-map.json`);
8+
const builtFiles = await Promise.all(Object.values(imports).map((imp) => imp()));
9+
const dirParts = builtFiles[0].sourceFile.split('/');
10+
const baseDir = dirParts.length ? dirParts[0] : '';
11+
const templateFiles: Record<string, TemplateData> = builtFiles.reduce((acc, file) => {
12+
const templateName = file.templateName || file.sourceFile.split('/').at(-1);
2913

30-
const fileKeys = Object.keys(sourceFiles);
31-
const templateFiles: Record<string, TemplateData> = fileKeys.reduce((acc, path) => {
32-
const basePath = path.replace(relativePath, buildPath).replace(/\.(jsx|tsx)$/, '');
33-
const absHtmlPath = `${path
34-
.replace(relativePath, absBuildPath)
35-
.replace(/\.(jsx|tsx)$/, '')}.html`;
36-
const templateName = templateNameMap[absHtmlPath] || basePath.split('/').at(-1);
3714
return {
3815
...acc,
39-
[path]: {
40-
html: htmlFiles[`${basePath}.html`],
41-
path: path.replace(relativePath, ''),
42-
plain: plainFiles[`${basePath}.txt`],
43-
source: sourceFiles[path],
16+
[file.sourceFile]: {
17+
html: file.html,
18+
path: file.sourceFile.replace(`${baseDir}/`, ''),
19+
plain: file.plain,
20+
source: file.source,
4421
templateName
4522
}
4623
};

apps/preview/app/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Note: This should match the same declaration in jsx-email/src/cli/preview.mts
2+
export interface PreviewImportContent {
3+
html: string;
4+
plain: string;
5+
source: string;
6+
sourceFile: string;
7+
templateName: string;
8+
}
9+
110
export enum Views {
211
Desktop = 'desktop',
312
Html = 'html',

apps/preview/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const pkg = require('./package.json');
22

33
const getDeps = () => pkg.optimizeDeps;
44

5-
module.exports = { getDeps };
5+
module.exports = { getDeps, version: pkg.version };

apps/preview/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,23 @@
2828
},
2929
"dependencies": {
3030
"@radix-ui/colors": "3.0.0",
31-
"@radix-ui/react-collapsible": "1.1.0",
31+
"@radix-ui/react-collapsible": "1.1.1",
3232
"@radix-ui/react-icons": "^1.3.0",
33-
"@radix-ui/react-popover": "1.1.1",
33+
"@radix-ui/react-popover": "1.1.2",
3434
"@radix-ui/react-select": "^2.0.0",
3535
"@radix-ui/react-slot": "1.1.0",
3636
"@radix-ui/react-toggle-group": "1.1.0",
3737
"classnames": "2.5.1",
38-
"framer-motion": "11.5.6",
38+
"framer-motion": "11.12.0",
3939
"react-dom": "18.3.1",
40-
"react-router-dom": "6.26.2",
40+
"react-router-dom": "7.0.1",
4141
"shiki": "^1.18.0",
42-
"tailwindcss": "3.4.0",
4342
"titleize": "^4.0.0",
4443
"vite": "^5.2.11"
4544
},
4645
"devDependencies": {
4746
"autoprefixer": "^10.4.16",
4847
"postcss": "^8.4.32",
49-
"tailwindcss": "3.4.13"
48+
"tailwindcss": "3.4.15"
5049
}
5150
}

0 commit comments

Comments
 (0)