@object-ui/core 3.0.3 → 3.1.0

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 (78) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/actions/ActionEngine.d.ts +98 -0
  3. package/dist/actions/ActionEngine.js +222 -0
  4. package/dist/actions/UndoManager.d.ts +80 -0
  5. package/dist/actions/UndoManager.js +193 -0
  6. package/dist/actions/index.d.ts +2 -0
  7. package/dist/actions/index.js +2 -0
  8. package/dist/adapters/ApiDataSource.d.ts +2 -1
  9. package/dist/adapters/ApiDataSource.js +25 -0
  10. package/dist/adapters/ValueDataSource.d.ts +2 -1
  11. package/dist/adapters/ValueDataSource.js +99 -3
  12. package/dist/data-scope/ViewDataProvider.d.ts +143 -0
  13. package/dist/data-scope/ViewDataProvider.js +153 -0
  14. package/dist/data-scope/index.d.ts +1 -0
  15. package/dist/data-scope/index.js +1 -0
  16. package/dist/evaluator/ExpressionEvaluator.d.ts +7 -0
  17. package/dist/evaluator/ExpressionEvaluator.js +19 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +5 -0
  20. package/dist/protocols/DndProtocol.d.ts +84 -0
  21. package/dist/protocols/DndProtocol.js +113 -0
  22. package/dist/protocols/KeyboardProtocol.d.ts +93 -0
  23. package/dist/protocols/KeyboardProtocol.js +108 -0
  24. package/dist/protocols/NotificationProtocol.d.ts +71 -0
  25. package/dist/protocols/NotificationProtocol.js +99 -0
  26. package/dist/protocols/ResponsiveProtocol.d.ts +73 -0
  27. package/dist/protocols/ResponsiveProtocol.js +158 -0
  28. package/dist/protocols/SharingProtocol.d.ts +71 -0
  29. package/dist/protocols/SharingProtocol.js +124 -0
  30. package/dist/protocols/index.d.ts +12 -0
  31. package/dist/protocols/index.js +12 -0
  32. package/dist/utils/debug-collector.d.ts +59 -0
  33. package/dist/utils/debug-collector.js +73 -0
  34. package/dist/utils/debug.d.ts +37 -2
  35. package/dist/utils/debug.js +62 -3
  36. package/dist/utils/expand-fields.d.ts +40 -0
  37. package/dist/utils/expand-fields.js +68 -0
  38. package/dist/utils/extract-records.d.ts +16 -0
  39. package/dist/utils/extract-records.js +32 -0
  40. package/dist/utils/normalize-quick-filter.d.ts +29 -0
  41. package/dist/utils/normalize-quick-filter.js +66 -0
  42. package/package.json +3 -3
  43. package/src/__tests__/protocols/DndProtocol.test.ts +186 -0
  44. package/src/__tests__/protocols/KeyboardProtocol.test.ts +177 -0
  45. package/src/__tests__/protocols/NotificationProtocol.test.ts +142 -0
  46. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +176 -0
  47. package/src/__tests__/protocols/SharingProtocol.test.ts +188 -0
  48. package/src/actions/ActionEngine.ts +268 -0
  49. package/src/actions/UndoManager.ts +215 -0
  50. package/src/actions/__tests__/ActionEngine.test.ts +206 -0
  51. package/src/actions/__tests__/UndoManager.test.ts +320 -0
  52. package/src/actions/index.ts +2 -0
  53. package/src/adapters/ApiDataSource.ts +27 -0
  54. package/src/adapters/ValueDataSource.ts +109 -3
  55. package/src/adapters/__tests__/ValueDataSource.test.ts +147 -0
  56. package/src/data-scope/ViewDataProvider.ts +282 -0
  57. package/src/data-scope/__tests__/ViewDataProvider.test.ts +270 -0
  58. package/src/data-scope/index.ts +8 -0
  59. package/src/evaluator/ExpressionEvaluator.ts +22 -0
  60. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +31 -1
  61. package/src/index.ts +5 -0
  62. package/src/protocols/DndProtocol.ts +184 -0
  63. package/src/protocols/KeyboardProtocol.ts +185 -0
  64. package/src/protocols/NotificationProtocol.ts +159 -0
  65. package/src/protocols/ResponsiveProtocol.ts +210 -0
  66. package/src/protocols/SharingProtocol.ts +185 -0
  67. package/src/protocols/index.ts +13 -0
  68. package/src/utils/__tests__/debug-collector.test.ts +102 -0
  69. package/src/utils/__tests__/debug.test.ts +52 -1
  70. package/src/utils/__tests__/expand-fields.test.ts +120 -0
  71. package/src/utils/__tests__/extract-records.test.ts +50 -0
  72. package/src/utils/__tests__/normalize-quick-filter.test.ts +123 -0
  73. package/src/utils/debug-collector.ts +100 -0
  74. package/src/utils/debug.ts +87 -6
  75. package/src/utils/expand-fields.ts +76 -0
  76. package/src/utils/extract-records.ts +33 -0
  77. package/src/utils/normalize-quick-filter.ts +78 -0
  78. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,113 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // ============================================================================
9
+ // DnD Config Resolution
10
+ // ============================================================================
11
+ /**
12
+ * Resolve a DnD configuration by applying spec defaults to missing fields.
13
+ *
14
+ * @param config - Partial DnD configuration from the spec
15
+ * @returns Fully resolved DnD configuration
16
+ */
17
+ export function resolveDndConfig(config) {
18
+ return {
19
+ enabled: config.enabled ?? false,
20
+ sortable: config.sortable ?? false,
21
+ autoScroll: config.autoScroll ?? true,
22
+ touchDelay: config.touchDelay ?? 200,
23
+ dragItem: config.dragItem,
24
+ dropZone: config.dropZone,
25
+ };
26
+ }
27
+ // ============================================================================
28
+ // Drag Item Props
29
+ // ============================================================================
30
+ /**
31
+ * Convert a spec DragItem to component props suitable for a draggable element.
32
+ * Produces `draggable`, ARIA attributes, and data attributes for DnD libraries.
33
+ *
34
+ * @param item - DragItem configuration from the spec
35
+ * @returns Component props object for a draggable element
36
+ */
37
+ export function createDragItemProps(item) {
38
+ const ariaLabel = typeof item.ariaLabel === 'string'
39
+ ? item.ariaLabel
40
+ : item.ariaLabel?.defaultValue;
41
+ const label = typeof item.label === 'string'
42
+ ? item.label
43
+ : item.label?.defaultValue;
44
+ return {
45
+ draggable: !(item.disabled ?? false),
46
+ 'aria-roledescription': 'draggable',
47
+ 'aria-label': ariaLabel ?? label,
48
+ 'aria-describedby': item.ariaDescribedBy,
49
+ role: item.role ?? 'listitem',
50
+ 'data-drag-type': item.type,
51
+ 'data-drag-handle': item.handle ?? 'element',
52
+ 'data-drag-disabled': String(item.disabled ?? false),
53
+ };
54
+ }
55
+ // ============================================================================
56
+ // Drop Zone Props
57
+ // ============================================================================
58
+ /**
59
+ * Convert a spec DropZone to component props suitable for a droppable area.
60
+ * Produces ARIA attributes and data attributes for DnD libraries.
61
+ *
62
+ * @param zone - DropZone configuration from the spec
63
+ * @returns Component props object for a droppable area
64
+ */
65
+ export function createDropZoneProps(zone) {
66
+ const ariaLabel = typeof zone.ariaLabel === 'string'
67
+ ? zone.ariaLabel
68
+ : zone.ariaLabel?.defaultValue;
69
+ const label = typeof zone.label === 'string'
70
+ ? zone.label
71
+ : zone.label?.defaultValue;
72
+ return {
73
+ 'aria-dropeffect': zone.dropEffect ?? 'move',
74
+ 'aria-label': ariaLabel ?? label,
75
+ 'aria-describedby': zone.ariaDescribedBy,
76
+ role: zone.role ?? 'list',
77
+ 'data-drop-accept': zone.accept.join(','),
78
+ 'data-drop-max-items': zone.maxItems,
79
+ 'data-drop-highlight': String(zone.highlightOnDragOver ?? true),
80
+ };
81
+ }
82
+ // ============================================================================
83
+ // Drag Constraint Styles
84
+ // ============================================================================
85
+ /**
86
+ * Resolve a DragConstraint into CSS style properties that restrict
87
+ * drag movement along an axis or within bounds.
88
+ *
89
+ * @param constraint - DragConstraint configuration from the spec
90
+ * @returns CSS styles object for constraining drag movement
91
+ */
92
+ export function resolveDragConstraints(constraint) {
93
+ const styles = {
94
+ position: 'relative',
95
+ touchAction: 'none',
96
+ };
97
+ const axis = constraint.axis ?? 'both';
98
+ if (axis === 'x') {
99
+ styles.touchAction = 'pan-y';
100
+ }
101
+ else if (axis === 'y') {
102
+ styles.touchAction = 'pan-x';
103
+ }
104
+ const bounds = constraint.bounds ?? 'none';
105
+ if (bounds === 'parent') {
106
+ styles.overflow = 'hidden';
107
+ }
108
+ if (constraint.grid) {
109
+ styles['--drag-grid-x'] = `${constraint.grid[0]}px`;
110
+ styles['--drag-grid-y'] = `${constraint.grid[1]}px`;
111
+ }
112
+ return styles;
113
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * @object-ui/core - Keyboard Protocol Bridge
10
+ *
11
+ * Converts spec-aligned keyboard navigation and focus management
12
+ * schemas into runtime-usable configurations, shortcut parsers,
13
+ * and focus trap settings.
14
+ *
15
+ * @module protocols/KeyboardProtocol
16
+ * @packageDocumentation
17
+ */
18
+ import type { KeyboardNavigationConfig, KeyboardShortcut, FocusTrapConfig } from '@object-ui/types';
19
+ /** Fully resolved keyboard navigation configuration. */
20
+ export interface ResolvedKeyboardConfig {
21
+ shortcuts: KeyboardShortcut[];
22
+ focusManagement: ResolvedFocusManagement;
23
+ rovingTabindex: boolean;
24
+ ariaLabel?: string;
25
+ ariaDescribedBy?: string;
26
+ role?: string;
27
+ }
28
+ /** Fully resolved focus management configuration. */
29
+ export interface ResolvedFocusManagement {
30
+ tabOrder: 'auto' | 'manual';
31
+ skipLinks: boolean;
32
+ focusVisible: boolean;
33
+ focusTrap?: ResolvedFocusTrapConfig;
34
+ arrowNavigation: boolean;
35
+ }
36
+ /** Fully resolved focus trap configuration. */
37
+ export interface ResolvedFocusTrapConfig {
38
+ enabled: boolean;
39
+ initialFocus?: string;
40
+ returnFocus: boolean;
41
+ escapeDeactivates: boolean;
42
+ }
43
+ /** Parsed keyboard shortcut descriptor. */
44
+ export interface ParsedShortcut {
45
+ key: string;
46
+ ctrlOrMeta: boolean;
47
+ shift: boolean;
48
+ alt: boolean;
49
+ }
50
+ /** Minimal keyboard event shape for matching (no React dependency). */
51
+ export interface KeyboardEventLike {
52
+ key: string;
53
+ ctrlKey?: boolean;
54
+ metaKey?: boolean;
55
+ shiftKey?: boolean;
56
+ altKey?: boolean;
57
+ }
58
+ /**
59
+ * Resolve a keyboard navigation configuration by applying spec defaults.
60
+ *
61
+ * @param config - KeyboardNavigationConfig from the spec
62
+ * @returns Fully resolved keyboard navigation configuration
63
+ */
64
+ export declare function resolveKeyboardConfig(config: KeyboardNavigationConfig): ResolvedKeyboardConfig;
65
+ /**
66
+ * Parse a shortcut string like "Ctrl+Shift+S" into a structured descriptor.
67
+ * Recognises Ctrl, Meta, Cmd (mapped to ctrlOrMeta), Shift, and Alt modifiers.
68
+ * The last segment is treated as the key.
69
+ *
70
+ * Keys are normalised to lowercase for case-insensitive matching. The Shift
71
+ * modifier is tracked separately, so "Shift+A" and "Shift+a" are equivalent
72
+ * (both represent the same physical key combination).
73
+ *
74
+ * @param shortcut - Shortcut string (e.g. "Ctrl+S", "Alt+Shift+N", "Escape")
75
+ * @returns Parsed shortcut descriptor
76
+ */
77
+ export declare function parseShortcutKey(shortcut: string): ParsedShortcut;
78
+ /**
79
+ * Test whether a keyboard event matches a shortcut string.
80
+ * Comparison is case-insensitive; the Shift modifier is checked separately.
81
+ *
82
+ * @param event - The keyboard event (or a plain object with key + modifier flags)
83
+ * @param shortcut - Shortcut string (e.g. "Ctrl+S")
84
+ * @returns `true` if the event matches the shortcut
85
+ */
86
+ export declare function matchesShortcut(event: KeyboardEventLike, shortcut: string): boolean;
87
+ /**
88
+ * Create a resolved focus trap configuration from a spec FocusTrapConfig.
89
+ *
90
+ * @param config - FocusTrapConfig from the spec
91
+ * @returns Resolved focus trap configuration with defaults applied
92
+ */
93
+ export declare function createFocusTrapConfig(config: FocusTrapConfig): ResolvedFocusTrapConfig;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // ============================================================================
9
+ // Keyboard Config Resolution
10
+ // ============================================================================
11
+ /**
12
+ * Resolve a keyboard navigation configuration by applying spec defaults.
13
+ *
14
+ * @param config - KeyboardNavigationConfig from the spec
15
+ * @returns Fully resolved keyboard navigation configuration
16
+ */
17
+ export function resolveKeyboardConfig(config) {
18
+ const ariaLabel = typeof config.ariaLabel === 'string'
19
+ ? config.ariaLabel
20
+ : config.ariaLabel?.defaultValue;
21
+ return {
22
+ shortcuts: config.shortcuts ?? [],
23
+ focusManagement: resolveFocusManagement(config.focusManagement),
24
+ rovingTabindex: config.rovingTabindex ?? false,
25
+ ariaLabel,
26
+ ariaDescribedBy: config.ariaDescribedBy,
27
+ role: config.role,
28
+ };
29
+ }
30
+ /**
31
+ * Resolve focus management configuration with defaults.
32
+ */
33
+ function resolveFocusManagement(fm) {
34
+ return {
35
+ tabOrder: fm?.tabOrder ?? 'auto',
36
+ skipLinks: fm?.skipLinks ?? false,
37
+ focusVisible: fm?.focusVisible ?? true,
38
+ focusTrap: fm?.focusTrap ? createFocusTrapConfig(fm.focusTrap) : undefined,
39
+ arrowNavigation: fm?.arrowNavigation ?? false,
40
+ };
41
+ }
42
+ // ============================================================================
43
+ // Shortcut Parsing
44
+ // ============================================================================
45
+ /**
46
+ * Parse a shortcut string like "Ctrl+Shift+S" into a structured descriptor.
47
+ * Recognises Ctrl, Meta, Cmd (mapped to ctrlOrMeta), Shift, and Alt modifiers.
48
+ * The last segment is treated as the key.
49
+ *
50
+ * Keys are normalised to lowercase for case-insensitive matching. The Shift
51
+ * modifier is tracked separately, so "Shift+A" and "Shift+a" are equivalent
52
+ * (both represent the same physical key combination).
53
+ *
54
+ * @param shortcut - Shortcut string (e.g. "Ctrl+S", "Alt+Shift+N", "Escape")
55
+ * @returns Parsed shortcut descriptor
56
+ */
57
+ export function parseShortcutKey(shortcut) {
58
+ const parts = shortcut.split('+').map(p => p.trim());
59
+ const modifiers = new Set(parts.slice(0, -1).map(m => m.toLowerCase()));
60
+ const key = (parts[parts.length - 1] ?? '').toLowerCase();
61
+ return {
62
+ key,
63
+ ctrlOrMeta: modifiers.has('ctrl') || modifiers.has('meta') || modifiers.has('cmd'),
64
+ shift: modifiers.has('shift'),
65
+ alt: modifiers.has('alt'),
66
+ };
67
+ }
68
+ // ============================================================================
69
+ // Shortcut Matching
70
+ // ============================================================================
71
+ /**
72
+ * Test whether a keyboard event matches a shortcut string.
73
+ * Comparison is case-insensitive; the Shift modifier is checked separately.
74
+ *
75
+ * @param event - The keyboard event (or a plain object with key + modifier flags)
76
+ * @param shortcut - Shortcut string (e.g. "Ctrl+S")
77
+ * @returns `true` if the event matches the shortcut
78
+ */
79
+ export function matchesShortcut(event, shortcut) {
80
+ const parsed = parseShortcutKey(shortcut);
81
+ if (event.key.toLowerCase() !== parsed.key)
82
+ return false;
83
+ const eventCtrlOrMeta = !!(event.ctrlKey || event.metaKey);
84
+ if (parsed.ctrlOrMeta !== eventCtrlOrMeta)
85
+ return false;
86
+ if (parsed.shift !== !!(event.shiftKey))
87
+ return false;
88
+ if (parsed.alt !== !!(event.altKey))
89
+ return false;
90
+ return true;
91
+ }
92
+ // ============================================================================
93
+ // Focus Trap Configuration
94
+ // ============================================================================
95
+ /**
96
+ * Create a resolved focus trap configuration from a spec FocusTrapConfig.
97
+ *
98
+ * @param config - FocusTrapConfig from the spec
99
+ * @returns Resolved focus trap configuration with defaults applied
100
+ */
101
+ export function createFocusTrapConfig(config) {
102
+ return {
103
+ enabled: config.enabled ?? false,
104
+ initialFocus: config.initialFocus,
105
+ returnFocus: config.returnFocus ?? true,
106
+ escapeDeactivates: config.escapeDeactivates ?? true,
107
+ };
108
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * @object-ui/core - Notification Protocol Bridge
10
+ *
11
+ * Converts spec-aligned Notification schemas into toast-compatible
12
+ * objects that UI layers can render. Maps severity to variant,
13
+ * position names, and resolves default notification configs.
14
+ *
15
+ * @module protocols/NotificationProtocol
16
+ * @packageDocumentation
17
+ */
18
+ import type { Notification as SpecNotification, NotificationConfig, NotificationPosition } from '@object-ui/types';
19
+ /** Fully resolved notification configuration. */
20
+ export interface ResolvedNotificationConfig {
21
+ defaultPosition: NotificationPosition;
22
+ defaultDuration: number;
23
+ maxVisible: number;
24
+ stackDirection: 'up' | 'down';
25
+ pauseOnHover: boolean;
26
+ }
27
+ /** Toast-compatible representation of a spec Notification. */
28
+ export interface ToastNotification {
29
+ title?: string;
30
+ description: string;
31
+ variant: string;
32
+ position: string;
33
+ duration: number;
34
+ dismissible: boolean;
35
+ actions: ToastAction[];
36
+ }
37
+ /** Toast-compatible action button. */
38
+ export interface ToastAction {
39
+ label: string;
40
+ action: string;
41
+ variant: 'primary' | 'secondary' | 'link';
42
+ }
43
+ /**
44
+ * Map a spec notification severity to a toast variant string.
45
+ *
46
+ * @param severity - Spec severity (info, success, warning, error)
47
+ * @returns Toast variant (default, success, warning, destructive)
48
+ */
49
+ export declare function mapSeverityToVariant(severity: string): string;
50
+ /**
51
+ * Map a spec notification position (underscore-separated) to a
52
+ * toast position string (hyphen-separated).
53
+ *
54
+ * @param position - Spec position (e.g. "top_right")
55
+ * @returns Toast position (e.g. "top-right")
56
+ */
57
+ export declare function mapPosition(position: string): string;
58
+ /**
59
+ * Resolve a notification configuration by applying spec defaults.
60
+ *
61
+ * @param config - NotificationConfig from the spec
62
+ * @returns Fully resolved notification configuration
63
+ */
64
+ export declare function resolveNotificationConfig(config: NotificationConfig): ResolvedNotificationConfig;
65
+ /**
66
+ * Convert a spec Notification to a toast-compatible object.
67
+ *
68
+ * @param notification - Spec Notification
69
+ * @returns Toast-compatible notification with title, description, variant, etc.
70
+ */
71
+ export declare function specNotificationToToast(notification: SpecNotification): ToastNotification;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // ============================================================================
9
+ // Severity → Variant Mapping
10
+ // ============================================================================
11
+ const SEVERITY_TO_VARIANT = {
12
+ info: 'default',
13
+ success: 'success',
14
+ warning: 'warning',
15
+ error: 'destructive',
16
+ };
17
+ /**
18
+ * Map a spec notification severity to a toast variant string.
19
+ *
20
+ * @param severity - Spec severity (info, success, warning, error)
21
+ * @returns Toast variant (default, success, warning, destructive)
22
+ */
23
+ export function mapSeverityToVariant(severity) {
24
+ return SEVERITY_TO_VARIANT[severity] ?? 'default';
25
+ }
26
+ // ============================================================================
27
+ // Position Mapping
28
+ // ============================================================================
29
+ const POSITION_MAP = {
30
+ top_left: 'top-left',
31
+ top_center: 'top-center',
32
+ top_right: 'top-right',
33
+ bottom_left: 'bottom-left',
34
+ bottom_center: 'bottom-center',
35
+ bottom_right: 'bottom-right',
36
+ };
37
+ /**
38
+ * Map a spec notification position (underscore-separated) to a
39
+ * toast position string (hyphen-separated).
40
+ *
41
+ * @param position - Spec position (e.g. "top_right")
42
+ * @returns Toast position (e.g. "top-right")
43
+ */
44
+ export function mapPosition(position) {
45
+ return POSITION_MAP[position] ?? 'top-right';
46
+ }
47
+ // ============================================================================
48
+ // Notification Config Resolution
49
+ // ============================================================================
50
+ /**
51
+ * Resolve a notification configuration by applying spec defaults.
52
+ *
53
+ * @param config - NotificationConfig from the spec
54
+ * @returns Fully resolved notification configuration
55
+ */
56
+ export function resolveNotificationConfig(config) {
57
+ return {
58
+ defaultPosition: config.defaultPosition ?? 'top_right',
59
+ defaultDuration: config.defaultDuration ?? 5000,
60
+ maxVisible: config.maxVisible ?? 5,
61
+ stackDirection: config.stackDirection ?? 'down',
62
+ pauseOnHover: config.pauseOnHover ?? true,
63
+ };
64
+ }
65
+ // ============================================================================
66
+ // Spec Notification → Toast
67
+ // ============================================================================
68
+ /**
69
+ * Extract the display string from a translatable value (string or Translation object).
70
+ */
71
+ function resolveTranslatableString(value) {
72
+ if (value === undefined)
73
+ return undefined;
74
+ if (typeof value === 'string')
75
+ return value;
76
+ return value.defaultValue;
77
+ }
78
+ /**
79
+ * Convert a spec Notification to a toast-compatible object.
80
+ *
81
+ * @param notification - Spec Notification
82
+ * @returns Toast-compatible notification with title, description, variant, etc.
83
+ */
84
+ export function specNotificationToToast(notification) {
85
+ const actions = (notification.actions ?? []).map((a) => ({
86
+ label: typeof a.label === 'string' ? a.label : a.label?.defaultValue ?? '',
87
+ action: a.action,
88
+ variant: a.variant ?? 'primary',
89
+ }));
90
+ return {
91
+ title: resolveTranslatableString(notification.title),
92
+ description: resolveTranslatableString(notification.message) ?? '',
93
+ variant: mapSeverityToVariant(notification.severity ?? 'info'),
94
+ position: mapPosition(notification.position ?? 'top_right'),
95
+ duration: notification.duration ?? 5000,
96
+ dismissible: notification.dismissible ?? true,
97
+ actions,
98
+ };
99
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * @object-ui/core - Responsive Protocol Bridge
10
+ *
11
+ * Converts spec-aligned ResponsiveConfig schemas into Tailwind CSS
12
+ * utility classes for visibility, grid columns, and ordering across
13
+ * breakpoints. Also provides runtime width-based visibility checks.
14
+ *
15
+ * @module protocols/ResponsiveProtocol
16
+ * @packageDocumentation
17
+ */
18
+ import type { SpecResponsiveConfig } from '@object-ui/types';
19
+ /** Breakpoint name type matching Tailwind defaults. */
20
+ export type BreakpointKey = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
21
+ /** Breakpoint minimum pixel widths aligned with Tailwind CSS defaults. */
22
+ export declare const BREAKPOINT_VALUES: Record<BreakpointKey, number>;
23
+ /** Fully resolved responsive configuration. */
24
+ export interface ResolvedResponsiveConfig {
25
+ breakpoint?: BreakpointKey;
26
+ hiddenOn: BreakpointKey[];
27
+ columns: Partial<Record<BreakpointKey, number>>;
28
+ order: Partial<Record<BreakpointKey, number>>;
29
+ }
30
+ /**
31
+ * Resolve a responsive configuration by applying defaults.
32
+ *
33
+ * @param config - SpecResponsiveConfig from the spec
34
+ * @returns Fully resolved responsive configuration
35
+ */
36
+ export declare function resolveResponsiveConfig(config: SpecResponsiveConfig): ResolvedResponsiveConfig;
37
+ /**
38
+ * Generate Tailwind CSS classes for responsive visibility.
39
+ *
40
+ * If `breakpoint` is set, the element is hidden below that breakpoint
41
+ * (e.g. breakpoint "md" → `['hidden', 'md:block']`).
42
+ *
43
+ * If `hiddenOn` contains breakpoints, the element is hidden at those
44
+ * specific sizes (e.g. hiddenOn: ["sm", "lg"] → `['sm:hidden', 'md:block', 'lg:hidden', 'xl:block']`).
45
+ *
46
+ * @param config - SpecResponsiveConfig from the spec
47
+ * @returns Array of Tailwind CSS class strings
48
+ */
49
+ export declare function getVisibilityClasses(config: SpecResponsiveConfig): string[];
50
+ /**
51
+ * Generate Tailwind grid-cols classes for responsive column layouts.
52
+ *
53
+ * @param config - SpecResponsiveConfig from the spec
54
+ * @returns Array of Tailwind CSS grid column class strings
55
+ */
56
+ export declare function getColumnClasses(config: SpecResponsiveConfig): string[];
57
+ /**
58
+ * Generate Tailwind order utility classes for responsive ordering.
59
+ *
60
+ * @param config - SpecResponsiveConfig from the spec
61
+ * @returns Array of Tailwind CSS order class strings
62
+ */
63
+ export declare function getOrderClasses(config: SpecResponsiveConfig): string[];
64
+ /**
65
+ * Determine whether a component should be hidden at a given viewport width.
66
+ *
67
+ * Checks both the minimum `breakpoint` threshold and the `hiddenOn` list.
68
+ *
69
+ * @param config - SpecResponsiveConfig from the spec
70
+ * @param width - Current viewport width in pixels
71
+ * @returns `true` if the component should be hidden at the given width
72
+ */
73
+ export declare function shouldHideAtBreakpoint(config: SpecResponsiveConfig, width: number): boolean;