- Declare inspection or modification access on every canonical tool definition - Add bulk category controls while preserving individual disabled-tool storage - Keep runtime availability separate from document access semantics
30 lines
894 B
TypeScript
30 lines
894 B
TypeScript
import type { FigmaNodeProxy } from '#core/figma-api'
|
|
import { defineTool, nodeToResult } from '#core/tools/schema'
|
|
|
|
export const getSelection = defineTool({
|
|
name: 'get_selection',
|
|
documentAccess: 'inspect',
|
|
description: 'Get details about currently selected nodes.',
|
|
params: {},
|
|
execute: (figma) => {
|
|
const selection = figma.currentPage.selection
|
|
return { selection: selection.map(nodeToResult) }
|
|
}
|
|
})
|
|
|
|
export const selectNodes = defineTool({
|
|
name: 'select_nodes',
|
|
mutates: true,
|
|
documentAccess: 'inspect',
|
|
description: 'Select one or more nodes by ID.',
|
|
params: {
|
|
ids: { type: 'string[]', description: 'Node IDs to select', required: true }
|
|
},
|
|
execute: (figma, { ids }) => {
|
|
figma.currentPage.selection = ids
|
|
.map((id) => figma.getNodeById(id))
|
|
.filter((node): node is FigmaNodeProxy => node !== null)
|
|
return { selected: ids }
|
|
}
|
|
})
|