@object-ui/core 17.6.0 → 17.7.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.
- package/CHANGELOG.md +6610 -0
- package/README.md +101 -14
- package/dist/actions/ActionEngine.d.ts +4 -2
- package/dist/actions/ActionEngine.js +13 -8
- package/dist/actions/ActionRunner.d.ts +288 -27
- package/dist/actions/ActionRunner.js +443 -63
- package/dist/actions/TransactionManager.d.ts +7 -2
- package/dist/actions/actionKeys.d.ts +9 -7
- package/dist/actions/actionKeys.js +57 -14
- package/dist/actions/actionResponse.js +2 -2
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/actions/recordDelete.d.ts +118 -0
- package/dist/actions/recordDelete.js +112 -0
- package/dist/adapters/ValueDataSource.d.ts +6 -1
- package/dist/adapters/ValueDataSource.js +1090 -98
- package/dist/adapters/batchTransaction.d.ts +1 -1
- package/dist/adapters/batchTransaction.js +1 -1
- package/dist/builder/schema-builder.d.ts +38 -81
- package/dist/builder/schema-builder.js +33 -152
- package/dist/data-scope/ViewDataProvider.d.ts +1 -1
- package/dist/data-scope/ViewDataProvider.js +21 -1
- package/dist/data-scope/element-data-source.d.ts +261 -7
- package/dist/data-scope/element-data-source.js +342 -52
- package/dist/data-scope/index.d.ts +9 -4
- package/dist/data-scope/index.js +9 -4
- package/dist/evaluator/ExpressionEvaluator.d.ts +86 -0
- package/dist/evaluator/ExpressionEvaluator.js +184 -12
- package/dist/evaluator/FormulaFunctions.d.ts +0 -10
- package/dist/evaluator/FormulaFunctions.js +166 -27
- package/dist/evaluator/declaredPredicate.d.ts +93 -9
- package/dist/evaluator/declaredPredicate.js +117 -16
- package/dist/evaluator/fieldRules.d.ts +88 -4
- package/dist/evaluator/fieldRules.js +203 -31
- package/dist/evaluator/index.d.ts +1 -0
- package/dist/evaluator/index.js +1 -0
- package/dist/evaluator/listConditional.d.ts +103 -34
- package/dist/evaluator/listConditional.js +127 -50
- package/dist/evaluator/optionRules.d.ts +77 -6
- package/dist/evaluator/optionRules.js +87 -10
- package/dist/evaluator/predicateInput.d.ts +15 -4
- package/dist/evaluator/predicateInput.js +35 -2
- package/dist/evaluator/rowPredicateCanon.d.ts +7 -18
- package/dist/evaluator/rowPredicateCanon.js +65 -115
- package/dist/evaluator/subjectPermissions.d.ts +76 -0
- package/dist/evaluator/subjectPermissions.js +44 -0
- package/dist/evaluator/unevaluablePredicate.d.ts +57 -0
- package/dist/evaluator/unevaluablePredicate.js +70 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +80 -2
- package/dist/protocols/index.d.ts +0 -1
- package/dist/protocols/index.js +9 -1
- package/dist/registry/Registry.d.ts +358 -31
- package/dist/registry/Registry.js +263 -11
- package/dist/registry/WidgetRegistry.js +7 -3
- package/dist/registry/html-tier-intrinsics.d.ts +90 -0
- package/dist/registry/html-tier-intrinsics.js +110 -0
- package/dist/registry/public-blocks.d.ts +8 -0
- package/dist/registry/public-blocks.js +57 -0
- package/dist/theme/ThemeEngine.js +1 -1
- package/dist/utils/chart-category-key.d.ts +82 -0
- package/dist/utils/chart-category-key.js +84 -0
- package/dist/utils/chart-measure-key.d.ts +64 -0
- package/dist/utils/chart-measure-key.js +65 -0
- package/dist/utils/chart-presentation.d.ts +95 -112
- package/dist/utils/chart-presentation.js +169 -104
- package/dist/utils/chart-series.d.ts +131 -5
- package/dist/utils/chart-series.js +98 -16
- package/dist/utils/column-sortability.d.ts +157 -0
- package/dist/utils/column-sortability.js +217 -0
- package/dist/utils/dashboard-filters.d.ts +38 -6
- package/dist/utils/dashboard-filters.js +107 -61
- package/dist/utils/dataset-format.d.ts +211 -30
- package/dist/utils/dataset-format.js +389 -46
- package/dist/utils/date-display.d.ts +354 -0
- package/dist/utils/date-display.js +463 -0
- package/dist/utils/date-macros.js +7 -0
- package/dist/utils/drill-down.d.ts +78 -0
- package/dist/utils/drill-down.js +93 -0
- package/dist/utils/emptiness.d.ts +96 -0
- package/dist/utils/emptiness.js +101 -0
- package/dist/utils/expand-fields.d.ts +76 -6
- package/dist/utils/expand-fields.js +76 -6
- package/dist/utils/extract-records.d.ts +65 -5
- package/dist/utils/extract-records.js +65 -8
- package/dist/utils/filter-converter.d.ts +152 -4
- package/dist/utils/filter-converter.js +1092 -22
- package/dist/utils/filter-tokens.d.ts +49 -5
- package/dist/utils/filter-tokens.js +105 -33
- package/dist/utils/grouping-fields.d.ts +61 -0
- package/dist/utils/grouping-fields.js +84 -0
- package/dist/utils/managedBy.d.ts +3 -3
- package/dist/utils/managedBy.js +5 -5
- package/dist/utils/native-date-value.d.ts +48 -0
- package/dist/utils/native-date-value.js +167 -0
- package/dist/utils/non-grid-row-ceiling.d.ts +143 -0
- package/dist/utils/non-grid-row-ceiling.js +141 -0
- package/dist/utils/normalize-list-view.d.ts +121 -1
- package/dist/utils/normalize-list-view.js +186 -6
- package/dist/utils/number-display.d.ts +63 -14
- package/dist/utils/number-display.js +34 -12
- package/dist/utils/object-aggregate-query.d.ts +113 -0
- package/dist/utils/object-aggregate-query.js +50 -0
- package/dist/utils/parent-scope.d.ts +123 -0
- package/dist/utils/parent-scope.js +140 -0
- package/dist/utils/predicate-fields.d.ts +45 -12
- package/dist/utils/predicate-fields.js +137 -12
- package/dist/utils/record-color.d.ts +75 -0
- package/dist/utils/record-color.js +65 -0
- package/dist/utils/record-source.d.ts +298 -0
- package/dist/utils/record-source.js +331 -0
- package/dist/utils/record-title.d.ts +148 -8
- package/dist/utils/record-title.js +220 -26
- package/dist/utils/reference-keys.d.ts +21 -22
- package/dist/utils/reference-keys.js +532 -29
- package/dist/utils/sort-query.d.ts +115 -15
- package/dist/utils/sort-query.js +240 -13
- package/dist/utils/text-comparand.d.ts +92 -0
- package/dist/utils/text-comparand.js +99 -0
- package/dist/utils/without-denied-fields.d.ts +49 -0
- package/dist/utils/without-denied-fields.js +52 -0
- package/dist/validation/index.d.ts +8 -4
- package/dist/validation/index.js +8 -4
- package/dist/validation/schema-validator.d.ts +1 -1
- package/dist/validation/schema-validator.js +200 -82
- package/dist/validation/validators/object-validation-engine.d.ts +1 -1
- package/dist/validation/validators/object-validation-engine.js +14 -3
- package/package.json +8 -9
- package/dist/data-scope/DataScopeManager.d.ts +0 -127
- package/dist/data-scope/DataScopeManager.js +0 -229
- package/dist/protocols/ResponsiveProtocol.d.ts +0 -73
- package/dist/protocols/ResponsiveProtocol.js +0 -158
- package/dist/validation/validation-engine.d.ts +0 -88
- package/dist/validation/validation-engine.js +0 -434
|
@@ -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
|
-
}
|
|
@@ -1,88 +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 - Validation Engine
|
|
10
|
-
*
|
|
11
|
-
* Phase 3.5: Complete validation engine implementation with support for:
|
|
12
|
-
* - Sync and async validation
|
|
13
|
-
* - Cross-field validation
|
|
14
|
-
* - Custom validation functions
|
|
15
|
-
* - Improved error messages
|
|
16
|
-
*
|
|
17
|
-
* @module validation-engine
|
|
18
|
-
* @packageDocumentation
|
|
19
|
-
*/
|
|
20
|
-
import type { AdvancedValidationSchema, ValidationFunction, AsyncValidationFunction, ValidationContext, AdvancedValidationResult, AdvancedValidationError } from '@object-ui/types';
|
|
21
|
-
/**
|
|
22
|
-
* Validation Engine - Executes validation rules
|
|
23
|
-
*/
|
|
24
|
-
export declare class ValidationEngine {
|
|
25
|
-
private customValidators;
|
|
26
|
-
private customAsyncValidators;
|
|
27
|
-
/**
|
|
28
|
-
* Register a custom synchronous validator by name
|
|
29
|
-
*/
|
|
30
|
-
registerValidator(name: string, fn: ValidationFunction): void;
|
|
31
|
-
/**
|
|
32
|
-
* Register a custom asynchronous validator by name
|
|
33
|
-
*/
|
|
34
|
-
registerAsyncValidator(name: string, fn: AsyncValidationFunction): void;
|
|
35
|
-
/**
|
|
36
|
-
* Check if a custom validator is registered
|
|
37
|
-
*/
|
|
38
|
-
hasValidator(name: string): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Get all registered custom validator names
|
|
41
|
-
*/
|
|
42
|
-
getValidatorNames(): string[];
|
|
43
|
-
/**
|
|
44
|
-
* Validate a value against validation schema
|
|
45
|
-
*/
|
|
46
|
-
validate(value: any, schema: AdvancedValidationSchema, context?: ValidationContext): Promise<AdvancedValidationResult>;
|
|
47
|
-
/**
|
|
48
|
-
* Validate a single rule
|
|
49
|
-
*/
|
|
50
|
-
private validateRule;
|
|
51
|
-
/**
|
|
52
|
-
* Validate built-in rules
|
|
53
|
-
*/
|
|
54
|
-
private validateBuiltInRule;
|
|
55
|
-
/**
|
|
56
|
-
* Evaluate a condition
|
|
57
|
-
* Note: Conditions must be declarative objects, not functions, for security.
|
|
58
|
-
*/
|
|
59
|
-
private evaluateCondition;
|
|
60
|
-
/**
|
|
61
|
-
* Validate multiple fields
|
|
62
|
-
*/
|
|
63
|
-
validateFields(values: Record<string, any>, schemas: Record<string, AdvancedValidationSchema>): Promise<Record<string, AdvancedValidationResult>>;
|
|
64
|
-
/**
|
|
65
|
-
* Check if all fields are valid
|
|
66
|
-
*/
|
|
67
|
-
isValid(results: Record<string, AdvancedValidationResult>): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Get all errors from validation results
|
|
70
|
-
*/
|
|
71
|
-
getAllErrors(results: Record<string, AdvancedValidationResult>): AdvancedValidationError[];
|
|
72
|
-
/**
|
|
73
|
-
* Get all warnings from validation results
|
|
74
|
-
*/
|
|
75
|
-
getAllWarnings(results: Record<string, AdvancedValidationResult>): AdvancedValidationError[];
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Default validation engine instance
|
|
79
|
-
*/
|
|
80
|
-
export declare const defaultValidationEngine: ValidationEngine;
|
|
81
|
-
/**
|
|
82
|
-
* Convenience function to validate a value
|
|
83
|
-
*/
|
|
84
|
-
export declare function validate(value: any, schema: AdvancedValidationSchema, context?: ValidationContext): Promise<AdvancedValidationResult>;
|
|
85
|
-
/**
|
|
86
|
-
* Convenience function to validate multiple fields
|
|
87
|
-
*/
|
|
88
|
-
export declare function validateFields(values: Record<string, any>, schemas: Record<string, AdvancedValidationSchema>): Promise<Record<string, AdvancedValidationResult>>;
|