brew-js-react 0.1.5 → 0.1.6

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.
@@ -1,99 +1,119 @@
1
- import { defineAliasProperty, definePrototype, each, extend, makeArray } from "../include/zeta-dom/util.js";
2
- import { app } from "../app.js";
3
- import ClassNameMixin from "./ClassNameMixin.js";
4
-
5
- const FlyoutMixinSuper = ClassNameMixin.prototype;
6
- var flyoutMixinCounter = 0;
7
-
8
- export default function FlyoutMixin() {
9
- ClassNameMixin.call(this, ['open', 'closing', 'tweening-in', 'tweening-out']);
10
- this.modal = false;
11
- this.isFlyoutOpened = false;
12
- this.animating = false;
13
- this.visible = false;
14
- this.toggle = new ClassNameMixin(['target-opened']);
15
- }
16
-
17
- definePrototype(FlyoutMixin, ClassNameMixin, {
18
- reset: function () {
19
- this.toggle.reset();
20
- return FlyoutMixinSuper.reset.call(this);
21
- },
22
- next: function () {
23
- this.effects = undefined;
24
- return FlyoutMixinSuper.next.call(this);
25
- },
26
- withEffects: function () {
27
- this.effects = makeArray(arguments);
28
- return this;
29
- },
30
- getCustomAttributes: function () {
31
- return extend({}, FlyoutMixinSuper.getCustomAttributes.call(this), {
32
- 'is-flyout': ''
33
- }, this.modal && {
34
- 'is-modal': ''
35
- }, this.effects && {
36
- 'animate-on': 'open',
37
- 'animate-in': this.effects.join(' '),
38
- 'animate-out': ''
39
- });
40
- },
41
- onOpen: function (callback) {
42
- return this.onToggleState(function (opened) {
43
- if (opened) {
44
- return callback();
45
- }
46
- });
47
- },
48
- onToggleState: function (callback) {
49
- return this.watch('isFlyoutOpened', callback);
50
- },
51
- onVisibilityChanged: function (callback) {
52
- return this.watch('visible', callback);
53
- },
54
- initElement: function (element, state) {
55
- var self = this;
56
- FlyoutMixinSuper.initElement.call(self, element, state);
57
- if (!element.id) {
58
- element.id = 'flyout-' + (++flyoutMixinCounter);
59
- }
60
- app.on(element, {
61
- animationstart: function () {
62
- self.animating = true;
63
- },
64
- animationcomplete: function () {
65
- self.animating = false;
66
- },
67
- }, true);
68
- setImmediate(function () {
69
- each(self.toggle.elements(), function (i, v) {
70
- v.setAttribute('toggle', '#' + element.id);
71
- });
72
- });
73
- },
74
- clone: function () {
75
- var mixin = extend(FlyoutMixinSuper.clone.call(this), {
76
- toggle: this.toggle.ref.getMixin()
77
- });
78
- defineAliasProperty(mixin, 'isFlyoutOpened', this);
79
- defineAliasProperty(mixin, 'modal', this);
80
- return mixin;
81
- },
82
- onClassNameUpdated: function (element, prevState, state) {
83
- var self = this;
84
- var isAdded = function (v) {
85
- return prevState[v] !== state[v] && state[v];
86
- };
87
- var isRemoved = function (v) {
88
- return prevState[v] !== state[v] && !state[v];
89
- };
90
- if (isAdded('open')) {
91
- self.isFlyoutOpened = true;
92
- self.visible = true;
93
- } else if (isAdded('closing') || isAdded('tweening-out')) {
94
- self.isFlyoutOpened = false;
95
- } else if (isRemoved('open')) {
96
- self.visible = false;
97
- }
98
- }
99
- });
1
+ import { defineAliasProperty, definePrototype, each, extend, makeArray } from "../include/zeta-dom/util.js";
2
+ import { app } from "../app.js";
3
+ import ClassNameMixin from "./ClassNameMixin.js";
4
+
5
+ const FlyoutMixinSuper = ClassNameMixin.prototype;
6
+ var flyoutMixinCounter = 0;
7
+
8
+ function FlyoutToggleMixin(mixin) {
9
+ ClassNameMixin.call(this, ['target-opened']);
10
+ this.flyoutMixin = mixin;
11
+ }
12
+
13
+ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
14
+ getCustomAttributes: function () {
15
+ var element = this.flyoutMixin.elements()[0];
16
+ return extend({}, FlyoutMixinSuper.getCustomAttributes.call(this), {
17
+ 'toggle': element && ('#' + element.id)
18
+ });
19
+ },
20
+ clone: function () {
21
+ return extend(FlyoutMixinSuper.clone.call(this), { flyoutMixin: this.flyoutMixin });
22
+ }
23
+ });
24
+
25
+ export default function FlyoutMixin() {
26
+ var self = this;
27
+ ClassNameMixin.call(self, ['open', 'closing', 'tweening-in', 'tweening-out']);
28
+ self.modal = false;
29
+ self.isFlyoutOpened = false;
30
+ self.animating = false;
31
+ self.visible = false;
32
+ self.toggle = new FlyoutToggleMixin(self);
33
+ }
34
+
35
+ definePrototype(FlyoutMixin, ClassNameMixin, {
36
+ reset: function () {
37
+ this.toggle.reset();
38
+ return FlyoutMixinSuper.reset.call(this);
39
+ },
40
+ next: function () {
41
+ this.effects = undefined;
42
+ return FlyoutMixinSuper.next.call(this);
43
+ },
44
+ withEffects: function () {
45
+ this.effects = makeArray(arguments);
46
+ return this;
47
+ },
48
+ getCustomAttributes: function () {
49
+ var self = this;
50
+ return extend({}, FlyoutMixinSuper.getCustomAttributes.call(self), {
51
+ 'is-flyout': ''
52
+ }, self.modal && {
53
+ 'is-modal': ''
54
+ }, self.effects && {
55
+ 'animate-on': 'open',
56
+ 'animate-in': self.effects.join(' '),
57
+ 'animate-out': ''
58
+ });
59
+ },
60
+ onOpen: function (callback) {
61
+ return this.onToggleState(function (opened) {
62
+ if (opened) {
63
+ return callback();
64
+ }
65
+ });
66
+ },
67
+ onToggleState: function (callback) {
68
+ return this.watch('isFlyoutOpened', callback);
69
+ },
70
+ onVisibilityChanged: function (callback) {
71
+ return this.watch('visible', callback);
72
+ },
73
+ initElement: function (element, state) {
74
+ var self = this;
75
+ FlyoutMixinSuper.initElement.call(self, element, state);
76
+ if (!element.id) {
77
+ element.id = 'flyout-' + (++flyoutMixinCounter);
78
+ }
79
+ app.on(element, {
80
+ animationstart: function () {
81
+ self.animating = true;
82
+ },
83
+ animationcomplete: function () {
84
+ self.animating = false;
85
+ },
86
+ }, true);
87
+ setImmediate(function () {
88
+ each(self.toggle.elements(), function (i, v) {
89
+ v.setAttribute('toggle', '#' + element.id);
90
+ });
91
+ });
92
+ },
93
+ clone: function () {
94
+ var self = this;
95
+ var mixin = extend(FlyoutMixinSuper.clone.call(self), {
96
+ toggle: self.toggle.ref.getMixin()
97
+ });
98
+ defineAliasProperty(mixin, 'isFlyoutOpened', self);
99
+ defineAliasProperty(mixin, 'modal', self);
100
+ return mixin;
101
+ },
102
+ onClassNameUpdated: function (element, prevState, state) {
103
+ var self = this;
104
+ var isAdded = function (v) {
105
+ return prevState[v] !== state[v] && state[v];
106
+ };
107
+ var isRemoved = function (v) {
108
+ return prevState[v] !== state[v] && !state[v];
109
+ };
110
+ if (isAdded('open')) {
111
+ self.isFlyoutOpened = true;
112
+ self.visible = true;
113
+ } else if (isAdded('closing') || isAdded('tweening-out')) {
114
+ self.isFlyoutOpened = false;
115
+ } else if (isRemoved('open')) {
116
+ self.visible = false;
117
+ }
118
+ }
119
+ });
package/mixins/Mixin.d.ts CHANGED
@@ -10,9 +10,9 @@ interface MixinProps {
10
10
  export default abstract class Mixin implements ClassNameProvider {
11
11
  static readonly scrollableTarget: StaticAttributeMixin;
12
12
 
13
- static readonly use(ref: React.ForwardedRef<any>, ...args: (Mixin | string)[]): MixinProps;
14
- static readonly use(ref: Mixin, ...args: (Mixin | string)[]): MixinProps;
15
- static readonly use(...args: Mixin[]): MixinProps;
13
+ static readonly use(ref: React.ForwardedRef<any>, ...args: (Mixin | string | undefined)[]): MixinProps;
14
+ static readonly use(ref: Mixin, ...args: (Mixin | string | undefined)[]): MixinProps;
15
+ static readonly use(...args: (Mixin | undefined)[]): MixinProps;
16
16
 
17
17
  /**
18
18
  * @private Internal use.
@@ -6,9 +6,10 @@ import ClassNameMixin from "./ClassNameMixin.js";
6
6
  const ScrollableMixinSuper = ClassNameMixin.prototype;
7
7
 
8
8
  export default function ScrollableMixin() {
9
- ClassNameMixin.call(this, ['scrollable-x', 'scrollable-x-l', 'scrollable-x-r', 'scrollable-y', 'scrollable-y-d', 'scrollable-y-u']);
10
- this.target = Mixin.scrollableTarget;
11
- this.pageIndex = 0;
9
+ var self = this;
10
+ ClassNameMixin.call(self, ['scrollable-x', 'scrollable-x-l', 'scrollable-x-r', 'scrollable-y', 'scrollable-y-d', 'scrollable-y-u']);
11
+ self.target = Mixin.scrollableTarget;
12
+ self.pageIndex = 0;
12
13
  }
13
14
 
14
15
  definePrototype(ScrollableMixin, ClassNameMixin, {
@@ -24,9 +24,10 @@ export default function StatefulMixin() {
24
24
 
25
25
  definePrototype(StatefulMixin, Mixin, {
26
26
  get ref() {
27
- const state = this.state;
28
- this.next();
29
- return state.ref || (state.ref = new MixinRefImpl(this.clone()));
27
+ const self = this;
28
+ const state = self.state;
29
+ self.next();
30
+ return state.ref || (state.ref = new MixinRefImpl(self.clone()));
30
31
  },
31
32
  get state() {
32
33
  const obj = _(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brew-js-react",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",