brew-js-react 0.1.0-beta

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.
Files changed (44) hide show
  1. package/README.md +5 -0
  2. package/app.js +11 -0
  3. package/dialog.d.ts +33 -0
  4. package/dialog.js +83 -0
  5. package/dist/brew-js-react.js +1060 -0
  6. package/dist/brew-js-react.js.map +1 -0
  7. package/dist/brew-js-react.min.js +2 -0
  8. package/dist/brew-js-react.min.js.map +1 -0
  9. package/entry.js +2 -0
  10. package/hooks.d.ts +20 -0
  11. package/hooks.js +34 -0
  12. package/include/zeta-dom/dom.js +3 -0
  13. package/include/zeta-dom/domUtil.js +1 -0
  14. package/include/zeta-dom/events.js +1 -0
  15. package/include/zeta-dom/util.js +1 -0
  16. package/index.d.ts +4 -0
  17. package/index.js +4 -0
  18. package/mixin.d.ts +48 -0
  19. package/mixin.js +64 -0
  20. package/mixins/AnimateMixin.d.ts +9 -0
  21. package/mixins/AnimateMixin.js +31 -0
  22. package/mixins/AnimateSequenceItemMixin.d.ts +5 -0
  23. package/mixins/AnimateSequenceItemMixin.js +15 -0
  24. package/mixins/AnimateSequenceMixin.d.ts +6 -0
  25. package/mixins/AnimateSequenceMixin.js +29 -0
  26. package/mixins/ClassNameMixin.d.ts +12 -0
  27. package/mixins/ClassNameMixin.js +41 -0
  28. package/mixins/FlyoutMixin.d.ts +14 -0
  29. package/mixins/FlyoutMixin.js +95 -0
  30. package/mixins/FocusStateMixin.d.ts +3 -0
  31. package/mixins/FocusStateMixin.js +24 -0
  32. package/mixins/LoadingStateMixin.d.ts +3 -0
  33. package/mixins/LoadingStateMixin.js +27 -0
  34. package/mixins/Mixin.d.ts +47 -0
  35. package/mixins/Mixin.js +61 -0
  36. package/mixins/ScrollableMixin.d.ts +17 -0
  37. package/mixins/ScrollableMixin.js +46 -0
  38. package/mixins/StatefulMixin.d.ts +23 -0
  39. package/mixins/StatefulMixin.js +71 -0
  40. package/mixins/StaticAttributeMixin.d.ts +5 -0
  41. package/mixins/StaticAttributeMixin.js +13 -0
  42. package/package.json +46 -0
  43. package/view.d.ts +33 -0
  44. package/view.js +92 -0
package/view.js ADDED
@@ -0,0 +1,92 @@
1
+ import React from "react";
2
+ import brew from "brew-js";
3
+ import { useAsync } from "zeta-dom-react";
4
+ import { any, definePrototype, equal, exclude, extend, keys, makeArray, noop, pick, setImmediate } from "./include/zeta-dom/util.js";
5
+ import { app } from "./app.js";
6
+
7
+ const routeMap = new Map();
8
+
9
+ function ViewContainer() {
10
+ /** @type {any} */
11
+ var self = this;
12
+ React.Component.apply(self, arguments);
13
+ self.mounted = false;
14
+ self.componentWillUnmount = app.on('navigate', function () {
15
+ if (self.mounted && self.getViewComponent()) {
16
+ self.forceUpdate();
17
+ }
18
+ });
19
+ }
20
+
21
+ definePrototype(ViewContainer, React.Component, {
22
+ componentDidMount: function () {
23
+ this.mounted = true;
24
+ },
25
+ render: function () {
26
+ /** @type {any} */
27
+ var self = this;
28
+ var V = self.getViewComponent();
29
+ if (V && V !== self.currentViewComponent) {
30
+ self.currentViewComponent = V;
31
+ if (self.currentView && self.currentElement) {
32
+ self.prevView = self.currentView;
33
+ self.prevElement = self.currentElement;
34
+ self.currentElement = undefined;
35
+ brew.animateOut(self.prevElement, 'show').then(function () {
36
+ self.prevElement = undefined;
37
+ self.prevView = undefined;
38
+ self.forceUpdate();
39
+ });
40
+ }
41
+ self.currentView = React.createElement(V, {
42
+ key: app.route.view,
43
+ rootProps: exclude(self.props, ['views']),
44
+ onComponentLoaded: function (element) {
45
+ self.currentElement = element;
46
+ setImmediate(function () {
47
+ return brew.animateIn(element, 'show');
48
+ });
49
+ }
50
+ });
51
+ }
52
+ return React.createElement(React.Fragment, null, self.prevView, self.currentView);
53
+ },
54
+ getViewComponent: function () {
55
+ var views = this.props.views;
56
+ var V = any(views, function (V) {
57
+ var params = routeMap.get(V);
58
+ return params && equal(params, pick(app.route, keys(params)));
59
+ });
60
+ return V || void app.navigate(linkTo(views[0]), true);
61
+ }
62
+ });
63
+
64
+ export function registerView(factory, routeParams) {
65
+ var Component = function (props) {
66
+ var childProps = exclude(props, ['rootProps', 'onComponentLoaded']);
67
+ var Component = useAsync(factory)[0];
68
+ return React.createElement('div', extend({}, props.rootProps, {
69
+ ref: function (element) {
70
+ if (element && Component) {
71
+ (props.onComponentLoaded || noop)(element);
72
+ }
73
+ },
74
+ children: Component && React.createElement(Component.default, childProps)
75
+ }));
76
+ };
77
+ routeMap.set(Component, routeParams);
78
+ return Component;
79
+ }
80
+
81
+ export function renderView() {
82
+ var views = makeArray(arguments);
83
+ var props;
84
+ if (views[0] && typeof views[0] !== 'function') {
85
+ props = views.shift();
86
+ }
87
+ return React.createElement(ViewContainer, extend({}, props, { views }));
88
+ }
89
+
90
+ export function linkTo(view, params) {
91
+ return app.route.getPath(extend({}, app.route, params, routeMap.get(view)));
92
+ }