@sincpro/web-ui 2.5.0 → 2.7.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 +97 -7
- package/dist/components/activity/Activity.d.ts +8 -1
- package/dist/components/activity/Activity.js +9 -4
- package/dist/components/activity/Messages.d.ts +4 -0
- package/dist/components/attachments/Attachments.d.ts +1 -28
- package/dist/components/attachments/Attachments.js +5 -24
- package/dist/components/attachments/FileList.d.ts +28 -0
- package/dist/components/attachments/FileList.js +91 -0
- package/dist/components/attachments/FileThumb.d.ts +13 -0
- package/dist/components/attachments/FileThumb.js +34 -0
- package/dist/components/attachments/download.d.ts +9 -0
- package/dist/components/attachments/download.js +36 -0
- package/dist/components/attachments/files.d.ts +28 -0
- package/dist/components/attachments/index.d.ts +4 -2
- package/dist/components/attachments/index.js +4 -1
- package/dist/components/calendar/RecordCalendar.d.ts +2 -1
- package/dist/components/calendar/RecordCalendar.js +4 -1
- package/dist/components/calendar/calendar.css +37 -0
- package/dist/components/chat/ChatThread.d.ts +8 -1
- package/dist/components/chat/ChatThread.js +9 -4
- package/dist/components/chat/model.d.ts +4 -0
- package/dist/components/gantt/RecordGantt.d.ts +9 -1
- package/dist/components/gantt/RecordGantt.js +16 -3
- package/dist/components/gantt/gantt.css +52 -0
- package/dist/components/search/CriteriaBuilder.d.ts +11 -2
- package/dist/components/search/CriteriaBuilder.js +25 -6
- package/dist/components/search/FilterBuilder.d.ts +63 -5
- package/dist/components/search/FilterBuilder.js +346 -50
- package/dist/components/search/RuleValue.d.ts +17 -0
- package/dist/components/search/RuleValue.js +121 -0
- package/dist/components/search/SearchBar.d.ts +25 -2
- package/dist/components/search/SearchBar.js +360 -39
- package/dist/components/search/context.d.ts +45 -0
- package/dist/components/search/context.js +25 -0
- package/dist/components/search/criteria.d.ts +20 -0
- package/dist/components/search/index.d.ts +7 -4
- package/dist/components/search/index.js +9 -3
- package/dist/components/search/model.d.ts +16 -1
- package/dist/components/search/model.js +5 -0
- package/dist/components/search/query.d.ts +88 -4
- package/dist/components/search/query.js +262 -62
- package/dist/components/search/records.d.ts +68 -0
- package/dist/components/search/records.js +115 -0
- package/dist/foundations/copy.d.ts +27 -0
- package/dist/foundations/copy.es.js +15 -0
- package/dist/foundations/copy.js +15 -0
- package/dist/primitives/button/Button.d.ts +5 -1
- package/dist/primitives/button/Button.js +9 -2
- package/dist/primitives/value/Markdown.d.ts +1 -0
- package/dist/primitives/value/Markdown.js +1 -0
- package/dist/tokens.css +6 -85
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* ====================================================================
|
|
2
|
+
* THE RECORD CALENDAR (FullCalendar v7, `forma` theme) in these tokens.
|
|
3
|
+
*
|
|
4
|
+
* Context: FullCalendar's structure and its `forma` theme, then the palette that theme reads.
|
|
5
|
+
* It comes with `RecordCalendar` — imported by the component, not by `tokens.css` — so it
|
|
6
|
+
* travels in the calendar's chunk: a screen that never opens a calendar never downloads it.
|
|
7
|
+
*
|
|
8
|
+
* The theme reads a palette of `--fc-forma-*` variables. Pointed at web-ui's tokens it takes
|
|
9
|
+
* the theme — light, dark, a brand — with no dark block of its own: the tokens already flip.
|
|
10
|
+
* Aliases, so no contrast of their own to measure; the translucent washes are mixed from the
|
|
11
|
+
* ink so they read on either theme.
|
|
12
|
+
* ==================================================================== */
|
|
13
|
+
@import "@fullcalendar/react/skeleton.css";
|
|
14
|
+
@import "@fullcalendar/react/themes/forma/theme.css";
|
|
15
|
+
|
|
16
|
+
:root {
|
|
17
|
+
--fc-forma-primary: var(--color-primary);
|
|
18
|
+
--fc-forma-primary-over: var(--color-primary-hover);
|
|
19
|
+
--fc-forma-primary-down: var(--color-primary-hover);
|
|
20
|
+
--fc-forma-primary-foreground: var(--color-surface);
|
|
21
|
+
--fc-forma-event: var(--color-primary);
|
|
22
|
+
--fc-forma-event-contrast: var(--color-surface);
|
|
23
|
+
--fc-forma-background-event: var(--color-primary);
|
|
24
|
+
--fc-forma-highlight: color-mix(in srgb, var(--color-primary) 18%, transparent);
|
|
25
|
+
--fc-forma-background: var(--color-surface);
|
|
26
|
+
--fc-forma-faint: color-mix(in srgb, var(--color-ink) 3%, transparent);
|
|
27
|
+
--fc-forma-muted: color-mix(in srgb, var(--color-ink) 7%, transparent);
|
|
28
|
+
--fc-forma-strong: color-mix(in srgb, var(--color-ink) 12%, transparent);
|
|
29
|
+
--fc-forma-stronger: color-mix(in srgb, var(--color-ink) 16%, transparent);
|
|
30
|
+
--fc-forma-strongest: color-mix(in srgb, var(--color-ink) 20%, transparent);
|
|
31
|
+
--fc-forma-foreground: var(--color-ink);
|
|
32
|
+
--fc-forma-faint-foreground: var(--color-muted);
|
|
33
|
+
--fc-forma-muted-foreground: var(--color-muted);
|
|
34
|
+
--fc-forma-border: var(--color-line);
|
|
35
|
+
--fc-forma-muted-border: var(--color-line);
|
|
36
|
+
--fc-forma-strong-border: var(--color-line-strong);
|
|
37
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttachmentFile } from "../attachments/files.js";
|
|
1
2
|
import { type ChatMessage } from "./model.js";
|
|
2
3
|
export type ChatThreadProps = {
|
|
3
4
|
messages: readonly ChatMessage[];
|
|
@@ -9,5 +10,11 @@ export type ChatThreadProps = {
|
|
|
9
10
|
label?: string;
|
|
10
11
|
/** The «now» the day names are relative to. */
|
|
11
12
|
now?: Date;
|
|
13
|
+
/** Open a file a message carries. Present = its name is a button; WHERE it opens — a
|
|
14
|
+
* peek, a `FilePreview` — is the application's. */
|
|
15
|
+
onOpenFile?: (file: AttachmentFile, message: ChatMessage) => void;
|
|
16
|
+
/** Download a file a message carries by code (a token, a signed URL). Without it, a file
|
|
17
|
+
* with a `url` downloads by link. Busy while the promise runs; a rejection is said. */
|
|
18
|
+
onDownloadFile?: (file: AttachmentFile, message: ChatMessage) => void | Promise<unknown>;
|
|
12
19
|
};
|
|
13
|
-
export declare function ChatThread({ messages, onLoadOlder, loadingOlder, label, now, }: ChatThreadProps): import("react").JSX.Element;
|
|
20
|
+
export declare function ChatThread({ messages, onLoadOlder, loadingOlder, label, now, onOpenFile, onDownloadFile, }: ChatThreadProps): import("react").JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FileList } from "../attachments/FileList.js";
|
|
3
4
|
import { dayLabel, groupByDay, startsRun, } from "./model.js";
|
|
4
5
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
6
|
import { Button } from "../../primitives/button/Button.js";
|
|
@@ -33,7 +34,7 @@ import { useLayoutEffect, useRef, useState } from "react";
|
|
|
33
34
|
* ==================================================================== */
|
|
34
35
|
/** How close to the bottom still counts as «at the bottom», in pixels. */
|
|
35
36
|
const AT_BOTTOM = 48;
|
|
36
|
-
export function ChatThread({ messages, onLoadOlder, loadingOlder = false, label, now, }) {
|
|
37
|
+
export function ChatThread({ messages, onLoadOlder, loadingOlder = false, label, now, onOpenFile, onDownloadFile, }) {
|
|
37
38
|
const copy = useUiCopy();
|
|
38
39
|
const scroller = useRef(null);
|
|
39
40
|
/* A ref, not state: the scroll handler writes it on every frame and nothing
|
|
@@ -67,10 +68,14 @@ export function ChatThread({ messages, onLoadOlder, loadingOlder = false, label,
|
|
|
67
68
|
const words = { today: copy.chat.today, yesterday: copy.chat.yesterday };
|
|
68
69
|
return (_jsxs("div", { className: "relative flex min-h-0 flex-1 flex-col", children: [_jsxs("div", { ref: scroller, role: "log",
|
|
69
70
|
/* A scrollable region is reachable by keyboard (axe): the arrows scroll it. */
|
|
70
|
-
tabIndex: 0, "aria-label": label ?? copy.chat.thread, "aria-live": "polite", onScroll: onScroll, className: "flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-5 py-4", children: [onLoadOlder === undefined ? null : (_jsx("div", { className: "flex justify-center pb-3", children: _jsx(Button, { role: "ghost", size: "sm", disabled: loadingOlder, onClick: onLoadOlder, children: loadingOlder ? copy.chat.loadingOlder : copy.chat.loadOlder }) })), messages.length === 0 ? _jsx(Empty, { sentence: copy.chat.empty }) : null, groups.map((group) => (_jsxs("section", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "my-3 flex justify-center", children: _jsx("span", { className: "rounded-control border border-line bg-surface px-3 py-0.5 text-micro font-medium text-muted", children: dayLabel(group.day, clock, words, copy.locale) }) }), group.messages.map((message, index) => (_jsx(Bubble, { message: message, first: startsRun(group.messages, index), locale: copy.locale }, message.id)))] }, group.key)))] }), showJump ? (_jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-3 flex justify-center", children: _jsx("div", { className: "pointer-events-auto", children: _jsx(Button, { role: "secondary", size: "sm", onClick: toLatest, children: copy.chat.jumpLatest }) }) })) : null] }));
|
|
71
|
+
tabIndex: 0, "aria-label": label ?? copy.chat.thread, "aria-live": "polite", onScroll: onScroll, className: "flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-5 py-4", children: [onLoadOlder === undefined ? null : (_jsx("div", { className: "flex justify-center pb-3", children: _jsx(Button, { role: "ghost", size: "sm", disabled: loadingOlder, onClick: onLoadOlder, children: loadingOlder ? copy.chat.loadingOlder : copy.chat.loadOlder }) })), messages.length === 0 ? _jsx(Empty, { sentence: copy.chat.empty }) : null, groups.map((group) => (_jsxs("section", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "my-3 flex justify-center", children: _jsx("span", { className: "rounded-control border border-line bg-surface px-3 py-0.5 text-micro font-medium text-muted", children: dayLabel(group.day, clock, words, copy.locale) }) }), group.messages.map((message, index) => (_jsx(Bubble, { message: message, first: startsRun(group.messages, index), locale: copy.locale, onOpenFile: onOpenFile, onDownloadFile: onDownloadFile }, message.id)))] }, group.key)))] }), showJump ? (_jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-3 flex justify-center", children: _jsx("div", { className: "pointer-events-auto", children: _jsx(Button, { role: "secondary", size: "sm", onClick: toLatest, children: copy.chat.jumpLatest }) }) })) : null] }));
|
|
71
72
|
}
|
|
72
|
-
function Bubble({ message, first, locale, }) {
|
|
73
|
+
function Bubble({ message, first, locale, onOpenFile, onDownloadFile, }) {
|
|
73
74
|
const copy = useUiCopy();
|
|
74
75
|
const time = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).format(message.at);
|
|
75
|
-
return (_jsx("div", { className: `flex ${message.mine ? "justify-end" : "justify-start"} ${first ? "mt-2" : ""}`, children: _jsxs("div", { className: `max-w-prose rounded-control border px-3 py-2 ${message.mine ? "border-primary/30 bg-primary/10" : "border-line bg-surface"} ${message.pending === true ? "
|
|
76
|
+
return (_jsx("div", { className: `flex ${message.mine ? "justify-end" : "justify-start"} ${first ? "mt-2" : ""}`, children: _jsxs("div", { className: `max-w-prose rounded-control border px-3 py-2 ${message.mine ? "border-primary/30 bg-primary/10" : "border-line bg-surface"} ${message.pending === true ? "border-dashed" : ""}`, children: [first && !message.mine ? (_jsx("p", { className: "text-meta font-medium text-muted", children: message.author })) : null, message.body === "" ? null : (_jsx("p", { className: "text-body break-words whitespace-pre-wrap text-ink", children: message.body })), message.files === undefined ? null : (_jsx("div", { className: "mt-1.5", children: _jsx(FileList, { files: message.files, ...(onOpenFile === undefined
|
|
77
|
+
? {}
|
|
78
|
+
: { onOpen: (file) => onOpenFile(file, message) }), ...(onDownloadFile === undefined
|
|
79
|
+
? {}
|
|
80
|
+
: { onDownload: (file) => onDownloadFile(file, message) }) }) })), _jsxs("p", { className: "mt-1 text-micro text-muted", children: [_jsx("time", { dateTime: message.at.toISOString(), children: time }), message.pending === true ? ` · ${copy.chat.sending}` : null] })] }) }));
|
|
76
81
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttachmentFile } from "../attachments/files.js";
|
|
1
2
|
export type ChatMessage = {
|
|
2
3
|
id: string;
|
|
3
4
|
/** Who wrote it, as the screen names them: «Ana Ruiz». */
|
|
@@ -9,6 +10,9 @@ export type ChatMessage = {
|
|
|
9
10
|
mine?: boolean;
|
|
10
11
|
/** Sent but not yet confirmed by the server. Said, never a silent success. */
|
|
11
12
|
pending?: boolean;
|
|
13
|
+
/** The files it carries, drawn under the text as cards (`FileList`). A message may be
|
|
14
|
+
* only its files: then `body` is empty. One still uploading says so with its progress. */
|
|
15
|
+
files?: readonly AttachmentFile[];
|
|
12
16
|
};
|
|
13
17
|
export type DayGroup = {
|
|
14
18
|
/** `YYYY-MM-DD` in local time: a stable key, and the day's identity. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "@sincpro/web-ui/components/gantt/gantt.css";
|
|
1
2
|
/** A dependency between two records: «B starts when A ends» (`e2s`, the usual one). */
|
|
2
3
|
export type GanttLink = {
|
|
3
4
|
id: string;
|
|
@@ -35,7 +36,14 @@ export type RecordGanttProps<T> = {
|
|
|
35
36
|
* Records on a timeline — Odoo's Gantt view: projects, tasks, manufacturing orders.
|
|
36
37
|
*
|
|
37
38
|
* Context: drawn by SVAR React Gantt (MIT core: move, resize, progress, dependencies, zoom),
|
|
38
|
-
* dressed by `
|
|
39
|
+
* dressed by `gantt.css` — SVAR's stylesheet and its Willow theme's `--wx-*` variables pointed
|
|
40
|
+
* at web-ui's tokens —, imported here so it travels in the Gantt's chunk.
|
|
41
|
+
*
|
|
42
|
+
* The chart is drawn in the browser only: SVAR paints its grid with a canvas, which a server
|
|
43
|
+
* does not have, so a server-rendered chart (Next.js) would not match the browser's first
|
|
44
|
+
* render. The server — and the hydrating pass — draw the skeleton; the chart comes right
|
|
45
|
+
* after. An SPA, which does not hydrate, draws the chart at once.
|
|
46
|
+
*
|
|
39
47
|
* The chart keeps its own state while dragging; every finished change is reported (`onMove`,
|
|
40
48
|
* `onProgress`) and the app passes the saved `items` back, which the chart re-reads. Without
|
|
41
49
|
* `onMove` / `onProgress` it is read-only. Auto-scheduling, critical path and resource load are
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import "@sincpro/web-ui/components/gantt/gantt.css";
|
|
3
4
|
import { TimelineToolbar } from "../timeline/TimelineToolbar.js";
|
|
4
5
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
6
|
+
import { Skeleton } from "../../primitives/notice/Notice.js";
|
|
5
7
|
import { Gantt, Willow } from "@svar-ui/react-gantt";
|
|
6
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
9
|
+
/* Nothing to listen to: the answer («is this a browser?») never changes after the first
|
|
10
|
+
render. Only the hydrating pass reads the server's `false`. */
|
|
11
|
+
const subscribe = () => () => { };
|
|
7
12
|
/* The two rows of the time scale per zoom, written with `Intl` in the system's language
|
|
8
13
|
(SVAR's own format strings would ignore it), and how wide one cell of the finer row is. */
|
|
9
14
|
function scalesOf(zoom, locale) {
|
|
@@ -40,7 +45,14 @@ function scalesOf(zoom, locale) {
|
|
|
40
45
|
* Records on a timeline — Odoo's Gantt view: projects, tasks, manufacturing orders.
|
|
41
46
|
*
|
|
42
47
|
* Context: drawn by SVAR React Gantt (MIT core: move, resize, progress, dependencies, zoom),
|
|
43
|
-
* dressed by `
|
|
48
|
+
* dressed by `gantt.css` — SVAR's stylesheet and its Willow theme's `--wx-*` variables pointed
|
|
49
|
+
* at web-ui's tokens —, imported here so it travels in the Gantt's chunk.
|
|
50
|
+
*
|
|
51
|
+
* The chart is drawn in the browser only: SVAR paints its grid with a canvas, which a server
|
|
52
|
+
* does not have, so a server-rendered chart (Next.js) would not match the browser's first
|
|
53
|
+
* render. The server — and the hydrating pass — draw the skeleton; the chart comes right
|
|
54
|
+
* after. An SPA, which does not hydrate, draws the chart at once.
|
|
55
|
+
*
|
|
44
56
|
* The chart keeps its own state while dragging; every finished change is reported (`onMove`,
|
|
45
57
|
* `onProgress`) and the app passes the saved `items` back, which the chart re-reads. Without
|
|
46
58
|
* `onMove` / `onProgress` it is read-only. Auto-scheduling, critical path and resource load are
|
|
@@ -77,6 +89,7 @@ export function RecordGantt({ items, keyOf, titleOf, startOf, endOf, progressOf,
|
|
|
77
89
|
};
|
|
78
90
|
});
|
|
79
91
|
const editable = onMove !== undefined || onProgress !== undefined;
|
|
92
|
+
const inBrowser = useSyncExternalStore(subscribe, () => true, () => false);
|
|
80
93
|
/* The chart reports through its store's actions: `update-task` for a move, a stretch or the
|
|
81
94
|
progress handle — the finished one, not every pixel of the drag (`inProgress`). */
|
|
82
95
|
const init = (api) => {
|
|
@@ -106,5 +119,5 @@ export function RecordGantt({ items, keyOf, titleOf, startOf, endOf, progressOf,
|
|
|
106
119
|
void root.current?.requestFullscreen?.();
|
|
107
120
|
else if (document.fullscreenElement !== null)
|
|
108
121
|
void document.exitFullscreen();
|
|
109
|
-
} }), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(Willow, { fonts: false, children: _jsx(Gantt, { tasks: tasks, links: links.map((link) => ({ ...link, type: link.type ?? "e2s" })), scales: time.scales, cellWidth: cellWidth, readonly: !editable, columns: [{ id: "text", header: nameHeader ?? "", width: 260 }], init: init }) }) })] }));
|
|
122
|
+
} }), _jsx("div", { className: "min-h-0 flex-1", children: inBrowser ? (_jsx(Willow, { fonts: false, children: _jsx(Gantt, { tasks: tasks, links: links.map((link) => ({ ...link, type: link.type ?? "e2s" })), scales: time.scales, cellWidth: cellWidth, readonly: !editable, columns: [{ id: "text", header: nameHeader ?? "", width: 260 }], init: init }) })) : (_jsx(Skeleton, { label: copy.failed.loading })) })] }));
|
|
110
123
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* ====================================================================
|
|
2
|
+
* THE RECORD GANTT (SVAR, Willow theme) in these tokens.
|
|
3
|
+
*
|
|
4
|
+
* Context: SVAR's stylesheet (~160 KB, Willow included), then its variables pointed at
|
|
5
|
+
* web-ui's tokens. It comes with `RecordGantt` — imported by the component, not by
|
|
6
|
+
* `tokens.css` — so it travels in the Gantt's chunk: a screen that never opens a Gantt never
|
|
7
|
+
* downloads it.
|
|
8
|
+
*
|
|
9
|
+
* Willow DECLARES its `--wx-*` on `.wx-willow-theme`; redeclared on the same class here, after
|
|
10
|
+
* its import in the same file, they win — whenever the chunk arrives. Bars are the navy of the
|
|
11
|
+
* system, a summary the ink, a milestone the info tone; the type is the system's. Aliases:
|
|
12
|
+
* they flip with the theme.
|
|
13
|
+
* ==================================================================== */
|
|
14
|
+
@import "@svar-ui/react-gantt/all.css";
|
|
15
|
+
|
|
16
|
+
.wx-willow-theme {
|
|
17
|
+
--wx-color-primary: var(--color-primary);
|
|
18
|
+
--wx-color-primary-selected: color-mix(in srgb, var(--color-primary) 14%, transparent);
|
|
19
|
+
--wx-color-primary-font: var(--color-surface);
|
|
20
|
+
--wx-color-secondary-hover: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
|
21
|
+
--wx-color-success: var(--color-good);
|
|
22
|
+
--wx-color-warning: var(--color-warn);
|
|
23
|
+
--wx-color-info: var(--color-info);
|
|
24
|
+
--wx-color-danger: var(--color-danger);
|
|
25
|
+
--wx-color-font: var(--color-ink);
|
|
26
|
+
--wx-color-font-alt: var(--color-muted);
|
|
27
|
+
--wx-background: var(--color-surface);
|
|
28
|
+
--wx-background-alt: var(--color-ground);
|
|
29
|
+
--wx-background-hover: color-mix(in srgb, var(--color-ink) 5%, transparent);
|
|
30
|
+
--wx-font-family: inherit;
|
|
31
|
+
--wx-font-size: var(--text-meta);
|
|
32
|
+
--wx-font-size-sm: var(--text-micro);
|
|
33
|
+
--wx-icon-color: var(--color-muted);
|
|
34
|
+
--wx-border-color: var(--color-line);
|
|
35
|
+
--wx-border-radius: var(--radius-control);
|
|
36
|
+
--wx-radius-major: var(--radius-box);
|
|
37
|
+
--wx-gantt-border-color: var(--color-line);
|
|
38
|
+
--wx-gantt-task-color: var(--color-primary);
|
|
39
|
+
--wx-gantt-task-fill-color: var(--color-primary-hover);
|
|
40
|
+
--wx-gantt-task-border-color: var(--color-primary-hover);
|
|
41
|
+
--wx-gantt-task-font-color: var(--color-surface);
|
|
42
|
+
--wx-gantt-summary-color: var(--color-line-strong);
|
|
43
|
+
--wx-gantt-summary-fill-color: color-mix(in srgb, var(--color-ink) 45%, transparent);
|
|
44
|
+
--wx-gantt-summary-border-color: var(--color-line-strong);
|
|
45
|
+
--wx-gantt-summary-font-color: var(--color-ink);
|
|
46
|
+
--wx-gantt-milestone-color: var(--color-info);
|
|
47
|
+
--wx-gantt-select-color: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
|
48
|
+
--wx-gantt-link-color: var(--color-muted);
|
|
49
|
+
--wx-gantt-link-color-hovered: var(--color-ink);
|
|
50
|
+
--wx-gantt-holiday-background: var(--color-ground);
|
|
51
|
+
--wx-gantt-holiday-color: var(--color-muted);
|
|
52
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type ValueEditor } from "./context.js";
|
|
1
2
|
import type { BuiltFilter } from "./criteria.js";
|
|
2
3
|
import { type ModelDefinition } from "./model.js";
|
|
4
|
+
import type { SearchRecords } from "./records.js";
|
|
3
5
|
export interface BuiltSort {
|
|
4
6
|
field: string;
|
|
5
7
|
descending?: boolean;
|
|
@@ -53,10 +55,15 @@ export interface BuiltCriteria {
|
|
|
53
55
|
grouping?: BuiltGrouping;
|
|
54
56
|
specification?: Record<string, Record<string, never>>;
|
|
55
57
|
}
|
|
56
|
-
export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }: {
|
|
58
|
+
export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, searchRecords: ownSearchRecords, valueEditor: ownValueEditor, }: {
|
|
57
59
|
model: ModelDefinition;
|
|
58
60
|
/** The criteria that was already set. Reopening has to continue where it was left. */
|
|
59
61
|
initial?: BuiltCriteria;
|
|
62
|
+
/** Searches the records of a relation: a rule can then be about a relation itself, its
|
|
63
|
+
* records picked by name (see `records.ts`). Absent, the `SearchProvider`'s. */
|
|
64
|
+
searchRecords?: SearchRecords;
|
|
65
|
+
/** The application's own value controls (see `ValueEditor`). Absent, the provider's. */
|
|
66
|
+
valueEditor?: ValueEditor;
|
|
60
67
|
/**
|
|
61
68
|
* The condition's field to show first: the chip somebody
|
|
62
69
|
* touched in the bar.
|
|
@@ -66,6 +73,8 @@ export declare function CriteriaBuilder({ model, initial, focus, onApply, onCanc
|
|
|
66
73
|
* edit the wrong one.
|
|
67
74
|
*/
|
|
68
75
|
focus?: string;
|
|
69
|
-
|
|
76
|
+
/** The criteria applied, and how its filter reads —with the names of the records chosen—
|
|
77
|
+
* for the chip that shows it. */
|
|
78
|
+
onApply: (criteria: BuiltCriteria | undefined, said?: string) => void;
|
|
70
79
|
onCancel?: () => void;
|
|
71
80
|
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useSearchSettings, } from "./context.js";
|
|
4
|
+
import { blankGroup, describeFilter, ExpressionView, liftRecords, namesOf, SelectionTree, treeFromFilter, treeToFilter, useRecordNames, } from "./FilterBuilder.js";
|
|
4
5
|
import { LazyJsonEditor } from "./LazyJsonEditor.js";
|
|
5
6
|
import { filterableNames, } from "./model.js";
|
|
6
7
|
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
@@ -71,14 +72,26 @@ function nextGrain(grain) {
|
|
|
71
72
|
const at = GRAINS.indexOf(grain ?? null);
|
|
72
73
|
return GRAINS[(at + 1) % GRAINS.length] ?? null;
|
|
73
74
|
}
|
|
74
|
-
export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
75
|
+
export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, searchRecords: ownSearchRecords, valueEditor: ownValueEditor, }) {
|
|
75
76
|
const surface = useSurface();
|
|
77
|
+
const settings = useSearchSettings({
|
|
78
|
+
...(ownSearchRecords === undefined ? {} : { searchRecords: ownSearchRecords }),
|
|
79
|
+
...(ownValueEditor === undefined ? {} : { valueEditor: ownValueEditor }),
|
|
80
|
+
});
|
|
81
|
+
/* A filter read back carries keys; with records searchable, the rules about records are
|
|
82
|
+
drawn as such again — by name. */
|
|
83
|
+
const read = (filter) => {
|
|
84
|
+
const node = treeFromFilter(filter);
|
|
85
|
+
return node === null || settings.searchRecords === undefined
|
|
86
|
+
? node
|
|
87
|
+
: liftRecords(node, model);
|
|
88
|
+
};
|
|
76
89
|
const names = Object.keys(model.fields).sort();
|
|
77
90
|
/* Never a relational nor a value-object: neither has a comparison of its own
|
|
78
91
|
(empty `ops`), so neither serves as a target for a filter, an order or a level. */
|
|
79
92
|
const scalarNames = filterableNames(model);
|
|
80
93
|
const sortable = names.filter((name) => model.fields[name]?.sortable === true);
|
|
81
|
-
const decomposed = initial?.selection === undefined ? null :
|
|
94
|
+
const decomposed = initial?.selection === undefined ? null : read(initial.selection);
|
|
82
95
|
const [tree, setTree] = useState(() => decomposed !== null && decomposed.kind === "group"
|
|
83
96
|
? decomposed
|
|
84
97
|
: decomposed !== null
|
|
@@ -110,6 +123,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
110
123
|
const [fields, setFields] = useState(Object.keys(initial?.specification ?? {}));
|
|
111
124
|
const [rawText, setRawText] = useState(() => initial === undefined ? "" : JSON.stringify(initial, null, 2));
|
|
112
125
|
const [rawError, setRawError] = useState(null);
|
|
126
|
+
useRecordNames(tree, settings.searchRecords, (named) => setTree((current) => named(current)));
|
|
113
127
|
/** What the controls say, together: it is what is applied and what the JSON shows. */
|
|
114
128
|
function assemble(next) {
|
|
115
129
|
const selection = next.locked ?? lockedSelection ?? treeToFilter(next.tree ?? tree);
|
|
@@ -187,7 +201,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
187
201
|
return;
|
|
188
202
|
}
|
|
189
203
|
setRawError(null);
|
|
190
|
-
const node = parsed.selection === undefined ? null :
|
|
204
|
+
const node = parsed.selection === undefined ? null : read(parsed.selection);
|
|
191
205
|
if (node !== null) {
|
|
192
206
|
setTree(node.kind === "group" ? node : { kind: "group", join: "all", children: [node] });
|
|
193
207
|
setLockedSelection(null);
|
|
@@ -211,7 +225,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
211
225
|
? "border-chrome-ink/20 bg-chrome text-chrome-ink"
|
|
212
226
|
: "border-ink/15 bg-surface text-ink";
|
|
213
227
|
const select = `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`;
|
|
214
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children: lockedSelection !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mb-2 text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedSelection, model: model })] })) : (_jsx(SelectionTree, { model: model, group: tree, onChange: (next) => push({ tree: next }), ...(focus === undefined ? {} : { focus }) })) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.order }), _jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1", children: [_jsx(Tags, { items: order.map((sort, index) => ({
|
|
228
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children: lockedSelection !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mb-2 text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedSelection, model: model })] })) : (_jsx(SelectionTree, { model: model, group: tree, onChange: (next) => push({ tree: next }), ...settings, ...(focus === undefined ? {} : { focus }) })) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.order }), _jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1", children: [_jsx(Tags, { items: order.map((sort, index) => ({
|
|
215
229
|
id: `${sort.field}-${index}`,
|
|
216
230
|
label: sort.field,
|
|
217
231
|
note: sort.descending === true ? "↓" : "↑",
|
|
@@ -285,5 +299,10 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
285
299
|
return (_jsx("button", { type: "button", onClick: () => push({
|
|
286
300
|
fields: chosen ? fields.filter((one) => one !== name) : [...fields, name],
|
|
287
301
|
}), className: `rounded-pill border px-2 py-0.5 text-micro ${chosen ? chosenTone("canvas") : `text-muted ${box}`}`, children: name }, name));
|
|
288
|
-
}) })] }), _jsx(LazyJsonEditor, { value: rawText, onChange: updateRaw, error: rawError, height: "14rem", label: copy.builder.json }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { role: "primary", disabled: rawError !== null, onClick: () =>
|
|
302
|
+
}) })] }), _jsx(LazyJsonEditor, { value: rawText, onChange: updateRaw, error: rawError, height: "14rem", label: copy.builder.json }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { role: "primary", disabled: rawError !== null, onClick: () => {
|
|
303
|
+
const built = rawText.trim() === "" ? undefined : JSON.parse(rawText);
|
|
304
|
+
onApply(built, built?.selection === undefined
|
|
305
|
+
? undefined
|
|
306
|
+
: describeFilter(built.selection, model, undefined, namesOf(tree)));
|
|
307
|
+
}, children: copy.builder.apply }), onCancel === undefined ? null : (_jsx(Button, { role: "ghost", onClick: onCancel, children: copy.builder.cancel }))] })] }));
|
|
289
308
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ValueEditor } from "./context.js";
|
|
2
|
+
import type { BuiltFilter, CriteriaJoin, RecordKey, RecordOption, ThroughMatch } from "./criteria.js";
|
|
2
3
|
import { type ModelDefinition } from "./model.js";
|
|
3
4
|
import { type LoadModel, type ModelCache } from "./paths.js";
|
|
5
|
+
import { type RecordTarget, type SearchRecords } from "./records.js";
|
|
4
6
|
/** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
|
|
5
7
|
* `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
|
|
6
8
|
* is not a filter this component knows how to draw, and is treated as a shape error instead of
|
|
@@ -27,6 +29,16 @@ export interface TreeCondition {
|
|
|
27
29
|
/** The other end, for the operators that compare against two —today `between`—. Empty in
|
|
28
30
|
* all the others, where it means nothing. */
|
|
29
31
|
upper?: string;
|
|
32
|
+
/** The value as it travels when it is not the text: `true`, `7`, a list read back — kept so
|
|
33
|
+
* a rule read from a filter goes back out the same, not as the string it is drawn with.
|
|
34
|
+
* Writing in the box drops it: what is written is then the value. */
|
|
35
|
+
raw?: unknown;
|
|
36
|
+
/** The values CHOSEN, with the names they are read by — records of a relation, words of an
|
|
37
|
+
* enum, «está en» a list. What travels is their `id`. */
|
|
38
|
+
values?: RecordOption[];
|
|
39
|
+
/** The rule asks about RECORDS of a relation: `field` is the relation itself, chosen by
|
|
40
|
+
* name and compared by key (`recordsFilter`). */
|
|
41
|
+
target?: RecordTarget;
|
|
30
42
|
}
|
|
31
43
|
export interface TreeGroup {
|
|
32
44
|
kind: "group";
|
|
@@ -70,6 +82,36 @@ export declare function treeToFilter(node: TreeNode): BuiltFilter | undefined;
|
|
|
70
82
|
* shows it read-only while still letting you touch it as JSON.
|
|
71
83
|
*/
|
|
72
84
|
export declare function treeFromFilter(filter: unknown): TreeNode | null;
|
|
85
|
+
/** The operators a rule about records offers: one record or several, in or out — and, through
|
|
86
|
+
* a column that admits it, «está vacío». A to-many relation is asked by some of its records
|
|
87
|
+
* or none of them. */
|
|
88
|
+
export declare function recordOps(target: RecordTarget): string[];
|
|
89
|
+
/**
|
|
90
|
+
* The rules about RECORDS of a relation, recognised again in a tree read back.
|
|
91
|
+
*
|
|
92
|
+
* A filter carries keys, never which relation they were chosen from: `customer_id in [7, 9]`
|
|
93
|
+
* is, for the tree, a column compared to two numbers. The model says that `customer_id` is
|
|
94
|
+
* how «Cliente» is compared, so the row is drawn as «Cliente es alguno de [Andrés Pérez,
|
|
95
|
+
* Andrés Gutiérrez]» — the names asked of `searchRecords` by key. The same for a to-many
|
|
96
|
+
* crossed to its key: `{through: "tags", selection: {field: "id", operator: "in", …}}` is
|
|
97
|
+
* «Etiquetas es alguno de …».
|
|
98
|
+
*
|
|
99
|
+
* in {field: "customer_id", operator: "in", value: [7, 9]} (customer_id names Cliente)
|
|
100
|
+
* out {field: "customer", target: Cliente, operator: "in", values: [#7, #9]}
|
|
101
|
+
*
|
|
102
|
+
* Only on the record's own fields: a relation of a related record needs its model, and a row
|
|
103
|
+
* that stays a plain condition still filters the same.
|
|
104
|
+
*/
|
|
105
|
+
export declare function liftRecords(node: TreeNode, model: ModelDefinition): TreeNode;
|
|
106
|
+
/** The names of the records a tree has chosen, by relation and key: what says them in a
|
|
107
|
+
* sentence (`describeFilter`) once the tree is applied. */
|
|
108
|
+
export declare function namesOf(node: TreeNode): RecordNames;
|
|
109
|
+
/**
|
|
110
|
+
* Names the records a tree read back carries only by key — ONE question per relation, for the
|
|
111
|
+
* whole tree. Per row, five rows answered at five moments and each wrote its answer over a tree
|
|
112
|
+
* that no longer had the others'. Until it answers, a record reads «#7».
|
|
113
|
+
*/
|
|
114
|
+
export declare function useRecordNames(tree: TreeNode, searchRecords: SearchRecords | undefined, apply: (named: (tree: TreeNode) => TreeNode) => void): void;
|
|
73
115
|
/** The filter said in one line, for a chip or a label.
|
|
74
116
|
*
|
|
75
117
|
* in {field: "row_count", operator: ">", value: 1000}, with the model
|
|
@@ -95,7 +137,12 @@ export declare function treeFromFilter(filter: unknown): TreeNode | null;
|
|
|
95
137
|
export declare function describeFilter(node: BuiltFilter, model?: ModelDefinition,
|
|
96
138
|
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
97
139
|
* fields of a `through`. Without it they keep their raw names. */
|
|
98
|
-
modelAt?: (path: readonly string[]) => ModelDefinition | undefined
|
|
140
|
+
modelAt?: (path: readonly string[]) => ModelDefinition | undefined,
|
|
141
|
+
/** The names of the records a filter asks for, by relation and key: «Cliente es Andrés
|
|
142
|
+
* Pérez» instead of «customer_id es 7». The builder hands its own (`namesOf`). */
|
|
143
|
+
names?: RecordNames): string;
|
|
144
|
+
/** A record's name by the relation it was chosen from and its key, when it is known. */
|
|
145
|
+
export type RecordNames = (relation: string, key: RecordKey) => string | undefined;
|
|
99
146
|
/** The filter drawn as it is, recursive: a condition is a line, `all`/`any` are a
|
|
100
147
|
* group with its label and its children inside, `negate` is «no» wrapping the one it negates.
|
|
101
148
|
*
|
|
@@ -112,11 +159,16 @@ export declare function ExpressionView({ node, model, depth, modelAt, at, }: {
|
|
|
112
159
|
/** The path up to here (through the outer `through`s). */
|
|
113
160
|
at?: readonly string[];
|
|
114
161
|
}): import("react").JSX.Element;
|
|
115
|
-
export declare function SelectionTree({ model, group, onChange, depth, focus, loadModel, models: shared, }: {
|
|
162
|
+
export declare function SelectionTree({ model, group, onChange, depth, focus, loadModel, models: shared, searchRecords: ownSearchRecords, valueEditor: ownValueEditor, }: {
|
|
116
163
|
model: ModelDefinition;
|
|
117
164
|
group: TreeGroup;
|
|
118
165
|
onChange: (next: TreeGroup) => void;
|
|
119
166
|
depth?: number;
|
|
167
|
+
/** Searches the records of a relation: with it a rule can be about a relation ITSELF,
|
|
168
|
+
* its records picked by name (see `records.ts`). Absent, the `SearchProvider`'s. */
|
|
169
|
+
searchRecords?: SearchRecords;
|
|
170
|
+
/** The application's own value controls (see `ValueEditor`). Absent, the provider's. */
|
|
171
|
+
valueEditor?: ValueEditor;
|
|
120
172
|
/**
|
|
121
173
|
* The condition's field to show FIRST: the one somebody touched in
|
|
122
174
|
* the bar.
|
|
@@ -142,7 +194,7 @@ export declare function SelectionTree({ model, group, onChange, depth, focus, lo
|
|
|
142
194
|
/** The model cache the rules share. The outer tree builds it. */
|
|
143
195
|
models?: ModelCache;
|
|
144
196
|
}): import("react").JSX.Element;
|
|
145
|
-
export declare function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }: {
|
|
197
|
+
export declare function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, searchRecords: ownSearchRecords, valueEditor: ownValueEditor, }: {
|
|
146
198
|
model: ModelDefinition;
|
|
147
199
|
/** The model at the end of a path of relations. With this, a rule can ask about
|
|
148
200
|
* a field of a related record: «alguna línea con algún impuesto con monto > 10».
|
|
@@ -154,6 +206,12 @@ export declare function FilterBuilder({ model, initial, onApply, onCancel, loadM
|
|
|
154
206
|
/** The filter that was already set, if there was one. Reopening the builder with this inside
|
|
155
207
|
* has to continue where it was left, not start blank. */
|
|
156
208
|
initial?: BuiltFilter;
|
|
157
|
-
|
|
209
|
+
/** The filter applied, and how it reads —with the names of the records chosen, «Cliente es
|
|
210
|
+
* Andrés Pérez»— for the chip that shows it. */
|
|
211
|
+
onApply: (selection: BuiltFilter | undefined, said?: string) => void;
|
|
158
212
|
onCancel?: () => void;
|
|
213
|
+
/** Searches the records of a relation (see `records.ts`). Absent, the `SearchProvider`'s. */
|
|
214
|
+
searchRecords?: SearchRecords;
|
|
215
|
+
/** The application's own value controls (see `ValueEditor`). Absent, the provider's. */
|
|
216
|
+
valueEditor?: ValueEditor;
|
|
159
217
|
}): import("react").JSX.Element;
|