@lukso/transaction-view-headless 0.2.2-dev.a8c9315

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 (76) hide show
  1. package/.turbo/turbo-build.log +51 -0
  2. package/CHANGELOG.md +88 -0
  3. package/COMPONENT_ARCHITECTURE.md +190 -0
  4. package/COMPONENT_CONVERSION_ANALYSIS.md +371 -0
  5. package/CONTEXT_VARIANT_GUIDE.md +425 -0
  6. package/LAZY_LOADING_GUIDE.md +534 -0
  7. package/LICENSE +201 -0
  8. package/PLAYBACK_EXAMPLES.md +658 -0
  9. package/PLAYBACK_GUIDE.md +402 -0
  10. package/README.md +43 -0
  11. package/REGISTRY_SUMMARY.md +638 -0
  12. package/SUFFERING_ECONOMICS.md +346 -0
  13. package/SUFFERING_ECONOMICS.zip +0 -0
  14. package/VIEW_REGISTRATION_GUIDE.md +795 -0
  15. package/dist/composables/index.cjs +1321 -0
  16. package/dist/composables/index.cjs.map +1 -0
  17. package/dist/composables/index.d.cts +6 -0
  18. package/dist/composables/index.d.ts +6 -0
  19. package/dist/composables/index.js +1276 -0
  20. package/dist/composables/index.js.map +1 -0
  21. package/dist/index-CMLU1hKL.d.ts +374 -0
  22. package/dist/index-CSDjhiKV.d.cts +374 -0
  23. package/dist/index.cjs +1534 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +93 -0
  26. package/dist/index.d.ts +93 -0
  27. package/dist/index.js +1463 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/registry/index.cjs +522 -0
  30. package/dist/registry/index.cjs.map +1 -0
  31. package/dist/registry/index.d.cts +46 -0
  32. package/dist/registry/index.d.ts +46 -0
  33. package/dist/registry/index.js +487 -0
  34. package/dist/registry/index.js.map +1 -0
  35. package/dist/types/index.cjs +19 -0
  36. package/dist/types/index.cjs.map +1 -0
  37. package/dist/types/index.d.cts +203 -0
  38. package/dist/types/index.d.ts +203 -0
  39. package/dist/types/index.js +1 -0
  40. package/dist/types/index.js.map +1 -0
  41. package/dist/utils/index.cjs +217 -0
  42. package/dist/utils/index.cjs.map +1 -0
  43. package/dist/utils/index.d.cts +47 -0
  44. package/dist/utils/index.d.ts +47 -0
  45. package/dist/utils/index.js +188 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/view-loader-dD86QAlQ.d.cts +121 -0
  48. package/dist/view-loader-ii8AxiQR.d.ts +121 -0
  49. package/package.json +64 -0
  50. package/publish.log +0 -0
  51. package/src/composables/index.ts +59 -0
  52. package/src/composables/use-image-loader.ts +315 -0
  53. package/src/composables/use-transaction-playback.ts +396 -0
  54. package/src/composables/use-transaction-view.ts +309 -0
  55. package/src/config/lukso-config.ts +171 -0
  56. package/src/examples/context-aware-views.ts +300 -0
  57. package/src/examples/example-views.ts +197 -0
  58. package/src/examples/lit-plus-rn-strategy.ts +448 -0
  59. package/src/examples/lsp7-custom-matcher-examples.ts +174 -0
  60. package/src/examples/opt-in-context-examples.ts +372 -0
  61. package/src/examples/optimized-view-definitions.ts +408 -0
  62. package/src/examples/vue-to-lit-compilation.ts +358 -0
  63. package/src/hooks/useAddressQuery.ts +135 -0
  64. package/src/hooks/useAddressResolution.ts +437 -0
  65. package/src/index.ts +36 -0
  66. package/src/registry/index.ts +13 -0
  67. package/src/registry/view-loader.ts +305 -0
  68. package/src/registry/view-registry.ts +135 -0
  69. package/src/types/index.ts +16 -0
  70. package/src/types/view-contexts.ts +72 -0
  71. package/src/types/view-matching.ts +173 -0
  72. package/src/utils/context-matcher.ts +165 -0
  73. package/src/utils/index.ts +5 -0
  74. package/src/utils/view-matcher.ts +338 -0
  75. package/tsconfig.json +20 -0
  76. package/tsup.config.ts +34 -0
@@ -0,0 +1,374 @@
1
+ import * as _preact_signals_core from '@preact/signals-core';
2
+ import { Chain } from 'viem';
3
+ import { ProfileData, AssetData, TokenData, ImageData, DecoderResult, AddressIdentityCache, EnhancedInfo } from '@lukso/transaction-decoder';
4
+ import { ViewMatch, ViewMatchOptions, ViewRegistry } from './types/index.cjs';
5
+ import { V as ViewLoadingError } from './view-loader-dD86QAlQ.cjs';
6
+
7
+ interface LuksoConfig {
8
+ /** Chain ID for LUKSO network (42 for mainnet, 4201 for testnet) */
9
+ chainId: number;
10
+ /** RPC endpoint for the LUKSO network */
11
+ rpcUrl: string;
12
+ /** GraphQL endpoint for address resolution */
13
+ graphqlEndpoint?: string;
14
+ /** IPFS gateway for profile images and metadata */
15
+ ipfsGateway?: string;
16
+ /** Enable/disable address resolution */
17
+ enableAddressResolution?: boolean;
18
+ /** Cache duration for resolved addresses (in milliseconds) */
19
+ cacheDuration?: number;
20
+ }
21
+ /**
22
+ * Set global LUKSO configuration
23
+ * Call this once to configure all transaction components
24
+ */
25
+ declare function setLuksoConfig(config: Partial<LuksoConfig>): void;
26
+ /**
27
+ * Get current LUKSO configuration
28
+ */
29
+ declare function getLuksoConfig(): LuksoConfig;
30
+ /**
31
+ * Quick helper to set mainnet configuration
32
+ */
33
+ declare function useLuksoMainnet(): void;
34
+ /**
35
+ * Quick helper to set testnet configuration
36
+ */
37
+ declare function useLuksoTestnet(): void;
38
+ declare function cacheAddress(address: string, data: any): void;
39
+ declare function getCachedAddress(address: string): any | null;
40
+ declare function clearAddressCache(): void;
41
+ /**
42
+ * Check if address resolution is enabled
43
+ */
44
+ declare function isAddressResolutionEnabled(): boolean;
45
+ /**
46
+ * Current chain signal for reactive chain state
47
+ */
48
+ declare const currentChainSignal: _preact_signals_core.Signal<Chain | null>;
49
+ /**
50
+ * Set current chain signal from viem chain object
51
+ */
52
+ declare function setCurrentChain(chain: Chain): void;
53
+ /**
54
+ * Get current chain, falling back to chain derived from global config
55
+ */
56
+ declare function getCurrentChain(): Chain | null;
57
+ /**
58
+ * Initialize chain signal from global config
59
+ */
60
+ declare function initializeChainSignal(): Promise<void>;
61
+
62
+ /**
63
+ * Framework-agnostic address resolution hook
64
+ * Can be adapted for Vue (composable), React (hook), or Lit (controller)
65
+ * Uses batching mechanism inspired by the decoder package
66
+ */
67
+
68
+ /**
69
+ * Union type of all possible resolved address data
70
+ * Combines Profile, Asset, and Token data structures
71
+ */
72
+ type ResolvedAddress = {
73
+ address: string;
74
+ hasProfile: boolean;
75
+ truncatedAddress: string;
76
+ __gqltype?: 'Profile' | 'Asset' | 'Token' | 'Contract';
77
+ } & Partial<ProfileData> & Partial<AssetData> & Partial<TokenData>;
78
+ /**
79
+ * Resolve a single address using batched resolution
80
+ * Returns immediately with cached data or fallback, then updates with resolved data
81
+ * Handles both plain addresses and address-tokenId composite format (with - separator)
82
+ */
83
+ declare function resolveAddress(address: string, chainId?: number): Promise<ResolvedAddress>;
84
+ /**
85
+ * Resolve multiple addresses
86
+ */
87
+ declare function resolveAddresses(addresses: string[], chainId?: number): Promise<Map<string, ResolvedAddress>>;
88
+ /**
89
+ * Simple reactive state for frameworks to implement
90
+ * Each framework will wrap this with their reactivity system
91
+ */
92
+ interface AddressResolutionState {
93
+ resolved: ResolvedAddress | null;
94
+ loading: boolean;
95
+ error: string | null;
96
+ }
97
+ /**
98
+ * Create initial state
99
+ */
100
+ declare function createAddressResolutionState(): AddressResolutionState;
101
+ /**
102
+ * Framework-agnostic resolution function that updates state
103
+ */
104
+ declare function resolveAddressWithState(address: string, _state: AddressResolutionState, updateCallback: (newState: Partial<AddressResolutionState>) => void, chainId?: number): Promise<void>;
105
+
106
+ /**
107
+ * Image loading configuration for different contexts
108
+ */
109
+ interface ImageLoadOptions {
110
+ width?: number;
111
+ height?: number;
112
+ dpr?: number;
113
+ index?: number;
114
+ }
115
+ /**
116
+ * Resolved image result
117
+ */
118
+ interface ImageResult {
119
+ src: string;
120
+ width?: number;
121
+ height?: number;
122
+ }
123
+ /**
124
+ * Address/Profile data structure for image resolution
125
+ * Note: GraphQL pluralizes field names (icons, not icon)
126
+ */
127
+ interface AddressImageData {
128
+ profileImages?: ImageData[];
129
+ avatar?: ImageData[];
130
+ icons?: ImageData[];
131
+ images?: ImageData[];
132
+ __gqltype?: string;
133
+ }
134
+ /**
135
+ * Composable for loading images from various sources
136
+ * Extracted from Vue AddressView component for framework-agnostic use
137
+ */
138
+ declare function useImageLoader(): {
139
+ loadImage: (imageData: any[], options?: ImageLoadOptions) => Promise<ImageResult | null>;
140
+ loadProfileImage: (addressData: AddressImageData, options?: ImageLoadOptions) => Promise<ImageResult | null>;
141
+ loadBackgroundImage: (addressData: AddressImageData & {
142
+ backgroundImages?: any[];
143
+ }, options?: ImageLoadOptions) => Promise<ImageResult | null>;
144
+ getFallbackImage: (addressData: AddressImageData) => ImageResult;
145
+ isContractAddress: (addressData: AddressImageData) => boolean;
146
+ };
147
+ /**
148
+ * Composable for address resolution and formatting
149
+ * Connected to decoder package's GraphQL AddressResolver
150
+ */
151
+ declare function useAddressResolver(): {
152
+ resolveAddress: (address: string) => Promise<any>;
153
+ formatDisplayName: (addressData: any) => string;
154
+ getAddressPrefix: (addressData: any) => string;
155
+ shouldShowNameColor: (addressData: any) => boolean;
156
+ };
157
+
158
+ /**
159
+ * Transaction Playback System
160
+ *
161
+ * Provides index-based access to transaction views with smart handling of batches:
162
+ *
163
+ * **Single Transaction:**
164
+ * - Index 0: The transaction itself
165
+ * - Index 1: The transaction itself (same as 0)
166
+ * - Index 2+: null
167
+ *
168
+ * **Batch Transaction (setDataBatch, executeBatch):**
169
+ * - Index 0: Summary/expandable view of the batch
170
+ * - Index 1: First child transaction
171
+ * - Index 2: Second child transaction
172
+ * - Index N: Nth child transaction
173
+ *
174
+ * This design allows UI flexibility:
175
+ * - Always use index 1 to skip batch summaries
176
+ * - Use index 0 to show batch overview (optional)
177
+ * - Navigate batch children by index
178
+ */
179
+ /**
180
+ * Options for transaction playback
181
+ */
182
+ interface TransactionPlaybackOptions extends Partial<ViewMatchOptions> {
183
+ /** Custom registry to use instead of global */
184
+ registry?: ViewRegistry;
185
+ /** Fallback view ID if no matches found */
186
+ fallbackViewId?: string;
187
+ /** Chain for address resolution */
188
+ chain?: Chain;
189
+ }
190
+ /**
191
+ * Result of selecting a view at a specific index
192
+ */
193
+ interface PlaybackIndexResult {
194
+ /** The selected view match (or null if invalid index) */
195
+ match: ViewMatch | null;
196
+ /** The transaction data for this index */
197
+ transaction: DecoderResult | null;
198
+ /** Index information */
199
+ indexInfo: {
200
+ /** Requested index */
201
+ requested: number;
202
+ /** Actual index in children array (for batches) */
203
+ childIndex: number | null;
204
+ /** Whether this is a batch summary view (index 0 of batch) */
205
+ isBatchSummary: boolean;
206
+ /** Whether this is a valid index */
207
+ isValid: boolean;
208
+ };
209
+ /** Batch information (if applicable) */
210
+ batchInfo: {
211
+ /** Whether the root transaction is a batch */
212
+ isBatch: boolean;
213
+ /** Total number of children in batch (0 if not batch) */
214
+ childCount: number;
215
+ /** Available indices (e.g., [0, 1, 2, 3] for 3-child batch) */
216
+ availableIndices: number[];
217
+ };
218
+ }
219
+ /**
220
+ * Complete playback state for a transaction
221
+ */
222
+ interface TransactionPlaybackState {
223
+ /** The root transaction */
224
+ rootTransaction: DecoderResult;
225
+ /** Whether this is a batch transaction */
226
+ isBatch: boolean;
227
+ /** Child transactions (empty if not batch) */
228
+ children: DecoderResult[];
229
+ /** Total count of available indices */
230
+ indexCount: number;
231
+ /** Batch information */
232
+ batchInfo: {
233
+ /** Whether the root transaction is a batch */
234
+ isBatch: boolean;
235
+ /** Total number of children in batch (0 if not batch) */
236
+ childCount: number;
237
+ /** Available indices (e.g., [0, 1, 2, 3] for 3-child batch) */
238
+ availableIndices: number[];
239
+ };
240
+ /** Get view match for a specific index */
241
+ getViewAtIndex: (index: number) => PlaybackIndexResult;
242
+ /** Get all available views */
243
+ getAllViews: () => PlaybackIndexResult[];
244
+ }
245
+ /**
246
+ * Create a playback state for a transaction
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const playback = createTransactionPlayback(transaction, { framework: 'lit' })
251
+ *
252
+ * // For single transaction:
253
+ * playback.getViewAtIndex(0) // Returns the transaction
254
+ * playback.getViewAtIndex(1) // Returns the transaction (same)
255
+ * playback.getViewAtIndex(2) // Returns null (invalid)
256
+ *
257
+ * // For batch transaction:
258
+ * playback.getViewAtIndex(0) // Returns batch summary
259
+ * playback.getViewAtIndex(1) // Returns first child
260
+ * playback.getViewAtIndex(2) // Returns second child
261
+ * ```
262
+ */
263
+ declare function createTransactionPlayback(rootTransaction: DecoderResult, options?: TransactionPlaybackOptions): TransactionPlaybackState;
264
+ /**
265
+ * Simplified composable that just returns the view at a specific index
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Vue
270
+ * const index = ref(1) // Always show main transaction, skip batch summaries
271
+ * const result = useTransactionPlayback(transaction, index, { framework: 'lit' })
272
+ *
273
+ * // React
274
+ * const [index, setIndex] = useState(1)
275
+ * const result = useTransactionPlayback(transaction, index, { framework: 'lit' })
276
+ * ```
277
+ */
278
+ declare function useTransactionPlayback(rootTransaction: DecoderResult, index: number, options?: TransactionPlaybackOptions): PlaybackIndexResult;
279
+ /**
280
+ * Helper to check if an index is valid for a transaction
281
+ */
282
+ declare function isValidPlaybackIndex(transaction: DecoderResult, index: number): boolean;
283
+ /**
284
+ * Helper to get the range of valid indices for a transaction
285
+ */
286
+ declare function getValidPlaybackIndices(transaction: DecoderResult): number[];
287
+
288
+ /**
289
+ * Options for the transaction view composable
290
+ */
291
+ interface UseTransactionViewOptions extends Partial<ViewMatchOptions> {
292
+ /** Custom registry to use instead of global */
293
+ registry?: ViewRegistry;
294
+ /** Whether to automatically load the best matching component */
295
+ autoLoad?: boolean;
296
+ /** Fallback view ID to use if no matches found */
297
+ fallbackViewId?: string;
298
+ /** Whether to resolve addresses for this view (uses transaction.addresses array) */
299
+ resolve?: boolean;
300
+ /** Chain for address resolution (required if resolve: true) */
301
+ chain?: Chain;
302
+ /** Optional cache adapter for address resolution */
303
+ addressCache?: AddressIdentityCache;
304
+ }
305
+ /**
306
+ * Result from the transaction view composable
307
+ */
308
+ interface UseTransactionViewResult {
309
+ /** All matching views sorted by score */
310
+ matches: ViewMatch[];
311
+ /** The best matching view (highest score) */
312
+ bestMatch: ViewMatch | null;
313
+ /** The loaded component (if autoLoad is true) */
314
+ component: any;
315
+ /** Loading state */
316
+ isLoading: boolean;
317
+ /** Error state */
318
+ error: ViewLoadingError | null;
319
+ /** Address resolution loading state */
320
+ isResolvingAddresses: boolean;
321
+ /** Resolved address data map (if resolve: true) */
322
+ resolvedAddresses: Record<string, EnhancedInfo>;
323
+ /** Function to manually load a specific match */
324
+ loadMatch: (match: ViewMatch) => Promise<any>;
325
+ /** Function to load the best match */
326
+ loadBestMatch: () => Promise<any>;
327
+ /** Function to refresh matches (useful if registry changes) */
328
+ refreshMatches: () => void;
329
+ /** Function to manually trigger address resolution */
330
+ resolveAddresses: () => Promise<void>;
331
+ }
332
+ /**
333
+ * Framework-agnostic composable for finding and loading transaction views
334
+ *
335
+ * This is the main entry point for the view system. It handles:
336
+ * - Finding matching views based on transaction data
337
+ * - Loading components using the appropriate strategy
338
+ * - Providing a consistent API across all frameworks
339
+ *
340
+ * Usage in Vue:
341
+ * ```ts
342
+ * const { bestMatch, component, isLoading, resolvedAddresses } = useTransactionView(transaction, {
343
+ * framework: 'lit',
344
+ * autoLoad: true,
345
+ * resolve: true, // Auto-resolve addresses from transaction.addresses array
346
+ * chain: lukso, // Required for address resolution
347
+ * addressCache: cache // Optional cache adapter
348
+ * })
349
+ * ```
350
+ *
351
+ * Usage in React/React Native:
352
+ * ```ts
353
+ * const { bestMatch, component, loadBestMatch, resolvedAddresses, isResolvingAddresses } = useTransactionView(transaction, {
354
+ * framework: 'react-native',
355
+ * resolve: true,
356
+ * chain: luksoTestnet,
357
+ * addressCache: myCache
358
+ * })
359
+ * useEffect(() => {
360
+ * loadBestMatch()
361
+ * }, [transaction])
362
+ * ```
363
+ */
364
+ declare function useTransactionView(transaction: DecoderResult, options: UseTransactionViewOptions): UseTransactionViewResult;
365
+ /**
366
+ * Simplified version that just returns the best matching view without loading
367
+ */
368
+ declare function findBestTransactionView(transaction: DecoderResult, framework: 'lit' | 'rn', registry?: ViewRegistry): ViewMatch | null;
369
+ /**
370
+ * Get all matching views without loading
371
+ */
372
+ declare function findAllTransactionViews(transaction: DecoderResult, framework: 'lit' | 'rn', registry?: ViewRegistry): ViewMatch[];
373
+
374
+ export { type AddressImageData as A, setCurrentChain as B, getCurrentChain as C, initializeChainSignal as D, type ImageLoadOptions as I, type LuksoConfig as L, type PlaybackIndexResult as P, type ResolvedAddress as R, type TransactionPlaybackOptions as T, type UseTransactionViewOptions as U, type AddressResolutionState as a, type ImageResult as b, type UseTransactionViewResult as c, cacheAddress as d, clearAddressCache as e, findBestTransactionView as f, getCachedAddress as g, getLuksoConfig as h, isAddressResolutionEnabled as i, useLuksoMainnet as j, useLuksoTestnet as k, createAddressResolutionState as l, resolveAddresses as m, resolveAddressWithState as n, useAddressResolver as o, useImageLoader as p, type TransactionPlaybackState as q, resolveAddress as r, setLuksoConfig as s, createTransactionPlayback as t, useTransactionView as u, getValidPlaybackIndices as v, isValidPlaybackIndex as w, useTransactionPlayback as x, findAllTransactionViews as y, currentChainSignal as z };