@wordpress/e2e-tests 7.16.0 → 7.18.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 +4 -0
- package/package.json +8 -7
- package/plugins/block-icons/index.js +1 -1
- package/plugins/dataviews.php +25 -0
- package/plugins/interactive-blocks/directive-bind/render.php +3 -1
- package/plugins/interactive-blocks/directive-bind/view.js +32 -29
- package/plugins/interactive-blocks/directive-body/render.php +3 -1
- package/plugins/interactive-blocks/directive-body/view.js +11 -9
- package/plugins/interactive-blocks/directive-class/render.php +3 -1
- package/plugins/interactive-blocks/directive-class/view.js +20 -18
- package/plugins/interactive-blocks/directive-context/render.php +6 -4
- package/plugins/interactive-blocks/directive-context/view.js +49 -40
- package/plugins/interactive-blocks/directive-init/render.php +8 -6
- package/plugins/interactive-blocks/directive-init/view.js +59 -60
- package/plugins/interactive-blocks/directive-key/render.php +5 -1
- package/plugins/interactive-blocks/directive-key/view.js +18 -14
- package/plugins/interactive-blocks/directive-on/render.php +3 -1
- package/plugins/interactive-blocks/directive-on/view.js +27 -24
- package/plugins/interactive-blocks/directive-priorities/render.php +7 -2
- package/plugins/interactive-blocks/directive-priorities/view.js +107 -111
- package/plugins/interactive-blocks/directive-slots/render.php +3 -1
- package/plugins/interactive-blocks/directive-slots/view.js +17 -15
- package/plugins/interactive-blocks/directive-style/render.php +2 -1
- package/plugins/interactive-blocks/directive-style/view.js +21 -19
- package/plugins/interactive-blocks/directive-text/render.php +3 -1
- package/plugins/interactive-blocks/directive-text/view.js +16 -14
- package/plugins/interactive-blocks/{store-afterload → directive-watch}/block.json +3 -3
- package/plugins/interactive-blocks/{directive-effect → directive-watch}/render.php +8 -6
- package/plugins/interactive-blocks/directive-watch/view.js +53 -0
- package/plugins/interactive-blocks/negation-operator/render.php +4 -2
- package/plugins/interactive-blocks/negation-operator/view.js +15 -19
- package/plugins/interactive-blocks/router-navigate/render.php +11 -8
- package/plugins/interactive-blocks/router-navigate/view.js +27 -34
- package/plugins/interactive-blocks/router-regions/render.php +13 -3
- package/plugins/interactive-blocks/router-regions/view.js +37 -35
- package/plugins/interactive-blocks/store-tag/render.php +7 -4
- package/plugins/interactive-blocks/store-tag/view.js +19 -19
- package/plugins/interactive-blocks/tovdom/render.php +3 -1
- package/plugins/interactive-blocks/tovdom/view.js +5 -4
- package/plugins/interactive-blocks/tovdom-islands/render.php +11 -6
- package/plugins/interactive-blocks/tovdom-islands/view.js +24 -23
- package/plugins/interactive-blocks.php +4 -4
- package/specs/editor/various/datepicker.test.js +8 -8
- package/specs/editor/various/pattern-blocks.test.js +4 -4
- package/specs/editor/various/scheduling.test.js +1 -1
- package/plugins/interactive-blocks/directive-effect/block.json +0 -14
- package/plugins/interactive-blocks/directive-effect/view.js +0 -59
- package/plugins/interactive-blocks/store-afterload/render.php +0 -41
- package/plugins/interactive-blocks/store-afterload/view.js +0 -60
- package/specs/editor/plugins/__snapshots__/align-hook.test.js.snap +0 -43
- package/specs/editor/plugins/__snapshots__/block-directory-add.test.js.snap +0 -3
- package/specs/editor/plugins/__snapshots__/container-blocks.test.js.snap +0 -58
- package/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +0 -147
- package/specs/editor/plugins/__snapshots__/inner-blocks-render-appender.test.js.snap +0 -25
- package/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap +0 -9
- package/specs/editor/plugins/__snapshots__/plugins-api.test.js.snap +0 -7
- package/specs/editor/plugins/align-hook.test.js +0 -234
- package/specs/editor/plugins/annotations.test.js +0 -189
- package/specs/editor/plugins/block-directory-add.test.js +0 -205
- package/specs/editor/plugins/block-icons.test.js +0 -170
- package/specs/editor/plugins/child-blocks.test.js +0 -66
- package/specs/editor/plugins/container-blocks.test.js +0 -130
- package/specs/editor/plugins/cpt-locking.test.js +0 -251
- package/specs/editor/plugins/custom-taxonomies.test.js +0 -61
- package/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.test.js +0 -132
- package/specs/editor/plugins/inner-blocks-render-appender.test.js +0 -126
- package/specs/editor/plugins/meta-attribute-block.test.js +0 -100
- package/specs/editor/plugins/meta-boxes.test.js +0 -137
- package/specs/editor/plugins/plugins-api.test.js +0 -189
- package/specs/editor/various/is-typing.test.js +0 -101
- package/specs/editor/various/publish-button.test.js +0 -46
- package/specs/editor/various/sidebar-permalink.test.js +0 -53
@@ -1,27 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store, getContext } from '@wordpress/interactivity';
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
const { state } = store( 'directive-on', {
|
7
|
+
state: {
|
8
|
+
counter: 0,
|
9
|
+
text: '',
|
10
|
+
},
|
11
|
+
actions: {
|
12
|
+
clickHandler: ( event ) => {
|
13
|
+
state.counter += 1;
|
14
|
+
event.target.dispatchEvent(
|
15
|
+
new CustomEvent( 'customevent', { bubbles: true } )
|
16
|
+
);
|
8
17
|
},
|
9
|
-
|
10
|
-
|
11
|
-
state.counter += 1;
|
12
|
-
event.target.dispatchEvent(
|
13
|
-
new CustomEvent( 'customevent', { bubbles: true } )
|
14
|
-
);
|
15
|
-
},
|
16
|
-
inputHandler: ( { state, event } ) => {
|
17
|
-
state.text = event.target.value;
|
18
|
-
},
|
19
|
-
selectHandler: ( { context, event } ) => {
|
20
|
-
context.option = event.target.value;
|
21
|
-
},
|
22
|
-
customEventHandler: ({ context }) => {
|
23
|
-
context.customEvents += 1;
|
24
|
-
},
|
18
|
+
inputHandler: ( event ) => {
|
19
|
+
state.text = event.target.value;
|
25
20
|
},
|
26
|
-
|
27
|
-
|
21
|
+
selectHandler: ( event ) => {
|
22
|
+
const context = getContext();
|
23
|
+
context.option = event.target.value;
|
24
|
+
},
|
25
|
+
customEventHandler: () => {
|
26
|
+
const context = getContext();
|
27
|
+
context.customEvents += 1;
|
28
|
+
},
|
29
|
+
},
|
30
|
+
} );
|
@@ -5,8 +5,10 @@
|
|
5
5
|
* @package gutenberg-test-interactive-blocks
|
6
6
|
*/
|
7
7
|
|
8
|
+
gutenberg_enqueue_module( 'directive-priorities-view' );
|
8
9
|
?>
|
9
|
-
|
10
|
+
|
11
|
+
<div data-wp-interactive='{ "namespace": "directive-priorities" }'>
|
10
12
|
<pre data-testid="execution order"></pre>
|
11
13
|
|
12
14
|
<!-- Element with test directives -->
|
@@ -20,5 +22,8 @@
|
|
20
22
|
</div>
|
21
23
|
|
22
24
|
<div data-testid="non-existent-directives">
|
23
|
-
|
25
|
+
<!-- WARNING: the `div` with `data-wp-non-existent-directive` should remain
|
26
|
+
inline (i.e., without new line or blank characters in between) to
|
27
|
+
ensure it is the only child node. Otherwise, tests could fail. -->
|
28
|
+
<div data-wp-interactive='{ "namespace": "directive-priorities" }'><div data-wp-non-existent-directive></div></div>
|
24
29
|
</div>
|
@@ -1,121 +1,117 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
} = wp.interactivity;
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import {
|
5
|
+
store,
|
6
|
+
getContext,
|
7
|
+
directive,
|
8
|
+
deepSignal,
|
9
|
+
useEffect,
|
10
|
+
createElement as h,
|
11
|
+
} from '@wordpress/interactivity';
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
*/
|
19
|
-
const executionProof = ( n ) => {
|
20
|
-
const el = document.querySelector( '[data-testid="execution order"]' );
|
21
|
-
if ( ! el.textContent ) el.textContent = n;
|
22
|
-
else el.textContent += `, ${ n }`;
|
23
|
-
};
|
13
|
+
/**
|
14
|
+
* Namespace used in custom directives and store.
|
15
|
+
*/
|
16
|
+
const namespace = 'directive-priorities';
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
18
|
+
/**
|
19
|
+
* Util to check that render calls happen in order.
|
20
|
+
*
|
21
|
+
* @param {string} n Name passed from the directive being executed.
|
22
|
+
*/
|
23
|
+
const executionProof = ( n ) => {
|
24
|
+
const el = document.querySelector( '[data-testid="execution order"]' );
|
25
|
+
if ( ! el.textContent ) el.textContent = n;
|
26
|
+
else el.textContent += `, ${ n }`;
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Simple context directive, just for testing purposes. It provides a deep
|
31
|
+
* signal with these two properties:
|
32
|
+
* - attribute: 'from context'
|
33
|
+
* - text: 'from context'
|
34
|
+
*/
|
35
|
+
directive(
|
36
|
+
'test-context',
|
37
|
+
( { context: { Provider }, props: { children } } ) => {
|
38
|
+
executionProof( 'context' );
|
39
|
+
const value = deepSignal( {
|
40
|
+
[ namespace ]: {
|
36
41
|
attribute: 'from context',
|
37
42
|
text: 'from context',
|
38
|
-
}
|
39
|
-
return h( Provider, { value }, children );
|
40
|
-
},
|
41
|
-
{ priority: 8 }
|
42
|
-
);
|
43
|
-
|
44
|
-
/**
|
45
|
-
* Simple attribute directive, for testing purposes. It reads the value of
|
46
|
-
* `attribute` from context and populates `data-attribute` with it.
|
47
|
-
*/
|
48
|
-
directive( 'test-attribute', ( { context, evaluate, element } ) => {
|
49
|
-
executionProof( 'attribute' );
|
50
|
-
const contextValue = useContext( context );
|
51
|
-
const attributeValue = evaluate( 'context.attribute', {
|
52
|
-
context: contextValue,
|
43
|
+
},
|
53
44
|
} );
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
45
|
+
return h( Provider, { value }, children );
|
46
|
+
},
|
47
|
+
{ priority: 8 }
|
48
|
+
);
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Simple attribute directive, for testing purposes. It reads the value of
|
52
|
+
* `attribute` from context and populates `data-attribute` with it.
|
53
|
+
*/
|
54
|
+
directive( 'test-attribute', ( { evaluate, element } ) => {
|
55
|
+
executionProof( 'attribute' );
|
56
|
+
const attributeValue = evaluate( {
|
57
|
+
namespace,
|
58
|
+
value: 'context.attribute',
|
61
59
|
} );
|
60
|
+
useEffect( () => {
|
61
|
+
element.ref.current.setAttribute( 'data-attribute', attributeValue );
|
62
|
+
}, [] );
|
63
|
+
element.props[ 'data-attribute' ] = attributeValue;
|
64
|
+
} );
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
h( 'p', { 'data-testid': 'text' }, textValue );
|
77
|
-
},
|
78
|
-
{ priority: 12 }
|
79
|
-
);
|
66
|
+
/**
|
67
|
+
* Simple text directive, for testing purposes. It reads the value of
|
68
|
+
* `text` from context and populates `children` with it.
|
69
|
+
*/
|
70
|
+
directive(
|
71
|
+
'test-text',
|
72
|
+
( { evaluate, element } ) => {
|
73
|
+
executionProof( 'text' );
|
74
|
+
const textValue = evaluate( { namespace, value: 'context.text' } );
|
75
|
+
element.props.children = h( 'p', { 'data-testid': 'text' }, textValue );
|
76
|
+
},
|
77
|
+
{ priority: 12 }
|
78
|
+
);
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
);
|
107
|
-
},
|
108
|
-
{ priority: 14 }
|
109
|
-
);
|
80
|
+
/**
|
81
|
+
* Children directive, for testing purposes. It adds a wrapper around
|
82
|
+
* `children`, including two buttons to modify `text` and `attribute` values
|
83
|
+
* from the received context.
|
84
|
+
*/
|
85
|
+
directive(
|
86
|
+
'test-children',
|
87
|
+
( { evaluate, element } ) => {
|
88
|
+
executionProof( 'children' );
|
89
|
+
const updateAttribute = () => {
|
90
|
+
evaluate( { namespace, value: 'actions.updateAttribute' } );
|
91
|
+
};
|
92
|
+
const updateText = () => {
|
93
|
+
evaluate( { namespace, value: 'actions.updateText' } );
|
94
|
+
};
|
95
|
+
element.props.children = h(
|
96
|
+
'div',
|
97
|
+
{},
|
98
|
+
element.props.children,
|
99
|
+
h( 'button', { onClick: updateAttribute }, 'Update attribute' ),
|
100
|
+
h( 'button', { onClick: updateText }, 'Update text' )
|
101
|
+
);
|
102
|
+
},
|
103
|
+
{ priority: 14 }
|
104
|
+
);
|
110
105
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
updateAttribute( { context } ) {
|
117
|
-
context.attribute = 'updated';
|
118
|
-
},
|
106
|
+
store( 'directive-priorities', {
|
107
|
+
actions: {
|
108
|
+
updateText() {
|
109
|
+
const context = getContext();
|
110
|
+
context.text = 'updated';
|
119
111
|
},
|
120
|
-
|
121
|
-
|
112
|
+
updateAttribute() {
|
113
|
+
const context = getContext();
|
114
|
+
context.attribute = 'updated';
|
115
|
+
},
|
116
|
+
},
|
117
|
+
} );
|
@@ -5,9 +5,11 @@
|
|
5
5
|
* @package gutenberg-test-interactive-blocks
|
6
6
|
*/
|
7
7
|
|
8
|
+
gutenberg_enqueue_module( 'directive-slots-view' );
|
8
9
|
?>
|
10
|
+
|
9
11
|
<div
|
10
|
-
data-wp-interactive
|
12
|
+
data-wp-interactive='{ "namespace": "directive-slots" }'
|
11
13
|
data-wp-slot-provider
|
12
14
|
data-wp-context='{ "text": "fill" }'
|
13
15
|
>
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store, getContext } from '@wordpress/interactivity';
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
const { state } = store( 'directive-slots', {
|
7
|
+
state: {
|
8
|
+
slot: '',
|
9
|
+
},
|
10
|
+
actions: {
|
11
|
+
changeSlot( event ) {
|
12
|
+
state.slot = event.target.dataset.slot;
|
7
13
|
},
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
updateSlotText: ( { context } ) => {
|
13
|
-
const n = context.text[1];
|
14
|
-
context.text = `[${n} updated]`;
|
15
|
-
},
|
14
|
+
updateSlotText() {
|
15
|
+
const context = getContext();
|
16
|
+
const n = context.text[ 1 ];
|
17
|
+
context.text = `[${ n } updated]`;
|
16
18
|
},
|
17
|
-
}
|
18
|
-
} )
|
19
|
+
},
|
20
|
+
} );
|
@@ -5,9 +5,10 @@
|
|
5
5
|
* @package gutenberg-test-interactive-blocks
|
6
6
|
*/
|
7
7
|
|
8
|
+
gutenberg_enqueue_module( 'directive-style-view' );
|
8
9
|
?>
|
9
10
|
|
10
|
-
<div data-wp-interactive>
|
11
|
+
<div data-wp-interactive='{ "namespace": "directive-style" }'>
|
11
12
|
<button
|
12
13
|
data-wp-on--click="actions.toggleColor"
|
13
14
|
data-testid="toggle color"
|
@@ -1,22 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store, getContext } from '@wordpress/interactivity';
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
const { state } = store( 'directive-style', {
|
7
|
+
state: {
|
8
|
+
falseValue: false,
|
9
|
+
color: 'red',
|
10
|
+
border: '2px solid yellow',
|
11
|
+
},
|
12
|
+
actions: {
|
13
|
+
toggleColor() {
|
14
|
+
state.color = state.color === 'red' ? 'blue' : 'red';
|
9
15
|
},
|
10
|
-
|
11
|
-
|
12
|
-
state.color = state.color === "red" ? "blue" : "red";
|
13
|
-
},
|
14
|
-
switchColorToFalse: ({ state }) => {
|
15
|
-
state.color = false;
|
16
|
-
},
|
17
|
-
toggleContext: ( { context } ) => {
|
18
|
-
context.color = context.color === "red" ? "blue" : "red";
|
19
|
-
},
|
16
|
+
switchColorToFalse() {
|
17
|
+
state.color = false;
|
20
18
|
},
|
21
|
-
|
22
|
-
|
19
|
+
toggleContext() {
|
20
|
+
const context = getContext();
|
21
|
+
context.color = context.color === 'red' ? 'blue' : 'red';
|
22
|
+
},
|
23
|
+
},
|
24
|
+
} );
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store, getContext } from '@wordpress/interactivity';
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
const { state } = store( 'directive-context', {
|
7
|
+
state: {
|
8
|
+
text: 'Text 1',
|
9
|
+
},
|
10
|
+
actions: {
|
11
|
+
toggleStateText() {
|
12
|
+
state.text = state.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
7
13
|
},
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
},
|
12
|
-
toggleContextText: ( { context } ) => {
|
13
|
-
context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
14
|
-
},
|
14
|
+
toggleContextText() {
|
15
|
+
const context = getContext();
|
16
|
+
context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
15
17
|
},
|
16
|
-
}
|
17
|
-
} )
|
18
|
+
},
|
19
|
+
} );
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"apiVersion": 2,
|
3
|
-
"name": "test/
|
4
|
-
"title": "E2E Interactivity tests -
|
3
|
+
"name": "test/directive-watch",
|
4
|
+
"title": "E2E Interactivity tests - directive watch",
|
5
5
|
"category": "text",
|
6
6
|
"icon": "heart",
|
7
7
|
"description": "",
|
@@ -9,6 +9,6 @@
|
|
9
9
|
"interactivity": true
|
10
10
|
},
|
11
11
|
"textdomain": "e2e-interactivity",
|
12
|
-
"viewScript": "
|
12
|
+
"viewScript": "directive-watch-view",
|
13
13
|
"render": "file:./render.php"
|
14
14
|
}
|
@@ -1,29 +1,31 @@
|
|
1
1
|
<?php
|
2
2
|
/**
|
3
|
-
* HTML for testing the directive `data-wp-
|
3
|
+
* HTML for testing the directive `data-wp-watch`.
|
4
4
|
*
|
5
5
|
* @package gutenberg-test-interactive-blocks
|
6
6
|
*/
|
7
7
|
|
8
|
+
gutenberg_enqueue_module( 'directive-watch-view' );
|
8
9
|
?>
|
9
|
-
|
10
|
+
|
11
|
+
<div data-wp-interactive='{ "namespace": "directive-watch" }'>
|
10
12
|
<div data-wp-show-mock="state.isOpen">
|
11
13
|
<input
|
12
14
|
data-testid="input"
|
13
|
-
data-wp-
|
15
|
+
data-wp-watch="callbacks.elementAddedToTheDOM"
|
14
16
|
/>
|
15
17
|
</div>
|
16
18
|
|
17
19
|
<div
|
18
|
-
data-wp-text="
|
20
|
+
data-wp-text="state.elementInTheDOM"
|
19
21
|
data-testid="element in the DOM"
|
20
22
|
></div>
|
21
23
|
|
22
|
-
<div data-wp-
|
24
|
+
<div data-wp-watch="callbacks.changeFocus"></div>
|
23
25
|
|
24
26
|
<div
|
25
27
|
data-testid="short-circuit infinite loops"
|
26
|
-
data-wp-
|
28
|
+
data-wp-watch="callbacks.infiniteLoop"
|
27
29
|
data-wp-text="state.counter"
|
28
30
|
>
|
29
31
|
0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store, directive } from '@wordpress/interactivity';
|
5
|
+
|
6
|
+
// Fake `data-wp-show-mock` directive to test when things are removed from the
|
7
|
+
// DOM. Replace with `data-wp-show` when it's ready.
|
8
|
+
directive(
|
9
|
+
'show-mock',
|
10
|
+
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
|
11
|
+
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
|
12
|
+
if ( ! evaluate( entry ) ) return null;
|
13
|
+
return element;
|
14
|
+
}
|
15
|
+
);
|
16
|
+
|
17
|
+
const { state } = store( 'directive-watch', {
|
18
|
+
state: {
|
19
|
+
isOpen: true,
|
20
|
+
isElementInTheDOM: false,
|
21
|
+
counter: 0,
|
22
|
+
get elementInTheDOM() {
|
23
|
+
return state.isElementInTheDOM
|
24
|
+
? 'element is in the DOM'
|
25
|
+
: 'element is not in the DOM';
|
26
|
+
},
|
27
|
+
},
|
28
|
+
actions: {
|
29
|
+
toggle() {
|
30
|
+
state.isOpen = ! state.isOpen;
|
31
|
+
},
|
32
|
+
increment() {
|
33
|
+
state.counter = state.counter + 1;
|
34
|
+
},
|
35
|
+
},
|
36
|
+
callbacks: {
|
37
|
+
elementAddedToTheDOM: () => {
|
38
|
+
state.isElementInTheDOM = true;
|
39
|
+
|
40
|
+
return () => {
|
41
|
+
state.isElementInTheDOM = false;
|
42
|
+
};
|
43
|
+
},
|
44
|
+
changeFocus: () => {
|
45
|
+
if ( state.isOpen ) {
|
46
|
+
document.querySelector( "[data-testid='input']" ).focus();
|
47
|
+
}
|
48
|
+
},
|
49
|
+
infiniteLoop: () => {
|
50
|
+
state.counter = state.counter + 1;
|
51
|
+
},
|
52
|
+
},
|
53
|
+
} );
|
@@ -5,8 +5,10 @@
|
|
5
5
|
* @package gutenberg-test-interactive-blocks
|
6
6
|
*/
|
7
7
|
|
8
|
+
gutenberg_enqueue_module( 'negation-operator-view' );
|
8
9
|
?>
|
9
|
-
|
10
|
+
|
11
|
+
<div data-wp-interactive='{ "namespace": "negation-operator" }'>
|
10
12
|
<button
|
11
13
|
data-wp-on--click="actions.toggle"
|
12
14
|
data-testid="toggle active value"
|
@@ -20,7 +22,7 @@
|
|
20
22
|
></div>
|
21
23
|
|
22
24
|
<div
|
23
|
-
data-wp-bind--hidden="!
|
25
|
+
data-wp-bind--hidden="!state.isActive"
|
24
26
|
data-testid="add hidden attribute if selector is not active"
|
25
27
|
></div>
|
26
28
|
</div>
|
@@ -1,22 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const { store } = wp.interactivity;
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
import { store } from '@wordpress/interactivity';
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
const { state } = store( 'negation-operator', {
|
7
|
+
state: {
|
8
|
+
active: false,
|
9
|
+
get isActive() {
|
10
|
+
return state.active;
|
12
11
|
},
|
13
|
-
|
14
|
-
|
12
|
+
},
|
13
|
+
actions: {
|
14
|
+
toggle() {
|
15
|
+
state.active = ! state.active;
|
15
16
|
},
|
16
|
-
|
17
|
-
|
18
|
-
state.active = ! state.active;
|
19
|
-
},
|
20
|
-
},
|
21
|
-
} );
|
22
|
-
} )( window );
|
17
|
+
},
|
18
|
+
} );
|