@columnus/shared 0.1.47 → 0.1.49

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.
@@ -1,8 +1,12 @@
1
+ import type { Field } from "./schemaTypes.ts";
1
2
  export declare function truncateDisplay(s: string, n: number): string;
2
3
  /** One-line label for display-value cache and UI fallbacks; unwraps BlockNote JSON. */
3
4
  export declare function formatDisplayPreviewText(value: string, maxLen?: number): string;
4
- /** Heuristic label when no Preview template is configured. */
5
- export declare function fallbackPreviewLabel(row: Record<string, unknown>): string;
5
+ /**
6
+ * Heuristic Preview label when no Preview template is configured.
7
+ * Walks `fields` in schema order, takes up to two eligible values, truncates.
8
+ */
9
+ export declare function fallbackPreviewLabel(row: Record<string, unknown>, fields?: readonly Field[]): string;
6
10
  export declare function fallbackIdLabel(documentId: string): string;
7
11
  export declare function formatIdShort(id: string, n?: number): string;
8
12
  export declare function looksLikeId(s: string): boolean;
@@ -4,6 +4,17 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
+ // packages/@columnus/shared/src/dateValues.ts
8
+ function formatDateCell(ms) {
9
+ return new Intl.DateTimeFormat(void 0, { dateStyle: "medium" }).format(new Date(ms));
10
+ }
11
+ function formatDateTimeCell(ms) {
12
+ return new Intl.DateTimeFormat(void 0, {
13
+ dateStyle: "medium",
14
+ timeStyle: "short"
15
+ }).format(new Date(ms));
16
+ }
17
+
7
18
  // node_modules/zod/v3/external.js
8
19
  var external_exports = {};
9
20
  __export(external_exports, {
@@ -4272,7 +4283,9 @@ function extractPlainText(value, maxLength) {
4272
4283
  }
4273
4284
 
4274
4285
  // packages/@columnus/shared/src/displayLabel.ts
4275
- var PREFERRED_KEYS = ["name", "Name", "title", "Title", "email", "label", "slug"];
4286
+ var PREVIEW_PART_MAX = 24;
4287
+ var PREVIEW_TOTAL_MAX = 48;
4288
+ var PREVIEW_ID_SHORT_LEN = 12;
4276
4289
  function truncateDisplay(s, n) {
4277
4290
  return s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
4278
4291
  }
@@ -4287,17 +4300,62 @@ function formatDisplayPreviewText(value, maxLen = 36) {
4287
4300
  }
4288
4301
  return truncateDisplay(value, maxLen);
4289
4302
  }
4290
- function fallbackPreviewLabel(row) {
4291
- for (const key of PREFERRED_KEYS) {
4292
- const v = row[key];
4293
- if (typeof v === "string" && v.length > 0) return formatDisplayPreviewText(v);
4303
+ function formatPreviewPart(type, value) {
4304
+ switch (type.kind) {
4305
+ case "string":
4306
+ case "markdown":
4307
+ if (typeof value !== "string" || value.length === 0) return null;
4308
+ return formatDisplayPreviewText(value, PREVIEW_PART_MAX);
4309
+ case "date":
4310
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
4311
+ return truncateDisplay(formatDateCell(value), PREVIEW_PART_MAX);
4312
+ case "datetime":
4313
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
4314
+ return truncateDisplay(formatDateTimeCell(value), PREVIEW_PART_MAX);
4315
+ case "number":
4316
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
4317
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
4318
+ case "bigint":
4319
+ if (typeof value !== "bigint" && typeof value !== "number") return null;
4320
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
4321
+ case "literal":
4322
+ if (value === void 0 || value === null || value === "") return null;
4323
+ if (typeof value === "string") return formatDisplayPreviewText(value, PREVIEW_PART_MAX);
4324
+ if (typeof value === "number" || typeof value === "boolean") {
4325
+ return truncateDisplay(String(value), PREVIEW_PART_MAX);
4326
+ }
4327
+ return null;
4328
+ case "boolean":
4329
+ case "null":
4330
+ case "any":
4331
+ case "bytes":
4332
+ case "file":
4333
+ case "image":
4334
+ case "id":
4335
+ case "array":
4336
+ case "object":
4337
+ case "union":
4338
+ return null;
4339
+ default: {
4340
+ const _exhaustive = type;
4341
+ return _exhaustive;
4342
+ }
4343
+ }
4344
+ }
4345
+ function fallbackPreviewLabel(row, fields = []) {
4346
+ const documentId = typeof row._id === "string" ? row._id : String(row._id ?? "");
4347
+ const parts = [];
4348
+ for (const field of fields) {
4349
+ if (parts.length >= 2) break;
4350
+ const formatted = formatPreviewPart(field.type, row[field.name])?.trim();
4351
+ if (!formatted) continue;
4352
+ if (looksLikeId(formatted) || documentId && formatted === documentId) continue;
4353
+ parts.push(formatted);
4294
4354
  }
4295
- for (const [k, v] of Object.entries(row)) {
4296
- if (k.startsWith("_")) continue;
4297
- if (typeof v === "string" && v.length > 0) return formatDisplayPreviewText(v);
4298
- if (typeof v === "number") return String(v);
4355
+ if (parts.length === 0) {
4356
+ return documentId ? formatIdShort(documentId, PREVIEW_ID_SHORT_LEN) : "";
4299
4357
  }
4300
- return String(row._id ?? "");
4358
+ return truncateDisplay(parts.join(" "), PREVIEW_TOTAL_MAX);
4301
4359
  }
4302
4360
  function fallbackIdLabel(documentId) {
4303
4361
  return documentId;