@tristan2828/ui-foundation 4.122.0 → 4.123.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 +25 -16
- package/conventions/docs/cell-patterns.md +11 -5
- package/conventions/docs/design-language.md +24 -10
- package/dist/components/app/data-table.d.ts +10 -1
- package/dist/components/app/data-table.js +3 -3
- package/dist/components/app/delete-action.js +3 -2
- package/dist/components/app/entity-view-facts.d.ts +8 -0
- package/dist/components/app/entity-view-facts.js +10 -4
- package/dist/components/app/filter-bar.d.ts +7 -1
- package/dist/components/app/filter-bar.js +3 -2
- package/dist/components/app/filter-date.js +2 -1
- package/dist/components/app/filter-name.d.ts +1 -0
- package/dist/components/app/filter-name.js +11 -0
- package/dist/components/app/icon-action.d.ts +8 -2
- package/dist/components/app/icon-action.js +20 -3
- package/dist/components/app/list-header.d.ts +2 -0
- package/dist/components/app/list-header.js +1 -1
- package/dist/components/app/milkdown-editor.js +19 -3
- package/dist/components/app/rich-text-editor.d.ts +2 -1
- package/dist/components/app/rich-text-editor.js +8 -4
- package/dist/components/app/rich-text-slash.d.ts +9 -3
- package/dist/components/app/rich-text-slash.js +17 -4
- package/dist/components/ui/field.js +4 -2
- package/dist/hooks/table-url-changes.js +2 -1
- package/dist/hooks/use-table-url-state.js +15 -4
- package/dist/index.d.ts +1 -1
- package/openapi/foundation.yaml +1 -1
- package/package.json +1 -1
|
@@ -15,18 +15,18 @@
|
|
|
15
15
|
- Step 8: Add Playwright specs for all three screens · lines 760–837
|
|
16
16
|
- Step 9: Register the nav entry and route names · lines 838–852
|
|
17
17
|
- Step 10: `npm run verify`. · lines 853–855
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines 857–
|
|
19
|
-
- [The record view](#the-record-view) · lines 1010–
|
|
20
|
-
- [Forms](#forms) · lines
|
|
21
|
-
- [Dialogs](#dialogs) · lines
|
|
22
|
-
- [Toasts and feedback](#toasts-and-feedback) · lines
|
|
23
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
24
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
25
|
-
- [Deleting](#deleting) · lines
|
|
26
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
27
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
28
|
-
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines
|
|
29
|
-
- [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 857–1326
|
|
19
|
+
- [The record view](#the-record-view) · lines 1010–1167
|
|
20
|
+
- [Forms](#forms) · lines 1169–1240
|
|
21
|
+
- [Dialogs](#dialogs) · lines 1242–1273
|
|
22
|
+
- [Toasts and feedback](#toasts-and-feedback) · lines 1275–1326
|
|
23
|
+
- [What not to copy](#what-not-to-copy) · lines 1328–1361
|
|
24
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1363–1380
|
|
25
|
+
- [Deleting](#deleting) · lines 1382–1413
|
|
26
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1415–1436
|
|
27
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1438–1447
|
|
28
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1450–1492
|
|
29
|
+
- [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1494–1530
|
|
30
30
|
|
|
31
31
|
<!-- /index -->
|
|
32
32
|
|
|
@@ -1071,6 +1071,7 @@ A record uses the parts it has, in this order:
|
|
|
1071
1071
|
{ label: 'Status', kind: 'status', status: STATUS_KINDS[record.status], word: STATUS_LABELS[record.status] },
|
|
1072
1072
|
{ label: 'By', kind: 'text', text: formatDay(record.due) },
|
|
1073
1073
|
{ label: 'Areas', kind: 'badges', items: record.areas.map(areaLabel) },
|
|
1074
|
+
{ label: 'Flags', kind: 'badges', items: [{ label: 'Pinned', icon: PinIcon, tone: 'info' }] },
|
|
1074
1075
|
{ label: 'From', kind: 'record', name: provider.name, to: `/providers/${provider.id}`, short: true },
|
|
1075
1076
|
{ label: 'Open Tasks', kind: 'count', count: record.openTasks, to: `/tasks?project=${record.id}` },
|
|
1076
1077
|
{ label: 'Task', kind: 'link', href: task.url, name: task.name },
|
|
@@ -1112,7 +1113,10 @@ A record uses the parts it has, in this order:
|
|
|
1112
1113
|
hover and keyboard focus, and a line under the value on a touch
|
|
1113
1114
|
screen. Both are drawn in Details too, where the rail folds.
|
|
1114
1115
|
- A `badges` item may be `{ label, icon }` (4.115): the icon (a
|
|
1115
|
-
component or a node) before the label, in the muted tone.
|
|
1116
|
+
component or a node) before the label, in the muted tone. With
|
|
1117
|
+
`tone` (4.123: `success`, `warning`, `info`, `destructive`) a label
|
|
1118
|
+
that is a state ("Pinned", "Overdue") is the outline badge in that
|
|
1119
|
+
tone, its icon too; the word still says it.
|
|
1116
1120
|
- **A rating** (4.117) is `kind: 'rating'`, drawn as the list's cells
|
|
1117
1121
|
draw it, never as "4 of 5" text: stars (the default) or hearts for a
|
|
1118
1122
|
score out of `max` (5), the step bar for a quality level. `null` is
|
|
@@ -1178,7 +1182,8 @@ shape (4.85):
|
|
|
1178
1182
|
short one alone where a pairing would read wrong. Under 48rem every
|
|
1179
1183
|
field takes its own row but two dates or two numbers (`DateField` says
|
|
1180
1184
|
so itself; a date picker of your own with `kind="date"`). A choice
|
|
1181
|
-
(`ChoiceButtons`, found by itself, 4.98
|
|
1185
|
+
(`ChoiceButtons`, found by itself, 4.98, or a `ToggleGroup` that is the
|
|
1186
|
+
field's own control, 4.123) shares a row only with another
|
|
1182
1187
|
choice, two to a row; on a phone two stay side by side while both
|
|
1183
1188
|
groups fit, and go one per row when they don't. Never a hand-made
|
|
1184
1189
|
`sm:grid-cols-2` row. The picked option is in the theme colour (4.105);
|
|
@@ -1293,7 +1298,10 @@ sight.** What happened where the person is looking says so there.
|
|
|
1293
1298
|
the same component (`size="sm"`), or `trigger={null}` with
|
|
1294
1299
|
`open`/`onOpenChange`, opened by a `DataTable` `rowActions` entry's
|
|
1295
1300
|
`onSelect` (a row's ⋯ menu). `verb="Retire"` for a retire.
|
|
1296
|
-
Never a delete without a confirm, never a hand-written dialog.
|
|
1301
|
+
Never a delete without a confirm, never a hand-written dialog. Its icon
|
|
1302
|
+
is named "Delete <name>" (4.123), so several on one page (a record's,
|
|
1303
|
+
each of its rows') are told apart; its tooltip says "Delete". A test
|
|
1304
|
+
finds one by `getByRole('button', { name: 'Delete The Long Walk' })`.
|
|
1297
1305
|
- **A delete that asks a reason: `DeleteAction reason`** (4.96). One
|
|
1298
1306
|
optional field between the sentence and the buttons, a "Why" box:
|
|
1299
1307
|
`reason={{ label: 'Why remove it?', hint: 'Kept with its history.' }}`
|
|
@@ -1341,7 +1349,8 @@ sight.** What happened where the person is looking says so there.
|
|
|
1341
1349
|
`{}` with the server's default doing the rest), name the one the list
|
|
1342
1350
|
opens on with `defaultView`, and put what no control can show (a
|
|
1343
1351
|
computed "overdue") in the view's `rule` (cell-patterns.md "Saved views
|
|
1344
|
-
are pills").
|
|
1352
|
+
are pills"). The default view's `sort` is its plain address's too
|
|
1353
|
+
(4.123): pressing it writes no `?sort=`, and the rows keep that order.
|
|
1345
1354
|
- `src/api/gateway/widgets.ts`, `src/mocks/data.ts`, `src/mocks/handlers.ts`
|
|
1346
1355
|
are demo-domain content — write the entity's own versions rather than
|
|
1347
1356
|
adapting these by find-and-replace.
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1822–1860
|
|
41
41
|
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1862–1938
|
|
42
42
|
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1940–1963
|
|
43
|
-
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1965–
|
|
44
|
-
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines
|
|
45
|
-
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines
|
|
46
|
-
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines
|
|
43
|
+
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1965–2190
|
|
44
|
+
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2119–2190
|
|
45
|
+
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2192–2228
|
|
46
|
+
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2230–2279
|
|
47
47
|
|
|
48
48
|
<!-- /index -->
|
|
49
49
|
|
|
@@ -2051,7 +2051,13 @@ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView
|
|
|
2051
2051
|
most (`primary`), and the rest behind Filters (`secondary`, with their
|
|
2052
2052
|
chips, as `SecondaryFilters` draws them). No captions over controls:
|
|
2053
2053
|
each names itself. `FilterSelect` says "Any status" while off and
|
|
2054
|
-
"Status: Active" on
|
|
2054
|
+
"Status: Active" on, and is named by its label first (4.123): "Status"
|
|
2055
|
+
while it shows "Any status", "Status: Active", "Status: All reminders"
|
|
2056
|
+
for an `anyLabel` that doesn't say the label (`FilterDate` the same), so
|
|
2057
|
+
a test finds it by `getByRole('combobox', { name: /^Status/ })`.
|
|
2058
|
+
`search.onKeyDown` (4.123) gives the search box's keys to the app
|
|
2059
|
+
first: Enter on "#12" opening record 12, `preventDefault()` keeping the
|
|
2060
|
+
key from the box. `MultiChoice`'s `label` makes it "Rooms: Hall +1"
|
|
2055
2061
|
instead of a chip per pick. Below 48rem search and Filters share a line
|
|
2056
2062
|
and every filter, primary ones too, is in Filters' bottom sheet, so pass
|
|
2057
2063
|
`primaryActive` (their chips) and an `onClearAll` that clears them all
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
- [A list as a board](#a-list-as-a-board) · lines 1246–1297
|
|
30
30
|
- [A list as cards](#a-list-as-cards) · lines 1299–1345
|
|
31
31
|
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1347–1383
|
|
32
|
-
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1385–
|
|
33
|
-
- [A few equal things](#a-few-equal-things) · lines
|
|
34
|
-
- [An overview page](#an-overview-page) · lines
|
|
35
|
-
- [A record's header and empty values](#a-records-header-and-empty-values) · lines
|
|
36
|
-
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines
|
|
37
|
-
- [Picking at random](#picking-at-random) · lines
|
|
38
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
39
|
-
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines
|
|
40
|
-
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines
|
|
32
|
+
- [Parts of the page standards](#parts-of-the-page-standards) · lines 1385–1455
|
|
33
|
+
- [A few equal things](#a-few-equal-things) · lines 1457–1541
|
|
34
|
+
- [An overview page](#an-overview-page) · lines 1543–1614
|
|
35
|
+
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1615–1678
|
|
36
|
+
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1680–1804
|
|
37
|
+
- [Picking at random](#picking-at-random) · lines 1806–1837
|
|
38
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1839–1906
|
|
39
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1908–1933
|
|
40
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1935–2031
|
|
41
41
|
|
|
42
42
|
<!-- /index -->
|
|
43
43
|
|
|
@@ -1418,6 +1418,15 @@ into a table, a record or an overview.
|
|
|
1418
1418
|
list that needs it ("Each search runs against the catalog once a
|
|
1419
1419
|
day."). It wraps in the header's width and never widens a framed
|
|
1420
1420
|
table's shared width; on a phone it's under the title and its buttons.
|
|
1421
|
+
A `more` item that can't be used now (4.123, `disabled: true`: an
|
|
1422
|
+
import already running) stays in ⋯, greyed, never hidden.
|
|
1423
|
+
- **A bar between the header and the list** (`DataTable pageBar`, 4.123):
|
|
1424
|
+
something about the whole page that belongs above its rows, such as a
|
|
1425
|
+
deals bar, "Allow Reminders" or a budget's totals. It's drawn under
|
|
1426
|
+
`pageHeader` and above the views, in the same box, so C3 holds: the
|
|
1427
|
+
header, the bar and the card share the table's width, and the bar
|
|
1428
|
+
wraps in it rather than widening it. Never a bar put between a
|
|
1429
|
+
separate `ListHeader` and the table, which loses the shared width.
|
|
1421
1430
|
One sentence: anything longer belongs in a help page.
|
|
1422
1431
|
- **`Timeline`: a record's dated history.** `items` newest first
|
|
1423
1432
|
(`{ id, date, dateTime?, kind?, body, edit? }`): dates in a tabular
|
|
@@ -1634,7 +1643,12 @@ data on each its own.
|
|
|
1634
1643
|
done), then the universal ones as `IconAction`s: Print Notes
|
|
1635
1644
|
(`printer`, EntityView's own) and Delete (`trash-2`, the destructive
|
|
1636
1645
|
tone). Each is a square outline button at the header's 36px with its
|
|
1637
|
-
words as both its tooltip and its accessible name.
|
|
1646
|
+
words as both its tooltip and its accessible name. An `IconAction`
|
|
1647
|
+
that goes somewhere (Open Site, Print to a page) takes the link as
|
|
1648
|
+
`render` (4.123, `render={<Link to="/print" />}` or `render={<a href=…
|
|
1649
|
+
target="_blank" />}`) and is drawn as that link. `accessibleName` says
|
|
1650
|
+
more than the tooltip where several are on one page: `DeleteAction`'s
|
|
1651
|
+
icon is named "Delete <name>" (4.123), its tooltip still "Delete". Icon alone is for
|
|
1638
1652
|
the universal actions only (Delete, Print Notes, Copy link, Pin, Open
|
|
1639
1653
|
site, Restore, Open Full Page, Close, More); everything else keeps its
|
|
1640
1654
|
word. `printLook="words"` keeps Print Notes as a button with its words.
|
|
@@ -288,6 +288,15 @@ export type DataTableProps<TData extends Record<string, unknown>, TView extends
|
|
|
288
288
|
* phone, it spans the page as before.
|
|
289
289
|
*/
|
|
290
290
|
pageHeader?: ReactNode;
|
|
291
|
+
/**
|
|
292
|
+
* A bar between the page header and the list (4.123): something about
|
|
293
|
+
* the whole page that belongs above its rows, such as a deals bar, an
|
|
294
|
+
* "Allow reminders" notice or a budget's totals. Drawn under
|
|
295
|
+
* `pageHeader` and above the views, so C3 holds: the header, the bar and
|
|
296
|
+
* the card are still one box as wide as the table, and the bar never
|
|
297
|
+
* widens it (it wraps in that width instead).
|
|
298
|
+
*/
|
|
299
|
+
pageBar?: ReactNode;
|
|
291
300
|
/**
|
|
292
301
|
* A Columns menu at the end of the toolbar (L5): a tick for every column
|
|
293
302
|
* but the first (the name) and the row actions, remembered on this device
|
|
@@ -415,4 +424,4 @@ export type DataTableTotals = {
|
|
|
415
424
|
*/
|
|
416
425
|
cells?: Partial<Record<string, ReactNode>>;
|
|
417
426
|
};
|
|
418
|
-
export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, views, activeView, onViewChange, viewsLabel, pageHeader, columnsMenu, rowActions, phoneRow, limit, viewAll, look, }: DataTableProps<TData, TView>): import("react").JSX.Element;
|
|
427
|
+
export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, views, activeView, onViewChange, viewsLabel, pageHeader, pageBar, columnsMenu, rowActions, phoneRow, limit, viewAll, look, }: DataTableProps<TData, TView>): import("react").JSX.Element;
|
|
@@ -428,7 +428,7 @@ const ROW_ACTIONS_COLUMN = {
|
|
|
428
428
|
};
|
|
429
429
|
// The cell under the actions' column: as narrow as its button.
|
|
430
430
|
const ROW_ACTIONS_CELL_CLASS = 'w-px py-0';
|
|
431
|
-
export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', views, activeView = null, onViewChange, viewsLabel = 'Views', pageHeader, columnsMenu, rowActions, phoneRow, limit, viewAll, look = 'plain', }) {
|
|
431
|
+
export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', views, activeView = null, onViewChange, viewsLabel = 'Views', pageHeader, pageBar, columnsMenu, rowActions, phoneRow, limit, viewAll, look = 'plain', }) {
|
|
432
432
|
// The switch's own state, for a table that doesn't pass `layout`.
|
|
433
433
|
const [ownLayout, setOwnLayout] = useState('table');
|
|
434
434
|
const requestedLayout = layoutProp ?? ownLayout;
|
|
@@ -854,8 +854,8 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
854
854
|
// C3: with a header, the header, views and card are one box as wide as
|
|
855
855
|
// the table (the box fits its content, the card fills the box), so the
|
|
856
856
|
// header ends where the card does. CSS only: nothing is measured.
|
|
857
|
-
const sharedWidth = Boolean(pageHeader) && fitsColumns;
|
|
858
|
-
const content = framed ? (_jsxs("div", { ref: root, className: cn('flex flex-col gap-4', sharedWidth && CONTENT_WIDTH_CLASS), "data-width": width, "data-look": "framed", "data-shared-width": sharedWidth ? '' : undefined, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, viewPills, _jsx(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: _jsxs("div", { ref: body, "data-slot": "data-table-frame", className: cn(FRAME_CLASS, fitsColumns && !sharedWidth && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: [framedToolbar, _jsx("div", { "data-slot": "data-table-body", className: cn('flex flex-col gap-4', (stateView || cardLayout) && 'p-3', showPhoneRows && !stateView && FRAMED_PHONE_ROWS_CLASS), children: stateView ?? rowsView }), stateView ? null : pagination] }) })] })) : (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, viewPills, plainToolbar, _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: stateView ?? (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: [rowsView, pagination] })) })] }));
|
|
857
|
+
const sharedWidth = Boolean(pageHeader || pageBar) && fitsColumns;
|
|
858
|
+
const content = framed ? (_jsxs("div", { ref: root, className: cn('flex flex-col gap-4', sharedWidth && CONTENT_WIDTH_CLASS), "data-width": width, "data-look": "framed", "data-shared-width": sharedWidth ? '' : undefined, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, pageBar && (_jsx("div", { "data-slot": "data-table-page-bar", className: "min-w-0 contain-inline-size", children: pageBar })), viewPills, _jsx(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: _jsxs("div", { ref: body, "data-slot": "data-table-frame", className: cn(FRAME_CLASS, fitsColumns && !sharedWidth && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: [framedToolbar, _jsx("div", { "data-slot": "data-table-body", className: cn('flex flex-col gap-4', (stateView || cardLayout) && 'p-3', showPhoneRows && !stateView && FRAMED_PHONE_ROWS_CLASS), children: stateView ?? rowsView }), stateView ? null : pagination] }) })] })) : (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, pageBar && (_jsx("div", { "data-slot": "data-table-page-bar", className: "min-w-0 contain-inline-size", children: pageBar })), viewPills, plainToolbar, _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: stateView ?? (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: [rowsView, pagination] })) })] }));
|
|
859
859
|
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs(RowActionsContext.Provider, { value: rowActions, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
|
|
860
860
|
if (!open)
|
|
861
861
|
setSelection(null);
|
|
@@ -20,7 +20,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
20
20
|
// typed, closing asks "Discard your changes?" first (the dialog
|
|
21
21
|
// standard's `dirty`). Width, words and the buttons stay as they are.
|
|
22
22
|
//
|
|
23
|
-
// The trigger is an icon (IconAction's Trash2
|
|
23
|
+
// The trigger is an icon (IconAction's Trash2, named "Delete <name>" since
|
|
24
|
+
// 4.123, its tooltip "Delete") unless `trigger` says
|
|
24
25
|
// otherwise: `"button"` for a "Delete" button in words, an element of the
|
|
25
26
|
// caller's, or `null` for none, opened with `open`/`onOpenChange` (a row's
|
|
26
27
|
// menu item).
|
|
@@ -74,5 +75,5 @@ export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb
|
|
|
74
75
|
if (!next)
|
|
75
76
|
remove.reset();
|
|
76
77
|
setOpen(next);
|
|
77
|
-
}, children: [trigger === 'icon' && (_jsx(DialogTrigger, { render: _jsx(IconAction, { icon: Trash2Icon, label: verb, tone: "destructive", size: size }) })), trigger === 'button' && (_jsx(DialogTrigger, { render: _jsx(Button, { variant: "outline", size: size === 'sm' ? 'sm' : 'default' }), children: verb })), trigger && typeof trigger === 'object' && _jsx(DialogTrigger, { render: trigger }), _jsxs(DialogContent, { size: "confirm", dirty: reason !== undefined && typed.trim() !== '' && !remove.pending, "data-slot": "delete-action", "data-kind": kind, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: [verb, " ", name, "?"] }), _jsx(DialogDescription, { children: description ?? SAYS[kind] })] }), reason && (_jsxs(Field, { "data-slot": "delete-action-reason", children: [_jsx(FieldLabel, { htmlFor: reasonId, children: reason.label ?? 'Why' }), _jsx(Textarea, { id: reasonId, value: typed, placeholder: reason.placeholder, disabled: remove.pending, onChange: (event) => setTyped(event.target.value) }), reason.hint && _jsx(FieldDescription, { children: reason.hint })] })), _jsx(ActionError, { action: { ...remove, retry: confirm } }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", disabled: remove.pending }), children: "Cancel" }), _jsxs(Button, { variant: "destructive", disabled: remove.pending, onClick: () => void confirm(), children: [remove.pending && _jsx(Spinner, { className: "size-4" }), verb] })] })] })] }));
|
|
78
|
+
}, children: [trigger === 'icon' && (_jsx(DialogTrigger, { render: _jsx(IconAction, { icon: Trash2Icon, label: verb, accessibleName: `${verb} ${name}`, tone: "destructive", size: size }) })), trigger === 'button' && (_jsx(DialogTrigger, { render: _jsx(Button, { variant: "outline", size: size === 'sm' ? 'sm' : 'default' }), children: verb })), trigger && typeof trigger === 'object' && _jsx(DialogTrigger, { render: trigger }), _jsxs(DialogContent, { size: "confirm", dirty: reason !== undefined && typed.trim() !== '' && !remove.pending, "data-slot": "delete-action", "data-kind": kind, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: [verb, " ", name, "?"] }), _jsx(DialogDescription, { children: description ?? SAYS[kind] })] }), reason && (_jsxs(Field, { "data-slot": "delete-action-reason", children: [_jsx(FieldLabel, { htmlFor: reasonId, children: reason.label ?? 'Why' }), _jsx(Textarea, { id: reasonId, value: typed, placeholder: reason.placeholder, disabled: remove.pending, onChange: (event) => setTyped(event.target.value) }), reason.hint && _jsx(FieldDescription, { children: reason.hint })] })), _jsx(ActionError, { action: { ...remove, retry: confirm } }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", disabled: remove.pending }), children: "Cancel" }), _jsxs(Button, { variant: "destructive", disabled: remove.pending, onClick: () => void confirm(), children: [remove.pending && _jsx(Spinner, { className: "size-4" }), verb] })] })] })] }));
|
|
78
79
|
}
|
|
@@ -101,7 +101,15 @@ export type EntityViewFactBadge = {
|
|
|
101
101
|
label: string;
|
|
102
102
|
/** An icon component (a `LucideIcon`, an app's own mark) or a node drawn as it is. Decorative: the label says it. */
|
|
103
103
|
icon?: IconComponent | ReactNode;
|
|
104
|
+
/**
|
|
105
|
+
* The badge's tone (4.123), for a label that is a state ("Pinned",
|
|
106
|
+
* "Overdue"): the outline badge in that tone's text colour, its icon
|
|
107
|
+
* too. Neutral (the outline) unless set. The word still says it.
|
|
108
|
+
*/
|
|
109
|
+
tone?: EntityViewFactBadgeTone;
|
|
104
110
|
};
|
|
111
|
+
/** A badge item's tone (4.123): the design language's four, as outline badges. */
|
|
112
|
+
export type EntityViewFactBadgeTone = 'success' | 'warning' | 'info' | 'destructive';
|
|
105
113
|
/** A small button under a fact's value (4.115): "Close…" under a status that changes only through it. */
|
|
106
114
|
export type EntityViewFactAction = {
|
|
107
115
|
/** The button's words ("Close…"; an ellipsis when it opens a dialog). */
|
|
@@ -9,15 +9,21 @@ import { RatingScore } from './rating-score.js';
|
|
|
9
9
|
import { StepBar } from './step-bar.js';
|
|
10
10
|
import { StatusMark } from './status-mark.js';
|
|
11
11
|
import { FactSwitch } from './fact-extras.js';
|
|
12
|
+
const BADGE_TONE = {
|
|
13
|
+
success: 'outline-success',
|
|
14
|
+
warning: 'outline-warning',
|
|
15
|
+
info: 'outline-info',
|
|
16
|
+
destructive: 'outline-destructive',
|
|
17
|
+
};
|
|
12
18
|
const LINK_CLASS = 'rounded-sm font-medium text-link underline-offset-4 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50';
|
|
13
19
|
// A badge item's icon in the muted tone a list's item icons have
|
|
14
20
|
// (FactList's marks): a component drawn at the badge's icon size, or the
|
|
15
21
|
// app's own node as it is.
|
|
16
|
-
function badgeIcon(icon) {
|
|
22
|
+
function badgeIcon(icon, toned = false) {
|
|
17
23
|
// A component: a function, or a forwardRef or memo object (a LucideIcon); an element is a node.
|
|
18
24
|
const isComponent = typeof icon === 'function' || (typeof icon === 'object' && icon !== null && !isValidElement(icon) && '$$typeof' in icon);
|
|
19
25
|
const Icon = icon;
|
|
20
|
-
return (_jsx("span", { "data-slot": "entity-view-fact-badge-icon", "aria-hidden": "true", "data-icon": "inline-start", className:
|
|
26
|
+
return (_jsx("span", { "data-slot": "entity-view-fact-badge-icon", "aria-hidden": "true", "data-icon": "inline-start", className: cn('inline-flex shrink-0', !toned && 'text-muted-foreground'), children: isComponent ? _jsx(Icon, { "aria-hidden": "true", className: "size-3" }) : icon }));
|
|
21
27
|
}
|
|
22
28
|
/** A fact as the view draws it: `null` when empty. `label` names a control the fact draws (a switch). */
|
|
23
29
|
export function factValue(fact, label = '') {
|
|
@@ -36,8 +42,8 @@ export function factValue(fact, label = '') {
|
|
|
36
42
|
if (fact.items.length === 0)
|
|
37
43
|
return null;
|
|
38
44
|
return (_jsx("span", { className: "inline-flex max-w-full flex-wrap gap-1", children: fact.items.map((item, index) => {
|
|
39
|
-
const { label, icon } = typeof item === 'string' ? { label: item, icon: undefined } : item;
|
|
40
|
-
return (_jsxs(Badge, { variant:
|
|
45
|
+
const { label, icon, tone } = typeof item === 'string' ? { label: item, icon: undefined, tone: undefined } : item;
|
|
46
|
+
return (_jsxs(Badge, { variant: tone ? BADGE_TONE[tone] : 'outline', "data-tone": tone, className: "max-w-full", children: [icon !== undefined && icon !== null && badgeIcon(icon, tone !== undefined), _jsx("span", { className: "min-w-0 truncate", children: label })] }, `${index}:${label}`));
|
|
41
47
|
}) }));
|
|
42
48
|
case 'count':
|
|
43
49
|
return fact.to ? (_jsx(Link, { to: fact.to, className: cn(LINK_CLASS, 'tabular-nums'), children: fact.count })) : (_jsx("span", { className: "tabular-nums", children: fact.count }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { KeyboardEvent, ReactNode } from 'react';
|
|
2
2
|
import { type ActiveFilter } from './secondary-filters.js';
|
|
3
3
|
export type FilterBarSearch = {
|
|
4
4
|
value: string;
|
|
@@ -7,6 +7,12 @@ export type FilterBarSearch = {
|
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
/** The box's accessible name: "Search" unless set. */
|
|
9
9
|
label?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A key pressed in the box (4.123): Enter opening the one match, or
|
|
12
|
+
* "#12" going straight to record 12. Called before the box's own
|
|
13
|
+
* handling; `event.preventDefault()` keeps the key from it.
|
|
14
|
+
*/
|
|
15
|
+
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
10
16
|
};
|
|
11
17
|
export type FilterBarProps = {
|
|
12
18
|
search?: FilterBarSearch;
|
|
@@ -3,11 +3,12 @@ import { SearchIcon } from 'lucide-react';
|
|
|
3
3
|
import { InputGroup, InputGroupAddon, InputGroupInput } from '../ui/input-group.js';
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
5
|
import { useIsPhone } from '../../hooks/use-is-phone.js';
|
|
6
|
+
import { filterName } from './filter-name.js';
|
|
6
7
|
import { SecondaryFilters } from './secondary-filters.js';
|
|
7
8
|
const SEARCH_CLASS = 'w-56 max-w-full';
|
|
8
9
|
export function FilterBar({ search, primary, primaryActive = [], secondary, active = [], onClear, onClearAll, filtersLabel = 'Filters', }) {
|
|
9
10
|
const isMobile = useIsPhone();
|
|
10
|
-
const searchBox = search ? (_jsxs(InputGroup, { className: isMobile ? 'min-w-0 flex-1 basis-40' : SEARCH_CLASS, "data-slot": "filter-bar-search", children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, { "aria-hidden": "true" }) }), _jsx(InputGroupInput, { type: "search", value: search.value, onChange: (event) => search.onChange(event.target.value), placeholder: search.placeholder, "aria-label": search.label ?? 'Search' })] })) : null;
|
|
11
|
+
const searchBox = search ? (_jsxs(InputGroup, { className: isMobile ? 'min-w-0 flex-1 basis-40' : SEARCH_CLASS, "data-slot": "filter-bar-search", children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, { "aria-hidden": "true" }) }), _jsx(InputGroupInput, { type: "search", value: search.value, onChange: (event) => search.onChange(event.target.value), placeholder: search.placeholder, "aria-label": search.label ?? 'Search', onKeyDown: search.onKeyDown })] })) : null;
|
|
11
12
|
if (isMobile) {
|
|
12
13
|
const hasSheet = Boolean(primary || secondary);
|
|
13
14
|
return (_jsxs("div", { "data-slot": "filter-bar", "data-layout": "phone", className: "flex flex-wrap items-center gap-2", children: [searchBox, hasSheet && (_jsxs(SecondaryFilters, { className: "contents", label: filtersLabel, active: [...primaryActive, ...active], onClear: onClearAll ?? onClear ?? (() => { }), children: [primary, secondary] }))] }));
|
|
@@ -24,5 +25,5 @@ export function FilterSelect({ label, options, value, onValueChange, anyLabel, c
|
|
|
24
25
|
const any = anyLabel ?? `Any ${label}`;
|
|
25
26
|
const picked = options.find((option) => option.value === value);
|
|
26
27
|
const shown = picked ? `${label}: ${picked.label}` : any;
|
|
27
|
-
return (_jsxs(Select, { value: picked ? picked.value : ANY, onValueChange: (next) => onValueChange(next === ANY || next === null ? '' : String(next)), children: [_jsx(SelectTrigger, { "aria-label": shown, "data-slot": "filter-select", "data-active": picked ? true : undefined, className: className, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), options.map((option) => (_jsx(SelectItem, { value: option.value, children: option.label }, option.value)))] })] }));
|
|
28
|
+
return (_jsxs(Select, { value: picked ? picked.value : ANY, onValueChange: (next) => onValueChange(next === ANY || next === null ? '' : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-select", "data-active": picked ? true : undefined, className: className, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), options.map((option) => (_jsx(SelectItem, { value: option.value, children: option.label }, option.value)))] })] }));
|
|
28
29
|
}
|
|
@@ -11,6 +11,7 @@ import { cn } from 'cn';
|
|
|
11
11
|
import { Select, SelectContent, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
12
12
|
import { DATE_FILTER_PRESETS, DATE_FILTER_PRESET_LABELS, dateFilterText, dateRangeValue, parseDateFilter, } from '../../lib/date-filter.js';
|
|
13
13
|
import { DateField } from './date-field.js';
|
|
14
|
+
import { filterName } from './filter-name.js';
|
|
14
15
|
// Base UI's Select needs a value for "any" that isn't empty.
|
|
15
16
|
const ANY = '__any__';
|
|
16
17
|
const RANGE = '__range__';
|
|
@@ -41,5 +42,5 @@ export function FilterDate({ label, value, onValueChange, presets = DATE_FILTER_
|
|
|
41
42
|
const setEnd = (end, day) => {
|
|
42
43
|
onValueChange(dateRangeValue({ ...bounds, [end]: day || undefined }));
|
|
43
44
|
};
|
|
44
|
-
return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": shown, "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, locale: locale, className: "w-40" })] }))] }));
|
|
45
|
+
return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, locale: locale, className: "w-40" })] }))] }));
|
|
45
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterName(label: string, shown: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A filter select's accessible name (4.123, FilterSelect and FilterDate):
|
|
2
|
+
// what it filters first, so it's found by its label ("Status") whatever it
|
|
3
|
+
// shows, then the words shown unless they already say the label, so voice
|
|
4
|
+
// control can say them too. "Status" while it shows "Any status", "Status:
|
|
5
|
+
// Active" with a value, "Status: All reminders" for an `anyLabel` that
|
|
6
|
+
// doesn't say it.
|
|
7
|
+
export function filterName(label, shown) {
|
|
8
|
+
if (shown.startsWith(`${label}:`))
|
|
9
|
+
return shown;
|
|
10
|
+
return shown.toLowerCase().includes(label.toLowerCase()) ? label : `${label}: ${shown}`;
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
2
|
import { Button } from '../ui/button.js';
|
|
3
3
|
import type { IconComponent } from './icon-component.js';
|
|
4
4
|
export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | 'size' | 'aria-label'> & {
|
|
@@ -6,9 +6,15 @@ export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | '
|
|
|
6
6
|
icon: IconComponent;
|
|
7
7
|
/** What the action does ("Delete", "Print notes"): its tooltip and accessible name. */
|
|
8
8
|
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* The accessible name, when it says more than the tooltip (4.123):
|
|
11
|
+
* "Delete The Long Walk" for a tooltip of "Delete", so several on a page
|
|
12
|
+
* are told apart. Start it with `label`, so what's seen is what's said.
|
|
13
|
+
*/
|
|
14
|
+
accessibleName?: string;
|
|
9
15
|
/** `destructive` draws the icon in the destructive tone (Delete). Defaults to `default`. */
|
|
10
16
|
tone?: 'default' | 'destructive';
|
|
11
17
|
/** The button's size: `default` (36px, beside the header's other buttons) or `sm` (32px). */
|
|
12
18
|
size?: 'default' | 'sm';
|
|
13
19
|
};
|
|
14
|
-
export declare function IconAction({ icon: Icon, label, tone, size, variant, className, ...props }: IconActionProps): import("react").JSX.Element;
|
|
20
|
+
export declare function IconAction({ icon: Icon, label, accessibleName, tone, size, variant, className, render, ...props }: IconActionProps): import("react").JSX.Element;
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A command drawn as its icon alone (record page standard 3.2, #R3): an
|
|
3
|
+
// outline icon button at the header's button size, its `label` both the
|
|
4
|
+
// tooltip shown on hover or focus and the button's accessible name. For
|
|
5
|
+
// the universal actions only (Delete, Print notes, Copy link, Pin, Open
|
|
6
|
+
// site, Restore, More), each with one icon across the app; a record's own
|
|
7
|
+
// commands (New visit, Mark done) stay in words.
|
|
8
|
+
//
|
|
9
|
+
// It takes every Button prop, so it can be a dialog's trigger as it is:
|
|
10
|
+
// `<DialogTrigger render={<IconAction icon={Trash2Icon} label="Delete" tone="destructive" />} />`.
|
|
11
|
+
//
|
|
12
|
+
// A link (4.123): `render={<Link to="/print" />}` or `render={<a href=… />}`
|
|
13
|
+
// draws the icon as that link, its tooltip and name kept: the link is the
|
|
14
|
+
// tooltip's trigger itself, drawn as the button, so it stays a link with
|
|
15
|
+
// its href. A link takes no Button props.
|
|
16
|
+
import { isValidElement } from 'react';
|
|
2
17
|
import { cn } from 'cn';
|
|
3
|
-
import { Button } from '../ui/button.js';
|
|
18
|
+
import { Button, buttonVariants } from '../ui/button.js';
|
|
4
19
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
|
|
5
|
-
export function IconAction({ icon: Icon, label, tone = 'default', size = 'default', variant = 'outline', className, ...props }) {
|
|
6
|
-
|
|
20
|
+
export function IconAction({ icon: Icon, label, accessibleName, tone = 'default', size = 'default', variant = 'outline', className, render, ...props }) {
|
|
21
|
+
const look = cn(buttonVariants({ variant, size: size === 'sm' ? 'icon-sm' : 'icon' }), className);
|
|
22
|
+
const icon = _jsx(Icon, { "aria-hidden": "true", className: cn('size-4', tone === 'destructive' && 'text-destructive-text') });
|
|
23
|
+
return (_jsxs(Tooltip, { children: [render && isValidElement(render) ? (_jsx(TooltipTrigger, { render: render, "data-slot": "icon-action", "data-variant": variant, "aria-label": accessibleName ?? label, className: look, children: icon })) : (_jsx(TooltipTrigger, { render: _jsx(Button, { ...props, render: render, "data-slot": "icon-action", variant: variant, size: size === 'sm' ? 'icon-sm' : 'icon', "aria-label": accessibleName ?? label, className: className }), children: icon })), _jsx(TooltipContent, { children: label })] }));
|
|
7
24
|
}
|
|
@@ -9,6 +9,8 @@ export type ListHeaderAction = {
|
|
|
9
9
|
label: string;
|
|
10
10
|
onSelect: () => void;
|
|
11
11
|
icon?: IconComponent;
|
|
12
|
+
/** Can't be used now (4.123): an import already running, nothing to export. The item stays in ⋯, greyed. */
|
|
13
|
+
disabled?: boolean;
|
|
12
14
|
};
|
|
13
15
|
/** The one button beside New (4.117): a link to a page, or a function. */
|
|
14
16
|
export type ListHeaderSecondaryAction = {
|
|
@@ -64,7 +64,7 @@ export function ListHeader({ title, count, description, links = [], newAction, s
|
|
|
64
64
|
// A hint line under the button lines the row up by its tops (the title
|
|
65
65
|
// and the buttons level), the line hanging below.
|
|
66
66
|
const hinted = Boolean(secondaryAction?.hint);
|
|
67
|
-
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: cn('flex flex-wrap justify-between gap-x-4 gap-y-2', hinted ? 'items-start' : 'items-center'), children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: cn('ml-auto flex flex-wrap gap-2', hinted ? 'items-start' : 'items-center'), children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more", className: hasOwnMenu ? undefined : 'md:hidden' }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [secondaryAction && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { "data-slot": "list-header-secondary-item", className: "md:hidden", disabled: secondaryAction.disabled, render: secondaryAction.to !== undefined ? _jsx(Link, { to: secondaryAction.to }) : undefined, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.hint ? (_jsxs("span", { className: "flex flex-col", children: [secondaryAction.label, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { "data-slot": "list-header-secondary-item-hint", className: "type-caption text-muted-foreground", children: secondaryAction.hint })] })) : (secondaryAction.label)] }), hasOwnMenu && _jsx(DropdownMenuSeparator, { className: "md:hidden" })] })), menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), secondaryButton &&
|
|
67
|
+
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: cn('flex flex-wrap justify-between gap-x-4 gap-y-2', hinted ? 'items-start' : 'items-center'), children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: cn('ml-auto flex flex-wrap gap-2', hinted ? 'items-start' : 'items-center'), children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more", className: hasOwnMenu ? undefined : 'md:hidden' }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [secondaryAction && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { "data-slot": "list-header-secondary-item", className: "md:hidden", disabled: secondaryAction.disabled, render: secondaryAction.to !== undefined ? _jsx(Link, { to: secondaryAction.to }) : undefined, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.hint ? (_jsxs("span", { className: "flex flex-col", children: [secondaryAction.label, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { "data-slot": "list-header-secondary-item-hint", className: "type-caption text-muted-foreground", children: secondaryAction.hint })] })) : (secondaryAction.label)] }), hasOwnMenu && _jsx(DropdownMenuSeparator, { className: "md:hidden" })] })), menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, disabled: action.disabled, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), secondaryButton &&
|
|
68
68
|
(secondaryAction?.hint ? (_jsx(ActionHint, { hint: secondaryAction.hint, className: "max-md:hidden", children: secondaryButton })) : (_jsx("span", { className: "contents max-md:hidden", children: secondaryButton }))), newAction &&
|
|
69
69
|
(newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), description && (_jsx("p", { "data-slot": "list-header-description", className: "mt-1 max-w-prose type-body text-muted-foreground contain-inline-size", children: description })), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the List" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
|
|
70
70
|
}
|
|
@@ -114,7 +114,7 @@ import { withEmptyParagraphChildren } from './rich-text-empty-paragraph.js';
|
|
|
114
114
|
import { toggleHeadingInputRule, toggleHeadingRemark, withToggle } from './rich-text-toggle-heading.js';
|
|
115
115
|
import { addRowAtEnd, colorTableCells, fitAllColumns, handleTableKey, previewColumnWidth, runTableAction, setColumnWidth, tableLook as tableLookPlugin, tableWidthsOf } from './rich-text-table.js';
|
|
116
116
|
import { TABLE_MENU_EVENT, TableGrips } from './rich-text-table-grips.js';
|
|
117
|
-
import { applySlash, closeSlash, slashItems, slashOptionId, slashPlugin, slashQuery, } from './rich-text-slash.js';
|
|
117
|
+
import { applySlash, clearSlash, closeSlash, slashItems, slashOptionId, slashPlugin, slashQuery, } from './rich-text-slash.js';
|
|
118
118
|
import { RichTextSlashMenu } from './rich-text-slash-menu.js';
|
|
119
119
|
import { RichTextToolbar } from './rich-text-toolbar.js';
|
|
120
120
|
import { RichTextToolsBar } from './rich-text-tools-bar.js';
|
|
@@ -511,6 +511,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
511
511
|
const [pageBusy, setPageBusy] = useState(false);
|
|
512
512
|
// Opens the title box: from the slash menu's keys (set up once) too.
|
|
513
513
|
const startPageRef = useRef(() => { });
|
|
514
|
+
const pickSlashImageRef = useRef(() => { });
|
|
514
515
|
// The router's navigate, for a page link's click (NavigateBridge).
|
|
515
516
|
const navigateRef = useRef(null);
|
|
516
517
|
const inRouter = useInRouterContext();
|
|
@@ -598,7 +599,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
598
599
|
// The slash menu: open while a "/" typed at a line's start is followed
|
|
599
600
|
// by something some block answers to, and the field has focus.
|
|
600
601
|
const slash = menus && !readOnly && focused && editorState ? slashQuery(editorState) : null;
|
|
601
|
-
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage) }) : [];
|
|
602
|
+
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage), image: Boolean(upload) }) : [];
|
|
602
603
|
const slashOpen = slash !== null && slashMatches.length > 0;
|
|
603
604
|
const slashMenuKey = slash ? `${slash.from}:${slash.query}` : '';
|
|
604
605
|
const slashIndex = slashActive.key === slashMenuKey ? Math.min(slashActive.index, slashMatches.length - 1) : 0;
|
|
@@ -898,6 +899,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
898
899
|
const item = menu.items[menu.index];
|
|
899
900
|
if (item.id === 'page')
|
|
900
901
|
startPageRef.current(view, menu.span, '');
|
|
902
|
+
else if (item.id === 'image')
|
|
903
|
+
pickSlashImageRef.current(view, menu.span);
|
|
901
904
|
else
|
|
902
905
|
applySlash(view, menu.span, item.id);
|
|
903
906
|
return true;
|
|
@@ -1020,6 +1023,14 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1020
1023
|
// The toolbar's Image button: the file picker, then each file picked
|
|
1021
1024
|
// uploaded in place of the selection, and focus back in the text.
|
|
1022
1025
|
const pickImages = () => imageInputRef.current?.click();
|
|
1026
|
+
// The slash menu's Image (4.123): the "/…" goes, then the file picker;
|
|
1027
|
+
// the images go in at the caret, where the "/" was.
|
|
1028
|
+
// A tick later: Chrome opens no picker for a click made inside the
|
|
1029
|
+
// editor's own keydown (Enter on the item); the key's activation lasts.
|
|
1030
|
+
const pickSlashImage = (view, span) => {
|
|
1031
|
+
clearSlash(view, span);
|
|
1032
|
+
setTimeout(pickImages, 0);
|
|
1033
|
+
};
|
|
1023
1034
|
const imagesPicked = (files) => {
|
|
1024
1035
|
const send = latest.current.upload;
|
|
1025
1036
|
if (!editorView || !send || files.length === 0)
|
|
@@ -1182,6 +1193,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1182
1193
|
};
|
|
1183
1194
|
useEffect(() => {
|
|
1184
1195
|
startPageRef.current = startPage;
|
|
1196
|
+
pickSlashImageRef.current = pickSlashImage;
|
|
1185
1197
|
});
|
|
1186
1198
|
// Selected words in one block (a double-click takes the space after a
|
|
1187
1199
|
// word too: the link gets the words, the spaces stay).
|
|
@@ -1284,7 +1296,11 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1284
1296
|
editorView &&
|
|
1285
1297
|
createPortal(_jsx(TableGrips, { view: editorView, state: editorState, getPos: widget.getPos, frame: widget.frame, box: widget.box, table: widget.table, readOnly: readOnly, focused: focused, onAction: (cell, action) => runTableAt(widget.getPos, cell, action), onColor: (cell, scope, color) => colorTableAt(widget.getPos, cell, scope, color), onWidth: (column, width) => widthTableAt(widget.getPos, column, width), onPreviewWidth: (column, width) => previewTableWidth(widget.getPos, column, width), text: textElement }), widget.grips, `${widget.key}-grips`),
|
|
1286
1298
|
];
|
|
1287
|
-
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) =>
|
|
1299
|
+
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) => item === 'page'
|
|
1300
|
+
? startPage(editorView, slash, '')
|
|
1301
|
+
: item === 'image'
|
|
1302
|
+
? pickSlashImage(editorView, slash)
|
|
1303
|
+
: applySlash(editorView, slash, item) })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1288
1304
|
const next = event.relatedTarget;
|
|
1289
1305
|
if (editorView && !editorView.dom.contains(next) && !inFloating(next))
|
|
1290
1306
|
setFocused(false);
|
|
@@ -45,7 +45,8 @@ export type RichTextEditorProps = {
|
|
|
45
45
|
inline?: boolean;
|
|
46
46
|
/**
|
|
47
47
|
* Images uploaded into the text: pasted, dropped, or picked with an
|
|
48
|
-
* Image button on the fixed toolbar
|
|
48
|
+
* Image button on the fixed toolbar or the slash menu's Image ("/image",
|
|
49
|
+
* 4.123, the way to pick one with only the floating toolbar). Each file goes through this (the
|
|
49
50
|
* app's own storage: the package knows no endpoint) and goes in as
|
|
50
51
|
* ``, from the result's `url`, else its `thumbUrl`. A
|
|
51
52
|
* placeholder shows where it will go while it uploads (it isn't saved);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// Long text written as Markdown, edited as formatted text where it's read
|
|
3
3
|
// (Notion-style), not as Markdown syntax in a textarea. The control for a
|
|
4
4
|
// `long text` field marked Markdown, on the form and in place on the view.
|
|
@@ -50,11 +50,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
50
50
|
// where it is. A caller that never feeds `onChange` back keeps its text.
|
|
51
51
|
//
|
|
52
52
|
// The editor (Milkdown) is loaded on first use, so a page that only reads
|
|
53
|
-
// Markdown never downloads it. Until it arrives
|
|
54
|
-
// the field
|
|
53
|
+
// Markdown never downloads it. Until it arrives the text shows as
|
|
54
|
+
// <Markdown> draws it (4.123), the field's size, so nothing moves when the
|
|
55
|
+
// editor takes its place; an empty one shows skeleton lines.
|
|
55
56
|
import { lazy, Suspense, useState } from 'react';
|
|
56
57
|
import { cn } from 'cn';
|
|
57
58
|
import { Skeleton } from '../ui/skeleton.js';
|
|
59
|
+
import { Markdown } from './markdown.js';
|
|
58
60
|
const MilkdownEditor = lazy(() => import('./milkdown-editor.js'));
|
|
59
61
|
// When the editor opens again: each time `defaultValue` changes to
|
|
60
62
|
// Markdown it didn't report. Adjusted while rendering (React's "storing
|
|
@@ -76,7 +78,9 @@ function useOpenings(defaultValue) {
|
|
|
76
78
|
export function RichTextEditor(props) {
|
|
77
79
|
const { opening, report } = useOpenings(props.defaultValue);
|
|
78
80
|
const { onChange } = props;
|
|
79
|
-
return (_jsx(Suspense, { fallback: _jsxs("div", { "data-slot": "rich-text-editor", "data-state": "loading", className: cn('flex w-full flex-col', !props.inline && 'rounded-lg border border-input', props.className), children: [(props.toolbar ?? true) === true && _jsx("div", { className: "h-9 border-b border-input" }),
|
|
81
|
+
return (_jsx(Suspense, { fallback: _jsxs("div", { "data-slot": "rich-text-editor", "data-state": "loading", className: cn('flex w-full flex-col', !props.inline && 'rounded-lg border border-input', props.className), children: [(props.toolbar ?? true) === true && _jsx("div", { className: "h-9 border-b border-input" }), _jsx("div", { "aria-busy": "true", className: cn('flex flex-col gap-2', props.inline ? 'py-0.5' : 'min-h-24 px-2.5 py-2',
|
|
82
|
+
// The room of the add-row bar the editor draws under a table.
|
|
83
|
+
!props.readOnly && '[&_table]:mb-5'), children: props.defaultValue.trim() ? (_jsx(Markdown, { headingLevel: props.headingLevel, headingFrom: props.headingFrom, foldKey: props.foldable === false ? undefined : props.foldKey, children: props.defaultValue })) : (_jsxs(_Fragment, { children: [_jsx(Skeleton, { className: "h-4 w-3/4" }), _jsx(Skeleton, { className: "h-4 w-1/2" })] })) })] }), children: _jsx(MilkdownEditor, { ...props, onChange: (markdown) => {
|
|
80
84
|
report(markdown);
|
|
81
85
|
onChange(markdown);
|
|
82
86
|
}, foldKey: props.foldable === false ? undefined : props.foldKey }, opening) }));
|
|
@@ -20,17 +20,23 @@ export declare function closeSlash(state: EditorState): Transaction;
|
|
|
20
20
|
export declare function slashOptionId(listId: string, index: number): string;
|
|
21
21
|
/** The plugin: opens on a typed "/", follows the text, closes once the span stops qualifying. */
|
|
22
22
|
export declare function slashPlugin(): Plugin<SlashState>;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* A slash menu item: a block, an image (only with the editor's `upload`,
|
|
25
|
+
* 4.123) or the new page (only with the app's `onCreatePage`).
|
|
26
|
+
*/
|
|
24
27
|
export type SlashItem = Omit<FormatItem, 'id'> & {
|
|
25
|
-
id: FormatId | 'page';
|
|
28
|
+
id: FormatId | 'image' | 'page';
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* The blocks matching what's typed after the "/": in the name, or the
|
|
29
|
-
* start of a keyword. With `page`, the new page
|
|
32
|
+
* start of a keyword. With `image`, an image too; with `page`, the new page.
|
|
30
33
|
*/
|
|
31
34
|
export declare function slashItems(query: string, options?: {
|
|
32
35
|
page?: boolean;
|
|
36
|
+
image?: boolean;
|
|
33
37
|
}): SlashItem[];
|
|
38
|
+
/** Picks the image item: the "/…" goes and the menu closes, the caret where it was, for the picked images. */
|
|
39
|
+
export declare function clearSlash(view: EditorView, span: SlashQuery): void;
|
|
34
40
|
/**
|
|
35
41
|
* Picks an item: the "/…" goes and the paragraph becomes that block, in one
|
|
36
42
|
* transaction (one undo step, which brings the "/…" back).
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// `/usr/bin`) never does, and neither does a "/" mid-line or inside a
|
|
9
9
|
// list, a quote or a code block.
|
|
10
10
|
import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
|
|
11
|
-
import { FileTextIcon } from 'lucide-react';
|
|
11
|
+
import { FileTextIcon, ImageIcon } from 'lucide-react';
|
|
12
12
|
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
|
|
13
13
|
import { toggleFormat } from './rich-text-formats.js';
|
|
14
14
|
const slashKey = new PluginKey('rich-text-slash');
|
|
@@ -109,26 +109,39 @@ const KEYWORDS = {
|
|
|
109
109
|
// once something's typed ("/warn"), so the list "/" opens with stays short.
|
|
110
110
|
const BLOCKS = FORMAT_GROUPS.flat().filter((item) => KEYWORDS[item.id]);
|
|
111
111
|
BLOCKS.splice(BLOCKS.findIndex((item) => item.id === 'heading3') + 1, 0, ...TOGGLE_HEADING_VARIANTS);
|
|
112
|
+
// An image (4.123): the file picker, the image going where the "/" was.
|
|
113
|
+
// The Image button's job for an editor with no fixed toolbar
|
|
114
|
+
// (`toolbar="floating"`), and a quicker way with one.
|
|
115
|
+
const IMAGE_ITEM = { id: 'image', label: 'Image', icon: ImageIcon };
|
|
116
|
+
const IMAGE_KEYWORDS = ['image', 'picture', 'photo', 'img', 'upload'];
|
|
112
117
|
// A page of its own, linked from here (src/lib/page-link.ts): last, since
|
|
113
118
|
// it's the only item that leaves the editor (a title box, then the app).
|
|
114
119
|
const PAGE_ITEM = { id: 'page', label: 'Page', icon: FileTextIcon };
|
|
115
120
|
const PAGE_KEYWORDS = ['page', 'subpage', 'child', 'link', 'new'];
|
|
116
121
|
/**
|
|
117
122
|
* The blocks matching what's typed after the "/": in the name, or the
|
|
118
|
-
* start of a keyword. With `page`, the new page
|
|
123
|
+
* start of a keyword. With `image`, an image too; with `page`, the new page.
|
|
119
124
|
*/
|
|
120
125
|
export function slashItems(query, options = {}) {
|
|
121
126
|
const typed = query.trim().toLowerCase();
|
|
122
127
|
const page = options.page && (!typed || 'page'.includes(typed) || PAGE_KEYWORDS.some((word) => word.startsWith(typed))) ? [PAGE_ITEM] : [];
|
|
128
|
+
const image = options.image && (!typed || IMAGE_KEYWORDS.some((word) => word.startsWith(typed))) ? [IMAGE_ITEM] : [];
|
|
123
129
|
if (!typed)
|
|
124
|
-
return [...BLOCKS, ...page];
|
|
130
|
+
return [...BLOCKS, ...image, ...page];
|
|
125
131
|
const blocks = [...BLOCKS];
|
|
126
132
|
blocks.splice(BLOCKS.findIndex((item) => item.id === 'callout') + 1, 0, ...CALLOUT_VARIANTS);
|
|
127
133
|
blocks.push(...HIGHLIGHT_VARIANTS);
|
|
128
|
-
const matches =
|
|
134
|
+
const matches = [
|
|
135
|
+
...blocks.filter((item) => item.label.toLowerCase().includes(typed) || KEYWORDS[item.id].some((word) => word.startsWith(typed))),
|
|
136
|
+
...image,
|
|
137
|
+
];
|
|
129
138
|
// "/page" puts the page first: it's what was asked for by name.
|
|
130
139
|
return typed.length >= 2 && 'page'.startsWith(typed) ? [...page, ...matches] : [...matches, ...page];
|
|
131
140
|
}
|
|
141
|
+
/** Picks the image item: the "/…" goes and the menu closes, the caret where it was, for the picked images. */
|
|
142
|
+
export function clearSlash(view, span) {
|
|
143
|
+
view.dispatch(view.state.tr.delete(span.from, span.to).setMeta(slashKey, 'close'));
|
|
144
|
+
}
|
|
132
145
|
/**
|
|
133
146
|
* Picks an item: the "/…" goes and the paragraph becomes that block, in one
|
|
134
147
|
* transaction (one undo step, which brings the "/…" back).
|
|
@@ -32,8 +32,10 @@ function FieldLegend({ className, variant = "legend", ...props }) {
|
|
|
32
32
|
// DateField marks its own box (`data-kind="date"`, 4.88).
|
|
33
33
|
const DATE_CONTROL = "input[type=date], [data-kind=date]";
|
|
34
34
|
const NUMBER_CONTROL = "input[type=number], input[inputmode=numeric], input[inputmode=decimal]";
|
|
35
|
-
// A row of choice buttons (ChoiceButtons, 4.98): two to a row (9C).
|
|
36
|
-
|
|
35
|
+
// A row of choice buttons (ChoiceButtons, 4.98): two to a row (9C). A
|
|
36
|
+
// ToggleGroup that is the field's own control (4.123) is one too; one
|
|
37
|
+
// nested deeper (a RecurrenceField's weekdays) isn't.
|
|
38
|
+
const CHOICE_CONTROL = "[data-slot=choice-buttons], :scope > [data-slot=toggle-group]";
|
|
37
39
|
function kindOf(field) {
|
|
38
40
|
const said = field.dataset.kind;
|
|
39
41
|
if (said === "date" || said === "number" || said === "choice")
|
|
@@ -33,7 +33,8 @@ export function viewToUrlChanges(filterNames, multiFilterNames, view, asDefault
|
|
|
33
33
|
[NO_VIEW_PARAM]: null,
|
|
34
34
|
...Object.fromEntries(filterNames.map((name) => [name, own[name] ?? ''])),
|
|
35
35
|
...Object.fromEntries(multiFilterNames.map((name) => [name, asDefault ? [] : (view.multiFilters?.[name] ?? [])])),
|
|
36
|
-
|
|
36
|
+
// The default view's sort is its plain address's (4.123): not written.
|
|
37
|
+
sort: view.sort && !asDefault ? serializeSort(view.sort) : null,
|
|
37
38
|
...(view.group === undefined ? {} : { group: view.group || null }),
|
|
38
39
|
page: null,
|
|
39
40
|
};
|
|
@@ -53,15 +53,25 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
53
53
|
browserStore.set(groupStorageKey, next);
|
|
54
54
|
};
|
|
55
55
|
const page = Math.max(1, Math.floor(Number(params.get('page'))) || 1);
|
|
56
|
-
const [sortField, sortDir] = (params.get('sort') ?? '').split(':');
|
|
57
|
-
const sorting = sortField ? [{ id: sortField, desc: sortDir === 'desc' }] : [];
|
|
58
56
|
const fallback = defaultView === undefined ? undefined : views[defaultView];
|
|
59
57
|
const state = readFilterState(params, filterNames, multiFilterNames, fallback);
|
|
60
58
|
const { filters, multiFilters } = state;
|
|
59
|
+
// The URL's sort, else the default view's at the list's plain address
|
|
60
|
+
// (4.123): pressing the default view writes no `?sort=`, as it writes no
|
|
61
|
+
// filters, and its sort still holds.
|
|
62
|
+
const urlSort = params.get('sort');
|
|
63
|
+
const [sortField, sortDir] = (urlSort ?? '').split(':');
|
|
64
|
+
const sorting = sortField && urlSort !== 'none'
|
|
65
|
+
? [{ id: sortField, desc: sortDir === 'desc' }]
|
|
66
|
+
: urlSort === null && state.atDefault && fallback?.sort
|
|
67
|
+
? [...fallback.sort]
|
|
68
|
+
: [];
|
|
69
|
+
// Leaving the plain address (a filter changed by hand) keeps the sort it showed.
|
|
70
|
+
const keptSort = urlSort === null && state.atDefault && fallback?.sort ? { sort: serializeSort(fallback.sort) } : {};
|
|
61
71
|
const activeView = activeViewOf(views, filters, multiFilters);
|
|
62
72
|
const ruleNames = ruleFilterNames(views);
|
|
63
73
|
// The reader changing filters by hand: see filterChanges.
|
|
64
|
-
const changeFilters = (changes) => update(filterChanges(state, changes, ruleNames, fallback !== undefined));
|
|
74
|
+
const changeFilters = (changes) => update({ ...keptSort, ...filterChanges(state, changes, ruleNames, fallback !== undefined) });
|
|
65
75
|
function update(changes) {
|
|
66
76
|
setParams((previous) => applyUrlChanges(previous, changes), { replace: true });
|
|
67
77
|
}
|
|
@@ -84,7 +94,8 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
84
94
|
update({ group: next || null });
|
|
85
95
|
},
|
|
86
96
|
setPage: (next) => update({ page: next > 1 ? String(next) : null }),
|
|
87
|
-
|
|
97
|
+
// Unsorting where the default view's sort would come back writes `sort=none`.
|
|
98
|
+
setSorting: (next) => update({ sort: serializeSort(next) ?? (fallback?.sort && state.atDefault ? 'none' : null), page: null }),
|
|
88
99
|
setFilter: (name, value) => changeFilters({ [name]: value }),
|
|
89
100
|
// Several filters in one call — for any user action that changes more
|
|
90
101
|
// than one (both ends of a date range, "clear filters"). Two setters in
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { EmptyText, type EmptyTextProps } from './components/app/empty-value.js'
|
|
|
29
29
|
export { isEmptyValue } from './lib/empty-value.js';
|
|
30
30
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
31
31
|
export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
|
|
32
|
-
export { type EntityViewFact, type EntityViewFactAction, type EntityViewFactBadge, type EntityViewFactListItem, type EntityViewFactRatingLook, type EntityViewFactValue, } from './components/app/entity-view-facts.js';
|
|
32
|
+
export { type EntityViewFact, type EntityViewFactAction, type EntityViewFactBadge, type EntityViewFactBadgeTone, type EntityViewFactListItem, type EntityViewFactRatingLook, type EntityViewFactValue, } from './components/app/entity-view-facts.js';
|
|
33
33
|
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
34
34
|
export { usePrinting } from './components/app/print-context.js';
|
|
35
35
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
package/openapi/foundation.yaml
CHANGED
|
@@ -349,7 +349,7 @@ components:
|
|
|
349
349
|
minLength: 1
|
|
350
350
|
maxLength: 200
|
|
351
351
|
pattern: "^FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(;(INTERVAL|BYMONTH|BYMONTHDAY|BYDAY|UNTIL|COUNT|WKST)=[A-Z0-9,+-]+)*$"
|
|
352
|
-
# The pattern before WKST (4.95 to 4.
|
|
352
|
+
# The pattern before WKST (4.95 to 4.118). check-contract still
|
|
353
353
|
# accepts an app's copy with it: such an app can't store WKST,
|
|
354
354
|
# and needn't copy this one until it wants to.
|
|
355
355
|
x-earlier-patterns:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.123.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|