1+ import Parchment from 'parchment' ;
12import Block from '../blots/block' ;
23import Container from '../blots/container' ;
3- import Quill from '../core/quill' ;
44
5- class TableContainer extends Container {
5+ class TableCell extends Block {
66 static create ( value ) {
7- const node = super . create ( value ) ;
8- node . setAttribute ( 'contenteditable' , false ) ;
7+ const node = super . create ( ) ;
8+ if ( value && value . row ) {
9+ node . setAttribute ( 'data-row' , value . row ) ;
10+ } else {
11+ node . setAttribute ( 'data-row' , tableId ( ) ) ;
12+ }
13+ node . setAttribute ( 'contenteditable' , true ) ;
914 return node ;
1015 }
11- }
12- TableContainer . blotName = 'table-container' ;
13- TableContainer . tagName = 'TABLE' ;
1416
15- class TableBody extends Container { }
16- TableBody . blotName = 'table-body' ;
17- TableBody . tagName = 'TBODY' ;
17+ static formats ( domNode ) {
18+ if ( domNode . hasAttribute ( 'data-row' ) ) {
19+ return {
20+ row : domNode . getAttribute ( 'data-row' ) ,
21+ } ;
22+ }
23+ return undefined ;
24+ }
25+
26+ table ( ) {
27+ let cur = this . parent ;
28+ while ( cur != null && cur . statics . blotName !== 'table-container' ) {
29+ cur = cur . parent ;
30+ }
31+ return cur ;
32+ }
33+ }
34+ TableCell . blotName = 'table' ;
35+ TableCell . tagName = 'TD' ;
1836
1937class TableRow extends Container {
2038 checkMerge ( ) {
@@ -29,15 +47,14 @@ class TableRow extends Container {
2947TableRow . blotName = 'table-row' ;
3048TableRow . tagName = 'TR' ;
3149
32- class TableCell extends Block {
50+ class TableBody extends Container { }
51+ TableBody . blotName = 'table-body' ;
52+ TableBody . tagName = 'TBODY' ;
53+
54+ class TableContainer extends Container {
3355 static create ( value ) {
34- const node = super . create ( ) ;
35- if ( value && value . row ) {
36- node . setAttribute ( 'data-row' , value . row ) ;
37- } else {
38- node . setAttribute ( 'data-row' , tableId ( ) ) ;
39- }
40- node . setAttribute ( 'contenteditable' , true ) ;
56+ const node = super . create ( value ) ;
57+ node . setAttribute ( 'contenteditable' , false ) ;
4158 return node ;
4259 }
4360
@@ -57,31 +74,10 @@ class TableCell extends Block {
5774 blot . optimize ( ) ; // Add break blot
5875 } ) ;
5976 } ) ;
60- static formats ( domNode ) {
61- if ( domNode . hasAttribute ( 'data-row' ) ) {
62- return {
63- row : domNode . getAttribute ( 'data-row' ) ,
64- } ;
65- }
66- return undefined ;
67- }
68-
69- static register ( ) {
70- Quill . register ( TableRow ) ;
71- Quill . register ( TableBody ) ;
72- Quill . register ( TableContainer ) ;
73- }
74-
75- table ( ) {
76- let cur = this . parent ;
77- while ( cur != null && cur . statics . blotName !== 'table-container' ) {
78- cur = cur . parent ;
79- }
80- return cur ;
8177 }
8278}
83- TableCell . blotName = 'table' ;
84- TableCell . tagName = 'TD ' ;
79+ TableContainer . blotName = 'table-container ' ;
80+ TableContainer . tagName = 'TABLE ' ;
8581
8682TableContainer . allowedChildren = [ TableBody ] ;
8783TableBody . requiredContainer = TableContainer ;
@@ -98,4 +94,4 @@ function tableId() {
9894 . slice ( 4 ) ;
9995}
10096
101- export { TableCell as default , tableId } ;
97+ export { TableCell , TableRow , TableBody , TableContainer , tableId } ;
0 commit comments