-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffc58bf
commit 1abe6b2
Showing
12 changed files
with
137 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { setTableTitle } from 'roosterjs-content-model-api'; | ||
import { showInputDialog } from 'roosterjs-react'; | ||
import type { RibbonButton } from 'roosterjs-react'; | ||
|
||
/** | ||
* Key of localized strings of Table title button | ||
*/ | ||
export type TableTitleButtonStringKey = 'buttonTableTitle'; | ||
|
||
/** | ||
* "Table Title" button on the format ribbon | ||
*/ | ||
export const tableTitleButton: RibbonButton<TableTitleButtonStringKey> = { | ||
key: 'buttonTableTitle', | ||
unlocalizedText: 'Add Table Title', | ||
iconName: 'OpenInNewWindow', | ||
flipWhenRtl: true, | ||
onClick: (editor, key, strings, uiUtility) => { | ||
showInputDialog( | ||
uiUtility, | ||
key, | ||
'Add table title', | ||
{ | ||
title: { | ||
labelKey: null, | ||
unlocalizedLabel: null, | ||
initValue: '', | ||
}, | ||
description: { | ||
labelKey: null, | ||
unlocalizedLabel: null, | ||
initValue: '', | ||
}, | ||
}, | ||
strings, | ||
(itemName, newValue, values) => { | ||
if (itemName == 'title') { | ||
values.title = newValue; | ||
} | ||
if (itemName == 'description') { | ||
values.description = newValue; | ||
} | ||
return values; | ||
} | ||
).then(values => { | ||
editor.focus(); | ||
setTableTitle(editor, values.title || ''); | ||
}); | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
...ipts/controlsV2/sidePane/contentModel/components/format/formatPart/TitleFormatRenderer.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,11 @@ | ||
import { createTextFormatRenderer } from '../utils/createTextFormatRenderer'; | ||
import { FormatRenderer } from '../utils/FormatRenderer'; | ||
import { TitleFormat } from 'roosterjs-content-model-types'; | ||
|
||
export const TitleFormatRenderer: FormatRenderer<TitleFormat> = createTextFormatRenderer< | ||
TitleFormat | ||
>( | ||
'Title', | ||
format => format.title, | ||
(format, value) => (format.title = value) | ||
); |
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
28 changes: 28 additions & 0 deletions
28
packages/roosterjs-content-model-api/lib/publicApi/table/setTableTitle.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,28 @@ | ||
import { getFirstSelectedTable, mutateBlock } from 'roosterjs-content-model-dom'; | ||
import type { IEditor } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* Set table title | ||
* @param editor The editor instance | ||
* @param title The title to set | ||
*/ | ||
export function setTableTitle(editor: IEditor, title: string) { | ||
editor.focus(); | ||
|
||
editor.formatContentModel( | ||
model => { | ||
const [table] = getFirstSelectedTable(model); | ||
|
||
if (table) { | ||
mutateBlock(table).format.title = title; | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
{ | ||
apiName: 'setTableTitle', | ||
} | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/roosterjs-content-model-dom/lib/formatHandlers/common/titleFormatHandler.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,18 @@ | ||
import type { FormatHandler } from '../FormatHandler'; | ||
import type { TitleFormat } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const titleFormatHandler: FormatHandler<TitleFormat> = { | ||
parse: (format, element) => { | ||
if (element.title) { | ||
format.title = element.title; | ||
} | ||
}, | ||
apply: (format, element) => { | ||
if (format.title) { | ||
element.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
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
9 changes: 9 additions & 0 deletions
9
packages/roosterjs-content-model-types/lib/contentModel/format/formatParts/TitleFormat.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,9 @@ | ||
/** | ||
* Format for element with Title | ||
*/ | ||
export type TitleFormat = { | ||
/** | ||
* Title of the element | ||
*/ | ||
title?: 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