Files
feuerwerk/plugins/demo-plugin.js
T
2026-09-17 19:00:03 +02:00

30 lines
882 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Demo plugin (#113): a tab "Assets" that shows every asset of the project as a node, laid out in
* a grid in the order of the asset list. It follows the project: adding, renaming or deleting an
* asset redraws the board.
*
* A plugin imports nothing – everything it needs comes in through `api`.
*/
export const meta = { id: 'demo', name: 'Demo plugin', version: '1.0.0', api: 1 };
const COLUMNS = 4;
const CELL_W = 220;
const CELL_H = 64;
export function activate(api) {
const board = new api.ui.NodeBoard();
const show = () =>
board.setNodes(
api.project.assets().map((asset, i) => ({
id: asset.id,
title: asset.name,
x: (i % COLUMNS) * CELL_W,
y: Math.floor(i / COLUMNS) * CELL_H,
})),
);
show();
api.project.on('change', show);
api.tabs.add({ id: 'assets', label: 'Assets', create: () => board });
}