@sincpro/web-ui 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +159 -4
  2. package/dist/components/activity/Activity.js +3 -2
  3. package/dist/components/form/Form.js +12 -3
  4. package/dist/components/form/FormIndex.d.ts +5 -1
  5. package/dist/components/form/FormIndex.js +71 -23
  6. package/dist/components/form/Sheet.js +22 -4
  7. package/dist/components/record/ActionDock.d.ts +36 -0
  8. package/dist/components/record/ActionDock.js +58 -0
  9. package/dist/components/record/Breadcrumb.d.ts +3 -1
  10. package/dist/components/record/Breadcrumb.js +13 -5
  11. package/dist/components/record/DirtyActions.js +11 -1
  12. package/dist/components/record/Pager.d.ts +12 -10
  13. package/dist/components/record/Pager.js +39 -6
  14. package/dist/components/record/RecordHeader.d.ts +13 -1
  15. package/dist/components/record/RecordHeader.js +107 -31
  16. package/dist/components/record/SmartButtons.d.ts +8 -2
  17. package/dist/components/record/SmartButtons.js +8 -3
  18. package/dist/components/record/StatusBar.d.ts +68 -1
  19. package/dist/components/record/StatusBar.js +218 -48
  20. package/dist/components/record/dock.d.ts +56 -0
  21. package/dist/components/record/dock.js +58 -0
  22. package/dist/components/record/index.d.ts +3 -1
  23. package/dist/components/record/index.js +5 -1
  24. package/dist/components/search/CriteriaBuilder.d.ts +5 -2
  25. package/dist/components/search/CriteriaBuilder.js +2 -1
  26. package/dist/components/search/FieldPath.js +16 -7
  27. package/dist/components/search/FilterBuilder.d.ts +13 -4
  28. package/dist/components/search/FilterBuilder.js +72 -23
  29. package/dist/components/search/RuleValue.d.ts +6 -2
  30. package/dist/components/search/RuleValue.js +27 -5
  31. package/dist/components/search/SearchBar.d.ts +6 -6
  32. package/dist/components/search/SearchBar.js +41 -4
  33. package/dist/components/search/context.d.ts +6 -2
  34. package/dist/components/search/context.js +5 -2
  35. package/dist/components/search/index.d.ts +1 -1
  36. package/dist/components/search/records.d.ts +23 -0
  37. package/dist/foundations/copy.d.ts +9 -0
  38. package/dist/foundations/copy.es.js +10 -1
  39. package/dist/foundations/copy.js +5 -0
  40. package/dist/foundations/form.d.ts +10 -1
  41. package/dist/foundations/grouping.d.ts +9 -0
  42. package/dist/foundations/index.d.ts +3 -1
  43. package/dist/foundations/index.js +8 -2
  44. package/dist/foundations/keys.d.ts +34 -0
  45. package/dist/foundations/keys.js +99 -0
  46. package/dist/foundations/shortcut.d.ts +17 -1
  47. package/dist/foundations/shortcut.js +57 -1
  48. package/dist/foundations/viewStyle.d.ts +8 -0
  49. package/dist/foundations/viewStyle.js +12 -0
  50. package/dist/primitives/menu/Menu.d.ts +3 -0
  51. package/dist/primitives/menu/Menu.js +7 -1
  52. package/dist/primitives/table/DataTable.d.ts +15 -0
  53. package/dist/primitives/table/DataTable.js +67 -12
  54. package/dist/primitives/table/EditableTable.js +7 -2
  55. package/dist/primitives/table/SheetTable.d.ts +3 -0
  56. package/dist/primitives/table/SheetTable.js +15 -2
  57. package/dist/primitives/value/Value.d.ts +5 -1
  58. package/dist/primitives/value/Value.js +9 -3
  59. package/dist/tokens.css +19 -2
  60. package/dist/views/list/List.d.ts +2 -1
  61. package/dist/views/list/List.js +6 -2
  62. package/dist/views/list/ListView.d.ts +1 -1
  63. package/dist/views/list/ListView.js +53 -14
  64. package/dist/views/list/derive.d.ts +1 -1
  65. package/dist/views/list/derive.js +45 -9
  66. package/dist/views/list/types.d.ts +33 -0
  67. package/dist/views/record/Record.d.ts +16 -2
  68. package/dist/views/record/Record.js +33 -8
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -268,12 +268,12 @@ The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`
268
268
  `menu.section`, `menu.item`, `menu.fold`, `dialog`, `block`, `record-card`, `board.tile`,
269
269
  `board.stat`, `board.stat.value`, `activity.changes`, `file-list`, `file-list.file`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
270
270
  `search.panel`, `search.suggestions`, `search.suggestion`, `search.record`, `search.advanced`,
271
- `search.keys`, `search-entry`, `search-entry.keys`, `table`,
271
+ `search.keys`, `search-entry`, `search-entry.keys`, `table`, `table.pile`,
272
272
  `table.head`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
273
273
  `frame`, `frame.bar`, `frame.sidebar`, `frame.main`, `sidebar`, `sidebar.brand`,
274
274
  `sidebar.user`, `sidebar.search`, `sidebar.nav`, `sidebar.account`, `navigation`,
275
275
  `navigation.item`, `dirty.blocked`, `dirty.bar`, `field`, `field.label`, `form.section`,
276
- `form.index`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
276
+ `form.index`, `dock`, `dock.pill`, `dock.bare`, `pager`, `smart`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
277
277
  `guide.progress`, `guide.title`, `guide.body`, `guide.actions`. A part that is one of many
278
278
  carries `data-key` too (`navigation.item`). Put your rules in a cascade layer above web-ui's, or
279
279
  outside any layer.
@@ -297,6 +297,21 @@ written out under it on the left, the control on the right —, every `FormSecti
297
297
  the rail. The layout (`stacked` / `horizontal`) is still the screen's: stacked, the help and the
298
298
  control go under the label. Without the provider nothing changes.
299
299
 
300
+ #### A dense record found by its index: the «sections» style
301
+
302
+ `FormStyleProvider value="sections"` keeps the ERP's density and takes the settings' shape:
303
+ every `SheetGroup` on the paper and every notebook page (`Record.Page`) is a card on the
304
+ ground, listed in the index at the left (sticky under the application bar, marking the one
305
+ being read), and inside each card the dense grid stays — label | value, two or three columns,
306
+ a group inside a card stays a titled group. The notebook's pages are not tabs any more: a long
307
+ record is read top to bottom and found by its index, nothing hidden behind a tab. Save and
308
+ Discard float as in settings, and the activity stands apart. Pair it with the modern style:
309
+ `5 · Plantillas/Registros/Ficha de contacto › En secciones`.
310
+
311
+ A table's TITLE column (the card's title on a phone: `stack: "title"`, or the first column)
312
+ keeps `--size-cell-title` (14 rem): a product name cut with «…» asks for no width of its own,
313
+ and beside figures with a width it was squeezed to «Imp…».
314
+
300
315
  #### Searching the records of a relation — and extending the search
301
316
 
302
317
  Typing «andres» in the bar offers «Cliente con «andres» ▸», and the ▸ (or →) unfolds the
@@ -316,7 +331,11 @@ const searchRecords: SearchRecords = ({ relation, path, text, keys, signal }) =>
316
331
  ? api.names(relation, keys, { signal }) // name what a filter read back carries
317
332
  : api.literalSearch(relation, text, { limit: 8, signal }); // what was typed
318
333
 
319
- <SearchProvider searchRecords={searchRecords} valueEditor={myValueEditor}>
334
+ <SearchProvider
335
+ searchRecords={searchRecords}
336
+ browseRecords={(browse) => openChooser(browse)} // your list in choosing mode, its own bar
337
+ valueEditor={myValueEditor}
338
+ >
320
339
  <App /> {/* every SearchBar, FilterBuilder and CriteriaBuilder inside */}
321
340
  </SearchProvider>;
322
341
  ```
@@ -326,13 +345,23 @@ const searchRecords: SearchRecords = ({ relation, path, text, keys, signal }) =>
326
345
  other side (`relationKey`, `id` by default) — the filter crosses it with `through`. An enum's
327
346
  words come from `translations.choices`.
328
347
 
348
+ A path is walked the same way: in «Cliente › País» the first option is «País (el registro)» —
349
+ the rule then asks for COUNTRIES, picked by name— above País's own fields, for when the
350
+ question is about a field («Código empieza con B»). «Buscar más…» opens your chooser: another
351
+ context, the relation's whole list with its own search bar (which unfolds relations too).
352
+
353
+ Who does what: web-ui draws and notifies; **web-framework** wires `searchRecords` to the
354
+ entity's literal search, `browseRecords` to the entity's list in choosing mode and `loadModel`
355
+ to the related meta — once, for every entity; composer decides where the chooser opens (a modal
356
+ over a page, beside a modal); the application only overrides what it wants.
357
+
329
358
  What can be extended, and how:
330
359
 
331
360
  | You want | Use |
332
361
  | ------------------------------------------------ | -------------------------------------------------------------------------------------------- |
333
362
  | The records of a relation, from your server | `searchRecords` (prop, or `SearchProvider` once) |
334
363
  | A record drawn your way in the dropdown | `SearchBar renderRecord` |
335
- | «Buscar más…» under the records: your chooser | `SearchBar onBrowseRecords(field, text)` + `withValue` |
364
+ | «Buscar más…» under the records: your chooser | `browseRecords` (prop or `SearchProvider`), bar and builder; answer with `choose` |
336
365
  | A field's value drawn your way in the builder | `valueEditor` (prop or `SearchProvider`): answer `undefined` to keep ours |
337
366
  | A list that opens filtered (defaults, a link) | `queryField` + `valuesCriteria` / `conditionCriteria` / `toggleNamed` |
338
367
  | One more value into a chip, by code | `withValue(criteria, field, record)` |
@@ -340,6 +369,132 @@ What can be extended, and how:
340
369
  | Your own builder | `SelectionTree`, `RuleValue`, `liftRecords`, `recordsFilter`, `recordOps` |
341
370
  | The words of an operator («no está establecido») | the copy table: `ops` |
342
371
 
372
+ #### A group says what it adds up to, under each column
373
+
374
+ A table grouped by a field draws each pile's row like Odoo's grouped list: its name, how many,
375
+ and under every column that declared an `aggregate` what the pile adds up to — written like
376
+ the footer («185.200,50», «máx 5»). Whoever counts the piles (the server's grouped read) sends
377
+ the sums in `Pile.totals`, by column id; without them the table sums the rows when the pile
378
+ holds all of them — the sum of one page of a pile of thousands looks like its total and is
379
+ not. The sheet's bands and the report built from the piles say the same numbers: in the report
380
+ every pile is a group with its amounts, and a «Total» line closes it.
381
+
382
+ A column's numbers are written ONE way, in its cells, its piles and its footer: its `format`,
383
+ else its `decimals` (`DataColumn.decimals`, `SheetColumn.decimals`): `2` writes «6.057,10»
384
+ under «8.370,57», not «6.057,1».
385
+
386
+ #### The direction: the modern style (`ViewStyleProvider`)
387
+
388
+ **Modern is where the system is going.** It is not a trial: it is how new screens are drawn,
389
+ and it keeps being applied to the rest of the system and refined. `traditional` stays — same
390
+ API, same data — for the applications already drawn in it. What the direction is:
391
+
392
+ - **The page breathes on the ground.** No white band on top of the paper: the trail IS the
393
+ page's heading (`Breadcrumb size="lg"`), and the counters and the state sit a step down,
394
+ quieter.
395
+ - **One floating pill holds the actions** — at the bottom, centred, under the thumb —, the
396
+ same on a record, a list and a settings form. It turns into «N cambios · Descartar ·
397
+ Guardar» while there are changes, and into what is done to the chosen rows while some are
398
+ chosen. Never two pills at once.
399
+ - **Pills are the shape of the identity**: the actions' pill, the pager (a translucent primary
400
+ pill), the state as a pill of pills (`StatusBar look="segmented"`), the counters as links
401
+ with their count in a pill.
402
+ - **Colour means something**: the gold is the one action that moves the record forward; the
403
+ translucent primary, where you are; red, what undoes.
404
+ - **The keyboard reaches everything**: every action can carry its shortcut, drawn for the
405
+ person's keyboard (see below).
406
+ - **A number reads the same everywhere**: its column's decimals and format in the cells, the
407
+ groups, the footer and the report.
408
+
409
+ Already in the direction: dense records in sections with an index (`FormStyleProvider
410
+ value="sections"`, below) and the state on a phone (`display="auto"`). Next: the rest of the
411
+ screens taking the floating pill, and the phone's pill when an action does not fit.
412
+
413
+ A record and a list are written once — `Record.Dock` and `List.Dock` with their actions as
414
+ data — and the application's style decides how they are drawn, the way it chooses its density:
415
+
416
+ ```tsx
417
+ // "traditional" is the default; a single Record can say its own with `look`.
418
+ <ViewStyleProvider value="modern">
419
+ <App />
420
+ </ViewStyleProvider>
421
+ ```
422
+
423
+ - **traditional**: the ERP rail — a band with the trail, the counters and the pager; the
424
+ actions as the bar's buttons (the primary first and gold, «⋯» with the rest), in a record
425
+ and in a list alike.
426
+ - **modern**: the trail is the page's heading with the pager as a translucent primary pill on
427
+ its line (`Pager look="pill"`); a step down, the counters as links (`SmartButton
428
+ look="link"`) and the state; the band is the ground; and the actions float in ONE pill at
429
+ the bottom, centred — a record's, and a list's. `placement="top"` rests a record's pill in
430
+ the rail and floats it at the top on scroll.
431
+
432
+ **The state.** `StatusBar look`: `track` (Odoo's — the traditional style's), `segmented` (a
433
+ pill of pills, the actions' shape — the modern style's), `steps`, `progress` and `pill` (one chip that unfolds the stages). Each
434
+ stage can carry an `icon`, an `activeIcon` (worn when it is the current or the chosen one:
435
+ ○ → ◉), a `hint` (said when pointed at) and a `count` (how many are there, in a list grouped by
436
+ stage). `display` says what a stage shows — `auto` (the default: every name where there is
437
+ room, on a phone only the current one's), `both`, `label`, `icon` (the name said to a screen
438
+ reader and on hover) or `current` (the icons, and the current stage's name) —, and
439
+ `renderStage` draws a stage your way inside the system's segment, which keeps the order, the
440
+ paint, the focus and the names. `Record.Status look` picks one; all side by side in
441
+ `3 · Componentes/Registro/Riel, estado y contadores`.
442
+
443
+ #### Keyboard shortcuts that run
444
+
445
+ A combination is written once — `"Alt+D"`, `"Mod+S"` (⌘ on a Mac, Ctrl elsewhere) — and is
446
+ pressed, drawn and announced for the person's keyboard (`foundations/keys`: «⌥D» / «Alt+D»,
447
+ `aria-keyshortcuts`). It RUNS while the piece that declares it is on screen, and declarations
448
+ stack: the record in a peek over the page answers, not the page under it.
449
+
450
+ - `DockAction.shortcut` — any action, a sub-action or one waiting in «Más» included.
451
+ - `Record.Pager` / `Pager keys` — Alt+P and Alt+N by default (Odoo's), `false` for none.
452
+ - Save answers Mod+S wherever it is (`DirtyActions`).
453
+ - Your own: `useShortcuts([{ keys: "Alt+K", run, enabled }])`, and `useKeysHint(keys)` to draw
454
+ it.
455
+
456
+ A combination with a modifier works while a field is being typed in; a bare key does not.
457
+
458
+ #### The record's actions floating (`Record.Dock`)
459
+
460
+ The «settings» style floats Save and Discard in a dark pill; `Record.Dock` tries that pill for
461
+ ALL of a record's actions. In place of `Record.Actions`, the actions are written as data, and the
462
+ pill decides what is seen: the primary, gold and last; `visible` secondary ones (one with
463
+ sub-actions is a menu button, «Imprimir ▾»); the rest in «Más ⋯», sub-actions as submenus, what
464
+ undoes apart and last, in red. Where it goes is `placement`: `rail` (the traditional buttons),
465
+ `bottom` (the modern default, floating centred) or `top` (resting in the rail, a layer of the
466
+ sticky stack once it scrolls away); while there are changes the same pill holds «N cambios ·
467
+ Descartar · Guardar».
468
+
469
+ ```tsx
470
+ <Record.Rail>
471
+ <Record.Crumbs crumbs={…} />
472
+ <Record.Dock
473
+ label="Acciones de la factura"
474
+ actions={[
475
+ { id: "pay", label: "Registrar pago", icon: CreditCard, primary: true, onSelect: pay },
476
+ { id: "send", label: "Enviar", icon: Send, onSelect: send },
477
+ { id: "print", label: "Imprimir", icon: Printer, items: [
478
+ { id: "print-invoice", label: "Factura", shortcut: "Mod+P", onSelect: printInvoice },
479
+ { id: "print-note", label: "Remito", onSelect: printNote },
480
+ ] },
481
+ { id: "copy", label: "Duplicar", icon: Copy, shortcut: "Alt+D", onSelect: duplicate },
482
+ { id: "void", label: "Anular en el SIAT", icon: Ban, danger: true, onSelect: voidIt },
483
+ ]}
484
+ // placement="rail" | "bottom" | "top", align="center" | "end", look="chrome" | "canvas", visible={2}
485
+ />
486
+ <Record.Status stages={…} current="posted" />
487
+ </Record.Rail>
488
+ ```
489
+
490
+ A list says the same with `List.Dock` — `actions` (what it starts) and `selection` (what is
491
+ done to the chosen rows). `placement` is `bar` (the bar's buttons; the chosen rows' in place of
492
+ the search) or `bottom` (ONE floating pill, the chosen rows' while some are chosen); absent,
493
+ the view style decides. `selectionPlacement` overrides where the chosen rows' actions go.
494
+
495
+ `ActionDock` is the pill alone (`placement="inline"`, or sticky `top` / `bottom` anywhere, with
496
+ a `lead` before the actions) and `dockPlan` the rule, for a screen that is neither.
497
+
343
498
  #### A guided tour: the screen says what each thing is
344
499
 
345
500
  `Guide` walks a person through a screen: the rest dims, the thing being explained is cut out,
@@ -190,8 +190,9 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
190
190
  const alertsId = ownAlertsId ?? autoAlertsId;
191
191
  const auto = layout === "auto";
192
192
  /* Beside the sheet it is joined to it — the sheet's right edge is the line between the two.
193
- In the «settings» form style there is no sheet, only cards on the ground: it stands apart. */
194
- const joined = useFormStyle() !== "settings";
193
+ In the «settings» and «sections» form styles there is no sheet, only cards on the ground:
194
+ it stands apart. */
195
+ const joined = useFormStyle() === "dense";
195
196
  /* The notes of the fields and rows of the record around — `Record` keeps them. */
196
197
  const notes = useNoteEntries();
197
198
  const byTime = (items) => [...items].sort((x, y) => at(y.at) - at(x.at));
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useFormIndexEntry } from "./FormIndex.js";
3
+ import { InCardScope, useFormIndexEntry } from "./FormIndex.js";
4
4
  import { byDensity, useDensity } from "../../foundations/density.js";
5
5
  import { useFormStyle } from "../../foundations/form.js";
6
6
  import { Hint } from "../../primitives/hint/Hint.js";
@@ -22,8 +22,10 @@ import { Tag } from "../../primitives/tag/Tag.js";
22
22
  * go into every aspect to discover it was empty. */
23
23
  export function FormSection({ title, hint, status, actions, columns = 1, children, }) {
24
24
  const d = useDensity();
25
- const settings = useFormStyle() === "settings";
26
- const indexed = useFormIndexEntry(settings ? title : undefined);
25
+ const style = useFormStyle();
26
+ const settings = style === "settings";
27
+ const sections = style === "sections";
28
+ const indexed = useFormIndexEntry(settings || sections ? title : undefined);
27
29
  const asGrid = columns > 1 && d === "comfortable";
28
30
  const grid = columns === 3 ? "grid-cols-3" : "grid-cols-2";
29
31
  const withHeader = title !== undefined ||
@@ -37,6 +39,13 @@ export function FormSection({ title, hint, status, actions, columns = 1, childre
37
39
  to decide whether its label still fits beside the control (`grid-setting`). */
38
40
  return (_jsxs("section", { ...(indexed === undefined ? {} : { id: indexed }), "data-ui": "form.section", className: "@container flex min-w-0 scroll-mt-3 flex-col gap-1 rounded-ui-card border border-ui-card-border bg-ui-card px-5 py-4", children: [withHeader ? (_jsxs("header", { className: "flex min-w-0 flex-wrap items-start gap-x-2.5 gap-y-1 pb-2", children: [title === undefined && hint === undefined ? null : (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [title === undefined ? null : (_jsx("h2", { className: "min-w-0 text-title font-semibold text-ink", children: title })), hint === undefined ? null : (_jsx("p", { className: "max-w-prose text-micro text-muted", children: hint }))] })), status === undefined ? null : _jsx(Tag, { tone: status.tone, children: status.label }), actions === undefined ? null : (_jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: actions }))] })) : null, _jsx("div", { className: "flex min-w-0 flex-col divide-y divide-line *:py-3.5 *:first:pt-0 *:last:pb-0", children: children })] }));
39
41
  }
42
+ if (sections) {
43
+ /* «sections»: the settings' card, the dense sheet's body — label | value in its columns,
44
+ not rows that explain themselves. A group inside stays a group (`InCardScope`). */
45
+ return (_jsxs("section", { ...(indexed === undefined ? {} : { id: indexed }), "data-ui": "form.section", className: `@container flex min-w-0 scroll-mt-3 flex-col rounded-ui-card border border-ui-card-border bg-ui-card ${byDensity(d, "gap-3 px-5 py-4", "gap-2 px-3 py-3")}`, children: [withHeader ? (_jsxs("header", { className: "flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-1", children: [title === undefined ? null : (_jsx("h2", { className: "min-w-0 text-title font-semibold text-ink first-letter:uppercase", children: title })), hint === undefined ? null : _jsx(Hint, { children: hint }), status === undefined ? null : _jsx(Tag, { tone: status.tone, children: status.label }), actions === undefined ? null : (_jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: actions }))] })) : null, _jsx(InCardScope, { children: _jsx("div", { className: `min-w-0 ${asGrid
46
+ ? `grid ${grid} gap-x-8 ${byDensity(d, "gap-y-3.5", "gap-y-2.5")}`
47
+ : `flex flex-col ${byDensity(d, "gap-3.5", "gap-2.5")}`}`, children: children }) })] }));
48
+ }
40
49
  return (_jsxs("section", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-3", "gap-2")}`, children: [withHeader ? (_jsxs("header", { className: "flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-1", children: [title === undefined && hint === undefined ? null : (_jsxs("h3", { className: "flex min-w-0 items-center gap-1 text-meta font-medium text-ink", children: [title === undefined ? null : _jsx("span", { className: "min-w-0 truncate", children: title }), hint === undefined ? null : _jsx(Hint, { children: hint })] })), status === undefined ? null : _jsx(Tag, { tone: status.tone, children: status.label }), actions === undefined ? null : (_jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: actions }))] })) : null, _jsx("div", { className: `min-w-0 ${asGrid
41
50
  ? `grid ${grid} gap-x-8 ${byDensity(d, "gap-y-3.5", "gap-y-2.5")}`
42
51
  : `flex flex-col ${byDensity(d, "gap-3.5", "gap-2.5")}`}`, children: children })] }));
@@ -1,5 +1,9 @@
1
1
  import { type ReactNode } from "react";
2
- /** Where a form's sections register: the sheet of a «settings» form. */
2
+ export declare function InCardScope({ children }: {
3
+ children: ReactNode;
4
+ }): import("react").JSX.Element;
5
+ export declare function useInCard(): boolean;
6
+ /** Where a form's sections register: the sheet of a «settings» or «sections» form. */
3
7
  export declare function FormIndexScope({ children }: {
4
8
  children: ReactNode;
5
9
  }): import("react").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useUiCopy } from "../../foundations/copy.js";
4
+ import { STICKY_TOP } from "../../foundations/sticky.js";
4
5
  import { createContext, useContext, useEffect, useId, useMemo, useState, useSyncExternalStore, } from "react";
5
6
  function createRegistry() {
6
7
  let entries = [];
@@ -26,8 +27,21 @@ function createRegistry() {
26
27
  };
27
28
  }
28
29
  const NONE = [];
30
+ /* A step below what sticks above it — the same step the cards keep from the bar. */
31
+ const INDEX_TOP = {
32
+ top: `calc(var(${STICKY_TOP}, 0px) + var(--spacing) * 3)`,
33
+ };
29
34
  const IndexContext = createContext(null);
30
- /** Where a form's sections register: the sheet of a «settings» form. */
35
+ /** Whether what is drawn is already INSIDE a card — a section of the «sections» style: a
36
+ * group in it stays a group (titled, hairline columns), not a card inside a card. */
37
+ const InCard = createContext(false);
38
+ export function InCardScope({ children }) {
39
+ return _jsx(InCard, { value: true, children: children });
40
+ }
41
+ export function useInCard() {
42
+ return useContext(InCard);
43
+ }
44
+ /** Where a form's sections register: the sheet of a «settings» or «sections» form. */
31
45
  export function FormIndexScope({ children }) {
32
46
  const [registry] = useState(createRegistry);
33
47
  return _jsx(IndexContext, { value: registry, children: children });
@@ -61,36 +75,70 @@ export function FormIndex() {
61
75
  const entries = useSyncExternalStore(registry?.subscribe ?? (() => () => undefined), registry?.snapshot ?? (() => NONE), () => NONE);
62
76
  const ordered = useMemo(() => inDocumentOrder(entries), [entries]);
63
77
  const [current, setCurrent] = useState(undefined);
64
- /* The section being read is the first one crossing the top two fifths of the screen:
65
- the one whose title just went by is still the one being read until the next arrives. */
78
+ /* The section being read is the LAST one whose top went past the upper two fifths of what
79
+ scrolls — the one whose title just went by is still being read until the next arrives —,
80
+ and at the end of the scroll, the last section: a short last card never reaches that
81
+ line, and pressing it in the index must mark it. Measured on scroll (capture: a record in
82
+ a panel scrolls its own box), once a frame. */
66
83
  useEffect(() => {
67
- if (ordered.length < 2 || typeof IntersectionObserver === "undefined")
84
+ if (ordered.length < 2)
68
85
  return;
69
- const seen = new Set();
70
- const observer = new IntersectionObserver((changes) => {
71
- for (const change of changes) {
72
- if (change.isIntersecting)
73
- seen.add(change.target.id);
74
- else
75
- seen.delete(change.target.id);
86
+ let frame = 0;
87
+ const measure = (scroller) => {
88
+ const height = scroller === null ? window.innerHeight : scroller.clientHeight;
89
+ const top = scroller === null ? 0 : scroller.getBoundingClientRect().top;
90
+ const atEnd = scroller === null
91
+ ? Math.ceil(window.innerHeight + window.scrollY) >=
92
+ document.documentElement.scrollHeight - 2
93
+ : Math.ceil(scroller.scrollTop + scroller.clientHeight) >=
94
+ scroller.scrollHeight - 2;
95
+ if (atEnd && (scroller !== null || window.scrollY > 0)) {
96
+ setCurrent(ordered.at(-1)?.id);
97
+ return;
98
+ }
99
+ const atStart = scroller === null ? window.scrollY <= 2 : scroller.scrollTop <= 2;
100
+ if (atStart) {
101
+ setCurrent(ordered[0]?.id);
102
+ return;
103
+ }
104
+ const line = top + height * 0.4;
105
+ /* Cards side by side share their top: the first of them is the one being read. */
106
+ let reading = ordered[0]?.id;
107
+ let readingTop = Number.NEGATIVE_INFINITY;
108
+ for (const entry of ordered) {
109
+ const element = document.getElementById(entry.id);
110
+ if (element === null)
111
+ continue;
112
+ const at = element.getBoundingClientRect().top;
113
+ if (at <= line && at > readingTop + 1) {
114
+ reading = entry.id;
115
+ readingTop = at;
116
+ }
76
117
  }
77
- const first = ordered.find((entry) => seen.has(entry.id));
78
- if (first !== undefined)
79
- setCurrent(first.id);
80
- }, { rootMargin: "0px 0px -60% 0px" });
81
- for (const entry of ordered) {
82
- const element = document.getElementById(entry.id);
83
- if (element !== null)
84
- observer.observe(element);
85
- }
86
- return () => observer.disconnect();
118
+ setCurrent(reading);
119
+ };
120
+ const onScroll = (event) => {
121
+ const target = event.target;
122
+ const scroller = target instanceof Element && target !== document.documentElement ? target : null;
123
+ /* Only the scroll that moves the sections: a table scrolling sideways inside one is not. */
124
+ if (scroller !== null &&
125
+ !ordered.some((one) => scroller.querySelector(`[id="${one.id}"]`)))
126
+ return;
127
+ cancelAnimationFrame(frame);
128
+ frame = requestAnimationFrame(() => measure(scroller));
129
+ };
130
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
131
+ return () => {
132
+ cancelAnimationFrame(frame);
133
+ document.removeEventListener("scroll", onScroll, { capture: true });
134
+ };
87
135
  }, [ordered]);
88
136
  if (ordered.length < 2)
89
137
  return null;
90
138
  const marked = current ?? ordered[0]?.id;
91
- return (_jsx("nav", { "aria-label": copy.field.sections, "data-ui": "form.index", className: "hidden w-(--container-form-index) shrink-0 @3xl/form:block", children: _jsx("ul", { className: "sticky top-3 flex flex-col gap-0.5", children: ordered.map((entry) => (_jsx("li", { children: _jsx("a", { href: `#${entry.id}`, ...(entry.id === marked ? { "aria-current": "location" } : {}), onClick: (event) => {
139
+ return (_jsx("nav", { "aria-label": copy.field.sections, "data-ui": "form.index", className: "hidden w-(--container-form-index) shrink-0 @3xl/form:block", children: _jsx("ul", { className: "sticky flex flex-col gap-0.5", style: INDEX_TOP, children: ordered.map((entry) => (_jsx("li", { children: _jsx("a", { href: `#${entry.id}`, ...(entry.id === marked ? { "aria-current": "location" } : {}), onClick: (event) => {
92
140
  event.preventDefault();
93
141
  document.getElementById(entry.id)?.scrollIntoView({ block: "start" });
94
142
  setCurrent(entry.id);
95
- }, className: "block truncate rounded-ui-nav px-2.5 py-1.5 text-meta text-muted transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 hover:text-ink focus-visible:outline-2 focus-visible:outline-primary aria-[current]:bg-ui-nav-current aria-[current]:font-medium aria-[current]:text-ink", children: entry.title }) }, entry.id))) }) }));
143
+ }, className: "block truncate rounded-ui-nav px-2.5 py-1.5 text-meta first-letter:uppercase text-muted transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 hover:text-ink focus-visible:outline-2 focus-visible:outline-primary aria-[current]:bg-ui-nav-current aria-[current]:font-medium aria-[current]:text-ink", children: entry.title }) }, entry.id))) }) }));
96
144
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { FormIndex, FormIndexScope } from "./FormIndex.js";
3
+ import { FormIndex, FormIndexScope, InCardScope, useFormIndexEntry, useInCard, } from "./FormIndex.js";
4
4
  import { byDensity, useDensity } from "../../foundations/density.js";
5
5
  import { useFormStyle } from "../../foundations/form.js";
6
6
  import { FieldLayoutProvider, } from "../../primitives/field/layout.js";
@@ -48,11 +48,15 @@ function Facts({ fields, columns, layout, }) {
48
48
  }
49
49
  export function Sheet({ fields, columns = 2, layout = "stacked", head, children, }) {
50
50
  const d = useDensity();
51
- const settings = useFormStyle() === "settings";
51
+ const style = useFormStyle();
52
+ const settings = style === "settings" || style === "sections";
52
53
  const facts = fields !== undefined && fields.length > 0;
53
54
  if (!facts && head === undefined && children === undefined)
54
55
  return null;
55
- const top = facts || head !== undefined ? (_jsxs("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-4", "gap-3")}`, children: [facts ? _jsx(Facts, { fields: fields, columns: columns, layout: layout }) : null, head] })) : null;
56
+ const top = facts || head !== undefined ? (_jsxs("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-4", "gap-3")}`, children: [facts ? (style === "sections" ? (
57
+ /* The record's own facts, a card with no name: they are its head, not a section
58
+ to find. */
59
+ _jsx("div", { className: CARD, children: _jsx(InCardScope, { children: _jsx(Facts, { fields: fields, columns: columns, layout: layout }) }) })) : (_jsx(Facts, { fields: fields, columns: columns, layout: layout }))) : null, head] })) : null;
56
60
  if (settings)
57
61
  return (_jsx(FieldLayoutProvider, { value: layout, children: _jsx(FormIndexScope, { children: _jsx("div", { className: "@container/form min-w-0", children: _jsxs("div", { className: "flex min-w-0 gap-6", children: [_jsx(FormIndex, {}), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-4", children: [top, children] })] }) }) }) }));
58
62
  return (_jsx(FieldLayoutProvider, { value: layout, children: _jsxs("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-(--spacing-block)", "gap-2.5")}`, children: [top, children] }) }));
@@ -62,6 +66,8 @@ export function Sheet({ fields, columns = 2, layout = "stacked", head, children,
62
66
  * groups them when a column has no title. */
63
67
  export function SheetGroups({ children, columns = 2, }) {
64
68
  const d = useDensity();
69
+ const inCard = useInCard();
70
+ const cards = useFormStyle() === "sections" && !inCard;
65
71
  const stacked = d === "compact";
66
72
  // Below `handheld` the columns stack the way compact density does: two 180 px
67
73
  // columns on a phone left each label beside a control with no width at all. The
@@ -74,6 +80,11 @@ export function SheetGroups({ children, columns = 2, }) {
74
80
  ? "grid-cols-3 @max-handheld:grid-cols-1"
75
81
  : "grid-cols-2 @max-handheld:grid-cols-1";
76
82
  const items = Children.toArray(children);
83
+ /* «sections»: each group is a card of its own, side by side with a gap — no hairline: the
84
+ cards' edges already part them. */
85
+ if (cards) {
86
+ return (_jsx("div", { className: "@container min-w-0", children: _jsx("div", { className: `grid min-w-0 items-start gap-4 ${grid}`, children: children }) }));
87
+ }
77
88
  return (_jsx("div", { className: "@container min-w-0", children: _jsx("div", { className: `grid min-w-0 ${grid}`, children: items.map((child, i) => {
78
89
  const first = i === 0;
79
90
  const last = i === items.length - 1;
@@ -94,9 +105,16 @@ export function SheetGroups({ children, columns = 2, }) {
94
105
  export function SheetGroup({ title, hint, icon: Icon, children, }) {
95
106
  const d = useDensity();
96
107
  const withHeader = title !== undefined;
97
- return (_jsxs("section", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-2.5", "gap-2")}`, children: [withHeader ? (
108
+ /* «sections», on the ground: the group is a card, listed in the index by its title. */
109
+ const inCard = useInCard();
110
+ const card = useFormStyle() === "sections" && !inCard;
111
+ const indexed = useFormIndexEntry(card ? title : undefined);
112
+ const body = (_jsxs("section", { ...(indexed === undefined ? {} : { id: indexed }), ...(card ? { "data-ui": "form.section" } : {}), className: `flex min-w-0 flex-col ${byDensity(d, "gap-2.5", "gap-2")} ${card ? `scroll-mt-3 ${CARD}` : ""}`, children: [withHeader ? (
98
113
  /* A group title is ABOVE its labels, not one of them: at the labels' size and weight
99
114
  «Cliente» the group read like «Cliente» the field. One step up in size and weight,
100
115
  and a hairline that says where the group starts. */
101
116
  _jsxs("header", { className: "flex min-w-0 items-center gap-2 border-b border-line pb-1.5", children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-sm) shrink-0 text-muted", strokeWidth: 1.75, "aria-hidden": true })), _jsx("h2", { className: "min-w-0 truncate text-body font-semibold text-ink", children: title }), hint === undefined ? null : _jsx(Hint, { children: hint })] })) : hint === undefined ? null : (_jsx(Hint, { children: hint })), _jsx("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-2.5", "gap-2")}`, children: children })] }));
117
+ return card ? _jsx(InCardScope, { children: body }) : body;
102
118
  }
119
+ /* A card of the «sections» style: the settings' card, at the dense sheet's padding. */
120
+ const CARD = "rounded-ui-card border border-ui-card-border bg-ui-card px-5 py-4 @max-handheld:px-3 @max-handheld:py-3";
@@ -0,0 +1,36 @@
1
+ import { type DirtyState } from "./DirtyActions.js";
2
+ import { type DockAction } from "./dock.js";
3
+ import type { ReactNode } from "react";
4
+ /** Where the dock floats. `top` and `bottom` stick to that edge of what scrolls; `inline`
5
+ * draws only the pill — its host places it (`Record.Dock` does). */
6
+ export type DockPlacement = "top" | "bottom" | "inline";
7
+ /** The pill's band: the dark one (the settings bar's), a light card — or `bare`: no pill at
8
+ * all, the actions as the rail's buttons (the record's `traditional` style draws them so). */
9
+ export type DockLook = "chrome" | "canvas" | "bare";
10
+ export interface ActionDockProps {
11
+ actions: readonly DockAction[];
12
+ /** How many secondary actions are seen beside the primary; the rest wait in «Más». */
13
+ visible?: number;
14
+ /** Unsaved changes: the dock holds Discard and Save instead of the actions. */
15
+ dirty?: DirtyState;
16
+ /** It has just saved: «Guardado» for a moment (`useJustSaved`). */
17
+ saved?: boolean;
18
+ placement?: DockPlacement;
19
+ /** Centred over what it acts on, or at its end. */
20
+ align?: "center" | "end";
21
+ look?: DockLook;
22
+ /** The toolbar's accessible name: «Acciones de la factura». */
23
+ label?: string;
24
+ /** What the pill says before its actions — «3 elegidas ✕» over a list's chosen rows. Drawn
25
+ * on the pill's band: write it with `useSurface()` colours. */
26
+ lead?: ReactNode;
27
+ }
28
+ /** Where a record's actions go: as the rail's buttons, or floating — resting in the rail and
29
+ * detaching on scroll (`top`), or at the bottom of the screen (`bottom`). Absent, the record's
30
+ * style decides: `traditional` → `rail`, `modern` → `bottom`. */
31
+ export type RecordDockPlacement = "rail" | "top" | "bottom";
32
+ /** What `Record.Dock` takes: the dock's, with the record's placements. */
33
+ export type RecordDockProps = Omit<ActionDockProps, "dirty" | "saved" | "placement"> & {
34
+ placement?: RecordDockPlacement;
35
+ };
36
+ export declare function ActionDock({ actions, visible, dirty, saved, placement, align, look, label, lead, }: ActionDockProps): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { DirtyActions, SavedMark, } from "./DirtyActions.js";
4
+ import { dockOption, dockPlan, dockShortcuts, moreGroups, } from "./dock.js";
5
+ import { useUiCopy } from "../../foundations/copy.js";
6
+ import { keysLabel } from "../../foundations/keys.js";
7
+ import { useKeyboardPlatform, useKeysHint, useShortcuts, } from "../../foundations/shortcut.js";
8
+ import { stickyTop } from "../../foundations/sticky.js";
9
+ import { SurfaceProvider, useSurface } from "../../foundations/surface.js";
10
+ import { Button } from "../../primitives/button/Button.js";
11
+ import { Menu } from "../../primitives/menu/Menu.js";
12
+ import { MoreHorizontal } from "lucide-react";
13
+ const PILL = { "--ui-button-radius": "var(--radius-pill)" };
14
+ /** One action as a button, its shortcut in its title and in `aria-keyshortcuts`. */
15
+ function DockButton({ action, role, size, surface, }) {
16
+ const hint = useKeysHint(action.shortcut);
17
+ return (_jsx(Button, { role: role, ...(size === undefined ? {} : { size }), surface: surface, ...(action.icon === undefined ? {} : { icon: action.icon }), ...(action.disabled === undefined ? {} : { disabled: action.disabled }), ...(action.onSelect === undefined ? {} : { onClick: action.onSelect }), ...(hint === undefined
18
+ ? {}
19
+ : { title: `${action.label} (${hint.label})`, "aria-keyshortcuts": hint.aria }), children: action.label }));
20
+ }
21
+ /** The same actions with no pill: the rail's buttons — the primary first and gold, the
22
+ * secondary ones bordered, «⋯» with the rest. What the `traditional` style draws. */
23
+ function Bare({ actions, visible, dirty, saved, label, }) {
24
+ const copy = useUiCopy();
25
+ const surface = useSurface();
26
+ const platform = useKeyboardPlatform();
27
+ const label_ = (keys) => keysLabel(keys, platform);
28
+ const plan = dockPlan(actions, visible);
29
+ const more = moreGroups(plan, label_);
30
+ const tone = surface === "chrome" ? "chrome" : "canvas";
31
+ if (dirty !== undefined) {
32
+ return (_jsx("div", { className: "flex shrink-0 items-center gap-1.5", children: _jsx(DirtyActions, { ...dirty }) }));
33
+ }
34
+ return (_jsxs("div", { role: "toolbar", "aria-label": label ?? copy.dock.label, "data-ui": "dock.bare", className: "flex shrink-0 items-center gap-1.5", children: [plan.primary === undefined ? null : (_jsx(DockButton, { action: plan.primary, role: "primary", size: "sm", surface: tone })), plan.shown.map((action) => action.items === undefined ? (_jsx(DockButton, { action: action, role: "secondary", size: "sm", surface: tone }, action.id)) : (_jsx(Menu, { role: "secondary", size: "sm", surface: surface === "chrome" ? "chrome" : "canvas", label: action.label, ...(action.icon === undefined ? {} : { icon: action.icon }), groups: [{ options: action.items.map((one) => dockOption(one, label_)) }] }, action.id))), more.length === 0 ? null : (_jsx(Menu, { label: copy.dock.more, icon: MoreHorizontal, iconOnly: true, chevron: false, size: "sm", surface: surface === "chrome" ? "chrome" : "canvas", groups: more })), _jsx(SavedMark, { saved: saved === true })] }));
35
+ }
36
+ /** The pill alone: the actions, or Save and Discard. */
37
+ function Pill({ actions, visible, dirty, saved, look, label, lead, }) {
38
+ const copy = useUiCopy();
39
+ const platform = useKeyboardPlatform();
40
+ const label_ = (keys) => keysLabel(keys, platform);
41
+ const plan = dockPlan(actions, visible);
42
+ const more = moreGroups(plan, label_);
43
+ return (_jsx(SurfaceProvider, { value: look, children: _jsx("div", { role: "toolbar", "aria-label": label ?? copy.dock.label, "data-ui": "dock.pill", style: PILL, className: `pointer-events-auto flex max-w-full min-w-0 items-center gap-1 rounded-pill p-1.5 shadow-float *:shrink-0 ${look === "chrome"
44
+ ? "border border-chrome-edge bg-chrome"
45
+ : "border border-line bg-surface"}`, children: dirty !== undefined ? (_jsx(DirtyActions, { ...dirty, floating: true })) : (_jsxs(_Fragment, { children: [lead, plan.shown.map((action) => action.items === undefined ? (_jsx(DockButton, { action: action, role: "ghost", surface: look }, action.id)) : (_jsx(Menu, { role: "ghost", surface: look, label: action.label, ...(action.icon === undefined ? {} : { icon: action.icon }), groups: [{ options: action.items.map((one) => dockOption(one, label_)) }] }, action.id))), more.length === 0 ? null : (_jsx(Menu, { label: copy.dock.more, icon: MoreHorizontal, iconOnly: true, chevron: false, variant: "text", surface: look, align: "end", groups: more })), plan.primary === undefined ? null : (_jsx(DockButton, { action: plan.primary, role: "primary", surface: look })), _jsx(SavedMark, { saved: saved === true })] })) }) }));
46
+ }
47
+ export function ActionDock({ actions, visible = 2, dirty, saved, placement = "top", align = "center", look = "chrome", label, lead, }) {
48
+ /* The combinations run while the dock is on screen; while there are changes Save answers
49
+ Mod+S itself. */
50
+ useShortcuts(dockShortcuts(actions, dirty !== undefined));
51
+ const pill = look === "bare" ? (_jsx(Bare, { actions: actions, visible: visible, ...(dirty === undefined ? {} : { dirty }), ...(saved === undefined ? {} : { saved }), ...(label === undefined ? {} : { label }) })) : (_jsx(Pill, { actions: actions, visible: visible, look: look, ...(lead === undefined ? {} : { lead }), ...(dirty === undefined ? {} : { dirty }), ...(saved === undefined ? {} : { saved }), ...(label === undefined ? {} : { label }) }));
52
+ if (placement === "inline")
53
+ return pill;
54
+ /* Sticky to the edge of what scrolls, as the settings bar: no padding to keep in sync with
55
+ its height, and at the end of the page it settles in its place in the flow. Only the pill
56
+ takes the pointer — the band around it lets the page be pressed through. */
57
+ return (_jsx("div", { "data-ui": "dock", "data-placement": placement, ...(placement === "top" ? { style: stickyTop } : {}), className: `pointer-events-none sticky z-20 flex px-3 ${placement === "top" ? "py-2" : "bottom-0 mt-auto pt-3 safe-bottom"} ${align === "end" ? "justify-end" : "justify-center"}`, children: pill }));
58
+ }
@@ -33,9 +33,11 @@ export interface Crumb {
33
33
  * Folding and truncating are not the same and that is why both exist: one removes
34
34
  * CRUMBS and the other removes LETTERS.
35
35
  */
36
- export declare function Breadcrumb({ crumbs, surface: surfaceProp, folded, }: {
36
+ export declare function Breadcrumb({ crumbs, surface: surfaceProp, size, folded, }: {
37
37
  crumbs: readonly Crumb[];
38
38
  surface?: Surface;
39
+ /** `lg`: the trail is the page's heading — the record's «modern» style draws it so. */
40
+ size?: "md" | "lg";
39
41
  /** From how many crumbs the middle folds. Below this every crumb is drawn:
40
42
  * folding two crumbs hides half the trail to save one chevron. */
41
43
  folded?: number;