Skip to content

Commit 28322ef

Browse files
author
Rajat
committed
Code mirror compatibility extension for tiptap
1 parent a4efa4a commit 28322ef

8 files changed

Lines changed: 102 additions & 33 deletions

File tree

apps/web/app/(with-contexts)/(with-layout)/blog/[slug]/[id]/client-side-text-renderer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { TextRenderer } from "@courselit/page-blocks";
44
import { ThemeStyle } from "@courselit/page-models";
55
import { TableOfContent } from "@components/table-of-content";
6+
import WidgetErrorBoundary from "@components/public/base-layout/template/widget-error-boundary";
67

78
export default function ClientSideTextRenderer({
89
json,
@@ -14,7 +15,9 @@ export default function ClientSideTextRenderer({
1415
return (
1516
<div className="flex flex-col gap-4">
1617
<TableOfContent json={json} theme={theme} />
17-
<TextRenderer json={json} theme={theme} />
18+
<WidgetErrorBoundary widgetName="text-editor">
19+
<TextRenderer json={json} theme={theme} />
20+
</WidgetErrorBoundary>
1821
</div>
1922
);
2023
}

apps/web/app/(with-contexts)/course/[slug]/[id]/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { getProduct } from "./helpers";
2828
import { getUserProfile } from "@/app/(with-contexts)/helpers";
2929
import { BadgeCheck } from "lucide-react";
3030
import { emptyDoc as TextEditorEmptyDoc } from "@courselit/text-editor";
31+
import WidgetErrorBoundary from "@components/public/base-layout/template/widget-error-boundary";
3132
const { permissions } = UIConstants;
3233

3334
export default function ProductPage(props: {
@@ -130,7 +131,12 @@ export default function ProductPage(props: {
130131
json={descriptionJson}
131132
theme={theme.theme}
132133
/>
133-
<TextRenderer json={descriptionJson} theme={theme.theme} />
134+
<WidgetErrorBoundary widgetName="text-editor">
135+
<TextRenderer
136+
json={descriptionJson}
137+
theme={theme.theme}
138+
/>
139+
</WidgetErrorBoundary>
134140
</div>
135141
</div>
136142
{isEnrolled(product.courseId, profile as Profile) && (

apps/web/components/community/banner.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BUTTON_SAVING, TOAST_TITLE_SUCCESS } from "@ui-config/strings";
99
import { AddressContext } from "@components/contexts";
1010
import type { TextEditorContent } from "@courselit/common-models";
1111
import { Editor, emptyDoc as TextEditorEmptyDoc } from "@courselit/text-editor";
12+
import WidgetErrorBoundary from "@components/public/base-layout/template/widget-error-boundary";
1213

1314
interface BannerComponentProps {
1415
canEdit: boolean;
@@ -78,14 +79,16 @@ export default function Banner({
7879
<>
7980
<AlertDescription>
8081
{isTextEditorNonEmpty(bannerText) ? (
81-
<TextRenderer
82-
json={
83-
bannerText as unknown as Record<
84-
string,
85-
unknown
86-
>
87-
}
88-
/>
82+
<WidgetErrorBoundary widgetName="text-editor">
83+
<TextRenderer
84+
json={
85+
bannerText as unknown as Record<
86+
string,
87+
unknown
88+
>
89+
}
90+
/>
91+
</WidgetErrorBoundary>
8992
) : (
9093
canEdit && (
9194
<div className="flex items-center space-x-2 text-muted-foreground">

apps/web/components/community/info.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from "@components/ui/dialog";
3535
import { COMMUNITY_SETTINGS, TOAST_TITLE_SUCCESS } from "@ui-config/strings";
3636
import { Share2 } from "lucide-react";
37+
import WidgetErrorBoundary from "@components/public/base-layout/template/widget-error-boundary";
3738
const { permissions } = UIConstants;
3839

3940
interface CommunityInfoProps {
@@ -124,10 +125,12 @@ export function CommunityInfo({
124125
<div className="space-y-2">
125126
<div className="text-sm text-muted-foreground">
126127
{description && (
127-
<TextRenderer
128-
json={description}
129-
theme={theme.theme}
130-
/>
128+
<WidgetErrorBoundary widgetName="text-editor">
129+
<TextRenderer
130+
json={description}
131+
theme={theme.theme}
132+
/>
133+
</WidgetErrorBoundary>
131134
)}
132135
</div>
133136
<p className="text-sm">

apps/web/components/public/lesson-viewer/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { isEnrolled } from "../../../ui-lib/utils";
3838
import LessonEmbedViewer from "./embed-viewer";
3939
import QuizViewer from "./quiz-viewer";
4040
import { getUserProfile } from "@/app/(with-contexts)/helpers";
41+
import WidgetErrorBoundary from "../base-layout/template/widget-error-boundary";
4142

4243
interface CaptionProps {
4344
text: string;
@@ -299,14 +300,16 @@ export const LessonViewer = ({
299300
{String.prototype.toUpperCase.call(LESSON_TYPE_TEXT) ===
300301
lesson.type &&
301302
lesson.content && (
302-
<TextRenderer
303-
json={
304-
lesson.content as unknown as Record<
305-
string,
306-
unknown
307-
>
308-
}
309-
/>
303+
<WidgetErrorBoundary widgetName="text-editor">
304+
<TextRenderer
305+
json={
306+
lesson.content as unknown as Record<
307+
string,
308+
unknown
309+
>
310+
}
311+
/>
312+
</WidgetErrorBoundary>
310313
)}
311314
{String.prototype.toUpperCase.call(
312315
LESSON_TYPE_EMBED,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This is only to maintain backward compatibility for codeMirror node type
2+
3+
import { Node } from "@tiptap/core";
4+
5+
export const CodeMirrorNode = Node.create({
6+
name: "codeMirror",
7+
content: "block+",
8+
code: true,
9+
10+
addOptions() {
11+
return {
12+
HTMLAttributes: {},
13+
};
14+
},
15+
16+
parseHTML() {
17+
return [
18+
{
19+
tag: "pre",
20+
},
21+
];
22+
},
23+
24+
renderHTML({ HTMLAttributes }) {
25+
return ["pre", HTMLAttributes, 0];
26+
},
27+
});

packages/text-editor/src/extensions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import css from "highlight.js/lib/languages/css";
2121
import xml from "highlight.js/lib/languages/xml";
2222
import type { Extensions } from "@tiptap/core";
2323
import { createId } from "./create-id";
24+
import { CodeMirrorNode } from "./components/custom-code-mirror";
2425

2526
lowlight.registerLanguage("javascript", javascript);
2627
lowlight.registerLanguage("typescript", typescript);
@@ -92,4 +93,5 @@ export const createExtensions = ({
9293
},
9394
}),
9495
Highlight,
96+
CodeMirrorNode,
9597
];

pnpm-lock.yaml

Lines changed: 33 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)