| @@ -776,8 +776,10 @@ | ||
| 776 | 776 | wp_dequeue_style( $handle ); |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | + openstation_chromeless_keep_components_style( $scripts ); | |
| 781 | + | |
| 780 | 782 | /** |
| 781 | 783 | * Fires after OpenStation drops the command-palette family in a window. |
| 782 | 784 | */ |
| 783 | 785 | do_action( 'openstation_chromeless_trimmed_command_palette' ); |
| @@ -782,8 +784,70 @@ | ||
| 782 | 784 | */ |
| 783 | 785 | do_action( 'openstation_chromeless_trimmed_command_palette' ); |
| 784 | 786 | } |
| 785 | 787 | add_action( 'admin_enqueue_scripts', 'openstation_chromeless_trim_command_palette', PHP_INT_MAX ); |
| 788 | + | |
| 789 | +/** | |
| 790 | + * Keeps the `wp-components` stylesheet for screens that use the components. | |
| 791 | + * | |
| 792 | + * Core's palette enqueues the `wp-commands` stylesheet, which depends on | |
| 793 | + * `wp-components`, on every admin page. Plugins that render with | |
| 794 | + * `@wordpress/components` routinely depend on the `wp-components` | |
| 795 | + * SCRIPT and never declare the matching style, because in the classic | |
| 796 | + * admin the palette always brought it along. Trimming the palette from a | |
| 797 | + * window took that stylesheet away from them. | |
| 798 | + * | |
| 799 | + * What breaks first is anything that floats. A window narrower than | |
| 800 | + * Core's 782px "medium" breakpoint puts every Popover into its full-screen | |
| 801 | + * `is-expanded` mode, which drops the inline positioning and relies on | |
| 802 | + * `.components-popover.is-expanded` from this stylesheet. Without it the | |
| 803 | + * AI plugin's DataViews "View options" popover rendered as a static | |
| 804 | + * block below the page, so the button looked dead. Dropdowns, modals and | |
| 805 | + * snackbars lose their styling the same way. | |
| 806 | + * | |
| 807 | + * So if a queued plugin or theme script reaches the `wp-components` | |
| 808 | + * script, its stylesheet is queued too, which is what the classic admin | |
| 809 | + * effectively guaranteed. Screens that don't render components pay | |
| 810 | + * nothing. | |
| 811 | + * | |
| 812 | + * @param WP_Scripts $scripts The scripts registry. | |
| 813 | + */ | |
| 814 | +function openstation_chromeless_keep_components_style( $scripts ) { | |
| 815 | + if ( ! wp_style_is( 'wp-components', 'registered' ) || wp_style_is( 'wp-components', 'enqueued' ) ) { | |
| 816 | + return; | |
| 817 | + } | |
| 818 | + | |
| 819 | + // Only screens that render components count. Core packages such as | |
| 820 | + // `wp-abilities` reach `wp-components` as a library on every admin | |
| 821 | + // page, so the walk skips them, the same structural rule the palette | |
| 822 | + // family walk uses ({@see openstation_handle_depends_on()}). Measured: | |
| 823 | + // with it, Settings and the Posts list stay lean while the AI plugin's | |
| 824 | + // logs and WooCommerce's admin app keep the stylesheet. Without it, | |
| 825 | + // every window got it. | |
| 826 | + $uses_components = in_array( 'wp-components', $scripts->queue, true ); | |
| 827 | + $memo = array(); | |
| 828 | + foreach ( $scripts->queue as $handle ) { | |
| 829 | + if ( $uses_components ) { | |
| 830 | + break; | |
| 831 | + } | |
| 832 | + if ( openstation_is_core_package_handle( $scripts, $handle ) ) { | |
| 833 | + continue; | |
| 834 | + } | |
| 835 | + $uses_components = openstation_handle_depends_on( $scripts, $handle, array( 'wp-components' ), $memo ); | |
| 836 | + } | |
| 837 | + | |
| 838 | + /** | |
| 839 | + * Filters whether a window keeps the `wp-components` stylesheet after | |
| 840 | + * the command palette is trimmed. | |
| 841 | + * | |
| 842 | + * @param bool $keep Whether to enqueue it. Defaults to whether a queued | |
| 843 | + * plugin or theme script depends on the `wp-components` | |
| 844 | + * script. | |
| 845 | + */ | |
| 846 | + if ( apply_filters( 'openstation_chromeless_keep_components_style', $uses_components ) ) { | |
| 847 | + wp_enqueue_style( 'wp-components' ); | |
| 848 | + } | |
| 849 | +} | |
| 786 | 850 | |
| 787 | 851 | /** |
| 788 | 852 | * Second pass: strip the palette family from the actual print list. |
| 789 | 853 | * |