brew-js-react 0.6.4 → 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/dist/brew-js-react.js +124 -90
- 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 +44 -5
- package/view.js +103 -86
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;
|
|
@@ -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
|
+
});
|
|
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
|
});
|
|
@@ -640,13 +661,13 @@ definePrototype(ViewContainer, Component, {
|
|
|
640
661
|
if (self.context.active) {
|
|
641
662
|
self.updateView();
|
|
642
663
|
}
|
|
643
|
-
|
|
644
|
-
return
|
|
664
|
+
self.onRender();
|
|
665
|
+
return self.views;
|
|
645
666
|
},
|
|
646
667
|
updateView: function updateView() {
|
|
647
668
|
var self = this;
|
|
648
669
|
var V = self.getViewComponent();
|
|
649
|
-
var viewChanged = V !== self.
|
|
670
|
+
var viewChanged = V !== (self.currentContext || '').view;
|
|
650
671
|
if (V && (viewChanged || !(self.children || '')[0])) {
|
|
651
672
|
// ensure the current path actually corresponds to the matched view
|
|
652
673
|
// when some views are not included in the list of allowed views
|
|
@@ -656,67 +677,78 @@ definePrototype(ViewContainer, Component, {
|
|
|
656
677
|
return;
|
|
657
678
|
}
|
|
658
679
|
}
|
|
659
|
-
|
|
660
|
-
|
|
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) {
|
|
661
692
|
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;
|
|
693
|
+
var rootProps = self.props.rootProps;
|
|
668
694
|
var initElement = executeOnce(function (element) {
|
|
669
|
-
context
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
view: V
|
|
687
|
-
}, true);
|
|
688
|
-
}
|
|
695
|
+
defineOwnProperty(context, 'container', element, true);
|
|
696
|
+
self.currentContext = self.currentContext || context;
|
|
697
|
+
});
|
|
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
|
+
});
|
|
689
712
|
});
|
|
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);
|
|
690
728
|
});
|
|
691
|
-
|
|
729
|
+
self.abort = resolve;
|
|
730
|
+
self.views[2] = /*#__PURE__*/createElement(StateContext.Provider, {
|
|
692
731
|
key: state.id,
|
|
693
732
|
value: context
|
|
694
|
-
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(
|
|
733
|
+
}, /*#__PURE__*/createElement(ViewStateContainer, null, /*#__PURE__*/createElement('div', extend(exclude(rootProps, ['loader', 'onError']), {
|
|
695
734
|
ref: initElement,
|
|
696
735
|
'brew-view': ''
|
|
697
736
|
}), /*#__PURE__*/createElement(ErrorBoundary, {
|
|
698
|
-
onLoad: onLoad
|
|
737
|
+
onLoad: onLoad,
|
|
738
|
+
context: context,
|
|
739
|
+
self: self,
|
|
740
|
+
loader: rootProps.loader
|
|
699
741
|
}))));
|
|
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);
|
|
742
|
+
}));
|
|
714
743
|
},
|
|
715
744
|
getViewComponent: function getViewComponent() {
|
|
716
745
|
var props = this.props;
|
|
717
|
-
return any(props.views,
|
|
746
|
+
return any(props.views, function (v) {
|
|
747
|
+
return matchViewParams(v, app_app.route);
|
|
748
|
+
}) || props.defaultView;
|
|
718
749
|
}
|
|
719
750
|
});
|
|
751
|
+
fill(ViewContainer.prototype, 'abort onRender setActive setPage unmountView', noop);
|
|
720
752
|
function normalizePart(value, part) {
|
|
721
753
|
return isUndefinedOrNull(value) || value === '' || value === part ? '' : value[0] === part ? value : part + value;
|
|
722
754
|
}
|
|
@@ -775,25 +807,27 @@ function createViewComponent(factory) {
|
|
|
775
807
|
promise = children;
|
|
776
808
|
catchAsync(promise);
|
|
777
809
|
} else {
|
|
778
|
-
|
|
810
|
+
useLayoutEffect(props.onLoad, []);
|
|
779
811
|
return children;
|
|
780
812
|
}
|
|
781
813
|
var component = useAsync(function () {
|
|
782
|
-
return promise.then(null,
|
|
814
|
+
return promise.then(null, function (error) {
|
|
815
|
+
promise = null;
|
|
816
|
+
props.onError(error);
|
|
817
|
+
});
|
|
783
818
|
})[0];
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}, [component]);
|
|
789
|
-
return component ? /*#__PURE__*/createElement(component["default"], props.viewProps) : null;
|
|
819
|
+
if (component) {
|
|
820
|
+
props.onLoad();
|
|
821
|
+
}
|
|
822
|
+
return component ? /*#__PURE__*/createElement(component["default"], props.viewProps) : props.self.currentContext === props.context && props.loader || null;
|
|
790
823
|
};
|
|
791
824
|
}
|
|
792
825
|
function useViewContext() {
|
|
793
826
|
return useContext(StateContext);
|
|
794
827
|
}
|
|
795
828
|
function isViewMatched(view) {
|
|
796
|
-
|
|
829
|
+
var route = app_app.route;
|
|
830
|
+
return matchViewParams(view, route) && resolvePath(view, route) === route.toString();
|
|
797
831
|
}
|
|
798
832
|
function isViewRendered(view) {
|
|
799
833
|
return !!(routeMap.get(view) || '').rendered;
|
|
@@ -832,7 +866,7 @@ function registerView(factory, routeParams) {
|
|
|
832
866
|
return Component;
|
|
833
867
|
}
|
|
834
868
|
function registerErrorView(factory) {
|
|
835
|
-
errorView =
|
|
869
|
+
errorView = throwNotFunction(factory);
|
|
836
870
|
}
|
|
837
871
|
function renderView() {
|
|
838
872
|
var views = makeArray(arguments);
|