-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove table format #2225
Merged
Merged
Remove table format #2225
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f74149b
apply table format fix
juliaroldi 7dce8ed
remove console.log
juliaroldi 34519c3
fix comments
juliaroldi 453c6e1
test
juliaroldi 6c07965
add color spectrum check
juliaroldi 263e6eb
remove empty line
juliaroldi 82b1b5d
Merge branch 'master' into u/julairoldi/fix-table-header-color
juliaroldi 2900d67
Merge branch 'master' into u/julairoldi/fix-table-header-color
juliaroldi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,17 @@ const DARK_COLORS_LIGHTNESS = 20; | |
const BRIGHT_COLORS_LIGHTNESS = 80; | ||
const White = '#ffffff'; | ||
const Black = '#000000'; | ||
const DEFAULT_COLORS = ['rgb(0,0,0', '#000000', '#ffffff', 'rgb(255, 255, 255)']; | ||
|
||
/** | ||
* Set shade color of table cell | ||
* @param cell The cell to set shade color to | ||
* @param color The color to set | ||
* @param isColorOverride @optional When pass true, it means this shade color is not part of table format, so it can be preserved when apply table format | ||
* @param applyToSegments @optional When pass true, we will also apply text color from table cell to its child blocks and segments | ||
* | ||
*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this empty line |
||
export function setTableCellBackgroundColor( | ||
cell: ContentModelTableCell, | ||
color: string | null | undefined, | ||
|
@@ -43,28 +46,63 @@ export function setTableCellBackgroundColor( | |
delete cell.format.textColor; | ||
} | ||
|
||
if (applyToSegments && cell.format.textColor) { | ||
cell.blocks.forEach(block => { | ||
if (block.blockType == 'Paragraph') { | ||
if (applyToSegments) { | ||
setAdaptiveCellColor(cell); | ||
} | ||
} else { | ||
delete cell.format.backgroundColor; | ||
delete cell.format.textColor; | ||
if (applyToSegments) { | ||
removeAdaptiveCellColor(cell); | ||
} | ||
} | ||
|
||
delete cell.cachedElement; | ||
} | ||
|
||
function removeAdaptiveCellColor(cell: ContentModelTableCell) { | ||
cell.blocks.forEach(block => { | ||
if (block.blockType == 'Paragraph') { | ||
if ( | ||
block.segmentFormat?.textColor && | ||
DEFAULT_COLORS.indexOf(block.segmentFormat?.textColor) > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) { | ||
delete block.segmentFormat.textColor; | ||
} | ||
block.segments.forEach(segment => { | ||
if ( | ||
segment.format.textColor && | ||
DEFAULT_COLORS.indexOf(segment.format.textColor) > 0 | ||
) { | ||
delete segment.format.textColor; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function setAdaptiveCellColor(cell: ContentModelTableCell) { | ||
if (cell.format.textColor) { | ||
cell.blocks.forEach(block => { | ||
if (block.blockType == 'Paragraph') { | ||
if (!block.segmentFormat?.textColor) { | ||
block.segmentFormat = { | ||
...block.segmentFormat, | ||
textColor: cell.format.textColor, | ||
}; | ||
block.segments.forEach(segment => { | ||
} | ||
|
||
block.segments.forEach(segment => { | ||
if (!segment.format?.textColor) { | ||
segment.format = { | ||
...segment.format, | ||
textColor: cell.format.textColor, | ||
}; | ||
}); | ||
} | ||
}); | ||
} | ||
} else { | ||
delete cell.format.backgroundColor; | ||
delete cell.format.textColor; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
delete cell.cachedElement; | ||
} | ||
|
||
function calculateLightness(color: string) { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rgb(0,0,0) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need this?
It is possible user's default color is not black/white
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think DEFAULT_COLORS is a bad name. The DEFAULT_COLORS is not the user default color, but the colors that we use when we adapt the text color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are removing the background color, we also need remove this textColor that we added before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, how can we know if this color is added by the code when we add background color, or added by user's manual action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check the color override flag from cell metadata. If there is color override flag, background color is added from table cell shade feature, then text color on table cell is also added there. Otherwise, the text color may be from original table. In that case, should we still change the color?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in this change do you also need to clear that flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid matching text and background colors, I checked if they were equal and also equal to the adaptive text color. I tried metadata approach and it did not work, because it erased the text color when I did these steps: