@columnus/shared 0.1.47 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6444,8 +6444,80 @@ var cleanupStateValidator = v.object({
6444
6444
  desiredManifestHash: v.string()
6445
6445
  });
6446
6446
 
6447
+ // packages/@columnus/shared/src/dateValues.ts
6448
+ function formatDateCell(ms) {
6449
+ return new Intl.DateTimeFormat(void 0, { dateStyle: "medium" }).format(new Date(ms));
6450
+ }
6451
+ function formatDateTimeCell(ms) {
6452
+ return new Intl.DateTimeFormat(void 0, {
6453
+ dateStyle: "medium",
6454
+ timeStyle: "short"
6455
+ }).format(new Date(ms));
6456
+ }
6457
+ function pad2(n) {
6458
+ return String(n).padStart(2, "0");
6459
+ }
6460
+ function dateInputValue(ms) {
6461
+ const d = new Date(ms);
6462
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
6463
+ }
6464
+ function dateTimeInputValue(ms) {
6465
+ const d = new Date(ms);
6466
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
6467
+ }
6468
+ function parseDateInput(s) {
6469
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s.trim());
6470
+ if (!m) return null;
6471
+ const y = Number(m[1]);
6472
+ const mo = Number(m[2]) - 1;
6473
+ const d = Number(m[3]);
6474
+ const dt = new Date(y, mo, d);
6475
+ if (dt.getFullYear() !== y || dt.getMonth() !== mo || dt.getDate() !== d) return null;
6476
+ return dt.getTime();
6477
+ }
6478
+ function parseDateTimeInput(s) {
6479
+ const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(s.trim());
6480
+ if (!m) return null;
6481
+ const y = Number(m[1]);
6482
+ const mo = Number(m[2]) - 1;
6483
+ const d = Number(m[3]);
6484
+ const h = Number(m[4]);
6485
+ const min = Number(m[5]);
6486
+ const dt = new Date(y, mo, d, h, min);
6487
+ if (dt.getFullYear() !== y || dt.getMonth() !== mo || dt.getDate() !== d || dt.getHours() !== h || dt.getMinutes() !== min) {
6488
+ return null;
6489
+ }
6490
+ return dt.getTime();
6491
+ }
6492
+ function serializeDateCsv(ms) {
6493
+ return dateInputValue(ms);
6494
+ }
6495
+ function serializeDateTimeCsv(ms) {
6496
+ return new Date(ms).toISOString();
6497
+ }
6498
+ function parseDateCsv(s, kind) {
6499
+ const trimmed = s.trim();
6500
+ if (!trimmed) return null;
6501
+ if (kind === "date") {
6502
+ const fromDate = parseDateInput(trimmed);
6503
+ if (fromDate !== null) return fromDate;
6504
+ const fromIso2 = Date.parse(trimmed);
6505
+ if (Number.isFinite(fromIso2)) {
6506
+ const d = new Date(fromIso2);
6507
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
6508
+ }
6509
+ return null;
6510
+ }
6511
+ const fromLocal = parseDateTimeInput(trimmed);
6512
+ if (fromLocal !== null) return fromLocal;
6513
+ const fromIso = Date.parse(trimmed);
6514
+ return Number.isFinite(fromIso) ? fromIso : null;
6515
+ }
6516
+
6447
6517
  // packages/@columnus/shared/src/displayLabel.ts
6448
- var PREFERRED_KEYS = ["name", "Name", "title", "Title", "email", "label", "slug"];
6518
+ var PREVIEW_PART_MAX = 24;
6519
+ var PREVIEW_TOTAL_MAX = 48;
6520
+ var PREVIEW_ID_SHORT_LEN = 12;
6449
6521
  function truncateDisplay(s, n) {
6450
6522
  return s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
6451
6523
  }
@@ -6460,17 +6532,62 @@ function formatDisplayPreviewText(value, maxLen = 36) {
6460
6532
  }
6461
6533
  return truncateDisplay(value, maxLen);
6462
6534
  }
6463
- function fallbackPreviewLabel(row) {
6464
- for (const key of PREFERRED_KEYS) {
6465
- const v3 = row[key];
6466
- if (typeof v3 === "string" && v3.length > 0) return formatDisplayPreviewText(v3);
6535
+ function formatPreviewPart(type, value) {
6536
+ switch (type.kind) {
6537
+ case "string":
6538
+ case "markdown":
6539
+ if (typeof value !== "string" || value.length === 0) return null;
6540
+ return formatDisplayPreviewText(value, PREVIEW_PART_MAX);
6541
+ case "date":
6542
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
6543
+ return truncateDisplay(formatDateCell(value), PREVIEW_PART_MAX);
6544
+ case "datetime":
6545
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
6546
+ return truncateDisplay(formatDateTimeCell(value), PREVIEW_PART_MAX);
6547
+ case "number":
6548
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
6549
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
6550
+ case "bigint":
6551
+ if (typeof value !== "bigint" && typeof value !== "number") return null;
6552
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
6553
+ case "literal":
6554
+ if (value === void 0 || value === null || value === "") return null;
6555
+ if (typeof value === "string") return formatDisplayPreviewText(value, PREVIEW_PART_MAX);
6556
+ if (typeof value === "number" || typeof value === "boolean") {
6557
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
6558
+ }
6559
+ return null;
6560
+ case "boolean":
6561
+ case "null":
6562
+ case "any":
6563
+ case "bytes":
6564
+ case "file":
6565
+ case "image":
6566
+ case "id":
6567
+ case "array":
6568
+ case "object":
6569
+ case "union":
6570
+ return null;
6571
+ default: {
6572
+ const _exhaustive = type;
6573
+ return _exhaustive;
6574
+ }
6575
+ }
6576
+ }
6577
+ function fallbackPreviewLabel(row, fields = []) {
6578
+ const documentId = typeof row._id === "string" ? row._id : String(row._id ?? "");
6579
+ const parts = [];
6580
+ for (const field of fields) {
6581
+ if (parts.length >= 2) break;
6582
+ const formatted = formatPreviewPart(field.type, row[field.name])?.trim();
6583
+ if (!formatted) continue;
6584
+ if (looksLikeId(formatted) || documentId && formatted === documentId) continue;
6585
+ parts.push(formatted);
6467
6586
  }
6468
- for (const [k, v3] of Object.entries(row)) {
6469
- if (k.startsWith("_")) continue;
6470
- if (typeof v3 === "string" && v3.length > 0) return formatDisplayPreviewText(v3);
6471
- if (typeof v3 === "number") return String(v3);
6587
+ if (parts.length === 0) {
6588
+ return documentId ? formatIdShort(documentId, PREVIEW_ID_SHORT_LEN) : "";
6472
6589
  }
6473
- return String(row._id ?? "");
6590
+ return truncateDisplay(parts.join(" "), PREVIEW_TOTAL_MAX);
6474
6591
  }
6475
6592
  function fallbackIdLabel(documentId) {
6476
6593
  return documentId;
@@ -6911,76 +7028,6 @@ function filterChangedPatchFields(patch, baseline) {
6911
7028
  return out;
6912
7029
  }
6913
7030
 
6914
- // packages/@columnus/shared/src/dateValues.ts
6915
- function formatDateCell(ms) {
6916
- return new Intl.DateTimeFormat(void 0, { dateStyle: "medium" }).format(new Date(ms));
6917
- }
6918
- function formatDateTimeCell(ms) {
6919
- return new Intl.DateTimeFormat(void 0, {
6920
- dateStyle: "medium",
6921
- timeStyle: "short"
6922
- }).format(new Date(ms));
6923
- }
6924
- function pad2(n) {
6925
- return String(n).padStart(2, "0");
6926
- }
6927
- function dateInputValue(ms) {
6928
- const d = new Date(ms);
6929
- return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
6930
- }
6931
- function dateTimeInputValue(ms) {
6932
- const d = new Date(ms);
6933
- return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
6934
- }
6935
- function parseDateInput(s) {
6936
- const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s.trim());
6937
- if (!m) return null;
6938
- const y = Number(m[1]);
6939
- const mo = Number(m[2]) - 1;
6940
- const d = Number(m[3]);
6941
- const dt = new Date(y, mo, d);
6942
- if (dt.getFullYear() !== y || dt.getMonth() !== mo || dt.getDate() !== d) return null;
6943
- return dt.getTime();
6944
- }
6945
- function parseDateTimeInput(s) {
6946
- const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(s.trim());
6947
- if (!m) return null;
6948
- const y = Number(m[1]);
6949
- const mo = Number(m[2]) - 1;
6950
- const d = Number(m[3]);
6951
- const h = Number(m[4]);
6952
- const min = Number(m[5]);
6953
- const dt = new Date(y, mo, d, h, min);
6954
- if (dt.getFullYear() !== y || dt.getMonth() !== mo || dt.getDate() !== d || dt.getHours() !== h || dt.getMinutes() !== min) {
6955
- return null;
6956
- }
6957
- return dt.getTime();
6958
- }
6959
- function serializeDateCsv(ms) {
6960
- return dateInputValue(ms);
6961
- }
6962
- function serializeDateTimeCsv(ms) {
6963
- return new Date(ms).toISOString();
6964
- }
6965
- function parseDateCsv(s, kind) {
6966
- const trimmed = s.trim();
6967
- if (!trimmed) return null;
6968
- if (kind === "date") {
6969
- const fromDate = parseDateInput(trimmed);
6970
- if (fromDate !== null) return fromDate;
6971
- const fromIso2 = Date.parse(trimmed);
6972
- if (Number.isFinite(fromIso2)) {
6973
- const d = new Date(fromIso2);
6974
- return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
6975
- }
6976
- return null;
6977
- }
6978
- const fromLocal = parseDateTimeInput(trimmed);
6979
- if (fromLocal !== null) return fromLocal;
6980
- const fromIso = Date.parse(trimmed);
6981
- return Number.isFinite(fromIso) ? fromIso : null;
6982
- }
6983
-
6984
7031
  // packages/@columnus/shared/src/csv.ts
6985
7032
  var import_papaparse = __toESM(require_papaparse_min());
6986
7033