@pod-os/elements 0.37.0 → 0.38.0-rc.4b2b787.0
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/dist/cjs/elements.cjs.js +1 -1
- package/dist/cjs/{index-OR1wNkjG.js → index-CmQJab4P.js} +70 -19
- package/dist/cjs/{jsonld-V2RB47OZ-B82QNsYZ.js → jsonld-V2RB47OZ-BpANcb5R.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/pos-add-literal-value_3.cjs.entry.js +1 -1
- package/dist/cjs/pos-add-new-thing_32.cjs.entry.js +2 -2
- package/dist/cjs/pos-container-contents.cjs.entry.js +3 -3
- package/dist/cjs/pos-list.cjs.entry.js +1 -1
- package/dist/cjs/pos-markdown-document.cjs.entry.js +2 -2
- package/dist/cjs/pos-subjects.cjs.entry.js +1 -1
- package/dist/cjs/pos-switch.cjs.entry.js +41 -7
- package/dist/collection/components/pos-app/pos-app.js +1 -1
- package/dist/collection/components/pos-container-contents/pos-container-contents.js +2 -2
- package/dist/collection/components/pos-list/pos-list.js +1 -1
- package/dist/collection/components/pos-markdown-document/pos-markdown-document.js +2 -2
- package/dist/collection/components/pos-switch/pos-case/pos-case.js +38 -0
- package/dist/collection/components/pos-switch/pos-switch.js +44 -8
- package/dist/components/index2.js +2 -2
- package/dist/components/pos-app2.js +1 -1
- package/dist/components/pos-case.js +1 -1
- package/dist/components/pos-container-contents2.js +1 -1
- package/dist/components/pos-list.js +1 -1
- package/dist/components/pos-markdown-document2.js +1 -1
- package/dist/components/pos-switch.js +1 -1
- package/dist/elements/elements.esm.js +1 -1
- package/dist/elements/p-07f69d8c.entry.js +1 -0
- package/dist/elements/{p-dc4c38c8.entry.js → p-59e18120.entry.js} +1 -1
- package/dist/elements/{p-c7032012.entry.js → p-935e8df7.entry.js} +1 -1
- package/dist/elements/{p-ab4eba43.entry.js → p-9899cefb.entry.js} +2 -2
- package/dist/elements/{p-8e76e9dc.entry.js → p-9ac2654c.entry.js} +1 -1
- package/dist/elements/{p-a1dd6b42.entry.js → p-9dbe8f72.entry.js} +1 -1
- package/dist/elements/{p-BLUiM5OK.js → p-DUt7ij35.js} +1 -1
- package/dist/elements/p-Dzr3lPEW.js +67 -0
- package/dist/elements/p-cfa86eeb.entry.js +1 -0
- package/dist/esm/elements.js +1 -1
- package/dist/esm/{index-CXK32bJz.js → index-DymdXook.js} +70 -19
- package/dist/esm/{jsonld-V2RB47OZ-BbN7F0s8.js → jsonld-V2RB47OZ-CtbtC7fM.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/pos-add-literal-value_3.entry.js +1 -1
- package/dist/esm/pos-add-new-thing_32.entry.js +2 -2
- package/dist/esm/pos-container-contents.entry.js +3 -3
- package/dist/esm/pos-list.entry.js +1 -1
- package/dist/esm/pos-markdown-document.entry.js +2 -2
- package/dist/esm/pos-subjects.entry.js +1 -1
- package/dist/esm/pos-switch.entry.js +41 -7
- package/dist/types/components/pos-switch/pos-case/pos-case.d.ts +8 -0
- package/dist/types/components/pos-switch/pos-switch.d.ts +7 -3
- package/dist/types/components.d.ts +18 -0
- package/package.json +2 -2
- package/dist/elements/p-3a890f5f.entry.js +0 -1
- package/dist/elements/p-53610ccd.entry.js +0 -1
- package/dist/elements/p-DHl0QGLf.js +0 -67
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
2
|
import { subscribeResource } from "../events/ResourceAware";
|
|
3
|
+
import { combineLatest, firstValueFrom, Subject, takeUntil } from "rxjs";
|
|
3
4
|
/**
|
|
4
5
|
* Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.
|
|
5
6
|
* See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.
|
|
@@ -8,27 +9,56 @@ import { subscribeResource } from "../events/ResourceAware";
|
|
|
8
9
|
export class PosSwitch {
|
|
9
10
|
constructor() {
|
|
10
11
|
this.error = null;
|
|
12
|
+
this.disconnected$ = new Subject();
|
|
11
13
|
this.receiveResource = (resource) => {
|
|
12
|
-
|
|
14
|
+
// reset any existing resource
|
|
15
|
+
this.disconnected$.next();
|
|
16
|
+
this.resource = undefined;
|
|
17
|
+
let observables = [];
|
|
18
|
+
if (this.caseElements.some(caseElement => caseElement.hasAttribute('if-typeof'))) {
|
|
19
|
+
const observeTypes = resource.observeTypes().pipe(takeUntil(this.disconnected$));
|
|
20
|
+
observeTypes.subscribe(types => {
|
|
21
|
+
this.types = types;
|
|
22
|
+
});
|
|
23
|
+
observables.push(observeTypes);
|
|
24
|
+
}
|
|
25
|
+
if (this.caseElements.some(caseElement => caseElement.hasAttribute('if-property'))) {
|
|
26
|
+
const observeRelations = resource.observeRelations().pipe(takeUntil(this.disconnected$));
|
|
27
|
+
observeRelations.subscribe(relations => {
|
|
28
|
+
this.relations = relations;
|
|
29
|
+
});
|
|
30
|
+
observables.push(observeRelations);
|
|
31
|
+
}
|
|
32
|
+
if (this.caseElements.some(caseElement => caseElement.hasAttribute('if-rev'))) {
|
|
33
|
+
const observeReverseRelations = resource.observeReverseRelations().pipe(takeUntil(this.disconnected$));
|
|
34
|
+
observeReverseRelations.subscribe(reverseRelations => {
|
|
35
|
+
this.reverseRelations = reverseRelations;
|
|
36
|
+
});
|
|
37
|
+
observables.push(observeReverseRelations);
|
|
38
|
+
}
|
|
39
|
+
firstValueFrom(combineLatest(observables)).then(() => (this.resource = resource));
|
|
13
40
|
};
|
|
14
41
|
}
|
|
15
42
|
componentWillLoad() {
|
|
16
|
-
subscribeResource(this);
|
|
17
43
|
const caseElements = this.host.querySelectorAll('pos-case');
|
|
18
44
|
if (caseElements.length == 0) {
|
|
19
45
|
this.error = 'No pos-case elements found';
|
|
20
46
|
}
|
|
21
47
|
else {
|
|
22
|
-
this.caseElements = caseElements;
|
|
48
|
+
this.caseElements = Array.from(caseElements);
|
|
49
|
+
subscribeResource(this);
|
|
23
50
|
}
|
|
24
51
|
}
|
|
25
52
|
test(caseElement) {
|
|
26
53
|
let state = null;
|
|
27
54
|
if (caseElement.getAttribute('if-typeof') !== null) {
|
|
28
|
-
state = this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
55
|
+
state = this.types.map(x => x.uri).includes(caseElement.getAttribute('if-typeof'));
|
|
56
|
+
}
|
|
57
|
+
if (caseElement.getAttribute('if-property') !== null) {
|
|
58
|
+
state = this.relations.map(x => x.predicate).includes(caseElement.getAttribute('if-property'));
|
|
59
|
+
}
|
|
60
|
+
if (caseElement.getAttribute('if-rev') !== null) {
|
|
61
|
+
state = this.reverseRelations.map(x => x.predicate).includes(caseElement.getAttribute('if-rev'));
|
|
32
62
|
}
|
|
33
63
|
if (caseElement.getAttribute('not') != null) {
|
|
34
64
|
state = !state;
|
|
@@ -58,13 +88,19 @@ export class PosSwitch {
|
|
|
58
88
|
const activeElementsContent = activeElements.map(el => el.querySelector('template').innerHTML).join('\n');
|
|
59
89
|
return h(Host, { innerHTML: activeElementsContent });
|
|
60
90
|
}
|
|
91
|
+
disconnectedCallback() {
|
|
92
|
+
this.disconnected$.next();
|
|
93
|
+
this.disconnected$.complete();
|
|
94
|
+
}
|
|
61
95
|
static get is() { return "pos-switch"; }
|
|
62
96
|
static get states() {
|
|
63
97
|
return {
|
|
64
98
|
"error": {},
|
|
65
99
|
"resource": {},
|
|
66
100
|
"caseElements": {},
|
|
67
|
-
"
|
|
101
|
+
"types": {},
|
|
102
|
+
"relations": {},
|
|
103
|
+
"reverseRelations": {}
|
|
68
104
|
};
|
|
69
105
|
}
|
|
70
106
|
static get events() {
|