create-nextblock 0.13.9 → 0.13.10
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/templates/nextblock-template/app/cms/blocks/components/BlockEditorArea.tsx +10 -1
- package/templates/nextblock-template/app/cms/blocks/components/ColumnEditor.tsx +5 -1
- package/templates/nextblock-template/app/cms/blocks/components/EditableBlock.tsx +55 -24
- package/templates/nextblock-template/app/cms/blocks/components/MultiEntityPicker.tsx +25 -13
- package/templates/nextblock-template/lib/blocks/blockRegistry.ts +21 -1
- package/templates/nextblock-template/next-env.d.ts +1 -1
- package/templates/nextblock-template/package.json +1 -1
- package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import type { Database, Json } from "@nextblock-cms/db";
|
|
|
9
9
|
import { BlockType } from '../../../../lib/blocks/blockRegistry';
|
|
10
10
|
|
|
11
11
|
type Block = Database["public"]["Tables"]["blocks"]["Row"];
|
|
12
|
-
import { getBlockDefinition, SectionBlockContent } from '../../../../lib/blocks/blockRegistry';
|
|
12
|
+
import { blockHasEditableContent, getBlockDefinition, SectionBlockContent } from '../../../../lib/blocks/blockRegistry';
|
|
13
13
|
import { Button } from "@nextblock-cms/ui";
|
|
14
14
|
import { PlusCircle } from "lucide-react";
|
|
15
15
|
import {
|
|
@@ -113,6 +113,8 @@ export default function BlockEditorArea({ parentId, parentType, initialBlocks, l
|
|
|
113
113
|
const [isBlockSelectorOpen, setIsBlockSelectorOpen] = useState(false);
|
|
114
114
|
const [activeBlock, setActiveBlock] = useState<Block | null>(null);
|
|
115
115
|
const [insertionIndex, setInsertionIndex] = useState<number | null>(null);
|
|
116
|
+
// Id of the block that was just added, so its editor can open on its own.
|
|
117
|
+
const [autoEditBlockId, setAutoEditBlockId] = useState<number | null>(null);
|
|
116
118
|
const [editingNestedBlockInfo, setEditingNestedBlockInfo] = useState<EditingNestedBlockInfo | null>(null);
|
|
117
119
|
const [NestedBlockEditorComponent, setNestedBlockEditorComponent] = useState<ComponentType<any> | null>(null);
|
|
118
120
|
const [tempNestedBlockContent, setTempNestedBlockContent] = useState<Json | null>(null);
|
|
@@ -377,6 +379,11 @@ export default function BlockEditorArea({ parentId, parentType, initialBlocks, l
|
|
|
377
379
|
|
|
378
380
|
setBlocks(finalBlocks);
|
|
379
381
|
lastSavedBlocks.current = finalBlocks;
|
|
382
|
+
// Context-driven blocks (cart, checkout, …) have nothing to configure,
|
|
383
|
+
// so only jump into the editor when there is something to edit.
|
|
384
|
+
if (blockHasEditableContent(blockType)) {
|
|
385
|
+
setAutoEditBlockId(newBlock.id);
|
|
386
|
+
}
|
|
380
387
|
router.refresh();
|
|
381
388
|
} else {
|
|
382
389
|
alert(`Error adding block: ${createResult?.error}`);
|
|
@@ -506,6 +513,8 @@ export default function BlockEditorArea({ parentId, parentType, initialBlocks, l
|
|
|
506
513
|
</div>
|
|
507
514
|
<SortableBlockItem
|
|
508
515
|
block={block}
|
|
516
|
+
autoOpenEditor={block.id === autoEditBlockId}
|
|
517
|
+
onAutoOpenHandled={() => setAutoEditBlockId(null)}
|
|
509
518
|
onContentChange={handleContentChange}
|
|
510
519
|
onDelete={async (blockIdToDelete) => {
|
|
511
520
|
startTransition(async () => {
|
|
@@ -5,7 +5,7 @@ import { cn } from '@nextblock-cms/utils';
|
|
|
5
5
|
import { Button } from '@nextblock-cms/ui';
|
|
6
6
|
import { PlusCircle, Trash2, Edit2, GripVertical, Image as ImageIcon } from "lucide-react";
|
|
7
7
|
import { SectionBlockContent } from '../../../../lib/blocks/blockRegistry';
|
|
8
|
-
import { availableBlockTypes, getBlockDefinition, getInitialContent, BlockType } from '../../../../lib/blocks/blockRegistry';
|
|
8
|
+
import { availableBlockTypes, blockHasEditableContent, getBlockDefinition, getInitialContent, BlockType } from '../../../../lib/blocks/blockRegistry';
|
|
9
9
|
import { useDroppable } from "@dnd-kit/core";
|
|
10
10
|
import { useSortable } from "@dnd-kit/sortable";
|
|
11
11
|
import { CSS } from "@dnd-kit/utilities";
|
|
@@ -415,6 +415,10 @@ export default function ColumnEditor({ columnIndex, blocks, onBlocksChange, bloc
|
|
|
415
415
|
temp_id: `temp-${Date.now()}-${Math.random()}`
|
|
416
416
|
};
|
|
417
417
|
onBlocksChange([...blocks, newBlock]);
|
|
418
|
+
// Open the new block's editor straight away, matching the top-level editor.
|
|
419
|
+
if (blockHasEditableContent(selectedBlockType)) {
|
|
420
|
+
handleStartEdit(newBlock, blocks.length);
|
|
421
|
+
}
|
|
418
422
|
};
|
|
419
423
|
|
|
420
424
|
const handleSelectBlockType = (selectedBlockType: BlockType) => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// app/cms/blocks/components/EditableBlock.tsx
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
|
-
import React, { useState, Suspense, useMemo, lazy, LazyExoticComponent, ComponentType } from 'react';
|
|
4
|
+
import React, { useState, useEffect, useRef, Suspense, useMemo, lazy, LazyExoticComponent, ComponentType } from 'react';
|
|
5
5
|
import type { Database } from "@nextblock-cms/db";
|
|
6
6
|
import PostsGridBlockEditor from '../editors/PostsGridBlockEditor';
|
|
7
7
|
|
|
8
8
|
type Block = Database['public']['Tables']['blocks']['Row'];
|
|
9
9
|
import { Button, Card, CardContent, Avatar, AvatarImage, AvatarFallback } from "@nextblock-cms/ui";
|
|
10
10
|
import { GripVertical, Edit2, Image as ImageIcon, MessageSquareQuote } from "lucide-react";
|
|
11
|
-
import { getBlockDefinition, blockRegistry, BlockType } from '../../../../lib/blocks/blockRegistry';
|
|
11
|
+
import { blockHasEditableContent, getBlockDefinition, blockRegistry, BlockType } from '../../../../lib/blocks/blockRegistry';
|
|
12
12
|
import { BlockEditorModal } from './BlockEditorModal';
|
|
13
13
|
import { DeleteBlockButtonClient } from './DeleteBlockButtonClient';
|
|
14
14
|
import { cn } from '@nextblock-cms/utils';
|
|
@@ -23,6 +23,10 @@ export interface EditableBlockProps {
|
|
|
23
23
|
dragHandleProps?: Record<string, any>;
|
|
24
24
|
onEditNestedBlock?: (parentBlockId: string, columnIndex: number, blockIndexInColumn: number) => void;
|
|
25
25
|
className?: string;
|
|
26
|
+
/** Open this block's editor as soon as it mounts — set for a just-added block. */
|
|
27
|
+
autoOpenEditor?: boolean;
|
|
28
|
+
/** Called once the auto-open has fired, so the parent can clear the flag. */
|
|
29
|
+
onAutoOpenHandled?: () => void;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export default function EditableBlock({
|
|
@@ -32,12 +36,15 @@ export default function EditableBlock({
|
|
|
32
36
|
dragHandleProps,
|
|
33
37
|
onEditNestedBlock,
|
|
34
38
|
className,
|
|
39
|
+
autoOpenEditor,
|
|
40
|
+
onAutoOpenHandled,
|
|
35
41
|
}: EditableBlockProps) {
|
|
36
42
|
void onEditNestedBlock;
|
|
37
43
|
// Move all hooks to the top before any conditional returns
|
|
38
44
|
const [isConfigPanelOpen, setIsConfigPanelOpen] = useState(false);
|
|
39
45
|
const [editingBlock, setEditingBlock] = useState<Block | null>(null);
|
|
40
46
|
const [LazyEditor, setLazyEditor] = useState<LazyExoticComponent<ComponentType<any>> | ComponentType<any> | null>(null);
|
|
47
|
+
const autoOpenedRef = useRef<number | null>(null);
|
|
41
48
|
|
|
42
49
|
const SectionEditor = useMemo(() => {
|
|
43
50
|
if (block?.block_type === 'section') {
|
|
@@ -49,15 +56,12 @@ export default function EditableBlock({
|
|
|
49
56
|
return null;
|
|
50
57
|
}, [block?.block_type]);
|
|
51
58
|
|
|
52
|
-
// Add a guard for undefined block prop after hooks
|
|
53
|
-
if (!block) {
|
|
54
|
-
// Or some other placeholder/error display
|
|
55
|
-
return <div className="p-4 border rounded-lg bg-card shadow text-red-500">Error: Block data is missing in EditableBlock.</div>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
59
|
const handleEditClick = () => {
|
|
60
|
+
// cart / checkout / product_details are context-driven: empty schema, and the
|
|
61
|
+
// editor file their registry entry names does not exist. Opening one throws.
|
|
62
|
+
if (!blockHasEditableContent(block.block_type)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
61
65
|
if (block.block_type === 'section') {
|
|
62
66
|
setIsConfigPanelOpen(prev => !prev);
|
|
63
67
|
} else {
|
|
@@ -87,6 +91,22 @@ export default function EditableBlock({
|
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
|
|
94
|
+
// A block the author just added opens straight into its editor — adding a
|
|
95
|
+
// heading is always followed by wanting to type one. The ref keeps it to once
|
|
96
|
+
// per block, so closing the editor (or a router refresh) does not reopen it.
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!autoOpenEditor || !block || autoOpenedRef.current === block.id) return;
|
|
99
|
+
autoOpenedRef.current = block.id;
|
|
100
|
+
handleEditClick();
|
|
101
|
+
onAutoOpenHandled?.();
|
|
102
|
+
}, [autoOpenEditor, block, handleEditClick, onAutoOpenHandled]);
|
|
103
|
+
|
|
104
|
+
// Add a guard for undefined block prop after hooks
|
|
105
|
+
if (!block) {
|
|
106
|
+
// Or some other placeholder/error display
|
|
107
|
+
return <div className="p-4 border rounded-lg bg-card shadow text-red-500">Error: Block data is missing in EditableBlock.</div>;
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
const handleCardClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
91
111
|
// If the element that was clicked, or any of its parents up to the card, is a button,
|
|
92
112
|
// then we should ignore the click on the card. This lets the button's own onClick handle the event.
|
|
@@ -279,14 +299,22 @@ export default function EditableBlock({
|
|
|
279
299
|
default: {
|
|
280
300
|
const blockDefinition = getBlockDefinition(currentBlockType as BlockType);
|
|
281
301
|
const blockLabel = blockDefinition?.label || currentBlockType;
|
|
302
|
+
const hasEditableContent = blockHasEditableContent(currentBlockType);
|
|
282
303
|
const placeholder = (
|
|
283
304
|
<div
|
|
284
|
-
className=
|
|
305
|
+
className={cn(
|
|
306
|
+
"py-4 flex flex-col items-center justify-center space-y-2 min-h-[80px] border border-dashed rounded-md bg-muted/20",
|
|
307
|
+
hasEditableContent && "cursor-pointer hover:border-primary"
|
|
308
|
+
)}
|
|
285
309
|
onClick={handleCardClick}
|
|
286
310
|
>
|
|
287
311
|
<div className="text-center">
|
|
288
312
|
<p className="text-sm font-medium text-muted-foreground">{blockLabel}</p>
|
|
289
|
-
<p className="text-xs text-muted-foreground">
|
|
313
|
+
<p className="text-xs text-muted-foreground">
|
|
314
|
+
{hasEditableContent
|
|
315
|
+
? 'Click edit to modify content'
|
|
316
|
+
: 'Renders from the current page context — nothing to configure'}
|
|
317
|
+
</p>
|
|
290
318
|
</div>
|
|
291
319
|
</div>
|
|
292
320
|
);
|
|
@@ -304,13 +332,14 @@ export default function EditableBlock({
|
|
|
304
332
|
|
|
305
333
|
const isSection = block?.block_type === 'section';
|
|
306
334
|
const blockDefinition = getBlockDefinition(block.block_type as BlockType);
|
|
335
|
+
const isEditable = blockHasEditableContent(block.block_type);
|
|
307
336
|
|
|
308
337
|
return (
|
|
309
338
|
<div
|
|
310
339
|
onClick={handleCardClick}
|
|
311
340
|
className={cn(
|
|
312
341
|
"p-4 border rounded-lg bg-card shadow",
|
|
313
|
-
!isSection && "cursor-pointer hover:border-primary transition-colors",
|
|
342
|
+
!isSection && isEditable && "cursor-pointer hover:border-primary transition-colors",
|
|
314
343
|
className
|
|
315
344
|
)}
|
|
316
345
|
>
|
|
@@ -322,17 +351,19 @@ export default function EditableBlock({
|
|
|
322
351
|
<h4 className="font-semibold p-0 m-0 mb-1">{blockDefinition?.label || block.block_type}</h4>
|
|
323
352
|
</div>
|
|
324
353
|
<div className="flex items-center gap-1">
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
e
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
354
|
+
{isEditable && (
|
|
355
|
+
<Button
|
|
356
|
+
variant="ghost"
|
|
357
|
+
size="icon"
|
|
358
|
+
onClick={(e) => {
|
|
359
|
+
e.stopPropagation();
|
|
360
|
+
handleEditClick();
|
|
361
|
+
}}
|
|
362
|
+
aria-label={isSection ? "Toggle Section Config" : "Edit block"}
|
|
363
|
+
>
|
|
364
|
+
<Edit2 className="h-4 w-4 text-muted-foreground" />
|
|
365
|
+
</Button>
|
|
366
|
+
)}
|
|
336
367
|
<DeleteBlockButtonClient
|
|
337
368
|
blockId={block.id}
|
|
338
369
|
blockTitle={blockDefinition?.label || block.block_type}
|
|
@@ -5,7 +5,6 @@ import { Check, ChevronsUpDown, Loader2, Search, X } from 'lucide-react';
|
|
|
5
5
|
import {
|
|
6
6
|
Badge,
|
|
7
7
|
Button,
|
|
8
|
-
Checkbox,
|
|
9
8
|
Input,
|
|
10
9
|
Popover,
|
|
11
10
|
PopoverContent,
|
|
@@ -13,6 +12,25 @@ import {
|
|
|
13
12
|
} from '@nextblock-cms/ui';
|
|
14
13
|
import { cn } from '@nextblock-cms/utils';
|
|
15
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A checkbox *look* without the interactive element. The whole option row is the
|
|
17
|
+
* button, and Radix's `Checkbox` renders its own `<button>` — nesting the two is
|
|
18
|
+
* invalid HTML and breaks hydration.
|
|
19
|
+
*/
|
|
20
|
+
function CheckIndicator({ checked }: { checked: boolean }) {
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
aria-hidden="true"
|
|
24
|
+
className={cn(
|
|
25
|
+
'flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-[4px] border border-primary transition-colors',
|
|
26
|
+
checked && 'bg-primary text-primary-foreground'
|
|
27
|
+
)}
|
|
28
|
+
>
|
|
29
|
+
{checked && <Check className="h-3 w-3" />}
|
|
30
|
+
</span>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
16
34
|
export interface PickerOption {
|
|
17
35
|
id: string;
|
|
18
36
|
label: string;
|
|
@@ -179,7 +197,11 @@ export default function MultiEntityPicker({
|
|
|
179
197
|
/>
|
|
180
198
|
</div>
|
|
181
199
|
|
|
182
|
-
<div
|
|
200
|
+
<div
|
|
201
|
+
role="listbox"
|
|
202
|
+
aria-multiselectable="true"
|
|
203
|
+
className="max-h-60 overflow-y-auto p-1"
|
|
204
|
+
>
|
|
183
205
|
{filteredOptions.length === 0 ? (
|
|
184
206
|
<p className="py-6 text-center text-xs text-muted-foreground">
|
|
185
207
|
{isLoading ? 'Loading…' : emptyMessage}
|
|
@@ -204,12 +226,7 @@ export default function MultiEntityPicker({
|
|
|
204
226
|
isChecked && 'bg-accent/40'
|
|
205
227
|
)}
|
|
206
228
|
>
|
|
207
|
-
<
|
|
208
|
-
checked={isChecked}
|
|
209
|
-
tabIndex={-1}
|
|
210
|
-
aria-hidden="true"
|
|
211
|
-
className="pointer-events-none h-3.5 w-3.5 shrink-0"
|
|
212
|
-
/>
|
|
229
|
+
<CheckIndicator checked={isChecked} />
|
|
213
230
|
<span className="flex min-w-0 flex-col">
|
|
214
231
|
<span className="truncate font-medium">{option.label}</span>
|
|
215
232
|
{option.description && (
|
|
@@ -226,11 +243,6 @@ export default function MultiEntityPicker({
|
|
|
226
243
|
{option.badge}
|
|
227
244
|
</Badge>
|
|
228
245
|
)}
|
|
229
|
-
{isChecked && (
|
|
230
|
-
<Check
|
|
231
|
-
className={cn('h-3.5 w-3.5 shrink-0 text-primary', !option.badge && 'ml-auto')}
|
|
232
|
-
/>
|
|
233
|
-
)}
|
|
234
246
|
</button>
|
|
235
247
|
);
|
|
236
248
|
})
|
|
@@ -572,9 +572,29 @@ export function getBlockDefinition(blockType: string): BlockDefinition | undefin
|
|
|
572
572
|
return undefined;
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Whether a block type has anything for an author to configure.
|
|
577
|
+
*
|
|
578
|
+
* `cart`, `checkout` and `product_details` are context-driven: they declare an
|
|
579
|
+
* empty schema and ship no editor file at all, so opening an editor for them
|
|
580
|
+
* would show an empty dialog (and fail on the missing module). Used to decide
|
|
581
|
+
* whether adding a block should jump straight into its editor.
|
|
582
|
+
*
|
|
583
|
+
* @param blockType - The block type or custom-block slug
|
|
584
|
+
* @returns true when the block exposes editable fields
|
|
585
|
+
*/
|
|
586
|
+
export function blockHasEditableContent(blockType: string): boolean {
|
|
587
|
+
const definition = getBlockDefinition(blockType);
|
|
588
|
+
// Custom blocks are not in the registry; they always render a field editor.
|
|
589
|
+
if (!definition) return true;
|
|
590
|
+
const shape = (definition.schema as unknown as { shape?: Record<string, unknown> })?.shape;
|
|
591
|
+
if (!shape) return true;
|
|
592
|
+
return Object.keys(shape).length > 0;
|
|
593
|
+
}
|
|
594
|
+
|
|
575
595
|
/**
|
|
576
596
|
* Get the initial content for a specific block type
|
|
577
|
-
*
|
|
597
|
+
*
|
|
578
598
|
* @param blockType - The type of block to get initial content for
|
|
579
599
|
* @returns The initial content object or undefined if block type not found
|
|
580
600
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="next" />
|
|
2
2
|
/// <reference types="next/image-types/global" />
|
|
3
|
-
import "./.next/types/routes.d.ts";
|
|
3
|
+
import "./.next/dev/types/routes.d.ts";
|
|
4
4
|
|
|
5
5
|
// NOTE: This file should not be edited
|
|
6
6
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|