@stll/ui 0.89.1 → 0.90.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.
- package/dist/calendar/day-calendar.d.ts +11 -0
- package/dist/calendar/day-calendar.js +9 -3
- package/dist/components/composer-frame.d.ts +22 -0
- package/dist/components/composer-frame.js +139 -0
- package/dist/components/composer-frame.native.d.ts +29 -0
- package/dist/components/composer-frame.native.js +105 -0
- package/dist/components/composer-frame.shared.d.ts +50 -0
- package/dist/components/composer-frame.shared.js +0 -0
- package/dist/components/composer-layout.d.ts +35 -0
- package/dist/components/composer-layout.js +52 -0
- package/dist/components/composer-tokens.d.ts +24 -44
- package/dist/components/composer-tokens.js +25 -45
- package/dist/components/composer.d.ts +2 -15
- package/dist/components/composer.js +2 -17
- package/dist/components/control-face.js +1 -1
- package/dist/components/details-grid.js +7 -3
- package/dist/components/dialog-form-state.js +4 -3
- package/dist/components/entity-actions.d.ts +33 -1
- package/dist/components/entity-actions.js +47 -23
- package/dist/components/hex-color-picker.js +1 -1
- package/dist/components/landing-shell.d.ts +3 -3
- package/dist/components/landing-shell.js +20 -27
- package/dist/components/menu.d.ts +7 -1
- package/dist/components/menu.js +8 -3
- package/dist/components/outcome-screen.js +1 -1
- package/dist/components/outline-rail.js +13 -12
- package/dist/components/select.js +1 -1
- package/dist/components/settings.d.ts +6 -0
- package/dist/components/settings.js +14 -3
- package/dist/components/sheet.native.js +3 -3
- package/dist/components/sidebar.js +15 -7
- package/dist/components/switch.js +2 -2
- package/dist/components/switch.native.d.ts +2 -1
- package/dist/components/switch.native.js +6 -5
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.js +2 -2
- package/dist/components/textarea.native.d.ts +6 -3
- package/dist/components/textarea.native.js +27 -8
- package/dist/components/textarea.shared.d.ts +8 -1
- package/dist/components/toggle-classes.d.ts +9 -2
- package/dist/components/toggle-classes.js +10 -3
- package/dist/data-table/schema.js +1 -5
- package/dist/effects/dom.d.ts +53 -0
- package/dist/effects/dom.js +177 -0
- package/dist/effects/effects.d.ts +88 -0
- package/dist/effects/effects.js +196 -0
- package/dist/hooks/use-inline-overflow.d.ts +2 -2
- package/dist/hooks/use-inline-overflow.js +12 -15
- package/dist/hooks/use-latest.d.ts +2 -19
- package/dist/hooks/use-latest.js +1 -27
- package/dist/icons.d.ts +2 -2
- package/dist/icons.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/slot.js +7 -3
- package/dist/styles/theme.css +29 -0
- package/package.json +17 -1
|
@@ -57,6 +57,15 @@ export type DayCalendarBlock = (DayCalendarBlockFields & {
|
|
|
57
57
|
kind: "mixed";
|
|
58
58
|
}) | (DayCalendarBlockFields & {
|
|
59
59
|
kind: "segment";
|
|
60
|
+
}) |
|
|
61
|
+
/** Time that should have been recorded and was not: drawn hatched. */
|
|
62
|
+
(DayCalendarBlockFields & {
|
|
63
|
+
kind: "unrecorded";
|
|
64
|
+
}) |
|
|
65
|
+
/** Time that was only scheduled, such as a calendar event: drawn as an
|
|
66
|
+
* outline, never as recorded or entered time. */
|
|
67
|
+
(DayCalendarBlockFields & {
|
|
68
|
+
kind: "scheduled";
|
|
60
69
|
});
|
|
61
70
|
export type DayCalendarRangeSelection = {
|
|
62
71
|
label: string;
|
|
@@ -68,6 +77,8 @@ type DayCalendarColumnHeader = {
|
|
|
68
77
|
badge?: ReactNode;
|
|
69
78
|
id: string;
|
|
70
79
|
label: ReactNode;
|
|
80
|
+
/** `narrow` for a lane that only annotates the columns beside it. */
|
|
81
|
+
width?: "narrow";
|
|
71
82
|
};
|
|
72
83
|
/**
|
|
73
84
|
* A `locked` column has no blocks field, so caller data cannot reach it: it
|
|
@@ -11,6 +11,10 @@ import { useState } from "react";
|
|
|
11
11
|
import { panic } from "better-result";
|
|
12
12
|
import { Temporal } from "temporal-polyfill/full";
|
|
13
13
|
// src/calendar/day-calendar.tsx
|
|
14
|
+
const COLUMN_TRACKS = {
|
|
15
|
+
narrow: "minmax(0, 0.6fr)",
|
|
16
|
+
regular: "minmax(0, 1fr)"
|
|
17
|
+
};
|
|
14
18
|
const isSameDraftView = (left, right) => left.date === right.date && left.endHour === right.endHour && left.granularity === right.granularity && left.startHour === right.startHour && left.timeZone === right.timeZone;
|
|
15
19
|
/**
|
|
16
20
|
* A draft's range belongs to the day and grid it was made on; once they
|
|
@@ -173,7 +177,7 @@ const DayCalendar = ({ ariaLabel, columns, date, granularity, hours, locale, now
|
|
|
173
177
|
return;
|
|
174
178
|
}
|
|
175
179
|
};
|
|
176
|
-
const gridStyle = { gridTemplateColumns:
|
|
180
|
+
const gridStyle = { gridTemplateColumns: [GUTTER_WIDTH, ...columns.map(({ width }) => COLUMN_TRACKS[width ?? "regular"])].join(" ") };
|
|
177
181
|
const bodyStyle = { blockSize: height };
|
|
178
182
|
const slotHeight = DAY_CALENDAR_SLOT_HEIGHT_PX[granularity];
|
|
179
183
|
const slotLinesStyle = {
|
|
@@ -336,7 +340,9 @@ const BLOCK_MIN_PX = 6;
|
|
|
336
340
|
const BLOCK_KIND_CLASSES = {
|
|
337
341
|
entry: "font-medium",
|
|
338
342
|
mixed: "text-muted-foreground",
|
|
339
|
-
|
|
343
|
+
scheduled: "text-muted-foreground border border-current/40",
|
|
344
|
+
segment: "",
|
|
345
|
+
unrecorded: "text-muted-foreground border border-dashed border-current/30 bg-[repeating-linear-gradient(135deg,transparent_0_6px,color-mix(in_oklab,currentColor_12%,transparent)_6px_12px)]"
|
|
340
346
|
};
|
|
341
347
|
const ENTRY_STATE_CLASSES = {
|
|
342
348
|
draft: "border border-dashed border-current/40",
|
|
@@ -475,7 +481,7 @@ function blockSurfaceStyle(block) {
|
|
|
475
481
|
const tone = block.tone;
|
|
476
482
|
const suggestion = block.kind === "entry" && block.state === "suggestion";
|
|
477
483
|
switch (tone.type) {
|
|
478
|
-
case "neutral": return { backgroundColor: suggestion ? "transparent" : void 0 };
|
|
484
|
+
case "neutral": return { backgroundColor: suggestion || block.kind === "scheduled" ? "transparent" : void 0 };
|
|
479
485
|
case "topic": return {
|
|
480
486
|
"--day-calendar-tone": getTopicColor(tone.key),
|
|
481
487
|
backgroundColor: `color-mix(in srgb, var(--day-calendar-tone) ${String(TOPIC_TINT_PERCENT)}%, var(--card))`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from "react";
|
|
2
|
+
import { ComposerFrameContract } from "./composer-frame.shared.js";
|
|
3
|
+
/** What the box sits on. */
|
|
4
|
+
type ComposerSurface = "page" | "document";
|
|
5
|
+
type ComposerFrameProps = Omit<ComponentProps<"div">, "children" | "className"> & ComposerFrameContract & {
|
|
6
|
+
/** Painted over the start of the text while given, one line tall; its
|
|
7
|
+
* content cuts itself to the line. The surface decides when it shows.
|
|
8
|
+
* A phone's text field draws its own placeholder, so the native frame
|
|
9
|
+
* has no such slot. */
|
|
10
|
+
placeholder?: ReactNode;
|
|
11
|
+
surface?: ComposerSurface | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The one composer box. Every web composer (the chat bar and hero, the
|
|
15
|
+
* docked bar over documents, the law entry box, the Outlook assistant)
|
|
16
|
+
* renders through it. It owns the box, the bar/stacked layout and the
|
|
17
|
+
* switch between them, and the text's scroll region (its height cap, its
|
|
18
|
+
* edge scrollbar, its fades), so no surface lays text and controls out by
|
|
19
|
+
* hand and no control ever covers text.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ComposerFrame: ({ above, attachments, empty, leading, placeholder, ring, stature, surface, text, trailing, ...boxProps }: ComposerFrameProps) => import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../lib/utils.js";
|
|
3
|
+
import { useComposerLayout } from "./composer-layout.js";
|
|
4
|
+
import { COMPOSER_BOX_CLASS, COMPOSER_TEXT_CLASS, COMPOSER_TEXT_REGION_MAX_HEIGHT_CLASS, DOC_FLOAT_SURFACE_CLASS } from "./composer-tokens.js";
|
|
5
|
+
import { ScrollArea } from "./scroll-area.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useCallback } from "react";
|
|
8
|
+
// src/components/composer-frame.tsx
|
|
9
|
+
/**
|
|
10
|
+
* One grid for both layouts; only the cells' placement changes, so a switch
|
|
11
|
+
* never remounts the text slot (an editor would lose its focus and
|
|
12
|
+
* selection). The stacked action row leaves its middle column empty.
|
|
13
|
+
*/
|
|
14
|
+
const COMPOSER_GRID_CLASS = {
|
|
15
|
+
bar: "grid min-h-11 grid-cols-[auto_minmax(0,1fr)_auto] items-end gap-1 px-1.5 py-px",
|
|
16
|
+
stacked: "grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-0.5"
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The text cell. In the bar its block inset makes one `leading-5` line
|
|
20
|
+
* exactly the row's inner height (44px row, 1px inset each side, 42px), so
|
|
21
|
+
* text and controls share one centre. Stacked, it spans the box with no
|
|
22
|
+
* inline-end inset, so the scroll region and its scrollbar reach the box's
|
|
23
|
+
* edge.
|
|
24
|
+
*/
|
|
25
|
+
const COMPOSER_TEXT_CELL_CLASS = {
|
|
26
|
+
bar: "col-start-2 row-start-1 min-w-0 py-[11px]",
|
|
27
|
+
stacked: "col-span-3 row-start-1 min-w-0 ps-3.5 pt-2 pb-1"
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The text inside the scroll region. Stacked, its inline-end inset keeps the
|
|
31
|
+
* text 10px clear of the scrollbar, which the scroll area draws 6px wide and
|
|
32
|
+
* 4px inside the box's edge.
|
|
33
|
+
*/
|
|
34
|
+
const COMPOSER_TEXT_CONTENT_CLASS = {
|
|
35
|
+
bar: "",
|
|
36
|
+
stacked: "pe-5"
|
|
37
|
+
};
|
|
38
|
+
/** Where each control group sits, in each layout. */
|
|
39
|
+
const COMPOSER_LEADING_SEAT_CLASS = {
|
|
40
|
+
bar: "col-start-1 row-start-1 h-[calc(--spacing(11)-2px)] self-end",
|
|
41
|
+
stacked: "col-start-1 row-start-2 ps-1.5 pb-1.5"
|
|
42
|
+
};
|
|
43
|
+
const COMPOSER_TRAILING_SEAT_CLASS = {
|
|
44
|
+
bar: "col-start-3 row-start-1 h-[calc(--spacing(11)-2px)] self-end",
|
|
45
|
+
stacked: "col-start-3 row-start-2 pe-1.5 pb-1.5"
|
|
46
|
+
};
|
|
47
|
+
/** A control group's own layout, in either seat. */
|
|
48
|
+
const COMPOSER_CONTROL_GROUP_CLASS = "flex min-w-0 shrink-0 items-center gap-0.5";
|
|
49
|
+
/** The large box's three-line height, on the editable element itself, so a
|
|
50
|
+
* click anywhere in it lands in the editor. */
|
|
51
|
+
const COMPOSER_LARGE_TEXT_CLASS = "min-h-15 [&_[role=textbox]]:min-h-15 [&_textarea]:min-h-15";
|
|
52
|
+
const COMPOSER_RING_CLASS = {
|
|
53
|
+
none: "",
|
|
54
|
+
focus: "focus-within:border-ring",
|
|
55
|
+
anonymized: "ring-info/40 border-info/40 focus-within:border-info/60 shadow-[0_0_0_4px_rgb(from_var(--color-info)_r_g_b_/_0.08)] ring-1",
|
|
56
|
+
attention: "border-primary ring-primary/40 ring-4"
|
|
57
|
+
};
|
|
58
|
+
const COMPOSER_SURFACE_CLASS = {
|
|
59
|
+
page: "",
|
|
60
|
+
document: cn("shadow-floating-ring", DOC_FLOAT_SURFACE_CLASS)
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The one composer box. Every web composer (the chat bar and hero, the
|
|
64
|
+
* docked bar over documents, the law entry box, the Outlook assistant)
|
|
65
|
+
* renders through it. It owns the box, the bar/stacked layout and the
|
|
66
|
+
* switch between them, and the text's scroll region (its height cap, its
|
|
67
|
+
* edge scrollbar, its fades), so no surface lays text and controls out by
|
|
68
|
+
* hand and no control ever covers text.
|
|
69
|
+
*/
|
|
70
|
+
const ComposerFrame = ({ above, attachments, empty, leading, placeholder, ring, stature, surface = "page", text, trailing, ...boxProps }) => {
|
|
71
|
+
const { layout, measured } = useComposerLayout(stature, empty);
|
|
72
|
+
const measureText = useCallback((content) => {
|
|
73
|
+
if (content === null) return;
|
|
74
|
+
const observer = new ResizeObserver(() => {
|
|
75
|
+
const lineHeight = content.querySelector("[data-slot=\"composer-line-ruler\"]")?.offsetHeight ?? 0;
|
|
76
|
+
if (lineHeight > 0) measured(content.clientHeight, lineHeight);
|
|
77
|
+
});
|
|
78
|
+
observer.observe(content);
|
|
79
|
+
return () => {
|
|
80
|
+
observer.disconnect();
|
|
81
|
+
};
|
|
82
|
+
}, [measured]);
|
|
83
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
84
|
+
"data-slot": "composer-frame",
|
|
85
|
+
...boxProps,
|
|
86
|
+
className: cn(COMPOSER_BOX_CLASS, "relative", COMPOSER_RING_CLASS[ring], COMPOSER_SURFACE_CLASS[surface]),
|
|
87
|
+
"data-composer-layout": layout,
|
|
88
|
+
children: [
|
|
89
|
+
above,
|
|
90
|
+
attachments !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
91
|
+
"data-slot": "composer-attachments",
|
|
92
|
+
children: attachments
|
|
93
|
+
}),
|
|
94
|
+
/* @__PURE__ */ jsxs("div", {
|
|
95
|
+
className: COMPOSER_GRID_CLASS[layout],
|
|
96
|
+
children: [
|
|
97
|
+
/* @__PURE__ */ jsx("div", {
|
|
98
|
+
className: COMPOSER_TEXT_CELL_CLASS[layout],
|
|
99
|
+
children: /* @__PURE__ */ jsx(ScrollArea, {
|
|
100
|
+
axis: "vertical",
|
|
101
|
+
className: COMPOSER_TEXT_REGION_MAX_HEIGHT_CLASS,
|
|
102
|
+
"data-slot": "composer-text-region",
|
|
103
|
+
scrollFade: true,
|
|
104
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
105
|
+
className: cn("relative min-h-5 wrap-anywhere", COMPOSER_TEXT_CLASS, COMPOSER_TEXT_CONTENT_CLASS[layout], stature === "large" && COMPOSER_LARGE_TEXT_CLASS),
|
|
106
|
+
"data-slot": "composer-text",
|
|
107
|
+
ref: measureText,
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ jsx("span", {
|
|
110
|
+
"aria-hidden": "true",
|
|
111
|
+
className: "pointer-events-none invisible absolute start-0 top-0",
|
|
112
|
+
"data-slot": "composer-line-ruler",
|
|
113
|
+
children: ""
|
|
114
|
+
}),
|
|
115
|
+
text,
|
|
116
|
+
placeholder !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
117
|
+
className: "text-foreground-placeholder pointer-events-none absolute inset-x-0 top-0 flex h-5 min-w-0 items-center gap-2",
|
|
118
|
+
children: placeholder
|
|
119
|
+
})
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ jsx("div", {
|
|
125
|
+
className: cn(COMPOSER_CONTROL_GROUP_CLASS, COMPOSER_LEADING_SEAT_CLASS[layout]),
|
|
126
|
+
"data-slot": "composer-leading",
|
|
127
|
+
children: leading
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsx("div", {
|
|
130
|
+
className: cn(COMPOSER_CONTROL_GROUP_CLASS, COMPOSER_TRAILING_SEAT_CLASS[layout]),
|
|
131
|
+
"data-slot": "composer-trailing",
|
|
132
|
+
children: trailing
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
export { ComposerFrame };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren } from "react";
|
|
2
|
+
import { ComposerFrameContract } from "./composer-frame.shared.js";
|
|
3
|
+
import { ViewProps } from "react-native";
|
|
4
|
+
type ComposerFrameProps = Omit<ViewProps, "children"> & ComposerFrameContract & {
|
|
5
|
+
/**
|
|
6
|
+
* Draws the box in place of the bordered one, such as the app's Liquid
|
|
7
|
+
* Glass capsule on iOS (a platform effect this package does not depend
|
|
8
|
+
* on). The frame lays its content out the same inside it; `ring` paints
|
|
9
|
+
* only the bordered box.
|
|
10
|
+
*/
|
|
11
|
+
Box?: ComponentType<PropsWithChildren> | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The web's `ComposerFrame` (./composer-frame.tsx) on a phone: the one
|
|
15
|
+
* composer box, with the same slots and the same rule for its two layouts
|
|
16
|
+
* (./composer-layout.ts). Compact, it is one bar while the text fits one
|
|
17
|
+
* line; the first time the text needs a second line (a wrap or a line
|
|
18
|
+
* break, read from the text's laid-out height against one line of it) the
|
|
19
|
+
* text spans the box over a control row, until the draft is empty again.
|
|
20
|
+
* The text grows to the shared cap, then scrolls itself; the attachments
|
|
21
|
+
* and the controls stay outside that region. Rows run from the start edge,
|
|
22
|
+
* so a right-to-left layout mirrors them.
|
|
23
|
+
*
|
|
24
|
+
* The web's `placeholder` is not a slot here: a phone's text field draws its
|
|
25
|
+
* own. Nor is `surface`: the document a web composer floats over is a web
|
|
26
|
+
* surface; `Box` draws a platform's own box.
|
|
27
|
+
*/
|
|
28
|
+
export declare const ComposerFrame: ({ above, attachments, Box, empty, leading, ring, stature, text, trailing, ...viewProps }: ComposerFrameProps) => import("react").JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { cn } from "../lib/utils.js";
|
|
2
|
+
import { useComposerLayout } from "./composer-layout.js";
|
|
3
|
+
import { COMPOSER_BOX_CLASS, COMPOSER_TEXT_REGION_MAX_HEIGHT_CLASS } from "./composer-tokens.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { View, useWindowDimensions } from "react-native";
|
|
6
|
+
// src/components/composer-frame.native.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The row the text sits in. In the bar it holds the controls too: 54pt, a
|
|
9
|
+
* 42pt text line (a 24pt line, 9pt above and below) inside 6pt of inset.
|
|
10
|
+
* Stacked it is a column: the text over the control row.
|
|
11
|
+
*/
|
|
12
|
+
const COMPOSER_ROW_CLASS = {
|
|
13
|
+
bar: "min-h-[54px] flex-row items-end gap-2 px-2 py-1.5",
|
|
14
|
+
stacked: "pt-1.5"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The text cell. Its first line sits 15pt below the box's top in both
|
|
18
|
+
* layouts, so the switch moves the text sideways only. Stacked it spans the
|
|
19
|
+
* box.
|
|
20
|
+
*/
|
|
21
|
+
const COMPOSER_TEXT_CELL_CLASS = {
|
|
22
|
+
bar: "min-w-0 flex-1 py-2.25",
|
|
23
|
+
stacked: "px-3.5 pt-2.25 pb-1"
|
|
24
|
+
};
|
|
25
|
+
/** The large box's three-line height while empty. */
|
|
26
|
+
const COMPOSER_LARGE_TEXT_CLASS = "min-h-18";
|
|
27
|
+
/** A control group in the bar: one text line tall, so its controls centre
|
|
28
|
+
* on the line. */
|
|
29
|
+
const COMPOSER_BAR_SEAT_CLASS = "h-10.5 flex-row items-center gap-2";
|
|
30
|
+
/** The stacked control row: leading at the start, trailing at the end. */
|
|
31
|
+
const COMPOSER_CONTROL_ROW_CLASS = "flex-row items-center justify-between gap-2 px-2 pb-1.5";
|
|
32
|
+
const COMPOSER_CONTROL_GROUP_CLASS = "flex-row items-center gap-2";
|
|
33
|
+
const COMPOSER_RING_CLASS = {
|
|
34
|
+
none: "border-border",
|
|
35
|
+
focus: "border-border",
|
|
36
|
+
anonymized: "border-info/40",
|
|
37
|
+
attention: "border-primary"
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The web's `ComposerFrame` (./composer-frame.tsx) on a phone: the one
|
|
41
|
+
* composer box, with the same slots and the same rule for its two layouts
|
|
42
|
+
* (./composer-layout.ts). Compact, it is one bar while the text fits one
|
|
43
|
+
* line; the first time the text needs a second line (a wrap or a line
|
|
44
|
+
* break, read from the text's laid-out height against one line of it) the
|
|
45
|
+
* text spans the box over a control row, until the draft is empty again.
|
|
46
|
+
* The text grows to the shared cap, then scrolls itself; the attachments
|
|
47
|
+
* and the controls stay outside that region. Rows run from the start edge,
|
|
48
|
+
* so a right-to-left layout mirrors them.
|
|
49
|
+
*
|
|
50
|
+
* The web's `placeholder` is not a slot here: a phone's text field draws its
|
|
51
|
+
* own. Nor is `surface`: the document a web composer floats over is a web
|
|
52
|
+
* surface; `Box` draws a platform's own box.
|
|
53
|
+
*/
|
|
54
|
+
const ComposerFrame = ({ above, attachments, Box, empty, leading, ring, stature, text, trailing, ...viewProps }) => {
|
|
55
|
+
const { layout, measured } = useComposerLayout(stature, empty);
|
|
56
|
+
const { fontScale } = useWindowDimensions();
|
|
57
|
+
const measureText = (event) => {
|
|
58
|
+
measured(event.nativeEvent.layout.height, 24 * fontScale);
|
|
59
|
+
};
|
|
60
|
+
const bar = layout === "bar";
|
|
61
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
62
|
+
above,
|
|
63
|
+
attachments,
|
|
64
|
+
/* @__PURE__ */ jsxs(View, {
|
|
65
|
+
className: COMPOSER_ROW_CLASS[layout],
|
|
66
|
+
children: [
|
|
67
|
+
bar ? /* @__PURE__ */ jsx(View, {
|
|
68
|
+
className: COMPOSER_BAR_SEAT_CLASS,
|
|
69
|
+
children: leading
|
|
70
|
+
}) : null,
|
|
71
|
+
/* @__PURE__ */ jsx(View, {
|
|
72
|
+
className: COMPOSER_TEXT_CELL_CLASS[layout],
|
|
73
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
74
|
+
className: cn(COMPOSER_TEXT_REGION_MAX_HEIGHT_CLASS, stature === "large" && COMPOSER_LARGE_TEXT_CLASS),
|
|
75
|
+
onLayout: measureText,
|
|
76
|
+
children: text
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
bar ? /* @__PURE__ */ jsx(View, {
|
|
80
|
+
className: COMPOSER_BAR_SEAT_CLASS,
|
|
81
|
+
children: trailing
|
|
82
|
+
}) : null,
|
|
83
|
+
bar ? null : /* @__PURE__ */ jsxs(View, {
|
|
84
|
+
className: COMPOSER_CONTROL_ROW_CLASS,
|
|
85
|
+
children: [/* @__PURE__ */ jsx(View, {
|
|
86
|
+
className: COMPOSER_CONTROL_GROUP_CLASS,
|
|
87
|
+
children: leading
|
|
88
|
+
}), /* @__PURE__ */ jsx(View, {
|
|
89
|
+
className: COMPOSER_CONTROL_GROUP_CLASS,
|
|
90
|
+
children: trailing
|
|
91
|
+
})]
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
] });
|
|
96
|
+
return Box === void 0 ? /* @__PURE__ */ jsx(View, {
|
|
97
|
+
...viewProps,
|
|
98
|
+
className: cn(COMPOSER_BOX_CLASS, COMPOSER_RING_CLASS[ring]),
|
|
99
|
+
children: content
|
|
100
|
+
}) : /* @__PURE__ */ jsx(View, {
|
|
101
|
+
...viewProps,
|
|
102
|
+
children: /* @__PURE__ */ jsx(Box, { children: content })
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
export { ComposerFrame };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* How a frame lays its text and controls out.
|
|
4
|
+
*
|
|
5
|
+
* `bar`: one row: the leading controls, the text, the trailing controls, all
|
|
6
|
+
* centred on the one text line.
|
|
7
|
+
*
|
|
8
|
+
* `stacked`: the text across the whole box on top, the controls in a row
|
|
9
|
+
* beneath it, leading at the start and trailing at the end. Text and
|
|
10
|
+
* controls never share a row, so no control stands beside (or over) a line
|
|
11
|
+
* of text, however long the draft grows.
|
|
12
|
+
*/
|
|
13
|
+
export type ComposerLayout = "bar" | "stacked";
|
|
14
|
+
/**
|
|
15
|
+
* Which composer a frame is.
|
|
16
|
+
*
|
|
17
|
+
* `compact`, the follow-up bar: empty or one line, it is a `bar`; the first
|
|
18
|
+
* time its text needs a second line (a wrap or a line break) it is
|
|
19
|
+
* `stacked`, and it stays stacked until the draft is empty again, so it
|
|
20
|
+
* never flips back and forth at the wrap point while someone types. `empty`
|
|
21
|
+
* is the draft's emptiness, the one thing the switch back reads.
|
|
22
|
+
*
|
|
23
|
+
* `large`, the hero box: always `stacked`, three lines tall while empty.
|
|
24
|
+
*/
|
|
25
|
+
export type ComposerStature = {
|
|
26
|
+
stature: "compact";
|
|
27
|
+
empty: boolean;
|
|
28
|
+
} | {
|
|
29
|
+
stature: "large";
|
|
30
|
+
empty?: never;
|
|
31
|
+
};
|
|
32
|
+
/** Which edge treatment the box wears. */
|
|
33
|
+
export type ComposerRing = "none" | "focus" | "anonymized" | "attention";
|
|
34
|
+
/** The props every composer frame renderer accepts, with one meaning. */
|
|
35
|
+
export type ComposerFrameContract = ComposerStature & {
|
|
36
|
+
/** The editable element: an editor, or a `Textarea` with the `composer`
|
|
37
|
+
* appearance. It grows with its content; the frame caps it and scrolls. */
|
|
38
|
+
text: ReactNode;
|
|
39
|
+
/** Draft attachments, above the text and outside its scroll region. */
|
|
40
|
+
attachments?: ReactNode;
|
|
41
|
+
/** Chrome anchored above the box (preset chips), positioned by the
|
|
42
|
+
* surface from the box's top edge outward. Draft attachments go in
|
|
43
|
+
* `attachments`, never here. */
|
|
44
|
+
above?: ReactNode;
|
|
45
|
+
/** The controls at the start: the (+) menu, a scope control. */
|
|
46
|
+
leading?: ReactNode;
|
|
47
|
+
/** The controls at the end, the primary (send) control last. */
|
|
48
|
+
trailing?: ReactNode;
|
|
49
|
+
ring: ComposerRing;
|
|
50
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ComposerLayout, ComposerStature } from "./composer-frame.shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* What the layout remembers between renders: whether the text has needed a
|
|
4
|
+
* second line since the draft was last empty, and whether it is empty now.
|
|
5
|
+
*/
|
|
6
|
+
export type ComposerLayoutState = {
|
|
7
|
+
readonly secondLine: boolean;
|
|
8
|
+
readonly empty: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** A frame's first state: one line, as empty as its draft. */
|
|
11
|
+
export declare const composerLayoutStart: (empty: boolean) => ComposerLayoutState;
|
|
12
|
+
/**
|
|
13
|
+
* The draft's emptiness, as the surface reports it. The switch back to the
|
|
14
|
+
* bar happens when the draft becomes empty, not while it is: a draft of
|
|
15
|
+
* blank lines is empty yet several lines tall, and resetting on every report
|
|
16
|
+
* would flip it between the two layouts forever.
|
|
17
|
+
*/
|
|
18
|
+
export declare const withDraftEmptiness: (state: ComposerLayoutState, empty: boolean) => ComposerLayoutState;
|
|
19
|
+
/**
|
|
20
|
+
* The text's measured height against one line of it: a wrap, a line break
|
|
21
|
+
* and a taller inline chip all count, where a character count would guess.
|
|
22
|
+
* Once on a second line it stays there until the draft is empty again, so it
|
|
23
|
+
* never flips back and forth at the wrap point while someone types.
|
|
24
|
+
*/
|
|
25
|
+
export declare const withTextHeight: (state: ComposerLayoutState, height: number, lineHeight: number) => ComposerLayoutState;
|
|
26
|
+
/** The layout a frame of this stature draws in this state. */
|
|
27
|
+
export declare const composerLayoutOf: (stature: ComposerStature["stature"], state: ComposerLayoutState) => ComposerLayout;
|
|
28
|
+
/**
|
|
29
|
+
* The frame's layout, kept across renders: `measured` takes each new height
|
|
30
|
+
* of the text and one line of it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const useComposerLayout: (stature: ComposerStature["stature"], empty: boolean | undefined) => {
|
|
33
|
+
layout: ComposerLayout;
|
|
34
|
+
measured: (height: number, lineHeight: number) => void;
|
|
35
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
// src/components/composer-layout.ts
|
|
3
|
+
/** Above this many line heights, the text is on a second line. */
|
|
4
|
+
const SECOND_LINE_THRESHOLD = 1.5;
|
|
5
|
+
/** A frame's first state: one line, as empty as its draft. */
|
|
6
|
+
const composerLayoutStart = (empty) => ({
|
|
7
|
+
secondLine: false,
|
|
8
|
+
empty
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The draft's emptiness, as the surface reports it. The switch back to the
|
|
12
|
+
* bar happens when the draft becomes empty, not while it is: a draft of
|
|
13
|
+
* blank lines is empty yet several lines tall, and resetting on every report
|
|
14
|
+
* would flip it between the two layouts forever.
|
|
15
|
+
*/
|
|
16
|
+
const withDraftEmptiness = (state, empty) => {
|
|
17
|
+
if (state.empty === empty) return state;
|
|
18
|
+
return {
|
|
19
|
+
empty,
|
|
20
|
+
secondLine: empty ? false : state.secondLine
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The text's measured height against one line of it: a wrap, a line break
|
|
25
|
+
* and a taller inline chip all count, where a character count would guess.
|
|
26
|
+
* Once on a second line it stays there until the draft is empty again, so it
|
|
27
|
+
* never flips back and forth at the wrap point while someone types.
|
|
28
|
+
*/
|
|
29
|
+
const withTextHeight = (state, height, lineHeight) => !state.secondLine && height > lineHeight * SECOND_LINE_THRESHOLD ? {
|
|
30
|
+
...state,
|
|
31
|
+
secondLine: true
|
|
32
|
+
} : state;
|
|
33
|
+
/** The layout a frame of this stature draws in this state. */
|
|
34
|
+
const composerLayoutOf = (stature, state) => stature === "large" || state.secondLine ? "stacked" : "bar";
|
|
35
|
+
/**
|
|
36
|
+
* The frame's layout, kept across renders: `measured` takes each new height
|
|
37
|
+
* of the text and one line of it.
|
|
38
|
+
*/
|
|
39
|
+
const useComposerLayout = (stature, empty) => {
|
|
40
|
+
const draftEmpty = empty === true;
|
|
41
|
+
const [state, setState] = useState(() => composerLayoutStart(draftEmpty));
|
|
42
|
+
const current = withDraftEmptiness(state, draftEmpty);
|
|
43
|
+
if (current !== state) setState(current);
|
|
44
|
+
const measured = useCallback((height, lineHeight) => {
|
|
45
|
+
setState((latest) => withTextHeight(latest, height, lineHeight));
|
|
46
|
+
}, []);
|
|
47
|
+
return {
|
|
48
|
+
layout: composerLayoutOf(stature, current),
|
|
49
|
+
measured
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export { composerLayoutOf, composerLayoutStart, useComposerLayout, withDraftEmptiness, withTextHeight };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The tokens
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `rounded-2xl` / 13px in the inspector).
|
|
2
|
+
* The tokens a composer's paint shares: the box, its text, its round
|
|
3
|
+
* controls, its text region's cap and the rows beside it. The box's layout
|
|
4
|
+
* (where the text sits, where the controls sit, when it switches between
|
|
5
|
+
* the two) is not a token: it belongs to `ComposerFrame` (./composer-frame.tsx
|
|
6
|
+
* and its React Native twin ./composer-frame.native.tsx), and every composer
|
|
7
|
+
* renders through it, so no surface can lay text and controls out by hand.
|
|
9
8
|
*/
|
|
10
9
|
/** Shared responsive size for the two round controls flanking a composer. */
|
|
11
10
|
export declare const COMPOSER_CONTROL_BUTTON_SIZE: "icon-sm";
|
|
@@ -14,51 +13,32 @@ export declare const COMPOSER_CONTROL_BUTTON_SIZE: "icon-sm";
|
|
|
14
13
|
* stature it reads as a soft pill, which is the shape the composers were
|
|
15
14
|
* meant to unify on. */
|
|
16
15
|
export declare const COMPOSER_BOX_CLASS = "bg-background rounded-2xl border";
|
|
17
|
-
/** The box's focus ring in its default (non-anonymized) treatment. */
|
|
18
|
-
export declare const COMPOSER_BOX_FOCUS_CLASS = "focus-within:border-ring";
|
|
19
16
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* Background for chrome floating over a document page (the docked composer,
|
|
18
|
+
* the suggestion stepper, preset chips). In light mode the rendered page
|
|
19
|
+
* reads as white paper in every accent palette, while `--popover` follows
|
|
20
|
+
* the palette (Flexoki `#fffcf0`, Nord `#eceff4`): solid but visibly
|
|
21
|
+
* hue-tinted against the document. These surfaces are anchored to the
|
|
22
|
+
* document instead: white in light; in dark the page follows the theme, so
|
|
23
|
+
* the popover token stays correct.
|
|
23
24
|
*/
|
|
24
|
-
export declare const
|
|
25
|
+
export declare const DOC_FLOAT_SURFACE_CLASS = "[--doc-float-surface:var(--color-white)] dark:[--doc-float-surface:var(--popover)] bg-(--doc-float-surface)";
|
|
25
26
|
/**
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The most a composer's text region grows to before it scrolls: 16 lines of
|
|
28
|
+
* the web's `leading-5`, 320 points on a phone. Both `ComposerFrame`
|
|
29
|
+
* renderers cap their text region with it; the controls and the attachments
|
|
30
|
+
* sit outside the region, so they stay put while the text scrolls.
|
|
30
31
|
*/
|
|
31
|
-
export declare const
|
|
32
|
-
/**
|
|
33
|
-
* The compact text cell: one `text-sm` line at `leading-5` plus the
|
|
34
|
-
* vertical inset that makes a single line exactly as tall as the row's
|
|
35
|
-
* inner height (44px row, 1px inset each side ⇒ 42px), so text and controls
|
|
36
|
-
* share one centre. The editable element itself takes `min-h-0` so an empty
|
|
37
|
-
* composer collapses to this one line and grows from there.
|
|
38
|
-
*/
|
|
39
|
-
export declare const COMPOSER_COMPACT_TEXT_CELL_CLASS = "relative min-w-0 py-[11px]";
|
|
32
|
+
export declare const COMPOSER_TEXT_REGION_MAX_HEIGHT_CLASS = "max-h-80";
|
|
40
33
|
/** Text stature of the editor and every placeholder painted over it. */
|
|
41
34
|
export declare const COMPOSER_TEXT_CLASS = "text-sm leading-5";
|
|
42
35
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* `
|
|
46
|
-
*
|
|
47
|
-
* it directly.
|
|
48
|
-
*/
|
|
49
|
-
export declare const COMPOSER_LARGE_TEXT_WELL_CLASS = "ps-3 pe-3 pt-2 pb-1";
|
|
50
|
-
/** The `large` editable element's stature: three lines before it grows. */
|
|
51
|
-
export declare const COMPOSER_LARGE_EDITOR_CLASS = "min-h-15";
|
|
52
|
-
/**
|
|
53
|
-
* The placeholder painted over an empty editor, in either stature.
|
|
54
|
-
* `ComposerPlaceholder` cuts its text through TruncatedText; a row that wears
|
|
55
|
-
* this class around other content cuts its own text the same way.
|
|
36
|
+
* One line of a phone composer's text, in points: the line of the native
|
|
37
|
+
* field's `text-base`, which a thumb-sized composer uses where the web's
|
|
38
|
+
* reads `text-sm`. The native `Textarea` sets it and the native
|
|
39
|
+
* `ComposerFrame` measures the text against it.
|
|
56
40
|
*/
|
|
57
|
-
export declare const
|
|
58
|
-
/** The `large` action row under the text well: leading controls, trailing send. */
|
|
59
|
-
export declare const COMPOSER_LARGE_ACTION_ROW_CLASS = "flex items-center justify-end gap-0.5 px-1.5 pb-1.5";
|
|
60
|
-
/** The leading group of the action row (the (+) menu, or a scope control). */
|
|
61
|
-
export declare const COMPOSER_LEADING_GROUP_CLASS = "flex min-w-0 items-center gap-0.5";
|
|
41
|
+
export declare const COMPOSER_NATIVE_LINE_HEIGHT = 24;
|
|
62
42
|
/**
|
|
63
43
|
* The round, foreground-filled primary control at the action row's end:
|
|
64
44
|
* the chat's send/stop/retry button and the law home's submit. `size-7`
|