@sincpro/web-ui 2.11.0 → 2.12.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 +35 -3
- 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/listing/AxisLevels.d.ts +2 -5
- package/dist/components/listing/AxisLevels.js +5 -22
- package/dist/components/listing/ColumnsMenu.d.ts +3 -7
- package/dist/components/listing/ColumnsMenu.js +4 -8
- 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 +9 -5
- package/dist/components/listing/index.js +13 -6
- 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/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/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/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/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.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/index.d.ts +18 -11
- package/dist/foundations/index.js +21 -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/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 +1135 -0
- package/dist/foundations/uiCopy.js +749 -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/field/Field.d.ts +2 -6
- package/dist/primitives/field/Field.js +4 -10
- package/dist/primitives/field/classes.d.ts +6 -0
- package/dist/primitives/field/classes.js +13 -0
- package/dist/primitives/field/index.d.ts +2 -1
- package/dist/primitives/field/index.js +3 -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/table/EditableTable.d.ts +3 -37
- package/dist/primitives/table/EditableTable.js +2 -47
- package/dist/primitives/table/Table.d.ts +2 -4
- package/dist/primitives/table/Table.js +4 -11
- 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/countText.d.ts +3 -0
- package/dist/primitives/tag/countText.js +7 -0
- package/dist/primitives/tag/index.d.ts +2 -1
- 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/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/format.d.ts +16 -0
- package/dist/primitives/value/format.js +81 -0
- package/dist/primitives/value/index.d.ts +7 -4
- package/dist/primitives/value/index.js +9 -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/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { currentCopy, currentCopyLocale, } from "../../foundations/uiCopy.js";
|
|
2
|
+
/**
|
|
3
|
+
* THE FORMATTERS a value is written with — a number (`Numeric`, `Cell`) and a date
|
|
4
|
+
* (`DateValue`) — in the installed locale unless one is passed.
|
|
5
|
+
*
|
|
6
|
+
* Context: they lived beside their components, which carry `"use client"`, and a React
|
|
7
|
+
* Server Components bundler turns every export of a client module into a client reference:
|
|
8
|
+
* `formatCount(1234)` called on the server returned a reference, not «1,234». Here, without
|
|
9
|
+
* the directive, they are functions anywhere. On the server they read the server's installed
|
|
10
|
+
* words (`installCopy`, called in the module of the root layout) — or the locale passed.
|
|
11
|
+
*/
|
|
12
|
+
/* ── Numbers ─────────────────────────────────────────────────────────── */
|
|
13
|
+
function integerFormat(locale) {
|
|
14
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 });
|
|
15
|
+
}
|
|
16
|
+
function decimalFormat(locale) {
|
|
17
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 2 });
|
|
18
|
+
}
|
|
19
|
+
/** Four decimals and not two for distances — they live near zero
|
|
20
|
+
* (`0.0696`, `0.0149`) and with two they turn into `0.07` and `0.01`, which is
|
|
21
|
+
* losing exactly the part that tells one column from another. */
|
|
22
|
+
function distanceFormat(locale) {
|
|
23
|
+
return new Intl.NumberFormat(locale, {
|
|
24
|
+
minimumFractionDigits: 4,
|
|
25
|
+
maximumFractionDigits: 4,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export const formatCount = (value, locale = currentCopyLocale()) => integerFormat(locale).format(value);
|
|
29
|
+
export const formatNumber = (value, locale = currentCopyLocale()) => decimalFormat(locale).format(value);
|
|
30
|
+
export const formatDistance = (value, locale = currentCopyLocale()) => distanceFormat(locale).format(value);
|
|
31
|
+
/** A number written with any `Intl.NumberFormatOptions` — a currency, a percentage, fixed
|
|
32
|
+
* decimals — in the session locale. The same options `NumberInput` takes, so a value reads
|
|
33
|
+
* the same in its form and in the cell or the figure that shows it elsewhere. */
|
|
34
|
+
export const formatWith = (value, options, locale = currentCopyLocale()) => new Intl.NumberFormat(locale, options).format(value);
|
|
35
|
+
/* ── Dates — see `DateValue.tsx` for why the relative stops at a week ── */
|
|
36
|
+
function relativeFormat(locale) {
|
|
37
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
38
|
+
}
|
|
39
|
+
/** The day alone, in digits and in the locale's order. Exported for `DateValue`'s `date`
|
|
40
|
+
* format; not public. */
|
|
41
|
+
export function dateFormat(locale) {
|
|
42
|
+
return new Intl.DateTimeFormat(locale, {
|
|
43
|
+
day: "2-digit",
|
|
44
|
+
month: "2-digit",
|
|
45
|
+
year: "numeric",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function timeFormat(locale) {
|
|
49
|
+
return new Intl.DateTimeFormat(locale, {
|
|
50
|
+
hour: "2-digit",
|
|
51
|
+
minute: "2-digit",
|
|
52
|
+
hourCycle: "h23",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const MINUTE = 60_000;
|
|
56
|
+
const HOUR = 60 * MINUTE;
|
|
57
|
+
const DAY = 24 * HOUR;
|
|
58
|
+
/** The steps, from finest to coarsest. The first one that fits, wins. */
|
|
59
|
+
const STEPS = [
|
|
60
|
+
[MINUTE, "minute"],
|
|
61
|
+
[HOUR, "hour"],
|
|
62
|
+
[DAY, "day"],
|
|
63
|
+
];
|
|
64
|
+
/** Context: `copy` defaults to the installed words — what a caller outside a component has;
|
|
65
|
+
* a component passes its branch's (read with `useUiCopy`), so a provider reaches the
|
|
66
|
+
* sentence. */
|
|
67
|
+
export function formatRelative(when, now = new Date(), copy = currentCopy()) {
|
|
68
|
+
const locale = copy.locale;
|
|
69
|
+
const delta = when.getTime() - now.getTime();
|
|
70
|
+
const abs = Math.abs(delta);
|
|
71
|
+
if (abs < MINUTE)
|
|
72
|
+
return copy.time.justNow;
|
|
73
|
+
if (abs > 7 * DAY)
|
|
74
|
+
return dateFormat(locale).format(when);
|
|
75
|
+
const step = STEPS.find(([ms]) => abs < ms * 60) ?? STEPS[STEPS.length - 1];
|
|
76
|
+
const [ms, unit] = step;
|
|
77
|
+
return relativeFormat(locale).format(Math.round(delta / ms), unit);
|
|
78
|
+
}
|
|
79
|
+
export function formatDateTime(when, locale = currentCopyLocale()) {
|
|
80
|
+
return `${dateFormat(locale).format(when)} ${timeFormat(locale).format(when)}`;
|
|
81
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { Copyable, type CopyableProps, CopyButton, } from "./Copyable.js";
|
|
2
|
-
export { DateValue
|
|
2
|
+
export { DateValue } from "./DateValue.js";
|
|
3
|
+
export { formatCount, formatDateTime, formatDistance, formatNumber, formatRelative, formatWith, } from "./format.js";
|
|
3
4
|
export { Markdown, type MarkdownProps } from "./Markdown.js";
|
|
4
|
-
export { Meter, type
|
|
5
|
+
export { Meter, type MeterProps } from "./Meter.js";
|
|
6
|
+
export { type MeterLevel, meterLevel, type MeterThresholds, } from "./meterLevel.js";
|
|
5
7
|
export { Metric, type MetricProps, Metrics } from "./Metric.js";
|
|
6
8
|
export { Avatar, type AvatarSize, type PersonContact, UserChip, type UserChipProps, UserStack, } from "./Person.js";
|
|
7
9
|
export { ProgressBar, type ProgressBarProps, } from "./ProgressBar.js";
|
|
8
10
|
export { RelationCard, type RelationCardProps, type RelationSummary, RelationValue, type RelationValueProps, } from "./Relation.js";
|
|
9
|
-
export {
|
|
11
|
+
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
12
|
+
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
10
13
|
export { type Rounding, type RoundingMethod, roundTo, } from "./rounding.js";
|
|
11
14
|
export { Totals, type TotalsCredit, type TotalsDeduction, type TotalsFact, type TotalsProps, type TotalsRow, } from "./Totals.js";
|
|
12
|
-
export { Cell,
|
|
15
|
+
export { Cell, KeyValue, Numeric } from "./Value.js";
|
|
13
16
|
export { YesNo, type YesNoLook } from "./YesNo.js";
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/* Show a number or a datum so that it reads as such and not as text. */
|
|
2
2
|
export { Copyable, CopyButton, } from "./Copyable.js";
|
|
3
|
-
export { DateValue
|
|
3
|
+
export { DateValue } from "./DateValue.js";
|
|
4
|
+
/* The formatters, without `"use client"`: a server component writes a number or a date the
|
|
5
|
+
same way. */
|
|
6
|
+
export { formatCount, formatDateTime, formatDistance, formatNumber, formatRelative, formatWith, } from "./format.js";
|
|
4
7
|
export { Markdown } from "./Markdown.js";
|
|
5
|
-
export { Meter
|
|
8
|
+
export { Meter } from "./Meter.js";
|
|
9
|
+
export { meterLevel, } from "./meterLevel.js";
|
|
6
10
|
export { Metric, Metrics } from "./Metric.js";
|
|
7
11
|
export { Avatar, UserChip, UserStack, } from "./Person.js";
|
|
8
12
|
export { ProgressBar, } from "./ProgressBar.js";
|
|
9
13
|
export { RelationCard, RelationValue, } from "./Relation.js";
|
|
10
14
|
/* The HTML of a note, read — cleaned of anything that runs. */
|
|
11
|
-
export {
|
|
15
|
+
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
16
|
+
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
12
17
|
export { roundTo, } from "./rounding.js";
|
|
13
18
|
export { Totals, } from "./Totals.js";
|
|
14
|
-
export { Cell,
|
|
19
|
+
export { Cell, KeyValue, Numeric } from "./Value.js";
|
|
15
20
|
export { YesNo } from "./YesNo.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type MeterLevel = "good" | "warn" | "danger";
|
|
2
|
+
/** Percentages of the range where the color changes. */
|
|
3
|
+
export type MeterThresholds = {
|
|
4
|
+
warn: number;
|
|
5
|
+
danger: number;
|
|
6
|
+
};
|
|
7
|
+
/** Exported for `Meter`'s default; not public. */
|
|
8
|
+
export declare const DEFAULT_THRESHOLDS: MeterThresholds;
|
|
9
|
+
/** The level of a percentage: under `warn` is good, up to `danger` is warn, above is danger. */
|
|
10
|
+
export declare function meterLevel(percentage: number, thresholds?: MeterThresholds): MeterLevel;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Without `"use client"`, apart from `Meter.tsx`: a server component that colours a figure by
|
|
2
|
+
how full it is reads the same thresholds. */
|
|
3
|
+
/** Exported for `Meter`'s default; not public. */
|
|
4
|
+
export const DEFAULT_THRESHOLDS = { warn: 70, danger: 90 };
|
|
5
|
+
/** The level of a percentage: under `warn` is good, up to `danger` is warn, above is danger. */
|
|
6
|
+
export function meterLevel(percentage, thresholds = DEFAULT_THRESHOLDS) {
|
|
7
|
+
if (percentage > thresholds.danger)
|
|
8
|
+
return "danger";
|
|
9
|
+
if (percentage >= thresholds.warn)
|
|
10
|
+
return "warn";
|
|
11
|
+
return "good";
|
|
12
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The words of an HTML, without its tags: what is shown where it cannot be cleaned. */
|
|
2
|
+
export declare function richTextPlain(html: string): string;
|
|
3
|
+
/** Nothing written: no text and no image — «<p></p>» from an emptied editor counts as nothing. */
|
|
4
|
+
export declare function isRichTextEmpty(html: string | null | undefined): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* Without `"use client"`, apart from `RichText.tsx`: a server component that writes a note's
|
|
2
|
+
words in a summary — or asks whether it says anything — reads these. Cleaning the HTML
|
|
3
|
+
(`sanitizeRichText`) stays there: it needs a DOM. */
|
|
4
|
+
/** The words of an HTML, without its tags: what is shown where it cannot be cleaned. */
|
|
5
|
+
export function richTextPlain(html) {
|
|
6
|
+
return html
|
|
7
|
+
.replace(/<(?:br|\/p|\/li|\/h[1-6]|\/tr)\s*\/?>/gi, " ")
|
|
8
|
+
.replace(/<[^>]*>/g, "")
|
|
9
|
+
.replace(/ /g, " ")
|
|
10
|
+
.replace(/&/g, "&")
|
|
11
|
+
.replace(/</g, "<")
|
|
12
|
+
.replace(/>/g, ">")
|
|
13
|
+
.replace(/"/g, '"')
|
|
14
|
+
.replace(/'/g, "'")
|
|
15
|
+
.replace(/\s+/g, " ")
|
|
16
|
+
.trim();
|
|
17
|
+
}
|
|
18
|
+
/** Nothing written: no text and no image — «<p></p>» from an emptied editor counts as nothing. */
|
|
19
|
+
export function isRichTextEmpty(html) {
|
|
20
|
+
if (html === null || html === undefined)
|
|
21
|
+
return true;
|
|
22
|
+
return richTextPlain(html) === "" && !/<(?:img|hr|table)\b/i.test(html);
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|