@object-ui/plugin-aggrid 0.4.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +99 -0
  2. package/CHANGELOG.md +16 -0
  3. package/OBJECT_AGGRID_CN.md +483 -0
  4. package/QUICKSTART.md +186 -0
  5. package/README.md +221 -1
  6. package/dist/AddressField-Bntpynvd.js +95 -0
  7. package/dist/AgGridImpl-3Mmf2qrR.js +229 -0
  8. package/dist/AutoNumberField-C1kBJaxh.js +8 -0
  9. package/dist/FileField-BDwbJvor.js +101 -0
  10. package/dist/FormulaField-BXNiyGoh.js +9 -0
  11. package/dist/GeolocationField-Df3yYcM9.js +141 -0
  12. package/dist/GridField-CcjQp4WM.js +29 -0
  13. package/dist/LocationField-BIfN5QIq.js +33 -0
  14. package/dist/MasterDetailField-CAEmxbIT.js +117 -0
  15. package/dist/ObjectAgGridImpl-EjifM4aY.js +28727 -0
  16. package/dist/ObjectField-BpkQpIF-.js +51 -0
  17. package/dist/QRCodeField-VCBewTDG.js +96 -0
  18. package/dist/RichTextField-CyQwSi2C.js +37 -0
  19. package/dist/SignatureField-Cr4tsEbj.js +96 -0
  20. package/dist/SummaryField-CnEJ_GZI.js +9 -0
  21. package/dist/UserField-DJjaVyrV.js +49 -0
  22. package/dist/VectorField-cPYmcKnV.js +25 -0
  23. package/dist/{index-B6NPAFZx.js → index-B87wd1E0.js} +301 -143
  24. package/dist/index.css +1 -1
  25. package/dist/index.js +4 -3
  26. package/dist/index.umd.cjs +225 -2
  27. package/dist/src/AgGridImpl.d.ts +5 -2
  28. package/dist/src/ObjectAgGridImpl.d.ts +6 -0
  29. package/dist/src/VirtualScrolling.d.ts +72 -0
  30. package/dist/src/field-renderers.d.ts +67 -0
  31. package/dist/src/index.d.ts +47 -2
  32. package/dist/src/object-aggrid.types.d.ts +74 -0
  33. package/dist/src/types.d.ts +48 -1
  34. package/package.json +11 -9
  35. package/src/AgGridImpl.tsx +100 -11
  36. package/src/ObjectAgGridImpl.tsx +501 -0
  37. package/src/VirtualScrolling.ts +74 -0
  38. package/src/field-renderers.test.tsx +383 -0
  39. package/src/field-renderers.tsx +224 -0
  40. package/src/index.test.ts +1 -1
  41. package/src/index.tsx +211 -2
  42. package/src/object-aggrid.test.ts +99 -0
  43. package/src/object-aggrid.types.ts +123 -0
  44. package/src/types.ts +57 -1
  45. package/vite.config.ts +13 -0
  46. package/dist/AgGridImpl-DKkq6v1B.js +0 -171
package/QUICKSTART.md ADDED
@@ -0,0 +1,186 @@
1
+ # Quick Start Guide - ObjectAgGrid
2
+
3
+ ## Installation
4
+
5
+ The ObjectAgGrid component is already installed as part of the @object-ui/plugin-aggrid package.
6
+
7
+ ## Basic Usage
8
+
9
+ ### Step 1: Import Required Packages
10
+
11
+ ```typescript
12
+ import { ObjectStackAdapter } from '@object-ui/data-objectstack';
13
+ import '@object-ui/plugin-aggrid'; // Auto-registers the component
14
+ ```
15
+
16
+ ### Step 2: Create a Data Source
17
+
18
+ ```typescript
19
+ const dataSource = new ObjectStackAdapter({
20
+ baseUrl: 'https://your-api.example.com',
21
+ token: 'your-auth-token' // Optional
22
+ });
23
+ ```
24
+
25
+ ### Step 3: Define Your Schema
26
+
27
+ ```typescript
28
+ const gridSchema = {
29
+ type: 'object-aggrid',
30
+ objectName: 'contacts', // The object to fetch from your backend
31
+ dataSource: dataSource,
32
+ pagination: true,
33
+ pageSize: 20,
34
+ theme: 'quartz',
35
+ height: 600
36
+ };
37
+ ```
38
+
39
+ ### Step 4: Use in Your Component
40
+
41
+ ```typescript
42
+ import { SchemaRenderer } from '@object-ui/components';
43
+
44
+ function MyComponent() {
45
+ return (
46
+ <div>
47
+ <h1>My Contacts</h1>
48
+ <SchemaRenderer schema={gridSchema} />
49
+ </div>
50
+ );
51
+ }
52
+ ```
53
+
54
+ ## Common Use Cases
55
+
56
+ ### Show Only Specific Fields
57
+
58
+ ```typescript
59
+ const schema = {
60
+ type: 'object-aggrid',
61
+ objectName: 'contacts',
62
+ dataSource: dataSource,
63
+ fieldNames: ['name', 'email', 'phone', 'company'], // Only show these
64
+ pagination: true
65
+ };
66
+ ```
67
+
68
+ ### Enable Inline Editing
69
+
70
+ ```typescript
71
+ const schema = {
72
+ type: 'object-aggrid',
73
+ objectName: 'tasks',
74
+ dataSource: dataSource,
75
+ editable: true,
76
+ singleClickEdit: true, // Single-click to edit
77
+ callbacks: {
78
+ onCellValueChanged: (event) => {
79
+ console.log('Updated:', event.data);
80
+ // Changes are automatically saved to backend!
81
+ }
82
+ }
83
+ };
84
+ ```
85
+
86
+ ### Add Filters and Sorting
87
+
88
+ ```typescript
89
+ const schema = {
90
+ type: 'object-aggrid',
91
+ objectName: 'products',
92
+ dataSource: dataSource,
93
+ filters: {
94
+ category: 'Electronics',
95
+ price: { $lt: 1000 }
96
+ },
97
+ sort: {
98
+ price: 'asc'
99
+ }
100
+ };
101
+ ```
102
+
103
+ ### Enable CSV Export
104
+
105
+ ```typescript
106
+ const schema = {
107
+ type: 'object-aggrid',
108
+ objectName: 'sales',
109
+ dataSource: dataSource,
110
+ exportConfig: {
111
+ enabled: true,
112
+ fileName: 'sales-report.csv'
113
+ }
114
+ };
115
+ ```
116
+
117
+ ## What Happens Automatically
118
+
119
+ When you use ObjectAgGrid, it automatically:
120
+
121
+ 1. ✅ Fetches the object schema (field definitions) from your backend
122
+ 2. ✅ Generates appropriate column definitions based on field types
123
+ 3. ✅ Applies proper formatters (currency, dates, percentages, etc.)
124
+ 4. ✅ Loads data with pagination
125
+ 5. ✅ Saves edits back to the backend (when `editable: true`)
126
+
127
+ ## Field Types Automatically Formatted
128
+
129
+ - **Currency**: `$1,234.56`
130
+ - **Percent**: `45.5%`
131
+ - **Date**: Localized date format
132
+ - **Boolean**: ✓ Yes / ✗ No
133
+ - **Email**: Clickable mailto links
134
+ - **Phone**: Clickable tel links
135
+ - **URL**: Clickable external links
136
+ - **Color**: Color swatches
137
+ - **Rating**: Star ratings ⭐⭐⭐⭐⭐
138
+ - And 20+ more field types!
139
+
140
+ ## Backend Requirements
141
+
142
+ Your ObjectStack backend should provide:
143
+
144
+ 1. **Metadata Endpoint**: Returns object schema with field definitions
145
+ ```typescript
146
+ GET /api/v1/metadata/object/{objectName}
147
+ ```
148
+
149
+ 2. **Data Endpoint**: Returns paginated data
150
+ ```typescript
151
+ GET /api/data/{objectName}?$top=20&$skip=0
152
+ ```
153
+
154
+ 3. **Update Endpoint** (for editable grids):
155
+ ```typescript
156
+ PATCH /api/data/{objectName}/{id}
157
+ ```
158
+
159
+ ## Next Steps
160
+
161
+ - See `OBJECT_AGGRID_CN.md` for Chinese documentation
162
+ - See `examples/object-aggrid-demo.tsx` for complete examples
163
+ - See `README.md` for full API reference
164
+
165
+ ## Troubleshooting
166
+
167
+ **Data not loading?**
168
+ - Check that your `dataSource` is properly initialized
169
+ - Verify the `objectName` exists in your backend
170
+ - Check browser console for errors
171
+
172
+ **Columns not showing?**
173
+ - Verify your object schema has field definitions
174
+ - Check that fields have `name` and `type` properties
175
+
176
+ **Editing not working?**
177
+ - Make sure `editable: true` is set
178
+ - Verify fields are not marked as `readonly`
179
+ - Check that your backend update endpoint is working
180
+
181
+ ## Support
182
+
183
+ For issues or questions, please refer to:
184
+ - Full documentation in `README.md`
185
+ - Chinese documentation in `OBJECT_AGGRID_CN.md`
186
+ - Implementation details in `IMPLEMENTATION_SUMMARY.md`
package/README.md CHANGED
@@ -31,6 +31,21 @@ pnpm add @object-ui/plugin-aggrid ag-grid-community ag-grid-react
31
31
 
32
32
  Note: `ag-grid-community` and `ag-grid-react` are peer dependencies and must be installed separately.
33
33
 
34
+ ### Next.js App Router Setup
35
+
36
+ If you're using Next.js with the App Router and dynamic imports, you may need to import AG Grid CSS in your root layout to ensure styles load correctly:
37
+
38
+ ```typescript
39
+ // app/layout.tsx
40
+ import 'ag-grid-community/styles/ag-grid.css';
41
+ import 'ag-grid-community/styles/ag-theme-quartz.css';
42
+ import 'ag-grid-community/styles/ag-theme-alpine.css';
43
+ import 'ag-grid-community/styles/ag-theme-balham.css';
44
+ import 'ag-grid-community/styles/ag-theme-material.css';
45
+ ```
46
+
47
+ This is necessary when the plugin is loaded dynamically (e.g., via `React.lazy()` or dynamic imports in client components), as Next.js may not properly process CSS imports from dynamically loaded modules.
48
+
34
49
  ## Usage
35
50
 
36
51
  ### Automatic Registration (Side-Effect Import)
@@ -497,7 +512,212 @@ pnpm type-check
497
512
 
498
513
  MIT
499
514
 
500
- ## Resources
515
+ ## Object AgGrid - Metadata-Driven AG Grid
516
+
517
+ The `object-aggrid` component extends the standard `aggrid` with metadata-driven capabilities using `@objectstack/client`. It automatically fetches object schemas and data, and generates appropriate column definitions based on field types.
518
+
519
+ ### Features
520
+
521
+ - **Automatic Metadata Fetching**: Retrieves object schema from ObjectStack backend
522
+ - **Automatic Data Loading**: Fetches data with pagination, filtering, and sorting
523
+ - **Field Type Support**: Supports all ObjectUI field types with appropriate formatters and renderers
524
+ - **Inline Editing**: Automatically saves changes to the backend
525
+ - **Zero Column Configuration**: Columns are generated from metadata
526
+ - **Selective Field Display**: Optionally show only specific fields
527
+
528
+ ### Installation
529
+
530
+ ```bash
531
+ pnpm add @object-ui/plugin-aggrid @object-ui/data-objectstack ag-grid-community ag-grid-react
532
+ ```
533
+
534
+ ### Usage
535
+
536
+ ```typescript
537
+ import '@object-ui/plugin-aggrid';
538
+ import { ObjectStackAdapter } from '@object-ui/data-objectstack';
539
+
540
+ // Create data source
541
+ const dataSource = new ObjectStackAdapter({
542
+ baseUrl: 'https://api.example.com',
543
+ token: 'your-api-token'
544
+ });
545
+
546
+ // Use in schema
547
+ const schema = {
548
+ type: 'object-aggrid',
549
+ objectName: 'contacts', // Object to fetch
550
+ dataSource: dataSource, // ObjectStack data source
551
+ pagination: true,
552
+ pageSize: 20,
553
+ theme: 'quartz',
554
+ height: 600
555
+ };
556
+ ```
557
+
558
+ ### Supported Field Types
559
+
560
+ The component automatically applies appropriate formatters and cell renderers for all field types:
561
+
562
+ - **Text Types**: text, textarea, markdown, html
563
+ - **Numeric Types**: number, currency (with locale formatting), percent
564
+ - **Boolean**: Displays ✓ Yes / ✗ No
565
+ - **Date/Time**: date, datetime, time (with locale formatting)
566
+ - **Contact**: email (clickable mailto), phone (clickable tel), url (clickable link)
567
+ - **Select/Lookup**: select, lookup, master_detail (shows labels)
568
+ - **Visual**: color (with color swatch), image, avatar, rating (stars)
569
+ - **Advanced**: formula, summary, auto_number, user, file
570
+
571
+ ### Schema API for Object AgGrid
572
+
573
+ ```typescript
574
+ {
575
+ type: 'object-aggrid',
576
+
577
+ // Required
578
+ objectName: string, // Name of the object to fetch
579
+ dataSource: DataSource, // ObjectStack data source instance
580
+
581
+ // Optional Field Configuration
582
+ fieldNames?: string[], // Show only these fields (default: all)
583
+ fields?: FieldMetadata[], // Override field metadata
584
+
585
+ // Query Parameters
586
+ filters?: Record<string, any>, // Query filters
587
+ sort?: Record<string, 'asc' | 'desc'>, // Sorting
588
+ pageSize?: number, // Rows per page (default: 10)
589
+
590
+ // Display Options (same as aggrid)
591
+ pagination?: boolean, // Enable pagination (default: true)
592
+ theme?: string, // Grid theme (default: 'quartz')
593
+ height?: number | string, // Grid height (default: 500)
594
+
595
+ // Editing
596
+ editable?: boolean, // Enable inline editing (auto-saves to backend)
597
+
598
+ // Export, Status Bar, Callbacks, etc. (same as aggrid)
599
+ exportConfig?: ExportConfig,
600
+ statusBar?: StatusBarConfig,
601
+ columnConfig?: ColumnConfig,
602
+ callbacks?: {
603
+ onDataLoaded?: (data: any[]) => void,
604
+ onDataError?: (error: Error) => void,
605
+ // ... other aggrid callbacks
606
+ }
607
+ }
608
+ ```
609
+
610
+ ### Examples
611
+
612
+ #### Basic Usage
613
+
614
+ ```typescript
615
+ const schema = {
616
+ type: 'object-aggrid',
617
+ objectName: 'users',
618
+ dataSource: myDataSource,
619
+ pagination: true,
620
+ pageSize: 25
621
+ };
622
+ ```
623
+
624
+ #### With Field Selection
625
+
626
+ ```typescript
627
+ const schema = {
628
+ type: 'object-aggrid',
629
+ objectName: 'contacts',
630
+ dataSource: myDataSource,
631
+ fieldNames: ['name', 'email', 'phone', 'company'],
632
+ pagination: true
633
+ };
634
+ ```
635
+
636
+ #### With Filters and Sorting
637
+
638
+ ```typescript
639
+ const schema = {
640
+ type: 'object-aggrid',
641
+ objectName: 'products',
642
+ dataSource: myDataSource,
643
+ filters: {
644
+ category: 'Electronics',
645
+ price: { $lt: 1000 }
646
+ },
647
+ sort: {
648
+ price: 'asc'
649
+ },
650
+ pagination: true
651
+ };
652
+ ```
653
+
654
+ #### Editable Grid with Auto-Save
655
+
656
+ ```typescript
657
+ const schema = {
658
+ type: 'object-aggrid',
659
+ objectName: 'tasks',
660
+ dataSource: myDataSource,
661
+ editable: true, // Enable editing
662
+ singleClickEdit: true, // Single-click to edit
663
+ callbacks: {
664
+ onCellValueChanged: (event) => {
665
+ // Changes are automatically saved to backend
666
+ console.log('Saved:', event.data);
667
+ }
668
+ }
669
+ };
670
+ ```
671
+
672
+ #### With Export
673
+
674
+ ```typescript
675
+ const schema = {
676
+ type: 'object-aggrid',
677
+ objectName: 'sales',
678
+ dataSource: myDataSource,
679
+ exportConfig: {
680
+ enabled: true,
681
+ fileName: 'sales-report.csv'
682
+ }
683
+ };
684
+ ```
685
+
686
+ ### Field Type Formatting Examples
687
+
688
+ **Currency Field:**
689
+ ```typescript
690
+ // Schema defines: { type: 'currency', currency: 'USD', precision: 2 }
691
+ // Renders as: $1,234.56
692
+ ```
693
+
694
+ **Percent Field:**
695
+ ```typescript
696
+ // Schema defines: { type: 'percent', precision: 1 }
697
+ // Renders as: 45.5%
698
+ ```
699
+
700
+ **Email Field:**
701
+ ```typescript
702
+ // Schema defines: { type: 'email' }
703
+ // Renders as: <a href="mailto:user@example.com">user@example.com</a>
704
+ ```
705
+
706
+ **Rating Field:**
707
+ ```typescript
708
+ // Schema defines: { type: 'rating', max: 5 }
709
+ // Renders as: ⭐⭐⭐⭐⭐
710
+ ```
711
+
712
+ **Color Field:**
713
+ ```typescript
714
+ // Schema defines: { type: 'color' }
715
+ // Renders as: [color swatch] #FF5733
716
+ ```
717
+
718
+ ## License
719
+
720
+
501
721
 
502
722
  - [AG Grid Community Documentation](https://www.ag-grid.com/documentation/)
503
723
  - [AG Grid Column Definitions](https://www.ag-grid.com/documentation/javascript/column-definitions/)
@@ -0,0 +1,95 @@
1
+ import { j as e } from "./index-B87wd1E0.js";
2
+ import { Label as d, Input as r } from "@object-ui/components";
3
+ function u({ value: n, onChange: o, field: h, readonly: a, ...i }) {
4
+ const s = n || {}, l = (t, c) => {
5
+ o({
6
+ ...s,
7
+ [t]: c
8
+ });
9
+ }, x = (t) => [
10
+ t.street,
11
+ t.city,
12
+ [t.state, t.zipCode].filter(Boolean).join(" "),
13
+ t.country
14
+ ].filter(Boolean).join(", ") || "-";
15
+ return a ? /* @__PURE__ */ e.jsx("span", { className: "text-sm", children: x(s) }) : /* @__PURE__ */ e.jsxs("div", { className: "space-y-3", children: [
16
+ /* @__PURE__ */ e.jsxs("div", { children: [
17
+ /* @__PURE__ */ e.jsx(d, { htmlFor: "street", className: "text-xs", children: "Street Address" }),
18
+ /* @__PURE__ */ e.jsx(
19
+ r,
20
+ {
21
+ id: "street",
22
+ type: "text",
23
+ value: s.street || "",
24
+ onChange: (t) => l("street", t.target.value),
25
+ placeholder: "123 Main St",
26
+ disabled: a || i.disabled,
27
+ className: i.className
28
+ }
29
+ )
30
+ ] }),
31
+ /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
32
+ /* @__PURE__ */ e.jsxs("div", { children: [
33
+ /* @__PURE__ */ e.jsx(d, { htmlFor: "city", className: "text-xs", children: "City" }),
34
+ /* @__PURE__ */ e.jsx(
35
+ r,
36
+ {
37
+ id: "city",
38
+ type: "text",
39
+ value: s.city || "",
40
+ onChange: (t) => l("city", t.target.value),
41
+ placeholder: "San Francisco",
42
+ disabled: a || i.disabled
43
+ }
44
+ )
45
+ ] }),
46
+ /* @__PURE__ */ e.jsxs("div", { children: [
47
+ /* @__PURE__ */ e.jsx(d, { htmlFor: "state", className: "text-xs", children: "State / Province" }),
48
+ /* @__PURE__ */ e.jsx(
49
+ r,
50
+ {
51
+ id: "state",
52
+ type: "text",
53
+ value: s.state || "",
54
+ onChange: (t) => l("state", t.target.value),
55
+ placeholder: "CA",
56
+ disabled: a || i.disabled
57
+ }
58
+ )
59
+ ] })
60
+ ] }),
61
+ /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
62
+ /* @__PURE__ */ e.jsxs("div", { children: [
63
+ /* @__PURE__ */ e.jsx(d, { htmlFor: "zipCode", className: "text-xs", children: "ZIP / Postal Code" }),
64
+ /* @__PURE__ */ e.jsx(
65
+ r,
66
+ {
67
+ id: "zipCode",
68
+ type: "text",
69
+ value: s.zipCode || "",
70
+ onChange: (t) => l("zipCode", t.target.value),
71
+ placeholder: "94102",
72
+ disabled: a || i.disabled
73
+ }
74
+ )
75
+ ] }),
76
+ /* @__PURE__ */ e.jsxs("div", { children: [
77
+ /* @__PURE__ */ e.jsx(d, { htmlFor: "country", className: "text-xs", children: "Country" }),
78
+ /* @__PURE__ */ e.jsx(
79
+ r,
80
+ {
81
+ id: "country",
82
+ type: "text",
83
+ value: s.country || "",
84
+ onChange: (t) => l("country", t.target.value),
85
+ placeholder: "United States",
86
+ disabled: a || i.disabled
87
+ }
88
+ )
89
+ ] })
90
+ ] })
91
+ ] });
92
+ }
93
+ export {
94
+ u as AddressField
95
+ };