@crisp-ui-kit/crisp 0.51.0 → 0.52.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 (40) hide show
  1. package/dist/cjs/core/caret-rect.js +73 -0
  2. package/dist/cjs/core/index.js +7 -1
  3. package/dist/cjs/core/mention.js +32 -0
  4. package/dist/cjs/core/use-mention-trigger.js +124 -0
  5. package/dist/cjs/product/recordpanel/recordpanel.js +13 -81
  6. package/dist/cjs/product/recordpanel/recordpanel.recipe.js +53 -44
  7. package/dist/cjs/product/recordstable/editable-field.js +11 -8
  8. package/dist/cjs/product/recordstable/recordstable.tag.js +8 -3
  9. package/dist/cjs/product/richtext/index.js +2 -1
  10. package/dist/cjs/product/richtext/richtext.js +440 -23
  11. package/dist/cjs/product/richtext/richtext.recipe.js +59 -9
  12. package/dist/esm/core/caret-rect.js +70 -0
  13. package/dist/esm/core/index.js +3 -0
  14. package/dist/esm/core/mention.js +29 -0
  15. package/dist/esm/core/use-mention-trigger.js +88 -0
  16. package/dist/esm/product/recordpanel/index.js +1 -1
  17. package/dist/esm/product/recordpanel/recordpanel.js +15 -83
  18. package/dist/esm/product/recordpanel/recordpanel.recipe.js +54 -45
  19. package/dist/esm/product/recordstable/editable-field.js +11 -8
  20. package/dist/esm/product/recordstable/recordstable.tag.js +8 -3
  21. package/dist/esm/product/richtext/index.js +1 -1
  22. package/dist/esm/product/richtext/richtext.js +439 -22
  23. package/dist/esm/product/richtext/richtext.recipe.js +60 -10
  24. package/dist/recordpanel.css +47 -41
  25. package/dist/recordpanel.layered.css +47 -41
  26. package/dist/richtext.css +31 -5
  27. package/dist/richtext.layered.css +31 -5
  28. package/dist/styles.css +79 -47
  29. package/dist/styles.layered.css +79 -47
  30. package/dist/types/core/caret-rect.d.ts +16 -0
  31. package/dist/types/core/index.d.ts +3 -0
  32. package/dist/types/core/mention.d.ts +27 -0
  33. package/dist/types/core/use-mention-trigger.d.ts +41 -0
  34. package/dist/types/product/recordpanel/index.d.ts +1 -1
  35. package/dist/types/product/recordpanel/recordpanel.d.ts +81 -27
  36. package/dist/types/product/recordstable/editable-field.d.ts +11 -8
  37. package/dist/types/product/recordstable/recordstable.tag.d.ts +8 -3
  38. package/dist/types/product/richtext/index.d.ts +1 -1
  39. package/dist/types/product/richtext/richtext.d.ts +168 -7
  40. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The pixel position of a caret index inside a `<textarea>`/`<input>`, in
3
+ * viewport coordinates — where a mention picker anchors.
4
+ *
5
+ * Neither element exposes caret geometry directly, so this uses the standard
6
+ * mirror-div technique: an off-screen div replicating every computed style
7
+ * that affects text layout (font, padding, border, wrapping), holding the
8
+ * same text up to the caret plus a marker span. The marker's own
9
+ * `getBoundingClientRect()`, translated back onto the real field's box, is
10
+ * the caret's actual rendered position — nothing here guesses at line
11
+ * height or character width itself.
12
+ */
13
+ export function caretRectInField(field, index) {
14
+ const div = document.createElement("div");
15
+ const style = window.getComputedStyle(field);
16
+ const mirrored = [
17
+ "boxSizing",
18
+ "width",
19
+ "paddingTop",
20
+ "paddingRight",
21
+ "paddingBottom",
22
+ "paddingLeft",
23
+ "borderTopWidth",
24
+ "borderRightWidth",
25
+ "borderBottomWidth",
26
+ "borderLeftWidth",
27
+ "fontFamily",
28
+ "fontSize",
29
+ "fontWeight",
30
+ "fontStyle",
31
+ "letterSpacing",
32
+ "lineHeight",
33
+ "textTransform",
34
+ "textIndent",
35
+ "textAlign",
36
+ "wordSpacing",
37
+ "tabSize",
38
+ ];
39
+ for (const prop of mirrored)
40
+ div.style.setProperty(prop, style[prop]);
41
+ div.style.position = "absolute";
42
+ div.style.visibility = "hidden";
43
+ div.style.top = "0";
44
+ div.style.left = "-9999px";
45
+ div.style.whiteSpace =
46
+ field instanceof HTMLTextAreaElement ? "pre-wrap" : "pre";
47
+ div.style.wordWrap = "break-word";
48
+ div.style.overflow = "hidden";
49
+ div.style.height = "auto";
50
+ const value = field.value;
51
+ div.textContent = value.slice(0, index);
52
+ const marker = document.createElement("span");
53
+ // a trailing empty span collapses to zero width and reports the wrong x —
54
+ // give it a hair of content so its box sits exactly at the caret
55
+ marker.textContent = value.slice(index, index + 1) || ".";
56
+ div.appendChild(marker);
57
+ document.body.appendChild(div);
58
+ div.scrollTop = field.scrollTop;
59
+ div.scrollLeft = field.scrollLeft;
60
+ const fieldRect = field.getBoundingClientRect();
61
+ const divRect = div.getBoundingClientRect();
62
+ const markerRect = marker.getBoundingClientRect();
63
+ const x = fieldRect.left + (markerRect.left - divRect.left) - div.scrollLeft;
64
+ const y = fieldRect.top +
65
+ (markerRect.top - divRect.top) -
66
+ div.scrollTop +
67
+ markerRect.height;
68
+ document.body.removeChild(div);
69
+ return { x, y };
70
+ }
@@ -1,3 +1,4 @@
1
+ export { caretRectInField } from "./caret-rect.js";
1
2
  export { cellDatePrecision, formatCellDate, parseCellDate, } from "./cell-date.js";
2
3
  export { cx } from "./cx.js";
3
4
  export { defineRecipe } from "./define.js";
@@ -6,6 +7,7 @@ export { isRtlElement } from "./direction.js";
6
7
  export { FloatingPortal } from "./floating-portal.js";
7
8
  export { hasOpenFloatingLayer, isInsideLaterFloatingLayer, registerFloatingLayer, } from "./floating-stack.js";
8
9
  export { formValueStyle } from "./form-value.js";
10
+ export { matchMentionTrigger, } from "./mention.js";
9
11
  export { placeFloating, } from "./place-floating.js";
10
12
  export { Primitive } from "./primitive.js";
11
13
  export { resolveRecipe } from "./resolve.js";
@@ -14,4 +16,5 @@ export { defineSpec, specToRecipe } from "./spec.js";
14
16
  export { useFocusAfterRemoval } from "./use-focus-after-removal.js";
15
17
  export { useFormReset } from "./use-form-reset.js";
16
18
  export { useLabelAssociation } from "./use-label-association.js";
19
+ export { useMentionTrigger, } from "./use-mention-trigger.js";
17
20
  export { usePrefersReducedMotion } from "./use-prefers-reduced-motion.js";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Is there an active "@query" mention trigger ending at the caret?
3
+ *
4
+ * Matches the rule every "@mention" implementation (GitHub, Slack, Linear)
5
+ * actually uses: the trigger character must start a word — the very first
6
+ * character, or preceded by whitespace — and nothing between it and the
7
+ * caret may contain whitespace. `foo@bar` is an email/handle stuck to a word,
8
+ * not a trigger; `@jo next` has already moved past the mention it typed.
9
+ *
10
+ * Takes plain text rather than a live DOM node so it is one pure function
11
+ * usable against a `<textarea>`'s `value` and a `contentEditable` text
12
+ * node's content alike, and is the one thing here worth unit-testing on its
13
+ * own — everything downstream of it (caret geometry, DOM insertion) needs a
14
+ * real browser to verify.
15
+ */
16
+ export function matchMentionTrigger(textBeforeCaret, trigger = "@") {
17
+ if (!trigger)
18
+ return null;
19
+ const start = textBeforeCaret.lastIndexOf(trigger);
20
+ if (start === -1)
21
+ return null;
22
+ const before = start > 0 ? textBeforeCaret[start - 1] : undefined;
23
+ if (before !== undefined && !/\s/.test(before))
24
+ return null;
25
+ const query = textBeforeCaret.slice(start + trigger.length);
26
+ if (/\s/.test(query))
27
+ return null;
28
+ return { query, start };
29
+ }
@@ -0,0 +1,88 @@
1
+ import * as React from "react";
2
+ import { caretRectInField } from "./caret-rect.js";
3
+ import { matchMentionTrigger, } from "./mention.js";
4
+ /**
5
+ * Watches a `<textarea>`/`<input>` for an "@query" mention trigger and
6
+ * reports where to anchor a consumer-supplied picker (#372).
7
+ *
8
+ * crisp draws no picker of its own here — GitHub/Slack/Linear-style @mention
9
+ * UI varies too much by app (avatars, groups, recent-first ordering, a
10
+ * "create new person" row) to have one measured shape, and this repo's rule
11
+ * is measure-first, never invented polish. What is shared and worth owning
12
+ * centrally is the fiddly, easy-to-get-wrong part: deciding when "@" is
13
+ * actually a trigger rather than part of a word or an email address (see
14
+ * `matchMentionTrigger`), and where its picker anchors on screen (see
15
+ * `caretRectInField`, since neither element exposes caret geometry itself).
16
+ *
17
+ * Does not close on blur: a picker built from this needs to survive the
18
+ * field losing focus to a `mousedown` on one of its own rows, the same
19
+ * problem every floating surface in this repo solves for itself (see
20
+ * `RichTextEditor`'s toolbar `keepSel`, or `Popover`'s own outside-pointer-
21
+ * down listener) — so closing on outside interaction is left to the
22
+ * consumer's picker, which already knows what counts as "outside" for its
23
+ * own markup.
24
+ */
25
+ export function useMentionTrigger(ref, { trigger = "@" } = {}) {
26
+ const [state, setState] = React.useState({
27
+ open: false,
28
+ query: "",
29
+ anchor: null,
30
+ });
31
+ const matchRef = React.useRef(null);
32
+ const recompute = React.useCallback(() => {
33
+ const el = ref.current;
34
+ if (!el || el.selectionStart == null) {
35
+ matchRef.current = null;
36
+ setState({ open: false, query: "", anchor: null });
37
+ return;
38
+ }
39
+ const caret = el.selectionStart;
40
+ const match = matchMentionTrigger(el.value.slice(0, caret), trigger);
41
+ matchRef.current = match;
42
+ if (!match) {
43
+ setState({ open: false, query: "", anchor: null });
44
+ return;
45
+ }
46
+ setState({
47
+ open: true,
48
+ query: match.query,
49
+ anchor: caretRectInField(el, caret),
50
+ });
51
+ }, [ref, trigger]);
52
+ React.useEffect(() => {
53
+ const el = ref.current;
54
+ if (!el)
55
+ return;
56
+ // "input" covers typing; "click"/"keyup" cover the caret moving without
57
+ // the text changing (arrow keys, clicking elsewhere on the same line).
58
+ el.addEventListener("input", recompute);
59
+ el.addEventListener("click", recompute);
60
+ el.addEventListener("keyup", recompute);
61
+ return () => {
62
+ el.removeEventListener("input", recompute);
63
+ el.removeEventListener("click", recompute);
64
+ el.removeEventListener("keyup", recompute);
65
+ };
66
+ }, [ref, recompute]);
67
+ const close = React.useCallback(() => {
68
+ matchRef.current = null;
69
+ setState({ open: false, query: "", anchor: null });
70
+ }, []);
71
+ const insert = React.useCallback((text) => {
72
+ const el = ref.current;
73
+ const match = matchRef.current;
74
+ if (!el || !match)
75
+ return;
76
+ const caret = el.selectionStart ?? el.value.length;
77
+ const before = el.value.slice(0, match.start);
78
+ const after = el.value.slice(caret);
79
+ el.value = before + text + after;
80
+ const cursor = before.length + text.length;
81
+ el.focus();
82
+ el.setSelectionRange(cursor, cursor);
83
+ // a controlled consumer listens on "input", the same event typing fires
84
+ el.dispatchEvent(new Event("input", { bubbles: true }));
85
+ close();
86
+ }, [ref, close]);
87
+ return { ...state, close, insert };
88
+ }
@@ -1,2 +1,2 @@
1
- export { RecordPanel } from "./recordpanel.js";
1
+ export { RecordPanel, } from "./recordpanel.js";
2
2
  export { recordpanelRecipe } from "./recordpanel.recipe.js";
@@ -1,38 +1,21 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { X } from "lucide-react";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowUpRight, ChevronDown, ChevronUp, X } from "lucide-react";
3
3
  import * as React from "react";
4
4
  import { Avatar } from "../../components/avatar/index.js";
5
- import { Select } from "../../components/select/index.js";
6
- import { Spinner } from "../../components/spinner/index.js";
7
- import { Switch } from "../../components/switch/index.js";
8
5
  import { hasOpenFloatingLayer } from "../../core/index.js";
9
- import { editableInputType, tagTone, useEditableField, } from "../recordstable/index.js";
10
6
  import { recordpanelRecipe } from "./recordpanel.recipe.js";
11
- function FieldValue({ col, row, emptyLabel, }) {
12
- const v = row[col.key];
13
- if (v == null || v === "" || (Array.isArray(v) && !v.length)) {
14
- return _jsx("span", { className: "crisp-recordpanel-empty", children: emptyLabel });
15
- }
16
- switch (col.type) {
17
- case "tags":
18
- return (_jsx(_Fragment, { children: v.map((t) => (_jsx("span", { className: "crisp-recordstable-tag", "data-tone": tagTone(t), children: t }, t))) }));
19
- case "number":
20
- return _jsx(_Fragment, { children: typeof v === "number" ? v.toLocaleString() : v });
21
- case "url":
22
- return (_jsx("a", { className: "crisp-recordpanel-link", href: `https://${v}`, target: "_blank", rel: "noreferrer", children: v }));
23
- default:
24
- return _jsx(_Fragment, { children: String(v) });
25
- }
26
- }
27
7
  /**
28
- * Right-side record peek panel — shows one record's fields, opened from a
29
- * RecordsTable row (via `onOpenRecord`). Render it inside a `position:
30
- * relative` container (e.g. the app main area); it slides in from the right and
31
- * overlays the content.
8
+ * Right-side record peek panel — Attio's own peek shows a Highlights card
9
+ * area and an Activity feed (measured live: hover a Companies row, click its
10
+ * "Open preview" trigger), never an editable field list (#448 — a "Details"
11
+ * list was this component's own invention before, and #431's editable API
12
+ * had nothing real in this panel to attach to; that API stays on
13
+ * `RecordPage`'s own Details column, where Attio does let you edit in
14
+ * place). Render it inside a `position: relative` container (e.g. the app
15
+ * main area); it slides in from the right and overlays the content.
32
16
  */
33
- export function RecordPanel({ record, columns, onClose, className, closeLabel = "Close panel", title, detailsLabel = "Details", emptyLabel = "Empty", footer, onEdit, ...rest }) {
17
+ export function RecordPanel({ record, onClose, className, closeLabel = "Close panel", onOpenRecord, openRecordLabel = "Open record", onPrevious, previousRecordLabel = "Previous record", onNext, nextRecordLabel = "Next record", title, avatar, avatarTone = "brand", highlightsLabel = "Highlights", highlights, activityLabel = "Activity", viewAllActivityLabel = "View all", onViewAllActivity, activity, footer, ...rest }) {
34
18
  const titleId = React.useId();
35
- const { editingKey, pendingKey, error, openEditing, closeEditing, commit } = useEditableField(onEdit);
36
19
  // close on Escape while open -- but not when a Menu/Select/Popover/
37
20
  // ContextMenu opened from inside the panel (e.g. a footer "More actions"
38
21
  // menu) is itself open (#361): that Escape belongs to the nested layer,
@@ -57,67 +40,16 @@ export function RecordPanel({ record, columns, onClose, className, closeLabel =
57
40
  if (!record)
58
41
  return;
59
42
  const onKey = (e) => {
60
- if (e.key !== "Escape")
61
- return;
62
- // #431: Escape while a field is open cancels JUST that field, the
63
- // same way DataTable's own editable cells treat it -- not the whole
64
- // panel. Checked ahead of `hasOpenFloatingLayer()` (capture phase, so
65
- // this runs before the field's own bubble-phase onKeyDown would ever
66
- // get a chance to stopPropagation -- same reasoning as the
67
- // floating-layer check below).
68
- if (editingKey) {
69
- closeEditing();
70
- return;
71
- }
72
- if (hasOpenFloatingLayer())
43
+ if (e.key !== "Escape" || hasOpenFloatingLayer())
73
44
  return;
74
45
  onClose();
75
46
  };
76
47
  document.addEventListener("keydown", onKey, true);
77
48
  return () => document.removeEventListener("keydown", onKey, true);
78
- }, [record, onClose, editingKey, closeEditing]);
49
+ }, [record, onClose]);
79
50
  if (!record)
80
51
  return null;
81
- const entityCol = columns.find((c) => c.type === "entity");
82
- const entity = entityCol
83
- ? record[entityCol.key]
84
- : undefined;
85
- const fields = columns.filter((c) => c.type !== "entity");
86
- const heading = title ?? entity?.name ?? "Record";
87
- return (_jsxs("div", { className: recordpanelRecipe({ className }), ...rest, role: "dialog", "aria-labelledby": titleId, children: [_jsxs("div", { className: "crisp-recordpanel-header", children: [entity?.avatar ? (_jsx("img", { className: "crisp-recordpanel-fav", src: entity.avatar, alt: "" })) : entity ? (_jsx(Avatar, { size: "md", shape: "rounded", tone: "brand", children: entity.name.charAt(0) })) : null, _jsx("span", { id: titleId, className: "crisp-recordpanel-title", children: heading }), _jsx("button", { type: "button", className: "crisp-recordpanel-iconbtn", "aria-label": closeLabel, onClick: onClose, children: _jsx(X, { size: 18, strokeWidth: 1.75 }) })] }), _jsxs("div", { className: "crisp-recordpanel-body", children: [_jsx("div", { className: "crisp-recordpanel-sectionlabel", children: detailsLabel }), fields.map((col) => {
88
- // #431: a field only actually opens when there's an `onEdit` to
89
- // commit through -- `editable` with nothing to call would be a
90
- // dead click.
91
- const canEdit = Boolean(col.editable && onEdit);
92
- const isPending = pendingKey === col.key;
93
- const fieldError = error?.key === col.key ? error.message : null;
94
- // select/switch are always their own live widget -- no click-to-
95
- // open, no separate edit/view mode, the same convention
96
- // DataTable's identical `editor` columns use (#385): choosing a
97
- // value or flipping a toggle IS the commit gesture.
98
- if (canEdit && col.editor) {
99
- const value = record[col.key];
100
- return (_jsxs("div", { className: "crisp-recordpanel-field", children: [_jsxs("span", { className: "crisp-recordpanel-field-label", children: [col.icon ? _jsx(col.icon, { size: 15, strokeWidth: 1.75 }) : null, col.label] }), _jsxs("span", { className: "crisp-recordpanel-field-value", children: [_jsxs("span", { className: "crisp-recordpanel-edit-picker", children: [col.editor === "select" ? (_jsx(Select, { variant: "ghost", "aria-label": `Edit ${col.label}`, value: value != null ? String(value) : undefined, disabled: isPending, options: col.editOptions ?? [], onValueChange: (v) => commit(record.id, col.key, v) })) : (_jsx(Switch, { "aria-label": `Edit ${col.label}`, checked: value === true || value === "true", disabled: isPending, onCheckedChange: (checked) => commit(record.id, col.key, String(checked)) })), isPending && (_jsx(Spinner, { size: 14, className: "crisp-recordpanel-edit-pending" }))] }), fieldError && (_jsx("span", { className: "crisp-recordpanel-edit-error", children: fieldError }))] })] }, col.key));
101
- }
102
- if (canEdit && editingKey === col.key) {
103
- const value = record[col.key];
104
- const editor = editableInputType(col.type);
105
- return (_jsxs("div", { className: "crisp-recordpanel-field", children: [_jsxs("span", { className: "crisp-recordpanel-field-label", children: [col.icon ? _jsx(col.icon, { size: 15, strokeWidth: 1.75 }) : null, col.label] }), _jsxs("span", { className: "crisp-recordpanel-field-value", children: [_jsx("input", { className: "crisp-recordpanel-edit",
106
- // biome-ignore lint/a11y/noAutofocus: focus the field the moment it opens
107
- autoFocus: true, ...editor, disabled: isPending, defaultValue: value == null ? "" : String(value), "aria-label": `Edit ${col.label}`, onKeyDown: (e) => {
108
- if (isPending)
109
- return;
110
- if (e.key === "Enter")
111
- commit(record.id, col.key, e.currentTarget.value);
112
- else if (e.key === "Escape")
113
- closeEditing();
114
- }, onBlur: (e) => {
115
- if (isPending)
116
- return;
117
- commit(record.id, col.key, e.currentTarget.value);
118
- } }), isPending && (_jsx(Spinner, { size: 14, className: "crisp-recordpanel-edit-pending" })), fieldError && (_jsx("span", { className: "crisp-recordpanel-edit-error", children: fieldError }))] })] }, col.key));
119
- }
120
- return (_jsxs("div", { className: "crisp-recordpanel-field", children: [_jsxs("span", { className: "crisp-recordpanel-field-label", children: [col.icon ? _jsx(col.icon, { size: 15, strokeWidth: 1.75 }) : null, col.label] }), _jsxs("span", { className: "crisp-recordpanel-field-value", "data-editable": canEdit ? "" : undefined, children: [canEdit ? (_jsx("button", { type: "button", className: "crisp-recordpanel-edit-trigger", onClick: () => openEditing(col.key), children: _jsx(FieldValue, { col: col, row: record, emptyLabel: emptyLabel }) })) : (_jsx(FieldValue, { col: col, row: record, emptyLabel: emptyLabel })), fieldError && (_jsx("span", { className: "crisp-recordpanel-edit-error", children: fieldError }))] })] }, col.key));
121
- })] }), footer != null && (_jsx("div", { className: "crisp-recordpanel-footer", children: footer }))] }));
52
+ const heading = title ?? record.name ?? "Record";
53
+ return (_jsxs("div", { className: recordpanelRecipe({ className }), ...rest, role: "dialog", "aria-labelledby": titleId, children: [_jsxs("div", { className: "crisp-recordpanel-toolbar", children: [_jsx("button", { type: "button", className: "crisp-recordpanel-iconbtn", "aria-label": closeLabel, onClick: onClose, children: _jsx(X, { size: 16, strokeWidth: 1.75 }) }), (onPrevious || onNext) && (_jsxs("span", { className: "crisp-recordpanel-pager", children: [_jsx("button", { type: "button", className: "crisp-recordpanel-navbtn", "aria-label": previousRecordLabel, disabled: !onPrevious, onClick: onPrevious, children: _jsx(ChevronUp, { size: 16, strokeWidth: 1.75 }) }), _jsx("button", { type: "button", className: "crisp-recordpanel-navbtn", "aria-label": nextRecordLabel, disabled: !onNext, onClick: onNext, children: _jsx(ChevronDown, { size: 16, strokeWidth: 1.75 }) })] })), _jsx("span", { className: "crisp-recordpanel-toolbar-spacer" }), onOpenRecord && (_jsx("button", { type: "button", className: "crisp-recordpanel-navbtn", "aria-label": openRecordLabel, onClick: onOpenRecord, children: _jsx(ArrowUpRight, { "data-rtl-flip": "", size: 16, strokeWidth: 1.75 }) }))] }), _jsxs("div", { className: "crisp-recordpanel-header", children: [avatar ? (_jsx("img", { className: "crisp-recordpanel-fav", src: avatar, alt: "" })) : (_jsx(Avatar, { size: "md", shape: "rounded", tone: avatarTone, children: (record.name ?? "?").charAt(0) })), _jsx("span", { id: titleId, className: "crisp-recordpanel-title", children: heading })] }), _jsxs("div", { className: "crisp-recordpanel-body", children: [highlights && highlights.length > 0 && (_jsxs("div", { className: "crisp-recordpanel-section", children: [_jsx("div", { className: "crisp-recordpanel-section-head", children: _jsx("span", { className: "crisp-recordpanel-section-label", children: highlightsLabel }) }), _jsx("div", { className: "crisp-recordpanel-highlights", children: highlights.map((h) => (_jsxs("div", { className: "crisp-recordpanel-highlight", children: [_jsxs("span", { className: "crisp-recordpanel-highlight-label", children: [_jsx("span", { children: h.label }), h.icon ? _jsx(h.icon, { size: 16, strokeWidth: 1.75 }) : null] }), _jsx("span", { className: "crisp-recordpanel-highlight-value", children: h.value })] }, h.key))) })] })), activity != null && (_jsxs("div", { className: "crisp-recordpanel-section", children: [_jsxs("div", { className: "crisp-recordpanel-section-head", children: [_jsx("span", { className: "crisp-recordpanel-section-label", children: activityLabel }), onViewAllActivity && (_jsx("button", { type: "button", className: "crisp-recordpanel-section-action", onClick: onViewAllActivity, children: viewAllActivityLabel }))] }), _jsx("div", { className: "crisp-recordpanel-activity", children: activity })] }))] }), footer != null && (_jsx("div", { className: "crisp-recordpanel-footer", children: footer }))] }));
122
54
  }
123
55
  RecordPanel.displayName = "RecordPanel";
@@ -1,9 +1,9 @@
1
- import { defineRecipe, resolveRecipe } from "../../core/index.js";
1
+ import { defineRecipe, resolveRecipe, rtlFlipCss } from "../../core/index.js";
2
2
  import { contract as c, elevation as e } from "../../tokens/index.js";
3
- import { recordTagCss } from "../recordstable/recordstable.tag.js";
4
3
  // A right-side record peek panel — slides in over the main content to show one
5
- // record's fields, the way a row peek panel opens. Positioned absolutely inside a
6
- // relative container (the app main area); slides in via @starting-style.
4
+ // record's Highlights and Activity, the way Attio's own peek does. Positioned
5
+ // absolutely inside a relative container (the app main area); slides in via
6
+ // @starting-style.
7
7
  const config = defineRecipe({
8
8
  name: "recordpanel",
9
9
  base: `
@@ -18,53 +18,60 @@ const config = defineRecipe({
18
18
  @starting-style { transform: translateX(calc(100% + ${c.space["2"]})); }
19
19
  & * { box-sizing: border-box; }
20
20
 
21
- & .crisp-recordpanel-header { display: flex; align-items: center; gap: ${c.space["2"]}; height: 52px; flex-shrink: 0; padding: 0 ${c.space["3"]}; border-bottom: 1px solid ${c.borderSubtle}; }
21
+ /* #448: measured live on app.attio.com's peek -- a toolbar row above
22
+ the identity header: Close, then Previous/Next, on the left; "Open
23
+ record" on the right. 49px tall, 8px/10px padding, a hairline border
24
+ beneath (the same borderSubtle every other panel/row edge here
25
+ already uses). Close keeps the existing transparent ghost button;
26
+ Previous/Next/Open record are a distinct field-elevation style
27
+ (white fill, e.field's own ring+shadow, solid icon) -- measured as
28
+ genuinely different chrome from Close, not a reuse. */
29
+ & .crisp-recordpanel-toolbar { display: flex; align-items: center; height: 49px; flex-shrink: 0; padding: ${c.space["2"]} ${c.space["2.5"]}; border-bottom: 1px solid ${c.borderSubtle}; }
30
+ & .crisp-recordpanel-toolbar-spacer { flex: 1; }
31
+ & .crisp-recordpanel-pager { display: flex; align-items: center; gap: ${c.space["1.5"]}; margin-inline-start: ${c.space["3"]}; }
32
+ & .crisp-recordpanel-iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex-shrink: 0; padding: 0; border: none; border-radius: ${c.radius.md}; background: transparent; color: color-mix(in srgb, ${c.fgPrimary} 55%, transparent); font-family: inherit; cursor: pointer; transition: background-color .12s; }
33
+ & .crisp-recordpanel-iconbtn:hover { background: ${c.bgRaised}; color: ${c.fgPrimary}; }
34
+ & .crisp-recordpanel-navbtn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex-shrink: 0; padding: 0; border: none; border-radius: ${c.radius.md}; background: ${c.bgSurface}; box-shadow: ${e.field}; color: ${c.fgPrimary}; font-family: inherit; cursor: pointer; }
35
+ & .crisp-recordpanel-navbtn:hover:not(:disabled) { background: ${c.bgRaised}; }
36
+ & .crisp-recordpanel-navbtn:disabled { opacity: 0.4; cursor: not-allowed; }
37
+
38
+ & .crisp-recordpanel-header { display: flex; align-items: center; gap: ${c.space["2"]}; height: 52px; flex-shrink: 0; padding: 0 ${c.space["3"]}; }
22
39
  & .crisp-recordpanel-fav { width: 22px; height: ${c.size.chip}; border-radius: ${c.radius.sm}; flex-shrink: 0; object-fit: cover; background: ${c.bgRaised}; }
23
40
  & .crisp-recordpanel-title { flex: 1; min-width: 0; font-size: ${c.text.xl}; font-weight: ${c.weight.semibold}; letter-spacing: -0.2px; color: ${c.fgPrimary}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
24
- & .crisp-recordpanel-iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex-shrink: 0; padding: 0; border: none; border-radius: ${c.radius.md}; background: transparent; color: ${c.fgMuted}; font-family: inherit; cursor: pointer; transition: background-color .12s; }
25
- & .crisp-recordpanel-iconbtn:hover { background: ${c.bgRaised}; color: ${c.fgPrimary}; }
26
41
 
27
42
  & .crisp-recordpanel-body { flex: 1; min-height: 0; overflow-y: auto; padding: ${c.space["2"]} ${c.space["3"]}; }
28
- & .crisp-recordpanel-sectionlabel { font-size: ${c.text.sm}; font-weight: ${c.weight.medium}; color: ${c.fgMuted}; padding: ${c.space["2"]} ${c.space["1"]} ${c.space["1"]}; }
29
- & .crisp-recordpanel-field { display: flex; align-items: flex-start; gap: ${c.space["2"]}; min-height: 32px; padding: ${c.space["1"]} ${c.space["1"]}; border-radius: ${c.radius.md}; }
30
- & .crisp-recordpanel-field:hover { background: color-mix(in srgb, ${c.fgPrimary} 3%, transparent); }
31
- & .crisp-recordpanel-field-label { display: flex; align-items: center; gap: ${c.space["1.5"]}; width: 132px; flex-shrink: 0; padding-top: 3px; color: ${c.fgMuted}; font-size: ${c.text.md}; }
32
- & .crisp-recordpanel-field-label svg { flex-shrink: 0; }
33
- & .crisp-recordpanel-field-value { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: ${c.space["1"]}; padding-top: 3px; font-size: ${c.text.lg}; color: ${c.fgPrimary}; }
34
- & .crisp-recordpanel-field-value[data-editable] { cursor: pointer; }
35
- /* the click-to-edit trigger is a real <button> (keyboard-operable),
36
- reset back to plain inline text and made a flex-wrap container of its
37
- own -- FieldValue can render several chips (tags), which still need
38
- to wrap the way they did before this had a button around them at
39
- all. It wraps only FieldValue, never the error slot beside it (see
40
- the component's own comment) -- NOT \`display: contents\`, which
41
- drops a button's accessible semantics in some engines. */
42
- & .crisp-recordpanel-edit-trigger { display: inline-flex; flex-wrap: wrap; align-items: center; gap: ${c.space["1"]}; margin: 0; padding: 0; border: none; background: none; text-align: start; font: inherit; color: inherit; cursor: pointer; }
43
- & .crisp-recordpanel-empty { color: ${c.fgMuted}; }
44
43
 
45
- /* #431: measured live on app.attio.com's record side panel -- clicking a
46
- field's value opens a plain, borderless field exactly filling the
47
- value's own box (no border, no background, no box-shadow), same font
48
- as the value it replaces (hence \`font: inherit\`, not a restated
49
- size/weight). A field row's own hover tint above already carries the
50
- "this is interactive" affordance; the pending/error treatment isn't
51
- Attio-measured -- it reuses the same tokens DataTable's identical
52
- states already use (opacity 0.5, \`bgDanger\`), per #385/#430. */
53
- & .crisp-recordpanel-edit { display: block; width: 100%; margin: 0; padding: 0; border: none; border-radius: ${c.radius.sm}; background: none; box-shadow: none; outline: none; font: inherit; color: inherit; }
54
- /* not Attio-measured (its own field shows no focus ring either, caret
55
- only) -- kept for real keyboard users, the same brand ring every
56
- other crisp field already shows on focus (DataTable's identical
57
- .crisp-datatable-edit:focus, e.g.). */
58
- & .crisp-recordpanel-edit:focus { box-shadow: inset 0 0 0 1px ${c.bgBrandSolid}; }
59
- & .crisp-recordpanel-edit:disabled { opacity: 0.5; cursor: not-allowed; }
60
- & .crisp-recordpanel-edit-pending { flex-shrink: 0; color: ${c.fgMuted}; }
61
- & .crisp-recordpanel-edit-error { flex-basis: 100%; margin-top: ${c.space["0.5"]}; font-size: ${c.text.sm}; color: ${c.bgDanger}; }
62
- & .crisp-recordpanel-edit-picker { display: flex; align-items: center; gap: ${c.space["1"]}; width: 100%; }
63
- & .crisp-recordpanel-edit-picker .crisp-select-trigger { flex: 1; min-width: 0; }
44
+ /* #448: measured live on app.attio.com's peek (hover a Companies row,
45
+ click "Open preview"). Section label reads identically for both
46
+ Highlights and Activity: 14px/500, the same 63%-of-fgPrimary mix
47
+ RecordPage's own field-label already uses (product/recordpage's
48
+ .crisp-recordpage-field-label) -- one more surface landing on the
49
+ same measured "muted section heading" colour. */
50
+ & .crisp-recordpanel-section { padding: ${c.space["2"]} ${c.space["1"]} 0; }
51
+ & .crisp-recordpanel-section-head { display: flex; align-items: center; justify-content: space-between; gap: ${c.space["2"]}; height: 20px; margin-bottom: ${c.space["2"]}; }
52
+ & .crisp-recordpanel-section-label { font-size: ${c.text.lg}; font-weight: ${c.weight.medium}; color: color-mix(in srgb, ${c.fgPrimary} 63%, transparent); }
53
+ /* "View all" -- measured 10px/400, a lighter mix than the section label
54
+ (55%, not 63%) -- its own distinct, honestly-measured value, not a
55
+ reuse of a nearby one that happened to be close. */
56
+ & .crisp-recordpanel-section-action { border: none; background: none; padding: 0; font-family: inherit; font-size: 10px; font-weight: ${c.weight.regular}; color: color-mix(in srgb, ${c.fgPrimary} 55%, transparent); cursor: pointer; }
57
+ & .crisp-recordpanel-section-action:hover { color: ${c.fgPrimary}; }
64
58
 
65
- ${recordTagCss}
66
- & .crisp-recordpanel-link { color: ${c.bgBrandSolid}; text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
67
- & .crisp-recordpanel-link:hover { text-decoration: underline; }
59
+ /* Highlights: a 2-column grid of label+icon+value cards, no card
60
+ chrome at all (no border/background/radius/shadow -- confirmed on
61
+ the live DOM: every highlight's computed style is fully transparent).
62
+ 8px row/column gap; two rows measured "233x86" inside 473px content
63
+ width is exactly (473 - 8) / 2. */
64
+ & .crisp-recordpanel-highlights { display: grid; grid-template-columns: 1fr 1fr; gap: ${c.space["2"]}; }
65
+ & .crisp-recordpanel-highlight { display: flex; flex-direction: column; gap: ${c.space["1.5"]}; min-width: 0; }
66
+ & .crisp-recordpanel-highlight-label { display: flex; align-items: center; gap: ${c.space["1"]}; font-size: ${c.text.sm}; font-weight: ${c.weight.medium}; color: color-mix(in srgb, ${c.fgPrimary} 63%, transparent); }
67
+ & .crisp-recordpanel-highlight-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
68
+ & .crisp-recordpanel-highlight-label svg { flex-shrink: 0; color: ${c.fgMuted}; }
69
+ & .crisp-recordpanel-highlight-value { font-size: ${c.text.lg}; font-weight: ${c.weight.medium}; color: ${c.fgPrimary}; overflow: hidden; text-overflow: ellipsis; }
70
+
71
+ /* Activity is a consumer-supplied slot (crisp has no activity-feed
72
+ model of its own to render) -- this only wraps it with the measured
73
+ section heading above. */
74
+ & .crisp-recordpanel-activity { font-size: ${c.text.lg}; }
68
75
 
69
76
  /* #329: an optional slot for record actions (e.g. Edit). Reuses the
70
77
  header's own measured values rather than inventing new ones -- the
@@ -73,6 +80,8 @@ const config = defineRecipe({
73
80
  edge), and the header/body gap (space.2) for its own vertical padding
74
81
  and for spacing between whatever it's given. */
75
82
  & .crisp-recordpanel-footer { flex-shrink: 0; display: flex; align-items: center; gap: ${c.space["2"]}; padding: ${c.space["2"]} ${c.space["3"]}; border-top: 1px solid ${c.borderSubtle}; }
83
+
84
+ ${rtlFlipCss}
76
85
  `,
77
86
  variants: {},
78
87
  defaultVariants: {},
@@ -1,17 +1,20 @@
1
1
  import * as React from "react";
2
2
  /**
3
- * The async-commit state machine behind `RecordPanel`/`RecordPage`'s
4
- * editable fields (#431) — the same shape `DataTable`'s own `commitEdit`
5
- * uses (#385/#430): a sync `onEdit` (returns `undefined`) commits and closes
3
+ * The async-commit state machine behind `RecordPage`'s editable Details
4
+ * column (#431) — the same shape `DataTable`'s own `commitEdit` uses
5
+ * (#385/#430): a sync `onEdit` (returns `undefined`) commits and closes
6
6
  * immediately; a Promise-returning `onEdit` keeps the field open and pending
7
7
  * while it settles, then either closes it (resolve) or closes it AND
8
8
  * reverts while showing the rejection's message (reject). The revert needs
9
- * no extra code here either: neither `RecordPanel` nor `RecordPage` mutates
10
- * `record` itself, so once `editingKey` clears, the field simply renders
11
- * `record[key]` again — whatever it still says.
9
+ * no extra code here either: `RecordPage` never mutates `record` itself, so
10
+ * once `editingKey` clears, the field simply renders `record[key]` again —
11
+ * whatever it still says.
12
12
  *
13
- * One hook shared by both consumers rather than two copies of the same
14
- * three `useState`s and the same `.then` branching.
13
+ * `RecordPanel` (the peek panel) used to share this hook too, before #448
14
+ * found that Attio's own peek has no editable field at all to attach it to
15
+ * — only `RecordPage`'s Details column does. Kept as its own module rather
16
+ * than folded back into `recordpage.tsx`: a second consumer turning up
17
+ * again is a smaller change than re-extracting it would be.
15
18
  */
16
19
  export function useEditableField(onEdit) {
17
20
  const [editingKey, setEditingKey] = React.useState(null);
@@ -4,9 +4,14 @@ import { contract as c } from "../../tokens/index.js";
4
4
  * `border-radius: ${c.radius.chip}`, 14px/20px at weight 500, and a 1px inset ring in the
5
5
  * tone's colour.
6
6
  *
7
- * Shared because RecordsTable and RecordPanel render the *same* chip. It used
8
- * to be pasted into both recipes, and the two copies had already started to
9
- * drift — adding the measured inset ring meant patching the same rules twice.
7
+ * Its own module (not pasted into `recordstable.recipe.ts`) because it used
8
+ * to be shared with `RecordPanel`'s own Details field list too, and the two
9
+ * copies had already started to drift before that sharing existed — adding
10
+ * the measured inset ring meant patching the same rules twice. `RecordPanel`
11
+ * no longer renders a Details list (#448, Attio's own peek doesn't have
12
+ * one), so `RecordsTable` is this module's only consumer now; kept as its
13
+ * own file rather than folded back in, since a second consumer showing up
14
+ * again is exactly how the drift happened the first time.
10
15
  */
11
16
  export const recordTagCss = `& .crisp-recordstable-tag { display: inline-flex; align-items: center; height: ${c.size.chip}; padding: 0 ${c.space["1"]}; border-radius: ${c.radius.chip}; font-size: ${c.text.lg}; line-height: 20px; font-weight: ${c.weight.medium}; white-space: nowrap; background: color-mix(in srgb, ${c.fgPrimary} 6%, transparent); color: color-mix(in srgb, ${c.fgPrimary} 82%, transparent); box-shadow: inset 0 0 0 1px ${c.borderSubtle}; }
12
17
  & .crisp-recordstable-tag[data-tone="brand"] { background: color-mix(in srgb, ${c.bgBrandSolid} 14%, transparent); color: color-mix(in srgb, ${c.bgBrandSolid} 82%, ${c.fgPrimary}); box-shadow: inset 0 0 0 1px color-mix(in srgb, ${c.bgBrandSolid} 30%, transparent); }
@@ -1,2 +1,2 @@
1
- export { RichTextEditor, } from "./richtext.js";
1
+ export { RICHTEXT_COLOR_TONES, RichTextEditor, } from "./richtext.js";
2
2
  export { richtextRecipe } from "./richtext.recipe.js";