brew-js-react 0.3.4 → 0.4.1
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/app.js +8 -0
- package/dist/brew-js-react.js +61 -56
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +2 -2
- package/dist/brew-js-react.min.js.map +1 -1
- package/hooks.d.ts +10 -0
- package/hooks.js +27 -28
- package/mixin.js +4 -18
- package/package.json +4 -4
- package/view.d.ts +6 -1
- package/view.js +26 -12
package/app.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { combineFn, throwNotFunction } from "./include/zeta-dom/util.js";
|
|
1
2
|
import { install } from "./include/brew-js/app.js";
|
|
2
3
|
import defaults from "./include/brew-js/defaults.js";
|
|
3
4
|
|
|
4
5
|
/** @type {Brew.AppInstance<Brew.WithRouter & Brew.WithI18n>} */
|
|
5
6
|
export var app;
|
|
6
7
|
|
|
8
|
+
const appInitCallabcks = [];
|
|
9
|
+
|
|
10
|
+
export function onAppInit(callback) {
|
|
11
|
+
appInitCallabcks.push(throwNotFunction(callback));
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
install('react', function (app_) {
|
|
8
15
|
// @ts-ignore: type inference issue
|
|
9
16
|
app = app_;
|
|
17
|
+
combineFn(appInitCallabcks)(app);
|
|
10
18
|
});
|
|
11
19
|
|
|
12
20
|
defaults.react = true;
|
package/dist/brew-js-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! brew-js-react v0.
|
|
1
|
+
/*! brew-js-react v0.4.1 | (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"));
|
|
@@ -214,6 +214,7 @@ __webpack_require__.d(src_namespaceObject, {
|
|
|
214
214
|
"useAnimateMixin": () => (useAnimateMixin),
|
|
215
215
|
"useAnimateSequenceMixin": () => (useAnimateSequenceMixin),
|
|
216
216
|
"useAppReady": () => (useAppReady),
|
|
217
|
+
"useAppReadyState": () => (useAppReadyState),
|
|
217
218
|
"useFlyoutMixin": () => (useFlyoutMixin),
|
|
218
219
|
"useFocusStateMixin": () => (useFocusStateMixin),
|
|
219
220
|
"useLanguage": () => (useLanguage),
|
|
@@ -387,6 +388,7 @@ var _lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_z
|
|
|
387
388
|
textInputAllowed = _lib$dom.textInputAllowed,
|
|
388
389
|
beginDrag = _lib$dom.beginDrag,
|
|
389
390
|
beginPinchZoom = _lib$dom.beginPinchZoom,
|
|
391
|
+
insertText = _lib$dom.insertText,
|
|
390
392
|
getShortcut = _lib$dom.getShortcut,
|
|
391
393
|
setShortcut = _lib$dom.setShortcut,
|
|
392
394
|
focusable = _lib$dom.focusable,
|
|
@@ -538,12 +540,18 @@ var defaults_defaultExport = external_commonjs_brew_js_commonjs2_brew_js_amd_bre
|
|
|
538
540
|
;// CONCATENATED MODULE: ./src/app.js
|
|
539
541
|
|
|
540
542
|
|
|
543
|
+
|
|
541
544
|
/** @type {Brew.AppInstance<Brew.WithRouter & Brew.WithI18n>} */
|
|
542
545
|
|
|
543
546
|
var app_app;
|
|
547
|
+
var appInitCallabcks = [];
|
|
548
|
+
function onAppInit(callback) {
|
|
549
|
+
appInitCallabcks.push(throwNotFunction(callback));
|
|
550
|
+
}
|
|
544
551
|
install('react', function (app_) {
|
|
545
552
|
// @ts-ignore: type inference issue
|
|
546
553
|
app_app = app_;
|
|
554
|
+
combineFn(appInitCallabcks)(app_app);
|
|
547
555
|
});
|
|
548
556
|
brew_js_defaults.react = true;
|
|
549
557
|
;// CONCATENATED MODULE: ./tmp/brew-js/anim.js
|
|
@@ -585,6 +593,14 @@ var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_reac
|
|
|
585
593
|
active: true
|
|
586
594
|
}));
|
|
587
595
|
var errorView;
|
|
596
|
+
/** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
|
|
597
|
+
|
|
598
|
+
var view_event = {};
|
|
599
|
+
onAppInit(function () {
|
|
600
|
+
app_app.on('beforepageload', function (e) {
|
|
601
|
+
view_event = e;
|
|
602
|
+
});
|
|
603
|
+
});
|
|
588
604
|
|
|
589
605
|
function ErrorBoundary() {
|
|
590
606
|
external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
|
|
@@ -628,7 +644,7 @@ definePrototype(ErrorBoundary, external_commonjs_react_commonjs2_react_amd_react
|
|
|
628
644
|
|
|
629
645
|
return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(props.view, {
|
|
630
646
|
onComponentLoaded: onComponentLoaded,
|
|
631
|
-
|
|
647
|
+
viewProps: self.props.viewProps
|
|
632
648
|
});
|
|
633
649
|
},
|
|
634
650
|
reset: function reset() {
|
|
@@ -649,10 +665,9 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
649
665
|
var self = this;
|
|
650
666
|
self.componentWillUnmount = combineFn(watch(app_app.route, function () {
|
|
651
667
|
self.setActive(self.getViewComponent() === self.currentViewComponent);
|
|
652
|
-
}), app_app.on('beforepageload', function (
|
|
653
|
-
self.waitFor = e.waitFor;
|
|
668
|
+
}), app_app.on('beforepageload', function () {
|
|
654
669
|
self.stateId = history.state;
|
|
655
|
-
self.updateView(
|
|
670
|
+
self.updateView();
|
|
656
671
|
self.forceUpdate();
|
|
657
672
|
}));
|
|
658
673
|
},
|
|
@@ -666,7 +681,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
666
681
|
|
|
667
682
|
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
683
|
},
|
|
669
|
-
updateView: function updateView(
|
|
684
|
+
updateView: function updateView() {
|
|
670
685
|
var self = this;
|
|
671
686
|
var V = self.getViewComponent();
|
|
672
687
|
|
|
@@ -711,6 +726,10 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
711
726
|
});
|
|
712
727
|
notifyAsync(element, promise);
|
|
713
728
|
});
|
|
729
|
+
var viewProps = freeze({
|
|
730
|
+
navigationType: view_event.navigationType,
|
|
731
|
+
viewData: view_event.data || {}
|
|
732
|
+
});
|
|
714
733
|
var state = {
|
|
715
734
|
view: V
|
|
716
735
|
};
|
|
@@ -721,7 +740,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
721
740
|
ref: initElement
|
|
722
741
|
}), /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ErrorBoundary, {
|
|
723
742
|
onComponentLoaded: onComponentLoaded,
|
|
724
|
-
|
|
743
|
+
viewProps: viewProps
|
|
725
744
|
}))));
|
|
726
745
|
extend(self, {
|
|
727
746
|
currentPath: app_app.path,
|
|
@@ -729,7 +748,7 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
729
748
|
currentViewComponent: V,
|
|
730
749
|
setActive: defineObservableProperty(state, 'active', true, true)
|
|
731
750
|
});
|
|
732
|
-
(
|
|
751
|
+
(view_event.waitFor || noop)(promise);
|
|
733
752
|
}
|
|
734
753
|
},
|
|
735
754
|
getViewComponent: function getViewComponent() {
|
|
@@ -797,9 +816,7 @@ function createViewComponent(factory) {
|
|
|
797
816
|
}
|
|
798
817
|
|
|
799
818
|
return function fn(props) {
|
|
800
|
-
var viewProps = props.viewProps
|
|
801
|
-
viewData: useRouteState('_d_' + routeMap.get(fn).id, props.viewData || {})[0]
|
|
802
|
-
};
|
|
819
|
+
var viewProps = props.viewProps;
|
|
803
820
|
var children = !promise && factory(viewProps);
|
|
804
821
|
|
|
805
822
|
if (isThenable(children)) {
|
|
@@ -874,6 +891,11 @@ function renderView() {
|
|
|
874
891
|
var views = makeArray(arguments);
|
|
875
892
|
var rootProps = isFunction(views[0]) ? {} : views.shift();
|
|
876
893
|
var defaultView = views[0];
|
|
894
|
+
each(views, function (i, v) {
|
|
895
|
+
if (!routeMap.has(v)) {
|
|
896
|
+
throw new Error('Invalid argument to renderView: ' + (isFunction(v) ? v.name : v));
|
|
897
|
+
}
|
|
898
|
+
});
|
|
877
899
|
views.sort(sortViews);
|
|
878
900
|
return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewContainer, {
|
|
879
901
|
rootProps: rootProps,
|
|
@@ -909,10 +931,9 @@ function redirectTo(view, params, data) {
|
|
|
909
931
|
|
|
910
932
|
|
|
911
933
|
var emitter = new ZetaEventContainer();
|
|
912
|
-
var states = {};
|
|
913
934
|
|
|
914
935
|
function getCurrentStates() {
|
|
915
|
-
return
|
|
936
|
+
return app_app.historyStorage.current;
|
|
916
937
|
}
|
|
917
938
|
|
|
918
939
|
function ViewState(key, value) {
|
|
@@ -925,7 +946,9 @@ definePrototype(ViewState, {
|
|
|
925
946
|
return this.value;
|
|
926
947
|
},
|
|
927
948
|
set: function set(value) {
|
|
928
|
-
|
|
949
|
+
var self = this;
|
|
950
|
+
self.value = value;
|
|
951
|
+
self.store.set(self.key, value);
|
|
929
952
|
},
|
|
930
953
|
onPopState: function onPopState(callback) {
|
|
931
954
|
throwNotFunction(callback);
|
|
@@ -935,15 +958,14 @@ definePrototype(ViewState, {
|
|
|
935
958
|
}
|
|
936
959
|
});
|
|
937
960
|
function useAppReady() {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
(0,
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
return ready;
|
|
961
|
+
return useAppReadyState().ready;
|
|
962
|
+
}
|
|
963
|
+
function useAppReadyState() {
|
|
964
|
+
var readyState = (0,external_zeta_dom_react_.useObservableProperty)(app_app, 'readyState');
|
|
965
|
+
return {
|
|
966
|
+
ready: readyState === 'ready',
|
|
967
|
+
error: readyState === 'error'
|
|
968
|
+
};
|
|
947
969
|
}
|
|
948
970
|
function useRouteParam(name, defaultValue) {
|
|
949
971
|
var container = useViewContainerState();
|
|
@@ -987,15 +1009,15 @@ function useRouteParam(name, defaultValue) {
|
|
|
987
1009
|
function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
988
1010
|
var container = useViewContainerState();
|
|
989
1011
|
var cur = getCurrentStates();
|
|
990
|
-
var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(key
|
|
1012
|
+
var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(cur.has(key) ? cur.get(key) : defaultValue);
|
|
991
1013
|
|
|
992
|
-
if (container.active && cur
|
|
993
|
-
if (snapshotOnUpdate && key
|
|
1014
|
+
if (container.active && cur.get(key) !== state[0]) {
|
|
1015
|
+
if (snapshotOnUpdate && cur.has(key)) {
|
|
994
1016
|
app_app.snapshot();
|
|
995
1017
|
cur = getCurrentStates();
|
|
996
1018
|
}
|
|
997
1019
|
|
|
998
|
-
cur
|
|
1020
|
+
cur.set(key, state[0]);
|
|
999
1021
|
}
|
|
1000
1022
|
|
|
1001
1023
|
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
@@ -1003,7 +1025,7 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
|
1003
1025
|
return bind(window, 'popstate', function () {
|
|
1004
1026
|
if (container.active) {
|
|
1005
1027
|
var cur = getCurrentStates();
|
|
1006
|
-
state[1](key
|
|
1028
|
+
state[1](cur.has(key) ? cur.get(key) : defaultValue);
|
|
1007
1029
|
}
|
|
1008
1030
|
});
|
|
1009
1031
|
}
|
|
@@ -1017,25 +1039,22 @@ function ViewStateContainer(props) {
|
|
|
1017
1039
|
return {
|
|
1018
1040
|
getState: function getState(uniqueId, key) {
|
|
1019
1041
|
var cur = getCurrentStates();
|
|
1020
|
-
var
|
|
1042
|
+
var value = cur.get(key);
|
|
1043
|
+
var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(key, value));
|
|
1021
1044
|
|
|
1022
1045
|
if (container.active) {
|
|
1023
|
-
var
|
|
1046
|
+
var store = state.store;
|
|
1024
1047
|
|
|
1025
|
-
if (
|
|
1026
|
-
var newValue = cur[key] && cur[key].value;
|
|
1048
|
+
if (store && (store !== cur && cur.has(key) || key !== state.key)) {
|
|
1027
1049
|
emitter.emit('popstate', state, {
|
|
1028
|
-
newValue:
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
var previous = new ViewState(state.key, state.value);
|
|
1032
|
-
states[stateId][previous.key] = previous;
|
|
1033
|
-
state.value = newValue;
|
|
1050
|
+
newValue: value
|
|
1051
|
+
});
|
|
1052
|
+
state.value = value;
|
|
1034
1053
|
state.key = key;
|
|
1035
1054
|
}
|
|
1036
1055
|
|
|
1037
|
-
state.
|
|
1038
|
-
cur
|
|
1056
|
+
state.store = cur;
|
|
1057
|
+
cur.set(key, state.value);
|
|
1039
1058
|
}
|
|
1040
1059
|
|
|
1041
1060
|
return state;
|
|
@@ -1759,15 +1778,6 @@ function createUseFunction(ctor) {
|
|
|
1759
1778
|
};
|
|
1760
1779
|
}
|
|
1761
1780
|
|
|
1762
|
-
function disposeMixin(mixin) {
|
|
1763
|
-
mixin.disposed = true;
|
|
1764
|
-
setImmediate(function () {
|
|
1765
|
-
if (mixin.disposed) {
|
|
1766
|
-
mixin.dispose();
|
|
1767
|
-
}
|
|
1768
|
-
});
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
1781
|
var useAnimateMixin = createUseFunction(AnimateMixin);
|
|
1772
1782
|
var useAnimateSequenceMixin = createUseFunction(AnimateSequenceMixin);
|
|
1773
1783
|
var useFlyoutMixin = createUseFunction(FlyoutMixin);
|
|
@@ -1775,14 +1785,9 @@ var useFocusStateMixin = createUseFunction(FocusStateMixin);
|
|
|
1775
1785
|
var useLoadingStateMixin = createUseFunction(LoadingStateMixin);
|
|
1776
1786
|
var useScrollableMixin = createUseFunction(ScrollableMixin);
|
|
1777
1787
|
function useMixin(ctor) {
|
|
1778
|
-
|
|
1788
|
+
return (0,external_zeta_dom_react_.useSingleton)(function () {
|
|
1779
1789
|
return new ctor();
|
|
1780
|
-
})
|
|
1781
|
-
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
1782
|
-
mixin.disposed = false;
|
|
1783
|
-
return disposeMixin.bind(0, mixin);
|
|
1784
|
-
}, []);
|
|
1785
|
-
return mixin;
|
|
1790
|
+
}).reset();
|
|
1786
1791
|
}
|
|
1787
1792
|
function useMixinRef(mixin) {
|
|
1788
1793
|
return mixin && mixin.getMixin().reset();
|