@@ -4,49 +4,52 @@ Object.defineProperty(exports, "__esModule", {
4
4
value : true
5
5
} ) ;
6
6
7
- var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
7
+ var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ; /**
8
+ * @usage :
9
+ * Editor.addMark(editor,'color', '#f00')
10
+ */
8
11
9
12
var _react = require ( 'react' ) ;
10
13
11
14
var _react2 = _interopRequireDefault ( _react ) ;
12
15
13
16
var _slateHyperscript = require ( 'slate-hyperscript' ) ;
14
17
18
+ var _nextSlatePlugin = require ( '@jswork/next-slate-plugin' ) ;
19
+
20
+ var _nextSlatePlugin2 = _interopRequireDefault ( _nextSlatePlugin ) ;
21
+
15
22
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
16
23
17
- exports . default = {
18
- name : 'color' ,
19
- importer : function importer ( el , children ) {
20
- var nodeName = el . nodeName . toLowerCase ( ) ;
21
- if ( nodeName === 'span' && el . style . color ) {
22
- return ( 0 , _slateHyperscript . jsx ) ( 'text' , { value : el . style . color } , children ) ;
23
- }
24
- } ,
25
- // to-html
26
- exporter : function exporter ( node , children ) {
27
- if ( ! children ) {
28
- if ( node . color ) {
29
- var value = node . color . value ;
24
+ exports . default = _nextSlatePlugin2 . default . define ( {
25
+ id : 'color' ,
26
+ serialize : {
27
+ input : function input ( _ref , children ) {
28
+ var el = _ref . el ;
30
29
31
- return '<span style="color: ' + value + ';">' + node . text + '</span>' ;
30
+ var nodeName = el . nodeName . toLowerCase ( ) ;
31
+ if ( nodeName === 'span' && el . style . color ) {
32
+ return ( 0 , _slateHyperscript . jsx ) ( 'text' , { color : el . style . color } , children ) ;
32
33
}
34
+ } ,
35
+ output : function output ( _ref2 ) {
36
+ var el = _ref2 . el ,
37
+ color = _ref2 . color ;
38
+
39
+ el . style . color = color ;
40
+ return el ;
33
41
}
34
42
} ,
35
- hooks : {
36
- leaf : function leaf ( inContext , _ref ) {
37
- var attributes = _ref . attributes ,
38
- children = _ref . children ,
39
- _leaf = _ref . leaf ;
40
-
41
- if ( _leaf . color ) {
42
- var value = _leaf . color . value ;
43
-
44
- return _react2 . default . createElement (
45
- 'span' ,
46
- _extends ( { } , attributes , { style : { color : value } } ) ,
47
- children
48
- ) ;
49
- }
50
- }
43
+ render : function render ( _ , _ref3 ) {
44
+ var attributes = _ref3 . attributes ,
45
+ children = _ref3 . children ,
46
+ leaf = _ref3 . leaf ;
47
+ var color = leaf . color ;
48
+
49
+ return _react2 . default . createElement (
50
+ 'span' ,
51
+ _extends ( { style : { color : color } } , attributes ) ,
52
+ children
53
+ ) ;
51
54
}
52
- } ;
55
+ } ) ;
0 commit comments