@object-ui/core 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/actions/ActionEngine.d.ts +98 -0
- package/dist/actions/ActionEngine.js +222 -0
- package/dist/actions/UndoManager.d.ts +80 -0
- package/dist/actions/UndoManager.js +193 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +2 -0
- package/dist/adapters/ApiDataSource.d.ts +2 -1
- package/dist/adapters/ApiDataSource.js +25 -0
- package/dist/adapters/ValueDataSource.d.ts +2 -1
- package/dist/adapters/ValueDataSource.js +99 -3
- package/dist/data-scope/ViewDataProvider.d.ts +143 -0
- package/dist/data-scope/ViewDataProvider.js +153 -0
- package/dist/data-scope/index.d.ts +1 -0
- package/dist/data-scope/index.js +1 -0
- package/dist/evaluator/ExpressionEvaluator.d.ts +7 -0
- package/dist/evaluator/ExpressionEvaluator.js +19 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/protocols/DndProtocol.d.ts +84 -0
- package/dist/protocols/DndProtocol.js +113 -0
- package/dist/protocols/KeyboardProtocol.d.ts +93 -0
- package/dist/protocols/KeyboardProtocol.js +108 -0
- package/dist/protocols/NotificationProtocol.d.ts +71 -0
- package/dist/protocols/NotificationProtocol.js +99 -0
- package/dist/protocols/ResponsiveProtocol.d.ts +73 -0
- package/dist/protocols/ResponsiveProtocol.js +158 -0
- package/dist/protocols/SharingProtocol.d.ts +71 -0
- package/dist/protocols/SharingProtocol.js +124 -0
- package/dist/protocols/index.d.ts +12 -0
- package/dist/protocols/index.js +12 -0
- package/dist/utils/debug-collector.d.ts +59 -0
- package/dist/utils/debug-collector.js +73 -0
- package/dist/utils/debug.d.ts +37 -2
- package/dist/utils/debug.js +62 -3
- package/dist/utils/expand-fields.d.ts +40 -0
- package/dist/utils/expand-fields.js +68 -0
- package/dist/utils/extract-records.d.ts +16 -0
- package/dist/utils/extract-records.js +32 -0
- package/dist/utils/normalize-quick-filter.d.ts +29 -0
- package/dist/utils/normalize-quick-filter.js +66 -0
- package/package.json +3 -3
- package/src/__tests__/protocols/DndProtocol.test.ts +186 -0
- package/src/__tests__/protocols/KeyboardProtocol.test.ts +177 -0
- package/src/__tests__/protocols/NotificationProtocol.test.ts +142 -0
- package/src/__tests__/protocols/ResponsiveProtocol.test.ts +176 -0
- package/src/__tests__/protocols/SharingProtocol.test.ts +188 -0
- package/src/actions/ActionEngine.ts +268 -0
- package/src/actions/UndoManager.ts +215 -0
- package/src/actions/__tests__/ActionEngine.test.ts +206 -0
- package/src/actions/__tests__/UndoManager.test.ts +320 -0
- package/src/actions/index.ts +2 -0
- package/src/adapters/ApiDataSource.ts +27 -0
- package/src/adapters/ValueDataSource.ts +109 -3
- package/src/adapters/__tests__/ValueDataSource.test.ts +147 -0
- package/src/data-scope/ViewDataProvider.ts +282 -0
- package/src/data-scope/__tests__/ViewDataProvider.test.ts +270 -0
- package/src/data-scope/index.ts +8 -0
- package/src/evaluator/ExpressionEvaluator.ts +22 -0
- package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +31 -1
- package/src/index.ts +5 -0
- package/src/protocols/DndProtocol.ts +184 -0
- package/src/protocols/KeyboardProtocol.ts +185 -0
- package/src/protocols/NotificationProtocol.ts +159 -0
- package/src/protocols/ResponsiveProtocol.ts +210 -0
- package/src/protocols/SharingProtocol.ts +185 -0
- package/src/protocols/index.ts +13 -0
- package/src/utils/__tests__/debug-collector.test.ts +102 -0
- package/src/utils/__tests__/debug.test.ts +52 -1
- package/src/utils/__tests__/expand-fields.test.ts +120 -0
- package/src/utils/__tests__/extract-records.test.ts +50 -0
- package/src/utils/__tests__/normalize-quick-filter.test.ts +123 -0
- package/src/utils/debug-collector.ts +100 -0
- package/src/utils/debug.ts +87 -6
- package/src/utils/expand-fields.ts +76 -0
- package/src/utils/extract-records.ts +33 -0
- package/src/utils/normalize-quick-filter.ts +78 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @object-ui/core - Sharing Protocol Bridge
|
|
10
|
+
*
|
|
11
|
+
* Converts spec-aligned SharingConfig and EmbedConfig schemas into
|
|
12
|
+
* runtime-usable configurations. Provides embed code generation and
|
|
13
|
+
* configuration validation.
|
|
14
|
+
*
|
|
15
|
+
* @module protocols/SharingProtocol
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import type { SharingConfig, EmbedConfig } from '@object-ui/types';
|
|
19
|
+
/** Fully resolved sharing configuration. */
|
|
20
|
+
export interface ResolvedSharingConfig {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
publicLink?: string;
|
|
23
|
+
password?: string;
|
|
24
|
+
allowedDomains: string[];
|
|
25
|
+
expiresAt?: string;
|
|
26
|
+
allowAnonymous: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Fully resolved embed configuration. */
|
|
29
|
+
export interface ResolvedEmbedConfig {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
allowedOrigins: string[];
|
|
32
|
+
width: string;
|
|
33
|
+
height: string;
|
|
34
|
+
showHeader: boolean;
|
|
35
|
+
showNavigation: boolean;
|
|
36
|
+
responsive: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Validation result for sharing configuration. */
|
|
39
|
+
export interface SharingValidationResult {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
errors: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a sharing configuration by applying spec defaults.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Partial SharingConfig from the spec
|
|
47
|
+
* @returns Fully resolved sharing configuration
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveSharingConfig(config: Partial<SharingConfig>): ResolvedSharingConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve an embed configuration by applying spec defaults.
|
|
52
|
+
*
|
|
53
|
+
* @param config - Partial EmbedConfig from the spec
|
|
54
|
+
* @returns Fully resolved embed configuration
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveEmbedConfig(config: Partial<EmbedConfig>): ResolvedEmbedConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Generate an HTML iframe embed snippet from an EmbedConfig and URL.
|
|
59
|
+
*
|
|
60
|
+
* @param config - EmbedConfig from the spec
|
|
61
|
+
* @param url - The URL to embed
|
|
62
|
+
* @returns HTML string containing an iframe element
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateEmbedCode(config: EmbedConfig, url: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Validate a sharing configuration and return any errors.
|
|
67
|
+
*
|
|
68
|
+
* @param config - SharingConfig to validate
|
|
69
|
+
* @returns Validation result with `valid` flag and error messages
|
|
70
|
+
*/
|
|
71
|
+
export declare function validateSharingConfig(config: SharingConfig): SharingValidationResult;
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
// Sharing Config Resolution
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a sharing configuration by applying spec defaults.
|
|
13
|
+
*
|
|
14
|
+
* @param config - Partial SharingConfig from the spec
|
|
15
|
+
* @returns Fully resolved sharing configuration
|
|
16
|
+
*/
|
|
17
|
+
export function resolveSharingConfig(config) {
|
|
18
|
+
return {
|
|
19
|
+
enabled: config.enabled ?? false,
|
|
20
|
+
publicLink: config.publicLink,
|
|
21
|
+
password: config.password,
|
|
22
|
+
allowedDomains: config.allowedDomains ?? [],
|
|
23
|
+
expiresAt: config.expiresAt,
|
|
24
|
+
allowAnonymous: config.allowAnonymous ?? false,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Embed Config Resolution
|
|
29
|
+
// ============================================================================
|
|
30
|
+
/**
|
|
31
|
+
* Resolve an embed configuration by applying spec defaults.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Partial EmbedConfig from the spec
|
|
34
|
+
* @returns Fully resolved embed configuration
|
|
35
|
+
*/
|
|
36
|
+
export function resolveEmbedConfig(config) {
|
|
37
|
+
return {
|
|
38
|
+
enabled: config.enabled ?? false,
|
|
39
|
+
allowedOrigins: config.allowedOrigins ?? [],
|
|
40
|
+
width: config.width ?? '100%',
|
|
41
|
+
height: config.height ?? '600px',
|
|
42
|
+
showHeader: config.showHeader ?? true,
|
|
43
|
+
showNavigation: config.showNavigation ?? false,
|
|
44
|
+
responsive: config.responsive ?? true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Embed Code Generation
|
|
49
|
+
// ============================================================================
|
|
50
|
+
/**
|
|
51
|
+
* Generate an HTML iframe embed snippet from an EmbedConfig and URL.
|
|
52
|
+
*
|
|
53
|
+
* @param config - EmbedConfig from the spec
|
|
54
|
+
* @param url - The URL to embed
|
|
55
|
+
* @returns HTML string containing an iframe element
|
|
56
|
+
*/
|
|
57
|
+
export function generateEmbedCode(config, url) {
|
|
58
|
+
const resolved = resolveEmbedConfig(config);
|
|
59
|
+
const sanitizedUrl = escapeHtmlAttr(url);
|
|
60
|
+
const title = 'Embedded content';
|
|
61
|
+
const parts = [
|
|
62
|
+
`<iframe`,
|
|
63
|
+
` src="${sanitizedUrl}"`,
|
|
64
|
+
` width="${escapeHtmlAttr(resolved.width)}"`,
|
|
65
|
+
` height="${escapeHtmlAttr(resolved.height)}"`,
|
|
66
|
+
` title="${title}"`,
|
|
67
|
+
` frameborder="0"`,
|
|
68
|
+
` allowfullscreen`,
|
|
69
|
+
];
|
|
70
|
+
if (resolved.responsive) {
|
|
71
|
+
parts.push(` style="max-width: 100%; border: none;"`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
parts.push(` style="border: none;"`);
|
|
75
|
+
}
|
|
76
|
+
parts.push(`></iframe>`);
|
|
77
|
+
return parts.join('\n');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Escape a string for safe use in an HTML attribute value.
|
|
81
|
+
*/
|
|
82
|
+
function escapeHtmlAttr(value) {
|
|
83
|
+
return value
|
|
84
|
+
.replace(/&/g, '&')
|
|
85
|
+
.replace(/"/g, '"')
|
|
86
|
+
.replace(/</g, '<')
|
|
87
|
+
.replace(/>/g, '>');
|
|
88
|
+
}
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Sharing Config Validation
|
|
91
|
+
// ============================================================================
|
|
92
|
+
/**
|
|
93
|
+
* Validate a sharing configuration and return any errors.
|
|
94
|
+
*
|
|
95
|
+
* @param config - SharingConfig to validate
|
|
96
|
+
* @returns Validation result with `valid` flag and error messages
|
|
97
|
+
*/
|
|
98
|
+
export function validateSharingConfig(config) {
|
|
99
|
+
const errors = [];
|
|
100
|
+
if (config.enabled && !config.publicLink) {
|
|
101
|
+
errors.push('A public link is required when sharing is enabled.');
|
|
102
|
+
}
|
|
103
|
+
if (config.expiresAt) {
|
|
104
|
+
const expiryDate = new Date(config.expiresAt);
|
|
105
|
+
if (isNaN(expiryDate.getTime())) {
|
|
106
|
+
errors.push('expiresAt must be a valid ISO 8601 date string.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (config.allowedDomains) {
|
|
110
|
+
for (const domain of config.allowedDomains) {
|
|
111
|
+
if (!domain || domain.trim().length === 0) {
|
|
112
|
+
errors.push('allowedDomains contains an empty or whitespace-only entry.');
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (config.password !== undefined && config.password.length === 0) {
|
|
118
|
+
errors.push('Password must not be an empty string when provided.');
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
valid: errors.length === 0,
|
|
122
|
+
errors,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export * from './DndProtocol.js';
|
|
9
|
+
export * from './KeyboardProtocol.js';
|
|
10
|
+
export * from './NotificationProtocol.js';
|
|
11
|
+
export * from './ResponsiveProtocol.js';
|
|
12
|
+
export * from './SharingProtocol.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export * from './DndProtocol.js';
|
|
9
|
+
export * from './KeyboardProtocol.js';
|
|
10
|
+
export * from './NotificationProtocol.js';
|
|
11
|
+
export * from './ResponsiveProtocol.js';
|
|
12
|
+
export * from './SharingProtocol.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* DebugCollector — lightweight, tree-shakeable event collector
|
|
10
|
+
* for perf / expression / action debug data.
|
|
11
|
+
*
|
|
12
|
+
* Usage in production is a no-op when the singleton is never imported.
|
|
13
|
+
* Consumers call `DebugCollector.getInstance()` and subscribe via
|
|
14
|
+
* `.subscribe()`.
|
|
15
|
+
*/
|
|
16
|
+
export interface PerfEntry {
|
|
17
|
+
type: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ExprEntry {
|
|
23
|
+
expression: string;
|
|
24
|
+
result: unknown;
|
|
25
|
+
context?: Record<string, unknown>;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
}
|
|
28
|
+
export interface EventEntry {
|
|
29
|
+
action: string;
|
|
30
|
+
payload?: unknown;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
}
|
|
33
|
+
export type DebugEntry = {
|
|
34
|
+
kind: 'perf';
|
|
35
|
+
data: PerfEntry;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'expr';
|
|
38
|
+
data: ExprEntry;
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'event';
|
|
41
|
+
data: EventEntry;
|
|
42
|
+
};
|
|
43
|
+
type DebugSubscriber = (entry: DebugEntry) => void;
|
|
44
|
+
export declare class DebugCollector {
|
|
45
|
+
private static instance;
|
|
46
|
+
private entries;
|
|
47
|
+
private subscribers;
|
|
48
|
+
static getInstance(): DebugCollector;
|
|
49
|
+
/** Reset singleton — only used for testing */
|
|
50
|
+
static resetInstance(): void;
|
|
51
|
+
addPerf(entry: PerfEntry): void;
|
|
52
|
+
addExpr(entry: ExprEntry): void;
|
|
53
|
+
addEvent(entry: EventEntry): void;
|
|
54
|
+
getEntries(kind?: DebugEntry['kind']): DebugEntry[];
|
|
55
|
+
clear(): void;
|
|
56
|
+
subscribe(fn: DebugSubscriber): () => void;
|
|
57
|
+
private push;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
const MAX_ENTRIES = 200;
|
|
9
|
+
export class DebugCollector {
|
|
10
|
+
constructor() {
|
|
11
|
+
Object.defineProperty(this, "entries", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: []
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "subscribers", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: new Set()
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!DebugCollector.instance) {
|
|
26
|
+
DebugCollector.instance = new DebugCollector();
|
|
27
|
+
}
|
|
28
|
+
return DebugCollector.instance;
|
|
29
|
+
}
|
|
30
|
+
/** Reset singleton — only used for testing */
|
|
31
|
+
static resetInstance() {
|
|
32
|
+
DebugCollector.instance = null;
|
|
33
|
+
}
|
|
34
|
+
addPerf(entry) {
|
|
35
|
+
this.push({ kind: 'perf', data: entry });
|
|
36
|
+
}
|
|
37
|
+
addExpr(entry) {
|
|
38
|
+
this.push({ kind: 'expr', data: entry });
|
|
39
|
+
}
|
|
40
|
+
addEvent(entry) {
|
|
41
|
+
this.push({ kind: 'event', data: entry });
|
|
42
|
+
}
|
|
43
|
+
getEntries(kind) {
|
|
44
|
+
if (!kind)
|
|
45
|
+
return this.entries.slice();
|
|
46
|
+
return this.entries.filter((e) => e.kind === kind);
|
|
47
|
+
}
|
|
48
|
+
clear() {
|
|
49
|
+
this.entries = [];
|
|
50
|
+
}
|
|
51
|
+
subscribe(fn) {
|
|
52
|
+
this.subscribers.add(fn);
|
|
53
|
+
return () => this.subscribers.delete(fn);
|
|
54
|
+
}
|
|
55
|
+
push(entry) {
|
|
56
|
+
this.entries.push(entry);
|
|
57
|
+
if (this.entries.length > MAX_ENTRIES) {
|
|
58
|
+
this.entries = this.entries.slice(-MAX_ENTRIES);
|
|
59
|
+
}
|
|
60
|
+
for (const fn of this.subscribers) {
|
|
61
|
+
try {
|
|
62
|
+
fn(entry);
|
|
63
|
+
}
|
|
64
|
+
catch { /* subscriber errors must not break debug flow */ }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
Object.defineProperty(DebugCollector, "instance", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: null
|
|
73
|
+
});
|
package/dist/utils/debug.d.ts
CHANGED
|
@@ -5,7 +5,43 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
type DebugCategory = 'schema' | 'registry' | 'expression' | 'action' | 'plugin' | 'render';
|
|
8
|
+
export type DebugCategory = 'schema' | 'registry' | 'expression' | 'action' | 'plugin' | 'render' | 'dashboard';
|
|
9
|
+
/**
|
|
10
|
+
* Fine-grained debug flags parsed from URL parameters.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* ?__debug → { enabled: true }
|
|
15
|
+
* ?__debug_schema → { enabled: true, schema: true }
|
|
16
|
+
* ?__debug_perf&__debug_data → { enabled: true, perf: true, data: true }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface DebugFlags {
|
|
20
|
+
/** Master switch — true when any debug parameter is present */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
schema?: boolean;
|
|
23
|
+
perf?: boolean;
|
|
24
|
+
data?: boolean;
|
|
25
|
+
expr?: boolean;
|
|
26
|
+
events?: boolean;
|
|
27
|
+
registry?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse debug flags from a URL search string (e.g. `?__debug&__debug_schema`).
|
|
31
|
+
* SSR-safe — returns `{ enabled: false }` when `window` is unavailable.
|
|
32
|
+
*
|
|
33
|
+
* @param search — Optional search string. Defaults to `window.location.search` when available.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseDebugFlags(search?: string): DebugFlags;
|
|
36
|
+
/**
|
|
37
|
+
* Check whether debug mode is enabled.
|
|
38
|
+
*
|
|
39
|
+
* Resolution order (first truthy wins):
|
|
40
|
+
* 1. URL parameter `?__debug` (browser only)
|
|
41
|
+
* 2. `globalThis.OBJECTUI_DEBUG`
|
|
42
|
+
* 3. `process.env.OBJECTUI_DEBUG`
|
|
43
|
+
*/
|
|
44
|
+
export declare function isDebugEnabled(): boolean;
|
|
9
45
|
/**
|
|
10
46
|
* Log a debug message when OBJECTUI_DEBUG is enabled.
|
|
11
47
|
* No-op in production or when debug mode is off.
|
|
@@ -28,4 +64,3 @@ export declare function debugTime(label: string): void;
|
|
|
28
64
|
* End a debug timer and log the elapsed time.
|
|
29
65
|
*/
|
|
30
66
|
export declare function debugTimeEnd(label: string): void;
|
|
31
|
-
export {};
|
package/dist/utils/debug.js
CHANGED
|
@@ -5,11 +5,70 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
const DEBUG_PARAM_PREFIX = '__debug';
|
|
9
|
+
/**
|
|
10
|
+
* Parse debug flags from a URL search string (e.g. `?__debug&__debug_schema`).
|
|
11
|
+
* SSR-safe — returns `{ enabled: false }` when `window` is unavailable.
|
|
12
|
+
*
|
|
13
|
+
* @param search — Optional search string. Defaults to `window.location.search` when available.
|
|
14
|
+
*/
|
|
15
|
+
export function parseDebugFlags(search) {
|
|
16
|
+
let qs = search;
|
|
17
|
+
if (qs === undefined) {
|
|
18
|
+
try {
|
|
19
|
+
qs = typeof window !== 'undefined' ? window.location.search : '';
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
qs = '';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const params = new URLSearchParams(qs);
|
|
26
|
+
const hasMain = params.has(DEBUG_PARAM_PREFIX);
|
|
27
|
+
const schema = params.has(`${DEBUG_PARAM_PREFIX}_schema`);
|
|
28
|
+
const perf = params.has(`${DEBUG_PARAM_PREFIX}_perf`);
|
|
29
|
+
const data = params.has(`${DEBUG_PARAM_PREFIX}_data`);
|
|
30
|
+
const expr = params.has(`${DEBUG_PARAM_PREFIX}_expr`);
|
|
31
|
+
const events = params.has(`${DEBUG_PARAM_PREFIX}_events`);
|
|
32
|
+
const registry = params.has(`${DEBUG_PARAM_PREFIX}_registry`);
|
|
33
|
+
const anySub = schema || perf || data || expr || events || registry;
|
|
34
|
+
const enabled = hasMain || anySub;
|
|
35
|
+
return {
|
|
36
|
+
enabled,
|
|
37
|
+
...(schema && { schema }),
|
|
38
|
+
...(perf && { perf }),
|
|
39
|
+
...(data && { data }),
|
|
40
|
+
...(expr && { expr }),
|
|
41
|
+
...(events && { events }),
|
|
42
|
+
...(registry && { registry }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check whether debug mode is enabled.
|
|
47
|
+
*
|
|
48
|
+
* Resolution order (first truthy wins):
|
|
49
|
+
* 1. URL parameter `?__debug` (browser only)
|
|
50
|
+
* 2. `globalThis.OBJECTUI_DEBUG`
|
|
51
|
+
* 3. `process.env.OBJECTUI_DEBUG`
|
|
52
|
+
*/
|
|
53
|
+
export function isDebugEnabled() {
|
|
9
54
|
try {
|
|
55
|
+
// 1. URL parameter (browser only, SSR-safe)
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
57
|
+
try {
|
|
58
|
+
const flags = parseDebugFlags(window.location.search);
|
|
59
|
+
if (flags.enabled)
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch { /* ignore */ }
|
|
63
|
+
}
|
|
64
|
+
// 2. globalThis flag
|
|
10
65
|
const g = typeof globalThis !== 'undefined' && globalThis.OBJECTUI_DEBUG;
|
|
11
|
-
|
|
12
|
-
|
|
66
|
+
if (g === true || g === 'true')
|
|
67
|
+
return true;
|
|
68
|
+
// 3. process.env
|
|
69
|
+
if (typeof process !== 'undefined' && process.env?.OBJECTUI_DEBUG === 'true')
|
|
70
|
+
return true;
|
|
71
|
+
return false;
|
|
13
72
|
}
|
|
14
73
|
catch {
|
|
15
74
|
return false;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI — expand-fields utility
|
|
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
|
+
* Build an array of field names that should be included in `$expand`
|
|
10
|
+
* when fetching data. This scans the given object schema fields
|
|
11
|
+
* (and optional column configuration) for `lookup` and `master_detail`
|
|
12
|
+
* field types, so the backend (e.g. objectql) returns expanded objects
|
|
13
|
+
* instead of raw foreign-key IDs.
|
|
14
|
+
*
|
|
15
|
+
* @param schemaFields - Object map of field metadata from `getObjectSchema()`,
|
|
16
|
+
* e.g. `{ account: { type: 'lookup', reference_to: 'accounts' }, ... }`.
|
|
17
|
+
* @param columns - Optional explicit column list. When provided, only
|
|
18
|
+
* lookup/master_detail fields that appear in `columns` are expanded.
|
|
19
|
+
* Accepts `string[]` or `ListColumn[]` (objects with a `field` property).
|
|
20
|
+
* @returns Array of field names to pass as `$expand`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const fields = {
|
|
25
|
+
* name: { type: 'text' },
|
|
26
|
+
* account: { type: 'lookup', reference_to: 'accounts' },
|
|
27
|
+
* parent: { type: 'master_detail', reference_to: 'contacts' },
|
|
28
|
+
* };
|
|
29
|
+
* buildExpandFields(fields);
|
|
30
|
+
* // → ['account', 'parent']
|
|
31
|
+
*
|
|
32
|
+
* buildExpandFields(fields, ['name', 'account']);
|
|
33
|
+
* // → ['account']
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildExpandFields(schemaFields?: Record<string, any> | null, columns?: (string | {
|
|
37
|
+
field?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
fieldName?: string;
|
|
40
|
+
})[]): string[];
|