@progress/kendo-react-dialogs 13.4.0-develop.1 → 13.4.0-develop.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Window.mjs CHANGED
@@ -5,415 +5,524 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import * as r from "react";
9
- import * as H from "react-dom";
10
- import n from "prop-types";
11
- import { WindowTitleBar as N } from "./WindowTitlebar.mjs";
12
- import { withIdHOC as U, createPropsContext as z, withPropsContext as k, keepFocusInContainer as _, Keys as a, dispatchEvent as g, canUseDOM as S, ZIndexContext as A, classNames as Z, Draggable as O } from "@progress/kendo-react-common";
13
- import { ResizeHandlers as K } from "./WindowResizeHandlers.mjs";
14
- import { MiddleLayerOptimization as P } from "./MiddleLayerOptimization.mjs";
15
- import { windowStage as i } from "./StageEnum.mjs";
16
- import { WindowActionsBar as B } from "./WindowActionsBar.mjs";
17
- import { DEFAULT_DIALOGS_ZINDEX as v, ZINDEX_DIALOGS_STEP as R, DATA_DIALOGS_ID as X } from "./constants.mjs";
18
- import { getMaxZIndex as x } from "./utils.mjs";
19
- const E = 300, C = 300, D = 120, T = 100, l = 5, u = class u extends r.Component {
20
- constructor(s) {
21
- super(s), this.context = 0, this.draggable = null, this.offSetCoordinates = { x: 0, y: 0 }, this.titleId = this.generateTitleId(), this.mounted = !1, this.activeElement = null, this.onKeyDown = (t) => {
22
- var p, w, m;
23
- if (this.props.modal && _(t, this.element), t.target !== t.currentTarget)
8
+ import * as w from "react";
9
+ import * as ut from "react-dom";
10
+ import * as i from "prop-types";
11
+ import { WindowTitleBar as ft } from "./WindowTitlebar.mjs";
12
+ import { withIdHOC as ht, createPropsContext as gt, withPropsContext as st, ZIndexContext as Ze, canUseDOM as le, keepFocusInContainer as mt, Keys as E, dispatchEvent as v, classNames as wt, Draggable as Tt } from "@progress/kendo-react-common";
13
+ import { ResizeHandlers as Et } from "./WindowResizeHandlers.mjs";
14
+ import { MiddleLayerOptimization as Ct } from "./MiddleLayerOptimization.mjs";
15
+ import { windowStage as o } from "./StageEnum.mjs";
16
+ import { WindowActionsBar as _e } from "./WindowActionsBar.mjs";
17
+ import { DEFAULT_DIALOGS_ZINDEX as Pe, ZINDEX_DIALOGS_STEP as Ke, DATA_DIALOGS_ID as Lt } from "./constants.mjs";
18
+ import { getMaxZIndex as Xe } from "./utils.mjs";
19
+ const { useState: H, useEffect: N, useCallback: d, useMemo: K, useRef: F, useImperativeHandle: Dt, useContext: It, forwardRef: bt } = w, Q = 300, p = 300, me = 120, we = 100, I = 5, U = {
20
+ minWidth: me,
21
+ minHeight: we,
22
+ resizable: !0,
23
+ draggable: !0,
24
+ modal: !1,
25
+ doubleClickStageChange: !0,
26
+ autoFocus: !0
27
+ }, Ge = bt((e, k) => {
28
+ var ve;
29
+ const {
30
+ minWidth: de = U.minWidth,
31
+ minHeight: ue = U.minHeight,
32
+ resizable: fe = U.resizable,
33
+ draggable: Te = U.draggable,
34
+ modal: he = U.modal,
35
+ doubleClickStageChange: Ye = U.doubleClickStageChange,
36
+ autoFocus: je = U.autoFocus
37
+ } = e, [$e, X] = H(e.stage || o.DEFAULT), [G, ee] = H(!1), [te, b] = H(0), [ne, W] = H(0), [ie, M] = H(Q), [oe, S] = H(p), [qe, ge] = H(!0), [se, Ee] = H(Pe), a = (ve = e.stage) != null ? ve : $e, A = It(Ze), B = F(null), Ce = F(null), h = F({
38
+ leftBeforeAction: 0,
39
+ topBeforeAction: 0,
40
+ widthBeforeAction: Q,
41
+ heightBeforeAction: p
42
+ }), x = F({ x: 0, y: 0 }), z = F(void 0), V = F(
43
+ le ? document.activeElement : null
44
+ ), Le = F("window-title-" + (e.id ? e.id + "-accessibility-id" : "")), O = F({
45
+ left: 0,
46
+ top: 0,
47
+ width: Q,
48
+ height: p,
49
+ internalLeft: ne,
50
+ internalTop: te,
51
+ internalWidth: ie,
52
+ internalHeight: oe,
53
+ stage: a,
54
+ draggable: Te,
55
+ props: e
56
+ }), R = d(() => {
57
+ const t = le ? document : null;
58
+ return e.appendTo ? e.appendTo.ownerDocument : t;
59
+ }, [e.appendTo]), s = d(() => {
60
+ const t = R();
61
+ return t == null ? void 0 : t.defaultView;
62
+ }, [R]), Z = K(() => {
63
+ var t;
64
+ return a !== o.FULLSCREEN ? Math.max((t = e.top) != null ? t : te, 0) : 0;
65
+ }, [a, e.top, te]), _ = K(() => {
66
+ var t;
67
+ return a !== o.FULLSCREEN ? Math.max((t = e.left) != null ? t : ne, 0) : 0;
68
+ }, [a, e.left, ne]), C = K(() => {
69
+ var n;
70
+ const t = (n = e.width) != null ? n : ie;
71
+ if (a === o.FULLSCREEN) {
72
+ if (e.appendTo)
73
+ return e.appendTo.offsetWidth;
74
+ const r = s();
75
+ return r ? r.innerWidth : 0;
76
+ }
77
+ return t;
78
+ }, [a, e.width, e.appendTo, ie, s]), L = K(() => {
79
+ const t = e.height === void 0 ? oe : e.height;
80
+ if (a === o.FULLSCREEN) {
81
+ if (e.appendTo)
82
+ return e.appendTo.offsetHeight;
83
+ const n = s();
84
+ return n ? n.innerHeight : 0;
85
+ } else if (a === o.MINIMIZED)
86
+ return 0;
87
+ return t;
88
+ }, [a, e.height, e.appendTo, oe, s]), re = K(() => e.id ? e.id + "-accessibility-id" : void 0, [e.id]);
89
+ N(() => {
90
+ O.current = {
91
+ left: _,
92
+ top: Z,
93
+ width: C,
94
+ height: L,
95
+ internalLeft: ne,
96
+ internalTop: te,
97
+ internalWidth: ie,
98
+ internalHeight: oe,
99
+ stage: a,
100
+ draggable: Te,
101
+ props: e
102
+ };
103
+ });
104
+ const P = K(() => {
105
+ if (A === void 0)
106
+ return A != null ? A : Pe;
107
+ const t = A ? A + Ke : 0;
108
+ return se > t ? se : A + Ke;
109
+ }, [se, A]), De = d(() => {
110
+ var r, l;
111
+ if (e.top !== void 0)
112
+ return e.top;
113
+ if (e.initialTop !== void 0)
114
+ return e.initialTop;
115
+ let t = p;
116
+ if (e.height !== void 0 ? t = e.height : e.initialHeight !== void 0 && (t = e.initialHeight), e.appendTo && t)
117
+ return e.appendTo.offsetHeight / 2 - t / 2;
118
+ const n = s();
119
+ return n ? n.innerHeight / 2 - ((l = t != null ? t : (r = B.current) == null ? void 0 : r.clientHeight) != null ? l : 0) / 2 : 0;
120
+ }, [e.top, e.initialTop, e.height, e.initialHeight, e.appendTo, s]), Ie = d(() => {
121
+ if (e.left !== void 0)
122
+ return e.left;
123
+ if (e.initialLeft !== void 0)
124
+ return e.initialLeft;
125
+ let t = Q;
126
+ if (e.width !== void 0 ? t = e.width : e.initialWidth !== void 0 && (t = e.initialWidth), e.appendTo)
127
+ return e.appendTo.offsetWidth / 2 - t / 2;
128
+ const n = s();
129
+ return n ? n.innerWidth / 2 - t / 2 : 0;
130
+ }, [e.left, e.initialLeft, e.width, e.initialWidth, e.appendTo, s]), be = d(() => {
131
+ let t = Q;
132
+ return e.width !== void 0 ? t = e.width : e.initialWidth !== void 0 && (t = e.initialWidth), t;
133
+ }, [e.width, e.initialWidth]), We = d(() => {
134
+ let t = p;
135
+ return e.height !== void 0 ? t = e.height : e.initialHeight !== void 0 && (t = e.initialHeight), t;
136
+ }, [e.height, e.initialHeight]), Je = d((t) => t.filter((n) => (n == null ? void 0 : n.type) === _e), []), Qe = d((t) => t.filter((n) => n && n.type !== _e), []), m = d(() => typeof k == "object" && k !== null && "current" in k ? k.current : null, [k]), y = d(
137
+ (t, n, r, l, c, u) => {
138
+ var j, $, q;
139
+ if (!t)
140
+ return;
141
+ const {
142
+ internalLeft: T,
143
+ internalTop: g,
144
+ internalWidth: D,
145
+ internalHeight: ce
146
+ } = O.current;
147
+ t({
148
+ nativeEvent: n.nativeEvent ? n.nativeEvent : n.originalEvent,
149
+ drag: r,
150
+ end: l,
151
+ target: m(),
152
+ left: (j = c == null ? void 0 : c.left) != null ? j : T,
153
+ top: ($ = c == null ? void 0 : c.top) != null ? $ : g,
154
+ width: (q = u == null ? void 0 : u.width) != null ? q : D,
155
+ height: (u == null ? void 0 : u.height) === void 0 ? ce : u == null ? void 0 : u.height
156
+ });
157
+ },
158
+ [m]
159
+ ), pe = d(
160
+ (t) => {
161
+ var u, T;
162
+ if (he && mt(t, B.current), t.target !== t.currentTarget)
24
163
  return;
25
- const e = this.props.minWidth || D, o = this.props.minHeight || T, h = t.metaKey || t.ctrlKey, c = (m = (w = this.height) != null ? w : (p = this.windowElement) == null ? void 0 : p.clientHeight) != null ? m : 0;
26
- if (h && this.props.resizable) {
164
+ const n = de || me, r = ue || we, l = t.metaKey || t.ctrlKey, c = (T = L != null ? L : (u = B.current) == null ? void 0 : u.clientHeight) != null ? T : 0;
165
+ if (l && fe) {
27
166
  switch (t.keyCode) {
28
- case a.up:
29
- t.preventDefault(), o <= c - l && this.setState({ height: c - l });
167
+ case E.up:
168
+ t.preventDefault(), r <= c - I && S(c - I);
30
169
  break;
31
- case a.down:
32
- t.preventDefault(), this.setState({ height: c + l });
170
+ case E.down:
171
+ t.preventDefault(), S(c + I);
33
172
  break;
34
- case a.left:
35
- e <= this.width - l && this.setState({ width: this.width - l });
173
+ case E.left:
174
+ n <= C - I && M(C - I);
36
175
  break;
37
- case a.right:
38
- this.setState({ width: this.width + l });
176
+ case E.right:
177
+ M(C + I);
39
178
  break;
40
179
  default:
41
180
  return;
42
181
  }
43
- this.dispatchMoveEvent(this.props.onResize, t, !1, void 0);
182
+ y(e.onResize, t, !1, void 0);
44
183
  return;
45
184
  }
46
185
  if (t.altKey) {
47
186
  switch (t.keyCode) {
48
- case a.up:
49
- this.windowStage === i.MINIMIZED ? (this.handleRestore(t), g(this.props.onStageChange, t, this, { state: i.DEFAULT })) : this.windowStage === i.DEFAULT && (this.handleFullscreen(t), g(this.props.onStageChange, t, this, { state: i.FULLSCREEN }));
187
+ case E.up:
188
+ a === o.MINIMIZED ? (Y(t), v(e.onStageChange, t, m(), {
189
+ state: o.DEFAULT
190
+ })) : a === o.DEFAULT && (ae(t), v(e.onStageChange, t, m(), {
191
+ state: o.FULLSCREEN
192
+ }));
50
193
  break;
51
- case a.down:
52
- this.windowStage === i.FULLSCREEN ? (this.handleRestore(t), g(this.props.onStageChange, t, this, { state: i.DEFAULT })) : this.windowStage === i.DEFAULT && (this.handleMinimize(t), g(this.props.onStageChange, t, this, { state: i.MINIMIZED }));
194
+ case E.down:
195
+ a === o.FULLSCREEN ? (Y(t), v(e.onStageChange, t, m(), {
196
+ state: o.DEFAULT
197
+ })) : a === o.DEFAULT && (Se(t), v(e.onStageChange, t, m(), {
198
+ state: o.MINIMIZED
199
+ }));
53
200
  break;
54
201
  }
55
202
  return;
56
203
  }
57
204
  if (!t.ctrlKey)
58
205
  switch (t.keyCode) {
59
- case a.esc:
60
- this.props.onClose && this.handleCloseWindow(t);
206
+ case E.esc:
207
+ e.onClose && ye(t);
61
208
  return;
62
- case a.up:
63
- this.setState((d) => ({ top: d.top - l }));
209
+ case E.up:
210
+ b((g) => g - I);
64
211
  break;
65
- case a.down:
66
- this.setState((d) => ({ top: d.top + l }));
212
+ case E.down:
213
+ b((g) => g + I);
67
214
  break;
68
- case a.left:
69
- this.setState((d) => ({ left: d.left - l }));
215
+ case E.left:
216
+ W((g) => g - I);
70
217
  break;
71
- case a.right:
72
- this.setState((d) => ({ left: d.left + l }));
218
+ case E.right:
219
+ W((g) => g + I);
73
220
  break;
74
221
  default:
75
222
  return;
76
223
  }
77
- this.dispatchMoveEvent(this.props.onMove, t, !1, void 0);
78
- }, this.onPress = (t) => {
79
- const e = t.event;
80
- this.windowCoordinatesState.differenceLeft = e.pageX - this.left, this.windowCoordinatesState.differenceTop = e.pageY - this.top;
81
- }, this.onDrag = (t) => {
82
- const e = t.event;
83
- e.originalEvent.preventDefault(), this.windowStage !== i.FULLSCREEN && this.props.draggable && (this.setState({
84
- top: Math.max(e.pageY - this.windowCoordinatesState.differenceTop, 0),
85
- left: e.pageX - this.windowCoordinatesState.differenceLeft,
86
- isDragging: !0
87
- }), this.props.onMove && this.dispatchMoveEvent(this.props.onMove, e, !0, !1));
88
- }, this.onRelease = (t) => {
89
- const e = t.event;
90
- this.windowStage !== i.FULLSCREEN && this.props.draggable && this.props.onMove && this.dispatchMoveEvent(this.props.onMove, e, !0, !0), this.setState({
91
- isDragging: !1
92
- });
93
- }, this.onFocus = () => {
94
- this._blurTimeout ? (clearTimeout(this._blurTimeout), this._blurTimeout = void 0) : this.setState({
95
- focused: !0,
96
- zIndex: x(this.getCurrentZIndex(), this.getDocument(), this._id)
97
- });
98
- }, this.onBlur = () => {
99
- clearTimeout(this._blurTimeout);
100
- const t = this.getWindow();
101
- t && (this._blurTimeout = t.setTimeout(() => {
102
- this.mounted && this.setState({ focused: !1 }), this._blurTimeout = void 0;
103
- }));
104
- }, this.getInitialTop = () => {
105
- var o, h;
106
- if (this.props.top !== void 0)
107
- return this.props.top;
108
- if (this.props.initialTop !== void 0)
109
- return this.props.initialTop;
110
- let t = C;
111
- if (this.props.height !== void 0 ? t = this.props.height : this.props.initialHeight !== void 0 && (t = this.props.initialHeight), this.props.appendTo && t)
112
- return this.props.appendTo.offsetHeight / 2 - t / 2;
113
- const e = this.getWindow();
114
- return e ? e.innerHeight / 2 - ((h = t != null ? t : (o = this.windowElement) == null ? void 0 : o.clientHeight) != null ? h : 0) / 2 : 0;
115
- }, this.getInitialLeft = () => {
116
- if (this.props.left !== void 0)
117
- return this.props.left;
118
- if (this.props.initialLeft !== void 0)
119
- return this.props.initialLeft;
120
- let t = E;
121
- if (this.props.width !== void 0 ? t = this.props.width : this.props.initialWidth !== void 0 && (t = this.props.initialWidth), this.props.appendTo)
122
- return this.props.appendTo.offsetWidth / 2 - t / 2;
123
- const e = this.getWindow();
124
- return e ? e.innerWidth / 2 - t / 2 : 0;
125
- }, this.getInitialWidth = () => {
126
- let t = E;
127
- return this.props.width !== void 0 ? t = this.props.width : this.props.initialWidth !== void 0 && (t = this.props.initialWidth), t;
128
- }, this.getInitialHeight = () => {
129
- let t = C;
130
- return this.props.height !== void 0 ? t = this.props.height : this.props.initialHeight !== void 0 && (t = this.props.initialHeight), t;
131
- }, this.handleMinimize = (t) => {
132
- t.preventDefault(), this.windowCoordinatesState.leftBeforeAction = this.left, this.windowCoordinatesState.topBeforeAction = this.top, this.windowCoordinatesState.widthBeforeAction = this.width, this.windowCoordinatesState.heightBeforeAction = this.height, this.setState({
133
- stage: i.MINIMIZED,
134
- height: 0
135
- }), g(this.props.onStageChange, t, this, { state: i.MINIMIZED });
136
- }, this.handleFullscreen = (t) => {
137
- t.preventDefault(), this.windowCoordinatesState.leftBeforeAction = this.left, this.windowCoordinatesState.topBeforeAction = this.top, this.windowCoordinatesState.widthBeforeAction = this.width, this.windowCoordinatesState.heightBeforeAction = this.height;
138
- const e = this.getWindow(), o = e ? e.innerWidth : 0, h = e ? e.innerHeight : 0;
139
- this.setState({
140
- left: 0,
141
- top: 0,
142
- width: this.props.appendTo ? this.props.appendTo.offsetWidth : o,
143
- height: this.props.appendTo ? this.props.appendTo.offsetHeight : h,
144
- stage: i.FULLSCREEN
145
- }), g(this.props.onStageChange, t, this, { state: i.FULLSCREEN });
146
- }, this.handleRestore = (t) => {
147
- t.preventDefault(), this.windowStage === i.FULLSCREEN ? this.setState({
148
- stage: i.DEFAULT,
149
- left: this.windowCoordinatesState.leftBeforeAction,
150
- top: this.windowCoordinatesState.topBeforeAction,
151
- width: this.windowCoordinatesState.widthBeforeAction,
152
- height: this.windowCoordinatesState.heightBeforeAction
153
- }) : this.windowStage === i.MINIMIZED && this.setState({
154
- stage: i.DEFAULT,
155
- height: this.windowCoordinatesState.heightBeforeAction
156
- }), g(this.props.onStageChange, t, this, { state: i.DEFAULT });
157
- }, this.handleCloseWindow = (t) => {
158
- t.preventDefault(), g(this.props.onClose, t, this, { state: void 0 });
159
- }, this.handleDoubleClick = (t) => {
160
- this.windowStage === i.FULLSCREEN || this.windowStage === i.MINIMIZED ? this.handleRestore(t) : this.handleFullscreen(t);
161
- }, this.handleResize = (t, e) => {
162
- var M, F, y;
163
- const o = this.props.appendTo ? t.pageX - this.offSetCoordinates.x : t.pageX, h = this.props.appendTo ? t.pageY - this.offSetCoordinates.y : t.pageY, c = this.width, p = (y = (F = this.height) != null ? F : (M = this.windowElement) == null ? void 0 : M.clientHeight) != null ? y : 0, w = this.props.minWidth || D, m = this.props.minHeight || T, d = this.top - h, L = this.left - o, b = o - this.left, W = h - this.top, f = Object.assign({}, this.state, { isDragging: !e.end });
164
- e.direction.indexOf("n") >= 0 && m - (p + d) < 0 && (this.top > 0 && (f.height = p + d), f.top = h), e.direction.indexOf("s") >= 0 && m - W < 0 && (f.height = W), e.direction.indexOf("w") >= 0 && w - (c + L) < 0 && (this.left > 0 && (f.width = c + L), f.left = o), e.direction.indexOf("e") >= 0 && w - b < 0 && (f.width = b), this.setState(f), this.dispatchMoveEvent(this.props.onResize, t, !0, e.end);
165
- }, this.dispatchMoveEvent = (t, e, o, h) => {
166
- t && t.call(void 0, {
167
- nativeEvent: e.nativeEvent ? e.nativeEvent : e.originalEvent,
168
- drag: o,
169
- end: h,
170
- target: this,
171
- left: this.state.left,
172
- top: this.state.top,
173
- width: this.state.width,
174
- hight: this.state.height,
175
- height: this.state.height
176
- });
177
- }, this.handleBrowserWindowResize = () => {
178
- if (this.windowStage === i.FULLSCREEN) {
179
- const t = this.getWindow(), e = t ? t.innerWidth : 0, o = t ? t.innerHeight : 0;
180
- this.setState({
181
- width: this.props.appendTo ? this.props.appendTo.offsetWidth : e,
182
- height: this.props.appendTo ? this.props.appendTo.offsetHeight : o
183
- });
224
+ y(e.onMove, t, !1, void 0);
225
+ },
226
+ // eslint-disable-next-line react-hooks/exhaustive-deps
227
+ [
228
+ he,
229
+ de,
230
+ ue,
231
+ fe,
232
+ e.onResize,
233
+ e.onStageChange,
234
+ e.onClose,
235
+ e.onMove,
236
+ L,
237
+ C,
238
+ a,
239
+ y,
240
+ m
241
+ ]
242
+ ), et = d((t) => {
243
+ const n = t.event, { left: r, top: l } = O.current;
244
+ h.current.differenceLeft = n.pageX - r, h.current.differenceTop = n.pageY - l;
245
+ }, []), tt = d(
246
+ (t) => {
247
+ const n = t.event;
248
+ n.originalEvent.preventDefault();
249
+ const {
250
+ stage: r,
251
+ draggable: l,
252
+ props: c,
253
+ width: u,
254
+ height: T
255
+ } = O.current;
256
+ if (r !== o.FULLSCREEN && l) {
257
+ const g = Math.max(n.pageY - (h.current.differenceTop || 0), 0), D = n.pageX - (h.current.differenceLeft || 0);
258
+ b(g), W(D), ee(!0), c.onMove && y(
259
+ c.onMove,
260
+ n,
261
+ !0,
262
+ !1,
263
+ { left: D, top: g },
264
+ { width: u, height: T }
265
+ );
184
266
  }
185
- }, this.getCurrentZIndex = () => !this.state || this.context === void 0 ? this.context ? this.context : v : this.state.zIndex > (this.context ? this.context + R : 0) ? this.state.zIndex : this.context + R, this.getDocument = () => {
186
- const t = S ? document : null;
187
- return this.props.appendTo ? this.props.appendTo.ownerDocument : t;
188
- }, this.getWindow = () => {
189
- const t = this.getDocument();
190
- return t && t.defaultView;
191
- }, this.state = {
192
- stage: this.props.stage || i.DEFAULT,
193
- isDragging: !1,
194
- top: 0,
195
- left: 0,
196
- width: E,
197
- height: C,
198
- focused: !0,
199
- zIndex: v
200
- }, S && (this.activeElement = document.activeElement);
201
- }
202
- get _id() {
203
- return this.props.id + "-accessibility-id";
204
- }
205
- /**
206
- * @hidden
207
- */
208
- componentDidMount() {
209
- this.element && this.props.autoFocus && this.element.focus({ preventScroll: !0 });
210
- const s = this.getWindow();
211
- s && s.addEventListener("resize", this.handleBrowserWindowResize), this.setState({
212
- stage: this.props.stage || i.DEFAULT,
213
- isDragging: !1,
214
- top: this.getInitialTop(),
215
- left: this.getInitialLeft(),
216
- width: this.getInitialWidth(),
217
- height: this.getInitialHeight(),
218
- focused: !0,
219
- zIndex: x(this.getCurrentZIndex(), this.getDocument(), this._id)
220
- }), this.windowCoordinatesState = {
221
- leftBeforeAction: this.getInitialLeft(),
222
- topBeforeAction: this.getInitialTop(),
223
- widthBeforeAction: this.getInitialWidth(),
224
- heightBeforeAction: this.getInitialHeight()
267
+ },
268
+ [y]
269
+ ), nt = d(
270
+ (t) => {
271
+ const n = t.event, {
272
+ stage: r,
273
+ draggable: l,
274
+ props: c,
275
+ left: u,
276
+ top: T,
277
+ width: g,
278
+ height: D
279
+ } = O.current;
280
+ r !== o.FULLSCREEN && l && c.onMove && y(
281
+ c.onMove,
282
+ n,
283
+ !0,
284
+ !0,
285
+ { left: u, top: T },
286
+ { width: g, height: D }
287
+ ), ee(!1);
288
+ },
289
+ [y]
290
+ ), it = d(() => {
291
+ z.current ? (clearTimeout(z.current), z.current = void 0) : (ge(!0), Ee(Xe(P, R(), re)));
292
+ }, [P, R, re]), ot = d(() => {
293
+ clearTimeout(z.current);
294
+ const t = s();
295
+ t && (z.current = t.setTimeout(() => {
296
+ ge(!1), z.current = void 0;
297
+ }));
298
+ }, [s]), Se = d(
299
+ (t) => {
300
+ t.preventDefault(), h.current.leftBeforeAction = _, h.current.topBeforeAction = Z, h.current.widthBeforeAction = C, h.current.heightBeforeAction = L, X(o.MINIMIZED), S(0), v(e.onStageChange, t, m(), { state: o.MINIMIZED });
301
+ },
302
+ [_, Z, C, L, e.onStageChange, m]
303
+ ), ae = d(
304
+ (t) => {
305
+ t.preventDefault(), h.current.leftBeforeAction = _, h.current.topBeforeAction = Z, h.current.widthBeforeAction = C, h.current.heightBeforeAction = L;
306
+ const n = s(), r = n ? n.innerWidth : 0, l = n ? n.innerHeight : 0;
307
+ W(0), b(0), M(e.appendTo ? e.appendTo.offsetWidth : r), S(e.appendTo ? e.appendTo.offsetHeight : l), X(o.FULLSCREEN), v(e.onStageChange, t, m(), { state: o.FULLSCREEN });
308
+ },
309
+ [_, Z, C, L, e.appendTo, e.onStageChange, s, m]
310
+ ), Y = d(
311
+ (t) => {
312
+ t.preventDefault(), a === o.FULLSCREEN ? (X(o.DEFAULT), W(h.current.leftBeforeAction), b(h.current.topBeforeAction), M(h.current.widthBeforeAction), S(h.current.heightBeforeAction)) : a === o.MINIMIZED && (X(o.DEFAULT), S(h.current.heightBeforeAction)), v(e.onStageChange, t, m(), { state: o.DEFAULT });
313
+ },
314
+ [a, e.onStageChange, m]
315
+ ), ye = d(
316
+ (t) => {
317
+ t.preventDefault(), v(e.onClose, t, m(), { state: void 0 });
318
+ },
319
+ [e.onClose, m]
320
+ ), rt = d(
321
+ (t) => {
322
+ a === o.FULLSCREEN || a === o.MINIMIZED ? Y(t) : ae(t);
323
+ },
324
+ [a, Y, ae]
325
+ ), at = d(
326
+ (t, n) => {
327
+ var Ne, Ue, ke, xe, ze, Oe;
328
+ const {
329
+ props: r,
330
+ width: l,
331
+ height: c,
332
+ top: u,
333
+ left: T
334
+ } = O.current, g = r.appendTo ? t.pageX - x.current.x : t.pageX, D = r.appendTo ? t.pageY - x.current.y : t.pageY, ce = (Ue = c != null ? c : (Ne = B.current) == null ? void 0 : Ne.clientHeight) != null ? Ue : 0, j = de || me, $ = ue || we, q = u - D, He = T - g, Fe = g - T, Me = D - u;
335
+ let J = !1;
336
+ const f = {
337
+ isDragging: !n.end
338
+ };
339
+ n.direction.indexOf("n") >= 0 && $ - (ce + q) < 0 && (u > 0 && (f.height = ce + q), f.top = D, J = !0), n.direction.indexOf("s") >= 0 && $ - Me < 0 && (f.height = Me, J = !0), n.direction.indexOf("w") >= 0 && j - (l + He) < 0 && (T > 0 && (f.width = l + He), f.left = g, J = !0), n.direction.indexOf("e") >= 0 && j - Fe < 0 && (f.width = Fe, J = !0), J && (f.height !== void 0 && S(f.height), f.top !== void 0 && b(f.top), f.width !== void 0 && M(f.width), f.left !== void 0 && W(f.left), f.isDragging !== void 0 && ee(f.isDragging)), y(
340
+ r.onResize,
341
+ t,
342
+ !0,
343
+ n.end,
344
+ { left: (ke = f.left) != null ? ke : T, top: (xe = f.top) != null ? xe : u },
345
+ { width: (ze = f.width) != null ? ze : l, height: (Oe = f.height) != null ? Oe : c }
346
+ );
347
+ },
348
+ [y]
349
+ ), Ae = d(() => {
350
+ if (a === o.FULLSCREEN) {
351
+ const t = s(), n = t ? t.innerWidth : 0, r = t ? t.innerHeight : 0;
352
+ M(e.appendTo ? e.appendTo.offsetWidth : n), S(e.appendTo ? e.appendTo.offsetHeight : r);
353
+ }
354
+ }, [a, e.appendTo, s]);
355
+ N(() => {
356
+ const t = B.current;
357
+ t && je && t.focus({ preventScroll: !0 });
358
+ const n = s();
359
+ n && n.addEventListener("resize", Ae), X(e.stage || o.DEFAULT), ee(!1), b(De()), W(Ie()), M(be()), S(We()), ge(!0), Ee(Xe(P, R(), re)), h.current = {
360
+ leftBeforeAction: Ie(),
361
+ topBeforeAction: De(),
362
+ widthBeforeAction: be(),
363
+ heightBeforeAction: We()
225
364
  };
226
- const t = this.getDocument();
227
- if (this.props.appendTo && t) {
228
- const e = this.props.appendTo.getBoundingClientRect(), o = t.body.getBoundingClientRect();
229
- this.offSetCoordinates.x = e.left - o.left, this.offSetCoordinates.y = e.top - o.top;
365
+ const r = R();
366
+ if (e.appendTo && r) {
367
+ const l = e.appendTo.getBoundingClientRect(), c = r.body.getBoundingClientRect();
368
+ x.current.x = l.left - c.left, x.current.y = l.top - c.top;
230
369
  }
231
- this.mounted = !0;
232
- }
233
- /**
234
- * @hidden
235
- */
236
- componentWillUnmount() {
237
- const s = this.getWindow();
238
- s && s.removeEventListener("resize", this.handleBrowserWindowResize), this.mounted = !1, setTimeout(() => {
239
- var t;
240
- !this.element && this.activeElement && S && (document.contains(this.activeElement) ? this.activeElement.focus({ preventScroll: !0 }) : this.activeElement.id && ((t = document.getElementById(this.activeElement.id)) == null || t.focus({ preventScroll: !0 })));
241
- });
242
- }
243
- /**
244
- * @hidden
245
- */
246
- componentDidUpdate(s) {
247
- this.props.left && s.left !== this.props.left && this.setState({ left: this.props.left }), this.props.top && s.top !== this.props.top && this.setState({ top: this.props.top }), this.props.initialLeft && s.initialLeft !== this.props.initialLeft && this.setState({ left: this.props.initialLeft }), this.props.initialTop && s.initialTop !== this.props.initialTop && this.setState({ top: this.props.initialTop });
248
- const t = this.getDocument();
249
- if (this.props.appendTo && t) {
250
- const e = this.props.appendTo.getBoundingClientRect(), o = t.body.getBoundingClientRect();
251
- this.offSetCoordinates.x = e.left - o.left, this.offSetCoordinates.y = e.top - o.top;
370
+ return () => {
371
+ var c;
372
+ const l = s();
373
+ l && l.removeEventListener("resize", Ae), V.current && le && (document.contains(V.current) ? V.current.focus({ preventScroll: !0 }) : V.current.id && ((c = document.getElementById(V.current.id)) == null || c.focus({ preventScroll: !0 })));
374
+ };
375
+ }, []), N(() => {
376
+ e.left !== void 0 && !G && W(e.left);
377
+ }, [e.left, G]), N(() => {
378
+ e.top !== void 0 && !G && b(e.top);
379
+ }, [e.top, G]), N(() => {
380
+ e.initialLeft !== void 0 && W(e.initialLeft);
381
+ }, [e.initialLeft]), N(() => {
382
+ e.initialTop !== void 0 && b(e.initialTop);
383
+ }, [e.initialTop]), N(() => {
384
+ const t = R();
385
+ if (e.appendTo && t) {
386
+ const n = e.appendTo.getBoundingClientRect(), r = t.body.getBoundingClientRect();
387
+ x.current.x = n.left - r.left, x.current.y = n.top - r.top;
252
388
  }
253
- this.mounted = !0;
254
- }
255
- /**
256
- * @hidden
257
- */
258
- render() {
259
- const s = r.Children.toArray(this.props.children), t = this.getContent(s), e = this.getActionBar(s), o = this.getCurrentZIndex(), h = Z("k-window", this.props.className, {
260
- [`k-window-${this.props.themeColor}`]: this.props.themeColor,
261
- "k-window-minimized": this.state.stage === "MINIMIZED",
262
- "k-focus": this.state.focused
263
- }), c = /* @__PURE__ */ r.createElement(A.Provider, { value: o }, /* @__PURE__ */ r.createElement(r.Fragment, null, this.props.modal && /* @__PURE__ */ r.createElement(
264
- "div",
265
- {
266
- className: "k-overlay",
267
- style: {
268
- zIndex: o,
269
- ...this.props.overlayStyle
270
- }
389
+ }, [e.appendTo, R]), Dt(
390
+ k,
391
+ () => ({
392
+ get element() {
393
+ return B.current;
394
+ },
395
+ get windowElement() {
396
+ return B.current;
397
+ },
398
+ get draggable() {
399
+ return Ce.current;
400
+ },
401
+ props: e
402
+ }),
403
+ [e]
404
+ );
405
+ const Be = w.Children.toArray(e.children), ct = Qe(Be), lt = Je(Be), dt = wt("k-window", e.className, {
406
+ [`k-window-${e.themeColor}`]: e.themeColor,
407
+ "k-window-minimized": a === "MINIMIZED",
408
+ "k-focus": qe
409
+ }), Re = /* @__PURE__ */ w.createElement(Ze.Provider, { value: P }, /* @__PURE__ */ w.createElement(w.Fragment, null, he && /* @__PURE__ */ w.createElement(
410
+ "div",
411
+ {
412
+ className: "k-overlay",
413
+ style: {
414
+ zIndex: P,
415
+ ...e.overlayStyle
416
+ }
417
+ }
418
+ ), /* @__PURE__ */ w.createElement(
419
+ "div",
420
+ {
421
+ id: e.id,
422
+ [Lt]: re,
423
+ tabIndex: 0,
424
+ role: "dialog",
425
+ "aria-labelledby": Le.current,
426
+ onFocus: it,
427
+ onBlur: ot,
428
+ onKeyDown: pe,
429
+ ref: B,
430
+ className: dt,
431
+ style: {
432
+ top: Z,
433
+ left: _,
434
+ width: C,
435
+ height: L || "",
436
+ zIndex: P,
437
+ ...e.style
271
438
  }
272
- ), /* @__PURE__ */ r.createElement(
273
- "div",
439
+ },
440
+ /* @__PURE__ */ w.createElement(
441
+ Ct,
274
442
  {
275
- id: this.props.id,
276
- [X]: this._id,
277
- tabIndex: 0,
278
- role: "dialog",
279
- "aria-labelledby": this.titleId,
280
- onFocus: this.onFocus,
281
- onBlur: this.onBlur,
282
- onKeyDown: this.onKeyDown,
283
- ref: (p) => {
284
- this.windowElement = p, this.element = p;
285
- },
286
- className: h,
287
- style: {
288
- top: this.top,
289
- left: this.left,
290
- width: this.width,
291
- height: this.height || "",
292
- zIndex: o,
293
- ...this.props.style
294
- }
443
+ shouldUpdateOnDrag: e.shouldUpdateOnDrag || !1,
444
+ isDragging: G
295
445
  },
296
- /* @__PURE__ */ r.createElement(
297
- P,
446
+ /* @__PURE__ */ w.createElement(
447
+ Tt,
298
448
  {
299
- shouldUpdateOnDrag: this.props.shouldUpdateOnDrag || !1,
300
- isDragging: this.state.isDragging
449
+ onPress: et,
450
+ onDrag: tt,
451
+ onRelease: nt,
452
+ autoScroll: !1,
453
+ ref: Ce
301
454
  },
302
- /* @__PURE__ */ r.createElement(
303
- O,
455
+ /* @__PURE__ */ w.createElement(
456
+ ft,
304
457
  {
305
- onPress: this.onPress,
306
- onDrag: this.onDrag,
307
- onRelease: this.onRelease,
308
- autoScroll: !1,
309
- ref: (p) => {
310
- this.draggable = p;
311
- }
458
+ stage: a,
459
+ onDoubleClick: Ye ? rt : void 0,
460
+ onMinimizeButtonClick: Se,
461
+ onFullScreenButtonClick: ae,
462
+ onRestoreButtonClick: Y,
463
+ onCloseButtonClick: ye,
464
+ closeButton: e.closeButton,
465
+ minimizeButton: e.minimizeButton,
466
+ maximizeButton: e.maximizeButton,
467
+ restoreButton: e.restoreButton,
468
+ id: Le.current
312
469
  },
313
- /* @__PURE__ */ r.createElement(
314
- N,
315
- {
316
- stage: this.windowStage,
317
- onDoubleClick: this.props.doubleClickStageChange ? this.handleDoubleClick : void 0,
318
- onMinimizeButtonClick: this.handleMinimize,
319
- onFullScreenButtonClick: this.handleFullscreen,
320
- onRestoreButtonClick: this.handleRestore,
321
- onCloseButtonClick: this.handleCloseWindow,
322
- closeButton: this.props.closeButton,
323
- minimizeButton: this.props.minimizeButton,
324
- maximizeButton: this.props.maximizeButton,
325
- restoreButton: this.props.restoreButton,
326
- id: this.titleId
327
- },
328
- this.props.title
329
- )
330
- ),
331
- this.windowStage !== i.MINIMIZED ? /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement("div", { className: "k-window-content" }, t), e) : null,
332
- this.windowStage === i.DEFAULT && this.props.resizable ? /* @__PURE__ */ r.createElement(K, { onResize: this.handleResize }) : null
333
- )
334
- )));
335
- return S ? this.props.appendTo !== null ? H.createPortal(c, this.props.appendTo || document.body) : c : null;
336
- }
337
- // Getters
338
- get top() {
339
- return this.windowStage !== i.FULLSCREEN ? Math.max(this.props.top || this.state.top, 0) : 0;
340
- }
341
- get left() {
342
- return this.windowStage !== i.FULLSCREEN ? Math.max(this.props.left || this.state.left, 0) : 0;
343
- }
344
- get width() {
345
- let s = this.props.width || this.state.width;
346
- if (this.windowStage === i.FULLSCREEN) {
347
- if (this.props.appendTo)
348
- return s = this.props.appendTo.offsetWidth, s;
349
- const t = this.getWindow();
350
- s = t ? t.innerWidth : 0;
351
- }
352
- return s;
353
- }
354
- get height() {
355
- let s = this.props.height || this.state.height;
356
- if (this.windowStage === i.FULLSCREEN) {
357
- if (this.props.appendTo)
358
- return s = this.props.appendTo.offsetHeight, s;
359
- const t = this.getWindow();
360
- s = t ? t.innerHeight : 0;
361
- } else this.windowStage === i.MINIMIZED && (s = 0);
362
- return s;
363
- }
364
- get windowStage() {
365
- return this.props.stage || this.state.stage;
366
- }
367
- getActionBar(s) {
368
- return s.filter((t) => t && t.type === B);
369
- }
370
- getContent(s) {
371
- return s.filter((t) => t && t.type !== B);
372
- }
373
- generateTitleId() {
374
- return "window-title-" + this._id;
375
- }
376
- };
377
- u.displayName = "Window", u.propTypes = {
378
- width: n.number,
379
- height: n.number,
380
- left: n.number,
381
- top: n.number,
382
- initialWidth: n.number,
383
- initialHeight: n.number,
384
- initialLeft: n.number,
385
- initialTop: n.number,
386
- minWidth: n.number,
387
- minHeight: n.number,
388
- resizable: n.bool,
389
- draggable: n.bool,
390
- title: n.any,
391
- shouldUpdateOnDrag: n.bool,
392
- stage: n.oneOf(["DEFAULT", "MINIMIZED", "FULLSCREEN"]),
393
- className: n.string,
394
- id: n.string,
395
- style: n.object,
396
- overlayStyle: n.object,
397
- autoFocus: n.bool
398
- }, u.defaultProps = {
399
- minWidth: D,
400
- minHeight: T,
401
- resizable: !0,
402
- draggable: !0,
403
- modal: !1,
404
- doubleClickStageChange: !0,
405
- autoFocus: !0
406
- }, u.contextType = A;
407
- let I = u;
408
- const G = z(), Y = U(
409
- k(
410
- G,
411
- I
470
+ e.title
471
+ )
472
+ ),
473
+ a === o.MINIMIZED ? null : /* @__PURE__ */ w.createElement(w.Fragment, null, /* @__PURE__ */ w.createElement("div", { className: "k-window-content" }, ct), lt),
474
+ a === o.DEFAULT && fe ? /* @__PURE__ */ w.createElement(Et, { onResize: at }) : null
475
+ )
476
+ )));
477
+ return le ? e.appendTo === null ? Re : ut.createPortal(Re, e.appendTo || document.body) : null;
478
+ });
479
+ Ge.displayName = "Window";
480
+ const Wt = gt(), Ve = ht(
481
+ st(
482
+ Wt,
483
+ Ge
412
484
  )
413
485
  );
414
- Y.displayName = "KendoReactWindow";
486
+ Ve.displayName = "KendoReactWindow";
487
+ const St = {
488
+ autoFocus: i.bool,
489
+ title: i.any,
490
+ className: i.string,
491
+ closeButton: i.func,
492
+ minimizeButton: i.func,
493
+ maximizeButton: i.func,
494
+ restoreButton: i.func,
495
+ modal: i.bool,
496
+ overlayStyle: i.object,
497
+ width: i.number,
498
+ height: i.number,
499
+ minWidth: i.number,
500
+ minHeight: i.number,
501
+ left: i.number,
502
+ top: i.number,
503
+ initialLeft: i.number,
504
+ initialTop: i.number,
505
+ initialWidth: i.number,
506
+ initialHeight: i.number,
507
+ resizable: i.bool,
508
+ draggable: i.bool,
509
+ doubleClickStageChange: i.bool,
510
+ stage: i.oneOf(["DEFAULT", "MINIMIZED", "FULLSCREEN"]),
511
+ onClose: i.func,
512
+ onMove: i.func,
513
+ onResize: i.func,
514
+ onStageChange: i.func,
515
+ children: i.node,
516
+ id: i.string,
517
+ dir: i.string,
518
+ style: i.object,
519
+ appendTo: i.any,
520
+ themeColor: i.oneOf(["primary", "dark", "light"]),
521
+ shouldUpdateOnDrag: i.bool
522
+ };
523
+ Ve.propTypes = St;
415
524
  export {
416
- Y as Window,
417
- G as WindowPropsContext,
418
- I as WindowWithoutContext
525
+ Ve as Window,
526
+ Wt as WindowPropsContext,
527
+ Ge as WindowWithoutContext
419
528
  };