@almadar/patterns 2.16.0 → 2.17.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.
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Canonical emit-payload shapes for framework data patterns.
3
+ *
4
+ * The patterns (DataGrid, DataList, Timeline, CardGrid, List, Form,
5
+ * InfiniteScrollSentinel, SortableList, ...) dispatch events via
6
+ * `eventBus.emit` with these payload shapes. Typing them once here means
7
+ * every emit site and every listener agrees on the contract — no more
8
+ * inline `{ row: itemData }` literals that erase the entity type, and
9
+ * no more `itemData: Record<string, unknown>` at the receiver.
10
+ *
11
+ * Pattern-specific payload contracts live here (in `@almadar/patterns`)
12
+ * because they're pattern-level contracts — the framework-level generic
13
+ * primitives (`EventPayloadValue`, `FieldValue`) stay in `@almadar/core`.
14
+ * Patterns import the primitives and build named payload shapes on top
15
+ * of them.
16
+ *
17
+ * Consumers:
18
+ * - Component authors import the relevant payload type at the emit site
19
+ * and use `satisfies` to assert conformance without widening.
20
+ * - Generated trait reducers receive the payload typed as one of these
21
+ * shapes, so a SAVE transition handler for a Form sees
22
+ * `FormSubmitPayload<T>`, not `unknown`.
23
+ * - Verifiers can eventually assert "trait event X's declared payload
24
+ * matches the pattern's emit shape" once the patterns registry carries
25
+ * a per-prop `payloadShape` reference (follow-up — not in 2.17.0).
26
+ *
27
+ * @packageDocumentation
28
+ */
29
+ import type { EventPayloadValue, FieldValue } from '@almadar/core';
30
+ /**
31
+ * Payload dispatched by per-item action buttons in data patterns
32
+ * (DataGrid, DataList, Timeline, CardGrid, List, ...).
33
+ *
34
+ * When a user clicks an itemAction, the pattern emits `UI:{action.event}`
35
+ * with this payload. The trait reducer gets both the row's id (lookups,
36
+ * delete, update) AND the full row for downstream logic (opening a
37
+ * detail panel pre-filled with the row, computing a derived value,
38
+ * etc.).
39
+ *
40
+ * Generic over the row shape. `DataGridItemAction` used on `CartItem[]`
41
+ * gives the trait `ItemActionPayload<CartItem>`, not `unknown`.
42
+ */
43
+ export interface ItemActionPayload<T extends EventPayloadValue = EventPayloadValue> {
44
+ /** Row primary key. */
45
+ id: string | number;
46
+ /** Full row data at click time. */
47
+ row: T;
48
+ }
49
+ /**
50
+ * Payload dispatched when a selection-capable data pattern observes a
51
+ * selection change (`selectionEvent` on DataGrid / DataList / ...).
52
+ * Carries every currently-selected row id; the receiving trait can
53
+ * reconcile against its row set to recompute derived state ("bulk
54
+ * enabled", "3 items selected", etc.).
55
+ */
56
+ export interface SelectionChangePayload {
57
+ selectedIds: string[];
58
+ }
59
+ /**
60
+ * Payload dispatched when an infinite-scroll-enabled pattern's sentinel
61
+ * becomes visible (`loadMoreEvent` on DataGrid / DataList /
62
+ * InfiniteScrollSentinel).
63
+ *
64
+ * No fields required — the receiving trait knows its own cursor (last
65
+ * loaded page, current offset). Declared as an empty record so consumers
66
+ * can pattern-match on the event without checking payload shape.
67
+ */
68
+ export type LoadMoreRequestPayload = Record<string, never>;
69
+ /**
70
+ * Payload dispatched by a schema-driven `Form` on successful submit
71
+ * (`submitEvent`). `data` holds the form's collected field values.
72
+ *
73
+ * Generic over the field-value bag so a typed `Form<Partial<CartItem>>`
74
+ * passes `FormSubmitPayload<Partial<CartItem>>` to the trait's SAVE
75
+ * handler, and a generic form falls back to the `FieldValue`-keyed
76
+ * default.
77
+ */
78
+ export interface FormSubmitPayload<T extends Record<string, FieldValue | undefined> = Record<string, FieldValue | undefined>> {
79
+ data: T;
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/patterns",
3
- "version": "2.16.0",
3
+ "version": "2.17.0",
4
4
  "description": "Pattern registry and component mappings for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,9 +27,9 @@
27
27
  "access": "public"
28
28
  },
29
29
  "devDependencies": {
30
- "eslint": "10.0.0",
31
- "@typescript-eslint/parser": "8.56.0",
32
30
  "@almadar/eslint-plugin": ">=2.3.0",
31
+ "@typescript-eslint/parser": "8.56.0",
32
+ "eslint": "10.0.0",
33
33
  "tsup": "^8.0.0",
34
34
  "typescript": "^5.4.0",
35
35
  "vitest": "^1.4.0"
@@ -48,7 +48,7 @@
48
48
  ],
49
49
  "homepage": "https://github.com/almadar-io/almadar#readme",
50
50
  "dependencies": {
51
- "@almadar/core": ">=4.8.2"
51
+ "@almadar/core": ">=5.6.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsup && tsc -p tsconfig.build.json",