@selfhelp/shared 1.23.0 → 1.25.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 (37) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/dist/index.d.mts +300 -100
  3. package/dist/index.d.ts +300 -100
  4. package/dist/index.js +531 -3
  5. package/dist/index.mjs +506 -3
  6. package/dist/plugin-sdk/index.d.mts +1 -1
  7. package/dist/plugin-sdk/index.d.ts +1 -1
  8. package/dist/plugin-sdk/index.js +7 -1
  9. package/dist/plugin-sdk/index.mjs +7 -1
  10. package/dist/registry/index.d.mts +2 -2
  11. package/dist/registry/index.d.ts +2 -2
  12. package/dist/registry/index.js +15 -1
  13. package/dist/registry/index.mjs +14 -1
  14. package/dist/{styles.registry-BBd9T2Ox.d.ts → styles.registry-C2ACy7H0.d.ts} +734 -2
  15. package/dist/{styles.registry-IjDTff8P.d.mts → styles.registry-DnIJqEzM.d.mts} +734 -2
  16. package/package.json +1 -1
  17. package/src/api/__tests__/endpoints.test.ts +45 -0
  18. package/src/api/__tests__/formListErrors.test.ts +143 -0
  19. package/src/api/endpoints.ts +41 -0
  20. package/src/api/formListErrors.ts +134 -0
  21. package/src/api/index.ts +1 -0
  22. package/src/content/__tests__/formListState.test.ts +448 -0
  23. package/src/content/__tests__/formRecordPrefill.test.ts +120 -0
  24. package/src/content/formListState.ts +559 -0
  25. package/src/content/formRecordPrefill.ts +108 -5
  26. package/src/content/index.ts +1 -0
  27. package/src/registry/__tests__/platform.test.ts +15 -6
  28. package/src/registry/__tests__/registry.test.ts +14 -0
  29. package/src/registry/styles.registry.ts +23 -0
  30. package/src/types/api/__tests__/formWrites.test.ts +84 -0
  31. package/src/types/api/form-lists.ts +475 -0
  32. package/src/types/api/forms.ts +149 -4
  33. package/src/types/api/index.ts +1 -0
  34. package/src/types/styles/__tests__/entryFormListFormFields.test.ts +44 -0
  35. package/src/types/styles/composite.ts +13 -0
  36. package/src/types/styles/forms.ts +124 -0
  37. package/src/types/styles/unknown.ts +5 -1
@@ -0,0 +1,44 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { describe, expectTypeOf, it } from 'vitest';
7
+ import type { IContentField } from '../base';
8
+ import type { IEntryFormListStyle, IFormRecordStyle, TEntryFormListFormFields } from '../forms';
9
+
10
+ /**
11
+ * Compile-time pin: the form fields on Entry List with Form stay aligned with
12
+ * form-record (Pick), so a rename or type change on the form cannot drift.
13
+ */
14
+ describe('TEntryFormListFormFields', () => {
15
+ it('matches the corresponding IFormRecordStyle members', () => {
16
+ expectTypeOf<TEntryFormListFormFields['name']>().toEqualTypeOf<IFormRecordStyle['name']>();
17
+ expectTypeOf<TEntryFormListFormFields['btn_save_label']>().toEqualTypeOf<
18
+ IFormRecordStyle['btn_save_label']
19
+ >();
20
+ expectTypeOf<TEntryFormListFormFields['btn_update_label']>().toEqualTypeOf<
21
+ IFormRecordStyle['btn_update_label']
22
+ >();
23
+ expectTypeOf<TEntryFormListFormFields['btn_update_color']>().toEqualTypeOf<
24
+ IFormRecordStyle['btn_update_color']
25
+ >();
26
+ expectTypeOf<TEntryFormListFormFields['alert_success']>().toEqualTypeOf<
27
+ IFormRecordStyle['alert_success']
28
+ >();
29
+ expectTypeOf<TEntryFormListFormFields['redirect_at_end']>().toEqualTypeOf<
30
+ IFormRecordStyle['redirect_at_end']
31
+ >();
32
+ expectTypeOf<TEntryFormListFormFields['buttons_order']>().toEqualTypeOf<
33
+ IFormRecordStyle['buttons_order']
34
+ >();
35
+ });
36
+
37
+ it('is carried by IEntryFormListStyle without changing style_name', () => {
38
+ expectTypeOf<IEntryFormListStyle['style_name']>().toEqualTypeOf<'entry-form-list'>();
39
+ expectTypeOf<IEntryFormListStyle['name']>().toEqualTypeOf<IContentField<string> | undefined>();
40
+ expectTypeOf<IEntryFormListStyle['btn_update_label']>().toEqualTypeOf<
41
+ IContentField<string> | undefined
42
+ >();
43
+ });
44
+ });
@@ -140,11 +140,24 @@ export interface IEntryRecordStyle extends IBaseStyle {
140
140
  * `/team-members/{record_id}`). The holder loads that single row.
141
141
  */
142
142
  load_record_from?: IContentField<string>;
143
+ /**
144
+ * Typed JSON fixed filter (same shape as a list's `list_fixed_filter`).
145
+ * Bounds which record this detail may show; a record outside it is treated
146
+ * like a missing record (F166).
147
+ */
148
+ fixed_filter?: IContentField<string>;
143
149
  scope?: IContentField<string>;
144
150
  }
145
151
 
146
152
  export interface IEntryRecordDeleteStyle extends IBaseStyle {
147
153
  style_name: 'entry-record-delete';
154
+ /** The record this button deletes: injected by the server from the enclosing record (not a CMS field). */
155
+ record_id?: IContentField<string>;
156
+ /**
157
+ * The version that record has when the page is built, as digits (injected next to `record_id`;
158
+ * absent when the record no longer exists). Send it back as `expected_version`.
159
+ */
160
+ record_version?: IContentField<string>;
148
161
  /** Delete button text (catalog field; the generic `label` field is not linked to this style). */
149
162
  label_delete?: IContentField<string>;
150
163
  confirmation_title?: IContentField<string>;
@@ -8,6 +8,12 @@ import type {
8
8
  TSharedSize,
9
9
  TSharedRadius,
10
10
  } from '../mantine/common';
11
+ import type {
12
+ IFormListError,
13
+ IFormListState,
14
+ TFormListLayout,
15
+ TFormListPresentation,
16
+ } from '../api/form-lists';
11
17
 
12
18
  export type TMantineTextInputVariant = 'default' | 'filled' | 'unstyled';
13
19
  export type TMantineTextareaAutosize = '0' | '1';
@@ -511,6 +517,12 @@ export interface IEntryTableEntry {
511
517
  _can_delete?: boolean;
512
518
  /** Per-row edit permission (backend rule `canUpdateOwnedRecord`). */
513
519
  _can_edit?: boolean;
520
+ /**
521
+ * The version the record has when the page is built (present on rows that offer delete
522
+ * or edit). Send it back as `expected_version`: a delete without it is refused (400), one
523
+ * based on an old version is refused (409) and the record stays.
524
+ */
525
+ _version?: number;
514
526
  [key: string]: unknown;
515
527
  }
516
528
 
@@ -582,3 +594,115 @@ export interface IEntryTableStyle extends IBaseStyle {
582
594
  */
583
595
  field_labels?: Record<string, string>;
584
596
  }
597
+
598
+ /**
599
+ * Fields and server-added state both list styles share. The configuration
600
+ * fields hold what the author set; the JSON fields (`list_columns`, `list_sort`,
601
+ * `list_controls`, `list_fixed_filter`, `quick_actions`) are JSON documents the
602
+ * server validates when the section is saved or imported, so a renderer never
603
+ * parses them: it draws `list_state`.
604
+ */
605
+ export interface IFormListBaseStyle extends IStyleWithSpacing {
606
+ /**
607
+ * The server-rendered state of the list for this visitor and URL, added by the
608
+ * page endpoints after the page cache. Absent when {@link list_error} is set.
609
+ */
610
+ list_state?: IFormListState;
611
+ /** Why the list has no state (sign in, not allowed, invalid parameter, bad configuration). The page is still served. */
612
+ list_error?: IFormListError;
613
+ /** Optional auto-styled heading rendered above the list when set. */
614
+ title?: IContentField<string>;
615
+ /** The list's name in the URL (`<key>.page`, `<key>.q`, ...); unique on a page. */
616
+ list_key?: IContentField<string>;
617
+ /**
618
+ * Numeric `data_tables.id`, or empty.
619
+ * - On `entry-form-list`: empty means the list owns its table (created on
620
+ * first submit as `data_tables.name = "<list section id>"`). Set to another
621
+ * table for a read-only override: the list only deletes and runs quick
622
+ * actions; inputs, create and edit are refused.
623
+ * - On `data-view`: required; the view is always read-only.
624
+ */
625
+ data_table?: IContentField<string>;
626
+ list_layout?: IContentField<TFormListLayout>;
627
+ /** Rows per page, 1 to 100. */
628
+ page_size?: IContentField<string>;
629
+ /** JSON: up to 30 columns `{field, label, sortable, searchable, format}`. */
630
+ list_columns?: IContentField<string>;
631
+ /** JSON: up to 3 default sort keys `{field, direction}`. */
632
+ list_sort?: IContentField<string>;
633
+ /** JSON: up to 12 visitor controls (search-adjacent filters). */
634
+ list_controls?: IContentField<string>;
635
+ /** JSON: the author's dataset filter; every read and write of the list honours it. */
636
+ list_fixed_filter?: IContentField<string>;
637
+ /** '1' (default on `entry-form-list`): the list shows and changes the visitor's own records only. */
638
+ own_entries_only?: IContentField<string>;
639
+ label_empty?: IContentField<string>;
640
+ label_search?: IContentField<string>;
641
+ }
642
+
643
+ /**
644
+ * Form fields that an Entry List with Form carries when it is its own form.
645
+ * Picked from {@link IFormRecordStyle} so labels, alerts and button knobs cannot
646
+ * drift from standalone forms. Not included: `description` (the list has
647
+ * `title`), `close_modal_on_save`, `redirect_on_save`, `btn_cancel_url` (the
648
+ * list closes its modal or returns to itself).
649
+ */
650
+ export type TEntryFormListFormFields = Pick<
651
+ IFormRecordStyle,
652
+ | 'name'
653
+ | 'btn_save_label'
654
+ | 'btn_save_color'
655
+ | 'btn_update_label'
656
+ | 'btn_update_color'
657
+ | 'btn_cancel_label'
658
+ | 'btn_cancel_color'
659
+ | 'alert_success'
660
+ | 'alert_success_title'
661
+ | 'alert_error'
662
+ | 'alert_error_title'
663
+ | 'confirm_submit'
664
+ | 'confirm_message'
665
+ | 'buttons_size'
666
+ | 'buttons_radius'
667
+ | 'buttons_variant'
668
+ | 'buttons_position'
669
+ | 'buttons_order'
670
+ | 'redirect_at_end'
671
+ >;
672
+
673
+ /**
674
+ * Entry List with Form: a server-rendered list of records that is also the form
675
+ * that creates and edits them. Put the inputs directly inside the list; the
676
+ * first successful submit creates `data_tables.name = "<list section id>"`.
677
+ * A nested `form-record` / `form-log` / `entry-record-form` / `entry-form-list`
678
+ * is refused. When {@link IFormListBaseStyle.data_table} names another table,
679
+ * the list is a read-only override (delete and quick actions only).
680
+ */
681
+ export interface IEntryFormListStyle extends IFormListBaseStyle, TEntryFormListFormFields {
682
+ style_name: 'entry-form-list';
683
+ form_presentation?: IContentField<TFormListPresentation>;
684
+ /** JSON: up to 8 server-defined quick actions `{id, label, confirm, set, when}`. */
685
+ quick_actions?: IContentField<string>;
686
+ allow_create?: IContentField<string>;
687
+ allow_update?: IContentField<string>;
688
+ allow_delete?: IContentField<string>;
689
+ /** '1' offers versions, comparison and restore of a record. */
690
+ show_history?: IContentField<string>;
691
+ label_add?: IContentField<string>;
692
+ label_confirm_delete?: IContentField<string>;
693
+ }
694
+
695
+ /**
696
+ * Data View: the read-only sibling of {@link IEntryFormListStyle}. It shows a
697
+ * table, cards or your own layout of records and never writes; a forged write is
698
+ * refused. With the `custom` layout its child sections are the template of ONE
699
+ * record: the server renders them per record into `list_state.rows[].sections`, so
700
+ * the page itself carries no children for it.
701
+ */
702
+ export interface IDataViewStyle extends IFormListBaseStyle {
703
+ style_name: 'data-view';
704
+ /** A site path containing `{record_id}` exactly once; a row links there. */
705
+ detail_url?: IContentField<string>;
706
+ /** Classes of the element that holds the records of the `custom` layout (for example a grid); web only. */
707
+ list_row_css?: IContentField<string>;
708
+ }
@@ -88,6 +88,8 @@ import type {
88
88
  IProgressRootStyle,
89
89
  IProgressSectionStyle,
90
90
  IEntryTableStyle,
91
+ IEntryFormListStyle,
92
+ IDataViewStyle,
91
93
  } from './forms';
92
94
  import type {
93
95
  IAccordionStyle,
@@ -208,7 +210,9 @@ export type TStyle =
208
210
  | IVersionStyle
209
211
  | IRefContainerStyle
210
212
  | IDataContainerStyle
211
- | IEntryTableStyle;
213
+ | IEntryTableStyle
214
+ | IEntryFormListStyle
215
+ | IDataViewStyle;
212
216
 
213
217
  /**
214
218
  * Discriminator — name of every supported style. Derived from the