@object-ui/core 3.1.5 → 3.3.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.
- package/CHANGELOG.md +18 -0
- package/README.md +20 -1
- package/dist/actions/ActionRunner.d.ts +9 -0
- package/dist/actions/ActionRunner.js +41 -4
- package/dist/adapters/ValueDataSource.d.ts +5 -1
- package/dist/adapters/ValueDataSource.js +30 -1
- package/dist/errors/index.js +2 -3
- package/dist/evaluator/ExpressionCache.d.ts +9 -10
- package/dist/evaluator/ExpressionCache.js +29 -8
- package/dist/evaluator/SafeExpressionParser.d.ts +131 -0
- package/dist/evaluator/SafeExpressionParser.js +851 -0
- package/dist/evaluator/index.d.ts +1 -0
- package/dist/evaluator/index.js +1 -0
- package/dist/protocols/DndProtocol.js +2 -14
- package/dist/protocols/KeyboardProtocol.js +1 -4
- package/dist/protocols/NotificationProtocol.js +3 -13
- package/dist/utils/debug.js +2 -1
- package/dist/utils/filter-converter.js +25 -5
- package/package.json +33 -9
- package/.turbo/turbo-build.log +0 -4
- package/src/__benchmarks__/core.bench.ts +0 -64
- package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
- package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
- package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
- package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
- package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
- package/src/actions/ActionEngine.ts +0 -268
- package/src/actions/ActionRunner.ts +0 -717
- package/src/actions/TransactionManager.ts +0 -521
- package/src/actions/UndoManager.ts +0 -215
- package/src/actions/__tests__/ActionEngine.test.ts +0 -206
- package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
- package/src/actions/__tests__/ActionRunner.test.ts +0 -711
- package/src/actions/__tests__/TransactionManager.test.ts +0 -447
- package/src/actions/__tests__/UndoManager.test.ts +0 -320
- package/src/actions/index.ts +0 -12
- package/src/adapters/ApiDataSource.ts +0 -376
- package/src/adapters/README.md +0 -180
- package/src/adapters/ValueDataSource.ts +0 -438
- package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
- package/src/adapters/__tests__/ValueDataSource.test.ts +0 -472
- package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
- package/src/adapters/index.ts +0 -15
- package/src/adapters/resolveDataSource.ts +0 -79
- package/src/builder/__tests__/schema-builder.test.ts +0 -235
- package/src/builder/schema-builder.ts +0 -584
- package/src/data-scope/DataScopeManager.ts +0 -269
- package/src/data-scope/ViewDataProvider.ts +0 -282
- package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
- package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
- package/src/data-scope/index.ts +0 -24
- package/src/errors/__tests__/errors.test.ts +0 -292
- package/src/errors/index.ts +0 -270
- package/src/evaluator/ExpressionCache.ts +0 -192
- package/src/evaluator/ExpressionContext.ts +0 -118
- package/src/evaluator/ExpressionEvaluator.ts +0 -315
- package/src/evaluator/FormulaFunctions.ts +0 -398
- package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
- package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
- package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -131
- package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
- package/src/evaluator/index.ts +0 -12
- package/src/index.ts +0 -38
- package/src/protocols/DndProtocol.ts +0 -184
- package/src/protocols/KeyboardProtocol.ts +0 -185
- package/src/protocols/NotificationProtocol.ts +0 -159
- package/src/protocols/ResponsiveProtocol.ts +0 -210
- package/src/protocols/SharingProtocol.ts +0 -185
- package/src/protocols/index.ts +0 -13
- package/src/query/__tests__/query-ast.test.ts +0 -211
- package/src/query/__tests__/window-functions.test.ts +0 -275
- package/src/query/index.ts +0 -7
- package/src/query/query-ast.ts +0 -341
- package/src/registry/PluginScopeImpl.ts +0 -259
- package/src/registry/PluginSystem.ts +0 -206
- package/src/registry/Registry.ts +0 -219
- package/src/registry/WidgetRegistry.ts +0 -316
- package/src/registry/__tests__/PluginSystem.test.ts +0 -309
- package/src/registry/__tests__/Registry.test.ts +0 -293
- package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
- package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
- package/src/theme/ThemeEngine.ts +0 -530
- package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
- package/src/theme/index.ts +0 -24
- package/src/types/index.ts +0 -21
- package/src/utils/__tests__/debug-collector.test.ts +0 -102
- package/src/utils/__tests__/debug.test.ts +0 -134
- package/src/utils/__tests__/expand-fields.test.ts +0 -120
- package/src/utils/__tests__/extract-records.test.ts +0 -50
- package/src/utils/__tests__/filter-converter.test.ts +0 -118
- package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
- package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
- package/src/utils/debug-collector.ts +0 -100
- package/src/utils/debug.ts +0 -147
- package/src/utils/expand-fields.ts +0 -76
- package/src/utils/extract-records.ts +0 -33
- package/src/utils/filter-converter.ts +0 -133
- package/src/utils/merge-views-into-objects.ts +0 -36
- package/src/utils/normalize-quick-filter.ts +0 -78
- package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
- package/src/validation/__tests__/schema-validator.test.ts +0 -118
- package/src/validation/__tests__/validation-engine.test.ts +0 -102
- package/src/validation/index.ts +0 -10
- package/src/validation/schema-validator.ts +0 -344
- package/src/validation/validation-engine.ts +0 -528
- package/src/validation/validators/index.ts +0 -25
- package/src/validation/validators/object-validation-engine.ts +0 -722
- package/tsconfig.json +0 -15
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -2
package/dist/evaluator/index.js
CHANGED
|
@@ -35,16 +35,10 @@ export function resolveDndConfig(config) {
|
|
|
35
35
|
* @returns Component props object for a draggable element
|
|
36
36
|
*/
|
|
37
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
38
|
return {
|
|
45
39
|
draggable: !(item.disabled ?? false),
|
|
46
40
|
'aria-roledescription': 'draggable',
|
|
47
|
-
'aria-label': ariaLabel ?? label,
|
|
41
|
+
'aria-label': item.ariaLabel ?? item.label,
|
|
48
42
|
'aria-describedby': item.ariaDescribedBy,
|
|
49
43
|
role: item.role ?? 'listitem',
|
|
50
44
|
'data-drag-type': item.type,
|
|
@@ -63,15 +57,9 @@ export function createDragItemProps(item) {
|
|
|
63
57
|
* @returns Component props object for a droppable area
|
|
64
58
|
*/
|
|
65
59
|
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
60
|
return {
|
|
73
61
|
'aria-dropeffect': zone.dropEffect ?? 'move',
|
|
74
|
-
'aria-label': ariaLabel ?? label,
|
|
62
|
+
'aria-label': zone.ariaLabel ?? zone.label,
|
|
75
63
|
'aria-describedby': zone.ariaDescribedBy,
|
|
76
64
|
role: zone.role ?? 'list',
|
|
77
65
|
'data-drop-accept': zone.accept.join(','),
|
|
@@ -15,14 +15,11 @@
|
|
|
15
15
|
* @returns Fully resolved keyboard navigation configuration
|
|
16
16
|
*/
|
|
17
17
|
export function resolveKeyboardConfig(config) {
|
|
18
|
-
const ariaLabel = typeof config.ariaLabel === 'string'
|
|
19
|
-
? config.ariaLabel
|
|
20
|
-
: config.ariaLabel?.defaultValue;
|
|
21
18
|
return {
|
|
22
19
|
shortcuts: config.shortcuts ?? [],
|
|
23
20
|
focusManagement: resolveFocusManagement(config.focusManagement),
|
|
24
21
|
rovingTabindex: config.rovingTabindex ?? false,
|
|
25
|
-
ariaLabel,
|
|
22
|
+
ariaLabel: config.ariaLabel,
|
|
26
23
|
ariaDescribedBy: config.ariaDescribedBy,
|
|
27
24
|
role: config.role,
|
|
28
25
|
};
|
|
@@ -65,16 +65,6 @@ export function resolveNotificationConfig(config) {
|
|
|
65
65
|
// ============================================================================
|
|
66
66
|
// Spec Notification → Toast
|
|
67
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
68
|
/**
|
|
79
69
|
* Convert a spec Notification to a toast-compatible object.
|
|
80
70
|
*
|
|
@@ -83,13 +73,13 @@ function resolveTranslatableString(value) {
|
|
|
83
73
|
*/
|
|
84
74
|
export function specNotificationToToast(notification) {
|
|
85
75
|
const actions = (notification.actions ?? []).map((a) => ({
|
|
86
|
-
label:
|
|
76
|
+
label: a.label,
|
|
87
77
|
action: a.action,
|
|
88
78
|
variant: a.variant ?? 'primary',
|
|
89
79
|
}));
|
|
90
80
|
return {
|
|
91
|
-
title:
|
|
92
|
-
description:
|
|
81
|
+
title: notification.title,
|
|
82
|
+
description: notification.message ?? '',
|
|
93
83
|
variant: mapSeverityToVariant(notification.severity ?? 'info'),
|
|
94
84
|
position: mapPosition(notification.position ?? 'top_right'),
|
|
95
85
|
duration: notification.duration ?? 5000,
|
package/dist/utils/debug.js
CHANGED
|
@@ -66,7 +66,8 @@ export function isDebugEnabled() {
|
|
|
66
66
|
if (g === true || g === 'true')
|
|
67
67
|
return true;
|
|
68
68
|
// 3. process.env
|
|
69
|
-
|
|
69
|
+
const proc = globalThis.process;
|
|
70
|
+
if (proc?.env?.OBJECTUI_DEBUG === 'true')
|
|
70
71
|
return true;
|
|
71
72
|
return false;
|
|
72
73
|
}
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* @returns ObjectStack operator or null if not recognized
|
|
13
13
|
*/
|
|
14
14
|
export function convertOperatorToAST(operator) {
|
|
15
|
+
// Spec reference: framework/packages/spec/src/data/filter.zod.ts
|
|
16
|
+
// Canonical MongoDB-style keys are camelCase ($startsWith, $endsWith, $notContains).
|
|
17
|
+
// Lowercase aliases are accepted for tolerance.
|
|
15
18
|
const operatorMap = {
|
|
16
19
|
'$eq': '=',
|
|
17
20
|
'$ne': '!=',
|
|
@@ -20,11 +23,16 @@ export function convertOperatorToAST(operator) {
|
|
|
20
23
|
'$lt': '<',
|
|
21
24
|
'$lte': '<=',
|
|
22
25
|
'$in': 'in',
|
|
23
|
-
'$nin': '
|
|
24
|
-
'$notin': '
|
|
26
|
+
'$nin': 'nin',
|
|
27
|
+
'$notin': 'nin',
|
|
28
|
+
'$between': 'between',
|
|
25
29
|
'$contains': 'contains',
|
|
30
|
+
'$notContains': 'notcontains',
|
|
31
|
+
'$notcontains': 'notcontains',
|
|
32
|
+
'$startsWith': 'startswith',
|
|
26
33
|
'$startswith': 'startswith',
|
|
27
|
-
'$
|
|
34
|
+
'$endsWith': 'endswith',
|
|
35
|
+
'$endswith': 'endswith',
|
|
28
36
|
};
|
|
29
37
|
return operatorMap[operator] || null;
|
|
30
38
|
}
|
|
@@ -66,10 +74,21 @@ export function convertFiltersToAST(filter) {
|
|
|
66
74
|
console.warn(`[ObjectUI] Warning: $regex operator is not fully supported. ` +
|
|
67
75
|
`Converting to 'contains' which only supports substring matching, not regex patterns. ` +
|
|
68
76
|
`Field: '${field}', Value: ${JSON.stringify(operatorValue)}. ` +
|
|
69
|
-
`Consider using $contains or $
|
|
77
|
+
`Consider using $contains or $startsWith instead.`);
|
|
70
78
|
conditions.push([field, 'contains', operatorValue]);
|
|
71
79
|
continue;
|
|
72
80
|
}
|
|
81
|
+
// $null / $exists translate based on their boolean value (per spec semantics).
|
|
82
|
+
// $null: true → IS NULL | $null: false → IS NOT NULL
|
|
83
|
+
// $exists: true → IS NOT NULL | $exists: false → IS NULL
|
|
84
|
+
if (operator === '$null') {
|
|
85
|
+
conditions.push([field, operatorValue ? 'is_null' : 'is_not_null', true]);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (operator === '$exists') {
|
|
89
|
+
conditions.push([field, operatorValue ? 'is_not_null' : 'is_null', true]);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
73
92
|
const astOperator = convertOperatorToAST(operator);
|
|
74
93
|
if (astOperator) {
|
|
75
94
|
conditions.push([field, astOperator, operatorValue]);
|
|
@@ -77,7 +96,8 @@ export function convertFiltersToAST(filter) {
|
|
|
77
96
|
else {
|
|
78
97
|
// Unknown operator - throw error to avoid silent failure
|
|
79
98
|
throw new Error(`[ObjectUI] Unknown filter operator '${operator}' for field '${field}'. ` +
|
|
80
|
-
`Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $
|
|
99
|
+
`Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $between, ` +
|
|
100
|
+
`$contains, $notContains, $startsWith, $endsWith, $null, $exists. ` +
|
|
81
101
|
`If you need exact object matching, use the value directly without an operator.`);
|
|
82
102
|
}
|
|
83
103
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/core",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Core logic, types, and validation for Object UI. Zero React dependencies.",
|
|
8
|
-
"homepage": "https://www.objectui.org",
|
|
8
|
+
"homepage": "https://www.objectui.org/docs/core",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/objectstack-ai/objectui.git",
|
|
11
|
+
"url": "git+https://github.com/objectstack-ai/objectui.git",
|
|
12
12
|
"directory": "packages/core"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
@@ -25,15 +25,39 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@objectstack/spec": "^
|
|
29
|
-
"lodash": "^4.
|
|
30
|
-
"zod": "^4.3
|
|
31
|
-
"@object-ui/types": "3.1
|
|
28
|
+
"@objectstack/spec": "^4.0.4",
|
|
29
|
+
"lodash": "^4.18.1",
|
|
30
|
+
"zod": "^4.4.3",
|
|
31
|
+
"@object-ui/types": "3.3.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"typescript": "^
|
|
35
|
-
"vitest": "^4.1.
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vitest": "^4.1.5"
|
|
36
36
|
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"objectui",
|
|
39
|
+
"sdui",
|
|
40
|
+
"schema-driven-ui",
|
|
41
|
+
"react",
|
|
42
|
+
"tailwind",
|
|
43
|
+
"shadcn",
|
|
44
|
+
"objectstack",
|
|
45
|
+
"core",
|
|
46
|
+
"engine",
|
|
47
|
+
"expression-engine",
|
|
48
|
+
"action-engine",
|
|
49
|
+
"registry"
|
|
50
|
+
],
|
|
51
|
+
"author": "ObjectStack Team <team@objectstack.ai>",
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist",
|
|
57
|
+
"README.md",
|
|
58
|
+
"CHANGELOG.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
],
|
|
37
61
|
"scripts": {
|
|
38
62
|
"build": "tsc",
|
|
39
63
|
"test": "vitest run",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,64 +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
|
-
/**
|
|
10
|
-
* Performance benchmark suite for @object-ui/core.
|
|
11
|
-
*
|
|
12
|
-
* Part of Q1 2026 roadmap §1.4 Test Coverage Improvement.
|
|
13
|
-
*
|
|
14
|
-
* Run with: npx vitest bench packages/core/src/__benchmarks__/
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { bench, describe } from 'vitest';
|
|
18
|
-
import { ExpressionEvaluator } from '@object-ui/core';
|
|
19
|
-
import { ComponentRegistry } from '@object-ui/core';
|
|
20
|
-
import { contrastRatio, meetsContrastLevel, hexToHSL } from '@object-ui/core';
|
|
21
|
-
|
|
22
|
-
describe('ExpressionEvaluator performance', () => {
|
|
23
|
-
const evaluator = new ExpressionEvaluator({ data: { name: 'Alice', age: 30, active: true } });
|
|
24
|
-
|
|
25
|
-
bench('evaluate simple string', () => {
|
|
26
|
-
evaluator.evaluate('Hello ${data.name}');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
bench('evaluate 100 expressions', () => {
|
|
30
|
-
for (let i = 0; i < 100; i++) {
|
|
31
|
-
evaluator.evaluate('Hello ${data.name}');
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('ComponentRegistry performance', () => {
|
|
37
|
-
bench('get registered component', () => {
|
|
38
|
-
ComponentRegistry.get('button');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
bench('has check', () => {
|
|
42
|
-
ComponentRegistry.has('button');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('Theme utilities performance', () => {
|
|
47
|
-
bench('hexToHSL conversion', () => {
|
|
48
|
-
hexToHSL('#336699');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
bench('contrastRatio calculation', () => {
|
|
52
|
-
contrastRatio('#000000', '#ffffff');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
bench('meetsContrastLevel check', () => {
|
|
56
|
-
meetsContrastLevel('#000000', '#ffffff', 'AA');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
bench('100 contrast checks', () => {
|
|
60
|
-
for (let i = 0; i < 100; i++) {
|
|
61
|
-
meetsContrastLevel('#336699', '#ffffff', 'AA');
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import type { DndConfig, DragItem, DropZone, DragConstraint } from '@object-ui/types';
|
|
3
|
-
import {
|
|
4
|
-
resolveDndConfig,
|
|
5
|
-
createDragItemProps,
|
|
6
|
-
createDropZoneProps,
|
|
7
|
-
resolveDragConstraints,
|
|
8
|
-
} from '../../protocols/DndProtocol';
|
|
9
|
-
|
|
10
|
-
describe('DndProtocol', () => {
|
|
11
|
-
// ==========================================================================
|
|
12
|
-
// resolveDndConfig
|
|
13
|
-
// ==========================================================================
|
|
14
|
-
describe('resolveDndConfig', () => {
|
|
15
|
-
it('should apply all defaults for minimal config', () => {
|
|
16
|
-
const config = {} as DndConfig;
|
|
17
|
-
const resolved = resolveDndConfig(config);
|
|
18
|
-
|
|
19
|
-
expect(resolved.enabled).toBe(false);
|
|
20
|
-
expect(resolved.sortable).toBe(false);
|
|
21
|
-
expect(resolved.autoScroll).toBe(true);
|
|
22
|
-
expect(resolved.touchDelay).toBe(200);
|
|
23
|
-
expect(resolved.dragItem).toBeUndefined();
|
|
24
|
-
expect(resolved.dropZone).toBeUndefined();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should preserve explicit values', () => {
|
|
28
|
-
const config = {
|
|
29
|
-
enabled: true,
|
|
30
|
-
sortable: true,
|
|
31
|
-
autoScroll: false,
|
|
32
|
-
touchDelay: 500,
|
|
33
|
-
} as DndConfig;
|
|
34
|
-
const resolved = resolveDndConfig(config);
|
|
35
|
-
|
|
36
|
-
expect(resolved.enabled).toBe(true);
|
|
37
|
-
expect(resolved.sortable).toBe(true);
|
|
38
|
-
expect(resolved.autoScroll).toBe(false);
|
|
39
|
-
expect(resolved.touchDelay).toBe(500);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should pass through dragItem and dropZone', () => {
|
|
43
|
-
const dragItem = { type: 'card' } as DragItem;
|
|
44
|
-
const dropZone = { accept: ['card'] } as DropZone;
|
|
45
|
-
const config = { dragItem, dropZone } as DndConfig;
|
|
46
|
-
const resolved = resolveDndConfig(config);
|
|
47
|
-
|
|
48
|
-
expect(resolved.dragItem).toBe(dragItem);
|
|
49
|
-
expect(resolved.dropZone).toBe(dropZone);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// ==========================================================================
|
|
54
|
-
// createDragItemProps
|
|
55
|
-
// ==========================================================================
|
|
56
|
-
describe('createDragItemProps', () => {
|
|
57
|
-
it('should return correct props for a basic drag item', () => {
|
|
58
|
-
const item = { type: 'card', label: 'Task card' } as DragItem;
|
|
59
|
-
const props = createDragItemProps(item);
|
|
60
|
-
|
|
61
|
-
expect(props.draggable).toBe(true);
|
|
62
|
-
expect(props['aria-roledescription']).toBe('draggable');
|
|
63
|
-
expect(props['aria-label']).toBe('Task card');
|
|
64
|
-
expect(props.role).toBe('listitem');
|
|
65
|
-
expect(props['data-drag-type']).toBe('card');
|
|
66
|
-
expect(props['data-drag-handle']).toBe('element');
|
|
67
|
-
expect(props['data-drag-disabled']).toBe('false');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should set draggable false when disabled', () => {
|
|
71
|
-
const item = { type: 'card', disabled: true } as DragItem;
|
|
72
|
-
const props = createDragItemProps(item);
|
|
73
|
-
|
|
74
|
-
expect(props.draggable).toBe(false);
|
|
75
|
-
expect(props['data-drag-disabled']).toBe('true');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should use ariaLabel over label when both provided', () => {
|
|
79
|
-
const item = { type: 'card', label: 'Label', ariaLabel: 'Aria Label' } as DragItem;
|
|
80
|
-
const props = createDragItemProps(item);
|
|
81
|
-
|
|
82
|
-
expect(props['aria-label']).toBe('Aria Label');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should handle translation object for ariaLabel', () => {
|
|
86
|
-
const item = {
|
|
87
|
-
type: 'card',
|
|
88
|
-
ariaLabel: { key: 'drag.label', defaultValue: 'Translated label' },
|
|
89
|
-
} as unknown as DragItem;
|
|
90
|
-
const props = createDragItemProps(item);
|
|
91
|
-
|
|
92
|
-
expect(props['aria-label']).toBe('Translated label');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should use custom role and handle when provided', () => {
|
|
96
|
-
const item = { type: 'row', role: 'option', handle: 'grip' } as DragItem;
|
|
97
|
-
const props = createDragItemProps(item);
|
|
98
|
-
|
|
99
|
-
expect(props.role).toBe('option');
|
|
100
|
-
expect(props['data-drag-handle']).toBe('grip');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// ==========================================================================
|
|
105
|
-
// createDropZoneProps
|
|
106
|
-
// ==========================================================================
|
|
107
|
-
describe('createDropZoneProps', () => {
|
|
108
|
-
it('should return correct props for a basic drop zone', () => {
|
|
109
|
-
const zone = { accept: ['card', 'task'], label: 'Column' } as unknown as DropZone;
|
|
110
|
-
const props = createDropZoneProps(zone);
|
|
111
|
-
|
|
112
|
-
expect(props['aria-dropeffect']).toBe('move');
|
|
113
|
-
expect(props['aria-label']).toBe('Column');
|
|
114
|
-
expect(props.role).toBe('list');
|
|
115
|
-
expect(props['data-drop-accept']).toBe('card,task');
|
|
116
|
-
expect(props['data-drop-highlight']).toBe('true');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should use explicit dropEffect and role', () => {
|
|
120
|
-
const zone = { accept: ['item'], dropEffect: 'copy', role: 'region' } as unknown as DropZone;
|
|
121
|
-
const props = createDropZoneProps(zone);
|
|
122
|
-
|
|
123
|
-
expect(props['aria-dropeffect']).toBe('copy');
|
|
124
|
-
expect(props.role).toBe('region');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should set maxItems when provided', () => {
|
|
128
|
-
const zone = { accept: ['card'], maxItems: 10 } as unknown as DropZone;
|
|
129
|
-
const props = createDropZoneProps(zone);
|
|
130
|
-
|
|
131
|
-
expect(props['data-drop-max-items']).toBe(10);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should handle ariaLabel as translation object', () => {
|
|
135
|
-
const zone = {
|
|
136
|
-
accept: ['card'],
|
|
137
|
-
ariaLabel: { key: 'drop.label', defaultValue: 'Drop here' },
|
|
138
|
-
} as unknown as DropZone;
|
|
139
|
-
const props = createDropZoneProps(zone);
|
|
140
|
-
|
|
141
|
-
expect(props['aria-label']).toBe('Drop here');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// ==========================================================================
|
|
146
|
-
// resolveDragConstraints
|
|
147
|
-
// ==========================================================================
|
|
148
|
-
describe('resolveDragConstraints', () => {
|
|
149
|
-
it('should return base styles for default axis (both)', () => {
|
|
150
|
-
const constraint = {} as DragConstraint;
|
|
151
|
-
const styles = resolveDragConstraints(constraint);
|
|
152
|
-
|
|
153
|
-
expect(styles.position).toBe('relative');
|
|
154
|
-
expect(styles.touchAction).toBe('none');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should set touchAction to pan-y for x axis', () => {
|
|
158
|
-
const constraint = { axis: 'x' } as DragConstraint;
|
|
159
|
-
const styles = resolveDragConstraints(constraint);
|
|
160
|
-
|
|
161
|
-
expect(styles.touchAction).toBe('pan-y');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should set touchAction to pan-x for y axis', () => {
|
|
165
|
-
const constraint = { axis: 'y' } as DragConstraint;
|
|
166
|
-
const styles = resolveDragConstraints(constraint);
|
|
167
|
-
|
|
168
|
-
expect(styles.touchAction).toBe('pan-x');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should set overflow hidden for parent bounds', () => {
|
|
172
|
-
const constraint = { bounds: 'parent' } as DragConstraint;
|
|
173
|
-
const styles = resolveDragConstraints(constraint);
|
|
174
|
-
|
|
175
|
-
expect(styles.overflow).toBe('hidden');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should set grid CSS custom properties', () => {
|
|
179
|
-
const constraint = { grid: [20, 30] } as unknown as DragConstraint;
|
|
180
|
-
const styles = resolveDragConstraints(constraint);
|
|
181
|
-
|
|
182
|
-
expect(styles['--drag-grid-x']).toBe('20px');
|
|
183
|
-
expect(styles['--drag-grid-y']).toBe('30px');
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import type { KeyboardNavigationConfig, FocusTrapConfig } from '@object-ui/types';
|
|
3
|
-
import {
|
|
4
|
-
resolveKeyboardConfig,
|
|
5
|
-
parseShortcutKey,
|
|
6
|
-
matchesShortcut,
|
|
7
|
-
createFocusTrapConfig,
|
|
8
|
-
} from '../../protocols/KeyboardProtocol';
|
|
9
|
-
|
|
10
|
-
describe('KeyboardProtocol', () => {
|
|
11
|
-
// ==========================================================================
|
|
12
|
-
// resolveKeyboardConfig
|
|
13
|
-
// ==========================================================================
|
|
14
|
-
describe('resolveKeyboardConfig', () => {
|
|
15
|
-
it('should apply defaults for empty config', () => {
|
|
16
|
-
const config = {} as KeyboardNavigationConfig;
|
|
17
|
-
const resolved = resolveKeyboardConfig(config);
|
|
18
|
-
|
|
19
|
-
expect(resolved.shortcuts).toEqual([]);
|
|
20
|
-
expect(resolved.rovingTabindex).toBe(false);
|
|
21
|
-
expect(resolved.focusManagement.tabOrder).toBe('auto');
|
|
22
|
-
expect(resolved.focusManagement.skipLinks).toBe(false);
|
|
23
|
-
expect(resolved.focusManagement.focusVisible).toBe(true);
|
|
24
|
-
expect(resolved.focusManagement.arrowNavigation).toBe(false);
|
|
25
|
-
expect(resolved.focusManagement.focusTrap).toBeUndefined();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should resolve ariaLabel from string', () => {
|
|
29
|
-
const config = { ariaLabel: 'Navigation' } as KeyboardNavigationConfig;
|
|
30
|
-
const resolved = resolveKeyboardConfig(config);
|
|
31
|
-
|
|
32
|
-
expect(resolved.ariaLabel).toBe('Navigation');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should resolve ariaLabel from translation object', () => {
|
|
36
|
-
const config = {
|
|
37
|
-
ariaLabel: { key: 'nav.label', defaultValue: 'Nav panel' },
|
|
38
|
-
} as unknown as KeyboardNavigationConfig;
|
|
39
|
-
const resolved = resolveKeyboardConfig(config);
|
|
40
|
-
|
|
41
|
-
expect(resolved.ariaLabel).toBe('Nav panel');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should preserve explicit values', () => {
|
|
45
|
-
const config = {
|
|
46
|
-
rovingTabindex: true,
|
|
47
|
-
role: 'toolbar',
|
|
48
|
-
ariaDescribedBy: 'desc-id',
|
|
49
|
-
} as KeyboardNavigationConfig;
|
|
50
|
-
const resolved = resolveKeyboardConfig(config);
|
|
51
|
-
|
|
52
|
-
expect(resolved.rovingTabindex).toBe(true);
|
|
53
|
-
expect(resolved.role).toBe('toolbar');
|
|
54
|
-
expect(resolved.ariaDescribedBy).toBe('desc-id');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// ==========================================================================
|
|
59
|
-
// parseShortcutKey
|
|
60
|
-
// ==========================================================================
|
|
61
|
-
describe('parseShortcutKey', () => {
|
|
62
|
-
it('should parse Ctrl+S', () => {
|
|
63
|
-
const parsed = parseShortcutKey('Ctrl+S');
|
|
64
|
-
|
|
65
|
-
expect(parsed.key).toBe('s');
|
|
66
|
-
expect(parsed.ctrlOrMeta).toBe(true);
|
|
67
|
-
expect(parsed.shift).toBe(false);
|
|
68
|
-
expect(parsed.alt).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should parse Alt+Shift+N', () => {
|
|
72
|
-
const parsed = parseShortcutKey('Alt+Shift+N');
|
|
73
|
-
|
|
74
|
-
expect(parsed.key).toBe('n');
|
|
75
|
-
expect(parsed.ctrlOrMeta).toBe(false);
|
|
76
|
-
expect(parsed.shift).toBe(true);
|
|
77
|
-
expect(parsed.alt).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should parse single key Escape', () => {
|
|
81
|
-
const parsed = parseShortcutKey('Escape');
|
|
82
|
-
|
|
83
|
-
expect(parsed.key).toBe('escape');
|
|
84
|
-
expect(parsed.ctrlOrMeta).toBe(false);
|
|
85
|
-
expect(parsed.shift).toBe(false);
|
|
86
|
-
expect(parsed.alt).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should be case insensitive', () => {
|
|
90
|
-
const parsed = parseShortcutKey('ctrl+s');
|
|
91
|
-
|
|
92
|
-
expect(parsed.key).toBe('s');
|
|
93
|
-
expect(parsed.ctrlOrMeta).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should parse single key F1', () => {
|
|
97
|
-
const parsed = parseShortcutKey('F1');
|
|
98
|
-
|
|
99
|
-
expect(parsed.key).toBe('f1');
|
|
100
|
-
expect(parsed.ctrlOrMeta).toBe(false);
|
|
101
|
-
expect(parsed.shift).toBe(false);
|
|
102
|
-
expect(parsed.alt).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should recognise Meta as ctrlOrMeta', () => {
|
|
106
|
-
const parsed = parseShortcutKey('Meta+K');
|
|
107
|
-
|
|
108
|
-
expect(parsed.ctrlOrMeta).toBe(true);
|
|
109
|
-
expect(parsed.key).toBe('k');
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// ==========================================================================
|
|
114
|
-
// matchesShortcut
|
|
115
|
-
// ==========================================================================
|
|
116
|
-
describe('matchesShortcut', () => {
|
|
117
|
-
it('should match Ctrl+S event', () => {
|
|
118
|
-
const event = { key: 's', ctrlKey: true };
|
|
119
|
-
expect(matchesShortcut(event, 'Ctrl+S')).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should match Meta+S event (Cmd on Mac)', () => {
|
|
123
|
-
const event = { key: 's', metaKey: true };
|
|
124
|
-
expect(matchesShortcut(event, 'Ctrl+S')).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should not match when key differs', () => {
|
|
128
|
-
const event = { key: 'a', ctrlKey: true };
|
|
129
|
-
expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should not match when modifier is missing', () => {
|
|
133
|
-
const event = { key: 's' };
|
|
134
|
-
expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should not match when extra modifier is present', () => {
|
|
138
|
-
const event = { key: 's', ctrlKey: true, shiftKey: true };
|
|
139
|
-
expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should match Escape without modifiers', () => {
|
|
143
|
-
const event = { key: 'Escape' };
|
|
144
|
-
expect(matchesShortcut(event, 'Escape')).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// ==========================================================================
|
|
149
|
-
// createFocusTrapConfig
|
|
150
|
-
// ==========================================================================
|
|
151
|
-
describe('createFocusTrapConfig', () => {
|
|
152
|
-
it('should apply defaults for minimal config', () => {
|
|
153
|
-
const config = {} as FocusTrapConfig;
|
|
154
|
-
const resolved = createFocusTrapConfig(config);
|
|
155
|
-
|
|
156
|
-
expect(resolved.enabled).toBe(false);
|
|
157
|
-
expect(resolved.returnFocus).toBe(true);
|
|
158
|
-
expect(resolved.escapeDeactivates).toBe(true);
|
|
159
|
-
expect(resolved.initialFocus).toBeUndefined();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should preserve explicit values', () => {
|
|
163
|
-
const config = {
|
|
164
|
-
enabled: true,
|
|
165
|
-
initialFocus: '#first-input',
|
|
166
|
-
returnFocus: false,
|
|
167
|
-
escapeDeactivates: false,
|
|
168
|
-
} as FocusTrapConfig;
|
|
169
|
-
const resolved = createFocusTrapConfig(config);
|
|
170
|
-
|
|
171
|
-
expect(resolved.enabled).toBe(true);
|
|
172
|
-
expect(resolved.initialFocus).toBe('#first-input');
|
|
173
|
-
expect(resolved.returnFocus).toBe(false);
|
|
174
|
-
expect(resolved.escapeDeactivates).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|