brew-js-react 0.1.11 → 0.2.2
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 +10 -4
- package/dist/brew-js-react.js +361 -196
- 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.d.ts +3 -1
- package/hooks.js +113 -42
- package/i18n.js +16 -9
- package/include/zeta-dom/domLock.js +1 -0
- package/mixin.js +6 -2
- package/mixins/FlyoutMixin.d.ts +1 -0
- package/mixins/FlyoutMixin.js +3 -0
- package/mixins/FocusStateMixin.js +2 -2
- package/mixins/Mixin.d.ts +4 -0
- package/mixins/Mixin.js +2 -0
- package/mixins/StatefulMixin.js +82 -76
- package/package.json +3 -3
- package/view.d.ts +6 -0
- package/view.js +54 -20
package/mixin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
import { extend } from "./include/zeta-dom/util.js";
|
|
3
3
|
import Mixin from "./mixins/Mixin.js";
|
|
4
4
|
import AnimateMixin from "./mixins/AnimateMixin.js";
|
|
@@ -34,9 +34,13 @@ export const useLoadingStateMixin = createUseFunction(LoadingStateMixin);
|
|
|
34
34
|
export const useScrollableMixin = createUseFunction(ScrollableMixin);
|
|
35
35
|
|
|
36
36
|
export function useMixin(ctor) {
|
|
37
|
-
|
|
37
|
+
var mixin = useState(function () {
|
|
38
38
|
return new ctor();
|
|
39
39
|
})[0].reset();
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
return mixin.dispose.bind(mixin);
|
|
42
|
+
}, []);
|
|
43
|
+
return mixin;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export function useMixinRef(mixin) {
|
package/mixins/FlyoutMixin.d.ts
CHANGED
package/mixins/FlyoutMixin.js
CHANGED
|
@@ -10,6 +10,7 @@ export default function FlyoutMixin() {
|
|
|
10
10
|
var self = this;
|
|
11
11
|
ClassNameMixin.call(self, ['open', 'closing', 'tweening-in', 'tweening-out']);
|
|
12
12
|
self.modal = false;
|
|
13
|
+
self.tabThrough = false;
|
|
13
14
|
self.isFlyoutOpened = false;
|
|
14
15
|
self.animating = false;
|
|
15
16
|
self.visible = false;
|
|
@@ -36,6 +37,8 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
|
|
|
36
37
|
'swipe-dismiss': self.swipeToDismiss
|
|
37
38
|
}, self.modal && {
|
|
38
39
|
'is-modal': ''
|
|
40
|
+
}, self.tabThrough && {
|
|
41
|
+
'tab-through': ''
|
|
39
42
|
}, self.effects && {
|
|
40
43
|
'animate-on': 'open',
|
|
41
44
|
'animate-in': self.effects.join(' '),
|
|
@@ -13,9 +13,9 @@ definePrototype(FocusStateMixin, StatefulMixin, {
|
|
|
13
13
|
initElement: function (element, state) {
|
|
14
14
|
FocusStateMixinSuper.initElement.call(this, element, state);
|
|
15
15
|
dom.on(element, {
|
|
16
|
-
focusin: function () {
|
|
16
|
+
focusin: function (e) {
|
|
17
17
|
state.focused = true;
|
|
18
|
-
setClass(element, 'focused',
|
|
18
|
+
setClass(element, 'focused', e.source);
|
|
19
19
|
},
|
|
20
20
|
focusout: function () {
|
|
21
21
|
state.focused = false;
|
package/mixins/Mixin.d.ts
CHANGED
|
@@ -30,6 +30,10 @@ export default abstract class Mixin implements ClassNameProvider {
|
|
|
30
30
|
* @private Internal use.
|
|
31
31
|
*/
|
|
32
32
|
getCustomAttributes(): Zeta.Dictionary<string>;
|
|
33
|
+
/**
|
|
34
|
+
* @private Internal use.
|
|
35
|
+
*/
|
|
36
|
+
dispose(): void;
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* Watches a property on the object.
|
package/mixins/Mixin.js
CHANGED
package/mixins/StatefulMixin.js
CHANGED
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
import { createPrivateStore, definePrototype, inherit, randomId, values } from "../include/zeta-dom/util.js";
|
|
2
|
-
import Mixin from "./Mixin.js";
|
|
3
|
-
|
|
4
|
-
const _ = createPrivateStore();
|
|
5
|
-
|
|
6
|
-
function MixinRefImpl(mixin) {
|
|
7
|
-
this.mixin = mixin;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
definePrototype(MixinRefImpl, {
|
|
11
|
-
getMixin: function () {
|
|
12
|
-
return this.mixin;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export default function StatefulMixin() {
|
|
17
|
-
Mixin.call(this);
|
|
18
|
-
_(this, {
|
|
19
|
-
states: {},
|
|
20
|
-
prefix: '',
|
|
21
|
-
counter: 0
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
definePrototype(StatefulMixin, Mixin, {
|
|
26
|
-
get ref() {
|
|
27
|
-
const self = this;
|
|
28
|
-
const state = self.state;
|
|
29
|
-
self.next();
|
|
30
|
-
return state.ref || (state.ref = new MixinRefImpl(self.clone()));
|
|
31
|
-
},
|
|
32
|
-
get state() {
|
|
33
|
-
const obj = _(this);
|
|
34
|
-
const key = obj.prefix + obj.counter;
|
|
35
|
-
return obj.states[key] || (obj.states[key] = this.initState());
|
|
36
|
-
},
|
|
37
|
-
reset: function () {
|
|
38
|
-
_(this).counter = 0;
|
|
39
|
-
return this;
|
|
40
|
-
},
|
|
41
|
-
next: function () {
|
|
42
|
-
_(this).counter++;
|
|
43
|
-
return this;
|
|
44
|
-
},
|
|
45
|
-
getRef: function () {
|
|
46
|
-
const self = this;
|
|
47
|
-
const state = self.state;
|
|
48
|
-
return function (current) {
|
|
49
|
-
if (current && current !== state.element) {
|
|
50
|
-
state.element = current;
|
|
51
|
-
self.initElement(current, state);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
elements: function () {
|
|
56
|
-
return values(_(this).states).map(function (v) {
|
|
57
|
-
return v.element;
|
|
58
|
-
}).filter(function (v) {
|
|
59
|
-
return v;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
initState: function () {
|
|
63
|
-
return { element: null };
|
|
64
|
-
},
|
|
65
|
-
initElement: function (element, state) {
|
|
66
|
-
},
|
|
67
|
-
clone: function () {
|
|
68
|
-
const clone = inherit(Object.getPrototypeOf(this));
|
|
69
|
-
_(clone, {
|
|
70
|
-
states: _(this).states,
|
|
71
|
-
prefix: randomId() + '.',
|
|
72
|
-
counter: 0
|
|
73
|
-
});
|
|
74
|
-
return clone;
|
|
75
|
-
}
|
|
76
|
-
|
|
1
|
+
import { createPrivateStore, definePrototype, each, inherit, randomId, values } from "../include/zeta-dom/util.js";
|
|
2
|
+
import Mixin from "./Mixin.js";
|
|
3
|
+
|
|
4
|
+
const _ = createPrivateStore();
|
|
5
|
+
|
|
6
|
+
function MixinRefImpl(mixin) {
|
|
7
|
+
this.mixin = mixin;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
definePrototype(MixinRefImpl, {
|
|
11
|
+
getMixin: function () {
|
|
12
|
+
return this.mixin;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default function StatefulMixin() {
|
|
17
|
+
Mixin.call(this);
|
|
18
|
+
_(this, {
|
|
19
|
+
states: {},
|
|
20
|
+
prefix: '',
|
|
21
|
+
counter: 0
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
definePrototype(StatefulMixin, Mixin, {
|
|
26
|
+
get ref() {
|
|
27
|
+
const self = this;
|
|
28
|
+
const state = self.state;
|
|
29
|
+
self.next();
|
|
30
|
+
return state.ref || (state.ref = new MixinRefImpl(self.clone()));
|
|
31
|
+
},
|
|
32
|
+
get state() {
|
|
33
|
+
const obj = _(this);
|
|
34
|
+
const key = obj.prefix + obj.counter;
|
|
35
|
+
return obj.states[key] || (obj.states[key] = this.initState());
|
|
36
|
+
},
|
|
37
|
+
reset: function () {
|
|
38
|
+
_(this).counter = 0;
|
|
39
|
+
return this;
|
|
40
|
+
},
|
|
41
|
+
next: function () {
|
|
42
|
+
_(this).counter++;
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
getRef: function () {
|
|
46
|
+
const self = this;
|
|
47
|
+
const state = self.state;
|
|
48
|
+
return function (current) {
|
|
49
|
+
if (current && current !== state.element) {
|
|
50
|
+
state.element = current;
|
|
51
|
+
self.initElement(current, state);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
elements: function () {
|
|
56
|
+
return values(_(this).states).map(function (v) {
|
|
57
|
+
return v.element;
|
|
58
|
+
}).filter(function (v) {
|
|
59
|
+
return v;
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
initState: function () {
|
|
63
|
+
return { element: null };
|
|
64
|
+
},
|
|
65
|
+
initElement: function (element, state) {
|
|
66
|
+
},
|
|
67
|
+
clone: function () {
|
|
68
|
+
const clone = inherit(Object.getPrototypeOf(this));
|
|
69
|
+
_(clone, {
|
|
70
|
+
states: _(this).states,
|
|
71
|
+
prefix: randomId() + '.',
|
|
72
|
+
counter: 0
|
|
73
|
+
});
|
|
74
|
+
return clone;
|
|
75
|
+
},
|
|
76
|
+
dispose: function () {
|
|
77
|
+
var states = _(this).states;
|
|
78
|
+
each(states, function (i, v) {
|
|
79
|
+
delete states[i];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brew-js-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"brew-js": ">=0.3.2",
|
|
21
21
|
"waterpipe": "^2.5.0",
|
|
22
|
-
"zeta-dom": ">=0.
|
|
23
|
-
"zeta-dom-react": ">=0.
|
|
22
|
+
"zeta-dom": ">=0.2.3",
|
|
23
|
+
"zeta-dom-react": ">=0.2.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": ">=16.8.0",
|
package/view.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export type ViewComponentRootProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
2
2
|
export type ViewComponent<P> = React.FC<P>;
|
|
3
3
|
|
|
4
|
+
export interface ViewContainerState {
|
|
5
|
+
readonly active: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useViewContainerState(): ViewContainerState;
|
|
9
|
+
|
|
4
10
|
/**
|
|
5
11
|
* Registers view component with specific route paramters.
|
|
6
12
|
* Route parameters will be matched against current route state by {@link renderView}.
|
package/view.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
2
|
import { useAsync } from "zeta-dom-react";
|
|
3
|
-
import
|
|
3
|
+
import dom from "./include/zeta-dom/dom.js";
|
|
4
|
+
import { notifyAsync } from "./include/zeta-dom/domLock.js";
|
|
5
|
+
import { any, defineGetterProperty, definePrototype, each, extend, isFunction, keys, makeArray, noop, pick, randomId, setImmediate } from "./include/zeta-dom/util.js";
|
|
4
6
|
import { animateIn, animateOut } from "./include/brew-js/anim.js";
|
|
5
7
|
import { app } from "./app.js";
|
|
8
|
+
import { ViewStateContainer } from "./hooks.js";
|
|
6
9
|
|
|
10
|
+
const root = dom.root;
|
|
7
11
|
const routeMap = new Map();
|
|
8
12
|
const usedParams = {};
|
|
13
|
+
const StateContext = React.createContext(Object.freeze({ active: true }));
|
|
9
14
|
|
|
10
15
|
let stateId;
|
|
11
16
|
|
|
@@ -31,33 +36,58 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
31
36
|
componentDidMount: function () {
|
|
32
37
|
this.mounted = true;
|
|
33
38
|
},
|
|
39
|
+
componentDidCatch: function (error) {
|
|
40
|
+
dom.emit('error', this.parentElement || root, { error }, true);
|
|
41
|
+
},
|
|
34
42
|
render: function () {
|
|
35
43
|
/** @type {any} */
|
|
36
44
|
var self = this;
|
|
45
|
+
var resolve;
|
|
46
|
+
var promise = new Promise(function (_resolve) {
|
|
47
|
+
resolve = _resolve;
|
|
48
|
+
});
|
|
37
49
|
var V = self.getViewComponent();
|
|
38
50
|
if (V && V !== self.currentViewComponent) {
|
|
39
51
|
self.currentViewComponent = V;
|
|
40
52
|
if (self.currentView && self.currentElement) {
|
|
53
|
+
var prevPath = self.currentPath;
|
|
54
|
+
var prevElement = self.currentElement;
|
|
41
55
|
self.prevView = self.currentView;
|
|
42
|
-
self.prevElement = self.currentElement;
|
|
43
56
|
self.currentElement = undefined;
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
app.emit('pageleave', prevElement, { pathname: prevPath }, true);
|
|
58
|
+
animateOut(prevElement, 'show').then(function () {
|
|
46
59
|
self.prevView = undefined;
|
|
47
60
|
self.forceUpdate();
|
|
48
61
|
});
|
|
49
62
|
}
|
|
50
|
-
|
|
63
|
+
var providerProps = {
|
|
51
64
|
key: routeMap.get(V).id,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
value: {}
|
|
66
|
+
};
|
|
67
|
+
var view = React.createElement(StateContext.Provider, providerProps,
|
|
68
|
+
React.createElement(ViewStateContainer, null,
|
|
69
|
+
React.createElement(V, {
|
|
70
|
+
rootProps: self.props.rootProps,
|
|
71
|
+
onComponentLoaded: function (element) {
|
|
72
|
+
self.currentElement = element;
|
|
73
|
+
self.parentElement = element.parentElement;
|
|
74
|
+
setImmediate(function () {
|
|
75
|
+
resolve();
|
|
76
|
+
animateIn(element, 'show');
|
|
77
|
+
app.emit('pageenter', element, { pathname: app.path }, true);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
})));
|
|
81
|
+
defineGetterProperty(providerProps.value, 'active', function () {
|
|
82
|
+
return self.currentView === view;
|
|
59
83
|
});
|
|
84
|
+
self.currentPath = app.path;
|
|
85
|
+
self.currentView = view;
|
|
86
|
+
} else {
|
|
87
|
+
app.emit('pageenter', self.currentElement, { pathname: app.path }, true);
|
|
88
|
+
resolve();
|
|
60
89
|
}
|
|
90
|
+
notifyAsync(self.parentElement || root, promise);
|
|
61
91
|
return React.createElement(React.Fragment, null, self.prevView, self.currentView);
|
|
62
92
|
},
|
|
63
93
|
getViewComponent: function () {
|
|
@@ -66,6 +96,10 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
66
96
|
}
|
|
67
97
|
});
|
|
68
98
|
|
|
99
|
+
export function useViewContainerState() {
|
|
100
|
+
return React.useContext(StateContext);
|
|
101
|
+
}
|
|
102
|
+
|
|
69
103
|
export function isViewMatched(view) {
|
|
70
104
|
var params = routeMap.get(view);
|
|
71
105
|
return !!params && false === any(params.matchers, function (v, i) {
|
|
@@ -76,14 +110,14 @@ export function isViewMatched(view) {
|
|
|
76
110
|
|
|
77
111
|
export function registerView(factory, routeParams) {
|
|
78
112
|
var Component = function (props) {
|
|
79
|
-
var
|
|
113
|
+
var state = useAsync(factory);
|
|
114
|
+
var ref = useRef();
|
|
115
|
+
if (state[0] || state[1].error) {
|
|
116
|
+
(props.onComponentLoaded || noop)(ref.current);
|
|
117
|
+
}
|
|
80
118
|
return React.createElement('div', extend({}, props.rootProps, {
|
|
81
|
-
ref:
|
|
82
|
-
|
|
83
|
-
(props.onComponentLoaded || noop)(element);
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
children: Component && React.createElement(Component.default)
|
|
119
|
+
ref: ref,
|
|
120
|
+
children: state[0] && React.createElement(state[0].default)
|
|
87
121
|
}));
|
|
88
122
|
};
|
|
89
123
|
routeParams = extend({}, routeParams);
|