brew-js-react 0.4.7 → 0.4.8
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 +84 -79
- 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.js +53 -40
- package/package.json +5 -5
- package/view.js +6 -3
package/dist/brew-js-react.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
/*! brew-js-react v0.4.
|
|
1
|
+
/*! brew-js-react v0.4.8 | (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
|
-
module.exports = factory(require("brew-js"), require("react"), require("react-dom"),
|
|
4
|
+
module.exports = factory(require("brew-js"), require("react"), require("react-dom"), require("zeta-dom"), require("zeta-dom-react"), require("waterpipe"));
|
|
5
5
|
else if(typeof define === 'function' && define.amd)
|
|
6
|
-
define("brew-js-react", ["brew-js", "react", "react-dom", "
|
|
6
|
+
define("brew-js-react", ["brew-js", "react", "react-dom", "zeta-dom", "zeta-dom-react", "waterpipe"], factory);
|
|
7
7
|
else if(typeof exports === 'object')
|
|
8
|
-
exports["brew-js-react"] = factory(require("brew-js"), require("react"), require("react-dom"),
|
|
8
|
+
exports["brew-js-react"] = factory(require("brew-js"), require("react"), require("react-dom"), require("zeta-dom"), require("zeta-dom-react"), require("waterpipe"));
|
|
9
9
|
else
|
|
10
|
-
root["brew-js-react"] = factory(root["brew"], root["React"], root["ReactDOM"], root["
|
|
11
|
-
})(self, function(__WEBPACK_EXTERNAL_MODULE__80__, __WEBPACK_EXTERNAL_MODULE__359__, __WEBPACK_EXTERNAL_MODULE__318__,
|
|
10
|
+
root["brew-js-react"] = factory(root["brew"], root["React"], root["ReactDOM"], root["zeta"], root["zeta-dom-react"], root["waterpipe"]);
|
|
11
|
+
})(self, function(__WEBPACK_EXTERNAL_MODULE__80__, __WEBPACK_EXTERNAL_MODULE__359__, __WEBPACK_EXTERNAL_MODULE__318__, __WEBPACK_EXTERNAL_MODULE__654__, __WEBPACK_EXTERNAL_MODULE__103__, __WEBPACK_EXTERNAL_MODULE__28__) {
|
|
12
12
|
return /******/ (() => { // webpackBootstrap
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
14
14
|
|
|
15
|
-
/***/ 715:
|
|
16
|
-
/***/ ((module) => {
|
|
17
|
-
|
|
18
|
-
"use strict";
|
|
19
|
-
if(typeof __WEBPACK_EXTERNAL_MODULE__715__ === 'undefined') { var e = new Error("Cannot find module 'react-dom/client'"); e.code = 'MODULE_NOT_FOUND'; throw e; }
|
|
20
|
-
|
|
21
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__715__;
|
|
22
|
-
|
|
23
|
-
/***/ }),
|
|
24
|
-
|
|
25
15
|
/***/ 28:
|
|
26
16
|
/***/ ((module) => {
|
|
27
17
|
|
|
@@ -70,38 +60,33 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__654__;
|
|
|
70
60
|
|
|
71
61
|
/***/ }),
|
|
72
62
|
|
|
73
|
-
/***/
|
|
63
|
+
/***/ 862:
|
|
74
64
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
75
65
|
|
|
76
|
-
var
|
|
66
|
+
var ReactDOM = __webpack_require__(318);
|
|
77
67
|
var ReactDOMClient;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
|
|
69
|
+
if (ReactDOM.createRoot) {
|
|
70
|
+
ReactDOMClient = ReactDOM;
|
|
71
|
+
} else {
|
|
81
72
|
ReactDOMClient = {
|
|
82
73
|
createRoot(container, options) {
|
|
83
74
|
return {
|
|
84
75
|
render(children) {
|
|
85
|
-
|
|
76
|
+
ReactDOM.render(children, container);
|
|
86
77
|
},
|
|
87
78
|
unmount() {
|
|
88
|
-
|
|
79
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
89
80
|
}
|
|
90
81
|
};
|
|
91
82
|
},
|
|
92
83
|
hydrateRoot(container, initialChildren, options) {
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
render(children) {
|
|
96
|
-
React.render(children, container);
|
|
97
|
-
},
|
|
98
|
-
unmount() {
|
|
99
|
-
React.unmountComponentAtNode(container);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
84
|
+
ReactDOM.hydrate(initialChildren, container);
|
|
85
|
+
return ReactDOMClient.createRoot(container, options);
|
|
102
86
|
},
|
|
103
87
|
};
|
|
104
88
|
}
|
|
89
|
+
|
|
105
90
|
/** @type {import("react-dom/client")} */
|
|
106
91
|
module.exports = ReactDOMClient;
|
|
107
92
|
|
|
@@ -241,14 +226,14 @@ var install = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_
|
|
|
241
226
|
var external_commonjs_react_commonjs2_react_amd_react_root_React_ = __webpack_require__(359);
|
|
242
227
|
// EXTERNAL MODULE: external {"commonjs":"react-dom","commonjs2":"react-dom","amd":"react-dom","root":"ReactDOM"}
|
|
243
228
|
var external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_ = __webpack_require__(318);
|
|
244
|
-
// EXTERNAL MODULE: ./node_modules/@misonou/react-dom-client/
|
|
245
|
-
var
|
|
229
|
+
// EXTERNAL MODULE: ./node_modules/@misonou/react-dom-client/fallback.js
|
|
230
|
+
var fallback = __webpack_require__(862);
|
|
246
231
|
;// CONCATENATED MODULE: ./src/include/external/react-dom-client.js
|
|
247
232
|
// @ts-nocheck
|
|
248
233
|
|
|
249
234
|
/** @type {import("react-dom/client")} */
|
|
250
235
|
|
|
251
|
-
/* harmony default export */ const
|
|
236
|
+
/* harmony default export */ const react_dom_client = (fallback);
|
|
252
237
|
// EXTERNAL MODULE: external {"commonjs":"zeta-dom","commonjs2":"zeta-dom","amd":"zeta-dom","root":"zeta"}
|
|
253
238
|
var external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_ = __webpack_require__(654);
|
|
254
239
|
;// CONCATENATED MODULE: ./tmp/zeta-dom/util.js
|
|
@@ -438,7 +423,7 @@ var addAsyncAction = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_roo
|
|
|
438
423
|
|
|
439
424
|
function createDialog(props) {
|
|
440
425
|
var root = document.createElement('div');
|
|
441
|
-
var reactRoot =
|
|
426
|
+
var reactRoot = react_dom_client.createRoot(root);
|
|
442
427
|
|
|
443
428
|
var _closeDialog = closeFlyout.bind(0, root);
|
|
444
429
|
|
|
@@ -611,6 +596,9 @@ var emitter = new ZetaEventContainer();
|
|
|
611
596
|
var rootContext = freeze(extend(new ViewContext(null, null), {
|
|
612
597
|
container: root
|
|
613
598
|
}));
|
|
599
|
+
|
|
600
|
+
var rootState = _(rootContext);
|
|
601
|
+
|
|
614
602
|
var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(rootContext);
|
|
615
603
|
var errorView;
|
|
616
604
|
/** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
|
|
@@ -618,6 +606,8 @@ var errorView;
|
|
|
618
606
|
var view_event = {};
|
|
619
607
|
onAppInit(function () {
|
|
620
608
|
app_app.on('beforepageload', function (e) {
|
|
609
|
+
rootState.setPage(app_app.page);
|
|
610
|
+
rootState.setActive(true);
|
|
621
611
|
view_event = e;
|
|
622
612
|
e.waitFor(new Promise(function (resolve) {
|
|
623
613
|
(function updateViewRecursive(next) {
|
|
@@ -635,21 +625,20 @@ onAppInit(function () {
|
|
|
635
625
|
return v.children;
|
|
636
626
|
}));
|
|
637
627
|
});
|
|
638
|
-
})(
|
|
628
|
+
})(rootState.children);
|
|
639
629
|
}));
|
|
640
|
-
|
|
641
|
-
_(rootContext).setPage(app_app.page);
|
|
642
630
|
});
|
|
643
631
|
});
|
|
644
632
|
|
|
645
633
|
function ViewContext(view, page) {
|
|
646
634
|
var self = this;
|
|
635
|
+
watch(self, true);
|
|
647
636
|
defineOwnProperty(self, 'view', view, true);
|
|
648
637
|
|
|
649
638
|
_(self, {
|
|
650
639
|
children: [],
|
|
651
640
|
setPage: defineObservableProperty(self, 'page', page, true),
|
|
652
|
-
setActive: defineObservableProperty(self, 'active',
|
|
641
|
+
setActive: defineObservableProperty(self, 'active', !!page, true)
|
|
653
642
|
});
|
|
654
643
|
|
|
655
644
|
watch(self, 'page', function (page, previousPage) {
|
|
@@ -1000,26 +989,24 @@ function redirectTo(view, params, data) {
|
|
|
1000
989
|
|
|
1001
990
|
|
|
1002
991
|
|
|
1003
|
-
|
|
1004
992
|
var hooks_emitter = new ZetaEventContainer();
|
|
1005
993
|
|
|
1006
994
|
function getCurrentStates() {
|
|
1007
995
|
return app_app.historyStorage.current;
|
|
1008
996
|
}
|
|
1009
997
|
|
|
1010
|
-
function ViewState(key,
|
|
998
|
+
function ViewState(key, dispose) {
|
|
1011
999
|
this.key = key;
|
|
1012
|
-
this.
|
|
1000
|
+
this.store = getCurrentStates();
|
|
1001
|
+
this.dispose = dispose;
|
|
1013
1002
|
}
|
|
1014
1003
|
|
|
1015
1004
|
definePrototype(ViewState, {
|
|
1016
1005
|
get: function get() {
|
|
1017
|
-
return this.
|
|
1006
|
+
return this.store.get(this.key);
|
|
1018
1007
|
},
|
|
1019
1008
|
set: function set(value) {
|
|
1020
|
-
|
|
1021
|
-
self.value = value;
|
|
1022
|
-
self.store.set(self.key, value);
|
|
1009
|
+
this.store.set(this.key, value);
|
|
1023
1010
|
},
|
|
1024
1011
|
onPopState: function onPopState(callback) {
|
|
1025
1012
|
throwNotFunction(callback);
|
|
@@ -1028,6 +1015,34 @@ definePrototype(ViewState, {
|
|
|
1028
1015
|
});
|
|
1029
1016
|
}
|
|
1030
1017
|
});
|
|
1018
|
+
|
|
1019
|
+
function updateViewState(state, key, store) {
|
|
1020
|
+
var newValue = state.get();
|
|
1021
|
+
|
|
1022
|
+
if (key !== state.key || store !== state.store && store.has(key)) {
|
|
1023
|
+
newValue = store.get(key);
|
|
1024
|
+
hooks_emitter.emit('popstate', state, {
|
|
1025
|
+
newValue: newValue
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
state.key = key;
|
|
1030
|
+
state.store = store;
|
|
1031
|
+
store.set(key, newValue);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
function useViewContextWithEffect(callback, deps) {
|
|
1035
|
+
var container = useViewContext();
|
|
1036
|
+
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
1037
|
+
return app_app.on('beforepageload popstate', function () {
|
|
1038
|
+
if (container.active) {
|
|
1039
|
+
callback(getCurrentStates());
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
}, deps);
|
|
1043
|
+
return container;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1031
1046
|
function useAppReady() {
|
|
1032
1047
|
return useAppReadyState().ready;
|
|
1033
1048
|
}
|
|
@@ -1079,11 +1094,18 @@ function useRouteParam(name, defaultValue) {
|
|
|
1079
1094
|
return value;
|
|
1080
1095
|
}
|
|
1081
1096
|
function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
1082
|
-
var container = useViewContext();
|
|
1083
1097
|
var cur = getCurrentStates();
|
|
1084
|
-
var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(cur.has(key) ? cur.get(key) : defaultValue);
|
|
1098
|
+
var state = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(cur && cur.has(key) ? cur.get(key) : defaultValue);
|
|
1099
|
+
var container = useViewContextWithEffect(function (cur) {
|
|
1100
|
+
state[1](function (oldValue) {
|
|
1101
|
+
return cur.has(key) ? cur.get(key) : (cur.set(key, oldValue), oldValue);
|
|
1102
|
+
});
|
|
1103
|
+
}, [key]);
|
|
1085
1104
|
|
|
1086
|
-
if (
|
|
1105
|
+
if (!cur) {
|
|
1106
|
+
// delay app ready to ensure that beforepageload event can be caught
|
|
1107
|
+
app_app.beforeInit(delay(1));
|
|
1108
|
+
} else if (container.active && cur.get(key) !== state[0]) {
|
|
1087
1109
|
if (snapshotOnUpdate && cur.has(key)) {
|
|
1088
1110
|
app_app.snapshot();
|
|
1089
1111
|
cur = getCurrentStates();
|
|
@@ -1092,44 +1114,27 @@ function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
|
1092
1114
|
cur.set(key, state[0]);
|
|
1093
1115
|
}
|
|
1094
1116
|
|
|
1095
|
-
(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
|
|
1096
|
-
if (snapshotOnUpdate) {
|
|
1097
|
-
return bind(window, 'popstate', function () {
|
|
1098
|
-
if (container.active) {
|
|
1099
|
-
var cur = getCurrentStates();
|
|
1100
|
-
state[1](cur.has(key) ? cur.get(key) : defaultValue);
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
}, [container, snapshotOnUpdate]);
|
|
1105
1117
|
return state;
|
|
1106
1118
|
}
|
|
1107
1119
|
function ViewStateContainer(props) {
|
|
1108
|
-
var
|
|
1120
|
+
var cache = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)({})[0];
|
|
1121
|
+
var container = useViewContextWithEffect(function (cur) {
|
|
1122
|
+
each(cache, function (i, v) {
|
|
1123
|
+
updateViewState(v, v.key, cur);
|
|
1124
|
+
});
|
|
1125
|
+
}, []);
|
|
1109
1126
|
var provider = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
|
|
1110
|
-
var cache = {};
|
|
1111
1127
|
return {
|
|
1112
1128
|
getState: function getState(uniqueId, key) {
|
|
1113
|
-
var
|
|
1114
|
-
var value = cur.get(key);
|
|
1115
|
-
var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(key, value));
|
|
1116
|
-
|
|
1117
|
-
if (container.active) {
|
|
1118
|
-
var store = state.store;
|
|
1119
|
-
|
|
1120
|
-
if (store && (store !== cur && cur.has(key) || key !== state.key)) {
|
|
1121
|
-
hooks_emitter.emit('popstate', state, {
|
|
1122
|
-
newValue: value
|
|
1123
|
-
});
|
|
1124
|
-
state.value = value;
|
|
1125
|
-
state.key = key;
|
|
1126
|
-
}
|
|
1129
|
+
var state = cache[uniqueId];
|
|
1127
1130
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1131
|
+
if (state && container.active) {
|
|
1132
|
+
updateViewState(state, key, getCurrentStates());
|
|
1130
1133
|
}
|
|
1131
1134
|
|
|
1132
|
-
return state
|
|
1135
|
+
return state || (cache[uniqueId] = new ViewState(key, function () {
|
|
1136
|
+
delete cache[uniqueId];
|
|
1137
|
+
}));
|
|
1133
1138
|
}
|
|
1134
1139
|
};
|
|
1135
1140
|
})[0];
|