@vuu-ui/vuu-data-react 0.8.5 → 0.8.6-debug

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 (35) hide show
  1. package/cjs/index.js +499 -1
  2. package/cjs/index.js.map +3 -3
  3. package/esm/index.js +480 -1
  4. package/esm/index.js.map +3 -3
  5. package/package.json +8 -8
  6. package/types/{hooks → vuu-data-react/src/hooks}/useVuuMenuActions.d.ts +5 -6
  7. package/types/vuu-popups/src/dialog/Dialog.d.ts +7 -0
  8. package/types/vuu-popups/src/dialog/index.d.ts +1 -0
  9. package/types/vuu-popups/src/index.d.ts +5 -0
  10. package/types/vuu-popups/src/menu/ContextMenu.d.ts +15 -0
  11. package/types/vuu-popups/src/menu/MenuList.d.ts +43 -0
  12. package/types/vuu-popups/src/menu/context-menu-provider.d.ts +10 -0
  13. package/types/vuu-popups/src/menu/index.d.ts +4 -0
  14. package/types/vuu-popups/src/menu/key-code.d.ts +12 -0
  15. package/types/vuu-popups/src/menu/list-dom-utils.d.ts +4 -0
  16. package/types/vuu-popups/src/menu/use-cascade.d.ts +25 -0
  17. package/types/vuu-popups/src/menu/use-items-with-ids-next.d.ts +13 -0
  18. package/types/vuu-popups/src/menu/use-keyboard-navigation.d.ts +26 -0
  19. package/types/vuu-popups/src/menu/useContextMenu.d.ts +13 -0
  20. package/types/vuu-popups/src/menu/utils.d.ts +2 -0
  21. package/types/vuu-popups/src/popup/index.d.ts +1 -0
  22. package/types/vuu-popups/src/popup/popup-service.d.ts +55 -0
  23. package/types/vuu-popups/src/popup-menu/PopupMenu.d.ts +14 -0
  24. package/types/vuu-popups/src/popup-menu/index.d.ts +1 -0
  25. package/types/vuu-popups/src/portal/Portal.d.ts +8 -0
  26. package/types/vuu-popups/src/portal/index.d.ts +3 -0
  27. package/types/vuu-popups/src/portal/portal-utils.d.ts +1 -0
  28. package/types/vuu-popups/src/portal/render-portal.d.ts +10 -0
  29. /package/types/{hooks → vuu-data-react/src/hooks}/index.d.ts +0 -0
  30. /package/types/{hooks → vuu-data-react/src/hooks}/useDataSource.d.ts +0 -0
  31. /package/types/{hooks → vuu-data-react/src/hooks}/useServerConnectionQuality.d.ts +0 -0
  32. /package/types/{hooks → vuu-data-react/src/hooks}/useServerConnectionStatus.d.ts +0 -0
  33. /package/types/{hooks → vuu-data-react/src/hooks}/useTypeaheadSuggestions.d.ts +0 -0
  34. /package/types/{hooks → vuu-data-react/src/hooks}/useVuuTables.d.ts +0 -0
  35. /package/types/{index.d.ts → vuu-data-react/src/index.d.ts} +0 -0
package/esm/index.js CHANGED
@@ -1,2 +1,481 @@
1
- import{getFullRange as g,metadataKeys as P,WindowRange as A}from"@vuu-ui/vuu-utils";import{useCallback as V,useEffect as h,useMemo as w,useRef as f,useState as E}from"react";var{SELECTED:C}=P;function me({dataSource:e,renderBufferSize:t=10}){let[,n]=E(null),r=f(!0),o=f(!1),c=f(null),s=f([]),a=f({from:0,to:10}),i=w(()=>new R(g(a.current,t)),[t]),m=V(u=>{for(let l of u)i.add(l);s.current=i.data.slice(),o.current=!0},[i]),M=V(u=>{u.type==="viewport-update"&&(u.size!==void 0&&i.setRowCount(u.size),u.rows?(m(u.rows),n({})):u.size!==void 0&&(s.current=i.data.slice(),o.current=!0))},[i,m]);h(()=>()=>{c.current&&(cancelAnimationFrame(c.current),c.current=null),r.current=!1},[]);let d=V(u=>{a.current=u;let l=g(a.current,t);e.range=l,i.setRange(l.from,l.to)},[e,i,t]);return w(()=>{let{from:u,to:l}=a.current,p=g({from:u,to:l},t);e.range=p,i.setRange(p.from,p.to)},[e,i,t]),h(()=>{let{from:u,to:l}=g(a.current,t);e.subscribe({range:{from:u,to:l}},M)},[e,M,t]),h(()=>()=>{e.unsubscribe()},[e]),[s.current,i.rowCount,g(a.current,t),d]}var R=class{constructor({from:t,to:n}){this.rowCount=0;this.setRowCount=t=>{t<this.data.length&&(this.data.length=t),this.rowCount=t};this.range=new A(t,n),this.data=new Array(n-t)}add(t){let[n]=t;if(this.isWithinRange(n)){let r=n-this.range.from;this.data[r]=t,this.data[r-1]&&this.data[r-1][C]===1&&t[C]===0&&(t[C]=2),n===this.rowCount-1&&(this.data.length=r+1)}}getAtIndex(t){return this.range.isWithin(t)&&this.data[t-this.range.from]!=null?this.data[t-this.range.from]:void 0}isWithinRange(t){return this.range.isWithin(t)}setRange(t,n){if(t!==this.range.from||n!==this.range.to){let[r,o]=this.range.overlap(t,n),c=new Array(n-t);for(let s=r;s<o;s++){let a=this.getAtIndex(s);if(a){let i=s-t;c[i]=a}}this.data=c,this.range.from=t,this.range.to=n}}};import{useCallback as O,useEffect as _,useState as F}from"react";import{ConnectionManager as v}from"@vuu-ui/vuu-data";var fe=()=>{let[e,t]=F("disconnected"),n=O(({status:r})=>{t(r)},[]);return _(()=>(v.on("connection-status",n),()=>{v.removeListener("connection-status",n)}),[n]),e};import{useCallback as W,useEffect as U,useState as N}from"react";import{ConnectionManager as S}from"@vuu-ui/vuu-data";var Re=()=>{let[e,t]=N(0),n=W(({messages:r})=>{t(r.messagesLength)},[]);return U(()=>(S.on("connection-metrics",n),()=>{S.removeListener("connection-metrics",n)}),[n]),e};import{useCallback as G}from"react";import{makeRpcCall as K}from"@vuu-ui/vuu-data";var b={type:"RPC_CALL",service:"TypeAheadRpcHandler"},be=(e,t,n="",r=[])=>n!==""&&!r.includes(n.toLowerCase())?[e,t,n]:[e,t],Te=()=>G(async t=>{let n=t.length===2?{method:"getUniqueFieldValues",params:t,...b}:{method:"getUniqueFieldValuesStartingWith",params:t,...b};return await K(n)},[]);import{getFilterPredicate as T}from"@vuu-ui/vuu-filter-parser";import{getRowRecord as H,isGroupMenuItemDescriptor as q,metadataKeys as j}from"@vuu-ui/vuu-utils";import{useCallback as I}from"react";var Le="addRowsFromInstruments",{KEY:k}=j,Y={},$=e=>e.type==="vuu-links",Pe=e=>e.type==="vuu-link-created",Ae=e=>e.type==="vuu-link-removed",Q=e=>e.type==="vuu-menu",Ee=e=>Q(e)||$(e),Oe=e=>e.type==="vuu-link-created"||e.type==="vuu-link-removed",J=e=>"rpcName"in e,X=e=>"menus"in e,Z=e=>e.name==="ROOT",x=e=>e.context==="cell",B=e=>e.context==="row",z=e=>e.context==="selected-rows",ee=(e,t,n=0)=>{switch(e){case"grid":return t==="selected-rows"?n>0:!0;case"header":return t==="grid";default:return!1}},te=(e,t,n,r,o)=>{if(e==="cell"||e==="row")return T(o,r)(t);if(e==="selected-rows"){if(n.length===0)return!1;{let c=T(o,r);return n.every(c)}}return!0},ne=e=>{let{rpcName:t}=e;return x(e)?{field:e.field,rowKey:e.rowKey,rpcName:t,value:e.value,type:"VIEW_PORT_MENU_CELL_RPC"}:B(e)?{rowKey:e.rowKey,row:e.row,rpcName:t,type:"VIEW_PORT_MENU_ROW_RPC"}:z(e)?{rpcName:t,type:"VIEW_PORT_MENUS_SELECT_RPC"}:{rpcName:t,type:"VIEW_PORT_MENU_TABLE_RPC"}},re=({filter:e})=>typeof e=="string"&&e.length>0,ue=(e,t)=>{switch(e.context){case"cell":return{...e,field:t.columnName,rowKey:t.row[k],value:t.row[t.columnMap[t.columnName]]};case"row":return{...e,row:H(t.row,t.columnMap),rowKey:t.row[k]};default:return e}},y=(e,t,n)=>{var r;return X(e)?e.menus.some(o=>y(o,t,n)):ee(t,e.context,(r=n.selectedRows)==null?void 0:r.length)?t==="grid"&&re(e)?te(e.context,n.row,n.selectedRows,e.filter,n.columnMap):x(e)&&e.field!=="*"?e.field===n.columnName:!0:!1},D=(e,t,n)=>{if(y(e,t,n)){if(J(e))return{label:e.name,action:"MENU_RPC_CALL",options:ue(e,n)};{let r=e.menus.map(o=>D(o,t,n)).filter(o=>o!==void 0);if(r.length>0)return{label:e.name,children:r}}}},_e=({clientSideMenuActionHandler:e,dataSource:t,menuActionConfig:n=Y,onRpcResponse:r})=>{let o=I((s,a)=>{let{visualLink:i,visualLinks:m,vuuMenu:M}=n,d=[];if(s==="grid"&&m&&!i&&m.forEach(u=>{let{link:l,label:p}=u,L=p||l.toTable;d.push({label:`Link to ${L}`,action:"link-table",options:u})}),M){let u=D(M,s,a);Z(M)&&q(u)?d.push(...u.children):u&&d.push(u)}return d},[n]),c=I((s,a)=>{if(e!=null&&e(s,a))return!0;if(s==="MENU_RPC_CALL"){let i=ne(a);return t.menuRpcCall(i).then(m=>{r&&m&&r&&r(m)}),!0}else{if(s==="link-table")return t.visualLink=a,!0;console.log(`useViewServer handleMenuAction, can't handle action type ${s}`)}return!1},[e,t,r]);return{buildViewserverMenuOptions:o,handleMenuAction:c}};import{useCallback as oe,useEffect as se,useState as ae}from"react";import{getServerAPI as ie}from"@vuu-ui/vuu-data";var Ge=()=>{let[e,t]=ae(),n=oe(r=>{let o=new Map;return r.forEach(c=>{o.set(c.table.table,c)}),o},[]);return se(()=>{async function r(){let o=await ie(),{tables:c}=await o.getTableList(),s=n(await Promise.all(c.map(a=>o.getTableSchema(a))));t(s)}r()},[n]),e};export{R as MovingWindow,Le as addRowsFromInstruments,be as getTypeaheadParams,Q as isViewportMenusAction,Pe as isVisualLinkCreatedAction,Ae as isVisualLinkRemovedAction,$ as isVisualLinksAction,Ee as isVuuFeatureAction,Oe as isVuuFeatureInvocation,me as useDataSource,Re as useServerConnectionQuality,fe as useServerConnectionStatus,Te as useTypeaheadSuggestions,_e as useVuuMenuActions,Ge as useVuuTables};
1
+ // src/hooks/useDataSource.ts
2
+ import { getFullRange, metadataKeys, WindowRange } from "@vuu-ui/vuu-utils";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ var { SELECTED } = metadataKeys;
5
+ function useDataSource({
6
+ dataSource,
7
+ renderBufferSize = 10
8
+ }) {
9
+ const [, forceUpdate] = useState(null);
10
+ const isMounted = useRef(true);
11
+ const hasUpdated = useRef(false);
12
+ const rafHandle = useRef(null);
13
+ const data = useRef([]);
14
+ const rangeRef = useRef({ from: 0, to: 10 });
15
+ const dataWindow = useMemo(
16
+ () => new MovingWindow(getFullRange(rangeRef.current, renderBufferSize)),
17
+ [renderBufferSize]
18
+ );
19
+ const setData = useCallback(
20
+ (updates) => {
21
+ for (const row of updates) {
22
+ dataWindow.add(row);
23
+ }
24
+ data.current = dataWindow.data.slice();
25
+ hasUpdated.current = true;
26
+ },
27
+ [dataWindow]
28
+ );
29
+ const datasourceMessageHandler = useCallback(
30
+ (message) => {
31
+ if (message.type === "viewport-update") {
32
+ if (message.size !== void 0) {
33
+ dataWindow.setRowCount(message.size);
34
+ }
35
+ if (message.rows) {
36
+ setData(message.rows);
37
+ forceUpdate({});
38
+ } else if (message.size !== void 0) {
39
+ data.current = dataWindow.data.slice();
40
+ hasUpdated.current = true;
41
+ }
42
+ }
43
+ },
44
+ [dataWindow, setData]
45
+ );
46
+ useEffect(
47
+ () => () => {
48
+ if (rafHandle.current) {
49
+ cancelAnimationFrame(rafHandle.current);
50
+ rafHandle.current = null;
51
+ }
52
+ isMounted.current = false;
53
+ },
54
+ []
55
+ );
56
+ const setRange = useCallback(
57
+ (range) => {
58
+ rangeRef.current = range;
59
+ const fullRange = getFullRange(rangeRef.current, renderBufferSize);
60
+ dataSource.range = fullRange;
61
+ dataWindow.setRange(fullRange.from, fullRange.to);
62
+ },
63
+ [dataSource, dataWindow, renderBufferSize]
64
+ );
65
+ useMemo(() => {
66
+ const { from, to } = rangeRef.current;
67
+ const fullRange = getFullRange({ from, to }, renderBufferSize);
68
+ dataSource.range = fullRange;
69
+ dataWindow.setRange(fullRange.from, fullRange.to);
70
+ }, [dataSource, dataWindow, renderBufferSize]);
71
+ useEffect(() => {
72
+ const { from, to } = getFullRange(rangeRef.current, renderBufferSize);
73
+ dataSource.subscribe(
74
+ {
75
+ range: { from, to }
76
+ },
77
+ datasourceMessageHandler
78
+ );
79
+ }, [dataSource, datasourceMessageHandler, renderBufferSize]);
80
+ useEffect(
81
+ () => () => {
82
+ dataSource.unsubscribe();
83
+ },
84
+ [dataSource]
85
+ );
86
+ return [
87
+ data.current,
88
+ dataWindow.rowCount,
89
+ getFullRange(rangeRef.current, renderBufferSize),
90
+ setRange
91
+ ];
92
+ }
93
+ var MovingWindow = class {
94
+ constructor({ from, to }) {
95
+ this.rowCount = 0;
96
+ this.setRowCount = (rowCount) => {
97
+ if (rowCount < this.data.length) {
98
+ this.data.length = rowCount;
99
+ }
100
+ this.rowCount = rowCount;
101
+ };
102
+ this.range = new WindowRange(from, to);
103
+ this.data = new Array(to - from);
104
+ }
105
+ add(data) {
106
+ const [index] = data;
107
+ if (this.isWithinRange(index)) {
108
+ const internalIndex = index - this.range.from;
109
+ this.data[internalIndex] = data;
110
+ if (this.data[internalIndex - 1]) {
111
+ if (this.data[internalIndex - 1][SELECTED] === 1 && data[SELECTED] === 0) {
112
+ data[SELECTED] = 2;
113
+ }
114
+ }
115
+ if (index === this.rowCount - 1) {
116
+ this.data.length = internalIndex + 1;
117
+ }
118
+ }
119
+ }
120
+ getAtIndex(index) {
121
+ return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
122
+ }
123
+ isWithinRange(index) {
124
+ return this.range.isWithin(index);
125
+ }
126
+ setRange(from, to) {
127
+ if (from !== this.range.from || to !== this.range.to) {
128
+ const [overlapFrom, overlapTo] = this.range.overlap(from, to);
129
+ const newData = new Array(to - from);
130
+ for (let i = overlapFrom; i < overlapTo; i++) {
131
+ const data = this.getAtIndex(i);
132
+ if (data) {
133
+ const index = i - from;
134
+ newData[index] = data;
135
+ }
136
+ }
137
+ this.data = newData;
138
+ this.range.from = from;
139
+ this.range.to = to;
140
+ }
141
+ }
142
+ };
143
+
144
+ // src/hooks/useServerConnectionStatus.ts
145
+ import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
146
+ import { ConnectionManager } from "@vuu-ui/vuu-data";
147
+ var useServerConnectionStatus = () => {
148
+ const [connectionStatus, setConnectionStatus] = useState2("disconnected");
149
+ const handleStatusChange = useCallback2(
150
+ ({ status }) => {
151
+ setConnectionStatus(status);
152
+ },
153
+ []
154
+ );
155
+ useEffect2(() => {
156
+ ConnectionManager.on("connection-status", handleStatusChange);
157
+ return () => {
158
+ ConnectionManager.removeListener("connection-status", handleStatusChange);
159
+ };
160
+ }, [handleStatusChange]);
161
+ return connectionStatus;
162
+ };
163
+
164
+ // src/hooks/useServerConnectionQuality.ts
165
+ import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
166
+ import { ConnectionManager as ConnectionManager2 } from "@vuu-ui/vuu-data";
167
+ var useServerConnectionQuality = () => {
168
+ const [messagesPerSecond, setMessagesPerSecond] = useState3(0);
169
+ const handleConnectivityMessage = useCallback3(({ messages }) => {
170
+ setMessagesPerSecond(messages.messagesLength);
171
+ }, []);
172
+ useEffect3(() => {
173
+ ConnectionManager2.on("connection-metrics", handleConnectivityMessage);
174
+ return () => {
175
+ ConnectionManager2.removeListener(
176
+ "connection-metrics",
177
+ handleConnectivityMessage
178
+ );
179
+ };
180
+ }, [handleConnectivityMessage]);
181
+ return messagesPerSecond;
182
+ };
183
+
184
+ // src/hooks/useTypeaheadSuggestions.ts
185
+ import { useCallback as useCallback4 } from "react";
186
+ import { makeRpcCall } from "@vuu-ui/vuu-data";
187
+ var TYPEAHEAD_MESSAGE_CONSTANTS = {
188
+ type: "RPC_CALL",
189
+ service: "TypeAheadRpcHandler"
190
+ };
191
+ var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
192
+ if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
193
+ return [table, column, text];
194
+ }
195
+ return [table, column];
196
+ };
197
+ var useTypeaheadSuggestions = () => {
198
+ const getTypeaheadSuggestions = useCallback4(
199
+ async (params) => {
200
+ const rpcMessage = params.length === 2 ? {
201
+ method: "getUniqueFieldValues",
202
+ params,
203
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
204
+ } : {
205
+ method: "getUniqueFieldValuesStartingWith",
206
+ params,
207
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
208
+ };
209
+ const suggestions = await makeRpcCall(rpcMessage);
210
+ return suggestions;
211
+ },
212
+ []
213
+ );
214
+ return getTypeaheadSuggestions;
215
+ };
216
+
217
+ // src/hooks/useVuuMenuActions.ts
218
+ import { getFilterPredicate } from "@vuu-ui/vuu-filter-parser";
219
+ import {
220
+ getRowRecord,
221
+ isGroupMenuItemDescriptor,
222
+ metadataKeys as metadataKeys2
223
+ } from "@vuu-ui/vuu-utils";
224
+ import { useCallback as useCallback5 } from "react";
225
+ var addRowsFromInstruments = "addRowsFromInstruments";
226
+ var { KEY } = metadataKeys2;
227
+ var NO_CONFIG = {};
228
+ var isVisualLinksAction = (action) => action.type === "vuu-links";
229
+ var isVisualLinkCreatedAction = (action) => action.type === "vuu-link-created";
230
+ var isVisualLinkRemovedAction = (action) => action.type === "vuu-link-removed";
231
+ var isViewportMenusAction = (action) => action.type === "vuu-menu";
232
+ var isVuuFeatureAction = (action) => isViewportMenusAction(action) || isVisualLinksAction(action);
233
+ var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
234
+ var isMenuItem = (menu) => "rpcName" in menu;
235
+ var isGroupMenuItem = (menu) => "menus" in menu;
236
+ var isRoot = (menu) => menu.name === "ROOT";
237
+ var isCellMenu = (options) => options.context === "cell";
238
+ var isRowMenu = (options) => options.context === "row";
239
+ var isSelectionMenu = (options) => options.context === "selected-rows";
240
+ var vuuContextCompatibleWithTableLocation = (uiLocation, vuuContext, selectedRowCount = 0) => {
241
+ switch (uiLocation) {
242
+ case "grid":
243
+ if (vuuContext === "selected-rows") {
244
+ return selectedRowCount > 0;
245
+ } else {
246
+ return true;
247
+ }
248
+ case "header":
249
+ return vuuContext === "grid";
250
+ default:
251
+ return false;
252
+ }
253
+ };
254
+ var gridRowMeetsFilterCriteria = (context, row, selectedRows, filter, columnMap) => {
255
+ if (context === "cell" || context === "row") {
256
+ const filterPredicate = getFilterPredicate(columnMap, filter);
257
+ return filterPredicate(row);
258
+ } else if (context === "selected-rows") {
259
+ if (selectedRows.length === 0) {
260
+ return false;
261
+ } else {
262
+ const filterPredicate = getFilterPredicate(columnMap, filter);
263
+ return selectedRows.every(filterPredicate);
264
+ }
265
+ }
266
+ return true;
267
+ };
268
+ var getMenuRpcRequest = (options) => {
269
+ const { rpcName } = options;
270
+ if (isCellMenu(options)) {
271
+ return {
272
+ field: options.field,
273
+ rowKey: options.rowKey,
274
+ rpcName,
275
+ value: options.value,
276
+ type: "VIEW_PORT_MENU_CELL_RPC"
277
+ };
278
+ } else if (isRowMenu(options)) {
279
+ return {
280
+ rowKey: options.rowKey,
281
+ row: options.row,
282
+ rpcName,
283
+ type: "VIEW_PORT_MENU_ROW_RPC"
284
+ };
285
+ } else if (isSelectionMenu(options)) {
286
+ return {
287
+ rpcName,
288
+ type: "VIEW_PORT_MENUS_SELECT_RPC"
289
+ };
290
+ } else {
291
+ return {
292
+ rpcName,
293
+ type: "VIEW_PORT_MENU_TABLE_RPC"
294
+ };
295
+ }
296
+ };
297
+ var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
298
+ var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
299
+ var getMenuItemOptions = (menu, options) => {
300
+ switch (menu.context) {
301
+ case "cell":
302
+ return {
303
+ ...menu,
304
+ field: options.columnName,
305
+ rowKey: options.row[KEY],
306
+ value: options.row[options.columnMap[options.columnName]]
307
+ };
308
+ case "row":
309
+ return {
310
+ ...menu,
311
+ row: getRowRecord(options.row, options.columnMap),
312
+ rowKey: options.row[KEY]
313
+ };
314
+ default:
315
+ return menu;
316
+ }
317
+ };
318
+ var menuShouldBeRenderedInThisContext = (menuItem, tableLocation, options) => {
319
+ var _a;
320
+ if (isGroupMenuItem(menuItem)) {
321
+ return menuItem.menus.some(
322
+ (childMenu) => menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)
323
+ );
324
+ }
325
+ if (!vuuContextCompatibleWithTableLocation(
326
+ tableLocation,
327
+ menuItem.context,
328
+ (_a = options.selectedRows) == null ? void 0 : _a.length
329
+ )) {
330
+ return false;
331
+ }
332
+ if (tableLocation === "grid" && hasFilter(menuItem)) {
333
+ return gridRowMeetsFilterCriteria(
334
+ menuItem.context,
335
+ options.row,
336
+ options.selectedRows,
337
+ menuItem.filter,
338
+ options.columnMap
339
+ );
340
+ }
341
+ if (isCellMenu(menuItem) && menuItem.field !== "*") {
342
+ return menuItem.field === options.columnName;
343
+ }
344
+ return true;
345
+ };
346
+ var buildMenuDescriptor = (menu, tableLocation, options) => {
347
+ if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {
348
+ if (isMenuItem(menu)) {
349
+ return {
350
+ label: menu.name,
351
+ action: "MENU_RPC_CALL",
352
+ options: getMenuItemOptions(menu, options)
353
+ };
354
+ } else {
355
+ const children = menu.menus.map(
356
+ (childMenu) => buildMenuDescriptor(childMenu, tableLocation, options)
357
+ ).filter(
358
+ (childMenu) => childMenu !== void 0
359
+ );
360
+ if (children.length > 0) {
361
+ return {
362
+ label: menu.name,
363
+ children
364
+ };
365
+ }
366
+ }
367
+ }
368
+ };
369
+ var useVuuMenuActions = ({
370
+ clientSideMenuActionHandler,
371
+ dataSource,
372
+ menuActionConfig = NO_CONFIG,
373
+ onRpcResponse
374
+ }) => {
375
+ const buildViewserverMenuOptions = useCallback5(
376
+ (location, options) => {
377
+ const { visualLink, visualLinks, vuuMenu } = menuActionConfig;
378
+ const descriptors = [];
379
+ if (location === "grid" && visualLinks && !visualLink) {
380
+ visualLinks.forEach((linkDescriptor) => {
381
+ const { link, label: linkLabel } = linkDescriptor;
382
+ const label = linkLabel ? linkLabel : link.toTable;
383
+ descriptors.push({
384
+ label: `Link to ${label}`,
385
+ action: "link-table",
386
+ options: linkDescriptor
387
+ });
388
+ });
389
+ }
390
+ if (vuuMenu && isTableLocation(location)) {
391
+ const menuDescriptor = buildMenuDescriptor(
392
+ vuuMenu,
393
+ location,
394
+ options
395
+ );
396
+ if (isRoot(vuuMenu) && isGroupMenuItemDescriptor(menuDescriptor)) {
397
+ descriptors.push(...menuDescriptor.children);
398
+ } else if (menuDescriptor) {
399
+ descriptors.push(menuDescriptor);
400
+ }
401
+ }
402
+ return descriptors;
403
+ },
404
+ [menuActionConfig]
405
+ );
406
+ const handleMenuAction = useCallback5(
407
+ ({ menuId, options }) => {
408
+ if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
409
+ return true;
410
+ } else if (menuId === "MENU_RPC_CALL") {
411
+ const rpcRequest = getMenuRpcRequest(options);
412
+ dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
413
+ if (onRpcResponse && rpcResponse) {
414
+ onRpcResponse && onRpcResponse(rpcResponse);
415
+ }
416
+ });
417
+ return true;
418
+ } else if (menuId === "link-table") {
419
+ return dataSource.visualLink = options, true;
420
+ } else {
421
+ console.log(
422
+ `useViewServer handleMenuAction, can't handle action type ${menuId}`
423
+ );
424
+ }
425
+ return false;
426
+ },
427
+ [clientSideMenuActionHandler, dataSource, onRpcResponse]
428
+ );
429
+ return {
430
+ buildViewserverMenuOptions,
431
+ handleMenuAction
432
+ };
433
+ };
434
+
435
+ // src/hooks/useVuuTables.ts
436
+ import { useCallback as useCallback6, useEffect as useEffect4, useState as useState4 } from "react";
437
+ import { getServerAPI } from "@vuu-ui/vuu-data";
438
+ var useVuuTables = () => {
439
+ const [tables, setTables] = useState4();
440
+ const buildTables = useCallback6((schemas) => {
441
+ const vuuTables = /* @__PURE__ */ new Map();
442
+ schemas.forEach((schema) => {
443
+ vuuTables.set(schema.table.table, schema);
444
+ });
445
+ return vuuTables;
446
+ }, []);
447
+ useEffect4(() => {
448
+ async function fetchTableMetadata() {
449
+ const server = await getServerAPI();
450
+ const { tables: tables2 } = await server.getTableList();
451
+ const tableSchemas = buildTables(
452
+ await Promise.all(
453
+ tables2.map(
454
+ (tableDescriptor) => server.getTableSchema(tableDescriptor)
455
+ )
456
+ )
457
+ );
458
+ setTables(tableSchemas);
459
+ }
460
+ fetchTableMetadata();
461
+ }, [buildTables]);
462
+ return tables;
463
+ };
464
+ export {
465
+ MovingWindow,
466
+ addRowsFromInstruments,
467
+ getTypeaheadParams,
468
+ isViewportMenusAction,
469
+ isVisualLinkCreatedAction,
470
+ isVisualLinkRemovedAction,
471
+ isVisualLinksAction,
472
+ isVuuFeatureAction,
473
+ isVuuFeatureInvocation,
474
+ useDataSource,
475
+ useServerConnectionQuality,
476
+ useServerConnectionStatus,
477
+ useTypeaheadSuggestions,
478
+ useVuuMenuActions,
479
+ useVuuTables
480
+ };
2
481
  //# sourceMappingURL=index.js.map