-
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.
Merge pull request #2921 from microsoft/u/juliaroldi/bump-rooster-js
Bump RoosterJS Version 9.17.0
- Loading branch information
Showing
32 changed files
with
718 additions
and
305 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { getFirstSelectedTable, mutateBlock } from 'roosterjs-content-model-dom'; | ||
import { IEditor } from 'roosterjs-content-model-types'; | ||
import { RibbonButton, showInputDialog } from 'roosterjs-react'; | ||
|
||
/** | ||
* @internal | ||
* "Image Border Style" button on the format ribbon | ||
*/ | ||
export const tableTitleButton: RibbonButton<'buttonNameTableTitle'> = { | ||
key: 'buttonNameTableTitle', | ||
unlocalizedText: 'Table Title', | ||
iconName: 'TableComputed', | ||
isDisabled: formatState => !formatState.isInTable, | ||
onClick: (editor, _, strings, uiUtilities) => { | ||
const items = { | ||
title: { | ||
autoFocus: true, | ||
labelKey: 'buttonNameTableTitle' as const, | ||
unlocalizedLabel: 'Title', | ||
initValue: '', | ||
}, | ||
}; | ||
|
||
showInputDialog( | ||
uiUtilities, | ||
'buttonNameTableTitle', | ||
'Insert Table', | ||
items, | ||
strings, | ||
(itemName, newValue, values) => { | ||
if (itemName == 'title') { | ||
values.title = newValue; | ||
return values; | ||
} else { | ||
return null; | ||
} | ||
} | ||
).then(result => { | ||
editor.focus(); | ||
if (result && result.title) { | ||
insertTableTitle(editor, result.title); | ||
} | ||
}); | ||
}, | ||
}; | ||
|
||
const insertTableTitle = (editor: IEditor, title: string) => { | ||
editor.formatContentModel(model => { | ||
const table = getFirstSelectedTable(model)[0]; | ||
if (table) { | ||
mutateBlock(table).format.title = title; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
}; |
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
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
26 changes: 26 additions & 0 deletions
26
packages/roosterjs-content-model-dom/lib/formatHandlers/common/ariaFormatHandler.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,26 @@ | ||
import type { AriaFormat } from 'roosterjs-content-model-types'; | ||
import type { FormatHandler } from '../FormatHandler'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const ariaFormatHandler: FormatHandler<AriaFormat> = { | ||
parse: (format, element) => { | ||
const ariaDescribedBy = element.getAttribute('aria-describedby'); | ||
const title = element.getAttribute('title'); | ||
if (ariaDescribedBy) { | ||
format.ariaDescribedBy = ariaDescribedBy; | ||
} | ||
if (title) { | ||
format.title = title; | ||
} | ||
}, | ||
apply: (format, element) => { | ||
if (format.ariaDescribedBy) { | ||
element.setAttribute('aria-describedby', format.ariaDescribedBy); | ||
} | ||
if (format.title) { | ||
element.setAttribute('title', format.title); | ||
} | ||
}, | ||
}; |
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
81 changes: 81 additions & 0 deletions
81
packages/roosterjs-content-model-dom/test/formatHandlers/common/ariaFormatHandlerTest.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,81 @@ | ||
import { AriaFormat, DomToModelContext, ModelToDomContext } from 'roosterjs-content-model-types'; | ||
import { ariaFormatHandler } from '../../../lib/formatHandlers/common/ariaFormatHandler'; | ||
import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; | ||
import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext'; | ||
|
||
describe('ariaFormatHandler.parse', () => { | ||
let div: HTMLElement; | ||
let format: AriaFormat; | ||
let context: DomToModelContext; | ||
|
||
beforeEach(() => { | ||
div = document.createElement('div'); | ||
format = {}; | ||
context = createDomToModelContext(); | ||
}); | ||
|
||
it('No title and describedby', () => { | ||
ariaFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({}); | ||
}); | ||
|
||
it('has title and describedby', () => { | ||
div.setAttribute('title', 'test'); | ||
div.setAttribute('aria-describedby', 'test'); | ||
ariaFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({ | ||
title: 'test', | ||
ariaDescribedBy: 'test', | ||
}); | ||
}); | ||
|
||
it('has title and no describedby', () => { | ||
div.setAttribute('title', 'test'); | ||
ariaFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({ | ||
title: 'test', | ||
}); | ||
}); | ||
|
||
it('no title and has describedby', () => { | ||
div.setAttribute('aria-describedby', 'test'); | ||
ariaFormatHandler.parse(format, div, context, {}); | ||
expect(format).toEqual({ ariaDescribedBy: 'test' }); | ||
}); | ||
}); | ||
|
||
describe('idFormatHandler.apply', () => { | ||
let div: HTMLElement; | ||
let format: AriaFormat; | ||
let context: ModelToDomContext; | ||
|
||
beforeEach(() => { | ||
div = document.createElement('div'); | ||
format = {}; | ||
context = createModelToDomContext(); | ||
}); | ||
|
||
it('No title and no describedby', () => { | ||
ariaFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div></div>'); | ||
}); | ||
|
||
it('Has title and has describedby', () => { | ||
format.title = 'test'; | ||
format.ariaDescribedBy = 'test'; | ||
ariaFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div aria-describedby="test" title="test"></div>'); | ||
}); | ||
|
||
it('No title and has describedby', () => { | ||
format.ariaDescribedBy = 'test'; | ||
ariaFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div aria-describedby="test"></div>'); | ||
}); | ||
|
||
it('Has title and no describedby', () => { | ||
format.title = 'test'; | ||
ariaFormatHandler.apply(format, div, context); | ||
expect(div.outerHTML).toBe('<div title="test"></div>'); | ||
}); | ||
}); |
Oops, something went wrong.