@piedata/pieui 1.1.1 → 1.1.3
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 +39 -39
- 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/Chats/ChatCard/ui/components/AttachFileButton.d.ts.map +1 -1
- package/dist/components/Chats/ChatCard/ui/components/ChatCardInput.d.ts +0 -1
- package/dist/components/Chats/ChatCard/ui/components/ChatCardInput.d.ts.map +1 -1
- package/dist/components/PieRoot/index.d.ts.map +1 -1
- package/dist/components/index.esm.js +14 -24
- package/dist/components/index.js +21 -31
- package/dist/index.esm.js +18 -28
- package/dist/index.js +32 -42
- package/dist/util/ajaxCommonUtils.d.ts +7 -1
- package/dist/util/ajaxCommonUtils.d.ts.map +1 -1
- package/package.json +9 -9
- 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 -48
- 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
package/src/types/index.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {ComponentType, ReactNode} from "react";
|
|
2
|
-
|
|
3
|
-
export type WebAppUser = {
|
|
4
|
-
id: string
|
|
5
|
-
username: string
|
|
6
|
-
photo_url: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type MainButtonType = {
|
|
10
|
-
show: () => void
|
|
11
|
-
onClick: (callback: () => void) => void
|
|
12
|
-
offClick: (callback: () => void) => void
|
|
13
|
-
setText: (text: string) => void
|
|
14
|
-
hide: () => void
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type BackButtonType = {
|
|
18
|
-
show: () => void
|
|
19
|
-
onClick: (callback: () => void) => void
|
|
20
|
-
hide: () => void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type WebAppInitData = {
|
|
24
|
-
user: WebAppUser
|
|
25
|
-
start_param?: string
|
|
26
|
-
chat_type?: 'sender' | 'private' | 'group' | 'supergroup' | 'channel'
|
|
27
|
-
chat_instance?: string
|
|
28
|
-
auth_date: number
|
|
29
|
-
hash: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type WebApp = {
|
|
33
|
-
sendData: (data: string) => void
|
|
34
|
-
showAlert: (message: string) => void
|
|
35
|
-
MainButton: MainButtonType
|
|
36
|
-
BackButton: BackButtonType
|
|
37
|
-
initDataUnsafe: WebAppInitData
|
|
38
|
-
initData: string
|
|
39
|
-
ready: () => void
|
|
40
|
-
close: () => void
|
|
41
|
-
openLink: (link: string, option: string) => void
|
|
42
|
-
platform: 'ios' | 'android' | 'web'
|
|
43
|
-
expand: () => void
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type Telegram = {
|
|
47
|
-
WebApp: WebApp
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type InitDataUnsafe = {
|
|
51
|
-
user?: WebAppUser
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type InitData = string
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export interface UIConfigType {
|
|
58
|
-
card: string
|
|
59
|
-
data: any
|
|
60
|
-
content: UIConfigType | Array<UIConfigType>
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface UIEventType {
|
|
64
|
-
name: string
|
|
65
|
-
data: Record<any, any>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type SetUiAjaxConfigurationType =
|
|
69
|
-
| ((content: UIConfigType | null) => void)
|
|
70
|
-
| ((events: Array<UIEventType> | null) => void)
|
|
71
|
-
|
|
72
|
-
export interface PieEvent {
|
|
73
|
-
cardName: string
|
|
74
|
-
name: string
|
|
75
|
-
eventName: string
|
|
76
|
-
data: any
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type PieEventEmitter = (event: PieEvent) => void
|
|
80
|
-
|
|
81
|
-
declare global {
|
|
82
|
-
interface Window {
|
|
83
|
-
sid: string
|
|
84
|
-
Telegram: Telegram
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export interface ComponentMetadata {
|
|
90
|
-
author?: string
|
|
91
|
-
version?: string
|
|
92
|
-
description?: string
|
|
93
|
-
tags?: string[]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
export interface PieComplexContainerComponentProps<TData = unknown> {
|
|
98
|
-
data: TData
|
|
99
|
-
content: Array<UIConfigType>
|
|
100
|
-
setUiAjaxConfiguration?: SetUiAjaxConfigurationType
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface PieContainerComponentProps<TData = unknown> {
|
|
104
|
-
data: TData
|
|
105
|
-
content: UIConfigType
|
|
106
|
-
setUiAjaxConfiguration?: SetUiAjaxConfigurationType
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface PieComplexComponentProps<TData = unknown> {
|
|
110
|
-
data: TData
|
|
111
|
-
setUiAjaxConfiguration?: SetUiAjaxConfigurationType
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface PieSimpleComponentProps<TData = unknown> {
|
|
115
|
-
data: TData
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export type PieComponentProps<TData = unknown> =
|
|
119
|
-
| PieSimpleComponentProps<TData>
|
|
120
|
-
| PieContainerComponentProps<TData>
|
|
121
|
-
| PieComplexContainerComponentProps<TData>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export interface ComponentRegistration<TProps> {
|
|
125
|
-
name: string
|
|
126
|
-
component?: ComponentType<TProps>
|
|
127
|
-
fallback?: ReactNode
|
|
128
|
-
loader?: () => Promise<{ default: ComponentType<TProps> }>
|
|
129
|
-
metadata?: ComponentMetadata
|
|
130
|
-
isLazy?: boolean
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
export interface PieConfig {
|
|
135
|
-
apiServer: string
|
|
136
|
-
centrifugeServer?: string
|
|
137
|
-
enableRenderingLog?: boolean
|
|
138
|
-
pageProcessor?: string
|
|
139
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {getApiServer, isRenderingLogEnabled} from './pieConfig'
|
|
2
|
-
import '../types'
|
|
3
|
-
import { SetUiAjaxConfigurationType, UIEventType } from '../types'
|
|
4
|
-
import waitForSidAvailable from './waitForSidAvailable'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const getAjaxSubmit = (
|
|
8
|
-
setUiAjaxConfiguration?: SetUiAjaxConfigurationType,
|
|
9
|
-
kwargs: Record<string, any> = {},
|
|
10
|
-
depsNames: Array<string> = [],
|
|
11
|
-
pathname?: string,
|
|
12
|
-
) => {
|
|
13
|
-
const renderingLogEnabled = isRenderingLogEnabled()
|
|
14
|
-
|
|
15
|
-
if (renderingLogEnabled) {
|
|
16
|
-
console.log('Registering AJAX: ', pathname, kwargs, depsNames)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!pathname || !setUiAjaxConfiguration) {
|
|
20
|
-
if (renderingLogEnabled) {
|
|
21
|
-
console.warn('Registration FAILED: pathname or setUiAjaxConfiguration is missing!')
|
|
22
|
-
}
|
|
23
|
-
return () => {}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return async (extraKwargs: Record<string, any> = {}) => {
|
|
27
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
28
|
-
if (renderingLogEnabled) {
|
|
29
|
-
console.warn('getAjaxSubmit called on server, skipping DOM-dependent logic')
|
|
30
|
-
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (depsNames.includes('sid')) {
|
|
35
|
-
await waitForSidAvailable()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const data = new FormData()
|
|
39
|
-
for (const [key, value] of Object.entries({ ...kwargs, ...extraKwargs })) {
|
|
40
|
-
data.append(key, value)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const depName of depsNames) {
|
|
44
|
-
if (depName === 'sid') {
|
|
45
|
-
if (!window.sid) throw new Error("SocketIO isn't initialized properly")
|
|
46
|
-
data.append('sid', window.sid)
|
|
47
|
-
} else {
|
|
48
|
-
const inputs = document.getElementsByName(depName)
|
|
49
|
-
if (!inputs.length) {
|
|
50
|
-
if (renderingLogEnabled) {
|
|
51
|
-
console.warn(`No input found with name ${depName}`)
|
|
52
|
-
}
|
|
53
|
-
continue
|
|
54
|
-
}
|
|
55
|
-
const input = inputs[0]
|
|
56
|
-
if (input instanceof HTMLInputElement) {
|
|
57
|
-
if (input.type === 'file' && input.files) {
|
|
58
|
-
Array.from(input.files).forEach((file) => data.append(depName, file))
|
|
59
|
-
} else {
|
|
60
|
-
data.append(depName, input.value)
|
|
61
|
-
}
|
|
62
|
-
} else if (input instanceof HTMLTextAreaElement) {
|
|
63
|
-
data.append(depName, input.value)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const apiEndpoint = getApiServer() + 'api/ajax_content' + pathname
|
|
69
|
-
|
|
70
|
-
setUiAjaxConfiguration(null)
|
|
71
|
-
return await fetch(apiEndpoint, {
|
|
72
|
-
method: 'POST',
|
|
73
|
-
body: data,
|
|
74
|
-
})
|
|
75
|
-
.then(async (response) => {
|
|
76
|
-
const contentType = response.headers.get('content-type') || ''
|
|
77
|
-
const isJson = contentType.includes('application/json')
|
|
78
|
-
const isStream = !!response.body?.getReader && !isJson
|
|
79
|
-
|
|
80
|
-
if (isStream) {
|
|
81
|
-
const reader = response.body!.getReader()
|
|
82
|
-
const decoder = new TextDecoder()
|
|
83
|
-
let buffer = ''
|
|
84
|
-
|
|
85
|
-
// eslint-disable-next-line no-constant-condition
|
|
86
|
-
while (true) {
|
|
87
|
-
const { done, value } = await reader.read()
|
|
88
|
-
if (done) break
|
|
89
|
-
buffer += decoder.decode(value, { stream: true })
|
|
90
|
-
|
|
91
|
-
const lines = buffer.split('\n')
|
|
92
|
-
buffer = lines.pop() ?? ''
|
|
93
|
-
|
|
94
|
-
for (const line of lines) {
|
|
95
|
-
const trimmed = line.trim()
|
|
96
|
-
if (!trimmed) continue
|
|
97
|
-
try {
|
|
98
|
-
const currentEvent = JSON.parse(trimmed) as UIEventType
|
|
99
|
-
;(setUiAjaxConfiguration as (events: UIEventType[]) => void)([
|
|
100
|
-
currentEvent,
|
|
101
|
-
])
|
|
102
|
-
} catch (err) {
|
|
103
|
-
if (renderingLogEnabled) {
|
|
104
|
-
console.warn('Failed to parse streamed line:', trimmed)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (buffer.trim()) {
|
|
111
|
-
try {
|
|
112
|
-
const currentEvent = JSON.parse(buffer) as UIEventType
|
|
113
|
-
;(setUiAjaxConfiguration as (events: UIEventType[]) => void)([
|
|
114
|
-
currentEvent,
|
|
115
|
-
])
|
|
116
|
-
} catch (err) {
|
|
117
|
-
if (renderingLogEnabled) {
|
|
118
|
-
console.warn('Failed to parse final streamed line:', buffer)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return {}
|
|
123
|
-
} else {
|
|
124
|
-
const data = await response.json()
|
|
125
|
-
setUiAjaxConfiguration(data)
|
|
126
|
-
return data
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
.catch((err) => {
|
|
130
|
-
if (renderingLogEnabled) {
|
|
131
|
-
console.error('AJAX request failed:', err)
|
|
132
|
-
}
|
|
133
|
-
setUiAjaxConfiguration(null)
|
|
134
|
-
return err
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
}
|
package/src/util/centrifuge.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react'
|
|
2
|
-
import { Centrifuge } from 'centrifuge'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const getCentrifuge = (apiServer: string, centrifugeServer?: string) => {
|
|
6
|
-
|
|
7
|
-
async function getToken() {
|
|
8
|
-
const res = await fetch(apiServer + 'api/centrifuge/gen_token')
|
|
9
|
-
if (!res.ok) {
|
|
10
|
-
if (res.status === 403) {
|
|
11
|
-
throw new Centrifuge.UnauthorizedError('Backend is not answering')
|
|
12
|
-
}
|
|
13
|
-
throw new Error(`Unexpected status code ${res.status}`)
|
|
14
|
-
}
|
|
15
|
-
const data = await res.json()
|
|
16
|
-
return data.token
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return centrifugeServer ?
|
|
20
|
-
new Centrifuge(centrifugeServer || '', {
|
|
21
|
-
getToken,
|
|
22
|
-
}): null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// export const centrifuge =
|
|
27
|
-
// getCentrifugeServer() ?
|
|
28
|
-
// new Centrifuge(getCentrifugeServer() || '', {
|
|
29
|
-
// getToken,
|
|
30
|
-
// }): null
|
|
31
|
-
|
|
32
|
-
const CentrifugeIOContext = createContext<Centrifuge | null>(null)
|
|
33
|
-
export default CentrifugeIOContext
|
package/src/util/fallback.tsx
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { registerPieComponent } from './registry'
|
|
2
|
-
|
|
3
|
-
// Import all components that need registration
|
|
4
|
-
import SequenceCard from '../components/Containers/SequenceCard/ui/SequenceCard'
|
|
5
|
-
import UnionCard from '../components/Containers/UnionCard/ui/UnionCard'
|
|
6
|
-
import AjaxGroupCard from '../components/Containers/AjaxGroupCard/ui/AjaxGroupCard'
|
|
7
|
-
|
|
8
|
-
import AjaxButtonCard from '../components/Buttons/AjaxButtonCard/ui/AjaxButtonCard'
|
|
9
|
-
|
|
10
|
-
import ChatCard from '../components/Chats/ChatCard/ui/ChatCard'
|
|
11
|
-
|
|
12
|
-
let initialized = false
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Initialize all PieUI components by registering them in the component registry.
|
|
16
|
-
* This function should be called once before using PieRoot or any dynamic components.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { initializePieComponents } from 'pieui'
|
|
21
|
-
*
|
|
22
|
-
* // Call this once in your app initialization
|
|
23
|
-
* initializePieComponents()
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export function initializePieComponents(): void {
|
|
27
|
-
if (initialized) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Register all built-in components
|
|
32
|
-
registerPieComponent({
|
|
33
|
-
name: 'SequenceCard',
|
|
34
|
-
component: SequenceCard,
|
|
35
|
-
metadata: {
|
|
36
|
-
author: "PieData",
|
|
37
|
-
description: "Simple div with styles joining few components"
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
registerPieComponent({
|
|
42
|
-
name: 'UnionCard',
|
|
43
|
-
component: UnionCard,
|
|
44
|
-
metadata: {
|
|
45
|
-
author: "PieData",
|
|
46
|
-
description: "Renders one of many components"
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
registerPieComponent({
|
|
51
|
-
name: 'AjaxGroupCard',
|
|
52
|
-
component: AjaxGroupCard,
|
|
53
|
-
metadata: {
|
|
54
|
-
author: "PieData",
|
|
55
|
-
description: "Group card with AJAX support"
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
registerPieComponent({
|
|
60
|
-
name: 'AjaxButtonCard',
|
|
61
|
-
component: AjaxButtonCard,
|
|
62
|
-
metadata: {
|
|
63
|
-
author: "PieData",
|
|
64
|
-
description: "Button with AJAX support"
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
registerPieComponent({
|
|
69
|
-
name: 'ChatCard',
|
|
70
|
-
component: ChatCard,
|
|
71
|
-
metadata: {
|
|
72
|
-
author: "PieData",
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
initialized = true
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Check if PieUI components have been initialized
|
|
81
|
-
*/
|
|
82
|
-
export function isPieComponentsInitialized(): boolean {
|
|
83
|
-
return initialized
|
|
84
|
-
}
|
package/src/util/lazy.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { lazy, ComponentType, LazyExoticComponent } from 'react'
|
|
2
|
-
|
|
3
|
-
const moduleCache = new Map<string, any>()
|
|
4
|
-
|
|
5
|
-
export function trackLazy<T extends ComponentType<any>>(
|
|
6
|
-
loader: () => Promise<{ default: T }>,
|
|
7
|
-
name: string,
|
|
8
|
-
): LazyExoticComponent<T> {
|
|
9
|
-
return lazy(() => {
|
|
10
|
-
if (moduleCache.has(name)) {
|
|
11
|
-
return moduleCache.get(name)!
|
|
12
|
-
}
|
|
13
|
-
const promise = loader().then((mod) => mod)
|
|
14
|
-
moduleCache.set(name, promise)
|
|
15
|
-
return promise
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const preloadComponent = async (name: string, loader?: () => Promise<any>) => {
|
|
20
|
-
if (!loader) return
|
|
21
|
-
if (moduleCache.has(name)) return moduleCache.get(name)
|
|
22
|
-
const promise = loader().then((mod) => mod)
|
|
23
|
-
moduleCache.set(name, promise)
|
|
24
|
-
return promise
|
|
25
|
-
}
|
package/src/util/mitt.ts
DELETED
package/src/util/pieConfig.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {createContext, useContext} from "react";
|
|
2
|
-
import {PieConfig} from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const PieConfigContext = createContext<PieConfig | null>(null)
|
|
6
|
-
|
|
7
|
-
export const usePieConfig = () => {
|
|
8
|
-
const context = useContext(PieConfigContext)
|
|
9
|
-
if (!context) {
|
|
10
|
-
throw new Error('usePieConfig must be used within PieConfigProvider')
|
|
11
|
-
}
|
|
12
|
-
return context
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Helper functions that match the old API
|
|
16
|
-
export const useApiServer = () => {
|
|
17
|
-
const { apiServer } = usePieConfig()
|
|
18
|
-
return apiServer
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const getApiServer = useApiServer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export const useCentrifugeServer = () => {
|
|
25
|
-
const { centrifugeServer } = usePieConfig()
|
|
26
|
-
return centrifugeServer
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const getCentrifugeServer = useCentrifugeServer
|
|
30
|
-
|
|
31
|
-
export const useIsRenderingLogEnabled = () => {
|
|
32
|
-
const { enableRenderingLog } = usePieConfig()
|
|
33
|
-
return enableRenderingLog
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const isRenderingLogEnabled = useIsRenderingLogEnabled
|
|
37
|
-
|
|
38
|
-
export const usePageProcessor = () => {
|
|
39
|
-
const { pageProcessor } = usePieConfig()
|
|
40
|
-
return pageProcessor
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const getPageProcessor = usePageProcessor
|
package/src/util/registry.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {ComponentMetadata, ComponentRegistration} from '../types'
|
|
2
|
-
import {trackLazy} from './lazy'
|
|
3
|
-
import {ComponentType} from 'react'
|
|
4
|
-
|
|
5
|
-
const registry = new Map<string, ComponentRegistration<any>>()
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const normalizeRegistration = <TProps,>(
|
|
9
|
-
registration: ComponentRegistration<TProps>
|
|
10
|
-
): ComponentRegistration<TProps> => {
|
|
11
|
-
if (!registration.name) {
|
|
12
|
-
throw new Error('Component registration requires a name')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!registration.component && !registration.loader) {
|
|
16
|
-
throw new Error(`Component "${registration.name}" requires component or loader`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const entry: ComponentRegistration<TProps> = {
|
|
20
|
-
name: registration.name,
|
|
21
|
-
component: registration.component,
|
|
22
|
-
loader: registration.loader,
|
|
23
|
-
metadata: registration.metadata,
|
|
24
|
-
fallback: registration.fallback,
|
|
25
|
-
isLazy: false,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!entry.component && entry.loader) {
|
|
29
|
-
entry.component = trackLazy(
|
|
30
|
-
entry.loader,
|
|
31
|
-
registration.name
|
|
32
|
-
) as ComponentType<TProps>
|
|
33
|
-
entry.loader = undefined
|
|
34
|
-
entry.isLazy = true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return entry
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export function registerPieComponent<TProps>(
|
|
42
|
-
registration: ComponentRegistration<TProps>
|
|
43
|
-
): ComponentType<TProps> | undefined {
|
|
44
|
-
const entry = normalizeRegistration(registration)
|
|
45
|
-
registry.set(entry.name, entry)
|
|
46
|
-
return entry.component
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export const registerMultipleComponents = (
|
|
51
|
-
components: ComponentRegistration<any>[]
|
|
52
|
-
) => {
|
|
53
|
-
components.forEach((component) => registerPieComponent(component))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const unregisterComponent = (name: string) => {
|
|
57
|
-
registry.delete(name)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const hasComponent = (name: string) => {
|
|
61
|
-
return registry.has(name)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const getComponentMeta = (name: string): ComponentMetadata | undefined => {
|
|
65
|
-
return registry.get(name)?.metadata
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export const getRegistryEntry = (
|
|
70
|
-
name: string
|
|
71
|
-
): ComponentRegistration<any> | undefined => {
|
|
72
|
-
return registry.get(name)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const getAllRegisteredComponents = (): string[] => {
|
|
76
|
-
return Array.from(registry.keys())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const getRegistrySize = (): number => {
|
|
80
|
-
return registry.size
|
|
81
|
-
}
|
package/src/util/socket.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {io, Socket} from 'socket.io-client'
|
|
2
|
-
import { createContext } from 'react'
|
|
3
|
-
|
|
4
|
-
// export const socket = io(getApiServer(), {
|
|
5
|
-
// autoConnect: false,
|
|
6
|
-
// transports: ['websocket'],
|
|
7
|
-
// })
|
|
8
|
-
|
|
9
|
-
export const getSocket = (apiServer: string) => io(apiServer, {
|
|
10
|
-
autoConnect: false,
|
|
11
|
-
transports: ['websocket'],
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
const onPieInitEvent = (event) => {
|
|
16
|
-
window.sid = event.sid
|
|
17
|
-
console.log(`Connected: ${window.sid}`)
|
|
18
|
-
}
|
|
19
|
-
socket.on(`pieinit`, onPieInitEvent)
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const SocketIOContext = createContext<Socket | null>(null)
|
|
23
|
-
|
|
24
|
-
export default SocketIOContext
|
package/src/util/sx2radium.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
import Radium from 'radium'
|
|
3
|
-
|
|
4
|
-
export function sx2radium(sx: Record<string, any> | CSSProperties | undefined): CSSProperties {
|
|
5
|
-
if (!sx) {
|
|
6
|
-
return {}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const copy = { ...sx }
|
|
10
|
-
if ('animationName' in copy && typeof copy.animationName === 'object') {
|
|
11
|
-
const uniqueAnimationName = 'radiumAnimation_' + Math.random().toString(36).substring(2, 8)
|
|
12
|
-
copy.animationName = Radium.keyframes(copy.animationName, uniqueAnimationName)
|
|
13
|
-
}
|
|
14
|
-
return copy
|
|
15
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export function useIsSupported(apiServer: string, name: string): boolean | null {
|
|
4
|
-
const [isSupported, setIsSupported] = useState<boolean | null>(null)
|
|
5
|
-
const [supportIsRequested, setSupportIsRequested] = useState(false)
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
if (!supportIsRequested) {
|
|
8
|
-
setSupportIsRequested(true)
|
|
9
|
-
fetch(apiServer + `api/support/${name}`, { method: 'GET' })
|
|
10
|
-
.then((res) => res.json())
|
|
11
|
-
.then((res) => {
|
|
12
|
-
setIsSupported(res)
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
}, [])
|
|
16
|
-
return isSupported
|
|
17
|
-
}
|