react-dialogger 1.1.85 → 1.1.87

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,6 +1,6 @@
1
1
  import { Component } from "react";
2
2
  import { DialogBase } from "./index.js";
3
- import { ActionProps, ActionState, DialogActionType, TBVariant, TBColor, DialogActionOptionsType, TDialogStateListenerForActionCallbackType, ActionIntent } from "../types/index.js";
3
+ import { ActionProps, ActionState, DialogActionType, TBVariant, TBColor, DialogActionOptionsType, TDialogStateListenerForActionCallbackType, ActionIntent, ActionIntentsType } from "../types/index.js";
4
4
  export declare const BASE_INTENTS: {
5
5
  readonly positive: {
6
6
  readonly color: "primary";
@@ -65,7 +65,7 @@ declare class DialogActionBase extends Component<ActionProps, ActionState> {
65
65
  /**
66
66
  * @deprecated use Options*/
67
67
  isDisabled: () => boolean;
68
- updateIntent: (intent: ActionIntent) => DialogActionBase;
68
+ updateIntent(intent: ActionIntentsType): this;
69
69
  setInProcess: (inProcess: boolean) => DialogActionBase;
70
70
  isInProcess: () => boolean;
71
71
  remove: () => void;
@@ -82,7 +82,7 @@ var DialogActionBase = /** @class */ (function (_super) {
82
82
  __extends(DialogActionBase, _super);
83
83
  function DialogActionBase(props) {
84
84
  if (props === void 0) { props = {}; }
85
- var _a, _b, _c, _d, _e, _f, _g;
85
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
86
86
  var _this = _super.call(this, props) || this; // This ensures that props is treated as readonly
87
87
  _this._options = {
88
88
  label: 'Button label',
@@ -139,10 +139,6 @@ var DialogActionBase = /** @class */ (function (_super) {
139
139
  _this.isDisabled = function () {
140
140
  return _this.state.options.disabled;
141
141
  };
142
- _this.updateIntent = function (intent) {
143
- _this.setState(function (prevState) { return (__assign(__assign({}, _this.state), { intent: intent })); });
144
- return _this;
145
- };
146
142
  _this.setInProcess = function (inProcess) {
147
143
  _this.setState(function (prevState) { return (__assign(__assign({}, prevState), { options: __assign(__assign({}, prevState.options), { disabled: inProcess }), inProcess: inProcess })); });
148
144
  return _this;
@@ -196,13 +192,13 @@ var DialogActionBase = /** @class */ (function (_super) {
196
192
  _this._inProcess = props.inProcess;
197
193
  var converted = (_b = (_a = props.name) === null || _a === void 0 ? void 0 : _a.replace(/action/i, '')) !== null && _b !== void 0 ? _b : props.name;
198
194
  var label = (_g = ((_f = (_e = (_d = (_c = _this.props.dialogBaseComponent) === null || _c === void 0 ? void 0 : _c.dialogOptions) === null || _d === void 0 ? void 0 : _d.localText) === null || _e === void 0 ? void 0 : _e[converted]) !== null && _f !== void 0 ? _f : converted)) !== null && _g !== void 0 ? _g : 'Button';
199
- var initialIntents = props.dialogBaseComponent.dialogOptions.base.actions.initialIntents;
195
+ var initialIntents = ((_l = (_k = (_j = (_h = props.dialogBaseComponent) === null || _h === void 0 ? void 0 : _h.dialogOptions) === null || _j === void 0 ? void 0 : _j.base) === null || _k === void 0 ? void 0 : _k.actions) !== null && _l !== void 0 ? _l : {}).initialIntents;
200
196
  var mergedIntents = __assign(__assign({}, exports.BASE_INTENTS), initialIntents);
201
197
  _this.state = {
202
198
  coords: { x: -1, y: -1 },
203
199
  isRippling: false,
204
200
  // intent: props.intent,
205
- options: __assign(__assign(__assign({}, props.options), mergedIntents[props.intent]), { label: label }),
201
+ options: __assign(__assign(__assign({}, props.options), mergedIntents[props.intent]), { label: (_m = props.options.label) !== null && _m !== void 0 ? _m : label }),
206
202
  inProcess: false
207
203
  };
208
204
  _this._buttonRef = React.createRef();
@@ -266,6 +262,12 @@ var DialogActionBase = /** @class */ (function (_super) {
266
262
  this._onClick = callback; // callback( this, this._dialogBaseComponent );
267
263
  return this;
268
264
  };
265
+ // updateIntent = ( intent: ActionIntent ): DialogActionBase => {
266
+ DialogActionBase.prototype.updateIntent = function (intent) {
267
+ var _this = this;
268
+ this.setState(function (prevState) { return (__assign(__assign({}, _this.state), { intent: intent })); });
269
+ return this;
270
+ };
269
271
  return DialogActionBase;
270
272
  }(react_1.Component));
271
273
  exports.default = DialogActionBase;
@@ -36,7 +36,8 @@ declare class DialogBase<Values extends FormikProps<Values>> extends Component<B
36
36
  private readonly _dialogWithBackDropRef;
37
37
  protected readonly _parent: Dialog;
38
38
  private _accessFrom;
39
- private _processingListeners;
39
+ private readonly _processingListeners;
40
+ private readonly _abortedListeners;
40
41
  constructor(props?: Readonly<BaseDialogProps>);
41
42
  private T;
42
43
  private readonly _features;
@@ -70,6 +71,7 @@ declare class DialogBase<Values extends FormikProps<Values>> extends Component<B
70
71
  };
71
72
  updateBody(body: TDialogCallbackFn): void;
72
73
  processingListener(listener: (inProcess: boolean) => void): this;
74
+ onAbort(callbackFn: TDialogCallbackFn<void>): this;
73
75
  getDom: () => HTMLDivElement;
74
76
  get snackbar(): {
75
77
  open: (message: string, severity: TSeverity, key?: string, action?: IDialogSnackbar["action"], autoHideDuration?: number | null) => void;
@@ -70,7 +70,7 @@ var DialogBase = /** @class */ (function (_super) {
70
70
  __extends(DialogBase, _super);
71
71
  function DialogBase(props) {
72
72
  if (props === void 0) { props = {}; }
73
- var _a;
73
+ var _a, _b;
74
74
  var _this = _super.call(this, props) || this;
75
75
  // ✨✨✨✨✨✨✨✨✨✨✨
76
76
  _this._dialogTranslate = { lastX: 0, lastY: 0 };
@@ -148,13 +148,29 @@ var DialogBase = /** @class */ (function (_super) {
148
148
  return _this._inProcess;
149
149
  };
150
150
  _this.close = function (callbackFn) {
151
+ var handleAbort = function () {
152
+ _this.setState(function (prevState) { return (__assign(__assign({}, prevState), { aborted: true })); });
153
+ setTimeout(function () {
154
+ for (var _i = 0, _a = _this._abortedListeners; _i < _a.length; _i++) {
155
+ var aborted = _a[_i];
156
+ if (typeof aborted === "function") {
157
+ aborted(_this);
158
+ }
159
+ }
160
+ _this.close(callbackFn);
161
+ }, 50);
162
+ };
151
163
  setTimeout(function () {
152
164
  var _a, _b, _c, _d;
153
- if (_this._footerRef.current.inProcess) {
165
+ if (_this._footerRef.current.inProcess && !_this.state.aborted) {
154
166
  var notify = (_a = _this._dialogOptions.base.notifyOnClosing) !== null && _a !== void 0 ? _a : "snackbar";
155
167
  if (notify === "snackbar") {
156
168
  var busyMessage = (_d = (_c = (_b = _this._dialogOptions) === null || _b === void 0 ? void 0 : _b.localText) === null || _c === void 0 ? void 0 : _c.busyMessage) !== null && _d !== void 0 ? _d : 'In Process, Please wait...';
157
- _this.snackbar.open(busyMessage, "warning");
169
+ _this.snackbar.open(busyMessage, "warning", null, function (key, snackbarRef) { return (0, jsx_runtime_1.jsx)(_components_1.DialogActionBase, { name: 'force_close', onClick: handleAbort, options: {
170
+ label: 'Abort',
171
+ variant: 'text',
172
+ color: '#361540'
173
+ } }); });
158
174
  }
159
175
  else {
160
176
  _this._dialogWithBackDropRef.current.baseZoomEffect();
@@ -191,7 +207,8 @@ var DialogBase = /** @class */ (function (_super) {
191
207
  _this.state = {
192
208
  inProcess: { inProcess: false },
193
209
  prevDialogRect: (0, _helpers_1.dialogRectAuto)(),
194
- body: props.body
210
+ body: props.body,
211
+ aborted: false
195
212
  };
196
213
  var defaultOptions = {
197
214
  base: {
@@ -237,6 +254,7 @@ var DialogBase = /** @class */ (function (_super) {
237
254
  _this._dialogWithBackDropRef = (0, react_1.createRef)();
238
255
  _this._parent = props.parent;
239
256
  _this._processingListeners = (_a = props.processingListeners) !== null && _a !== void 0 ? _a : [];
257
+ _this._abortedListeners = (_b = props.abortedListeners) !== null && _b !== void 0 ? _b : [];
240
258
  _this._features = [];
241
259
  return _this;
242
260
  }
@@ -413,6 +431,11 @@ var DialogBase = /** @class */ (function (_super) {
413
431
  this._processingListeners.push(listener);
414
432
  return this;
415
433
  };
434
+ DialogBase.prototype.onAbort = function (callbackFn) {
435
+ // @ts-ignore
436
+ this._abortedListeners.push(callbackFn);
437
+ return this;
438
+ };
416
439
  Object.defineProperty(DialogBase.prototype, "snackbar", {
417
440
  // Reference: https://notistack.com/api-reference#mutual-props
418
441
  get: function () {
@@ -2,7 +2,8 @@ import * as React from "react";
2
2
  import { DialogAction } from "./DialogAction";
3
3
  import { TInitialHolder, DialogValues, IDialogSize, TDialogStateListenerCallbackType, DialogOptionsType, IDialogApiDef, TDialogCallbackVoidFn, TDialogCallbackFn } from "../types/index.js";
4
4
  declare class Dialog {
5
- private _processingListeners;
5
+ private readonly _processingListeners;
6
+ private readonly _abortedListeners;
6
7
  private _stateListener;
7
8
  private _keyboardListener;
8
9
  private _resizeListener;
@@ -26,6 +27,7 @@ declare class Dialog {
26
27
  * Only from init */
27
28
  stateListener(listener: TDialogStateListenerCallbackType): this;
28
29
  processingListener(listener: (inProcess: boolean) => void): this;
30
+ onAbort(callbackFn: TDialogCallbackFn<void>): this;
29
31
  initialValues(values: DialogValues): this;
30
32
  initialHolder(holder: TInitialHolder): this;
31
33
  keyboardListener(listener: (key: string, dialog: IDialogApiDef) => void): this;
package/models/Dialog.js CHANGED
@@ -54,6 +54,9 @@ var appLogger_1 = require("../helpers/appLogger");
54
54
  var Dialog = /** @class */ (function () {
55
55
  function Dialog(dialogRef, options) {
56
56
  var _this = this;
57
+ // ✨✨✨✨✨✨✨✨✨✨✨
58
+ this._processingListeners = [];
59
+ this._abortedListeners = [];
57
60
  this._headerRef = React.createRef();
58
61
  this.highestZ = function () {
59
62
  var presentationElements = document.querySelectorAll('div[data-family="presentation"]');
@@ -117,7 +120,12 @@ var Dialog = /** @class */ (function () {
117
120
  };
118
121
  Dialog.prototype.processingListener = function (listener) {
119
122
  // @ts-ignore
120
- this._processingListeners = listener;
123
+ this._processingListeners.push(listener);
124
+ return this;
125
+ };
126
+ Dialog.prototype.onAbort = function (callbackFn) {
127
+ // @ts-ignore
128
+ this._abortedListeners.push(callbackFn);
121
129
  return this;
122
130
  };
123
131
  Dialog.prototype.initialValues = function (values) {
@@ -151,7 +159,7 @@ var Dialog = /** @class */ (function () {
151
159
  // Refs
152
160
  headerRef: this._headerRef,
153
161
  // Listeners
154
- stateListener: this._stateListener, keyboardListener: this._keyboardListener, resizeListener: this._resizeListener, processingListeners: this._processingListeners,
162
+ stateListener: this._stateListener, keyboardListener: this._keyboardListener, resizeListener: this._resizeListener, processingListeners: this._processingListeners, abortedListeners: this._abortedListeners,
155
163
  // Others
156
164
  dialogSize: this._dialogSize, initialHolder: this._initialHolder, snackbarAnchor: this._snackbarAnchor, root: root, dom: dom, parent: this }, this._apiRef ? { ref: this._apiRef } : null), { onClose: this._onCloseCallback });
157
165
  // @ts-ignore
@@ -30,7 +30,8 @@ var DialogAction = /** @class */ (function () {
30
30
  return _this;
31
31
  };
32
32
  this.setOptions = function (options) {
33
- _this._options = options;
33
+ _this._actionComponent.current.updateOptions(options);
34
+ // this._options = options;
34
35
  return _this;
35
36
  };
36
37
  this.onClick = function (callback) {
@@ -65,6 +66,7 @@ var DialogAction = /** @class */ (function () {
65
66
  });
66
67
  DialogAction.prototype.setIntent = function (intent) {
67
68
  this._intent = intent;
69
+ // this._actionComponent?.current?.updateIntent(intent)
68
70
  return this;
69
71
  };
70
72
  DialogAction.prototype.intent = function () {
@@ -72,7 +74,9 @@ var DialogAction = /** @class */ (function () {
72
74
  };
73
75
  Object.defineProperty(DialogAction.prototype, "options", {
74
76
  get: function () {
75
- return this._options;
77
+ var _a, _b, _c;
78
+ // return this._options;
79
+ return (_c = (_b = (_a = this._actionComponent) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.options) !== null && _c !== void 0 ? _c : this._options;
76
80
  },
77
81
  enumerable: false,
78
82
  configurable: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-dialogger",
3
- "version": "1.1.85",
3
+ "version": "1.1.87",
4
4
  "description": "This package is a continuation of the react-araci package. Due to an error, react-araci was removed, and it has been decided to continue under the new package name react-dialogger",
5
5
  "main": "index.js",
6
6
  "author": "Sueleyman Topaloglu",
package/styles/dialog.css CHANGED
@@ -210,7 +210,7 @@
210
210
  overflow: clip;
211
211
  }
212
212
  .dialog-main .dialog-header {
213
- min-height: 64px;
213
+ min-height: 3rem;
214
214
  padding: 10px 20px 10px 20px;
215
215
  display: flex;
216
216
  flex: 0;
@@ -276,7 +276,7 @@
276
276
  z-index: 2;
277
277
  }
278
278
  .dialog-main .dialog-footer {
279
- min-height: 64px;
279
+ min-height: 3rem;
280
280
  border-top: 0.5px solid rgba(0, 0, 0, 0.2);
281
281
  padding: 10px 20px 10px 20px;
282
282
  bottom: 0;
@@ -17,7 +17,7 @@ export interface ActionProps {
17
17
  * @see options.label */
18
18
  label?: string;
19
19
  onClick: DialogActionType;
20
- dialogBaseComponent: DialogBase<any>;
20
+ dialogBaseComponent?: DialogBase<any>;
21
21
  /**
22
22
  * @deprecated
23
23
  * @see options.variant */
@@ -43,7 +43,7 @@ export interface ActionProps {
43
43
  baseStyle?: CSSProperties;
44
44
  fontFamily?: string;
45
45
  stateListener?: TDialogStateListenerForActionCallbackType;
46
- intent: ActionIntentsType;
46
+ intent?: ActionIntentsType;
47
47
  }
48
48
  export interface ActionState {
49
49
  isRippling: boolean;
@@ -17,6 +17,12 @@ export interface BaseDialogState {
17
17
  fullscreenMode?: boolean;
18
18
  prevDialogRect: WithBackdrop['prevDialogRect'];
19
19
  body: TDialogCallbackFn;
20
+ /**
21
+ * Indicates whether the operation was aborted by the user or the system.
22
+ * - true: The dialog or background process (e.g., API request) was aborted.
23
+ * - false: The operation is continuing or completed normally.
24
+ */
25
+ aborted: boolean;
20
26
  }
21
27
  export interface DialogFormikAdapter<Values> extends Omit<FormikProps<any>, 'values' | 'setValues' | 'setFieldValue' | 'validateForm' | 'errors'> {
22
28
  values: Values;
@@ -43,6 +49,7 @@ export interface BaseDialogProps {
43
49
  keyboardListener: (key: string, dialog: IDialogApiDef) => void;
44
50
  resizeListener?: (size: IDialogSize, dialog: IDialogApiDef) => void;
45
51
  processingListeners?: Array<(inProcess: boolean) => void>;
52
+ abortedListeners?: Array<(dialog: IDialogApiDef) => void>;
46
53
  }
47
54
  export interface IDialogSize {
48
55
  width?: ITypeWidth | number;
@@ -139,7 +146,7 @@ export type TDialogStateListenerCallbackType = (values: FormikProps<any>['values
139
146
  export type TDialogCallbackFn<T = React.ReactNode | React.ReactElement> = (dialog: IDialogApiDef) => T;
140
147
  export type TDialogHeader = TDialogCallbackFn | React.ReactNode | React.JSX.Element;
141
148
  export type TDialogCallbackVoidFn = TDialogCallbackFn<void>;
142
- export interface IDialogApiDef extends Pick<DialogBase<any>, 'isInProcess' | 'setInProcess' | 'values' | 'setValue' | 'setValues' | 'close' | 'dialogOptions' | 'actions' | 'snackbar' | 'formikValidate' | 'formikProps' | 'focus' | 'updateBody' | 'processingListener' | 'addFeature' | 'getFeature'> {
149
+ export interface IDialogApiDef extends Pick<DialogBase<any>, 'isInProcess' | 'setInProcess' | 'values' | 'setValue' | 'setValues' | 'close' | 'dialogOptions' | 'actions' | 'snackbar' | 'formikValidate' | 'formikProps' | 'focus' | 'updateBody' | 'processingListener' | 'addFeature' | 'getFeature' | 'onAbort'> {
143
150
  }
144
151
  export interface IDialogCloseRef extends Pick<DialogBase<any>, 'close'> {
145
152
  }