brew-js-react 0.6.7 → 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 CHANGED
@@ -14,7 +14,7 @@ export type DialogBaseProps<T, V = T> = Omit<DialogOptions<T, V | undefined>, 'o
14
14
  /** @deprecated */
15
15
  export type DialogRenderComponentProps<T, V = T> = DialogOptions<T, V | undefined> & DialogContext<V | undefined>;
16
16
 
17
- export type DialogControllerOptions = Pick<DialogOptions<any>, 'container' | 'className' | 'focus' | 'modal'>;
17
+ export type DialogControllerOptions = Omit<DialogOptions<any>, 'onRender' | 'onCommit' | 'onOpen' | 'onClose' | 'controller'>;
18
18
 
19
19
  export interface DialogControllerAdvancedOptions extends DialogControllerOptions, Pick<DialogOptions<any>, 'onClose' | 'onOpen' | 'preventLeave' | 'preventNavigation'> {
20
20
  /**
@@ -203,6 +203,20 @@ export function createDialog<P extends DialogOptionsStrict<any, any>>(props: P):
203
203
 
204
204
  export function createDialog<P extends DialogOptions<any, any>>(props: P): DialogState<VoidOrOptional<P extends DialogOptions<infer T, infer V> ? T | V : unknown>>;
205
205
 
206
+ /**
207
+ * Opens a dialog.
208
+ * @param props A dictionary containing options.
209
+ */
210
+ export function openDialog<T, V>(props: DialogOptionsStrict<T, V>): Promise<DialogResult<VoidOrOptional<T>>>;
211
+
212
+ export function openDialog<T, V>(props: DialogOptions<T, V>): Promise<DialogResult<VoidOrOptional<T | V>>>;
213
+
214
+ export function openDialog<T, V = T>(props: DialogOptions<T, V | undefined>): Promise<DialogResult<VoidOrOptional<T | V>>>;
215
+
216
+ export function openDialog<P extends DialogOptionsStrict<any, any>>(props: P): Promise<DialogResult<VoidOrOptional<P extends DialogOptionsStrict<infer T, any> ? T : unknown>>>;
217
+
218
+ export function openDialog<P extends DialogOptions<any, any>>(props: P): Promise<DialogResult<VoidOrOptional<P extends DialogOptions<infer T, infer V> ? T | V : unknown>>>;
219
+
206
220
  /**
207
221
  * Renders a dialog declaratively.
208
222
  */
package/dialog.js CHANGED
@@ -2,10 +2,10 @@ import { createElement, StrictMode, useEffect, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import ReactDOMClient from "@misonou/react-dom-client";
4
4
  import { createAsyncScope } from "zeta-dom-react";
5
- import { always, arrRemove, combineFn, createPrivateStore, defineObservableProperty, either, extend, noop, pick, resolve, setImmediate } from "zeta-dom/util";
5
+ import { always, arrRemove, combineFn, createPrivateStore, defineObservableProperty, either, exclude, extend, noop, pick, resolve, setImmediate } from "zeta-dom/util";
6
6
  import { containsOrEquals, removeNode } from "zeta-dom/domUtil";
7
7
  import dom from "zeta-dom/dom";
8
- import { lock, preventLeave, runAsync, subscribeAsync } from "zeta-dom/domLock";
8
+ import { runAsync, subscribeAsync } from "zeta-dom/domLock";
9
9
  import { closeFlyout, isFlyoutOpen, openFlyout } from "brew-js/domAction";
10
10
 
11
11
  const _ = createPrivateStore();
@@ -40,24 +40,19 @@ function createDialogElement(props, unmountAfterUse) {
40
40
  return root;
41
41
  }
42
42
 
43
- function openDialog(element, props, container) {
43
+ function showDialog(element, props, container) {
44
44
  if (!containsOrEquals(dom.root, element)) {
45
45
  element.className = props.className || '';
46
- (container || props.container || document.body).appendChild(element);
47
46
  if (props.modal) {
48
47
  element.setAttribute('is-modal', '');
49
48
  }
50
- setImmediate(function () {
51
- dom.retainFocus(dom.activeElement, element);
52
- });
53
- }
54
- var promise = openFlyout(element, null, pick(props, ['focus', 'closeOnBlur']));
55
- if (props.preventLeave) {
56
- preventLeave(element, promise);
57
- } else if (props.preventNavigation) {
58
- lock(element, promise);
49
+ (container || props.container || document.body).appendChild(element);
59
50
  }
60
- return promise;
51
+ return openFlyout(element, null, pick(props, ['focus', 'closeOnBlur', 'preventLeave', 'preventNavigation']));
52
+ }
53
+
54
+ export function openDialog(props) {
55
+ return createDialog(props).open();
61
56
  }
62
57
 
63
58
  /**
@@ -89,7 +84,7 @@ export function createDialog(props) {
89
84
  content = createElement(props.wrapper, dialogProps, content);
90
85
  }
91
86
  reactRoot.render(createElement(StrictMode, null, createElement(scope.Provider, null, content)));
92
- return shared ? { then: noop } : openDialog(root, props, container);
87
+ return shared ? { then: noop } : showDialog(root, props, container);
93
88
  }
94
89
 
95
90
  return {
@@ -153,7 +148,7 @@ export function createDialogQueue(props) {
153
148
  childProps = { closeOnBlur: false };
154
149
  props = extend({}, props, childProps);
155
150
  } else {
156
- childProps = props && pick(props, ['className', 'focus', 'modal', 'container']);
151
+ childProps = props && exclude(props, ['onCommit', 'onRender', 'onOpen', 'onClose']);
157
152
  }
158
153
  _(controller, {
159
154
  root: root,
@@ -161,7 +156,7 @@ export function createDialogQueue(props) {
161
156
  props: childProps,
162
157
  enqueue: function (callback) {
163
158
  if (root && !isFlyoutOpen(root)) {
164
- openDialog(root, props).then(dismissAll);
159
+ showDialog(root, props).then(dismissAll);
165
160
  }
166
161
  if (queue.length || active.length >= (multiple ? props.concurrent || Infinity : 1)) {
167
162
  return new Promise(function (resolve) {
@@ -189,7 +184,7 @@ export function Dialog(props) {
189
184
  var opened = isFlyoutOpen(element);
190
185
  if (either(opened, _props.isOpen)) {
191
186
  if (!opened) {
192
- openDialog(element, _props);
187
+ showDialog(element, _props);
193
188
  } else {
194
189
  closeFlyout(element);
195
190
  }
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.6.7 | (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"));
@@ -192,6 +192,7 @@ __webpack_require__.d(__webpack_exports__, {
192
192
  makeTranslation: () => (/* reexport */ makeTranslation),
193
193
  matchView: () => (/* reexport */ matchView),
194
194
  navigateTo: () => (/* reexport */ navigateTo),
195
+ openDialog: () => (/* reexport */ openDialog),
195
196
  redirectTo: () => (/* reexport */ redirectTo),
196
197
  registerErrorView: () => (/* reexport */ registerErrorView),
197
198
  registerView: () => (/* reexport */ registerView),
@@ -351,8 +352,6 @@ var reportError = dom.reportError;
351
352
  ;// CONCATENATED MODULE: ./|umd|/zeta-dom/domLock.js
352
353
 
353
354
  var _lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.dom,
354
- lock = _lib$dom.lock,
355
- preventLeave = _lib$dom.preventLeave,
356
355
  runAsync = _lib$dom.runAsync,
357
356
  subscribeAsync = _lib$dom.subscribeAsync;
358
357
 
@@ -402,24 +401,18 @@ function createDialogElement(props, unmountAfterUse) {
402
401
  subscribeAsync(root, true);
403
402
  return root;
404
403
  }
405
- function openDialog(element, props, container) {
404
+ function showDialog(element, props, container) {
406
405
  if (!containsOrEquals(zeta_dom_dom.root, element)) {
407
406
  element.className = props.className || '';
408
- (container || props.container || document.body).appendChild(element);
409
407
  if (props.modal) {
410
408
  element.setAttribute('is-modal', '');
411
409
  }
412
- setImmediate(function () {
413
- zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, element);
414
- });
415
- }
416
- var promise = openFlyout(element, null, pick(props, ['focus', 'closeOnBlur']));
417
- if (props.preventLeave) {
418
- preventLeave(element, promise);
419
- } else if (props.preventNavigation) {
420
- lock(element, promise);
410
+ (container || props.container || document.body).appendChild(element);
421
411
  }
422
- return promise;
412
+ return openFlyout(element, null, pick(props, ['focus', 'closeOnBlur', 'preventLeave', 'preventNavigation']));
413
+ }
414
+ function openDialog(props) {
415
+ return createDialog(props).open();
423
416
  }
424
417
 
425
418
  /**
@@ -452,7 +445,7 @@ function createDialog(props) {
452
445
  reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, /*#__PURE__*/createElement(scope.Provider, null, content)));
453
446
  return shared ? {
454
447
  then: noop
455
- } : openDialog(root, props, container);
448
+ } : showDialog(root, props, container);
456
449
  }
457
450
  return {
458
451
  root: root,
@@ -513,7 +506,7 @@ function createDialogQueue(props) {
513
506
  };
514
507
  props = extend({}, props, childProps);
515
508
  } else {
516
- childProps = props && pick(props, ['className', 'focus', 'modal', 'container']);
509
+ childProps = props && exclude(props, ['onCommit', 'onRender', 'onOpen', 'onClose']);
517
510
  }
518
511
  _(controller, {
519
512
  root: root,
@@ -521,7 +514,7 @@ function createDialogQueue(props) {
521
514
  props: childProps,
522
515
  enqueue: function enqueue(callback) {
523
516
  if (root && !isFlyoutOpen(root)) {
524
- openDialog(root, props).then(dismissAll);
517
+ showDialog(root, props).then(dismissAll);
525
518
  }
526
519
  if (queue.length || active.length >= (multiple ? props.concurrent || Infinity : 1)) {
527
520
  return new Promise(function (resolve) {
@@ -552,7 +545,7 @@ function Dialog(props) {
552
545
  var opened = isFlyoutOpen(element);
553
546
  if (either(opened, _props.isOpen)) {
554
547
  if (!opened) {
555
- openDialog(element, _props);
548
+ showDialog(element, _props);
556
549
  } else {
557
550
  closeFlyout(element);
558
551
  }
@@ -1330,37 +1323,31 @@ util_define(Mixin, {
1330
1323
  },
1331
1324
  use: function use() {
1332
1325
  var args = makeArray(arguments);
1333
- var ref = args[0];
1334
1326
  var props = {};
1335
- var mixins = args.filter(function (v) {
1336
- return v instanceof Mixin;
1337
- });
1338
- var refs = mixins.map(function (v) {
1339
- return v.getRef();
1340
- });
1341
- if (ref && !(ref instanceof Mixin)) {
1342
- if (typeof ref !== 'function') {
1343
- refs.push(function (v) {
1344
- ref.current = v;
1345
- });
1346
- } else {
1347
- refs.push(ref);
1348
- }
1327
+ var refs = [];
1328
+ var ref = args[0];
1329
+ if (!ref) {
1349
1330
  args.shift();
1350
- } else if (!ref) {
1331
+ } else if (typeof ref === 'function') {
1332
+ refs.push(ref);
1333
+ args.shift();
1334
+ } else if (typeof ref !== 'string' && !(ref instanceof Mixin)) {
1335
+ refs.push(function (w) {
1336
+ ref.current = w;
1337
+ });
1351
1338
  args.shift();
1352
1339
  }
1353
- each(mixins, function (i, v) {
1354
- 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
+ }
1355
1346
  });
1356
- extend(props, {
1347
+ return extend(props, {
1357
1348
  ref: combineFn(refs),
1358
1349
  className: classNames.apply(null, args)
1359
1350
  });
1360
- each(mixins, function (i, v) {
1361
- v.next();
1362
- });
1363
- return props;
1364
1351
  }
1365
1352
  });
1366
1353
  ;// CONCATENATED MODULE: ./|umd|/zeta-dom/observe.js