Skip to content

Commit

Permalink
fix: read only extensions and write extensions synced
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 committed Jan 6, 2025
1 parent e094b49 commit 61ded96
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 35 deletions.
23 changes: 19 additions & 4 deletions packages/editor/src/core/extensions/extensions.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Extensions } from "@tiptap/core";
import BulletList from "@tiptap/extension-bullet-list";
import CharacterCount from "@tiptap/extension-character-count";
import ListItem from "@tiptap/extension-list-item";
import OrderedList from "@tiptap/extension-ordered-list";
import Placeholder from "@tiptap/extension-placeholder";
import TaskItem from "@tiptap/extension-task-item";
import TaskList from "@tiptap/extension-task-list";
import ListItem from "@tiptap/extension-list-item";
import TextStyle from "@tiptap/extension-text-style";
import TiptapUnderline from "@tiptap/extension-underline";
import StarterKit from "@tiptap/starter-kit";
import BulletList from "@tiptap/extension-bullet-list";
import OrderedList from "@tiptap/extension-ordered-list";
import { Markdown } from "tiptap-markdown";
// extensions
import {
Expand All @@ -32,6 +32,7 @@ import {
TableCell,
TableHeader,
TableRow,
FlatListExtension,
} from "@/extensions";
// helpers
import { isValidHttpUrl } from "@/helpers/common";
Expand All @@ -40,7 +41,6 @@ import { CoreEditorAdditionalExtensions } from "@/plane-editor/extensions";
// types
import { TExtensions, TFileHandler, TMentionHandler } from "@/types";
import { DropCursorExtension } from "./drop-cursor";
import { FlatListExtension } from "./flat-list/list-extension";

type TArguments = {
disabledExtensions: TExtensions[];
Expand Down Expand Up @@ -83,6 +83,9 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
DropCursorExtension,
FlatListExtension,
BulletList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
Expand All @@ -92,6 +95,9 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
},
}),
OrderedList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
Expand All @@ -101,6 +107,9 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
},
}),
ListItem.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
Expand All @@ -110,6 +119,9 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
},
}),
TaskList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
Expand All @@ -119,6 +131,9 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
},
}),
TaskItem.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/core/extensions/flat-list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./list-extension";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Node } from "@tiptap/core";
import { keymap } from "@tiptap/pm/keymap";
import { inputRules } from "@tiptap/pm/inputrules";
import { keymap } from "@tiptap/pm/keymap";
import {
ListAttributes,
IndentListOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/core/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from "./quote";
export * from "./read-only-extensions";
export * from "./side-menu";
export * from "./text-align";
export * from "./flat-list";
104 changes: 74 additions & 30 deletions packages/editor/src/core/extensions/read-only-extensions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Extensions } from "@tiptap/core";
import BulletList from "@tiptap/extension-bullet-list";
import CharacterCount from "@tiptap/extension-character-count";
import ListItem from "@tiptap/extension-list-item";
import OrderedList from "@tiptap/extension-ordered-list";
import TaskItem from "@tiptap/extension-task-item";
import TaskList from "@tiptap/extension-task-list";
import TextStyle from "@tiptap/extension-text-style";
Expand All @@ -24,14 +27,14 @@ import {
CustomTextAlignExtension,
CustomCalloutReadOnlyExtension,
CustomColorExtension,
FlatListExtension,
} from "@/extensions";
// helpers
import { isValidHttpUrl } from "@/helpers/common";
// types
import { TExtensions, TFileHandler, TReadOnlyMentionHandler } from "@/types";
// plane editor extensions
import { CoreReadOnlyEditorAdditionalExtensions } from "@/plane-editor/extensions";
import { FlatListExtension } from "./flat-list/list-extension";
// types
import { TExtensions, TFileHandler, TReadOnlyMentionHandler } from "@/types";

type Props = {
disabledExtensions: TExtensions[];
Expand All @@ -44,21 +47,9 @@ export const CoreReadOnlyEditorExtensions = (props: Props): Extensions => {

return [
StarterKit.configure({
bulletList: {
HTMLAttributes: {
class: "list-disc pl-7 space-y-2",
},
},
orderedList: {
HTMLAttributes: {
class: "list-decimal pl-7 space-y-2",
},
},
listItem: {
HTMLAttributes: {
class: "not-prose space-y-2",
},
},
bulletList: false,
orderedList: false,
listItem: false,
code: false,
codeBlock: false,
horizontalRule: false,
Expand All @@ -76,6 +67,71 @@ export const CoreReadOnlyEditorExtensions = (props: Props): Extensions => {
dropcursor: false,
gapcursor: false,
}),
FlatListExtension,
BulletList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
}).configure({
HTMLAttributes: {
class: "list-disc pl-7 space-y-2",
},
}),
OrderedList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
}).configure({
HTMLAttributes: {
class: "list-decimal pl-7 space-y-2",
},
}),
ListItem.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
}).configure({
HTMLAttributes: {
class: "not-prose space-y-2",
},
}),
TaskList.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
}).configure({
HTMLAttributes: {
class: "not-prose pl-2 space-y-2",
},
}),
TaskItem.extend({
parseHTML() {
return [];
},
addInputRules() {
return [];
},
addKeyboardShortcuts() {
return {};
},
}).configure({
HTMLAttributes: {
class: "relative",
},
nested: true,
}),
CustomQuoteExtension,
CustomHorizontalRule.configure({
HTMLAttributes: {
Expand Down Expand Up @@ -106,17 +162,6 @@ export const CoreReadOnlyEditorExtensions = (props: Props): Extensions => {
}),
TiptapUnderline,
TextStyle,
TaskList.configure({
HTMLAttributes: {
class: "not-prose pl-2 space-y-2",
},
}),
TaskItem.configure({
HTMLAttributes: {
class: "relative pointer-events-none",
},
nested: true,
}),
CustomCodeBlockExtension.configure({
HTMLAttributes: {
class: "",
Expand All @@ -139,6 +184,5 @@ export const CoreReadOnlyEditorExtensions = (props: Props): Extensions => {
...CoreReadOnlyEditorAdditionalExtensions({
disabledExtensions,
}),
FlatListExtension,
];
};

0 comments on commit 61ded96

Please sign in to comment.