Skip to content

Commit 470be53

Browse files
committed
🚚(docs-package) move Divider in docs package
Move the Divider custom block to the common package. It will be needed in multiple places, Docs app and the y-provider server.
1 parent a0c7550 commit 470be53

File tree

6 files changed

+68
-59
lines changed

6 files changed

+68
-59
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BlockNoteView } from '@blocknote/mantine';
1111
import '@blocknote/mantine/style.css';
1212
import { useCreateBlockNote } from '@blocknote/react';
1313
import { HocuspocusProvider } from '@hocuspocus/provider';
14+
import { createDividerBlock } from 'package-docs';
1415
import { useEffect } from 'react';
1516
import { useTranslation } from 'react-i18next';
1617
import * as Y from 'yjs';
@@ -33,7 +34,7 @@ import { randomColor } from '../utils';
3334

3435
import { BlockNoteSuggestionMenu } from './BlockNoteSuggestionMenu';
3536
import { BlockNoteToolbar } from './BlockNoteToolBar/BlockNoteToolbar';
36-
import { CalloutBlock, DividerBlock } from './custom-blocks';
37+
import { CalloutBlock } from './custom-blocks';
3738
import {
3839
InterlinkingLinkInlineContent,
3940
InterlinkingSearchInlineContent,
@@ -49,7 +50,9 @@ const baseBlockNoteSchema = withPageBreak(
4950
blockSpecs: {
5051
...defaultBlockSpecs,
5152
callout: CalloutBlock,
52-
divider: DividerBlock,
53+
divider: createDividerBlock({
54+
color: 'var(--c--theme--colors--greyscale-300)',
55+
}),
5356
},
5457
inlineContentSpecs: {
5558
...defaultInlineContentSpecs,

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteSuggestionMenu.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import {
66
useBlockNoteEditor,
77
useDictionary,
88
} from '@blocknote/react';
9+
import { getDividerReactSlashMenuItems } from 'package-docs';
910
import React, { useMemo } from 'react';
1011
import { useTranslation } from 'react-i18next';
1112

13+
import { Icon } from '@/components';
14+
1215
import {
1316
DocsBlockSchema,
1417
DocsInlineContentSchema,
1518
DocsStyleSchema,
1619
} from '../types';
1720

18-
import {
19-
getCalloutReactSlashMenuItems,
20-
getDividerReactSlashMenuItems,
21-
} from './custom-blocks';
21+
import { getCalloutReactSlashMenuItems } from './custom-blocks';
2222
import { useGetInterlinkingMenuItems } from './custom-inline-content';
2323
import XLMultiColumn from './xl-multi-column';
2424

@@ -55,7 +55,12 @@ export const BlockNoteSuggestionMenu = () => {
5555
getCalloutReactSlashMenuItems(editor, t, basicBlocksName),
5656
getMultiColumnSlashMenuItems?.(editor) || [],
5757
getPageBreakReactSlashMenuItems(editor),
58-
getDividerReactSlashMenuItems(editor, t, basicBlocksName),
58+
getDividerReactSlashMenuItems(
59+
editor,
60+
t,
61+
basicBlocksName,
62+
<Icon iconName="remove" $size="18px" />,
63+
),
5964
),
6065
query,
6166
),

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DividerBlock.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './CalloutBlock';
2-
export * from './DividerBlock';
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { BlockNoteEditor, insertOrUpdateBlock } from '@blocknote/core';
2+
import { createReactBlockSpec } from '@blocknote/react';
3+
import { TFunction } from 'i18next';
4+
5+
interface DividerBlockProps {
6+
color?: string;
7+
}
8+
9+
export const createDividerBlock = ({ color }: DividerBlockProps) => {
10+
return createReactBlockSpec(
11+
{
12+
type: 'divider',
13+
propSchema: {},
14+
content: 'none',
15+
},
16+
{
17+
render: () => {
18+
return (
19+
<hr
20+
style={{
21+
width: '100%',
22+
background: color,
23+
margin: '1rem 0',
24+
border: `1px solid ${color}`,
25+
}}
26+
/>
27+
);
28+
},
29+
},
30+
);
31+
};
32+
33+
export const getDividerReactSlashMenuItems = (
34+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35+
editor: BlockNoteEditor<any, any, any>,
36+
t: TFunction<'translation', undefined>,
37+
group: string,
38+
icon: React.ReactNode,
39+
) => [
40+
{
41+
title: t('Divider'),
42+
onItemClick: () => {
43+
insertOrUpdateBlock(editor, {
44+
type: 'divider',
45+
});
46+
},
47+
aliases: ['divider', 'hr', 'horizontal rule', 'line', 'separator'],
48+
group,
49+
icon,
50+
subtext: t('Add a horizontal line'),
51+
},
52+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './DividerBlock';

0 commit comments

Comments
 (0)