@vuu-ui/vuu-data-react 0.8.5-debug → 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.
- package/cjs/index.js +10 -9
- package/cjs/index.js.map +2 -2
- package/esm/index.js +10 -9
- package/esm/index.js.map +2 -2
- package/package.json +8 -8
- package/types/{hooks → vuu-data-react/src/hooks}/useVuuMenuActions.d.ts +5 -6
- package/types/vuu-popups/src/dialog/Dialog.d.ts +7 -0
- package/types/vuu-popups/src/dialog/index.d.ts +1 -0
- package/types/vuu-popups/src/index.d.ts +5 -0
- package/types/vuu-popups/src/menu/ContextMenu.d.ts +15 -0
- package/types/vuu-popups/src/menu/MenuList.d.ts +43 -0
- package/types/vuu-popups/src/menu/context-menu-provider.d.ts +10 -0
- package/types/vuu-popups/src/menu/index.d.ts +4 -0
- package/types/vuu-popups/src/menu/key-code.d.ts +12 -0
- package/types/vuu-popups/src/menu/list-dom-utils.d.ts +4 -0
- package/types/vuu-popups/src/menu/use-cascade.d.ts +25 -0
- package/types/vuu-popups/src/menu/use-items-with-ids-next.d.ts +13 -0
- package/types/vuu-popups/src/menu/use-keyboard-navigation.d.ts +26 -0
- package/types/vuu-popups/src/menu/useContextMenu.d.ts +13 -0
- package/types/vuu-popups/src/menu/utils.d.ts +2 -0
- package/types/vuu-popups/src/popup/index.d.ts +1 -0
- package/types/vuu-popups/src/popup/popup-service.d.ts +55 -0
- package/types/vuu-popups/src/popup-menu/PopupMenu.d.ts +14 -0
- package/types/vuu-popups/src/popup-menu/index.d.ts +1 -0
- package/types/vuu-popups/src/portal/Portal.d.ts +8 -0
- package/types/vuu-popups/src/portal/index.d.ts +3 -0
- package/types/vuu-popups/src/portal/portal-utils.d.ts +1 -0
- package/types/vuu-popups/src/portal/render-portal.d.ts +10 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/index.d.ts +0 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/useDataSource.d.ts +0 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/useServerConnectionQuality.d.ts +0 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/useServerConnectionStatus.d.ts +0 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/useTypeaheadSuggestions.d.ts +0 -0
- /package/types/{hooks → vuu-data-react/src/hooks}/useVuuTables.d.ts +0 -0
- /package/types/{index.d.ts → vuu-data-react/src/index.d.ts} +0 -0
package/cjs/index.js
CHANGED
|
@@ -330,6 +330,7 @@ var getMenuRpcRequest = (options) => {
|
|
|
330
330
|
};
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
|
+
var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
|
|
333
334
|
var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
|
|
334
335
|
var getMenuItemOptions = (menu, options) => {
|
|
335
336
|
switch (menu.context) {
|
|
@@ -408,10 +409,10 @@ var useVuuMenuActions = ({
|
|
|
408
409
|
onRpcResponse
|
|
409
410
|
}) => {
|
|
410
411
|
const buildViewserverMenuOptions = (0, import_react5.useCallback)(
|
|
411
|
-
(
|
|
412
|
+
(location, options) => {
|
|
412
413
|
const { visualLink, visualLinks, vuuMenu } = menuActionConfig;
|
|
413
414
|
const descriptors = [];
|
|
414
|
-
if (
|
|
415
|
+
if (location === "grid" && visualLinks && !visualLink) {
|
|
415
416
|
visualLinks.forEach((linkDescriptor) => {
|
|
416
417
|
const { link, label: linkLabel } = linkDescriptor;
|
|
417
418
|
const label = linkLabel ? linkLabel : link.toTable;
|
|
@@ -422,10 +423,10 @@ var useVuuMenuActions = ({
|
|
|
422
423
|
});
|
|
423
424
|
});
|
|
424
425
|
}
|
|
425
|
-
if (vuuMenu) {
|
|
426
|
+
if (vuuMenu && isTableLocation(location)) {
|
|
426
427
|
const menuDescriptor = buildMenuDescriptor(
|
|
427
428
|
vuuMenu,
|
|
428
|
-
|
|
429
|
+
location,
|
|
429
430
|
options
|
|
430
431
|
);
|
|
431
432
|
if (isRoot(vuuMenu) && (0, import_vuu_utils2.isGroupMenuItemDescriptor)(menuDescriptor)) {
|
|
@@ -439,10 +440,10 @@ var useVuuMenuActions = ({
|
|
|
439
440
|
[menuActionConfig]
|
|
440
441
|
);
|
|
441
442
|
const handleMenuAction = (0, import_react5.useCallback)(
|
|
442
|
-
(
|
|
443
|
-
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(
|
|
443
|
+
({ menuId, options }) => {
|
|
444
|
+
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
|
|
444
445
|
return true;
|
|
445
|
-
} else if (
|
|
446
|
+
} else if (menuId === "MENU_RPC_CALL") {
|
|
446
447
|
const rpcRequest = getMenuRpcRequest(options);
|
|
447
448
|
dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
|
|
448
449
|
if (onRpcResponse && rpcResponse) {
|
|
@@ -450,11 +451,11 @@ var useVuuMenuActions = ({
|
|
|
450
451
|
}
|
|
451
452
|
});
|
|
452
453
|
return true;
|
|
453
|
-
} else if (
|
|
454
|
+
} else if (menuId === "link-table") {
|
|
454
455
|
return dataSource.visualLink = options, true;
|
|
455
456
|
} else {
|
|
456
457
|
console.log(
|
|
457
|
-
`useViewServer handleMenuAction, can't handle action type ${
|
|
458
|
+
`useViewServer handleMenuAction, can't handle action type ${menuId}`
|
|
458
459
|
);
|
|
459
460
|
}
|
|
460
461
|
return false;
|
package/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
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
|
-
"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 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 { 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 TableMenuLocation,\n VuuServerMenuOptions\n >;\n handleMenuAction: VuuMenuActionHandler;\n}\n\nexport interface MenuActionConfig {\n vuuMenu?: VuuMenu;\n visualLink?: DataSourceVisualLinkCreatedMessage;\n visualLinks?: LinkDescriptorWithLabel[];\n}\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?: (\n response:\n | MenuRpcResponse\n | VuuUIMessageInRPCEditReject\n | VuuUIMessageInRPCEditResponse\n ) => void;\n}\n\ntype TableMenuLocation = \"grid\" | \"header\" | \"filter\";\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<\n TableMenuLocation,\n VuuServerMenuOptions\n > = useCallback(\n (tableLocation, options) => {\n const { visualLink, visualLinks, vuuMenu } = menuActionConfig;\n const descriptors: ContextMenuItemDescriptor[] = [];\n\n if (tableLocation === \"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) {\n const menuDescriptor = buildMenuDescriptor(\n vuuMenu,\n tableLocation,\n options\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 (type: string, options: unknown) => {\n if (clientSideMenuActionHandler?.(type, options)) {\n return true;\n } else if (type === \"MENU_RPC_CALL\") {\n const rpcRequest = getMenuRpcRequest(options as VuuMenuItem);\n dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {\n if (onRpcResponse && rpcResponse) {\n onRpcResponse && onRpcResponse(rpcResponse);\n }\n });\n return true;\n } else if (type === \"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 ${type}`\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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,uBAAwD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AAQ;AAAA,QACR;AAAA,QACA,GAAG;AAAA,MACL,IACC;AAAA,QACC,QAAQ;AAAA,QACR;AAAA,QACA,GAAG;AAAA,MACL;AAEN,YAAM,cAAc,UAAM,8BAAsB,UAAU;AAG1D,aAAO;AAAA,IAIT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;
|
|
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 { MenuActionClosePopup } from \"packages/vuu-popups/src\";\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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,uBAAwD;AACxD,mBAAkE;AAElE,IAAM,EAAE,SAAS,IAAI;AAOd,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,mBAAmB;AACrB,GAKE;AACA,QAAM,CAAC,EAAE,WAAW,QAAI,uBAAwB,IAAI;AACpD,QAAM,gBAAY,qBAAO,IAAI;AAC7B,QAAM,iBAAa,qBAAO,KAAK;AAC/B,QAAM,gBAAY,qBAAO,IAAI;AAC7B,QAAM,WAAO,qBAAwB,CAAC,CAAC;AACvC,QAAM,eAAW,qBAAO,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC;AAE3C,QAAM,iBAAa;AAAA,IACjB,MAAM,IAAI,iBAAa,+BAAa,SAAS,SAAS,gBAAgB,CAAC;AAAA,IACvE,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,cAAU;AAAA,IACd,CAAC,YAA6B;AAC5B,iBAAW,OAAO,SAAS;AACzB,mBAAW,IAAI,GAAG;AAAA,MACpB;AAEA,WAAK,UAAU,WAAW,KAAK,MAAM;AAErC,iBAAW,UAAU;AAAA,IACvB;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,+BAA8C;AAAA,IAClD,CAAC,YAAY;AACX,UAAI,QAAQ,SAAS,mBAAmB;AACtC,YAAI,QAAQ,SAAS,QAAW;AAC9B,qBAAW,YAAY,QAAQ,IAAI;AAAA,QACrC;AACA,YAAI,QAAQ,MAAM;AAChB,kBAAQ,QAAQ,IAAI;AACpB,sBAAY,C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_react", "import_react", "import_vuu_data", "import_react", "import_vuu_data", "import_vuu_utils", "import_react", "import_react", "import_vuu_data", "tables"]
|
|
7
7
|
}
|
package/esm/index.js
CHANGED
|
@@ -294,6 +294,7 @@ var getMenuRpcRequest = (options) => {
|
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
};
|
|
297
|
+
var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
|
|
297
298
|
var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
|
|
298
299
|
var getMenuItemOptions = (menu, options) => {
|
|
299
300
|
switch (menu.context) {
|
|
@@ -372,10 +373,10 @@ var useVuuMenuActions = ({
|
|
|
372
373
|
onRpcResponse
|
|
373
374
|
}) => {
|
|
374
375
|
const buildViewserverMenuOptions = useCallback5(
|
|
375
|
-
(
|
|
376
|
+
(location, options) => {
|
|
376
377
|
const { visualLink, visualLinks, vuuMenu } = menuActionConfig;
|
|
377
378
|
const descriptors = [];
|
|
378
|
-
if (
|
|
379
|
+
if (location === "grid" && visualLinks && !visualLink) {
|
|
379
380
|
visualLinks.forEach((linkDescriptor) => {
|
|
380
381
|
const { link, label: linkLabel } = linkDescriptor;
|
|
381
382
|
const label = linkLabel ? linkLabel : link.toTable;
|
|
@@ -386,10 +387,10 @@ var useVuuMenuActions = ({
|
|
|
386
387
|
});
|
|
387
388
|
});
|
|
388
389
|
}
|
|
389
|
-
if (vuuMenu) {
|
|
390
|
+
if (vuuMenu && isTableLocation(location)) {
|
|
390
391
|
const menuDescriptor = buildMenuDescriptor(
|
|
391
392
|
vuuMenu,
|
|
392
|
-
|
|
393
|
+
location,
|
|
393
394
|
options
|
|
394
395
|
);
|
|
395
396
|
if (isRoot(vuuMenu) && isGroupMenuItemDescriptor(menuDescriptor)) {
|
|
@@ -403,10 +404,10 @@ var useVuuMenuActions = ({
|
|
|
403
404
|
[menuActionConfig]
|
|
404
405
|
);
|
|
405
406
|
const handleMenuAction = useCallback5(
|
|
406
|
-
(
|
|
407
|
-
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(
|
|
407
|
+
({ menuId, options }) => {
|
|
408
|
+
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
|
|
408
409
|
return true;
|
|
409
|
-
} else if (
|
|
410
|
+
} else if (menuId === "MENU_RPC_CALL") {
|
|
410
411
|
const rpcRequest = getMenuRpcRequest(options);
|
|
411
412
|
dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
|
|
412
413
|
if (onRpcResponse && rpcResponse) {
|
|
@@ -414,11 +415,11 @@ var useVuuMenuActions = ({
|
|
|
414
415
|
}
|
|
415
416
|
});
|
|
416
417
|
return true;
|
|
417
|
-
} else if (
|
|
418
|
+
} else if (menuId === "link-table") {
|
|
418
419
|
return dataSource.visualLink = options, true;
|
|
419
420
|
} else {
|
|
420
421
|
console.log(
|
|
421
|
-
`useViewServer handleMenuAction, can't handle action type ${
|
|
422
|
+
`useViewServer handleMenuAction, can't handle action type ${menuId}`
|
|
422
423
|
);
|
|
423
424
|
}
|
|
424
425
|
return false;
|
package/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../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
|
-
"sourcesContent": ["// 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 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 { 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 TableMenuLocation,\n VuuServerMenuOptions\n >;\n handleMenuAction: VuuMenuActionHandler;\n}\n\nexport interface MenuActionConfig {\n vuuMenu?: VuuMenu;\n visualLink?: DataSourceVisualLinkCreatedMessage;\n visualLinks?: LinkDescriptorWithLabel[];\n}\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?: (\n response:\n | MenuRpcResponse\n | VuuUIMessageInRPCEditReject\n | VuuUIMessageInRPCEditResponse\n ) => void;\n}\n\ntype TableMenuLocation = \"grid\" | \"header\" | \"filter\";\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<\n TableMenuLocation,\n VuuServerMenuOptions\n > = useCallback(\n (tableLocation, options) => {\n const { visualLink, visualLinks, vuuMenu } = menuActionConfig;\n const descriptors: ContextMenuItemDescriptor[] = [];\n\n if (tableLocation === \"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) {\n const menuDescriptor = buildMenuDescriptor(\n vuuMenu,\n tableLocation,\n options\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 (type: string, options: unknown) => {\n if (clientSideMenuActionHandler?.(type, options)) {\n return true;\n } else if (type === \"MENU_RPC_CALL\") {\n const rpcRequest = getMenuRpcRequest(options as VuuMenuItem);\n dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {\n if (onRpcResponse && rpcResponse) {\n onRpcResponse && onRpcResponse(rpcResponse);\n }\n });\n return true;\n } else if (type === \"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 ${type}`\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": ";AAIA,SAAS,cAAc,cAAc,mBAAmB;AACxD,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAElE,IAAM,EAAE,SAAS,IAAI;AAOd,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,mBAAmB;AACrB,GAKE;AACA,QAAM,CAAC,EAAE,WAAW,IAAI,SAAwB,IAAI;AACpD,QAAM,YAAY,OAAO,IAAI;AAC7B,QAAM,aAAa,OAAO,KAAK;AAC/B,QAAM,YAAY,OAAO,IAAI;AAC7B,QAAM,OAAO,OAAwB,CAAC,CAAC;AACvC,QAAM,WAAW,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG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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 { MenuActionClosePopup } from \"packages/vuu-popups/src\";\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": ";AAIA,SAAS,cAAc,cAAc,mBAAmB;AACxD,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAElE,IAAM,EAAE,SAAS,IA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,UAC5C;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT,WAAW,WAAW,cAAc;AAElC,eACG,WAAW,aAAa,SAAqC;AAAA,MAElE,OAAO;AACL,gBAAQ;AAAA,UACN,6DAA6D;AAAA,QAC/D;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,6BAA6B,YAAY,aAAa;AAAA,EACzD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;;AChYA,SAAS,eAAAC,cAAa,aAAAC,YAAW,YAAAC,iBAAgB;AACjD,SAAS,oBAAiC;AAEnC,IAAM,eAAe,MAAM;AAChC,QAAM,CAAC,QAAQ,SAAS,IAAIA,UAA+C;AAE3E,QAAM,cAAcF,aAAY,CAAC,YAA2B;AAC1D,UAAM,YAAY,oBAAI,IAAyB;AAC/C,YAAQ,QAAQ,CAAC,WAAW;AAC1B,gBAAU,IAAI,OAAO,MAAM,OAAO,MAAM;AAAA,IAC1C,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,EAAAC,WAAU,MAAM;AACd,mBAAe,qBAAqB;AAClC,YAAM,SAAS,MAAM,aAAa;AAClC,YAAM,EAAE,QAAAE,QAAO,IAAI,MAAM,OAAO,aAAa;AAC7C,YAAM,eAAe;AAAA,QACnB,MAAM,QAAQ;AAAA,UACZA,QAAO;AAAA,YAAI,CAAC,oBACV,OAAO,eAAe,eAAe;AAAA,UACvC;AAAA,QACF;AAAA,MACF;AACA,gBAAU,YAAY;AAAA,IACxB;AAEA,uBAAmB;AAAA,EACrB,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO;AACT;",
|
|
6
6
|
"names": ["useCallback", "useEffect", "useState", "useCallback", "useEffect", "useState", "ConnectionManager", "useCallback", "metadataKeys", "useCallback", "useCallback", "useEffect", "useState", "tables"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuu-ui/vuu-data-react",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6-debug",
|
|
4
4
|
"author": "heswell",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@vuu-ui/vuu-datagrid-types": "0.8.
|
|
8
|
-
"@vuu-ui/vuu-filter-types": "0.8.
|
|
9
|
-
"@vuu-ui/vuu-protocol-types": "0.8.
|
|
7
|
+
"@vuu-ui/vuu-datagrid-types": "0.8.6-debug",
|
|
8
|
+
"@vuu-ui/vuu-filter-types": "0.8.6-debug",
|
|
9
|
+
"@vuu-ui/vuu-protocol-types": "0.8.6-debug"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@vuu-ui/vuu-data": "0.8.
|
|
13
|
-
"@vuu-ui/vuu-data-types": "0.8.
|
|
14
|
-
"@vuu-ui/vuu-filter-parser": "0.8.
|
|
15
|
-
"@vuu-ui/vuu-utils": "0.8.
|
|
12
|
+
"@vuu-ui/vuu-data": "0.8.6-debug",
|
|
13
|
+
"@vuu-ui/vuu-data-types": "0.8.6-debug",
|
|
14
|
+
"@vuu-ui/vuu-filter-parser": "0.8.6-debug",
|
|
15
|
+
"@vuu-ui/vuu-utils": "0.8.6-debug"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": "^17.0.2"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataSource, DataSourceMenusMessage, DataSourceVisualLinkCreatedMessage, DataSourceVisualLinkRemovedMessage, DataSourceVisualLinksMessage, MenuRpcResponse, VuuFeatureInvocationMessage, VuuFeatureMessage, VuuUIMessageInRPCEditReject, VuuUIMessageInRPCEditResponse } from "@vuu-ui/vuu-data";
|
|
2
|
-
import { DataSourceRow, MenuBuilder } from "@vuu-ui/vuu-data-types";
|
|
2
|
+
import { DataSourceRow, MenuActionHandler, MenuBuilder } from "@vuu-ui/vuu-data-types";
|
|
3
3
|
import { GridAction } from "@vuu-ui/vuu-datagrid-types";
|
|
4
4
|
import { LinkDescriptorWithLabel, VuuMenu, VuuMenuItem, VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
|
|
5
5
|
import { ColumnMap } from "@vuu-ui/vuu-utils";
|
|
@@ -23,14 +23,15 @@ export declare const isVuuFeatureAction: (action: GridAction) => action is VuuFe
|
|
|
23
23
|
export declare const isVuuFeatureInvocation: (action: GridAction) => action is VuuFeatureInvocationMessage;
|
|
24
24
|
export type VuuMenuActionHandler = (type: string, options: unknown) => boolean;
|
|
25
25
|
export interface ViewServerHookResult {
|
|
26
|
-
buildViewserverMenuOptions: MenuBuilder
|
|
27
|
-
handleMenuAction:
|
|
26
|
+
buildViewserverMenuOptions: MenuBuilder;
|
|
27
|
+
handleMenuAction: MenuActionHandler;
|
|
28
28
|
}
|
|
29
29
|
export interface MenuActionConfig {
|
|
30
30
|
vuuMenu?: VuuMenu;
|
|
31
31
|
visualLink?: DataSourceVisualLinkCreatedMessage;
|
|
32
32
|
visualLinks?: LinkDescriptorWithLabel[];
|
|
33
33
|
}
|
|
34
|
+
export type RpcResponseHandler = (response: MenuRpcResponse | VuuUIMessageInRPCEditReject | VuuUIMessageInRPCEditResponse) => void;
|
|
34
35
|
export interface VuuMenuActionHookProps {
|
|
35
36
|
/**
|
|
36
37
|
* By default, vuuMenuActions will be handled automatically. When activated, a
|
|
@@ -44,9 +45,8 @@ export interface VuuMenuActionHookProps {
|
|
|
44
45
|
clientSideMenuActionHandler?: VuuMenuActionHandler;
|
|
45
46
|
dataSource: DataSource;
|
|
46
47
|
menuActionConfig?: MenuActionConfig;
|
|
47
|
-
onRpcResponse?:
|
|
48
|
+
onRpcResponse?: RpcResponseHandler;
|
|
48
49
|
}
|
|
49
|
-
type TableMenuLocation = "grid" | "header" | "filter";
|
|
50
50
|
export type VuuServerMenuOptions = {
|
|
51
51
|
columnMap: ColumnMap;
|
|
52
52
|
columnName: string;
|
|
@@ -55,4 +55,3 @@ export type VuuServerMenuOptions = {
|
|
|
55
55
|
viewport: string;
|
|
56
56
|
};
|
|
57
57
|
export declare const useVuuMenuActions: ({ clientSideMenuActionHandler, dataSource, menuActionConfig, onRpcResponse, }: VuuMenuActionHookProps) => ViewServerHookResult;
|
|
58
|
-
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
import "./Dialog.css";
|
|
3
|
+
export interface DialogProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
isOpen?: boolean;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const Dialog: ({ children, className, isOpen, onClose, title, ...props }: DialogProps) => JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dialog";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MenuListProps } from "./MenuList";
|
|
3
|
+
import { PopupCloseCallback } from "../popup";
|
|
4
|
+
export interface ContextMenuProps extends Omit<MenuListProps, "onCloseMenu"> {
|
|
5
|
+
onClose?: PopupCloseCallback;
|
|
6
|
+
position?: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
withPortal?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const ContextMenu: {
|
|
13
|
+
({ activatedByKeyboard, children: childrenProp, className, id: idProp, onClose, position, style, ...menuListProps }: ContextMenuProps): JSX.Element;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { FC, HTMLAttributes, ReactElement, ReactNode } from "react";
|
|
2
|
+
import "./MenuList.css";
|
|
3
|
+
export declare const Separator: () => JSX.Element;
|
|
4
|
+
export interface MenuItemGroupProps {
|
|
5
|
+
children: ReactElement<MenuItemProps>[] | [ReactElement<MenuItemLabelProps>, ...ReactElement<MenuItemProps>[]];
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MenuItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
action?: string;
|
|
10
|
+
idx?: number;
|
|
11
|
+
options?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare const MenuItemGroup: FC<MenuItemGroupProps>;
|
|
14
|
+
export declare const MenuItem: {
|
|
15
|
+
({ children, idx, ...props }: MenuItemProps): JSX.Element;
|
|
16
|
+
Label: {
|
|
17
|
+
({ children }: {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}): JSX.Element;
|
|
20
|
+
displayName: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export interface MenuItemLabelProps {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
export declare const isMenuItemLabel: (item: ReactNode) => item is React.ReactElement<MenuItemLabelProps, string | React.JSXElementConstructor<any>>;
|
|
27
|
+
export interface MenuListProps extends HTMLAttributes<HTMLDivElement> {
|
|
28
|
+
activatedByKeyboard?: boolean;
|
|
29
|
+
children: ReactElement[];
|
|
30
|
+
childMenuShowing?: string;
|
|
31
|
+
highlightedIdx?: number;
|
|
32
|
+
isRoot?: boolean;
|
|
33
|
+
listItemProps?: Partial<MenuItemProps>;
|
|
34
|
+
onActivate?: (menuId: string) => void;
|
|
35
|
+
onCloseMenu: (idx: number) => void;
|
|
36
|
+
onOpenMenu?: (menuItemEl: HTMLElement) => void;
|
|
37
|
+
onHighlightMenuItem?: (idx: number) => void;
|
|
38
|
+
}
|
|
39
|
+
declare const MenuList: {
|
|
40
|
+
({ activatedByKeyboard, childMenuShowing, children, className, highlightedIdx: highlightedIdxProp, id: idProp, isRoot, listItemProps, onHighlightMenuItem, onActivate, onCloseMenu, onOpenMenu, ...props }: MenuListProps): JSX.Element;
|
|
41
|
+
displayName: string;
|
|
42
|
+
};
|
|
43
|
+
export default MenuList;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContextMenuContextType, MenuActionHandler, MenuBuilder } from "@vuu-ui/vuu-data-types";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
export declare const ContextMenuContext: import("react").Context<ContextMenuContextType | null>;
|
|
4
|
+
export interface ContextMenuProviderProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
label?: string;
|
|
7
|
+
menuActionHandler?: MenuActionHandler;
|
|
8
|
+
menuBuilder: MenuBuilder;
|
|
9
|
+
}
|
|
10
|
+
export declare const ContextMenuProvider: ({ children, label, menuActionHandler, menuBuilder, }: ContextMenuProviderProps) => JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const ArrowUp = "ArrowUp";
|
|
2
|
+
export declare const ArrowDown = "ArrowDown";
|
|
3
|
+
export declare const ArrowLeft = "ArrowLeft";
|
|
4
|
+
export declare const Backspace = "Backspace";
|
|
5
|
+
export declare const ArrowRight = "ArrowRight";
|
|
6
|
+
export declare const Enter = "Enter";
|
|
7
|
+
export declare const Escape = "Escape";
|
|
8
|
+
export declare const Delete = "Delete";
|
|
9
|
+
export declare const isCharacterKey: (evt: KeyboardEvent) => boolean | undefined;
|
|
10
|
+
export declare const isNavigationKey: ({ key }: {
|
|
11
|
+
key: string;
|
|
12
|
+
}, orientation?: string) => boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function listItemIndex(listItemEl: HTMLElement): number | undefined;
|
|
2
|
+
export declare const closestListItem: (el: HTMLElement | null | undefined) => HTMLElement;
|
|
3
|
+
export declare const closestListItemId: (el: HTMLElement) => string | undefined;
|
|
4
|
+
export declare const closestListItemIndex: (el: HTMLElement) => number | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MouseEvent } from "react";
|
|
2
|
+
import { MenuItemProps } from "./MenuList";
|
|
3
|
+
export type RuntimeMenuDescriptor = {
|
|
4
|
+
id: string;
|
|
5
|
+
left: number;
|
|
6
|
+
top: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const getHostMenuId: (id: string, rootId: string) => string;
|
|
9
|
+
export interface CascadeHookProps {
|
|
10
|
+
id: string;
|
|
11
|
+
onActivate: (menuId: string) => void;
|
|
12
|
+
onMouseEnterItem: (evt: MouseEvent, itemId: string) => void;
|
|
13
|
+
position: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface CascadeHooksResult {
|
|
19
|
+
closeMenu: () => void;
|
|
20
|
+
handleRender: () => void;
|
|
21
|
+
listItemProps: Partial<MenuItemProps>;
|
|
22
|
+
openMenu: (menuItemEl: HTMLElement) => void;
|
|
23
|
+
openMenus: RuntimeMenuDescriptor[];
|
|
24
|
+
}
|
|
25
|
+
export declare const useCascade: ({ id: rootId, onActivate, onMouseEnterItem, position: { x: posX, y: posY }, }: CascadeHookProps) => CascadeHooksResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
export declare const isMenuItemGroup: (child: ReactElement) => boolean;
|
|
3
|
+
type Menus = {
|
|
4
|
+
[key: string]: ReactElement[];
|
|
5
|
+
};
|
|
6
|
+
type Actions = {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
action: string;
|
|
9
|
+
options?: unknown;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const useItemsWithIdsNext: (childrenProp: ReactElement[], rootId: string) => [Menus, Actions];
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FocusEvent, KeyboardEvent } from "react";
|
|
2
|
+
export interface KeyboardNavigationProps {
|
|
3
|
+
autoHighlightFirstItem?: boolean;
|
|
4
|
+
count: number;
|
|
5
|
+
highlightedIndex?: number;
|
|
6
|
+
onActivate: (idx: number) => void;
|
|
7
|
+
onHighlight?: (idx: number) => void;
|
|
8
|
+
onCloseMenu: (idx: number) => void;
|
|
9
|
+
onOpenMenu?: (menuItemEl: HTMLElement) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface KeyboardHookListProps {
|
|
12
|
+
onFocus: (evt: FocusEvent) => void;
|
|
13
|
+
onKeyDown: (evt: KeyboardEvent) => void;
|
|
14
|
+
onMouseDownCapture: () => void;
|
|
15
|
+
onMouseMove: () => void;
|
|
16
|
+
onMouseLeave: () => void;
|
|
17
|
+
}
|
|
18
|
+
export interface NavigationHookResult {
|
|
19
|
+
focusVisible: number;
|
|
20
|
+
controlledHighlighting: boolean;
|
|
21
|
+
highlightedIndex: number;
|
|
22
|
+
setHighlightedIndex: (idx: number) => void;
|
|
23
|
+
listProps: KeyboardHookListProps;
|
|
24
|
+
setIgnoreFocus: (ignoreFocus: boolean) => void;
|
|
25
|
+
}
|
|
26
|
+
export declare const useKeyboardNavigation: ({ autoHighlightFirstItem, count, highlightedIndex: highlightedIndexProp, onActivate, onHighlight, onCloseMenu, onOpenMenu, }: KeyboardNavigationProps) => NavigationHookResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MouseEvent } from "react";
|
|
2
|
+
import { MenuActionHandler, MenuBuilder } from "@vuu-ui/vuu-data-types";
|
|
3
|
+
import { ContextMenuProps } from "./ContextMenu";
|
|
4
|
+
export type ContextMenuOptions = {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
contextMenu?: JSX.Element;
|
|
7
|
+
ContextMenuProps?: Partial<ContextMenuProps> & {
|
|
8
|
+
className?: string;
|
|
9
|
+
"data-mode"?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type ShowContextMenu = (e: MouseEvent<HTMLElement>, location: string, options: ContextMenuOptions) => void;
|
|
13
|
+
export declare const useContextMenu: (menuBuilder?: MenuBuilder, menuActionHandler?: MenuActionHandler) => [ShowContextMenu, () => void];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./popup-service";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { ContextMenuOptions } from "../menu";
|
|
3
|
+
import "./popup-service.css";
|
|
4
|
+
export type PopupCloseCallback = (reason?: PopupCloseReason) => void;
|
|
5
|
+
export type ClickAwayClosePopup = {
|
|
6
|
+
type: "click-away";
|
|
7
|
+
mouseEvt: MouseEvent;
|
|
8
|
+
};
|
|
9
|
+
export type MenuActionClosePopup = {
|
|
10
|
+
menuId: string;
|
|
11
|
+
options: ContextMenuOptions;
|
|
12
|
+
type: "menu-action";
|
|
13
|
+
};
|
|
14
|
+
export type PopupCloseReason = ClickAwayClosePopup | MenuActionClosePopup;
|
|
15
|
+
export declare const reasonIsMenuAction: (reason?: PopupCloseReason) => reason is MenuActionClosePopup;
|
|
16
|
+
export declare const reasonIsClickAway: (reason?: PopupCloseReason) => reason is ClickAwayClosePopup;
|
|
17
|
+
export interface ShowPopupProps {
|
|
18
|
+
depth?: number;
|
|
19
|
+
/**
|
|
20
|
+
* if true, focus will be invoked on first focusable element
|
|
21
|
+
*/
|
|
22
|
+
focus?: boolean;
|
|
23
|
+
name?: string;
|
|
24
|
+
group?: string;
|
|
25
|
+
position?: "above" | "below" | "";
|
|
26
|
+
left?: number;
|
|
27
|
+
right?: "auto" | number;
|
|
28
|
+
top?: number;
|
|
29
|
+
component: ReactElement;
|
|
30
|
+
width?: number | "auto";
|
|
31
|
+
}
|
|
32
|
+
export declare class PopupService {
|
|
33
|
+
static onClose: PopupCloseCallback | undefined;
|
|
34
|
+
static showPopup({ group, name, left, position, right, top, width, component, }: ShowPopupProps): void;
|
|
35
|
+
static escapeKeyListener(evt: KeyboardEvent): void;
|
|
36
|
+
static hidePopup(reason?: PopupCloseReason, name?: string, group?: string): void;
|
|
37
|
+
static keepWithinThePage(el: HTMLElement, right?: number | "auto"): void;
|
|
38
|
+
}
|
|
39
|
+
export declare class DialogService {
|
|
40
|
+
static showDialog(dialog: ReactElement): void;
|
|
41
|
+
static closeDialog(): void;
|
|
42
|
+
}
|
|
43
|
+
export interface PopupProps {
|
|
44
|
+
children: ReactElement;
|
|
45
|
+
close?: boolean;
|
|
46
|
+
depth: number;
|
|
47
|
+
group?: string;
|
|
48
|
+
name: string;
|
|
49
|
+
position?: "above" | "below" | "";
|
|
50
|
+
width: number;
|
|
51
|
+
}
|
|
52
|
+
export declare const Popup: (props: PopupProps) => React.DetailedReactHTMLElement<{
|
|
53
|
+
className: string;
|
|
54
|
+
ref: React.RefObject<HTMLElement>;
|
|
55
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
import "./PopupMenu.css";
|
|
3
|
+
import { MenuActionHandler, MenuBuilder } from "@vuu-ui/vuu-data-types";
|
|
4
|
+
export interface PopupMenuProps extends HTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
icon?: string;
|
|
6
|
+
menuActionHandler?: MenuActionHandler;
|
|
7
|
+
menuBuilder?: MenuBuilder;
|
|
8
|
+
menuLocation?: string;
|
|
9
|
+
menuOptions?: {
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
onMenuClose?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const PopupMenu: ({ className, icon, id: idProp, menuActionHandler, menuBuilder, menuLocation, menuOptions, onMenuClose, tabIndex, ...htmlAttributes }: PopupMenuProps) => JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PopupMenu";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const installTheme: (themeId: string) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
export interface HTMLContainerProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
dataMode?: string;
|
|
5
|
+
x?: number;
|
|
6
|
+
y?: number;
|
|
7
|
+
win?: typeof globalThis;
|
|
8
|
+
}
|
|
9
|
+
export declare const createContainer: (props: HTMLContainerProps) => HTMLDivElement;
|
|
10
|
+
export declare const renderPortal: (component: ReactElement, container: HTMLElement, x: number, y: number, onRender?: () => void) => void;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|