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 { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge"; 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[]) { export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)); return twMerge(clsx(inputs));
@ -14,16 +26,8 @@ export const findTableAncestor = (
return node as HTMLTableElement; return node as HTMLTableElement;
}; };
interface EditorClassNames { export const getTrimmedHTML = (html: string) => {
noBorder?: boolean; html = html.replace(/^(<p><\/p>)+/, '');
borderOnFocus?: boolean; html = html.replace(/(<p><\/p>)+$/, '');
customClassName?: string; return html;
} }
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
);

View File

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

View File

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