@linktr.ee/linkapp 0.0.18 → 0.0.19
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-runtime.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/setup-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup-runtime.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/setup-runtime.ts"],"names":[],"mappings":"AA+KA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAyBtD"}
|
|
@@ -5,7 +5,7 @@ import { detectLayouts } from "../build/detect-layouts.js";
|
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
/**
|
|
8
|
-
* Generates main.tsx content with detected layouts
|
|
8
|
+
* Generates main.tsx content with detected layouts and parent-iframe communication
|
|
9
9
|
*/
|
|
10
10
|
function generateMainTsx(projectPath) {
|
|
11
11
|
const detection = detectLayouts(projectPath);
|
|
@@ -26,10 +26,10 @@ function generateMainTsx(projectPath) {
|
|
|
26
26
|
// Generate the wrapper logic - use Layout if it exists, otherwise render directly
|
|
27
27
|
const renderLogic = hasLayout
|
|
28
28
|
? ` <Layout>
|
|
29
|
-
<LayoutComponent {...
|
|
29
|
+
<LayoutComponent {...data} />
|
|
30
30
|
</Layout>`
|
|
31
|
-
: ` <LayoutComponent {...
|
|
32
|
-
return `import { StrictMode } from 'react'
|
|
31
|
+
: ` <LayoutComponent {...data} />`;
|
|
32
|
+
return `import { StrictMode, useEffect } from 'react'
|
|
33
33
|
import { createRoot } from 'react-dom/client'
|
|
34
34
|
${layoutImport}
|
|
35
35
|
${imports}
|
|
@@ -40,12 +40,52 @@ const layouts: Record<string, React.ComponentType<any>> = {
|
|
|
40
40
|
${layoutsObj}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// Type for extension data from parent iframe
|
|
44
|
+
type ExtensionData = {
|
|
45
|
+
__linkUrl?: string
|
|
46
|
+
__thumbnail?: string
|
|
47
|
+
__linkParams?: any
|
|
48
|
+
__environment?: any
|
|
49
|
+
displayType?: string
|
|
50
|
+
[key: string]: any
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const rootElement = document.getElementById('root')
|
|
54
|
+
if (!rootElement) {
|
|
55
|
+
throw new Error('Root element not found')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Detect if we're running inside an iframe (production on Linktree)
|
|
59
|
+
const isInIframe = window.parent !== window
|
|
60
|
+
|
|
61
|
+
// Mock context for development mode
|
|
62
|
+
const mockContext: ExtensionData = {
|
|
63
|
+
linkUrl: 'https://example.com/demo',
|
|
64
|
+
showTitle: true,
|
|
65
|
+
theme: {
|
|
66
|
+
cssVariables: {
|
|
67
|
+
'--button-style-text': '#000000',
|
|
68
|
+
'--button-style-background': '#ffffff',
|
|
69
|
+
'--button-style-inner-radius': '12px',
|
|
70
|
+
'--button-style-border-color': '#e5e7eb',
|
|
71
|
+
'--button-style-background-hover': '#f3f4f6',
|
|
72
|
+
'--button-style-contrast-color': '#ffffff',
|
|
73
|
+
'--profileBackground': '#ffffff',
|
|
74
|
+
},
|
|
75
|
+
textColor: '#000000',
|
|
76
|
+
backgroundColor: '#ffffff',
|
|
77
|
+
borderRadius: '12px',
|
|
78
|
+
borderColor: '#e5e7eb',
|
|
79
|
+
backgroundHover: '#f3f4f6',
|
|
80
|
+
contrastColor: '#ffffff',
|
|
81
|
+
textHoverColor: '#111827',
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function App({ data }: { data: ExtensionData }) {
|
|
86
|
+
// Get layout from query parameter or default to classic
|
|
45
87
|
const params = new URLSearchParams(window.location.search)
|
|
46
88
|
const layoutName = params.get('layout') || 'classic'
|
|
47
|
-
|
|
48
|
-
// Get the layout component
|
|
49
89
|
const LayoutComponent = layouts[layoutName] || layouts.classic
|
|
50
90
|
|
|
51
91
|
if (!LayoutComponent) {
|
|
@@ -58,45 +98,68 @@ function App() {
|
|
|
58
98
|
)
|
|
59
99
|
}
|
|
60
100
|
|
|
61
|
-
// Mock context for development
|
|
62
|
-
const mockContext = {
|
|
63
|
-
linkUrl: 'https://example.com/demo',
|
|
64
|
-
showTitle: true,
|
|
65
|
-
theme: {
|
|
66
|
-
cssVariables: {
|
|
67
|
-
'--button-style-text': '#000000',
|
|
68
|
-
'--button-style-background': '#ffffff',
|
|
69
|
-
'--button-style-inner-radius': '12px',
|
|
70
|
-
'--button-style-border-color': '#e5e7eb',
|
|
71
|
-
'--button-style-background-hover': '#f3f4f6',
|
|
72
|
-
'--button-style-contrast-color': '#ffffff',
|
|
73
|
-
'--profileBackground': '#ffffff',
|
|
74
|
-
},
|
|
75
|
-
textColor: '#000000',
|
|
76
|
-
backgroundColor: '#ffffff',
|
|
77
|
-
borderRadius: '12px',
|
|
78
|
-
borderColor: '#e5e7eb',
|
|
79
|
-
backgroundHover: '#f3f4f6',
|
|
80
|
-
contrastColor: '#ffffff',
|
|
81
|
-
textHoverColor: '#111827',
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
|
|
85
101
|
return (
|
|
86
102
|
${renderLogic}
|
|
87
103
|
)
|
|
88
104
|
}
|
|
89
105
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
const postExtensionReadyMessage = () => {
|
|
107
|
+
const height = rootElement.clientHeight
|
|
108
|
+
const message = {
|
|
109
|
+
type: 'extension-ready',
|
|
110
|
+
data: {
|
|
111
|
+
ready: true,
|
|
112
|
+
height: height,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
console.log('[LinkApp] Posting extension-ready message with height:', height)
|
|
116
|
+
window.parent.postMessage(message, '*')
|
|
93
117
|
}
|
|
94
118
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
const renderApp = (data: ExtensionData) => {
|
|
120
|
+
const root = createRoot(rootElement)
|
|
121
|
+
root.render(
|
|
122
|
+
<StrictMode>
|
|
123
|
+
<App data={data} />
|
|
124
|
+
</StrictMode>
|
|
125
|
+
)
|
|
126
|
+
postExtensionReadyMessage()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Setup parent-iframe communication for production mode
|
|
130
|
+
if (isInIframe) {
|
|
131
|
+
// Listen for extension-data from parent ExtensionEmbed component
|
|
132
|
+
window.addEventListener('message', function handler(event) {
|
|
133
|
+
// Security: validate origin (allow Linktree domains and localhost for testing)
|
|
134
|
+
const allowedOrigins = /^https:\\/\\/(qa\\.)?linktr\\.ee$|^https:\\/\\/linktree\\.local$|^https?:\\/\\/localhost(:\\d+)?$/
|
|
135
|
+
if (!allowedOrigins.test(event.origin)) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (event.data?.type !== 'extension-data') {
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Render app with data from parent
|
|
144
|
+
renderApp(event.data.data ?? {})
|
|
145
|
+
window.removeEventListener('message', handler)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
// Send extension-loaded message to parent
|
|
149
|
+
window.parent.postMessage({ type: 'extension-loaded' }, '*')
|
|
150
|
+
|
|
151
|
+
// Forward interaction events to parent for analytics
|
|
152
|
+
document.addEventListener('interaction-event', (event: Event) => {
|
|
153
|
+
const customEvent = event as CustomEvent<Record<string, unknown>>
|
|
154
|
+
window.parent.postMessage(
|
|
155
|
+
{ type: 'interaction-event', data: customEvent.detail },
|
|
156
|
+
'*'
|
|
157
|
+
)
|
|
158
|
+
})
|
|
159
|
+
} else {
|
|
160
|
+
// Development mode: render immediately with mock data
|
|
161
|
+
renderApp(mockContext)
|
|
162
|
+
}
|
|
100
163
|
`;
|
|
101
164
|
}
|
|
102
165
|
/**
|
|
@@ -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