lightview 1.7.1-b → 1.8.1-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/chart.html +7 -5
- package/components/chart/example.html +3 -5
- package/components/chart.html +67 -65
- package/components/components.js +29 -9
- package/components/gantt/example.html +2 -7
- package/components/gantt/gantt.html +33 -26
- package/components/gauge/example.html +1 -1
- package/components/gauge/gauge.html +20 -0
- package/components/gauge.html +47 -44
- package/components/orgchart/example.html +25 -0
- package/components/orgchart/orgchart.html +41 -0
- package/components/repl/code-editor.html +64 -0
- package/components/repl/editor.html +37 -0
- package/components/repl/editorjs-inline-tool/index.js +3 -0
- package/components/repl/editorjs-inline-tool/inline-tools.js +28 -0
- package/components/repl/editorjs-inline-tool/tool.js +175 -0
- package/components/repl/repl-with-wysiwyg.html +355 -0
- package/components/repl/repl.html +345 -0
- package/components/repl/sup.js +44 -0
- package/components/repl/wysiwyg-repl.html +258 -0
- package/components/timeline/example.html +33 -0
- package/components/timeline/timeline.html +44 -0
- package/examples/anchor.html +11 -0
- package/examples/chart.html +22 -54
- package/examples/counter.html +5 -3
- package/examples/counter2.html +26 -0
- package/examples/directives.html +19 -17
- package/examples/forgeinform.html +45 -43
- package/examples/form.html +22 -20
- package/examples/gauge.html +2 -0
- package/examples/invalid-template-literals.html +5 -3
- package/examples/message.html +10 -4
- package/examples/nested.html +1 -1
- package/examples/object-bound-form.html +12 -10
- package/examples/remote.html +17 -15
- package/examples/shared.html +41 -0
- package/examples/xor.html +21 -19
- package/lightview.js +138 -90
- package/package.json +7 -2
- package/sites/client.html +48 -0
- package/sites/index.html +247 -0
- package/test/basic.html +17 -16
- package/test/basic.test.mjs +0 -10
- package/test/extended.html +17 -20
- package/types.js +10 -1
- package/unsplash.key +1 -0
- package/components/gauge/guage.html +0 -19
- package/examples/duration.html +0 -279
package/examples/xor.html
CHANGED
|
@@ -7,25 +7,27 @@
|
|
|
7
7
|
<p>
|
|
8
8
|
Play: <input type="checkbox" value="${run}">
|
|
9
9
|
</p>
|
|
10
|
-
<script
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
<script id="lightview">
|
|
11
|
+
(document.currentComponent||(document.currentComponent=document.body)).mount = async function() {
|
|
12
|
+
self.variables({
|
|
13
|
+
run: "boolean"
|
|
14
|
+
}, {reactive});
|
|
15
|
+
self.variables({
|
|
16
|
+
name: "string"
|
|
17
|
+
}, {
|
|
18
|
+
imported
|
|
19
|
+
});
|
|
20
|
+
addEventListener("change", ({
|
|
21
|
+
variableName,
|
|
22
|
+
value
|
|
23
|
+
}) => {
|
|
24
|
+
if (variableName === "run" && value === true) {
|
|
25
|
+
self.siblings.forEach((sibling) => {
|
|
26
|
+
sibling.setVariableValue(variableName, false);
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
29
31
|
</script>
|
|
30
32
|
</template>
|
|
31
33
|
<title>Lightview:Examples:XOR</title>
|
package/lightview.js
CHANGED
|
@@ -28,6 +28,8 @@ SOFTWARE.
|
|
|
28
28
|
imported(x) => exported(x) => reactive(x) => remote(x,{path:".
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
+
if(document.body) document.currentComponent = document.body;
|
|
32
|
+
|
|
31
33
|
const Lightview = {};
|
|
32
34
|
|
|
33
35
|
const {observe} = (() => {
|
|
@@ -143,19 +145,10 @@ const {observe} = (() => {
|
|
|
143
145
|
}
|
|
144
146
|
instance.push(...parsed);
|
|
145
147
|
} else if (instance instanceof Date) {
|
|
146
|
-
|
|
147
|
-
if(!isNaN(time)) instance.setTime(time);
|
|
148
|
-
else return;
|
|
148
|
+
instance.setTime(Date.parse(value));
|
|
149
149
|
} else {
|
|
150
150
|
Object.assign(instance, JSON.parse(value));
|
|
151
151
|
}
|
|
152
|
-
/*if (toType !== Date) {
|
|
153
|
-
Object.defineProperty(instance, "constructor", {
|
|
154
|
-
configurable: true,
|
|
155
|
-
writable: true,
|
|
156
|
-
value: toType.prototype.constructor || toType
|
|
157
|
-
});
|
|
158
|
-
}*/
|
|
159
152
|
return instance;
|
|
160
153
|
}
|
|
161
154
|
return JSON.parse(value);
|
|
@@ -180,10 +173,11 @@ const {observe} = (() => {
|
|
|
180
173
|
if (property === "toJSON") return function toJSON() { return [...target]; }
|
|
181
174
|
if (property === "toString") return function toString() { return JSON.stringify([...target]); }
|
|
182
175
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
value
|
|
176
|
+
if(target instanceof Date) {
|
|
177
|
+
const value = data[property];
|
|
178
|
+
if(typeof(value)==="function") return value.bind(data);
|
|
186
179
|
}
|
|
180
|
+
let value = target[property];
|
|
187
181
|
const type = typeof (value);
|
|
188
182
|
if (CURRENTOBSERVER && typeof (property) !== "symbol" && type !== "function") {
|
|
189
183
|
const observers = dependents[property] ||= new Set();
|
|
@@ -237,6 +231,7 @@ const {observe} = (() => {
|
|
|
237
231
|
const createVarsProxy = (vars, component, constructor) => {
|
|
238
232
|
return new Proxy(vars, {
|
|
239
233
|
get(target, property) {
|
|
234
|
+
if(property==="self") return component;
|
|
240
235
|
if(target instanceof Date) return Reflect.get(target,property);
|
|
241
236
|
let {value,get} = target[property] || {};
|
|
242
237
|
if(get) return target[property].value = get.call(target[property]);
|
|
@@ -276,6 +271,9 @@ const {observe} = (() => {
|
|
|
276
271
|
throw new TypeError(`Can't assign instance of '${newValue.constructor.name}' to variable '${property}:${type.name.replace("bound ", "")}'`)
|
|
277
272
|
}
|
|
278
273
|
throw new TypeError(`Can't assign '${typeof (newValue)} ${newtype === "string" ? '"' + newValue + '"' : newValue}' to variable '${property}:${typetype === "function" ? type.name.replace("bound ", "") : type} ${type.required ? "required" : ""}'`)
|
|
274
|
+
},
|
|
275
|
+
keys() {
|
|
276
|
+
return [...Object.keys(vars)];
|
|
279
277
|
}
|
|
280
278
|
});
|
|
281
279
|
}
|
|
@@ -355,8 +353,10 @@ const {observe} = (() => {
|
|
|
355
353
|
if (template) {
|
|
356
354
|
const name = getTemplateVariableName(template);
|
|
357
355
|
try {
|
|
358
|
-
|
|
359
|
-
|
|
356
|
+
const parts = name ? name.split(".") : null;
|
|
357
|
+
let value;
|
|
358
|
+
value = (parts
|
|
359
|
+
? (value = walk(extras,parts)) || (value = walk(component.varsProxy,parts)) || (value == null ? component[name] : value)
|
|
360
360
|
: Function("context", "extras", "with(context) { with(extras) { return `" + (safe ? template : Lightview.sanitizeTemplate(template)) + "` } }")(component.varsProxy,extras));
|
|
361
361
|
//let value = Function("context", "with(context) { return `" + Lightview.sanitizeTemplate(template) + "` }")(component.varsProxy);
|
|
362
362
|
if(typeof(value)==="function") return value;
|
|
@@ -398,23 +398,28 @@ const {observe} = (() => {
|
|
|
398
398
|
nameparts = variableName.split(".");
|
|
399
399
|
let type = input.tagName === "SELECT" && input.hasAttribute("multiple") ? Array : inputTypeToType(inputtype);
|
|
400
400
|
const variable = walk(component.vars,nameparts) || {type};
|
|
401
|
-
if(type==="any") type = variable.type;
|
|
402
|
-
if(value==null)
|
|
401
|
+
if(type==="any") type = variable?.type.type || variable?.type;
|
|
402
|
+
if(value==null) {
|
|
403
|
+
const avalue = input.getAttribute("value");
|
|
404
|
+
if(avalue) value = avalue;
|
|
405
|
+
}
|
|
403
406
|
if(object && nameparts.length>1) {
|
|
404
407
|
const [root,...path] = nameparts;
|
|
405
408
|
object = walk(object,path,path.length-2,true);
|
|
406
409
|
const key = path[path.length-1];
|
|
407
410
|
object[key] = coerce(value,type);
|
|
408
411
|
} else {
|
|
409
|
-
if (type !== variable.type) {
|
|
410
|
-
if (variable.type === "any" || variable.type === "unknown") variable.type = type;
|
|
411
|
-
else throw new TypeError(`Attempt to bind <input name="${variableName}" type="${type}"> to variable ${variableName}:${variable.type}`)
|
|
412
|
-
}
|
|
413
412
|
const existing = component.vars[variableName];
|
|
414
|
-
if(
|
|
413
|
+
if(existing) {
|
|
414
|
+
existingtype = existing?.type.type || existing?.type;
|
|
415
|
+
if(existingtype!==type) throw new TypeError(`Attempt to bind <input name="${variableName}" type="${type}"> to variable ${variableName}:${existing.type}`)
|
|
416
|
+
existing.reactive = true;
|
|
417
|
+
} else {
|
|
418
|
+
component.variables({[variableName]: type},{reactive});
|
|
419
|
+
}
|
|
415
420
|
if(inputtype!=="radio") {
|
|
416
|
-
if(typeof(value)==="string" && value.includes("${")) input.
|
|
417
|
-
else
|
|
421
|
+
if(typeof(value)==="string" && value.includes("${")) input.setAttribute("value","");
|
|
422
|
+
else component.setVariableValue(variableName, coerce(value,type));
|
|
418
423
|
}
|
|
419
424
|
}
|
|
420
425
|
let eventname = "change";
|
|
@@ -473,9 +478,6 @@ const {observe} = (() => {
|
|
|
473
478
|
return {
|
|
474
479
|
init({variable, component}) {
|
|
475
480
|
variable.shared = true;
|
|
476
|
-
/*addEventListener("change", ({variableName, value}) => {
|
|
477
|
-
if (variableName===variable.name && component.vars[variableName]?.shared) component.siblings.forEach((instance) => instance.setVariableValue(variableName, value))
|
|
478
|
-
})*/
|
|
479
481
|
variable.set = function(newValue) {
|
|
480
482
|
if(component.vars[this.name]?.shared) component.siblings.forEach((instance) => instance.setVariableValue(this.name, newValue));
|
|
481
483
|
}
|
|
@@ -533,22 +535,43 @@ const {observe} = (() => {
|
|
|
533
535
|
value: imported
|
|
534
536
|
}
|
|
535
537
|
};
|
|
536
|
-
const createClass = (domElementNode, {observer, framed}) => {
|
|
538
|
+
const createClass = (domElementNode, {observer, framed, href=window.location.href}) => {
|
|
537
539
|
const instances = new Set(),
|
|
538
|
-
dom = domElementNode.tagName === "TEMPLATE"
|
|
539
|
-
? domElementNode.content.cloneNode(true)
|
|
540
|
-
: domElementNode.cloneNode(true),
|
|
541
540
|
observedAttributes = [];
|
|
541
|
+
/*let dom = domElementNode.tagName === "TEMPLATE"
|
|
542
|
+
? domElementNode.content.cloneNode(true)
|
|
543
|
+
: domElementNode.cloneNode(true);*/
|
|
544
|
+
let dom;
|
|
542
545
|
observedAttributes.add = function(name) { observedAttributes.includes(name) || observedAttributes.push(name); }
|
|
543
|
-
|
|
544
|
-
return class CustomElement extends HTMLElement {
|
|
546
|
+
const cls = class CustomElement extends HTMLElement {
|
|
545
547
|
static get instances() {
|
|
546
548
|
return instances;
|
|
547
549
|
}
|
|
550
|
+
static setTemplateNode(node) {
|
|
551
|
+
dom = node.tagName === "TEMPLATE"
|
|
552
|
+
? document.createElement("div")
|
|
553
|
+
: node.cloneNode(true);
|
|
554
|
+
if(node.tagName === "TEMPLATE") {
|
|
555
|
+
dom.innerHTML = node.innerHTML;
|
|
556
|
+
[...node.attributes].forEach((attr) => dom.setAttribute(attr.name,attr.value));
|
|
557
|
+
document.currentComponent = node;
|
|
558
|
+
document.currentComponent.componentBaseURI = window.location.href;
|
|
559
|
+
const lvscript = dom.querySelector("#lightview");
|
|
560
|
+
if(lvscript) {
|
|
561
|
+
const script = document.createElement("script");
|
|
562
|
+
script.innerHTML = lvscript.innerHTML;
|
|
563
|
+
document.head.appendChild(script);
|
|
564
|
+
script.remove();
|
|
565
|
+
}
|
|
566
|
+
document.currentComponent = null;
|
|
567
|
+
}
|
|
568
|
+
dom.mount = node.mount;
|
|
569
|
+
}
|
|
548
570
|
constructor() {
|
|
549
571
|
super();
|
|
572
|
+
this.componentBaseURI = href;
|
|
550
573
|
instances.add(this);
|
|
551
|
-
const currentComponent = this,
|
|
574
|
+
const currentComponent = document.currentComponent =this,
|
|
552
575
|
shadow = this.attachShadow({mode: "open"}),
|
|
553
576
|
eventlisteners = {};
|
|
554
577
|
this.vars = {
|
|
@@ -581,7 +604,6 @@ const {observe} = (() => {
|
|
|
581
604
|
},
|
|
582
605
|
self: {value: currentComponent, type: CustomElement, constant: true}
|
|
583
606
|
};
|
|
584
|
-
this.defaultAttributes = domElementNode.tagName === "TEMPLATE" ? domElementNode.attributes : dom.attributes;
|
|
585
607
|
this.varsProxy = createVarsProxy(this.vars, this, CustomElement);
|
|
586
608
|
if (framed || CustomElement.lightviewFramed) this.variables({message: Object}, {exported});
|
|
587
609
|
["getElementById", "querySelector", "querySelectorAll"]
|
|
@@ -592,7 +614,17 @@ const {observe} = (() => {
|
|
|
592
614
|
value: (...args) => this.shadowRoot[fname](...args)
|
|
593
615
|
})
|
|
594
616
|
});
|
|
595
|
-
[...dom.childNodes].forEach((child) =>
|
|
617
|
+
[...dom.childNodes].forEach((child) => {
|
|
618
|
+
if(child.tagName && customElements.get(child.tagName.toLowerCase())) {
|
|
619
|
+
const node = document.createElement(child.tagName);
|
|
620
|
+
[...child.attributes].forEach((attr) => node.setAttribute(attr.name,attr.value));
|
|
621
|
+
document.currentComponent = node;
|
|
622
|
+
shadow.appendChild(node);
|
|
623
|
+
} else {
|
|
624
|
+
const node = child.cloneNode(true);
|
|
625
|
+
shadow.appendChild(node);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
596
628
|
importAnchors(shadow, this);
|
|
597
629
|
}
|
|
598
630
|
|
|
@@ -608,57 +640,44 @@ const {observe} = (() => {
|
|
|
608
640
|
instances.delete(this);
|
|
609
641
|
}
|
|
610
642
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
.
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
for (const attr of script.attributes) currentScript.setAttribute(attr.name,attr.value);
|
|
627
|
-
currentScript.innerHTML = text;
|
|
628
|
-
shadow.appendChild(currentScript);
|
|
629
|
-
await new Promise((resolve) => {
|
|
630
|
-
const timeout = setTimeout(() => resolve(),500);
|
|
631
|
-
currentScript.onload = () => {
|
|
632
|
-
clearTimeout(timeout);
|
|
633
|
-
currentScript.remove();
|
|
634
|
-
resolve();
|
|
635
|
-
}
|
|
636
|
-
})
|
|
637
|
-
continue;
|
|
638
|
-
};
|
|
639
|
-
const scriptid = Math.random() + "";
|
|
640
|
-
for (const attr of script.attributes) {
|
|
641
|
-
currentScript.setAttribute(attr.name, attr.name === "type" ? attr.value.replace("lightview/", "") : attr.value);
|
|
642
|
-
}
|
|
643
|
-
currentScript.classList.remove("lightview");
|
|
644
|
-
currentScript.innerHTML = `Object.getPrototypeOf(async function(){}).constructor('if(window["${scriptid}"]?.ctx) { const ctx = window["${scriptid}"].ctx; { with(ctx) { ${text}; } } }')().then(() => window["${scriptid}"]()); `;
|
|
645
|
-
await new Promise((resolve) => {
|
|
646
|
-
window[scriptid] = () => {
|
|
647
|
-
delete window[scriptid];
|
|
648
|
-
currentScript.remove();
|
|
649
|
-
script.remove();
|
|
650
|
-
resolve();
|
|
651
|
-
}
|
|
652
|
-
window[scriptid].ctx = ctx.varsProxy;
|
|
653
|
-
shadow.appendChild(currentScript);
|
|
654
|
-
})
|
|
643
|
+
connectedCallback() {
|
|
644
|
+
[...dom.attributes].forEach((attr) => {
|
|
645
|
+
if(!this.hasAttribute(attr.name)) this.setAttribute(attr.name,attr.value);
|
|
646
|
+
})
|
|
647
|
+
if(dom.mount) {
|
|
648
|
+
const script = document.createElement("script");
|
|
649
|
+
document.currentComponent = this;
|
|
650
|
+
script.innerHTML = `with(document.currentComponent.varsProxy) {
|
|
651
|
+
const component = document.currentComponent;
|
|
652
|
+
(async () => { await (${dom.mount}).call(self,self);
|
|
653
|
+
component.compile(); })();
|
|
654
|
+
};`;
|
|
655
|
+
this.appendChild(script);
|
|
656
|
+
script.remove();
|
|
657
|
+
document.currentComponent = null;
|
|
655
658
|
}
|
|
659
|
+
}
|
|
660
|
+
compile() {
|
|
656
661
|
// Promise.all(promises).then(() => {
|
|
662
|
+
const ctx = this,
|
|
663
|
+
shadow = this.shadowRoot;
|
|
657
664
|
const nodes = getNodes(ctx),
|
|
658
665
|
processNodes = (nodes,object) => {
|
|
659
666
|
nodes.forEach((node) => {
|
|
660
667
|
if (node.nodeType === Node.TEXT_NODE && node.template.includes("${")) {
|
|
661
668
|
observe(() => resolveNodeOrText(node, this,true,node.extras));
|
|
669
|
+
if(node.parentElement?.tagName==="TEXTAREA") {
|
|
670
|
+
const name = getTemplateVariableName(node.template);
|
|
671
|
+
if (name) {
|
|
672
|
+
const nameparts = name.split(".");
|
|
673
|
+
if(node.extras && node.extras[nameparts[0]]) {
|
|
674
|
+
object = node.extras[nameparts[0]];
|
|
675
|
+
}
|
|
676
|
+
if(!this.vars[nameparts[0]] || this.vars[nameparts[0]].reactive || object) {
|
|
677
|
+
bindInput(node.parentElement, name, this, resolveNodeOrText(node.template, this,true,node.extras), object);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
662
681
|
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
663
682
|
// resolve the value before all else;
|
|
664
683
|
const attr = node.attributes.value,
|
|
@@ -673,7 +692,7 @@ const {observe} = (() => {
|
|
|
673
692
|
if (name) {
|
|
674
693
|
const nameparts = name.split(".");
|
|
675
694
|
if(node.extras && node.extras[nameparts[0]]) {
|
|
676
|
-
|
|
695
|
+
object = node.extras[nameparts[0]];
|
|
677
696
|
}
|
|
678
697
|
if(!this.vars[nameparts[0]] || this.vars[nameparts[0]].reactive || object) {
|
|
679
698
|
bindInput(node, name, this, resolveNodeOrText(attr, this,false,node.extras), object);
|
|
@@ -705,7 +724,11 @@ const {observe} = (() => {
|
|
|
705
724
|
}
|
|
706
725
|
})
|
|
707
726
|
} else if (eltype!=="radio") {
|
|
708
|
-
attr.value = value;
|
|
727
|
+
//attr.value = typeof(value)==="string" ? value : JSON.stringify(value);
|
|
728
|
+
let avalue = typeof(value)==="string" ? value : value.toString ? value.toString() : JSON.stringify(value);
|
|
729
|
+
if(avalue.startsWith('"')) avalue = avalue.substring(1);
|
|
730
|
+
if(avalue.endsWith('"')) avalue = avalue.substring(0,avalue.length-1);
|
|
731
|
+
attr.value = avalue;
|
|
709
732
|
}
|
|
710
733
|
}
|
|
711
734
|
});
|
|
@@ -713,9 +736,9 @@ const {observe} = (() => {
|
|
|
713
736
|
}
|
|
714
737
|
[...node.attributes].forEach(async (attr) => {
|
|
715
738
|
if (attr.name === "value" && attr.template) return;
|
|
716
|
-
attr.template ||= attr.nodeValue?.includes("${") ? attr.nodeValue : undefined;
|
|
717
739
|
const {name, value} = attr,
|
|
718
740
|
vname = node.attributes.name?.value;
|
|
741
|
+
if(value.includes("${")) attr.template = value;
|
|
719
742
|
if (name === "type" && value=="radio" && vname) {
|
|
720
743
|
bindInput(node, vname, this, undefined, object);
|
|
721
744
|
observe(() => {
|
|
@@ -766,7 +789,7 @@ const {observe} = (() => {
|
|
|
766
789
|
} else if (type === "l-if") {
|
|
767
790
|
observe(() => {
|
|
768
791
|
const value = resolveNodeOrText(attr, this,true,node.extras);
|
|
769
|
-
node.style.setProperty("display", value == true ? "revert" : "none");
|
|
792
|
+
node.style.setProperty("display", value == true || value === "true" ? "revert" : "none");
|
|
770
793
|
})
|
|
771
794
|
} else if (type === "l-for") {
|
|
772
795
|
node.template ||= node.innerHTML;
|
|
@@ -798,10 +821,14 @@ const {observe} = (() => {
|
|
|
798
821
|
while (node.lastElementChild) node.lastElementChild.remove();
|
|
799
822
|
}
|
|
800
823
|
}
|
|
824
|
+
//const nodes = getNodes(parsed.body);
|
|
801
825
|
children.forEach((child) => {
|
|
826
|
+
//while (parsed.body.firstChild) {
|
|
827
|
+
//const child = parsed.body.firstChild;
|
|
802
828
|
if (after) node.parentElement.insertBefore(child, node);
|
|
803
829
|
else node.appendChild(child);
|
|
804
830
|
})
|
|
831
|
+
//processNodes(nodes);
|
|
805
832
|
})
|
|
806
833
|
} else if(attr.template) {
|
|
807
834
|
observe(() => {
|
|
@@ -833,7 +860,7 @@ const {observe} = (() => {
|
|
|
833
860
|
observer.observe(ctx, {attributeOldValue: true, subtree:true, characterData:true, characterDataOldValue:true});
|
|
834
861
|
if(this.hasAttribute("l-unhide")) this.removeAttribute("hidden");
|
|
835
862
|
//ctx.vars.postEvent.value("connected");
|
|
836
|
-
this.dispatchEvent(new Event("
|
|
863
|
+
this.dispatchEvent(new Event("mounted"));
|
|
837
864
|
// })
|
|
838
865
|
}
|
|
839
866
|
adoptedCallback(callback) {
|
|
@@ -902,6 +929,7 @@ const {observe} = (() => {
|
|
|
902
929
|
if(set!==undefined && constant!==undefined) throw new TypeError(`${key} has the constant value ${constant} and can't be set to ${set}`);
|
|
903
930
|
variable.value = set;
|
|
904
931
|
if(constant!==undefined) {
|
|
932
|
+
if(remote || imported) throw new TypeError(`${key} can't be a constant and also remote or imported`)
|
|
905
933
|
variable.constant = true;
|
|
906
934
|
variable.value = constant;
|
|
907
935
|
}
|
|
@@ -928,16 +956,18 @@ const {observe} = (() => {
|
|
|
928
956
|
}, {});
|
|
929
957
|
}
|
|
930
958
|
}
|
|
959
|
+
cls.setTemplateNode(domElementNode);
|
|
960
|
+
return cls;
|
|
931
961
|
}
|
|
932
962
|
|
|
933
|
-
const createComponent = (name, node, {framed, observer} = {}) => {
|
|
963
|
+
const createComponent = (name, node, {framed, observer, href} = {}) => {
|
|
934
964
|
let ctor = customElements.get(name);
|
|
935
965
|
if (ctor) {
|
|
936
966
|
if (framed && !ctor.lightviewFramed) ctor.lightviewFramed = true;
|
|
937
967
|
else console.warn(new Error(`${name} is already a CustomElement. Not redefining`));
|
|
938
968
|
return ctor;
|
|
939
969
|
}
|
|
940
|
-
ctor = createClass(node, {observer, framed});
|
|
970
|
+
ctor = createClass(node, {observer, framed, href});
|
|
941
971
|
customElements.define(name, ctor);
|
|
942
972
|
Lightview.customElements.set(name, ctor);
|
|
943
973
|
return ctor;
|
|
@@ -954,16 +984,34 @@ const {observe} = (() => {
|
|
|
954
984
|
const html = await (await fetch(url.href)).text(),
|
|
955
985
|
dom = parser.parseFromString(html, "text/html"),
|
|
956
986
|
unhide = !!dom.head.querySelector('meta[name="l-unhide"]'),
|
|
957
|
-
|
|
958
|
-
for (const childlink of
|
|
987
|
+
modulelinks = dom.head.querySelectorAll('link[href$=".html"][rel=module]');
|
|
988
|
+
for (const childlink of modulelinks) {
|
|
959
989
|
const href = childlink.getAttribute("href"),
|
|
960
990
|
childurl = new URL(href, url.href);
|
|
961
991
|
childlink.setAttribute("href", childurl.href);
|
|
962
992
|
if (link.hasAttribute("crossorigin")) childlink.setAttribute("crossorigin", link.getAttribute("crossorigin"))
|
|
963
993
|
await importLink(childlink, observer);
|
|
964
994
|
}
|
|
995
|
+
const links = dom.head.querySelectorAll('link:not([href$=".html"][rel=module])');
|
|
996
|
+
for(const childlink of links) {
|
|
997
|
+
const href = childlink.getAttribute("href"),
|
|
998
|
+
childurl = new URL(href, url.href);
|
|
999
|
+
childlink.setAttribute("href", childurl.href);
|
|
1000
|
+
if (link.hasAttribute("crossorigin")) childlink.setAttribute("crossorigin", link.getAttribute("crossorigin"));
|
|
1001
|
+
dom.body.insertBefore(childlink,dom.body.firstChild);
|
|
1002
|
+
}
|
|
1003
|
+
document.currentComponent = dom.body;
|
|
1004
|
+
document.currentComponent.componentBaseURI = url.href;
|
|
1005
|
+
const lvscript = dom.getElementById("lightview");
|
|
1006
|
+
if(lvscript) {
|
|
1007
|
+
const script = document.createElement("script");
|
|
1008
|
+
script.innerHTML = lvscript.innerHTML;
|
|
1009
|
+
document.body.appendChild(script);
|
|
1010
|
+
script.remove();
|
|
1011
|
+
}
|
|
1012
|
+
document.currentComponent = null;
|
|
1013
|
+
createComponent(as, dom.body, {observer,href:url.href});
|
|
965
1014
|
if (unhide) dom.body.removeAttribute("hidden");
|
|
966
|
-
createComponent(as, dom.body, {observer});
|
|
967
1015
|
}
|
|
968
1016
|
return {as};
|
|
969
1017
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightview",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1b",
|
|
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": {
|
|
@@ -28,9 +28,14 @@
|
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/anywhichway/lightview/issues"
|
|
30
30
|
},
|
|
31
|
-
"homepage": "https://
|
|
31
|
+
"homepage": "https://lightview.dev",
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@editorjs/editorjs": "^2.16.0",
|
|
34
|
+
"editorjs-inline-tool": "^0.4.0",
|
|
33
35
|
"jest": "^27.5.1",
|
|
34
36
|
"jest-puppeteer": "^6.1.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"froala-editor": "^4.0.11"
|
|
35
40
|
}
|
|
36
41
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Lightview:Sites:Client</title>
|
|
6
|
+
<template id="template"></template>
|
|
7
|
+
<script src="../lightview.js"></script>
|
|
8
|
+
<script src="https://unpkg.com/peerjs@1.3.2/dist/peerjs.min.js"></script>
|
|
9
|
+
<script>
|
|
10
|
+
const template = document.getElementById("template"),
|
|
11
|
+
client = new Peer("anywhichway3",{debug:3});
|
|
12
|
+
client.on("open",(id) => {
|
|
13
|
+
console.log(id);
|
|
14
|
+
setTimeout(()=> document.body.innerHTML+=id);
|
|
15
|
+
const server = client.connect("anywhichway1");
|
|
16
|
+
server.on("open",() => {
|
|
17
|
+
server.send("Hi from " + id);
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
server.send("Hi from " + id);
|
|
20
|
+
},5000);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
client.on("connection",(conn) => {
|
|
24
|
+
//conn.on("open",() => {
|
|
25
|
+
// conn.send("Client does not accept inbound connections")
|
|
26
|
+
// });
|
|
27
|
+
conn.on("data",(data) => {
|
|
28
|
+
console.log(data);
|
|
29
|
+
template.innerHTML = data;
|
|
30
|
+
setTimeout(()=> document.body.innerHTML=data);
|
|
31
|
+
const component = window.customElements.get("x-body");
|
|
32
|
+
if(component) component.setTemplateNode(template)
|
|
33
|
+
else Lightview.createComponent("x-body",template);
|
|
34
|
+
const body = document.createElement("x-body");
|
|
35
|
+
document.body.parentElement.replaceChild(body, document.body);
|
|
36
|
+
Object.defineProperty(document, "body", {
|
|
37
|
+
enumerable: true, configurable: true, get() {
|
|
38
|
+
return body;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|