Skip to content

Commit d19f9f7

Browse files
refactor: update console logs to use console.info and add tree selection handling in AppletLayers
1 parent 643d11a commit d19f9f7

File tree

6 files changed

+165
-124
lines changed

6 files changed

+165
-124
lines changed

src/components/applets/AppletCanvasSettings.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
data-test="canvas-apply"
3838
@click="
3939
() => {
40-
console.log('Apply canvas size:', width, height)
40+
console.warn('TODO: Apply canvas size:', width, height)
4141
}
4242
"
4343
/>
@@ -48,7 +48,7 @@
4848
data-test="canvas-reset"
4949
@click="
5050
() => {
51-
console.log('Reset canvas size')
51+
console.warn('TODO: Reset canvas size')
5252
}
5353
"
5454
/>
@@ -104,7 +104,7 @@ function toggleGrid() {
104104
}
105105
106106
function updateSize() {
107-
console.log('TODO: updateSize')
107+
console.warn('TODO: updateSize')
108108
}
109109
</script>
110110

src/components/applets/AppletLayers.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<LayoutDrawerApplet name="Layers">
33
<!-- <pre>{{ json }}</pre> -->
44
<q-tree
5-
v-if="json"
65
v-model:selected="selectedElement"
76
:nodes="[json]"
87
node-key="id"
98
label-key="tagName"
109
:expanded="[json.id]"
10+
@update:selected="onTreeSelectionChange"
1111
>
1212
<template #default-header="prop">
1313
<q-icon :name="ICONS[prop.node.tagName]" class="q-mr-sm" />
@@ -19,7 +19,7 @@
1919
</template>
2020

2121
<script setup>
22-
import { computed, ref } from 'vue'
22+
import { computed, ref, watch } from 'vue'
2323
import LayoutDrawerApplet from 'components/layout/LayoutDrawerApplet.vue'
2424
import { useEditorStore } from 'src/stores/editor-store.js'
2525
@@ -28,6 +28,23 @@ const editorStore = useEditorStore()
2828
const json = computed(() => editorStore.json)
2929
3030
const selectedElement = ref(null)
31+
32+
// Watch for changes in editor store selection and sync to tree
33+
watch(
34+
() => editorStore.selectedId,
35+
(newSelectedId) => {
36+
selectedElement.value = newSelectedId
37+
},
38+
{ immediate: true },
39+
)
40+
41+
// Handle tree selection changes and update editor store
42+
function onTreeSelectionChange(nodeId) {
43+
if (nodeId !== editorStore.selectedId) {
44+
editorStore.setSelectionById(nodeId)
45+
}
46+
}
47+
3148
// json to be displayed in a tree view
3249
3350
const ICONS = {

src/components/editor/EditorCanvas.vue

Lines changed: 51 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
<div v-html="safeSvgHtml"></div>
2323

2424
<!-- Selection Outline -->
25-
<!-- <div
25+
<div
2626
v-if="selectionBox"
27+
ref="selectionBoxElement"
2728
class="selection-outline"
2829
:style="selectionStyle"
2930
data-test="selection-outline"
3031
@mousedown.stop="onSelectionMouseDown"
31-
/> -->
32+
/>
3233

3334
<!-- Rubber Band -->
3435
<!-- <div
@@ -105,14 +106,8 @@ const canvasBackground = ref(null)
105106
const svgContainer = ref(null)
106107
107108
// Canvas dimensions and zoom
108-
const canvasWidth = computed(() => {
109-
console.log('Canvas width computed:', store.canvasWidth)
110-
return store.canvasWidth
111-
})
112-
const canvasHeight = computed(() => {
113-
console.log('Canvas height computed:', store.canvasHeight)
114-
return store.canvasHeight
115-
})
109+
const canvasWidth = computed(() => store.canvasWidth)
110+
const canvasHeight = computed(() => store.canvasHeight)
116111
117112
// Pan and zoom state
118113
const panX = ref(0)
@@ -132,8 +127,8 @@ const scrollY = ref(0)
132127
133128
// Computed styles
134129
const canvasWrapperStyle = computed(() => ({
135-
width: `${canvasWidth.value * props.zoom }px`,
136-
height: `${canvasHeight.value * props.zoom }px`,
130+
width: `${canvasWidth.value * props.zoom}px`,
131+
height: `${canvasHeight.value * props.zoom}px`,
137132
position: 'absolute',
138133
top: '50%',
139134
left: '50%',
@@ -143,8 +138,8 @@ const canvasWrapperStyle = computed(() => ({
143138
}))
144139
145140
const canvasBackgroundStyle = computed(() => ({
146-
width: `${canvasWidth.value * props.zoom }px`,
147-
height: `${canvasHeight.value * props.zoom }px`,
141+
width: `${canvasWidth.value * props.zoom}px`,
142+
height: `${canvasHeight.value * props.zoom}px`,
148143
position: 'relative',
149144
background: '#f8f9fa',
150145
// border: '10px solid #e0e0e0',
@@ -180,27 +175,25 @@ const svgContainerStyle = computed(() => ({
180175
zIndex: 2,
181176
}))
182177
183-
// Commented out for simple canvas - no selection functionality
184-
// const selectionBox = computed(() => {
185-
// if (!store.selectedId) return null
186-
// const rect = store.getRectById(store.selectedId)
187-
// return rect
188-
// })
189-
190-
// Commented out for simple canvas
191-
// const selectionStyle = computed(() => {
192-
// if (!selectionBox.value) return {}
193-
// const { x, y, width, height } = selectionBox.value
194-
// return {
195-
// position: 'absolute',
196-
// left: `${x * props.zoom}px`,
197-
// top: `${y * props.zoom}px`,
198-
// width: `${width * props.zoom}px`,
199-
// height: `${height * props.zoom}px`,
200-
// pointerEvents: 'auto',
201-
// zIndex: 3,
202-
// }
203-
// })
178+
// Selection box computation
179+
const selectionBox = computed(() => (store.selectedId ? store.getBBoxById(store.selectedId) : null))
180+
const selectionBoxElement = ref(null)
181+
182+
// Selection style computation
183+
const selectionStyle = computed(() => {
184+
if (!selectionBox.value) return {}
185+
const { x, y, width, height } = selectionBox.value
186+
187+
return {
188+
position: 'absolute',
189+
left: `${x * props.zoom}px`,
190+
top: `${y * props.zoom}px`,
191+
width: `${width * props.zoom}px`,
192+
height: `${height * props.zoom}px`,
193+
pointerEvents: 'auto',
194+
zIndex: 3,
195+
}
196+
})
204197
205198
// Commented out for simple canvas
206199
// const rubberBand = computed(() => {
@@ -230,22 +223,16 @@ const svgContainerStyle = computed(() => ({
230223
231224
// Zoom functions are now handled by parent component
232225
233-
function updateCanvasSize() {
234-
// Update SVG viewBox to match canvas dimensions
235-
// store.updateSvgViewBox()
236-
console.log('updateCanvasSize')
237-
}
238-
239-
// Coordinate conversion - commented out for simple canvas
240-
// function toLocalCoords(evt) {
241-
// const svgEl = svgContainer.value
242-
// if (!svgEl) return { x: 0, y: 0 }
226+
// Coordinate conversion
227+
function toLocalCoords(evt) {
228+
const svgEl = svgContainer.value
229+
if (!svgEl) return { x: 0, y: 0 }
243230
244-
// const rect = svgEl.getBoundingClientRect()
245-
// const x = (evt.clientX - rect.left) / props.zoom
246-
// const y = (evt.clientY - rect.top) / props.zoom
247-
// return { x, y }
248-
// }
231+
const rect = svgEl.getBoundingClientRect()
232+
const x = (evt.clientX - rect.left) / props.zoom
233+
const y = (evt.clientY - rect.top) / props.zoom
234+
return { x, y }
235+
}
249236
250237
// Event handlers
251238
function onScroll() {
@@ -366,20 +353,22 @@ function onKeyUp(evt) {
366353
}
367354
}
368355
369-
function onClick() {
370-
// Commented out for simple canvas - no selection functionality
371-
// if (store.activeTool !== 'select') return
372-
// const p = toLocalCoords(evt)
373-
// store.setSelectionByPoint(p.x, p.y)
356+
function onClick(evt) {
357+
const p = toLocalCoords(evt)
358+
const selectedId = store.setSelectionByPoint(p.x, p.y)
359+
360+
console.info('Canvas clicked, active tool:', store.activeTool, p)
361+
if (selectedId) {
362+
console.info('Selection result:', selectedId)
363+
}
364+
365+
if (store.activeTool !== 'select') return
374366
}
375367
376-
// Commented out for simple canvas - no selection functionality
377-
// function onSelectionMouseDown(evt) {
378-
// if (store.activeTool !== 'select' || !selectionBox.value) return
379-
// const p = toLocalCoords(evt)
380-
// dragOffset.value = { dx: p.x - selectionBox.value.x, dy: p.y - selectionBox.value.y }
381-
// draggingSelection.value = true
382-
// }
368+
function onSelectionMouseDown(evt) {
369+
// Prevent the click from propagating to the canvas behind the selection
370+
evt.stopPropagation()
371+
}
383372
384373
// Watch for canvas dimension changes and reset pan position
385374
watch([canvasWidth, canvasHeight], () => {
@@ -395,12 +384,6 @@ let resizeObserver = null
395384
396385
// Initialize canvas
397386
onMounted(() => {
398-
updateCanvasSize()
399-
400-
// if(store.json) {
401-
// console.log('Initial JSON:', store.json)
402-
// }
403-
404387
// Set up resize observer
405388
if (scrollContainer.value) {
406389
resizeObserver = new ResizeObserver(() => {

src/pages/EditorPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function resetZoom() {
5757
// }
5858
5959
function handleToolbarClick(item) {
60-
console.log('Toolbar item clicked:', item.name)
60+
console.info('Toolbar item clicked:', item.name)
6161
6262
switch (item.name) {
6363
case 'toggle-left':

src/services/svg-io.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ export function importSvg(xml) {
55
ensureIds(doc)
66

77
const newXml = new XMLSerializer().serializeToString(doc) // re-serialize to clean up with ensured IDs
8-
98
const svg = doc.documentElement
10-
11-
// console.log('SVG root element:', svg)
129
const json = domToJson(svg)
13-
// console.log('Parsed SVG DOM:', dom)
1410

1511
const title = (doc.querySelector('svg > title')?.textContent || '').trim()
1612
const viewBox = svg.getAttribute('viewBox') || '0 0 800 600'
@@ -31,7 +27,6 @@ export function importSvg(xml) {
3127
}
3228
}
3329

34-
// console.log('SVG dimensions extracted:', { w, h, viewBox, title })
3530
return {
3631
xml: newXml,
3732
svg,
@@ -51,7 +46,6 @@ export function sanitizeOnExport(svgEl) {
5146
const disallowedAttrs = [/^on.*/i]
5247
const walker = svgEl.ownerDocument.createTreeWalker(svgEl, NodeFilter.SHOW_ELEMENT)
5348
while (walker.nextNode()) {
54-
console.log('Sanitizing element:', walker.currentNode.id || walker.currentNode.tagName)
5549
const el = walker.currentNode
5650
for (const attr of Array.from(el.attributes)) {
5751
if (disallowedAttrs.some((re) => re.test(attr.name))) {
@@ -63,11 +57,12 @@ export function sanitizeOnExport(svgEl) {
6357
}
6458

6559
export function domToJson(node) {
66-
const id =
67-
node.id ||
68-
(node.attributes && node.attributes.getNamedItem('id')?.value) ||
69-
new Date().getTime().toString(36) + Math.random().toString(36).slice(2)
70-
// console.log('Processing node:', node)
60+
let id = node.id || (node.attributes && node.attributes.getNamedItem('id')?.value) || null
61+
62+
if (!id) {
63+
id = 'id-' + new Date().getTime().toString(36) + Math.random().toString(36).slice(2)
64+
}
65+
7166
if (node.nodeType === Node.ELEMENT_NODE) {
7267
const obj = {
7368
id,

0 commit comments

Comments
 (0)