react-dialogger 1.1.112 → 1.1.114

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.
@@ -2,6 +2,6 @@ import { DialogAction } from "../models/index.js";
2
2
  import { DialogBase } from "./index.js";
3
3
  declare const Actions: ({ actions, dialog }: {
4
4
  actions?: DialogAction[];
5
- dialog: DialogBase<any, any, any>;
5
+ dialog: DialogBase<any, any>;
6
6
  }) => import("react/jsx-runtime").JSX.Element;
7
7
  export { Actions };
@@ -6,7 +6,7 @@ var _components_1 = require("./index.js");
6
6
  var Actions = function (_a) {
7
7
  var actions = _a.actions, dialog = _a.dialog;
8
8
  var dialogOptions = dialog.dialogOptions;
9
- return (0, jsx_runtime_1.jsx)("div", { style: { position: 'relative', display: 'flex', flexDirection: 'row', columnGap: 10, alignItems: 'center' }, children: actions.map(function (action, index) {
9
+ return (0, jsx_runtime_1.jsx)("div", { style: { position: 'relative', display: 'flex', flexDirection: 'row', columnGap: 10, alignItems: 'center' }, children: actions === null || actions === void 0 ? void 0 : actions.map(function (action, index) {
10
10
  var referencedAction = dialog.initializeActionRef(action.name);
11
11
  action._actionComponent = referencedAction;
12
12
  return (0, jsx_runtime_1.jsx)(_components_1.DialogActionBase, { name: action.name, ref: referencedAction, dialogBaseComponent: dialog,
@@ -16,7 +16,7 @@ export declare const BASE_INTENTS: {
16
16
  };
17
17
  };
18
18
  declare class DialogActionBase extends Component<ActionProps, ActionState> {
19
- get dialogBaseComponent(): DialogBase<any, any, any>;
19
+ get dialogBaseComponent(): DialogBase<any, any>;
20
20
  protected _options: DialogActionOptionsType;
21
21
  protected _intent: ActionIntent;
22
22
  _stateListener: TDialogStateListenerForActionCallbackType;
@@ -1,11 +1,11 @@
1
1
  import { Component, RefObject } from 'react';
2
2
  import { FormikProps } from "formik";
3
3
  import { DialogActionBase } from "./index.js";
4
- import { BaseDialogProps, BaseDialogState, IDialogSize, DialogOptionsType, TDialogCallbackFn, TDialogCallbackVoidFn, WithBackdrop, IDialogSnackbar, IInProcess, TInitialHolder, ISnackbarAnchor, TSeverity, TAccessFrom, ActionApiDef, DialogContentFooterReturnType, DialogFormikAdapter, DialogExternalHandlers, DialogExternalHandler, Dialogify, DialogExternalRefs, DialogExternalRef } from "../types/index.js";
4
+ import { BaseDialogProps, BaseDialogState, IDialogSize, DialogOptionsType, TDialogCallbackFn, WithBackdrop, IDialogSnackbar, IInProcess, TInitialHolder, ISnackbarAnchor, TSeverity, TAccessFrom, ActionApiDef, DialogContentFooterReturnType, DialogFormikAdapter, Dialogify, DialogInjectDef } from "../types/index.js";
5
5
  import Dialog, { DialogAction } from "../models/index.js";
6
6
  interface IFormikAdapter extends Pick<FormikProps<any>, 'setValues' | 'setFieldValue' | 'values'> {
7
7
  }
8
- declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers extends Record<string, DialogExternalHandler> = {}, StockDialogRefs extends Record<string, DialogExternalRef> = {}> extends Component<BaseDialogProps<Values, StockDialogHandlers, StockDialogRefs>, BaseDialogState> {
8
+ declare class DialogBase<V, I> extends Component<BaseDialogProps<V, I>, BaseDialogState<V, I>> {
9
9
  _dialogTranslate: {
10
10
  lastX: number;
11
11
  lastY: number;
@@ -14,8 +14,8 @@ declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers
14
14
  [key: string]: RefObject<DialogActionBase>;
15
15
  };
16
16
  protected _inlineFormikProps: IFormikAdapter;
17
- protected _header: TDialogCallbackFn;
18
- protected _body: TDialogCallbackFn;
17
+ protected _header: TDialogCallbackFn<V, I>;
18
+ protected _body: TDialogCallbackFn<V, I>;
19
19
  protected _actions: DialogAction[];
20
20
  protected _dialogSize: IDialogSize;
21
21
  protected _holder?: TInitialHolder;
@@ -25,13 +25,11 @@ declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers
25
25
  protected readonly _dialogBodyRef: RefObject<any>;
26
26
  protected readonly _snackbarRef: WithBackdrop['snackbarRef'];
27
27
  protected _dialogOptions?: DialogOptionsType;
28
- protected _onClose: TDialogCallbackVoidFn;
28
+ protected _onClose: TDialogCallbackFn<V, I, void>;
29
29
  protected _shInterval: number;
30
30
  protected _snackbarAnchor: ISnackbarAnchor;
31
- protected _parent: Dialog<Values, StockDialogHandlers, StockDialogRefs>;
32
- protected _xhandlers: DialogExternalHandlers<StockDialogHandlers>;
33
- protected _xrefs: DialogExternalRefs<StockDialogRefs>;
34
- protected _initialValues: Dialogify<Values>;
31
+ protected _parent: Dialog<V, I>;
32
+ protected _initialValues: Dialogify<V>;
35
33
  private _inProcess;
36
34
  private _footerRef;
37
35
  protected _headerRef: RefObject<DialogContentFooterReturnType>;
@@ -39,15 +37,14 @@ declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers
39
37
  private _accessFrom;
40
38
  private readonly _processingListeners;
41
39
  private readonly _abortedListeners;
42
- constructor(props: BaseDialogProps<Values, StockDialogHandlers, StockDialogRefs> & {
43
- parent: Dialog<Values, StockDialogHandlers, StockDialogRefs>;
44
- });
40
+ deps(): DialogInjectDef<I>;
41
+ get values(): Readonly<{
42
+ [K in keyof V]: Dialogify<V[K]>;
43
+ }>;
44
+ inject<T>(key: string, value: DialogInjectDef<T>): DialogBase<V, T>;
45
+ constructor(props: BaseDialogProps<V, I> & {});
45
46
  setValue<T>(key: string, value: Dialogify<T>): void;
46
- get xhandlers(): StockDialogHandlers;
47
- appendXHandler<H>(key: string, handler: DialogExternalHandler): void;
48
- get xrefs(): DialogExternalRefs<DialogExternalRef>;
49
- appendXRef<R>(key: R, ref: DialogExternalRef): void;
50
- get parent(): Dialog<Values, StockDialogHandlers, StockDialogRefs>;
47
+ get parent(): Dialog<V, I>;
51
48
  get dialogTranslate(): {
52
49
  lastX: number;
53
50
  lastY: number;
@@ -61,7 +58,6 @@ declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers
61
58
  set formikProps(value: FormikProps<any>);
62
59
  get formikValidate(): Promise<DialogFormikAdapter<any>>;
63
60
  set inlineFormikProps(inlineFormikProps: IFormikAdapter);
64
- get values(): Values;
65
61
  setValues<T>(values: Dialogify<T>, callbackFn?: () => void): void;
66
62
  componentDidMount(): void;
67
63
  setInProcess: (process: boolean, message?: string, holder?: TInitialHolder) => this;
@@ -72,9 +68,9 @@ declare class DialogBase<Values extends Record<string, any>, StockDialogHandlers
72
68
  get actions(): {
73
69
  [key: string]: ActionApiDef;
74
70
  };
75
- updateBody(body: TDialogCallbackFn): void;
71
+ updateBody(body: TDialogCallbackFn<V, I>): void;
76
72
  processingListener(listener: (inProcess: boolean) => void): this;
77
- onAbort(callbackFn: TDialogCallbackFn<void>): this;
73
+ onAbort(callbackFn: TDialogCallbackFn<V, I, void>): this;
78
74
  getDom: () => HTMLDivElement;
79
75
  get snackbar(): {
80
76
  open: (message: string, severity: TSeverity, key?: string, action?: IDialogSnackbar["action"], autoHideDuration?: number | null) => void;
@@ -66,7 +66,6 @@ var lodash_1 = require("lodash");
66
66
  var _components_1 = require("./index.js");
67
67
  var _helpers_1 = require("../helpers/index.js");
68
68
  var _context_1 = require("../context/index.js");
69
- var isRefObject_1 = require("../helpers/isRefObject");
70
69
  var DialogBase = /** @class */ (function (_super) {
71
70
  __extends(DialogBase, _super);
72
71
  function DialogBase(props) {
@@ -192,11 +191,13 @@ var DialogBase = /** @class */ (function (_super) {
192
191
  // Refs Props
193
192
  dialogRef: _this._dialogRef, headerRef: _this._headerRef, bodyRef: _this._dialogBodyRef, footerRef: _this._footerRef, backdropRef: _this._backdropRef, snackbarRef: _this._snackbarRef, prevDialogRect: _this.state.prevDialogRect, children: (0, jsx_runtime_1.jsx)(_components_1.DialogWithBackdropWrapper, {}) });
194
193
  };
194
+ // this.inject(props.inject);
195
195
  _this.state = {
196
196
  inProcess: { inProcess: false },
197
197
  prevDialogRect: (0, _helpers_1.dialogRectAuto)(),
198
198
  body: props.body,
199
- aborted: false
199
+ aborted: false,
200
+ inject: props.inject
200
201
  };
201
202
  var defaultOptions = {
202
203
  base: {
@@ -243,46 +244,28 @@ var DialogBase = /** @class */ (function (_super) {
243
244
  _this._processingListeners = (_a = props.processingListeners) !== null && _a !== void 0 ? _a : [];
244
245
  _this._abortedListeners = (_b = props.abortedListeners) !== null && _b !== void 0 ? _b : [];
245
246
  _this._initialValues = props.initialValues;
246
- _this._xhandlers = props.xhandlers;
247
- _this._xrefs = props.xrefs;
248
247
  return _this;
249
248
  }
250
- DialogBase.prototype.setValue = function (key, value) {
251
- var _a;
252
- (_a = this._inlineFormikProps) === null || _a === void 0 ? void 0 : _a.setFieldValue(key, value);
249
+ DialogBase.prototype.deps = function () {
250
+ return this.state.inject;
253
251
  };
254
- Object.defineProperty(DialogBase.prototype, "xhandlers", {
252
+ Object.defineProperty(DialogBase.prototype, "values", {
255
253
  get: function () {
256
- // @ts-ignore
257
- return this._xhandlers;
254
+ return this._inlineFormikProps.values;
258
255
  },
259
256
  enumerable: false,
260
257
  configurable: true
261
258
  });
262
- DialogBase.prototype.appendXHandler = function (key, handler) {
263
- // public appendXHandler(key: string, handler: DialogExternalHandler) {
264
- if (!key)
265
- throw new Error('Handler key is required');
266
- if (typeof handler !== 'function')
267
- throw new Error("Handler \"".concat(String(key), "\" must be a function"));
268
- // @ts-ignore
269
- this._xhandlers[key] = handler;
259
+ DialogBase.prototype.inject = function (key, value) {
260
+ this.setState(function (prevState) {
261
+ var _a;
262
+ return (__assign(__assign({}, prevState), { inject: __assign(__assign({}, prevState.inject), (_a = {}, _a[key] = value, _a)) }));
263
+ });
264
+ return this;
270
265
  };
271
- Object.defineProperty(DialogBase.prototype, "xrefs", {
272
- get: function () {
273
- // @ts-ignore
274
- return this._xrefs;
275
- },
276
- enumerable: false,
277
- configurable: true
278
- });
279
- DialogBase.prototype.appendXRef = function (key, ref) {
280
- if (!key)
281
- throw new Error('Ref key is required');
282
- if (!(0, isRefObject_1.isRefObject)(ref))
283
- throw new Error("Ref \"".concat(String(key), "\" must be a Reference RefObject"));
284
- // @ts-ignore
285
- this._xrefs[key] = ref;
266
+ DialogBase.prototype.setValue = function (key, value) {
267
+ var _a;
268
+ (_a = this._inlineFormikProps) === null || _a === void 0 ? void 0 : _a.setFieldValue(key, value);
286
269
  };
287
270
  Object.defineProperty(DialogBase.prototype, "parent", {
288
271
  get: function () {
@@ -360,13 +343,9 @@ var DialogBase = /** @class */ (function (_super) {
360
343
  enumerable: false,
361
344
  configurable: true
362
345
  });
363
- Object.defineProperty(DialogBase.prototype, "values", {
364
- get: function () {
365
- return this._inlineFormikProps.values;
366
- },
367
- enumerable: false,
368
- configurable: true
369
- });
346
+ // get values(): V {
347
+ // return this._inlineFormikProps.values;
348
+ // }
370
349
  DialogBase.prototype.setValues = function (values, callbackFn) {
371
350
  this._inlineFormikProps.setValues(values);
372
351
  if (typeof callbackFn === "function") {
@@ -412,8 +391,9 @@ var DialogBase = /** @class */ (function (_super) {
412
391
  Object.defineProperty(DialogBase.prototype, "actions", {
413
392
  get: function () {
414
393
  var _this = this;
394
+ var _a;
415
395
  var __actions = {};
416
- this._actions.forEach(function (action, index) {
396
+ (_a = this._actions) === null || _a === void 0 ? void 0 : _a.forEach(function (action, index) {
417
397
  var _a;
418
398
  __actions[action.name] = (_a = _this._actionRefs[action.name]) === null || _a === void 0 ? void 0 : _a.current; // ?? action;
419
399
  });
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { TDialogCallbackFn } from "../types/index.js";
3
3
  interface IContentBodyProps {
4
- body: TDialogCallbackFn;
4
+ body: TDialogCallbackFn<any, any>;
5
5
  }
6
6
  declare const DialogContentBody: React.FC<IContentBodyProps>;
7
7
  export { DialogContentBody };
@@ -81,6 +81,7 @@ var DialogContentFooter = (0, react_1.forwardRef)(function (props, ref) {
81
81
  // footerProps = {...dialogOptions.slotProps.footer, dialogOptions: dialogOptions, inProcess: dialog.isInProcess() }
82
82
  footerProps = dialogOptions.slotProps.footer;
83
83
  }
84
+ console.log('DialogBase_Render', dialog.actions);
84
85
  return (0, jsx_runtime_1.jsxs)("div", { className: 'dialog-footer', style: (_c = (_b = dialogOptions.base) === null || _b === void 0 ? void 0 : _b.footer) === null || _c === void 0 ? void 0 : _c.style, children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(_context_1.WithHeaderFooterContext, __assign({}, staticProps, { dialog: dialog, children: dialogOptions.slot.footer ?
85
86
  (0, jsx_runtime_1.jsx)(CustomFooter, __assign({}, staticProps, footerProps))
86
87
  :
@@ -1,7 +1,7 @@
1
1
  import { TDialogCallbackFn, IDialogBoundsDef } from "../types/index.js";
2
2
  import * as React from "react";
3
3
  interface IContentHeaderProps {
4
- header: TDialogCallbackFn;
4
+ header: TDialogCallbackFn<any, any>;
5
5
  bounds: IDialogBoundsDef;
6
6
  }
7
7
  declare const DialogContentHeader: React.FC<IContentHeaderProps>;
@@ -75,6 +75,7 @@ var DialogContentHeader = function (_a) {
75
75
  var CustomHeader = (_b = dialogOptions.slot) === null || _b === void 0 ? void 0 : _b.header;
76
76
  var staticProps = {
77
77
  dialogOptions: dialogOptions,
78
+ // @ts-ignore
78
79
  dialog: dialog
79
80
  };
80
81
  if (dialogOptions.slot.header) {
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import { DialogContentContextProviderProps, DialogContentContextProviderSharedProps } from "../types/index.js";
3
- export declare const DialogContentContext: React.Context<DialogContentContextProviderSharedProps>;
3
+ export declare const DialogContentContext: React.Context<DialogContentContextProviderSharedProps<Record<string, any>, unknown>>;
4
4
  declare const DialogContentContextProvider: React.FC<DialogContentContextProviderProps>;
5
5
  export { DialogContentContextProvider };
@@ -1,7 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { DialogAction } from "./DialogAction";
3
- import { TInitialHolder, IDialogSize, TDialogStateListenerCallbackType, DialogOptionsType, IDialogApiDef, TDialogCallbackVoidFn, TDialogCallbackFn, DialogExternalHandlers, Dialogify, DialogExternalRefs } from "../types/index.js";
4
- declare class Dialog<Values extends Record<string, any>, StockDialogHandlers extends Record<string, any> = {}, StockDialogRefs extends Record<string, any> = {}> {
3
+ import { TInitialHolder, IDialogSize, TDialogStateListenerCallbackType, DialogOptionsType, IDialogApiDef, TDialogCallbackFn, Dialogify, DialogInjectDef } from "../types/index.js";
4
+ declare class Dialog<V, I> {
5
+ private _initialValues?;
6
+ private _inject?;
5
7
  private readonly _processingListeners;
6
8
  private readonly _abortedListeners;
7
9
  private _stateListener;
@@ -23,29 +25,27 @@ declare class Dialog<Values extends Record<string, any>, StockDialogHandlers ext
23
25
  private _headerRef;
24
26
  private readonly _apiRef;
25
27
  private _onCloseCallback;
26
- private _initialValues;
27
- private _xhandlers;
28
- private _xrefs;
29
- constructor(dialogRef?: React.RefObject<IDialogApiDef | undefined | null> | null, options?: DialogOptionsType);
30
- setHeader(header: TDialogCallbackFn): this;
31
- setBody(body: TDialogCallbackFn): this;
28
+ constructor(dialogRef?: React.RefObject<IDialogApiDef | undefined | null> | null, options?: DialogOptionsType, _initialValues?: Dialogify<V>, _inject?: DialogInjectDef<I>);
29
+ inject<T>(args: DialogInjectDef<T>): Dialog<V, T>;
30
+ initialValues<K>(args: Dialogify<K>): Dialog<K, I>;
31
+ setHeader(header: TDialogCallbackFn<V, I>): this;
32
+ setBody(body: TDialogCallbackFn<V, I>): this;
32
33
  addActions(actions: Array<DialogAction>): this;
33
34
  addAction(action: DialogAction): this;
34
35
  /**
35
36
  * Only from init */
36
37
  stateListener(listener: TDialogStateListenerCallbackType): this;
37
38
  processingListener(listener: (inProcess: boolean) => void): this;
38
- onAbort(callbackFn: TDialogCallbackFn<void>): this;
39
- initialValues<T extends Record<string, any>>(values: Dialogify<T>): Dialog<T, any, any>;
40
- registerHandlers<H extends StockDialogHandlers>(handlers: DialogExternalHandlers<H>): Dialog<any, H, any>;
41
- registerRefs<R extends StockDialogRefs>(refs: DialogExternalRefs<R>): Dialog<any, any, R>;
39
+ onAbort(callbackFn: TDialogCallbackFn<V, I, void>): this;
42
40
  initialHolder(holder: TInitialHolder): this;
43
41
  keyboardListener(listener: (key: string, dialog: IDialogApiDef) => void): this;
44
42
  resizeListener(listener: (size: IDialogSize, dialog: IDialogApiDef) => void): this;
45
- onClose(callback: TDialogCallbackVoidFn): this;
43
+ onClose(callback: TDialogCallbackFn<V, I, void>): this;
46
44
  private highestZ;
47
45
  private createDom;
48
- get values(): Dialogify<Values>;
49
- show(callback?: TDialogCallbackVoidFn): void;
46
+ /**
47
+ * @deprecated only from inline */
48
+ get values(): Dialogify<V>;
49
+ show(callback?: TDialogCallbackFn<V, I, void>): void;
50
50
  }
51
51
  export default Dialog;
package/models/Dialog.js CHANGED
@@ -52,8 +52,11 @@ var DialogBase_1 = __importDefault(require("../components/DialogBase"));
52
52
  var client_1 = require("react-dom/client");
53
53
  var appLogger_1 = require("../helpers/appLogger");
54
54
  var Dialog = /** @class */ (function () {
55
- function Dialog(dialogRef, options) {
55
+ // private _initialValues :Dialogify<V>;
56
+ function Dialog(dialogRef, options, _initialValues, _inject) {
56
57
  var _this = this;
58
+ this._initialValues = _initialValues;
59
+ this._inject = _inject;
57
60
  // ✨✨✨✨✨✨✨✨✨✨✨
58
61
  this._processingListeners = [];
59
62
  this._abortedListeners = [];
@@ -104,6 +107,22 @@ var Dialog = /** @class */ (function () {
104
107
  }
105
108
  // this._xrefs = {} as DialogExternalRefs<StockDialogRefs>;
106
109
  }
110
+ Dialog.prototype.inject = function (args) {
111
+ // @ts-ignore
112
+ var t = new Dialog(this._apiRef, this._dialogOptions, this._initialValues, args);
113
+ var newDialog = Object.assign(this, t);
114
+ return newDialog;
115
+ };
116
+ // public initialValues<T extends Record<string, any>>( values: Dialogify<T> ): Dialog<T, I> {
117
+ Dialog.prototype.initialValues = function (args) {
118
+ // const next = this as unknown as Dialog<K, I>;
119
+ // next._initialValues = values;
120
+ // return next;
121
+ // @ts-ignore
122
+ var t = new Dialog(this._apiRef, this._dialogOptions, args, this._inject);
123
+ var newDialog = Object.assign(this, t);
124
+ return newDialog;
125
+ };
107
126
  Dialog.prototype.setHeader = function (header) {
108
127
  this._header = header;
109
128
  return this;
@@ -136,29 +155,6 @@ var Dialog = /** @class */ (function () {
136
155
  this._abortedListeners.push(callbackFn);
137
156
  return this;
138
157
  };
139
- // 👌Ok
140
- // public initialValues<T>( values: Dialogify<T> ): this {
141
- // this._initialValues = values as Dialogify<Values>;;
142
- // return this;
143
- // }
144
- // 👌Ok Combined with Dialog Class
145
- Dialog.prototype.initialValues = function (values) {
146
- var next = this;
147
- next._initialValues = values;
148
- return next;
149
- };
150
- Dialog.prototype.registerHandlers = function (handlers) {
151
- // this._xhandlers = handlers;
152
- // return this;
153
- var next = this;
154
- this._xhandlers = handlers;
155
- return next;
156
- };
157
- Dialog.prototype.registerRefs = function (refs) {
158
- var next = this;
159
- this._xrefs = refs;
160
- return next;
161
- };
162
158
  Dialog.prototype.initialHolder = function (holder) {
163
159
  this._initialHolder = holder;
164
160
  return this;
@@ -176,6 +172,8 @@ var Dialog = /** @class */ (function () {
176
172
  return this;
177
173
  };
178
174
  Object.defineProperty(Dialog.prototype, "values", {
175
+ /**
176
+ * @deprecated only from inline */
179
177
  get: function () {
180
178
  return this._initialValues;
181
179
  },
@@ -183,11 +181,12 @@ var Dialog = /** @class */ (function () {
183
181
  configurable: true
184
182
  });
185
183
  Dialog.prototype.show = function (callback) {
184
+ // public show ( callback?: (dialog: DialogBase<Values, I> & IDialogApiDef ) => void ): void {
186
185
  var dom = this.createDom();
187
186
  var root = (0, client_1.createRoot)(dom);
188
187
  var props = __assign(__assign({
189
188
  // Initials
190
- initialOptions: this._dialogOptions, initialValues: this._initialValues, xhandlers: this._xhandlers, xrefs: this._xrefs, didMountCallback: callback,
189
+ initialOptions: this._dialogOptions, initialValues: this._initialValues, didMountCallback: callback,
191
190
  // Component contents
192
191
  header: this._header, body: this._body, actions: this._actions,
193
192
  // Refs
@@ -195,8 +194,11 @@ var Dialog = /** @class */ (function () {
195
194
  // Listeners
196
195
  stateListener: this._stateListener, keyboardListener: this._keyboardListener, resizeListener: this._resizeListener, processingListeners: this._processingListeners, abortedListeners: this._abortedListeners,
197
196
  // Others
198
- dialogSize: this._dialogSize, initialHolder: this._initialHolder, snackbarAnchor: this._snackbarAnchor, root: root, dom: dom, parent: this }, this._apiRef ? { ref: this._apiRef } : null), { onClose: this._onCloseCallback });
197
+ dialogSize: this._dialogSize, initialHolder: this._initialHolder, snackbarAnchor: this._snackbarAnchor, root: root, dom: dom, parent: this }, this._apiRef ? { ref: this._apiRef } : null), { onClose: this._onCloseCallback, inject: this._inject });
199
198
  // @ts-ignore
199
+ // root.render( React.createElement( DialogBase as React.ComponentType<
200
+ // typeof this._initialValues
201
+ // >, props ) );
200
202
  root.render(React.createElement(DialogBase_1.default, props));
201
203
  };
202
204
  return Dialog;
File without changes
package/models/test.js ADDED
@@ -0,0 +1,79 @@
1
+ // import Dialog from "./Dialog";
2
+ //
3
+ // const myRef = { current: "HELLO" };
4
+ // const myFunction = (name: string, age: number) => {
5
+ // return 21;
6
+ // };
7
+ //
8
+ // const f = (new Dialog(null, {}))
9
+ // const z = f.inject({
10
+ // // name: 'Suleyman',
11
+ // myFunc: myFunction,
12
+ // myRef,
13
+ // array_: {
14
+ // name: myFunction
15
+ // }
16
+ // })
17
+ // const name = z.getInject().myFunc('Suleyman', 22)
18
+ // const refika = z.getInject().array_.name('Suleyman', 44);
19
+ // const d = z.showMe( data => {
20
+ // data.getInject().myFunc('Suleyman', 21);
21
+ // })
22
+ // // // const typedDialog = f.inject({}); // ✅ BOZMAYACAK
23
+ //
24
+ // // f.getInject().test('Suleyman', 21); // ✅
25
+ // // f.getInject().rt.;
26
+ //
27
+ // // // typedDialog.getInject().test()// ✅
28
+ //
29
+ //
30
+ // // function bar<T>(arg: T){
31
+ // // return arg;
32
+ // // }
33
+ //
34
+ // // const retval = bar({
35
+ // // a: 1, b: 2, c: 3
36
+ // // });
37
+ //
38
+ // // retval.a
39
+ //
40
+ // class M<T> {
41
+ //
42
+ // private _name: string;
43
+ // constructor(private b?: T) {}
44
+ //
45
+ // static create<U>(args: U): M<U> {
46
+ // return new M(args);
47
+ // }
48
+ //
49
+ // public name(name: string): this {
50
+ // this._name = name;
51
+ // return this;
52
+ // }
53
+ //
54
+ // initialValues<U>(args: U): M<U> {
55
+ // return new M(args);
56
+ // }
57
+ //
58
+ // getD(): T {
59
+ // return this.b;
60
+ // }
61
+ //
62
+ // getC( callback: (data: T) => void): M<T>{
63
+ // callback(this.b);
64
+ // return this;
65
+ // }
66
+ // }
67
+ //
68
+ // // const t = M.create({ a: 1 });
69
+ // const t = new M();
70
+ //
71
+ // // t.getD().; // ✅
72
+ // t.name('Suleyman')
73
+ // .initialValues({
74
+ // b: 2, c: 3, name: 'Suleyman', age: 29
75
+ // })
76
+ // .getC( data => {
77
+ // console.log('getC', data.age);
78
+ // }).getD().age
79
+ //
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "react-dialogger",
3
- "version": "1.1.112",
3
+ "version": "1.1.114",
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",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "notistack": "^3.0.2",
10
9
  "formik": "^2.4.6",
11
- "react-draggable": "^4.4.6",
12
10
  "lodash": "^4.17.21",
13
11
  "lodash.isequal": "^4.5.0",
12
+ "notistack": "^3.0.2",
14
13
  "react": "^18.2.0",
15
- "react-dom": "^18.2.0"
14
+ "react-dom": "^18.2.0",
15
+ "react-draggable": "^4.4.6"
16
16
  },
17
17
  "maintainers": [
18
18
  {
@@ -29,5 +29,8 @@
29
29
  "react-component",
30
30
  "dynamic dialog",
31
31
  "react-dialogger"
32
- ]
32
+ ],
33
+ "devDependencies": {
34
+ "tsx": "^4.21.0"
35
+ }
33
36
  }
@@ -3,13 +3,13 @@ import { DialogBase, DialogActionBase } from "../components/index.js";
3
3
  import * as React from "react";
4
4
  import { DialogAction } from "../models/index.js";
5
5
  import { CSSProperties } from "react";
6
- export type ActionDialogDef = Omit<IDialogApiDef, 'switchFullScreen'>;
6
+ export type ActionDialogDef<V, I> = Omit<IDialogApiDef, 'switchFullScreen'>;
7
7
  export type ActionDef = Pick<DialogAction, 'onClick' | 'setOptions' | 'name'>;
8
8
  export type ActionApiDef = Pick<InstanceType<typeof DialogActionBase>, 'updateOptions' | 'updateColor' | 'updateVariant' | 'updateLabel' | 'updateIntent' | 'setOptions' | 'setInProcess' | 'getLabel' | 'options' | 'click' | 'remove' | 'name'>;
9
9
  export interface IDialogActionDef extends ActionApiDef {
10
10
  }
11
11
  export type DialogActionType = (button: ActionApiDef, dialog: Omit<IDialogApiDef, 'switchFullScreen'>) => void;
12
- export interface ActionProps {
12
+ export interface ActionProps<V extends Record<string, any> = Record<string, any>, I extends Record<string, any> = Record<string, any>> {
13
13
  name: string;
14
14
  options?: DialogActionOptionsType;
15
15
  /**
@@ -17,7 +17,7 @@ export interface ActionProps {
17
17
  * @see options.label */
18
18
  label?: string;
19
19
  onClick: DialogActionType;
20
- dialogBaseComponent?: DialogBase<any, any, any>;
20
+ dialogBaseComponent?: DialogBase<V, I>;
21
21
  /**
22
22
  * @deprecated
23
23
  * @see options.variant */
@@ -3,9 +3,9 @@ import DialogBase from "../components/DialogBase";
3
3
  import { ReactNode, RefObject } from "react";
4
4
  import { BaseDialogDOMRect } from "./index.js";
5
5
  import { Resizeable } from "../helpers/index.js";
6
- export interface DialogContentContextProviderProps {
7
- dialogBase: DialogBase<any, any, any>;
8
- body: TDialogCallbackFn<ReturnType<any>>;
6
+ export interface DialogContentContextProviderProps<V extends Record<string, any> = Record<string, any>, I = unknown> {
7
+ dialogBase: DialogBase<V, I>;
8
+ body: TDialogCallbackFn<V, I, ReturnType<any>>;
9
9
  dialogRef: RefObject<any>;
10
10
  headerRef: RefObject<any>;
11
11
  bodyRef: RefObject<any>;
@@ -15,8 +15,8 @@ export interface DialogContentContextProviderProps {
15
15
  prevDialogRect: BaseDialogDOMRect;
16
16
  children: ReactNode;
17
17
  }
18
- export interface DialogContentContextProviderSharedProps extends Partial<Pick<DialogContentContextProviderProps, 'body' | 'dialogRef' | 'headerRef' | 'bodyRef' | 'footerRef' | 'backdropRef' | 'snackbarRef' | 'prevDialogRect'>> {
18
+ export interface DialogContentContextProviderSharedProps<V extends Record<string, any> = Record<string, any>, I = unknown> extends Partial<Pick<DialogContentContextProviderProps<V, I>, 'body' | 'dialogRef' | 'headerRef' | 'bodyRef' | 'footerRef' | 'backdropRef' | 'snackbarRef' | 'prevDialogRect'>> {
19
19
  baseZoomEffect: () => void;
20
- dialog: DialogBase<any, any, any>;
20
+ dialog: DialogBase<V, I>;
21
21
  resizeableObject: Resizeable | null;
22
22
  }
@@ -10,19 +10,20 @@ import { SharedProps, SnackbarKey, SnackbarProvider, VariantType } from "notista
10
10
  export interface TBaseDialogState {
11
11
  [K: string]: any;
12
12
  }
13
- export interface BaseDialogState {
13
+ export interface BaseDialogState<V, I> {
14
14
  /**@deprecated use FormikProps Values*/
15
15
  values: DialogValues<Record<string, any>>;
16
16
  inProcess: IInProcess;
17
17
  fullscreenMode?: boolean;
18
18
  prevDialogRect: WithBackdrop['prevDialogRect'];
19
- body: TDialogCallbackFn;
19
+ body: TDialogCallbackFn<any, any>;
20
20
  /**
21
21
  * Indicates whether the operation was aborted by the user or the system.
22
22
  * - true: The dialog or background process (e.g., API request) was aborted.
23
23
  * - false: The operation is continuing or completed normally.
24
24
  */
25
25
  aborted: boolean;
26
+ inject: DialogInjectDef<I>;
26
27
  }
27
28
  export interface DialogFormikAdapter<Values> extends Omit<FormikProps<any>, 'values' | 'setValues' | 'setFieldValue' | 'validateForm' | 'errors'> {
28
29
  values: Values;
@@ -31,27 +32,26 @@ export interface DialogFormikAdapter<Values> extends Omit<FormikProps<any>, 'val
31
32
  validateForm(): Promise<any>;
32
33
  errors: any;
33
34
  }
34
- export interface BaseDialogProps<Values extends Record<string, any>, StockDialogHandlers extends Record<string, any>, StockDialogRefs extends Record<string, any>> {
35
- initialValues: Dialogify<Values>;
35
+ export interface BaseDialogProps<V extends Record<string, any>, I> {
36
+ inject: DialogInjectDef<I>;
37
+ initialValues: Dialogify<V>;
36
38
  initialOptions?: DialogOptionsType;
37
- body: TDialogCallbackFn;
38
- header?: TDialogCallbackFn;
39
+ body: TDialogCallbackFn<V, I>;
40
+ header?: TDialogCallbackFn<V, I>;
39
41
  actions?: Array<DialogAction>;
40
- didMountCallback?: TDialogCallbackVoidFn;
42
+ didMountCallback?: TDialogCallbackFn<V, I, void>;
41
43
  dialogSize?: IDialogSize;
42
44
  stateListener: TDialogStateListenerCallbackType;
43
- xhandlers: DialogExternalHandlers<StockDialogHandlers>;
44
- xrefs: DialogExternalRefs<StockDialogRefs>;
45
45
  initialHolder: TInitialHolder;
46
46
  snackbarAnchor?: ISnackbarAnchor;
47
47
  dom: HTMLDivElement;
48
48
  parent?: DialogValues<Record<string, any>>;
49
- onClose?: TDialogCallbackVoidFn;
49
+ onClose?: TDialogCallbackFn<V, I, void>;
50
50
  root?: any;
51
- keyboardListener: (key: string, dialog: IDialogApiDef) => void;
52
- resizeListener?: (size: IDialogSize, dialog: IDialogApiDef) => void;
51
+ keyboardListener: (key: string, dialog: IDialogApiDef<V, I>) => void;
52
+ resizeListener?: (size: IDialogSize, dialog: IDialogApiDef<V, I>) => void;
53
53
  processingListeners?: Array<(inProcess: boolean) => void>;
54
- abortedListeners?: Array<(dialog: IDialogApiDef) => void>;
54
+ abortedListeners?: Array<(dialog: IDialogApiDef<V, I>) => void>;
55
55
  }
56
56
  export interface IDialogSize {
57
57
  width?: ITypeWidth | number;
@@ -141,15 +141,19 @@ export interface BaseDialogSlotProps {
141
141
  dialogOptions: DialogOptionsType;
142
142
  dialog?: IDialogApiDef;
143
143
  }
144
- export interface IStateDef extends Pick<BaseDialogState, "values" | "fullscreenMode" | "inProcess"> {
144
+ export interface IStateDef extends Pick<BaseDialogState<any, any>, "values" | "fullscreenMode" | "inProcess"> {
145
145
  }
146
146
  export interface IListenerDialogDef extends Omit<IDialogApiDef, "values" | "setValues"> {
147
147
  }
148
148
  export type TDialogStateListenerCallbackType = (values: FormikProps<any>['values'], dialog: IListenerDialogDef) => void;
149
- export type TDialogCallbackFn<T = React.ReactNode | React.ReactElement> = (dialog: IDialogApiDef) => T;
150
- export type TDialogHeader = TDialogCallbackFn | React.ReactNode | React.JSX.Element;
151
- export type TDialogCallbackVoidFn = TDialogCallbackFn<void>;
152
- export interface IDialogApiDef extends Pick<DialogBase<any, any, any>, 'isInProcess' | 'setInProcess' | 'values' | 'setValue' | 'setValues' | 'close' | 'dialogOptions' | 'actions' | 'snackbar' | 'formikValidate' | 'formikProps' | 'focus' | 'updateBody' | 'processingListener' | 'onAbort' | 'xhandlers' | 'appendXHandler' | 'xrefs' | 'appendXRef'> {
149
+ export type TDialogCallbackFn<V, I, T = React.ReactNode | React.ReactElement> = (dialog: DialogBase<V, I> & IDialogApiDef) => T;
150
+ export type DialogValues<V extends Record<string, any>> = {
151
+ [K in keyof V]: Dialogify<V[K]>;
152
+ };
153
+ export type DialogInjects<I extends Record<string, any>> = {
154
+ [K in keyof I]: DialogInjectDef<I[K]>;
155
+ };
156
+ export interface IDialogApiDef<V extends Record<string, any> = Record<string, any>, I extends Record<string, any> = Record<string, any>> extends Pick<DialogBase<V, I>, 'isInProcess' | 'setInProcess' | 'values' | 'setValue' | 'setValues' | 'close' | 'dialogOptions' | 'actions' | 'snackbar' | 'formikValidate' | 'formikProps' | 'focus' | 'updateBody' | 'processingListener' | 'onAbort' | 'deps' | 'inject'> {
153
157
  }
154
158
  interface OpenArgs {
155
159
  message: any;
@@ -173,10 +177,10 @@ export interface IDialogSnackbar {
173
177
  }
174
178
  export interface WithBackdrop {
175
179
  ref: React.RefObject<any>;
176
- body: TDialogCallbackFn;
177
- header: TDialogCallbackFn;
180
+ body: TDialogCallbackFn<any, any>;
181
+ header: TDialogCallbackFn<any, any>;
178
182
  actions?: DialogAction[];
179
- dialog: DialogBase<any, any, any>;
183
+ dialog: DialogBase<any, any>;
180
184
  backdropRef: RefObject<any>;
181
185
  initialValues: Partial<Record<string, any>>;
182
186
  dialogRef: RefObject<any>;
@@ -194,8 +198,8 @@ export interface DialogWithBackdropWrapperRefProps {
194
198
  formikProps?: FormikProps<any>;
195
199
  }
196
200
  export interface IContentProps {
197
- body: TDialogCallbackFn;
198
- header: TDialogCallbackFn;
201
+ body: TDialogCallbackFn<any, any>;
202
+ header: TDialogCallbackFn<any, any>;
199
203
  actions: DialogAction[];
200
204
  dialogRef: React.RefObject<any>;
201
205
  headerRef: React.RefObject<any>;
@@ -203,7 +207,7 @@ export interface IContentProps {
203
207
  footerRef: React.RefObject<DialogContentFooterReturnType>;
204
208
  backdropRef: React.RefObject<any>;
205
209
  dialogOptions: DialogOptionsType;
206
- dialog: DialogBase<any, any, any>;
210
+ dialog: DialogBase<any, any>;
207
211
  resizeableObject?: Resizeable | null;
208
212
  prevDialogRect: WithBackdrop['prevDialogRect'];
209
213
  snackbarRef: WithBackdrop['snackbarRef'];
@@ -248,10 +252,6 @@ export type NonFunction<T> = T extends Function ? never : T;
248
252
  export type DialogValue<T> = string | number | boolean | null | undefined | DialogValue<T>[] | {
249
253
  [key: string]: DialogValue<T>;
250
254
  };
251
- export type ModelDialogValues<T> = {
252
- [K in keyof T]: DialogValue<T>;
253
- };
254
- export type DialogValues<T extends Record<string, any>> = ModelDialogValues<T>;
255
255
  export type Dialogify<T> = T extends Function ? never : T extends {
256
256
  current: null;
257
257
  } ? never : T extends string | number | boolean | null | undefined | Date ? T : T extends Array<infer U> ? Dialogify<U>[] : T extends object ? {
@@ -269,6 +269,11 @@ export type DialogExternalRefs<T> = T extends {
269
269
  } ? DialogExternalRef : T extends object ? {
270
270
  [K in keyof T]: DialogExternalRefs<T[K]>;
271
271
  } : never;
272
+ export type DialogInjectDef<T> = T extends Function ? T : T extends {
273
+ current: any;
274
+ } ? T : T extends string | number | boolean | null | undefined | Date ? never : T extends Array<infer U> ? never : T extends object ? {
275
+ [K in keyof T]: DialogInjectDef<T[K]>;
276
+ } : never;
272
277
  export interface BaseDialogDOMRect {
273
278
  height?: number;
274
279
  width?: number;
@@ -292,6 +297,6 @@ export interface ICoords {
292
297
  y: number;
293
298
  }
294
299
  export interface DialogProps {
295
- setHeader(header: TDialogCallbackFn): Dialog<any, any, any>;
300
+ setHeader(header: TDialogCallbackFn<any, any>): Dialog<any, any>;
296
301
  }
297
302
  export {};
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import { DialogBase } from "../components/index.js";
3
3
  import { Resizeable } from "../helpers/index.js";
4
- declare const resizeManager: (dialogRef: React.RefObject<HTMLDivElement>, dialog: DialogBase<any, any, any>) => Resizeable | null;
4
+ declare const resizeManager: <V, I>(dialogRef: React.RefObject<HTMLDivElement>, dialog: DialogBase<V, I>) => Resizeable | null;
5
5
  export { resizeManager };