@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,28 @@
|
|
|
1
|
+
import { describe, it, expect, } from "@stencil/vitest";
|
|
2
|
+
import { Subject } from "rxjs";
|
|
3
|
+
import { toProperty } from "../../../rx";
|
|
4
|
+
describe('toProperty()', () => {
|
|
5
|
+
it('Streams value into property.', async () => {
|
|
6
|
+
let cmp = new ComponentMockWithProperty();
|
|
7
|
+
let subject = new Subject();
|
|
8
|
+
subject.pipe(toProperty(cmp, 'foo')).subscribe();
|
|
9
|
+
expect(cmp.foo).toBe('');
|
|
10
|
+
subject.next('bar');
|
|
11
|
+
expect(cmp.foo).toBe('bar');
|
|
12
|
+
});
|
|
13
|
+
it('Streams value into property which is not defined.', () => {
|
|
14
|
+
let cmp = new ComponentMockWithoutProperty();
|
|
15
|
+
let subject = new Subject();
|
|
16
|
+
subject.pipe(toProperty(cmp, 'foo')).subscribe();
|
|
17
|
+
expect(cmp.foo).toBe(undefined);
|
|
18
|
+
subject.next('bar');
|
|
19
|
+
expect(cmp.foo).toBe('bar');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
class ComponentMockWithoutProperty {
|
|
23
|
+
}
|
|
24
|
+
class ComponentMockWithProperty {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.foo = '';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect, } from "@stencil/vitest";
|
|
2
|
+
import { Subject } from "rxjs";
|
|
3
|
+
import { untilDisconnected } from "../../../rx";
|
|
4
|
+
describe('untilDisconnected()', () => {
|
|
5
|
+
it('Emits until disconnected.', async () => {
|
|
6
|
+
let cmp = new ComponentMock();
|
|
7
|
+
let observable = new Subject();
|
|
8
|
+
let values = [];
|
|
9
|
+
observable
|
|
10
|
+
.pipe(untilDisconnected(cmp))
|
|
11
|
+
.subscribe((value) => {
|
|
12
|
+
values.push(value);
|
|
13
|
+
});
|
|
14
|
+
observable.next(1);
|
|
15
|
+
observable.next(2);
|
|
16
|
+
cmp.disconnectedCallback();
|
|
17
|
+
observable.next(3);
|
|
18
|
+
expect(values).toStrictEqual([1, 2]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
class ComponentMock {
|
|
22
|
+
disconnectedCallback() {
|
|
23
|
+
// noop.
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Host, h, } from "@stencil/core";
|
|
2
|
+
import { fromEvent, whileConnected, } from "../../../../rx";
|
|
3
|
+
export class TestWhileConnectedComponent {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._raw = 0;
|
|
6
|
+
this._reemitted = 0;
|
|
7
|
+
}
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
fromEvent(this, 'click')
|
|
10
|
+
.pipe(whileConnected(this))
|
|
11
|
+
.subscribe(() => {
|
|
12
|
+
this._raw++;
|
|
13
|
+
});
|
|
14
|
+
fromEvent(this, 'click')
|
|
15
|
+
.pipe(whileConnected(this, {
|
|
16
|
+
reemit: true,
|
|
17
|
+
}))
|
|
18
|
+
.subscribe(() => {
|
|
19
|
+
this._reemitted++;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
return (h(Host, { key: '200210990aa48a6d459121125f66cefb39984a6d' }, this._raw, "/", this._reemitted));
|
|
24
|
+
}
|
|
25
|
+
static get is() { return "test-while-connected"; }
|
|
26
|
+
static get states() {
|
|
27
|
+
return {
|
|
28
|
+
"_raw": {},
|
|
29
|
+
"_reemitted": {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expect } from "@stencil/vitest";
|
|
2
|
+
import { Subject } from "rxjs";
|
|
3
|
+
import { describe, vi, it, beforeEach, } from "vitest";
|
|
4
|
+
import { setProperty } from "../../../rx";
|
|
5
|
+
vi.mock('@stencil/core', () => ({
|
|
6
|
+
forceUpdate: vi.fn(() => void 0),
|
|
7
|
+
}));
|
|
8
|
+
import { forceUpdate } from "@stencil/core";
|
|
9
|
+
describe('setProperty().', () => {
|
|
10
|
+
let observable;
|
|
11
|
+
let cmp;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
observable = new Subject();
|
|
14
|
+
cmp = new ComponentMock();
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
it('Sets property without triggering render.', async () => {
|
|
18
|
+
observable.subscribe(setProperty(cmp, 'foo'));
|
|
19
|
+
expect(cmp.foo).toBeUndefined();
|
|
20
|
+
observable.next('bar');
|
|
21
|
+
expect(cmp.foo).toBe('bar');
|
|
22
|
+
expect(forceUpdate).not.toHaveBeenCalled();
|
|
23
|
+
await Promise.resolve();
|
|
24
|
+
expect(forceUpdate).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
it('Sets property with triggering render synchronously.', async () => {
|
|
27
|
+
observable.subscribe(setProperty(cmp, 'foo', {
|
|
28
|
+
scheduleRender: true,
|
|
29
|
+
nextTick: false,
|
|
30
|
+
}));
|
|
31
|
+
expect(cmp.foo).toBeUndefined();
|
|
32
|
+
observable.next('bar');
|
|
33
|
+
expect(cmp.foo).toBe('bar');
|
|
34
|
+
expect(forceUpdate).toHaveBeenCalled();
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
await Promise.resolve();
|
|
37
|
+
expect(forceUpdate).not.toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
it('Sets property with triggering render asynchronously.', async () => {
|
|
40
|
+
observable.subscribe(setProperty(cmp, 'foo', {
|
|
41
|
+
scheduleRender: true,
|
|
42
|
+
nextTick: true,
|
|
43
|
+
}));
|
|
44
|
+
expect(cmp.foo).toBeUndefined();
|
|
45
|
+
observable.next('bar');
|
|
46
|
+
expect(cmp.foo).toBe('bar');
|
|
47
|
+
expect(forceUpdate).not.toHaveBeenCalled();
|
|
48
|
+
await Promise.resolve();
|
|
49
|
+
expect(forceUpdate).toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
class ComponentMock {
|
|
53
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { filter, take, } from "rxjs";
|
|
2
|
+
import { whileConnected } from "../rx/operator/while-connected";
|
|
3
|
+
export function applyOperators(...args) {
|
|
4
|
+
let [observable, cmp, options] = args;
|
|
5
|
+
return applyOperatorsInternal(observable, cmp, options);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A TypeScript types hack to make the applyOperators function work
|
|
9
|
+
* with both ViewChild and ViewChildren options.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function applyOperatorsInternal(observable, cmp, options) {
|
|
14
|
+
if (options === null || options === void 0 ? void 0 : options.whileConnected) {
|
|
15
|
+
observable = observable.pipe(whileConnected(cmp, {
|
|
16
|
+
reemit: true,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
if (options === null || options === void 0 ? void 0 : options.filter) {
|
|
20
|
+
observable = observable.pipe(true === options.filter
|
|
21
|
+
? filter((value) => {
|
|
22
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return !!value;
|
|
26
|
+
})
|
|
27
|
+
: filter(options.filter));
|
|
28
|
+
}
|
|
29
|
+
if (options === null || options === void 0 ? void 0 : options.cached) {
|
|
30
|
+
observable = observable.pipe(take(1));
|
|
31
|
+
}
|
|
32
|
+
return observable;
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getHostRef, isPropOrState, } from './stencil';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { distinctUntilChanged, filter, identity, } from "rxjs";
|
|
2
|
+
import { mutationObservable, } from "../rx";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an RxJS operator that emits only when the element changes, based on the provided comparator function.
|
|
5
|
+
*
|
|
6
|
+
* If boolean `true` is provided, the default comparator function will be used, which compares the elements by reference.
|
|
7
|
+
*
|
|
8
|
+
* If falsy value is provided, the operator will emit every time the source observable emits.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function distinctUntilElementChanged(comparator) {
|
|
13
|
+
if (!comparator) {
|
|
14
|
+
return identity;
|
|
15
|
+
}
|
|
16
|
+
if ('function' === typeof comparator) {
|
|
17
|
+
return distinctUntilChanged(comparator);
|
|
18
|
+
}
|
|
19
|
+
return distinctUntilChanged();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns an RxJS operator that emits only when the array of elements changes, based on the provided comparator function.
|
|
23
|
+
*
|
|
24
|
+
* If boolean `true` is provided, the default comparator function will be used, which compares the elements by reference.
|
|
25
|
+
*
|
|
26
|
+
* If falsy value is provided, the operator will emit every time the source observable emits.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function distinctUntilElementsChanged(comparator) {
|
|
31
|
+
if (!comparator) {
|
|
32
|
+
return identity;
|
|
33
|
+
}
|
|
34
|
+
// If the comparator is a function, use it to compare elements. Otherwise, use the default comparator that compares elements by reference.
|
|
35
|
+
let cmpFn = 'function' === typeof comparator ? comparator : (previous, current) => previous === current;
|
|
36
|
+
return distinctUntilChanged((previous, current) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (previous.length !== current.length) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return (_a = previous === null || previous === void 0 ? void 0 : previous.every((item, index) => cmpFn(item, current[index]))) !== null && _a !== void 0 ? _a : false;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Observe the subtree of an element for mutations.
|
|
46
|
+
*
|
|
47
|
+
* This function returns an observable that emits an array of MutationRecords whenever a mutation occurs
|
|
48
|
+
* in the subtree of the specified element.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export function observeSubtree(element) {
|
|
53
|
+
return mutationObservable(element, {
|
|
54
|
+
childList: true,
|
|
55
|
+
subtree: true,
|
|
56
|
+
}).pipe(filter((records) => {
|
|
57
|
+
for (let i = 0; i < records.length; i++) {
|
|
58
|
+
if ('childList' !== records[i].type) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (records[i].addedNodes.length || records[i].removedNodes.length) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the host reference of a component.
|
|
3
|
+
*
|
|
4
|
+
* This is useful for accessing the underlying DOM element of a Stencil component.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function getHostRef(cmp) {
|
|
9
|
+
return cmp.__stencil__getHostRef();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if a property is defined as a member of the component with @State or @Prop decorator.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function isPropOrState(cmp, property) {
|
|
17
|
+
let hostRef = getHostRef(cmp);
|
|
18
|
+
return !!hostRef.$cmpMeta$.$members$[property];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a component uses Shadow DOM.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function usesShadowDom(cmp) {
|
|
26
|
+
let hostRef = getHostRef(cmp);
|
|
27
|
+
let flags = hostRef.$cmpMeta$.$flags$;
|
|
28
|
+
return (flags & (1 << 0)) !== 0;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if a node is an emulated view child node.
|
|
32
|
+
*
|
|
33
|
+
* We are checking if node is a child node of the component which is not
|
|
34
|
+
* in emulated slot.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export function isEmulatedViewChild(node, element) {
|
|
39
|
+
// If the node has the 's-ol' property, it is not an emulated content child.
|
|
40
|
+
if ('s-ol' in node) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// If it is direct child of the component, it is not an emulated content child.
|
|
44
|
+
if (node.parentElement === element) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return isEmulatedViewChild(node.parentElement, element);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the tag name of a component.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export function getComponentTagName(cmp) {
|
|
55
|
+
let hostRef = getHostRef(cmp);
|
|
56
|
+
return hostRef.$cmpMeta$.$tagName$;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a component has been rendered at least once.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export function isRendered(cmp) {
|
|
64
|
+
let hostRef = getHostRef(cmp);
|
|
65
|
+
return (hostRef.$renderCount$ || 0) > 0;
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
let registries = new Map();
|
|
2
|
+
export class ValuesRegistry {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._observables = new WeakMap();
|
|
5
|
+
}
|
|
6
|
+
has(element, property) {
|
|
7
|
+
return this._observables.has(element) && this._observables.get(element).has(property);
|
|
8
|
+
}
|
|
9
|
+
get(element, property) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
return (_b = (_a = this._observables.get(element)) === null || _a === void 0 ? void 0 : _a.get(property)) === null || _b === void 0 ? void 0 : _b[0];
|
|
12
|
+
}
|
|
13
|
+
set(element, property, observable, initial) {
|
|
14
|
+
this.delete(element, property);
|
|
15
|
+
if (!this._observables.has(element)) {
|
|
16
|
+
this._observables.set(element, new Map());
|
|
17
|
+
}
|
|
18
|
+
this._observables.get(element).set(property, [observable, initial, undefined]);
|
|
19
|
+
this._observables.get(element).get(property)[2] = observable.subscribe((value) => {
|
|
20
|
+
this._observables.get(element).get(property)[1] = value;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
delete(element, property) {
|
|
24
|
+
if (this._observables.has(element) && this._observables.get(element).has(property)) {
|
|
25
|
+
let previous = this._observables.get(element).get(property)[2];
|
|
26
|
+
previous === null || previous === void 0 ? void 0 : previous.unsubscribe();
|
|
27
|
+
this._observables.get(element).delete(property);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
value(element, property) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return (_b = (_a = this._observables.get(element)) === null || _a === void 0 ? void 0 : _a.get(property)) === null || _b === void 0 ? void 0 : _b[1];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function getRegistry(key) {
|
|
36
|
+
if (!registries.has(key)) {
|
|
37
|
+
registries.set(key, new ValuesRegistry());
|
|
38
|
+
}
|
|
39
|
+
return registries.get(key);
|
|
40
|
+
}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getElement as
|
|
1
|
+
import{getElement as e,Build as t}from"@stencil/core/internal/client";export{getAssetPath,render,setAssetPath,setNonce,setPlatformOptions}from"@stencil/core/internal/client";import{c as n}from"./index2.js";import{u as r,i,g as o}from"./stencil.js";import{o as l,d as c,a,v as d,r as b}from"./mutation-observable.js";export{m as mutationObservable}from"./mutation-observable.js";export{f as fromEvent,s as scheduleRender}from"./schedule-render.js";export{p as propertiesObservable}from"./properties-observable.js";export{p as propertyObservable}from"./property-observable.js";export{u as untilDisconnected}from"./until-disconnected.js";export{s as setProperty}from"./set-property.js";function h(t,r){return i=>{let o=e(t);if(!(null==r?void 0:r.reemit))return i.pipe(n.filter((()=>o.isConnected)));let l,s=!1,u=new n.Subject,c=t.connectedCallback;return t.connectedCallback=function(){null==c||c.call(this),s&&(u.next(l),s=!1,l=void 0)},n.merge(u,i.pipe(n.tap((e=>{o.isConnected||(s=!0,l=e)})),n.filter((()=>o.isConnected))))}}function v(...e){let[t,r,i]=e;return function(e,t,r){return(null==r?void 0:r.whileConnected)&&(e=e.pipe(h(t,{reemit:!0}))),(null==r?void 0:r.filter)&&(e=e.pipe(n.filter(!0===r.filter?e=>!!(Array.isArray(e)&&e.length>0)||!!e:r.filter))),(null==r?void 0:r.cached)&&(e=e.pipe(n.take(1))),e}(t,r,i)}let j=new Map;class O{constructor(){this._observables=new WeakMap}has(e,t){return this._observables.has(e)&&this._observables.get(e).has(t)}get(e,t){var n,r;return null===(r=null===(n=this._observables.get(e))||void 0===n?void 0:n.get(t))||void 0===r?void 0:r[0]}set(e,t,n,r){this.delete(e,t),this._observables.has(e)||this._observables.set(e,new Map),this._observables.get(e).set(t,[n,r,void 0]),this._observables.get(e).get(t)[2]=n.subscribe((n=>{this._observables.get(e).get(t)[1]=n}))}delete(e,t){if(this._observables.has(e)&&this._observables.get(e).has(t)){let n=this._observables.get(e).get(t)[2];null==n||n.unsubscribe(),this._observables.get(e).delete(t)}}value(e,t){var n,r;return null===(r=null===(n=this._observables.get(e))||void 0===n?void 0:n.get(t))||void 0===r?void 0:r[1]}}function y(e){return j.has(e)||j.set(e,new O),j.get(e)}function g(t,o,s){let u=e(t),a=l(u).pipe(n.map((()=>{})),n.startWith(void 0));return s=Object.assign({distinct:!0},s),r(t)?a.pipe(n.map((()=>u.querySelector(o))),c(s.distinct)):a.pipe(n.map((()=>{let e=Array.from(u.querySelectorAll(o));for(let t=0;t<e.length;t++){let n=e[t];if(!i(n,u))return n}return null})),c(s.distinct))}function C(n,r){return function(i,o){let l=i.connectedCallback;i.connectedCallback=function(){null==l||l.call(this)};let s=Object.getOwnPropertyDescriptor(i.prototype,o)||{configurable:!0,enumerable:!0};delete s.value,delete s.writable,Object.defineProperty(i,o,Object.assign(Object.assign({},s),{set(e){t.isDev&&console.warn(`@ContentChild property "${o}" is read-only and cannot be set.`)},get(){let t=e(this),i=y("@ContentChild");if(!i.has(t,o)){let e=g(this,n,r);e=v(e,this,r),i.set(t,o,e)}return i.value(t,o)}}))}}function w(t,o,s){let u=e(t),c=l(u).pipe(n.map((()=>{})),n.startWith(void 0));return s=Object.assign({distinct:!0},s),r(t)?c.pipe(n.map((()=>Array.from(u.querySelectorAll(o)))),a(s.distinct)):c.pipe(n.map((()=>Array.from(u.querySelectorAll(o)).filter((e=>!i(e,u))))),a(s.distinct))}function x(n,r){return function(i,o){let l=i.connectedCallback;i.connectedCallback=function(){null==l||l.call(this)};let s=Object.getOwnPropertyDescriptor(i.prototype,o)||{configurable:!0,enumerable:!0};delete s.value,delete s.writable,Object.defineProperty(i,o,Object.assign(Object.assign({},s),{set(e){t.isDev&&console.warn(`@ContentChildren property "${o}" is read-only and cannot be set.`)},get(){let t=e(i),l=y("@ContentChildren");if(!l.has(t,o)){let e=w(this,n,r);e=v(e,this,r),l.set(t,o,e)}return l.value(t,o)}}))}}function A(n,r){return function(i,o){let l=i.connectedCallback;i.connectedCallback=function(){null==l||l.call(this)};let s=Object.getOwnPropertyDescriptor(i.prototype,o)||{configurable:!0,enumerable:!0};delete s.value,delete s.writable,Object.defineProperty(i,o,Object.assign(Object.assign({},s),{set(e){t.isDev&&console.warn(`@ViewChild property "${o}" is read-only and cannot be set.`)},get(){let t=e(this),i=y("@ViewChild");if(!i.has(t,o)){let e=d(this,n,r);e=v(e,this,r),i.set(t,o,e)}return i.value(t,o)}}))}}function $(e,t){return"content"===(null==t?void 0:t.target)?C(e,t):A(e,t)}function P(t,l,s){let u=e(t),c=o(t),d=b(t);return s=Object.assign({distinct:!0},s),(c.t||0)>0&&(d=d.pipe(n.startWith(void 0))),r(t)?d.pipe(n.map((()=>Array.from(u.shadowRoot.querySelectorAll(l)))),a(s.distinct)):d.pipe(n.map((()=>Array.from(u.querySelectorAll(l)))),n.map((e=>e.filter((e=>i(e,u))))),a(s.distinct))}function V(n,r){return function(i,o){let l=i.connectedCallback;i.connectedCallback=function(){null==l||l.call(this)};let s=Object.getOwnPropertyDescriptor(i.prototype,o)||{configurable:!0,enumerable:!0};delete s.value,delete s.writable,Object.defineProperty(i,o,Object.assign(Object.assign({},s),{set(e){t.isDev&&console.warn(`@ViewChildren property "${o}" is read-only and cannot be set.`)},get(){let t=e(i),l=y("@ViewChildren");if(!l.has(t,o)){let e=P(this,n,r);e=v(e,this,r),l.set(t,o,e)}return l.value(t,o)}}))}}function M(e,t){return"content"===(null==t?void 0:t.target)?x(e,t):V(e,t)}function k(e,r){return t.isDev&&!e.hasOwnProperty(r)&&console.warn(`It seams that ${r} does not exist on component ${o(e).o.i}. This warning will not be displayed in production environment.`),t=>t.pipe(n.tap((t=>{e[r]=t})))}export{C as ContentChild,x as ContentChildren,$ as QuerySelector,M as QuerySelectorAll,A as ViewChild,V as ViewChildren,g as contentChildObservable,w as contentChildrenObservable,b as renderObservable,k as toProperty,d as viewChildObservable,P as viewChildrenObservable,h as whileConnected}
|