@vuu-ui/vuu-data-react 0.8.25-debug → 0.8.25

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/esm/index.js CHANGED
@@ -1,576 +1,2 @@
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/useLookupValues.ts
145
- import { VuuDataSource } from "@vuu-ui/vuu-data-remote";
146
- import { useShellContext } from "@vuu-ui/vuu-shell";
147
- import {
148
- buildColumnMap,
149
- isLookupRenderer,
150
- isTypeDescriptor,
151
- isValueListRenderer
152
- } from "@vuu-ui/vuu-utils";
153
- import { useMemo as useMemo2, useState as useState2 } from "react";
154
- var NO_VALUES = [];
155
- var toListOption = (value) => ({
156
- label: value,
157
- value
158
- });
159
- var lookupValueMap = /* @__PURE__ */ new Map();
160
- var loadLookupValues = ({
161
- labelColumn,
162
- table,
163
- valueColumn
164
- }) => {
165
- const tableKey = `${table.module}:${table.table}`;
166
- const lookupValues = lookupValueMap.get(tableKey);
167
- if (lookupValues) {
168
- return lookupValues;
169
- } else {
170
- const promise = new Promise((resolve) => {
171
- const columns = [valueColumn, labelColumn];
172
- const columnMap = buildColumnMap(columns);
173
- const dataSource = new VuuDataSource({
174
- bufferSize: 0,
175
- table
176
- });
177
- dataSource.subscribe(
178
- {
179
- columns,
180
- range: { from: 0, to: 100 }
181
- },
182
- (message) => {
183
- if (message.type === "viewport-update") {
184
- if (message.rows) {
185
- const listOptions = message.rows.map((row) => ({
186
- value: row[columnMap[valueColumn]],
187
- label: row[columnMap[labelColumn]]
188
- }));
189
- resolve(listOptions);
190
- dataSource.unsubscribe();
191
- }
192
- }
193
- }
194
- );
195
- });
196
- lookupValueMap.set(tableKey, promise);
197
- return promise;
198
- }
199
- };
200
- var getSelectedOption = (values, selectedValue) => {
201
- var _a;
202
- if (selectedValue === void 0) {
203
- return null;
204
- }
205
- return (_a = values.find((option) => option.value === selectedValue)) != null ? _a : null;
206
- };
207
- var getLookupDetails = ({ name, type }) => {
208
- if (isTypeDescriptor(type) && isLookupRenderer(type.renderer)) {
209
- return type.renderer.lookup;
210
- } else {
211
- throw Error(
212
- `useLookupValues column ${name} is not configured to use lookup values`
213
- );
214
- }
215
- };
216
- var useLookupValues = (column, initialValueProp) => {
217
- const { type: columnType } = column;
218
- const { getLookupValues } = useShellContext();
219
- const initialState = useMemo2(() => {
220
- var _a;
221
- if (isTypeDescriptor(columnType) && isValueListRenderer(columnType == null ? void 0 : columnType.renderer)) {
222
- const values2 = columnType.renderer.values.map(toListOption);
223
- return {
224
- initialValue: getSelectedOption(values2, initialValueProp),
225
- values: values2
226
- };
227
- } else {
228
- const lookupDetails = getLookupDetails(column);
229
- const values2 = (_a = getLookupValues == null ? void 0 : getLookupValues(lookupDetails.table)) != null ? _a : NO_VALUES;
230
- return {
231
- initialValue: getSelectedOption(values2, initialValueProp),
232
- values: values2
233
- };
234
- }
235
- }, [column, columnType, getLookupValues, initialValueProp]);
236
- const [{ initialValue, values }, setLookupState] = useState2(initialState);
237
- useMemo2(() => {
238
- if (values === NO_VALUES) {
239
- const lookupDetails = getLookupDetails(column);
240
- loadLookupValues(lookupDetails).then(
241
- (values2) => setLookupState({
242
- initialValue: getSelectedOption(values2, initialValueProp),
243
- values: values2
244
- })
245
- );
246
- }
247
- }, [values, column, initialValueProp]);
248
- return {
249
- initialValue,
250
- values
251
- };
252
- };
253
-
254
- // src/hooks/useServerConnectionStatus.ts
255
- import { useCallback as useCallback2, useEffect as useEffect2, useState as useState3 } from "react";
256
- import { ConnectionManager } from "@vuu-ui/vuu-data-remote";
257
- var useServerConnectionStatus = () => {
258
- const [connectionStatus, setConnectionStatus] = useState3("disconnected");
259
- const handleStatusChange = useCallback2(
260
- ({ status }) => {
261
- setConnectionStatus(status);
262
- },
263
- []
264
- );
265
- useEffect2(() => {
266
- ConnectionManager.on("connection-status", handleStatusChange);
267
- return () => {
268
- ConnectionManager.removeListener("connection-status", handleStatusChange);
269
- };
270
- }, [handleStatusChange]);
271
- return connectionStatus;
272
- };
273
-
274
- // src/hooks/useServerConnectionQuality.ts
275
- import { useCallback as useCallback3, useEffect as useEffect3, useState as useState4 } from "react";
276
- import { ConnectionManager as ConnectionManager2 } from "@vuu-ui/vuu-data-remote";
277
- var useServerConnectionQuality = () => {
278
- const [messagesPerSecond, setMessagesPerSecond] = useState4(0);
279
- const handleConnectivityMessage = useCallback3(({ messages }) => {
280
- setMessagesPerSecond(messages.messagesLength);
281
- }, []);
282
- useEffect3(() => {
283
- ConnectionManager2.on("connection-metrics", handleConnectivityMessage);
284
- return () => {
285
- ConnectionManager2.removeListener(
286
- "connection-metrics",
287
- handleConnectivityMessage
288
- );
289
- };
290
- }, [handleConnectivityMessage]);
291
- return messagesPerSecond;
292
- };
293
-
294
- // src/hooks/useTypeaheadSuggestions.ts
295
- import { makeRpcCall } from "@vuu-ui/vuu-data-remote";
296
- import { useCallback as useCallback4 } from "react";
297
- var TYPEAHEAD_MESSAGE_CONSTANTS = {
298
- type: "RPC_CALL",
299
- service: "TypeAheadRpcHandler"
300
- };
301
- var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
302
- if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
303
- return [table, column, text];
304
- }
305
- return [table, column];
306
- };
307
- var useTypeaheadSuggestions = () => useCallback4(async (params) => {
308
- const rpcMessage = params.length === 2 ? {
309
- method: "getUniqueFieldValues",
310
- params,
311
- ...TYPEAHEAD_MESSAGE_CONSTANTS
312
- } : {
313
- method: "getUniqueFieldValuesStartingWith",
314
- params,
315
- ...TYPEAHEAD_MESSAGE_CONSTANTS
316
- };
317
- return makeRpcCall(rpcMessage);
318
- }, []);
319
-
320
- // src/hooks/useVuuMenuActions.ts
321
- import { getFilterPredicate } from "@vuu-ui/vuu-filter-parser";
322
- import {
323
- getRowRecord,
324
- isGroupMenuItemDescriptor,
325
- metadataKeys as metadataKeys2
326
- } from "@vuu-ui/vuu-utils";
327
- import { useCallback as useCallback5 } from "react";
328
- var addRowsFromInstruments = "addRowsFromInstruments";
329
- var { KEY } = metadataKeys2;
330
- var NO_CONFIG = {};
331
- var isMenuItem = (menu) => "rpcName" in menu;
332
- var isGroupMenuItem = (menu) => "menus" in menu;
333
- var isRoot = (menu) => menu.name === "ROOT";
334
- var isCellMenu = (options) => options.context === "cell";
335
- var isRowMenu = (options) => options.context === "row";
336
- var isSelectionMenu = (options) => options.context === "selected-rows";
337
- var vuuContextCompatibleWithTableLocation = (uiLocation, vuuContext, selectedRowCount = 0) => {
338
- switch (uiLocation) {
339
- case "grid":
340
- if (vuuContext === "selected-rows") {
341
- return selectedRowCount > 0;
342
- } else {
343
- return true;
344
- }
345
- case "header":
346
- return vuuContext === "grid";
347
- default:
348
- return false;
349
- }
350
- };
351
- var gridRowMeetsFilterCriteria = (context, row, selectedRows, filter, columnMap) => {
352
- if (context === "cell" || context === "row") {
353
- const filterPredicate = getFilterPredicate(columnMap, filter);
354
- return filterPredicate(row);
355
- } else if (context === "selected-rows") {
356
- if (selectedRows.length === 0) {
357
- return false;
358
- } else {
359
- const filterPredicate = getFilterPredicate(columnMap, filter);
360
- return selectedRows.every(filterPredicate);
361
- }
362
- }
363
- return true;
364
- };
365
- var getMenuRpcRequest = (options) => {
366
- const { rpcName } = options;
367
- if (isCellMenu(options)) {
368
- return {
369
- field: options.field,
370
- rowKey: options.rowKey,
371
- rpcName,
372
- value: options.value,
373
- type: "VIEW_PORT_MENU_CELL_RPC"
374
- };
375
- } else if (isRowMenu(options)) {
376
- return {
377
- rowKey: options.rowKey,
378
- row: options.row,
379
- rpcName,
380
- type: "VIEW_PORT_MENU_ROW_RPC"
381
- };
382
- } else if (isSelectionMenu(options)) {
383
- return {
384
- rpcName,
385
- type: "VIEW_PORT_MENUS_SELECT_RPC"
386
- };
387
- } else {
388
- return {
389
- rpcName,
390
- type: "VIEW_PORT_MENU_TABLE_RPC"
391
- };
392
- }
393
- };
394
- var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
395
- var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
396
- var getMenuItemOptions = (menu, options) => {
397
- switch (menu.context) {
398
- case "cell":
399
- return {
400
- ...menu,
401
- field: options.columnName,
402
- rowKey: options.row[KEY],
403
- value: options.row[options.columnMap[options.columnName]]
404
- };
405
- case "row":
406
- return {
407
- ...menu,
408
- row: getRowRecord(options.row, options.columnMap),
409
- rowKey: options.row[KEY]
410
- };
411
- default:
412
- return menu;
413
- }
414
- };
415
- var menuShouldBeRenderedInThisContext = (menuItem, tableLocation, options) => {
416
- var _a;
417
- if (isGroupMenuItem(menuItem)) {
418
- return menuItem.menus.some(
419
- (childMenu) => menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)
420
- );
421
- }
422
- if (!vuuContextCompatibleWithTableLocation(
423
- tableLocation,
424
- menuItem.context,
425
- (_a = options.selectedRows) == null ? void 0 : _a.length
426
- )) {
427
- return false;
428
- }
429
- if (tableLocation === "grid" && hasFilter(menuItem)) {
430
- return gridRowMeetsFilterCriteria(
431
- menuItem.context,
432
- options.row,
433
- options.selectedRows,
434
- menuItem.filter,
435
- options.columnMap
436
- );
437
- }
438
- if (isCellMenu(menuItem) && menuItem.field !== "*") {
439
- return menuItem.field === options.columnName;
440
- }
441
- return true;
442
- };
443
- var buildMenuDescriptor = (menu, tableLocation, options) => {
444
- if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {
445
- if (isMenuItem(menu)) {
446
- return {
447
- label: menu.name,
448
- action: "MENU_RPC_CALL",
449
- options: getMenuItemOptions(menu, options)
450
- };
451
- } else {
452
- const children = menu.menus.map(
453
- (childMenu) => buildMenuDescriptor(childMenu, tableLocation, options)
454
- ).filter(
455
- (childMenu) => childMenu !== void 0
456
- );
457
- if (children.length > 0) {
458
- return {
459
- label: menu.name,
460
- children
461
- };
462
- }
463
- }
464
- }
465
- };
466
- var useVuuMenuActions = ({
467
- clientSideMenuActionHandler,
468
- dataSource,
469
- menuActionConfig = NO_CONFIG,
470
- onRpcResponse
471
- }) => {
472
- const buildViewserverMenuOptions = useCallback5(
473
- (location, options) => {
474
- const { links, menu } = dataSource;
475
- const { visualLink } = menuActionConfig;
476
- const descriptors = [];
477
- if (location === "grid" && links && !visualLink) {
478
- links.forEach((linkDescriptor) => {
479
- const { link, label: linkLabel } = linkDescriptor;
480
- const label = linkLabel ? linkLabel : link.toTable;
481
- descriptors.push({
482
- label: `Link to ${label}`,
483
- action: "link-table",
484
- options: linkDescriptor
485
- });
486
- });
487
- }
488
- if (menu && isTableLocation(location)) {
489
- const menuDescriptor = buildMenuDescriptor(
490
- menu,
491
- location,
492
- options
493
- );
494
- if (isRoot(menu) && isGroupMenuItemDescriptor(menuDescriptor)) {
495
- descriptors.push(...menuDescriptor.children);
496
- } else if (menuDescriptor) {
497
- descriptors.push(menuDescriptor);
498
- }
499
- }
500
- return descriptors;
501
- },
502
- [dataSource, menuActionConfig]
503
- );
504
- const handleMenuAction = useCallback5(
505
- ({ menuId, options }) => {
506
- if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
507
- return true;
508
- } else if (menuId === "MENU_RPC_CALL") {
509
- const rpcRequest = getMenuRpcRequest(options);
510
- dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
511
- if (onRpcResponse && rpcResponse) {
512
- onRpcResponse && onRpcResponse(rpcResponse);
513
- }
514
- });
515
- return true;
516
- } else if (menuId === "link-table") {
517
- return dataSource.visualLink = options, true;
518
- } else {
519
- console.log(
520
- `useViewServer handleMenuAction, can't handle action type ${menuId}`
521
- );
522
- }
523
- return false;
524
- },
525
- [clientSideMenuActionHandler, dataSource, onRpcResponse]
526
- );
527
- return {
528
- buildViewserverMenuOptions,
529
- handleMenuAction
530
- };
531
- };
532
-
533
- // src/hooks/useVuuTables.ts
534
- import { getServerAPI } from "@vuu-ui/vuu-data-remote";
535
- import { useCallback as useCallback6, useEffect as useEffect4, useState as useState5 } from "react";
536
- var useVuuTables = () => {
537
- const [tables, setTables] = useState5();
538
- const buildTables = useCallback6((schemas) => {
539
- const vuuTables = /* @__PURE__ */ new Map();
540
- schemas.forEach((schema) => {
541
- vuuTables.set(schema.table.table, schema);
542
- });
543
- return vuuTables;
544
- }, []);
545
- useEffect4(() => {
546
- async function fetchTableMetadata() {
547
- console.log("GET TABLE LIST");
548
- const server = await getServerAPI();
549
- const { tables: tables2 } = await server.getTableList();
550
- const tableSchemas = buildTables(
551
- await Promise.all(
552
- tables2.map((vuuTable) => server.getTableSchema(vuuTable))
553
- )
554
- );
555
- setTables(tableSchemas);
556
- }
557
- fetchTableMetadata();
558
- }, [buildTables]);
559
- return tables;
560
- };
561
- var getVuuTableSchema = (table) => getServerAPI().then((server) => server.getTableSchema(table));
562
- export {
563
- MovingWindow,
564
- addRowsFromInstruments,
565
- getSelectedOption,
566
- getTypeaheadParams,
567
- getVuuTableSchema,
568
- useDataSource,
569
- useLookupValues,
570
- useServerConnectionQuality,
571
- useServerConnectionStatus,
572
- useTypeaheadSuggestions,
573
- useVuuMenuActions,
574
- useVuuTables
575
- };
1
+ import{getFullRange as M,metadataKeys as N,WindowRange as F}from"@vuu-ui/vuu-utils";import{useCallback as h,useEffect as R,useMemo as V,useRef as g,useState as H}from"react";var{SELECTED:C}=N;function ve({dataSource:e,renderBufferSize:t=10}){let[,n]=H(null),r=g(!0),o=g(!1),l=g(null),s=g([]),a=g({from:0,to:10}),u=V(()=>new w(M(a.current,t)),[t]),c=h(i=>{for(let m of i)u.add(m);s.current=u.data.slice(),o.current=!0},[u]),p=h(i=>{i.type==="viewport-update"&&(i.size!==void 0&&u.setRowCount(i.size),i.rows?(c(i.rows),n({})):i.size!==void 0&&(s.current=u.data.slice(),o.current=!0))},[u,c]);R(()=>()=>{l.current&&(cancelAnimationFrame(l.current),l.current=null),r.current=!1},[]);let f=h(i=>{a.current=i;let m=M(a.current,t);e.range=m,u.setRange(m.from,m.to)},[e,u,t]);return V(()=>{let{from:i,to:m}=a.current,d=M({from:i,to:m},t);e.range=d,u.setRange(d.from,d.to)},[e,u,t]),R(()=>{let{from:i,to:m}=M(a.current,t);e.subscribe({range:{from:i,to:m}},p)},[e,p,t]),R(()=>()=>{e.unsubscribe()},[e]),[s.current,u.rowCount,M(a.current,t),f]}var w=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 F(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),l=new Array(n-t);for(let s=r;s<o;s++){let a=this.getAtIndex(s);if(a){let u=s-t;l[u]=a}}this.data=l,this.range.from=t,this.range.to=n}}};import{VuuDataSource as K}from"@vuu-ui/vuu-data-remote";import{useShellContext as G}from"@vuu-ui/vuu-shell";import{buildColumnMap as q,isLookupRenderer as $,isTypeDescriptor as k,isValueListRenderer as j}from"@vuu-ui/vuu-utils";import{useMemo as S,useState as Y}from"react";var v=[],Q=e=>({label:e,value:e}),T=new Map,J=({labelColumn:e,table:t,valueColumn:n})=>{let r=`${t.module}:${t.table}`,o=T.get(r);if(o)return o;{let l=new Promise(s=>{let a=[n,e],u=q(a),c=new K({bufferSize:0,table:t});c.subscribe({columns:a,range:{from:0,to:100}},p=>{if(p.type==="viewport-update"&&p.rows){let f=p.rows.map(i=>({value:i[u[n]],label:i[u[e]]}));s(f),c.unsubscribe()}})});return T.set(r,l),l}},b=(e,t)=>{var n;return t===void 0?null:(n=e.find(r=>r.value===t))!=null?n:null},L=({name:e,type:t})=>{if(k(t)&&$(t.renderer))return t.renderer.lookup;throw Error(`useLookupValues column ${e} is not configured to use lookup values`)},De=(e,t)=>{let{type:n}=e,{getLookupValues:r}=G(),o=S(()=>{var u;if(k(n)&&j(n==null?void 0:n.renderer)){let c=n.renderer.values.map(Q);return{initialValue:b(c,t),values:c}}else{let c=L(e),p=(u=r==null?void 0:r(c.table))!=null?u:v;return{initialValue:b(p,t),values:p}}},[e,n,r,t]),[{initialValue:l,values:s},a]=Y(o);return S(()=>{if(s===v){let u=L(e);J(u).then(c=>a({initialValue:b(c,t),values:c}))}},[s,e,t]),{initialValue:l,values:s}};import{useCallback as X,useEffect as Z,useState as B}from"react";import{ConnectionManager as I}from"@vuu-ui/vuu-data-remote";var Ee=()=>{let[e,t]=B("disconnected"),n=X(({status:r})=>{t(r)},[]);return Z(()=>(I.on("connection-status",n),()=>{I.removeListener("connection-status",n)}),[n]),e};import{useCallback as z,useEffect as ee,useState as te}from"react";import{ConnectionManager as y}from"@vuu-ui/vuu-data-remote";var We=()=>{let[e,t]=te(0),n=z(({messages:r})=>{t(r.messagesLength)},[]);return ee(()=>(y.on("connection-metrics",n),()=>{y.removeListener("connection-metrics",n)}),[n]),e};import{makeRpcCall as ne}from"@vuu-ui/vuu-data-remote";import{useCallback as re}from"react";var D={type:"RPC_CALL",service:"TypeAheadRpcHandler"},Ke=(e,t,n="",r=[])=>n!==""&&!r.includes(n.toLowerCase())?[e,t,n]:[e,t],Ge=()=>re(async e=>{let t=e.length===2?{method:"getUniqueFieldValues",params:e,...D}:{method:"getUniqueFieldValuesStartingWith",params:e,...D};return ne(t)},[]);import{getFilterPredicate as x}from"@vuu-ui/vuu-filter-parser";import{getRowRecord as oe,isGroupMenuItemDescriptor as ue,metadataKeys as se}from"@vuu-ui/vuu-utils";import{useCallback as P}from"react";var Je="addRowsFromInstruments",{KEY:O}=se,ie={},ae=e=>"rpcName"in e,le=e=>"menus"in e,ce=e=>e.name==="ROOT",E=e=>e.context==="cell",pe=e=>e.context==="row",me=e=>e.context==="selected-rows",fe=(e,t,n=0)=>{switch(e){case"grid":return t==="selected-rows"?n>0:!0;case"header":return t==="grid";default:return!1}},de=(e,t,n,r,o)=>{if(e==="cell"||e==="row")return x(o,r)(t);if(e==="selected-rows"){if(n.length===0)return!1;{let l=x(o,r);return n.every(l)}}return!0},Me=e=>{let{rpcName:t}=e;return E(e)?{field:e.field,rowKey:e.rowKey,rpcName:t,value:e.value,type:"VIEW_PORT_MENU_CELL_RPC"}:pe(e)?{rowKey:e.rowKey,row:e.row,rpcName:t,type:"VIEW_PORT_MENU_ROW_RPC"}:me(e)?{rpcName:t,type:"VIEW_PORT_MENUS_SELECT_RPC"}:{rpcName:t,type:"VIEW_PORT_MENU_TABLE_RPC"}},ge=e=>["grid","header","filter"].includes(e),he=({filter:e})=>typeof e=="string"&&e.length>0,Re=(e,t)=>{switch(e.context){case"cell":return{...e,field:t.columnName,rowKey:t.row[O],value:t.row[t.columnMap[t.columnName]]};case"row":return{...e,row:oe(t.row,t.columnMap),rowKey:t.row[O]};default:return e}},A=(e,t,n)=>{var r;return le(e)?e.menus.some(o=>A(o,t,n)):fe(t,e.context,(r=n.selectedRows)==null?void 0:r.length)?t==="grid"&&he(e)?de(e.context,n.row,n.selectedRows,e.filter,n.columnMap):E(e)&&e.field!=="*"?e.field===n.columnName:!0:!1},_=(e,t,n)=>{if(A(e,t,n)){if(ae(e))return{label:e.name,action:"MENU_RPC_CALL",options:Re(e,n)};{let r=e.menus.map(o=>_(o,t,n)).filter(o=>o!==void 0);if(r.length>0)return{label:e.name,children:r}}}},Xe=({clientSideMenuActionHandler:e,dataSource:t,menuActionConfig:n=ie,onRpcResponse:r})=>{let o=P((s,a)=>{let{links:u,menu:c}=t,{visualLink:p}=n,f=[];if(s==="grid"&&u&&!p&&u.forEach(i=>{let{link:m,label:d}=i,W=d||m.toTable;f.push({label:`Link to ${W}`,action:"link-table",options:i})}),c&&ge(s)){let i=_(c,s,a);ce(c)&&ue(i)?f.push(...i.children):i&&f.push(i)}return f},[t,n]),l=P(({menuId:s,options:a})=>{if(e!=null&&e(s,a))return!0;if(s==="MENU_RPC_CALL"){let u=Me(a);return t.menuRpcCall(u).then(c=>{r&&c&&r&&r(c)}),!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:l}};import{getServerAPI as U}from"@vuu-ui/vuu-data-remote";import{useCallback as Ce,useEffect as we,useState as be}from"react";var et=()=>{let[e,t]=be(),n=Ce(r=>{let o=new Map;return r.forEach(l=>{o.set(l.table.table,l)}),o},[]);return we(()=>{async function r(){console.log("GET TABLE LIST");let o=await U(),{tables:l}=await o.getTableList(),s=n(await Promise.all(l.map(a=>o.getTableSchema(a))));t(s)}r()},[n]),e},tt=e=>U().then(t=>t.getTableSchema(e));export{w as MovingWindow,Je as addRowsFromInstruments,b as getSelectedOption,Ke as getTypeaheadParams,tt as getVuuTableSchema,ve as useDataSource,De as useLookupValues,We as useServerConnectionQuality,Ee as useServerConnectionStatus,Ge as useTypeaheadSuggestions,Xe as useVuuMenuActions,et as useVuuTables};
576
2
  //# sourceMappingURL=index.js.map