brew-js-react 0.4.1 → 0.4.2

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.
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.4.1 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
1
+ /*! brew-js-react v0.4.2 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("brew-js"), require("react"), require("react-dom"), (function webpackLoadOptionalExternalModule() { try { return require("react-dom/client"); } catch(e) {} }()), require("zeta-dom"), require("zeta-dom-react"), require("waterpipe"), require("jQuery"));
@@ -196,6 +196,7 @@ __webpack_require__.d(src_namespaceObject, {
196
196
  "FocusStateMixin": () => (FocusStateMixin),
197
197
  "LoadingStateMixin": () => (LoadingStateMixin),
198
198
  "Mixin": () => (Mixin),
199
+ "ScrollIntoViewMixin": () => (ScrollIntoViewMixin),
199
200
  "ScrollableMixin": () => (ScrollableMixin),
200
201
  "StatefulMixin": () => (StatefulMixin),
201
202
  "ViewStateContainer": () => (ViewStateContainer),
@@ -223,8 +224,10 @@ __webpack_require__.d(src_namespaceObject, {
223
224
  "useMixinRef": () => (useMixinRef),
224
225
  "useRouteParam": () => (useRouteParam),
225
226
  "useRouteState": () => (useRouteState),
227
+ "useScrollIntoViewMixin": () => (useScrollIntoViewMixin),
226
228
  "useScrollableMixin": () => (useScrollableMixin),
227
- "useViewContainerState": () => (useViewContainerState)
229
+ "useViewContainerState": () => (useViewContext),
230
+ "useViewContext": () => (useViewContext)
228
231
  });
229
232
 
230
233
  // EXTERNAL MODULE: external {"commonjs":"brew-js","commonjs2":"brew-js","amd":"brew-js","root":"brew"}
@@ -364,6 +367,7 @@ var domUtil_lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_do
364
367
  removeNode = domUtil_lib$util.removeNode,
365
368
  getClass = domUtil_lib$util.getClass,
366
369
  setClass = domUtil_lib$util.setClass,
370
+ getSafeAreaInset = domUtil_lib$util.getSafeAreaInset,
367
371
  getScrollOffset = domUtil_lib$util.getScrollOffset,
368
372
  getScrollParent = domUtil_lib$util.getScrollParent,
369
373
  getContentRect = domUtil_lib$util.getContentRect,
@@ -584,10 +588,13 @@ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_br
584
588
 
585
589
 
586
590
 
591
+
592
+
587
593
  var root = zeta_dom_dom.root;
588
594
  var routeMap = new Map();
589
595
  var usedParams = {};
590
596
  var sortedViews = [];
597
+ var emitter = new ZetaEventContainer();
591
598
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
592
599
  container: root,
593
600
  active: true
@@ -602,6 +609,16 @@ onAppInit(function () {
602
609
  });
603
610
  });
604
611
 
612
+ function ViewContext(view) {
613
+ defineOwnProperty(this, 'view', view, true);
614
+ }
615
+
616
+ definePrototype(ViewContext, {
617
+ on: function on(event, handler) {
618
+ return emitter.add(this, event, handler);
619
+ }
620
+ });
621
+
605
622
  function ErrorBoundary() {
606
623
  external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
607
624
  this.state = {};
@@ -726,13 +743,12 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
726
743
  });
727
744
  notifyAsync(element, promise);
728
745
  });
746
+ var state = new ViewContext(V);
729
747
  var viewProps = freeze({
730
748
  navigationType: view_event.navigationType,
749
+ viewContext: state,
731
750
  viewData: view_event.data || {}
732
751
  });
733
- var state = {
734
- view: V
735
- };
736
752
  var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, {
737
753
  key: routeMap.get(V).id,
738
754
  value: state
@@ -746,10 +762,18 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
746
762
  currentPath: app_app.path,
747
763
  currentView: view,
748
764
  currentViewComponent: V,
765
+ setPage: defineObservableProperty(state, 'page', app_app.page, true),
749
766
  setActive: defineObservableProperty(state, 'active', true, true)
750
767
  });
768
+ watch(state, 'page', function (page, previousPage) {
769
+ emitter.emit('pagechange', state, {
770
+ previousPage: previousPage
771
+ });
772
+ });
751
773
  (view_event.waitFor || noop)(promise);
752
774
  }
775
+
776
+ (self.setPage || noop)(app_app.page);
753
777
  },
754
778
  getViewComponent: function getViewComponent() {
755
779
  var props = this.props;
@@ -842,7 +866,7 @@ function createViewComponent(factory) {
842
866
  };
843
867
  }
844
868
 
845
- function useViewContainerState() {
869
+ function useViewContext() {
846
870
  return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
847
871
  }
848
872
  function isViewMatched(view) {
@@ -922,6 +946,7 @@ function navigateTo(view, params, data, replace) {
922
946
  function redirectTo(view, params, data) {
923
947
  return navigateTo(view, params, data, true);
924
948
  }
949
+
925
950
  ;// CONCATENATED MODULE: ./src/hooks.js
926
951
 
927
952
 
@@ -930,7 +955,7 @@ function redirectTo(view, params, data) {
930
955
 
931
956
 
932
957
 
933
- var emitter = new ZetaEventContainer();
958
+ var hooks_emitter = new ZetaEventContainer();
934
959
 
935
960
  function getCurrentStates() {
936
961
  return app_app.historyStorage.current;
@@ -952,7 +977,7 @@ definePrototype(ViewState, {
952
977
  },
953
978
  onPopState: function onPopState(callback) {
954
979
  throwNotFunction(callback);
955
- return emitter.add(this, 'popstate', function (e) {
980
+ return hooks_emitter.add(this, 'popstate', function (e) {
956
981
  callback.call(this, e.newValue);
957
982
  });
958
983
  }
@@ -968,7 +993,7 @@ function useAppReadyState() {
968
993
  };
969
994
  }
970
995
  function useRouteParam(name, defaultValue) {
971
- var container = useViewContainerState();
996
+ var container = useViewContext();
972
997
  var route = app_app.route;
973
998
  var value = route[name] || '';
974
999
  var ref = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useRef)(value);
@@ -1007,7 +1032,7 @@ function useRouteParam(name, defaultValue) {
1007
1032
  return value;
1008
1033
  }
1009
1034
  function useRouteState(key, defaultValue, snapshotOnUpdate) {
1010
- var container = useViewContainerState();
1035
+ var container = useViewContext();
1011
1036
  var cur = getCurrentStates();
1012
1037
  var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(cur.has(key) ? cur.get(key) : defaultValue);
1013
1038
 
@@ -1033,7 +1058,7 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
1033
1058
  return state;
1034
1059
  }
1035
1060
  function ViewStateContainer(props) {
1036
- var container = useViewContainerState();
1061
+ var container = useViewContext();
1037
1062
  var provider = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
1038
1063
  var cache = {};
1039
1064
  return {
@@ -1046,7 +1071,7 @@ function ViewStateContainer(props) {
1046
1071
  var store = state.store;
1047
1072
 
1048
1073
  if (store && (store !== cur && cur.has(key) || key !== state.key)) {
1049
- emitter.emit('popstate', state, {
1074
+ hooks_emitter.emit('popstate', state, {
1050
1075
  newValue: value
1051
1076
  });
1052
1077
  state.value = value;
@@ -1751,6 +1776,29 @@ each('destroy enable disable setOptions refresh scrollPadding stop scrollLeft sc
1751
1776
  return obj.scrollable.apply(obj, [v].concat(makeArray(arguments)));
1752
1777
  });
1753
1778
  });
1779
+ ;// CONCATENATED MODULE: ./src/mixins/ScrollIntoViewMixin.js
1780
+
1781
+
1782
+
1783
+ function ScrollIntoViewMixin() {
1784
+ StatefulMixin.call(this);
1785
+ }
1786
+ definePrototype(ScrollIntoViewMixin, StatefulMixin, {
1787
+ when: function when(deps) {
1788
+ var state = this.state;
1789
+
1790
+ var callback = state.callback || (state.callback = function () {
1791
+ scrollIntoView(state.element);
1792
+ });
1793
+
1794
+ if (state.deps && !equal(deps, state.deps)) {
1795
+ setImmediateOnce(callback);
1796
+ }
1797
+
1798
+ state.deps = makeArray(deps);
1799
+ return this;
1800
+ }
1801
+ });
1754
1802
  ;// CONCATENATED MODULE: ./src/mixin.js
1755
1803
 
1756
1804
 
@@ -1766,6 +1814,7 @@ each('destroy enable disable setOptions refresh scrollPadding stop scrollLeft sc
1766
1814
 
1767
1815
 
1768
1816
 
1817
+
1769
1818
  function extendSelf(options) {
1770
1819
  extend(this, options);
1771
1820
  }
@@ -1784,6 +1833,7 @@ var useFlyoutMixin = createUseFunction(FlyoutMixin);
1784
1833
  var useFocusStateMixin = createUseFunction(FocusStateMixin);
1785
1834
  var useLoadingStateMixin = createUseFunction(LoadingStateMixin);
1786
1835
  var useScrollableMixin = createUseFunction(ScrollableMixin);
1836
+ var useScrollIntoViewMixin = createUseFunction(ScrollIntoViewMixin);
1787
1837
  function useMixin(ctor) {
1788
1838
  return (0,external_zeta_dom_react_.useSingleton)(function () {
1789
1839
  return new ctor();