Skip to content

Commit d330a30

Browse files
committed
allow Tool to be function
1 parent baf1dd1 commit d330a30

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/svelte/src/toolbar/configure.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const config = {
1212
export function configure(options) {
1313
for (const [key, value] of options) {
1414
if (key === 'tools') {
15-
for (const tool of /** @type {import('./public.d.ts').Tool[]}*/ value) {
15+
for (let tool of /** @type {import('./public.d.ts').Config.tools[0][]}*/ value) {
16+
if(typeof tool === 'function') {
17+
tool = tool();
18+
}
1619
const existing = config.tools.find((t) => t.name === tool.name);
1720
if (existing) {
1821
for (const [k, v] of tool) {

packages/svelte/src/toolbar/public.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export interface Tool {
88
keyCombo?: string;
99
disabled?: boolean;
1010
}
11+
type ToolFn = ()=>Tool
12+
1113
export interface Config {
1214
position?: 'top' | 'bottom';
13-
tools?: Tool[];
15+
tools?: (Tool | ToolFn)[];
1416
}

0 commit comments

Comments
 (0)