@codefluss/base-types 0.0.1-alpha.1

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.
@@ -0,0 +1,606 @@
1
+ /**
2
+ * Dependency Injection Types
3
+ *
4
+ * These types define the external dependencies that the plugin requires
5
+ * from the host application. All dependencies must be injected via props.
6
+ *
7
+ * @package @codefluss/base-types
8
+ * @version 1.0.0
9
+ */
10
+
11
+ import type { ComponentType } from 'react';
12
+
13
+ /**
14
+ * Responsive font size values for different breakpoints
15
+ */
16
+ export interface ResponsiveFontSizes {
17
+ mobile: string;
18
+ tablet: string;
19
+ desktop: string;
20
+ }
21
+
22
+ /**
23
+ * Responsive line height values for different breakpoints
24
+ */
25
+ export interface ResponsiveLineHeights {
26
+ mobile: number;
27
+ tablet: number;
28
+ desktop: number;
29
+ }
30
+
31
+ /**
32
+ * Design System Font Configuration
33
+ */
34
+ export interface DesignSystemFont {
35
+ family: string;
36
+ size: string;
37
+ weight: string;
38
+ lineHeight: string;
39
+ element?: string; // HTML element (h1, h2, p, etc.)
40
+ responsive?: ResponsiveFontSizes; // Optional responsive font sizes
41
+ responsiveLineHeight?: ResponsiveLineHeights; // Optional responsive line heights
42
+ }
43
+
44
+ /**
45
+ * Design System Color Configuration
46
+ */
47
+ export interface DesignSystemColor {
48
+ value: string;
49
+ label: string;
50
+ }
51
+
52
+ /**
53
+ * Box Model Value - Single side values
54
+ */
55
+ export interface BoxModelValue {
56
+ top: number;
57
+ right: number;
58
+ bottom: number;
59
+ left: number;
60
+ }
61
+
62
+ /**
63
+ * Grid Preset Values (Container-specific)
64
+ * Clean camelCase naming
65
+ */
66
+ export interface GridPresetValues {
67
+ columns: number;
68
+ rows: number;
69
+ columnGap: number;
70
+ rowGap: number;
71
+ maxWidth: number;
72
+ margin: number | string;
73
+ alignmentHorizontal: string;
74
+ alignmentVertical: string;
75
+ alignmentContent: string;
76
+ }
77
+
78
+ /**
79
+ * Responsive spacing values for different breakpoints
80
+ * Only 3 viewports: mobile, tablet, desktop
81
+ */
82
+ export interface ResponsiveBoxValues {
83
+ mobile: BoxModelValue;
84
+ tablet: BoxModelValue;
85
+ desktop: BoxModelValue;
86
+ }
87
+
88
+ /**
89
+ * Spacing Preset - Combined margin + padding with responsive values
90
+ */
91
+ export interface SpacingPreset {
92
+ presetId: string;
93
+ name: string;
94
+ margin: ResponsiveBoxValues;
95
+ padding: ResponsiveBoxValues;
96
+ }
97
+
98
+ /**
99
+ * Responsive spacing scale entry
100
+ */
101
+ export interface ResponsiveSpacingScale {
102
+ mobile: number;
103
+ tablet: number;
104
+ desktop: number;
105
+ unit: string;
106
+ }
107
+
108
+ /**
109
+ * Design System Spacing Configuration
110
+ * Clean, type-safe API
111
+ */
112
+ export interface DesignSystemSpacing {
113
+ /** Spacing scale values */
114
+ scale: number[];
115
+
116
+ /** Responsive spacing scales by token */
117
+ scaleResponsive: Map<string, ResponsiveSpacingScale>;
118
+
119
+ /**
120
+ * Get a spacing preset by ID
121
+ * @param presetId - The preset identifier
122
+ * @returns The spacing preset (guaranteed to exist, falls back to 'default')
123
+ */
124
+ getPreset(presetId: string): SpacingPreset;
125
+ }
126
+
127
+ /**
128
+ * Design System Grid Configuration
129
+ * Clean, type-safe API
130
+ */
131
+ export interface DesignSystemGrid {
132
+ /**
133
+ * Get a grid preset by ID
134
+ * @param presetId - The preset identifier
135
+ * @returns The grid preset values (guaranteed to exist, falls back to 'default')
136
+ */
137
+ getPreset(presetId: string): GridPresetValues;
138
+ }
139
+
140
+ /**
141
+ * Breakpoint configuration for responsive design
142
+ */
143
+ export interface BreakpointConfig {
144
+ minWidth: number;
145
+ name: string;
146
+ }
147
+
148
+ /**
149
+ * Design System Breakpoints
150
+ */
151
+ export interface DesignSystemBreakpoints {
152
+ mobile: BreakpointConfig;
153
+ tablet: BreakpointConfig;
154
+ desktop: BreakpointConfig;
155
+ }
156
+
157
+ /**
158
+ * Design System Layout Configuration
159
+ */
160
+ export interface DesignSystemLayout {
161
+ maxWidth?: string;
162
+ gap?: string;
163
+ padding?: string;
164
+ margin?: string;
165
+ }
166
+
167
+ /**
168
+ * Button Style Preset Configuration (Unified)
169
+ *
170
+ * Complete button style preset that replaces the separate
171
+ * ButtonSizePreset and ButtonVariantPreset interfaces.
172
+ * Matches design_system_button_styles table structure.
173
+ */
174
+ export interface ButtonStylePreset {
175
+ // Identifiers
176
+ id: string;
177
+ presetId: string;
178
+ name: string;
179
+ size: string;
180
+
181
+ // Typography
182
+ fontSizePresetId?: string;
183
+ fontWeight?: string;
184
+
185
+ // Spacing (reference to spacing preset)
186
+ spacingPresetId?: string;
187
+
188
+ // Border
189
+ borderRadiusPresetId?: string;
190
+
191
+ // Effect Presets
192
+ shadowPresetId?: string;
193
+ focusRingPresetId?: string;
194
+
195
+ // Animation Presets
196
+ animationPresetId?: string;
197
+ hoverEffectPresetId?: string;
198
+
199
+ // Colors - Default State
200
+ backgroundColorPresetId?: string;
201
+ textColorPresetId?: string;
202
+ borderColorPresetId?: string;
203
+
204
+ // Colors - Hover State
205
+ hoverBackgroundColorPresetId?: string;
206
+ hoverTextColorPresetId?: string;
207
+ hoverBorderColorPresetId?: string;
208
+
209
+ // Colors - Active/Pressed State
210
+ activeBackgroundColorPresetId?: string;
211
+ activeTextColorPresetId?: string;
212
+ activeBorderColorPresetId?: string;
213
+
214
+ // Transition Durations (in milliseconds)
215
+ defaultTransitionDuration: number;
216
+ hoverTransitionDuration: number;
217
+ activeTransitionDuration: number;
218
+
219
+ // Disabled State
220
+ disabledOpacity: number;
221
+
222
+ // Text Decoration per state
223
+ defaultTextDecoration?: string;
224
+ hoverTextDecoration?: string;
225
+ activeTextDecoration?: string;
226
+
227
+ // Text Transform per state
228
+ defaultTextTransform?: string;
229
+ hoverTextTransform?: string;
230
+ activeTextTransform?: string;
231
+
232
+ // Metadata
233
+ usageDescription?: string;
234
+ isDefault: boolean;
235
+ }
236
+
237
+ /**
238
+ * @deprecated Use ButtonStylePreset instead
239
+ * Legacy Button Size Preset Configuration
240
+ */
241
+ export interface ButtonSizePreset {
242
+ button_id: string;
243
+ name: string;
244
+ padding: string;
245
+ fontSize: string;
246
+ iconSize: string;
247
+ minHeight: string;
248
+ borderRadius?: string;
249
+ fontWeight?: string;
250
+ usage_description?: string;
251
+ }
252
+
253
+ /**
254
+ * @deprecated Use ButtonStylePreset instead
255
+ * Legacy Button Variant Preset Configuration
256
+ */
257
+ export interface ButtonVariantPreset {
258
+ background: string;
259
+ hoverBackground: string;
260
+ textColor: string;
261
+ borderColor: string;
262
+ }
263
+
264
+ /**
265
+ * Shadow Configuration
266
+ */
267
+ export interface ShadowConfig {
268
+ value: string;
269
+ dark?: string;
270
+ }
271
+
272
+ /**
273
+ * Accordion Style Preset Configuration
274
+ *
275
+ * Complete accordion style preset for collapsible components.
276
+ * Matches design_system_accordion_presets table structure.
277
+ */
278
+ export interface AccordionStylePreset {
279
+ // Identifiers
280
+ id: string;
281
+ presetId: string;
282
+ name: string;
283
+
284
+ // Header Settings
285
+ headerHeight?: string;
286
+ headerFontSizePresetId?: string;
287
+ headerFontWeight?: string;
288
+ headerPaddingPresetId?: string;
289
+ headerBackgroundColorPresetId?: string;
290
+ headerHoverBackgroundColorPresetId?: string;
291
+ headerTextColorPresetId?: string;
292
+ headerBorderColorPresetId?: string;
293
+
294
+ // Body Settings
295
+ bodyMinHeight?: string;
296
+ bodyPaddingPresetId?: string;
297
+ bodyBackgroundColorPresetId?: string;
298
+ bodyBorderColorPresetId?: string;
299
+
300
+ // General
301
+ borderRadiusPresetId?: string;
302
+ shadowPresetId?: string;
303
+ spacingPresetId?: string;
304
+
305
+ // Animation
306
+ transitionDuration: number;
307
+ transitionEasing?: string;
308
+
309
+ // State Colors
310
+ expandedBackgroundColorPresetId?: string;
311
+ expandedTextColorPresetId?: string;
312
+
313
+ // Metadata
314
+ usageDescription?: string;
315
+ isDefault: boolean;
316
+ }
317
+
318
+ /**
319
+ * Form Style Preset Configuration (Unified)
320
+ *
321
+ * Complete form style preset that contains all styling for form elements.
322
+ * Matches design_system_form_styles table structure.
323
+ */
324
+ export interface FormStylePreset {
325
+ // Identifiers
326
+ id: string;
327
+ presetId: string;
328
+ name: string;
329
+ variant: string;
330
+ size: string;
331
+
332
+ // Typography
333
+ fontSizePresetId?: string;
334
+
335
+ // Spacing
336
+ paddingX: number;
337
+ paddingY: number;
338
+ borderWidth: number;
339
+ borderRadiusPresetId?: string;
340
+
341
+ // Effect Presets
342
+ shadowPresetId?: string;
343
+ focusRingPresetId?: string;
344
+
345
+ // Animation Presets
346
+ animationPresetId?: string;
347
+ hoverEffectPresetId?: string;
348
+
349
+ // Colors - Default State
350
+ backgroundColorPresetId?: string;
351
+ textColorPresetId?: string;
352
+ borderColorPresetId?: string;
353
+ placeholderColorPresetId?: string;
354
+ focusRingColorPresetId?: string;
355
+
356
+ // Colors - Hover State
357
+ hoverBackgroundColorPresetId?: string;
358
+ hoverBorderColorPresetId?: string;
359
+
360
+ // Disabled State
361
+ disabledOpacity: number;
362
+
363
+ // Error State
364
+ errorBorderColorPresetId?: string;
365
+ errorTextColorPresetId?: string;
366
+
367
+ // Submit Button Reference
368
+ submitButtonPresetId?: string;
369
+
370
+ // Container Styling
371
+ containerBackgroundColorPresetId?: string;
372
+ containerSpacingPresetId?: string;
373
+
374
+ // Label Styling
375
+ labelFontPresetId?: string;
376
+ labelColorPresetId?: string;
377
+
378
+ // Description/Help Text Styling
379
+ descriptionFontPresetId?: string;
380
+ descriptionColorPresetId?: string;
381
+
382
+ // Field Spacing
383
+ fieldGap?: number;
384
+
385
+ // Metadata
386
+ usageDescription?: string;
387
+ isDefault: boolean;
388
+ }
389
+
390
+ /**
391
+ * Design System API
392
+ *
393
+ * Interface for accessing global design system values.
394
+ * The host application must provide an implementation.
395
+ */
396
+ export interface PluginDesignSystem {
397
+ fonts: {
398
+ getPreset: (presetId: string) => DesignSystemFont | undefined;
399
+ };
400
+ colors: {
401
+ getPreset: (presetId: string) => DesignSystemColor | undefined;
402
+ };
403
+ spacing: DesignSystemSpacing;
404
+ grid?: DesignSystemGrid; // Container-specific, optional
405
+ layout: {
406
+ getPreset: (presetId: string) => DesignSystemLayout | undefined;
407
+ };
408
+ breakpoints: {
409
+ getConfig: () => DesignSystemBreakpoints;
410
+ };
411
+ /**
412
+ * Button System (optional)
413
+ * Provides unified button style presets from design system database
414
+ * Each preset contains colors, typography, spacing, and effects
415
+ */
416
+ buttons?: {
417
+ /**
418
+ * Get button style preset by ID
419
+ * @param presetId - Button preset identifier (e.g., 'primary', 'secondary', 'custom-1')
420
+ * @returns Button style preset or undefined if not found
421
+ */
422
+ getPreset: (presetId: string) => ButtonStylePreset | undefined;
423
+ /**
424
+ * List all available button style presets
425
+ * @returns Array of button style presets sorted by sort_order
426
+ */
427
+ listPresets?: () => ButtonStylePreset[];
428
+ };
429
+ /**
430
+ * Form System (optional)
431
+ * Provides unified form style presets from design system database
432
+ * Each preset contains colors, typography, spacing, and effects for form elements
433
+ */
434
+ forms?: {
435
+ /**
436
+ * Get form style preset by ID
437
+ * @param presetId - Form preset identifier (e.g., 'default', 'outlined', 'custom-1')
438
+ * @returns Form style preset or undefined if not found
439
+ */
440
+ getPreset: (presetId: string) => FormStylePreset | undefined;
441
+ /**
442
+ * List all available form style presets
443
+ * @returns Array of form style presets sorted by sort_order
444
+ */
445
+ listPresets?: () => FormStylePreset[];
446
+ };
447
+ /**
448
+ * Accordion System (optional)
449
+ * Provides unified accordion style presets from design system database
450
+ * Each preset contains colors, typography, spacing, and effects for accordion components
451
+ */
452
+ accordions?: {
453
+ /**
454
+ * Get accordion style preset by ID
455
+ * @param presetId - Accordion preset identifier (e.g., 'default', 'sm', 'lg', 'custom-1')
456
+ * @returns Accordion style preset or undefined if not found
457
+ */
458
+ getPreset: (presetId: string) => AccordionStylePreset | undefined;
459
+ /**
460
+ * List all available accordion style presets
461
+ * @returns Array of accordion style presets sorted by sort_order
462
+ */
463
+ listPresets?: () => AccordionStylePreset[];
464
+ };
465
+ /**
466
+ * Shadow System (optional)
467
+ * Provides shadow presets with light and dark mode variants
468
+ */
469
+ shadows?: {
470
+ getPreset: (presetId: string) => ShadowConfig;
471
+ };
472
+ }
473
+
474
+ /**
475
+ * Utility Functions API
476
+ *
477
+ * Interface for utility functions required by the plugin.
478
+ * The host application must provide implementations.
479
+ */
480
+ export interface PluginUtils {
481
+ /**
482
+ * Class name utility (e.g., clsx, classnames, tailwind-merge)
483
+ * Combines multiple class names intelligently
484
+ */
485
+ cn: (...inputs: any[]) => string;
486
+ }
487
+
488
+ /**
489
+ * Plugin Renderer Props
490
+ *
491
+ * Props interface for the PluginRenderer component.
492
+ * This is injected by the host application to render child plugins.
493
+ */
494
+ export interface PluginRendererProps {
495
+ /**
496
+ * Plugin ID to render (e.g., 'base-text', 'base-image')
497
+ */
498
+ pluginId: string;
499
+
500
+ /**
501
+ * Element ID for tracking
502
+ */
503
+ elementId: string;
504
+
505
+ /**
506
+ * Plugin data/configuration
507
+ */
508
+ data: Record<string, unknown>;
509
+
510
+ /**
511
+ * Current language code
512
+ */
513
+ language: string;
514
+
515
+ /**
516
+ * Is in editor mode?
517
+ */
518
+ isEditorMode?: boolean;
519
+
520
+ /**
521
+ * Is element selected?
522
+ */
523
+ isSelected?: boolean;
524
+
525
+ /**
526
+ * Click handler
527
+ */
528
+ onClick?: (id: string) => void;
529
+ }
530
+
531
+ /**
532
+ * Plugin Callbacks
533
+ *
534
+ * Event callbacks that plugins can use to communicate with the host application.
535
+ */
536
+ export interface PluginCallbacks {
537
+ /**
538
+ * Called when content changes (for text, rich-text components)
539
+ * @param elementId - ID of the element
540
+ * @param language - Language code
541
+ * @param content - New content value
542
+ */
543
+ onContentChange?: (
544
+ elementId: string,
545
+ language: string,
546
+ content: string
547
+ ) => void;
548
+
549
+ /**
550
+ * Called when child element is dropped into container
551
+ * @param containerId - ID of the container element
552
+ * @param droppedElementId - ID of the dropped element
553
+ * @param index - Optional insertion index
554
+ */
555
+ onChildAdded?: (
556
+ containerId: string,
557
+ droppedElementId: string,
558
+ index?: number
559
+ ) => void;
560
+
561
+ /**
562
+ * Called when child element is removed from container
563
+ * @param containerId - ID of the container element
564
+ * @param removedElementId - ID of the removed element
565
+ */
566
+ onChildRemoved?: (containerId: string, removedElementId: string) => void;
567
+
568
+ /**
569
+ * Called when container layout is changed
570
+ * @param containerId - ID of the container element
571
+ * @param layoutMode - New layout mode
572
+ */
573
+ onLayoutChange?: (
574
+ containerId: string,
575
+ layoutMode: 'flexbox' | 'grid'
576
+ ) => void;
577
+ }
578
+
579
+ /**
580
+ * Complete Plugin Dependencies
581
+ *
582
+ * All external dependencies that must be injected into the plugin.
583
+ * PLUGIN-DRIVEN ARCHITECTURE: Plugins receive dependencies from the host app.
584
+ */
585
+ export interface PluginDependencies {
586
+ /**
587
+ * Design System API for accessing global design tokens
588
+ */
589
+ designSystem: PluginDesignSystem;
590
+
591
+ /**
592
+ * Utility functions (e.g., cn for classnames)
593
+ */
594
+ utils: PluginUtils;
595
+
596
+ /**
597
+ * PluginRenderer component for rendering child plugins
598
+ * CRITICAL: Container plugins need this to render their NESTED children
599
+ */
600
+ PluginRenderer: ComponentType<PluginRendererProps>;
601
+
602
+ /**
603
+ * Optional callbacks for communication with host app
604
+ */
605
+ callbacks?: PluginCallbacks;
606
+ }
package/src/index.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @codefluss/base-types
3
+ *
4
+ * Shared type definitions for the Codefluss Page Builder plugin system.
5
+ * This package provides the single source of truth for all plugin-related types.
6
+ *
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ */
10
+
11
+ // Export common types (single source of truth)
12
+ export * from './common-types';
13
+
14
+ // Export all types from plugin-system
15
+ export type {
16
+ PropertyControlType,
17
+ PropertyType,
18
+ PropertyCategory,
19
+ PropertyPriority,
20
+ SliderConfig,
21
+ NumberConfig,
22
+ NumberWithUnitConfig,
23
+ SelectConfig,
24
+ InputConfig,
25
+ ColorPickerConfig,
26
+ TextareaConfig,
27
+ BoxModelConfig,
28
+ SpacingConfig,
29
+ TypographyToolbarConfig,
30
+ GradientEditorConfig,
31
+ BorderEditorConfig,
32
+ AlignmentToggleConfig,
33
+ DisplayConfig,
34
+ PropertyUIConfig,
35
+ PropertyValidation,
36
+ PropertyDefinition,
37
+ PluginMeta,
38
+ PluginCapabilities,
39
+ PluginConfig,
40
+ // Dual-Component Architecture Props
41
+ PluginDependencies,
42
+ BasePluginProps,
43
+ EditorModeProps,
44
+ RendererProps,
45
+ ContainerProps,
46
+ } from "./plugin-system";
47
+
48
+ // Export all types from dependencies
49
+ export type {
50
+ ResponsiveFontSizes,
51
+ DesignSystemFont,
52
+ DesignSystemColor,
53
+ BreakpointConfig,
54
+ DesignSystemBreakpoints,
55
+ BoxModelValue,
56
+ ResponsiveBoxValues,
57
+ SpacingPreset,
58
+ ResponsiveSpacingScale,
59
+ GridPresetValues,
60
+ DesignSystemSpacing,
61
+ DesignSystemGrid,
62
+ DesignSystemLayout,
63
+ PluginDesignSystem,
64
+ PluginUtils,
65
+ PluginRendererProps,
66
+ PluginCallbacks,
67
+ } from "./dependencies";
68
+