@object-ui/components 3.3.0 → 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 +20 -0
- package/README.md +21 -1
- package/dist/index.css +6339 -2
- package/dist/index.js +17600 -17481
- package/dist/index.umd.cjs +36 -36
- package/dist/packages/components/src/custom/empty.d.ts +12 -1
- package/dist/packages/components/src/renderers/action/action-bar.d.ts +12 -1
- package/dist/packages/components/src/ui/chart.d.ts +10 -29
- package/package.json +65 -44
- package/.turbo/turbo-build.log +0 -84
- package/README_SHADCN_SYNC.md +0 -281
- package/TESTING.md +0 -335
- package/docs/FilterBuilder.md +0 -268
- package/metadata/Chart.component.yml +0 -30
- package/metadata/FilterBuilder.component.yml +0 -39
- package/metadata/GridLayout.component.yml +0 -27
- package/metadata/Menu.component.yml +0 -31
- package/metadata/ObjectForm.component.yml +0 -34
- package/metadata/ObjectGrid.component.yml +0 -72
- package/metadata/Page.component.yml +0 -24
- package/postcss.config.js +0 -14
- package/shadcn-components.json +0 -440
- package/src/SchemaRenderer.tsx +0 -28
- package/src/__tests__/PageRendererRegions.test.tsx +0 -668
- package/src/__tests__/README.md +0 -124
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +0 -811
- package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +0 -327
- package/src/__tests__/accessibility.test.tsx +0 -137
- package/src/__tests__/action-bar.test.tsx +0 -206
- package/src/__tests__/api-consistency.test.tsx +0 -596
- package/src/__tests__/basic-renderers.test.tsx +0 -255
- package/src/__tests__/color-contrast.test.tsx +0 -212
- package/src/__tests__/complex-disclosure-renderers.test.tsx +0 -302
- package/src/__tests__/compliance.test.tsx +0 -72
- package/src/__tests__/config-field-renderer.test.tsx +0 -307
- package/src/__tests__/config-panel-renderer.test.tsx +0 -580
- package/src/__tests__/config-primitives.test.tsx +0 -106
- package/src/__tests__/edge-cases.test.tsx +0 -285
- package/src/__tests__/feedback-overlay-renderers.test.tsx +0 -349
- package/src/__tests__/filter-builder.test.tsx +0 -409
- package/src/__tests__/form-renderers.test.tsx +0 -364
- package/src/__tests__/layout-data-renderers.test.tsx +0 -340
- package/src/__tests__/mobile-accessibility.test.tsx +0 -120
- package/src/__tests__/navigation-overlay.test.tsx +0 -370
- package/src/__tests__/snapshot-critical.test.tsx +0 -317
- package/src/__tests__/snapshot.test.tsx +0 -205
- package/src/__tests__/test-utils.tsx +0 -190
- package/src/__tests__/use-config-draft.test.tsx +0 -295
- package/src/__tests__/view-compliance.test.tsx +0 -153
- package/src/__tests__/wcag-audit.test.tsx +0 -493
- package/src/custom/action-param-dialog.tsx +0 -264
- package/src/custom/button-group.tsx +0 -91
- package/src/custom/combobox.tsx +0 -104
- package/src/custom/config-field-renderer.tsx +0 -276
- package/src/custom/config-panel-renderer.tsx +0 -306
- package/src/custom/config-row.tsx +0 -50
- package/src/custom/date-picker.tsx +0 -61
- package/src/custom/empty.tsx +0 -112
- package/src/custom/field.tsx +0 -81
- package/src/custom/filter-builder.tsx +0 -418
- package/src/custom/index.ts +0 -21
- package/src/custom/input-group.tsx +0 -53
- package/src/custom/item.tsx +0 -201
- package/src/custom/kbd.tsx +0 -36
- package/src/custom/mobile-dialog-content.tsx +0 -67
- package/src/custom/native-select.tsx +0 -33
- package/src/custom/navigation-overlay.tsx +0 -334
- package/src/custom/section-header.tsx +0 -68
- package/src/custom/sort-builder.tsx +0 -129
- package/src/custom/spinner.tsx +0 -26
- package/src/custom/view-skeleton.tsx +0 -243
- package/src/custom/view-states.tsx +0 -153
- package/src/debug/DebugPanel.tsx +0 -313
- package/src/debug/__tests__/DebugPanel.test.tsx +0 -134
- package/src/debug/index.ts +0 -10
- package/src/hooks/use-config-draft.ts +0 -127
- package/src/hooks/use-mobile.tsx +0 -27
- package/src/index.css +0 -245
- package/src/index.ts +0 -47
- package/src/lib/use-sync-external-store-shim.ts +0 -10
- package/src/lib/use-sync-external-store-with-selector-shim.ts +0 -90
- package/src/lib/utils.tsx +0 -35
- package/src/new-components.test.ts +0 -73
- package/src/renderers/action/action-bar.tsx +0 -221
- package/src/renderers/action/action-button.tsx +0 -158
- package/src/renderers/action/action-group.tsx +0 -270
- package/src/renderers/action/action-icon.tsx +0 -150
- package/src/renderers/action/action-menu.tsx +0 -203
- package/src/renderers/action/index.ts +0 -19
- package/src/renderers/action/resolve-icon.ts +0 -35
- package/src/renderers/basic/button-group.tsx +0 -79
- package/src/renderers/basic/div.tsx +0 -60
- package/src/renderers/basic/html.tsx +0 -43
- package/src/renderers/basic/icon.tsx +0 -89
- package/src/renderers/basic/image.tsx +0 -49
- package/src/renderers/basic/index.ts +0 -18
- package/src/renderers/basic/navigation-menu.tsx +0 -81
- package/src/renderers/basic/pagination.tsx +0 -109
- package/src/renderers/basic/separator.tsx +0 -57
- package/src/renderers/basic/span.tsx +0 -63
- package/src/renderers/basic/text.tsx +0 -52
- package/src/renderers/complex/README-KANBAN.md +0 -208
- package/src/renderers/complex/TIMELINE.md +0 -353
- package/src/renderers/complex/__tests__/data-table-airtable-ux.test.tsx +0 -239
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +0 -275
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +0 -120
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +0 -221
- package/src/renderers/complex/__tests__/data-table.test.ts +0 -76
- package/src/renderers/complex/carousel.tsx +0 -69
- package/src/renderers/complex/data-table.tsx +0 -1243
- package/src/renderers/complex/filter-builder.tsx +0 -77
- package/src/renderers/complex/index.ts +0 -16
- package/src/renderers/complex/resizable.tsx +0 -66
- package/src/renderers/complex/scroll-area.tsx +0 -58
- package/src/renderers/complex/table.tsx +0 -95
- package/src/renderers/data-display/alert.tsx +0 -46
- package/src/renderers/data-display/avatar.tsx +0 -38
- package/src/renderers/data-display/badge.tsx +0 -55
- package/src/renderers/data-display/breadcrumb.tsx +0 -61
- package/src/renderers/data-display/index.ts +0 -18
- package/src/renderers/data-display/kbd.tsx +0 -50
- package/src/renderers/data-display/list.tsx +0 -75
- package/src/renderers/data-display/statistic.tsx +0 -95
- package/src/renderers/data-display/table.tsx +0 -78
- package/src/renderers/data-display/tree-view.tsx +0 -176
- package/src/renderers/disclosure/accordion.tsx +0 -69
- package/src/renderers/disclosure/collapsible.tsx +0 -53
- package/src/renderers/disclosure/index.ts +0 -11
- package/src/renderers/disclosure/toggle-group.tsx +0 -79
- package/src/renderers/feedback/empty.tsx +0 -49
- package/src/renderers/feedback/index.ts +0 -16
- package/src/renderers/feedback/loading.tsx +0 -78
- package/src/renderers/feedback/progress.tsx +0 -29
- package/src/renderers/feedback/skeleton.tsx +0 -31
- package/src/renderers/feedback/sonner.tsx +0 -56
- package/src/renderers/feedback/spinner.tsx +0 -55
- package/src/renderers/feedback/toast.tsx +0 -59
- package/src/renderers/feedback/toaster.tsx +0 -23
- package/src/renderers/form/button.tsx +0 -103
- package/src/renderers/form/calendar.tsx +0 -34
- package/src/renderers/form/checkbox.tsx +0 -71
- package/src/renderers/form/combobox.tsx +0 -48
- package/src/renderers/form/command.tsx +0 -58
- package/src/renderers/form/date-picker.tsx +0 -84
- package/src/renderers/form/file-upload.tsx +0 -184
- package/src/renderers/form/form.tsx +0 -540
- package/src/renderers/form/index.ts +0 -26
- package/src/renderers/form/input-otp.tsx +0 -51
- package/src/renderers/form/input.tsx +0 -121
- package/src/renderers/form/label.tsx +0 -45
- package/src/renderers/form/radio-group.tsx +0 -63
- package/src/renderers/form/select.tsx +0 -94
- package/src/renderers/form/slider.tsx +0 -61
- package/src/renderers/form/switch.tsx +0 -48
- package/src/renderers/form/textarea.tsx +0 -76
- package/src/renderers/form/toggle.tsx +0 -42
- package/src/renderers/index.ts +0 -18
- package/src/renderers/layout/aspect-ratio.tsx +0 -51
- package/src/renderers/layout/card.tsx +0 -85
- package/src/renderers/layout/container.tsx +0 -122
- package/src/renderers/layout/flex.tsx +0 -132
- package/src/renderers/layout/grid.tsx +0 -178
- package/src/renderers/layout/index.ts +0 -19
- package/src/renderers/layout/page.tsx +0 -466
- package/src/renderers/layout/semantic.tsx +0 -48
- package/src/renderers/layout/stack.tsx +0 -132
- package/src/renderers/layout/tabs.tsx +0 -97
- package/src/renderers/navigation/header-bar.tsx +0 -118
- package/src/renderers/navigation/index.ts +0 -10
- package/src/renderers/navigation/sidebar.tsx +0 -208
- package/src/renderers/overlay/alert-dialog.tsx +0 -72
- package/src/renderers/overlay/context-menu.tsx +0 -100
- package/src/renderers/overlay/dialog.tsx +0 -77
- package/src/renderers/overlay/drawer.tsx +0 -77
- package/src/renderers/overlay/dropdown-menu.tsx +0 -99
- package/src/renderers/overlay/hover-card.tsx +0 -55
- package/src/renderers/overlay/index.ts +0 -18
- package/src/renderers/overlay/menubar.tsx +0 -76
- package/src/renderers/overlay/popover.tsx +0 -56
- package/src/renderers/overlay/sheet.tsx +0 -77
- package/src/renderers/overlay/tooltip.tsx +0 -67
- package/src/renderers/placeholders.tsx +0 -107
- package/src/stories/CRMApp.stories.tsx +0 -706
- package/src/stories/ConfigPanel.stories.tsx +0 -232
- package/src/stories/Guide.mdx +0 -55
- package/src/stories/MockedData.stories.tsx +0 -121
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -1
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -1
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -1
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -1
- package/src/stories/assets/youtube.svg +0 -1
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/page.css +0 -68
- package/src/stories-json/Accessibility.mdx +0 -297
- package/src/stories-json/EdgeCases.stories.tsx +0 -160
- package/src/stories-json/GettingStarted.mdx +0 -89
- package/src/stories-json/Introduction.mdx +0 -127
- package/src/stories-json/accordion.stories.tsx +0 -43
- package/src/stories-json/aggrid.stories.tsx +0 -103
- package/src/stories-json/alert.stories.tsx +0 -39
- package/src/stories-json/aspect-ratio.stories.tsx +0 -34
- package/src/stories-json/avatar.stories.tsx +0 -38
- package/src/stories-json/badge.stories.tsx +0 -53
- package/src/stories-json/breadcrumb.stories.tsx +0 -30
- package/src/stories-json/button-group.stories.tsx +0 -43
- package/src/stories-json/button.stories.tsx +0 -73
- package/src/stories-json/calendar.stories.tsx +0 -85
- package/src/stories-json/card.stories.tsx +0 -48
- package/src/stories-json/carousel.stories.tsx +0 -33
- package/src/stories-json/charts.stories.tsx +0 -195
- package/src/stories-json/chatbot.stories.tsx +0 -349
- package/src/stories-json/code-editor.stories.tsx +0 -92
- package/src/stories-json/collapsible.stories.tsx +0 -40
- package/src/stories-json/controls.stories.tsx +0 -36
- package/src/stories-json/crm-live-data.stories.tsx +0 -154
- package/src/stories-json/dashboard.stories.tsx +0 -318
- package/src/stories-json/data-table.stories.tsx +0 -136
- package/src/stories-json/data_display_extras.stories.tsx +0 -102
- package/src/stories-json/date-picker.stories.tsx +0 -28
- package/src/stories-json/detail-view.stories.tsx +0 -258
- package/src/stories-json/dialog.stories.tsx +0 -43
- package/src/stories-json/feedback_extras.stories.tsx +0 -40
- package/src/stories-json/feedback_others.stories.tsx +0 -46
- package/src/stories-json/form-variants.stories.tsx +0 -210
- package/src/stories-json/form_advanced.stories.tsx +0 -117
- package/src/stories-json/form_extras.stories.tsx +0 -123
- package/src/stories-json/grid.stories.tsx +0 -56
- package/src/stories-json/icon.stories.tsx +0 -36
- package/src/stories-json/input.stories.tsx +0 -52
- package/src/stories-json/kanban.stories.tsx +0 -295
- package/src/stories-json/layout_extended.stories.tsx +0 -76
- package/src/stories-json/layout_flex.stories.tsx +0 -107
- package/src/stories-json/list-view.stories.tsx +0 -97
- package/src/stories-json/markdown.stories.tsx +0 -129
- package/src/stories-json/menus.stories.tsx +0 -63
- package/src/stories-json/metric-card.stories.tsx +0 -143
- package/src/stories-json/navigation-menu.stories.tsx +0 -37
- package/src/stories-json/object-aggrid-advanced.stories.tsx +0 -389
- package/src/stories-json/object-aggrid.stories.tsx +0 -252
- package/src/stories-json/object-form.stories.tsx +0 -130
- package/src/stories-json/object-gantt.stories.tsx +0 -114
- package/src/stories-json/object-grid.stories.tsx +0 -315
- package/src/stories-json/object-map.stories.tsx +0 -116
- package/src/stories-json/object-view.stories.tsx +0 -118
- package/src/stories-json/overlay_extras.stories.tsx +0 -113
- package/src/stories-json/overlay_others.stories.tsx +0 -76
- package/src/stories-json/page.stories.tsx +0 -55
- package/src/stories-json/reports.stories.tsx +0 -163
- package/src/stories-json/resizable.stories.tsx +0 -44
- package/src/stories-json/select.stories.tsx +0 -34
- package/src/stories-json/separator.stories.tsx +0 -41
- package/src/stories-json/sidebar.stories.tsx +0 -147
- package/src/stories-json/statistic.stories.tsx +0 -44
- package/src/stories-json/tabs.stories.tsx +0 -51
- package/src/stories-json/timeline.stories.tsx +0 -188
- package/src/stories-json/typography.stories.tsx +0 -45
- package/src/types/config-panel.ts +0 -101
- package/src/ui/accordion.tsx +0 -66
- package/src/ui/alert-dialog.tsx +0 -149
- package/src/ui/alert.tsx +0 -67
- package/src/ui/aspect-ratio.tsx +0 -15
- package/src/ui/avatar.tsx +0 -58
- package/src/ui/badge.tsx +0 -44
- package/src/ui/breadcrumb.tsx +0 -123
- package/src/ui/button.tsx +0 -64
- package/src/ui/calendar.tsx +0 -221
- package/src/ui/card.tsx +0 -87
- package/src/ui/carousel.tsx +0 -270
- package/src/ui/chart.tsx +0 -377
- package/src/ui/checkbox.tsx +0 -38
- package/src/ui/collapsible.tsx +0 -19
- package/src/ui/command.tsx +0 -161
- package/src/ui/context-menu.tsx +0 -208
- package/src/ui/dialog.tsx +0 -130
- package/src/ui/drawer.tsx +0 -126
- package/src/ui/dropdown-menu.tsx +0 -208
- package/src/ui/form.tsx +0 -186
- package/src/ui/hover-card.tsx +0 -37
- package/src/ui/index.ts +0 -56
- package/src/ui/input-otp.tsx +0 -79
- package/src/ui/input.tsx +0 -30
- package/src/ui/label.tsx +0 -34
- package/src/ui/menubar.tsx +0 -264
- package/src/ui/navigation-menu.tsx +0 -136
- package/src/ui/pagination.tsx +0 -125
- package/src/ui/popover.tsx +0 -39
- package/src/ui/progress.tsx +0 -36
- package/src/ui/radio-group.tsx +0 -52
- package/src/ui/resizable.tsx +0 -53
- package/src/ui/scroll-area.tsx +0 -56
- package/src/ui/select.tsx +0 -168
- package/src/ui/separator.tsx +0 -39
- package/src/ui/sheet.tsx +0 -150
- package/src/ui/sidebar.tsx +0 -781
- package/src/ui/skeleton.tsx +0 -23
- package/src/ui/slider.tsx +0 -39
- package/src/ui/sonner.tsx +0 -53
- package/src/ui/switch.tsx +0 -37
- package/src/ui/table.tsx +0 -125
- package/src/ui/tabs.tsx +0 -63
- package/src/ui/textarea.tsx +0 -30
- package/src/ui/toast.tsx +0 -137
- package/src/ui/toggle-group.tsx +0 -69
- package/src/ui/toggle.tsx +0 -53
- package/src/ui/tooltip.tsx +0 -38
- package/src/ui/typography.tsx +0 -85
- package/tsconfig.json +0 -19
- package/vite.config.ts +0 -71
- package/vitest.config.ts +0 -5
package/src/debug/DebugPanel.tsx
DELETED
|
@@ -1,313 +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
|
-
import React, { useState, useCallback, useMemo } from 'react';
|
|
10
|
-
import type { DebugFlags } from '@object-ui/core';
|
|
11
|
-
import { ComponentRegistry, DebugCollector } from '@object-ui/core';
|
|
12
|
-
import type { PerfEntry, ExprEntry, EventEntry, DebugEntry } from '@object-ui/core';
|
|
13
|
-
import { cn } from '../lib/utils';
|
|
14
|
-
|
|
15
|
-
/* ------------------------------------------------------------------ */
|
|
16
|
-
/* Types */
|
|
17
|
-
/* ------------------------------------------------------------------ */
|
|
18
|
-
|
|
19
|
-
export interface DebugPanelTab {
|
|
20
|
-
id: string;
|
|
21
|
-
label: string;
|
|
22
|
-
icon?: React.ReactNode;
|
|
23
|
-
render: () => React.ReactNode;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface DebugPanelProps {
|
|
27
|
-
/** Whether the panel is open */
|
|
28
|
-
open: boolean;
|
|
29
|
-
/** Toggle callback */
|
|
30
|
-
onClose: () => void;
|
|
31
|
-
/** Debug flags from the URL / hook */
|
|
32
|
-
flags?: DebugFlags;
|
|
33
|
-
/** Current schema being rendered (for the Schema tab) */
|
|
34
|
-
schema?: unknown;
|
|
35
|
-
/** Current data context (for the Data tab) */
|
|
36
|
-
dataContext?: unknown;
|
|
37
|
-
/** Extra tabs provided by plugins */
|
|
38
|
-
extraTabs?: DebugPanelTab[];
|
|
39
|
-
/** CSS class override */
|
|
40
|
-
className?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/* ------------------------------------------------------------------ */
|
|
44
|
-
/* Built-in tab renderers */
|
|
45
|
-
/* ------------------------------------------------------------------ */
|
|
46
|
-
|
|
47
|
-
function SchemaTab({ schema }: { schema?: unknown }) {
|
|
48
|
-
if (!schema) {
|
|
49
|
-
return <p className="text-xs text-muted-foreground italic">No schema available</p>;
|
|
50
|
-
}
|
|
51
|
-
return (
|
|
52
|
-
<pre className="text-[11px] leading-relaxed font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all">
|
|
53
|
-
{JSON.stringify(schema, null, 2)}
|
|
54
|
-
</pre>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function DataTab({ dataContext }: { dataContext?: unknown }) {
|
|
59
|
-
if (!dataContext) {
|
|
60
|
-
return <p className="text-xs text-muted-foreground italic">No data context available</p>;
|
|
61
|
-
}
|
|
62
|
-
return (
|
|
63
|
-
<pre className="text-[11px] leading-relaxed font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all">
|
|
64
|
-
{JSON.stringify(dataContext, null, 2)}
|
|
65
|
-
</pre>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function RegistryTab() {
|
|
70
|
-
const entries = useMemo(() => {
|
|
71
|
-
try {
|
|
72
|
-
return ComponentRegistry.getAllTypes();
|
|
73
|
-
} catch {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
}, []);
|
|
77
|
-
|
|
78
|
-
if (entries.length === 0) {
|
|
79
|
-
return <p className="text-xs text-muted-foreground italic">No registered components</p>;
|
|
80
|
-
}
|
|
81
|
-
return (
|
|
82
|
-
<div className="space-y-1 max-h-[60vh] overflow-auto">
|
|
83
|
-
{entries.map((name: string) => (
|
|
84
|
-
<div
|
|
85
|
-
key={name}
|
|
86
|
-
className="flex items-center gap-2 px-2 py-1 rounded text-xs font-mono bg-muted/30"
|
|
87
|
-
>
|
|
88
|
-
<span className="inline-block w-2 h-2 rounded-full bg-green-500 shrink-0" />
|
|
89
|
-
{name}
|
|
90
|
-
</div>
|
|
91
|
-
))}
|
|
92
|
-
<p className="text-[10px] text-muted-foreground mt-2">
|
|
93
|
-
{entries.length} component{entries.length !== 1 ? 's' : ''} registered
|
|
94
|
-
</p>
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function FlagsTab({ flags }: { flags?: DebugFlags }) {
|
|
100
|
-
if (!flags) {
|
|
101
|
-
return <p className="text-xs text-muted-foreground italic">No debug flags</p>;
|
|
102
|
-
}
|
|
103
|
-
return (
|
|
104
|
-
<pre className="text-[11px] leading-relaxed font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all">
|
|
105
|
-
{JSON.stringify(flags, null, 2)}
|
|
106
|
-
</pre>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* ------------------------------------------------------------------ */
|
|
111
|
-
/* Collector-backed tabs (Perf / Expr / Events) */
|
|
112
|
-
/* ------------------------------------------------------------------ */
|
|
113
|
-
|
|
114
|
-
function useCollectorEntries(kind?: DebugEntry['kind']): DebugEntry[] {
|
|
115
|
-
const collector = DebugCollector.getInstance();
|
|
116
|
-
const [entries, setEntries] = useState<DebugEntry[]>(() => collector.getEntries(kind));
|
|
117
|
-
|
|
118
|
-
React.useEffect(() => {
|
|
119
|
-
// Sync on mount in case entries were added before subscribe
|
|
120
|
-
setEntries(collector.getEntries(kind));
|
|
121
|
-
const unsub = collector.subscribe(() => {
|
|
122
|
-
setEntries(collector.getEntries(kind));
|
|
123
|
-
});
|
|
124
|
-
return unsub;
|
|
125
|
-
}, [collector, kind]);
|
|
126
|
-
|
|
127
|
-
return entries;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function PerfTab() {
|
|
131
|
-
const entries = useCollectorEntries('perf');
|
|
132
|
-
const perfItems = entries.map((e) => e.data as PerfEntry);
|
|
133
|
-
|
|
134
|
-
if (perfItems.length === 0) {
|
|
135
|
-
return <p className="text-xs text-muted-foreground italic">No performance data collected yet</p>;
|
|
136
|
-
}
|
|
137
|
-
return (
|
|
138
|
-
<div className="space-y-1 max-h-[60vh] overflow-auto">
|
|
139
|
-
{perfItems.map((p, i) => (
|
|
140
|
-
<div
|
|
141
|
-
key={i}
|
|
142
|
-
className={cn(
|
|
143
|
-
'flex items-center justify-between px-2 py-1 rounded text-xs font-mono',
|
|
144
|
-
p.durationMs > 16 ? 'bg-red-50 text-red-700' : 'bg-muted/30',
|
|
145
|
-
)}
|
|
146
|
-
>
|
|
147
|
-
<span className="truncate mr-2">{p.type}{p.id ? `:${p.id}` : ''}</span>
|
|
148
|
-
<span className="shrink-0 tabular-nums">{p.durationMs.toFixed(2)}ms</span>
|
|
149
|
-
</div>
|
|
150
|
-
))}
|
|
151
|
-
<p className="text-[10px] text-muted-foreground mt-2">
|
|
152
|
-
{perfItems.length} render{perfItems.length !== 1 ? 's' : ''} tracked
|
|
153
|
-
</p>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function ExprTab() {
|
|
159
|
-
const entries = useCollectorEntries('expr');
|
|
160
|
-
const exprItems = entries.map((e) => e.data as ExprEntry);
|
|
161
|
-
|
|
162
|
-
if (exprItems.length === 0) {
|
|
163
|
-
return <p className="text-xs text-muted-foreground italic">No expression evaluations tracked yet</p>;
|
|
164
|
-
}
|
|
165
|
-
return (
|
|
166
|
-
<div className="space-y-1.5 max-h-[60vh] overflow-auto">
|
|
167
|
-
{exprItems.map((ex, i) => (
|
|
168
|
-
<div key={i} className="px-2 py-1.5 rounded bg-muted/30 text-xs font-mono">
|
|
169
|
-
<div className="text-muted-foreground truncate">{ex.expression}</div>
|
|
170
|
-
<div className="mt-0.5">→ {JSON.stringify(ex.result)}</div>
|
|
171
|
-
</div>
|
|
172
|
-
))}
|
|
173
|
-
<p className="text-[10px] text-muted-foreground mt-2">
|
|
174
|
-
{exprItems.length} evaluation{exprItems.length !== 1 ? 's' : ''} tracked
|
|
175
|
-
</p>
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function EventsTab() {
|
|
181
|
-
const entries = useCollectorEntries('event');
|
|
182
|
-
const eventItems = entries.map((e) => e.data as EventEntry);
|
|
183
|
-
|
|
184
|
-
if (eventItems.length === 0) {
|
|
185
|
-
return <p className="text-xs text-muted-foreground italic">No events captured yet</p>;
|
|
186
|
-
}
|
|
187
|
-
return (
|
|
188
|
-
<div className="space-y-1.5 max-h-[60vh] overflow-auto">
|
|
189
|
-
{eventItems.map((ev, i) => (
|
|
190
|
-
<div key={i} className="px-2 py-1.5 rounded bg-muted/30 text-xs font-mono">
|
|
191
|
-
<div className="flex items-center justify-between">
|
|
192
|
-
<span className="font-semibold">{ev.action}</span>
|
|
193
|
-
<span className="text-[10px] text-muted-foreground tabular-nums">
|
|
194
|
-
{new Date(ev.timestamp).toLocaleTimeString()}
|
|
195
|
-
</span>
|
|
196
|
-
</div>
|
|
197
|
-
{ev.payload !== undefined && (
|
|
198
|
-
<pre className="mt-0.5 text-[10px] text-muted-foreground truncate">
|
|
199
|
-
{JSON.stringify(ev.payload)}
|
|
200
|
-
</pre>
|
|
201
|
-
)}
|
|
202
|
-
</div>
|
|
203
|
-
))}
|
|
204
|
-
<p className="text-[10px] text-muted-foreground mt-2">
|
|
205
|
-
{eventItems.length} event{eventItems.length !== 1 ? 's' : ''} captured
|
|
206
|
-
</p>
|
|
207
|
-
</div>
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* ------------------------------------------------------------------ */
|
|
212
|
-
/* DebugPanel */
|
|
213
|
-
/* ------------------------------------------------------------------ */
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* A floating developer debug panel activated via URL parameters or manual toggle.
|
|
217
|
-
*
|
|
218
|
-
* Built-in tabs:
|
|
219
|
-
* - **Schema** — current rendered JSON schema
|
|
220
|
-
* - **Data** — active data context
|
|
221
|
-
* - **Perf** — component render timing (highlights slow renders >16ms)
|
|
222
|
-
* - **Expr** — expression evaluation trace
|
|
223
|
-
* - **Events** — action/event timeline
|
|
224
|
-
* - **Registry** — all registered component types
|
|
225
|
-
* - **Flags** — current debug flags
|
|
226
|
-
*
|
|
227
|
-
* Plugins can inject additional tabs via the `extraTabs` prop.
|
|
228
|
-
*/
|
|
229
|
-
export function DebugPanel({
|
|
230
|
-
open,
|
|
231
|
-
onClose,
|
|
232
|
-
flags,
|
|
233
|
-
schema,
|
|
234
|
-
dataContext,
|
|
235
|
-
extraTabs = [],
|
|
236
|
-
className,
|
|
237
|
-
}: DebugPanelProps) {
|
|
238
|
-
const builtInTabs: DebugPanelTab[] = useMemo(() => [
|
|
239
|
-
{ id: 'schema', label: 'Schema', render: () => <SchemaTab schema={schema} /> },
|
|
240
|
-
{ id: 'data', label: 'Data', render: () => <DataTab dataContext={dataContext} /> },
|
|
241
|
-
{ id: 'perf', label: 'Perf', render: () => <PerfTab /> },
|
|
242
|
-
{ id: 'expr', label: 'Expr', render: () => <ExprTab /> },
|
|
243
|
-
{ id: 'events', label: 'Events', render: () => <EventsTab /> },
|
|
244
|
-
{ id: 'registry', label: 'Registry', render: () => <RegistryTab /> },
|
|
245
|
-
{ id: 'flags', label: 'Flags', render: () => <FlagsTab flags={flags} /> },
|
|
246
|
-
], [schema, dataContext, flags]);
|
|
247
|
-
|
|
248
|
-
const allTabs = useMemo(() => [...builtInTabs, ...extraTabs], [builtInTabs, extraTabs]);
|
|
249
|
-
const [activeTabId, setActiveTabId] = useState(allTabs[0]?.id ?? 'schema');
|
|
250
|
-
|
|
251
|
-
const activeTab = allTabs.find((t) => t.id === activeTabId) ?? allTabs[0];
|
|
252
|
-
|
|
253
|
-
const handleTabChange = useCallback((id: string) => {
|
|
254
|
-
setActiveTabId(id);
|
|
255
|
-
}, []);
|
|
256
|
-
|
|
257
|
-
if (!open) return null;
|
|
258
|
-
|
|
259
|
-
return (
|
|
260
|
-
<div
|
|
261
|
-
className={cn(
|
|
262
|
-
'fixed bottom-4 right-4 z-[9999] w-[420px] max-w-[95vw] rounded-lg border bg-background shadow-2xl',
|
|
263
|
-
'flex flex-col overflow-hidden',
|
|
264
|
-
className,
|
|
265
|
-
)}
|
|
266
|
-
data-testid="debug-panel"
|
|
267
|
-
role="dialog"
|
|
268
|
-
aria-label="Developer Debug Panel"
|
|
269
|
-
>
|
|
270
|
-
{/* Header */}
|
|
271
|
-
<div className="flex items-center justify-between px-3 py-2 border-b bg-muted/30">
|
|
272
|
-
<span className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
|
273
|
-
🛠 Debug Panel
|
|
274
|
-
</span>
|
|
275
|
-
<button
|
|
276
|
-
onClick={onClose}
|
|
277
|
-
className="text-muted-foreground hover:text-foreground text-sm leading-none px-1"
|
|
278
|
-
aria-label="Close debug panel"
|
|
279
|
-
data-testid="debug-panel-close"
|
|
280
|
-
>
|
|
281
|
-
✕
|
|
282
|
-
</button>
|
|
283
|
-
</div>
|
|
284
|
-
|
|
285
|
-
{/* Tabs */}
|
|
286
|
-
<div className="flex border-b overflow-x-auto" role="tablist">
|
|
287
|
-
{allTabs.map((tab) => (
|
|
288
|
-
<button
|
|
289
|
-
key={tab.id}
|
|
290
|
-
role="tab"
|
|
291
|
-
aria-selected={tab.id === activeTab?.id}
|
|
292
|
-
onClick={() => handleTabChange(tab.id)}
|
|
293
|
-
className={cn(
|
|
294
|
-
'px-3 py-1.5 text-xs font-medium whitespace-nowrap transition-colors',
|
|
295
|
-
tab.id === activeTab?.id
|
|
296
|
-
? 'border-b-2 border-primary text-foreground'
|
|
297
|
-
: 'text-muted-foreground hover:text-foreground',
|
|
298
|
-
)}
|
|
299
|
-
data-testid={`debug-tab-${tab.id}`}
|
|
300
|
-
>
|
|
301
|
-
{tab.icon && <span className="mr-1">{tab.icon}</span>}
|
|
302
|
-
{tab.label}
|
|
303
|
-
</button>
|
|
304
|
-
))}
|
|
305
|
-
</div>
|
|
306
|
-
|
|
307
|
-
{/* Content */}
|
|
308
|
-
<div className="p-3 overflow-auto max-h-[50vh]" data-testid="debug-panel-content">
|
|
309
|
-
{activeTab?.render()}
|
|
310
|
-
</div>
|
|
311
|
-
</div>
|
|
312
|
-
);
|
|
313
|
-
}
|
|
@@ -1,134 +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
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
10
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
11
|
-
import { DebugPanel } from '../DebugPanel';
|
|
12
|
-
|
|
13
|
-
describe('DebugPanel', () => {
|
|
14
|
-
it('should render nothing when open is false', () => {
|
|
15
|
-
const { container } = render(
|
|
16
|
-
<DebugPanel open={false} onClose={vi.fn()} />,
|
|
17
|
-
);
|
|
18
|
-
expect(container.innerHTML).toBe('');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should render the panel when open is true', () => {
|
|
22
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
23
|
-
expect(screen.getByTestId('debug-panel')).toBeInTheDocument();
|
|
24
|
-
expect(screen.getByText('🛠 Debug Panel')).toBeInTheDocument();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should render built-in tabs', () => {
|
|
28
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
29
|
-
expect(screen.getByTestId('debug-tab-schema')).toBeInTheDocument();
|
|
30
|
-
expect(screen.getByTestId('debug-tab-data')).toBeInTheDocument();
|
|
31
|
-
expect(screen.getByTestId('debug-tab-perf')).toBeInTheDocument();
|
|
32
|
-
expect(screen.getByTestId('debug-tab-expr')).toBeInTheDocument();
|
|
33
|
-
expect(screen.getByTestId('debug-tab-events')).toBeInTheDocument();
|
|
34
|
-
expect(screen.getByTestId('debug-tab-registry')).toBeInTheDocument();
|
|
35
|
-
expect(screen.getByTestId('debug-tab-flags')).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should call onClose when close button is clicked', () => {
|
|
39
|
-
const onClose = vi.fn();
|
|
40
|
-
render(<DebugPanel open={true} onClose={onClose} />);
|
|
41
|
-
fireEvent.click(screen.getByTestId('debug-panel-close'));
|
|
42
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should switch tabs on click', () => {
|
|
46
|
-
render(
|
|
47
|
-
<DebugPanel
|
|
48
|
-
open={true}
|
|
49
|
-
onClose={vi.fn()}
|
|
50
|
-
schema={{ type: 'text', content: 'Hello' }}
|
|
51
|
-
dataContext={{ name: 'Test' }}
|
|
52
|
-
/>,
|
|
53
|
-
);
|
|
54
|
-
// Default tab is Schema
|
|
55
|
-
expect(screen.getByTestId('debug-tab-schema')).toHaveAttribute('aria-selected', 'true');
|
|
56
|
-
|
|
57
|
-
// Click Data tab
|
|
58
|
-
fireEvent.click(screen.getByTestId('debug-tab-data'));
|
|
59
|
-
expect(screen.getByTestId('debug-tab-data')).toHaveAttribute('aria-selected', 'true');
|
|
60
|
-
expect(screen.getByTestId('debug-tab-schema')).toHaveAttribute('aria-selected', 'false');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should display schema JSON in Schema tab', () => {
|
|
64
|
-
const testSchema = { type: 'button', content: 'Click' };
|
|
65
|
-
render(<DebugPanel open={true} onClose={vi.fn()} schema={testSchema} />);
|
|
66
|
-
const content = screen.getByTestId('debug-panel-content');
|
|
67
|
-
expect(content.textContent).toContain('"type": "button"');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should display data JSON in Data tab', () => {
|
|
71
|
-
render(
|
|
72
|
-
<DebugPanel
|
|
73
|
-
open={true}
|
|
74
|
-
onClose={vi.fn()}
|
|
75
|
-
dataContext={{ user: 'Alice' }}
|
|
76
|
-
/>,
|
|
77
|
-
);
|
|
78
|
-
fireEvent.click(screen.getByTestId('debug-tab-data'));
|
|
79
|
-
const content = screen.getByTestId('debug-panel-content');
|
|
80
|
-
expect(content.textContent).toContain('"user": "Alice"');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should display debug flags in Flags tab', () => {
|
|
84
|
-
render(
|
|
85
|
-
<DebugPanel
|
|
86
|
-
open={true}
|
|
87
|
-
onClose={vi.fn()}
|
|
88
|
-
flags={{ enabled: true, schema: true }}
|
|
89
|
-
/>,
|
|
90
|
-
);
|
|
91
|
-
fireEvent.click(screen.getByTestId('debug-tab-flags'));
|
|
92
|
-
const content = screen.getByTestId('debug-panel-content');
|
|
93
|
-
expect(content.textContent).toContain('"enabled": true');
|
|
94
|
-
expect(content.textContent).toContain('"schema": true');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should render extra tabs from plugins', () => {
|
|
98
|
-
const extraTab = {
|
|
99
|
-
id: 'custom',
|
|
100
|
-
label: 'Custom',
|
|
101
|
-
render: () => <div data-testid="custom-content">Custom Content</div>,
|
|
102
|
-
};
|
|
103
|
-
render(<DebugPanel open={true} onClose={vi.fn()} extraTabs={[extraTab]} />);
|
|
104
|
-
expect(screen.getByTestId('debug-tab-custom')).toBeInTheDocument();
|
|
105
|
-
|
|
106
|
-
fireEvent.click(screen.getByTestId('debug-tab-custom'));
|
|
107
|
-
expect(screen.getByTestId('custom-content')).toBeInTheDocument();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should have proper accessibility attributes', () => {
|
|
111
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
112
|
-
const panel = screen.getByTestId('debug-panel');
|
|
113
|
-
expect(panel).toHaveAttribute('role', 'dialog');
|
|
114
|
-
expect(panel).toHaveAttribute('aria-label', 'Developer Debug Panel');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should show empty state for Perf tab', () => {
|
|
118
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
119
|
-
fireEvent.click(screen.getByTestId('debug-tab-perf'));
|
|
120
|
-
expect(screen.getByTestId('debug-panel-content').textContent).toContain('No performance data');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should show empty state for Expr tab', () => {
|
|
124
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
125
|
-
fireEvent.click(screen.getByTestId('debug-tab-expr'));
|
|
126
|
-
expect(screen.getByTestId('debug-panel-content').textContent).toContain('No expression evaluations');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should show empty state for Events tab', () => {
|
|
130
|
-
render(<DebugPanel open={true} onClose={vi.fn()} />);
|
|
131
|
-
fireEvent.click(screen.getByTestId('debug-tab-events'));
|
|
132
|
-
expect(screen.getByTestId('debug-panel-content').textContent).toContain('No events captured');
|
|
133
|
-
});
|
|
134
|
-
});
|
package/src/debug/index.ts
DELETED
|
@@ -1,10 +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
|
-
export { DebugPanel } from './DebugPanel';
|
|
10
|
-
export type { DebugPanelProps, DebugPanelTab } from './DebugPanel';
|
|
@@ -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
|
-
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
10
|
-
|
|
11
|
-
export interface UseConfigDraftOptions {
|
|
12
|
-
/** Panel mode: 'create' starts dirty; 'edit' starts clean */
|
|
13
|
-
mode?: 'create' | 'edit';
|
|
14
|
-
/** Optional callback invoked on every field change */
|
|
15
|
-
onUpdate?: (field: string, value: any) => void;
|
|
16
|
-
/** Maximum undo history size (default: 50) */
|
|
17
|
-
maxHistory?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface UseConfigDraftReturn<T extends Record<string, any>> {
|
|
21
|
-
/** The mutable draft copy */
|
|
22
|
-
draft: T;
|
|
23
|
-
/** Whether the draft differs from the source */
|
|
24
|
-
isDirty: boolean;
|
|
25
|
-
/** Update a single field in the draft */
|
|
26
|
-
updateField: (field: string, value: any) => void;
|
|
27
|
-
/** Revert draft back to source */
|
|
28
|
-
discard: () => void;
|
|
29
|
-
/** Low-level setter (use updateField for individual changes) */
|
|
30
|
-
setDraft: React.Dispatch<React.SetStateAction<T>>;
|
|
31
|
-
/** Undo the last change */
|
|
32
|
-
undo: () => void;
|
|
33
|
-
/** Redo a previously undone change */
|
|
34
|
-
redo: () => void;
|
|
35
|
-
/** Whether undo is available */
|
|
36
|
-
canUndo: boolean;
|
|
37
|
-
/** Whether redo is available */
|
|
38
|
-
canRedo: boolean;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Generic draft-state management for configuration panels.
|
|
43
|
-
*
|
|
44
|
-
* Mirrors the proven draft → save / discard pattern from ViewConfigPanel
|
|
45
|
-
* while being reusable across Dashboard, Form, Page, Report, and any
|
|
46
|
-
* future config panel. Includes undo/redo history support.
|
|
47
|
-
*
|
|
48
|
-
* @param source - The "committed" configuration object.
|
|
49
|
-
* @param options - Optional mode and change callback.
|
|
50
|
-
*/
|
|
51
|
-
export function useConfigDraft<T extends Record<string, any>>(
|
|
52
|
-
source: T,
|
|
53
|
-
options?: UseConfigDraftOptions,
|
|
54
|
-
): UseConfigDraftReturn<T> {
|
|
55
|
-
const maxHistory = options?.maxHistory ?? 50;
|
|
56
|
-
const [draft, setDraft] = useState<T>({ ...source });
|
|
57
|
-
const [isDirty, setIsDirty] = useState(options?.mode === 'create');
|
|
58
|
-
const pastRef = useRef<T[]>([]);
|
|
59
|
-
const futureRef = useRef<T[]>([]);
|
|
60
|
-
const [, forceRender] = useState(0);
|
|
61
|
-
|
|
62
|
-
// Reset draft when source identity changes
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
setDraft({ ...source });
|
|
65
|
-
setIsDirty(options?.mode === 'create');
|
|
66
|
-
pastRef.current = [];
|
|
67
|
-
futureRef.current = [];
|
|
68
|
-
}, [source]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
69
|
-
|
|
70
|
-
const updateField = useCallback(
|
|
71
|
-
(field: string, value: any) => {
|
|
72
|
-
setDraft((prev) => {
|
|
73
|
-
pastRef.current = [...pastRef.current.slice(-(maxHistory - 1)), prev];
|
|
74
|
-
futureRef.current = [];
|
|
75
|
-
return { ...prev, [field]: value };
|
|
76
|
-
});
|
|
77
|
-
setIsDirty(true);
|
|
78
|
-
forceRender((n) => n + 1);
|
|
79
|
-
options?.onUpdate?.(field, value);
|
|
80
|
-
},
|
|
81
|
-
[options?.onUpdate, maxHistory], // eslint-disable-line react-hooks/exhaustive-deps
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const undo = useCallback(() => {
|
|
85
|
-
if (pastRef.current.length === 0) return;
|
|
86
|
-
setDraft((prev) => {
|
|
87
|
-
const past = [...pastRef.current];
|
|
88
|
-
const previous = past.pop()!;
|
|
89
|
-
pastRef.current = past;
|
|
90
|
-
futureRef.current = [prev, ...futureRef.current];
|
|
91
|
-
return previous;
|
|
92
|
-
});
|
|
93
|
-
forceRender((n) => n + 1);
|
|
94
|
-
}, []);
|
|
95
|
-
|
|
96
|
-
const redo = useCallback(() => {
|
|
97
|
-
if (futureRef.current.length === 0) return;
|
|
98
|
-
setDraft((prev) => {
|
|
99
|
-
const future = [...futureRef.current];
|
|
100
|
-
const next = future.shift()!;
|
|
101
|
-
futureRef.current = future;
|
|
102
|
-
pastRef.current = [...pastRef.current, prev];
|
|
103
|
-
return next;
|
|
104
|
-
});
|
|
105
|
-
forceRender((n) => n + 1);
|
|
106
|
-
}, []);
|
|
107
|
-
|
|
108
|
-
const discard = useCallback(() => {
|
|
109
|
-
setDraft({ ...source });
|
|
110
|
-
setIsDirty(false);
|
|
111
|
-
pastRef.current = [];
|
|
112
|
-
futureRef.current = [];
|
|
113
|
-
forceRender((n) => n + 1);
|
|
114
|
-
}, [source]);
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
draft,
|
|
118
|
-
isDirty,
|
|
119
|
-
updateField,
|
|
120
|
-
discard,
|
|
121
|
-
setDraft,
|
|
122
|
-
undo,
|
|
123
|
-
redo,
|
|
124
|
-
canUndo: pastRef.current.length > 0,
|
|
125
|
-
canRedo: futureRef.current.length > 0,
|
|
126
|
-
};
|
|
127
|
-
}
|
package/src/hooks/use-mobile.tsx
DELETED
|
@@ -1,27 +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
|
-
import * as React from "react"
|
|
10
|
-
|
|
11
|
-
const MOBILE_BREAKPOINT = 768
|
|
12
|
-
|
|
13
|
-
export function useIsMobile() {
|
|
14
|
-
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
|
15
|
-
|
|
16
|
-
React.useEffect(() => {
|
|
17
|
-
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
18
|
-
const onChange = () => {
|
|
19
|
-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
20
|
-
}
|
|
21
|
-
mql.addEventListener("change", onChange)
|
|
22
|
-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
23
|
-
return () => mql.removeEventListener("change", onChange)
|
|
24
|
-
}, [])
|
|
25
|
-
|
|
26
|
-
return !!isMobile
|
|
27
|
-
}
|