@vuu-ui/vuu-data-react 0.8.11-debug → 0.8.12
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/LICENSE +201 -0
- package/cjs/index.js +1 -499
- package/cjs/index.js.map +2 -2
- package/esm/index.js +1 -480
- package/esm/index.js.map +2 -2
- package/package.json +9 -9
package/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/vuu-data-react/src/index.ts", "../../../packages/vuu-data-react/src/hooks/useDataSource.ts", "../../../packages/vuu-data-react/src/hooks/useServerConnectionStatus.ts", "../../../packages/vuu-data-react/src/hooks/useServerConnectionQuality.ts", "../../../packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts", "../../../packages/vuu-data-react/src/hooks/useVuuMenuActions.ts", "../../../packages/vuu-data-react/src/hooks/useVuuTables.ts"],
|
|
4
4
|
"sourcesContent": ["export * from \"./hooks\";\n", "// TODO is this hook needed ? it is currently used only in a vuu salt story\nimport { DataSource, SubscribeCallback } from \"@vuu-ui/vuu-data\";\nimport { DataSourceRow } from \"@vuu-ui/vuu-data-types\";\nimport { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { getFullRange, metadataKeys, WindowRange } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nconst { SELECTED } = metadataKeys;\n\nexport interface DataSourceHookProps {\n dataSource: DataSource;\n renderBufferSize?: number;\n}\n\nexport function useDataSource({\n dataSource,\n renderBufferSize = 10,\n}: DataSourceHookProps): [\n DataSourceRow[],\n number,\n VuuRange,\n (range: VuuRange) => void\n] {\n const [, forceUpdate] = useState<object | null>(null);\n const isMounted = useRef(true);\n const hasUpdated = useRef(false);\n const rafHandle = useRef(null);\n const data = useRef<DataSourceRow[]>([]);\n const rangeRef = useRef({ from: 0, to: 10 });\n\n const dataWindow = useMemo(\n () => new MovingWindow(getFullRange(rangeRef.current, renderBufferSize)),\n [renderBufferSize]\n );\n\n const setData = useCallback(\n (updates: DataSourceRow[]) => {\n for (const row of updates) {\n dataWindow.add(row);\n }\n // Why bother with the slice ?\n data.current = dataWindow.data.slice();\n\n hasUpdated.current = true;\n },\n [dataWindow]\n );\n\n const datasourceMessageHandler: SubscribeCallback = useCallback(\n (message) => {\n if (message.type === \"viewport-update\") {\n if (message.size !== undefined) {\n dataWindow.setRowCount(message.size);\n }\n if (message.rows) {\n setData(message.rows);\n forceUpdate({});\n } else if (message.size !== undefined) {\n // TODO is this right ?\n data.current = dataWindow.data.slice();\n hasUpdated.current = true;\n }\n }\n },\n [dataWindow, setData]\n );\n\n useEffect(\n () => () => {\n if (rafHandle.current) {\n cancelAnimationFrame(rafHandle.current);\n rafHandle.current = null;\n }\n isMounted.current = false;\n },\n []\n );\n\n const setRange = useCallback(\n (range) => {\n rangeRef.current = range;\n const fullRange = getFullRange(rangeRef.current, renderBufferSize);\n dataSource.range = fullRange;\n dataWindow.setRange(fullRange.from, fullRange.to);\n },\n [dataSource, dataWindow, renderBufferSize]\n );\n\n useMemo(() => {\n const { from, to } = rangeRef.current;\n const fullRange = getFullRange({ from, to }, renderBufferSize);\n dataSource.range = fullRange;\n dataWindow.setRange(fullRange.from, fullRange.to);\n }, [dataSource, dataWindow, renderBufferSize]);\n\n useEffect(() => {\n const { from, to } = getFullRange(rangeRef.current, renderBufferSize);\n dataSource.subscribe(\n {\n range: { from, to },\n },\n datasourceMessageHandler\n );\n }, [dataSource, datasourceMessageHandler, renderBufferSize]);\n\n useEffect(\n () => () => {\n dataSource.unsubscribe();\n },\n [dataSource]\n );\n\n return [\n data.current,\n dataWindow.rowCount,\n getFullRange(rangeRef.current, renderBufferSize),\n setRange,\n ];\n}\n\nexport class MovingWindow {\n public data: DataSourceRow[];\n public rowCount = 0;\n private range: WindowRange;\n\n constructor({ from, to }: VuuRange) {\n this.range = new WindowRange(from, to);\n this.data = new Array(to - from);\n }\n\n setRowCount = (rowCount: number) => {\n if (rowCount < this.data.length) {\n this.data.length = rowCount;\n }\n this.rowCount = rowCount;\n };\n\n add(data: DataSourceRow) {\n const [index] = data;\n if (this.isWithinRange(index)) {\n const internalIndex = index - this.range.from;\n this.data[internalIndex] = data;\n if (this.data[internalIndex - 1]) {\n // assign 'post-selected' selection state\n if (\n this.data[internalIndex - 1][SELECTED] === 1 &&\n data[SELECTED] === 0\n ) {\n data[SELECTED] = 2;\n }\n }\n if (index === this.rowCount - 1) {\n this.data.length = internalIndex + 1;\n }\n }\n }\n\n getAtIndex(index: number) {\n return this.range.isWithin(index) &&\n this.data[index - this.range.from] != null\n ? this.data[index - this.range.from]\n : undefined;\n }\n\n isWithinRange(index: number) {\n return this.range.isWithin(index);\n }\n\n setRange(from: number, to: number) {\n if (from !== this.range.from || to !== this.range.to) {\n const [overlapFrom, overlapTo] = this.range.overlap(from, to);\n const newData = new Array(to - from);\n for (let i = overlapFrom; i < overlapTo; i++) {\n const data = this.getAtIndex(i);\n if (data) {\n const index = i - from;\n newData[index] = data;\n }\n }\n this.data = newData;\n this.range.from = from;\n this.range.to = to;\n }\n }\n}\n", "import { useCallback, useEffect, useState } from \"react\";\nimport { ConnectionManager, ConnectionStatusMessage } from \"@vuu-ui/vuu-data\";\n\nexport const useServerConnectionStatus = () => {\n const [connectionStatus, setConnectionStatus] = useState(\"disconnected\");\n\n const handleStatusChange = useCallback(\n ({ status }: ConnectionStatusMessage) => {\n setConnectionStatus(status);\n },\n []\n );\n\n useEffect(() => {\n ConnectionManager.on(\"connection-status\", handleStatusChange);\n return () => {\n ConnectionManager.removeListener(\"connection-status\", handleStatusChange);\n };\n }, [handleStatusChange]);\n\n return connectionStatus;\n};\n", "import { useCallback, useEffect, useState } from \"react\";\nimport { ConnectionManager } from \"@vuu-ui/vuu-data\";\n\nexport const useServerConnectionQuality = () => {\n const [messagesPerSecond, setMessagesPerSecond] = useState<number>(0);\n const handleConnectivityMessage = useCallback(({ messages }) => {\n setMessagesPerSecond(messages.messagesLength);\n }, []);\n\n useEffect(() => {\n ConnectionManager.on(\"connection-metrics\", handleConnectivityMessage);\n return () => {\n ConnectionManager.removeListener(\n \"connection-metrics\",\n handleConnectivityMessage\n );\n };\n }, [handleConnectivityMessage]);\n\n return messagesPerSecond;\n};\n", "import {\n ClientToServerGetUniqueValues,\n ClientToServerGetUniqueValuesStartingWith,\n TypeaheadParams,\n VuuTable,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport { useCallback } from \"react\";\nimport { makeRpcCall } from \"@vuu-ui/vuu-data\";\n\nexport type SuggestionFetcher = (params: TypeaheadParams) => Promise<string[]>;\n\n// const SPECIAL_SPACE = \"_\";\nconst TYPEAHEAD_MESSAGE_CONSTANTS = {\n type: \"RPC_CALL\",\n service: \"TypeAheadRpcHandler\",\n};\n\nexport const getTypeaheadParams = (\n table: VuuTable,\n column: string,\n text = \"\",\n selectedValues: string[] = []\n): TypeaheadParams => {\n if (text !== \"\" && !selectedValues.includes(text.toLowerCase())) {\n return [table, column, text];\n }\n return [table, column];\n};\n\n// const containSpace = (text: string) => text.indexOf(\" \") !== -1;\n// const replaceSpace = (text: string) => text.replace(/\\s/g, SPECIAL_SPACE);\n\nexport const useTypeaheadSuggestions = () => {\n const getTypeaheadSuggestions: SuggestionFetcher = useCallback(\n async (params: TypeaheadParams) => {\n const rpcMessage =\n params.length === 2\n ? ({\n method: \"getUniqueFieldValues\",\n params,\n ...TYPEAHEAD_MESSAGE_CONSTANTS,\n } as ClientToServerGetUniqueValues)\n : ({\n method: \"getUniqueFieldValuesStartingWith\",\n params,\n ...TYPEAHEAD_MESSAGE_CONSTANTS,\n } as ClientToServerGetUniqueValuesStartingWith);\n\n const suggestions = await makeRpcCall<string[]>(rpcMessage);\n\n // TODO replacing space with underscores like this is not being correctly handled elsewhere\n return suggestions;\n // return suggestions.some(containSpace)\n // ? suggestions.map(replaceSpace)\n // : suggestions;\n },\n []\n );\n\n return getTypeaheadSuggestions;\n};\n", "import {\n DataSource,\n DataSourceMenusMessage,\n DataSourceVisualLinkCreatedMessage,\n DataSourceVisualLinkRemovedMessage,\n DataSourceVisualLinksMessage,\n MenuRpcResponse,\n VuuFeatureInvocationMessage,\n VuuFeatureMessage,\n VuuUIMessageInRPCEditReject,\n VuuUIMessageInRPCEditResponse,\n} from \"@vuu-ui/vuu-data\";\nimport {\n ContextMenuItemDescriptor,\n DataSourceRow,\n MenuActionHandler,\n MenuBuilder,\n} from \"@vuu-ui/vuu-data-types\";\nimport { GridAction } from \"@vuu-ui/vuu-datagrid-types\";\nimport { getFilterPredicate } from \"@vuu-ui/vuu-filter-parser\";\nimport {\n ClientToServerMenuCellRPC,\n ClientToServerMenuRowRPC,\n ClientToServerMenuRPC,\n LinkDescriptorWithLabel,\n VuuMenu,\n VuuMenuContext,\n VuuMenuItem,\n VuuRowDataItemType,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport {\n ColumnMap,\n getRowRecord,\n isGroupMenuItemDescriptor,\n metadataKeys,\n} from \"@vuu-ui/vuu-utils\";\nimport type { MenuActionClosePopup } from \"@vuu-ui/vuu-popups\";\nimport { useCallback } from \"react\";\n\nexport const addRowsFromInstruments = \"addRowsFromInstruments\";\n\nexport interface VuuCellMenuItem extends VuuMenuItem {\n rowKey: string;\n field: string;\n value: VuuRowDataItemType;\n}\nexport interface VuuRowMenuItem extends VuuMenuItem {\n rowKey: string;\n row: { [key: string]: VuuRowDataItemType };\n}\n\nconst { KEY } = metadataKeys;\n\nconst NO_CONFIG: MenuActionConfig = {};\n\nexport const isVisualLinksAction = (\n action: GridAction\n): action is DataSourceVisualLinksMessage => action.type === \"vuu-links\";\n\nexport const isVisualLinkCreatedAction = (\n action: GridAction\n): action is DataSourceVisualLinkCreatedMessage =>\n action.type === \"vuu-link-created\";\n\nexport const isVisualLinkRemovedAction = (\n action: GridAction\n): action is DataSourceVisualLinkRemovedMessage =>\n action.type === \"vuu-link-removed\";\n\nexport const isViewportMenusAction = (\n action: GridAction\n): action is DataSourceMenusMessage => action.type === \"vuu-menu\";\n\nexport const isVuuFeatureAction = (\n action: GridAction\n): action is VuuFeatureMessage =>\n isViewportMenusAction(action) || isVisualLinksAction(action);\n\nexport const isVuuFeatureInvocation = (\n action: GridAction\n): action is VuuFeatureInvocationMessage =>\n action.type === \"vuu-link-created\" || action.type === \"vuu-link-removed\";\n\nconst isMenuItem = (menu: VuuMenuItem | VuuMenu): menu is VuuMenuItem =>\n \"rpcName\" in menu;\n\nconst isGroupMenuItem = (menu: VuuMenuItem | VuuMenu): menu is VuuMenu =>\n \"menus\" in menu;\n\nconst isRoot = (menu: VuuMenu) => menu.name === \"ROOT\";\n\nconst isCellMenu = (options: VuuMenuItem): options is VuuCellMenuItem =>\n options.context === \"cell\";\nconst isRowMenu = (options: VuuMenuItem): options is VuuRowMenuItem =>\n options.context === \"row\";\nconst isSelectionMenu = (options: VuuMenuItem): options is VuuMenuItem =>\n options.context === \"selected-rows\";\n\nconst vuuContextCompatibleWithTableLocation = (\n uiLocation: \"grid\" | \"header\" | \"filter\",\n vuuContext: VuuMenuContext,\n selectedRowCount = 0\n) => {\n switch (uiLocation) {\n case \"grid\":\n if (vuuContext === \"selected-rows\") {\n return selectedRowCount > 0;\n } else {\n return true;\n }\n case \"header\":\n return vuuContext === \"grid\";\n default:\n return false;\n }\n};\n\nconst gridRowMeetsFilterCriteria = (\n context: VuuMenuContext,\n row: DataSourceRow,\n selectedRows: DataSourceRow[],\n filter: string,\n columnMap: ColumnMap\n): boolean => {\n if (context === \"cell\" || context === \"row\") {\n const filterPredicate = getFilterPredicate(columnMap, filter);\n return filterPredicate(row);\n } else if (context === \"selected-rows\") {\n if (selectedRows.length === 0) {\n return false;\n } else {\n const filterPredicate = getFilterPredicate(columnMap, filter);\n return selectedRows.every(filterPredicate);\n }\n }\n return true;\n};\n\nconst getMenuRpcRequest = (\n options: VuuMenuItem\n): Omit<ClientToServerMenuRPC, \"vpId\"> => {\n const { rpcName } = options;\n if (isCellMenu(options)) {\n return {\n field: options.field,\n rowKey: options.rowKey,\n rpcName,\n value: options.value,\n type: \"VIEW_PORT_MENU_CELL_RPC\",\n } as Omit<ClientToServerMenuCellRPC, \"vpId\">;\n } else if (isRowMenu(options)) {\n return {\n rowKey: options.rowKey,\n row: options.row,\n rpcName,\n type: \"VIEW_PORT_MENU_ROW_RPC\",\n } as Omit<ClientToServerMenuRowRPC, \"vpId\">;\n } else if (isSelectionMenu(options)) {\n return {\n rpcName,\n type: \"VIEW_PORT_MENUS_SELECT_RPC\",\n } as Omit<ClientToServerMenuRPC, \"vpId\">;\n } else {\n return {\n rpcName,\n type: \"VIEW_PORT_MENU_TABLE_RPC\",\n } as Omit<ClientToServerMenuRPC, \"vpId\">;\n }\n};\n\nexport type VuuMenuActionHandler = (type: string, options: unknown) => boolean;\n\nexport interface ViewServerHookResult {\n buildViewserverMenuOptions: MenuBuilder;\n handleMenuAction: MenuActionHandler;\n}\n\nexport interface MenuActionConfig {\n vuuMenu?: VuuMenu;\n visualLink?: DataSourceVisualLinkCreatedMessage;\n visualLinks?: LinkDescriptorWithLabel[];\n}\n\nexport type RpcResponseHandler = (\n response:\n | MenuRpcResponse\n | VuuUIMessageInRPCEditReject\n | VuuUIMessageInRPCEditResponse\n) => void;\n\nexport interface VuuMenuActionHookProps {\n /**\n * By default, vuuMenuActions will be handled automatically. When activated, a\n * message will be sent to server and response will be handled here too.\n * This prop allows client to provide a custom handler for a menu Item. This will\n * take priority and if handler returns true, no further processing for the menu\n * item will be handled by Vuu. This can also be used to prevent an item from being\n * actioned, even when no custom handling is intended. If the handler returns false,\n * Vuu will process the menuItem.\n */\n clientSideMenuActionHandler?: VuuMenuActionHandler;\n dataSource: DataSource;\n menuActionConfig?: MenuActionConfig;\n onRpcResponse?: RpcResponseHandler;\n}\n\ntype TableMenuLocation = \"grid\" | \"header\" | \"filter\";\n\nconst isTableLocation = (location: string): location is TableMenuLocation =>\n [\"grid\", \"header\", \"filter\"].includes(location);\n\nexport type VuuServerMenuOptions = {\n columnMap: ColumnMap;\n columnName: string;\n row: DataSourceRow;\n selectedRows: DataSourceRow[];\n viewport: string;\n};\n\nconst hasFilter = ({ filter }: VuuMenuItem) =>\n typeof filter === \"string\" && filter.length > 0;\n\nconst getMenuItemOptions = (\n menu: VuuMenuItem,\n options: VuuServerMenuOptions\n): VuuMenuItem => {\n switch (menu.context) {\n case \"cell\":\n return {\n ...menu,\n field: options.columnName,\n rowKey: options.row[KEY],\n value: options.row[options.columnMap[options.columnName]],\n } as VuuCellMenuItem;\n case \"row\":\n return {\n ...menu,\n row: getRowRecord(options.row, options.columnMap),\n rowKey: options.row[KEY],\n } as VuuRowMenuItem;\n default:\n return menu;\n }\n};\n\nconst menuShouldBeRenderedInThisContext = (\n menuItem: VuuMenu | VuuMenuItem,\n tableLocation: TableMenuLocation,\n options: VuuServerMenuOptions\n): boolean => {\n if (isGroupMenuItem(menuItem)) {\n return menuItem.menus.some((childMenu) =>\n menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)\n );\n }\n if (\n !vuuContextCompatibleWithTableLocation(\n tableLocation,\n menuItem.context,\n options.selectedRows?.length\n )\n ) {\n return false;\n }\n\n if (tableLocation === \"grid\" && hasFilter(menuItem)) {\n return gridRowMeetsFilterCriteria(\n menuItem.context,\n options.row,\n options.selectedRows,\n menuItem.filter,\n options.columnMap\n );\n }\n\n if (isCellMenu(menuItem) && menuItem.field !== \"*\") {\n return menuItem.field === options.columnName;\n }\n\n return true;\n};\n\nconst buildMenuDescriptor = (\n menu: VuuMenu | VuuMenuItem,\n tableLocation: TableMenuLocation,\n options: VuuServerMenuOptions\n): ContextMenuItemDescriptor | undefined => {\n if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {\n if (isMenuItem(menu)) {\n return {\n label: menu.name,\n action: \"MENU_RPC_CALL\",\n options: getMenuItemOptions(menu, options),\n };\n } else {\n const children = menu.menus\n .map((childMenu) =>\n buildMenuDescriptor(childMenu, tableLocation, options)\n )\n .filter(\n (childMenu) => childMenu !== undefined\n ) as ContextMenuItemDescriptor[];\n if (children.length > 0) {\n return {\n label: menu.name,\n children,\n };\n }\n }\n }\n};\n\nexport const useVuuMenuActions = ({\n clientSideMenuActionHandler,\n dataSource,\n menuActionConfig = NO_CONFIG,\n onRpcResponse,\n}: VuuMenuActionHookProps): ViewServerHookResult => {\n const buildViewserverMenuOptions: MenuBuilder = useCallback(\n (location, options) => {\n const { visualLink, visualLinks, vuuMenu } = menuActionConfig;\n const descriptors: ContextMenuItemDescriptor[] = [];\n\n if (location === \"grid\" && visualLinks && !visualLink) {\n visualLinks.forEach((linkDescriptor: LinkDescriptorWithLabel) => {\n const { link, label: linkLabel } = linkDescriptor;\n const label = linkLabel ? linkLabel : link.toTable;\n descriptors.push({\n label: `Link to ${label}`,\n action: \"link-table\",\n options: linkDescriptor,\n });\n });\n }\n\n if (vuuMenu && isTableLocation(location)) {\n const menuDescriptor = buildMenuDescriptor(\n vuuMenu,\n location,\n options as VuuServerMenuOptions\n );\n if (isRoot(vuuMenu) && isGroupMenuItemDescriptor(menuDescriptor)) {\n descriptors.push(...menuDescriptor.children);\n } else if (menuDescriptor) {\n descriptors.push(menuDescriptor);\n }\n }\n\n return descriptors;\n },\n [menuActionConfig]\n );\n\n const handleMenuAction = useCallback(\n ({ menuId, options }: MenuActionClosePopup) => {\n if (clientSideMenuActionHandler?.(menuId, options)) {\n return true;\n } else if (menuId === \"MENU_RPC_CALL\") {\n const rpcRequest = getMenuRpcRequest(options as unknown as VuuMenuItem);\n dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {\n if (onRpcResponse && rpcResponse) {\n onRpcResponse && onRpcResponse(rpcResponse);\n }\n });\n return true;\n } else if (menuId === \"link-table\") {\n // return dataSource.createLink(options as LinkDescriptorWithLabel), true;\n return (\n (dataSource.visualLink = options as LinkDescriptorWithLabel), true\n );\n } else {\n console.log(\n `useViewServer handleMenuAction, can't handle action type ${menuId}`\n );\n }\n return false;\n },\n [clientSideMenuActionHandler, dataSource, onRpcResponse]\n );\n\n return {\n buildViewserverMenuOptions,\n handleMenuAction,\n };\n};\n", "import { useCallback, useEffect, useState } from \"react\";\nimport { getServerAPI, TableSchema } from \"@vuu-ui/vuu-data\";\n\nexport const useVuuTables = () => {\n const [tables, setTables] = useState<Map<string, TableSchema> | undefined>();\n\n const buildTables = useCallback((schemas: TableSchema[]) => {\n const vuuTables = new Map<string, TableSchema>();\n schemas.forEach((schema) => {\n vuuTables.set(schema.table.table, schema);\n });\n return vuuTables;\n }, []);\n\n useEffect(() => {\n async function fetchTableMetadata() {\n const server = await getServerAPI();\n const { tables } = await server.getTableList();\n const tableSchemas = buildTables(\n await Promise.all(\n tables.map((tableDescriptor) =>\n server.getTableSchema(tableDescriptor)\n )\n )\n );\n setTables(tableSchemas);\n }\n\n fetchTableMetadata();\n }, [buildTables]);\n\n return tables;\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_react", "import_react", "import_vuu_data", "import_react", "import_vuu_data", "import_vuu_utils", "import_react", "import_react", "import_vuu_data", "tables"]
|
|
5
|
+
"mappings": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,kBAAAE,EAAA,2BAAAC,EAAA,uBAAAC,EAAA,0BAAAC,EAAA,8BAAAC,EAAA,8BAAAC,EAAA,wBAAAC,EAAA,uBAAAC,GAAA,2BAAAC,GAAA,kBAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,4BAAAC,EAAA,sBAAAC,GAAA,iBAAAC,KAAA,eAAAC,EAAAjB,ICIA,IAAAkB,EAAwD,6BACxDC,EAAkE,iBAE5D,CAAE,SAAAC,CAAS,EAAI,eAOd,SAASC,EAAc,CAC5B,WAAAC,EACA,iBAAAC,EAAmB,EACrB,EAKE,CACA,GAAM,CAAC,CAAEC,CAAW,KAAI,YAAwB,IAAI,EAC9CC,KAAY,UAAO,EAAI,EACvBC,KAAa,UAAO,EAAK,EACzBC,KAAY,UAAO,IAAI,EACvBC,KAAO,UAAwB,CAAC,CAAC,E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AF,EAAmB,CACrB,EAAG,CAACJ,CAAW,CAAC,EAETF,CACT",
|
|
6
|
+
"names": ["src_exports", "__export", "MovingWindow", "addRowsFromInstruments", "getTypeaheadParams", "isViewportMenusAction", "isVisualLinkCreatedAction", "isVisualLinkRemovedAction", "isVisualLinksAction", "isVuuFeatureAction", "isVuuFeatureInvocation", "useDataSource", "useServerConnectionQuality", "useServerConnectionStatus", "useTypeaheadSuggestions", "useVuuMenuActions", "useVuuTables", "__toCommonJS", "import_vuu_utils", "import_react", "SELECTED", "useDataSource", "dataSource", "renderBufferSize", "forceUpdate", "isMounted", "hasUpdated", "rafHandle", "data", "rangeRef", "dataWindow", "MovingWindow", "setData", "updates", "row", "datasourceMessageHandler", "message", "setRange", "range", "fullRange", "from", "to", "rowCount", "index", "internalIndex", "overlapFrom", "overlapTo", "newData", "i", "import_react", "import_vuu_data", "useServerConnectionStatus", "connectionStatus", "setConnectionStatus", "handleStatusChange", "status", "import_react", "import_vuu_data", "useServerConnectionQuality", "messagesPerSecond", "setMessagesPerSecond", "handleConnectivityMessage", "messages", "import_react", "import_vuu_data", "TYPEAHEAD_MESSAGE_CONSTANTS", "getTypeaheadParams", "table", "column", "text", "selectedValues", "useTypeaheadSuggestions", "params", "rpcMessage", "import_vuu_filter_parser", "import_vuu_utils", "import_react", "addRowsFromInstruments", "KEY", "NO_CONFIG", "isVisualLinksAction", "action", "isVisualLinkCreatedAction", "isVisualLinkRemovedAction", "isViewportMenusAction", "isVuuFeatureAction", "isVuuFeatureInvocation", "isMenuItem", "menu", "isGroupMenuItem", "isRoot", "isCellMenu", "options", "isRowMenu", "isSelectionMenu", "vuuContextCompatibleWithTableLocation", "uiLocation", "vuuContext", "selectedRowCount", "gridRowMeetsFilterCriteria", "context", "row", "selectedRows", "filter", "columnMap", "filterPredicate", "getMenuRpcRequest", "rpcName", "isTableLocation", "location", "hasFilter", "getMenuItemOptions", "menuShouldBeRenderedInThisContext", "menuItem", "tableLocation", "_a", "childMenu", "buildMenuDescriptor", "children", "useVuuMenuActions", "clientSideMenuActionHandler", "dataSource", "menuActionConfig", "onRpcResponse", "buildViewserverMenuOptions", "visualLink", "visualLinks", "vuuMenu", "descriptors", "linkDescriptor", "link", "linkLabel", "label", "menuDescriptor", "handleMenuAction", "menuId", "rpcRequest", "rpcResponse", "import_react", "import_vuu_data", "useVuuTables", "tables", "setTables", "buildTables", "schemas", "vuuTables", "schema", "fetchTableMetadata", "server", "tableSchemas", "tableDescriptor"]
|
|
7
7
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,481 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
import{getFullRange as g,metadataKeys as P,WindowRange as A}from"@vuu-ui/vuu-utils";import{useCallback as C,useEffect as R,useMemo as w,useRef as f,useState as E}from"react";var{SELECTED:h}=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 V(g(a.current,t)),[t]),p=C(u=>{for(let l of u)i.add(l);s.current=i.data.slice(),o.current=!0},[i]),m=C(u=>{u.type==="viewport-update"&&(u.size!==void 0&&i.setRowCount(u.size),u.rows?(p(u.rows),n({})):u.size!==void 0&&(s.current=i.data.slice(),o.current=!0))},[i,p]);R(()=>()=>{c.current&&(cancelAnimationFrame(c.current),c.current=null),r.current=!1},[]);let d=C(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,M=g({from:u,to:l},t);e.range=M,i.setRange(M.from,M.to)},[e,i,t]),R(()=>{let{from:u,to:l}=g(a.current,t);e.subscribe({range:{from:u,to:l}},m)},[e,m,t]),R(()=>()=>{e.unsubscribe()},[e]),[s.current,i.rowCount,g(a.current,t),d]}var V=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][h]===1&&t[h]===0&&(t[h]=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 _,useEffect as O,useState as F}from"react";import{ConnectionManager as v}from"@vuu-ui/vuu-data";var Ce=()=>{let[e,t]=F("disconnected"),n=_(({status:r})=>{t(r)},[]);return O(()=>(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 we=()=>{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 H}from"@vuu-ui/vuu-data";var b={type:"RPC_CALL",service:"TypeAheadRpcHandler"},Te=(e,t,n="",r=[])=>n!==""&&!r.includes(n.toLowerCase())?[e,t,n]:[e,t],ye=()=>G(async t=>{let n=t.length===2?{method:"getUniqueFieldValues",params:t,...b}:{method:"getUniqueFieldValuesStartingWith",params:t,...b};return await H(n)},[]);import{getFilterPredicate as T}from"@vuu-ui/vuu-filter-parser";import{getRowRecord as K,isGroupMenuItemDescriptor as q,metadataKeys as j}from"@vuu-ui/vuu-utils";import{useCallback as y}from"react";var Pe="addRowsFromInstruments",{KEY:I}=j,Y={},$=e=>e.type==="vuu-links",Ae=e=>e.type==="vuu-link-created",Ee=e=>e.type==="vuu-link-removed",Q=e=>e.type==="vuu-menu",_e=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=e=>["grid","header","filter"].includes(e),ue=({filter:e})=>typeof e=="string"&&e.length>0,oe=(e,t)=>{switch(e.context){case"cell":return{...e,field:t.columnName,rowKey:t.row[I],value:t.row[t.columnMap[t.columnName]]};case"row":return{...e,row:K(t.row,t.columnMap),rowKey:t.row[I]};default:return e}},k=(e,t,n)=>{var r;return X(e)?e.menus.some(o=>k(o,t,n)):ee(t,e.context,(r=n.selectedRows)==null?void 0:r.length)?t==="grid"&&ue(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(k(e,t,n)){if(J(e))return{label:e.name,action:"MENU_RPC_CALL",options:oe(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}}}},Fe=({clientSideMenuActionHandler:e,dataSource:t,menuActionConfig:n=Y,onRpcResponse:r})=>{let o=y((s,a)=>{let{visualLink:i,visualLinks:p,vuuMenu:m}=n,d=[];if(s==="grid"&&p&&!i&&p.forEach(u=>{let{link:l,label:M}=u,L=M||l.toTable;d.push({label:`Link to ${L}`,action:"link-table",options:u})}),m&&re(s)){let u=D(m,s,a);Z(m)&&q(u)?d.push(...u.children):u&&d.push(u)}return d},[n]),c=y(({menuId:s,options:a})=>{if(e!=null&&e(s,a))return!0;if(s==="MENU_RPC_CALL"){let i=ne(a);return t.menuRpcCall(i).then(p=>{r&&p&&r&&r(p)}),!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 se,useEffect as ae,useState as ie}from"react";import{getServerAPI as ce}from"@vuu-ui/vuu-data";var He=()=>{let[e,t]=ie(),n=se(r=>{let o=new Map;return r.forEach(c=>{o.set(c.table.table,c)}),o},[]);return ae(()=>{async function r(){let o=await ce(),{tables:c}=await o.getTableList(),s=n(await Promise.all(c.map(a=>o.getTableSchema(a))));t(s)}r()},[n]),e};export{V as MovingWindow,Pe as addRowsFromInstruments,Te as getTypeaheadParams,Q as isViewportMenusAction,Ae as isVisualLinkCreatedAction,Ee as isVisualLinkRemovedAction,$ as isVisualLinksAction,_e as isVuuFeatureAction,Oe as isVuuFeatureInvocation,me as useDataSource,we as useServerConnectionQuality,Ce as useServerConnectionStatus,ye as useTypeaheadSuggestions,Fe as useVuuMenuActions,He as useVuuTables};
|
|
481
2
|
//# sourceMappingURL=index.js.map
|