PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
← All changes | includes/window-chrome.php +244 -234 0.9.01.1.10 View file →
@@ -5,71 +5,68 @@
5 5 * Mirrors the commands / settings-tabs / title-bar-buttons registration
6 6 * pattern across four surfaces:
7 7 *
8 8 * - **Themes** (Layer 1) — per-window CSS-variable maps.
9 - * `desktop_mode_register_window_theme_script()` /
10 - * `desktop_mode_register_window_theme()`.
9 + * `openstation_register_window_theme_script()` /
10 + * `openstation_register_window_theme()`.
11 11 *
12 12 * - **Controls** (Layer 2) — title-bar buttons (close / minimize /
13 13 * maximize plus plugin custom controls).
14 - * `desktop_mode_register_window_control_script()` /
15 - * `desktop_mode_register_window_control()`.
14 + * `openstation_register_window_control_script()` /
15 + * `openstation_register_window_control()`.
16 16 *
17 17 * - **Slots** (Layer 3) — named title-bar regions plugins can
18 18 * replace (icon, title, before-controls, …).
19 - * `desktop_mode_register_window_slot_script()` /
20 - * `desktop_mode_register_window_slot()`.
19 + * `openstation_register_window_slot_script()` /
20 + * `openstation_register_window_slot()`.
21 21 *
22 22 * - **Chrome** (Layer 4, Experimental) — full title-bar render
23 23 * replacement.
24 - * `desktop_mode_register_window_chrome_script()` /
25 - * `desktop_mode_register_window_chrome()`.
24 + * `openstation_register_window_chrome_script()` /
25 + * `openstation_register_window_chrome()`.
26 26 *
27 27 * Each surface contributes a `serverWindow*Scripts` and (optionally)
28 28 * `serverWindow*` array to the shell payload, consumed by the matching
29 29 * sync module under `src/window-chrome/{themes,controls,slots,chrome}/server-sync.ts`.
30 30 *
31 - * @since 0.6.0
32 - * @package WPDesktopMode
31 + * @package OpenStation
33 32 */
34 33
35 34 defined( 'ABSPATH' ) || exit;
36 35
37 -/* ============================================================
36 +/*
37 +============================================================
38 38 * Layer 1 — Themes
39 - * ============================================================ */
39 + * ============================================================
40 + */
40 41
41 42 /**
42 43 * Declare a WP-registered script handle as a window-theme provider.
43 44 *
44 - * The script's JS calls `wp.desktop.registerWindowTheme( { id, tokens,
45 + * The script's JS calls `wp.os.registerWindowTheme( { id, tokens,
45 46 * match, owner } )` as usual. Plugins that pass `owner` matching this
46 47 * handle get live unregister on deactivation.
47 48 *
48 - * @since 0.6.0
49 - *
50 49 * @param string $handle WP-registered script handle.
51 50 * @return true|WP_Error `true` on success; `WP_Error` on validation failure.
52 51 */
53 -function desktop_mode_register_window_theme_script( $handle ) {
52 +function openstation_register_window_theme_script( $handle ) {
54 53 $handle = (string) $handle;
55 54 if ( '' === $handle ) {
56 - return desktop_mode_registration_error(
57 - 'desktop_mode_missing_handle',
55 + return openstation_registration_error(
56 + 'openstation_missing_handle',
58 57 __( 'Window theme script registration requires a non-empty script handle.', 'desktop-mode' )
59 58 );
60 59 }
61 60
62 - desktop_mode_window_theme_script_registry( $handle, true );
61 + openstation_window_theme_script_registry( $handle, true );
63 62
64 63 /**
65 64 * Fires after a desktop window-theme script handle is registered.
66 65 *
67 - * @since 0.6.0
68 - *
69 66 * @param string $handle The registered script handle.
70 67 */
71 - do_action( 'desktop_mode_window_theme_script_registered', $handle );
68 + do_action( 'openstation_window_theme_script_registered', $handle );
72 69
73 70 return true;
74 71 }
75 72
@@ -74,14 +71,12 @@
74 71 }
75 72
76 73 /**
77 74 * Declare a window theme server-side. Optional companion to
78 - * `desktop_mode_register_window_theme_script()` for plugins that want
75 + * `openstation_register_window_theme_script()` for plugins that want
79 76 * to ship a tokens map without writing JS — designers can hand off
80 77 * a single PHP-array of CSS variables and call it done.
81 78 *
82 - * @since 0.6.0
83 - *
84 79 * @param array $args {
85 80 * @type string $id Unique theme id (`vendor/sub-id`). Required.
86 81 * @type string $label Human-readable label. Default empty.
87 82 * @type array $tokens CSS-variable map (keys must start with `--`). Required.
@@ -89,9 +84,9 @@
89 84 * @type string $script Optional script handle (also registers it).
90 85 * }
91 86 * @return true|WP_Error
92 87 */
93 -function desktop_mode_register_window_theme( $args = array() ) {
88 +function openstation_register_window_theme( $args = array() ) {
94 89 $defaults = array(
95 90 'id' => '',
96 91 'label' => '',
97 92 'tokens' => array(),
@@ -97,20 +92,20 @@
97 92 'tokens' => array(),
98 93 'priority' => 100,
99 94 'script' => '',
100 95 );
101 - $args = wp_parse_args( $args, $defaults );
96 + $args = wp_parse_args( $args, $defaults );
102 97
103 98 $id = (string) $args['id'];
104 99 if ( '' === $id ) {
105 - return desktop_mode_registration_error(
106 - 'desktop_mode_missing_id',
100 + return openstation_registration_error(
101 + 'openstation_missing_id',
107 102 __( 'Window theme registration requires a non-empty `id`.', 'desktop-mode' )
108 103 );
109 104 }
110 105 if ( ! is_array( $args['tokens'] ) || empty( $args['tokens'] ) ) {
111 - return desktop_mode_registration_error(
112 - 'desktop_mode_missing_tokens',
106 + return openstation_registration_error(
107 + 'openstation_missing_tokens',
113 108 __( 'Window theme registration requires a non-empty `tokens` map.', 'desktop-mode' ),
114 109 array( 'id' => $id )
115 110 );
116 111 }
@@ -117,10 +112,10 @@
117 112 $tokens = array();
118 113 foreach ( $args['tokens'] as $key => $value ) {
119 114 $key = (string) $key;
120 115 if ( '' === $key || 0 !== strpos( $key, '--' ) ) {
121 - return desktop_mode_registration_error(
122 - 'desktop_mode_invalid_token',
116 + return openstation_registration_error(
117 + 'openstation_invalid_token',
123 118 __( 'Window theme tokens must use CSS custom-property keys (start with "--").', 'desktop-mode' ),
124 119 array(
125 120 'id' => $id,
126 121 'key' => $key,
@@ -136,23 +131,21 @@
136 131 'tokens' => $tokens,
137 132 'priority' => (int) $args['priority'],
138 133 'script' => (string) $args['script'],
139 134 );
140 - desktop_mode_window_theme_registry( $id, $entry );
135 + openstation_window_theme_registry( $id, $entry );
141 136
142 137 if ( '' !== $entry['script'] ) {
143 - desktop_mode_window_theme_script_registry( $entry['script'], true );
138 + openstation_window_theme_script_registry( $entry['script'], true );
144 139 }
145 140
146 141 /**
147 142 * Fires after a desktop window-theme is successfully registered.
148 143 *
149 - * @since 0.6.0
150 - *
151 144 * @param string $id The theme id.
152 145 * @param array $entry The stored registry entry.
153 146 */
154 - do_action( 'desktop_mode_window_theme_registered', $id, $entry );
147 + do_action( 'openstation_window_theme_registered', $id, $entry );
155 148
156 149 return true;
157 150 }
158 151
@@ -158,9 +151,8 @@
158 151
159 152 /**
160 153 * Internal module-level registry for theme script handles.
161 154 *
162 - * @since 0.6.0
163 155 * @internal
164 156 *
165 157 * @param string $handle Script handle to read or write.
166 158 * @param bool|null $value Pass `true` to register; `null` to read only.
@@ -165,9 +157,9 @@
165 157 * @param string $handle Script handle to read or write.
166 158 * @param bool|null $value Pass `true` to register; `null` to read only.
167 159 * @return array|bool When called with no args returns the full store.
168 160 */
169 -function desktop_mode_window_theme_script_registry( $handle = '', $value = null ) {
161 +function openstation_window_theme_script_registry( $handle = '', $value = null ) {
170 162 static $store = array();
171 163
172 164 if ( '__flush__' === (string) $handle ) {
173 165 $store = array();
@@ -181,17 +173,16 @@
181 173 }
182 174 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
183 175 }
184 176
185 -/** Flush the theme-script registry. Tests only. @since 0.6.0 */
186 -function desktop_mode_flush_window_theme_script_registry() {
187 - desktop_mode_window_theme_script_registry( '__flush__' );
177 +/** Flush the theme-script registry. Tests only. */
178 +function openstation_flush_window_theme_script_registry() {
179 + openstation_window_theme_script_registry( '__flush__' );
188 180 }
189 181
190 182 /**
191 183 * Internal module-level registry for window themes.
192 184 *
193 - * @since 0.6.0
194 185 * @internal
195 186 *
196 187 * @param string $id Theme id to read or write.
197 188 * @param array|null $entry Entry to store, or `null` to read.
@@ -196,9 +187,9 @@
196 187 * @param string $id Theme id to read or write.
197 188 * @param array|null $entry Entry to store, or `null` to read.
198 189 * @return array|null
199 190 */
200 -function desktop_mode_window_theme_registry( $id = '', $entry = null ) {
191 +function openstation_window_theme_registry( $id = '', $entry = null ) {
201 192 static $store = array();
202 193
203 194 if ( '__flush__' === (string) $id ) {
204 195 $store = array();
@@ -212,23 +203,21 @@
212 203 }
213 204 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
214 205 }
215 206
216 -/** Flush the theme registry. Tests only. @since 0.6.0 */
217 -function desktop_mode_flush_window_theme_registry() {
218 - desktop_mode_window_theme_registry( '__flush__' );
207 +/** Flush the theme registry. Tests only. */
208 +function openstation_flush_window_theme_registry() {
209 + openstation_window_theme_registry( '__flush__' );
219 210 }
220 211
221 212 /**
222 213 * Build the theme-script payload. Same shape as
223 - * `desktop_mode_build_desktop_command_scripts_payload()`.
214 + * `openstation_build_desktop_command_scripts_payload()`.
224 215 *
225 - * @since 0.6.0
226 - *
227 216 * @return array[] List of `{ handle, scriptUrl }` entries.
228 217 */
229 -function desktop_mode_build_window_theme_scripts_payload() {
230 - $registry = desktop_mode_window_theme_script_registry();
218 +function openstation_build_window_theme_scripts_payload() {
219 + $registry = openstation_window_theme_script_registry();
231 220 if ( ! is_array( $registry ) || empty( $registry ) ) {
232 221 return array();
233 222 }
234 223
@@ -237,12 +226,12 @@
237 226 foreach ( $registry as $handle => $active ) {
238 227 if ( ! $active || isset( $seen[ $handle ] ) ) {
239 228 continue;
240 229 }
241 - $payload = desktop_mode_resolve_script_payload( $handle );
230 + $payload = openstation_resolve_script_payload( $handle );
242 231 if ( '' === $payload['url'] ) {
243 - desktop_mode_warn_unresolvable_script_handle(
244 - 'desktop_mode_register_window_theme_script',
232 + openstation_warn_unresolvable_script_handle(
233 + 'openstation_register_window_theme_script',
245 234 'Window theme',
246 235 (string) $handle
247 236 );
248 237 continue;
@@ -253,8 +242,11 @@
253 242 'scriptBefore' => $payload['before'],
254 243 'scriptAfter' => $payload['after'],
255 244 'scriptL10n' => $payload['l10n'],
256 245 'scriptTranslations' => $payload['translations'],
246 + // The handle's dependency closure, replayed before the bundle
247 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
248 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
257 249 );
258 250 $seen[ $handle ] = true;
259 251 }
260 252 return $out;
@@ -263,14 +255,12 @@
263 255 /**
264 256 * Build the theme-metadata payload. Resolves the optional companion
265 257 * script handle for each entry.
266 258 *
267 - * @since 0.6.0
268 - *
269 259 * @return array[]
270 260 */
271 -function desktop_mode_build_window_themes_payload() {
272 - $registry = desktop_mode_window_theme_registry();
261 +function openstation_build_window_themes_payload() {
262 + $registry = openstation_window_theme_registry();
273 263 if ( ! is_array( $registry ) || empty( $registry ) ) {
274 264 return array();
275 265 }
276 266
@@ -277,57 +267,64 @@
277 267 $out = array();
278 268 foreach ( $registry as $entry ) {
279 269 $handle = (string) $entry['script'];
280 270 $payload = '' !== $handle
281 - ? desktop_mode_resolve_script_payload( $handle )
282 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
283 - $out[] = array(
284 - 'id' => (string) $entry['id'],
285 - 'label' => (string) $entry['label'],
286 - 'tokens' => (array) $entry['tokens'],
287 - 'priority' => (int) $entry['priority'],
288 - 'scriptUrl' => $payload['url'],
289 - 'scriptHandle' => $handle,
290 - 'scriptBefore' => $payload['before'],
291 - 'scriptAfter' => $payload['after'],
292 - 'scriptL10n' => $payload['l10n'],
271 + ? openstation_resolve_script_payload( $handle )
272 + : array(
273 + 'url' => '',
274 + 'before' => array(),
275 + 'after' => array(),
276 + 'l10n' => array(),
277 + 'translations' => '',
278 + );
279 + $out[] = array(
280 + 'id' => (string) $entry['id'],
281 + 'label' => (string) $entry['label'],
282 + 'tokens' => (array) $entry['tokens'],
283 + 'priority' => (int) $entry['priority'],
284 + 'scriptUrl' => $payload['url'],
285 + 'scriptHandle' => $handle,
286 + 'scriptBefore' => $payload['before'],
287 + 'scriptAfter' => $payload['after'],
288 + 'scriptL10n' => $payload['l10n'],
293 289 'scriptTranslations' => $payload['translations'],
290 + // The handle's dependency closure, replayed before the bundle
291 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
292 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
294 293 );
295 294 }
296 295 return $out;
297 296 }
298 297
299 -/* ============================================================
298 +/*
299 +============================================================
300 300 * Layer 2 — Controls
301 - * ============================================================ */
301 + * ============================================================
302 + */
302 303
303 304 /**
304 305 * Declare a WP-registered script handle as a window-control provider.
305 306 *
306 - * @since 0.6.0
307 - *
308 307 * @param string $handle WP-registered script handle.
309 308 * @return true|WP_Error
310 309 */
311 -function desktop_mode_register_window_control_script( $handle ) {
310 +function openstation_register_window_control_script( $handle ) {
312 311 $handle = (string) $handle;
313 312 if ( '' === $handle ) {
314 - return desktop_mode_registration_error(
315 - 'desktop_mode_missing_handle',
313 + return openstation_registration_error(
314 + 'openstation_missing_handle',
316 315 __( 'Window control script registration requires a non-empty script handle.', 'desktop-mode' )
317 316 );
318 317 }
319 318
320 - desktop_mode_window_control_script_registry( $handle, true );
319 + openstation_window_control_script_registry( $handle, true );
321 320
322 321 /**
323 322 * Fires after a window-control script handle is registered.
324 323 *
325 - * @since 0.6.0
326 - *
327 324 * @param string $handle The registered script handle.
328 325 */
329 - do_action( 'desktop_mode_window_control_script_registered', $handle );
326 + do_action( 'openstation_window_control_script_registered', $handle );
330 327
331 328 return true;
332 329 }
333 330
@@ -334,10 +331,8 @@
334 331 /**
335 332 * Declare a window control server-side. The control's `onClick` /
336 333 * `render` callback always lives JS-side.
337 334 *
338 - * @since 0.6.0
339 - *
340 335 * @param array $args {
341 336 * @type string $id Required, `vendor/sub-id`.
342 337 * @type string $label Required.
343 338 * @type string $icon Dashicons class / built-in key / SVG.
@@ -346,9 +341,9 @@
346 341 * @type string $script Optional companion script handle.
347 342 * }
348 343 * @return true|WP_Error
349 344 */
350 -function desktop_mode_register_window_control( $args = array() ) {
345 +function openstation_register_window_control( $args = array() ) {
351 346 $defaults = array(
352 347 'id' => '',
353 348 'label' => '',
354 349 'icon' => '',
@@ -355,20 +350,20 @@
355 350 'placement' => 'left',
356 351 'order' => 100,
357 352 'script' => '',
358 353 );
359 - $args = wp_parse_args( $args, $defaults );
354 + $args = wp_parse_args( $args, $defaults );
360 355
361 356 $id = (string) $args['id'];
362 357 if ( '' === $id ) {
363 - return desktop_mode_registration_error(
364 - 'desktop_mode_missing_id',
358 + return openstation_registration_error(
359 + 'openstation_missing_id',
365 360 __( 'Window control registration requires a non-empty `id`.', 'desktop-mode' )
366 361 );
367 362 }
368 363 if ( '' === (string) $args['label'] ) {
369 - return desktop_mode_registration_error(
370 - 'desktop_mode_missing_label',
364 + return openstation_registration_error(
365 + 'openstation_missing_label',
371 366 __( 'Window control registration requires a non-empty `label`.', 'desktop-mode' ),
372 367 array( 'id' => $id )
373 368 );
374 369 }
@@ -373,10 +368,10 @@
373 368 );
374 369 }
375 370 $placement = (string) $args['placement'];
376 371 if ( ! in_array( $placement, array( 'left', 'right', 'controls' ), true ) ) {
377 - return desktop_mode_registration_error(
378 - 'desktop_mode_invalid_placement',
372 + return openstation_registration_error(
373 + 'openstation_invalid_placement',
379 374 __( 'Window control `placement` must be one of "left", "right", "controls".', 'desktop-mode' ),
380 375 array(
381 376 'id' => $id,
382 377 'placement' => $placement,
@@ -391,29 +386,27 @@
391 386 'placement' => $placement,
392 387 'order' => (int) $args['order'],
393 388 'script' => (string) $args['script'],
394 389 );
395 - desktop_mode_window_control_registry( $id, $entry );
390 + openstation_window_control_registry( $id, $entry );
396 391
397 392 if ( '' !== $entry['script'] ) {
398 - desktop_mode_window_control_script_registry( $entry['script'], true );
393 + openstation_window_control_script_registry( $entry['script'], true );
399 394 }
400 395
401 396 /**
402 397 * Fires after a window-control is successfully registered.
403 398 *
404 - * @since 0.6.0
405 - *
406 399 * @param string $id The control id.
407 400 * @param array $entry The stored registry entry.
408 401 */
409 - do_action( 'desktop_mode_window_control_registered', $id, $entry );
402 + do_action( 'openstation_window_control_registered', $id, $entry );
410 403
411 404 return true;
412 405 }
413 406
414 407 /** @internal */
415 -function desktop_mode_window_control_script_registry( $handle = '', $value = null ) {
408 +function openstation_window_control_script_registry( $handle = '', $value = null ) {
416 409 static $store = array();
417 410
418 411 if ( '__flush__' === (string) $handle ) {
419 412 $store = array();
@@ -427,15 +420,15 @@
427 420 }
428 421 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
429 422 }
430 423
431 -/** Tests only. @since 0.6.0 */
432 -function desktop_mode_flush_window_control_script_registry() {
433 - desktop_mode_window_control_script_registry( '__flush__' );
424 +/** Tests only. */
425 +function openstation_flush_window_control_script_registry() {
426 + openstation_window_control_script_registry( '__flush__' );
434 427 }
435 428
436 429 /** @internal */
437 -function desktop_mode_window_control_registry( $id = '', $entry = null ) {
430 +function openstation_window_control_registry( $id = '', $entry = null ) {
438 431 static $store = array();
439 432
440 433 if ( '__flush__' === (string) $id ) {
441 434 $store = array();
@@ -449,19 +442,18 @@
449 442 }
450 443 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
451 444 }
452 445
453 -/** Tests only. @since 0.6.0 */
454 -function desktop_mode_flush_window_control_registry() {
455 - desktop_mode_window_control_registry( '__flush__' );
446 +/** Tests only. */
447 +function openstation_flush_window_control_registry() {
448 + openstation_window_control_registry( '__flush__' );
456 449 }
457 450
458 451 /**
459 - * @since 0.6.0
460 452 * @return array[] List of `{ handle, scriptUrl }` entries.
461 453 */
462 -function desktop_mode_build_window_control_scripts_payload() {
463 - $registry = desktop_mode_window_control_script_registry();
454 +function openstation_build_window_control_scripts_payload() {
455 + $registry = openstation_window_control_script_registry();
464 456 if ( ! is_array( $registry ) || empty( $registry ) ) {
465 457 return array();
466 458 }
467 459
@@ -470,12 +462,12 @@
470 462 foreach ( $registry as $handle => $active ) {
471 463 if ( ! $active || isset( $seen[ $handle ] ) ) {
472 464 continue;
473 465 }
474 - $payload = desktop_mode_resolve_script_payload( $handle );
466 + $payload = openstation_resolve_script_payload( $handle );
475 467 if ( '' === $payload['url'] ) {
476 - desktop_mode_warn_unresolvable_script_handle(
477 - 'desktop_mode_register_window_control_script',
468 + openstation_warn_unresolvable_script_handle(
469 + 'openstation_register_window_control_script',
478 470 'Window control',
479 471 (string) $handle
480 472 );
481 473 continue;
@@ -486,8 +478,11 @@
486 478 'scriptBefore' => $payload['before'],
487 479 'scriptAfter' => $payload['after'],
488 480 'scriptL10n' => $payload['l10n'],
489 481 'scriptTranslations' => $payload['translations'],
482 + // The handle's dependency closure, replayed before the bundle
483 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
484 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
490 485 );
491 486 $seen[ $handle ] = true;
492 487 }
493 488 return $out;
@@ -493,13 +488,12 @@
493 488 return $out;
494 489 }
495 490
496 491 /**
497 - * @since 0.6.0
498 492 * @return array[]
499 493 */
500 -function desktop_mode_build_window_controls_payload() {
501 - $registry = desktop_mode_window_control_registry();
494 +function openstation_build_window_controls_payload() {
495 + $registry = openstation_window_control_registry();
502 496 if ( ! is_array( $registry ) || empty( $registry ) ) {
503 497 return array();
504 498 }
505 499
@@ -506,40 +500,49 @@
506 500 $out = array();
507 501 foreach ( $registry as $entry ) {
508 502 $handle = (string) $entry['script'];
509 503 $payload = '' !== $handle
510 - ? desktop_mode_resolve_script_payload( $handle )
511 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
512 - $out[] = array(
513 - 'id' => (string) $entry['id'],
514 - 'label' => (string) $entry['label'],
515 - 'icon' => (string) $entry['icon'],
516 - 'placement' => (string) $entry['placement'],
517 - 'order' => (int) $entry['order'],
518 - 'scriptUrl' => $payload['url'],
519 - 'scriptHandle' => $handle,
520 - 'scriptBefore' => $payload['before'],
521 - 'scriptAfter' => $payload['after'],
522 - 'scriptL10n' => $payload['l10n'],
504 + ? openstation_resolve_script_payload( $handle )
505 + : array(
506 + 'url' => '',
507 + 'before' => array(),
508 + 'after' => array(),
509 + 'l10n' => array(),
510 + 'translations' => '',
511 + );
512 + $out[] = array(
513 + 'id' => (string) $entry['id'],
514 + 'label' => (string) $entry['label'],
515 + 'icon' => (string) $entry['icon'],
516 + 'placement' => (string) $entry['placement'],
517 + 'order' => (int) $entry['order'],
518 + 'scriptUrl' => $payload['url'],
519 + 'scriptHandle' => $handle,
520 + 'scriptBefore' => $payload['before'],
521 + 'scriptAfter' => $payload['after'],
522 + 'scriptL10n' => $payload['l10n'],
523 523 'scriptTranslations' => $payload['translations'],
524 + // The handle's dependency closure, replayed before the bundle
525 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
526 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
524 527 );
525 528 }
526 529 return $out;
527 530 }
528 531
529 -/* ============================================================
532 +/*
533 +============================================================
530 534 * Layer 3 — Slots
531 - * ============================================================ */
535 + * ============================================================
536 + */
532 537
533 538 /**
534 539 * Canonical slot names. Mirrors the `WindowSlotName` TypeScript
535 540 * union in `src/types.ts`.
536 541 *
537 - * @since 0.6.0
538 - *
539 542 * @return string[]
540 543 */
541 -function desktop_mode_window_slot_names() {
544 +function openstation_window_slot_names() {
542 545 return array(
543 546 'before-titlebar',
544 547 'before-icon',
545 548 'icon',
@@ -552,47 +555,42 @@
552 555 );
553 556 }
554 557
555 558 /**
556 - * @since 0.6.0
557 559 * @param string $handle WP-registered script handle.
558 560 * @return true|WP_Error
559 561 */
560 -function desktop_mode_register_window_slot_script( $handle ) {
562 +function openstation_register_window_slot_script( $handle ) {
561 563 $handle = (string) $handle;
562 564 if ( '' === $handle ) {
563 - return desktop_mode_registration_error(
564 - 'desktop_mode_missing_handle',
565 + return openstation_registration_error(
566 + 'openstation_missing_handle',
565 567 __( 'Window slot script registration requires a non-empty script handle.', 'desktop-mode' )
566 568 );
567 569 }
568 570
569 - desktop_mode_window_slot_script_registry( $handle, true );
571 + openstation_window_slot_script_registry( $handle, true );
570 572
571 573 /**
572 574 * Fires after a window-slot script handle is registered.
573 575 *
574 - * @since 0.6.0
575 - *
576 576 * @param string $handle The registered script handle.
577 577 */
578 - do_action( 'desktop_mode_window_slot_script_registered', $handle );
578 + do_action( 'openstation_window_slot_script_registered', $handle );
579 579
580 580 return true;
581 581 }
582 582
583 583 /**
584 - * @since 0.6.0
585 - *
586 584 * @param array $args {
587 585 * @type string $id Required.
588 - * @type string $slot Required, one of {@see desktop_mode_window_slot_names()}.
586 + * @type string $slot Required, one of {@see openstation_window_slot_names()}.
589 587 * @type int $order Default 100.
590 588 * @type string $script Optional script handle.
591 589 * }
592 590 * @return true|WP_Error
593 591 */
594 -function desktop_mode_register_window_slot( $args = array() ) {
592 +function openstation_register_window_slot( $args = array() ) {
595 593 $defaults = array(
596 594 'id' => '',
597 595 'slot' => '',
598 596 'order' => 100,
@@ -597,21 +595,21 @@
597 595 'slot' => '',
598 596 'order' => 100,
599 597 'script' => '',
600 598 );
601 - $args = wp_parse_args( $args, $defaults );
599 + $args = wp_parse_args( $args, $defaults );
602 600
603 601 $id = (string) $args['id'];
604 602 if ( '' === $id ) {
605 - return desktop_mode_registration_error(
606 - 'desktop_mode_missing_id',
603 + return openstation_registration_error(
604 + 'openstation_missing_id',
607 605 __( 'Window slot registration requires a non-empty `id`.', 'desktop-mode' )
608 606 );
609 607 }
610 608 $slot = (string) $args['slot'];
611 - if ( ! in_array( $slot, desktop_mode_window_slot_names(), true ) ) {
612 - return desktop_mode_registration_error(
613 - 'desktop_mode_invalid_slot',
609 + if ( ! in_array( $slot, openstation_window_slot_names(), true ) ) {
610 + return openstation_registration_error(
611 + 'openstation_invalid_slot',
614 612 __( 'Window slot registration requires a known `slot` name.', 'desktop-mode' ),
615 613 array(
616 614 'id' => $id,
617 615 'slot' => $slot,
@@ -624,29 +622,27 @@
624 622 'slot' => $slot,
625 623 'order' => (int) $args['order'],
626 624 'script' => (string) $args['script'],
627 625 );
628 - desktop_mode_window_slot_registry( $id, $entry );
626 + openstation_window_slot_registry( $id, $entry );
629 627
630 628 if ( '' !== $entry['script'] ) {
631 - desktop_mode_window_slot_script_registry( $entry['script'], true );
629 + openstation_window_slot_script_registry( $entry['script'], true );
632 630 }
633 631
634 632 /**
635 633 * Fires after a window-slot is successfully registered.
636 634 *
637 - * @since 0.6.0
638 - *
639 635 * @param string $id The slot-renderer id.
640 636 * @param array $entry The stored registry entry.
641 637 */
642 - do_action( 'desktop_mode_window_slot_registered', $id, $entry );
638 + do_action( 'openstation_window_slot_registered', $id, $entry );
643 639
644 640 return true;
645 641 }
646 642
647 643 /** @internal */
648 -function desktop_mode_window_slot_script_registry( $handle = '', $value = null ) {
644 +function openstation_window_slot_script_registry( $handle = '', $value = null ) {
649 645 static $store = array();
650 646
651 647 if ( '__flush__' === (string) $handle ) {
652 648 $store = array();
@@ -660,15 +656,15 @@
660 656 }
661 657 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
662 658 }
663 659
664 -/** Tests only. @since 0.6.0 */
665 -function desktop_mode_flush_window_slot_script_registry() {
666 - desktop_mode_window_slot_script_registry( '__flush__' );
660 +/** Tests only. */
661 +function openstation_flush_window_slot_script_registry() {
662 + openstation_window_slot_script_registry( '__flush__' );
667 663 }
668 664
669 665 /** @internal */
670 -function desktop_mode_window_slot_registry( $id = '', $entry = null ) {
666 +function openstation_window_slot_registry( $id = '', $entry = null ) {
671 667 static $store = array();
672 668
673 669 if ( '__flush__' === (string) $id ) {
674 670 $store = array();
@@ -682,19 +678,18 @@
682 678 }
683 679 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
684 680 }
685 681
686 -/** Tests only. @since 0.6.0 */
687 -function desktop_mode_flush_window_slot_registry() {
688 - desktop_mode_window_slot_registry( '__flush__' );
682 +/** Tests only. */
683 +function openstation_flush_window_slot_registry() {
684 + openstation_window_slot_registry( '__flush__' );
689 685 }
690 686
691 687 /**
692 - * @since 0.6.0
693 688 * @return array[] List of `{ handle, scriptUrl }` entries.
694 689 */
695 -function desktop_mode_build_window_slot_scripts_payload() {
696 - $registry = desktop_mode_window_slot_script_registry();
690 +function openstation_build_window_slot_scripts_payload() {
691 + $registry = openstation_window_slot_script_registry();
697 692 if ( ! is_array( $registry ) || empty( $registry ) ) {
698 693 return array();
699 694 }
700 695
@@ -703,12 +698,12 @@
703 698 foreach ( $registry as $handle => $active ) {
704 699 if ( ! $active || isset( $seen[ $handle ] ) ) {
705 700 continue;
706 701 }
707 - $payload = desktop_mode_resolve_script_payload( $handle );
702 + $payload = openstation_resolve_script_payload( $handle );
708 703 if ( '' === $payload['url'] ) {
709 - desktop_mode_warn_unresolvable_script_handle(
710 - 'desktop_mode_register_window_slot_script',
704 + openstation_warn_unresolvable_script_handle(
705 + 'openstation_register_window_slot_script',
711 706 'Window slot',
712 707 (string) $handle
713 708 );
714 709 continue;
@@ -719,8 +714,11 @@
719 714 'scriptBefore' => $payload['before'],
720 715 'scriptAfter' => $payload['after'],
721 716 'scriptL10n' => $payload['l10n'],
722 717 'scriptTranslations' => $payload['translations'],
718 + // The handle's dependency closure, replayed before the bundle
719 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
720 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
723 721 );
724 722 $seen[ $handle ] = true;
725 723 }
726 724 return $out;
@@ -726,13 +724,12 @@
726 724 return $out;
727 725 }
728 726
729 727 /**
730 - * @since 0.6.0
731 728 * @return array[]
732 729 */
733 -function desktop_mode_build_window_slots_payload() {
734 - $registry = desktop_mode_window_slot_registry();
730 +function openstation_build_window_slots_payload() {
731 + $registry = openstation_window_slot_registry();
735 732 if ( ! is_array( $registry ) || empty( $registry ) ) {
736 733 return array();
737 734 }
738 735
@@ -739,58 +736,65 @@
739 736 $out = array();
740 737 foreach ( $registry as $entry ) {
741 738 $handle = (string) $entry['script'];
742 739 $payload = '' !== $handle
743 - ? desktop_mode_resolve_script_payload( $handle )
744 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
745 - $out[] = array(
746 - 'id' => (string) $entry['id'],
747 - 'slot' => (string) $entry['slot'],
748 - 'order' => (int) $entry['order'],
749 - 'scriptUrl' => $payload['url'],
750 - 'scriptHandle' => $handle,
751 - 'scriptBefore' => $payload['before'],
752 - 'scriptAfter' => $payload['after'],
753 - 'scriptL10n' => $payload['l10n'],
740 + ? openstation_resolve_script_payload( $handle )
741 + : array(
742 + 'url' => '',
743 + 'before' => array(),
744 + 'after' => array(),
745 + 'l10n' => array(),
746 + 'translations' => '',
747 + );
748 + $out[] = array(
749 + 'id' => (string) $entry['id'],
750 + 'slot' => (string) $entry['slot'],
751 + 'order' => (int) $entry['order'],
752 + 'scriptUrl' => $payload['url'],
753 + 'scriptHandle' => $handle,
754 + 'scriptBefore' => $payload['before'],
755 + 'scriptAfter' => $payload['after'],
756 + 'scriptL10n' => $payload['l10n'],
754 757 'scriptTranslations' => $payload['translations'],
758 + // The handle's dependency closure, replayed before the bundle
759 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
760 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
755 761 );
756 762 }
757 763 return $out;
758 764 }
759 765
760 -/* ============================================================
766 +/*
767 +============================================================
761 768 * Layer 4 — Custom chrome (Experimental)
762 - * ============================================================ */
769 + * ============================================================
770 + */
763 771
764 772 /**
765 773 * Declare a WP-registered script handle as a window-chrome provider.
766 774 *
767 - * **Experimental** since 0.6.0 — chrome render contract may change.
775 + * **Experimental** — chrome render contract may change.
768 776 *
769 - * @since 0.6.0
770 - *
771 777 * @param string $handle WP-registered script handle.
772 778 * @return true|WP_Error
773 779 */
774 -function desktop_mode_register_window_chrome_script( $handle ) {
780 +function openstation_register_window_chrome_script( $handle ) {
775 781 $handle = (string) $handle;
776 782 if ( '' === $handle ) {
777 - return desktop_mode_registration_error(
778 - 'desktop_mode_missing_handle',
783 + return openstation_registration_error(
784 + 'openstation_missing_handle',
779 785 __( 'Window chrome script registration requires a non-empty script handle.', 'desktop-mode' )
780 786 );
781 787 }
782 788
783 - desktop_mode_window_chrome_script_registry( $handle, true );
789 + openstation_window_chrome_script_registry( $handle, true );
784 790
785 791 /**
786 792 * Fires after a window-chrome script handle is registered.
787 793 *
788 - * @since 0.6.0
789 - *
790 794 * @param string $handle The registered script handle.
791 795 */
792 - do_action( 'desktop_mode_window_chrome_script_registered', $handle );
796 + do_action( 'openstation_window_chrome_script_registered', $handle );
793 797
794 798 return true;
795 799 }
796 800
@@ -797,10 +801,8 @@
797 801 /**
798 802 * Declare a custom chrome server-side. **Experimental** — chrome
799 803 * render contract may change.
800 804 *
801 - * @since 0.6.0
802 - *
803 805 * @param array $args {
804 806 * @type string $id Required.
805 807 * @type string $label Default empty.
806 808 * @type string $script Optional script handle.
@@ -806,20 +808,20 @@
806 808 * @type string $script Optional script handle.
807 809 * }
808 810 * @return true|WP_Error
809 811 */
810 -function desktop_mode_register_window_chrome( $args = array() ) {
812 +function openstation_register_window_chrome( $args = array() ) {
811 813 $defaults = array(
812 814 'id' => '',
813 815 'label' => '',
814 816 'script' => '',
815 817 );
816 - $args = wp_parse_args( $args, $defaults );
818 + $args = wp_parse_args( $args, $defaults );
817 819
818 820 $id = (string) $args['id'];
819 821 if ( '' === $id ) {
820 - return desktop_mode_registration_error(
821 - 'desktop_mode_missing_id',
822 + return openstation_registration_error(
823 + 'openstation_missing_id',
822 824 __( 'Window chrome registration requires a non-empty `id`.', 'desktop-mode' )
823 825 );
824 826 }
825 827
@@ -827,29 +829,27 @@
827 829 'id' => $id,
828 830 'label' => (string) $args['label'],
829 831 'script' => (string) $args['script'],
830 832 );
831 - desktop_mode_window_chrome_registry( $id, $entry );
833 + openstation_window_chrome_registry( $id, $entry );
832 834
833 835 if ( '' !== $entry['script'] ) {
834 - desktop_mode_window_chrome_script_registry( $entry['script'], true );
836 + openstation_window_chrome_script_registry( $entry['script'], true );
835 837 }
836 838
837 839 /**
838 840 * Fires after a window-chrome is successfully registered.
839 841 *
840 - * @since 0.6.0
841 - *
842 842 * @param string $id The chrome id.
843 843 * @param array $entry The stored registry entry.
844 844 */
845 - do_action( 'desktop_mode_window_chrome_registered', $id, $entry );
845 + do_action( 'openstation_window_chrome_registered', $id, $entry );
846 846
847 847 return true;
848 848 }
849 849
850 850 /** @internal */
851 -function desktop_mode_window_chrome_script_registry( $handle = '', $value = null ) {
851 +function openstation_window_chrome_script_registry( $handle = '', $value = null ) {
852 852 static $store = array();
853 853
854 854 if ( '__flush__' === (string) $handle ) {
855 855 $store = array();
@@ -863,15 +863,15 @@
863 863 }
864 864 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
865 865 }
866 866
867 -/** Tests only. @since 0.6.0 */
868 -function desktop_mode_flush_window_chrome_script_registry() {
869 - desktop_mode_window_chrome_script_registry( '__flush__' );
867 +/** Tests only. */
868 +function openstation_flush_window_chrome_script_registry() {
869 + openstation_window_chrome_script_registry( '__flush__' );
870 870 }
871 871
872 872 /** @internal */
873 -function desktop_mode_window_chrome_registry( $id = '', $entry = null ) {
873 +function openstation_window_chrome_registry( $id = '', $entry = null ) {
874 874 static $store = array();
875 875
876 876 if ( '__flush__' === (string) $id ) {
877 877 $store = array();
@@ -885,19 +885,18 @@
885 885 }
886 886 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
887 887 }
888 888
889 -/** Tests only. @since 0.6.0 */
890 -function desktop_mode_flush_window_chrome_registry() {
891 - desktop_mode_window_chrome_registry( '__flush__' );
889 +/** Tests only. */
890 +function openstation_flush_window_chrome_registry() {
891 + openstation_window_chrome_registry( '__flush__' );
892 892 }
893 893
894 894 /**
895 - * @since 0.6.0
896 895 * @return array[] List of `{ handle, scriptUrl }` entries.
897 896 */
898 -function desktop_mode_build_window_chrome_scripts_payload() {
899 - $registry = desktop_mode_window_chrome_script_registry();
897 +function openstation_build_window_chrome_scripts_payload() {
898 + $registry = openstation_window_chrome_script_registry();
900 899 if ( ! is_array( $registry ) || empty( $registry ) ) {
901 900 return array();
902 901 }
903 902
@@ -906,12 +905,12 @@
906 905 foreach ( $registry as $handle => $active ) {
907 906 if ( ! $active || isset( $seen[ $handle ] ) ) {
908 907 continue;
909 908 }
910 - $payload = desktop_mode_resolve_script_payload( $handle );
909 + $payload = openstation_resolve_script_payload( $handle );
911 910 if ( '' === $payload['url'] ) {
912 - desktop_mode_warn_unresolvable_script_handle(
913 - 'desktop_mode_register_window_chrome_script',
911 + openstation_warn_unresolvable_script_handle(
912 + 'openstation_register_window_chrome_script',
914 913 'Window chrome',
915 914 (string) $handle
916 915 );
917 916 continue;
@@ -922,8 +921,11 @@
922 921 'scriptBefore' => $payload['before'],
923 922 'scriptAfter' => $payload['after'],
924 923 'scriptL10n' => $payload['l10n'],
925 924 'scriptTranslations' => $payload['translations'],
925 + // The handle's dependency closure, replayed before the bundle
926 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
927 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
926 928 );
927 929 $seen[ $handle ] = true;
928 930 }
929 931 return $out;
@@ -929,13 +931,12 @@
929 931 return $out;
930 932 }
931 933
932 934 /**
933 - * @since 0.6.0
934 935 * @return array[]
935 936 */
936 -function desktop_mode_build_window_chromes_payload() {
937 - $registry = desktop_mode_window_chrome_registry();
937 +function openstation_build_window_chromes_payload() {
938 + $registry = openstation_window_chrome_registry();
938 939 if ( ! is_array( $registry ) || empty( $registry ) ) {
939 940 return array();
940 941 }
941 942
@@ -942,19 +943,28 @@
942 943 $out = array();
943 944 foreach ( $registry as $entry ) {
944 945 $handle = (string) $entry['script'];
945 946 $payload = '' !== $handle
946 - ? desktop_mode_resolve_script_payload( $handle )
947 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
948 - $out[] = array(
949 - 'id' => (string) $entry['id'],
950 - 'label' => (string) $entry['label'],
951 - 'scriptUrl' => $payload['url'],
952 - 'scriptHandle' => $handle,
953 - 'scriptBefore' => $payload['before'],
954 - 'scriptAfter' => $payload['after'],
955 - 'scriptL10n' => $payload['l10n'],
947 + ? openstation_resolve_script_payload( $handle )
948 + : array(
949 + 'url' => '',
950 + 'before' => array(),
951 + 'after' => array(),
952 + 'l10n' => array(),
953 + 'translations' => '',
954 + );
955 + $out[] = array(
956 + 'id' => (string) $entry['id'],
957 + 'label' => (string) $entry['label'],
958 + 'scriptUrl' => $payload['url'],
959 + 'scriptHandle' => $handle,
960 + 'scriptBefore' => $payload['before'],
961 + 'scriptAfter' => $payload['after'],
962 + 'scriptL10n' => $payload['l10n'],
956 963 'scriptTranslations' => $payload['translations'],
964 + // The handle's dependency closure, replayed before the bundle
965 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
966 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
957 967 );
958 968 }
959 969 return $out;
960 970 }