@7365admin1/layer-common 4.15.3-staging.326 → 4.15.3-staging.328
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.
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
>
|
|
27
27
|
<iframe
|
|
28
28
|
ref="frameEl"
|
|
29
|
-
:key="
|
|
30
|
-
:src="
|
|
29
|
+
:key="liveSrc"
|
|
30
|
+
:src="liveSrc"
|
|
31
31
|
class="vms-tile__frame"
|
|
32
32
|
:title="`Live view of ${camera.name || 'camera'}`"
|
|
33
33
|
allowfullscreen
|
|
@@ -154,6 +154,7 @@ import {
|
|
|
154
154
|
clampPan,
|
|
155
155
|
clampZoom,
|
|
156
156
|
healthView,
|
|
157
|
+
liveSource,
|
|
157
158
|
LIVE_CONNECT_TIMEOUT_MS,
|
|
158
159
|
LIVE_FRAME_TIMEOUT_MS,
|
|
159
160
|
playerOrigin,
|
|
@@ -222,6 +223,14 @@ const view = computed(() =>
|
|
|
222
223
|
tileView(props.camera, { online: props.online, player: player.value })
|
|
223
224
|
);
|
|
224
225
|
|
|
226
|
+
/**
|
|
227
|
+
* The address this tile is showing — the server's signed one when there is one,
|
|
228
|
+
* the stored one otherwise. Taken verbatim: `src`, the remount key, the origin
|
|
229
|
+
* a player message must come from and the reload watch all read THIS, so they
|
|
230
|
+
* cannot drift apart and start disagreeing about which address is on screen.
|
|
231
|
+
*/
|
|
232
|
+
const liveSrc = computed(() => liveSource(props.camera));
|
|
233
|
+
|
|
225
234
|
/* ------------------------------------------------------------------ health */
|
|
226
235
|
|
|
227
236
|
const recorder = computed(() => healthView(props.health, props.now || Date.now()));
|
|
@@ -389,7 +398,7 @@ function onPlayerError() {
|
|
|
389
398
|
* understand must never be able to turn a badge green.
|
|
390
399
|
*/
|
|
391
400
|
function onPlayerMessage(event: MessageEvent) {
|
|
392
|
-
const origin = playerOrigin(
|
|
401
|
+
const origin = playerOrigin(liveSrc.value);
|
|
393
402
|
if (!origin || event.origin !== origin) return;
|
|
394
403
|
if (frameEl.value && event.source !== frameEl.value.contentWindow) return;
|
|
395
404
|
|
|
@@ -441,7 +450,7 @@ function restartFrameClock() {
|
|
|
441
450
|
* evidence, is the same mistake as declaring it live on a timer.
|
|
442
451
|
*/
|
|
443
452
|
watch(
|
|
444
|
-
() =>
|
|
453
|
+
() => liveSrc.value,
|
|
445
454
|
(host) => {
|
|
446
455
|
clearTimer();
|
|
447
456
|
clearFrameTimer();
|
|
@@ -292,8 +292,11 @@ import {
|
|
|
292
292
|
BULK_SHEET_DEFAULT_SIZE,
|
|
293
293
|
BULK_SHEET_SIZES,
|
|
294
294
|
DEFAULT_DIAL_CODE,
|
|
295
|
+
bulkAlphaNumeric,
|
|
296
|
+
bulkIdNumber,
|
|
295
297
|
bulkPhoneToStore,
|
|
296
298
|
bulkRowCounts,
|
|
299
|
+
splitPhoneEntry,
|
|
297
300
|
bulkSubmitBatches,
|
|
298
301
|
emptyBulkRow,
|
|
299
302
|
isBulkRowEmpty,
|
|
@@ -684,11 +687,33 @@ function commitAndMoveRight() {
|
|
|
684
687
|
|
|
685
688
|
function setCell(row: BulkVehicleRow, key: ColumnKey, value: string) {
|
|
686
689
|
if (isLocked(row)) return;
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
690
|
+
|
|
691
|
+
if (key === "plateNumber") {
|
|
692
|
+
// Letters and digits, in capitals - the same rule the one-vehicle form's
|
|
693
|
+
// Vehicle Number field applies as you type, so a plate typed "sba 1234 x"
|
|
694
|
+
// here and "SBA1234X" there are one plate, not two.
|
|
695
|
+
row.plateNumber = bulkAlphaNumeric(value);
|
|
696
|
+
} else if (key === "nric") {
|
|
697
|
+
// Capitals, keeping the separators an ID can carry (a dash, a slash) and
|
|
698
|
+
// losing only the spacing people write it with. Dropping a dash would
|
|
699
|
+
// store a number that is not the person's.
|
|
700
|
+
row.nric = bulkIdNumber(value);
|
|
701
|
+
} else if (key === "dialCode") {
|
|
702
|
+
// A row without a dial code would store a number under nobody's country,
|
|
703
|
+
// so emptying the cell puts the default back rather than leaving it blank.
|
|
704
|
+
row.dialCode = value.trim() || DEFAULT_DIAL_CODE;
|
|
705
|
+
} else if (key === "phone") {
|
|
706
|
+
// The cell keeps digits only - the country belongs to the Code column. A
|
|
707
|
+
// number that arrives carrying its own code (+60…, 0060…) moves the Code
|
|
708
|
+
// with it rather than being stored under the wrong country.
|
|
709
|
+
const entry = splitPhoneEntry(value, DIAL_CODE_VALUES);
|
|
710
|
+
if (entry.dialCode) row.dialCode = entry.dialCode;
|
|
711
|
+
row.phone = entry.phone;
|
|
712
|
+
if (entry.dialCode) row.invalid = row.invalid.filter((f) => f !== "dialCode");
|
|
713
|
+
} else {
|
|
714
|
+
row[key] = value;
|
|
715
|
+
}
|
|
716
|
+
|
|
692
717
|
row.invalid = row.invalid.filter((field) => field !== key);
|
|
693
718
|
|
|
694
719
|
// Emptied of everything again: whatever happened to it last time no longer
|
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.15.3-staging.
|
|
5
|
+
"version": "4.15.3-staging.328",
|
|
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.",
|
package/utils/camera-wall.ts
CHANGED
|
@@ -59,6 +59,20 @@ export type TWallCamera = {
|
|
|
59
59
|
* renderable live-video page — it is the picture, not a fragment to resolve.
|
|
60
60
|
*/
|
|
61
61
|
host?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The SIGNED live address, when the server has one for this camera.
|
|
64
|
+
*
|
|
65
|
+
* The relay's live routes are being closed behind a signature the server
|
|
66
|
+
* mints per request (`exp` + `sig`, covering the channel). That signature
|
|
67
|
+
* cannot live on `host`: `host` is the stored record, copied into patrol
|
|
68
|
+
* routes and re-read by the server's own `isRelayPlayerUrl`, which rejects an
|
|
69
|
+
* address carrying a query. So the server hands the signed address over
|
|
70
|
+
* beside it, and leaves `host` exactly as it always was.
|
|
71
|
+
*
|
|
72
|
+
* Absent for a camera whose relay is not configured — and then the wall falls
|
|
73
|
+
* back to `host` and behaves precisely as it does today.
|
|
74
|
+
*/
|
|
75
|
+
liveUrl?: string | null;
|
|
62
76
|
type?: string;
|
|
63
77
|
status?: string;
|
|
64
78
|
capabilities?: Record<string, TWallCapability>;
|
|
@@ -714,6 +728,22 @@ export function playerSignal(data: unknown): TPlayerSignal {
|
|
|
714
728
|
* that is not a URL at all. Kept here so the rule is tested rather than
|
|
715
729
|
* inlined in a component.
|
|
716
730
|
*/
|
|
731
|
+
/**
|
|
732
|
+
* The address the player is actually pointed at.
|
|
733
|
+
*
|
|
734
|
+
* `liveUrl` is the server's signed address and wins whenever it is there;
|
|
735
|
+
* `host` is the unsigned stored one and is what every camera used before
|
|
736
|
+
* signing existed. Never rebuilt, never re-encoded, never stripped of its
|
|
737
|
+
* query — a signature dropped here is a camera that goes black the day the
|
|
738
|
+
* relay starts enforcing, with nothing on screen to say why.
|
|
739
|
+
*/
|
|
740
|
+
export function liveSource(
|
|
741
|
+
camera: Pick<TWallCamera, "host" | "liveUrl"> | null | undefined
|
|
742
|
+
): string {
|
|
743
|
+
const signed = typeof camera?.liveUrl === "string" ? camera.liveUrl.trim() : "";
|
|
744
|
+
return signed || camera?.host || "";
|
|
745
|
+
}
|
|
746
|
+
|
|
717
747
|
export function playerOrigin(host: string | null | undefined): string {
|
|
718
748
|
if (!host) return "";
|
|
719
749
|
try {
|
|
@@ -79,16 +79,46 @@ export function isBulkRowEmpty(row: BulkVehicleRow): boolean {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* A phone number
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* A phone number as the sheet holds one: DIGITS, and nothing else. The country
|
|
83
|
+
* is the Code column's business, so a cell keeps only the number itself - what
|
|
84
|
+
* a person would dial locally. Blank is fine; it is not a required column.
|
|
85
85
|
*/
|
|
86
86
|
export function isValidBulkPhone(value: unknown): boolean {
|
|
87
87
|
const text = String(value ?? "").trim();
|
|
88
88
|
if (!text) return true;
|
|
89
|
-
|
|
89
|
+
return /^\d{7,15}$/.test(text);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Everything but the digits, gone: what a phone cell stores. */
|
|
93
|
+
export function bulkPhoneDigits(value: unknown): string {
|
|
94
|
+
return String(value ?? "").replace(/\D/g, "");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Split what somebody typed or pasted into a phone cell into the country it
|
|
99
|
+
* names and the number itself.
|
|
100
|
+
*
|
|
101
|
+
* "+60 12-345 6789" and "006012 3456789" both carry their own country, so the
|
|
102
|
+
* Code column follows the number rather than contradicting it. A plain local
|
|
103
|
+
* number names no country and leaves the Code alone.
|
|
104
|
+
*/
|
|
105
|
+
export function splitPhoneEntry(
|
|
106
|
+
value: unknown,
|
|
107
|
+
codes: string[],
|
|
108
|
+
): { dialCode: string; phone: string } {
|
|
109
|
+
const text = String(value ?? "").trim().replace(/[\s()\-.]/g, "");
|
|
110
|
+
const carriesCode = text.startsWith("+") || text.startsWith("00");
|
|
90
111
|
const digits = text.replace(/\D/g, "");
|
|
91
|
-
|
|
112
|
+
|
|
113
|
+
if (!carriesCode || !digits) return { dialCode: "", phone: digits };
|
|
114
|
+
|
|
115
|
+
const body = text.startsWith("00") ? digits.slice(2) : digits;
|
|
116
|
+
const match = [...codes]
|
|
117
|
+
.sort((a, b) => b.length - a.length)
|
|
118
|
+
.find((code) => body.startsWith(code.replace(/\D/g, "")));
|
|
119
|
+
|
|
120
|
+
if (!match) return { dialCode: "", phone: body };
|
|
121
|
+
return { dialCode: match, phone: body.slice(match.replace(/\D/g, "").length) };
|
|
92
122
|
}
|
|
93
123
|
|
|
94
124
|
/** What the one-vehicle form puts in front of a number with no country code. */
|
|
@@ -104,22 +134,18 @@ export const DEFAULT_DIAL_CODE = "+65";
|
|
|
104
134
|
* together. A number already written with a country code keeps its own.
|
|
105
135
|
*/
|
|
106
136
|
export function bulkPhoneToStore(value: unknown, dialCode?: string): string {
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
137
|
+
const digits = bulkPhoneDigits(value);
|
|
138
|
+
if (!digits) return "";
|
|
109
139
|
|
|
110
140
|
const code = String(dialCode ?? "").trim() || DEFAULT_DIAL_CODE;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
// A number that already carries a country code keeps the one it carries.
|
|
114
|
-
if (compact.startsWith("+")) return compact;
|
|
115
|
-
if (compact.startsWith("00")) return `+${compact.slice(2)}`;
|
|
141
|
+
const codeDigits = code.replace(/\D/g, "");
|
|
116
142
|
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
return `+${
|
|
143
|
+
// A number that already carries its country's digits is not given them twice.
|
|
144
|
+
if (codeDigits && digits.startsWith(codeDigits) && digits.length > codeDigits.length) {
|
|
145
|
+
return `+${digits}`;
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
return
|
|
148
|
+
return `+${codeDigits}${digits}`;
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
/** Each dial code's number patterns, e.g. { "+65": ["^\\+65\\d{8}$"] }. */
|
|
@@ -175,10 +201,34 @@ export function isValidBulkNumber(
|
|
|
175
201
|
return patterns.some((pattern) => matches(pattern, stored));
|
|
176
202
|
}
|
|
177
203
|
|
|
178
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* An NRIC or a plate as the system keeps them: letters and digits, in capitals.
|
|
206
|
+
*
|
|
207
|
+
* The one-vehicle form's own NRIC and Vehicle Number fields strip everything
|
|
208
|
+
* else as you type, so "sba 1234 x" and "SBA1234X" cannot both be stored for
|
|
209
|
+
* one car. The sheet applies the same rule, wherever a value came from.
|
|
210
|
+
*/
|
|
211
|
+
export function bulkAlphaNumeric(value: unknown): string {
|
|
212
|
+
return String(value ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* An identity number as the sheet keeps one: capitals, and the separators an
|
|
217
|
+
* ID can really carry.
|
|
218
|
+
*
|
|
219
|
+
* Not every ID is eight letters and digits - a Malaysian IC is written
|
|
220
|
+
* 900101-14-5678, a permit can carry a slash - so a symbol is kept rather than
|
|
221
|
+
* silently dropped. What goes is only what nobody's ID contains: spaces,
|
|
222
|
+
* commas and full stops, which are how people space a number out when they
|
|
223
|
+
* write it down.
|
|
224
|
+
*/
|
|
225
|
+
export function bulkIdNumber(value: unknown): string {
|
|
226
|
+
return String(value ?? "").replace(/[\s,.]/g, "").toUpperCase();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A plate number: letters and digits, and nothing else. */
|
|
179
230
|
export function isValidBulkPlate(value: unknown): boolean {
|
|
180
|
-
|
|
181
|
-
return /^[A-Za-z0-9][A-Za-z0-9 -]{0,14}$/.test(text);
|
|
231
|
+
return /^[A-Za-z0-9]{1,15}$/.test(String(value ?? "").trim());
|
|
182
232
|
}
|
|
183
233
|
|
|
184
234
|
/** Plates written the same way once spacing and case are ignored. */
|
|
@@ -184,6 +184,32 @@ function decodeXml(text: string): string {
|
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* A number as the sheet showed it, not as the file stored it.
|
|
189
|
+
*
|
|
190
|
+
* A workbook may keep 98695434 as `9.8695434E7` - which is the same number,
|
|
191
|
+
* and nobody's phone. The digits are shifted by hand rather than through
|
|
192
|
+
* `Number`, so a long one cannot lose its last digit to a float.
|
|
193
|
+
*/
|
|
194
|
+
export function plainNumberText(raw: string): string {
|
|
195
|
+
const match = /^([-+]?)(\d+)(?:\.(\d+))?[eE]([-+]?\d+)$/.exec(String(raw ?? "").trim());
|
|
196
|
+
if (!match) return String(raw ?? "");
|
|
197
|
+
|
|
198
|
+
const [, sign, whole, fraction = "", exponent] = match;
|
|
199
|
+
const digits = `${whole}${fraction}`;
|
|
200
|
+
const point = whole.length + Number(exponent);
|
|
201
|
+
|
|
202
|
+
let text: string;
|
|
203
|
+
if (point <= 0) text = `0.${"0".repeat(-point)}${digits}`;
|
|
204
|
+
else if (point >= digits.length) text = digits + "0".repeat(point - digits.length);
|
|
205
|
+
else text = `${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
206
|
+
|
|
207
|
+
// 98695434.000 and 98695434 are the same number; the sheet shows the shorter.
|
|
208
|
+
if (text.includes(".")) text = text.replace(/\.?0+$/, "");
|
|
209
|
+
|
|
210
|
+
return `${sign === "-" ? "-" : ""}${text}`;
|
|
211
|
+
}
|
|
212
|
+
|
|
187
213
|
/** A1 -> 0, B1 -> 1, AA1 -> 26. */
|
|
188
214
|
export function columnFromRef(ref: string): number {
|
|
189
215
|
const letters = String(ref ?? "").match(/^[A-Z]+/)?.[0] ?? "";
|
|
@@ -309,7 +335,7 @@ function sheetToGrid(xml: string, strings: string[]): string[][] {
|
|
|
309
335
|
value =
|
|
310
336
|
type === "s"
|
|
311
337
|
? (strings[Number(decodeXml(raw))] ?? "")
|
|
312
|
-
: decodeXml(raw);
|
|
338
|
+
: plainNumberText(decodeXml(raw));
|
|
313
339
|
}
|
|
314
340
|
}
|
|
315
341
|
|