Support negation operator in selectors in the Interactivity API#50732
Merged
SantosGuillamot merged 2 commits intotrunkfrom May 19, 2023
Merged
Conversation
Member
Actually, @luisherranz proposed using negation with a selector when working on the File block. We can test it and even refactor with the following diff: diff --git a/lib/experimental/interactivity-api/blocks.php b/lib/experimental/interactivity-api/blocks.php
index 755c1d1d4f..8430245d53 100644
--- a/lib/experimental/interactivity-api/blocks.php
+++ b/lib/experimental/interactivity-api/blocks.php
@@ -23,7 +23,7 @@ function gutenberg_block_core_file_add_directives_to_content( $block_content, $b
$processor->next_tag();
$processor->set_attribute( 'data-wp-island', '' );
$processor->next_tag( 'object' );
- $processor->set_attribute( 'data-wp-bind.hidden', 'selectors.core.file.hasNoPdfPreview' );
+ $processor->set_attribute( 'data-wp-bind.hidden', '! selectors.core.file.hasPdfPreview' );
$processor->set_attribute( 'hidden', true );
return $processor->get_updated_html();
}
diff --git a/packages/block-library/src/file/interactivity.js b/packages/block-library/src/file/interactivity.js
index cf9ae41002..8060f7addf 100644
--- a/packages/block-library/src/file/interactivity.js
+++ b/packages/block-library/src/file/interactivity.js
@@ -2,15 +2,13 @@
* Internal dependencies
*/
import { store } from '../utils/interactivity';
-import { browserSupportsPdfs } from './utils';
+import { browserSupportsPdfs as hasPdfPreview } from './utils';
store( {
selectors: {
core: {
file: {
- hasNoPdfPreview() {
- return ! browserSupportsPdfs();
- },
+ hasPdfPreview,
},
},
}, |
|
Size Change: -6.85 kB (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
22 tasks
Contributor
Author
|
I made the changes to the file block in this commit 🙂 . |
westonruter
added a commit
that referenced
this pull request
May 19, 2023
…dd/static-closures * 'trunk' of https://github.com/WordPress/gutenberg: (26 commits) Add transparent outline to input control BackdropUI focus style. (#50772) Added wrapper element for RichText in File block (#50607) Remove the experimental flag of the command center (#50781) Update the document title in the site editor to open the command center (#50369) Remove `unwrap` from transforms and add `ungroup` to more blocks (#50385) Add new experimental version of DropdownMenu (#49473) Force display of in custom css input boxes to LTR (#50768) Polish experimental navigation block (#50670) Support negation operator in selectors in the Interactivity API (#50732) Minor updates to theme.json schema pages (#50742) $revisions_controller is not used. Let's delete it. (#50763) Remove OffCanvasEditor (#50705) Mobile - E2E test - Update code to use the new navigateUp helper (#50736) Try: Smaller external link icon (#50728) Block Editor: Remove unused 'useIsDimensionsSupportValid' method (#50735) Fix flaky media inserter drag-and-dropping e2e test (#50740) docs: Fix change log typo (#50737) Edit Site: Fix `useEditedEntityRecord()` loading state (#50730) Fix labelling, description, and focus style of the block transform to pattern previews (#50577) Fix Global Styles sidebar block selection on zoom out mode (#50708) ...
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
As explained in the original pull request in the block-interactivity-experiments repo, change the logic of the negation operator to support selectors.
Why?
Although it is not currently needed for the experimental blocks, it is not possible to use the negation operator with selectors. Something like
data-wp-bind.hidden="!selectors.open"won't work.How?
I moved the logic from
resolvetogetEvaluateafter we return the value of the function.In the original PR, I added tests to ensure it works properly.