@sincpro/web-ui 1.8.0 → 1.9.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.
@@ -1,15 +1,36 @@
1
- import type { ReactNode } from "react";
2
- /** Who did something to the record and when, already written: «Carla Rojas», «hace 3 días». */
1
+ import { type UserChipProps } from "../../primitives/value/Person.js";
2
+ import { type ReactNode } from "react";
3
+ /**
4
+ * Who did something to the record and when.
5
+ *
6
+ * `by` is the person: a name (drawn as the system's `UserChip`, the same face and name a
7
+ * «Vendedor» field shows), the chip's props (to give it a photo, a contact card or «Abrir»),
8
+ * or a node the application already drew. Optional: an import, a sync or a backend that does
9
+ * not keep the author still knows WHEN — the line then says only that, never «por —».
10
+ *
11
+ * `at` is the moment: a `Date`, an ISO string or a timestamp is written by the system as the
12
+ * locale's date and time (DD/MM/YYYY HH:mm in Spanish), so every record says it the same
13
+ * way; anything else is shown as the application wrote it.
14
+ */
3
15
  export type RecordStamp = {
4
- by: ReactNode;
5
- at: ReactNode;
16
+ by?: ReactNode | UserChipProps;
17
+ at: ReactNode | Date;
6
18
  };
7
19
  /**
8
20
  * The last line of the paper: who created the record and who touched it last.
9
21
  *
10
22
  * Context: «¿quién cambió esto?» is the first question in front of a number that looks wrong,
11
23
  * and the activity's timeline answers it only for what was logged. Small and at the end: it is
12
- * consulted, not read.
24
+ * consulted, not read — so it is the quietest thing on the paper, below the facts, behind a
25
+ * rule.
26
+ *
27
+ * It was one run-on sentence («Creado por Josefa Muñoz · 02/09/2026») with the person as bare
28
+ * text and the date in whatever shape the app sent. It is now the record's own grammar: a
29
+ * muted label and its value, the person as the chip every other person-field uses and the date
30
+ * as `DateValue` — so the footer reads like the form above it, not like a log line.
31
+ *
32
+ * Its side padding follows the density: the compact body (a dialog, a card) has none, and a
33
+ * footer with `px-4` stood out of the column of fields it closes.
13
34
  */
14
35
  export declare function RecordAudit({ created, updated, }: {
15
36
  created?: RecordStamp;
@@ -1,27 +1,68 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { fillCopy, useUiCopy } from "../../foundations/copy.js";
3
+ import { useUiCopy } from "../../foundations/copy.js";
4
+ import { byDensity, useDensity } from "../../foundations/density.js";
5
+ import { DateValue } from "../../primitives/value/DateValue.js";
6
+ import { UserChip } from "../../primitives/value/Person.js";
7
+ import { isValidElement } from "react";
4
8
  /**
5
9
  * The last line of the paper: who created the record and who touched it last.
6
10
  *
7
11
  * Context: «¿quién cambió esto?» is the first question in front of a number that looks wrong,
8
12
  * and the activity's timeline answers it only for what was logged. Small and at the end: it is
9
- * consulted, not read.
13
+ * consulted, not read — so it is the quietest thing on the paper, below the facts, behind a
14
+ * rule.
15
+ *
16
+ * It was one run-on sentence («Creado por Josefa Muñoz · 02/09/2026») with the person as bare
17
+ * text and the date in whatever shape the app sent. It is now the record's own grammar: a
18
+ * muted label and its value, the person as the chip every other person-field uses and the date
19
+ * as `DateValue` — so the footer reads like the form above it, not like a log line.
20
+ *
21
+ * Its side padding follows the density: the compact body (a dialog, a card) has none, and a
22
+ * footer with `px-4` stood out of the column of fields it closes.
10
23
  */
11
24
  export function RecordAudit({ created, updated, }) {
12
25
  const copy = useUiCopy();
13
- const stamp = (template, one) => {
14
- const [before, middle, after] = splitStamp(template);
15
- return (_jsxs("span", { children: [before, _jsx("span", { className: "text-ink", children: one.by }), middle, _jsx("span", { className: "tabular-nums", children: one.at }), after] }));
16
- };
26
+ const d = useDensity();
17
27
  if (created === undefined && updated === undefined)
18
28
  return null;
19
- return (_jsxs("p", { className: "flex flex-wrap gap-x-4 gap-y-1 border-t border-line px-4 py-2.5 text-micro text-muted", children: [created === undefined ? null : stamp(copy.record.created, created), updated === undefined ? null : stamp(copy.record.updated, updated)] }));
29
+ return (_jsxs("dl", { className: `flex min-w-0 flex-wrap items-center gap-x-6 gap-y-1.5 border-t border-line ${byDensity(d, "px-4 py-2.5", "py-2")}`, children: [created === undefined ? null : _jsx(Stamp, { label: copy.record.created, stamp: created }), updated === undefined ? null : _jsx(Stamp, { label: copy.record.updated, stamp: updated })] }));
30
+ }
31
+ function Stamp({ label, stamp }) {
32
+ return (_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx("dt", { className: "shrink-0 text-micro text-muted", children: label }), _jsxs("dd", { className: "flex min-w-0 items-center gap-2", children: [_jsx(Author, { by: stamp.by }), _jsx(Moment, { at: stamp.at })] })] }));
33
+ }
34
+ /** Blank, or the dash an application wrote for «nobody» (`by ?? "—"`, from when `by` was
35
+ * required): a chip would draw it as a face with «—» for initials. */
36
+ const NOBODY = /^[\s\-–—]*$/;
37
+ function Author({ by }) {
38
+ if (by === undefined || by === null || typeof by === "boolean")
39
+ return null;
40
+ if (typeof by === "string") {
41
+ return NOBODY.test(by) ? null : _jsx(UserChip, { name: by, size: "sm" });
42
+ }
43
+ if (isChipProps(by))
44
+ return _jsx(UserChip, { size: "sm", ...by });
45
+ return _jsx("span", { className: "min-w-0 text-meta text-ink", children: by });
46
+ }
47
+ /** The chip's props are a plain object with a name; a React element also is an object, and
48
+ * a node the application drew is passed through untouched. */
49
+ function isChipProps(by) {
50
+ return (typeof by === "object" &&
51
+ by !== null &&
52
+ !isValidElement(by) &&
53
+ !Array.isArray(by) &&
54
+ typeof by.name === "string");
20
55
  }
21
- /** «Creado por {by} · {at}» cut around its two holes, so `by` and `at` can be nodes. */
22
- function splitStamp(template) {
23
- const marked = fillCopy(template, { by: "\u0000", at: "\u0001" });
24
- const [before = "", rest = ""] = marked.split("\u0000");
25
- const [middle = "", after = ""] = rest.split("\u0001");
26
- return [before, middle, after];
56
+ /** A date-only string (`2026-09-02`) is a day: its hour would be an invented midnight. */
57
+ const DAY_ONLY = /^\d{4}-\d{2}-\d{2}$/;
58
+ /** What a backend sends for a moment: `2026-09-02`, `2026-09-02T11:40:00Z`, `2026-09-02 11:40`. */
59
+ const ISO = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
60
+ function Moment({ at }) {
61
+ if (at instanceof Date || typeof at === "number") {
62
+ return _jsx(DateValue, { when: at, format: "exact" });
63
+ }
64
+ if (typeof at === "string" && ISO.test(at)) {
65
+ return (_jsx(DateValue, { when: DAY_ONLY.test(at) ? at : at.replace(" ", "T"), format: DAY_ONLY.test(at) ? "date" : "exact" }));
66
+ }
67
+ return _jsx("span", { className: "text-meta whitespace-nowrap tabular-nums text-muted", children: at });
27
68
  }
@@ -88,7 +88,8 @@ export type UiCopy = {
88
88
  noticeMany: string;
89
89
  /** The accessible name of the band of what is wrong with the record. */
90
90
  blocking: string;
91
- /** The paper's last line (`Record.Audit`): «{by}» and «{at}» are already written. */
91
+ /** The labels of the paper's last line (`Record.Audit`): the person and the moment are
92
+ * drawn beside them as values, so they are names, not sentences with holes. */
92
93
  created: string;
93
94
  updated: string;
94
95
  };
@@ -83,8 +83,8 @@ export const SPANISH_COPY = {
83
83
  noticeOne: "{count} aviso",
84
84
  noticeMany: "{count} avisos",
85
85
  blocking: "Lo que está mal en este registro",
86
- created: "Creado por {by} · {at}",
87
- updated: "Modificado por última vez por {by} · {at}",
86
+ created: "Creado",
87
+ updated: "Última modificación",
88
88
  },
89
89
  shell: {
90
90
  close: "Cerrar",
@@ -59,8 +59,8 @@ export const ENGLISH_COPY = {
59
59
  noticeOne: "{count} notice",
60
60
  noticeMany: "{count} notices",
61
61
  blocking: "What is wrong with this record",
62
- created: "Created by {by} · {at}",
63
- updated: "Last changed by {by} · {at}",
62
+ created: "Created",
63
+ updated: "Last changed",
64
64
  },
65
65
  shell: {
66
66
  modules: "All modules",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-ui",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",