Skip to content

Commit

Permalink
Merge branch 'master' into u/acampostams/fix-table-tabbing
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres-CT98 authored Sep 24, 2024
2 parents 2124b6d + e3bc1f3 commit 55fa15e
Show file tree
Hide file tree
Showing 32 changed files with 2,151 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const dropDownMenuItems = {
[BulletListType.LongArrow]: 'LongArrow',
[BulletListType.UnfilledArrow]: 'UnfilledArrow',
[BulletListType.Hyphen]: 'Hyphen',
[BulletListType.DoubleLongArrow]: 'DoubleLongArrow',
[BulletListType.Circle]: 'Circle',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const initialState: OptionState = {
autoHyphen: true,
autoFraction: true,
autoOrdinals: true,
autoMailto: true,
autoTel: true,
},
markdownOptions: {
bold: true,
Expand Down
14 changes: 14 additions & 0 deletions demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export class Plugins extends PluginsBase<keyof BuildInPluginList> {
private autoHyphen = React.createRef<HTMLInputElement>();
private autoFraction = React.createRef<HTMLInputElement>();
private autoOrdinals = React.createRef<HTMLInputElement>();
private autoTel = React.createRef<HTMLInputElement>();
private autoMailto = React.createRef<HTMLInputElement>();
private markdownBold = React.createRef<HTMLInputElement>();
private markdownItalic = React.createRef<HTMLInputElement>();
private markdownStrikethrough = React.createRef<HTMLInputElement>();
Expand Down Expand Up @@ -166,6 +168,18 @@ export class Plugins extends PluginsBase<keyof BuildInPluginList> {
this.props.state.autoFormatOptions.autoOrdinals,
(state, value) => (state.autoFormatOptions.autoOrdinals = value)
)}
{this.renderCheckBox(
'Telephone',
this.autoTel,
this.props.state.autoFormatOptions.autoTel,
(state, value) => (state.autoFormatOptions.autoTel = value)
)}
{this.renderCheckBox(
'Email',
this.autoMailto,
this.props.state.autoFormatOptions.autoMailto,
(state, value) => (state.autoFormatOptions.autoMailto = value)
)}
</>
)}
{this.renderPluginItem(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"coverage-istanbul-loader": "3.0.5",
"css-loader": "3.5.3",
"detect-port": "^1.3.0",
"dompurify": "2.3.0",
"dompurify": "2.5.4",
"eslint": "^8.50.0",
"eslint-plugin-etc": "^2.0.3",
"eslint-plugin-react": "^7.33.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ export function setModelIndentation(
//if block has only one level, there is not need to check if it is multilevel selection
} else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {
if (isIndent) {
const lastLevel = block.levels[block.levels.length - 1];
const threadIdx = thread.indexOf(block);
const previousItem = thread[threadIdx - 1];
const nextItem = thread[threadIdx + 1];
const levelLength = block.levels.length;
const lastLevel = block.levels[levelLength - 1];
const newLevel: ContentModelListLevel = createListLevel(
lastLevel?.listType || 'UL',
lastLevel?.format
lastLevel?.format,
previousItem && previousItem.levels.length > levelLength
? previousItem.levels[levelLength].dataset
: nextItem && nextItem.levels.length > levelLength
? nextItem.levels[levelLength].dataset
: undefined
);

updateListMetadata(newLevel, metadata => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function clearModelFormat(
blocksToClear: [ReadonlyContentModelBlockGroup[], ShallowMutableContentModelBlock][],
segmentsToClear: ShallowMutableContentModelSegment[],
tablesToClear: [ContentModelTable, boolean][]
) {
): boolean {
let pendingStructureChange = false;

iterateSelections(
model,
(path, tableContext, block, segments) => {
Expand Down Expand Up @@ -75,14 +77,14 @@ export function clearModelFormat(
blocksToClear.length == 1
) {
segmentsToClear.splice(0, segmentsToClear.length, ...adjustWordSelection(model, marker));
clearListFormat(blocksToClear[0][0]);
pendingStructureChange = clearListFormat(blocksToClear[0][0]) || pendingStructureChange;
} else if (blocksToClear.length > 1 || blocksToClear.some(x => isWholeBlockSelected(x[1]))) {
// 2. If a full block or multiple blocks are selected, clear block format
for (let i = blocksToClear.length - 1; i >= 0; i--) {
const [path, block] = blocksToClear[i];

clearBlockFormat(path, block);
clearListFormat(path);
pendingStructureChange = clearListFormat(path) || pendingStructureChange;
clearContainerFormat(path, block);
}
}
Expand All @@ -92,6 +94,8 @@ export function clearModelFormat(

// 4. Clear format for table if any
createTablesFormat(tablesToClear);

return pendingStructureChange;
}

function createTablesFormat(tablesToClear: [ContentModelTable, boolean][]) {
Expand Down Expand Up @@ -191,6 +195,10 @@ function clearListFormat(path: ReadonlyContentModelBlockGroup[]) {

if (listItem) {
mutateBlock(listItem).levels = [];

return true;
} else {
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
ContentModelTable,
} from 'roosterjs-content-model-types';

const MAX_TRY = 3;

/**
* Clear format of selection
* @param editor The editor to clear format from
Expand All @@ -17,17 +19,27 @@ export function clearFormat(editor: IEditor) {

editor.formatContentModel(
model => {
const blocksToClear: [ContentModelBlockGroup[], ContentModelBlock][] = [];
const segmentsToClear: ContentModelSegment[] = [];
const tablesToClear: [ContentModelTable, boolean][] = [];
let changed = false;
let needtoRun = true;
let triedTimes = 0;

while (needtoRun && triedTimes++ < MAX_TRY) {
const blocksToClear: [ContentModelBlockGroup[], ContentModelBlock][] = [];
const segmentsToClear: ContentModelSegment[] = [];
const tablesToClear: [ContentModelTable, boolean][] = [];

needtoRun = clearModelFormat(model, blocksToClear, segmentsToClear, tablesToClear);

clearModelFormat(model, blocksToClear, segmentsToClear, tablesToClear);
normalizeContentModel(model);

normalizeContentModel(model);
changed =
changed ||
blocksToClear.length > 0 ||
segmentsToClear.length > 0 ||
tablesToClear.length > 0;
}

return (
blocksToClear.length > 0 || segmentsToClear.length > 0 || tablesToClear.length > 0
);
return changed;
},
{
apiName: 'clearFormat',
Expand Down
Loading

0 comments on commit 55fa15e

Please sign in to comment.