@sincpro/web-framework 0.2.0 → 0.4.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 +56 -19
- package/dist/core/copy.d.ts +2 -0
- package/dist/core/copy.js +2 -0
- package/dist/core/edit.d.ts +35 -3
- package/dist/core/edit.js +49 -5
- package/dist/core/entity.d.ts +14 -2
- package/dist/core/entity.js +33 -1
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +4 -2
- package/dist/core/lines.d.ts +52 -0
- package/dist/core/lines.js +120 -0
- package/dist/core/list.d.ts +1 -1
- package/dist/core/lookup.d.ts +2 -0
- package/dist/core/lookup.js +3 -1
- package/dist/core/present.js +7 -2
- package/dist/core/rest.d.ts +5 -9
- package/dist/core/rest.js +14 -6
- package/dist/core/transport.d.ts +9 -1
- package/dist/core/zone.d.ts +27 -0
- package/dist/core/zone.js +75 -0
- package/dist/react/context.d.ts +13 -1
- package/dist/react/context.js +10 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +1 -0
- package/dist/react/useGroups.d.ts +13 -1
- package/dist/react/useGroups.js +48 -7
- package/dist/react/useListing.d.ts +8 -4
- package/dist/react/useListing.js +11 -5
- package/dist/react/usePivot.d.ts +33 -0
- package/dist/react/usePivot.js +59 -0
- package/dist/react/useRecord.d.ts +13 -9
- package/dist/react/useRecord.js +55 -13
- package/dist/web/index.d.ts +7 -1
- package/dist/web/index.js +7 -1
- package/dist/web/list/EntityList.d.ts +46 -7
- package/dist/web/list/EntityList.js +132 -21
- package/dist/web/list/EntitySearchBar.js +19 -1
- package/dist/web/list/columns.d.ts +0 -13
- package/dist/web/list/columns.js +20 -1
- package/dist/web/list/groups.d.ts +3 -1
- package/dist/web/list/groups.js +8 -1
- package/dist/web/list/openIn.d.ts +41 -0
- package/dist/web/list/openIn.js +55 -0
- package/dist/web/list/pivot.d.ts +23 -0
- package/dist/web/list/pivot.js +64 -0
- package/dist/web/list/presentation.d.ts +51 -0
- package/dist/web/list/presentation.js +20 -0
- package/dist/web/record/EntityPicker.d.ts +3 -1
- package/dist/web/record/EntityPicker.js +15 -5
- package/dist/web/record/EntityTags.js +16 -5
- package/dist/web/record/RelatedList.d.ts +6 -0
- package/dist/web/record/RelatedList.js +26 -2
- package/dist/web/record/control.d.ts +43 -0
- package/dist/web/record/control.js +67 -0
- package/dist/web/record/edit.d.ts +16 -8
- package/dist/web/record/edit.js +57 -49
- package/dist/web/record/lines.d.ts +84 -0
- package/dist/web/record/lines.js +190 -0
- package/dist/web/record/opening.d.ts +8 -0
- package/dist/web/record/summary.js +14 -6
- package/dist/web/workspace/SincproApp.d.ts +4 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/dist/web/workspace/composer.d.ts +2 -1
- package/dist/web/workspace/composer.js +27 -16
- package/dist/web/workspace/open.d.ts +2 -14
- package/dist/web/workspace/open.js +2 -13
- package/dist/web/workspace/record.js +6 -3
- package/dist/web/workspace/workspace.d.ts +4 -2
- package/dist/web/workspace/workspace.js +10 -4
- package/package.json +9 -9
package/dist/web/list/groups.js
CHANGED
|
@@ -33,7 +33,9 @@ export function groupableOf(meta, locale) {
|
|
|
33
33
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
34
34
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
35
35
|
*/
|
|
36
|
-
export function pilesOf(buckets, levels, meta, locale, rowsOf
|
|
36
|
+
export function pilesOf(buckets, levels, meta, locale, rowsOf,
|
|
37
|
+
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
38
|
+
brings) {
|
|
37
39
|
const bucketAt = new Map();
|
|
38
40
|
const none = frameworkCopy().list.noValue;
|
|
39
41
|
const labelFor = (bucket, depth, key) => {
|
|
@@ -52,6 +54,10 @@ export function pilesOf(buckets, levels, meta, locale, rowsOf) {
|
|
|
52
54
|
const detail = detailOf(meta, bucket.measures, locale);
|
|
53
55
|
return detail === undefined ? {} : { detail };
|
|
54
56
|
};
|
|
57
|
+
const more = (bucket, deepest) => {
|
|
58
|
+
const next = deepest ? brings?.(bucket) : undefined;
|
|
59
|
+
return next === undefined ? {} : { more: next };
|
|
60
|
+
};
|
|
55
61
|
const walk = (level, above, depth) => level.map((bucket) => {
|
|
56
62
|
const key = bucket.value === null || bucket.value === undefined ? "" : String(bucket.value);
|
|
57
63
|
const path = [...above, key];
|
|
@@ -67,6 +73,7 @@ export function pilesOf(buckets, levels, meta, locale, rowsOf) {
|
|
|
67
73
|
...detailed(bucket),
|
|
68
74
|
items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
|
|
69
75
|
piles: walk(below, path, depth + 1),
|
|
76
|
+
...more(bucket, below.length === 0),
|
|
70
77
|
};
|
|
71
78
|
});
|
|
72
79
|
return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { OpenOptions, WorkspaceApi } from "@sincpro/web-composer";
|
|
2
|
+
import { type OpenTarget } from "@sincpro/web-ui";
|
|
3
|
+
/**
|
|
4
|
+
* Where a record may open, and the menu that offers it.
|
|
5
|
+
*
|
|
6
|
+
* Context: a record opened from a list used to go one way — a press opened the page — and the
|
|
7
|
+
* other places (a look, beside, a window) were the composer's `RecordLink` icons, shown only to
|
|
8
|
+
* a pointer hovering the name of a TABLE row: nothing from the rows, the board, a one2many, and
|
|
9
|
+
* never a modal. A record opens anywhere the workspace can put it unless the screen says
|
|
10
|
+
* otherwise (`openTargets`), and «Abrir en…» says so where it is seen, in web-ui's own words
|
|
11
|
+
* (`openIn`) — the same menu a many2one already has.
|
|
12
|
+
*
|
|
13
|
+
* The places allowed depend on where the list is: from inside a modal, no modal (a second one
|
|
14
|
+
* would replace the first and lose what was typed in it) — composer says where a view is
|
|
15
|
+
* (`api.over`).
|
|
16
|
+
*/
|
|
17
|
+
/** A record's form fits; a short task (register a payment) passes its own size. */
|
|
18
|
+
export declare const RECORD_SIZE: {
|
|
19
|
+
readonly w: 760;
|
|
20
|
+
readonly h: 560;
|
|
21
|
+
};
|
|
22
|
+
/** Where a record may open from this view, the default first. */
|
|
23
|
+
export declare function targetsFor(api: Pick<WorkspaceApi, "over">): readonly OpenTarget[];
|
|
24
|
+
/** web-ui's target as composer's options. Destinations share their names, so only the size is
|
|
25
|
+
* added — to the two that have one. */
|
|
26
|
+
export declare function openOptions(to: OpenTarget, size?: {
|
|
27
|
+
w: number;
|
|
28
|
+
h: number;
|
|
29
|
+
}): OpenOptions;
|
|
30
|
+
/**
|
|
31
|
+
* «Abrir en…»: a visible menu of the places a record may open, beside its name. Nothing when
|
|
32
|
+
* there is one place or none — then a press is all there is.
|
|
33
|
+
*
|
|
34
|
+
* <OpenInMenu targets={["modal", "side", "window"]} onOpen={(to) => openIn(api, ref, to)} />
|
|
35
|
+
*/
|
|
36
|
+
export declare function OpenInMenu({ targets, onOpen, name, }: {
|
|
37
|
+
targets: readonly OpenTarget[];
|
|
38
|
+
onOpen: (to: OpenTarget) => void;
|
|
39
|
+
/** Whose menu it is, for a screen reader: «Abrir en… — F-2026-0004». */
|
|
40
|
+
name?: string;
|
|
41
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Menu, useUiCopy } from "@sincpro/web-ui";
|
|
4
|
+
import { AppWindow, Eye, FileText, PanelRight, SquareArrowOutUpRight, SquareStack, } from "lucide-react";
|
|
5
|
+
/**
|
|
6
|
+
* Where a record may open, and the menu that offers it.
|
|
7
|
+
*
|
|
8
|
+
* Context: a record opened from a list used to go one way — a press opened the page — and the
|
|
9
|
+
* other places (a look, beside, a window) were the composer's `RecordLink` icons, shown only to
|
|
10
|
+
* a pointer hovering the name of a TABLE row: nothing from the rows, the board, a one2many, and
|
|
11
|
+
* never a modal. A record opens anywhere the workspace can put it unless the screen says
|
|
12
|
+
* otherwise (`openTargets`), and «Abrir en…» says so where it is seen, in web-ui's own words
|
|
13
|
+
* (`openIn`) — the same menu a many2one already has.
|
|
14
|
+
*
|
|
15
|
+
* The places allowed depend on where the list is: from inside a modal, no modal (a second one
|
|
16
|
+
* would replace the first and lose what was typed in it) — composer says where a view is
|
|
17
|
+
* (`api.over`).
|
|
18
|
+
*/
|
|
19
|
+
/** A record's form fits; a short task (register a payment) passes its own size. */
|
|
20
|
+
export const RECORD_SIZE = { w: 760, h: 560 };
|
|
21
|
+
const EVERYWHERE = ["modal", "peek", "side", "page", "window"];
|
|
22
|
+
const FROM_A_MODAL = ["side", "peek", "page", "window"];
|
|
23
|
+
/** Where a record may open from this view, the default first. */
|
|
24
|
+
export function targetsFor(api) {
|
|
25
|
+
return api.over === null ? EVERYWHERE : FROM_A_MODAL;
|
|
26
|
+
}
|
|
27
|
+
/** web-ui's target as composer's options. Destinations share their names, so only the size is
|
|
28
|
+
* added — to the two that have one. */
|
|
29
|
+
export function openOptions(to, size = RECORD_SIZE) {
|
|
30
|
+
return to === "modal" || to === "window" ? { to, size } : { to };
|
|
31
|
+
}
|
|
32
|
+
const ICON = {
|
|
33
|
+
page: FileText,
|
|
34
|
+
peek: Eye,
|
|
35
|
+
modal: SquareStack,
|
|
36
|
+
side: PanelRight,
|
|
37
|
+
window: AppWindow,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* «Abrir en…»: a visible menu of the places a record may open, beside its name. Nothing when
|
|
41
|
+
* there is one place or none — then a press is all there is.
|
|
42
|
+
*
|
|
43
|
+
* <OpenInMenu targets={["modal", "side", "window"]} onOpen={(to) => openIn(api, ref, to)} />
|
|
44
|
+
*/
|
|
45
|
+
export function OpenInMenu({ targets, onOpen, name, }) {
|
|
46
|
+
const copy = useUiCopy().picker;
|
|
47
|
+
if (targets.length === 0)
|
|
48
|
+
return null;
|
|
49
|
+
const options = targets.map((to) => ({
|
|
50
|
+
id: to,
|
|
51
|
+
label: copy.openIn[to],
|
|
52
|
+
icon: ICON[to],
|
|
53
|
+
}));
|
|
54
|
+
return (_jsx(Menu, { label: name === undefined ? copy.openMore : `${copy.openMore} ${name}`, title: copy.openMore, groups: [{ options }], onSelect: (id) => onOpen(id), icon: SquareArrowOutUpRight, iconOnly: true, size: "sm", role: "ghost", align: "end", width: "sm" }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
|
|
2
|
+
import type { GroupLevel } from "../../core/list.js";
|
|
3
|
+
import type { Pivot } from "@sincpro/web-ui";
|
|
4
|
+
/**
|
|
5
|
+
* web-ui's `Pivot` (`folded`), from what the SERVER counted (`usePivot`): the rows axis is the
|
|
6
|
+
* outer groups, the columns axis every inner value that appeared, each crossing an inner group,
|
|
7
|
+
* each row's total its outer group, each column's total the grouping by the columns alone.
|
|
8
|
+
* Nothing is added up here — a margin is read from the base, never summed from cells.
|
|
9
|
+
*
|
|
10
|
+
* A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
|
|
11
|
+
* value («paid») is not a word for a person.
|
|
12
|
+
*/
|
|
13
|
+
export declare function pivotOf<T extends AnyRecord>({ crossed, byColumn, rows, columns, measures, meta, locale, }: {
|
|
14
|
+
/** Grouped by rows, then columns (`usePivot().crossed`). */
|
|
15
|
+
crossed: readonly Bucket<T>[];
|
|
16
|
+
/** Grouped by the columns alone (`usePivot().columns`). */
|
|
17
|
+
byColumn: readonly Bucket<T>[];
|
|
18
|
+
rows: GroupLevel;
|
|
19
|
+
columns: GroupLevel;
|
|
20
|
+
measures: readonly string[];
|
|
21
|
+
meta: Meta | null | undefined;
|
|
22
|
+
locale: string | undefined;
|
|
23
|
+
}): Pivot;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { labelOf } from "@sincpro/criteria";
|
|
2
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
3
|
+
import { textOf } from "../../core/present.js";
|
|
4
|
+
/**
|
|
5
|
+
* web-ui's `Pivot` (`folded`), from what the SERVER counted (`usePivot`): the rows axis is the
|
|
6
|
+
* outer groups, the columns axis every inner value that appeared, each crossing an inner group,
|
|
7
|
+
* each row's total its outer group, each column's total the grouping by the columns alone.
|
|
8
|
+
* Nothing is added up here — a margin is read from the base, never summed from cells.
|
|
9
|
+
*
|
|
10
|
+
* A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
|
|
11
|
+
* value («paid») is not a word for a person.
|
|
12
|
+
*/
|
|
13
|
+
export function pivotOf({ crossed, byColumn, rows, columns, measures, meta, locale, }) {
|
|
14
|
+
const none = frameworkCopy().list.noValue;
|
|
15
|
+
const keyOf = (bucket) => bucket.value === null || bucket.value === undefined || bucket.value === ""
|
|
16
|
+
? none
|
|
17
|
+
: (textOf(meta, bucket.field, bucket.value, locale) ?? String(bucket.value));
|
|
18
|
+
const cellOf = (bucket) => ({
|
|
19
|
+
count: bucket.count,
|
|
20
|
+
values: Object.fromEntries(measures.map((name) => {
|
|
21
|
+
const value = bucket.measures?.[name];
|
|
22
|
+
return [name, value === null || value === undefined ? null : Number(value)];
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
25
|
+
const rowKeys = crossed.map((bucket) => [keyOf(bucket)]);
|
|
26
|
+
// Columns in the server's order of the columns alone; any value only a crossing has, after.
|
|
27
|
+
const seen = new Set(byColumn.map(keyOf));
|
|
28
|
+
const columnKeys = [...seen];
|
|
29
|
+
for (const outer of crossed)
|
|
30
|
+
for (const inner of outer.groups ?? []) {
|
|
31
|
+
const key = keyOf(inner);
|
|
32
|
+
if (!seen.has(key)) {
|
|
33
|
+
seen.add(key);
|
|
34
|
+
columnKeys.push(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const at = new Map();
|
|
38
|
+
const rowTotals = new Map();
|
|
39
|
+
for (const outer of crossed) {
|
|
40
|
+
const row = keyOf(outer);
|
|
41
|
+
rowTotals.set(row, cellOf(outer));
|
|
42
|
+
for (const inner of outer.groups ?? [])
|
|
43
|
+
at.set(`${row}\u0000${keyOf(inner)}`, cellOf(inner));
|
|
44
|
+
}
|
|
45
|
+
const columnTotals = new Map(byColumn.map((bucket) => [keyOf(bucket), cellOf(bucket)]));
|
|
46
|
+
return {
|
|
47
|
+
rows: {
|
|
48
|
+
levels: [{ ...rows, label: labelOf(meta, rows.field, locale) }],
|
|
49
|
+
keys: rowKeys,
|
|
50
|
+
},
|
|
51
|
+
columns: {
|
|
52
|
+
levels: [{ ...columns, label: labelOf(meta, columns.field, locale) }],
|
|
53
|
+
keys: columnKeys.map((key) => [key]),
|
|
54
|
+
},
|
|
55
|
+
measures: measures.map((name) => ({
|
|
56
|
+
id: name,
|
|
57
|
+
header: labelOf(meta, name, locale),
|
|
58
|
+
format: (value) => textOf(meta, name, value, locale) ?? String(value),
|
|
59
|
+
})),
|
|
60
|
+
cell: (row, column) => at.get(`${row[0] ?? ""}\u0000${column[0] ?? ""}`),
|
|
61
|
+
rowTotal: (row) => rowTotals.get(row[0] ?? ""),
|
|
62
|
+
columnTotal: (column) => columnTotals.get(column[0] ?? ""),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { Entity } from "../../core/entity.js";
|
|
3
|
+
import { type ListDefinition } from "../../core/list.js";
|
|
4
|
+
import type { PickerItem, RecordCard, RowOf } from "@sincpro/web-ui";
|
|
5
|
+
import type { ComponentProps } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* How a record of an entity looks at each size — a choice, a row, a card — declared ONCE with
|
|
8
|
+
* the entity and used wherever the framework draws one of its records.
|
|
9
|
+
*
|
|
10
|
+
* Context: the name of a record is the backend's (`meta.display`, Odoo's `display_name`) and
|
|
11
|
+
* its parts are the summary's (`entity(…, { summary })`); what was missing is how it is DRAWN.
|
|
12
|
+
* Every place built its own: the picker's option was always name + key + face, the rows face
|
|
13
|
+
* name + three facts, the board's card whatever the row said. Now an application says it once:
|
|
14
|
+
*
|
|
15
|
+
* export const customers = presented(entity<Customer>("sales:customer", { list: "/customers" }), {
|
|
16
|
+
* option: (c) => ({ meta: c.tax_id, aside: <Saldo value={c.balance} /> }),
|
|
17
|
+
* row: (c) => ({ tags: c.blocked ? <Tag tone="bad">Bloqueado</Tag> : undefined }),
|
|
18
|
+
* card: (c) => ({ subtitle: c.city, figure: <Saldo value={c.balance} /> }),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* Each size answers the PROPS of web-ui's piece for it (`PickerItem`, `RowOf`, `RecordCard`),
|
|
22
|
+
* merged OVER the default: give only what changes, and what is not given stays as it was.
|
|
23
|
+
* Props and not components for the reason `factsOf`/`columnsOf` give: web-ui keeps the
|
|
24
|
+
* keyboard, the highlight of what was typed, the press rule and the accessibility of the
|
|
25
|
+
* piece, and finds its slots by type. A whole component of the application in an option's
|
|
26
|
+
* place needs web-ui to take one (`ROADMAP.md`).
|
|
27
|
+
*
|
|
28
|
+
* A function around `entity()` and not a field of it: `core/` draws nothing and cannot name a
|
|
29
|
+
* React node; the presentation is the web's, so it is added here. The result IS the entity —
|
|
30
|
+
* every place that takes one takes it — with its presentation on board.
|
|
31
|
+
*/
|
|
32
|
+
/** A choice in a many2one, a many2many and ⌘K. ⌘K writes only text: `name` and `meta`. */
|
|
33
|
+
export type OptionLook = Partial<Omit<PickerItem, "id">>;
|
|
34
|
+
/** A row of the «rows» face — and of the board's card when there is no `card`. */
|
|
35
|
+
export type RowLook = Partial<RowOf>;
|
|
36
|
+
/** The board's card. Opening it stays the list's: `onOpen` is not the presentation's. */
|
|
37
|
+
export type CardLook = Partial<Omit<ComponentProps<typeof RecordCard>, "onOpen">>;
|
|
38
|
+
export type Presentation<T> = {
|
|
39
|
+
option?: (record: T) => OptionLook;
|
|
40
|
+
row?: (record: T) => RowLook;
|
|
41
|
+
card?: (record: T) => CardLook;
|
|
42
|
+
};
|
|
43
|
+
export type Presented<T extends AnyRecord> = Entity<T> & {
|
|
44
|
+
readonly presentation: Presentation<T>;
|
|
45
|
+
};
|
|
46
|
+
/** The entity with how its records look: pass it wherever an entity goes. */
|
|
47
|
+
export declare function presented<T extends AnyRecord>(entity: Entity<T>, presentation: Presentation<T>): Presented<T>;
|
|
48
|
+
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
49
|
+
export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
|
|
50
|
+
/** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
|
|
51
|
+
export declare function over<B extends object, L extends object>(base: B, look: L | undefined): B;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isList } from "../../core/list.js";
|
|
2
|
+
/** The entity with how its records look: pass it wherever an entity goes. */
|
|
3
|
+
export function presented(entity, presentation) {
|
|
4
|
+
return { ...entity, presentation };
|
|
5
|
+
}
|
|
6
|
+
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
7
|
+
export function presentationOf(source) {
|
|
8
|
+
const base = isList(source) ? source.entity : source;
|
|
9
|
+
return "presentation" in base ? base.presentation : {};
|
|
10
|
+
}
|
|
11
|
+
/** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
|
|
12
|
+
export function over(base, look) {
|
|
13
|
+
if (look === undefined)
|
|
14
|
+
return base;
|
|
15
|
+
const out = { ...base };
|
|
16
|
+
for (const [key, value] of Object.entries(look))
|
|
17
|
+
if (value !== undefined)
|
|
18
|
+
out[key] = value;
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
@@ -41,7 +41,9 @@ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onCha
|
|
|
41
41
|
/** Which records may be chosen at all: applied by the server under what is typed. */
|
|
42
42
|
criteria?: Criteria<T>;
|
|
43
43
|
value?: string;
|
|
44
|
-
|
|
44
|
+
/** The key chosen, and its record when the choice brought it — what a line keeps beside the
|
|
45
|
+
* key so its cell names the choice without asking again. */
|
|
46
|
+
onChange: (id: string, chosen?: T) => void;
|
|
45
47
|
/** Open the chosen record where the person asked — in composer,
|
|
46
48
|
* `(id, to) => openIn(api, entity.ref(id), to)`. */
|
|
47
49
|
onOpen?: (id: string, to: OpenTarget) => void;
|
|
@@ -6,6 +6,7 @@ import { isList } from "../../core/list.js";
|
|
|
6
6
|
import { useListing } from "../../react/useListing.js";
|
|
7
7
|
import { useLookup } from "../../react/useLookup.js";
|
|
8
8
|
import { EntityList } from "../list/EntityList.js";
|
|
9
|
+
import { over, presentationOf } from "../list/presentation.js";
|
|
9
10
|
import { Dialog, IconButton, Picker } from "@sincpro/web-ui";
|
|
10
11
|
import { TextSearch } from "lucide-react";
|
|
11
12
|
import { useState } from "react";
|
|
@@ -44,19 +45,28 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
|
|
|
44
45
|
...(value === undefined ? {} : { value }),
|
|
45
46
|
});
|
|
46
47
|
const person = (isList(entity) ? entity.entity : entity).summary.person === true;
|
|
48
|
+
const look = presentationOf(entity).option;
|
|
47
49
|
const [choosing, setChoosing] = useState(false);
|
|
48
50
|
const browseAll = onBrowseAll ?? (() => setChoosing(true));
|
|
49
|
-
const picker = (_jsx(Picker, { items: lookup.options.map((one) => ({
|
|
51
|
+
const picker = (_jsx(Picker, { items: lookup.options.map((one) => over({
|
|
50
52
|
id: one.id,
|
|
51
53
|
name: one.label,
|
|
52
54
|
...(one.detail === undefined ? {} : { meta: one.detail, haystack: one.detail }),
|
|
53
55
|
// A person or a company is chosen by their face: the photo, or their initials.
|
|
54
56
|
...(person ? { avatar: one.image ?? true } : {}),
|
|
55
|
-
}
|
|
57
|
+
},
|
|
58
|
+
// The entity's own look of a choice, over the default (`presented`).
|
|
59
|
+
look === undefined || one.record === undefined ? undefined : look(one.record))), ...(value === undefined ? {} : { value }), ...(lookup.chosen === undefined
|
|
60
|
+
? {}
|
|
61
|
+
: {
|
|
62
|
+
valueLabel: (lookup.chosen.record === undefined || look === undefined
|
|
63
|
+
? undefined
|
|
64
|
+
: look(lookup.chosen.record).name) ?? lookup.chosen.label,
|
|
65
|
+
}), onChange: (id) => onChange(id, lookup.options.find((one) => one.id === id)?.record), ...(lookup.searchable ? { onSearch: lookup.search } : {}),
|
|
56
66
|
// «Loading» only before there is anything: refining keeps the ten on screen.
|
|
57
67
|
loading: lookup.loading && lookup.options.length === 0, ...(onOpen === undefined ? {} : { onOpen }), ...(openTargets === undefined ? {} : { openTargets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
|
|
58
|
-
return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(criteria === undefined ? {} : { criteria }), onChoose: (id) => {
|
|
59
|
-
onChange(id);
|
|
68
|
+
return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(criteria === undefined ? {} : { criteria }), onChoose: (id, row) => {
|
|
69
|
+
onChange(id, row);
|
|
60
70
|
setChoosing(false);
|
|
61
71
|
}, onClose: () => setChoosing(false) })) : null] }));
|
|
62
72
|
}
|
|
@@ -69,5 +79,5 @@ function Chooser({ entity, columns, criteria, onChoose, onClose, }) {
|
|
|
69
79
|
});
|
|
70
80
|
const key = listing.meta?.get_id || listing.meta?.identity || "id";
|
|
71
81
|
return (_jsx(Dialog, { open: true, width: "lg", title: (isList(entity) ? entity.title : nameOf(listing.meta, listing.locale)) ||
|
|
72
|
-
listing.entity.kind, onClose: onClose, children: _jsx(EntityList, { listing: listing, embedded: true,
|
|
82
|
+
listing.entity.kind, onClose: onClose, children: _jsx(EntityList, { listing: listing, embedded: true, ...(columns === undefined ? {} : { columns }), onOpen: (row) => onChoose(String(row[key]), row) }) }));
|
|
73
83
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { isList } from "../../core/list.js";
|
|
4
4
|
import { useLookup } from "../../react/useLookup.js";
|
|
5
|
+
import { presentationOf } from "../list/presentation.js";
|
|
5
6
|
import { TagsField } from "@sincpro/web-ui";
|
|
6
7
|
/**
|
|
7
8
|
* A many2many: put SEVERAL records of an entity on this one — the followers of an invoice,
|
|
@@ -26,11 +27,21 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
|
|
|
26
27
|
values: value,
|
|
27
28
|
});
|
|
28
29
|
const person = (isList(entity) ? entity.entity : entity).summary.person === true;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const look = presentationOf(entity).option;
|
|
31
|
+
// A chip says a name and shows a face; the list under it also the datum that tells two apart
|
|
32
|
+
// (web-ui 1.5 `TagOption.meta`, never on the chip). Of the entity's look of a choice, those
|
|
33
|
+
// three — as text: a tag option is plain.
|
|
34
|
+
const asTag = (one) => {
|
|
35
|
+
const own = look === undefined || one.record === undefined ? {} : look(one.record);
|
|
36
|
+
const avatar = own.avatar ?? (person ? (one.image ?? true) : undefined);
|
|
37
|
+
const meta = typeof own.meta === "string" ? own.meta : one.detail;
|
|
38
|
+
return {
|
|
39
|
+
value: one.id,
|
|
40
|
+
label: own.name ?? one.label,
|
|
41
|
+
...(avatar === undefined ? {} : { avatar }),
|
|
42
|
+
...(meta === undefined || meta === "" ? {} : { meta }),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
34
45
|
const offered = new Set(lookup.options.map((one) => one.id));
|
|
35
46
|
// The chosen ride along for their labels; the field never offers them again.
|
|
36
47
|
const options = [
|
|
@@ -10,6 +10,12 @@ import { type EntityListProps } from "../list/EntityList.js";
|
|
|
10
10
|
* entity's own search template: the lines of an order are searched by product, the invoices of
|
|
11
11
|
* a customer by number. The column that points back to this record is left out — it is the
|
|
12
12
|
* same on every row. Use `RecordLines` when the page the record brought is all there is.
|
|
13
|
+
*
|
|
14
|
+
* «Agregar» opens the form of a new related record already pointing back here, where the view
|
|
15
|
+
* says (`RecordOpening.create`: a modal that answers, in a workspace), and the list is read
|
|
16
|
+
* again once it exists. Never a row of the table: each one is an aggregate with its own create,
|
|
17
|
+
* rules and preview. There is none while this record does not exist yet — there is nothing to
|
|
18
|
+
* point back to — nor when the relation is read only or the entity cannot be created.
|
|
13
19
|
*/
|
|
14
20
|
export declare function RelatedList<P extends AnyRecord, T extends AnyRecord>({ record, name, entity, pageSize, ...list }: {
|
|
15
21
|
record: RecordReading<P>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
3
4
|
import { defaultFields } from "../../core/present.js";
|
|
4
5
|
import { useRelated } from "../../react/useRelated.js";
|
|
5
6
|
import { EntityList } from "../list/EntityList.js";
|
|
7
|
+
import { useRecordOpening } from "./opening.js";
|
|
8
|
+
import { Button } from "@sincpro/web-ui";
|
|
6
9
|
import { useMemo } from "react";
|
|
7
10
|
/**
|
|
8
11
|
* A relation of a record as a list inside it — searched, ordered and paged by the server.
|
|
@@ -12,9 +15,16 @@ import { useMemo } from "react";
|
|
|
12
15
|
* entity's own search template: the lines of an order are searched by product, the invoices of
|
|
13
16
|
* a customer by number. The column that points back to this record is left out — it is the
|
|
14
17
|
* same on every row. Use `RecordLines` when the page the record brought is all there is.
|
|
18
|
+
*
|
|
19
|
+
* «Agregar» opens the form of a new related record already pointing back here, where the view
|
|
20
|
+
* says (`RecordOpening.create`: a modal that answers, in a workspace), and the list is read
|
|
21
|
+
* again once it exists. Never a row of the table: each one is an aggregate with its own create,
|
|
22
|
+
* rules and preview. There is none while this record does not exist yet — there is nothing to
|
|
23
|
+
* point back to — nor when the relation is read only or the entity cannot be created.
|
|
15
24
|
*/
|
|
16
25
|
export function RelatedList({ record, name, entity, pageSize, ...list }) {
|
|
17
26
|
const listing = useRelated(record, name, entity, pageSize === undefined ? {} : { pageSize });
|
|
27
|
+
const opening = useRecordOpening();
|
|
18
28
|
// Every row points back to THIS record: the column that says so is the same on all of them.
|
|
19
29
|
const back = record.meta?.fields[name]?.identified_by;
|
|
20
30
|
const own = list.columns;
|
|
@@ -22,5 +32,19 @@ export function RelatedList({ record, name, entity, pageSize, ...list }) {
|
|
|
22
32
|
(listing.meta === null || !back
|
|
23
33
|
? undefined
|
|
24
34
|
: defaultFields(listing.meta).filter((field) => field !== back)), [own, listing.meta, back]);
|
|
25
|
-
|
|
35
|
+
const create = opening?.create;
|
|
36
|
+
// The value the rows point back with — the same key `useRelated` scopes the list by.
|
|
37
|
+
const identity = record.meta?.get_id || record.meta?.identity || "id";
|
|
38
|
+
const here = record.record === null ? undefined : record.record[identity];
|
|
39
|
+
const adding = create === undefined ||
|
|
40
|
+
entity.create === undefined ||
|
|
41
|
+
!back ||
|
|
42
|
+
record.isNew ||
|
|
43
|
+
here === undefined ||
|
|
44
|
+
record.edit.state(name).readonly ? null : (_jsx(Button, { size: "sm", role: "secondary", onClick: () => create(entity, { [back]: here }, listing.reload), children: frameworkCopy().record.add }));
|
|
45
|
+
return (_jsx(EntityList, { listing: listing, embedded: true, ...list, ...(columns === undefined ? {} : { columns }), ...(adding === null && list.actions === undefined
|
|
46
|
+
? {}
|
|
47
|
+
: {
|
|
48
|
+
actions: (_jsxs(_Fragment, { children: [list.actions, adding] })),
|
|
49
|
+
}) }));
|
|
26
50
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { Entity } from "../../core/entity.js";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
/** What a control of a field receives: its value, how to change it, and its state now. */
|
|
5
|
+
export type FieldControl = {
|
|
6
|
+
value: unknown;
|
|
7
|
+
set: (value: unknown) => void;
|
|
8
|
+
readonly: boolean;
|
|
9
|
+
invalid: boolean;
|
|
10
|
+
label: string;
|
|
11
|
+
/** No `Field` names it — a cell of a table: the control carries its label itself. Inside a
|
|
12
|
+
* `Field` it must not, or React Aria reads both and names it «Precio Precio». */
|
|
13
|
+
standalone?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
|
|
17
|
+
* list of words,
|
|
18
|
+
* a text.
|
|
19
|
+
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
20
|
+
* one rule for what a value is edited with.
|
|
21
|
+
*/
|
|
22
|
+
export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
|
|
23
|
+
value: unknown;
|
|
24
|
+
label: string;
|
|
25
|
+
}[]): ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
28
|
+
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
29
|
+
*
|
|
30
|
+
* Context: shared by a record's field and a line. Inside a line (`ownChooser`: its row or its
|
|
31
|
+
* dialog) «Buscar más…» is the picker's own chooser, never the workspace's: the workspace opens
|
|
32
|
+
* it outside the line — a row commits when the focus leaves it, and the answer would land on a
|
|
33
|
+
* line no longer being written; over the line's dialog it would be a modal over a modal.
|
|
34
|
+
*/
|
|
35
|
+
export declare function RelationPicker({ target, value, onChange, label, ownChooser, standalone, }: {
|
|
36
|
+
target: Entity;
|
|
37
|
+
value: string;
|
|
38
|
+
onChange: (id: string, chosen?: AnyRecord) => void;
|
|
39
|
+
label: string;
|
|
40
|
+
ownChooser?: boolean;
|
|
41
|
+
/** No `Field` names it (a cell): it carries `label` itself — as `FieldControl.standalone`. */
|
|
42
|
+
standalone?: boolean;
|
|
43
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { instantOf, timeZoneNow, wallTimeOf } from "../../core/zone.js";
|
|
4
|
+
import { EntityPicker } from "./EntityPicker.js";
|
|
5
|
+
import { useRecordOpening } from "./opening.js";
|
|
6
|
+
import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
|
|
7
|
+
/**
|
|
8
|
+
* The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
|
|
9
|
+
* list of words,
|
|
10
|
+
* a text.
|
|
11
|
+
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
12
|
+
* one rule for what a value is edited with.
|
|
13
|
+
*/
|
|
14
|
+
export function controlFor(control, type, exact, choices) {
|
|
15
|
+
const { value, set } = control;
|
|
16
|
+
const named = control.standalone === true ? { "aria-label": control.label } : {};
|
|
17
|
+
if (choices.length > 0)
|
|
18
|
+
return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "boolean":
|
|
21
|
+
return _jsx(Checkbox, { checked: value === true, onChange: set, label: control.label });
|
|
22
|
+
case "integer":
|
|
23
|
+
case "number":
|
|
24
|
+
return (_jsx(NumberInput, { value: value === null || value === undefined || value === "" ? "" : Number(value),
|
|
25
|
+
// A decimal travels as text so no digit is lost; the server reads it that way back.
|
|
26
|
+
onChange: (next) => set(next === "" ? null : exact ? String(next) : next), ...named }));
|
|
27
|
+
case "datetime": {
|
|
28
|
+
// An instant from the server, typed on the wall clock of the installed zone.
|
|
29
|
+
const zone = timeZoneNow();
|
|
30
|
+
return (_jsx(DateTimePicker, { value: typeof value === "string" && value !== "" ? wallTimeOf(value, zone) : null, onChange: (wall) => set(wall === null ? null : instantOf(wall, zone)), ...named }));
|
|
31
|
+
}
|
|
32
|
+
case "date":
|
|
33
|
+
return (_jsx(DatePicker, { value: typeof value === "string" && value !== "" ? value : null, onChange: set, ...named }));
|
|
34
|
+
case "text[]": {
|
|
35
|
+
// A list of words is chips: each word is its own key, and typing a new one adds it.
|
|
36
|
+
const words = Array.isArray(value) ? value.map(String) : [];
|
|
37
|
+
return (_jsx(TagsField, { value: words, options: words.map((word) => ({ value: word, label: word })), onChange: set, onCreate: (word) => word, ...named }));
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
return (_jsx(TextInput, { value: value === null || value === undefined ? "" : String(value), onChange: set, ...named }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
45
|
+
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
46
|
+
*
|
|
47
|
+
* Context: shared by a record's field and a line. Inside a line (`ownChooser`: its row or its
|
|
48
|
+
* dialog) «Buscar más…» is the picker's own chooser, never the workspace's: the workspace opens
|
|
49
|
+
* it outside the line — a row commits when the focus leaves it, and the answer would land on a
|
|
50
|
+
* line no longer being written; over the line's dialog it would be a modal over a modal.
|
|
51
|
+
*/
|
|
52
|
+
export function RelationPicker({ target, value, onChange, label, ownChooser = false, standalone = false, }) {
|
|
53
|
+
const opening = useRecordOpening();
|
|
54
|
+
return (_jsx(EntityPicker, { entity: target, value: value, onChange: onChange,
|
|
55
|
+
// «Buscar más…» is an option of the picker already: no second button beside it.
|
|
56
|
+
browse: false, ...(standalone ? { "aria-label": label } : {}), ...(opening === null
|
|
57
|
+
? {}
|
|
58
|
+
: {
|
|
59
|
+
onOpen: (chosen, to) => opening.open(target.ref(chosen), to),
|
|
60
|
+
openTargets: opening.targets,
|
|
61
|
+
...(ownChooser || opening.choose === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: {
|
|
64
|
+
onBrowseAll: (query) => opening.choose?.(target, (id) => onChange(id), query),
|
|
65
|
+
}),
|
|
66
|
+
}) }));
|
|
67
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { type AnyRecord } from "@sincpro/criteria";
|
|
1
2
|
import type { RecordReading } from "../../react/useRecord.js";
|
|
3
|
+
import type { EntityListProps } from "../list/EntityList.js";
|
|
4
|
+
import { type FieldControl } from "./control.js";
|
|
5
|
+
import { type LinesLook } from "./lines.js";
|
|
6
|
+
export type { FieldControl } from "./control.js";
|
|
2
7
|
import { type DirtyState } from "@sincpro/web-ui";
|
|
3
8
|
import type { ReactNode } from "react";
|
|
4
9
|
/**
|
|
@@ -18,22 +23,25 @@ import type { ReactNode } from "react";
|
|
|
18
23
|
* search, the ten first, «Buscar más…» — and, read-only, the record's name as a link. Where it
|
|
19
24
|
* opens is the view's (`RecordOpening`: a modal in a workspace, nothing outside one).
|
|
20
25
|
*
|
|
26
|
+
* A one2many is a block: its lines (`lines`) or its related list (`list`), each with every piece
|
|
27
|
+
* replaceable the screen's way.
|
|
28
|
+
*
|
|
21
29
|
* <RecordField record={invoice} name="due_date" />
|
|
22
30
|
* <RecordField record={invoice} name="customer_id" />
|
|
31
|
+
* <RecordField record={invoice} name="lines" lines={{ controls: { qty: Stepper } }} />
|
|
23
32
|
*/
|
|
24
|
-
export
|
|
25
|
-
value: unknown;
|
|
26
|
-
set: (value: unknown) => void;
|
|
27
|
-
readonly: boolean;
|
|
28
|
-
invalid: boolean;
|
|
29
|
-
label: string;
|
|
30
|
-
};
|
|
31
|
-
export declare function RecordField<T extends Record<string, unknown>>({ record, name, as, bare, }: {
|
|
33
|
+
export declare function RecordField<T extends Record<string, unknown>>({ record, name, as, bare, lines: look, list: listed, }: {
|
|
32
34
|
record: RecordReading<T>;
|
|
33
35
|
name: string;
|
|
34
36
|
as?: (control: FieldControl) => ReactNode;
|
|
35
37
|
/** The control without its label — inside a page or a section that already names it. */
|
|
36
38
|
bare?: boolean;
|
|
39
|
+
/** Lines (a one2many of no entity of its own), the screen's way: where a line is written,
|
|
40
|
+
* which columns, a cell or a control of its own, columns that are not fields, the dialog. */
|
|
41
|
+
lines?: LinesLook;
|
|
42
|
+
/** A one2many of a declared entity, the screen's way: anything `EntityList` takes — its
|
|
43
|
+
* cells, row actions, commands, faces of its own. What it passes wins over the defaults. */
|
|
44
|
+
list?: Omit<EntityListProps<AnyRecord>, "listing" | "embedded">;
|
|
37
45
|
}): import("react").JSX.Element | null;
|
|
38
46
|
/**
|
|
39
47
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|