Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/experimental/synchronization.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ function gutenberg_rest_api_init_collaborative_editing() {
wp_add_inline_script( 'wp-sync', 'window.__experimentalCollaborativeEditingSecret = "' . $collaborative_editing_secret . '";', 'before' );
}
add_action( 'admin_init', 'gutenberg_rest_api_init_collaborative_editing' );

/**
* Add support for collaborative editing to some built-in post types.
*/
function gutenberg_add_collaborative_editing_post_type_support() {
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( ! $gutenberg_experiments || ! array_key_exists( 'gutenberg-sync-collaboration', $gutenberg_experiments ) ) {
return;
}

foreach ( array( 'page', 'post' ) as $post_type ) {
if ( post_type_exists( $post_type ) ) {
add_post_type_support( $post_type, 'collaborative-editing' );
}
}
}
add_action( 'init', 'gutenberg_add_collaborative_editing_post_type_support', 10, 0 );
4 changes: 2 additions & 2 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ function gutenberg_initialize_experiments_settings() {

add_settings_field(
'gutenberg-sync-collaboration',
__( 'Collaboration: add real time editing', 'gutenberg' ),
__( 'Collaboration: enable real-time collaboration', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enables live collaboration and offline persistence between peers.', 'gutenberg' ),
'label' => __( 'Enables real-time collaboration between peers.', 'gutenberg' ),
'id' => 'gutenberg-sync-collaboration',
)
);
Expand Down
202 changes: 105 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions packages/block-editor/src/components/provider/use-block-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,25 @@ export default function useBlockSync( {
// and so it would already be persisted.
__unstableMarkNextChangeAsNotPersistent();
if ( clientId ) {
const blockName = getBlockName( clientId );
const isPostContentBlock = blockName === 'core/post-content';

// It is important to batch here because otherwise,
// as soon as `setHasControlledInnerBlocks` is called
// the effect to restore might be triggered
// before the actual blocks get set properly in state.
registry.batch( () => {
setHasControlledInnerBlocks( clientId, true );
const storeBlocks = controlledBlocks.map( ( block ) =>
cloneBlock( block )
);

// For post-content block children, preserve the
// original blocks to maintain UUIDs used for
// multi-user collaboration
//
// Unsure: Why are these blocks being cloned? Do they need to be?
const storeBlocks = isPostContentBlock
? controlledBlocks
: controlledBlocks.map( ( block ) => cloneBlock( block ) );

if ( subscribedRef.current ) {
pendingChangesRef.current.incoming = storeBlocks;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@wordpress/data": "file:../data",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/element": "file:../element",
"@wordpress/hooks": "file:../hooks",
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
Expand All @@ -52,6 +53,7 @@
"change-case": "^4.1.2",
"equivalent-key-map": "^0.2.2",
"fast-deep-equal": "^3.1.3",
"lib0": "^0.2.99",
"memize": "^2.1.0",
"uuid": "^9.0.1"
},
Expand Down
Loading
Loading