Skip to content

Commit 896e35d

Browse files
committed
update theme file
1 parent f8ec206 commit 896e35d

3 files changed

Lines changed: 121 additions & 11 deletions

File tree

app/Concerns/HasTheme.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,21 @@ public function toRegistry(): array
148148
'devDependencies' => $this->devDependencies ?? [],
149149
'registryDependencies' => $this->registryDependencies ?? [],
150150
'files' => $this->files ?? [],
151-
'css' => $this->css ?? [],
152151
'tailwind' => $this->tailwind,
153-
'cssVars' => $this->buildCssVars(),
154152
'meta' => $this->meta,
155153
'docs' => $this->docs,
156154
'tags' => $this->tags->pluck('name')->toArray(),
157155
];
158156

157+
if (! empty($this->css)) {
158+
$registry['css'] = $this->css;
159+
}
160+
161+
$cssVars = $this->buildCssVars();
162+
if (! empty($cssVars)) {
163+
$registry['cssVars'] = $cssVars;
164+
}
165+
159166
if ($this->type === 'registry:style') {
160167
$registry['extends'] = $this->extends;
161168
}

resources/js/pages/dashboard/components/edit.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Head, Link, useForm } from '@inertiajs/react';
22
import { ArrowLeft, Plus, Trash2, Save, FileCode } from 'lucide-react';
3-
import React, { useState } from 'react';
43
import { toast } from 'sonner';
4+
import InputError from '@/components/input-error';
55
import { Button } from '@/components/ui/button';
6-
import { useFileHandling } from '@/hooks/use-file-handling';
76
import {
87
Card,
98
CardContent,
@@ -14,16 +13,17 @@ import {
1413
import { Input } from '@/components/ui/input';
1514
import { Label } from '@/components/ui/label';
1615
import { Textarea } from '@/components/ui/textarea';
17-
import InputError from '@/components/input-error';
18-
import { index, update } from '@/routes/dashboard/components';
16+
import { useFileHandling } from '@/hooks/use-file-handling';
1917
import { dashboard } from '@/routes';
20-
import MainEditorBlock from '@/layouts/main/theme/main-editor-block';
18+
import { index, update } from '@/routes/dashboard/components';
2119

2220
const getLanguageFromPath = (path: string) => {
2321
if (!path) {
2422
return 'typescript';
2523
}
24+
2625
const ext = path.split('.').pop()?.toLowerCase();
26+
2727
switch (ext) {
2828
case 'css':
2929
return 'css';
@@ -280,7 +280,9 @@ export default function EditComponent({
280280
{existingCategories.join(', ')}
281281
</p>
282282
)}
283-
<InputError message={(errors as any).categories} />
283+
<InputError
284+
message={(errors as any).categories}
285+
/>
284286
</div>
285287

286288
<div className="grid gap-4 sm:grid-cols-2">
@@ -299,7 +301,9 @@ export default function EditComponent({
299301
)
300302
}
301303
/>
302-
<InputError message={(errors as any).dependencies} />
304+
<InputError
305+
message={(errors as any).dependencies}
306+
/>
303307
</div>
304308
<div className="space-y-1">
305309
<Label htmlFor="registryDependencies">
@@ -317,7 +321,9 @@ export default function EditComponent({
317321
}
318322
/>
319323
<InputError
320-
message={(errors as any).registryDependencies}
324+
message={
325+
(errors as any).registryDependencies
326+
}
321327
/>
322328
</div>
323329
</div>
@@ -414,7 +420,8 @@ export default function EditComponent({
414420
Code Content
415421
</Label>
416422
<div className="overflow-hidden rounded-md border border-border/80 bg-background">
417-
<MainEditorBlock
423+
<MainEdit
424+
orBlock
418425
value={file.content}
419426
onChange={(val) =>
420427
handleFileChange(
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
use App\Models\Theme;
4+
use App\Models\User;
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
7+
uses(RefreshDatabase::class);
8+
9+
beforeEach(function () {
10+
User::factory()->create(['id' => 1]);
11+
});
12+
13+
test('theme registry endpoint returns the theme successfully', function () {
14+
$theme = Theme::factory()->create([
15+
'name' => 'japanese-zen',
16+
'css' => [],
17+
'vars_light' => [],
18+
'vars_dark' => [],
19+
'font_family' => null,
20+
]);
21+
22+
$response = $this->get('/r/themes/japanese-zen.json');
23+
24+
$response->assertOk()
25+
->assertJson([
26+
'name' => 'japanese-zen',
27+
'type' => 'registry:theme',
28+
]);
29+
});
30+
31+
test('theme registry endpoint omits empty css field to avoid empty array schema mismatch', function () {
32+
$theme = Theme::factory()->create([
33+
'name' => 'japanese-zen',
34+
'css' => [],
35+
]);
36+
37+
$response = $this->get('/r/themes/japanese-zen.json');
38+
39+
$response->assertOk();
40+
$data = $response->json();
41+
expect($data)->not->toHaveKey('css');
42+
});
43+
44+
test('theme registry endpoint includes css field when it is populated', function () {
45+
$theme = Theme::factory()->create([
46+
'name' => 'japanese-zen',
47+
'css' => [
48+
'@layer base' => [
49+
'body' => [
50+
'background' => 'var(--background)',
51+
],
52+
],
53+
],
54+
]);
55+
56+
$response = $this->get('/r/themes/japanese-zen.json');
57+
58+
$response->assertOk();
59+
$data = $response->json();
60+
expect($data)->toHaveKey('css')
61+
->and($data['css'])->toBeArray(); // Since decoded from JSON object into PHP associative array
62+
});
63+
64+
test('theme registry endpoint omits empty cssVars field', function () {
65+
$theme = Theme::factory()->create([
66+
'name' => 'japanese-zen',
67+
'vars_light' => [],
68+
'vars_dark' => [],
69+
'vars_theme' => [],
70+
'font_family' => null,
71+
'font_mono' => null,
72+
'font_serif' => null,
73+
]);
74+
75+
$response = $this->get('/r/themes/japanese-zen.json');
76+
77+
$response->assertOk();
78+
$data = $response->json();
79+
expect($data)->not->toHaveKey('cssVars');
80+
});
81+
82+
test('theme registry endpoint includes cssVars when populated', function () {
83+
$theme = Theme::factory()->create([
84+
'name' => 'japanese-zen',
85+
'vars_light' => [
86+
'background' => 'oklch(0.97 0.01 90)',
87+
],
88+
]);
89+
90+
$response = $this->get('/r/themes/japanese-zen.json');
91+
92+
$response->assertOk();
93+
$data = $response->json();
94+
expect($data)->toHaveKey('cssVars')
95+
->and($data['cssVars'])->toBeArray();
96+
});

0 commit comments

Comments
 (0)