brew-js-react 0.2.3 → 0.2.4

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),
@@ -525,6 +526,7 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
525
526
  var view_root = zeta_dom_dom.root;
526
527
  var routeMap = new Map();
527
528
  var usedParams = {};
529
+ var sortedViews = [];
528
530
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
529
531
  active: true
530
532
  }));
@@ -588,7 +590,9 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
588
590
 
589
591
  var providerProps = {
590
592
  key: routeMap.get(V).id,
591
- value: {}
593
+ value: {
594
+ view: V
595
+ }
592
596
  };
593
597
  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, {
594
598
  rootProps: self.props.rootProps,
@@ -634,7 +638,6 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
634
638
 
635
639
  if (targetPath !== app_app.path) {
636
640
  app_app.navigate(targetPath, true);
637
- return;
638
641
  }
639
642
  }
640
643
 
@@ -642,13 +645,14 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
642
645
  }
643
646
  });
644
647
 
645
- function getCurrentParams(view, includeAll) {
648
+ function getCurrentParams(view, includeAll, params) {
646
649
  var state = routeMap.get(view);
647
650
 
648
651
  if (!state.maxParams) {
652
+ var matchers = exclude(state.matchers, ['remainingSegments']);
649
653
  var matched = map(app_app.routes, function (v) {
650
654
  var route = app_app.parseRoute(v);
651
- var matched = route.length && !any(state.matchers, function (v, i) {
655
+ var matched = route.length && !any(matchers, function (v, i) {
652
656
  var pos = route.params[i];
653
657
  return (v ? !(pos >= 0) : pos < route.minLength) || !isFunction(v) && !route.match(i, v);
654
658
  });
@@ -657,8 +661,8 @@ function getCurrentParams(view, includeAll) {
657
661
 
658
662
  if (matched[1]) {
659
663
  matched = grep(matched, function (v) {
660
- return !any(v.params, function (v, i) {
661
- return usedParams[i] && !state.matchers[i];
664
+ return !single(v.params, function (v, i) {
665
+ return usedParams[i] && !matchers[i];
662
666
  });
663
667
  });
664
668
  }
@@ -674,19 +678,41 @@ function getCurrentParams(view, includeAll) {
674
678
  }
675
679
  }
676
680
 
677
- return pick(app_app.route, includeAll ? state.maxParams : state.minParams);
681
+ return pick(params || app_app.route, includeAll ? state.maxParams : state.minParams);
678
682
  }
679
683
 
680
- function useViewContainerState() {
681
- return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
684
+ function sortViews(a, b) {
685
+ return (routeMap.get(b) || {}).matchCount - (routeMap.get(a) || {}).matchCount;
682
686
  }
683
- function isViewMatched(view) {
687
+
688
+ function matchViewParams(view, route) {
684
689
  var params = routeMap.get(view);
685
- return !!params && false === any(params.matchers, function (v, i) {
686
- var value = app_app.route[i] || '';
690
+ return !!params && !single(params.matchers, function (v, i) {
691
+ var value = route[i] || '';
687
692
  return isFunction(v) ? !v(value) : (v || '') !== value;
688
693
  });
689
694
  }
695
+
696
+ function useViewContainerState() {
697
+ return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
698
+ }
699
+ function isViewMatched(view) {
700
+ return matchViewParams(view, app_app.route);
701
+ }
702
+ function matchView(path, views) {
703
+ var route = app_app.route;
704
+
705
+ if (typeof path === 'string') {
706
+ route = route.parse(path);
707
+ } else {
708
+ views = path;
709
+ }
710
+
711
+ views = views ? makeArray(views).sort(sortViews) : sortedViews;
712
+ return any(views, function (v) {
713
+ return matchViewParams(v, route);
714
+ }) || undefined;
715
+ }
690
716
  function registerView(factory, routeParams) {
691
717
  var Component = function Component(props) {
692
718
  var state = (0,external_zeta_dom_react_.useAsync)(factory);
@@ -718,15 +744,15 @@ function registerView(factory, routeParams) {
718
744
  return typeof v === 'string';
719
745
  })
720
746
  });
747
+ sortedViews.push(Component);
748
+ sortedViews.sort(sortViews);
721
749
  return Component;
722
750
  }
723
751
  function renderView() {
724
752
  var views = makeArray(arguments);
725
753
  var rootProps = isFunction(views[0]) ? {} : views.shift();
726
754
  var defaultView = views[0];
727
- views.sort(function (a, b) {
728
- return (routeMap.get(b) || {}).matchCount - (routeMap.get(a) || {}).matchCount;
729
- });
755
+ views.sort(sortViews);
730
756
  return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewContainer, {
731
757
  rootProps: rootProps,
732
758
  views: views,
@@ -740,7 +766,7 @@ function linkTo(view, params) {
740
766
  return '/';
741
767
  }
742
768
 
743
- var newParams = extend(getCurrentParams(view), params, state.params);
769
+ var newParams = extend(getCurrentParams(view), getCurrentParams(view, true, params), state.params);
744
770
  return app_app.route.getPath(newParams);
745
771
  }
746
772
  function navigateTo(view, params) {