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