@piedata/pieui 1.1.2 → 1.1.4
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/dist/cli.js +124 -59
- package/dist/components/Buttons/AjaxButtonCard/ui/AjaxButtonCard.d.ts.map +1 -1
- package/dist/components/Chats/ChatCard/ui/ChatCard.d.ts.map +1 -1
- package/dist/components/PieRoot/index.d.ts.map +1 -1
- package/dist/components/index.esm.js +13 -13
- package/dist/components/index.js +20 -20
- package/dist/index.esm.js +15 -15
- package/dist/index.js +23 -23
- package/dist/util/ajaxCommonUtils.d.ts +7 -1
- package/dist/util/ajaxCommonUtils.d.ts.map +1 -1
- package/package.json +2 -5
- package/src/components/Buttons/AjaxButtonCard/index.ts +0 -1
- package/src/components/Buttons/AjaxButtonCard/types/index.ts +0 -17
- package/src/components/Buttons/AjaxButtonCard/ui/AjaxButtonCard.tsx +0 -38
- package/src/components/Chats/ChatCard/index.ts +0 -1
- package/src/components/Chats/ChatCard/types/annyang.d.ts +0 -11
- package/src/components/Chats/ChatCard/types/index.ts +0 -59
- package/src/components/Chats/ChatCard/ui/ChatCard.tsx +0 -130
- package/src/components/Chats/ChatCard/ui/components/AttachFileButton.tsx +0 -49
- package/src/components/Chats/ChatCard/ui/components/AttachedFileView.tsx +0 -29
- package/src/components/Chats/ChatCard/ui/components/ChatCardInput.tsx +0 -177
- package/src/components/Chats/ChatCard/ui/components/ChatOption.tsx +0 -25
- package/src/components/Chats/ChatCard/ui/components/Markdown.tsx +0 -21
- package/src/components/Chats/ChatCard/ui/components/MessageAvatar.tsx +0 -17
- package/src/components/Chats/ChatCard/ui/components/MessageCard.tsx +0 -80
- package/src/components/Chats/ChatCard/ui/components/MessageContent.tsx +0 -27
- package/src/components/Chats/ChatCard/ui/components/MessagesBoard.tsx +0 -61
- package/src/components/Chats/ChatCard/ui/components/Options.tsx +0 -20
- package/src/components/Chats/ChatCard/ui/components/ResizableTextarea.tsx +0 -59
- package/src/components/Chats/ChatCard/ui/components/SendButton.tsx +0 -37
- package/src/components/Chats/ChatCard/ui/components/VoiceListeningButton.tsx +0 -35
- package/src/components/Chats/ChatCard/ui/components/icons/AttachFileIcon.tsx +0 -18
- package/src/components/Chats/ChatCard/ui/components/icons/AttachedFileIcon.tsx +0 -18
- package/src/components/Chats/ChatCard/ui/components/icons/CancelFileIcon.tsx +0 -14
- package/src/components/Chats/ChatCard/ui/components/icons/DefaultAvatar.tsx +0 -10
- package/src/components/Chats/ChatCard/ui/components/icons/SendIcon.tsx +0 -18
- package/src/components/Chats/ChatCard/ui/components/icons/VoiceRecordIcon.tsx +0 -15
- package/src/components/Containers/AjaxGroupCard/index.ts +0 -1
- package/src/components/Containers/AjaxGroupCard/types/index.ts +0 -17
- package/src/components/Containers/AjaxGroupCard/ui/AjaxGroupCard.tsx +0 -96
- package/src/components/Containers/SequenceCard/index.ts +0 -1
- package/src/components/Containers/SequenceCard/types/index.ts +0 -10
- package/src/components/Containers/SequenceCard/ui/SequenceCard.tsx +0 -32
- package/src/components/Containers/UnionCard/index.ts +0 -1
- package/src/components/Containers/UnionCard/types/index.ts +0 -8
- package/src/components/Containers/UnionCard/ui/UnionCard.tsx +0 -27
- package/src/components/PieCard/index.tsx +0 -149
- package/src/components/PieCard/types/index.ts +0 -18
- package/src/components/PieRoot/index.tsx +0 -154
- package/src/components/PieRoot/types/index.ts +0 -14
- package/src/components/PieTelegramRoot/index.tsx +0 -161
- package/src/components/UI/index.tsx +0 -70
- package/src/components/index.ts +0 -6
- package/src/index.ts +0 -15
- package/src/providers/CentrifugeIOInitProvider.tsx +0 -42
- package/src/providers/SocketIOInitProvider.tsx +0 -52
- package/src/types/index.ts +0 -139
- package/src/util/ajaxCommonUtils.ts +0 -137
- package/src/util/centrifuge.ts +0 -33
- package/src/util/fallback.tsx +0 -6
- package/src/util/initializeComponents.ts +0 -84
- package/src/util/lazy.ts +0 -25
- package/src/util/mitt.ts +0 -11
- package/src/util/pieConfig.ts +0 -43
- package/src/util/registry.ts +0 -81
- package/src/util/socket.ts +0 -24
- package/src/util/sx2radium.ts +0 -15
- package/src/util/tailwindCommonUtils.ts +0 -6
- package/src/util/useIsSupported.ts +0 -17
- package/src/util/useOpenAIWebRTC.ts +0 -176
- package/src/util/useWebApp.ts +0 -32
- package/src/util/waitForSidAvailable.ts +0 -21
- package/src/util/webrtcClient.ts +0 -247
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from 'react';
|
|
2
|
-
import { isRenderingLogEnabled } from '../../util/pieConfig';
|
|
3
|
-
import CentrifugeIOContext from '../../util/centrifuge';
|
|
4
|
-
import SocketIOContext from '../../util/socket';
|
|
5
|
-
import MittContext from '../../util/mitt';
|
|
6
|
-
import {PieCardProps} from './types';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const PieCard = ({
|
|
10
|
-
card,
|
|
11
|
-
data,
|
|
12
|
-
children,
|
|
13
|
-
useSocketioSupport = false,
|
|
14
|
-
useCentrifugeSupport = false,
|
|
15
|
-
useMittSupport = false,
|
|
16
|
-
centrifugeChannel = undefined,
|
|
17
|
-
methods = undefined,
|
|
18
|
-
}: PieCardProps) => {
|
|
19
|
-
const renderingLogEnabled = isRenderingLogEnabled()
|
|
20
|
-
// const name = data.name;
|
|
21
|
-
if (renderingLogEnabled) {
|
|
22
|
-
console.log('[PieCard] Rendering card:', card)
|
|
23
|
-
console.log('[PieCard] Card data:', data)
|
|
24
|
-
console.log('[PieCard] Component name:', data?.name)
|
|
25
|
-
console.log('[PieCard] Real-time support:', {
|
|
26
|
-
socketio: useSocketioSupport,
|
|
27
|
-
centrifuge: useCentrifugeSupport,
|
|
28
|
-
mitt: useMittSupport,
|
|
29
|
-
centrifugeChannel
|
|
30
|
-
})
|
|
31
|
-
console.log('[PieCard] Methods:', methods ? Object.keys(methods) : 'none')
|
|
32
|
-
console.log('[PieCard] Has children:', !!children)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const socket = useContext(SocketIOContext)
|
|
36
|
-
const centrifuge = useContext(CentrifugeIOContext)
|
|
37
|
-
const mitt = useContext(MittContext)
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!socket || !useSocketioSupport || !methods || !data.name) {
|
|
41
|
-
if (renderingLogEnabled && useSocketioSupport) {
|
|
42
|
-
console.log('[PieCard] Socket.IO setup skipped:', {
|
|
43
|
-
hasSocket: !!socket,
|
|
44
|
-
useSocketioSupport,
|
|
45
|
-
hasMethods: !!methods,
|
|
46
|
-
hasDataName: !!data?.name
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
Object.entries(methods).forEach(([methodName, methodHandler]) => {
|
|
52
|
-
const eventName = `pie${methodName}_${data.name}`
|
|
53
|
-
if (renderingLogEnabled) {
|
|
54
|
-
console.log(`[PieCard] Socket.IO registering event: ${eventName}`)
|
|
55
|
-
}
|
|
56
|
-
socket.on(eventName, methodHandler)
|
|
57
|
-
})
|
|
58
|
-
return () => {
|
|
59
|
-
Object.entries(methods).forEach(([methodName, methodHandler]) => {
|
|
60
|
-
const eventName = `pie${methodName}_${data.name}`
|
|
61
|
-
if (renderingLogEnabled) {
|
|
62
|
-
console.log(`[PieCard] Socket.IO unregistering event: ${eventName}`)
|
|
63
|
-
}
|
|
64
|
-
socket.off(eventName, methodHandler)
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}, [socket, methods, data.name])
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (!centrifuge || !useCentrifugeSupport || !centrifugeChannel || !methods || !data.name) {
|
|
71
|
-
if (renderingLogEnabled && useCentrifugeSupport) {
|
|
72
|
-
console.log('[PieCard] Centrifuge setup skipped:', {
|
|
73
|
-
hasCentrifuge: !!centrifuge,
|
|
74
|
-
useCentrifugeSupport,
|
|
75
|
-
hasCentrifugeChannel: !!centrifugeChannel,
|
|
76
|
-
hasMethods: !!methods,
|
|
77
|
-
hasDataName: !!data?.name
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const subscriptions = Object.entries(methods).map(([methodName, methodHandler]) => {
|
|
84
|
-
const channelName = `pie${methodName}_${data.name}_${centrifugeChannel}`
|
|
85
|
-
if (renderingLogEnabled) {
|
|
86
|
-
console.log(`[PieCard] Centrifuge subscribing to channel: ${channelName}`)
|
|
87
|
-
}
|
|
88
|
-
const subscription = centrifuge.newSubscription(channelName)
|
|
89
|
-
subscription.on('publication', (ctx) => {
|
|
90
|
-
if (renderingLogEnabled) {
|
|
91
|
-
console.log(`[PieCard] Centrifuge received data on ${channelName}:`, ctx.data)
|
|
92
|
-
}
|
|
93
|
-
methodHandler(ctx.data)
|
|
94
|
-
})
|
|
95
|
-
subscription.subscribe()
|
|
96
|
-
return subscription
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
return () => {
|
|
100
|
-
subscriptions.forEach((subscription) => {
|
|
101
|
-
if (renderingLogEnabled) {
|
|
102
|
-
console.log(`[PieCard] Centrifuge unsubscribing from channel`)
|
|
103
|
-
}
|
|
104
|
-
subscription.unsubscribe()
|
|
105
|
-
centrifuge.removeSubscription(subscription)
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
}, [centrifuge, centrifugeChannel, methods, data.name])
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (!mitt || !useMittSupport || !methods || !data.name) {
|
|
112
|
-
if (renderingLogEnabled && useMittSupport) {
|
|
113
|
-
console.log('[PieCard] Mitt setup skipped:', {
|
|
114
|
-
hasMitt: !!mitt,
|
|
115
|
-
useMittSupport,
|
|
116
|
-
hasMethods: !!methods,
|
|
117
|
-
hasDataName: !!data?.name
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
Object.entries(methods).forEach(([methodName, methodHandler]) => {
|
|
124
|
-
const eventName = `pie${methodName}_${data.name}`
|
|
125
|
-
if (renderingLogEnabled) {
|
|
126
|
-
console.log(`[PieCard] Mitt registering event: ${eventName}`)
|
|
127
|
-
}
|
|
128
|
-
mitt.on(eventName, methodHandler)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
return () => {
|
|
132
|
-
Object.entries(methods).forEach(([methodName, methodHandler]) => {
|
|
133
|
-
const eventName = `pie${methodName}_${data.name}`
|
|
134
|
-
if (renderingLogEnabled) {
|
|
135
|
-
console.log(`[PieCard] Mitt unregistering event: ${eventName}`)
|
|
136
|
-
}
|
|
137
|
-
mitt.off(eventName, methodHandler)
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
}, [mitt, methods, data.name])
|
|
141
|
-
|
|
142
|
-
if (renderingLogEnabled) {
|
|
143
|
-
console.log('[PieCard] Rendering complete, returning children')
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return children
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default PieCard
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {ReactNode} from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export interface PieCardData {
|
|
5
|
-
name: string
|
|
6
|
-
[key: string]: any
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface PieCardProps {
|
|
10
|
-
card: string
|
|
11
|
-
data: PieCardData
|
|
12
|
-
children: ReactNode
|
|
13
|
-
useSocketioSupport?: boolean
|
|
14
|
-
useCentrifugeSupport?: boolean
|
|
15
|
-
useMittSupport?: boolean
|
|
16
|
-
centrifugeChannel?: string
|
|
17
|
-
methods?: Record<string, (data: any) => void>
|
|
18
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {useEffect, useMemo} from 'react'
|
|
2
|
-
import {QueryClient, QueryClientProvider, useQuery} from '@tanstack/react-query'
|
|
3
|
-
|
|
4
|
-
import Radium from "radium";
|
|
5
|
-
import {PieRootProps} from './types'
|
|
6
|
-
|
|
7
|
-
import MittContext, {emitter} from "../../util/mitt"
|
|
8
|
-
import SocketIOContext, {getSocket} from "../../util/socket"
|
|
9
|
-
import CentrifugeIOContext, { getCentrifuge } from "../../util/centrifuge"
|
|
10
|
-
|
|
11
|
-
import SocketIOInitProvider from "../../providers/SocketIOInitProvider"
|
|
12
|
-
import CentrifugeIOInitProvider from "../../providers/CentrifugeIOInitProvider"
|
|
13
|
-
import FallbackContext from "../../util/fallback";
|
|
14
|
-
import {UIConfigType} from "../../types";
|
|
15
|
-
import {AxiosError} from "axios";
|
|
16
|
-
import UI from "../UI";
|
|
17
|
-
import { createAxiosDateTransformer } from "axios-date-transformer";
|
|
18
|
-
import {initializePieComponents, isPieComponentsInitialized} from "../../util/initializeComponents.ts";
|
|
19
|
-
import {
|
|
20
|
-
getApiServer,
|
|
21
|
-
isRenderingLogEnabled,
|
|
22
|
-
getCentrifugeServer,
|
|
23
|
-
PieConfigContext
|
|
24
|
-
} from "../../util/pieConfig";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const PieRootContent = ({ location, fallback, onError, initializePie }: PieRootProps) => {
|
|
28
|
-
const apiServer = getApiServer()
|
|
29
|
-
const centrifugeServer = getCentrifugeServer()
|
|
30
|
-
const renderingLogEnabled = isRenderingLogEnabled()
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (isPieComponentsInitialized()) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
initializePieComponents()
|
|
37
|
-
initializePie()
|
|
38
|
-
}, [])
|
|
39
|
-
|
|
40
|
-
const axiosInstance = useMemo(() => createAxiosDateTransformer({
|
|
41
|
-
baseURL: apiServer,
|
|
42
|
-
}), [])
|
|
43
|
-
|
|
44
|
-
if (renderingLogEnabled) {
|
|
45
|
-
console.log('[PieRoot] Rendering with location:', location)
|
|
46
|
-
console.log('[PieRoot] API_SERVER:', apiServer)
|
|
47
|
-
console.log('[PieRoot] Fallback provided:', !!fallback)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!apiServer) {
|
|
51
|
-
throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER")
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// if (!isPieComponentsInitialized()) {
|
|
55
|
-
// throw Error("Pie components are not initialized. Use initializePieComponents() at the top of page file")
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
const {
|
|
59
|
-
data: uiConfiguration,
|
|
60
|
-
isLoading,
|
|
61
|
-
error,
|
|
62
|
-
} = useQuery<UIConfigType, AxiosError>({
|
|
63
|
-
queryKey: ['uiConfig', location.pathname + location.search, isPieComponentsInitialized()],
|
|
64
|
-
queryFn: async () => {
|
|
65
|
-
if (!isPieComponentsInitialized()) {
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
const apiEndpoint = '/api/content' + location.pathname + location.search
|
|
69
|
-
if (renderingLogEnabled) {
|
|
70
|
-
console.log('[PieRoot] Fetching UI configuration from:', apiEndpoint)
|
|
71
|
-
}
|
|
72
|
-
const response = await axiosInstance.get(apiEndpoint, {
|
|
73
|
-
headers: {
|
|
74
|
-
'Access-Control-Allow-Origin': '*',
|
|
75
|
-
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
|
|
76
|
-
'Content-type': 'application/json',
|
|
77
|
-
},
|
|
78
|
-
withCredentials: true,
|
|
79
|
-
})
|
|
80
|
-
if (renderingLogEnabled) {
|
|
81
|
-
console.log('[PieRoot] Received UI configuration:', response.data)
|
|
82
|
-
}
|
|
83
|
-
return response.data
|
|
84
|
-
},
|
|
85
|
-
staleTime: Infinity,
|
|
86
|
-
gcTime: Infinity,
|
|
87
|
-
refetchOnWindowFocus: false,
|
|
88
|
-
refetchOnMount: false,
|
|
89
|
-
refetchOnReconnect: false,
|
|
90
|
-
retry: true,
|
|
91
|
-
retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30000),
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
if (error) {
|
|
95
|
-
if (renderingLogEnabled) {
|
|
96
|
-
console.error('[PieRoot] Error fetching UI configuration:', error)
|
|
97
|
-
console.error('[PieRoot] Error details:', {
|
|
98
|
-
message: error.message,
|
|
99
|
-
status: error.response?.status,
|
|
100
|
-
data: error.response?.data
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
onError?.()
|
|
104
|
-
return fallback
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (isLoading || !uiConfiguration) {
|
|
109
|
-
if (renderingLogEnabled) {
|
|
110
|
-
console.log('[PieRoot] Loading state:', { isLoading, hasUiConfiguration: !!uiConfiguration })
|
|
111
|
-
}
|
|
112
|
-
return fallback
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (renderingLogEnabled) {
|
|
116
|
-
console.log('[PieRoot] UI configuration loaded successfully:', uiConfiguration)
|
|
117
|
-
console.log('[PieRoot] Rendering UI with configuration')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<MittContext.Provider value={emitter}>
|
|
122
|
-
<SocketIOContext.Provider value={getSocket(apiServer)}>
|
|
123
|
-
<CentrifugeIOContext.Provider value={getCentrifuge(apiServer, centrifugeServer)}>
|
|
124
|
-
<FallbackContext.Provider value={fallback ?? <></>}>
|
|
125
|
-
<SocketIOInitProvider>
|
|
126
|
-
<CentrifugeIOInitProvider>
|
|
127
|
-
|
|
128
|
-
<Radium.StyleRoot>
|
|
129
|
-
<UI uiConfig={uiConfiguration} />
|
|
130
|
-
</Radium.StyleRoot>
|
|
131
|
-
|
|
132
|
-
</CentrifugeIOInitProvider>
|
|
133
|
-
</SocketIOInitProvider>
|
|
134
|
-
</FallbackContext.Provider>
|
|
135
|
-
</CentrifugeIOContext.Provider>
|
|
136
|
-
</SocketIOContext.Provider>
|
|
137
|
-
</MittContext.Provider>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const PieRoot = (props: PieRootProps) => {
|
|
143
|
-
const queryClient = new QueryClient()
|
|
144
|
-
return (
|
|
145
|
-
<PieConfigContext.Provider value={props.config}>
|
|
146
|
-
<QueryClientProvider client={queryClient}>
|
|
147
|
-
<PieRootContent {...props} />
|
|
148
|
-
</QueryClientProvider>
|
|
149
|
-
</PieConfigContext.Provider>
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export default PieRoot
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import {PieConfig} from "../../../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface PieRootProps {
|
|
6
|
-
location: {
|
|
7
|
-
pathname: string;
|
|
8
|
-
search: string;
|
|
9
|
-
},
|
|
10
|
-
fallback?: ReactNode
|
|
11
|
-
onError?: () => void
|
|
12
|
-
config: PieConfig
|
|
13
|
-
initializePie: () => void
|
|
14
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import React, {useEffect, useMemo} from 'react'
|
|
2
|
-
import {QueryClient, QueryClientProvider, useQuery} from '@tanstack/react-query'
|
|
3
|
-
|
|
4
|
-
import Radium from "radium";
|
|
5
|
-
import {PieRootProps} from '../PieRoot/types'
|
|
6
|
-
|
|
7
|
-
import MittContext, {emitter} from "../../util/mitt"
|
|
8
|
-
import SocketIOContext, {getSocket} from "../../util/socket"
|
|
9
|
-
import CentrifugeIOContext, {getCentrifuge} from "../../util/centrifuge"
|
|
10
|
-
|
|
11
|
-
import SocketIOInitProvider from "../../providers/SocketIOInitProvider"
|
|
12
|
-
import CentrifugeIOInitProvider from "../../providers/CentrifugeIOInitProvider"
|
|
13
|
-
import FallbackContext from "../../util/fallback";
|
|
14
|
-
import {UIConfigType} from "../../types";
|
|
15
|
-
import {AxiosError} from "axios";
|
|
16
|
-
import UI from "../UI";
|
|
17
|
-
import { createAxiosDateTransformer } from "axios-date-transformer";
|
|
18
|
-
import {
|
|
19
|
-
getApiServer,
|
|
20
|
-
isRenderingLogEnabled,
|
|
21
|
-
getCentrifugeServer,
|
|
22
|
-
PieConfigContext
|
|
23
|
-
} from "../../util/pieConfig";
|
|
24
|
-
import {initializePieComponents, isPieComponentsInitialized} from "../../util/initializeComponents.ts";
|
|
25
|
-
import {useWebApp} from "../../util/useWebApp.ts";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const PieTelegramRootContent: React.FC<PieRootProps> = ({ location, fallback, onError, initializePie }) => {
|
|
29
|
-
const apiServer = getApiServer()
|
|
30
|
-
const centrifugeServer = getCentrifugeServer()
|
|
31
|
-
const renderingLogEnabled = isRenderingLogEnabled()
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (isPieComponentsInitialized()) {
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
initializePieComponents()
|
|
38
|
-
initializePie()
|
|
39
|
-
}, [])
|
|
40
|
-
|
|
41
|
-
const axiosInstance = useMemo(() => createAxiosDateTransformer({
|
|
42
|
-
baseURL: apiServer,
|
|
43
|
-
}), [])
|
|
44
|
-
|
|
45
|
-
if (renderingLogEnabled) {
|
|
46
|
-
console.log('[PieRoot] Rendering with location:', location)
|
|
47
|
-
console.log('[PieRoot] API_SERVER:', apiServer)
|
|
48
|
-
console.log('[PieRoot] Fallback provided:', !!fallback)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!apiServer) {
|
|
52
|
-
throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER")
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// if (!isPieComponentsInitialized()) {
|
|
56
|
-
// throw Error("Pie components are not initialized. Use initializePieComponents() at the top of page file")
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
const webApp = useWebApp()
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
data: uiConfiguration,
|
|
63
|
-
isLoading,
|
|
64
|
-
error,
|
|
65
|
-
} = useQuery<UIConfigType, AxiosError>({
|
|
66
|
-
queryKey: ['uiConfig', location.pathname + location.search, webApp?.initData, isPieComponentsInitialized()],
|
|
67
|
-
queryFn: async () => {
|
|
68
|
-
if (!isPieComponentsInitialized()) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
const querySymbol = location.search ? '&' : '?'
|
|
72
|
-
const initData = webApp?.initData
|
|
73
|
-
? `${querySymbol}initData=${encodeURIComponent(webApp.initData)}`
|
|
74
|
-
: ''
|
|
75
|
-
const apiEndpoint = '/api/content' + location.pathname + location.search + initData
|
|
76
|
-
|
|
77
|
-
if (renderingLogEnabled) {
|
|
78
|
-
console.log('[PieRoot] Fetching UI configuration from:', apiEndpoint)
|
|
79
|
-
}
|
|
80
|
-
const response = await axiosInstance.get(apiEndpoint, {
|
|
81
|
-
headers: {
|
|
82
|
-
'Access-Control-Allow-Origin': '*',
|
|
83
|
-
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
|
|
84
|
-
'Content-type': 'application/json',
|
|
85
|
-
},
|
|
86
|
-
withCredentials: true,
|
|
87
|
-
})
|
|
88
|
-
if (renderingLogEnabled) {
|
|
89
|
-
console.log('[PieRoot] Received UI configuration:', response.data)
|
|
90
|
-
}
|
|
91
|
-
return response.data
|
|
92
|
-
},
|
|
93
|
-
staleTime: Infinity,
|
|
94
|
-
gcTime: Infinity,
|
|
95
|
-
refetchOnWindowFocus: false,
|
|
96
|
-
refetchOnMount: false,
|
|
97
|
-
refetchOnReconnect: false,
|
|
98
|
-
retry: true,
|
|
99
|
-
retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30000),
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
if (error && renderingLogEnabled) {
|
|
103
|
-
console.error('[PieRoot] Error fetching UI configuration:', error)
|
|
104
|
-
console.error('[PieRoot] Error details:', {
|
|
105
|
-
message: error.message,
|
|
106
|
-
status: error.response?.status,
|
|
107
|
-
data: error.response?.data
|
|
108
|
-
})
|
|
109
|
-
onError?.()
|
|
110
|
-
return fallback
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (isLoading || !uiConfiguration) {
|
|
115
|
-
if (renderingLogEnabled) {
|
|
116
|
-
console.log('[PieRoot] Loading state:', { isLoading, hasUiConfiguration: !!uiConfiguration })
|
|
117
|
-
}
|
|
118
|
-
return fallback
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (renderingLogEnabled) {
|
|
122
|
-
console.log('[PieRoot] UI configuration loaded successfully:', uiConfiguration)
|
|
123
|
-
console.log('[PieRoot] Rendering UI with configuration')
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return (
|
|
127
|
-
<MittContext.Provider value={emitter}>
|
|
128
|
-
<SocketIOContext.Provider value={getSocket(apiServer)}>
|
|
129
|
-
<CentrifugeIOContext.Provider value={getCentrifuge(apiServer, centrifugeServer)}>
|
|
130
|
-
<FallbackContext.Provider value={fallback ?? <></>}>
|
|
131
|
-
<SocketIOInitProvider>
|
|
132
|
-
<CentrifugeIOInitProvider>
|
|
133
|
-
|
|
134
|
-
<Radium.StyleRoot>
|
|
135
|
-
<UI uiConfig={uiConfiguration} />
|
|
136
|
-
</Radium.StyleRoot>
|
|
137
|
-
|
|
138
|
-
</CentrifugeIOInitProvider>
|
|
139
|
-
</SocketIOInitProvider>
|
|
140
|
-
</FallbackContext.Provider>
|
|
141
|
-
</CentrifugeIOContext.Provider>
|
|
142
|
-
</SocketIOContext.Provider>
|
|
143
|
-
</MittContext.Provider>
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const PieTelegramRoot: React.FC<PieRootProps> = (props) => {
|
|
150
|
-
const queryClient = new QueryClient()
|
|
151
|
-
return (
|
|
152
|
-
<PieConfigContext.Provider value={props.config}>
|
|
153
|
-
<QueryClientProvider client={queryClient}>
|
|
154
|
-
<PieTelegramRootContent {...props} />
|
|
155
|
-
</QueryClientProvider>
|
|
156
|
-
</PieConfigContext.Provider>
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
export default PieTelegramRoot
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { UIConfigType, SetUiAjaxConfigurationType } from '../../types'
|
|
2
|
-
import { getRegistryEntry } from "../../util/registry";
|
|
3
|
-
import {Suspense, useContext, ReactNode} from "react";
|
|
4
|
-
import FallbackContext from "../../util/fallback";
|
|
5
|
-
import { isRenderingLogEnabled } from '../../util/pieConfig';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function UI({
|
|
9
|
-
uiConfig,
|
|
10
|
-
setUiAjaxConfiguration,
|
|
11
|
-
}: {
|
|
12
|
-
uiConfig: UIConfigType
|
|
13
|
-
setUiAjaxConfiguration?: SetUiAjaxConfigurationType
|
|
14
|
-
}) {
|
|
15
|
-
const Fallback: ReactNode = useContext(FallbackContext)
|
|
16
|
-
const renderingLogEnabled = isRenderingLogEnabled()
|
|
17
|
-
|
|
18
|
-
if (renderingLogEnabled) {
|
|
19
|
-
console.log('[UI] Rendering component:', uiConfig.card)
|
|
20
|
-
console.log('[UI] Component data:', uiConfig.data)
|
|
21
|
-
console.log('[UI] Component content:', uiConfig.content)
|
|
22
|
-
console.log('[UI] Has setUiAjaxConfiguration:', !!setUiAjaxConfiguration)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const entry = getRegistryEntry(uiConfig.card)
|
|
26
|
-
if (!entry?.component) {
|
|
27
|
-
if (renderingLogEnabled) {
|
|
28
|
-
console.warn(`[UI] Component not found in registry: ${uiConfig.card}`)
|
|
29
|
-
console.log('[UI] Returning fallback component')
|
|
30
|
-
}
|
|
31
|
-
return Fallback
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (renderingLogEnabled) {
|
|
35
|
-
console.log('[UI] Found component in registry:', {
|
|
36
|
-
name: entry.name,
|
|
37
|
-
isLazy: entry.isLazy,
|
|
38
|
-
hasMetadata: !!entry.metadata
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const Component = entry.component
|
|
43
|
-
|
|
44
|
-
const node = (
|
|
45
|
-
<Component
|
|
46
|
-
data={uiConfig.data}
|
|
47
|
-
content={uiConfig.content}
|
|
48
|
-
setUiAjaxConfiguration={setUiAjaxConfiguration}
|
|
49
|
-
/>
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
if (entry.isLazy) {
|
|
53
|
-
if (renderingLogEnabled) {
|
|
54
|
-
console.log('[UI] Rendering lazy component with Suspense:', entry.name)
|
|
55
|
-
}
|
|
56
|
-
return (
|
|
57
|
-
<Suspense key={`${entry.name}`} fallback={entry.fallback ?? Fallback}>
|
|
58
|
-
{node}
|
|
59
|
-
</Suspense>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (renderingLogEnabled) {
|
|
64
|
-
console.log('[UI] Rendering component directly:', entry.name)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return node
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default UI
|
package/src/components/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { default as PieCard } from './PieCard';
|
|
2
|
-
export { default as UI } from './UI';
|
|
3
|
-
export { default as ChatCard } from './Chats/ChatCard';
|
|
4
|
-
export { default as AjaxButtonCard } from './Buttons/AjaxButtonCard'
|
|
5
|
-
export { default as SequenceCard } from './Containers/SequenceCard'
|
|
6
|
-
export { default as UnionCard } from './Containers/UnionCard'
|
package/src/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { default as UI } from './components/UI'
|
|
2
|
-
export { default as PieRoot } from './components/PieRoot'
|
|
3
|
-
export { default as PieTelegramRoot } from './components/PieTelegramRoot'
|
|
4
|
-
export { default as PieCard } from './components/PieCard'
|
|
5
|
-
export { registerPieComponent } from './util/registry'
|
|
6
|
-
export { initializePieComponents, isPieComponentsInitialized } from './util/initializeComponents'
|
|
7
|
-
|
|
8
|
-
export type {
|
|
9
|
-
PieSimpleComponentProps,
|
|
10
|
-
PieComplexComponentProps,
|
|
11
|
-
PieContainerComponentProps,
|
|
12
|
-
PieComplexContainerComponentProps,
|
|
13
|
-
PieConfig
|
|
14
|
-
} from './types'
|
|
15
|
-
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useContext, useEffect } from 'react'
|
|
2
|
-
import CentrifugeIOContext from '../util/centrifuge'
|
|
3
|
-
import { useIsSupported } from '../util/useIsSupported'
|
|
4
|
-
import { getApiServer } from "../util/pieConfig";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const CentrifugeIOInitProvider = ({ children }: { children: ReactNode }) => {
|
|
8
|
-
const centrifuge = useContext(CentrifugeIOContext)
|
|
9
|
-
const apiServer = getApiServer()
|
|
10
|
-
|
|
11
|
-
const isCentrifugeSupported = useIsSupported(apiServer, 'centrifuge')
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (!centrifuge) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const onConnectEvent = () => {
|
|
19
|
-
console.log('Centrifuge connected')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const onDisconnectEvent = (event: any) => {
|
|
23
|
-
console.log(`Centrifuge disconnected:`, event)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isCentrifugeSupported) {
|
|
27
|
-
centrifuge.on('connected', onConnectEvent)
|
|
28
|
-
centrifuge.on('disconnected', onDisconnectEvent)
|
|
29
|
-
centrifuge.connect()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
if (isCentrifugeSupported) {
|
|
34
|
-
centrifuge.disconnect()
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, [centrifuge, isCentrifugeSupported])
|
|
38
|
-
|
|
39
|
-
return children
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default CentrifugeIOInitProvider
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useContext, useEffect } from 'react'
|
|
2
|
-
import SocketIOContext from '../util/socket'
|
|
3
|
-
import { useIsSupported } from '../util/useIsSupported'
|
|
4
|
-
import { Socket } from 'socket.io-client'
|
|
5
|
-
import { getApiServer } from "../util/pieConfig";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const SocketIOInitProvider = ({ children }: { children: ReactNode }) => {
|
|
9
|
-
const socket: Socket | null = useContext(SocketIOContext)
|
|
10
|
-
const apiServer = getApiServer()
|
|
11
|
-
const isSocketIOSupported = useIsSupported(apiServer, 'socketIO')
|
|
12
|
-
|
|
13
|
-
const onPieInitEvent = (event: any) => {
|
|
14
|
-
if (typeof window !== 'undefined') {
|
|
15
|
-
window.sid = event.sid
|
|
16
|
-
console.log(`SocketIO initialized: ${window.sid}`)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (!socket) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
const onConnectEvent = () => {
|
|
25
|
-
console.log('SocketIO connected')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const onDisconnectEvent = (event: any) => {
|
|
29
|
-
console.log(`SocketIO disconnected: ${event}`)
|
|
30
|
-
socket.connect()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (isSocketIOSupported) {
|
|
34
|
-
socket.on(`pieinit`, onPieInitEvent)
|
|
35
|
-
socket.on('connect', onConnectEvent)
|
|
36
|
-
socket.on('disconnect', onDisconnectEvent)
|
|
37
|
-
socket.connect()
|
|
38
|
-
}
|
|
39
|
-
return () => {
|
|
40
|
-
if (isSocketIOSupported) {
|
|
41
|
-
socket.off(`pieinit`, onPieInitEvent)
|
|
42
|
-
socket.off('connect', onConnectEvent)
|
|
43
|
-
socket.off('disconnect', onDisconnectEvent)
|
|
44
|
-
socket.disconnect()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}, [socket, isSocketIOSupported])
|
|
48
|
-
|
|
49
|
-
return children
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default SocketIOInitProvider
|