create-nextblock 0.14.2 → 0.14.5

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 (68) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/[slug]/page.tsx +7 -2
  3. package/templates/nextblock-template/app/[slug]/page.utils.ts +8 -3
  4. package/templates/nextblock-template/app/actions/postActions.ts +3 -0
  5. package/templates/nextblock-template/app/actions/visibilityActions.ts +210 -0
  6. package/templates/nextblock-template/app/actions/visualEditingActions.test.ts +83 -3
  7. package/templates/nextblock-template/app/actions/visualEditingActions.ts +34 -14
  8. package/templates/nextblock-template/app/api/ai/global-agent/route.ts +45 -0
  9. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +736 -117
  10. package/templates/nextblock-template/app/api/view/route.ts +114 -0
  11. package/templates/nextblock-template/app/article/[slug]/page.utils.ts +1 -2
  12. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +2 -2
  13. package/templates/nextblock-template/app/cms/blocks/components/ColumnEditor.tsx +17 -22
  14. package/templates/nextblock-template/app/cms/blocks/components/EditableBlock.tsx +13 -19
  15. package/templates/nextblock-template/app/cms/blocks/editors/HeadingBlockEditor.tsx +45 -34
  16. package/templates/nextblock-template/app/cms/components/DraftStatusActions.tsx +10 -0
  17. package/templates/nextblock-template/app/cms/components/VisibilityBadge.tsx +62 -0
  18. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +528 -0
  19. package/templates/nextblock-template/app/cms/pages/[id]/edit/EditPageClient.tsx +33 -17
  20. package/templates/nextblock-template/app/cms/pages/[id]/edit/page.tsx +19 -7
  21. package/templates/nextblock-template/app/cms/pages/actions.ts +17 -10
  22. package/templates/nextblock-template/app/cms/pages/components/PageForm.tsx +7 -29
  23. package/templates/nextblock-template/app/cms/pages/page.tsx +6 -19
  24. package/templates/nextblock-template/app/cms/posts/[id]/edit/page.tsx +42 -18
  25. package/templates/nextblock-template/app/cms/posts/actions.ts +16 -27
  26. package/templates/nextblock-template/app/cms/posts/components/PostForm.tsx +3 -60
  27. package/templates/nextblock-template/app/cms/posts/page.tsx +6 -13
  28. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +63 -9
  29. package/templates/nextblock-template/app/cms/revisions/RevisionHistoryButton.tsx +66 -32
  30. package/templates/nextblock-template/app/cms/revisions/actions.ts +332 -285
  31. package/templates/nextblock-template/app/cms/revisions/service.test.ts +498 -0
  32. package/templates/nextblock-template/app/cms/revisions/service.ts +549 -471
  33. package/templates/nextblock-template/app/cms/revisions/utils.ts +304 -132
  34. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeEditor.tsx +382 -0
  35. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeManager.tsx +267 -0
  36. package/templates/nextblock-template/app/cms/settings/global-css/page.tsx +40 -24
  37. package/templates/nextblock-template/app/cms/settings/global-css/theme-actions.ts +259 -0
  38. package/templates/nextblock-template/app/layout.tsx +49 -0
  39. package/templates/nextblock-template/app/lib/sitemap-utils.ts +6 -4
  40. package/templates/nextblock-template/app/lib/ucp/server.ts +4 -1
  41. package/templates/nextblock-template/app/page.tsx +6 -3
  42. package/templates/nextblock-template/app/product/[slug]/page.tsx +27 -3
  43. package/templates/nextblock-template/app/providers.tsx +16 -4
  44. package/templates/nextblock-template/components/blocks/renderers/HeadingBlockRenderer.tsx +7 -10
  45. package/templates/nextblock-template/components/theme-icon.tsx +78 -0
  46. package/templates/nextblock-template/components/theme-switcher.tsx +85 -90
  47. package/templates/nextblock-template/components/visual-editing/NextblockVisualEditing.tsx +4 -1
  48. package/templates/nextblock-template/context/ThemeCatalogContext.tsx +44 -0
  49. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +77 -0
  50. package/templates/nextblock-template/docs/04-DATABASE-AND-AUTH.md +7 -2
  51. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +114 -0
  52. package/templates/nextblock-template/lib/blocks/blockColors.ts +132 -0
  53. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +17 -1
  54. package/templates/nextblock-template/lib/cms-transfer/server.ts +13 -0
  55. package/templates/nextblock-template/lib/full-backup/server.ts +1 -0
  56. package/templates/nextblock-template/lib/publishing/viewUrl.ts +26 -0
  57. package/templates/nextblock-template/lib/search/server.ts +3 -0
  58. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +102 -87
  59. package/templates/nextblock-template/lib/themes/buildThemeCss.test.ts +163 -0
  60. package/templates/nextblock-template/lib/themes/buildThemeCss.ts +124 -0
  61. package/templates/nextblock-template/lib/themes/tokenColor.ts +31 -0
  62. package/templates/nextblock-template/lib/themes/tokens.ts +143 -0
  63. package/templates/nextblock-template/lib/visual-editing/mutations.ts +4 -1
  64. package/templates/nextblock-template/lib/visual-editing/product-drafts.ts +46 -1
  65. package/templates/nextblock-template/next-env.d.ts +2 -2
  66. package/templates/nextblock-template/package.json +1 -1
  67. package/templates/nextblock-template/scripts/verify-site-themes.ts +63 -0
  68. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -1,132 +1,304 @@
1
- // apps/nextblock/app/cms/revisions/utils.ts
2
- import { createClient } from "@nextblock-cms/db/server";
3
- import type { Database, Json } from "@nextblock-cms/db";
4
-
5
- type BlockRow = Database['public']['Tables']['blocks']['Row'];
6
-
7
- export interface PageMetaContent {
8
- title: string;
9
- slug: string;
10
- language_id: number;
11
- status: Database['public']['Enums']['page_status'];
12
- meta_title: string | null;
13
- meta_description: string | null;
14
- feature_image_id: string | null;
15
- }
16
-
17
- export interface PostMetaContent extends PageMetaContent {
18
- label: string | null;
19
- excerpt: string | null;
20
- subtitle: string | null;
21
- published_at: string | null;
22
- feature_image_id: string | null;
23
- }
24
-
25
- export interface SimpleBlockContent {
26
- language_id: number;
27
- block_type: BlockRow['block_type'];
28
- content: Json;
29
- order: number;
30
- }
31
-
32
- export interface FullPageContent {
33
- meta: PageMetaContent;
34
- blocks: SimpleBlockContent[];
35
- }
36
-
37
- export interface FullPostContent {
38
- meta: PostMetaContent;
39
- blocks: SimpleBlockContent[];
40
- }
41
-
42
- export async function getFullPageContent(
43
- pageId: number,
44
- opts?: { overrideBlockId?: number; overrideBlockContent?: unknown; excludeDeletedBlockId?: number }
45
- ): Promise<FullPageContent | null> {
46
- const supabase = createClient();
47
- const { data: page, error: pageError } = await supabase
48
- .from('pages')
49
- .select('id, title, slug, language_id, status, meta_title, meta_description, feature_image_id')
50
- .eq('id', pageId)
51
- .single();
52
- if (pageError || !page) return null;
53
-
54
- const { data: blocks, error: blocksError } = await supabase
55
- .from('blocks')
56
- .select('id, language_id, block_type, content, order, page_id, post_id')
57
- .eq('page_id', pageId)
58
- .order('order', { ascending: true });
59
- if (blocksError) return null;
60
-
61
- const processed = (blocks || [])
62
- .filter(b => opts?.excludeDeletedBlockId ? b.id !== opts.excludeDeletedBlockId : true)
63
- .map(b => ({
64
- language_id: b.language_id,
65
- block_type: b.block_type,
66
- content: (opts?.overrideBlockId && b.id === opts.overrideBlockId)
67
- ? (opts.overrideBlockContent as Json)
68
- : (b.content as Json),
69
- order: b.order,
70
- } satisfies SimpleBlockContent));
71
-
72
- return {
73
- meta: {
74
- title: page.title,
75
- slug: page.slug,
76
- language_id: page.language_id,
77
- status: page.status,
78
- meta_title: page.meta_title,
79
- meta_description: page.meta_description,
80
- feature_image_id: page.feature_image_id ?? null,
81
- },
82
- blocks: processed,
83
- };
84
- }
85
-
86
- export async function getFullPostContent(
87
- postId: number,
88
- opts?: { overrideBlockId?: number; overrideBlockContent?: unknown; excludeDeletedBlockId?: number }
89
- ): Promise<FullPostContent | null> {
90
- const supabase = createClient();
91
- const { data: post, error: postError } = await supabase
92
- .from('posts')
93
- .select('id, title, slug, language_id, status, meta_title, meta_description, label, excerpt, subtitle, published_at, feature_image_id')
94
- .eq('id', postId)
95
- .single();
96
- if (postError || !post) return null;
97
-
98
- const { data: blocks, error: blocksError } = await supabase
99
- .from('blocks')
100
- .select('id, language_id, block_type, content, order, page_id, post_id')
101
- .eq('post_id', postId)
102
- .order('order', { ascending: true });
103
- if (blocksError) return null;
104
-
105
- const processed = (blocks || [])
106
- .filter(b => opts?.excludeDeletedBlockId ? b.id !== opts.excludeDeletedBlockId : true)
107
- .map(b => ({
108
- language_id: b.language_id,
109
- block_type: b.block_type,
110
- content: (opts?.overrideBlockId && b.id === opts.overrideBlockId)
111
- ? (opts.overrideBlockContent as Json)
112
- : (b.content as Json),
113
- order: b.order,
114
- } satisfies SimpleBlockContent));
115
-
116
- return {
117
- meta: {
118
- title: post.title,
119
- slug: post.slug,
120
- language_id: post.language_id,
121
- status: post.status,
122
- meta_title: post.meta_title,
123
- meta_description: post.meta_description,
124
- label: post.label,
125
- excerpt: post.excerpt,
126
- subtitle: post.subtitle,
127
- published_at: post.published_at ? new Date(post.published_at).toISOString() : null,
128
- feature_image_id: post.feature_image_id ?? null,
129
- },
130
- blocks: processed,
131
- };
132
- }
1
+ // apps/nextblock/app/cms/revisions/utils.ts
2
+ import { createClient } from "@nextblock-cms/db/server";
3
+ import type { Database, Json } from "@nextblock-cms/db";
4
+
5
+ type BlockRow = Database['public']['Tables']['blocks']['Row'];
6
+
7
+ /**
8
+ * The columns a revision snapshot captures, in one place.
9
+ *
10
+ * These lists are the contract between four things that must agree exactly:
11
+ * - the SELECTs in this file (what a snapshot records),
12
+ * - the UPDATEs in service.ts (what a restore replays),
13
+ * - the jsonb_build_object() calls in migration 00000000000016 (the stored baseline),
14
+ * - RESTORE_EXCLUDED_META_COLUMNS below (what a restore must never replay).
15
+ *
16
+ * Anything editable that is missing here is silently un-restorable: a publish that only
17
+ * changed that field produces an empty JSON Patch, which createPageRevision treats as
18
+ * "nothing happened" and drops on the floor.
19
+ */
20
+ export const PAGE_META_COLUMNS = [
21
+ 'title',
22
+ 'slug',
23
+ 'language_id',
24
+ 'status',
25
+ 'meta_title',
26
+ 'meta_description',
27
+ 'custom_canonical',
28
+ 'published_at',
29
+ 'feature_image_id',
30
+ ] as const;
31
+
32
+ export const POST_META_COLUMNS = [
33
+ ...PAGE_META_COLUMNS,
34
+ 'label',
35
+ 'excerpt',
36
+ 'subtitle',
37
+ ] as const;
38
+
39
+ export const PRODUCT_META_COLUMNS = [
40
+ 'title',
41
+ 'slug',
42
+ 'language_id',
43
+ 'status',
44
+ 'meta_title',
45
+ 'meta_description',
46
+ 'custom_canonical',
47
+ 'published_at',
48
+ 'short_description',
49
+ 'description_json',
50
+ ] as const;
51
+
52
+ /**
53
+ * Visibility is owned by setContentVisibility (app/actions/visibilityActions.ts), which
54
+ * deliberately bypasses the draft/revision pipeline. Both fields are still *captured* —
55
+ * they are useful history — but replaying them on restore would let "restore the wording
56
+ * from last Tuesday" silently unpublish a live page or resurrect a cancelled schedule.
57
+ *
58
+ * They are excluded from change detection for the same reason: a status flip made from
59
+ * the top bar would otherwise be misattributed to whichever author saved next.
60
+ */
61
+ export const RESTORE_EXCLUDED_META_COLUMNS = ['status', 'published_at'] as const;
62
+
63
+ export interface PageMetaContent {
64
+ title: string;
65
+ slug: string;
66
+ language_id: number;
67
+ status: Database['public']['Enums']['page_status'];
68
+ meta_title: string | null;
69
+ meta_description: string | null;
70
+ custom_canonical: string | null;
71
+ published_at: string | null;
72
+ feature_image_id: string | null;
73
+ }
74
+
75
+ export interface PostMetaContent extends PageMetaContent {
76
+ label: string | null;
77
+ excerpt: string | null;
78
+ subtitle: string | null;
79
+ }
80
+
81
+ export interface ProductMetaContent {
82
+ title: string;
83
+ slug: string;
84
+ language_id: number;
85
+ status: string;
86
+ meta_title: string | null;
87
+ meta_description: string | null;
88
+ custom_canonical: string | null;
89
+ published_at: string | null;
90
+ short_description: string | null;
91
+ description_json: Json | null;
92
+ }
93
+
94
+ export interface SimpleBlockContent {
95
+ language_id: number;
96
+ block_type: BlockRow['block_type'];
97
+ content: Json;
98
+ order: number;
99
+ }
100
+
101
+ export interface FullPageContent {
102
+ meta: PageMetaContent;
103
+ blocks: SimpleBlockContent[];
104
+ }
105
+
106
+ export interface FullPostContent {
107
+ meta: PostMetaContent;
108
+ blocks: SimpleBlockContent[];
109
+ }
110
+
111
+ export interface FullProductContent {
112
+ meta: ProductMetaContent;
113
+ blocks: SimpleBlockContent[];
114
+ }
115
+
116
+ export type AnyFullContent = FullPageContent | FullPostContent | FullProductContent;
117
+
118
+ /**
119
+ * Any Supabase client shape. Callers pass the cookie-scoped client, the service-role client,
120
+ * or nothing at all — the generics on those two differ enough that a union of them makes
121
+ * `.from()` uncallable, so this stays deliberately loose.
122
+ */
123
+ type AnySupabaseClient = any;
124
+
125
+ /**
126
+ * Normalise a timestamp to the exact format JSON snapshots use everywhere else —
127
+ * `Date#toISOString()`, millisecond precision, `Z` suffix. Postgres renders timestamptz
128
+ * with microseconds and a `+00:00` offset, so without this a value that round-trips
129
+ * through the database comes back textually different and shows up as a phantom diff.
130
+ */
131
+ function normalizeTimestamp(value: string | null | undefined): string | null {
132
+ if (!value) return null;
133
+ const parsed = new Date(value);
134
+ return Number.isNaN(parsed.getTime()) ? null : parsed.toISOString();
135
+ }
136
+
137
+ interface BlockCaptureOptions {
138
+ overrideBlockId?: number;
139
+ overrideBlockContent?: unknown;
140
+ excludeDeletedBlockId?: number;
141
+ }
142
+
143
+ /** Reduce raw block rows to the id-free shape stored in revisions. */
144
+ function toSimpleBlocks(
145
+ blocks: Pick<BlockRow, 'id' | 'language_id' | 'block_type' | 'content' | 'order'>[] | null,
146
+ opts?: BlockCaptureOptions
147
+ ): SimpleBlockContent[] {
148
+ return (blocks || [])
149
+ .filter(b => (opts?.excludeDeletedBlockId ? b.id !== opts.excludeDeletedBlockId : true))
150
+ .map(b => ({
151
+ language_id: b.language_id,
152
+ block_type: b.block_type,
153
+ content: (opts?.overrideBlockId && b.id === opts.overrideBlockId)
154
+ ? (opts.overrideBlockContent as Json)
155
+ : (b.content as Json),
156
+ order: b.order,
157
+ } satisfies SimpleBlockContent));
158
+ }
159
+
160
+ /**
161
+ * Blocks are ordered by `order` then `id`. Revision blocks carry no id, so their array
162
+ * position *is* their identity — two blocks sharing an `order` value would otherwise swap
163
+ * places between two reads and register as a content change that never happened.
164
+ */
165
+ const BLOCK_SELECT = 'id, language_id, block_type, content, order';
166
+
167
+ export async function getFullPageContent(
168
+ pageId: number,
169
+ opts?: BlockCaptureOptions,
170
+ client?: AnySupabaseClient
171
+ ): Promise<FullPageContent | null> {
172
+ const supabase = (client ?? createClient()) as AnySupabaseClient;
173
+ const { data: page, error: pageError } = await supabase
174
+ .from('pages')
175
+ .select(`id, ${PAGE_META_COLUMNS.join(', ')}`)
176
+ .eq('id', pageId)
177
+ .single();
178
+ if (pageError || !page) return null;
179
+
180
+ const { data: blocks, error: blocksError } = await supabase
181
+ .from('blocks')
182
+ .select(BLOCK_SELECT)
183
+ .eq('page_id', pageId)
184
+ .order('order', { ascending: true })
185
+ .order('id', { ascending: true });
186
+ if (blocksError) return null;
187
+
188
+ const row = page as Record<string, any>;
189
+
190
+ return {
191
+ meta: {
192
+ title: row['title'],
193
+ slug: row['slug'],
194
+ language_id: row['language_id'],
195
+ status: row['status'],
196
+ meta_title: row['meta_title'] ?? null,
197
+ meta_description: row['meta_description'] ?? null,
198
+ custom_canonical: row['custom_canonical'] ?? null,
199
+ published_at: normalizeTimestamp(row['published_at']),
200
+ feature_image_id: row['feature_image_id'] ?? null,
201
+ },
202
+ blocks: toSimpleBlocks(blocks as any, opts),
203
+ };
204
+ }
205
+
206
+ export async function getFullPostContent(
207
+ postId: number,
208
+ opts?: BlockCaptureOptions,
209
+ client?: AnySupabaseClient
210
+ ): Promise<FullPostContent | null> {
211
+ const supabase = (client ?? createClient()) as AnySupabaseClient;
212
+ const { data: post, error: postError } = await supabase
213
+ .from('posts')
214
+ .select(`id, ${POST_META_COLUMNS.join(', ')}`)
215
+ .eq('id', postId)
216
+ .single();
217
+ if (postError || !post) return null;
218
+
219
+ const { data: blocks, error: blocksError } = await supabase
220
+ .from('blocks')
221
+ .select(BLOCK_SELECT)
222
+ .eq('post_id', postId)
223
+ .order('order', { ascending: true })
224
+ .order('id', { ascending: true });
225
+ if (blocksError) return null;
226
+
227
+ const row = post as Record<string, any>;
228
+
229
+ return {
230
+ meta: {
231
+ title: row['title'],
232
+ slug: row['slug'],
233
+ language_id: row['language_id'],
234
+ status: row['status'],
235
+ meta_title: row['meta_title'] ?? null,
236
+ meta_description: row['meta_description'] ?? null,
237
+ custom_canonical: row['custom_canonical'] ?? null,
238
+ published_at: normalizeTimestamp(row['published_at']),
239
+ feature_image_id: row['feature_image_id'] ?? null,
240
+ label: row['label'] ?? null,
241
+ excerpt: row['excerpt'] ?? null,
242
+ subtitle: row['subtitle'] ?? null,
243
+ },
244
+ blocks: toSimpleBlocks(blocks as any, opts),
245
+ };
246
+ }
247
+
248
+ export async function getFullProductContent(
249
+ productId: string,
250
+ opts?: BlockCaptureOptions,
251
+ client?: AnySupabaseClient
252
+ ): Promise<FullProductContent | null> {
253
+ const supabase = (client ?? createClient()) as AnySupabaseClient;
254
+ const { data: product, error: productError } = await supabase
255
+ .from('products')
256
+ .select(`id, ${PRODUCT_META_COLUMNS.join(', ')}`)
257
+ .eq('id', productId)
258
+ .single();
259
+ if (productError || !product) return null;
260
+
261
+ const { data: blocks, error: blocksError } = await supabase
262
+ .from('blocks')
263
+ .select(BLOCK_SELECT)
264
+ .eq('product_id', productId)
265
+ .order('order', { ascending: true })
266
+ .order('id', { ascending: true });
267
+ if (blocksError) return null;
268
+
269
+ const row = product as Record<string, any>;
270
+
271
+ return {
272
+ meta: {
273
+ title: row['title'],
274
+ slug: row['slug'],
275
+ language_id: row['language_id'],
276
+ status: row['status'],
277
+ meta_title: row['meta_title'] ?? null,
278
+ meta_description: row['meta_description'] ?? null,
279
+ custom_canonical: row['custom_canonical'] ?? null,
280
+ published_at: normalizeTimestamp(row['published_at']),
281
+ short_description: row['short_description'] ?? null,
282
+ description_json: (row['description_json'] ?? null) as Json | null,
283
+ },
284
+ blocks: toSimpleBlocks(blocks as any, opts),
285
+ };
286
+ }
287
+
288
+ /**
289
+ * Build the meta payload a restore writes back, minus the fields a restore must never
290
+ * replay (see RESTORE_EXCLUDED_META_COLUMNS).
291
+ */
292
+ export function buildRestoreMetaUpdate(
293
+ meta: Record<string, unknown>,
294
+ columns: readonly string[]
295
+ ): Record<string, unknown> {
296
+ const excluded = new Set<string>(RESTORE_EXCLUDED_META_COLUMNS);
297
+ const update: Record<string, unknown> = {};
298
+ for (const column of columns) {
299
+ if (excluded.has(column)) continue;
300
+ if (!Object.prototype.hasOwnProperty.call(meta, column)) continue;
301
+ update[column] = meta[column];
302
+ }
303
+ return update;
304
+ }