refactor: move web utils to packages (#7145)
* refactor: move web utils to packages * fix: build and lint errors * chore: update drag handle plugin * chore: update table cell type to fix build errors * fix: build errors * chore: sync few changes * fix: build errors * chore: minor fixes related to duplicate assets imports * fix: build errors * chore: minor changes
This commit is contained in:
parent
dffcc6dc10
commit
2014400bed
614 changed files with 1999 additions and 3030 deletions
37
packages/utils/src/editor.ts
Normal file
37
packages/utils/src/editor.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// local imports
|
||||
import { getFileURL } from "./file";
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
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() ?? "";
|
||||
};
|
||||
|
||||
export const isEditorEmpty = (description: string | undefined): boolean =>
|
||||
!description ||
|
||||
description === "<p></p>" ||
|
||||
description === `<p class="editor-paragraph-block"></p>` ||
|
||||
description.trim() === "";
|
||||
Loading…
Add table
Add a link
Reference in a new issue