Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToC block: re-enable + use static markup and only support core Heading and Page Break blocks #29739

Merged
merged 25 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c53df83
ToC block: use static markup and only support core Heading and Page B…
ZebulanStanphill Jun 27, 2021
afadefa
Remove unused index prop from NestedHeadingData.
ZebulanStanphill Jun 27, 2021
2796c70
Add unit test fixtures.
ZebulanStanphill Oct 15, 2021
f564667
Update test.
ZebulanStanphill Nov 2, 2021
4b7bbc6
Use some TypeScript.
ZebulanStanphill Nov 11, 2021
0ff623d
Disable permalink support when core/editor store is unavailable.
ZebulanStanphill Mar 2, 2022
8ba556a
Add Zebulan as code owner for Table of Contents.
ZebulanStanphill Mar 2, 2022
dc2730a
Switch from ul to ol for list element.
ZebulanStanphill Mar 14, 2022
8f7db2d
Optimize re-renders caused by shallow comparisons of useSelect return…
ZebulanStanphill Mar 16, 2022
4282578
Optimize calculating which page the block is on.
ZebulanStanphill Mar 21, 2022
3080087
Enable Heading anchor auto-generation when a Table of Contents is in …
ZebulanStanphill Mar 22, 2022
803eddc
Add List -> Table of Contents block transform.
ZebulanStanphill Mar 30, 2022
6a724bf
Prevent links from being clicked in the editor since they don't work …
ZebulanStanphill Mar 30, 2022
1eb8d22
Strip HTML tags from listed headings.
ZebulanStanphill Mar 31, 2022
e7e866a
Prefer <Disabled /> over pointer-events rule
mcsf Mar 31, 2022
6221796
Make comment formatting consistent.
ZebulanStanphill Mar 31, 2022
38bb612
Simplify TypeScript config.
ZebulanStanphill Mar 31, 2022
a8a1cbd
Simplify condition using optional chaining in utils.ts.
ZebulanStanphill Mar 31, 2022
6d9c653
Fix page index calculation breaking when ToC or Page Break is nested.
ZebulanStanphill Mar 31, 2022
21adec5
Make comment about editor store dependency consistent with other plac…
ZebulanStanphill Apr 1, 2022
fa6cc7d
Simplify logic thanks to changes made in #39985.
ZebulanStanphill Apr 4, 2022
2ed8a4a
Optimize logic when onlyIncludeCurrentPage is false.
ZebulanStanphill Apr 8, 2022
c439c5b
Revise JSDoc for permalink const.
ZebulanStanphill Apr 8, 2022
425109f
Update inspector panel title as per #40275.
ZebulanStanphill Apr 14, 2022
327338f
Make block experimental.
ZebulanStanphill Apr 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/packages/block-library/src/page-list @tellthemachines
/packages/block-library/src/comment-template @michalczaplinski
/packages/block-library/src/comments @michalczaplinski
/packages/block-library/src/table-of-contents @ZebulanStanphill

# Duotone
/lib/block-supports/duotone.php @ajlende
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ Summarize your post with a list of headings. Add HTML anchors to Heading blocks
- **Name:** core/table-of-contents
- **Category:** layout
- **Supports:** ~~html~~
- **Attributes:** onlyIncludeCurrentPage
- **Attributes:** headings, onlyIncludeCurrentPage

## Tag Cloud

Expand Down
3 changes: 1 addition & 2 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function gutenberg_reregister_core_block_types() {
'social-links',
'spacer',
'table',
// 'table-of-contents',
'table-of-contents',
'text-columns',
'verse',
'video',
Expand Down Expand Up @@ -107,7 +107,6 @@ function gutenberg_reregister_core_block_types() {
'site-logo.php' => 'core/site-logo',
'site-tagline.php' => 'core/site-tagline',
'site-title.php' => 'core/site-title',
// 'table-of-contents.php' => 'core/table-of-contents',
'tag-cloud.php' => 'core/tag-cloud',
'template-part.php' => 'core/template-part',
'term-description.php' => 'core/term-description',
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ function HeadingEdit( {
} );

const { canGenerateAnchors } = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
const { getGlobalBlockCount, getSettings } = select( blockEditorStore );
const settings = getSettings();

return {
canGenerateAnchors: !! settings.generateAnchors,
canGenerateAnchors:
!! settings.generateAnchors ||
getGlobalBlockCount( 'core/table-of-contents' ) > 0,
ZebulanStanphill marked this conversation as resolved.
Show resolved Hide resolved
};
}, [] );

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import * as socialLink from './social-link';
import * as socialLinks from './social-links';
import * as spacer from './spacer';
import * as table from './table';
import * as tableOfContents from './table-of-contents';
import * as tagCloud from './tag-cloud';
import * as templatePart from './template-part';
import * as termDescription from './term-description';
Expand Down Expand Up @@ -175,7 +176,6 @@ export const __experimentalGetCoreBlocks = () => [
socialLinks,
spacer,
table,
// tableOfContents,
tagCloud,
textColumns,
verse,
Expand Down Expand Up @@ -269,6 +269,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
[
// Experimental blocks.
postAuthorName,
tableOfContents,
...( window.__experimentalEnableListBlockV2
? [ listItem ]
: [] ),
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/list/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ const transforms = {
} );
},
},
{
type: 'block',
blocks: [ 'core/table-of-contents' ],
transform: () => {
return createBlock( 'core/table-of-contents' );
},
},
Comment on lines +211 to +217
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what value this brings!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think of it as serving a similar function to the transforms for the Navigation Link that let you convert a Page Link to a Category Link (and etc.)... obviously, the block just gets replaced with little to nothing kept from the original block, but the purpose is to make replacing the block easier. If you convert a Table of Contents to a static list, but then want to go back later, a transform is more convenient than deleting the List and inserting a ToC. Or at least that's the idea.

(In the future, some simple stuff like background/text color from the List could be transferred over, but I decided against adding those to the ToC right now to avoid making this PR even bigger.)

],
};

Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/table-of-contents/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
"keywords": [ "document outline", "summary" ],
"textdomain": "default",
"attributes": {
"headings": {
"type": "array",
"items": {
"type": "object"
}
},
"onlyIncludeCurrentPage": {
"type": "boolean",
"default": false
}
},
"usesContext": [ "postId" ],
"supports": {
"html": false
}
},
"example": {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to have something basic here.

Copy link
Member Author

@ZebulanStanphill ZebulanStanphill Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of how the block updates itself, any dummy heading data put in here would be quickly overwritten (I think). Perhaps if there was a way to detect if the block was being rendered in "example-preview mode" or whatever, this could be worked around. It would be kinda hacky to do something like that, though.

A somewhat less weird solution would be to add the ability for examples to include "context" blocks that aren't shown in the preview, but are still part of the simulated document the previewed block is a part of. No clue what the schema changes necessary would be, nor if such a thing is even worth considering. It seems perhaps a bit too convoluted.

}
Loading