-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1902 from WordPress/update/query-to-matchers
Rename blocks.query as blocks.source
- Loading branch information
Showing
32 changed files
with
143 additions
and
143 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { nodeListToReact, nodeToReact } from 'dom-react'; | ||
import { flow } from 'lodash'; | ||
import { | ||
attr as originalAttr, | ||
prop as originalProp, | ||
html as originalHtml, | ||
text as originalText, | ||
query as originalQuery, | ||
} from 'hpq'; | ||
|
||
/** | ||
* Given a source function creator, returns a new function which applies an | ||
* internal flag to the created source. | ||
* | ||
* @param {Function} fn Original source function creator | ||
* @return {Function} Modified source function creator | ||
*/ | ||
function withKnownSourceFlag( fn ) { | ||
return flow( fn, ( source ) => { | ||
source._wpBlocksKnownSource = true; | ||
return source; | ||
} ); | ||
} | ||
|
||
export const attr = withKnownSourceFlag( originalAttr ); | ||
export const prop = withKnownSourceFlag( originalProp ); | ||
export const html = withKnownSourceFlag( originalHtml ); | ||
export const text = withKnownSourceFlag( originalText ); | ||
export const query = withKnownSourceFlag( originalQuery ); | ||
export const children = withKnownSourceFlag( ( selector ) => { | ||
return ( domNode ) => { | ||
let match = domNode; | ||
|
||
if ( selector ) { | ||
match = domNode.querySelector( selector ); | ||
} | ||
|
||
if ( match ) { | ||
return nodeListToReact( match.childNodes || [], createElement ); | ||
} | ||
|
||
return []; | ||
}; | ||
} ); | ||
export const node = withKnownSourceFlag( ( selector ) => { | ||
return ( domNode ) => { | ||
let match = domNode; | ||
|
||
if ( selector ) { | ||
match = domNode.querySelector( selector ); | ||
} | ||
|
||
return nodeToReact( match, createElement ); | ||
}; | ||
} ); |
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
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
Oops, something went wrong.