@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.
- package/.turbo/turbo-build.log +51 -0
- package/CHANGELOG.md +88 -0
- package/COMPONENT_ARCHITECTURE.md +190 -0
- package/COMPONENT_CONVERSION_ANALYSIS.md +371 -0
- package/CONTEXT_VARIANT_GUIDE.md +425 -0
- package/LAZY_LOADING_GUIDE.md +534 -0
- package/LICENSE +201 -0
- package/PLAYBACK_EXAMPLES.md +658 -0
- package/PLAYBACK_GUIDE.md +402 -0
- package/README.md +43 -0
- package/REGISTRY_SUMMARY.md +638 -0
- package/SUFFERING_ECONOMICS.md +346 -0
- package/SUFFERING_ECONOMICS.zip +0 -0
- package/VIEW_REGISTRATION_GUIDE.md +795 -0
- package/dist/composables/index.cjs +1321 -0
- package/dist/composables/index.cjs.map +1 -0
- package/dist/composables/index.d.cts +6 -0
- package/dist/composables/index.d.ts +6 -0
- package/dist/composables/index.js +1276 -0
- package/dist/composables/index.js.map +1 -0
- package/dist/index-CMLU1hKL.d.ts +374 -0
- package/dist/index-CSDjhiKV.d.cts +374 -0
- package/dist/index.cjs +1534 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +1463 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/index.cjs +522 -0
- package/dist/registry/index.cjs.map +1 -0
- package/dist/registry/index.d.cts +46 -0
- package/dist/registry/index.d.ts +46 -0
- package/dist/registry/index.js +487 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +203 -0
- package/dist/types/index.d.ts +203 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +217 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +47 -0
- package/dist/utils/index.d.ts +47 -0
- package/dist/utils/index.js +188 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/view-loader-dD86QAlQ.d.cts +121 -0
- package/dist/view-loader-ii8AxiQR.d.ts +121 -0
- package/package.json +64 -0
- package/publish.log +0 -0
- package/src/composables/index.ts +59 -0
- package/src/composables/use-image-loader.ts +315 -0
- package/src/composables/use-transaction-playback.ts +396 -0
- package/src/composables/use-transaction-view.ts +309 -0
- package/src/config/lukso-config.ts +171 -0
- package/src/examples/context-aware-views.ts +300 -0
- package/src/examples/example-views.ts +197 -0
- package/src/examples/lit-plus-rn-strategy.ts +448 -0
- package/src/examples/lsp7-custom-matcher-examples.ts +174 -0
- package/src/examples/opt-in-context-examples.ts +372 -0
- package/src/examples/optimized-view-definitions.ts +408 -0
- package/src/examples/vue-to-lit-compilation.ts +358 -0
- package/src/hooks/useAddressQuery.ts +135 -0
- package/src/hooks/useAddressResolution.ts +437 -0
- package/src/index.ts +36 -0
- package/src/registry/index.ts +13 -0
- package/src/registry/view-loader.ts +305 -0
- package/src/registry/view-registry.ts +135 -0
- package/src/types/index.ts +16 -0
- package/src/types/view-contexts.ts +72 -0
- package/src/types/view-matching.ts +173 -0
- package/src/utils/context-matcher.ts +165 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/view-matcher.ts +338 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +34 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { LoaderHelpers } from '../registry/view-loader'
|
|
2
|
+
import type { ViewContext } from '../types/view-contexts'
|
|
3
|
+
import type { ViewDefinition } from '../types/view-matching'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Examples showing how context support is opt-in with our optimized Lit + React Native strategy
|
|
7
|
+
*/
|
|
8
|
+
export const OptInContextExamples: ViewDefinition[] = [
|
|
9
|
+
// UNIVERSAL VIEW - Works in any context (no context specified)
|
|
10
|
+
{
|
|
11
|
+
id: 'lsp7-transfer-universal',
|
|
12
|
+
name: 'LSP7 Transfer (Universal)',
|
|
13
|
+
description: 'Works in any context - approval, feed, detail, etc.',
|
|
14
|
+
priority: 80,
|
|
15
|
+
criteria: {
|
|
16
|
+
recordType: 'lsp7-transfer',
|
|
17
|
+
standard: 'LSP7',
|
|
18
|
+
// No context specified = matches any context
|
|
19
|
+
},
|
|
20
|
+
frameworks: {
|
|
21
|
+
lit: {
|
|
22
|
+
loader: LoaderHelpers.litComponent('lsp7-transfer-view'),
|
|
23
|
+
component: 'lsp7-transfer-view',
|
|
24
|
+
package: '@lukso/decoder-web-components',
|
|
25
|
+
},
|
|
26
|
+
rn: {
|
|
27
|
+
loader: LoaderHelpers.rnComponent(
|
|
28
|
+
'@lukso/decoder-rn-views/LSP7Transfer'
|
|
29
|
+
),
|
|
30
|
+
component: 'LSP7Transfer',
|
|
31
|
+
package: '@lukso/decoder-rn-views',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// CONTEXT-SPECIFIC VIEW - Only works in approval context
|
|
37
|
+
{
|
|
38
|
+
id: 'lsp7-transfer-approval-only',
|
|
39
|
+
name: 'LSP7 Transfer (Approval Only)',
|
|
40
|
+
description: 'Specialized for approval context only',
|
|
41
|
+
priority: 120, // Higher priority when context matches
|
|
42
|
+
criteria: {
|
|
43
|
+
recordType: 'lsp7-transfer',
|
|
44
|
+
standard: 'LSP7',
|
|
45
|
+
context: 'approval', // Opt-in: ONLY matches approval context
|
|
46
|
+
},
|
|
47
|
+
frameworks: {
|
|
48
|
+
lit: {
|
|
49
|
+
loader: LoaderHelpers.litComponent('lsp7-transfer-approval'),
|
|
50
|
+
component: 'lsp7-transfer-approval',
|
|
51
|
+
package: '@lukso/decoder-web-components',
|
|
52
|
+
},
|
|
53
|
+
rn: {
|
|
54
|
+
loader: LoaderHelpers.rnComponent(
|
|
55
|
+
'@lukso/decoder-rn-views/approval/LSP7TransferApproval'
|
|
56
|
+
),
|
|
57
|
+
component: 'LSP7TransferApproval',
|
|
58
|
+
package: '@lukso/decoder-rn-views',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
// MULTI-CONTEXT VIEW - Supports multiple contexts
|
|
64
|
+
{
|
|
65
|
+
id: 'lsp7-transfer-compact',
|
|
66
|
+
name: 'LSP7 Transfer (Compact)',
|
|
67
|
+
description: 'Optimized for feed and list contexts',
|
|
68
|
+
priority: 110,
|
|
69
|
+
criteria: {
|
|
70
|
+
recordType: 'lsp7-transfer',
|
|
71
|
+
standard: 'LSP7',
|
|
72
|
+
context: ['feed', 'list'], // Opt-in: Only these two contexts
|
|
73
|
+
},
|
|
74
|
+
frameworks: {
|
|
75
|
+
lit: {
|
|
76
|
+
loader: LoaderHelpers.litComponent('lsp7-transfer-compact'),
|
|
77
|
+
component: 'lsp7-transfer-compact',
|
|
78
|
+
package: '@lukso/decoder-web-components',
|
|
79
|
+
},
|
|
80
|
+
rn: {
|
|
81
|
+
loader: LoaderHelpers.rnComponent(
|
|
82
|
+
'@lukso/decoder-rn-views/compact/LSP7TransferCompact'
|
|
83
|
+
),
|
|
84
|
+
component: 'LSP7TransferCompact',
|
|
85
|
+
package: '@lukso/decoder-rn-views',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// FALLBACK VIEW - Universal fallback
|
|
91
|
+
{
|
|
92
|
+
id: 'generic-transaction-universal',
|
|
93
|
+
name: 'Generic Transaction (Universal)',
|
|
94
|
+
description: 'Fallback for any transaction in any context',
|
|
95
|
+
priority: 10,
|
|
96
|
+
criteria: {
|
|
97
|
+
customMatcher: () => true,
|
|
98
|
+
// No context = universal fallback
|
|
99
|
+
},
|
|
100
|
+
frameworks: {
|
|
101
|
+
lit: {
|
|
102
|
+
loader: LoaderHelpers.litComponent('generic-transaction-view'),
|
|
103
|
+
component: 'generic-transaction-view',
|
|
104
|
+
package: '@lukso/decoder-web-components',
|
|
105
|
+
},
|
|
106
|
+
rn: {
|
|
107
|
+
loader: LoaderHelpers.rnComponent(
|
|
108
|
+
'@lukso/decoder-rn-views/GenericTransaction'
|
|
109
|
+
),
|
|
110
|
+
component: 'GenericTransaction',
|
|
111
|
+
package: '@lukso/decoder-rn-views',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
// CONTEXT-AWARE FALLBACK - Context-specific fallback
|
|
117
|
+
{
|
|
118
|
+
id: 'generic-approval-fallback',
|
|
119
|
+
name: 'Generic Approval Fallback',
|
|
120
|
+
description: 'Fallback for unknown transactions in approval context',
|
|
121
|
+
priority: 15, // Slightly higher than universal fallback
|
|
122
|
+
criteria: {
|
|
123
|
+
context: 'approval',
|
|
124
|
+
customMatcher: () => true,
|
|
125
|
+
},
|
|
126
|
+
frameworks: {
|
|
127
|
+
lit: {
|
|
128
|
+
loader: LoaderHelpers.litComponent('generic-approval-view'),
|
|
129
|
+
component: 'generic-approval-view',
|
|
130
|
+
package: '@lukso/decoder-web-components',
|
|
131
|
+
},
|
|
132
|
+
rn: {
|
|
133
|
+
loader: LoaderHelpers.rnComponent(
|
|
134
|
+
'@lukso/decoder-rn-views/approval/GenericApproval'
|
|
135
|
+
),
|
|
136
|
+
component: 'GenericApproval',
|
|
137
|
+
package: '@lukso/decoder-rn-views',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Examples of how view selection works with opt-in context using our optimized strategy
|
|
145
|
+
*/
|
|
146
|
+
export const SelectionExamples = {
|
|
147
|
+
// Example 1: Request WITH context (Lit web component)
|
|
148
|
+
withApprovalContextWeb: `
|
|
149
|
+
// Request: LSP7 transfer in approval context (any web framework)
|
|
150
|
+
findMatchingViews(lsp7Transaction, views, {
|
|
151
|
+
framework: 'lit',
|
|
152
|
+
context: 'approval'
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// Results (in priority order):
|
|
156
|
+
// 1. lsp7-transfer-approval-only (score: ~95%, priority: 120) ✅ Perfect match
|
|
157
|
+
// 2. lsp7-transfer-universal (score: ~70%, priority: 80) ⚠️ Universal (slight penalty)
|
|
158
|
+
// 3. generic-approval-fallback (score: ~20%, priority: 15) ⚠️ Fallback
|
|
159
|
+
// 4. generic-transaction-universal (score: ~18%, priority: 10) ⚠️ Universal fallback
|
|
160
|
+
|
|
161
|
+
// Winner: lsp7-transfer-approval-only (context-specific Lit component)
|
|
162
|
+
// Works in Vue: <lsp7-transfer-approval :transaction="tx" @approve="handle" />
|
|
163
|
+
// Works in React: <lsp7-transfer-approval ref={el => el.transaction = tx} />
|
|
164
|
+
// Works in Angular: <lsp7-transfer-approval [transaction]="tx" (approve)="handle($event)" />
|
|
165
|
+
`,
|
|
166
|
+
|
|
167
|
+
// Example 1: Request WITH context (React Native)
|
|
168
|
+
withApprovalContextMobile: `
|
|
169
|
+
// Request: LSP7 transfer in approval context (React Native)
|
|
170
|
+
findMatchingViews(lsp7Transaction, views, {
|
|
171
|
+
framework: rn,
|
|
172
|
+
context: 'approval'
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
// Results: Same scoring, different components
|
|
176
|
+
// Winner: LSP7TransferApproval React Native component
|
|
177
|
+
<LSP7TransferApproval
|
|
178
|
+
transaction={transaction}
|
|
179
|
+
onApprove={handleApprove}
|
|
180
|
+
style={styles.approvalView}
|
|
181
|
+
/>
|
|
182
|
+
`,
|
|
183
|
+
|
|
184
|
+
withFeedContext: `
|
|
185
|
+
// Request: LSP7 transfer in feed context
|
|
186
|
+
findMatchingViews(lsp7Transaction, views, {
|
|
187
|
+
framework: 'lit', // or rn
|
|
188
|
+
context: 'feed'
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// Results:
|
|
192
|
+
// 1. lsp7-transfer-compact (score: ~95%, priority: 110) ✅ Perfect match (feed is in context array)
|
|
193
|
+
// 2. lsp7-transfer-universal (score: ~70%, priority: 80) ⚠️ Universal (slight penalty)
|
|
194
|
+
// 3. generic-transaction-universal (score: ~18%, priority: 10) ⚠️ Universal fallback
|
|
195
|
+
|
|
196
|
+
// Note: lsp7-transfer-approval-only gets score ~9.5% (heavily penalized - wrong context)
|
|
197
|
+
// Winner: lsp7-transfer-compact (multi-context view)
|
|
198
|
+
`,
|
|
199
|
+
|
|
200
|
+
// Example 2: Request WITHOUT context
|
|
201
|
+
withoutContext: `
|
|
202
|
+
// Request: LSP7 transfer with no context specified
|
|
203
|
+
findMatchingViews(lsp7Transaction, views, {
|
|
204
|
+
framework: 'lit' // or rn
|
|
205
|
+
// No context specified
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// Results:
|
|
209
|
+
// 1. lsp7-transfer-universal (score: 75%, priority: 80) ✅ Perfect - universal view
|
|
210
|
+
// 2. generic-transaction-universal (score: 20%, priority: 10) ⚠️ Universal fallback
|
|
211
|
+
|
|
212
|
+
// Context-specific views get heavily penalized (~10% of normal score):
|
|
213
|
+
// - lsp7-transfer-approval-only (score: ~9.5%) ❌ Requires context
|
|
214
|
+
// - lsp7-transfer-compact (score: ~9.5%) ❌ Requires context
|
|
215
|
+
|
|
216
|
+
// Winner: lsp7-transfer-universal (designed to work anywhere)
|
|
217
|
+
`,
|
|
218
|
+
|
|
219
|
+
unknownTransaction: `
|
|
220
|
+
// Request: Unknown transaction type in approval context
|
|
221
|
+
findMatchingViews(unknownTransaction, views, {
|
|
222
|
+
framework: 'lit', // or rn
|
|
223
|
+
context: 'approval'
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
// Results:
|
|
227
|
+
// 1. generic-approval-fallback (score: ~20%, priority: 15) ✅ Context-aware fallback
|
|
228
|
+
// 2. generic-transaction-universal (score: ~18%, priority: 10) ⚠️ Universal fallback
|
|
229
|
+
|
|
230
|
+
// Winner: generic-approval-fallback (better for approval context)
|
|
231
|
+
`,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Migration strategy for existing views using our optimized approach
|
|
236
|
+
*/
|
|
237
|
+
export const MigrationStrategy = `
|
|
238
|
+
/**
|
|
239
|
+
* MIGRATION STRATEGY: Gradual Context Adoption with Suffering Reduction
|
|
240
|
+
*
|
|
241
|
+
* Phase 1: Convert to Lit + React Native (Suffering Reduction)
|
|
242
|
+
* - Convert existing Vue/React/Angular views to Lit web components
|
|
243
|
+
* - Convert existing mobile views to React Native
|
|
244
|
+
* - Immediate 50% reduction in maintenance overhead
|
|
245
|
+
* - All existing views continue to work unchanged (universal contexts)
|
|
246
|
+
*
|
|
247
|
+
* Phase 2: Add context-specific views gradually
|
|
248
|
+
* - Add approval-specific views for security-critical transactions
|
|
249
|
+
* - Add compact views for feeds/lists
|
|
250
|
+
* - Context-specific views get higher priority when context matches
|
|
251
|
+
* - Universal views remain as fallbacks
|
|
252
|
+
*
|
|
253
|
+
* Phase 3: Optimize and celebrate
|
|
254
|
+
* - Monitor usage patterns and optimize popular views
|
|
255
|
+
* - Remove unused universal views if fully replaced by context-specific ones
|
|
256
|
+
* - Enjoy the mathematical superiority of 2x less suffering
|
|
257
|
+
*
|
|
258
|
+
* Benefits:
|
|
259
|
+
* - Zero breaking changes during migration
|
|
260
|
+
* - Gradual adoption with immediate suffering reduction
|
|
261
|
+
* - Better UX where it matters most (approval flows)
|
|
262
|
+
* - Universal web compatibility automatically achieved
|
|
263
|
+
* - Native mobile performance from day one
|
|
264
|
+
*
|
|
265
|
+
* Result: Developer suffering reduced by 50%, user experience improved by ∞%
|
|
266
|
+
*/
|
|
267
|
+
`
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Web framework integration examples with Lit components
|
|
271
|
+
*/
|
|
272
|
+
export const WebFrameworkIntegration = {
|
|
273
|
+
vue: `
|
|
274
|
+
<!-- Vue: Lit web components work seamlessly -->
|
|
275
|
+
<template>
|
|
276
|
+
<div class="transaction-container">
|
|
277
|
+
<lsp7-transfer-approval
|
|
278
|
+
:transaction="transaction"
|
|
279
|
+
:show-actions="true"
|
|
280
|
+
@approve="handleApprove"
|
|
281
|
+
@reject="handleReject"
|
|
282
|
+
/>
|
|
283
|
+
</div>
|
|
284
|
+
</template>
|
|
285
|
+
|
|
286
|
+
<script setup>
|
|
287
|
+
import '@lukso/decoder-web-components'
|
|
288
|
+
// Vue developers barely notice it's a web component!
|
|
289
|
+
</script>`,
|
|
290
|
+
|
|
291
|
+
react: `
|
|
292
|
+
// React: Use Lit components with refs
|
|
293
|
+
import { useRef, useEffect } from 'react'
|
|
294
|
+
import '@lukso/decoder-web-components'
|
|
295
|
+
|
|
296
|
+
function TransactionApproval({ transaction, onApprove }) {
|
|
297
|
+
const elementRef = useRef(null)
|
|
298
|
+
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
const element = elementRef.current
|
|
301
|
+
if (!element) return
|
|
302
|
+
|
|
303
|
+
element.transaction = transaction
|
|
304
|
+
element.addEventListener('approve', (e) => onApprove(e.detail))
|
|
305
|
+
|
|
306
|
+
return () => {
|
|
307
|
+
element.removeEventListener('approve', onApprove)
|
|
308
|
+
}
|
|
309
|
+
}, [transaction, onApprove])
|
|
310
|
+
|
|
311
|
+
return <lsp7-transfer-approval ref={elementRef} />
|
|
312
|
+
}`,
|
|
313
|
+
|
|
314
|
+
angular: `
|
|
315
|
+
// Angular: Web components work with CUSTOM_ELEMENTS_SCHEMA
|
|
316
|
+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
|
|
317
|
+
import '@lukso/decoder-web-components'
|
|
318
|
+
|
|
319
|
+
@Component({
|
|
320
|
+
template: \`
|
|
321
|
+
<lsp7-transfer-approval
|
|
322
|
+
[transaction]="transaction"
|
|
323
|
+
[showActions]="true"
|
|
324
|
+
(approve)="handleApprove($event)"
|
|
325
|
+
></lsp7-transfer-approval>
|
|
326
|
+
\`,
|
|
327
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
328
|
+
})
|
|
329
|
+
export class TransactionComponent {
|
|
330
|
+
// Angular treats web components as first-class citizens
|
|
331
|
+
}`,
|
|
332
|
+
|
|
333
|
+
svelte: `
|
|
334
|
+
<!-- Svelte: Excellent web component support -->
|
|
335
|
+
<script>
|
|
336
|
+
import '@lukso/decoder-web-components'
|
|
337
|
+
|
|
338
|
+
export let transaction
|
|
339
|
+
|
|
340
|
+
function handleApprove(event) {
|
|
341
|
+
console.log('Approved:', event.detail)
|
|
342
|
+
}
|
|
343
|
+
</script>
|
|
344
|
+
|
|
345
|
+
<lsp7-transfer-approval
|
|
346
|
+
{transaction}
|
|
347
|
+
showActions={true}
|
|
348
|
+
on:approve={handleApprove}
|
|
349
|
+
/>`,
|
|
350
|
+
|
|
351
|
+
reactNative: `
|
|
352
|
+
// React Native: Native components for optimal mobile performance
|
|
353
|
+
import { LSP7TransferApproval } from '@lukso/decoder-rn-views'
|
|
354
|
+
import { StyleSheet } from rn
|
|
355
|
+
|
|
356
|
+
function TransactionScreen({ transaction }) {
|
|
357
|
+
return (
|
|
358
|
+
<LSP7TransferApproval
|
|
359
|
+
transaction={transaction}
|
|
360
|
+
onApprove={handleApprove}
|
|
361
|
+
style={styles.transaction}
|
|
362
|
+
/>
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const styles = StyleSheet.create({
|
|
367
|
+
transaction: {
|
|
368
|
+
padding: 16,
|
|
369
|
+
marginVertical: 8
|
|
370
|
+
}
|
|
371
|
+
})`,
|
|
372
|
+
}
|