cryptis-video-editor 0.1.4 → 0.1.5

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.esm.js CHANGED
@@ -10,7 +10,7 @@ import StateManager, { ENTER_EDIT_MODE, LAYER_CLONE, LAYER_DELETE, ACTIVE_SPLIT,
10
10
  import { create } from 'zustand';
11
11
  import { Trash, SquareSplitHorizontal, ZoomOut, ZoomIn, Plus, MusicIcon, ArrowRight, ArrowUpRight, CreditCard, BookOpen, CaptionsIcon, ChevronLeft, ChevronRight, Check, X, Copy, LayoutPanelLeft, MoreVertical, FolderClosedIcon, HelpCircle, Home, Image as Image$3, RectangleHorizontalIcon, Laptop, LineChart, Puzzle, MessagesSquare, Moon, Package, File as File$1, RectangleVerticalIcon, FileText, ZapIcon, Search, SquareIcon, Sparkles, SquareStack, SpellCheck, SpellCheck2, Crop, GalleryThumbnails, LaptopMinimal, GalleryVertical, ChevronsUp, Volume2, Settings, WandSparkles, Loader2, SunMedium, Type, User, AlertTriangle, UploadIcon, VideoIcon, AudioLinesIcon, XIcon, CircleCheckIcon, ShareIcon, Download, ChevronDown, PlusIcon, GripVerticalIcon, Music, ChevronDownIcon, CheckIcon, ChevronUpIcon, FileIcon, Video as Video$2, Pause, Play, SearchIcon, Underline, Strikethrough, CircleOff, LassoSelect } from 'lucide-react';
12
12
  import * as SliderPrimitive from '@radix-ui/react-slider';
13
- import { debounce as debounce$1, throttle, isEqual, groupBy } from 'lodash';
13
+ import { debounce, throttle, isEqual, groupBy } from 'lodash';
14
14
  import TimelineBase, { util, Control, resize, controlsUtils, Trimmable, timeMsToUnits as timeMsToUnits$1, unitsToTimeMs as unitsToTimeMs$1, Pattern, Resizable, Helper as Helper$1, Track as Track$1, PreviewTrackItem as PreviewTrackItem$1, TIMELINE_PREFIX, TIMELINE_BOUNDING_CHANGED, generateId, TIMELINE_SEEK, DRAG_PREFIX, DRAG_START, DRAG_END } from '@designcombo/timeline';
15
15
  import { getAudioData, getWaveformPortion, visualizeAudio } from '@remotion/media-utils';
16
16
  import * as ScrollArea$1 from '@radix-ui/react-scroll-area';
@@ -26,6 +26,7 @@ import { BoxAnim, ContentAnim, MaskAnim } from '@designcombo/animations';
26
26
  import styled from '@emotion/styled';
27
27
  import { keyframes, css } from '@emotion/react';
28
28
  import { Player as Player$1 } from '@remotion/player';
29
+ import * as ResizablePrimitive from 'react-resizable-panels';
29
30
  import * as SeparatorPrimitive from '@radix-ui/react-separator';
30
31
  import * as SelectPrimitive from '@radix-ui/react-select';
31
32
  import { AnimatePresence, motion, useAnimation } from 'framer-motion';
@@ -890,7 +891,7 @@ const Ruler = (props) => {
890
891
  resize(canvasRef.current, canvasContext, scrollLeft);
891
892
  }, [canvasContext, scrollLeft, timelineOffsetX]);
892
893
  useEffect(() => {
893
- const resizeHandler = debounce$1(handleResize, 200);
894
+ const resizeHandler = debounce(handleResize, 200);
894
895
  window.addEventListener("resize", resizeHandler);
895
896
  return () => {
896
897
  window.removeEventListener("resize", resizeHandler);
@@ -3374,7 +3375,7 @@ function Navbar({ user, stateManager, setProjectName, projectName }) {
3374
3375
  dispatch(HISTORY_REDO);
3375
3376
  };
3376
3377
  // Create a debounced function for setting the project name
3377
- const debouncedSetProjectName = useCallback(debounce$1((name) => {
3378
+ const debouncedSetProjectName = useCallback(debounce((name) => {
3378
3379
  console.log("Debounced setProjectName:", name);
3379
3380
  setProjectName(name);
3380
3381
  }, 2000), // 2 seconds delay
@@ -31458,2422 +31459,14 @@ const Scene = forwardRef(({ stateManager }, ref) => {
31458
31459
  });
31459
31460
  Scene.displayName = "Scene";
31460
31461
 
31461
- // The "contextmenu" event is not supported as a PointerEvent in all browsers yet, so MouseEvent still need to be handled
31462
-
31463
- const PanelGroupContext = createContext(null);
31464
- PanelGroupContext.displayName = "PanelGroupContext";
31465
-
31466
- const DATA_ATTRIBUTES = {
31467
- group: "data-panel-group",
31468
- groupDirection: "data-panel-group-direction",
31469
- groupId: "data-panel-group-id",
31470
- panel: "data-panel",
31471
- panelCollapsible: "data-panel-collapsible",
31472
- panelId: "data-panel-id",
31473
- panelSize: "data-panel-size",
31474
- resizeHandle: "data-resize-handle",
31475
- resizeHandleActive: "data-resize-handle-active",
31476
- resizeHandleEnabled: "data-panel-resize-handle-enabled",
31477
- resizeHandleId: "data-panel-resize-handle-id",
31478
- resizeHandleState: "data-resize-handle-state"
31479
- };
31480
- const PRECISION = 10;
31481
-
31482
- const useIsomorphicLayoutEffect$1 = useLayoutEffect ;
31483
-
31484
- const useId = React["useId".toString()];
31485
- const wrappedUseId = typeof useId === "function" ? useId : () => null;
31486
- let counter = 0;
31487
- function useUniqueId(idFromParams = null) {
31488
- const idFromUseId = wrappedUseId();
31489
- const idRef = useRef(idFromParams || idFromUseId || null);
31490
- if (idRef.current === null) {
31491
- idRef.current = "" + counter++;
31492
- }
31493
- return idFromParams !== null && idFromParams !== void 0 ? idFromParams : idRef.current;
31494
- }
31495
-
31496
- function PanelWithForwardedRef({
31497
- children,
31498
- className: classNameFromProps = "",
31499
- collapsedSize,
31500
- collapsible,
31501
- defaultSize,
31502
- forwardedRef,
31503
- id: idFromProps,
31504
- maxSize,
31505
- minSize,
31506
- onCollapse,
31507
- onExpand,
31508
- onResize,
31509
- order,
31510
- style: styleFromProps,
31511
- tagName: Type = "div",
31512
- ...rest
31513
- }) {
31514
- const context = useContext(PanelGroupContext);
31515
- if (context === null) {
31516
- throw Error(`Panel components must be rendered within a PanelGroup container`);
31517
- }
31518
- const {
31519
- collapsePanel,
31520
- expandPanel,
31521
- getPanelSize,
31522
- getPanelStyle,
31523
- groupId,
31524
- isPanelCollapsed,
31525
- reevaluatePanelConstraints,
31526
- registerPanel,
31527
- resizePanel,
31528
- unregisterPanel
31529
- } = context;
31530
- const panelId = useUniqueId(idFromProps);
31531
- const panelDataRef = useRef({
31532
- callbacks: {
31533
- onCollapse,
31534
- onExpand,
31535
- onResize
31536
- },
31537
- constraints: {
31538
- collapsedSize,
31539
- collapsible,
31540
- defaultSize,
31541
- maxSize,
31542
- minSize
31543
- },
31544
- id: panelId,
31545
- idIsFromProps: idFromProps !== undefined,
31546
- order
31547
- });
31548
- useRef({
31549
- didLogMissingDefaultSizeWarning: false
31550
- });
31551
- useIsomorphicLayoutEffect$1(() => {
31552
- const {
31553
- callbacks,
31554
- constraints
31555
- } = panelDataRef.current;
31556
- const prevConstraints = {
31557
- ...constraints
31558
- };
31559
- panelDataRef.current.id = panelId;
31560
- panelDataRef.current.idIsFromProps = idFromProps !== undefined;
31561
- panelDataRef.current.order = order;
31562
- callbacks.onCollapse = onCollapse;
31563
- callbacks.onExpand = onExpand;
31564
- callbacks.onResize = onResize;
31565
- constraints.collapsedSize = collapsedSize;
31566
- constraints.collapsible = collapsible;
31567
- constraints.defaultSize = defaultSize;
31568
- constraints.maxSize = maxSize;
31569
- constraints.minSize = minSize;
31570
-
31571
- // If constraints have changed, we should revisit panel sizes.
31572
- // This is uncommon but may happen if people are trying to implement pixel based constraints.
31573
- if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
31574
- reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
31575
- }
31576
- });
31577
- useIsomorphicLayoutEffect$1(() => {
31578
- const panelData = panelDataRef.current;
31579
- registerPanel(panelData);
31580
- return () => {
31581
- unregisterPanel(panelData);
31582
- };
31583
- }, [order, panelId, registerPanel, unregisterPanel]);
31584
- useImperativeHandle(forwardedRef, () => ({
31585
- collapse: () => {
31586
- collapsePanel(panelDataRef.current);
31587
- },
31588
- expand: minSize => {
31589
- expandPanel(panelDataRef.current, minSize);
31590
- },
31591
- getId() {
31592
- return panelId;
31593
- },
31594
- getSize() {
31595
- return getPanelSize(panelDataRef.current);
31596
- },
31597
- isCollapsed() {
31598
- return isPanelCollapsed(panelDataRef.current);
31599
- },
31600
- isExpanded() {
31601
- return !isPanelCollapsed(panelDataRef.current);
31602
- },
31603
- resize: size => {
31604
- resizePanel(panelDataRef.current, size);
31605
- }
31606
- }), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
31607
- const style = getPanelStyle(panelDataRef.current, defaultSize);
31608
- return createElement(Type, {
31609
- ...rest,
31610
- children,
31611
- className: classNameFromProps,
31612
- id: panelId,
31613
- style: {
31614
- ...style,
31615
- ...styleFromProps
31616
- },
31617
- // CSS selectors
31618
- [DATA_ATTRIBUTES.groupId]: groupId,
31619
- [DATA_ATTRIBUTES.panel]: "",
31620
- [DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
31621
- [DATA_ATTRIBUTES.panelId]: panelId,
31622
- [DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
31623
- });
31624
- }
31625
- const Panel$1 = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
31626
- ...props,
31627
- forwardedRef: ref
31628
- }));
31629
- PanelWithForwardedRef.displayName = "Panel";
31630
- Panel$1.displayName = "forwardRef(Panel)";
31631
-
31632
- let currentCursorStyle = null;
31633
- let prevRuleIndex = -1;
31634
- let styleElement = null;
31635
- function getCursorStyle(state, constraintFlags, isPointerDown) {
31636
- const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
31637
- const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
31638
- const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
31639
- const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
31640
- if (constraintFlags) {
31641
- if (horizontalMin) {
31642
- if (verticalMin) {
31643
- return "se-resize";
31644
- } else if (verticalMax) {
31645
- return "ne-resize";
31646
- } else {
31647
- return "e-resize";
31648
- }
31649
- } else if (horizontalMax) {
31650
- if (verticalMin) {
31651
- return "sw-resize";
31652
- } else if (verticalMax) {
31653
- return "nw-resize";
31654
- } else {
31655
- return "w-resize";
31656
- }
31657
- } else if (verticalMin) {
31658
- return "s-resize";
31659
- } else if (verticalMax) {
31660
- return "n-resize";
31661
- }
31662
- }
31663
- switch (state) {
31664
- case "horizontal":
31665
- return "ew-resize";
31666
- case "intersection":
31667
- return "move";
31668
- case "vertical":
31669
- return "ns-resize";
31670
- }
31671
- }
31672
- function resetGlobalCursorStyle() {
31673
- if (styleElement !== null) {
31674
- document.head.removeChild(styleElement);
31675
- currentCursorStyle = null;
31676
- styleElement = null;
31677
- prevRuleIndex = -1;
31678
- }
31679
- }
31680
- function setGlobalCursorStyle(state, constraintFlags, isPointerDown) {
31681
- var _styleElement$sheet$i, _styleElement$sheet2;
31682
- const style = getCursorStyle(state, constraintFlags);
31683
- if (currentCursorStyle === style) {
31684
- return;
31685
- }
31686
- currentCursorStyle = style;
31687
- if (styleElement === null) {
31688
- styleElement = document.createElement("style");
31689
- document.head.appendChild(styleElement);
31690
- }
31691
- if (prevRuleIndex >= 0) {
31692
- var _styleElement$sheet;
31693
- (_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
31694
- }
31695
- prevRuleIndex = (_styleElement$sheet$i = (_styleElement$sheet2 = styleElement.sheet) === null || _styleElement$sheet2 === void 0 ? void 0 : _styleElement$sheet2.insertRule(`*{cursor: ${style} !important;}`)) !== null && _styleElement$sheet$i !== void 0 ? _styleElement$sheet$i : -1;
31696
- }
31697
-
31698
- function isKeyDown(event) {
31699
- return event.type === "keydown";
31700
- }
31701
- function isPointerEvent(event) {
31702
- return event.type.startsWith("pointer");
31703
- }
31704
- function isMouseEvent(event) {
31705
- return event.type.startsWith("mouse");
31706
- }
31707
-
31708
- function getResizeEventCoordinates(event) {
31709
- if (isPointerEvent(event)) {
31710
- if (event.isPrimary) {
31711
- return {
31712
- x: event.clientX,
31713
- y: event.clientY
31714
- };
31715
- }
31716
- } else if (isMouseEvent(event)) {
31717
- return {
31718
- x: event.clientX,
31719
- y: event.clientY
31720
- };
31721
- }
31722
- return {
31723
- x: Infinity,
31724
- y: Infinity
31725
- };
31726
- }
31727
-
31728
- function getInputType() {
31729
- if (typeof matchMedia === "function") {
31730
- return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
31731
- }
31732
- }
31733
-
31734
- function intersects(rectOne, rectTwo, strict) {
31735
- if (strict) {
31736
- return rectOne.x < rectTwo.x + rectTwo.width && rectOne.x + rectOne.width > rectTwo.x && rectOne.y < rectTwo.y + rectTwo.height && rectOne.y + rectOne.height > rectTwo.y;
31737
- } else {
31738
- return rectOne.x <= rectTwo.x + rectTwo.width && rectOne.x + rectOne.width >= rectTwo.x && rectOne.y <= rectTwo.y + rectTwo.height && rectOne.y + rectOne.height >= rectTwo.y;
31739
- }
31740
- }
31741
-
31742
- // Forked from NPM stacking-order@2.0.0
31743
-
31744
- /**
31745
- * Determine which of two nodes appears in front of the other —
31746
- * if `a` is in front, returns 1, otherwise returns -1
31747
- * @param {HTMLElement | SVGElement} a
31748
- * @param {HTMLElement | SVGElement} b
31749
- */
31750
- function compare(a, b) {
31751
- if (a === b) throw new Error("Cannot compare node with itself");
31752
- const ancestors = {
31753
- a: get_ancestors(a),
31754
- b: get_ancestors(b)
31755
- };
31756
- let common_ancestor;
31757
-
31758
- // remove shared ancestors
31759
- while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
31760
- a = ancestors.a.pop();
31761
- b = ancestors.b.pop();
31762
- common_ancestor = a;
31763
- }
31764
- assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
31765
- const z_indexes = {
31766
- a: get_z_index(find_stacking_context(ancestors.a)),
31767
- b: get_z_index(find_stacking_context(ancestors.b))
31768
- };
31769
- if (z_indexes.a === z_indexes.b) {
31770
- const children = common_ancestor.childNodes;
31771
- const furthest_ancestors = {
31772
- a: ancestors.a.at(-1),
31773
- b: ancestors.b.at(-1)
31774
- };
31775
- let i = children.length;
31776
- while (i--) {
31777
- const child = children[i];
31778
- if (child === furthest_ancestors.a) return 1;
31779
- if (child === furthest_ancestors.b) return -1;
31780
- }
31781
- }
31782
- return Math.sign(z_indexes.a - z_indexes.b);
31783
- }
31784
- const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
31785
-
31786
- /** @param {HTMLElement | SVGElement} node */
31787
- function is_flex_item(node) {
31788
- var _get_parent;
31789
- // @ts-ignore
31790
- const display = getComputedStyle((_get_parent = get_parent(node)) !== null && _get_parent !== void 0 ? _get_parent : node).display;
31791
- return display === "flex" || display === "inline-flex";
31792
- }
31793
-
31794
- /** @param {HTMLElement | SVGElement} node */
31795
- function creates_stacking_context(node) {
31796
- const style = getComputedStyle(node);
31797
-
31798
- // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
31799
- if (style.position === "fixed") return true;
31800
- // Forked to fix upstream bug https://github.com/Rich-Harris/stacking-order/issues/3
31801
- // if (
31802
- // (style.zIndex !== "auto" && style.position !== "static") ||
31803
- // is_flex_item(node)
31804
- // )
31805
- if (style.zIndex !== "auto" && (style.position !== "static" || is_flex_item(node))) return true;
31806
- if (+style.opacity < 1) return true;
31807
- if ("transform" in style && style.transform !== "none") return true;
31808
- if ("webkitTransform" in style && style.webkitTransform !== "none") return true;
31809
- if ("mixBlendMode" in style && style.mixBlendMode !== "normal") return true;
31810
- if ("filter" in style && style.filter !== "none") return true;
31811
- if ("webkitFilter" in style && style.webkitFilter !== "none") return true;
31812
- if ("isolation" in style && style.isolation === "isolate") return true;
31813
- if (props.test(style.willChange)) return true;
31814
- // @ts-expect-error
31815
- if (style.webkitOverflowScrolling === "touch") return true;
31816
- return false;
31817
- }
31818
-
31819
- /** @param {(HTMLElement| SVGElement)[]} nodes */
31820
- function find_stacking_context(nodes) {
31821
- let i = nodes.length;
31822
- while (i--) {
31823
- const node = nodes[i];
31824
- assert(node, "Missing node");
31825
- if (creates_stacking_context(node)) return node;
31826
- }
31827
- return null;
31828
- }
31829
-
31830
- /** @param {HTMLElement | SVGElement} node */
31831
- function get_z_index(node) {
31832
- return node && Number(getComputedStyle(node).zIndex) || 0;
31833
- }
31834
-
31835
- /** @param {HTMLElement} node */
31836
- function get_ancestors(node) {
31837
- const ancestors = [];
31838
- while (node) {
31839
- ancestors.push(node);
31840
- // @ts-ignore
31841
- node = get_parent(node);
31842
- }
31843
- return ancestors; // [ node, ... <body>, <html>, document ]
31844
- }
31845
-
31846
- /** @param {HTMLElement} node */
31847
- function get_parent(node) {
31848
- const {
31849
- parentNode
31850
- } = node;
31851
- if (parentNode && parentNode instanceof ShadowRoot) {
31852
- return parentNode.host;
31853
- }
31854
- return parentNode;
31855
- }
31856
-
31857
- const EXCEEDED_HORIZONTAL_MIN = 0b0001;
31858
- const EXCEEDED_HORIZONTAL_MAX = 0b0010;
31859
- const EXCEEDED_VERTICAL_MIN = 0b0100;
31860
- const EXCEEDED_VERTICAL_MAX = 0b1000;
31861
- const isCoarsePointer = getInputType() === "coarse";
31862
- let intersectingHandles = [];
31863
- let isPointerDown = false;
31864
- let ownerDocumentCounts = new Map();
31865
- let panelConstraintFlags = new Map();
31866
- const registeredResizeHandlers = new Set();
31867
- function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
31868
- var _ownerDocumentCounts$;
31869
- const {
31870
- ownerDocument
31871
- } = element;
31872
- const data = {
31873
- direction,
31874
- element,
31875
- hitAreaMargins,
31876
- setResizeHandlerState
31877
- };
31878
- const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
31879
- ownerDocumentCounts.set(ownerDocument, count + 1);
31880
- registeredResizeHandlers.add(data);
31881
- updateListeners();
31882
- return function unregisterResizeHandle() {
31883
- var _ownerDocumentCounts$2;
31884
- panelConstraintFlags.delete(resizeHandleId);
31885
- registeredResizeHandlers.delete(data);
31886
- const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
31887
- ownerDocumentCounts.set(ownerDocument, count - 1);
31888
- updateListeners();
31889
- if (count === 1) {
31890
- ownerDocumentCounts.delete(ownerDocument);
31891
- }
31892
-
31893
- // If the resize handle that is currently unmounting is intersecting with the pointer,
31894
- // update the global pointer to account for the change
31895
- if (intersectingHandles.includes(data)) {
31896
- const index = intersectingHandles.indexOf(data);
31897
- if (index >= 0) {
31898
- intersectingHandles.splice(index, 1);
31899
- }
31900
- updateCursor();
31901
-
31902
- // Also instruct the handle to stop dragging; this prevents the parent group from being left in an inconsistent state
31903
- // See github.com/bvaughn/react-resizable-panels/issues/402
31904
- setResizeHandlerState("up", true, null);
31905
- }
31906
- };
31907
- }
31908
- function handlePointerDown(event) {
31909
- const {
31910
- target
31911
- } = event;
31912
- const {
31913
- x,
31914
- y
31915
- } = getResizeEventCoordinates(event);
31916
- isPointerDown = true;
31917
- recalculateIntersectingHandles({
31918
- target,
31919
- x,
31920
- y
31921
- });
31922
- updateListeners();
31923
- if (intersectingHandles.length > 0) {
31924
- updateResizeHandlerStates("down", event);
31925
-
31926
- // Update cursor based on return value(s) from active handles
31927
- updateCursor();
31928
- event.preventDefault();
31929
- if (!isWithinResizeHandle(target)) {
31930
- event.stopImmediatePropagation();
31931
- }
31932
- }
31933
- }
31934
- function handlePointerMove(event) {
31935
- const {
31936
- x,
31937
- y
31938
- } = getResizeEventCoordinates(event);
31939
-
31940
- // Edge case (see #340)
31941
- // Detect when the pointer has been released outside an iframe on a different domain
31942
- if (isPointerDown &&
31943
- // Skip this check for "pointerleave" events, else Firefox triggers a false positive (see #514)
31944
- event.type !== "pointerleave" && event.buttons === 0) {
31945
- isPointerDown = false;
31946
- updateResizeHandlerStates("up", event);
31947
- }
31948
- if (!isPointerDown) {
31949
- const {
31950
- target
31951
- } = event;
31952
-
31953
- // Recalculate intersecting handles whenever the pointer moves, except if it has already been pressed
31954
- // at that point, the handles may not move with the pointer (depending on constraints)
31955
- // but the same set of active handles should be locked until the pointer is released
31956
- recalculateIntersectingHandles({
31957
- target,
31958
- x,
31959
- y
31960
- });
31961
- }
31962
- updateResizeHandlerStates("move", event);
31963
-
31964
- // Update cursor based on return value(s) from active handles
31965
- updateCursor();
31966
- if (intersectingHandles.length > 0) {
31967
- event.preventDefault();
31968
- }
31969
- }
31970
- function handlePointerUp(event) {
31971
- const {
31972
- target
31973
- } = event;
31974
- const {
31975
- x,
31976
- y
31977
- } = getResizeEventCoordinates(event);
31978
- panelConstraintFlags.clear();
31979
- isPointerDown = false;
31980
- if (intersectingHandles.length > 0) {
31981
- event.preventDefault();
31982
- if (!isWithinResizeHandle(target)) {
31983
- event.stopImmediatePropagation();
31984
- }
31985
- }
31986
- updateResizeHandlerStates("up", event);
31987
- recalculateIntersectingHandles({
31988
- target,
31989
- x,
31990
- y
31991
- });
31992
- updateCursor();
31993
- updateListeners();
31994
- }
31995
- function isWithinResizeHandle(element) {
31996
- let currentElement = element;
31997
- while (currentElement) {
31998
- if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
31999
- return true;
32000
- }
32001
- currentElement = currentElement.parentElement;
32002
- }
32003
- return false;
32004
- }
32005
- function recalculateIntersectingHandles({
32006
- target,
32007
- x,
32008
- y
32009
- }) {
32010
- intersectingHandles.splice(0);
32011
- let targetElement = null;
32012
- if (target instanceof HTMLElement || target instanceof SVGElement) {
32013
- targetElement = target;
32014
- }
32015
- registeredResizeHandlers.forEach(data => {
32016
- const {
32017
- element: dragHandleElement,
32018
- hitAreaMargins
32019
- } = data;
32020
- const dragHandleRect = dragHandleElement.getBoundingClientRect();
32021
- const {
32022
- bottom,
32023
- left,
32024
- right,
32025
- top
32026
- } = dragHandleRect;
32027
- const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
32028
- const eventIntersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
32029
- if (eventIntersects) {
32030
- // TRICKY
32031
- // We listen for pointers events at the root in order to support hit area margins
32032
- // (determining when the pointer is close enough to an element to be considered a "hit")
32033
- // Clicking on an element "above" a handle (e.g. a modal) should prevent a hit though
32034
- // so at this point we need to compare stacking order of a potentially intersecting drag handle,
32035
- // and the element that was actually clicked/touched
32036
- if (targetElement !== null && document.contains(targetElement) && dragHandleElement !== targetElement && !dragHandleElement.contains(targetElement) && !targetElement.contains(dragHandleElement) &&
32037
- // Calculating stacking order has a cost, so we should avoid it if possible
32038
- // That is why we only check potentially intersecting handles,
32039
- // and why we skip if the event target is within the handle's DOM
32040
- compare(targetElement, dragHandleElement) > 0) {
32041
- // If the target is above the drag handle, then we also need to confirm they overlap
32042
- // If they are beside each other (e.g. a panel and its drag handle) then the handle is still interactive
32043
- //
32044
- // It's not enough to compare only the target
32045
- // The target might be a small element inside of a larger container
32046
- // (For example, a SPAN or a DIV inside of a larger modal dialog)
32047
- let currentElement = targetElement;
32048
- let didIntersect = false;
32049
- while (currentElement) {
32050
- if (currentElement.contains(dragHandleElement)) {
32051
- break;
32052
- } else if (intersects(currentElement.getBoundingClientRect(), dragHandleRect, true)) {
32053
- didIntersect = true;
32054
- break;
32055
- }
32056
- currentElement = currentElement.parentElement;
32057
- }
32058
- if (didIntersect) {
32059
- return;
32060
- }
32061
- }
32062
- intersectingHandles.push(data);
32063
- }
32064
- });
32065
- }
32066
- function reportConstraintsViolation(resizeHandleId, flag) {
32067
- panelConstraintFlags.set(resizeHandleId, flag);
32068
- }
32069
- function updateCursor() {
32070
- let intersectsHorizontal = false;
32071
- let intersectsVertical = false;
32072
- intersectingHandles.forEach(data => {
32073
- const {
32074
- direction
32075
- } = data;
32076
- if (direction === "horizontal") {
32077
- intersectsHorizontal = true;
32078
- } else {
32079
- intersectsVertical = true;
32080
- }
32081
- });
32082
- let constraintFlags = 0;
32083
- panelConstraintFlags.forEach(flag => {
32084
- constraintFlags |= flag;
32085
- });
32086
- if (intersectsHorizontal && intersectsVertical) {
32087
- setGlobalCursorStyle("intersection", constraintFlags);
32088
- } else if (intersectsHorizontal) {
32089
- setGlobalCursorStyle("horizontal", constraintFlags);
32090
- } else if (intersectsVertical) {
32091
- setGlobalCursorStyle("vertical", constraintFlags);
32092
- } else {
32093
- resetGlobalCursorStyle();
32094
- }
32095
- }
32096
- let listenersAbortController;
32097
- function updateListeners() {
32098
- var _listenersAbortContro;
32099
- (_listenersAbortContro = listenersAbortController) === null || _listenersAbortContro === void 0 ? void 0 : _listenersAbortContro.abort();
32100
- listenersAbortController = new AbortController();
32101
- const options = {
32102
- capture: true,
32103
- signal: listenersAbortController.signal
32104
- };
32105
- if (!registeredResizeHandlers.size) {
32106
- return;
32107
- }
32108
- if (isPointerDown) {
32109
- if (intersectingHandles.length > 0) {
32110
- ownerDocumentCounts.forEach((count, ownerDocument) => {
32111
- const {
32112
- body
32113
- } = ownerDocument;
32114
- if (count > 0) {
32115
- body.addEventListener("contextmenu", handlePointerUp, options);
32116
- body.addEventListener("pointerleave", handlePointerMove, options);
32117
- body.addEventListener("pointermove", handlePointerMove, options);
32118
- }
32119
- });
32120
- }
32121
- ownerDocumentCounts.forEach((_, ownerDocument) => {
32122
- const {
32123
- body
32124
- } = ownerDocument;
32125
- body.addEventListener("pointerup", handlePointerUp, options);
32126
- body.addEventListener("pointercancel", handlePointerUp, options);
32127
- });
32128
- } else {
32129
- ownerDocumentCounts.forEach((count, ownerDocument) => {
32130
- const {
32131
- body
32132
- } = ownerDocument;
32133
- if (count > 0) {
32134
- body.addEventListener("pointerdown", handlePointerDown, options);
32135
- body.addEventListener("pointermove", handlePointerMove, options);
32136
- }
32137
- });
32138
- }
32139
- }
32140
- function updateResizeHandlerStates(action, event) {
32141
- registeredResizeHandlers.forEach(data => {
32142
- const {
32143
- setResizeHandlerState
32144
- } = data;
32145
- const isActive = intersectingHandles.includes(data);
32146
- setResizeHandlerState(action, isActive, event);
32147
- });
32148
- }
32149
-
32150
- function useForceUpdate() {
32151
- const [_, setCount] = useState(0);
32152
- return useCallback(() => setCount(prevCount => prevCount + 1), []);
32153
- }
32154
-
32155
- function assert(expectedCondition, message) {
32156
- if (!expectedCondition) {
32157
- console.error(message);
32158
- throw Error(message);
32159
- }
32160
- }
32161
-
32162
- function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
32163
- if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
32164
- return 0;
32165
- } else {
32166
- return actual > expected ? 1 : -1;
32167
- }
32168
- }
32169
- function fuzzyNumbersEqual$1(actual, expected, fractionDigits = PRECISION) {
32170
- return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
32171
- }
32172
-
32173
- function fuzzyNumbersEqual(actual, expected, fractionDigits) {
32174
- return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
32175
- }
32176
-
32177
- function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
32178
- if (actual.length !== expected.length) {
32179
- return false;
32180
- }
32181
- for (let index = 0; index < actual.length; index++) {
32182
- const actualSize = actual[index];
32183
- const expectedSize = expected[index];
32184
- if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
32185
- return false;
32186
- }
32187
- }
32188
- return true;
32189
- }
32190
-
32191
- // Panel size must be in percentages; pixel values should be pre-converted
32192
- function resizePanel({
32193
- panelConstraints: panelConstraintsArray,
32194
- panelIndex,
32195
- size
32196
- }) {
32197
- const panelConstraints = panelConstraintsArray[panelIndex];
32198
- assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
32199
- let {
32200
- collapsedSize = 0,
32201
- collapsible,
32202
- maxSize = 100,
32203
- minSize = 0
32204
- } = panelConstraints;
32205
- if (fuzzyCompareNumbers(size, minSize) < 0) {
32206
- if (collapsible) {
32207
- // Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
32208
- const halfwayPoint = (collapsedSize + minSize) / 2;
32209
- if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
32210
- size = collapsedSize;
32211
- } else {
32212
- size = minSize;
32213
- }
32214
- } else {
32215
- size = minSize;
32216
- }
32217
- }
32218
- size = Math.min(maxSize, size);
32219
- size = parseFloat(size.toFixed(PRECISION));
32220
- return size;
32221
- }
32222
-
32223
- // All units must be in percentages; pixel values should be pre-converted
32224
- function adjustLayoutByDelta({
32225
- delta,
32226
- initialLayout,
32227
- panelConstraints: panelConstraintsArray,
32228
- pivotIndices,
32229
- prevLayout,
32230
- trigger
32231
- }) {
32232
- if (fuzzyNumbersEqual(delta, 0)) {
32233
- return initialLayout;
32234
- }
32235
- const nextLayout = [...initialLayout];
32236
- const [firstPivotIndex, secondPivotIndex] = pivotIndices;
32237
- assert(firstPivotIndex != null, "Invalid first pivot index");
32238
- assert(secondPivotIndex != null, "Invalid second pivot index");
32239
- let deltaApplied = 0;
32240
-
32241
- // const DEBUG = [];
32242
- // DEBUG.push(`adjustLayoutByDelta()`);
32243
- // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
32244
- // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
32245
- // DEBUG.push(` delta: ${delta}`);
32246
- // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
32247
- // DEBUG.push(` trigger: ${trigger}`);
32248
- // DEBUG.push("");
32249
-
32250
- // A resizing panel affects the panels before or after it.
32251
- //
32252
- // A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
32253
- // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
32254
- //
32255
- // A positive delta means the panel(s) immediately before the resize handle should "expand".
32256
- // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
32257
-
32258
- {
32259
- // If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
32260
- // We no longer check the halfway threshold because this may prevent the panel from expanding at all.
32261
- if (trigger === "keyboard") {
32262
- {
32263
- // Check if we should expand a collapsed panel
32264
- const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
32265
- const panelConstraints = panelConstraintsArray[index];
32266
- assert(panelConstraints, `Panel constraints not found for index ${index}`);
32267
- const {
32268
- collapsedSize = 0,
32269
- collapsible,
32270
- minSize = 0
32271
- } = panelConstraints;
32272
-
32273
- // DEBUG.push(`edge case check 1: ${index}`);
32274
- // DEBUG.push(` -> collapsible? ${collapsible}`);
32275
- if (collapsible) {
32276
- const prevSize = initialLayout[index];
32277
- assert(prevSize != null, `Previous layout not found for panel index ${index}`);
32278
- if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
32279
- const localDelta = minSize - prevSize;
32280
- // DEBUG.push(` -> expand delta: ${localDelta}`);
32281
-
32282
- if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
32283
- delta = delta < 0 ? 0 - localDelta : localDelta;
32284
- // DEBUG.push(` -> delta: ${delta}`);
32285
- }
32286
- }
32287
- }
32288
- }
32289
-
32290
- {
32291
- // Check if we should collapse a panel at its minimum size
32292
- const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
32293
- const panelConstraints = panelConstraintsArray[index];
32294
- assert(panelConstraints, `No panel constraints found for index ${index}`);
32295
- const {
32296
- collapsedSize = 0,
32297
- collapsible,
32298
- minSize = 0
32299
- } = panelConstraints;
32300
-
32301
- // DEBUG.push(`edge case check 2: ${index}`);
32302
- // DEBUG.push(` -> collapsible? ${collapsible}`);
32303
- if (collapsible) {
32304
- const prevSize = initialLayout[index];
32305
- assert(prevSize != null, `Previous layout not found for panel index ${index}`);
32306
- if (fuzzyNumbersEqual(prevSize, minSize)) {
32307
- const localDelta = prevSize - collapsedSize;
32308
- // DEBUG.push(` -> expand delta: ${localDelta}`);
32309
-
32310
- if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
32311
- delta = delta < 0 ? 0 - localDelta : localDelta;
32312
- // DEBUG.push(` -> delta: ${delta}`);
32313
- }
32314
- }
32315
- }
32316
- }
32317
- }
32318
- // DEBUG.push("");
32319
- }
32320
-
32321
- {
32322
- // Pre-calculate max available delta in the opposite direction of our pivot.
32323
- // This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
32324
- // If this amount is less than the requested delta, adjust the requested delta.
32325
- // If this amount is greater than the requested delta, that's useful information too–
32326
- // as an expanding panel might change from collapsed to min size.
32327
-
32328
- const increment = delta < 0 ? 1 : -1;
32329
- let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
32330
- let maxAvailableDelta = 0;
32331
-
32332
- // DEBUG.push("pre calc...");
32333
- while (true) {
32334
- const prevSize = initialLayout[index];
32335
- assert(prevSize != null, `Previous layout not found for panel index ${index}`);
32336
- const maxSafeSize = resizePanel({
32337
- panelConstraints: panelConstraintsArray,
32338
- panelIndex: index,
32339
- size: 100
32340
- });
32341
- const delta = maxSafeSize - prevSize;
32342
- // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
32343
-
32344
- maxAvailableDelta += delta;
32345
- index += increment;
32346
- if (index < 0 || index >= panelConstraintsArray.length) {
32347
- break;
32348
- }
32349
- }
32350
-
32351
- // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
32352
- const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
32353
- delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
32354
- // DEBUG.push(` -> adjusted delta: ${delta}`);
32355
- // DEBUG.push("");
32356
- }
32357
-
32358
- {
32359
- // Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
32360
-
32361
- const pivotIndex = delta < 0 ? firstPivotIndex : secondPivotIndex;
32362
- let index = pivotIndex;
32363
- while (index >= 0 && index < panelConstraintsArray.length) {
32364
- const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
32365
- const prevSize = initialLayout[index];
32366
- assert(prevSize != null, `Previous layout not found for panel index ${index}`);
32367
- const unsafeSize = prevSize - deltaRemaining;
32368
- const safeSize = resizePanel({
32369
- panelConstraints: panelConstraintsArray,
32370
- panelIndex: index,
32371
- size: unsafeSize
32372
- });
32373
- if (!fuzzyNumbersEqual(prevSize, safeSize)) {
32374
- deltaApplied += prevSize - safeSize;
32375
- nextLayout[index] = safeSize;
32376
- if (deltaApplied.toFixed(3).localeCompare(Math.abs(delta).toFixed(3), undefined, {
32377
- numeric: true
32378
- }) >= 0) {
32379
- break;
32380
- }
32381
- }
32382
- if (delta < 0) {
32383
- index--;
32384
- } else {
32385
- index++;
32386
- }
32387
- }
32388
- }
32389
- // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
32390
- // DEBUG.push(` deltaApplied: ${deltaApplied}`);
32391
- // DEBUG.push("");
32392
-
32393
- // If we were unable to resize any of the panels panels, return the previous state.
32394
- // This will essentially bailout and ignore e.g. drags past a panel's boundaries
32395
- if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
32396
- // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
32397
- // console.log(DEBUG.join("\n"));
32398
-
32399
- return prevLayout;
32400
- }
32401
- {
32402
- // Now distribute the applied delta to the panels in the other direction
32403
- const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
32404
- const prevSize = initialLayout[pivotIndex];
32405
- assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
32406
- const unsafeSize = prevSize + deltaApplied;
32407
- const safeSize = resizePanel({
32408
- panelConstraints: panelConstraintsArray,
32409
- panelIndex: pivotIndex,
32410
- size: unsafeSize
32411
- });
32412
-
32413
- // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
32414
- nextLayout[pivotIndex] = safeSize;
32415
-
32416
- // Edge case where expanding or contracting one panel caused another one to change collapsed state
32417
- if (!fuzzyNumbersEqual(safeSize, unsafeSize)) {
32418
- let deltaRemaining = unsafeSize - safeSize;
32419
- const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
32420
- let index = pivotIndex;
32421
- while (index >= 0 && index < panelConstraintsArray.length) {
32422
- const prevSize = nextLayout[index];
32423
- assert(prevSize != null, `Previous layout not found for panel index ${index}`);
32424
- const unsafeSize = prevSize + deltaRemaining;
32425
- const safeSize = resizePanel({
32426
- panelConstraints: panelConstraintsArray,
32427
- panelIndex: index,
32428
- size: unsafeSize
32429
- });
32430
- if (!fuzzyNumbersEqual(prevSize, safeSize)) {
32431
- deltaRemaining -= safeSize - prevSize;
32432
- nextLayout[index] = safeSize;
32433
- }
32434
- if (fuzzyNumbersEqual(deltaRemaining, 0)) {
32435
- break;
32436
- }
32437
- if (delta > 0) {
32438
- index--;
32439
- } else {
32440
- index++;
32441
- }
32442
- }
32443
- }
32444
- }
32445
- // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
32446
- // DEBUG.push(` deltaApplied: ${deltaApplied}`);
32447
- // DEBUG.push("");
32448
-
32449
- const totalSize = nextLayout.reduce((total, size) => size + total, 0);
32450
- // DEBUG.push(`total size: ${totalSize}`);
32451
-
32452
- // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
32453
- // In that case, fall back to our most recent valid layout
32454
- if (!fuzzyNumbersEqual(totalSize, 100)) {
32455
- // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
32456
- // console.log(DEBUG.join("\n"));
32457
-
32458
- return prevLayout;
32459
- }
32460
-
32461
- // console.log(DEBUG.join("\n"));
32462
- return nextLayout;
32463
- }
32464
-
32465
- function calculateAriaValues({
32466
- layout,
32467
- panelsArray,
32468
- pivotIndices
32469
- }) {
32470
- let currentMinSize = 0;
32471
- let currentMaxSize = 100;
32472
- let totalMinSize = 0;
32473
- let totalMaxSize = 0;
32474
- const firstIndex = pivotIndices[0];
32475
- assert(firstIndex != null, "No pivot index found");
32476
-
32477
- // A panel's effective min/max sizes also need to account for other panel's sizes.
32478
- panelsArray.forEach((panelData, index) => {
32479
- const {
32480
- constraints
32481
- } = panelData;
32482
- const {
32483
- maxSize = 100,
32484
- minSize = 0
32485
- } = constraints;
32486
- if (index === firstIndex) {
32487
- currentMinSize = minSize;
32488
- currentMaxSize = maxSize;
32489
- } else {
32490
- totalMinSize += minSize;
32491
- totalMaxSize += maxSize;
32492
- }
32493
- });
32494
- const valueMax = Math.min(currentMaxSize, 100 - totalMinSize);
32495
- const valueMin = Math.max(currentMinSize, 100 - totalMaxSize);
32496
- const valueNow = layout[firstIndex];
32497
- return {
32498
- valueMax,
32499
- valueMin,
32500
- valueNow
32501
- };
32502
- }
32503
-
32504
- function getResizeHandleElementsForGroup(groupId, scope = document) {
32505
- return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
32506
- }
32507
-
32508
- function getResizeHandleElementIndex(groupId, id, scope = document) {
32509
- const handles = getResizeHandleElementsForGroup(groupId, scope);
32510
- const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
32511
- return index !== null && index !== void 0 ? index : null;
32512
- }
32513
-
32514
- function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
32515
- const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
32516
- return index != null ? [index, index + 1] : [-1, -1];
32517
- }
32518
-
32519
- function isHTMLElement(target) {
32520
- if (target instanceof HTMLElement) {
32521
- return true;
32522
- }
32523
-
32524
- // Fallback to duck typing to handle edge case of portals within a popup window
32525
- return typeof target === "object" && target !== null && "tagName" in target && "getAttribute" in target;
32526
- }
32527
-
32528
- function getPanelGroupElement(id, rootElement = document) {
32529
- // If the root element is the PanelGroup
32530
- if (isHTMLElement(rootElement) && rootElement.dataset.panelGroupId == id) {
32531
- return rootElement;
32532
- }
32533
-
32534
- // Else query children
32535
- const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
32536
- if (element) {
32537
- return element;
32538
- }
32539
- return null;
32540
- }
32541
-
32542
- function getResizeHandleElement(id, scope = document) {
32543
- const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
32544
- if (element) {
32545
- return element;
32546
- }
32547
- return null;
32548
- }
32549
-
32550
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
32551
- var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
32552
- const handle = getResizeHandleElement(handleId, scope);
32553
- const handles = getResizeHandleElementsForGroup(groupId, scope);
32554
- const index = handle ? handles.indexOf(handle) : -1;
32555
- const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
32556
- const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
32557
- return [idBefore, idAfter];
32558
- }
32559
-
32560
- // https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
32561
-
32562
- function useWindowSplitterPanelGroupBehavior({
32563
- committedValuesRef,
32564
- eagerValuesRef,
32565
- groupId,
32566
- layout,
32567
- panelDataArray,
32568
- panelGroupElement,
32569
- setLayout
32570
- }) {
32571
- useRef({
32572
- didWarnAboutMissingResizeHandle: false
32573
- });
32574
- useIsomorphicLayoutEffect$1(() => {
32575
- if (!panelGroupElement) {
32576
- return;
32577
- }
32578
- const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
32579
- for (let index = 0; index < panelDataArray.length - 1; index++) {
32580
- const {
32581
- valueMax,
32582
- valueMin,
32583
- valueNow
32584
- } = calculateAriaValues({
32585
- layout,
32586
- panelsArray: panelDataArray,
32587
- pivotIndices: [index, index + 1]
32588
- });
32589
- const resizeHandleElement = resizeHandleElements[index];
32590
- if (resizeHandleElement == null) ; else {
32591
- const panelData = panelDataArray[index];
32592
- assert(panelData, `No panel data found for index "${index}"`);
32593
- resizeHandleElement.setAttribute("aria-controls", panelData.id);
32594
- resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
32595
- resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
32596
- resizeHandleElement.setAttribute("aria-valuenow", valueNow != null ? "" + Math.round(valueNow) : "");
32597
- }
32598
- }
32599
- return () => {
32600
- resizeHandleElements.forEach((resizeHandleElement, index) => {
32601
- resizeHandleElement.removeAttribute("aria-controls");
32602
- resizeHandleElement.removeAttribute("aria-valuemax");
32603
- resizeHandleElement.removeAttribute("aria-valuemin");
32604
- resizeHandleElement.removeAttribute("aria-valuenow");
32605
- });
32606
- };
32607
- }, [groupId, layout, panelDataArray, panelGroupElement]);
32608
- useEffect(() => {
32609
- if (!panelGroupElement) {
32610
- return;
32611
- }
32612
- const eagerValues = eagerValuesRef.current;
32613
- assert(eagerValues, `Eager values not found`);
32614
- const {
32615
- panelDataArray
32616
- } = eagerValues;
32617
- const groupElement = getPanelGroupElement(groupId, panelGroupElement);
32618
- assert(groupElement != null, `No group found for id "${groupId}"`);
32619
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
32620
- assert(handles, `No resize handles found for group id "${groupId}"`);
32621
- const cleanupFunctions = handles.map(handle => {
32622
- const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
32623
- assert(handleId, `Resize handle element has no handle id attribute`);
32624
- const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
32625
- if (idBefore == null || idAfter == null) {
32626
- return () => {};
32627
- }
32628
- const onKeyDown = event => {
32629
- if (event.defaultPrevented) {
32630
- return;
32631
- }
32632
- switch (event.key) {
32633
- case "Enter":
32634
- {
32635
- event.preventDefault();
32636
- const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
32637
- if (index >= 0) {
32638
- const panelData = panelDataArray[index];
32639
- assert(panelData, `No panel data found for index ${index}`);
32640
- const size = layout[index];
32641
- const {
32642
- collapsedSize = 0,
32643
- collapsible,
32644
- minSize = 0
32645
- } = panelData.constraints;
32646
- if (size != null && collapsible) {
32647
- const nextLayout = adjustLayoutByDelta({
32648
- delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
32649
- initialLayout: layout,
32650
- panelConstraints: panelDataArray.map(panelData => panelData.constraints),
32651
- pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
32652
- prevLayout: layout,
32653
- trigger: "keyboard"
32654
- });
32655
- if (layout !== nextLayout) {
32656
- setLayout(nextLayout);
32657
- }
32658
- }
32659
- }
32660
- break;
32661
- }
32662
- }
32663
- };
32664
- handle.addEventListener("keydown", onKeyDown);
32665
- return () => {
32666
- handle.removeEventListener("keydown", onKeyDown);
32667
- };
32668
- });
32669
- return () => {
32670
- cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
32671
- };
32672
- }, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
32673
- }
32674
-
32675
- function areEqual(arrayA, arrayB) {
32676
- if (arrayA.length !== arrayB.length) {
32677
- return false;
32678
- }
32679
- for (let index = 0; index < arrayA.length; index++) {
32680
- if (arrayA[index] !== arrayB[index]) {
32681
- return false;
32682
- }
32683
- }
32684
- return true;
32685
- }
32686
-
32687
- function getResizeEventCursorPosition(direction, event) {
32688
- const isHorizontal = direction === "horizontal";
32689
- const {
32690
- x,
32691
- y
32692
- } = getResizeEventCoordinates(event);
32693
- return isHorizontal ? x : y;
32694
- }
32695
-
32696
- function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
32697
- const isHorizontal = direction === "horizontal";
32698
- const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
32699
- assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
32700
- const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
32701
- assert(groupId, `Resize handle element has no group id attribute`);
32702
- let {
32703
- initialCursorPosition
32704
- } = initialDragState;
32705
- const cursorPosition = getResizeEventCursorPosition(direction, event);
32706
- const groupElement = getPanelGroupElement(groupId, panelGroupElement);
32707
- assert(groupElement, `No group element found for id "${groupId}"`);
32708
- const groupRect = groupElement.getBoundingClientRect();
32709
- const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
32710
- const offsetPixels = cursorPosition - initialCursorPosition;
32711
- const offsetPercentage = offsetPixels / groupSizeInPixels * 100;
32712
- return offsetPercentage;
32713
- }
32714
-
32715
- // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
32716
- function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
32717
- if (isKeyDown(event)) {
32718
- const isHorizontal = direction === "horizontal";
32719
- let delta = 0;
32720
- if (event.shiftKey) {
32721
- delta = 100;
32722
- } else if (keyboardResizeBy != null) {
32723
- delta = keyboardResizeBy;
32724
- } else {
32725
- delta = 10;
32726
- }
32727
- let movement = 0;
32728
- switch (event.key) {
32729
- case "ArrowDown":
32730
- movement = isHorizontal ? 0 : delta;
32731
- break;
32732
- case "ArrowLeft":
32733
- movement = isHorizontal ? -delta : 0;
32734
- break;
32735
- case "ArrowRight":
32736
- movement = isHorizontal ? delta : 0;
32737
- break;
32738
- case "ArrowUp":
32739
- movement = isHorizontal ? 0 : -delta;
32740
- break;
32741
- case "End":
32742
- movement = 100;
32743
- break;
32744
- case "Home":
32745
- movement = -100;
32746
- break;
32747
- }
32748
- return movement;
32749
- } else {
32750
- if (initialDragState == null) {
32751
- return 0;
32752
- }
32753
- return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
32754
- }
32755
- }
32756
-
32757
- function calculateUnsafeDefaultLayout({
32758
- panelDataArray
32759
- }) {
32760
- const layout = Array(panelDataArray.length);
32761
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
32762
- let numPanelsWithSizes = 0;
32763
- let remainingSize = 100;
32764
-
32765
- // Distribute default sizes first
32766
- for (let index = 0; index < panelDataArray.length; index++) {
32767
- const panelConstraints = panelConstraintsArray[index];
32768
- assert(panelConstraints, `Panel constraints not found for index ${index}`);
32769
- const {
32770
- defaultSize
32771
- } = panelConstraints;
32772
- if (defaultSize != null) {
32773
- numPanelsWithSizes++;
32774
- layout[index] = defaultSize;
32775
- remainingSize -= defaultSize;
32776
- }
32777
- }
32778
-
32779
- // Remaining size should be distributed evenly between panels without default sizes
32780
- for (let index = 0; index < panelDataArray.length; index++) {
32781
- const panelConstraints = panelConstraintsArray[index];
32782
- assert(panelConstraints, `Panel constraints not found for index ${index}`);
32783
- const {
32784
- defaultSize
32785
- } = panelConstraints;
32786
- if (defaultSize != null) {
32787
- continue;
32788
- }
32789
- const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
32790
- const size = remainingSize / numRemainingPanels;
32791
- numPanelsWithSizes++;
32792
- layout[index] = size;
32793
- remainingSize -= size;
32794
- }
32795
- return layout;
32796
- }
32797
-
32798
- // Layout should be pre-converted into percentages
32799
- function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
32800
- layout.forEach((size, index) => {
32801
- const panelData = panelsArray[index];
32802
- assert(panelData, `Panel data not found for index ${index}`);
32803
- const {
32804
- callbacks,
32805
- constraints,
32806
- id: panelId
32807
- } = panelData;
32808
- const {
32809
- collapsedSize = 0,
32810
- collapsible
32811
- } = constraints;
32812
- const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
32813
- if (lastNotifiedSize == null || size !== lastNotifiedSize) {
32814
- panelIdToLastNotifiedSizeMap[panelId] = size;
32815
- const {
32816
- onCollapse,
32817
- onExpand,
32818
- onResize
32819
- } = callbacks;
32820
- if (onResize) {
32821
- onResize(size, lastNotifiedSize);
32822
- }
32823
- if (collapsible && (onCollapse || onExpand)) {
32824
- if (onExpand && (lastNotifiedSize == null || fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && !fuzzyNumbersEqual$1(size, collapsedSize)) {
32825
- onExpand();
32826
- }
32827
- if (onCollapse && (lastNotifiedSize == null || !fuzzyNumbersEqual$1(lastNotifiedSize, collapsedSize)) && fuzzyNumbersEqual$1(size, collapsedSize)) {
32828
- onCollapse();
32829
- }
32830
- }
32831
- }
32832
- });
32833
- }
32834
-
32835
- function compareLayouts(a, b) {
32836
- if (a.length !== b.length) {
32837
- return false;
32838
- } else {
32839
- for (let index = 0; index < a.length; index++) {
32840
- if (a[index] != b[index]) {
32841
- return false;
32842
- }
32843
- }
32844
- }
32845
- return true;
32846
- }
32847
-
32848
- // This method returns a number between 1 and 100 representing
32849
-
32850
- // the % of the group's overall space this panel should occupy.
32851
- function computePanelFlexBoxStyle({
32852
- defaultSize,
32853
- dragState,
32854
- layout,
32855
- panelData,
32856
- panelIndex,
32857
- precision = 3
32858
- }) {
32859
- const size = layout[panelIndex];
32860
- let flexGrow;
32861
- if (size == null) {
32862
- // Initial render (before panels have registered themselves)
32863
- // In order to support server rendering, fall back to default size if provided
32864
- flexGrow = defaultSize != undefined ? defaultSize.toFixed(precision) : "1";
32865
- } else if (panelData.length === 1) {
32866
- // Special case: Single panel group should always fill full width/height
32867
- flexGrow = "1";
32868
- } else {
32869
- flexGrow = size.toFixed(precision);
32870
- }
32871
- return {
32872
- flexBasis: 0,
32873
- flexGrow,
32874
- flexShrink: 1,
32875
- // Without this, Panel sizes may be unintentionally overridden by their content
32876
- overflow: "hidden",
32877
- // Disable pointer events inside of a panel during resize
32878
- // This avoid edge cases like nested iframes
32879
- pointerEvents: dragState !== null ? "none" : undefined
32880
- };
32881
- }
32882
-
32883
- function debounce(callback, durationMs = 10) {
32884
- let timeoutId = null;
32885
- let callable = (...args) => {
32886
- if (timeoutId !== null) {
32887
- clearTimeout(timeoutId);
32888
- }
32889
- timeoutId = setTimeout(() => {
32890
- callback(...args);
32891
- }, durationMs);
32892
- };
32893
- return callable;
32894
- }
32895
-
32896
- // PanelGroup might be rendering in a server-side environment where localStorage is not available
32897
- // or on a browser with cookies/storage disabled.
32898
- // In either case, this function avoids accessing localStorage until needed,
32899
- // and avoids throwing user-visible errors.
32900
- function initializeDefaultStorage(storageObject) {
32901
- try {
32902
- if (typeof localStorage !== "undefined") {
32903
- // Bypass this check for future calls
32904
- storageObject.getItem = name => {
32905
- return localStorage.getItem(name);
32906
- };
32907
- storageObject.setItem = (name, value) => {
32908
- localStorage.setItem(name, value);
32909
- };
32910
- } else {
32911
- throw new Error("localStorage not supported in this environment");
32912
- }
32913
- } catch (error) {
32914
- console.error(error);
32915
- storageObject.getItem = () => null;
32916
- storageObject.setItem = () => {};
32917
- }
32918
- }
32919
-
32920
- function getPanelGroupKey(autoSaveId) {
32921
- return `react-resizable-panels:${autoSaveId}`;
32922
- }
32923
-
32924
- // Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
32925
- // so they should not be used as part of the serialization key.
32926
- // Using the min/max size attributes should work well enough as a backup.
32927
- // Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
32928
- function getPanelKey(panels) {
32929
- return panels.map(panel => {
32930
- const {
32931
- constraints,
32932
- id,
32933
- idIsFromProps,
32934
- order
32935
- } = panel;
32936
- if (idIsFromProps) {
32937
- return id;
32938
- } else {
32939
- return order ? `${order}:${JSON.stringify(constraints)}` : JSON.stringify(constraints);
32940
- }
32941
- }).sort((a, b) => a.localeCompare(b)).join(",");
32942
- }
32943
- function loadSerializedPanelGroupState(autoSaveId, storage) {
32944
- try {
32945
- const panelGroupKey = getPanelGroupKey(autoSaveId);
32946
- const serialized = storage.getItem(panelGroupKey);
32947
- if (serialized) {
32948
- const parsed = JSON.parse(serialized);
32949
- if (typeof parsed === "object" && parsed != null) {
32950
- return parsed;
32951
- }
32952
- }
32953
- } catch (error) {}
32954
- return null;
32955
- }
32956
- function loadPanelGroupState(autoSaveId, panels, storage) {
32957
- var _loadSerializedPanelG, _state$panelKey;
32958
- const state = (_loadSerializedPanelG = loadSerializedPanelGroupState(autoSaveId, storage)) !== null && _loadSerializedPanelG !== void 0 ? _loadSerializedPanelG : {};
32959
- const panelKey = getPanelKey(panels);
32960
- return (_state$panelKey = state[panelKey]) !== null && _state$panelKey !== void 0 ? _state$panelKey : null;
32961
- }
32962
- function savePanelGroupState(autoSaveId, panels, panelSizesBeforeCollapse, sizes, storage) {
32963
- var _loadSerializedPanelG2;
32964
- const panelGroupKey = getPanelGroupKey(autoSaveId);
32965
- const panelKey = getPanelKey(panels);
32966
- const state = (_loadSerializedPanelG2 = loadSerializedPanelGroupState(autoSaveId, storage)) !== null && _loadSerializedPanelG2 !== void 0 ? _loadSerializedPanelG2 : {};
32967
- state[panelKey] = {
32968
- expandToSizes: Object.fromEntries(panelSizesBeforeCollapse.entries()),
32969
- layout: sizes
32970
- };
32971
- try {
32972
- storage.setItem(panelGroupKey, JSON.stringify(state));
32973
- } catch (error) {
32974
- console.error(error);
32975
- }
32976
- }
32977
-
32978
- // All units must be in percentages; pixel values should be pre-converted
32979
- function validatePanelGroupLayout({
32980
- layout: prevLayout,
32981
- panelConstraints
32982
- }) {
32983
- const nextLayout = [...prevLayout];
32984
- const nextLayoutTotalSize = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
32985
-
32986
- // Validate layout expectations
32987
- if (nextLayout.length !== panelConstraints.length) {
32988
- throw Error(`Invalid ${panelConstraints.length} panel layout: ${nextLayout.map(size => `${size}%`).join(", ")}`);
32989
- } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100) && nextLayout.length > 0) {
32990
- for (let index = 0; index < panelConstraints.length; index++) {
32991
- const unsafeSize = nextLayout[index];
32992
- assert(unsafeSize != null, `No layout data found for index ${index}`);
32993
- const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
32994
- nextLayout[index] = safeSize;
32995
- }
32996
- }
32997
- let remainingSize = 0;
32998
-
32999
- // First pass: Validate the proposed layout given each panel's constraints
33000
- for (let index = 0; index < panelConstraints.length; index++) {
33001
- const unsafeSize = nextLayout[index];
33002
- assert(unsafeSize != null, `No layout data found for index ${index}`);
33003
- const safeSize = resizePanel({
33004
- panelConstraints,
33005
- panelIndex: index,
33006
- size: unsafeSize
33007
- });
33008
- if (unsafeSize != safeSize) {
33009
- remainingSize += unsafeSize - safeSize;
33010
- nextLayout[index] = safeSize;
33011
- }
33012
- }
33013
-
33014
- // If there is additional, left over space, assign it to any panel(s) that permits it
33015
- // (It's not worth taking multiple additional passes to evenly distribute)
33016
- if (!fuzzyNumbersEqual(remainingSize, 0)) {
33017
- for (let index = 0; index < panelConstraints.length; index++) {
33018
- const prevSize = nextLayout[index];
33019
- assert(prevSize != null, `No layout data found for index ${index}`);
33020
- const unsafeSize = prevSize + remainingSize;
33021
- const safeSize = resizePanel({
33022
- panelConstraints,
33023
- panelIndex: index,
33024
- size: unsafeSize
33025
- });
33026
- if (prevSize !== safeSize) {
33027
- remainingSize -= safeSize - prevSize;
33028
- nextLayout[index] = safeSize;
33029
-
33030
- // Once we've used up the remainder, bail
33031
- if (fuzzyNumbersEqual(remainingSize, 0)) {
33032
- break;
33033
- }
33034
- }
33035
- }
33036
- }
33037
- return nextLayout;
33038
- }
33039
-
33040
- const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
33041
- const defaultStorage = {
33042
- getItem: name => {
33043
- initializeDefaultStorage(defaultStorage);
33044
- return defaultStorage.getItem(name);
33045
- },
33046
- setItem: (name, value) => {
33047
- initializeDefaultStorage(defaultStorage);
33048
- defaultStorage.setItem(name, value);
33049
- }
33050
- };
33051
- const debounceMap = {};
33052
- function PanelGroupWithForwardedRef({
33053
- autoSaveId = null,
33054
- children,
33055
- className: classNameFromProps = "",
33056
- direction,
33057
- forwardedRef,
33058
- id: idFromProps = null,
33059
- onLayout = null,
33060
- keyboardResizeBy = null,
33061
- storage = defaultStorage,
33062
- style: styleFromProps,
33063
- tagName: Type = "div",
33064
- ...rest
33065
- }) {
33066
- const groupId = useUniqueId(idFromProps);
33067
- const panelGroupElementRef = useRef(null);
33068
- const [dragState, setDragState] = useState(null);
33069
- const [layout, setLayout] = useState([]);
33070
- const forceUpdate = useForceUpdate();
33071
- const panelIdToLastNotifiedSizeMapRef = useRef({});
33072
- const panelSizeBeforeCollapseRef = useRef(new Map());
33073
- const prevDeltaRef = useRef(0);
33074
- const committedValuesRef = useRef({
33075
- autoSaveId,
33076
- direction,
33077
- dragState,
33078
- id: groupId,
33079
- keyboardResizeBy,
33080
- onLayout,
33081
- storage
33082
- });
33083
- const eagerValuesRef = useRef({
33084
- layout,
33085
- panelDataArray: [],
33086
- panelDataArrayChanged: false
33087
- });
33088
- useRef({
33089
- didLogIdAndOrderWarning: false,
33090
- didLogPanelConstraintsWarning: false,
33091
- prevPanelIds: []
33092
- });
33093
- useImperativeHandle(forwardedRef, () => ({
33094
- getId: () => committedValuesRef.current.id,
33095
- getLayout: () => {
33096
- const {
33097
- layout
33098
- } = eagerValuesRef.current;
33099
- return layout;
33100
- },
33101
- setLayout: unsafeLayout => {
33102
- const {
33103
- onLayout
33104
- } = committedValuesRef.current;
33105
- const {
33106
- layout: prevLayout,
33107
- panelDataArray
33108
- } = eagerValuesRef.current;
33109
- const safeLayout = validatePanelGroupLayout({
33110
- layout: unsafeLayout,
33111
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
33112
- });
33113
- if (!areEqual(prevLayout, safeLayout)) {
33114
- setLayout(safeLayout);
33115
- eagerValuesRef.current.layout = safeLayout;
33116
- if (onLayout) {
33117
- onLayout(safeLayout);
33118
- }
33119
- callPanelCallbacks(panelDataArray, safeLayout, panelIdToLastNotifiedSizeMapRef.current);
33120
- }
33121
- }
33122
- }), []);
33123
- useIsomorphicLayoutEffect$1(() => {
33124
- committedValuesRef.current.autoSaveId = autoSaveId;
33125
- committedValuesRef.current.direction = direction;
33126
- committedValuesRef.current.dragState = dragState;
33127
- committedValuesRef.current.id = groupId;
33128
- committedValuesRef.current.onLayout = onLayout;
33129
- committedValuesRef.current.storage = storage;
33130
- });
33131
- useWindowSplitterPanelGroupBehavior({
33132
- committedValuesRef,
33133
- eagerValuesRef,
33134
- groupId,
33135
- layout,
33136
- panelDataArray: eagerValuesRef.current.panelDataArray,
33137
- setLayout,
33138
- panelGroupElement: panelGroupElementRef.current
33139
- });
33140
- useEffect(() => {
33141
- const {
33142
- panelDataArray
33143
- } = eagerValuesRef.current;
33144
-
33145
- // If this panel has been configured to persist sizing information, save sizes to local storage.
33146
- if (autoSaveId) {
33147
- if (layout.length === 0 || layout.length !== panelDataArray.length) {
33148
- return;
33149
- }
33150
- let debouncedSave = debounceMap[autoSaveId];
33151
-
33152
- // Limit the frequency of localStorage updates.
33153
- if (debouncedSave == null) {
33154
- debouncedSave = debounce(savePanelGroupState, LOCAL_STORAGE_DEBOUNCE_INTERVAL);
33155
- debounceMap[autoSaveId] = debouncedSave;
33156
- }
33157
-
33158
- // Clone mutable data before passing to the debounced function,
33159
- // else we run the risk of saving an incorrect combination of mutable and immutable values to state.
33160
- const clonedPanelDataArray = [...panelDataArray];
33161
- const clonedPanelSizesBeforeCollapse = new Map(panelSizeBeforeCollapseRef.current);
33162
- debouncedSave(autoSaveId, clonedPanelDataArray, clonedPanelSizesBeforeCollapse, layout, storage);
33163
- }
33164
- }, [autoSaveId, layout, storage]);
33165
-
33166
- // DEV warnings
33167
- useEffect(() => {
33168
- });
33169
-
33170
- // External APIs are safe to memoize via committed values ref
33171
- const collapsePanel = useCallback(panelData => {
33172
- const {
33173
- onLayout
33174
- } = committedValuesRef.current;
33175
- const {
33176
- layout: prevLayout,
33177
- panelDataArray
33178
- } = eagerValuesRef.current;
33179
- if (panelData.constraints.collapsible) {
33180
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
33181
- const {
33182
- collapsedSize = 0,
33183
- panelSize,
33184
- pivotIndices
33185
- } = panelDataHelper(panelDataArray, panelData, prevLayout);
33186
- assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
33187
- if (!fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
33188
- // Store size before collapse;
33189
- // This is the size that gets restored if the expand() API is used.
33190
- panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
33191
- const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
33192
- const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
33193
- const nextLayout = adjustLayoutByDelta({
33194
- delta,
33195
- initialLayout: prevLayout,
33196
- panelConstraints: panelConstraintsArray,
33197
- pivotIndices,
33198
- prevLayout,
33199
- trigger: "imperative-api"
33200
- });
33201
- if (!compareLayouts(prevLayout, nextLayout)) {
33202
- setLayout(nextLayout);
33203
- eagerValuesRef.current.layout = nextLayout;
33204
- if (onLayout) {
33205
- onLayout(nextLayout);
33206
- }
33207
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
33208
- }
33209
- }
33210
- }
33211
- }, []);
33212
-
33213
- // External APIs are safe to memoize via committed values ref
33214
- const expandPanel = useCallback((panelData, minSizeOverride) => {
33215
- const {
33216
- onLayout
33217
- } = committedValuesRef.current;
33218
- const {
33219
- layout: prevLayout,
33220
- panelDataArray
33221
- } = eagerValuesRef.current;
33222
- if (panelData.constraints.collapsible) {
33223
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
33224
- const {
33225
- collapsedSize = 0,
33226
- panelSize = 0,
33227
- minSize: minSizeFromProps = 0,
33228
- pivotIndices
33229
- } = panelDataHelper(panelDataArray, panelData, prevLayout);
33230
- const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
33231
- if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
33232
- // Restore this panel to the size it was before it was collapsed, if possible.
33233
- const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
33234
- const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
33235
- const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
33236
- const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
33237
- const nextLayout = adjustLayoutByDelta({
33238
- delta,
33239
- initialLayout: prevLayout,
33240
- panelConstraints: panelConstraintsArray,
33241
- pivotIndices,
33242
- prevLayout,
33243
- trigger: "imperative-api"
33244
- });
33245
- if (!compareLayouts(prevLayout, nextLayout)) {
33246
- setLayout(nextLayout);
33247
- eagerValuesRef.current.layout = nextLayout;
33248
- if (onLayout) {
33249
- onLayout(nextLayout);
33250
- }
33251
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
33252
- }
33253
- }
33254
- }
33255
- }, []);
33256
-
33257
- // External APIs are safe to memoize via committed values ref
33258
- const getPanelSize = useCallback(panelData => {
33259
- const {
33260
- layout,
33261
- panelDataArray
33262
- } = eagerValuesRef.current;
33263
- const {
33264
- panelSize
33265
- } = panelDataHelper(panelDataArray, panelData, layout);
33266
- assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
33267
- return panelSize;
33268
- }, []);
33269
-
33270
- // This API should never read from committedValuesRef
33271
- const getPanelStyle = useCallback((panelData, defaultSize) => {
33272
- const {
33273
- panelDataArray
33274
- } = eagerValuesRef.current;
33275
- const panelIndex = findPanelDataIndex(panelDataArray, panelData);
33276
- return computePanelFlexBoxStyle({
33277
- defaultSize,
33278
- dragState,
33279
- layout,
33280
- panelData: panelDataArray,
33281
- panelIndex
33282
- });
33283
- }, [dragState, layout]);
33284
-
33285
- // External APIs are safe to memoize via committed values ref
33286
- const isPanelCollapsed = useCallback(panelData => {
33287
- const {
33288
- layout,
33289
- panelDataArray
33290
- } = eagerValuesRef.current;
33291
- const {
33292
- collapsedSize = 0,
33293
- collapsible,
33294
- panelSize
33295
- } = panelDataHelper(panelDataArray, panelData, layout);
33296
- assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
33297
- return collapsible === true && fuzzyNumbersEqual$1(panelSize, collapsedSize);
33298
- }, []);
33299
-
33300
- // External APIs are safe to memoize via committed values ref
33301
- const isPanelExpanded = useCallback(panelData => {
33302
- const {
33303
- layout,
33304
- panelDataArray
33305
- } = eagerValuesRef.current;
33306
- const {
33307
- collapsedSize = 0,
33308
- collapsible,
33309
- panelSize
33310
- } = panelDataHelper(panelDataArray, panelData, layout);
33311
- assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
33312
- return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
33313
- }, []);
33314
- const registerPanel = useCallback(panelData => {
33315
- const {
33316
- panelDataArray
33317
- } = eagerValuesRef.current;
33318
- panelDataArray.push(panelData);
33319
- panelDataArray.sort((panelA, panelB) => {
33320
- const orderA = panelA.order;
33321
- const orderB = panelB.order;
33322
- if (orderA == null && orderB == null) {
33323
- return 0;
33324
- } else if (orderA == null) {
33325
- return -1;
33326
- } else if (orderB == null) {
33327
- return 1;
33328
- } else {
33329
- return orderA - orderB;
33330
- }
33331
- });
33332
- eagerValuesRef.current.panelDataArrayChanged = true;
33333
- forceUpdate();
33334
- }, [forceUpdate]);
33335
-
33336
- // (Re)calculate group layout whenever panels are registered or unregistered.
33337
- // eslint-disable-next-line react-hooks/exhaustive-deps
33338
- useIsomorphicLayoutEffect$1(() => {
33339
- if (eagerValuesRef.current.panelDataArrayChanged) {
33340
- eagerValuesRef.current.panelDataArrayChanged = false;
33341
- const {
33342
- autoSaveId,
33343
- onLayout,
33344
- storage
33345
- } = committedValuesRef.current;
33346
- const {
33347
- layout: prevLayout,
33348
- panelDataArray
33349
- } = eagerValuesRef.current;
33350
-
33351
- // If this panel has been configured to persist sizing information,
33352
- // default size should be restored from local storage if possible.
33353
- let unsafeLayout = null;
33354
- if (autoSaveId) {
33355
- const state = loadPanelGroupState(autoSaveId, panelDataArray, storage);
33356
- if (state) {
33357
- panelSizeBeforeCollapseRef.current = new Map(Object.entries(state.expandToSizes));
33358
- unsafeLayout = state.layout;
33359
- }
33360
- }
33361
- if (unsafeLayout == null) {
33362
- unsafeLayout = calculateUnsafeDefaultLayout({
33363
- panelDataArray
33364
- });
33365
- }
33366
-
33367
- // Validate even saved layouts in case something has changed since last render
33368
- // e.g. for pixel groups, this could be the size of the window
33369
- const nextLayout = validatePanelGroupLayout({
33370
- layout: unsafeLayout,
33371
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
33372
- });
33373
- if (!areEqual(prevLayout, nextLayout)) {
33374
- setLayout(nextLayout);
33375
- eagerValuesRef.current.layout = nextLayout;
33376
- if (onLayout) {
33377
- onLayout(nextLayout);
33378
- }
33379
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
33380
- }
33381
- }
33382
- });
33383
-
33384
- // Reset the cached layout if hidden by the Activity/Offscreen API
33385
- useIsomorphicLayoutEffect$1(() => {
33386
- const eagerValues = eagerValuesRef.current;
33387
- return () => {
33388
- eagerValues.layout = [];
33389
- };
33390
- }, []);
33391
- const registerResizeHandle = useCallback(dragHandleId => {
33392
- let isRTL = false;
33393
- const panelGroupElement = panelGroupElementRef.current;
33394
- if (panelGroupElement) {
33395
- const style = window.getComputedStyle(panelGroupElement, null);
33396
- if (style.getPropertyValue("direction") === "rtl") {
33397
- isRTL = true;
33398
- }
33399
- }
33400
- return function resizeHandler(event) {
33401
- event.preventDefault();
33402
- const panelGroupElement = panelGroupElementRef.current;
33403
- if (!panelGroupElement) {
33404
- return () => null;
33405
- }
33406
- const {
33407
- direction,
33408
- dragState,
33409
- id: groupId,
33410
- keyboardResizeBy,
33411
- onLayout
33412
- } = committedValuesRef.current;
33413
- const {
33414
- layout: prevLayout,
33415
- panelDataArray
33416
- } = eagerValuesRef.current;
33417
- const {
33418
- initialLayout
33419
- } = dragState !== null && dragState !== void 0 ? dragState : {};
33420
- const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
33421
- let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
33422
- const isHorizontal = direction === "horizontal";
33423
- if (isHorizontal && isRTL) {
33424
- delta = -delta;
33425
- }
33426
- const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
33427
- const nextLayout = adjustLayoutByDelta({
33428
- delta,
33429
- initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
33430
- panelConstraints,
33431
- pivotIndices,
33432
- prevLayout,
33433
- trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
33434
- });
33435
- const layoutChanged = !compareLayouts(prevLayout, nextLayout);
33436
-
33437
- // Only update the cursor for layout changes triggered by touch/mouse events (not keyboard)
33438
- // Update the cursor even if the layout hasn't changed (we may need to show an invalid cursor state)
33439
- if (isPointerEvent(event) || isMouseEvent(event)) {
33440
- // Watch for multiple subsequent deltas; this might occur for tiny cursor movements.
33441
- // In this case, Panel sizes might not change–
33442
- // but updating cursor in this scenario would cause a flicker.
33443
- if (prevDeltaRef.current != delta) {
33444
- prevDeltaRef.current = delta;
33445
- if (!layoutChanged && delta !== 0) {
33446
- // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
33447
- // This mimics VS Code behavior.
33448
- if (isHorizontal) {
33449
- reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
33450
- } else {
33451
- reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
33452
- }
33453
- } else {
33454
- reportConstraintsViolation(dragHandleId, 0);
33455
- }
33456
- }
33457
- }
33458
- if (layoutChanged) {
33459
- setLayout(nextLayout);
33460
- eagerValuesRef.current.layout = nextLayout;
33461
- if (onLayout) {
33462
- onLayout(nextLayout);
33463
- }
33464
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
33465
- }
33466
- };
33467
- }, []);
33468
-
33469
- // External APIs are safe to memoize via committed values ref
33470
- const resizePanel = useCallback((panelData, unsafePanelSize) => {
33471
- const {
33472
- onLayout
33473
- } = committedValuesRef.current;
33474
- const {
33475
- layout: prevLayout,
33476
- panelDataArray
33477
- } = eagerValuesRef.current;
33478
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
33479
- const {
33480
- panelSize,
33481
- pivotIndices
33482
- } = panelDataHelper(panelDataArray, panelData, prevLayout);
33483
- assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
33484
- const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
33485
- const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
33486
- const nextLayout = adjustLayoutByDelta({
33487
- delta,
33488
- initialLayout: prevLayout,
33489
- panelConstraints: panelConstraintsArray,
33490
- pivotIndices,
33491
- prevLayout,
33492
- trigger: "imperative-api"
33493
- });
33494
- if (!compareLayouts(prevLayout, nextLayout)) {
33495
- setLayout(nextLayout);
33496
- eagerValuesRef.current.layout = nextLayout;
33497
- if (onLayout) {
33498
- onLayout(nextLayout);
33499
- }
33500
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
33501
- }
33502
- }, []);
33503
- const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
33504
- const {
33505
- layout,
33506
- panelDataArray
33507
- } = eagerValuesRef.current;
33508
- const {
33509
- collapsedSize: prevCollapsedSize = 0,
33510
- collapsible: prevCollapsible
33511
- } = prevConstraints;
33512
- const {
33513
- collapsedSize: nextCollapsedSize = 0,
33514
- collapsible: nextCollapsible,
33515
- maxSize: nextMaxSize = 100,
33516
- minSize: nextMinSize = 0
33517
- } = panelData.constraints;
33518
- const {
33519
- panelSize: prevPanelSize
33520
- } = panelDataHelper(panelDataArray, panelData, layout);
33521
- if (prevPanelSize == null) {
33522
- // It's possible that the panels in this group have changed since the last render
33523
- return;
33524
- }
33525
- if (prevCollapsible && nextCollapsible && fuzzyNumbersEqual$1(prevPanelSize, prevCollapsedSize)) {
33526
- if (!fuzzyNumbersEqual$1(prevCollapsedSize, nextCollapsedSize)) {
33527
- resizePanel(panelData, nextCollapsedSize);
33528
- }
33529
- } else if (prevPanelSize < nextMinSize) {
33530
- resizePanel(panelData, nextMinSize);
33531
- } else if (prevPanelSize > nextMaxSize) {
33532
- resizePanel(panelData, nextMaxSize);
33533
- }
33534
- }, [resizePanel]);
33535
-
33536
- // TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
33537
- const startDragging = useCallback((dragHandleId, event) => {
33538
- const {
33539
- direction
33540
- } = committedValuesRef.current;
33541
- const {
33542
- layout
33543
- } = eagerValuesRef.current;
33544
- if (!panelGroupElementRef.current) {
33545
- return;
33546
- }
33547
- const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
33548
- assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
33549
- const initialCursorPosition = getResizeEventCursorPosition(direction, event);
33550
- setDragState({
33551
- dragHandleId,
33552
- dragHandleRect: handleElement.getBoundingClientRect(),
33553
- initialCursorPosition,
33554
- initialLayout: layout
33555
- });
33556
- }, []);
33557
- const stopDragging = useCallback(() => {
33558
- setDragState(null);
33559
- }, []);
33560
- const unregisterPanel = useCallback(panelData => {
33561
- const {
33562
- panelDataArray
33563
- } = eagerValuesRef.current;
33564
- const index = findPanelDataIndex(panelDataArray, panelData);
33565
- if (index >= 0) {
33566
- panelDataArray.splice(index, 1);
33567
-
33568
- // TRICKY
33569
- // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
33570
- // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
33571
- // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
33572
- delete panelIdToLastNotifiedSizeMapRef.current[panelData.id];
33573
- eagerValuesRef.current.panelDataArrayChanged = true;
33574
- forceUpdate();
33575
- }
33576
- }, [forceUpdate]);
33577
- const context = useMemo(() => ({
33578
- collapsePanel,
33579
- direction,
33580
- dragState,
33581
- expandPanel,
33582
- getPanelSize,
33583
- getPanelStyle,
33584
- groupId,
33585
- isPanelCollapsed,
33586
- isPanelExpanded,
33587
- reevaluatePanelConstraints,
33588
- registerPanel,
33589
- registerResizeHandle,
33590
- resizePanel,
33591
- startDragging,
33592
- stopDragging,
33593
- unregisterPanel,
33594
- panelGroupElement: panelGroupElementRef.current
33595
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
33596
- const style = {
33597
- display: "flex",
33598
- flexDirection: direction === "horizontal" ? "row" : "column",
33599
- height: "100%",
33600
- overflow: "hidden",
33601
- width: "100%"
33602
- };
33603
- return createElement(PanelGroupContext.Provider, {
33604
- value: context
33605
- }, createElement(Type, {
33606
- ...rest,
33607
- children,
33608
- className: classNameFromProps,
33609
- id: idFromProps,
33610
- ref: panelGroupElementRef,
33611
- style: {
33612
- ...style,
33613
- ...styleFromProps
33614
- },
33615
- // CSS selectors
33616
- [DATA_ATTRIBUTES.group]: "",
33617
- [DATA_ATTRIBUTES.groupDirection]: direction,
33618
- [DATA_ATTRIBUTES.groupId]: groupId
33619
- }));
33620
- }
33621
- const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
33622
- ...props,
33623
- forwardedRef: ref
33624
- }));
33625
- PanelGroupWithForwardedRef.displayName = "PanelGroup";
33626
- PanelGroup.displayName = "forwardRef(PanelGroup)";
33627
- function findPanelDataIndex(panelDataArray, panelData) {
33628
- return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
33629
- }
33630
- function panelDataHelper(panelDataArray, panelData, layout) {
33631
- const panelIndex = findPanelDataIndex(panelDataArray, panelData);
33632
- const isLastPanel = panelIndex === panelDataArray.length - 1;
33633
- const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
33634
- const panelSize = layout[panelIndex];
33635
- return {
33636
- ...panelData.constraints,
33637
- panelSize,
33638
- pivotIndices
33639
- };
33640
- }
33641
-
33642
- // https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
33643
-
33644
- function useWindowSplitterResizeHandlerBehavior({
33645
- disabled,
33646
- handleId,
33647
- resizeHandler,
33648
- panelGroupElement
33649
- }) {
33650
- useEffect(() => {
33651
- if (disabled || resizeHandler == null || panelGroupElement == null) {
33652
- return;
33653
- }
33654
- const handleElement = getResizeHandleElement(handleId, panelGroupElement);
33655
- if (handleElement == null) {
33656
- return;
33657
- }
33658
- const onKeyDown = event => {
33659
- if (event.defaultPrevented) {
33660
- return;
33661
- }
33662
- switch (event.key) {
33663
- case "ArrowDown":
33664
- case "ArrowLeft":
33665
- case "ArrowRight":
33666
- case "ArrowUp":
33667
- case "End":
33668
- case "Home":
33669
- {
33670
- event.preventDefault();
33671
- resizeHandler(event);
33672
- break;
33673
- }
33674
- case "F6":
33675
- {
33676
- event.preventDefault();
33677
- const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
33678
- assert(groupId, `No group element found for id "${groupId}"`);
33679
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
33680
- const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
33681
- assert(index !== null, `No resize element found for id "${handleId}"`);
33682
- const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
33683
- const nextHandle = handles[nextIndex];
33684
- nextHandle.focus();
33685
- break;
33686
- }
33687
- }
33688
- };
33689
- handleElement.addEventListener("keydown", onKeyDown);
33690
- return () => {
33691
- handleElement.removeEventListener("keydown", onKeyDown);
33692
- };
33693
- }, [panelGroupElement, disabled, handleId, resizeHandler]);
33694
- }
33695
-
33696
- function PanelResizeHandle({
33697
- children = null,
33698
- className: classNameFromProps = "",
33699
- disabled = false,
33700
- hitAreaMargins,
33701
- id: idFromProps,
33702
- onBlur,
33703
- onClick,
33704
- onDragging,
33705
- onFocus,
33706
- onPointerDown,
33707
- onPointerUp,
33708
- style: styleFromProps = {},
33709
- tabIndex = 0,
33710
- tagName: Type = "div",
33711
- ...rest
33712
- }) {
33713
- var _hitAreaMargins$coars, _hitAreaMargins$fine;
33714
- const elementRef = useRef(null);
33715
-
33716
- // Use a ref to guard against users passing inline props
33717
- const callbacksRef = useRef({
33718
- onClick,
33719
- onDragging,
33720
- onPointerDown,
33721
- onPointerUp
33722
- });
33723
- useEffect(() => {
33724
- callbacksRef.current.onClick = onClick;
33725
- callbacksRef.current.onDragging = onDragging;
33726
- callbacksRef.current.onPointerDown = onPointerDown;
33727
- callbacksRef.current.onPointerUp = onPointerUp;
33728
- });
33729
- const panelGroupContext = useContext(PanelGroupContext);
33730
- if (panelGroupContext === null) {
33731
- throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
33732
- }
33733
- const {
33734
- direction,
33735
- groupId,
33736
- registerResizeHandle: registerResizeHandleWithParentGroup,
33737
- startDragging,
33738
- stopDragging,
33739
- panelGroupElement
33740
- } = panelGroupContext;
33741
- const resizeHandleId = useUniqueId(idFromProps);
33742
- const [state, setState] = useState("inactive");
33743
- const [isFocused, setIsFocused] = useState(false);
33744
- const [resizeHandler, setResizeHandler] = useState(null);
33745
- const committedValuesRef = useRef({
33746
- state
33747
- });
33748
- useIsomorphicLayoutEffect$1(() => {
33749
- committedValuesRef.current.state = state;
33750
- });
33751
- useEffect(() => {
33752
- if (disabled) {
33753
- setResizeHandler(null);
33754
- } else {
33755
- const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
33756
- setResizeHandler(() => resizeHandler);
33757
- }
33758
- }, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
33759
-
33760
- // Extract hit area margins before passing them to the effect's dependency array
33761
- // so that inline object values won't trigger re-renders
33762
- const coarseHitAreaMargins = (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15;
33763
- const fineHitAreaMargins = (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5;
33764
- useEffect(() => {
33765
- if (disabled || resizeHandler == null) {
33766
- return;
33767
- }
33768
- const element = elementRef.current;
33769
- assert(element, "Element ref not attached");
33770
- let didMove = false;
33771
- const setResizeHandlerState = (action, isActive, event) => {
33772
- if (!isActive) {
33773
- setState("inactive");
33774
- return;
33775
- }
33776
- switch (action) {
33777
- case "down":
33778
- {
33779
- setState("drag");
33780
- didMove = false;
33781
- assert(event, 'Expected event to be defined for "down" action');
33782
- startDragging(resizeHandleId, event);
33783
- const {
33784
- onDragging,
33785
- onPointerDown
33786
- } = callbacksRef.current;
33787
- onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
33788
- onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
33789
- break;
33790
- }
33791
- case "move":
33792
- {
33793
- const {
33794
- state
33795
- } = committedValuesRef.current;
33796
- didMove = true;
33797
- if (state !== "drag") {
33798
- setState("hover");
33799
- }
33800
- assert(event, 'Expected event to be defined for "move" action');
33801
- resizeHandler(event);
33802
- break;
33803
- }
33804
- case "up":
33805
- {
33806
- setState("hover");
33807
- stopDragging();
33808
- const {
33809
- onClick,
33810
- onDragging,
33811
- onPointerUp
33812
- } = callbacksRef.current;
33813
- onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
33814
- onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
33815
- if (!didMove) {
33816
- onClick === null || onClick === void 0 ? void 0 : onClick();
33817
- }
33818
- break;
33819
- }
33820
- }
33821
- };
33822
- return registerResizeHandle(resizeHandleId, element, direction, {
33823
- coarse: coarseHitAreaMargins,
33824
- fine: fineHitAreaMargins
33825
- }, setResizeHandlerState);
33826
- }, [coarseHitAreaMargins, direction, disabled, fineHitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
33827
- useWindowSplitterResizeHandlerBehavior({
33828
- disabled,
33829
- handleId: resizeHandleId,
33830
- resizeHandler,
33831
- panelGroupElement
33832
- });
33833
- const style = {
33834
- touchAction: "none",
33835
- userSelect: "none"
33836
- };
33837
- return createElement(Type, {
33838
- ...rest,
33839
- children,
33840
- className: classNameFromProps,
33841
- id: idFromProps,
33842
- onBlur: () => {
33843
- setIsFocused(false);
33844
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
33845
- },
33846
- onFocus: () => {
33847
- setIsFocused(true);
33848
- onFocus === null || onFocus === void 0 ? void 0 : onFocus();
33849
- },
33850
- ref: elementRef,
33851
- role: "separator",
33852
- style: {
33853
- ...style,
33854
- ...styleFromProps
33855
- },
33856
- tabIndex,
33857
- // CSS selectors
33858
- [DATA_ATTRIBUTES.groupDirection]: direction,
33859
- [DATA_ATTRIBUTES.groupId]: groupId,
33860
- [DATA_ATTRIBUTES.resizeHandle]: "",
33861
- [DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
33862
- [DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
33863
- [DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
33864
- [DATA_ATTRIBUTES.resizeHandleState]: state
33865
- });
33866
- }
33867
- PanelResizeHandle.displayName = "PanelResizeHandle";
33868
-
33869
31462
  function ResizablePanelGroup({ className, ...props }) {
33870
- return (jsx(PanelGroup, { "data-slot": "resizable-panel-group", className: cn$1("flex h-full w-full data-[panel-group-direction=vertical]:flex-col", className), ...props }));
31463
+ return (jsx(ResizablePrimitive.PanelGroup, { "data-slot": "resizable-panel-group", className: cn$1("flex h-full w-full data-[panel-group-direction=vertical]:flex-col", className), ...props }));
33871
31464
  }
33872
31465
  function ResizablePanel({ ...props }) {
33873
- return jsx(Panel$1, { "data-slot": "resizable-panel", ...props });
31466
+ return jsx(ResizablePrimitive.Panel, { "data-slot": "resizable-panel", ...props });
33874
31467
  }
33875
31468
  function ResizableHandle({ withHandle, className, ...props }) {
33876
- return (jsx(PanelResizeHandle, { "data-slot": "resizable-handle", className: cn$1("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90", className), ...props, children: withHandle && (jsx("div", { className: "bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border", children: jsx(GripVerticalIcon, { className: "size-2.5" }) })) }));
31469
+ return (jsx(ResizablePrimitive.PanelResizeHandle, { "data-slot": "resizable-handle", className: cn$1("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90", className), ...props, children: withHandle && (jsx("div", { className: "bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border", children: jsx(GripVerticalIcon, { className: "size-2.5" }) })) }));
33877
31470
  }
33878
31471
 
33879
31472
  const loadFonts = (fonts) => {
@@ -46883,7 +44476,7 @@ const CaptionWords = ({ handleModalAnimation, trackItem }) => {
46883
44476
  }
46884
44477
  });
46885
44478
  };
46886
- const handleSetPosition = useCallback(debounce$1((left, top) => {
44479
+ const handleSetPosition = useCallback(debounce((left, top) => {
46887
44480
  const updates = captionsData.reduce((acc, item) => ({
46888
44481
  ...acc,
46889
44482
  [item.id]: {