@alaarab/ogrid-mcp 2.4.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/README.md +68 -0
- package/bundled-docs/api/README.md +94 -0
- package/bundled-docs/api/column-def.mdx +379 -0
- package/bundled-docs/api/components-column-chooser.mdx +310 -0
- package/bundled-docs/api/components-column-header-filter.mdx +363 -0
- package/bundled-docs/api/components-datagrid-table.mdx +316 -0
- package/bundled-docs/api/components-pagination-controls.mdx +344 -0
- package/bundled-docs/api/components-sidebar.mdx +427 -0
- package/bundled-docs/api/components-status-bar.mdx +309 -0
- package/bundled-docs/api/grid-api.mdx +299 -0
- package/bundled-docs/api/js-api.mdx +198 -0
- package/bundled-docs/api/ogrid-props.mdx +244 -0
- package/bundled-docs/api/types.mdx +640 -0
- package/bundled-docs/features/cell-references.mdx +225 -0
- package/bundled-docs/features/column-chooser.mdx +279 -0
- package/bundled-docs/features/column-groups.mdx +290 -0
- package/bundled-docs/features/column-pinning.mdx +282 -0
- package/bundled-docs/features/column-reordering.mdx +359 -0
- package/bundled-docs/features/column-types.mdx +181 -0
- package/bundled-docs/features/context-menu.mdx +216 -0
- package/bundled-docs/features/csv-export.mdx +227 -0
- package/bundled-docs/features/editing.mdx +377 -0
- package/bundled-docs/features/filtering.mdx +330 -0
- package/bundled-docs/features/formulas.mdx +381 -0
- package/bundled-docs/features/grid-api.mdx +311 -0
- package/bundled-docs/features/keyboard-navigation.mdx +236 -0
- package/bundled-docs/features/pagination.mdx +245 -0
- package/bundled-docs/features/performance.mdx +433 -0
- package/bundled-docs/features/row-selection.mdx +256 -0
- package/bundled-docs/features/server-side-data.mdx +291 -0
- package/bundled-docs/features/sidebar.mdx +234 -0
- package/bundled-docs/features/sorting.mdx +241 -0
- package/bundled-docs/features/spreadsheet-selection.mdx +201 -0
- package/bundled-docs/features/status-bar.mdx +205 -0
- package/bundled-docs/features/toolbar.mdx +284 -0
- package/bundled-docs/features/virtual-scrolling.mdx +624 -0
- package/bundled-docs/getting-started/installation.mdx +216 -0
- package/bundled-docs/getting-started/overview.mdx +151 -0
- package/bundled-docs/getting-started/quick-start.mdx +425 -0
- package/bundled-docs/getting-started/vanilla-js.mdx +191 -0
- package/bundled-docs/guides/accessibility.mdx +550 -0
- package/bundled-docs/guides/controlled-vs-uncontrolled.mdx +153 -0
- package/bundled-docs/guides/custom-cell-editors.mdx +201 -0
- package/bundled-docs/guides/framework-showcase.mdx +200 -0
- package/bundled-docs/guides/mcp-live-testing.mdx +291 -0
- package/bundled-docs/guides/mcp.mdx +172 -0
- package/bundled-docs/guides/migration-from-ag-grid.mdx +223 -0
- package/bundled-docs/guides/theming.mdx +211 -0
- package/dist/esm/bridge-client.d.ts +87 -0
- package/dist/esm/bridge-client.js +162 -0
- package/dist/esm/index.js +1060 -0
- package/package.json +43 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// src/bridge-client.ts
|
|
2
|
+
function connectGridToBridge(options) {
|
|
3
|
+
const {
|
|
4
|
+
gridId,
|
|
5
|
+
getData,
|
|
6
|
+
getColumns,
|
|
7
|
+
getPagination,
|
|
8
|
+
getSort,
|
|
9
|
+
getFilters,
|
|
10
|
+
api,
|
|
11
|
+
onCellUpdate,
|
|
12
|
+
bridgeUrl = "http://localhost:7890",
|
|
13
|
+
pollIntervalMs = 500
|
|
14
|
+
} = options;
|
|
15
|
+
let stopped = false;
|
|
16
|
+
let intervalId = null;
|
|
17
|
+
function buildState() {
|
|
18
|
+
const data = getData();
|
|
19
|
+
const columns = getColumns();
|
|
20
|
+
const pagination = getPagination?.() ?? {
|
|
21
|
+
page: 1,
|
|
22
|
+
pageSize: data.length,
|
|
23
|
+
totalCount: data.length,
|
|
24
|
+
pageCount: 1
|
|
25
|
+
};
|
|
26
|
+
const sortModel = getSort?.() ?? [];
|
|
27
|
+
const filterModel = getFilters?.() ?? {};
|
|
28
|
+
return {
|
|
29
|
+
gridId,
|
|
30
|
+
rowCount: data.length,
|
|
31
|
+
data: data.slice(0, 200),
|
|
32
|
+
// cap at 200 rows to keep payload small
|
|
33
|
+
columns,
|
|
34
|
+
sortModel,
|
|
35
|
+
filterModel,
|
|
36
|
+
...pagination
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function connect() {
|
|
40
|
+
try {
|
|
41
|
+
await fetch(`${bridgeUrl}/grids/connect`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify(buildState())
|
|
45
|
+
});
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function push() {
|
|
50
|
+
if (stopped) return;
|
|
51
|
+
try {
|
|
52
|
+
await fetch(`${bridgeUrl}/grids/${encodeURIComponent(gridId)}/state`, {
|
|
53
|
+
method: "PUT",
|
|
54
|
+
headers: { "Content-Type": "application/json" },
|
|
55
|
+
body: JSON.stringify(buildState())
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function handleCommand(cmd) {
|
|
61
|
+
let result = null;
|
|
62
|
+
let error;
|
|
63
|
+
try {
|
|
64
|
+
switch (cmd.type) {
|
|
65
|
+
case "update_cell": {
|
|
66
|
+
const rowIndex = cmd.payload["rowIndex"];
|
|
67
|
+
const columnId = cmd.payload["columnId"];
|
|
68
|
+
const value = cmd.payload["value"];
|
|
69
|
+
if (onCellUpdate) {
|
|
70
|
+
onCellUpdate(rowIndex, columnId, value);
|
|
71
|
+
result = { ok: true, rowIndex, columnId, value };
|
|
72
|
+
} else {
|
|
73
|
+
error = "No onCellUpdate handler provided";
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "set_filter": {
|
|
78
|
+
const columnId = cmd.payload["columnId"];
|
|
79
|
+
const value = cmd.payload["value"];
|
|
80
|
+
if (api?.updateFilter) {
|
|
81
|
+
api.updateFilter(columnId, value);
|
|
82
|
+
result = { ok: true };
|
|
83
|
+
} else {
|
|
84
|
+
error = "No api.updateFilter available";
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "clear_filters": {
|
|
89
|
+
if (api?.clearFilters) {
|
|
90
|
+
api.clearFilters();
|
|
91
|
+
result = { ok: true };
|
|
92
|
+
} else {
|
|
93
|
+
error = "No api.clearFilters available";
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "set_sort": {
|
|
98
|
+
const sortModel = cmd.payload["sortModel"];
|
|
99
|
+
if (api?.updateSort) {
|
|
100
|
+
api.updateSort(sortModel);
|
|
101
|
+
result = { ok: true };
|
|
102
|
+
} else {
|
|
103
|
+
error = "No api.updateSort available";
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "go_to_page": {
|
|
108
|
+
const page = cmd.payload["page"];
|
|
109
|
+
if (api?.goToPage) {
|
|
110
|
+
api.goToPage(page);
|
|
111
|
+
result = { ok: true };
|
|
112
|
+
} else {
|
|
113
|
+
error = "No api.goToPage available";
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
error = `Unknown command type: ${cmd.type}`;
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
error = String(e);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
await fetch(
|
|
125
|
+
`${bridgeUrl}/grids/${encodeURIComponent(gridId)}/commands/${encodeURIComponent(cmd.id)}/result`,
|
|
126
|
+
{
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: { "Content-Type": "application/json" },
|
|
129
|
+
body: JSON.stringify({ result, error })
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function tick() {
|
|
136
|
+
if (stopped) return;
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch(
|
|
139
|
+
`${bridgeUrl}/grids/${encodeURIComponent(gridId)}/commands`
|
|
140
|
+
);
|
|
141
|
+
if (res.ok) {
|
|
142
|
+
const cmds = await res.json();
|
|
143
|
+
for (const cmd of cmds) {
|
|
144
|
+
void handleCommand(cmd);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
await push();
|
|
150
|
+
}
|
|
151
|
+
void connect();
|
|
152
|
+
intervalId = setInterval(() => void tick(), pollIntervalMs);
|
|
153
|
+
return {
|
|
154
|
+
disconnect() {
|
|
155
|
+
stopped = true;
|
|
156
|
+
if (intervalId !== null) clearInterval(intervalId);
|
|
157
|
+
},
|
|
158
|
+
push
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { connectGridToBridge };
|