brew-js-react 0.5.5 → 0.5.6

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/brew.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare namespace Brew {
2
+ interface PageEvent {
3
+ /**
4
+ * Returns the view component associated to target.
5
+ * The property is only available in `pageenter` or `pageleave event.
6
+ */
7
+ readonly view?: import("./view").ViewComponent<any>;
8
+ }
9
+ }
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.5.5 | (c) misonou | https://misonou.github.io */
1
+ /*! brew-js-react v0.5.6 | (c) misonou | https://misonou.github.io */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("zeta-dom"), require("react"), require("react-dom"), require("brew-js"), require("zeta-dom-react"), require("waterpipe"), require("jquery"));
@@ -205,6 +205,7 @@ __webpack_require__.d(__webpack_exports__, {
205
205
  useLoadingStateMixin: () => (/* reexport */ useLoadingStateMixin),
206
206
  useMixin: () => (/* reexport */ useMixin),
207
207
  useMixinRef: () => (/* reexport */ useMixinRef),
208
+ useQueryParam: () => (/* reexport */ useQueryParam),
208
209
  useRouteParam: () => (/* reexport */ useRouteParam),
209
210
  useRouteState: () => (/* reexport */ useRouteState),
210
211
  useScrollIntoViewMixin: () => (/* reexport */ useScrollIntoViewMixin),
@@ -250,6 +251,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
250
251
  makeArray = _lib$util.makeArray,
251
252
  makeAsync = _lib$util.makeAsync,
252
253
  map = _lib$util.map,
254
+ mapObject = _lib$util.mapObject,
253
255
  noop = _lib$util.noop,
254
256
  pick = _lib$util.pick,
255
257
  pipe = _lib$util.pipe,
@@ -295,7 +297,6 @@ var external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_ = __webpa
295
297
  ;// CONCATENATED MODULE: ./|umd|/brew-js/domAction.js
296
298
 
297
299
  var closeFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.closeFlyout,
298
- isFlyoutOpen = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isFlyoutOpen,
299
300
  openFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.openFlyout,
300
301
  toggleFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toggleFlyout;
301
302
 
@@ -402,6 +403,16 @@ var external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react
402
403
 
403
404
  var EventContainer = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.EventContainer;
404
405
 
406
+ ;// CONCATENATED MODULE: ./|umd|/brew-js/util/common.js
407
+
408
+ var getQueryParam = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.getQueryParam,
409
+ setQueryParam = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.setQueryParam;
410
+
411
+ ;// CONCATENATED MODULE: ./|umd|/brew-js/util/path.js
412
+
413
+ var parsePath = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.parsePath,
414
+ removeQueryAndHash = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.removeQueryAndHash;
415
+
405
416
  ;// CONCATENATED MODULE: ./|umd|/brew-js/app.js
406
417
 
407
418
  /* harmony default export */ const app = ((/* unused pure expression or super */ null && (lib)));
@@ -433,10 +444,6 @@ brew_js_defaults.react = true;
433
444
  var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.animateIn,
434
445
  animateOut = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.animateOut;
435
446
 
436
- ;// CONCATENATED MODULE: ./|umd|/brew-js/util/path.js
437
-
438
- var removeQueryAndHash = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.removeQueryAndHash;
439
-
440
447
  ;// CONCATENATED MODULE: ./src/view.js
441
448
 
442
449
 
@@ -531,6 +538,8 @@ definePrototype(ErrorBoundary, external_commonjs_react_commonjs2_react_amd_react
531
538
  error: error
532
539
  }, true);
533
540
  });
541
+ // ensure promise sent to beforepageload event is resolved
542
+ self.props.onComponentLoaded();
534
543
  }
535
544
  },
536
545
  render: function render() {
@@ -599,7 +608,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
599
608
  if (V && (viewChanged || !(self.children || '')[0])) {
600
609
  // ensure the current path actually corresponds to the matched view
601
610
  // when some views are not included in the list of allowed views
602
- var targetPath = resolvePath(V, getCurrentParams(V, true));
611
+ var targetPath = resolvePath(V, app_app.route);
603
612
  if (targetPath !== removeQueryAndHash(app_app.path)) {
604
613
  app_app.navigate(targetPath, true);
605
614
  return;
@@ -620,7 +629,8 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
620
629
  unmountView = function unmountView() {
621
630
  self.prevView = self.currentView;
622
631
  app_app.emit('pageleave', element, {
623
- pathname: state.page.path
632
+ pathname: state.page.path,
633
+ view: V
624
634
  }, true);
625
635
  animateOut(element, 'show').then(function () {
626
636
  self.prevView = undefined;
@@ -629,7 +639,8 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
629
639
  };
630
640
  animateIn(element, 'show', '[brew-view]', true);
631
641
  app_app.emit('pageenter', element, {
632
- pathname: state.page.path
642
+ pathname: state.page.path,
643
+ view: V
633
644
  }, true);
634
645
  }
635
646
  });
@@ -670,7 +681,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
670
681
  return any(props.views, isViewMatched) || props.defaultView;
671
682
  }
672
683
  });
673
- function getCurrentParams(view, includeAll, params) {
684
+ function getCurrentParams(view, params) {
674
685
  var state = routeMap.get(view);
675
686
  if (!state.maxParams) {
676
687
  var matchers = exclude(state.matchers, ['remainingSegments']);
@@ -701,7 +712,7 @@ function getCurrentParams(view, includeAll, params) {
701
712
  });
702
713
  }
703
714
  }
704
- return pick(params || app_app.route, includeAll ? state.maxParams : state.minParams);
715
+ return extend(pick(app_app.route, state.minParams), params && pick(params, state.maxParams), state.params);
705
716
  }
706
717
  function sortViews(a, b) {
707
718
  return (routeMap.get(b) || {}).matchCount - (routeMap.get(a) || {}).matchCount;
@@ -732,11 +743,14 @@ function createViewComponent(factory) {
732
743
  return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(s["default"], viewProps);
733
744
  });
734
745
  }, !!promise)[1];
735
- if (!promise || !state.loading) {
736
- props.onComponentLoaded();
737
- if (state.error) {
738
- throw state.error;
746
+ var loaded = !promise || !state.loading;
747
+ external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect(function () {
748
+ if (loaded) {
749
+ setImmediate(props.onComponentLoaded);
739
750
  }
751
+ }, [loaded]);
752
+ if (state.error) {
753
+ throw state.error;
740
754
  }
741
755
  return children || state.value || /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment);
742
756
  };
@@ -803,12 +817,10 @@ function renderView() {
803
817
  });
804
818
  }
805
819
  function resolvePath(view, params) {
806
- var state = routeMap.get(view);
807
- if (!state) {
820
+ if (!routeMap.has(view)) {
808
821
  return '/';
809
822
  }
810
- var newParams = extend(getCurrentParams(view), getCurrentParams(view, true, params || {}), state.params);
811
- return app_app.route.getPath(newParams);
823
+ return app_app.route.getPath(getCurrentParams(view, params));
812
824
  }
813
825
  function linkTo(view, params) {
814
826
  return app_app.toHref(resolvePath(view, params));
@@ -827,6 +839,8 @@ function redirectTo(view, params, data) {
827
839
 
828
840
 
829
841
 
842
+
843
+
830
844
  var hooks_emitter = new EventContainer();
831
845
  function getCurrentStates() {
832
846
  return app_app.historyStorage.current;
@@ -932,6 +946,58 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
932
946
  }
933
947
  return state;
934
948
  }
949
+ function useQueryParam(key, value, snapshotOnUpdate) {
950
+ if (isPlainObject(key)) {
951
+ snapshotOnUpdate = value;
952
+ value = key;
953
+ key = false;
954
+ }
955
+ var container = useViewContext();
956
+ var getParams = function getParams() {
957
+ return mapObject(key === false ? value : kv(key, value), function (v, i) {
958
+ return getQueryParam(i, app_app.path) || v || '';
959
+ });
960
+ };
961
+ var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)([]);
962
+ (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useMemo)(function () {
963
+ state[0].splice(0, 2, getParams());
964
+ }, [key]);
965
+ var current = state[0][0];
966
+ var trackChanges = function trackChanges(values) {
967
+ if (!equal(values, current)) {
968
+ extend(current, values);
969
+ state[1]([current]);
970
+ }
971
+ };
972
+ var setParams = (0,external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useMemoizedFunction)(function (values) {
973
+ if (key !== false) {
974
+ values = kv(key, isFunction(values) ? values(current[key]) : values);
975
+ } else if (isFunction(values)) {
976
+ values = values(extend({}, current));
977
+ }
978
+ if (container.active) {
979
+ var url = parsePath(app_app.path);
980
+ var search = util_keys(values).reduce(function (v, i) {
981
+ return values[i] !== current[i] ? setQueryParam(i, values[i] || null, v) : v;
982
+ }, url.search);
983
+ if (search !== url.search) {
984
+ if (snapshotOnUpdate) {
985
+ app_app.snapshot();
986
+ }
987
+ catchAsync(app_app.navigate(search + url.hash, true));
988
+ trackChanges(getParams());
989
+ }
990
+ }
991
+ });
992
+ (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
993
+ return app_app.watch('path', function () {
994
+ if (container.active) {
995
+ trackChanges(getParams());
996
+ }
997
+ });
998
+ }, [key]);
999
+ return [key !== false ? current[key] : state[0][1] || (state[0][1] = freeze(extend({}, current))), setParams];
1000
+ }
935
1001
  function ViewStateContainer(props) {
936
1002
  var cache = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)({})[0];
937
1003
  var container = useViewContextWithEffect(function (cur) {
@@ -1450,11 +1516,7 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1450
1516
  });
1451
1517
  },
1452
1518
  open: function open(value, source) {
1453
- var element = this.elements()[0];
1454
- if (!isFlyoutOpen(element)) {
1455
- valueMap.set(element, value);
1456
- }
1457
- return openFlyout(element, source, this.getOptions());
1519
+ return openFlyout(this.elements()[0], value, source, this.getOptions());
1458
1520
  },
1459
1521
  close: function close(value) {
1460
1522
  return closeFlyout(this.elements()[0], value);
@@ -1477,6 +1539,17 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1477
1539
  var self = this;
1478
1540
  FlyoutMixinSuper.initElement.call(self, element, state);
1479
1541
  self.onDispose(app_app.on(element, {
1542
+ flyoutshow: function flyoutshow(e) {
1543
+ valueMap.set(element, e.data);
1544
+ self.isFlyoutOpened = true;
1545
+ self.visible = true;
1546
+ },
1547
+ flyoutclose: function flyoutclose() {
1548
+ self.isFlyoutOpened = false;
1549
+ },
1550
+ flyouthide: function flyouthide() {
1551
+ self.visible = false;
1552
+ },
1480
1553
  animationstart: function animationstart() {
1481
1554
  self.animating = true;
1482
1555
  },
@@ -1484,15 +1557,6 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1484
1557
  self.animating = false;
1485
1558
  }
1486
1559
  }, true));
1487
- },
1488
- onClassNameUpdated: function onClassNameUpdated(element, prevState, state) {
1489
- var self = this;
1490
- var isFlyoutOpened = isFlyoutOpen(element);
1491
- if (!isFlyoutOpened) {
1492
- valueMap["delete"](element);
1493
- }
1494
- self.visible = state.open;
1495
- self.isFlyoutOpened = isFlyoutOpened;
1496
1560
  }
1497
1561
  });
1498
1562
  ;// CONCATENATED MODULE: ./src/mixins/FocusStateMixin.js