@@ -14,7 +14,7 @@ const stepSize = Facet.define({
14
14
} ,
15
15
} ) ;
16
16
17
- const stripe = Decoration . line ( {
17
+ let stripe = Decoration . line ( {
18
18
attributes : { class : 'cm-zebra-stripe' } ,
19
19
} ) ;
20
20
@@ -57,10 +57,10 @@ const showStripes = ViewPlugin.fromClass(
57
57
} ,
58
58
) ;
59
59
60
- const baseTheme = ( opt : Pick < Partial < ZebraStripesOptions > , 'lightColor' | 'darkColor' > = { } ) => {
60
+ const baseTheme = ( opt : Pick < Partial < ZebraStripesOptions > , 'lightColor' | 'darkColor' | 'className' > = { } ) => {
61
61
return EditorView . baseTheme ( {
62
- ' &light .cm-zebra-stripe' : { backgroundColor : opt . lightColor || '#eef6ff' } ,
63
- ' &dark .cm-zebra-stripe' : { backgroundColor : opt . darkColor || '#3a404d' } ,
62
+ [ ` &light .${ opt . className } ` ] : { backgroundColor : opt . lightColor || '#eef6ff' } ,
63
+ [ ` &dark .${ opt . className } ` ] : { backgroundColor : opt . darkColor || '#3a404d' } ,
64
64
} ) ;
65
65
} ;
66
66
@@ -72,13 +72,18 @@ export type ZebraStripesOptions = {
72
72
* @example `[1,[2,6], 10]`
73
73
*/
74
74
lineNumber ?: ( number | number [ ] ) [ ] | null ;
75
+ /** @default `cm-zebra-stripe` */
76
+ className ?: string ;
75
77
} ;
76
78
77
79
const range = ( start : number , stop : number , step : number ) =>
78
80
Array . from ( { length : ( stop - start ) / step + 1 } , ( _ , i ) => start + i * step ) ;
79
81
80
82
export function zebraStripes ( options : ZebraStripesOptions = { } ) : Extension {
81
- const zebraStripeTheme = baseTheme ( { lightColor : options . lightColor , darkColor : options . darkColor } ) ;
83
+ const { className = 'cm-zebra-stripe' } = options ;
84
+ stripe = Decoration . line ( {
85
+ attributes : { class : className } ,
86
+ } ) ;
82
87
if ( options . lineNumber && Array . isArray ( options . lineNumber ) ) {
83
88
options . step = null ;
84
89
options . lineNumber = options . lineNumber . map ( ( item ) => {
@@ -90,10 +95,14 @@ export function zebraStripes(options: ZebraStripesOptions = {}): Extension {
90
95
} else {
91
96
options . lineNumber = null ;
92
97
}
93
- return [
98
+ const extensions = [
94
99
options . lineNumber === null ? [ ] : lineNumber . of ( options . lineNumber || [ ] ) ,
95
100
options . step === null ? [ ] : stepSize . of ( options . step || 2 ) ,
96
101
showStripes ,
97
- zebraStripeTheme ,
98
102
] ;
103
+ if ( className ) {
104
+ const zebraStripeTheme = baseTheme ( { lightColor : options . lightColor , darkColor : options . darkColor , className } ) ;
105
+ extensions . push ( zebraStripeTheme ) ;
106
+ }
107
+ return extensions ;
99
108
}
0 commit comments