@selfhelp/shared 1.23.0 → 1.24.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 (35) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/dist/index.d.mts +300 -100
  3. package/dist/index.d.ts +300 -100
  4. package/dist/index.js +519 -3
  5. package/dist/index.mjs +495 -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 +3 -1
  9. package/dist/plugin-sdk/index.mjs +3 -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 +3 -1
  13. package/dist/registry/index.mjs +3 -1
  14. package/dist/{styles.registry-BBd9T2Ox.d.ts → styles.registry-BKWoDg7q.d.ts} +701 -2
  15. package/dist/{styles.registry-IjDTff8P.d.mts → styles.registry-aopb3vsI.d.mts} +701 -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/styles.registry.ts +2 -0
  29. package/src/types/api/__tests__/formWrites.test.ts +84 -0
  30. package/src/types/api/form-lists.ts +469 -0
  31. package/src/types/api/forms.ts +149 -4
  32. package/src/types/api/index.ts +1 -0
  33. package/src/types/styles/composite.ts +13 -0
  34. package/src/types/styles/forms.ts +84 -0
  35. package/src/types/styles/unknown.ts +5 -1
@@ -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,75 @@ 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
+ /** Numeric `data_tables.id`, or empty: the table of the inline form. Required for a data view. */
618
+ data_table?: IContentField<string>;
619
+ list_layout?: IContentField<TFormListLayout>;
620
+ /** Rows per page, 1 to 100. */
621
+ page_size?: IContentField<string>;
622
+ /** JSON: up to 30 columns `{field, label, sortable, searchable, format}`. */
623
+ list_columns?: IContentField<string>;
624
+ /** JSON: up to 3 default sort keys `{field, direction}`. */
625
+ list_sort?: IContentField<string>;
626
+ /** JSON: up to 12 visitor controls (search-adjacent filters). */
627
+ list_controls?: IContentField<string>;
628
+ /** JSON: the author's dataset filter; every read and write of the list honours it. */
629
+ list_fixed_filter?: IContentField<string>;
630
+ /** '1' (default on `entry-form-list`): the list shows and changes the visitor's own records only. */
631
+ own_entries_only?: IContentField<string>;
632
+ label_empty?: IContentField<string>;
633
+ label_search?: IContentField<string>;
634
+ }
635
+
636
+ /**
637
+ * Entry List with Form: a server-rendered list of records with create, view,
638
+ * edit, delete and quick actions, over the generic data store. Its child
639
+ * sections include the inline form that creates and edits records.
640
+ */
641
+ export interface IEntryFormListStyle extends IFormListBaseStyle {
642
+ style_name: 'entry-form-list';
643
+ form_presentation?: IContentField<TFormListPresentation>;
644
+ /** JSON: up to 8 server-defined quick actions `{id, label, confirm, set, when}`. */
645
+ quick_actions?: IContentField<string>;
646
+ allow_create?: IContentField<string>;
647
+ allow_update?: IContentField<string>;
648
+ allow_delete?: IContentField<string>;
649
+ /** '1' offers versions, comparison and restore of a record. */
650
+ show_history?: IContentField<string>;
651
+ label_add?: IContentField<string>;
652
+ label_confirm_delete?: IContentField<string>;
653
+ }
654
+
655
+ /**
656
+ * Data View: the read-only sibling of {@link IEntryFormListStyle}. It shows a
657
+ * table, cards or your own layout of records and never writes; a forged write is
658
+ * refused. With the `custom` layout its child sections are the template of ONE
659
+ * record: the server renders them per record into `list_state.rows[].sections`, so
660
+ * the page itself carries no children for it.
661
+ */
662
+ export interface IDataViewStyle extends IFormListBaseStyle {
663
+ style_name: 'data-view';
664
+ /** A site path containing `{record_id}` exactly once; a row links there. */
665
+ detail_url?: IContentField<string>;
666
+ /** Classes of the element that holds the records of the `custom` layout (for example a grid); web only. */
667
+ list_row_css?: IContentField<string>;
668
+ }
@@ -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