brew-js-react 0.4.0 → 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.0 | (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),
@@ -214,6 +215,7 @@ __webpack_require__.d(src_namespaceObject, {
214
215
  "useAnimateMixin": () => (useAnimateMixin),
215
216
  "useAnimateSequenceMixin": () => (useAnimateSequenceMixin),
216
217
  "useAppReady": () => (useAppReady),
218
+ "useAppReadyState": () => (useAppReadyState),
217
219
  "useFlyoutMixin": () => (useFlyoutMixin),
218
220
  "useFocusStateMixin": () => (useFocusStateMixin),
219
221
  "useLanguage": () => (useLanguage),
@@ -222,8 +224,10 @@ __webpack_require__.d(src_namespaceObject, {
222
224
  "useMixinRef": () => (useMixinRef),
223
225
  "useRouteParam": () => (useRouteParam),
224
226
  "useRouteState": () => (useRouteState),
227
+ "useScrollIntoViewMixin": () => (useScrollIntoViewMixin),
225
228
  "useScrollableMixin": () => (useScrollableMixin),
226
- "useViewContainerState": () => (useViewContainerState)
229
+ "useViewContainerState": () => (useViewContext),
230
+ "useViewContext": () => (useViewContext)
227
231
  });
228
232
 
229
233
  // EXTERNAL MODULE: external {"commonjs":"brew-js","commonjs2":"brew-js","amd":"brew-js","root":"brew"}
@@ -363,6 +367,7 @@ var domUtil_lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_do
363
367
  removeNode = domUtil_lib$util.removeNode,
364
368
  getClass = domUtil_lib$util.getClass,
365
369
  setClass = domUtil_lib$util.setClass,
370
+ getSafeAreaInset = domUtil_lib$util.getSafeAreaInset,
366
371
  getScrollOffset = domUtil_lib$util.getScrollOffset,
367
372
  getScrollParent = domUtil_lib$util.getScrollParent,
368
373
  getContentRect = domUtil_lib$util.getContentRect,
@@ -583,10 +588,13 @@ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_br
583
588
 
584
589
 
585
590
 
591
+
592
+
586
593
  var root = zeta_dom_dom.root;
587
594
  var routeMap = new Map();
588
595
  var usedParams = {};
589
596
  var sortedViews = [];
597
+ var emitter = new ZetaEventContainer();
590
598
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
591
599
  container: root,
592
600
  active: true
@@ -601,6 +609,16 @@ onAppInit(function () {
601
609
  });
602
610
  });
603
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
+
604
622
  function ErrorBoundary() {
605
623
  external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
606
624
  this.state = {};
@@ -725,13 +743,12 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
725
743
  });
726
744
  notifyAsync(element, promise);
727
745
  });
746
+ var state = new ViewContext(V);
728
747
  var viewProps = freeze({
729
748
  navigationType: view_event.navigationType,
749
+ viewContext: state,
730
750
  viewData: view_event.data || {}
731
751
  });
732
- var state = {
733
- view: V
734
- };
735
752
  var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, {
736
753
  key: routeMap.get(V).id,
737
754
  value: state
@@ -745,10 +762,18 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
745
762
  currentPath: app_app.path,
746
763
  currentView: view,
747
764
  currentViewComponent: V,
765
+ setPage: defineObservableProperty(state, 'page', app_app.page, true),
748
766
  setActive: defineObservableProperty(state, 'active', true, true)
749
767
  });
768
+ watch(state, 'page', function (page, previousPage) {
769
+ emitter.emit('pagechange', state, {
770
+ previousPage: previousPage
771
+ });
772
+ });
750
773
  (view_event.waitFor || noop)(promise);
751
774
  }
775
+
776
+ (self.setPage || noop)(app_app.page);
752
777
  },
753
778
  getViewComponent: function getViewComponent() {
754
779
  var props = this.props;
@@ -841,7 +866,7 @@ function createViewComponent(factory) {
841
866
  };
842
867
  }
843
868
 
844
- function useViewContainerState() {
869
+ function useViewContext() {
845
870
  return external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext(StateContext);
846
871
  }
847
872
  function isViewMatched(view) {
@@ -890,6 +915,11 @@ function renderView() {
890
915
  var views = makeArray(arguments);
891
916
  var rootProps = isFunction(views[0]) ? {} : views.shift();
892
917
  var defaultView = views[0];
918
+ each(views, function (i, v) {
919
+ if (!routeMap.has(v)) {
920
+ throw new Error('Invalid argument to renderView: ' + (isFunction(v) ? v.name : v));
921
+ }
922
+ });
893
923
  views.sort(sortViews);
894
924
  return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewContainer, {
895
925
  rootProps: rootProps,
@@ -916,6 +946,7 @@ function navigateTo(view, params, data, replace) {
916
946
  function redirectTo(view, params, data) {
917
947
  return navigateTo(view, params, data, true);
918
948
  }
949
+
919
950
  ;// CONCATENATED MODULE: ./src/hooks.js
920
951
 
921
952
 
@@ -924,7 +955,7 @@ function redirectTo(view, params, data) {
924
955
 
925
956
 
926
957
 
927
- var emitter = new ZetaEventContainer();
958
+ var hooks_emitter = new ZetaEventContainer();
928
959
 
929
960
  function getCurrentStates() {
930
961
  return app_app.historyStorage.current;
@@ -946,24 +977,23 @@ definePrototype(ViewState, {
946
977
  },
947
978
  onPopState: function onPopState(callback) {
948
979
  throwNotFunction(callback);
949
- return emitter.add(this, 'popstate', function (e) {
980
+ return hooks_emitter.add(this, 'popstate', function (e) {
950
981
  callback.call(this, e.newValue);
951
982
  });
952
983
  }
953
984
  });
954
985
  function useAppReady() {
955
- var sReady = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(false);
956
- var ready = sReady[0],
957
- setReady = sReady[1];
958
- (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
959
- app_app.ready.then(function () {
960
- setReady(true);
961
- });
962
- }, []);
963
- return ready;
986
+ return useAppReadyState().ready;
987
+ }
988
+ function useAppReadyState() {
989
+ var readyState = (0,external_zeta_dom_react_.useObservableProperty)(app_app, 'readyState');
990
+ return {
991
+ ready: readyState === 'ready',
992
+ error: readyState === 'error'
993
+ };
964
994
  }
965
995
  function useRouteParam(name, defaultValue) {
966
- var container = useViewContainerState();
996
+ var container = useViewContext();
967
997
  var route = app_app.route;
968
998
  var value = route[name] || '';
969
999
  var ref = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useRef)(value);
@@ -1002,7 +1032,7 @@ function useRouteParam(name, defaultValue) {
1002
1032
  return value;
1003
1033
  }
1004
1034
  function useRouteState(key, defaultValue, snapshotOnUpdate) {
1005
- var container = useViewContainerState();
1035
+ var container = useViewContext();
1006
1036
  var cur = getCurrentStates();
1007
1037
  var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(cur.has(key) ? cur.get(key) : defaultValue);
1008
1038
 
@@ -1028,7 +1058,7 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
1028
1058
  return state;
1029
1059
  }
1030
1060
  function ViewStateContainer(props) {
1031
- var container = useViewContainerState();
1061
+ var container = useViewContext();
1032
1062
  var provider = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
1033
1063
  var cache = {};
1034
1064
  return {
@@ -1041,7 +1071,7 @@ function ViewStateContainer(props) {
1041
1071
  var store = state.store;
1042
1072
 
1043
1073
  if (store && (store !== cur && cur.has(key) || key !== state.key)) {
1044
- emitter.emit('popstate', state, {
1074
+ hooks_emitter.emit('popstate', state, {
1045
1075
  newValue: value
1046
1076
  });
1047
1077
  state.value = value;
@@ -1746,6 +1776,29 @@ each('destroy enable disable setOptions refresh scrollPadding stop scrollLeft sc
1746
1776
  return obj.scrollable.apply(obj, [v].concat(makeArray(arguments)));
1747
1777
  });
1748
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
+ });
1749
1802
  ;// CONCATENATED MODULE: ./src/mixin.js
1750
1803
 
1751
1804
 
@@ -1761,6 +1814,7 @@ each('destroy enable disable setOptions refresh scrollPadding stop scrollLeft sc
1761
1814
 
1762
1815
 
1763
1816
 
1817
+
1764
1818
  function extendSelf(options) {
1765
1819
  extend(this, options);
1766
1820
  }
@@ -1773,30 +1827,17 @@ function createUseFunction(ctor) {
1773
1827
  };
1774
1828
  }
1775
1829
 
1776
- function disposeMixin(mixin) {
1777
- mixin.disposed = true;
1778
- setImmediate(function () {
1779
- if (mixin.disposed) {
1780
- mixin.dispose();
1781
- }
1782
- });
1783
- }
1784
-
1785
1830
  var useAnimateMixin = createUseFunction(AnimateMixin);
1786
1831
  var useAnimateSequenceMixin = createUseFunction(AnimateSequenceMixin);
1787
1832
  var useFlyoutMixin = createUseFunction(FlyoutMixin);
1788
1833
  var useFocusStateMixin = createUseFunction(FocusStateMixin);
1789
1834
  var useLoadingStateMixin = createUseFunction(LoadingStateMixin);
1790
1835
  var useScrollableMixin = createUseFunction(ScrollableMixin);
1836
+ var useScrollIntoViewMixin = createUseFunction(ScrollIntoViewMixin);
1791
1837
  function useMixin(ctor) {
1792
- var mixin = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
1838
+ return (0,external_zeta_dom_react_.useSingleton)(function () {
1793
1839
  return new ctor();
1794
- })[0].reset();
1795
- (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
1796
- mixin.disposed = false;
1797
- return disposeMixin.bind(0, mixin);
1798
- }, []);
1799
- return mixin;
1840
+ }).reset();
1800
1841
  }
1801
1842
  function useMixinRef(mixin) {
1802
1843
  return mixin && mixin.getMixin().reset();