add tool config

feat/devtool
dominikg 4 months ago
parent 71b03fc1c5
commit baf1dd1e7f

@ -1,7 +1,8 @@
<script>
let props = $props()
let props = $props();
</script>
<h1>toolbar</h1>
<pre>
{JSON.stringify(props,null,2)}
{JSON.stringify(props, null, 2)}
</pre>

@ -2,15 +2,29 @@
* toolbar config
* @type {import('./public.d.ts').Config}
*/
const config = {};
const config = {
tools: []
};
/**
* @param {Partial<import('./public.d.ts').Config>} options
*/
export function configure(options){
// TODO deep merge?
for(const [key,value] of options){
config[key]=value;
export function configure(options) {
for (const [key, value] of options) {
if (key === 'tools') {
for (const tool of /** @type {import('./public.d.ts').Tool[]}*/ value) {
const existing = config.tools.find((t) => t.name === tool.name);
if (existing) {
for (const [k, v] of tool) {
existing[k] = v;
}
} else {
config.tools.push(tool);
}
}
} else {
config[key] = value;
}
}
}
@ -18,7 +32,7 @@ export function configure(options){
*
* @return {import('./public.d.ts').Config}
*/
export function getConfig(){
export function getConfig() {
// TODO clone to avoid direct manipulation
return config;
}

@ -1,3 +1,3 @@
export {default as ToolBar} from './ToolBar.svelte'
export * from './configure.js'
export {mountUI as default} from './runtime.js'
export { default as ToolBar } from './ToolBar.svelte';
export * from './configure.js';
export { mountUI as default } from './runtime.js';

@ -1,5 +1,14 @@
export * from './index.js'
export * from './index.js';
export interface Tool {
name: string;
icon: string; // url or svg
activate();
deactivate();
keyCombo?: string;
disabled?: boolean;
}
export interface Config {
position: 'top'|'bottom'
position?: 'top' | 'bottom';
tools?: Tool[];
}

@ -12,10 +12,8 @@ function create_toolbar_host() {
document.documentElement.appendChild(el);
return el;
}
export function mountUI(){
if(typeof window !== 'undefined') {
export function mountUI() {
if (typeof window !== 'undefined') {
mount(ToolBar, { target: create_toolbar_host() });
}
}

Loading…
Cancel
Save