-
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.
Block API: Ensure backwards compatibility for block matchers
- Loading branch information
1 parent
7d79f94
commit 8252a6b
Showing
7 changed files
with
113 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { nodeListToReact, nodeToReact } from 'dom-react'; | ||
export { attr, prop, html, text, query } from 'hpq'; | ||
|
||
export const children = ( selector ) => { | ||
return ( domNode ) => { | ||
let match = domNode; | ||
|
||
if ( selector ) { | ||
match = domNode.querySelector( selector ); | ||
} | ||
|
||
if ( match ) { | ||
return nodeListToReact( match.childNodes || [], createElement ); | ||
} | ||
|
||
return []; | ||
}; | ||
}; | ||
|
||
export const node = ( 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
function warnAboutDeprecatedMatcher() { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'Attributes matchers are deprecated and they will be removed in a future version of Gutenberg. ' + | ||
'Please update your attributes definition https://wordpress.org/gutenberg/handbook/reference/attributes/' | ||
); | ||
} | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { nodeListToReact, nodeToReact } from 'dom-react'; | ||
export { attr, prop, html, text, query } from 'hpq'; | ||
|
||
export const children = ( selector ) => { | ||
return ( domNode ) => { | ||
let match = domNode; | ||
export const attr = ( selector, attribute ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'attribute', | ||
attribute: attribute === undefined ? selector : attribute, | ||
selector: attribute === undefined ? undefined : selector, | ||
}; | ||
}; | ||
|
||
if ( selector ) { | ||
match = domNode.querySelector( selector ); | ||
} | ||
export const prop = ( selector, property ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'property', | ||
property: property === undefined ? selector : property, | ||
selector: property === undefined ? undefined : selector, | ||
}; | ||
}; | ||
|
||
if ( match ) { | ||
return nodeListToReact( match.childNodes || [], createElement ); | ||
} | ||
export const html = ( selector ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'html', | ||
selector, | ||
}; | ||
}; | ||
|
||
return []; | ||
export const text = ( selector ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'text', | ||
selector, | ||
}; | ||
}; | ||
|
||
export const node = ( selector ) => { | ||
return ( domNode ) => { | ||
let match = domNode; | ||
export const query = ( selector, subMatchers ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'query', | ||
selector, | ||
query: subMatchers, | ||
}; | ||
}; | ||
|
||
if ( selector ) { | ||
match = domNode.querySelector( selector ); | ||
} | ||
export const children = ( selector ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'children', | ||
selector, | ||
}; | ||
}; | ||
|
||
return nodeToReact( match, createElement ); | ||
export const node = ( selector ) => () => { | ||
warnAboutDeprecatedMatcher(); | ||
return { | ||
source: 'node', | ||
selector, | ||
}; | ||
}; |
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