Skip to content

Commit 9e9d9b2

Browse files
committed
Store/read selector from URL
1 parent c5ceb41 commit 9e9d9b2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

html-api-debugger/html-api-debugger.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function () {
113113

114114
$options = array(
115115
'context_html' => null,
116+
'selector' => null,
116117
);
117118

118119
$html = '';
@@ -123,6 +124,9 @@ function () {
123124
if ( isset( $_GET['contextHTML'] ) && is_string( $_GET['contextHTML'] ) ) {
124125
$options['context_html'] = stripslashes( $_GET['contextHTML'] );
125126
}
127+
if ( isset( $_GET['selector'] ) && is_string( $_GET['selector'] ) ) {
128+
$options['selector'] = stripslashes( $_GET['selector'] );
129+
}
126130
// phpcs:enable WordPress.Security.NonceVerification.Recommended
127131

128132
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

html-api-debugger/interactivity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function generate_page( string $html, array $options ): string {
3737
'showInvisible' => false,
3838
'showVirtual' => false,
3939
'contextHTML' => $options['context_html'] ?? '',
40+
'selector' => $options['selector'] ?? '',
4041

4142
'hoverInfo' => 'breadcrumbs',
4243
'hoverBreadcrumbs' => true,
@@ -152,7 +153,7 @@ class="context-html"
152153
<label>Show invisible <input type="checkbox" data-wp-bind--checked="state.showInvisible" data-wp-on-async--input="handleShowInvisibleClick"></label>
153154
<span><label>Show virtual <input type="checkbox" data-wp-bind--checked="state.showVirtual" data-wp-on-async--input="handleShowVirtualClick"></label></span>
154155
<div data-wp-bind-hidden="!state.htmlapiResponse.supports.selectors">
155-
<label>CSS Selectors <textarea placeholder="CSS selector: .my-class" data-wp-on-async--input="handleSelectorChange"></textarea></label>
156+
<label>CSS Selectors <textarea placeholder="CSS selector: .my-class" data-wp-on-async--input="handleSelectorChange"><?php echo "\n" . esc_textarea( str_replace( "\0", '', $options['selector'] ?? '' ) ); ?></textarea></label>
156157
</div>
157158
</div>
158159
<div>

html-api-debugger/view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ let mutationObserver = null;
4949
*
5050
* @typedef Supports
5151
* @property {boolean} create_fragment_advanced
52+
* @property {boolean} selectors
5253
*
5354
*
5455
* @typedef HtmlApiResponse
@@ -261,6 +262,9 @@ const store = createStore(NS, {
261262
if (store.state.contextHTMLForUse) {
262263
searchParams.set('contextHTML', store.state.contextHTMLForUse);
263264
}
265+
if (store.state.selector) {
266+
searchParams.set('selector', store.state.selector);
267+
}
264268
const base = '/wp-admin/admin.php';
265269
const u = new URL(
266270
'https://playground.wordpress.net/?plugin=html-api-debugger',
@@ -502,6 +506,7 @@ const store = createStore(NS, {
502506
for (const [param, prop] of /** @type {const} */ ([
503507
['html', 'html'],
504508
['contextHTML', 'contextHTMLForUse'],
509+
['selector', 'selector'],
505510
])) {
506511
if (store.state[prop]) {
507512
u.searchParams.set(param, store.state[prop]);

0 commit comments

Comments
 (0)