-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
135 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
export function setYDoc( doc ) { | ||
return { | ||
type: 'SET_YJS_DOC', | ||
type: 'SET_COLLAB_YJS_DOC', | ||
doc, | ||
}; | ||
} | ||
|
||
export function setUndoManager( undoManager ) { | ||
return { | ||
type: 'SET_COLLAB_UNDO_MANAGER', | ||
undoManager, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
import { ActionCreators } from 'redux-undo'; | ||
|
||
import { createRegistryControl } from '@wordpress/data'; | ||
|
||
const debugUndo = require( 'debug' )( 'iso-editor:collab:undo' ); | ||
|
||
const applyChangesToYDoc = createRegistryControl( ( registry ) => ( action ) => { | ||
const doc = registry.select( 'isolated/editor' ).getYDoc(); | ||
|
||
if ( doc ) { | ||
if ( doc && ! action.isTriggeredByYDoc ) { | ||
doc.applyDataChanges( { blocks: action.blocks } ); | ||
} | ||
|
||
return action; | ||
} ); | ||
|
||
export const UPDATE_BLOCKS_WITH_UNDO = applyChangesToYDoc; | ||
export const UPDATE_BLOCKS_WITHOUT_UNDO = applyChangesToYDoc; | ||
export default { | ||
UPDATE_BLOCKS_WITH_UNDO: applyChangesToYDoc, | ||
UPDATE_BLOCKS_WITHOUT_UNDO: applyChangesToYDoc, | ||
|
||
[ ActionCreators.undo().type ]: createRegistryControl( ( registry ) => ( action ) => { | ||
const undoManager = registry.select( 'isolated/editor' ).getUndoManager(); | ||
|
||
if ( ! undoManager ) { | ||
return action; | ||
} | ||
|
||
debugUndo( 'undo' ); | ||
undoManager.undo(); | ||
return; // prevent default action | ||
} ), | ||
|
||
[ ActionCreators.redo().type ]: createRegistryControl( ( registry ) => ( action ) => { | ||
const undoManager = registry.select( 'isolated/editor' ).getUndoManager(); | ||
|
||
if ( ! undoManager ) { | ||
return action; | ||
} | ||
|
||
debugUndo( 'redo' ); | ||
registry.select( 'isolated/editor' ).getUndoManager().redo(); | ||
return; // prevent default action | ||
} ), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export function getYDoc( state ) { | ||
return state.collab.yDoc; | ||
} | ||
|
||
export function getUndoManager( state ) { | ||
return state.collab.undoManager; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters