brew-js-react 0.6.6 → 0.7.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/dialog.d.ts +72 -1
- package/dialog.js +153 -59
- package/dist/brew-js-react.js +185 -98
- 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/mixins/AnimateMixin.d.ts +6 -0
- package/mixins/AnimateSequenceItemMixin.d.ts +6 -0
- package/mixins/AnimateSequenceMixin.d.ts +6 -0
- package/mixins/FlyoutMixin.d.ts +6 -0
- package/mixins/Mixin.d.ts +16 -13
- package/mixins/Mixin.js +17 -23
- package/mixins/ScrollableMixin.d.ts +7 -1
- package/mixins/StaticAttributeMixin.d.ts +9 -3
- package/package.json +4 -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/mixins/AnimateMixin.d.ts
CHANGED
|
@@ -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,10 @@ 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
|
+
getCustomAttributes(): Record<'animate-sequence' | 'animate-sequence-type' | 'animate-out', string>;
|
|
16
22
|
}
|
package/mixins/FlyoutMixin.d.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
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 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
|
|
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
|
|
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():
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(
|
|
58
|
-
|
|
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,19 @@
|
|
|
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:
|
|
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:
|
|
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
|
+
getCustomAttributes(): P;
|
|
13
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brew-js-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.
|
|
16
|
+
"brew-js": ">=0.7.1",
|
|
17
17
|
"waterpipe": "^2.5.0",
|
|
18
|
-
"zeta-dom": ">=0.
|
|
19
|
-
"zeta-dom-react": ">=0.
|
|
18
|
+
"zeta-dom": ">=0.6.0",
|
|
19
|
+
"zeta-dom-react": ">=0.6.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": ">=16.8.0",
|