trimming html at start and end of content added

This commit is contained in:
Palanikannan1437 2023-10-02 17:44:56 +05:30
parent 51e281592f
commit 2c804c8d6c
3 changed files with 21 additions and 17 deletions

View File

@ -1,5 +1,17 @@
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
interface EditorClassNames {
noBorder?: boolean;
borderOnFocus?: boolean;
customClassName?: string;
}
export const getEditorClassNames = ({ noBorder, borderOnFocus, customClassName }: EditorClassNames) => cn(
'relative w-full max-w-full sm:rounded-lg mt-2 p-3 relative focus:outline-none rounded-md',
noBorder ? '' : 'border border-custom-border-200',
borderOnFocus ? 'focus:border border-custom-border-300' : 'focus:border-0',
customClassName
);
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
@ -14,16 +26,8 @@ export const findTableAncestor = (
return node as HTMLTableElement;
};
interface EditorClassNames {
noBorder?: boolean;
borderOnFocus?: boolean;
customClassName?: string;
}
export const getEditorClassNames = ({ noBorder, borderOnFocus, customClassName }: EditorClassNames) => cn(
'relative w-full max-w-full sm:rounded-lg mt-2 p-3 relative focus:outline-none rounded-md',
noBorder ? '' : 'border border-custom-border-200',
borderOnFocus ? 'focus:border border-custom-border-300' : 'focus:border-0',
customClassName
);
export const getTrimmedHTML = (html: string) => {
html = html.replace(/^(<p><\/p>)+/, '');
html = html.replace(/(<p><\/p>)+$/, '');
return html;
}

View File

@ -6,6 +6,7 @@ import { DeleteImage } from '@/types/delete-image';
import { CoreEditorProps } from "../props";
import { CoreEditorExtensions } from "../extensions";
import { EditorProps } from '@tiptap/pm/view';
import { getTrimmedHTML } from "@/lib/utils";
const DEBOUNCE_DELAY = 1500;
@ -24,6 +25,7 @@ interface CustomEditorProps {
}
export const useEditor = ({ uploadFile, editable, deleteFile, editorProps = {}, value, extensions = [], onChange, setIsSubmitting, debouncedUpdatesEnabled, forwardedRef, setShouldShowAlert, }: CustomEditorProps) => {
console.log("content aaya", value)
const editor = useCustomEditor({
editable: editable ?? true,
editorProps: {
@ -39,7 +41,7 @@ export const useEditor = ({ uploadFile, editable, deleteFile, editorProps = {},
if (debouncedUpdatesEnabled) {
debouncedUpdates({ onChange: onChange, editor });
} else {
onChange?.(editor.getJSON(), editor.getHTML());
onChange?.(editor.getJSON(), getTrimmedHTML(editor.getHTML()));
}
},
});
@ -58,7 +60,7 @@ export const useEditor = ({ uploadFile, editable, deleteFile, editorProps = {},
const debouncedUpdates = useDebouncedCallback(async ({ onChange, editor }) => {
if (onChange) {
onChange(editor.getJSON(), editor.getHTML());
onChange(editor.getJSON(), getTrimmedHTML(editor.getHTML()));
}
}, DEBOUNCE_DELAY);

View File

@ -20,8 +20,6 @@ import { USER_ACTIVITY } from "constants/fetch-keys";
// helper
import { timeAgo } from "helpers/date-time.helper";
import { SettingsSidebar } from "components/project";
// services
import fileService from "@/services/file.service";
const ProfileActivity = () => {
const router = useRouter();