@almadar/patterns 2.16.0 → 2.17.1

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,85 @@
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 { EventPayload, 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
+ * Intersected with `EventPayload` so the whole thing is structurally
44
+ * compatible with `eventBus.emit`'s typed parameter — interfaces alone
45
+ * aren't assignable to `EventPayload`'s index signature in strict mode.
46
+ */
47
+ export type ItemActionPayload<T extends EventPayloadValue = EventPayloadValue> = EventPayload & {
48
+ /** Row primary key. */
49
+ id: string | number;
50
+ /** Full row data at click time. */
51
+ row: T;
52
+ };
53
+ /**
54
+ * Payload dispatched when a selection-capable data pattern observes a
55
+ * selection change (`selectionEvent` on DataGrid / DataList / ...).
56
+ * Carries every currently-selected row id; the receiving trait can
57
+ * reconcile against its row set to recompute derived state ("bulk
58
+ * enabled", "3 items selected", etc.).
59
+ */
60
+ export type SelectionChangePayload = EventPayload & {
61
+ selectedIds: readonly string[];
62
+ };
63
+ /**
64
+ * Payload dispatched when an infinite-scroll-enabled pattern's sentinel
65
+ * becomes visible (`loadMoreEvent` on DataGrid / DataList /
66
+ * InfiniteScrollSentinel).
67
+ *
68
+ * No fields required — the receiving trait knows its own cursor (last
69
+ * loaded page, current offset). Declared as `EventPayload` (the empty-
70
+ * object bound) so consumers can pass `{}` and listeners can
71
+ * destructure without runtime checks.
72
+ */
73
+ export type LoadMoreRequestPayload = EventPayload;
74
+ /**
75
+ * Payload dispatched by a schema-driven `Form` on successful submit
76
+ * (`submitEvent`). `data` holds the form's collected field values.
77
+ *
78
+ * Generic over the field-value bag so a typed `Form<Partial<CartItem>>`
79
+ * passes `FormSubmitPayload<Partial<CartItem>>` to the trait's SAVE
80
+ * handler, and a generic form falls back to the `FieldValue`-keyed
81
+ * default.
82
+ */
83
+ export type FormSubmitPayload<T extends Record<string, FieldValue | undefined> = Record<string, FieldValue | undefined>> = EventPayload & {
84
+ data: T;
85
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/patterns",
3
- "version": "2.16.0",
3
+ "version": "2.17.1",
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",