@tristan2828/ui-foundation 4.126.0 → 4.127.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/conventions/docs/add-an-entity.md +118 -34
- package/conventions/docs/cell-patterns.md +88 -41
- package/conventions/docs/design-language.md +45 -13
- package/dist/api/contracts.d.ts +8 -1
- package/dist/api/gateway/errors.js +4 -0
- package/dist/api/schema.d.ts +9 -0
- package/dist/components/app/data-table-tools.d.ts +12 -0
- package/dist/components/app/data-table-tools.js +2 -2
- package/dist/components/app/data-table.d.ts +2 -1
- package/dist/components/app/data-table.js +1 -1
- package/dist/components/app/edit-in-place-presets.d.ts +51 -1
- package/dist/components/app/edit-in-place-presets.js +30 -0
- package/dist/components/app/edit-in-place-store.d.ts +31 -4
- package/dist/components/app/edit-in-place-store.js +59 -11
- package/dist/components/app/edit-in-place.d.ts +11 -0
- package/dist/components/app/editable-value.js +43 -8
- package/dist/components/app/entity-view.js +5 -1
- package/dist/components/app/equal-items.d.ts +32 -6
- package/dist/components/app/equal-items.js +59 -8
- package/dist/components/app/error-state.js +1 -0
- package/dist/components/app/milkdown-editor.js +3 -2
- package/dist/components/app/pill-filter.d.ts +16 -0
- package/dist/components/app/pill-filter.js +22 -1
- package/dist/components/app/rating-input.d.ts +22 -0
- package/dist/components/app/rating-input.js +65 -0
- package/dist/components/app/rating-score.d.ts +2 -1
- package/dist/components/app/rating-score.js +2 -6
- package/dist/components/app/rich-text-editor.d.ts +4 -2
- package/dist/components/app/rich-text-editor.js +3 -2
- package/dist/components/app/rich-text-keyboard-bar.js +3 -2
- package/dist/components/app/rich-text-toolbar.js +1 -1
- package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
- package/dist/components/app/rich-text-tools-bar.js +2 -2
- package/dist/hooks/use-record-update.d.ts +13 -1
- package/dist/hooks/use-record-update.js +17 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -0
- package/dist/lib/markdown-merge.d.ts +12 -0
- package/dist/lib/markdown-merge.js +90 -0
- package/dist/lib/rating-glyphs.d.ts +3 -0
- package/dist/lib/rating-glyphs.js +7 -0
- package/openapi/foundation.yaml +12 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// A few equal things in a record (record page standard R10): the phases of
|
|
3
3
|
// a plan, the stores a price is compared at, a handful of options. One data
|
|
4
|
-
// shape,
|
|
4
|
+
// shape, five looks, each the record picks for what it shows:
|
|
5
5
|
//
|
|
6
6
|
// - `cards`: a row of equal cards that wraps (one column on a phone), each
|
|
7
7
|
// its title, its state as a badge and its fields as short label/value
|
|
@@ -15,6 +15,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
15
15
|
// - `panels`: a panel per item side by side, every detail labelled above
|
|
16
16
|
// its value, stacking on a phone. For things with several details each
|
|
17
17
|
// that need to read as separate.
|
|
18
|
+
// - `stepper` (4.127): the items in order as a row of numbered steps, each
|
|
19
|
+
// done, current or upcoming (an item's `step`), picking the one item
|
|
20
|
+
// whose panel shows under it; it opens on the current step. For a
|
|
21
|
+
// sequence where one is running and the others are looked at in turn (a
|
|
22
|
+
// plan's phases). The steps are a tablist: arrow keys, Home and End move
|
|
23
|
+
// and pick; on a phone the row scrolls sideways in its own box, as the
|
|
24
|
+
// record's tab bar does.
|
|
18
25
|
//
|
|
19
26
|
// The parts are the record's own: a state is a `Badge` in the outline
|
|
20
27
|
// style (design-language.md "The three badge styles"), a field is the
|
|
@@ -29,8 +36,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
29
36
|
// `actions`, its own buttons (Edit, Remove), at the end of its title line,
|
|
30
37
|
// or the table's last column. `wide` gives an item the whole row in
|
|
31
38
|
// `cards` and `panels`, for content that needs it (an editor open).
|
|
32
|
-
import { Fragment, useState } from 'react';
|
|
33
|
-
import {
|
|
39
|
+
import { Fragment, useLayoutEffect, useRef, useState } from 'react';
|
|
40
|
+
import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
|
|
41
|
+
import { CheckIcon, ChevronDownIcon } from 'lucide-react';
|
|
34
42
|
import { cn } from 'cn';
|
|
35
43
|
import { Badge } from '../ui/badge.js';
|
|
36
44
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible.js';
|
|
@@ -123,9 +131,51 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
|
|
|
123
131
|
const Heading = `h${level}`;
|
|
124
132
|
return (_jsx("li", { "data-slot": "equal-item", children: _jsxs(Collapsible, { open: open, onOpenChange: setOpen, children: [_jsxs("div", { className: "flex min-w-0 items-center", children: [_jsx(Heading, { className: "m-0 min-w-0 flex-1", children: _jsxs(CollapsibleTrigger, { "data-slot": "equal-item-toggle", className: "flex min-h-11 w-full items-center gap-2 px-4 py-2 text-left outline-none hover:bg-muted/50 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset", children: [_jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-4 shrink-0 text-muted-foreground transition-transform', !open && '-rotate-90') }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx("span", { className: "min-w-0 type-body font-semibold break-words text-foreground", children: item.title }), _jsx(StateBadge, { state: item.state })] })] }) }), _jsx(Actions, { actions: item.actions, className: "pr-4" })] }), _jsx(CollapsibleContent, { className: "flex flex-col gap-3 px-4 pt-1 pb-4 pl-10", children: _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "beside" }) })] }) }));
|
|
125
133
|
}
|
|
134
|
+
// The items as numbered steps joined by a line, a tablist picking the one
|
|
135
|
+
// panel shown under it (Base UI's tabs: arrow keys, Home and End move and
|
|
136
|
+
// pick, Tab goes on into the panel). A step's name is what it shows plus
|
|
137
|
+
// hidden words ("Step 2: Phase 2: Build, done"), never an aria-label, so
|
|
138
|
+
// the visible text stays in the name. Wider than its column (a phone, many
|
|
139
|
+
// steps), the row scrolls sideways in its own box, never the page, and
|
|
140
|
+
// keeps the shown step in view.
|
|
141
|
+
function Stepper({ items, label, level, noFieldsText, featuredId, selectedId, onSelectedChange, }) {
|
|
142
|
+
const has = (id) => id !== undefined && items.some((item) => item.id === id);
|
|
143
|
+
const first = has(featuredId) ? featuredId : (items.find((item) => item.step === 'current') ?? items[0]).id;
|
|
144
|
+
const [own, setOwn] = useState(first);
|
|
145
|
+
const shownId = has(selectedId) ? selectedId : has(own) ? own : first;
|
|
146
|
+
const listRef = useRef(null);
|
|
147
|
+
// Keep the shown step in the row's view when it scrolls sideways; the
|
|
148
|
+
// row only, never the page.
|
|
149
|
+
useLayoutEffect(() => {
|
|
150
|
+
const list = listRef.current;
|
|
151
|
+
const tab = list?.querySelector('[data-slot="equal-item-step"][data-active]');
|
|
152
|
+
if (!list || !tab || list.scrollWidth <= list.clientWidth)
|
|
153
|
+
return;
|
|
154
|
+
const left = tab.offsetLeft - list.offsetLeft;
|
|
155
|
+
if (left < list.scrollLeft || left + tab.offsetWidth > list.scrollLeft + list.clientWidth) {
|
|
156
|
+
list.scrollLeft = left - (list.clientWidth - tab.offsetWidth) / 2;
|
|
157
|
+
}
|
|
158
|
+
}, [shownId]);
|
|
159
|
+
return (_jsxs(TabsPrimitive.Root, { "data-slot": "equal-items-stepper", value: shownId, onValueChange: (next) => {
|
|
160
|
+
const id = String(next);
|
|
161
|
+
setOwn(id);
|
|
162
|
+
onSelectedChange?.(id);
|
|
163
|
+
}, className: "flex min-w-0 flex-col gap-3", children: [_jsx(TabsPrimitive.List, { ref: listRef, activateOnFocus: true, "aria-label": label, className: "relative flex max-w-full overflow-x-auto overflow-y-hidden [scrollbar-width:thin]", children: items.map((item, index) => {
|
|
164
|
+
const step = item.step ?? 'upcoming';
|
|
165
|
+
return (_jsxs(TabsPrimitive.Tab, { value: item.id, "data-slot": "equal-item-step", "data-step": step, "aria-current": step === 'current' ? 'step' : undefined, className: cn('group/step relative flex min-h-11 min-w-18 flex-1 basis-0 flex-col items-center gap-1 rounded-md px-1 pt-1 pb-1.5 text-center text-xs text-muted-foreground outline-none', 'hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset', 'data-active:font-semibold data-active:text-foreground',
|
|
166
|
+
// The line from the step before, under the marks.
|
|
167
|
+
'before:absolute before:top-4 before:right-1/2 before:h-0.5 before:w-full first:before:hidden', step === 'upcoming' ? 'before:bg-border' : 'before:bg-primary'), children: [_jsxs("span", { "aria-hidden": "true", "data-slot": "equal-item-step-mark", className: cn('relative z-10 grid size-6.5 shrink-0 place-items-center rounded-full border-2 text-xs font-bold tabular-nums', step === 'done'
|
|
168
|
+
? 'border-primary bg-primary text-primary-foreground'
|
|
169
|
+
: step === 'current'
|
|
170
|
+
? 'border-primary bg-card text-foreground'
|
|
171
|
+
: 'border-border bg-card text-muted-foreground',
|
|
172
|
+
// The shown step: a ring round its mark.
|
|
173
|
+
'group-data-active/step:ring-2 group-data-active/step:ring-ring group-data-active/step:ring-offset-2 group-data-active/step:ring-offset-card'), children: [step === 'done' ? _jsx(CheckIcon, { className: "size-3.5" }) : index + 1, item.attention && (_jsx("span", { "data-slot": "equal-item-step-attention", className: "absolute -top-0.5 -right-0.5 size-2.5 rounded-full border border-card bg-warning-text" }))] }), _jsxs("span", { className: "line-clamp-3 max-w-full min-w-0 break-words", children: [_jsx("span", { className: "sr-only", children: `Step ${index + 1}: ` }), item.title, step === 'done' && _jsx("span", { className: "sr-only", children: ", done" }), item.attention && _jsx("span", { className: "sr-only", children: `, ${item.attention}` })] }), step === 'current' && _jsx("span", { className: "font-normal text-muted-foreground", children: "Current" })] }, item.id));
|
|
174
|
+
}) }), items.map((item) => (_jsxs(TabsPrimitive.Panel, { value: item.id, "data-slot": "equal-item", "data-step": item.step ?? 'upcoming', className: cn('flex min-w-0 flex-col gap-3 rounded-lg border bg-card p-4 text-card-foreground outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50', item.step === 'current' ? 'border-primary' : 'border-border'), children: [_jsx(Title, { item: item, level: level }), _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "beside" })] }, item.id)))] }));
|
|
175
|
+
}
|
|
126
176
|
/**
|
|
127
177
|
* A few equal, related things inside a record view (record page standard
|
|
128
|
-
* R10): one data shape,
|
|
178
|
+
* R10): one data shape, five looks.
|
|
129
179
|
*
|
|
130
180
|
* ```tsx
|
|
131
181
|
* <EqualItems
|
|
@@ -142,15 +192,16 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
|
|
|
142
192
|
*
|
|
143
193
|
* `cards` for a few things with little to say about each, `table` for
|
|
144
194
|
* things compared on the same values, `featured` when one is current or
|
|
145
|
-
* best, `panels` when each has several details and must read as separate
|
|
146
|
-
*
|
|
195
|
+
* best, `panels` when each has several details and must read as separate,
|
|
196
|
+
* `stepper` for a sequence with a current step, its steps picking the one
|
|
197
|
+
* panel shown (design-language.md "A few equal things"). An item's own `content` (an
|
|
147
198
|
* editor) goes under its fields at full width, its `actions` (Edit, Remove)
|
|
148
199
|
* at its title line's end; `wide` gives it the whole row of cards or panels.
|
|
149
200
|
*/
|
|
150
|
-
export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', actionsColumn = 'Actions', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
|
|
201
|
+
export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, selectedId, onSelectedChange, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', actionsColumn = 'Actions', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
|
|
151
202
|
if (items.length === 0) {
|
|
152
203
|
return (_jsx("p", { "data-slot": "equal-items", "data-look": look, "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
|
|
153
204
|
}
|
|
154
205
|
const shared = { items, label, level: headingLevel, noFieldsText };
|
|
155
|
-
return (_jsx("div", { "data-slot": "equal-items", "data-look": look, className: cn('min-w-0', className), children: look === 'table' ? (_jsx(ItemsTable, { items: items, label: label, titleColumn: titleColumn, stateColumn: stateColumn, actionsColumn: actionsColumn })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
|
|
206
|
+
return (_jsx("div", { "data-slot": "equal-items", "data-look": look, className: cn('min-w-0', className), children: look === 'table' ? (_jsx(ItemsTable, { items: items, label: label, titleColumn: titleColumn, stateColumn: stateColumn, actionsColumn: actionsColumn })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'stepper' ? (_jsx(Stepper, { ...shared, featuredId: featuredId, selectedId: selectedId, onSelectedChange: onSelectedChange })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
|
|
156
207
|
}
|
|
@@ -68,7 +68,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
68
68
|
// for notes that are always editable where they're read.
|
|
69
69
|
// - Images in the text show (``), at most the field's width.
|
|
70
70
|
// With `upload`, an image pasted, dropped or picked with the toolbar's
|
|
71
|
-
// Image button
|
|
71
|
+
// Image button (the fixed toolbar's, the tools strip's with
|
|
72
|
+
// `toolbar="floating"`, the phone's row) is uploaded through it and goes in as ``
|
|
72
73
|
// (rich-text-image-upload.ts); a refusal or a failed upload is a toast.
|
|
73
74
|
// - Toggle headings (`## Safety {toggle="true"}`, rich-text-toggle-heading.ts):
|
|
74
75
|
// a heading's `toggle` attribute, typed as `>## `, picked from the slash
|
|
@@ -1461,7 +1462,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1461
1462
|
const next = event.relatedTarget;
|
|
1462
1463
|
if (!editorView.dom.contains(next) && !inFloating(next))
|
|
1463
1464
|
setFocused(false);
|
|
1464
|
-
} })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1465
|
+
} })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onImage: upload ? pickImages : undefined, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1465
1466
|
const next = event.relatedTarget;
|
|
1466
1467
|
if (editorView && !editorView.dom.contains(next) && !inFloating(next))
|
|
1467
1468
|
setFocused(false);
|
|
@@ -15,3 +15,19 @@ export type PillFilterProps = {
|
|
|
15
15
|
className?: string;
|
|
16
16
|
};
|
|
17
17
|
export declare function PillFilter({ label, options, value, onValueChange, allLabel, className }: PillFilterProps): import("react").JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* One pill as PillGroup draws it: a PillFilterOption, and for DataTable's
|
|
20
|
+
* views (4.127) a count after the label, "Needs a Look · 3".
|
|
21
|
+
*/
|
|
22
|
+
export type PillGroupOption = PillFilterOption & {
|
|
23
|
+
/** The number shown after the label; null, undefined or 0 shows none, past 99 "99+". */
|
|
24
|
+
count?: number | null;
|
|
25
|
+
/**
|
|
26
|
+
* The pill keeps room for a two-digit count from its first render, so
|
|
27
|
+
* a count that arrives later (or never) moves no pill.
|
|
28
|
+
*/
|
|
29
|
+
counted?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function PillGroup({ label, options, value, onValueChange, allLabel, className, }: Omit<PillFilterProps, 'options'> & {
|
|
32
|
+
options: readonly PillGroupOption[];
|
|
33
|
+
}): import("react").JSX.Element;
|
|
@@ -12,6 +12,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
12
12
|
// button with aria-pressed.
|
|
13
13
|
import { cn } from 'cn';
|
|
14
14
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
15
|
+
import { navCountText } from './app-shell-nav.js';
|
|
15
16
|
// The All pill's value inside the group: Base UI's toggles need one that
|
|
16
17
|
// isn't empty, and '' is what the app's filter calls All.
|
|
17
18
|
const ALL = '__all__';
|
|
@@ -20,6 +21,16 @@ const ALL = '__all__';
|
|
|
20
21
|
const PILL_CLASS = 'rounded-full px-3 aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground ' +
|
|
21
22
|
'aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground';
|
|
22
23
|
export function PillFilter({ label, options, value, onValueChange, allLabel = 'All', className }) {
|
|
24
|
+
return (_jsx(PillGroup, { label: label, options: options, value: value, onValueChange: onValueChange, allLabel: allLabel, className: className }));
|
|
25
|
+
}
|
|
26
|
+
// The count as drawn: navCountText's rules (nothing at 0 or while loading,
|
|
27
|
+
// "99+" past 99), shared with the sidebar's counts.
|
|
28
|
+
function countText(count) {
|
|
29
|
+
return navCountText(count ?? undefined);
|
|
30
|
+
}
|
|
31
|
+
// PillFilter's pills, with an optional count per pill. Internal: DataTable's
|
|
32
|
+
// views draw theirs with it (data-table-tools.tsx's ViewPills).
|
|
33
|
+
export function PillGroup({ label, options, value, onValueChange, allLabel = 'All', className, }) {
|
|
23
34
|
const pills = allLabel === null ? options : [{ value: ALL, label: allLabel }, ...options];
|
|
24
35
|
const pressed = value === '' && allLabel !== null ? ALL : value;
|
|
25
36
|
return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className: cn('flex-wrap', className), value: [pressed], onValueChange: (next) => {
|
|
@@ -28,5 +39,15 @@ export function PillFilter({ label, options, value, onValueChange, allLabel = 'A
|
|
|
28
39
|
if (chosen === undefined || chosen === pressed)
|
|
29
40
|
return;
|
|
30
41
|
onValueChange(chosen === ALL ? '' : chosen);
|
|
31
|
-
}, children: pills.map((option) =>
|
|
42
|
+
}, children: pills.map((option) => {
|
|
43
|
+
const count = countText(option.count);
|
|
44
|
+
return (_jsx(ToggleGroupItem, { value: option.value, "aria-label": count !== undefined ? `${option.label}, ${count}` : undefined, className: PILL_CLASS, children: option.counted || count !== undefined ? _jsx(CountedLabel, { label: option.label, count: count, counted: option.counted }) : option.label }, option.value));
|
|
45
|
+
}) }));
|
|
46
|
+
}
|
|
47
|
+
// "Needs a Look · 3". A hidden copy with a two-digit count (::after, not in
|
|
48
|
+
// the DOM's text or the name) holds the pill at that width while the count
|
|
49
|
+
// loads, is 0 or is one digit, the way EntityView's tab names hold their
|
|
50
|
+
// bold width; the label sits centred in it.
|
|
51
|
+
function CountedLabel({ label, count, counted }) {
|
|
52
|
+
return (_jsx("span", { "data-slot": "pill-label", "data-reserve": counted ? `${label} · 00` : undefined, className: "inline-grid after:invisible after:col-start-1 after:row-start-1 after:h-0 after:tabular-nums after:content-[attr(data-reserve)]", children: _jsx("span", { "data-slot": "pill-text", className: "col-start-1 row-start-1 justify-self-center tabular-nums", children: count !== undefined ? `${label} · ${count}` : label }) }));
|
|
32
53
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RatingScoreGlyph } from './rating-score.js';
|
|
2
|
+
/** How a RatingInput's value was set: a click or tap, or the keyboard. */
|
|
3
|
+
export type RatingInputSource = 'pointer' | 'keyboard';
|
|
4
|
+
export type RatingInputProps = {
|
|
5
|
+
/** How many stars are set, 1…max, or `null` for none (rounded, clamped). */
|
|
6
|
+
value: number | null;
|
|
7
|
+
/** How many stars it has. Defaults to 5. */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** Stars (the default) or hearts. */
|
|
10
|
+
glyph?: RatingScoreGlyph;
|
|
11
|
+
/** The new value: a star's number, or `null` when the set one was pressed again. */
|
|
12
|
+
onChange: (value: number | null, source: RatingInputSource) => void;
|
|
13
|
+
/** The group's accessible name: the field's label ("My Rating"). */
|
|
14
|
+
label: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** The line describing it (a field's error or hint). */
|
|
17
|
+
'aria-describedby'?: string;
|
|
18
|
+
invalid?: boolean;
|
|
19
|
+
id?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function RatingInput({ value, max, glyph, onChange, label, disabled, invalid, id, className, 'aria-describedby': describedBy, }: RatingInputProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A score out of a few, set by clicking a star (cell pattern 9, 4.127):
|
|
3
|
+
// RatingScore's glyphs and tokens, as a control. "My Rating" as ★★★★☆,
|
|
4
|
+
// where a click on the second star makes it 2.
|
|
5
|
+
//
|
|
6
|
+
// - One radio group named by `label` (shadcn's RadioGroup on Base UI): one
|
|
7
|
+
// tab stop, the arrow keys move along the stars and set the value, Space
|
|
8
|
+
// or a click sets the star it's on. Each star is a radio named "2 of 5".
|
|
9
|
+
// - Pressing the star that's already set clears it (`null`): a click, or
|
|
10
|
+
// Space on it. Nothing else can clear it, so a slip of the arrow keys
|
|
11
|
+
// never empties a score.
|
|
12
|
+
// - Hovering previews: the stars up to the pointer fill as they would on a
|
|
13
|
+
// click, and leaving puts the value back. A mouse's only: a finger has
|
|
14
|
+
// no hover, and a tap's preview would stick.
|
|
15
|
+
// - Drawn as RatingScore draws: the filled glyphs in `foreground`, the
|
|
16
|
+
// rest outlines in `muted-foreground` (3:1 on the page in both themes),
|
|
17
|
+
// so the count carries the value and survives greyscale.
|
|
18
|
+
// - Compact on a mouse's screen (24px targets, the glyphs RatingScore's
|
|
19
|
+
// 16px), 44px targets on a touch screen (`pointer-coarse`), the glyphs
|
|
20
|
+
// 20px. Fixed-size: as wide at 1 as at 5, so setting it moves nothing.
|
|
21
|
+
// - `onChange`'s second argument says how it was set: `pointer` (a click
|
|
22
|
+
// or a tap, a deliberate pick) or `keyboard` (an arrow, which may be one
|
|
23
|
+
// of several on the way). `inPlace.rating` saves a pick at once and an
|
|
24
|
+
// arrow's value a pause after the last one.
|
|
25
|
+
import { Radio } from '@base-ui/react/radio';
|
|
26
|
+
import { useRef, useState } from 'react';
|
|
27
|
+
import { cn } from 'cn';
|
|
28
|
+
import { RadioGroup } from '../ui/radio-group.js';
|
|
29
|
+
import { RATING_GLYPH_PATHS } from '../../lib/rating-glyphs.js';
|
|
30
|
+
const clamp = (value, max) => (value == null ? null : Math.min(Math.max(0, Math.round(value)), max) || null);
|
|
31
|
+
export function RatingInput({ value, max = 5, glyph = 'star', onChange, label, disabled = false, invalid = false, id, className, 'aria-describedby': describedBy, }) {
|
|
32
|
+
const set = clamp(value, max);
|
|
33
|
+
const [preview, setPreview] = useState(null);
|
|
34
|
+
// What started the change Base UI reports: a key (an arrow, Space) or a pointer.
|
|
35
|
+
const source = useRef('pointer');
|
|
36
|
+
const filled = disabled ? (set ?? 0) : (preview ?? set ?? 0);
|
|
37
|
+
const path = RATING_GLYPH_PATHS[glyph];
|
|
38
|
+
const onKeyDown = () => {
|
|
39
|
+
source.current = 'keyboard';
|
|
40
|
+
};
|
|
41
|
+
const onPointerDown = () => {
|
|
42
|
+
source.current = 'pointer';
|
|
43
|
+
};
|
|
44
|
+
const hover = (star) => (event) => {
|
|
45
|
+
if (event.pointerType === 'mouse')
|
|
46
|
+
setPreview(star);
|
|
47
|
+
};
|
|
48
|
+
return (_jsx(RadioGroup, { id: id, "data-slot": "rating-input", "data-value": set ?? undefined, "data-glyph": glyph, "aria-label": label, "aria-describedby": describedBy, "aria-invalid": invalid || undefined, value: set, onValueChange: (next) => {
|
|
49
|
+
if (next != null && next !== set)
|
|
50
|
+
onChange(next, source.current);
|
|
51
|
+
}, disabled: disabled, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerLeave: hover(null), className: cn('inline-flex w-fit shrink-0 items-center gap-0 align-middle text-foreground', invalid && 'rounded-md ring-3 ring-destructive/20 dark:ring-destructive/40', className), children: Array.from({ length: max }, (_, at) => {
|
|
52
|
+
const star = at + 1;
|
|
53
|
+
const on = star <= filled;
|
|
54
|
+
return (_jsx(Radio.Root, { value: star, "data-star": star, "aria-label": `${star} of ${max}`, onPointerEnter: hover(star),
|
|
55
|
+
// Pressing the set star again clears it (a click, a tap or
|
|
56
|
+
// Space, which Base UI turns into a click). Base UI reports no
|
|
57
|
+
// change for it. The arrow keys check a radio by focusing it,
|
|
58
|
+
// never by a click, so they never clear.
|
|
59
|
+
onClick: () => {
|
|
60
|
+
if (disabled || star !== set)
|
|
61
|
+
return;
|
|
62
|
+
onChange(null, source.current);
|
|
63
|
+
}, className: cn('inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-sm outline-none', 'focus-visible:ring-3 focus-visible:ring-ring/50', 'pointer-coarse:size-11', 'data-disabled:cursor-not-allowed data-disabled:opacity-50'), children: _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", "data-filled": on ? '' : undefined, className: cn('size-4 shrink-0 pointer-coarse:size-5', on ? 'text-current' : 'text-muted-foreground'), children: _jsx("path", { d: path, className: on ? 'fill-current stroke-current' : 'fill-none stroke-current', strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }, star));
|
|
64
|
+
}) }));
|
|
65
|
+
}
|
|
@@ -12,11 +12,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
// Fixed-size glyphs: the score is as wide at 1 as at 5, so a value edited
|
|
13
13
|
// in place never moves what's beside it.
|
|
14
14
|
import { cn } from 'cn';
|
|
15
|
-
|
|
16
|
-
const PATHS = {
|
|
17
|
-
star: 'M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z',
|
|
18
|
-
heart: 'M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5',
|
|
19
|
-
};
|
|
15
|
+
import { RATING_GLYPH_PATHS } from '../../lib/rating-glyphs.js';
|
|
20
16
|
/** A score's spoken words: "4 of 5", or "Loved, 4 of 5" with a word. */
|
|
21
17
|
function ratingScoreName(value, max = 5, word) {
|
|
22
18
|
const filled = Math.min(Math.max(0, Math.round(value)), max);
|
|
@@ -24,6 +20,6 @@ function ratingScoreName(value, max = 5, word) {
|
|
|
24
20
|
}
|
|
25
21
|
export function RatingScore({ value, max = 5, glyph = 'star', word, label, className }) {
|
|
26
22
|
const filled = Math.min(Math.max(0, Math.round(value)), max);
|
|
27
|
-
const path =
|
|
23
|
+
const path = RATING_GLYPH_PATHS[glyph];
|
|
28
24
|
return (_jsxs("span", { role: "img", "aria-label": label ?? ratingScoreName(filled, max, word), "data-slot": "rating-score", "data-value": filled, "data-glyph": glyph, className: cn('inline-flex shrink-0 items-center gap-1.5 align-middle text-foreground', className), children: [_jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0 items-center gap-0.5", children: Array.from({ length: max }, (_, at) => (_jsx("svg", { viewBox: "0 0 24 24", "data-filled": at < filled ? '' : undefined, className: cn('size-4 shrink-0', at < filled ? 'text-current' : 'text-muted-foreground'), children: _jsx("path", { d: path, className: at < filled ? 'fill-current stroke-current' : 'fill-none stroke-current', strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }, at))) }), word && (_jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: word }))] }));
|
|
29
25
|
}
|
|
@@ -58,8 +58,10 @@ export type RichTextEditorProps = {
|
|
|
58
58
|
inline?: boolean;
|
|
59
59
|
/**
|
|
60
60
|
* Images uploaded into the text: pasted, dropped, or picked with an
|
|
61
|
-
* Image button on the fixed toolbar
|
|
62
|
-
*
|
|
61
|
+
* Image button (on the fixed toolbar; with `toolbar="floating"`, on the
|
|
62
|
+
* "Editor tools" strip shown while the field has focus; on a phone, in
|
|
63
|
+
* the row pinned to the keyboard) or the slash menu's Image ("/image",
|
|
64
|
+
* 4.123). Each file goes through this (the
|
|
63
65
|
* app's own storage: the package knows no endpoint) and goes in as
|
|
64
66
|
* ``, from the result's `url`, else its `thumbUrl`. A
|
|
65
67
|
* placeholder shows where it will go while it uploads (it isn't saved);
|
|
@@ -23,8 +23,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
23
23
|
// keys scroll.
|
|
24
24
|
//
|
|
25
25
|
// Images in the text (``) show, at most the field's width.
|
|
26
|
-
// With `upload`, an image pasted, dropped or picked with
|
|
27
|
-
//
|
|
26
|
+
// With `upload`, an image pasted, dropped or picked with an Image button
|
|
27
|
+
// (the fixed toolbar's, or the tools strip's with `toolbar="floating"`) is
|
|
28
|
+
// uploaded through the app's own storage and goes in as
|
|
28
29
|
// ``; while it uploads, a placeholder shows where it will go.
|
|
29
30
|
//
|
|
30
31
|
// A table's columns fit their words. Grips on its column and row (or a
|
|
@@ -10,7 +10,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
10
10
|
// - Pinned to the bottom of what is visible (`visualViewport`), so it sits
|
|
11
11
|
// on the keyboard and follows it as it opens, closes and resizes.
|
|
12
12
|
// - The row: Aa, then the list buttons used while typing (Task, Bulleted,
|
|
13
|
-
// Outdent, Indent), Insert (opens the slash menu on a new line)
|
|
13
|
+
// Outdent, Indent), Insert (opens the slash menu on a new line), Image
|
|
14
|
+
// when the editor uploads images (the fixed toolbar's file picker), and
|
|
14
15
|
// Undo; with words selected, their formats first (Bold to Link), in
|
|
15
16
|
// place of the floating bar, which would land under the system's Copy
|
|
16
17
|
// bar. Hide keyboard last.
|
|
@@ -194,7 +195,7 @@ export function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat,
|
|
|
194
195
|
if (!open)
|
|
195
196
|
virtualKeyboard()?.show();
|
|
196
197
|
view.focus();
|
|
197
|
-
}, children: panel ? _jsx(KeyboardIcon, { "aria-hidden": "true" }) : 'Aa' }), _jsx(Separator, { orientation: "vertical", className: "mx-1 h-6 data-vertical:self-center" }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto [scrollbar-width:none]", children: [_jsx(FormatButtons, { formats: words ? 'keyboardWords' : 'keyboard', state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }), !words && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Insert Block", disabled: readOnly || inCode, className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => insertBlock(view), children: _jsx(PlusIcon, { "aria-hidden": "true" }) }), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Undo",
|
|
198
|
+
}, children: panel ? _jsx(KeyboardIcon, { "aria-hidden": "true" }) : 'Aa' }), _jsx(Separator, { orientation: "vertical", className: "mx-1 h-6 data-vertical:self-center" }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto [scrollbar-width:none]", children: [_jsx(FormatButtons, { formats: words ? 'keyboardWords' : 'keyboard', state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }), !words && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Insert Block", disabled: readOnly || inCode, className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => insertBlock(view), children: _jsx(PlusIcon, { "aria-hidden": "true" }) }), onImage && (_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Image", disabled: readOnly, className: "[&_svg]:size-5", onMouseDown: keep, onClick: onImage, children: _jsx(ImageIcon, { "aria-hidden": "true" }) })), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Undo",
|
|
198
199
|
// Always on: `state` doesn't follow typing (F6), and with nothing
|
|
199
200
|
// to undo it does nothing.
|
|
200
201
|
disabled: readOnly, className: "[&_svg]:size-5", onMouseDown: keep, onClick: press(() => undo(view.state, view.dispatch)), children: _jsx(Undo2Icon, { "aria-hidden": "true" }) })] }))] }), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Hide Keyboard", className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => {
|
|
@@ -117,7 +117,7 @@ export function FormatButtons({ formats, state, readOnly, onFormat, onPage, onIm
|
|
|
117
117
|
onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(index), onKeyDown: onKeyDown, onPressedChange: () => onFormat(item.id) }), children: _jsx(Icon, {}) }), _jsx(TooltipContent, { children: tip })] }, item.id));
|
|
118
118
|
})] }, groupIndex))), onPage && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
|
|
119
119
|
buttons.current[pageIndex] = element;
|
|
120
|
-
}, variant: "ghost", size: "icon-sm", "aria-label": "Turn Into Page", disabled: readOnly, tabIndex: pageIndex === current ? 0 : -1, onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(pageIndex), onKeyDown: onKeyDown, onClick: onPage }), children: _jsx(FileTextIcon, {}) }), _jsx(TooltipContent, { children: "Turn Into Page \u00B7 a new page named for the words, linked here" })] })] })), onImage && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
|
|
120
|
+
}, variant: "ghost", size: "icon-sm", "aria-label": "Turn Into Page", disabled: readOnly, tabIndex: pageIndex === current ? 0 : -1, onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(pageIndex), onKeyDown: onKeyDown, onClick: onPage }), children: _jsx(FileTextIcon, {}) }), _jsx(TooltipContent, { children: "Turn Into Page \u00B7 a new page named for the words, linked here" })] })] })), onImage && (_jsxs(_Fragment, { children: [(items.length > 0 || onPage) && _jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
|
|
121
121
|
buttons.current[imageIndex] = element;
|
|
122
122
|
}, variant: "ghost", size: "icon-sm", "aria-label": "Image", disabled: readOnly, tabIndex: imageIndex === current ? 0 : -1, onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(imageIndex), onKeyDown: onKeyDown, onClick: onImage }), children: _jsx(ImageIcon, {}) }), _jsx(TooltipContent, { children: "Image \u00B7 or paste or drop one" })] })] })), onFullScreen && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Toggle, { ref: (element) => {
|
|
123
123
|
buttons.current[fullScreenIndex] = element;
|
|
@@ -8,6 +8,8 @@ export interface RichTextToolsBarProps {
|
|
|
8
8
|
/** The editable element's id, for `aria-controls`. */
|
|
9
9
|
controls: string;
|
|
10
10
|
onFormat: (id: FormatId) => void;
|
|
11
|
+
/** The Image button pressed: pick images to upload. No button without it (the editor has no `upload`). */
|
|
12
|
+
onImage?: () => void;
|
|
11
13
|
onFullScreen: () => void;
|
|
12
14
|
/** Esc: focus back to the text. */
|
|
13
15
|
onReturn: () => void;
|
|
@@ -15,4 +17,4 @@ export interface RichTextToolsBarProps {
|
|
|
15
17
|
onBlur: (event: FocusEvent) => void;
|
|
16
18
|
ref?: Ref<HTMLDivElement>;
|
|
17
19
|
}
|
|
18
|
-
export declare function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onFullScreen, onReturn, onBlur, ref }: RichTextToolsBarProps): import("react").JSX.Element;
|
|
20
|
+
export declare function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onImage, onFullScreen, onReturn, onBlur, ref }: RichTextToolsBarProps): import("react").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from 'cn';
|
|
3
3
|
import { FormatButtons } from './rich-text-toolbar.js';
|
|
4
|
-
export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onFullScreen, onReturn, onBlur, ref }) {
|
|
4
|
+
export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onImage, onFullScreen, onReturn, onBlur, ref }) {
|
|
5
5
|
const onKeyDown = (event) => {
|
|
6
6
|
// Full screen's Esc is the field's (milkdown-editor.tsx); otherwise it
|
|
7
7
|
// gives focus back to the text.
|
|
@@ -13,5 +13,5 @@ export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onForm
|
|
|
13
13
|
};
|
|
14
14
|
return (_jsx("div", { ref: ref, role: "toolbar", "aria-label": "Editor tools", "aria-controls": controls, "data-slot": "rich-text-tools-bar", className: cn('absolute right-0 z-40 flex items-center gap-0.5 rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10',
|
|
15
15
|
// Above the field, or inside its corner once it fills the window.
|
|
16
|
-
fullScreen ? 'top-2 right-2' : 'bottom-full mb-1'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "tools", state: state, readOnly: readOnly, onFormat: onFormat, onFullScreen: onFullScreen, fullScreen: fullScreen }) }));
|
|
16
|
+
fullScreen ? 'top-2 right-2' : 'bottom-full mb-1'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "tools", state: state, readOnly: readOnly, onFormat: onFormat, onImage: onImage, onFullScreen: onFullScreen, fullScreen: fullScreen }) }));
|
|
17
17
|
}
|
|
@@ -21,6 +21,18 @@ export type RecordUpdateOptions<TRecord extends {
|
|
|
21
21
|
listsKey: QueryKey;
|
|
22
22
|
/** The gateway's PATCH: sends `update`, resolves with the saved record, rejects with an `AppError`. */
|
|
23
23
|
update: (id: TRecord['id'], update: TUpdate) => Promise<TRecord>;
|
|
24
|
+
/**
|
|
25
|
+
* Adds the version the change was built on to what's sent, when the
|
|
26
|
+
* record has one: `(update, widget) => ({ ...update, baseUpdatedAt:
|
|
27
|
+
* widget.updatedAt })`. `record` is the server's latest record this tab
|
|
28
|
+
* knows (in a burst of saves, the one the previous save returned), so a
|
|
29
|
+
* save never conflicts with this tab's own. The server answers 409 when
|
|
30
|
+
* the record's version is no longer that one (AppError kind `conflict`):
|
|
31
|
+
* the record is refetched, and nothing was written. Leave it out and no
|
|
32
|
+
* version is sent (docs/foundation/add-an-entity.md "Saves that don't
|
|
33
|
+
* overwrite").
|
|
34
|
+
*/
|
|
35
|
+
withVersion?: (update: TUpdate, record: TRecord) => TUpdate;
|
|
24
36
|
/** What a refusal's toast calls the record: "Couldn't update <name>: <reason>". */
|
|
25
37
|
name: (record: TRecord) => string;
|
|
26
38
|
/**
|
|
@@ -63,7 +75,7 @@ export declare function refusalReason(error: AppError, sent?: object): string;
|
|
|
63
75
|
*/
|
|
64
76
|
export declare function recordUpdateMutationOptions<TRecord extends {
|
|
65
77
|
id: RecordId;
|
|
66
|
-
}, TUpdate extends Partial<TRecord>>(queryClient: QueryClient, { id, detailKey, listsKey, update, name, optimistic, toastOnError, onSuccess, onError, onSettled, }: RecordUpdateOptions<TRecord, TUpdate>): MutationOptions<TRecord, AppError, RecordChange<TRecord, TUpdate>, {
|
|
78
|
+
}, TUpdate extends Partial<TRecord>>(queryClient: QueryClient, { id, detailKey, listsKey, update, name, withVersion, optimistic, toastOnError, onSuccess, onError, onSettled, }: RecordUpdateOptions<TRecord, TUpdate>): MutationOptions<TRecord, AppError, RecordChange<TRecord, TUpdate>, {
|
|
67
79
|
entry: Entry<TRecord, TUpdate>;
|
|
68
80
|
}>;
|
|
69
81
|
/**
|
|
@@ -26,6 +26,14 @@
|
|
|
26
26
|
// function change has nothing to build on and is refused like any other
|
|
27
27
|
// refusal. Both warn in the console, naming the keys searched.
|
|
28
28
|
//
|
|
29
|
+
// - **A version check, when the record has one** (`withVersion`). Each
|
|
30
|
+
// request carries the version of the record it was built on (its
|
|
31
|
+
// `updatedAt`), and the server answers 409 when another writer saved
|
|
32
|
+
// since: nothing is written, the save rejects with an AppError of kind
|
|
33
|
+
// `conflict`, and the record is fetched again so the screen shows what
|
|
34
|
+
// the other writer saved. Without `withVersion` nothing is sent and
|
|
35
|
+
// nothing is checked, as before.
|
|
36
|
+
//
|
|
29
37
|
// Editing in place uses the same save with `optimistic: false` and
|
|
30
38
|
// `toastOnError: false`: nothing changes on screen until the server
|
|
31
39
|
// agrees, and a refusal comes back to the field (`mutateAsync` rejects)
|
|
@@ -69,7 +77,7 @@ export function refusalReason(error, sent) {
|
|
|
69
77
|
* The mutation options behind `useRecordUpdate`, for a given QueryClient.
|
|
70
78
|
* Exported for tests and for code outside React; screens use the hook.
|
|
71
79
|
*/
|
|
72
|
-
export function recordUpdateMutationOptions(queryClient, { id, detailKey, listsKey, update, name, optimistic = true, toastOnError = true, onSuccess, onError, onSettled, }) {
|
|
80
|
+
export function recordUpdateMutationOptions(queryClient, { id, detailKey, listsKey, update, name, withVersion, optimistic = true, toastOnError = true, onSuccess, onError, onSettled, }) {
|
|
73
81
|
const key = hashKey(detailKey);
|
|
74
82
|
const lists = { queryKey: listsKey };
|
|
75
83
|
const map = recordStates(queryClient);
|
|
@@ -110,8 +118,10 @@ export function recordUpdateMutationOptions(queryClient, { id, detailKey, listsK
|
|
|
110
118
|
scope: { id: `record-update:${key}` },
|
|
111
119
|
mutationFn: (change) => {
|
|
112
120
|
const confirmed = map.get(key)?.confirmed ?? cached();
|
|
113
|
-
if (confirmed)
|
|
114
|
-
|
|
121
|
+
if (confirmed) {
|
|
122
|
+
const built = resolve(change, confirmed);
|
|
123
|
+
return update(id, withVersion ? withVersion(built, confirmed) : built);
|
|
124
|
+
}
|
|
115
125
|
// The screen holds the record somewhere these keys don't reach (a
|
|
116
126
|
// query gathering a related list's records, say). An object change
|
|
117
127
|
// needs no current record, so it's still sent; a function change
|
|
@@ -147,6 +157,10 @@ export function recordUpdateMutationOptions(queryClient, { id, detailKey, listsK
|
|
|
147
157
|
const record = state.confirmed;
|
|
148
158
|
const sent = record ? resolve(change, record) : typeof change === 'function' ? undefined : change;
|
|
149
159
|
settle(state, context.entry);
|
|
160
|
+
// Another writer saved since: show what they saved (the detail;
|
|
161
|
+
// the lists refetch once the last save settles, in settle).
|
|
162
|
+
if (error.kind === 'conflict')
|
|
163
|
+
void queryClient.invalidateQueries({ queryKey: detailKey });
|
|
150
164
|
if (toastOnError)
|
|
151
165
|
toast.error(`Couldn't update ${record ? name(record) : 'this record'}: ${refusalReason(error, sent)}`);
|
|
152
166
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,8 @@ export { JobStatus, type JobProgress, type JobStatusProps } from './components/a
|
|
|
45
45
|
export { OfflineNotice, type OfflineNoticeProps } from './components/app/offline-notice.js';
|
|
46
46
|
export { useOffline } from './lib/connection.js';
|
|
47
47
|
export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
|
|
48
|
-
export {
|
|
48
|
+
export { rebaseMarkdown } from './lib/markdown-merge.js';
|
|
49
|
+
export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRatingConfig, type InPlaceRecord, type InPlaceRecurrenceConfig, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
|
|
49
50
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
50
51
|
export { TITLE_CASE_SMALL_WORDS, titleCase } from './lib/title-case.js';
|
|
51
52
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
@@ -84,7 +85,7 @@ export { Notice, type NoticeProps, type NoticeTone } from './components/app/noti
|
|
|
84
85
|
export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
|
|
85
86
|
export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, type ListHeaderSecondaryAction, type ListHeaderSibling, } from './components/app/list-header.js';
|
|
86
87
|
export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
|
|
87
|
-
export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
|
|
88
|
+
export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemStep, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
|
|
88
89
|
export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
|
|
89
90
|
export { Freshness, type FreshnessProps } from './components/app/freshness.js';
|
|
90
91
|
export { isStale } from './lib/freshness.js';
|
|
@@ -96,6 +97,7 @@ export { MultiLineChart, type ChartSeries, type ChartTone, type MultiLineChartPr
|
|
|
96
97
|
export { StepBar, type StepBarProps } from './components/app/step-bar.js';
|
|
97
98
|
export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
|
|
98
99
|
export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
|
|
100
|
+
export { RatingInput, type RatingInputProps, type RatingInputSource } from './components/app/rating-input.js';
|
|
99
101
|
export { DateField, type DateFieldProps } from './components/app/date-field.js';
|
|
100
102
|
export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
|
|
101
103
|
export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,10 @@ export { JobStatus } from './components/app/job-status.js';
|
|
|
53
53
|
export { OfflineNotice } from './components/app/offline-notice.js';
|
|
54
54
|
export { useOffline } from './lib/connection.js';
|
|
55
55
|
export { editInPlace, } from './components/app/edit-in-place.js';
|
|
56
|
+
// "Keep Mine" for long text after it changed elsewhere: both sides' edits,
|
|
57
|
+
// block by block, or null when they touch the same part (an `editInPlace`'s
|
|
58
|
+
// `rebase`; long text has it by default).
|
|
59
|
+
export { rebaseMarkdown } from './lib/markdown-merge.js';
|
|
56
60
|
export { inPlace, } from './components/app/edit-in-place-presets.js';
|
|
57
61
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
58
62
|
export { TITLE_CASE_SMALL_WORDS, titleCase } from './lib/title-case.js';
|
|
@@ -104,6 +108,7 @@ export { MultiLineChart, } from './components/app/multi-line-chart.js';
|
|
|
104
108
|
export { StepBar } from './components/app/step-bar.js';
|
|
105
109
|
export { RatingStar } from './components/app/rating-star.js';
|
|
106
110
|
export { RatingScore } from './components/app/rating-score.js';
|
|
111
|
+
export { RatingInput } from './components/app/rating-input.js';
|
|
107
112
|
export { DateField } from './components/app/date-field.js';
|
|
108
113
|
export { EmojiField } from './components/app/emoji-field.js';
|
|
109
114
|
export { MonthDayField } from './components/app/month-day-field.js';
|
|
@@ -34,6 +34,18 @@ export declare class MarkdownMergeError extends Error {
|
|
|
34
34
|
* than `current`.
|
|
35
35
|
*/
|
|
36
36
|
export declare function mergeMarkdown(original: string, baseline: string, current: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Both edits at once, block by block: `mine` and `theirs` each started from
|
|
39
|
+
* `base` (the same saved text, edited in two places: this tab and another
|
|
40
|
+
* tab, a phone or an AI chat). Every top-level block only one side changed
|
|
41
|
+
* takes that side's change; a block neither changed keeps `theirs`'s own
|
|
42
|
+
* bytes. Returns null when both changed the same stretch of blocks (or
|
|
43
|
+
* both added text at the same place), when it can't be done without
|
|
44
|
+
* losing one of them: the caller asks the person instead. A three-way
|
|
45
|
+
* merge (diff3) over blocks matched by meaning, as `mergeMarkdown`
|
|
46
|
+
* matches them; it never merges inside a block.
|
|
47
|
+
*/
|
|
48
|
+
export declare function rebaseMarkdown(base: string, mine: string, theirs: string): string | null;
|
|
37
49
|
/**
|
|
38
50
|
* The document's own marks, for writing a block the person edited the way
|
|
39
51
|
* the rest is written: its bullet (`-`, `*`, `+`) and its thematic break.
|