@7365admin1/layer-common 4.15.3-staging.327 → 4.16.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +21 -4
  2. package/components/DocumentForm.vue +112 -407
  3. package/components/DocumentManagement.vue +12 -213
  4. package/components/EntryPass/QrTemplatePreview.vue +25 -21
  5. package/components/EntryPassInformation.vue +24 -119
  6. package/components/Facility/BookingSetup.vue +0 -63
  7. package/components/HidIntercomManagement.vue +43 -193
  8. package/components/HidReaderUserRoster.vue +2 -32
  9. package/components/HidUserEnrollment.vue +212 -771
  10. package/components/InvitationClientForm.vue +1 -19
  11. package/components/Layout/Header.vue +0 -26
  12. package/components/VehicleAddSelection.vue +2 -7
  13. package/components/VehicleManagement.vue +3 -31
  14. package/components/VisitorManagement.vue +5 -267
  15. package/composables/useAccessManagement.ts +0 -5
  16. package/composables/useDocument.ts +0 -7
  17. package/composables/useFacility.ts +0 -11
  18. package/composables/useHidAmico.ts +0 -97
  19. package/composables/useHidNavigation.ts +1 -25
  20. package/composables/usePeople.ts +0 -19
  21. package/composables/useVehicle.ts +0 -35
  22. package/composables/useWebUsb.ts +11 -14
  23. package/package.json +1 -1
  24. package/types/document.d.ts +0 -14
  25. package/types/facility.d.ts +0 -4
  26. package/types/people.d.ts +1 -4
  27. package/utils/materialSymbols.ts +0 -3
  28. package/components/HidProfileQrCode.vue +0 -323
  29. package/components/NotificationBell.vue +0 -321
  30. package/components/VehicleBulkAddForm.vue +0 -1417
  31. package/composables/useNotification.ts +0 -78
  32. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  33. package/utils/vehicle-bulk-rows.ts +0 -584
  34. package/utils/vehicle-bulk-sheet.ts +0 -387
@@ -1,387 +0,0 @@
1
- /**
2
- * The spreadsheet a person fills in away from the screen.
3
- *
4
- * The bulk whitelist sheet is fastest when the typing has already been done
5
- * somewhere else - a management office keeps its residents in Excel, not in a
6
- * browser tab. So there are two halves here:
7
- *
8
- * - a TEMPLATE to download: the sheet's own columns, in the sheet's own order,
9
- * with one example line so nobody has to guess how a block is spelled;
10
- * - a READER for what comes back, whether it was saved as CSV (what Excel
11
- * keeps when the template is edited and saved) or as a workbook (.xlsx).
12
- *
13
- * The file has to BE the template - the same columns in the same order - so
14
- * that a row means what it says. Nothing else here judges a row: it turns a
15
- * file into a grid of text in the sheet's column order; the grid then goes through the same paste path as
16
- * Ctrl+V, so block, level and unit names are matched to this site's records
17
- * and anything that matches nothing is left blank and marked red.
18
- *
19
- * A text file (CSV, or what Excel keeps when the template is saved) is read
20
- * with `parsePastedGrid` - the clipboard's own reader, so a pasted block and
21
- * an uploaded file cannot disagree - and a workbook with `xlsxToGrid` below.
22
- * `mapUploadedGrid` then puts either one into the sheet's columns.
23
- */
24
-
25
- /** The template's column headings, in the order the sheet shows them. */
26
- export const BULK_SHEET_HEADINGS = [
27
- "Block",
28
- "Level",
29
- "Unit",
30
- "NRIC",
31
- "Full Name",
32
- "Code",
33
- "Phone Number",
34
- "Vehicle No.",
35
- ] as const;
36
-
37
- /** What each column may be called in a file somebody else made. */
38
- const HEADING_ALIASES: string[][] = [
39
- ["block", "blk", "block name", "block no", "building"],
40
- ["level", "lvl", "floor", "storey", "level no"],
41
- ["unit", "unit no", "unit number", "house no", "apartment"],
42
- ["nric", "nric fin", "fin", "ic", "ic no", "id no", "identity no"],
43
- ["full name", "name", "owner", "owner name", "resident", "resident name"],
44
- ["code", "country code", "dial code", "dialling code", "idd", "country"],
45
- [
46
- "phone number",
47
- "phone",
48
- "phone no",
49
- "mobile",
50
- "mobile no",
51
- "contact",
52
- "contact no",
53
- "contact number",
54
- "handphone",
55
- ],
56
- [
57
- "vehicle no",
58
- "vehicle",
59
- "vehicle number",
60
- "plate",
61
- "plate no",
62
- "plate number",
63
- "car plate",
64
- "carplate",
65
- "iu number",
66
- ],
67
- ];
68
-
69
- /** Headings compare on their letters and digits only. */
70
- export function normaliseHeading(value: string): string {
71
- return String(value ?? "")
72
- .replace(/^/, "")
73
- .toLowerCase()
74
- .replace(/[^a-z0-9]+/g, " ")
75
- .trim();
76
- }
77
-
78
- /**
79
- * Where each of the sheet's columns sits in an uploaded file's header row,
80
- * or -1 when that file does not carry it.
81
- */
82
- export function headingIndexes(headerRow: string[]): number[] {
83
- const seen = headerRow.map((cell) => normaliseHeading(cell));
84
- return HEADING_ALIASES.map((aliases) =>
85
- seen.findIndex((cell) => cell && aliases.includes(cell)),
86
- );
87
- }
88
-
89
- function isEmptyLine(cells: string[]): boolean {
90
- return cells.every((cell) => !String(cell ?? "").trim());
91
- }
92
-
93
- export type UploadedSheet = {
94
- /** Rows in the template's column order. Empty unless the columns matched. */
95
- rows: string[][];
96
- /** Whether the file's heading line is the template's, in the same order. */
97
- matchesTemplate: boolean;
98
- /** The heading line as the file spells it - for telling a person what it has. */
99
- header: string[];
100
- };
101
-
102
- /**
103
- * Does this heading line say what the template's says?
104
- *
105
- * The same columns, in the same order - spelling is forgiven ("Vehicle No"
106
- * for "Vehicle No.", any case or punctuation), the order is not. A file whose
107
- * columns are somewhere else, or has extra ones, is a file whose rows we
108
- * would be guessing at, and a guess here puts a person's phone number in the
109
- * NRIC field of somebody else's car.
110
- */
111
- export function headerMatchesTemplate(headerRow: string[]): boolean {
112
- const cells = [...(headerRow ?? [])].map((cell) => String(cell ?? "").trim());
113
- while (cells.length && !cells[cells.length - 1]) cells.pop();
114
-
115
- if (cells.length !== BULK_SHEET_HEADINGS.length) return false;
116
-
117
- return cells.every((cell, index) =>
118
- HEADING_ALIASES[index].includes(normaliseHeading(cell)),
119
- );
120
- }
121
-
122
- /**
123
- * Put an uploaded file's grid into the sheet's columns.
124
- *
125
- * The file has to be the template: its first line names the template's
126
- * columns, in the template's order. Anything else comes back with
127
- * `matchesTemplate: false` and no rows, for the screen to explain.
128
- */
129
- export function mapUploadedGrid(grid: string[][]): UploadedSheet {
130
- const lines = (grid ?? []).filter((line) => line && !isEmptyLine(line));
131
- if (!lines.length) return { rows: [], matchesTemplate: false, header: [] };
132
-
133
- const header = lines[0].map((cell) => String(cell ?? "").trim());
134
- if (!headerMatchesTemplate(header)) {
135
- return { rows: [], matchesTemplate: false, header };
136
- }
137
-
138
- // Every line under the header is somebody's car. Nothing is dropped for
139
- // looking like something else - two people in one household can have the
140
- // same details but for the plate, and a repeated row is the person's to fix.
141
- const rows = lines
142
- .slice(1)
143
- .map((line) =>
144
- BULK_SHEET_HEADINGS.map((_, column) => String(line[column] ?? "").trim()),
145
- )
146
- .filter((line) => !isEmptyLine(line));
147
-
148
- return { rows, matchesTemplate: true, header };
149
- }
150
-
151
- /**
152
- * The blank sheet to fill in, as CSV - what Excel and Sheets both open.
153
- *
154
- * Headings only. An example line would have to be deleted before uploading,
155
- * and a file where it was not is a file that adds a car nobody owns.
156
- */
157
- export function vehicleBulkTemplateCsv(): string {
158
- const quote = (value: string) =>
159
- /[",\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
160
-
161
- return `${BULK_SHEET_HEADINGS.map(quote).join(",")}\r\n`;
162
- }
163
-
164
- /* ------------------------------ workbooks -------------------------------- */
165
-
166
- const XML_ENTITIES: Record<string, string> = {
167
- amp: "&",
168
- lt: "<",
169
- gt: ">",
170
- quot: '"',
171
- apos: "'",
172
- };
173
-
174
- function decodeXml(text: string): string {
175
- return text.replace(/&(#x?[0-9a-fA-F]+|[a-z]+);/g, (whole, entity: string) => {
176
- if (entity[0] === "#") {
177
- const code =
178
- entity[1] === "x" || entity[1] === "X"
179
- ? parseInt(entity.slice(2), 16)
180
- : parseInt(entity.slice(1), 10);
181
- return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
182
- }
183
- return XML_ENTITIES[entity] ?? whole;
184
- });
185
- }
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
-
213
- /** A1 -> 0, B1 -> 1, AA1 -> 26. */
214
- export function columnFromRef(ref: string): number {
215
- const letters = String(ref ?? "").match(/^[A-Z]+/)?.[0] ?? "";
216
- let index = 0;
217
- for (const letter of letters) index = index * 26 + (letter.charCodeAt(0) - 64);
218
- return index - 1;
219
- }
220
-
221
- type ZipEntry = { method: number; start: number; size: number };
222
-
223
- function view(bytes: Uint8Array) {
224
- return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
225
- }
226
-
227
- /**
228
- * The entries of a zip file, by name.
229
- *
230
- * An .xlsx IS a zip, and this reads only what one needs: where each part
231
- * starts and how it was packed. Written rather than pulled in - a workbook
232
- * reader is a large dependency for a layer that ships to every app, and the
233
- * part of it this screen uses is the hundred lines below.
234
- */
235
- function readZipEntries(bytes: Uint8Array): Map<string, ZipEntry> {
236
- const data = view(bytes);
237
- const entries = new Map<string, ZipEntry>();
238
-
239
- let end = -1;
240
- for (let index = bytes.length - 22; index >= 0 && index > bytes.length - 66_000; index--) {
241
- if (data.getUint32(index, true) === 0x06054b50) {
242
- end = index;
243
- break;
244
- }
245
- }
246
- if (end < 0) throw new Error("not-a-zip");
247
-
248
- const count = data.getUint16(end + 10, true);
249
- let offset = data.getUint32(end + 16, true);
250
-
251
- for (let item = 0; item < count; item++) {
252
- if (data.getUint32(offset, true) !== 0x02014b50) break;
253
-
254
- const method = data.getUint16(offset + 10, true);
255
- const size = data.getUint32(offset + 20, true);
256
- const nameLength = data.getUint16(offset + 28, true);
257
- const extraLength = data.getUint16(offset + 30, true);
258
- const commentLength = data.getUint16(offset + 32, true);
259
- const localOffset = data.getUint32(offset + 42, true);
260
- const name = new TextDecoder().decode(
261
- bytes.subarray(offset + 46, offset + 46 + nameLength),
262
- );
263
-
264
- // The local header repeats the name and may carry more extra bytes than
265
- // the central one, so the data's start is worked out from it.
266
- const localNameLength = data.getUint16(localOffset + 26, true);
267
- const localExtraLength = data.getUint16(localOffset + 28, true);
268
-
269
- entries.set(name, {
270
- method,
271
- start: localOffset + 30 + localNameLength + localExtraLength,
272
- size,
273
- });
274
-
275
- offset += 46 + nameLength + extraLength + commentLength;
276
- }
277
-
278
- return entries;
279
- }
280
-
281
- async function readPart(bytes: Uint8Array, entry: ZipEntry): Promise<string> {
282
- const packed = bytes.subarray(entry.start, entry.start + entry.size);
283
- if (entry.method === 0) return new TextDecoder().decode(packed);
284
- if (entry.method !== 8) throw new Error("unsupported-compression");
285
-
286
- const stream = new Blob([packed as BlobPart])
287
- .stream()
288
- .pipeThrough(new DecompressionStream("deflate-raw"));
289
- return new Response(stream).text();
290
- }
291
-
292
- function sharedStringsOf(xml: string): string[] {
293
- const strings: string[] = [];
294
- const items = xml.match(/<si\b[\s\S]*?<\/si>|<si\b[^>]*\/>/g) ?? [];
295
-
296
- for (const item of items) {
297
- const texts = item.replace(/<t[^>]*\/>/g, "").match(/<t[^>]*>[\s\S]*?<\/t>/g) ?? [];
298
- strings.push(
299
- texts
300
- .map((text) => decodeXml(text.replace(/^<t[^>]*>/, "").replace(/<\/t>$/, "")))
301
- .join(""),
302
- );
303
- }
304
-
305
- return strings;
306
- }
307
-
308
- function sheetToGrid(xml: string, strings: string[]): string[][] {
309
- const grid: string[][] = [];
310
- const rows = xml.match(/<row\b[\s\S]*?<\/row>|<row\b[^>]*\/>/g) ?? [];
311
- let cursor = 0;
312
-
313
- for (const row of rows) {
314
- const rowNumber = Number(row.match(/<row[^>]*\sr="(\d+)"/)?.[1] ?? 0);
315
- const line: string[] = [];
316
- const cells =
317
- row.match(/<c\b[^>]*\/>|<c\b[^>]*>[\s\S]*?<\/c>/g) ?? [];
318
-
319
- for (const cell of cells) {
320
- const attributes = cell.match(/^<c\b([^>]*)>/)?.[1] ?? "";
321
- const reference = attributes.match(/\sr="([A-Z]+\d+)"/)?.[1] ?? "";
322
- const type = attributes.match(/\st="([^"]+)"/)?.[1] ?? "n";
323
- const column = reference ? columnFromRef(reference) : line.length;
324
-
325
- let value = "";
326
- if (type === "inlineStr") {
327
- const texts =
328
- cell.replace(/<t[^>]*\/>/g, "").match(/<t[^>]*>[\s\S]*?<\/t>/g) ?? [];
329
- value = texts
330
- .map((text) => decodeXml(text.replace(/^<t[^>]*>/, "").replace(/<\/t>$/, "")))
331
- .join("");
332
- } else {
333
- const raw = cell.match(/<v[^>]*>([\s\S]*?)<\/v>/)?.[1];
334
- if (raw !== undefined) {
335
- value =
336
- type === "s"
337
- ? (strings[Number(decodeXml(raw))] ?? "")
338
- : plainNumberText(decodeXml(raw));
339
- }
340
- }
341
-
342
- while (line.length < column) line.push("");
343
- line[column] = value;
344
- }
345
-
346
- // A workbook may skip empty rows; keep the alignment they had.
347
- const target = rowNumber > 0 ? rowNumber - 1 : cursor;
348
- while (grid.length < target) grid.push([]);
349
- grid[target] = line;
350
- cursor = target + 1;
351
- }
352
-
353
- return grid;
354
- }
355
-
356
- /**
357
- * The first worksheet of an .xlsx workbook, as a grid of text.
358
- *
359
- * Only what a filled-in template carries is read: text, numbers as they were
360
- * typed, and shared or inline strings. Formatting, formulas' cached values
361
- * aside, and everything else a workbook can hold are of no interest here.
362
- */
363
- export async function xlsxToGrid(data: ArrayBuffer | Uint8Array): Promise<string[][]> {
364
- const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
365
- const entries = readZipEntries(bytes);
366
-
367
- const sheetName = [...entries.keys()]
368
- .filter((name) => /^xl\/worksheets\/sheet\d+\.xml$/.test(name))
369
- .sort(
370
- (a, b) =>
371
- Number(a.match(/(\d+)\.xml$/)![1]) - Number(b.match(/(\d+)\.xml$/)![1]),
372
- )[0];
373
-
374
- if (!sheetName) throw new Error("no-worksheet");
375
-
376
- const sharedEntry = entries.get("xl/sharedStrings.xml");
377
- const strings = sharedEntry
378
- ? sharedStringsOf(await readPart(bytes, sharedEntry))
379
- : [];
380
-
381
- return sheetToGrid(await readPart(bytes, entries.get(sheetName)!), strings);
382
- }
383
-
384
- /** True for a file that has to be unzipped rather than read as text. */
385
- export function isWorkbookName(name: string): boolean {
386
- return /\.(xlsx|xlsm)$/i.test(String(name ?? ""));
387
- }