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.
Files changed (122) hide show
  1. package/README.md +15 -16
  2. package/docs/CNAME +1 -0
  3. package/docs/api.html +674 -0
  4. package/docs/blank.html +10 -0
  5. package/docs/comparedto.html +89 -0
  6. package/docs/components/chart-repl.html +69 -0
  7. package/docs/components/chart.html +17 -0
  8. package/{components → docs/components}/components.js +31 -11
  9. package/docs/components/contents.html +17 -0
  10. package/docs/components/gantt-repl.html +61 -0
  11. package/docs/components/gantt.html +42 -0
  12. package/docs/components/gauge-repl.html +66 -0
  13. package/docs/components/gauge.html +20 -0
  14. package/docs/components/orgchart-repl.html +64 -0
  15. package/docs/components/orgchart.html +41 -0
  16. package/docs/components/repl-as-src.html +17 -0
  17. package/docs/components/repl-repl.html +95 -0
  18. package/docs/components/repl.html +527 -0
  19. package/docs/components/timeline-repl.html +72 -0
  20. package/docs/components/timeline.html +44 -0
  21. package/docs/components.html +14 -0
  22. package/docs/css/highlightjs.min.css +9 -0
  23. package/docs/css/tutorial.css +35 -0
  24. package/docs/examples/anchor.html +11 -0
  25. package/{components/chart/example.html → docs/examples/chart.html} +6 -4
  26. package/docs/examples/counter.html +26 -0
  27. package/{examples → docs/examples}/counter.test.mjs +0 -0
  28. package/docs/examples/counter2.html +26 -0
  29. package/{examples → docs/examples}/directives.html +20 -18
  30. package/{examples → docs/examples}/foreign.html +1 -1
  31. package/docs/examples/forgeinform.html +98 -0
  32. package/docs/examples/form.html +61 -0
  33. package/{examples → docs/examples}/gauge.html +4 -2
  34. package/{examples → docs/examples}/invalid-template-literals.html +6 -4
  35. package/{examples → docs/examples}/medium/remote.html +1 -1
  36. package/docs/examples/message.html +18 -0
  37. package/{examples → docs/examples}/nested.html +2 -2
  38. package/docs/examples/object-bound-form.html +34 -0
  39. package/{examples → docs/examples}/remote-server.js +0 -0
  40. package/docs/examples/remote.html +34 -0
  41. package/{examples → docs/examples}/remote.json +0 -0
  42. package/{examples → docs/examples}/scratch.html +1 -1
  43. package/docs/examples/sensors/index.html +44 -0
  44. package/{examples → docs/examples}/sensors/sensor-server.js +0 -0
  45. package/docs/examples/shared.html +41 -0
  46. package/{examples → docs/examples}/template.html +1 -1
  47. package/{examples → docs/examples}/timeline.html +2 -2
  48. package/docs/examples/todo.html +40 -0
  49. package/docs/examples/top.html +10 -0
  50. package/{examples → docs/examples}/types.html +1 -1
  51. package/{examples → docs/examples}/xor.html +22 -20
  52. package/docs/examples.html +25 -0
  53. package/docs/index.html +44 -0
  54. package/docs/javascript/codejar.min.js +8 -0
  55. package/docs/javascript/highlightjs.min.js +1173 -0
  56. package/docs/javascript/isomorphic-git.js +9 -0
  57. package/docs/javascript/json5.min.js +1 -0
  58. package/docs/javascript/lightning-fs.js +1 -0
  59. package/docs/javascript/lightview.js +1285 -0
  60. package/docs/javascript/marked.min.js +6 -0
  61. package/docs/javascript/peerjs.min.js +70 -0
  62. package/docs/javascript/turndown.js +973 -0
  63. package/docs/javascript/types.js +606 -0
  64. package/docs/javascript/utils.js +45 -0
  65. package/docs/lightview.html +63 -0
  66. package/docs/old_index.html +965 -0
  67. package/docs/old_index.md +1132 -0
  68. package/docs/slidein.html +51 -0
  69. package/docs/tutorial/0-getting-started.html +67 -0
  70. package/docs/tutorial/1-intro-to-variables.html +103 -0
  71. package/docs/tutorial/10-template-components.html +80 -0
  72. package/docs/tutorial/11-linked-components.html +76 -0
  73. package/docs/tutorial/12-imported-components.html +67 -0
  74. package/docs/tutorial/13-input-binding.html +94 -0
  75. package/docs/tutorial/14-automatic-variable-creation.html +74 -0
  76. package/docs/tutorial/15-form-binding.html +110 -0
  77. package/docs/tutorial/16-if-directive.html +60 -0
  78. package/docs/tutorial/17-loop-directives.html +83 -0
  79. package/docs/tutorial/18-sanitizing-and-escaping-input.html +79 -0
  80. package/docs/tutorial/2-imported-and-exported-variables.html +80 -0
  81. package/docs/tutorial/3-data-types.html +89 -0
  82. package/docs/tutorial/4-extended-data-types.html +83 -0
  83. package/docs/tutorial/5-extended-functional-types.html +96 -0
  84. package/docs/tutorial/5.1-extended-functional-types.html +79 -0
  85. package/docs/tutorial/5.2-extended-functional-types.html +70 -0
  86. package/docs/tutorial/6-conventional-javascript.html +75 -0
  87. package/docs/tutorial/7-monitoring-with-observers.html +107 -0
  88. package/docs/tutorial/8-event-listeners.html +65 -0
  89. package/docs/tutorial/9-intro-to-components.html +91 -0
  90. package/docs/tutorial/contents.html +32 -0
  91. package/docs/tutorial/my-component.html +29 -0
  92. package/docs/tutorial/remote-value.json +4 -0
  93. package/docs/websiterepl.html +46 -0
  94. package/lightview.js +499 -363
  95. package/lightview.min.js +1 -0
  96. package/lightview_good.js +1267 -0
  97. package/lightview_optimized.js +1274 -0
  98. package/package.json +7 -2
  99. package/repl_hold.html +320 -0
  100. package/test/basic.html +29 -17
  101. package/test/basic.test.mjs +1 -11
  102. package/test/extended.html +16 -19
  103. package/types.js +118 -36
  104. package/unsplash.key +1 -0
  105. package/components/chart/chart.html +0 -15
  106. package/components/chart.html +0 -81
  107. package/components/gantt/example.html +0 -27
  108. package/components/gantt/gantt.html +0 -34
  109. package/components/gauge/example.html +0 -28
  110. package/components/gauge/guage.html +0 -19
  111. package/components/gauge.html +0 -57
  112. package/components/timeline.html +0 -81
  113. package/examples/chart.html +0 -66
  114. package/examples/counter.html +0 -24
  115. package/examples/forgeinform.html +0 -96
  116. package/examples/form.html +0 -59
  117. package/examples/message.html +0 -12
  118. package/examples/object-bound-form.html +0 -32
  119. package/examples/remote.html +0 -32
  120. package/examples/sensors/index.html +0 -30
  121. package/examples/todo.html +0 -38
  122. package/examples/top.html +0 -10
@@ -0,0 +1,96 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Extended Functional Type:Remote</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 Functional Type - Remote
19
+
20
+ In addition to `constant`, `exported`, `imported`, and `reactive`, Lightview supports the functional types `remote`,
21
+ `shared`, and `observed`.
22
+
23
+ - `remote` automatically gets a value from a URL
24
+ - `shared` automatically synchronizes a value across all instances of the same component
25
+ - `observed` in like import, except it changes the variable value every time its corresponding attribute changes on the component
26
+
27
+ These types must be loaded from the file `types.js` as shown in the example REPL.
28
+
29
+ If you want to import all of them in an efficient manner, do this:
30
+
31
+ ```javascript
32
+ const {remote, shared, observed} = await import("../types.js");
33
+ this.variables(
34
+ { remote: "function"},
35
+ { constant: remote }
36
+ );
37
+ this.variables(
38
+ { remote: "function"},
39
+ { constant: shared }
40
+ );
41
+ this.variables(
42
+ { remote: "function"},
43
+ { constant: observed }
44
+ );
45
+ ```
46
+
47
+ For the demo REPL, the file located at `./tutorial/remote-value.json` has the contents `{"name":"joe","age":27}`. Try replacing
48
+ `./tutorial/remote-value.json` with `http://api.open-notify.org/astros.json` to see how many people are in space right now.
49
+
50
+ You may have noted that although `remote` is imported as a function, it is not used as such. For details on how to use
51
+ `remote` with a configuration object to support TTL based auto-refresh, automatically sending changed values to the server
52
+ and custom get/patch see the [API documentation](../api.html#remote).
53
+
54
+ The `observed` and `shared` types are covered on the next pages.
55
+
56
+ </div>
57
+ <button class="nav-previous"><a href="./4-extended-data-types.html" target="content">Previous</a></button>
58
+ <button class="nav-next"><a href="./5.1-extended-functional-types.html" target="content">Next</a></button>
59
+ </div>
60
+ <div style="float:right;margin-right:10px">
61
+ <h2></h2>
62
+ <l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
63
+ <div slot="bodyhtml"></div>
64
+ <div slot="script"></div>
65
+ <template slot="src">
66
+ <l-head>
67
+ <script src="../javascript/lightview.js?as=x-body"></script>
68
+ </l-head>
69
+ <l-body>
70
+ Result: ${result}
71
+ </l-body>
72
+ <script id="lightview">
73
+ currentComponent.mount = async function() {
74
+ this.variables(
75
+ { remote: "function"},
76
+ { constant: (await import("../javascript/types.js")).remote }
77
+ );
78
+ this.variables(
79
+ {
80
+ result:"object"
81
+ },
82
+ {
83
+ reactive,
84
+ remote:"./remote-value.json"
85
+ }
86
+ );
87
+ }
88
+ </script>
89
+ </template>
90
+ </l-repl>
91
+ </div>
92
+ <script>
93
+ processMarkdown();
94
+ </script>
95
+ </body>
96
+ </html>
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Extended Functional Type:Shared</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 Functional Type - Shared
19
+
20
+ The extended functional type `shared` automatically synchronizes a value across all instances of the same component.
21
+
22
+ The `shared` type must be loaded from the file `types.js` as shown in the example REPL.
23
+
24
+ In this example, we provide at attribute value on only one of the &lt;my-input&gt; tags and it is automatically
25
+ propagated as a value to the other tag. Try editing the values.
26
+
27
+ Note how the `myinput` component it defined in a &lt;template&gt; tag rather than another file. This is
28
+ covered in more detail in the [Template Components](./10-template-components.html) section of the tutorial.
29
+
30
+
31
+ </div>
32
+ <button class="nav-previous"><a href="./5-extended-functional-types.html" target="content">Previous</a></button>
33
+ <button class="nav-next"><a href="./5.2-extended-functional-types.html" target="content">Next</a></button>
34
+ </div>
35
+ <div style="float:right;margin-right:10px">
36
+ <h2></h2>
37
+ <l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
38
+ <div slot="headhtml"></div>
39
+ <div slot="bodyhtml"></div>
40
+ <template slot="src">
41
+ <l-head>
42
+ <template id="my-input">
43
+ Name: <input value="${name}">
44
+ <script id="lightview">
45
+ currentComponent.mount = async function() {
46
+ this.variables(
47
+ { shared: "function"},
48
+ { constant: (await import("../javascript/types.js")).shared }
49
+ );
50
+ this.variables(
51
+ {
52
+ name:"string"
53
+ },
54
+ {
55
+ shared,
56
+ imported,
57
+ reactive
58
+ }
59
+ );
60
+ }
61
+ </script>
62
+ </template>
63
+ <script src="../javascript/lightview.js?"></script>
64
+ </l-head>
65
+ <l-body>
66
+ <script>
67
+ Lightview.createComponent("my-input", document.getElementById("my-input"))
68
+ </script>
69
+ <my-input></my-input><br>
70
+ <my-input name="joe"></my-input>
71
+ </l-body>
72
+ </template>
73
+ </l-repl>
74
+ </div>
75
+ <script>
76
+ processMarkdown();
77
+ </script>
78
+ </body>
79
+ </html>
@@ -0,0 +1,70 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Extended Functional Type:Observed</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 Functional Type - Observed
19
+
20
+ Unlike `imported` variables which only get the value of an attribute when the component is created, `observed` attributes
21
+ update the associated variable every time the attribute changes.
22
+
23
+ Clicking on the `Change Attribute` button sets a new value for the attribute "name". Lightview detects this and updates the
24
+ variable `name`. Since `name` is also `reactive`, the HTML nodes referencing it are also updated.
25
+
26
+ </div>
27
+ <button class="nav-previous"><a href="./5.1-extended-functional-types.html" target="content">Previous</a></button>
28
+ <button class="nav-next"><a href="./6-conventional-javascript.html" target="content">Next</a></button>
29
+ </div>
30
+ <div style="float:right;margin-right:10px">
31
+ <h2></h2>
32
+ <l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
33
+ <div slot="bodyhtml"></div>
34
+ <div slot="script"></div>
35
+ <template slot="src">
36
+ <l-head>
37
+ <script src="../javascript/lightview.js?as=x-body"></script>
38
+ </l-head>
39
+ <l-body name="joe">
40
+ Name: ${name}
41
+ <button l-on:click="${changeAttribute}">Change Attribute</button>
42
+ </l-body>
43
+ <script id="lightview">
44
+ currentComponent.mount = async function() {
45
+ this.variables(
46
+ { observed: "function"},
47
+ { constant: (await import("../javascript/types.js")).observed }
48
+ );
49
+ this.variables(
50
+ {
51
+ name:"string"
52
+ },
53
+ {
54
+ reactive,
55
+ observed
56
+ }
57
+ );
58
+ this.changeAttribute = () => {
59
+ this.setAttribute("name","mary" + Math.round(Math.random()*10))
60
+ }
61
+ }
62
+ </script>
63
+ </template>
64
+ </l-repl>
65
+ </div>
66
+ <script>
67
+ processMarkdown();
68
+ </script>
69
+ </body>
70
+ </html>
@@ -0,0 +1,75 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Conventional Javascript</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
+ ## Conventional and Lightview Javascript
19
+
20
+ All Lightview development involves the creation of components and all Lightview components have at least and at most one
21
+ `script` with the id "lightview". There can also be other `script` elements in a component file.
22
+
23
+ If you do not explicitly create a component, then (as with this example), the body of the file containing the script is
24
+ treated like a component.
25
+
26
+ You can use conventional JavaScript with `let`, `const`, closures, etc. inside your Lightview script. And,
27
+ Lightview scripts always support a top level `await`, even though they are not declared as `type="module"`.
28
+
29
+ Try changing `loops = 5` to another number and watch the script do a countdown. Note that the countdown does not start
30
+ until the component has received a `mounted` event. This is the point at which script with the id "lightview" has
31
+ been fully processed, i.e. all variables have been declared and initialized and an initial pass has being
32
+ made to replace variables in the HTML.
33
+
34
+
35
+ </div>
36
+ <button class="nav-previous"><a href="./5.2-extended-functional-types.html" target="content">Previous</a></button>
37
+ <button class="nav-next"><a href="./7-monitoring-with-observers.html" target="content">Next</a></button>
38
+ </div>
39
+ <div style="float:right;margin-right:10px">
40
+ <h2></h2>
41
+ <l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
42
+ <div slot="bodyhtml"></div>
43
+ <div slot="script"></div>
44
+ <template slot="src">
45
+ <l-head>
46
+ <script src="../javascript/lightview.js?as=x-body"></script>
47
+ </l-head>
48
+ <l-body>
49
+ ${count}
50
+ </l-body>
51
+ <script id="lightview">
52
+ var tick = () => {
53
+ return new Promise((resolve) => setTimeout(() => resolve(),1000))
54
+ }
55
+ currentComponent.mount = function() {
56
+ let loops = 5,
57
+ i = 0;
58
+ this.variables({count:"any"},{reactive,set:loops});
59
+ this.addEventListener("mounted",async () => {
60
+ while(loops--) {
61
+ await tick();
62
+ count = loops;
63
+ };
64
+ count = "Go";
65
+ })
66
+ }
67
+ </script>
68
+ </template>
69
+ </l-repl>
70
+ </div>
71
+ <script>
72
+ processMarkdown();
73
+ </script>
74
+ </body>
75
+ </html>
@@ -0,0 +1,107 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Monitoring With Observers</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
+ ## Monitoring With Observers
19
+
20
+ Lightview supports the observer programming paradigm, a powerful mechanism for responding to changes across one or more
21
+ variables.
22
+
23
+ To create an observer, wrap a function that references the reactive variables you want to monitor in a call to `observe`.
24
+
25
+ Any time the value of one of the variables changes, the function will be called.
26
+
27
+ You can cancel an observer by assigning the return value of `observe` to a variable and calling `cancel()` on that value.
28
+
29
+ This can be much simpler than setting up event listeners.
30
+
31
+ *Note*: In this example we only reference one reactive variable, but you can reference as many as you wish. One observer
32
+ can take the place of multiple event listeners. Try pasting this code as the REPL body.
33
+
34
+ ```javascript
35
+ ${command||""}<br>
36
+ ${x}:${y}
37
+ ```
38
+ And, paste this as the REPL script:
39
+
40
+ ```javascript
41
+ currentComponent.mount = function() {
42
+ this.variables({x:"number",y:"number",command:"string"},{reactive});
43
+
44
+ x = 0;
45
+ y = 6;
46
+
47
+ let previousx, previousy;
48
+ let t1, t2;
49
+ const observer = observe(() => {
50
+ if(x!==y) {
51
+ if(x!==previousx) {
52
+ previousx = x;
53
+ t1 = setTimeout(() => y--,1000);
54
+ }
55
+ if(y!==previousy) {
56
+ previousy = y;
57
+ t2 = setTimeout(() => x++,1000);
58
+ }
59
+ } else {
60
+ command = "stop!";
61
+ clearTimeout(t1);
62
+ clearTimeout(t2);
63
+ observer.cancel();
64
+ }
65
+ });
66
+ }
67
+ ```
68
+
69
+
70
+ </div>
71
+ <button class="nav-previous"><a href="./6-conventional-javascript.html" target="content">Previous</a></button>
72
+ <button class="nav-next"><a href="./8-event-listeners.html" target="content">Next</a></button>
73
+ </div>
74
+ <div style="float:right;margin-right:10px">
75
+ <h2></h2>
76
+ <l-repl id="repl" style="min-height:95vh;min-width:600px;" previewpinned>
77
+ <div slot="bodyhtml"></div>
78
+ <div slot="script"></div>
79
+ <template slot="src">
80
+ <l-head>
81
+ <script src="../javascript/lightview.js?as=x-body"></script>
82
+ </l-head>
83
+ <l-body>
84
+ ${command||""}
85
+ </l-body>
86
+ <script id="lightview">
87
+ currentComponent.mount = function() {
88
+ this.variables({count:"number"},{reactive,set:0});
89
+ this.variables({command:"string"},{reactive});
90
+
91
+ const commands = ["On your marks ...","Get set ...","Go!"];
92
+ observe(() => {
93
+ if(count < commands.length) {
94
+ command = commands[count];
95
+ setTimeout(()=>count++,3000)
96
+ }
97
+ });
98
+ }
99
+ </script>
100
+ </template>
101
+ </l-repl>
102
+ </div>
103
+ <script>
104
+ processMarkdown();
105
+ </script>
106
+ </body>
107
+ </html>
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Event Listeners</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
+ ## Event Listeners
19
+
20
+ Event listeners can be added to any HTML element using the `l-on:[eventType]` directive, e.g.
21
+ `<div l-on:click="${myClickHandler}"></div>`.
22
+
23
+ You can choose to keep the listeners private to the component or expose them as properties. To keep them
24
+ private, use variables of type "function". To expose them, just define them on `this` or `self`.
25
+
26
+ *Caution*: If you define public listeners, make sure their names do not collide with standard HTML element property names,
27
+ e.g. `getComputedStyle`.
28
+
29
+
30
+ </div>
31
+ <button class="nav-previous"><a href="./7-monitoring-with-observers.html" target="content">Previous</a></button>
32
+ <button class="nav-next"><a href="./9-intro-to-components.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
+ <button l-on:click="${onClickPrivate}">Private</button>
45
+ <button l-on:click="${onClickPublic}">Public</button>
46
+ ${clicked}
47
+ </l-body>
48
+ <script id="lightview">
49
+ currentComponent.mount = function() {
50
+ this.variables({clicked:"string"},{reactive,set:""});
51
+ this.variables({onClickPrivate:"function"});
52
+
53
+ onClickPrivate = ({target}) => clicked = `clicked ${target.innerText}`;
54
+
55
+ this.onClickPublic = ({target}) => clicked = `clicked ${target.innerText}`;
56
+ }
57
+ </script>
58
+ </template>
59
+ </l-repl>
60
+ </div>
61
+ <script>
62
+ processMarkdown();
63
+ </script>
64
+ </body>
65
+ </html>
@@ -0,0 +1,91 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Lightview:Tutorial:Introduction To Components</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
+ ## Introduction To Components
19
+
20
+ Until this point, we have not shown you the `head` HTML element or used a `style` block.
21
+
22
+ All HTML pages using Lightview MUST include include a `lightview.js` file as a regular (not `module`) script in their
23
+ head or close to the top of the `body`.
24
+
25
+ You MAY treat an entire page as a component by passing `lightview.js` the query string `as=x-body`. The document body
26
+ will get replaced with the custom element `x-body`.
27
+
28
+ When you use `as=x-body`, the page becomes a component with its HTML rendered in a shadow DOM.
29
+
30
+ You MAY include a `style` block that will be isolated to the shadow DOM.
31
+
32
+ And, you MAY include a `script` block with the id "lightview", the variables of which are also isolated to the shadow DOM
33
+ unless you explicitly add them to an object with higher scope, e.g. `window` or `document`. The execution of the script
34
+ is not isolated. The script can walk up the DOM and out of the shadows unless you explicitly render the component in an
35
+ `iframe`.
36
+
37
+ You may also include other script blocks, which will also be somewhat isolated to the shadow DOM.
38
+
39
+ *Note*: If you do not include `id="lightview"` for the script block you expect to provide Lightview type behavior, the
40
+ component will not behave properly.
41
+
42
+ On this page we continue to let you edit the script block. On the next page we will use a `template` tag to define the
43
+ component and create it manually with a regular script. Take the opportunity on this page to inspect the preview area
44
+ using your JavaScript debugger and look at the `iframe` code with the id "preview", note how the body gets replaced with
45
+ an element named `x-body`.
46
+
47
+
48
+ </div>
49
+ <button class="nav-previous"><a href="./8-event-listeners.html" target="content">Previous</a></button>
50
+ <button class="nav-next"><a href="./10-template-components.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" readonly></div>
56
+ <div slot="bodyhtml"></div>
57
+ <div slot="css"></div>
58
+ <div slot="script"></div>
59
+ <template slot="src">
60
+ <l-head>
61
+ <script src="../javascript/lightview.js?as=x-body"></script>
62
+ </l-head>
63
+ <l-body>
64
+ <button l-on:click="${onClickPrivate}">Private</button>
65
+ <button l-on:click="${onClickPublic}">Public</button>
66
+ ${clicked}
67
+ </l-body>
68
+ <style>
69
+ button {
70
+ border: none;
71
+ border-radius: 5px;
72
+ }
73
+ </style>
74
+ <script id="lightview">
75
+ currentComponent.mount = function() {
76
+ this.variables({clicked:"string"},{reactive,set:""});
77
+ this.variables({onClickPrivate:"function"});
78
+
79
+ onClickPrivate = ({target}) => clicked = `clicked ${target.innerText}`;
80
+
81
+ this.onClickPublic = ({target}) => clicked = `clicked ${target.innerText}`;
82
+ }
83
+ </script>
84
+ </template>
85
+ </l-repl>
86
+ </div>
87
+ <script>
88
+ processMarkdown();
89
+ </script>
90
+ </body>
91
+ </html>
@@ -0,0 +1,32 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Ligtchview:Tutorial:Contents</title>
6
+ </head>
7
+ <body>
8
+ <ul style="list-style:none;padding-inline-start: 10px">
9
+ <li><a href="./0-getting-started.html">Getting Started</a></li>
10
+ <li><a href="./1-intro-to-variables.html">Intro To Variables</a></li>
11
+ <li><a href="./2-imported-and-exported-variables.html">Imported and Exported Variables</a></li>
12
+ <li><a href="./3-data-types.html">Data Types</a></li>
13
+ <li><a href="./4-extended-data-types.html">Extended Data Types</a></li>
14
+ <li><a href="./5-extended-functional-types.html">Extended Functional Type: Remote</a></li>
15
+ <li><a href="./5.1-extended-functional-types.html">Extended Functional Type: Shared</a></li>
16
+ <li><a href="./5.2-extended-functional-types.html">Extended Functional Type: Observed</a></li>
17
+ <li><a href="./6-conventional-javascript.html">Conventional and Lightview JavaScript</a></li>
18
+ <li><a href="./7-monitoring-with-observers.html">Monitoring with Observers</a></li>
19
+ <li><a href="./8-event-listeners.html">Event Listeners</a></li>
20
+ <li><a href="./9-intro-to-components.html">Intro to Components</a></li>
21
+ <li><a href="./10-template-components.html">Template Components</a></li>
22
+ <li><a href="./11-linked-components.html">Linked Components</a></li>
23
+ <li><a href="./12-imported-components.html">Imported Components</a></li>
24
+ <li><a href="./13-input-binding.html">Input Binding</a></li>
25
+ <li><a href="./14-automatic-variable-creation.html">Automatic Variable Creation</a></li>
26
+ <li><a href="./15-form-binding.html">Form Binding</a></li>
27
+ <li><a href="./16-if-directive.html">If Directive</a></li>
28
+ <li><a href="./17-loop-directives.html">Loop Directives</a></li>
29
+ <li><a href="./18-sanitizing-and-escaping-input.html">Sanitizing and Escaping HTML</a></li>
30
+ </ul>
31
+ </body>
32
+ </html>
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>My Component</title>
6
+ <script src="../javascript/lightview.js?as=x-body"></script>
7
+ </head>
8
+ <body>
9
+ <button l-on:click="${onClickPrivate}">Private</button>
10
+ <button l-on:click="${onClickPublic}">Public</button>
11
+ ${clicked}
12
+ <style>
13
+ button {
14
+ border: none;
15
+ border-radius: 5px;
16
+ }
17
+ </style>
18
+ <script id="lightview">
19
+ (currentComponent ||= document.body).mount = function() {
20
+ this.variables({clicked:"string"},{reactive,set:""});
21
+ this.variables({onClickPrivate:"function"});
22
+
23
+ onClickPrivate = ({target}) => clicked = `clicked ${target.innerText}`;
24
+
25
+ this.onClickPublic = ({target}) => clicked = `clicked ${target.innerText}`;
26
+ }
27
+ </script>
28
+ </body>
29
+ </html>
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "joe",
3
+ "age": 27
4
+ }