brew-js-react 0.2.2 → 0.2.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.
@@ -181,6 +181,7 @@ __webpack_require__.d(src_namespaceObject, {
181
181
  "isViewMatched": () => (isViewMatched),
182
182
  "linkTo": () => (linkTo),
183
183
  "makeTranslation": () => (makeTranslation),
184
+ "matchView": () => (matchView),
184
185
  "navigateTo": () => (navigateTo),
185
186
  "redirectTo": () => (redirectTo),
186
187
  "registerView": () => (registerView),
@@ -243,8 +244,10 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
243
244
  any = _lib$util.any,
244
245
  single = _lib$util.single,
245
246
  kv = _lib$util.kv,
247
+ fill = _lib$util.fill,
246
248
  pick = _lib$util.pick,
247
249
  exclude = _lib$util.exclude,
250
+ mapObject = _lib$util.mapObject,
248
251
  mapGet = _lib$util.mapGet,
249
252
  mapRemove = _lib$util.mapRemove,
250
253
  arrRemove = _lib$util.arrRemove,
@@ -261,7 +264,8 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
261
264
  setImmediateOnce = _lib$util.setImmediateOnce,
262
265
  throwNotFunction = _lib$util.throwNotFunction,
263
266
  errorWithCode = _lib$util.errorWithCode,
264
- keys = _lib$util.keys,
267
+ isErrorWithCode = _lib$util.isErrorWithCode,
268
+ util_keys = _lib$util.keys,
265
269
  values = _lib$util.values,
266
270
  util_hasOwnProperty = _lib$util.hasOwnProperty,
267
271
  getOwnPropertyDescriptors = _lib$util.getOwnPropertyDescriptors,
@@ -513,6 +517,19 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
513
517
 
514
518
  ;// CONCATENATED MODULE: ./src/include/brew-js/anim.js
515
519
 
520
+ ;// CONCATENATED MODULE: ./tmp/brew-js/util/path.js
521
+
522
+ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.setBaseUrl,
523
+ combinePath = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.combinePath,
524
+ normalizePath = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.normalizePath,
525
+ removeQueryAndHash = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.removeQueryAndHash,
526
+ withBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.withBaseUrl,
527
+ toAbsoluteUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toAbsoluteUrl,
528
+ toRelativeUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toRelativeUrl,
529
+ isSubPathOf = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isSubPathOf;
530
+
531
+ ;// CONCATENATED MODULE: ./src/include/brew-js/util/path.js
532
+
516
533
  ;// CONCATENATED MODULE: ./src/view.js
517
534
 
518
535
 
@@ -522,9 +539,11 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
522
539
 
523
540
 
524
541
 
542
+
525
543
  var view_root = zeta_dom_dom.root;
526
544
  var routeMap = new Map();
527
545
  var usedParams = {};
546
+ var sortedViews = [];
528
547
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
529
548
  active: true
530
549
  }));
@@ -545,6 +564,7 @@ function ViewContainer() {
545
564
 
546
565
  self.componentWillUnmount = app_app.on('navigate', function () {
547
566
  if (self.mounted && self.getViewComponent()) {
567
+ self.isForceUpdate = true;
548
568
  self.forceUpdate();
549
569
  }
550
570
  });
@@ -587,7 +607,9 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
587
607
 
588
608
  var providerProps = {
589
609
  key: routeMap.get(V).id,
590
- value: {}
610
+ value: {
611
+ view: V
612
+ }
591
613
  };
592
614
  var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, providerProps, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
593
615
  rootProps: self.props.rootProps,
@@ -609,9 +631,13 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
609
631
  self.currentPath = app_app.path;
610
632
  self.currentView = view;
611
633
  } else {
612
- app_app.emit('pageenter', self.currentElement, {
613
- pathname: app_app.path
614
- }, true);
634
+ if (self.isForceUpdate) {
635
+ self.isForceUpdate = false;
636
+ app_app.emit('pageenter', self.currentElement, {
637
+ pathname: app_app.path
638
+ }, true);
639
+ }
640
+
615
641
  resolve();
616
642
  }
617
643
 
@@ -620,19 +646,90 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
620
646
  },
621
647
  getViewComponent: function getViewComponent() {
622
648
  var props = this.props;
623
- return any(props.views, isViewMatched) || history.state === stateId && void redirectTo(props.defaultView);
649
+ var matched = any(props.views, isViewMatched) || props.defaultView;
650
+
651
+ if (history.state === stateId) {
652
+ // ensure the current path actually corresponds to the matched view
653
+ // when some views are not included in the list of allowed views
654
+ var targetPath = linkTo(matched, getCurrentParams(matched, true));
655
+
656
+ if (targetPath !== removeQueryAndHash(app_app.path)) {
657
+ app_app.navigate(targetPath, true);
658
+ }
659
+ }
660
+
661
+ return matched;
624
662
  }
625
663
  });
626
- function useViewContainerState() {
627
- return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
664
+
665
+ function getCurrentParams(view, includeAll, params) {
666
+ var state = routeMap.get(view);
667
+
668
+ if (!state.maxParams) {
669
+ var matchers = exclude(state.matchers, ['remainingSegments']);
670
+ var matched = map(app_app.routes, function (v) {
671
+ var route = app_app.parseRoute(v);
672
+ var matched = route.length && !any(matchers, function (v, i) {
673
+ var pos = route.params[i];
674
+ return (v ? !(pos >= 0) : pos < route.minLength) || !isFunction(v) && !route.match(i, v);
675
+ });
676
+ return matched ? route : null;
677
+ });
678
+
679
+ if (matched[1]) {
680
+ matched = grep(matched, function (v) {
681
+ return !single(v.params, function (v, i) {
682
+ return usedParams[i] && !matchers[i];
683
+ });
684
+ });
685
+ }
686
+
687
+ if (matched[0]) {
688
+ var last = matched.slice(-1)[0];
689
+ state.maxParams = util_keys(extend.apply(0, [{}].concat(matched.map(function (v) {
690
+ return v.params;
691
+ }))));
692
+ state.minParams = map(last.params, function (v, i) {
693
+ return state.params[i] || v >= last.minLength ? null : i;
694
+ });
695
+ }
696
+ }
697
+
698
+ return pick(params || app_app.route, includeAll ? state.maxParams : state.minParams);
628
699
  }
629
- function isViewMatched(view) {
700
+
701
+ function sortViews(a, b) {
702
+ return (routeMap.get(b) || {}).matchCount - (routeMap.get(a) || {}).matchCount;
703
+ }
704
+
705
+ function matchViewParams(view, route) {
630
706
  var params = routeMap.get(view);
631
- return !!params && false === any(params.matchers, function (v, i) {
632
- var value = app_app.route[i] || '';
707
+ return !!params && !single(params.matchers, function (v, i) {
708
+ var value = route[i] || '';
633
709
  return isFunction(v) ? !v(value) : (v || '') !== value;
634
710
  });
635
711
  }
712
+
713
+ function useViewContainerState() {
714
+ return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
715
+ }
716
+ function isViewMatched(view) {
717
+ return matchViewParams(view, app_app.route);
718
+ }
719
+ function matchView(path, views) {
720
+ var route = app_app.route;
721
+
722
+ if (typeof path === 'string') {
723
+ route = route.parse(path);
724
+ } else {
725
+ views = path;
726
+ }
727
+
728
+ views = views ? makeArray(views).sort(sortViews) : sortedViews;
729
+ return any(views, function (v) {
730
+ return matchViewParams(v, route);
731
+ }) || undefined;
732
+ }
636
733
  function registerView(factory, routeParams) {
637
734
  var Component = function Component(props) {
638
735
  var state = (0,external_zeta_dom_react_.useAsync)(factory);
@@ -658,21 +755,21 @@ function registerView(factory, routeParams) {
658
755
  });
659
756
  routeMap.set(Component, {
660
757
  id: randomId(),
661
- matchCount: keys(routeParams).length,
758
+ matchCount: util_keys(routeParams).length,
662
759
  matchers: routeParams,
663
760
  params: pick(routeParams, function (v) {
664
761
  return typeof v === 'string';
665
762
  })
666
763
  });
764
+ sortedViews.push(Component);
765
+ sortedViews.sort(sortViews);
667
766
  return Component;
668
767
  }
669
768
  function renderView() {
670
769
  var views = makeArray(arguments);
671
770
  var rootProps = isFunction(views[0]) ? {} : views.shift();
672
771
  var defaultView = views[0];
673
- views.sort(function (a, b) {
674
- return (routeMap.get(b) || {}).matchCount - (routeMap.get(a) || {}).matchCount;
675
- });
772
+ views.sort(sortViews);
676
773
  return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewContainer, {
677
774
  rootProps: rootProps,
678
775
  views: views,
@@ -680,19 +777,13 @@ function renderView() {
680
777
  });
681
778
  }
682
779
  function linkTo(view, params) {
683
- var viewParams = (routeMap.get(view) || {}).params;
684
- var newParams = {};
685
-
686
- for (var i in app_app.route) {
687
- if (viewParams && i in viewParams) {
688
- newParams[i] = viewParams[i];
689
- } else if (params && i in params) {
690
- newParams[i] = params[i];
691
- } else if (!usedParams[i]) {
692
- newParams[i] = app_app.route[i];
693
- }
780
+ var state = routeMap.get(view);
781
+
782
+ if (!state) {
783
+ return '/';
694
784
  }
695
785
 
786
+ var newParams = extend(getCurrentParams(view), getCurrentParams(view, true, params), state.params);
696
787
  return app_app.route.getPath(newParams);
697
788
  }
698
789
  function navigateTo(view, params) {
@@ -715,7 +806,8 @@ function getCurrentStates() {
715
806
  return states[history.state] || (states[history.state] = {});
716
807
  }
717
808
 
718
- function ViewState(value) {
809
+ function ViewState(key, value) {
810
+ this.key = key;
719
811
  this.value = value;
720
812
  }
721
813
 
@@ -797,20 +889,21 @@ function ViewStateContainer(props) {
797
889
  return {
798
890
  getState: function getState(uniqueId, key) {
799
891
  var cur = getCurrentStates();
800
- var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(cur[key] && cur[key].value));
892
+ var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(key, cur[key] && cur[key].value));
801
893
 
802
894
  if (container.active) {
803
895
  var stateId = state.stateId;
804
896
 
805
- if (stateId && stateId !== history.state) {
897
+ if (stateId && (stateId !== history.state || key !== state.key)) {
806
898
  var newValue = cur[key] && cur[key].value;
807
899
  emitter.emit('popstate', state, {
808
900
  newValue: newValue
809
901
  }); // detach value in previous history state from current one
810
902
 
811
- var previous = new ViewState(state.value);
812
- states[stateId][key] = previous;
903
+ var previous = new ViewState(state.key, state.value);
904
+ states[stateId][previous.key] = previous;
813
905
  state.value = newValue;
906
+ state.key = key;
814
907
  }
815
908
 
816
909
  state.stateId = history.state;
@@ -918,7 +1011,10 @@ function makeTranslation(resources, defaultLang) {
918
1011
  return {
919
1012
  translate: cache[''],
920
1013
  getTranslation: getTranslationCallback,
921
- useTranslation: useTranslation
1014
+ useTranslation: useTranslation,
1015
+ keys: function keys(prefix) {
1016
+ return util_keys(resources[defaultLang][prefix] || empty);
1017
+ }
922
1018
  };
923
1019
  }
924
1020
  ;// CONCATENATED MODULE: ./src/mixins/StaticAttributeMixin.js
@@ -1016,6 +1112,7 @@ function StatefulMixin() {
1016
1112
  Mixin.call(this);
1017
1113
 
1018
1114
  _(this, {
1115
+ elements: new WeakSet(),
1019
1116
  states: {},
1020
1117
  prefix: '',
1021
1118
  counter: 0
@@ -1048,8 +1145,9 @@ definePrototype(StatefulMixin, Mixin, {
1048
1145
  var self = this;
1049
1146
  var state = self.state;
1050
1147
  return function (current) {
1051
- if (current && current !== state.element) {
1052
- state.element = current;
1148
+ state.element = current;
1149
+
1150
+ if (current && setAdd(_(self).elements, current)) {
1053
1151
  self.initElement(current, state);
1054
1152
  }
1055
1153
  };
@@ -1068,13 +1166,13 @@ definePrototype(StatefulMixin, Mixin, {
1068
1166
  },
1069
1167
  initElement: function initElement(element, state) {},
1070
1168
  clone: function clone() {
1071
- var clone = inherit(Object.getPrototypeOf(this));
1169
+ var self = this;
1170
+ var clone = inherit(Object.getPrototypeOf(self), self);
1072
1171
 
1073
- _(clone, {
1074
- states: _(this).states,
1172
+ _(clone, extend({}, _(self), {
1075
1173
  prefix: randomId() + '.',
1076
1174
  counter: 0
1077
- });
1175
+ }));
1078
1176
 
1079
1177
  return clone;
1080
1178
  },
@@ -1143,11 +1241,6 @@ definePrototype(ClassNameMixin, StatefulMixin, {
1143
1241
  }
1144
1242
  });
1145
1243
  },
1146
- clone: function clone() {
1147
- return extend(ClassNameMixinSuper.clone.call(this), {
1148
- classNames: this.classNames
1149
- });
1150
- },
1151
1244
  onClassNameUpdated: function onClassNameUpdated(element, prevState, state) {}
1152
1245
  });
1153
1246
  ;// CONCATENATED MODULE: ./src/mixins/AnimateMixin.js
@@ -1275,16 +1368,17 @@ function FlyoutToggleMixin(mixin) {
1275
1368
  this.flyoutMixin = mixin;
1276
1369
  }
1277
1370
  definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1371
+ open: function open(value) {
1372
+ return this.flyoutMixin.open(value);
1373
+ },
1374
+ close: function close(value) {
1375
+ return this.flyoutMixin.close(value);
1376
+ },
1278
1377
  getCustomAttributes: function getCustomAttributes() {
1279
1378
  var element = this.flyoutMixin.elements()[0];
1280
1379
  return extend({}, FlyoutToggleMixinSuper.getCustomAttributes.call(this), {
1281
1380
  'toggle': element && '#' + element.id
1282
1381
  });
1283
- },
1284
- clone: function clone() {
1285
- return extend(FlyoutToggleMixinSuper.clone.call(this), {
1286
- flyoutMixin: this.flyoutMixin
1287
- });
1288
1382
  }
1289
1383
  });
1290
1384
  ;// CONCATENATED MODULE: ./src/mixins/FlyoutMixin.js
@@ -1292,11 +1386,13 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1292
1386
 
1293
1387
 
1294
1388
 
1389
+
1295
1390
  var FlyoutMixinSuper = ClassNameMixin.prototype;
1391
+ var valueMap = new WeakMap();
1296
1392
  var flyoutMixinCounter = 0;
1297
1393
  function FlyoutMixin() {
1298
1394
  var self = this;
1299
- ClassNameMixin.call(self, ['open', 'closing', 'tweening-in', 'tweening-out']);
1395
+ ClassNameMixin.call(self, ['open', 'closing', 'visible', 'tweening-in', 'tweening-out']);
1300
1396
  self.modal = false;
1301
1397
  self.tabThrough = false;
1302
1398
  self.isFlyoutOpened = false;
@@ -1332,10 +1428,19 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1332
1428
  'animate-out': ''
1333
1429
  });
1334
1430
  },
1431
+ open: function open(value) {
1432
+ var element = this.elements()[0];
1433
+ valueMap.set(element, value);
1434
+ return openFlyout(element);
1435
+ },
1436
+ close: function close(value) {
1437
+ return closeFlyout(this.elements()[0], value);
1438
+ },
1335
1439
  onOpen: function onOpen(callback) {
1440
+ var element = this.elements()[0];
1336
1441
  return this.onToggleState(function (opened) {
1337
1442
  if (opened) {
1338
- return callback();
1443
+ return callback(valueMap.get(element));
1339
1444
  }
1340
1445
  });
1341
1446
  },