@morphika/andami 0.5.1 → 0.5.2

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 (117) hide show
  1. package/app/admin/assets/page.tsx +6 -6
  2. package/app/admin/database/page.tsx +302 -302
  3. package/app/admin/error.tsx +53 -53
  4. package/app/admin/layout.tsx +320 -320
  5. package/app/admin/navigation/page.tsx +255 -255
  6. package/app/admin/pages/[slug]/page.tsx +6 -6
  7. package/app/admin/pages/page.tsx +11 -11
  8. package/app/admin/projects/page.tsx +14 -14
  9. package/app/admin/setup/page.tsx +1 -1
  10. package/app/admin/styles/page.tsx +1 -1
  11. package/components/admin/MetadataEditor.tsx +6 -6
  12. package/components/admin/nav-builder/NavBuilder.tsx +1 -1
  13. package/components/admin/nav-builder/NavBuilderGrid.tsx +3 -3
  14. package/components/admin/nav-builder/NavGridCell.tsx +48 -48
  15. package/components/admin/nav-builder/NavGridItem.tsx +4 -4
  16. package/components/admin/nav-builder/NavItemSettings.tsx +331 -331
  17. package/components/admin/nav-builder/NavItemTypePicker.tsx +102 -102
  18. package/components/admin/nav-builder/NavLivePreview.tsx +1 -1
  19. package/components/admin/nav-builder/NavMobileLivePreview.tsx +226 -226
  20. package/components/admin/nav-builder/NavMobileSettings.tsx +242 -242
  21. package/components/admin/nav-builder/NavSettingsFields.tsx +514 -514
  22. package/components/admin/setup-wizard/BrandingStep.tsx +3 -3
  23. package/components/admin/setup-wizard/DatabaseStep.tsx +2 -2
  24. package/components/admin/setup-wizard/DoneStep.tsx +1 -1
  25. package/components/admin/setup-wizard/SetupWizard.tsx +4 -4
  26. package/components/admin/setup-wizard/StorageStep.tsx +2 -2
  27. package/components/admin/setup-wizard/WelcomeStep.tsx +2 -2
  28. package/components/admin/styles/ColorsEditor.tsx +2 -2
  29. package/components/admin/styles/FontsEditor.tsx +6 -6
  30. package/components/admin/styles/GridLayoutEditor.tsx +9 -9
  31. package/components/admin/styles/LinksButtonsEditor.tsx +5 -5
  32. package/components/admin/styles/TypographyEditor.tsx +6 -6
  33. package/components/admin/styles/shared.tsx +68 -68
  34. package/components/blocks/AudioBlockRenderer.tsx +286 -286
  35. package/components/blocks/MarqueeBlockRenderer.tsx +316 -0
  36. package/components/blocks/ProjectCarouselBlockRenderer.tsx +1 -1
  37. package/components/builder/BlockCardIcons.tsx +316 -316
  38. package/components/builder/BlockTypePicker.tsx +1 -1
  39. package/components/builder/BubbleIcons.tsx +90 -0
  40. package/components/builder/BuilderCanvas.tsx +2 -0
  41. package/components/builder/CanvasMinimap.tsx +2 -2
  42. package/components/builder/CoverSectionCanvas.tsx +363 -363
  43. package/components/builder/DeviceFrame.tsx +1 -1
  44. package/components/builder/DndWrapper.tsx +3 -3
  45. package/components/builder/InsertionLines.tsx +1 -1
  46. package/components/builder/SectionCardIcons.tsx +421 -320
  47. package/components/builder/SectionEditorBar.tsx +1 -1
  48. package/components/builder/SectionTypePicker.tsx +4 -4
  49. package/components/builder/SectionV2Canvas.tsx +1 -1
  50. package/components/builder/SectionV2Column.tsx +69 -67
  51. package/components/builder/SortableBlock.tsx +93 -73
  52. package/components/builder/SortableRow.tsx +27 -26
  53. package/components/builder/VirtualAssetGrid.tsx +2 -2
  54. package/components/builder/asset-browser/R2BrowserContent.tsx +11 -11
  55. package/components/builder/blockStyles.tsx +192 -185
  56. package/components/builder/color-picker/AlphaSlider.tsx +141 -141
  57. package/components/builder/color-picker/ColorInputs.tsx +105 -105
  58. package/components/builder/color-picker/EyedropperButton.tsx +74 -74
  59. package/components/builder/color-picker/HueSlider.tsx +124 -124
  60. package/components/builder/color-picker/SaturationCanvas.tsx +142 -142
  61. package/components/builder/color-picker/SwatchBar.tsx +93 -93
  62. package/components/builder/editors/AudioBlockEditor.tsx +242 -242
  63. package/components/builder/editors/BeforeAfterBlockEditor.tsx +360 -360
  64. package/components/builder/editors/ButtonBlockEditor.tsx +4 -4
  65. package/components/builder/editors/EnterAnimationPicker.tsx +2 -2
  66. package/components/builder/editors/HoverEffectPicker.tsx +2 -2
  67. package/components/builder/editors/ImageBlockEditor.tsx +2 -2
  68. package/components/builder/editors/ImageGridBlockEditor.tsx +4 -4
  69. package/components/builder/editors/MarqueeBlockEditor.tsx +621 -0
  70. package/components/builder/editors/ProjectCarouselBlockEditor.tsx +443 -443
  71. package/components/builder/editors/ProjectGridEditor.tsx +9 -9
  72. package/components/builder/editors/SpacerBlockEditor.tsx +5 -5
  73. package/components/builder/editors/StaggerSettings.tsx +109 -109
  74. package/components/builder/editors/TextBlockEditor.tsx +3 -3
  75. package/components/builder/editors/TextStylePicker.tsx +1 -1
  76. package/components/builder/editors/VideoBlockEditor.tsx +2 -2
  77. package/components/builder/editors/index.ts +11 -10
  78. package/components/builder/editors/shared.tsx +6 -6
  79. package/components/builder/live-preview/LiveAudioPreview.tsx +120 -120
  80. package/components/builder/live-preview/LiveBeforeAfterPreview.tsx +1 -1
  81. package/components/builder/live-preview/LiveImageGridPreview.tsx +10 -2
  82. package/components/builder/live-preview/LiveImagePreview.tsx +1 -1
  83. package/components/builder/live-preview/LiveMarqueePreview.tsx +39 -0
  84. package/components/builder/live-preview/LiveProjectCarouselPreview.tsx +1 -1
  85. package/components/builder/live-preview/LiveVideoPreview.tsx +1 -1
  86. package/components/builder/live-preview/ProjectCardWrapper.tsx +291 -291
  87. package/components/builder/settings-panel/AnimationTab.tsx +138 -138
  88. package/components/builder/settings-panel/BlockLayoutTab.tsx +7 -7
  89. package/components/builder/settings-panel/CardEntranceSection.tsx +114 -114
  90. package/components/builder/settings-panel/ColumnV2Settings.tsx +5 -5
  91. package/components/builder/settings-panel/CoverSectionLayoutTab.tsx +71 -71
  92. package/components/builder/settings-panel/CoverSectionSettings.tsx +335 -335
  93. package/components/builder/settings-panel/PageSettings.tsx +3 -3
  94. package/components/builder/settings-panel/ParallaxSlideSettings.tsx +2 -2
  95. package/components/builder/settings-panel/SectionV2AnimationTab.tsx +4 -4
  96. package/components/builder/settings-panel/SectionV2LayoutTab.tsx +356 -356
  97. package/components/builder/settings-panel/SectionV2Settings.tsx +14 -14
  98. package/components/builder/settings-panel/TRBLInputs.tsx +1 -1
  99. package/lib/animation/enter-types.ts +1 -0
  100. package/lib/animation/hover-effect-presets.ts +210 -210
  101. package/lib/animation/hover-effect-types.ts +1 -0
  102. package/lib/builder/block-registrations.ts +468 -417
  103. package/lib/builder/constants.ts +111 -111
  104. package/lib/builder/store-sections.ts +2 -2
  105. package/lib/builder/types-slices.ts +414 -414
  106. package/lib/builder/types.ts +4 -1
  107. package/lib/config/index.ts +27 -27
  108. package/lib/sanity/types.ts +98 -1
  109. package/lib/version.ts +1 -1
  110. package/package.json +1 -1
  111. package/sanity/schemas/blocks/audioBlock.ts +69 -69
  112. package/sanity/schemas/blocks/index.ts +12 -11
  113. package/sanity/schemas/blocks/marqueeBlock.ts +292 -0
  114. package/sanity/schemas/index.ts +120 -117
  115. package/styles/admin.css +85 -85
  116. package/styles/animations.css +237 -237
  117. 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
+ }