@gustavolmo/react-window-manager 0.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.
- package/dist/index.css +546 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +674 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
// src/window-manager/window-store-factory.tsx
|
|
2
|
+
import { create } from "zustand";
|
|
3
|
+
var windowRegistry = {};
|
|
4
|
+
var createWindowStore = (windowId, bottomOffsetPx) => {
|
|
5
|
+
if (windowRegistry[windowId])
|
|
6
|
+
console.error("This store ID is already in use: " + windowId);
|
|
7
|
+
const zIndexAtLaunch = Object.keys(windowRegistry).length + 1;
|
|
8
|
+
const storeInstance = create((set, get) => ({
|
|
9
|
+
windowId,
|
|
10
|
+
isActive: false,
|
|
11
|
+
setIsActive: (isActive) => set({ isActive }),
|
|
12
|
+
resetFlag: false,
|
|
13
|
+
reset: () => set({ resetFlag: !get().resetFlag, isWinMinimized: true }),
|
|
14
|
+
zIndex: zIndexAtLaunch,
|
|
15
|
+
setZIndex: (newIndex) => set({ zIndex: newIndex }),
|
|
16
|
+
self: void 0,
|
|
17
|
+
setSelf: (ref) => set({ self: ref }),
|
|
18
|
+
winVisualState: "demaximized",
|
|
19
|
+
setWinVisualState: (newState) => set({ winVisualState: newState }),
|
|
20
|
+
isWinMinimized: true,
|
|
21
|
+
setIsWinMinimized: (isMini) => set({ isWinMinimized: isMini }),
|
|
22
|
+
dragClickOffset: { pointX: 0, pointY: 0 },
|
|
23
|
+
setDragClickOffset: (newCoord) => set({ dragClickOffset: { pointX: newCoord.pointX, pointY: newCoord.pointY } }),
|
|
24
|
+
isDragging: false,
|
|
25
|
+
setIsDragging: (updatedIsDragging) => set({ isDragging: updatedIsDragging }),
|
|
26
|
+
winCoord: { pointX: 40, pointY: 40 },
|
|
27
|
+
setWinCoord: (newWinCoord) => set({ winCoord: { pointX: newWinCoord.pointX, pointY: newWinCoord.pointY } }),
|
|
28
|
+
isResizing: false,
|
|
29
|
+
setIsResizing: (updatedIsResizing) => set({ isResizing: updatedIsResizing }),
|
|
30
|
+
winWidth: window.innerWidth * 0.95,
|
|
31
|
+
setWinWidth: (newWinWidth) => set({ winWidth: newWinWidth }),
|
|
32
|
+
winHeight: window.innerHeight * 0.75,
|
|
33
|
+
setWinHeight: (newWinHeight) => set({ winHeight: newWinHeight }),
|
|
34
|
+
stopDragAndResize: () => set({ isDragging: false, isResizing: false }),
|
|
35
|
+
maximizeWindow: () => {
|
|
36
|
+
set({
|
|
37
|
+
winCoord: { pointX: 0, pointY: 0 },
|
|
38
|
+
winHeight: window.innerHeight - bottomOffsetPx,
|
|
39
|
+
winWidth: window.innerWidth,
|
|
40
|
+
winVisualState: "maximized"
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
demaximizeWindow: () => {
|
|
44
|
+
set({
|
|
45
|
+
winCoord: { pointX: 40, pointY: 40 },
|
|
46
|
+
winWidth: window.innerWidth * 0.95,
|
|
47
|
+
winHeight: window.innerHeight * 0.75,
|
|
48
|
+
winVisualState: "demaximized"
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
minimizeWindow: () => set({ isWinMinimized: true }),
|
|
52
|
+
openWindow: () => {
|
|
53
|
+
const winRef = get().self;
|
|
54
|
+
if (get().isWinMinimized && winRef?.current) {
|
|
55
|
+
set({ isWinMinimized: false });
|
|
56
|
+
winRef.current.style.transform = "translate(0, 0) scale(1)";
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
dockWindowRight: () => {
|
|
60
|
+
set({
|
|
61
|
+
winCoord: { pointX: window.innerWidth / 2, pointY: 0 },
|
|
62
|
+
winWidth: window.innerWidth / 2,
|
|
63
|
+
winHeight: window.innerHeight - bottomOffsetPx,
|
|
64
|
+
winVisualState: "demaximized"
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
dockWindowLeft: () => {
|
|
68
|
+
set({
|
|
69
|
+
winCoord: { pointX: 0, pointY: 0 },
|
|
70
|
+
winWidth: window.innerWidth / 2,
|
|
71
|
+
winHeight: window.innerHeight - bottomOffsetPx,
|
|
72
|
+
winVisualState: "demaximized"
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
dockWindowBottomRight: () => set({
|
|
76
|
+
winCoord: {
|
|
77
|
+
pointX: window.innerWidth / 2,
|
|
78
|
+
pointY: window.innerHeight / 2 - bottomOffsetPx / 2
|
|
79
|
+
},
|
|
80
|
+
winWidth: window.innerWidth / 2,
|
|
81
|
+
winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
|
|
82
|
+
winVisualState: "demaximized"
|
|
83
|
+
}),
|
|
84
|
+
dockWindowTopRight: () => set({
|
|
85
|
+
winCoord: { pointX: window.innerWidth / 2, pointY: 0 },
|
|
86
|
+
winWidth: window.innerWidth / 2,
|
|
87
|
+
winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
|
|
88
|
+
winVisualState: "demaximized"
|
|
89
|
+
}),
|
|
90
|
+
dockWindowBottomLeft: () => set({
|
|
91
|
+
winCoord: { pointX: 0, pointY: window.innerHeight / 2 - bottomOffsetPx / 2 },
|
|
92
|
+
winWidth: window.innerWidth / 2,
|
|
93
|
+
winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
|
|
94
|
+
winVisualState: "demaximized"
|
|
95
|
+
}),
|
|
96
|
+
dockWindowTopLeft: () => set({
|
|
97
|
+
winCoord: { pointX: 0, pointY: 0 },
|
|
98
|
+
winWidth: window.innerWidth / 2,
|
|
99
|
+
winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
|
|
100
|
+
winVisualState: "demaximized"
|
|
101
|
+
}),
|
|
102
|
+
WIN_MIN_WIDTH: 360,
|
|
103
|
+
WIN_MIN_HEIGHT: 240,
|
|
104
|
+
setWIN_MIN_WIDTH: (w) => set({ WIN_MIN_WIDTH: w }),
|
|
105
|
+
setWIN_MIN_HEIGHT: (h) => set({ WIN_MIN_HEIGHT: h })
|
|
106
|
+
}));
|
|
107
|
+
windowRegistry[windowId] = storeInstance;
|
|
108
|
+
return storeInstance;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/window-manager/window-global-actions.ts
|
|
112
|
+
var stopAllDragAndResize = () => {
|
|
113
|
+
for (const key of Object.keys(windowRegistry)) {
|
|
114
|
+
windowRegistry[key].getState().stopDragAndResize();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var resetAllWindows = () => {
|
|
118
|
+
for (const key of Object.keys(windowRegistry)) {
|
|
119
|
+
windowRegistry[key].getState().reset();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var bringTargetWindowToFront = (targetId) => {
|
|
123
|
+
const targetWindow = windowRegistry[targetId].getState();
|
|
124
|
+
for (const key of Object.keys(windowRegistry)) {
|
|
125
|
+
const window2 = windowRegistry[key].getState();
|
|
126
|
+
if (window2.windowId === targetWindow.windowId) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
window2.setIsActive(false);
|
|
130
|
+
if (window2.zIndex >= targetWindow.zIndex) {
|
|
131
|
+
window2.setZIndex(window2.zIndex - 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
targetWindow.setZIndex(Object.keys(windowRegistry).length);
|
|
135
|
+
targetWindow.setIsActive(true);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/window-manager/window-button.tsx
|
|
139
|
+
import { jsx } from "react/jsx-runtime";
|
|
140
|
+
function WindowButton({
|
|
141
|
+
children,
|
|
142
|
+
useWindowStore,
|
|
143
|
+
styles,
|
|
144
|
+
closedStyle = "brightness-[85%]",
|
|
145
|
+
openStyle = "brightness-150"
|
|
146
|
+
}) {
|
|
147
|
+
const { openWindow, minimizeWindow, isWinMinimized, windowId, isActive } = useWindowStore();
|
|
148
|
+
const handleOpenCloseWin = () => {
|
|
149
|
+
if (isWinMinimized) {
|
|
150
|
+
bringTargetWindowToFront(windowId);
|
|
151
|
+
openWindow();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (isActive) {
|
|
155
|
+
minimizeWindow();
|
|
156
|
+
}
|
|
157
|
+
bringTargetWindowToFront(windowId);
|
|
158
|
+
};
|
|
159
|
+
return /* @__PURE__ */ jsx(
|
|
160
|
+
"button",
|
|
161
|
+
{
|
|
162
|
+
id: `${windowId}_button`,
|
|
163
|
+
onClick: handleOpenCloseWin,
|
|
164
|
+
className: `
|
|
165
|
+
${styles}
|
|
166
|
+
${isWinMinimized ? closedStyle : openStyle}`,
|
|
167
|
+
children
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/screen-manager/screen-state.ts
|
|
173
|
+
import { create as create2 } from "zustand";
|
|
174
|
+
var useScreenState = create2((set) => ({
|
|
175
|
+
x: 10,
|
|
176
|
+
y: 10,
|
|
177
|
+
setX: (newX) => set({ x: newX }),
|
|
178
|
+
setY: (newY) => set({ y: newY })
|
|
179
|
+
}));
|
|
180
|
+
|
|
181
|
+
// src/screen-manager/screen-listeners.tsx
|
|
182
|
+
import { useEffect } from "react";
|
|
183
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
184
|
+
function ScreenListeners() {
|
|
185
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
186
|
+
/* @__PURE__ */ jsx2(CursorCoordinates, {}),
|
|
187
|
+
/* @__PURE__ */ jsx2(WindowResizeReset, {})
|
|
188
|
+
] });
|
|
189
|
+
}
|
|
190
|
+
function WindowResizeReset() {
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const handleWindowResize = () => {
|
|
193
|
+
resetAllWindows();
|
|
194
|
+
};
|
|
195
|
+
window.addEventListener("resize", handleWindowResize);
|
|
196
|
+
return () => document.removeEventListener("pointermove", handleWindowResize);
|
|
197
|
+
}, []);
|
|
198
|
+
return /* @__PURE__ */ jsx2(Fragment, {});
|
|
199
|
+
}
|
|
200
|
+
function CursorCoordinates() {
|
|
201
|
+
const { setX, setY } = useScreenState();
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
const handleWindowPosition = (e) => {
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
setX(e.clientX);
|
|
206
|
+
setY(e.clientY);
|
|
207
|
+
};
|
|
208
|
+
document.addEventListener("pointermove", handleWindowPosition);
|
|
209
|
+
return () => document.removeEventListener("pointermove", handleWindowPosition);
|
|
210
|
+
}, [setX, setY]);
|
|
211
|
+
return /* @__PURE__ */ jsx2(Fragment, {});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/window-manager/workspace-layout.tsx
|
|
215
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
216
|
+
function WorkspaceLayout({ children }) {
|
|
217
|
+
return /* @__PURE__ */ jsxs2(
|
|
218
|
+
"main",
|
|
219
|
+
{
|
|
220
|
+
onMouseLeave: stopAllDragAndResize,
|
|
221
|
+
onMouseUp: stopAllDragAndResize,
|
|
222
|
+
className: "absolute overflow-hidden h-full w-full touch-none",
|
|
223
|
+
children: [
|
|
224
|
+
/* @__PURE__ */ jsx3(ScreenListeners, {}),
|
|
225
|
+
children
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/window-manager/window-layout.tsx
|
|
232
|
+
import { useEffect as useEffect2, useRef } from "react";
|
|
233
|
+
|
|
234
|
+
// src/window-assets/svg-win-icons.tsx
|
|
235
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
236
|
+
function iconWinMaximize() {
|
|
237
|
+
return /* @__PURE__ */ jsx4(
|
|
238
|
+
"svg",
|
|
239
|
+
{
|
|
240
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
241
|
+
fill: "none",
|
|
242
|
+
viewBox: "0 0 24 24",
|
|
243
|
+
width: 24,
|
|
244
|
+
height: 24,
|
|
245
|
+
strokeWidth: 1.5,
|
|
246
|
+
stroke: "white",
|
|
247
|
+
color: "white",
|
|
248
|
+
className: "size-6",
|
|
249
|
+
children: /* @__PURE__ */ jsx4(
|
|
250
|
+
"path",
|
|
251
|
+
{
|
|
252
|
+
strokeLinecap: "round",
|
|
253
|
+
strokeLinejoin: "round",
|
|
254
|
+
d: "M5.25 7.5A2.25 2.25 0 0 1 7.5 5.25h9a2.25 2.25 0 0 1 2.25 2.25v9a2.25 2.25 0 0 1-2.25 2.25h-9a2.25 2.25 0 0 1-2.25-2.25v-9Z"
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function iconWinDemaximize() {
|
|
261
|
+
return /* @__PURE__ */ jsx4(
|
|
262
|
+
"svg",
|
|
263
|
+
{
|
|
264
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
265
|
+
fill: "none",
|
|
266
|
+
viewBox: "0 0 24 24",
|
|
267
|
+
width: 24,
|
|
268
|
+
height: 24,
|
|
269
|
+
strokeWidth: 1.5,
|
|
270
|
+
stroke: "white",
|
|
271
|
+
color: "white",
|
|
272
|
+
className: "size-6",
|
|
273
|
+
children: /* @__PURE__ */ jsx4(
|
|
274
|
+
"path",
|
|
275
|
+
{
|
|
276
|
+
strokeLinecap: "round",
|
|
277
|
+
strokeLinejoin: "round",
|
|
278
|
+
d: "M16.5 8.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v8.25A2.25 2.25 0 0 0 6 16.5h2.25m8.25-8.25H18a2.25 2.25 0 0 1 2.25 2.25V18A2.25 2.25 0 0 1 18 20.25h-7.5A2.25 2.25 0 0 1 8.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 0 0-2.25 2.25v6"
|
|
279
|
+
}
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
function iconWinMinimize() {
|
|
285
|
+
return /* @__PURE__ */ jsx4(
|
|
286
|
+
"svg",
|
|
287
|
+
{
|
|
288
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
289
|
+
fill: "none",
|
|
290
|
+
viewBox: "0 0 24 24",
|
|
291
|
+
width: 24,
|
|
292
|
+
height: 24,
|
|
293
|
+
strokeWidth: 1.5,
|
|
294
|
+
stroke: "white",
|
|
295
|
+
color: "white",
|
|
296
|
+
className: "size-6",
|
|
297
|
+
children: /* @__PURE__ */ jsx4("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" })
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/window-manager/window-layout.tsx
|
|
303
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
304
|
+
var responsiveBreakInPx = {
|
|
305
|
+
sm: 640,
|
|
306
|
+
md: 768,
|
|
307
|
+
lg: 1024,
|
|
308
|
+
xl: 1280,
|
|
309
|
+
never: 0
|
|
310
|
+
};
|
|
311
|
+
function WindowLayout({
|
|
312
|
+
responsiveBreak = "lg",
|
|
313
|
+
children,
|
|
314
|
+
windowName,
|
|
315
|
+
navbarChildren,
|
|
316
|
+
useWindowStore,
|
|
317
|
+
defaultDock
|
|
318
|
+
}) {
|
|
319
|
+
const { x, y } = useScreenState();
|
|
320
|
+
const windowRef = useRef(null);
|
|
321
|
+
const {
|
|
322
|
+
windowId,
|
|
323
|
+
zIndex,
|
|
324
|
+
isActive,
|
|
325
|
+
setSelf,
|
|
326
|
+
resetFlag,
|
|
327
|
+
winVisualState,
|
|
328
|
+
setWinVisualState,
|
|
329
|
+
isWinMinimized,
|
|
330
|
+
dragClickOffset,
|
|
331
|
+
setDragClickOffset,
|
|
332
|
+
isDragging,
|
|
333
|
+
setIsDragging,
|
|
334
|
+
winCoord,
|
|
335
|
+
setWinCoord,
|
|
336
|
+
isResizing,
|
|
337
|
+
setIsResizing,
|
|
338
|
+
winWidth,
|
|
339
|
+
setWinWidth,
|
|
340
|
+
winHeight,
|
|
341
|
+
setWinHeight,
|
|
342
|
+
minimizeWindow,
|
|
343
|
+
maximizeWindow,
|
|
344
|
+
demaximizeWindow,
|
|
345
|
+
dockWindowRight,
|
|
346
|
+
dockWindowLeft,
|
|
347
|
+
dockWindowTopLeft,
|
|
348
|
+
dockWindowBottomLeft,
|
|
349
|
+
dockWindowTopRight,
|
|
350
|
+
dockWindowBottomRight,
|
|
351
|
+
WIN_MIN_WIDTH,
|
|
352
|
+
WIN_MIN_HEIGHT
|
|
353
|
+
} = useWindowStore();
|
|
354
|
+
useEffect2(() => {
|
|
355
|
+
setSelf(windowRef);
|
|
356
|
+
if (isMobile())
|
|
357
|
+
maximizeWindow();
|
|
358
|
+
else if (defaultDock === "left")
|
|
359
|
+
dockWindowLeft();
|
|
360
|
+
else if (defaultDock === "right")
|
|
361
|
+
dockWindowRight();
|
|
362
|
+
else if (defaultDock === "full")
|
|
363
|
+
maximizeWindow();
|
|
364
|
+
else
|
|
365
|
+
demaximizeWindow();
|
|
366
|
+
}, [setSelf, windowRef, resetFlag]);
|
|
367
|
+
useEffect2(() => {
|
|
368
|
+
if (isMobile())
|
|
369
|
+
return;
|
|
370
|
+
if (!isDragging)
|
|
371
|
+
return;
|
|
372
|
+
if (winVisualState === "maximized")
|
|
373
|
+
demaximizeWindow();
|
|
374
|
+
let adjustedX = x - dragClickOffset.pointX;
|
|
375
|
+
if (x > window.innerWidth || x < 0)
|
|
376
|
+
adjustedX = winCoord.pointX;
|
|
377
|
+
let adjustedY = y - dragClickOffset.pointY;
|
|
378
|
+
if (y > window.innerHeight || y < 0)
|
|
379
|
+
adjustedY = winCoord.pointY;
|
|
380
|
+
setWinCoord({ pointX: adjustedX, pointY: adjustedY });
|
|
381
|
+
}, [isDragging, x, y]);
|
|
382
|
+
useEffect2(() => {
|
|
383
|
+
if (!isResizing)
|
|
384
|
+
return;
|
|
385
|
+
setWinVisualState("demaximized");
|
|
386
|
+
if (isResizing === "bottom-height")
|
|
387
|
+
resizeBottomWinHeight();
|
|
388
|
+
if (isResizing === "top-height")
|
|
389
|
+
resizeTopWinHeight();
|
|
390
|
+
if (isResizing === "right-width")
|
|
391
|
+
resizeRightWinWidth();
|
|
392
|
+
if (isResizing === "left-width")
|
|
393
|
+
resizeLeftWinWidth();
|
|
394
|
+
if (isResizing === "bottom-right-all")
|
|
395
|
+
resizeRightBottomWidthAndHeight();
|
|
396
|
+
if (isResizing === "bottom-left-all")
|
|
397
|
+
resizeLeftBottomWidthAndHeight();
|
|
398
|
+
}, [isResizing, x, y]);
|
|
399
|
+
const handleNavbarClick = (isDragging2) => {
|
|
400
|
+
setDragClickOffset({ pointX: x - winCoord.pointX, pointY: y - winCoord.pointY });
|
|
401
|
+
setIsDragging(isDragging2);
|
|
402
|
+
};
|
|
403
|
+
const isMobile = () => {
|
|
404
|
+
return window.innerWidth < responsiveBreakInPx[responsiveBreak];
|
|
405
|
+
};
|
|
406
|
+
const resizeRightWinWidth = () => {
|
|
407
|
+
const winBox = windowRef.current?.getBoundingClientRect();
|
|
408
|
+
if (!winBox)
|
|
409
|
+
return;
|
|
410
|
+
const minWinWidth = x - winBox.left < WIN_MIN_WIDTH;
|
|
411
|
+
if (minWinWidth)
|
|
412
|
+
return;
|
|
413
|
+
const cursorOutOfBounds = x > window.innerWidth || x < 0;
|
|
414
|
+
if (cursorOutOfBounds)
|
|
415
|
+
return;
|
|
416
|
+
const sizeDiff = x - winBox.right;
|
|
417
|
+
setWinWidth(winWidth + sizeDiff);
|
|
418
|
+
};
|
|
419
|
+
const resizeLeftWinWidth = () => {
|
|
420
|
+
const winBox = windowRef.current?.getBoundingClientRect();
|
|
421
|
+
if (!winBox)
|
|
422
|
+
return;
|
|
423
|
+
const minWinWidth = winBox.right - x < WIN_MIN_WIDTH;
|
|
424
|
+
if (minWinWidth)
|
|
425
|
+
return;
|
|
426
|
+
const cursorOutOfBounds = x > window.innerWidth || x < 0;
|
|
427
|
+
if (cursorOutOfBounds)
|
|
428
|
+
return;
|
|
429
|
+
const sizeDiff = winBox.left - x;
|
|
430
|
+
setWinWidth(winWidth + sizeDiff);
|
|
431
|
+
setWinCoord({ pointX: x, pointY: winCoord.pointY });
|
|
432
|
+
};
|
|
433
|
+
const resizeBottomWinHeight = () => {
|
|
434
|
+
const winBox = windowRef.current?.getBoundingClientRect();
|
|
435
|
+
if (!winBox)
|
|
436
|
+
return;
|
|
437
|
+
const minWinHeight = y - winBox.top < WIN_MIN_HEIGHT;
|
|
438
|
+
if (minWinHeight)
|
|
439
|
+
return;
|
|
440
|
+
const cursorOutOfBounds = y > window.innerHeight || y < 0;
|
|
441
|
+
if (cursorOutOfBounds)
|
|
442
|
+
return;
|
|
443
|
+
const sizeDiff = y - winBox.bottom;
|
|
444
|
+
setWinHeight(winHeight + sizeDiff);
|
|
445
|
+
};
|
|
446
|
+
const resizeTopWinHeight = () => {
|
|
447
|
+
const winBox = windowRef.current?.getBoundingClientRect();
|
|
448
|
+
if (!winBox)
|
|
449
|
+
return;
|
|
450
|
+
const minWinHeight = winBox.bottom - y < WIN_MIN_HEIGHT;
|
|
451
|
+
if (minWinHeight)
|
|
452
|
+
return;
|
|
453
|
+
const cursorOutOfBounds = y > window.innerHeight || y < 0;
|
|
454
|
+
if (cursorOutOfBounds)
|
|
455
|
+
return;
|
|
456
|
+
const sizeDiff = winBox.top - y;
|
|
457
|
+
setWinHeight(winHeight + sizeDiff);
|
|
458
|
+
setWinCoord({ pointX: winCoord.pointX, pointY: y });
|
|
459
|
+
};
|
|
460
|
+
const resizeRightBottomWidthAndHeight = () => {
|
|
461
|
+
resizeRightWinWidth();
|
|
462
|
+
resizeBottomWinHeight();
|
|
463
|
+
};
|
|
464
|
+
const resizeLeftBottomWidthAndHeight = () => {
|
|
465
|
+
resizeLeftWinWidth();
|
|
466
|
+
resizeBottomWinHeight();
|
|
467
|
+
};
|
|
468
|
+
const handleResizeClick = (isResizing2) => {
|
|
469
|
+
setIsResizing(isResizing2);
|
|
470
|
+
};
|
|
471
|
+
const cornerDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex xl:p-0 px-2 shrink-0 gap-1`, children: [
|
|
472
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-1", children: [
|
|
473
|
+
/* @__PURE__ */ jsx5(
|
|
474
|
+
"button",
|
|
475
|
+
{
|
|
476
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 border w-4 h-[10px] rounded-sm",
|
|
477
|
+
onClick: dockWindowTopLeft
|
|
478
|
+
}
|
|
479
|
+
),
|
|
480
|
+
/* @__PURE__ */ jsx5(
|
|
481
|
+
"button",
|
|
482
|
+
{
|
|
483
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 border w-4 h-[10px] rounded-sm",
|
|
484
|
+
onClick: dockWindowBottomLeft
|
|
485
|
+
}
|
|
486
|
+
)
|
|
487
|
+
] }),
|
|
488
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-1", children: [
|
|
489
|
+
/* @__PURE__ */ jsx5(
|
|
490
|
+
"button",
|
|
491
|
+
{
|
|
492
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 border w-4 h-[10px] rounded-sm",
|
|
493
|
+
onClick: dockWindowTopRight
|
|
494
|
+
}
|
|
495
|
+
),
|
|
496
|
+
/* @__PURE__ */ jsx5(
|
|
497
|
+
"button",
|
|
498
|
+
{
|
|
499
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 border w-4 h-[10px] rounded-sm",
|
|
500
|
+
onClick: dockWindowBottomRight
|
|
501
|
+
}
|
|
502
|
+
)
|
|
503
|
+
] })
|
|
504
|
+
] });
|
|
505
|
+
const sideDideControl = /* @__PURE__ */ jsxs3("div", { className: `flex px-2 shrink-0 items-center gap-1`, children: [
|
|
506
|
+
/* @__PURE__ */ jsx5(
|
|
507
|
+
"button",
|
|
508
|
+
{
|
|
509
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 px-[1px] border w-4 h-6 rounded-sm",
|
|
510
|
+
onClick: dockWindowLeft
|
|
511
|
+
}
|
|
512
|
+
),
|
|
513
|
+
/* @__PURE__ */ jsx5(
|
|
514
|
+
"button",
|
|
515
|
+
{
|
|
516
|
+
className: "hover:bg-gray-100 hover:bg-opacity-20 px-[1px] border w-4 h-6 rounded-sm",
|
|
517
|
+
onClick: dockWindowRight
|
|
518
|
+
}
|
|
519
|
+
)
|
|
520
|
+
] });
|
|
521
|
+
const maximizeControl = winVisualState === "maximized" ? /* @__PURE__ */ jsx5(
|
|
522
|
+
"button",
|
|
523
|
+
{
|
|
524
|
+
className: `block hover:bg-gray-100 hover:bg-opacity-20 px-5 h-full`,
|
|
525
|
+
onClick: demaximizeWindow,
|
|
526
|
+
children: iconWinDemaximize()
|
|
527
|
+
}
|
|
528
|
+
) : /* @__PURE__ */ jsx5(
|
|
529
|
+
"button",
|
|
530
|
+
{
|
|
531
|
+
className: `block hover:bg-gray-100 hover:bg-opacity-20 px-5 h-full`,
|
|
532
|
+
onClick: maximizeWindow,
|
|
533
|
+
children: iconWinMaximize()
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
const minimizeControl = /* @__PURE__ */ jsx5("button", { className: "hover:bg-red-500 hover:bg-opacity-20 px-5 h-full", onClick: minimizeWindow, children: iconWinMinimize() });
|
|
537
|
+
return /* @__PURE__ */ jsxs3(
|
|
538
|
+
"div",
|
|
539
|
+
{
|
|
540
|
+
onMouseDown: () => bringTargetWindowToFront(windowId),
|
|
541
|
+
id: windowId,
|
|
542
|
+
ref: windowRef,
|
|
543
|
+
style: {
|
|
544
|
+
top: `${winCoord.pointY}px`,
|
|
545
|
+
left: `${winCoord.pointX}px`,
|
|
546
|
+
width: `${winWidth}px`,
|
|
547
|
+
height: `${winHeight}px`,
|
|
548
|
+
zIndex: `${zIndex}`,
|
|
549
|
+
/* MINIMIZE LOGIC */
|
|
550
|
+
transition: "transform 0.2s ease-in-out, opacity 0.3s ease-in-out",
|
|
551
|
+
opacity: isWinMinimized ? 0 : 1,
|
|
552
|
+
transform: isWinMinimized ? `translate(${window.innerWidth / 2 - winCoord.pointX - winWidth / 2}px,
|
|
553
|
+
${window.innerHeight - winCoord.pointY - winHeight / 2}px) scale(0.02)` : ""
|
|
554
|
+
},
|
|
555
|
+
onMouseUp: () => {
|
|
556
|
+
handleNavbarClick(false);
|
|
557
|
+
handleResizeClick(false);
|
|
558
|
+
},
|
|
559
|
+
className: `fixed bg-white shadow-lg border border-zinc-600`,
|
|
560
|
+
children: [
|
|
561
|
+
/* @__PURE__ */ jsxs3(
|
|
562
|
+
"nav",
|
|
563
|
+
{
|
|
564
|
+
className: `h-[32px] w-full bg-neutral-800 flex items-center
|
|
565
|
+
${isActive ? "brightness-100 opacity-100" : "brightness-75 opacity-90"}`,
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ jsxs3(
|
|
568
|
+
"div",
|
|
569
|
+
{
|
|
570
|
+
onMouseDown: () => handleNavbarClick(true),
|
|
571
|
+
onDoubleClick: maximizeWindow,
|
|
572
|
+
className: "w-full h-8 px-2 text-white flex items-center text-sm truncate",
|
|
573
|
+
children: [
|
|
574
|
+
windowName,
|
|
575
|
+
navbarChildren
|
|
576
|
+
]
|
|
577
|
+
}
|
|
578
|
+
),
|
|
579
|
+
!isMobile() && cornerDockControl,
|
|
580
|
+
!isMobile() && sideDideControl,
|
|
581
|
+
!isMobile() && maximizeControl,
|
|
582
|
+
minimizeControl
|
|
583
|
+
]
|
|
584
|
+
}
|
|
585
|
+
),
|
|
586
|
+
/* @__PURE__ */ jsx5(
|
|
587
|
+
"span",
|
|
588
|
+
{
|
|
589
|
+
onMouseDown: () => handleResizeClick("right-width"),
|
|
590
|
+
id: "win-resize-width",
|
|
591
|
+
className: "fixed w-2 opacity-60 cursor-w-resize z-10",
|
|
592
|
+
style: {
|
|
593
|
+
top: `${winCoord.pointY}px`,
|
|
594
|
+
left: `${winCoord.pointX + winWidth - 4}px`,
|
|
595
|
+
height: `${winHeight}px`
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
),
|
|
599
|
+
/* @__PURE__ */ jsx5(
|
|
600
|
+
"span",
|
|
601
|
+
{
|
|
602
|
+
onMouseDown: () => handleResizeClick("left-width"),
|
|
603
|
+
id: "win-resize-width",
|
|
604
|
+
className: "fixed w-2 opacity-60 cursor-w-resize z-10",
|
|
605
|
+
style: {
|
|
606
|
+
top: `${winCoord.pointY}px`,
|
|
607
|
+
left: `${winCoord.pointX - 4}px`,
|
|
608
|
+
height: `${winHeight}px`
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
),
|
|
612
|
+
/* @__PURE__ */ jsx5(
|
|
613
|
+
"span",
|
|
614
|
+
{
|
|
615
|
+
onMouseDown: () => handleResizeClick("bottom-height"),
|
|
616
|
+
id: "win-resize-height",
|
|
617
|
+
className: "fixed h-2 opacity-60 cursor-s-resize z-10",
|
|
618
|
+
style: {
|
|
619
|
+
top: `${winCoord.pointY + winHeight - 6}px`,
|
|
620
|
+
left: `${winCoord.pointX}px`,
|
|
621
|
+
width: `${winWidth}px`
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
),
|
|
625
|
+
/* @__PURE__ */ jsx5(
|
|
626
|
+
"span",
|
|
627
|
+
{
|
|
628
|
+
onMouseDown: () => handleResizeClick("top-height"),
|
|
629
|
+
id: "win-resize-height",
|
|
630
|
+
className: "fixed h-2 opacity-60 cursor-s-resize z-10",
|
|
631
|
+
style: {
|
|
632
|
+
top: `${winCoord.pointY - 6}px`,
|
|
633
|
+
left: `${winCoord.pointX}px`,
|
|
634
|
+
width: `${winWidth}px`
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
),
|
|
638
|
+
/* @__PURE__ */ jsx5(
|
|
639
|
+
"span",
|
|
640
|
+
{
|
|
641
|
+
onMouseDown: () => handleResizeClick("bottom-right-all"),
|
|
642
|
+
id: "win-resize-all",
|
|
643
|
+
className: "fixed h-3 w-3 opacity-60 cursor-se-resize z-20",
|
|
644
|
+
style: {
|
|
645
|
+
top: `${winCoord.pointY + winHeight - 8}px`,
|
|
646
|
+
left: `${winCoord.pointX + winWidth - 8}px`
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
),
|
|
650
|
+
/* @__PURE__ */ jsx5(
|
|
651
|
+
"span",
|
|
652
|
+
{
|
|
653
|
+
onMouseDown: () => handleResizeClick("bottom-left-all"),
|
|
654
|
+
id: "win-resize-all",
|
|
655
|
+
className: "fixed h-3 w-3 opacity-60 cursor-sw-resize z-20",
|
|
656
|
+
style: {
|
|
657
|
+
top: `${winCoord.pointY + winHeight - 8}px`,
|
|
658
|
+
left: `${winCoord.pointX - 8}px`
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
),
|
|
662
|
+
/* @__PURE__ */ jsx5("div", { className: `w-full h-[calc(100%-32px)] overflow-auto`, children })
|
|
663
|
+
]
|
|
664
|
+
}
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
export {
|
|
668
|
+
WindowButton,
|
|
669
|
+
WindowLayout,
|
|
670
|
+
WorkspaceLayout,
|
|
671
|
+
createWindowStore,
|
|
672
|
+
windowRegistry
|
|
673
|
+
};
|
|
674
|
+
//# sourceMappingURL=index.js.map
|