Skip to content

Commit 993c2f4

Browse files
committed
Support ins and del tags
1 parent 354c8e9 commit 993c2f4

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

src/Editor.css

+15
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,18 @@
129129
box-shadow: 0 0 0 1.5px var(--color-gray-7);
130130
transition: box-shadow var(--easing-fast);
131131
}
132+
133+
._legoEditor_inserted,
134+
._legoEditor_deleted {
135+
text-decoration: none;
136+
}
137+
138+
._legoEditor_inserted * {
139+
background-color: var(--color-green-1);
140+
color: var(--color-green-6);
141+
}
142+
143+
._legoEditor_deleted * {
144+
background-color: var(--color-red-1);
145+
color: var(--danger-color);
146+
}

src/custom-types.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export type Elements =
2929
| 'figure'
3030
| 'image'
3131
| 'image_caption'
32-
| 'quote';
32+
| 'quote'
33+
| 'ins'
34+
| 'del';
3335

3436
export type CustomText = { text: string } & {
3537
[key in Mark]?: boolean;
@@ -75,6 +77,14 @@ export type ListElement = {
7577
type: 'ol_list' | 'ul_list';
7678
children: (ListElement | ListItemElement)[];
7779
};
80+
export type InsertedElement = {
81+
type: 'ins';
82+
children: CustomText[];
83+
};
84+
export type DeletedElement = {
85+
type: 'del';
86+
children: CustomText[];
87+
};
7888

7989
type CustomElement =
8090
| ListElement
@@ -85,7 +95,9 @@ type CustomElement =
8595
| FigureElement
8696
| QuoteElement
8797
| CodeBlockElement
88-
| LinkElement;
98+
| LinkElement
99+
| InsertedElement
100+
| DeletedElement;
89101

90102
export interface ExtendedEditor extends BaseEditor {
91103
savedSelection?: BaseRange;

src/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ const renderElement = (props: RenderElementProps): JSX.Element => {
186186
{children}
187187
</a>
188188
);
189+
case 'ins':
190+
return <ins className="_legoEditor_inserted">{children}</ins>;
191+
case 'del':
192+
return <del className="_legoEditor_deleted">{children}</del>;
189193
default:
190194
return <p {...attributes}>{children}</p>;
191195
}

src/plugins/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const TEXT_BLOCKS: Elements[] = [
9999
'paragraph',
100100
'code_block',
101101
'quote',
102+
'ins',
103+
'del',
102104
];
103105

104106
/**

src/serializer.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const ELEMENT_TAGS: TAGS = {
2424
figcaption: 'image_caption',
2525
a: 'link',
2626
blockquote: 'quote',
27+
ins: 'ins',
28+
del: 'del',
2729
};
2830

2931
const MARK_TAGS = {
@@ -118,6 +120,10 @@ export const serialize = (node: SlateNode): string => {
118120
return `<a ${isInternalLink(node.url) ? '' : 'target="_blank" '}href="${node.url}">${children}</a>`;
119121
case 'quote':
120122
return `<blockquote>${children}</blockquote>`;
123+
case 'ins':
124+
return `<ins>${children}</ins>`;
125+
case 'del':
126+
return `<del>${children}</del>`;
121127
default:
122128
return children;
123129
}

0 commit comments

Comments
 (0)