react-dialogger 1.1.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.
Files changed (51) hide show
  1. package/README.md +303 -0
  2. package/components/CircularProgress.d.ts +8 -0
  3. package/components/CircularProgress.js +50 -0
  4. package/components/DialogActionBase.d.ts +44 -0
  5. package/components/DialogActionBase.js +222 -0
  6. package/components/DialogBase.d.ts +132 -0
  7. package/components/DialogBase.js +880 -0
  8. package/components/Futures/DialogCloseAction.d.ts +3 -0
  9. package/components/Futures/DialogCloseAction.js +54 -0
  10. package/components/Futures/DialogFullscreenAction.d.ts +3 -0
  11. package/components/Futures/DialogFullscreenAction.js +60 -0
  12. package/components/Futures/DialogHeaderActionsWrapper.d.ts +3 -0
  13. package/components/Futures/DialogHeaderActionsWrapper.js +11 -0
  14. package/components/Futures/DialogProcessing.d.ts +3 -0
  15. package/components/Futures/DialogProcessing.js +41 -0
  16. package/components/Futures/index.d.ts +4 -0
  17. package/components/Futures/index.js +11 -0
  18. package/components/RippleButton.d.ts +15 -0
  19. package/components/RippleButton.js +81 -0
  20. package/components/icons/CloseIcon.d.ts +6 -0
  21. package/components/icons/CloseIcon.js +23 -0
  22. package/components/icons/FullscreenExitIcon.d.ts +6 -0
  23. package/components/icons/FullscreenExitIcon.js +23 -0
  24. package/components/icons/FullscreenIcon.d.ts +6 -0
  25. package/components/icons/FullscreenIcon.js +23 -0
  26. package/components/icons/ResizeIcon.d.ts +6 -0
  27. package/components/icons/ResizeIcon.js +14 -0
  28. package/hooks/useDialogOptions.d.ts +3 -0
  29. package/hooks/useDialogOptions.js +82 -0
  30. package/index.d.ts +8 -0
  31. package/index.js +25 -0
  32. package/models/Dialog.d.ts +44 -0
  33. package/models/Dialog.js +142 -0
  34. package/models/DialogAction.d.ts +54 -0
  35. package/models/DialogAction.js +277 -0
  36. package/models/Resizeable.d.ts +21 -0
  37. package/models/Resizeable.js +87 -0
  38. package/package.json +20 -0
  39. package/styles/circular-progress.css +42 -0
  40. package/styles/dialog.action.css +234 -0
  41. package/styles/dialog.css +336 -0
  42. package/types/DialogActionTypes.d.ts +66 -0
  43. package/types/DialogActionTypes.js +3 -0
  44. package/types/DialogTypes.d.ts +128 -0
  45. package/types/DialogTypes.js +2 -0
  46. package/types/SizePosTypes.d.ts +5 -0
  47. package/types/SizePosTypes.js +2 -0
  48. package/types/index.d.ts +4 -0
  49. package/types/index.js +2 -0
  50. package/types/types.d.ts +58 -0
  51. package/types/types.js +2 -0
@@ -0,0 +1,880 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ var __importDefault = (this && this.__importDefault) || function (mod) {
52
+ return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.DialogHeaderFooterContext = void 0;
56
+ var react_1 = require("react");
57
+ var React = __importStar(require("react"));
58
+ var react_draggable_1 = __importDefault(require("react-draggable"));
59
+ var notistack_1 = require("notistack");
60
+ var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
61
+ var lodash_1 = require("lodash");
62
+ var DialogActionBase_1 = __importDefault(require("./DialogActionBase"));
63
+ var client_1 = require("react-dom/client");
64
+ var Resizeable_1 = __importDefault(require("../models/Resizeable"));
65
+ var ResizeIcon_1 = __importDefault(require("./icons/ResizeIcon"));
66
+ var Futures_1 = require("./Futures");
67
+ var WithSnackbar = function (props) {
68
+ return React.createElement(notistack_1.SnackbarProvider, { ref: props.snackbarRef, maxSnack: props.maxSnack }, props.children);
69
+ };
70
+ var WithHeaderFooterContext = function (props) {
71
+ return React.createElement(exports.DialogHeaderFooterContext.Provider, { value: __assign({}, props) }, props.children);
72
+ };
73
+ var hexToRgb = function (hex, opacity) {
74
+ try {
75
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
76
+ var colors = {
77
+ r: parseInt(result[1], 16),
78
+ g: parseInt(result[2], 16),
79
+ b: parseInt(result[3], 16)
80
+ };
81
+ return "rgba(".concat(colors.r, ", ").concat(colors.g, ", ").concat(colors.b, ", ").concat(opacity, ")");
82
+ }
83
+ catch (e) {
84
+ console.warn('Color should be hex string', e.message);
85
+ }
86
+ return '';
87
+ };
88
+ exports.DialogHeaderFooterContext = React.createContext(null);
89
+ var DialogBase = /** @class */ (function (_super) {
90
+ __extends(DialogBase, _super);
91
+ function DialogBase(props) {
92
+ if (props === void 0) { props = {}; }
93
+ var _a;
94
+ var _this = _super.call(this, props) || this; // This ensures that props is treated as readonly
95
+ _this._dialogTranslate = { lastX: 0, lastY: 0 };
96
+ _this._shInterval = 300;
97
+ _this._inProcess = { inProcess: false };
98
+ // Initialize a ref for each action dynamically
99
+ _this.initializeActionRef = function (key) {
100
+ if (!_this._actionRefs.hasOwnProperty(key)) {
101
+ _this._actionRefs[key] = (0, react_1.createRef)();
102
+ }
103
+ // Replace with referenced
104
+ return _this._actionRefs[key];
105
+ };
106
+ /**@deprecate
107
+ * @see this.state
108
+ * */
109
+ _this.getState = function () {
110
+ return _this.state;
111
+ };
112
+ _this.dialogAutoPos = function () {
113
+ var nodes = Array.from(document.querySelectorAll('.appinsource-dialog-root'));
114
+ if (nodes.length > 1) {
115
+ var lastDialog = nodes[nodes.length - 2];
116
+ var dialogMain = lastDialog.querySelector('#dialog-main');
117
+ return {
118
+ top: (dialogMain === null || dialogMain === void 0 ? void 0 : dialogMain.getBoundingClientRect().top) + 10,
119
+ left: (dialogMain === null || dialogMain === void 0 ? void 0 : dialogMain.getBoundingClientRect().left) + 10,
120
+ isMultiple: true
121
+ };
122
+ }
123
+ return { top: 0, left: 0, isMultiple: false };
124
+ };
125
+ _this.setInProcess_noRef = function (process, message, holder) {
126
+ var _a, _b;
127
+ _this._inProcess = __assign({ inProcess: process }, message ? { message: message } : {});
128
+ // this.setState( prevState => ({
129
+ // ...prevState, inProcess: { inProcess: process, ...message ? {message} : {} }
130
+ // }));
131
+ if (!process) {
132
+ _this._holder = null;
133
+ }
134
+ else {
135
+ if (holder) {
136
+ _this._holder = holder;
137
+ }
138
+ }
139
+ if ((_b = (_a = _this._dialogOptions.base) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.disabledOnDialogProcessing) {
140
+ if (process) {
141
+ // Set current disabled of action
142
+ _this._actions.forEach(function (action) {
143
+ var _a;
144
+ // Save the current disabled state before changing it
145
+ // const currentDisabled = action.getDisabled();
146
+ var currentDisabled = (_a = action.options.disabled) !== null && _a !== void 0 ? _a : action.getDisabled();
147
+ console.log('this._actions', currentDisabled, process);
148
+ // Set the options with prevDisabled as the current disabled state
149
+ if (currentDisabled !== process) {
150
+ action
151
+ .setOptions(__assign(__assign({}, action.options), { prevDisabled: currentDisabled, disabled: process // Set the new disabled state based on the process
152
+ }));
153
+ }
154
+ });
155
+ }
156
+ else {
157
+ // Call prevDisabled state from memo
158
+ _this._actions.forEach(function (action) {
159
+ // Restore the previous disabled state from options
160
+ action
161
+ .setOptions(__assign(__assign({}, action.options), { disabled: action.options.prevDisabled // Set the new disabled state based on the process
162
+ }));
163
+ });
164
+ }
165
+ }
166
+ if (!process) {
167
+ _this.snackbar.close("kInProcess");
168
+ }
169
+ _this.forceUpdate();
170
+ return _this;
171
+ };
172
+ _this.setInProcess = function (process, message, holder) {
173
+ var _a, _b;
174
+ _this._inProcess = __assign({ inProcess: process }, message ? { message: message } : {});
175
+ // this.setState( prevState => ({
176
+ // ...prevState, inProcess: { inProcess: process, ...message ? {message} : {} }
177
+ // }));
178
+ if (!process) {
179
+ _this._holder = null;
180
+ }
181
+ else {
182
+ if (holder) {
183
+ _this._holder = holder;
184
+ }
185
+ }
186
+ if ((_b = (_a = _this._dialogOptions.base) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.disabledOnDialogProcessing) {
187
+ if (process) {
188
+ for (var actionKey in _this._actionRefs) {
189
+ var action = _this._actionRefs[actionKey];
190
+ // Save the current disabled state before changing it
191
+ var currentDisabled = action.current.options.disabled;
192
+ console.log('this._actions', currentDisabled, process);
193
+ // Set the options with prevDisabled as the current disabled state
194
+ if (currentDisabled !== process) {
195
+ action.current
196
+ .setOptions(__assign(__assign({}, action.current.options), { prevDisabled: currentDisabled, disabled: process // Set the new disabled state based on the process
197
+ }));
198
+ }
199
+ }
200
+ }
201
+ else {
202
+ for (var actionKey in _this._actionRefs) {
203
+ var action = _this._actionRefs[actionKey];
204
+ // Restore the previous disabled state from options
205
+ // Call prevDisabled state from memo
206
+ action.current
207
+ .setOptions(__assign(__assign({}, action.current.options), { disabled: action.current.options.prevDisabled // Set the new disabled state based on the process
208
+ }));
209
+ }
210
+ }
211
+ }
212
+ if (!process) {
213
+ _this.snackbar.close("kInProcess");
214
+ }
215
+ _this.forceUpdate();
216
+ return _this;
217
+ };
218
+ _this.isInProcess = function () {
219
+ // return this.state.inProcess;
220
+ return _this._inProcess;
221
+ };
222
+ _this.close = function (callbackFn) {
223
+ var _a;
224
+ if (_this.isInProcess().inProcess) {
225
+ var notify = (_a = _this._dialogOptions.base.notifyOnClosing) !== null && _a !== void 0 ? _a : "snackbar";
226
+ if (notify === "snackbar") {
227
+ // this.snackbar.open(this._dialogOptions.snackbar.busyMessage ? this._dialogOptions.snackbar.busyMessage : 'In Process, Please wait...', "warning", "kInProcess");
228
+ _this.snackbar.open(_this._dialogOptions.snackbar.busyMessage ? _this._dialogOptions.snackbar.busyMessage : 'In Process, Please wait...', "warning");
229
+ }
230
+ else {
231
+ _this.baseZoomEffect();
232
+ }
233
+ return;
234
+ }
235
+ // ReactDOM.unmountComponentAtNode(this.props.dom);
236
+ var _backdrop = _this._backdropRef.current;
237
+ var _dialog = _this._dialogRef.current;
238
+ _backdrop === null || _backdrop === void 0 ? void 0 : _backdrop.classList.remove('dialog-backdrop-show');
239
+ _backdrop === null || _backdrop === void 0 ? void 0 : _backdrop.classList.add('dialog-backdrop-hide');
240
+ _dialog === null || _dialog === void 0 ? void 0 : _dialog.classList.remove('show-position-' + _this._dialogOptions.base.initialAnchor.vertical);
241
+ _dialog === null || _dialog === void 0 ? void 0 : _dialog.classList.add('hide-position-' + _this._dialogOptions.base.initialAnchor.vertical);
242
+ setTimeout(function () {
243
+ _this.props.root.unmount();
244
+ _this.props.dom.remove();
245
+ // unmountComponentAtNode(this.props.dom);
246
+ // @deprecated
247
+ if (typeof _this._onClose === "function") {
248
+ _this._onClose();
249
+ }
250
+ if (typeof callbackFn === "function") {
251
+ callbackFn();
252
+ }
253
+ }, _this._shInterval);
254
+ };
255
+ _this.focus = function () {
256
+ if (_this._dialogRef.current) {
257
+ _this._dialogRef.current.focus();
258
+ }
259
+ };
260
+ _this.orderPositionWithReference = function () {
261
+ try {
262
+ if (undefined !== _this._order) {
263
+ switch (_this._order.position) {
264
+ case "after":
265
+ _this.props.dom.before(_this._order.dom);
266
+ break;
267
+ case "before":
268
+ _this.props.dom.after(_this._order.dom);
269
+ break;
270
+ default: // same
271
+ }
272
+ }
273
+ }
274
+ catch (e) {
275
+ console.error('Error with orderPositionWithReference', e.message);
276
+ }
277
+ };
278
+ /**
279
+ * @deprecated
280
+ * @info This method is deprecated and will be removed in a future release.
281
+ * Please use an alternative approach for setting dialog ordering or layout.
282
+ * The dialog ordering functionality will be managed differently in future versions.
283
+ */
284
+ _this.setOrder = function (position, component) {
285
+ _this._order = { position: position, dom: component };
286
+ _this.forceUpdate();
287
+ return _this;
288
+ };
289
+ _this.getDom = function () {
290
+ return _this.props.dom;
291
+ };
292
+ _this.baseZoomEffect = function () {
293
+ var _a = _this._dialogTranslate, lastX = _a.lastX, lastY = _a.lastY;
294
+ _this._dialogRef.current.animate([
295
+ // key frames
296
+ { transform: "translate(".concat(lastX, "px, ").concat(lastY, "px) scale(1)") },
297
+ { transform: "translate(".concat(lastX, "px, ").concat(lastY, "px) scale(1.01)") },
298
+ // { boxShadow: `0 0 20px red`},
299
+ { transform: "translate(".concat(lastX, "px, ").concat(lastY, "px) scale(1)") }
300
+ ], {
301
+ // sync options
302
+ duration: 300,
303
+ iterations: 1
304
+ });
305
+ };
306
+ _this.withBackdrop = function (body, header, actions) {
307
+ _this.orderPositionWithReference();
308
+ var _a = _this._dialogOptions.backdrop, backgroundColor = _a.backgroundColor, opacity = _a.opacity;
309
+ var bgCl = hexToRgb(backgroundColor, opacity);
310
+ return React.createElement("div", { className: "dialog-backdrop dialog-backdrop-show", ref: _this._backdropRef, style: {
311
+ justifyContent: _this._dialogOptions.base.initialAnchor.horizontal,
312
+ // alignItems: dialogOptions.base.initialAnchor.vertical,
313
+ background: bgCl
314
+ }, onClick: function (e) {
315
+ if (_this.state.fullscreenMode)
316
+ return;
317
+ if (_this._dialogOptions.backdrop.hideOnClick) {
318
+ _this.close();
319
+ return;
320
+ }
321
+ _this.baseZoomEffect();
322
+ } }, _this.Content(body, header, actions));
323
+ };
324
+ _this.switchFullScreen = function () {
325
+ if (!_this.state.fullscreenMode) {
326
+ _this._dialogRef.current.classList.add('fullscreen');
327
+ }
328
+ else {
329
+ // alert(2);
330
+ _this._dialogRef.current.classList.remove('fullscreen');
331
+ }
332
+ _this._dialogRef.current.classList.add('no-user-select');
333
+ setTimeout(function () {
334
+ _this._dialogRef.current.classList.remove('no-user-select');
335
+ }, 500);
336
+ _this.setState(function (prevState) { return (__assign(__assign({}, prevState), { fullscreenMode: !_this.state.fullscreenMode })); });
337
+ };
338
+ _this.Placeholder = function (placeholder) {
339
+ var bgColor = _this._dialogOptions.base.style.backgroundColor ?
340
+ _this._dialogOptions.base.style.backgroundColor : "#FFFFFF";
341
+ var bg = _this._dialogOptions.base.style.background ?
342
+ _this._dialogOptions.base.style.background : "#FFFFFF";
343
+ return React.createElement("div", { className: 'dialog-content-placeholder', style: {
344
+ backgroundColor: bgColor,
345
+ background: bg,
346
+ display: placeholder ? 'flex' : 'none',
347
+ } }, placeholder);
348
+ };
349
+ _this.Header = function (header) {
350
+ var _a, _b, _c, _d, _e, _f, _g;
351
+ var CustomHeader = (_a = _this._dialogOptions.slot) === null || _a === void 0 ? void 0 : _a.header;
352
+ var staticProps = {
353
+ dialogValues: _this.state.values,
354
+ dialogOptions: _this._dialogOptions,
355
+ // apiRef: { current: this as IDialogRef } as RefObject<IDialogRef|IDialogCloseRef>
356
+ // apiRef: { current: this as IDialogRef }
357
+ dialog: _this
358
+ };
359
+ var headerProps = {};
360
+ if (_this._dialogOptions.slotProps.header) {
361
+ headerProps = _this._dialogOptions.slotProps.header(staticProps);
362
+ }
363
+ if (_this._dialogOptions.slot.header) {
364
+ return React.createElement("div", { onDoubleClick: function (event) {
365
+ if (_this._fullscreen) {
366
+ _this.switchFullScreen();
367
+ }
368
+ }, style: (_c = (_b = _this._dialogOptions.base) === null || _b === void 0 ? void 0 : _b.header) === null || _c === void 0 ? void 0 : _c.style, className: "dialog-header ".concat(_this._draggable && !_this.state.fullscreenMode ? 'drag-handle' : '') },
369
+ React.createElement(WithHeaderFooterContext, __assign({}, staticProps),
370
+ React.createElement(CustomHeader, __assign({}, staticProps, headerProps, { dialog: _this }))));
371
+ }
372
+ if (header instanceof Function) {
373
+ return React.createElement("div", { onDoubleClick: function (event) {
374
+ if (_this._fullscreen) {
375
+ _this.switchFullScreen();
376
+ }
377
+ }, style: (_e = (_d = _this._dialogOptions.base) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.style, className: "dialog-header ".concat(_this._draggable && !_this.state.fullscreenMode ? 'drag-handle' : '') },
378
+ header(_this),
379
+ (_this._closeable || _this._fullscreen) &&
380
+ React.createElement(WithHeaderFooterContext, { dialog: _this },
381
+ React.createElement(Futures_1.DialogHeaderActionsWrapper, null,
382
+ _this._fullscreen &&
383
+ React.createElement(Futures_1.DialogFullscreenAction, null),
384
+ _this._closeable &&
385
+ React.createElement(Futures_1.DialogCloseAction, null))));
386
+ }
387
+ return React.createElement("div", { style: (_g = (_f = _this._dialogOptions.base) === null || _f === void 0 ? void 0 : _f.header) === null || _g === void 0 ? void 0 : _g.style, className: 'drag-handle dialog-header' }, header);
388
+ };
389
+ _this.getSize = function () {
390
+ return _this._dialogSize;
391
+ };
392
+ _this.Body = function (body) {
393
+ if (body instanceof Function) {
394
+ return React.createElement("div", { ref: _this._dialogBodyRef, className: 'dialog-body', style: { height: '100%' } },
395
+ _this.Placeholder(_this._holder),
396
+ body(_this));
397
+ }
398
+ return React.createElement("div", { style: { height: '100%', padding: 10 } }, _this._holder ?
399
+ _this.Placeholder(_this._holder)
400
+ :
401
+ //@ts-ignore
402
+ body);
403
+ };
404
+ _this.Footer = function (actions) {
405
+ var _a, _b, _c;
406
+ var CustomFooter = (_a = _this._dialogOptions.slot) === null || _a === void 0 ? void 0 : _a.footer;
407
+ var staticProps = {
408
+ dialogValues: _this.state.values,
409
+ dialogOptions: _this._dialogOptions,
410
+ // apiRef: { current: this as IDialogRef } as RefObject<IDialogRef|IDialogCloseRef>
411
+ // apiRef: { current: this as IDialogRef }
412
+ dialog: _this
413
+ };
414
+ var footerProps = {};
415
+ if (_this._dialogOptions.slotProps.footer) {
416
+ footerProps = _this._dialogOptions.slotProps.footer({
417
+ dialogValues: _this.state.values,
418
+ dialogOptions: _this._dialogOptions,
419
+ inProcess: _this.isInProcess()
420
+ });
421
+ }
422
+ console.log('FooterSlot_props_Y', footerProps, staticProps);
423
+ return React.createElement("div", { className: 'dialog-footer', style: (_c = (_b = _this._dialogOptions.base) === null || _b === void 0 ? void 0 : _b.footer) === null || _c === void 0 ? void 0 : _c.style },
424
+ React.createElement("div", null,
425
+ React.createElement(WithHeaderFooterContext, __assign({}, staticProps, { dialog: _this }), _this._dialogOptions.slot.footer ?
426
+ /*<CustomFooter inProcess={this._inProcess} dialogValues={this.state.values} dialogOptions={this._dialogOptions} />*/
427
+ React.createElement(CustomFooter, __assign({}, staticProps, footerProps))
428
+ :
429
+ React.createElement(Futures_1.DialogProcessing, null)
430
+ /*<CircularProgress size={20} inProcess={this._inProcess} color={this._dialogOptions.progress.color}/>*/
431
+ )),
432
+ _this.Actions(actions));
433
+ };
434
+ _this.Actions = function (actions) {
435
+ return React.createElement("div", { style: { position: 'relative', display: 'flex', flexDirection: 'row', columnGap: 10, alignItems: 'center' } }, actions.map(function (action, index) {
436
+ // const ref = this.slotActionsRef[index];
437
+ // const ActionSlot = this._dialogOptions?.slot?.action;
438
+ // // console.log('ActionSlot',ActionSlot);
439
+ // if (ActionSlot) {
440
+ // return <ActionSlot
441
+ // ref={ref}
442
+ // key={index.toString()}
443
+ // {...this._dialogOptions?.slotProps?.action}
444
+ // onClick={ (event: React.MouseEvent) => {
445
+ // action._onClickSlot( ref, this );
446
+ // }}
447
+ // label={action.options.label}
448
+ // style={{...this._dialogOptions.slotProps?.action?.style, ...action.options.style }}
449
+ // />
450
+ //
451
+ // }
452
+ var referencedAction = _this.initializeActionRef(action.name);
453
+ // this._actions[action.name] = referencedAction.current
454
+ return React.createElement(DialogActionBase_1.default, { name: action.name, ref: referencedAction, key: index.toString(), dialogBaseComponent: _this, options: action.options, onClick: action.onClickHandler(), inProcess: action.isInProcess(),
455
+ // onLoad={ dialogAction => {
456
+ // action.baseDialogAction = dialogAction;
457
+ // }}
458
+ style: action.options.style, baseStyle: _this._dialogOptions.base.actions.baseStyle, fontFamily: _this._fontFamily, stateListener: action._stateListener });
459
+ }));
460
+ };
461
+ _this.Content = function (body, header, actions) {
462
+ var _a;
463
+ var _b, _c;
464
+ if (_this._dialogRef.current) {
465
+ // Öncelikle ref'i al ve input elemanlarını bul
466
+ var inputElements = _this._dialogRef.current.querySelectorAll("input");
467
+ // Tüm input elemanlarını döngüye al
468
+ inputElements.forEach(function (input) {
469
+ console.log(input); // Her bir input elemanını burada işleyebilirsiniz
470
+ // Örneğin, input değerini okuma veya ayarlama
471
+ input.addEventListener('keydown', function (e) { return e.key === "Enter" && e.preventDefault(); }); // Değerini boşaltmak için örnek
472
+ input.addEventListener('keyup', function (e) { return e.key === "Enter" && e.preventDefault(); }); // Değerini boşaltmak için örnek
473
+ input.addEventListener('keypress', function (e) { return e.key === "Enter" && e.preventDefault(); }); // Değerini boşaltmak için örnek
474
+ });
475
+ }
476
+ console.log('Content:', actions);
477
+ var xKey = _this.dialogPosFromMultipleDialogs.isMultiple ? "left" : "marginLeft";
478
+ var yKey = _this.dialogPosFromMultipleDialogs.isMultiple ? "top" : "marginTop";
479
+ return React.createElement(react_draggable_1.default, { disabled: !_this._draggable || _this.state.fullscreenMode, axis: 'both', handle: _this._draggable ? '.drag-handle' : '', scale: 1, ref: _this._backdropRef, onDrag: function (event, data) {
480
+ event.stopPropagation();
481
+ _this._dialogTranslate = { lastX: data.lastX, lastY: data.lastY };
482
+ } },
483
+ React.createElement("div", { id: "dialog-main", ref: _this._dialogRef, onClick: function (e) {
484
+ e.stopPropagation();
485
+ }, onKeyDown: function (e) {
486
+ if (typeof _this.props.keyboardListener === "function") {
487
+ // @ts-ignore
488
+ _this.props.keyboardListener(e.key, _this);
489
+ }
490
+ },
491
+ // className={this._dialogSize.width === 'auto' ? 'auto' : `dialog-width-${this._dialogSize.width} dialog-main show-opacity show-position-${this._dialogOptions.base.initialAnchor.vertical}`}
492
+ className: _this._dialogOptions.base.size.width === 'auto' ? 'auto' : "dialog-width-".concat(_this._dialogOptions.base.size.width, " dialog-main show-opacity show-position-").concat(_this._dialogOptions.base.initialAnchor.vertical), style: __assign(__assign(__assign(__assign({ alignSelf: _this._dialogOptions.base.initialAnchor.vertical, height: (_b = _this._dialogOptions.base.size.height) !== null && _b !== void 0 ? _b : 'auto' }, typeof _this._dialogOptions.base.size.width === "number" ? { width: _this._dialogOptions.base.size.width } : null), (_a = { outline: 'none' }, _a[yKey] = _this.dialogPosFromMultipleDialogs.top + 'px', _a[xKey] = _this.dialogPosFromMultipleDialogs.left + 'px', _a)), _this._dialogOptions.base.style), { fontFamily: _this._fontFamily }) },
493
+ React.createElement(WithSnackbar, { snackbarRef: _this._snackbarRef, maxSnack: _this._dialogOptions.snackbar.maxSnack },
494
+ (_this._header || _this._dialogOptions.slot.header) && _this.Header(header),
495
+ _this.Body(body),
496
+ _this.Footer(actions)),
497
+ (_this._dialogOptions.base.resizeable) &&
498
+ React.createElement(React.Fragment, null,
499
+ React.createElement("div", { className: "resizable-handle", onMouseDown: (_c = _this._Resizeable) === null || _c === void 0 ? void 0 : _c.resizeHandleMouseDown },
500
+ React.createElement(ResizeIcon_1.default, { color: '#286e94' })))));
501
+ };
502
+ _this.render = function () {
503
+ return _this.withBackdrop(_this._body, _this._header, _this._actions);
504
+ };
505
+ _this.state = __assign(__assign({}, _this._initialState), { fullscreenMode: false, isResizing: false, values: props.initialValues, inProcess: { inProcess: false } });
506
+ var defaultOptions = {
507
+ base: {
508
+ initialAnchor: {
509
+ vertical: "flex-start",
510
+ horizontal: "center"
511
+ },
512
+ size: {
513
+ width: "md",
514
+ height: "initial"
515
+ },
516
+ actions: {
517
+ baseStyle: {
518
+ padding: '3px 20px',
519
+ }
520
+ }
521
+ }
522
+ };
523
+ _this._dialogOptions = (0, lodash_1.merge)({}, defaultOptions, window["dialogOptions"], props.options);
524
+ _this._fontFamily = (_a = _this._dialogOptions.base.style.fontFamily) !== null && _a !== void 0 ? _a : 'Arial';
525
+ _this._header = props.header;
526
+ _this._body = props.body;
527
+ _this._actions = props.actions;
528
+ _this._backdropRef = React.createRef();
529
+ _this._dialogRef = React.createRef();
530
+ _this._dialogBodyRef = React.createRef();
531
+ _this._inProcess = { inProcess: false };
532
+ _this._snackbarRef = React.createRef();
533
+ if (props.dialogSize) {
534
+ _this._dialogSize = props.dialogSize;
535
+ }
536
+ else {
537
+ _this._dialogSize = { width: 'md' };
538
+ }
539
+ _this._dialogOptions = (0, lodash_1.merge)({}, {
540
+ base: {
541
+ size: _this._dialogSize
542
+ }
543
+ }, _this._dialogOptions);
544
+ // this._draggable = props.draggable ? props.draggable : this._dialogOptions.base.draggable;
545
+ _this._draggable = typeof _this._dialogOptions.base.draggable === "boolean" ? _this._dialogOptions.base.draggable : true;
546
+ // this._resizeable = props.resizeable ? props.resizeable : this._dialogOptions.base.resizeable;
547
+ _this._resizeable = typeof _this._dialogOptions.base.resizeable === "boolean" ? _this._dialogOptions.base.resizeable : false;
548
+ _this._closeable = typeof _this._dialogOptions.base.closeable === "boolean" ? _this._dialogOptions.base.closeable : false;
549
+ _this._fullscreen = typeof _this._dialogOptions.base.fullscreen === "boolean" ? _this._dialogOptions.base.fullscreen : false;
550
+ _this._order = props.order;
551
+ _this._holder = props.initialHolder;
552
+ _this._parent = props.parent;
553
+ _this._onClose = props.onClose;
554
+ _this.dialogPosFromMultipleDialogs = _this.dialogAutoPos();
555
+ if (_this._dialogOptions.base.resizeable) {
556
+ _this._Resizeable = new Resizeable_1.default();
557
+ }
558
+ // Initialize _actionRefs as an empty object
559
+ _this._actionRefs = {};
560
+ // Initialize Slots
561
+ // this._slots = this._dialogOptions.base.slots
562
+ _this._initialValues = props.initialValues;
563
+ return _this;
564
+ }
565
+ Object.defineProperty(DialogBase.prototype, "parent", {
566
+ get: function () {
567
+ return this._parent;
568
+ },
569
+ enumerable: false,
570
+ configurable: true
571
+ });
572
+ Object.defineProperty(DialogBase.prototype, "fullscreenMode", {
573
+ get: function () {
574
+ return this.state.fullscreenMode;
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+ Object.defineProperty(DialogBase.prototype, "dialogOptions", {
580
+ get: function () {
581
+ return this._dialogOptions;
582
+ },
583
+ enumerable: false,
584
+ configurable: true
585
+ });
586
+ Object.defineProperty(DialogBase.prototype, "formikProps", {
587
+ // get state(): T | Readonly<BaseDialogState> {
588
+ // return super.state
589
+ // }
590
+ get: function () {
591
+ return this._formikProps;
592
+ },
593
+ set: function (value) {
594
+ this._formikProps = value;
595
+ },
596
+ enumerable: false,
597
+ configurable: true
598
+ });
599
+ Object.defineProperty(DialogBase.prototype, "formikValidate", {
600
+ get: function () {
601
+ var _this = this;
602
+ if (!this.formikProps) {
603
+ new Error("No any formik Props");
604
+ }
605
+ return new Promise(function (resolve, reject) {
606
+ _this.formikProps.validateForm();
607
+ setTimeout(function () {
608
+ if (Object.keys(_this.formikProps.errors).length) {
609
+ reject(_this.formikProps.errors);
610
+ return;
611
+ }
612
+ resolve(_this.formikProps);
613
+ }, 100);
614
+ return;
615
+ });
616
+ },
617
+ enumerable: false,
618
+ configurable: true
619
+ });
620
+ Object.defineProperty(DialogBase.prototype, "values", {
621
+ get: function () {
622
+ return this.state.values;
623
+ },
624
+ enumerable: false,
625
+ configurable: true
626
+ });
627
+ DialogBase.prototype.setValues = function (values, callbackFn) {
628
+ var prevValues = __assign({}, this.state.values);
629
+ // this.setState( prevState => ({...prevState, values: {...prevValues, ...values}}) );
630
+ this.setState(function (prevState) { return (__assign(__assign({}, prevState), { values: __assign(__assign({}, prevValues), values) })); }, function () {
631
+ if (typeof callbackFn === 'function') {
632
+ callbackFn();
633
+ }
634
+ });
635
+ };
636
+ DialogBase.prototype.setValue = function (key, values) {
637
+ this.setState(function (prevState) {
638
+ var clonedVal = __assign({}, prevState.values);
639
+ clonedVal[key] = values;
640
+ return __assign(__assign({}, prevState), { values: clonedVal });
641
+ });
642
+ };
643
+ DialogBase.prototype.componentDidMount = function () {
644
+ var _this = this;
645
+ var _a, _b;
646
+ // İlk konumları global seçeneklerden al
647
+ var _c = this._dialogOptions.snackbar.anchorOrigin, vertical = _c.vertical, horizontal = _c.horizontal;
648
+ var initialAnchor = { vertical: vertical, horizontal: horizontal };
649
+ // Kullanıcı tanımlı konumlar varsa, onları ilk konumlarla birleştir
650
+ this._snackbarAnchor = __assign(__assign(__assign({}, initialAnchor), (((_a = this.props.snackbarAnchor) === null || _a === void 0 ? void 0 : _a.vertical) ? { vertical: this.props.snackbarAnchor.vertical } : {})), (((_b = this.props.snackbarAnchor) === null || _b === void 0 ? void 0 : _b.horizontal) ? { horizontal: this.props.snackbarAnchor.horizontal } : {}));
651
+ // didMountCallback varsa, promise ile çağır
652
+ if (undefined !== this.props.didMountCallback && typeof this.props.didMountCallback === "function") {
653
+ // @ts-ignore
654
+ // this.props.didMountCallback( this )
655
+ new Promise(function (resolve, reject) {
656
+ try {
657
+ setTimeout(function () {
658
+ resolve(true);
659
+ }, _this._shInterval);
660
+ }
661
+ catch (e) {
662
+ // fail(e);
663
+ }
664
+ }).then(function (completed) {
665
+ if (completed) {
666
+ // @ts-ignore
667
+ _this.props.didMountCallback(_this);
668
+ }
669
+ });
670
+ }
671
+ if (this._dialogRef.current) {
672
+ this._dialogRef.current.tabIndex = 0; // Odaklanabilir hale getirir
673
+ this._dialogRef.current.focus();
674
+ if (this._Resizeable) {
675
+ this._Resizeable.setContainer(this._dialogRef.current);
676
+ }
677
+ }
678
+ // Initialize SlotsProps
679
+ // this._slots?.forEach( (slot: any) => {
680
+ // this._slotProps[slot.name] = slot;
681
+ // });
682
+ // // Callback Slot Props
683
+ // try{
684
+ // this._dialogOptions.base?.slotProps(this._slotProps);
685
+ // } catch (e){
686
+ //
687
+ // }
688
+ // Parent objesinin accessFrom özelliğini ayarla
689
+ this.props.parent.accessFrom = "internal";
690
+ };
691
+ DialogBase.prototype.componentDidUpdate = function (prevProps, prevState, snapshot) {
692
+ /*if(this._dialogRef.current && this._dialogOptions.base.resizeable && !this._Resizeable){
693
+ console.log('this._Resizeable.onResizeListener', this._Resizeable );
694
+
695
+ this._Resizeable.onResizeListener((width, height) => {
696
+ console.log('this._Resizeable.onResizeListener', width, height );
697
+ this._dialogRef.current.style.width = width + 'px';
698
+ this._dialogRef.current.style.height = height + 'px';
699
+ })
700
+ }*/
701
+ };
702
+ // getSnapshotBeforeUpdate(prevProps: Readonly<BaseDialogProps>, prevState: Readonly<BaseDialogState>): any {
703
+ // }
704
+ DialogBase.prototype.componentWillUnmount = function () {
705
+ if (this._Resizeable) {
706
+ // Temizlik fonksiyonu
707
+ this._Resizeable.cleanUp();
708
+ }
709
+ };
710
+ DialogBase.prototype.setState = function (state, callback) {
711
+ var _this = this;
712
+ var prevState = this.state;
713
+ _super.prototype.setState.call(this, state, function () {
714
+ var _a;
715
+ // if( typeof this.props.stateListener === "function" && JSON.stringify(prevState) !== JSON.stringify(state) ){
716
+ if (typeof _this.props.stateListener === "function" && !(0, lodash_isequal_1.default)(prevState, state)) {
717
+ _this.props.stateListener(_this.state, _this.state.values, _this);
718
+ }
719
+ for (var actionKey in _this._actionRefs) {
720
+ var action = _this._actionRefs[actionKey];
721
+ if (typeof action.current._stateListener === "function") {
722
+ // action.getStateListener()( this.state, this.state.values, action.baseDialogAction, this );
723
+ // When using ref
724
+ action.current._stateListener(_this.state, _this.state.values, (_a = _this._actionRefs[action.current.name]) === null || _a === void 0 ? void 0 : _a.current, _this);
725
+ // action.getStateListener()( this.state, this.state.values, action.baseDialogAction, this );
726
+ }
727
+ // console.log('setStateRunned', action.current._stateListener, action.current.name, this._actionRefs, this );
728
+ }
729
+ // this._actions.forEach( action => {
730
+ // if( typeof action.getStateListener() === "function" ){
731
+ // // action.getStateListener()( this.state, this.state.values, action.baseDialogAction, this );
732
+ // // When using ref
733
+ // action.getStateListener()( this.state, this.state.values, this._actionRefs[action.name]?.current, this );
734
+ // // action.getStateListener()( this.state, this.state.values, action.baseDialogAction, this );
735
+ // }
736
+ // })
737
+ if (callback) {
738
+ setTimeout(function () {
739
+ callback();
740
+ }, 100);
741
+ }
742
+ });
743
+ };
744
+ DialogBase.prototype.setHeader = function (header) {
745
+ this._header = header;
746
+ this.forceUpdate();
747
+ return this;
748
+ };
749
+ DialogBase.prototype.setBody = function (body) {
750
+ this._body = body;
751
+ this.forceUpdate();
752
+ return this;
753
+ };
754
+ DialogBase.prototype.addActions = function (actions) {
755
+ this._actions = actions;
756
+ return this;
757
+ };
758
+ DialogBase.prototype.addAction = function (action) {
759
+ this._actions.push(action);
760
+ return this;
761
+ };
762
+ DialogBase.prototype.stateListener = function (listener) {
763
+ this._stateListener = listener;
764
+ return this;
765
+ };
766
+ DialogBase.prototype.keyboardListener = function (listener) {
767
+ this._keyboardListener = listener;
768
+ return this;
769
+ };
770
+ DialogBase.prototype.initialHolder = function (holder) {
771
+ this._initialHolder = holder;
772
+ return this;
773
+ };
774
+ // protected initialValues<T extends TValues>(values: T): DialogWithValues<T> {
775
+ //
776
+ // this.setState( prevState => {
777
+ // return {
778
+ // ...prevState, values
779
+ // }
780
+ // })
781
+ // // Burada yeni tipli bir sınıfa dönüyoruz
782
+ // return this as unknown as DialogWithValues<T>;
783
+ // }
784
+ DialogBase.prototype.onClose = function (callback) {
785
+ this._onClose = callback;
786
+ return this;
787
+ };
788
+ Object.defineProperty(DialogBase.prototype, "actions", {
789
+ get: function () {
790
+ var _this = this;
791
+ var __actions = {};
792
+ this._actions.forEach(function (action, index) {
793
+ // if (!this.slotActionsRef[index]) {
794
+ // this.slotActionsRef[index] = createRef();
795
+ // }
796
+ var _a, _b;
797
+ /**
798
+ * Herbir action Ref Objecsine atandi Her Ref Objeside BaseDialogActionBase ine baglandi
799
+ * inital Actionlar DialogAction i reference aliyor ve buda ic method erisimlerine engel oluyor DialogActionBase in ötelliklerine ulasamiyor o yuzden
800
+ * hetBir Action ic Reference ataniyor ve ic referencedeki methodlar disaridan cagirilabiliyor
801
+ * */
802
+ __actions[action.name] = (_b = (_a = _this._actionRefs[action.name]) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : action;
803
+ });
804
+ return __actions;
805
+ },
806
+ enumerable: false,
807
+ configurable: true
808
+ });
809
+ Object.defineProperty(DialogBase.prototype, "snackbar", {
810
+ // Reference: https://notistack.com/api-reference#mutual-props
811
+ get: function () {
812
+ var _this = this;
813
+ var _a;
814
+ var s = (_a = this._snackbarRef) === null || _a === void 0 ? void 0 : _a.current;
815
+ var sId = Math.random().toString(36).substring(2, 9);
816
+ var openMe = function (message, severity, key, action, autoHideDuration) {
817
+ s === null || s === void 0 ? void 0 : s.enqueueSnackbar(message, __assign({ autoHideDuration: autoHideDuration !== undefined ? autoHideDuration : _this._dialogOptions.snackbar.autoHideDuration, variant: severity,
818
+ // maxSnack: this._dialogOptions.snackbar.maxSnack,
819
+ key: key !== null && key !== void 0 ? key : sId, anchorOrigin: {
820
+ vertical: _this._dialogOptions.snackbar.anchorOrigin.vertical,
821
+ horizontal: _this._dialogOptions.snackbar.anchorOrigin.horizontal,
822
+ } }, action ? { action: function (key) {
823
+ return action(key, s);
824
+ } } : {}));
825
+ };
826
+ var open = function (message, severity, key, action, autoHideDuration) {
827
+ openMe(message, severity, key, action, autoHideDuration);
828
+ };
829
+ var openX = function (_a) {
830
+ var message = _a.message, severity = _a.severity, key = _a.key, action = _a.action, autoHideDuration = _a.autoHideDuration;
831
+ openMe(message, severity, key, action, autoHideDuration);
832
+ };
833
+ var close = function (key) {
834
+ s === null || s === void 0 ? void 0 : s.closeSnackbar(key);
835
+ };
836
+ return {
837
+ open: open,
838
+ openX: openX,
839
+ close: close
840
+ };
841
+ },
842
+ enumerable: false,
843
+ configurable: true
844
+ });
845
+ DialogBase.prototype.show = function (callback) {
846
+ console.log('this._actions', this._actions);
847
+ this._dom = document.createElement('div');
848
+ this._dom.setAttribute('role', 'presentation');
849
+ this._dom.classList.add('appinsource-dialog-root');
850
+ document.body.appendChild(this._dom);
851
+ var root = (0, client_1.createRoot)(this._dom);
852
+ var props = {
853
+ ref: this._innerRef,
854
+ options: this._dialogOptions,
855
+ header: this._header,
856
+ body: this._body,
857
+ actions: this._actions,
858
+ stateListener: this._stateListener,
859
+ dialogSize: this._dialogSize,
860
+ didMountCallback: callback,
861
+ keyboardListener: this._keyboardListener,
862
+ /**Dialog order with Reference Element, like before-after-same reference*/
863
+ order: this._order,
864
+ // initialState: this._initialState,
865
+ // initialValues: this._initialValues,
866
+ // initialUserProps: this._initialUserProps,
867
+ initialValues: this._initialValues,
868
+ initialHolder: this._initialHolder,
869
+ snackbarAnchor: this._snackbarAnchor,
870
+ dom: this._dom,
871
+ parent: this,
872
+ onClose: this._onClose,
873
+ root: root,
874
+ };
875
+ // @ts-ignore
876
+ root.render(React.createElement(DialogBase, props));
877
+ };
878
+ return DialogBase;
879
+ }(react_1.Component));
880
+ exports.default = DialogBase;