brew-js-react 0.6.3 → 0.6.5
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.d.ts +57 -21
- package/dialog.js +10 -4
- package/dist/brew-js-react.js +172 -134
- 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/i18n.d.ts +34 -47
- package/mixins/ClassNameMixin.d.ts +1 -1
- package/mixins/ScrollableMixin.d.ts +3 -1
- package/mixins/StaticAttributeMixin.d.ts +1 -1
- package/package.json +6 -4
- package/view.d.ts +72 -13
- package/view.js +127 -104
package/dist/brew-js-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! brew-js-react v0.6.
|
|
1
|
+
/*! brew-js-react v0.6.5 | (c) misonou | https://misonou.github.io */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory(require("zeta-dom"), require("brew-js"), require("react"), require("react-dom"), require("zeta-dom-react"), require("waterpipe"), require("jquery"));
|
|
@@ -181,6 +181,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
181
181
|
ScrollableMixin: () => (/* reexport */ ScrollableMixin),
|
|
182
182
|
StatefulMixin: () => (/* reexport */ StatefulMixin),
|
|
183
183
|
UnmanagedClassNameMixin: () => (/* reexport */ UnmanagedClassNameMixin),
|
|
184
|
+
ViewContext: () => (/* reexport */ ViewContext),
|
|
184
185
|
ViewStateContainer: () => (/* reexport */ ViewStateContainer),
|
|
185
186
|
createDialog: () => (/* reexport */ createDialog),
|
|
186
187
|
isViewMatched: () => (/* reexport */ isViewMatched),
|
|
@@ -220,6 +221,7 @@ var external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_ = __we
|
|
|
220
221
|
;// CONCATENATED MODULE: ./|umd|/zeta-dom/util.js
|
|
221
222
|
|
|
222
223
|
var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.util,
|
|
224
|
+
always = _lib$util.always,
|
|
223
225
|
any = _lib$util.any,
|
|
224
226
|
arrRemove = _lib$util.arrRemove,
|
|
225
227
|
catchAsync = _lib$util.catchAsync,
|
|
@@ -301,12 +303,12 @@ var external_commonjs_react_commonjs2_react_amd_react_root_React_ = __webpack_re
|
|
|
301
303
|
;// CONCATENATED MODULE: ./|umd|/react.js
|
|
302
304
|
|
|
303
305
|
var Component = external_commonjs_react_commonjs2_react_amd_react_root_React_.Component,
|
|
304
|
-
Fragment = external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment,
|
|
305
306
|
StrictMode = external_commonjs_react_commonjs2_react_amd_react_root_React_.StrictMode,
|
|
306
307
|
createContext = external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext,
|
|
307
308
|
createElement = external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement,
|
|
308
309
|
useContext = external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext,
|
|
309
310
|
useEffect = external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect,
|
|
311
|
+
useLayoutEffect = external_commonjs_react_commonjs2_react_amd_react_root_React_.useLayoutEffect,
|
|
310
312
|
useMemo = external_commonjs_react_commonjs2_react_amd_react_root_React_.useMemo,
|
|
311
313
|
useRef = external_commonjs_react_commonjs2_react_amd_react_root_React_.useRef,
|
|
312
314
|
useState = external_commonjs_react_commonjs2_react_amd_react_root_React_.useState;
|
|
@@ -315,6 +317,20 @@ var Component = external_commonjs_react_commonjs2_react_amd_react_root_React_.Co
|
|
|
315
317
|
var external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_ = __webpack_require__(33);
|
|
316
318
|
// EXTERNAL MODULE: ./node_modules/@misonou/react-dom-client/fallback.js
|
|
317
319
|
var fallback = __webpack_require__(621);
|
|
320
|
+
// EXTERNAL MODULE: external {"commonjs":"zeta-dom-react","commonjs2":"zeta-dom-react","amd":"zeta-dom-react","root":["zeta","react"]}
|
|
321
|
+
var external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_ = __webpack_require__(402);
|
|
322
|
+
;// CONCATENATED MODULE: ./|umd|/zeta-dom-react.js
|
|
323
|
+
|
|
324
|
+
var ViewStateProvider = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.ViewStateProvider,
|
|
325
|
+
classNames = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.classNames,
|
|
326
|
+
createAsyncScope = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.createAsyncScope,
|
|
327
|
+
useAsync = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useAsync,
|
|
328
|
+
useEagerState = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useEagerState,
|
|
329
|
+
useMemoizedFunction = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useMemoizedFunction,
|
|
330
|
+
useObservableProperty = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useObservableProperty,
|
|
331
|
+
useSingleton = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useSingleton,
|
|
332
|
+
useValueTrigger = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useValueTrigger;
|
|
333
|
+
|
|
318
334
|
;// CONCATENATED MODULE: ./|umd|/zeta-dom/domUtil.js
|
|
319
335
|
|
|
320
336
|
var domUtil_lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.util,
|
|
@@ -355,12 +371,14 @@ var closeFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_b
|
|
|
355
371
|
|
|
356
372
|
|
|
357
373
|
|
|
374
|
+
|
|
358
375
|
/**
|
|
359
376
|
* @param {Partial<import("./dialog").DialogOptions<any>>} props
|
|
360
377
|
*/
|
|
361
378
|
function createDialog(props) {
|
|
362
379
|
var root = document.createElement('div');
|
|
363
380
|
var reactRoot = fallback.createRoot(root);
|
|
381
|
+
var scope = createAsyncScope(root);
|
|
364
382
|
var closeDialog = closeFlyout.bind(0, root);
|
|
365
383
|
var promise;
|
|
366
384
|
zeta_dom_dom.on(root, {
|
|
@@ -391,16 +409,20 @@ function createDialog(props) {
|
|
|
391
409
|
root.setAttribute('is-modal', '');
|
|
392
410
|
}
|
|
393
411
|
if (props.onRender) {
|
|
412
|
+
var commitDialog = props.onCommit ? function (value) {
|
|
413
|
+
return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
|
|
414
|
+
} : closeDialog;
|
|
394
415
|
var dialogProps = extend({}, props, {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
416
|
+
errorHandler: scope.errorHandler,
|
|
417
|
+
closeDialog: commitDialog,
|
|
418
|
+
commitDialog: commitDialog,
|
|
419
|
+
dismissDialog: closeDialog
|
|
398
420
|
});
|
|
399
421
|
var content = /*#__PURE__*/createElement(props.onRender, dialogProps);
|
|
400
422
|
if (props.wrapper) {
|
|
401
423
|
content = /*#__PURE__*/createElement(props.wrapper, dialogProps, content);
|
|
402
424
|
}
|
|
403
|
-
reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, content));
|
|
425
|
+
reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, /*#__PURE__*/createElement(scope.Provider, null, content)));
|
|
404
426
|
}
|
|
405
427
|
promise = resolve().then(function () {
|
|
406
428
|
zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, root);
|
|
@@ -440,19 +462,6 @@ function Dialog(props) {
|
|
|
440
462
|
}, [dialog]);
|
|
441
463
|
return /*#__PURE__*/external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.createPortal(props.children, dialog.root);
|
|
442
464
|
}
|
|
443
|
-
// EXTERNAL MODULE: external {"commonjs":"zeta-dom-react","commonjs2":"zeta-dom-react","amd":"zeta-dom-react","root":["zeta","react"]}
|
|
444
|
-
var external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_ = __webpack_require__(402);
|
|
445
|
-
;// CONCATENATED MODULE: ./|umd|/zeta-dom-react.js
|
|
446
|
-
|
|
447
|
-
var ViewStateProvider = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.ViewStateProvider,
|
|
448
|
-
classNames = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.classNames,
|
|
449
|
-
useAsync = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useAsync,
|
|
450
|
-
useEagerState = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useEagerState,
|
|
451
|
-
useMemoizedFunction = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useMemoizedFunction,
|
|
452
|
-
useObservableProperty = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useObservableProperty,
|
|
453
|
-
useSingleton = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useSingleton,
|
|
454
|
-
useValueTrigger = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useValueTrigger;
|
|
455
|
-
|
|
456
465
|
;// CONCATENATED MODULE: ./|umd|/zeta-dom/events.js
|
|
457
466
|
|
|
458
467
|
var EventContainer = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.EventContainer;
|
|
@@ -460,7 +469,8 @@ var EventContainer = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_
|
|
|
460
469
|
;// CONCATENATED MODULE: ./|umd|/brew-js/util/common.js
|
|
461
470
|
|
|
462
471
|
var getQueryParam = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.getQueryParam,
|
|
463
|
-
setQueryParam = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.setQueryParam
|
|
472
|
+
setQueryParam = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.setQueryParam,
|
|
473
|
+
toQueryString = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toQueryString;
|
|
464
474
|
|
|
465
475
|
;// CONCATENATED MODULE: ./|umd|/brew-js/util/path.js
|
|
466
476
|
|
|
@@ -482,6 +492,7 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
|
|
|
482
492
|
|
|
483
493
|
|
|
484
494
|
|
|
495
|
+
|
|
485
496
|
var _ = createPrivateStore();
|
|
486
497
|
var root = zeta_dom_dom.root;
|
|
487
498
|
var routeMap = new Map();
|
|
@@ -495,7 +506,9 @@ var rootState = _(rootContext);
|
|
|
495
506
|
var StateContext = /*#__PURE__*/createContext(rootContext);
|
|
496
507
|
var errorView;
|
|
497
508
|
/** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
|
|
498
|
-
var view_event = {
|
|
509
|
+
var view_event = {
|
|
510
|
+
waitFor: noop
|
|
511
|
+
};
|
|
499
512
|
onAppInit(function () {
|
|
500
513
|
app_app.on('beforepageload', function (e) {
|
|
501
514
|
rootState.setPage(app_app.page);
|
|
@@ -532,86 +545,109 @@ function ViewContext(view, page, parent) {
|
|
|
532
545
|
});
|
|
533
546
|
});
|
|
534
547
|
}
|
|
548
|
+
defineOwnProperty(ViewContext, 'root', rootContext, true);
|
|
535
549
|
definePrototype(ViewContext, {
|
|
536
550
|
getChildren: function getChildren() {
|
|
537
551
|
return map(_(this).children, function (v) {
|
|
538
552
|
return v.currentContext;
|
|
539
553
|
});
|
|
540
554
|
},
|
|
555
|
+
setErrorView: function setErrorView(errorView, error) {
|
|
556
|
+
var wrapper = _(this).wrapper;
|
|
557
|
+
return wrapper && errorView && !wrapper.setState({
|
|
558
|
+
error: error,
|
|
559
|
+
errorView: errorView
|
|
560
|
+
});
|
|
561
|
+
},
|
|
541
562
|
on: function on(event, handler) {
|
|
542
563
|
return emitter.add(this, event, handler);
|
|
543
564
|
}
|
|
544
565
|
});
|
|
545
|
-
function ErrorBoundary() {
|
|
546
|
-
Component.
|
|
566
|
+
function ErrorBoundary(props) {
|
|
567
|
+
Component.call(this, props);
|
|
547
568
|
this.state = {};
|
|
569
|
+
_(props.context).wrapper = this;
|
|
548
570
|
}
|
|
549
|
-
ErrorBoundary.contextType = StateContext;
|
|
550
571
|
definePrototype(ErrorBoundary, Component, {
|
|
572
|
+
componentDidMount: function componentDidMount() {
|
|
573
|
+
var self = this;
|
|
574
|
+
self.componentWillUnmount = watch(self.props.context, 'page', function () {
|
|
575
|
+
self.state.errorView = null;
|
|
576
|
+
self.forceUpdate();
|
|
577
|
+
});
|
|
578
|
+
},
|
|
551
579
|
componentDidCatch: function componentDidCatch(error) {
|
|
552
580
|
var self = this;
|
|
553
|
-
if (errorView &&
|
|
581
|
+
if (errorView && self.state.errorView !== errorView) {
|
|
554
582
|
self.setState({
|
|
555
|
-
error: error
|
|
583
|
+
error: error,
|
|
584
|
+
errorView: errorView
|
|
556
585
|
});
|
|
557
586
|
} else {
|
|
558
|
-
|
|
559
|
-
self.props.
|
|
560
|
-
reportError(error, self.context.container);
|
|
587
|
+
self.props.onLoad();
|
|
588
|
+
reportError(error, self.props.context.container);
|
|
561
589
|
}
|
|
562
590
|
},
|
|
563
591
|
render: function render() {
|
|
564
592
|
var self = this;
|
|
565
|
-
|
|
593
|
+
var context = self.props.context;
|
|
594
|
+
if (!context.container) {
|
|
566
595
|
setImmediate(function () {
|
|
596
|
+
extend(self, createAsyncScope(context.container));
|
|
597
|
+
zeta_dom_dom.on(context.container, 'error', function (e) {
|
|
598
|
+
return emitter.emit(e, context, {
|
|
599
|
+
error: e.error
|
|
600
|
+
});
|
|
601
|
+
});
|
|
567
602
|
self.forceUpdate();
|
|
568
603
|
});
|
|
569
604
|
return null;
|
|
570
605
|
}
|
|
571
|
-
var
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
return /*#__PURE__*/createElement(errorView, {
|
|
580
|
-
onComponentLoaded: onComponentLoaded,
|
|
581
|
-
onError: onError,
|
|
582
|
-
viewProps: props
|
|
583
|
-
});
|
|
606
|
+
var errorView = self.state.errorView;
|
|
607
|
+
if (errorView) {
|
|
608
|
+
self.props.onLoad();
|
|
609
|
+
return /*#__PURE__*/createElement(self.Provider, null, /*#__PURE__*/createElement(self.state.errorView, {
|
|
610
|
+
view: context.view,
|
|
611
|
+
error: self.state.error,
|
|
612
|
+
reset: self.reset.bind(self)
|
|
613
|
+
}));
|
|
584
614
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
615
|
+
var onError = self.componentDidCatch.bind(self);
|
|
616
|
+
var viewProps = {
|
|
617
|
+
errorHandler: self.errorHandler,
|
|
618
|
+
navigationType: view_event.navigationType,
|
|
619
|
+
viewContext: context,
|
|
620
|
+
viewData: context.page.data || {}
|
|
621
|
+
};
|
|
622
|
+
return /*#__PURE__*/createElement(self.Provider, null, /*#__PURE__*/createElement(context.view, extend({
|
|
623
|
+
viewProps: viewProps,
|
|
624
|
+
onError: onError
|
|
625
|
+
}, self.props)));
|
|
590
626
|
},
|
|
591
627
|
reset: function reset() {
|
|
592
628
|
this.setState({
|
|
593
|
-
|
|
629
|
+
errorView: null
|
|
594
630
|
});
|
|
595
631
|
}
|
|
596
632
|
});
|
|
597
633
|
function ViewContainer() {
|
|
598
634
|
Component.apply(this, arguments);
|
|
635
|
+
this.views = [];
|
|
599
636
|
}
|
|
600
637
|
ViewContainer.contextType = StateContext;
|
|
601
638
|
definePrototype(ViewContainer, Component, {
|
|
602
|
-
setActive: noop,
|
|
603
639
|
componentDidMount: function componentDidMount() {
|
|
604
640
|
var self = this;
|
|
605
641
|
var parent = _(self.context).children;
|
|
606
642
|
var unwatch = watch(app_app.route, function () {
|
|
607
|
-
self.setActive(self.getViewComponent() === self.
|
|
643
|
+
self.setActive(self.getViewComponent() === (self.currentContext || '').view);
|
|
608
644
|
});
|
|
609
645
|
self.componentWillUnmount = function () {
|
|
610
646
|
self.setActive(false);
|
|
611
647
|
arrRemove(parent, self);
|
|
612
648
|
unwatch();
|
|
613
649
|
setImmediate(function () {
|
|
614
|
-
if (self.
|
|
650
|
+
if (self.currentContext && !self.currentContext.active) {
|
|
615
651
|
self.unmountView();
|
|
616
652
|
}
|
|
617
653
|
});
|
|
@@ -625,13 +661,13 @@ definePrototype(ViewContainer, Component, {
|
|
|
625
661
|
if (self.context.active) {
|
|
626
662
|
self.updateView();
|
|
627
663
|
}
|
|
628
|
-
|
|
629
|
-
return
|
|
664
|
+
self.onRender();
|
|
665
|
+
return self.views;
|
|
630
666
|
},
|
|
631
667
|
updateView: function updateView() {
|
|
632
668
|
var self = this;
|
|
633
669
|
var V = self.getViewComponent();
|
|
634
|
-
var viewChanged = V !== self.
|
|
670
|
+
var viewChanged = V !== (self.currentContext || '').view;
|
|
635
671
|
if (V && (viewChanged || !(self.children || '')[0])) {
|
|
636
672
|
// ensure the current path actually corresponds to the matched view
|
|
637
673
|
// when some views are not included in the list of allowed views
|
|
@@ -641,75 +677,81 @@ definePrototype(ViewContainer, Component, {
|
|
|
641
677
|
return;
|
|
642
678
|
}
|
|
643
679
|
}
|
|
644
|
-
|
|
645
|
-
|
|
680
|
+
var state = routeMap.get(V) || {};
|
|
681
|
+
if ((self.views[2] || '').key === state.id) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
self.views[2] = null;
|
|
685
|
+
self.abort();
|
|
686
|
+
if (!V || !viewChanged) {
|
|
687
|
+
self.setActive(true);
|
|
688
|
+
self.setPage(app_app.page);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
view_event.waitFor(new Promise(function (resolve) {
|
|
646
692
|
var context = new ViewContext(V, app_app.page, self.context);
|
|
647
|
-
var
|
|
648
|
-
var onComponentLoaded;
|
|
649
|
-
var promise = new Promise(function (resolve) {
|
|
650
|
-
onComponentLoaded = resolve;
|
|
651
|
-
});
|
|
652
|
-
var unmountView = onComponentLoaded;
|
|
693
|
+
var rootProps = self.props.rootProps;
|
|
653
694
|
var initElement = executeOnce(function (element) {
|
|
654
|
-
context
|
|
655
|
-
|
|
656
|
-
if (self.currentContext === context) {
|
|
657
|
-
unmountView = function unmountView() {
|
|
658
|
-
self.prevView = self.currentView;
|
|
659
|
-
app_app.emit('pageleave', element, {
|
|
660
|
-
pathname: context.page.path,
|
|
661
|
-
view: V
|
|
662
|
-
}, true);
|
|
663
|
-
animateOut(element, 'show').then(function () {
|
|
664
|
-
self.prevView = undefined;
|
|
665
|
-
self.forceUpdate();
|
|
666
|
-
});
|
|
667
|
-
};
|
|
668
|
-
animateIn(element, 'show', '[brew-view]', true);
|
|
669
|
-
app_app.emit('pageenter', element, {
|
|
670
|
-
pathname: context.page.path,
|
|
671
|
-
view: V
|
|
672
|
-
}, true);
|
|
673
|
-
}
|
|
674
|
-
});
|
|
695
|
+
defineOwnProperty(context, 'container', element, true);
|
|
696
|
+
self.currentContext = self.currentContext || context;
|
|
675
697
|
});
|
|
676
|
-
var
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
698
|
+
var onLoad = executeOnce(function () {
|
|
699
|
+
var element = context.container;
|
|
700
|
+
var promise = self.unmountView();
|
|
701
|
+
self.unmountView = executeOnce(function () {
|
|
702
|
+
state.rendered--;
|
|
703
|
+
self.setActive(false);
|
|
704
|
+
app_app.emit('pageleave', element, {
|
|
705
|
+
pathname: context.page.path,
|
|
706
|
+
view: V
|
|
707
|
+
}, true);
|
|
708
|
+
return animateOut(element, 'show').then(function () {
|
|
709
|
+
self.views[0] = null;
|
|
710
|
+
self.forceUpdate();
|
|
711
|
+
});
|
|
681
712
|
});
|
|
682
|
-
|
|
683
|
-
|
|
713
|
+
always(promise, delay).then(function () {
|
|
714
|
+
app_app.emit('pageenter', element, {
|
|
715
|
+
pathname: context.page.path,
|
|
716
|
+
view: V
|
|
717
|
+
}, true);
|
|
718
|
+
});
|
|
719
|
+
self.views.shift();
|
|
720
|
+
self.currentContext = context;
|
|
721
|
+
extend(self, _(context));
|
|
722
|
+
state.rendered++;
|
|
723
|
+
animateIn(element, 'show', '[brew-view]', true);
|
|
724
|
+
resolve();
|
|
725
|
+
});
|
|
726
|
+
context.on('error', function () {
|
|
727
|
+
return (rootProps.onError || noop).apply(this, arguments);
|
|
728
|
+
});
|
|
729
|
+
self.abort = resolve;
|
|
730
|
+
self.views[2] = /*#__PURE__*/createElement(StateContext.Provider, {
|
|
684
731
|
key: state.id,
|
|
685
732
|
value: context
|
|
686
|
-
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(
|
|
733
|
+
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(exclude(rootProps, ['loader', 'onError']), {
|
|
687
734
|
ref: initElement,
|
|
688
735
|
'brew-view': ''
|
|
689
736
|
}), /*#__PURE__*/createElement(ErrorBoundary, {
|
|
690
|
-
|
|
691
|
-
|
|
737
|
+
onLoad: onLoad,
|
|
738
|
+
context: context,
|
|
739
|
+
self: self,
|
|
740
|
+
loader: rootProps.loader
|
|
692
741
|
}))));
|
|
693
|
-
|
|
694
|
-
currentContext: context,
|
|
695
|
-
currentView: view,
|
|
696
|
-
currentViewComponent: V,
|
|
697
|
-
unmountView: executeOnce(function () {
|
|
698
|
-
self.setActive(false);
|
|
699
|
-
state.rendered--;
|
|
700
|
-
unmountView();
|
|
701
|
-
})
|
|
702
|
-
});
|
|
703
|
-
state.rendered++;
|
|
704
|
-
(view_event.waitFor || noop)(promise);
|
|
705
|
-
}
|
|
706
|
-
(self.setPage || noop)(app_app.page);
|
|
742
|
+
}));
|
|
707
743
|
},
|
|
708
744
|
getViewComponent: function getViewComponent() {
|
|
709
745
|
var props = this.props;
|
|
710
|
-
return any(props.views,
|
|
746
|
+
return any(props.views, function (v) {
|
|
747
|
+
return matchViewParams(v, app_app.route);
|
|
748
|
+
}) || props.defaultView;
|
|
711
749
|
}
|
|
712
750
|
});
|
|
751
|
+
fill(ViewContainer.prototype, 'abort onRender setActive setPage unmountView', noop);
|
|
752
|
+
function normalizePart(value, part) {
|
|
753
|
+
return isUndefinedOrNull(value) || value === '' || value === part ? '' : value[0] === part ? value : part + value;
|
|
754
|
+
}
|
|
713
755
|
function getCurrentParams(view, params) {
|
|
714
756
|
var state = routeMap.get(view);
|
|
715
757
|
if (!state.maxParams) {
|
|
@@ -760,38 +802,32 @@ function createViewComponent(factory) {
|
|
|
760
802
|
factory = createElement.bind(null, factory);
|
|
761
803
|
}
|
|
762
804
|
return function fn(props) {
|
|
763
|
-
var
|
|
764
|
-
var viewProps = useState(props.viewProps);
|
|
765
|
-
var children = !promise && factory(viewProps[0]);
|
|
805
|
+
var children = promise || factory(props.viewProps);
|
|
766
806
|
if (isThenable(children)) {
|
|
767
807
|
promise = children;
|
|
768
|
-
children = null;
|
|
769
808
|
catchAsync(promise);
|
|
809
|
+
} else {
|
|
810
|
+
useLayoutEffect(props.onLoad, []);
|
|
811
|
+
return children;
|
|
770
812
|
}
|
|
771
|
-
var
|
|
772
|
-
return promise.then(null,
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
useEffect(function () {
|
|
776
|
-
state.elementRef(viewContext.container);
|
|
777
|
-
// listen to property directly so that it is invoked after pagechange event handlers in actual component
|
|
778
|
-
return watch(viewContext, 'page', function () {
|
|
779
|
-
viewProps[1](props.viewProps);
|
|
813
|
+
var component = useAsync(function () {
|
|
814
|
+
return promise.then(null, function (error) {
|
|
815
|
+
promise = null;
|
|
816
|
+
props.onError(error);
|
|
780
817
|
});
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
}, [loaded]);
|
|
787
|
-
return children || (state.value ? /*#__PURE__*/createElement(state.value["default"], viewProps[0]) : null);
|
|
818
|
+
})[0];
|
|
819
|
+
if (component) {
|
|
820
|
+
props.onLoad();
|
|
821
|
+
}
|
|
822
|
+
return component ? /*#__PURE__*/createElement(component["default"], props.viewProps) : props.self.currentContext === props.context && props.loader || null;
|
|
788
823
|
};
|
|
789
824
|
}
|
|
790
825
|
function useViewContext() {
|
|
791
826
|
return useContext(StateContext);
|
|
792
827
|
}
|
|
793
828
|
function isViewMatched(view) {
|
|
794
|
-
|
|
829
|
+
var route = app_app.route;
|
|
830
|
+
return matchViewParams(view, route) && resolvePath(view, route) === route.toString();
|
|
795
831
|
}
|
|
796
832
|
function isViewRendered(view) {
|
|
797
833
|
return !!(routeMap.get(view) || '').rendered;
|
|
@@ -830,7 +866,7 @@ function registerView(factory, routeParams) {
|
|
|
830
866
|
return Component;
|
|
831
867
|
}
|
|
832
868
|
function registerErrorView(factory) {
|
|
833
|
-
errorView =
|
|
869
|
+
errorView = throwNotFunction(factory);
|
|
834
870
|
}
|
|
835
871
|
function renderView() {
|
|
836
872
|
var views = makeArray(arguments);
|
|
@@ -849,10 +885,12 @@ function renderView() {
|
|
|
849
885
|
});
|
|
850
886
|
}
|
|
851
887
|
function resolvePath(view, params) {
|
|
852
|
-
|
|
853
|
-
|
|
888
|
+
var suffix = '';
|
|
889
|
+
if (isArray(params)) {
|
|
890
|
+
suffix = normalizePart(isPlainObject(params[1]) ? toQueryString(params[1]) : params[1], '?') + normalizePart(params[2], '#');
|
|
891
|
+
params = params[0];
|
|
854
892
|
}
|
|
855
|
-
return app_app.route.getPath(getCurrentParams(view, params));
|
|
893
|
+
return (routeMap.has(view) ? app_app.route.getPath(getCurrentParams(view, params)) : '/') + suffix;
|
|
856
894
|
}
|
|
857
895
|
function linkTo(view, params) {
|
|
858
896
|
return app_app.toHref(resolvePath(view, params));
|