brew-js-react 0.6.5 → 0.6.7
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.d.ts +58 -1
- package/dialog.js +157 -58
- package/dist/brew-js-react.js +190 -77
- 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/mixin.d.ts +13 -0
- package/mixin.js +8 -8
- package/package.json +1 -1
- package/view.d.ts +6 -1
- package/view.js +17 -4
package/mixin.d.ts
CHANGED
|
@@ -9,10 +9,15 @@ import FlyoutToggleMixin from "./mixins/FlyoutToggleMixin";
|
|
|
9
9
|
import FocusStateMixin from "./mixins/FocusStateMixin";
|
|
10
10
|
import LoadingStateMixin from "./mixins/LoadingStateMixin";
|
|
11
11
|
import StatefulMixin, { MixinRef } from "./mixins/StatefulMixin";
|
|
12
|
+
import StaticAttributeMixin from "./mixins/StaticAttributeMixin";
|
|
12
13
|
import ScrollableMixin, { ScrollableMixinOptions } from "./mixins/ScrollableMixin";
|
|
13
14
|
import ScrollIntoViewMixin from "./mixins/ScrollIntoViewMixin";
|
|
14
15
|
import UnmanagedClassNameMixin from "./mixins/UnmanagedClassNameMixin";
|
|
15
16
|
|
|
17
|
+
export interface WithOptions<T> {
|
|
18
|
+
withOptions(options: T): this;
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
export * from "./mixins/Mixin";
|
|
17
22
|
export * from "./mixins/AnimateMixin";
|
|
18
23
|
export * from "./mixins/AnimateSequenceItemMixin";
|
|
@@ -36,6 +41,7 @@ export {
|
|
|
36
41
|
FocusStateMixin,
|
|
37
42
|
LoadingStateMixin,
|
|
38
43
|
StatefulMixin,
|
|
44
|
+
StaticAttributeMixin,
|
|
39
45
|
ScrollableMixin,
|
|
40
46
|
ScrollIntoViewMixin,
|
|
41
47
|
UnmanagedClassNameMixin,
|
|
@@ -100,6 +106,13 @@ export function useClassNameToggleMixin<T extends Zeta.Dictionary<boolean>>(dict
|
|
|
100
106
|
*/
|
|
101
107
|
export function useMixin<T extends typeof Mixin>(mixin: T): InstanceType<T>;
|
|
102
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Creates a mixin of the specified type within the lifetime of current component.
|
|
111
|
+
* @param mixin Constructor of the mixin type.
|
|
112
|
+
* @param options A dictionary specifying options.
|
|
113
|
+
*/
|
|
114
|
+
export function useMixin<T extends typeof Mixin>(mixin: T, options: InstanceType<T> extends WithOptions<infer U> ? U : never): InstanceType<T>;
|
|
115
|
+
|
|
103
116
|
/**
|
|
104
117
|
* Uses mixin passed from parent component.
|
|
105
118
|
* @param mixin A {@link MixinRef} object.
|
package/mixin.js
CHANGED
|
@@ -11,6 +11,7 @@ import FlyoutToggleMixin from "./mixins/FlyoutToggleMixin.js";
|
|
|
11
11
|
import FocusStateMixin from "./mixins/FocusStateMixin.js";
|
|
12
12
|
import LoadingStateMixin from "./mixins/LoadingStateMixin.js";
|
|
13
13
|
import StatefulMixin from "./mixins/StatefulMixin.js";
|
|
14
|
+
import StaticAttributeMixin from "./mixins/StaticAttributeMixin.js";
|
|
14
15
|
import ScrollableMixin from "./mixins/ScrollableMixin.js";
|
|
15
16
|
import ScrollIntoViewMixin from "./mixins/ScrollIntoViewMixin.js";
|
|
16
17
|
import UnmanagedClassNameMixin from "./mixins/UnmanagedClassNameMixin.js";
|
|
@@ -20,11 +21,7 @@ function extendSelf(options) {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function createUseFunction(ctor) {
|
|
23
|
-
return
|
|
24
|
-
var mixin = useMixin(ctor);
|
|
25
|
-
(mixin.withOptions || extendSelf).apply(mixin, arguments);
|
|
26
|
-
return mixin;
|
|
27
|
-
};
|
|
24
|
+
return useMixin.bind(0, ctor);
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
export const useAnimateMixin = /*#__PURE__*/ createUseFunction(AnimateMixin);
|
|
@@ -37,10 +34,12 @@ export const useScrollableMixin = /*#__PURE__*/ createUseFunction(ScrollableMixi
|
|
|
37
34
|
export const useScrollIntoViewMixin = /*#__PURE__*/ createUseFunction(ScrollIntoViewMixin);
|
|
38
35
|
export const useUnmanagedClassNameMixin = /*#__PURE__*/ createUseFunction(UnmanagedClassNameMixin);
|
|
39
36
|
|
|
40
|
-
export function useMixin(ctor) {
|
|
41
|
-
|
|
37
|
+
export function useMixin(ctor, options) {
|
|
38
|
+
var mixin = useSingleton(function () {
|
|
42
39
|
return new ctor();
|
|
43
|
-
}).reset();
|
|
40
|
+
}, []).reset();
|
|
41
|
+
(mixin.withOptions || extendSelf).call(mixin, options);
|
|
42
|
+
return mixin;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export function useMixinRef(mixin) {
|
|
@@ -59,6 +58,7 @@ export {
|
|
|
59
58
|
FocusStateMixin,
|
|
60
59
|
LoadingStateMixin,
|
|
61
60
|
StatefulMixin,
|
|
61
|
+
StaticAttributeMixin,
|
|
62
62
|
ScrollableMixin,
|
|
63
63
|
ScrollIntoViewMixin,
|
|
64
64
|
UnmanagedClassNameMixin,
|
package/package.json
CHANGED
package/view.d.ts
CHANGED
|
@@ -139,7 +139,11 @@ export interface ErrorViewProps<T = any> {
|
|
|
139
139
|
reset(): void;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export interface ViewComponentRootProps extends Omit<React.ComponentProps<'div'>, 'onError'> {
|
|
142
|
+
export interface ViewComponentRootProps extends Omit<React.ComponentProps<'div'>, 'onError' | 'ref'> {
|
|
143
|
+
/**
|
|
144
|
+
* Specifies a ref object that can retrieve the active view context.
|
|
145
|
+
*/
|
|
146
|
+
ref?: React.RefObject<ViewContext>;
|
|
143
147
|
/**
|
|
144
148
|
* Specifies initial loader if the first matched view is lazy-loaded.
|
|
145
149
|
*/
|
|
@@ -148,6 +152,7 @@ export interface ViewComponentRootProps extends Omit<React.ComponentProps<'div'>
|
|
|
148
152
|
* Specifies callback to handle error raised within the view.
|
|
149
153
|
* @param event Error event.
|
|
150
154
|
* @param context Associated view context.
|
|
155
|
+
* @deprecated
|
|
151
156
|
*/
|
|
152
157
|
onError?: (event: Zeta.ZetaErrorEvent<HTMLElement, ViewContext>, context: ViewContext) => any;
|
|
153
158
|
}
|
package/view.js
CHANGED
|
@@ -107,7 +107,7 @@ definePrototype(ErrorBoundary, Component, {
|
|
|
107
107
|
setImmediate(function () {
|
|
108
108
|
extend(self, createAsyncScope(context.container));
|
|
109
109
|
dom.on(context.container, 'error', function (e) {
|
|
110
|
-
return emitter.emit(e, context, { error: e.error });
|
|
110
|
+
return emitter.emit(e, context, { error: e.error }, false);
|
|
111
111
|
});
|
|
112
112
|
self.forceUpdate();
|
|
113
113
|
});
|
|
@@ -162,6 +162,14 @@ definePrototype(ViewContainer, Component, {
|
|
|
162
162
|
parent.push(self);
|
|
163
163
|
self.setActive(true);
|
|
164
164
|
},
|
|
165
|
+
componentDidUpdate: function (prevProps) {
|
|
166
|
+
(prevProps.rootProps.ref || {}).current = null;
|
|
167
|
+
this.setContext(this.currentContext);
|
|
168
|
+
},
|
|
169
|
+
setContext: function (context) {
|
|
170
|
+
this.currentContext = context;
|
|
171
|
+
(this.props.rootProps.ref || {}).current = context;
|
|
172
|
+
},
|
|
165
173
|
render: function () {
|
|
166
174
|
/** @type {any} */
|
|
167
175
|
var self = this;
|
|
@@ -200,7 +208,12 @@ definePrototype(ViewContainer, Component, {
|
|
|
200
208
|
var rootProps = self.props.rootProps;
|
|
201
209
|
var initElement = executeOnce(function (element) {
|
|
202
210
|
defineOwnProperty(context, 'container', element, true);
|
|
203
|
-
|
|
211
|
+
dom.on(element, 'error', function (e) {
|
|
212
|
+
if (context !== self.currentContext) {
|
|
213
|
+
e.handled();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
self.setContext(self.currentContext || context);
|
|
204
217
|
});
|
|
205
218
|
var onLoad = executeOnce(function () {
|
|
206
219
|
var element = context.container;
|
|
@@ -218,14 +231,14 @@ definePrototype(ViewContainer, Component, {
|
|
|
218
231
|
app.emit('pageenter', element, { pathname: context.page.path, view: V }, true);
|
|
219
232
|
});
|
|
220
233
|
self.views.shift();
|
|
221
|
-
self.
|
|
234
|
+
self.setContext(context);
|
|
222
235
|
extend(self, _(context));
|
|
223
236
|
state.rendered++;
|
|
224
237
|
animateIn(element, 'show', '[brew-view]', true);
|
|
225
238
|
resolve();
|
|
226
239
|
});
|
|
227
240
|
context.on('error', function () {
|
|
228
|
-
return (rootProps.onError || noop).apply(this, arguments);
|
|
241
|
+
return (self.props.rootProps.onError || noop).apply(this, arguments);
|
|
229
242
|
});
|
|
230
243
|
self.abort = resolve;
|
|
231
244
|
self.views[2] = createElement(StateContext.Provider, { key: state.id, value: context },
|