2025-05-20 12:14:20 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-19 09:16:27 +01:00
|
|
|
import type { JSX } from "react";
|
2025-06-03 13:41:57 +01:00
|
|
|
import type { MatrixEvent } from "matrix-js-sdk/lib/matrix";
|
2025-05-16 15:49:07 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* Properties for all message components.
|
|
|
|
|
* @alpha Subject to change.
|
2025-05-16 15:49:07 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
export type CustomMessageComponentProps = {
|
2025-05-16 15:49:07 +01:00
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* The Matrix event for this textual body.
|
2025-05-16 15:49:07 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
mxEvent: MatrixEvent;
|
|
|
|
|
/**
|
|
|
|
|
* Words to highlight on (e.g. from search results).
|
|
|
|
|
* May be undefined if the client does not need to highlight
|
|
|
|
|
*/
|
|
|
|
|
highlights?: string[];
|
|
|
|
|
/**
|
|
|
|
|
* Should previews be shown for this event
|
|
|
|
|
*/
|
|
|
|
|
showUrlPreview?: boolean;
|
|
|
|
|
/**
|
|
|
|
|
* Is this event being rendered to a static export
|
|
|
|
|
*/
|
|
|
|
|
forExport?: boolean;
|
|
|
|
|
};
|
2025-05-16 15:49:07 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* Function used to render a message component.
|
|
|
|
|
* @beta Unlikely to change
|
2025-05-16 15:49:07 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
export type CustomMessageRenderFunction = (
|
2025-05-19 09:16:27 +01:00
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* Properties for the message to be renderered.
|
2025-05-19 09:16:27 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
props: CustomMessageComponentProps,
|
2025-05-19 09:16:27 +01:00
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* Render function for the original component. This may be omitted if the message would not normally be rendered.
|
2025-05-19 09:16:27 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
originalComponent?: () => React.JSX.Element,
|
2025-05-16 15:49:07 +01:00
|
|
|
) => JSX.Element | null;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-05-19 09:16:27 +01:00
|
|
|
* API for inserting custom components into Element.
|
2025-05-16 15:49:07 +01:00
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export interface CustomComponentsApi {
|
|
|
|
|
/**
|
2025-05-30 14:51:28 +01:00
|
|
|
* Register a renderer for a message type in the timeline.
|
|
|
|
|
*
|
2025-05-19 09:16:27 +01:00
|
|
|
* The render function should either return a rendered component, or `null` if the
|
2025-05-30 14:51:28 +01:00
|
|
|
* component should not be overidden (for instance, to passthrough to another module or allow
|
|
|
|
|
* the application complete control)
|
2025-05-19 09:16:27 +01:00
|
|
|
*
|
|
|
|
|
* Multiple render function may be registered for a single target, however the first
|
|
|
|
|
* non-null result will be used. If all results are null, or no registrations exist
|
|
|
|
|
* for a target then the original component is used.
|
|
|
|
|
*
|
2025-05-30 14:51:28 +01:00
|
|
|
* @param eventType - The event type this renderer is for. Use a RegExp instance if you want to target multiple types.
|
|
|
|
|
* @param renderer - The render function.
|
2025-05-16 15:49:07 +01:00
|
|
|
*/
|
2025-05-30 14:51:28 +01:00
|
|
|
registerMessageRenderer(eventType: string | RegExp, renderer: CustomMessageRenderFunction): void;
|
2025-05-16 15:49:07 +01:00
|
|
|
}
|