Skip to content
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

Feature: Design Tab (WIP) #205

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion app/features/selectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,20 @@ export function Selectable(visbug) {
const removeSelectedCallback = cb =>
selectedCallbacks = selectedCallbacks.filter(callback => callback != cb)

const tellWatchers = () =>
const layersFromDOM = ({nodeName, className, id, children}) => ({
nodeName, className, id,
children: [...children].map(layersFromDOM),
})

const tellWatchers = () => {
selectedCallbacks.forEach(cb => cb(selected))

visbug.$shadow.host.dispatchEvent(new CustomEvent('selected', {
bubbles: true,
detail: JSON.stringify(selected.map(layersFromDOM)),
}))
}

const disconnect = () => {
unselect_all()
unlisten()
Expand Down
1 change: 1 addition & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Open source browser design tools",
"manifest_version": 2,
"icons": { "128": "icons/visbug.png" },
"devtools_page": "panel/index.html",
"permissions": [
"activeTab",
"contextMenus",
Expand Down
13 changes: 13 additions & 0 deletions extension/pane/sizing/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<p>Calculated/authored/natural/responsive</p>
</body>
</html>
13 changes: 13 additions & 0 deletions extension/pane/styleguide/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<p>fonts/colors/spacing/etc</p>
</body>
</html>
13 changes: 13 additions & 0 deletions extension/pane/visbug/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<p>Hello from VisBug</p>
</body>
</html>
Binary file added extension/panel/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions extension/panel/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head></head>
<body>
<script src="index.js" type="module"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions extension/panel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// init panels
chrome.devtools.panels.create('Design', null, 'panel/panel.html', design_panel => {
// design_panel.onShown.addListener(e =>
// post({action: 'show-toolbar'}))
})

chrome.devtools.panels.elements.createSidebarPane('VisBug', sidebar => {
sidebar.setPage('../pane/visbug/index.html')
sidebar.setHeight('8ex')
})

chrome.devtools.panels.elements.createSidebarPane('Style Guide', sidebar => {
sidebar.setPage('../pane/styleguide/index.html')
sidebar.setHeight('8ex')
})

chrome.devtools.panels.elements.createSidebarPane('Sizing', sidebar => {
sidebar.setPage('../pane/sizing/index.html')
sidebar.setHeight('8ex')
})
83 changes: 83 additions & 0 deletions extension/panel/panel.bundle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
:root {
--bg: hsl(0,0%,100%);
--bg-hover: hsl(0,0%,95%);
--dot: hsl(0,0%,90%);
--text: hsl(0,0%,10%);
}

body {
margin: 0;
background-color: var(--bg);
color: var(--text);
background-image: -webkit-repeating-radial-gradient(
center center,
rgba(0,0,0,.05),
rgba(0,0,0,.05) 1px,
transparent 1px,
transparent 100%
);
background-size: 0.5rem 0.5rem
}

body.dark {
--bg: hsl(0,0%,15%);
--bg-hover: hsl(0,0%,20%);
--dot: hsl(0,0%,25%);
--text: hsl(0,0%,80%);
}

img {
width: 100%;
height: 100%;
object-fit: cover;
}

#layers {
background-color: var(--bg);
color: var(--text);
padding: 0.5rem;
}

ol {
padding: 0;
margin: 0;
list-style-type: none
}

ol > li,
ol li > .layer {
margin-left: 0.8rem;
}

details > summary:focus {
/*outline-color: hotpink;*/
outline: none;
}

details > summary::-webkit-details-marker {
color: hotpink;
}

details .layer {
padding: 0.5rem 1rem;
border-radius: 1rem
}

details .layer:hover {
background: var(--bg-hover);
cursor: pointer;
}

.layer {
display: inline-flex;
align-items: center;
}

details [icon] {
width: 0.5rem;
height: 0.5rem;
border-radius: 50%;
background-color: var(--dot);
display: inline-block;
margin-right: 0.5rem;
}
85 changes: 85 additions & 0 deletions extension/panel/panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
:root {
--bg: hsl(0,0%,100%);
--bg-hover: hsl(0,0%,95%);
--dot: hsl(0,0%,90%);
--text: hsl(0,0%,10%);
}

body {
margin: 0;
background-color: var(--bg);
color: var(--text);
background-image: -webkit-repeating-radial-gradient(
center center,
rgba(0,0,0,.05),
rgba(0,0,0,.05) 1px,
transparent 1px,
transparent 100%
);
background-size: 0.5rem 0.5rem;

&.dark {
--bg: hsl(0,0%,15%);
--bg-hover: hsl(0,0%,20%);
--dot: hsl(0,0%,25%);
--text: hsl(0,0%,80%);
}
}

img {
width: 100%;
height: 100%;
object-fit: cover;
}

#layers {
background-color: var(--bg);
color: var(--text);
padding: 0.5rem;
}

ol {
padding: 0;
margin: 0;
list-style-type: none;

& > li,
& li > .layer {
margin-left: 0.8rem;
}
}

details > summary {
&:focus {
/*outline-color: hotpink;*/
outline: none;
}

&::-webkit-details-marker {
color: hotpink;
}
}

details .layer {
padding: 0.5rem 1rem;
border-radius: 1rem;

&:hover {
background: var(--bg-hover);
cursor: pointer;
}
}

.layer {
display: inline-flex;
align-items: center;
}

details [icon] {
width: 0.5rem;
height: 0.5rem;
border-radius: 50%;
background-color: var(--dot);
display: inline-block;
margin-right: 0.5rem;
}
12 changes: 12 additions & 0 deletions extension/panel/panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<link rel="stylesheet" href="panel.bundle.css">
</head>
<body>
<!-- <img src="demo.png"> -->

<div id="layers"></div>

<script src="panel.js" type="module"></script>
</body>
</html>
54 changes: 54 additions & 0 deletions extension/panel/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Channel from '../utils/channel.js'

const channel_name = 'design-panel'
const Pipe = new Channel({
name: channel_name,
model: {
tabId: chrome.devtools.inspectedWindow.tabId,
src_channel: channel_name,
target_channel: 'design-artboard',
}
})

document.body.classList.add(
chrome.devtools.panels.themeName)

Pipe.port.onMessage.addListener((message, sender) => {
console.log(`${channel_name} recieved port message`, message, sender)

if (message.action == 'selected')
render_layers(message.payload)
})

Pipe.message.onMessage.addListener((request, sender, sendResponse) => {
console.log(`${channel_name} onMessage`, request)
})

// todo: render node props then children
const recurse_nodes = ({nodeName, className, id, children}) => `
<details open>
<summary class="layer">
<span icon></span>
${nodeName}${id ? '#' + id : ''} ${className}
</summary>
<ol>
${children.map(node =>
node.children.length
? `<li>${recurse_nodes(node)}</li>`
: `
<li>
<span class="layer">
<span icon></span>
${node.nodeName}${node.id ? '#' + node.id : ''} ${node.className}
</span>
</li>
`
).join('')}
</ol>
</details>
`

const render_layers = nodes => {
console.log('show in dom', nodes)
document.getElementById('layers').innerHTML = nodes.map(recurse_nodes).join('')
}
Loading