@object-ui/core 17.6.0 → 18.0.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 (147) hide show
  1. package/CHANGELOG.md +7260 -0
  2. package/README.md +228 -14
  3. package/dist/actions/ActionEngine.d.ts +4 -2
  4. package/dist/actions/ActionEngine.js +13 -8
  5. package/dist/actions/ActionRunner.d.ts +473 -69
  6. package/dist/actions/ActionRunner.js +792 -125
  7. package/dist/actions/TransactionManager.d.ts +7 -2
  8. package/dist/actions/UndoManager.d.ts +8 -13
  9. package/dist/actions/actionKeys.d.ts +9 -7
  10. package/dist/actions/actionKeys.js +67 -14
  11. package/dist/actions/actionResponse.js +2 -2
  12. package/dist/actions/index.d.ts +2 -0
  13. package/dist/actions/index.js +2 -0
  14. package/dist/actions/navigationTarget.d.ts +41 -0
  15. package/dist/actions/navigationTarget.js +20 -0
  16. package/dist/actions/recordDelete.d.ts +154 -0
  17. package/dist/actions/recordDelete.js +110 -0
  18. package/dist/adapters/ApiDataSource.d.ts +8 -4
  19. package/dist/adapters/ApiDataSource.js +19 -7
  20. package/dist/adapters/ValueDataSource.d.ts +6 -1
  21. package/dist/adapters/ValueDataSource.js +1090 -98
  22. package/dist/adapters/batchTransaction.d.ts +1 -1
  23. package/dist/adapters/batchTransaction.js +1 -1
  24. package/dist/adapters/resolveDataSource.d.ts +9 -6
  25. package/dist/adapters/resolveDataSource.js +9 -12
  26. package/dist/builder/schema-builder.d.ts +38 -81
  27. package/dist/builder/schema-builder.js +33 -152
  28. package/dist/data-scope/ViewDataProvider.d.ts +8 -25
  29. package/dist/data-scope/ViewDataProvider.js +27 -54
  30. package/dist/data-scope/element-data-source.d.ts +261 -7
  31. package/dist/data-scope/element-data-source.js +342 -52
  32. package/dist/data-scope/index.d.ts +9 -4
  33. package/dist/data-scope/index.js +9 -4
  34. package/dist/evaluator/ExpressionEvaluator.d.ts +86 -0
  35. package/dist/evaluator/ExpressionEvaluator.js +184 -12
  36. package/dist/evaluator/FormulaFunctions.d.ts +0 -10
  37. package/dist/evaluator/FormulaFunctions.js +166 -27
  38. package/dist/evaluator/deadlineSettled.d.ts +40 -0
  39. package/dist/evaluator/deadlineSettled.js +45 -0
  40. package/dist/evaluator/declaredPredicate.d.ts +93 -9
  41. package/dist/evaluator/declaredPredicate.js +117 -16
  42. package/dist/evaluator/fieldRules.d.ts +88 -4
  43. package/dist/evaluator/fieldRules.js +208 -31
  44. package/dist/evaluator/index.d.ts +2 -0
  45. package/dist/evaluator/index.js +2 -0
  46. package/dist/evaluator/listConditional.d.ts +103 -34
  47. package/dist/evaluator/listConditional.js +127 -50
  48. package/dist/evaluator/optionRules.d.ts +77 -6
  49. package/dist/evaluator/optionRules.js +87 -10
  50. package/dist/evaluator/predicateInput.d.ts +15 -4
  51. package/dist/evaluator/predicateInput.js +35 -2
  52. package/dist/evaluator/rowPredicateCanon.d.ts +7 -18
  53. package/dist/evaluator/rowPredicateCanon.js +65 -115
  54. package/dist/evaluator/subjectPermissions.d.ts +105 -0
  55. package/dist/evaluator/subjectPermissions.js +86 -0
  56. package/dist/evaluator/unevaluablePredicate.d.ts +57 -0
  57. package/dist/evaluator/unevaluablePredicate.js +70 -0
  58. package/dist/index.d.ts +15 -0
  59. package/dist/index.js +83 -2
  60. package/dist/protocols/index.d.ts +0 -1
  61. package/dist/protocols/index.js +9 -1
  62. package/dist/registry/Registry.d.ts +382 -34
  63. package/dist/registry/Registry.js +247 -12
  64. package/dist/registry/WidgetRegistry.js +7 -3
  65. package/dist/registry/html-tier-intrinsics.d.ts +90 -0
  66. package/dist/registry/html-tier-intrinsics.js +110 -0
  67. package/dist/registry/public-blocks.d.ts +8 -0
  68. package/dist/registry/public-blocks.js +57 -0
  69. package/dist/theme/ThemeEngine.js +1 -1
  70. package/dist/utils/affordanceGrants.d.ts +371 -0
  71. package/dist/utils/affordanceGrants.js +252 -0
  72. package/dist/utils/chart-category-key.d.ts +82 -0
  73. package/dist/utils/chart-category-key.js +84 -0
  74. package/dist/utils/chart-measure-key.d.ts +64 -0
  75. package/dist/utils/chart-measure-key.js +65 -0
  76. package/dist/utils/chart-presentation.d.ts +95 -112
  77. package/dist/utils/chart-presentation.js +169 -104
  78. package/dist/utils/chart-series.d.ts +165 -5
  79. package/dist/utils/chart-series.js +123 -18
  80. package/dist/utils/column-sortability.d.ts +157 -0
  81. package/dist/utils/column-sortability.js +217 -0
  82. package/dist/utils/dashboard-filters.d.ts +38 -6
  83. package/dist/utils/dashboard-filters.js +107 -61
  84. package/dist/utils/dataset-format.d.ts +211 -30
  85. package/dist/utils/dataset-format.js +389 -46
  86. package/dist/utils/date-display.d.ts +346 -0
  87. package/dist/utils/date-display.js +644 -0
  88. package/dist/utils/date-macros.js +7 -0
  89. package/dist/utils/drill-down.d.ts +78 -0
  90. package/dist/utils/drill-down.js +93 -0
  91. package/dist/utils/emptiness.d.ts +96 -0
  92. package/dist/utils/emptiness.js +101 -0
  93. package/dist/utils/expand-fields.d.ts +81 -9
  94. package/dist/utils/expand-fields.js +81 -9
  95. package/dist/utils/extract-records.d.ts +65 -5
  96. package/dist/utils/extract-records.js +65 -8
  97. package/dist/utils/filter-converter.d.ts +158 -6
  98. package/dist/utils/filter-converter.js +1098 -24
  99. package/dist/utils/filter-tokens.d.ts +49 -5
  100. package/dist/utils/filter-tokens.js +105 -33
  101. package/dist/utils/grouping-fields.d.ts +61 -0
  102. package/dist/utils/grouping-fields.js +84 -0
  103. package/dist/utils/managedBy.d.ts +3 -3
  104. package/dist/utils/managedBy.js +5 -5
  105. package/dist/utils/native-date-value.d.ts +48 -0
  106. package/dist/utils/native-date-value.js +167 -0
  107. package/dist/utils/non-grid-row-ceiling.d.ts +143 -0
  108. package/dist/utils/non-grid-row-ceiling.js +141 -0
  109. package/dist/utils/normalize-list-view.d.ts +135 -11
  110. package/dist/utils/normalize-list-view.js +243 -64
  111. package/dist/utils/number-display.d.ts +63 -14
  112. package/dist/utils/number-display.js +34 -12
  113. package/dist/utils/object-aggregate-query.d.ts +113 -0
  114. package/dist/utils/object-aggregate-query.js +50 -0
  115. package/dist/utils/parent-scope.d.ts +123 -0
  116. package/dist/utils/parent-scope.js +140 -0
  117. package/dist/utils/predicate-fields.d.ts +45 -12
  118. package/dist/utils/predicate-fields.js +141 -12
  119. package/dist/utils/record-color.d.ts +75 -0
  120. package/dist/utils/record-color.js +65 -0
  121. package/dist/utils/record-source.d.ts +298 -0
  122. package/dist/utils/record-source.js +331 -0
  123. package/dist/utils/record-title.d.ts +148 -8
  124. package/dist/utils/record-title.js +220 -26
  125. package/dist/utils/reference-keys.d.ts +21 -22
  126. package/dist/utils/reference-keys.js +532 -29
  127. package/dist/utils/sort-query.d.ts +115 -15
  128. package/dist/utils/sort-query.js +240 -13
  129. package/dist/utils/text-comparand.d.ts +92 -0
  130. package/dist/utils/text-comparand.js +99 -0
  131. package/dist/utils/without-denied-fields.d.ts +49 -0
  132. package/dist/utils/without-denied-fields.js +52 -0
  133. package/dist/validation/index.d.ts +8 -4
  134. package/dist/validation/index.js +8 -4
  135. package/dist/validation/schema-validator.d.ts +1 -1
  136. package/dist/validation/schema-validator.js +225 -83
  137. package/dist/validation/server-owned-value.d.ts +5 -1
  138. package/dist/validation/server-owned-value.js +5 -1
  139. package/dist/validation/validators/object-validation-engine.d.ts +1 -1
  140. package/dist/validation/validators/object-validation-engine.js +14 -3
  141. package/package.json +8 -9
  142. package/dist/data-scope/DataScopeManager.d.ts +0 -127
  143. package/dist/data-scope/DataScopeManager.js +0 -229
  144. package/dist/protocols/ResponsiveProtocol.d.ts +0 -73
  145. package/dist/protocols/ResponsiveProtocol.js +0 -158
  146. package/dist/validation/validation-engine.d.ts +0 -88
  147. package/dist/validation/validation-engine.js +0 -434
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/core",
3
- "version": "17.6.0",
3
+ "version": "18.0.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -25,15 +25,14 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@objectstack/formula": "^17.0.0",
29
- "@objectstack/spec": "^17.0.0",
30
- "lodash": "^4.18.1",
31
- "zod": "^4.4.3",
32
- "@object-ui/types": "17.6.0"
28
+ "@objectstack/formula": "^18.0.0",
29
+ "@objectstack/spec": "^18.0.0",
30
+ "@object-ui/types": "18.0.0"
33
31
  },
34
32
  "devDependencies": {
35
33
  "typescript": "^6.0.3",
36
- "vitest": "^4.1.10"
34
+ "vitest": "^4.1.10",
35
+ "@object-ui/test-support": "17.4.0"
37
36
  },
38
37
  "keywords": [
39
38
  "objectui",
@@ -60,8 +59,8 @@
60
59
  "LICENSE"
61
60
  ],
62
61
  "scripts": {
63
- "build": "tsc",
64
- "test": "vitest run",
62
+ "build": "tsc && node ../../scripts/check-dist-completeness.mjs",
63
+ "test": "vitest run --root ../.. packages/core/",
65
64
  "type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
66
65
  "lint": "eslint ."
67
66
  }
@@ -1,127 +0,0 @@
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 - DataScope Manager
10
- *
11
- * Runtime implementation of the DataContext interface for managing
12
- * named data scopes. Provides row-level data access control and
13
- * reactive data state management within the UI component tree.
14
- *
15
- * @module data-scope
16
- * @packageDocumentation
17
- */
18
- import type { DataScope, DataContext, DataSource } from '@object-ui/types';
19
- /**
20
- * Row-level filter for restricting data access within a scope
21
- */
22
- export interface RowLevelFilter {
23
- /** Field to filter on */
24
- field: string;
25
- /** Filter operator */
26
- operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'nin' | 'contains';
27
- /** Filter value */
28
- value: any;
29
- }
30
- /**
31
- * Configuration for creating a data scope
32
- */
33
- export interface DataScopeConfig {
34
- /** Data source instance */
35
- dataSource?: DataSource;
36
- /** Initial data */
37
- data?: any;
38
- /** Row-level filters to apply */
39
- filters?: RowLevelFilter[];
40
- /** Whether this scope is read-only */
41
- readOnly?: boolean;
42
- }
43
- /**
44
- * DataScopeManager — Runtime implementation of DataContext.
45
- *
46
- * Manages named data scopes for the component tree, providing:
47
- * - Scope registration and lookup
48
- * - Row-level security via filters
49
- * - Data state management (data, loading, error)
50
- *
51
- * @example
52
- * ```ts
53
- * const manager = new DataScopeManager();
54
- * manager.registerScope('contacts', {
55
- * dataSource: myDataSource,
56
- * data: [],
57
- * });
58
- * const scope = manager.getScope('contacts');
59
- * ```
60
- */
61
- export declare class DataScopeManager implements DataContext {
62
- scopes: Record<string, DataScope>;
63
- private filters;
64
- private readOnlyScopes;
65
- private listeners;
66
- /**
67
- * Register a data scope
68
- */
69
- registerScope(name: string, scope: DataScope): void;
70
- /**
71
- * Register a data scope with configuration
72
- */
73
- registerScopeWithConfig(name: string, config: DataScopeConfig): void;
74
- /**
75
- * Get a data scope by name
76
- */
77
- getScope(name: string): DataScope | undefined;
78
- /**
79
- * Remove a data scope
80
- */
81
- removeScope(name: string): void;
82
- /**
83
- * Check if a scope is read-only
84
- */
85
- isReadOnly(name: string): boolean;
86
- /**
87
- * Get row-level filters for a scope
88
- */
89
- getFilters(name: string): RowLevelFilter[];
90
- /**
91
- * Set row-level filters for a scope
92
- */
93
- setFilters(name: string, filters: RowLevelFilter[]): void;
94
- /**
95
- * Apply row-level filters to a dataset
96
- */
97
- applyFilters(name: string, data: any[]): any[];
98
- /**
99
- * Update data in a scope
100
- */
101
- updateScopeData(name: string, data: any): void;
102
- /**
103
- * Update loading state for a scope
104
- */
105
- updateScopeLoading(name: string, loading: boolean): void;
106
- /**
107
- * Update error state for a scope
108
- */
109
- updateScopeError(name: string, error: Error | string | null): void;
110
- /**
111
- * Subscribe to scope changes
112
- */
113
- onScopeChange(name: string, listener: (scope: DataScope) => void): () => void;
114
- /**
115
- * Get all registered scope names
116
- */
117
- getScopeNames(): string[];
118
- /**
119
- * Clear all scopes
120
- */
121
- clear(): void;
122
- private notifyListeners;
123
- }
124
- /**
125
- * Default DataScopeManager instance
126
- */
127
- export declare const defaultDataScopeManager: DataScopeManager;
@@ -1,229 +0,0 @@
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
- * DataScopeManager — Runtime implementation of DataContext.
10
- *
11
- * Manages named data scopes for the component tree, providing:
12
- * - Scope registration and lookup
13
- * - Row-level security via filters
14
- * - Data state management (data, loading, error)
15
- *
16
- * @example
17
- * ```ts
18
- * const manager = new DataScopeManager();
19
- * manager.registerScope('contacts', {
20
- * dataSource: myDataSource,
21
- * data: [],
22
- * });
23
- * const scope = manager.getScope('contacts');
24
- * ```
25
- */
26
- export class DataScopeManager {
27
- constructor() {
28
- Object.defineProperty(this, "scopes", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: {}
33
- });
34
- Object.defineProperty(this, "filters", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: {}
39
- });
40
- Object.defineProperty(this, "readOnlyScopes", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: new Set()
45
- });
46
- Object.defineProperty(this, "listeners", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: new Map()
51
- });
52
- }
53
- /**
54
- * Register a data scope
55
- */
56
- registerScope(name, scope) {
57
- this.scopes[name] = scope;
58
- this.notifyListeners(name, scope);
59
- }
60
- /**
61
- * Register a data scope with configuration
62
- */
63
- registerScopeWithConfig(name, config) {
64
- const scope = {
65
- dataSource: config.dataSource,
66
- data: config.data,
67
- loading: false,
68
- error: null,
69
- };
70
- if (config.filters) {
71
- this.filters[name] = config.filters;
72
- }
73
- if (config.readOnly) {
74
- this.readOnlyScopes.add(name);
75
- }
76
- this.scopes[name] = scope;
77
- this.notifyListeners(name, scope);
78
- }
79
- /**
80
- * Get a data scope by name
81
- */
82
- getScope(name) {
83
- return this.scopes[name];
84
- }
85
- /**
86
- * Remove a data scope
87
- */
88
- removeScope(name) {
89
- delete this.scopes[name];
90
- delete this.filters[name];
91
- this.readOnlyScopes.delete(name);
92
- this.listeners.delete(name);
93
- }
94
- /**
95
- * Check if a scope is read-only
96
- */
97
- isReadOnly(name) {
98
- return this.readOnlyScopes.has(name);
99
- }
100
- /**
101
- * Get row-level filters for a scope
102
- */
103
- getFilters(name) {
104
- return this.filters[name] || [];
105
- }
106
- /**
107
- * Set row-level filters for a scope
108
- */
109
- setFilters(name, filters) {
110
- this.filters[name] = filters;
111
- }
112
- /**
113
- * Apply row-level filters to a dataset
114
- */
115
- applyFilters(name, data) {
116
- const scopeFilters = this.filters[name];
117
- if (!scopeFilters || scopeFilters.length === 0) {
118
- return data;
119
- }
120
- return data.filter(row => {
121
- return scopeFilters.every(filter => {
122
- const fieldValue = row[filter.field];
123
- return evaluateFilter(fieldValue, filter.operator, filter.value);
124
- });
125
- });
126
- }
127
- /**
128
- * Update data in a scope
129
- */
130
- updateScopeData(name, data) {
131
- const scope = this.scopes[name];
132
- if (!scope)
133
- return;
134
- if (this.readOnlyScopes.has(name)) {
135
- throw new Error(`Cannot update read-only scope: ${name}`);
136
- }
137
- scope.data = data;
138
- this.notifyListeners(name, scope);
139
- }
140
- /**
141
- * Update loading state for a scope
142
- */
143
- updateScopeLoading(name, loading) {
144
- const scope = this.scopes[name];
145
- if (!scope)
146
- return;
147
- scope.loading = loading;
148
- this.notifyListeners(name, scope);
149
- }
150
- /**
151
- * Update error state for a scope
152
- */
153
- updateScopeError(name, error) {
154
- const scope = this.scopes[name];
155
- if (!scope)
156
- return;
157
- scope.error = error;
158
- this.notifyListeners(name, scope);
159
- }
160
- /**
161
- * Subscribe to scope changes
162
- */
163
- onScopeChange(name, listener) {
164
- if (!this.listeners.has(name)) {
165
- this.listeners.set(name, []);
166
- }
167
- this.listeners.get(name).push(listener);
168
- return () => {
169
- const arr = this.listeners.get(name);
170
- if (arr) {
171
- const idx = arr.indexOf(listener);
172
- if (idx >= 0)
173
- arr.splice(idx, 1);
174
- }
175
- };
176
- }
177
- /**
178
- * Get all registered scope names
179
- */
180
- getScopeNames() {
181
- return Object.keys(this.scopes);
182
- }
183
- /**
184
- * Clear all scopes
185
- */
186
- clear() {
187
- this.scopes = {};
188
- this.filters = {};
189
- this.readOnlyScopes.clear();
190
- this.listeners.clear();
191
- }
192
- notifyListeners(name, scope) {
193
- const arr = this.listeners.get(name);
194
- if (arr) {
195
- arr.forEach(listener => listener(scope));
196
- }
197
- }
198
- }
199
- /**
200
- * Evaluate a single filter condition against a field value
201
- */
202
- function evaluateFilter(fieldValue, operator, filterValue) {
203
- switch (operator) {
204
- case 'eq':
205
- return fieldValue === filterValue;
206
- case 'ne':
207
- return fieldValue !== filterValue;
208
- case 'gt':
209
- return fieldValue > filterValue;
210
- case 'lt':
211
- return fieldValue < filterValue;
212
- case 'gte':
213
- return fieldValue >= filterValue;
214
- case 'lte':
215
- return fieldValue <= filterValue;
216
- case 'in':
217
- return Array.isArray(filterValue) && filterValue.includes(fieldValue);
218
- case 'nin':
219
- return Array.isArray(filterValue) && !filterValue.includes(fieldValue);
220
- case 'contains':
221
- return typeof fieldValue === 'string' && fieldValue.includes(String(filterValue));
222
- default:
223
- return true;
224
- }
225
- }
226
- /**
227
- * Default DataScopeManager instance
228
- */
229
- export const defaultDataScopeManager = new DataScopeManager();
@@ -1,73 +0,0 @@
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;
@@ -1,158 +0,0 @@
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
- /** Breakpoint minimum pixel widths aligned with Tailwind CSS defaults. */
9
- export const BREAKPOINT_VALUES = {
10
- xs: 0,
11
- sm: 640,
12
- md: 768,
13
- lg: 1024,
14
- xl: 1280,
15
- '2xl': 1536,
16
- };
17
- /** Ordered breakpoint keys from smallest to largest. */
18
- const BREAKPOINT_ORDER = ['xs', 'sm', 'md', 'lg', 'xl', '2xl'];
19
- // ============================================================================
20
- // Config Resolution
21
- // ============================================================================
22
- /**
23
- * Resolve a responsive configuration by applying defaults.
24
- *
25
- * @param config - SpecResponsiveConfig from the spec
26
- * @returns Fully resolved responsive configuration
27
- */
28
- export function resolveResponsiveConfig(config) {
29
- return {
30
- breakpoint: config.breakpoint,
31
- hiddenOn: (config.hiddenOn ?? []),
32
- columns: (config.columns ?? {}),
33
- order: (config.order ?? {}),
34
- };
35
- }
36
- // ============================================================================
37
- // Visibility Classes
38
- // ============================================================================
39
- /**
40
- * Generate Tailwind CSS classes for responsive visibility.
41
- *
42
- * If `breakpoint` is set, the element is hidden below that breakpoint
43
- * (e.g. breakpoint "md" → `['hidden', 'md:block']`).
44
- *
45
- * If `hiddenOn` contains breakpoints, the element is hidden at those
46
- * specific sizes (e.g. hiddenOn: ["sm", "lg"] → `['sm:hidden', 'md:block', 'lg:hidden', 'xl:block']`).
47
- *
48
- * @param config - SpecResponsiveConfig from the spec
49
- * @returns Array of Tailwind CSS class strings
50
- */
51
- export function getVisibilityClasses(config) {
52
- const classes = [];
53
- // Minimum breakpoint visibility
54
- if (config.breakpoint) {
55
- const bp = config.breakpoint;
56
- if (bp !== 'xs') {
57
- classes.push('hidden');
58
- classes.push(`${bp}:block`);
59
- }
60
- }
61
- // Per-breakpoint hidden overrides
62
- const hiddenOn = (config.hiddenOn ?? []);
63
- if (hiddenOn.length > 0) {
64
- for (let i = 0; i < BREAKPOINT_ORDER.length; i++) {
65
- const bp = BREAKPOINT_ORDER[i];
66
- const isHidden = hiddenOn.includes(bp);
67
- const prevHidden = i > 0 ? hiddenOn.includes(BREAKPOINT_ORDER[i - 1]) : false;
68
- if (isHidden && !prevHidden) {
69
- classes.push(bp === 'xs' ? 'hidden' : `${bp}:hidden`);
70
- }
71
- else if (!isHidden && prevHidden) {
72
- classes.push(bp === 'xs' ? 'block' : `${bp}:block`);
73
- }
74
- }
75
- }
76
- return classes;
77
- }
78
- // ============================================================================
79
- // Column Classes
80
- // ============================================================================
81
- /**
82
- * Generate Tailwind grid-cols classes for responsive column layouts.
83
- *
84
- * @param config - SpecResponsiveConfig from the spec
85
- * @returns Array of Tailwind CSS grid column class strings
86
- */
87
- export function getColumnClasses(config) {
88
- const classes = [];
89
- const columns = (config.columns ?? {});
90
- for (const bp of BREAKPOINT_ORDER) {
91
- const cols = columns[bp];
92
- if (cols == null)
93
- continue;
94
- const prefix = bp === 'xs' ? '' : `${bp}:`;
95
- classes.push(`${prefix}grid-cols-${cols}`);
96
- }
97
- return classes;
98
- }
99
- // ============================================================================
100
- // Order Classes
101
- // ============================================================================
102
- /**
103
- * Generate Tailwind order utility classes for responsive ordering.
104
- *
105
- * @param config - SpecResponsiveConfig from the spec
106
- * @returns Array of Tailwind CSS order class strings
107
- */
108
- export function getOrderClasses(config) {
109
- const classes = [];
110
- const order = (config.order ?? {});
111
- for (const bp of BREAKPOINT_ORDER) {
112
- const ord = order[bp];
113
- if (ord == null)
114
- continue;
115
- const prefix = bp === 'xs' ? '' : `${bp}:`;
116
- classes.push(`${prefix}order-${ord}`);
117
- }
118
- return classes;
119
- }
120
- // ============================================================================
121
- // Runtime Width Check
122
- // ============================================================================
123
- /**
124
- * Determine whether a component should be hidden at a given viewport width.
125
- *
126
- * Checks both the minimum `breakpoint` threshold and the `hiddenOn` list.
127
- *
128
- * @param config - SpecResponsiveConfig from the spec
129
- * @param width - Current viewport width in pixels
130
- * @returns `true` if the component should be hidden at the given width
131
- */
132
- export function shouldHideAtBreakpoint(config, width) {
133
- // Check minimum breakpoint
134
- if (config.breakpoint) {
135
- const minWidth = BREAKPOINT_VALUES[config.breakpoint];
136
- if (minWidth !== undefined && width < minWidth) {
137
- return true;
138
- }
139
- }
140
- // Check hiddenOn list
141
- const hiddenOn = (config.hiddenOn ?? []);
142
- if (hiddenOn.length > 0) {
143
- const currentBp = getCurrentBreakpoint(width);
144
- return hiddenOn.includes(currentBp);
145
- }
146
- return false;
147
- }
148
- /**
149
- * Determine the current breakpoint name for a given width.
150
- */
151
- function getCurrentBreakpoint(width) {
152
- for (let i = BREAKPOINT_ORDER.length - 1; i >= 0; i--) {
153
- if (width >= BREAKPOINT_VALUES[BREAKPOINT_ORDER[i]]) {
154
- return BREAKPOINT_ORDER[i];
155
- }
156
- }
157
- return 'xs';
158
- }