@sincpro/web-ui 2.11.0 → 2.13.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/README.md +77 -20
- package/dist/components/activity/Messages.d.ts +3 -23
- package/dist/components/activity/Messages.js +3 -17
- package/dist/components/activity/index.d.ts +2 -1
- package/dist/components/activity/index.js +2 -1
- package/dist/components/activity/messageKind.d.ts +23 -0
- package/dist/components/activity/messageKind.js +17 -0
- package/dist/components/assist/assist.d.ts +1 -1
- package/dist/components/assist/assist.js +1 -1
- package/dist/components/frame/model.js +1 -1
- package/dist/components/guide/index.d.ts +2 -1
- package/dist/components/guide/index.js +2 -1
- package/dist/components/guide/selector.d.ts +25 -0
- package/dist/components/guide/selector.js +14 -0
- package/dist/components/guide/target.d.ts +3 -25
- package/dist/components/guide/target.js +2 -14
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/listing/AxisLevels.d.ts +2 -5
- package/dist/components/listing/AxisLevels.js +5 -22
- package/dist/components/listing/BoardColumns.js +10 -6
- package/dist/components/listing/ColumnsMenu.d.ts +3 -7
- package/dist/components/listing/ColumnsMenu.js +4 -8
- package/dist/components/listing/Listing.js +3 -1
- package/dist/components/listing/ListingBar.d.ts +16 -94
- package/dist/components/listing/ListingBar.js +24 -2
- package/dist/components/listing/RecordCard.d.ts +41 -3
- package/dist/components/listing/RecordCard.js +63 -22
- package/dist/components/listing/Row.js +5 -2
- package/dist/components/listing/collapsed.d.ts +2 -0
- package/dist/components/listing/collapsed.js +8 -0
- package/dist/components/listing/columnSpecs.d.ts +34 -0
- package/dist/components/listing/columnSpecs.js +54 -0
- package/dist/components/listing/columns.d.ts +3 -21
- package/dist/components/listing/columns.js +2 -39
- package/dist/components/listing/index.d.ts +11 -7
- package/dist/components/listing/index.js +15 -8
- package/dist/components/listing/levels.d.ts +9 -0
- package/dist/components/listing/levels.js +27 -0
- package/dist/components/listing/pageSizes.d.ts +9 -0
- package/dist/components/listing/pageSizes.js +11 -0
- package/dist/components/listing/pages.d.ts +2 -9
- package/dist/components/listing/pages.js +5 -9
- package/dist/components/listing/set.d.ts +1 -1
- package/dist/components/listing/tree.d.ts +2 -1
- package/dist/components/listing/tree.js +4 -5
- package/dist/components/preview/FilePreview.d.ts +3 -3
- package/dist/components/preview/FilePreview.js +3 -15
- package/dist/components/preview/index.d.ts +2 -1
- package/dist/components/preview/index.js +2 -1
- package/dist/components/preview/previewKind.d.ts +3 -0
- package/dist/components/preview/previewKind.js +17 -0
- package/dist/components/receipt/Receipt.d.ts +51 -0
- package/dist/components/receipt/Receipt.js +23 -0
- package/dist/components/receipt/index.d.ts +1 -0
- package/dist/components/receipt/index.js +3 -0
- package/dist/components/search/CriteriaChips.js +5 -3
- package/dist/components/search/FilterBuilder.d.ts +5 -139
- package/dist/components/search/FilterBuilder.js +5 -579
- package/dist/components/search/JsonEditor.d.ts +2 -8
- package/dist/components/search/JsonEditor.js +5 -15
- package/dist/components/search/RuleValue.d.ts +2 -2
- package/dist/components/search/RuleValue.js +5 -4
- package/dist/components/search/datePeriods.js +1 -1
- package/dist/components/search/filterTree.d.ts +183 -0
- package/dist/components/search/filterTree.js +570 -0
- package/dist/components/search/formatJson.d.ts +8 -0
- package/dist/components/search/formatJson.js +17 -0
- package/dist/components/search/index.d.ts +5 -3
- package/dist/components/search/index.js +7 -3
- package/dist/components/search/query.js +1 -1
- package/dist/components/shell/KioskFrame.d.ts +35 -0
- package/dist/components/shell/KioskFrame.js +39 -0
- package/dist/components/shell/SearchEntry.js +1 -1
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +1 -0
- package/dist/foundations/calendar.js +1 -1
- package/dist/foundations/catalog.d.ts +7 -8
- package/dist/foundations/catalog.js +10 -35
- package/dist/foundations/chart.js +1 -1
- package/dist/foundations/clock.d.ts +3 -0
- package/dist/foundations/clock.js +41 -0
- package/dist/foundations/controlName.d.ts +12 -0
- package/dist/foundations/controlName.js +14 -0
- package/dist/foundations/copy.d.ts +3 -1130
- package/dist/foundations/copy.es.d.ts +1 -1
- package/dist/foundations/copy.es.js +26 -0
- package/dist/foundations/copy.js +13 -747
- package/dist/foundations/copyStore.d.ts +21 -0
- package/dist/foundations/copyStore.js +47 -0
- package/dist/foundations/density.d.ts +4 -8
- package/dist/foundations/density.js +2 -9
- package/dist/foundations/form.d.ts +2 -12
- package/dist/foundations/form.js +4 -14
- package/dist/foundations/idle.d.ts +1 -0
- package/dist/foundations/idle.js +34 -0
- package/dist/foundations/index.d.ts +21 -11
- package/dist/foundations/index.js +28 -11
- package/dist/foundations/keys.d.ts +8 -0
- package/dist/foundations/keys.js +6 -0
- package/dist/foundations/pickBy.d.ts +16 -0
- package/dist/foundations/pickBy.js +17 -0
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/pointer.d.ts +25 -0
- package/dist/foundations/pointer.js +28 -0
- package/dist/foundations/shortcut.d.ts +3 -9
- package/dist/foundations/shortcut.js +2 -7
- package/dist/foundations/sticky.d.ts +2 -6
- package/dist/foundations/sticky.js +5 -8
- package/dist/foundations/stickyStyle.d.ts +12 -0
- package/dist/foundations/stickyStyle.js +13 -0
- package/dist/foundations/surface.d.ts +2 -2
- package/dist/foundations/surface.js +4 -2
- package/dist/foundations/theme.d.ts +3 -13
- package/dist/foundations/theme.js +2 -15
- package/dist/foundations/themeChoice.d.ts +19 -0
- package/dist/foundations/themeChoice.js +22 -0
- package/dist/foundations/types.d.ts +3 -0
- package/dist/foundations/uiCopy.d.ts +1173 -0
- package/dist/foundations/uiCopy.js +775 -0
- package/dist/foundations/xlsx.d.ts +4 -10
- package/dist/foundations/xlsx.js +0 -0
- package/dist/foundations/xlsxDownload.d.ts +8 -0
- package/dist/foundations/xlsxDownload.js +28 -0
- package/dist/primitives/button/Button.d.ts +3 -15
- package/dist/primitives/button/Button.js +2 -65
- package/dist/primitives/button/classes.d.ts +21 -0
- package/dist/primitives/button/classes.js +65 -0
- package/dist/primitives/button/index.d.ts +2 -1
- package/dist/primitives/button/index.js +3 -1
- package/dist/primitives/choice/RadioGroup.d.ts +8 -1
- package/dist/primitives/choice/RadioGroup.js +9 -1
- package/dist/primitives/choice/options.d.ts +3 -0
- package/dist/primitives/field/Field.d.ts +2 -6
- package/dist/primitives/field/Field.js +4 -10
- package/dist/primitives/field/Keypad.d.ts +43 -0
- package/dist/primitives/field/Keypad.js +62 -0
- package/dist/primitives/field/Stepper.d.ts +28 -0
- package/dist/primitives/field/Stepper.js +52 -0
- package/dist/primitives/field/classes.d.ts +6 -0
- package/dist/primitives/field/classes.js +13 -0
- package/dist/primitives/field/clipboard.js +1 -1
- package/dist/primitives/field/index.d.ts +5 -1
- package/dist/primitives/field/index.js +9 -1
- package/dist/primitives/field/keypadKeys.d.ts +24 -0
- package/dist/primitives/field/keypadKeys.js +80 -0
- package/dist/primitives/hint/Hint.js +1 -1
- package/dist/primitives/menu/Menu.d.ts +2 -19
- package/dist/primitives/menu/Menu.js +4 -30
- package/dist/primitives/menu/classes.d.ts +18 -0
- package/dist/primitives/menu/classes.js +33 -0
- package/dist/primitives/menu/index.d.ts +2 -1
- package/dist/primitives/menu/index.js +3 -1
- package/dist/primitives/notice/Flag.js +1 -1
- package/dist/primitives/notice/Outcome.d.ts +28 -0
- package/dist/primitives/notice/Outcome.js +28 -0
- package/dist/primitives/notice/index.d.ts +1 -0
- package/dist/primitives/notice/index.js +2 -0
- package/dist/primitives/table/CellCopy.js +1 -1
- package/dist/primitives/table/EditableTable.d.ts +3 -37
- package/dist/primitives/table/EditableTable.js +2 -47
- package/dist/primitives/table/ReportTable.js +1 -1
- package/dist/primitives/table/RowActions.js +1 -1
- package/dist/primitives/table/Table.d.ts +2 -4
- package/dist/primitives/table/Table.js +13 -16
- package/dist/primitives/table/cellTone.d.ts +5 -0
- package/dist/primitives/table/cellTone.js +13 -0
- package/dist/primitives/table/editRules.d.ts +43 -0
- package/dist/primitives/table/editRules.js +53 -0
- package/dist/primitives/table/index.d.ts +4 -2
- package/dist/primitives/table/index.js +4 -2
- package/dist/primitives/tag/Count.d.ts +2 -3
- package/dist/primitives/tag/Count.js +4 -5
- package/dist/primitives/tag/Tags.d.ts +22 -1
- package/dist/primitives/tag/Tags.js +57 -14
- package/dist/primitives/tag/countText.d.ts +3 -0
- package/dist/primitives/tag/countText.js +7 -0
- package/dist/primitives/tag/index.d.ts +3 -2
- package/dist/primitives/tag/index.js +2 -1
- package/dist/primitives/value/DateValue.d.ts +2 -5
- package/dist/primitives/value/DateValue.js +6 -44
- package/dist/primitives/value/Elapsed.d.ts +16 -0
- package/dist/primitives/value/Elapsed.js +37 -0
- package/dist/primitives/value/Meter.d.ts +3 -8
- package/dist/primitives/value/Meter.js +2 -9
- package/dist/primitives/value/RichText.d.ts +2 -4
- package/dist/primitives/value/RichText.js +5 -20
- package/dist/primitives/value/Value.d.ts +10 -7
- package/dist/primitives/value/Value.js +7 -24
- package/dist/primitives/value/elapsedTime.d.ts +26 -0
- package/dist/primitives/value/elapsedTime.js +32 -0
- package/dist/primitives/value/format.d.ts +16 -0
- package/dist/primitives/value/format.js +81 -0
- package/dist/primitives/value/index.d.ts +9 -4
- package/dist/primitives/value/index.js +13 -4
- package/dist/primitives/value/meterLevel.d.ts +10 -0
- package/dist/primitives/value/meterLevel.js +12 -0
- package/dist/primitives/value/richTextPlain.d.ts +4 -0
- package/dist/primitives/value/richTextPlain.js +23 -0
- package/dist/tokens.css +87 -1
- package/dist/views/list/List.d.ts +11 -0
- package/dist/views/list/List.js +14 -3
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +26 -6
- package/dist/views/list/types.d.ts +7 -0
- package/dist/views/record/Record.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* Without `"use client"`, apart from `Table.tsx`: a cell a server component draws takes the
|
|
2
|
+
same tone. */
|
|
3
|
+
/** The background of a cell, by tone. It replaces the row wash on that cell:
|
|
4
|
+
* a hovered row and a painted cell are two signals, and stacking them reads
|
|
5
|
+
* as a third color. */
|
|
6
|
+
export const CELL_TONE = {
|
|
7
|
+
neutral: "bg-ink/6",
|
|
8
|
+
info: "bg-info/12",
|
|
9
|
+
good: "bg-good/12",
|
|
10
|
+
warn: "bg-warn/15",
|
|
11
|
+
bad: "bg-bad/12",
|
|
12
|
+
accent: "bg-accent/20",
|
|
13
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE RULES OF AN EDITABLE TABLE that need no browser: where a column goes in a stacked
|
|
3
|
+
* card, which lines a section heads, where `Tab` goes from the edge of a row. Apart from
|
|
4
|
+
* `EditableTable.tsx` and without `"use client"`, so a server component — and a test —
|
|
5
|
+
* reads them as plain functions.
|
|
6
|
+
*/
|
|
7
|
+
/** Where a column goes when the row is drawn as a stacked card (a narrow box).
|
|
8
|
+
* `trail` sits at the top right, beside the title — a state, the row's buttons. */
|
|
9
|
+
export type StackPlace = "title" | "detail" | "amount" | "trail" | "hidden";
|
|
10
|
+
/** The lines each section heads: the rows after it up to the next section. Notes do not
|
|
11
|
+
* cut a section, and are not lines. */
|
|
12
|
+
export declare function sectionLines<T>(rows: readonly T[], getRowId: (row: T) => string, kind: (row: T) => "section" | "note" | null): Map<string, T[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Where each column goes in the stacked card, defaults resolved: a declared `stack`
|
|
15
|
+
* wins; otherwise the first undeclared column is the title (unless one was declared),
|
|
16
|
+
* the last undeclared numeric one is the amount (unless one was declared), and the rest
|
|
17
|
+
* are detail.
|
|
18
|
+
*/
|
|
19
|
+
export declare function stackPlaces(columns: readonly {
|
|
20
|
+
stack?: StackPlace;
|
|
21
|
+
numeric?: boolean;
|
|
22
|
+
}[]): StackPlace[];
|
|
23
|
+
/** Where `Tab` goes from the edge of an edited row: the next or previous row opened, a new
|
|
24
|
+
* row added, or out of the table the browser's way. */
|
|
25
|
+
export type TabTarget = {
|
|
26
|
+
kind: "row";
|
|
27
|
+
id: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "add";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "leave";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Where `Tab` past the last control (`next`) or `Shift+Tab` before the first (`prev`) of
|
|
35
|
+
* the edited row `from` goes, over the rows in the order they are drawn.
|
|
36
|
+
*
|
|
37
|
+
* Past the last row it adds one when the table can — unless `from` is itself a row just
|
|
38
|
+
* added and still blank: one more `Tab` there means «I am done», not «another blank line».
|
|
39
|
+
*/
|
|
40
|
+
export declare function tabTarget(order: readonly string[], from: string, direction: "next" | "prev", { canAdd, blank }: {
|
|
41
|
+
canAdd: boolean;
|
|
42
|
+
blank: boolean;
|
|
43
|
+
}): TabTarget;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE RULES OF AN EDITABLE TABLE that need no browser: where a column goes in a stacked
|
|
3
|
+
* card, which lines a section heads, where `Tab` goes from the edge of a row. Apart from
|
|
4
|
+
* `EditableTable.tsx` and without `"use client"`, so a server component — and a test —
|
|
5
|
+
* reads them as plain functions.
|
|
6
|
+
*/
|
|
7
|
+
/** The lines each section heads: the rows after it up to the next section. Notes do not
|
|
8
|
+
* cut a section, and are not lines. */
|
|
9
|
+
export function sectionLines(rows, getRowId, kind) {
|
|
10
|
+
const out = new Map();
|
|
11
|
+
let current = null;
|
|
12
|
+
for (const row of rows) {
|
|
13
|
+
const k = kind(row);
|
|
14
|
+
if (k === "section") {
|
|
15
|
+
current = [];
|
|
16
|
+
out.set(getRowId(row), current);
|
|
17
|
+
}
|
|
18
|
+
else if (k === null)
|
|
19
|
+
current?.push(row);
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where each column goes in the stacked card, defaults resolved: a declared `stack`
|
|
25
|
+
* wins; otherwise the first undeclared column is the title (unless one was declared),
|
|
26
|
+
* the last undeclared numeric one is the amount (unless one was declared), and the rest
|
|
27
|
+
* are detail.
|
|
28
|
+
*/
|
|
29
|
+
export function stackPlaces(columns) {
|
|
30
|
+
const titleAt = columns.some((c) => c.stack === "title")
|
|
31
|
+
? -1
|
|
32
|
+
: columns.findIndex((c) => c.stack === undefined);
|
|
33
|
+
const amountAt = columns.some((c) => c.stack === "amount")
|
|
34
|
+
? -1
|
|
35
|
+
: columns.findLastIndex((c, i) => c.stack === undefined && c.numeric === true && i !== titleAt);
|
|
36
|
+
return columns.map((c, i) => c.stack ?? (i === titleAt ? "title" : i === amountAt ? "amount" : "detail"));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Where `Tab` past the last control (`next`) or `Shift+Tab` before the first (`prev`) of
|
|
40
|
+
* the edited row `from` goes, over the rows in the order they are drawn.
|
|
41
|
+
*
|
|
42
|
+
* Past the last row it adds one when the table can — unless `from` is itself a row just
|
|
43
|
+
* added and still blank: one more `Tab` there means «I am done», not «another blank line».
|
|
44
|
+
*/
|
|
45
|
+
export function tabTarget(order, from, direction, { canAdd, blank }) {
|
|
46
|
+
const at = order.indexOf(from);
|
|
47
|
+
if (at === -1)
|
|
48
|
+
return { kind: "leave" };
|
|
49
|
+
const to = order[direction === "next" ? at + 1 : at - 1];
|
|
50
|
+
if (to !== undefined)
|
|
51
|
+
return { kind: "row", id: to };
|
|
52
|
+
return direction === "next" && canAdd && !blank ? { kind: "add" } : { kind: "leave" };
|
|
53
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export { CELL_TONE } from "./cellTone.js";
|
|
1
2
|
export { type Aggregate, type DataColumn, DataTable, type DataTableCreate, type GroupColumn, type YesNoColumn, } from "./DataTable.js";
|
|
2
|
-
export { EditableTable, type EditAdd, type EditBands, type EditCellState, type EditColumn, type EditFlag, type EditLayout, type EditRowState,
|
|
3
|
+
export { EditableTable, type EditAdd, type EditBands, type EditCellState, type EditColumn, type EditFlag, type EditLayout, type EditRowState, } from "./EditableTable.js";
|
|
4
|
+
export { sectionLines, type StackPlace, stackPlaces, type TabTarget, tabTarget, } from "./editRules.js";
|
|
3
5
|
export { PileFootLine } from "./PileFootLine.js";
|
|
4
6
|
export { PivotTable, type PivotTableProps, } from "./PivotTable.js";
|
|
5
7
|
export { type ReportColumn, type ReportRow, type ReportRowKind, ReportTable, } from "./ReportTable.js";
|
|
6
8
|
export { type RowAction, RowActions } from "./RowActions.js";
|
|
7
9
|
export { type SheetColumn, SheetTable } from "./SheetTable.js";
|
|
8
10
|
export { compareBy, flipSort, moveSort, pressSort, type SortDirection, sortPosition, type SortState, } from "./sorting.js";
|
|
9
|
-
export {
|
|
11
|
+
export { Table, Td, Th, THead, Tr } from "./Table.js";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* The presentation (`Table`) is ours and is used on its own; `DataTable` is the
|
|
2
2
|
wiring to TanStack for grouping and sorting. See the note in `DataTable.tsx`. */
|
|
3
|
+
export { CELL_TONE } from "./cellTone.js";
|
|
3
4
|
export { DataTable, } from "./DataTable.js";
|
|
4
|
-
export { EditableTable,
|
|
5
|
+
export { EditableTable, } from "./EditableTable.js";
|
|
6
|
+
export { sectionLines, stackPlaces, tabTarget, } from "./editRules.js";
|
|
5
7
|
export { PileFootLine } from "./PileFootLine.js";
|
|
6
8
|
export { PivotTable, } from "./PivotTable.js";
|
|
7
9
|
export { ReportTable, } from "./ReportTable.js";
|
|
8
10
|
export { RowActions } from "./RowActions.js";
|
|
9
11
|
export { SheetTable } from "./SheetTable.js";
|
|
10
12
|
export { compareBy, flipSort, moveSort, pressSort, sortPosition, } from "./sorting.js";
|
|
11
|
-
export {
|
|
13
|
+
export { Table, Td, Th, THead, Tr } from "./Table.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Surface, Tone } from "../../foundations/types.js";
|
|
2
|
+
import { countText } from "./countText.js";
|
|
2
3
|
export type CountProps = {
|
|
3
4
|
/** How many. Without it the count is a dot: something is there, not counted. */
|
|
4
5
|
value?: number;
|
|
@@ -17,7 +18,5 @@ export type CountProps = {
|
|
|
17
18
|
* seen: hidden from assistive technology so it is not read twice. */
|
|
18
19
|
"aria-hidden"?: boolean;
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
* hosts that also need it in words — a button's `aria-label`, a `title`. */
|
|
22
|
-
export declare function countText(value: number, format: (n: number) => string, max?: number): string;
|
|
21
|
+
export { countText };
|
|
23
22
|
export declare function Count({ value, tone, solid, max, showZero, current, surface, "aria-hidden": hidden, }: CountProps): import("react").JSX.Element | null;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
4
|
import { useSurface } from "../../foundations/surface.js";
|
|
5
|
+
import { countText } from "./countText.js";
|
|
5
6
|
import { useMemo } from "react";
|
|
6
7
|
/* Static and in a table: Tailwind cannot compose `bg-${tone}/12`. The gold is never text on
|
|
7
8
|
the canvas (2.43:1), so there its count is ink on a gold wash — the same rule as `Tag`. */
|
|
@@ -32,11 +33,9 @@ const DOT = {
|
|
|
32
33
|
bad: { canvas: "bg-bad", chrome: "bg-chrome-bad" },
|
|
33
34
|
accent: { canvas: "bg-accent", chrome: "bg-chrome-accent" },
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export
|
|
38
|
-
return max !== undefined && value > max ? `${format(max)}+` : format(value);
|
|
39
|
-
}
|
|
36
|
+
/* `countText` is a plain function (`countText.ts`), without the directive, so a server
|
|
37
|
+
component reads it; re-exported so every path that read it here keeps reading it. */
|
|
38
|
+
export { countText };
|
|
40
39
|
function skinOf(tone, surface, { solid, current, zero }) {
|
|
41
40
|
if (solid)
|
|
42
41
|
return SOLID[tone][surface];
|
|
@@ -19,6 +19,9 @@ export type TagItem = {
|
|
|
19
19
|
* the chip; this replaces the verb when the chip needs a more exact one
|
|
20
20
|
* («quitar el filtro»). */
|
|
21
21
|
removeLabel?: string;
|
|
22
|
+
/** How many records answer to it — «Bebidas 12», «Pagada 187». Drawn after the label in
|
|
23
|
+
* figures that line up, so a strip of filters reads as a small histogram. */
|
|
24
|
+
count?: number | string;
|
|
22
25
|
/** It is chosen right now. */
|
|
23
26
|
selected?: boolean;
|
|
24
27
|
/** It is MARKED by the keyboard of someone else — the search input that
|
|
@@ -31,7 +34,18 @@ export type TagItem = {
|
|
|
31
34
|
tone?: Tone;
|
|
32
35
|
title?: string;
|
|
33
36
|
};
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* How big a chip is drawn — a PLACE, like a button's size:
|
|
39
|
+
*
|
|
40
|
+
* sm a line of text: the chips of a field, of a search bar, of a row
|
|
41
|
+
* md a control of the bar: the quick filters over a list, a shop's facets
|
|
42
|
+
* lg a till's or a kiosk's categories — aimed at from arm's length
|
|
43
|
+
*
|
|
44
|
+
* `md` and `lg` are as tall as the controls (`--size-control-sm` / `-lg`), so under a finger
|
|
45
|
+
* they grow with the rest; `sm` grows to a size a thumb can aim at.
|
|
46
|
+
*/
|
|
47
|
+
export type TagsSize = "sm" | "md" | "lg";
|
|
48
|
+
export declare function Tags({ items, surface, label, labelledBy, stack, multiple, size, scroll, }: {
|
|
35
49
|
items: readonly TagItem[];
|
|
36
50
|
/** By default it inherits the surface that wraps it. */
|
|
37
51
|
surface?: Surface;
|
|
@@ -56,4 +70,11 @@ export declare function Tags({ items, surface, label, labelledBy, stack, multipl
|
|
|
56
70
|
* default the choice is ONE — a join, a grain, a period — and the strip is
|
|
57
71
|
* announced as single-select. */
|
|
58
72
|
multiple?: boolean;
|
|
73
|
+
size?: TagsSize;
|
|
74
|
+
/**
|
|
75
|
+
* One line that scrolls sideways, instead of wrapping. The categories of a till are read
|
|
76
|
+
* in a row and found by position — wrapped into three lines they move every time one is
|
|
77
|
+
* added. The edges fade while there is more to see.
|
|
78
|
+
*/
|
|
79
|
+
scroll?: boolean;
|
|
59
80
|
}): import("react").JSX.Element | null;
|
|
@@ -7,23 +7,38 @@ import { chosenTone, tagTone } from "./Tag.js";
|
|
|
7
7
|
import { Avatar } from "../value/Person.js";
|
|
8
8
|
import { X } from "lucide-react";
|
|
9
9
|
import { Button as AriaButton, Tag as AriaTag, TagGroup, TagList, } from "react-aria-components";
|
|
10
|
-
export function Tags({ items, surface, label, labelledBy, stack = false, multiple = false, }) {
|
|
10
|
+
export function Tags({ items, surface, label, labelledBy, stack = false, multiple = false, size = "sm", scroll = false, }) {
|
|
11
11
|
const sup = useSurface(surface);
|
|
12
12
|
if (items.length === 0)
|
|
13
13
|
return null;
|
|
14
14
|
const interactive = items.some((i) => i.onSelect !== undefined || i.onRemove !== undefined);
|
|
15
|
+
const layout = stack ? STACK : scroll ? SCROLL : STRIP[size];
|
|
15
16
|
if (!interactive)
|
|
16
|
-
return _jsx(StillStrip, { items: items, surface: sup, label: label, stack: stack });
|
|
17
|
-
return (_jsx(AriaLocale, { children: _jsx(ChipGroup, { items: items, surface: sup, label: label, labelledBy: labelledBy, stack: stack, multiple: multiple }) }));
|
|
17
|
+
return (_jsx(StillStrip, { items: items, surface: sup, label: label, stack: stack, layout: layout, size: size }));
|
|
18
|
+
return (_jsx(AriaLocale, { children: _jsx(ChipGroup, { items: items, surface: sup, label: label, labelledBy: labelledBy, stack: stack, multiple: multiple, layout: layout, size: size }) }));
|
|
18
19
|
}
|
|
19
|
-
const STRIP =
|
|
20
|
+
const STRIP = {
|
|
21
|
+
sm: "flex min-w-0 flex-wrap items-center gap-1",
|
|
22
|
+
md: "flex min-w-0 flex-wrap items-center gap-1.5",
|
|
23
|
+
lg: "flex min-w-0 flex-wrap items-center gap-2",
|
|
24
|
+
};
|
|
25
|
+
/* The fade at the edges is `scroll-hint`'s, over the surface the strip sits on; the bottom
|
|
26
|
+
padding keeps a focus ring from being clipped by the scroll box. */
|
|
27
|
+
const SCROLL = "scroll-hint scroll-quiet flex min-w-0 flex-nowrap items-center gap-2 overflow-x-auto py-1";
|
|
20
28
|
const STACK = "flex min-w-0 flex-col items-stretch gap-0.5";
|
|
21
29
|
/** A strip nobody presses: text in a row, a list only when it is named. */
|
|
22
|
-
function StillStrip({ items, surface, label, stack, }) {
|
|
30
|
+
function StillStrip({ items, surface, label, stack, layout, size, }) {
|
|
23
31
|
const listed = label !== undefined;
|
|
24
|
-
return (_jsx("span", { className:
|
|
32
|
+
return (_jsx("span", { className: layout, ...(listed ? { role: "list", "aria-label": label } : {}), children: items.map((item) => (_jsx("span", { "data-ui": "tags.item", ...(listed ? { role: "listitem" } : {}), ...(item.title === undefined ? {} : { title: item.title }), "data-size": size, className: shell({
|
|
33
|
+
item,
|
|
34
|
+
surface,
|
|
35
|
+
stack,
|
|
36
|
+
size,
|
|
37
|
+
removable: false,
|
|
38
|
+
pressable: false,
|
|
39
|
+
}), children: _jsx(Inside, { item: item }) }, item.id))) }));
|
|
25
40
|
}
|
|
26
|
-
function ChipGroup({ items, surface, label, labelledBy, stack, multiple, }) {
|
|
41
|
+
function ChipGroup({ items, surface, label, labelledBy, stack, multiple, layout, size, }) {
|
|
27
42
|
const byId = new Map(items.map((item) => [item.id, item]));
|
|
28
43
|
const removable = items.some((i) => i.onRemove !== undefined);
|
|
29
44
|
/* Selection is React Aria's only when the chips SAY whether they are chosen: then the
|
|
@@ -65,19 +80,29 @@ function ChipGroup({ items, surface, label, labelledBy, stack, multiple, }) {
|
|
|
65
80
|
: {}),
|
|
66
81
|
/* Escape belongs to whatever holds the strip — the popover it lives in closes with it —
|
|
67
82
|
and not to «clear the selection», which would erase the choice without a word. */
|
|
68
|
-
escapeKeyBehavior: "none", className: "min-w-0", children: _jsx(TagList, { items: items, className:
|
|
83
|
+
escapeKeyBehavior: "none", className: "min-w-0", children: _jsx(TagList, { items: items, className: layout, children: (item) => (_jsxs(AriaTag, { "data-ui": "tags.item", "data-size": size, id: item.id, textValue: item.note === undefined ? item.label : `${item.label} ${item.note}`, ...(!selecting && item.onSelect !== undefined
|
|
69
84
|
? { onAction: item.onSelect }
|
|
70
85
|
: {}), ...(item.title === undefined ? {} : { title: item.title }), className: ({ isFocusVisible, isHovered }) => cn(shell({
|
|
71
86
|
item,
|
|
72
87
|
surface,
|
|
73
88
|
stack,
|
|
89
|
+
size,
|
|
74
90
|
removable: item.onRemove !== undefined,
|
|
75
91
|
pressable: item.onSelect !== undefined,
|
|
76
|
-
}), item.onSelect !== undefined &&
|
|
92
|
+
}), item.onSelect !== undefined &&
|
|
93
|
+
isHovered &&
|
|
94
|
+
item.active !== true &&
|
|
95
|
+
!(item.selected === true && size !== "sm")
|
|
77
96
|
? bySurface(surface, "border-ink/40", "border-chrome-ink/40")
|
|
78
97
|
: "", "outline-offset-1", focusRing({ isFocusVisible })), children: [_jsx(Inside, { item: item }), item.onRemove === undefined ? null : _jsx(Remove, { item: item, surface: surface })] })) }) }));
|
|
79
98
|
}
|
|
80
|
-
function paint(item, surface) {
|
|
99
|
+
function paint(item, surface, size) {
|
|
100
|
+
/* A chosen chip of a filter row or a till's categories is the CHOICE the screen is in —
|
|
101
|
+
filled, like the chosen segment of a `SegmentedControl`. A chosen `sm` chip stays a tint:
|
|
102
|
+
there it is a value among values. */
|
|
103
|
+
if (item.selected === true && size !== "sm") {
|
|
104
|
+
return bySurface(surface, "border border-primary bg-primary text-surface", "border border-chrome-link bg-chrome-link text-chrome");
|
|
105
|
+
}
|
|
81
106
|
if (item.active === true) {
|
|
82
107
|
return bySurface(surface, "border border-primary bg-primary text-surface", "border border-chrome-link bg-chrome-link text-chrome");
|
|
83
108
|
}
|
|
@@ -90,18 +115,36 @@ function paint(item, surface) {
|
|
|
90
115
|
/* Stacked, each chip takes its whole line: a column of chips of different widths does not
|
|
91
116
|
read as a list, it reads as a mess — and the blank on the right is what lets it be
|
|
92
117
|
pressed without aiming. */
|
|
93
|
-
|
|
94
|
-
|
|
118
|
+
/* The height of each size, and the room the label gets inside it. `sm` is a line of text and
|
|
119
|
+
grows under a finger only if someone can press it. */
|
|
120
|
+
const SIZE = {
|
|
121
|
+
sm: { box: "gap-1 py-0.5 text-micro", pad: "px-2", removePad: "pr-0.5 pl-2" },
|
|
122
|
+
md: {
|
|
123
|
+
box: "h-(--size-control-sm) gap-1.5 text-meta",
|
|
124
|
+
pad: "px-3",
|
|
125
|
+
removePad: "pr-1.5 pl-3",
|
|
126
|
+
},
|
|
127
|
+
lg: {
|
|
128
|
+
box: "h-(--size-control-lg) gap-2 text-body font-medium",
|
|
129
|
+
pad: "px-4",
|
|
130
|
+
removePad: "pr-2 pl-4",
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
function shell({ item, surface, stack, size, removable, pressable, }) {
|
|
134
|
+
const box = SIZE[size];
|
|
135
|
+
return cn(stack ? "flex w-full justify-start" : "inline-flex shrink-0", "min-w-0 items-center rounded-ui-tag transition-colors duration-(--duration-instant)", box.box, size === "sm" && (pressable || removable) ? "touch:min-h-8 touch:text-meta" : "", paint(item, surface, size), removable ? box.removePad : box.pad, pressable ? "cursor-pointer" : "cursor-default");
|
|
95
136
|
}
|
|
96
137
|
function Inside({ item }) {
|
|
97
138
|
const Icon = item.icon;
|
|
98
139
|
return (_jsxs(_Fragment, { children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-3 shrink-0 opacity-70", strokeWidth: 2, "aria-hidden": true })), item.avatar === undefined ? null : (_jsx("span", { "aria-hidden": true, className: "-my-0.5 -ml-1.5 flex shrink-0", children: _jsx(Avatar, { name: item.label, size: "sm", ...(typeof item.avatar === "string" ? { src: item.avatar } : {}) }) })), _jsx("span", { className: "min-w-0 truncate", children: item.label }), item.note === undefined ? null : (
|
|
99
140
|
/* Secondary by its separator and weight, not by fading: at 60 % the note fell
|
|
100
141
|
under 4.5:1 on a tinted chip. */
|
|
101
|
-
_jsxs("span", { className: "shrink-0 font-normal", children: ["\u00B7 ", item.note] }))
|
|
142
|
+
_jsxs("span", { className: "shrink-0 font-normal", children: ["\u00B7 ", item.note] })), item.count === undefined ? null : (
|
|
143
|
+
/* Apart by a gap and lighter, not dimmer — the same reason as the note. */
|
|
144
|
+
_jsx("span", { "data-ui": "tags.count", className: "shrink-0 font-normal tabular-nums", children: item.count }))] }));
|
|
102
145
|
}
|
|
103
146
|
/* The × is React Aria's `remove` slot: it removes THIS chip and never presses it, so
|
|
104
147
|
removing a pressable chip does not also choose it. */
|
|
105
148
|
function Remove({ item, surface }) {
|
|
106
|
-
return (_jsx(AriaButton, { slot: "remove", ...(item.removeLabel === undefined ? {} : { "aria-label": item.removeLabel }), className: ({ isFocusVisible }) => cn("inline-flex size-4 shrink-0 cursor-default items-center justify-center rounded-pill transition-colors duration-(--duration-instant)", bySurface(surface, "hover:bg-ink/15 pressed:bg-ink/20", "hover:bg-chrome-ink/25 pressed:bg-chrome-ink/30"), focusRing({ isFocusVisible })), children: _jsx(X, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }));
|
|
149
|
+
return (_jsx(AriaButton, { slot: "remove", ...(item.removeLabel === undefined ? {} : { "aria-label": item.removeLabel }), className: ({ isFocusVisible }) => cn("hit-target inline-flex size-4 shrink-0 cursor-default items-center justify-center rounded-pill transition-colors duration-(--duration-instant)", bySurface(surface, "hover:bg-ink/15 pressed:bg-ink/20", "hover:bg-chrome-ink/25 pressed:bg-chrome-ink/30"), focusRing({ isFocusVisible })), children: _jsx(X, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }));
|
|
107
150
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* Without `"use client"`, apart from `Count.tsx` (which reads its surface and its words from
|
|
2
|
+
context): a server component that writes a count in words calls it. */
|
|
3
|
+
/** The text of a count: formatted for the locale, and «99+» past `max`. Exported for the
|
|
4
|
+
* hosts that also need it in words — a button's `aria-label`, a `title`. */
|
|
5
|
+
export function countText(value, format, max) {
|
|
6
|
+
return max !== undefined && value > max ? `${format(max)}+` : format(value);
|
|
7
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { StatusDot, Tag } from "./Tag.js";
|
|
2
|
-
export { Count, type CountProps
|
|
3
|
-
export {
|
|
2
|
+
export { Count, type CountProps } from "./Count.js";
|
|
3
|
+
export { countText } from "./countText.js";
|
|
4
|
+
export { type TagItem, Tags, type TagsSize } from "./Tags.js";
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
export { StatusDot, Tag } from "./Tag.js";
|
|
3
3
|
/* How many things are behind something, or that something asks for: one counter for the
|
|
4
4
|
sidebar, the tabs, the systray, a menu and an application's own button. */
|
|
5
|
-
export { Count
|
|
5
|
+
export { Count } from "./Count.js";
|
|
6
|
+
export { countText } from "./countText.js";
|
|
6
7
|
/* The strip of chips: the same in the bar, in the dropdown and anywhere
|
|
7
8
|
a list of short words is drawn. */
|
|
8
9
|
export { Tags } from "./Tags.js";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* a component passes its branch's (`useUiCopy()`), so a provider reaches the sentence. */
|
|
4
|
-
export declare function formatRelative(when: Date, now?: Date, copy?: UiCopy): string;
|
|
5
|
-
export declare function formatDateTime(when: Date, locale?: string): string;
|
|
1
|
+
import { formatDateTime, formatRelative } from "./format.js";
|
|
2
|
+
export { formatDateTime, formatRelative };
|
|
6
3
|
export declare function DateValue({ when, format,
|
|
7
4
|
/** So it can be tested: without this, a story with «hace 2 min» changes its
|
|
8
5
|
* text every minute and no snapshot works as a reference. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { dateFormat, formatDateTime, formatRelative, } from "./format.js";
|
|
4
5
|
/* ==================================================================== *
|
|
5
6
|
* WHEN — a date says two things and they can't both be said together.
|
|
6
7
|
*
|
|
@@ -19,49 +20,10 @@ import { currentCopy, currentCopyLocale, useUiCopy, } from "../../foundations/co
|
|
|
19
20
|
* order two things or remember which one it was. From there on the date is
|
|
20
21
|
* drawn, which is what at that distance is really being asked.
|
|
21
22
|
* ==================================================================== */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return new Intl.DateTimeFormat(locale, {
|
|
27
|
-
day: "2-digit",
|
|
28
|
-
month: "2-digit",
|
|
29
|
-
year: "numeric",
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function timeFormat(locale) {
|
|
33
|
-
return new Intl.DateTimeFormat(locale, {
|
|
34
|
-
hour: "2-digit",
|
|
35
|
-
minute: "2-digit",
|
|
36
|
-
hourCycle: "h23",
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const MINUTE = 60_000;
|
|
40
|
-
const HOUR = 60 * MINUTE;
|
|
41
|
-
const DAY = 24 * HOUR;
|
|
42
|
-
/** The steps, from finest to coarsest. The first one that fits, wins. */
|
|
43
|
-
const STEPS = [
|
|
44
|
-
[MINUTE, "minute"],
|
|
45
|
-
[HOUR, "hour"],
|
|
46
|
-
[DAY, "day"],
|
|
47
|
-
];
|
|
48
|
-
/** Context: `copy` defaults to the installed words — what a caller outside a component has;
|
|
49
|
-
* a component passes its branch's (`useUiCopy()`), so a provider reaches the sentence. */
|
|
50
|
-
export function formatRelative(when, now = new Date(), copy = currentCopy()) {
|
|
51
|
-
const locale = copy.locale;
|
|
52
|
-
const delta = when.getTime() - now.getTime();
|
|
53
|
-
const abs = Math.abs(delta);
|
|
54
|
-
if (abs < MINUTE)
|
|
55
|
-
return copy.time.justNow;
|
|
56
|
-
if (abs > 7 * DAY)
|
|
57
|
-
return dateFormat(locale).format(when);
|
|
58
|
-
const step = STEPS.find(([ms]) => abs < ms * 60) ?? STEPS[STEPS.length - 1];
|
|
59
|
-
const [ms, unit] = step;
|
|
60
|
-
return relativeFormat(locale).format(Math.round(delta / ms), unit);
|
|
61
|
-
}
|
|
62
|
-
export function formatDateTime(when, locale = currentCopyLocale()) {
|
|
63
|
-
return `${dateFormat(locale).format(when)} ${timeFormat(locale).format(when)}`;
|
|
64
|
-
}
|
|
23
|
+
/* The formatters — `formatRelative`, `formatDateTime` — are `format.ts`, without the
|
|
24
|
+
directive, so a server component writes a date the same way; re-exported so every path that
|
|
25
|
+
read them here keeps reading them. */
|
|
26
|
+
export { formatDateTime, formatRelative };
|
|
65
27
|
/** A day written as `YYYY-MM-DD` (what a date field stores) is that day HERE. `new Date()`
|
|
66
28
|
* reads it as midnight in UTC, and west of Greenwich that is the evening before: a due date
|
|
67
29
|
* of the 15th was drawn as the 14th in La Paz. Anything else goes through `Date` as is. */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ElapsedSince, type ElapsedThresholds } from "./elapsedTime.js";
|
|
2
|
+
export type ElapsedProps = {
|
|
3
|
+
/** When the wait started. */
|
|
4
|
+
since: ElapsedSince;
|
|
5
|
+
/** For a test or a screenshot: a fixed «now» instead of the live clock. */
|
|
6
|
+
now?: number;
|
|
7
|
+
} & ElapsedThresholds;
|
|
8
|
+
/**
|
|
9
|
+
* How long it has been waiting, live: «4:05», amber past `warnAfter`, red past `badAfter`.
|
|
10
|
+
*
|
|
11
|
+
* Context: a kitchen display reads AGE, not arrival — the cook looks for the red ticket, not
|
|
12
|
+
* for «12:40». The figure ticks every second off one shared clock (`useNow`), and the clock
|
|
13
|
+
* icon with the written time keeps the colour from being the only channel. On the server it
|
|
14
|
+
* draws nothing: there is no «now» both sides agree on.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Elapsed({ since, now: fixed, warnAfter, badAfter }: ElapsedProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useNow } from "../../foundations/clock.js";
|
|
4
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { elapsedMillis, elapsedTone, formatElapsed, } from "./elapsedTime.js";
|
|
6
|
+
import { Timer } from "lucide-react";
|
|
7
|
+
/* The figure in its tone — text on a card, so the readable ones. */
|
|
8
|
+
const TEXT = {
|
|
9
|
+
neutral: "text-muted",
|
|
10
|
+
info: "text-info",
|
|
11
|
+
good: "text-good",
|
|
12
|
+
warn: "text-warn",
|
|
13
|
+
bad: "text-bad",
|
|
14
|
+
accent: "text-ink",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* How long it has been waiting, live: «4:05», amber past `warnAfter`, red past `badAfter`.
|
|
18
|
+
*
|
|
19
|
+
* Context: a kitchen display reads AGE, not arrival — the cook looks for the red ticket, not
|
|
20
|
+
* for «12:40». The figure ticks every second off one shared clock (`useNow`), and the clock
|
|
21
|
+
* icon with the written time keeps the colour from being the only channel. On the server it
|
|
22
|
+
* draws nothing: there is no «now» both sides agree on.
|
|
23
|
+
*/
|
|
24
|
+
export function Elapsed({ since, now: fixed, warnAfter, badAfter }) {
|
|
25
|
+
const copy = useUiCopy();
|
|
26
|
+
const live = useNow();
|
|
27
|
+
const now = fixed ?? live;
|
|
28
|
+
if (now === null)
|
|
29
|
+
return null;
|
|
30
|
+
const millis = elapsedMillis(since, now);
|
|
31
|
+
const tone = elapsedTone(millis, {
|
|
32
|
+
...(warnAfter === undefined ? {} : { warnAfter }),
|
|
33
|
+
...(badAfter === undefined ? {} : { badAfter }),
|
|
34
|
+
});
|
|
35
|
+
const text = formatElapsed(millis);
|
|
36
|
+
return (_jsxs("span", { "data-ui": "elapsed", "data-tone": tone ?? "neutral", title: fillCopy(copy.elapsed.waiting, { time: text }), className: `inline-flex shrink-0 items-center gap-1 text-meta font-semibold tabular-nums ${TEXT[tone ?? "neutral"]}`, children: [_jsx(Timer, { "aria-hidden": true, className: "size-(--size-icon-sm)", strokeWidth: 2.25 }), _jsx("span", { className: "sr-only", children: copy.elapsed.label }), text] }));
|
|
37
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
+
import { type MeterLevel, meterLevel, type MeterThresholds } from "./meterLevel.js";
|
|
1
2
|
import type { ReactNode } from "react";
|
|
2
|
-
export type MeterLevel
|
|
3
|
-
|
|
4
|
-
export type MeterThresholds = {
|
|
5
|
-
warn: number;
|
|
6
|
-
danger: number;
|
|
7
|
-
};
|
|
8
|
-
/** The level of a percentage: under `warn` is good, up to `danger` is warn, above is danger. */
|
|
9
|
-
export declare function meterLevel(percentage: number, thresholds?: MeterThresholds): MeterLevel;
|
|
3
|
+
export type { MeterLevel, MeterThresholds };
|
|
4
|
+
export { meterLevel };
|
|
10
5
|
export type MeterProps = {
|
|
11
6
|
/** What is measured: «Crédito usado», «Stock». */
|
|
12
7
|
label: string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { AriaLocale } from "../../foundations/aria.js";
|
|
4
4
|
import { tv } from "../../foundations/variants.js";
|
|
5
|
+
import { DEFAULT_THRESHOLDS, meterLevel, } from "./meterLevel.js";
|
|
5
6
|
import { Meter as AriaMeter } from "react-aria-components";
|
|
6
7
|
/**
|
|
7
8
|
* Where a quantity stands against a known range: the credit used, the stock against the
|
|
@@ -29,15 +30,7 @@ const fill = tv({
|
|
|
29
30
|
},
|
|
30
31
|
},
|
|
31
32
|
});
|
|
32
|
-
|
|
33
|
-
/** The level of a percentage: under `warn` is good, up to `danger` is warn, above is danger. */
|
|
34
|
-
export function meterLevel(percentage, thresholds = DEFAULT_THRESHOLDS) {
|
|
35
|
-
if (percentage > thresholds.danger)
|
|
36
|
-
return "danger";
|
|
37
|
-
if (percentage >= thresholds.warn)
|
|
38
|
-
return "warn";
|
|
39
|
-
return "good";
|
|
40
|
-
}
|
|
33
|
+
export { meterLevel };
|
|
41
34
|
export function Meter({ label, value, minValue = 0, maxValue = 100, formatOptions, valueLabel, thresholds = DEFAULT_THRESHOLDS, showValue = true, width = "w-64", }) {
|
|
42
35
|
return (_jsx(AriaLocale, { children: _jsx(AriaMeter, { "aria-label": label, value: value, minValue: minValue, maxValue: maxValue, formatOptions: formatOptions, valueLabel: valueLabel, className: `flex max-w-full flex-col gap-1.5 ${width}`, children: ({ percentage, valueText }) => {
|
|
43
36
|
const level = meterLevel(percentage, thresholds);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { isRichTextEmpty, richTextPlain } from "./richTextPlain.js";
|
|
1
2
|
/** The HTML with everything that runs taken out, or `null` where there is no DOM to do it. */
|
|
2
3
|
export declare function sanitizeRichText(html: string): string | null;
|
|
3
|
-
|
|
4
|
-
export declare function richTextPlain(html: string): string;
|
|
5
|
-
/** Nothing written: no text and no image — «<p></p>» from an emptied editor counts as nothing. */
|
|
6
|
-
export declare function isRichTextEmpty(html: string | null | undefined): boolean;
|
|
4
|
+
export { isRichTextEmpty, richTextPlain };
|
|
7
5
|
/** The HTML of a note, read: cleaned, in the system's text style (`rich-text` in tokens.css). */
|
|
8
6
|
export declare function RichTextValue({ value }: {
|
|
9
7
|
value: string | null | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
4
5
|
import DOMPurify from "dompurify";
|
|
5
6
|
import { useSyncExternalStore } from "react";
|
|
6
7
|
/* ==================================================================== *
|
|
@@ -93,26 +94,10 @@ export function sanitizeRichText(html) {
|
|
|
93
94
|
ALLOWED_URI_REGEXP: /^(?:https?:|mailto:|tel:|data:image\/(?:png|jpeg|gif|webp);)/i,
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.replace(/<[^>]*>/g, "")
|
|
101
|
-
.replace(/ /g, " ")
|
|
102
|
-
.replace(/&/g, "&")
|
|
103
|
-
.replace(/</g, "<")
|
|
104
|
-
.replace(/>/g, ">")
|
|
105
|
-
.replace(/"/g, '"')
|
|
106
|
-
.replace(/'/g, "'")
|
|
107
|
-
.replace(/\s+/g, " ")
|
|
108
|
-
.trim();
|
|
109
|
-
}
|
|
110
|
-
/** Nothing written: no text and no image — «<p></p>» from an emptied editor counts as nothing. */
|
|
111
|
-
export function isRichTextEmpty(html) {
|
|
112
|
-
if (html === null || html === undefined)
|
|
113
|
-
return true;
|
|
114
|
-
return richTextPlain(html) === "" && !/<(?:img|hr|table)\b/i.test(html);
|
|
115
|
-
}
|
|
97
|
+
/* `richTextPlain` and `isRichTextEmpty` are plain functions (`richTextPlain.ts`), without the
|
|
98
|
+
directive, so a server component reads them; re-exported so every path that read them here
|
|
99
|
+
keeps reading them. `sanitizeRichText` stays: DOMPurify needs a DOM. */
|
|
100
|
+
export { isRichTextEmpty, richTextPlain };
|
|
116
101
|
const subscribe = () => () => { };
|
|
117
102
|
/** The HTML of a note, read: cleaned, in the system's text style (`rich-text` in tokens.css). */
|
|
118
103
|
export function RichTextValue({ value }) {
|