@sincpro/web-framework 0.1.0 → 0.3.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 +298 -40
- package/dist/core/cache.js +2 -2
- package/dist/core/copy.d.ts +26 -0
- package/dist/core/copy.js +32 -0
- package/dist/core/edit.d.ts +48 -3
- package/dist/core/edit.js +79 -5
- package/dist/core/entity.d.ts +46 -0
- package/dist/core/entity.js +57 -0
- package/dist/core/form.d.ts +21 -0
- package/dist/core/form.js +30 -0
- package/dist/core/index.d.ts +11 -3
- package/dist/core/index.js +10 -2
- package/dist/core/lines.d.ts +53 -0
- package/dist/core/lines.js +120 -0
- package/dist/core/list.d.ts +64 -0
- package/dist/core/list.js +22 -0
- package/dist/core/lookup.d.ts +7 -2
- package/dist/core/lookup.js +8 -2
- package/dist/core/measure.d.ts +16 -0
- package/dist/core/measure.js +38 -0
- package/dist/core/memory.js +18 -4
- package/dist/core/relation.d.ts +28 -0
- package/dist/core/relation.js +30 -0
- package/dist/core/rest.d.ts +5 -9
- package/dist/core/rest.js +25 -7
- package/dist/core/retry.d.ts +24 -0
- package/dist/core/retry.js +25 -0
- package/dist/core/summary.d.ts +50 -0
- package/dist/core/summary.js +54 -0
- package/dist/core/trail.d.ts +44 -0
- package/dist/core/trail.js +70 -0
- package/dist/core/transport.d.ts +22 -2
- package/dist/react/context.d.ts +20 -1
- package/dist/react/context.js +10 -2
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +4 -1
- package/dist/react/useCommand.d.ts +3 -1
- package/dist/react/useCommand.js +12 -4
- package/dist/react/useGroups.d.ts +52 -0
- package/dist/react/useGroups.js +110 -0
- package/dist/react/useListing.d.ts +29 -7
- package/dist/react/useListing.js +49 -8
- package/dist/react/useLookup.d.ts +30 -5
- package/dist/react/useLookup.js +56 -3
- package/dist/react/usePivot.d.ts +33 -0
- package/dist/react/usePivot.js +59 -0
- package/dist/react/useRecord.d.ts +28 -9
- package/dist/react/useRecord.js +156 -18
- package/dist/react/useSummary.d.ts +15 -0
- package/dist/react/useSummary.js +22 -0
- package/dist/web/index.d.ts +15 -3
- package/dist/web/index.js +14 -2
- package/dist/web/list/EntityList.d.ts +69 -7
- package/dist/web/list/EntityList.js +281 -23
- package/dist/web/list/EntitySearchBar.d.ts +16 -8
- package/dist/web/list/EntitySearchBar.js +52 -4
- package/dist/web/list/columns.d.ts +0 -13
- package/dist/web/list/columns.js +20 -1
- package/dist/web/list/groups.d.ts +17 -0
- package/dist/web/list/groups.js +80 -0
- 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/list/rowCommands.d.ts +41 -0
- package/dist/web/list/rowCommands.js +56 -0
- package/dist/web/record/EntityPicker.d.ts +45 -14
- package/dist/web/record/EntityPicker.js +64 -20
- package/dist/web/record/EntityTags.d.ts +38 -0
- package/dist/web/record/EntityTags.js +52 -0
- package/dist/web/record/RelatedList.d.ts +8 -1
- package/dist/web/record/RelatedList.js +37 -3
- package/dist/web/record/control.d.ts +42 -0
- package/dist/web/record/control.js +60 -0
- package/dist/web/record/edit.d.ts +27 -12
- package/dist/web/record/edit.js +92 -25
- package/dist/web/record/lines.d.ts +84 -0
- package/dist/web/record/lines.js +190 -0
- package/dist/web/record/opening.d.ts +34 -0
- package/dist/web/record/opening.js +10 -0
- package/dist/web/record/summary.d.ts +22 -0
- package/dist/web/record/summary.js +63 -0
- package/dist/web/workspace/SincproApp.d.ts +4 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/dist/web/workspace/composer.d.ts +27 -4
- package/dist/web/workspace/composer.js +75 -7
- package/dist/web/workspace/open.d.ts +49 -0
- package/dist/web/workspace/open.js +51 -0
- package/dist/web/workspace/record.d.ts +30 -0
- package/dist/web/workspace/record.js +83 -0
- package/dist/web/workspace/skin.d.ts +0 -9
- package/dist/web/workspace/skin.js +25 -13
- package/dist/web/workspace/workspace.d.ts +33 -3
- package/dist/web/workspace/workspace.js +63 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ server — entities, criteria, commands, drafts, events — and puts it on scree
|
|
|
8
8
|
application declares its entities and names its fields; the rest follows.
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
yarn add @sincpro/web-framework @sincpro/web-ui @sincpro/criteria @sincpro/criteria-react react react-dom
|
|
11
|
+
yarn add @sincpro/web-framework @sincpro/web-ui @sincpro/web-composer @sincpro/criteria @sincpro/criteria-react react react-dom
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Requires React 19 or newer.
|
|
@@ -61,64 +61,246 @@ be able to build it here, without asking us and without fighting us. So:
|
|
|
61
61
|
| **this package** | The glue: entity + model definition + state + actions, drawn with web-ui, opened with composer |
|
|
62
62
|
| Your application | What an invoice is |
|
|
63
63
|
|
|
64
|
-
## How it
|
|
64
|
+
## How it fits together
|
|
65
|
+
|
|
66
|
+
Three packages, one direction. **web-ui draws and tells** («they pressed this name, and asked
|
|
67
|
+
for a modal»); it never imports composer and never knows where anything opens. **Composer
|
|
68
|
+
decides where** — page, modal, preview, side panel, window, the breadcrumb, the phone — and never
|
|
69
|
+
draws a record. **This package connects them**, from what the server publishes about each model.
|
|
70
|
+
|
|
71
|
+
```mermaid
|
|
72
|
+
flowchart LR
|
|
73
|
+
subgraph server["sincpro_framework · the backend"]
|
|
74
|
+
api["entities · criteria · commands<br/>drafts · events · model definition"]
|
|
75
|
+
end
|
|
76
|
+
subgraph fw["@sincpro/web-framework · connects"]
|
|
77
|
+
direction TB
|
|
78
|
+
core["core/<br/>Transport · entity() · Meta<br/>textOf · summaryOf"]
|
|
79
|
+
react["react/<br/>useListing · useRecord<br/>useLookup · useSummaryOf"]
|
|
80
|
+
web["web/<br/>EntityList · EntityPicker · RelatedRecord<br/>openIn · entityView · SincproApp"]
|
|
81
|
+
core --> react --> web
|
|
82
|
+
end
|
|
83
|
+
ui["@sincpro/web-ui · draws and tells<br/>List · Record · Picker<br/>RelationValue · RecordCard"]
|
|
84
|
+
composer["@sincpro/web-composer · decides where<br/>page · modal · preview · side · window<br/>crumbs · ⌘K · phone"]
|
|
85
|
+
app["your application<br/>entity() + its screens"]
|
|
86
|
+
|
|
87
|
+
api <-->|"criteria over the wire<br/>(@sincpro/criteria)"| core
|
|
88
|
+
web -->|"props read from the model"| ui
|
|
89
|
+
ui -->|"gestures: onOpenIn(to), onChoose,<br/>onBrowseAll, onCreate"| web
|
|
90
|
+
web -->|"api.open · api.pick · api.setTitle"| composer
|
|
91
|
+
composer -->|"mounts the entity's view"| web
|
|
92
|
+
app -->|"declares"| fw
|
|
93
|
+
```
|
|
65
94
|
|
|
66
|
-
|
|
95
|
+
What happens when a person presses the customer of an invoice:
|
|
96
|
+
|
|
97
|
+
```mermaid
|
|
98
|
+
sequenceDiagram
|
|
99
|
+
actor person as Person
|
|
100
|
+
participant value as RelationValue<br/>(web-ui)
|
|
101
|
+
participant related as RelatedRecord / openIn<br/>(this package)
|
|
102
|
+
participant composer as Composer
|
|
103
|
+
participant view as Customer view<br/>(entityView)
|
|
104
|
+
participant server as Server
|
|
105
|
+
|
|
106
|
+
person->>value: presses «Globex Bolivia»
|
|
107
|
+
value->>related: onOpenIn("modal") — the first of openTargets
|
|
108
|
+
related->>related: targetsFor(api): inside a modal? then beside, never a modal
|
|
109
|
+
related->>composer: api.open(ventas:cliente/C-004, { to: "modal", size: 760×560 })
|
|
110
|
+
composer->>view: mounts the registered view over the invoice
|
|
111
|
+
view->>server: useRecord → the record (and its model, once)
|
|
112
|
+
server-->>view: record + meta
|
|
113
|
+
view->>composer: api.setTitle("Globex Bolivia") — the modal and the crumb say its name
|
|
114
|
+
```
|
|
67
115
|
|
|
68
|
-
|
|
69
|
-
|
|
116
|
+
Everything a screen shows about a value or a record is read from the model the same way, so a
|
|
117
|
+
cell, a fact, a card and a link cannot disagree:
|
|
118
|
+
|
|
119
|
+
```mermaid
|
|
120
|
+
flowchart LR
|
|
121
|
+
meta["Meta<br/>(server, defineMeta or OpenAPI)"] --> text["textOf<br/>«Pagada» · 12 mar 2026 · 1 150,50"]
|
|
122
|
+
meta --> summary["summaryOf<br/>name · description · state · type<br/>image · created · updated"]
|
|
123
|
+
record["a record"] --> text
|
|
124
|
+
record --> summary
|
|
125
|
+
declared["entity(…, { summary })"] -.->|"its own field names"| summary
|
|
126
|
+
text --> cells["columns · facts · chips"]
|
|
127
|
+
summary --> card["cardOf → RecordCard"]
|
|
128
|
+
summary --> relation["relationOf → RelationValue"]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Integrating it in an application
|
|
70
132
|
|
|
71
|
-
|
|
133
|
+
**1. Styles.** web-ui's tokens, and Tailwind told to look inside the packages (Tailwind v4 skips
|
|
134
|
+
`node_modules`, so their classes would never be generated). Composer brings its own sheet.
|
|
135
|
+
|
|
136
|
+
```css
|
|
137
|
+
@import "@sincpro/web-ui/tokens.css";
|
|
138
|
+
@source "../node_modules/@sincpro/web-ui/dist";
|
|
139
|
+
@source "../node_modules/@sincpro/web-framework/dist";
|
|
140
|
+
@source "./";
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**2. The transport** — the one door to the backend. The session is the application's: it puts
|
|
144
|
+
its headers here.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
72
147
|
export const transport = restTransport({
|
|
73
148
|
base: "/v1",
|
|
74
149
|
headers: () => ({ Authorization: `Bearer ${session.token}` }),
|
|
75
150
|
});
|
|
76
151
|
```
|
|
77
152
|
|
|
78
|
-
|
|
153
|
+
**3. The entities** — declared once: where each is read and written, and its key in the
|
|
154
|
+
workspace (`domain:kind`). `summary` only when its fields are not the conventional ones.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
export const customers = entity<Customer>("sales:customer", {
|
|
158
|
+
list: "/customers",
|
|
159
|
+
summary: { image: "logo", person: true },
|
|
160
|
+
});
|
|
161
|
+
export const invoices = entity<Invoice>("sales:invoice", {
|
|
162
|
+
list: "/invoices",
|
|
163
|
+
create: "POST /invoices",
|
|
164
|
+
save: "PUT /invoices/{id}",
|
|
165
|
+
commands: { post: "POST /invoices/{id}/post" },
|
|
166
|
+
history: { route: "/sales-events", type: "Invoice" },
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**4. The views** — each entity becomes a composer view: its list without an id, its record with
|
|
171
|
+
one, its search in ⌘K. Declared and nothing more, it already has both screens, drawn from its
|
|
172
|
+
model: `EntityList` (literal search on Enter, pages, «New») and `EntityRecord` (its name, type and
|
|
173
|
+
state on top; its fields in the model's order, a many2one as a picker of its entity; each
|
|
174
|
+
one2many in a tab; «save / discard», the conflict, the restored draft, who made it, its history;
|
|
175
|
+
«3 / 64» and the arrows to its neighbours when it was opened from a list).
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const views = [
|
|
179
|
+
entityView(invoices, { transport, name: "Invoices" }), // both screens, from the model
|
|
180
|
+
];
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
They are defaults, not cages: give your own screens, or keep `EntityRecord` and choose what it
|
|
184
|
+
shows.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
const views = [
|
|
188
|
+
entityView(invoices, {
|
|
189
|
+
transport,
|
|
190
|
+
name: "Invoices",
|
|
191
|
+
list: InvoiceList,
|
|
192
|
+
record: InvoiceView,
|
|
193
|
+
}),
|
|
194
|
+
entityView(customers, {
|
|
195
|
+
transport,
|
|
196
|
+
name: "Customers",
|
|
197
|
+
list: CustomerList,
|
|
198
|
+
record: CustomerView,
|
|
199
|
+
}),
|
|
200
|
+
];
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**5. The application** — transport, language (web-ui's, composer's and the framework's words),
|
|
204
|
+
cache, toasts and the workspace, in one place:
|
|
79
205
|
|
|
80
206
|
```tsx
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
207
|
+
<SincproApp
|
|
208
|
+
transport={transport}
|
|
209
|
+
views={views}
|
|
210
|
+
entities={[invoices, customers]} // a relation of a model resolves to one of these, alone
|
|
211
|
+
start={invoices.ref()}
|
|
212
|
+
language="es"
|
|
213
|
+
/>
|
|
84
214
|
```
|
|
85
215
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
216
|
+
An application with its own shell mounts the same pieces itself: `FrameworkProvider`, composer's
|
|
217
|
+
`Composer` with `webUiSkin`, and the three copy tables.
|
|
218
|
+
|
|
219
|
+
**6. The screens.** A list is the entity and the names of its fields — the server searches,
|
|
220
|
+
filters, orders, groups and pages; a row opens the record's page:
|
|
90
221
|
|
|
91
222
|
```tsx
|
|
92
|
-
function
|
|
223
|
+
function InvoiceList({ api }: ViewProps) {
|
|
93
224
|
const listing = useListing(invoices);
|
|
94
225
|
return (
|
|
95
226
|
<EntityList
|
|
96
227
|
listing={listing}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
id: "paid",
|
|
101
|
-
label: "Only paid",
|
|
102
|
-
where: { field: "state", operator: "=", value: "paid" },
|
|
103
|
-
},
|
|
104
|
-
]}
|
|
105
|
-
onOpen={(row) => api.open(invoiceRef(row.number))}
|
|
228
|
+
api={api}
|
|
229
|
+
columns={["number", "customer", "state", "amount_total"]}
|
|
106
230
|
/>
|
|
107
231
|
);
|
|
108
232
|
}
|
|
109
233
|
```
|
|
110
234
|
|
|
111
|
-
|
|
235
|
+
A record keeps writing web-ui's `Record` tree. Its fields come from the model; a related record
|
|
236
|
+
is read with its summary and opened where it belongs; a many2one is chosen with a literal search
|
|
237
|
+
on the server, and «Buscar más…» opens the customers' own list to choose from:
|
|
112
238
|
|
|
113
239
|
```tsx
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
240
|
+
function InvoiceView({ api, resource }: ViewProps) {
|
|
241
|
+
const invoice = useRecord(invoices, resource.id ?? "");
|
|
242
|
+
const crumbs = useCrumbs(api);
|
|
243
|
+
useRecordInWorkspace(api, invoice); // its real name in the crumb, «unsaved» asks first
|
|
244
|
+
const dirty = dirtyOf(invoice); // «Save / Discard» while something was typed
|
|
245
|
+
if (invoice.status !== "ready") return <Skeleton rows={4} label="Loading" />;
|
|
246
|
+
return (
|
|
247
|
+
<Record
|
|
248
|
+
identity={{ title: invoice.record.number }}
|
|
249
|
+
{...(dirty === undefined ? {} : { dirty })}
|
|
250
|
+
>
|
|
251
|
+
<Record.Rail>
|
|
252
|
+
<Record.Crumbs crumbs={crumbs} />
|
|
253
|
+
{/* Always there on an edited record: without them web-ui remounts the paper on «dirty». */}
|
|
254
|
+
<Record.Actions>
|
|
255
|
+
<CommandButton entity={invoices} id={invoice.id} command="post" label="Post" />
|
|
256
|
+
</Record.Actions>
|
|
257
|
+
</Record.Rail>
|
|
258
|
+
<Record.Paper>
|
|
259
|
+
<Field label="Customer">
|
|
260
|
+
<RelatedRecord api={api} entity={customers} value={invoice.record.customer} />
|
|
261
|
+
</Field>
|
|
262
|
+
<RecordField
|
|
263
|
+
record={invoice}
|
|
264
|
+
name="customer_id"
|
|
265
|
+
as={({ value, set }) => (
|
|
266
|
+
<EntityPicker
|
|
267
|
+
entity={customers}
|
|
268
|
+
value={String(value ?? "")}
|
|
269
|
+
onChange={set}
|
|
270
|
+
onBrowseAll={chooserIn(api, customers, set)}
|
|
271
|
+
/>
|
|
272
|
+
)}
|
|
273
|
+
/>
|
|
274
|
+
<RecordField record={invoice} name="notes" />
|
|
275
|
+
</Record.Paper>
|
|
276
|
+
</Record>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
How a record of an entity LOOKS — as a choice, a row, a card — is said once, around the entity,
|
|
282
|
+
and every place that draws one uses it (`EntityPicker`, `EntityTags`, ⌘K, `EntityList`'s rows and
|
|
283
|
+
board). Each size answers web-ui's props for it, over the default; give only what changes:
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
export const customers = presented(
|
|
287
|
+
entity<Customer>("sales:customer", { list: "/customers" }),
|
|
288
|
+
{
|
|
289
|
+
option: (c) => ({ meta: `NIT ${c.tax_id}`, aside: <Balance value={c.balance} /> }),
|
|
290
|
+
row: (c) => (c.blocked ? { tags: <Tag tone="bad">Blocked</Tag> } : {}),
|
|
291
|
+
card: (c) => ({ subtitle: c.city }),
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Any record, at any size, from its summary:
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
const summarize = useSummaryOf(customers);
|
|
300
|
+
<RecordCard
|
|
301
|
+
{...cardOf(summarize(row))}
|
|
302
|
+
onOpen={() => openIn(api, customers.ref(row.id), "page")}
|
|
303
|
+
/>;
|
|
122
304
|
```
|
|
123
305
|
|
|
124
306
|
A domain with no sincpro_framework behind it declares its model by hand and is drawn the same
|
|
@@ -138,17 +320,75 @@ const tickets = defineMeta({
|
|
|
138
320
|
});
|
|
139
321
|
```
|
|
140
322
|
|
|
323
|
+
## The abstractions
|
|
324
|
+
|
|
325
|
+
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
326
|
+
hook and draw your own, or go straight to the loose piece.
|
|
327
|
+
|
|
328
|
+
| Question | Declarative | Hook | Loose piece |
|
|
329
|
+
| -------------------------------- | ------------------------------------------------------- | ------------------------------------- | ------------------------------------ |
|
|
330
|
+
| Where is the data? | `entity()` | — | `restTransport`, `memoryTransport` |
|
|
331
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
332
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
333
|
+
| How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
|
|
334
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
335
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
336
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | — | `formOf` |
|
|
337
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
338
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
339
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
340
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
341
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
342
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
343
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
344
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
345
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
346
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
|
|
347
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
348
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
349
|
+
| Act on it (with a dry run) | `CommandButton`, `commands` on rows | `useCommand` | `transport.send` |
|
|
350
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
351
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
352
|
+
|
|
353
|
+
The rules behind them, in short:
|
|
354
|
+
|
|
355
|
+
- **A reference names any record** (`domain:kind/id`, `entity.ref(id)`). Two contexts talk by
|
|
356
|
+
reference, never by import; whatever must survive a reload travels in it.
|
|
357
|
+
- **A related record opens in a modal** the size of a record, and «Abrir en…» offers preview,
|
|
358
|
+
side and page. **From inside a modal**, beside or as a preview — never a modal over a modal.
|
|
359
|
+
`openIn` decides it from what composer says about the view, so no screen writes it.
|
|
360
|
+
- **What a record does not have is not drawn**: no picture, no image; no state, no tag.
|
|
361
|
+
- **Every word on screen** is the model's (`labelOf`, `choiceLabelOf`) or the framework's copy
|
|
362
|
+
table (`frameworkCopy()`), never a string in a component.
|
|
363
|
+
|
|
364
|
+
### Where state lives
|
|
365
|
+
|
|
366
|
+
There is no store of ours to learn: each kind of state already has its owner.
|
|
367
|
+
|
|
368
|
+
| State | Lives in | Read with |
|
|
369
|
+
| -------------------------------------------- | -------------------------------------------------- | ---------------------------------- |
|
|
370
|
+
| Who answers, language, known models | `FrameworkProvider` (this package) | the hooks, through context |
|
|
371
|
+
| What the backend sees on every request | the transport's `headers` (e.g. `sincpro-context`) | the backend's `use_context()` |
|
|
372
|
+
| What an opening carries (company, a default) | composer: the reference's `params` | `api.self.params`, `api.setParams` |
|
|
373
|
+
| The record a modal covers | composer: `api.over` | `api.over` |
|
|
374
|
+
| What a chooser was asked | composer: `pick(…, { question })` | `api.choosing` |
|
|
375
|
+
| What the user is on, what is selected | composer: `api.context` | `useWorkspaceContext(api)` |
|
|
376
|
+
| A screen's list, record, groups | the hooks | `useListing`, `useRecord`, … |
|
|
377
|
+
|
|
378
|
+
Not yet: a new record does not take the `params` it was opened with as its initial values
|
|
379
|
+
(`ROADMAP.md`, «Estado y contexto»).
|
|
380
|
+
|
|
141
381
|
### Inside
|
|
142
382
|
|
|
143
383
|
Three folders, one direction — `make doctor` keeps the arrows:
|
|
144
384
|
|
|
145
|
-
| Folder | Knows
|
|
146
|
-
| --------------- |
|
|
147
|
-
| `core` | transport, cache, entity, model definition, what a value
|
|
148
|
-
| `react` | `useListing`, `useRecord`, `useRelated`, `
|
|
149
|
-
| `web/list` | a collection: `EntityList`, `EntitySearchBar`, `columnsOf`
|
|
150
|
-
| `web/record` | one record: `RecordField`, `factsOf`, `RelatedList`, `EntityPicker`, `
|
|
151
|
-
| `web/workspace` | the composer: `entityView`, `
|
|
385
|
+
| Folder | Knows | Why apart |
|
|
386
|
+
| --------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
387
|
+
| `core` | transport, cache, entity, model definition, what a value and a record read as | plain logic, tested in Node in milliseconds |
|
|
388
|
+
| `react` | `useListing`, `useRecord`, `useRelated`, `useSummaryOf`…, the provider | state that draws nothing: usable without `EntityList` |
|
|
389
|
+
| `web/list` | a collection: `EntityList`, `EntitySearchBar`, `columnsOf` | N records, any size |
|
|
390
|
+
| `web/record` | one record: `RecordField`, `factsOf`, `RelatedList`, `EntityPicker`, `cardOf` | works outside a workspace (no composer) |
|
|
391
|
+
| `web/workspace` | the composer: `entityView`, `openIn`, `RelatedRecord`, `<SincproApp>` | where it opens, the application context |
|
|
152
392
|
|
|
153
393
|
Everything is imported from `@sincpro/web-framework`.
|
|
154
394
|
|
|
@@ -174,6 +414,24 @@ Everything is imported from `@sincpro/web-framework`.
|
|
|
174
414
|
| `EntityList` views | The same set as table, rows or board | ✅ |
|
|
175
415
|
| `useRelated`, `RelatedList` | A record's relation as a live list: searched and paged by the server, inside a form | ✅ |
|
|
176
416
|
| `EntityPicker` chooser | «see all…» opens the whole set, searched on the server: a many2one over millions | ✅ |
|
|
417
|
+
| `useRecord(entity, "")`, `create` | A new record: the model's defaults, saved to `create`, then it IS the record it became | ✅ |
|
|
418
|
+
| `retryKeys`, `Idempotency-Key` | A Command or a create retried after a lost answer runs once, not twice | ✅ |
|
|
419
|
+
| `entity.newRef()`, «New» in the list | The record's form with no id, in a page or a window; replaced by the record once created | ✅ |
|
|
420
|
+
| `EntityPicker criteria` | A many2one narrowed by another field: the invoices OF the chosen customer | ✅ |
|
|
421
|
+
| `chooserIn`, `entity.chooserRef()` | «see all…» as the composer's chooser: a row answers (`api.pick`) | ✅ |
|
|
422
|
+
| `useGroups`, «Group by» | Groups counted by the server over the whole set; a group's rows read when it is opened | ✅ |
|
|
423
|
+
| `defineList`, `listView` | A named list (a fixed scope, its columns and filters) as data, and as a workspace view | ✅ |
|
|
424
|
+
| `EntityPicker` `browse`, `columns` | The chooser always a click away, as a table searched literally by the server | ✅ |
|
|
425
|
+
| `useFollowed` | A detail panel follows the record the person is on, without knowing the list | ✅ |
|
|
426
|
+
| `commands`, `useRowCommands` | An entity's Commands on each row, idempotent, offered only where `when` holds | ✅ |
|
|
427
|
+
| `summaryOf`, `cardOf`, `relationOf` | Any record at any size: name, description, state, type, picture, who made and changed it | ✅ |
|
|
428
|
+
| `openIn`, `RelatedRecord` | A related record opens in a modal; «Abrir en…» for the rest; never a modal over a modal | ✅ |
|
|
429
|
+
| Literal search everywhere | Picker: the first ten, the server's search as you type; tables: «Buscar «X»» on Enter | ✅ |
|
|
430
|
+
| `EntityTags` | A many2many as chips over thousands: the server's search, faces, the chosen never again | ✅ |
|
|
431
|
+
| `RecordField` + `entities` | A many2one / one2many drawn from the model alone, opened where the view says | ✅ |
|
|
432
|
+
| `EntityRecord`, `formOf` | Any entity's record screen without writing it | ✅ |
|
|
433
|
+
| `Trail`, `Record.Pager` | Previous / next from a record, across the server's pages | ✅ |
|
|
434
|
+
| `EntityList sums` | Each group says how much it adds up, summed by the server over all of it | ✅ |
|
|
177
435
|
|
|
178
436
|
What it does **not** do: mobile (`sincpro_mobile` has its own core), sessions and login (the
|
|
179
437
|
application's), routing (composer's), string-named widget registries, technical logs on a
|
package/dist/core/cache.js
CHANGED
|
@@ -30,11 +30,11 @@ export function cachedTransport(transport, options = {}) {
|
|
|
30
30
|
one(route, signal) {
|
|
31
31
|
return remembered(`one ${route}`, () => transport.one(route, signal));
|
|
32
32
|
},
|
|
33
|
-
async send(method, route, body, signal) {
|
|
33
|
+
async send(method, route, body, signal, sending) {
|
|
34
34
|
// A preview writes nothing; anything else may have changed what was read.
|
|
35
35
|
const preview = route.endsWith("/preview");
|
|
36
36
|
try {
|
|
37
|
-
return await transport.send(method, route, body, signal);
|
|
37
|
+
return await transport.send(method, route, body, signal, sending);
|
|
38
38
|
}
|
|
39
39
|
finally {
|
|
40
40
|
// Even a refused write may have changed something (a 409 says someone else did).
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ export type FrameworkCopy = {
|
|
|
30
30
|
capped: (shown: number) => string;
|
|
31
31
|
/** Conditions the server could not answer: the list is WIDER than asked. */
|
|
32
32
|
dropped: (fields: readonly string[]) => string;
|
|
33
|
+
/** The group of the records that hold no value in the field grouped by. */
|
|
34
|
+
noValue: string;
|
|
35
|
+
/** More groups than shown: narrow the set instead of scrolling them. */
|
|
36
|
+
groupsCapped: (shown: number) => string;
|
|
37
|
+
/** «12 groups · 187 records»: what the grouping split. */
|
|
38
|
+
groups: (groups: number, records: number) => string;
|
|
33
39
|
};
|
|
34
40
|
record: {
|
|
35
41
|
/** A draft this caller kept is back on screen. */
|
|
@@ -43,6 +49,26 @@ export type FrameworkCopy = {
|
|
|
43
49
|
loading: string;
|
|
44
50
|
/** Under an embedded list the record holds only one page of. */
|
|
45
51
|
partial: (shown: number, total: number) => string;
|
|
52
|
+
/** The title of a record that does not exist yet, after the model's name. */
|
|
53
|
+
creating: (name: string) => string;
|
|
54
|
+
/** The list's button that opens the form of a new record. */
|
|
55
|
+
create: string;
|
|
56
|
+
/** A record's one2many: the button that opens the form of a new related record. */
|
|
57
|
+
add: string;
|
|
58
|
+
};
|
|
59
|
+
picker: {
|
|
60
|
+
/** The button beside a many2one that opens the chooser over the whole set. */
|
|
61
|
+
browse: string;
|
|
62
|
+
};
|
|
63
|
+
summary: {
|
|
64
|
+
/** The facts of a record's summary: when it was made and last changed. */
|
|
65
|
+
created: string;
|
|
66
|
+
updated: string;
|
|
67
|
+
/** «12 mar 2026 · Ana Rojas»: when, and who when it is known. */
|
|
68
|
+
when: (at: string, by: string | null) => string;
|
|
69
|
+
/** A card's last line: «Updated 12 Mar 2026 by Ana», or «Created …» if never changed. */
|
|
70
|
+
updatedLine: (at: string, by: string | null) => string;
|
|
71
|
+
createdLine: (at: string, by: string | null) => string;
|
|
46
72
|
};
|
|
47
73
|
command: {
|
|
48
74
|
/** The confirmation of an action that cannot be undone, after its dry run. */
|
package/dist/core/copy.js
CHANGED
|
@@ -15,6 +15,9 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
15
15
|
builder: "Criteria builder",
|
|
16
16
|
capped: (shown) => `Showing the first ${shown}. Narrow the search to see the rest.`,
|
|
17
17
|
dropped: (fields) => `The server ignored a condition on ${fields.join(", ")}: the list shows more than asked.`,
|
|
18
|
+
noValue: "No value",
|
|
19
|
+
groupsCapped: (shown) => `The first ${shown} groups. Narrow the search to see the rest.`,
|
|
20
|
+
groups: (groups, records) => `${groups} ${groups === 1 ? "group" : "groups"} · ${records} ${records === 1 ? "record" : "records"}`,
|
|
18
21
|
},
|
|
19
22
|
record: {
|
|
20
23
|
restored: "A draft you kept is back. Save it or discard it.",
|
|
@@ -24,6 +27,19 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
24
27
|
keep: "Keep draft",
|
|
25
28
|
loading: "Loading the record",
|
|
26
29
|
partial: (shown, total) => `Showing ${shown} of ${total}.`,
|
|
30
|
+
creating: (name) => (name ? `${name} · new` : "New"),
|
|
31
|
+
create: "New",
|
|
32
|
+
add: "Add",
|
|
33
|
+
},
|
|
34
|
+
picker: {
|
|
35
|
+
browse: "Search all",
|
|
36
|
+
},
|
|
37
|
+
summary: {
|
|
38
|
+
created: "Created",
|
|
39
|
+
updated: "Updated",
|
|
40
|
+
when: (at, by) => (by === null ? at : `${at} · ${by}`),
|
|
41
|
+
updatedLine: (at, by) => (by === null ? `Updated ${at}` : `Updated ${at} by ${by}`),
|
|
42
|
+
createdLine: (at, by) => (by === null ? `Created ${at}` : `Created ${at} by ${by}`),
|
|
27
43
|
},
|
|
28
44
|
command: {
|
|
29
45
|
confirm: "Do it",
|
|
@@ -67,6 +83,9 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
67
83
|
builder: "Constructor de criteria",
|
|
68
84
|
capped: (shown) => `Se muestran los primeros ${shown}. Refiná la búsqueda para ver el resto.`,
|
|
69
85
|
dropped: (fields) => `El servidor ignoró una condición sobre ${fields.join(", ")}: la lista muestra más de lo pedido.`,
|
|
86
|
+
noValue: "Sin valor",
|
|
87
|
+
groupsCapped: (shown) => `Los primeros ${shown} grupos. Acotá la búsqueda para ver el resto.`,
|
|
88
|
+
groups: (groups, records) => `${groups} ${groups === 1 ? "grupo" : "grupos"} · ${records} ${records === 1 ? "registro" : "registros"}`,
|
|
70
89
|
},
|
|
71
90
|
record: {
|
|
72
91
|
restored: "Volvió un borrador que guardaste. Guardalo o descartalo.",
|
|
@@ -76,6 +95,19 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
76
95
|
keep: "Guardar borrador",
|
|
77
96
|
loading: "Cargando el registro",
|
|
78
97
|
partial: (shown, total) => `Se muestran ${shown} de ${total}.`,
|
|
98
|
+
creating: (name) => (name ? `${name} · nuevo` : "Nuevo"),
|
|
99
|
+
create: "Nuevo",
|
|
100
|
+
add: "Agregar",
|
|
101
|
+
},
|
|
102
|
+
picker: {
|
|
103
|
+
browse: "Buscar en todos",
|
|
104
|
+
},
|
|
105
|
+
summary: {
|
|
106
|
+
created: "Creado",
|
|
107
|
+
updated: "Actualizado",
|
|
108
|
+
when: (at, by) => (by === null ? at : `${at} · ${by}`),
|
|
109
|
+
updatedLine: (at, by) => by === null ? `Actualizado el ${at}` : `Actualizado el ${at} por ${by}`,
|
|
110
|
+
createdLine: (at, by) => (by === null ? `Creado el ${at}` : `Creado el ${at} por ${by}`),
|
|
79
111
|
},
|
|
80
112
|
command: {
|
|
81
113
|
confirm: "Hacerlo",
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -16,12 +16,57 @@ export type FieldState = {
|
|
|
16
16
|
required: boolean;
|
|
17
17
|
visible: boolean;
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* What a server preview said about a field. A list of records — an invoice's lines — carries
|
|
21
|
+
* each one's own in `items`, in the order the form sent them (sincpro_framework's
|
|
22
|
+
* `FieldState.items`).
|
|
23
|
+
*/
|
|
24
|
+
export type ServerFieldState = Partial<FieldState> & {
|
|
25
|
+
items?: readonly Readonly<Record<string, ServerFieldState>>[];
|
|
26
|
+
};
|
|
27
|
+
export type FieldStates = Readonly<Record<string, ServerFieldState>>;
|
|
28
|
+
/** What the server's preview warned about, pointing where it belongs (`path`: the field, or a
|
|
29
|
+
* line's cell — `["lines", 1, "price"]`). It refuses nothing. sincpro_framework's warning. */
|
|
30
|
+
export type Advice = {
|
|
31
|
+
message: string;
|
|
32
|
+
field?: string | null;
|
|
33
|
+
path?: readonly (string | number)[];
|
|
34
|
+
};
|
|
21
35
|
export declare function fieldStateOf(meta: Meta | null | undefined, name: string, values: AnyRecord, fromServer?: FieldStates): FieldState;
|
|
36
|
+
/** Each line's states of a list of records, as the server said them — by position. */
|
|
37
|
+
export declare function lineStatesOf(fromServer: FieldStates | undefined, name: string): readonly FieldStates[];
|
|
22
38
|
/** The fields whose value differs from the record's — what a save or a draft sends. */
|
|
23
39
|
export declare function changesOf(record: AnyRecord, values: AnyRecord): AnyRecord;
|
|
24
40
|
/** What is missing before it can be saved: a required, visible, editable field left empty. */
|
|
25
41
|
export declare function missingOf(meta: Meta | null | undefined, values: AnyRecord, fromServer?: FieldStates): string[];
|
|
26
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Where the server's word points inside the record, as one key: `"discount"`, `"lines/1/qty"`.
|
|
44
|
+
* A JSON pointer (RFC 6901), bare (`/discount`) or as a fragment (`#/values/lines/1/qty`) — the
|
|
45
|
+
* command's `values/` envelope dropped, `~1`/`~0` read back — or a path (`["lines", 1, "qty"]`).
|
|
46
|
+
* Errors and warnings are read with the same rule, so both land on the same cell.
|
|
47
|
+
*/
|
|
48
|
+
export declare function pathOf(at: string | readonly (string | number)[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* The server's word on what did not validate, by where it points (`pathOf`): a field's own
|
|
51
|
+
* error under its name, a line's cell's under its whole path (`lines/1/qty`). The first word for
|
|
52
|
+
* a place wins. `errorAt` reads a field's, its lines' included.
|
|
53
|
+
*/
|
|
27
54
|
export declare function errorsByField(errors: readonly FieldError[] | undefined): Record<string, string>;
|
|
55
|
+
/** The error at `at` or under it (`lines` finds `lines/1/qty`): what marks a field invalid. */
|
|
56
|
+
export declare function errorAt(errors: Readonly<Record<string, string>>, at: string): string | undefined;
|
|
57
|
+
/** The warnings at `at` or under it — a line's (`lines/1`) finds its cells'. One with no path
|
|
58
|
+
* is placed by its field. */
|
|
59
|
+
export declare function adviceAt(advice: readonly Advice[], at: string): Advice[];
|
|
60
|
+
/**
|
|
61
|
+
* A record that does not exist yet: the defaults the model publishes for each field
|
|
62
|
+
* (`FieldMeta.default`, sincpro_framework's `defaults_of`), and nothing else.
|
|
63
|
+
*
|
|
64
|
+
* defaultsOf(invoiceMeta) -> { state: "draft", payment: "cash", discount: "0" }
|
|
65
|
+
*/
|
|
66
|
+
export declare function defaultsOf(meta: Meta | null | undefined): AnyRecord;
|
|
67
|
+
/**
|
|
68
|
+
* What a create sends: every value on screen the caller may write. A field the model marks
|
|
69
|
+
* `readonly` is the server's to fill (the number, the totals), and an empty one is left for
|
|
70
|
+
* the server's own default — never sent as `""`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function creationOf(meta: Meta | null | undefined, values: AnyRecord): AnyRecord;
|