title( 'Hello' )
* ->size( 480, 320 )
* ->state( array( 'count' => 0 ) )
* ->action( 'bump', function ( State $state ) {
* $state->set( 'count', $state->get( 'count' ) + 1 );
* } )
* ->view( function ( State $state ) { ?>
*
* Bump
* 520,
'height' => 400,
'min_width' => 280,
'min_height' => 220,
);
/**
* @var array
*/
private $nav = array(
'admin' => 'site',
'placement' => 'dock',
'nav_kind' => 'app',
'dock_order' => 0,
'placeable' => false,
'autofocus' => false,
);
/**
* @var array|null
*/
private $desktop_icon = null;
/**
* @var callable|null
*/
private $gate = null;
/**
* @var string[]
*/
private $capabilities = array();
/**
* @var string
*/
private $style = '';
/**
* @var array
*/
private $defaults = array();
/**
* @var callable|null
*/
private $mount = null;
/**
* @var array
*/
private $actions = array();
/**
* @var callable|null
*/
private $view = null;
/**
* @var callable|null
*/
private $data = null;
/**
* Built client-view script, absolute path.
*
* @var string
*/
private $client = '';
/**
* Whether `data()` ships with the window config. See `prefetch()`.
*
* @var bool
*/
private $prefetch = false;
/**
* @var array>
*/
private $title_bar_buttons = array();
/**
* @var array>
*/
private $window_actions = array();
/**
* Per-window chrome: `theme` tokens, `controls`, `slots`.
*
* @var array
*/
private $appearance = array();
/**
* @var array
*/
private $config = array();
/**
* Config callables resolved when the manifest is built.
*
* @var callable[]
*/
private $config_lazy = array();
/**
* Extra tabs: `value => array( label, view, position )`.
*
* @var array>
*/
private $tabs = array();
/**
* Channel subscriptions: `channel => action`.
*
* @var array
*/
private $channels = array();
/**
* Content types whose `os..changed` broadcasts re-render
* this app.
*
* @var string[]
*/
private $watch = array();
/**
* @var string
*/
private $dir = '';
/**
* @var string
*/
private $file = '';
/**
* @param string $id App id — also the window id and the icon id.
* @throws \InvalidArgumentException When the id is not a slug.
*/
private function __construct( $id ) {
$id = strtolower( trim( (string) $id ) );
if ( ! preg_match( '/^[a-z0-9][a-z0-9_-]*$/', $id ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Escaped by `Html\esc()`; the host-agnostic core cannot call `esc_html()`, and Plugin Check runs its own ruleset without our `customEscapingFunctions`.
throw new \InvalidArgumentException( sprintf( 'Invalid app id "%s": use lowercase letters, digits, "-" and "_".', esc( $id ) ) );
}
$this->id = $id;
}
/**
* Start a definition.
*
* @param string $id App id.
* @return self
*/
public static function define( $id ) {
return new self( $id );
}
// -------------------------------------------------------- identity
/**
* Window title (also the desktop icon's label by default).
*
* @param string $title Title.
* @return self
*/
public function title( $title ) {
$this->title = (string) $title;
return $this;
}
/**
* Icon: a Dashicons class, an image URL, or raw `