brew-js-react 0.2.1 → 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 +117 -55
- 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 +1 -1
- package/hooks.js +113 -84
- 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 +1 -1
- package/view.js +8 -4
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
package/view.js
CHANGED
|
@@ -50,11 +50,12 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
50
50
|
if (V && V !== self.currentViewComponent) {
|
|
51
51
|
self.currentViewComponent = V;
|
|
52
52
|
if (self.currentView && self.currentElement) {
|
|
53
|
+
var prevPath = self.currentPath;
|
|
54
|
+
var prevElement = self.currentElement;
|
|
53
55
|
self.prevView = self.currentView;
|
|
54
|
-
self.prevElement = self.currentElement;
|
|
55
56
|
self.currentElement = undefined;
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
app.emit('pageleave', prevElement, { pathname: prevPath }, true);
|
|
58
|
+
animateOut(prevElement, 'show').then(function () {
|
|
58
59
|
self.prevView = undefined;
|
|
59
60
|
self.forceUpdate();
|
|
60
61
|
});
|
|
@@ -72,15 +73,18 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
72
73
|
self.parentElement = element.parentElement;
|
|
73
74
|
setImmediate(function () {
|
|
74
75
|
resolve();
|
|
75
|
-
|
|
76
|
+
animateIn(element, 'show');
|
|
77
|
+
app.emit('pageenter', element, { pathname: app.path }, true);
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
})));
|
|
79
81
|
defineGetterProperty(providerProps.value, 'active', function () {
|
|
80
82
|
return self.currentView === view;
|
|
81
83
|
});
|
|
84
|
+
self.currentPath = app.path;
|
|
82
85
|
self.currentView = view;
|
|
83
86
|
} else {
|
|
87
|
+
app.emit('pageenter', self.currentElement, { pathname: app.path }, true);
|
|
84
88
|
resolve();
|
|
85
89
|
}
|
|
86
90
|
notifyAsync(self.parentElement || root, promise);
|