brew-js-react 0.3.2 → 0.3.3
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 +1753 -1749
- 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 +18 -5
- package/mixins/FlyoutMixin.js +2 -2
- package/mixins/FocusStateMixin.js +2 -2
- package/mixins/LoadingStateMixin.js +2 -2
- package/mixins/ScrollableMixin.js +2 -2
- package/mixins/StatefulMixin.js +2 -1
- package/package.json +5 -2
- package/view.js +6 -2
package/hooks.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { ViewStateProvider } from "zeta-dom-react";
|
|
3
3
|
import { definePrototype, extend, kv, setImmediateOnce, throwNotFunction, watch } from "./include/zeta-dom/util.js";
|
|
4
|
+
import { bind } from "./include/zeta-dom/domUtil.js";
|
|
4
5
|
import { ZetaEventContainer } from "./include/zeta-dom/events.js";
|
|
5
6
|
import { app } from "./app.js";
|
|
6
7
|
import { useViewContainerState } from "./view.js";
|
|
@@ -77,13 +78,25 @@ export function useRouteParam(name, defaultValue) {
|
|
|
77
78
|
return value;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
export function useRouteState(key, defaultValue) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (container.active) {
|
|
81
|
+
export function useRouteState(key, defaultValue, snapshotOnUpdate) {
|
|
82
|
+
var container = useViewContainerState();
|
|
83
|
+
var cur = getCurrentStates();
|
|
84
|
+
var state = useState(key in cur ? cur[key] : defaultValue);
|
|
85
|
+
if (container.active && cur[key] !== state[0]) {
|
|
86
|
+
if (snapshotOnUpdate && key in cur) {
|
|
87
|
+
app.snapshot();
|
|
88
|
+
cur = getCurrentStates();
|
|
89
|
+
}
|
|
85
90
|
cur[key] = state[0];
|
|
86
91
|
}
|
|
92
|
+
useEffect(function () {
|
|
93
|
+
return bind(window, 'popstate', function () {
|
|
94
|
+
if (snapshotOnUpdate && container.active) {
|
|
95
|
+
var cur = getCurrentStates();
|
|
96
|
+
state[1](key in cur ? cur[key] : defaultValue);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}, [container, snapshotOnUpdate]);
|
|
87
100
|
return state;
|
|
88
101
|
}
|
|
89
102
|
|
package/mixins/FlyoutMixin.js
CHANGED
|
@@ -79,14 +79,14 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
|
|
|
79
79
|
if (!element.id) {
|
|
80
80
|
element.id = 'flyout-' + (++flyoutMixinCounter);
|
|
81
81
|
}
|
|
82
|
-
app.on(element, {
|
|
82
|
+
self.onDispose(app.on(element, {
|
|
83
83
|
animationstart: function () {
|
|
84
84
|
self.animating = true;
|
|
85
85
|
},
|
|
86
86
|
animationcomplete: function () {
|
|
87
87
|
self.animating = false;
|
|
88
88
|
},
|
|
89
|
-
}, true);
|
|
89
|
+
}, true));
|
|
90
90
|
setImmediate(function () {
|
|
91
91
|
each(self.toggle.elements(), function (i, v) {
|
|
92
92
|
v.setAttribute('toggle', '#' + element.id);
|
|
@@ -12,7 +12,7 @@ export default function FocusStateMixin() {
|
|
|
12
12
|
definePrototype(FocusStateMixin, StatefulMixin, {
|
|
13
13
|
initElement: function (element, state) {
|
|
14
14
|
FocusStateMixinSuper.initElement.call(this, element, state);
|
|
15
|
-
dom.on(element, {
|
|
15
|
+
this.onDispose(dom.on(element, {
|
|
16
16
|
focusin: function (e) {
|
|
17
17
|
state.focused = true;
|
|
18
18
|
setClass(element, 'focused', e.source);
|
|
@@ -21,7 +21,7 @@ definePrototype(FocusStateMixin, StatefulMixin, {
|
|
|
21
21
|
state.focused = false;
|
|
22
22
|
setClass(element, 'focused', false);
|
|
23
23
|
}
|
|
24
|
-
});
|
|
24
|
+
}));
|
|
25
25
|
},
|
|
26
26
|
getClassNames: function () {
|
|
27
27
|
return [{ focused: !!this.state.focused }];
|
|
@@ -14,7 +14,7 @@ definePrototype(LoadingStateMixin, StatefulMixin, {
|
|
|
14
14
|
initElement: function (element, state) {
|
|
15
15
|
LoadingStateMixinSuper.initElement.call(this, element, state);
|
|
16
16
|
lock(element);
|
|
17
|
-
dom.on(element, {
|
|
17
|
+
this.onDispose(dom.on(element, {
|
|
18
18
|
asyncStart: function () {
|
|
19
19
|
state.loading = true;
|
|
20
20
|
setClass(element, 'loading', true);
|
|
@@ -27,7 +27,7 @@ definePrototype(LoadingStateMixin, StatefulMixin, {
|
|
|
27
27
|
state.loading = false;
|
|
28
28
|
setClass(element, 'loading', false);
|
|
29
29
|
}
|
|
30
|
-
});
|
|
30
|
+
}));
|
|
31
31
|
},
|
|
32
32
|
getClassNames: function () {
|
|
33
33
|
return [{ loading: !!this.state.loading }];
|
|
@@ -35,7 +35,7 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
|
|
|
35
35
|
},
|
|
36
36
|
initElement: function (element, state) {
|
|
37
37
|
var self = this;
|
|
38
|
-
app.on(element, {
|
|
38
|
+
self.onDispose(app.on(element, {
|
|
39
39
|
statechange: function (e) {
|
|
40
40
|
if ('pageIndex' in e.newValues) {
|
|
41
41
|
extend(self, { pageIndex: e.newValues.pageIndex });
|
|
@@ -47,7 +47,7 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
|
|
|
47
47
|
scrollStop: function() {
|
|
48
48
|
self.scrolling = false;
|
|
49
49
|
}
|
|
50
|
-
}, true);
|
|
50
|
+
}, true));
|
|
51
51
|
},
|
|
52
52
|
clone: function () {
|
|
53
53
|
var mixin = ScrollableMixinSuper.clone.call(this);
|
package/mixins/StatefulMixin.js
CHANGED
|
@@ -16,7 +16,7 @@ definePrototype(MixinRefImpl, {
|
|
|
16
16
|
export default function StatefulMixin() {
|
|
17
17
|
Mixin.call(this);
|
|
18
18
|
_(this, {
|
|
19
|
-
elements: new
|
|
19
|
+
elements: new Set(),
|
|
20
20
|
flush: watch(this, false),
|
|
21
21
|
dispose: [],
|
|
22
22
|
states: {},
|
|
@@ -84,6 +84,7 @@ definePrototype(StatefulMixin, Mixin, {
|
|
|
84
84
|
var states = state.states;
|
|
85
85
|
combineFn(state.dispose.splice(0))();
|
|
86
86
|
state.flush();
|
|
87
|
+
state.elements.clear();
|
|
87
88
|
each(states, function (i, v) {
|
|
88
89
|
delete states[i];
|
|
89
90
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brew-js-react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"repository": "github:misonou/brew-js-react",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@misonou/react-dom-client": "^1.0.3",
|
|
16
|
-
"brew-js": ">=0.4.
|
|
16
|
+
"brew-js": ">=0.4.9",
|
|
17
17
|
"waterpipe": "^2.5.0",
|
|
18
18
|
"zeta-dom": ">=0.3.1",
|
|
19
19
|
"zeta-dom-react": ">=0.2.1"
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"webpack": "^5.3.0",
|
|
44
44
|
"webpack-cli": "^4.1.0"
|
|
45
45
|
},
|
|
46
|
+
"sideEffects": [
|
|
47
|
+
"./src/app.js"
|
|
48
|
+
],
|
|
46
49
|
"keywords": [
|
|
47
50
|
"html",
|
|
48
51
|
"dom",
|
package/view.js
CHANGED
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { useAsync } from "zeta-dom-react";
|
|
3
3
|
import dom from "./include/zeta-dom/dom.js";
|
|
4
4
|
import { notifyAsync } from "./include/zeta-dom/domLock.js";
|
|
5
|
-
import { any, combineFn, defineObservableProperty, definePrototype, each, exclude, executeOnce, extend, grep, isFunction, isThenable, isUndefinedOrNull, keys, makeArray, map, noop, pick, randomId, single, throwNotFunction, watch } from "./include/zeta-dom/util.js";
|
|
5
|
+
import { any, combineFn, defineObservableProperty, definePrototype, each, exclude, executeOnce, extend, grep, isFunction, isThenable, isUndefinedOrNull, keys, makeArray, map, noop, pick, randomId, setImmediate, single, throwNotFunction, watch } from "./include/zeta-dom/util.js";
|
|
6
6
|
import { animateIn, animateOut } from "./include/brew-js/anim.js";
|
|
7
7
|
import { removeQueryAndHash } from "./include/brew-js/util/path.js";
|
|
8
8
|
import { app } from "./app.js";
|
|
@@ -28,7 +28,11 @@ definePrototype(ErrorBoundary, React.Component, {
|
|
|
28
28
|
if (errorView && !self.state.error) {
|
|
29
29
|
self.setState({ error });
|
|
30
30
|
} else {
|
|
31
|
-
|
|
31
|
+
// emit error in next tick as ref callback may yet to be invoked
|
|
32
|
+
// if error is thrown synchronously in first render
|
|
33
|
+
setImmediate(function () {
|
|
34
|
+
dom.emit('error', self.context.container, { error }, true);
|
|
35
|
+
});
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
render: function () {
|