brew-js-react 0.3.3 → 0.3.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.
- package/dist/brew-js-react.js +45 -23
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +2 -1
- package/dist/brew-js-react.min.js.map +1 -1
- package/hooks.js +8 -6
- package/mixin.js +12 -2
- package/package.json +2 -2
- package/view.d.ts +41 -8
- package/view.js +25 -17
package/dist/brew-js-react.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*! brew-js-react v0.3.4 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
|
|
1
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
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"));
|
|
@@ -209,6 +210,7 @@ __webpack_require__.d(src_namespaceObject, {
|
|
|
209
210
|
"registerErrorView": () => (registerErrorView),
|
|
210
211
|
"registerView": () => (registerView),
|
|
211
212
|
"renderView": () => (renderView),
|
|
213
|
+
"resolvePath": () => (resolvePath),
|
|
212
214
|
"useAnimateMixin": () => (useAnimateMixin),
|
|
213
215
|
"useAnimateSequenceMixin": () => (useAnimateSequenceMixin),
|
|
214
216
|
"useAppReady": () => (useAppReady),
|
|
@@ -625,7 +627,8 @@ definePrototype(ErrorBoundary, external_commonjs_react_commonjs2_react_amd_react
|
|
|
625
627
|
}
|
|
626
628
|
|
|
627
629
|
return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(props.view, {
|
|
628
|
-
onComponentLoaded: onComponentLoaded
|
|
630
|
+
onComponentLoaded: onComponentLoaded,
|
|
631
|
+
viewData: self.props.viewData
|
|
629
632
|
});
|
|
630
633
|
},
|
|
631
634
|
reset: function reset() {
|
|
@@ -649,6 +652,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
649
652
|
}), app_app.on('beforepageload', function (e) {
|
|
650
653
|
self.waitFor = e.waitFor;
|
|
651
654
|
self.stateId = history.state;
|
|
655
|
+
self.updateView(e.data);
|
|
652
656
|
self.forceUpdate();
|
|
653
657
|
}));
|
|
654
658
|
},
|
|
@@ -656,16 +660,20 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
656
660
|
/** @type {any} */
|
|
657
661
|
var self = this;
|
|
658
662
|
|
|
659
|
-
if (history.state
|
|
660
|
-
|
|
663
|
+
if (history.state === self.stateId) {
|
|
664
|
+
self.updateView();
|
|
661
665
|
}
|
|
662
666
|
|
|
667
|
+
return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
|
|
668
|
+
},
|
|
669
|
+
updateView: function updateView(viewData) {
|
|
670
|
+
var self = this;
|
|
663
671
|
var V = self.getViewComponent();
|
|
664
672
|
|
|
665
673
|
if (V) {
|
|
666
674
|
// ensure the current path actually corresponds to the matched view
|
|
667
675
|
// when some views are not included in the list of allowed views
|
|
668
|
-
var targetPath =
|
|
676
|
+
var targetPath = resolvePath(V, getCurrentParams(V, true));
|
|
669
677
|
|
|
670
678
|
if (targetPath !== removeQueryAndHash(app_app.path)) {
|
|
671
679
|
app_app.navigate(targetPath, true);
|
|
@@ -712,7 +720,8 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
712
720
|
}, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement('div', extend({}, self.props.rootProps, {
|
|
713
721
|
ref: initElement
|
|
714
722
|
}), /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ErrorBoundary, {
|
|
715
|
-
onComponentLoaded: onComponentLoaded
|
|
723
|
+
onComponentLoaded: onComponentLoaded,
|
|
724
|
+
viewData: viewData
|
|
716
725
|
}))));
|
|
717
726
|
extend(self, {
|
|
718
727
|
currentPath: app_app.path,
|
|
@@ -722,10 +731,6 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
722
731
|
});
|
|
723
732
|
(self.waitFor || noop)(promise);
|
|
724
733
|
}
|
|
725
|
-
|
|
726
|
-
var child = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
|
|
727
|
-
self.lastChild = child;
|
|
728
|
-
return child;
|
|
729
734
|
},
|
|
730
735
|
getViewComponent: function getViewComponent() {
|
|
731
736
|
var props = this.props;
|
|
@@ -791,8 +796,10 @@ function createViewComponent(factory) {
|
|
|
791
796
|
factory = external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement.bind(null, factory);
|
|
792
797
|
}
|
|
793
798
|
|
|
794
|
-
return function (props) {
|
|
795
|
-
var viewProps =
|
|
799
|
+
return function fn(props) {
|
|
800
|
+
var viewProps = props.viewProps || {
|
|
801
|
+
viewData: useRouteState('_d_' + routeMap.get(fn).id, props.viewData || {})[0]
|
|
802
|
+
};
|
|
796
803
|
var children = !promise && factory(viewProps);
|
|
797
804
|
|
|
798
805
|
if (isThenable(children)) {
|
|
@@ -874,7 +881,7 @@ function renderView() {
|
|
|
874
881
|
defaultView: defaultView
|
|
875
882
|
});
|
|
876
883
|
}
|
|
877
|
-
function
|
|
884
|
+
function resolvePath(view, params) {
|
|
878
885
|
var state = routeMap.get(view);
|
|
879
886
|
|
|
880
887
|
if (!state) {
|
|
@@ -884,11 +891,14 @@ function linkTo(view, params) {
|
|
|
884
891
|
var newParams = extend(getCurrentParams(view), getCurrentParams(view, true, params || {}), state.params);
|
|
885
892
|
return app_app.route.getPath(newParams);
|
|
886
893
|
}
|
|
887
|
-
function
|
|
888
|
-
return app_app.
|
|
894
|
+
function linkTo(view, params) {
|
|
895
|
+
return app_app.toHref(resolvePath(view, params));
|
|
896
|
+
}
|
|
897
|
+
function navigateTo(view, params, data, replace) {
|
|
898
|
+
return app_app.navigate(resolvePath(view, params), replace, data && freeze(extend({}, data)));
|
|
889
899
|
}
|
|
890
|
-
function redirectTo(view, params) {
|
|
891
|
-
return
|
|
900
|
+
function redirectTo(view, params, data) {
|
|
901
|
+
return navigateTo(view, params, data, true);
|
|
892
902
|
}
|
|
893
903
|
;// CONCATENATED MODULE: ./src/hooks.js
|
|
894
904
|
|
|
@@ -989,12 +999,14 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
|
989
999
|
}
|
|
990
1000
|
|
|
991
1001
|
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1002
|
+
if (snapshotOnUpdate) {
|
|
1003
|
+
return bind(window, 'popstate', function () {
|
|
1004
|
+
if (container.active) {
|
|
1005
|
+
var cur = getCurrentStates();
|
|
1006
|
+
state[1](key in cur ? cur[key] : defaultValue);
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
998
1010
|
}, [container, snapshotOnUpdate]);
|
|
999
1011
|
return state;
|
|
1000
1012
|
}
|
|
@@ -1747,6 +1759,15 @@ function createUseFunction(ctor) {
|
|
|
1747
1759
|
};
|
|
1748
1760
|
}
|
|
1749
1761
|
|
|
1762
|
+
function disposeMixin(mixin) {
|
|
1763
|
+
mixin.disposed = true;
|
|
1764
|
+
setImmediate(function () {
|
|
1765
|
+
if (mixin.disposed) {
|
|
1766
|
+
mixin.dispose();
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1750
1771
|
var useAnimateMixin = createUseFunction(AnimateMixin);
|
|
1751
1772
|
var useAnimateSequenceMixin = createUseFunction(AnimateSequenceMixin);
|
|
1752
1773
|
var useFlyoutMixin = createUseFunction(FlyoutMixin);
|
|
@@ -1758,7 +1779,8 @@ function useMixin(ctor) {
|
|
|
1758
1779
|
return new ctor();
|
|
1759
1780
|
})[0].reset();
|
|
1760
1781
|
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
1761
|
-
|
|
1782
|
+
mixin.disposed = false;
|
|
1783
|
+
return disposeMixin.bind(0, mixin);
|
|
1762
1784
|
}, []);
|
|
1763
1785
|
return mixin;
|
|
1764
1786
|
}
|