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.
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.6.6 | (c) misonou | https://misonou.github.io */
1
+ /*! brew-js-react v0.7.0 | (c) misonou | https://misonou.github.io */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("zeta-dom"), require("brew-js"), require("react"), require("react-dom"), require("zeta-dom-react"), require("waterpipe"), require("jquery"));
@@ -180,16 +180,19 @@ __webpack_require__.d(__webpack_exports__, {
180
180
  ScrollIntoViewMixin: () => (/* reexport */ ScrollIntoViewMixin),
181
181
  ScrollableMixin: () => (/* reexport */ ScrollableMixin),
182
182
  StatefulMixin: () => (/* reexport */ StatefulMixin),
183
+ StaticAttributeMixin: () => (/* reexport */ StaticAttributeMixin),
183
184
  UnmanagedClassNameMixin: () => (/* reexport */ UnmanagedClassNameMixin),
184
185
  ViewContext: () => (/* reexport */ ViewContext),
185
186
  ViewStateContainer: () => (/* reexport */ ViewStateContainer),
186
187
  createDialog: () => (/* reexport */ createDialog),
188
+ createDialogQueue: () => (/* reexport */ createDialogQueue),
187
189
  isViewMatched: () => (/* reexport */ isViewMatched),
188
190
  isViewRendered: () => (/* reexport */ isViewRendered),
189
191
  linkTo: () => (/* reexport */ linkTo),
190
192
  makeTranslation: () => (/* reexport */ makeTranslation),
191
193
  matchView: () => (/* reexport */ matchView),
192
194
  navigateTo: () => (/* reexport */ navigateTo),
195
+ openDialog: () => (/* reexport */ openDialog),
193
196
  redirectTo: () => (/* reexport */ redirectTo),
194
197
  registerErrorView: () => (/* reexport */ registerErrorView),
195
198
  registerView: () => (/* reexport */ registerView),
@@ -349,8 +352,6 @@ var reportError = dom.reportError;
349
352
  ;// CONCATENATED MODULE: ./|umd|/zeta-dom/domLock.js
350
353
 
351
354
  var _lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.dom,
352
- lock = _lib$dom.lock,
353
- preventLeave = _lib$dom.preventLeave,
354
355
  runAsync = _lib$dom.runAsync,
355
356
  subscribeAsync = _lib$dom.subscribeAsync;
356
357
 
@@ -371,96 +372,189 @@ var closeFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_b
371
372
 
372
373
 
373
374
 
374
-
375
- /**
376
- * @param {Partial<import("./dialog").DialogOptions<any>>} props
377
- */
378
- function createDialog(props) {
379
- var root = document.createElement('div');
380
- var reactRoot = fallback.createRoot(root);
381
- var scope = createAsyncScope(root);
382
- var closeDialog = closeFlyout.bind(0, root);
375
+ var _ = createPrivateStore();
376
+ function debounceAsync(callback) {
383
377
  var promise;
378
+ return function () {
379
+ if (!promise) {
380
+ promise = callback.apply(this, arguments);
381
+ always(promise, function () {
382
+ promise = null;
383
+ });
384
+ }
385
+ return promise;
386
+ };
387
+ }
388
+ function createDialogElement(props, unmountAfterUse) {
389
+ var root = document.createElement('div');
384
390
  zeta_dom_dom.on(root, {
385
391
  flyoutshow: function flyoutshow() {
386
392
  (props.onOpen || noop)(root);
387
393
  },
388
394
  flyouthide: function flyouthide() {
389
- promise = null;
390
395
  removeNode(root);
391
396
  (props.onClose || noop)(root);
392
- if (props.onRender) {
393
- reactRoot.unmount();
394
- }
397
+ (unmountAfterUse || noop)();
395
398
  }
396
399
  });
397
400
  root.setAttribute('loading-class', '');
398
401
  subscribeAsync(root, true);
402
+ return root;
403
+ }
404
+ function showDialog(element, props, container) {
405
+ if (!containsOrEquals(zeta_dom_dom.root, element)) {
406
+ element.className = props.className || '';
407
+ if (props.modal) {
408
+ element.setAttribute('is-modal', '');
409
+ }
410
+ (container || props.container || document.body).appendChild(element);
411
+ }
412
+ return openFlyout(element, null, pick(props, ['focus', 'closeOnBlur', 'preventLeave', 'preventNavigation']));
413
+ }
414
+ function openDialog(props) {
415
+ return createDialog(props).open();
416
+ }
417
+
418
+ /**
419
+ * @param {Partial<import("./dialog").DialogOptions<any>>} props
420
+ */
421
+ function createDialog(props) {
422
+ var controller = _(props.controller) || {};
423
+ var shared = controller.mode === 'shared';
424
+ var state = shared ? controller : {};
425
+ var root = state.root || (state.root = createDialogElement(props, function () {
426
+ reactRoot.unmount();
427
+ }));
428
+ var reactRoot = state.reactRoot || (state.reactRoot = fallback.createRoot(root));
429
+ var scope = state.scope || (state.scope = createAsyncScope(root));
430
+ var closeDialog = shared ? noop : closeFlyout.bind(0, root);
431
+ function render(closeDialog, props, container) {
432
+ var commitDialog = props.onCommit ? function (value) {
433
+ return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
434
+ } : closeDialog;
435
+ var dialogProps = extend({}, props, {
436
+ errorHandler: scope.errorHandler,
437
+ closeDialog: commitDialog,
438
+ commitDialog: commitDialog,
439
+ dismissDialog: closeDialog
440
+ });
441
+ var content = /*#__PURE__*/createElement(props.onRender, dialogProps);
442
+ if (props.wrapper) {
443
+ content = /*#__PURE__*/createElement(props.wrapper, dialogProps, content);
444
+ }
445
+ reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, /*#__PURE__*/createElement(scope.Provider, null, content)));
446
+ return shared ? {
447
+ then: noop
448
+ } : showDialog(root, props, container);
449
+ }
399
450
  return {
400
451
  root: root,
401
- close: closeDialog,
402
- open: function open() {
403
- if (promise) {
404
- return promise;
405
- }
406
- root.className = props.className || '';
407
- document.body.appendChild(root);
408
- if (props.modal) {
409
- root.setAttribute('is-modal', '');
410
- }
411
- if (props.onRender) {
412
- var commitDialog = props.onCommit ? function (value) {
413
- return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
414
- } : closeDialog;
415
- var dialogProps = extend({}, props, {
416
- errorHandler: scope.errorHandler,
417
- closeDialog: commitDialog,
418
- commitDialog: commitDialog,
419
- dismissDialog: closeDialog
452
+ close: function close(value) {
453
+ return closeDialog(value);
454
+ },
455
+ open: debounceAsync(function () {
456
+ if (controller.enqueue) {
457
+ return controller.enqueue(function (next) {
458
+ closeDialog = shared ? next : closeDialog;
459
+ render(closeDialog, extend({}, controller.props, props), controller.root).then(next);
420
460
  });
421
- var content = /*#__PURE__*/createElement(props.onRender, dialogProps);
422
- if (props.wrapper) {
423
- content = /*#__PURE__*/createElement(props.wrapper, dialogProps, content);
461
+ }
462
+ return render(closeDialog, props);
463
+ })
464
+ };
465
+ }
466
+
467
+ /**
468
+ * @param {import("./dialog").DialogControllerOptions | undefined} props
469
+ */
470
+ function createDialogQueue(props) {
471
+ var mode = props && props.mode;
472
+ var root = mode && createDialogElement(props);
473
+ var multiple = mode === 'multiple';
474
+ var childProps;
475
+ var queue = [];
476
+ var active = [];
477
+ var controller = {};
478
+ var setPendingCount = defineObservableProperty(controller, 'pendingCount', 0, true);
479
+ function dismissPending() {
480
+ combineFn(queue.splice(0))();
481
+ setPendingCount(0);
482
+ }
483
+ function dismissAll(value) {
484
+ combineFn(active.splice(0))(multiple ? undefined : value);
485
+ dismissPending();
486
+ }
487
+ function render(callback) {
488
+ return new Promise(function (resolvePromise) {
489
+ var next = function next(value) {
490
+ if (arrRemove(active, resolvePromise)) {
491
+ resolvePromise(value);
492
+ setImmediate(function () {
493
+ (queue.shift() || noop)(true);
494
+ });
424
495
  }
425
- reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, /*#__PURE__*/createElement(scope.Provider, null, content)));
496
+ return root && !queue[0] && !active[0] ? closeFlyout(root) : resolve();
497
+ };
498
+ active.push(resolvePromise);
499
+ setPendingCount(queue.length);
500
+ callback(next);
501
+ });
502
+ }
503
+ if (multiple) {
504
+ childProps = {
505
+ closeOnBlur: false
506
+ };
507
+ props = extend({}, props, childProps);
508
+ } else {
509
+ childProps = props && exclude(props, ['onCommit', 'onRender', 'onOpen', 'onClose']);
510
+ }
511
+ _(controller, {
512
+ root: root,
513
+ mode: mode,
514
+ props: childProps,
515
+ enqueue: function enqueue(callback) {
516
+ if (root && !isFlyoutOpen(root)) {
517
+ showDialog(root, props).then(dismissAll);
426
518
  }
427
- promise = resolve().then(function () {
428
- zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, root);
429
- return openFlyout(root, null, pick(props, ['focus']));
430
- });
431
- if (props.preventLeave) {
432
- preventLeave(root, promise);
433
- } else if (props.preventNavigation) {
434
- lock(root, promise);
519
+ if (queue.length || active.length >= (multiple ? props.concurrent || Infinity : 1)) {
520
+ return new Promise(function (resolve) {
521
+ queue.push(function (renderNext) {
522
+ resolve(renderNext && render(callback));
523
+ });
524
+ setPendingCount(queue.length);
525
+ });
435
526
  }
436
- return promise;
527
+ return render(callback);
437
528
  }
438
- };
529
+ });
530
+ return extend(controller, {
531
+ dismissAll: dismissAll,
532
+ dismissPending: dismissPending
533
+ });
439
534
  }
440
535
 
441
536
  /**
442
537
  * @param {import("./dialog").DialogProps} props
443
538
  */
444
539
  function Dialog(props) {
445
- var _props = useState({})[0];
446
- var dialog = useState(function () {
447
- return createDialog(_props);
540
+ var _props = extend(useState({})[0], props);
541
+ var element = useState(function () {
542
+ return createDialogElement(_props);
448
543
  })[0];
449
- extend(_props, props);
450
544
  useEffect(function () {
451
- var opened = containsOrEquals(zeta_dom_dom.root, dialog.root);
545
+ var opened = isFlyoutOpen(element);
452
546
  if (either(opened, _props.isOpen)) {
453
547
  if (!opened) {
454
- dialog.open();
548
+ showDialog(element, _props);
455
549
  } else {
456
- dialog.close();
550
+ closeFlyout(element);
457
551
  }
458
552
  }
459
553
  }, [_props.isOpen]);
460
554
  useEffect(function () {
461
- return dialog.close;
462
- }, [dialog]);
463
- return /*#__PURE__*/external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.createPortal(props.children, dialog.root);
555
+ return closeFlyout.bind(0, element);
556
+ }, []);
557
+ return /*#__PURE__*/external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.createPortal(props.children, element);
464
558
  }
465
559
  ;// CONCATENATED MODULE: ./|umd|/zeta-dom/events.js
466
560
 
@@ -493,7 +587,7 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
493
587
 
494
588
 
495
589
 
496
- var _ = createPrivateStore();
590
+ var view_ = createPrivateStore();
497
591
  var root = zeta_dom_dom.root;
498
592
  var routeMap = new Map();
499
593
  var usedParams = {};
@@ -502,7 +596,7 @@ var emitter = new EventContainer();
502
596
  var rootContext = freeze(extend(new ViewContext(), {
503
597
  container: root
504
598
  }));
505
- var rootState = _(rootContext);
599
+ var rootState = view_(rootContext);
506
600
  var StateContext = /*#__PURE__*/createContext(rootContext);
507
601
  var errorView;
508
602
  /** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
@@ -531,7 +625,7 @@ function ViewContext(view, page, parent) {
531
625
  var self = this;
532
626
  defineOwnProperty(self, 'view', view || null, true);
533
627
  defineOwnProperty(self, 'parent', parent || null, true);
534
- _(self, {
628
+ view_(self, {
535
629
  children: [],
536
630
  setPage: defineObservableProperty(self, 'page', page || null, true),
537
631
  setActive: defineObservableProperty(self, 'active', !!page, true)
@@ -548,12 +642,12 @@ function ViewContext(view, page, parent) {
548
642
  defineOwnProperty(ViewContext, 'root', rootContext, true);
549
643
  definePrototype(ViewContext, {
550
644
  getChildren: function getChildren() {
551
- return map(_(this).children, function (v) {
645
+ return map(view_(this).children, function (v) {
552
646
  return v.currentContext;
553
647
  });
554
648
  },
555
649
  setErrorView: function setErrorView(errorView, error) {
556
- var wrapper = _(this).wrapper;
650
+ var wrapper = view_(this).wrapper;
557
651
  return wrapper && errorView && !wrapper.setState({
558
652
  error: error,
559
653
  errorView: errorView
@@ -566,7 +660,7 @@ definePrototype(ViewContext, {
566
660
  function ErrorBoundary(props) {
567
661
  Component.call(this, props);
568
662
  this.state = {};
569
- _(props.context).wrapper = this;
663
+ view_(props.context).wrapper = this;
570
664
  }
571
665
  definePrototype(ErrorBoundary, Component, {
572
666
  componentDidMount: function componentDidMount() {
@@ -638,7 +732,7 @@ ViewContainer.contextType = StateContext;
638
732
  definePrototype(ViewContainer, Component, {
639
733
  componentDidMount: function componentDidMount() {
640
734
  var self = this;
641
- var parent = _(self.context).children;
735
+ var parent = view_(self.context).children;
642
736
  var unwatch = watch(app_app.route, function () {
643
737
  self.setActive(self.getViewComponent() === (self.currentContext || '').view);
644
738
  });
@@ -731,7 +825,7 @@ definePrototype(ViewContainer, Component, {
731
825
  });
732
826
  self.views.shift();
733
827
  self.setContext(context);
734
- extend(self, _(context));
828
+ extend(self, view_(context));
735
829
  state.rendered++;
736
830
  animateIn(element, 'show', '[brew-view]', true);
737
831
  resolve();
@@ -1229,37 +1323,31 @@ util_define(Mixin, {
1229
1323
  },
1230
1324
  use: function use() {
1231
1325
  var args = makeArray(arguments);
1232
- var ref = args[0];
1233
1326
  var props = {};
1234
- var mixins = args.filter(function (v) {
1235
- return v instanceof Mixin;
1236
- });
1237
- var refs = mixins.map(function (v) {
1238
- return v.getRef();
1239
- });
1240
- if (ref && !(ref instanceof Mixin)) {
1241
- if (typeof ref !== 'function') {
1242
- refs.push(function (v) {
1243
- ref.current = v;
1244
- });
1245
- } else {
1246
- refs.push(ref);
1247
- }
1327
+ var refs = [];
1328
+ var ref = args[0];
1329
+ if (!ref) {
1330
+ args.shift();
1331
+ } else if (typeof ref === 'function') {
1332
+ refs.push(ref);
1248
1333
  args.shift();
1249
- } else if (!ref) {
1334
+ } else if (typeof ref !== 'string' && !(ref instanceof Mixin)) {
1335
+ refs.push(function (w) {
1336
+ ref.current = w;
1337
+ });
1250
1338
  args.shift();
1251
1339
  }
1252
- each(mixins, function (i, v) {
1253
- extend(props, v.getCustomAttributes());
1340
+ each(args, function (i, v) {
1341
+ if (v instanceof Mixin) {
1342
+ refs.push(v.getRef());
1343
+ extend(props, v.getCustomAttributes());
1344
+ v.next();
1345
+ }
1254
1346
  });
1255
- extend(props, {
1347
+ return extend(props, {
1256
1348
  ref: combineFn(refs),
1257
1349
  className: classNames.apply(null, args)
1258
1350
  });
1259
- each(mixins, function (i, v) {
1260
- v.next();
1261
- });
1262
- return props;
1263
1351
  }
1264
1352
  });
1265
1353
  ;// CONCATENATED MODULE: ./|umd|/zeta-dom/observe.js
@@ -1883,15 +1971,12 @@ definePrototype(UnmanagedClassNameMixin, ClassNameMixin, {
1883
1971
 
1884
1972
 
1885
1973
 
1974
+
1886
1975
  function extendSelf(options) {
1887
1976
  extend(this, options);
1888
1977
  }
1889
1978
  function createUseFunction(ctor) {
1890
- return function () {
1891
- var mixin = useMixin(ctor);
1892
- (mixin.withOptions || extendSelf).apply(mixin, arguments);
1893
- return mixin;
1894
- };
1979
+ return useMixin.bind(0, ctor);
1895
1980
  }
1896
1981
  var useAnimateMixin = /*#__PURE__*/createUseFunction(AnimateMixin);
1897
1982
  var useAnimateSequenceMixin = /*#__PURE__*/createUseFunction(AnimateSequenceMixin);
@@ -1902,10 +1987,12 @@ var useLoadingStateMixin = /*#__PURE__*/createUseFunction(LoadingStateMixin);
1902
1987
  var useScrollableMixin = /*#__PURE__*/createUseFunction(ScrollableMixin);
1903
1988
  var useScrollIntoViewMixin = /*#__PURE__*/createUseFunction(ScrollIntoViewMixin);
1904
1989
  var useUnmanagedClassNameMixin = /*#__PURE__*/createUseFunction(UnmanagedClassNameMixin);
1905
- function useMixin(ctor) {
1906
- return useSingleton(function () {
1990
+ function useMixin(ctor, options) {
1991
+ var mixin = useSingleton(function () {
1907
1992
  return new ctor();
1908
- }).reset();
1993
+ }, []).reset();
1994
+ (mixin.withOptions || extendSelf).call(mixin, options);
1995
+ return mixin;
1909
1996
  }
1910
1997
  function useMixinRef(mixin) {
1911
1998
  return mixin && mixin.getMixin().reset();