brew-js-react 0.6.4 → 0.6.6
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 +136 -89
- 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 +2 -2
- package/view.d.ts +49 -5
- package/view.js +114 -84
package/dist/brew-js-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! brew-js-react v0.6.
|
|
1
|
+
/*! brew-js-react v0.6.6 | (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;
|
|
@@ -504,7 +506,9 @@ var rootState = _(rootContext);
|
|
|
504
506
|
var StateContext = /*#__PURE__*/createContext(rootContext);
|
|
505
507
|
var errorView;
|
|
506
508
|
/** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
|
|
507
|
-
var view_event = {
|
|
509
|
+
var view_event = {
|
|
510
|
+
waitFor: noop
|
|
511
|
+
};
|
|
508
512
|
onAppInit(function () {
|
|
509
513
|
app_app.on('beforepageload', function (e) {
|
|
510
514
|
rootState.setPage(app_app.page);
|
|
@@ -541,92 +545,109 @@ function ViewContext(view, page, parent) {
|
|
|
541
545
|
});
|
|
542
546
|
});
|
|
543
547
|
}
|
|
548
|
+
defineOwnProperty(ViewContext, 'root', rootContext, true);
|
|
544
549
|
definePrototype(ViewContext, {
|
|
545
550
|
getChildren: function getChildren() {
|
|
546
551
|
return map(_(this).children, function (v) {
|
|
547
552
|
return v.currentContext;
|
|
548
553
|
});
|
|
549
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
|
+
},
|
|
550
562
|
on: function on(event, handler) {
|
|
551
563
|
return emitter.add(this, event, handler);
|
|
552
564
|
}
|
|
553
565
|
});
|
|
554
|
-
function ErrorBoundary() {
|
|
555
|
-
Component.
|
|
566
|
+
function ErrorBoundary(props) {
|
|
567
|
+
Component.call(this, props);
|
|
556
568
|
this.state = {};
|
|
569
|
+
_(props.context).wrapper = this;
|
|
557
570
|
}
|
|
558
|
-
ErrorBoundary.contextType = StateContext;
|
|
559
571
|
definePrototype(ErrorBoundary, Component, {
|
|
560
572
|
componentDidMount: function componentDidMount() {
|
|
561
573
|
var self = this;
|
|
562
|
-
self.componentWillUnmount = watch(self.context, 'page', function () {
|
|
563
|
-
self.state.
|
|
574
|
+
self.componentWillUnmount = watch(self.props.context, 'page', function () {
|
|
575
|
+
self.state.errorView = null;
|
|
564
576
|
self.forceUpdate();
|
|
565
577
|
});
|
|
566
578
|
},
|
|
567
579
|
componentDidCatch: function componentDidCatch(error) {
|
|
568
580
|
var self = this;
|
|
569
|
-
if (errorView &&
|
|
581
|
+
if (errorView && self.state.errorView !== errorView) {
|
|
570
582
|
self.setState({
|
|
571
|
-
error: error
|
|
583
|
+
error: error,
|
|
584
|
+
errorView: errorView
|
|
572
585
|
});
|
|
573
586
|
} else {
|
|
574
|
-
// ensure promise sent to beforepageload event is resolved
|
|
575
587
|
self.props.onLoad();
|
|
576
|
-
reportError(error, self.context.container);
|
|
588
|
+
reportError(error, self.props.context.container);
|
|
577
589
|
}
|
|
578
590
|
},
|
|
579
591
|
render: function render() {
|
|
580
592
|
var self = this;
|
|
581
|
-
var context = self.context;
|
|
593
|
+
var context = self.props.context;
|
|
582
594
|
if (!context.container) {
|
|
583
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
|
+
}, false);
|
|
601
|
+
});
|
|
584
602
|
self.forceUpdate();
|
|
585
603
|
});
|
|
586
604
|
return null;
|
|
587
605
|
}
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
onError: self.componentDidCatch.bind(self),
|
|
593
|
-
viewProps: error ? {
|
|
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, {
|
|
594
610
|
view: context.view,
|
|
595
|
-
error: error,
|
|
611
|
+
error: self.state.error,
|
|
596
612
|
reset: self.reset.bind(self)
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
613
|
+
}));
|
|
614
|
+
}
|
|
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 || {}
|
|
603
621
|
};
|
|
604
|
-
return /*#__PURE__*/createElement(
|
|
622
|
+
return /*#__PURE__*/createElement(self.Provider, null, /*#__PURE__*/createElement(context.view, extend({
|
|
623
|
+
viewProps: viewProps,
|
|
624
|
+
onError: onError
|
|
625
|
+
}, self.props)));
|
|
605
626
|
},
|
|
606
627
|
reset: function reset() {
|
|
607
628
|
this.setState({
|
|
608
|
-
|
|
629
|
+
errorView: null
|
|
609
630
|
});
|
|
610
631
|
}
|
|
611
632
|
});
|
|
612
633
|
function ViewContainer() {
|
|
613
634
|
Component.apply(this, arguments);
|
|
635
|
+
this.views = [];
|
|
614
636
|
}
|
|
615
637
|
ViewContainer.contextType = StateContext;
|
|
616
638
|
definePrototype(ViewContainer, Component, {
|
|
617
|
-
setActive: noop,
|
|
618
639
|
componentDidMount: function componentDidMount() {
|
|
619
640
|
var self = this;
|
|
620
641
|
var parent = _(self.context).children;
|
|
621
642
|
var unwatch = watch(app_app.route, function () {
|
|
622
|
-
self.setActive(self.getViewComponent() === self.
|
|
643
|
+
self.setActive(self.getViewComponent() === (self.currentContext || '').view);
|
|
623
644
|
});
|
|
624
645
|
self.componentWillUnmount = function () {
|
|
625
646
|
self.setActive(false);
|
|
626
647
|
arrRemove(parent, self);
|
|
627
648
|
unwatch();
|
|
628
649
|
setImmediate(function () {
|
|
629
|
-
if (self.
|
|
650
|
+
if (self.currentContext && !self.currentContext.active) {
|
|
630
651
|
self.unmountView();
|
|
631
652
|
}
|
|
632
653
|
});
|
|
@@ -634,19 +655,27 @@ definePrototype(ViewContainer, Component, {
|
|
|
634
655
|
parent.push(self);
|
|
635
656
|
self.setActive(true);
|
|
636
657
|
},
|
|
658
|
+
componentDidUpdate: function componentDidUpdate(prevProps) {
|
|
659
|
+
(prevProps.rootProps.ref || {}).current = null;
|
|
660
|
+
this.setContext(this.currentContext);
|
|
661
|
+
},
|
|
662
|
+
setContext: function setContext(context) {
|
|
663
|
+
this.currentContext = context;
|
|
664
|
+
(this.props.rootProps.ref || {}).current = context;
|
|
665
|
+
},
|
|
637
666
|
render: function render() {
|
|
638
667
|
/** @type {any} */
|
|
639
668
|
var self = this;
|
|
640
669
|
if (self.context.active) {
|
|
641
670
|
self.updateView();
|
|
642
671
|
}
|
|
643
|
-
|
|
644
|
-
return
|
|
672
|
+
self.onRender();
|
|
673
|
+
return self.views;
|
|
645
674
|
},
|
|
646
675
|
updateView: function updateView() {
|
|
647
676
|
var self = this;
|
|
648
677
|
var V = self.getViewComponent();
|
|
649
|
-
var viewChanged = V !== self.
|
|
678
|
+
var viewChanged = V !== (self.currentContext || '').view;
|
|
650
679
|
if (V && (viewChanged || !(self.children || '')[0])) {
|
|
651
680
|
// ensure the current path actually corresponds to the matched view
|
|
652
681
|
// when some views are not included in the list of allowed views
|
|
@@ -656,67 +685,83 @@ definePrototype(ViewContainer, Component, {
|
|
|
656
685
|
return;
|
|
657
686
|
}
|
|
658
687
|
}
|
|
659
|
-
|
|
660
|
-
|
|
688
|
+
var state = routeMap.get(V) || {};
|
|
689
|
+
if ((self.views[2] || '').key === state.id) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
self.views[2] = null;
|
|
693
|
+
self.abort();
|
|
694
|
+
if (!V || !viewChanged) {
|
|
695
|
+
self.setActive(true);
|
|
696
|
+
self.setPage(app_app.page);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
view_event.waitFor(new Promise(function (resolve) {
|
|
661
700
|
var context = new ViewContext(V, app_app.page, self.context);
|
|
662
|
-
var
|
|
663
|
-
var onLoad;
|
|
664
|
-
var promise = new Promise(function (resolve) {
|
|
665
|
-
onLoad = resolve;
|
|
666
|
-
});
|
|
667
|
-
var unmountView = onLoad;
|
|
701
|
+
var rootProps = self.props.rootProps;
|
|
668
702
|
var initElement = executeOnce(function (element) {
|
|
669
|
-
context
|
|
670
|
-
|
|
671
|
-
if (self.currentContext
|
|
672
|
-
|
|
673
|
-
self.prevView = self.currentView;
|
|
674
|
-
app_app.emit('pageleave', element, {
|
|
675
|
-
pathname: context.page.path,
|
|
676
|
-
view: V
|
|
677
|
-
}, true);
|
|
678
|
-
animateOut(element, 'show').then(function () {
|
|
679
|
-
self.prevView = undefined;
|
|
680
|
-
self.forceUpdate();
|
|
681
|
-
});
|
|
682
|
-
};
|
|
683
|
-
animateIn(element, 'show', '[brew-view]', true);
|
|
684
|
-
app_app.emit('pageenter', element, {
|
|
685
|
-
pathname: context.page.path,
|
|
686
|
-
view: V
|
|
687
|
-
}, true);
|
|
703
|
+
defineOwnProperty(context, 'container', element, true);
|
|
704
|
+
zeta_dom_dom.on(element, 'error', function (e) {
|
|
705
|
+
if (context !== self.currentContext) {
|
|
706
|
+
e.handled();
|
|
688
707
|
}
|
|
689
708
|
});
|
|
709
|
+
self.setContext(self.currentContext || context);
|
|
690
710
|
});
|
|
691
|
-
var
|
|
711
|
+
var onLoad = executeOnce(function () {
|
|
712
|
+
var element = context.container;
|
|
713
|
+
var promise = self.unmountView();
|
|
714
|
+
self.unmountView = executeOnce(function () {
|
|
715
|
+
state.rendered--;
|
|
716
|
+
self.setActive(false);
|
|
717
|
+
app_app.emit('pageleave', element, {
|
|
718
|
+
pathname: context.page.path,
|
|
719
|
+
view: V
|
|
720
|
+
}, true);
|
|
721
|
+
return animateOut(element, 'show').then(function () {
|
|
722
|
+
self.views[0] = null;
|
|
723
|
+
self.forceUpdate();
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
always(promise, delay).then(function () {
|
|
727
|
+
app_app.emit('pageenter', element, {
|
|
728
|
+
pathname: context.page.path,
|
|
729
|
+
view: V
|
|
730
|
+
}, true);
|
|
731
|
+
});
|
|
732
|
+
self.views.shift();
|
|
733
|
+
self.setContext(context);
|
|
734
|
+
extend(self, _(context));
|
|
735
|
+
state.rendered++;
|
|
736
|
+
animateIn(element, 'show', '[brew-view]', true);
|
|
737
|
+
resolve();
|
|
738
|
+
});
|
|
739
|
+
context.on('error', function () {
|
|
740
|
+
return (self.props.rootProps.onError || noop).apply(this, arguments);
|
|
741
|
+
});
|
|
742
|
+
self.abort = resolve;
|
|
743
|
+
self.views[2] = /*#__PURE__*/createElement(StateContext.Provider, {
|
|
692
744
|
key: state.id,
|
|
693
745
|
value: context
|
|
694
|
-
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(
|
|
746
|
+
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(exclude(rootProps, ['loader', 'onError']), {
|
|
695
747
|
ref: initElement,
|
|
696
748
|
'brew-view': ''
|
|
697
749
|
}), /*#__PURE__*/createElement(ErrorBoundary, {
|
|
698
|
-
onLoad: onLoad
|
|
750
|
+
onLoad: onLoad,
|
|
751
|
+
context: context,
|
|
752
|
+
self: self,
|
|
753
|
+
loader: rootProps.loader
|
|
699
754
|
}))));
|
|
700
|
-
|
|
701
|
-
currentContext: context,
|
|
702
|
-
currentView: view,
|
|
703
|
-
currentViewComponent: V,
|
|
704
|
-
unmountView: executeOnce(function () {
|
|
705
|
-
self.setActive(false);
|
|
706
|
-
state.rendered--;
|
|
707
|
-
unmountView();
|
|
708
|
-
})
|
|
709
|
-
});
|
|
710
|
-
state.rendered++;
|
|
711
|
-
(view_event.waitFor || noop)(promise);
|
|
712
|
-
}
|
|
713
|
-
(self.setPage || noop)(app_app.page);
|
|
755
|
+
}));
|
|
714
756
|
},
|
|
715
757
|
getViewComponent: function getViewComponent() {
|
|
716
758
|
var props = this.props;
|
|
717
|
-
return any(props.views,
|
|
759
|
+
return any(props.views, function (v) {
|
|
760
|
+
return matchViewParams(v, app_app.route);
|
|
761
|
+
}) || props.defaultView;
|
|
718
762
|
}
|
|
719
763
|
});
|
|
764
|
+
fill(ViewContainer.prototype, 'abort onRender setActive setPage unmountView', noop);
|
|
720
765
|
function normalizePart(value, part) {
|
|
721
766
|
return isUndefinedOrNull(value) || value === '' || value === part ? '' : value[0] === part ? value : part + value;
|
|
722
767
|
}
|
|
@@ -775,25 +820,27 @@ function createViewComponent(factory) {
|
|
|
775
820
|
promise = children;
|
|
776
821
|
catchAsync(promise);
|
|
777
822
|
} else {
|
|
778
|
-
|
|
823
|
+
useLayoutEffect(props.onLoad, []);
|
|
779
824
|
return children;
|
|
780
825
|
}
|
|
781
826
|
var component = useAsync(function () {
|
|
782
|
-
return promise.then(null,
|
|
827
|
+
return promise.then(null, function (error) {
|
|
828
|
+
promise = null;
|
|
829
|
+
props.onError(error);
|
|
830
|
+
});
|
|
783
831
|
})[0];
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}, [component]);
|
|
789
|
-
return component ? /*#__PURE__*/createElement(component["default"], props.viewProps) : null;
|
|
832
|
+
if (component) {
|
|
833
|
+
props.onLoad();
|
|
834
|
+
}
|
|
835
|
+
return component ? /*#__PURE__*/createElement(component["default"], props.viewProps) : props.self.currentContext === props.context && props.loader || null;
|
|
790
836
|
};
|
|
791
837
|
}
|
|
792
838
|
function useViewContext() {
|
|
793
839
|
return useContext(StateContext);
|
|
794
840
|
}
|
|
795
841
|
function isViewMatched(view) {
|
|
796
|
-
|
|
842
|
+
var route = app_app.route;
|
|
843
|
+
return matchViewParams(view, route) && resolvePath(view, route) === route.toString();
|
|
797
844
|
}
|
|
798
845
|
function isViewRendered(view) {
|
|
799
846
|
return !!(routeMap.get(view) || '').rendered;
|
|
@@ -832,7 +879,7 @@ function registerView(factory, routeParams) {
|
|
|
832
879
|
return Component;
|
|
833
880
|
}
|
|
834
881
|
function registerErrorView(factory) {
|
|
835
|
-
errorView =
|
|
882
|
+
errorView = throwNotFunction(factory);
|
|
836
883
|
}
|
|
837
884
|
function renderView() {
|
|
838
885
|
var views = makeArray(arguments);
|