@@ -963,6 +963,67 @@ describe('Table commands', async () => {
963963
964964 sharedTests ( ) ;
965965 } ) ;
966+
967+ it ( 'targets the inner table when a structuredContentBlock wrapper around it is selected' , async ( ) => {
968+ const { docx, media, mediaFiles, fonts } = cachedBlankDoc ;
969+ ( { editor } = initTestEditor ( { content : docx , media, mediaFiles, fonts } ) ) ;
970+ ( { schema } = editor ) ;
971+
972+ const nilBorders = Object . assign (
973+ { } ,
974+ ...[ 'top' , 'left' , 'bottom' , 'right' ] . map ( ( side ) => ( {
975+ [ side ] : { color : 'auto' , size : 0 , space : 0 , val : 'nil' } ,
976+ } ) ) ,
977+ ) ;
978+
979+ const outerBorders = {
980+ top : { val : 'single' , size : 8 , space : 0 , color : '000000' } ,
981+ bottom : { val : 'single' , size : 8 , space : 0 , color : '000000' } ,
982+ left : { val : 'single' , size : 8 , space : 0 , color : '000000' } ,
983+ right : { val : 'single' , size : 8 , space : 0 , color : '000000' } ,
984+ } ;
985+
986+ const innerTable = createTable ( schema , 2 , 2 , false ) ;
987+ const sdt = schema . nodes . structuredContentBlock . create ( { id : '2001' , tag : 'block_table_sdt' } , [ innerTable ] ) ;
988+ const outerCell = schema . nodes . tableCell . create (
989+ {
990+ tableCellProperties : { borders : outerBorders } ,
991+ tableCellPropertiesInlineKeys : [ 'borders' ] ,
992+ } ,
993+ [ sdt ] ,
994+ ) ;
995+ const outerRow = schema . nodes . tableRow . create ( { paraId : 'A1B2C3D4' } , [ outerCell ] ) ;
996+ const outerTable = schema . nodes . table . create ( { } , [ outerRow ] ) ;
997+ const doc = schema . nodes . doc . create ( null , [ outerTable ] ) ;
998+ editor . setState ( EditorState . create ( { schema, doc, plugins : editor . state . plugins } ) ) ;
999+
1000+ let sdtPos = null ;
1001+ editor . state . doc . descendants ( ( node , pos ) => {
1002+ if ( node . type . name === 'structuredContentBlock' ) {
1003+ sdtPos = pos ;
1004+ return false ;
1005+ }
1006+ return true ;
1007+ } ) ;
1008+ expect ( sdtPos ) . not . toBeNull ( ) ;
1009+
1010+ editor . view . dispatch ( editor . state . tr . setSelection ( NodeSelection . create ( editor . state . doc , sdtPos ) ) ) ;
1011+
1012+ const success = editor . commands . deleteCellAndTableBorders ( editor ) ;
1013+ expect ( success ) . toBe ( true ) ;
1014+
1015+ const updatedOuterTable = editor . state . doc . child ( 0 ) ;
1016+ const updatedOuterCell = updatedOuterTable . firstChild . firstChild ;
1017+ expect ( updatedOuterCell . attrs . tableCellProperties ?. borders ) . toEqual ( outerBorders ) ;
1018+
1019+ const updatedInnerTable = updatedOuterCell . firstChild . firstChild ;
1020+ expect ( updatedInnerTable . type . name ) . toBe ( 'table' ) ;
1021+ updatedInnerTable . forEach ( ( row ) => {
1022+ row . forEach ( ( cell ) => {
1023+ expect ( cell . attrs . tableCellProperties ?. borders ) . toEqual ( nilBorders ) ;
1024+ } ) ;
1025+ } ) ;
1026+ } ) ;
9661027 } ) ;
9671028
9681029 describe ( 'table style normalization' , async ( ) => {
@@ -1305,6 +1366,51 @@ describe('Table commands', async () => {
13051366 expect ( $from . node ( $from . depth - 1 ) . type . spec . tableRole ) . toBe ( 'cell' ) ;
13061367 } ) ;
13071368
1369+ it ( 'inserts the table inside a selected structuredContentBlock instead of creating a sibling block' , async ( ) => {
1370+ const { docx, media, mediaFiles, fonts } = cachedBlankDoc ;
1371+ ( { editor } = initTestEditor ( { content : docx , media, mediaFiles, fonts } ) ) ;
1372+
1373+ const { schema } = editor . state ;
1374+ const emptyParagraph = schema . nodes . paragraph . create ( ) ;
1375+ const sdt = schema . nodes . structuredContentBlock . create ( { id : '1001' , tag : 'block_table_sdt' } , [ emptyParagraph ] ) ;
1376+ const doc = schema . nodes . doc . create ( null , [ sdt ] ) ;
1377+ editor . setState ( EditorState . create ( { schema, doc, plugins : editor . state . plugins } ) ) ;
1378+
1379+ editor . view . dispatch ( editor . state . tr . setSelection ( NodeSelection . create ( editor . state . doc , 0 ) ) ) ;
1380+ editor . commands . insertTable ( { rows : 2 , cols : 2 } ) ;
1381+
1382+ expect ( editor . state . doc . childCount ) . toBe ( 1 ) ;
1383+ expect ( editor . state . doc . child ( 0 ) . type . name ) . toBe ( 'structuredContentBlock' ) ;
1384+
1385+ const insertedSdt = editor . state . doc . child ( 0 ) ;
1386+ expect ( insertedSdt . childCount ) . toBe ( 1 ) ;
1387+ expect ( insertedSdt . child ( 0 ) . type . name ) . toBe ( 'table' ) ;
1388+ } ) ;
1389+
1390+ it ( 'inserts the table inside structuredContentBlock content for text selections' , async ( ) => {
1391+ const { docx, media, mediaFiles, fonts } = cachedBlankDoc ;
1392+ ( { editor } = initTestEditor ( { content : docx , media, mediaFiles, fonts } ) ) ;
1393+
1394+ const { schema } = editor . state ;
1395+ const paragraph = schema . nodes . paragraph . create ( null , schema . text ( 'Hello' ) ) ;
1396+ const sdt = schema . nodes . structuredContentBlock . create ( { id : '1002' , tag : 'block_table_sdt' } , [ paragraph ] ) ;
1397+ const doc = schema . nodes . doc . create ( null , [ sdt ] ) ;
1398+ editor . setState ( EditorState . create ( { schema, doc, plugins : editor . state . plugins } ) ) ;
1399+
1400+ const textSelection = TextSelection . create ( editor . state . doc , 2 , 7 ) ;
1401+ editor . view . dispatch ( editor . state . tr . setSelection ( textSelection ) ) ;
1402+
1403+ editor . commands . insertTable ( { rows : 2 , cols : 2 } ) ;
1404+
1405+ expect ( editor . state . doc . childCount ) . toBe ( 1 ) ;
1406+ expect ( editor . state . doc . child ( 0 ) . type . name ) . toBe ( 'structuredContentBlock' ) ;
1407+
1408+ const insertedSdt = editor . state . doc . child ( 0 ) ;
1409+ expect ( insertedSdt . childCount ) . toBe ( 2 ) ;
1410+ expect ( insertedSdt . child ( 0 ) . type . name ) . toBe ( 'paragraph' ) ;
1411+ expect ( insertedSdt . child ( 1 ) . type . name ) . toBe ( 'table' ) ;
1412+ } ) ;
1413+
13081414 it ( 'places cursor in first cell and adds trailing paragraph when inserting table with AllSelection' , async ( ) => {
13091415 const { docx, media, mediaFiles, fonts } = cachedBlankDoc ;
13101416 ( { editor } = initTestEditor ( { content : docx , media, mediaFiles, fonts } ) ) ;
0 commit comments