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

Import / Export POC #371

Draft
wants to merge 7 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
43 changes: 41 additions & 2 deletions app/components/vis-bug/vis-bug.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { VisBugStyles } from '../styles.store'
import { VisBugModel } from './model'
import * as Icons from './vis-bug.icons'
import { provideSelectorEngine } from '../../features/search'
import { metaKey } from '../../utilities/'

import {
metaKey, applyStyle, showHideSelected
} from '../../utilities/'

const modemap = {
'hex': 'toHexString',
Expand All @@ -43,6 +46,7 @@ export default class VisBug extends HTMLElement {
this.colorPicker = ColorPicker(this.$shadow, this.selectorEngine)

provideSelectorEngine(this.selectorEngine)
this.selectorEngine.onSelectedUpdate(selection => this.broadcastSelection(selection))

this.toolSelected($('[data-tool="guides"]', this.$shadow)[0])
}
Expand All @@ -65,7 +69,7 @@ export default class VisBug extends HTMLElement {
this.toolSelected(e.currentTarget) && e.stopPropagation())

draggable({
el:this,
el:this,
surface: this.$shadow.querySelector('ol:not([colors])'),
cursor: 'grab',
})
Expand Down Expand Up @@ -230,6 +234,41 @@ export default class VisBug extends HTMLElement {
}
}

applyStyles(visbugPayload) {
this.selectorEngine
.selection()
.map(el => showHideSelected(el))
.forEach(el => {
const tagged = Object.assign(visbugPayload,
{ synthetic: true },
)
applyStyle({el, ...tagged})
})
}

broadcastSelection(nodes) {
const stringifyElement = node => {
const {nodeName, classList, id, index, parentNode } = node
return `${id?'#'+id:''}${nodeName.toLowerCase()}${classList.length?'.'+ classList.toString().split(' ').join('.'):''}:nth-child(${[...parentNode.children].indexOf(node)+1})`
}

const selection_payload = [...nodes]
.map(node =>
`${stringifyElement(node.parentNode)} > ${stringifyElement(node)}`)

// todo: create a callback system here to be iterated on
// todo: iterate over callbacks and invoke with payload
console.log(selection_payload)
}

consumeSelection(visbugSelectionPayload) {
const nodes = visbugSelectionPayload.flatMap(queryString =>
[...document.querySelectorAll(queryString)])

// this.selectorEngine.select(nodes)
console.log(nodes)
}

get activeTool() {
return this.active_tool.dataset.tool
}
Expand Down
8 changes: 5 additions & 3 deletions app/features/margin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import hotkeys from 'hotkeys-js'
import { metaKey, getStyle, getSide, showHideSelected } from '../utilities/'
import {
metaKey, getStyle, getSide,
showHideSelected, applyStyle
} from '../utilities/'

const key_events = 'up,down,left,right'
.split(',')
Expand Down Expand Up @@ -50,8 +53,7 @@ export function pushElement(els, direction) {
? payload.current - payload.amount
: payload.current + payload.amount
}))
.forEach(({el, style, margin}) =>
el.style[style] = `${margin < 0 ? 0 : margin}px`)
.forEach(applyStyle)
}

export function pushAllElementSides(els, keycommand) {
Expand Down
18 changes: 13 additions & 5 deletions app/features/padding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import hotkeys from 'hotkeys-js'
import { metaKey, getStyle, getSide, showHideSelected } from '../utilities/'
import {
metaKey, getStyle, getSide,
showHideSelected, applyStyle
} from '../utilities/'

const key_events = 'up,down,left,right'
.split(',')
Expand Down Expand Up @@ -50,8 +53,13 @@ export function padElement(els, direction) {
? payload.current - payload.amount
: payload.current + payload.amount
}))
.forEach(({el, style, padding}) =>
el.style[style] = `${padding < 0 ? 0 : padding}px`)
.map(({el, style, padding, current}) => ({
el,
style,
was: `${current}px`,
is: `${padding < 0 ? 0 : padding}px`
}))
.forEach(applyStyle)
}

export function padAllElementSides(els, keycommand) {
Expand Down Expand Up @@ -109,10 +117,10 @@ export function createPaddingVisual(el, hover = false) {
sides[side] = Math.round(val.toFixed(1) * 100) / 100
})

boxdisplay.position = {
boxdisplay.position = {
mode: 'padding',
color: hover ? 'purple' : 'pink',
bounds,
bounds,
sides,
}
}
Expand Down
1 change: 1 addition & 0 deletions app/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './accessibility'
export * from './common'
export * from './strings'
export * from './window'
export * from './side-effects'
21 changes: 21 additions & 0 deletions app/utilities/side-effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const state = {
bundle: [],
}

setInterval(() => {
if (state.bundle.length) {
console.log(state.bundle)
state.bundle = []
}
}, 0)

const pushPayload = payload =>
state.bundle.push(payload)

export const applyStyle = payload => {
const {el, style, was, is} = payload
el.style[style] = is

if (!payload.synthetic)
pushPayload(payload)
}