Revert "feat(web/context): mouse enter and mouse leave events (#218)"

This reverts commit 7a22da68e6.
This commit is contained in:
masonschafercodes
2023-02-08 04:05:30 -05:00
committed by Luke
parent c9c90efaf8
commit 7acad823b8
3 changed files with 23 additions and 64 deletions

View File

@@ -1,5 +1,4 @@
local contextMenus = {}
local lastHoveredContextItem = nil
local openContextMenu = nil
local keepInput = IsNuiFocusKeepingInput()
@@ -9,7 +8,6 @@ local keepInput = IsNuiFocusKeepingInput()
---@field icon? string
---@field iconColor? string
---@field onSelect? fun(args: any)
---@field onHover? fun(hoverState: boolean, args: any)
---@field arrow? boolean
---@field description? string
---@field metadata? string | { [string]: any } | string[]
@@ -43,25 +41,9 @@ local function closeContext(_, cb, onExit)
if not cb then SendNUIMessage({ action = 'hideContext' }) end
if lastHoveredContextItem then
local data = contextMenus[openContextMenu].options[lastHoveredContextItem]
if data.onHover then data.onHover(false, data.args) end
lastHoveredContextItem = nil
end
openContextMenu = nil
end
local function checkID(id)
if math.type(tonumber(id)) == 'float' then
id = math.tointeger(id)
elseif tonumber(id) then
id += 1
end
return id
end
---@param id string
function lib.showContext(id)
if not contextMenus[id] then error('No context menu of such id found.') end
@@ -107,11 +89,14 @@ RegisterNUICallback('openContext', function(data, cb)
lib.showContext(data.id)
end)
RegisterNUICallback('clickContext', function(id, cb)
cb(1)
local id = checkID(id)
if math.type(tonumber(id)) == 'float' then
id = math.tointeger(id)
elseif tonumber(id) then
id += 1
end
local data = contextMenus[openContextMenu].options[id]
@@ -125,35 +110,12 @@ RegisterNUICallback('clickContext', function(id, cb)
if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
if lastHoveredContextItem then
local data = contextMenus[openContextMenu].options[lastHoveredContextItem]
if data.onHover then data.onHover(false, data.args) end
lastHoveredContextItem = nil
end
SendNUIMessage({
action = 'hideContext'
})
end)
RegisterNUICallback('onHover', function(data, cb)
cb(1)
local id = checkID(data.id)
local hoverState = data.hoverState
local data = contextMenus[openContextMenu].options[id]
if not data.onHover then return end
if data.onHover and hoverState == true then
lastHoveredContextItem = id
data.onHover(true, data.args)
end
if data.onHover and hoverState == false then
lastHoveredContextItem = nil
data.onHover(false, data.args)
end
end)
RegisterNUICallback('closeContext', closeContext)