previewcn 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -283,7 +283,7 @@ export function PreviewcnDevtools() {
283
283
 
284
284
  return <DevtoolsInner />;
285
285
  }
286
- `}function R(){return `"use client";
286
+ `}function N(){return `"use client";
287
287
 
288
288
  import { useState } from "react";
289
289
 
@@ -387,7 +387,7 @@ export function FontSelector({ value, onChange }: FontSelectorProps) {
387
387
  </div>
388
388
  );
389
389
  }
390
- `}function N(){return `"use client";
390
+ `}function R(){return `"use client";
391
391
 
392
392
  type ModeToggleProps = {
393
393
  value: boolean | null;
@@ -483,7 +483,7 @@ export function ModeToggle({ value, onChange }: ModeToggleProps) {
483
483
  }
484
484
  `}function E(){return `"use client";
485
485
 
486
- import { useEffect, useRef, type ReactNode } from "react";
486
+ import { useEffect, type ReactNode } from "react";
487
487
 
488
488
  import { useThemeState } from "./use-theme-state";
489
489
  import { applyTheme } from "./theme-applier";
@@ -730,12 +730,10 @@ export default function Panel({ onClose }: PanelProps) {
730
730
  resetTheme,
731
731
  } = useThemeState();
732
732
 
733
- const didApplyOnOpenRef = useRef(false);
733
+ // Apply stored theme only when the panel opens
734
734
  useEffect(() => {
735
- if (didApplyOnOpenRef.current) return;
736
- didApplyOnOpenRef.current = true;
737
735
  applyTheme(config);
738
- }, [config]);
736
+ }, []);
739
737
 
740
738
  usePanelKeyframes();
741
739
 
@@ -830,6 +828,10 @@ export type PresetSpec = {
830
828
  light?: string;
831
829
  dark?: string;
832
830
  };
831
+ destructiveForeground?: {
832
+ light?: string;
833
+ dark?: string;
834
+ };
833
835
  };
834
836
 
835
837
  export const colorPresetSpecs: PresetSpec[] = [
@@ -1086,6 +1088,11 @@ const defaultPrimaryForeground = {
1086
1088
  dark: "oklch(0.985 0 0)",
1087
1089
  };
1088
1090
 
1091
+ const defaultDestructiveForeground = {
1092
+ light: "oklch(0.985 0 0)",
1093
+ dark: "oklch(0.985 0 0)",
1094
+ };
1095
+
1089
1096
  function createColorPreset(spec: PresetSpec): ColorPreset {
1090
1097
  return {
1091
1098
  name: spec.name,
@@ -1097,6 +1104,8 @@ function createColorPreset(spec: PresetSpec): ColorPreset {
1097
1104
  "primary-foreground":
1098
1105
  spec.primaryForeground?.light ?? defaultPrimaryForeground.light,
1099
1106
  destructive: spec.destructive?.light ?? defaultDestructive.light,
1107
+ "destructive-foreground":
1108
+ spec.destructiveForeground?.light ?? defaultDestructiveForeground.light,
1100
1109
  },
1101
1110
  dark: {
1102
1111
  ...neutralColors.dark,
@@ -1104,6 +1113,8 @@ function createColorPreset(spec: PresetSpec): ColorPreset {
1104
1113
  "primary-foreground":
1105
1114
  spec.primaryForeground?.dark ?? defaultPrimaryForeground.dark,
1106
1115
  destructive: spec.destructive?.dark ?? defaultDestructive.dark,
1116
+ "destructive-foreground":
1117
+ spec.destructiveForeground?.dark ?? defaultDestructiveForeground.dark,
1107
1118
  },
1108
1119
  },
1109
1120
  };
@@ -1925,5 +1936,5 @@ export function useThemeState() {
1925
1936
  };
1926
1937
  }
1927
1938
  `}function Pe(){return `export { PreviewcnDevtools } from "./devtools";
1928
- `}function q(){return [{path:"index.ts",content:Pe()},{path:"devtools.tsx",content:F()},{path:"trigger.tsx",content:U()},{path:"panel.tsx",content:E()},{path:"color-picker.tsx",content:w()},{path:"preset-selector.tsx",content:I()},{path:"radius-selector.tsx",content:$()},{path:"font-selector.tsx",content:R()},{path:"mode-toggle.tsx",content:N()},{path:"css-export-button.tsx",content:T()},{path:"theme-applier.ts",content:B()},{path:"use-theme-state.ts",content:V()},{path:"css-export.ts",content:S()},{path:"presets/index.ts",content:O()},{path:"presets/colors.ts",content:j()},{path:"presets/color-preset-specs.ts",content:D()},{path:"presets/radius.ts",content:L()},{path:"presets/fonts.ts",content:M()},{path:"presets/theme-presets.ts",content:A()}]}function g(e){return u.cyan(e)}async function Z(e,t){return !!(await we({type:"confirm",name:"value",message:e,initial:t})).value}async function Q(e,t){await C.mkdir(e,{recursive:true});for(let o of t){let r=l.join(e,o.path);await C.mkdir(l.dirname(r),{recursive:true}),await C.writeFile(r,o.content,"utf-8");}}async function ee(e){a.info(`Initializing PreviewCN...
1939
+ `}function q(){return [{path:"index.ts",content:Pe()},{path:"devtools.tsx",content:F()},{path:"trigger.tsx",content:U()},{path:"panel.tsx",content:E()},{path:"color-picker.tsx",content:w()},{path:"preset-selector.tsx",content:I()},{path:"radius-selector.tsx",content:$()},{path:"font-selector.tsx",content:N()},{path:"mode-toggle.tsx",content:R()},{path:"css-export-button.tsx",content:T()},{path:"theme-applier.ts",content:B()},{path:"use-theme-state.ts",content:V()},{path:"css-export.ts",content:S()},{path:"presets/index.ts",content:O()},{path:"presets/colors.ts",content:j()},{path:"presets/color-preset-specs.ts",content:D()},{path:"presets/radius.ts",content:L()},{path:"presets/fonts.ts",content:M()},{path:"presets/theme-presets.ts",content:A()}]}function g(e){return u.cyan(e)}async function Z(e,t){return !!(await we({type:"confirm",name:"value",message:e,initial:t})).value}async function Q(e,t){await C.mkdir(e,{recursive:true});for(let o of t){let r=l.join(e,o.path);await C.mkdir(l.dirname(r),{recursive:true}),await C.writeFile(r,o.content,"utf-8");}}async function ee(e){a.info(`Initializing PreviewCN...
1929
1940
  `);let t=process.cwd(),o=G("Detecting project type...").start(),r=await h(t);r.isNextJs||(o.fail("Not a Next.js project"),a.error("PreviewCN requires a Next.js project with App Router."),a.hint("Make sure you're in the root of a Next.js project."),process.exit(1)),r.isAppRouter||(o.fail("App Router not detected"),a.error("PreviewCN requires Next.js App Router (app/ directory)."),a.hint("Create an app/ directory or migrate from pages/ to app/."),process.exit(1)),o.succeed("Next.js App Router project detected");let s=await k(t);s||(a.error("Could not find app/layout.tsx"),process.exit(1)),a.info(`Found layout at: ${g(l__default.relative(t,s))}`);let{targetDir:n,importPath:c}=await y(t);a.info(`Components will be generated at: ${g(l__default.relative(t,n))}`),e.yes||await Z("This will generate PreviewCN components and modify your app layout. Continue?",true)||(a.info("Aborted."),process.exit(0)),await Te(n,s,c),console.log(),a.success("PreviewCN devtools initialized successfully!"),console.log(),a.info("Next step:"),console.log(` Run ${g("pnpm dev")} (or your dev command) to start the dev server.`),console.log(` Click the ${g("theme palette icon")} in the bottom-right corner to open the editor.`),console.log();}async function Te(e,t,o){let r=G("Generating PreviewCN components...").start();try{let n=q();await Q(e,n);let c=l__default.relative(process.cwd(),e);r.succeed(`Generated ${n.length} files in ${c}`);}catch(n){r.fail("Failed to generate PreviewCN components"),a.error(n instanceof Error?n.message:String(n)),process.exit(1);}let s=G("Adding PreviewcnDevtools to layout...").start();try{await z(t,o),s.succeed("Added PreviewcnDevtools to layout");}catch(n){s.fail("Failed to modify layout for devtools"),a.error(n instanceof Error?n.message:String(n)),a.hint("You may need to add PreviewcnDevtools manually. See documentation.");}}var x=new Command;x.name("previewcn").description("CLI for PreviewCN - real-time shadcn/ui theme editor").version("0.1.0");x.command("init",{isDefault:true}).description("Initialize PreviewCN devtools in your Next.js project").option("-y, --yes","Skip confirmation prompts").action(ee);x.command("doctor").description("Check PreviewCN setup and diagnose issues").action(X);x.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "previewcn",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },