@7365admin1/layer-common 4.30.0 → 4.32.0

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.
@@ -0,0 +1,247 @@
1
+ <template>
2
+ <!--
3
+ LIFT QUEUE (README §5): one card per lift on the site's building map -
4
+ header "Lift 1 · 1 riding · 2 waiting" and the car's status, an animated
5
+ shaft (floor rails, waiting robots blinking at their floor, the car moving
6
+ between floors with its doors), and the rows: n · robot · from → to ·
7
+ wait · state. Read from the lift-sessions API every 3 s; the car is
8
+ SIMULATED until a lift driver exists (said on the card).
9
+ -->
10
+ <div class="hero-head">
11
+ <div>
12
+ <button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
13
+ <div class="hero-kicker hero-kicker--accent">{{ kicker }}</div>
14
+ <h2 class="hero-title">Lift queue</h2>
15
+ </div>
16
+ </div>
17
+
18
+ <div v-if="error" class="hero-notice" role="alert">{{ error }}</div>
19
+ <div v-else-if="!connected" class="hero-notice" role="status">Reconnecting… the lift queue shows its last reading.</div>
20
+
21
+ <div v-if="loading && !cards.length" class="hero-lifts" role="status" aria-label="Loading the lift queue">
22
+ <div v-for="i in 2" :key="i" class="hero-lift hero-lift--skel"><span class="hero-skel__row" /><span class="hero-skel__row" /><span class="hero-skel__row" /></div>
23
+ </div>
24
+ <div v-else-if="!cards.length && !error && connected" class="hero-notice hero-notice--panel">
25
+ <div class="hero-notice__title">No lifts on this building map yet.</div>
26
+ <div class="hero-notice__body">
27
+ {{ canEditMap ? "Add a lift shaft on Building map → Edit map; robots that change floors queue here." : "A manager adds lift shafts on the building map; robots that change floors queue here." }}
28
+ </div>
29
+ </div>
30
+
31
+ <div v-else class="hero-lifts">
32
+ <div v-for="l in cards" :key="l.name" class="hero-lift">
33
+ <div class="hero-lift__head">
34
+ <span class="hero-lift__name">{{ l.name }}</span>
35
+ <span class="hero-lift__sub">{{ l.sub }}</span>
36
+ <span class="hero-lift__car"><span class="hero-lift__cardot" :class="[`hero-lift__cardot--${l.carTone}`, { 'hero-lift__cardot--blink': l.riding }]" aria-hidden="true" />{{ l.carText }}</span>
37
+ </div>
38
+
39
+ <div class="hero-lift__shaft" :style="{ height: `${l.shaftH}px` }" :title="l.simulated ? 'Simulated lift - no real lift is controlled yet' : undefined">
40
+ <div class="hero-lift__labels">
41
+ <div v-for="f in l.rails" :key="f.floorNo" class="hero-lift__floor" :class="{ 'hero-lift__floor--lit': f.lit }" :style="{ top: `${f.top}px` }">
42
+ <span class="hero-lift__floorname">{{ f.name }}</span>
43
+ <span v-for="w in f.waiting" :key="w" class="hero-lift__waiting" :title="w" />
44
+ </div>
45
+ </div>
46
+ <div class="hero-lift__well">
47
+ <div v-for="f in l.rails" :key="f.floorNo" class="hero-lift__rail" :style="{ top: `${f.top}px` }" />
48
+ <div class="hero-lift__flow" :style="{ opacity: l.riding ? 1 : 0 }" />
49
+ <div
50
+ class="hero-lift__carbox"
51
+ :class="`hero-lift__carbox--${l.carTone}`"
52
+ :style="{ height: `${l.carH}px`, top: `${l.fromTop}px`, '--from': `${l.fromTop}px`, '--to': `${l.toTop}px`, animation: l.riding ? 'heroLift 6s ease-in-out infinite alternate' : 'none' }"
53
+ >
54
+ <span class="hero-lift__carlabel">{{ l.carLabel }}</span>
55
+ <div class="hero-lift__doors" :style="{ animation: l.riding ? 'heroDoors 6s ease-in-out infinite' : 'none' }" />
56
+ </div>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="hero-lift__rows">
61
+ <div v-if="l.empty" class="hero-lift__empty">No robots using this lift.</div>
62
+ <div v-else class="hero-lift__list">
63
+ <div
64
+ v-for="q in l.rows"
65
+ :key="q.key"
66
+ class="hero-lift-row hero-lift-row--click"
67
+ :class="{ 'hero-lift-row--act': canCommand }"
68
+ role="button"
69
+ tabindex="0"
70
+ @click="q.robotId && emit('open', q.robotId)"
71
+ @keydown.enter="q.robotId && emit('open', q.robotId)"
72
+ >
73
+ <span class="hero-lift-row__n">{{ q.n }}</span>
74
+ <div class="hero-lift-row__who"><b>{{ q.robot }}</b><span class="hero-lift-row__route"> · {{ q.from }} → {{ q.to }}</span></div>
75
+ <span class="hero-lift-row__wait">{{ q.wait }}</span>
76
+ <span class="hero-chip" :class="`hero-tone--${liftState(q.state).tone}`">{{ liftState(q.state).label }}</span>
77
+ <button
78
+ v-if="canCommand"
79
+ type="button"
80
+ class="hero-lift-row__release"
81
+ :style="{ visibility: q.state === 'riding' || q.state === 'requested' ? 'visible' : 'hidden' }"
82
+ :disabled="busy === q.key"
83
+ @click.stop="release(q)"
84
+ >
85
+ {{ q.state === "riding" ? "Release" : "Leave queue" }}
86
+ </button>
87
+ <span v-if="liftState(q.state).stripe !== 'none'" class="hero-lift-row__stripe" :class="`hero-lift-row__stripe--${liftState(q.state).stripe}`" aria-hidden="true" />
88
+ </div>
89
+ </div>
90
+
91
+ <form v-if="canCommand && demoRobots.length" class="hero-lift__ask" @submit.prevent="ask(l)">
92
+ <select v-model="askRobot[l.name]" class="hero-input hero-select hero-select--sm" aria-label="Robot">
93
+ <option value="" disabled>Robot</option>
94
+ <option v-for="r in demoRobots" :key="String(r._id)" :value="String(r._id)">{{ r.name }}</option>
95
+ </select>
96
+ <select v-model.number="askFrom[l.name]" class="hero-input hero-select hero-select--sm" aria-label="From floor">
97
+ <option v-for="f in l.rails.map((x) => x.floorNo).slice().reverse()" :key="f" :value="f">{{ floorName(f) }}</option>
98
+ </select>
99
+ <span class="hero-muted">→</span>
100
+ <select v-model.number="askTo[l.name]" class="hero-input hero-select hero-select--sm" aria-label="To floor">
101
+ <option v-for="f in l.rails.map((x) => x.floorNo).slice().reverse()" :key="f" :value="f">{{ floorName(f) }}</option>
102
+ </select>
103
+ <v-btn type="submit" variant="outlined" size="small" :loading="busy === l.name" :disabled="!askRobot[l.name]">Request lift</v-btn>
104
+ <span class="hero-muted hero-lift__simnote">Demo robots only · simulated lift</span>
105
+ </form>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ <RobotToast v-model="toast" />
110
+ </template>
111
+
112
+ <script setup lang="ts">
113
+ import { computed, onBeforeUnmount, ref, toRef, watch } from "vue";
114
+ import RobotToast from "./Toast.vue";
115
+ import useRobotBuilding from "../../composables/useRobotBuilding";
116
+ import { floorName, liftState, robotErrorMessage } from "../../utils/robot-display";
117
+ import { liftCard, type TLiftRowView } from "../../utils/robot-building";
118
+
119
+ const props = withDefaults(
120
+ defineProps<{
121
+ organization: string;
122
+ site: string;
123
+ siteName?: string;
124
+ clientName?: string;
125
+ type?: "cleaning" | "security";
126
+ /** Request / release a lift for a demo robot (the update-robot grant). */
127
+ canCommand?: boolean;
128
+ canEditMap?: boolean;
129
+ backToNetwork?: boolean;
130
+ pollMs?: number;
131
+ }>(),
132
+ { siteName: "", clientName: "", type: "cleaning", canCommand: false, canEditMap: false, backToNetwork: false, pollMs: 3000 },
133
+ );
134
+ const emit = defineEmits<{
135
+ open: [id: string];
136
+ network: [];
137
+ status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
138
+ }>();
139
+
140
+ const { rows, map, names, loading: mapLoading, error: mapError } = useRobotBuilding(
141
+ toRef(props, "organization"),
142
+ toRef(props, "site"),
143
+ toRef(props, "type"),
144
+ );
145
+ const kicker = computed(() => [props.clientName || names.value.clientName, props.siteName || names.value.siteName].filter(Boolean).join(" · "));
146
+ const { getLiftQueue, requestLift, releaseLiftSession } = useRobots();
147
+
148
+ /* ---- the queue, every 3 s while the page is visible ---- */
149
+ const items = ref<Array<Record<string, any>>>([]);
150
+ const connected = ref(true);
151
+ const queueLoading = ref(false);
152
+ const now = ref(Date.now());
153
+ const loading = computed(() => mapLoading.value || queueLoading.value);
154
+ const error = computed(() => mapError.value);
155
+
156
+ async function poll() {
157
+ const id = map.value?._id;
158
+ if (!id) return void (items.value = []);
159
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
160
+ try {
161
+ items.value = (await getLiftQueue(String(id)))?.items ?? [];
162
+ connected.value = true;
163
+ } catch {
164
+ connected.value = false;
165
+ } finally {
166
+ queueLoading.value = false;
167
+ now.value = Date.now();
168
+ }
169
+ }
170
+ let timer: ReturnType<typeof setInterval> | undefined;
171
+ watch(
172
+ () => map.value?._id,
173
+ (id) => {
174
+ clearInterval(timer);
175
+ items.value = [];
176
+ if (!id) return;
177
+ queueLoading.value = true;
178
+ poll();
179
+ timer = setInterval(poll, props.pollMs);
180
+ },
181
+ { immediate: true },
182
+ );
183
+ onBeforeUnmount(() => clearInterval(timer));
184
+
185
+ /**
186
+ * Scope isolation: only robots of the type on screen, that this app may see,
187
+ * are shown riding or waiting; another type's ride leaves the car unlabelled.
188
+ */
189
+ const allowed = computed(() => new Set(rows.value.map((r) => String(r._id))));
190
+ const scoped = (s: any) => s && allowed.value.has(String(s.robotId));
191
+ const cards = computed(() =>
192
+ items.value.map((lift) =>
193
+ liftCard(
194
+ { ...lift, active: scoped(lift.active) ? lift.active : null, queue: (lift.queue ?? []).filter(scoped), recent: (lift.recent ?? []).filter(scoped) },
195
+ now.value,
196
+ ),
197
+ ),
198
+ );
199
+
200
+ /* ---- manager actions: demo robots only (the lift is simulated) ---- */
201
+ const demoRobots = computed(() => rows.value.filter((r) => r.brand === "demo" || r.demo === true));
202
+ const askRobot = ref<Record<string, string>>({});
203
+ const askFrom = ref<Record<string, number>>({});
204
+ const askTo = ref<Record<string, number>>({});
205
+ watch(cards, (list) => {
206
+ for (const l of list) {
207
+ const fl = l.rails.map((x) => x.floorNo);
208
+ if (!(l.name in askFrom.value)) askFrom.value[l.name] = fl[fl.length - 1] ?? 1;
209
+ if (!(l.name in askTo.value)) askTo.value[l.name] = fl[0] ?? 1;
210
+ if (!askRobot.value[l.name] && demoRobots.value[0]) askRobot.value[l.name] = String(demoRobots.value[0]._id);
211
+ }
212
+ });
213
+ const busy = ref("");
214
+ const toast = ref("");
215
+ async function ask(l: { name: string }) {
216
+ const robotId = askRobot.value[l.name];
217
+ if (!robotId || !map.value?._id) return;
218
+ busy.value = l.name;
219
+ try {
220
+ await requestLift(String(map.value._id), l.name, { robotId, fromFloor: askFrom.value[l.name]!, toFloor: askTo.value[l.name]! });
221
+ toast.value = `Lift requested → ${rows.value.find((r) => String(r._id) === robotId)?.name ?? "robot"}`;
222
+ await poll();
223
+ } catch (e) {
224
+ toast.value = robotErrorMessage(e, "The lift could not be requested.");
225
+ } finally {
226
+ busy.value = "";
227
+ }
228
+ }
229
+ async function release(q: TLiftRowView) {
230
+ busy.value = q.key;
231
+ try {
232
+ await releaseLiftSession(q.key);
233
+ toast.value = q.state === "riding" ? `Lift released · ${q.robot}` : `${q.robot} left the queue`;
234
+ await poll();
235
+ } catch (e) {
236
+ toast.value = robotErrorMessage(e, "The lift could not be released.");
237
+ } finally {
238
+ busy.value = "";
239
+ }
240
+ }
241
+
242
+ watch(
243
+ [connected, () => rows.value.filter((r) => r.fault).length, () => names.value.siteName, () => names.value.clientName],
244
+ ([up, faults, siteName, clientName]) => emit("status", { connected: up, faults, siteName, clientName }),
245
+ { immediate: true },
246
+ );
247
+ </script>
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <!--
3
+ Robot detail's live position / spot-clean plan (README §3): the robot as a
4
+ 16px square with a rotating radar sweep and a ping ring, its name + status
5
+ tag, a fading breadcrumb trail (last 14), dashed crosshair lines that
6
+ follow it and the telemetry readout. Security: its dashed route, numbered
7
+ checkpoints (the one it is heading for filled) and the route tag. Spot
8
+ clean: each click adds a numbered point. "Reconnecting…" when the position
9
+ is lost - never a frozen dot.
10
+ -->
11
+ <RobotFloorPlan detail :pick="pick" @pick="emit('pick', $event)">
12
+ <RobotPatrolRoutes v-if="route" :routes="[route]" :animate="routeMoving" large />
13
+ <template v-if="point">
14
+ <span v-for="t in trailDots(trail)" :key="t.key" class="hero-trail" :style="{ left: t.left, top: t.top, opacity: t.op }" aria-hidden="true" />
15
+ <span class="hero-cross hero-cross--h" :style="{ top: point.top, transition: `top ${tickMs}ms linear` }" aria-hidden="true" />
16
+ <span class="hero-cross hero-cross--v" :style="{ left: point.left, transition: `left ${tickMs}ms linear` }" aria-hidden="true" />
17
+ <div class="hero-readout">{{ readout }}</div>
18
+ <div class="hero-me" :style="{ left: point.left, top: point.top, transition: `left ${tickMs}ms linear, top ${tickMs}ms linear` }">
19
+ <div class="hero-me__tag">{{ name }} <span>{{ statusLabel }}</span></div>
20
+ <div class="hero-me__radar" aria-hidden="true" />
21
+ <div class="hero-me__ping" aria-hidden="true" />
22
+ <div class="hero-me__body" :style="{ transform: `rotate(${heading}deg)` }" aria-hidden="true"><div class="hero-me__tick" /></div>
23
+ </div>
24
+ </template>
25
+ <RobotReconnecting v-if="lost" />
26
+ <div v-for="(p, i) in spot" :key="i" class="hero-spot" :style="{ left: `${p.x}%`, top: `${p.y}%` }">{{ i + 1 }}</div>
27
+ </RobotFloorPlan>
28
+ </template>
29
+
30
+ <script setup lang="ts">
31
+ import RobotFloorPlan from "./FloorPlan.vue";
32
+ import RobotPatrolRoutes from "./PatrolRoutes.vue";
33
+ import RobotReconnecting from "./Reconnecting.vue";
34
+ import { trailDots, type TPatrolRouteView } from "../../utils/robot-display";
35
+
36
+ withDefaults(
37
+ defineProps<{
38
+ name?: string;
39
+ statusLabel?: string;
40
+ /** Where the robot is ({ left, top } in %), or null when it is not live on this plan. */
41
+ point?: { left: string; top: string } | null;
42
+ heading?: number;
43
+ trail?: Array<{ x: number; y: number }>;
44
+ /** "x 17.9 · y 34.1 · 53° · 0.4 m/s". */
45
+ readout?: string;
46
+ /** Position lost: "Reconnecting…" over the plan. */
47
+ lost?: boolean;
48
+ route?: TPatrolRouteView | null;
49
+ /** The route's dash walks only while the robot patrols. */
50
+ routeMoving?: boolean;
51
+ /** Spot-clean points (0-100 shares) and whether clicks add them. */
52
+ spot?: Array<{ x: number; y: number }>;
53
+ pick?: boolean;
54
+ tickMs?: number;
55
+ }>(),
56
+ { name: "", statusLabel: "", point: null, heading: 0, trail: () => [], readout: "", lost: false, route: null, routeMoving: false, spot: () => [], pick: false, tickMs: 1200 },
57
+ );
58
+ const emit = defineEmits<{ pick: [point: { x: number; y: number }] }>();
59
+ </script>
@@ -0,0 +1,233 @@
1
+ <template>
2
+ <!--
3
+ Map editor (README §4 "Edit mode"): Wall · Zone · Door · Lift shaft · Move
4
+ · Delete | Undo ⌃Z | Save, one floor at a time on a flat 2D plan. A click
5
+ places the tool's shape; Move = click a shape, then its destination;
6
+ Delete = click a shape. Keyboard: Tab to the plan, arrows move the
7
+ cursor, Enter places. Save checks in plain words first, then writes the
8
+ building map through the API (versioned; a stale save is refused).
9
+ -->
10
+ <div ref="root" class="hero-editor" :class="{ 'hero-editor--fs': isFs }">
11
+ <div class="hero-editor__bar">
12
+ <div class="hero-seg" role="toolbar" aria-label="Map editor tools">
13
+ <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" @click="state = editorReduce(state, { type: 'undo' })">Undo <span class="hero-seg__kbd">⌃Z</span></button>
15
+ <button type="button" class="hero-seg__opt hero-seg__opt--save" :disabled="saving" @click="save">{{ saving ? "Saving…" : "Save" }}</button>
16
+ </div>
17
+ <select v-model.number="floor" class="hero-input hero-select hero-editor__floor" aria-label="Floor">
18
+ <option v-for="f in floors" :key="f" :value="f">{{ floorName(f) }}</option>
19
+ </select>
20
+ <input
21
+ v-if="tool === 'zone'"
22
+ v-model="zoneName"
23
+ class="hero-input hero-editor__zone"
24
+ aria-label="Zone name"
25
+ placeholder="Zone name (required to save)"
26
+ @input="state = editorReduce(state, { type: 'rename', name: zoneName })"
27
+ />
28
+ <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
+ </div>
34
+
35
+ <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>
36
+
37
+ <div class="hero-editor__split">
38
+ <div
39
+ ref="plan"
40
+ class="hero-editor__plan"
41
+ tabindex="0"
42
+ role="application"
43
+ :aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor, Enter places.`"
44
+ @click="onPlanClick"
45
+ @keydown="onKey"
46
+ @blur="keyboard = false"
47
+ >
48
+ <span class="hero-editor__room" style="left: 8%; top: 10%; width: 34%; height: 30%" aria-hidden="true" />
49
+ <span class="hero-editor__room" style="left: 58%; top: 10%; width: 34%; height: 44%" aria-hidden="true" />
50
+ <span class="hero-editor__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
51
+ <svg class="hero-editor__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
52
+ <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': state.moving === s.id }" :points="pts(s)" vector-effect="non-scaling-stroke" />
54
+ <line v-else-if="s.kind === 'wall'" class="hero-editor__wall" :class="{ 'hero-editor__sel': state.moving === s.id }" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" />
55
+ </template>
56
+ </svg>
57
+ <template v-for="s in visible" :key="`l-${s.id}`">
58
+ <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': state.moving === s.id }" :style="boxStyle(s)" :title="shapeTitle(s)">Lift</div>
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)" />
61
+ </template>
62
+ <span v-if="keyboard" class="hero-editor__cursor" :style="{ left: `${cursor.x}%`, top: `${cursor.y}%` }" aria-hidden="true" />
63
+ </div>
64
+
65
+ <aside class="hero-editor__aside">
66
+ <div class="hero-aside__title hero-editor__asidetitle">On {{ floorName(floor) }}</div>
67
+ <div v-for="s in visible" :key="`r-${s.id}`" class="hero-editor__row">
68
+ <span>{{ shapeTitle(s) }}</span><span class="hero-editor__pos">{{ shapeAnchor(s).x }}, {{ shapeAnchor(s).y }}</span>
69
+ </div>
70
+ <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, arrow keys move the cursor, Enter places.</div>
72
+ </aside>
73
+ </div>
74
+ </div>
75
+ </template>
76
+
77
+ <script setup lang="ts">
78
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
79
+ import { floorName, MAP_TOOLS } from "../../utils/robot-display";
80
+ import {
81
+ editorProblem,
82
+ editorReduce,
83
+ emptyEditor,
84
+ saveErrorText,
85
+ savedNotice,
86
+ shapeAnchor,
87
+ shapeBox,
88
+ shapesFromMap,
89
+ shapesOnFloor,
90
+ shapeTitle,
91
+ toMapBody,
92
+ TOOL_HINTS,
93
+ type TEditorShape,
94
+ type TEditorState,
95
+ type TEditorTool,
96
+ } from "../../utils/robot-building";
97
+
98
+ const props = withDefaults(
99
+ defineProps<{
100
+ /** The site's saved building map, or null (the first save creates it). */
101
+ map?: Record<string, any> | null;
102
+ floors: number[];
103
+ siteName?: string;
104
+ /** The robot a first save is attached to - maps are stored per robot. */
105
+ ownerRobotId?: string;
106
+ /** The floor to open on. */
107
+ startFloor?: number | null;
108
+ }>(),
109
+ { map: null, siteName: "", ownerRobotId: "", startFloor: null },
110
+ );
111
+ const emit = defineEmits<{ saved: [] }>();
112
+ const { createBuildingMap, updateBuildingMap } = useRobots();
113
+
114
+ const state = ref<TEditorState>(emptyEditor(shapesFromMap(props.map)));
115
+ /** A newer map (after our own save, or another tab's) replaces the shapes only while nothing is unsaved. */
116
+ watch(
117
+ () => props.map,
118
+ (m) => {
119
+ if (!state.value.dirty) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
120
+ },
121
+ );
122
+
123
+ const tool = ref<TEditorTool>("wall");
124
+ const zoneName = ref("");
125
+ const floor = ref<number>(props.startFloor !== null && props.floors.includes(props.startFloor) ? props.startFloor : props.floors[0] ?? 1);
126
+ watch(() => props.floors, (f) => {
127
+ if (!f.includes(floor.value)) floor.value = f[0] ?? 1;
128
+ });
129
+ const visible = computed(() => shapesOnFloor(state.value.shapes, floor.value));
130
+
131
+ function pickTool(id: TEditorTool) {
132
+ tool.value = id;
133
+ state.value = editorReduce(state.value, { type: "tool" });
134
+ }
135
+
136
+ /* ---- the plan: a click (or Enter at the keyboard cursor) ---- */
137
+ const plan = ref<HTMLElement | null>(null);
138
+ const cursor = ref({ x: 50, y: 50 });
139
+ const keyboard = ref(false);
140
+
141
+ /** The topmost shape under a point (walls and doors get a little slack). */
142
+ function hit(x: number, y: number): TEditorShape | null {
143
+ for (const s of [...visible.value].reverse()) {
144
+ const b = shapeBox(s);
145
+ const pad = s.kind === "wall" || s.kind === "door" ? 1.8 : 0;
146
+ if (x >= b.x - pad && x <= b.x + b.w + pad && y >= b.y - pad && y <= b.y + b.h + pad) return s;
147
+ }
148
+ return null;
149
+ }
150
+ function act(x: number, y: number) {
151
+ const target = hit(x, y);
152
+ // Move with a shape picked: this point is its destination, even over another shape.
153
+ if (target && !(tool.value === "move" && state.value.moving)) {
154
+ state.value = editorReduce(state.value, { type: "pick", id: target.id, tool: tool.value, zoneName: zoneName.value });
155
+ if (tool.value === "move" && target.kind === "zone") zoneName.value = target.name ?? "";
156
+ return;
157
+ }
158
+ state.value = editorReduce(state.value, { type: "place", tool: tool.value, floorNo: floor.value, x, y, zoneName: zoneName.value, floors: props.floors });
159
+ }
160
+ function onPlanClick(e: MouseEvent) {
161
+ const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
162
+ const clamp = (v: number) => Math.max(0, Math.min(98, v));
163
+ act(clamp(((e.clientX - r.left) / r.width) * 100), clamp(((e.clientY - r.top) / r.height) * 100));
164
+ }
165
+ function onKey(e: KeyboardEvent) {
166
+ const step = e.shiftKey ? 10 : 2;
167
+ const move: Record<string, [number, number]> = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };
168
+ if (move[e.key]) {
169
+ e.preventDefault();
170
+ keyboard.value = true;
171
+ const [dx, dy] = move[e.key]!;
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 (e.key === "Enter" || e.key === " ") {
174
+ e.preventDefault();
175
+ keyboard.value = true;
176
+ act(cursor.value.x, cursor.value.y);
177
+ }
178
+ }
179
+
180
+ /** Ctrl/Cmd+Z anywhere in the editor except while typing a name. */
181
+ function onUndoKey(e: KeyboardEvent) {
182
+ if (!(e.ctrlKey || e.metaKey) || e.key.toLowerCase() !== "z" || e.shiftKey) return;
183
+ if ((e.target as HTMLElement)?.tagName === "INPUT") return;
184
+ e.preventDefault();
185
+ state.value = editorReduce(state.value, { type: "undo" });
186
+ }
187
+ onMounted(() => window.addEventListener("keydown", onUndoKey));
188
+ onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
189
+
190
+ /* ---- save ---- */
191
+ const saving = ref(false);
192
+ async function save() {
193
+ const problem = editorProblem(state.value);
194
+ if (problem) return void (state.value = editorReduce(state.value, { type: "notice", text: problem, ok: false }));
195
+ if (!props.map?._id && !props.ownerRobotId) {
196
+ return void (state.value = editorReduce(state.value, {
197
+ type: "notice",
198
+ 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
+ ok: false,
200
+ }));
201
+ }
202
+ const name = String(props.map?.name || `${props.siteName || "Site"} building`).slice(0, 60);
203
+ const body = toMapBody(state.value.shapes, name, props.map);
204
+ saving.value = true;
205
+ try {
206
+ if (props.map?._id) await updateBuildingMap(String(props.map._id), { ...body, version: Number(props.map.version) || 1 });
207
+ else await createBuildingMap({ ...body, robotId: props.ownerRobotId });
208
+ state.value = editorReduce(state.value, { type: "saved", text: savedNotice(new Date(), state.value.shapes.length, props.siteName) });
209
+ emit("saved");
210
+ } catch (e) {
211
+ state.value = editorReduce(state.value, { type: "notice", text: saveErrorText(e), ok: false });
212
+ } finally {
213
+ saving.value = false;
214
+ }
215
+ }
216
+
217
+ /* ---- drawing helpers + full screen ---- */
218
+ const pts = (s: TEditorShape) => s.points.map((p) => `${p.x},${p.y}`).join(" ");
219
+ function boxStyle(s: TEditorShape) {
220
+ const b = shapeBox(s);
221
+ return { left: `${b.x}%`, top: `${b.y}%`, width: `${b.w}%`, height: `${b.h}%` };
222
+ }
223
+ const root = ref<HTMLElement | null>(null);
224
+ const isFs = ref(false);
225
+ const onFs = () => (isFs.value = document.fullscreenElement === root.value);
226
+ onMounted(() => document.addEventListener("fullscreenchange", onFs));
227
+ onBeforeUnmount(() => document.removeEventListener("fullscreenchange", onFs));
228
+ function fullscreen() {
229
+ if (document.fullscreenElement) document.exitFullscreen?.();
230
+ else root.value?.requestFullscreen?.();
231
+ }
232
+ defineExpose({ root });
233
+ </script>
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <!-- The HERO mark: the robot head, outline + red eye (from the supplied logo; swap for the official vector when it exists). -->
3
+ <svg :width="size" :height="size" viewBox="0 0 100 100" fill="none" stroke="currentColor" stroke-width="5" stroke-linejoin="round" aria-hidden="true">
4
+ <path d="M32 10h36l14 12v40l-14 22H32L18 62V22z" />
5
+ <rect x="27" y="24" width="46" height="34" />
6
+ <path d="M34 64h32v12H34z" />
7
+ <path d="M8 30h8v30H8zM84 30h8v30h-8z" />
8
+ <g fill="var(--hero-accent)" stroke="none">
9
+ <circle cx="50" cy="41" r="8" />
10
+ <path d="M30 38h12l-2 6H30zM58 38h12v6H60z" />
11
+ </g>
12
+ </svg>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ withDefaults(defineProps<{ size?: number }>(), { size: 30 });
17
+ </script>