@ssv/ngx.ux 2.0.0-dev160 → 2.0.1-dev198

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,12 @@
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.0](https://github.com/sketch7/ngx.ux/compare/1.3.0...1.4.0) (2020-11-25)
15
+
16
+ ### Features
17
+
18
+ - **viewport:** implement `ssvViewportMatcherVar` directive
19
+
14
20
  ## [1.3.0](https://github.com/sketch7/ngx.ux/compare/1.2.2...1.3.0) (2020-11-11)
15
21
 
16
22
  ### Features
package/README.md CHANGED
@@ -126,6 +126,26 @@ Structural directive which loads components based on a viewport sizing condition
126
126
  </ng-template>
127
127
  ```
128
128
 
129
+ ### Viewport Matcher Var (directive)
130
+ Structural directive which provides the condition var whether it matches or not (params are similar to `ssvViewportMatcher`).
131
+
132
+ ```html
133
+ <!-- simple -->
134
+ <div *ssvViewportMatcherVar="let isLarge when 'large'">
135
+ isLarge={{isLarge}}
136
+ </div>
137
+
138
+ <!-- expression based - tuple (shorthand) *recommended usage* -->
139
+ <div *ssvViewportMatcherVar="let isMediumDown when ['<=', 'medium']">
140
+ isMediumDown={{isMediumDown}}
141
+ </div>
142
+
143
+ <!-- includes/or -->
144
+ <div *ssvViewportMatcherVar="let isLargeOrSmall when ['small', 'large']">
145
+ isLargeOrSmall={{isLargeOrSmall}}
146
+ </div>
147
+ ```
148
+
129
149
  ### Viewport Service
130
150
 
131
151
  ```ts
@@ -679,15 +679,20 @@
679
679
  this._sizeTypes = generateViewportSizeTypeInfoList(config.viewport.breakpoints);
680
680
  this._sizeTypeMap = generateViewportSizeTypeInfoRefs(this._sizeTypes);
681
681
  if (windowRef.hasNative) {
682
- this.resize$ = rxjs.fromEvent(window, "resize").pipe(operators.map(function () { return _this.getViewportSize(); }), operators.auditTime(config.viewport.resizePollingSpeed), operators.share());
682
+ this.resizeSnap$ = rxjs.fromEvent(window, "resize").pipe(operators.map(function () { return _this.getViewportSize(); }), operators.share());
683
+ this.resize$ = this.resizeSnap$.pipe(operators.auditTime(config.viewport.resizePollingSpeed), operators.share());
683
684
  }
684
685
  else {
685
- this.resize$ = rxjs.of(viewportServerSize.get());
686
+ this.resizeSnap$ = this.resize$ = rxjs.of(viewportServerSize.get());
686
687
  }
687
688
  var size = this.getViewportSize();
688
689
  this._sizeTypeSnapshot = getSizeTypeInfo(size.width, this.sizeTypes);
689
- 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));
690
- 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));
690
+ 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)); };
691
+ this.sizeSnap$ = sizeFn(this.resizeSnap$);
692
+ this.size$ = sizeFn(this.resize$);
693
+ 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)); };
694
+ this.sizeType$ = sizeTypeFn(this.size$);
695
+ this.sizeTypeSnap$ = sizeTypeFn(this.sizeSnap$);
691
696
  }
692
697
  Object.defineProperty(ViewportService.prototype, "sizeTypeSnapshot", {
693
698
  /** Viewport size type snapshot of the last value. (Prefer use `sizeType$` observable when possible.) */
@@ -854,9 +859,10 @@
854
859
  return matchViewportData(dataConfig, sizeType, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
855
860
  };
856
861
  /** Get data for match as observable. */
857
- ViewportDataService.prototype.get$ = function (dataConfig, strategy) {
862
+ ViewportDataService.prototype.get$ = function (dataConfig, strategy, throttle) {
858
863
  var _this = this;
859
- return this.viewport.sizeType$.pipe(operators.map(function (sizeType) { return _this.get(dataConfig, strategy, sizeType); }), operators.distinctUntilChanged());
864
+ if (throttle === void 0) { throttle = true; }
865
+ return (throttle ? this.viewport.sizeType$ : this.viewport.sizeTypeSnap$).pipe(operators.map(function (sizeType) { return _this.get(dataConfig, strategy, sizeType); }), operators.distinctUntilChanged());
860
866
  };
861
867
  /** Generate rules based on strategies for data. */
862
868
  ViewportDataService.prototype.generateRules = function (dataConfig, strategy) {
@@ -916,6 +922,76 @@
916
922
  { type: i0.ChangeDetectorRef }
917
923
  ]; };
918
924
 
925
+ var NAME_CAMEL = "ssvViewportMatcherVar";
926
+ var SsvViewportMatcherVarContext = /** @class */ (function () {
927
+ function SsvViewportMatcherVarContext($implicit) {
928
+ if ($implicit === void 0) { $implicit = false; }
929
+ this.$implicit = $implicit;
930
+ }
931
+ return SsvViewportMatcherVarContext;
932
+ }());
933
+ var SsvViewportMatcherVarDirective = /** @class */ (function () {
934
+ function SsvViewportMatcherVarDirective(viewport, viewContainer, templateRef) {
935
+ this.viewport = viewport;
936
+ this.viewContainer = viewContainer;
937
+ this.templateRef = templateRef;
938
+ this._matchConditions = {};
939
+ this._context = new SsvViewportMatcherVarContext();
940
+ this._destroy$ = new rxjs.Subject();
941
+ this._update$ = new rxjs.ReplaySubject(1);
942
+ }
943
+ Object.defineProperty(SsvViewportMatcherVarDirective.prototype, "condition", {
944
+ set: function (value) {
945
+ if (isViewportSizeMatcherExpression(value)) {
946
+ this._matchConditions.expression = value;
947
+ }
948
+ else if (isViewportSizeMatcherTupleExpression(value)) {
949
+ var _a = __read(value, 2), op = _a[0], size = _a[1];
950
+ this._matchConditions.expression = {
951
+ operation: op,
952
+ size: size
953
+ };
954
+ }
955
+ else {
956
+ this._matchConditions.sizeType = value;
957
+ }
958
+ this._update$.next();
959
+ },
960
+ enumerable: false,
961
+ configurable: true
962
+ });
963
+ SsvViewportMatcherVarDirective.prototype.ngOnInit = function () {
964
+ var _this = this;
965
+ this.updateView();
966
+ rxjs.combineLatest([this.viewport.sizeType$, this._update$]).pipe(operators.map(function (_a) {
967
+ var _b = __read(_a, 1), sizeType = _b[0];
968
+ return isViewportConditionMatch(sizeType, _this._matchConditions, _this.viewport.sizeTypeMap);
969
+ }), operators.tap(function (x) { return _this._context.$implicit = x; }), operators.tap(function () { return _this._viewRef.markForCheck(); }), operators.takeUntil(this._destroy$)).subscribe();
970
+ };
971
+ SsvViewportMatcherVarDirective.prototype.ngOnDestroy = function () {
972
+ this._destroy$.next();
973
+ this._destroy$.complete();
974
+ };
975
+ SsvViewportMatcherVarDirective.prototype.updateView = function () {
976
+ this.viewContainer.clear();
977
+ this._viewRef = this.viewContainer.createEmbeddedView(this.templateRef, this._context);
978
+ };
979
+ return SsvViewportMatcherVarDirective;
980
+ }());
981
+ SsvViewportMatcherVarDirective.decorators = [
982
+ { type: i0.Directive, args: [{
983
+ selector: "[" + NAME_CAMEL + "]",
984
+ },] }
985
+ ];
986
+ SsvViewportMatcherVarDirective.ctorParameters = function () { return [
987
+ { type: ViewportService },
988
+ { type: i0.ViewContainerRef },
989
+ { type: i0.TemplateRef }
990
+ ]; };
991
+ SsvViewportMatcherVarDirective.propDecorators = {
992
+ condition: [{ type: i0.Input, args: [NAME_CAMEL + "When",] }]
993
+ };
994
+
919
995
  var SsvViewportMatcherContext = /** @class */ (function () {
920
996
  function SsvViewportMatcherContext() {
921
997
  this.sizeType = null;
@@ -924,10 +1000,10 @@
924
1000
  return SsvViewportMatcherContext;
925
1001
  }());
926
1002
  var SsvViewportMatcherDirective = /** @class */ (function () {
927
- function SsvViewportMatcherDirective(viewport, renderer, _viewContainer, cdr, templateRef) {
1003
+ function SsvViewportMatcherDirective(viewport, renderer, viewContainer, cdr, templateRef) {
928
1004
  this.viewport = viewport;
929
1005
  this.renderer = renderer;
930
- this._viewContainer = _viewContainer;
1006
+ this.viewContainer = viewContainer;
931
1007
  this.cdr = cdr;
932
1008
  this._context = new SsvViewportMatcherContext();
933
1009
  this._thenTemplateRef = null;
@@ -939,44 +1015,6 @@
939
1015
  this._update$ = new rxjs.Subject();
940
1016
  this._thenTemplateRef = templateRef;
941
1017
  }
942
- SsvViewportMatcherDirective.prototype.ngOnInit = function () {
943
- var _this = this;
944
- // console.log("ssvViewportMatcher init");
945
- this._update$
946
- .pipe(
947
- // tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
948
- operators.filter(function () { return !!_this.sizeInfo; }),
949
- // tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
950
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
951
- operators.tap(function () { return _this._updateView(_this.sizeInfo); }), operators.tap(function () { return _this.cdr.markForCheck(); }))
952
- .subscribe();
953
- this.sizeType$$ = this.viewport.sizeType$
954
- .pipe(
955
- // tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
956
- operators.tap(function (x) { return _this.sizeInfo = x; }), operators.tap(function () { return _this._update$.next(_this._context); }))
957
- .subscribe();
958
- this.cssClass$$ = this.viewport.sizeType$
959
- .pipe(operators.startWith(undefined), operators.filter(function () { return !!(_this._thenViewRef || _this._elseViewRef); }), operators.pairwise(), operators.tap(function (_b) {
960
- var _c = __read(_b, 2), prev = _c[0], curr = _c[1];
961
- var _a;
962
- var el = _this._thenViewRef
963
- ? _this._thenViewRef.rootNodes[0]
964
- : (_a = _this._elseViewRef) === null || _a === void 0 ? void 0 : _a.rootNodes[0];
965
- if (!el.classList) {
966
- return;
967
- }
968
- if (prev) {
969
- _this.renderer.removeClass(el, "ssv-vp-size--" + prev.name);
970
- }
971
- _this.renderer.addClass(el, "ssv-vp-size--" + (curr === null || curr === void 0 ? void 0 : curr.name));
972
- }))
973
- .subscribe();
974
- };
975
- SsvViewportMatcherDirective.prototype.ngOnDestroy = function () {
976
- this.cssClass$$.unsubscribe();
977
- this.sizeType$$.unsubscribe();
978
- this._update$.complete();
979
- };
980
1018
  Object.defineProperty(SsvViewportMatcherDirective.prototype, "ssvViewportMatcher", {
981
1019
  set: function (value) {
982
1020
  if (isViewportSizeMatcherExpression(value)) {
@@ -1020,22 +1058,60 @@
1020
1058
  enumerable: false,
1021
1059
  configurable: true
1022
1060
  });
1061
+ SsvViewportMatcherDirective.prototype.ngOnInit = function () {
1062
+ var _this = this;
1063
+ // console.log("ssvViewportMatcher init");
1064
+ this._update$
1065
+ .pipe(
1066
+ // tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
1067
+ operators.filter(function () { return !!_this.sizeInfo; }),
1068
+ // tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
1069
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1070
+ operators.tap(function () { return _this._updateView(_this.sizeInfo); }), operators.tap(function () { return _this.cdr.markForCheck(); }))
1071
+ .subscribe();
1072
+ this.sizeType$$ = this.viewport.sizeType$
1073
+ .pipe(
1074
+ // tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
1075
+ operators.tap(function (x) { return _this.sizeInfo = x; }), operators.tap(function () { return _this._update$.next(_this._context); }))
1076
+ .subscribe();
1077
+ this.cssClass$$ = this.viewport.sizeType$
1078
+ .pipe(operators.startWith(undefined), operators.filter(function () { return !!(_this._thenViewRef || _this._elseViewRef); }), operators.pairwise(), operators.tap(function (_b) {
1079
+ var _c = __read(_b, 2), prev = _c[0], curr = _c[1];
1080
+ var _a;
1081
+ var el = _this._thenViewRef
1082
+ ? _this._thenViewRef.rootNodes[0]
1083
+ : (_a = _this._elseViewRef) === null || _a === void 0 ? void 0 : _a.rootNodes[0];
1084
+ if (!el.classList) {
1085
+ return;
1086
+ }
1087
+ if (prev) {
1088
+ _this.renderer.removeClass(el, "ssv-vp-size--" + prev.name);
1089
+ }
1090
+ _this.renderer.addClass(el, "ssv-vp-size--" + (curr === null || curr === void 0 ? void 0 : curr.name));
1091
+ }))
1092
+ .subscribe();
1093
+ };
1094
+ SsvViewportMatcherDirective.prototype.ngOnDestroy = function () {
1095
+ this.cssClass$$.unsubscribe();
1096
+ this.sizeType$$.unsubscribe();
1097
+ this._update$.complete();
1098
+ };
1023
1099
  SsvViewportMatcherDirective.prototype._updateView = function (sizeInfo) {
1024
1100
  if (isViewportConditionMatch(sizeInfo, this._context, this.viewport.sizeTypeMap)) {
1025
1101
  if (!this._thenViewRef) {
1026
- this._viewContainer.clear();
1102
+ this.viewContainer.clear();
1027
1103
  this._elseViewRef = null;
1028
1104
  if (this._thenTemplateRef) {
1029
- this._thenViewRef = this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
1105
+ this._thenViewRef = this.viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
1030
1106
  }
1031
1107
  }
1032
1108
  }
1033
1109
  else {
1034
1110
  if (!this._elseViewRef) {
1035
- this._viewContainer.clear();
1111
+ this.viewContainer.clear();
1036
1112
  this._thenViewRef = null;
1037
1113
  if (this._elseTemplateRef) {
1038
- this._elseViewRef = this._viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
1114
+ this._elseViewRef = this.viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
1039
1115
  }
1040
1116
  }
1041
1117
  }
@@ -1065,6 +1141,7 @@
1065
1141
  var MODULE_CONFIG_DATA = new i0.InjectionToken("@ssv/ngx.ux/configData");
1066
1142
  var components = [
1067
1143
  SsvViewportMatcherDirective,
1144
+ SsvViewportMatcherVarDirective,
1068
1145
  ViewportDataPipe,
1069
1146
  ];
1070
1147
  // todo: create module for Viewport
@@ -1108,7 +1185,7 @@
1108
1185
  return {};
1109
1186
  }
1110
1187
 
1111
- var VERSION = "2.0.0-dev160";
1188
+ var VERSION = "2.0.1-dev198";
1112
1189
 
1113
1190
  /**
1114
1191
  * Generated bundle index. Do not edit.
@@ -1118,6 +1195,8 @@
1118
1195
  exports.SsvUxModule = SsvUxModule;
1119
1196
  exports.SsvViewportMatcherContext = SsvViewportMatcherContext;
1120
1197
  exports.SsvViewportMatcherDirective = SsvViewportMatcherDirective;
1198
+ exports.SsvViewportMatcherVarContext = SsvViewportMatcherVarContext;
1199
+ exports.SsvViewportMatcherVarDirective = SsvViewportMatcherVarDirective;
1121
1200
  exports.UX_CONFIG = UX_CONFIG;
1122
1201
  exports.UX_DEFAULT_CONFIG = UX_DEFAULT_CONFIG;
1123
1202
  exports.UX_VIEWPORT_DEFAULT_BREAKPOINTS = UX_VIEWPORT_DEFAULT_BREAKPOINTS;