@7365admin1/layer-common 4.35.0 → 4.35.1-staging.371

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/assets/css/robot-hero.css +40 -3
  3. package/components/AccessCardAddForm.vue +5 -4
  4. package/components/AccessCardAssignToUnitForm.vue +3 -2
  5. package/components/AccessCardPreviewDialog.vue +4 -3
  6. package/components/Dialog/UpdateMoreAction.vue +11 -1
  7. package/components/DocumentForm.vue +407 -112
  8. package/components/DocumentManagement.vue +213 -12
  9. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  10. package/components/EntryPassInformation.vue +119 -24
  11. package/components/Facility/BookingSetup.vue +63 -0
  12. package/components/HidAccessLogDashboard.vue +41 -8
  13. package/components/HidAccessPermissions.vue +424 -0
  14. package/components/HidIntercomManagement.vue +148 -14
  15. package/components/HidProfileQrCode.vue +332 -0
  16. package/components/HidQrCodeConfiguration.vue +17 -195
  17. package/components/HidReaderManagement.vue +306 -0
  18. package/components/HidReaderUserRoster.vue +44 -3
  19. package/components/HidUserEnrollment.vue +845 -155
  20. package/components/InvitationClientForm.vue +19 -1
  21. package/components/Robot/MapEditor.vue +313 -56
  22. package/components/VisitorForm.vue +12 -0
  23. package/components/VisitorManagement.vue +267 -5
  24. package/composables/useAccessManagement.ts +5 -0
  25. package/composables/useDocument.ts +7 -0
  26. package/composables/useFacility.ts +11 -0
  27. package/composables/useHidAmico.ts +134 -0
  28. package/composables/useHidNavigation.ts +25 -1
  29. package/composables/useHidReaderSelection.ts +50 -0
  30. package/composables/usePeople.ts +19 -0
  31. package/composables/usePropertyPermission.ts +17 -0
  32. package/composables/useSecurityPermission.ts +19 -0
  33. package/composables/useSiteCategory.ts +45 -0
  34. package/composables/useSiteEntryPassSettings.ts +26 -0
  35. package/composables/useWebUsb.ts +14 -11
  36. package/package.json +1 -1
  37. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  38. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  39. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  40. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  41. package/plugins/API.ts +11 -0
  42. package/types/document.d.ts +14 -0
  43. package/types/facility.d.ts +4 -0
  44. package/types/people.d.ts +28 -1
  45. package/utils/hid-permission-assignments.ts +190 -0
  46. package/utils/hid-reader-selection.ts +52 -0
  47. package/utils/occupancy-role.ts +109 -0
  48. package/utils/robot-building.ts +472 -36
@@ -388,9 +388,27 @@ watch(
388
388
  const roles = ref<any[]>([])
389
389
  const { getRoles } = useRole()
390
390
 
391
+ /*
392
+ * `type` is the ROLE type, not the service the client subscribes to, and the
393
+ * only caller (`ClientMain.vue` "Invite Client") passes no `app` prop -- so
394
+ * this sent `type: ""` and the endpoint applied no type filter at all. The
395
+ * dropdown therefore listed every org-less role of every type, which includes
396
+ * the platform's OWN staff roles (`type: "admin"` -- the two rows the console's
397
+ * `/super-admin/role-permissions` screen edits). Offering a Seven365 console
398
+ * staff role on a CLIENT invitation is the defect.
399
+ *
400
+ * A client admin's role is `type: "organization"`, which is what the client
401
+ * roles screen (`org/[organization]/roles-permissions.vue`) already lists. This
402
+ * narrows to exactly that. It is a narrowing of this one picker only: no role
403
+ * changes, no permission changes, and the org-less `organization` roles that
404
+ * were already being picked are all still offered.
405
+ *
406
+ * Keying off the selected service instead would empty the dropdown -- no
407
+ * org-less role carries a service type -- so `props.app` is not the filter.
408
+ */
391
409
  const { data: roleData, refresh: refreshRoles } = await useLazyAsyncData(
392
410
  "roles",
393
- () => getRoles({ org: org.value?._id, type: props.app, limit: 50 }),
411
+ () => getRoles({ org: org.value?._id, type: "organization", limit: 50 }),
394
412
  { watch: [() => props.app] }
395
413
  )
396
414
 
@@ -1,29 +1,41 @@
1
1
  <template>
2
2
  <!--
3
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).
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" @click="state = editorReduce(state, { type: 'undo' })">Undo <span class="hero-seg__kbd">⌃Z</span></button>
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="state = editorReduce(state, { type: 'rename', name: zoneName })"
38
+ @input="dispatch({ type: 'rename', name: zoneName })"
27
39
  />
28
40
  <span class="hero-editor__hint">{{ TOOL_HINTS[tool] }}</span>
29
41
  <v-btn variant="outlined" class="hero-editor__fs" @click="fullscreen">
@@ -38,10 +50,16 @@
38
50
  <div
39
51
  ref="plan"
40
52
  class="hero-editor__plan"
53
+ :class="`hero-editor__plan--${planCursor}`"
54
+ :style="gridStyle"
41
55
  tabindex="0"
42
56
  role="application"
43
- :aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor, Enter places.`"
44
- @click="onPlanClick"
57
+ :aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor or nudge the selection, Enter places or selects, Delete removes, Escape clears.`"
58
+ @pointerdown="onPlanDown"
59
+ @pointermove="onPointerMove"
60
+ @pointerup="onPointerUp"
61
+ @pointercancel="onPointerCancel"
62
+ @dblclick="onDoubleClick"
45
63
  @keydown="onKey"
46
64
  @blur="keyboard = false"
47
65
  >
@@ -50,25 +68,45 @@
50
68
  <span class="hero-editor__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
51
69
  <svg class="hero-editor__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
52
70
  <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" />
71
+ <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" />
72
+ <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" />
73
+ <template v-else-if="s.kind === 'door'">
74
+ <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" />
75
+ <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" />
76
+ </template>
55
77
  </template>
78
+ <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
79
  </svg>
57
80
  <template v-for="s in visible" :key="`l-${s.id}`">
58
81
  <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)" />
82
+ <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
83
  </template>
84
+ <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)" />
85
+ <span v-if="marquee" class="hero-editor__marquee" :style="rectStyle(marquee)" aria-hidden="true" />
62
86
  <span v-if="keyboard" class="hero-editor__cursor" :style="{ left: `${cursor.x}%`, top: `${cursor.y}%` }" aria-hidden="true" />
63
87
  </div>
64
88
 
65
89
  <aside class="hero-editor__aside">
90
+ <template v-if="selectedShapes.length">
91
+ <div class="hero-aside__title hero-editor__asidetitle">{{ selectedShapes.length === 1 ? shapeTitle(selectedShapes[0]!) : `${selectedShapes.length} selected` }}</div>
92
+ <div class="hero-editor__actions">
93
+ <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>
94
+ <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>
95
+ <template v-if="selectedZone">
96
+ <button type="button" class="hero-editor__act" @click="addCorner">Add corner</button>
97
+ <button type="button" class="hero-editor__act" :disabled="state.vertex?.id !== selectedZone.id || selectedZone.points.length <= 3" @click="dispatch({ type: 'remove' })">Remove corner</button>
98
+ </template>
99
+ <button type="button" class="hero-editor__act hero-editor__act--del" @click="removeSelection">Delete <span class="hero-seg__kbd">Del</span></button>
100
+ </div>
101
+ <div v-if="selectedZone" class="hero-muted">Double-click an edge to add a corner; double-click a corner to remove it.</div>
102
+ <div v-if="selectedShapes.some((s) => s.kind === 'lift')" class="hero-muted">A lift shaft turns a quarter at a time.</div>
103
+ </template>
66
104
  <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">
105
+ <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
106
  <span>{{ shapeTitle(s) }}</span><span class="hero-editor__pos">{{ shapeAnchor(s).x }}, {{ shapeAnchor(s).y }}</span>
69
- </div>
107
+ </button>
70
108
  <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>
109
+ <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
110
  </aside>
73
111
  </div>
74
112
  </div>
@@ -78,21 +116,37 @@
78
116
  import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
79
117
  import { floorName, MAP_TOOLS } from "../../utils/robot-display";
80
118
  import {
119
+ DEFAULT_GRID_M,
120
+ doorSwing,
81
121
  editorProblem,
82
122
  editorReduce,
83
123
  emptyEditor,
124
+ GRID_STEPS_M,
125
+ gridShares,
126
+ hitShape,
127
+ NUDGE_BIG_M,
128
+ NUDGE_M,
129
+ PLAN_H_M,
130
+ PLAN_W_M,
84
131
  saveErrorText,
85
132
  savedNotice,
86
133
  shapeAnchor,
87
134
  shapeBox,
135
+ shapeHandles,
88
136
  shapesFromMap,
137
+ shapesInRect,
89
138
  shapesOnFloor,
90
139
  shapeTitle,
140
+ snapToGrid,
91
141
  toMapBody,
92
142
  TOOL_HINTS,
143
+ turnCentre,
144
+ type TDragOp,
145
+ type TEditorAction,
93
146
  type TEditorShape,
94
147
  type TEditorState,
95
148
  type TEditorTool,
149
+ type TShapeHandle,
96
150
  } from "../../utils/robot-building";
97
151
 
98
152
  const props = withDefaults(
@@ -112,77 +166,277 @@ const emit = defineEmits<{ saved: [] }>();
112
166
  const { createBuildingMap, updateBuildingMap } = useRobots();
113
167
 
114
168
  const state = ref<TEditorState>(emptyEditor(shapesFromMap(props.map)));
169
+ const dispatch = (a: TEditorAction) => (state.value = editorReduce(state.value, a));
115
170
  /** A newer map (after our own save, or another tab's) replaces the shapes only while nothing is unsaved. */
116
171
  watch(
117
172
  () => props.map,
118
173
  (m) => {
119
- if (!state.value.dirty) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
174
+ if (!state.value.dirty && !state.value.drag) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
120
175
  },
121
176
  );
122
177
 
123
178
  const tool = ref<TEditorTool>("wall");
124
179
  const zoneName = ref("");
180
+ const snapOn = ref(true);
181
+ const gridM = ref(DEFAULT_GRID_M);
182
+ const gridStyle = computed(() => {
183
+ const g = gridShares(gridM.value);
184
+ return { backgroundSize: `${g.x}% ${g.y}%` };
185
+ });
125
186
  const floor = ref<number>(props.startFloor !== null && props.floors.includes(props.startFloor) ? props.startFloor : props.floors[0] ?? 1);
126
187
  watch(() => props.floors, (f) => {
127
188
  if (!f.includes(floor.value)) floor.value = f[0] ?? 1;
128
189
  });
190
+ watch(floor, () => dispatch({ type: "select", ids: [] }));
129
191
  const visible = computed(() => shapesOnFloor(state.value.shapes, floor.value));
192
+ const isSel = (id: string) => state.value.selected.includes(id);
193
+ const selectedShapes = computed(() => visible.value.filter((s) => isSel(s.id)));
194
+ const single = computed(() => (selectedShapes.value.length === 1 ? selectedShapes.value[0]! : null));
195
+ const selectedZone = computed(() => (single.value?.kind === "zone" ? single.value : null));
196
+ watch(selectedZone, (z) => {
197
+ if (z) zoneName.value = z.name ?? "";
198
+ });
199
+ const handles = computed<TShapeHandle[]>(() => (single.value ? shapeHandles(single.value) : []));
200
+ const rotateLine = computed(() => {
201
+ const r = handles.value.find((h) => h.kind === "rotate");
202
+ if (!r || !single.value) return null;
203
+ const c = turnCentre(single.value);
204
+ return { x1: c.x, y1: c.y, x2: r.x, y2: r.y };
205
+ });
206
+ const swings = computed(() => Object.fromEntries(visible.value.filter((s) => s.kind === "door").map((s) => [s.id, doorSwing(s)])));
130
207
 
131
208
  function pickTool(id: TEditorTool) {
132
209
  tool.value = id;
133
- state.value = editorReduce(state.value, { type: "tool" });
210
+ dispatch({ type: "tool", tool: id });
134
211
  }
135
212
 
136
- /* ---- the plan: a click (or Enter at the keyboard cursor) ---- */
213
+ /* ---- pointer: mouse, touch and pen alike ---- */
137
214
  const plan = ref<HTMLElement | null>(null);
138
215
  const cursor = ref({ x: 50, y: 50 });
139
216
  const keyboard = ref(false);
217
+ const marquee = ref<{ x: number; y: number; w: number; h: number } | null>(null);
218
+ const hoverId = ref<string | null>(null);
219
+ type TPress = { pointer: number; x: number; y: number; cx: number; cy: number; mode: "drag" | "marquee" | "click"; op?: TDragOp; shift: boolean; started: boolean };
220
+ let press: TPress | null = null;
221
+ /** The cursor a drag in progress shows: move, rotate or a resize direction. */
222
+ const dragKind = ref("");
140
223
 
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;
224
+ function at(e: { clientX: number; clientY: number }) {
225
+ const r = plan.value!.getBoundingClientRect();
226
+ const c = (v: number) => Math.max(0, Math.min(100, v));
227
+ return { x: c(((e.clientX - r.left) / r.width) * 100), y: c(((e.clientY - r.top) / r.height) * 100) };
228
+ }
229
+ /** How near counts as "on" a line or corner: 10 screen pixels (16 for a finger), in metres. */
230
+ function tolerance(pointerType = "mouse") {
231
+ const r = plan.value?.getBoundingClientRect();
232
+ if (!r?.width) return 0.4;
233
+ return Math.max(PLAN_W_M / r.width, PLAN_H_M / r.height) * (pointerType === "touch" ? 16 : 10);
234
+ }
235
+
236
+ function startPress(e: PointerEvent, mode: TPress["mode"], op?: TDragOp) {
237
+ const p = at(e);
238
+ press = { pointer: e.pointerId, x: p.x, y: p.y, cx: e.clientX, cy: e.clientY, mode, op, shift: e.shiftKey, started: false };
239
+ plan.value?.setPointerCapture?.(e.pointerId);
240
+ }
241
+
242
+ function onPlanDown(e: PointerEvent) {
243
+ if (e.pointerType === "mouse" && e.button !== 0) return;
244
+ plan.value?.focus({ preventScroll: true });
245
+ keyboard.value = false;
246
+ const p = at(e);
247
+ const target = hitShape(visible.value, p, tolerance(e.pointerType));
248
+ const t = tool.value;
249
+ if (t === "delete") {
250
+ if (target) dispatch({ type: "pick", id: target.id, tool: "delete" });
251
+ return;
147
252
  }
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 ?? "";
253
+ if (t === "zone" && target?.kind === "zone" && zoneName.value.trim() && !isSel(target.id)) {
254
+ dispatch({ type: "pick", id: target.id, tool: "zone", zoneName: zoneName.value });
156
255
  return;
157
256
  }
158
- state.value = editorReduce(state.value, { type: "place", tool: tool.value, floorNo: floor.value, x, y, zoneName: zoneName.value, floors: props.floors });
257
+ // 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).
258
+ if (t === "move" || target?.kind === t) {
259
+ if (!target) return startPress(e, "marquee");
260
+ if (e.shiftKey) {
261
+ dispatch({ type: "select", ids: [target.id], mode: "toggle" });
262
+ return;
263
+ }
264
+ if (!isSel(target.id)) dispatch({ type: "select", ids: [target.id] });
265
+ return startPress(e, "drag", { kind: "move" });
266
+ }
267
+ // A drawing tool: place (on the grid while snapping), and select the new shape.
268
+ e.preventDefault();
269
+ const q = snapOn.value && !e.shiftKey ? snapToGrid(p, gridM.value) : p;
270
+ 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 });
271
+ }
272
+
273
+ function onHandleDown(e: PointerEvent, h: TShapeHandle) {
274
+ if ((e.pointerType === "mouse" && e.button !== 0) || !single.value) return;
275
+ plan.value?.focus({ preventScroll: true });
276
+ const id = single.value.id;
277
+ const op: TDragOp =
278
+ h.kind === "resize" ? { kind: "handle", id, handle: h.handle! } : h.kind === "vertex" ? { kind: "vertex", id, index: h.index! } : { kind: "rotate", id };
279
+ // Grabbing a zone corner marks it, so Delete / Remove corner acts on it even without a drag.
280
+ if (h.kind === "vertex" && single.value.kind === "zone") state.value = { ...state.value, vertex: { id, index: h.index! } };
281
+ startPress(e, "drag", op);
282
+ }
283
+
284
+ function onPointerMove(e: PointerEvent) {
285
+ if (!press) {
286
+ if (e.pointerType === "mouse") hoverId.value = hitShape(visible.value, at(e), tolerance())?.id ?? null;
287
+ return;
288
+ }
289
+ if (e.pointerId !== press.pointer) return;
290
+ const p = at(e);
291
+ if (!press.started) {
292
+ if (Math.hypot(e.clientX - press.cx, e.clientY - press.cy) < 3) return;
293
+ press.started = true;
294
+ if (press.mode === "drag") {
295
+ dispatch({ type: "dragStart", op: press.op!, x: press.x, y: press.y });
296
+ dragKind.value = press.op!.kind === "rotate" ? "rotate" : press.op!.kind === "handle" ? handleCursor(press.op!.handle) : "move";
297
+ }
298
+ }
299
+ if (press.mode === "drag") {
300
+ const snap = snapOn.value && !e.shiftKey;
301
+ dispatch({ type: "dragMove", x: p.x, y: p.y, grid: snap ? gridM.value : 0, tolerance: snap ? tolerance(e.pointerType) : 0 });
302
+ } else if (press.mode === "marquee") {
303
+ marquee.value = { x: press.x, y: press.y, w: p.x - press.x, h: p.y - press.y };
304
+ }
305
+ }
306
+
307
+ function endPress() {
308
+ if (press) plan.value?.releasePointerCapture?.(press.pointer);
309
+ press = null;
310
+ marquee.value = null;
311
+ dragKind.value = "";
312
+ }
313
+
314
+ function onPointerUp(e: PointerEvent) {
315
+ if (!press || e.pointerId !== press.pointer) return;
316
+ if (press.mode === "drag" && press.started) dispatch({ type: "dragEnd" });
317
+ else if (press.mode === "marquee") {
318
+ if (press.started && marquee.value) dispatch({ type: "select", ids: shapesInRect(visible.value, marquee.value), mode: press.shift ? "add" : "replace" });
319
+ else if (!press.shift) dispatch({ type: "select", ids: [] });
320
+ }
321
+ endPress();
322
+ }
323
+
324
+ function onPointerCancel() {
325
+ if (press?.mode === "drag" && press.started) dispatch({ type: "dragCancel" });
326
+ endPress();
159
327
  }
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));
328
+
329
+ /**
330
+ * Double-click on a selected zone: on a corner removes it, on an edge adds a
331
+ * corner there. (The plan holds the pointer during a press, so the double
332
+ * click always arrives here, even over a handle.)
333
+ */
334
+ function onDoubleClick(e: MouseEvent) {
335
+ const z = selectedZone.value;
336
+ if (!z || tool.value === "delete") return;
337
+ const p = at(e);
338
+ const r = plan.value!.getBoundingClientRect();
339
+ const reach = 14; // px
340
+ const corner = z.points.findIndex((q) => Math.hypot(((q.x - p.x) / 100) * r.width, ((q.y - p.y) / 100) * r.height) <= reach);
341
+ if (corner >= 0) dispatch({ type: "removeVertex", id: z.id, index: corner });
342
+ else dispatch({ type: "addVertex", id: z.id, x: p.x, y: p.y, within: tolerance() * 1.5 });
164
343
  }
344
+
345
+ /** Add corner (button): the middle of the zone's longest edge. */
346
+ function addCorner() {
347
+ const z = selectedZone.value;
348
+ if (!z) return;
349
+ let best = { len: -1, x: 0, y: 0 };
350
+ z.points.forEach((a, i) => {
351
+ const b = z.points[(i + 1) % z.points.length]!;
352
+ const len = Math.hypot((b.x - a.x) * PLAN_W_M, (b.y - a.y) * PLAN_H_M);
353
+ if (len > best.len) best = { len, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
354
+ });
355
+ dispatch({ type: "addVertex", id: z.id, x: best.x, y: best.y });
356
+ }
357
+
358
+ function removeSelection() {
359
+ state.value = { ...state.value, vertex: null };
360
+ dispatch({ type: "remove" });
361
+ }
362
+
363
+ function onRow(e: MouseEvent, s: TEditorShape) {
364
+ if (tool.value !== "move") pickTool("move");
365
+ dispatch({ type: "select", ids: [s.id], mode: e.shiftKey ? "toggle" : "replace" });
366
+ }
367
+
368
+ const handleCursor = (h: string) => (h === "n" || h === "s" ? "ns" : h === "e" || h === "w" ? "ew" : h === "nw" || h === "se" ? "nwse" : "nesw");
369
+ /** The plan's cursor: what a drag is doing, else what a press would do here. */
370
+ const planCursor = computed(() => {
371
+ if (dragKind.value) return dragKind.value;
372
+ if (tool.value === "delete") return hoverId.value ? "pointer" : "default";
373
+ const hover = hoverId.value ? visible.value.find((s) => s.id === hoverId.value) : null;
374
+ if (hover && (tool.value === "move" || hover.kind === tool.value)) return "move";
375
+ return tool.value === "move" ? "default" : "crosshair";
376
+ });
377
+
378
+ /* ---- keyboard ---- */
379
+ function act(x: number, y: number, shift = false) {
380
+ const target = hitShape(visible.value, { x, y }, tolerance());
381
+ const t = tool.value;
382
+ if (t === "delete") return void (target && dispatch({ type: "pick", id: target.id, tool: "delete" }));
383
+ if (t === "zone" && target?.kind === "zone" && zoneName.value.trim() && !isSel(target.id)) {
384
+ return void dispatch({ type: "pick", id: target.id, tool: "zone", zoneName: zoneName.value });
385
+ }
386
+ if (t === "move" || target?.kind === t) {
387
+ if (target) dispatch({ type: "select", ids: [target.id], mode: shift ? "toggle" : "replace" });
388
+ return;
389
+ }
390
+ dispatch({ type: "place", tool: t, floorNo: floor.value, x: Math.min(98, x), y: Math.min(98, y), zoneName: zoneName.value, floors: props.floors });
391
+ }
392
+
165
393
  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]) {
394
+ const k = e.key;
395
+ if (k === "Escape") {
396
+ if (state.value.drag) onPointerCancel();
397
+ else if (state.value.selected.length) dispatch({ type: "select", ids: [] });
398
+ else keyboard.value = false;
399
+ return;
400
+ }
401
+ if (k === "Delete" || k === "Backspace") {
402
+ e.preventDefault();
403
+ return void dispatch({ type: "remove" });
404
+ }
405
+ if ((e.ctrlKey || e.metaKey) && k.toLowerCase() === "a") {
169
406
  e.preventDefault();
407
+ return void dispatch({ type: "selectAll", floorNo: floor.value });
408
+ }
409
+ if (!e.ctrlKey && !e.metaKey && !e.altKey && (k === "f" || k === "F")) return void dispatch({ type: "flip" });
410
+ if (!e.ctrlKey && !e.metaKey && !e.altKey && (k === "r" || k === "R")) return void dispatch({ type: "turn" });
411
+ const dir: Record<string, [number, number]> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] };
412
+ if (dir[k]) {
413
+ e.preventDefault();
414
+ const [dx, dy] = dir[k]!;
415
+ if (state.value.selected.length && !state.value.drag) {
416
+ const m = e.shiftKey ? NUDGE_BIG_M : NUDGE_M;
417
+ return void dispatch({ type: "nudge", dx: dx * m, dy: dy * m });
418
+ }
170
419
  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 === " ") {
420
+ const step = e.shiftKey ? 10 : 2;
421
+ 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)) };
422
+ } else if (k === "Enter" || k === " ") {
174
423
  e.preventDefault();
175
424
  keyboard.value = true;
176
- act(cursor.value.x, cursor.value.y);
425
+ act(cursor.value.x, cursor.value.y, e.shiftKey);
177
426
  }
178
427
  }
179
428
 
180
- /** Ctrl/Cmd+Z anywhere in the editor except while typing a name. */
429
+ /** Ctrl/Cmd+Z undo, Ctrl/Cmd+Shift+Z or Ctrl+Y redo - anywhere in the editor except while typing. */
181
430
  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;
431
+ if (!(e.ctrlKey || e.metaKey)) return;
432
+ const k = e.key.toLowerCase();
433
+ const redo = (k === "z" && e.shiftKey) || (k === "y" && !e.shiftKey);
434
+ if (!(k === "z" && !e.shiftKey) && !redo) return;
435
+ const tag = (e.target as HTMLElement)?.tagName;
436
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
184
437
  e.preventDefault();
185
- state.value = editorReduce(state.value, { type: "undo" });
438
+ if (state.value.drag) return;
439
+ dispatch({ type: redo ? "redo" : "undo" });
186
440
  }
187
441
  onMounted(() => window.addEventListener("keydown", onUndoKey));
188
442
  onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
@@ -191,13 +445,13 @@ onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
191
445
  const saving = ref(false);
192
446
  async function save() {
193
447
  const problem = editorProblem(state.value);
194
- if (problem) return void (state.value = editorReduce(state.value, { type: "notice", text: problem, ok: false }));
448
+ if (problem) return void dispatch({ type: "notice", text: problem, ok: false });
195
449
  if (!props.map?._id && !props.ownerRobotId) {
196
- return void (state.value = editorReduce(state.value, {
450
+ return void dispatch({
197
451
  type: "notice",
198
452
  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
453
  ok: false,
200
- }));
454
+ });
201
455
  }
202
456
  const name = String(props.map?.name || `${props.siteName || "Site"} building`).slice(0, 60);
203
457
  const body = toMapBody(state.value.shapes, name, props.map);
@@ -205,21 +459,24 @@ async function save() {
205
459
  try {
206
460
  if (props.map?._id) await updateBuildingMap(String(props.map._id), { ...body, version: Number(props.map.version) || 1 });
207
461
  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) });
462
+ dispatch({ type: "saved", text: savedNotice(new Date(), state.value.shapes.length, props.siteName) });
209
463
  emit("saved");
210
464
  } catch (e) {
211
- state.value = editorReduce(state.value, { type: "notice", text: saveErrorText(e), ok: false });
465
+ dispatch({ type: "notice", text: saveErrorText(e), ok: false });
212
466
  } finally {
213
467
  saving.value = false;
214
468
  }
215
469
  }
216
470
 
217
471
  /* ---- drawing helpers + full screen ---- */
218
- const pts = (s: TEditorShape) => s.points.map((p) => `${p.x},${p.y}`).join(" ");
472
+ const pts = (list: Array<{ x: number; y: number }>) => list.map((p) => `${p.x},${p.y}`).join(" ");
219
473
  function boxStyle(s: TEditorShape) {
220
474
  const b = shapeBox(s);
221
475
  return { left: `${b.x}%`, top: `${b.y}%`, width: `${b.w}%`, height: `${b.h}%` };
222
476
  }
477
+ function rectStyle(r: { x: number; y: number; w: number; h: number }) {
478
+ 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)}%` };
479
+ }
223
480
  const root = ref<HTMLElement | null>(null);
224
481
  const isFs = ref(false);
225
482
  const onFs = () => (isFs.value = document.fullscreenElement === root.value);
@@ -910,8 +910,20 @@ const hidQrReaderId = computed(() => (
910
910
  hidQrConfiguredReaderId.value || String(hidQrReader.value?._id || "")
911
911
  ));
912
912
 
913
+ /*
914
+ * Visitor QR passes are hidden at the manager's request (2026-09-23).
915
+ *
916
+ * A flag rather than a deletion: issuing, the preview dialog, printing and the
917
+ * regenerate handler below are all intact and untouched, so bringing the
918
+ * feature back is this one line. Every surface that offers a Visitor QR reads
919
+ * `hidQrCodePassAllowed`, which is why the switch belongs here and not in each
920
+ * of them.
921
+ */
922
+ const HID_VISITOR_QR_ENABLED = false;
923
+
913
924
  const hidQrCodePassAllowed = computed(() => {
914
925
  return (
926
+ HID_VISITOR_QR_ENABLED &&
915
927
  hidQrCodePassEnabled.value &&
916
928
  ["guest", "contractor", "walk-in"].includes(prop.type)
917
929
  );