@@ -33,6 +33,13 @@ export default function renderContainerBlock (parent, block, activeBlocks, match
3333 lang,
3434 column
3535 } = block
36+
37+ if ( type === 'table' ) {
38+ this . renderingTable = block
39+ } else if ( / t h e a d | t b o d y / . test ( type ) ) {
40+ this . renderingRowContainer = block
41+ }
42+
3643 const children = block . children . map ( child => this . renderBlock ( block , child , activeBlocks , matches , useCache ) )
3744 const data = {
3845 attrs : { } ,
@@ -51,8 +58,20 @@ export default function renderContainerBlock (parent, block, activeBlocks, match
5158 Object . assign ( data . attrs , { spellcheck : 'false' } )
5259 }
5360
54- if ( / t h | t d / . test ( type ) ) {
61+ if ( / ^ ( t h | t d ) $ / . test ( type ) ) {
5562 const { cells } = this . muya . contentState . selectedTableCells || { }
63+ if ( align ) {
64+ Object . assign ( data . attrs , {
65+ style : `text-align:${ align } `
66+ } )
67+ }
68+
69+ if ( typeof column === 'number' ) {
70+ Object . assign ( data . dataset , {
71+ column
72+ } )
73+ }
74+
5675 if ( cells && cells . length ) {
5776 const cell = cells . find ( c => c . key === key )
5877 if ( cell ) {
@@ -71,45 +90,29 @@ export default function renderContainerBlock (parent, block, activeBlocks, match
7190 selector += '.ag-cell-border-left'
7291 }
7392 }
74- }
75- }
93+ } else {
94+ // Judge whether to render the table drag bar.
95+ const { renderingTable, renderingRowContainer } = this
7696
77- // Judge whether to render the table drag bar.
78- const { cells } = this . muya . contentState . selectedTableCells || { }
79- if ( / t h | t d / . test ( type ) && ( ! cells || cells && cells . length === 0 ) ) {
80- const table = this . muya . contentState . closest ( block , 'table' )
81- const findTable = activeBlocks . find ( b => b . key === table . key )
82- if ( findTable ) {
83- const { row : tableRow , column : tableColumn } = findTable
84- const isLastRow = ( ) => {
85- const rowContainer = this . muya . contentState . closest ( block , / t b o d y | t h e a d / )
86- if ( rowContainer . type === 'thead' ) {
87- return tableRow === 0
88- } else {
89- return ! parent . nextSibling
97+ const findTable = renderingTable ? activeBlocks . find ( b => b . key === renderingTable . key ) : null
98+ if ( findTable && renderingRowContainer ) {
99+ const { row : tableRow , column : tableColumn } = findTable
100+ const isLastRow = ( ) => {
101+ if ( renderingRowContainer . type === 'thead' ) {
102+ return tableRow === 0
103+ } else {
104+ return ! parent . nextSibling
105+ }
106+ }
107+ if ( block . parent === activeBlocks [ 1 ] . parent && ! block . preSibling && tableRow > 0 ) {
108+ children . unshift ( renderLeftBar ( ) )
90109 }
91- }
92- if ( block . parent === activeBlocks [ 1 ] . parent && ! block . preSibling && tableRow > 0 ) {
93- children . unshift ( renderLeftBar ( ) )
94- }
95110
96- if ( column === activeBlocks [ 1 ] . column && isLastRow ( ) && tableColumn > 0 ) {
97- children . push ( renderBottomBar ( ) )
111+ if ( column === activeBlocks [ 1 ] . column && isLastRow ( ) && tableColumn > 0 ) {
112+ children . push ( renderBottomBar ( ) )
113+ }
98114 }
99115 }
100- }
101-
102- if ( / t h | t d / . test ( type ) ) {
103- if ( align ) {
104- Object . assign ( data . attrs , {
105- style : `text-align:${ align } `
106- } )
107- }
108- if ( typeof column === 'number' ) {
109- Object . assign ( data . dataset , {
110- column
111- } )
112- }
113116 } else if ( / ^ h / . test ( type ) ) {
114117 if ( / ^ h \d $ / . test ( type ) ) {
115118 // TODO: This should be the best place to create and update the TOC.
0 commit comments