2b29918bf8
## PR Description This PR: - Introduces a `FrontComponentHostCommunicationApi`, which allows us to pass functions to be executed from the worker - Exposes a navigate function from the host to the front component remote workers, enabling SDK components to trigger in-app navigation - Gets rid of `useSyncExternalStore` and makes the execution context reactive without it - Refactors and improves the `esbuild` plugin system ## Video https://github.com/user-attachments/assets/7b26a1c2-f85f-4898-a71d-f60c70e61711
28 lines
792 B
TypeScript
28 lines
792 B
TypeScript
import { type AppPath, type NavigateOptions } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
type NavigateFunction = (
|
|
to: AppPath,
|
|
params?: Record<string, string | null>,
|
|
queryParams?: Record<string, unknown>,
|
|
options?: NavigateOptions,
|
|
) => Promise<void>;
|
|
|
|
let navigateFunction: NavigateFunction | undefined;
|
|
|
|
export const setNavigate = (fn: NavigateFunction): void => {
|
|
navigateFunction = fn;
|
|
};
|
|
|
|
export const navigate: NavigateFunction = (
|
|
to: AppPath,
|
|
params?: Record<string, string | null>,
|
|
queryParams?: Record<string, unknown>,
|
|
options?: NavigateOptions,
|
|
): Promise<void> => {
|
|
if (!isDefined(navigateFunction)) {
|
|
throw new Error('navigateFunction is not set');
|
|
}
|
|
return navigateFunction(to, params, queryParams, options);
|
|
};
|