Skip to content

Commit 64d9236

Browse files
authored
Merge pull request #3547 from superdoc-dev/sd-2751_configurable-toc-icon
fix: make toc toolbar icon configurable
2 parents fa9d733 + 3385cad commit 64d9236

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

packages/super-editor/src/editors/v1/components/toolbar/defaultItems.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,17 +1076,11 @@ export const makeDefaultItems = ({
10761076
const stickyItemsWidth = 120;
10771077
const toolbarPadding = 32;
10781078

1079-
const itemsToHideXL = [
1080-
'linkedStyles',
1081-
'clearFormatting',
1082-
'copyFormat',
1083-
'ruler',
1084-
'formattingMarks',
1085-
'tableOfContents',
1086-
];
1079+
const itemsToHideXL = ['linkedStyles', 'clearFormatting', 'copyFormat', 'ruler', 'formattingMarks'];
10871080
const itemsToHideSM = ['zoom', 'fontFamily', 'fontSize', 'redo'];
10881081
const shouldUseLgCompactStyles = availableWidth <= RESPONSIVE_BREAKPOINTS.lg;
10891082
const shouldIncludeFormattingMarks = superToolbar.config?.showFormattingMarksButton === true;
1083+
const shouldIncludeTableOfContents = superToolbar.config?.showTableOfContentsButton === true;
10901084

10911085
if (shouldUseLgCompactStyles) {
10921086
documentMode.attributes.value = {
@@ -1122,7 +1116,7 @@ export const makeDefaultItems = ({
11221116
separator,
11231117
link,
11241118
image,
1125-
tableOfContents,
1119+
...(shouldIncludeTableOfContents ? [tableOfContents] : []),
11261120
tableItem,
11271121
tableActionsItem,
11281122
separator,

packages/super-editor/src/editors/v1/components/toolbar/defaultItems.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ function buildItems(availableWidth, superToolbarOverrides = {}) {
4444
});
4545
}
4646

47+
describe('makeDefaultItems table of contents button opt-in', () => {
48+
it('does not include tableOfContents in the default toolbar items', () => {
49+
const { defaultItems, overflowItems } = buildItems(2000);
50+
expect(getItem(defaultItems, overflowItems, 'tableOfContents')).toBeUndefined();
51+
});
52+
53+
it('includes tableOfContents when showTableOfContentsButton is true', () => {
54+
const { defaultItems, overflowItems } = buildItems(2000, {
55+
config: { showTableOfContentsButton: true },
56+
});
57+
const tableOfContents = getItem(defaultItems, overflowItems, 'tableOfContents');
58+
59+
expect(tableOfContents).toBeDefined();
60+
expect(tableOfContents.command).toBe('insertTableOfContents');
61+
});
62+
});
63+
4764
describe('makeDefaultItems formatting marks button opt-in', () => {
4865
it('does not include formattingMarks in the default toolbar items', () => {
4966
const { defaultItems, overflowItems } = buildItems(2000);
@@ -73,7 +90,7 @@ describe('makeDefaultItems formatting marks button opt-in', () => {
7390
describe('makeDefaultItems XL overflow boundary (SD-2328)', () => {
7491
const XL_OVERFLOW_SAFETY_BUFFER = 20;
7592
const XL_CUTOFF = RESPONSIVE_BREAKPOINTS.xl + XL_OVERFLOW_SAFETY_BUFFER;
76-
const XL_ITEMS = ['linkedStyles', 'clearFormatting', 'copyFormat', 'ruler', 'tableOfContents'];
93+
const XL_ITEMS = ['linkedStyles', 'clearFormatting', 'copyFormat', 'ruler'];
7794

7895
it(`moves XL items into overflow at ${XL_CUTOFF - 1}px (below cutoff)`, () => {
7996
const { defaultItems, overflowItems } = buildItems(XL_CUTOFF - 1);

packages/super-editor/src/editors/v1/components/toolbar/super-toolbar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { insertTableOfContentsAtSelection } from '@extensions/table-of-contents/
4949
* @property {string} [aiEndpoint] - Endpoint for AI integration
5050
* @property {Array<Record<string, unknown>> | ToolbarItem[]} [customButtons=[]] - Custom buttons to add to the toolbar. SuperDoc forwards the structural `Array<Record<string, unknown>>` shape from `Modules.toolbar.customButtons`; the runtime wraps each entry into a full `ToolbarItem` via `useToolbarItem`.
5151
* @property {boolean} [showFormattingMarksButton=false] - Show the formatting marks (pilcrow) button in the toolbar. Distinct from `layoutEngineOptions.showFormattingMarks`, which controls whether the marks render in the document.
52+
* @property {boolean} [showTableOfContentsButton=false] - Show the table of contents insert button in the toolbar. Off by default until the feature is generally available.
5253
* @property {boolean} [isDev] - Dev-mode flag forwarded from `SuperDoc.isDev`; gates debug tooltips and overlays.
5354
* @property {object} [superdoc] - The owning SuperDoc instance. Set by SuperDoc when constructing the toolbar; the toolbar uses it to dispatch commands back through the parent.
5455
* @property {boolean} [responsiveToContainer=false] - When `true`, the toolbar measures the container width instead of the document width when deciding which items to collapse.
@@ -169,6 +170,7 @@ export class SuperToolbar extends EventEmitter {
169170
aiEndpoint: null,
170171
customButtons: [],
171172
showFormattingMarksButton: false,
173+
showTableOfContentsButton: false,
172174
};
173175

174176
/**

packages/superdoc/src/core/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,10 @@ export interface Modules {
12271227
* controls whether the marks render in the document.
12281228
*/
12291229
showFormattingMarksButton?: boolean;
1230+
/**
1231+
* Show the table of contents insert button in the toolbar. Off by default.
1232+
*/
1233+
showTableOfContentsButton?: boolean;
12301234
} & Record<string, unknown>;
12311235
/** Link click popover configuration. */
12321236
links?: {

0 commit comments

Comments
 (0)