angular-three 1.4.5 → 1.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.
@@ -931,18 +931,39 @@ function extend(objects) {
931
931
  }
932
932
  const NGT_CATALOGUE = new InjectionToken('THREE Constructors Catalogue', { factory: () => catalogue });
933
933
 
934
- class NgtArgs {
934
+ class NgtCommonDirective {
935
935
  constructor() {
936
936
  this.vcr = inject(ViewContainerRef);
937
937
  this.template = inject(TemplateRef);
938
- this.injectedArgs = [];
939
938
  this.injected = false;
939
+ this.shouldCreateView = true;
940
940
  const commentNode = this.vcr.element.nativeElement;
941
941
  if (commentNode['__ngt_renderer_add_comment__']) {
942
942
  commentNode['__ngt_renderer_add_comment__']();
943
943
  delete commentNode['__ngt_renderer_add_comment__'];
944
944
  }
945
945
  }
946
+ createView() {
947
+ if (this.shouldCreateView) {
948
+ if (this.view && !this.view.destroyed) {
949
+ this.view.destroy();
950
+ }
951
+ this.view = this.vcr.createEmbeddedView(this.template);
952
+ this.view.detectChanges();
953
+ }
954
+ }
955
+ }
956
+ NgtCommonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtCommonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
957
+ NgtCommonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.3", type: NgtCommonDirective, ngImport: i0 });
958
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtCommonDirective, decorators: [{
959
+ type: Directive
960
+ }], ctorParameters: function () { return []; } });
961
+
962
+ class NgtArgs extends NgtCommonDirective {
963
+ constructor() {
964
+ super(...arguments);
965
+ this.injectedArgs = [];
966
+ }
946
967
  set args(args) {
947
968
  if (args == null || !Array.isArray(args))
948
969
  return;
@@ -962,20 +983,41 @@ class NgtArgs {
962
983
  validate() {
963
984
  return !this.injected && !!this.injectedArgs.length;
964
985
  }
965
- createView() {
966
- if (this.view && !this.view.destroyed) {
967
- this.view.destroy();
968
- }
969
- this.view = this.vcr.createEmbeddedView(this.template);
970
- this.view.detectChanges();
971
- }
972
986
  }
973
- NgtArgs.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtArgs, deps: [], target: i0.ɵɵFactoryTarget.Directive });
974
- NgtArgs.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.3", type: NgtArgs, isStandalone: true, selector: "[args]", inputs: { args: "args" }, ngImport: i0 });
987
+ NgtArgs.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtArgs, deps: null, target: i0.ɵɵFactoryTarget.Directive });
988
+ NgtArgs.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.3", type: NgtArgs, isStandalone: true, selector: "[args]", inputs: { args: "args" }, usesInheritance: true, ngImport: i0 });
975
989
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtArgs, decorators: [{
976
990
  type: Directive,
977
991
  args: [{ selector: '[args]', standalone: true }]
978
- }], ctorParameters: function () { return []; }, propDecorators: { args: [{
992
+ }], propDecorators: { args: [{
993
+ type: Input
994
+ }] } });
995
+
996
+ class NgtRef extends NgtCommonDirective {
997
+ set ref(ref) {
998
+ if (!ref || ref == null)
999
+ return;
1000
+ this.injected = false;
1001
+ this.injectedRef = ref;
1002
+ this.createView();
1003
+ }
1004
+ get ref() {
1005
+ if (this.validate()) {
1006
+ this.injected = true;
1007
+ return this.injectedRef;
1008
+ }
1009
+ return null;
1010
+ }
1011
+ validate() {
1012
+ return !this.injected && !!this.injectedRef && !this.injectedRef.nativeElement;
1013
+ }
1014
+ }
1015
+ NgtRef.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtRef, deps: null, target: i0.ɵɵFactoryTarget.Directive });
1016
+ NgtRef.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.3", type: NgtRef, isStandalone: true, selector: "[ref]", inputs: { ref: "ref" }, usesInheritance: true, ngImport: i0 });
1017
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.3", ngImport: i0, type: NgtRef, decorators: [{
1018
+ type: Directive,
1019
+ args: [{ selector: '[ref]', standalone: true }]
1020
+ }], propDecorators: { ref: [{
979
1021
  type: Input
980
1022
  }] } });
981
1023
 
@@ -1678,11 +1720,11 @@ class NgtRendererStore {
1678
1720
  return;
1679
1721
  // setup [ref] here
1680
1722
  // ref should never change
1681
- if (name === SPECIAL_PROPERTIES.REF && is.ref(value)) {
1682
- node.__ngt_renderer__[11 /* NgtRendererClassId.ref */] = value;
1683
- value.nativeElement = node;
1684
- return;
1685
- }
1723
+ // if (name === SPECIAL_PROPERTIES.REF && is.ref(value)) {
1724
+ // node.__ngt_renderer__[NgtRendererClassId.ref] = value;
1725
+ // value.nativeElement = node;
1726
+ // return;
1727
+ // }
1686
1728
  const parent = getLocalState(node).parent || node.__ngt_renderer__[1 /* NgtRendererClassId.parent */];
1687
1729
  // rawValue
1688
1730
  if (getLocalState(node).isRaw && name === SPECIAL_PROPERTIES.VALUE) {
@@ -1758,8 +1800,9 @@ class NgtRendererStore {
1758
1800
  }
1759
1801
  getCreationState() {
1760
1802
  const injectedArgs = this.firstNonInjectedDirective(NgtArgs)?.args || [];
1803
+ const injectedRef = this.firstNonInjectedDirective(NgtRef)?.ref || null;
1761
1804
  const store = this.tryGetPortalStore();
1762
- return { injectedArgs, store };
1805
+ return { injectedArgs, injectedRef, store };
1763
1806
  }
1764
1807
  destroy(node, parent) {
1765
1808
  const state = node.__ngt_renderer__;
@@ -1976,7 +2019,7 @@ class NgtRenderer {
1976
2019
  if (name === SPECIAL_DOM_TAG.NGT_VALUE) {
1977
2020
  return this.store.createNode('three', Object.assign({ __ngt_renderer__: { rawValue: undefined } }, { __ngt__: { isRaw: true } }));
1978
2021
  }
1979
- const { injectedArgs, store } = this.store.getCreationState();
2022
+ const { injectedArgs, injectedRef, store } = this.store.getCreationState();
1980
2023
  // handle primitive
1981
2024
  if (name === SPECIAL_DOM_TAG.NGT_PRIMITIVE) {
1982
2025
  if (!injectedArgs[0])
@@ -1989,7 +2032,10 @@ class NgtRenderer {
1989
2032
  }
1990
2033
  if (!localState.store)
1991
2034
  localState.store = store;
1992
- return this.store.createNode('three', object);
2035
+ const primitiveNode = this.store.createNode('three', object);
2036
+ if (injectedRef)
2037
+ injectedRef.nativeElement = primitiveNode;
2038
+ return primitiveNode;
1993
2039
  }
1994
2040
  const threeTag = name.startsWith('ngt') ? name.slice(4) : name;
1995
2041
  const threeName = kebabToPascal(threeTag);
@@ -2005,6 +2051,10 @@ class NgtRenderer {
2005
2051
  else if (is.material(instance)) {
2006
2052
  localState.attach = ['material'];
2007
2053
  }
2054
+ if (injectedRef) {
2055
+ injectedRef.nativeElement = node;
2056
+ node.__ngt_renderer__[11 /* NgtRendererClassId.ref */] = injectedRef;
2057
+ }
2008
2058
  return node;
2009
2059
  }
2010
2060
  const domNode = this.store.createNode('dom', element);
@@ -2916,5 +2966,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.3", ngImpor
2916
2966
  * Generated bundle index. Do not edit.
2917
2967
  */
2918
2968
 
2919
- export { NGT_CATALOGUE, NgtArgs, NgtCanvas, NgtPortal, NgtPortalBeforeRender, NgtPortalContent, NgtPush, NgtRepeat, NgtRxStore, NgtStore, addAfterEffect, addEffect, addTail, applyProps, checkNeedsUpdate, checkUpdate, createAttachFunction, createLoop, extend, flushGlobalEffects, getLocalState, injectBeforeRender, injectNgtDestroy, injectNgtLoader, injectNgtRef, invalidateInstance, is, makeDefaultCamera, makeDefaultRenderer, makeDpr, makeId, makeObjectGraph, prepare, rootStateMap, safeDetectChanges, startWithUndefined, tapEffect, updateCamera };
2969
+ export { NGT_CATALOGUE, NgtArgs, NgtCanvas, NgtPortal, NgtPortalBeforeRender, NgtPortalContent, NgtPush, NgtRef, NgtRepeat, NgtRxStore, NgtStore, addAfterEffect, addEffect, addTail, applyProps, checkNeedsUpdate, checkUpdate, createAttachFunction, createLoop, extend, flushGlobalEffects, getLocalState, injectBeforeRender, injectNgtDestroy, injectNgtLoader, injectNgtRef, invalidateInstance, is, makeDefaultCamera, makeDefaultRenderer, makeDpr, makeId, makeObjectGraph, prepare, rootStateMap, safeDetectChanges, startWithUndefined, tapEffect, updateCamera };
2920
2970
  //# sourceMappingURL=angular-three.mjs.map