@7365admin1/layer-common 4.35.1-staging.370 → 4.35.1-staging.372
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/css/robot-hero.css +42 -5
- package/components/Robot/BuildingMap.vue +16 -9
- package/components/Robot/LiftQueue.vue +9 -4
- package/components/Robot/MapEditor.vue +314 -64
- package/composables/useRobotBuilding.ts +22 -3
- package/composables/useRobots.ts +13 -0
- package/package.json +2 -2
- package/utils/robot-building.ts +472 -36
- package/utils/robot-fleet-core.ts +57 -0
|
@@ -1,35 +1,43 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<!--
|
|
3
3
|
Map editor (README §4 "Edit mode"): Wall · Zone · Door · Lift shaft · Move
|
|
4
|
-
· Delete | Undo
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
· Delete | Undo · Redo | Save, one floor at a time on a flat 2D plan.
|
|
5
|
+
A drawing tool places its shape where you click (the new shape comes
|
|
6
|
+
selected with its handles). Move: click selects (Shift adds), drag moves
|
|
7
|
+
the selection, drag on empty space selects an area; handles resize a lift
|
|
8
|
+
shaft or zone, drag a wall's or door's ends and a zone's corners, and turn
|
|
9
|
+
a door or lift shaft. Snaps to the grid (Shift while dragging = free).
|
|
10
|
+
Keyboard: arrows move the cursor or nudge the selection, Enter places or
|
|
11
|
+
selects, Delete removes, Esc clears, Ctrl/Cmd+Z undo, Ctrl/Cmd+Shift+Z or
|
|
12
|
+
Ctrl+Y redo. Every drag is one undo step. Save checks in plain words
|
|
13
|
+
first, then writes the building map through the API (versioned).
|
|
9
14
|
-->
|
|
10
15
|
<div ref="root" class="hero-editor" :class="{ 'hero-editor--fs': isFs }">
|
|
11
16
|
<div class="hero-editor__bar">
|
|
12
17
|
<div class="hero-seg" role="toolbar" aria-label="Map editor tools">
|
|
13
18
|
<button v-for="t in MAP_TOOLS" :key="t.id" type="button" class="hero-seg__opt" :aria-pressed="tool === t.id" @click="pickTool(t.id)">{{ t.label }}</button>
|
|
14
|
-
<button type="button" class="hero-seg__opt hero-seg__opt--undo"
|
|
19
|
+
<button type="button" class="hero-seg__opt hero-seg__opt--undo" :disabled="!state.undo.length" @click="dispatch({ type: 'undo' })">Undo <span class="hero-seg__kbd">⌃Z</span></button>
|
|
20
|
+
<button type="button" class="hero-seg__opt hero-seg__opt--redo" :disabled="!state.redo.length" @click="dispatch({ type: 'redo' })">Redo <span class="hero-seg__kbd">⌃⇧Z</span></button>
|
|
15
21
|
<button type="button" class="hero-seg__opt hero-seg__opt--save" :disabled="saving" @click="save">{{ saving ? "Saving…" : "Save" }}</button>
|
|
16
22
|
</div>
|
|
23
|
+
<div class="hero-seg" role="group" aria-label="Grid">
|
|
24
|
+
<button type="button" class="hero-seg__opt" :aria-pressed="snapOn" title="Snap to the grid while dragging (hold Shift to place freely)" @click="snapOn = !snapOn">Snap</button>
|
|
25
|
+
<select v-model.number="gridM" class="hero-editor__grid" aria-label="Grid step">
|
|
26
|
+
<option v-for="g in GRID_STEPS_M" :key="g" :value="g">Grid {{ g }} m</option>
|
|
27
|
+
</select>
|
|
28
|
+
</div>
|
|
17
29
|
<select v-model.number="floor" class="hero-input hero-select hero-editor__floor" aria-label="Floor">
|
|
18
30
|
<option v-for="f in floors" :key="f" :value="f">{{ floorName(f) }}</option>
|
|
19
31
|
</select>
|
|
20
32
|
<input
|
|
21
|
-
v-if="tool === 'zone'"
|
|
33
|
+
v-if="tool === 'zone' || selectedZone"
|
|
22
34
|
v-model="zoneName"
|
|
23
35
|
class="hero-input hero-editor__zone"
|
|
24
36
|
aria-label="Zone name"
|
|
25
37
|
placeholder="Zone name (required to save)"
|
|
26
|
-
@input="
|
|
38
|
+
@input="dispatch({ type: 'rename', name: zoneName })"
|
|
27
39
|
/>
|
|
28
40
|
<span class="hero-editor__hint">{{ TOOL_HINTS[tool] }}</span>
|
|
29
|
-
<v-btn variant="outlined" class="hero-editor__fs" @click="fullscreen">
|
|
30
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" /></svg>
|
|
31
|
-
Full screen
|
|
32
|
-
</v-btn>
|
|
33
41
|
</div>
|
|
34
42
|
|
|
35
43
|
<div v-if="state.notice" class="hero-editor__notice" :class="{ 'hero-editor__notice--ok': state.notice.ok }" role="status" aria-live="polite">{{ state.notice.text }}</div>
|
|
@@ -38,10 +46,16 @@
|
|
|
38
46
|
<div
|
|
39
47
|
ref="plan"
|
|
40
48
|
class="hero-editor__plan"
|
|
49
|
+
:class="`hero-editor__plan--${planCursor}`"
|
|
50
|
+
:style="gridStyle"
|
|
41
51
|
tabindex="0"
|
|
42
52
|
role="application"
|
|
43
|
-
:aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor, Enter places.`"
|
|
44
|
-
@
|
|
53
|
+
:aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor or nudge the selection, Enter places or selects, Delete removes, Escape clears.`"
|
|
54
|
+
@pointerdown="onPlanDown"
|
|
55
|
+
@pointermove="onPointerMove"
|
|
56
|
+
@pointerup="onPointerUp"
|
|
57
|
+
@pointercancel="onPointerCancel"
|
|
58
|
+
@dblclick="onDoubleClick"
|
|
45
59
|
@keydown="onKey"
|
|
46
60
|
@blur="keyboard = false"
|
|
47
61
|
>
|
|
@@ -50,25 +64,45 @@
|
|
|
50
64
|
<span class="hero-editor__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
|
|
51
65
|
<svg class="hero-editor__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
|
|
52
66
|
<template v-for="s in visible" :key="s.id">
|
|
53
|
-
<polygon v-if="s.kind === 'zone'" class="hero-editor__zone-shape" :class="{ 'hero-editor__sel':
|
|
54
|
-
<line v-else-if="s.kind === 'wall'" class="hero-editor__wall" :class="{ 'hero-editor__sel':
|
|
67
|
+
<polygon v-if="s.kind === 'zone'" class="hero-editor__zone-shape" :class="{ 'hero-editor__sel': isSel(s.id) }" :points="pts(s.points)" vector-effect="non-scaling-stroke" />
|
|
68
|
+
<line v-else-if="s.kind === 'wall'" class="hero-editor__wall" :class="{ 'hero-editor__sel': isSel(s.id) }" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" />
|
|
69
|
+
<template v-else-if="s.kind === 'door'">
|
|
70
|
+
<polyline v-if="swings[s.id]" class="hero-editor__swing" :points="pts([...swings[s.id]!.leaf, ...swings[s.id]!.arc.slice().reverse()])" vector-effect="non-scaling-stroke" />
|
|
71
|
+
<line class="hero-editor__door" :class="{ 'hero-editor__sel': isSel(s.id) }" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" vector-effect="non-scaling-stroke" />
|
|
72
|
+
</template>
|
|
55
73
|
</template>
|
|
74
|
+
<line v-if="rotateLine" class="hero-editor__rotline" :x1="rotateLine.x1" :y1="rotateLine.y1" :x2="rotateLine.x2" :y2="rotateLine.y2" vector-effect="non-scaling-stroke" />
|
|
56
75
|
</svg>
|
|
57
76
|
<template v-for="s in visible" :key="`l-${s.id}`">
|
|
58
77
|
<div v-if="s.kind === 'zone'" class="hero-editor__label" :style="boxStyle(s)" :title="shapeTitle(s)">{{ s.name || "Unnamed zone" }}</div>
|
|
59
|
-
<div v-else-if="s.kind === 'lift'" class="hero-editor__lift" :class="{ 'hero-editor__sel':
|
|
60
|
-
<div v-else-if="s.kind === 'door'" class="hero-editor__door" :class="{ 'hero-editor__sel': state.moving === s.id }" :style="{ left: `${shapeAnchor(s).x}%`, top: `${shapeAnchor(s).y}%` }" :title="shapeTitle(s)" />
|
|
78
|
+
<div v-else-if="s.kind === 'lift'" class="hero-editor__lift" :class="{ 'hero-editor__sel': isSel(s.id) }" :style="boxStyle(s)" :title="shapeTitle(s)">Lift</div>
|
|
61
79
|
</template>
|
|
80
|
+
<div v-for="h in handles" :key="h.key" class="hero-editor__handle" :class="[`hero-editor__handle--${h.kind}`, { 'hero-editor__handle--on': h.kind === 'vertex' && state.vertex?.index === h.index }]" :style="{ left: `${h.x}%`, top: `${h.y}%`, cursor: h.kind === 'rotate' ? undefined : h.cursor }" aria-hidden="true" @pointerdown.stop="onHandleDown($event, h)" />
|
|
81
|
+
<span v-if="marquee" class="hero-editor__marquee" :style="rectStyle(marquee)" aria-hidden="true" />
|
|
62
82
|
<span v-if="keyboard" class="hero-editor__cursor" :style="{ left: `${cursor.x}%`, top: `${cursor.y}%` }" aria-hidden="true" />
|
|
63
83
|
</div>
|
|
64
84
|
|
|
65
85
|
<aside class="hero-editor__aside">
|
|
86
|
+
<template v-if="selectedShapes.length">
|
|
87
|
+
<div class="hero-aside__title hero-editor__asidetitle">{{ selectedShapes.length === 1 ? shapeTitle(selectedShapes[0]!) : `${selectedShapes.length} selected` }}</div>
|
|
88
|
+
<div class="hero-editor__actions">
|
|
89
|
+
<button v-if="selectedShapes.some((s) => s.kind === 'door')" type="button" class="hero-editor__act" @click="dispatch({ type: 'flip' })">Flip swing <span class="hero-seg__kbd">F</span></button>
|
|
90
|
+
<button v-if="selectedShapes.some((s) => s.kind === 'door' || s.kind === 'lift')" type="button" class="hero-editor__act" @click="dispatch({ type: 'turn' })">Turn 90° <span class="hero-seg__kbd">R</span></button>
|
|
91
|
+
<template v-if="selectedZone">
|
|
92
|
+
<button type="button" class="hero-editor__act" @click="addCorner">Add corner</button>
|
|
93
|
+
<button type="button" class="hero-editor__act" :disabled="state.vertex?.id !== selectedZone.id || selectedZone.points.length <= 3" @click="dispatch({ type: 'remove' })">Remove corner</button>
|
|
94
|
+
</template>
|
|
95
|
+
<button type="button" class="hero-editor__act hero-editor__act--del" @click="removeSelection">Delete <span class="hero-seg__kbd">Del</span></button>
|
|
96
|
+
</div>
|
|
97
|
+
<div v-if="selectedZone" class="hero-muted">Double-click an edge to add a corner; double-click a corner to remove it.</div>
|
|
98
|
+
<div v-if="selectedShapes.some((s) => s.kind === 'lift')" class="hero-muted">A lift shaft turns a quarter at a time.</div>
|
|
99
|
+
</template>
|
|
66
100
|
<div class="hero-aside__title hero-editor__asidetitle">On {{ floorName(floor) }}</div>
|
|
67
|
-
<
|
|
101
|
+
<button v-for="s in visible" :key="`r-${s.id}`" type="button" class="hero-editor__row" :class="{ 'hero-editor__row--sel': isSel(s.id) }" :aria-pressed="isSel(s.id)" @click="onRow($event, s)">
|
|
68
102
|
<span>{{ shapeTitle(s) }}</span><span class="hero-editor__pos">{{ shapeAnchor(s).x }}, {{ shapeAnchor(s).y }}</span>
|
|
69
|
-
</
|
|
103
|
+
</button>
|
|
70
104
|
<div v-if="!visible.length" class="hero-muted">Nothing drawn yet. Pick a tool and click the plan.</div>
|
|
71
|
-
<div class="hero-editor__note">The plan image comes from the robot; everything here is drawn on top of it. Keyboard: Tab to the plan
|
|
105
|
+
<div class="hero-editor__note">The plan image comes from the robot; everything here is drawn on top of it. Keyboard: Tab to the plan; arrow keys move the cursor (or nudge what is selected, Shift for 1 m); Enter places or selects; Delete removes; Esc clears the selection.</div>
|
|
72
106
|
</aside>
|
|
73
107
|
</div>
|
|
74
108
|
</div>
|
|
@@ -78,21 +112,37 @@
|
|
|
78
112
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
79
113
|
import { floorName, MAP_TOOLS } from "../../utils/robot-display";
|
|
80
114
|
import {
|
|
115
|
+
DEFAULT_GRID_M,
|
|
116
|
+
doorSwing,
|
|
81
117
|
editorProblem,
|
|
82
118
|
editorReduce,
|
|
83
119
|
emptyEditor,
|
|
120
|
+
GRID_STEPS_M,
|
|
121
|
+
gridShares,
|
|
122
|
+
hitShape,
|
|
123
|
+
NUDGE_BIG_M,
|
|
124
|
+
NUDGE_M,
|
|
125
|
+
PLAN_H_M,
|
|
126
|
+
PLAN_W_M,
|
|
84
127
|
saveErrorText,
|
|
85
128
|
savedNotice,
|
|
86
129
|
shapeAnchor,
|
|
87
130
|
shapeBox,
|
|
131
|
+
shapeHandles,
|
|
88
132
|
shapesFromMap,
|
|
133
|
+
shapesInRect,
|
|
89
134
|
shapesOnFloor,
|
|
90
135
|
shapeTitle,
|
|
136
|
+
snapToGrid,
|
|
91
137
|
toMapBody,
|
|
92
138
|
TOOL_HINTS,
|
|
139
|
+
turnCentre,
|
|
140
|
+
type TDragOp,
|
|
141
|
+
type TEditorAction,
|
|
93
142
|
type TEditorShape,
|
|
94
143
|
type TEditorState,
|
|
95
144
|
type TEditorTool,
|
|
145
|
+
type TShapeHandle,
|
|
96
146
|
} from "../../utils/robot-building";
|
|
97
147
|
|
|
98
148
|
const props = withDefaults(
|
|
@@ -112,77 +162,277 @@ const emit = defineEmits<{ saved: [] }>();
|
|
|
112
162
|
const { createBuildingMap, updateBuildingMap } = useRobots();
|
|
113
163
|
|
|
114
164
|
const state = ref<TEditorState>(emptyEditor(shapesFromMap(props.map)));
|
|
165
|
+
const dispatch = (a: TEditorAction) => (state.value = editorReduce(state.value, a));
|
|
115
166
|
/** A newer map (after our own save, or another tab's) replaces the shapes only while nothing is unsaved. */
|
|
116
167
|
watch(
|
|
117
168
|
() => props.map,
|
|
118
169
|
(m) => {
|
|
119
|
-
if (!state.value.dirty) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
|
|
170
|
+
if (!state.value.dirty && !state.value.drag) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
|
|
120
171
|
},
|
|
121
172
|
);
|
|
122
173
|
|
|
123
174
|
const tool = ref<TEditorTool>("wall");
|
|
124
175
|
const zoneName = ref("");
|
|
176
|
+
const snapOn = ref(true);
|
|
177
|
+
const gridM = ref(DEFAULT_GRID_M);
|
|
178
|
+
const gridStyle = computed(() => {
|
|
179
|
+
const g = gridShares(gridM.value);
|
|
180
|
+
return { backgroundSize: `${g.x}% ${g.y}%` };
|
|
181
|
+
});
|
|
125
182
|
const floor = ref<number>(props.startFloor !== null && props.floors.includes(props.startFloor) ? props.startFloor : props.floors[0] ?? 1);
|
|
126
183
|
watch(() => props.floors, (f) => {
|
|
127
184
|
if (!f.includes(floor.value)) floor.value = f[0] ?? 1;
|
|
128
185
|
});
|
|
186
|
+
watch(floor, () => dispatch({ type: "select", ids: [] }));
|
|
129
187
|
const visible = computed(() => shapesOnFloor(state.value.shapes, floor.value));
|
|
188
|
+
const isSel = (id: string) => state.value.selected.includes(id);
|
|
189
|
+
const selectedShapes = computed(() => visible.value.filter((s) => isSel(s.id)));
|
|
190
|
+
const single = computed(() => (selectedShapes.value.length === 1 ? selectedShapes.value[0]! : null));
|
|
191
|
+
const selectedZone = computed(() => (single.value?.kind === "zone" ? single.value : null));
|
|
192
|
+
watch(selectedZone, (z) => {
|
|
193
|
+
if (z) zoneName.value = z.name ?? "";
|
|
194
|
+
});
|
|
195
|
+
const handles = computed<TShapeHandle[]>(() => (single.value ? shapeHandles(single.value) : []));
|
|
196
|
+
const rotateLine = computed(() => {
|
|
197
|
+
const r = handles.value.find((h) => h.kind === "rotate");
|
|
198
|
+
if (!r || !single.value) return null;
|
|
199
|
+
const c = turnCentre(single.value);
|
|
200
|
+
return { x1: c.x, y1: c.y, x2: r.x, y2: r.y };
|
|
201
|
+
});
|
|
202
|
+
const swings = computed(() => Object.fromEntries(visible.value.filter((s) => s.kind === "door").map((s) => [s.id, doorSwing(s)])));
|
|
130
203
|
|
|
131
204
|
function pickTool(id: TEditorTool) {
|
|
132
205
|
tool.value = id;
|
|
133
|
-
|
|
206
|
+
dispatch({ type: "tool", tool: id });
|
|
134
207
|
}
|
|
135
208
|
|
|
136
|
-
/* ----
|
|
209
|
+
/* ---- pointer: mouse, touch and pen alike ---- */
|
|
137
210
|
const plan = ref<HTMLElement | null>(null);
|
|
138
211
|
const cursor = ref({ x: 50, y: 50 });
|
|
139
212
|
const keyboard = ref(false);
|
|
213
|
+
const marquee = ref<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
214
|
+
const hoverId = ref<string | null>(null);
|
|
215
|
+
type TPress = { pointer: number; x: number; y: number; cx: number; cy: number; mode: "drag" | "marquee" | "click"; op?: TDragOp; shift: boolean; started: boolean };
|
|
216
|
+
let press: TPress | null = null;
|
|
217
|
+
/** The cursor a drag in progress shows: move, rotate or a resize direction. */
|
|
218
|
+
const dragKind = ref("");
|
|
140
219
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
220
|
+
function at(e: { clientX: number; clientY: number }) {
|
|
221
|
+
const r = plan.value!.getBoundingClientRect();
|
|
222
|
+
const c = (v: number) => Math.max(0, Math.min(100, v));
|
|
223
|
+
return { x: c(((e.clientX - r.left) / r.width) * 100), y: c(((e.clientY - r.top) / r.height) * 100) };
|
|
224
|
+
}
|
|
225
|
+
/** How near counts as "on" a line or corner: 10 screen pixels (16 for a finger), in metres. */
|
|
226
|
+
function tolerance(pointerType = "mouse") {
|
|
227
|
+
const r = plan.value?.getBoundingClientRect();
|
|
228
|
+
if (!r?.width) return 0.4;
|
|
229
|
+
return Math.max(PLAN_W_M / r.width, PLAN_H_M / r.height) * (pointerType === "touch" ? 16 : 10);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function startPress(e: PointerEvent, mode: TPress["mode"], op?: TDragOp) {
|
|
233
|
+
const p = at(e);
|
|
234
|
+
press = { pointer: e.pointerId, x: p.x, y: p.y, cx: e.clientX, cy: e.clientY, mode, op, shift: e.shiftKey, started: false };
|
|
235
|
+
plan.value?.setPointerCapture?.(e.pointerId);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function onPlanDown(e: PointerEvent) {
|
|
239
|
+
if (e.pointerType === "mouse" && e.button !== 0) return;
|
|
240
|
+
plan.value?.focus({ preventScroll: true });
|
|
241
|
+
keyboard.value = false;
|
|
242
|
+
const p = at(e);
|
|
243
|
+
const target = hitShape(visible.value, p, tolerance(e.pointerType));
|
|
244
|
+
const t = tool.value;
|
|
245
|
+
if (t === "delete") {
|
|
246
|
+
if (target) dispatch({ type: "pick", id: target.id, tool: "delete" });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (t === "zone" && target?.kind === "zone" && zoneName.value.trim() && !isSel(target.id)) {
|
|
250
|
+
dispatch({ type: "pick", id: target.id, tool: "zone", zoneName: zoneName.value });
|
|
251
|
+
return;
|
|
147
252
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (
|
|
253
|
+
// Move grabs anything; a drawing tool grabs only its own kind (a wall tool draws walls inside a zone, a door goes on a wall).
|
|
254
|
+
if (t === "move" || target?.kind === t) {
|
|
255
|
+
if (!target) return startPress(e, "marquee");
|
|
256
|
+
if (e.shiftKey) {
|
|
257
|
+
dispatch({ type: "select", ids: [target.id], mode: "toggle" });
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (!isSel(target.id)) dispatch({ type: "select", ids: [target.id] });
|
|
261
|
+
return startPress(e, "drag", { kind: "move" });
|
|
262
|
+
}
|
|
263
|
+
// A drawing tool: place (on the grid while snapping), and select the new shape.
|
|
264
|
+
e.preventDefault();
|
|
265
|
+
const q = snapOn.value && !e.shiftKey ? snapToGrid(p, gridM.value) : p;
|
|
266
|
+
dispatch({ type: "place", tool: t, floorNo: floor.value, x: Math.min(98, q.x), y: Math.min(98, q.y), zoneName: zoneName.value, floors: props.floors });
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function onHandleDown(e: PointerEvent, h: TShapeHandle) {
|
|
270
|
+
if ((e.pointerType === "mouse" && e.button !== 0) || !single.value) return;
|
|
271
|
+
plan.value?.focus({ preventScroll: true });
|
|
272
|
+
const id = single.value.id;
|
|
273
|
+
const op: TDragOp =
|
|
274
|
+
h.kind === "resize" ? { kind: "handle", id, handle: h.handle! } : h.kind === "vertex" ? { kind: "vertex", id, index: h.index! } : { kind: "rotate", id };
|
|
275
|
+
// Grabbing a zone corner marks it, so Delete / Remove corner acts on it even without a drag.
|
|
276
|
+
if (h.kind === "vertex" && single.value.kind === "zone") state.value = { ...state.value, vertex: { id, index: h.index! } };
|
|
277
|
+
startPress(e, "drag", op);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function onPointerMove(e: PointerEvent) {
|
|
281
|
+
if (!press) {
|
|
282
|
+
if (e.pointerType === "mouse") hoverId.value = hitShape(visible.value, at(e), tolerance())?.id ?? null;
|
|
156
283
|
return;
|
|
157
284
|
}
|
|
158
|
-
|
|
285
|
+
if (e.pointerId !== press.pointer) return;
|
|
286
|
+
const p = at(e);
|
|
287
|
+
if (!press.started) {
|
|
288
|
+
if (Math.hypot(e.clientX - press.cx, e.clientY - press.cy) < 3) return;
|
|
289
|
+
press.started = true;
|
|
290
|
+
if (press.mode === "drag") {
|
|
291
|
+
dispatch({ type: "dragStart", op: press.op!, x: press.x, y: press.y });
|
|
292
|
+
dragKind.value = press.op!.kind === "rotate" ? "rotate" : press.op!.kind === "handle" ? handleCursor(press.op!.handle) : "move";
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (press.mode === "drag") {
|
|
296
|
+
const snap = snapOn.value && !e.shiftKey;
|
|
297
|
+
dispatch({ type: "dragMove", x: p.x, y: p.y, grid: snap ? gridM.value : 0, tolerance: snap ? tolerance(e.pointerType) : 0 });
|
|
298
|
+
} else if (press.mode === "marquee") {
|
|
299
|
+
marquee.value = { x: press.x, y: press.y, w: p.x - press.x, h: p.y - press.y };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function endPress() {
|
|
304
|
+
if (press) plan.value?.releasePointerCapture?.(press.pointer);
|
|
305
|
+
press = null;
|
|
306
|
+
marquee.value = null;
|
|
307
|
+
dragKind.value = "";
|
|
159
308
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
309
|
+
|
|
310
|
+
function onPointerUp(e: PointerEvent) {
|
|
311
|
+
if (!press || e.pointerId !== press.pointer) return;
|
|
312
|
+
if (press.mode === "drag" && press.started) dispatch({ type: "dragEnd" });
|
|
313
|
+
else if (press.mode === "marquee") {
|
|
314
|
+
if (press.started && marquee.value) dispatch({ type: "select", ids: shapesInRect(visible.value, marquee.value), mode: press.shift ? "add" : "replace" });
|
|
315
|
+
else if (!press.shift) dispatch({ type: "select", ids: [] });
|
|
316
|
+
}
|
|
317
|
+
endPress();
|
|
164
318
|
}
|
|
319
|
+
|
|
320
|
+
function onPointerCancel() {
|
|
321
|
+
if (press?.mode === "drag" && press.started) dispatch({ type: "dragCancel" });
|
|
322
|
+
endPress();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Double-click on a selected zone: on a corner removes it, on an edge adds a
|
|
327
|
+
* corner there. (The plan holds the pointer during a press, so the double
|
|
328
|
+
* click always arrives here, even over a handle.)
|
|
329
|
+
*/
|
|
330
|
+
function onDoubleClick(e: MouseEvent) {
|
|
331
|
+
const z = selectedZone.value;
|
|
332
|
+
if (!z || tool.value === "delete") return;
|
|
333
|
+
const p = at(e);
|
|
334
|
+
const r = plan.value!.getBoundingClientRect();
|
|
335
|
+
const reach = 14; // px
|
|
336
|
+
const corner = z.points.findIndex((q) => Math.hypot(((q.x - p.x) / 100) * r.width, ((q.y - p.y) / 100) * r.height) <= reach);
|
|
337
|
+
if (corner >= 0) dispatch({ type: "removeVertex", id: z.id, index: corner });
|
|
338
|
+
else dispatch({ type: "addVertex", id: z.id, x: p.x, y: p.y, within: tolerance() * 1.5 });
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Add corner (button): the middle of the zone's longest edge. */
|
|
342
|
+
function addCorner() {
|
|
343
|
+
const z = selectedZone.value;
|
|
344
|
+
if (!z) return;
|
|
345
|
+
let best = { len: -1, x: 0, y: 0 };
|
|
346
|
+
z.points.forEach((a, i) => {
|
|
347
|
+
const b = z.points[(i + 1) % z.points.length]!;
|
|
348
|
+
const len = Math.hypot((b.x - a.x) * PLAN_W_M, (b.y - a.y) * PLAN_H_M);
|
|
349
|
+
if (len > best.len) best = { len, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
350
|
+
});
|
|
351
|
+
dispatch({ type: "addVertex", id: z.id, x: best.x, y: best.y });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function removeSelection() {
|
|
355
|
+
state.value = { ...state.value, vertex: null };
|
|
356
|
+
dispatch({ type: "remove" });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function onRow(e: MouseEvent, s: TEditorShape) {
|
|
360
|
+
if (tool.value !== "move") pickTool("move");
|
|
361
|
+
dispatch({ type: "select", ids: [s.id], mode: e.shiftKey ? "toggle" : "replace" });
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const handleCursor = (h: string) => (h === "n" || h === "s" ? "ns" : h === "e" || h === "w" ? "ew" : h === "nw" || h === "se" ? "nwse" : "nesw");
|
|
365
|
+
/** The plan's cursor: what a drag is doing, else what a press would do here. */
|
|
366
|
+
const planCursor = computed(() => {
|
|
367
|
+
if (dragKind.value) return dragKind.value;
|
|
368
|
+
if (tool.value === "delete") return hoverId.value ? "pointer" : "default";
|
|
369
|
+
const hover = hoverId.value ? visible.value.find((s) => s.id === hoverId.value) : null;
|
|
370
|
+
if (hover && (tool.value === "move" || hover.kind === tool.value)) return "move";
|
|
371
|
+
return tool.value === "move" ? "default" : "crosshair";
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
/* ---- keyboard ---- */
|
|
375
|
+
function act(x: number, y: number, shift = false) {
|
|
376
|
+
const target = hitShape(visible.value, { x, y }, tolerance());
|
|
377
|
+
const t = tool.value;
|
|
378
|
+
if (t === "delete") return void (target && dispatch({ type: "pick", id: target.id, tool: "delete" }));
|
|
379
|
+
if (t === "zone" && target?.kind === "zone" && zoneName.value.trim() && !isSel(target.id)) {
|
|
380
|
+
return void dispatch({ type: "pick", id: target.id, tool: "zone", zoneName: zoneName.value });
|
|
381
|
+
}
|
|
382
|
+
if (t === "move" || target?.kind === t) {
|
|
383
|
+
if (target) dispatch({ type: "select", ids: [target.id], mode: shift ? "toggle" : "replace" });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
dispatch({ type: "place", tool: t, floorNo: floor.value, x: Math.min(98, x), y: Math.min(98, y), zoneName: zoneName.value, floors: props.floors });
|
|
387
|
+
}
|
|
388
|
+
|
|
165
389
|
function onKey(e: KeyboardEvent) {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
390
|
+
const k = e.key;
|
|
391
|
+
if (k === "Escape") {
|
|
392
|
+
if (state.value.drag) onPointerCancel();
|
|
393
|
+
else if (state.value.selected.length) dispatch({ type: "select", ids: [] });
|
|
394
|
+
else keyboard.value = false;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (k === "Delete" || k === "Backspace") {
|
|
169
398
|
e.preventDefault();
|
|
399
|
+
return void dispatch({ type: "remove" });
|
|
400
|
+
}
|
|
401
|
+
if ((e.ctrlKey || e.metaKey) && k.toLowerCase() === "a") {
|
|
402
|
+
e.preventDefault();
|
|
403
|
+
return void dispatch({ type: "selectAll", floorNo: floor.value });
|
|
404
|
+
}
|
|
405
|
+
if (!e.ctrlKey && !e.metaKey && !e.altKey && (k === "f" || k === "F")) return void dispatch({ type: "flip" });
|
|
406
|
+
if (!e.ctrlKey && !e.metaKey && !e.altKey && (k === "r" || k === "R")) return void dispatch({ type: "turn" });
|
|
407
|
+
const dir: Record<string, [number, number]> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] };
|
|
408
|
+
if (dir[k]) {
|
|
409
|
+
e.preventDefault();
|
|
410
|
+
const [dx, dy] = dir[k]!;
|
|
411
|
+
if (state.value.selected.length && !state.value.drag) {
|
|
412
|
+
const m = e.shiftKey ? NUDGE_BIG_M : NUDGE_M;
|
|
413
|
+
return void dispatch({ type: "nudge", dx: dx * m, dy: dy * m });
|
|
414
|
+
}
|
|
170
415
|
keyboard.value = true;
|
|
171
|
-
const
|
|
172
|
-
cursor.value = { x: Math.max(0, Math.min(98, cursor.value.x + dx)), y: Math.max(0, Math.min(98, cursor.value.y + dy)) };
|
|
173
|
-
} else if (
|
|
416
|
+
const step = e.shiftKey ? 10 : 2;
|
|
417
|
+
cursor.value = { x: Math.max(0, Math.min(98, cursor.value.x + dx * step)), y: Math.max(0, Math.min(98, cursor.value.y + dy * step)) };
|
|
418
|
+
} else if (k === "Enter" || k === " ") {
|
|
174
419
|
e.preventDefault();
|
|
175
420
|
keyboard.value = true;
|
|
176
|
-
act(cursor.value.x, cursor.value.y);
|
|
421
|
+
act(cursor.value.x, cursor.value.y, e.shiftKey);
|
|
177
422
|
}
|
|
178
423
|
}
|
|
179
424
|
|
|
180
|
-
/** Ctrl/Cmd+Z anywhere in the editor except while typing
|
|
425
|
+
/** Ctrl/Cmd+Z undo, Ctrl/Cmd+Shift+Z or Ctrl+Y redo - anywhere in the editor except while typing. */
|
|
181
426
|
function onUndoKey(e: KeyboardEvent) {
|
|
182
|
-
if (!(e.ctrlKey || e.metaKey)
|
|
183
|
-
|
|
427
|
+
if (!(e.ctrlKey || e.metaKey)) return;
|
|
428
|
+
const k = e.key.toLowerCase();
|
|
429
|
+
const redo = (k === "z" && e.shiftKey) || (k === "y" && !e.shiftKey);
|
|
430
|
+
if (!(k === "z" && !e.shiftKey) && !redo) return;
|
|
431
|
+
const tag = (e.target as HTMLElement)?.tagName;
|
|
432
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
|
|
184
433
|
e.preventDefault();
|
|
185
|
-
|
|
434
|
+
if (state.value.drag) return;
|
|
435
|
+
dispatch({ type: redo ? "redo" : "undo" });
|
|
186
436
|
}
|
|
187
437
|
onMounted(() => window.addEventListener("keydown", onUndoKey));
|
|
188
438
|
onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
|
|
@@ -191,13 +441,13 @@ onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
|
|
|
191
441
|
const saving = ref(false);
|
|
192
442
|
async function save() {
|
|
193
443
|
const problem = editorProblem(state.value);
|
|
194
|
-
if (problem) return void (
|
|
444
|
+
if (problem) return void dispatch({ type: "notice", text: problem, ok: false });
|
|
195
445
|
if (!props.map?._id && !props.ownerRobotId) {
|
|
196
|
-
return void (
|
|
446
|
+
return void dispatch({
|
|
197
447
|
type: "notice",
|
|
198
448
|
text: "Can't save yet: this site has no robot to keep the map with. Add a robot to the site first, then draw the map.",
|
|
199
449
|
ok: false,
|
|
200
|
-
})
|
|
450
|
+
});
|
|
201
451
|
}
|
|
202
452
|
const name = String(props.map?.name || `${props.siteName || "Site"} building`).slice(0, 60);
|
|
203
453
|
const body = toMapBody(state.value.shapes, name, props.map);
|
|
@@ -205,29 +455,29 @@ async function save() {
|
|
|
205
455
|
try {
|
|
206
456
|
if (props.map?._id) await updateBuildingMap(String(props.map._id), { ...body, version: Number(props.map.version) || 1 });
|
|
207
457
|
else await createBuildingMap({ ...body, robotId: props.ownerRobotId });
|
|
208
|
-
|
|
458
|
+
dispatch({ type: "saved", text: savedNotice(new Date(), state.value.shapes.length, props.siteName) });
|
|
209
459
|
emit("saved");
|
|
210
460
|
} catch (e) {
|
|
211
|
-
|
|
461
|
+
dispatch({ type: "notice", text: saveErrorText(e), ok: false });
|
|
212
462
|
} finally {
|
|
213
463
|
saving.value = false;
|
|
214
464
|
}
|
|
215
465
|
}
|
|
216
466
|
|
|
217
467
|
/* ---- drawing helpers + full screen ---- */
|
|
218
|
-
const pts = (
|
|
468
|
+
const pts = (list: Array<{ x: number; y: number }>) => list.map((p) => `${p.x},${p.y}`).join(" ");
|
|
219
469
|
function boxStyle(s: TEditorShape) {
|
|
220
470
|
const b = shapeBox(s);
|
|
221
471
|
return { left: `${b.x}%`, top: `${b.y}%`, width: `${b.w}%`, height: `${b.h}%` };
|
|
222
472
|
}
|
|
473
|
+
function rectStyle(r: { x: number; y: number; w: number; h: number }) {
|
|
474
|
+
return { left: `${Math.min(r.x, r.x + r.w)}%`, top: `${Math.min(r.y, r.y + r.h)}%`, width: `${Math.abs(r.w)}%`, height: `${Math.abs(r.h)}%` };
|
|
475
|
+
}
|
|
223
476
|
const root = ref<HTMLElement | null>(null);
|
|
224
477
|
const isFs = ref(false);
|
|
225
478
|
const onFs = () => (isFs.value = document.fullscreenElement === root.value);
|
|
226
479
|
onMounted(() => document.addEventListener("fullscreenchange", onFs));
|
|
227
480
|
onBeforeUnmount(() => document.removeEventListener("fullscreenchange", onFs));
|
|
228
|
-
|
|
229
|
-
if (document.fullscreenElement) document.exitFullscreen?.();
|
|
230
|
-
else root.value?.requestFullscreen?.();
|
|
231
|
-
}
|
|
481
|
+
// Full screen is the page header's one button (BuildingMap), which full-screens `root` while editing.
|
|
232
482
|
defineExpose({ root });
|
|
233
483
|
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { computed, ref, watch, type Ref } from "vue";
|
|
1
|
+
import { computed, onBeforeUnmount, ref, watch, type Ref } from "vue";
|
|
2
|
+
import { hasFleetRobots, isFleetBuilding } from "../utils/robot-fleet-core";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* One site's building for the HERO building map and lift queue: the robots
|
|
@@ -7,6 +8,10 @@ import { computed, ref, watch, type Ref } from "vue";
|
|
|
7
8
|
* SITE (`/building-maps?site=`), whichever robot type it was saved from: the
|
|
8
9
|
* building belongs to the site, so a map drawn in Hygiene shows in Security.
|
|
9
10
|
*
|
|
11
|
+
* A site with HERO Fleet Core robots draws the FLEET building instead (read
|
|
12
|
+
* through from the fleet server, in the same plan frame as those robots,
|
|
13
|
+
* read-only), refreshed every 5 s so doors and lifts move.
|
|
14
|
+
*
|
|
10
15
|
* ponytail: the first 50 robots at the site; the map read is one call.
|
|
11
16
|
*/
|
|
12
17
|
export default function useRobotBuilding(
|
|
@@ -14,7 +19,7 @@ export default function useRobotBuilding(
|
|
|
14
19
|
site: Ref<string>,
|
|
15
20
|
type: Ref<"cleaning" | "security">,
|
|
16
21
|
) {
|
|
17
|
-
const { getSiteFleet, getSiteSummary, listSiteBuildingMaps, getBuildingMap } = useRobots();
|
|
22
|
+
const { getSiteFleet, getSiteSummary, listSiteBuildingMaps, getBuildingMap, getFleetCoreBuilding } = useRobots();
|
|
18
23
|
|
|
19
24
|
/** Every robot at the site this app may see, both types where the app shows both. */
|
|
20
25
|
const all = ref<Array<Record<string, any>>>([]);
|
|
@@ -27,10 +32,24 @@ export default function useRobotBuilding(
|
|
|
27
32
|
const rows = computed(() => all.value.filter((r) => r.type === type.value));
|
|
28
33
|
|
|
29
34
|
async function loadMap() {
|
|
35
|
+
if (hasFleetRobots(all.value)) {
|
|
36
|
+
const building = await getFleetCoreBuilding(site.value).catch(() => null);
|
|
37
|
+
if (building) return building;
|
|
38
|
+
}
|
|
30
39
|
const newest = (await listSiteBuildingMaps(site.value, { limit: 1 }))?.items?.[0];
|
|
31
40
|
return newest ? await getBuildingMap(String(newest._id)) : null;
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
/** Live doors and lifts of the fleet building; a failed refresh keeps the last reading. */
|
|
44
|
+
const fleet = computed(() => isFleetBuilding(map.value));
|
|
45
|
+
const timer = setInterval(async () => {
|
|
46
|
+
if (!fleet.value || (typeof document !== "undefined" && document.visibilityState === "hidden")) return;
|
|
47
|
+
const mine = run;
|
|
48
|
+
const next = await getFleetCoreBuilding(site.value).catch(() => null);
|
|
49
|
+
if (next && mine === run) map.value = next;
|
|
50
|
+
}, 5000);
|
|
51
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
52
|
+
|
|
34
53
|
let run = 0;
|
|
35
54
|
async function load() {
|
|
36
55
|
const mine = ++run;
|
|
@@ -59,5 +78,5 @@ export default function useRobotBuilding(
|
|
|
59
78
|
|
|
60
79
|
watch([organization, site], load, { immediate: true });
|
|
61
80
|
|
|
62
|
-
return { all, rows, map, names, loading, error, reload: load };
|
|
81
|
+
return { all, rows, map, fleet, names, loading, error, reload: load };
|
|
63
82
|
}
|
package/composables/useRobots.ts
CHANGED
|
@@ -293,6 +293,18 @@ export default function useRobots() {
|
|
|
293
293
|
});
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
/**
|
|
297
|
+
* The HERO Fleet Core building at a site: levels, walls, doors, lifts (in the
|
|
298
|
+
* HERO plan frame) with live door and lift states, read through from the
|
|
299
|
+
* fleet server - nothing stored. 404 where the server has no fleet.
|
|
300
|
+
*/
|
|
301
|
+
function getFleetCoreBuilding(site: string) {
|
|
302
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/fleet-core/building", {
|
|
303
|
+
method: "GET",
|
|
304
|
+
query: { site, appSlug },
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
296
308
|
/* ------------------------------------------ alerts + activity log */
|
|
297
309
|
|
|
298
310
|
/**
|
|
@@ -394,6 +406,7 @@ export default function useRobots() {
|
|
|
394
406
|
return {
|
|
395
407
|
listBuildingMaps,
|
|
396
408
|
listSiteBuildingMaps,
|
|
409
|
+
getFleetCoreBuilding,
|
|
397
410
|
getSiteFaults,
|
|
398
411
|
getSiteActivity,
|
|
399
412
|
getNetworkActivity,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.35.1-staging.
|
|
5
|
+
"version": "4.35.1-staging.372",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build": "nuxt build .playground",
|
|
37
37
|
"generate": "nuxt generate .playground",
|
|
38
38
|
"preview": "nuxt preview .playground",
|
|
39
|
-
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
39
|
+
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && esbuild utils/robot-fleet-core.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-fleet-core.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
40
40
|
"test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
|
|
41
41
|
"release": "yarn run build && changeset publish"
|
|
42
42
|
},
|