brew-js-react 0.2.5 → 0.2.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/dialog.js +4 -4
- package/dist/brew-js-react.js +90 -80
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +1 -1
- package/dist/brew-js-react.min.js.map +1 -1
- package/hooks.js +8 -4
- package/mixin.d.ts +3 -0
- package/mixins/ClassNameMixin.js +2 -2
- package/mixins/ErrorHandlerMixin.d.ts +3 -0
- package/mixins/FlyoutMixin.js +4 -0
- package/mixins/StatefulMixin.d.ts +1 -0
- package/mixins/StatefulMixin.js +10 -2
- package/package.json +3 -3
- package/view.js +225 -234
package/dialog.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
-
import { always, catchAsync, either, extend, noop, pipe
|
|
3
|
+
import { always, catchAsync, either, extend, makeAsync, noop, pipe } from "./include/zeta-dom/util.js";
|
|
4
4
|
import { containsOrEquals, removeNode } from "./include/zeta-dom/domUtil.js";
|
|
5
5
|
import dom from "./include/zeta-dom/dom.js";
|
|
6
6
|
import { lock } from "./include/zeta-dom/domLock.js";
|
|
@@ -45,9 +45,9 @@ export function createDialog(props) {
|
|
|
45
45
|
if (props.onRender) {
|
|
46
46
|
var dialogProps = extend({}, props, {
|
|
47
47
|
closeDialog: function (value) {
|
|
48
|
-
var promise =
|
|
48
|
+
var promise = makeAsync(props.onCommit || pipe)(value);
|
|
49
49
|
catchAsync(lock(dom.activeElement, promise));
|
|
50
|
-
promise.then(closeDialog);
|
|
50
|
+
promise.then(closeDialog, noop);
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
ReactDOM.render(React.createElement(props.onRender, dialogProps), root);
|
|
@@ -66,7 +66,7 @@ export function createDialog(props) {
|
|
|
66
66
|
* @param {import("./dialog").DialogProps} props
|
|
67
67
|
*/
|
|
68
68
|
export function Dialog(props) {
|
|
69
|
-
const _props = useState(
|
|
69
|
+
const _props = useState({})[0];
|
|
70
70
|
const dialog = useState(function () {
|
|
71
71
|
return createDialog(_props);
|
|
72
72
|
})[0];
|
package/dist/brew-js-react.js
CHANGED
|
@@ -210,7 +210,8 @@ var _defaultExport = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_roo
|
|
|
210
210
|
/* harmony default export */ const app = (_defaultExport);
|
|
211
211
|
var install = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.install,
|
|
212
212
|
addExtension = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addExtension,
|
|
213
|
-
addDetect = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addDetect
|
|
213
|
+
addDetect = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addDetect,
|
|
214
|
+
isElementActive = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isElementActive;
|
|
214
215
|
|
|
215
216
|
;// CONCATENATED MODULE: ./src/include/brew-js/app.js
|
|
216
217
|
|
|
@@ -296,8 +297,12 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
|
|
|
296
297
|
reject = _lib$util.reject,
|
|
297
298
|
always = _lib$util.always,
|
|
298
299
|
resolveAll = _lib$util.resolveAll,
|
|
300
|
+
retryable = _lib$util.retryable,
|
|
301
|
+
deferrable = _lib$util.deferrable,
|
|
299
302
|
catchAsync = _lib$util.catchAsync,
|
|
300
|
-
setPromiseTimeout = _lib$util.setPromiseTimeout
|
|
303
|
+
setPromiseTimeout = _lib$util.setPromiseTimeout,
|
|
304
|
+
delay = _lib$util.delay,
|
|
305
|
+
makeAsync = _lib$util.makeAsync;
|
|
301
306
|
|
|
302
307
|
;// CONCATENATED MODULE: ./src/include/zeta-dom/util.js
|
|
303
308
|
|
|
@@ -439,9 +444,9 @@ function createDialog(props) {
|
|
|
439
444
|
if (props.onRender) {
|
|
440
445
|
var dialogProps = extend({}, props, {
|
|
441
446
|
closeDialog: function closeDialog(value) {
|
|
442
|
-
var promise =
|
|
447
|
+
var promise = makeAsync(props.onCommit || pipe)(value);
|
|
443
448
|
catchAsync(lock(zeta_dom_dom.activeElement, promise));
|
|
444
|
-
promise.then(_closeDialog);
|
|
449
|
+
promise.then(_closeDialog, noop);
|
|
445
450
|
}
|
|
446
451
|
});
|
|
447
452
|
external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.render( /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(props.onRender, dialogProps), root);
|
|
@@ -461,7 +466,7 @@ function createDialog(props) {
|
|
|
461
466
|
*/
|
|
462
467
|
|
|
463
468
|
function Dialog(props) {
|
|
464
|
-
var _props = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(
|
|
469
|
+
var _props = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)({})[0];
|
|
465
470
|
var dialog = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
|
|
466
471
|
return createDialog(_props);
|
|
467
472
|
})[0];
|
|
@@ -526,7 +531,8 @@ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_br
|
|
|
526
531
|
withBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.withBaseUrl,
|
|
527
532
|
toAbsoluteUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toAbsoluteUrl,
|
|
528
533
|
toRelativeUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toRelativeUrl,
|
|
529
|
-
isSubPathOf = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isSubPathOf
|
|
534
|
+
isSubPathOf = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isSubPathOf,
|
|
535
|
+
toSegments = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toSegments;
|
|
530
536
|
|
|
531
537
|
;// CONCATENATED MODULE: ./src/include/brew-js/util/path.js
|
|
532
538
|
|
|
@@ -540,64 +546,65 @@ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_br
|
|
|
540
546
|
|
|
541
547
|
|
|
542
548
|
|
|
543
|
-
var
|
|
549
|
+
var root = zeta_dom_dom.root;
|
|
544
550
|
var routeMap = new Map();
|
|
545
551
|
var usedParams = {};
|
|
546
552
|
var sortedViews = [];
|
|
547
553
|
var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
|
|
548
554
|
active: true
|
|
549
555
|
}));
|
|
550
|
-
var stateId;
|
|
551
556
|
|
|
552
557
|
function ViewContainer() {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(self, arguments);
|
|
556
|
-
self.mounted = false;
|
|
557
|
-
|
|
558
|
-
if (!stateId) {
|
|
559
|
-
stateId = history.state;
|
|
560
|
-
app_app.on('navigate', function () {
|
|
561
|
-
stateId = history.state;
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
self.componentWillUnmount = app_app.on('navigate', function () {
|
|
566
|
-
if (self.mounted && self.getViewComponent()) {
|
|
567
|
-
self.isForceUpdate = true;
|
|
568
|
-
self.forceUpdate();
|
|
569
|
-
}
|
|
570
|
-
});
|
|
558
|
+
external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
|
|
559
|
+
this.stateId = history.state;
|
|
571
560
|
}
|
|
572
561
|
|
|
573
562
|
definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react_root_React_.Component, {
|
|
574
563
|
componentDidMount: function componentDidMount() {
|
|
575
|
-
|
|
564
|
+
/** @type {any} */
|
|
565
|
+
var self = this;
|
|
566
|
+
self.componentWillUnmount = combineFn(watch(app_app.route, function () {
|
|
567
|
+
self.setActive(self.getViewComponent() === self.currentViewComponent);
|
|
568
|
+
}), app_app.on('beforepageload', function (e) {
|
|
569
|
+
self.waitFor = e.waitFor;
|
|
570
|
+
self.stateId = history.state;
|
|
571
|
+
self.forceUpdate();
|
|
572
|
+
}));
|
|
576
573
|
},
|
|
577
574
|
componentDidCatch: function componentDidCatch(error) {
|
|
578
|
-
zeta_dom_dom.emit('error', this.parentElement ||
|
|
575
|
+
zeta_dom_dom.emit('error', this.parentElement || root, {
|
|
579
576
|
error: error
|
|
580
577
|
}, true);
|
|
581
578
|
},
|
|
582
579
|
render: function render() {
|
|
583
580
|
/** @type {any} */
|
|
584
581
|
var self = this;
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
582
|
+
|
|
583
|
+
if (history.state !== self.stateId) {
|
|
584
|
+
return self.lastChild || null;
|
|
585
|
+
}
|
|
586
|
+
|
|
589
587
|
var V = self.getViewComponent();
|
|
590
588
|
|
|
589
|
+
if (V) {
|
|
590
|
+
// ensure the current path actually corresponds to the matched view
|
|
591
|
+
// when some views are not included in the list of allowed views
|
|
592
|
+
var targetPath = linkTo(V, getCurrentParams(V, true));
|
|
593
|
+
|
|
594
|
+
if (targetPath !== removeQueryAndHash(app_app.path)) {
|
|
595
|
+
app_app.navigate(targetPath, true);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
591
599
|
if (V && V !== self.currentViewComponent) {
|
|
592
|
-
|
|
600
|
+
var prevElement = self.currentElement;
|
|
593
601
|
|
|
594
|
-
if (
|
|
595
|
-
|
|
596
|
-
var prevElement = self.currentElement;
|
|
602
|
+
if (prevElement) {
|
|
603
|
+
self.setActive(false);
|
|
597
604
|
self.prevView = self.currentView;
|
|
598
605
|
self.currentElement = undefined;
|
|
599
606
|
app_app.emit('pageleave', prevElement, {
|
|
600
|
-
pathname:
|
|
607
|
+
pathname: self.currentPath
|
|
601
608
|
}, true);
|
|
602
609
|
animateOut(prevElement, 'show').then(function () {
|
|
603
610
|
self.prevView = undefined;
|
|
@@ -605,15 +612,19 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
605
612
|
});
|
|
606
613
|
}
|
|
607
614
|
|
|
608
|
-
var
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
615
|
+
var resolve;
|
|
616
|
+
var promise = new Promise(function (resolve_) {
|
|
617
|
+
resolve = resolve_;
|
|
618
|
+
});
|
|
619
|
+
var state = {
|
|
620
|
+
view: V
|
|
613
621
|
};
|
|
614
|
-
var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider,
|
|
622
|
+
var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, {
|
|
623
|
+
key: routeMap.get(V).id,
|
|
624
|
+
value: state
|
|
625
|
+
}, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
|
|
615
626
|
rootProps: self.props.rootProps,
|
|
616
|
-
onComponentLoaded: function
|
|
627
|
+
onComponentLoaded: executeOnce(function (element) {
|
|
617
628
|
self.currentElement = element;
|
|
618
629
|
self.parentElement = element.parentElement;
|
|
619
630
|
util_setImmediate(function () {
|
|
@@ -623,42 +634,25 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
623
634
|
pathname: app_app.path
|
|
624
635
|
}, true);
|
|
625
636
|
});
|
|
626
|
-
}
|
|
637
|
+
})
|
|
627
638
|
})));
|
|
628
|
-
|
|
629
|
-
|
|
639
|
+
extend(self, {
|
|
640
|
+
currentPath: app_app.path,
|
|
641
|
+
currentView: view,
|
|
642
|
+
currentViewComponent: V,
|
|
643
|
+
setActive: defineObservableProperty(state, 'active', true, true)
|
|
630
644
|
});
|
|
631
|
-
self.
|
|
632
|
-
self.
|
|
633
|
-
} else {
|
|
634
|
-
if (self.isForceUpdate) {
|
|
635
|
-
self.isForceUpdate = false;
|
|
636
|
-
app_app.emit('pageenter', self.currentElement, {
|
|
637
|
-
pathname: app_app.path
|
|
638
|
-
}, true);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
resolve();
|
|
645
|
+
(self.waitFor || noop)(promise);
|
|
646
|
+
notifyAsync(self.parentElement || root, promise);
|
|
642
647
|
}
|
|
643
648
|
|
|
644
|
-
|
|
645
|
-
|
|
649
|
+
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);
|
|
650
|
+
self.lastChild = child;
|
|
651
|
+
return child;
|
|
646
652
|
},
|
|
647
653
|
getViewComponent: function getViewComponent() {
|
|
648
654
|
var props = this.props;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (history.state === stateId) {
|
|
652
|
-
// ensure the current path actually corresponds to the matched view
|
|
653
|
-
// when some views are not included in the list of allowed views
|
|
654
|
-
var targetPath = linkTo(matched, getCurrentParams(matched, true));
|
|
655
|
-
|
|
656
|
-
if (targetPath !== removeQueryAndHash(app_app.path)) {
|
|
657
|
-
app_app.navigate(targetPath, true);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
return matched;
|
|
655
|
+
return any(props.views, isViewMatched) || props.defaultView;
|
|
662
656
|
}
|
|
663
657
|
});
|
|
664
658
|
|
|
@@ -740,7 +734,7 @@ function registerView(factory, routeParams) {
|
|
|
740
734
|
}
|
|
741
735
|
|
|
742
736
|
return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement('div', extend({}, props.rootProps, {
|
|
743
|
-
ref: ref,
|
|
737
|
+
ref: (0,external_zeta_dom_react_.combineRef)(ref, state[1].elementRef),
|
|
744
738
|
children: state[0] && /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(state[0]["default"])
|
|
745
739
|
}));
|
|
746
740
|
};
|
|
@@ -846,9 +840,13 @@ function useRouteParam(name, defaultValue) {
|
|
|
846
840
|
var setValue = function setValue() {
|
|
847
841
|
var current = route[name] || '';
|
|
848
842
|
|
|
849
|
-
if (
|
|
850
|
-
|
|
851
|
-
|
|
843
|
+
if (current !== ref.current) {
|
|
844
|
+
if (container.active) {
|
|
845
|
+
ref.current = current;
|
|
846
|
+
forceUpdate({});
|
|
847
|
+
} else {
|
|
848
|
+
watch(container, 'active', setValue);
|
|
849
|
+
}
|
|
852
850
|
}
|
|
853
851
|
}; // route parameter might be changed after state initialization and before useEffect hook is called
|
|
854
852
|
|
|
@@ -1113,6 +1111,8 @@ function StatefulMixin() {
|
|
|
1113
1111
|
|
|
1114
1112
|
_(this, {
|
|
1115
1113
|
elements: new WeakSet(),
|
|
1114
|
+
flush: watch(this, false),
|
|
1115
|
+
dispose: [],
|
|
1116
1116
|
states: {},
|
|
1117
1117
|
prefix: '',
|
|
1118
1118
|
counter: 0
|
|
@@ -1159,6 +1159,9 @@ definePrototype(StatefulMixin, Mixin, {
|
|
|
1159
1159
|
return v;
|
|
1160
1160
|
});
|
|
1161
1161
|
},
|
|
1162
|
+
onDispose: function onDispose(callback) {
|
|
1163
|
+
_(this).dispose.push(callback);
|
|
1164
|
+
},
|
|
1162
1165
|
initState: function initState() {
|
|
1163
1166
|
return {
|
|
1164
1167
|
element: null
|
|
@@ -1177,8 +1180,11 @@ definePrototype(StatefulMixin, Mixin, {
|
|
|
1177
1180
|
return clone;
|
|
1178
1181
|
},
|
|
1179
1182
|
dispose: function dispose() {
|
|
1180
|
-
var
|
|
1183
|
+
var state = _(this);
|
|
1181
1184
|
|
|
1185
|
+
var states = state.states;
|
|
1186
|
+
combineFn(state.dispose.splice(0))();
|
|
1187
|
+
state.flush();
|
|
1182
1188
|
each(states, function (i, v) {
|
|
1183
1189
|
delete states[i];
|
|
1184
1190
|
});
|
|
@@ -1202,7 +1208,7 @@ function checkState(self, element, state, isAsync) {
|
|
|
1202
1208
|
var cb = self.onClassNameUpdated.bind(self, element, prev, extend({}, classNames));
|
|
1203
1209
|
|
|
1204
1210
|
if (isAsync) {
|
|
1205
|
-
|
|
1211
|
+
util_setImmediate(cb);
|
|
1206
1212
|
} else {
|
|
1207
1213
|
cb();
|
|
1208
1214
|
}
|
|
@@ -1221,7 +1227,7 @@ definePrototype(ClassNameMixin, StatefulMixin, {
|
|
|
1221
1227
|
var self = this;
|
|
1222
1228
|
var element = self.state.element;
|
|
1223
1229
|
|
|
1224
|
-
if (element && containsOrEquals(root, element)) {
|
|
1230
|
+
if (element && containsOrEquals(zeta_dom_dom.root, element)) {
|
|
1225
1231
|
checkState(self, element, self.state, true);
|
|
1226
1232
|
}
|
|
1227
1233
|
|
|
@@ -1399,6 +1405,10 @@ function FlyoutMixin() {
|
|
|
1399
1405
|
self.animating = false;
|
|
1400
1406
|
self.visible = false;
|
|
1401
1407
|
self.toggle = new FlyoutToggleMixin(self);
|
|
1408
|
+
self.onDispose(function () {
|
|
1409
|
+
self.isFlyoutOpened = false;
|
|
1410
|
+
self.visible = false;
|
|
1411
|
+
});
|
|
1402
1412
|
}
|
|
1403
1413
|
definePrototype(FlyoutMixin, ClassNameMixin, {
|
|
1404
1414
|
reset: function reset() {
|