create-nextblock 0.13.7 → 0.13.9

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 (44) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/(auth-pages)/two-factor/actions.ts +21 -1
  3. package/templates/nextblock-template/app/(auth-pages)/two-factor/components/TwoFactorForm.tsx +34 -10
  4. package/templates/nextblock-template/app/actions/email.ts +78 -7
  5. package/templates/nextblock-template/app/actions/feedback.ts +57 -14
  6. package/templates/nextblock-template/app/actions/interactions.test.ts +3 -0
  7. package/templates/nextblock-template/app/actions/productGridActions.ts +40 -0
  8. package/templates/nextblock-template/app/actions.ts +17 -4
  9. package/templates/nextblock-template/app/api/cms/ecommerce/product-picker/route.ts +151 -0
  10. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +4 -1
  11. package/templates/nextblock-template/app/cms/blocks/components/BlockTypeSelector.tsx +17 -5
  12. package/templates/nextblock-template/app/cms/blocks/components/MultiEntityPicker.tsx +251 -0
  13. package/templates/nextblock-template/app/cms/blocks/editors/ProductGridBlockEditor.tsx +375 -18
  14. package/templates/nextblock-template/app/cms/components/EcommerceActiveContext.tsx +27 -0
  15. package/templates/nextblock-template/app/cms/settings/bot-protection/actions.ts +9 -6
  16. package/templates/nextblock-template/app/cms/settings/bot-protection/components/BotProtectionForm.tsx +1 -5
  17. package/templates/nextblock-template/app/cms/settings/copyright/actions.ts +9 -6
  18. package/templates/nextblock-template/app/cms/settings/copyright/components/CopyrightForm.tsx +1 -5
  19. package/templates/nextblock-template/app/cms/settings/cortex-ai/actions.ts +18 -8
  20. package/templates/nextblock-template/app/cms/settings/email/actions.ts +59 -29
  21. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +5 -1
  22. package/templates/nextblock-template/app/cms/settings/global-css/actions.ts +6 -5
  23. package/templates/nextblock-template/app/cms/settings/global-css/components/GlobalCssForm.tsx +2 -1
  24. package/templates/nextblock-template/app/cms/settings/google-analytics/actions.ts +18 -7
  25. package/templates/nextblock-template/app/cms/settings/google-analytics/components/GoogleAnalyticsForm.tsx +1 -1
  26. package/templates/nextblock-template/app/cms/settings/privacy/actions.ts +16 -7
  27. package/templates/nextblock-template/app/cms/settings/privacy/components/PrivacyForm.tsx +1 -1
  28. package/templates/nextblock-template/app/cms/settings/registration/actions.ts +18 -7
  29. package/templates/nextblock-template/app/cms/settings/registration/components/RegistrationForm.tsx +1 -1
  30. package/templates/nextblock-template/app/cms/settings/security/actions.ts +227 -131
  31. package/templates/nextblock-template/app/cms/settings/security/components/SecurityPanel.tsx +134 -18
  32. package/templates/nextblock-template/components/blocks/ProductGridClient.tsx +114 -0
  33. package/templates/nextblock-template/lib/auth/twoFactor.test.ts +254 -0
  34. package/templates/nextblock-template/lib/auth/twoFactor.ts +56 -13
  35. package/templates/nextblock-template/lib/blocks/ProductGridBlock.tsx +78 -139
  36. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +3 -3
  37. package/templates/nextblock-template/lib/blocks/blockTypes.ts +19 -0
  38. package/templates/nextblock-template/lib/blocks/ecommerce-block-schemas.ts +61 -2
  39. package/templates/nextblock-template/lib/blocks/product-grid-data.ts +210 -0
  40. package/templates/nextblock-template/lib/cms/action-result.ts +12 -0
  41. package/templates/nextblock-template/lib/config/email-settings.ts +40 -3
  42. package/templates/nextblock-template/next-env.d.ts +1 -1
  43. package/templates/nextblock-template/package.json +1 -1
  44. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -16,6 +16,8 @@ import {
16
16
  } from "@nextblock-cms/ui";
17
17
  import { Search, X, Package } from 'lucide-react';
18
18
  import { blockRegistry, BlockType } from '../../../../lib/blocks/blockRegistry';
19
+ import { isEcommerceBlockType } from '../../../../lib/blocks/blockTypes';
20
+ import { useEcommerceActive } from '../../components/EcommerceActiveContext';
19
21
  import BlockTypeCard from './BlockTypeCard';
20
22
 
21
23
  interface BlockTypeSelectorProps {
@@ -25,7 +27,8 @@ interface BlockTypeSelectorProps {
25
27
  allowedBlockTypes?: BlockType[];
26
28
  }
27
29
 
28
- const CATEGORIES = ["All", "Layout", "Content", "Media", "Interactive", "E-commerce", "Custom"];
30
+ const ECOMMERCE_CATEGORY = "E-commerce";
31
+ const CATEGORIES = ["All", "Layout", "Content", "Media", "Interactive", ECOMMERCE_CATEGORY, "Custom"];
29
32
 
30
33
  const getBlockCategory = (type: string, isCustomSlug?: boolean): string => {
31
34
  if (isCustomSlug) {
@@ -50,7 +53,7 @@ const getBlockCategory = (type: string, isCustomSlug?: boolean): string => {
50
53
  case 'cart':
51
54
  case 'checkout':
52
55
  case 'product_details':
53
- return 'E-commerce';
56
+ return ECOMMERCE_CATEGORY;
54
57
  default:
55
58
  return 'Content';
56
59
  }
@@ -65,6 +68,9 @@ const BlockTypeSelector: React.FC<BlockTypeSelectorProps> = ({
65
68
  const [searchQuery, setSearchQuery] = React.useState('');
66
69
  const [activeCategory, setActiveCategory] = React.useState('All');
67
70
  const [customDefs, setCustomDefs] = React.useState<any[]>([]);
71
+ // Store blocks are only offered when the ecommerce package is activated. The
72
+ // context defaults to false outside the CMS layout, so this fails closed.
73
+ const isEcommerceActive = useEcommerceActive();
68
74
 
69
75
  // Reset state and fetch custom blocks when modal is opened
70
76
  React.useEffect(() => {
@@ -93,10 +99,16 @@ const BlockTypeSelector: React.FC<BlockTypeSelectorProps> = ({
93
99
  onOpenChange(false);
94
100
  };
95
101
 
102
+ const visibleCategories = React.useMemo(
103
+ () => CATEGORIES.filter((category) => category !== ECOMMERCE_CATEGORY || isEcommerceActive),
104
+ [isEcommerceActive]
105
+ );
106
+
96
107
  const blockDefs = React.useMemo(() => {
97
108
  const coreDefs = Object.values(blockRegistry).filter(
98
109
  (blockDef) =>
99
- !allowedBlockTypes || allowedBlockTypes.includes(blockDef.type)
110
+ (!allowedBlockTypes || allowedBlockTypes.includes(blockDef.type)) &&
111
+ (isEcommerceActive || !isEcommerceBlockType(blockDef.type))
100
112
  );
101
113
 
102
114
  const mappedCustomDefs = customDefs.map((def) => ({
@@ -114,7 +126,7 @@ const BlockTypeSelector: React.FC<BlockTypeSelectorProps> = ({
114
126
  }));
115
127
 
116
128
  return [...coreDefs, ...mappedCustomDefs];
117
- }, [allowedBlockTypes, customDefs]);
129
+ }, [allowedBlockTypes, customDefs, isEcommerceActive]);
118
130
 
119
131
  // Memoized filter and search results to prevent re-calculations during key strokes
120
132
  const filteredBlockDefs = React.useMemo(() => {
@@ -174,7 +186,7 @@ const BlockTypeSelector: React.FC<BlockTypeSelectorProps> = ({
174
186
 
175
187
  {/* Category Filter Tabs */}
176
188
  <div className="flex flex-wrap gap-1.5 pb-3 border-b border-border">
177
- {CATEGORIES.map((category) => (
189
+ {visibleCategories.map((category) => (
178
190
  <button
179
191
  key={category}
180
192
  type="button"
@@ -0,0 +1,251 @@
1
+ "use client";
2
+
3
+ import React from 'react';
4
+ import { Check, ChevronsUpDown, Loader2, Search, X } from 'lucide-react';
5
+ import {
6
+ Badge,
7
+ Button,
8
+ Checkbox,
9
+ Input,
10
+ Popover,
11
+ PopoverContent,
12
+ PopoverTrigger,
13
+ } from '@nextblock-cms/ui';
14
+ import { cn } from '@nextblock-cms/utils';
15
+
16
+ export interface PickerOption {
17
+ id: string;
18
+ label: string;
19
+ /** Secondary line under the label, e.g. a slug or SKU. */
20
+ description?: string | null;
21
+ /** Small trailing tag, e.g. a language code or publish status. */
22
+ badge?: string | null;
23
+ }
24
+
25
+ interface MultiEntityPickerProps {
26
+ options: PickerOption[];
27
+ /**
28
+ * Labels for already-selected ids that the current `options` page may not
29
+ * contain (server-filtered lists). Used for the chips only, never listed.
30
+ */
31
+ selectedOptions?: PickerOption[];
32
+ selectedIds: string[];
33
+ onChange: (ids: string[]) => void;
34
+ placeholder?: string;
35
+ searchPlaceholder?: string;
36
+ emptyMessage?: string;
37
+ /** Singular / plural noun used in the trigger label, e.g. ['category', 'categories']. */
38
+ nouns: [string, string];
39
+ isLoading?: boolean;
40
+ /**
41
+ * Provide to filter server-side (the component then stops filtering locally).
42
+ * Omit for a fully client-side list.
43
+ */
44
+ onSearchChange?: (query: string) => void;
45
+ /** Number the selected chips — use when selection order is display order. */
46
+ showOrder?: boolean;
47
+ maxSelected?: number;
48
+ /** Extra line under the control, e.g. "Showing the first 50 products". */
49
+ hint?: React.ReactNode;
50
+ }
51
+
52
+ export default function MultiEntityPicker({
53
+ options,
54
+ selectedOptions: selectedOptionsProp,
55
+ selectedIds,
56
+ onChange,
57
+ placeholder = 'Select…',
58
+ searchPlaceholder = 'Search…',
59
+ emptyMessage = 'Nothing found.',
60
+ nouns,
61
+ isLoading = false,
62
+ onSearchChange,
63
+ showOrder = false,
64
+ maxSelected,
65
+ hint,
66
+ }: MultiEntityPickerProps) {
67
+ const [open, setOpen] = React.useState(false);
68
+ const [searchQuery, setSearchQuery] = React.useState('');
69
+ const isServerFiltered = typeof onSearchChange === 'function';
70
+
71
+ const labelsById = React.useMemo(
72
+ () =>
73
+ new Map(
74
+ [...options, ...(selectedOptionsProp ?? [])].map((option) => [option.id, option])
75
+ ),
76
+ [options, selectedOptionsProp]
77
+ );
78
+
79
+ // Selection order is meaningful (it drives display order), so walk selectedIds
80
+ // rather than options. Ids whose option has not loaded yet still get a chip.
81
+ const selectedOptions = React.useMemo(
82
+ () =>
83
+ selectedIds.map(
84
+ (id) => labelsById.get(id) ?? { id, label: 'Loading…', description: null }
85
+ ),
86
+ [selectedIds, labelsById]
87
+ );
88
+
89
+ const filteredOptions = React.useMemo(() => {
90
+ if (isServerFiltered || !searchQuery.trim()) return options;
91
+ const query = searchQuery.trim().toLowerCase();
92
+ return options.filter(
93
+ (option) =>
94
+ option.label.toLowerCase().includes(query) ||
95
+ (option.description ?? '').toLowerCase().includes(query)
96
+ );
97
+ }, [options, searchQuery, isServerFiltered]);
98
+
99
+ const atLimit = typeof maxSelected === 'number' && selectedIds.length >= maxSelected;
100
+
101
+ const handleSearchChange = (value: string) => {
102
+ setSearchQuery(value);
103
+ onSearchChange?.(value);
104
+ };
105
+
106
+ const toggle = (id: string) => {
107
+ if (selectedIds.includes(id)) {
108
+ onChange(selectedIds.filter((selectedId) => selectedId !== id));
109
+ return;
110
+ }
111
+ if (atLimit) return;
112
+ onChange([...selectedIds, id]);
113
+ };
114
+
115
+ const remove = (id: string) => onChange(selectedIds.filter((selectedId) => selectedId !== id));
116
+
117
+ const [singular, plural] = nouns;
118
+ const triggerLabel =
119
+ selectedIds.length > 0
120
+ ? `${selectedIds.length} ${selectedIds.length === 1 ? singular : plural} selected`
121
+ : placeholder;
122
+
123
+ return (
124
+ <div className="space-y-2">
125
+ {selectedOptions.length > 0 && (
126
+ <ul className="flex flex-wrap gap-1.5 rounded-md border bg-muted/30 p-1.5">
127
+ {selectedOptions.map((option, index) => (
128
+ <li key={option.id}>
129
+ <Badge
130
+ variant="secondary"
131
+ className="flex items-center gap-1 rounded-full py-0.5 pl-2 pr-1 text-xs font-normal"
132
+ >
133
+ {showOrder && (
134
+ <span className="text-[10px] font-semibold tabular-nums text-muted-foreground">
135
+ {index + 1}
136
+ </span>
137
+ )}
138
+ <span className="max-w-[180px] truncate">{option.label}</span>
139
+ <button
140
+ type="button"
141
+ onClick={() => remove(option.id)}
142
+ aria-label={`Remove ${option.label}`}
143
+ className="rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive"
144
+ >
145
+ <X className="h-3 w-3" />
146
+ </button>
147
+ </Badge>
148
+ </li>
149
+ ))}
150
+ </ul>
151
+ )}
152
+
153
+ <Popover open={open} onOpenChange={setOpen}>
154
+ <PopoverTrigger asChild>
155
+ <Button
156
+ type="button"
157
+ variant="outline"
158
+ role="combobox"
159
+ aria-expanded={open}
160
+ className="h-9 w-full justify-between text-xs font-normal"
161
+ >
162
+ <span className="truncate">{triggerLabel}</span>
163
+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
164
+ </Button>
165
+ </PopoverTrigger>
166
+ <PopoverContent className="w-[--radix-popover-trigger-width] p-0" align="start">
167
+ <div className="flex items-center border-b px-3">
168
+ {isLoading ? (
169
+ <Loader2 className="mr-2 h-4 w-4 shrink-0 animate-spin opacity-50" />
170
+ ) : (
171
+ <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
172
+ )}
173
+ <Input
174
+ autoFocus
175
+ className="h-9 w-full border-0 bg-transparent py-2 text-xs shadow-none focus-visible:ring-0 focus-visible:ring-offset-0"
176
+ placeholder={searchPlaceholder}
177
+ value={searchQuery}
178
+ onChange={(event) => handleSearchChange(event.target.value)}
179
+ />
180
+ </div>
181
+
182
+ <div className="max-h-60 overflow-y-auto p-1">
183
+ {filteredOptions.length === 0 ? (
184
+ <p className="py-6 text-center text-xs text-muted-foreground">
185
+ {isLoading ? 'Loading…' : emptyMessage}
186
+ </p>
187
+ ) : (
188
+ filteredOptions.map((option) => {
189
+ const isChecked = selectedIds.includes(option.id);
190
+ const isBlocked = !isChecked && atLimit;
191
+ return (
192
+ <button
193
+ key={option.id}
194
+ type="button"
195
+ role="option"
196
+ aria-selected={isChecked}
197
+ disabled={isBlocked}
198
+ onClick={() => toggle(option.id)}
199
+ className={cn(
200
+ 'relative flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs outline-none transition-colors',
201
+ isBlocked
202
+ ? 'cursor-not-allowed opacity-40'
203
+ : 'cursor-pointer hover:bg-accent hover:text-accent-foreground',
204
+ isChecked && 'bg-accent/40'
205
+ )}
206
+ >
207
+ <Checkbox
208
+ checked={isChecked}
209
+ tabIndex={-1}
210
+ aria-hidden="true"
211
+ className="pointer-events-none h-3.5 w-3.5 shrink-0"
212
+ />
213
+ <span className="flex min-w-0 flex-col">
214
+ <span className="truncate font-medium">{option.label}</span>
215
+ {option.description && (
216
+ <span className="truncate font-mono text-[10px] leading-tight text-muted-foreground">
217
+ {option.description}
218
+ </span>
219
+ )}
220
+ </span>
221
+ {option.badge && (
222
+ <Badge
223
+ variant="outline"
224
+ className="ml-auto shrink-0 px-1.5 py-0 text-[9px] uppercase"
225
+ >
226
+ {option.badge}
227
+ </Badge>
228
+ )}
229
+ {isChecked && (
230
+ <Check
231
+ className={cn('h-3.5 w-3.5 shrink-0 text-primary', !option.badge && 'ml-auto')}
232
+ />
233
+ )}
234
+ </button>
235
+ );
236
+ })
237
+ )}
238
+ </div>
239
+
240
+ {atLimit && (
241
+ <p className="border-t px-3 py-2 text-[11px] text-muted-foreground">
242
+ Limit reached ({maxSelected}). Remove one to add another.
243
+ </p>
244
+ )}
245
+ </PopoverContent>
246
+ </Popover>
247
+
248
+ {hint && <p className="text-[11px] leading-snug text-muted-foreground">{hint}</p>}
249
+ </div>
250
+ );
251
+ }