@@ -13,14 +13,67 @@ let lastPicked = localStorage.__picker_last_picked || "#fff";
1313function color ( defaultColor , onhide ) {
1414 defaultColor = defaultColor || lastPicked ;
1515 let type = checkColorType ( defaultColor ) || "hex" ;
16- return new Promise ( ( resolve ) => {
16+ return new Promise ( ( resolve , reject ) => {
1717 const colorModes = [ "hsl" , "hex" , "rgb" ] ;
1818 let mode = colorModes . indexOf ( type ) ;
1919 let color = null ;
2020
2121 const parent = tag ( "div" , {
2222 className : "message color-picker" ,
2323 } ) ;
24+
25+ const formatToggle = tag ( "span" , {
26+ className : "format-toggle" ,
27+ onclick : function ( e ) {
28+ e . preventDefault ( ) ;
29+ e . stopPropagation ( ) ;
30+ formatPopup . classList . toggle ( "visible" ) ;
31+ } ,
32+ children : [
33+ tag ( "span" , {
34+ className : "format-toggle-text" ,
35+ textContent : type . toUpperCase ( ) ,
36+ } ) ,
37+ tag ( "span" , {
38+ className : "icon keyboard_arrow_down" ,
39+ } ) ,
40+ ] ,
41+ } ) ;
42+
43+ const formatPopup = tag ( "div" , {
44+ className : "format-popup" ,
45+ children : [
46+ tag ( "div" , {
47+ className : "format-popup-backdrop" ,
48+ onclick : function ( ) {
49+ formatPopup . classList . remove ( "visible" ) ;
50+ } ,
51+ } ) ,
52+ tag ( "div" , {
53+ className : "format-popup-body" ,
54+ children : colorModes . map ( ( m ) =>
55+ tag ( "span" , {
56+ className : `format-option${ m === type ? " active" : "" } ` ,
57+ textContent : m . toUpperCase ( ) ,
58+ onclick : function ( ) {
59+ mode = colorModes . indexOf ( m ) ;
60+ type = m ;
61+ formatToggle . get ( ".format-toggle-text" ) . textContent =
62+ m . toUpperCase ( ) ;
63+ formatPopup . querySelector ( ".active" ) . classList . remove ( "active" ) ;
64+ this . classList . add ( "active" ) ;
65+ formatPopup . classList . remove ( "visible" ) ;
66+ picker . setOptions ( {
67+ color : color || defaultColor ,
68+ editorFormat : type ,
69+ } ) ;
70+ } ,
71+ } ) ,
72+ ) ,
73+ } ) ,
74+ ] ,
75+ } ) ;
76+
2477 const okBtn = tag ( "button" , {
2578 textContent : strings . ok ,
2679 onclick : function ( ) {
@@ -30,39 +83,39 @@ function color(defaultColor, onhide) {
3083 resolve ( color ) ;
3184 } ,
3285 } ) ;
33- const toggleMode = tag ( "button" , {
34- textContent : type ,
35- onclick : function ( e ) {
36- ++ mode ;
37- if ( mode >= colorModes . length ) mode = 0 ;
38- type = colorModes [ mode ] ;
39- this . textContent = type ;
40- picker . setOptions ( {
41- color,
42- editorFormat : type ,
43- } ) ;
44- e . preventDefault ( ) ;
45- e . stopPropagation ( ) ;
46- e . stopImmediatePropagation ( ) ;
86+ const cancelBtn = tag ( "button" , {
87+ textContent : strings . cancel ,
88+ onclick : function ( ) {
89+ hide ( ) ;
90+ reject ( new Error ( "cancelled" ) ) ;
4791 } ,
4892 } ) ;
4993 const box = tag ( "div" , {
5094 className : "prompt box" ,
5195 children : [
52- tag ( "strong " , {
96+ tag ( "div " , {
5397 className : "title" ,
54- textContent : strings [ "choose color" ] ,
98+ children : [
99+ tag ( "span" , {
100+ className : "title-text" ,
101+ textContent : strings [ "choose color" ] ,
102+ } ) ,
103+ formatToggle ,
104+ ] ,
55105 } ) ,
56106 parent ,
57107 tag ( "div" , {
58108 className : "button-container" ,
59- children : [ toggleMode , okBtn ] ,
109+ children : [ cancelBtn , okBtn ] ,
60110 } ) ,
61111 ] ,
62112 } ) ;
63113 const mask = tag ( "span" , {
64114 className : "mask" ,
65- onclick : hide ,
115+ onclick : function ( ) {
116+ hide ( ) ;
117+ reject ( new Error ( "cancelled" ) ) ;
118+ } ,
66119 } ) ;
67120 const picker = new Picker ( {
68121 parent,
@@ -75,10 +128,14 @@ function color(defaultColor, onhide) {
75128 } ) ;
76129
77130 picker . show ( ) ;
131+ parent . append ( formatPopup ) ;
78132
79133 actionStack . push ( {
80134 id : "box" ,
81- action : hideSelect ,
135+ action ( ) {
136+ hide ( ) ;
137+ reject ( new Error ( "cancelled" ) ) ;
138+ } ,
82139 } ) ;
83140
84141 document . body . append ( box , mask ) ;
0 commit comments