-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove deprecated colors from borders, text and background. (#2045)
* Support more border styles * init * Revert unrelated change * Fix dependencies * address comments * try fix build
- Loading branch information
1 parent
7c6a320
commit 0439b5a
Showing
15 changed files
with
901 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 16 additions & 36 deletions
52
...sterjs-content-model-editor/lib/editor/plugins/PastePlugin/utils/deprecatedColorParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
import { chainSanitizerCallback } from 'roosterjs-editor-dom'; | ||
import { HtmlSanitizerOptions } from 'roosterjs-editor-types'; | ||
|
||
const DeprecatedColorList: string[] = [ | ||
'activeborder', | ||
'activecaption', | ||
'appworkspace', | ||
'background', | ||
'buttonhighlight', | ||
'buttonshadow', | ||
'captiontext', | ||
'inactiveborder', | ||
'inactivecaption', | ||
'inactivecaptiontext', | ||
'infobackground', | ||
'infotext', | ||
'menu', | ||
'menutext', | ||
'scrollbar', | ||
'threeddarkshadow', | ||
'threedface', | ||
'threedhighlight', | ||
'threedlightshadow', | ||
'threedfhadow', | ||
'window', | ||
'windowframe', | ||
'windowtext', | ||
]; | ||
import { BorderFormat, FormatParser } from 'roosterjs-content-model-types'; | ||
import { BorderKeys, DeprecatedColors } from 'roosterjs-content-model-dom'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function parseDeprecatedColor(sanitizingOption: Required<HtmlSanitizerOptions>) { | ||
['color', 'background-color'].forEach(property => { | ||
chainSanitizerCallback( | ||
sanitizingOption.cssStyleCallbacks, | ||
property, | ||
(value: string) => DeprecatedColorList.indexOf(value) < 0 | ||
); | ||
export const deprecatedBorderColorParser: FormatParser<BorderFormat> = ( | ||
format: BorderFormat | ||
): void => { | ||
BorderKeys.forEach(key => { | ||
const value = format[key]; | ||
let color: string = ''; | ||
if ( | ||
value && | ||
DeprecatedColors.some(dColor => value.indexOf(dColor) > -1 && (color = dColor)) | ||
) { | ||
const newValue = value.replace(color, '').trimRight(); | ||
format[key] = newValue; | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...del/roosterjs-content-model-editor/test/editor/plugins/paste/deprecatedColorParserTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { deprecatedBorderColorParser } from '../../../../lib/editor/plugins/PastePlugin/utils/deprecatedColorParser'; | ||
|
||
const DeprecatedColors: string[] = [ | ||
'activeborder', | ||
'activecaption', | ||
'appworkspace', | ||
'background', | ||
'buttonhighlight', | ||
'buttonshadow', | ||
'captiontext', | ||
'inactiveborder', | ||
'inactivecaption', | ||
'inactivecaptiontext', | ||
'infobackground', | ||
'infotext', | ||
'menu', | ||
'menutext', | ||
'scrollbar', | ||
'threeddarkshadow', | ||
'threedface', | ||
'threedfhadow', | ||
'threedhighlight', | ||
'threedlightshadow', | ||
'window', | ||
'windowframe', | ||
'windowtext', | ||
]; | ||
|
||
describe('deprecateColorParserTests |', () => { | ||
DeprecatedColors.forEach(color => { | ||
it('Remove ' + color + ' in borderTop', () => { | ||
const format = { borderTop: '1pt solid ' + color }; | ||
|
||
deprecatedBorderColorParser(format, <any>null, <any>null, <any>null); | ||
|
||
expect(format).toEqual({ | ||
borderTop: '1pt solid', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.