@runopencode/rx-stencil 0.4.4 → 0.5.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/{index-CbERigo8.js → index-DWhjpI-K.js} +396 -41
- package/dist/{esm/set-property-CpZKE-Xu.js → cjs/index-Dssn3hdS.js} +2 -61
- package/dist/cjs/index.cjs.js +280 -244
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mutation-observable-qY7nC854.js +152 -0
- package/dist/cjs/properties-observable-DXbVBslA.js +23 -0
- package/dist/cjs/property-observable-CPp5WEjC.js +86 -0
- package/dist/cjs/rx-async.cjs.entry.js +21 -14
- package/dist/cjs/rx-stencil.cjs.js +3 -3
- package/dist/cjs/schedule-render-DG4hFv5E.js +53 -0
- package/dist/cjs/set-property-C3KARzdl.js +33 -0
- package/dist/cjs/stencil-uD4ZIy1h.js +75 -0
- package/dist/cjs/test-properties-observable.cjs.entry.js +27 -0
- package/dist/cjs/test-property-observable.cjs.entry.js +31 -0
- package/dist/cjs/test-schedule-render.cjs.entry.js +28 -0
- package/dist/cjs/test-view-child-observable-shadow-dom.cjs.entry.js +40 -0
- package/dist/cjs/until-disconnected-BTCr-3q2.js +27 -0
- package/dist/collection/collection-manifest.json +9 -2
- package/dist/collection/components/async/async.js +42 -10
- package/dist/collection/components/index.js +1 -1
- package/dist/collection/rx/decorator/content-child.js +34 -0
- package/dist/collection/rx/decorator/content-children.js +34 -0
- package/dist/collection/rx/decorator/index.js +6 -2
- package/dist/collection/rx/decorator/query-selector-all.js +6 -38
- package/dist/collection/rx/decorator/query-selector.js +6 -51
- package/dist/collection/rx/decorator/view-child.js +34 -0
- package/dist/collection/rx/decorator/view-children.js +34 -0
- package/dist/collection/rx/index.js +1 -0
- package/dist/collection/rx/observable/connected-observable.js +27 -0
- package/dist/collection/rx/observable/content-child-observable.js +24 -0
- package/dist/collection/rx/observable/content-children-observable.js +15 -0
- package/dist/collection/rx/observable/from-event.js +26 -0
- package/dist/collection/rx/observable/index.js +9 -4
- package/dist/collection/rx/observable/mutation-observable.js +6 -0
- package/dist/collection/rx/observable/properties-observable.js +5 -0
- package/dist/collection/rx/observable/property-observable.js +72 -17
- package/dist/collection/rx/observable/render-observable.js +18 -9
- package/dist/collection/rx/observable/view-child-observable.js +30 -0
- package/dist/collection/rx/observable/view-children-observable.js +21 -0
- package/dist/collection/rx/operator/index.js +4 -3
- package/dist/collection/rx/operator/to-property.js +7 -7
- package/dist/collection/rx/operator/until-disconnected.js +12 -94
- package/dist/collection/rx/operator/while-connected.js +39 -0
- package/dist/collection/rx/subscriber/index.js +1 -1
- package/dist/collection/rx/subscriber/set-property.js +13 -0
- package/dist/collection/rx/types.js +1 -0
- package/dist/collection/tests/rx/observable/from-event/test-from-event.component.js +30 -0
- package/dist/collection/tests/rx/observable/properties-observable/test-properties-observable.component.js +85 -0
- package/dist/collection/tests/rx/observable/property-observable/test-property-observable.component.js +47 -0
- package/dist/collection/tests/rx/observable/render-observable.unit.js +38 -0
- package/dist/collection/tests/rx/observable/view-child-observable/test-view-child-observable-shadow-dom.component.js +96 -0
- package/dist/collection/tests/rx/operator/schedule-render/test-schedule-render.component.js +42 -0
- package/dist/collection/tests/rx/operator/to-property.unit.js +28 -0
- package/dist/collection/tests/rx/operator/until-disconnected.unit.js +25 -0
- package/dist/collection/tests/rx/operator/while-connected/test-while-connected.component.js +32 -0
- package/dist/collection/tests/rx/subscriber/set-property.unit.js +53 -0
- package/dist/collection/utils/decorator.js +33 -0
- package/dist/collection/utils/index.js +1 -1
- package/dist/collection/utils/rxjs.js +67 -0
- package/dist/collection/utils/stencil.js +66 -0
- package/dist/collection/utils/values-registry.js +40 -0
- package/dist/components/index.js +1 -1
- package/dist/components/index2.js +1 -0
- package/dist/components/mutation-observable.js +1 -0
- package/dist/components/properties-observable.js +1 -0
- package/dist/components/property-observable.js +1 -0
- package/dist/components/rx-async.js +1 -1
- package/dist/components/schedule-render.js +1 -0
- package/dist/components/set-property.js +1 -1
- package/dist/components/stencil.js +1 -0
- package/dist/components/test-properties-observable.d.ts +11 -0
- package/dist/components/test-properties-observable.js +1 -0
- package/dist/components/test-property-observable.d.ts +11 -0
- package/dist/components/test-property-observable.js +1 -0
- package/dist/components/test-schedule-render.d.ts +11 -0
- package/dist/components/test-schedule-render.js +1 -0
- package/dist/components/test-view-child-observable-shadow-dom.d.ts +11 -0
- package/dist/components/test-view-child-observable-shadow-dom.js +1 -0
- package/dist/components/until-disconnected.js +1 -0
- package/dist/esm/{index-BIBww8qU.js → index-BCGlW-2C.js} +396 -42
- package/dist/{cjs/set-property-BZHuI0P5.js → esm/index-Bn8mRT4P.js} +1 -67
- package/dist/esm/index.js +266 -240
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mutation-observable-xA7xgk29.js +145 -0
- package/dist/esm/properties-observable-Bzq-rZ4c.js +21 -0
- package/dist/esm/property-observable-BKyQe0OR.js +84 -0
- package/dist/esm/rx-async.entry.js +18 -11
- package/dist/esm/rx-stencil.js +4 -4
- package/dist/esm/schedule-render-BGCI5FMG.js +50 -0
- package/dist/esm/set-property-CgrvJ28c.js +31 -0
- package/dist/esm/stencil-BQCAKjCT.js +68 -0
- package/dist/esm/test-properties-observable.entry.js +25 -0
- package/dist/esm/test-property-observable.entry.js +29 -0
- package/dist/esm/test-schedule-render.entry.js +26 -0
- package/dist/esm/test-view-child-observable-shadow-dom.entry.js +38 -0
- package/dist/esm/until-disconnected-D2pF81SM.js +25 -0
- package/dist/rx-stencil/index.esm.js +1 -1
- package/dist/rx-stencil/p-7c570c65.entry.js +1 -0
- package/dist/rx-stencil/p-BCGlW-2C.js +3 -0
- package/dist/rx-stencil/p-BLLg2g3n.js +1 -0
- package/dist/rx-stencil/p-BQCAKjCT.js +1 -0
- package/dist/rx-stencil/p-Bn8mRT4P.js +1 -0
- package/dist/rx-stencil/p-D1zETqVV.js +1 -0
- package/dist/rx-stencil/p-DHIVm3-O.js +1 -0
- package/dist/rx-stencil/p-J0xLdrjW.js +1 -0
- package/dist/rx-stencil/p-Sf5sf4Pq.js +1 -0
- package/dist/rx-stencil/p-a4c71f45.entry.js +1 -0
- package/dist/rx-stencil/p-b2c6ba01.entry.js +1 -0
- package/dist/rx-stencil/p-dc654207.entry.js +1 -0
- package/dist/rx-stencil/p-e661490a.entry.js +1 -0
- package/dist/rx-stencil/p-wVeMJABH.js +1 -0
- package/dist/rx-stencil/rx-stencil.esm.js +1 -1
- package/dist/types/components/async/async.d.ts +9 -2
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/components.d.ts +92 -2
- package/dist/types/rx/decorator/content-child.d.ts +3 -0
- package/dist/types/rx/decorator/content-children.d.ts +3 -0
- package/dist/types/rx/decorator/index.d.ts +6 -2
- package/dist/types/rx/decorator/query-selector-all.d.ts +7 -21
- package/dist/types/rx/decorator/query-selector.d.ts +7 -29
- package/dist/types/rx/decorator/view-child.d.ts +27 -0
- package/dist/types/rx/decorator/view-children.d.ts +11 -0
- package/dist/types/rx/index.d.ts +1 -0
- package/dist/types/rx/observable/connected-observable.d.ts +9 -0
- package/dist/types/rx/observable/content-child-observable.d.ts +5 -0
- package/dist/types/rx/observable/content-children-observable.d.ts +5 -0
- package/dist/types/rx/observable/from-event.d.ts +26 -0
- package/dist/types/rx/observable/index.d.ts +9 -4
- package/dist/types/rx/observable/mutation-observable.d.ts +6 -0
- package/dist/types/rx/observable/properties-observable.d.ts +5 -0
- package/dist/types/rx/observable/property-observable.d.ts +1 -1
- package/dist/types/rx/observable/render-observable.d.ts +6 -1
- package/dist/types/rx/observable/view-child-observable.d.ts +17 -0
- package/dist/types/rx/observable/view-children-observable.d.ts +5 -0
- package/dist/types/rx/operator/index.d.ts +4 -3
- package/dist/types/rx/operator/to-property.d.ts +1 -3
- package/dist/types/rx/operator/while-connected.d.ts +22 -0
- package/dist/types/rx/subscriber/index.d.ts +1 -1
- package/dist/types/rx/subscriber/set-property.d.ts +13 -0
- package/dist/types/rx/types.d.ts +12 -0
- package/dist/types/stencil-public-runtime.d.ts +74 -55
- package/dist/types/tests/rx/observable/properties-observable/test-properties-observable.component.d.ts +9 -0
- package/dist/types/tests/rx/observable/property-observable/test-property-observable.component.d.ts +8 -0
- package/dist/types/tests/rx/observable/render-observable.unit.d.ts +1 -0
- package/dist/types/tests/rx/observable/view-child-observable/test-view-child-observable-shadow-dom.component.d.ts +12 -0
- package/dist/types/tests/rx/operator/schedule-render/test-schedule-render.component.d.ts +7 -0
- package/dist/types/tests/rx/operator/to-property.unit.d.ts +1 -0
- package/dist/types/tests/rx/operator/until-disconnected.unit.d.ts +1 -0
- package/dist/types/tests/rx/subscriber/set-property.unit.d.ts +1 -0
- package/dist/types/utils/decorator.d.ts +11 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/rxjs.d.ts +31 -0
- package/dist/types/utils/stencil.d.ts +54 -0
- package/dist/types/utils/values-registry.d.ts +10 -0
- package/loader/index.d.ts +1 -1
- package/package.json +19 -10
- package/dist/collection/utils/get-property-descriptor.js +0 -17
- package/dist/rx-stencil/p-77100dee.entry.js +0 -1
- package/dist/rx-stencil/p-BIBww8qU.js +0 -2
- package/dist/rx-stencil/p-IbpJ_cRo.js +0 -1
- package/dist/types/utils/get-property-descriptor.d.ts +0 -7
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-DWhjpI-K.js');
|
|
4
|
+
var index$1 = require('./index-Dssn3hdS.js');
|
|
5
|
+
|
|
6
|
+
let observables = new WeakMap();
|
|
7
|
+
/**
|
|
8
|
+
* Operator that unsubscribes from the source observable when
|
|
9
|
+
* the component is disconnected from DOM.
|
|
10
|
+
*/
|
|
11
|
+
function untilDisconnected(cmp) {
|
|
12
|
+
return (source) => {
|
|
13
|
+
let element = index.getElement(cmp);
|
|
14
|
+
if (!observables.has(element)) {
|
|
15
|
+
let observable = new index$1.cjsExports.Subject();
|
|
16
|
+
let previous = cmp.disconnectedCallback;
|
|
17
|
+
cmp.disconnectedCallback = function () {
|
|
18
|
+
previous === null || previous === void 0 ? void 0 : previous.call(this);
|
|
19
|
+
observable.next();
|
|
20
|
+
};
|
|
21
|
+
observables.set(element, observable.asObservable());
|
|
22
|
+
}
|
|
23
|
+
return source.pipe(index$1.cjsExports.takeUntil(observables.get(element)));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.untilDisconnected = untilDisconnected;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"entries": [
|
|
3
|
-
"components/async/async.js"
|
|
3
|
+
"components/async/async.js",
|
|
4
|
+
"tests/rx/observable/from-event/test-from-event.component.js",
|
|
5
|
+
"tests/rx/observable/properties-observable/test-properties-observable.component.js",
|
|
6
|
+
"tests/rx/observable/property-observable/test-property-observable.component.js",
|
|
7
|
+
"tests/rx/observable/view-child-observable/test-view-child-observable-shadow-dom.component.js",
|
|
8
|
+
"tests/rx/operator/schedule-render/test-schedule-render.component.js",
|
|
9
|
+
"tests/rx/operator/while-connected/test-while-connected.component.js"
|
|
4
10
|
],
|
|
11
|
+
"mixins": [],
|
|
5
12
|
"compiler": {
|
|
6
13
|
"name": "@stencil/core",
|
|
7
|
-
"version": "4.
|
|
14
|
+
"version": "4.45.0",
|
|
8
15
|
"typescriptVersion": "5.8.3"
|
|
9
16
|
},
|
|
10
17
|
"collections": [],
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { h, Host, } from "@stencil/core";
|
|
2
2
|
import { from, isObservable, of, switchMap, } from "rxjs";
|
|
3
|
-
import { propertyObservable, setProperty, } from "../../rx";
|
|
3
|
+
import { propertyObservable, setProperty, untilDisconnected, } from "../../rx";
|
|
4
4
|
export class Async {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.value = null;
|
|
7
|
+
this.transform = (value) => value;
|
|
7
8
|
this._value = null;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* {@inheritdoc}
|
|
12
|
+
*/
|
|
9
13
|
connectedCallback() {
|
|
10
|
-
propertyObservable(this, 'value')
|
|
14
|
+
propertyObservable(this, 'value')
|
|
15
|
+
.pipe(switchMap((value) => {
|
|
11
16
|
if (isObservable(value)) {
|
|
12
17
|
return value;
|
|
13
18
|
}
|
|
@@ -15,16 +20,14 @@ export class Async {
|
|
|
15
20
|
return from(value);
|
|
16
21
|
}
|
|
17
22
|
return of(value);
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
nextTick: false,
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
disconnectedCallback() {
|
|
24
|
-
// noop
|
|
23
|
+
}), untilDisconnected(this))
|
|
24
|
+
.subscribe(setProperty(this, '_value'));
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* {@inheritdoc}
|
|
28
|
+
*/
|
|
26
29
|
render() {
|
|
27
|
-
return (h(Host, { key: '
|
|
30
|
+
return (h(Host, { key: 'f59ccdf7defbbb0d9d3b87bc20e3edaae9a2513b' }, this.transform(this._value)));
|
|
28
31
|
}
|
|
29
32
|
static get is() { return "rx-async"; }
|
|
30
33
|
static get originalStyleUrls() {
|
|
@@ -62,7 +65,36 @@ export class Async {
|
|
|
62
65
|
"getter": false,
|
|
63
66
|
"setter": false,
|
|
64
67
|
"defaultValue": "null"
|
|
68
|
+
},
|
|
69
|
+
"transform": {
|
|
70
|
+
"type": "unknown",
|
|
71
|
+
"mutable": false,
|
|
72
|
+
"complexType": {
|
|
73
|
+
"original": "ValueTransformFn",
|
|
74
|
+
"resolved": "unknown",
|
|
75
|
+
"references": {
|
|
76
|
+
"ValueTransformFn": {
|
|
77
|
+
"location": "local",
|
|
78
|
+
"path": "/Users/thecelavi/Sites/RunOpenCode/stencil-libs/rx-stencil/src/components/async/async.tsx",
|
|
79
|
+
"id": "src/components/async/async.tsx::ValueTransformFn"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"required": false,
|
|
84
|
+
"optional": false,
|
|
85
|
+
"docs": {
|
|
86
|
+
"tags": [],
|
|
87
|
+
"text": ""
|
|
88
|
+
},
|
|
89
|
+
"getter": false,
|
|
90
|
+
"setter": false,
|
|
91
|
+
"defaultValue": "(value: unknown | null | undefined): any => value"
|
|
65
92
|
}
|
|
66
93
|
};
|
|
67
94
|
}
|
|
95
|
+
static get states() {
|
|
96
|
+
return {
|
|
97
|
+
"_value": {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
68
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './async/async';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Build, getElement, } from "@stencil/core";
|
|
2
|
+
import { applyOperators } from "../../utils/decorator";
|
|
3
|
+
import { getRegistry, } from "../../utils/values-registry";
|
|
4
|
+
import { contentChildObservable } from "../observable/content-child-observable";
|
|
5
|
+
export function ContentChild(selector, options) {
|
|
6
|
+
return function (cmp, property) {
|
|
7
|
+
let connectedCallback = cmp.connectedCallback;
|
|
8
|
+
cmp.connectedCallback = function () {
|
|
9
|
+
this[property]; // Access the property to initialize it and set up the observable.
|
|
10
|
+
connectedCallback === null || connectedCallback === void 0 ? void 0 : connectedCallback.call(this);
|
|
11
|
+
};
|
|
12
|
+
let descriptor = Object.getOwnPropertyDescriptor(cmp.prototype, property) || {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
};
|
|
16
|
+
delete descriptor['value'];
|
|
17
|
+
delete descriptor['writable'];
|
|
18
|
+
Object.defineProperty(cmp, property, Object.assign(Object.assign({}, descriptor), { set(_value) {
|
|
19
|
+
if (Build.isDev) {
|
|
20
|
+
console.warn(`@ContentChild property "${property}" is read-only and cannot be set.`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
let element = getElement(this);
|
|
25
|
+
let registry = getRegistry('@ContentChild');
|
|
26
|
+
if (!registry.has(element, property)) {
|
|
27
|
+
let observable = contentChildObservable(this, selector, options);
|
|
28
|
+
observable = applyOperators(observable, this, options);
|
|
29
|
+
registry.set(element, property, observable);
|
|
30
|
+
}
|
|
31
|
+
return registry.value(element, property);
|
|
32
|
+
} }));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Build, getElement, } from "@stencil/core";
|
|
2
|
+
import { applyOperators } from "../../utils/decorator";
|
|
3
|
+
import { getRegistry, } from "../../utils/values-registry";
|
|
4
|
+
import { contentChildrenObservable } from "../observable/content-children-observable";
|
|
5
|
+
export function ContentChildren(selector, options) {
|
|
6
|
+
return function (cmp, property) {
|
|
7
|
+
let connectedCallback = cmp.connectedCallback;
|
|
8
|
+
cmp.connectedCallback = function () {
|
|
9
|
+
this[property]; // Access the property to initialize it and set up the observable.
|
|
10
|
+
connectedCallback === null || connectedCallback === void 0 ? void 0 : connectedCallback.call(this);
|
|
11
|
+
};
|
|
12
|
+
let descriptor = Object.getOwnPropertyDescriptor(cmp.prototype, property) || {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
};
|
|
16
|
+
delete descriptor['value'];
|
|
17
|
+
delete descriptor['writable'];
|
|
18
|
+
Object.defineProperty(cmp, property, Object.assign(Object.assign({}, descriptor), { set(_value) {
|
|
19
|
+
if (Build.isDev) {
|
|
20
|
+
console.warn(`@ContentChildren property "${property}" is read-only and cannot be set.`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
let element = getElement(cmp);
|
|
25
|
+
let registry = getRegistry('@ContentChildren');
|
|
26
|
+
if (!registry.has(element, property)) {
|
|
27
|
+
let observable = contentChildrenObservable(this, selector, options);
|
|
28
|
+
observable = applyOperators(observable, this, options);
|
|
29
|
+
registry.set(element, property, observable);
|
|
30
|
+
}
|
|
31
|
+
return registry.value(element, property);
|
|
32
|
+
} }));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './content-child';
|
|
2
|
+
export * from './content-children';
|
|
3
|
+
export * from './query-selector';
|
|
4
|
+
export * from './query-selector-all';
|
|
5
|
+
export * from './view-child';
|
|
6
|
+
export * from './view-children';
|
|
@@ -1,40 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { renderObservable } from "../observable";
|
|
4
|
-
import { observeSubNodes } from "./query-selector";
|
|
5
|
-
/**
|
|
6
|
-
* Property decorator inspired by Angular's @ViewChild/@ContentChild.
|
|
7
|
-
*
|
|
8
|
-
* After each render, the decorated property will be set to the first element
|
|
9
|
-
* matching the given selector. If no element is found, the property will be
|
|
10
|
-
* set to null.
|
|
11
|
-
*/
|
|
1
|
+
import { ContentChildren, } from "./content-children";
|
|
2
|
+
import { ViewChildren, } from "./view-children";
|
|
12
3
|
export function QuerySelectorAll(selector, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
get: function () {
|
|
19
|
-
let observableProperty = `__rx__query_selector_all__observable__shadow_root__${(options === null || options === void 0 ? void 0 : options.shadowRoot) ? 'yes' : 'no'}__mutation_observer__${(options === null || options === void 0 ? void 0 : options.mutationObserver) ? 'yes' : 'no'}__selector__${selector}__`;
|
|
20
|
-
if (!this[observableProperty]) {
|
|
21
|
-
let root = (options === null || options === void 0 ? void 0 : options.shadowRoot) ? getElement(this).shadowRoot : getElement(this);
|
|
22
|
-
let observable = (options === null || options === void 0 ? void 0 : options.mutationObserver) ? observeSubNodes(root) : renderObservable(this);
|
|
23
|
-
this[observableProperty] = observable.pipe(startWith(), map(() => Array.from(root.querySelectorAll(selector))), distinctUntilChanged((previous, current) => {
|
|
24
|
-
if (previous.length !== current.length) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
for (let i = 0; i < previous.length; i++) {
|
|
28
|
-
if (previous[i] !== current[i]) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}), shareReplay(1));
|
|
34
|
-
}
|
|
35
|
-
return this[observableProperty];
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(target, property, descriptor);
|
|
39
|
-
};
|
|
4
|
+
if ('content' === (options === null || options === void 0 ? void 0 : options.target)) {
|
|
5
|
+
return ContentChildren(selector, options);
|
|
6
|
+
}
|
|
7
|
+
return ViewChildren(selector, options);
|
|
40
8
|
}
|
|
@@ -1,53 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { mutationObservable, renderObservable, } from "../observable";
|
|
4
|
-
/**
|
|
5
|
-
* Observe all sub nodes of the given node and notify
|
|
6
|
-
* when any of them is removed and/or added.
|
|
7
|
-
*
|
|
8
|
-
* {@internal}
|
|
9
|
-
*/
|
|
10
|
-
export function observeSubNodes(target) {
|
|
11
|
-
return mutationObservable(target, {
|
|
12
|
-
subtree: true,
|
|
13
|
-
childList: true,
|
|
14
|
-
}).pipe(filter((records) => {
|
|
15
|
-
for (let i = 0; i < records.length; i++) {
|
|
16
|
-
if ('childList' !== records[i].type) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (records[i].addedNodes.length || records[i].removedNodes.length) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}), map(() => {
|
|
25
|
-
/* noop */
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Property decorator inspired by Angular's @ViewChild/@ContentChild.
|
|
30
|
-
*
|
|
31
|
-
* After each render, the decorated property will be set to the first element
|
|
32
|
-
* matching the given selector. If no element is found, the property will be
|
|
33
|
-
* set to null.
|
|
34
|
-
*/
|
|
1
|
+
import { ContentChild, } from "./content-child";
|
|
2
|
+
import { ViewChild, } from "./view-child";
|
|
35
3
|
export function QuerySelector(selector, options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
get: function () {
|
|
42
|
-
let observableProperty = `__rx__query_selector__observable__shadow_root__${(options === null || options === void 0 ? void 0 : options.shadowRoot) ? 'yes' : 'no'}__mutation_observer__${(options === null || options === void 0 ? void 0 : options.mutationObserver) ? 'yes' : 'no'}__selector__${selector}__`;
|
|
43
|
-
if (!this[observableProperty]) {
|
|
44
|
-
let root = (options === null || options === void 0 ? void 0 : options.shadowRoot) ? getElement(this).shadowRoot : getElement(this);
|
|
45
|
-
let observable = (options === null || options === void 0 ? void 0 : options.mutationObserver) ? observeSubNodes(root) : renderObservable(this);
|
|
46
|
-
this[observableProperty] = observable.pipe(startWith(), map(() => root.querySelector(selector)), distinctUntilChanged(), shareReplay(1));
|
|
47
|
-
}
|
|
48
|
-
return this[observableProperty];
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
Object.defineProperty(target, property, descriptor);
|
|
52
|
-
};
|
|
4
|
+
if ('content' === (options === null || options === void 0 ? void 0 : options.target)) {
|
|
5
|
+
return ContentChild(selector, options);
|
|
6
|
+
}
|
|
7
|
+
return ViewChild(selector, options);
|
|
53
8
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Build, getElement, } from "@stencil/core";
|
|
2
|
+
import { applyOperators } from "../../utils/decorator";
|
|
3
|
+
import { getRegistry, } from "../../utils/values-registry";
|
|
4
|
+
import { viewChildObservable, } from "../observable/view-child-observable";
|
|
5
|
+
export function ViewChild(selector, options) {
|
|
6
|
+
return function (cmp, property) {
|
|
7
|
+
let connectedCallback = cmp.connectedCallback;
|
|
8
|
+
cmp.connectedCallback = function () {
|
|
9
|
+
this[property]; // Access the property to initialize it and set up the observable.
|
|
10
|
+
connectedCallback === null || connectedCallback === void 0 ? void 0 : connectedCallback.call(this);
|
|
11
|
+
};
|
|
12
|
+
let descriptor = Object.getOwnPropertyDescriptor(cmp.prototype, property) || {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
};
|
|
16
|
+
delete descriptor['value'];
|
|
17
|
+
delete descriptor['writable'];
|
|
18
|
+
Object.defineProperty(cmp, property, Object.assign(Object.assign({}, descriptor), { set(_value) {
|
|
19
|
+
if (Build.isDev) {
|
|
20
|
+
console.warn(`@ViewChild property "${property}" is read-only and cannot be set.`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
let element = getElement(this);
|
|
25
|
+
let registry = getRegistry('@ViewChild');
|
|
26
|
+
if (!registry.has(element, property)) {
|
|
27
|
+
let observable = viewChildObservable(this, selector, options);
|
|
28
|
+
observable = applyOperators(observable, this, options);
|
|
29
|
+
registry.set(element, property, observable);
|
|
30
|
+
}
|
|
31
|
+
return registry.value(element, property);
|
|
32
|
+
} }));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Build, getElement, } from "@stencil/core";
|
|
2
|
+
import { applyOperators } from "../../utils/decorator";
|
|
3
|
+
import { getRegistry, } from "../../utils/values-registry";
|
|
4
|
+
import { viewChildrenObservable } from "../observable/view-children-observable";
|
|
5
|
+
export function ViewChildren(selector, options) {
|
|
6
|
+
return function (cmp, property) {
|
|
7
|
+
let connectedCallback = cmp.connectedCallback;
|
|
8
|
+
cmp.connectedCallback = function () {
|
|
9
|
+
this[property]; // Access the property to initialize it and set up the observable.
|
|
10
|
+
connectedCallback === null || connectedCallback === void 0 ? void 0 : connectedCallback.call(this);
|
|
11
|
+
};
|
|
12
|
+
let descriptor = Object.getOwnPropertyDescriptor(cmp.prototype, property) || {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
};
|
|
16
|
+
delete descriptor['value'];
|
|
17
|
+
delete descriptor['writable'];
|
|
18
|
+
Object.defineProperty(cmp, property, Object.assign(Object.assign({}, descriptor), { set(_value) {
|
|
19
|
+
if (Build.isDev) {
|
|
20
|
+
console.warn(`@ViewChildren property "${property}" is read-only and cannot be set.`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
let element = getElement(cmp);
|
|
25
|
+
let registry = getRegistry('@ViewChildren');
|
|
26
|
+
if (!registry.has(element, property)) {
|
|
27
|
+
let observable = viewChildrenObservable(this, selector, options);
|
|
28
|
+
observable = applyOperators(observable, this, options);
|
|
29
|
+
registry.set(element, property, observable);
|
|
30
|
+
}
|
|
31
|
+
return registry.value(element, property);
|
|
32
|
+
} }));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getElement, } from "@stencil/core";
|
|
2
|
+
import { BehaviorSubject, } from "rxjs";
|
|
3
|
+
let observables = new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Returns an observable that emits `true` when the component is connected to DOM,
|
|
6
|
+
* and `false` when it is disconnected from DOM.
|
|
7
|
+
*
|
|
8
|
+
* Uses hot observable pattern.
|
|
9
|
+
*/
|
|
10
|
+
export function connectedObservable(cmp) {
|
|
11
|
+
let element = getElement(cmp);
|
|
12
|
+
if (!observables.has(element)) {
|
|
13
|
+
let previousConnected = cmp.connectedCallback;
|
|
14
|
+
let previousDisconnected = cmp.disconnectedCallback;
|
|
15
|
+
let observable = new BehaviorSubject(element.isConnected);
|
|
16
|
+
cmp.connectedCallback = function () {
|
|
17
|
+
previousConnected === null || previousConnected === void 0 ? void 0 : previousConnected.call(this);
|
|
18
|
+
observable.next(true);
|
|
19
|
+
};
|
|
20
|
+
cmp.disconnectedCallback = function () {
|
|
21
|
+
previousDisconnected === null || previousDisconnected === void 0 ? void 0 : previousDisconnected.call(this);
|
|
22
|
+
observable.next(false);
|
|
23
|
+
};
|
|
24
|
+
observables.set(element, observable.asObservable());
|
|
25
|
+
}
|
|
26
|
+
return observables.get(element);
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getElement, } from "@stencil/core";
|
|
2
|
+
import { map, startWith, } from "rxjs";
|
|
3
|
+
import { isEmulatedViewChild, usesShadowDom, } from "../../utils/stencil";
|
|
4
|
+
import { distinctUntilElementChanged, observeSubtree, } from "../../utils/rxjs";
|
|
5
|
+
export function contentChildObservable(cmp, selector, options) {
|
|
6
|
+
let element = getElement(cmp);
|
|
7
|
+
let mutations = observeSubtree(element).pipe(map(() => void 0), startWith(void 0));
|
|
8
|
+
options = Object.assign({ distinct: true }, options);
|
|
9
|
+
// In shadow DOM, we can just listen for the mutations and query the element directly.
|
|
10
|
+
if (usesShadowDom(cmp)) {
|
|
11
|
+
return mutations.pipe(map(() => element.querySelector(selector)), distinctUntilElementChanged(options.distinct));
|
|
12
|
+
}
|
|
13
|
+
// When shadow DOM is emulated, we need to filter out elements that are part of the emulated view child.
|
|
14
|
+
return mutations.pipe(map(() => {
|
|
15
|
+
let candidates = Array.from(element.querySelectorAll(selector));
|
|
16
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
17
|
+
let candidate = candidates[i];
|
|
18
|
+
if (!isEmulatedViewChild(candidate, element)) {
|
|
19
|
+
return candidate;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}), distinctUntilElementChanged(options.distinct));
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getElement, } from "@stencil/core";
|
|
2
|
+
import { map, startWith, } from "rxjs";
|
|
3
|
+
import { isEmulatedViewChild, usesShadowDom, } from "../../utils/stencil";
|
|
4
|
+
import { distinctUntilElementsChanged, observeSubtree, } from "../../utils/rxjs";
|
|
5
|
+
export function contentChildrenObservable(cmp, selector, options) {
|
|
6
|
+
let element = getElement(cmp);
|
|
7
|
+
let mutations = observeSubtree(element).pipe(map(() => void 0), startWith(void 0));
|
|
8
|
+
options = Object.assign({ distinct: true }, options);
|
|
9
|
+
// In shadow DOM, we can just listen for the mutations and query the element directly.
|
|
10
|
+
if (usesShadowDom(cmp)) {
|
|
11
|
+
return mutations.pipe(map(() => Array.from(element.querySelectorAll(selector))), distinctUntilElementsChanged(options.distinct));
|
|
12
|
+
}
|
|
13
|
+
// When shadow DOM is emulated, we need to filter out elements that are part of the emulated view child.
|
|
14
|
+
return mutations.pipe(map(() => Array.from(element.querySelectorAll(selector)).filter((candidate) => !isEmulatedViewChild(candidate, element))), distinctUntilElementsChanged(options.distinct));
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getElement, } from "@stencil/core";
|
|
2
|
+
import { Observable, } from "rxjs";
|
|
3
|
+
export function fromEvent(cmp, eventName, delegateOrOptions, options) {
|
|
4
|
+
let element = getElement(cmp);
|
|
5
|
+
let delegate = 'string' === typeof delegateOrOptions ? delegateOrOptions : undefined;
|
|
6
|
+
let configuration = 'object' === typeof delegateOrOptions ? delegateOrOptions : options;
|
|
7
|
+
return new Observable((subscriber) => {
|
|
8
|
+
let handler = (event) => {
|
|
9
|
+
if (!delegate) {
|
|
10
|
+
subscriber.next(event);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!(event.target instanceof Element)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!event.target.closest(delegate)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
subscriber.next(event);
|
|
20
|
+
};
|
|
21
|
+
element.addEventListener(eventName, handler, configuration);
|
|
22
|
+
return () => {
|
|
23
|
+
element.removeEventListener(eventName, handler, configuration);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from './content-child-observable';
|
|
2
|
+
export * from './content-children-observable';
|
|
3
|
+
export * from './from-event';
|
|
4
|
+
export * from './mutation-observable';
|
|
5
|
+
export * from './properties-observable';
|
|
6
|
+
export * from './property-observable';
|
|
7
|
+
export * from './render-observable';
|
|
8
|
+
export * from './view-child-observable';
|
|
9
|
+
export * from './view-children-observable';
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Observable, } from "rxjs";
|
|
2
|
+
/**
|
|
3
|
+
* Create mutation observer and return observable that emits mutation records when the target node is mutated.
|
|
4
|
+
*
|
|
5
|
+
* @param {Node} target The target node to observe for mutations.
|
|
6
|
+
* @param {MutationObserverInit} options The options for the mutation observer.
|
|
7
|
+
*/
|
|
2
8
|
export function mutationObservable(target, options) {
|
|
3
9
|
return new Observable((observer) => {
|
|
4
10
|
let mutation = new MutationObserver((mutations) => {
|
|
@@ -2,6 +2,11 @@ import { combineLatest, } from "rxjs";
|
|
|
2
2
|
import { propertyObservable } from "./property-observable";
|
|
3
3
|
/**
|
|
4
4
|
* Returns an observable that emits an array of values from the given properties.
|
|
5
|
+
*
|
|
6
|
+
* It always emits an array of values, even if only one property is specified. The order
|
|
7
|
+
* of the values in the emitted array corresponds to the order of the properties specified.
|
|
8
|
+
*
|
|
9
|
+
* Do note that `combineLatest()` operator is used to combine the observables.
|
|
5
10
|
*/
|
|
6
11
|
export function propertiesObservable(cmp, ...properties) {
|
|
7
12
|
if (0 === properties.length) {
|
|
@@ -1,27 +1,82 @@
|
|
|
1
|
+
import { getElement, } from "@stencil/core";
|
|
2
|
+
import { BUILD } from "@stencil/core/internal/app-data";
|
|
1
3
|
import { BehaviorSubject, distinctUntilChanged, } from "rxjs";
|
|
2
|
-
import {
|
|
4
|
+
import { getHostRef, isPropOrState, } from "../../utils";
|
|
5
|
+
/**
|
|
6
|
+
* A WeakMap to store BehaviorSubjects for each component property.
|
|
7
|
+
*
|
|
8
|
+
* The key is the HTMLElement (component instance), and the value is a record of property names to BehaviorSubjects.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
let subjects = new WeakMap();
|
|
13
|
+
/**
|
|
14
|
+
* The name of the watcher callback function that will be registered on the component instance.
|
|
15
|
+
*/
|
|
16
|
+
const WATCHER_CALLBACK_NAME = '__runopencode_rx_stencil_watcher';
|
|
3
17
|
/**
|
|
4
18
|
* Returns an observable that emits property value when the component property value changes.
|
|
5
19
|
*/
|
|
6
20
|
export function propertyObservable(cmp, property) {
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
let element = getElement(cmp);
|
|
22
|
+
let initialize = false;
|
|
23
|
+
if (!subjects.has(element)) {
|
|
24
|
+
subjects.set(element, {});
|
|
25
|
+
}
|
|
26
|
+
if (!subjects.get(element)[property]) {
|
|
27
|
+
subjects.get(element)[property] = new BehaviorSubject(cmp[property]);
|
|
28
|
+
initialize = true;
|
|
29
|
+
}
|
|
30
|
+
if (!initialize) {
|
|
31
|
+
return subjects.get(element)[property]
|
|
32
|
+
.asObservable()
|
|
33
|
+
.pipe(distinctUntilChanged());
|
|
34
|
+
}
|
|
35
|
+
let subject = subjects.get(element)[property];
|
|
36
|
+
let isMember = isPropOrState(cmp, property);
|
|
37
|
+
// If the property is not a member of the component (not decorated with @Prop or @State),
|
|
38
|
+
// we can watch it by modifying the property descriptor directly.
|
|
39
|
+
if (!isMember) {
|
|
40
|
+
let descriptor = Object.getOwnPropertyDescriptor(cmp, property);
|
|
41
|
+
Object.defineProperty(cmp, property, {
|
|
42
|
+
get() {
|
|
43
|
+
return subject.value;
|
|
44
|
+
},
|
|
45
|
+
set(value) {
|
|
46
|
+
subject.next(value);
|
|
47
|
+
if (descriptor && descriptor.set) {
|
|
48
|
+
descriptor.set.call(this, value);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
configurable: true,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
});
|
|
54
|
+
return subject
|
|
55
|
+
.asObservable()
|
|
56
|
+
.pipe(distinctUntilChanged());
|
|
57
|
+
}
|
|
58
|
+
let hostRef = getHostRef(cmp);
|
|
59
|
+
// If callback function is not registered on the component, we need to register it and ensure that some of the
|
|
60
|
+
// stencil internal flags are set to ensure that the callback will be called when the property changes.
|
|
61
|
+
if (!cmp[WATCHER_CALLBACK_NAME]) {
|
|
62
|
+
// This flag ensures that Stencil will call the prop change callback when the property changes.
|
|
63
|
+
BUILD.propChangeCallback = true;
|
|
64
|
+
// $flags$ needs to include 128 (0x80) to indicate that the component has watchers.
|
|
65
|
+
hostRef.$flags$ |= 128;
|
|
66
|
+
// $watchers$ object needs to exist so we can add them for property.
|
|
67
|
+
hostRef.$cmpMeta$.$watchers$ = hostRef.$cmpMeta$.$watchers$ || {};
|
|
68
|
+
// Finally, we need to register the watcher callback function on the component instance.
|
|
69
|
+
cmp[WATCHER_CALLBACK_NAME] = function (current, _previous, property) {
|
|
70
|
+
let element = getElement(this);
|
|
71
|
+
let subject = subjects.get(element)[property];
|
|
72
|
+
subject.next(current);
|
|
20
73
|
};
|
|
21
|
-
Object.defineProperty(cmp, property, descriptor);
|
|
22
|
-
cmp[subjectProperty] = subject;
|
|
23
74
|
}
|
|
24
|
-
|
|
75
|
+
hostRef.$cmpMeta$.$watchers$[property] = hostRef.$cmpMeta$.$watchers$[property] || [];
|
|
76
|
+
hostRef.$cmpMeta$.$watchers$[property].push({
|
|
77
|
+
[WATCHER_CALLBACK_NAME]: 0,
|
|
78
|
+
});
|
|
79
|
+
return subject
|
|
25
80
|
.asObservable()
|
|
26
81
|
.pipe(distinctUntilChanged());
|
|
27
82
|
}
|