@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,408 @@
1
+ import { LoaderHelpers } from '../registry/view-loader'
2
+ import type { ViewDefinition } from '../types/view-matching'
3
+
4
+ /**
5
+ * Optimized View Definitions: Suffering Economics in Action
6
+ *
7
+ * Following our mathematical proof that 2 strategic implementations
8
+ * provide superior outcomes to 4+ framework-specific implementations,
9
+ * these view definitions demonstrate the practical application of
10
+ * Suffering Economics optimization.
11
+ */
12
+
13
+ export const OptimizedViewDefinitions: ViewDefinition[] = [
14
+ // LSP7 Transfer: Universal web + Mobile native
15
+ {
16
+ id: 'lsp7-transfer-optimized',
17
+ name: 'LSP7 Transfer (Suffering Optimized)',
18
+ description:
19
+ 'Universal web component + native mobile, 2x less suffering than traditional approach',
20
+ priority: 100,
21
+ criteria: {
22
+ recordType: 'lsp7-transfer',
23
+ standard: 'LSP7',
24
+ },
25
+ frameworks: {
26
+ // Universal web compatibility (works in Vue, React, Angular, Svelte, etc.)
27
+ lit: {
28
+ loader: LoaderHelpers.litComponent('lsp7-transfer-view'),
29
+ component: 'lsp7-transfer-view',
30
+ package: '@lukso/decoder-web-components',
31
+ },
32
+ // Mobile-native optimization
33
+ rn: {
34
+ loader: LoaderHelpers.rnComponent(
35
+ '@lukso/decoder-rn-views/LSP7Transfer.jsx'
36
+ ),
37
+ component: 'LSP7Transfer',
38
+ package: '@lukso/decoder-rn-views',
39
+ },
40
+ },
41
+ },
42
+
43
+ // LSP8 Transfer: Context-aware versions
44
+ {
45
+ id: 'lsp8-transfer-approval',
46
+ name: 'LSP8 Transfer (Approval Context)',
47
+ description: 'Security-focused approval view for NFT transfers',
48
+ priority: 120,
49
+ criteria: {
50
+ recordType: 'lsp8-transfer',
51
+ standard: 'LSP8',
52
+ context: 'approval',
53
+ },
54
+ frameworks: {
55
+ lit: {
56
+ loader: LoaderHelpers.litComponent('lsp8-transfer-approval'),
57
+ component: 'lsp8-transfer-approval',
58
+ package: '@lukso/decoder-web-components',
59
+ },
60
+ rn: {
61
+ loader: LoaderHelpers.rnComponent(
62
+ '@lukso/decoder-rn-views/approval/LSP8TransferApproval.jsx'
63
+ ),
64
+ component: 'LSP8TransferApproval',
65
+ package: '@lukso/decoder-rn-views',
66
+ },
67
+ },
68
+ },
69
+
70
+ {
71
+ id: 'lsp8-transfer-feed',
72
+ name: 'LSP8 Transfer (Feed Context)',
73
+ description: 'Compact view for activity feeds',
74
+ priority: 110,
75
+ criteria: {
76
+ recordType: 'lsp8-transfer',
77
+ standard: 'LSP8',
78
+ context: ['feed', 'list'],
79
+ },
80
+ frameworks: {
81
+ lit: {
82
+ loader: LoaderHelpers.litComponent('lsp8-transfer-compact'),
83
+ component: 'lsp8-transfer-compact',
84
+ package: '@lukso/decoder-web-components',
85
+ },
86
+ rn: {
87
+ loader: LoaderHelpers.rnComponent(
88
+ '@lukso/decoder-rn-views/feed/LSP8TransferFeed.jsx'
89
+ ),
90
+ component: 'LSP8TransferFeed',
91
+ package: '@lukso/decoder-rn-views',
92
+ },
93
+ },
94
+ },
95
+
96
+ // Execute Batch: Complex transaction handling
97
+ {
98
+ id: 'execute-batch-universal',
99
+ name: 'Execute Batch (Universal)',
100
+ description:
101
+ 'Expandable batch transaction view with child transaction support',
102
+ priority: 100,
103
+ criteria: {
104
+ recordType: 'executeBatch',
105
+ functionName: 'executeBatch',
106
+ },
107
+ frameworks: {
108
+ lit: {
109
+ loader: LoaderHelpers.litComponent('execute-batch-view'),
110
+ component: 'execute-batch-view',
111
+ package: '@lukso/decoder-web-components',
112
+ },
113
+ rn: {
114
+ loader: LoaderHelpers.rnComponent(
115
+ '@lukso/decoder-rn-views/ExecuteBatch.jsx'
116
+ ),
117
+ component: 'ExecuteBatch',
118
+ package: '@lukso/decoder-rn-views',
119
+ },
120
+ },
121
+ },
122
+
123
+ // Set Data: Key-value operations
124
+ {
125
+ id: 'set-data-detailed',
126
+ name: 'Set Data Operation',
127
+ description: 'Key-value display with expandable details',
128
+ priority: 90,
129
+ criteria: {
130
+ functionName: 'setData',
131
+ recordType: 'set-data',
132
+ },
133
+ frameworks: {
134
+ lit: {
135
+ loader: LoaderHelpers.litComponent('set-data-view'),
136
+ component: 'set-data-view',
137
+ package: '@lukso/decoder-web-components',
138
+ },
139
+ rn: {
140
+ loader: LoaderHelpers.rnComponent(
141
+ '@lukso/decoder-rn-views/SetData.jsx'
142
+ ),
143
+ component: 'SetData',
144
+ package: '@lukso/decoder-rn-views',
145
+ },
146
+ },
147
+ },
148
+
149
+ // High-value transaction: Custom matching logic
150
+ {
151
+ id: 'high-value-transfer',
152
+ name: 'High-Value Transfer Warning',
153
+ description:
154
+ 'Special handling for high-value transfers (>1 ETH equivalent)',
155
+ priority: 150, // Higher priority to catch high-value transfers
156
+ criteria: {
157
+ functionName: 'transfer',
158
+ customMatcher: (transaction) => {
159
+ if (!transaction.value) return false
160
+ return BigInt(transaction.value) > BigInt('1000000000000000000') // > 1 ETH
161
+ },
162
+ },
163
+ frameworks: {
164
+ lit: {
165
+ loader: LoaderHelpers.litComponent('high-value-transfer-warning'),
166
+ component: 'high-value-transfer-warning',
167
+ package: '@lukso/decoder-web-components',
168
+ },
169
+ rn: {
170
+ loader: LoaderHelpers.rnComponent(
171
+ '@lukso/decoder-rn-views/HighValueTransfer.jsx'
172
+ ),
173
+ component: 'HighValueTransfer',
174
+ package: '@lukso/decoder-rn-views',
175
+ },
176
+ },
177
+ },
178
+
179
+ // Universal fallback: Catches everything else
180
+ {
181
+ id: 'generic-transaction-fallback',
182
+ name: 'Generic Transaction (Universal Fallback)',
183
+ description: 'Fallback view for unknown transaction types',
184
+ priority: 10, // Lowest priority
185
+ criteria: {
186
+ // No specific criteria = matches everything
187
+ customMatcher: () => true,
188
+ },
189
+ frameworks: {
190
+ lit: {
191
+ loader: LoaderHelpers.litComponent('generic-transaction-view'),
192
+ component: 'generic-transaction-view',
193
+ package: '@lukso/decoder-web-components',
194
+ },
195
+ rn: {
196
+ loader: LoaderHelpers.rnComponent(
197
+ '@lukso/decoder-rn-views/GenericTransaction.jsx'
198
+ ),
199
+ component: 'GenericTransaction',
200
+ package: '@lukso/decoder-rn-views',
201
+ },
202
+ },
203
+ },
204
+
205
+ // Context-specific fallbacks
206
+ {
207
+ id: 'generic-approval-fallback',
208
+ name: 'Generic Approval (Context Fallback)',
209
+ description: 'Fallback for unknown transactions in approval context',
210
+ priority: 15,
211
+ criteria: {
212
+ context: 'approval',
213
+ customMatcher: () => true,
214
+ },
215
+ frameworks: {
216
+ lit: {
217
+ loader: LoaderHelpers.litComponent('generic-approval-view'),
218
+ component: 'generic-approval-view',
219
+ package: '@lukso/decoder-web-components',
220
+ },
221
+ rn: {
222
+ loader: LoaderHelpers.rnComponent(
223
+ '@lukso/decoder-rn-views/approval/GenericApproval.jsx'
224
+ ),
225
+ component: 'GenericApproval',
226
+ package: '@lukso/decoder-rn-views',
227
+ },
228
+ },
229
+ },
230
+ ]
231
+
232
+ /**
233
+ * Usage examples demonstrating the suffering reduction in practice
234
+ */
235
+ export const UsageExamples = {
236
+ // Vue usage (universal web component)
237
+ vueUsage: `
238
+ <!-- Vue: Uses Lit web component seamlessly -->
239
+ <template>
240
+ <div class="transaction-container">
241
+ <lsp7-transfer-view
242
+ :transaction="transaction"
243
+ :show-actions="showActions"
244
+ @approve="handleApprove"
245
+ @reject="handleReject"
246
+ @address-click="handleAddressClick"
247
+ />
248
+ </div>
249
+ </template>
250
+
251
+ <script setup>
252
+ import '@lukso/decoder-web-components' // Registers all web components
253
+
254
+ const props = defineProps(['transaction', 'showActions'])
255
+ const emit = defineEmits(['approve', 'reject', 'address-click'])
256
+
257
+ const handleApprove = (event) => emit('approve', event.detail)
258
+ const handleReject = (event) => emit('reject', event.detail)
259
+ const handleAddressClick = (event) => emit('address-click', event.detail)
260
+ </script>
261
+
262
+ <!-- Vue developers barely notice it's a web component! -->`,
263
+
264
+ // React usage (with @lit-labs/react wrapper)
265
+ reactUsage: `
266
+ // React: Seamless integration via wrapper
267
+ import { LSP7Transfer } from '@lukso/decoder-react-wrappers'
268
+
269
+ function TransactionApproval({ transaction, showActions }) {
270
+ const handleApprove = (transactionData) => {
271
+ console.log('Approved:', transactionData)
272
+ }
273
+
274
+ return (
275
+ <div className="transaction-container">
276
+ <LSP7Transfer
277
+ transaction={transaction}
278
+ showActions={showActions}
279
+ onApprove={handleApprove}
280
+ onReject={handleReject}
281
+ onAddressClick={handleAddressClick}
282
+ />
283
+ </div>
284
+ )
285
+ }
286
+
287
+ // Feels like a normal React component, but it's actually a Lit web component!`,
288
+
289
+ // React Native usage (native components)
290
+ reactNativeUsage: `
291
+ // React Native: Platform-optimized native components
292
+ import { LSP7Transfer } from '@lukso/decoder-rn-views'
293
+ import { View, StyleSheet } from rn
294
+
295
+ function TransactionScreen({ transaction, showActions }) {
296
+ const handleApprove = (transactionData) => {
297
+ console.log('Approved:', transactionData)
298
+ }
299
+
300
+ return (
301
+ <View style={styles.container}>
302
+ <LSP7Transfer
303
+ transaction={transaction}
304
+ showActions={showActions}
305
+ onApprove={handleApprove}
306
+ onReject={handleReject}
307
+ style={styles.transaction}
308
+ />
309
+ </View>
310
+ )
311
+ }
312
+
313
+ const styles = StyleSheet.create({
314
+ container: { flex: 1, padding: 16 },
315
+ transaction: { marginVertical: 8 }
316
+ })`,
317
+
318
+ // Headless usage (framework-agnostic business logic)
319
+ headlessUsage: `
320
+ // Headless system: Framework-agnostic business logic
321
+ import { useTransactionView, getGlobalRegistry } from '@lukso/transaction-view-headless'
322
+
323
+ // Register views once at app startup
324
+ const registry = getGlobalRegistry()
325
+ OptimizedViewDefinitions.forEach(view => registry.register(view))
326
+
327
+ // Use in any framework
328
+ function SomeComponent({ transaction }) {
329
+ const { bestMatch, component, addressData } = useTransactionView(transaction, {
330
+ framework: 'lit', // or rn
331
+ context: 'approval',
332
+ autoLoad: true
333
+ })
334
+
335
+ // bestMatch.view.id = 'lsp7-transfer-optimized'
336
+ // component = the loaded web component or React Native component
337
+ // addressData = resolved address information (shared business logic)
338
+ }`,
339
+
340
+ // Multi-framework deployment
341
+ deploymentExample: `
342
+ // Same components work across ALL frameworks!
343
+
344
+ // Vue app
345
+ import '@lukso/decoder-web-components'
346
+ // Uses: <lsp7-transfer-view>
347
+
348
+ // React app
349
+ import '@lukso/decoder-react-wrappers'
350
+ // Uses: <LSP7Transfer> (wrapper around web component)
351
+
352
+ // Angular app
353
+ import '@lukso/decoder-web-components'
354
+ // Uses: <lsp7-transfer-view> with CUSTOM_ELEMENTS_SCHEMA
355
+
356
+ // Svelte app
357
+ import '@lukso/decoder-web-components'
358
+ // Uses: <lsp7-transfer-view> with native web component support
359
+
360
+ // React Native app
361
+ import { LSP7Transfer } from '@lukso/decoder-rn-views'
362
+ // Uses: Native mobile components
363
+
364
+ // Vanilla HTML
365
+ <script type="module" src="./decoder-web-components.js"></script>
366
+ <lsp7-transfer-view transaction="..."></lsp7-transfer-view>
367
+
368
+ ONE implementation, UNIVERSAL compatibility! 🎯`,
369
+ }
370
+
371
+ /**
372
+ * Benefits realized through this optimization
373
+ */
374
+ export const RealizedBenefits = [
375
+ '✅ 2x less suffering: 2 implementations instead of 4+',
376
+ '✅ Universal web compatibility: Works in ALL web frameworks',
377
+ '✅ Native mobile optimization: React Native performance',
378
+ '✅ Future-proof: New frameworks automatically supported',
379
+ '✅ Reduced maintenance: 2 codebases instead of 6+',
380
+ '✅ Consistent UX: Same components everywhere',
381
+ '✅ Better performance: Native web standards + native mobile',
382
+ '✅ Developer smugness: Mathematical superiority proven 📊',
383
+ ]
384
+
385
+ /**
386
+ * Migration strategy from traditional multi-framework approach
387
+ */
388
+ export const MigrationStrategy = `
389
+ Phase 1: Implement Lit web components
390
+ - Convert existing Vue/React components to Lit
391
+ - Maintain backward compatibility through wrappers
392
+ - Suffering level: Moderate (learning Lit)
393
+
394
+ Phase 2: Optimize React Native components
395
+ - Replace web-in-webview with native components
396
+ - Use StyleSheet and platform-specific optimizations
397
+ - Suffering level: Low (familiar React patterns)
398
+
399
+ Phase 3: Remove framework-specific implementations
400
+ - Delete Vue/React/Angular specific components
401
+ - Keep only Lit + React Native
402
+ - Suffering level: Negative (maintenance burden removed!)
403
+
404
+ Phase 4: Enjoy mathematical superiority
405
+ - Deploy universal components everywhere
406
+ - Watch competitors maintain 6+ implementations
407
+ - Suffering level: Smugness overflow error 😎
408
+ `