create-isotope-app 1.2.4 → 1.2.6
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.
- package/package.json +1 -1
- package/src/templates/core/kernel.js +12 -1
- package/src/templates/pages/posts.js +51 -25
package/package.json
CHANGED
|
@@ -126,7 +126,18 @@ class Kernel {
|
|
|
126
126
|
$replacement = "";
|
|
127
127
|
if (isset($data[$listKey]) && is_array($data[$listKey])) {
|
|
128
128
|
foreach ($data[$listKey] as $item) {
|
|
129
|
-
$
|
|
129
|
+
$rowHtml = $itemTpl;
|
|
130
|
+
if (is_array($item) || is_object($item)) {
|
|
131
|
+
$itemArray = (array)$item;
|
|
132
|
+
foreach ($itemArray as $k => $v) {
|
|
133
|
+
if (is_scalar($v)) {
|
|
134
|
+
$rowHtml = preg_replace('/\\\\{\\\\s*' . preg_quote($itemVar, '/') . '\\\\.' . preg_quote($k, '/') . '\\\\s*\\\\}/i', (string)$v, $rowHtml);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
$rowHtml = preg_replace('/\\\\{\\\\s*' . preg_quote($itemVar, '/') . '\\\\s*\\\\}/i', (string)$item, $rowHtml);
|
|
139
|
+
}
|
|
140
|
+
$replacement .= $rowHtml;
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
return $replacement;
|
|
@@ -5,37 +5,47 @@ export const postsPageIsx = (styleChoice) => {
|
|
|
5
5
|
export const nucleus = proton\`
|
|
6
6
|
// DATABASE CRUD EXAMPLE
|
|
7
7
|
try {
|
|
8
|
-
//
|
|
9
|
-
|
|
8
|
+
// Attempt to fetch from database
|
|
9
|
+
$posts = \\Isotope\\Database::query("SELECT * FROM posts ORDER BY created_at DESC")->fetchAll();
|
|
10
10
|
|
|
11
|
-
// Mock data for demonstration if DB is not connected
|
|
12
|
-
$posts = [
|
|
13
|
-
['id' => 1, 'title' => 'Getting Started with Isotope', 'content' => 'Isotope is amazing!', 'created_at' => '2024-02-15'],
|
|
14
|
-
['id' => 2, 'title' => 'Atomic Fusion Explained', 'content' => 'Combine PHP and React easily.', 'created_at' => '2024-02-16']
|
|
15
|
-
];
|
|
16
|
-
|
|
17
11
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
18
12
|
$action = $_POST['action'] ?? '';
|
|
19
|
-
if ($action === 'create') {
|
|
20
|
-
$title = $_POST['title']
|
|
21
|
-
|
|
13
|
+
if ($action === 'create' && !empty($_POST['title'])) {
|
|
14
|
+
$title = $_POST['title'];
|
|
15
|
+
\\Isotope\\Database::query("INSERT INTO posts (title, content) VALUES (?, ?)", [$title, "New content from Isotope"]);
|
|
22
16
|
header("Location: /posts");
|
|
23
17
|
exit;
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
'posts' => $posts,
|
|
29
|
-
'db_config' => $_ENV['DB_NAME'] ?? 'Not Configured'
|
|
30
|
-
];
|
|
31
20
|
} catch (\\Exception $e) {
|
|
32
|
-
|
|
21
|
+
// Fallback to mock data if database is not set up yet
|
|
22
|
+
$posts = [
|
|
23
|
+
['id' => 1, 'title' => 'Getting Started with Isotope', 'content' => 'Isotope is amazing!', 'created_at' => '2024-02-15'],
|
|
24
|
+
['id' => 2, 'title' => 'Atomic Fusion Explained', 'content' => 'Combine PHP and React easily.', 'created_at' => '2024-02-16']
|
|
25
|
+
];
|
|
33
26
|
}
|
|
27
|
+
|
|
28
|
+
return [
|
|
29
|
+
'posts' => $posts,
|
|
30
|
+
'db_config' => $_ENV['DB_NAME'] ?? 'Not Configured'
|
|
31
|
+
];
|
|
34
32
|
\`;
|
|
35
33
|
|
|
36
34
|
"use client";
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
interface Post {
|
|
37
|
+
id: number;
|
|
38
|
+
title: string;
|
|
39
|
+
content: string;
|
|
40
|
+
created_at?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PostsPageProps {
|
|
44
|
+
posts: Post[];
|
|
45
|
+
db_config?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function PostsPage({ posts, db_config }: PostsPageProps) {
|
|
39
49
|
return (
|
|
40
50
|
<div className="p-8 max-w-4xl mx-auto text-white">
|
|
41
51
|
<h1 className="text-4xl font-bold mb-8 text-[#00d4ff]">Blog Posts (CRUD Demo)</h1>
|
|
@@ -48,6 +58,7 @@ export default function PostsPage({ posts, db_config }) {
|
|
|
48
58
|
type="text"
|
|
49
59
|
name="title"
|
|
50
60
|
placeholder="Post title..."
|
|
61
|
+
required
|
|
51
62
|
className="flex-1 bg-black/40 border border-white/20 rounded-lg px-4 py-2 focus:border-[#00d4ff] outline-none"
|
|
52
63
|
/>
|
|
53
64
|
<button className="bg-[#00d4ff] text-black font-bold px-6 py-2 rounded-lg hover:bg-[#00b8e6] transition-colors">
|
|
@@ -58,7 +69,7 @@ export default function PostsPage({ posts, db_config }) {
|
|
|
58
69
|
</div>
|
|
59
70
|
|
|
60
71
|
<div className="space-y-4">
|
|
61
|
-
{posts.map(post => (
|
|
72
|
+
{posts.map((post: Post) => (
|
|
62
73
|
<div key={post.id} className="p-6 bg-white/5 rounded-xl border border-white/10 hover:border-[#00d4ff]/30 transition-all">
|
|
63
74
|
<div className="flex justify-between items-start mb-2">
|
|
64
75
|
<h3 className="text-2xl font-bold">{post.title}</h3>
|
|
@@ -76,10 +87,14 @@ export default function PostsPage({ posts, db_config }) {
|
|
|
76
87
|
return `import { proton } from '../../src/isotope';
|
|
77
88
|
|
|
78
89
|
export const nucleus = proton\`
|
|
79
|
-
// DATABASE CRUD EXAMPLE (Mock)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
// DATABASE CRUD EXAMPLE (Mock fallback)
|
|
91
|
+
try {
|
|
92
|
+
$posts = \\Isotope\\Database::query("SELECT * FROM posts ORDER BY created_at DESC")->fetchAll();
|
|
93
|
+
} catch (\\Exception $e) {
|
|
94
|
+
$posts = [
|
|
95
|
+
['id' => 1, 'title' => 'Default Template Post', 'content' => 'No Tailwind content here.']
|
|
96
|
+
];
|
|
97
|
+
}
|
|
83
98
|
return [
|
|
84
99
|
'posts' => $posts
|
|
85
100
|
];
|
|
@@ -87,11 +102,22 @@ return [
|
|
|
87
102
|
|
|
88
103
|
"use client";
|
|
89
104
|
|
|
90
|
-
|
|
105
|
+
interface Post {
|
|
106
|
+
id: number;
|
|
107
|
+
title: string;
|
|
108
|
+
content: string;
|
|
109
|
+
created_at?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface PostsPageProps {
|
|
113
|
+
posts: Post[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default function PostsPage({ posts }: PostsPageProps) {
|
|
91
117
|
return (
|
|
92
118
|
<div style={{ padding: '2rem', color: 'white' }}>
|
|
93
119
|
<h1>CRUD Demo</h1>
|
|
94
|
-
{posts.map(post => (
|
|
120
|
+
{posts.map((post: Post) => (
|
|
95
121
|
<div key={post.id} style={{ marginBottom: '1rem', padding: '1rem', border: '1px solid #333' }}>
|
|
96
122
|
<h3>{post.title}</h3>
|
|
97
123
|
<p>{post.content}</p>
|