Floor plan editor: move corners by drag or arrow keys, insert on edges, delete by double click
Deploy / test (push) Failing after 3s
Deploy / deploy (push) Skipped

Corners stay editable after drawing: drag a corner (mouse or touch), focus it and nudge with the arrow
keys (Shift for larger steps), '+' on an edge inserts a corner in its middle, double click or Delete
removes one. Tested in a browser harness with the real field markup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-23 16:47:55 +02:00
1 parent f7cbc66451
commit dfd3f77a5d
2 files changed
+79 -16

No files matched your search

@@ -18,35 +18,98 @@
<div
x-data="{
state: $wire.$entangle('{{ $getStatePath() }}'),
points() { return String(this.state ?? '').trim().split(/\s+/).filter((pair) => /^\d+(\.\d+)?,\d+(\.\d+)?$/.test(pair)) },
add(event) {
const box = this.$refs.plan.getBoundingClientRect()
const x = Math.min(100, Math.max(0, Math.round((event.clientX - box.left) / box.width * 1000) / 10))
const y = Math.min(100, Math.max(0, Math.round((event.clientY - box.top) / box.height * 1000) / 10))
this.state = [...this.points(), x + ',' + y].join(' ')
dragging: null,
pairs() {
return String(this.state ?? '').trim().split(/\s+/)
.filter((pair) => /^\d+(\.\d+)?,\d+(\.\d+)?$/.test(pair))
.map((pair) => pair.split(',').map(Number))
},
undo() { this.state = this.points().slice(0, -1).join(' ') },
write(pairs) { this.state = pairs.map(([x, y]) => x + ',' + y).join(' ') },
clamp(value) { return Math.min(100, Math.max(0, Math.round(value * 10) / 10)) },
position(event) {
const box = this.$refs.plan.getBoundingClientRect()
return [this.clamp((event.clientX - box.left) / box.width * 100), this.clamp((event.clientY - box.top) / box.height * 100)]
},
midpoints() {
const pairs = this.pairs()
if (pairs.length < 2) return []
return pairs.map((a, index) => {
const b = pairs[(index + 1) % pairs.length]
return { index, x: this.clamp((a[0] + b[0]) / 2), y: this.clamp((a[1] + b[1]) / 2) }
}).slice(0, pairs.length === 2 ? 1 : pairs.length)
},
add(event) {
this.write([...this.pairs(), this.position(event)])
},
startDrag(index, event) {
this.dragging = index
event.target.setPointerCapture(event.pointerId)
},
drag(event) {
if (this.dragging === null) return
const pairs = this.pairs()
pairs[this.dragging] = this.position(event)
this.write(pairs)
},
endDrag() { this.dragging = null },
insert(index) {
const pairs = this.pairs()
const middle = this.midpoints().find((point) => point.index === index)
pairs.splice(index + 1, 0, [middle.x, middle.y])
this.write(pairs)
},
remove(index) {
const pairs = this.pairs()
pairs.splice(index, 1)
this.write(pairs)
},
nudge(index, dx, dy, event) {
const step = event.shiftKey ? 1 : 0.2
const pairs = this.pairs()
pairs[index] = [this.clamp(pairs[index][0] + dx * step), this.clamp(pairs[index][1] + dy * step)]
this.write(pairs)
},
undo() { this.write(this.pairs().slice(0, -1)) },
clear() { this.state = '' },
}"
>
<div x-ref="plan" x-on:click="add($event)" style="position:relative;cursor:crosshair;user-select:none;border:1px solid #e4e4e7;border-radius:.5rem;overflow:hidden">
<div x-ref="plan" x-on:click="add($event)" x-on:pointermove="drag($event)" x-on:pointerup="endDrag()" x-on:pointercancel="endDrag()"
style="position:relative;cursor:crosshair;user-select:none;touch-action:none;border:1px solid #e4e4e7;border-radius:.5rem;overflow:hidden">
<img src="{{ $planPhoto->url('lg') }}" alt="" draggable="false" style="display:block;width:100%;height:auto">
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style="position:absolute;inset:0;width:100%;height:100%;pointer-events:none" aria-hidden="true">
@foreach ($otherAreas as $area)
<polygon points="{{ $area }}" fill="rgba(37,99,235,.10)" stroke="#2563eb" stroke-width="1.5" vector-effect="non-scaling-stroke" />
@endforeach
<polygon x-bind:points="points().join(' ')" fill="rgba(217,119,6,.28)" stroke="#d97706" stroke-width="2.5" vector-effect="non-scaling-stroke" />
<polygon x-bind:points="pairs().map((pair) => pair.join(',')).join(' ')" fill="rgba(217,119,6,.28)" stroke="#d97706" stroke-width="2.5" vector-effect="non-scaling-stroke" />
</svg>
<template x-for="(point, index) in points()" x-bind:key="index">
<span x-bind:style="`position:absolute;left:${point.split(',')[0]}%;top:${point.split(',')[1]}%;width:12px;height:12px;margin:-6px 0 0 -6px;background:#fff;border:2px solid #d97706;border-radius:2px`"></span>
<template x-for="point in midpoints()" x-bind:key="'m' + point.index">
<button type="button" x-on:click.stop="insert(point.index)" x-bind:aria-label="'Punkt zwischen Ecke ' + (point.index + 1) + ' und der nächsten einfügen'" title="Punkt einfügen"
x-bind:style="`position:absolute;left:${point.x}%;top:${point.y}%;width:18px;height:18px;margin:-9px 0 0 -9px;padding:0;border-radius:999px;border:1.5px solid #d97706;background:rgba(255,255,255,.85);color:#b45309;font:600 13px/1 sans-serif;cursor:copy`">+</button>
</template>
<template x-for="(pair, index) in pairs()" x-bind:key="'p' + index">
<button type="button"
x-on:pointerdown.stop="startDrag(index, $event)"
x-on:click.stop
x-on:dblclick.stop="remove(index)"
x-on:keydown.arrow-left.prevent="nudge(index, -1, 0, $event)"
x-on:keydown.arrow-right.prevent="nudge(index, 1, 0, $event)"
x-on:keydown.arrow-up.prevent="nudge(index, 0, -1, $event)"
x-on:keydown.arrow-down.prevent="nudge(index, 0, 1, $event)"
x-on:keydown.delete.prevent="remove(index)"
x-bind:aria-label="'Ecke ' + (index + 1) + ' – ziehen oder mit den Pfeiltasten verschieben, Entf löscht'"
x-bind:title="'Ecke ' + (index + 1)"
x-bind:style="`position:absolute;left:${pair[0]}%;top:${pair[1]}%;width:16px;height:16px;margin:-8px 0 0 -8px;padding:0;background:${dragging === index ? '#d97706' : '#fff'};border:2px solid #d97706;border-radius:3px;cursor:${dragging === index ? 'grabbing' : 'grab'};touch-action:none`"></button>
</template>
</div>
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;margin-top:.5rem">
<span style="font-size:.875rem;color:#52525b" x-text="points().length + (points().length === 1 ? ' Eckpunkt' : ' Eckpunkte')"></span>
<x-filament::button size="sm" color="gray" x-on:click="undo()" x-bind:disabled="points().length === 0">Letzten Punkt entfernen</x-filament::button>
<x-filament::button size="sm" color="danger" outlined x-on:click="clear()" x-bind:disabled="points().length === 0">Fläche leeren</x-filament::button>
<span style="font-size:.875rem;color:#52525b" x-text="pairs().length + (pairs().length === 1 ? ' Eckpunkt' : ' Eckpunkte')"></span>
<x-filament::button size="sm" color="gray" x-on:click="undo()" x-bind:disabled="pairs().length === 0">Letzten Punkt entfernen</x-filament::button>
<x-filament::button size="sm" color="danger" outlined x-on:click="clear()" x-bind:disabled="pairs().length === 0">Fläche leeren</x-filament::button>
</div>
<p style="margin-top:.25rem;font-size:.875rem;color:#71717a">Klicken Sie nacheinander die Ecken des Raums auf dem Bild an, im Uhrzeigersinn. Blau umrandet: die anderen Räume.</p>
<p style="margin-top:.25rem;font-size:.875rem;color:#71717a">
Neue Ecke: auf das Bild klicken. Ecke verschieben: Punkt mit der Maus ziehen oder anklicken und mit den Pfeiltasten bewegen (mit Umschalt in größeren Schritten).
Ecke einfügen: „+“ auf einer Kante. Ecke löschen: Doppelklick auf den Punkt oder Entf. Blau umrandet: die anderen Räume.
</p>
</div>
@endif
</x-dynamic-component>