@sincpro/web-framework 3.12.1 → 3.14.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 +65 -1
- package/dist/core/cache.js +11 -0
- package/dist/core/copy.d.ts +20 -0
- package/dist/core/copy.js +23 -0
- package/dist/core/edit.d.ts +3 -0
- package/dist/core/edit.js +9 -6
- package/dist/core/files.d.ts +58 -0
- package/dist/core/files.js +57 -15
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +5 -3
- package/dist/core/present.d.ts +16 -0
- package/dist/core/present.js +41 -4
- package/dist/core/reorder.d.ts +59 -0
- package/dist/core/reorder.js +106 -0
- package/dist/core/richText.d.ts +39 -0
- package/dist/core/richText.js +45 -0
- package/dist/core/summary.js +5 -1
- package/dist/errors/index.d.ts +3 -1
- package/dist/errors/index.js +14 -2
- package/dist/errors/narrowed.d.ts +2 -0
- package/dist/errors/narrowed.js +7 -0
- package/dist/errors/server.js +1 -7
- package/dist/react/context.d.ts +20 -1
- package/dist/react/context.js +11 -4
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/react/useTextOf.d.ts +3 -2
- package/dist/react/useTextOf.js +4 -4
- package/dist/react/useUpload.d.ts +33 -0
- package/dist/react/useUpload.js +69 -0
- package/dist/telemetry/index.d.ts +21 -1
- package/dist/telemetry/index.js +35 -1
- package/dist/web/index.d.ts +6 -1
- package/dist/web/index.js +6 -1
- package/dist/web/list/EntityList.js +11 -5
- package/dist/web/list/reorder.d.ts +31 -0
- package/dist/web/list/reorder.js +67 -0
- package/dist/web/record/ActionButton.d.ts +1 -1
- package/dist/web/record/ActionButton.js +7 -2
- package/dist/web/record/ask.d.ts +18 -0
- package/dist/web/record/ask.js +15 -0
- package/dist/web/record/choice.d.ts +32 -0
- package/dist/web/record/choice.js +36 -0
- package/dist/web/record/control.d.ts +4 -0
- package/dist/web/record/control.js +52 -1
- package/dist/web/record/edit.js +37 -5
- package/dist/web/record/fileControl.d.ts +22 -0
- package/dist/web/record/fileControl.js +48 -0
- package/dist/web/record/person.d.ts +23 -0
- package/dist/web/record/person.js +27 -0
- package/dist/web/record/record.js +8 -2
- package/dist/web/record/richText.d.ts +27 -0
- package/dist/web/record/richText.js +59 -0
- package/dist/web/workspace/SincproApp.d.ts +10 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/package.json +5 -5
package/dist/web/index.d.ts
CHANGED
|
@@ -12,21 +12,26 @@ export { OpenInMenu } from "./list/openIn.js";
|
|
|
12
12
|
export { pivotOf } from "./list/pivot.js";
|
|
13
13
|
export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, type TileLook, tonesOver, } from "./list/presentation.js";
|
|
14
14
|
export { type Choice, type Chooser, findChoices, type FrameworkReads, modelLoader, recordsBrowser, RecordsBrowserProvider, recordsSearch, refusalNotice, useLoadModel, useRecordsBrowser, useSearchRecords, } from "./list/records.js";
|
|
15
|
+
export { type Reorder, useReorder } from "./list/reorder.js";
|
|
15
16
|
export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
|
|
16
17
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
17
18
|
export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
|
|
18
|
-
export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
|
|
19
|
+
export { type AskedField, type AskField, type AskForm, askFormOf, unansweredOf, } from "./record/ask.js";
|
|
20
|
+
export { ChoiceTag, type ChoiceTagLook, choiceTagOf, } from "./record/choice.js";
|
|
19
21
|
export { type CommandActionProps, CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
20
22
|
export { RelationPicker } from "./record/control.js";
|
|
21
23
|
export { type ActionLook, type DockedAction } from "./record/dock.js";
|
|
22
24
|
export { dirtyOf, type FieldControl, RecordField, } from "./record/edit.js";
|
|
23
25
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
24
26
|
export { EntityTags } from "./record/EntityTags.js";
|
|
27
|
+
export { FileControl } from "./record/fileControl.js";
|
|
25
28
|
export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
|
|
26
29
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
30
|
+
export { isPersonEntity, PersonValue } from "./record/person.js";
|
|
27
31
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
28
32
|
export { type LifecycleDone, RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
29
33
|
export { RelatedList } from "./record/RelatedList.js";
|
|
34
|
+
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
30
35
|
export { type ServiceActionProps, ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
31
36
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
32
37
|
export { Refused } from "./Refused.js";
|
package/dist/web/index.js
CHANGED
|
@@ -12,21 +12,26 @@ export { OpenInMenu } from "./list/openIn.js";
|
|
|
12
12
|
export { pivotOf } from "./list/pivot.js";
|
|
13
13
|
export { partLookOf, presentationOf, presented, tonesOver, } from "./list/presentation.js";
|
|
14
14
|
export { findChoices, modelLoader, recordsBrowser, RecordsBrowserProvider, recordsSearch, refusalNotice, useLoadModel, useRecordsBrowser, useSearchRecords, } from "./list/records.js";
|
|
15
|
+
export { useReorder } from "./list/reorder.js";
|
|
15
16
|
export { useRowCommands, } from "./list/rowCommands.js";
|
|
16
17
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
17
18
|
export {} from "./record/ActionButton.js";
|
|
18
|
-
export { askFormOf, } from "./record/ask.js";
|
|
19
|
+
export { askFormOf, unansweredOf, } from "./record/ask.js";
|
|
20
|
+
export { ChoiceTag, choiceTagOf, } from "./record/choice.js";
|
|
19
21
|
export { CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
20
22
|
export { RelationPicker } from "./record/control.js";
|
|
21
23
|
export {} from "./record/dock.js";
|
|
22
24
|
export { dirtyOf, RecordField, } from "./record/edit.js";
|
|
23
25
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
24
26
|
export { EntityTags } from "./record/EntityTags.js";
|
|
27
|
+
export { FileControl } from "./record/fileControl.js";
|
|
25
28
|
export { RecordLinesEditor, } from "./record/lines.js";
|
|
26
29
|
export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
30
|
+
export { isPersonEntity, PersonValue } from "./record/person.js";
|
|
27
31
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
28
32
|
export { RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
29
33
|
export { RelatedList } from "./record/RelatedList.js";
|
|
34
|
+
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
30
35
|
export { ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
31
36
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
32
37
|
export { Refused } from "./Refused.js";
|
|
@@ -21,6 +21,7 @@ import { pilesOf } from "./groups.js";
|
|
|
21
21
|
import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
|
|
22
22
|
import { pivotOf } from "./pivot.js";
|
|
23
23
|
import { over, presentationOf, } from "./presentation.js";
|
|
24
|
+
import { useReorder } from "./reorder.js";
|
|
24
25
|
import { RESTORE, useRowCommands, } from "./rowCommands.js";
|
|
25
26
|
import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
|
|
26
27
|
import { Plus, RotateCcw } from "lucide-react";
|
|
@@ -448,7 +449,10 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
|
|
|
448
449
|
const rowActions = offered.length === 0 && askedRowActions === undefined
|
|
449
450
|
? undefined
|
|
450
451
|
: (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
|
|
451
|
-
|
|
452
|
+
// Rows put in their order by hand: only on the whole order, never grouped or while choosing.
|
|
453
|
+
const reorder = useReorder(listing, idOf, !grouped && !choosing);
|
|
454
|
+
const refusal = rowCommands.error ?? reorder.error;
|
|
455
|
+
const refused = refusal === null ? null : explain(refusal);
|
|
452
456
|
// The way through the set. Inside a record or a panel, only while there is more than what is
|
|
453
457
|
// on screen: «1–5 / 5» repeats the rows.
|
|
454
458
|
const fits = embedded && !partial;
|
|
@@ -460,10 +464,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
|
|
|
460
464
|
// written, an empty one too. Its parts side by side and apart: the slot does not space them,
|
|
461
465
|
// and «Totales de esta página» read glued to «1–50 / 112».
|
|
462
466
|
const paging = !pageTotals && dropped.length === 0 && through === null ? null : (_jsxs("span", { className: "flex items-center gap-3", children: [pageTotals ? _jsx("span", { className: "text-meta text-muted", children: copy.pageTotals }) : null, dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), through] }));
|
|
463
|
-
return (_jsxs(List, { items:
|
|
467
|
+
return (_jsxs(List, { items: reorder.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
|
|
464
468
|
// The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
|
|
465
469
|
// the sort menu reorders them — the same list the criteria builder writes.
|
|
466
|
-
|
|
470
|
+
// While the rows can be dragged the order shown IS their position: the table gets no column
|
|
471
|
+
// sort (web-ui turns its grip off under one), the list keeps its order as it is.
|
|
472
|
+
sort: reorder.move === undefined ? sortStates : [], ...(embedded ? {} : { sortable }), onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))), state: {
|
|
467
473
|
// Only the FIRST reading shows the skeleton. Refining (typing, a filter, the next
|
|
468
474
|
// page) keeps the rows on screen until the server answers: web-ui swaps the body for
|
|
469
475
|
// a skeleton while `loading`, and a row that vanished under the pointer lost a click.
|
|
@@ -487,7 +493,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
|
|
|
487
493
|
// Emptied (or cleared with ×): the whole set again, at once.
|
|
488
494
|
if (next === "" && listing.text !== "")
|
|
489
495
|
listing.search("", { now: true });
|
|
490
|
-
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
496
|
+
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }), ...(reorder.move === undefined ? {} : { onReorder: reorder.move }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
491
497
|
const value = row[column.id];
|
|
492
498
|
return value === null || value === undefined
|
|
493
499
|
? null
|
|
@@ -501,5 +507,5 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
|
|
|
501
507
|
measures: [],
|
|
502
508
|
meta,
|
|
503
509
|
locale,
|
|
504
|
-
}) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, views.includes("tiles") ? (_jsx(List.Tiles, { ...(tileOfRow === undefined ? {} : { card: tileOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
|
|
510
|
+
}) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, views.includes("tiles") ? (_jsx(List.Tiles, { ...(tileOfRow === undefined ? {} : { card: tileOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), reorder.elsewhere ? (_jsx(Callout, { tone: "warn", onDismiss: reorder.dismiss, children: copy.reorderElsewhere })) : null, refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
|
|
505
511
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import { type Reordering } from "../../core/reorder.js";
|
|
3
|
+
import type { Listing } from "../../react/useListing.js";
|
|
4
|
+
/**
|
|
5
|
+
* A listing's rows put in their order by hand: when they may be dragged (`reorderingOf`), the
|
|
6
|
+
* rows as the screen shows them while a move travels, and the move itself — one `Edit` of the
|
|
7
|
+
* record moved through its entity's own edit route, or one per row when its group is respaced.
|
|
8
|
+
*
|
|
9
|
+
* const reorder = useReorder(listing, idOf);
|
|
10
|
+
* <List.Table onReorder={reorder.move} /> // absent: no grip
|
|
11
|
+
*
|
|
12
|
+
* Context: the rule is `core/reorder.ts`; this only sends it. The row moves on screen at once;
|
|
13
|
+
* the list is read again when the writes are done — and also when one is refused (someone else
|
|
14
|
+
* moved it: `StaleAggregate`), so the screen goes back to what is stored and says why.
|
|
15
|
+
*/
|
|
16
|
+
export type Reorder<T> = {
|
|
17
|
+
/** Where the rows may move — `undefined`: they may not, here and now. */
|
|
18
|
+
reordering: Reordering | undefined;
|
|
19
|
+
/** The listing's rows, with a move still travelling already in its place. */
|
|
20
|
+
rows: readonly T[];
|
|
21
|
+
/** Puts `id` in front of `before` (`null`: the end). Absent while the rows cannot move. */
|
|
22
|
+
move?: (id: string, before: string | null) => void;
|
|
23
|
+
/** The last refusal of a write, until `dismiss`. */
|
|
24
|
+
error: unknown;
|
|
25
|
+
/** The last drop landed outside the row's group, and nothing was written. */
|
|
26
|
+
elsewhere: boolean;
|
|
27
|
+
dismiss: () => void;
|
|
28
|
+
};
|
|
29
|
+
export declare function useReorder<T extends AnyRecord>(listing: Listing<T>, keyOf: (row: T) => string,
|
|
30
|
+
/** `false` while the screen does not allow it (grouped, choosing). */
|
|
31
|
+
allowed?: boolean): Reorder<T>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { pathFor } from "@sincpro/client-framework";
|
|
3
|
+
import { movesFor, placed, reorderingOf, } from "../../core/reorder.js";
|
|
4
|
+
import { useFramework } from "../../react/context.js";
|
|
5
|
+
import { useEffect, useMemo, useState } from "react";
|
|
6
|
+
export function useReorder(listing, keyOf,
|
|
7
|
+
/** `false` while the screen does not allow it (grouped, choosing). */
|
|
8
|
+
allowed = true) {
|
|
9
|
+
const { transport } = useFramework();
|
|
10
|
+
const { entity, meta, order, rows: read } = listing;
|
|
11
|
+
const route = entity.edit;
|
|
12
|
+
const reordering = useMemo(() => (allowed && route !== undefined ? reorderingOf(meta, order) : undefined), [allowed, route, meta, order]);
|
|
13
|
+
const [shown, setShown] = useState(null);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [elsewhere, setElsewhere] = useState(false);
|
|
16
|
+
// A new reading is what is stored: it replaces the order a move showed ahead of it.
|
|
17
|
+
useEffect(() => setShown(null), [read]);
|
|
18
|
+
const rows = shown ?? read;
|
|
19
|
+
const move = reordering === undefined || route === undefined
|
|
20
|
+
? undefined
|
|
21
|
+
: (id, before) => {
|
|
22
|
+
const moves = movesFor(rows, keyOf, reordering, id, before);
|
|
23
|
+
if (moves === "elsewhere") {
|
|
24
|
+
setElsewhere(true);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (moves.length === 0)
|
|
28
|
+
return;
|
|
29
|
+
setElsewhere(false);
|
|
30
|
+
setError(null);
|
|
31
|
+
setShown(placed(rows, keyOf, id, before));
|
|
32
|
+
void (async () => {
|
|
33
|
+
try {
|
|
34
|
+
for (const one of moves) {
|
|
35
|
+
const row = rows.find((candidate) => keyOf(candidate) === one.id) ?? {};
|
|
36
|
+
await transport.send(route.method, pathFor(route, one.id, row), {
|
|
37
|
+
id: one.id,
|
|
38
|
+
values: { [reordering.handle]: one.value },
|
|
39
|
+
changed: [reordering.handle],
|
|
40
|
+
version: 0,
|
|
41
|
+
...(typeof row["version"] === "number"
|
|
42
|
+
? { origin_version: row["version"] }
|
|
43
|
+
: {}),
|
|
44
|
+
action: "save",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (failure) {
|
|
49
|
+
setError(failure);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
listing.reload();
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
reordering,
|
|
58
|
+
rows,
|
|
59
|
+
...(move === undefined ? {} : { move }),
|
|
60
|
+
error,
|
|
61
|
+
elsewhere,
|
|
62
|
+
dismiss: () => {
|
|
63
|
+
setError(null);
|
|
64
|
+
setElsewhere(false);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type AskForm } from "./ask.js";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
/** What a person filled in before the action runs, by field name. */
|
|
5
5
|
export type Asked = Readonly<Record<string, unknown>>;
|
|
@@ -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
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
4
|
+
import { unansweredOf } from "./ask.js";
|
|
4
5
|
import { Refused } from "../Refused.js";
|
|
5
6
|
import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
|
|
6
7
|
import { useState } from "react";
|
|
@@ -19,7 +20,11 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
19
20
|
const copy = frameworkCopy().command;
|
|
20
21
|
const [values, setValues] = useState(() => ({ ...form.initial }));
|
|
21
22
|
const rehearsing = action.rehearse !== undefined;
|
|
23
|
+
// A required answer left empty keeps it from running — the server would only refuse it.
|
|
24
|
+
const unanswered = unansweredOf(form, values);
|
|
22
25
|
const confirm = async () => {
|
|
26
|
+
if (unanswered.length > 0)
|
|
27
|
+
return;
|
|
23
28
|
if (rehearsing && action.rehearsal === null) {
|
|
24
29
|
await action.rehearse?.(values);
|
|
25
30
|
return;
|
|
@@ -28,7 +33,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
28
33
|
if (answer !== undefined)
|
|
29
34
|
onDone(answer);
|
|
30
35
|
};
|
|
31
|
-
return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
36
|
+
return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex items-center justify-end gap-2", children: [unanswered.length === 0 ? null : (_jsx("p", { className: "mr-auto text-meta text-muted", children: frameworkCopy().record.missing(unanswered) })), _jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || unanswered.length > 0, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
32
37
|
const control = {
|
|
33
38
|
value: values[field.name],
|
|
34
39
|
set: (next) => {
|
|
@@ -43,7 +48,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
43
48
|
};
|
|
44
49
|
// A control that names itself is not wrapped in a `Field` (its name would double):
|
|
45
50
|
// what is expected goes under it.
|
|
46
|
-
return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
|
|
51
|
+
return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, required: field.required, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
|
|
47
52
|
}) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/dist/web/record/ask.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { ReactNode } from "react";
|
|
|
11
11
|
* label="Delegar áreas…" ask={["areas"]} />
|
|
12
12
|
* ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
|
|
13
13
|
* ask={[{ name: "role", label: "Rol", choices: ROLES, initial: "member", hint: "Lo que podrá hacer" }]}
|
|
14
|
+
* ask={[{ name: "observacion", label: "Motivo", widget: "textarea", required: true }]}
|
|
14
15
|
*
|
|
15
16
|
* Context: a Command that needs input could not live among a record's actions, so a screen drew
|
|
16
17
|
* its fields in the record's body with a button of their own. What the dialog shows is the
|
|
@@ -20,6 +21,11 @@ import type { ReactNode } from "react";
|
|
|
20
21
|
* hint, `{ name: "motivo", label, widget }` a field the entity lacks. A control of the
|
|
21
22
|
* application's goes in with `as`, never a widget named in a string (`widget` takes only the
|
|
22
23
|
* framework's own).
|
|
24
|
+
*
|
|
25
|
+
* A required answer (`required`, or a field the model marks required) keeps «Confirmar» off
|
|
26
|
+
* until it is given, and the dialog says what is missing: a reason left empty used to reach the
|
|
27
|
+
* server only to be refused (422). Only the presence is checked here — how long or what shape an
|
|
28
|
+
* answer must have is the use case's rule, and its refusal lands on the field.
|
|
23
29
|
*/
|
|
24
30
|
export type AskField = string | {
|
|
25
31
|
name: string;
|
|
@@ -42,6 +48,9 @@ export type AskField = string | {
|
|
|
42
48
|
initial?: unknown;
|
|
43
49
|
/** What is expected, said by the field — over the backend's own help for it. */
|
|
44
50
|
hint?: string;
|
|
51
|
+
/** It must be answered before the action runs — over the model's `required` for a field of
|
|
52
|
+
* the entity. «Confirmar» stays off while it is empty. */
|
|
53
|
+
required?: boolean;
|
|
45
54
|
};
|
|
46
55
|
/** A field ready to draw: its name, its label, its control. */
|
|
47
56
|
export type AskedField = {
|
|
@@ -49,6 +58,8 @@ export type AskedField = {
|
|
|
49
58
|
label: string;
|
|
50
59
|
/** What is expected — the action's hint, or the model's help for the field. */
|
|
51
60
|
hint?: string | undefined;
|
|
61
|
+
/** It must be answered before the action runs. */
|
|
62
|
+
required: boolean;
|
|
52
63
|
/** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
|
|
53
64
|
labelled: boolean;
|
|
54
65
|
draw: (control: FieldControl) => ReactNode;
|
|
@@ -70,3 +81,10 @@ export declare function askFormOf(fields: readonly AskField[], options: {
|
|
|
70
81
|
/** The declared entity a relation points at, to choose it with its picker. */
|
|
71
82
|
entityFor?: (target: string) => Entity | undefined;
|
|
72
83
|
}): AskForm;
|
|
84
|
+
/**
|
|
85
|
+
* The labels of the required answers still empty, in the order they are asked: what keeps an
|
|
86
|
+
* action from running, as the dialog says it.
|
|
87
|
+
*
|
|
88
|
+
* unansweredOf(form, { observacion: "" }) -> ["Motivo"]
|
|
89
|
+
*/
|
|
90
|
+
export declare function unansweredOf(form: AskForm, values: Readonly<Record<string, unknown>>): string[];
|
package/dist/web/record/ask.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { choicesOf } from "@sincpro/criteria";
|
|
4
|
+
import { isEmptyValue } from "../../core/edit.js";
|
|
4
5
|
import { fieldMetaOf, viewOf } from "../../core/present.js";
|
|
5
6
|
import { relationFieldOf } from "../../core/relation.js";
|
|
6
7
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
@@ -41,10 +42,13 @@ export function askFormOf(fields, options) {
|
|
|
41
42
|
const widget = said.widget ?? field?.widget;
|
|
42
43
|
const label = said.label ?? view?.label ?? said.name;
|
|
43
44
|
const hint = said.hint ?? view?.help;
|
|
45
|
+
// The model's fixed `required` only: a `required_when` speaks of the record's form.
|
|
46
|
+
const required = said.required ?? field?.required === true;
|
|
44
47
|
asked.push({
|
|
45
48
|
name,
|
|
46
49
|
label,
|
|
47
50
|
hint,
|
|
51
|
+
required,
|
|
48
52
|
labelled: said.as === undefined && target === undefined && labels(type, [...choices]),
|
|
49
53
|
draw: said.as ??
|
|
50
54
|
(target === undefined
|
|
@@ -61,3 +65,14 @@ export function askFormOf(fields, options) {
|
|
|
61
65
|
}
|
|
62
66
|
return { fields: asked, initial };
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The labels of the required answers still empty, in the order they are asked: what keeps an
|
|
70
|
+
* action from running, as the dialog says it.
|
|
71
|
+
*
|
|
72
|
+
* unansweredOf(form, { observacion: "" }) -> ["Motivo"]
|
|
73
|
+
*/
|
|
74
|
+
export function unansweredOf(form, values) {
|
|
75
|
+
return form.fields
|
|
76
|
+
.filter((one) => one.required && isEmptyValue(values[one.name]))
|
|
77
|
+
.map((one) => one.label);
|
|
78
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Entity } from "@sincpro/client-framework";
|
|
2
|
+
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
3
|
+
import { type Tone } from "@sincpro/web-ui";
|
|
4
|
+
/** A choice's value as a tag: its word and its tone. */
|
|
5
|
+
export type ChoiceTagLook = {
|
|
6
|
+
label: string;
|
|
7
|
+
tone: Tone;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A value of a choice as a tag: its word, the model's (`textOf`), in the tone the entity declared
|
|
11
|
+
* for it (`presented(entity, { tones })`), `neutral` when none was.
|
|
12
|
+
*
|
|
13
|
+
* choiceTagOf(pagos, meta, "estado", "PAGADO", "es") -> { label: "Pagado", tone: "good" }
|
|
14
|
+
*
|
|
15
|
+
* Context: a member's own page showed a payment's state outside any list. The tone was declared
|
|
16
|
+
* once and the word was the model's, but nothing public drew the pair, so the application wrote
|
|
17
|
+
* `presentationOf(entity).tones` plus `textOf` by hand (#42).
|
|
18
|
+
*/
|
|
19
|
+
export declare function choiceTagOf<T extends AnyRecord>(entity: Entity<T>, meta: Meta | null | undefined, field: keyof T & string, value: unknown, locale?: string): ChoiceTagLook;
|
|
20
|
+
/**
|
|
21
|
+
* A value of a choice, drawn as the framework draws it in a list — anywhere: a panel, a page of
|
|
22
|
+
* the application's own. Its model is the one given, else the one the provider already read for
|
|
23
|
+
* the entity; without either, the value itself is the word.
|
|
24
|
+
*
|
|
25
|
+
* <ChoiceTag entity={pagos} field="estado" value={pago.estado} />
|
|
26
|
+
*/
|
|
27
|
+
export declare function ChoiceTag<T extends AnyRecord>({ entity, field, value, meta, }: {
|
|
28
|
+
entity: Entity<T>;
|
|
29
|
+
field: keyof T & string;
|
|
30
|
+
value: unknown;
|
|
31
|
+
meta?: Meta | null;
|
|
32
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { textOf } from "../../core/present.js";
|
|
4
|
+
import { useFrameworkIfAny } from "../../react/context.js";
|
|
5
|
+
import { presentationOf } from "../list/presentation.js";
|
|
6
|
+
import { Tag } from "@sincpro/web-ui";
|
|
7
|
+
/**
|
|
8
|
+
* A value of a choice as a tag: its word, the model's (`textOf`), in the tone the entity declared
|
|
9
|
+
* for it (`presented(entity, { tones })`), `neutral` when none was.
|
|
10
|
+
*
|
|
11
|
+
* choiceTagOf(pagos, meta, "estado", "PAGADO", "es") -> { label: "Pagado", tone: "good" }
|
|
12
|
+
*
|
|
13
|
+
* Context: a member's own page showed a payment's state outside any list. The tone was declared
|
|
14
|
+
* once and the word was the model's, but nothing public drew the pair, so the application wrote
|
|
15
|
+
* `presentationOf(entity).tones` plus `textOf` by hand (#42).
|
|
16
|
+
*/
|
|
17
|
+
export function choiceTagOf(entity, meta, field, value, locale) {
|
|
18
|
+
const tones = presentationOf(entity).tones?.[field];
|
|
19
|
+
return {
|
|
20
|
+
label: textOf(meta, field, value, locale) ?? String(value ?? ""),
|
|
21
|
+
tone: tones?.[String(value)] ?? "neutral",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A value of a choice, drawn as the framework draws it in a list — anywhere: a panel, a page of
|
|
26
|
+
* the application's own. Its model is the one given, else the one the provider already read for
|
|
27
|
+
* the entity; without either, the value itself is the word.
|
|
28
|
+
*
|
|
29
|
+
* <ChoiceTag entity={pagos} field="estado" value={pago.estado} />
|
|
30
|
+
*/
|
|
31
|
+
export function ChoiceTag({ entity, field, value, meta, }) {
|
|
32
|
+
const framework = useFrameworkIfAny();
|
|
33
|
+
const model = meta ?? framework?.metas.get(entity.key) ?? null;
|
|
34
|
+
const look = choiceTagOf(entity, model, field, value, framework?.locale);
|
|
35
|
+
return _jsx(Tag, { tone: look.tone, children: look.label });
|
|
36
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Entity } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import type { UploadAbout } from "../../core/files.js";
|
|
3
4
|
import type { ReactNode } from "react";
|
|
4
5
|
/** What a control of a field receives: its value, how to change it, and its state now. */
|
|
5
6
|
export type FieldControl = {
|
|
@@ -11,6 +12,9 @@ export type FieldControl = {
|
|
|
11
12
|
/** No `Field` names it — a cell of a table: the control carries its label itself. Inside a
|
|
12
13
|
* `Field` it must not, or React Aria reads both and names it «Precio Precio». */
|
|
13
14
|
standalone?: boolean;
|
|
15
|
+
/** Whose field it is — the entity, the record's id, the field —, for what is sent apart from
|
|
16
|
+
* the record: a file, a picture inside a rich text. `RecordField` says it. */
|
|
17
|
+
about?: UploadAbout;
|
|
14
18
|
};
|
|
15
19
|
/**
|
|
16
20
|
* The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
|
|
3
|
+
import { dayOf, instantOf, Money, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
|
|
4
|
+
import { currencyNow } from "../../core/present.js";
|
|
4
5
|
import { EntityPicker } from "./EntityPicker.js";
|
|
5
6
|
import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, SegmentedControl, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
6
7
|
/** A choice answered with one press — a segmented control — instead of a select: up to three
|
|
@@ -39,6 +40,8 @@ export function controlFor(control, type, exact, choices, widget, segmented = fa
|
|
|
39
40
|
return (_jsx(SegmentedControl, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set }));
|
|
40
41
|
if (choices.length > 0)
|
|
41
42
|
return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
|
|
43
|
+
if (widget === "money")
|
|
44
|
+
return moneyInput(control, exact, named);
|
|
42
45
|
switch (type) {
|
|
43
46
|
case "boolean":
|
|
44
47
|
return _jsx(Checkbox, { checked: value === true, onChange: set, label: control.label });
|
|
@@ -85,3 +88,51 @@ export function RelationPicker({ target, value, onChange, label, ownChooser = fa
|
|
|
85
88
|
// «Buscar más…» is an option of the picker already: no second button beside it.
|
|
86
89
|
browse: false, ownChooser: ownChooser, ...(onClear === undefined ? {} : { onClear }), ...(standalone ? { "aria-label": label } : {}) }));
|
|
87
90
|
}
|
|
91
|
+
/** Whether `Intl` writes `code` as a currency — an ISO 4217 code —, asked once per code. */
|
|
92
|
+
const knownCurrencies = new Map();
|
|
93
|
+
function isCurrency(code) {
|
|
94
|
+
let known = knownCurrencies.get(code);
|
|
95
|
+
if (known === undefined) {
|
|
96
|
+
try {
|
|
97
|
+
new Intl.NumberFormat(undefined, { style: "currency", currency: code });
|
|
98
|
+
known = true;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
known = false;
|
|
102
|
+
}
|
|
103
|
+
knownCurrencies.set(code, known);
|
|
104
|
+
}
|
|
105
|
+
return known;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* An amount typed as money — «Bs 1.150,50» while it is typed, grouped and in its currency's
|
|
109
|
+
* decimals: a money (`{ amount, currency }`) keeps its own currency, a bare amount the model draws
|
|
110
|
+
* as money is in the business's (`FrameworkProvider currency`). What is typed goes back in the
|
|
111
|
+
* shape it came: a money whole, its amount as text; a bare exact amount as text — no digit passes
|
|
112
|
+
* through a float on its way to the server.
|
|
113
|
+
*
|
|
114
|
+
* Context: a money field was edited with a plain number input — no currency, no grouping —,
|
|
115
|
+
* while the same value read beside it as «Bs 1.150,50». web-ui's `NumberInput` types a currency
|
|
116
|
+
* through `format`; a code `Intl` does not know (a loyalty point) is its unit instead.
|
|
117
|
+
*/
|
|
118
|
+
function moneyInput(control, exact, named) {
|
|
119
|
+
const { value, set } = control;
|
|
120
|
+
const held = Money.isMoney(value) ? value : null;
|
|
121
|
+
const code = held?.currency ?? currencyNow();
|
|
122
|
+
const amount = held === null ? value : held.amount;
|
|
123
|
+
const typed = amount === null || amount === undefined || amount === "" ? "" : Number(amount);
|
|
124
|
+
const decimals = code === undefined ? 2 : Money.decimalsOf(code);
|
|
125
|
+
const known = code !== undefined && isCurrency(code);
|
|
126
|
+
const format = {
|
|
127
|
+
...(known ? { style: "currency", currency: code } : {}),
|
|
128
|
+
minimumFractionDigits: decimals,
|
|
129
|
+
maximumFractionDigits: decimals,
|
|
130
|
+
};
|
|
131
|
+
return (_jsx(NumberInput, { value: Number.isNaN(typed) ? "" : typed, format: format, ...(code !== undefined && !known ? { unit: code } : {}), onChange: (next) => {
|
|
132
|
+
if (next === "")
|
|
133
|
+
return set(null);
|
|
134
|
+
if (held !== null)
|
|
135
|
+
return set({ amount: String(next), currency: held.currency });
|
|
136
|
+
set(exact ? String(next) : next);
|
|
137
|
+
}, ...named }));
|
|
138
|
+
}
|
package/dist/web/record/edit.js
CHANGED
|
@@ -8,14 +8,18 @@ import { holdsFile } from "../../core/files.js";
|
|
|
8
8
|
import { editableLines } from "../../core/lines.js";
|
|
9
9
|
import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
|
|
10
10
|
import { relationFieldOf } from "../../core/relation.js";
|
|
11
|
+
import { holdsRichText } from "../../core/richText.js";
|
|
11
12
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
12
13
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
13
14
|
import { attachmentOf } from "../files.js";
|
|
14
15
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
16
|
+
import { FileControl } from "./fileControl.js";
|
|
15
17
|
import { RecordLinesEditor } from "./lines.js";
|
|
16
|
-
import { useRecordOpening } from "./opening.js";
|
|
18
|
+
import { useRecordOpening, } from "./opening.js";
|
|
19
|
+
import { isPersonEntity, PersonValue } from "./person.js";
|
|
17
20
|
import { RecordLines } from "./record.js";
|
|
18
21
|
import { RelatedList } from "./RelatedList.js";
|
|
22
|
+
import { RichTextControl } from "./richText.js";
|
|
19
23
|
import { Checkbox, Field, FileValue, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
|
|
20
24
|
/** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
|
|
21
25
|
function setAt(value, path, next) {
|
|
@@ -32,6 +36,24 @@ function KeyValue({ target, id, ...rest }) {
|
|
|
32
36
|
const name = useNameOf(target, id);
|
|
33
37
|
return _jsx(RelationValue, { name: name ?? id, ...rest });
|
|
34
38
|
}
|
|
39
|
+
/** Whose a field is, for what is sent apart from the record: the entity, the record's id — a
|
|
40
|
+
* new one's too, the id it was given here (`newEntityId`) —, the field. */
|
|
41
|
+
function aboutOf(record, name) {
|
|
42
|
+
const { meta, edit } = record;
|
|
43
|
+
const key = meta?.get_id || meta?.identity || "id";
|
|
44
|
+
const held = edit.values[key];
|
|
45
|
+
const id = record.id !== "" ? record.id : held === null || held === undefined ? "" : String(held);
|
|
46
|
+
return {
|
|
47
|
+
entity: meta?.aggregate ?? record.entity.key,
|
|
48
|
+
id: id === "" ? null : id,
|
|
49
|
+
field: name,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** A key alone to a person, read: named by key, drawn with their initials. */
|
|
53
|
+
function KeyPerson({ target, id, opening, }) {
|
|
54
|
+
const name = useNameOf(target, id);
|
|
55
|
+
return _jsx(PersonValue, { target: target, id: id, name: name ?? id, opening: opening });
|
|
56
|
+
}
|
|
35
57
|
/**
|
|
36
58
|
* One field of a record being edited, from the model: its word, whether it is required or
|
|
37
59
|
* read-only now (the hints, evaluated over what is on screen), the server's error for it, and a
|
|
@@ -80,7 +102,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
80
102
|
const relation = nested ? undefined : relationFieldOf(meta, name);
|
|
81
103
|
const target = useEntityFor(relation?.target);
|
|
82
104
|
const opening = useRecordOpening();
|
|
83
|
-
const { metas } = useFramework();
|
|
105
|
+
const { metas, uploads } = useFramework();
|
|
84
106
|
const settings = useFormStyle() === "settings";
|
|
85
107
|
if (!state.visible)
|
|
86
108
|
return null;
|
|
@@ -154,13 +176,18 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
154
176
|
readonly: state.readonly,
|
|
155
177
|
invalid: error !== undefined,
|
|
156
178
|
label: view.label,
|
|
179
|
+
about: aboutOf(record, name),
|
|
157
180
|
};
|
|
158
181
|
const field = fieldMetaOf(meta, name);
|
|
159
182
|
if (as === undefined && holdsFile(field)) {
|
|
160
183
|
// A file is ONE value — its picture or its kind, the name it was sent with, its type and
|
|
161
|
-
// size —, never a section of its parts.
|
|
184
|
+
// size —, never a section of its parts. Another one is given through the application's
|
|
185
|
+
// uploads (`FrameworkProvider uploads`); without them, it is only read.
|
|
162
186
|
const file = attachmentOf(value);
|
|
163
|
-
|
|
187
|
+
const editable = !state.readonly && uploads !== undefined && !nested;
|
|
188
|
+
return (_jsx(Field, { label: view.label, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: editable ? (_jsx(FileControl, { control: control, image: field?.widget === "image",
|
|
189
|
+
// Answered no value: the backend already put the file in the record — read it again.
|
|
190
|
+
onKept: (published) => published.value === undefined ? record.reload() : control.set(published.value) })) : file === null ? (_jsx(ReadValue, { value: "\u2014" })) : (_jsx(FileValue, { file: file, size: "md" })) }));
|
|
164
191
|
}
|
|
165
192
|
/** A many2one of a declared entity: chosen by the server's literal search, opened where the
|
|
166
193
|
* view says. Written by its key; read by the record it points at. */
|
|
@@ -176,6 +203,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
176
203
|
onOpenIn: (to) => opening.open(target.ref(id), to),
|
|
177
204
|
openTargets: opening.targets,
|
|
178
205
|
};
|
|
206
|
+
// A person reads as their face and name; their card opens their record.
|
|
207
|
+
if (isPersonEntity(target) && id !== "")
|
|
208
|
+
return relation.held ? (_jsx(PersonValue, { target: target, id: id, name: textOf(meta, relation.relation, edit.values[relation.relation], locale) ?? id, held: edit.values[relation.relation], opening: opening })) : (_jsx(KeyPerson, { target: target, id: id, opening: opening }));
|
|
179
209
|
// A relation held beside its key names itself; a key alone (`EntityID`) asks its name.
|
|
180
210
|
if (!relation.held)
|
|
181
211
|
return _jsx(KeyValue, { target: target, id: id, ...opens });
|
|
@@ -203,7 +233,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
203
233
|
return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
|
|
204
234
|
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
|
|
205
235
|
// Said only in web-ui's «settings» form style: a field that may stay empty, and is typed in.
|
|
206
|
-
optional: !state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices,
|
|
236
|
+
optional: !state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : holdsRichText(field) ? (_jsx(RichTextControl, { control: control })) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices,
|
|
237
|
+
// A value object of an amount and a currency is a money, whatever it is called.
|
|
238
|
+
field?.widget ?? (isMoneyDefinition(field?.definition) ? "money" : undefined), settings && state.required)) }));
|
|
207
239
|
}
|
|
208
240
|
/**
|
|
209
241
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Published } from "../../core/files.js";
|
|
2
|
+
import type { FieldControl } from "./control.js";
|
|
3
|
+
/**
|
|
4
|
+
* A record's file or picture, given by a person: what it holds now — its picture or its kind,
|
|
5
|
+
* the name it was sent with —, and the zone that takes another — dropped, pasted or chosen —, its
|
|
6
|
+
* bytes sent where the application says (`uploads`) with their progress, a cancel, a retry, and a
|
|
7
|
+
* refusal in the copy's words by the backend's reason.
|
|
8
|
+
*
|
|
9
|
+
* Context: an application saved the record first, then uploaded through a picker of its own.
|
|
10
|
+
* sincpro_framework takes no file inside a Command (#364): its Command asks for an upload id, the
|
|
11
|
+
* bytes go there (`uploadTo`), and the save names it. Once the bytes are there the field holds
|
|
12
|
+
* what the application answered (`Published.value`: the id the save's Command names), and the
|
|
13
|
+
* record is dirty as with any field; when it answered none, the backend already put the file in
|
|
14
|
+
* the record, and `onKept` reads it again.
|
|
15
|
+
*/
|
|
16
|
+
export declare function FileControl({ control, image, onKept, }: {
|
|
17
|
+
control: FieldControl;
|
|
18
|
+
/** A picture: the zone's dialog offers images only. What it may be is still the backend's. */
|
|
19
|
+
image?: boolean;
|
|
20
|
+
/** What to do once the bytes are there; by default the field takes `Published.value`. */
|
|
21
|
+
onKept?: (published: Published) => void;
|
|
22
|
+
}): import("react").JSX.Element;
|