@byeolnaerim/flex-layout 0.0.2

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.js ADDED
@@ -0,0 +1,816 @@
1
+ import { useState, useEffect, useRef, useCallback } from 'react';
2
+ import equal from 'fast-deep-equal';
3
+ import { BehaviorSubject, Subject, combineLatest, map as map$1, filter as filter$1, switchMap, EMPTY, fromEvent, buffer, debounceTime, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
4
+ import { filter, map, distinctUntilChanged } from 'rxjs/operators';
5
+
6
+ // src/flex-layout/providers/FlexLayoutHooks.tsx
7
+ function updateScrollStore(subject, newValue) {
8
+ const currentValue = subject.getValue();
9
+ if (!equal(currentValue, newValue)) {
10
+ subject.next(newValue);
11
+ }
12
+ }
13
+ function updateRefStore(store, newState) {
14
+ const prevState = store.getValue();
15
+ if (!equal(prevState, newState)) {
16
+ store.next(newState);
17
+ }
18
+ }
19
+ function updateSplitScreenStore(newValue) {
20
+ const prevValue = layoutSplitScreenStore.getValue();
21
+ if (!equal(prevValue, newValue)) {
22
+ layoutSplitScreenStore.next(newValue);
23
+ }
24
+ }
25
+ var scrollPositions = {};
26
+ var scrollPositionsSubject = new BehaviorSubject(scrollPositions);
27
+ var setScrollPosition = (layoutName, position) => {
28
+ const current = scrollPositionsSubject.getValue();
29
+ const prevPos = current[layoutName];
30
+ if (prevPos && prevPos.x === position.x && prevPos.y === position.y) {
31
+ return;
32
+ }
33
+ const newPositions = {
34
+ ...current,
35
+ [layoutName]: position
36
+ };
37
+ updateScrollStore(scrollPositionsSubject, newPositions);
38
+ };
39
+ var getScrollPosition = (layoutName) => {
40
+ return scrollPositionsSubject.pipe(
41
+ // 해당 layoutName이 정의되지 않았을 때는 제외
42
+ filter((e) => e[layoutName] !== void 0),
43
+ map((positions) => positions[layoutName]),
44
+ distinctUntilChanged(
45
+ (prev, curr) => prev?.x === curr?.x && prev?.y === curr?.y
46
+ )
47
+ );
48
+ };
49
+ var removeScrollPosition = (layoutName) => {
50
+ const current = scrollPositionsSubject.getValue();
51
+ delete current[layoutName];
52
+ const newPositions = { ...current };
53
+ updateScrollStore(scrollPositionsSubject, newPositions);
54
+ };
55
+ var layoutSplitScreenStore = new BehaviorSubject({});
56
+ var setSplitScreen = (rootName, layoutName, newComponents) => {
57
+ const current = layoutSplitScreenStore.getValue();
58
+ const updatedLayout = { ...current[rootName] || {} };
59
+ updatedLayout[layoutName] = newComponents;
60
+ const newStoreValue = {
61
+ ...current,
62
+ [rootName]: updatedLayout
63
+ };
64
+ updateSplitScreenStore(newStoreValue);
65
+ };
66
+ var resetRootSplitScreen = (rootName) => {
67
+ const current = layoutSplitScreenStore.getValue();
68
+ const newStoreValue = {
69
+ ...current,
70
+ [rootName]: {}
71
+ };
72
+ updateSplitScreenStore(newStoreValue);
73
+ };
74
+ var removeSplitScreenChild = (rootName, layoutName) => {
75
+ const current = layoutSplitScreenStore.getValue();
76
+ if (!current[rootName]) return;
77
+ const updatedLayout = { ...current[rootName] };
78
+ delete updatedLayout[layoutName];
79
+ const newStoreValue = {
80
+ ...current,
81
+ [rootName]: updatedLayout
82
+ };
83
+ updateSplitScreenStore(newStoreValue);
84
+ };
85
+ var getCurrentSplitScreenComponents = (rootName, layoutName) => {
86
+ const current = layoutSplitScreenStore.getValue();
87
+ if (!current[rootName]) return;
88
+ return current[rootName][layoutName];
89
+ };
90
+ var getSplitScreen = (rootName, layoutName) => {
91
+ return layoutSplitScreenStore.pipe(
92
+ map((splitScreen) => splitScreen[rootName][layoutName]),
93
+ distinctUntilChanged((prev, curr) => {
94
+ const filterChildren2 = (obj) => {
95
+ const { children, component, targetComponent, x, y, ...rest } = obj || {};
96
+ return rest;
97
+ };
98
+ return equal(filterChildren2(prev), filterChildren2(curr));
99
+ })
100
+ );
101
+ };
102
+ var flexContainerStore = new BehaviorSubject({});
103
+ var flexResizePanelStore = new BehaviorSubject({});
104
+ var setContainerRef = (layoutName, containerName, ref) => {
105
+ const currentRefs = flexContainerStore.getValue();
106
+ const updatedLayoutRefs = { ...currentRefs[layoutName] || {} };
107
+ if (ref === null) {
108
+ delete updatedLayoutRefs[containerName];
109
+ } else {
110
+ updatedLayoutRefs[containerName] = ref;
111
+ }
112
+ const newRefs = {
113
+ ...currentRefs,
114
+ [layoutName]: updatedLayoutRefs
115
+ };
116
+ updateRefStore(flexContainerStore, newRefs);
117
+ };
118
+ var setResizePanelRef = (layoutName, containerName, ref) => {
119
+ const currentRefs = flexResizePanelStore.getValue();
120
+ const updatedLayoutRefs = { ...currentRefs[layoutName] || {} };
121
+ if (ref === null) {
122
+ delete updatedLayoutRefs[containerName];
123
+ } else {
124
+ updatedLayoutRefs[containerName] = ref;
125
+ }
126
+ const newRefs = {
127
+ ...currentRefs,
128
+ [layoutName]: updatedLayoutRefs
129
+ };
130
+ updateRefStore(flexResizePanelStore, newRefs);
131
+ };
132
+ var getLayoutInfos = (layoutName) => {
133
+ return combineLatest([flexContainerStore, flexResizePanelStore]).pipe(
134
+ map(([containerRefs, resizePanelRefs]) => {
135
+ const containerData = containerRefs[layoutName] || {};
136
+ const resizePanelData = resizePanelRefs[layoutName] || {};
137
+ return {
138
+ container: containerData,
139
+ resizePanel: resizePanelData
140
+ };
141
+ }),
142
+ filter((result) => result.container !== null)
143
+ // 빈 객체 제외
144
+ );
145
+ };
146
+ var getContainerRef = ({
147
+ containerName,
148
+ layoutName
149
+ }) => {
150
+ return flexContainerStore.pipe(
151
+ map((refs) => {
152
+ if (layoutName) {
153
+ return refs[layoutName]?.[containerName] || null;
154
+ } else {
155
+ return Object.entries(refs).find(
156
+ ([key, value]) => refs[key][containerName]
157
+ )?.[1][containerName];
158
+ }
159
+ }),
160
+ filter((ref) => ref !== null)
161
+ );
162
+ };
163
+ var getResizePanelRef = ({
164
+ containerName,
165
+ layoutName
166
+ }) => {
167
+ return flexResizePanelStore.pipe(
168
+ map((refs) => {
169
+ if (layoutName) {
170
+ return refs[layoutName]?.[containerName] || null;
171
+ } else {
172
+ return Object.entries(refs).find(
173
+ ([key, value]) => refs[key][containerName]
174
+ )?.[1][containerName];
175
+ }
176
+ }),
177
+ filter((ref) => ref !== null)
178
+ );
179
+ };
180
+
181
+ // src/flex-layout/utils/FlexLayoutUtils.ts
182
+ function isDocumentOut({ x, y }) {
183
+ if (typeof window == "undefined") return;
184
+ const { innerWidth, innerHeight, scrollX, scrollY } = window;
185
+ return x < 0 || y < 0 || x > innerWidth + scrollX || y > innerHeight + scrollY;
186
+ }
187
+ var lastTouchEvent;
188
+ function getClientXy(event) {
189
+ let clientX;
190
+ let clientY;
191
+ if (window.MouseEvent && event instanceof window.MouseEvent) {
192
+ clientX = event.clientX;
193
+ clientY = event.clientY;
194
+ } else if (window.TouchEvent && event instanceof window.TouchEvent) {
195
+ const _event = event.touches.length == 0 ? lastTouchEvent : event;
196
+ clientX = _event.touches[0].clientX;
197
+ clientY = _event.touches[0].clientY;
198
+ lastTouchEvent = event;
199
+ } else {
200
+ return;
201
+ }
202
+ return { clientX, clientY };
203
+ }
204
+ function isOverMove(elementSize, elementMinSize) {
205
+ return Math.floor(elementSize) <= 0 || (isNaN(elementMinSize) ? false : elementMinSize >= Math.floor(elementSize));
206
+ }
207
+ function findNotCloseFlexContent(target, direction) {
208
+ if (!target) return target;
209
+ let _target = target;
210
+ const isCloseCheck = () => {
211
+ let grow = parseFloat(window.getComputedStyle(_target).flex.split(" ")[0]) || 0;
212
+ if (grow == 0) {
213
+ return true;
214
+ } else {
215
+ return false;
216
+ }
217
+ };
218
+ while (isCloseCheck()) {
219
+ let nextTarget = _target[direction]?.[direction];
220
+ _target = nextTarget;
221
+ if (!_target) {
222
+ break;
223
+ }
224
+ }
225
+ return _target;
226
+ }
227
+ function remain(flexContainerList) {
228
+ return new Promise((resolve) => {
229
+ let notGrowList = [];
230
+ let totalGrow = flexContainerList.reduce((t, e, i) => {
231
+ if (e.hasAttribute("data-grow") == false) {
232
+ notGrowList.push(e);
233
+ return t;
234
+ }
235
+ let grow = parseFloat(e.dataset.grow || "");
236
+ e.style.flex = `${grow} 1 0%`;
237
+ t -= grow;
238
+ return t;
239
+ }, flexContainerList.length);
240
+ if (notGrowList.length != 0) {
241
+ resize(notGrowList, totalGrow);
242
+ }
243
+ resolve(flexContainerList);
244
+ });
245
+ }
246
+ function resize(list, totalGrow) {
247
+ return new Promise((resolve) => {
248
+ let resizeWeight = totalGrow / list.length;
249
+ list.forEach((e) => {
250
+ e.dataset.grow = resizeWeight.toString();
251
+ e.style.flex = `${resizeWeight} 1 0%`;
252
+ });
253
+ resolve(resizeWeight);
254
+ });
255
+ }
256
+ function mathWeight(totalCount, totalGrow) {
257
+ return 1 + (totalGrow - totalCount) / totalCount;
258
+ }
259
+ function mathGrow(childSize, parentSize, containerCount) {
260
+ return containerCount * (childSize / parentSize);
261
+ }
262
+ function getGrow(growTarget) {
263
+ const target = growTarget instanceof Element ? growTarget : growTarget;
264
+ return parseFloat(target.style.flex.split(" ")[0]) || parseFloat(target.dataset.grow || "");
265
+ }
266
+ function closeFlex(resizeTarget, containers, {
267
+ isResize = false,
268
+ isDsiabledResizePanel = false,
269
+ sizeName
270
+ }) {
271
+ return new Promise((resolve) => {
272
+ if (!resizeTarget.hasAttribute("data-is_resize_panel")) ; else if (isDsiabledResizePanel) {
273
+ resizeTarget.dataset.is_resize_panel = "false";
274
+ }
275
+ resizeTarget.dataset.prev_grow = getGrow(resizeTarget).toString();
276
+ let notCloseList = containers.filter(
277
+ (e) => e.style.flex != "0 1 0%" && e != resizeTarget
278
+ );
279
+ let notCloseAndOpenTargetList = [...notCloseList, resizeTarget];
280
+ notCloseAndOpenTargetList.forEach((e) => {
281
+ e.style.transition = "flex 0.5s";
282
+ e.ontransitionend = (event) => {
283
+ if (event.propertyName != "flex-grow") {
284
+ return;
285
+ }
286
+ notCloseAndOpenTargetList.forEach(
287
+ (e2) => e2.style.transition = ""
288
+ );
289
+ e.ontransitionend = () => {
290
+ };
291
+ };
292
+ if (e == resizeTarget) {
293
+ e.dataset.grow = "0";
294
+ e.style.flex = `0 1 0%`;
295
+ return;
296
+ }
297
+ if (isResize) {
298
+ return;
299
+ }
300
+ let percent = getGrow(e) / containers.length;
301
+ if (notCloseList.length == 1) {
302
+ e.dataset.grow = containers.length.toString();
303
+ e.style.flex = `${containers.length} 1 0%`;
304
+ return;
305
+ }
306
+ e.dataset.grow = (containers.length * percent).toString();
307
+ e.style.flex = `${containers.length * percent} 1 0%`;
308
+ });
309
+ if (isResize) {
310
+ resize(notCloseList, containers.length);
311
+ }
312
+ resolve(resizeTarget);
313
+ });
314
+ }
315
+ function openFlex(resizeTarget, containers, {
316
+ isPrevSizeOpen = false,
317
+ isResize = false,
318
+ openGrowImportant = 0,
319
+ sizeName
320
+ }) {
321
+ return new Promise((resolve) => {
322
+ if (!resizeTarget.hasAttribute("data-is_resize_panel")) ; else if (resizeTarget.hasAttribute("data-is_resize_panel") && resizeTarget.dataset.is_resize_panel == "false") {
323
+ resizeTarget.dataset.is_resize_panel = "true";
324
+ }
325
+ let notCloseList = containers.filter(
326
+ (e) => e.style.flex != "0 1 0%" && e != resizeTarget
327
+ );
328
+ let notCloseAndOpenTargetList = [...notCloseList, resizeTarget];
329
+ let openTargetGrow = 1;
330
+ const sizeStyleName = "client" + sizeName.charAt(0).toUpperCase() + sizeName.substring(1);
331
+ const parentSize = sizeName && resizeTarget.parentElement && resizeTarget.parentElement[sizeStyleName] || 0;
332
+ if (isPrevSizeOpen && resizeTarget.hasAttribute("data-prev_grow")) {
333
+ openTargetGrow = parseFloat(resizeTarget.dataset.prev_grow || "1") || 1;
334
+ } else if (parentSize && parentSize !== 0) {
335
+ openTargetGrow = parentSize / notCloseList.length / (parentSize - 1) * containers.length;
336
+ } else {
337
+ openTargetGrow = 1;
338
+ }
339
+ if (openGrowImportant) {
340
+ openTargetGrow = openGrowImportant;
341
+ }
342
+ openTargetGrow = openTargetGrow === Infinity ? 1 : openTargetGrow;
343
+ notCloseAndOpenTargetList.forEach((e) => {
344
+ e.style.transition = "flex 0.5s";
345
+ e.ontransitionend = (event) => {
346
+ if (event.propertyName != "flex-grow") {
347
+ return;
348
+ }
349
+ notCloseAndOpenTargetList.forEach(
350
+ (e2) => e2.style.transition = ""
351
+ );
352
+ e.ontransitionend = () => {
353
+ };
354
+ };
355
+ if (e == resizeTarget) {
356
+ resizeTarget.dataset.grow = openTargetGrow.toString();
357
+ resizeTarget.style.flex = `${openTargetGrow} 1 0%`;
358
+ return;
359
+ }
360
+ if (isResize) {
361
+ return;
362
+ }
363
+ let grow = parentSize / notCloseList.length / (parentSize - 1) * (containers.length - openTargetGrow);
364
+ grow = grow === Infinity ? 1 : grow;
365
+ e.dataset.grow = grow.toString();
366
+ e.style.flex = `${grow} 1 0%`;
367
+ });
368
+ if (isResize) {
369
+ resize(notCloseAndOpenTargetList, containers.length);
370
+ }
371
+ resolve(openTargetGrow);
372
+ });
373
+ }
374
+ var g = globalThis;
375
+ g.__FLEX_SUBJECTS__ ?? (g.__FLEX_SUBJECTS__ = { openClose: {}, spread: {} });
376
+ var containerOpenCloseSubjectMap = g.__FLEX_SUBJECTS__.openClose;
377
+ var containerSpreadSubjectMap = g.__FLEX_SUBJECTS__.spread;
378
+ var ContainerOpenCloseProvider = ({
379
+ layoutName,
380
+ containerName,
381
+ sizeName
382
+ }) => {
383
+ if (!containerOpenCloseSubjectMap[containerName]) {
384
+ containerOpenCloseSubjectMap[containerName] = new Subject();
385
+ }
386
+ if (!containerSpreadSubjectMap[containerName]) {
387
+ containerSpreadSubjectMap[containerName] = new Subject();
388
+ }
389
+ const [containers, setContainers] = useState([]);
390
+ const [container, setContainer] = useState();
391
+ useEffect(() => {
392
+ const subscription = getLayoutInfos(layoutName).subscribe(
393
+ (layout) => {
394
+ if (!layout || !layout.container[containerName] || !layout.container[containerName].current)
395
+ return;
396
+ setContainers(
397
+ Object.values(layout.container).filter(
398
+ (e) => e.current !== null
399
+ ).map((e) => e.current)
400
+ );
401
+ setContainer(layout.container[containerName].current);
402
+ }
403
+ );
404
+ return () => subscription.unsubscribe();
405
+ }, [containerName, layoutName]);
406
+ useEffect(() => {
407
+ const styleName = `${sizeName.charAt(0).toUpperCase() + sizeName.substring(1)}`;
408
+ const clientSize = "client" + styleName;
409
+ const outerSize = "outer" + styleName;
410
+ const maxSize = "max" + styleName;
411
+ const subscribe = containerOpenCloseSubjectMap[containerName].subscribe(
412
+ ({
413
+ mode,
414
+ initOpenState: isOpenState,
415
+ onClose,
416
+ onOpen,
417
+ openOption = {},
418
+ closeOption = {}
419
+ }) => {
420
+ if (!container || containers.length === 0) return;
421
+ const currentGrow = getGrow(container);
422
+ const styleMap = window.getComputedStyle(container);
423
+ const maxSizeGrow = mathGrow(
424
+ parseInt(styleMap[maxSize]),
425
+ container.parentElement && container.parentElement[clientSize] || window[outerSize],
426
+ containers.length
427
+ );
428
+ const open = () => openFlex(container, containers, {
429
+ sizeName,
430
+ ...isNaN(maxSizeGrow) ? {} : {
431
+ openGrowImportant: maxSizeGrow
432
+ },
433
+ ...openOption
434
+ }).then((openTargetGrow) => {
435
+ if (onOpen) onOpen();
436
+ containerSpreadSubjectMap[containerName].next({
437
+ isOpen: true,
438
+ grow: openTargetGrow,
439
+ targetContainer: container
440
+ });
441
+ });
442
+ const close = () => closeFlex(container, containers, {
443
+ sizeName,
444
+ ...closeOption
445
+ }).then(() => {
446
+ if (onClose) onClose();
447
+ containerSpreadSubjectMap[containerName].next({
448
+ isOpen: false,
449
+ grow: 0,
450
+ targetContainer: container
451
+ });
452
+ });
453
+ if (mode === "toggle") {
454
+ if (currentGrow === 0) {
455
+ open();
456
+ } else {
457
+ close();
458
+ }
459
+ } else if (mode === "open") {
460
+ if (currentGrow === 0) {
461
+ open();
462
+ }
463
+ } else if (mode === "close") {
464
+ if (currentGrow !== 0) {
465
+ close();
466
+ }
467
+ }
468
+ }
469
+ );
470
+ return () => {
471
+ subscribe.unsubscribe();
472
+ };
473
+ }, [containerName, container, containers, sizeName]);
474
+ return null;
475
+ };
476
+ var useContainers = (layoutName) => {
477
+ const [containers, setContainers] = useState([]);
478
+ useEffect(() => {
479
+ const subscription = getLayoutInfos(layoutName).subscribe(
480
+ (layout) => {
481
+ setContainers(
482
+ Object.values(layout.container).filter(
483
+ (e) => e.current !== null
484
+ ).map((e) => e.current)
485
+ );
486
+ }
487
+ );
488
+ return () => subscription.unsubscribe();
489
+ }, [layoutName]);
490
+ return containers;
491
+ };
492
+ var useLayoutName = (containerName) => {
493
+ const [layoutName, setLayoutName] = useState();
494
+ useEffect(() => {
495
+ const subscribe = flexContainerStore.pipe(
496
+ map$1(
497
+ (layouts) => Object.entries(layouts).filter(([_, v]) => v[containerName]).map(([k]) => k)[0]
498
+ // 첫 번째 결과 가져오기
499
+ )
500
+ ).subscribe(setLayoutName);
501
+ return () => subscribe.unsubscribe();
502
+ }, [containerName]);
503
+ return layoutName;
504
+ };
505
+ var useDecompositionLayout = ({
506
+ layoutName: initialLayoutName,
507
+ containerName
508
+ }) => {
509
+ const derivedLayoutName = useLayoutName(containerName);
510
+ const finalLayoutName = initialLayoutName || derivedLayoutName;
511
+ const [containers, setContainers] = useState([]);
512
+ const [container, setContainer] = useState();
513
+ const [resizePanel, setResizePanel] = useState();
514
+ useEffect(() => {
515
+ if (!finalLayoutName) return;
516
+ const subscription = getLayoutInfos(finalLayoutName).subscribe(
517
+ (layout) => {
518
+ if (!layout) return;
519
+ setContainers(
520
+ Object.values(layout.container).filter(
521
+ (e) => e.current !== null
522
+ ).map((e) => e.current)
523
+ );
524
+ if (containerName && layout.container[containerName] && layout.container[containerName].current) {
525
+ setContainer(layout.container[containerName].current);
526
+ if (layout.resizePanel[containerName] && layout.resizePanel[containerName].current) {
527
+ setResizePanel(
528
+ layout.resizePanel[containerName].current
529
+ );
530
+ }
531
+ }
532
+ }
533
+ );
534
+ return () => subscription.unsubscribe();
535
+ }, [containerName, finalLayoutName]);
536
+ return { layout: containers, container, resizePanel };
537
+ };
538
+ var useContainerSize = (containerName) => {
539
+ const { layout, container, resizePanel } = useDecompositionLayout({
540
+ containerName
541
+ });
542
+ const [size, setSize] = useState();
543
+ useEffect(() => {
544
+ if (!container) return;
545
+ const observer = new ResizeObserver((entries) => {
546
+ for (const entry of entries) {
547
+ setSize({
548
+ width: entry.contentRect.width,
549
+ height: entry.contentRect.height
550
+ });
551
+ }
552
+ });
553
+ observer.observe(container);
554
+ return () => observer.disconnect();
555
+ }, [container]);
556
+ return { size };
557
+ };
558
+ var useDoubleClick = (containerName, opt) => {
559
+ const [isOpen, setIsOpen] = useState();
560
+ const [isDoubleClick, setIsDoubleClick] = useState();
561
+ useEffect(() => {
562
+ const resizePanelClickEvent = getResizePanelRef({
563
+ containerName
564
+ }).pipe(
565
+ filter$1(
566
+ (resizePanelref) => resizePanelref != void 0 && resizePanelref.current != void 0
567
+ ),
568
+ //take(1),
569
+ switchMap((resizePanelref) => {
570
+ if (!resizePanelref || !resizePanelref.current) return EMPTY;
571
+ return fromEvent(resizePanelref.current, "click");
572
+ })
573
+ );
574
+ const subscribe = resizePanelClickEvent.pipe(
575
+ buffer(resizePanelClickEvent.pipe(debounceTime(500))),
576
+ filter$1((clickEventArray) => clickEventArray.length >= 2),
577
+ map$1((events) => {
578
+ containerOpenCloseSubjectMap[containerName].next({
579
+ ...opt,
580
+ openOption: {
581
+ ...opt.openOption,
582
+ isPrevSizeOpen: false
583
+ },
584
+ onClose: () => {
585
+ if (opt.onClose) opt.onClose();
586
+ setIsOpen(false);
587
+ setIsDoubleClick(true);
588
+ },
589
+ onOpen: () => {
590
+ if (opt.onOpen) opt.onOpen();
591
+ setIsOpen(true);
592
+ setIsDoubleClick(true);
593
+ }
594
+ });
595
+ })
596
+ ).subscribe();
597
+ return () => {
598
+ subscribe.unsubscribe();
599
+ };
600
+ }, [containerName]);
601
+ return { isOpen, isDoubleClick, setIsDoubleClick };
602
+ };
603
+ var dragState = new Subject();
604
+ var filterChildren = (obj) => {
605
+ const { children, ...rest } = obj || {};
606
+ return rest;
607
+ };
608
+ var useDragCapture = (targetRef) => {
609
+ const stateRef = useRef(null);
610
+ const forceUpdate = useRef(0);
611
+ useEffect(() => {
612
+ const subscription = dragState.pipe(
613
+ map$1((value) => {
614
+ if (!targetRef || !targetRef.current) return null;
615
+ const { x, y } = value;
616
+ const rect = targetRef.current.getBoundingClientRect();
617
+ const {
618
+ width,
619
+ height,
620
+ x: rectX,
621
+ y: rectY,
622
+ right,
623
+ bottom
624
+ } = rect;
625
+ let isOver = false;
626
+ if (x < rectX || x > right || y < rectY || y > bottom) {
627
+ isOver = true;
628
+ }
629
+ const leftBoundary = rectX + width * 0.2;
630
+ const rightBoundary = right - width * 0.2;
631
+ const topBoundary = rectY + height * 0.2;
632
+ const bottomBoundary = bottom - height * 0.2;
633
+ let position = "centerBoundary";
634
+ if (x < leftBoundary) {
635
+ position = "leftBoundary";
636
+ } else if (x > rightBoundary) {
637
+ position = "rightBoundary";
638
+ } else if (y < topBoundary) {
639
+ position = "topBoundary";
640
+ } else if (y > bottomBoundary) {
641
+ position = "bottomBoundary";
642
+ }
643
+ return {
644
+ positionName: position,
645
+ isOver,
646
+ ...value
647
+ };
648
+ }),
649
+ distinctUntilChanged$1(
650
+ (prev, curr) => equal(filterChildren(prev), filterChildren(curr))
651
+ )
652
+ ).subscribe({
653
+ next: (value) => {
654
+ if (value && !equal(
655
+ filterChildren(stateRef.current),
656
+ filterChildren(value)
657
+ )) {
658
+ stateRef.current = value;
659
+ forceUpdate.current++;
660
+ }
661
+ },
662
+ error: (err) => console.error(err)
663
+ });
664
+ return () => subscription.unsubscribe();
665
+ }, [targetRef]);
666
+ const [, rerender] = useState({});
667
+ useEffect(() => {
668
+ const interval = setInterval(() => {
669
+ rerender({});
670
+ }, 50);
671
+ return () => clearInterval(interval);
672
+ }, []);
673
+ return stateRef.current;
674
+ };
675
+ var dropMovementEventSubject = new Subject();
676
+ var allSplitScreenCount = new BehaviorSubject(0);
677
+ var useDragEvents = ({
678
+ isBlockingActiveInput = false
679
+ }) => {
680
+ const dragResumeTimer = useRef(null);
681
+ const scrollThreshold = 10;
682
+ const isScrolling = useRef(false);
683
+ const isPending = useRef(false);
684
+ const isMouseDown = useRef(false);
685
+ const isDragging = useRef(false);
686
+ const touchStartX = useRef(0);
687
+ const touchStartY = useRef(0);
688
+ const handleStart = useCallback(
689
+ ({
690
+ event: _event,
691
+ dragStartCallback
692
+ }) => {
693
+ const event = _event instanceof Event ? _event : _event.nativeEvent;
694
+ if (dragResumeTimer.current) {
695
+ clearTimeout(dragResumeTimer.current);
696
+ dragResumeTimer.current = null;
697
+ }
698
+ if (event.target.contentEditable === "true" || isBlockingActiveInput && document.activeElement === event.target) {
699
+ return;
700
+ }
701
+ if (event.cancelable) {
702
+ event.preventDefault();
703
+ }
704
+ isPending.current = true;
705
+ isMouseDown.current = true;
706
+ if (event instanceof globalThis.TouchEvent) {
707
+ const touch = event.touches[0];
708
+ touchStartX.current = touch.clientX;
709
+ touchStartY.current = touch.clientY;
710
+ } else if (event instanceof globalThis.MouseEvent) {
711
+ touchStartX.current = event.clientX;
712
+ touchStartY.current = event.clientY;
713
+ }
714
+ setTimeout(() => {
715
+ if (!isPending.current || isScrolling.current) return;
716
+ isPending.current = false;
717
+ isDragging.current = true;
718
+ const xy = getClientXy(event);
719
+ if (!xy) return;
720
+ const { clientX, clientY } = xy;
721
+ dragStartCallback({ x: clientX, y: clientY });
722
+ }, 300);
723
+ },
724
+ [isBlockingActiveInput]
725
+ );
726
+ const handleMove = useCallback(
727
+ ({
728
+ event: _event,
729
+ notDragCallback,
730
+ dragStartCallback,
731
+ moveingCallback
732
+ }) => {
733
+ if (!isMouseDown.current) return;
734
+ const event = _event instanceof Event ? _event : _event.nativeEvent;
735
+ const xy = getClientXy(event);
736
+ if (!xy) return;
737
+ const { clientX, clientY } = xy;
738
+ const deltaX = Math.abs(clientX - touchStartX.current);
739
+ const deltaY = Math.abs(clientY - touchStartY.current);
740
+ if (isPending.current && (deltaX > scrollThreshold || deltaY > scrollThreshold)) {
741
+ isScrolling.current = true;
742
+ isPending.current = false;
743
+ isDragging.current = false;
744
+ if (notDragCallback)
745
+ notDragCallback({ x: clientX, y: clientY });
746
+ if (dragResumeTimer.current) {
747
+ clearTimeout(dragResumeTimer.current);
748
+ dragResumeTimer.current = null;
749
+ }
750
+ dragResumeTimer.current = setTimeout(() => {
751
+ if (!isMouseDown.current) return;
752
+ if (dragStartCallback)
753
+ dragStartCallback({ x: clientX, y: clientY });
754
+ isPending.current = true;
755
+ isScrolling.current = false;
756
+ handleStart({ event: _event, dragStartCallback });
757
+ }, 400);
758
+ return;
759
+ }
760
+ if (!isDragging.current || isPending.current) return;
761
+ moveingCallback({ x: clientX, y: clientY });
762
+ },
763
+ [isBlockingActiveInput]
764
+ );
765
+ const handleEnd = useCallback(
766
+ ({
767
+ event: _event,
768
+ dragEndCallback
769
+ }) => {
770
+ isScrolling.current = false;
771
+ isMouseDown.current = false;
772
+ if (isPending.current) {
773
+ isPending.current = false;
774
+ return;
775
+ }
776
+ const event = _event instanceof Event ? _event : _event.nativeEvent;
777
+ if (!isDragging.current) return;
778
+ isDragging.current = false;
779
+ const xy = getClientXy(event);
780
+ if (!xy) return;
781
+ const { clientX, clientY } = xy;
782
+ dragEndCallback({ x: clientX, y: clientY });
783
+ },
784
+ [isBlockingActiveInput]
785
+ );
786
+ return {
787
+ handleStart,
788
+ handleMove,
789
+ handleEnd
790
+ };
791
+ };
792
+ var folderEventSubject = new Subject();
793
+ var setFolderEvent = (newValue) => {
794
+ folderEventSubject.next(newValue);
795
+ };
796
+ var useFolderEvent = () => {
797
+ const [folderEvent, setFolderEvent2] = useState(
798
+ null
799
+ );
800
+ useEffect(() => {
801
+ const subscription = folderEventSubject.subscribe((e) => {
802
+ if (!e) return;
803
+ setFolderEvent2(e);
804
+ });
805
+ return () => {
806
+ if (subscription) {
807
+ subscription.unsubscribe();
808
+ }
809
+ };
810
+ }, []);
811
+ return { folderEvent };
812
+ };
813
+
814
+ export { ContainerOpenCloseProvider, allSplitScreenCount, closeFlex, containerOpenCloseSubjectMap, containerSpreadSubjectMap, dragState, dropMovementEventSubject, findNotCloseFlexContent, flexContainerStore, flexResizePanelStore, folderEventSubject, getClientXy, getContainerRef, getCurrentSplitScreenComponents, getGrow, getLayoutInfos, getResizePanelRef, getScrollPosition, getSplitScreen, isDocumentOut, isOverMove, layoutSplitScreenStore, mathGrow, mathWeight, openFlex, remain, removeScrollPosition, removeSplitScreenChild, resetRootSplitScreen, resize, scrollPositions, setContainerRef, setFolderEvent, setResizePanelRef, setScrollPosition, setSplitScreen, useContainerSize, useContainers, useDecompositionLayout, useDoubleClick, useDragCapture, useDragEvents, useFolderEvent, useLayoutName };
815
+ //# sourceMappingURL=index.js.map
816
+ //# sourceMappingURL=index.js.map