-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
example.html
123 lines (121 loc) · 4.81 KB
/
example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Alpine.js Devtools Example</title>
<!-- <script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script> -->
<!-- Rollup server is configured to serve contents of node_modules/alpinejs/dist, see rollup.config.js -->
<!-- Uncomment the following script to use that version, eg. when working offline -->
<script src="/alpine.js" defer></script>
</head>
<body>
<div
x-data="{
el: $el,
els: [$el],
nestedUnserializable: { el: $el, nestedFn() {}, array: [ { hello: 'world' }] },
myFunction() { return true },
bool: true,
num: 5,
str: 'string',
arr: ['world', 'bar'],
nestedObjArr: { array: [ { nested: 'property' }] },
}"
>
<div>Bool, type: "<span x-text="typeof bool"></span>", value: "<span x-text="bool"></span>"</div>
<div>Num, type: "<span x-text="typeof num"></span>", value: "<span x-text="num"></span>"</div>
<div>Str, type: "<span x-text="typeof str"></span>", value: "<span x-text="str"></span>"</div>
<div>
Arr, type: "<span x-text="typeof arr"></span>", value (stringified): "<span
x-text="JSON.stringify(arr)"
></span
>"
</div>
<div>
Nested serializable array/object value (stringified): "<span
data-testid="nested-obj-arr"
x-text="JSON.stringify(nestedObjArr)"
></span
>"
</div>
</div>
<!-- can be used to test jQuery interop stuff -->
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div name="jQuery-test" x-data="{ el: $($el) }"></div>
-->
<div id="app" x-data="{ hello: 'world' }">
<span x-text="hello"></span>
</div>
<div x-data="myFn()">
<span x-text="hello"></span>
</div>
<div name="component" x-data="{ hello: 'world' }">
<span x-text="hello"></span>
</div>
<div role="combobox" x-data="{ hello: 'world' }">
<span x-text="hello"></span>
<div x-data x-title="nested1">
Nesting 1
<div x-data x-title="nested2">Nesting 2</div>
</div>
</div>
<div x-title="model-no-render" x-data="{ text: 'initial', model: { nested: 'nested-initial' } }">
<label>
Doesn't re-render but has x-model
<input type="text" x-model="text" data-testid="model-no-render" />
</label>
<label>
x-model on nested value
<input type="text" x-model="model.nested" data-testid="nested-model-no-render" />
</label>
</div>
<button
data-testid="replace-component-button"
onclick="event.target.parentNode.replaceChild(window.span, event.target)"
x-data
x-title="Replaceable"
>
Press to replace self with a new component
</button>
<br />
<button
x-data
x-title="Inserts others"
data-testid="add-component-button"
onclick="event.target.insertAdjacentHTML(
'afterend',
`
<button data-testid='delete-component-button' onclick='event.target.remove()' x-data x-title='Inserted'>Press to remove self</button>
`
)"
>
Add new component
</button>
<br />
<script>
// For testing inserting. Will insert anywhere.
window.span = document.createElement('span')
window.span.setAttribute('x-data', '')
window.span.setAttribute('x-title', 'Span')
window.span.setAttribute('x-text', `"I'm an Alpine component"`)
</script>
<script>
function myFn() {
return {
hello: 'world',
}
}
</script>
<button data-testid="inject-broken" onclick="injectBroken(event.target)">Inject broken component</button>
<script>
function injectBroken(target) {
target.insertAdjacentHTML('afterend', `<div x-data="{ foo: 'aaa' ">Broken x-data</div>`)
}
</script>
<button data-testid="broken-click" x-data x-on:click="foo.bar.baz">Broken x-on:click</button>
<div>
<a data-testid="navigation-target" href="/navigation-target.html">Go to next page</a>
</div>
</body>
</html>