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