Skip to content

Commit

Permalink
Merge pull request #1223 from webkom/support-ins-del-tags
Browse files Browse the repository at this point in the history
Support ins and del tags
  • Loading branch information
ivarnakken authored Sep 12, 2024
2 parents 83ab7ec + 88c604f commit 8ee52f9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webkom/lego-editor",
"version": "2.4.0",
"version": "2.5.0",
"description": "A React editor written in TS with slate.js for lego-webapp",
"type": "module",
"main": "./dist/lego-editor.umd.cjs",
Expand Down
22 changes: 22 additions & 0 deletions src/Editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,25 @@
box-shadow: 0 0 0 1.5px var(--color-gray-7);
transition: box-shadow var(--easing-fast);
}

._legoEditor_inserted,
._legoEditor_deleted {
text-decoration: none;
}

._legoEditor_inserted *,
._legoEditor_deleted * {
border-radius: var(--border-radius-sm);
}

._legoEditor_inserted * {
background-color: var(--color-green-1);
color: var(
--color-green-6
); /* TODO: Replace with var(--success-color) when lego-bricks is updated */
}

._legoEditor_deleted * {
background-color: var(--color-red-1);
color: var(--danger-color);
}
16 changes: 14 additions & 2 deletions src/custom-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export type Elements =
| 'figure'
| 'image'
| 'image_caption'
| 'quote';
| 'quote'
| 'ins'
| 'del';

export type CustomText = { text: string } & {
[key in Mark]?: boolean;
Expand Down Expand Up @@ -75,6 +77,14 @@ export type ListElement = {
type: 'ol_list' | 'ul_list';
children: (ListElement | ListItemElement)[];
};
export type InsertedElement = {
type: 'ins';
children: CustomText[];
};
export type DeletedElement = {
type: 'del';
children: CustomText[];
};

type CustomElement =
| ListElement
Expand All @@ -85,7 +95,9 @@ type CustomElement =
| FigureElement
| QuoteElement
| CodeBlockElement
| LinkElement;
| LinkElement
| InsertedElement
| DeletedElement;

export interface ExtendedEditor extends BaseEditor {
savedSelection?: BaseRange;
Expand Down
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ const renderElement = (props: RenderElementProps): JSX.Element => {
{children}
</a>
);
case 'ins':
return <ins className="_legoEditor_inserted">{children}</ins>;
case 'del':
return <del className="_legoEditor_deleted">{children}</del>;
default:
return <p {...attributes}>{children}</p>;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const TEXT_BLOCKS: Elements[] = [
'paragraph',
'code_block',
'quote',
'ins',
'del',
];

/**
Expand Down
6 changes: 6 additions & 0 deletions src/serializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const ELEMENT_TAGS: TAGS = {
figcaption: 'image_caption',
a: 'link',
blockquote: 'quote',
ins: 'ins',
del: 'del',
};

const MARK_TAGS = {
Expand Down Expand Up @@ -118,6 +120,10 @@ export const serialize = (node: SlateNode): string => {
return `<a ${isInternalLink(node.url) ? '' : 'target="_blank" '}href="${node.url}">${children}</a>`;
case 'quote':
return `<blockquote>${children}</blockquote>`;
case 'ins':
return `<ins>${children}</ins>`;
case 'del':
return `<del>${children}</del>`;
default:
return children;
}
Expand Down

0 comments on commit 8ee52f9

Please sign in to comment.