Skip to content

Commit baf1dd1

Browse files
committed
add tool config
1 parent 71b03fc commit baf1dd1

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script>
2-
let props = $props()
2+
let props = $props();
33
</script>
4+
45
<h1>toolbar</h1>
56
<pre>
6-
{JSON.stringify(props,null,2)}
7+
{JSON.stringify(props, null, 2)}
78
</pre>

packages/svelte/src/toolbar/configure.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
* toolbar config
33
* @type {import('./public.d.ts').Config}
44
*/
5-
const config = {};
5+
const config = {
6+
tools: []
7+
};
68

79
/**
810
* @param {Partial<import('./public.d.ts').Config>} options
911
*/
10-
export function configure(options){
11-
// TODO deep merge?
12-
for(const [key,value] of options){
13-
config[key]=value;
12+
export function configure(options) {
13+
for (const [key, value] of options) {
14+
if (key === 'tools') {
15+
for (const tool of /** @type {import('./public.d.ts').Tool[]}*/ value) {
16+
const existing = config.tools.find((t) => t.name === tool.name);
17+
if (existing) {
18+
for (const [k, v] of tool) {
19+
existing[k] = v;
20+
}
21+
} else {
22+
config.tools.push(tool);
23+
}
24+
}
25+
} else {
26+
config[key] = value;
27+
}
1428
}
1529
}
1630

1731
/**
1832
*
1933
* @return {import('./public.d.ts').Config}
2034
*/
21-
export function getConfig(){
35+
export function getConfig() {
2236
// TODO clone to avoid direct manipulation
2337
return config;
2438
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export {default as ToolBar} from './ToolBar.svelte'
2-
export * from './configure.js'
3-
export {mountUI as default} from './runtime.js'
1+
export { default as ToolBar } from './ToolBar.svelte';
2+
export * from './configure.js';
3+
export { mountUI as default } from './runtime.js';
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
export * from './index.js'
1+
export * from './index.js';
22

3+
export interface Tool {
4+
name: string;
5+
icon: string; // url or svg
6+
activate();
7+
deactivate();
8+
keyCombo?: string;
9+
disabled?: boolean;
10+
}
311
export interface Config {
4-
position: 'top'|'bottom'
12+
position?: 'top' | 'bottom';
13+
tools?: Tool[];
514
}

packages/svelte/src/toolbar/runtime.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ function create_toolbar_host() {
1212
document.documentElement.appendChild(el);
1313
return el;
1414
}
15-
export function mountUI(){
16-
if(typeof window !== 'undefined') {
15+
export function mountUI() {
16+
if (typeof window !== 'undefined') {
1717
mount(ToolBar, { target: create_toolbar_host() });
1818
}
1919
}
20-
21-

0 commit comments

Comments
 (0)