add initial toolbar draft

feat/devtool
Manuel Serret 4 months ago
parent 9d2f7550bd
commit 620ba56f05

@ -146,6 +146,7 @@
},
"devDependencies": {
"@jridgewell/trace-mapping": "^0.3.25",
"@neodrag/svelte": "^2.3.2",
"@playwright/test": "^1.46.1",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
@ -164,9 +165,9 @@
"dependencies": {
"@ampproject/remapping": "^2.3.0",
"@jridgewell/sourcemap-codec": "^1.5.0",
"@sveltejs/acorn-typescript": "^1.0.5",
"@types/estree": "^1.0.5",
"acorn": "^8.12.1",
"@sveltejs/acorn-typescript": "^1.0.5",
"aria-query": "^5.3.1",
"axobject-query": "^4.1.0",
"clsx": "^2.1.1",

@ -0,0 +1,10 @@
<!-- Grabbed from https://github.com/sveltejs/branding/blob/master/svelte-logo.svg -->
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"
><title>svelte-logo</title><path
d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157"
style="fill:#ff3e00"
/><path
d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287"
style="fill:#fff"
/></svg
>

After

Width:  |  Height:  |  Size: 1.9 KiB

@ -1,8 +1,100 @@
<script>
let props = $props();
import { draggable } from '@neodrag/svelte';
import Icon from './Icon.svelte';
import { configure, getConfig } from 'svelte/toolbar';
let open = $state(true); // todo change this to false
configure({
tools: [
{ name: 'state' },
{
name: 'inspector',
activate: () => {
console.log('inspector activated');
}
},
{ name: 'a11y' },
{ name: 'config' }
]
});
let config = getConfig();
/** @type {string[]} */
let active_tool_names = $state([]);
/**
* @param {import('./public').Tool} tool
*/
function toggle_tool(tool) {
const active = active_tool_names.includes(tool.name);
if (!active) {
active_tool_names.push(tool.name);
tool.activate();
} else {
active_tool_names.splice(active_tool_names.indexOf(tool.name), 1);
tool.deactivate();
}
console.log(active_tool_names);
}
</script>
<h1>toolbar</h1>
<pre>
{JSON.stringify(props, null, 2)}
</pre>
<div class="toolbar" use:draggable={{ bounds: document.body }}>
{#if open}
<ul class="tools">
{#each config.tools as tool}
<li class:active={active_tool_names.includes(tool.name)}>
<button onclick={() => toggle_tool(tool)}>{tool.name}</button>
</li>
{/each}
</ul>
{/if}
<button type="button" class="toolbar-selector" onclick={() => (open = !open)}>
<Icon />
</button>
</div>
<style>
.toolbar-selector {
cursor: pointer;
}
.toolbar-selector :global(svg) {
width: 50px;
height: 50px;
}
.tools {
background-color: #666; /* TODO: consider dark / light mode */
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: center;
}
.tools li {
display: inline-block;
background-color: #444;
border: #111 1px solid;
border-radius: 50%;
margin: 0 10px;
padding: 10px;
height: 30px;
}
.tools li.active {
border-color: #ff3e00;
}
.toolbar {
display: inline-flex;
color: white;
position: static;
}
.toolbar > * {
/* display: inline-block; */
}
</style>

@ -12,7 +12,7 @@ const config = {
export function configure(options) {
for (const [key, value] of Object.entries(options)) {
if (key === 'tools') {
continue
continue;
} else {
// @ts-expect-error index access
config[key] = value;
@ -37,7 +37,7 @@ export function configure(options) {
/**
*
* @return {import('./public.d.ts').Config}
* @return {import('./public.d.ts').ResolvedConfig}
*/
export function getConfig() {
// TODO clone to avoid direct manipulation

@ -8,7 +8,7 @@ export interface Tool {
keyCombo?: string;
disabled?: boolean;
}
type ToolFn = ()=>Tool
type ToolFn = () => Tool;
export interface Config {
position?: 'top' | 'bottom';
@ -16,5 +16,5 @@ export interface Config {
}
export interface ResolvedConfig extends Config {
tools: Tool[]
tools: Tool[];
}

@ -2557,7 +2557,7 @@ declare module 'svelte/toolbar' {
keyCombo?: string;
disabled?: boolean;
}
type ToolFn = ()=>Tool
type ToolFn = () => Tool;
export interface Config {
position?: 'top' | 'bottom';
@ -2569,7 +2569,7 @@ declare module 'svelte/toolbar' {
}
export function configure(options: Partial<Config>): void;
export function getConfig(): Config;
export function getConfig(): ResolvedConfig;
export function mountUI(): void;
export {};

@ -105,6 +105,9 @@ importers:
'@jridgewell/trace-mapping':
specifier: ^0.3.25
version: 0.3.25
'@neodrag/svelte':
specifier: ^2.3.2
version: 2.3.2(svelte@5.28.2)
'@playwright/test':
specifier: ^1.46.1
version: 1.46.1
@ -477,6 +480,11 @@ packages:
'@manypkg/get-packages@1.1.3':
resolution: {integrity: sha512-fo+QhuU3qE/2TQMQmbVMqaQ6EWbMhi4ABWP+O4AM1NqPBuy0OrApV5LO6BrrgnhtAHS2NH6RrVk9OL181tTi8A==}
'@neodrag/svelte@2.3.2':
resolution: {integrity: sha512-1aPgnv2LqikkPEoTVgCPCqtXUXOD7OjCHLAIssTv0hkmyHLG9i697Cu+Tzco4/Q4KgOQXCDnLsa4Fvya5wXP9g==}
peerDependencies:
svelte: ^3.0.0 || ^4.0.0 || ^5.0.0
'@nodelib/fs.scandir@2.1.5':
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
engines: {node: '>= 8'}
@ -2121,6 +2129,10 @@ packages:
svelte:
optional: true
svelte@5.28.2:
resolution: {integrity: sha512-FbWBxgWOpQfhKvoGJv/TFwzqb4EhJbwCD17dB0tEpQiw1XyUEKZJtgm4nA4xq3LLsMo7hu5UY/BOFmroAxKTMg==}
engines: {node: '>=18'}
symbol-tree@3.2.4:
resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==}
@ -2797,6 +2809,10 @@ snapshots:
globby: 11.1.0
read-yaml-file: 1.1.0
'@neodrag/svelte@2.3.2(svelte@5.28.2)':
dependencies:
svelte: 5.28.2
'@nodelib/fs.scandir@2.1.5':
dependencies:
'@nodelib/fs.stat': 2.0.5
@ -2989,6 +3005,10 @@ snapshots:
dependencies:
acorn: 8.14.0
'@sveltejs/acorn-typescript@1.0.5(acorn@8.14.1)':
dependencies:
acorn: 8.14.1
'@sveltejs/eslint-config@8.1.0(@stylistic/eslint-plugin-js@1.8.0(eslint@9.9.1))(eslint-config-prettier@9.1.0(eslint@9.9.1))(eslint-plugin-n@17.16.1(eslint@9.9.1)(typescript@5.5.4))(eslint-plugin-svelte@2.38.0(eslint@9.9.1)(svelte@packages+svelte))(eslint@9.9.1)(typescript-eslint@8.26.0(eslint@9.9.1)(typescript@5.5.4))(typescript@5.5.4)':
dependencies:
'@stylistic/eslint-plugin-js': 1.8.0(eslint@9.9.1)
@ -4441,6 +4461,23 @@ snapshots:
optionalDependencies:
svelte: link:packages/svelte
svelte@5.28.2:
dependencies:
'@ampproject/remapping': 2.3.0
'@jridgewell/sourcemap-codec': 1.5.0
'@sveltejs/acorn-typescript': 1.0.5(acorn@8.14.1)
'@types/estree': 1.0.7
acorn: 8.14.1
aria-query: 5.3.1
axobject-query: 4.1.0
clsx: 2.1.1
esm-env: 1.2.1
esrap: 1.4.6
is-reference: 3.0.3
locate-character: 3.0.0
magic-string: 0.30.17
zimmerframe: 1.1.2
symbol-tree@3.2.4: {}
tapable@2.2.1: {}

Loading…
Cancel
Save