2024-10-08 16:54:02 +05:30
|
|
|
// helpers
|
2024-12-20 13:41:25 +05:30
|
|
|
import { getFileURL } from "@/helpers/file.helper";
|
2024-10-11 20:13:38 +05:30
|
|
|
|
|
|
|
|
type TEditorSrcArgs = {
|
|
|
|
|
assetId: string;
|
|
|
|
|
projectId?: string;
|
|
|
|
|
workspaceSlug: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description generate the file source using assetId
|
|
|
|
|
* @param {TEditorSrcArgs} args
|
|
|
|
|
*/
|
|
|
|
|
export const getEditorAssetSrc = (args: TEditorSrcArgs): string | undefined => {
|
|
|
|
|
const { assetId, projectId, workspaceSlug } = args;
|
|
|
|
|
let url: string | undefined = "";
|
|
|
|
|
if (projectId) {
|
|
|
|
|
url = getFileURL(`/api/assets/v2/workspaces/${workspaceSlug}/projects/${projectId}/${assetId}/`);
|
|
|
|
|
} else {
|
|
|
|
|
url = getFileURL(`/api/assets/v2/workspaces/${workspaceSlug}/${assetId}/`);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-29 19:39:55 +05:30
|
|
|
export const getTextContent = (jsx: JSX.Element | React.ReactNode | null | undefined): string => {
|
|
|
|
|
if (!jsx) return "";
|
|
|
|
|
|
|
|
|
|
const div = document.createElement("div");
|
|
|
|
|
div.innerHTML = jsx.toString();
|
|
|
|
|
return div.textContent?.trim() ?? "";
|
|
|
|
|
};
|