brew-js-react 0.2.10 → 0.3.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/mixin.js CHANGED
@@ -5,7 +5,6 @@ import AnimateMixin from "./mixins/AnimateMixin.js";
5
5
  import AnimateSequenceItemMixin from "./mixins/AnimateSequenceItemMixin.js";
6
6
  import AnimateSequenceMixin from "./mixins/AnimateSequenceMixin.js";
7
7
  import ClassNameMixin from "./mixins/ClassNameMixin.js";
8
- import ErrorHandlerMixin from "./mixins/ErrorHandlerMixin.js";
9
8
  import FlyoutMixin from "./mixins/FlyoutMixin.js";
10
9
  import FlyoutToggleMixin from "./mixins/FlyoutToggleMixin.js";
11
10
  import FocusStateMixin from "./mixins/FocusStateMixin.js";
@@ -27,7 +26,6 @@ function createUseFunction(ctor) {
27
26
 
28
27
  export const useAnimateMixin = createUseFunction(AnimateMixin);
29
28
  export const useAnimateSequenceMixin = createUseFunction(AnimateSequenceMixin);
30
- export const useErrorHandlerMixin = createUseFunction(ErrorHandlerMixin);
31
29
  export const useFlyoutMixin = createUseFunction(FlyoutMixin);
32
30
  export const useFocusStateMixin = createUseFunction(FocusStateMixin);
33
31
  export const useLoadingStateMixin = createUseFunction(LoadingStateMixin);
@@ -53,7 +51,6 @@ export {
53
51
  AnimateSequenceItemMixin,
54
52
  AnimateSequenceMixin,
55
53
  ClassNameMixin,
56
- ErrorHandlerMixin,
57
54
  FlyoutMixin,
58
55
  FlyoutToggleMixin,
59
56
  FocusStateMixin,
@@ -1,57 +1,56 @@
1
- import { definePrototype, each, equal, extend, setImmediate } from "../include/zeta-dom/util.js";
2
- import { containsOrEquals } from "../include/zeta-dom/domUtil.js";
3
- import dom from "../include/zeta-dom/dom.js";
4
- import StatefulMixin from "./StatefulMixin.js";
5
-
6
- const ClassNameMixinSuper = StatefulMixin.prototype;
7
-
8
- function checkState(self, element, state, isAsync) {
9
- var classNames = state.classNames;
10
- var prev = extend({}, classNames);
11
- each(self.classNames, function (i, v) {
12
- classNames[v] = element.classList.contains(v);
13
- });
14
- if (!equal(prev, classNames)) {
15
- var cb = self.onClassNameUpdated.bind(self, element, prev, extend({}, classNames));
16
- if (isAsync) {
17
- setImmediate(cb);
18
- } else {
19
- cb();
20
- }
21
- }
22
- }
23
-
24
- export default function ClassNameMixin(classNames) {
25
- StatefulMixin.call(this);
26
- this.classNames = classNames || [];
27
- }
28
-
29
- definePrototype(ClassNameMixin, StatefulMixin, {
30
- getClassNames: function () {
31
- return [this.state.classNames];
32
- },
33
- getRef: function () {
34
- var self = this;
35
- var element = self.state.element;
36
- if (element && containsOrEquals(dom.root, element)) {
37
- checkState(self, element, self.state, true);
38
- }
39
- return ClassNameMixinSuper.getRef.call(this);
40
- },
41
- initState: function () {
42
- return {
43
- element: null,
44
- classNames: {}
45
- };
46
- },
47
- initElement: function (element, state) {
48
- var self = this;
49
- dom.watchAttributes(element, ['class'], function (nodes) {
50
- if (nodes.includes(element)) {
51
- checkState(self, element, state);
52
- }
53
- });
54
- },
55
- onClassNameUpdated: function (element, prevState, state) {
56
- }
57
- });
1
+ import { definePrototype, each, equal, extend, setImmediate } from "../include/zeta-dom/util.js";
2
+ import { containsOrEquals } from "../include/zeta-dom/domUtil.js";
3
+ import dom from "../include/zeta-dom/dom.js";
4
+ import { watchOwnAttributes } from "../include/zeta-dom/observe.js";
5
+ import StatefulMixin from "./StatefulMixin.js";
6
+
7
+ const ClassNameMixinSuper = StatefulMixin.prototype;
8
+
9
+ function checkState(self, element, state, isAsync) {
10
+ var classNames = state.classNames;
11
+ var prev = extend({}, classNames);
12
+ each(self.classNames, function (i, v) {
13
+ classNames[v] = element.classList.contains(v);
14
+ });
15
+ if (!equal(prev, classNames)) {
16
+ var cb = self.onClassNameUpdated.bind(self, element, prev, extend({}, classNames));
17
+ if (isAsync) {
18
+ setImmediate(cb);
19
+ } else {
20
+ cb();
21
+ }
22
+ }
23
+ }
24
+
25
+ export default function ClassNameMixin(classNames) {
26
+ StatefulMixin.call(this);
27
+ this.classNames = classNames || [];
28
+ }
29
+
30
+ definePrototype(ClassNameMixin, StatefulMixin, {
31
+ getClassNames: function () {
32
+ return [this.state.classNames];
33
+ },
34
+ getRef: function () {
35
+ var self = this;
36
+ var element = self.state.element;
37
+ if (element && containsOrEquals(dom.root, element)) {
38
+ checkState(self, element, self.state, true);
39
+ }
40
+ return ClassNameMixinSuper.getRef.call(this);
41
+ },
42
+ initState: function () {
43
+ return {
44
+ element: null,
45
+ classNames: {}
46
+ };
47
+ },
48
+ initElement: function (element, state) {
49
+ var self = this;
50
+ watchOwnAttributes(element, 'class', function () {
51
+ checkState(self, element, state);
52
+ });
53
+ },
54
+ onClassNameUpdated: function (element, prevState, state) {
55
+ }
56
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brew-js-react",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "brew-js": ">=0.4.5",
22
22
  "waterpipe": "^2.5.0",
23
- "zeta-dom": ">=0.2.11",
23
+ "zeta-dom": ">=0.3.1",
24
24
  "zeta-dom-react": ">=0.2.1"
25
25
  },
26
26
  "peerDependencies": {
@@ -1,37 +0,0 @@
1
- import dom from "../include/zeta-dom/dom";
2
- import StatefulMixin from "./StatefulMixin";
3
-
4
- /**
5
- * @deprecated
6
- */
7
- export default class ErrorHandlerMixin extends StatefulMixin {
8
- /**
9
- * Catches errors from promises registered to descandant elements by {@link dom.lock}.
10
- * Unfiltered handlers are called after filtered handlers, registered by other overloads, regardless of order.
11
- *
12
- * If handler returns a value other than `undefined`, including promises resolving to whatever values,
13
- * the error is marked as handled and no further handlers are called nor will be propagated up the DOM tree.
14
- * @param handler Callback to be invoked.
15
- */
16
- catch(handler: (e: any) => any): Zeta.UnregisterCallback;
17
-
18
- /**
19
- * Catches errors with property `code` matching the specified code, from promises registered to descandant elements by {@link dom.lock}.
20
- *
21
- * If handler returns a value other than `undefined`, including promises resolving to whatever values,
22
- * the error is marked as handled and no further handlers are called nor will be propagated up the DOM tree.
23
- * @param code Value to be matched against.
24
- * @param handler Callback to be invoked when the criteria matches.
25
- */
26
- catch(code: string, handler: (e: Error) => any): Zeta.UnregisterCallback;
27
-
28
- /**
29
- * Catches errors that are instances of the specified error type, from promises registered to descandant elements by {@link dom.lock}.
30
- *
31
- * If handler returns a value other than `undefined`, including promises resolving to whatever values,
32
- * the error is marked as handled and no further handlers are called nor will be propagated up the DOM tree.
33
- * @param type Constructor of a specific error type.
34
- * @param handler Callback to be invoked when the criteria matches.
35
- */
36
- catch<T extends Error>(type: typeof T, handler: (e: T) => any): Zeta.UnregisterCallback;
37
- }
@@ -1,40 +0,0 @@
1
- import dom from "../include/zeta-dom/dom.js";
2
- import { ZetaEventContainer } from "../include/zeta-dom/events.js";
3
- import { definePrototype, is, isFunction } from "../include/zeta-dom/util.js";
4
- import StatefulMixin from "./StatefulMixin.js";
5
-
6
- const ErrorHandlerMixinSuper = StatefulMixin.prototype;
7
- const emitter = new ZetaEventContainer();
8
-
9
- function isErrorMatched(filter, error) {
10
- if (isFunction(filter)) {
11
- return is(error, filter);
12
- }
13
- return error && error.code === filter;
14
- }
15
-
16
- export default function ErrorHandlerMixin() {
17
- StatefulMixin.call(this);
18
- }
19
-
20
- definePrototype(ErrorHandlerMixin, StatefulMixin, {
21
- catch: function (filter, callback) {
22
- if (!callback) {
23
- callback = filter;
24
- filter = null;
25
- }
26
- return emitter.add(this, filter ? 'error' : 'default', function (e) {
27
- if (!filter || isErrorMatched(filter, e.error)) {
28
- return callback(e.error);
29
- }
30
- });
31
- },
32
- initElement: function (element, state) {
33
- var self = this;
34
- ErrorHandlerMixinSuper.initElement.call(self, element, state);
35
- dom.on(element, 'error', function (e) {
36
- var data = { error: e.error };
37
- return emitter.emit('error', self, data) || emitter.emit('default', self, data);
38
- });
39
- }
40
- });