brew-js-react 0.4.8 → 0.5.0
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 +164 -136
- 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/hooks.js +15 -8
- package/mixin.d.ts +56 -2
- package/mixin.js +7 -1
- package/mixins/AnimateMixin.d.ts +7 -0
- package/mixins/AnimateSequenceItemMixin.d.ts +6 -0
- package/mixins/AnimateSequenceItemMixin.js +6 -1
- package/mixins/AnimateSequenceMixin.d.ts +10 -0
- package/mixins/AnimateSequenceMixin.js +10 -8
- package/mixins/ClassNameMixin.d.ts +10 -1
- package/mixins/ClassNameMixin.js +13 -28
- package/mixins/ClassNameToggleMixin.d.ts +24 -0
- package/mixins/ClassNameToggleMixin.js +23 -0
- package/mixins/FlyoutMixin.d.ts +7 -0
- package/mixins/FlyoutMixin.js +1 -16
- package/mixins/FlyoutToggleMixin.d.ts +6 -0
- package/mixins/FocusStateMixin.d.ts +7 -0
- package/mixins/FocusStateMixin.js +2 -8
- package/mixins/LoadingStateMixin.d.ts +8 -0
- package/mixins/LoadingStateMixin.js +2 -3
- package/mixins/Mixin.d.ts +23 -5
- package/mixins/Mixin.js +3 -0
- package/mixins/ScrollIntoViewMixin.d.ts +17 -0
- package/mixins/ScrollIntoViewMixin.js +13 -9
- package/mixins/ScrollableMixin.d.ts +7 -0
- package/mixins/ScrollableMixin.js +2 -9
- package/mixins/StatefulMixin.d.ts +57 -9
- package/mixins/StatefulMixin.js +35 -37
- package/mixins/UnmanagedClassNameMixin.d.ts +18 -0
- package/mixins/UnmanagedClassNameMixin.js +13 -0
- package/package.json +1 -1
- package/view.js +2 -2
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="jq-scrollable" />
|
|
2
2
|
|
|
3
3
|
import ClassNameMixin from "./ClassNameMixin";
|
|
4
|
+
import Mixin from "./Mixin";
|
|
4
5
|
import StaticAttributeMixin from "./StaticAttributeMixin";
|
|
6
|
+
import { useScrollableMixin } from "../mixin";
|
|
5
7
|
|
|
6
8
|
export interface ScrollableMixinOptions {
|
|
7
9
|
/**
|
|
@@ -39,6 +41,11 @@ export interface ScrollableMixinOptions {
|
|
|
39
41
|
persistScroll?: boolean;
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Enables scrollable plugin on the applied element.
|
|
46
|
+
*
|
|
47
|
+
* Mixin should be created using {@link useScrollableMixin} and applied to element by {@link Mixin.use}.
|
|
48
|
+
*/
|
|
42
49
|
export default class ScrollableMixin extends ClassNameMixin implements JQueryScrollable {
|
|
43
50
|
/**
|
|
44
51
|
* Gets a mixin object that when applied to descecant element
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineHiddenProperty, definePrototype, each, extend } from "../include/zeta-dom/util.js";
|
|
2
2
|
import { getDirectiveComponent } from "../include/brew-js/directive.js";
|
|
3
3
|
import { app } from "../app.js";
|
|
4
4
|
import Mixin from "./Mixin.js";
|
|
5
5
|
import ClassNameMixin from "./ClassNameMixin.js";
|
|
6
6
|
|
|
7
7
|
const ScrollableMixinSuper = ClassNameMixin.prototype;
|
|
8
|
-
const aliasProps = 'pageIndex scrolling'.split(' ');
|
|
9
8
|
|
|
10
9
|
export default function ScrollableMixin() {
|
|
11
10
|
var self = this;
|
|
@@ -36,6 +35,7 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
|
|
|
36
35
|
},
|
|
37
36
|
initElement: function (element, state) {
|
|
38
37
|
var self = this;
|
|
38
|
+
ScrollableMixinSuper.initElement.call(self, element, state);
|
|
39
39
|
self.onDispose(app.on(element, {
|
|
40
40
|
scrollIndexChange: function (e) {
|
|
41
41
|
self.pageIndex = e.newIndex;
|
|
@@ -47,13 +47,6 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
|
|
|
47
47
|
self.scrolling = false;
|
|
48
48
|
}
|
|
49
49
|
}, true));
|
|
50
|
-
},
|
|
51
|
-
clone: function () {
|
|
52
|
-
var mixin = ScrollableMixinSuper.clone.call(this);
|
|
53
|
-
each(aliasProps, function (i, v) {
|
|
54
|
-
defineAliasProperty(mixin, v, self);
|
|
55
|
-
});
|
|
56
|
-
return mixin;
|
|
57
50
|
}
|
|
58
51
|
});
|
|
59
52
|
|
|
@@ -1,24 +1,72 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import Mixin from "./Mixin";
|
|
3
2
|
|
|
4
|
-
interface MixinState {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export interface MixinState {
|
|
4
|
+
/**
|
|
5
|
+
* Gets the element associated to this state object.
|
|
6
|
+
*/
|
|
7
|
+
readonly element: HTMLElement;
|
|
8
|
+
/**
|
|
9
|
+
* Additional state.
|
|
10
|
+
*/
|
|
11
|
+
[x: string]: any;
|
|
7
12
|
}
|
|
8
13
|
|
|
9
|
-
export interface MixinRef<T extends StatefulMixin = StatefulMixin> {
|
|
14
|
+
export interface MixinRef<T extends StatefulMixin = StatefulMixin> {
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
getMixin(): T;
|
|
19
|
+
}
|
|
10
20
|
|
|
11
21
|
export default abstract class StatefulMixin<T extends MixinState = MixinState> extends Mixin {
|
|
22
|
+
/**
|
|
23
|
+
* Gets a {@link MixinRef} object that can be passed to child components.
|
|
24
|
+
*/
|
|
12
25
|
get ref(): MixinRef<typeof this>;
|
|
13
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Gets a pending state object to store values before element is mounted.
|
|
28
|
+
*
|
|
29
|
+
* By default, existing values on the actual state object will be overwritten in subsequent update.
|
|
30
|
+
* To handle changes, overrides the {@link StatefulMixin.mergeState} method.
|
|
31
|
+
*/
|
|
32
|
+
protected get state(): Exclude<Partial<T>, 'element'>;
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Gets an array of mounted elements which this mixin has been applied.
|
|
36
|
+
*/
|
|
18
37
|
elements(): HTMLElement[];
|
|
38
|
+
/**
|
|
39
|
+
* Registers callback to clean up resources when the host component is unmounted.
|
|
40
|
+
* @param callback A callback.
|
|
41
|
+
*/
|
|
19
42
|
onDispose(callback: Zeta.UnregisterCallback): void;
|
|
20
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Override this method to create state object with initial values.
|
|
46
|
+
*/
|
|
21
47
|
protected initState(): T;
|
|
48
|
+
/**
|
|
49
|
+
* Override this method to initialize resources when the element is first mounted, e.g. attach event listeners.
|
|
50
|
+
* @param element A DOM element.
|
|
51
|
+
* @param state Persisted state object associated with the element.
|
|
52
|
+
*/
|
|
22
53
|
protected initElement(element: HTMLElement, state: T): void;
|
|
54
|
+
/**
|
|
55
|
+
* Override this method to handle state changes.
|
|
56
|
+
* When overriden, new states are required to copied manually to the persisted state object.
|
|
57
|
+
* @param element A DOM element.
|
|
58
|
+
* @param state Persisted state object associated with the element.
|
|
59
|
+
* @param newState New states passed from {@link StatefulMixin.state}.
|
|
60
|
+
*/
|
|
61
|
+
protected mergeState(element: HTMLElement, state: T, newState: Partial<T>): void;
|
|
62
|
+
/**
|
|
63
|
+
* Override this method to apply changes to mounted element.
|
|
64
|
+
* @param element A DOM element.
|
|
65
|
+
* @param state Persisted state object associated with the element.
|
|
66
|
+
*/
|
|
67
|
+
protected onLayoutEffect(element: HTMLElement, state: T): void;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated This method is no longer used.
|
|
70
|
+
*/
|
|
23
71
|
protected clone(): this;
|
|
24
72
|
}
|
package/mixins/StatefulMixin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { combineFn, createPrivateStore, definePrototype,
|
|
1
|
+
import { combineFn, createPrivateStore, definePrototype, extend, keys, map, pipe, watch } from "../include/zeta-dom/util.js";
|
|
2
2
|
import Mixin from "./Mixin.js";
|
|
3
3
|
|
|
4
4
|
const _ = createPrivateStore();
|
|
@@ -16,51 +16,53 @@ definePrototype(MixinRefImpl, {
|
|
|
16
16
|
export default function StatefulMixin() {
|
|
17
17
|
Mixin.call(this);
|
|
18
18
|
_(this, {
|
|
19
|
-
elements: new
|
|
19
|
+
elements: new Set(),
|
|
20
|
+
states: new WeakMap(),
|
|
20
21
|
flush: watch(this, false),
|
|
21
|
-
dispose: []
|
|
22
|
-
states: {},
|
|
23
|
-
prefix: '',
|
|
24
|
-
counter: 0
|
|
22
|
+
dispose: []
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
definePrototype(StatefulMixin, Mixin, {
|
|
29
27
|
get ref() {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
self.next();
|
|
33
|
-
return state.ref || (state.ref = new MixinRefImpl(self.clone()));
|
|
28
|
+
const state = _(this);
|
|
29
|
+
return state.ref || (state.ref = new MixinRefImpl(this));
|
|
34
30
|
},
|
|
35
31
|
get state() {
|
|
36
|
-
|
|
37
|
-
const key = obj.prefix + obj.counter;
|
|
38
|
-
return obj.states[key] || (obj.states[key] = this.initState());
|
|
32
|
+
return _(this).pending;
|
|
39
33
|
},
|
|
40
34
|
reset: function () {
|
|
41
|
-
_(this).
|
|
35
|
+
_(this).pending = {};
|
|
42
36
|
return this;
|
|
43
37
|
},
|
|
44
38
|
next: function () {
|
|
45
|
-
_(this).
|
|
39
|
+
_(this).pending = {};
|
|
46
40
|
return this;
|
|
47
41
|
},
|
|
48
42
|
getRef: function () {
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
var self = this;
|
|
44
|
+
var obj = _(self);
|
|
45
|
+
var newState = obj.pending;
|
|
46
|
+
var state;
|
|
51
47
|
return function (current) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
if (current) {
|
|
49
|
+
state = obj.states.get(current) || extend(self.initState(), newState);
|
|
50
|
+
if (state.element !== current) {
|
|
51
|
+
state.element = current;
|
|
52
|
+
self.initElement(current, state);
|
|
53
|
+
obj.states.set(current, state);
|
|
54
|
+
} else if (keys(newState)[0]) {
|
|
55
|
+
self.mergeState(current, state, newState);
|
|
56
|
+
}
|
|
57
|
+
self.onLayoutEffect(current, state);
|
|
58
|
+
obj.elements.add(current);
|
|
59
|
+
} else {
|
|
60
|
+
obj.elements.delete(state.element);
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
63
|
},
|
|
58
64
|
elements: function () {
|
|
59
|
-
return
|
|
60
|
-
return v.element;
|
|
61
|
-
}).filter(function (v) {
|
|
62
|
-
return v;
|
|
63
|
-
});
|
|
65
|
+
return map(_(this).elements, pipe);
|
|
64
66
|
},
|
|
65
67
|
onDispose: function (callback) {
|
|
66
68
|
_(this).dispose.push(callback);
|
|
@@ -70,23 +72,19 @@ definePrototype(StatefulMixin, Mixin, {
|
|
|
70
72
|
},
|
|
71
73
|
initElement: function (element, state) {
|
|
72
74
|
},
|
|
75
|
+
mergeState: function (element, state, newState) {
|
|
76
|
+
extend(state, newState);
|
|
77
|
+
},
|
|
78
|
+
onLayoutEffect: function (element, state) {
|
|
79
|
+
},
|
|
73
80
|
clone: function () {
|
|
74
|
-
|
|
75
|
-
const clone = inherit(Object.getPrototypeOf(self), self);
|
|
76
|
-
_(clone, extend({}, _(self), {
|
|
77
|
-
prefix: randomId() + '.',
|
|
78
|
-
counter: 0
|
|
79
|
-
}));
|
|
80
|
-
return clone;
|
|
81
|
+
return this;
|
|
81
82
|
},
|
|
82
83
|
dispose: function () {
|
|
83
84
|
var state = _(this);
|
|
84
|
-
var states = state.states;
|
|
85
85
|
combineFn(state.dispose.splice(0))();
|
|
86
86
|
state.flush();
|
|
87
|
-
state.
|
|
88
|
-
|
|
89
|
-
delete states[i];
|
|
90
|
-
});
|
|
87
|
+
state.states = {};
|
|
88
|
+
state.pending = {};
|
|
91
89
|
}
|
|
92
90
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import ClassNameMixin from "./ClassNameMixin"
|
|
2
|
+
import Mixin from "./Mixin";
|
|
3
|
+
import { useUnmanagedClassNameMixin } from "../mixin"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Keeps track and preserves the presence of specified CSS classes on applied elements
|
|
7
|
+
* while the host component is re-rendered.
|
|
8
|
+
*
|
|
9
|
+
* Mixin should be created using {@link useUnmanagedClassNameMixin} and applied to element by {@link Mixin.use}.
|
|
10
|
+
*/
|
|
11
|
+
export default class UnmanagedClassNameMixin extends ClassNameMixin {
|
|
12
|
+
/**
|
|
13
|
+
* Memorizes which specified CSS class names are present on the element,
|
|
14
|
+
* and re-apply them in the next render.
|
|
15
|
+
* @param classes A list of CSS class names.
|
|
16
|
+
*/
|
|
17
|
+
memorize(...classes: string[]): this;
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { definePrototype, makeArray } from "../include/zeta-dom/util.js";
|
|
2
|
+
import ClassNameMixin from "./ClassNameMixin.js";
|
|
3
|
+
|
|
4
|
+
export default function UnmanagedClassNameMixin() {
|
|
5
|
+
ClassNameMixin.call(this);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
definePrototype(UnmanagedClassNameMixin, ClassNameMixin, {
|
|
9
|
+
memorize: function () {
|
|
10
|
+
this.classNames = makeArray(arguments);
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
});
|
package/package.json
CHANGED
package/view.js
CHANGED
|
@@ -168,7 +168,7 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
168
168
|
self.currentElement = element;
|
|
169
169
|
state.container = element;
|
|
170
170
|
promise.then(function () {
|
|
171
|
-
animateIn(element, 'show');
|
|
171
|
+
animateIn(element, 'show', '[brew-view]', true);
|
|
172
172
|
app.emit('pageenter', element, { pathname: app.path }, true);
|
|
173
173
|
});
|
|
174
174
|
notifyAsync(element, promise);
|
|
@@ -181,7 +181,7 @@ definePrototype(ViewContainer, React.Component, {
|
|
|
181
181
|
});
|
|
182
182
|
var view = React.createElement(StateContext.Provider, { key: routeMap.get(V).id, value: state },
|
|
183
183
|
React.createElement(ViewStateContainer, null,
|
|
184
|
-
React.createElement('div', extend({}, self.props.rootProps, { ref: initElement }),
|
|
184
|
+
React.createElement('div', extend({}, self.props.rootProps, { ref: initElement, 'brew-view': '' }),
|
|
185
185
|
React.createElement(ErrorBoundary, { onComponentLoaded, viewProps }))));
|
|
186
186
|
extend(self, _(state), {
|
|
187
187
|
cancelPrevious: onComponentLoaded,
|