lightview 1.6.3-b → 1.6.6-b
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 +2 -2
- package/components/chart.html +6 -5
- package/components/gauge.html +1 -1
- package/examples/chart.html +11 -9
- package/examples/foreign.html +27 -13
- package/examples/forgeinform.html +29 -8
- package/examples/form.html +1 -1
- package/examples/medium/remote.html +59 -0
- package/examples/remote.json +1 -1
- package/examples/types.html +1 -0
- package/examples/xor.html +1 -1
- package/jest.config.json +1 -1
- package/lightview.js +287 -209
- package/package.json +1 -1
- package/test/basic.html +1 -1
- package/test/extended.html +32 -0
- package/test/extended.test.mjs +448 -0
- package/types.js +62 -53
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# lightview v1.6.
|
|
1
|
+
# lightview v1.6.6b (BETA)
|
|
2
2
|
|
|
3
3
|
Small, simple, powerful web UI and micro front end creation ...
|
|
4
4
|
|
|
5
|
-
Great ideas from Svelte, React, Vue and Riot combined into one small tool: <
|
|
5
|
+
Great ideas from Svelte, React, Vue and Riot combined into one small tool: < 7.5K (minified/gzipped).
|
|
6
6
|
|
|
7
7
|
See the docs and examples at [https://lightview.dev](https://lightview.dev).
|
|
8
8
|
|
package/components/chart.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
});
|
|
24
24
|
let chart,
|
|
25
25
|
datatable,
|
|
26
|
-
options;
|
|
26
|
+
options = {};
|
|
27
27
|
self.variables({type: "string", title: "string", style: "string"}, {observed});
|
|
28
28
|
if(style) target.setAttribute("style",style);
|
|
29
29
|
self.addRow = (row) => {
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
chart.draw(datatable, options);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
+
self.setOptions = (newOptions) => {
|
|
40
|
+
Object.assign(options,newOptions);
|
|
41
|
+
};
|
|
39
42
|
self.init = () => {
|
|
40
43
|
const node = self.firstChild,
|
|
41
44
|
callback = (textNode, oldValue, newValue) => {
|
|
@@ -48,9 +51,7 @@
|
|
|
48
51
|
target.innerText = e + newValue;
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
|
-
options =
|
|
52
|
-
title: title
|
|
53
|
-
};
|
|
54
|
+
if(!options.title && title) options.title = title;
|
|
54
55
|
chart = new google.visualization[type](target);
|
|
55
56
|
node.characterDataMutationCallback = callback;
|
|
56
57
|
callback(node, node.textContent, node.textContent);
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
resizeObserver.observe(target);
|
|
68
69
|
self.removeAttribute("hidden");
|
|
69
70
|
};
|
|
70
|
-
addEventListener("connected", ({target}) => {
|
|
71
|
+
self.addEventListener("connected", ({target}) => {
|
|
71
72
|
google.charts.load("current", {"packages": ["corechart","gauge"]});
|
|
72
73
|
google.charts.setOnLoadCallback(self.init);
|
|
73
74
|
});
|
package/components/gauge.html
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
resizeObserver.observe(target);
|
|
49
49
|
self.removeAttribute("hidden");
|
|
50
50
|
};
|
|
51
|
-
addEventListener("connected", ({target}) => {
|
|
51
|
+
self.addEventListener("connected", ({target}) => {
|
|
52
52
|
google.charts.load("current", {"packages": ["corechart","gauge"]});
|
|
53
53
|
google.charts.setOnLoadCallback(self.init);
|
|
54
54
|
});
|
package/examples/chart.html
CHANGED
|
@@ -50,15 +50,17 @@
|
|
|
50
50
|
</l-chart>
|
|
51
51
|
<script>
|
|
52
52
|
const gauges = document.getElementById("myGauges");
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
gauges.addEventListener("connected",() => {
|
|
54
|
+
setInterval(function() {
|
|
55
|
+
gauges.setValue(0, 1, 40 + Math.round(60 * Math.random()));
|
|
56
|
+
}, 6000);
|
|
57
|
+
setInterval(function() {
|
|
58
|
+
gauges.setValue(1, 1, 40 + Math.round(60 * Math.random()));
|
|
59
|
+
}, 5000);
|
|
60
|
+
setInterval(function() {
|
|
61
|
+
gauges.setValue(2, 1, 60 + Math.round(40 * Math.random()));
|
|
62
|
+
}, 7500);
|
|
63
|
+
})
|
|
62
64
|
</script>
|
|
63
65
|
</body>
|
|
64
66
|
</html>
|
package/examples/foreign.html
CHANGED
|
@@ -12,24 +12,38 @@
|
|
|
12
12
|
The component below is loaded from an alternate domain and running in a child iframe.
|
|
13
13
|
The logging console is below the component in this frame.
|
|
14
14
|
</p>
|
|
15
|
-
<
|
|
15
|
+
<p>New Order:<span id="orderclip"></span></p>
|
|
16
|
+
<iframe id="myframe"
|
|
17
|
+
class="l-remote" style="border-width:2px;border-style:dashed;"
|
|
18
|
+
src="https://lightview.dev/examples/foreignform.html?id=myframe"></iframe>
|
|
16
19
|
<div id="console" style="max-height:250px;scroll:auto"></div>
|
|
17
20
|
<script>
|
|
18
|
-
const
|
|
19
|
-
const console = document.getElementById("console");
|
|
20
|
-
for (const {target,attributeName,oldValue} of mutationsList) {
|
|
21
|
-
const line = document.createElement("div"),
|
|
22
|
-
event = {attributeName,oldValue,value:target.getAttribute(attributeName)};
|
|
23
|
-
line.innerText = JSON.stringify(event);
|
|
24
|
-
console.appendChild(line);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const observer = new MutationObserver(mutationCallback),
|
|
28
|
-
iframe = document.getElementById("myframe");
|
|
29
|
-
observer.observe(iframe, { attributes:true, attributeOldValue: true });
|
|
21
|
+
const iframe = document.getElementById("myframe");
|
|
30
22
|
iframe.addEventListener("DOMContentLoaded",(event) => {
|
|
23
|
+
// modify the line below, or remove this event listener
|
|
24
|
+
// based on the needs of your application
|
|
31
25
|
console.log(event);
|
|
32
26
|
});
|
|
27
|
+
iframe.addEventListener("message",({detail}) => {
|
|
28
|
+
// modify the lines below, or remove this event listener
|
|
29
|
+
// based on the needs of your application
|
|
30
|
+
const orderclip = document.getElementById("orderclip");
|
|
31
|
+
orderclip.innerText = JSON.stringify(detail);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
iframe.addEventListener("attribute.changed",(event) => {
|
|
35
|
+
const {target,detail} = event,
|
|
36
|
+
{attributeName,value,oldValue} = detail;
|
|
37
|
+
event.stopImmediatePropagation();
|
|
38
|
+
if(target.getAttribute(attributeName)!==oldValue) {
|
|
39
|
+
// modify the lines below, or remove this event listener
|
|
40
|
+
// based on the needs of your application
|
|
41
|
+
const console = document.getElementById("console"),
|
|
42
|
+
line = document.createElement("div");
|
|
43
|
+
line.innerText = JSON.stringify(detail);
|
|
44
|
+
console.appendChild(line);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
33
47
|
</script>
|
|
34
48
|
</body>
|
|
35
49
|
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
<option>tomato</option>
|
|
28
28
|
<option>cheese</option>
|
|
29
29
|
</select>
|
|
30
|
+
<br><button l-on:click="placeOrder">Place Order</button>
|
|
30
31
|
</p>
|
|
32
|
+
Expose: <input type="checkbox" value="${checked}">
|
|
31
33
|
<p l-if="${checked}">
|
|
32
34
|
Now you've done it. You've exposed me.
|
|
33
35
|
</p>
|
|
@@ -45,24 +47,43 @@
|
|
|
45
47
|
</p>
|
|
46
48
|
</div>
|
|
47
49
|
<script type="lightview/module">
|
|
50
|
+
const orders = [];
|
|
51
|
+
self.variables({
|
|
52
|
+
checked: "boolean"
|
|
53
|
+
}, {
|
|
54
|
+
reactive
|
|
55
|
+
});
|
|
48
56
|
self.variables({
|
|
49
57
|
color: "string",
|
|
50
|
-
checked: "boolean",
|
|
51
58
|
hamburger: Array
|
|
52
59
|
}, {
|
|
53
|
-
reactive
|
|
60
|
+
reactive, exported
|
|
61
|
+
});
|
|
62
|
+
self.addEventListener("connected",() => {
|
|
63
|
+
color = "green";
|
|
64
|
+
checked = true;
|
|
65
|
+
hamburger = ["lettuce"];
|
|
54
66
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
self.placeOrder = () => {
|
|
68
|
+
orders.push(hamburger);
|
|
69
|
+
message = {hamburger};
|
|
70
|
+
};
|
|
58
71
|
// demo instrumentation
|
|
59
72
|
const variableValues = () => {
|
|
60
73
|
const el = self.getElementById("variables");
|
|
61
74
|
while (el.lastElementChild) el.lastElementChild.remove();
|
|
62
75
|
self.getVariableNames().forEach((name) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
const line = document.createElement("div");
|
|
77
|
+
line.innerText = `${name} = ${JSON.stringify(self.getVariableValue(name))}`;
|
|
78
|
+
el.appendChild(line);
|
|
79
|
+
});
|
|
80
|
+
const line = document.createElement("div");
|
|
81
|
+
line.innerText = "Previous Orders";
|
|
82
|
+
el.appendChild(line);
|
|
83
|
+
orders.forEach((order) => {
|
|
84
|
+
const line = document.createElement("div");
|
|
85
|
+
line.innerText = JSON.stringify(order);
|
|
86
|
+
el.appendChild(line);
|
|
66
87
|
});
|
|
67
88
|
};
|
|
68
89
|
variableValues();
|
package/examples/form.html
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>Lightview:Examples:Medium:Remote</title>
|
|
4
|
+
<!--
|
|
5
|
+
for convenience, import the chart component from the Lightview component library
|
|
6
|
+
alias it to r-chart rather than use the default l-chart
|
|
7
|
+
we could use any gauge component that exposes methods to update its view
|
|
8
|
+
-->
|
|
9
|
+
<link href="../../components/chart.html" rel="module" crossorigin="use-credentials" as="r-chart">
|
|
10
|
+
<!--
|
|
11
|
+
load the lightview library, about 7K
|
|
12
|
+
use the body of this file to create a custom element to replace itself
|
|
13
|
+
-->
|
|
14
|
+
<script src="../../lightview.js?as=x-body"></script>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<!--
|
|
18
|
+
layout the dashboad using the chart component r-chart
|
|
19
|
+
-->
|
|
20
|
+
<div style="width:100%;text-align:center">
|
|
21
|
+
<!--
|
|
22
|
+
set the initial value 0 for all components in a relaxed JSON5 configuration data block
|
|
23
|
+
-->
|
|
24
|
+
<r-chart id="dashboard" style="display:inline-block" type="Gauge" title="Server Status" hidden l-unhide>
|
|
25
|
+
[
|
|
26
|
+
['Label', 'Value'], // gauge will always take two columns, Label and Value
|
|
27
|
+
['Memory', 0],
|
|
28
|
+
['CPU', 0],
|
|
29
|
+
['Network', 0]
|
|
30
|
+
]
|
|
31
|
+
</r-chart>
|
|
32
|
+
</div>
|
|
33
|
+
<script type="lightview/module">
|
|
34
|
+
// use local, normal variables for as much as possible
|
|
35
|
+
const {remote} = await import("../../types.js"), // load the functional type 'remote`
|
|
36
|
+
sensorIndex = { // map sensor names to indexes in the dashboard data
|
|
37
|
+
memory:0,
|
|
38
|
+
cpu:1,
|
|
39
|
+
network:2
|
|
40
|
+
},
|
|
41
|
+
dashboard = document.body.getElementById("dashboard"),
|
|
42
|
+
path = "https://lightview.dev/sensors/"; // replace base path for your own implementation
|
|
43
|
+
// create remote reactive variables for sensors with differing refresh rates (ttl in milliseconds)
|
|
44
|
+
self.variables({memory:"number"},{remote:remote({ttl:5000,path})});
|
|
45
|
+
self.variables({cpu:"number"},{remote:remote({ttl:2500,path})});
|
|
46
|
+
self.variables({network:"number"},{remote:remote({ttl:1500,path})});
|
|
47
|
+
dashboard.addEventListener("connected",() => {
|
|
48
|
+
dashboard.setOptions({ // when dashboard component has finished initializing, set more options
|
|
49
|
+
redFrom: 90, redTo: 100,
|
|
50
|
+
yellowFrom:75, yellowTo: 90,
|
|
51
|
+
minorTicks: 5});
|
|
52
|
+
addEventListener("change",({variableName,value}) => { // execute the magic with a localized eventListener
|
|
53
|
+
const index = sensorIndex[variableName];
|
|
54
|
+
dashboard.setValue(index, 1, value);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
</body>
|
|
59
|
+
</html>
|
package/examples/remote.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"joe","age":
|
|
1
|
+
{"name":"joe","age":40}
|
package/examples/types.html
CHANGED
package/examples/xor.html
CHANGED
package/jest.config.json
CHANGED