brew-js-react 0.4.3 → 0.4.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- export type DialogCloseCallback<T> = (value?: T) => void;
1
+ export type DialogCloseCallback<T> = (value?: T) => Promise<void>;
2
2
 
3
3
  export interface DialogState<T> {
4
4
  readonly root: HTMLElement;
package/dialog.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { createElement, useEffect, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import ReactDOMClient from "./include/external/react-dom-client.js";
4
- import { always, catchAsync, either, extend, makeAsync, noop, pipe } from "./include/zeta-dom/util.js";
5
- import { containsOrEquals, removeNode } from "./include/zeta-dom/domUtil.js";
4
+ import { always, either, extend, makeAsync, noop, pipe, setImmediate } from "./include/zeta-dom/util.js";
5
+ import { containsOrEquals, removeNode, setClass } from "./include/zeta-dom/domUtil.js";
6
6
  import dom from "./include/zeta-dom/dom.js";
7
- import { lock, preventLeave } from "./include/zeta-dom/domLock.js";
7
+ import { lock, notifyAsync, preventLeave, subscribeAsync } from "./include/zeta-dom/domLock.js";
8
8
  import { closeFlyout, openFlyout } from "./include/brew-js/domAction.js";
9
9
 
10
10
  /**
@@ -16,13 +16,22 @@ export function createDialog(props) {
16
16
  var closeDialog = closeFlyout.bind(0, root);
17
17
  var promise;
18
18
 
19
- dom.on(root, 'flyouthide', function () {
20
- removeNode(root);
21
- (props.onClose || noop)(root);
22
- if (props.onRender) {
23
- reactRoot.unmount();
19
+ dom.on(root, {
20
+ flyouthide: function () {
21
+ removeNode(root);
22
+ (props.onClose || noop)(root);
23
+ if (props.onRender) {
24
+ reactRoot.unmount();
25
+ }
26
+ },
27
+ asyncStart: function () {
28
+ setClass(root, 'loading', true);
29
+ },
30
+ asyncEnd: function () {
31
+ setClass(root, 'loading', false);
24
32
  }
25
33
  });
34
+ subscribeAsync(root);
26
35
 
27
36
  return {
28
37
  root: root,
@@ -42,8 +51,8 @@ export function createDialog(props) {
42
51
  var dialogProps = extend({}, props, {
43
52
  closeDialog: function (value) {
44
53
  var promise = makeAsync(props.onCommit || pipe)(value);
45
- catchAsync(lock(dom.activeElement, promise));
46
- promise.then(closeDialog, noop);
54
+ notifyAsync(dom.activeElement, promise);
55
+ return promise.then(closeDialog);
47
56
  }
48
57
  });
49
58
  var content = createElement(props.onRender, dialogProps);
@@ -51,6 +60,9 @@ export function createDialog(props) {
51
60
  content = createElement(props.wrapper, dialogProps, content);
52
61
  }
53
62
  reactRoot.render(content);
63
+ setImmediate(function () {
64
+ dom.focus(root);
65
+ });
54
66
  }
55
67
  promise = openFlyout(root);
56
68
  if (props.preventLeave) {
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.4.3 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
1
+ /*! brew-js-react v0.4.5 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("brew-js"), require("react"), require("react-dom"), (function webpackLoadOptionalExternalModule() { try { return require("react-dom/client"); } catch(e) {} }()), require("zeta-dom"), require("zeta-dom-react"), require("waterpipe"), require("jQuery"));
@@ -397,12 +397,14 @@ var _lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_z
397
397
  setShortcut = _lib$dom.setShortcut,
398
398
  focusable = _lib$dom.focusable,
399
399
  focused = _lib$dom.focused,
400
+ setTabRoot = _lib$dom.setTabRoot,
400
401
  setModal = _lib$dom.setModal,
401
402
  releaseModal = _lib$dom.releaseModal,
402
403
  retainFocus = _lib$dom.retainFocus,
403
404
  releaseFocus = _lib$dom.releaseFocus,
404
405
  iterateFocusPath = _lib$dom.iterateFocusPath,
405
- dom_focus = _lib$dom.focus;
406
+ dom_focus = _lib$dom.focus,
407
+ dom_blur = _lib$dom.blur;
406
408
 
407
409
  ;// CONCATENATED MODULE: ./src/include/zeta-dom/dom.js
408
410
 
@@ -444,14 +446,23 @@ function createDialog(props) {
444
446
  var _closeDialog = closeFlyout.bind(0, root);
445
447
 
446
448
  var promise;
447
- zeta_dom_dom.on(root, 'flyouthide', function () {
448
- removeNode(root);
449
- (props.onClose || noop)(root);
449
+ zeta_dom_dom.on(root, {
450
+ flyouthide: function flyouthide() {
451
+ removeNode(root);
452
+ (props.onClose || noop)(root);
450
453
 
451
- if (props.onRender) {
452
- reactRoot.unmount();
454
+ if (props.onRender) {
455
+ reactRoot.unmount();
456
+ }
457
+ },
458
+ asyncStart: function asyncStart() {
459
+ setClass(root, 'loading', true);
460
+ },
461
+ asyncEnd: function asyncEnd() {
462
+ setClass(root, 'loading', false);
453
463
  }
454
464
  });
465
+ subscribeAsync(root);
455
466
  return {
456
467
  root: root,
457
468
  close: _closeDialog,
@@ -473,8 +484,8 @@ function createDialog(props) {
473
484
  var dialogProps = extend({}, props, {
474
485
  closeDialog: function closeDialog(value) {
475
486
  var promise = makeAsync(props.onCommit || pipe)(value);
476
- catchAsync(lock(zeta_dom_dom.activeElement, promise));
477
- promise.then(_closeDialog, noop);
487
+ notifyAsync(zeta_dom_dom.activeElement, promise);
488
+ return promise.then(_closeDialog);
478
489
  }
479
490
  });
480
491
  var content = /*#__PURE__*/(0,external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement)(props.onRender, dialogProps);
@@ -484,6 +495,9 @@ function createDialog(props) {
484
495
  }
485
496
 
486
497
  reactRoot.render(content);
498
+ setImmediate(function () {
499
+ zeta_dom_dom.focus(root);
500
+ });
487
501
  }
488
502
 
489
503
  promise = openFlyout(root);
@@ -1323,7 +1337,7 @@ function StatefulMixin() {
1323
1337
  Mixin.call(this);
1324
1338
 
1325
1339
  StatefulMixin_(this, {
1326
- elements: new Set(),
1340
+ elements: new WeakSet(),
1327
1341
  flush: watch(this, false),
1328
1342
  dispose: [],
1329
1343
  states: {},
@@ -1398,7 +1412,7 @@ definePrototype(StatefulMixin, Mixin, {
1398
1412
  var states = state.states;
1399
1413
  combineFn(state.dispose.splice(0))();
1400
1414
  state.flush();
1401
- state.elements.clear();
1415
+ state.elements = new WeakSet();
1402
1416
  each(states, function (i, v) {
1403
1417
  delete states[i];
1404
1418
  });
@@ -1538,6 +1552,8 @@ definePrototype(AnimateSequenceMixin, AnimateMixin, {
1538
1552
  ;// CONCATENATED MODULE: ./src/mixins/FlyoutToggleMixin.js
1539
1553
 
1540
1554
 
1555
+
1556
+
1541
1557
  var FlyoutToggleMixinSuper = ClassNameMixin.prototype;
1542
1558
  function FlyoutToggleMixin(mixin) {
1543
1559
  ClassNameMixin.call(this, ['target-opened']);
@@ -1550,11 +1566,12 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1550
1566
  close: function close(value) {
1551
1567
  return this.flyoutMixin.close(value);
1552
1568
  },
1553
- getCustomAttributes: function getCustomAttributes() {
1554
- var element = this.flyoutMixin.elements()[0];
1555
- return extend({}, FlyoutToggleMixinSuper.getCustomAttributes.call(this), {
1556
- 'toggle': element && '#' + element.id
1557
- });
1569
+ initElement: function initElement(element, state) {
1570
+ var self = this;
1571
+ FlyoutToggleMixinSuper.initElement.call(self, element, state);
1572
+ self.onDispose(zeta_dom_dom.on(element, 'click', function () {
1573
+ openFlyout(self.flyoutMixin.elements()[0], null, element, true);
1574
+ }));
1558
1575
  }
1559
1576
  });
1560
1577
  ;// CONCATENATED MODULE: ./src/mixins/FlyoutMixin.js
@@ -1565,7 +1582,6 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1565
1582
 
1566
1583
  var FlyoutMixinSuper = ClassNameMixin.prototype;
1567
1584
  var valueMap = new WeakMap();
1568
- var flyoutMixinCounter = 0;
1569
1585
  function FlyoutMixin() {
1570
1586
  var self = this;
1571
1587
  ClassNameMixin.call(self, ['open', 'closing', 'visible', 'tweening-in', 'tweening-out']);
@@ -1633,11 +1649,6 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1633
1649
  initElement: function initElement(element, state) {
1634
1650
  var self = this;
1635
1651
  FlyoutMixinSuper.initElement.call(self, element, state);
1636
-
1637
- if (!element.id) {
1638
- element.id = 'flyout-' + ++flyoutMixinCounter;
1639
- }
1640
-
1641
1652
  self.onDispose(app_app.on(element, {
1642
1653
  animationstart: function animationstart() {
1643
1654
  self.animating = true;
@@ -1646,11 +1657,6 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1646
1657
  self.animating = false;
1647
1658
  }
1648
1659
  }, true));
1649
- setImmediate(function () {
1650
- each(self.toggle.elements(), function (i, v) {
1651
- v.setAttribute('toggle', '#' + element.id);
1652
- });
1653
- });
1654
1660
  },
1655
1661
  clone: function clone() {
1656
1662
  var self = this;
@@ -1677,23 +1683,47 @@ function FocusStateMixin() {
1677
1683
  StatefulMixin.call(this);
1678
1684
  }
1679
1685
  definePrototype(FocusStateMixin, StatefulMixin, {
1686
+ "for": function _for(ref) {
1687
+ this.state.ref = ref;
1688
+ return this;
1689
+ },
1680
1690
  initElement: function initElement(element, state) {
1681
1691
  FocusStateMixinSuper.initElement.call(this, element, state);
1692
+
1693
+ var checkTarget = function checkTarget(callback, arg) {
1694
+ var ref = state.ref;
1695
+ var target = ref && (typeof ref === 'string' ? element.querySelector(ref) : ref.current);
1696
+
1697
+ if (target && !zeta_dom_dom.focused(target)) {
1698
+ callback(arg || target);
1699
+ }
1700
+ };
1701
+
1682
1702
  this.onDispose(zeta_dom_dom.on(element, {
1683
1703
  focusin: function focusin(e) {
1684
- state.focused = true;
1704
+ state.focused = e.source;
1685
1705
  setClass(element, 'focused', e.source);
1706
+ checkTarget(zeta_dom_dom.focus);
1686
1707
  },
1687
1708
  focusout: function focusout() {
1688
1709
  state.focused = false;
1689
1710
  setClass(element, 'focused', false);
1711
+ },
1712
+ focuschange: function focuschange() {
1713
+ checkTarget(zeta_dom_dom.blur, element);
1690
1714
  }
1691
1715
  }));
1692
1716
  },
1693
1717
  getClassNames: function getClassNames() {
1694
- return [{
1695
- focused: !!this.state.focused
1696
- }];
1718
+ var classes = {};
1719
+ var focused = this.state.focused;
1720
+
1721
+ if (focused) {
1722
+ classes.focused = true;
1723
+ classes['focused-' + focused] = true;
1724
+ }
1725
+
1726
+ return [classes];
1697
1727
  }
1698
1728
  });
1699
1729
  ;// CONCATENATED MODULE: ./src/mixins/LoadingStateMixin.js
@@ -1709,20 +1739,9 @@ function LoadingStateMixin() {
1709
1739
  definePrototype(LoadingStateMixin, StatefulMixin, {
1710
1740
  initElement: function initElement(element, state) {
1711
1741
  LoadingStateMixinSuper.initElement.call(this, element, state);
1712
- lock(element);
1713
- this.onDispose(zeta_dom_dom.on(element, {
1714
- asyncStart: function asyncStart() {
1715
- state.loading = true;
1716
- setClass(element, 'loading', true);
1717
- },
1718
- asyncEnd: function asyncEnd() {
1719
- state.loading = false;
1720
- setClass(element, 'loading', false);
1721
- },
1722
- cancelled: function cancelled() {
1723
- state.loading = false;
1724
- setClass(element, 'loading', false);
1725
- }
1742
+ this.onDispose(subscribeAsync(element, function (loading) {
1743
+ state.loading = loading;
1744
+ setClass(element, 'loading', loading);
1726
1745
  }));
1727
1746
  },
1728
1747
  getClassNames: function getClassNames() {
@@ -1760,11 +1779,9 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
1760
1779
  var options = this.options || {};
1761
1780
  return extend({}, ScrollableMixinSuper.getCustomAttributes.call(this), {
1762
1781
  'scrollable': [options.direction || 'both', options.handle || 'auto'].join(' ')
1763
- }, options.paged && {
1764
- 'var': '{ pageIndex: 0 }',
1782
+ }, options.pagedItemSelector && {
1765
1783
  'scroller-snap-page': options.paged,
1766
- 'scroller-page': options.pagedItemSelector,
1767
- 'scroller-state': 'pageIndex'
1784
+ 'scroller-page': options.pagedItemSelector
1768
1785
  }, options.persistScroll && {
1769
1786
  'persist-scroll': ''
1770
1787
  });
@@ -1775,12 +1792,8 @@ definePrototype(ScrollableMixin, ClassNameMixin, {
1775
1792
  initElement: function initElement(element, state) {
1776
1793
  var self = this;
1777
1794
  self.onDispose(app_app.on(element, {
1778
- statechange: function statechange(e) {
1779
- if ('pageIndex' in e.newValues) {
1780
- extend(self, {
1781
- pageIndex: e.newValues.pageIndex
1782
- });
1783
- }
1795
+ scrollIndexChange: function scrollIndexChange(e) {
1796
+ self.pageIndex = e.newIndex;
1784
1797
  },
1785
1798
  scrollStart: function scrollStart() {
1786
1799
  self.scrolling = true;