This commit is contained in:
Insality
2025-10-27 01:49:16 +02:00
parent f3f19337a3
commit 1601d6d56e
4 changed files with 99 additions and 52 deletions

View File

@@ -28,18 +28,6 @@ local function handle_install(item, install_folder, on_success, on_error)
end
---Handle opening API documentation
---@param item table - Widget item
local function handle_open_api(item)
if item.api then
print("Opening API documentation:", item.api)
editor.browse(item.api)
else
print("No API documentation available for:", item.id)
end
end
---Show installation status dialog
---@param success boolean - Whether installation was successful
---@param message string - Status message
@@ -71,6 +59,7 @@ local function show_install_status(success, message)
end
---Open the asset store dialog
function M.open_asset_store(store_url)
print("Opening Druid Asset Store from:", store_url)
@@ -86,16 +75,12 @@ function M.open_asset_store(store_url)
local initial_items = store_data.items
local dialog_component = editor.ui.component(function(props)
-- State management
local items, set_items = editor.ui.use_state(initial_items)
local install_folder, set_install_folder = editor.ui.use_state(editor.prefs.get("druid.asset_install_folder") or installer.get_default_install_folder())
local all_items = editor.ui.use_state(initial_items)
local filtered_items, set_filtered_items = editor.ui.use_state(initial_items)
local install_folder, set_install_folder = editor.ui.use_state(installer.get_install_folder())
local search_query, set_search_query = editor.ui.use_state("")
local install_status, set_install_status = editor.ui.use_state("")
-- Installation status check function
local function is_widget_installed(item)
return installer.is_widget_installed(item, install_folder)
end
-- Installation handlers
local function on_install(item)
handle_install(item, install_folder,
@@ -110,10 +95,6 @@ function M.open_asset_store(store_url)
)
end
local function on_open_api(item)
handle_open_api(item)
end
-- Build UI content
local content_children = {}
@@ -146,7 +127,10 @@ function M.open_asset_store(store_url)
}),
editor.ui.string_field({
value = search_query,
on_value_changed = set_search_query,
on_value_changed = function(new_query)
set_search_query(new_query)
set_filtered_items(internal.filter_items(all_items, new_query))
end,
title = "Search:",
tooltip = "Search for widgets by title, author, or description",
})
@@ -154,16 +138,17 @@ function M.open_asset_store(store_url)
}))
-- Main content area
if #items == 0 then
if #filtered_items == 0 then
local message = search_query ~= "" and
"No widgets found matching '" .. search_query .. "'." or
"No widgets found matching the current filters."
table.insert(content_children, editor.ui.label({
text = "No widgets found matching the current filters.",
text = message,
color = editor.ui.COLOR.HINT,
alignment = editor.ui.ALIGNMENT.CENTER
}))
else
table.insert(content_children, ui_components.create_widget_list(
items, is_widget_installed, on_install, on_open_api
))
table.insert(content_children, ui_components.create_widget_list(filtered_items, on_install))
end
-- Install status message

View File

@@ -18,4 +18,67 @@ function M.download_json(json_url)
end
---Filter items based on search query
---Filter items based on search query
---@param items table - List of widget items
---@param query string - Search query
---@return table - Filtered items
function M.filter_items(items, query)
if query == "" then
return items
end
local filtered = {}
local lower_query = string.lower(query)
for _, item in ipairs(items) do
-- Search in title, author, description
local matches = false
if item.title and string.find(string.lower(item.title), lower_query, 1, true) then
matches = true
elseif item.author and string.find(string.lower(item.author), lower_query, 1, true) then
matches = true
elseif item.description and string.find(string.lower(item.description), lower_query, 1, true) then
matches = true
end
-- Search in tags
if not matches and item.tags then
for _, tag in ipairs(item.tags) do
if string.find(string.lower(tag), lower_query, 1, true) then
matches = true
break
end
end
end
-- Search in dependencies
if not matches and item.depends then
for _, dep in ipairs(item.depends) do
if string.find(string.lower(dep), lower_query, 1, true) then
matches = true
break
end
end
end
if matches then
table.insert(filtered, item)
end
end
return filtered
end
---Open a URL in the default browser
---@param url string - The URL to open
function M.open_url(url)
if not url then
print("No URL available for:", url)
end
editor.browse(url)
end
return M

View File

@@ -100,10 +100,10 @@ function M.is_widget_installed(item, install_folder)
end
---Get default installation folder
---@return string - Default installation folder path
function M.get_default_install_folder()
return DEFAULT_INSTALL_FOLDER
---Get installation folder
---@return string - Installation folder path
function M.get_install_folder()
return editor.prefs.get("druid.asset_install_folder") or DEFAULT_INSTALL_FOLDER
end

View File

@@ -1,6 +1,9 @@
--- Module for reusable UI components in the asset store
--- Contains component builders for filters, widget items, and lists
local internal = require("druid.editor_scripts.core.asset_store_internal")
local installer = require("druid.editor_scripts.core.installer")
local M = {}
@@ -143,9 +146,8 @@ end
---@param item table - Widget item data
---@param is_installed boolean - Whether widget is already installed
---@param on_install function - Callback for install button
---@param on_open_api function - Callback for API docs button
---@return userdata - UI component
function M.create_widget_item(item, is_installed, on_install, on_open_api)
function M.create_widget_item(item, is_installed, on_install)
local size_text = item.size and format_size(item.size) or "Unknown size"
local version_text = item.version and "v" .. item.version or "Unknown version"
@@ -158,7 +160,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
-- Create dependencies display
local deps_text = ""
if item.depends and #item.depends > 0 then
deps_text = "Depends on: " .. table.concat(item.depends, ", ")
deps_text = "Depends: " .. table.concat(item.depends, ", ")
end
return editor.ui.horizontal({
@@ -185,14 +187,14 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
children = {
editor.ui.label({
text = item.title or item.id,
color = editor.ui.COLOR.TEXT
color = editor.ui.COLOR.OVERRIDE
}),
editor.ui.label({
text = version_text .. "",
color = editor.ui.COLOR.HINT
text = version_text,
color = editor.ui.COLOR.WARNING
}),
editor.ui.label({
text = "by " .. (item.author or "Unknown"),
text = "by " .. (item.author or "Unknown"),
color = editor.ui.COLOR.HINT
}),
editor.ui.label({
@@ -217,7 +219,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
-- Dependencies
deps_text ~= "" and editor.ui.label({
text = deps_text,
color = editor.ui.COLOR.WARNING
color = editor.ui.COLOR.HINT
}) or nil,
-- Installation status
@@ -240,7 +242,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
}),
editor.ui.button({
text = "API",
on_pressed = on_open_api,
on_pressed = function() internal.open_url(item.api) end,
enabled = item.api ~= nil
})
}
@@ -252,20 +254,17 @@ end
---Create a scrollable list of widget items
---@param items table - List of widget items to display
---@param is_installed_func function - Function to check if widget is installed
---@param on_install function - Callback for install button
---@param on_open_api function - Callback for API docs button
---@return userdata - UI component
function M.create_widget_list(items, is_installed_func, on_install, on_open_api)
function M.create_widget_list(items, on_install)
local widget_items = {}
local install_folder = installer.get_install_folder()
for index = 1, 9 do
for _, item in ipairs(items) do
local is_installed = is_installed_func and is_installed_func(item) or false
local is_installed = installer.is_widget_installed(item, install_folder)
table.insert(widget_items, M.create_widget_item(item, is_installed,
function() on_install(item) end,
function() on_open_api(item) end
function() on_install(item) end
))
end
end