Directory

Docs: Interactivity API - Add viewScriptModule as a requirement to work with the Interactivity API by juanmaguitar · Pull Request #61355 · WordPress/gutenberg · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Interactivity API - Add viewScriptModule as a requirement to work with the Interactivity API #61355

Merged
merged 5 commits into from
May 3, 2024

Conversation

juanmaguitar
Copy link
Contributor

What?

Add viewScriptModule as a requirement to work with the Interactivity API

Why?

Because it's currently a critical requirement and is not properly reflected in the docs.

@juanmaguitar juanmaguitar added [Type] Developer Documentation Documentation for developers [Feature] Interactivity API API to add frontend interactivity to blocks. labels May 3, 2024
Copy link

github-actions bot commented May 3, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I left some notes. I want to make sure we refine the section that mentions namespaces.

docs/reference-guides/interactivity-api/README.md Outdated Show resolved Hide resolved
#### Add `wp-interactive` directive to a DOM element

To "activate" the Interactivity API in a DOM element (and its children), add the [`wp-interactive`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#wp-interactive) directive to the element in the block's `render.php` or `save.js` files.
To "activate" the Interactivity API in a DOM element (and its children), add the [`wp-interactive`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#wp-interactive) directive to the element in the block's `render.php` or `save.js` files. Its value must be the unique namespace of your plugin or block:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is accurate. The namespace is an Interactivity API concept. It may match your plugin or block name. Or you may develop a plugin that shares the same namespace across many blocks.

I want to make sure we're not conflating a block name with an Interactivity API store - the namespaces are really about the stores and don't technically have anything to do with block names. They're unique store identifiers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, @sirreal.

Can this directive be used without a value?
Example:

<div data-wp-interactive>
    <!-- Interactivity API zone -->
</div>

Is there any way directives can specify the store they want to use for a specific callback (on a directive level)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

I just did some testing and it looks like data-wp-interactive is sufficient to recognize an interactive region.

Other stores can be accessed by prefixing the directive values with namespace:: like this: interactiveNamespace::state.whatever. So if you have another store like store( "otherNS", { state: { title: "Hello" } } ) you could do this:

<div data-wp-interactive>
    <h1 data-wp-text="otherNS::state.title"></h1>
</div>

I went to this page to look it up: https://make.wordpress.org/core/2024/03/04/interactivity-api-dev-note/
I think the section "Working with other namespaces" should have described this but it looks like had some of the code samples broken. FYI @cbravobernal (I think the syntaxhighlighter block breaks HTML fairly often and it may be better to use the code block).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oks, I have removed the part about "Its value must be the unique namespace of your plugin or block:" as it's confusing and it seems too specific for these introductory steps.

Any additional explanations and clarifications should be added to the wp-interactive documentation

@juanmaguitar juanmaguitar requested a review from sirreal May 3, 2024 16:20
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

docs/reference-guides/interactivity-api/README.md Outdated Show resolved Hide resolved
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
@juanmaguitar juanmaguitar enabled auto-merge (squash) May 3, 2024 17:59
@juanmaguitar juanmaguitar merged commit 2373c53 into trunk May 3, 2024
60 checks passed
@juanmaguitar juanmaguitar deleted the docs/iapi-requirement-viewScriptModule branch May 3, 2024 18:27
@github-actions github-actions bot added this to the Gutenberg 18.4 milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants