Skip to content

Commit 2088c76

Browse files
chore: release v2.0.0-alpha.4
1 parent 29d9bf9 commit 2088c76

File tree

8 files changed

+102
-42
lines changed

8 files changed

+102
-42
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
99
"check-types": "turbo run check-types",
10-
"pkg-build": "turbo run build --filter=shadcn-theme-editor && tsx scripts/scaflo.ts",
11-
"publish:pkg": "pnpm run package-build && pnpm publish --filter shadcn-theme-editor",
12-
"publish:pkg:dry": "turbo run build --filter=shadcn-theme-editor && pnpm publish --filter shadcn-theme-editor --dry-run --no-git-checks"
10+
"pkg-build": "turbo run build --filter=shadcn-theme-editor && tsx scripts/scaflo.ts"
1311
},
1412
"devDependencies": {
1513
"@types/fs-extra": "^11.0.4",

pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/scaflo.ts

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ import fs from "fs-extra";
22
import path from "path";
33
import { fileURLToPath } from "url";
44

5+
//* Scaflo types
6+
7+
type FileWriteMethods = "a" | "w" | Record<string, string>; // Append, Write (default), or Replace key-value
8+
9+
type FileType = {
10+
name: string;
11+
content: string;
12+
method?: FileWriteMethods;
13+
};
14+
15+
type JsonStructure = {
16+
dependencies?: Array<string | Record<string, string>>;
17+
files?: FileType[];
18+
groups?: { base: string; files: FileType[] };
19+
20+
registryDependencies: string[]; //* modified (shadcn's components)
21+
};
22+
523
const currentFile = fileURLToPath(import.meta.url);
624
const rootDir = path.resolve(path.dirname(currentFile), "..");
725

@@ -34,28 +52,36 @@ function getAllFileNames(dirPath: string): string[] {
3452
}
3553
}
3654

37-
type RegistryFile = {
38-
path: string;
39-
type: "registry:component";
40-
content: string;
41-
};
55+
function readDeps() {
56+
const pkg = fs.readJsonSync(path.join(editorPath, "package.json"));
4257

43-
type RegistryJson = {
44-
$schema: string;
45-
name: string;
46-
type: "registry:component";
47-
title: string;
48-
description: string;
49-
files: RegistryFile[];
50-
dependencies: string[];
51-
registryDependencies: string[];
52-
};
58+
return Object.entries(pkg.dependencies).map(
59+
([name, version]) => `${name}@${version}`,
60+
);
61+
}
62+
63+
// type RegistryFile = {
64+
// path: string;
65+
// type: "registry:component";
66+
// content: string;
67+
// };
68+
69+
// type RegistryJson = {
70+
// $schema: string;
71+
// name: string;
72+
// type: "registry:component";
73+
// title: string;
74+
// description: string;
75+
// files: RegistryFile[];
76+
// dependencies: string[];
77+
// registryDependencies: string[];
78+
// };
5379

5480
function generateShadcnRegistry(
5581
rootDir: string,
5682
_modify?: (content: string, filePath: string) => string,
57-
): RegistryJson {
58-
const files: RegistryFile[] = [];
83+
): JsonStructure {
84+
const files: FileType[] = [];
5985
const modify: NonNullable<typeof _modify> = _modify ?? ((content) => content);
6086

6187
function walk(dir: string) {
@@ -74,8 +100,7 @@ function generateShadcnRegistry(
74100
const modified = modify(original, fullPath);
75101

76102
files.push({
77-
path: `registry/magicui/${path.relative(rootDir, fullPath).replace(/\\/g, "/")}`,
78-
type: "registry:component",
103+
name: `/${path.relative(rootDir, fullPath).replace(/\\/g, "/")}`,
79104
content: modified,
80105
});
81106
}
@@ -84,23 +109,28 @@ function generateShadcnRegistry(
84109

85110
walk(rootDir);
86111

87-
const registry: RegistryJson = {
88-
$schema: "https://ui.shadcn.com/schema/registry-item.json",
89-
name: "Shadcn Theme Editor",
90-
type: "registry:component",
91-
title: "Shadcn Theme Editor",
92-
description:
93-
"Shadcn Theme Editor is a user-friendly component designed to simplify the process of managing and customizing theme colors in Shadcn-based projects.",
112+
const registry: JsonStructure = {
113+
// $schema: "https://ui.shadcn.com/schema/registry-item.json",
114+
// name: "Shadcn Theme Editor",
115+
// type: "registry:component",
116+
// title: "Shadcn Theme Editor",
117+
// description:
118+
// "Shadcn Theme Editor is a user-friendly component designed to simplify the process of managing and customizing theme colors in Shadcn-based projects.",
94119
files,
95120
registryDependencies: getAllFileNames(
96121
path.join(editorPath, "/src/components/ui"),
97122
),
98-
dependencies: ["lucide-react"],
123+
dependencies: ["lucide-react", ...readDeps()],
99124
};
100125

101126
return registry;
102127
}
103128

104129
console.log("⏳ Starting Shadcn registry generation…");
105-
fs.writeJSONSync(outputPath, generateShadcnRegistry(editorMainPath));
130+
fs.writeJSONSync(
131+
outputPath,
132+
generateShadcnRegistry(editorMainPath, (content) =>
133+
content.replace("@/components/icons", "lucide-react"),
134+
),
135+
);
106136
console.log(`✅ Registry successfully generated at: ${outputPath}`);

shadcn-theme-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shadcn-theme-editor",
3-
"version": "2.0.0-alpha.3",
3+
"version": "2.0.0-alpha.4",
44
"description": "",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

shadcn-theme-editor/src/(main)/index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ export default function Editor({
4949
triggerClassName,
5050
toCssString,
5151
getCopyValue,
52+
title,
53+
getContainer,
5254
}: {
5355
side?: Side;
5456
className?: string;
5557
triggerClassName?: string;
58+
title?: string;
5659
} & Pick<React.ComponentProps<typeof Sidebar>, "customColors"> &
57-
Partial<Pick<typeof sharedData, "toCssString" | "getCopyValue">>) {
60+
Partial<
61+
Pick<typeof sharedData, "toCssString" | "getCopyValue" | "getContainer">
62+
>) {
5863
//*
5964

6065
useEffect(() => {
@@ -149,6 +154,8 @@ export default function Editor({
149154
sharedData.toCssString = toCssString ?? sharedData.toCssString;
150155
sharedData.getCopyValue = getCopyValue ?? sharedData.getCopyValue;
151156

157+
sharedData.getContainer = getContainer ?? sharedData.getContainer;
158+
152159
checkLocalStorageTheme();
153160
}, []);
154161

@@ -165,15 +172,16 @@ export default function Editor({
165172
<PaletteIcon className="size-6" />
166173
</SheetTrigger>
167174
<SheetContent
175+
data-shadcn-theme-editor
168176
side={side}
169177
className={cn(
170-
"bg-background flex flex-col overflow-hidden py-4 sm:max-w-72",
178+
"bg-background flex flex-col gap-0 overflow-hidden py-4 sm:max-w-72",
171179
className,
172180
)}
173181
>
174182
{sharedData.success ? (
175183
<>
176-
<Header />
184+
<Header title={title} />
177185
<Sidebar customColors={customColors} />
178186
<Footer />
179187
<SheetClose />
@@ -188,12 +196,10 @@ export default function Editor({
188196
);
189197
}
190198

191-
function Header() {
199+
function Header({ title = "Shadcn Theme Editor" }: { title?: string }) {
192200
return (
193201
<div className="border-b px-2 shadow-md">
194-
<span className="flex items-center px-2 py-1 font-semibold">
195-
Shadcn Theme Editor
196-
</span>
202+
<span className="flex items-center px-2 py-1 font-semibold">{title}</span>
197203
<div className="mb-1 mt-2 flex items-center justify-between gap-2 py-1 pl-2 text-sm font-semibold">
198204
Theming
199205
<div className="flex pr-2">

shadcn-theme-editor/src/(main)/lib/shared.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export const sharedData: {
2323

2424
// all colors:
2525
allColors: CustomColors; //! currently no need to shared
26+
27+
// Returns the container element to which styles will be applied
28+
getContainer: () => HTMLElement;
2629
} = {
2730
toCssString: undefined as never,
2831
getCopyValue: undefined as never,
@@ -32,4 +35,5 @@ export const sharedData: {
3235
success: true,
3336
defaultThemeEmittor: createEmittor({}),
3437
allColors: {},
38+
getContainer: () => document.documentElement,
3539
};

shadcn-theme-editor/src/(main)/lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const copy2clipboard = (text: string) =>
55

66
export function setProperity(proprity: string, value: string | null) {
77
// document.querySelector(":root")?.style.setProperty(proprity, value);
8-
document.documentElement?.style.setProperty(proprity, value);
8+
sharedData.getContainer().style.setProperty(proprity, value);
99
}
1010

1111
export function memoize<Args extends unknown[], R>(
@@ -31,7 +31,7 @@ export function resetCurrentTheme(full = true) {
3131
Only perform a full theme reset if no saved theme was found.
3232
If a theme exists, keep some settings so the saved theme can override them later.
3333
*/
34-
const style = document.documentElement.style;
34+
const style = sharedData.getContainer().style;
3535

3636
Object.keys(sharedData.currentTheme).forEach((propertyName) =>
3737
style.removeProperty(propertyName),

web/public/r/editor.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)