@lukso/transaction-view-headless 0.4.3 → 0.4.4-dev.c5d67d4

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 (41) hide show
  1. package/.turbo/turbo-build.log +32 -30
  2. package/.turbo/turbo-typecheck.log +1 -1
  3. package/ARG_ACCESS_PATTERN.md +265 -0
  4. package/CHANGELOG.md +14 -0
  5. package/CONTEXT_VARIANT_GUIDE.md +4 -4
  6. package/EVENT_SYSTEM_SUMMARY.md +601 -0
  7. package/HEADER_EVENTS_GUIDE.md +291 -0
  8. package/RECOMPOSITION_REFERENCE.md +303 -0
  9. package/TRANSACTION_MODIFICATION_GUIDE.md +927 -0
  10. package/dist/composables/index.cjs +1 -1
  11. package/dist/composables/index.cjs.map +1 -1
  12. package/dist/composables/index.d.cts +3 -3
  13. package/dist/composables/index.d.ts +3 -3
  14. package/dist/composables/index.js +1 -1
  15. package/dist/composables/index.js.map +1 -1
  16. package/dist/{index-CSDjhiKV.d.cts → index-BqL7xdDl.d.cts} +2 -2
  17. package/dist/{index-CMLU1hKL.d.ts → index-CNUHqRdk.d.ts} +2 -2
  18. package/dist/index.cjs +60 -1
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +5 -4
  21. package/dist/index.d.ts +5 -4
  22. package/dist/index.js +55 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/registry/index.d.cts +2 -2
  25. package/dist/registry/index.d.ts +2 -2
  26. package/dist/types/index.cjs +68 -0
  27. package/dist/types/index.cjs.map +1 -1
  28. package/dist/types/index.d.cts +229 -169
  29. package/dist/types/index.d.ts +229 -169
  30. package/dist/types/index.js +55 -0
  31. package/dist/types/index.js.map +1 -1
  32. package/dist/utils/index.d.cts +1 -1
  33. package/dist/utils/index.d.ts +1 -1
  34. package/dist/{view-loader-dD86QAlQ.d.cts → view-loader--mEEI8YY.d.ts} +1 -1
  35. package/dist/{view-loader-ii8AxiQR.d.ts → view-loader-D7ApWfdN.d.cts} +1 -1
  36. package/dist/view-matching-C9G3z8lQ.d.cts +203 -0
  37. package/dist/view-matching-C9G3z8lQ.d.ts +203 -0
  38. package/package.json +3 -3
  39. package/src/composables/use-transaction-playback.ts +8 -5
  40. package/src/types/index.ts +14 -0
  41. package/src/types/view-events.ts +322 -0
@@ -0,0 +1,322 @@
1
+ /**
2
+ * View Events and Header Information Types
3
+ *
4
+ * Defines the event system for transaction views to communicate
5
+ * with their parent containers about header display and other UI concerns.
6
+ */
7
+
8
+ /**
9
+ * Header information that a view can provide to its parent container
10
+ *
11
+ * Views can emit this information to override the default header
12
+ * that would be derived from the transaction's top-level from/to addresses.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Inside a transfer view component
17
+ * this.dispatchEvent(new CustomEvent('header-info', {
18
+ * bubbles: true,
19
+ * composed: true,
20
+ * detail: {
21
+ * from: transferFromAddress,
22
+ * to: transferToAddress,
23
+ * title: 'LSP7 Token Transfer'
24
+ * }
25
+ * }))
26
+ * ```
27
+ */
28
+ export interface TransactionHeaderInfo {
29
+ /**
30
+ * The "from" address to display in the header
31
+ * Overrides the transaction's top-level from address
32
+ */
33
+ from?: string
34
+
35
+ /**
36
+ * The "to" address to display in the header
37
+ * Overrides the transaction's top-level to address
38
+ */
39
+ to?: string
40
+
41
+ /**
42
+ * Optional title for the transaction
43
+ * @example "LSP7 Token Transfer", "Set Data", "Execute"
44
+ */
45
+ title?: string
46
+
47
+ /**
48
+ * Optional subtitle or description
49
+ * @example "Send 100 tokens", "Update profile data"
50
+ */
51
+ subtitle?: string
52
+
53
+ /**
54
+ * Optional icon identifier
55
+ * @example "transfer", "setdata", "execute"
56
+ */
57
+ icon?: string
58
+
59
+ /**
60
+ * Optional additional metadata
61
+ * Can be used for custom header rendering
62
+ */
63
+ metadata?: Record<string, any>
64
+ }
65
+
66
+ /**
67
+ * Type-safe custom event for header information
68
+ */
69
+ export interface HeaderInfoEvent extends CustomEvent {
70
+ detail: TransactionHeaderInfo
71
+ }
72
+
73
+ /**
74
+ * Transaction modification information
75
+ *
76
+ * Views emit this to modify their transaction's data (e.g., changing a parameter).
77
+ * The view encodes its LOCAL transaction data, and the parent handles re-wrapping
78
+ * if the transaction is inside Execute or ExecuteBatch wrappers.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // In a transfer view, user clicks "Force Transfer" checkbox
83
+ * const newData = encodeFunctionData({
84
+ * abi: LSP7_ABI,
85
+ * functionName: 'transfer',
86
+ * args: [from, to, amount, true, data] // force = true
87
+ * })
88
+ *
89
+ * dispatchTransactionModification(this, {
90
+ * data: newData,
91
+ * transactionIndex: this.index,
92
+ * reason: 'User enabled force transfer to EOA',
93
+ * userInitiated: true
94
+ * })
95
+ * ```
96
+ */
97
+ export interface TransactionModification {
98
+ /**
99
+ * The modified data for THIS transaction level (not wrapped)
100
+ *
101
+ * This is the encoded function call for the current transaction only,
102
+ * not wrapped in Execute or Batch calls. The parent container handles re-wrapping.
103
+ */
104
+ data: `0x${string}`
105
+
106
+ /**
107
+ * The playback index this modification applies to
108
+ *
109
+ * - 0 = batch summary (modifies batch itself)
110
+ * - 1 = first transaction (or single tx)
111
+ * - 2 = second child transaction
112
+ * - etc.
113
+ *
114
+ * This must match the `index` prop of <transaction-playback>
115
+ */
116
+ transactionIndex: number
117
+
118
+ /**
119
+ * Human-readable explanation of why this modification occurred
120
+ *
121
+ * @example "User enabled force transfer to EOA"
122
+ * @example "Slippage tolerance increased to 2%"
123
+ * @example "Gas limit adjusted for complex operation"
124
+ */
125
+ reason: string
126
+
127
+ /**
128
+ * Whether this modification was triggered by user interaction
129
+ *
130
+ * - true: User clicked checkbox, changed input, adjusted slider, etc.
131
+ * - false: Automatic adjustment by view logic
132
+ */
133
+ userInitiated: boolean
134
+
135
+ /**
136
+ * Optional structured summary for quick display/logging
137
+ */
138
+ summary?: {
139
+ /** Name of the field that changed */
140
+ field: string
141
+
142
+ /** Human-readable old value */
143
+ oldValue: string
144
+
145
+ /** Human-readable new value */
146
+ newValue: string
147
+ }
148
+
149
+ /**
150
+ * Optional validation information
151
+ */
152
+ validation?: {
153
+ /** Whether the modification is valid */
154
+ isValid: boolean
155
+
156
+ /** Error message if invalid */
157
+ error?: string
158
+
159
+ /** Warning messages (modification is valid but user should be aware) */
160
+ warnings?: string[]
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Extended modification info added by transaction-playback
166
+ *
167
+ * This is what the top-level container receives after transaction-playback
168
+ * adds context about where in the transaction tree this modification applies.
169
+ */
170
+ export interface TransactionModificationWithContext
171
+ extends TransactionModification {
172
+ /**
173
+ * Path from root transaction to this transaction
174
+ *
175
+ * @example [1] - Simple transaction at index 1
176
+ * @example [0, 2] - Batch at index 0, child at index 2
177
+ * @example [0, 1, 0] - Nested batch: batch[0].children[1].children[0]
178
+ */
179
+ transactionPath: number[]
180
+
181
+ /**
182
+ * The full local transaction object with modified data
183
+ * (Before re-wrapping)
184
+ */
185
+ localTransaction: any // DecoderResult, but avoiding circular dep
186
+
187
+ /**
188
+ * Re-decoded result for verification
189
+ * Parent should verify this decodes successfully before applying
190
+ */
191
+ decodedResult: any // DecoderResult
192
+ }
193
+
194
+ /**
195
+ * Type-safe custom event for transaction modifications
196
+ */
197
+ export interface TransactionModificationEvent extends CustomEvent {
198
+ detail: TransactionModification
199
+ }
200
+
201
+ /**
202
+ * Event type names for transaction views
203
+ */
204
+ export const TransactionViewEvents = {
205
+ /**
206
+ * Emitted when a view wants to provide custom header information
207
+ * Parent containers should listen for this event and update their header accordingly
208
+ */
209
+ HEADER_INFO: 'header-info',
210
+
211
+ /**
212
+ * Emitted when a view modifies its transaction data
213
+ * Parent containers should listen, re-wrap if needed, and update the transaction
214
+ */
215
+ TRANSACTION_MODIFICATION: 'transaction-modification',
216
+
217
+ /**
218
+ * Emitted when a view's state changes (future use)
219
+ * @example Loading state, error state, interactive state changes
220
+ */
221
+ STATE_CHANGE: 'view-state-change',
222
+
223
+ /**
224
+ * Emitted when a view has an action for the user (future use)
225
+ * @example "Approve", "Reject", "Sign"
226
+ */
227
+ ACTION: 'view-action',
228
+ } as const
229
+
230
+ /**
231
+ * Helper function to dispatch header info event
232
+ * Use this in view components to emit header information
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * import { dispatchHeaderInfo } from '@lukso/transaction-view-headless'
237
+ *
238
+ * class MyTransferView extends LitElement {
239
+ * connectedCallback() {
240
+ * super.connectedCallback()
241
+ * dispatchHeaderInfo(this, {
242
+ * from: this.transferFrom,
243
+ * to: this.transferTo,
244
+ * title: 'Token Transfer'
245
+ * })
246
+ * }
247
+ * }
248
+ * ```
249
+ */
250
+ export function dispatchHeaderInfo(
251
+ element: HTMLElement,
252
+ headerInfo: TransactionHeaderInfo
253
+ ): void {
254
+ element.dispatchEvent(
255
+ new CustomEvent(TransactionViewEvents.HEADER_INFO, {
256
+ bubbles: true,
257
+ composed: true, // Allows event to cross shadow DOM boundaries
258
+ detail: headerInfo,
259
+ })
260
+ )
261
+ }
262
+
263
+ /**
264
+ * Type guard to check if an event is a HeaderInfoEvent
265
+ */
266
+ export function isHeaderInfoEvent(event: Event): event is HeaderInfoEvent {
267
+ return (
268
+ event instanceof CustomEvent &&
269
+ event.type === TransactionViewEvents.HEADER_INFO
270
+ )
271
+ }
272
+
273
+ /**
274
+ * Helper function to dispatch transaction modification event
275
+ * Use this in view components to emit transaction modifications
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * import { dispatchTransactionModification } from '@lukso/transaction-view-headless'
280
+ *
281
+ * class MyTransferView extends LitElement {
282
+ * private handleForceCheckbox(checked: boolean) {
283
+ * const newData = encodeFunctionData({
284
+ * abi: LSP7_ABI,
285
+ * functionName: 'transfer',
286
+ * args: [...args, checked]
287
+ * })
288
+ *
289
+ * dispatchTransactionModification(this, {
290
+ * data: newData,
291
+ * transactionIndex: this.index,
292
+ * reason: 'User enabled force transfer',
293
+ * userInitiated: true
294
+ * })
295
+ * }
296
+ * }
297
+ * ```
298
+ */
299
+ export function dispatchTransactionModification(
300
+ element: HTMLElement,
301
+ modification: TransactionModification
302
+ ): void {
303
+ element.dispatchEvent(
304
+ new CustomEvent(TransactionViewEvents.TRANSACTION_MODIFICATION, {
305
+ bubbles: true,
306
+ composed: true,
307
+ detail: modification,
308
+ })
309
+ )
310
+ }
311
+
312
+ /**
313
+ * Type guard to check if an event is a TransactionModificationEvent
314
+ */
315
+ export function isTransactionModificationEvent(
316
+ event: Event
317
+ ): event is TransactionModificationEvent {
318
+ return (
319
+ event instanceof CustomEvent &&
320
+ event.type === TransactionViewEvents.TRANSACTION_MODIFICATION
321
+ )
322
+ }