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

Add anchor support to static blocks #23197

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 packages/block-editor/src/hooks/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const withInspectorControl = createHigherOrderComponent(
anchor: nextValue,
} );
} }
autoComplete="off"
/>
</InspectorAdvancedControls>
</>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/audio/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}
},
"supports": {
"anchor": true,
"align": true,
"lightBlockWrapper": true
}
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}
},
"supports": {
"anchor": true,
"align": true,
"alignWide": false,
"reusable": false,
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/buttons/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "core/buttons",
"category": "design",
"supports": {
"anchor": true,
"align": true,
"alignWide": false,
"lightBlockWrapper": true
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
},
"supports": {
"anchor": true,
"html": false,
"lightBlockWrapper": true
}
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
},
"supports": {
"anchor": true,
"reusable": false,
"html": false,
"lightBlockWrapper": true
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
},
"supports": {
"anchor": true,
"align": [
"wide",
"full"
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
}
},
"supports": {
"anchor": true,
"align": true,
"html": false,
"lightBlockWrapper": true,
Expand Down
12 changes: 8 additions & 4 deletions packages/block-library/src/cover/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/image' ],
transform: ( { caption, url, align, id } ) =>
transform: ( { caption, url, align, id, anchor } ) =>
createBlock( 'core/cover', {
title: caption,
url,
align,
id,
anchor,
} ),
},
{
type: 'block',
blocks: [ 'core/video' ],
transform: ( { caption, src, align, id } ) =>
transform: ( { caption, src, align, id, anchor } ) =>
createBlock( 'core/cover', {
title: caption,
url: src,
align,
id,
backgroundType: VIDEO_BACKGROUND_TYPE,
anchor,
} ),
},
],
Expand Down Expand Up @@ -58,12 +60,13 @@ const transforms = {
! customGradient
);
},
transform: ( { title, url, align, id } ) =>
transform: ( { title, url, align, id, anchor } ) =>
createBlock( 'core/image', {
caption: title,
url,
align,
id,
anchor,
} ),
},
{
Expand All @@ -89,12 +92,13 @@ const transforms = {
! customGradient
);
},
transform: ( { title, url, align, id } ) =>
transform: ( { title, url, align, id, anchor } ) =>
createBlock( 'core/video', {
caption: title,
src: url,
id,
align,
anchor,
} ),
},
],
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/file/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}
},
"supports": {
"anchor": true,
"align": true
}
}
6 changes: 6 additions & 0 deletions packages/block-library/src/file/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const transforms = {
fileName: attributes.caption,
textLinkHref: attributes.src,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand All @@ -60,6 +61,7 @@ const transforms = {
fileName: attributes.caption,
textLinkHref: attributes.src,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand All @@ -72,6 +74,7 @@ const transforms = {
fileName: attributes.caption,
textLinkHref: attributes.url,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand All @@ -93,6 +96,7 @@ const transforms = {
src: attributes.href,
caption: attributes.fileName,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand All @@ -112,6 +116,7 @@ const transforms = {
src: attributes.href,
caption: attributes.fileName,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand All @@ -131,6 +136,7 @@ const transforms = {
url: attributes.href,
caption: attributes.fileName,
id: attributes.id,
anchor: attributes.anchor,
} );
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
}
},
"supports": {
"anchor": true,
"align": true
}
}
8 changes: 5 additions & 3 deletions packages/block-library/src/heading/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { content } ) => {
transform: ( { content, anchor } ) => {
return createBlock( name, {
content,
anchor,
} );
},
},
Expand All @@ -26,7 +27,7 @@ const transforms = {
schema: ( { phrasingContentSchema, isPaste } ) => {
const schema = {
children: phrasingContentSchema,
attributes: isPaste ? [] : [ 'style' ],
attributes: isPaste ? [] : [ 'style', 'id' ],
};
return {
h1: schema,
Expand Down Expand Up @@ -69,9 +70,10 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { content } ) => {
transform: ( { content, anchor } ) => {
return createBlock( 'core/paragraph', {
content,
anchor,
} );
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
}
},
"supports": {
"anchor": true,
"lightBlockWrapper": true
}
}
2 changes: 2 additions & 0 deletions packages/block-library/src/image/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const transforms = {
const alignMatches = /(?:^|\s)align(left|center|right)(?:$|\s)/.exec(
className
);
const anchor = node.id === '' ? undefined : node.id;
const align = alignMatches ? alignMatches[ 1 ] : undefined;
const idMatches = /(?:^|\s)wp-image-(\d+)(?:$|\s)/.exec(
className
Expand Down Expand Up @@ -115,6 +116,7 @@ const transforms = {
href,
rel,
linkClass,
anchor,
}
);
return createBlock( 'core/image', attributes );
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/list/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}
},
"supports": {
"anchor": true,
"className": false,
"__unstablePasteTextInline": true,
"lightBlockWrapper": true
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/list/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ const transforms = {
),
multilineTag: 'li',
} ),
anchor: blockAttributes.anchor,
} );
},
},
{
type: 'block',
blocks: [ 'core/quote' ],
transform: ( { value } ) => {
transform: ( { value, anchor } ) => {
return createBlock( 'core/list', {
values: toHTMLString( {
value: create( { html: value, multilineTag: 'p' } ),
multilineTag: 'li',
} ),
anchor,
} );
},
},
Expand All @@ -86,6 +88,7 @@ const transforms = {
transform( node ) {
const attributes = {
ordered: node.nodeName === 'OL',
anchor: node.id === '' ? undefined : node.id,
};

if ( attributes.ordered ) {
Expand Down Expand Up @@ -157,7 +160,7 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/quote' ],
transform: ( { values } ) => {
transform: ( { values, anchor } ) => {
return createBlock( 'core/quote', {
value: toHTMLString( {
value: create( {
Expand All @@ -167,6 +170,7 @@ const transforms = {
} ),
multilineTag: 'p',
} ),
anchor,
} );
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/media-text/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
}
},
"supports": {
"anchor": true,
"align": [
"wide",
"full"
Expand Down
12 changes: 8 additions & 4 deletions packages/block-library/src/media-text/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/image' ],
transform: ( { alt, url, id } ) =>
transform: ( { alt, url, id, anchor } ) =>
createBlock( 'core/media-text', {
mediaAlt: alt,
mediaId: id,
mediaUrl: url,
mediaType: 'image',
anchor,
} ),
},
{
type: 'block',
blocks: [ 'core/video' ],
transform: ( { src, id } ) =>
transform: ( { src, id, anchor } ) =>
createBlock( 'core/media-text', {
mediaId: id,
mediaUrl: src,
mediaType: 'video',
anchor,
} ),
},
],
Expand All @@ -34,11 +36,12 @@ const transforms = {
isMatch: ( { mediaType, mediaUrl } ) => {
return ! mediaUrl || mediaType === 'image';
},
transform: ( { mediaAlt, mediaId, mediaUrl } ) => {
transform: ( { mediaAlt, mediaId, mediaUrl, anchor } ) => {
return createBlock( 'core/image', {
alt: mediaAlt,
id: mediaId,
url: mediaUrl,
anchor,
} );
},
},
Expand All @@ -48,10 +51,11 @@ const transforms = {
isMatch: ( { mediaType, mediaUrl } ) => {
return ! mediaUrl || mediaType === 'video';
},
transform: ( { mediaId, mediaUrl } ) => {
transform: ( { mediaId, mediaUrl, anchor } ) => {
return createBlock( 'core/video', {
id: mediaId,
src: mediaUrl,
anchor,
} );
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
}
},
"supports": {
"anchor": true,
"className": false,
"lightBlockWrapper": true,
"__experimentalColor": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/paragraph/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const transforms = {
schema: ( { phrasingContentSchema, isPaste } ) => ( {
p: {
children: phrasingContentSchema,
attributes: isPaste ? [] : [ 'style' ],
attributes: isPaste ? [] : [ 'style', 'id' ],
},
} ),
transform( node ) {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/preformatted/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
}
},
"supports": {
"anchor": true,
"lightBlockWrapper": true
}
}
3 changes: 2 additions & 1 deletion packages/block-library/src/preformatted/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const transforms = {
{
type: 'block',
blocks: [ 'core/code', 'core/paragraph' ],
transform: ( { content } ) =>
transform: ( { content, anchor } ) =>
createBlock( 'core/preformatted', {
content,
anchor,
} ),
},
{
Expand Down
Loading