@morphika/andami 0.5.1 → 0.5.3

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 (147) hide show
  1. package/README.md +27 -2
  2. package/app/admin/assets/page.tsx +6 -6
  3. package/app/admin/database/page.tsx +302 -302
  4. package/app/admin/error.tsx +53 -53
  5. package/app/admin/layout.tsx +332 -320
  6. package/app/admin/navigation/page.tsx +255 -255
  7. package/app/admin/pages/[slug]/page.tsx +44 -27
  8. package/app/admin/pages/page.tsx +24 -19
  9. package/app/admin/projects/page.tsx +30 -21
  10. package/app/admin/setup/page.tsx +1 -1
  11. package/app/admin/styles/page.tsx +1 -1
  12. package/app/api/admin/assets/register/route.ts +51 -14
  13. package/app/api/admin/assets/registry/route.ts +4 -1
  14. package/app/api/admin/assets/relink/confirm/route.ts +4 -1
  15. package/app/api/admin/assets/relink/route.ts +4 -1
  16. package/app/api/admin/assets/scan/route.ts +4 -1
  17. package/app/api/admin/backups/restore-data/route.ts +4 -1
  18. package/app/api/admin/r2/connect/route.ts +4 -1
  19. package/app/api/admin/r2/delete/route.ts +4 -1
  20. package/app/api/admin/r2/rename/route.ts +4 -1
  21. package/app/api/admin/r2/upload-url/route.ts +4 -1
  22. package/app/api/admin/revalidate/route.ts +4 -1
  23. package/app/api/admin/storage/switch/route.ts +4 -1
  24. package/app/api/custom-sections/[id]/route.ts +5 -6
  25. package/components/admin/MetadataEditor.tsx +6 -6
  26. package/components/admin/PublishToggle.tsx +2 -2
  27. package/components/admin/nav-builder/NavBuilder.tsx +1 -1
  28. package/components/admin/nav-builder/NavBuilderGrid.tsx +3 -3
  29. package/components/admin/nav-builder/NavGridCell.tsx +48 -48
  30. package/components/admin/nav-builder/NavGridItem.tsx +8 -6
  31. package/components/admin/nav-builder/NavItemSettings.tsx +331 -331
  32. package/components/admin/nav-builder/NavItemTypePicker.tsx +102 -102
  33. package/components/admin/nav-builder/NavLivePreview.tsx +1 -1
  34. package/components/admin/nav-builder/NavMobileLivePreview.tsx +226 -226
  35. package/components/admin/nav-builder/NavMobileSettings.tsx +242 -242
  36. package/components/admin/nav-builder/NavSettingsFields.tsx +518 -514
  37. package/components/admin/setup-wizard/BrandingStep.tsx +3 -3
  38. package/components/admin/setup-wizard/DatabaseStep.tsx +2 -2
  39. package/components/admin/setup-wizard/DoneStep.tsx +1 -1
  40. package/components/admin/setup-wizard/SetupWizard.tsx +4 -4
  41. package/components/admin/setup-wizard/StorageStep.tsx +2 -2
  42. package/components/admin/setup-wizard/WelcomeStep.tsx +2 -2
  43. package/components/admin/styles/ColorsEditor.tsx +9 -8
  44. package/components/admin/styles/FontsEditor.tsx +9 -7
  45. package/components/admin/styles/GridLayoutEditor.tsx +9 -9
  46. package/components/admin/styles/LinksButtonsEditor.tsx +5 -5
  47. package/components/admin/styles/TypographyEditor.tsx +6 -6
  48. package/components/admin/styles/shared.tsx +68 -68
  49. package/components/blocks/AudioBlockRenderer.tsx +286 -286
  50. package/components/blocks/CoverSectionRenderer.tsx +7 -1
  51. package/components/blocks/MarqueeBlockRenderer.tsx +316 -0
  52. package/components/blocks/ProjectCarouselBlockRenderer.tsx +1 -1
  53. package/components/blocks/SectionV2Renderer.tsx +8 -1
  54. package/components/builder/BlockCardIcons.tsx +316 -316
  55. package/components/builder/BlockTypePicker.tsx +1 -1
  56. package/components/builder/BubbleIcons.tsx +104 -0
  57. package/components/builder/BuilderCanvas.tsx +2 -0
  58. package/components/builder/CanvasMinimap.tsx +66 -49
  59. package/components/builder/CanvasToolbar.tsx +31 -41
  60. package/components/builder/CoverSectionCanvas.tsx +363 -363
  61. package/components/builder/DeviceFrame.tsx +1 -1
  62. package/components/builder/DndWrapper.tsx +3 -3
  63. package/components/builder/InsertionLines.tsx +1 -1
  64. package/components/builder/SectionCardIcons.tsx +421 -320
  65. package/components/builder/SectionEditorBar.tsx +5 -3
  66. package/components/builder/SectionTypePicker.tsx +7 -5
  67. package/components/builder/SectionV2Canvas.tsx +1 -1
  68. package/components/builder/SectionV2Column.tsx +82 -68
  69. package/components/builder/SettingsPanel.tsx +21 -17
  70. package/components/builder/SortableBlock.tsx +93 -73
  71. package/components/builder/SortableRow.tsx +33 -35
  72. package/components/builder/VirtualAssetGrid.tsx +10 -4
  73. package/components/builder/asset-browser/R2BrowserContent.tsx +18 -14
  74. package/components/builder/blockStyles.tsx +192 -185
  75. package/components/builder/color-picker/AlphaSlider.tsx +141 -141
  76. package/components/builder/color-picker/ColorInputs.tsx +105 -105
  77. package/components/builder/color-picker/EyedropperButton.tsx +75 -74
  78. package/components/builder/color-picker/HueSlider.tsx +124 -124
  79. package/components/builder/color-picker/SaturationCanvas.tsx +142 -142
  80. package/components/builder/color-picker/SwatchBar.tsx +98 -93
  81. package/components/builder/color-picker/UnifiedColorPicker.tsx +11 -6
  82. package/components/builder/editors/AudioBlockEditor.tsx +242 -242
  83. package/components/builder/editors/BeforeAfterBlockEditor.tsx +360 -360
  84. package/components/builder/editors/ButtonBlockEditor.tsx +4 -4
  85. package/components/builder/editors/EnterAnimationPicker.tsx +2 -2
  86. package/components/builder/editors/HoverEffectPicker.tsx +2 -2
  87. package/components/builder/editors/ImageBlockEditor.tsx +2 -2
  88. package/components/builder/editors/ImageGridBlockEditor.tsx +8 -6
  89. package/components/builder/editors/MarqueeBlockEditor.tsx +622 -0
  90. package/components/builder/editors/ProjectCarouselBlockEditor.tsx +443 -443
  91. package/components/builder/editors/ProjectGridEditor.tsx +21 -16
  92. package/components/builder/editors/SpacerBlockEditor.tsx +29 -27
  93. package/components/builder/editors/StaggerSettings.tsx +109 -109
  94. package/components/builder/editors/TextBlockEditor.tsx +22 -17
  95. package/components/builder/editors/TextStylePicker.tsx +1 -1
  96. package/components/builder/editors/VideoBlockEditor.tsx +2 -2
  97. package/components/builder/editors/index.ts +11 -10
  98. package/components/builder/editors/shared.tsx +10 -8
  99. package/components/builder/live-preview/LiveAudioPreview.tsx +120 -120
  100. package/components/builder/live-preview/LiveBeforeAfterPreview.tsx +1 -1
  101. package/components/builder/live-preview/LiveImageGridPreview.tsx +10 -2
  102. package/components/builder/live-preview/LiveImagePreview.tsx +4 -2
  103. package/components/builder/live-preview/LiveMarqueePreview.tsx +39 -0
  104. package/components/builder/live-preview/LiveProjectCarouselPreview.tsx +1 -1
  105. package/components/builder/live-preview/LiveVideoPreview.tsx +1 -1
  106. package/components/builder/live-preview/ProjectCardWrapper.tsx +293 -291
  107. package/components/builder/live-preview/RichTextBubbleMenu.tsx +10 -6
  108. package/components/builder/live-preview/shared.tsx +5 -2
  109. package/components/builder/settings-panel/AnimationTab.tsx +138 -138
  110. package/components/builder/settings-panel/BlockLayoutTab.tsx +11 -9
  111. package/components/builder/settings-panel/CardEntranceSection.tsx +114 -114
  112. package/components/builder/settings-panel/ColumnV2LayoutTab.tsx +242 -0
  113. package/components/builder/settings-panel/ColumnV2Settings.tsx +5 -5
  114. package/components/builder/settings-panel/CoverSectionLayoutTab.tsx +71 -71
  115. package/components/builder/settings-panel/CoverSectionSettings.tsx +337 -335
  116. package/components/builder/settings-panel/PageSettings.tsx +3 -3
  117. package/components/builder/settings-panel/ParallaxSlideSettings.tsx +2 -2
  118. package/components/builder/settings-panel/SectionV2AnimationTab.tsx +4 -4
  119. package/components/builder/settings-panel/SectionV2LayoutTab.tsx +356 -356
  120. package/components/builder/settings-panel/SectionV2Settings.tsx +25 -20
  121. package/components/builder/settings-panel/TRBLInputs.tsx +1 -1
  122. package/components/builder/settings-panel/index.ts +1 -0
  123. package/lib/animation/enter-types.ts +1 -0
  124. package/lib/animation/hover-effect-presets.ts +210 -210
  125. package/lib/animation/hover-effect-types.ts +1 -0
  126. package/lib/builder/block-registrations.ts +468 -417
  127. package/lib/builder/constants.ts +111 -111
  128. package/lib/builder/serializer/normalizers.ts +14 -0
  129. package/lib/builder/serializer/serializers.ts +27 -0
  130. package/lib/builder/store-sections.ts +23 -2
  131. package/lib/builder/types-slices.ts +428 -414
  132. package/lib/builder/types.ts +4 -1
  133. package/lib/config/index.ts +27 -27
  134. package/lib/sanity/queries.ts +48 -0
  135. package/lib/sanity/types.ts +112 -1
  136. package/lib/version.ts +1 -1
  137. package/package.json +7 -5
  138. package/sanity/schemas/blocks/audioBlock.ts +69 -69
  139. package/sanity/schemas/blocks/index.ts +12 -11
  140. package/sanity/schemas/blocks/marqueeBlock.ts +292 -0
  141. package/sanity/schemas/index.ts +120 -117
  142. package/sanity/schemas/objects/coverSection.ts +32 -0
  143. package/sanity/schemas/objects/parallaxSlide.ts +32 -0
  144. package/sanity/schemas/pageSectionV2.ts +32 -0
  145. package/styles/admin.css +85 -85
  146. package/styles/animations.css +237 -237
  147. package/styles/base.css +114 -114
@@ -1,356 +1,356 @@
1
- "use client";
2
-
3
- /**
4
- * SectionV2LayoutTab — Layout tab content for V2 grid sections.
5
- *
6
- * Extracted from SectionV2Settings.tsx in Session 95.
7
- * Session 158: Redesigned to match BlockLayoutTab style —
8
- * section title icons, TRBLInputs for spacing/offset,
9
- * AssetPathInput for background image, SELECT_CLASS for selects.
10
- * No Alignment section (that's for blocks only).
11
- *
12
- * Controls: spacing (TRBL padding), background (color/opacity/image),
13
- * offset (TRBL margins), and border properties.
14
- */
15
-
16
- import { useBuilderStore } from "../../../lib/builder/store";
17
- import type { PageSectionV2, SectionV2Settings as SectionV2SettingsType } from "../../../lib/sanity/types";
18
- import {
19
- SettingsField,
20
- SettingsSection,
21
- SELECT_CLASS,
22
- AssetPathInput,
23
- } from "../editors/shared";
24
- import ColorSwatchPicker, { usePaletteSwatches } from "../ColorSwatchPicker";
25
- import { serializeColorField, parseColorField, isGradient } from "../../../lib/color-utils";
26
- import { TRBLInputs } from "./TRBLInputs";
27
-
28
- // ── Section title icons (centralized colored icons — Session 163) ──
29
- import {
30
- SpacingIcon,
31
- OffsetIcon,
32
- BackgroundIcon,
33
- BorderIcon,
34
- } from "../editors/section-icons";
35
-
36
- // ── Override indicator badge (matching BlockLayoutTab pattern) ──
37
-
38
- function SectionOverrideBadge({
39
- hasAny,
40
- onReset,
41
- viewport,
42
- }: {
43
- hasAny: boolean;
44
- onReset: () => void;
45
- viewport: string;
46
- }) {
47
- if (viewport === "desktop") return null;
48
- if (hasAny) {
49
- return (
50
- <div className="flex items-center gap-2 mt-1">
51
- <span className="text-[9px] text-[#076bff]">overridden</span>
52
- <button
53
- onClick={onReset}
54
- className="text-[10px] text-neutral-400 hover:text-[var(--admin-error)] transition-colors"
55
- >
56
- Reset
57
- </button>
58
- </div>
59
- );
60
- }
61
- return <p className="text-[9px] text-neutral-300 italic mt-1">inherited</p>;
62
- }
63
-
64
- export function SectionV2LayoutTab({ section }: { section: PageSectionV2 }) {
65
- const store = useBuilderStore();
66
- const paletteSwatches = usePaletteSwatches();
67
- const settings = section.settings;
68
- const activeViewport = store.activeViewport;
69
-
70
- // Live preview callbacks (Phase 4)
71
- const handleBgPreview = (val: import("../../../lib/sanity/types").ColorField) => {
72
- store.setColorPickerPreview({ sectionKey: section._key, field: "background_color", value: val });
73
- };
74
- const handleBorderPreview = (val: import("../../../lib/sanity/types").ColorField) => {
75
- store.setColorPickerPreview({ sectionKey: section._key, field: "border_color", value: val });
76
- };
77
-
78
- const viewportLabel = activeViewport !== "desktop"
79
- ? activeViewport === "tablet" ? "Tablet" : "Phone"
80
- : null;
81
-
82
- /**
83
- * Update setting with viewport awareness.
84
- * Desktop writes directly to settings; tablet/phone writes to responsive overrides.
85
- */
86
- const updateSettingResponsive = (property: string, value: unknown) => {
87
- if (activeViewport === "desktop") {
88
- store.updateSectionV2Settings(section._key, { [property]: value } as Partial<SectionV2SettingsType>);
89
- } else {
90
- const existing = section.responsive || {};
91
- const vp = activeViewport as "tablet" | "phone";
92
- const vpSettings = { ...(existing[vp]?.settings || {}), [property]: value };
93
- if (value === undefined) delete (vpSettings as Record<string, unknown>)[property];
94
- const vpOverride = { ...(existing[vp] || {}), settings: Object.keys(vpSettings).length ? vpSettings : undefined };
95
- const responsive = { ...existing, [vp]: vpOverride };
96
- // Clean up empty viewport override
97
- if (!vpOverride.columns?.length && !vpOverride.settings) delete responsive[vp];
98
- store.updateSectionV2Responsive(section._key, Object.keys(responsive).length ? responsive : undefined);
99
- }
100
- };
101
-
102
- /** Read a setting value respecting viewport overrides */
103
- const getSettingValue = <T,>(property: string, fallback: T): T => {
104
- if (activeViewport !== "desktop") {
105
- const vp = activeViewport as "tablet" | "phone";
106
- const vpSettings = section.responsive?.[vp]?.settings as Record<string, unknown> | undefined;
107
- const override = vpSettings?.[property];
108
- if (override !== undefined) return override as T;
109
- }
110
- const val = (settings as unknown as Record<string, unknown>)[property];
111
- return (val !== undefined ? val : fallback) as T;
112
- };
113
-
114
- const hasOverride = (property: string): boolean => {
115
- if (activeViewport === "desktop") return false;
116
- const vp = activeViewport as "tablet" | "phone";
117
- const vpSettings = section.responsive?.[vp]?.settings as Record<string, unknown> | undefined;
118
- return vpSettings?.[property] !== undefined;
119
- };
120
-
121
- const hasAnyOverrideInGroup = (properties: string[]): boolean => {
122
- return properties.some((p) => hasOverride(p));
123
- };
124
-
125
- const resetGroup = (properties: string[]) => {
126
- for (const prop of properties) {
127
- updateSettingResponsive(prop, undefined);
128
- }
129
- };
130
-
131
- const bgIsGradient = isGradient(parseColorField(getSettingValue<string>("background_color", "")));
132
-
133
- return (
134
- <>
135
- {viewportLabel && (
136
- <div className="px-4 pt-3">
137
- <div className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#076bff]/8 border border-[#076bff]/15">
138
- <span className="text-[11px] font-medium text-[#076bff]">
139
- Editing {viewportLabel} overrides
140
- </span>
141
- </div>
142
- </div>
143
- )}
144
-
145
- {/* Spacing (Padding) */}
146
- <SettingsSection title="Spacing" defaultOpen icon={<SpacingIcon />}>
147
- <TRBLInputs
148
- top={getSettingValue<string>("spacing_top", "0")}
149
- right={getSettingValue<string>("spacing_right", "0")}
150
- bottom={getSettingValue<string>("spacing_bottom", "0")}
151
- left={getSettingValue<string>("spacing_left", "0")}
152
- onChange={(field, value) => {
153
- updateSettingResponsive(`spacing_${field}`, value);
154
- }}
155
- />
156
- <SectionOverrideBadge
157
- hasAny={hasAnyOverrideInGroup(["spacing_top", "spacing_right", "spacing_bottom", "spacing_left"])}
158
- onReset={() => resetGroup(["spacing_top", "spacing_right", "spacing_bottom", "spacing_left"])}
159
- viewport={activeViewport}
160
- />
161
- </SettingsSection>
162
-
163
- {/* Offset (Margin) */}
164
- <SettingsSection title="Offset" icon={<OffsetIcon />}>
165
- <TRBLInputs
166
- top={getSettingValue<string>("offset_top", "0")}
167
- right={getSettingValue<string>("offset_right", "0")}
168
- bottom={getSettingValue<string>("offset_bottom", "0")}
169
- left={getSettingValue<string>("offset_left", "0")}
170
- onChange={(field, value) => {
171
- updateSettingResponsive(`offset_${field}`, value);
172
- }}
173
- />
174
- <SectionOverrideBadge
175
- hasAny={hasAnyOverrideInGroup(["offset_top", "offset_right", "offset_bottom", "offset_left"])}
176
- onReset={() => resetGroup(["offset_top", "offset_right", "offset_bottom", "offset_left"])}
177
- viewport={activeViewport}
178
- />
179
- </SettingsSection>
180
-
181
- {/* Background */}
182
- <SettingsSection title="Background" defaultOpen icon={<BackgroundIcon />}>
183
- <SettingsField label="Color">
184
- <ColorSwatchPicker
185
- value={parseColorField(getSettingValue<string>("background_color", ""))}
186
- onChange={(val) => { store.clearColorPickerPreview(); updateSettingResponsive("background_color", serializeColorField(val)); }}
187
- swatches={paletteSwatches}
188
- allowGradients
189
- onPreview={handleBgPreview}
190
- />
191
- </SettingsField>
192
-
193
- <SettingsField label="Opacity">
194
- <div className="flex items-center gap-2">
195
- <input
196
- type="range"
197
- min={0}
198
- max={100}
199
- value={getSettingValue<number>("background_opacity", 100)}
200
- onChange={(e) => updateSettingResponsive("background_opacity", parseInt(e.target.value))}
201
- className={`flex-1 accent-[#076bff] ${bgIsGradient ? "opacity-40 pointer-events-none" : ""}`}
202
- disabled={bgIsGradient}
203
- />
204
- <span className="text-xs text-neutral-900 w-10 text-right">
205
- {getSettingValue<number>("background_opacity", 100)}%
206
- </span>
207
- </div>
208
- {bgIsGradient && (
209
- <p className="text-[9px] text-neutral-400 italic mt-1">
210
- Opacity is controlled per stop in gradient mode
211
- </p>
212
- )}
213
- </SettingsField>
214
-
215
- <SettingsField label="Image">
216
- <AssetPathInput
217
- value={getSettingValue<string>("background_image", "")}
218
- onFocus={() => store._pushSnapshot()}
219
- onChange={(v) => updateSettingResponsive("background_image", v)}
220
- placeholder="path/to/image.jpg"
221
- filterType="image"
222
- />
223
- </SettingsField>
224
-
225
- {getSettingValue<string>("background_image", "") && (
226
- <>
227
- <SettingsField label="Size">
228
- <select
229
- value={getSettingValue<string>("background_size", "cover")}
230
- onChange={(e) => updateSettingResponsive("background_size", e.target.value)}
231
- className={SELECT_CLASS}
232
- >
233
- <option value="cover">Cover</option>
234
- <option value="contain">Contain</option>
235
- <option value="auto">Auto</option>
236
- </select>
237
- </SettingsField>
238
-
239
- <SettingsField label="Position">
240
- <select
241
- value={getSettingValue<string>("background_position", "center center")}
242
- onChange={(e) => updateSettingResponsive("background_position", e.target.value)}
243
- className={SELECT_CLASS}
244
- >
245
- <option value="center center">Center</option>
246
- <option value="top center">Top</option>
247
- <option value="bottom center">Bottom</option>
248
- <option value="left center">Left</option>
249
- <option value="right center">Right</option>
250
- </select>
251
- </SettingsField>
252
-
253
- <SettingsField label="Repeat">
254
- <select
255
- value={getSettingValue<string>("background_repeat", "no-repeat")}
256
- onChange={(e) => updateSettingResponsive("background_repeat", e.target.value)}
257
- className={SELECT_CLASS}
258
- >
259
- <option value="no-repeat">No Repeat</option>
260
- <option value="repeat">Repeat</option>
261
- <option value="repeat-x">Repeat X</option>
262
- <option value="repeat-y">Repeat Y</option>
263
- </select>
264
- </SettingsField>
265
- </>
266
- )}
267
-
268
- <SectionOverrideBadge
269
- hasAny={hasAnyOverrideInGroup(["background_color", "background_opacity", "background_image", "background_size", "background_position", "background_repeat"])}
270
- onReset={() => resetGroup(["background_color", "background_opacity", "background_image", "background_size", "background_position", "background_repeat"])}
271
- viewport={activeViewport}
272
- />
273
- </SettingsSection>
274
-
275
- {/* Border */}
276
- <SettingsSection title="Border" icon={<BorderIcon />}>
277
- <SettingsField label="Color">
278
- <ColorSwatchPicker
279
- value={parseColorField(getSettingValue<string>("border_color", ""))}
280
- onChange={(val) => { store.clearColorPickerPreview(); updateSettingResponsive("border_color", serializeColorField(val)); }}
281
- swatches={paletteSwatches}
282
- allowGradients
283
- onPreview={handleBorderPreview}
284
- />
285
- </SettingsField>
286
-
287
- <SettingsField label="Width">
288
- <div className="flex items-center gap-2">
289
- <input
290
- type="range"
291
- min={0}
292
- max={20}
293
- value={parseInt(getSettingValue<string>("border_width", "0"))}
294
- onChange={(e) => updateSettingResponsive("border_width", e.target.value)}
295
- className="flex-1 accent-[#076bff]"
296
- />
297
- <span className="text-xs text-neutral-900 w-10 text-right">
298
- {getSettingValue<string>("border_width", "0")}px
299
- </span>
300
- </div>
301
- </SettingsField>
302
-
303
- <SettingsField label="Style">
304
- <select
305
- value={getSettingValue<string>("border_style", "none")}
306
- onChange={(e) => updateSettingResponsive("border_style", e.target.value)}
307
- className={SELECT_CLASS}
308
- >
309
- <option value="none">None</option>
310
- <option value="solid">Solid</option>
311
- <option value="dashed">Dashed</option>
312
- <option value="dotted">Dotted</option>
313
- </select>
314
- </SettingsField>
315
-
316
- <SettingsField label="Sides">
317
- <select
318
- value={getSettingValue<string>("border_sides", "all")}
319
- onChange={(e) => updateSettingResponsive("border_sides", e.target.value)}
320
- className={SELECT_CLASS}
321
- >
322
- <option value="all">All</option>
323
- <option value="top">Top</option>
324
- <option value="right">Right</option>
325
- <option value="bottom">Bottom</option>
326
- <option value="left">Left</option>
327
- <option value="top-bottom">Top & Bottom</option>
328
- <option value="left-right">Left & Right</option>
329
- </select>
330
- </SettingsField>
331
-
332
- <SettingsField label="Radius">
333
- <div className="flex items-center gap-2">
334
- <input
335
- type="range"
336
- min={0}
337
- max={50}
338
- value={parseInt(getSettingValue<string>("border_radius", "0"))}
339
- onChange={(e) => updateSettingResponsive("border_radius", e.target.value)}
340
- className="flex-1 accent-[#076bff]"
341
- />
342
- <span className="text-xs text-neutral-900 w-10 text-right">
343
- {getSettingValue<string>("border_radius", "0")}px
344
- </span>
345
- </div>
346
- </SettingsField>
347
-
348
- <SectionOverrideBadge
349
- hasAny={hasAnyOverrideInGroup(["border_color", "border_width", "border_style", "border_sides", "border_radius"])}
350
- onReset={() => resetGroup(["border_color", "border_width", "border_style", "border_sides", "border_radius"])}
351
- viewport={activeViewport}
352
- />
353
- </SettingsSection>
354
- </>
355
- );
356
- }
1
+ "use client";
2
+
3
+ /**
4
+ * SectionV2LayoutTab — Layout tab content for V2 grid sections.
5
+ *
6
+ * Extracted from SectionV2Settings.tsx in Session 95.
7
+ * Session 158: Redesigned to match BlockLayoutTab style —
8
+ * section title icons, TRBLInputs for spacing/offset,
9
+ * AssetPathInput for background image, SELECT_CLASS for selects.
10
+ * No Alignment section (that's for blocks only).
11
+ *
12
+ * Controls: spacing (TRBL padding), background (color/opacity/image),
13
+ * offset (TRBL margins), and border properties.
14
+ */
15
+
16
+ import { useBuilderStore } from "../../../lib/builder/store";
17
+ import type { PageSectionV2, SectionV2Settings as SectionV2SettingsType } from "../../../lib/sanity/types";
18
+ import {
19
+ SettingsField,
20
+ SettingsSection,
21
+ SELECT_CLASS,
22
+ AssetPathInput,
23
+ } from "../editors/shared";
24
+ import ColorSwatchPicker, { usePaletteSwatches } from "../ColorSwatchPicker";
25
+ import { serializeColorField, parseColorField, isGradient } from "../../../lib/color-utils";
26
+ import { TRBLInputs } from "./TRBLInputs";
27
+
28
+ // ── Section title icons (centralized colored icons — Session 163) ──
29
+ import {
30
+ SpacingIcon,
31
+ OffsetIcon,
32
+ BackgroundIcon,
33
+ BorderIcon,
34
+ } from "../editors/section-icons";
35
+
36
+ // ── Override indicator badge (matching BlockLayoutTab pattern) ──
37
+
38
+ function SectionOverrideBadge({
39
+ hasAny,
40
+ onReset,
41
+ viewport,
42
+ }: {
43
+ hasAny: boolean;
44
+ onReset: () => void;
45
+ viewport: string;
46
+ }) {
47
+ if (viewport === "desktop") return null;
48
+ if (hasAny) {
49
+ return (
50
+ <div className="flex items-center gap-2 mt-1">
51
+ <span className="text-[9px] text-[#3580f9]">overridden</span>
52
+ <button
53
+ onClick={onReset}
54
+ className="text-[10px] text-neutral-400 hover:text-[var(--admin-error)] transition-colors"
55
+ >
56
+ Reset
57
+ </button>
58
+ </div>
59
+ );
60
+ }
61
+ return <p className="text-[9px] text-neutral-300 italic mt-1">inherited</p>;
62
+ }
63
+
64
+ export function SectionV2LayoutTab({ section }: { section: PageSectionV2 }) {
65
+ const store = useBuilderStore();
66
+ const paletteSwatches = usePaletteSwatches();
67
+ const settings = section.settings;
68
+ const activeViewport = store.activeViewport;
69
+
70
+ // Live preview callbacks (Phase 4)
71
+ const handleBgPreview = (val: import("../../../lib/sanity/types").ColorField) => {
72
+ store.setColorPickerPreview({ sectionKey: section._key, field: "background_color", value: val });
73
+ };
74
+ const handleBorderPreview = (val: import("../../../lib/sanity/types").ColorField) => {
75
+ store.setColorPickerPreview({ sectionKey: section._key, field: "border_color", value: val });
76
+ };
77
+
78
+ const viewportLabel = activeViewport !== "desktop"
79
+ ? activeViewport === "tablet" ? "Tablet" : "Phone"
80
+ : null;
81
+
82
+ /**
83
+ * Update setting with viewport awareness.
84
+ * Desktop writes directly to settings; tablet/phone writes to responsive overrides.
85
+ */
86
+ const updateSettingResponsive = (property: string, value: unknown) => {
87
+ if (activeViewport === "desktop") {
88
+ store.updateSectionV2Settings(section._key, { [property]: value } as Partial<SectionV2SettingsType>);
89
+ } else {
90
+ const existing = section.responsive || {};
91
+ const vp = activeViewport as "tablet" | "phone";
92
+ const vpSettings = { ...(existing[vp]?.settings || {}), [property]: value };
93
+ if (value === undefined) delete (vpSettings as Record<string, unknown>)[property];
94
+ const vpOverride = { ...(existing[vp] || {}), settings: Object.keys(vpSettings).length ? vpSettings : undefined };
95
+ const responsive = { ...existing, [vp]: vpOverride };
96
+ // Clean up empty viewport override
97
+ if (!vpOverride.columns?.length && !vpOverride.settings) delete responsive[vp];
98
+ store.updateSectionV2Responsive(section._key, Object.keys(responsive).length ? responsive : undefined);
99
+ }
100
+ };
101
+
102
+ /** Read a setting value respecting viewport overrides */
103
+ const getSettingValue = <T,>(property: string, fallback: T): T => {
104
+ if (activeViewport !== "desktop") {
105
+ const vp = activeViewport as "tablet" | "phone";
106
+ const vpSettings = section.responsive?.[vp]?.settings as Record<string, unknown> | undefined;
107
+ const override = vpSettings?.[property];
108
+ if (override !== undefined) return override as T;
109
+ }
110
+ const val = (settings as unknown as Record<string, unknown>)[property];
111
+ return (val !== undefined ? val : fallback) as T;
112
+ };
113
+
114
+ const hasOverride = (property: string): boolean => {
115
+ if (activeViewport === "desktop") return false;
116
+ const vp = activeViewport as "tablet" | "phone";
117
+ const vpSettings = section.responsive?.[vp]?.settings as Record<string, unknown> | undefined;
118
+ return vpSettings?.[property] !== undefined;
119
+ };
120
+
121
+ const hasAnyOverrideInGroup = (properties: string[]): boolean => {
122
+ return properties.some((p) => hasOverride(p));
123
+ };
124
+
125
+ const resetGroup = (properties: string[]) => {
126
+ for (const prop of properties) {
127
+ updateSettingResponsive(prop, undefined);
128
+ }
129
+ };
130
+
131
+ const bgIsGradient = isGradient(parseColorField(getSettingValue<string>("background_color", "")));
132
+
133
+ return (
134
+ <>
135
+ {viewportLabel && (
136
+ <div className="px-4 pt-3">
137
+ <div className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#3580f9]/8 border border-[#3580f9]/15">
138
+ <span className="text-[11px] font-medium text-[#3580f9]">
139
+ Editing {viewportLabel} overrides
140
+ </span>
141
+ </div>
142
+ </div>
143
+ )}
144
+
145
+ {/* Spacing (Padding) */}
146
+ <SettingsSection title="Spacing" defaultOpen icon={<SpacingIcon />}>
147
+ <TRBLInputs
148
+ top={getSettingValue<string>("spacing_top", "0")}
149
+ right={getSettingValue<string>("spacing_right", "0")}
150
+ bottom={getSettingValue<string>("spacing_bottom", "0")}
151
+ left={getSettingValue<string>("spacing_left", "0")}
152
+ onChange={(field, value) => {
153
+ updateSettingResponsive(`spacing_${field}`, value);
154
+ }}
155
+ />
156
+ <SectionOverrideBadge
157
+ hasAny={hasAnyOverrideInGroup(["spacing_top", "spacing_right", "spacing_bottom", "spacing_left"])}
158
+ onReset={() => resetGroup(["spacing_top", "spacing_right", "spacing_bottom", "spacing_left"])}
159
+ viewport={activeViewport}
160
+ />
161
+ </SettingsSection>
162
+
163
+ {/* Offset (Margin) */}
164
+ <SettingsSection title="Offset" icon={<OffsetIcon />}>
165
+ <TRBLInputs
166
+ top={getSettingValue<string>("offset_top", "0")}
167
+ right={getSettingValue<string>("offset_right", "0")}
168
+ bottom={getSettingValue<string>("offset_bottom", "0")}
169
+ left={getSettingValue<string>("offset_left", "0")}
170
+ onChange={(field, value) => {
171
+ updateSettingResponsive(`offset_${field}`, value);
172
+ }}
173
+ />
174
+ <SectionOverrideBadge
175
+ hasAny={hasAnyOverrideInGroup(["offset_top", "offset_right", "offset_bottom", "offset_left"])}
176
+ onReset={() => resetGroup(["offset_top", "offset_right", "offset_bottom", "offset_left"])}
177
+ viewport={activeViewport}
178
+ />
179
+ </SettingsSection>
180
+
181
+ {/* Background */}
182
+ <SettingsSection title="Background" defaultOpen icon={<BackgroundIcon />}>
183
+ <SettingsField label="Color">
184
+ <ColorSwatchPicker
185
+ value={parseColorField(getSettingValue<string>("background_color", ""))}
186
+ onChange={(val) => { store.clearColorPickerPreview(); updateSettingResponsive("background_color", serializeColorField(val)); }}
187
+ swatches={paletteSwatches}
188
+ allowGradients
189
+ onPreview={handleBgPreview}
190
+ />
191
+ </SettingsField>
192
+
193
+ <SettingsField label="Opacity">
194
+ <div className="flex items-center gap-2">
195
+ <input
196
+ type="range"
197
+ min={0}
198
+ max={100}
199
+ value={getSettingValue<number>("background_opacity", 100)}
200
+ onChange={(e) => updateSettingResponsive("background_opacity", parseInt(e.target.value))}
201
+ className={`flex-1 accent-[#3580f9] ${bgIsGradient ? "opacity-40 pointer-events-none" : ""}`}
202
+ disabled={bgIsGradient}
203
+ />
204
+ <span className="text-xs text-neutral-900 w-10 text-right">
205
+ {getSettingValue<number>("background_opacity", 100)}%
206
+ </span>
207
+ </div>
208
+ {bgIsGradient && (
209
+ <p className="text-[9px] text-neutral-400 italic mt-1">
210
+ Opacity is controlled per stop in gradient mode
211
+ </p>
212
+ )}
213
+ </SettingsField>
214
+
215
+ <SettingsField label="Image">
216
+ <AssetPathInput
217
+ value={getSettingValue<string>("background_image", "")}
218
+ onFocus={() => store._pushSnapshot()}
219
+ onChange={(v) => updateSettingResponsive("background_image", v)}
220
+ placeholder="path/to/image.jpg"
221
+ filterType="image"
222
+ />
223
+ </SettingsField>
224
+
225
+ {getSettingValue<string>("background_image", "") && (
226
+ <>
227
+ <SettingsField label="Size">
228
+ <select
229
+ value={getSettingValue<string>("background_size", "cover")}
230
+ onChange={(e) => updateSettingResponsive("background_size", e.target.value)}
231
+ className={SELECT_CLASS}
232
+ >
233
+ <option value="cover">Cover</option>
234
+ <option value="contain">Contain</option>
235
+ <option value="auto">Auto</option>
236
+ </select>
237
+ </SettingsField>
238
+
239
+ <SettingsField label="Position">
240
+ <select
241
+ value={getSettingValue<string>("background_position", "center center")}
242
+ onChange={(e) => updateSettingResponsive("background_position", e.target.value)}
243
+ className={SELECT_CLASS}
244
+ >
245
+ <option value="center center">Center</option>
246
+ <option value="top center">Top</option>
247
+ <option value="bottom center">Bottom</option>
248
+ <option value="left center">Left</option>
249
+ <option value="right center">Right</option>
250
+ </select>
251
+ </SettingsField>
252
+
253
+ <SettingsField label="Repeat">
254
+ <select
255
+ value={getSettingValue<string>("background_repeat", "no-repeat")}
256
+ onChange={(e) => updateSettingResponsive("background_repeat", e.target.value)}
257
+ className={SELECT_CLASS}
258
+ >
259
+ <option value="no-repeat">No Repeat</option>
260
+ <option value="repeat">Repeat</option>
261
+ <option value="repeat-x">Repeat X</option>
262
+ <option value="repeat-y">Repeat Y</option>
263
+ </select>
264
+ </SettingsField>
265
+ </>
266
+ )}
267
+
268
+ <SectionOverrideBadge
269
+ hasAny={hasAnyOverrideInGroup(["background_color", "background_opacity", "background_image", "background_size", "background_position", "background_repeat"])}
270
+ onReset={() => resetGroup(["background_color", "background_opacity", "background_image", "background_size", "background_position", "background_repeat"])}
271
+ viewport={activeViewport}
272
+ />
273
+ </SettingsSection>
274
+
275
+ {/* Border */}
276
+ <SettingsSection title="Border" icon={<BorderIcon />}>
277
+ <SettingsField label="Color">
278
+ <ColorSwatchPicker
279
+ value={parseColorField(getSettingValue<string>("border_color", ""))}
280
+ onChange={(val) => { store.clearColorPickerPreview(); updateSettingResponsive("border_color", serializeColorField(val)); }}
281
+ swatches={paletteSwatches}
282
+ allowGradients
283
+ onPreview={handleBorderPreview}
284
+ />
285
+ </SettingsField>
286
+
287
+ <SettingsField label="Width">
288
+ <div className="flex items-center gap-2">
289
+ <input
290
+ type="range"
291
+ min={0}
292
+ max={20}
293
+ value={parseInt(getSettingValue<string>("border_width", "0"))}
294
+ onChange={(e) => updateSettingResponsive("border_width", e.target.value)}
295
+ className="flex-1 accent-[#3580f9]"
296
+ />
297
+ <span className="text-xs text-neutral-900 w-10 text-right">
298
+ {getSettingValue<string>("border_width", "0")}px
299
+ </span>
300
+ </div>
301
+ </SettingsField>
302
+
303
+ <SettingsField label="Style">
304
+ <select
305
+ value={getSettingValue<string>("border_style", "none")}
306
+ onChange={(e) => updateSettingResponsive("border_style", e.target.value)}
307
+ className={SELECT_CLASS}
308
+ >
309
+ <option value="none">None</option>
310
+ <option value="solid">Solid</option>
311
+ <option value="dashed">Dashed</option>
312
+ <option value="dotted">Dotted</option>
313
+ </select>
314
+ </SettingsField>
315
+
316
+ <SettingsField label="Sides">
317
+ <select
318
+ value={getSettingValue<string>("border_sides", "all")}
319
+ onChange={(e) => updateSettingResponsive("border_sides", e.target.value)}
320
+ className={SELECT_CLASS}
321
+ >
322
+ <option value="all">All</option>
323
+ <option value="top">Top</option>
324
+ <option value="right">Right</option>
325
+ <option value="bottom">Bottom</option>
326
+ <option value="left">Left</option>
327
+ <option value="top-bottom">Top & Bottom</option>
328
+ <option value="left-right">Left & Right</option>
329
+ </select>
330
+ </SettingsField>
331
+
332
+ <SettingsField label="Radius">
333
+ <div className="flex items-center gap-2">
334
+ <input
335
+ type="range"
336
+ min={0}
337
+ max={50}
338
+ value={parseInt(getSettingValue<string>("border_radius", "0"))}
339
+ onChange={(e) => updateSettingResponsive("border_radius", e.target.value)}
340
+ className="flex-1 accent-[#3580f9]"
341
+ />
342
+ <span className="text-xs text-neutral-900 w-10 text-right">
343
+ {getSettingValue<string>("border_radius", "0")}px
344
+ </span>
345
+ </div>
346
+ </SettingsField>
347
+
348
+ <SectionOverrideBadge
349
+ hasAny={hasAnyOverrideInGroup(["border_color", "border_width", "border_style", "border_sides", "border_radius"])}
350
+ onReset={() => resetGroup(["border_color", "border_width", "border_style", "border_sides", "border_radius"])}
351
+ viewport={activeViewport}
352
+ />
353
+ </SettingsSection>
354
+ </>
355
+ );
356
+ }