Skip to content

Commit c41ac57

Browse files
ianeli1juliaroldiJiuqingSongshaipetelAndres-CT98
authored
Bump Rooster to 8.43.0, Content Model to 0.1.2 (#1604)
* convert alpha to decimals * fix auto format list * add null and refactor * Content Model Selection API step 4: Refactor existing table API (#1479) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Support element with namespace (#1489) * Content Model: Fix a bug when process margin (#1493) * Fix margin issue * Fix test * Fix A tag without href (#1495) * Fix Cut/Copy page scroll issue (#1496) * Fix Cut/Copy page scroll issue * Fix test * fix image plugin z-index calc * Content Model Format State Step 1: Refactor formatSegmentWithContentModel() (#1490) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Format state step 1 * Improve * update condition per comments * Content Model Format State Step 2: Allow retrieving metadata directly (#1491) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Format state step 1 * FormatState step 2 * Improve * Content Model Format State Step 3: Add getFormatState API and ContentModelPlugin (#1492) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Format state step 1 * FormatState step 2 * FormatState step 3: Add getFormatState API and ContentModel plugin * Improve * Improve * Improve * fix test * improve, fix safari issue * fix test * wip * WIP * wip * Content Model: Add API clearFormat (#1497) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Format state step 1 * FormatState step 2 * FormatState step 3: Add getFormatState API and ContentModel plugin * Improve * Content Model: clearFormat * fix build * Improve * Improve * fix test * improve, fix safari issue * fix test * remove wrapper when content change * fix * Content Model: Move format API: link, image, captalization, ... (#1506) * Selection API step 1 * Selection API 2 * New selection API * Refactor table API * add test * Format state step 1 * FormatState step 2 * FormatState step 3: Add getFormatState API and ContentModel plugin * Improve * Content Model: clearFormat * fix build * Improve * Improve * fix test * improve, fix safari issue * fix test * ContentModel: Support insertLink and removeLink * changeCapitalization and setImageAltText * fix for image selection * refactor * refactor * Test image edit with ShadowDOM * improve * Fix #1509 (#1511) * ContentModel: Improve Divider (#1513) * ContentModel: Improve Divider * Add BorderFormat to ContentModelBlockFormat * Add test * fix build * Content Model: Support "no color" when set color (#1514) * Content Model: Support "no color" when set color * improve * Content Model: Use Entity handle readonly element (#1515) * image wrapper using shadow dom * Content Model: Support get and apply segment format (#1518) * Do not merge table when insert a table (#1519) * wip * Content Model: Fix #1239 (#1521) * WIP AND fix for span height * stop dragging * comment * prototype * remove change * prevent drag * remove new max-width * Load fluent ui from cdnjs (#1525) * small changes * Content Model: Improve selection (#1526) * Apply format to word where cursor is located (#1367) * attempt with traversers * attempt using splitTextNode * Return to original implementation * Fix build * implementation with content model * Implement word selection with new content model * removed selectWordFromCollapsedRange.ts * optimization fixes and file changes * standardize function and remove castings * fix paragraph and pending state * fix pending state, name change * Added test cases, disabled end or start of word * fixed dependency * fix pending state * more tests * fixed tests * End of word format fix (#1528) * End of word format fix Fix scenario where format was wrongly applied where the cursor was located at the end of a word * add tests * Variable based dark color (#1531) * Variable based dark color * fix test * improve * Improve * Fix comment * Fix #1532: Support isCode in FormatState (#1533) * Fix #1532 * add comment * fix build * fix comment * Bump ua-parser-js from 0.7.31 to 0.7.33 (#1535) Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.31 to 0.7.33. - [Release notes](https://github.com/faisalman/ua-parser-js/releases) - [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md) - [Commits](faisalman/ua-parser-js@0.7.31...0.7.33) --- updated-dependencies: - dependency-name: ua-parser-js dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix #1529 #1530 and 187095 (#1534) * WIP * test and fixes * unit tests * fix list trigger * Content Model: Adjust selection for link to select a word (#1538) * Content Model: Adjust word selection for link * add test * fix build * Fix table format (#1541) * refactor * move comment * Content Model code simplify 1 (#1544) * Content Model code simplify 2: Clean up EditorContext (#1545) * Content Model code simplify 1 * Content Model: Clean up EditorContext * improve * Content Model code simplify 3: Remove get/setPendingFormat from editor interface (#1546) * Content Model code simplify 1 * Content Model: Clean up EditorContext * improve * Content Model: Remove get/setPendingFormat * Add support for paragraph line spacing for content model (#1543) * Fetch line height from children * Create new content model api * Spacing btn * Fix tests * Remove key from roosterjs-react * testing * Allow segment to hold lineHeight format * Remove lineHeight from segments whenever possible * Fix imports * Remove normalization * Add todo for edge case * Render segment line height * Content Model Editor 1: Rename interface IExperimentalContentModelEditor (#1547) * Content Model code simplify 1 * Content Model: Clean up EditorContext * improve * Content Model: Remove get/setPendingFormat * Content Model: Rename IExperimentalContentModelEditor * fix build * WIP PROTOTYPE * Content Model Editor 2: Publish ContentModelEditor class (#1548) * Content Model code simplify 1 * Content Model: Clean up EditorContext * improve * Content Model: Remove get/setPendingFormat * Content Model: Rename IExperimentalContentModelEditor * Publish ContentModelEditor class * fix build * add test * fix build * fix build * Reorganize Contente Model code (#1555) * blur issue * Fix some block format issues (#1554) * Fix some block format issues * Improve * Content Model: Fix image size for outlook (#1556) * Content Model: Fix image size for outlook * Fix build * fix build * improve * add filter to client rects * Content Model: Support align table to center (#1557) * simply code * Content Model: Fix PRE tag (#1559) * Content Model: Support insert image with src (#1563) * Content Model: Get init segment format from root container (#1567) * Content Model: Get init segment format from root container * Improve * add test * Add missing setSpacing comment (#1564) * do not call updateHandle * check viewport * Content Model: Improve pending format implementation (#1570) * Disable list indentation on mac (#1552) * Disable list indentation on mac * Switch to default disabled * Content Model: Improve hyperlink handling (#1569) * Add support for adding/removing space before/after paragraphs in content model (#1565) * Create api for block margins * Create space before after buttons * Update testing * Fix by using decorator * Replace positive value with none * Treat no margin as space removed * Fix testing * Improve tag name selecting * testing * rename and improve logic * Add support for formatState on onClick call * Update button impl * Revert "Update button impl" This reverts commit edce3ad. * Revert "Add support for formatState on onClick call" This reverts commit 3d6b83d. * use getFormatState() * Update test name * Fix a pending format issue in firefox (#1572) * Content Model: Keep root level entity when format with Content Model (#1573) * Content Model: Preserve segment format when insert table (#1574) * delete table * fix enum * refactor * Fix #1585 (#1587) * strict mode * remove file * add zeros * enable strict mode * Content Model: Improve clearFormat API (#1579) * Content Model: Improve clearFormat * Improve * Improve * fix build * improve * WIP * Content Model: Improve getFormatState (#1594) * Fix color issue with Font tag (#1595) * refactor * Fix #1586 (#1597) * Add `dir` and `textAlign` in `FormatState` (#1590) Co-authored-by: Echo Li <yalinli@microsoft.com> * uncoment * Step 1: Add HTMLSpanElements around ReadOnly Inline entities to prevent cursor issues, (#1580) * init * add tests and build fixes * Fix failing tests in EntityPlugin * Fix comments * Fix comments * Move functionality to insertEntity * typedoc * refactor * refactor * add tests * Content Model: Improve pending format behavior (#1598) * Improve pending format behavior * fix test * Add flight check in InsertEntity #1602 * Improve PRE again (#1601) * Bump versions to 8.43.0 * Bump content model * Remove duplicate implementation * Change content model version to 0.2.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Júlia Roldi <juliaroldi@microsoft.com> Co-authored-by: Jiuqing Song <jisong@microsoft.com> Co-authored-by: Julia Roldi <87443959+juliaroldi@users.noreply.github.com> Co-authored-by: Shai Petel <shai@kwizcom.com> Co-authored-by: Shai Petel <shai@petel.com> Co-authored-by: Andres-CT98 <107568016+Andres-CT98@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Echo-az <63284518+Echo-az@users.noreply.github.com> Co-authored-by: Echo Li <yalinli@microsoft.com> Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>
1 parent e53b232 commit c41ac57

78 files changed

Lines changed: 2060 additions & 646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/scripts/controls/sidePane/editorOptions/ContentEditFeatures.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const EditFeatureDescriptionMap: Record<keyof ContentEditFeatureSettings, string
4848
autoNumberingList:
4949
'When press space after an number, a letter or roman number followed by ), ., -, or between parenthesis in an empty line, toggle numbering',
5050
mergeListOnBackspaceAfterList: 'When backspacing between lists, merge the lists',
51+
deleteTableWithBackspace: 'Delete table with backspace key with whole table is selected',
5152
};
5253

5354
export interface ContentEditFeaturessProps {

demo/scripts/controls/sidePane/editorOptions/EditorOptionsPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const initialState: BuildInPluginState = {
3232
ExperimentalFeatures.DefaultFormatInSpan,
3333
ExperimentalFeatures.AutoFormatList,
3434
ExperimentalFeatures.VariableBasedDarkColor,
35+
ExperimentalFeatures.InlineEntityReadOnlyDelimiters,
3536
],
3637
isRtl: false,
3738
};

demo/scripts/controls/sidePane/editorOptions/ExperimentalFeatures.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const FeatureNames: Partial<Record<ExperimentalFeatures, string>> = {
1919
[ExperimentalFeatures.DefaultFormatInSpan]:
2020
'When apply default format when initialize or user type, apply the format on a SPAN element.',
2121
[ExperimentalFeatures.VariableBasedDarkColor]: 'Use variable-based color for dark mode',
22+
[ExperimentalFeatures.DeleteTableWithBackspace]:
23+
'Delete a table selected with the table selector pressing Backspace key',
24+
[ExperimentalFeatures.InlineEntityReadOnlyDelimiters]:
25+
'Add read entities around read only entities to handle browser edge cases.',
2226
};
2327

2428
export default class ExperimentalFeaturesPane extends React.Component<

demo/scripts/controls/sidePane/snapshot/SnapshotPane.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class SnapshotPane extends React.Component<SnapshotPaneProps, Sna
4343
this.props.onRestoreSnapshot({
4444
html: this.textarea.value,
4545
metadata: null,
46+
knownColors: [],
4647
})
4748
}>
4849
{'Restore snapshot'}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "roosterjs",
3-
"version": "8.42.0",
3+
"version": "8.43.0",
44
"description": "Framework-independent javascript editor",
55
"repository": {
66
"type": "git",

packages/roosterjs-content-model/lib/formatHandlers/block/whiteSpaceFormatHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export const whiteSpaceFormatHandler: FormatHandler<WhiteSpaceFormat> = {
1616
if (format.whiteSpace == 'pre') {
1717
const pre = element.ownerDocument.createElement('pre');
1818

19+
pre.style.marginTop = '0';
20+
pre.style.marginBottom = '0';
21+
1922
element.parentNode?.appendChild(pre);
2023
pre.appendChild(element);
2124
} else if (format.whiteSpace) {

packages/roosterjs-content-model/lib/formatHandlers/utils/color.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DarkColorHandler, DarkModeDatasetNames } from 'roosterjs-editor-types';
2+
import { getTagOfNode } from 'roosterjs-editor-dom';
23

34
/**
45
* @internal
@@ -26,6 +27,8 @@ export function getColor(
2627

2728
if (!color) {
2829
color =
30+
(darkColorHandler &&
31+
tryGetFontColor(element, isDarkMode, darkColorHandler, isBackground)) ||
2932
(isBackground ? element.style.backgroundColor : element.style.color) ||
3033
element.getAttribute(isBackground ? 'bgcolor' : 'color') ||
3134
undefined;
@@ -73,3 +76,26 @@ export function setColor(
7376
element.style.color = effectiveColor;
7477
}
7578
}
79+
80+
/**
81+
* There is a known issue that when input with IME in Chrome, it is possible Chrome insert a new FONT tag with colors.
82+
* If editor is in dark mode, this color will cause the FONT tag doesn't have light mode color info so that after convert
83+
* to light mode the color will be wrong.
84+
* To workaround it, we check if this is a known color (for light mode with VariableBasedDarkColor enabled, all used colors
85+
* are stored in darkColorHandler), then use the related light mode color instead.
86+
*/
87+
function tryGetFontColor(
88+
element: HTMLElement,
89+
isDarkMode: boolean,
90+
darkColorHandler: DarkColorHandler,
91+
isBackground: boolean
92+
) {
93+
let darkColor: string | null;
94+
95+
return getTagOfNode(element) == 'FONT' &&
96+
!element.style.getPropertyValue(isBackground ? 'background-color' : 'color') &&
97+
isDarkMode &&
98+
(darkColor = element.getAttribute(isBackground ? 'bgcolor' : 'color'))
99+
? darkColorHandler.findLightColorFromDarkColor(darkColor)
100+
: null;
101+
}

packages/roosterjs-content-model/lib/modelApi/common/clearModelFormat.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { adjustWordSelection } from '../selection/adjustWordSelection';
12
import { applyTableFormat } from '../table/applyTableFormat';
23
import { arrayPush } from 'roosterjs-editor-dom';
34
import { ContentModelBlock } from '../../publicTypes/block/ContentModelBlock';
@@ -39,27 +40,39 @@ export function clearModelFormat(
3940
}
4041
},
4142
{
42-
includeListFormatHolder: 'anySegment',
43+
// When there is a default format to apply, we know how to handle segment format under list.
44+
// So no need to clear format of list number.
45+
// Otherwise, we will clear all format of selected text. And since they are under LI tag, we
46+
// also need to clear the format of LI (format holder) so that the format is really cleared
47+
includeListFormatHolder: defaultSegmentFormat ? 'never' : 'anySegment',
4348
}
4449
);
4550

46-
// If a full block or multiple blocks are selected, clear block format first
51+
const marker = segmentsToClear[0];
52+
53+
// 2. If selection is collapsed, add selection to whole word to clear if any
4754
if (
48-
(blocksToClear.length == 1 && isOnlySelectionMarkerSelected(blocksToClear[0][1])) ||
49-
blocksToClear.length > 1 ||
50-
blocksToClear.some(x => isWholeBlockSelected(x[1]))
55+
blocksToClear.length == 1 &&
56+
isOnlySelectionMarkerSelected(blocksToClear[0][1]) &&
57+
blocksToClear.length == 1
5158
) {
59+
segmentsToClear.splice(0, segmentsToClear.length, ...adjustWordSelection(model, marker));
60+
clearListFormat(blocksToClear[0][0]);
61+
} else if (blocksToClear.length > 1 || blocksToClear.some(x => isWholeBlockSelected(x[1]))) {
62+
// 2. If a full block or multiple blocks are selected, clear block format
5263
for (let i = blocksToClear.length - 1; i >= 0; i--) {
5364
const [path, block] = blocksToClear[i];
5465

55-
clearBlockFormat(path, block, segmentsToClear);
66+
clearBlockFormat(path, block);
5667
clearListFormat(path);
5768
clearQuoteFormat(path, block);
5869
}
5970
}
6071

61-
// Then clear segments format and table format if any
72+
// 3. Finally clear format for segments
6273
clearSegmentsFormat(segmentsToClear, defaultSegmentFormat);
74+
75+
// 4. Clear format for table if any
6376
createTablesFormat(tablesToClear);
6477
}
6578

@@ -84,7 +97,10 @@ function clearSegmentsFormat(
8497
) {
8598
segmentsToClear.forEach(x => {
8699
x.format = { ...(defaultSegmentFormat || {}) };
87-
delete x.link;
100+
101+
if (x.link) {
102+
delete x.link.format.textColor;
103+
}
88104
});
89105
}
90106

@@ -139,19 +155,14 @@ function clearListFormat(path: ContentModelBlockGroup[]) {
139155
}
140156
}
141157

142-
function clearBlockFormat(
143-
path: ContentModelBlockGroup[],
144-
block: ContentModelBlock,
145-
segmentsToClear: ContentModelSegment[]
146-
) {
158+
function clearBlockFormat(path: ContentModelBlockGroup[], block: ContentModelBlock) {
147159
if (block.blockType == 'Divider') {
148160
const index = path[0].blocks.indexOf(block);
149161

150162
if (index >= 0) {
151163
path[0].blocks.splice(index, 1);
152164
}
153165
} else if (block.blockType == 'Paragraph') {
154-
arrayPush(segmentsToClear, block.segments);
155166
block.format = {};
156167
delete block.decorator;
157168
}

packages/roosterjs-content-model/lib/modelApi/common/mergeModel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export interface MergeModelOption {
2525
* @default false
2626
*/
2727
mergeTable?: boolean;
28+
29+
/**
30+
* Use this insert position to merge instead of querying selection from target model
31+
* @default undefined
32+
*/
33+
insertPosition?: InsertPosition;
2834
}
2935

3036
/**
@@ -35,7 +41,7 @@ export function mergeModel(
3541
source: ContentModelDocument,
3642
options?: MergeModelOption
3743
) {
38-
const insertPosition = deleteSelection(target);
44+
const insertPosition = options?.insertPosition ?? deleteSelection(target);
3945

4046
if (insertPosition) {
4147
for (let i = 0; i < source.blocks.length; i++) {
@@ -140,7 +146,7 @@ function mergeTable(
140146
}
141147
}
142148

143-
normalizeTable(table);
149+
normalizeTable(table, markerPosition.marker.format);
144150
applyTableFormat(table, undefined /*newFormat*/, true /*keepCellShade*/);
145151
} else {
146152
insertBlock(markerPosition, newTable);

0 commit comments

Comments
 (0)