| @@ -99,8 +99,27 @@ | ||
| 99 | 99 | * paints. Declaring it here is what |
| 100 | 100 | * keeps it off the boot critical |
| 101 | 101 | * path: it travels with the window |
| 102 | 102 | * it extends. Default empty. |
| 103 | + * @type string[] $styles Companion style handles injected on | |
| 104 | + * the window's first open, after the | |
| 105 | + * window's own `$style`, in the order | |
| 106 | + * given — so at equal specificity a | |
| 107 | + * companion's overrides win, the same | |
| 108 | + * source-order contract an enqueue | |
| 109 | + * dependency gives. The styles-side | |
| 110 | + * mirror of `$scripts`: a stylesheet | |
| 111 | + * that only paints surfaces inside | |
| 112 | + * this window is dead weight on every | |
| 113 | + * document that never shows it — | |
| 114 | + * declared here it costs nothing at | |
| 115 | + * boot and never reaches chromeless | |
| 116 | + * iframes at all. Unlike `$style` | |
| 117 | + * (injected when the window registers, | |
| 118 | + * so mid-session activations paint), | |
| 119 | + * companions wait for the first open; | |
| 120 | + * the deferral is the point. Default | |
| 121 | + * empty. | |
| 103 | 122 | * @type bool $preload_script Load `$script` (and `$scripts`) at |
| 104 | 123 | * shell boot instead of on first |
| 105 | 124 | * open. Default false — a window's |
| 106 | 125 | * bundle is dead weight until the |
| @@ -129,8 +148,15 @@ | ||
| 129 | 148 | * A PROPOSED default only: the user's |
| 130 | 149 | * OpenStation Preferences → Navigation |
| 131 | 150 | * pick wins, and so does a right-click |
| 132 | 151 | * "Keep in dock". |
| 152 | + * @type string $admin 'site' | 'network' | 'any'. Default | |
| 153 | + * 'site': offered on every site's | |
| 154 | + * shell and never on the network | |
| 155 | + * admin's, which is right for a window | |
| 156 | + * that reads the current site's REST | |
| 157 | + * API. 'network' is the network | |
| 158 | + * admin's shell only; 'any' is both. | |
| 133 | 159 | * @type string $nav_kind 'app' | 'control'. Default 'app'. |
| 134 | 160 | * What the window IS, which decides |
| 135 | 161 | * where its launcher defaults to (apps |
| 136 | 162 | * to the desktop, controls to the |
| @@ -214,8 +240,9 @@ | ||
| 214 | 240 | 'icon' => 'dashicons-admin-generic', |
| 215 | 241 | 'template' => null, |
| 216 | 242 | 'script' => '', |
| 217 | 243 | 'scripts' => array(), |
| 244 | + 'styles' => array(), | |
| 218 | 245 | 'preload_script' => false, |
| 219 | 246 | // Optional WP style handle (registered with `wp_register_style()`). |
| 220 | 247 | // Resolved at payload-build time so the shell can lazy-inject a |
| 221 | 248 | // `<link rel="stylesheet">` when a peer plugin is activated |
| @@ -227,8 +254,9 @@ | ||
| 227 | 254 | 'height' => 400, |
| 228 | 255 | 'min_width' => 280, |
| 229 | 256 | 'min_height' => 220, |
| 230 | 257 | 'placement' => 'dock', |
| 258 | + 'admin' => 'site', | |
| 231 | 259 | 'nav_kind' => 'app', |
| 232 | 260 | 'dock_order' => 0, |
| 233 | 261 | 'placeable' => false, |
| 234 | 262 | 'capabilities' => array(), |
| @@ -234,11 +262,17 @@ | ||
| 234 | 262 | 'capabilities' => array(), |
| 235 | 263 | 'autofocus' => false, |
| 236 | 264 | 'main_tab_label' => '', |
| 237 | 265 | 'main_tab_padding' => '', |
| 266 | + // Admin pages this window answers for, `array( id, page )` per | |
| 267 | + // entry. See `App::menu()` and `openstation_apps_menu_pages()`. | |
| 268 | + 'menu_pages' => array(), | |
| 238 | 269 | 'config' => array(), |
| 239 | 270 | ); |
| 240 | 271 | $args = wp_parse_args( $args, $defaults ); |
| 272 | + if ( ! in_array( $args['admin'], array( 'site', 'network', 'any' ), true ) ) { | |
| 273 | + $args['admin'] = 'site'; | |
| 274 | + } | |
| 241 | 275 | |
| 242 | 276 | // Capability gate — ALL listed caps must match. Fail closed. |
| 243 | 277 | foreach ( (array) $args['capabilities'] as $cap ) { |
| 244 | 278 | if ( ! current_user_can( (string) $cap ) ) { |
| @@ -303,8 +337,19 @@ | ||
| 303 | 337 | } |
| 304 | 338 | ) |
| 305 | 339 | ) |
| 306 | 340 | ), |
| 341 | + // Companion style handles, same dedupe/strip as `scripts`. | |
| 342 | + 'styles' => array_values( | |
| 343 | + array_unique( | |
| 344 | + array_filter( | |
| 345 | + array_map( 'strval', (array) $args['styles'] ), | |
| 346 | + static function ( $handle ) { | |
| 347 | + return '' !== $handle; | |
| 348 | + } | |
| 349 | + ) | |
| 350 | + ) | |
| 351 | + ), | |
| 307 | 352 | 'preload_script' => (bool) $args['preload_script'], |
| 308 | 353 | 'style' => (string) $args['style'], |
| 309 | 354 | 'width' => (int) $args['width'], |
| 310 | 355 | 'height' => (int) $args['height'], |
| @@ -311,8 +356,10 @@ | ||
| 311 | 356 | 'min_width' => (int) $args['min_width'], |
| 312 | 357 | 'min_height' => (int) $args['min_height'], |
| 313 | 358 | 'placement' => $placement, |
| 314 | 359 | 'nav_kind' => $nav_kind, |
| 360 | + // Which admin's shell offers it; see the `admin` arg. | |
| 361 | + 'admin' => $args['admin'], | |
| 315 | 362 | // Sort key among system tiles, ascending. `0` (the default) |
| 316 | 363 | // puts a plugin's tile ahead of the shell's own trailing |
| 317 | 364 | // cluster — Mio 10, Overview 20, System 30 — which is where a |
| 318 | 365 | // launcher belongs. Trash uses 40 to sit at the very end. |
| @@ -326,8 +373,12 @@ | ||
| 326 | 373 | // Bundle-bound config delivered through the same path as |
| 327 | 374 | // `wp_localize_script` `extra['data']` — see the `config` doc |
| 328 | 375 | // in this function's `$args` block and `openstation_resolve_script_payload()` |
| 329 | 376 | // for how it lands on the wire. |
| 377 | + // Admin pages this window answers for, `array( id, page )` per | |
| 378 | + // entry — dropped here once, which is why the shell saw an | |
| 379 | + // empty list and claimed none of them. | |
| 380 | + 'menu_pages' => is_array( $args['menu_pages'] ) ? array_values( $args['menu_pages'] ) : array(), | |
| 330 | 381 | 'config' => is_array( $args['config'] ) ? $args['config'] : array(), |
| 331 | 382 | ); |
| 332 | 383 | openstation_native_window_registry( $id, $entry ); |
| 333 | 384 | |
| @@ -486,8 +537,9 @@ | ||
| 486 | 537 | 'bordered' => true, |
| 487 | 538 | 'compact' => true, |
| 488 | 539 | 'loading' => true, |
| 489 | 540 | 'loading-rows' => true, |
| 541 | + 'empty' => true, | |
| 490 | 542 | 'columns' => true, |
| 491 | 543 | 'rows' => true, |
| 492 | 544 | 'sortable' => true, |
| 493 | 545 | 'expandable' => true, |
| @@ -492,8 +544,9 @@ | ||
| 492 | 544 | 'sortable' => true, |
| 493 | 545 | 'expandable' => true, |
| 494 | 546 | 'preset' => true, |
| 495 | 547 | 'label' => true, |
| 548 | + 'heading' => true, | |
| 496 | 549 | 'description' => true, |
| 497 | 550 | 'orientation' => true, |
| 498 | 551 | 'level' => true, |
| 499 | 552 | 'collapsed' => true, |
| @@ -931,9 +984,9 @@ | ||
| 931 | 984 | * builds that payload at 10, and data attached after it would ship a |
| 932 | 985 | * bundle with no config. |
| 933 | 986 | */ |
| 934 | 987 | function openstation_enqueue_native_window_scripts() { |
| 935 | - if ( ! openstation_is_enabled() || openstation_is_chromeless_request() || openstation_is_classic_request() ) { | |
| 988 | + if ( ! openstation_is_shell_request() ) { | |
| 936 | 989 | return; |
| 937 | 990 | } |
| 938 | 991 | $registry = openstation_native_window_registry(); |
| 939 | 992 | if ( ! is_array( $registry ) ) { |
| @@ -961,8 +1014,16 @@ | ||
| 961 | 1014 | wp_enqueue_script( $entry['script'] ); |
| 962 | 1015 | foreach ( (array) $entry['scripts'] as $companion ) { |
| 963 | 1016 | wp_enqueue_script( $companion ); |
| 964 | 1017 | } |
| 1018 | + // Preload means "everything at boot" — companion styles | |
| 1019 | + // ride along so the window paints styled on a preloaded | |
| 1020 | + // first open, same as its scripts are already parsed. | |
| 1021 | + if ( ! empty( $entry['styles'] ) ) { | |
| 1022 | + foreach ( (array) $entry['styles'] as $companion_style ) { | |
| 1023 | + wp_enqueue_style( $companion_style ); | |
| 1024 | + } | |
| 1025 | + } | |
| 965 | 1026 | } |
| 966 | 1027 | // Localize the config the JS side reads to register itself. |
| 967 | 1028 | wp_localize_script( |
| 968 | 1029 | $entry['script'], |
| @@ -1023,9 +1084,9 @@ | ||
| 1023 | 1084 | * these via `document.getElementById( `os-native-window-${id}` )` |
| 1024 | 1085 | * and clones them into each opened window's body. |
| 1025 | 1086 | */ |
| 1026 | 1087 | function openstation_render_native_window_templates() { |
| 1027 | - if ( ! openstation_is_enabled() || openstation_is_chromeless_request() || openstation_is_classic_request() ) { | |
| 1088 | + if ( ! openstation_is_shell_request() ) { | |
| 1028 | 1089 | return; |
| 1029 | 1090 | } |
| 1030 | 1091 | $registry = openstation_native_window_registry(); |
| 1031 | 1092 | if ( ! is_array( $registry ) ) { |
| @@ -1051,4 +1112,21 @@ | ||
| 1051 | 1112 | echo '</template>'; |
| 1052 | 1113 | } |
| 1053 | 1114 | } |
| 1054 | 1115 | add_action( 'admin_footer', 'openstation_render_native_window_templates', 20 ); |
| 1116 | + | |
| 1117 | +/** | |
| 1118 | + * Whether a registered window is offered on the admin this request is | |
| 1119 | + * in: the network admin's shell offers `network` and `any` windows, | |
| 1120 | + * every site's shell offers `site` and `any`. See the `admin` arg of | |
| 1121 | + * {@see openstation_register_window()}. | |
| 1122 | + * | |
| 1123 | + * @param array<string,mixed> $entry Registry entry. | |
| 1124 | + * @return bool | |
| 1125 | + */ | |
| 1126 | +function openstation_native_window_offered_here( $entry ) { | |
| 1127 | + $admin = isset( $entry['admin'] ) ? (string) $entry['admin'] : 'site'; | |
| 1128 | + if ( 'any' === $admin ) { | |
| 1129 | + return true; | |
| 1130 | + } | |
| 1131 | + return is_network_admin() ? 'network' === $admin : 'site' === $admin; | |
| 1132 | +} | |