@sincpro/web-framework 3.3.0 → 3.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/dist/core/copy.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ export type FrameworkCopy = {
|
|
|
69
69
|
archive: string;
|
|
70
70
|
/** Out of the trash (`Restore`): read again. */
|
|
71
71
|
restore: string;
|
|
72
|
+
/** The record's main card in web-ui's «settings» form style, beside its other sections. */
|
|
73
|
+
general: string;
|
|
72
74
|
};
|
|
73
75
|
picker: {
|
|
74
76
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
package/dist/core/copy.js
CHANGED
|
@@ -36,6 +36,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
36
36
|
delete: "Delete",
|
|
37
37
|
archive: "Move to the trash",
|
|
38
38
|
restore: "Restore",
|
|
39
|
+
general: "General",
|
|
39
40
|
},
|
|
40
41
|
picker: {
|
|
41
42
|
browse: "Search all",
|
|
@@ -125,6 +126,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
125
126
|
delete: "Eliminar",
|
|
126
127
|
archive: "Mover a la papelera",
|
|
127
128
|
restore: "Restaurar",
|
|
129
|
+
general: "Datos generales",
|
|
128
130
|
},
|
|
129
131
|
picker: {
|
|
130
132
|
browse: "Buscar en todos",
|
|
@@ -24,11 +24,15 @@ export type FieldControl = {
|
|
|
24
24
|
* note, so every application passed `as` for each long text. Only the framework's own names are
|
|
25
25
|
* read here: a name an application registers is drawn with `as`, never looked up in a registry
|
|
26
26
|
* of strings.
|
|
27
|
+
*
|
|
28
|
+
* `segmented`: the form asks for a short choice to be a segmented control — web-ui's «settings»
|
|
29
|
+
* form style, for a REQUIRED choice (a segmented control cannot be emptied). It still is a select
|
|
30
|
+
* in a cell, and with more than three options or a label that would not fit beside the others.
|
|
27
31
|
*/
|
|
28
32
|
export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
|
|
29
33
|
value: unknown;
|
|
30
34
|
label: string;
|
|
31
|
-
}[], widget?: string): ReactNode;
|
|
35
|
+
}[], widget?: string, segmented?: boolean): ReactNode;
|
|
32
36
|
/**
|
|
33
37
|
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
34
38
|
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
|
|
4
4
|
import { EntityPicker } from "./EntityPicker.js";
|
|
5
|
-
import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
5
|
+
import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, SegmentedControl, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
6
|
+
/** A choice answered with one press — a segmented control — instead of a select: up to three
|
|
7
|
+
* options that fit side by side. */
|
|
8
|
+
const FEW_CHOICES = 3;
|
|
9
|
+
const SHORT_LABEL = 24;
|
|
6
10
|
/**
|
|
7
11
|
* The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
|
|
8
12
|
* date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
|
|
@@ -15,14 +19,24 @@ import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, Select, T
|
|
|
15
19
|
* note, so every application passed `as` for each long text. Only the framework's own names are
|
|
16
20
|
* read here: a name an application registers is drawn with `as`, never looked up in a registry
|
|
17
21
|
* of strings.
|
|
22
|
+
*
|
|
23
|
+
* `segmented`: the form asks for a short choice to be a segmented control — web-ui's «settings»
|
|
24
|
+
* form style, for a REQUIRED choice (a segmented control cannot be emptied). It still is a select
|
|
25
|
+
* in a cell, and with more than three options or a label that would not fit beside the others.
|
|
18
26
|
*/
|
|
19
|
-
export function controlFor(control, type, exact, choices, widget) {
|
|
27
|
+
export function controlFor(control, type, exact, choices, widget, segmented = false) {
|
|
20
28
|
const { value, set } = control;
|
|
21
29
|
const named = control.standalone === true ? { "aria-label": control.label } : {};
|
|
22
30
|
// Several of the values at once — a list whose values are a choice: each one a check, the
|
|
23
31
|
// list's label above them.
|
|
24
32
|
if (choices.length > 0 && type.endsWith("[]"))
|
|
25
33
|
return (_jsx(CheckList, { label: control.label, items: choices.map((one) => ({ value: String(one.value), label: one.label })), value: Array.isArray(value) ? value.map(String) : [], onChange: set }));
|
|
34
|
+
if (segmented &&
|
|
35
|
+
control.standalone !== true &&
|
|
36
|
+
choices.length > 0 &&
|
|
37
|
+
choices.length <= FEW_CHOICES &&
|
|
38
|
+
choices.every((one) => one.label.length <= SHORT_LABEL))
|
|
39
|
+
return (_jsx(SegmentedControl, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set }));
|
|
26
40
|
if (choices.length > 0)
|
|
27
41
|
return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
|
|
28
42
|
switch (type) {
|
package/dist/web/record/edit.js
CHANGED
|
@@ -14,7 +14,7 @@ import { RecordLinesEditor } from "./lines.js";
|
|
|
14
14
|
import { useRecordOpening } from "./opening.js";
|
|
15
15
|
import { RecordLines } from "./record.js";
|
|
16
16
|
import { RelatedList } from "./RelatedList.js";
|
|
17
|
-
import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
|
|
17
|
+
import { Checkbox, Field, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
|
|
18
18
|
/** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
|
|
19
19
|
function setAt(value, path, next) {
|
|
20
20
|
const base = typeof value === "object" && value !== null ? value : {};
|
|
@@ -79,6 +79,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
79
79
|
const target = useEntityFor(relation?.target);
|
|
80
80
|
const opening = useRecordOpening();
|
|
81
81
|
const { metas } = useFramework();
|
|
82
|
+
const settings = useFormStyle() === "settings";
|
|
82
83
|
if (!state.visible)
|
|
83
84
|
return null;
|
|
84
85
|
// A one2many is a BLOCK, named by a section — never a `Field`: web-ui's controls read the
|
|
@@ -191,7 +192,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
191
192
|
return controlFor(control, view.type, false, choices, field?.widget);
|
|
192
193
|
if (view.type === "boolean" && as === undefined)
|
|
193
194
|
return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
|
|
194
|
-
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
|
|
195
|
+
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
|
|
196
|
+
// Said only in web-ui's «settings» form style: a field that may stay empty, and is typed in.
|
|
197
|
+
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, field?.widget, settings && state.required)) }));
|
|
195
198
|
}
|
|
196
199
|
/**
|
|
197
200
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
|
@@ -17,7 +17,7 @@ import { dirtyOf, RecordField } from "../record/edit.js";
|
|
|
17
17
|
import { RecordLifecycle } from "../record/RecordLifecycle.js";
|
|
18
18
|
import { Refused } from "../Refused.js";
|
|
19
19
|
import { useRecordInWorkspace } from "./workspace.js";
|
|
20
|
-
import { Button, Callout, FormSection, Record, Skeleton } from "@sincpro/web-ui";
|
|
20
|
+
import { Button, Callout, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
|
|
21
21
|
import { useState } from "react";
|
|
22
22
|
/**
|
|
23
23
|
* The record of an entity, drawn from its model — the screen `entityView` opens when the
|
|
@@ -158,6 +158,7 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
|
|
|
158
158
|
// On a phone a form is one column, its label over its value: two side by side at 400 px
|
|
159
159
|
// squeezed a text area beside its word (web-ui's grid does not narrow by itself).
|
|
160
160
|
const phone = usePhone(api);
|
|
161
|
+
const settings = useFormStyle() === "settings";
|
|
161
162
|
if (reading.status === "loading")
|
|
162
163
|
return _jsx(Skeleton, { rows: 6, label: copy.loading });
|
|
163
164
|
if (reading.status === "failed")
|
|
@@ -180,7 +181,9 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
|
|
|
180
181
|
const own = actions?.(reading) ?? null;
|
|
181
182
|
const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
|
|
182
183
|
const tabs = pages ?? layout.pages;
|
|
183
|
-
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns,
|
|
184
|
+
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns, ...(settings && fields === undefined && layout.sections.length > 0
|
|
185
|
+
? { title: copy.general }
|
|
186
|
+
: {}), children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
|
|
184
187
|
? null
|
|
185
188
|
: layout.sections.map((name) => (_jsx(FormSection, { title: labelOf(meta, name, locale), columns: columns, children: Object.keys(meta?.fields[name]?.definition?.fields ?? {}).map((part) => (_jsx(RecordField, { record: reading, name: `${name}.${part}` }, part))) }, name))), edit.advice
|
|
186
189
|
.filter((one) => (one.path?.length ?? 0) <= 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@sincpro/criteria": "^2.2.2",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.7.0",
|
|
47
|
-
"@sincpro/web-ui": "^2.
|
|
47
|
+
"@sincpro/web-ui": "^2.5.0",
|
|
48
48
|
"react": ">=19",
|
|
49
49
|
"react-dom": ">=19"
|
|
50
50
|
},
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@sincpro/criteria": "^2.2.2",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.8.0",
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
79
|
+
"@sincpro/web-ui": "^2.5.0",
|
|
80
80
|
"@storybook/addon-a11y": "10.6.5",
|
|
81
81
|
"@storybook/addon-docs": "10.6.5",
|
|
82
82
|
"@storybook/addon-mcp": "10.6.5",
|