Skip to content

feat: extension design overhaul #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f24cdac
prepare svelte-kit project
ignatiusmb Aug 28, 2023
d74971f
move out of dest
ignatiusmb Aug 28, 2023
cc60b22
move to lib + ts-ify
ignatiusmb Aug 28, 2023
fe03a29
generate icons to build
ignatiusmb Aug 28, 2023
18624de
manifest v3
ignatiusmb Aug 28, 2023
14d625c
update svelte-check script
ignatiusmb Aug 28, 2023
47f948c
merge master -> svelte-kit
ignatiusmb Aug 28, 2023
4244f12
reinstate dependencies
ignatiusmb Aug 28, 2023
0e68c2c
remove rollup
ignatiusmb Aug 28, 2023
a53e304
include code files in static folder
ignatiusmb Aug 28, 2023
9bbe954
checkjs
ignatiusmb Aug 28, 2023
a01f351
simplify background.js
ignatiusmb Aug 29, 2023
a1c07a0
lint
ignatiusmb Aug 29, 2023
8354c31
merge master -> svelte-kit
ignatiusmb Aug 29, 2023
dcea416
styling + use css vars
ignatiusmb Aug 29, 2023
17dd991
move to ts file
ignatiusmb Aug 29, 2023
df391d4
compile scripts
ignatiusmb Aug 31, 2023
4154a12
spa mode
ignatiusmb Aug 31, 2023
d746317
integrate svelte-listener
ignatiusmb Aug 31, 2023
1189b55
commit dev component
ignatiusmb Aug 31, 2023
fa2d21f
adjust resources path
ignatiusmb Aug 31, 2023
2aa42e1
draft it up
ignatiusmb Aug 31, 2023
d4262a7
ignore generated
ignatiusmb Aug 31, 2023
134cf48
simplify runtime
ignatiusmb Sep 4, 2023
3f0dd4b
Merge branch 'master' of https://github.com/sveltejs/svelte-devtools …
ignatiusmb Sep 4, 2023
ff72f62
rename injected script
ignatiusmb Sep 5, 2023
fb7d058
strongly type dispatched dev events
ignatiusmb Sep 6, 2023
a724af2
add register component and block event
ignatiusmb Sep 6, 2023
db135d5
cleanup
ignatiusmb Sep 6, 2023
2edbda8
move stuff around
ignatiusmb Sep 6, 2023
914eca2
workaround file watching
ignatiusmb Sep 6, 2023
a7bf12d
overhaul listener
ignatiusmb Sep 7, 2023
bb88d4a
rename page to panel
ignatiusmb Sep 7, 2023
f1c6755
move to just vite
ignatiusmb Sep 7, 2023
8d3a9b0
finally starting some styling
ignatiusmb Sep 7, 2023
c1c7f69
cleanup here and there
ignatiusmb Sep 8, 2023
70d1965
Merge branch 'master' into overhaul
ignatiusmb Sep 8, 2023
7d505c3
simulate hmr
ignatiusmb Sep 10, 2023
d43a953
fix relaying messages
ignatiusmb Sep 10, 2023
fcb3643
revamp styling
ignatiusmb Sep 11, 2023
242cdde
more strict typings
ignatiusmb Sep 11, 2023
79f836a
strict equality checks
ignatiusmb Sep 11, 2023
0e79965
cleanup and styling
ignatiusmb Sep 12, 2023
4a592d8
lint and stuff
ignatiusmb Sep 12, 2023
d396a5b
rename prop
ignatiusmb Sep 12, 2023
82de7cd
merge master -> overhaul
ignatiusmb Sep 12, 2023
101d706
comment out imports
ignatiusmb Sep 12, 2023
2615ff2
Merge branch 'master' into overhaul
ignatiusmb Sep 12, 2023
9a79e63
fix lockfile
ignatiusmb Sep 12, 2023
0d5973d
remove files added from merge
ignatiusmb Sep 12, 2023
95ec40a
merge master -> overhaul
ignatiusmb Sep 13, 2023
aecad95
format
ignatiusmb Sep 13, 2023
e9e7c77
if else block
ignatiusmb Sep 13, 2023
76a20c0
merge master -> overhaul
ignatiusmb Sep 13, 2023
057b65d
merge master -> overhaul
ignatiusmb Sep 14, 2023
471e963
cleanup
ignatiusmb Sep 14, 2023
3480425
reinstate break
ignatiusmb Sep 25, 2023
146c68c
final comments
ignatiusmb Sep 25, 2023
fd36209
fixes and compress svg attributes
ignatiusmb Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ After installing you will see a new tab in Developer Tools. This tab displays a

The `svelte-devtools` extension requires your Svelte application to be compiled with the `dev` option set to `true`. If you're using [SvelteKit](https://kit.svelte.dev/), this is done automatically, outside of that you will need to set it manually.

This extensions officially supports Svelte 4.0 and above.
This extension officially supports Svelte 4.0 and above.

## Development

Expand Down
95 changes: 59 additions & 36 deletions src/app.css
Original file line number Diff line number Diff line change
@@ -1,76 +1,99 @@
:root {
--background: rgb(255, 255, 255);
--color: rgb(74, 74, 79);

--t-duration: 240ms;
}

html {
height: 100%;
font-size: 12px;
}

body {
display: flex;
margin: 0;
height: 100%;
color: rgb(74, 74, 79);
background: var(--background);
color: var(--color);
font-family: monospace;
}

body.dark {
background-color: rgb(36, 36, 36);
color: rgb(177, 177, 179);
--color: rgb(177, 177, 179);
--background: rgb(36, 36, 36);
scrollbar-color: rgb(115, 115, 115) rgb(60, 60, 61);
}

/* dark mode scrollbar */
body.dark ::-webkit-scrollbar {
width: 14px;
height: 14px;
width: 0.875rem;
height: 0.875rem;
background-color: transparent;
box-shadow: inset 0 0 1px rgba(255, 255, 255, 0.5);
}

body.dark ::-webkit-scrollbar-thumb {
background-color: rgb(51, 51, 51);
box-shadow: inset 0 0 1px rgba(255, 255, 255, 0.5);
border: 1px solid rgba(255, 255, 255, 0.2);
}

/* basic resets */
ul {
margin: 0;
padding: 0;
list-style: none;
}

/* expandable arrows */
.expandable::before {
content: '';
position: absolute;
top: 0;
left: calc(var(--left, 3px) - 3px);

border-top: 0.375rem solid rgba(135, 135, 137, 0.9);
border-right: 0.25rem solid transparent;
border-left: 0.25rem solid transparent;
transition-duration: var(--t-duration);
transform: translate3d(0%, calc(50% + 0.25rem + var(--y-pad, 0px)), 0) rotate(-90deg);
/* transform: translate3d(-150%, calc(50% + 0.25rem + var(--y-pad, 0px)), 0) rotate(-90deg); */
}
.expandable.expanded::before {
transform: translate3d(0%, calc(50% + 0.25rem + var(--y-pad, 0px)), 0) rotate(0deg);
/* transform: translate3d(-150%, calc(50% + 0.25rem + var(--y-pad, 0px)), 0) rotate(0deg); */
}

/* tooltip pseudo-elements */
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
opacity: 1;
pointer-events: auto;
}
[data-tooltip]::before {
content: '';
opacity: 0;
pointer-events: none;

[data-tooltip]::after {
position: absolute;
bottom: -0.167rem /* -2px */;
left: 0;
z-index: 1;
display: block;
padding: 0.5rem /* 6px */ 1.333rem /* 16px */;
border-radius: 0.417rem /* 5px */;
background-color: rgb(48, 64, 81);
color: white;
bottom: -0.2rem;
left: 2.5rem;
border-right: 0.5rem solid transparent;
border-bottom: 0.5rem solid rgb(48, 64, 81);
border-left: 0.5rem solid transparent;
transition: opacity 0.2s;
}
[data-tooltip]::after {
content: attr(data-tooltip);
white-space: pre;
opacity: 0;
transition: opacity 0.2s;
transform: translateY(100%);
pointer-events: none;
}

[data-tooltip]::before {
z-index: 1;
position: absolute;
bottom: -0.167rem /* -2px */;
left: 2.5rem /* 30px */;
display: block;
width: 0;
height: 0;
border-right: 0.417rem /* 5px */ solid transparent;
border-bottom: 0.417rem /* 5px */ solid rgb(48, 64, 81);
border-left: 0.417rem /* 5px */ solid transparent;
content: '';
opacity: 0;
bottom: 0;
left: 0;

display: flex;
padding: 0.25rem 0.375rem;
border-radius: 0.25rem;
transition: opacity 0.2s;
pointer-events: none;
transform: translateY(100%);

background-color: rgb(48, 64, 81);
color: white;
}
131 changes: 77 additions & 54 deletions src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,80 @@
import { highlight, startPicker, stopPicker } from './highlight.js';
import { highlight } from './highlight.js';
import { addListener } from './listener.js';
import { profiler } from './profiler.js';
// import { profiler } from './profiler.js';
import { getNode } from './svelte.js';

// @ts-expect-error - possibly find an alternative
// @ts-ignore - possibly find an alternative
window.__svelte_devtools_inject_state = function (id, key, value) {
const { detail: component } = getNode(id) || {};
component && component.$inject_state({ [key]: value });
};

// @ts-expect-error - possibly find an alternative
// @ts-ignore - possibly find an alternative
window.__svelte_devtools_select_element = function (element) {
const node = getNode(element);
if (node) send('inspect', { node: serializeNode(node) });
if (node) send('inspect', { node: serialize(node) });
};

window.addEventListener('message', ({ data }) => {
const node = getNode(data.nodeId);

switch (data.type) {
case 'setSelected':
// @ts-expect-error - saved for `inspect()`
if (node) window.$s = node.detail;
break;

case 'setHover':
highlight(node);
break;

case 'startPicker':
startPicker();
break;

case 'stopPicker':
stopPicker();
break;

case 'startProfiler':
profiler.start();
break;

case 'stopProfiler':
profiler.stop();
break;
window.addEventListener('message', ({ data, source }) => {
// only accept messages from our application or script
if (source !== window || data?.source !== 'svelte-devtools') return;

if (data.type === 'ext/select') {
const node = getNode(data.payload);
// @ts-expect-error - saved for `inspect()`
if (node) window.$s = node.detail;
} else if (data.type === 'ext/highlight') {
const node = getNode(data.payload);
return highlight(node);
}

// --- TODO: cleanup/implement below ---

// case 'ext/inspect': {
// console.log(data.payload, data.payload instanceof HTMLElement);
// /** @param {MouseEvent} event */
// const move = ({ target }) => highlight({ type: 'element', detail: target });
// if (data.payload instanceof HTMLElement) {
// const node = getNode(data.payload);
// if (node) window.postMessage({ type: 'inspect', node: serialize(node) });
// } else if (data.payload === 'start') {
// document.addEventListener('mousemove', move, true);
// document.addEventListener(
// 'click',
// ({ target }) => {
// document.removeEventListener('mousemove', move, true);
// const node = getNode(/** @type {Node} */ (target));
// if (node) window.postMessage({ type: 'inspect', node: serialize(node) });
// },
// { capture: true, once: true },
// );
// return;
// }
// document.removeEventListener('mousemove', move, true);
// return highlight(undefined);
// }

// case 'ext/profiler': {
// return data.payload ? startProfiler() : stopProfiler();
// }

// switch (data.type) {

// case 'startPicker':
// startPicker();
// break;

// case 'stopPicker':
// stopPicker();
// break;

// case 'startProfiler':
// profiler.start();
// break;

// case 'stopProfiler':
// profiler.stop();
// break;
});

/**
Expand All @@ -53,9 +84,9 @@ window.addEventListener('message', ({ data }) => {
function clone(value, seen = new Map()) {
switch (typeof value) {
case 'function':
return { __isFunction: true, source: value.toString(), name: value.name };
return { __is: 'function', source: value.toString(), name: value.name };
case 'symbol':
return { __isSymbol: true, name: value.toString() };
return { __is: 'symbol', name: value.toString() };
case 'object': {
if (value === window || value === null) return null;
if (Array.isArray(value)) return value.map((o) => clone(o, seen));
Expand All @@ -64,11 +95,9 @@ function clone(value, seen = new Map()) {
/** @type {Record<string, any>} */
const o = {};
seen.set(value, o);

for (const [key, v] of Object.entries(value)) {
o[key] = clone(v, seen);
}

return o;
}
default:
Expand All @@ -77,7 +106,7 @@ function clone(value, seen = new Map()) {
}

/** @param {SvelteBlockDetail} node */
function serializeNode(node) {
function serialize(node) {
const res = /** @type {SvelteBlockDetail} */ ({
id: node.id,
type: node.type,
Expand Down Expand Up @@ -114,7 +143,6 @@ function serializeNode(node) {
attributes: attributes.map(({ name: key, value }) => ({ key, value })),
listeners: listeners.map((o) => ({ ...o, handler: o.handler.toString() })),
};

break;
}

Expand All @@ -133,6 +161,7 @@ function serializeNode(node) {
ctx: cloned.map(([key, value]) => ({ key, value })),
source: source.slice(source.indexOf('{'), source.indexOf('}') + 1),
};
break;
}
}

Expand All @@ -144,33 +173,27 @@ function serializeNode(node) {
* @param {Record<string, any>} [payload]
*/
function send(type, payload) {
window.postMessage({ source: 'svelte-devtools', type, ...payload });
window.postMessage({ source: 'svelte-devtools', type, payload });
}

addListener({
add(node, anchor) {
send('addNode', {
target: node.parent ? node.parent.id : null,
anchor: anchor ? anchor.id : null,
node: serializeNode(node),
send('courier/node:add', {
node: serialize(node),
target: node.parent?.id ?? null,
anchor: anchor?.id ?? null,
});
},

remove(node) {
send('removeNode', {
node: serializeNode(node),
});
send('courier/node:remove', { node: serialize(node) });
},

update(node) {
send('updateNode', {
node: serializeNode(node),
});
send('courier/node:update', { node: serialize(node) });
},

profile(frame) {
send('updateProfile', {
frame,
});
profile(/** frame */) {
// send('courier/profile:update', { frame });
},
});
4 changes: 2 additions & 2 deletions src/client/svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ document.addEventListener('SvelteRegisterBlock', ({ detail }) => {
block.m = (target, anchor) => {
const parent = current_block;

// @ts-expect-error - don't need 'block' | 'source' | 'ctx'
// @ts-expect-error - only the necessities
const node = /** @type {SvelteBlockDetail} */ ({
id: current_node_id,
type: 'block',
Expand Down Expand Up @@ -152,7 +152,7 @@ document.addEventListener('SvelteRegisterBlock', ({ detail }) => {
node.parentBlock = group;
node.type = 'iteration';

// @ts-expect-error - try to fix
// @ts-expect-error - overloaded nodes
nodes.add({ node, target: group, anchor });
} else {
nodes.add({ node, target, anchor });
Expand Down
2 changes: 1 addition & 1 deletion src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './app.css';
import App from './routes/App.svelte';
import App from './routes/+layout.svelte';

if (chrome.devtools.panels.themeName === 'dark') {
document.body.classList.add('dark');
Expand Down
Loading