1
1
import * as React from 'react' ;
2
2
import { ContextPane , ContextItem , ContextSep } from 'nice-ui/lib/4-card/ContextMenu' ;
3
3
import { useToolbarPlugin } from '../../context' ;
4
+ import { SYMBOL } from 'nano-theme' ;
4
5
import type { Inline , Peritext , Slice } from '../../../../../json-crdt-extensions' ;
5
6
import type { CaretViewProps } from '../../../../web/react/cursor/CaretView' ;
6
- import type { ToolbarSlice , ToolBarSliceRegistryEntry } from '../../types' ;
7
+ import type { Formatting , ToolBarSliceRegistryEntry } from '../../types' ;
7
8
8
- class ToolbarSliceImpl implements ToolbarSlice {
9
+ class FormattingImpl implements Formatting {
9
10
public constructor (
10
11
public readonly slice : Slice < string > ,
11
12
public readonly def : ToolBarSliceRegistryEntry ,
12
13
) { }
13
14
}
14
15
15
- const getConfigurableFormattingItems = ( txt : Peritext , inline ?: Inline ) : ToolbarSliceImpl [ ] => {
16
+ const getConfigurableFormattingItems = ( txt : Peritext , inline ?: Inline ) : Formatting [ ] => {
16
17
const slices = inline ?. p1 . layers ;
17
- const res : ToolbarSlice [ ] = [ ] ;
18
+ const res : Formatting [ ] = [ ] ;
18
19
if ( ! slices ) return res ;
19
20
const registry = txt . editor . getRegistry ( ) ;
20
21
for ( const slice of slices ) {
@@ -24,7 +25,7 @@ const getConfigurableFormattingItems = (txt: Peritext, inline?: Inline): Toolbar
24
25
if ( ! def ) continue ;
25
26
const isConfigurable = ! ! def . schema ;
26
27
if ( ! isConfigurable ) continue ;
27
- res . push ( new ToolbarSliceImpl ( slice , def ) ) ;
28
+ res . push ( new FormattingImpl ( slice , def ) ) ;
28
29
}
29
30
return res ;
30
31
} ;
@@ -48,9 +49,20 @@ export const CaretBottomOverlay: React.FC<CaretBottomOverlayProps> = (props) =>
48
49
const { def, slice} = formatting ;
49
50
const data = def . data ( ) ;
50
51
const menu = data . menu ;
52
+ const previewText = data . previewText ?.( formatting ) || '' ;
53
+ const previewTextFormatted = previewText . length < 20 ? previewText : `${ previewText . slice ( 0 , 20 ) } ${ SYMBOL . ELLIPSIS } ` ;
51
54
return (
52
- < ContextItem inset icon = { menu ?. icon ?.( ) } right = { data . renderIcon ?.( formatting ) } onClick = { ( ) => { } } >
55
+ < ContextItem inset
56
+ icon = { menu ?. icon ?.( ) }
57
+ right = { data . renderIcon ?.( formatting ) }
58
+ onClick = { ( ) => { } }
59
+ >
53
60
{ menu ?. name ?? def . name }
61
+ { ! ! previewTextFormatted && (
62
+ < span style = { { opacity : 0.5 } } >
63
+ { previewTextFormatted }
64
+ </ span >
65
+ ) }
54
66
</ ContextItem >
55
67
) ;
56
68
} ) }
0 commit comments