Skip to content

armgit / ui

Public Imported from GitHub
0
TypeScript

Refine PDF editor registry, badge, and icon handling

Andrew Luo71079a523e8c
diff --git a/apps/v4/app/r/[...path]/route.ts b/apps/v4/app/r/[...path]/route.ts
index ce803f8..3ac5ef4 100644
--- a/apps/v4/app/r/[...path]/route.ts
+++ b/apps/v4/app/r/[...path]/route.ts
@@ -8,11 +8,6 @@ type RegistryCatalog = {
[key: string]: unknown
}
-type RegistryItem = {
- registryDependencies?: string[]
- [key: string]: unknown
-}
-
class RegistryJsonNotFoundError extends Error {
constructor(readonly fileName: string) {
super(`Registry JSON file "${fileName}" was not found.`)
@@ -21,35 +16,6 @@ class RegistryJsonNotFoundError extends Error {
const registryJsonCache = new Map<string, Promise<unknown>>()
-function getRegistryItemNames(registry: RegistryCatalog) {
- return new Set(registry.items.map((item) => item.name))
-}
-
-function isExternalDependency(dependency: string) {
- return (
- dependency.startsWith("http://") ||
- dependency.startsWith("https://") ||
- dependency.startsWith("@")
- )
-}
-
-function rewriteLocalRegistryDependencies(
- item: RegistryItem,
- localItemNames: Set<string>,
- origin: string
-) {
- if (!item.registryDependencies) return item
-
- return {
- ...item,
- registryDependencies: item.registryDependencies.map((dependency) =>
- !isExternalDependency(dependency) && localItemNames.has(dependency)
- ? `${origin}/r/${dependency}.json`
- : dependency
- ),
- }
-}
-
function parseRegistryPath(pathSegments: string[]) {
if (pathSegments.length !== 1) return null
@@ -91,7 +57,10 @@ function getRegistryDirectories() {
async function readRegistryJson<T>(fileName: string): Promise<T> {
for (const registryDirectory of getRegistryDirectories()) {
try {
- const file = await readFile(path.join(registryDirectory, fileName), "utf8")
+ const file = await readFile(
+ path.join(registryDirectory, fileName),
+ "utf8"
+ )
return JSON.parse(file) as T
} catch (error) {
@@ -116,7 +85,7 @@ function loadBuiltRegistryJson<T>(fileName: string) {
}
export async function GET(
- request: Request,
+ _request: Request,
context: {
params: Promise<{ path?: string[] }>
}
@@ -135,17 +104,8 @@ export async function GET(
)
}
- const [registry, item] = await Promise.all([
- loadBuiltRegistryJson<RegistryCatalog>("registry.json"),
- loadBuiltRegistryJson<RegistryItem>(`${parsedPath.name}.json`),
- ])
-
return Response.json(
- rewriteLocalRegistryDependencies(
- item,
- getRegistryItemNames(registry),
- new URL(request.url).origin
- )
+ await loadBuiltRegistryJson<unknown>(`${parsedPath.name}.json`)
)
} catch (error) {
if (error instanceof RegistryJsonNotFoundError) {
diff --git a/apps/v4/components/docs-sidebar.tsx b/apps/v4/components/docs-sidebar.tsx
index 4f3dc89..450f881 100644
--- a/apps/v4/components/docs-sidebar.tsx
+++ b/apps/v4/components/docs-sidebar.tsx
@@ -110,6 +110,7 @@ export function DocsSidebar({
const isExperimental =
page.url === "/docs/components/xlsx-editor" ||
page.url === "/docs/components/docx-editor"
+ const isNew = page.url === "/docs/components/pdf-editor"
return (
<SidebarMenuItem key={page.url} className="relative">
@@ -118,7 +119,9 @@ export function DocsSidebar({
isActive={page.url === pathname}
className={cn(
"relative h-[30px] w-fit overflow-visible border border-transparent text-[0.8rem] font-medium after:absolute after:inset-x-0 after:-inset-y-1 after:z-0 after:rounded-md data-[active=true]:border-accent data-[active=true]:bg-accent 3xl:fixed:w-full 3xl:fixed:max-w-48",
- isExperimental && "w-full overflow-hidden pr-24"
+ (isExperimental || isNew) &&
+ "w-full overflow-hidden",
+ isExperimental ? "pr-24" : isNew && "pr-12"
)}
>
<Link href={page.url}>
@@ -126,9 +129,9 @@ export function DocsSidebar({
{page.name}
</Link>
</SidebarMenuButton>
- {isExperimental ? (
+ {isExperimental || isNew ? (
<SidebarMenuBadge className="right-2 rounded-full border bg-background px-1.5 text-[0.625rem] tracking-wide text-muted-foreground uppercase">
- Experimental
+ {isExperimental ? "Experimental" : "New"}
</SidebarMenuBadge>
) : null}
</SidebarMenuItem>
diff --git a/apps/v4/components/extend/pdf-editor-shared.tsx b/apps/v4/components/extend/pdf-editor-shared.tsx
index b725cbe..35c1eae 100644
--- a/apps/v4/components/extend/pdf-editor-shared.tsx
+++ b/apps/v4/components/extend/pdf-editor-shared.tsx
@@ -729,7 +729,7 @@ export function LineGlyph({ className, style }: PdfEditorGlyphProps) {
<IconPlaceholder
lucide="Minus"
tabler="IconLine"
- hugeicons="LineIcon"
+ hugeicons="MinusSignIcon"
phosphor="LineSegmentIcon"
remixicon="RiSubtractLine"
className={className}