-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathrender.php
235 lines (227 loc) · 6.06 KB
/
render.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* HTML for testing the directive `data-wp-context`.
*
* @package gutenberg-test-interactive-blocks
*/
?>
<div data-wp-interactive='{"namespace": "directive-context"}'>
<div
data-wp-context='{ "prop1":"parent","prop2":"parent","obj":{"prop4":"parent","prop5":"parent"},"array":[1,2,3] }'
>
<pre
data-testid="parent context"
data-wp-bind--children="state.renderContext"
>
<!-- rendered during hydration -->
</pre>
<button data-testid="parent replace" data-wp-on--click="actions.replaceObj">Replace obj</button>
<button
data-testid="parent prop1"
name="prop1"
value="modifiedFromParent"
data-wp-on--click="actions.updateContext"
>
prop1
</button>
<button
data-testid="parent prop2"
name="prop2"
value="modifiedFromParent"
data-wp-on--click="actions.updateContext"
>
prop2
</button>
<button
data-testid="parent obj.prop4"
name="obj.prop4"
value="modifiedFromParent"
data-wp-on--click="actions.updateContext"
>
obj.prop4
</button>
<button
data-testid="parent obj.prop5"
name="obj.prop5"
value="modifiedFromParent"
data-wp-on--click="actions.updateContext"
>
obj.prop5
</button>
<button
data-testid="parent new"
name="new"
value="modifiedFromParent"
data-wp-on--click="actions.updateContext"
>
new
</button>
<div
data-wp-context='{ "prop2":"child","prop3":"child","obj":{"prop5":"child","prop6":"child"},"array":[4,5,6] }'
>
<pre
data-testid="child context"
data-wp-bind--children="state.renderContext"
>
<!-- rendered during hydration -->
</pre>
<button data-testid="child replace" data-wp-on--click="actions.replaceObj">Replace obj</button>
<button
data-testid="child prop1"
name="prop1"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
prop1
</button>
<button
data-testid="child prop2"
name="prop2"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
prop2
</button>
<button
data-testid="child prop3"
name="prop3"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
prop3
</button>
<button
data-testid="child obj.prop4"
name="obj.prop4"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
obj.prop4
</button>
<button
data-testid="child obj.prop5"
name="obj.prop5"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
obj.prop5
</button>
<button
data-testid="child obj.prop6"
name="obj.prop6"
value="modifiedFromChild"
data-wp-on--click="actions.updateContext"
>
obj.prop6
</button>
<button
data-testid="child copy obj"
data-wp-on--click="actions.copyObj"
>
Copy obj
</button>
<div>
Is proxy preserved? <span
data-testid="is proxy preserved"
data-wp-text="state.isProxyPreserved"
></span>
</div>
<div>
Is proxy preserved on copy? <span
data-testid="is proxy preserved on copy"
data-wp-text="state.isProxyPreservedOnCopy"
></span>
</div>
</div>
<br />
<button
data-testid="context & other directives"
data-wp-context='{ "text": "Text 1" }'
data-wp-text="context.text"
data-wp-on--click="actions.toggleContextText"
data-wp-bind--value="context.text"
>
Toggle Context Text
</button>
</div>
</div>
<div
data-wp-interactive='{"namespace": "directive-context-navigate"}'
data-wp-router-region="navigation"
data-wp-context='{ "text": "first page" }'
>
<div data-wp-context='{}'>
<div data-testid="navigation inherited text" data-wp-text="context.text"></div>
<div data-testid="navigation inherited text2" data-wp-text="context.text2"></div>
</div>
<div data-testid="navigation text" data-wp-text="context.text"></div>
<div data-testid="navigation new text" data-wp-text="context.newText"></div>
<button data-testid="toggle text" data-wp-on--click="actions.toggleText">Toggle Text</button>
<button data-testid="add new text" data-wp-on--click="actions.addNewText">Add New Text</button>
<button data-testid="add text2" data-wp-on--click="actions.addText2">Add Text 2</button>
<button data-testid="navigate" data-wp-on--click="actions.navigate">Navigate</button>
<button data-testid="async navigate" data-wp-on--click="actions.asyncNavigate">Async Navigate</button>
</div>
<div
data-wp-interactive='{"namespace": "directive-context-non-default"}'
data-wp-context--non-default='{ "text": "non default" }'
data-wp-context='{ "defaultText": "default" }'
>
<span data-testid="non-default suffix context" data-wp-text="context.text"></span>
<span data-testid="default suffix context" data-wp-text="context.defaultText"></span>
</div>
<div
data-wp-interactive='directive-context'
data-wp-context='{ "list": [
{ "id": 1, "text": "Text 1" },
{ "id": 2, "text": "Text 2" }
] }'
>
<button data-testid="select 1" data-wp-on--click="actions.selectItem" value=1>Select 1</button>
<button data-testid="select 2" data-wp-on--click="actions.selectItem" value=2>Select 2</button>
<div data-testid="selected" data-wp-text="state.selected"></div>
</div>
<div
data-wp-interactive="directive-context-watch"
data-wp-context='{"counter":0}'
>
<button
data-testid="counter parent"
data-wp-on--click="actions.increment"
data-wp-text="context.counter"
></button>
<div
data-wp-context='{"counter":0, "changes":0}'
data-wp-watch="callbacks.countChanges"
>
<button
data-testid="counter child"
data-wp-on--click="actions.increment"
data-wp-text="context.counter"
>
</button>
<span
data-testid="counter changes"
data-wp-text="context.changes"
></span>
</div>
</div>
<div
data-testid="inheritance from other namespaces"
data-wp-interactive="directive-context/parent"
data-wp-context='{ "prop": "fromParentNs" }'
>
<div
data-wp-interactive="directive-context/child"
data-wp-context='{ "prop": "fromChildNs" }'
>
<span
data-testid="parent"
data-wp-text="directive-context/parent::context.prop"
></span>
<span
data-testid="child"
data-wp-text="directive-context/child::context.prop"
></span>
</div>
</div>