File tree Expand file tree Collapse file tree 5 files changed +39
-17
lines changed
packages/svelte/src/toolbar Expand file tree Collapse file tree 5 files changed +39
-17
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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' ;
Original file line number Diff line number Diff line change 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+ }
311export interface Config {
4- position : 'top' | 'bottom'
12+ position ?: 'top' | 'bottom' ;
13+ tools ?: Tool [ ] ;
514}
Original file line number Diff line number Diff 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-
You can’t perform that action at this time.
0 commit comments