mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-09 06:55:07 +00:00
refactor: presets
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import path from "path"
|
||||
import { runInit } from "@/src/commands/init"
|
||||
import { preFlightAdd } from "@/src/preflights/preflight-add"
|
||||
import {
|
||||
promptForBase,
|
||||
promptForPreset,
|
||||
resolveRegistryBaseConfig,
|
||||
} from "@/src/preset/presets"
|
||||
import { getRegistryItems, getShadcnRegistryIndex } from "@/src/registry/api"
|
||||
import { DEPRECATED_COMPONENTS } from "@/src/registry/constants"
|
||||
import { clearRegistryContext } from "@/src/registry/context"
|
||||
@@ -18,11 +23,6 @@ import { getProjectInfo } from "@/src/utils/get-project-info"
|
||||
import { handleError } from "@/src/utils/handle-error"
|
||||
import { highlighter } from "@/src/utils/highlighter"
|
||||
import { logger } from "@/src/utils/logger"
|
||||
import {
|
||||
promptForBase,
|
||||
promptForPreset,
|
||||
resolveRegistryBaseConfig,
|
||||
} from "@/src/utils/presets"
|
||||
import { ensureRegistriesInConfig } from "@/src/utils/registries"
|
||||
import { spinner } from "@/src/utils/spinner"
|
||||
import { updateAppIndex } from "@/src/utils/update-app-index"
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { promises as fs } from "fs"
|
||||
import path from "path"
|
||||
import { preFlightInit } from "@/src/preflights/preflight-init"
|
||||
import { decodePreset, isPresetCode } from "@/src/preset/preset"
|
||||
import {
|
||||
DEFAULT_PRESETS,
|
||||
promptForBase,
|
||||
promptForPreset,
|
||||
resolveInitUrl,
|
||||
resolveRegistryBaseConfig,
|
||||
} from "@/src/preset/presets"
|
||||
import { getRegistryBaseColors, getRegistryStyles } from "@/src/registry/api"
|
||||
import { BUILTIN_REGISTRIES } from "@/src/registry/constants"
|
||||
import { clearRegistryContext } from "@/src/registry/context"
|
||||
@@ -45,14 +53,6 @@ import {
|
||||
import { handleError } from "@/src/utils/handle-error"
|
||||
import { highlighter } from "@/src/utils/highlighter"
|
||||
import { logger } from "@/src/utils/logger"
|
||||
import { decodePreset, isPresetCode } from "@/src/utils/preset"
|
||||
import {
|
||||
DEFAULT_PRESETS,
|
||||
promptForBase,
|
||||
promptForPreset,
|
||||
resolveInitUrl,
|
||||
resolveRegistryBaseConfig,
|
||||
} from "@/src/utils/presets"
|
||||
import { ensureRegistriesInConfig } from "@/src/utils/registries"
|
||||
import { spinner } from "@/src/utils/spinner"
|
||||
import { Command } from "commander"
|
||||
@@ -285,6 +285,7 @@ export const init = new Command()
|
||||
title: t.title,
|
||||
value,
|
||||
description: t.description,
|
||||
disabled: options.monorepo && value === "laravel",
|
||||
})),
|
||||
})
|
||||
|
||||
|
||||
@@ -20,4 +20,4 @@ export {
|
||||
generateRandomConfig,
|
||||
generateRandomPreset,
|
||||
type PresetConfig,
|
||||
} from "../utils/preset"
|
||||
} from "./preset"
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
// Value arrays — order matters for backward compat. Never reorder, only append.
|
||||
export const PRESET_BASES = ["radix", "base"] as const
|
||||
|
||||
export const PRESET_STYLES = ["nova", "vega", "maia", "lyra", "mira"] as const
|
||||
|
||||
export const PRESET_BASE_COLORS = [
|
||||
"neutral",
|
||||
"stone",
|
||||
@@ -22,6 +24,7 @@ export const PRESET_BASE_COLORS = [
|
||||
"mist",
|
||||
"taupe",
|
||||
] as const
|
||||
|
||||
export const PRESET_THEMES = [
|
||||
"neutral",
|
||||
"stone",
|
||||
@@ -49,6 +52,7 @@ export const PRESET_THEMES = [
|
||||
"mist",
|
||||
"taupe",
|
||||
] as const
|
||||
|
||||
export const PRESET_ICON_LIBRARIES = [
|
||||
"lucide",
|
||||
"hugeicons",
|
||||
@@ -56,6 +60,7 @@ export const PRESET_ICON_LIBRARIES = [
|
||||
"phosphor",
|
||||
"remixicon",
|
||||
] as const
|
||||
|
||||
export const PRESET_FONTS = [
|
||||
"inter",
|
||||
"noto-sans",
|
||||
@@ -72,7 +77,10 @@ export const PRESET_FONTS = [
|
||||
"lora",
|
||||
"merriweather",
|
||||
"playfair-display",
|
||||
"noto-serif",
|
||||
"roboto-slab",
|
||||
] as const
|
||||
|
||||
export const PRESET_RADII = [
|
||||
"default",
|
||||
"none",
|
||||
@@ -80,6 +88,7 @@ export const PRESET_RADII = [
|
||||
"medium",
|
||||
"large",
|
||||
] as const
|
||||
|
||||
export const PRESET_MENU_ACCENTS = ["subtle", "bold"] as const
|
||||
export const PRESET_MENU_COLORS = ["default", "inverted"] as const
|
||||
|
||||
@@ -159,8 +168,13 @@ export function encodePreset(config: Partial<PresetConfig>) {
|
||||
|
||||
// Decode a preset code back into a PresetConfig.
|
||||
export function decodePreset(code: string): PresetConfig | null {
|
||||
if (!code || code.length < 2) return null
|
||||
if (code[0] !== VERSION_CHAR) return null
|
||||
if (!code || code.length < 2) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (code[0] !== VERSION_CHAR) {
|
||||
return null
|
||||
}
|
||||
|
||||
const bits = fromBase62(code.slice(1))
|
||||
if (bits < 0) return null
|
||||
@@ -179,11 +193,20 @@ export function decodePreset(code: string): PresetConfig | null {
|
||||
|
||||
// Check if a string looks like a preset code (version char + base62).
|
||||
export function isPresetCode(value: string) {
|
||||
if (!value || value.length < 2 || value.length > 10) return false
|
||||
if (value[0] !== VERSION_CHAR) return false
|
||||
for (let i = 1; i < value.length; i++) {
|
||||
if (BASE62.indexOf(value[i]) === -1) return false
|
||||
if (!value || value.length < 2 || value.length > 10) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (value[0] !== VERSION_CHAR) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (let i = 1; i < value.length; i++) {
|
||||
if (BASE62.indexOf(value[i]) === -1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ export const templates = {
|
||||
vite,
|
||||
start,
|
||||
"react-router": reactRouter,
|
||||
laravel,
|
||||
astro,
|
||||
laravel,
|
||||
}
|
||||
|
||||
// Resolve a template key from a detected framework name.
|
||||
|
||||
@@ -4,24 +4,3 @@ export { transformIcons } from "../utils/transformers/transform-icons"
|
||||
export { transformMenu } from "../utils/transformers/transform-menu"
|
||||
export { transformRender } from "../utils/transformers/transform-render"
|
||||
export { transformDirection } from "../utils/transformers/transform-rtl"
|
||||
export {
|
||||
PRESET_BASES,
|
||||
PRESET_STYLES,
|
||||
PRESET_BASE_COLORS,
|
||||
PRESET_THEMES,
|
||||
PRESET_ICON_LIBRARIES,
|
||||
PRESET_FONTS,
|
||||
PRESET_RADII,
|
||||
PRESET_MENU_ACCENTS,
|
||||
PRESET_MENU_COLORS,
|
||||
DEFAULT_PRESET_CONFIG,
|
||||
toBase62,
|
||||
fromBase62,
|
||||
encodePreset,
|
||||
decodePreset,
|
||||
isPresetCode,
|
||||
isValidPreset,
|
||||
generateRandomConfig,
|
||||
generateRandomPreset,
|
||||
type PresetConfig,
|
||||
} from "../utils/preset"
|
||||
|
||||
Reference in New Issue
Block a user