@ssv/ngx.ux 1.3.0 → 1.4.1

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/CHANGELOG.md CHANGED
@@ -11,6 +11,19 @@
11
11
  - **viewport:** change `ViewportSizeType` and `UX_VIEWPORT_DEFAULT_BREAKPOINTS` has been changed (see readme)
12
12
  - **viewport:** remove `ViewportService.calculateItemsPerRow` function
13
13
 
14
+ ## [1.4.1](https://github.com/sketch7/ngx.ux/compare/1.4.0...1.4.1) (2023-04-13)
15
+
16
+ ### Features
17
+
18
+ - **viewport:** `ViewportService` - add `resizeSnap$`, `sizeTypeSnap$`, `sizeSnap$` which are unthrottled
19
+ - **viewport:** `ViewportDataService` `get$` add option to `throttle`
20
+
21
+ ## [1.4.0](https://github.com/sketch7/ngx.ux/compare/1.3.0...1.4.0) (2020-11-25)
22
+
23
+ ### Features
24
+
25
+ - **viewport:** implement `ssvViewportMatcherVar` directive
26
+
14
27
  ## [1.3.0](https://github.com/sketch7/ngx.ux/compare/1.2.2...1.3.0) (2020-11-11)
15
28
 
16
29
  ### Features
package/README.md CHANGED
@@ -125,6 +125,21 @@ Structural directive which loads components based on a viewport sizing condition
125
125
  </ng-template>
126
126
  ```
127
127
 
128
+ ### Viewport Matcher Var (directive)
129
+ Structural directive which provides the condition var whether it matches or not (params are similar to `ssvViewportMatcher`).
130
+
131
+ ```html
132
+ <!-- simple -->
133
+ <div *ssvViewportMatcherVar="let isLarge when 'large'">
134
+ isLarge={{isLarge}}
135
+ </div>
136
+
137
+ <!-- expression based - tuple (shorthand) *recommended usage* -->
138
+ <div *ssvViewportMatcherVar="let isMediumDown when ['<=', 'medium']">
139
+ isMediumDown={{isMediumDown}}
140
+ </div>
141
+ ```
142
+
128
143
  ### Viewport Service
129
144
 
130
145
  ```ts
@@ -601,15 +601,20 @@
601
601
  this._sizeTypes = generateViewportSizeTypeInfoList(config.viewport.breakpoints);
602
602
  this._sizeTypeMap = generateViewportSizeTypeInfoRefs(this._sizeTypes);
603
603
  if (windowRef.hasNative) {
604
- this.resize$ = rxjs.fromEvent(window, "resize").pipe(operators.map(function () { return _this.getViewportSize(); }), operators.auditTime(config.viewport.resizePollingSpeed), operators.share());
604
+ this.resizeSnap$ = rxjs.fromEvent(window, "resize").pipe(operators.map(function () { return _this.getViewportSize(); }), operators.share());
605
+ this.resize$ = this.resizeSnap$.pipe(operators.auditTime(config.viewport.resizePollingSpeed), operators.share());
605
606
  }
606
607
  else {
607
- this.resize$ = rxjs.of(viewportServerSize.get());
608
+ this.resizeSnap$ = this.resize$ = rxjs.of(viewportServerSize.get());
608
609
  }
609
610
  var size = this.getViewportSize();
610
611
  this._sizeTypeSnapshot = getSizeTypeInfo(size.width, this.sizeTypes);
611
- this.size$ = this.resize$.pipe(operators.startWith(size), operators.distinctUntilChanged(function (a, b) { return a.width === b.width && a.height === b.height; }), operators.shareReplay(1));
612
- this.sizeType$ = this.size$.pipe(operators.distinctUntilChanged(function (a, b) { return a.width === b.width; }), operators.map(function (x) { return getSizeTypeInfo(x.width, _this.sizeTypes); }), operators.distinctUntilChanged(), operators.tap(function (x) { return _this._sizeTypeSnapshot = x; }), operators.shareReplay(1));
612
+ var sizeFn = function (obs$) { return obs$.pipe(operators.startWith(size), operators.distinctUntilChanged(function (a, b) { return a.width === b.width && a.height === b.height; }), operators.shareReplay(1)); };
613
+ this.sizeSnap$ = sizeFn(this.resizeSnap$);
614
+ this.size$ = sizeFn(this.resize$);
615
+ var sizeTypeFn = function (obs$) { return obs$.pipe(operators.distinctUntilChanged(function (a, b) { return a.width === b.width; }), operators.map(function (x) { return getSizeTypeInfo(x.width, _this.sizeTypes); }), operators.distinctUntilChanged(), operators.tap(function (x) { return _this._sizeTypeSnapshot = x; }), operators.shareReplay(1)); };
616
+ this.sizeType$ = sizeTypeFn(this.size$);
617
+ this.sizeTypeSnap$ = sizeTypeFn(this.sizeSnap$);
613
618
  }
614
619
  Object.defineProperty(ViewportService.prototype, "sizeTypeSnapshot", {
615
620
  /** Viewport size type snapshot of the last value. (Prefer use `sizeType$` observable when possible.) */
@@ -793,9 +798,10 @@
793
798
  return matchViewportData(dataConfig, sizeType, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
794
799
  };
795
800
  /** Get data for match as observable. */
796
- ViewportDataService.prototype.get$ = function (dataConfig, strategy) {
801
+ ViewportDataService.prototype.get$ = function (dataConfig, strategy, throttle) {
797
802
  var _this = this;
798
- return this.viewport.sizeType$.pipe(operators.map(function (sizeType) { return _this.get(dataConfig, strategy, sizeType); }), operators.distinctUntilChanged());
803
+ if (throttle === void 0) { throttle = true; }
804
+ return (throttle ? this.viewport.sizeType$ : this.viewport.sizeTypeSnap$).pipe(operators.map(function (sizeType) { return _this.get(dataConfig, strategy, sizeType); }), operators.distinctUntilChanged());
799
805
  };
800
806
  /** Generate rules based on strategies for data. */
801
807
  ViewportDataService.prototype.generateRules = function (dataConfig, strategy) {
@@ -856,6 +862,76 @@
856
862
  return ViewportDataPipe;
857
863
  }());
858
864
 
865
+ var NAME_CAMEL = "ssvViewportMatcherVar";
866
+ var SsvViewportMatcherVarContext = /** @class */ (function () {
867
+ function SsvViewportMatcherVarContext($implicit) {
868
+ if ($implicit === void 0) { $implicit = false; }
869
+ this.$implicit = $implicit;
870
+ }
871
+ return SsvViewportMatcherVarContext;
872
+ }());
873
+ var SsvViewportMatcherVarDirective = /** @class */ (function () {
874
+ function SsvViewportMatcherVarDirective(viewport, viewContainer, templateRef) {
875
+ this.viewport = viewport;
876
+ this.viewContainer = viewContainer;
877
+ this.templateRef = templateRef;
878
+ this._matchConditions = {};
879
+ this._context = new SsvViewportMatcherVarContext();
880
+ this._destroy$ = new rxjs.Subject();
881
+ this._update$ = new rxjs.ReplaySubject(1);
882
+ }
883
+ Object.defineProperty(SsvViewportMatcherVarDirective.prototype, "condition", {
884
+ set: function (value) {
885
+ if (isViewportSizeMatcherExpression(value)) {
886
+ this._matchConditions.expression = value;
887
+ }
888
+ else if (isViewportSizeMatcherTupleExpression(value)) {
889
+ var _a = __read(value, 2), op = _a[0], size = _a[1];
890
+ this._matchConditions.expression = {
891
+ operation: op,
892
+ size: size
893
+ };
894
+ }
895
+ else {
896
+ this._matchConditions.sizeType = value;
897
+ }
898
+ this._update$.next();
899
+ },
900
+ enumerable: true,
901
+ configurable: true
902
+ });
903
+ SsvViewportMatcherVarDirective.prototype.ngOnInit = function () {
904
+ var _this = this;
905
+ this.updateView();
906
+ rxjs.combineLatest([this.viewport.sizeType$, this._update$]).pipe(operators.map(function (_a) {
907
+ var _b = __read(_a, 1), sizeType = _b[0];
908
+ return isViewportConditionMatch(sizeType, _this._matchConditions, _this.viewport.sizeTypeMap);
909
+ }), operators.tap(function (x) { return _this._context.$implicit = x; }), operators.tap(function () { return _this._viewRef.markForCheck(); }), operators.takeUntil(this._destroy$)).subscribe();
910
+ };
911
+ SsvViewportMatcherVarDirective.prototype.ngOnDestroy = function () {
912
+ this._destroy$.next();
913
+ this._destroy$.complete();
914
+ };
915
+ SsvViewportMatcherVarDirective.prototype.updateView = function () {
916
+ this.viewContainer.clear();
917
+ this._viewRef = this.viewContainer.createEmbeddedView(this.templateRef, this._context);
918
+ };
919
+ SsvViewportMatcherVarDirective.ctorParameters = function () { return [
920
+ { type: ViewportService },
921
+ { type: core.ViewContainerRef },
922
+ { type: core.TemplateRef }
923
+ ]; };
924
+ __decorate([
925
+ core.Input(NAME_CAMEL + "When")
926
+ ], SsvViewportMatcherVarDirective.prototype, "condition", null);
927
+ SsvViewportMatcherVarDirective = __decorate([
928
+ core.Directive({
929
+ selector: "[" + NAME_CAMEL + "]",
930
+ })
931
+ ], SsvViewportMatcherVarDirective);
932
+ return SsvViewportMatcherVarDirective;
933
+ }());
934
+
859
935
  var SsvViewportMatcherContext = /** @class */ (function () {
860
936
  function SsvViewportMatcherContext() {
861
937
  this.sizeType = null;
@@ -864,10 +940,10 @@
864
940
  return SsvViewportMatcherContext;
865
941
  }());
866
942
  var SsvViewportMatcherDirective = /** @class */ (function () {
867
- function SsvViewportMatcherDirective(viewport, renderer, _viewContainer, cdr, templateRef) {
943
+ function SsvViewportMatcherDirective(viewport, renderer, viewContainer, cdr, templateRef) {
868
944
  this.viewport = viewport;
869
945
  this.renderer = renderer;
870
- this._viewContainer = _viewContainer;
946
+ this.viewContainer = viewContainer;
871
947
  this.cdr = cdr;
872
948
  this._context = new SsvViewportMatcherContext();
873
949
  this._thenTemplateRef = null;
@@ -879,44 +955,6 @@
879
955
  this._update$ = new rxjs.Subject();
880
956
  this._thenTemplateRef = templateRef;
881
957
  }
882
- SsvViewportMatcherDirective.prototype.ngOnInit = function () {
883
- // console.log("ssvViewportMatcher init");
884
- var _this = this;
885
- this._update$
886
- .pipe(
887
- // tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
888
- operators.filter(function () { return !!_this.sizeInfo; }),
889
- // tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
890
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
891
- operators.tap(function () { return _this._updateView(_this.sizeInfo); }), operators.tap(function () { return _this.cdr.markForCheck(); }))
892
- .subscribe();
893
- this.sizeType$$ = this.viewport.sizeType$
894
- .pipe(
895
- // tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
896
- operators.tap(function (x) { return _this.sizeInfo = x; }), operators.tap(function () { return _this._update$.next(_this._context); }))
897
- .subscribe();
898
- this.cssClass$$ = this.viewport.sizeType$
899
- .pipe(operators.startWith(undefined), operators.filter(function () { return !!(_this._thenViewRef || _this._elseViewRef); }), operators.pairwise(), operators.tap(function (_a) {
900
- var _b = __read(_a, 2), prev = _b[0], curr = _b[1];
901
- var _c;
902
- var el = _this._thenViewRef
903
- ? _this._thenViewRef.rootNodes[0]
904
- : (_c = _this._elseViewRef) === null || _c === void 0 ? void 0 : _c.rootNodes[0];
905
- if (!el.classList) {
906
- return;
907
- }
908
- if (prev) {
909
- _this.renderer.removeClass(el, "ssv-vp-size--" + prev.name);
910
- }
911
- _this.renderer.addClass(el, "ssv-vp-size--" + (curr === null || curr === void 0 ? void 0 : curr.name));
912
- }))
913
- .subscribe();
914
- };
915
- SsvViewportMatcherDirective.prototype.ngOnDestroy = function () {
916
- this.cssClass$$.unsubscribe();
917
- this.sizeType$$.unsubscribe();
918
- this._update$.complete();
919
- };
920
958
  Object.defineProperty(SsvViewportMatcherDirective.prototype, "ssvViewportMatcher", {
921
959
  set: function (value) {
922
960
  if (isViewportSizeMatcherExpression(value)) {
@@ -960,22 +998,60 @@
960
998
  enumerable: true,
961
999
  configurable: true
962
1000
  });
1001
+ SsvViewportMatcherDirective.prototype.ngOnInit = function () {
1002
+ // console.log("ssvViewportMatcher init");
1003
+ var _this = this;
1004
+ this._update$
1005
+ .pipe(
1006
+ // tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
1007
+ operators.filter(function () { return !!_this.sizeInfo; }),
1008
+ // tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
1009
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1010
+ operators.tap(function () { return _this._updateView(_this.sizeInfo); }), operators.tap(function () { return _this.cdr.markForCheck(); }))
1011
+ .subscribe();
1012
+ this.sizeType$$ = this.viewport.sizeType$
1013
+ .pipe(
1014
+ // tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
1015
+ operators.tap(function (x) { return _this.sizeInfo = x; }), operators.tap(function () { return _this._update$.next(_this._context); }))
1016
+ .subscribe();
1017
+ this.cssClass$$ = this.viewport.sizeType$
1018
+ .pipe(operators.startWith(undefined), operators.filter(function () { return !!(_this._thenViewRef || _this._elseViewRef); }), operators.pairwise(), operators.tap(function (_a) {
1019
+ var _b = __read(_a, 2), prev = _b[0], curr = _b[1];
1020
+ var _c;
1021
+ var el = _this._thenViewRef
1022
+ ? _this._thenViewRef.rootNodes[0]
1023
+ : (_c = _this._elseViewRef) === null || _c === void 0 ? void 0 : _c.rootNodes[0];
1024
+ if (!el.classList) {
1025
+ return;
1026
+ }
1027
+ if (prev) {
1028
+ _this.renderer.removeClass(el, "ssv-vp-size--" + prev.name);
1029
+ }
1030
+ _this.renderer.addClass(el, "ssv-vp-size--" + (curr === null || curr === void 0 ? void 0 : curr.name));
1031
+ }))
1032
+ .subscribe();
1033
+ };
1034
+ SsvViewportMatcherDirective.prototype.ngOnDestroy = function () {
1035
+ this.cssClass$$.unsubscribe();
1036
+ this.sizeType$$.unsubscribe();
1037
+ this._update$.complete();
1038
+ };
963
1039
  SsvViewportMatcherDirective.prototype._updateView = function (sizeInfo) {
964
1040
  if (isViewportConditionMatch(sizeInfo, this._context, this.viewport.sizeTypeMap)) {
965
1041
  if (!this._thenViewRef) {
966
- this._viewContainer.clear();
1042
+ this.viewContainer.clear();
967
1043
  this._elseViewRef = null;
968
1044
  if (this._thenTemplateRef) {
969
- this._thenViewRef = this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
1045
+ this._thenViewRef = this.viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
970
1046
  }
971
1047
  }
972
1048
  }
973
1049
  else {
974
1050
  if (!this._elseViewRef) {
975
- this._viewContainer.clear();
1051
+ this.viewContainer.clear();
976
1052
  this._thenViewRef = null;
977
1053
  if (this._elseTemplateRef) {
978
- this._elseViewRef = this._viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
1054
+ this._elseViewRef = this.viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
979
1055
  }
980
1056
  }
981
1057
  }
@@ -1009,6 +1085,7 @@
1009
1085
  var MODULE_CONFIG_DATA = new core.InjectionToken("@ssv/ngx.ux/configData");
1010
1086
  var components = [
1011
1087
  SsvViewportMatcherDirective,
1088
+ SsvViewportMatcherVarDirective,
1012
1089
  ViewportDataPipe,
1013
1090
  ];
1014
1091
  // todo: create module for Viewport
@@ -1054,13 +1131,15 @@
1054
1131
  return {};
1055
1132
  }
1056
1133
 
1057
- var VERSION = "1.3.0";
1134
+ var VERSION = "1.4.1";
1058
1135
 
1059
1136
  exports.COMPARISON_OPERATION_FUNC_MAPPING = COMPARISON_OPERATION_FUNC_MAPPING;
1060
1137
  exports.MODULE_CONFIG_DATA = MODULE_CONFIG_DATA;
1061
1138
  exports.SsvUxModule = SsvUxModule;
1062
1139
  exports.SsvViewportMatcherContext = SsvViewportMatcherContext;
1063
1140
  exports.SsvViewportMatcherDirective = SsvViewportMatcherDirective;
1141
+ exports.SsvViewportMatcherVarContext = SsvViewportMatcherVarContext;
1142
+ exports.SsvViewportMatcherVarDirective = SsvViewportMatcherVarDirective;
1064
1143
  exports.UX_CONFIG = UX_CONFIG;
1065
1144
  exports.UX_DEFAULT_CONFIG = UX_DEFAULT_CONFIG;
1066
1145
  exports.UX_VIEWPORT_DEFAULT_BREAKPOINTS = UX_VIEWPORT_DEFAULT_BREAKPOINTS;