@piedata/pieui 1.0.1 → 1.1.1
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 +11 -9
- package/dist/components/Buttons/AjaxButtonCard/ui/AjaxButtonCard.d.ts +2 -2
- package/dist/components/Buttons/AjaxButtonCard/ui/AjaxButtonCard.d.ts.map +1 -1
- package/dist/components/Chats/ChatCard/ui/components/AttachFileButton.d.ts.map +1 -1
- package/dist/components/Chats/ChatCard/ui/components/ChatCardInput.d.ts +1 -0
- package/dist/components/Chats/ChatCard/ui/components/ChatCardInput.d.ts.map +1 -1
- package/dist/components/Chats/ChatCard/ui/components/Markdown.d.ts +0 -1
- package/dist/components/Chats/ChatCard/ui/components/Markdown.d.ts.map +1 -1
- package/dist/components/Containers/AjaxGroupCard/ui/AjaxGroupCard.d.ts +2 -2
- package/dist/components/Containers/AjaxGroupCard/ui/AjaxGroupCard.d.ts.map +1 -1
- package/dist/components/Containers/SequenceCard/ui/SequenceCard.d.ts.map +1 -1
- package/dist/components/Containers/UnionCard/ui/UnionCard.d.ts.map +1 -1
- package/dist/components/PieCard/index.d.ts.map +1 -1
- package/dist/components/PieRoot/index.d.ts +1 -2
- package/dist/components/PieRoot/index.d.ts.map +1 -1
- package/dist/components/PieRoot/types/index.d.ts +3 -0
- package/dist/components/PieRoot/types/index.d.ts.map +1 -1
- package/dist/components/PieTelegramRoot/index.d.ts.map +1 -1
- package/dist/components/UI/index.d.ts.map +1 -1
- package/dist/components/index.esm.js +24 -26
- package/dist/components/index.js +33 -36
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +30 -32
- package/dist/index.js +43 -46
- package/dist/providers/CentrifugeIOInitProvider.d.ts.map +1 -1
- package/dist/providers/SocketIOInitProvider.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/util/ajaxCommonUtils.d.ts.map +1 -1
- package/dist/util/centrifuge.d.ts +1 -1
- package/dist/util/centrifuge.d.ts.map +1 -1
- package/dist/util/initializeComponents.d.ts.map +1 -1
- package/dist/util/pieConfig.d.ts +12 -0
- package/dist/util/pieConfig.d.ts.map +1 -0
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/socket.d.ts +1 -1
- package/dist/util/socket.d.ts.map +1 -1
- package/dist/util/useIsSupported.d.ts +1 -1
- package/dist/util/useIsSupported.d.ts.map +1 -1
- package/dist/util/useWebApp.d.ts +2 -2
- package/dist/util/useWebApp.d.ts.map +1 -1
- package/dist/util/waitForSidAvailable.d.ts +1 -2
- package/dist/util/waitForSidAvailable.d.ts.map +1 -1
- package/dist/util/webrtcClient.d.ts.map +1 -1
- package/package.json +22 -18
- package/src/components/Buttons/AjaxButtonCard/index.ts +1 -0
- package/src/components/Buttons/AjaxButtonCard/types/index.ts +17 -0
- package/src/components/Buttons/AjaxButtonCard/ui/AjaxButtonCard.tsx +38 -0
- package/src/components/Chats/ChatCard/index.ts +1 -0
- package/src/components/Chats/ChatCard/types/annyang.d.ts +11 -0
- package/src/components/Chats/ChatCard/types/index.ts +59 -0
- package/src/components/Chats/ChatCard/ui/ChatCard.tsx +130 -0
- package/src/components/Chats/ChatCard/ui/components/AttachFileButton.tsx +48 -0
- package/src/components/Chats/ChatCard/ui/components/AttachedFileView.tsx +29 -0
- package/src/components/Chats/ChatCard/ui/components/ChatCardInput.tsx +177 -0
- package/src/components/Chats/ChatCard/ui/components/ChatOption.tsx +25 -0
- package/src/components/Chats/ChatCard/ui/components/Markdown.tsx +21 -0
- package/src/components/Chats/ChatCard/ui/components/MessageAvatar.tsx +17 -0
- package/src/components/Chats/ChatCard/ui/components/MessageCard.tsx +80 -0
- package/src/components/Chats/ChatCard/ui/components/MessageContent.tsx +27 -0
- package/src/components/Chats/ChatCard/ui/components/MessagesBoard.tsx +61 -0
- package/src/components/Chats/ChatCard/ui/components/Options.tsx +20 -0
- package/src/components/Chats/ChatCard/ui/components/ResizableTextarea.tsx +59 -0
- package/src/components/Chats/ChatCard/ui/components/SendButton.tsx +37 -0
- package/src/components/Chats/ChatCard/ui/components/VoiceListeningButton.tsx +35 -0
- package/src/components/Chats/ChatCard/ui/components/icons/AttachFileIcon.tsx +18 -0
- package/src/components/Chats/ChatCard/ui/components/icons/AttachedFileIcon.tsx +18 -0
- package/src/components/Chats/ChatCard/ui/components/icons/CancelFileIcon.tsx +14 -0
- package/src/components/Chats/ChatCard/ui/components/icons/DefaultAvatar.tsx +10 -0
- package/src/components/Chats/ChatCard/ui/components/icons/SendIcon.tsx +18 -0
- package/src/components/Chats/ChatCard/ui/components/icons/VoiceRecordIcon.tsx +15 -0
- package/src/components/Containers/AjaxGroupCard/index.ts +1 -0
- package/src/components/Containers/AjaxGroupCard/types/index.ts +17 -0
- package/src/components/Containers/AjaxGroupCard/ui/AjaxGroupCard.tsx +96 -0
- package/src/components/Containers/SequenceCard/index.ts +1 -0
- package/src/components/Containers/SequenceCard/types/index.ts +10 -0
- package/src/components/Containers/SequenceCard/ui/SequenceCard.tsx +32 -0
- package/src/components/Containers/UnionCard/index.ts +1 -0
- package/src/components/Containers/UnionCard/types/index.ts +8 -0
- package/src/components/Containers/UnionCard/ui/UnionCard.tsx +27 -0
- package/src/components/PieCard/index.tsx +149 -0
- package/src/components/PieCard/types/index.ts +18 -0
- package/src/components/PieRoot/index.tsx +154 -0
- package/src/components/PieRoot/types/index.ts +14 -0
- package/src/components/PieTelegramRoot/index.tsx +161 -0
- package/src/components/UI/index.tsx +70 -0
- package/src/components/index.ts +6 -0
- package/src/index.ts +15 -0
- package/src/providers/CentrifugeIOInitProvider.tsx +42 -0
- package/src/providers/SocketIOInitProvider.tsx +52 -0
- package/src/types/index.ts +139 -0
- package/src/util/ajaxCommonUtils.ts +137 -0
- package/src/util/centrifuge.ts +33 -0
- package/src/util/fallback.tsx +6 -0
- package/src/util/initializeComponents.ts +84 -0
- package/src/util/lazy.ts +25 -0
- package/src/util/mitt.ts +11 -0
- package/src/util/pieConfig.ts +43 -0
- package/src/util/registry.ts +81 -0
- package/src/util/socket.ts +24 -0
- package/src/util/sx2radium.ts +15 -0
- package/src/util/tailwindCommonUtils.ts +6 -0
- package/src/util/useIsSupported.ts +17 -0
- package/src/util/useOpenAIWebRTC.ts +176 -0
- package/src/util/useWebApp.ts +32 -0
- package/src/util/waitForSidAvailable.ts +21 -0
- package/src/util/webrtcClient.ts +247 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/components/PieBaseRoot/index.d.ts +0 -5
- package/dist/components/PieBaseRoot/index.d.ts.map +0 -1
- package/dist/components/PieBaseRoot/types/index.d.ts +0 -6
- package/dist/components/PieBaseRoot/types/index.d.ts.map +0 -1
- package/dist/components/PieStaticRoot/index.d.ts +0 -5
- package/dist/components/PieStaticRoot/index.d.ts.map +0 -1
- package/dist/components/PieStaticRoot/types/index.d.ts +0 -7
- package/dist/components/PieStaticRoot/types/index.d.ts.map +0 -1
- package/dist/config/constant.d.ts +0 -10
- package/dist/config/constant.d.ts.map +0 -1
- package/dist/util/axiosWithCache.d.ts +0 -3
- package/dist/util/axiosWithCache.d.ts.map +0 -1
- package/dist/util/globalForm.d.ts +0 -3
- package/dist/util/globalForm.d.ts.map +0 -1
- package/dist/util/queryClient.d.ts +0 -3
- package/dist/util/queryClient.d.ts.map +0 -1
- package/dist/util/useBodyStyles.d.ts +0 -5
- package/dist/util/useBodyStyles.d.ts.map +0 -1
- package/dist/util/useImage.d.ts +0 -5
- package/dist/util/useImage.d.ts.map +0 -1
- package/dist/util/useScreenSize.d.ts +0 -6
- package/dist/util/useScreenSize.d.ts.map +0 -1
- package/dist/util/useTitle.d.ts +0 -2
- package/dist/util/useTitle.d.ts.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {PieContainerComponentProps} from "../../../../types";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export interface AjaxGroupCardData {
|
|
5
|
+
name: string
|
|
6
|
+
noReturn: boolean
|
|
7
|
+
returnType: 'content' | 'events'
|
|
8
|
+
useLoader: boolean
|
|
9
|
+
|
|
10
|
+
useSocketioSupport?: boolean
|
|
11
|
+
useCentrifugeSupport?: boolean
|
|
12
|
+
useMittSupport?: boolean
|
|
13
|
+
centrifugeChannel?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export interface AjaxGroupCardProps extends PieContainerComponentProps<AjaxGroupCardData> {}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {ReactNode, useContext, useEffect, useRef, useState} from 'react'
|
|
2
|
+
import UI from '../../../UI'
|
|
3
|
+
import { AjaxGroupCardProps } from '../types'
|
|
4
|
+
import { UIConfigType, UIEventType } from '../../../../types'
|
|
5
|
+
import PieCard from '../../../PieCard'
|
|
6
|
+
import MittContext from '../../../../util/mitt'
|
|
7
|
+
import FallbackContext from '../../../../util/fallback'
|
|
8
|
+
import { registerPieComponent } from '../../../../util/registry'
|
|
9
|
+
import Radium from "radium";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const AjaxGroupCard = ({
|
|
13
|
+
data,
|
|
14
|
+
content,
|
|
15
|
+
}: AjaxGroupCardProps) => {
|
|
16
|
+
const {
|
|
17
|
+
useLoader,
|
|
18
|
+
noReturn,
|
|
19
|
+
returnType,
|
|
20
|
+
useSocketioSupport,
|
|
21
|
+
useCentrifugeSupport,
|
|
22
|
+
useMittSupport,
|
|
23
|
+
centrifugeChannel,
|
|
24
|
+
} = data
|
|
25
|
+
const Fallback: ReactNode = useContext(FallbackContext)
|
|
26
|
+
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
27
|
+
const [uiAjaxConfiguration, setUiAjaxConfiguration] = useState<UIConfigType | null>(null)
|
|
28
|
+
const lastValidUiConfigRef = useRef<UIConfigType>(content)
|
|
29
|
+
const mitt = useContext(MittContext)
|
|
30
|
+
|
|
31
|
+
const setUiAjaxConfigurationForContentWrapper = (content: UIConfigType | null) => {
|
|
32
|
+
if (content === null) {
|
|
33
|
+
setIsLoading(true)
|
|
34
|
+
} else {
|
|
35
|
+
setIsLoading(false)
|
|
36
|
+
if (!noReturn) {
|
|
37
|
+
lastValidUiConfigRef.current = content
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!noReturn) {
|
|
41
|
+
setUiAjaxConfiguration(content)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const onChangeContent = (event: any) => {
|
|
46
|
+
lastValidUiConfigRef.current = event.content
|
|
47
|
+
setUiAjaxConfiguration(event.content)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const setUiAjaxConfigurationForEventsWrapper = (events: Array<UIEventType> | null) => {
|
|
51
|
+
if (events === null) {
|
|
52
|
+
setIsLoading(true)
|
|
53
|
+
} else {
|
|
54
|
+
setIsLoading(false)
|
|
55
|
+
if (!noReturn) {
|
|
56
|
+
for (const ev of events) {
|
|
57
|
+
mitt.emit(ev.name, ev.data)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setUiAjaxConfiguration(content)
|
|
65
|
+
setIsLoading(false)
|
|
66
|
+
}, [content])
|
|
67
|
+
|
|
68
|
+
if (!uiAjaxConfiguration && useLoader) {
|
|
69
|
+
return Fallback
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<PieCard
|
|
74
|
+
card={'AjaxGroupCard'}
|
|
75
|
+
data={data}
|
|
76
|
+
methods={{
|
|
77
|
+
changeContent: onChangeContent,
|
|
78
|
+
}}
|
|
79
|
+
useSocketioSupport={useSocketioSupport}
|
|
80
|
+
useCentrifugeSupport={useCentrifugeSupport}
|
|
81
|
+
useMittSupport={useMittSupport}
|
|
82
|
+
centrifugeChannel={centrifugeChannel}
|
|
83
|
+
>
|
|
84
|
+
<UI
|
|
85
|
+
uiConfig={uiAjaxConfiguration ?? lastValidUiConfigRef.current}
|
|
86
|
+
setUiAjaxConfiguration={
|
|
87
|
+
returnType === 'events'
|
|
88
|
+
? setUiAjaxConfigurationForEventsWrapper
|
|
89
|
+
: setUiAjaxConfigurationForContentWrapper
|
|
90
|
+
}
|
|
91
|
+
/>
|
|
92
|
+
</PieCard>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default Radium(AjaxGroupCard)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ui/SequenceCard'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CSSProperties } from 'react'
|
|
2
|
+
import {PieComplexContainerComponentProps} from "../../../../types";
|
|
3
|
+
|
|
4
|
+
export interface SequenceCardData {
|
|
5
|
+
name: string
|
|
6
|
+
sx: CSSProperties
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export interface SequenceCardProps extends PieComplexContainerComponentProps<SequenceCardData> {}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UIConfigType } from '../../../../types'
|
|
2
|
+
import {SequenceCardProps} from '../types'
|
|
3
|
+
import PieCard from '../../../PieCard'
|
|
4
|
+
import UI from '../../../UI'
|
|
5
|
+
import Radium from "radium";
|
|
6
|
+
import {sx2radium} from "../../../../util/sx2radium.ts";
|
|
7
|
+
|
|
8
|
+
const SequenceCard = ({
|
|
9
|
+
data,
|
|
10
|
+
content,
|
|
11
|
+
setUiAjaxConfiguration,
|
|
12
|
+
}: SequenceCardProps) => {
|
|
13
|
+
const { name, sx } = data
|
|
14
|
+
return (
|
|
15
|
+
<PieCard card={name} data={data}>
|
|
16
|
+
<div style={sx2radium(sx)} id={name}>
|
|
17
|
+
{content.map((obj: UIConfigType, i: number) => {
|
|
18
|
+
return (
|
|
19
|
+
<UI
|
|
20
|
+
key={`children-${i}`}
|
|
21
|
+
uiConfig={obj}
|
|
22
|
+
setUiAjaxConfiguration={setUiAjaxConfiguration}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
})}
|
|
26
|
+
</div>
|
|
27
|
+
</PieCard>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export default Radium(SequenceCard)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ui/UnionCard'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UIConfigType } from '../../../../types'
|
|
2
|
+
import {UnionCardProps} from '../types'
|
|
3
|
+
import PieCard from '../../../PieCard'
|
|
4
|
+
import UI from '../../../UI'
|
|
5
|
+
|
|
6
|
+
const UnionCard = ({
|
|
7
|
+
data,
|
|
8
|
+
content,
|
|
9
|
+
setUiAjaxConfiguration,
|
|
10
|
+
}: UnionCardProps) => {
|
|
11
|
+
const { name } = data
|
|
12
|
+
return (
|
|
13
|
+
<PieCard card={name} data={data}>
|
|
14
|
+
{content.map((obj: UIConfigType, i: number) => {
|
|
15
|
+
return (
|
|
16
|
+
<UI
|
|
17
|
+
key={`children-${i}`}
|
|
18
|
+
uiConfig={obj}
|
|
19
|
+
setUiAjaxConfiguration={setUiAjaxConfiguration}
|
|
20
|
+
/>
|
|
21
|
+
)
|
|
22
|
+
})}
|
|
23
|
+
</PieCard>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default UnionCard
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|