From 97e82593ec96b362fd3092a64080f1a057ccf4a0 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Wed, 16 Jul 2025 21:21:06 +0700 Subject: [PATCH] feat: tiptap --- .../launches/general.preview.component.tsx | 56 ++++++++++++------- .../src/components/new-launch/editor.tsx | 10 +++- .../components/new-launch/manage.modal.tsx | 19 +++---- package.json | 1 + pnpm-lock.yaml | 12 ++++ 5 files changed, 65 insertions(+), 33 deletions(-) diff --git a/apps/frontend/src/components/launches/general.preview.component.tsx b/apps/frontend/src/components/launches/general.preview.component.tsx index 004e193c..7eb53c06 100644 --- a/apps/frontend/src/components/launches/general.preview.component.tsx +++ b/apps/frontend/src/components/launches/general.preview.component.tsx @@ -8,45 +8,59 @@ import { textSlicer } from '@gitroom/helpers/utils/count.length'; import interClass from '@gitroom/react/helpers/inter.font'; import Image from 'next/image'; import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store'; +import { stripHtmlValidation } from '@gitroom/helpers/utils/strip.html.validation'; export const GeneralPreviewComponent: FC<{ maximumCharacters?: number; }> = (props) => { const { value: topValue, integration } = useIntegration(); const current = useLaunchStore((state) => state.current); const mediaDir = useMediaDirectory(); - const newValues = useFormatting(topValue, { - removeMarkdown: true, - saveBreaklines: true, - specialFunc: (text: string) => { - const { start, end } = textSlicer( - integration?.identifier || '', - props.maximumCharacters || 10000, - text - ); - return ( - text.slice(start, end) + - '' + - text?.slice(end) + - '' - ); - }, + + const renderContent = topValue.map((p) => { + const newContent = stripHtmlValidation(p.content, true) + .replace(/(@.+?)(\s)/gi, (match, match1, match2) => { + return `${match1.trim()}${match2}`; + }) + .replace(/@\[(.+?)]\((.+?)\)/gi, (match, name, id) => { + return `@${name}`; + }); + + const { start, end } = textSlicer( + integration?.identifier || '', + props.maximumCharacters || 10000, + newContent + ); + + const finalValue = + newContent.slice(start, end) + + `` + + newContent.slice(end) + + ``; + + return { text: finalValue, images: p.image }; }); + + console.log(renderContent); return (
- {newValues.map((value, index) => ( + {renderContent.map((value, index) => (
x @@ -84,7 +98,9 @@ export const GeneralPreviewComponent: FC<{
- {current === 'global' ? '' : integration?.display || '@username'} + {current === 'global' + ? '' + : integration?.display || '@username'}
 | File[]) => {
+    async (event: ClipboardEvent | File[]) => {
       // @ts-ignore
       const clipboardItems = event.clipboardData?.items;
       if (!clipboardItems) {
@@ -532,10 +532,16 @@ export const Editor: FC<{
       InterceptBoldShortcut,
       InterceptUnderlineShortcut,
       Span,
+      History.configure({
+        depth: 100, // default is 100
+        newGroupDelay: 100, // default is 500ms
+      }),
     ],
     content: props.value || '',
     shouldRerenderOnTransaction: true,
     immediatelyRender: false,
+    // @ts-ignore
+    onPaste: paste,
     onUpdate: (innerProps) => {
       props?.onChange?.(innerProps.editor.getHTML());
     },
diff --git a/apps/frontend/src/components/new-launch/manage.modal.tsx b/apps/frontend/src/components/new-launch/manage.modal.tsx
index 78d09b3d..d0152872 100644
--- a/apps/frontend/src/components/new-launch/manage.modal.tsx
+++ b/apps/frontend/src/components/new-launch/manage.modal.tsx
@@ -203,16 +203,13 @@ export const ManageModal: FC = (props) => {
         });
 
         for (const item of sliceNeeded) {
-          if (
-            !(await deleteDialog(
-              `${item?.integration?.name} (${item?.integration?.identifier}) post is too long, it will be cropped, do you want to continue?`,
-              'Yes, continue'
-            ))
-          ) {
-            item.preview();
-            setLoading(false);
-            return;
-          }
+          toaster.show(
+            `${item?.integration?.name} (${item?.integration?.identifier}) post is too long, please fix it`,
+            'warning'
+          );
+          item.preview();
+          setLoading(false);
+          return;
         }
       }
 
@@ -251,7 +248,7 @@ export const ManageModal: FC = (props) => {
           settings: { ...(post.settings || {}) },
           value: post.values.map((value: any) => ({
             ...(value.id ? { id: value.id } : {}),
-            content: value.content.slice(0, post.maximumCharacters || 1000000),
+            content: value.content,
             image:
               (value?.media || []).map(
                 ({ id, path, alt, thumbnail, thumbnailTimestamp }: any) => ({
diff --git a/package.json b/package.json
index 492e4f99..c6427c10 100644
--- a/package.json
+++ b/package.json
@@ -81,6 +81,7 @@
     "@tailwindcss/postcss": "^4.1.7",
     "@tiptap/extension-bold": "^3.0.6",
     "@tiptap/extension-document": "^3.0.6",
+    "@tiptap/extension-history": "^3.0.7",
     "@tiptap/extension-paragraph": "^3.0.6",
     "@tiptap/extension-text": "^3.0.6",
     "@tiptap/extension-underline": "^3.0.6",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 5af5a684..c071f20b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -120,6 +120,9 @@ importers:
       '@tiptap/extension-document':
         specifier: ^3.0.6
         version: 3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))
+      '@tiptap/extension-history':
+        specifier: ^3.0.7
+        version: 3.0.7(@tiptap/extensions@3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))(@tiptap/pm@3.0.6))
       '@tiptap/extension-paragraph':
         specifier: ^3.0.6
         version: 3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))
@@ -5489,6 +5492,11 @@ packages:
     peerDependencies:
       '@tiptap/core': ^3.0.6
 
+  '@tiptap/extension-history@3.0.7':
+    resolution: {integrity: sha512-F+zjS7Wz53sNCWh3KqSAug4/COgxs060tR9up0OXjw7iB3gJz6JMNpGaWmYF5WdOsLxph7FGRMb/Mr5keCqVDA==}
+    peerDependencies:
+      '@tiptap/extensions': ^3.0.7
+
   '@tiptap/extension-horizontal-rule@3.0.6':
     resolution: {integrity: sha512-we803tmjQc7SIxw05DNCjrVg6e+eM8bJNM9qPTU4Uo2PkJxvGPshhhfvCz5wchz2ohL3zjEUKJ1FCB6j6iL2nA==}
     peerDependencies:
@@ -21187,6 +21195,10 @@ snapshots:
     dependencies:
       '@tiptap/core': 3.0.6(@tiptap/pm@3.0.6)
 
+  '@tiptap/extension-history@3.0.7(@tiptap/extensions@3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))(@tiptap/pm@3.0.6))':
+    dependencies:
+      '@tiptap/extensions': 3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))(@tiptap/pm@3.0.6)
+
   '@tiptap/extension-horizontal-rule@3.0.6(@tiptap/core@3.0.6(@tiptap/pm@3.0.6))(@tiptap/pm@3.0.6)':
     dependencies:
       '@tiptap/core': 3.0.6(@tiptap/pm@3.0.6)