Skip to content

Commit 1b21897

Browse files
anaisbergSimonClo
authored andcommitted
🚧 create block
1 parent 62433ef commit 1b21897

File tree

11 files changed

+144
-13
lines changed

11 files changed

+144
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to
1111
### Added
1212

1313
- ✨(frontend) add customization for translations #857
14+
- ✨(frontend) Add a custom database block to the editor #1053
1415

1516
## [3.3.0] - 2025-05-06
1617

@@ -37,21 +38,20 @@ and this project adheres to
3738
- ⬆️(docker) upgrade node images to alpine 3.21 #973
3839

3940
### Fixed
41+
4042
- 🐛(y-provider) increase JSON size limits for transcription conversion #989
4143

4244
### Removed
4345

4446
- 🔥(back) remove footer endpoint #948
4547

46-
4748
## [3.2.1] - 2025-05-06
4849

4950
## Fixed
5051

5152
- 🐛(frontend) fix list copy paste #943
5253
- 📝(doc) update contributing policy (commit signatures are now mandatory) #895
5354

54-
5555
## [3.2.0] - 2025-05-05
5656

5757
## Added
@@ -62,7 +62,7 @@ and this project adheres to
6262
- ✨(settings) Allow configuring PKCE for the SSO #886
6363
- 🌐(i18n) activate chinese and spanish languages #884
6464
- 🔧(backend) allow overwriting the data directory #893
65-
- ➕(backend) add `django-lasuite` dependency #839
65+
- ➕(backend) add `django-lasuite` dependency #839
6666
- ✨(frontend) advanced table features #908
6767

6868
## Changed
@@ -113,7 +113,6 @@ and this project adheres to
113113
- 🐛(backend) compute ancestor_links in get_abilities if needed #725
114114
- 🔒️(back) restrict access to document accesses #801
115115

116-
117116
## [2.6.0] - 2025-03-21
118117

119118
## Added
@@ -132,7 +131,6 @@ and this project adheres to
132131
- 🔒️(back) throttle user list endpoint #636
133132
- 🔒️(back) remove pagination and limit to 5 for user list endpoint #636
134133

135-
136134
## [2.5.0] - 2025-03-18
137135

138136
## Added
@@ -155,15 +153,14 @@ and this project adheres to
155153
## Fixed
156154

157155
- 🐛(frontend) SVG export #706
158-
- 🐛(frontend) remove scroll listener table content #688
156+
- 🐛(frontend) remove scroll listener table content #688
159157
- 🔒️(back) restrict access to favorite_list endpoint #690
160-
- 🐛(backend) refactor to fix filtering on children
161-
and descendants views #695
158+
- 🐛(backend) refactor to fix filtering on children
159+
and descendants views #695
162160
- 🐛(action) fix notify-argocd workflow #713
163161
- 🚨(helm) fix helmfile lint #736
164162
- 🚚(frontend) redirect to 401 page when 401 error #759
165163

166-
167164
## [2.4.0] - 2025-03-06
168165

169166
## Added
@@ -178,7 +175,6 @@ and this project adheres to
178175

179176
- 🐛(frontend) fix collaboration error #684
180177

181-
182178
## [2.3.0] - 2025-03-03
183179

184180
## Added

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import { randomColor } from '../utils';
2727

2828
import { BlockNoteSuggestionMenu } from './BlockNoteSuggestionMenu';
2929
import { BlockNoteToolbar } from './BlockNoteToolBar/BlockNoteToolbar';
30-
import { CalloutBlock, DividerBlock } from './custom-blocks';
30+
import { CalloutBlock, DatabaseBlock, DividerBlock } from './custom-blocks';
3131

3232
export const blockNoteSchema = withPageBreak(
3333
BlockNoteSchema.create({
3434
blockSpecs: {
3535
...defaultBlockSpecs,
3636
callout: CalloutBlock,
37+
database: DatabaseBlock,
3738
divider: DividerBlock,
3839
},
3940
}),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DocsBlockSchema } from '../types';
1313

1414
import {
1515
getCalloutReactSlashMenuItems,
16+
getDatabaseReactSlashMenuItems,
1617
getDividerReactSlashMenuItems,
1718
} from './custom-blocks';
1819

@@ -29,6 +30,7 @@ export const BlockNoteSuggestionMenu = () => {
2930
getDefaultReactSlashMenuItems(editor),
3031
getPageBreakReactSlashMenuItems(editor),
3132
getCalloutReactSlashMenuItems(editor, t, basicBlocksName),
33+
getDatabaseReactSlashMenuItems(editor, t, basicBlocksName),
3234
getDividerReactSlashMenuItems(editor, t, basicBlocksName),
3335
),
3436
query,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-disable react-hooks/rules-of-hooks */
2+
import { defaultProps, insertOrUpdateBlock } from '@blocknote/core';
3+
import { createReactBlockSpec } from '@blocknote/react';
4+
import { TFunction } from 'i18next';
5+
import React, { useEffect } from 'react';
6+
7+
import { Box, Icon } from '@/components';
8+
9+
import { DocsBlockNoteEditor } from '../../types';
10+
11+
export const DatabaseBlock = createReactBlockSpec(
12+
{
13+
type: 'database',
14+
propSchema: {
15+
textAlignment: defaultProps.textAlignment,
16+
backgroundColor: defaultProps.backgroundColor,
17+
},
18+
content: 'inline',
19+
},
20+
{
21+
render: ({ block, editor }) => {
22+
// Temporary: sets a orange background color to a database block when added by
23+
// the user, while keeping the colors menu on the drag handler usable for
24+
// this custom block.
25+
useEffect(() => {
26+
if (
27+
!block.content.length &&
28+
block.props.backgroundColor === 'default'
29+
) {
30+
editor.updateBlock(block, { props: { backgroundColor: 'orange' } });
31+
}
32+
}, [block, editor]);
33+
34+
return (
35+
<Box
36+
$padding="1rem"
37+
$gap="0.625rem"
38+
style={{
39+
flexGrow: 1,
40+
flexDirection: 'row',
41+
}}
42+
>
43+
<Box as="p">🏗️ Database block is in development</Box>{' '}
44+
</Box>
45+
);
46+
},
47+
},
48+
);
49+
50+
export const getDatabaseReactSlashMenuItems = (
51+
editor: DocsBlockNoteEditor,
52+
t: TFunction<'translation', undefined>,
53+
group: string,
54+
) => [
55+
{
56+
title: t('Database'),
57+
onItemClick: () => {
58+
insertOrUpdateBlock(editor, {
59+
type: 'database',
60+
});
61+
},
62+
aliases: ['database', 'encadré', 'hervorhebung', 'benadrukken'],
63+
group,
64+
icon: <Icon iconName="lightbulb" $size="18px" />,
65+
subtext: t('Add a database block'),
66+
},
67+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './CalloutBlock';
22
export * from './DividerBlock';
3+
export * from './DatabaseBlock';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Paragraph, TextRun } from 'docx';
2+
3+
import { DocsExporterDocx } from '../types';
4+
import { docxBlockPropsToStyles } from '../utils';
5+
6+
export const blockMappingDatabaseDocx: DocsExporterDocx['mappings']['blockMapping']['database'] =
7+
(block, exporter) => {
8+
return new Paragraph({
9+
...docxBlockPropsToStyles({}, exporter.options.colors),
10+
spacing: { before: 10, after: 10 },
11+
children: [
12+
new TextRun({
13+
text: ' ',
14+
break: 1,
15+
}),
16+
new TextRun({
17+
text: ' ',
18+
break: 1,
19+
}),
20+
],
21+
});
22+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { StyleSheet, Text, View } from '@react-pdf/renderer';
2+
3+
import { DocsExporterPDF } from '../types';
4+
5+
const styles = StyleSheet.create({
6+
wrapper: {
7+
width: '100%',
8+
display: 'flex',
9+
flexDirection: 'row',
10+
padding: 8,
11+
gap: 4,
12+
},
13+
emoji: {
14+
fontSize: 16,
15+
},
16+
text: {
17+
maxWidth: '94%',
18+
paddingTop: 2,
19+
},
20+
});
21+
22+
export const blockMappingDatabasePDF: DocsExporterPDF['mappings']['blockMapping']['database'] =
23+
() => {
24+
return (
25+
<View wrap={false} style={styles.wrapper}>
26+
<Text debug={false} style={styles.text}>
27+
{' '}
28+
</Text>
29+
</View>
30+
);
31+
};

src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from './calloutDocx';
22
export * from './calloutPDF';
3+
export * from './databaseDocx';
4+
export * from './databasePDF';
35
export * from './dividerDocx';
46
export * from './dividerPDF';
57
export * from './headingPDF';

src/frontend/apps/impress/src/features/docs/doc-export/mappingDocx.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { BlockMapping } from '@blocknote/core';
12
import { docxDefaultSchemaMappings } from '@blocknote/xl-docx-exporter';
23

34
import {
45
blockMappingCalloutDocx,
6+
blockMappingDatabaseDocx,
57
blockMappingDividerDocx,
68
blockMappingImageDocx,
79
blockMappingQuoteDocx,
@@ -14,7 +16,8 @@ export const docxDocsSchemaMappings: DocsExporterDocx['mappings'] = {
1416
...docxDefaultSchemaMappings.blockMapping,
1517
callout: blockMappingCalloutDocx,
1618
divider: blockMappingDividerDocx,
19+
database: blockMappingDatabaseDocx,
1720
quote: blockMappingQuoteDocx,
1821
image: blockMappingImageDocx,
19-
},
22+
} as BlockMapping<any, any, any, any, any>, // eslint-disable-line @typescript-eslint/no-explicit-any
2023
};

src/frontend/apps/impress/src/features/docs/doc-export/mappingPDF.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { BlockMapping } from '@blocknote/core';
12
import { pdfDefaultSchemaMappings } from '@blocknote/xl-pdf-exporter';
23

34
import {
45
blockMappingCalloutPDF,
6+
blockMappingDatabasePDF,
57
blockMappingDividerPDF,
68
blockMappingHeadingPDF,
79
blockMappingImagePDF,
@@ -16,11 +18,12 @@ export const pdfDocsSchemaMappings: DocsExporterPDF['mappings'] = {
1618
blockMapping: {
1719
...pdfDefaultSchemaMappings.blockMapping,
1820
callout: blockMappingCalloutPDF,
21+
database: blockMappingDatabasePDF, // TODO: create Db block
1922
heading: blockMappingHeadingPDF,
2023
image: blockMappingImagePDF,
2124
paragraph: blockMappingParagraphPDF,
2225
divider: blockMappingDividerPDF,
2326
quote: blockMappingQuotePDF,
2427
table: blockMappingTablePDF,
25-
},
28+
} as BlockMapping<any, any, any, any, any>, // eslint-disable-line @typescript-eslint/no-explicit-any
2629
};

0 commit comments

Comments
 (0)