angular-three 1.0.0-beta.3 → 1.0.0-beta.5
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 +55 -4
- package/esm2020/index.mjs +9 -1
- package/esm2020/lib/di/destroy.mjs +24 -0
- package/esm2020/lib/di/ref.mjs +71 -0
- package/fesm2015/angular-three.mjs +90 -2
- package/fesm2015/angular-three.mjs.map +1 -1
- package/fesm2020/angular-three.mjs +90 -2
- package/fesm2020/angular-three.mjs.map +1 -1
- package/index.d.ts +8 -0
- package/lib/di/destroy.d.ts +9 -0
- package/lib/di/ref.d.ts +12 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { ElementRef, Injectable, inject, InjectionToken, ViewContainerRef, TemplateRef, Directive, Input, EventEmitter, getDebugNode, ChangeDetectorRef, RendererFactory2, Component, Output, EnvironmentInjector, createEnvironmentInjector, HostBinding, ViewChild } from '@angular/core';
|
|
3
3
|
import { injectNgxResize, provideNgxResizeOptions } from 'ngx-resize';
|
|
4
|
-
import { BehaviorSubject, startWith, tap, isObservable, of, map, from, retry, catchError, share, ReplaySubject, switchMap, forkJoin, take, filter } from 'rxjs';
|
|
4
|
+
import { BehaviorSubject, startWith, tap, isObservable, of, map, from, retry, catchError, share, ReplaySubject, switchMap, forkJoin, take, filter, distinctUntilChanged, takeUntil, merge } from 'rxjs';
|
|
5
5
|
import { DOCUMENT, NgForOf } from '@angular/common';
|
|
6
6
|
import { RxState, selectSlice } from '@rx-angular/state';
|
|
7
7
|
import * as THREE from 'three';
|
|
@@ -2488,9 +2488,97 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
2488
2488
|
type: Input
|
|
2489
2489
|
}] } });
|
|
2490
2490
|
|
|
2491
|
+
/**
|
|
2492
|
+
* A utility injection fn that can be used in other injection fn to provide the destroy capability.
|
|
2493
|
+
*/
|
|
2494
|
+
function injectNgtDestroy(cb) {
|
|
2495
|
+
try {
|
|
2496
|
+
const cdr = inject(ChangeDetectorRef);
|
|
2497
|
+
const destroy$ = new ReplaySubject();
|
|
2498
|
+
queueMicrotask(() => {
|
|
2499
|
+
cdr.onDestroy(() => {
|
|
2500
|
+
destroy$.next();
|
|
2501
|
+
destroy$.complete();
|
|
2502
|
+
cb?.();
|
|
2503
|
+
});
|
|
2504
|
+
});
|
|
2505
|
+
return { destroy$, cdr };
|
|
2506
|
+
}
|
|
2507
|
+
catch (e) {
|
|
2508
|
+
console.warn(`[NGT] injectNgtDestroy is being called outside of Constructor Context`);
|
|
2509
|
+
return {};
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
function injectNgtRef(initialValue = null) {
|
|
2514
|
+
let ref = new ElementRef(initialValue);
|
|
2515
|
+
if (is.ref(initialValue)) {
|
|
2516
|
+
ref = initialValue;
|
|
2517
|
+
}
|
|
2518
|
+
let lastValue = ref.nativeElement;
|
|
2519
|
+
const cdRefs = [];
|
|
2520
|
+
const ref$ = new BehaviorSubject(lastValue);
|
|
2521
|
+
const { destroy$, cdr } = injectNgtDestroy(() => {
|
|
2522
|
+
ref$.complete();
|
|
2523
|
+
});
|
|
2524
|
+
cdRefs.push(cdr);
|
|
2525
|
+
const obs$ = ref$.asObservable().pipe(distinctUntilChanged(), takeUntil(destroy$));
|
|
2526
|
+
const subscribe = (callback) => {
|
|
2527
|
+
return obs$.subscribe((current) => {
|
|
2528
|
+
callback(current, lastValue);
|
|
2529
|
+
lastValue = current;
|
|
2530
|
+
});
|
|
2531
|
+
};
|
|
2532
|
+
const $ = obs$.pipe(filter((value, index) => index > 0 || value != null), takeUntil(destroy$));
|
|
2533
|
+
const children$ = (type = 'objects') => $.pipe(switchMap((instance) => {
|
|
2534
|
+
const localState = getLocalState(instance);
|
|
2535
|
+
if (localState.objects && localState.nonObjects) {
|
|
2536
|
+
return merge(localState.objects, localState.nonObjects).pipe(map(() => {
|
|
2537
|
+
try {
|
|
2538
|
+
return type === 'both'
|
|
2539
|
+
? [...localState.objects.value, ...localState.nonObjects.value]
|
|
2540
|
+
: localState[type].value;
|
|
2541
|
+
}
|
|
2542
|
+
catch (e) {
|
|
2543
|
+
console.error(`[NGT] Exception in accessing children of ${instance}`);
|
|
2544
|
+
return [];
|
|
2545
|
+
}
|
|
2546
|
+
}));
|
|
2547
|
+
}
|
|
2548
|
+
return of([]);
|
|
2549
|
+
}), filter((children, index) => index > 0 || children.length > 0), takeUntil(destroy$));
|
|
2550
|
+
Object.defineProperty(ref, 'nativeElement', {
|
|
2551
|
+
set: (newVal) => {
|
|
2552
|
+
if (ref.nativeElement !== newVal) {
|
|
2553
|
+
ref$.next(newVal);
|
|
2554
|
+
lastValue = ref.nativeElement;
|
|
2555
|
+
ref.nativeElement = newVal;
|
|
2556
|
+
// clone the cdRefs so we can mutate cdRefs in the loop
|
|
2557
|
+
const cds = [...cdRefs];
|
|
2558
|
+
for (let i = 0; i < cds.length; i++) {
|
|
2559
|
+
const cd = cds[i];
|
|
2560
|
+
// if a ChangeDetectorRef is destroyed, we stop tracking it and go to the next one
|
|
2561
|
+
if (cd.destroyed) {
|
|
2562
|
+
cdRefs.splice(i, 1);
|
|
2563
|
+
continue;
|
|
2564
|
+
}
|
|
2565
|
+
// during creation phase, 'context' on ViewRef will be null
|
|
2566
|
+
// we check the "context" to avoid running detectChanges during this phase.
|
|
2567
|
+
// becuase there's nothing to check
|
|
2568
|
+
if (cd['context']) {
|
|
2569
|
+
cd.detectChanges();
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
},
|
|
2574
|
+
get: () => ref$.value,
|
|
2575
|
+
});
|
|
2576
|
+
return Object.assign(ref, { subscribe, $, children$, useCDR: (cdr) => void cdRefs.push(cdr) });
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2491
2579
|
/**
|
|
2492
2580
|
* Generated bundle index. Do not edit.
|
|
2493
2581
|
*/
|
|
2494
2582
|
|
|
2495
|
-
export { NGT_CATALOGUE, NgtArgs, NgtCanvas, NgtCanvasContainer, NgtRepeat, extend };
|
|
2583
|
+
export { NGT_CATALOGUE, NgtArgs, NgtCanvas, NgtCanvasContainer, NgtRepeat, NgtRxStore, NgtStore, checkNeedsUpdate, checkUpdate, extend, getLocalState, injectNgtDestroy, injectNgtLoader, injectNgtRef, invalidateInstance, is, prepare, rootStateMap, startWithUndefined, updateCamera };
|
|
2496
2584
|
//# sourceMappingURL=angular-three.mjs.map
|