lightview 1.7.2-b → 1.7.3-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 CHANGED
@@ -1,4 +1,4 @@
1
- # lightview v1.7.2b (BETA)
1
+ # lightview v1.7.3b (BETA)
2
2
 
3
3
  Small, simple, powerful web UI and micro front end creation ...
4
4
 
@@ -1,14 +1,14 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta charset="UTF-8">
4
- <title>Lightview:Chart</title>
4
+ <title>Lightview:Component:Chart</title>
5
5
  </head>
6
6
  <body>
7
7
  <div id="target"></div>
8
8
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
9
9
  <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
10
10
  <script type="lightview/module">
11
- const {chart} = await import("/components/components.js");
11
+ const {chart} = await import("../components.js");
12
12
  chart(self);
13
13
  </script>
14
14
  </body>
@@ -1,4 +1,4 @@
1
- const chart = (self,{packages = ["corechart"],options={},columns=[],rows=[],type,rowTransform}={}) => {
1
+ const chart = (self,{packages = ["corechart"],options={},columns=[],rows=[],type,optionsTransform, rowTransform}={}) => {
2
2
  options = {...options};
3
3
  columns = [...columns];
4
4
  let chart,
@@ -36,27 +36,39 @@ const chart = (self,{packages = ["corechart"],options={},columns=[],rows=[],type
36
36
  if(entry.contentBoxSize) {
37
37
  // Firefox implements `contentBoxSize` as a single content rect, rather than an array
38
38
  const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
39
- options.width = contentBoxSize.inlineSize;
39
+ if(options.width !== contentBoxSize.inlineSize) {
40
+ options.width = contentBoxSize.inlineSize;
41
+ chart.draw(datatable, options);
42
+ }
40
43
  } else {
41
- options.width = entry.contentRect.width;
44
+ if(options.width !== entry.contentRect.width) {
45
+ options.width = entry.contentRect.width;
46
+ chart.draw(datatable, options);
47
+ }
42
48
  }
43
49
  }
44
- chart.draw(datatable, options);
45
50
  }),
46
51
  callback = (textNode, oldValue, newValue) => {
47
52
  datatable = new google.visualization.DataTable();
48
53
  try {
49
54
  const config = JSON5.parse(newValue.trim());
50
- if(config.options) options=config.options;
55
+ if(config.options) Object.assign(options,config.options);
51
56
  if(config.columns) columns=config.columns;
52
57
  if(config.rows) rows=config.rows;
53
58
  columns.forEach((column) => {
54
59
  datatable.addColumn(column);
55
60
  });
56
- if(rowTransform) rows = rows.map((row) => rowTransform(row));
61
+ if(optionsTransform) options = optionsTransform(options);
62
+ if(rowTransform) rows = rows.map((row,index) => rowTransform(row,index,options));
57
63
  datatable.addRows(rows);
64
+ const {selectedStyle,style} = options;
65
+ rows.forEach((row,index) => {
66
+ if(selectedStyle) datatable.setRowProperty(index,"selectedStyle",selectedStyle);
67
+ if(style) datatable.setRowProperty(index,"style",style);
68
+ });
58
69
  chart.draw(datatable, options);
59
70
  } catch (e) {
71
+ console.error(e + newValue);
60
72
  target.innerText = e + newValue;
61
73
  }
62
74
  };
@@ -81,7 +93,7 @@ const chart = (self,{packages = ["corechart"],options={},columns=[],rows=[],type
81
93
  // Will be used by the Lightview global observer
82
94
  node.characterDataMutationCallback = callback;
83
95
  // resized charts if window resizes
84
- resizeObserver.observe(target);
96
+ resizeObserver.observe(document.body);
85
97
  self.dispatchEvent(new Event("mounted"));
86
98
  };
87
99
  self.addEventListener("connected", ({target}) => {
@@ -1,6 +1,7 @@
1
1
  <!DOCTYPE html>
2
+ <html>
2
3
  <head>
3
- <title>Lightview:Chart:Example</title>
4
+ <title>Lightview:Component:Gantt:Example</title>
4
5
  <link href="./gantt.html" rel="module">
5
6
  <script src="../../lightview.js"></script>
6
7
  </head>
@@ -17,11 +18,5 @@
17
18
  ]
18
19
  }
19
20
  </l-gantt>
20
- <script>
21
- const el = document.getElementById("myChart");
22
- el.addEventListener("mounted",() => {
23
- chart = el.chart;
24
- });
25
- </script>
26
21
  </body>
27
22
  </html>
@@ -1,13 +1,13 @@
1
1
  <html>
2
2
  <head>
3
- <title>Lightview:Gantt</title>
3
+ <title>Lightview:Component:Gantt</title>
4
4
  </head>
5
5
  <body>
6
6
  <div id="target"></div>
7
7
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
8
8
  <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
9
9
  <script type="lightview/module">
10
- const {chart} = await import("/components/components.js"),
10
+ const {chart} = await import("../components.js"),
11
11
  {duration} = await import("/types.js");
12
12
  chart(self,{
13
13
  packages:["gantt"],
@@ -21,9 +21,15 @@
21
21
  {label:"Dependencies",type:"string"}
22
22
  ],
23
23
  type:"Gantt",
24
- rowTransform(row) {
24
+ rowTransform(row,i) {
25
25
  return row.map((item,index) => {
26
- if(item && (index===2 || index===3)) return new Date(item);
26
+ if(item && (index===2 || index===3)) {
27
+ const date = new Date(item);
28
+ if(!date || typeof(date)!=="object" || !(date instanceof Date)) {
29
+ throw new TypeError(`row:${i} col:${index} is not a date`);
30
+ }
31
+ return date;
32
+ }
27
33
  if(item && index===4) return duration.parse(item);
28
34
  return item;
29
35
  })
@@ -1,6 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <head>
3
- <title>Lightview:Gauge:Example</title>
3
+ <title>Lightview:Component:Gauge:Example</title>
4
4
  <link href="./gauge.html" rel="module">
5
5
  <script src="../../lightview.js"></script>
6
6
  </head>
@@ -1,14 +1,14 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta charset="UTF-8">
4
- <title>Lightview:Gauge</title>
4
+ <title>Lightview:Component:Gauge</title>
5
5
  </head>
6
6
  <body>
7
7
  <div id="target"></div>
8
8
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
9
9
  <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
10
10
  <script type="lightview/module">
11
- const {chart} = await import("/components/components.js");
11
+ const {chart} = await import("../components.js");
12
12
  chart(self,{
13
13
  packages:["corechart","gauge"],
14
14
  columns:[{label:"Label",type:"string"},{label:"Value",type:"number"}],
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Lightview:Component:OrgChart:Example</title>
5
+ <link href="./orgchart.html" rel="module">
6
+ <script src="../../lightview.js"></script>
7
+ </head>
8
+ <body>
9
+ <l-orgchart id="myChart" style="height:500px;" title="My Org">
10
+ {
11
+ options: {
12
+ selectedStyle:"color:red"
13
+ },
14
+ // 4 columns in definition data name,title,manager,tooltip
15
+ rows: [
16
+ ["Mike","President","",""],
17
+ ["Jim","CFO","Mike",""],
18
+ ['Alice', 'Controller','Jim',""],
19
+ ['Bob', 'CIO', 'Mike',""],
20
+ ['Carol', 'Executive Assistant',"Mike",""]
21
+ ]
22
+ }
23
+ </l-orgchart>
24
+ </body>
25
+ </html>
@@ -0,0 +1,36 @@
1
+ <html>
2
+ <head>
3
+ <title>Lightview:Component:OrgChart</title>
4
+ </head>
5
+ <body>
6
+ <link id="load-css-2" rel="stylesheet" type="text/css" href="https://www.gstatic.com/charts/51/css/orgchart/orgchart.css">
7
+ <div id="target"></div>
8
+ <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
9
+ <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
10
+ <script type="lightview/module">
11
+ const {chart} = await import("../components.js");
12
+ chart(self,{
13
+ options: {allowHtml: true, allowCollapse: true},
14
+ packages:["orgchart"],
15
+ columns:[
16
+ {label:"Name",type:"string"},
17
+ {label:"Manager",type:"string"},
18
+ {label:"Tooltip",type:"string"}
19
+ ],
20
+ type:"OrgChart",
21
+ // 4 columns in definition data name,title,manager,tooltip
22
+ rowTransform(row) {
23
+ return row.reduce((row,item,index) => {
24
+ item ||= "";
25
+ if(index===1) {
26
+ row[0] = {v:row[0],f:`<div style="text-align:center;">${row[0]}<div style="font-style:italic">${item}</div></div>`}
27
+ } else {
28
+ row.push(item);
29
+ }
30
+ return row;
31
+ },[]);
32
+ }
33
+ });
34
+ </script>
35
+ </body>
36
+ </html>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Lightview:Component:Timeline:Example</title>
5
+ <link href="./timeline.html" rel="module">
6
+ <script src="../../lightview.js"></script>
7
+ </head>
8
+ <body>
9
+ <l-timeline title="Presidents">
10
+ {
11
+ options: { showRowLabels: false },
12
+ rows: [
13
+ [ '1', 'George Washington','1789-03-30', '1797-2-04' ],
14
+ [ '2', 'John Adams', '1797-02-04', '1801-02-04' ],
15
+ [ '3', 'Thomas Jefferson', '1801-02-04', '1809-02-04']
16
+ ]
17
+ }
18
+ </l-timeline>
19
+ <l-timeline title="Presidents and Vice Presidents">
20
+ {
21
+ options: { },
22
+ rows: [
23
+ [ 'President', 'George Washington','1789-03-30', '1797-2-04' ],
24
+ [ 'President', 'John Adams', '1797-02-04', '1801-02-04' ],
25
+ [ 'President', 'Thomas Jefferson', '1801-02-04', '1809-02-04'],
26
+ [ 'Vice President', 'John Adams','1789-03-21', '1797-02-04'],
27
+ [ 'Vice President', 'Thomas Jefferson','1797-02-04', '1801-02-04'],
28
+ [ 'Vice President', 'Aaron Burr','1801-02-04', '1805-02-04']
29
+ ]
30
+ }
31
+ </l-timeline>
32
+ </body>
33
+ </html>
@@ -0,0 +1,42 @@
1
+ <html>
2
+ <head>
3
+ <title>Lightview:Component:Timeline</title>
4
+ </head>
5
+ <body>
6
+ <div id="target"></div>
7
+ <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
8
+ <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
9
+ <script type="lightview/module">
10
+ const {chart} = await import("../components.js");
11
+ chart(self,{
12
+ packages:["timeline"],
13
+ columns:[
14
+ {id:"RowLabel",type:"string"},
15
+ {id:"BarLabel",type:"string"},
16
+ {id:"Start",type:"date"},
17
+ {id:"End",type:"date"}
18
+ ],
19
+ type:"Timeline",
20
+ optionsTransform(options) {
21
+ options = {...options};
22
+ if("showRowLabels" in options) {
23
+ options.timeline = { showRowLabels:options.showRowLabels };
24
+ }
25
+ return options;
26
+ },
27
+ rowTransform(row,i) {
28
+ return row.map((item,index) => {
29
+ if(item && (index===2 || index===3)) {
30
+ const date = new Date(item);
31
+ if(!date || typeof(date)!=="object" || !(date instanceof Date)) {
32
+ throw new TypeError(`row:${i} col:${index} is not a date`);
33
+ }
34
+ return date;
35
+ }
36
+ return item;
37
+ })
38
+ }
39
+ });
40
+ </script>
41
+ </body>
42
+ </html>
package/examples/xor.html CHANGED
@@ -20,6 +20,7 @@
20
20
  variableName,
21
21
  value
22
22
  }) => {
23
+ debugger;
23
24
  if (variableName === "run" && value === true) {
24
25
  self.siblings.forEach((sibling) => {
25
26
  sibling.setVariableValue(variableName, false);
package/lightview.js CHANGED
@@ -147,13 +147,13 @@ const {observe} = (() => {
147
147
  } else {
148
148
  Object.assign(instance, JSON.parse(value));
149
149
  }
150
- if (toType !== Date) {
150
+ /*if (toType !== Date) {
151
151
  Object.defineProperty(instance, "constructor", {
152
152
  configurable: true,
153
153
  writable: true,
154
154
  value: toType.prototype.constructor || toType
155
155
  });
156
- }
156
+ }*/
157
157
  return instance;
158
158
  }
159
159
  return JSON.parse(value);
@@ -178,7 +178,10 @@ const {observe} = (() => {
178
178
  if (property === "toJSON") return function toJSON() { return [...target]; }
179
179
  if (property === "toString") return function toString() { return JSON.stringify([...target]); }
180
180
  }
181
- if(target instanceof Date) return Reflect.get(target,property);
181
+ if(target instanceof Date) {
182
+ const value = data[property];
183
+ if(typeof(value)==="function") return value.bind(data);
184
+ }
182
185
  let value = target[property];
183
186
  const type = typeof (value);
184
187
  if (CURRENTOBSERVER && typeof (property) !== "symbol" && type !== "function") {
@@ -354,8 +357,10 @@ const {observe} = (() => {
354
357
  if (template) {
355
358
  const name = getTemplateVariableName(template);
356
359
  try {
357
- let value = (name
358
- ? component[name] || walk(extras,name.split(".")) || walk(component.varsProxy,name.split("."))
360
+ const parts = name ? name.split(".") : null;
361
+ let value;
362
+ value = (parts
363
+ ? (value = walk(extras,parts)) || (value = walk(component.varsProxy,parts)) || (value == null ? component[name] : value)
359
364
  : Function("context", "extras", "with(context) { with(extras) { return `" + (safe ? template : Lightview.sanitizeTemplate(template)) + "` } }")(component.varsProxy,extras));
360
365
  //let value = Function("context", "with(context) { return `" + Lightview.sanitizeTemplate(template) + "` }")(component.varsProxy);
361
366
  if(typeof(value)==="function") return value;
@@ -398,7 +403,10 @@ const {observe} = (() => {
398
403
  let type = input.tagName === "SELECT" && input.hasAttribute("multiple") ? Array : inputTypeToType(inputtype);
399
404
  const variable = walk(component.vars,nameparts) || {type};
400
405
  if(type==="any") type = variable.type;
401
- if(value==null) value = input.getAttribute("value");
406
+ if(value==null) {
407
+ const avalue = input.getAttribute("value");
408
+ if(avalue) value = avalue;
409
+ }
402
410
  if(object && nameparts.length>1) {
403
411
  const [root,...path] = nameparts;
404
412
  object = walk(object,path,path.length-2,true);
@@ -472,9 +480,6 @@ const {observe} = (() => {
472
480
  return {
473
481
  init({variable, component}) {
474
482
  variable.shared = true;
475
- /*addEventListener("change", ({variableName, value}) => {
476
- if (variableName===variable.name && component.vars[variableName]?.shared) component.siblings.forEach((instance) => instance.setVariableValue(variableName, value))
477
- })*/
478
483
  variable.set = function(newValue) {
479
484
  if(component.vars[this.name]?.shared) component.siblings.forEach((instance) => instance.setVariableValue(this.name, newValue));
480
485
  }
@@ -617,9 +622,9 @@ const {observe} = (() => {
617
622
  if (script.attributes.src?.value?.includes("/lightview.js")) continue;
618
623
  const text = script.innerHTML
619
624
  .replaceAll(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, "$1") // remove comments;
620
- .replaceAll(/\r?\n/g, "") // remove \n
621
- .replaceAll(/import\s*\((\s*["'][\.\/].*["'])\)/g,`import(new URL($1,"${href ? href : window.location.href}").href)`) // handle relative paths
622
- .replaceAll(/'(([^'\\]|\\.)*)'/g,"\\'$1\\'"); // handle quotes
625
+ .replaceAll(/import\s*\((\s*["'][\.\/].*["'])\)(.*$)/gm,`import(new URL($1,"${href ? href : window.location.href}").href)$2`) // handle relative paths
626
+ .replaceAll(/'(([^'\\]|\\.)*)'/g,"\\'$1\\'") // handle quotes
627
+ .replaceAll(/\r?\n/g, ""); // remove \n
623
628
  const currentScript = document.createElement("script");
624
629
  if (script.className !== "lightview" && !((script.attributes.type?.value || "").includes("lightview/"))) {
625
630
  for (const attr of script.attributes) currentScript.setAttribute(attr.name,attr.value);
@@ -704,7 +709,11 @@ const {observe} = (() => {
704
709
  }
705
710
  })
706
711
  } else if (eltype!=="radio") {
707
- attr.value = value;
712
+ //attr.value = typeof(value)==="string" ? value : JSON.stringify(value);
713
+ let avalue = typeof(value)==="string" ? value : value.toString ? value.toString() : JSON.stringify(value);
714
+ if(avalue.startsWith('"')) avalue = avalue.substring(1);
715
+ if(avalue.endsWith('"')) avalue = avalue.substring(0,avalue.length-1);
716
+ attr.value = avalue;
708
717
  }
709
718
  }
710
719
  });
@@ -714,6 +723,7 @@ const {observe} = (() => {
714
723
  if (attr.name === "value" && attr.template) return;
715
724
  const {name, value} = attr,
716
725
  vname = node.attributes.name?.value;
726
+ if(value.includes("${")) attr.template = value;
717
727
  if (name === "type" && value=="radio" && vname) {
718
728
  bindInput(node, vname, this, undefined, object);
719
729
  observe(() => {
@@ -904,6 +914,7 @@ const {observe} = (() => {
904
914
  if(set!==undefined && constant!==undefined) throw new TypeError(`${key} has the constant value ${constant} and can't be set to ${set}`);
905
915
  variable.value = set;
906
916
  if(constant!==undefined) {
917
+ if(remote || imported) throw new TypeError(`${key} can't be a constant and also remote or imported`)
907
918
  variable.constant = true;
908
919
  variable.value = constant;
909
920
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightview",
3
- "version": "1.7.2b",
3
+ "version": "1.7.3b",
4
4
  "description": "Small, simple, powerful web UI and micro front end creation ... Great ideas from Svelte, React, Vue and Riot combined.",
5
5
  "main": "lightview.js",
6
6
  "scripts": {
package/test/basic.html CHANGED
@@ -5,10 +5,10 @@
5
5
  <title>Basic</title>
6
6
  <template id="x-test" name="joe" open="true" count=1 children='["mary"]' l-on:click="${bump}">
7
7
 
8
- <span id="children">${children}</span>
9
-
10
8
  <input id="idatetime" type="datetime" value="${idatetime}">
11
9
 
10
+ <span id="children">${children}</span>
11
+
12
12
  <span id="name">${name}</span>
13
13
  <span id="open">${open}</span>
14
14
  <span id="count">${count}</span>
@@ -63,7 +63,6 @@
63
63
 
64
64
  inumber = 1;
65
65
  irange = 1;
66
-
67
66
  idatetime = new Date();
68
67
 
69
68
  icheckbox = true;