You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/web/src/plugin/common/reg.ts

163 lines
3.5 KiB
TypeScript

import type { ChatInputActionContextProps } from '@/components/ChatBox/ChatInputBox/context';
import {
buildRegFn,
buildRegList,
ChatMessage,
FastFormFieldMeta,
GroupPanel,
regSocketEventListener,
} from 'tailchat-shared';
/**
*
*/
export interface PluginCustomPanel {
/**
* :
*
* - personal:
* - setting:
* - navbar: ()
* - groupdetail:
*/
position: 'personal' | 'setting' | 'navbar' | 'groupdetail';
/**
* Iconify
*/
icon: string;
/**
*
*/
name: string;
/**
*
*/
label: string;
/**
*
*/
render: React.ComponentType;
}
export const [pluginCustomPanel, regCustomPanel] =
buildRegList<PluginCustomPanel>();
/**
*
*/
export interface PluginGroupPanel {
/**
*
* @example com.msgbyte.webview/grouppanel
*/
name: string;
/**
*
*/
label: string;
/**
* ,
*/
provider: string;
/**
* , 使
*/
extraFormMeta: FastFormFieldMeta[];
/**
*
*/
render: React.ComponentType<{ panelInfo: GroupPanel }>;
}
export const [pluginGroupPanel, regGroupPanel] =
buildRegList<PluginGroupPanel>();
export interface PluginMessageInterpreter {
name?: string;
explainMessage: (message: string) => React.ReactNode;
}
/**
*
* ,
*/
export const [messageInterpreter, regMessageInterpreter] =
buildRegList<PluginMessageInterpreter>();
/**
*
*
*/
export const [getMessageRender, regMessageRender] = buildRegFn<
(message: string) => React.ReactNode
>('message-render', (message) => message);
/**
*
*
*/
const defaultMessageTextDecorators = {
url: (plain: string) => plain,
image: (plain: string, attrs: Record<string, unknown>) => plain,
mention: (userId: string, userName: string) => `@${userName}`,
};
const [_getMessageTextDecorators, regMessageTextDecorators] = buildRegFn<
() => Partial<typeof defaultMessageTextDecorators>
>('message-text-decorators', () => defaultMessageTextDecorators);
function getMessageTextDecorators() {
return {
...defaultMessageTextDecorators,
..._getMessageTextDecorators(),
};
}
export { getMessageTextDecorators, regMessageTextDecorators };
interface ChatInputAction {
label: string;
onClick: (actions: ChatInputActionContextProps) => void;
}
export type { ChatInputActionContextProps };
export const [pluginChatInputActions, regChatInputAction] =
buildRegList<ChatInputAction>();
export { regSocketEventListener };
/**
*
*/
export const [pluginColorScheme, regPluginColorScheme] = buildRegList<{
label: string;
name: string;
}>();
/**
*
*/
export const [pluginInspectServices, regInspectService] = buildRegList<{
label: string;
name: string;
}>();
/**
*
*/
export const [pluginMessageExtraParsers, regMessageExtraParser] = buildRegList<{
name: string;
render: (payload: ChatMessage) => React.ReactNode;
}>();
/**
*
*/
export const [pluginRootRoute, regPluginRootRoute] = buildRegList<{
name: string;
path: string;
component: React.ComponentType;
}>();