@@ -97,6 +97,7 @@ import {
97
97
insertListItemAt ,
98
98
insertTemplateAt ,
99
99
} from "~/builder/features/workspace/canvas-tools/outline/block-utils" ;
100
+ import { richTextPlaceholders } from "~/shared/content-model" ;
100
101
101
102
const BindInstanceToNodePlugin = ( {
102
103
refs,
@@ -1024,6 +1025,18 @@ const RichTextContentPlugin = (props: RichTextContentPluginProps) => {
1024
1025
return < RichTextContentPluginInternal { ...props } templates = { templates } /> ;
1025
1026
} ;
1026
1027
1028
+ const getTag = ( instanceId : Instance [ "id" ] ) => {
1029
+ const instances = $instances . get ( ) ;
1030
+ const metas = $registeredComponentMetas . get ( ) ;
1031
+ const instance = instances . get ( instanceId ) ;
1032
+ if ( instance === undefined ) {
1033
+ return ;
1034
+ }
1035
+ const meta = metas . get ( instance . component ) ;
1036
+ const tags = Object . keys ( meta ?. presetStyle ?? { } ) ;
1037
+ return instance . tag ?? tags [ 0 ] ;
1038
+ } ;
1039
+
1027
1040
const RichTextContentPluginInternal = ( {
1028
1041
rootInstanceSelector,
1029
1042
onOpen,
@@ -1136,20 +1149,14 @@ const RichTextContentPluginInternal = ({
1136
1149
1137
1150
if ( event . key === "Backspace" || event . key === "Delete" ) {
1138
1151
if ( $getRoot ( ) . getTextContentSize ( ) === 0 ) {
1139
- const currentInstance = $instances
1140
- . get ( )
1141
- . get ( rootInstanceSelector [ 0 ] ) ;
1142
-
1143
- if ( currentInstance ?. component === "ListItem" ) {
1152
+ const tag = getTag ( rootInstanceSelector [ 0 ] ) ;
1153
+ if ( tag === "li" ) {
1144
1154
onNext ( editor . getEditorState ( ) , { reason : "left" } ) ;
1145
-
1146
1155
const parentInstanceSelector = rootInstanceSelector . slice ( 1 ) ;
1147
1156
const parentInstance = $instances
1148
1157
. get ( )
1149
1158
. get ( parentInstanceSelector [ 0 ] ) ;
1150
-
1151
1159
const isLastChild = parentInstance ?. children . length === 1 ;
1152
-
1153
1160
updateWebstudioData ( ( data ) => {
1154
1161
deleteInstanceMutable (
1155
1162
data ,
@@ -1159,7 +1166,6 @@ const RichTextContentPluginInternal = ({
1159
1166
)
1160
1167
) ;
1161
1168
} ) ;
1162
-
1163
1169
event . preventDefault ( ) ;
1164
1170
return true ;
1165
1171
}
@@ -1185,28 +1191,22 @@ const RichTextContentPluginInternal = ({
1185
1191
1186
1192
if ( menuState === "closed" ) {
1187
1193
if ( event . key === "Enter" && ! event . shiftKey ) {
1188
- // Custom logic if we are editing ListItem
1189
- const currentInstance = $instances
1190
- . get ( )
1191
- . get ( rootInstanceSelector [ 0 ] ) ;
1192
-
1193
- if (
1194
- currentInstance ?. component === "ListItem" &&
1195
- $getRoot ( ) . getTextContentSize ( ) > 0
1196
- ) {
1197
- // Instead of creating block component we need to add a new ListItem
1194
+ // Custom logic if we are editing list item
1195
+ const tag = getTag ( rootInstanceSelector [ 0 ] ) ;
1196
+ if ( tag === "li" && $getRoot ( ) . getTextContentSize ( ) > 0 ) {
1197
+ // Instead of creating block component we need to add a new list item
1198
1198
insertListItemAt ( rootInstanceSelector ) ;
1199
1199
event . preventDefault ( ) ;
1200
1200
return true ;
1201
1201
}
1202
1202
1203
1203
// Check if it pressed on the last line, last symbol
1204
1204
1205
- const allowedComponents = [ "Paragraph " , "Text " , "Heading " ] ;
1205
+ const allowedTags = [ "p " , "h1 " , "h2" , "h3" , "h4" , "h5" , "h6 "] ;
1206
1206
1207
- for ( const component of allowedComponents ) {
1207
+ for ( const tag of allowedTags ) {
1208
1208
const templateSelector = templates . find (
1209
- ( [ instance ] ) => instance . component === component
1209
+ ( [ instance ] ) => getTag ( instance . id ) === tag
1210
1210
) ?. [ 1 ] ;
1211
1211
1212
1212
if ( templateSelector === undefined ) {
@@ -1249,10 +1249,7 @@ const RichTextContentPluginInternal = ({
1249
1249
1250
1250
insertTemplateAt ( templateSelector , rootInstanceSelector , false ) ;
1251
1251
1252
- if (
1253
- currentInstance ?. component === "ListItem" &&
1254
- $getRoot ( ) . getTextContentSize ( ) === 0
1255
- ) {
1252
+ if ( tag === "li" && $getRoot ( ) . getTextContentSize ( ) === 0 ) {
1256
1253
const parentInstanceSelector = rootInstanceSelector . slice ( 1 ) ;
1257
1254
const parentInstance = $instances
1258
1255
. get ( )
@@ -1679,11 +1676,13 @@ export const TextEditor = ({
1679
1676
continue ;
1680
1677
}
1681
1678
const meta = metas . get ( instance . component ) ;
1679
+ const tags = Object . keys ( meta ?. presetStyle ?? { } ) ;
1680
+ const tag = instance . tag ?? tags [ 0 ] ;
1682
1681
1683
1682
// opinionated: Non-collapsed elements without children can act as spacers (they have size for some reason).
1684
1683
if (
1685
1684
// Components with pseudo-elements (e.g., ::marker) that prevent content from collapsing
1686
- meta ?. placeholder === undefined &&
1685
+ richTextPlaceholders . has ( tag ) === false &&
1687
1686
instance ?. children . length === 0
1688
1687
) {
1689
1688
const elt = getElementByInstanceSelector ( nextSelector ) ;
0 commit comments