@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.
Files changed (52) hide show
  1. package/README.md +97 -7
  2. package/dist/components/activity/Activity.d.ts +8 -1
  3. package/dist/components/activity/Activity.js +9 -4
  4. package/dist/components/activity/Messages.d.ts +4 -0
  5. package/dist/components/attachments/Attachments.d.ts +1 -28
  6. package/dist/components/attachments/Attachments.js +5 -24
  7. package/dist/components/attachments/FileList.d.ts +28 -0
  8. package/dist/components/attachments/FileList.js +91 -0
  9. package/dist/components/attachments/FileThumb.d.ts +13 -0
  10. package/dist/components/attachments/FileThumb.js +34 -0
  11. package/dist/components/attachments/download.d.ts +9 -0
  12. package/dist/components/attachments/download.js +36 -0
  13. package/dist/components/attachments/files.d.ts +28 -0
  14. package/dist/components/attachments/index.d.ts +4 -2
  15. package/dist/components/attachments/index.js +4 -1
  16. package/dist/components/calendar/RecordCalendar.d.ts +2 -1
  17. package/dist/components/calendar/RecordCalendar.js +4 -1
  18. package/dist/components/calendar/calendar.css +37 -0
  19. package/dist/components/chat/ChatThread.d.ts +8 -1
  20. package/dist/components/chat/ChatThread.js +9 -4
  21. package/dist/components/chat/model.d.ts +4 -0
  22. package/dist/components/gantt/RecordGantt.d.ts +9 -1
  23. package/dist/components/gantt/RecordGantt.js +16 -3
  24. package/dist/components/gantt/gantt.css +52 -0
  25. package/dist/components/search/CriteriaBuilder.d.ts +11 -2
  26. package/dist/components/search/CriteriaBuilder.js +25 -6
  27. package/dist/components/search/FilterBuilder.d.ts +63 -5
  28. package/dist/components/search/FilterBuilder.js +346 -50
  29. package/dist/components/search/RuleValue.d.ts +17 -0
  30. package/dist/components/search/RuleValue.js +121 -0
  31. package/dist/components/search/SearchBar.d.ts +25 -2
  32. package/dist/components/search/SearchBar.js +360 -39
  33. package/dist/components/search/context.d.ts +45 -0
  34. package/dist/components/search/context.js +25 -0
  35. package/dist/components/search/criteria.d.ts +20 -0
  36. package/dist/components/search/index.d.ts +7 -4
  37. package/dist/components/search/index.js +9 -3
  38. package/dist/components/search/model.d.ts +16 -1
  39. package/dist/components/search/model.js +5 -0
  40. package/dist/components/search/query.d.ts +88 -4
  41. package/dist/components/search/query.js +262 -62
  42. package/dist/components/search/records.d.ts +68 -0
  43. package/dist/components/search/records.js +115 -0
  44. package/dist/foundations/copy.d.ts +27 -0
  45. package/dist/foundations/copy.es.js +15 -0
  46. package/dist/foundations/copy.js +15 -0
  47. package/dist/primitives/button/Button.d.ts +5 -1
  48. package/dist/primitives/button/Button.js +9 -2
  49. package/dist/primitives/value/Markdown.d.ts +1 -0
  50. package/dist/primitives/value/Markdown.js +1 -0
  51. package/dist/tokens.css +6 -85
  52. package/package.json +1 -1
@@ -0,0 +1,121 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { choiceLabel } from "./model.js";
4
+ import { useUiCopy } from "../../foundations/copy.js";
5
+ import { Picker } from "../../primitives/picker/Picker.js";
6
+ import { TagsField } from "../../primitives/picker/TagsField.js";
7
+ import { useEffect, useState } from "react";
8
+ /* ==================================================================== *
9
+ * THE VALUE OF A RULE — written when it is written, CHOSEN when it is chosen.
10
+ *
11
+ * Context: the builder asked every value in a text box, so «Cliente es …» wanted an id
12
+ * nobody knows and «Estado es …» a raw value («paid») nobody reads. The control now follows
13
+ * the field and the comparison:
14
+ *
15
+ * a relation es / no es one record, picked by name (Picker)
16
+ * está en / no … several, as tags (TagsField)
17
+ * an enum es / no es its words (select)
18
+ * está en / no … several of its words (TagsField)
19
+ * yes / no es sí · no (select)
20
+ * anything else what is typed (input)
21
+ *
22
+ * What is read is the name; what travels is the key — `values` keeps both. An application
23
+ * that wants a field drawn its own way answers it from `valueEditor` before any of this.
24
+ * ==================================================================== */
25
+ /** The comparisons that take several values. */
26
+ export function takesMany(operator) {
27
+ return operator === "in" || operator === "not in";
28
+ }
29
+ /** How long the control waits for the typing to stop before asking. */
30
+ const DELAY = 200;
31
+ /**
32
+ * The records of a relation as a control's options: asked of the application's search as
33
+ * the person types, the older question cancelled. It asks nothing until the list is opened —
34
+ * a filter with five rules does not fetch five lists nobody looks at.
35
+ */
36
+ function useRecordOptions(search, target, path) {
37
+ const [text, setText] = useState(null);
38
+ const [found, setFound] = useState({
39
+ loading: false,
40
+ options: [],
41
+ });
42
+ const key = target === undefined || text === null ? "" : `${path.join(".")}\u0000${text}`;
43
+ useEffect(() => {
44
+ if (search === undefined || target === undefined || text === null)
45
+ return;
46
+ const controller = new AbortController();
47
+ setFound((before) => ({ loading: true, options: before.options }));
48
+ const timer = window.setTimeout(() => {
49
+ search({ relation: target.relation, path, text, signal: controller.signal }).then((options) => {
50
+ if (!controller.signal.aborted)
51
+ setFound({ loading: false, options: [...options] });
52
+ }, () => {
53
+ if (!controller.signal.aborted)
54
+ setFound({ loading: false, options: [] });
55
+ });
56
+ }, DELAY);
57
+ return () => {
58
+ window.clearTimeout(timer);
59
+ controller.abort();
60
+ };
61
+ // Asked again only when WHAT is searched changes.
62
+ // eslint-disable-next-line react-hooks/exhaustive-deps
63
+ }, [key]);
64
+ return { ...found, search: (next) => setText(next) };
65
+ }
66
+ /** A relation's records: one, picked by name, or several as tags. */
67
+ function RecordValue({ props, target, searchRecords, }) {
68
+ const { values, onValues, path, operator, label } = props;
69
+ const found = useRecordOptions(searchRecords, target, path);
70
+ /* A record read back has no name until the builder asks for it (`useRecordNames`). */
71
+ const shown = (one) => (one.name === "" ? `#${one.id}` : one.name);
72
+ if (takesMany(operator)) {
73
+ const known = new Map();
74
+ for (const one of [...values, ...found.options])
75
+ known.set(String(one.id), one);
76
+ return (_jsx("span", { className: "min-w-0 flex-1 basis-56", children: _jsx(TagsField, { mode: "edit", "aria-label": label, value: values.map((one) => String(one.id)), options: [...known.values()].map((one) => ({
77
+ value: String(one.id),
78
+ label: shown(one),
79
+ ...(one.meta === undefined ? {} : { meta: one.meta }),
80
+ })), onSearch: found.search, onChange: (next) => onValues(next
81
+ .map((id) => known.get(id))
82
+ .filter((one) => one !== undefined)) }) }));
83
+ }
84
+ const chosen = values[0];
85
+ return (_jsx("span", { className: "min-w-0 flex-1 basis-56", children: _jsx(Picker, { mode: "edit", "aria-label": label, items: found.options.map((one) => ({
86
+ id: String(one.id),
87
+ name: one.name,
88
+ ...(one.meta === undefined ? {} : { meta: one.meta }),
89
+ })), loading: found.loading && found.options.length === 0, ...(chosen === undefined
90
+ ? {}
91
+ : { value: String(chosen.id), valueLabel: shown(chosen) }), onSearch: found.search, onChange: (id) => {
92
+ const one = found.options.find((each) => String(each.id) === id);
93
+ if (one !== undefined)
94
+ onValues([one]);
95
+ }, onClear: () => onValues([]) }) }));
96
+ }
97
+ /**
98
+ * The builder's own value control for a rule — what is drawn when the application's
99
+ * `valueEditor` does not answer for the field.
100
+ */
101
+ export function RuleValue({ props, target, searchRecords, box, inputType, }) {
102
+ const copy = useUiCopy();
103
+ const { field, name, model, operator, value, onValue, values, onValues, label } = props;
104
+ if (target !== undefined && searchRecords !== undefined) {
105
+ return _jsx(RecordValue, { props: props, target: target, searchRecords: searchRecords });
106
+ }
107
+ const choices = (field.choices ?? []).map((one) => String(one));
108
+ const word = (one) => model === undefined ? one : choiceLabel(model, name, one, copy.locale);
109
+ if (choices.length > 0 && takesMany(operator)) {
110
+ return (_jsx("span", { className: "min-w-0 flex-1 basis-56", children: _jsx(TagsField, { mode: "edit", "aria-label": label, value: values.map((one) => String(one.id)), options: choices.map((one) => ({ value: one, label: word(one) })), onChange: (next) => onValues(next.map((one) => ({ id: one, name: word(one) }))) }) }));
111
+ }
112
+ if (choices.length > 0) {
113
+ return (_jsxs("select", { "aria-label": label, value: value, onChange: (event) => onValue(event.target.value), className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`, children: [_jsx("option", { value: "", children: copy.builder.chooseValue }), choices.map((one) => (_jsx("option", { value: one, children: word(one) }, one)))] }));
114
+ }
115
+ const type = field.type.toLowerCase();
116
+ if (type === "boolean" || type === "bool") {
117
+ /* Sí / no travel as what they are —`true`, `false`—, not as the words. */
118
+ return (_jsxs("select", { "aria-label": label, value: props.raw === true ? "true" : props.raw === false ? "false" : "", onChange: (event) => props.onRaw(event.target.value === "" ? undefined : event.target.value === "true"), className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`, children: [_jsx("option", { value: "", children: copy.builder.chooseValue }), _jsx("option", { value: "true", children: copy.table.yes }), _jsx("option", { value: "false", children: copy.table.no })] }));
119
+ }
120
+ return (_jsx("input", { "aria-label": label, type: inputType, value: value, onChange: (event) => onValue(event.target.value), placeholder: copy.builder.value, className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}` }));
121
+ }
@@ -1,5 +1,7 @@
1
- import { type BuiltCondition, type BuiltFilter, type CriteriaJoin, type CriteriaPath, type SearchCriteria } from "./criteria.js";
1
+ import { type BuiltCondition, type BuiltFilter, type CriteriaJoin, type CriteriaPath, type RecordOption, type SearchCriteria } from "./criteria.js";
2
2
  import type { ModelDefinition } from "./model.js";
3
+ import { type QueryField } from "./query.js";
4
+ import type { SearchRecords } from "./records.js";
3
5
  import type { Surface } from "../../foundations/types.js";
4
6
  import type { MenuGroup } from "../../primitives/menu/Menu.js";
5
7
  import { type ReactNode } from "react";
@@ -80,6 +82,27 @@ export type SearchBarProps = {
80
82
  * enum's value, a number a numeric field answers): then that goes first and this after it.
81
83
  */
82
84
  literal?: (text: string) => BuiltCondition | BuiltFilter | null;
85
+ /**
86
+ * Searches the records of a relation — the application's, the SAME function the builder
87
+ * takes (see `records.ts`). With it a relation's row unfolds (▸, or →) into the records that
88
+ * match what was typed, and choosing one filters by THAT record, sent by its key and read by
89
+ * its name: «Cliente: Andrés Pérez». A second one of the same relation lands in the same chip
90
+ * — «… o Andrés Gutiérrez». A relation that cannot compare a text (its foreign key, a
91
+ * many2many) is offered only this way; `#cliente` goes straight to its records.
92
+ *
93
+ * Absent, the one of the nearest `SearchProvider`.
94
+ */
95
+ searchRecords?: SearchRecords;
96
+ /** «Buscar más…» under an unfolded relation's records: the chooser with the whole list
97
+ * (`api.pick` + `List onChoose`), on what was typed. What is chosen there, the application
98
+ * puts with `withValue(criteria, field, record)`. */
99
+ onBrowseRecords?: (field: QueryField, text: string) => void;
100
+ /** How a record found reads in the dropdown — a face, a NIT, a balance —, for one that does
101
+ * not fit «name + meta». The row around it stays the bar's: keys, focus, choosing. */
102
+ renderRecord?: (record: RecordOption, state: {
103
+ field: QueryField;
104
+ query: string;
105
+ }) => ReactNode;
83
106
  /** What goes stuck to the field, on its right. */
84
107
  trailing?: ReactNode;
85
108
  /** How many facets the bar shows before folding the rest into «+N»; the grouping chain
@@ -88,4 +111,4 @@ export type SearchBarProps = {
88
111
  /** By default it inherits it from the surface that wraps it. */
89
112
  surface?: Surface;
90
113
  };
91
- export declare function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, trailing, collapseAfter, surface, }: SearchBarProps): import("react").JSX.Element;
114
+ export declare function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, searchRecords: ownSearchRecords, onBrowseRecords, renderRecord, trailing, collapseAfter, surface, }: SearchBarProps): import("react").JSX.Element;