lightview 1.7.2-b → 1.8.2
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/README.md +15 -16
- package/docs/CNAME +1 -0
- package/docs/api.html +674 -0
- package/docs/blank.html +10 -0
- package/docs/comparedto.html +89 -0
- package/docs/components/chart-repl.html +69 -0
- package/docs/components/chart.html +17 -0
- package/{components → docs/components}/components.js +31 -11
- package/docs/components/contents.html +17 -0
- package/docs/components/gantt-repl.html +61 -0
- package/docs/components/gantt.html +42 -0
- package/docs/components/gauge-repl.html +66 -0
- package/docs/components/gauge.html +20 -0
- package/docs/components/orgchart-repl.html +64 -0
- package/docs/components/orgchart.html +41 -0
- package/docs/components/repl-as-src.html +17 -0
- package/docs/components/repl-repl.html +95 -0
- package/docs/components/repl.html +527 -0
- package/docs/components/timeline-repl.html +72 -0
- package/docs/components/timeline.html +44 -0
- package/docs/components.html +14 -0
- package/docs/css/highlightjs.min.css +9 -0
- package/docs/css/tutorial.css +35 -0
- package/docs/examples/anchor.html +11 -0
- package/{components/chart/example.html → docs/examples/chart.html} +6 -4
- package/docs/examples/counter.html +26 -0
- package/{examples → docs/examples}/counter.test.mjs +0 -0
- package/docs/examples/counter2.html +26 -0
- package/{examples → docs/examples}/directives.html +20 -18
- package/{examples → docs/examples}/foreign.html +1 -1
- package/docs/examples/forgeinform.html +98 -0
- package/docs/examples/form.html +61 -0
- package/{examples → docs/examples}/gauge.html +4 -2
- package/{examples → docs/examples}/invalid-template-literals.html +6 -4
- package/{examples → docs/examples}/medium/remote.html +1 -1
- package/docs/examples/message.html +18 -0
- package/{examples → docs/examples}/nested.html +2 -2
- package/docs/examples/object-bound-form.html +34 -0
- package/{examples → docs/examples}/remote-server.js +0 -0
- package/docs/examples/remote.html +34 -0
- package/{examples → docs/examples}/remote.json +0 -0
- package/{examples → docs/examples}/scratch.html +1 -1
- package/docs/examples/sensors/index.html +44 -0
- package/{examples → docs/examples}/sensors/sensor-server.js +0 -0
- package/docs/examples/shared.html +41 -0
- package/{examples → docs/examples}/template.html +1 -1
- package/{examples → docs/examples}/timeline.html +2 -2
- package/docs/examples/todo.html +40 -0
- package/docs/examples/top.html +10 -0
- package/{examples → docs/examples}/types.html +1 -1
- package/{examples → docs/examples}/xor.html +22 -20
- package/docs/examples.html +25 -0
- package/docs/index.html +44 -0
- package/docs/javascript/codejar.min.js +8 -0
- package/docs/javascript/highlightjs.min.js +1173 -0
- package/docs/javascript/isomorphic-git.js +9 -0
- package/docs/javascript/json5.min.js +1 -0
- package/docs/javascript/lightning-fs.js +1 -0
- package/docs/javascript/lightview.js +1285 -0
- package/docs/javascript/marked.min.js +6 -0
- package/docs/javascript/peerjs.min.js +70 -0
- package/docs/javascript/turndown.js +973 -0
- package/docs/javascript/types.js +606 -0
- package/docs/javascript/utils.js +45 -0
- package/docs/lightview.html +63 -0
- package/docs/old_index.html +965 -0
- package/docs/old_index.md +1132 -0
- package/docs/slidein.html +51 -0
- package/docs/tutorial/0-getting-started.html +67 -0
- package/docs/tutorial/1-intro-to-variables.html +103 -0
- package/docs/tutorial/10-template-components.html +80 -0
- package/docs/tutorial/11-linked-components.html +76 -0
- package/docs/tutorial/12-imported-components.html +67 -0
- package/docs/tutorial/13-input-binding.html +94 -0
- package/docs/tutorial/14-automatic-variable-creation.html +74 -0
- package/docs/tutorial/15-form-binding.html +110 -0
- package/docs/tutorial/16-if-directive.html +60 -0
- package/docs/tutorial/17-loop-directives.html +83 -0
- package/docs/tutorial/18-sanitizing-and-escaping-input.html +79 -0
- package/docs/tutorial/2-imported-and-exported-variables.html +80 -0
- package/docs/tutorial/3-data-types.html +89 -0
- package/docs/tutorial/4-extended-data-types.html +83 -0
- package/docs/tutorial/5-extended-functional-types.html +96 -0
- package/docs/tutorial/5.1-extended-functional-types.html +79 -0
- package/docs/tutorial/5.2-extended-functional-types.html +70 -0
- package/docs/tutorial/6-conventional-javascript.html +75 -0
- package/docs/tutorial/7-monitoring-with-observers.html +107 -0
- package/docs/tutorial/8-event-listeners.html +65 -0
- package/docs/tutorial/9-intro-to-components.html +91 -0
- package/docs/tutorial/contents.html +32 -0
- package/docs/tutorial/my-component.html +29 -0
- package/docs/tutorial/remote-value.json +4 -0
- package/docs/websiterepl.html +46 -0
- package/lightview.js +499 -363
- package/lightview.min.js +1 -0
- package/lightview_good.js +1267 -0
- package/lightview_optimized.js +1274 -0
- package/package.json +7 -2
- package/repl_hold.html +320 -0
- package/test/basic.html +29 -17
- package/test/basic.test.mjs +1 -11
- package/test/extended.html +16 -19
- package/types.js +118 -36
- package/unsplash.key +1 -0
- package/components/chart/chart.html +0 -15
- package/components/chart.html +0 -81
- package/components/gantt/example.html +0 -27
- package/components/gantt/gantt.html +0 -34
- package/components/gauge/example.html +0 -28
- package/components/gauge/guage.html +0 -19
- package/components/gauge.html +0 -57
- package/components/timeline.html +0 -81
- package/examples/chart.html +0 -66
- package/examples/counter.html +0 -24
- package/examples/forgeinform.html +0 -96
- package/examples/form.html +0 -59
- package/examples/message.html +0 -12
- package/examples/object-bound-form.html +0 -32
- package/examples/remote.html +0 -32
- package/examples/sensors/index.html +0 -30
- package/examples/todo.html +0 -38
- package/examples/top.html +0 -10
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Form Binding</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Form Binding
|
|
19
|
+
|
|
20
|
+
Forms allow you to map a set of variables to a single object.
|
|
21
|
+
|
|
22
|
+
If you provide a `value` attribute to a form element and the `value` attribute points to a variable that is an `object`,
|
|
23
|
+
then the values of the input elements of the form will be mapped to properties on the variable using their `name` attributes
|
|
24
|
+
when the form is submitted.
|
|
25
|
+
|
|
26
|
+
*Note*, the default action of the form is prevented unless there is an `action` attribute. Also, auto bound forms handle their inputs
|
|
27
|
+
on submit, not as the field values change.
|
|
28
|
+
|
|
29
|
+
Currently, the entire object bound to the form value is replaced. Partial updates may be possible in the future.
|
|
30
|
+
|
|
31
|
+
If the variable bound to the form is `reactive`, then any variables bound to the input fields SHOULD NOT be part of the
|
|
32
|
+
form variable, i.e. associated to the form variable via a dot annotated path, because the form variable will already be updated as the values
|
|
33
|
+
change.
|
|
34
|
+
|
|
35
|
+
Forms are also the way you can efficiently collect data without two-way data binding. You simply bind non-reactive variables to the form and the inputs.
|
|
36
|
+
|
|
37
|
+
Try adding an input field to the form.
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<p>Notes: <textarea name="notes"></textarea></p>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Try adding non-reactive variables.
|
|
44
|
+
|
|
45
|
+
<body>
|
|
46
|
+
```html
|
|
47
|
+
<form value="${user}">
|
|
48
|
+
<p>Email: <input name="email" type="email" value="${email}" required></p>
|
|
49
|
+
<p>Phone: <input name="phone" type="tel" value="${phone}" required></p>
|
|
50
|
+
<p><input type="submit"></input></p>
|
|
51
|
+
</form>
|
|
52
|
+
```
|
|
53
|
+
</body>
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
```javascript
|
|
58
|
+
currentComponent.mount = function() {
|
|
59
|
+
this.variables({user:"object"},{set:{}});
|
|
60
|
+
this.variables({email:"string"},{set:"joe@somewhere.com"});
|
|
61
|
+
this.variables({phone:"string"},{set:"555-555-5555"});
|
|
62
|
+
|
|
63
|
+
addEventListener("change",({variableName}) => {
|
|
64
|
+
const el = document.createElement("div");
|
|
65
|
+
el.innerText = JSON.stringify(this.getVariableValue(variableName));
|
|
66
|
+
this.shadowRoot.appendChild(el);
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
</div>
|
|
73
|
+
<button class="nav-previous"><a href="./14-automatic-variable-creation.html" target="content">Previous</a></button>
|
|
74
|
+
<button class="nav-next"><a href="./16-if-directive.html" target="content">Next</a></button>
|
|
75
|
+
</div>
|
|
76
|
+
<div style="float:right;margin-right:10px">
|
|
77
|
+
<h2></h2>
|
|
78
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned previewheight="250px">
|
|
79
|
+
<div slot="bodyhtml"></div>
|
|
80
|
+
<div slot="script"></div>
|
|
81
|
+
<template slot="src">
|
|
82
|
+
<l-head>
|
|
83
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
84
|
+
</l-head>
|
|
85
|
+
<l-body>
|
|
86
|
+
<form value="${user}">
|
|
87
|
+
<p>Email: <input name="email" type="email" required></p>
|
|
88
|
+
<p>Phone: <input name="phone" type="tel" required></p>
|
|
89
|
+
<p><input type="submit"></input></p>
|
|
90
|
+
</form>
|
|
91
|
+
</l-body>
|
|
92
|
+
<script id="lightview">
|
|
93
|
+
currentComponent.mount = function() {
|
|
94
|
+
this.variables({user:"object"},{reactive,set:{}});
|
|
95
|
+
|
|
96
|
+
addEventListener("change",({variableName}) => {
|
|
97
|
+
const el = document.createElement("div");
|
|
98
|
+
el.innerText = JSON.stringify(this.getVariableValue(variableName));
|
|
99
|
+
this.shadowRoot.appendChild(el);
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
</template>
|
|
104
|
+
</l-repl>
|
|
105
|
+
</div>
|
|
106
|
+
<script>
|
|
107
|
+
processMarkdown();
|
|
108
|
+
</script>
|
|
109
|
+
</body>
|
|
110
|
+
</html>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:If Directive</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## If Directive
|
|
19
|
+
|
|
20
|
+
The `l-if` directive supports the conditional display of content. It can be added to any html element. If its value
|
|
21
|
+
is `true`, the element and child nodes are displayed. Otherwise, they are not.
|
|
22
|
+
|
|
23
|
+
Try deleting the line `exposed = true`. Nothing should display.
|
|
24
|
+
|
|
25
|
+
Try adding `hiding = true` to the mount function in the script block. "I am hiding" should display.
|
|
26
|
+
|
|
27
|
+
Try changing `l-if="${hiding}"` to `l-if="${!hiding}"`. Nothing should display.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
</div>
|
|
31
|
+
<button class="nav-previous"><a href="./15-form-binding.html" target="content">Previous</a></button>
|
|
32
|
+
<button class="nav-next"><a href="./17-loop-directives.html" target="content">Next</a></button>
|
|
33
|
+
</div>
|
|
34
|
+
<div style="float:right;margin-right:10px">
|
|
35
|
+
<h2></h2>
|
|
36
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
37
|
+
<div slot="bodyhtml"></div>
|
|
38
|
+
<div slot="script"></div>
|
|
39
|
+
<template slot="src">
|
|
40
|
+
<l-head>
|
|
41
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
42
|
+
</l-head>
|
|
43
|
+
<l-body>
|
|
44
|
+
<p l-if="${exposed}">I am exposed</p>
|
|
45
|
+
<p l-if="${hiding}">I am hiding</p>
|
|
46
|
+
</l-body>
|
|
47
|
+
<script id="lightview">
|
|
48
|
+
currentComponent.mount = function() {
|
|
49
|
+
this.variables({exposed:"boolean",hiding:"boolean"});
|
|
50
|
+
exposed = true;
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
</template>
|
|
54
|
+
</l-repl>
|
|
55
|
+
</div>
|
|
56
|
+
<script>
|
|
57
|
+
processMarkdown();
|
|
58
|
+
</script>
|
|
59
|
+
</body>
|
|
60
|
+
</html>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Loop Directives</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Loop Directives
|
|
19
|
+
|
|
20
|
+
Lightview has a single looping directive, `l-for`, that can be configured to handle objects and arrays and loop over keys, values, or entries
|
|
21
|
+
with default variable names or variable names you provide.
|
|
22
|
+
|
|
23
|
+
The iterator directive takes the form `l-for:?accessor:?itemVariable:?indexVariable:?arrayVariable="${data}"`.
|
|
24
|
+
|
|
25
|
+
The default iterator accessor is `each`. You can also use `entries`, `keys`, and `values`.
|
|
26
|
+
|
|
27
|
+
The default iteration variables are `item`, `index`, and `array`.
|
|
28
|
+
|
|
29
|
+
Try pasting this code into the <body>:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<form value="${person}">
|
|
33
|
+
<div l-for:keys:key="${person}">
|
|
34
|
+
<p></p><label for="${key}">${key}:</label><input id="${key}" value="${person[key]}"></p>
|
|
35
|
+
</div>
|
|
36
|
+
<input type="submit">
|
|
37
|
+
</form>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Try pasting this code into the <body>:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<div l-for:each:child:i:children="${children}">
|
|
44
|
+
<p>${child} has index ${i} in ${JSON.stringify(children)}</p>
|
|
45
|
+
</div>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
</div>
|
|
49
|
+
<button class="nav-previous"><a href="./16-if-directive.html" target="content">Previous</a></button>
|
|
50
|
+
<button class="nav-next"><a href="./18-sanitizing-and-escaping-input.html" target="content">Next</a></button>
|
|
51
|
+
</div>
|
|
52
|
+
<div style="float:right;margin-right:10px">
|
|
53
|
+
<h2></h2>
|
|
54
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
55
|
+
<div slot="headhtml"></div>
|
|
56
|
+
<div slot="bodyhtml"></div>
|
|
57
|
+
<div slot="script"></div>
|
|
58
|
+
<template slot="src">
|
|
59
|
+
<l-head>
|
|
60
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
61
|
+
</l-head>
|
|
62
|
+
<l-body>
|
|
63
|
+
<ul l-for:entries="${person}">
|
|
64
|
+
<li>${item[0]}:${item[1]}</li>
|
|
65
|
+
</ul>
|
|
66
|
+
<ul l-for="${children}">
|
|
67
|
+
<li>${item}</li>
|
|
68
|
+
</ul>
|
|
69
|
+
</l-body>
|
|
70
|
+
<script id="lightview">
|
|
71
|
+
currentComponent.mount = function() {
|
|
72
|
+
this.variables({person:"object"},{set:{email:"joe@somewhere.com",phone:"555-555-5555"}});
|
|
73
|
+
this.variables({children:Array},{set:["mary","john"]});
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
</template>
|
|
77
|
+
</l-repl>
|
|
78
|
+
</div>
|
|
79
|
+
<script>
|
|
80
|
+
processMarkdown();
|
|
81
|
+
</script>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Sanitizing and Escaping HTML</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Sanitizing and Escaping HTML
|
|
19
|
+
|
|
20
|
+
Lightview "sanitizes" templates before attempting to resolve them by making suspicious code unparseable. The result is that the template will simply
|
|
21
|
+
not be replaced in the component. If resolution is successful and the target node is an HTMLElement or Attr, it takes the result of the template
|
|
22
|
+
interpolation and escapes all HTML characters before inserting the value into the DOM. If the target node is a TextNode,
|
|
23
|
+
no escaping is conducted because it is not needed. The DOM will not try to treat the content of a text node like it is HTML, even if it looks like HTML.
|
|
24
|
+
Surprisingly, most of the time, the target will be a TextNode.
|
|
25
|
+
|
|
26
|
+
Note that the only successful substitutions in the REPL are for the button label and the value of `test` plus 1.
|
|
27
|
+
|
|
28
|
+
See the API documentation on [Lightview.sanitizeTemplate](../api.html#sanitizeTemplate) and [Lightview.escapeHTML](../api.html#escapeHTML).
|
|
29
|
+
|
|
30
|
+
This concludes the tutorial. Feel free to post questions to the <a href="https://github.com/anywhichway/lightview/issues" target="_tab">
|
|
31
|
+
GitHub issues page</a>.
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
<button class="nav-previous"><a href="./17-loop-directives.html" target="content">Previous</a></button>
|
|
35
|
+
</div>
|
|
36
|
+
<div style="float:right;margin-right:10px">
|
|
37
|
+
<h2></h2>
|
|
38
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
39
|
+
<div slot="bodyhtml"></div>
|
|
40
|
+
<div slot="script"></div>
|
|
41
|
+
<template slot="src">
|
|
42
|
+
<l-head>
|
|
43
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
44
|
+
</l-head>
|
|
45
|
+
<l-body>
|
|
46
|
+
<p>
|
|
47
|
+
<button l-on:click="${bump}">Click count:${count}</button>
|
|
48
|
+
</p>
|
|
49
|
+
<div style="margin:20px">
|
|
50
|
+
<h1>Test:${test + 1}</h1>
|
|
51
|
+
${"<h1>Test:"+(test++)+"</h1>"}
|
|
52
|
+
<p>
|
|
53
|
+
${(while (test)<10 { test++}; test)}
|
|
54
|
+
</p>
|
|
55
|
+
<p>
|
|
56
|
+
${(() =>test)()}
|
|
57
|
+
</p>
|
|
58
|
+
<p>
|
|
59
|
+
${(() = >test)()}
|
|
60
|
+
</p>
|
|
61
|
+
<p>
|
|
62
|
+
${function(){return \${test}})()}
|
|
63
|
+
</p>
|
|
64
|
+
</div>
|
|
65
|
+
</l-body>
|
|
66
|
+
<script id="lightview">
|
|
67
|
+
currentComponent.mount = async function() {
|
|
68
|
+
self.variables({count: "number",test:"number"}, {reactive,set:0});
|
|
69
|
+
self.bump = () => count++;
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
</template>
|
|
73
|
+
</l-repl>
|
|
74
|
+
</div>
|
|
75
|
+
<script>
|
|
76
|
+
processMarkdown();
|
|
77
|
+
</script>
|
|
78
|
+
</body>
|
|
79
|
+
</html>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Imported and Exported Variables</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../slidein.html" rel="module">
|
|
8
|
+
<link href="../components/repl.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Imported and Exported Variables
|
|
19
|
+
|
|
20
|
+
In addition to being `reactive`, variables can be `imported` from and `exported` to attributes. During this process,
|
|
21
|
+
type coercion occurs.
|
|
22
|
+
|
|
23
|
+
If `imported` variables will never change or you plan to implement DOM updates in an alternate manner, you do not need to declare
|
|
24
|
+
them as `reactive`.
|
|
25
|
+
|
|
26
|
+
Variables can also be automatically exported. Try cut/paste replace the code with the below.
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
currentComponent.mount = function() {
|
|
30
|
+
this.variables({data:Array},{imported});
|
|
31
|
+
this.variables({response:Array},{exported});
|
|
32
|
+
response = '["You","are","in","a","handbasket"]';
|
|
33
|
+
// for demo, since this code is run in a sandbox REPL, attribute changes do not render to the UI
|
|
34
|
+
const el = document.createElement("div");
|
|
35
|
+
el.innerText = self.getAttribute("response");
|
|
36
|
+
this.shadowRoot.appendChild(el);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Variables that are `exported` will always update a component's attributes when they change, they do not need to be
|
|
41
|
+
`reactive` unless you plan to use them elsewhere.
|
|
42
|
+
|
|
43
|
+
*Note*: Because the script is run in a sandbox for security, the REPL itself does not update; hence, the attribute
|
|
44
|
+
value is retrieved and appended to the result to demonstrate that `exported` works.
|
|
45
|
+
|
|
46
|
+
There are also some extended functional types like `remote` to get a variable value from a URL, `shared` and `constant`. These are
|
|
47
|
+
[demonstrated later](./5-extended-functional-types.html).
|
|
48
|
+
|
|
49
|
+
See the API documentation on [variables](../api.html#variables) and [imported](../api.html#imported) or
|
|
50
|
+
[exported](../api.html#exported).
|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
<button class="nav-previous"><a href="./1-intro-to-variables.html" target="content">Previous</a></button>
|
|
54
|
+
<button class="nav-next"><a href="./3-data-types.html" target="content">Next</a></button>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="repl">
|
|
57
|
+
<h2></h2>
|
|
58
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
59
|
+
<div slot="bodyhtml"></div>
|
|
60
|
+
<div slot="script"></div>
|
|
61
|
+
<template slot="src">
|
|
62
|
+
<l-head>
|
|
63
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
64
|
+
</l-head>
|
|
65
|
+
<l-body data="Hello,there,world">
|
|
66
|
+
${data.join(" ")}!
|
|
67
|
+
</l-body>
|
|
68
|
+
<script id="lightview">
|
|
69
|
+
currentComponent.mount = function() {
|
|
70
|
+
this.variables({data:Array},{imported});
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
</template>
|
|
74
|
+
</l-repl>
|
|
75
|
+
</div>
|
|
76
|
+
<script>
|
|
77
|
+
processMarkdown();
|
|
78
|
+
</script>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Data Types</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Data Types
|
|
19
|
+
|
|
20
|
+
Variables in Lightview can be typed as any of the standard JavaScript `typeof` results with the exception of "undefined".
|
|
21
|
+
Runtime coercion is used and errors are thrown if a value can't be coerced into the correct type. If you do not want coercion,
|
|
22
|
+
then use the extended data types described [next](./4-extended-data-types.html).
|
|
23
|
+
|
|
24
|
+
- "boolean"
|
|
25
|
+
Since the focus of Lightview is UI management the values 1, "true", "on", "checked", "selected" all coerce to `true`. The values "false" and 0 coerce to `false`. The value `undefined` remains `undefined`, i.e. an indeterminate state.
|
|
26
|
+
- "function"
|
|
27
|
+
Variables of type "function" are useful for defining event listeners [as described later](./8-event-listeners.html).
|
|
28
|
+
- "number"
|
|
29
|
+
- "object"
|
|
30
|
+
- "string"
|
|
31
|
+
- "symbol"
|
|
32
|
+
|
|
33
|
+
Additionally, variables can be of type "any".
|
|
34
|
+
|
|
35
|
+
And, if you wish, a variable to be an instance of a particular type of object, you can use an unquoted reference to
|
|
36
|
+
any in scope constructor, e.g. `Array` or `MyCustomConstructor`.
|
|
37
|
+
|
|
38
|
+
The REPL is configured to display assignment results and errors. Try modifying the `testVariable` type and assignment.
|
|
39
|
+
Or, cut and paste this example into the code section. Then modify `[1,2,3]` to just be `1` or "1,2,3":
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
currentComponent.mount = function() {
|
|
43
|
+
this.variables({result:"any"},{reactive});
|
|
44
|
+
this.variables({testVariable:Array});
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
testVariable = [1,2,3];
|
|
48
|
+
result = testVariable;
|
|
49
|
+
} catch(e) {
|
|
50
|
+
result = e+"";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
</div>
|
|
55
|
+
<button class="nav-previous"><a href="./2-imported-and-exported-variables.html" target="content">Previous</a></button>
|
|
56
|
+
<button class="nav-next"><a href="./4-extended-data-types.html" target="content">Next</a></button>
|
|
57
|
+
</div>
|
|
58
|
+
<div style="float:right;margin-right:10px">
|
|
59
|
+
<h2></h2>
|
|
60
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
61
|
+
<div slot="script"></div>
|
|
62
|
+
<template slot="src">
|
|
63
|
+
<l-head>
|
|
64
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
65
|
+
</l-head>
|
|
66
|
+
<l-body>
|
|
67
|
+
Result: ${result}
|
|
68
|
+
</l-body>
|
|
69
|
+
<script id="lightview">
|
|
70
|
+
currentComponent.mount = function() {
|
|
71
|
+
this.variables({result:"any"},{reactive});
|
|
72
|
+
this.variables({testVariable:"boolean"});
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
testVariable = true;
|
|
76
|
+
result = testVariable;
|
|
77
|
+
} catch(e) {
|
|
78
|
+
result = e+"";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
</template>
|
|
83
|
+
</l-repl>
|
|
84
|
+
</div>
|
|
85
|
+
<script>
|
|
86
|
+
processMarkdown();
|
|
87
|
+
</script>
|
|
88
|
+
</body>
|
|
89
|
+
</html>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Tutorial:Extended Data Types</title>
|
|
6
|
+
<link href="../css/tutorial.css" rel="stylesheet">
|
|
7
|
+
<link href="../components/repl.html" rel="module">
|
|
8
|
+
<link href="../slidein.html" rel="module">
|
|
9
|
+
<script src="../javascript/highlightjs.min.js"></script>
|
|
10
|
+
<script src="../javascript/marked.min.js"></script>
|
|
11
|
+
<script src="../javascript/utils.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="tutorial-body">
|
|
14
|
+
<script src="../javascript/lightview.js"></script>
|
|
15
|
+
<div class="tutorial-instructions">
|
|
16
|
+
<l-slidein src="./contents.html" class="toc"></l-slidein>
|
|
17
|
+
<div class="markdown">
|
|
18
|
+
## Extended Data Types
|
|
19
|
+
|
|
20
|
+
Lightview provides extended data types that allow you to put additional constraints on variable values. For example:
|
|
21
|
+
|
|
22
|
+
- `number` supports a min, max, step, allowNaN and coercion control
|
|
23
|
+
- `string` supports minlength, maxlength, pattern (a RegExp), and coercion control.
|
|
24
|
+
|
|
25
|
+
Extended types must be imported from the file `types.js`. To do this, you must make the `mount` function asynchronous
|
|
26
|
+
and `await` the result of the `import`.
|
|
27
|
+
|
|
28
|
+
Unlike standard data types, coercion is off by default for extended data types, try setting the value to "2". You should see an error message.
|
|
29
|
+
Then, try adding `coerce:true` to the variable configuration. The error message should go away.
|
|
30
|
+
|
|
31
|
+
Try setting the value to 3. You should get a different error message.
|
|
32
|
+
|
|
33
|
+
Try removing all the configuration options, i.e. use `number({})`. The error message should disappear. Set the value to
|
|
34
|
+
NaN. This should work. Now add `allowNaN:false`. You should get an error message.
|
|
35
|
+
|
|
36
|
+
*Note*: You will see "@NaN" in the error message. JavaScript does not stringify `NaN`, `-Infinity` or `Infinity` when
|
|
37
|
+
converting to JSON, so Lightview has to use an unambiguous string representation.
|
|
38
|
+
|
|
39
|
+
Try modifying the type to just `number` without making it a function call. Then assign a number or a string.
|
|
40
|
+
|
|
41
|
+
Try modifying the type to be a `string` and playing with the configuration options and values.
|
|
42
|
+
|
|
43
|
+
Additional extended types and info on how to manage errors can be found in the [API documentation](./api.html).
|
|
44
|
+
|
|
45
|
+
</div>
|
|
46
|
+
<button class="nav-previous"><a href="./3-data-types.html" target="content">Previous</a></button>
|
|
47
|
+
<button class="nav-next"><a href="./5-extended-functional-types.html" target="content">Next</a></button>
|
|
48
|
+
</div>
|
|
49
|
+
<div style="float:right;margin-right:10px">
|
|
50
|
+
<h2></h2>
|
|
51
|
+
<l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
|
|
52
|
+
<div slot="bodyhtml"></div>
|
|
53
|
+
<div slot="script"></div>
|
|
54
|
+
<template slot="src">
|
|
55
|
+
<l-head>
|
|
56
|
+
<script src="../javascript/lightview.js?as=x-body"></script>
|
|
57
|
+
</l-head>
|
|
58
|
+
<l-body>
|
|
59
|
+
Result: ${result}
|
|
60
|
+
</l-body>
|
|
61
|
+
<script id="lightview">
|
|
62
|
+
currentComponent.mount = async function() {
|
|
63
|
+
const {number} = await import("../javascript/types.js");
|
|
64
|
+
this.variables({result:"any"},{reactive});
|
|
65
|
+
|
|
66
|
+
this.variables({testVariable:number({min:0,max:10,step:2})});
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
testVariable = 0;
|
|
70
|
+
result = testVariable;
|
|
71
|
+
} catch(e) {
|
|
72
|
+
result = e+"";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
</template>
|
|
77
|
+
</l-repl>
|
|
78
|
+
</div>
|
|
79
|
+
<script>
|
|
80
|
+
processMarkdown();
|
|
81
|
+
</script>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|