Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MIT licensed — fork it, build on it, ship your own version.
- **Git & GitHub** — the branch chip in the title bar shows the current branch and dirty state. From its dropdown you can switch branches, create branches, commit, push, or publish a brand-new repo to GitHub (via the `gh` CLI).
- **Tell an AI what's selected** — **⇧⌘C** copies whatever the canvas has selected as the trail of `file:line-range` pointers that leads to it: the page, each component drilled into on the way down, then the node itself. Paste that into Claude Code or any AI chat that can read the project and it knows exactly which markup you mean.
- **Code fallback** — pages with markup too complex for the visual model open in a code editor instead, still with live preview.
- **New project** — "Start from Lumos" or "Start from Astro" creates a named site with the framework's own scaffolder and installs its dependencies for you.
- **New project.** Choose "Start from Lumos", "Start from shadcn", or "Start from Astro". Stacki creates the site and installs its dependencies. A new shadcn site opens on Style Gallery and includes a Component Gallery page. Set Astro’s `site` option to your public URL before deploying so the sitemap, canonical links, and social image URLs use that domain.

## Running in development

Expand Down
24 changes: 23 additions & 1 deletion electron/handlers/projectHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as fs from 'fs';
import * as os from 'os';
import { writeNewProjectDefaults } from '../project/newProjectDefaults';
import { createStarter, newSiteDirectory, runCreateCommand, startSiteHistory, STARTERS } from '../project/starter';
import { createShadcnStarter, inspectShadcnPreset } from '../project/shadcnStarter';
import { isWin } from '../lib/mainHelpers';
import { ensureToolPath, run } from '../lib/nodeTools';
import { isAstroProject } from '../project/projectFiles';
Expand Down Expand Up @@ -105,11 +106,32 @@ function registerProjectCreateAstroHandlers({ ipcMain, send, showOpenDialog }: P
}

function registerProjectCreateStarterHandlers({ ipcMain, send }: Pick<MainHost, 'ipcMain' | 'send'>): void {
let creatingShadcn = false;
ipcMain.handle('project:inspectShadcnPreset', (_event, { preset }) => {
ensureToolPath();
return inspectShadcnPreset(preset);
});
// Starting from a starter. The scaffolder, the first commit and the package's
// name are in ./starter.js; what is here is the install that follows and the
// log the wizard reads.
ipcMain.handle('project:createStarter', async (_event, { starter = 'lumos', parentPath, name, packageManager = 'npm' }) => {
ipcMain.handle('project:createStarter', async (_event, request) => {
ensureToolPath(); // npm and git are both on the PATH the Dock does not have
const { packageManager = 'npm' } = request;
if (request.starter === 'shadcn') {
// The welcome windows share create:log, so only one attempt can own this stream.
if (creatingShadcn) {
throw new Error('A shadcn site is already being created.');
}
creatingShadcn = true;
try {
send('progress', { message: 'Creating the shadcn site…' });
return { ok: true, ...(await createShadcnStarter(request, (text) => send('create:log', text))) };
} finally {
send('progress', PROGRESS_CLEARED);
creatingShadcn = false;
}
}
const { starter = 'lumos', parentPath, name } = request;
await requirePackageManager(packageManager);
const result = await createStarter({
starter,
Expand Down
22 changes: 22 additions & 0 deletions electron/handlers/shadcnSettingsHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import path from 'node:path';
import { realpathSync } from 'node:fs';
import { err } from '../../shared/core/result';
import type { ShadcnSettingsReply } from '../../shared/ipc/shadcnSettings';
import { changeShadcnSetting, readShadcnSettings } from '../project/shadcnSettings';
import type { MainHost } from './mainHost';

export function registerShadcnSettingsHandlers(host: Pick<MainHost, 'ipcMain' | 'assertInProject'>): void {
const withProject = async (projectPath: string, operation: (root: string) => ShadcnSettingsReply | Promise<ShadcnSettingsReply>) => {
try {
const root = realpathSync(projectPath);
host.assertInProject(path.join(root, 'components.json'));
return await operation(root);
} catch (error: unknown) {
return err({ message: error instanceof Error ? error.message : String(error) });
}
};
host.ipcMain.handle('project:readShadcnSettings', (_event, { projectPath }) => withProject(projectPath, readShadcnSettings));
host.ipcMain.handle('project:changeShadcnSetting', (_event, { projectPath, setting, enabled }) =>
withProject(projectPath, (root) => changeShadcnSetting(root, { setting, enabled })),
);
}
2 changes: 2 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import { allowLoopbackFraming } from './app/previewFraming';
import { registerPageTemplateHandlers } from './handlers/pageTemplateHandlers';
import { registerPreviewHandlers } from './handlers/previewHandlers';
import { registerProjectHandlers } from './handlers/projectHandlers';
import { registerShadcnSettingsHandlers } from './handlers/shadcnSettingsHandlers';
import { registerProjectScanHandlers } from './handlers/projectScanHandlers';
import { registerStyleSourceHandlers } from './handlers/styleSourceHandlers';
import { registerAppPageFilesHandlers } from './handlers/appPageFilesHandlers';
Expand Down Expand Up @@ -1393,6 +1394,7 @@ registerPageTemplateHandlers(
);
registerPreviewHandlers(host);
registerProjectHandlers(host);
registerShadcnSettingsHandlers(host);
registerProjectMetadataHandlers(host);
registerInstructionHandlers(host);
registerAgentHandlers(host);
Expand Down
13 changes: 6 additions & 7 deletions electron/preload/frameInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ export function setCanvasInteraction(next: CanvasInteraction): void {

// The canvas's cursor. Select mode shows the editor's arrow everywhere. Interact
// mode shows the same arrow, never the I-beam over words: it is still the editor,
// and a page's text is selected and edited as in select mode. What acts on a
// click shows the pointer, so it is plain what will navigate or run: links,
// buttons, <summary>, labels, form controls, and whatever the page itself gives a
// cursor (`cursor: pointer` on a card). Fields typed into keep their I-beam,
// since interact mode lets them take focus and keystrokes.
// and a page's text is selected and edited as in select mode. Links, summaries,
// labels and form controls get click affordances. Buttons use the site's cursor
// so a project can switch its pointer styling off. Fields typed into keep their
// I-beam because interact mode lets them take focus and keystrokes.
//
// Interact mode's rules have no specificity (`:where`) and no !important, so a
// cursor the page sets on an element wins over them; the arrow on <html> is
Expand All @@ -74,8 +73,8 @@ export function setCanvasInteraction(next: CanvasInteraction): void {
const DESIGN_CURSOR_CSS = ['*, *::before, *::after { cursor: default !important; }', 'iframe, embed, object { pointer-events: none !important; }'].join('\n');
const INTERACT_CURSOR_CSS = [
':where(html) { cursor: default; }',
':where(a[href], area[href], button, summary, label, select, [role="button"], [role="link"], [onclick]) { cursor: pointer; }',
':where(input:is([type="button" i], [type="submit" i], [type="reset" i], [type="checkbox" i], [type="radio" i], [type="file" i], [type="image" i], [type="color" i], [type="range" i])) { cursor: pointer; }',
':where(a[href], area[href], summary, label, select, [role="link"], [onclick]):where(:not(button, [role="button"])) { cursor: pointer; }',
':where(input:is([type="button" i], [type="submit" i], [type="reset" i], [type="checkbox" i], [type="radio" i], [type="file" i], [type="image" i], [type="color" i], [type="range" i]):not([role="button"])) { cursor: pointer; }',
':where(textarea, input:not([type="button" i], [type="submit" i], [type="reset" i], [type="checkbox" i], [type="radio" i], [type="file" i], [type="image" i], [type="color" i], [type="range" i], [type="hidden" i]), [contenteditable]:not([contenteditable="false" i])) { cursor: text; }',
].join('\n');

Expand Down
3 changes: 3 additions & 0 deletions electron/preload/preloadBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ function projectBridge() {
inspectFolder: invoke('project:inspectFolder'),
takeOpenedFolders: invoke('project:takeOpenedFolders'),
createStarter: invoke('project:createStarter'),
readShadcnSettings: invoke('project:readShadcnSettings'),
changeShadcnSetting: invoke('project:changeShadcnSetting'),
inspectShadcnPreset: invoke('project:inspectShadcnPreset'),
scanProject: invoke('project:scan'),
listProjectClasses: invoke('project:classes'),
watchProject: invoke('watch:start'),
Expand Down
137 changes: 137 additions & 0 deletions electron/project/shadcnCreatePreview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Adapt the published Create preview to the Astro starter's local components.
import type { ShadcnBase, ShadcnIconLibrary } from '../../shared/ipc/shadcnStarter';
import { CREATE_PREVIEW_LICENSE, createPreviewSources } from './shadcnCreatePreviewSources';
import { createStylePreviewSources } from './shadcnCreateStylePreviewSources';
import { shadcnEditableGallery } from './shadcnEditableGallery';
import { shadcnGalleryAuditFixes } from './shadcnGalleryAudits';

const DIRECTORY = 'src/components/examples/create-preview';
const STYLE_DIRECTORY = 'src/components/examples/create-style-preview';

const ICON_PACKAGES: Readonly<Record<ShadcnIconLibrary, string>> = {
lucide: 'lucide-react',
tabler: '@tabler/icons-react',
hugeicons: '@hugeicons/core-free-icons',
phosphor: '@phosphor-icons/react',
remixicon: '@remixicon/react',
};

export const SHADCN_GALLERY_TITLES = { guide: 'Style Gallery', examples: 'Component Gallery' } as const;
const GALLERY_DESCRIPTIONS = {
guide: 'Explore the typography, color tokens, and design system patterns used across this shadcn starter.',
examples: 'Browse interactive shadcn examples for forms, charts, tables, and other common interface patterns.',
} as const;
export const SHADCN_CREATE_PREVIEW_PAGE = previewPage({ page: 'examples', directory: DIRECTORY });
export const SHADCN_CREATE_STYLE_PREVIEW_PAGE = previewPage({ page: 'guide', directory: STYLE_DIRECTORY });

function previewPage({ page, directory }: { readonly page: keyof typeof SHADCN_GALLERY_TITLES; readonly directory: string }): string {
const title = SHADCN_GALLERY_TITLES[page];
return `---
import Layout from "@/layouts/main.astro";
import Gallery from "@/${directory.slice('src/'.length)}/Gallery.astro";
---

<Layout title="${title}" page="${page}" description="${GALLERY_DESCRIPTIONS[page]}">
<h1 class="sr-only">${title}</h1>
<div class="h-full min-w-0" role="region" aria-label="${title}">
<Gallery />
</div>
</Layout>

`;
}

export function shadcnCreatePreviewFiles(config: {
readonly base: ShadcnBase;
readonly iconLibrary: ShadcnIconLibrary;
readonly style: string;
}): Readonly<Record<string, string>> {
const { base, iconLibrary, style } = config;
const galleries = [
{ directory: DIRECTORY, sources: createPreviewSources(base) },
{ directory: STYLE_DIRECTORY, sources: createStylePreviewSources(base) },
];
return {
...Object.fromEntries<string>(
galleries.flatMap(({ directory, sources }) => {
const adapted = Object.fromEntries(
Object.entries(sources).map(([file, source]) => [file, withLocalIcons(withPreviewStyles(shadcnGalleryAuditFixes(file, source)), iconLibrary)]),
);
const gallery = shadcnEditableGallery(adapted, { style, tooltip: directory === STYLE_DIRECTORY && base !== 'aria' });
return Object.entries(gallery).map(([file, source]) => [`${directory}/${file}`, source] as const);
}),
),
[`${DIRECTORY}/style.ts`]: styleSource(style),
[`${STYLE_DIRECTORY}/style.ts`]: STYLE_PREVIEW_TYPOGRAPHY,
[`${DIRECTORY}/LICENSE`]: CREATE_PREVIEW_LICENSE,
[`${STYLE_DIRECTORY}/LICENSE`]: CREATE_PREVIEW_LICENSE,
};
}

function styleSource(style: string): string {
return `// The standalone gallery uses the starter's preset instead of Create's URL state.
export function useDesignSystemSearchParams() {
return [{ style: ${JSON.stringify(style)} }] as const;
}
`;
}

const STYLE_PREVIEW_TYPOGRAPHY = `import { useEffect, useState } from "react";
import { useDesignSystemSearchParams } from "../create-preview/style";

export { useDesignSystemSearchParams };

export function usePreviewTypography() {
const [{ style }] = useDesignSystemSearchParams();
const [fonts, setFonts] = useState<{ readonly body: string; readonly heading: string | undefined }>({
body: "Default",
heading: undefined,
});
useEffect(() => {
// Read the installed theme's actual font variables, which can differ across presets.
const theme = getComputedStyle(document.body);
const body = firstFont(theme.getPropertyValue("--font-sans")) || "Default";
const heading = firstFont(theme.getPropertyValue("--font-heading"));
setFonts({ body, heading: heading && heading !== body ? heading : undefined });
}, []);
return { style: style.charAt(0).toUpperCase() + style.slice(1), ...fonts };
}

function firstFont(value: string): string {
return (value.split(",", 1)[0] ?? "").trim().replace(/^['"]|['"]$/g, "").replace(/ Variable$/, "");
}
`;

function withPreviewStyles(source: string): string {
// The preset selectors compile in the site's existing Tailwind entry.
return source
.replace(/\bstyle-([a-z]+):/g, '[&:where([data-style=$1]_*)]:')
.replace(/\b3xl:/g, 'min-[1600px]:')
.replaceAll('cn-font-heading', 'font-heading');
}

function withLocalIcons(source: string, library: ShadcnIconLibrary): string {
const imports = new Map<string, string>();
const output = source.replace(/<IconPlaceholder\s+([\s\S]*?)\/>/g, (_full, props: string) => {
const name = new RegExp(`\\b${library}="([A-Za-z][A-Za-z0-9]*)"`).exec(props)?.[1];
if (name === undefined) {
throw new Error(`The shadcn Create preview is missing an icon for ${library}.`);
}
const local = imports.get(name) ?? `CreateIcon${imports.size}`;
imports.set(name, local);
const attributes = props.replace(/\b(?:lucide|tabler|hugeicons|phosphor|remixicon)="[^"]*"\s*/g, '').trim();
if (library === 'hugeicons') {
return `<HugeiconsIcon icon={${local}} ${attributes} />`;
}
return `<${local} ${attributes} />`;
});
if (imports.size === 0) {
return output;
}
const icons = [...imports].map(([name, local]) => `${name} as ${local}`).join(', ');
// Preserve React's client directive above the added imports.
const client = output.startsWith('"use client"') ? '"use client"\n' : '';
const content = client === '' ? output : output.slice('"use client"'.length);
const hugeicons = library === 'hugeicons' ? 'import { HugeiconsIcon } from "@hugeicons/react";\n' : '';
return `${client}${hugeicons}import { ${icons} } from "${ICON_PACKAGES[library]}";\n${content}`;
}
Loading