mirror of
https://github.com/Insality/druid.git
synced 2025-11-26 10:50:52 +01:00
Update
This commit is contained in:
@@ -28,18 +28,6 @@ local function handle_install(item, install_folder, on_success, on_error)
|
|||||||
end
|
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
|
---Show installation status dialog
|
||||||
---@param success boolean - Whether installation was successful
|
---@param success boolean - Whether installation was successful
|
||||||
---@param message string - Status message
|
---@param message string - Status message
|
||||||
@@ -71,6 +59,7 @@ local function show_install_status(success, message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---Open the asset store dialog
|
---Open the asset store dialog
|
||||||
function M.open_asset_store(store_url)
|
function M.open_asset_store(store_url)
|
||||||
print("Opening Druid Asset Store from:", 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 initial_items = store_data.items
|
||||||
local dialog_component = editor.ui.component(function(props)
|
local dialog_component = editor.ui.component(function(props)
|
||||||
-- State management
|
-- State management
|
||||||
local items, set_items = editor.ui.use_state(initial_items)
|
local all_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 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 search_query, set_search_query = editor.ui.use_state("")
|
||||||
local install_status, set_install_status = 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
|
-- Installation handlers
|
||||||
local function on_install(item)
|
local function on_install(item)
|
||||||
handle_install(item, install_folder,
|
handle_install(item, install_folder,
|
||||||
@@ -110,10 +95,6 @@ function M.open_asset_store(store_url)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_open_api(item)
|
|
||||||
handle_open_api(item)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Build UI content
|
-- Build UI content
|
||||||
local content_children = {}
|
local content_children = {}
|
||||||
|
|
||||||
@@ -146,7 +127,10 @@ function M.open_asset_store(store_url)
|
|||||||
}),
|
}),
|
||||||
editor.ui.string_field({
|
editor.ui.string_field({
|
||||||
value = search_query,
|
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:",
|
title = "Search:",
|
||||||
tooltip = "Search for widgets by title, author, or description",
|
tooltip = "Search for widgets by title, author, or description",
|
||||||
})
|
})
|
||||||
@@ -154,16 +138,17 @@ function M.open_asset_store(store_url)
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
-- Main content area
|
-- 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({
|
table.insert(content_children, editor.ui.label({
|
||||||
text = "No widgets found matching the current filters.",
|
text = message,
|
||||||
color = editor.ui.COLOR.HINT,
|
color = editor.ui.COLOR.HINT,
|
||||||
alignment = editor.ui.ALIGNMENT.CENTER
|
alignment = editor.ui.ALIGNMENT.CENTER
|
||||||
}))
|
}))
|
||||||
else
|
else
|
||||||
table.insert(content_children, ui_components.create_widget_list(
|
table.insert(content_children, ui_components.create_widget_list(filtered_items, on_install))
|
||||||
items, is_widget_installed, on_install, on_open_api
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Install status message
|
-- Install status message
|
||||||
|
|||||||
@@ -18,4 +18,67 @@ function M.download_json(json_url)
|
|||||||
end
|
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
|
return M
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ function M.is_widget_installed(item, install_folder)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---Get default installation folder
|
---Get installation folder
|
||||||
---@return string - Default installation folder path
|
---@return string - Installation folder path
|
||||||
function M.get_default_install_folder()
|
function M.get_install_folder()
|
||||||
return DEFAULT_INSTALL_FOLDER
|
return editor.prefs.get("druid.asset_install_folder") or DEFAULT_INSTALL_FOLDER
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
--- Module for reusable UI components in the asset store
|
--- Module for reusable UI components in the asset store
|
||||||
--- Contains component builders for filters, widget items, and lists
|
--- 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 = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,9 +146,8 @@ end
|
|||||||
---@param item table - Widget item data
|
---@param item table - Widget item data
|
||||||
---@param is_installed boolean - Whether widget is already installed
|
---@param is_installed boolean - Whether widget is already installed
|
||||||
---@param on_install function - Callback for install button
|
---@param on_install function - Callback for install button
|
||||||
---@param on_open_api function - Callback for API docs button
|
|
||||||
---@return userdata - UI component
|
---@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 size_text = item.size and format_size(item.size) or "Unknown size"
|
||||||
local version_text = item.version and "v" .. item.version or "Unknown version"
|
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
|
-- Create dependencies display
|
||||||
local deps_text = ""
|
local deps_text = ""
|
||||||
if item.depends and #item.depends > 0 then
|
if item.depends and #item.depends > 0 then
|
||||||
deps_text = "Depends on: " .. table.concat(item.depends, ", ")
|
deps_text = "Depends: " .. table.concat(item.depends, ", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
return editor.ui.horizontal({
|
return editor.ui.horizontal({
|
||||||
@@ -185,18 +187,18 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
|
|||||||
children = {
|
children = {
|
||||||
editor.ui.label({
|
editor.ui.label({
|
||||||
text = item.title or item.id,
|
text = item.title or item.id,
|
||||||
color = editor.ui.COLOR.TEXT
|
color = editor.ui.COLOR.OVERRIDE
|
||||||
}),
|
}),
|
||||||
editor.ui.label({
|
editor.ui.label({
|
||||||
text = version_text .. " • ",
|
text = version_text,
|
||||||
|
color = editor.ui.COLOR.WARNING
|
||||||
|
}),
|
||||||
|
editor.ui.label({
|
||||||
|
text = "• by " .. (item.author or "Unknown"),
|
||||||
color = editor.ui.COLOR.HINT
|
color = editor.ui.COLOR.HINT
|
||||||
}),
|
}),
|
||||||
editor.ui.label({
|
editor.ui.label({
|
||||||
text = "by " .. (item.author or "Unknown"),
|
text = "• " .. size_text,
|
||||||
color = editor.ui.COLOR.HINT
|
|
||||||
}),
|
|
||||||
editor.ui.label({
|
|
||||||
text = " • " .. size_text,
|
|
||||||
color = editor.ui.COLOR.HINT
|
color = editor.ui.COLOR.HINT
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -217,7 +219,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
|
|||||||
-- Dependencies
|
-- Dependencies
|
||||||
deps_text ~= "" and editor.ui.label({
|
deps_text ~= "" and editor.ui.label({
|
||||||
text = deps_text,
|
text = deps_text,
|
||||||
color = editor.ui.COLOR.WARNING
|
color = editor.ui.COLOR.HINT
|
||||||
}) or nil,
|
}) or nil,
|
||||||
|
|
||||||
-- Installation status
|
-- Installation status
|
||||||
@@ -240,7 +242,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
|
|||||||
}),
|
}),
|
||||||
editor.ui.button({
|
editor.ui.button({
|
||||||
text = "API",
|
text = "API",
|
||||||
on_pressed = on_open_api,
|
on_pressed = function() internal.open_url(item.api) end,
|
||||||
enabled = item.api ~= nil
|
enabled = item.api ~= nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -252,20 +254,17 @@ end
|
|||||||
|
|
||||||
---Create a scrollable list of widget items
|
---Create a scrollable list of widget items
|
||||||
---@param items table - List of widget items to display
|
---@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_install function - Callback for install button
|
||||||
---@param on_open_api function - Callback for API docs button
|
|
||||||
---@return userdata - UI component
|
---@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 widget_items = {}
|
||||||
|
local install_folder = installer.get_install_folder()
|
||||||
|
|
||||||
for index = 1, 9 do
|
for index = 1, 9 do
|
||||||
for _, item in ipairs(items) 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,
|
table.insert(widget_items, M.create_widget_item(item, is_installed,
|
||||||
function() on_install(item) end,
|
function() on_install(item) end
|
||||||
function() on_open_api(item) end
|
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user