app.registerExtension({
name: "SelectionTools",
commands: [
{
id: "selection-tools.count",
label: "Count Selection",
icon: "pi pi-hashtag",
function: () => {
const count = app.canvas.selectedItems?.size || 0;
app.extensionManager.toast.add({
severity: "info",
summary: "Selection Count",
detail: `You have ${count} item${count !== 1 ? 's' : ''} selected`,
life: 3000
});
}
},
{
id: "selection-tools.copy-ids",
label: "Copy IDs",
icon: "pi pi-copy",
function: () => {
const items = Array.from(app.canvas.selectedItems || []);
const ids = items.map(item => item.id).filter(id => id !== undefined);
if (ids.length > 0) {
navigator.clipboard.writeText(ids.join(', '));
app.extensionManager.toast.add({
severity: "success",
summary: "Copied",
detail: `Copied ${ids.length} IDs to clipboard`,
life: 2000
});
}
}
},
{
id: "selection-tools.log-types",
label: "Log Types",
icon: "pi pi-info-circle",
function: () => {
const items = Array.from(app.canvas.selectedItems || []);
const typeCount = {};
items.forEach(item => {
const type = item.type || 'unknown';
typeCount[type] = (typeCount[type] || 0) + 1;
});
console.log("Selection types:", typeCount);
}
}
],
getSelectionToolboxCommands: (selectedItem) => {
const selectedItems = app.canvas.selectedItems;
const itemCount = selectedItems ? selectedItems.size : 0;
if (itemCount === 0) return [];
const commands = ["selection-tools.count", "selection-tools.log-types"];
// Only show copy command if items have IDs
const hasIds = Array.from(selectedItems).some(item => item.id !== undefined);
if (hasIds) {
commands.push("selection-tools.copy-ids");
}
return commands;
}
});