diff --git a/blocks/api/factory.js b/blocks/api/factory.js index 594d61afa792d..ef9de61959bd5 100644 --- a/blocks/api/factory.js +++ b/blocks/api/factory.js @@ -52,10 +52,14 @@ export function createBlock( name, blockAttributes = {}, innerBlocks = [] ) { return result; }, {} ); - // Blocks are stored with a unique ID, the assigned type name, - // the block attributes, and their inner blocks. + const clientId = uuid(); + + // Blocks are stored with a unique ID, the assigned type name, the block + // attributes, and their inner blocks. return { - uid: uuid(), + clientId, + // TODO: Remove from block interface in 3.5 "UID" deprecation. + uid: clientId, name, isValid: true, attributes, @@ -74,8 +78,12 @@ export function createBlock( name, blockAttributes = {}, innerBlocks = [] ) { * @return {Object} A cloned block. */ export function cloneBlock( block, mergeAttributes = {}, newInnerBlocks ) { + const clientId = uuid(); + return { ...block, + clientId, + // TODO: Remove from block interface in 3.5 "UID" deprecation. uid: uuid(), attributes: { ...block.attributes, @@ -365,8 +373,8 @@ export function switchToBlockType( blocks, name ) { const transformedBlock = { ...result, // The first transformed block whose type matches the "destination" - // type gets to keep the existing UID of the first block. - uid: index === firstSwitchedBlock ? firstBlock.uid : result.uid, + // type gets to keep the existing client ID of the first block. + clientId: index === firstSwitchedBlock ? firstBlock.clientId : result.clientId, }; /** diff --git a/blocks/api/raw-handling/test/shortcode-converter.js b/blocks/api/raw-handling/test/shortcode-converter.js index 48b69a14b1c90..a3de187ef95c7 100644 --- a/blocks/api/raw-handling/test/shortcode-converter.js +++ b/blocks/api/raw-handling/test/shortcode-converter.js @@ -28,8 +28,10 @@ describe( 'segmentHTMLToShortcodeBlock', () => { const expectedBlock = createBlock( 'core/shortcode', { text: '[foo bar="apple"]', } ); - // uuid will always be random. - expectedBlock.uid = transformed[ 1 ].uid; + // clientId will always be random. + expectedBlock.clientId = transformed[ 1 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + expectedBlock.uid = expectedBlock.clientId; expect( transformed[ 1 ] ).toEqual( expectedBlock ); expect( transformed[ 2 ] ).toBe( ` @@ -45,16 +47,20 @@ describe( 'segmentHTMLToShortcodeBlock', () => { const firstExpectedBlock = createBlock( 'core/shortcode', { text: '[foo one]', } ); - // uid will always be random. - firstExpectedBlock.uid = transformed[ 1 ].uid; + // clientId will always be random. + firstExpectedBlock.clientId = transformed[ 1 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + firstExpectedBlock.uid = firstExpectedBlock.clientId; expect( transformed[ 1 ] ).toEqual( firstExpectedBlock ); expect( transformed[ 2 ] ).toEqual( `

` ); const secondExpectedBlock = createBlock( 'core/shortcode', { text: '[foo two]', } ); - // uid will always be random. - secondExpectedBlock.uid = transformed[ 3 ].uid; + // clientId will always be random. + secondExpectedBlock.clientId = transformed[ 3 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + secondExpectedBlock.uid = secondExpectedBlock.clientId; expect( transformed[ 3 ] ).toEqual( secondExpectedBlock ); expect( transformed[ 4 ] ).toEqual( '

' ); expect( transformed ).toHaveLength( 5 ); @@ -71,32 +77,40 @@ describe( 'segmentHTMLToShortcodeBlock', () => { const firstExpectedBlock = createBlock( 'core/shortcode', { text: '[foo one]', } ); - // uid will always be random. - firstExpectedBlock.uid = transformed[ 1 ].uid; + // clientId will always be random. + firstExpectedBlock.clientId = transformed[ 1 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + firstExpectedBlock.uid = firstExpectedBlock.clientId; expect( transformed[ 1 ] ).toEqual( firstExpectedBlock ); expect( transformed[ 2 ] ).toEqual( `

` ); const secondExpectedBlock = createBlock( 'core/shortcode', { text: '[foo two]', } ); - // uid will always be random. - secondExpectedBlock.uid = transformed[ 3 ].uid; + // clientId will always be random. + secondExpectedBlock.clientId = transformed[ 3 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + secondExpectedBlock.uid = secondExpectedBlock.clientId; expect( transformed[ 3 ] ).toEqual( secondExpectedBlock ); expect( transformed[ 4 ] ).toEqual( `

` ); const thirdExpectedBlock = createBlock( 'core/shortcode', { text: '[foo three]', } ); - // uid will always be random. - thirdExpectedBlock.uid = transformed[ 5 ].uid; + // clientId will always be random. + thirdExpectedBlock.clientId = transformed[ 5 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + thirdExpectedBlock.uid = thirdExpectedBlock.clientId; expect( transformed[ 5 ] ).toEqual( thirdExpectedBlock ); expect( transformed[ 6 ] ).toEqual( `

` ); const fourthExpectedBlock = createBlock( 'core/shortcode', { text: '[foo four]', } ); - // uid will always be random. - fourthExpectedBlock.uid = transformed[ 7 ].uid; + // clientId will always be random. + fourthExpectedBlock.clientId = transformed[ 7 ].clientId; + // TODO: Remove in 3.5 "UID" deprecation. + fourthExpectedBlock.uid = fourthExpectedBlock.clientId; expect( transformed[ 7 ] ).toEqual( fourthExpectedBlock ); expect( transformed[ 8 ] ).toEqual( '

' ); expect( transformed ).toHaveLength( 9 ); diff --git a/blocks/api/test/factory.js b/blocks/api/test/factory.js index d181d933896c5..3da0c772b7e81 100644 --- a/blocks/api/test/factory.js +++ b/blocks/api/test/factory.js @@ -76,7 +76,7 @@ describe( 'block factory', () => { expect( block.isValid ).toBe( true ); expect( block.innerBlocks ).toHaveLength( 1 ); expect( block.innerBlocks[ 0 ].name ).toBe( 'core/test-block' ); - expect( typeof block.uid ).toBe( 'string' ); + expect( typeof block.clientId ).toBe( 'string' ); } ); } ); @@ -114,8 +114,8 @@ describe( 'block factory', () => { isDifferent: true, } ); expect( clonedBlock.innerBlocks ).toHaveLength( 1 ); - expect( typeof clonedBlock.uid ).toBe( 'string' ); - expect( clonedBlock.uid ).not.toBe( block.uid ); + expect( typeof clonedBlock.clientId ).toBe( 'string' ); + expect( clonedBlock.clientId ).not.toBe( block.clientId ); } ); it( 'should replace inner blocks of the existing block', () => { @@ -181,10 +181,10 @@ describe( 'block factory', () => { const clonedBlock = cloneBlock( block ); expect( clonedBlock.innerBlocks ).toHaveLength( 2 ); - expect( clonedBlock.innerBlocks[ 0 ].uid ).not.toBe( block.innerBlocks[ 0 ].uid ); + expect( clonedBlock.innerBlocks[ 0 ].clientId ).not.toBe( block.innerBlocks[ 0 ].clientId ); expect( clonedBlock.innerBlocks[ 0 ].attributes ).not.toBe( block.innerBlocks[ 0 ].attributes ); expect( clonedBlock.innerBlocks[ 0 ].attributes ).toEqual( block.innerBlocks[ 0 ].attributes ); - expect( clonedBlock.innerBlocks[ 1 ].uid ).not.toBe( block.innerBlocks[ 1 ].uid ); + expect( clonedBlock.innerBlocks[ 1 ].clientId ).not.toBe( block.innerBlocks[ 1 ].clientId ); expect( clonedBlock.innerBlocks[ 1 ].attributes ).not.toBe( block.innerBlocks[ 1 ].attributes ); expect( clonedBlock.innerBlocks[ 1 ].attributes ).toEqual( block.innerBlocks[ 1 ].attributes ); } ); @@ -731,7 +731,7 @@ describe( 'block factory', () => { const transformedBlocks = switchToBlockType( block, 'core/updated-text-block' ); expect( transformedBlocks ).toHaveLength( 1 ); - expect( transformedBlocks[ 0 ] ).toHaveProperty( 'uid' ); + expect( transformedBlocks[ 0 ] ).toHaveProperty( 'clientId' ); expect( transformedBlocks[ 0 ].name ).toBe( 'core/updated-text-block' ); expect( transformedBlocks[ 0 ].isValid ).toBe( true ); expect( transformedBlocks[ 0 ].attributes ).toEqual( { @@ -770,7 +770,7 @@ describe( 'block factory', () => { const transformedBlocks = switchToBlockType( block, 'core/updated-text-block' ); expect( transformedBlocks ).toHaveLength( 1 ); - expect( transformedBlocks[ 0 ] ).toHaveProperty( 'uid' ); + expect( transformedBlocks[ 0 ] ).toHaveProperty( 'clientId' ); expect( transformedBlocks[ 0 ].name ).toBe( 'core/updated-text-block' ); expect( transformedBlocks[ 0 ].isValid ).toBe( true ); expect( transformedBlocks[ 0 ].attributes ).toEqual( { @@ -1028,15 +1028,15 @@ describe( 'block factory', () => { // transformed block whose type matches the "destination" type gets // to keep the existing block's UID. expect( transformedBlocks ).toHaveLength( 2 ); - expect( transformedBlocks[ 0 ] ).toHaveProperty( 'uid' ); - expect( transformedBlocks[ 0 ].uid ).not.toBe( block.uid ); + expect( transformedBlocks[ 0 ] ).toHaveProperty( 'clientId' ); + expect( transformedBlocks[ 0 ].clientId ).not.toBe( block.clientId ); expect( transformedBlocks[ 0 ].name ).toBe( 'core/text-block' ); expect( transformedBlocks[ 0 ].isValid ).toBe( true ); expect( transformedBlocks[ 0 ].attributes ).toEqual( { value: 'chicken ribs', } ); - expect( transformedBlocks[ 1 ].uid ).toBe( block.uid ); - expect( transformedBlocks[ 1 ] ).toHaveProperty( 'uid' ); + expect( transformedBlocks[ 1 ].clientId ).toBe( block.clientId ); + expect( transformedBlocks[ 1 ] ).toHaveProperty( 'clientId' ); expect( transformedBlocks[ 1 ].name ).toBe( 'core/updated-text-block' ); expect( transformedBlocks[ 1 ].isValid ).toBe( true ); expect( transformedBlocks[ 1 ].attributes ).toEqual( { diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 3432451b53fd1..a9b4b2ce4800c 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -592,7 +592,7 @@ describe( 'block parser', () => { url: 'http://google.com', chicken: 'ribs & \'wings\'', } ); - expect( typeof parsed[ 0 ].uid ).toBe( 'string' ); + expect( typeof parsed[ 0 ].clientId ).toBe( 'string' ); } ); it( 'should parse empty post content', () => { @@ -625,7 +625,7 @@ describe( 'block parser', () => { expect( parsed[ 0 ].attributes ).toEqual( { content: 'Ribs', } ); - expect( typeof parsed[ 0 ].uid ).toBe( 'string' ); + expect( typeof parsed[ 0 ].clientId ).toBe( 'string' ); } ); it( 'should add the core namespace to un-namespaced blocks', () => { diff --git a/core-blocks/block/edit.js b/core-blocks/block/edit.js index a03befd1c6d23..cd70f46d1e45d 100644 --- a/core-blocks/block/edit.js +++ b/core-blocks/block/edit.js @@ -90,7 +90,7 @@ class SharedBlockEdit extends Component { onUpdateTitle( title ); } - updateAttributes( block.uid, changedAttributes ); + updateAttributes( block.clientId, changedAttributes ); onSave(); this.stopEditing(); @@ -112,7 +112,7 @@ class SharedBlockEdit extends Component { { diff --git a/core-blocks/gallery/index.js b/core-blocks/gallery/index.js index ed277e3a8eb07..b12ae034d5e3a 100644 --- a/core-blocks/gallery/index.js +++ b/core-blocks/gallery/index.js @@ -137,7 +137,7 @@ export const settings = { } ); editorMediaUpload( { filesList: files, - onFileChange: ( images ) => onChange( block.uid, { images } ), + onFileChange: ( images ) => onChange( block.clientId, { images } ), allowedType: 'image', } ); return block; diff --git a/core-blocks/test/fixtures/core-embed__animoto.json b/core-blocks/test/fixtures/core-embed__animoto.json index 8b011d74700ed..136fce645d4ee 100644 --- a/core-blocks/test/fixtures/core-embed__animoto.json +++ b/core-blocks/test/fixtures/core-embed__animoto.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/animoto", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__cloudup.json b/core-blocks/test/fixtures/core-embed__cloudup.json index 5a0ed4448bfa1..88e4a195e1ea4 100644 --- a/core-blocks/test/fixtures/core-embed__cloudup.json +++ b/core-blocks/test/fixtures/core-embed__cloudup.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/cloudup", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__collegehumor.json b/core-blocks/test/fixtures/core-embed__collegehumor.json index c7d2538359f26..86722305b5ab0 100644 --- a/core-blocks/test/fixtures/core-embed__collegehumor.json +++ b/core-blocks/test/fixtures/core-embed__collegehumor.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/collegehumor", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__dailymotion.json b/core-blocks/test/fixtures/core-embed__dailymotion.json index 73b58b18f8c55..317a615c5c78a 100644 --- a/core-blocks/test/fixtures/core-embed__dailymotion.json +++ b/core-blocks/test/fixtures/core-embed__dailymotion.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/dailymotion", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__facebook.json b/core-blocks/test/fixtures/core-embed__facebook.json index 0c3e22402c48d..df9b5d5cb6e82 100644 --- a/core-blocks/test/fixtures/core-embed__facebook.json +++ b/core-blocks/test/fixtures/core-embed__facebook.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/facebook", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__flickr.json b/core-blocks/test/fixtures/core-embed__flickr.json index ee5abd2f2f57b..103a3912a7ab4 100644 --- a/core-blocks/test/fixtures/core-embed__flickr.json +++ b/core-blocks/test/fixtures/core-embed__flickr.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/flickr", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__funnyordie.json b/core-blocks/test/fixtures/core-embed__funnyordie.json index 6d2991b0f553c..c8e313cd80e43 100644 --- a/core-blocks/test/fixtures/core-embed__funnyordie.json +++ b/core-blocks/test/fixtures/core-embed__funnyordie.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/funnyordie", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__hulu.json b/core-blocks/test/fixtures/core-embed__hulu.json index 17fbc3ac88cab..b9185cd0f68fb 100644 --- a/core-blocks/test/fixtures/core-embed__hulu.json +++ b/core-blocks/test/fixtures/core-embed__hulu.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/hulu", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__imgur.json b/core-blocks/test/fixtures/core-embed__imgur.json index 6d6ce18ea3ec3..a80705b701127 100644 --- a/core-blocks/test/fixtures/core-embed__imgur.json +++ b/core-blocks/test/fixtures/core-embed__imgur.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/imgur", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__instagram.json b/core-blocks/test/fixtures/core-embed__instagram.json index 5efe834e32d17..fb19a254a1040 100644 --- a/core-blocks/test/fixtures/core-embed__instagram.json +++ b/core-blocks/test/fixtures/core-embed__instagram.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/instagram", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__issuu.json b/core-blocks/test/fixtures/core-embed__issuu.json index 62f641f67ec27..91fc678f576d4 100644 --- a/core-blocks/test/fixtures/core-embed__issuu.json +++ b/core-blocks/test/fixtures/core-embed__issuu.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/issuu", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__kickstarter.json b/core-blocks/test/fixtures/core-embed__kickstarter.json index 4b7234ac3bbf3..a0c4f3d932bbd 100644 --- a/core-blocks/test/fixtures/core-embed__kickstarter.json +++ b/core-blocks/test/fixtures/core-embed__kickstarter.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/kickstarter", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__meetup-com.json b/core-blocks/test/fixtures/core-embed__meetup-com.json index e6e5246f29ade..e6e4e10f91e7d 100644 --- a/core-blocks/test/fixtures/core-embed__meetup-com.json +++ b/core-blocks/test/fixtures/core-embed__meetup-com.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/meetup-com", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__mixcloud.json b/core-blocks/test/fixtures/core-embed__mixcloud.json index 9a0cf0a53418a..6155fa124229f 100644 --- a/core-blocks/test/fixtures/core-embed__mixcloud.json +++ b/core-blocks/test/fixtures/core-embed__mixcloud.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/mixcloud", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__photobucket.json b/core-blocks/test/fixtures/core-embed__photobucket.json index 06f6ad166720e..d4a5a6031dab5 100644 --- a/core-blocks/test/fixtures/core-embed__photobucket.json +++ b/core-blocks/test/fixtures/core-embed__photobucket.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/photobucket", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__polldaddy.json b/core-blocks/test/fixtures/core-embed__polldaddy.json index 535716f60c12d..1b4fd5fe9c9f8 100644 --- a/core-blocks/test/fixtures/core-embed__polldaddy.json +++ b/core-blocks/test/fixtures/core-embed__polldaddy.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/polldaddy", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__reddit.json b/core-blocks/test/fixtures/core-embed__reddit.json index a7fd9e6d55f87..d3c0a401484be 100644 --- a/core-blocks/test/fixtures/core-embed__reddit.json +++ b/core-blocks/test/fixtures/core-embed__reddit.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/reddit", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__reverbnation.json b/core-blocks/test/fixtures/core-embed__reverbnation.json index ece7946d085ed..4114e247dda08 100644 --- a/core-blocks/test/fixtures/core-embed__reverbnation.json +++ b/core-blocks/test/fixtures/core-embed__reverbnation.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/reverbnation", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__screencast.json b/core-blocks/test/fixtures/core-embed__screencast.json index 76c63405b326d..9439ecc21cbc1 100644 --- a/core-blocks/test/fixtures/core-embed__screencast.json +++ b/core-blocks/test/fixtures/core-embed__screencast.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/screencast", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__scribd.json b/core-blocks/test/fixtures/core-embed__scribd.json index 63f639199cd40..151487f1d9386 100644 --- a/core-blocks/test/fixtures/core-embed__scribd.json +++ b/core-blocks/test/fixtures/core-embed__scribd.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/scribd", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__slideshare.json b/core-blocks/test/fixtures/core-embed__slideshare.json index a23a07895c584..860a12582c580 100644 --- a/core-blocks/test/fixtures/core-embed__slideshare.json +++ b/core-blocks/test/fixtures/core-embed__slideshare.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/slideshare", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__smugmug.json b/core-blocks/test/fixtures/core-embed__smugmug.json index b0ff2bddfcc3b..9b9c253816f2d 100644 --- a/core-blocks/test/fixtures/core-embed__smugmug.json +++ b/core-blocks/test/fixtures/core-embed__smugmug.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/smugmug", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__soundcloud.json b/core-blocks/test/fixtures/core-embed__soundcloud.json index d7cf59e41810c..71917b33b0fcb 100644 --- a/core-blocks/test/fixtures/core-embed__soundcloud.json +++ b/core-blocks/test/fixtures/core-embed__soundcloud.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/soundcloud", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__speaker.json b/core-blocks/test/fixtures/core-embed__speaker.json index ab9f9d5cd6d39..e4fcb3b787622 100644 --- a/core-blocks/test/fixtures/core-embed__speaker.json +++ b/core-blocks/test/fixtures/core-embed__speaker.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/speaker", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__spotify.json b/core-blocks/test/fixtures/core-embed__spotify.json index 00b5e6f3623ca..34ae81f8800c7 100644 --- a/core-blocks/test/fixtures/core-embed__spotify.json +++ b/core-blocks/test/fixtures/core-embed__spotify.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/spotify", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__ted.json b/core-blocks/test/fixtures/core-embed__ted.json index a6604a060ee86..71cf962f2299d 100644 --- a/core-blocks/test/fixtures/core-embed__ted.json +++ b/core-blocks/test/fixtures/core-embed__ted.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/ted", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__tumblr.json b/core-blocks/test/fixtures/core-embed__tumblr.json index 592340674e3d6..d9d8ec226b6d7 100644 --- a/core-blocks/test/fixtures/core-embed__tumblr.json +++ b/core-blocks/test/fixtures/core-embed__tumblr.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/tumblr", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__twitter.json b/core-blocks/test/fixtures/core-embed__twitter.json index 0ffe0dfd18dc7..14f254a84f7d1 100644 --- a/core-blocks/test/fixtures/core-embed__twitter.json +++ b/core-blocks/test/fixtures/core-embed__twitter.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/twitter", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__videopress.json b/core-blocks/test/fixtures/core-embed__videopress.json index 8017be64d89b7..30a559d9c2057 100644 --- a/core-blocks/test/fixtures/core-embed__videopress.json +++ b/core-blocks/test/fixtures/core-embed__videopress.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/videopress", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__vimeo.json b/core-blocks/test/fixtures/core-embed__vimeo.json index 8d83154acabe5..a0f2b798e75a3 100644 --- a/core-blocks/test/fixtures/core-embed__vimeo.json +++ b/core-blocks/test/fixtures/core-embed__vimeo.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/vimeo", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__wordpress-tv.json b/core-blocks/test/fixtures/core-embed__wordpress-tv.json index f674b6dcf279c..7c1f6cf966c82 100644 --- a/core-blocks/test/fixtures/core-embed__wordpress-tv.json +++ b/core-blocks/test/fixtures/core-embed__wordpress-tv.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/wordpress-tv", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__wordpress.json b/core-blocks/test/fixtures/core-embed__wordpress.json index a2daea8c0b3ca..25980b1db72ba 100644 --- a/core-blocks/test/fixtures/core-embed__wordpress.json +++ b/core-blocks/test/fixtures/core-embed__wordpress.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/wordpress", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core-embed__youtube.json b/core-blocks/test/fixtures/core-embed__youtube.json index f969d1225f91a..c98fb7d333cf2 100644 --- a/core-blocks/test/fixtures/core-embed__youtube.json +++ b/core-blocks/test/fixtures/core-embed__youtube.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core-embed/youtube", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__4-invalid-starting-letter.json b/core-blocks/test/fixtures/core__4-invalid-starting-letter.json index 792d06fd6ce23..3439923f417ab 100644 --- a/core-blocks/test/fixtures/core__4-invalid-starting-letter.json +++ b/core-blocks/test/fixtures/core__4-invalid-starting-letter.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/freeform", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__archives.json b/core-blocks/test/fixtures/core__archives.json index 27fd284777b07..0caf2ec732a3d 100644 --- a/core-blocks/test/fixtures/core__archives.json +++ b/core-blocks/test/fixtures/core__archives.json @@ -1,9 +1,13 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/archives", "isValid": true, - "attributes": {}, + "attributes": { + "showPostCounts": false, + "displayAsDropdown": false, + "align": "none" + }, "innerBlocks": [], "originalContent": "" } diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.json b/core-blocks/test/fixtures/core__archives__showPostCounts.json index 27fd284777b07..76d086c472d07 100644 --- a/core-blocks/test/fixtures/core__archives__showPostCounts.json +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.json @@ -1,9 +1,13 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/archives", "isValid": true, - "attributes": {}, + "attributes": { + "showPostCounts": true, + "displayAsDropdown": false, + "align": "none" + }, "innerBlocks": [], "originalContent": "" } diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html b/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html index b8928752375cd..e294016710bd4 100644 --- a/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html @@ -1 +1 @@ - + diff --git a/core-blocks/test/fixtures/core__audio.json b/core-blocks/test/fixtures/core__audio.json index f4dab3b72d162..6d6e5ba5bca66 100644 --- a/core-blocks/test/fixtures/core__audio.json +++ b/core-blocks/test/fixtures/core__audio.json @@ -1,14 +1,14 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/audio", "isValid": true, "attributes": { "src": "https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3", "caption": [], - "align": "right", "autoplay": false, - "loop": false + "loop": false, + "align": "right" }, "innerBlocks": [], "originalContent": "
\n \n
" diff --git a/core-blocks/test/fixtures/core__block.json b/core-blocks/test/fixtures/core__block.json index 02490abb1936a..da89e970b452b 100644 --- a/core-blocks/test/fixtures/core__block.json +++ b/core-blocks/test/fixtures/core__block.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/block", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__button__center.json b/core-blocks/test/fixtures/core__button__center.json index 5965af4df12e8..497b74f660166 100644 --- a/core-blocks/test/fixtures/core__button__center.json +++ b/core-blocks/test/fixtures/core__button__center.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/button", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__categories.json b/core-blocks/test/fixtures/core__categories.json index 96f2240e6b788..ff93919fbcc72 100644 --- a/core-blocks/test/fixtures/core__categories.json +++ b/core-blocks/test/fixtures/core__categories.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/categories", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__code.json b/core-blocks/test/fixtures/core__code.json index 01009fbb64042..0958025736676 100644 --- a/core-blocks/test/fixtures/core__code.json +++ b/core-blocks/test/fixtures/core__code.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/code", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__column.json b/core-blocks/test/fixtures/core__column.json index dc8565eeca31f..427423f08b835 100644 --- a/core-blocks/test/fixtures/core__column.json +++ b/core-blocks/test/fixtures/core__column.json @@ -1,12 +1,12 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/column", "isValid": true, "attributes": {}, "innerBlocks": [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { @@ -19,7 +19,7 @@ "originalContent": "

Column One, Paragraph One

" }, { - "uid": "_uid_1", + "clientId": "_clientId_1", "name": "core/paragraph", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__columns.json b/core-blocks/test/fixtures/core__columns.json index 31c03de312db6..5b234e0980bee 100644 --- a/core-blocks/test/fixtures/core__columns.json +++ b/core-blocks/test/fixtures/core__columns.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/columns", "isValid": true, "attributes": { @@ -8,13 +8,13 @@ }, "innerBlocks": [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/column", "isValid": true, "attributes": {}, "innerBlocks": [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { @@ -27,7 +27,7 @@ "originalContent": "

Column One, Paragraph One

" }, { - "uid": "_uid_1", + "clientId": "_clientId_1", "name": "core/paragraph", "isValid": true, "attributes": { @@ -43,13 +43,13 @@ "originalContent": "
\n\t\t\n\t\t\n\t
" }, { - "uid": "_uid_1", + "clientId": "_clientId_1", "name": "core/column", "isValid": true, "attributes": {}, "innerBlocks": [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { @@ -62,7 +62,7 @@ "originalContent": "

Column Two, Paragraph One

" }, { - "uid": "_uid_1", + "clientId": "_clientId_1", "name": "core/paragraph", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__cover-image.json b/core-blocks/test/fixtures/core__cover-image.json index 7f12304be6f8a..d4e5877c330b7 100644 --- a/core-blocks/test/fixtures/core__cover-image.json +++ b/core-blocks/test/fixtures/core__cover-image.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/cover-image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__embed.json b/core-blocks/test/fixtures/core__embed.json index 69b11621eaac1..ec2cbd732a343 100644 --- a/core-blocks/test/fixtures/core__embed.json +++ b/core-blocks/test/fixtures/core__embed.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/embed", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__file__new-window.json b/core-blocks/test/fixtures/core__file__new-window.json index bc071a02de86a..4922f02880ecc 100644 --- a/core-blocks/test/fixtures/core__file__new-window.json +++ b/core-blocks/test/fixtures/core__file__new-window.json @@ -1,16 +1,16 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/file", "isValid": true, "attributes": { + "id": 176, "href": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "fileName": "6546", "textLinkHref": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "textLinkTarget": "_blank", "showDownloadButton": true, - "downloadButtonText": "Download", - "id": 176 + "downloadButtonText": "Download" }, "innerBlocks": [], "originalContent": "
6546Download
" diff --git a/core-blocks/test/fixtures/core__file__no-download-button.json b/core-blocks/test/fixtures/core__file__no-download-button.json index e7e9b3db7fa1d..dc6e378cc67b3 100644 --- a/core-blocks/test/fixtures/core__file__no-download-button.json +++ b/core-blocks/test/fixtures/core__file__no-download-button.json @@ -1,15 +1,15 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/file", "isValid": true, "attributes": { + "id": 176, "href": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "fileName": "lkjfijwef", "textLinkHref": "http://localhost:8888/?attachment_id=176", "showDownloadButton": false, - "downloadButtonText": "Download", - "id": 176 + "downloadButtonText": "Download" }, "innerBlocks": [], "originalContent": "
lkjfijwef
" diff --git a/core-blocks/test/fixtures/core__file__no-text-link.json b/core-blocks/test/fixtures/core__file__no-text-link.json index 2ab6b80b90041..168733894e2ee 100644 --- a/core-blocks/test/fixtures/core__file__no-text-link.json +++ b/core-blocks/test/fixtures/core__file__no-text-link.json @@ -1,13 +1,13 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/file", "isValid": true, "attributes": { + "id": 176, "href": "http://localhost:8888/wp-content/uploads/2018/05/keycodes.js", "showDownloadButton": true, - "downloadButtonText": "Download", - "id": 176 + "downloadButtonText": "Download" }, "innerBlocks": [], "originalContent": "
Download
" diff --git a/core-blocks/test/fixtures/core__freeform.json b/core-blocks/test/fixtures/core__freeform.json index e71a19e0decae..72341f093f2fb 100644 --- a/core-blocks/test/fixtures/core__freeform.json +++ b/core-blocks/test/fixtures/core__freeform.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/freeform", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__freeform__undelimited.json b/core-blocks/test/fixtures/core__freeform__undelimited.json index e71a19e0decae..72341f093f2fb 100644 --- a/core-blocks/test/fixtures/core__freeform__undelimited.json +++ b/core-blocks/test/fixtures/core__freeform__undelimited.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/freeform", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__gallery.json b/core-blocks/test/fixtures/core__gallery.json index c8aebc9301e4b..0cf9d11b8cfe5 100644 --- a/core-blocks/test/fixtures/core__gallery.json +++ b/core-blocks/test/fixtures/core__gallery.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/gallery", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__gallery__columns.json b/core-blocks/test/fixtures/core__gallery__columns.json index 41614c3387ecb..74dd537db3809 100644 --- a/core-blocks/test/fixtures/core__gallery__columns.json +++ b/core-blocks/test/fixtures/core__gallery__columns.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/gallery", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__heading__h2-em.json b/core-blocks/test/fixtures/core__heading__h2-em.json index cac90a54f382e..ea753522fc29b 100644 --- a/core-blocks/test/fixtures/core__heading__h2-em.json +++ b/core-blocks/test/fixtures/core__heading__h2-em.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/heading", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__heading__h2.json b/core-blocks/test/fixtures/core__heading__h2.json index 24d2e6292ee05..f50eb3b39cd55 100644 --- a/core-blocks/test/fixtures/core__heading__h2.json +++ b/core-blocks/test/fixtures/core__heading__h2.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/heading", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__html.json b/core-blocks/test/fixtures/core__html.json index 1ce1fdf0b9180..cd7cf91f03cdc 100644 --- a/core-blocks/test/fixtures/core__html.json +++ b/core-blocks/test/fixtures/core__html.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/html", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__image.json b/core-blocks/test/fixtures/core__image.json index 1dd6cf0d959f8..159ec45e1a4ca 100644 --- a/core-blocks/test/fixtures/core__image.json +++ b/core-blocks/test/fixtures/core__image.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__image__attachment-link.json b/core-blocks/test/fixtures/core__image__attachment-link.json index 9506785e1a51c..927d2e6699428 100644 --- a/core-blocks/test/fixtures/core__image__attachment-link.json +++ b/core-blocks/test/fixtures/core__image__attachment-link.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__image__center-caption.json b/core-blocks/test/fixtures/core__image__center-caption.json index d7984e879b7e3..c9b19750b1868 100644 --- a/core-blocks/test/fixtures/core__image__center-caption.json +++ b/core-blocks/test/fixtures/core__image__center-caption.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__image__custom-link.json b/core-blocks/test/fixtures/core__image__custom-link.json index 1458fde3a4b40..55e604712ac01 100644 --- a/core-blocks/test/fixtures/core__image__custom-link.json +++ b/core-blocks/test/fixtures/core__image__custom-link.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__image__media-link.json b/core-blocks/test/fixtures/core__image__media-link.json index 2caa892e58091..7e10bde887a5f 100644 --- a/core-blocks/test/fixtures/core__image__media-link.json +++ b/core-blocks/test/fixtures/core__image__media-link.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/image", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__invalid-Capitals.json b/core-blocks/test/fixtures/core__invalid-Capitals.json index a5711c158ceaf..91dc39fca892a 100644 --- a/core-blocks/test/fixtures/core__invalid-Capitals.json +++ b/core-blocks/test/fixtures/core__invalid-Capitals.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/freeform", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__invalid-special.json b/core-blocks/test/fixtures/core__invalid-special.json index f950a3e0272f7..cd026a2a3c405 100644 --- a/core-blocks/test/fixtures/core__invalid-special.json +++ b/core-blocks/test/fixtures/core__invalid-special.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/freeform", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__latest-posts.json b/core-blocks/test/fixtures/core__latest-posts.json index e4138f3c4516a..4579db256b8d1 100644 --- a/core-blocks/test/fixtures/core__latest-posts.json +++ b/core-blocks/test/fixtures/core__latest-posts.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/latest-posts", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__latest-posts__displayPostDate.json b/core-blocks/test/fixtures/core__latest-posts__displayPostDate.json index c08b4aeb226b4..1af4a266a25c2 100644 --- a/core-blocks/test/fixtures/core__latest-posts__displayPostDate.json +++ b/core-blocks/test/fixtures/core__latest-posts__displayPostDate.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/latest-posts", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__list__ul.json b/core-blocks/test/fixtures/core__list__ul.json index 6c6c4fa879c38..ff66a5426b967 100644 --- a/core-blocks/test/fixtures/core__list__ul.json +++ b/core-blocks/test/fixtures/core__list__ul.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/list", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__more.json b/core-blocks/test/fixtures/core__more.json index ea7b6d9b6528d..886638ab06e05 100644 --- a/core-blocks/test/fixtures/core__more.json +++ b/core-blocks/test/fixtures/core__more.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/more", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__more__custom-text-teaser.json b/core-blocks/test/fixtures/core__more__custom-text-teaser.json index 41dfb4b410a3c..7f7811e0d1a54 100644 --- a/core-blocks/test/fixtures/core__more__custom-text-teaser.json +++ b/core-blocks/test/fixtures/core__more__custom-text-teaser.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/more", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__nextpage.json b/core-blocks/test/fixtures/core__nextpage.json index 5ce9cb21fc636..1a2c5478ae6b4 100644 --- a/core-blocks/test/fixtures/core__nextpage.json +++ b/core-blocks/test/fixtures/core__nextpage.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/nextpage", "isValid": true, "attributes": {}, diff --git a/core-blocks/test/fixtures/core__paragraph__align-right.json b/core-blocks/test/fixtures/core__paragraph__align-right.json index 731657d06705f..9d33128ef3af0 100644 --- a/core-blocks/test/fixtures/core__paragraph__align-right.json +++ b/core-blocks/test/fixtures/core__paragraph__align-right.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__paragraph__deprecated.json b/core-blocks/test/fixtures/core__paragraph__deprecated.json index 7fe227a9e14cb..4279147742265 100644 --- a/core-blocks/test/fixtures/core__paragraph__deprecated.json +++ b/core-blocks/test/fixtures/core__paragraph__deprecated.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__preformatted.json b/core-blocks/test/fixtures/core__preformatted.json index d8e03462e4c68..842557c90b428 100644 --- a/core-blocks/test/fixtures/core__preformatted.json +++ b/core-blocks/test/fixtures/core__preformatted.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/preformatted", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__pullquote.json b/core-blocks/test/fixtures/core__pullquote.json index e044ae447f65f..cc8642543873d 100644 --- a/core-blocks/test/fixtures/core__pullquote.json +++ b/core-blocks/test/fixtures/core__pullquote.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/pullquote", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__pullquote__multi-paragraph.json b/core-blocks/test/fixtures/core__pullquote__multi-paragraph.json index 3ce42dbb1e3ae..dfb28dafea49c 100644 --- a/core-blocks/test/fixtures/core__pullquote__multi-paragraph.json +++ b/core-blocks/test/fixtures/core__pullquote__multi-paragraph.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/pullquote", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__quote__style-1.json b/core-blocks/test/fixtures/core__quote__style-1.json index af662dec93e70..f152d155dac51 100644 --- a/core-blocks/test/fixtures/core__quote__style-1.json +++ b/core-blocks/test/fixtures/core__quote__style-1.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/quote", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__quote__style-2.json b/core-blocks/test/fixtures/core__quote__style-2.json index 230306c9fc133..2b910b66eeb1e 100644 --- a/core-blocks/test/fixtures/core__quote__style-2.json +++ b/core-blocks/test/fixtures/core__quote__style-2.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/quote", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__separator.json b/core-blocks/test/fixtures/core__separator.json index 7060deba1c063..12a687c00ac18 100644 --- a/core-blocks/test/fixtures/core__separator.json +++ b/core-blocks/test/fixtures/core__separator.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/separator", "isValid": true, "attributes": {}, diff --git a/core-blocks/test/fixtures/core__shortcode.json b/core-blocks/test/fixtures/core__shortcode.json index 37471b9d68f37..0f1d3e559dcd2 100644 --- a/core-blocks/test/fixtures/core__shortcode.json +++ b/core-blocks/test/fixtures/core__shortcode.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/shortcode", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__spacer.json b/core-blocks/test/fixtures/core__spacer.json index fbc8fa80f61f2..a157520b7563c 100644 --- a/core-blocks/test/fixtures/core__spacer.json +++ b/core-blocks/test/fixtures/core__spacer.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/spacer", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__subhead.json b/core-blocks/test/fixtures/core__subhead.json index c2373ee2781c0..6bee5aa70dc8c 100644 --- a/core-blocks/test/fixtures/core__subhead.json +++ b/core-blocks/test/fixtures/core__subhead.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/subhead", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__table.json b/core-blocks/test/fixtures/core__table.json index 0a38c827b437f..b0ae80fa903d1 100644 --- a/core-blocks/test/fixtures/core__table.json +++ b/core-blocks/test/fixtures/core__table.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/table", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__text-columns.json b/core-blocks/test/fixtures/core__text-columns.json index 44d2a980a68bd..a1f531dd8fe3c 100644 --- a/core-blocks/test/fixtures/core__text-columns.json +++ b/core-blocks/test/fixtures/core__text-columns.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/text-columns", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__text__converts-to-paragraph.json b/core-blocks/test/fixtures/core__text__converts-to-paragraph.json index f9ff727423d80..b2e12e5ce758f 100644 --- a/core-blocks/test/fixtures/core__text__converts-to-paragraph.json +++ b/core-blocks/test/fixtures/core__text__converts-to-paragraph.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/paragraph", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__verse.json b/core-blocks/test/fixtures/core__verse.json index 0f78462328135..b002134e73471 100644 --- a/core-blocks/test/fixtures/core__verse.json +++ b/core-blocks/test/fixtures/core__verse.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/verse", "isValid": true, "attributes": { diff --git a/core-blocks/test/fixtures/core__video.json b/core-blocks/test/fixtures/core__video.json index 8fff277cee4af..7992d3b94fb3e 100644 --- a/core-blocks/test/fixtures/core__video.json +++ b/core-blocks/test/fixtures/core__video.json @@ -1,6 +1,6 @@ [ { - "uid": "_uid_0", + "clientId": "_clientId_0", "name": "core/video", "isValid": true, "attributes": { diff --git a/core-blocks/test/full-content.js b/core-blocks/test/full-content.js index 4e9fa45cdf168..afa71247575ad 100644 --- a/core-blocks/test/full-content.js +++ b/core-blocks/test/full-content.js @@ -80,8 +80,10 @@ function normalizeParsedBlocks( blocks ) { // values that equal `undefined` will be removed block = JSON.parse( JSON.stringify( block ) ); - // Change unique UIDs to a predictable value - block.uid = '_uid_' + index; + // Change client IDs to a predictable value + block.clientId = '_clientId_' + index; + // TODO: Remove in 3.5 "UID" deprecation. + delete block.uid; // Walk each attribute and get a more concise representation of any // React elements diff --git a/core-blocks/test/server-registered.json b/core-blocks/test/server-registered.json index 730013b83cab7..4adfc2b53bcd1 100644 --- a/core-blocks/test/server-registered.json +++ b/core-blocks/test/server-registered.json @@ -1 +1 @@ -{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file +{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/archives":{"attributes":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"align":{"type":"string","default":"none"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file diff --git a/docs/data/data-core-editor.md b/docs/data/data-core-editor.md index 4d687d97cef39..9a8e34a20a430 100644 --- a/docs/data/data-core-editor.md +++ b/docs/data/data-core-editor.md @@ -334,13 +334,13 @@ Document title. ### getBlockName -Returns a block's name given its UID, or null if no block exists with the -UID. +Returns a block's name given its client ID, or null if no block exists with +the client ID. *Parameters* * state: Editor state. - * uid: Block unique ID. + * clientId: Block client ID. *Returns* @@ -352,8 +352,8 @@ Returns the number of blocks currently present in the post. *Parameters* - * state: Global application state. - * rootUID: Optional root UID of block list. + * state: Editor state. + * rootClientId: Optional root client ID of block list. *Returns* @@ -371,7 +371,7 @@ A selection is singular if its start and end match. *Returns* -UID of block selection start. +Client ID of block selection start. ### getBlockSelectionEnd @@ -385,7 +385,7 @@ A selection is singular if its start and end match. *Returns* -UID of block selection end. +Client ID of block selection end. ### getSelectedBlockCount @@ -411,18 +411,18 @@ Returns true if there is a single selected block, or false otherwise. Whether a single block is selected. -### getSelectedBlockUID +### getSelectedBlockClientId -Returns the currently selected block UID, or null if there is no selected -block. +Returns the currently selected block client ID, or null if there is no +selected block. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -Selected block UID. +Selected block client ID. ### getSelectedBlock @@ -436,63 +436,71 @@ Returns the currently selected block, or null if there is no selected block. Selected block. -### getBlockRootUID +### getBlockRootClientId -Given a block UID, returns the root block from which the block is nested, an -empty string for top-level blocks, or null if the block does not exist. +Given a block client ID, returns the root block from which the block is +nested, an empty string for top-level blocks, or null if the block does not +exist. *Parameters* - * state: Global application state. - * uid: Block from which to find root UID. + * state: Editor state. + * clientId: Block from which to find root client ID. *Returns* -Root UID, if exists +Root client ID, if exists -### getAdjacentBlockUid +### getAdjacentBlockClientId -Returns the UID of the block adjacent one at the given reference startUID and modifier -directionality. Defaults start UID to the selected block, and direction as -next block. Returns null if there is no adjacent block. +Returns the client ID of the block adjacent one at the given reference +startClientId and modifier directionality. Defaults start startClientId to +the selected block, and direction as next block. Returns null if there is no +adjacent block. *Parameters* - * state: Global application state. - * startUID: Optional UID of block from which to search. - * modifier: Directionality multiplier (1 next, -1 previous). + * state: Editor state. + * startClientId: Optional client ID of block from which to + search. + * modifier: Directionality multiplier (1 next, -1 + previous). *Returns* -Return the UID of the block, or null if none exists. +Return the client ID of the block, or null if none exists. -### getPreviousBlockUid +### getPreviousBlockClientId -Returns the previous block's UID from the given reference startUID. Defaults start -UID to the selected block. Returns null if there is no previous block. +Returns the previous block's client ID from the given reference start ID. +Defaults start to the selected block. Returns null if there is no previous +block. *Parameters* - * state: Global application state. - * startUID: Optional UID of block from which to search. + * state: Editor state. + * startClientId: Optional client ID of block from which to + search. *Returns* -Adjacent block's UID, or null if none exists. +Adjacent block's client ID, or null if none exists. -### getNextBlockUid +### getNextBlockClientId -Returns the next block's UID from the given reference startUID. Defaults start UID -to the selected block. Returns null if there is no next block. +Returns the next block's client ID from the given reference start ID. +Defaults start to the selected block. Returns null if there is no next +block. *Parameters* - * state: Global application state. - * startUID: Optional UID of block from which to search. + * state: Editor state. + * startClientId: Optional client ID of block from which to + search. *Returns* -Adjacent block's UID, or null if none exists. +Adjacent block's client ID, or null if none exists. ### getSelectedBlocksInitialCaretPosition @@ -507,42 +515,42 @@ This position is to used to position the caret properly when the selected block Selected block. -### getFirstMultiSelectedBlockUid +### getFirstMultiSelectedBlockClientId -Returns the unique ID of the first block in the multi-selection set, or null +Returns the client ID of the first block in the multi-selection set, or null if there is no multi-selection. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -First unique block ID in the multi-selection set. +First block client ID in the multi-selection set. -### getLastMultiSelectedBlockUid +### getLastMultiSelectedBlockClientId -Returns the unique ID of the last block in the multi-selection set, or null +Returns the client ID of the last block in the multi-selection set, or null if there is no multi-selection. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -Last unique block ID in the multi-selection set. +Last block client ID in the multi-selection set. ### isFirstMultiSelectedBlock Returns true if a multi-selection exists, and the block corresponding to the -specified unique ID is the first block of the multi-selection set, or false +specified client ID is the first block of the multi-selection set, or false otherwise. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* @@ -550,76 +558,73 @@ Whether block is first in mult-selection. ### isBlockMultiSelected -Returns true if the unique ID occurs within the block multi-selection, or +Returns true if the client ID occurs within the block multi-selection, or false otherwise. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* Whether block is in multi-selection set. -### getMultiSelectedBlocksStartUid +### getMultiSelectedBlocksStartClientId -Returns the unique ID of the block which begins the multi-selection set, or +Returns the client ID of the block which begins the multi-selection set, or null if there is no multi-selection. -N.b.: This is not necessarily the first uid in the selection. See -getFirstMultiSelectedBlockUid(). +This is not necessarily the first client ID in the selection. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -Unique ID of block beginning multi-selection. +Client ID of block beginning multi-selection. -### getMultiSelectedBlocksEndUid +### getMultiSelectedBlocksEndClientId -Returns the unique ID of the block which ends the multi-selection set, or +Returns the client ID of the block which ends the multi-selection set, or null if there is no multi-selection. -N.b.: This is not necessarily the last uid in the selection. See -getLastMultiSelectedBlockUid(). +This is not necessarily the last client ID in the selection. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -Unique ID of block ending multi-selection. +Client ID of block ending multi-selection. ### getBlockOrder -Returns an array containing all block unique IDs of the post being edited, -in the order they appear in the post. Optionally accepts a root UID of the -block list for which the order should be returned, defaulting to the top- -level block order. +Returns an array containing all block client IDs in the editor in the order +they appear. Optionally accepts a root client ID of the block list for which +the order should be returned, defaulting to the top-level block order. *Parameters* - * state: Global application state. - * rootUID: Optional root UID of block list. + * state: Editor state. + * rootClientId: Optional root client ID of block list. *Returns* -Ordered unique IDs of post blocks. +Ordered client IDs of editor blocks. ### getBlockIndex -Returns the index at which the block corresponding to the specified unique ID -occurs within the post block order, or `-1` if the block does not exist. +Returns the index at which the block corresponding to the specified client +ID occurs within the block order, or `-1` if the block does not exist. *Parameters* - * state: Global application state. - * uid: Block unique ID. - * rootUID: Optional root UID of block list. + * state: Editor state. + * clientId: Block client ID. + * rootClientId: Optional root client ID of block list. *Returns* @@ -627,13 +632,13 @@ Index at which block exists in order. ### isBlockSelected -Returns true if the block corresponding to the specified unique ID is +Returns true if the block corresponding to the specified client ID is currently selected and no multi-selection exists, or false otherwise. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* @@ -645,8 +650,8 @@ Returns true if one of the block's inner blocks is selected. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* @@ -654,20 +659,20 @@ Whether the block as an inner block selected ### isBlockWithinSelection -Returns true if the block corresponding to the specified unique ID is +Returns true if the block corresponding to the specified client ID is currently selected but isn't the last of the selected blocks. Here "last" refers to the block sequence in the document, _not_ the sequence of multi-selection, which is why `state.blockSelection.end` isn't used. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* -Whether block is selected and not the last in - the selection. +Whether block is selected and not the last in the + selection. ### hasMultiSelection @@ -709,12 +714,13 @@ True if multi is disable, false if not. ### getBlockMode -Returns thee block's editing mode. +Returns the block's editing mode, defaulting to "visual" if not explicitly +assigned. *Parameters* - * state: Global application state. - * uid: Block unique ID. + * state: Editor state. + * clientId: Block client ID. *Returns* @@ -739,11 +745,12 @@ be placed. Defaults to the last index. *Parameters* - * state: Global application state. + * state: Editor state. *Returns* -Insertion point object with `rootUID`, `layout`, `index` +Insertion point object with `rootClientId`, `layout`, +`index`. ### isBlockInsertionPointVisible @@ -783,13 +790,13 @@ Block Template ### getTemplateLock -Returns the defined block template lock -in the context of a given root block or in the global context. +Returns the defined block template lock. Optionally accepts a root block +client ID as context, otherwise defaulting to the global context. *Parameters* - * state: null - * rootUID: Block UID. + * state: Editor state. + * rootClientId: Optional block root client ID. *Returns* @@ -936,9 +943,10 @@ Returns true if the post is being published, or false otherwise. Whether post is being published. -### getProvisionalBlockUID +### getProvisionalBlockClientId -Returns the provisional block UID, or null if there is no provisional block. +Returns the provisional block client ID, or null if there is no provisional +block. *Parameters* @@ -946,7 +954,7 @@ Returns the provisional block UID, or null if there is no provisional block. *Returns* -Provisional block UID, if set. +Provisional block client ID, if set. ### isPermalinkEditable @@ -1000,12 +1008,12 @@ Whether predicate matches for some history. ### getBlockListSettings -Returns the Block List settings of a block if any. +Returns the Block List settings of a block, if any exist. *Parameters* * state: Editor state. - * uid: Block UID. + * clientId: Block client ID. *Returns* @@ -1119,23 +1127,36 @@ replacing. ### updateBlockAttributes Returns an action object used in signalling that the block attributes with -the specified UID has been updated. +the specified client ID has been updated. *Parameters* - * uid: Block UID. + * clientId: Block client ID. * attributes: Block attributes to be merged. ### updateBlock Returns an action object used in signalling that the block with the -specified UID has been updated. +specified client ID has been updated. *Parameters* - * uid: Block UID. + * clientId: Block client ID. * updates: Block attributes to be merged. +### selectBlock + +Returns an action object used in signalling that the block with the +specified client ID has been selected, optionally accepting a position +value reflecting its selection directionality. An initialPosition of -1 +reflects a reverse selection. + +*Parameters* + + * clientId: Block client ID. + * initialPosition: Optional initial position. Pass as -1 to + reflect reverse selection. + ### toggleSelection Returns an action object that enables or disables block selection. @@ -1152,7 +1173,7 @@ one or more replacement blocks. *Parameters* - * uids: Block UID(s) to replace. + * clientIds: Block client ID(s) to replace. * blocks: Replacement block(s). ### replaceBlock @@ -1162,7 +1183,7 @@ with one or more replacement blocks. *Parameters* - * uid: Block UID(s) to replace. + * clientId: Block client ID to replace. * block: Replacement block(s). ### moveBlockToPosition @@ -1172,10 +1193,10 @@ to a new index. *Parameters* - * uid: The UID of the block. - * fromRootUID: root UID source. - * toRootUID: root UID destination. - * layout: layout to move the block into. + * clientId: The client ID of the block. + * fromRootClientId: Root client ID source. + * toRootClientId: Root client ID destination. + * layout: Layout to move the block into. * index: The index to move the block into. ### insertBlock @@ -1187,7 +1208,8 @@ inserted, optionally at a specific index respective a root block list. * block: Block object to insert. * index: Index at which block should be inserted. - * rootUID: Optional root UID of block list to insert. + * rootClientId: Optional root client ID of block list on which + to insert. ### insertBlocks @@ -1198,7 +1220,8 @@ be inserted, optionally at a specific index respective a root block list. * blocks: Block objects to insert. * index: Index at which block should be inserted. - * rootUID: Optional root UID of block list to insert. + * rootClientId: Optional root cliente ID of block list on + which to insert. ### showInsertionPoint @@ -1240,8 +1263,8 @@ Returns an action object used in signalling that two blocks should be merged *Parameters* - * blockAUid: UID of the first block to merge. - * blockBUid: UID of the second block to merge. + * firstBlockClientId: Client ID of the first block to merge. + * secondBlockClientId: Client ID of the second block to merge. ### autosave @@ -1263,31 +1286,34 @@ be created. ### removeBlocks -Returns an action object used in signalling that the blocks -corresponding to the specified UID set are to be removed. +Returns an action object used in signalling that the blocks corresponding to +the set of specified client IDs are to be removed. *Parameters* - * uids: Block UIDs. - * selectPrevious: True if the previous block should be selected when a block is removed. + * clientIds: Client IDs of blocks to remove. + * selectPrevious: True if the previous block should be + selected when a block is removed. ### removeBlock Returns an action object used in signalling that the block with the -specified UID is to be removed. +specified client ID is to be removed. *Parameters* - * uid: Block UID. - * selectPrevious: True if the previous block should be selected when a block is removed. + * clientId: Client ID of block to remove. + * selectPrevious: True if the previous block should be + selected when a block is removed. ### toggleBlockMode -Returns an action object used to toggle the block editing mode (visual/html). +Returns an action object used to toggle the block editing mode between +visual and HTML modes. *Parameters* - * uid: Block UID. + * clientId: Block client ID. ### startTyping @@ -1371,7 +1397,7 @@ Returns an action object used to convert a shared block into a static block. *Parameters* - * uid: The ID of the block to attach. + * clientId: The client ID of the block to attach. ### convertBlockToShared @@ -1379,7 +1405,7 @@ Returns an action object used to convert a static block into a shared block. *Parameters* - * uid: The ID of the block to detach. + * clientId: The client ID of the block to detach. ### insertDefaultBlock @@ -1389,7 +1415,8 @@ type should be added to the block list. *Parameters* * attributes: Optional attributes of the block to assign. - * rootUID: Optional root UID of block list to append. + * rootClientId: Optional root client ID of block list on which + to append. * index: Optional index where to insert the default block ### updateBlockListSettings @@ -1398,7 +1425,8 @@ Returns an action object that changes the nested settings of a given block. *Parameters* - * id: UID of the block whose nested setting. + * clientId: Client ID of the block whose nested setting are + being received. * settings: Object with the new settings for the nested block. ### updateEditorSettings diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 9a816ad4c5fea..1b5e736f61753 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -12,12 +12,13 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo - `wp.element.createHigherOrderComponent` has been removed. Please use `wp.compose.createHigherOrderComponent` instead. - `wp.utils.buildTermsTree` has been removed. - `wp.utils.decodeEntities` has been removed. Please use `wp.htmlEntities.decodeEntities` instead. + - All references to a block's `uid` have been replaced with equivalent props and selectors for `clientId`. ## 3.4.0 - `focusOnMount` prop in the `Popover` component has been changed from `Boolean`-only to an enum-style property that accepts `"firstElement"`, `"container"`, or `false`. Please convert any `` usage to ``. - `wp.utils.keycodes` utilities are removed. Please use `wp.keycodes` instead. - - Block `id` prop in `edit` function removed. Please use block `clientId` prop instead. + - Block `id` prop in `edit` function removed. Please use block `clientId` prop instead. ## 3.3.0 diff --git a/edit-post/components/visual-editor/style.scss b/edit-post/components/visual-editor/style.scss index 0337b9dfd2dc1..cf5a44c16ebcb 100644 --- a/edit-post/components/visual-editor/style.scss +++ b/edit-post/components/visual-editor/style.scss @@ -73,7 +73,7 @@ // The centering math changes when a fullwide image doesn't have block padding. &[data-align="full"] > .editor-block-contextual-toolbar { width: calc( 100% + #{ ( $parent-block-padding * 2 ) + ( $block-padding * 2 ) } ); // Matches the negative margins applied to non-parent blocks, except for borders which are gone in fullwide. - + .editor-block-toolbar { max-width: $content-width - $border-width - $border-width; } @@ -136,7 +136,7 @@ margin-right: auto; position: relative; - &[data-root-uid=""] .editor-default-block-appender__content:hover { + &[data-root-client-id=""] .editor-default-block-appender__content:hover { // Outline on root-level default block appender is redundant with the // WritingFlow click redirector. outline: 1px solid transparent; diff --git a/edit-post/hooks/validate-multiple-use/index.js b/edit-post/hooks/validate-multiple-use/index.js index 68b9ce5178add..7a165bfbec71c 100644 --- a/edit-post/hooks/validate-multiple-use/index.js +++ b/edit-post/hooks/validate-multiple-use/index.js @@ -21,16 +21,16 @@ import { __ } from '@wordpress/i18n'; import { compose, createHigherOrderComponent } from '@wordpress/compose'; const enhance = compose( - /* - * For blocks whose block type doesn't support `multiple`, provides the wrapped - * component with `originalBlockUid` -- a reference to the first block of - * the same type in the content -- if and only if that "original" block is - * not the current one. Thus, an inexisting `originalBlockUid` prop signals - * that the block is valid. + /** + * For blocks whose block type doesn't support `multiple`, provides the + * wrapped component with `originalBlockClientId` -- a reference to the + * first block of the same type in the content -- if and only if that + * "original" block is not the current one. Thus, an inexisting + * `originalBlockClientId` prop signals that the block is valid. * * @param {Component} WrappedBlockEdit A filtered BlockEdit instance. - * @return {Component} Enhanced component with merged state - * data props. + * + * @return {Component} Enhanced component with merged state data props. */ withSelect( ( select, block ) => { const blocks = select( 'core/editor' ).getBlocks(); @@ -42,26 +42,26 @@ const enhance = compose( return {}; } - // Otherwise, only pass `originalBlockUid` if it refers to a different + // Otherwise, only pass `originalBlockClientId` if it refers to a different // block from the current one. const firstOfSameType = find( blocks, ( { name } ) => block.name === name ); - const isInvalid = firstOfSameType && firstOfSameType.uid !== block.id; + const isInvalid = firstOfSameType && firstOfSameType.clientId !== block.clientId; return { - originalBlockUid: isInvalid && firstOfSameType.uid, + originalBlockClientId: isInvalid && firstOfSameType.clientId, }; } ), - withDispatch( ( dispatch, { originalBlockUid } ) => ( { - selectFirst: () => dispatch( 'core/editor' ).selectBlock( originalBlockUid ), + withDispatch( ( dispatch, { originalBlockClientId } ) => ( { + selectFirst: () => dispatch( 'core/editor' ).selectBlock( originalBlockClientId ), } ) ), ); const withMultipleValidation = createHigherOrderComponent( ( BlockEdit ) => { return enhance( ( { - originalBlockUid, + originalBlockClientId, selectFirst, ...props } ) => { - if ( ! originalBlockUid ) { + if ( ! originalBlockClientId ) { return ; } diff --git a/editor/components/autocompleters/block.js b/editor/components/autocompleters/block.js index 7fe94e60402a7..963137e4eb40b 100644 --- a/editor/components/autocompleters/block.js +++ b/editor/components/autocompleters/block.js @@ -11,29 +11,34 @@ import './style.scss'; import BlockIcon from '../block-icon'; /** - * Get the UID of the parent where a newly inserted block would be placed. + * Returns the client ID of the parent where a newly inserted block would be + * placed. * - * @return {string} The UID of the parent where a newly inserted block would be placed. + * @return {string} Client ID of the parent where a newly inserted block would + * be placed. */ -function defaultGetBlockInsertionParentUID() { - return select( 'core/editor' ).getBlockInsertionPoint().rootUID; +function defaultGetBlockInsertionParentClientId() { + return select( 'core/editor' ).getBlockInsertionPoint().rootClientId; } /** - * Get the inserter items for the specified parent block. + * Returns the inserter items for the specified parent block. * - * @param {string} parentUID The UID of the block for which to retrieve inserter items. + * @param {string} parentClientId Client ID of the block for which to retrieve + * inserter items. * - * @return {Array} The inserter items for the specified parent. + * @return {Array} The inserter items for the specified + * parent. */ -function defaultGetInserterItems( parentUID ) { - return select( 'core/editor' ).getInserterItems( parentUID ); +function defaultGetInserterItems( parentClientId ) { + return select( 'core/editor' ).getInserterItems( parentClientId ); } /** - * Get the name of the currently selected block. + * Returns the name of the currently selected block. * - * @return {string?} The name of the currently selected block or `null` if no block is selected. + * @return {string?} The name of the currently selected block or `null` if no + * block is selected. */ function defaultGetSelectedBlockName() { const selectedBlock = select( 'core/editor' ).getSelectedBlock(); @@ -47,7 +52,7 @@ function defaultGetSelectedBlockName() { */ export function createBlockCompleter( { // Allow store-based selectors to be overridden for unit test. - getBlockInsertionParentUID = defaultGetBlockInsertionParentUID, + getBlockInsertionParentClientId = defaultGetBlockInsertionParentClientId, getInserterItems = defaultGetInserterItems, getSelectedBlockName = defaultGetSelectedBlockName, } = {} ) { @@ -57,7 +62,7 @@ export function createBlockCompleter( { triggerPrefix: '/', options() { const selectedBlockName = getSelectedBlockName(); - return getInserterItems( getBlockInsertionParentUID() ).filter( + return getInserterItems( getBlockInsertionParentClientId() ).filter( // Avoid offering to replace the current block with a block of the same type. ( inserterItem ) => selectedBlockName !== inserterItem.name ); diff --git a/editor/components/autocompleters/test/block.js b/editor/components/autocompleters/test/block.js index 07d5b57d2496b..379433adf858f 100644 --- a/editor/components/autocompleters/test/block.js +++ b/editor/components/autocompleters/test/block.js @@ -11,17 +11,17 @@ import blockCompleter, { createBlockCompleter } from '../block'; describe( 'block', () => { it( 'should retrieve block options for current insertion point', () => { const expectedOptions = [ {}, {}, {} ]; - const mockGetBlockInsertionParentUID = jest.fn( () => 'expected-insertion-point' ); + const mockGetBlockInsertionParentClientId = jest.fn( () => 'expected-insertion-point' ); const mockGetInserterItems = jest.fn( () => expectedOptions ); const completer = createBlockCompleter( { - getBlockInsertionParentUID: mockGetBlockInsertionParentUID, + getBlockInsertionParentClientId: mockGetBlockInsertionParentClientId, getInserterItems: mockGetInserterItems, getSelectedBlockName: () => 'non-existent-block-name', } ); const actualOptions = completer.options(); - expect( mockGetBlockInsertionParentUID ).toHaveBeenCalled(); + expect( mockGetBlockInsertionParentClientId ).toHaveBeenCalled(); expect( mockGetInserterItems ).toHaveBeenCalledWith( 'expected-insertion-point' ); expect( actualOptions ).toEqual( expectedOptions ); } ); @@ -32,7 +32,7 @@ describe( 'block', () => { const option3 = { name: 'block-3' }; const completer = createBlockCompleter( { - getBlockInsertionParentUID: () => 'ignored', + getBlockInsertionParentClientId: () => 'ignored', getInserterItems: () => [ option1, option2CurrentlySelected, option3 ], getSelectedBlockName: () => 'block-2-currently-selected', } ); diff --git a/editor/components/block-drop-zone/index.js b/editor/components/block-drop-zone/index.js index b249125018ba9..94b1108055b46 100644 --- a/editor/components/block-drop-zone/index.js +++ b/editor/components/block-drop-zone/index.js @@ -65,10 +65,10 @@ class BlockDropZone extends Component { return; } - let uid, type, rootUID, fromIndex; + let clientId, type, rootClientId, fromIndex; try { - ( { uid, type, rootUID, fromIndex } = JSON.parse( event.dataTransfer.getData( 'text' ) ) ); + ( { clientId, type, rootClientId, fromIndex } = JSON.parse( event.dataTransfer.getData( 'text' ) ) ); } catch ( err ) { return; } @@ -81,8 +81,8 @@ class BlockDropZone extends Component { // If the block is kept at the same level and moved downwards, subtract // to account for blocks shifting upward to occupy its old position. - const insertIndex = index && fromIndex < index && rootUID === this.props.rootUID ? positionIndex - 1 : positionIndex; - this.props.moveBlockToPosition( uid, rootUID, insertIndex ); + const insertIndex = index && fromIndex < index && rootClientId === this.props.rootClientId ? positionIndex - 1 : positionIndex; + this.props.moveBlockToPosition( clientId, rootClientId, insertIndex ); } render() { @@ -115,7 +115,7 @@ export default compose( return { insertBlocks( blocks, insertIndex ) { - const { rootUID, layout } = ownProps; + const { rootClientId, layout } = ownProps; if ( layout ) { // A block's transform function may return a single @@ -127,21 +127,21 @@ export default compose( ) ); } - insertBlocks( blocks, insertIndex, rootUID ); + insertBlocks( blocks, insertIndex, rootClientId ); }, updateBlockAttributes( ...args ) { updateBlockAttributes( ...args ); }, - moveBlockToPosition( uid, fromRootUID, index ) { - const { rootUID, layout } = ownProps; - moveBlockToPosition( uid, fromRootUID, rootUID, layout, index ); + moveBlockToPosition( clientId, fromRootClientId, index ) { + const { rootClientId, layout } = ownProps; + moveBlockToPosition( clientId, fromRootClientId, rootClientId, layout, index ); }, }; } ), - withSelect( ( select, { rootUID } ) => { + withSelect( ( select, { rootClientId } ) => { const { getTemplateLock } = select( 'core/editor' ); return { - isLocked: !! getTemplateLock( rootUID ), + isLocked: !! getTemplateLock( rootClientId ), }; } ) )( BlockDropZone ); diff --git a/editor/components/block-edit/context.js b/editor/components/block-edit/context.js index 99591d0fdb321..863cdc3e5d6fa 100644 --- a/editor/components/block-edit/context.js +++ b/editor/components/block-edit/context.js @@ -14,7 +14,7 @@ const { Consumer, Provider } = createContext( { isSelected: false, focusedElement: null, setFocusedElement: noop, - uid: null, + clientId: null, } ); export { Provider as BlockEditContextProvider }; diff --git a/editor/components/block-edit/edit.js b/editor/components/block-edit/edit.js index 4deaa389581be..f9ba6b0cc1e3f 100644 --- a/editor/components/block-edit/edit.js +++ b/editor/components/block-edit/edit.js @@ -28,9 +28,11 @@ export const Edit = ( props ) => { // them preferentially as the render value for the block. const Component = blockType.edit || blockType.save; + // TODO: `id` prop is to be removed in 3.5 "UID" deprecation. return ( ); diff --git a/editor/components/block-edit/index.js b/editor/components/block-edit/index.js index 87ddb69ca4803..d42f151da1a89 100644 --- a/editor/components/block-edit/index.js +++ b/editor/components/block-edit/index.js @@ -8,6 +8,7 @@ import { Component } from '@wordpress/element'; */ import Edit from './edit'; import { BlockEditContextProvider } from './context'; +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; class BlockEdit extends Component { constructor( props ) { @@ -31,12 +32,12 @@ class BlockEdit extends Component { } static getDerivedStateFromProps( props ) { - const { id, name, isSelected } = props; + const { clientId, name, isSelected } = props; return { name, isSelected, - uid: id, + clientId, }; } @@ -49,4 +50,4 @@ class BlockEdit extends Component { } } -export default BlockEdit; +export default withDeprecatedUniqueId( BlockEdit ); diff --git a/editor/components/block-list/block-draggable.js b/editor/components/block-list/block-draggable.js index 3c6ccabaf99a7..67f77189b36bd 100644 --- a/editor/components/block-list/block-draggable.js +++ b/editor/components/block-list/block-draggable.js @@ -8,7 +8,7 @@ import classnames from 'classnames'; */ import { Draggable } from '@wordpress/components'; -function BlockDraggable( { rootUID, index, uid, layout, isDragging, ...props } ) { +function BlockDraggable( { rootClientId, index, clientId, layout, isDragging, ...props } ) { const className = classnames( 'editor-block-list__block-draggable', { 'is-visible': isDragging, } ); @@ -16,8 +16,8 @@ function BlockDraggable( { rootUID, index, uid, layout, isDragging, ...props } ) const transferData = { type: 'block', fromIndex: index, - rootUID, - uid, + rootClientId, + clientId, layout, }; diff --git a/editor/components/block-list/block-html.js b/editor/components/block-list/block-html.js index bd5a18a90b4a5..3c70ebcfd8b92 100644 --- a/editor/components/block-list/block-html.js +++ b/editor/components/block-list/block-html.js @@ -35,7 +35,7 @@ class BlockHTML extends Component { const blockType = getBlockType( this.props.block.name ); const attributes = getBlockAttributes( blockType, this.state.html, this.props.block.attributes ); const isValid = isValidBlock( this.state.html, blockType, attributes ); - this.props.onChange( this.props.uid, attributes, this.state.html, isValid ); + this.props.onChange( this.props.clientId, attributes, this.state.html, isValid ); } onChange( event ) { @@ -57,11 +57,11 @@ class BlockHTML extends Component { export default compose( [ withSelect( ( select, ownProps ) => ( { - block: select( 'core/editor' ).getBlock( ownProps.uid ), + block: select( 'core/editor' ).getBlock( ownProps.clientId ), } ) ), withDispatch( ( dispatch ) => ( { - onChange( uid, attributes, originalContent, isValid ) { - dispatch( 'core/editor' ).updateBlock( uid, { attributes, originalContent, isValid } ); + onChange( clientId, attributes, originalContent, isValid ) { + dispatch( 'core/editor' ).updateBlock( clientId, { attributes, originalContent, isValid } ); }, } ) ), ] )( BlockHTML ); diff --git a/editor/components/block-list/block-mobile-toolbar.js b/editor/components/block-list/block-mobile-toolbar.js index 0595abdeb18b1..317f0e2022f02 100644 --- a/editor/components/block-list/block-mobile-toolbar.js +++ b/editor/components/block-list/block-mobile-toolbar.js @@ -10,12 +10,12 @@ import BlockMover from '../block-mover'; import BlockSettingsMenu from '../block-settings-menu'; import VisualEditorInserter from '../inserter'; -function BlockMobileToolbar( { rootUID, uid } ) { +function BlockMobileToolbar( { rootClientId, clientId } ) { return (
- - + +
); } diff --git a/editor/components/block-list/block.js b/editor/components/block-list/block.js index 0d4ec67a6b7a6..59635b73cb80e 100644 --- a/editor/components/block-list/block.js +++ b/editor/components/block-list/block.js @@ -107,7 +107,7 @@ export class BlockListBlock extends Component { this.wrapperNode = node; - this.props.blockRef( node, this.props.uid ); + this.props.blockRef( node, this.props.clientId ); } bindBlockNode( node ) { @@ -166,7 +166,7 @@ export class BlockListBlock extends Component { setAttributes( attributes ) { const { block, onChange } = this.props; const type = getBlockType( block.name ); - onChange( block.uid, attributes ); + onChange( block.clientId, attributes ); const metaAttributes = reduce( attributes, ( result, value, key ) => { if ( get( type, [ 'attributes', key, 'source' ] ) === 'meta' ) { @@ -229,20 +229,20 @@ export class BlockListBlock extends Component { } mergeBlocks( forward = false ) { - const { block, previousBlockUid, nextBlockUid, onMerge } = this.props; + const { block, previousBlockClientId, nextBlockClientId, onMerge } = this.props; // Do nothing when it's the first block. if ( - ( ! forward && ! previousBlockUid ) || - ( forward && ! nextBlockUid ) + ( ! forward && ! previousBlockClientId ) || + ( forward && ! nextBlockClientId ) ) { return; } if ( forward ) { - onMerge( block.uid, nextBlockUid ); + onMerge( block.clientId, nextBlockClientId ); } else { - onMerge( previousBlockUid, block.uid ); + onMerge( previousBlockClientId, block.clientId ); } } @@ -291,11 +291,11 @@ export class BlockListBlock extends Component { if ( event.shiftKey ) { if ( ! this.props.isSelected ) { - this.props.onShiftSelection( this.props.uid ); + this.props.onShiftSelection( this.props.clientId ); event.preventDefault(); } } else { - this.props.onSelectionStart( this.props.uid ); + this.props.onSelectionStart( this.props.clientId ); // Allow user to escape out of a multi-selection to a singular // selection of a block via click. This is handled here since @@ -334,11 +334,11 @@ export class BlockListBlock extends Component { case BACKSPACE: case DELETE: // Remove block on backspace. - const { uid, onRemove, previousBlockUid, onSelect } = this.props; - onRemove( uid ); + const { clientId, onRemove, previousBlockClientId, onSelect } = this.props; + onRemove( clientId ); - if ( previousBlockUid ) { - onSelect( previousBlockUid, -1 ); + if ( previousBlockClientId ) { + onSelect( previousBlockClientId, -1 ); } event.preventDefault(); break; @@ -372,8 +372,8 @@ export class BlockListBlock extends Component { isLocked, isFirst, isLast, - uid, - rootUID, + clientId, + rootClientId, layout, isSelected, isPartOfMultiSelection, @@ -437,7 +437,7 @@ export class BlockListBlock extends Component { ...blockType.getEditWrapperProps( block.attributes ), }; } - const blockElementId = `block-${ uid }`; + const blockElementId = `block-${ clientId }`; // Disable reasons: // @@ -471,9 +471,9 @@ export class BlockListBlock extends Component { > { ! isPartOfMultiSelection && isMovable && ( { shouldRenderMovers && ( ) } - { shouldShowBreadcrumb && } + { shouldShowBreadcrumb && ( + + ) } { shouldShowContextualToolbar && } - { isFirstMultiSelected && } + { isFirstMultiSelected && ( + + ) } { isValid && mode === 'visual' && ( @@ -532,14 +539,13 @@ export class BlockListBlock extends Component { insertBlocksAfter={ isLocked ? undefined : this.insertBlocksAfter } onReplace={ isLocked ? undefined : onReplace } mergeBlocks={ isLocked ? undefined : this.mergeBlocks } - clientId={ uid } - id={ uid } + clientId={ clientId } isSelectionEnabled={ this.props.isSelectionEnabled } toggleSelection={ this.props.toggleSelection } /> ) } { isValid && mode === 'html' && ( - + ) } { ! isValid && [
@@ -553,8 +559,8 @@ export class BlockListBlock extends Component { { shouldShowMobileToolbar && ( ) } @@ -562,7 +568,12 @@ export class BlockListBlock extends Component { { showEmptyBlockSideInserter && (
- +
{ +const applyWithSelect = withSelect( ( select, { clientId, rootClientId } ) => { const { isBlockSelected, - getPreviousBlockUid, - getNextBlockUid, + getPreviousBlockClientId, + getNextBlockClientId, getBlock, isAncestorMultiSelected, isBlockMultiSelected, @@ -598,33 +609,33 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => { hasSelectedInnerBlock, getTemplateLock, } = select( 'core/editor' ); - const isSelected = isBlockSelected( uid ); - const isParentOfSelectedBlock = hasSelectedInnerBlock( uid ); + const isSelected = isBlockSelected( clientId ); + const isParentOfSelectedBlock = hasSelectedInnerBlock( clientId ); const { hasFixedToolbar } = getEditorSettings(); - const block = getBlock( uid ); - const previousBlockUid = getPreviousBlockUid( uid ); - const previousBlock = getBlock( previousBlockUid ); - const templateLock = getTemplateLock( rootUID ); + const block = getBlock( clientId ); + const previousBlockClientId = getPreviousBlockClientId( clientId ); + const previousBlock = getBlock( previousBlockClientId ); + const templateLock = getTemplateLock( rootClientId ); return { - nextBlockUid: getNextBlockUid( uid ), - isPartOfMultiSelection: isBlockMultiSelected( uid ) || isAncestorMultiSelected( uid ), - isFirstMultiSelected: isFirstMultiSelectedBlock( uid ), + nextBlockClientId: getNextBlockClientId( clientId ), + isPartOfMultiSelection: isBlockMultiSelected( clientId ) || isAncestorMultiSelected( clientId ), + isFirstMultiSelected: isFirstMultiSelectedBlock( clientId ), isMultiSelecting: isMultiSelecting(), hasSelectedInnerBlock: isParentOfSelectedBlock, // We only care about this prop when the block is selected // Thus to avoid unnecessary rerenders we avoid updating the prop if the block is not selected. isTypingWithinBlock: ( isSelected || isParentOfSelectedBlock ) && isTyping(), - order: getBlockIndex( uid, rootUID ), + order: getBlockIndex( clientId, rootClientId ), meta: getEditedPostAttribute( 'meta' ), - mode: getBlockMode( uid ), + mode: getBlockMode( clientId ), isSelectionEnabled: isSelectionEnabled(), initialPosition: getSelectedBlocksInitialCaretPosition(), isEmptyDefaultBlock: block && isUnmodifiedDefaultBlock( block ), isPreviousBlockADefaultEmptyBlock: previousBlock && isUnmodifiedDefaultBlock( previousBlock ), isMovable: 'all' !== templateLock, isLocked: !! templateLock, - previousBlockUid, + previousBlockClientId, block, isSelected, hasFixedToolbar, @@ -645,23 +656,23 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { } = dispatch( 'core/editor' ); return { - onChange( uid, attributes ) { - updateBlockAttributes( uid, attributes ); + onChange( clientId, attributes ) { + updateBlockAttributes( clientId, attributes ); }, - onSelect( uid = ownProps.uid, initialPosition ) { - selectBlock( uid, initialPosition ); + onSelect( clientId = ownProps.clientId, initialPosition ) { + selectBlock( clientId, initialPosition ); }, onInsertBlocks( blocks, index ) { - const { rootUID, layout } = ownProps; + const { rootClientId, layout } = ownProps; blocks = blocks.map( ( block ) => cloneBlock( block, { layout } ) ); - insertBlocks( blocks, index, rootUID ); + insertBlocks( blocks, index, rootClientId ); }, onInsertDefaultBlockAfter() { - const { order, rootUID } = ownProps; - insertDefaultBlock( {}, rootUID, order + 1 ); + const { order, rootClientId } = ownProps; + insertDefaultBlock( {}, rootClientId, order + 1 ); }, - onRemove( uid ) { - removeBlock( uid ); + onRemove( clientId ) { + removeBlock( clientId ); }, onMerge( ...args ) { mergeBlocks( ...args ); @@ -671,7 +682,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { blocks = castArray( blocks ).map( ( block ) => ( cloneBlock( block, { layout } ) ) ); - replaceBlocks( [ ownProps.uid ], blocks ); + replaceBlocks( [ ownProps.clientId ], blocks ); }, onMetaChange( meta ) { editPost( { meta } ); diff --git a/editor/components/block-list/breadcrumb.js b/editor/components/block-list/breadcrumb.js index c78b39d21c4c6..16a95fbd7e0af 100644 --- a/editor/components/block-list/breadcrumb.js +++ b/editor/components/block-list/breadcrumb.js @@ -16,8 +16,8 @@ import BlockTitle from '../block-title'; * descends from a root block, a button is displayed enabling the user to select * the root block. * - * @param {string} props.uid UID of block. - * @param {string} props.rootUID UID of block's root. + * @param {string} props.clientId Client ID of block. + * @param {string} props.rootClientId Client ID of block's root. * @param {Function} props.selectRootBlock Callback to select root block. */ export class BlockBreadcrumb extends Component { @@ -48,18 +48,18 @@ export class BlockBreadcrumb extends Component { } render( ) { - const { uid, rootUID } = this.props; + const { clientId, rootClientId } = this.props; return (
- { rootUID && ( + { rootClientId && ( - + ) } - +
); @@ -68,11 +68,11 @@ export class BlockBreadcrumb extends Component { export default compose( [ withSelect( ( select, ownProps ) => { - const { getBlockRootUID } = select( 'core/editor' ); - const { uid } = ownProps; + const { getBlockRootClientId } = select( 'core/editor' ); + const { clientId } = ownProps; return { - rootUID: getBlockRootUID( uid ), + rootClientId: getBlockRootClientId( clientId ), }; } ), ] )( BlockBreadcrumb ); diff --git a/editor/components/block-list/index.js b/editor/components/block-list/index.js index 89edaab7a80c2..32897ad623f9c 100644 --- a/editor/components/block-list/index.js +++ b/editor/components/block-list/index.js @@ -21,13 +21,13 @@ import BlockListLayout from './layout'; const UngroupedLayoutBlockList = withSelect( ( select, ownProps ) => ( { - blockUIDs: select( 'core/editor' ).getBlockOrder( ownProps.rootUID ), + blockClientIds: select( 'core/editor' ).getBlockOrder( ownProps.rootClientId ), } ) )( BlockListLayout ); const GroupedLayoutBlockList = withSelect( ( select, ownProps ) => ( { - blocks: select( 'core/editor' ).getBlocks( ownProps.rootUID ), + blocks: select( 'core/editor' ).getBlocks( ownProps.rootClientId ), } ), )( ( { blocks, @@ -35,9 +35,9 @@ const GroupedLayoutBlockList = withSelect( ...props } ) => map( layouts, ( layout ) => { // Filter blocks assigned to layout when rendering grouped layouts. - const layoutBlockUIDs = reduce( blocks, ( result, block ) => { + const layoutBlockClientIds = reduce( blocks, ( result, block ) => { if ( get( block, [ 'attributes', 'layout' ] ) === layout.name ) { - result.push( block.uid ); + result.push( block.clientId ); } return result; @@ -48,7 +48,7 @@ const GroupedLayoutBlockList = withSelect( key={ layout.name } layout={ layout.name } isGroupedByLayout - blockUIDs={ layoutBlockUIDs } + blockClientIds={ layoutBlockClientIds } { ...props } /> ); diff --git a/editor/components/block-list/insertion-point.js b/editor/components/block-list/insertion-point.js index 67a78a251d3a5..022423d64014b 100644 --- a/editor/components/block-list/insertion-point.js +++ b/editor/components/block-list/insertion-point.js @@ -42,8 +42,8 @@ class BlockInsertionPoint extends Component { } onClick() { - const { layout, rootUID, index, ...props } = this.props; - props.insertDefaultBlock( { layout }, rootUID, index ); + const { layout, rootClientId, index, ...props } = this.props; + props.insertDefaultBlock( { layout }, rootClientId, index ); props.startTyping(); this.onBlurInserter(); if ( props.onInsert ) { @@ -75,7 +75,7 @@ class BlockInsertionPoint extends Component { } } export default compose( - withSelect( ( select, { uid, rootUID, canShowInserter } ) => { + withSelect( ( select, { clientId, rootClientId, canShowInserter } ) => { const { canInsertBlockType, getBlockIndex, @@ -87,20 +87,20 @@ export default compose( const { getDefaultBlockName, } = select( 'core/blocks' ); - const blockIndex = uid ? getBlockIndex( uid, rootUID ) : -1; + const blockIndex = clientId ? getBlockIndex( clientId, rootClientId ) : -1; const insertIndex = blockIndex; const insertionPoint = getBlockInsertionPoint(); - const block = uid ? getBlock( uid ) : null; + const block = clientId ? getBlock( clientId ) : null; const showInsertionPoint = ( isBlockInsertionPointVisible() && insertionPoint.index === insertIndex && - insertionPoint.rootUID === rootUID && + insertionPoint.rootClientId === rootClientId && ( ! block || ! isUnmodifiedDefaultBlock( block ) ) ); const defaultBlockName = getDefaultBlockName(); return { - canInsertDefaultBlock: canInsertBlockType( defaultBlockName, rootUID ), + canInsertDefaultBlock: canInsertBlockType( defaultBlockName, rootClientId ), showInserter: ! isTyping() && canShowInserter, index: insertIndex, showInsertionPoint, diff --git a/editor/components/block-list/invalid-block-warning.js b/editor/components/block-list/invalid-block-warning.js index e3ab117339c98..059a10ca886d1 100644 --- a/editor/components/block-list/invalid-block-warning.js +++ b/editor/components/block-list/invalid-block-warning.js @@ -40,12 +40,12 @@ export default withDispatch( ( dispatch, { block } ) => { const { replaceBlock } = dispatch( 'core/editor' ); return { convertToHTML() { - replaceBlock( block.uid, createBlock( 'core/html', { + replaceBlock( block.clientId, createBlock( 'core/html', { content: block.originalContent, } ) ); }, convertToBlocks() { - replaceBlock( block.uid, rawHandler( { + replaceBlock( block.clientId, rawHandler( { HTML: block.originalContent, mode: 'BLOCKS', } ) ); diff --git a/editor/components/block-list/layout.js b/editor/components/block-list/layout.js index 1b28a663b121b..5f1706fe40e9b 100644 --- a/editor/components/block-list/layout.js +++ b/editor/components/block-list/layout.js @@ -28,6 +28,7 @@ import './style.scss'; import BlockListBlock from './block'; import IgnoreNestedEvents from './ignore-nested-events'; import DefaultBlockAppender from '../default-block-appender'; +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; class BlockListLayout extends Component { constructor( props ) { @@ -59,13 +60,13 @@ class BlockListLayout extends Component { this.lastClientY = clientY; } - setBlockRef( node, uid ) { + setBlockRef( node, clientId ) { if ( node === null ) { - delete this.nodes[ uid ]; + delete this.nodes[ clientId ]; } else { this.nodes = { ...this.nodes, - [ uid ]: node, + [ clientId ]: node, }; } } @@ -96,28 +97,28 @@ class BlockListLayout extends Component { * Binds event handlers to the document for tracking a pending multi-select * in response to a mousedown event occurring in a rendered block. * - * @param {string} uid UID of the block where mousedown occurred. + * @param {string} clientId Client ID of block where mousedown occurred. * * @return {void} */ - onSelectionStart( uid ) { + onSelectionStart( clientId ) { if ( ! this.props.isSelectionEnabled ) { return; } - const boundaries = this.nodes[ uid ].getBoundingClientRect(); + const boundaries = this.nodes[ clientId ].getBoundingClientRect(); - // Create a uid to Y coördinate map. - const uidToCoordMap = mapValues( this.nodes, ( node ) => + // Create a clientId to Y coördinate map. + const clientIdToCoordMap = mapValues( this.nodes, ( node ) => node.getBoundingClientRect().top - boundaries.top ); - // Cache a Y coördinate to uid map for use in `onPointerMove`. - this.coordMap = invert( uidToCoordMap ); + // Cache a Y coördinate to clientId map for use in `onPointerMove`. + this.coordMap = invert( clientIdToCoordMap ); // Cache an array of the Y coördinates for use in `onPointerMove`. // Sort the coördinates, as `this.nodes` will not necessarily reflect // the current block sequence. - this.coordMapKeys = sortBy( Object.values( uidToCoordMap ) ); - this.selectionAtStart = uid; + this.coordMapKeys = sortBy( Object.values( clientIdToCoordMap ) ); + this.selectionAtStart = clientId; window.addEventListener( 'mousemove', this.onPointerMove ); // Capture scroll on all elements. @@ -128,12 +129,13 @@ class BlockListLayout extends Component { /** * Handles multi-selection changes in response to pointer move. * - * @param {string} uid Block under cursor in multi-select drag. + * @param {string} clientId Client ID of block under cursor in multi-select + * drag. */ - onSelectionChange( uid ) { + onSelectionChange( clientId ) { const { onMultiSelect, selectionStart, selectionEnd } = this.props; const { selectionAtStart } = this; - const isAtStart = selectionAtStart === uid; + const isAtStart = selectionAtStart === clientId; if ( ! selectionAtStart || ! this.props.isSelectionEnabled ) { return; @@ -146,8 +148,8 @@ class BlockListLayout extends Component { } // Expand multi-selection to block under cursor. - if ( ! isAtStart && selectionEnd !== uid ) { - onMultiSelect( selectionAtStart, uid ); + if ( ! isAtStart && selectionEnd !== clientId ) { + onMultiSelect( selectionAtStart, clientId ); } } @@ -175,26 +177,26 @@ class BlockListLayout extends Component { } } - onShiftSelection( uid ) { + onShiftSelection( clientId ) { if ( ! this.props.isSelectionEnabled ) { return; } - const { selectionStartUID, onMultiSelect, onSelect } = this.props; + const { selectionStartClientId, onMultiSelect, onSelect } = this.props; - if ( selectionStartUID ) { - onMultiSelect( selectionStartUID, uid ); + if ( selectionStartClientId ) { + onMultiSelect( selectionStartClientId, clientId ); } else { - onSelect( uid ); + onSelect( clientId ); } } render() { const { - blockUIDs, + blockClientIds, layout, isGroupedByLayout, - rootUID, + rootClientId, canInsertDefaultBlock, } = this.props; @@ -209,25 +211,25 @@ class BlockListLayout extends Component { return (
- { map( blockUIDs, ( uid, blockIndex ) => ( + { map( blockClientIds, ( clientId, blockIndex ) => ( ) ) } { canInsertDefaultBlock && ( @@ -238,24 +240,25 @@ class BlockListLayout extends Component { } export default compose( [ + withDeprecatedUniqueId, withSelect( ( select, ownProps ) => { const { isSelectionEnabled, isMultiSelecting, - getMultiSelectedBlocksStartUid, - getMultiSelectedBlocksEndUid, + getMultiSelectedBlocksStartClientId, + getMultiSelectedBlocksEndClientId, getBlockSelectionStart, canInsertBlockType, } = select( 'core/editor' ); - const { rootUID } = ownProps; + const { rootClientId } = ownProps; return { - selectionStart: getMultiSelectedBlocksStartUid(), - selectionEnd: getMultiSelectedBlocksEndUid(), - selectionStartUID: getBlockSelectionStart(), + selectionStart: getMultiSelectedBlocksStartClientId(), + selectionEnd: getMultiSelectedBlocksEndClientId(), + selectionStartClientId: getBlockSelectionStart(), isSelectionEnabled: isSelectionEnabled(), isMultiSelecting: isMultiSelecting(), - canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootUID ), + canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootClientId ), }; } ), withDispatch( ( dispatch ) => { diff --git a/editor/components/block-list/multi-controls.js b/editor/components/block-list/multi-controls.js index 6c5e1deda30f9..0141484e1594a 100644 --- a/editor/components/block-list/multi-controls.js +++ b/editor/components/block-list/multi-controls.js @@ -14,7 +14,13 @@ import { withSelect } from '@wordpress/data'; import BlockMover from '../block-mover'; import BlockSettingsMenu from '../block-settings-menu'; -function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting, isFirst, isLast } ) { +function BlockListMultiControls( { + multiSelectedBlockClientIds, + clientId, + isSelecting, + isFirst, + isLast, +} ) { if ( isSelecting ) { return null; } @@ -22,33 +28,33 @@ function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting, return [ , , ]; } -export default withSelect( ( select, { rootUID } ) => { +export default withSelect( ( select, { clientId } ) => { const { - getMultiSelectedBlockUids, + getMultiSelectedBlockClientIds, isMultiSelecting, getBlockIndex, getBlockCount, } = select( 'core/editor' ); - const uids = getMultiSelectedBlockUids(); - const firstIndex = getBlockIndex( first( uids ), rootUID ); - const lastIndex = getBlockIndex( last( uids ), rootUID ); + const clientIds = getMultiSelectedBlockClientIds(); + const firstIndex = getBlockIndex( first( clientIds ), clientId ); + const lastIndex = getBlockIndex( last( clientIds ), clientId ); return { - multiSelectedBlockUids: uids, + multiSelectedBlockClientIds: clientIds, isSelecting: isMultiSelecting(), isFirst: firstIndex === 0, isLast: lastIndex + 1 === getBlockCount(), diff --git a/editor/components/block-mover/index.js b/editor/components/block-mover/index.js index e9205feb890c7..a76199f995ed7 100644 --- a/editor/components/block-mover/index.js +++ b/editor/components/block-mover/index.js @@ -20,6 +20,7 @@ import { withInstanceId, compose } from '@wordpress/compose'; import './style.scss'; import { getBlockMoverDescription } from './mover-description'; import { upArrow, downArrow } from './arrows'; +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; export class BlockMover extends Component { constructor() { @@ -44,9 +45,9 @@ export class BlockMover extends Component { } render() { - const { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex, isLocked, instanceId, isHidden } = this.props; + const { onMoveUp, onMoveDown, isFirst, isLast, clientIds, blockType, firstIndex, isLocked, instanceId, isHidden } = this.props; const { isFocused } = this.state; - const blocksCount = castArray( uids ).length; + const blocksCount = castArray( clientIds ).length; if ( isLocked ) { return null; } @@ -107,22 +108,23 @@ export class BlockMover extends Component { } export default compose( - withSelect( ( select, { uids, rootUID } ) => { + withDeprecatedUniqueId, + withSelect( ( select, { clientIds, rootClientId } ) => { const { getBlock, getBlockIndex, getTemplateLock } = select( 'core/editor' ); - const firstUID = first( castArray( uids ) ); - const block = getBlock( firstUID ); + const firstClientId = first( castArray( clientIds ) ); + const block = getBlock( firstClientId ); return { - firstIndex: getBlockIndex( firstUID, rootUID ), + firstIndex: getBlockIndex( firstClientId, rootClientId ), blockType: block ? getBlockType( block.name ) : null, - isLocked: getTemplateLock( rootUID ) === 'all', + isLocked: getTemplateLock( rootClientId ) === 'all', }; } ), - withDispatch( ( dispatch, { uids, rootUID } ) => { + withDispatch( ( dispatch, { clientIds, rootClientId } ) => { const { moveBlocksDown, moveBlocksUp } = dispatch( 'core/editor' ); return { - onMoveDown: partial( moveBlocksDown, uids, rootUID ), - onMoveUp: partial( moveBlocksUp, uids, rootUID ), + onMoveDown: partial( moveBlocksDown, clientIds, rootClientId ), + onMoveUp: partial( moveBlocksUp, clientIds, rootClientId ), }; } ), withInstanceId, diff --git a/editor/components/block-mover/test/index.js b/editor/components/block-mover/test/index.js index 0391cc068e772..e22973b71f78f 100644 --- a/editor/components/block-mover/test/index.js +++ b/editor/components/block-mover/test/index.js @@ -11,7 +11,7 @@ import { upArrow, downArrow } from '../arrows'; describe( 'BlockMover', () => { describe( 'basic rendering', () => { - const selectedUids = [ 'IisUID', 'IisOtherUID' ]; + const selectedClientIds = [ 'IisClientId', 'IisOtherClientId' ]; const blockType = { title: 'yolo-block', @@ -23,7 +23,13 @@ describe( 'BlockMover', () => { } ); it( 'should render two IconButton components with the following props', () => { - const blockMover = shallow( ); + const blockMover = shallow( + + ); expect( blockMover.hasClass( 'editor-block-mover' ) ).toBe( true ); const moveUp = blockMover.childAt( 0 ); @@ -55,10 +61,12 @@ describe( 'BlockMover', () => { it( 'should render the up arrow with a onMoveUp callback', () => { const onMoveUp = ( event ) => event; const blockMover = shallow( - + firstIndex={ 0 } + /> ); const moveUp = blockMover.childAt( 0 ); expect( moveUp.prop( 'onClick' ) ).toBe( onMoveUp ); @@ -67,10 +75,12 @@ describe( 'BlockMover', () => { it( 'should render the down arrow with a onMoveDown callback', () => { const onMoveDown = ( event ) => event; const blockMover = shallow( - + firstIndex={ 0 } + /> ); const moveDown = blockMover.childAt( 1 ); expect( moveDown.prop( 'onClick' ) ).toBe( onMoveDown ); @@ -79,11 +89,13 @@ describe( 'BlockMover', () => { it( 'should render with a disabled up arrow when the block isFirst', () => { const onMoveUp = ( event ) => event; const blockMover = shallow( - + firstIndex={ 0 } + /> ); const moveUp = blockMover.childAt( 0 ); expect( moveUp.props() ).toMatchObject( { @@ -95,11 +107,13 @@ describe( 'BlockMover', () => { it( 'should render with a disabled down arrow when the block isLast', () => { const onMoveDown = ( event ) => event; const blockMover = shallow( - + firstIndex={ 0 } + /> ); const moveDown = blockMover.childAt( 1 ); expect( moveDown.props() ).toMatchObject( { diff --git a/editor/components/block-settings-menu/block-duplicate-button.js b/editor/components/block-settings-menu/block-duplicate-button.js index e44529480ab73..72c7e4be27c18 100644 --- a/editor/components/block-settings-menu/block-duplicate-button.js +++ b/editor/components/block-settings-menu/block-duplicate-button.js @@ -36,24 +36,32 @@ export function BlockDuplicateButton( { blocks, onDuplicate, onClick = noop, isL } export default compose( - withSelect( ( select, { uids, rootUID } ) => { - const { getBlocksByUID, getBlockIndex, getTemplateLock } = select( 'core/editor' ); + withSelect( ( select, { clientIds, rootClientId } ) => { + const { + getBlocksByClientId, + getBlockIndex, + getTemplateLock, + } = select( 'core/editor' ); + return { - blocks: getBlocksByUID( uids ), - index: getBlockIndex( last( castArray( uids ) ), rootUID ), - isLocked: !! getTemplateLock( rootUID ), + blocks: getBlocksByClientId( clientIds ), + index: getBlockIndex( last( castArray( clientIds ) ), rootClientId ), + isLocked: !! getTemplateLock( rootClientId ), }; } ), - withDispatch( ( dispatch, { blocks, index, rootUID } ) => ( { + withDispatch( ( dispatch, { blocks, index, rootClientId } ) => ( { onDuplicate() { const clonedBlocks = blocks.map( ( block ) => cloneBlock( block ) ); dispatch( 'core/editor' ).insertBlocks( clonedBlocks, index + 1, - rootUID + rootClientId ); if ( clonedBlocks.length > 1 ) { - dispatch( 'core/editor' ).multiSelect( first( clonedBlocks ).uid, last( clonedBlocks ).uid ); + dispatch( 'core/editor' ).multiSelect( + first( clonedBlocks ).clientId, + last( clonedBlocks ).clientId + ); } }, } ) ), diff --git a/editor/components/block-settings-menu/block-html-convert-button.js b/editor/components/block-settings-menu/block-html-convert-button.js index 4809eae9dac08..6403e28bff12a 100644 --- a/editor/components/block-settings-menu/block-html-convert-button.js +++ b/editor/components/block-settings-menu/block-html-convert-button.js @@ -11,9 +11,9 @@ import { withSelect, withDispatch } from '@wordpress/data'; import BlockConvertButton from './block-convert-button'; export default compose( - withSelect( ( select, { uid } ) => { + withSelect( ( select, { clientId } ) => { const { getBlock, canUserUseUnfilteredHTML } = select( 'core/editor' ); - const block = getBlock( uid ); + const block = getBlock( clientId ); return { block, canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), @@ -22,7 +22,7 @@ export default compose( } ), withDispatch( ( dispatch, { block, canUserUseUnfilteredHTML } ) => ( { onClick: () => dispatch( 'core/editor' ).replaceBlocks( - block.uid, + block.clientId, rawHandler( { HTML: getBlockContent( block ), mode: 'BLOCKS', diff --git a/editor/components/block-settings-menu/block-mode-toggle.js b/editor/components/block-settings-menu/block-mode-toggle.js index 61d1af42d6550..bb5899bb1a608 100644 --- a/editor/components/block-settings-menu/block-mode-toggle.js +++ b/editor/components/block-settings-menu/block-mode-toggle.js @@ -35,18 +35,18 @@ export function BlockModeToggle( { blockType, mode, onToggleMode, small = false, } export default compose( [ - withSelect( ( select, { uid } ) => { + withSelect( ( select, { clientId } ) => { const { getBlock, getBlockMode } = select( 'core/editor' ); - const block = getBlock( uid ); + const block = getBlock( clientId ); return { - mode: getBlockMode( uid ), + mode: getBlockMode( clientId ), blockType: block ? getBlockType( block.name ) : null, }; } ), - withDispatch( ( dispatch, { onToggle = noop, uid } ) => ( { + withDispatch( ( dispatch, { onToggle = noop, clientId } ) => ( { onToggleMode() { - dispatch( 'core/editor' ).toggleBlockMode( uid ); + dispatch( 'core/editor' ).toggleBlockMode( clientId ); onToggle(); }, } ) ), diff --git a/editor/components/block-settings-menu/block-remove-button.js b/editor/components/block-settings-menu/block-remove-button.js index 00a63b4eeb18c..d45486099115c 100644 --- a/editor/components/block-settings-menu/block-remove-button.js +++ b/editor/components/block-settings-menu/block-remove-button.js @@ -33,17 +33,21 @@ export function BlockRemoveButton( { onRemove, onClick = noop, isLocked, role, . } export default compose( - withDispatch( ( dispatch, { uids } ) => ( { + withDispatch( ( dispatch, { clientIds } ) => ( { onRemove() { - dispatch( 'core/editor' ).removeBlocks( uids ); + dispatch( 'core/editor' ).removeBlocks( clientIds ); }, } ) ), - withSelect( ( select, { uids } ) => { - const { getBlockRootUID, getTemplateLock } = select( 'core/editor' ); + withSelect( ( select, { clientIds } ) => { + const { + getBlockRootClientId, + getTemplateLock, + } = select( 'core/editor' ); + return { - isLocked: some( castArray( uids ), ( uid ) => { - const rootUID = getBlockRootUID( uid ); - const templateLock = getTemplateLock( rootUID ); + isLocked: some( castArray( clientIds ), ( clientId ) => { + const rootClientId = getBlockRootClientId( clientId ); + const templateLock = getTemplateLock( rootClientId ); return templateLock === 'all'; } ), }; diff --git a/editor/components/block-settings-menu/block-unknown-convert-button.js b/editor/components/block-settings-menu/block-unknown-convert-button.js index f31e54f65e101..f87149710455f 100644 --- a/editor/components/block-settings-menu/block-unknown-convert-button.js +++ b/editor/components/block-settings-menu/block-unknown-convert-button.js @@ -11,9 +11,9 @@ import { withSelect, withDispatch } from '@wordpress/data'; import BlockConvertButton from './block-convert-button'; export default compose( - withSelect( ( select, { uid } ) => { + withSelect( ( select, { clientId } ) => { const { canUserUseUnfilteredHTML, getBlock } = select( 'core/editor' ); - const block = getBlock( uid ); + const block = getBlock( clientId ); return { block, canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), @@ -22,7 +22,7 @@ export default compose( } ), withDispatch( ( dispatch, { block, canUserUseUnfilteredHTML } ) => ( { onClick: () => dispatch( 'core/editor' ).replaceBlocks( - block.uid, + block.clientId, rawHandler( { HTML: serialize( block ), mode: 'BLOCKS', diff --git a/editor/components/block-settings-menu/index.js b/editor/components/block-settings-menu/index.js index 02c70aba77fdd..3491ee7f8be3b 100644 --- a/editor/components/block-settings-menu/index.js +++ b/editor/components/block-settings-menu/index.js @@ -11,6 +11,7 @@ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { IconButton, Dropdown, NavigableMenu } from '@wordpress/components'; import { withDispatch } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; /** * Internal dependencies @@ -24,6 +25,7 @@ import SharedBlockDeleteButton from './shared-block-delete-button'; import BlockHTMLConvertButton from './block-html-convert-button'; import BlockUnknownConvertButton from './block-unknown-convert-button'; import _BlockSettingsMenuFirstItem from './block-settings-menu-first-item'; +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; export class BlockSettingsMenu extends Component { constructor() { @@ -49,16 +51,16 @@ export class BlockSettingsMenu extends Component { render() { const { - uids, + clientIds, onSelect, focus, - rootUID, + rootClientId, isHidden, } = this.props; const { isFocused } = this.state; - const blockUIDs = castArray( uids ); - const count = blockUIDs.length; - const firstBlockUID = blockUIDs[ 0 ]; + const blockClientIds = castArray( clientIds ); + const count = blockClientIds.length; + const firstBlockClientId = blockClientIds[ 0 ]; return (
@@ -77,7 +79,7 @@ export class BlockSettingsMenu extends Component { className={ toggleClassname } onClick={ () => { if ( count === 1 ) { - onSelect( firstBlockUID ); + onSelect( firstBlockClientId ); } onToggle(); } } @@ -94,14 +96,49 @@ export class BlockSettingsMenu extends Component { // Should this just use a DropdownMenu instead of a DropDown ? <_BlockSettingsMenuFirstItem.Slot fillProps={ { onClose } } /> - { count === 1 && } - { count === 1 && } - { count === 1 && } - - { count === 1 && } + { count === 1 && ( + + ) } + { count === 1 && ( + + ) } + { count === 1 && ( + + ) } + + { count === 1 && ( + + ) }
- { count === 1 && } - + { count === 1 && ( + + ) } + ) } /> @@ -110,8 +147,11 @@ export class BlockSettingsMenu extends Component { } } -export default withDispatch( ( dispatch ) => ( { - onSelect( uid ) { - dispatch( 'core/editor' ).selectBlock( uid ); - }, -} ) )( BlockSettingsMenu ); +export default compose( [ + withDeprecatedUniqueId, + withDispatch( ( dispatch ) => ( { + onSelect( clientId ) { + dispatch( 'core/editor' ).selectBlock( clientId ); + }, + } ) ), +] )( BlockSettingsMenu ); diff --git a/editor/components/block-settings-menu/shared-block-convert-button.js b/editor/components/block-settings-menu/shared-block-convert-button.js index 8fa70535413c0..5f7f9e1ee15ff 100644 --- a/editor/components/block-settings-menu/shared-block-convert-button.js +++ b/editor/components/block-settings-menu/shared-block-convert-button.js @@ -51,11 +51,11 @@ export function SharedBlockConvertButton( { } export default compose( [ - withSelect( ( select, { uid } ) => { + withSelect( ( select, { clientId } ) => { const { getBlock, getSharedBlock } = select( 'core/editor' ); const { getFallbackBlockName } = select( 'core/blocks' ); - const block = getBlock( uid ); + const block = getBlock( clientId ); if ( ! block ) { return { isVisible: false }; } @@ -67,7 +67,7 @@ export default compose( [ isStaticBlock: ! isSharedBlock( block ) || ! getSharedBlock( block.attributes.ref ), }; } ), - withDispatch( ( dispatch, { uid, onToggle = noop } ) => { + withDispatch( ( dispatch, { clientId, onToggle = noop } ) => { const { convertBlockToShared, convertBlockToStatic, @@ -75,11 +75,11 @@ export default compose( [ return { onConvertToStatic() { - convertBlockToStatic( uid ); + convertBlockToStatic( clientId ); onToggle(); }, onConvertToShared() { - convertBlockToShared( uid ); + convertBlockToShared( clientId ); onToggle(); }, }; diff --git a/editor/components/block-settings-menu/shared-block-delete-button.js b/editor/components/block-settings-menu/shared-block-delete-button.js index e08e23ba2c998..7f2e196a0d150 100644 --- a/editor/components/block-settings-menu/shared-block-delete-button.js +++ b/editor/components/block-settings-menu/shared-block-delete-button.js @@ -31,9 +31,9 @@ export function SharedBlockDeleteButton( { sharedBlock, onDelete, itemsRole } ) } export default compose( [ - withSelect( ( select, { uid } ) => { + withSelect( ( select, { clientId } ) => { const { getBlock, getSharedBlock } = select( 'core/editor' ); - const block = getBlock( uid ); + const block = getBlock( clientId ); return { sharedBlock: block && isSharedBlock( block ) ? getSharedBlock( block.attributes.ref ) : null, }; diff --git a/editor/components/block-styles/index.js b/editor/components/block-styles/index.js index 0a308dcd70be3..5a89fcd38cf71 100644 --- a/editor/components/block-styles/index.js +++ b/editor/components/block-styles/index.js @@ -135,8 +135,8 @@ function BlockStyles( { } export default compose( [ - withSelect( ( select, { uid } ) => { - const block = select( 'core/editor' ).getBlock( uid ); + withSelect( ( select, { clientId } ) => { + const block = select( 'core/editor' ).getBlock( clientId ); return { name: block.name, @@ -145,10 +145,12 @@ export default compose( [ styles: get( getBlockType( block.name ), [ 'styles' ] ), }; } ), - withDispatch( ( dispatch, { uid } ) => { + withDispatch( ( dispatch, { clientId } ) => { return { onChangeClassName( newClassName ) { - dispatch( 'core/editor' ).updateBlockAttributes( uid, { className: newClassName } ); + dispatch( 'core/editor' ).updateBlockAttributes( clientId, { + className: newClassName, + } ); }, }; } ), diff --git a/editor/components/block-switcher/index.js b/editor/components/block-switcher/index.js index b62c1a1b9e6d2..9c9fc1a4ee3e3 100644 --- a/editor/components/block-switcher/index.js +++ b/editor/components/block-switcher/index.js @@ -91,7 +91,11 @@ export class BlockSwitcher extends Component { title={ __( 'Block Styles' ) } initialOpen > - + } { allowedBlocks.length !== 0 && ! isLocked && @@ -129,16 +133,19 @@ export class BlockSwitcher extends Component { export default compose( withSelect( ( select, ownProps ) => { - const { getBlock, getBlockRootUID, getTemplateLock } = select( 'core/editor' ); + const { getBlock, getBlockRootClientId, getTemplateLock } = select( 'core/editor' ); return { - blocks: ownProps.uids.map( getBlock ), - isLocked: some( castArray( ownProps.uids ), ( uid ) => !! getTemplateLock( getBlockRootUID( uid ) ) ), + blocks: ownProps.clientIds.map( getBlock ), + isLocked: some( + castArray( ownProps.clientIds ), + ( clientId ) => !! getTemplateLock( getBlockRootClientId( clientId ) ) + ), }; } ), withDispatch( ( dispatch, ownProps ) => ( { onTransform( blocks, name ) { dispatch( 'core/editor' ).replaceBlocks( - ownProps.uids, + ownProps.clientIds, switchToBlockType( blocks, name ) ); }, diff --git a/editor/components/block-switcher/multi-blocks-switcher.js b/editor/components/block-switcher/multi-blocks-switcher.js index 1dc4cc21974fe..eeb9da3a39b82 100644 --- a/editor/components/block-switcher/multi-blocks-switcher.js +++ b/editor/components/block-switcher/multi-blocks-switcher.js @@ -9,21 +9,21 @@ import { withSelect } from '@wordpress/data'; import './style.scss'; import BlockSwitcher from './'; -export function MultiBlocksSwitcher( { isMultiBlockSelection, selectedBlockUids } ) { +export function MultiBlocksSwitcher( { isMultiBlockSelection, selectedBlockClientIds } ) { if ( ! isMultiBlockSelection ) { return null; } return ( - + ); } export default withSelect( ( select ) => { - const selectedBlockUids = select( 'core/editor' ).getMultiSelectedBlockUids(); + const selectedBlockClientIds = select( 'core/editor' ).getMultiSelectedBlockClientIds(); return { - isMultiBlockSelection: selectedBlockUids.length > 1, - selectedBlockUids, + isMultiBlockSelection: selectedBlockClientIds.length > 1, + selectedBlockClientIds, }; } )( MultiBlocksSwitcher ); diff --git a/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap b/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap index c35141f5834c4..a550bb9a06d91 100644 --- a/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap +++ b/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap @@ -2,12 +2,12 @@ exports[`MultiBlocksSwitcher should return a BlockSwitcher element matching the snapshot. 1`] = ` `; diff --git a/editor/components/block-switcher/test/index.js b/editor/components/block-switcher/test/index.js index 17220fc9dedd3..fc1487b948a3d 100644 --- a/editor/components/block-switcher/test/index.js +++ b/editor/components/block-switcher/test/index.js @@ -23,7 +23,7 @@ describe( 'BlockSwitcher', () => { isValid: true, name: 'core/heading', originalContent: '

How are you?

', - uid: 'a1303fd6-3e60-4fff-a770-0e0ea656c5b9', + clientId: 'a1303fd6-3e60-4fff-a770-0e0ea656c5b9', }; const textBlock = { @@ -33,7 +33,7 @@ describe( 'BlockSwitcher', () => { isValid: true, name: 'core/text', originalContent: '

I am great!

', - uid: 'b1303fdb-3e60-43faf-a770-2e1ea656c5b8', + clientId: 'b1303fdb-3e60-43faf-a770-2e1ea656c5b8', }; const headingBlock2 = { @@ -44,7 +44,7 @@ describe( 'BlockSwitcher', () => { isValid: true, name: 'core/text', originalContent: '

I am the greatest!

', - uid: 'c2403fd2-4e63-5ffa-b71c-1e0ea656c5b0', + clientId: 'c2403fd2-4e63-5ffa-b71c-1e0ea656c5b0', }; beforeAll( () => { diff --git a/editor/components/block-switcher/test/multi-blocks-switcher.js b/editor/components/block-switcher/test/multi-blocks-switcher.js index 37935f47788f6..30199f6c59852 100644 --- a/editor/components/block-switcher/test/multi-blocks-switcher.js +++ b/editor/components/block-switcher/test/multi-blocks-switcher.js @@ -11,13 +11,13 @@ import { MultiBlocksSwitcher } from '../multi-blocks-switcher'; describe( 'MultiBlocksSwitcher', () => { test( 'should return null when the selection is not a multi block selection.', () => { const isMultiBlockSelection = false; - const selectedBlockUids = [ - 'an-uid', + const selectedBlockClientIds = [ + 'clientid', ]; const wrapper = shallow( ); @@ -26,14 +26,14 @@ describe( 'MultiBlocksSwitcher', () => { test( 'should return a BlockSwitcher element matching the snapshot.', () => { const isMultiBlockSelection = true; - const selectedBlockUids = [ - 'an-uid', - 'another-uid', + const selectedBlockClientIds = [ + 'clientid-1', + 'clientid-2', ]; const wrapper = shallow( ); diff --git a/editor/components/block-title/README.md b/editor/components/block-title/README.md index 9bf6964f44d11..1e22d83dba461 100644 --- a/editor/components/block-title/README.md +++ b/editor/components/block-title/README.md @@ -6,5 +6,5 @@ Renders the block's configured title as a string, or empty if the title cannot b ## Usage ```jsx - + ``` diff --git a/editor/components/block-title/index.js b/editor/components/block-title/index.js index 0dd1c1232f768..5c729247d8a25 100644 --- a/editor/components/block-title/index.js +++ b/editor/components/block-title/index.js @@ -3,6 +3,12 @@ */ import { withSelect } from '@wordpress/data'; import { getBlockType } from '@wordpress/blocks'; +import { compose } from '@wordpress/compose'; + +/** + * Internal dependencies + */ +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; /** * Renders the block's configured title as a string, or empty if the title @@ -11,7 +17,7 @@ import { getBlockType } from '@wordpress/blocks'; * @example * * ```jsx - * + * * ``` * * @param {?string} props.name Block name. @@ -31,11 +37,14 @@ export function BlockTitle( { name } ) { return blockType.title; } -export default withSelect( ( select, ownProps ) => { - const { getBlockName } = select( 'core/editor' ); - const { uid } = ownProps; +export default compose( [ + withDeprecatedUniqueId, + withSelect( ( select, ownProps ) => { + const { getBlockName } = select( 'core/editor' ); + const { clientId } = ownProps; - return { - name: getBlockName( uid ), - }; -} )( BlockTitle ); + return { + name: getBlockName( clientId ), + }; + } ), +] )( BlockTitle ); diff --git a/editor/components/block-toolbar/index.js b/editor/components/block-toolbar/index.js index f3a4df5e385f2..8d573ccdc3336 100644 --- a/editor/components/block-toolbar/index.js +++ b/editor/components/block-toolbar/index.js @@ -12,8 +12,8 @@ import MultiBlocksSwitcher from '../block-switcher/multi-blocks-switcher'; import BlockControls from '../block-controls'; import BlockFormatControls from '../block-format-controls'; -function BlockToolbar( { blockUIDs, isValid, mode } ) { - if ( blockUIDs.length > 1 ) { +function BlockToolbar( { blockClientIds, isValid, mode } ) { + if ( blockClientIds.length > 1 ) { return (
@@ -27,7 +27,7 @@ function BlockToolbar( { blockUIDs, isValid, mode } ) { return (
- +
@@ -35,13 +35,19 @@ function BlockToolbar( { blockUIDs, isValid, mode } ) { } export default withSelect( ( select ) => { - const { getSelectedBlock, getBlockMode, getMultiSelectedBlockUids } = select( 'core/editor' ); + const { + getSelectedBlock, + getBlockMode, + getMultiSelectedBlockClientIds, + } = select( 'core/editor' ); const block = getSelectedBlock(); - const blockUIDs = block ? [ block.uid ] : getMultiSelectedBlockUids(); + const blockClientIds = block ? + [ block.clientId ] : + getMultiSelectedBlockClientIds(); return { - blockUIDs, + blockClientIds, isValid: block ? block.isValid : null, - mode: block ? getBlockMode( block.uid ) : null, + mode: block ? getBlockMode( block.clientId ) : null, }; } )( BlockToolbar ); diff --git a/editor/components/copy-handler/index.js b/editor/components/copy-handler/index.js index 7c2d40497fc82..fb5a205c0b892 100644 --- a/editor/components/copy-handler/index.js +++ b/editor/components/copy-handler/index.js @@ -46,12 +46,12 @@ class CopyHandler extends Component { } onCut( event ) { - const { multiSelectedBlockUids } = this.props; + const { multiSelectedBlockClientIds } = this.props; this.onCopy( event ); - if ( multiSelectedBlockUids.length ) { - this.props.onRemove( multiSelectedBlockUids ); + if ( multiSelectedBlockClientIds.length ) { + this.props.onRemove( multiSelectedBlockClientIds ); } } @@ -64,12 +64,12 @@ export default compose( [ withSelect( ( select ) => { const { getMultiSelectedBlocks, - getMultiSelectedBlockUids, + getMultiSelectedBlockClientIds, getSelectedBlock, } = select( 'core/editor' ); return { multiSelectedBlocks: getMultiSelectedBlocks(), - multiSelectedBlockUids: getMultiSelectedBlockUids(), + multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(), selectedBlock: getSelectedBlock(), }; } ), diff --git a/editor/components/default-block-appender/index.js b/editor/components/default-block-appender/index.js index 3c07149a33530..415c089b90962 100644 --- a/editor/components/default-block-appender/index.js +++ b/editor/components/default-block-appender/index.js @@ -21,6 +21,7 @@ import './style.scss'; import BlockDropZone from '../block-drop-zone'; import InserterWithShortcuts from '../inserter-with-shortcuts'; import Inserter from '../inserter'; +import withDeprecatedUniqueId from '../with-deprecated-unique-id'; export function DefaultBlockAppender( { isLocked, @@ -29,7 +30,7 @@ export function DefaultBlockAppender( { showPrompt, placeholder, layout, - rootUID, + rootClientId, hasTip, } ) { if ( isLocked || ! isVisible ) { @@ -40,11 +41,11 @@ export function DefaultBlockAppender( { return (
- + - + { __( 'Welcome to the wonderful world of blocks! Click the “+” (“Add block”) button to add a new block. There are blocks available for all kind of content: you can insert text, headings, images, lists, and lots more!' ) } @@ -66,19 +67,20 @@ export function DefaultBlockAppender( { ); } export default compose( + withDeprecatedUniqueId, withSelect( ( select, ownProps ) => { const { getBlockCount, getBlock, getEditorSettings, getTemplateLock } = select( 'core/editor' ); const { isTipVisible } = select( 'core/nux' ); - const isEmpty = ! getBlockCount( ownProps.rootUID ); - const lastBlock = getBlock( ownProps.lastBlockUID ); + const isEmpty = ! getBlockCount( ownProps.rootClientId ); + const lastBlock = getBlock( ownProps.lastBlockClientId ); const isLastBlockDefault = get( lastBlock, [ 'name' ] ) === getDefaultBlockName(); const { bodyPlaceholder } = getEditorSettings(); return { isVisible: isEmpty || ! isLastBlockDefault, showPrompt: isEmpty, - isLocked: !! getTemplateLock( ownProps.rootUID ), + isLocked: !! getTemplateLock( ownProps.rootClientId ), placeholder: bodyPlaceholder, hasTip: isTipVisible( 'core/editor.inserter' ), }; @@ -93,14 +95,14 @@ export default compose( return { onAppend() { - const { layout, rootUID, hasTip } = ownProps; + const { layout, rootClientId, hasTip } = ownProps; let attributes; if ( layout ) { attributes = { layout }; } - insertDefaultBlock( attributes, rootUID ); + insertDefaultBlock( attributes, rootClientId ); startTyping(); if ( hasTip ) { diff --git a/editor/components/default-block-appender/test/__snapshots__/index.js.snap b/editor/components/default-block-appender/test/__snapshots__/index.js.snap index 9fbe162f6225f..9dfa8c9f5d32e 100644 --- a/editor/components/default-block-appender/test/__snapshots__/index.js.snap +++ b/editor/components/default-block-appender/test/__snapshots__/index.js.snap @@ -3,7 +3,7 @@ exports[`DefaultBlockAppender should append a default block when input focused 1`] = `
onSelect( uid ); + const onSelectHeading = ( clientId ) => onSelect( clientId ); const focusTitle = () => { // Not great but it's the simplest way to focus the title right now. const titleNode = document.querySelector( '.editor-post-title__input' ); @@ -115,7 +115,7 @@ export const DocumentOutline = ( { blocks = [], title, onSelect, isTitleSupporte key={ index } level={ `H${ item.level }` } isValid={ isValid } - onClick={ () => onSelectHeading( item.uid ) } + onClick={ () => onSelectHeading( item.clientId ) } path={ item.path } > { item.isEmpty ? emptyHeadingContent : item.attributes.content } diff --git a/editor/components/document-outline/item.js b/editor/components/document-outline/item.js index 0b041f1740a7c..3db43383c5a5f 100644 --- a/editor/components/document-outline/item.js +++ b/editor/components/document-outline/item.js @@ -37,9 +37,9 @@ const TableOfContentsItem = ( { { // path is an array of nodes that are ancestors of the heading starting in the top level node. // This mapping renders each ancestor to make it easier for the user to know where the headings are nested. - path.map( ( { uid }, index ) => ( + path.map( ( { clientId }, index ) => ( - + ) ) } diff --git a/editor/components/editor-global-keyboard-shortcuts/index.js b/editor/components/editor-global-keyboard-shortcuts/index.js index 0839338294202..cc8a1e1374060 100644 --- a/editor/components/editor-global-keyboard-shortcuts/index.js +++ b/editor/components/editor-global-keyboard-shortcuts/index.js @@ -24,9 +24,9 @@ class EditorGlobalKeyboardShortcuts extends Component { } selectAll( event ) { - const { uids, onMultiSelect } = this.props; + const { clientIds, onMultiSelect } = this.props; event.preventDefault(); - onMultiSelect( first( uids ), last( uids ) ); + onMultiSelect( first( clientIds ), last( clientIds ) ); } undoOrRedo( event ) { @@ -47,11 +47,11 @@ class EditorGlobalKeyboardShortcuts extends Component { } deleteSelectedBlocks( event ) { - const { multiSelectedBlockUids, onRemove, isLocked } = this.props; - if ( multiSelectedBlockUids.length ) { + const { multiSelectedBlockClientIds, onRemove, isLocked } = this.props; + if ( multiSelectedBlockClientIds.length ) { event.preventDefault(); if ( ! isLocked ) { - onRemove( multiSelectedBlockUids ); + onRemove( multiSelectedBlockClientIds ); } } } @@ -95,19 +95,22 @@ export default compose( [ withSelect( ( select ) => { const { getBlockOrder, - getMultiSelectedBlockUids, + getMultiSelectedBlockClientIds, hasMultiSelection, isEditedPostDirty, - getBlockRootUID, + getBlockRootClientId, getTemplateLock, } = select( 'core/editor' ); - const multiSelectedBlockUids = getMultiSelectedBlockUids(); + const multiSelectedBlockClientIds = getMultiSelectedBlockClientIds(); return { - uids: getBlockOrder(), - multiSelectedBlockUids, + clientIds: getBlockOrder(), + multiSelectedBlockClientIds, hasMultiSelection: hasMultiSelection(), - isLocked: some( multiSelectedBlockUids, ( uid ) => !! getTemplateLock( getBlockRootUID( uid ) ) ), + isLocked: some( + multiSelectedBlockClientIds, + ( clientId ) => !! getTemplateLock( getBlockRootClientId( clientId ) ) + ), isDirty: isEditedPostDirty(), }; } ), diff --git a/editor/components/inner-blocks/index.js b/editor/components/inner-blocks/index.js index 32a6c4b692129..39e7d1ba9bd8e 100644 --- a/editor/components/inner-blocks/index.js +++ b/editor/components/inner-blocks/index.js @@ -81,7 +81,7 @@ class InnerBlocks extends Component { render() { const { - uid, + clientId, layouts, allowedBlocks, templateLock, @@ -97,7 +97,7 @@ class InnerBlocks extends Component { return (
@@ -106,7 +106,7 @@ class InnerBlocks extends Component { } InnerBlocks = compose( [ - withBlockEditContext( ( context ) => pick( context, [ 'uid' ] ) ), + withBlockEditContext( ( context ) => pick( context, [ 'clientId' ] ) ), withViewportMatch( { isSmallScreen: '< medium' } ), withSelect( ( select, ownProps ) => { const { @@ -114,16 +114,16 @@ InnerBlocks = compose( [ hasSelectedInnerBlock, getBlock, getBlockListSettings, - getBlockRootUID, + getBlockRootClientId, getTemplateLock, } = select( 'core/editor' ); - const { uid } = ownProps; - const parentUID = getBlockRootUID( uid ); + const { clientId } = ownProps; + const parentClientId = getBlockRootClientId( clientId ); return { - isSelectedBlockInRoot: isBlockSelected( uid ) || hasSelectedInnerBlock( uid ), - block: getBlock( uid ), - blockListSettings: getBlockListSettings( uid ), - parentLock: getTemplateLock( parentUID ), + isSelectedBlockInRoot: isBlockSelected( clientId ) || hasSelectedInnerBlock( clientId ), + block: getBlock( clientId ), + blockListSettings: getBlockListSettings( clientId ), + parentLock: getTemplateLock( parentClientId ), }; } ), withDispatch( ( dispatch, ownProps ) => { @@ -132,19 +132,19 @@ InnerBlocks = compose( [ insertBlocks, updateBlockListSettings, } = dispatch( 'core/editor' ); - const { block, uid } = ownProps; + const { block, clientId } = ownProps; return { replaceInnerBlocks( blocks ) { - const uids = map( block.innerBlocks, 'uid' ); - if ( uids.length ) { - replaceBlocks( uids, blocks ); + const clientIds = map( block.innerBlocks, 'clientId' ); + if ( clientIds.length ) { + replaceBlocks( clientIds, blocks ); } else { - insertBlocks( blocks, undefined, uid ); + insertBlocks( blocks, undefined, clientId ); } }, updateNestedSettings( settings ) { - dispatch( updateBlockListSettings( uid, settings ) ); + dispatch( updateBlockListSettings( clientId, settings ) ); }, }; } ), diff --git a/editor/components/inserter-with-shortcuts/index.js b/editor/components/inserter-with-shortcuts/index.js index 60ed1434bd3e3..5c99672d39751 100644 --- a/editor/components/inserter-with-shortcuts/index.js +++ b/editor/components/inserter-with-shortcuts/index.js @@ -49,23 +49,23 @@ function InserterWithShortcuts( { items, isLocked, onInsert } ) { } export default compose( - withSelect( ( select, { rootUID } ) => { + withSelect( ( select, { rootClientId } ) => { const { getInserterItems, getTemplateLock } = select( 'core/editor' ); return { - items: getInserterItems( rootUID ), - isLocked: !! getTemplateLock( rootUID ), + items: getInserterItems( rootClientId ), + isLocked: !! getTemplateLock( rootClientId ), }; } ), withDispatch( ( dispatch, ownProps ) => { - const { uid, rootUID, layout } = ownProps; + const { clientId, rootClientId, layout } = ownProps; return { onInsert( { name, initialAttributes } ) { const block = createBlock( name, { ...initialAttributes, layout } ); - if ( uid ) { - dispatch( 'core/editor' ).replaceBlocks( uid, block ); + if ( clientId ) { + dispatch( 'core/editor' ).replaceBlocks( clientId, block ); } else { - dispatch( 'core/editor' ).insertBlock( block, undefined, rootUID ); + dispatch( 'core/editor' ).insertBlock( block, undefined, rootClientId ); } }, }; diff --git a/editor/components/inserter/child-blocks.js b/editor/components/inserter/child-blocks.js index c6a9392cfafd4..4496144a83b99 100644 --- a/editor/components/inserter/child-blocks.js +++ b/editor/components/inserter/child-blocks.js @@ -27,14 +27,14 @@ function ChildBlocks( { rootBlockIcon, rootBlockTitle, items, ...props } ) { export default compose( ifCondition( ( { items } ) => items && items.length > 0 ), - withSelect( ( select, { rootUID } ) => { + withSelect( ( select, { rootClientId } ) => { const { getBlockType, } = select( 'core/blocks' ); const { getBlockName, } = select( 'core/editor' ); - const rootBlockName = getBlockName( rootUID ); + const rootBlockName = getBlockName( rootClientId ); const rootBlockType = getBlockType( rootBlockName ); return { rootBlockTitle: rootBlockType && rootBlockType.title, diff --git a/editor/components/inserter/index.js b/editor/components/inserter/index.js index 549193a4a0ca0..cb061f4e60da5 100644 --- a/editor/components/inserter/index.js +++ b/editor/components/inserter/index.js @@ -38,7 +38,7 @@ class Inserter extends Component { title, children, onInsertBlock, - rootUID, + rootClientId, } = this.props; if ( items.length === 0 ) { @@ -72,7 +72,13 @@ class Inserter extends Component { onClose(); }; - return ; + return ( + + ); } } /> ); @@ -88,25 +94,25 @@ export default compose( [ getInserterItems, } = select( 'core/editor' ); const insertionPoint = getBlockInsertionPoint(); - const { rootUID } = insertionPoint; + const { rootClientId } = insertionPoint; return { title: getEditedPostAttribute( 'title' ), insertionPoint, selectedBlock: getSelectedBlock(), - items: getInserterItems( rootUID ), - rootUID, + items: getInserterItems( rootClientId ), + rootClientId, }; } ), withDispatch( ( dispatch, ownProps ) => ( { onInsertBlock: ( item ) => { const { insertionPoint, selectedBlock } = ownProps; - const { index, rootUID, layout } = insertionPoint; + const { index, rootClientId, layout } = insertionPoint; const { name, initialAttributes } = item; const insertedBlock = createBlock( name, { ...initialAttributes, layout } ); if ( selectedBlock && isUnmodifiedDefaultBlock( selectedBlock ) ) { - return dispatch( 'core/editor' ).replaceBlocks( selectedBlock.uid, insertedBlock ); + return dispatch( 'core/editor' ).replaceBlocks( selectedBlock.clientId, insertedBlock ); } - return dispatch( 'core/editor' ).insertBlock( insertedBlock, index, rootUID ); + return dispatch( 'core/editor' ).insertBlock( insertedBlock, index, rootClientId ); }, } ) ), ] )( Inserter ); diff --git a/editor/components/inserter/menu.js b/editor/components/inserter/menu.js index 68d34a5dafa8f..cbe4c330bcce5 100644 --- a/editor/components/inserter/menu.js +++ b/editor/components/inserter/menu.js @@ -182,7 +182,7 @@ export class InserterMenu extends Component { } render() { - const { instanceId, onSelect, rootUID } = this.props; + const { instanceId, onSelect, rootClientId } = this.props; const { childItems, filterValue, hoveredItem, suggestedItems, sharedItems, itemsPerCategory, openPanels } = this.state; const isPanelOpen = ( panel ) => openPanels.indexOf( panel ) !== -1; const isSearching = !! filterValue; @@ -216,7 +216,7 @@ export class InserterMenu extends Component { { + withSelect( ( select, { rootClientId } ) => { const { getChildBlockNames, } = select( 'core/blocks' ); const { getBlockName, } = select( 'core/editor' ); - const rootBlockName = getBlockName( rootUID ); + const rootBlockName = getBlockName( rootClientId ); return { rootChildBlocks: getChildBlockNames( rootBlockName ), }; diff --git a/editor/components/multi-select-scroll-into-view/index.js b/editor/components/multi-select-scroll-into-view/index.js index 470d7bfa61ce8..b616e370d0287 100644 --- a/editor/components/multi-select-scroll-into-view/index.js +++ b/editor/components/multi-select-scroll-into-view/index.js @@ -18,7 +18,7 @@ import { getBlockDOMNode } from '../../utils/dom'; class MultiSelectScrollIntoView extends Component { componentDidUpdate() { // Relies on expectation that `componentDidUpdate` will only be called - // if value of `extentUID` changes. + // if value of `extentClientId` changes. this.scrollIntoView(); } @@ -29,12 +29,12 @@ class MultiSelectScrollIntoView extends Component { * @return {void} */ scrollIntoView() { - const { extentUID } = this.props; - if ( ! extentUID ) { + const { extentClientId } = this.props; + if ( ! extentClientId ) { return; } - const extentNode = getBlockDOMNode( extentUID ); + const extentNode = getBlockDOMNode( extentClientId ); if ( ! extentNode ) { return; } @@ -58,7 +58,9 @@ class MultiSelectScrollIntoView extends Component { } export default withSelect( ( select ) => { + const { getLastMultiSelectedBlockClientId } = select( 'core/editor' ); + return { - extentUID: select( 'core/editor' ).getLastMultiSelectedBlockUid(), + extentClientId: getLastMultiSelectedBlockClientId(), }; } )( MultiSelectScrollIntoView ); diff --git a/editor/components/preserve-scroll-in-reorder/index.js b/editor/components/preserve-scroll-in-reorder/index.js index 92fa7941be6e3..25a28bff45d40 100644 --- a/editor/components/preserve-scroll-in-reorder/index.js +++ b/editor/components/preserve-scroll-in-reorder/index.js @@ -37,10 +37,10 @@ class PreserveScrollInReorder extends Component { } /** - * Given the block UID of the start of the selection, saves the block's - * top offset as an instance property before a reorder is to occur. + * Given the block client ID of the start of the selection, saves the + * block's top offset as an instance property before a reorder is to occur. * - * @param {string} selectionStart UID of selected block. + * @param {string} selectionStart Client ID of selected block. * * @return {number?} The scroll offset. */ diff --git a/editor/components/skip-to-selected-block/index.js b/editor/components/skip-to-selected-block/index.js index 21400b1c5b19a..cd29f73248b3f 100644 --- a/editor/components/skip-to-selected-block/index.js +++ b/editor/components/skip-to-selected-block/index.js @@ -11,14 +11,14 @@ import { Button } from '@wordpress/components'; import './style.scss'; import { getBlockFocusableWrapper } from '../../utils/dom'; -const SkipToSelectedBlock = ( { selectedBlockUID } ) => { +const SkipToSelectedBlock = ( { selectedBlockClientId } ) => { const onClick = () => { - const selectedBlockElement = getBlockFocusableWrapper( selectedBlockUID ); + const selectedBlockElement = getBlockFocusableWrapper( selectedBlockClientId ); selectedBlockElement.focus(); }; return ( - selectedBlockUID && + selectedBlockClientId && @@ -27,6 +27,6 @@ const SkipToSelectedBlock = ( { selectedBlockUID } ) => { export default withSelect( ( select ) => { return { - selectedBlockUID: select( 'core/editor' ).getBlockSelectionStart(), + selectedBlockClientId: select( 'core/editor' ).getBlockSelectionStart(), }; } )( SkipToSelectedBlock ); diff --git a/editor/components/with-deprecated-unique-id/index.js b/editor/components/with-deprecated-unique-id/index.js new file mode 100644 index 0000000000000..3b49ec1225969 --- /dev/null +++ b/editor/components/with-deprecated-unique-id/index.js @@ -0,0 +1,60 @@ +/** + * External dependencies + */ +import { forOwn, compact, omit } from 'lodash'; + +/** + * WordPress dependencies + */ +import { createHigherOrderComponent } from '@wordpress/compose'; +import deprecated from '@wordpress/deprecated'; + +/** + * Set of deprecated UID props, where each key is the deprecated prop, its + * value the equivalent replacement. + * + * @type {Object} + */ +const DEPRECATED_UID_PROPS = { + lastBlockUID: 'lastBlockClientId', + rootUID: 'rootClientId', + uid: 'clientId', + uids: 'clientIds', +}; + +/** + * A higher-order component which replaces any instance of deprecated "UID" + * prop names with their updated equivalent prop, with a deprecated warning + * encouraging the developer to update their usage before its pending removal. + * + * @param {WPComponent} WrappedComponent Original component. + * + * @return {WPComponent} Enhanced component. + */ +export default createHigherOrderComponent( ( WrappedComponent ) => ( props ) => { + forOwn( DEPRECATED_UID_PROPS, ( replacement, prop ) => { + if ( ! props.hasOwnProperty( prop ) ) { + return; + } + + // Construct deprecated message, including original component's name + // if possible to retrieve. + const { name = WrappedComponent.displayName } = WrappedComponent; + const message = compact( [ + name, + `The \`${ prop }\` prop`, + ] ).join( ' ' ); + + deprecated( message, { + alternative: `the \`${ replacement }\` prop`, + plugin: 'Gutenberg', + version: 'v3.5', + } ); + + props = Object.assign( omit( props, prop ), { + [ replacement ]: props[ prop ], + } ); + } ); + + return ; +} ); diff --git a/editor/components/writing-flow/index.js b/editor/components/writing-flow/index.js index 865b9bd4d0794..e7beed323d3fa 100644 --- a/editor/components/writing-flow/index.js +++ b/editor/components/writing-flow/index.js @@ -147,26 +147,31 @@ class WritingFlow extends Component { expandSelection( isReverse ) { const { - selectedBlockUID, - selectionStartUID, - selectionBeforeEndUID, - selectionAfterEndUID, + selectedBlockClientId, + selectionStartClientId, + selectionBeforeEndClientId, + selectionAfterEndClientId, } = this.props; - const nextSelectionEndUID = isReverse ? selectionBeforeEndUID : selectionAfterEndUID; + const nextSelectionEndClientId = isReverse ? + selectionBeforeEndClientId : + selectionAfterEndClientId; - if ( nextSelectionEndUID ) { - this.props.onMultiSelect( selectionStartUID || selectedBlockUID, nextSelectionEndUID ); + if ( nextSelectionEndClientId ) { + this.props.onMultiSelect( + selectionStartClientId || selectedBlockClientId, + nextSelectionEndClientId + ); } } moveSelection( isReverse ) { - const { selectedFirstUid, selectedLastUid } = this.props; + const { selectedFirstClientId, selectedLastClientId } = this.props; - const focusedBlockUid = isReverse ? selectedFirstUid : selectedLastUid; + const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId; - if ( focusedBlockUid ) { - this.props.onSelectBlock( focusedBlockUid ); + if ( focusedBlockClientId ) { + this.props.onSelectBlock( focusedBlockClientId ); } } @@ -305,28 +310,28 @@ class WritingFlow extends Component { export default compose( [ withSelect( ( select ) => { const { - getSelectedBlockUID, - getMultiSelectedBlocksStartUid, - getMultiSelectedBlocksEndUid, - getPreviousBlockUid, - getNextBlockUid, - getFirstMultiSelectedBlockUid, - getLastMultiSelectedBlockUid, + getSelectedBlockClientId, + getMultiSelectedBlocksStartClientId, + getMultiSelectedBlocksEndClientId, + getPreviousBlockClientId, + getNextBlockClientId, + getFirstMultiSelectedBlockClientId, + getLastMultiSelectedBlockClientId, hasMultiSelection, getBlockOrder, } = select( 'core/editor' ); - const selectedBlockUID = getSelectedBlockUID(); - const selectionStartUID = getMultiSelectedBlocksStartUid(); - const selectionEndUID = getMultiSelectedBlocksEndUid(); + const selectedBlockClientId = getSelectedBlockClientId(); + const selectionStartClientId = getMultiSelectedBlocksStartClientId(); + const selectionEndClientId = getMultiSelectedBlocksEndClientId(); return { - selectedBlockUID, - selectionStartUID, - selectionBeforeEndUID: getPreviousBlockUid( selectionEndUID || selectedBlockUID ), - selectionAfterEndUID: getNextBlockUid( selectionEndUID || selectedBlockUID ), - selectedFirstUid: getFirstMultiSelectedBlockUid(), - selectedLastUid: getLastMultiSelectedBlockUid(), + selectedBlockClientId, + selectionStartClientId, + selectionBeforeEndClientId: getPreviousBlockClientId( selectionEndClientId || selectedBlockClientId ), + selectionAfterEndClientId: getNextBlockClientId( selectionEndClientId || selectedBlockClientId ), + selectedFirstClientId: getFirstMultiSelectedBlockClientId(), + selectedLastClientId: getLastMultiSelectedBlockClientId(), hasMultiSelection: hasMultiSelection(), blocks: getBlockOrder(), }; diff --git a/editor/store/actions.js b/editor/store/actions.js index 351e509c23a12..b68839160204e 100644 --- a/editor/store/actions.js +++ b/editor/store/actions.js @@ -126,43 +126,55 @@ export function receiveBlocks( blocks ) { /** * Returns an action object used in signalling that the block attributes with - * the specified UID has been updated. + * the specified client ID has been updated. * - * @param {string} uid Block UID. + * @param {string} clientId Block client ID. * @param {Object} attributes Block attributes to be merged. * * @return {Object} Action object. */ -export function updateBlockAttributes( uid, attributes ) { +export function updateBlockAttributes( clientId, attributes ) { return { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid, + clientId, attributes, }; } /** * Returns an action object used in signalling that the block with the - * specified UID has been updated. + * specified client ID has been updated. * - * @param {string} uid Block UID. - * @param {Object} updates Block attributes to be merged. + * @param {string} clientId Block client ID. + * @param {Object} updates Block attributes to be merged. * * @return {Object} Action object. */ -export function updateBlock( uid, updates ) { +export function updateBlock( clientId, updates ) { return { type: 'UPDATE_BLOCK', - uid, + clientId, updates, }; } -export function selectBlock( uid, initialPosition = null ) { +/** + * Returns an action object used in signalling that the block with the + * specified client ID has been selected, optionally accepting a position + * value reflecting its selection directionality. An initialPosition of -1 + * reflects a reverse selection. + * + * @param {string} clientId Block client ID. + * @param {?number} initialPosition Optional initial position. Pass as -1 to + * reflect reverse selection. + * + * @return {Object} Action object. + */ +export function selectBlock( clientId, initialPosition = null ) { return { type: 'SELECT_BLOCK', initialPosition, - uid, + clientId, }; } @@ -211,15 +223,15 @@ export function toggleSelection( isSelectionEnabled = true ) { * Returns an action object signalling that a blocks should be replaced with * one or more replacement blocks. * - * @param {(string|string[])} uids Block UID(s) to replace. - * @param {(Object|Object[])} blocks Replacement block(s). + * @param {(string|string[])} clientIds Block client ID(s) to replace. + * @param {(Object|Object[])} blocks Replacement block(s). * * @return {Object} Action object. */ -export function replaceBlocks( uids, blocks ) { +export function replaceBlocks( clientIds, blocks ) { return { type: 'REPLACE_BLOCKS', - uids: castArray( uids ), + clientIds: castArray( clientIds ), blocks: castArray( blocks ), time: Date.now(), }; @@ -229,30 +241,29 @@ export function replaceBlocks( uids, blocks ) { * Returns an action object signalling that a single block should be replaced * with one or more replacement blocks. * - * @param {(string|string[])} uid Block UID(s) to replace. - * @param {(Object|Object[])} block Replacement block(s). + * @param {(string|string[])} clientId Block client ID to replace. + * @param {(Object|Object[])} block Replacement block(s). * * @return {Object} Action object. */ -export function replaceBlock( uid, block ) { - return replaceBlocks( uid, block ); +export function replaceBlock( clientId, block ) { + return replaceBlocks( clientId, block ); } /** - * Action creator creator which, given the action type to dispatch - * creates a prop dispatcher callback for - * managing block movement. + * Higher-order action creator which, given the action type to dispatch creates + * an action creator for managing block movement. * - * @param {string} type Action type to dispatch. + * @param {string} type Action type to dispatch. * - * @return {Function} Prop dispatcher callback. + * @return {Function} Action creator. */ function createOnMove( type ) { - return ( uids, rootUID ) => { + return ( clientIds, rootClientId ) => { return { - uids: castArray( uids ), + clientIds: castArray( clientIds ), type, - rootUID, + rootClientId, }; }; } @@ -264,20 +275,20 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' ); * Returns an action object signalling that an indexed block should be moved * to a new index. * - * @param {?string} uid The UID of the block. - * @param {?string} fromRootUID root UID source. - * @param {?string} toRootUID root UID destination. - * @param {?string} layout layout to move the block into. - * @param {number} index The index to move the block into. + * @param {?string} clientId The client ID of the block. + * @param {?string} fromRootClientId Root client ID source. + * @param {?string} toRootClientId Root client ID destination. + * @param {?string} layout Layout to move the block into. + * @param {number} index The index to move the block into. * * @return {Object} Action object. */ -export function moveBlockToPosition( uid, fromRootUID, toRootUID, layout, index ) { +export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, layout, index ) { return { type: 'MOVE_BLOCK_TO_POSITION', - fromRootUID, - toRootUID, - uid, + fromRootClientId, + toRootClientId, + clientId, index, layout, }; @@ -287,32 +298,34 @@ export function moveBlockToPosition( uid, fromRootUID, toRootUID, layout, index * Returns an action object used in signalling that a single block should be * inserted, optionally at a specific index respective a root block list. * - * @param {Object} block Block object to insert. - * @param {?number} index Index at which block should be inserted. - * @param {?string} rootUID Optional root UID of block list to insert. + * @param {Object} block Block object to insert. + * @param {?number} index Index at which block should be inserted. + * @param {?string} rootClientId Optional root client ID of block list on which + * to insert. * * @return {Object} Action object. */ -export function insertBlock( block, index, rootUID ) { - return insertBlocks( [ block ], index, rootUID ); +export function insertBlock( block, index, rootClientId ) { + return insertBlocks( [ block ], index, rootClientId ); } /** * Returns an action object used in signalling that an array of blocks should * be inserted, optionally at a specific index respective a root block list. * - * @param {Object[]} blocks Block objects to insert. - * @param {?number} index Index at which block should be inserted. - * @param {?string} rootUID Optional root UID of block list to insert. + * @param {Object[]} blocks Block objects to insert. + * @param {?number} index Index at which block should be inserted. + * @param {?string} rootClientId Optional root cliente ID of block list on + * which to insert. * * @return {Object} Action object. */ -export function insertBlocks( blocks, index, rootUID ) { +export function insertBlocks( blocks, index, rootClientId ) { return { type: 'INSERT_BLOCKS', blocks: castArray( blocks ), index, - rootUID, + rootClientId, time: Date.now(), }; } @@ -415,15 +428,15 @@ export function trashPost( postId, postType ) { /** * Returns an action object used in signalling that two blocks should be merged * - * @param {string} blockAUid UID of the first block to merge. - * @param {string} blockBUid UID of the second block to merge. + * @param {string} firstBlockClientId Client ID of the first block to merge. + * @param {string} secondBlockClientId Client ID of the second block to merge. * * @return {Object} Action object. */ -export function mergeBlocks( blockAUid, blockBUid ) { +export function mergeBlocks( firstBlockClientId, secondBlockClientId ) { return { type: 'MERGE_BLOCKS', - blocks: [ blockAUid, blockBUid ], + blocks: [ firstBlockClientId, secondBlockClientId ], }; } @@ -466,46 +479,49 @@ export function createUndoLevel() { } /** - * Returns an action object used in signalling that the blocks - * corresponding to the specified UID set are to be removed. + * Returns an action object used in signalling that the blocks corresponding to + * the set of specified client IDs are to be removed. * - * @param {string|string[]} uids Block UIDs. - * @param {boolean} selectPrevious True if the previous block should be selected when a block is removed. + * @param {string|string[]} clientIds Client IDs of blocks to remove. + * @param {boolean} selectPrevious True if the previous block should be + * selected when a block is removed. * * @return {Object} Action object. */ -export function removeBlocks( uids, selectPrevious = true ) { +export function removeBlocks( clientIds, selectPrevious = true ) { return { type: 'REMOVE_BLOCKS', - uids: castArray( uids ), + clientIds: castArray( clientIds ), selectPrevious, }; } /** * Returns an action object used in signalling that the block with the - * specified UID is to be removed. + * specified client ID is to be removed. * - * @param {string} uid Block UID. - * @param {boolean} selectPrevious True if the previous block should be selected when a block is removed. + * @param {string} clientId Client ID of block to remove. + * @param {boolean} selectPrevious True if the previous block should be + * selected when a block is removed. * * @return {Object} Action object. */ -export function removeBlock( uid, selectPrevious = true ) { - return removeBlocks( [ uid ], selectPrevious ); +export function removeBlock( clientId, selectPrevious ) { + return removeBlocks( [ clientId ], selectPrevious ); } /** - * Returns an action object used to toggle the block editing mode (visual/html). + * Returns an action object used to toggle the block editing mode between + * visual and HTML modes. * - * @param {string} uid Block UID. + * @param {string} clientId Block client ID. * * @return {Object} Action object. */ -export function toggleBlockMode( uid ) { +export function toggleBlockMode( clientId ) { return { type: 'TOGGLE_BLOCK_MODE', - uid, + clientId, }; } @@ -661,45 +677,46 @@ export function updateSharedBlockTitle( id, title ) { /** * Returns an action object used to convert a shared block into a static block. * - * @param {Object} uid The ID of the block to attach. + * @param {string} clientId The client ID of the block to attach. * * @return {Object} Action object. */ -export function convertBlockToStatic( uid ) { +export function convertBlockToStatic( clientId ) { return { type: 'CONVERT_BLOCK_TO_STATIC', - uid, + clientId, }; } /** * Returns an action object used to convert a static block into a shared block. * - * @param {Object} uid The ID of the block to detach. + * @param {string} clientId The client ID of the block to detach. * * @return {Object} Action object. */ -export function convertBlockToShared( uid ) { +export function convertBlockToShared( clientId ) { return { type: 'CONVERT_BLOCK_TO_SHARED', - uid, + clientId, }; } /** * Returns an action object used in signalling that a new block of the default * type should be added to the block list. * - * @param {?Object} attributes Optional attributes of the block to assign. - * @param {?string} rootUID Optional root UID of block list to append. - * @param {?number} index Optional index where to insert the default block + * @param {?Object} attributes Optional attributes of the block to assign. + * @param {?string} rootClientId Optional root client ID of block list on which + * to append. + * @param {?number} index Optional index where to insert the default block * * @return {Object} Action object */ -export function insertDefaultBlock( attributes, rootUID, index ) { +export function insertDefaultBlock( attributes, rootClientId, index ) { const block = createBlock( getDefaultBlockName(), attributes ); return { - ...insertBlock( block, index, rootUID ), + ...insertBlock( block, index, rootClientId ), isProvisional: true, }; } @@ -707,15 +724,16 @@ export function insertDefaultBlock( attributes, rootUID, index ) { /** * Returns an action object that changes the nested settings of a given block. * - * @param {string} id UID of the block whose nested setting. + * @param {string} clientId Client ID of the block whose nested setting are + * being received. * @param {Object} settings Object with the new settings for the nested block. * * @return {Object} Action object */ -export function updateBlockListSettings( id, settings ) { +export function updateBlockListSettings( clientId, settings ) { return { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id, + clientId, settings, }; } diff --git a/editor/store/effects.js b/editor/store/effects.js index 4a630bc4a809d..194ca8cac229a 100644 --- a/editor/store/effects.js +++ b/editor/store/effects.js @@ -55,11 +55,11 @@ import { isEditedPostSaveable, getBlock, getBlockCount, - getBlockRootUID, + getBlockRootClientId, getBlocks, getSharedBlock, - getPreviousBlockUid, - getProvisionalBlockUID, + getPreviousBlockClientId, + getProvisionalBlockClientId, getSelectedBlock, isBlockSelected, getTemplate, @@ -88,9 +88,9 @@ const SHARED_BLOCK_NOTICE_ID = 'SHARED_BLOCK_NOTICE_ID'; */ export function removeProvisionalBlock( action, store ) { const state = store.getState(); - const provisionalBlockUID = getProvisionalBlockUID( state ); - if ( provisionalBlockUID && ! isBlockSelected( state, provisionalBlockUID ) ) { - return removeBlock( provisionalBlockUID, false ); + const provisionalBlockClientId = getProvisionalBlockClientId( state ); + if ( provisionalBlockClientId && ! isBlockSelected( state, provisionalBlockClientId ) ) { + return removeBlock( provisionalBlockClientId, false ); } } @@ -332,14 +332,14 @@ export default { MERGE_BLOCKS( action, store ) { const { dispatch } = store; const state = store.getState(); - const [ blockAUid, blockBUid ] = action.blocks; - const blockA = getBlock( state, blockAUid ); - const blockB = getBlock( state, blockBUid ); + const [ firstBlockClientId, secondBlockClientId ] = action.blocks; + const blockA = getBlock( state, firstBlockClientId ); + const blockB = getBlock( state, secondBlockClientId ); const blockType = getBlockType( blockA.name ); // Only focus the previous block if it's not mergeable if ( ! blockType.merge ) { - dispatch( selectBlock( blockA.uid ) ); + dispatch( selectBlock( blockA.clientId ) ); return; } @@ -360,9 +360,9 @@ export default { blocksWithTheSameType[ 0 ].attributes ); - dispatch( selectBlock( blockA.uid, -1 ) ); + dispatch( selectBlock( blockA.clientId, -1 ) ); dispatch( replaceBlocks( - [ blockA.uid, blockB.uid ], + [ blockA.clientId, blockB.clientId ], [ { ...blockA, @@ -508,8 +508,8 @@ export default { const { dispatch } = store; const state = store.getState(); - const { uid, title, isTemporary } = getSharedBlock( state, id ); - const { name, attributes, innerBlocks } = getBlock( state, uid ); + const { clientId, title, isTemporary } = getSharedBlock( state, id ); + const { name, attributes, innerBlocks } = getBlock( state, clientId ); const content = serialize( createBlock( name, attributes, innerBlocks ) ); const data = isTemporary ? { title, content } : { id, title, content }; @@ -554,7 +554,7 @@ export default { // Remove any other blocks that reference this shared block const allBlocks = getBlocks( getState() ); const associatedBlocks = allBlocks.filter( ( block ) => isSharedBlock( block ) && block.attributes.ref === id ); - const associatedBlockUids = associatedBlocks.map( ( block ) => block.uid ); + const associatedBlockClientIds = associatedBlocks.map( ( block ) => block.clientId ); const transactionId = uniqueId(); @@ -566,8 +566,8 @@ export default { // Remove the parsed block. dispatch( removeBlocks( [ - ...associatedBlockUids, - sharedBlock.uid, + ...associatedBlockClientIds, + sharedBlock.clientId, ] ) ); apiFetch( { path: `/wp/v2/${ basePath }/${ id }`, method: 'DELETE' } ) @@ -594,19 +594,19 @@ export default { }, CONVERT_BLOCK_TO_STATIC( action, store ) { const state = store.getState(); - const oldBlock = getBlock( state, action.uid ); + const oldBlock = getBlock( state, action.clientId ); const sharedBlock = getSharedBlock( state, oldBlock.attributes.ref ); - const referencedBlock = getBlock( state, sharedBlock.uid ); + const referencedBlock = getBlock( state, sharedBlock.clientId ); const newBlock = createBlock( referencedBlock.name, referencedBlock.attributes ); - store.dispatch( replaceBlock( oldBlock.uid, newBlock ) ); + store.dispatch( replaceBlock( oldBlock.clientId, newBlock ) ); }, CONVERT_BLOCK_TO_SHARED( action, store ) { const { getState, dispatch } = store; - const parsedBlock = getBlock( getState(), action.uid ); + const parsedBlock = getBlock( getState(), action.clientId ); const sharedBlock = { id: uniqueId( 'shared' ), - uid: parsedBlock.uid, + clientId: parsedBlock.clientId, title: __( 'Untitled shared block' ), }; @@ -618,7 +618,7 @@ export default { dispatch( saveSharedBlock( sharedBlock.id ) ); dispatch( replaceBlock( - parsedBlock.uid, + parsedBlock.clientId, createBlock( 'core/block', { ref: sharedBlock.id, layout: parsedBlock.attributes.layout, @@ -656,24 +656,24 @@ export default { return; } - const firstRemovedBlockUID = action.uids[ 0 ]; + const firstRemovedBlockClientId = action.clientIds[ 0 ]; const state = getState(); const currentSelectedBlock = getSelectedBlock( state ); // recreate the state before the block was removed. const previousState = { ...state, editor: { present: last( state.editor.past ) } }; - // rootUID of the removed block. - const rootUID = getBlockRootUID( previousState, firstRemovedBlockUID ); + // rootClientId of the removed block. + const rootClientId = getBlockRootClientId( previousState, firstRemovedBlockClientId ); - // UID of the block that was before the removed block - // or the rootUID if the removed block was the first amongst his siblings. - const blockUIDToSelect = getPreviousBlockUid( previousState, firstRemovedBlockUID ) || rootUID; + // Client ID of the block that was before the removed block or the + // rootClientId if the removed block was first amongst its siblings. + const blockClientIdToSelect = getPreviousBlockClientId( previousState, firstRemovedBlockClientId ) || rootClientId; // Dispatch select block action if the currently selected block // is not already the block we want to be selected. - if ( blockUIDToSelect !== currentSelectedBlock ) { - dispatch( selectBlock( blockUIDToSelect ) ); + if ( blockClientIdToSelect !== currentSelectedBlock ) { + dispatch( selectBlock( blockClientIdToSelect ) ); } }, }; diff --git a/editor/store/reducer.js b/editor/store/reducer.js index 4fdda91a3b6be..4c1faf4ea4eac 100644 --- a/editor/store/reducer.js +++ b/editor/store/reducer.js @@ -52,23 +52,23 @@ export function getPostRawValue( value ) { /** * Given an array of blocks, returns an object where each key is a nesting - * context, the value of which is an array of block UIDs existing within that - * nesting context. + * context, the value of which is an array of block client IDs existing within + * that nesting context. * - * @param {Array} blocks Blocks to map. - * @param {?string} rootUID Assumed root UID. + * @param {Array} blocks Blocks to map. + * @param {?string} rootClientId Assumed root client ID. * * @return {Object} Block order map object. */ -function mapBlockOrder( blocks, rootUID = '' ) { - const result = { [ rootUID ]: [] }; +function mapBlockOrder( blocks, rootClientId = '' ) { + const result = { [ rootClientId ]: [] }; blocks.forEach( ( block ) => { - const { uid, innerBlocks } = block; + const { clientId, innerBlocks } = block; - result[ rootUID ].push( uid ); + result[ rootClientId ].push( clientId ); - Object.assign( result, mapBlockOrder( innerBlocks, uid ) ); + Object.assign( result, mapBlockOrder( innerBlocks, clientId ) ); } ); return result; @@ -76,8 +76,8 @@ function mapBlockOrder( blocks, rootUID = '' ) { /** * Given an array of blocks, returns an object containing all blocks, recursing - * into inner blocks. Keys correspond to the block UID, the value of which is - * the block object. + * into inner blocks. Keys correspond to the block client ID, the value of + * which is the block object. * * @param {Array} blocks Blocks to flatten. * @@ -94,7 +94,7 @@ function getFlattenedBlocks( blocks ) { stack.push( ...innerBlocks ); - flattenedBlocks[ block.uid ] = block; + flattenedBlocks[ block.clientId ] = block; } return flattenedBlocks; @@ -126,7 +126,7 @@ export function hasSameKeys( a, b ) { export function isUpdatingSameBlockAttribute( action, previousAction ) { return ( action.type === 'UPDATE_BLOCK_ATTRIBUTES' && - action.uid === previousAction.uid && + action.clientId === previousAction.clientId && hasSameKeys( action.attributes, previousAction.attributes ) ); } @@ -171,7 +171,7 @@ export function shouldOverwriteState( action, previousAction ) { /** * Higher-order reducer targeting the combined editor reducer, augmenting - * block UIDs in remove action to include cascade of inner blocks. + * block client IDs in remove action to include cascade of inner blocks. * * @param {Function} reducer Original reducer function. * @@ -179,15 +179,15 @@ export function shouldOverwriteState( action, previousAction ) { */ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => { if ( state && action.type === 'REMOVE_BLOCKS' ) { - const uids = [ ...action.uids ]; + const clientIds = [ ...action.clientIds ]; - // For each removed UID, include its inner blocks in UIDs to remove, + // For each removed client ID, include its inner blocks to remove, // recursing into those so long as inner blocks exist. - for ( let i = 0; i < uids.length; i++ ) { - uids.push( ...state.blockOrder[ uids[ i ] ] ); + for ( let i = 0; i < clientIds.length; i++ ) { + clientIds.push( ...state.blockOrder[ clientIds[ i ] ] ); } - action = { ...action, uids }; + action = { ...action, clientIds }; } return reducer( state, action ); @@ -200,9 +200,9 @@ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => { * Handles the following state keys: * - edits: an object describing changes to be made to the current post, in * the format accepted by the WP REST API - * - blocksByUID: post content blocks keyed by UID - * - blockOrder: object where each key is a UID, its value an array of uids - * representing the order of its inner blocks + * - blocksByClientId: post content blocks keyed by client ID + * - blockOrder: object where each key is a client ID, its value an array of + * client IDs representing the order of its inner blocks * * @param {Object} state Current state. * @param {Object} action Dispatched action. @@ -280,7 +280,7 @@ export const editor = flow( [ return state; }, - blocksByUID( state = {}, action ) { + blocksByClientId( state = {}, action ) { switch ( action.type ) { case 'RESET_BLOCKS': case 'SETUP_EDITOR_STATE': @@ -294,7 +294,7 @@ export const editor = flow( [ case 'UPDATE_BLOCK_ATTRIBUTES': // Ignore updates if block isn't known - if ( ! state[ action.uid ] ) { + if ( ! state[ action.clientId ] ) { return state; } @@ -302,7 +302,7 @@ export const editor = flow( [ const nextAttributes = reduce( action.attributes, ( result, value, key ) => { if ( value !== result[ key ] ) { // Avoid mutating original block by creating shallow clone - if ( result === state[ action.uid ].attributes ) { + if ( result === state[ action.clientId ].attributes ) { result = { ...result }; } @@ -310,35 +310,35 @@ export const editor = flow( [ } return result; - }, state[ action.uid ].attributes ); + }, state[ action.clientId ].attributes ); // Skip update if nothing has been changed. The reference will // match the original block if `reduce` had no changed values. - if ( nextAttributes === state[ action.uid ].attributes ) { + if ( nextAttributes === state[ action.clientId ].attributes ) { return state; } // Otherwise merge attributes into state return { ...state, - [ action.uid ]: { - ...state[ action.uid ], + [ action.clientId ]: { + ...state[ action.clientId ], attributes: nextAttributes, }, }; case 'MOVE_BLOCK_TO_POSITION': // Avoid creating a new instance if the layout didn't change. - if ( state[ action.uid ].attributes.layout === action.layout ) { + if ( state[ action.clientId ].attributes.layout === action.layout ) { return state; } return { ...state, - [ action.uid ]: { - ...state[ action.uid ], + [ action.clientId ]: { + ...state[ action.clientId ], attributes: { - ...state[ action.uid ].attributes, + ...state[ action.clientId ].attributes, layout: action.layout, }, }, @@ -346,14 +346,14 @@ export const editor = flow( [ case 'UPDATE_BLOCK': // Ignore updates if block isn't known - if ( ! state[ action.uid ] ) { + if ( ! state[ action.clientId ] ) { return state; } return { ...state, - [ action.uid ]: { - ...state[ action.uid ], + [ action.clientId ]: { + ...state[ action.clientId ], ...action.updates, }, }; @@ -370,12 +370,12 @@ export const editor = flow( [ } return { - ...omit( state, action.uids ), + ...omit( state, action.clientIds ), ...getFlattenedBlocks( action.blocks ), }; case 'REMOVE_BLOCKS': - return omit( state, action.uids ); + return omit( state, action.clientIds ); case 'SAVE_SHARED_BLOCK_SUCCESS': { const { id, updatedId } = action; @@ -417,77 +417,77 @@ export const editor = flow( [ }; case 'INSERT_BLOCKS': { - const { rootUID = '', blocks } = action; - const subState = state[ rootUID ] || []; - const mappedBlocks = mapBlockOrder( blocks, rootUID ); + const { rootClientId = '', blocks } = action; + const subState = state[ rootClientId ] || []; + const mappedBlocks = mapBlockOrder( blocks, rootClientId ); const { index = subState.length } = action; return { ...state, ...mappedBlocks, - [ rootUID ]: insertAt( subState, mappedBlocks[ rootUID ], index ), + [ rootClientId ]: insertAt( subState, mappedBlocks[ rootClientId ], index ), }; } case 'MOVE_BLOCK_TO_POSITION': { - const { fromRootUID = '', toRootUID = '', uid } = action; - const { index = state[ toRootUID ].length } = action; + const { fromRootClientId = '', toRootClientId = '', clientId } = action; + const { index = state[ toRootClientId ].length } = action; // Moving inside the same parent block - if ( fromRootUID === toRootUID ) { - const subState = state[ toRootUID ]; - const fromIndex = subState.indexOf( uid ); + if ( fromRootClientId === toRootClientId ) { + const subState = state[ toRootClientId ]; + const fromIndex = subState.indexOf( clientId ); return { ...state, - [ toRootUID ]: moveTo( state[ toRootUID ], fromIndex, index ), + [ toRootClientId ]: moveTo( state[ toRootClientId ], fromIndex, index ), }; } // Moving from a parent block to another return { ...state, - [ fromRootUID ]: without( state[ fromRootUID ], uid ), - [ toRootUID ]: insertAt( state[ toRootUID ], uid, index ), + [ fromRootClientId ]: without( state[ fromRootClientId ], clientId ), + [ toRootClientId ]: insertAt( state[ toRootClientId ], clientId, index ), }; } case 'MOVE_BLOCKS_UP': { - const { uids, rootUID = '' } = action; - const firstUid = first( uids ); - const subState = state[ rootUID ]; + const { clientIds, rootClientId = '' } = action; + const firstClientId = first( clientIds ); + const subState = state[ rootClientId ]; - if ( ! subState.length || firstUid === first( subState ) ) { + if ( ! subState.length || firstClientId === first( subState ) ) { return state; } - const firstIndex = subState.indexOf( firstUid ); + const firstIndex = subState.indexOf( firstClientId ); return { ...state, - [ rootUID ]: moveTo( subState, firstIndex, firstIndex - 1, uids.length ), + [ rootClientId ]: moveTo( subState, firstIndex, firstIndex - 1, clientIds.length ), }; } case 'MOVE_BLOCKS_DOWN': { - const { uids, rootUID = '' } = action; - const firstUid = first( uids ); - const lastUid = last( uids ); - const subState = state[ rootUID ]; + const { clientIds, rootClientId = '' } = action; + const firstClientId = first( clientIds ); + const lastClientId = last( clientIds ); + const subState = state[ rootClientId ]; - if ( ! subState.length || lastUid === last( subState ) ) { + if ( ! subState.length || lastClientId === last( subState ) ) { return state; } - const firstIndex = subState.indexOf( firstUid ); + const firstIndex = subState.indexOf( firstClientId ); return { ...state, - [ rootUID ]: moveTo( subState, firstIndex, firstIndex + 1, uids.length ), + [ rootClientId ]: moveTo( subState, firstIndex, firstIndex + 1, clientIds.length ), }; } case 'REPLACE_BLOCKS': { - const { blocks, uids } = action; + const { blocks, clientIds } = action; if ( ! blocks ) { return state; } @@ -495,22 +495,22 @@ export const editor = flow( [ const mappedBlocks = mapBlockOrder( blocks ); return flow( [ - ( nextState ) => omit( nextState, uids ), + ( nextState ) => omit( nextState, clientIds ), ( nextState ) => ( { ...nextState, ...omit( mappedBlocks, '' ), } ), ( nextState ) => mapValues( nextState, ( subState ) => ( - reduce( subState, ( result, uid ) => { - if ( uid === uids[ 0 ] ) { + reduce( subState, ( result, clientId ) => { + if ( clientId === clientIds[ 0 ] ) { return [ ...result, ...mappedBlocks[ '' ], ]; } - if ( uids.indexOf( uid ) === -1 ) { - result.push( uid ); + if ( clientIds.indexOf( clientId ) === -1 ) { + result.push( clientId ); } return result; @@ -522,11 +522,11 @@ export const editor = flow( [ case 'REMOVE_BLOCKS': return flow( [ // Remove inner block ordering for removed blocks - ( nextState ) => omit( nextState, action.uids ), + ( nextState ) => omit( nextState, action.clientIds ), // Remove deleted blocks from other blocks' orderings ( nextState ) => mapValues( nextState, ( subState ) => ( - without( subState, ...action.uids ) + without( subState, ...action.clientIds ) ) ), ] )( state ); } @@ -643,25 +643,25 @@ export function blockSelection( state = { initialPosition: null, }; case 'SELECT_BLOCK': - if ( action.uid === state.start && action.uid === state.end ) { + if ( action.clientId === state.start && action.clientId === state.end ) { return state; } return { ...state, - start: action.uid, - end: action.uid, + start: action.clientId, + end: action.clientId, initialPosition: action.initialPosition, }; case 'INSERT_BLOCKS': return { ...state, - start: action.blocks[ 0 ].uid, - end: action.blocks[ 0 ].uid, + start: action.blocks[ 0 ].clientId, + end: action.blocks[ 0 ].clientId, initialPosition: null, isMultiSelecting: false, }; case 'REMOVE_BLOCKS': - if ( ! action.uids || ! action.uids.length || action.uids.indexOf( state.start ) === -1 ) { + if ( ! action.clientIds || ! action.clientIds.length || action.clientIds.indexOf( state.start ) === -1 ) { return state; } return { @@ -672,18 +672,18 @@ export function blockSelection( state = { isMultiSelecting: false, }; case 'REPLACE_BLOCKS': - if ( action.uids.indexOf( state.start ) === -1 ) { + if ( action.clientIds.indexOf( state.start ) === -1 ) { return state; } - // If there is replacement block(s), assign first's UID as the next - // selected block. If empty replacement, reset to null. - const nextSelectedBlockUID = get( action.blocks, [ 0, 'uid' ], null ); + // If there is replacement block(s), assign first's client ID as + // the next selected block. If empty replacement, reset to null. + const nextSelectedBlockClientId = get( action.blocks, [ 0, 'clientId' ], null ); return { ...state, - start: nextSelectedBlockUID, - end: nextSelectedBlockUID, + start: nextSelectedBlockClientId, + end: nextSelectedBlockClientId, initialPosition: null, isMultiSelecting: false, }; @@ -698,20 +698,20 @@ export function blockSelection( state = { } /** - * Reducer returning the UID of the provisional block. A provisional block is - * one which is to be removed if it does not receive updates in the time until - * the next selection or block reset. + * Reducer returning the client ID of the provisional block. A provisional + * block is one which is to be removed if it does not receive updates in the + * time until the next selection or block reset. * * @param {string} state Current state. * @param {Object} action Dispatched action. * * @return {string} Updated state. */ -export function provisionalBlockUID( state = null, action ) { +export function provisionalBlockClientId( state = null, action ) { switch ( action.type ) { case 'INSERT_BLOCKS': if ( action.isProvisional ) { - return first( action.blocks ).uid; + return first( action.blocks ).clientId; } break; @@ -721,16 +721,16 @@ export function provisionalBlockUID( state = null, action ) { case 'UPDATE_BLOCK_ATTRIBUTES': case 'UPDATE_BLOCK': case 'CONVERT_BLOCK_TO_SHARED': - const { uid } = action; - if ( uid === state ) { + const { clientId } = action; + if ( clientId === state ) { return null; } break; case 'REPLACE_BLOCKS': case 'REMOVE_BLOCKS': - const { uids } = action; - if ( includes( uids, state ) ) { + const { clientIds } = action; + if ( includes( clientIds, state ) ) { return null; } break; @@ -741,10 +741,10 @@ export function provisionalBlockUID( state = null, action ) { export function blocksMode( state = {}, action ) { if ( action.type === 'TOGGLE_BLOCK_MODE' ) { - const { uid } = action; + const { clientId } = action; return { ...state, - [ uid ]: state[ uid ] && state[ uid ] === 'html' ? 'visual' : 'html', + [ clientId ]: state[ clientId ] && state[ clientId ] === 'html' ? 'visual' : 'html', }; } @@ -925,9 +925,9 @@ export const sharedBlocks = combineReducers( { case 'RECEIVE_SHARED_BLOCKS': { return reduce( action.results, ( nextState, result ) => { const { id, title } = result.sharedBlock; - const { uid } = result.parsedBlock; + const { clientId } = result.parsedBlock; - const value = { uid, title }; + const value = { clientId, title }; if ( ! isEqual( nextState[ id ], value ) ) { if ( nextState === state ) { @@ -1025,8 +1025,8 @@ export const sharedBlocks = combineReducers( { } ); /** - * Reducer that for each block uid stores an object that represents its nested settings. - * E.g: what blocks can be nested inside a block. + * Reducer returning an object where each key is a block client ID, its value + * representing the settings for its nested blocks. * * @param {Object} state Current state. * @param {Object} action Dispatched action. @@ -1035,28 +1035,29 @@ export const sharedBlocks = combineReducers( { */ export const blockListSettings = ( state = {}, action ) => { switch ( action.type ) { - // even if the replaced blocks have the same uid our logic should correct the state. + // Even if the replaced blocks have the same client ID, our logic + // should correct the state. case 'REPLACE_BLOCKS' : case 'REMOVE_BLOCKS': { - return omit( state, action.uids ); + return omit( state, action.clientIds ); } case 'UPDATE_BLOCK_LIST_SETTINGS': { - const { id } = action; + const { clientId } = action; if ( ! action.settings ) { - if ( state.hasOwnProperty( id ) ) { - return omit( state, id ); + if ( state.hasOwnProperty( clientId ) ) { + return omit( state, clientId ); } return state; } - if ( isEqual( state[ id ], action.settings ) ) { + if ( isEqual( state[ clientId ], action.settings ) ) { return state; } return { ...state, - [ id ]: action.settings, + [ clientId ]: action.settings, }; } } @@ -1126,7 +1127,7 @@ export default optimist( combineReducers( { currentPost, isTyping, blockSelection, - provisionalBlockUID, + provisionalBlockClientId, blocksMode, blockListSettings, isInsertionPointVisible, diff --git a/editor/store/selectors.js b/editor/store/selectors.js index b6494f150d7c7..16ade0c8ca4fc 100644 --- a/editor/store/selectors.js +++ b/editor/store/selectors.js @@ -25,6 +25,7 @@ import createSelector from 'rememo'; import { serialize, getBlockType, getBlockTypes, hasBlockSupport, hasChildBlocks } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; import { moment } from '@wordpress/date'; +import deprecated from '@wordpress/deprecated'; /*** * Module constants @@ -443,54 +444,55 @@ export function getDocumentTitle( state ) { } /** - * Returns a new reference when the inner blocks of a given block UID change. - * This is used exclusively as a memoized selector dependant, relying on this - * selector's shared return value and recursively those of its inner blocks - * defined as dependencies. This abuses mechanics of the selector memoization - * to return from the original selector function only when dependants change. + * Returns a new reference when the inner blocks of a given block client ID + * change. This is used exclusively as a memoized selector dependant, relying + * on this selector's shared return value and recursively those of its inner + * blocks defined as dependencies. This abuses mechanics of the selector + * memoization to return from the original selector function only when + * dependants change. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {*} A value whose reference will change only when inner blocks of - * the given block UID change. + * the given block client ID change. */ export const getBlockDependantsCacheBust = createSelector( () => [], - ( state, uid ) => map( - getBlockOrder( state, uid ), - ( innerBlockUID ) => getBlock( state, innerBlockUID ), + ( state, clientId ) => map( + getBlockOrder( state, clientId ), + ( innerBlockClientId ) => getBlock( state, innerBlockClientId ), ), ); /** - * Returns a block's name given its UID, or null if no block exists with the - * UID. + * Returns a block's name given its client ID, or null if no block exists with + * the client ID. * - * @param {Object} state Editor state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {string} Block name. */ -export function getBlockName( state, uid ) { - const block = state.editor.present.blocksByUID[ uid ]; +export function getBlockName( state, clientId ) { + const block = state.editor.present.blocksByClientId[ clientId ]; return block ? block.name : null; } /** - * Returns a block given its unique ID. This is a parsed copy of the block, - * containing its `blockName`, identifier (`uid`), and current `attributes` - * state. This is not the block's registration settings, which must be - * retrieved from the blocks module registration store. + * Returns a block given its client ID. This is a parsed copy of the block, + * containing its `blockName`, `clientId`, and current `attributes` state. This + * is not the block's registration settings, which must be retrieved from the + * blocks module registration store. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {Object} Parsed block object. */ export const getBlock = createSelector( - ( state, uid ) => { - const block = state.editor.present.blocksByUID[ uid ]; + ( state, clientId ) => { + const block = state.editor.present.blocksByClientId[ clientId ]; if ( ! block ) { return null; } @@ -519,12 +521,12 @@ export const getBlock = createSelector( return { ...block, attributes, - innerBlocks: getBlocks( state, uid ), + innerBlocks: getBlocks( state, clientId ), }; }, - ( state, uid ) => [ - state.editor.present.blocksByUID[ uid ], - getBlockDependantsCacheBust( state, uid ), + ( state, clientId ) => [ + state.editor.present.blocksByClientId[ clientId ], + getBlockDependantsCacheBust( state, clientId ), state.editor.present.edits.meta, state.currentPost.meta, ] @@ -539,23 +541,25 @@ function getPostMeta( state, key ) { /** * Returns all block objects for the current post being edited as an array in * the order they appear in the post. - * Note: It's important to memoize this selector to avoid return a new instance on each call * - * @param {Object} state Global application state. - * @param {?String} rootUID Optional root UID of block list. + * Note: It's important to memoize this selector to avoid return a new instance + * on each call + * + * @param {Object} state Editor state. + * @param {?String} rootClientId Optional root client ID of block list. * * @return {Object[]} Post blocks. */ export const getBlocks = createSelector( - ( state, rootUID ) => { + ( state, rootClientId ) => { return map( - getBlockOrder( state, rootUID ), - ( uid ) => getBlock( state, uid ) + getBlockOrder( state, rootClientId ), + ( clientId ) => getBlock( state, clientId ) ); }, ( state ) => [ state.editor.present.blockOrder, - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, ] ); @@ -571,42 +575,52 @@ export const getBlocks = createSelector( export const getGlobalBlockCount = createSelector( ( state, blockName ) => { if ( ! blockName ) { - return size( state.editor.present.blocksByUID ); + return size( state.editor.present.blocksByClientId ); } return reduce( - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, ( count, block ) => block.name === blockName ? count + 1 : count, 0 ); }, ( state ) => [ - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, ] ); -export const getBlocksByUID = createSelector( - ( state, uids ) => { - return map( castArray( uids ), ( uid ) => getBlock( state, uid ) ); - }, +/** + * Given an array of block client IDs, returns the corresponding array of block + * objects. + * + * @param {Object} state Editor state. + * @param {string[]} clientIds Client IDs for which blocks are to be returned. + * + * @return {WPBlock[]} Block objects. + */ +export const getBlocksByClientId = createSelector( + ( state, clientIds ) => map( + castArray( clientIds ), + ( clientId ) => getBlock( state, clientId ) + ), ( state ) => [ - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, state.editor.present.blockOrder, state.editor.present.edits.meta, state.currentPost.meta, - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, ] ); /** * Returns the number of blocks currently present in the post. * - * @param {Object} state Global application state. - * @param {?string} rootUID Optional root UID of block list. + * @param {Object} state Editor state. + * @param {?string} rootClientId Optional root client ID of block list. * * @return {number} Number of blocks in the post. */ -export function getBlockCount( state, rootUID ) { - return getBlockOrder( state, rootUID ).length; +export function getBlockCount( state, rootClientId ) { + return getBlockOrder( state, rootClientId ).length; } /** @@ -616,7 +630,7 @@ export function getBlockCount( state, rootUID ) { * * @param {Object} state Global application state. * - * @return {?string} UID of block selection start. + * @return {?string} Client ID of block selection start. */ export function getBlockSelectionStart( state ) { return state.blockSelection.start; @@ -629,7 +643,7 @@ export function getBlockSelectionStart( state ) { * * @param {Object} state Global application state. * - * @return {?string} UID of block selection end. + * @return {?string} Client ID of block selection end. */ export function getBlockSelectionEnd( state ) { return state.blockSelection.end; @@ -643,7 +657,7 @@ export function getBlockSelectionEnd( state ) { * @return {number} Number of blocks selected in the post. */ export function getSelectedBlockCount( state ) { - const multiSelectedBlockCount = getMultiSelectedBlockUids( state ).length; + const multiSelectedBlockCount = getMultiSelectedBlockClientIds( state ).length; if ( multiSelectedBlockCount ) { return multiSelectedBlockCount; @@ -665,14 +679,14 @@ export function hasSelectedBlock( state ) { } /** - * Returns the currently selected block UID, or null if there is no selected - * block. + * Returns the currently selected block client ID, or null if there is no + * selected block. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * - * @return {?Object} Selected block UID. + * @return {?string} Selected block client ID. */ -export function getSelectedBlockUID( state ) { +export function getSelectedBlockClientId( state ) { const { start, end } = state.blockSelection; return start === end && start ? start : null; } @@ -685,25 +699,26 @@ export function getSelectedBlockUID( state ) { * @return {?Object} Selected block. */ export function getSelectedBlock( state ) { - const uid = getSelectedBlockUID( state ); - return uid ? getBlock( state, uid ) : null; + const clientId = getSelectedBlockClientId( state ); + return clientId ? getBlock( state, clientId ) : null; } /** - * Given a block UID, returns the root block from which the block is nested, an - * empty string for top-level blocks, or null if the block does not exist. + * Given a block client ID, returns the root block from which the block is + * nested, an empty string for top-level blocks, or null if the block does not + * exist. * - * @param {Object} state Global application state. - * @param {string} uid Block from which to find root UID. + * @param {Object} state Editor state. + * @param {string} clientId Block from which to find root client ID. * - * @return {?string} Root UID, if exists + * @return {?string} Root client ID, if exists */ -export function getBlockRootUID( state, uid ) { +export function getBlockRootClientId( state, clientId ) { const { blockOrder } = state.editor.present; - for ( const rootUID in blockOrder ) { - if ( includes( blockOrder[ rootUID ], uid ) ) { - return rootUID; + for ( const rootClientId in blockOrder ) { + if ( includes( blockOrder[ rootClientId ], clientId ) ) { + return rootClientId; } } @@ -711,46 +726,49 @@ export function getBlockRootUID( state, uid ) { } /** - * Returns the UID of the block adjacent one at the given reference startUID and modifier - * directionality. Defaults start UID to the selected block, and direction as - * next block. Returns null if there is no adjacent block. + * Returns the client ID of the block adjacent one at the given reference + * startClientId and modifier directionality. Defaults start startClientId to + * the selected block, and direction as next block. Returns null if there is no + * adjacent block. * - * @param {Object} state Global application state. - * @param {?string} startUID Optional UID of block from which to search. - * @param {?number} modifier Directionality multiplier (1 next, -1 previous). + * @param {Object} state Editor state. + * @param {?string} startClientId Optional client ID of block from which to + * search. + * @param {?number} modifier Directionality multiplier (1 next, -1 + * previous). * - * @return {?string} Return the UID of the block, or null if none exists. + * @return {?string} Return the client ID of the block, or null if none exists. */ -export function getAdjacentBlockUid( state, startUID, modifier = 1 ) { +export function getAdjacentBlockClientId( state, startClientId, modifier = 1 ) { // Default to selected block. - if ( startUID === undefined ) { - startUID = get( getSelectedBlock( state ), [ 'uid' ] ); + if ( startClientId === undefined ) { + startClientId = getSelectedBlockClientId( state ); } // Try multi-selection starting at extent based on modifier. - if ( startUID === undefined ) { + if ( startClientId === undefined ) { if ( modifier < 0 ) { - startUID = getFirstMultiSelectedBlockUid( state ); + startClientId = getFirstMultiSelectedBlockClientId( state ); } else { - startUID = getLastMultiSelectedBlockUid( state ); + startClientId = getLastMultiSelectedBlockClientId( state ); } } - // Validate working start UID. - if ( ! startUID ) { + // Validate working start client ID. + if ( ! startClientId ) { return null; } - // Retrieve start block root UID, being careful to allow the falsey empty - // string top-level root UID by explicitly testing against null. - const rootUID = getBlockRootUID( state, startUID ); - if ( rootUID === null ) { + // Retrieve start block root client ID, being careful to allow the falsey + // empty string top-level root by explicitly testing against null. + const rootClientId = getBlockRootClientId( state, startClientId ); + if ( rootClientId === null ) { return null; } const { blockOrder } = state.editor.present; - const orderSet = blockOrder[ rootUID ]; - const index = orderSet.indexOf( startUID ); + const orderSet = blockOrder[ rootClientId ]; + const index = orderSet.indexOf( startClientId ); const nextIndex = ( index + ( 1 * modifier ) ); // Block was first in set and we're attempting to get previous. @@ -768,29 +786,33 @@ export function getAdjacentBlockUid( state, startUID, modifier = 1 ) { } /** - * Returns the previous block's UID from the given reference startUID. Defaults start - * UID to the selected block. Returns null if there is no previous block. + * Returns the previous block's client ID from the given reference start ID. + * Defaults start to the selected block. Returns null if there is no previous + * block. * - * @param {Object} state Global application state. - * @param {?string} startUID Optional UID of block from which to search. + * @param {Object} state Editor state. + * @param {?string} startClientId Optional client ID of block from which to + * search. * - * @return {?string} Adjacent block's UID, or null if none exists. + * @return {?string} Adjacent block's client ID, or null if none exists. */ -export function getPreviousBlockUid( state, startUID ) { - return getAdjacentBlockUid( state, startUID, -1 ); +export function getPreviousBlockClientId( state, startClientId ) { + return getAdjacentBlockClientId( state, startClientId, -1 ); } /** - * Returns the next block's UID from the given reference startUID. Defaults start UID - * to the selected block. Returns null if there is no next block. + * Returns the next block's client ID from the given reference start ID. + * Defaults start to the selected block. Returns null if there is no next + * block. * - * @param {Object} state Global application state. - * @param {?string} startUID Optional UID of block from which to search. + * @param {Object} state Editor state. + * @param {?string} startClientId Optional client ID of block from which to + * search. * - * @return {?string} Adjacent block's UID, or null if none exists. + * @return {?string} Adjacent block's client ID, or null if none exists. */ -export function getNextBlockUid( state, startUID ) { - return getAdjacentBlockUid( state, startUID, 1 ); +export function getNextBlockClientId( state, startClientId ) { + return getAdjacentBlockClientId( state, startClientId, 1 ); } /** @@ -811,29 +833,29 @@ export function getSelectedBlocksInitialCaretPosition( state ) { } /** - * Returns the current multi-selection set of blocks unique IDs, or an empty + * Returns the current multi-selection set of block client IDs, or an empty * array if there is no multi-selection. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * - * @return {Array} Multi-selected block unique IDs. + * @return {Array} Multi-selected block client IDs. */ -export const getMultiSelectedBlockUids = createSelector( +export const getMultiSelectedBlockClientIds = createSelector( ( state ) => { const { start, end } = state.blockSelection; if ( start === end ) { return []; } - // Retrieve root UID to aid in retrieving relevant nested block order, - // being careful to allow the falsey empty string top-level root UID by - // explicitly testing against null. - const rootUID = getBlockRootUID( state, start ); - if ( rootUID === null ) { + // Retrieve root client ID to aid in retrieving relevant nested block + // order, being careful to allow the falsey empty string top-level root + // by explicitly testing against null. + const rootClientId = getBlockRootClientId( state, start ); + if ( rootClientId === null ) { return []; } - const blockOrder = getBlockOrder( state, rootUID ); + const blockOrder = getBlockOrder( state, rootClientId ); const startIndex = blockOrder.indexOf( start ); const endIndex = blockOrder.indexOf( end ); @@ -854,95 +876,97 @@ export const getMultiSelectedBlockUids = createSelector( * Returns the current multi-selection set of blocks, or an empty array if * there is no multi-selection. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * * @return {Array} Multi-selected block objects. */ export const getMultiSelectedBlocks = createSelector( ( state ) => { - const multiSelectedBlockUids = getMultiSelectedBlockUids( state ); - if ( ! multiSelectedBlockUids.length ) { + const multiSelectedBlockClientIds = getMultiSelectedBlockClientIds( state ); + if ( ! multiSelectedBlockClientIds.length ) { return EMPTY_ARRAY; } - return multiSelectedBlockUids.map( ( uid ) => getBlock( state, uid ) ); + return multiSelectedBlockClientIds.map( ( clientId ) => getBlock( state, clientId ) ); }, ( state ) => [ state.editor.present.blockOrder, state.blockSelection.start, state.blockSelection.end, - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, state.editor.present.edits.meta, state.currentPost.meta, ] ); /** - * Returns the unique ID of the first block in the multi-selection set, or null + * Returns the client ID of the first block in the multi-selection set, or null * if there is no multi-selection. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * - * @return {?string} First unique block ID in the multi-selection set. + * @return {?string} First block client ID in the multi-selection set. */ -export function getFirstMultiSelectedBlockUid( state ) { - return first( getMultiSelectedBlockUids( state ) ) || null; +export function getFirstMultiSelectedBlockClientId( state ) { + return first( getMultiSelectedBlockClientIds( state ) ) || null; } /** - * Returns the unique ID of the last block in the multi-selection set, or null + * Returns the client ID of the last block in the multi-selection set, or null * if there is no multi-selection. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * - * @return {?string} Last unique block ID in the multi-selection set. + * @return {?string} Last block client ID in the multi-selection set. */ -export function getLastMultiSelectedBlockUid( state ) { - return last( getMultiSelectedBlockUids( state ) ) || null; +export function getLastMultiSelectedBlockClientId( state ) { + return last( getMultiSelectedBlockClientIds( state ) ) || null; } /** * Returns true if a multi-selection exists, and the block corresponding to the - * specified unique ID is the first block of the multi-selection set, or false + * specified client ID is the first block of the multi-selection set, or false * otherwise. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {boolean} Whether block is first in mult-selection. */ -export function isFirstMultiSelectedBlock( state, uid ) { - return getFirstMultiSelectedBlockUid( state ) === uid; +export function isFirstMultiSelectedBlock( state, clientId ) { + return getFirstMultiSelectedBlockClientId( state ) === clientId; } /** - * Returns true if the unique ID occurs within the block multi-selection, or + * Returns true if the client ID occurs within the block multi-selection, or * false otherwise. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {boolean} Whether block is in multi-selection set. */ -export function isBlockMultiSelected( state, uid ) { - return getMultiSelectedBlockUids( state ).indexOf( uid ) !== -1; +export function isBlockMultiSelected( state, clientId ) { + return getMultiSelectedBlockClientIds( state ).indexOf( clientId ) !== -1; } /** - * Returns true if an ancestor of the block is multi-selected and false otherwise. + * Returns true if an ancestor of the block is multi-selected, or false + * otherwise. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * - * @return {boolean} Whether an ancestor of the block is in multi-selection set. + * @return {boolean} Whether an ancestor of the block is in multi-selection + * set. */ export const isAncestorMultiSelected = createSelector( - ( state, uid ) => { - let ancestorUid = uid; + ( state, clientId ) => { + let ancestorClientId = clientId; let isMultiSelected = false; - while ( ancestorUid && ! isMultiSelected ) { - ancestorUid = getBlockRootUID( state, ancestorUid ); - isMultiSelected = isBlockMultiSelected( state, ancestorUid ); + while ( ancestorClientId && ! isMultiSelected ) { + ancestorClientId = getBlockRootClientId( state, ancestorClientId ); + isMultiSelected = isBlockMultiSelected( state, ancestorClientId ); } return isMultiSelected; }, @@ -953,17 +977,18 @@ export const isAncestorMultiSelected = createSelector( ], ); /** - * Returns the unique ID of the block which begins the multi-selection set, or + * Returns the client ID of the block which begins the multi-selection set, or * null if there is no multi-selection. * - * N.b.: This is not necessarily the first uid in the selection. See - * getFirstMultiSelectedBlockUid(). + * This is not necessarily the first client ID in the selection. * - * @param {Object} state Global application state. + * @see getFirstMultiSelectedBlockClientId + * + * @param {Object} state Editor state. * - * @return {?string} Unique ID of block beginning multi-selection. + * @return {?string} Client ID of block beginning multi-selection. */ -export function getMultiSelectedBlocksStartUid( state ) { +export function getMultiSelectedBlocksStartClientId( state ) { const { start, end } = state.blockSelection; if ( start === end ) { return null; @@ -972,17 +997,18 @@ export function getMultiSelectedBlocksStartUid( state ) { } /** - * Returns the unique ID of the block which ends the multi-selection set, or + * Returns the client ID of the block which ends the multi-selection set, or * null if there is no multi-selection. * - * N.b.: This is not necessarily the last uid in the selection. See - * getLastMultiSelectedBlockUid(). + * This is not necessarily the last client ID in the selection. * - * @param {Object} state Global application state. + * @see getLastMultiSelectedBlockClientId + * + * @param {Object} state Editor state. * - * @return {?string} Unique ID of block ending multi-selection. + * @return {?string} Client ID of block ending multi-selection. */ -export function getMultiSelectedBlocksEndUid( state ) { +export function getMultiSelectedBlocksEndClientId( state ) { const { start, end } = state.blockSelection; if ( start === end ) { return null; @@ -991,85 +1017,87 @@ export function getMultiSelectedBlocksEndUid( state ) { } /** - * Returns an array containing all block unique IDs of the post being edited, - * in the order they appear in the post. Optionally accepts a root UID of the - * block list for which the order should be returned, defaulting to the top- - * level block order. + * Returns an array containing all block client IDs in the editor in the order + * they appear. Optionally accepts a root client ID of the block list for which + * the order should be returned, defaulting to the top-level block order. * - * @param {Object} state Global application state. - * @param {?string} rootUID Optional root UID of block list. + * @param {Object} state Editor state. + * @param {?string} rootClientId Optional root client ID of block list. * - * @return {Array} Ordered unique IDs of post blocks. + * @return {Array} Ordered client IDs of editor blocks. */ -export function getBlockOrder( state, rootUID ) { - return state.editor.present.blockOrder[ rootUID || '' ] || EMPTY_ARRAY; +export function getBlockOrder( state, rootClientId ) { + return state.editor.present.blockOrder[ rootClientId || '' ] || EMPTY_ARRAY; } /** - * Returns the index at which the block corresponding to the specified unique ID - * occurs within the post block order, or `-1` if the block does not exist. + * Returns the index at which the block corresponding to the specified client + * ID occurs within the block order, or `-1` if the block does not exist. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. - * @param {?string} rootUID Optional root UID of block list. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. + * @param {?string} rootClientId Optional root client ID of block list. * * @return {number} Index at which block exists in order. */ -export function getBlockIndex( state, uid, rootUID ) { - return getBlockOrder( state, rootUID ).indexOf( uid ); +export function getBlockIndex( state, clientId, rootClientId ) { + return getBlockOrder( state, rootClientId ).indexOf( clientId ); } /** - * Returns true if the block corresponding to the specified unique ID is + * Returns true if the block corresponding to the specified client ID is * currently selected and no multi-selection exists, or false otherwise. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {boolean} Whether block is selected and multi-selection exists. */ -export function isBlockSelected( state, uid ) { +export function isBlockSelected( state, clientId ) { const { start, end } = state.blockSelection; if ( start !== end ) { return false; } - return start === uid; + return start === clientId; } /** * Returns true if one of the block's inner blocks is selected. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {boolean} Whether the block as an inner block selected */ -export function hasSelectedInnerBlock( state, uid ) { - return some( getBlockOrder( state, uid ), ( innerUID ) => isBlockSelected( state, innerUID ) ); +export function hasSelectedInnerBlock( state, clientId ) { + return some( + getBlockOrder( state, clientId ), + ( innerClientId ) => isBlockSelected( state, innerClientId ) + ); } /** - * Returns true if the block corresponding to the specified unique ID is + * Returns true if the block corresponding to the specified client ID is * currently selected but isn't the last of the selected blocks. Here "last" * refers to the block sequence in the document, _not_ the sequence of * multi-selection, which is why `state.blockSelection.end` isn't used. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * - * @return {boolean} Whether block is selected and not the last in - * the selection. + * @return {boolean} Whether block is selected and not the last in the + * selection. */ -export function isBlockWithinSelection( state, uid ) { - if ( ! uid ) { +export function isBlockWithinSelection( state, clientId ) { + if ( ! clientId ) { return false; } - const uids = getMultiSelectedBlockUids( state ); - const index = uids.indexOf( uid ); - return index > -1 && index < uids.length - 1; + const clientIds = getMultiSelectedBlockClientIds( state ); + const index = clientIds.indexOf( clientId ); + return index > -1 && index < clientIds.length - 1; } /** @@ -1111,15 +1139,16 @@ export function isSelectionEnabled( state ) { } /** - * Returns thee block's editing mode. + * Returns the block's editing mode, defaulting to "visual" if not explicitly + * assigned. * - * @param {Object} state Global application state. - * @param {string} uid Block unique ID. + * @param {Object} state Editor state. + * @param {string} clientId Block client ID. * * @return {Object} Block editing mode. */ -export function getBlockMode( state, uid ) { - return state.blocksMode[ uid ] || 'visual'; +export function getBlockMode( state, clientId ) { + return state.blocksMode[ clientId ] || 'visual'; } /** @@ -1137,24 +1166,27 @@ export function isTyping( state ) { * Returns the insertion point, the index at which the new inserted block would * be placed. Defaults to the last index. * - * @param {Object} state Global application state. + * @param {Object} state Editor state. * - * @return {Object} Insertion point object with `rootUID`, `layout`, `index` + * @return {Object} Insertion point object with `rootClientId`, `layout`, + * `index`. */ export function getBlockInsertionPoint( state ) { - let rootUID, layout, index; + let rootClientId, layout, index; const { end } = state.blockSelection; if ( end ) { - rootUID = getBlockRootUID( state, end ) || undefined; + rootClientId = getBlockRootClientId( state, end ) || undefined; layout = get( getBlock( state, end ), [ 'attributes', 'layout' ] ); - index = getBlockIndex( state, end, rootUID ) + 1; + index = getBlockIndex( state, end, rootClientId ) + 1; } else { index = getBlockOrder( state ).length; } - return { rootUID, layout, index }; + // TODO: With deprecation of "UID" nomenclature in 3.5, ensure to remove + // the `rootUID` property here. + return { rootUID: rootClientId, rootClientId, layout, index }; } /** @@ -1189,22 +1221,24 @@ export function getTemplate( state ) { } /** - * Returns the defined block template lock - * in the context of a given root block or in the global context. + * Returns the defined block template lock. Optionally accepts a root block + * client ID as context, otherwise defaulting to the global context. * - * @param {boolean} state - * @param {?string} rootUID Block UID. + * @param {Object} state Editor state. + * @param {?string} rootClientId Optional block root client ID. * - * @return {?string} Block Template Lock + * @return {?string} Block Template Lock */ -export function getTemplateLock( state, rootUID ) { - if ( ! rootUID ) { +export function getTemplateLock( state, rootClientId ) { + if ( ! rootClientId ) { return state.settings.templateLock; } - const blockListSettings = getBlockListSettings( state, rootUID ); + + const blockListSettings = getBlockListSettings( state, rootClientId ); if ( ! blockListSettings ) { return null; } + return blockListSettings.templateLock; } @@ -1322,7 +1356,7 @@ export const getEditedPostContent = createSelector( }, ( state ) => [ state.editor.present.edits.content, - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, state.editor.present.blockOrder, ], ); @@ -1340,17 +1374,19 @@ export function getNotices( state ) { /** * Determines if the given block type is allowed to be inserted, and, if - * parentUID is provided, whether it is allowed to be nested within the given - * parent. + * parentClientId is provided, whether it is allowed to be nested within the + * given parent. * - * @param {Object} state Global application state. - * @param {string} blockName The name of the given block type, e.g. 'core/paragraph'. - * @param {?string} parentUID The parent that the given block is to be nested within, or null. + * @param {Object} state Editor state. + * @param {string} blockName The name of the given block type, e.g. + * 'core/paragraph'. + * @param {?string} parentClientId The parent that the given block is to be + * nested within, or null. * - * @return {boolean} Whether or not the given block type is allowed to be inserted. + * @return {boolean} Whether the given block type is allowed to be inserted. */ export const canInsertBlockType = createSelector( - ( state, blockName, parentUID = null ) => { + ( state, blockName, parentClientId = null ) => { const checkAllowList = ( list, item, defaultResult = null ) => { if ( isBoolean( list ) ) { return list; @@ -1373,17 +1409,17 @@ export const canInsertBlockType = createSelector( return false; } - const isLocked = !! getTemplateLock( state, parentUID ); + const isLocked = !! getTemplateLock( state, parentClientId ); if ( isLocked ) { return false; } - const parentBlockListSettings = getBlockListSettings( state, parentUID ); + const parentBlockListSettings = getBlockListSettings( state, parentClientId ); const parentAllowedBlocks = get( parentBlockListSettings, [ 'allowedBlocks' ] ); const hasParentAllowedBlock = checkAllowList( parentAllowedBlocks, blockName ); const blockAllowedParentBlocks = blockType.parent; - const parentName = getBlockName( state, parentUID ); + const parentName = getBlockName( state, parentClientId ); const hasBlockAllowedParent = checkAllowList( blockAllowedParentBlocks, parentName ); if ( hasParentAllowedBlock !== null && hasBlockAllowedParent !== null ) { @@ -1396,9 +1432,9 @@ export const canInsertBlockType = createSelector( return true; }, - ( state, blockName, parentUID ) => [ - state.blockListSettings[ parentUID ], - state.editor.present.blocksByUID[ parentUID ], + ( state, blockName, parentClientId ) => [ + state.blockListSettings[ parentClientId ], + state.editor.present.blocksByClientId[ parentClientId ], state.settings.allowedBlockTypes, state.settings.templateLock, ], @@ -1438,8 +1474,8 @@ function getInsertUsage( state, id ) { * * Items are returned ordered descendingly by their 'utility' and 'frecency'. * - * @param {Object} state Global application state. - * @param {?string} parentUID The block we are inserting into, if any. + * @param {Object} state Editor state. + * @param {?string} parentClientId The block we are inserting into, if any. * * @return {Editor.InserterItem[]} Items that appear in inserter. * @@ -1457,7 +1493,7 @@ function getInsertUsage( state, id ) { * @property {number} frecency Hueristic that combines frequency and recency. */ export const getInserterItems = createSelector( - ( state, parentUID = null ) => { + ( state, parentClientId = null ) => { const calculateUtility = ( category, count, isContextual ) => { if ( isContextual ) { return INSERTER_UTILITY_HIGH; @@ -1495,7 +1531,7 @@ export const getInserterItems = createSelector( return false; } - return canInsertBlockType( state, blockType.name, parentUID ); + return canInsertBlockType( state, blockType.name, parentClientId ); }; const buildBlockTypeInserterItem = ( blockType ) => { @@ -1525,11 +1561,11 @@ export const getInserterItems = createSelector( }; const shouldIncludeSharedBlock = ( sharedBlock ) => { - if ( ! canInsertBlockType( state, 'core/block', parentUID ) ) { + if ( ! canInsertBlockType( state, 'core/block', parentClientId ) ) { return false; } - const referencedBlock = getBlock( state, sharedBlock.uid ); + const referencedBlock = getBlock( state, sharedBlock.clientId ); if ( ! referencedBlock ) { return false; } @@ -1539,7 +1575,7 @@ export const getInserterItems = createSelector( return false; } - if ( ! canInsertBlockType( state, referencedBlockType.name, parentUID ) ) { + if ( ! canInsertBlockType( state, referencedBlockType.name, parentClientId ) ) { return false; } @@ -1549,7 +1585,7 @@ export const getInserterItems = createSelector( const buildSharedBlockInserterItem = ( sharedBlock ) => { const id = `core/block/${ sharedBlock.id }`; - const referencedBlock = getBlock( state, sharedBlock.uid ); + const referencedBlock = getBlock( state, sharedBlock.clientId ); const referencedBlockType = getBlockType( referencedBlock.name ); const { time, count = 0 } = getInsertUsage( state, id ) || {}; @@ -1584,10 +1620,10 @@ export const getInserterItems = createSelector( [ 'desc', 'desc' ] ); }, - ( state, parentUID ) => [ - state.blockListSettings[ parentUID ], + ( state, parentClientId ) => [ + state.blockListSettings[ parentClientId ], state.editor.present.blockOrder, - state.editor.present.blocksByUID, + state.editor.present.blocksByClientId, state.preferences.insertUsage, state.settings.allowedBlockTypes, state.settings.templateLock, @@ -1709,14 +1745,15 @@ export function isPublishingPost( state ) { } /** - * Returns the provisional block UID, or null if there is no provisional block. + * Returns the provisional block client ID, or null if there is no provisional + * block. * * @param {Object} state Editor state. * - * @return {?string} Provisional block UID, if set. + * @return {?string} Provisional block client ID, if set. */ -export function getProvisionalBlockUID( state ) { - return state.provisionalBlockUID; +export function getProvisionalBlockClientId( state ) { + return state.provisionalBlockClientId; } /** @@ -1792,15 +1829,15 @@ export function inSomeHistory( state, predicate ) { } /** - * Returns the Block List settings of a block if any. + * Returns the Block List settings of a block, if any exist. * - * @param {Object} state Editor state. - * @param {?string} uid Block UID. + * @param {Object} state Editor state. + * @param {?string} clientId Block client ID. * * @return {?Object} Block settings of the block if set. */ -export function getBlockListSettings( state, uid ) { - return state.blockListSettings[ uid ]; +export function getBlockListSettings( state, clientId ) { + return state.blockListSettings[ clientId ]; } /* @@ -1839,3 +1876,123 @@ export function getTokenSettings( state, name ) { export function canUserUseUnfilteredHTML( state ) { return has( getCurrentPost( state ), [ '_links', 'wp:action-unfiltered_html' ] ); } + +export function getAdjacentBlockUid( state, startUID, modifier ) { + deprecated( 'getAdjacentBlockUid', { + alternative: 'getAdjacentBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getAdjacentBlockClientId( state, startUID, modifier ); +} + +export function getBlockRootUID( state, uid ) { + deprecated( 'getBlockRootUID', { + alternative: 'getBlockRootClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getBlockRootClientId( state, uid ); +} + +export function getSelectedBlockUID( state ) { + deprecated( 'getSelectedBlockUID', { + alternative: 'getSelectedBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getSelectedBlockClientId( state ); +} + +export function getBlocksByUID( state, uids ) { + deprecated( 'getBlocksByUID', { + alternative: 'getBlocksByClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getBlocksByClientId( state, uids ); +} + +export function getPreviousBlockUid( state, startUID ) { + deprecated( 'getPreviousBlockUid', { + alternative: 'getPreviousBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getPreviousBlockClientId( state, startUID ); +} + +export function getNextBlockUid( state, startUID ) { + deprecated( 'getNextBlockUid', { + alternative: 'getNextBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getNextBlockClientId( state, startUID ); +} + +export function getMultiSelectedBlockUids( state ) { + deprecated( 'getMultiSelectedBlockUids', { + alternative: 'getMultiSelectedBlockClientIds', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getMultiSelectedBlockClientIds( state ); +} + +export function getFirstMultiSelectedBlockUid( state ) { + deprecated( 'getFirstMultiSelectedBlockUid', { + alternative: 'getFirstMultiSelectedBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getFirstMultiSelectedBlockClientId( state ); +} + +export function getLastMultiSelectedBlockUid( state ) { + deprecated( 'getLastMultiSelectedBlockUid', { + alternative: 'getLastMultiSelectedBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getLastMultiSelectedBlockClientId( state ); +} + +export function getMultiSelectedBlocksStartUid( state ) { + deprecated( 'getMultiSelectedBlocksStartUid', { + alternative: 'getMultiSelectedBlocksStartClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getMultiSelectedBlocksStartClientId( state ); +} + +export function getMultiSelectedBlocksEndUid( state ) { + deprecated( 'getMultiSelectedBlocksEndUid', { + alternative: 'getMultiSelectedBlocksEndClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getMultiSelectedBlocksEndClientId( state ); +} + +export function getProvisionalBlockUID( state ) { + deprecated( 'getProvisionalBlockUID', { + alternative: 'getProvisionalBlockClientId', + version: 'v3.5', + plugin: 'Gutenberg', + } ); + + return getProvisionalBlockClientId( state ); +} diff --git a/editor/store/test/actions.js b/editor/store/test/actions.js index 401250bfeff59..2f48edb07e0c7 100644 --- a/editor/store/test/actions.js +++ b/editor/store/test/actions.js @@ -81,12 +81,12 @@ describe( 'actions', () => { describe( 'updateBlockAttributes', () => { it( 'should return the UPDATE_BLOCK_ATTRIBUTES action', () => { - const uid = 'my-uid'; + const clientId = 'myclientid'; const attributes = {}; - const result = updateBlockAttributes( uid, attributes ); + const result = updateBlockAttributes( clientId, attributes ); expect( result ).toEqual( { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid, + clientId, attributes, } ); } ); @@ -94,12 +94,12 @@ describe( 'actions', () => { describe( 'updateBlock', () => { it( 'should return the UPDATE_BLOCK action', () => { - const uid = 'myuid'; + const clientId = 'myclientid'; const updates = {}; - const result = updateBlock( uid, updates ); + const result = updateBlock( clientId, updates ); expect( result ).toEqual( { type: 'UPDATE_BLOCK', - uid, + clientId, updates, } ); } ); @@ -107,12 +107,12 @@ describe( 'actions', () => { describe( 'selectBlock', () => { it( 'should return the SELECT_BLOCK action', () => { - const uid = 'my-uid'; - const result = selectBlock( uid, -1 ); + const clientId = 'myclientid'; + const result = selectBlock( clientId, -1 ); expect( result ).toEqual( { type: 'SELECT_BLOCK', initialPosition: -1, - uid, + clientId, } ); } ); } ); @@ -155,12 +155,12 @@ describe( 'actions', () => { describe( 'replaceBlock', () => { it( 'should return the REPLACE_BLOCKS action', () => { const block = { - uid: 'ribs', + clientId: 'ribs', }; expect( replaceBlock( [ 'chicken' ], block ) ).toEqual( { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks: [ block ], time: expect.any( Number ), } ); @@ -170,12 +170,12 @@ describe( 'actions', () => { describe( 'replaceBlocks', () => { it( 'should return the REPLACE_BLOCKS action', () => { const blocks = [ { - uid: 'ribs', + clientId: 'ribs', } ]; expect( replaceBlocks( [ 'chicken' ], blocks ) ).toEqual( { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks, time: expect.any( Number ), } ); @@ -185,14 +185,14 @@ describe( 'actions', () => { describe( 'insertBlock', () => { it( 'should return the INSERT_BLOCKS action', () => { const block = { - uid: 'ribs', + clientId: 'ribs', }; const index = 5; - expect( insertBlock( block, index, 'test_uid' ) ).toEqual( { + expect( insertBlock( block, index, 'testclientid' ) ).toEqual( { type: 'INSERT_BLOCKS', blocks: [ block ], index, - rootUID: 'test_uid', + rootClientId: 'testclientid', time: expect.any( Number ), } ); } ); @@ -201,14 +201,14 @@ describe( 'actions', () => { describe( 'insertBlocks', () => { it( 'should return the INSERT_BLOCKS action', () => { const blocks = [ { - uid: 'ribs', + clientId: 'ribs', } ]; const index = 3; - expect( insertBlocks( blocks, index, 'test_uid' ) ).toEqual( { + expect( insertBlocks( blocks, index, 'testclientid' ) ).toEqual( { type: 'INSERT_BLOCKS', blocks, index, - rootUID: 'test_uid', + rootClientId: 'testclientid', time: expect.any( Number ), } ); } ); @@ -270,11 +270,11 @@ describe( 'actions', () => { describe( 'mergeBlocks', () => { it( 'should return MERGE_BLOCKS action', () => { - const blockAUid = 'blockA'; - const blockBUid = 'blockB'; - expect( mergeBlocks( blockAUid, blockBUid ) ).toEqual( { + const firstBlockClientId = 'blockA'; + const secondBlockClientId = 'blockB'; + expect( mergeBlocks( firstBlockClientId, secondBlockClientId ) ).toEqual( { type: 'MERGE_BLOCKS', - blocks: [ blockAUid, blockBUid ], + blocks: [ firstBlockClientId, secondBlockClientId ], } ); } ); } ); @@ -297,10 +297,10 @@ describe( 'actions', () => { describe( 'removeBlocks', () => { it( 'should return REMOVE_BLOCKS action', () => { - const uids = [ 'uid' ]; - expect( removeBlocks( uids ) ).toEqual( { + const clientIds = [ 'clientId' ]; + expect( removeBlocks( clientIds ) ).toEqual( { type: 'REMOVE_BLOCKS', - uids, + clientIds, selectPrevious: true, } ); } ); @@ -308,18 +308,18 @@ describe( 'actions', () => { describe( 'removeBlock', () => { it( 'should return REMOVE_BLOCKS action', () => { - const uid = 'my-uid'; - expect( removeBlock( uid ) ).toEqual( { + const clientId = 'myclientid'; + expect( removeBlock( clientId ) ).toEqual( { type: 'REMOVE_BLOCKS', - uids: [ - uid, + clientIds: [ + clientId, ], selectPrevious: true, } ); - expect( removeBlock( uid, false ) ).toEqual( { + expect( removeBlock( clientId, false ) ).toEqual( { type: 'REMOVE_BLOCKS', - uids: [ - uid, + clientIds: [ + clientId, ], selectPrevious: false, } ); @@ -328,10 +328,10 @@ describe( 'actions', () => { describe( 'toggleBlockMode', () => { it( 'should return TOGGLE_BLOCK_MODE action', () => { - const uid = 'my-uid'; - expect( toggleBlockMode( uid ) ).toEqual( { + const clientId = 'myclientid'; + expect( toggleBlockMode( clientId ) ).toEqual( { type: 'TOGGLE_BLOCK_MODE', - uid, + clientId, } ); } ); } ); @@ -495,20 +495,20 @@ describe( 'actions', () => { describe( 'convertBlockToStatic', () => { it( 'should return the CONVERT_BLOCK_TO_STATIC action', () => { - const uid = '358b59ee-bab3-4d6f-8445-e8c6971a5605'; - expect( convertBlockToStatic( uid ) ).toEqual( { + const clientId = '358b59ee-bab3-4d6f-8445-e8c6971a5605'; + expect( convertBlockToStatic( clientId ) ).toEqual( { type: 'CONVERT_BLOCK_TO_STATIC', - uid, + clientId, } ); } ); } ); describe( 'convertBlockToShared', () => { it( 'should return the CONVERT_BLOCK_TO_SHARED action', () => { - const uid = '358b59ee-bab3-4d6f-8445-e8c6971a5605'; - expect( convertBlockToShared( uid ) ).toEqual( { + const clientId = '358b59ee-bab3-4d6f-8445-e8c6971a5605'; + expect( convertBlockToShared( clientId ) ).toEqual( { type: 'CONVERT_BLOCK_TO_SHARED', - uid, + clientId, } ); } ); } ); @@ -540,7 +540,7 @@ describe( 'actions', () => { it( 'should return the UPDATE_BLOCK_LIST_SETTINGS with undefined settings', () => { expect( updateBlockListSettings( 'chicken' ) ).toEqual( { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: 'chicken', + clientId: 'chicken', settings: undefined, } ); } ); @@ -548,7 +548,7 @@ describe( 'actions', () => { it( 'should return the UPDATE_BLOCK_LIST_SETTINGS action with the passed settings', () => { expect( updateBlockListSettings( 'chicken', { chicken: 'ribs' } ) ).toEqual( { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: 'chicken', + clientId: 'chicken', settings: { chicken: 'ribs' }, } ); } ); diff --git a/editor/store/test/effects.js b/editor/store/test/effects.js index 03ab0c5abb75e..1161cd1a98f6b 100644 --- a/editor/store/test/effects.js +++ b/editor/store/test/effects.js @@ -49,17 +49,17 @@ describe( 'effects', () => { const store = { getState: () => {} }; beforeAll( () => { - selectors.getProvisionalBlockUID = jest.spyOn( selectors, 'getProvisionalBlockUID' ); + selectors.getProvisionalBlockClientId = jest.spyOn( selectors, 'getProvisionalBlockClientId' ); selectors.isBlockSelected = jest.spyOn( selectors, 'isBlockSelected' ); } ); beforeEach( () => { - selectors.getProvisionalBlockUID.mockReset(); + selectors.getProvisionalBlockClientId.mockReset(); selectors.isBlockSelected.mockReset(); } ); afterAll( () => { - selectors.getProvisionalBlockUID.mockRestore(); + selectors.getProvisionalBlockClientId.mockRestore(); selectors.isBlockSelected.mockRestore(); } ); @@ -70,16 +70,16 @@ describe( 'effects', () => { } ); it( 'should return nothing if there is a provisional block and it is selected', () => { - selectors.getProvisionalBlockUID.mockReturnValue( 'chicken' ); - selectors.isBlockSelected.mockImplementation( ( state, uid ) => uid === 'chicken' ); + selectors.getProvisionalBlockClientId.mockReturnValue( 'chicken' ); + selectors.isBlockSelected.mockImplementation( ( state, clientId ) => clientId === 'chicken' ); const action = removeProvisionalBlock( {}, store ); expect( action ).toBeUndefined(); } ); it( 'should return remove action for provisional block', () => { - selectors.getProvisionalBlockUID.mockReturnValue( 'chicken' ); - selectors.isBlockSelected.mockImplementation( ( state, uid ) => uid === 'ribs' ); + selectors.getProvisionalBlockClientId.mockReturnValue( 'chicken' ); + selectors.isBlockSelected.mockImplementation( ( state, clientId ) => clientId === 'ribs' ); const action = removeProvisionalBlock( {}, store ); expect( action ).toEqual( removeBlock( 'chicken', false ) ); @@ -100,20 +100,20 @@ describe( 'effects', () => { it( 'should only focus the blockA if the blockA has no merge function', () => { registerBlockType( 'core/test-block', defaultBlockSettings ); const blockA = { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', }; const blockB = { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', }; - selectors.getBlock = ( state, uid ) => { - return blockA.uid === uid ? blockA : blockB; + selectors.getBlock = ( state, clientId ) => { + return blockA.clientId === clientId ? blockA : blockB; }; const dispatch = jest.fn(); const getState = () => ( {} ); - handler( mergeBlocks( blockA.uid, blockB.uid ), { dispatch, getState } ); + handler( mergeBlocks( blockA.clientId, blockB.clientId ), { dispatch, getState } ); expect( dispatch ).toHaveBeenCalledTimes( 1 ); expect( dispatch ).toHaveBeenCalledWith( selectBlock( 'chicken' ) ); @@ -131,27 +131,27 @@ describe( 'effects', () => { title: 'test block', } ); const blockA = { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: { content: 'ribs' }, }; - selectors.getBlock = ( state, uid ) => { - return blockA.uid === uid ? blockA : blockB; + selectors.getBlock = ( state, clientId ) => { + return blockA.clientId === clientId ? blockA : blockB; }; const dispatch = jest.fn(); const getState = () => ( {} ); - handler( mergeBlocks( blockA.uid, blockB.uid ), { dispatch, getState } ); + handler( mergeBlocks( blockA.clientId, blockB.clientId ), { dispatch, getState } ); expect( dispatch ).toHaveBeenCalledTimes( 2 ); expect( dispatch ).toHaveBeenCalledWith( selectBlock( 'chicken', -1 ) ); expect( dispatch ).toHaveBeenCalledWith( { ...replaceBlocks( [ 'chicken', 'ribs' ], [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ), @@ -172,21 +172,21 @@ describe( 'effects', () => { } ); registerBlockType( 'core/test-block-2', defaultBlockSettings ); const blockA = { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block2', attributes: { content: 'ribs' }, }; - selectors.getBlock = ( state, uid ) => { - return blockA.uid === uid ? blockA : blockB; + selectors.getBlock = ( state, clientId ) => { + return blockA.clientId === clientId ? blockA : blockB; }; const dispatch = jest.fn(); const getState = () => ( {} ); - handler( mergeBlocks( blockA.uid, blockB.uid ), { dispatch, getState } ); + handler( mergeBlocks( blockA.clientId, blockB.clientId ), { dispatch, getState } ); expect( dispatch ).not.toHaveBeenCalled(); } ); @@ -229,27 +229,27 @@ describe( 'effects', () => { title: 'test block 2', } ); const blockA = { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'chicken' }, }; const blockB = { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block-2', attributes: { content2: 'ribs' }, }; - selectors.getBlock = ( state, uid ) => { - return blockA.uid === uid ? blockA : blockB; + selectors.getBlock = ( state, clientId ) => { + return blockA.clientId === clientId ? blockA : blockB; }; const dispatch = jest.fn(); const getState = () => ( {} ); - handler( mergeBlocks( blockA.uid, blockB.uid ), { dispatch, getState } ); + handler( mergeBlocks( blockA.clientId, blockB.clientId ), { dispatch, getState } ); expect( dispatch ).toHaveBeenCalledTimes( 2 ); // expect( dispatch ).toHaveBeenCalledWith( focusBlock( 'chicken', { offset: -1 } ) ); expect( dispatch ).toHaveBeenCalledWith( { ...replaceBlocks( [ 'chicken', 'ribs' ], [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'chicken ribs' }, } ] ), @@ -701,12 +701,12 @@ describe( 'effects', () => { it( 'should receive parsed blocks', () => { const action = receiveSharedBlocks( [ { - parsedBlock: { uid: 'broccoli' }, + parsedBlock: { clientId: 'broccoli' }, }, ] ); expect( handler( action ) ).toEqual( receiveBlocks( [ - { uid: 'broccoli' }, + { clientId: 'broccoli' }, ] ) ); } ); } ); @@ -802,7 +802,7 @@ describe( 'effects', () => { } ); expect( dispatch ).toHaveBeenCalledWith( - removeBlocks( [ associatedBlock.uid, parsedBlock.uid ] ) + removeBlocks( [ associatedBlock.clientId, parsedBlock.clientId ] ) ); return promise.then( () => { @@ -880,11 +880,11 @@ describe( 'effects', () => { const dispatch = jest.fn(); const store = { getState: () => state, dispatch }; - handler( convertBlockToStatic( associatedBlock.uid ), store ); + handler( convertBlockToStatic( associatedBlock.clientId ), store ); expect( dispatch ).toHaveBeenCalledWith( { type: 'REPLACE_BLOCKS', - uids: [ associatedBlock.uid ], + clientIds: [ associatedBlock.clientId ], blocks: [ expect.objectContaining( { name: 'core/test-block', @@ -906,13 +906,13 @@ describe( 'effects', () => { const dispatch = jest.fn(); const store = { getState: () => state, dispatch }; - handler( convertBlockToShared( staticBlock.uid ), store ); + handler( convertBlockToShared( staticBlock.clientId ), store ); expect( dispatch ).toHaveBeenCalledWith( receiveSharedBlocks( [ { sharedBlock: { id: expect.stringMatching( /^shared/ ), - uid: staticBlock.uid, + clientId: staticBlock.clientId, title: 'Untitled shared block', }, parsedBlock: staticBlock, @@ -925,7 +925,7 @@ describe( 'effects', () => { expect( dispatch ).toHaveBeenCalledWith( { type: 'REPLACE_BLOCKS', - uids: [ staticBlock.uid ], + clientIds: [ staticBlock.clientId ], blocks: [ expect.objectContaining( { name: 'core/block', diff --git a/editor/store/test/reducer.js b/editor/store/test/reducer.js index c38da398742ec..bb2c7234ed2c6 100644 --- a/editor/store/test/reducer.js +++ b/editor/store/test/reducer.js @@ -30,7 +30,7 @@ import { preferences, saving, notices, - provisionalBlockUID, + provisionalBlockClientId, blocksMode, isInsertionPointVisible, sharedBlocks, @@ -73,14 +73,14 @@ describe( 'state', () => { it( 'should return false if not updating the same block', () => { const action = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 10, }, }; const previousAction = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', + clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', attributes: { foo: 20, }, @@ -92,14 +92,14 @@ describe( 'state', () => { it( 'should return false if not updating the same block attributes', () => { const action = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 10, }, }; const previousAction = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { bar: 20, }, @@ -111,14 +111,14 @@ describe( 'state', () => { it( 'should return true if updating the same block attributes', () => { const action = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 10, }, }; const previousAction = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 20, }, @@ -132,14 +132,14 @@ describe( 'state', () => { it( 'should return false if not editing post', () => { const action = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', + clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', attributes: { foo: 10, }, }; const previousAction = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', + clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', attributes: { foo: 10, }, @@ -216,14 +216,14 @@ describe( 'state', () => { it( 'should return true if updating same block attribute', () => { const action = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 10, }, }; const previousAction = { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', attributes: { foo: 20, }, @@ -278,43 +278,43 @@ describe( 'state', () => { unregisterBlockType( 'core/test-block' ); } ); - it( 'should return history (empty edits, blocksByUID, blockOrder), dirty flag by default', () => { + it( 'should return history (empty edits, blocksByClientId, blockOrder), dirty flag by default', () => { const state = editor( undefined, {} ); expect( state.past ).toEqual( [] ); expect( state.future ).toEqual( [] ); expect( state.present.edits ).toEqual( {} ); - expect( state.present.blocksByUID ).toEqual( {} ); + expect( state.present.blocksByClientId ).toEqual( {} ); expect( state.present.blockOrder ).toEqual( {} ); expect( state.isDirty ).toBe( false ); } ); - it( 'should key by reset blocks uid', () => { + it( 'should key by reset blocks clientId', () => { const original = editor( undefined, {} ); const state = editor( original, { type: 'RESET_BLOCKS', - blocks: [ { uid: 'bananas', innerBlocks: [] } ], + blocks: [ { clientId: 'bananas', innerBlocks: [] } ], } ); - expect( Object.keys( state.present.blocksByUID ) ).toHaveLength( 1 ); - expect( values( state.present.blocksByUID )[ 0 ].uid ).toBe( 'bananas' ); + expect( Object.keys( state.present.blocksByClientId ) ).toHaveLength( 1 ); + expect( values( state.present.blocksByClientId )[ 0 ].clientId ).toBe( 'bananas' ); expect( state.present.blockOrder ).toEqual( { '': [ 'bananas' ], bananas: [], } ); } ); - it( 'should key by reset blocks uid, including inner blocks', () => { + it( 'should key by reset blocks clientId, including inner blocks', () => { const original = editor( undefined, {} ); const state = editor( original, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'bananas', - innerBlocks: [ { uid: 'apples', innerBlocks: [] } ], + clientId: 'bananas', + innerBlocks: [ { clientId: 'apples', innerBlocks: [] } ], } ], } ); - expect( Object.keys( state.present.blocksByUID ) ).toHaveLength( 2 ); + expect( Object.keys( state.present.blocksByClientId ) ).toHaveLength( 2 ); expect( state.present.blockOrder ).toEqual( { '': [ 'bananas' ], apples: [], @@ -326,7 +326,7 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -335,14 +335,14 @@ describe( 'state', () => { const state = editor( original, { type: 'INSERT_BLOCKS', blocks: [ { - uid: 'ribs', + clientId: 'ribs', name: 'core/freeform', innerBlocks: [], } ], } ); - expect( Object.keys( state.present.blocksByUID ) ).toHaveLength( 2 ); - expect( values( state.present.blocksByUID )[ 1 ].uid ).toBe( 'ribs' ); + expect( Object.keys( state.present.blocksByClientId ) ).toHaveLength( 2 ); + expect( values( state.present.blocksByClientId )[ 1 ].clientId ).toBe( 'ribs' ); expect( state.present.blockOrder ).toEqual( { '': [ 'chicken', 'ribs' ], chicken: [], @@ -354,7 +354,7 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -362,17 +362,17 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks: [ { - uid: 'wings', + clientId: 'wings', name: 'core/freeform', innerBlocks: [], } ], } ); - expect( Object.keys( state.present.blocksByUID ) ).toHaveLength( 1 ); - expect( values( state.present.blocksByUID )[ 0 ].name ).toBe( 'core/freeform' ); - expect( values( state.present.blocksByUID )[ 0 ].uid ).toBe( 'wings' ); + expect( Object.keys( state.present.blocksByClientId ) ).toHaveLength( 1 ); + expect( values( state.present.blocksByClientId )[ 0 ].name ).toBe( 'core/freeform' ); + expect( values( state.present.blocksByClientId )[ 0 ].clientId ).toBe( 'wings' ); expect( state.present.blockOrder ).toEqual( { '': [ 'wings' ], wings: [], @@ -390,22 +390,22 @@ describe( 'state', () => { const state = editor( original, { type: 'REPLACE_BLOCKS', - uids: [ nestedBlock.uid ], + clientIds: [ nestedBlock.clientId ], blocks: [ replacementBlock ], } ); expect( state.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ replacementBlock.uid ], - [ replacementBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ replacementBlock.clientId ], + [ replacementBlock.clientId ]: [], } ); } ); - it( 'should replace the block even if the new block uid is the same', () => { + it( 'should replace the block even if the new block clientId is the same', () => { const originalState = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -413,32 +413,32 @@ describe( 'state', () => { } ); const replacedState = editor( originalState, { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/freeform', innerBlocks: [], } ], } ); - expect( Object.keys( replacedState.present.blocksByUID ) ).toHaveLength( 1 ); - expect( values( originalState.present.blocksByUID )[ 0 ].name ).toBe( 'core/test-block' ); - expect( values( replacedState.present.blocksByUID )[ 0 ].name ).toBe( 'core/freeform' ); - expect( values( replacedState.present.blocksByUID )[ 0 ].uid ).toBe( 'chicken' ); + expect( Object.keys( replacedState.present.blocksByClientId ) ).toHaveLength( 1 ); + expect( values( originalState.present.blocksByClientId )[ 0 ].name ).toBe( 'core/test-block' ); + expect( values( replacedState.present.blocksByClientId )[ 0 ].name ).toBe( 'core/freeform' ); + expect( values( replacedState.present.blocksByClientId )[ 0 ].clientId ).toBe( 'chicken' ); expect( replacedState.present.blockOrder ).toEqual( { '': [ 'chicken' ], chicken: [], } ); const nestedBlock = { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }; const wrapperBlock = createBlock( 'core/test-block', {}, [ nestedBlock ] ); const replacementNestedBlock = { - uid: 'chicken', + clientId: 'chicken', name: 'core/freeform', attributes: {}, innerBlocks: [], @@ -451,25 +451,25 @@ describe( 'state', () => { const replacedNestedState = editor( originalNestedState, { type: 'REPLACE_BLOCKS', - uids: [ nestedBlock.uid ], + clientIds: [ nestedBlock.clientId ], blocks: [ replacementNestedBlock ], } ); expect( replacedNestedState.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ replacementNestedBlock.uid ], - [ replacementNestedBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ replacementNestedBlock.clientId ], + [ replacementNestedBlock.clientId ]: [], } ); - expect( originalNestedState.present.blocksByUID.chicken.name ).toBe( 'core/test-block' ); - expect( replacedNestedState.present.blocksByUID.chicken.name ).toBe( 'core/freeform' ); + expect( originalNestedState.present.blocksByClientId.chicken.name ).toBe( 'core/test-block' ); + expect( replacedNestedState.present.blocksByClientId.chicken.name ).toBe( 'core/freeform' ); } ); it( 'should update the block', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, isValid: false, @@ -478,15 +478,15 @@ describe( 'state', () => { } ); const state = editor( deepFreeze( original ), { type: 'UPDATE_BLOCK', - uid: 'chicken', + clientId: 'chicken', updates: { attributes: { content: 'ribs' }, isValid: true, }, } ); - expect( state.present.blocksByUID.chicken ).toEqual( { - uid: 'chicken', + expect( state.present.blocksByClientId.chicken ).toEqual( { + clientId: 'chicken', name: 'core/test-block', attributes: { content: 'ribs' }, isValid: true, @@ -497,10 +497,10 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/block', attributes: { - ref: 'random-uid', + ref: 'random-clientId', }, isValid: false, innerBlocks: [], @@ -509,12 +509,12 @@ describe( 'state', () => { const state = editor( deepFreeze( original ), { type: 'SAVE_SHARED_BLOCK_SUCCESS', - id: 'random-uid', + id: 'random-clientId', updatedId: 3, } ); - expect( state.present.blocksByUID.chicken ).toEqual( { - uid: 'chicken', + expect( state.present.blocksByClientId.chicken ).toEqual( { + clientId: 'chicken', name: 'core/block', attributes: { ref: 3, @@ -527,12 +527,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -540,7 +540,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_UP', - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); @@ -556,15 +556,15 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_UP', - uids: [ movedBlock.uid ], - rootUID: wrapperBlock.uid, + clientIds: [ movedBlock.clientId ], + rootClientId: wrapperBlock.clientId, } ); expect( state.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ movedBlock.uid, siblingBlock.uid ], - [ movedBlock.uid ]: [], - [ siblingBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ movedBlock.clientId, siblingBlock.clientId ], + [ movedBlock.clientId ]: [], + [ siblingBlock.clientId ]: [], } ); } ); @@ -572,17 +572,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -590,7 +590,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_UP', - uids: [ 'ribs', 'veggies' ], + clientIds: [ 'ribs', 'veggies' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'ribs', 'veggies', 'chicken' ] ); @@ -607,16 +607,16 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_UP', - uids: [ movedBlockA.uid, movedBlockB.uid ], - rootUID: wrapperBlock.uid, + clientIds: [ movedBlockA.clientId, movedBlockB.clientId ], + rootClientId: wrapperBlock.clientId, } ); expect( state.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ movedBlockA.uid, movedBlockB.uid, siblingBlock.uid ], - [ movedBlockA.uid ]: [], - [ movedBlockB.uid ]: [], - [ siblingBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ movedBlockA.clientId, movedBlockB.clientId, siblingBlock.clientId ], + [ movedBlockA.clientId ]: [], + [ movedBlockB.clientId ]: [], + [ siblingBlock.clientId ]: [], } ); } ); @@ -624,12 +624,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -637,7 +637,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_UP', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], } ); expect( state.present.blockOrder ).toBe( original.present.blockOrder ); @@ -647,12 +647,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -660,7 +660,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_DOWN', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); @@ -676,15 +676,15 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_DOWN', - uids: [ movedBlock.uid ], - rootUID: wrapperBlock.uid, + clientIds: [ movedBlock.clientId ], + rootClientId: wrapperBlock.clientId, } ); expect( state.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ siblingBlock.uid, movedBlock.uid ], - [ movedBlock.uid ]: [], - [ siblingBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ siblingBlock.clientId, movedBlock.clientId ], + [ movedBlock.clientId ]: [], + [ siblingBlock.clientId ]: [], } ); } ); @@ -692,17 +692,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -710,7 +710,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_DOWN', - uids: [ 'chicken', 'ribs' ], + clientIds: [ 'chicken', 'ribs' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'veggies', 'chicken', 'ribs' ] ); @@ -727,16 +727,16 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_DOWN', - uids: [ movedBlockA.uid, movedBlockB.uid ], - rootUID: wrapperBlock.uid, + clientIds: [ movedBlockA.clientId, movedBlockB.clientId ], + rootClientId: wrapperBlock.clientId, } ); expect( state.present.blockOrder ).toEqual( { - '': [ wrapperBlock.uid ], - [ wrapperBlock.uid ]: [ siblingBlock.uid, movedBlockA.uid, movedBlockB.uid ], - [ movedBlockA.uid ]: [], - [ movedBlockB.uid ]: [], - [ siblingBlock.uid ]: [], + '': [ wrapperBlock.clientId ], + [ wrapperBlock.clientId ]: [ siblingBlock.clientId, movedBlockA.clientId, movedBlockB.clientId ], + [ movedBlockA.clientId ]: [], + [ movedBlockB.clientId ]: [], + [ siblingBlock.clientId ]: [], } ); } ); @@ -744,12 +744,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -757,7 +757,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCKS_DOWN', - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], } ); expect( state.present.blockOrder ).toBe( original.present.blockOrder ); @@ -767,12 +767,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -780,14 +780,14 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'REMOVE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'ribs' ] ); expect( state.present.blockOrder ).not.toHaveProperty( 'chicken' ); - expect( state.present.blocksByUID ).toEqual( { + expect( state.present.blocksByClientId ).toEqual( { ribs: { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, }, @@ -798,17 +798,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -816,15 +816,15 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'REMOVE_BLOCKS', - uids: [ 'chicken', 'veggies' ], + clientIds: [ 'chicken', 'veggies' ], } ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'ribs' ] ); expect( state.present.blockOrder ).not.toHaveProperty( 'chicken' ); expect( state.present.blockOrder ).not.toHaveProperty( 'veggies' ); - expect( state.present.blocksByUID ).toEqual( { + expect( state.present.blocksByClientId ).toEqual( { ribs: { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, }, @@ -845,10 +845,10 @@ describe( 'state', () => { const state = editor( original, { type: 'REMOVE_BLOCKS', - uids: [ block.uid ], + clientIds: [ block.clientId ], } ); - expect( state.present.blocksByUID ).toEqual( {} ); + expect( state.present.blocksByClientId ).toEqual( {} ); expect( state.present.blockOrder ).toEqual( { '': [], } ); @@ -858,12 +858,12 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'loquat', + clientId: 'loquat', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -874,13 +874,13 @@ describe( 'state', () => { type: 'INSERT_BLOCKS', index: 1, blocks: [ { - uid: 'persimmon', + clientId: 'persimmon', name: 'core/freeform', innerBlocks: [], } ], } ); - expect( Object.keys( state.present.blocksByUID ) ).toHaveLength( 3 ); + expect( Object.keys( state.present.blocksByClientId ) ).toHaveLength( 3 ); expect( state.present.blockOrder[ '' ] ).toEqual( [ 'kumquat', 'persimmon', 'loquat' ] ); } ); @@ -888,17 +888,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -906,7 +906,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCK_TO_POSITION', - uid: 'ribs', + clientId: 'ribs', index: 0, } ); @@ -917,17 +917,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -935,7 +935,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCK_TO_POSITION', - uid: 'ribs', + clientId: 'ribs', index: 2, } ); @@ -946,17 +946,17 @@ describe( 'state', () => { const original = editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'chicken', + clientId: 'chicken', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'ribs', + clientId: 'ribs', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'veggies', + clientId: 'veggies', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -964,7 +964,7 @@ describe( 'state', () => { } ); const state = editor( original, { type: 'MOVE_BLOCK_TO_POSITION', - uid: 'ribs', + clientId: 'ribs', index: 1, } ); @@ -1072,12 +1072,12 @@ describe( 'state', () => { state = editor( original, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', name: 'core/test-block', attributes: {}, innerBlocks: [], }, { - uid: 'loquat', + clientId: 'loquat', name: 'core/test-block', attributes: {}, innerBlocks: [], @@ -1088,32 +1088,32 @@ describe( 'state', () => { } ); } ); - describe( 'blocksByUID', () => { + describe( 'blocksByClientId', () => { it( 'should return with attribute block updates', () => { const original = deepFreeze( editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', attributes: {}, innerBlocks: [], } ], } ) ); const state = editor( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { updated: true, }, } ); - expect( state.present.blocksByUID.kumquat.attributes.updated ).toBe( true ); + expect( state.present.blocksByClientId.kumquat.attributes.updated ).toBe( true ); } ); it( 'should accumulate attribute block updates', () => { const original = deepFreeze( editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', attributes: { updated: true, }, @@ -1122,13 +1122,13 @@ describe( 'state', () => { } ) ); const state = editor( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { moreUpdated: true, }, } ); - expect( state.present.blocksByUID.kumquat.attributes ).toEqual( { + expect( state.present.blocksByClientId.kumquat.attributes ).toEqual( { updated: true, moreUpdated: true, } ); @@ -1141,20 +1141,20 @@ describe( 'state', () => { } ) ); const state = editor( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { updated: true, }, } ); - expect( state.present.blocksByUID ).toBe( original.present.blocksByUID ); + expect( state.present.blocksByClientId ).toBe( original.present.blocksByClientId ); } ); it( 'should return with same reference if no changes in updates', () => { const original = deepFreeze( editor( undefined, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', attributes: { updated: true, }, @@ -1163,13 +1163,13 @@ describe( 'state', () => { } ) ); const state = editor( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { updated: true, }, } ); - expect( state.present.blocksByUID ).toBe( state.present.blocksByUID ); + expect( state.present.blocksByClientId ).toBe( state.present.blocksByClientId ); } ); } ); @@ -1180,7 +1180,7 @@ describe( 'state', () => { state = editor( state, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', attributes: {}, innerBlocks: [], } ], @@ -1190,7 +1190,7 @@ describe( 'state', () => { state = editor( state, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { test: 1, }, @@ -1198,7 +1198,7 @@ describe( 'state', () => { state = editor( state, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { test: 2, }, @@ -1213,7 +1213,7 @@ describe( 'state', () => { state = editor( state, { type: 'RESET_BLOCKS', blocks: [ { - uid: 'kumquat', + clientId: 'kumquat', attributes: {}, innerBlocks: [], } ], @@ -1223,7 +1223,7 @@ describe( 'state', () => { state = editor( state, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { test: 1, }, @@ -1231,7 +1231,7 @@ describe( 'state', () => { state = editor( state, { type: 'UPDATE_BLOCK_ATTRIBUTES', - uid: 'kumquat', + clientId: 'kumquat', attributes: { other: 1, }, @@ -1318,10 +1318,10 @@ describe( 'state', () => { } ); describe( 'blockSelection()', () => { - it( 'should return with block uid as selected', () => { + it( 'should return with block clientId as selected', () => { const state = blockSelection( undefined, { type: 'SELECT_BLOCK', - uid: 'kumquat', + clientId: 'kumquat', initialPosition: -1, } ); @@ -1431,7 +1431,7 @@ describe( 'state', () => { const state1 = blockSelection( original, { type: 'SELECT_BLOCK', - uid: 'ribs', + clientId: 'ribs', } ); expect( state1 ).toBe( original ); @@ -1468,7 +1468,7 @@ describe( 'state', () => { const state3 = blockSelection( original, { type: 'INSERT_BLOCKS', blocks: [ { - uid: 'ribs', + clientId: 'ribs', name: 'core/freeform', } ], } ); @@ -1485,7 +1485,7 @@ describe( 'state', () => { const original = deepFreeze( { start: 'ribs', end: 'ribs' } ); const state = blockSelection( original, { type: 'MOVE_BLOCKS_UP', - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], } ); expect( state ).toBe( original ); @@ -1495,9 +1495,9 @@ describe( 'state', () => { const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); const state = blockSelection( original, { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks: [ { - uid: 'wings', + clientId: 'wings', name: 'core/freeform', } ], } ); @@ -1514,7 +1514,7 @@ describe( 'state', () => { const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); const state = blockSelection( original, { type: 'REPLACE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], blocks: [], } ); @@ -1530,9 +1530,9 @@ describe( 'state', () => { const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); const state = blockSelection( original, { type: 'REPLACE_BLOCKS', - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], blocks: [ { - uid: 'wings', + clientId: 'wings', name: 'core/freeform', } ], } ); @@ -1549,7 +1549,7 @@ describe( 'state', () => { } ); const state = blockSelection( original, { type: 'REMOVE_BLOCKS', - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], } ); expect( state ).toEqual( { @@ -1569,7 +1569,7 @@ describe( 'state', () => { } ); const state = blockSelection( original, { type: 'REMOVE_BLOCKS', - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], } ); expect( state ).toBe( original ); @@ -1593,7 +1593,7 @@ describe( 'state', () => { const state = preferences( deepFreeze( { insertUsage: {} } ), { type: 'INSERT_BLOCKS', blocks: [ { - uid: 'bacon', + clientId: 'bacon', name: 'core-embed/twitter', } ], time: 123456, @@ -1620,10 +1620,10 @@ describe( 'state', () => { } ), { type: 'INSERT_BLOCKS', blocks: [ { - uid: 'eggs', + clientId: 'eggs', name: 'core-embed/twitter', }, { - uid: 'bacon', + clientId: 'bacon', name: 'core/block', attributes: { ref: 123 }, } ], @@ -1795,7 +1795,7 @@ describe( 'state', () => { } ); } ); - describe( 'provisionalBlockUID()', () => { + describe( 'provisionalBlockClientId()', () => { const PROVISIONAL_UPDATE_ACTION_TYPES = [ 'UPDATE_BLOCK_ATTRIBUTES', 'UPDATE_BLOCK', @@ -1808,28 +1808,28 @@ describe( 'state', () => { ]; it( 'returns null by default', () => { - const state = provisionalBlockUID( undefined, {} ); + const state = provisionalBlockClientId( undefined, {} ); expect( state ).toBe( null ); } ); - it( 'returns the uid of the first inserted provisional block', () => { - const state = provisionalBlockUID( null, { + it( 'returns the clientId of the first inserted provisional block', () => { + const state = provisionalBlockClientId( null, { type: 'INSERT_BLOCKS', isProvisional: true, blocks: [ - { uid: 'chicken' }, + { clientId: 'chicken' }, ], } ); expect( state ).toBe( 'chicken' ); } ); - it( 'does not return uid of block if not provisional', () => { - const state = provisionalBlockUID( null, { + it( 'does not return clientId of block if not provisional', () => { + const state = provisionalBlockClientId( null, { type: 'INSERT_BLOCKS', blocks: [ - { uid: 'chicken' }, + { clientId: 'chicken' }, ], } ); @@ -1837,7 +1837,7 @@ describe( 'state', () => { } ); it( 'returns null on block reset', () => { - const state = provisionalBlockUID( 'chicken', { + const state = provisionalBlockClientId( 'chicken', { type: 'RESET_BLOCKS', } ); @@ -1846,9 +1846,9 @@ describe( 'state', () => { it( 'returns null on block update', () => { PROVISIONAL_UPDATE_ACTION_TYPES.forEach( ( type ) => { - const state = provisionalBlockUID( 'chicken', { + const state = provisionalBlockClientId( 'chicken', { type, - uid: 'chicken', + clientId: 'chicken', } ); expect( state ).toBe( null ); @@ -1857,9 +1857,9 @@ describe( 'state', () => { it( 'does not return null if update occurs to non-provisional block', () => { PROVISIONAL_UPDATE_ACTION_TYPES.forEach( ( type ) => { - const state = provisionalBlockUID( 'chicken', { + const state = provisionalBlockClientId( 'chicken', { type, - uid: 'ribs', + clientId: 'ribs', } ); expect( state ).toBe( 'chicken' ); @@ -1868,9 +1868,9 @@ describe( 'state', () => { it( 'returns null if replacement of provisional block', () => { PROVISIONAL_REPLACE_ACTION_TYPES.forEach( ( type ) => { - const state = provisionalBlockUID( 'chicken', { + const state = provisionalBlockClientId( 'chicken', { type, - uids: [ 'chicken' ], + clientIds: [ 'chicken' ], } ); expect( state ).toBe( null ); @@ -1879,9 +1879,9 @@ describe( 'state', () => { it( 'does not return null if replacement of non-provisional block', () => { PROVISIONAL_REPLACE_ACTION_TYPES.forEach( ( type ) => { - const state = provisionalBlockUID( 'chicken', { + const state = provisionalBlockClientId( 'chicken', { type, - uids: [ 'ribs' ], + clientIds: [ 'ribs' ], } ); expect( state ).toBe( 'chicken' ); @@ -1893,7 +1893,7 @@ describe( 'state', () => { it( 'should set mode to html if not set', () => { const action = { type: 'TOGGLE_BLOCK_MODE', - uid: 'chicken', + clientId: 'chicken', }; const value = blocksMode( deepFreeze( {} ), action ); @@ -1903,7 +1903,7 @@ describe( 'state', () => { it( 'should toggle mode to visual if set as html', () => { const action = { type: 'TOGGLE_BLOCK_MODE', - uid: 'chicken', + clientId: 'chicken', }; const value = blocksMode( deepFreeze( { chicken: 'html' } ), action ); @@ -1930,14 +1930,14 @@ describe( 'state', () => { title: 'My cool block', }, parsedBlock: { - uid: 'foo', + clientId: 'foo', }, } ], } ); expect( state ).toEqual( { data: { - 123: { uid: 'foo', title: 'My cool block' }, + 123: { clientId: 'foo', title: 'My cool block' }, }, isFetching: {}, isSaving: {}, @@ -1947,7 +1947,7 @@ describe( 'state', () => { it( 'should update a shared block', () => { const initialState = { data: { - 123: { uid: '', title: '' }, + 123: { clientId: '', title: '' }, }, isFetching: {}, isSaving: {}, @@ -1961,7 +1961,7 @@ describe( 'state', () => { expect( state ).toEqual( { data: { - 123: { uid: '', title: 'My block' }, + 123: { clientId: '', title: 'My block' }, }, isFetching: {}, isSaving: {}, @@ -1971,7 +1971,7 @@ describe( 'state', () => { it( 'should update the shared block\'s id if it was temporary', () => { const initialState = { data: { - shared1: { uid: '', title: '' }, + shared1: { clientId: '', title: '' }, }, isSaving: {}, }; @@ -1984,7 +1984,7 @@ describe( 'state', () => { expect( state ).toEqual( { data: { - 123: { uid: '', title: '' }, + 123: { clientId: '', title: '' }, }, isFetching: {}, isSaving: {}, @@ -2188,7 +2188,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', settings: { allowedBlocks: [ 'core/paragraph' ], }, @@ -2210,7 +2210,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', settings: { allowedBlocks: [ 'core/paragraph' ], }, @@ -2224,7 +2224,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', } ); expect( state ).toBe( original ); @@ -2242,7 +2242,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', settings: { allowedBlocks: [ 'core/list' ], }, @@ -2267,7 +2267,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'UPDATE_BLOCK_LIST_SETTINGS', - id: '9db792c6-a25a-495d-adbd-97d56a4c4189', + clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', } ); expect( state ).toEqual( {} ); @@ -2285,7 +2285,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'REPLACE_BLOCKS', - uids: [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], + clientIds: [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], } ); expect( state ).toEqual( { @@ -2304,7 +2304,7 @@ describe( 'state', () => { const state = blockListSettings( original, { type: 'REMOVE_BLOCKS', - uids: [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], + clientIds: [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], } ); expect( state ).toEqual( {} ); diff --git a/editor/store/test/selectors.js b/editor/store/test/selectors.js index c1b6ca1ea6d89..fb411be0b04f2 100644 --- a/editor/store/test/selectors.js +++ b/editor/store/test/selectors.js @@ -47,20 +47,20 @@ const { getBlockCount, hasSelectedBlock, getSelectedBlock, - getSelectedBlockUID, - getBlockRootUID, + getSelectedBlockClientId, + getBlockRootClientId, getCurrentPostAttribute, getEditedPostAttribute, getAutosaveAttribute, getGlobalBlockCount, - getMultiSelectedBlockUids, + getMultiSelectedBlockClientIds, getMultiSelectedBlocks, - getMultiSelectedBlocksStartUid, - getMultiSelectedBlocksEndUid, + getMultiSelectedBlocksStartClientId, + getMultiSelectedBlocksEndClientId, getBlockOrder, getBlockIndex, - getPreviousBlockUid, - getNextBlockUid, + getPreviousBlockClientId, + getNextBlockClientId, isBlockSelected, hasSelectedInnerBlock, isBlockWithinSelection, @@ -85,7 +85,7 @@ const { isPublishingPost, canInsertBlockType, getInserterItems, - getProvisionalBlockUID, + getProvisionalBlockClientId, isValidTemplate, getTemplate, getTemplateLock, @@ -591,7 +591,7 @@ describe( 'selectors', () => { editor: { present: { edits: {}, - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, }, isDirty: false, @@ -635,7 +635,7 @@ describe( 'selectors', () => { editor: { present: { edits: {}, - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, }, isDirty: false, @@ -658,7 +658,7 @@ describe( 'selectors', () => { editor: { present: { edits: {}, - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, }, isDirty: true, @@ -973,7 +973,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -989,7 +989,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1009,7 +1009,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1027,7 +1027,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1045,9 +1045,9 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { 123: { - uid: 123, + clientId: 123, name: 'core/test-block', attributes: { text: '', @@ -1073,7 +1073,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1096,7 +1096,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1115,7 +1115,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: { content: 'foo', @@ -1144,7 +1144,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: { content: 'foo', @@ -1217,7 +1217,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1232,9 +1232,9 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { 123: { - uid: 123, + clientId: 123, name: 'core/test-block', attributes: { text: '', @@ -1257,7 +1257,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1274,7 +1274,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: { content: 'sassel', @@ -1315,7 +1315,7 @@ describe( 'selectors', () => { } ); describe( 'getBlockDependantsCacheBust', () => { - const rootBlock = { uid: 123, name: 'core/paragraph', attributes: {} }; + const rootBlock = { clientId: 123, name: 'core/paragraph', attributes: {} }; const rootOrder = [ 123 ]; it( 'returns an unchanging reference', () => { @@ -1325,7 +1325,7 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, }, blockOrder: { @@ -1341,7 +1341,7 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, }, blockOrder: { @@ -1363,7 +1363,7 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, }, blockOrder: { @@ -1379,9 +1379,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, - 456: { uid: 456, name: 'core/paragraph', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': rootOrder, @@ -1400,14 +1400,14 @@ describe( 'selectors', () => { it( 'returns an unchanging reference on unchanging inner block', () => { const rootBlockOrder = [ 456 ]; - const childBlock = { uid: 456, name: 'core/paragraph', attributes: {} }; + const childBlock = { clientId: 456, name: 'core/paragraph', attributes: {} }; const childBlockOrder = []; const state = { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, 456: childBlock, }, @@ -1425,7 +1425,7 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, 456: childBlock, }, @@ -1452,9 +1452,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, - 456: { uid: 456, name: 'core/paragraph', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': rootOrder, @@ -1470,9 +1470,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, - 456: { uid: 456, name: 'core/paragraph', attributes: { content: [ 'foo' ] } }, + 456: { clientId: 456, name: 'core/paragraph', attributes: { content: [ 'foo' ] } }, }, blockOrder: { '': rootOrder, @@ -1491,7 +1491,7 @@ describe( 'selectors', () => { it( 'returns a new reference on updated grandchild inner block', () => { const rootBlockOrder = [ 456 ]; - const childBlock = { uid: 456, name: 'core/paragraph', attributes: {} }; + const childBlock = { clientId: 456, name: 'core/paragraph', attributes: {} }; const childBlockOrder = [ 789 ]; const grandChildBlockOrder = []; @@ -1499,10 +1499,10 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, 456: childBlock, - 789: { uid: 789, name: 'core/paragraph', attributes: {} }, + 789: { clientId: 789, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': rootOrder, @@ -1519,10 +1519,10 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 123: rootBlock, 456: childBlock, - 789: { uid: 789, name: 'core/paragraph', attributes: { content: [ 'foo' ] } }, + 789: { clientId: 789, name: 'core/paragraph', attributes: { content: [ 'foo' ] } }, }, blockOrder: { '': rootOrder, @@ -1542,12 +1542,12 @@ describe( 'selectors', () => { } ); describe( 'getBlockName', () => { - it( 'returns null if no block by uid', () => { + it( 'returns null if no block by clientId', () => { const state = { currentPost: {}, editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1564,9 +1564,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { + blocksByClientId: { 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': { - uid: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', + clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', name: 'core/paragraph', attributes: {}, }, @@ -1592,8 +1592,8 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 123 ], @@ -1605,7 +1605,7 @@ describe( 'selectors', () => { }; expect( getBlock( state, 123 ) ).toEqual( { - uid: 123, + clientId: 123, name: 'core/paragraph', attributes: {}, innerBlocks: [], @@ -1617,7 +1617,7 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -1632,9 +1632,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, - 456: { uid: 456, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 123 ], @@ -1647,11 +1647,11 @@ describe( 'selectors', () => { }; expect( getBlock( state, 123 ) ).toEqual( { - uid: 123, + clientId: 123, name: 'core/paragraph', attributes: {}, innerBlocks: [ { - uid: 456, + clientId: 456, name: 'core/paragraph', attributes: {}, innerBlocks: [], @@ -1681,8 +1681,8 @@ describe( 'selectors', () => { }, editor: { present: { - blocksByUID: { - 123: { uid: 123, name: 'core/meta-block', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/meta-block', attributes: {} }, }, blockOrder: { '': [ 123 ], @@ -1694,7 +1694,7 @@ describe( 'selectors', () => { }; expect( getBlock( state, 123 ) ).toEqual( { - uid: 123, + clientId: 123, name: 'core/meta-block', attributes: { foo: 'bar', @@ -1712,9 +1712,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 123, 23 ], @@ -1725,8 +1725,8 @@ describe( 'selectors', () => { }; expect( getBlocks( state ) ).toEqual( [ - { uid: 123, name: 'core/paragraph', attributes: {}, innerBlocks: [] }, - { uid: 23, name: 'core/heading', attributes: {}, innerBlocks: [] }, + { clientId: 123, name: 'core/paragraph', attributes: {}, innerBlocks: [] }, + { clientId: 23, name: 'core/heading', attributes: {}, innerBlocks: [] }, ] ); } ); } ); @@ -1736,9 +1736,9 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 123, 23 ], @@ -1754,10 +1754,10 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { - 123: { uid: 123, name: 'core/columns', attributes: {} }, - 456: { uid: 456, name: 'core/paragraph', attributes: {} }, - 789: { uid: 789, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/columns', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, + 789: { clientId: 789, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 123 ], @@ -1811,9 +1811,9 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, }, }, @@ -1826,11 +1826,11 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { - 123: { uid: 123, name: 'core/columns', attributes: {} }, - 456: { uid: 456, name: 'core/paragraph', attributes: {} }, - 789: { uid: 789, name: 'core/paragraph', attributes: {} }, - 124: { uid: 123, name: 'core/heading', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/columns', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, + 789: { clientId: 789, name: 'core/paragraph', attributes: {} }, + 124: { clientId: 123, name: 'core/heading', attributes: {} }, }, }, }, @@ -1843,7 +1843,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { }, }, }, @@ -1853,13 +1853,13 @@ describe( 'selectors', () => { } ); } ); - describe( 'getSelectedBlockUID', () => { + describe( 'getSelectedBlockClientId', () => { it( 'should return null if no block is selected', () => { const state = { blockSelection: { start: null, end: null }, }; - expect( getSelectedBlockUID( state ) ).toBe( null ); + expect( getSelectedBlockClientId( state ) ).toBe( null ); } ); it( 'should return null if there is multi selection', () => { @@ -1867,15 +1867,15 @@ describe( 'selectors', () => { blockSelection: { start: 23, end: 123 }, }; - expect( getSelectedBlockUID( state ) ).toBe( null ); + expect( getSelectedBlockClientId( state ) ).toBe( null ); } ); - it( 'should return the selected block UID', () => { + it( 'should return the selected block ClientId', () => { const state = { blockSelection: { start: 23, end: 23 }, }; - expect( getSelectedBlockUID( state ) ).toEqual( 23 ); + expect( getSelectedBlockClientId( state ) ).toEqual( 23 ); } ); } ); @@ -1885,9 +1885,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 23, 123 ], @@ -1908,9 +1908,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 23, 123 ], @@ -1931,9 +1931,9 @@ describe( 'selectors', () => { currentPost: {}, editor: { present: { - blocksByUID: { - 23: { uid: 23, name: 'core/heading', attributes: {} }, - 123: { uid: 123, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 23: { clientId: 23, name: 'core/heading', attributes: {} }, + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, }, blockOrder: { '': [ 23, 123 ], @@ -1947,7 +1947,7 @@ describe( 'selectors', () => { }; expect( getSelectedBlock( state ) ).toEqual( { - uid: 23, + clientId: 23, name: 'core/heading', attributes: {}, innerBlocks: [], @@ -1955,7 +1955,7 @@ describe( 'selectors', () => { } ); } ); - describe( 'getBlockRootUID', () => { + describe( 'getBlockRootClientId', () => { it( 'should return null if the block does not exist', () => { const state = { editor: { @@ -1965,10 +1965,10 @@ describe( 'selectors', () => { }, }; - expect( getBlockRootUID( state, 56 ) ).toBeNull(); + expect( getBlockRootClientId( state, 56 ) ).toBeNull(); } ); - it( 'should return root UID relative the block UID', () => { + it( 'should return root ClientId relative the block ClientId', () => { const state = { editor: { present: { @@ -1980,11 +1980,11 @@ describe( 'selectors', () => { }, }; - expect( getBlockRootUID( state, 56 ) ).toBe( '123' ); + expect( getBlockRootClientId( state, 56 ) ).toBe( '123' ); } ); } ); - describe( 'getMultiSelectedBlockUids', () => { + describe( 'getMultiSelectedBlockClientIds', () => { it( 'should return empty if there is no multi selection', () => { const state = { editor: { @@ -1997,10 +1997,10 @@ describe( 'selectors', () => { blockSelection: { start: null, end: null }, }; - expect( getMultiSelectedBlockUids( state ) ).toEqual( [] ); + expect( getMultiSelectedBlockClientIds( state ) ).toEqual( [] ); } ); - it( 'should return selected block uids if there is multi selection', () => { + it( 'should return selected block clientIds if there is multi selection', () => { const state = { editor: { present: { @@ -2012,10 +2012,10 @@ describe( 'selectors', () => { blockSelection: { start: 2, end: 4 }, }; - expect( getMultiSelectedBlockUids( state ) ).toEqual( [ 4, 3, 2 ] ); + expect( getMultiSelectedBlockClientIds( state ) ).toEqual( [ 4, 3, 2 ] ); } ); - it( 'should return selected block uids if there is multi selection (nested context)', () => { + it( 'should return selected block clientIds if there is multi selection (nested context)', () => { const state = { editor: { present: { @@ -2028,7 +2028,7 @@ describe( 'selectors', () => { blockSelection: { start: 7, end: 9 }, }; - expect( getMultiSelectedBlockUids( state ) ).toEqual( [ 9, 8, 7 ] ); + expect( getMultiSelectedBlockClientIds( state ) ).toEqual( [ 9, 8, 7 ] ); } ); } ); @@ -2037,7 +2037,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -2052,13 +2052,13 @@ describe( 'selectors', () => { } ); } ); - describe( 'getMultiSelectedBlocksStartUid', () => { + describe( 'getMultiSelectedBlocksStartClientId', () => { it( 'returns null if there is no multi selection', () => { const state = { blockSelection: { start: null, end: null }, }; - expect( getMultiSelectedBlocksStartUid( state ) ).toBeNull(); + expect( getMultiSelectedBlocksStartClientId( state ) ).toBeNull(); } ); it( 'returns multi selection start', () => { @@ -2066,17 +2066,17 @@ describe( 'selectors', () => { blockSelection: { start: 2, end: 4 }, }; - expect( getMultiSelectedBlocksStartUid( state ) ).toBe( 2 ); + expect( getMultiSelectedBlocksStartClientId( state ) ).toBe( 2 ); } ); } ); - describe( 'getMultiSelectedBlocksEndUid', () => { + describe( 'getMultiSelectedBlocksEndClientId', () => { it( 'returns null if there is no multi selection', () => { const state = { blockSelection: { start: null, end: null }, }; - expect( getMultiSelectedBlocksEndUid( state ) ).toBeNull(); + expect( getMultiSelectedBlocksEndClientId( state ) ).toBeNull(); } ); it( 'returns multi selection end', () => { @@ -2084,12 +2084,12 @@ describe( 'selectors', () => { blockSelection: { start: 2, end: 4 }, }; - expect( getMultiSelectedBlocksEndUid( state ) ).toBe( 4 ); + expect( getMultiSelectedBlocksEndClientId( state ) ).toBe( 4 ); } ); } ); describe( 'getBlockOrder', () => { - it( 'should return the ordered block UIDs of top-level blocks by default', () => { + it( 'should return the ordered block ClientIds of top-level blocks by default', () => { const state = { editor: { present: { @@ -2103,7 +2103,7 @@ describe( 'selectors', () => { expect( getBlockOrder( state ) ).toEqual( [ 123, 23 ] ); } ); - it( 'should return the ordered block UIDs at a specified rootUID', () => { + it( 'should return the ordered block ClientIds at a specified rootClientId', () => { const state = { editor: { present: { @@ -2150,7 +2150,7 @@ describe( 'selectors', () => { } ); } ); - describe( 'getPreviousBlockUid', () => { + describe( 'getPreviousBlockClientId', () => { it( 'should return the previous block', () => { const state = { editor: { @@ -2162,7 +2162,7 @@ describe( 'selectors', () => { }, }; - expect( getPreviousBlockUid( state, 23 ) ).toEqual( 123 ); + expect( getPreviousBlockClientId( state, 23 ) ).toEqual( 123 ); } ); it( 'should return the previous block (nested context)', () => { @@ -2177,7 +2177,7 @@ describe( 'selectors', () => { }, }; - expect( getPreviousBlockUid( state, 56, '123' ) ).toEqual( 456 ); + expect( getPreviousBlockClientId( state, 56, '123' ) ).toEqual( 456 ); } ); it( 'should return null for the first block', () => { @@ -2191,7 +2191,7 @@ describe( 'selectors', () => { }, }; - expect( getPreviousBlockUid( state, 123 ) ).toBeNull(); + expect( getPreviousBlockClientId( state, 123 ) ).toBeNull(); } ); it( 'should return null for the first block (nested context)', () => { @@ -2206,11 +2206,11 @@ describe( 'selectors', () => { }, }; - expect( getPreviousBlockUid( state, 456, '123' ) ).toBeNull(); + expect( getPreviousBlockClientId( state, 456, '123' ) ).toBeNull(); } ); } ); - describe( 'getNextBlockUid', () => { + describe( 'getNextBlockClientId', () => { it( 'should return the following block', () => { const state = { editor: { @@ -2222,7 +2222,7 @@ describe( 'selectors', () => { }, }; - expect( getNextBlockUid( state, 123 ) ).toEqual( 23 ); + expect( getNextBlockClientId( state, 123 ) ).toEqual( 23 ); } ); it( 'should return the following block (nested context)', () => { @@ -2237,7 +2237,7 @@ describe( 'selectors', () => { }, }; - expect( getNextBlockUid( state, 456, '123' ) ).toEqual( 56 ); + expect( getNextBlockClientId( state, 456, '123' ) ).toEqual( 56 ); } ); it( 'should return null for the last block', () => { @@ -2251,7 +2251,7 @@ describe( 'selectors', () => { }, }; - expect( getNextBlockUid( state, 23 ) ).toBeNull(); + expect( getNextBlockClientId( state, 23 ) ).toBeNull(); } ); it( 'should return null for the last block (nested context)', () => { @@ -2266,7 +2266,7 @@ describe( 'selectors', () => { }, }; - expect( getNextBlockUid( state, 56, '123' ) ).toBeNull(); + expect( getNextBlockClientId( state, 56, '123' ) ).toBeNull(); } ); } ); @@ -2297,7 +2297,7 @@ describe( 'selectors', () => { } ); describe( 'hasSelectedInnerBlock', () => { - it( 'should return false if the selected block is a child of the given UID', () => { + it( 'should return false if the selected block is a child of the given ClientId', () => { const state = { blockSelection: { start: 5, end: 5 }, editor: { @@ -2312,7 +2312,7 @@ describe( 'selectors', () => { expect( hasSelectedInnerBlock( state, 4 ) ).toBe( false ); } ); - it( 'should return true if the selected block is a child of the given UID', () => { + it( 'should return true if the selected block is a child of the given ClientId', () => { const state = { blockSelection: { start: 3, end: 3 }, editor: { @@ -2533,17 +2533,17 @@ describe( 'selectors', () => { currentPost: {}, preferences: { mode: 'visual' }, blockSelection: { - start: 'uid1', - end: 'uid1', + start: 'clientId1', + end: 'clientId1', }, editor: { present: { - blocksByUID: { - uid1: { uid: 'uid1' }, + blocksByClientId: { + clientId1: { clientId: 'clientId1' }, }, blockOrder: { - '': [ 'uid1' ], - uid1: [], + '': [ 'clientId1' ], + clientId1: [], }, edits: {}, }, @@ -2552,6 +2552,8 @@ describe( 'selectors', () => { }; expect( getBlockInsertionPoint( state ) ).toEqual( { + rootClientId: undefined, + // TODO: To be removed in 3.5 "UID" deprecation. rootUID: undefined, layout: undefined, index: 1, @@ -2563,19 +2565,19 @@ describe( 'selectors', () => { currentPost: {}, preferences: { mode: 'visual' }, blockSelection: { - start: 'uid2', - end: 'uid2', + start: 'clientId2', + end: 'clientId2', }, editor: { present: { - blocksByUID: { - uid1: { uid: 'uid1' }, - uid2: { uid: 'uid2' }, + blocksByClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, }, blockOrder: { - '': [ 'uid1' ], - uid1: [ 'uid2' ], - uid2: [], + '': [ 'clientId1' ], + clientId1: [ 'clientId2' ], + clientId2: [], }, edits: {}, }, @@ -2584,7 +2586,9 @@ describe( 'selectors', () => { }; expect( getBlockInsertionPoint( state ) ).toEqual( { - rootUID: 'uid1', + rootClientId: 'clientId1', + // TODO: To be removed in 3.5 "UID" deprecation. + rootUID: 'clientId1', layout: undefined, index: 1, } ); @@ -2595,17 +2599,17 @@ describe( 'selectors', () => { currentPost: {}, preferences: { mode: 'visual' }, blockSelection: { - start: 'uid1', - end: 'uid1', + start: 'clientId1', + end: 'clientId1', }, editor: { present: { - blocksByUID: { - uid1: { uid: 'uid1', attributes: { layout: 'wide' } }, + blocksByClientId: { + clientId1: { clientId: 'clientId1', attributes: { layout: 'wide' } }, }, blockOrder: { - '': [ 'uid1' ], - uid1: [], + '': [ 'clientId1' ], + clientId1: [], }, edits: {}, }, @@ -2614,30 +2618,32 @@ describe( 'selectors', () => { }; expect( getBlockInsertionPoint( state ) ).toEqual( { + rootClientId: undefined, + // TODO: To be removed in 3.5 "UID" deprecation. rootUID: undefined, layout: 'wide', index: 1, } ); } ); - it( 'should return an object for the last multi selected uid', () => { + it( 'should return an object for the last multi selected clientId', () => { const state = { currentPost: {}, preferences: { mode: 'visual' }, blockSelection: { - start: 'uid1', - end: 'uid2', + start: 'clientId1', + end: 'clientId2', }, editor: { present: { - blocksByUID: { - uid1: { uid: 'uid1' }, - uid2: { uid: 'uid2' }, + blocksByClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, }, blockOrder: { - '': [ 'uid1', 'uid2' ], - uid1: [], - uid2: [], + '': [ 'clientId1', 'clientId2' ], + clientId1: [], + clientId2: [], }, edits: {}, }, @@ -2646,6 +2652,8 @@ describe( 'selectors', () => { }; expect( getBlockInsertionPoint( state ) ).toEqual( { + rootClientId: undefined, + // TODO: To be removed in 3.5 "UID" deprecation. rootUID: undefined, layout: undefined, index: 2, @@ -2662,14 +2670,14 @@ describe( 'selectors', () => { }, editor: { present: { - blocksByUID: { - uid1: { uid: 'uid1' }, - uid2: { uid: 'uid2' }, + blocksByClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, }, blockOrder: { - '': [ 'uid1', 'uid2' ], - uid1: [], - uid2: [], + '': [ 'clientId1', 'clientId2' ], + clientId1: [], + clientId2: [], }, edits: {}, }, @@ -2678,6 +2686,8 @@ describe( 'selectors', () => { }; expect( getBlockInsertionPoint( state ) ).toEqual( { + rootClientId: undefined, + // TODO: To be removed in 3.5 "UID" deprecation. rootUID: undefined, layout: undefined, index: 2, @@ -2767,7 +2777,7 @@ describe( 'selectors', () => { editor: { present: { blockOrder: {}, - blocksByUID: {}, + blocksByClientId: {}, edits: {}, }, }, @@ -2784,9 +2794,9 @@ describe( 'selectors', () => { blockOrder: { '': [ 123, 456 ], }, - blocksByUID: { - 123: { uid: 123, name: 'core/image', attributes: {} }, - 456: { uid: 456, name: 'core/quote', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/image', attributes: {} }, + 456: { clientId: 456, name: 'core/quote', attributes: {} }, }, edits: {}, }, @@ -2804,8 +2814,8 @@ describe( 'selectors', () => { blockOrder: { '': [ 123 ], }, - blocksByUID: { - 123: { uid: 123, name: 'core/image', attributes: {} }, + blocksByClientId: { + 123: { clientId: 123, name: 'core/image', attributes: {} }, }, edits: {}, }, @@ -2823,8 +2833,8 @@ describe( 'selectors', () => { blockOrder: { '': [ 456 ], }, - blocksByUID: { - 456: { uid: 456, name: 'core/quote', attributes: {} }, + blocksByClientId: { + 456: { clientId: 456, name: 'core/quote', attributes: {} }, }, edits: {}, }, @@ -2842,8 +2852,8 @@ describe( 'selectors', () => { blockOrder: { '': [ 567 ], }, - blocksByUID: { - 567: { uid: 567, name: 'core-embed/youtube', attributes: {} }, + blocksByClientId: { + 567: { clientId: 567, name: 'core-embed/youtube', attributes: {} }, }, edits: {}, }, @@ -2861,9 +2871,9 @@ describe( 'selectors', () => { blockOrder: { '': [ 456, 789 ], }, - blocksByUID: { - 456: { uid: 456, name: 'core/quote', attributes: {} }, - 789: { uid: 789, name: 'core/paragraph', attributes: {} }, + blocksByClientId: { + 456: { clientId: 456, name: 'core/quote', attributes: {} }, + 789: { clientId: 789, name: 'core/paragraph', attributes: {} }, }, edits: {}, }, @@ -2893,7 +2903,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, }, }, blockListSettings: {}, @@ -2906,7 +2916,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, }, }, blockListSettings: {}, @@ -2921,7 +2931,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, }, }, blockListSettings: {}, @@ -2936,7 +2946,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, }, }, blockListSettings: {}, @@ -2951,7 +2961,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, }, }, blockListSettings: {}, @@ -2964,7 +2974,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, }, }, @@ -2979,7 +2989,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-b' }, }, }, @@ -2994,7 +3004,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, }, }, @@ -3013,7 +3023,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, }, }, @@ -3032,7 +3042,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-b' }, }, }, @@ -3053,7 +3063,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, }, blockOrder: {}, @@ -3062,7 +3072,7 @@ describe( 'selectors', () => { }, sharedBlocks: { data: { - 1: { uid: 'block1', title: 'Shared Block 1' }, + 1: { clientId: 'block1', title: 'Shared Block 1' }, }, }, currentPost: {}, @@ -3110,7 +3120,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, block2: { name: 'core/test-block-a' }, }, @@ -3120,8 +3130,8 @@ describe( 'selectors', () => { }, sharedBlocks: { data: { - 1: { uid: 'block1', title: 'Shared Block 1' }, - 2: { uid: 'block1', title: 'Shared Block 2' }, + 1: { clientId: 'block1', title: 'Shared Block 1' }, + 2: { clientId: 'block1', title: 'Shared Block 2' }, }, }, currentPost: {}, @@ -3147,7 +3157,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-a' }, block2: { name: 'core/test-block-a' }, }, @@ -3157,8 +3167,8 @@ describe( 'selectors', () => { }, sharedBlocks: { data: { - 1: { uid: 'block1', title: 'Shared Block 1' }, - 2: { uid: 'block1', title: 'Shared Block 2' }, + 1: { clientId: 'block1', title: 'Shared Block 1' }, + 2: { clientId: 'block1', title: 'Shared Block 2' }, }, }, currentPost: {}, @@ -3205,7 +3215,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-b' }, }, blockOrder: { @@ -3233,7 +3243,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -3257,7 +3267,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: {}, + blocksByClientId: {}, blockOrder: {}, edits: {}, }, @@ -3284,7 +3294,7 @@ describe( 'selectors', () => { const state = { editor: { present: { - blocksByUID: { + blocksByClientId: { block1: { name: 'core/test-block-b' }, }, blockOrder: { @@ -3315,7 +3325,7 @@ describe( 'selectors', () => { sharedBlocks: { data: { 8109: { - uid: 'foo', + clientId: 'foo', title: 'My cool block', }, }, @@ -3326,7 +3336,7 @@ describe( 'selectors', () => { expect( actualSharedBlock ).toEqual( { id: 8109, isTemporary: false, - uid: 'foo', + clientId: 'foo', title: 'My cool block', } ); } ); @@ -3336,7 +3346,7 @@ describe( 'selectors', () => { sharedBlocks: { data: { shared1: { - uid: 'foo', + clientId: 'foo', title: 'My cool block', }, }, @@ -3347,7 +3357,7 @@ describe( 'selectors', () => { expect( actualSharedBlock ).toEqual( { id: 'shared1', isTemporary: true, - uid: 'foo', + clientId: 'foo', title: 'My cool block', } ); } ); @@ -3421,16 +3431,16 @@ describe( 'selectors', () => { const state = { sharedBlocks: { data: { - 123: { uid: 'carrot' }, - shared1: { uid: 'broccoli' }, + 123: { clientId: 'carrot' }, + shared1: { clientId: 'broccoli' }, }, }, }; const sharedBlocks = getSharedBlocks( state ); expect( sharedBlocks ).toEqual( [ - { id: 123, isTemporary: false, uid: 'carrot' }, - { id: 'shared1', isTemporary: true, uid: 'broccoli' }, + { id: 123, isTemporary: false, clientId: 'carrot' }, + { id: 'shared1', isTemporary: true, clientId: 'broccoli' }, ] ); } ); @@ -3617,21 +3627,21 @@ describe( 'selectors', () => { } ); } ); - describe( 'getProvisionalBlockUID()', () => { + describe( 'getProvisionalBlockClientId()', () => { it( 'should return null if not set', () => { - const provisionalBlockUID = getProvisionalBlockUID( { - provisionalBlockUID: null, + const provisionalBlockClientId = getProvisionalBlockClientId( { + provisionalBlockClientId: null, } ); - expect( provisionalBlockUID ).toBe( null ); + expect( provisionalBlockClientId ).toBe( null ); } ); - it( 'should return UID of provisional block', () => { - const provisionalBlockUID = getProvisionalBlockUID( { - provisionalBlockUID: 'chicken', + it( 'should return ClientId of provisional block', () => { + const provisionalBlockClientId = getProvisionalBlockClientId( { + provisionalBlockClientId: 'chicken', } ); - expect( provisionalBlockUID ).toBe( 'chicken' ); + expect( provisionalBlockClientId ).toBe( 'chicken' ); } ); } ); @@ -3665,7 +3675,7 @@ describe( 'selectors', () => { } ); describe( 'getTemplateLock', () => { - it( 'should return the general template lock if no uid was set', () => { + it( 'should return the general template lock if no clientId was set', () => { const state = { settings: { templateLock: 'all' }, }; @@ -3673,7 +3683,7 @@ describe( 'selectors', () => { expect( getTemplateLock( state ) ).toBe( 'all' ); } ); - it( 'should return null if the specified uid was not found ', () => { + it( 'should return null if the specified clientId was not found ', () => { const state = { settings: { templateLock: 'all' }, blockListSettings: { @@ -3699,7 +3709,7 @@ describe( 'selectors', () => { expect( getTemplateLock( state, 'ribs' ) ).toBe( null ); } ); - it( 'should return the template lock for the specified uid', () => { + it( 'should return the template lock for the specified clientId', () => { const state = { settings: { templateLock: 'all' }, blockListSettings: { diff --git a/editor/utils/dom.js b/editor/utils/dom.js index 6fc736ccdb9e2..ccd8c88dc4327 100644 --- a/editor/utils/dom.js +++ b/editor/utils/dom.js @@ -4,29 +4,30 @@ import 'element-closest'; /** - * Given a block UID, returns the corresponding DOM node for the block, if - * exists. As much as possible, this helper should be avoided, and used only + * Given a block client ID, returns the corresponding DOM node for the block, + * if exists. As much as possible, this helper should be avoided, and used only * in cases where isolated behaviors need remote access to a block node. * - * @param {string} uid Block UID. + * @param {string} clientId Block client ID. * * @return {Element} Block DOM node. */ -export function getBlockDOMNode( uid ) { - return document.querySelector( '[data-block="' + uid + '"]' ); +export function getBlockDOMNode( clientId ) { + return document.querySelector( '[data-block="' + clientId + '"]' ); } /** - * Given a block UID, returns the corresponding DOM node for the block focusable - * wrapper, if exists. As much as possible, this helper should be avoided, and - * used only in cases where isolated behaviors need remote access to a block node. + * Given a block client ID, returns the corresponding DOM node for the block + * focusable wrapper, if exists. As much as possible, this helper should be + * avoided, and used only in cases where isolated behaviors need remote access + * to a block node. * - * @param {string} uid Block UID. + * @param {string} clientId Block client ID. * * @return {Element} Block DOM node. */ -export function getBlockFocusableWrapper( uid ) { - return getBlockDOMNode( uid ).closest( '.editor-block-list__block' ); +export function getBlockFocusableWrapper( clientId ) { + return getBlockDOMNode( clientId ).closest( '.editor-block-list__block' ); } /**