brew-js-react 0.6.7 → 0.7.1

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.
@@ -48,4 +48,10 @@ export default class AnimateMixin extends ClassNameMixin {
48
48
  * @see {@link AnimationEffect} and {@link AnimationTrigger}.
49
49
  */
50
50
  withEffects(...effects: AnimationEffect[]): this;
51
+
52
+ /**
53
+ * Applies custom attributes to element.
54
+ * @private It is used internally by mixins and is declared for type inference.
55
+ */
56
+ getCustomAttributes(): Record<'animate-in' | 'animate-out', string>;
51
57
  }
@@ -8,4 +8,10 @@ import ClassNameMixin from "./ClassNameMixin";
8
8
  */
9
9
  export default class AnimateSequenceItemMixin extends ClassNameMixin {
10
10
  constructor(className: string);
11
+
12
+ /**
13
+ * Applies custom attributes to element.
14
+ * @private It is used internally by mixins and is declared for type inference.
15
+ */
16
+ getCustomAttributes(): Record<'is-animate-sequence', string>;
11
17
  }
@@ -13,4 +13,11 @@ export default class AnimateSequenceMixin extends AnimateMixin {
13
13
  * Returns a mixin that marks element to be a target of this animate sequence.
14
14
  */
15
15
  readonly item: AnimateSequenceItemMixin;
16
+
17
+ /**
18
+ * Applies custom attributes to element.
19
+ * @private It is used internally by mixins and is declared for type inference.
20
+ */
21
+ // @ts-ignore
22
+ getCustomAttributes(): Record<'animate-sequence' | 'animate-sequence-type' | 'animate-out', string>;
16
23
  }
@@ -131,4 +131,10 @@ export default class FlyoutMixin<S = any, R = any> extends ClassNameMixin {
131
131
  * @returns A promise that resolves when the flyout is being closed.
132
132
  */
133
133
  toggleSelf(flag: boolean, source?: Element): Promise<HintedType<R>>;
134
+
135
+ /**
136
+ * Applies custom attributes to element.
137
+ * @private It is used internally by mixins and is declared for type inference.
138
+ */
139
+ getCustomAttributes(): Record<'is-flyout' | 'is-modal' | 'tab-through' | 'swipe-dismiss' | 'animate-on' | 'animate-in' | 'animate-out', string>;
134
140
  }
package/mixins/Mixin.d.ts CHANGED
@@ -2,32 +2,35 @@ import React from "react";
2
2
  import { ClassName, ClassNameProvider } from "zeta-dom-react";
3
3
  import StaticAttributeMixin from "./StaticAttributeMixin";
4
4
 
5
- interface MixinProps {
6
- ref: React.RefCallback<Element>;
5
+ export type MixinProps<T extends Element, M> = MixinDefaultProps<T> & UnionToIntersection<M extends CustomAttributeProvider<infer P> ? P : never>;
6
+
7
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
8
+ type MixinTypes<T extends readonly unknown[]> = Extract<Zeta.ArrayMember<T>, CustomAttributeProvider>;
9
+
10
+ interface MixinDefaultProps<T extends Element> {
11
+ ref: React.RefCallback<T>;
7
12
  className: string;
8
13
  }
9
14
 
15
+ interface CustomAttributeProvider<T = {}> {
16
+ getCustomAttributes(): T;
17
+ }
18
+
10
19
  export default abstract class Mixin implements ClassNameProvider {
11
- static readonly scrollableTarget: StaticAttributeMixin;
12
- static readonly tabRoot: StaticAttributeMixin;
20
+ static readonly scrollableTarget: StaticAttributeMixin<Record<'scrollable-target', string>>;
21
+ static readonly tabRoot: StaticAttributeMixin<Record<'tab-root', string>>;
13
22
 
14
23
  /**
15
24
  * Applies React ref and mixins to element.
16
25
  * @param ref A ref callback or ref object.
17
26
  * @param args Mixin instances or string literals. String literals are applied to element as CSS classes.
18
27
  */
19
- static use(ref: React.ForwardedRef<any>, ...args: (Mixin | string | undefined)[]): MixinProps;
28
+ static use<T extends Element, M extends readonly (Mixin | string | undefined)[]>(ref: React.ForwardedRef<T>, ...args: M): MixinProps<T, MixinTypes<M>>;
20
29
  /**
21
30
  * Applies mixins to element.
22
- * @param mixin Mixin instance.
23
31
  * @param args Mixin instances or string literals. String literals are applied to element as CSS classes.
24
32
  */
25
- static use(mixin: Mixin, ...args: (Mixin | string | undefined)[]): MixinProps;
26
- /**
27
- * Applies mixins to element.
28
- * @param mixins Mixin instances.
29
- */
30
- static use(...mixins: (Mixin | undefined)[]): MixinProps;
33
+ static use<M extends readonly (Mixin | string | undefined)[]>(...args: M): MixinProps<Element, MixinTypes<M>>;
31
34
 
32
35
  /**
33
36
  * @private Internal use.
@@ -48,7 +51,7 @@ export default abstract class Mixin implements ClassNameProvider {
48
51
  /**
49
52
  * Override this method to apply custom attributes to element.
50
53
  */
51
- getCustomAttributes(): Zeta.Dictionary<string>;
54
+ getCustomAttributes(): {};
52
55
  /**
53
56
  * @private Internal use.
54
57
  */
package/mixins/Mixin.js CHANGED
@@ -34,36 +34,30 @@ define(Mixin, {
34
34
  },
35
35
  use: function () {
36
36
  const args = makeArray(arguments);
37
- const ref = args[0];
38
37
  const props = {};
39
- const mixins = args.filter(function (v) {
40
- return v instanceof Mixin;
41
- });
42
- const refs = mixins.map(function (v) {
43
- return v.getRef();
44
- });
45
- if (ref && !(ref instanceof Mixin)) {
46
- if (typeof ref !== 'function') {
47
- refs.push(function (v) {
48
- ref.current = v;
49
- });
50
- } else {
51
- refs.push(ref);
52
- }
38
+ const refs = [];
39
+ const ref = args[0];
40
+ if (!ref) {
41
+ args.shift();
42
+ } else if (typeof ref === 'function') {
43
+ refs.push(ref);
53
44
  args.shift();
54
- } else if (!ref) {
45
+ } else if (typeof ref !== 'string' && !(ref instanceof Mixin)) {
46
+ refs.push(function (w) {
47
+ ref.current = w;
48
+ });
55
49
  args.shift();
56
50
  }
57
- each(mixins, function (i, v) {
58
- extend(props, v.getCustomAttributes());
51
+ each(args, function (i, v) {
52
+ if (v instanceof Mixin) {
53
+ refs.push(v.getRef());
54
+ extend(props, v.getCustomAttributes());
55
+ v.next();
56
+ }
59
57
  });
60
- extend(props, {
58
+ return extend(props, {
61
59
  ref: combineFn(refs),
62
60
  className: classNames.apply(null, args)
63
61
  });
64
- each(mixins, function (i, v) {
65
- v.next();
66
- });
67
- return props;
68
62
  }
69
63
  });
@@ -53,7 +53,7 @@ export default class ScrollableMixin extends ClassNameMixin implements JQueryScr
53
53
  * Gets a mixin object that when applied to descecant element
54
54
  * the element will act as content to be scrolled.
55
55
  */
56
- readonly target: StaticAttributeMixin;
56
+ readonly target: StaticAttributeMixin<Record<'scrollable-target', string>>;
57
57
  /**
58
58
  * Gets the element with scrollable plugin enabled.
59
59
  */
@@ -188,4 +188,10 @@ export default class ScrollableMixin extends ClassNameMixin implements JQueryScr
188
188
  * @returns A promise that resolves when scrolling is completed.
189
189
  */
190
190
  scrollToElement(target: Element | string, targetOrigin?: string, wrapperOrigin?: string, duration?: number, callback?: () => void): Promise<void> & JQueryScrollableState;
191
+
192
+ /**
193
+ * Applies custom attributes to element.
194
+ * @private It is used internally by mixins and is declared for type inference.
195
+ */
196
+ getCustomAttributes(): Record<'scrollable' | 'scroller-snap-page' | 'scroller-page' | 'persist-scroll', string>;
191
197
  }
@@ -1,13 +1,20 @@
1
1
  import Mixin from "./Mixin";
2
2
 
3
- export default class StaticAttributeMixin extends Mixin {
3
+ export default class StaticAttributeMixin<P = {}> extends Mixin {
4
4
  /**
5
5
  * @param name Name of attribute.
6
6
  * @param value Value to be set. Default is empty string.
7
7
  */
8
- constructor(name: string, value?: string);
8
+ constructor(name: keyof P, value?: P[keyof P]);
9
9
  /**
10
10
  * @param attributes A dictionary containing attributes and their values to be set on rendered elements.
11
11
  */
12
- constructor(attributes: Record<string, string>);
12
+ constructor(attributes: P);
13
+
14
+ /**
15
+ * Applies custom attributes to element.
16
+ * @private It is used internally by mixins and is declared for type inference.
17
+ */
18
+ // @ts-ignore
19
+ getCustomAttributes(): P;
13
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brew-js-react",
3
- "version": "0.6.7",
3
+ "version": "0.7.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -13,10 +13,10 @@
13
13
  "repository": "github:misonou/brew-js-react",
14
14
  "dependencies": {
15
15
  "@misonou/react-dom-client": "^1.1.1",
16
- "brew-js": ">=0.6.12",
16
+ "brew-js": ">=0.7.1",
17
17
  "waterpipe": "^2.5.0",
18
- "zeta-dom": ">=0.5.11",
19
- "zeta-dom-react": ">=0.5.11"
18
+ "zeta-dom": ">=0.6.0",
19
+ "zeta-dom-react": ">=0.6.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react": ">=16.8.0",
@@ -28,13 +28,12 @@
28
28
  "@babel/preset-react": "^7.16.7",
29
29
  "@jest/globals": "^26.6.2",
30
30
  "@misonou/build-utils": "^1.3.1",
31
- "@misonou/test-utils": "^1.0.3",
31
+ "@misonou/test-utils": "^1.4.3",
32
32
  "@testing-library/dom": "^8.11.3",
33
33
  "@testing-library/react": "^12.1.2",
34
34
  "@testing-library/react-hooks": "^7.0.2",
35
35
  "@types/jest": "^26.0.15",
36
36
  "babel-loader": "^9.1.3",
37
- "check-dts": "^0.8.2",
38
37
  "cross-env": "^7.0.2",
39
38
  "expect-type": "^0.20.0",
40
39
  "jest": "^27.0.6",
package/view.d.ts CHANGED
@@ -98,7 +98,14 @@ export class ViewContext implements Zeta.ZetaEventDispatcher<ViewContextEventMap
98
98
  * @param event Name of the event.
99
99
  * @param handler A callback function to be fired when the specified event is triggered.
100
100
  */
101
- on<E extends keyof ViewContextEventMap>(event: E, handler: Zeta.ZetaEventHandler<E, ViewContextEventMap, ViewContext>): Zeta.UnregisterCallback;
101
+ on<E extends Zeta.StringKeyOf<ViewContextEventMap>>(event: E, handler: Zeta.ZetaEventHandler<E, ViewContextEventMap, ViewContext>): Zeta.UnregisterCallback;
102
+
103
+ /**
104
+ * Adds an event handler to a specific event.
105
+ * @param event Name of the event.
106
+ * @param handler A callback function to be fired when the specified event is triggered.
107
+ */
108
+ on<E extends Zeta.HintedStringKeyOf<ViewContextEventMap>>(event: E, handler: Zeta.ZetaEventHandler<Zeta.WhitespaceDelimited<E>, ViewContextEventMap, ViewContext>): Zeta.UnregisterCallback;
102
109
  }
103
110
 
104
111
  export interface ViewProps<S = {}> {
package/view.js CHANGED
@@ -105,11 +105,13 @@ definePrototype(ErrorBoundary, Component, {
105
105
  var context = self.props.context;
106
106
  if (!context.container) {
107
107
  setImmediate(function () {
108
- extend(self, createAsyncScope(context.container));
109
- dom.on(context.container, 'error', function (e) {
110
- return emitter.emit(e, context, { error: e.error }, false);
111
- });
112
- self.forceUpdate();
108
+ if (!self.errorHandler) {
109
+ extend(self, createAsyncScope(context.container));
110
+ dom.on(context.container, 'error', function (e) {
111
+ return emitter.emit(e, context, { error: e.error }, false);
112
+ });
113
+ self.forceUpdate();
114
+ }
113
115
  });
114
116
  return null;
115
117
  }
@@ -312,7 +314,7 @@ function createViewComponent(factory) {
312
314
  }
313
315
  return function fn(props) {
314
316
  var children = promise || factory(props.viewProps);
315
- if (isThenable(children)) {
317
+ if (promise || isThenable(children)) {
316
318
  promise = children;
317
319
  catchAsync(promise);
318
320
  } else {
@@ -320,8 +322,8 @@ function createViewComponent(factory) {
320
322
  return children;
321
323
  }
322
324
  var component = useAsync(function () {
323
- return promise.then(null, function (error) {
324
- promise = null;
325
+ promise = true;
326
+ return (isThenable(children) || factory()).then(null, function (error) {
325
327
  props.onError(error);
326
328
  });
327
329
  })[0];