[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/interactivity-api/ -> class-wp-interactivity-api.php (summary)

Interactivity API: WP_Interactivity_API class.

File Size: 1000 lines (38 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 22 functions

  state()
  config()
  print_client_interactivity_data()
  register_script_modules()
  add_hooks()
  process_directives()
  process_directives_args()
  evaluate()
  extract_prefix_and_suffix()
  extract_directive_value()
  kebab_to_camel_case()
  data_wp_interactive_processor()
  data_wp_context_processor()
  data_wp_bind_processor()
  data_wp_class_processor()
  data_wp_style_processor()
  merge_style_property()
  data_wp_text_processor()
  get_router_animation_styles()
  print_router_loading_and_screen_reader_markup()
  data_wp_router_region_processor()
  data_wp_each_processor()

Functions
Functions that are not part of a class:

state( string $store_namespace, array $state = array()   X-Ref
Gets and/or sets the initial state of an Interactivity API store for a
given namespace.

If state for that store namespace already exists, it merges the new
provided state with the existing one.

return: array The current state for the specified store namespace. This will be the updated state if a $state
param: string $store_namespace The unique store namespace identifier.
param: array  $state           Optional. The array that will be merged with the existing state for the specified

config( string $store_namespace, array $config = array()   X-Ref
Gets and/or sets the configuration of the Interactivity API for a given
store namespace.

If configuration for that store namespace exists, it merges the new
provided configuration with the existing one.

return: array The configuration for the specified store namespace. This will be the updated configuration if a
param: string $store_namespace The unique store namespace identifier.
param: array  $config          Optional. The array that will be merged with the existing configuration for the

print_client_interactivity_data()   X-Ref
Prints the serialized client-side interactivity data.

Encodes the config and initial state into JSON and prints them inside a
script tag of type "application/json". Once in the browser, the state will
be parsed and used to hydrate the client-side interactivity stores and the
configuration will be available using a `getConfig` utility.


register_script_modules()   X-Ref
Registers the `@wordpress/interactivity` script modules.


add_hooks()   X-Ref
Adds the necessary hooks for the Interactivity API.


process_directives( string $html )   X-Ref
Processes the interactivity directives contained within the HTML content
and updates the markup accordingly.

return: string The processed HTML content. It returns the original content when the HTML contains unbalanced tags.
param: string $html The HTML content to process.

process_directives_args( string $html, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the interactivity directives contained within the HTML content
and updates the markup accordingly.

It needs the context and namespace stacks to be passed by reference, and
it returns null if the HTML contains unbalanced tags.

return: string|null The processed HTML content. It returns null when the HTML contains unbalanced tags.
param: string $html            The HTML content to process.
param: array  $context_stack   The reference to the array used to keep track of contexts during processing.
param: array  $namespace_stack The reference to the array used to manage namespaces during processing.

evaluate( $directive_value, string $default_namespace, $context = false )   X-Ref
Evaluates the reference path passed to a directive based on the current
store namespace, state and context.

return: mixed|null The result of the evaluation. Null if the reference path doesn't exist.
param: string|true $directive_value   The directive attribute value string or `true` when it's a boolean attribute.
param: string      $default_namespace The default namespace to use if none is explicitly defined in the directive
param: array|false $context           The current context for evaluating the directive or false if there is no

extract_prefix_and_suffix( string $directive_name )   X-Ref
Extracts the directive attribute name to separate and return the directive
prefix and an optional suffix.

The suffix is the string after the first double hyphen and the prefix is
everything that comes before the suffix.

Example:

extract_prefix_and_suffix( 'data-wp-interactive' )   => array( 'data-wp-interactive', null )
extract_prefix_and_suffix( 'data-wp-bind--src' )     => array( 'data-wp-bind', 'src' )
extract_prefix_and_suffix( 'data-wp-foo--and--bar' ) => array( 'data-wp-foo', 'and--bar' )

return: array An array containing the directive prefix and optional suffix.
param: string $directive_name The directive attribute name.

extract_directive_value( $directive_value, $default_namespace = null )   X-Ref
Parses and extracts the namespace and reference path from the given
directive attribute value.

If the value doesn't contain an explicit namespace, it returns the
default one. If the value contains a JSON object instead of a reference
path, the function tries to parse it and return the resulting array. If
the value contains strings that represent booleans ("true" and "false"),
numbers ("1" and "1.2") or "null", the function also transform them to
regular booleans, numbers and `null`.

Example:

extract_directive_value( 'actions.foo', 'myPlugin' )                      => array( 'myPlugin', 'actions.foo' )
extract_directive_value( 'otherPlugin::actions.foo', 'myPlugin' )         => array( 'otherPlugin', 'actions.foo' )
extract_directive_value( '{ "isOpen": false }', 'myPlugin' )              => array( 'myPlugin', array( 'isOpen' => false ) )
extract_directive_value( 'otherPlugin::{ "isOpen": false }', 'myPlugin' ) => array( 'otherPlugin', array( 'isOpen' => false ) )

return: array An array containing the namespace in the first item and the JSON, the reference path, or null on the
param: string|true $directive_value   The directive attribute value. It can be `true` when it's a boolean
param: string|null $default_namespace Optional. The default namespace if none is explicitly defined.

kebab_to_camel_case( string $str )   X-Ref
Transforms a kebab-case string to camelCase.

return: string The transformed camelCase string.
param: string $str The kebab-case string to transform to camelCase.

data_wp_interactive_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
No description

data_wp_context_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the `data-wp-context` directive.

It adds the context defined in the directive value to the stack so that
it's available for the nested interactivity elements.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.

data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the `data-wp-bind` directive.

It updates or removes the bound attributes based on the evaluation of its
associated reference.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.

data_wp_class_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the `data-wp-class` directive.

It adds or removes CSS classes in the current HTML element based on the
evaluation of its associated references.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.

data_wp_style_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the `data-wp-style` directive.

It updates the style attribute value of the current HTML element based on
the evaluation of its associated references.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.

merge_style_property( string $style_attribute_value, string $style_property_name, $style_property_value )   X-Ref
Merges an individual style property in the `style` attribute of an HTML
element, updating or removing the property when necessary.

If a property is modified, the old one is removed and the new one is added
at the end of the list.

return: string The new style attribute value after the specified property has been added, updated or removed.
param: string            $style_attribute_value The current style attribute value.
param: string            $style_property_name   The style property name to set.
param: string|false|null $style_property_value  The value to set for the style property. With false, null or an

data_wp_text_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack )   X-Ref
Processes the `data-wp-text` directive.

It updates the inner content of the current HTML element based on the
evaluation of its associated reference.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.

get_router_animation_styles()   X-Ref
Returns the CSS styles for animating the top loading bar in the router.

return: string The CSS styles for the router's top loading bar animation.

print_router_loading_and_screen_reader_markup()   X-Ref
Outputs the markup for the top loading indicator and the screen reader
notifications during client-side navigations.

This method prints a div element representing a loading bar visible during
navigation, as well as an aria-live region that can be read by screen
readers to announce navigation status.


data_wp_router_region_processor( WP_Interactivity_API_Directives_Processor $p, string $mode )   X-Ref
Processes the `data-wp-router-region` directive.

It renders in the footer a set of HTML elements to notify users about
client-side navigations. More concretely, the elements added are 1) a
top loading bar to visually inform that a navigation is in progress
and 2) an `aria-live` region for accessible navigation announcements.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.

data_wp_each_processor( WP_Interactivity_API_Directives_Processor $p, string $mode, array &$context_stack, array &$namespace_stack, array &$tag_stack )   X-Ref
Processes the `data-wp-each` directive.

This directive gets an array passed as reference and iterates over it
generating new content for each item based on the inner markup of the
`template` tag.

param: WP_Interactivity_API_Directives_Processor $p               The directives processor instance.
param: string                                    $mode            Whether the processing is entering or exiting the tag.
param: array                                     $context_stack   The reference to the context stack.
param: array                                     $namespace_stack The reference to the store namespace stack.
param: array                                     $tag_stack       The reference to the tag stack.



Generated : Sat Apr 27 08:20:02 2024 Cross-referenced by PHPXref