@wordpress/e2e-tests 9.21.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/mu-plugins/e2e-fast-sync-polling.php +4 -4
- package/package.json +5 -6
- package/plugins/animated-image-subsizes.php +10 -0
- package/plugins/autosave-failures.php +144 -0
- package/plugins/block-bindings.php +5 -0
- package/plugins/entity-actions-api/close-comments.js +49 -0
- package/plugins/entity-actions-api.php +106 -0
- package/plugins/entity-fields-api/comment-status.css +24 -0
- package/plugins/entity-fields-api/comment-status.js +26 -0
- package/plugins/entity-fields-api/reading-time.css +21 -0
- package/plugins/entity-fields-api/reading-time.js +82 -0
- package/plugins/entity-fields-api.php +291 -0
- package/plugins/interactive-blocks/directive-html/block.json +15 -0
- package/plugins/interactive-blocks/directive-html/render.php +54 -0
- package/plugins/interactive-blocks/directive-html/view.asset.php +1 -0
- package/plugins/interactive-blocks/directive-html/view.js +39 -0
- package/plugins/interactive-blocks/directive-init/render.php +1 -1
- package/plugins/interactive-blocks/directive-on/render.php +1 -1
- package/plugins/interactive-blocks/directive-on-document/render.php +1 -1
- package/plugins/interactive-blocks/directive-on-window/render.php +1 -1
- package/plugins/interactive-blocks/directive-run/render.php +1 -1
- package/plugins/interactive-blocks/directive-run/view.js +2 -2
- package/plugins/interactive-blocks/directive-watch/render.php +1 -1
- package/plugins/interactive-blocks/hydration-timing-async/view.js +1 -1
- package/plugins/interactive-blocks/router-html/block.json +19 -0
- package/plugins/interactive-blocks/router-html/render.php +64 -0
- package/plugins/interactive-blocks/router-html/view.asset.php +9 -0
- package/plugins/interactive-blocks/router-html/view.js +56 -0
- package/plugins/interactive-blocks/router-navigation-full-page/block.json +15 -0
- package/plugins/interactive-blocks/router-navigation-full-page/render.php +120 -0
- package/plugins/interactive-blocks/router-navigation-full-page/view.asset.php +9 -0
- package/plugins/interactive-blocks/router-navigation-full-page/view.js +95 -0
- package/plugins/interactive-blocks/router-navigation-lifecycle/block.json +15 -0
- package/plugins/interactive-blocks/router-navigation-lifecycle/render.php +303 -0
- package/plugins/interactive-blocks/router-navigation-lifecycle/view.asset.php +9 -0
- package/plugins/interactive-blocks/router-navigation-lifecycle/view.js +383 -0
- package/plugins/interactive-blocks/tovdom-islands/render.php +7 -10
- package/plugins/interactive-blocks/with-scope/render.php +1 -1
- package/plugins/interactive-blocks.php +12 -0
- package/plugins/lightbox-overlay-wrapper.php +25 -0
- package/plugins/react-18-compat-block/editor.js +38 -0
- package/plugins/rtc-websocket-provider/src/index.js +1 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Plugin Name: Gutenberg Test Entity Fields API
|
|
4
|
+
* Plugin URI: https://github.com/WordPress/gutenberg
|
|
5
|
+
* Author: Gutenberg Team
|
|
6
|
+
*
|
|
7
|
+
* Extends the fields of Pages through the Entity fields API, one
|
|
8
|
+
* self-contained function per case. Every server case registers its fields on
|
|
9
|
+
* `wp_entity_fields_api_init`, the action the registry fires the first time
|
|
10
|
+
* its fields are read, after `init`, once the default fields are registered.
|
|
11
|
+
*
|
|
12
|
+
* 1. `add_field_declarative`: a declarative field (`menu_order`), plain data,
|
|
13
|
+
* no JavaScript.
|
|
14
|
+
* 2. `add_field_with_script_module`: a field backed by a script module and a
|
|
15
|
+
* stylesheet (`reading_time`), its value and render coming from
|
|
16
|
+
* `entity-fields-api/reading-time.js`. The same module exports a complete
|
|
17
|
+
* `word_count` field no registration names: the module augments the fields
|
|
18
|
+
* it was registered with, so the entry is ignored and the field is not
|
|
19
|
+
* registered.
|
|
20
|
+
* 3. `update_field`: an update of a default field (`comment_status`), which
|
|
21
|
+
* becomes sortable and hideable, and gets a render from
|
|
22
|
+
* `entity-fields-api/comment-status.js`, keeping the rest of its
|
|
23
|
+
* definition.
|
|
24
|
+
* 4. `replace_field`: a substitute for a default field (`author`),
|
|
25
|
+
* unregistered and registered again as a plain integer with a new label.
|
|
26
|
+
* 5. `add_field_with_data`: a field whose value is data the plugin adds to
|
|
27
|
+
* the Pages REST endpoint (`subtitle`), a REST field backed by post meta,
|
|
28
|
+
* readable in the list and writable from the Quick Edit form, which the
|
|
29
|
+
* function adds the field to.
|
|
30
|
+
*
|
|
31
|
+
* @package gutenberg-test-entity-fields-api
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Case 1: a declarative field (`menu_order`), whose value is a property of
|
|
36
|
+
* the record. No JavaScript, no styles.
|
|
37
|
+
*/
|
|
38
|
+
function gutenberg_test_entity_fields_api_add_field_declarative() {
|
|
39
|
+
wp_register_entity_fields(
|
|
40
|
+
'gutenberg-test-entity-fields-api',
|
|
41
|
+
'postType',
|
|
42
|
+
'page',
|
|
43
|
+
array(
|
|
44
|
+
array(
|
|
45
|
+
'id' => 'menu_order',
|
|
46
|
+
'type' => 'integer',
|
|
47
|
+
'label' => 'Order',
|
|
48
|
+
'description' => 'Position of the page among its siblings.',
|
|
49
|
+
'enableSorting' => false,
|
|
50
|
+
'filterBy' => false,
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
add_action( 'wp_entity_fields_api_init', 'gutenberg_test_entity_fields_api_add_field_declarative' );
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Case 2: a field (`reading_time`) whose value and render come from a script
|
|
59
|
+
* module, styled by a stylesheet. Two functions:
|
|
60
|
+
*
|
|
61
|
+
* - The assets, on `init` like any plugin asset. The module is registered,
|
|
62
|
+
* not enqueued: Gutenberg adds the modules of the registered fields to the
|
|
63
|
+
* import map of the editor pages. A stylesheet cannot ride along with a
|
|
64
|
+
* script module, so the function enqueues it on every screen where the
|
|
65
|
+
* field can show.
|
|
66
|
+
* - The field, on `wp_entity_fields_api_init`. The action fires whenever the
|
|
67
|
+
* registry is first read, during REST requests too, so its callback
|
|
68
|
+
* registers the field and nothing else.
|
|
69
|
+
*
|
|
70
|
+
* The module also exports a complete `word_count` field, id and label
|
|
71
|
+
* included, that no registration names. A module only
|
|
72
|
+
* augments the fields it was registered with, so the entry is ignored and
|
|
73
|
+
* the field is not registered.
|
|
74
|
+
*/
|
|
75
|
+
function gutenberg_test_entity_fields_api_register_reading_time_assets() {
|
|
76
|
+
wp_register_script_module(
|
|
77
|
+
'gutenberg-test-entity-fields-api/reading-time',
|
|
78
|
+
plugins_url( 'entity-fields-api/reading-time.js', __FILE__ ),
|
|
79
|
+
array(),
|
|
80
|
+
filemtime( __DIR__ . '/entity-fields-api/reading-time.js' )
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
wp_register_style(
|
|
84
|
+
'gutenberg-test-entity-fields-api-reading-time',
|
|
85
|
+
plugins_url( 'entity-fields-api/reading-time.css', __FILE__ ),
|
|
86
|
+
array(),
|
|
87
|
+
filemtime( __DIR__ . '/entity-fields-api/reading-time.css' )
|
|
88
|
+
);
|
|
89
|
+
$enqueue_style = function () {
|
|
90
|
+
wp_enqueue_style( 'gutenberg-test-entity-fields-api-reading-time' );
|
|
91
|
+
};
|
|
92
|
+
// The post editor and the site editor.
|
|
93
|
+
add_action( 'enqueue_block_editor_assets', $enqueue_style );
|
|
94
|
+
// The extensible site editor renders its own document and exits on
|
|
95
|
+
// `admin_init`, before `enqueue_block_editor_assets` fires, so styles are
|
|
96
|
+
// enqueued from its `{page}_init` action instead.
|
|
97
|
+
add_action( 'site-editor-v2_init', $enqueue_style );
|
|
98
|
+
// The extensible site editor rendered inside the wp-admin chrome.
|
|
99
|
+
add_action( 'site-editor-v2-wp-admin_init', $enqueue_style );
|
|
100
|
+
}
|
|
101
|
+
add_action( 'init', 'gutenberg_test_entity_fields_api_register_reading_time_assets' );
|
|
102
|
+
|
|
103
|
+
function gutenberg_test_entity_fields_api_add_field_with_script_module() {
|
|
104
|
+
wp_register_entity_fields(
|
|
105
|
+
'gutenberg-test-entity-fields-api',
|
|
106
|
+
'postType',
|
|
107
|
+
'page',
|
|
108
|
+
array(
|
|
109
|
+
array(
|
|
110
|
+
'id' => 'reading_time',
|
|
111
|
+
'type' => 'integer',
|
|
112
|
+
'label' => 'Reading time',
|
|
113
|
+
'enableSorting' => false,
|
|
114
|
+
'filterBy' => false,
|
|
115
|
+
'readOnly' => true,
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
'gutenberg-test-entity-fields-api/reading-time'
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
add_action( 'wp_entity_fields_api_init', 'gutenberg_test_entity_fields_api_add_field_with_script_module' );
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Case 3: an update of a default field (`comment_status`). Only the properties
|
|
125
|
+
* given change, and the module applies to the field on top of the modules it
|
|
126
|
+
* has. Hideable, so the field can be shown from the view options.
|
|
127
|
+
*
|
|
128
|
+
* Only a registered field can be updated, so the update must come after the
|
|
129
|
+
* default fields, registered on `wp_entity_fields_api_init` at priority 0: the
|
|
130
|
+
* default priority does. An update before would be refused. The assets go
|
|
131
|
+
* on `init`, split from the field as in case 2.
|
|
132
|
+
*/
|
|
133
|
+
function gutenberg_test_entity_fields_api_register_comment_status_assets() {
|
|
134
|
+
wp_register_script_module(
|
|
135
|
+
'gutenberg-test-entity-fields-api/comment-status',
|
|
136
|
+
plugins_url( 'entity-fields-api/comment-status.js', __FILE__ ),
|
|
137
|
+
array(),
|
|
138
|
+
filemtime( __DIR__ . '/entity-fields-api/comment-status.js' )
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
wp_register_style(
|
|
142
|
+
'gutenberg-test-entity-fields-api-comment-status',
|
|
143
|
+
plugins_url( 'entity-fields-api/comment-status.css', __FILE__ ),
|
|
144
|
+
array(),
|
|
145
|
+
filemtime( __DIR__ . '/entity-fields-api/comment-status.css' )
|
|
146
|
+
);
|
|
147
|
+
$enqueue_style = function () {
|
|
148
|
+
wp_enqueue_style( 'gutenberg-test-entity-fields-api-comment-status' );
|
|
149
|
+
};
|
|
150
|
+
// The same screens as case 2: see the comments there.
|
|
151
|
+
add_action( 'enqueue_block_editor_assets', $enqueue_style );
|
|
152
|
+
add_action( 'site-editor-v2_init', $enqueue_style );
|
|
153
|
+
add_action( 'site-editor-v2-wp-admin_init', $enqueue_style );
|
|
154
|
+
}
|
|
155
|
+
add_action( 'init', 'gutenberg_test_entity_fields_api_register_comment_status_assets' );
|
|
156
|
+
|
|
157
|
+
function gutenberg_test_entity_fields_api_update_field() {
|
|
158
|
+
wp_update_entity_fields(
|
|
159
|
+
'gutenberg-test-entity-fields-api',
|
|
160
|
+
'postType',
|
|
161
|
+
'page',
|
|
162
|
+
array(
|
|
163
|
+
array(
|
|
164
|
+
'id' => 'comment_status',
|
|
165
|
+
'enableSorting' => true,
|
|
166
|
+
'enableHiding' => true,
|
|
167
|
+
),
|
|
168
|
+
),
|
|
169
|
+
'gutenberg-test-entity-fields-api/comment-status'
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
add_action( 'wp_entity_fields_api_init', 'gutenberg_test_entity_fields_api_update_field' );
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Case 4: a substitute for a default field (`author`). Unregistering drops
|
|
176
|
+
* its definition and detaches its script modules, so the registration that
|
|
177
|
+
* follows is the whole field. The default priority runs after the default
|
|
178
|
+
* fields: there is nothing to unregister before.
|
|
179
|
+
*/
|
|
180
|
+
function gutenberg_test_entity_fields_api_replace_field() {
|
|
181
|
+
wp_unregister_entity_fields( 'postType', 'page', array( 'author' ) );
|
|
182
|
+
wp_register_entity_fields(
|
|
183
|
+
'gutenberg-test-entity-fields-api',
|
|
184
|
+
'postType',
|
|
185
|
+
'page',
|
|
186
|
+
array(
|
|
187
|
+
array(
|
|
188
|
+
'id' => 'author',
|
|
189
|
+
'type' => 'integer',
|
|
190
|
+
'label' => 'Written by',
|
|
191
|
+
'filterBy' => false,
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
add_action( 'wp_entity_fields_api_init', 'gutenberg_test_entity_fields_api_replace_field' );
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Case 5: a field (`subtitle`) whose value is data the plugin adds to the
|
|
200
|
+
* Pages REST endpoint. Three parts:
|
|
201
|
+
*
|
|
202
|
+
* - A REST field reading and writing post meta the plugin owns, which the
|
|
203
|
+
* endpoint does not expose otherwise, so the record of every page carries
|
|
204
|
+
* `subtitle` and a request updating a page can set it. Hooked to
|
|
205
|
+
* `rest_api_init` on its own: a request to the Pages endpoint does not read
|
|
206
|
+
* the fields registry, so `wp_entity_fields_api_init` may never fire during it.
|
|
207
|
+
* - A declarative field like case 1. The field API reads the value from the
|
|
208
|
+
* record and, as the field is not read-only, the Quick Edit form saves the
|
|
209
|
+
* edits with the record, through the REST field.
|
|
210
|
+
* - An entry in the Quick Edit form of Pages. The form lists its fields
|
|
211
|
+
* explicitly in the view configuration of the entity, so a new field is
|
|
212
|
+
* not offered for editing until it is added there. Merging appends the
|
|
213
|
+
* field to the end of the form. Filtered from the moment the plugin
|
|
214
|
+
* loads, whenever the view configuration is read.
|
|
215
|
+
*/
|
|
216
|
+
function gutenberg_test_entity_fields_api_add_field_with_data() {
|
|
217
|
+
wp_register_entity_fields(
|
|
218
|
+
'gutenberg-test-entity-fields-api',
|
|
219
|
+
'postType',
|
|
220
|
+
'page',
|
|
221
|
+
array(
|
|
222
|
+
array(
|
|
223
|
+
'id' => 'subtitle',
|
|
224
|
+
'type' => 'text',
|
|
225
|
+
'label' => 'Subtitle',
|
|
226
|
+
'description' => 'A secondary title shown under the title.',
|
|
227
|
+
'enableSorting' => false,
|
|
228
|
+
'filterBy' => false,
|
|
229
|
+
),
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
add_action( 'wp_entity_fields_api_init', 'gutenberg_test_entity_fields_api_add_field_with_data' );
|
|
234
|
+
|
|
235
|
+
add_action(
|
|
236
|
+
'rest_api_init',
|
|
237
|
+
function () {
|
|
238
|
+
register_rest_field(
|
|
239
|
+
'page',
|
|
240
|
+
'subtitle',
|
|
241
|
+
array(
|
|
242
|
+
'schema' => array(
|
|
243
|
+
'description' => 'A secondary title shown under the title.',
|
|
244
|
+
'type' => 'string',
|
|
245
|
+
'context' => array( 'view', 'edit' ),
|
|
246
|
+
),
|
|
247
|
+
'get_callback' => function ( $item ) {
|
|
248
|
+
return (string) get_post_meta( $item['id'], '_gutenberg_test_subtitle', true );
|
|
249
|
+
},
|
|
250
|
+
'update_callback' => function ( $value, $post ) {
|
|
251
|
+
update_post_meta( $post->ID, '_gutenberg_test_subtitle', sanitize_text_field( $value ) );
|
|
252
|
+
return true;
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
add_filter(
|
|
260
|
+
'get_entity_view_config_posttype_page',
|
|
261
|
+
function ( $data ) {
|
|
262
|
+
return $data->merge(
|
|
263
|
+
array(
|
|
264
|
+
'form' => array(
|
|
265
|
+
'fields' => array( 'subtitle' ),
|
|
266
|
+
),
|
|
267
|
+
),
|
|
268
|
+
1
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Registers a submenu rendering the extensible site editor inside the
|
|
275
|
+
* wp-admin chrome, so the `site-editor-v2-wp-admin_init` enqueues above can
|
|
276
|
+
* be exercised. The page has no menu entry of its own.
|
|
277
|
+
*/
|
|
278
|
+
function gutenberg_test_entity_fields_api_register_embedded_page() {
|
|
279
|
+
if ( ! function_exists( 'gutenberg_site_editor_v2_wp_admin_render_page' ) ) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
add_submenu_page(
|
|
283
|
+
'themes.php',
|
|
284
|
+
'Pages (embedded)',
|
|
285
|
+
'Pages (embedded)',
|
|
286
|
+
'edit_theme_options',
|
|
287
|
+
'site-editor-v2-wp-admin',
|
|
288
|
+
'gutenberg_site_editor_v2_wp_admin_render_page'
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
add_action( 'admin_menu', 'gutenberg_test_entity_fields_api_register_embedded_page' );
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"name": "test/directive-html",
|
|
5
|
+
"title": "E2E Interactivity tests - directive html",
|
|
6
|
+
"category": "text",
|
|
7
|
+
"icon": "heart",
|
|
8
|
+
"description": "",
|
|
9
|
+
"supports": {
|
|
10
|
+
"interactivity": true
|
|
11
|
+
},
|
|
12
|
+
"textdomain": "e2e-interactivity",
|
|
13
|
+
"viewScriptModule": "file:./view.js",
|
|
14
|
+
"render": "file:./render.php"
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* HTML for testing the directive `data-wp-html`.
|
|
4
|
+
*
|
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
wp_interactivity_state(
|
|
9
|
+
'directive-html',
|
|
10
|
+
array(
|
|
11
|
+
'serverHtml' => array( 'wpServerHtml' => true ),
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
?>
|
|
15
|
+
|
|
16
|
+
<div data-wp-interactive="directive-html">
|
|
17
|
+
<span data-wp-text="state.hydration" data-testid="hydration">not hydrated</span>
|
|
18
|
+
<button data-wp-on--click="actions.setTrustedHtml" data-testid="set trusted html">
|
|
19
|
+
Set Trusted HTML
|
|
20
|
+
</button>
|
|
21
|
+
|
|
22
|
+
<div data-wp-html="state.html" data-testid="show state html">
|
|
23
|
+
<p data-testid="fallback">Fallback content</p>
|
|
24
|
+
</div>
|
|
25
|
+
<div data-wp-html="state.rejected" data-testid="rejected html"><p>Rejected fallback</p></div>
|
|
26
|
+
<div data-wp-html="state.serverHtml" data-testid="server html"><p>Server-rendered HTML</p></div>
|
|
27
|
+
<button data-wp-on--click="actions.setServerHtml" data-testid="set server html">Set Server HTML</button>
|
|
28
|
+
<ul data-testid="created items">
|
|
29
|
+
<template data-wp-each="state.list"><li><div data-wp-html="state.empty"></div></li></template>
|
|
30
|
+
</ul>
|
|
31
|
+
<button data-wp-on--click="actions.setRejected" data-testid="set rejected html">Set Rejected HTML</button>
|
|
32
|
+
|
|
33
|
+
<button data-wp-on--click="actions.setHtml" data-testid="set html">
|
|
34
|
+
Set HTML
|
|
35
|
+
</button>
|
|
36
|
+
|
|
37
|
+
<button
|
|
38
|
+
data-wp-on--click="actions.setLoading"
|
|
39
|
+
data-testid="set loading"
|
|
40
|
+
>
|
|
41
|
+
Set Loading
|
|
42
|
+
</button>
|
|
43
|
+
|
|
44
|
+
<div data-wp-html--suffix="state.html" data-testid="ignores suffixes">
|
|
45
|
+
<span data-testid="suffix-fallback">Suffix fallback</span>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div
|
|
49
|
+
data-wp-html---unique-id="state.html"
|
|
50
|
+
data-testid="ignores unique-ids"
|
|
51
|
+
>
|
|
52
|
+
<span data-testid="unique-id-fallback">Unique ID fallback</span>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<?php return array( 'dependencies' => array( '@wordpress/interactivity' ) );
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { store, asDangerousHTML } from '@wordpress/interactivity';
|
|
2
|
+
|
|
3
|
+
const policy = window.trustedTypes?.createPolicy( 'directive-html', {
|
|
4
|
+
createHTML: ( html ) => html,
|
|
5
|
+
} );
|
|
6
|
+
|
|
7
|
+
const { state } = store( 'directive-html', {
|
|
8
|
+
state: {
|
|
9
|
+
html: null,
|
|
10
|
+
// Matches the server-rendered fallback, so it renders before the
|
|
11
|
+
// rejected value replaces it.
|
|
12
|
+
rejected: asDangerousHTML(
|
|
13
|
+
policy?.createHTML( '<p>Rejected fallback</p>' ) ??
|
|
14
|
+
'<p>Rejected fallback</p>'
|
|
15
|
+
),
|
|
16
|
+
empty: null,
|
|
17
|
+
list: [ 'a', 'b' ],
|
|
18
|
+
hydration: 'hydrated',
|
|
19
|
+
},
|
|
20
|
+
actions: {
|
|
21
|
+
setHtml() {
|
|
22
|
+
state.html = asDangerousHTML(
|
|
23
|
+
'<strong data-testid="rendered-strong">Rendered HTML</strong>'
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
setLoading() {
|
|
27
|
+
state.html = null;
|
|
28
|
+
},
|
|
29
|
+
setTrustedHtml() {
|
|
30
|
+
state.html = asDangerousHTML( policy.createHTML( '<p>Late</p>' ) );
|
|
31
|
+
},
|
|
32
|
+
setRejected() {
|
|
33
|
+
state.rejected = asDangerousHTML( '<b>x</b>' );
|
|
34
|
+
},
|
|
35
|
+
setServerHtml() {
|
|
36
|
+
state.serverHtml = asDangerousHTML( '<p>Client HTML</p>' );
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
} );
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<div
|
|
20
20
|
data-testid="multiple inits"
|
|
21
21
|
data-wp-context='{"isReady":[false,false],"calls":[0,0]}'
|
|
22
|
-
data-wp-init
|
|
22
|
+
data-wp-init---one="actions.initOne"
|
|
23
23
|
data-wp-init---two="actions.initTwo"
|
|
24
24
|
>
|
|
25
25
|
<p data-wp-text="state.isReady" data-testid="isReady">false,false</p>
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<button
|
|
67
67
|
data-testid="multiple handlers button"
|
|
68
68
|
data-wp-on--click="actions.setClicked"
|
|
69
|
-
data-wp-on--click
|
|
69
|
+
data-wp-on--click---counter="actions.countClick"
|
|
70
70
|
data-wp-on--click---toggle="actions.toggle"
|
|
71
71
|
>Click me!</button>
|
|
72
72
|
</div>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</div>
|
|
27
27
|
<div
|
|
28
28
|
data-wp-on-document--keydown="actions.keydownHandler"
|
|
29
|
-
data-wp-on-document--keydown
|
|
29
|
+
data-wp-on-document--keydown---second="actions.keydownSecondHandler"
|
|
30
30
|
data-wp-on-document--keydown---third="actions.keydownThirdHandler"
|
|
31
31
|
>
|
|
32
32
|
<p data-wp-text="state.keydownHandler" data-testid="keydownHandler">no</p>
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
</div>
|
|
24
24
|
<div
|
|
25
25
|
data-wp-on-window--resize="actions.resizeHandler"
|
|
26
|
-
data-wp-on-window--resize
|
|
26
|
+
data-wp-on-window--resize---second="actions.resizeSecondHandler"
|
|
27
27
|
data-wp-on-window--resize---third="actions.resizeThirdHandler"
|
|
28
28
|
>
|
|
29
29
|
<p data-wp-text="state.resizeHandler" data-testid="resizeHandler">no</p>
|
|
@@ -39,8 +39,8 @@ const html = `
|
|
|
39
39
|
<div data-testid="navigated">yes</div>
|
|
40
40
|
|
|
41
41
|
<div
|
|
42
|
-
data-wp-run
|
|
43
|
-
data-wp-run
|
|
42
|
+
data-wp-run---hydrated="callbacks.updateIsHydrated"
|
|
43
|
+
data-wp-run---renderCount="callbacks.updateRenderCount"
|
|
44
44
|
data-wp-text="state.clickCount"
|
|
45
45
|
></div>
|
|
46
46
|
</div>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
<div
|
|
33
33
|
data-testid="multiple watches"
|
|
34
|
-
data-wp-watch
|
|
34
|
+
data-wp-watch---one="callbacks.watch1"
|
|
35
35
|
data-wp-watch---two="callbacks.watch2"
|
|
36
36
|
data-wp-bind--data-watch-one="state.watch1"
|
|
37
37
|
data-wp-bind--data-watch-two="state.watch2"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This module dynamically imports
|
|
2
|
+
* This module dynamically imports `@wordpress/interactivity` on DOMContentLoaded.
|
|
3
3
|
*
|
|
4
4
|
* This simulates a lazy-loading scenario where the Interactivity API is not
|
|
5
5
|
* statically imported. The test verifies that hydration still occurs even
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"name": "test/router-html",
|
|
5
|
+
"title": "E2E Interactivity tests - router HTML",
|
|
6
|
+
"category": "text",
|
|
7
|
+
"icon": "heart",
|
|
8
|
+
"attributes": {
|
|
9
|
+
"page": { "type": "string" },
|
|
10
|
+
"value": { "type": "string", "default": "null" },
|
|
11
|
+
"next": { "type": "string" }
|
|
12
|
+
},
|
|
13
|
+
"supports": {
|
|
14
|
+
"interactivity": true
|
|
15
|
+
},
|
|
16
|
+
"textdomain": "e2e-interactivity",
|
|
17
|
+
"viewScriptModule": "file:./view.js",
|
|
18
|
+
"render": "file:./render.php"
|
|
19
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* HTML for testing HTML elements kept across router navigation.
|
|
4
|
+
*
|
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
$attributes = get_defined_vars()['attributes'];
|
|
9
|
+
$page = $attributes['page'];
|
|
10
|
+
|
|
11
|
+
if ( 'pending' === $attributes['value'] ) {
|
|
12
|
+
wp_interactivity_state(
|
|
13
|
+
'router-html',
|
|
14
|
+
array(
|
|
15
|
+
/**
|
|
16
|
+
* Supplies the server-only derived HTML placeholder.
|
|
17
|
+
*
|
|
18
|
+
* @return null The client implementation is deferred.
|
|
19
|
+
*/
|
|
20
|
+
'late' => function () {
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
add_filter(
|
|
26
|
+
'script_module_data_@wordpress/interactivity',
|
|
27
|
+
/**
|
|
28
|
+
* Declares a derived value whose client implementation loads later.
|
|
29
|
+
*
|
|
30
|
+
* @param array|null $data Serialized Interactivity API server data.
|
|
31
|
+
* @return array Server data with the pending HTML getter declaration.
|
|
32
|
+
*/
|
|
33
|
+
function ( $data ) {
|
|
34
|
+
$data = $data ?? array();
|
|
35
|
+
$data['derivedStateClosures']['router-html'][] = 'state.late';
|
|
36
|
+
return $data;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
?>
|
|
41
|
+
|
|
42
|
+
<div data-wp-interactive="router-html">
|
|
43
|
+
<div
|
|
44
|
+
data-wp-interactive="router-html"
|
|
45
|
+
data-wp-router-region="router-html-kept"
|
|
46
|
+
<?php
|
|
47
|
+
echo wp_interactivity_data_wp_context(
|
|
48
|
+
array(
|
|
49
|
+
'value' => $attributes['value'],
|
|
50
|
+
'resolved' => false,
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
?>
|
|
54
|
+
>
|
|
55
|
+
<p data-testid="page-content">content from <?php echo esc_html( $page ); ?></p>
|
|
56
|
+
<div data-testid="kept-html" data-wp-html="state.html"><i><?php echo 'one' === $page ? 'one' : 'two'; ?></i></div>
|
|
57
|
+
<div data-testid="never-html" data-wp-html="state.never"><i><?php echo 'one' === $page ? 'never one' : 'never two'; ?></i></div>
|
|
58
|
+
<p data-testid="value" data-wp-text="state.value">not hydrated</p>
|
|
59
|
+
<button data-wp-on--click="actions.resolve">Resolve HTML</button>
|
|
60
|
+
<?php if ( ! empty( $attributes['next'] ) ) : ?>
|
|
61
|
+
<a href="<?php echo esc_url( $attributes['next'] ); ?>" data-wp-on--click="actions.navigate">Next</a>
|
|
62
|
+
<?php endif; ?>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asDangerousHTML,
|
|
3
|
+
getContext,
|
|
4
|
+
getServerContext,
|
|
5
|
+
store,
|
|
6
|
+
withSyncEvent,
|
|
7
|
+
} from '@wordpress/interactivity';
|
|
8
|
+
|
|
9
|
+
/** HTML tokens selected by each page's server context. */
|
|
10
|
+
const tokens = {
|
|
11
|
+
/** Initial or matching destination HTML. */
|
|
12
|
+
T: asDangerousHTML( '<p>T</p>' ),
|
|
13
|
+
/** Differing or late destination HTML. */
|
|
14
|
+
U: asDangerousHTML( '<p>U</p>' ),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const { state } = store( 'router-html', {
|
|
18
|
+
state: {
|
|
19
|
+
/** Always empty, including on a kept node. */
|
|
20
|
+
never: null,
|
|
21
|
+
/** Returns the destination token, null, or a pending derived value. */
|
|
22
|
+
get html() {
|
|
23
|
+
if ( getServerContext().value === 'pending' ) {
|
|
24
|
+
return state.late;
|
|
25
|
+
}
|
|
26
|
+
return getContext().resolved
|
|
27
|
+
? tokens.U
|
|
28
|
+
: ( tokens[ getServerContext().value ] ?? null );
|
|
29
|
+
},
|
|
30
|
+
/** Reports the destination's own serialized value selection. */
|
|
31
|
+
get value() {
|
|
32
|
+
return getServerContext().value;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
actions: {
|
|
36
|
+
/** Navigates using the router without a document reload. */
|
|
37
|
+
navigate: withSyncEvent( function* ( event ) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
const { actions } =
|
|
40
|
+
yield import( '@wordpress/interactivity-router' );
|
|
41
|
+
yield actions.navigate( event.target.href );
|
|
42
|
+
} ),
|
|
43
|
+
/** Resolves null HTML or registers the pending derived getter. */
|
|
44
|
+
resolve() {
|
|
45
|
+
getContext().resolved = true;
|
|
46
|
+
store( 'router-html', {
|
|
47
|
+
state: {
|
|
48
|
+
/** Supplies a late token after the pending destination loads. */
|
|
49
|
+
get late() {
|
|
50
|
+
return tokens.U;
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
} );
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
} );
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"name": "test/router-navigation-full-page",
|
|
5
|
+
"title": "E2E Interactivity tests - router navigation full-page mode",
|
|
6
|
+
"category": "text",
|
|
7
|
+
"icon": "heart",
|
|
8
|
+
"description": "",
|
|
9
|
+
"supports": {
|
|
10
|
+
"interactivity": true
|
|
11
|
+
},
|
|
12
|
+
"textdomain": "e2e-interactivity",
|
|
13
|
+
"viewScriptModule": "file:./view.js",
|
|
14
|
+
"render": "file:./render.php"
|
|
15
|
+
}
|